Updating with all new changes

This commit is contained in:
Philip 2010-11-10 19:42:42 -05:00
parent 673eb2437e
commit 179a9f731a
7 changed files with 363 additions and 258 deletions

View File

@ -1,14 +1,14 @@
#ifndef DEFINE_H
#define DEFINE_H
#if defined(WIN32) && !defined(__GNUC__)
#ifdef WIN32
#define PATH_SEP "\\"
#else
#define PATH_SEP "/"
#endif
#define SAVE_VERSION 43
#define MINOR_VERSION 0
#define MINOR_VERSION 1
#define IDENT_VERSION "G" //Change this if you're not Simon! It should be a single letter.
#define BETA

View File

@ -93,10 +93,12 @@ int drawtextmax(pixel *vid, int x, int y, int w, char *s, int r, int g, int b, i
int textnwidth(char *s, int n);
int textnheight(char *s, int n, int w);
void textnpos(char *s, int n, int w, int *cx, int *cy);
int textwidthx(char *s, int w);
int textposxy(char *s, int width, int w, int h);
#if defined(WIN32) && !defined(__GNUC__)
_inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a);
#else

View File

@ -205,7 +205,7 @@ void execute_save(pixel *vid_buf);
int execute_delete(pixel *vid_buf, char *id);
int execute_report(pixel *vid_buf, char *id);
int execute_report(pixel *vid_buf, char *id, char *reason);
void execute_submit(pixel *vid_buf, char *id, char *message);
@ -215,5 +215,7 @@ int execute_vote(pixel *vid_buf, char *id, char *action);
void open_link(char *uri);
int report_ui(pixel *vid_buf, char *save_id);
#endif

View File

@ -148,12 +148,13 @@
#define TYPE_LIQUID 0x0002 //2 Liquids
#define TYPE_SOLID 0x0004 //4 Solids
#define TYPE_GAS 0x0008 //8 Gasses (Includes plasma)
#define TYPE_ENERGY 0x0018 //16 Energy (Thunder, Light, Neutrons etc.)
#define TYPE_ENERGY 0x0010 //16 Energy (Thunder, Light, Neutrons etc.)
#define PROP_CONDUCTS 0x0020 //32 Conducts electricity (Currently Unused)
#define PROP_BLACK 0x0040 //64 Absorbs Photons
#define PROP_NEUTPENETRATE 0x0080 //128 Penetrated by neutrons
#define PROP_NEUTABSORB 0x0100 //256 Absorbs neutrons, reflect is default
#define PROP_DEADLY 0x0200 //512 Is deadly for stickman.
#define PROP_NEUTPASS 0x0200 //512 Neutrons pass through, such as with glass
#define PROP_DEADLY 0x0400 //1024 Is deadly for stickman.
#define FLAG_STAGNANT 1
struct particle
@ -230,8 +231,8 @@ static const part_type ptypes[PT_NUM] =
{"NITR", PIXPACK(0x20E010), 0.5f, 0.02f * CFDS, 0.92f, 0.97f, 0.0f, 0.2f, 0.00f, 0.000f * CFDS, 2, 1000, 2, 0, 3, 1, 23, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 50, "Liquid. Pressure sensitive explosive.", TYPE_LIQUID},
{"CLNE", PIXPACK(0xFFD010), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 251, "Solid. Duplicates any particles it touches.", TYPE_SOLID},
{"GAS", PIXPACK(0xE0FF20), 1.0f, 0.01f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 0.75f, 0.001f * CFDS, 0, 600, 0, 0, 1, 1, 1, SC_GAS, R_TEMP+2.0f +273.15f, 42, "Gas. Diffuses. Flammable. Liquifies under pressure.", TYPE_GAS},
{"C-4", PIXPACK(0xD080E0), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 1000, 2, 50, 1, 1, 100, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 88, "Solid. Pressure sensitive explosive.", TYPE_SOLID},
{"GOO", PIXPACK(0x804000), 0.1f, 0.00f * CFDS, 0.97f, 0.50f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 12, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 75, "Solid. Deforms and disappears under pressure.", TYPE_SOLID},
{"C-4", PIXPACK(0xD080E0), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 1000, 2, 50, 1, 1, 100, SC_EXPLOSIVE, R_TEMP+0.0f +273.15f, 88, "Solid. Pressure sensitive explosive.", TYPE_SOLID | PROP_NEUTPENETRATE},
{"GOO", PIXPACK(0x804000), 0.1f, 0.00f * CFDS, 0.97f, 0.50f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 12, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 75, "Solid. Deforms and disappears under pressure.", TYPE_SOLID | PROP_NEUTPENETRATE},
{"ICE", PIXPACK(0xA0C0FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, -0.0003f* CFDS, 0, 0, 0, 0, 20, 1, 100, SC_SOLIDS, R_TEMP-50.0f+273.15f, 46, "Solid. Freezes water. Crushes under pressure. Cools down air.", TYPE_SOLID},
{"METL", PIXPACK(0x404060), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Solid. Conducts electricity. Meltable.", TYPE_SOLID|PROP_CONDUCTS},
{"SPRK", PIXPACK(0xFFFF80), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.001f * CFDS, 0, 0, 0, 0, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Electricity. Conducted by metal and water.", TYPE_SOLID},
@ -264,7 +265,7 @@ static const part_type ptypes[PT_NUM] =
{"LRBD", PIXPACK(0xAAAAAA), 0.3f, 0.02f * CFDS, 0.95f, 0.80f, 0.0f, 0.15f, 0.00f, 0.000001f* CFDS,2, 1000, 1, 0, 2, 1, 45, SC_EXPLOSIVE, R_TEMP+45.0f+273.15f, 170, "Liquid Rubidium.", TYPE_LIQUID|PROP_CONDUCTS},
{"NTCT", PIXPACK(0x505040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Semi-conductor. Only conducts electricity when hot (More than 100C)", TYPE_SOLID},
{"SAND", PIXPACK(0xFFD090), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 5, 1, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 150, "Sand, Heavy particles. Meltable.", TYPE_PART},
{"GLAS", PIXPACK(0x404040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 150, "Solid. Meltable. Shatters under pressure", TYPE_SOLID},
{"GLAS", PIXPACK(0x404040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 1, 1, 100, SC_SOLIDS, R_TEMP+0.0f +273.15f, 150, "Solid. Meltable. Shatters under pressure", TYPE_SOLID | PROP_NEUTPASS},
{"PTCT", PIXPACK(0x405050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Semi-conductor. Only conducts electricity when cold (Less than 120C)", TYPE_SOLID},
{"BGLA", PIXPACK(0x606060), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 5, 2, 1, 90, SC_POWDERS, R_TEMP+0.0f +273.15f, 150, "Broken Glass, Heavy particles. Meltable. Bagels.", TYPE_PART},
{"THDR", PIXPACK(0xFFFFA0), 0.0f, 0.00f * CFDS, 1.0f, 0.30f, -0.99f, 0.6f, 0.62f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 1, SC_ELEC, 9000.0f +273.15f, 251, "Lightning! Very hot, inflicts damage upon most materials, transfers current to metals.", TYPE_ENERGY},

View File

@ -1002,18 +1002,25 @@ int textnwidth(char *s, int n)
}
return x-1;
}
int textnheight(char *s, int n, int w)
void textnpos(char *s, int n, int w, int *cx, int *cy)
{
int x = 0;
int y = 0;
//TODO: Implement Textnheight for wrapped text
for(; *s; s++)
{
if(!n)
if(!n){
break;
}
x += font_data[font_ptrs[(int)(*(unsigned char *)s)]];
if(x>=w) {
x = 0;
y += FONT_H+2;
}
n--;
}
return x-1;
*cx = x-1;
*cy = y;
}
int textwidthx(char *s, int w)
@ -1029,6 +1036,23 @@ int textwidthx(char *s, int w)
}
return n;
}
int textposxy(char *s, int width, int w, int h)
{
int x=0,y=0,n=0,cw;
for(; *s; s++)
{
cw = font_data[font_ptrs[(int)(*(unsigned char *)s)]];
if(x+(cw/2) >= w && y+6 >= h)
break;
x += cw;
if(x>=width) {
x = 0;
y += FONT_H+2;
}
n++;
}
return n;
}
#if defined(WIN32) && !defined(__GNUC__)
_inline void blendpixel(pixel *vid, int x, int y, int r, int g, int b, int a)
@ -1244,7 +1268,6 @@ void draw_parts(pixel *vid)
int cr, cg, cb;
float fr, fg, fb;
float pt = R_TEMP;
int gol[XRES][YRES];
for(i = 0; i<NPART; i++) {
#ifdef OpenGL
if(cmode == 6) //If fire mode
@ -1559,7 +1582,8 @@ void draw_parts(pixel *vid)
blendpixel(vid, nx-1, ny-1, cr, cg, cb, 32);
}
}
else if(t==PT_SWCH && parts[i].life == 10)
//Life can be 11 too, so don't just check for 10
else if(t==PT_SWCH && parts[i].life >= 10)
{
x = nx;
y = ny;

View File

@ -33,6 +33,7 @@ int svf_myvote = 0;
int svf_publish = 0;
char svf_id[16] = "";
char svf_name[64] = "";
char svf_description[255] = "";
char svf_tags[256] = "";
void *svf_last = NULL;
int svf_lsize;
@ -227,7 +228,7 @@ void add_sign_ui(pixel *vid_buf, int mx, int my)
//TODO: Finish text wrapping in text edits
void ui_edit_draw(pixel *vid_buf, ui_edit *ed)
{
int cx, i;
int cx, i, cy;
char echo[256], *str;
if(ed->hide)
@ -254,9 +255,15 @@ void ui_edit_draw(pixel *vid_buf, ui_edit *ed)
drawtext(vid_buf, ed->x, ed->y, ed->def, 128, 128, 128, 255);
if(ed->focus)
{
cx = textnwidth(str, ed->cursor);
if(ed->multiline){
textnpos(str, ed->cursor, ed->w-14, &cx, &cy);
} else {
cx = textnwidth(str, ed->cursor);
cy = 0;
}
for(i=-3; i<9; i++)
drawpixel(vid_buf, ed->x+cx, ed->y+i, 255, 255, 255, 255);
drawpixel(vid_buf, ed->x+cx, ed->y+i+cy, 255, 255, 255, 255);
}
}
@ -290,7 +297,7 @@ void ui_edit_process(int mx, int my, int mb, ui_edit *ed)
else if(mx>=ed->x-ed->nx && mx<ed->x+ed->w && my>=ed->y-5 && my<ed->y+ed->h)
{
ed->focus = 1;
ed->cursor = textwidthx(str, mx-ed->x);
ed->cursor = textposxy(str, ed->w-14, mx-ed->x, my-ed->y);
}
else
ed->focus = 0;
@ -1137,9 +1144,10 @@ finish:
int save_name_ui(pixel *vid_buf)
{
int x0=(XRES-192)/2,y0=(YRES-68-YRES/4)/2,b=1,bq,mx,my,ths,nd=0;
int x0=(XRES-420)/2,y0=(YRES-68-YRES/4)/2,b=1,bq,mx,my,ths,nd=0;
void *th;
ui_edit ed;
ui_edit ed2;
ui_checkbox cb;
th = build_thumb(&ths, 0);
@ -1161,6 +1169,18 @@ int save_name_ui(pixel *vid_buf)
ed.cursor = strlen(svf_name);
ed.multiline = 0;
strcpy(ed.str, svf_name);
ed2.x = x0+13;
ed2.y = y0+45;
ed2.w = 166;
ed2.h = 85;
ed2.nx = 1;
ed2.def = "[simulation description]";
ed2.focus = 0;
ed2.hide = 0;
ed2.cursor = strlen(svf_description);
ed2.multiline = 1;
strcpy(ed2.str, svf_description);
cb.x = x0+10;
cb.y = y0+53+YRES/4;
@ -1175,26 +1195,32 @@ int save_name_ui(pixel *vid_buf)
mx /= sdl_scale;
my /= sdl_scale;
drawrect(vid_buf, x0, y0, 192, 90+YRES/4, 192, 192, 192, 255);
clearrect(vid_buf, x0, y0, 192, 90+YRES/4);
drawrect(vid_buf, x0, y0, 420, 90+YRES/4, 192, 192, 192, 255);
clearrect(vid_buf, x0, y0, 420, 90+YRES/4);
drawtext(vid_buf, x0+8, y0+8, "New simulation name:", 255, 255, 255, 255);
drawtext(vid_buf, x0+10, y0+23, "\x82", 192, 192, 192, 255);
drawrect(vid_buf, x0+8, y0+20, 176, 16, 192, 192, 192, 255);
drawrect(vid_buf, x0+8, y0+40, 176, 95, 192, 192, 192, 255);
ui_edit_draw(vid_buf, &ed);
ui_edit_draw(vid_buf, &ed2);
drawrect(vid_buf, x0+(192-XRES/4)/2-2, y0+42, XRES/4+3, YRES/4+3, 128, 128, 128, 255);
render_thumb(th, ths, 0, vid_buf, x0+(192-XRES/4)/2, y0+44, 4);
drawrect(vid_buf, x0+(205-XRES/3)/2-2+205, y0+30, XRES/3+3, YRES/3+3, 128, 128, 128, 255);
render_thumb(th, ths, 0, vid_buf, x0+(205-XRES/3)/2+205, y0+32, 3);
ui_checkbox_draw(vid_buf, &cb);
drawtext(vid_buf, x0+34, y0+50+YRES/4, "Publish? (Do not publish others'\nworks without permission)", 192, 192, 192, 255);
drawtext(vid_buf, x0+5, y0+79+YRES/4, "Save simulation", 255, 255, 255, 255);
drawrect(vid_buf, x0, y0+74+YRES/4, 192, 16, 192, 192, 192, 255);
draw_line(vid_buf, x0+192, y0, x0+192, y0+90+YRES/4, 150, 150, 150, XRES+BARSIZE);
sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
ui_edit_process(mx, my, b, &ed);
ui_edit_process(mx, my, b, &ed2);
ui_checkbox_process(mx, my, b, bq, &cb);
if(b && !bq && ((mx>=x0+9 && mx<x0+23 && my>=y0+22 && my<y0+36) ||
@ -1206,6 +1232,8 @@ int save_name_ui(pixel *vid_buf)
nd = strcmp(svf_name, ed.str) || !svf_own;
strncpy(svf_name, ed.str, 63);
svf_name[63] = 0;
strncpy(svf_description, ed2.str, 254);
svf_description[254] = 0;
if(nd)
{
strcpy(svf_id, "");
@ -1225,6 +1253,8 @@ int save_name_ui(pixel *vid_buf)
nd = strcmp(svf_name, ed.str) || !svf_own;
strncpy(svf_name, ed.str, 63);
svf_name[63] = 0;
strncpy(svf_description, ed2.str, 254);
svf_description[254] = 0;
if(nd)
{
strcpy(svf_id, "");
@ -2278,128 +2308,6 @@ int search_ui(pixel *vid_buf)
if(open_ui(vid_buf, search_ids[mp], search_dates[mp]?search_dates[mp]:NULL)==1) {
goto finish;
}
/*
fillrect(vid_buf, 0, 0, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 255);
info_box(vid_buf, "Loading...");
if(search_dates[mp]) {
uri = malloc(strlen(search_ids[mp])*3+strlen(search_dates[mp])*3+strlen(SERVER)+71);
strcpy(uri, "http://" SERVER "/Get.api?Op=save&ID=");
strcaturl(uri, search_ids[mp]);
strappend(uri, "&Date=");
strcaturl(uri, search_dates[mp]);
} else {
uri = malloc(strlen(search_ids[mp])*3+strlen(SERVER)+64);
strcpy(uri, "http://" SERVER "/Get.api?Op=save&ID=");
strcaturl(uri, search_ids[mp]);
}
data = http_simple_get(uri, &status, &dlen);
free(uri);
if(status == 200)
{
status = parse_save(data, dlen, 1, 0, 0);
switch(status)
{
case 1:
error_ui(vid_buf, 0, "Simulation corrupted");
break;
case 2:
error_ui(vid_buf, 0, "Simulation from a newer version");
break;
case 3:
error_ui(vid_buf, 0, "Simulation on a too large grid");
break;
}
if(!status)
{
char *tnames[] = {"ID", NULL};
char *tparts[1];
int tplens[1];
if(svf_last)
free(svf_last);
svf_last = data;
svf_lsize = dlen;
tparts[0] = search_ids[mp];
tplens[0] = strlen(search_ids[mp]);
data = http_multipart_post("http://" SERVER "/Tags.api", tnames, tparts, tplens, svf_user, svf_pass, &status, NULL);
svf_open = 1;
svf_own = svf_login && !strcmp(search_owners[mp], svf_user);
svf_publish = search_publish[mp] && svf_login && !strcmp(search_owners[mp], svf_user);
strcpy(svf_id, search_ids[mp]);
strcpy(svf_name, search_names[mp]);
if(status == 200)
{
if(data)
{
strncpy(svf_tags, data, 255);
svf_tags[255] = 0;
}
else
svf_tags[0] = 0;
}
else
{
svf_tags[0] = 0;
}
if(svf_login)
{
char *names[] = {"ID", NULL};
char *parts[1];
parts[0] = search_ids[mp];
data = http_multipart_post("http://" SERVER "/Vote.api", names, parts, NULL, svf_user, svf_pass, &status, NULL);
if(status == 200)
{
if(data)
{
if(!strcmp(data, "Up"))
{
svf_myvote = 1;
}
else if(!strcmp(data, "Down"))
{
svf_myvote = -1;
}
else
{
svf_myvote = 0;
}
}
else
{
svf_myvote = 0;
}
}
else
{
svf_myvote = 0;
}
}
}
else
{
svf_open = 0;
svf_publish = 0;
svf_own = 0;
svf_myvote = 0;
svf_id[0] = 0;
svf_name[0] = 0;
svf_tags[0] = 0;
if(svf_last)
free(svf_last);
svf_last = NULL;
}
}
else
error_ui(vid_buf, status, http_ret_text(status));
if(data)
free(data);
goto finish;*/
}
if(!last)
@ -2600,10 +2508,75 @@ finish:
return 0;
}
int report_ui(pixel* vid_buf, char *save_id)
{
int b=1,bq,mx,my;
ui_edit ed;
ed.x = 209;
ed.y = 159;
ed.w = (XRES+BARSIZE-400)-18;
ed.h = (YRES+MENUSIZE-300)-36;
ed.nx = 1;
ed.def = "Report details";
ed.focus = 0;
ed.hide = 0;
ed.multiline = 1;
ed.cursor = 0;
strcpy(ed.str, "");
fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
while(!sdl_poll())
{
b = SDL_GetMouseState(&mx, &my);
if(!b)
break;
}
while(!sdl_poll()){
fillrect(vid_buf, 200, 150, (XRES+BARSIZE-400), (YRES+MENUSIZE-300), 0,0,0, 255);
drawrect(vid_buf, 200, 150, (XRES+BARSIZE-400), (YRES+MENUSIZE-300), 255, 255, 255, 255);
drawrect(vid_buf, 205, 155, (XRES+BARSIZE-400)-10, (YRES+MENUSIZE-300)-28, 255, 255, 255, 170);
bq = b;
b = SDL_GetMouseState(&mx, &my);
mx /= sdl_scale;
my /= sdl_scale;
drawrect(vid_buf, 200, (YRES+MENUSIZE-150)-18, 50, 18, 255, 255, 255, 255);
drawtext(vid_buf, 213, (YRES+MENUSIZE-150)-13, "Cancel", 255, 255, 255, 255);
drawrect(vid_buf, (XRES+BARSIZE-400)+150, (YRES+MENUSIZE-150)-18, 50, 18, 255, 255, 255, 255);
drawtext(vid_buf, (XRES+BARSIZE-400)+163, (YRES+MENUSIZE-150)-13, "Report", 255, 255, 255, 255);
if(mx>(XRES+BARSIZE-400)+150 && my>(YRES+MENUSIZE-150)-18 && mx<(XRES+BARSIZE-400)+200 && my<(YRES+MENUSIZE-150)){
fillrect(vid_buf, (XRES+BARSIZE-400)+150, (YRES+MENUSIZE-150)-18, 50, 18, 255, 255, 255, 40);
if(b){
if(execute_report(vid_buf, save_id, ed.str)){
info_ui(vid_buf, "Success", "This save has been reported");
return 1;
} else {
return 0;
}
}
}
if(mx>200 && my>(YRES+MENUSIZE-150)-18 && mx<250 && my<(YRES+MENUSIZE-150)){
fillrect(vid_buf, 200, (YRES+MENUSIZE-150)-18, 50, 18, 255, 255, 255, 40);
if(b)
return 0;
}
ui_edit_draw(vid_buf, &ed);
sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
ui_edit_process(mx, my, b, &ed);
}
return 0;
}
int open_ui(pixel *vid_buf, char *save_id, char *save_date)
{
int b=1,bq,mx,my,ca=0,thumb_w,thumb_h,active=0,active_2=0,cc=0,ccy=0,cix=0,hasdrawninfo=0,hasdrawnthumb=0,authoritah=0,myown=0,queue_open=0,data_size=0,retval=0,bc=255,openable=1;
char *uri, *uri_2, *o_uri;
int nyd,nyu,ry,lv;
char *uri, *uri_2, *o_uri;
void *data, *info_data;
save_info *info = malloc(sizeof(save_info));
void *http = NULL, *http_2 = NULL;
@ -2727,13 +2700,44 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
}
if(info_ready && !hasdrawninfo) {
//drawtext(vid_buf, 2, 2, info->name, 255, 255, 255, 255);
//Render all the save information
cix = drawtext(vid_buf, 60, (YRES/2)+60, info->name, 255, 255, 255, 255);
cix = drawtext(vid_buf, 60, (YRES/2)+72, "Author:", 255, 255, 255, 155);
cix = drawtext(vid_buf, cix+4, (YRES/2)+72, info->author, 255, 255, 255, 255);
cix = drawtext(vid_buf, cix+4, (YRES/2)+72, "Date:", 255, 255, 255, 155);
cix = drawtext(vid_buf, cix+4, (YRES/2)+72, info->date, 255, 255, 255, 255);
drawtextwrap(vid_buf, 62, (YRES/2)+86, (XRES/2)-24, info->description, 255, 255, 255, 200);
//Draw the score bars
if(info->voteup>0||info->votedown>0)
{
lv = (info->voteup>info->votedown?info->voteup:info->votedown);
if(50>lv)
{
ry = ((float)(50)/(float)lv);
if(lv<8)
{
ry = ry/(8-lv);
}
nyu = info->voteup*ry;
nyd = info->votedown*ry;
}
else
{
ry = ((float)lv/(float)(50));
nyu = info->voteup/ry;
nyd = info->votedown/ry;
}
fillrect(vid_buf, 46+(XRES/2)-51, (YRES/2)+53, 54, 6, 0, 107, 10, 255);
fillrect(vid_buf, 46+(XRES/2)-51, (YRES/2)+59, 54, 6, 107, 10, 0, 255);
drawrect(vid_buf, 46+(XRES/2)-51, (YRES/2)+53, 54, 6, 128, 128, 128, 255);
drawrect(vid_buf, 46+(XRES/2)-51, (YRES/2)+59, 54, 6, 128, 128, 128, 255);
fillrect(vid_buf, 48+(XRES/2)-nyu, (YRES/2)+54, nyu, 4, 57, 187, 57, 255);
fillrect(vid_buf, 48+(XRES/2)-nyd, (YRES/2)+60, nyd, 4, 187, 57, 57, 255);
}
ccy = 0;
for(cc=0; cc<info->comment_count; cc++) {
@ -2749,7 +2753,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
memcpy(old_vid, vid_buf, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
}
if(info_ready && svf_login){
//Render the comment box.
fillrect(vid_buf, 50+(XRES/2)+1, YRES+MENUSIZE-125, XRES+BARSIZE-100-((XRES/2)+1), 75, 0, 0, 0, 255);
drawrect(vid_buf, 50+(XRES/2)+1, YRES+MENUSIZE-125, XRES+BARSIZE-100-((XRES/2)+1), 75, 200, 200, 200, 255);
@ -2761,55 +2765,8 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
drawtext(vid_buf, XRES+BARSIZE-90, YRES+MENUSIZE-63, "Submit", 255, 255, 255, 255);
}
if(queue_open) {
if(info_ready && data_ready) {
// Do Open!
status = parse_save(data, data_size, 1, 0, 0);
if(!status) {
//if(svf_last)
//free(svf_last);
svf_last = data;
svf_lsize = data_size;
svf_open = 1;
svf_own = svf_login && !strcmp(info->author, svf_user);
svf_publish = info->publish && svf_login && !strcmp(info->author, svf_user);
strcpy(svf_id, save_id);
strcpy(svf_name, info->name);
if(info->tags)
{
strncpy(svf_tags, info->tags, 255);
svf_tags[255] = 0;
} else {
svf_tags[0] = 0;
}
svf_myvote = info->myvote;
retval = 1;
break;
} else {
queue_open = 0;
svf_open = 0;
svf_publish = 0;
svf_own = 0;
svf_myvote = 0;
svf_id[0] = 0;
svf_name[0] = 0;
svf_tags[0] = 0;
if(svf_last)
free(svf_last);
svf_last = NULL;
error_ui(vid_buf, 0, "An Error Occurred");
}
} else {
fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 190);
drawtext(vid_buf, XRES+BARSIZE/2, XRES+MENUSIZE, "Loading...", 0, 0, 0, 200);
}
}
//Open Button
bc = openable?255:150;
bc = openable?255:150;
drawrect(vid_buf, 50, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, bc);
drawtext(vid_buf, 73, YRES+MENUSIZE-63, "Open", 255, 255, 255, bc);
drawtext(vid_buf, 58, YRES+MENUSIZE-64, "\x81", 255, 255, 255, bc);
@ -2824,55 +2781,50 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
drawtext(vid_buf, 168, YRES+MENUSIZE-63, "Report", 255, 255, 255, bc);
drawtext(vid_buf, 158, YRES+MENUSIZE-63, "!", 255, 255, 255, bc);
//Delete Button
bc = authoritah?255:150;
drawrect(vid_buf, 200, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, bc);
drawtext(vid_buf, 218, YRES+MENUSIZE-63, "Delete", 255, 255, 255, bc);
drawtext(vid_buf, 206, YRES+MENUSIZE-64, "\xAA", 255, 255, 255, bc);
//Open in browser button
bc = 255;
bc = authoritah?255:150;
drawrect(vid_buf, 200, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, bc);
drawtext(vid_buf, 218, YRES+MENUSIZE-63, "Delete", 255, 255, 255, bc);
drawtext(vid_buf, 206, YRES+MENUSIZE-64, "\xAA", 255, 255, 255, bc);
//Open in browser button
bc = 255;
drawrect(vid_buf, 250, YRES+MENUSIZE-68, 107, 18, 255, 255, 255, bc);
drawtext(vid_buf, 273, YRES+MENUSIZE-63, "Open in Browser", 255, 255, 255, bc);
drawtext(vid_buf, 258, YRES+MENUSIZE-64, "\x81", 255, 255, 255, bc);
//Open Button
if(sdl_key==SDLK_RETURN && openable) {
//Open Button
if(sdl_key==SDLK_RETURN && openable) {
queue_open = 1;
}
if(mx > 50 && mx < 50+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && openable) {
if(mx > 50 && mx < 50+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && openable && !queue_open) {
fillrect(vid_buf, 50, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
if(b && !bq) {
//Button Clicked
//Button Clicked
queue_open = 1;
}
}
//Fav Button
if(mx > 100 && mx < 100+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login) {
//Fav Button
if(mx > 100 && mx < 100+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login && !queue_open) {
fillrect(vid_buf, 100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
if(b && !bq) {
if(b && !bq) {
//Button Clicked
fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
info_box(vid_buf, "Adding to favourites...");
execute_fav(vid_buf, save_id);
fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
info_box(vid_buf, "Adding to favourites...");
execute_fav(vid_buf, save_id);
}
}
//Report Button
if(mx > 150 && mx < 150+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login && info_ready) {
fillrect(vid_buf, 150, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
}
//Report Button
if(mx > 150 && mx < 150+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login && info_ready && !queue_open) {
fillrect(vid_buf, 150, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
if(b && !bq) {
//Button Clicked
if(confirm_ui(vid_buf, "Are you sure?", "Are you sure you wish to report this save?", "Report")){
fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 192);
info_box(vid_buf, "Reporting...");
if(execute_report(vid_buf, save_id)){
info_ui(vid_buf, "Success", "This save has been reported");
retval = 0;
break;
}
if(report_ui(vid_buf, save_id)){
retval = 0;
break;
}
}
}
//Delete Button
if(mx > 200 && mx < 200+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && (authoritah || myown)) {
if(mx > 200 && mx < 200+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && (authoritah || myown) && !queue_open) {
fillrect(vid_buf, 200, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
if(b && !bq) {
//Button Clicked
@ -2898,7 +2850,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
}
}
//Open in browser button
if(mx > 250 && mx < 250+107 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50) {
if(mx > 250 && mx < 250+107 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && !queue_open) {
fillrect(vid_buf, 250, YRES+MENUSIZE-68, 107, 18, 255, 255, 255, 40);
if(b && !bq) {
//Button Clicked
@ -2911,7 +2863,7 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
}
}
//Submit Button
if(mx > XRES+BARSIZE-100 && mx < XRES+BARSIZE-100+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login && info_ready) {
if(mx > XRES+BARSIZE-100 && mx < XRES+BARSIZE-100+50 && my > YRES+MENUSIZE-68 && my < YRES+MENUSIZE-50 && svf_login && info_ready && !queue_open) {
fillrect(vid_buf, XRES+BARSIZE-100, YRES+MENUSIZE-68, 50, 18, 255, 255, 255, 40);
if(b && !bq) {
//Button Clicked
@ -2921,18 +2873,86 @@ int open_ui(pixel *vid_buf, char *save_id, char *save_date)
}
}
if(!(mx>50 && my>50 && mx<XRES+BARSIZE-50 && my<XRES+MENUSIZE-50) && b && !queue_open){
retval = 0;
break;
}
if(queue_open) {
if(info_ready && data_ready) {
// Do Open!
status = parse_save(data, data_size, 1, 0, 0);
if(!status) {
//if(svf_last)
//free(svf_last);
svf_last = data;
svf_lsize = data_size;
svf_open = 1;
svf_own = svf_login && !strcmp(info->author, svf_user);
svf_publish = info->publish && svf_login && !strcmp(info->author, svf_user);
strcpy(svf_id, save_id);
strcpy(svf_name, info->name);
strcpy(svf_description, info->description);
if(info->tags)
{
strncpy(svf_tags, info->tags, 255);
svf_tags[255] = 0;
} else {
svf_tags[0] = 0;
}
svf_myvote = info->myvote;
retval = 1;
break;
} else {
queue_open = 0;
svf_open = 0;
svf_publish = 0;
svf_own = 0;
svf_myvote = 0;
svf_id[0] = 0;
svf_name[0] = 0;
svf_description[0] = 0;
svf_tags[0] = 0;
if(svf_last)
free(svf_last);
svf_last = NULL;
error_ui(vid_buf, 0, "An Error Occurred");
}
} else {
fillrect(vid_buf, -1, -1, XRES+BARSIZE, YRES+MENUSIZE, 0, 0, 0, 190);
drawtext(vid_buf, 50+(XRES/4)-textwidth("Loading...")/2, 50+(YRES/4), "Loading...", 255, 255, 255, 128);
}
}
sdl_blit(0, 0, (XRES+BARSIZE), YRES+MENUSIZE, vid_buf, (XRES+BARSIZE));
memcpy(vid_buf, old_vid, ((XRES+BARSIZE)*(YRES+MENUSIZE))*PIXELSIZE);
if(info_ready && svf_login){
ui_edit_process(mx, my, b, &ed);
}
if(sdl_key==SDLK_ESCAPE)
if(sdl_key==SDLK_ESCAPE){
retval = 0;
break;
}
if(lasttime<TIMEOUT)
lasttime++;
}
//Prevent those mouse clicks being passed down.
while(!sdl_poll())
{
b = SDL_GetMouseState(&mx, &my);
if(!b)
break;
}
//Close open connections
if(http)
http_async_req_close(http);
if(http_2)
http_async_req_close(http_2);
return retval;
}
@ -3372,24 +3392,26 @@ void execute_save(pixel *vid_buf)
int status;
char *result;
char *names[] = {"Name", "Data:save.bin", "Thumb:thumb.bin", "Publish", "ID", NULL};
char *parts[5];
int plens[5];
char *names[] = {"Name","Description", "Data:save.bin", "Thumb:thumb.bin", "Publish", "ID", NULL};
char *parts[6];
int plens[6];
parts[0] = svf_name;
plens[0] = strlen(svf_name);
parts[1] = build_save(plens+1, 0, 0, XRES, YRES);
parts[2] = build_thumb(plens+2, 1);
parts[3] = (svf_publish==1)?"Public":"Private";
plens[3] = strlen((svf_publish==1)?"Public":"Private");
parts[1] = svf_description;
plens[1] = strlen(svf_description);
parts[2] = build_save(plens+2, 0, 0, XRES, YRES);
parts[3] = build_thumb(plens+3, 1);
parts[4] = (svf_publish==1)?"Public":"Private";
plens[4] = strlen((svf_publish==1)?"Public":"Private");
if(svf_id[0])
{
parts[4] = svf_id;
plens[4] = strlen(svf_id);
parts[5] = svf_id;
plens[5] = strlen(svf_id);
}
else
names[4] = NULL;
names[5] = NULL;
result = http_multipart_post(
"http://" SERVER "/Save.api",
@ -3399,10 +3421,10 @@ void execute_save(pixel *vid_buf)
if(svf_last)
free(svf_last);
svf_last = parts[1];
svf_lsize = plens[1];
svf_last = parts[2];
svf_lsize = plens[2];
free(parts[2]);
free(parts[3]);
if(status!=200)
{
@ -3508,15 +3530,16 @@ void execute_submit(pixel *vid_buf, char *id, char *message)
free(result);
}
int execute_report(pixel *vid_buf, char *id)
int execute_report(pixel *vid_buf, char *id, char *reason)
{
int status;
char *result;
char *names[] = {"ID", NULL};
char *parts[1];
char *names[] = {"ID", "Reason", NULL};
char *parts[2];
parts[0] = id;
parts[1] = reason;
result = http_multipart_post(
"http://" SERVER "/Report.api",
@ -3616,11 +3639,25 @@ void open_link(char *uri){
#ifdef WIN32
ShellExecute(0, "OPEN", uri, NULL, NULL, 0);
#elif MACOSX
//char *cmd[] = { "open", uri, (char *)0 };
//execvp("open", cmd);
//LSOpenCFURLRef(CFURLCreateWithString(NULL, CFStringCreateWithCString(NULL, uri, 0) ,NULL), NULL); //TODO: Get this crap working
char *cmd = malloc(7+strlen(uri));
strcpy(cmd, "open ");
strappend(cmd, uri);
system(cmd);
#elif LIN32
execvp("xdg-open", uri);
//execlp("xdg-open", "xdg-open", uri, (char *)0);
char *cmd = malloc(11+strlen(uri));
strcpy(cmd, "xdg-open ");
strappend(cmd, uri);
system(cmd);
#elif LIN64
execvp("xdg-open", uri);
//execlp("xdg-open", "xdg-open", uri, (char *)0);
char *cmd = malloc(11+strlen(uri));
strcpy(cmd, "xdg-open ");
strappend(cmd, uri);
system(cmd);
#else
printf("Cannot open browser\n");
#endif

View File

@ -95,13 +95,19 @@ static int eval_move(int pt, int nx, int ny, unsigned *rr)
if(ptypes[pt].falldown!=1 && bmap[ny/CELL][nx/CELL]==10)
return 0;
if(ptypes[pt].properties&TYPE_ENERGY && (r && ((r&0xFF) >= PT_NUM || (ptypes[(r&0xFF)].properties&TYPE_ENERGY))))
if(r && (r&0xFF) < PT_NUM){
//if(ptypes[pt].properties&TYPE_ENERGY && (r && ((r&0xFF) >= PT_NUM || (ptypes[(r&0xFF)].properties&TYPE_ENERGY))))
if(ptypes[pt].properties&TYPE_ENERGY && ptypes[(r&0xFF)].properties&TYPE_ENERGY)
return 2;
if(pt==PT_NEUT && (r && ((r&0xFF) >= PT_NUM || (ptypes[(r&0xFF)].properties&PROP_NEUTPENETRATE))))
//if(pt==PT_NEUT && (r && ((r&0xFF) >= PT_NUM || (ptypes[(r&0xFF)].properties&PROP_NEUTPENETRATE))))
if(pt==PT_NEUT && ptypes[(r&0xFF)].properties&PROP_NEUTPASS)
return 2;
if(pt==PT_NEUT && ptypes[(r&0xFF)].properties&PROP_NEUTPENETRATE)
return 1;
if((r&0xFF)==PT_NEUT && ptypes[pt].properties&PROP_NEUTPENETRATE)
return 0;
}
if (r && ((r&0xFF) >= PT_NUM || (ptypes[pt].weight <= ptypes[(r&0xFF)].weight)))
return 0;
@ -1204,6 +1210,11 @@ void update_particles_i(pixel *vid, int start, int inc)
parts[i].tmp = 0;
parts[i].ctype = PT_BMTL;
}
if(parts[i].ctype==PT_PLUT)
{
parts[i].tmp = 0;
parts[i].ctype = PT_LAVA;
}
t = parts[i].type = parts[i].ctype;
parts[i].ctype = PT_NONE;
}
@ -1271,6 +1282,11 @@ void update_particles_i(pixel *vid, int start, int inc)
parts[i].tmp--;
parts[i].temp = 3500;
}
if(parts[i].ctype==PT_PLUT&&parts[i].tmp>0)
{
parts[i].tmp--;
parts[i].temp = MAX_TEMP;
}
}
pt = parts[i].temp = restrict_flt(parts[i].temp, MIN_TEMP, MAX_TEMP);
}
@ -1516,7 +1532,7 @@ void update_particles_i(pixel *vid, int start, int inc)
r = create_part(-1, x, y, PT_PLSM);
if(r!=-1)
parts[r].life = 50;
//goto killed;
goto killed;
} else if (parts[i].life < 40) {
parts[i].life--;
if((rand()%100)==0) {
@ -1533,7 +1549,7 @@ void update_particles_i(pixel *vid, int start, int inc)
//t = PT_NONE;
kill_part(i);
r = create_part(-1, x, y, PT_FSEP);
//goto killed;
goto killed;
}
for(nx=-2; nx<3; nx++)
for(ny=-2; ny<3; ny++)
@ -1559,7 +1575,7 @@ void update_particles_i(pixel *vid, int start, int inc)
r = create_part(-1, x, y, PT_PLSM);
if(r!=-1)
parts[r].life = 50;
//goto killed;
goto killed;
} else if (parts[i].life < 40) {
parts[i].life--;
if((rand()%10)==0) {
@ -1811,7 +1827,12 @@ void update_particles_i(pixel *vid, int start, int inc)
{
if(33>rand()%100)
{
create_part(r>>8, x+nx, y+ny, rand()%2 ? PT_LAVA : PT_URAN);
create_part(r>>8, x+nx, y+ny, rand()%3 ? PT_LAVA : PT_URAN);
parts[r>>8].temp = MAX_TEMP;
if(parts[r>>8].type==PT_LAVA){
parts[r>>8].tmp = 100;
parts[r>>8].ctype = PT_PLUT;
}
}
else
{
@ -2046,14 +2067,15 @@ void update_particles_i(pixel *vid, int start, int inc)
{
parts[i].type = PT_NONE;
kill_part(i);
goto killed;
}
parts[r>>8].life = 0;
parts[r>>8].type = PT_NONE;
kill_part(r>>8);
if(2>(rand()/(RAND_MAX/100)))
create_part(r>>8, x+nx, y+ny, PT_PHOT);
create_part(-1, x+nx, y+ny, PT_PHOT);
pv[y/CELL][x/CELL] -= 5.0f;
continue;
//goto killed;
}
}
}
@ -2111,9 +2133,11 @@ void update_particles_i(pixel *vid, int start, int inc)
}
pv[y/CELL][x/CELL] += 20;
kill_part(i);
goto killed;
} else if(parts[i].tmp>=3) {
if(parts[i].life<=0) {
kill_part(i);
goto killed;
}
}
}
@ -2252,6 +2276,19 @@ void update_particles_i(pixel *vid, int start, int inc)
}
}
}
//Check if there is a SWCH that is currently covered with SPRK
//If so check if the current SPRK is covering a NSCN
//If so turn the SPRK that covers the SWCH back into SWCH and turn it off
if(rt==PT_SPRK && parts[r>>8].ctype == PT_SWCH && t==PT_SPRK)
{
pavg = parts_avg(r>>8, i);
if(parts[i].ctype == PT_NSCN&&pavg != PT_INSL)
{
parts[r>>8].type = PT_SWCH;
parts[r>>8].ctype = PT_NONE;
parts[r>>8].life = 0;
}
}
pavg = parts_avg(i, r>>8);
if(rt==PT_SWCH && t==PT_SPRK)
{
@ -2260,7 +2297,7 @@ void update_particles_i(pixel *vid, int start, int inc)
parts[r>>8].life = 10;
if(parts[i].ctype == PT_NSCN&&pavg != PT_INSL)
parts[r>>8].life = 9;
if(!(parts[i].ctype == PT_PSCN||parts[i].ctype == PT_NSCN)&&parts[r>>8].life == 10&&pavg != PT_INSL)
if(!(parts[i].ctype == PT_PSCN||parts[i].ctype == PT_NSCN)&&parts[r>>8].life >= 10&&pavg != PT_INSL) //Life can be 11 too, so don't just check for 10
{
parts[r>>8].type = PT_SPRK;
parts[r>>8].ctype = PT_SWCH;
@ -2996,7 +3033,7 @@ killed:
kill_part(i);
continue;
}
else if(t==PT_NEUT || t==PT_PHOT)
else if(t==PT_NEUT || t==PT_PHOT) //Seems to break neutrons, sorry Skylark
{
r = pmap[ny][nx];
@ -3032,12 +3069,14 @@ killed:
continue;
}
} else {
kill_part(i);
if(t!=PT_NEUT)
kill_part(i);
continue;
}
if(!parts[i].ctype) {
kill_part(i);
if(t!=PT_NEUT)
kill_part(i);
continue;
}
}