diff options
Diffstat (limited to 'src')
| -rw-r--r-- | src/elements/fwrk.c | 2 | ||||
| -rw-r--r-- | src/elements/sprk.c | 21 | ||||
| -rw-r--r-- | src/main.c | 100 | ||||
| -rw-r--r-- | src/powder.c | 10 |
4 files changed, 62 insertions, 71 deletions
diff --git a/src/elements/fwrk.c b/src/elements/fwrk.c index 06390c5..5095cde 100644 --- a/src/elements/fwrk.c +++ b/src/elements/fwrk.c @@ -16,7 +16,7 @@ int update_FWRK(UPDATE_FUNC_ARGS) { } if (parts[i].life>=45) parts[i].life=0; - if ((parts[i].life<3&&parts[i].life>0)||parts[i].vy>6&&parts[i].life>0) + if ((parts[i].life<3&&parts[i].life>0)||(parts[i].vy>6&&parts[i].life>0)) { int q = (rand()%255+1); int w = (rand()%255+1); diff --git a/src/elements/sprk.c b/src/elements/sprk.c index f107b9a..89480ad 100644 --- a/src/elements/sprk.c +++ b/src/elements/sprk.c @@ -120,7 +120,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) { conduct_sprk = 0; if (ct==PT_NSCN && rt==PT_PSCN) conduct_sprk = 0; - if (ct==PT_ETRD && (parts[i].life!=5||!(rt==PT_METL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN))) + if (ct==PT_ETRD && !(rt==PT_METL||rt==PT_ETRD||rt==PT_BMTL||rt==PT_BRMT||rt==PT_LRBD||rt==PT_RBDM||rt==PT_PSCN||rt==PT_NSCN)) conduct_sprk = 0; if (ct==PT_INST&&rt!=PT_NSCN) conduct_sprk = 0; if (ct==PT_SWCH && (rt==PT_PSCN||rt==PT_NSCN||rt==PT_WATR||rt==PT_SLTW||rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR)) @@ -137,15 +137,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) { conduct_sprk = 0; if (conduct_sprk) { - if (ct==PT_ETRD) { - part_change_type(i,x,y,PT_ETRD); - parts[i].ctype = PT_NONE; - parts[i].life = 20; - part_change_type(r>>8,x+rx,y+ry,PT_SPRK); - parts[r>>8].life = 4; - parts[r>>8].ctype = rt; - } - else if (rt==PT_WATR||rt==PT_SLTW) { + if (rt==PT_WATR||rt==PT_SLTW) { if (parts[r>>8].life==0 && (parts[i].life<2 || ((r>>8)<i && parts[i].life<3))) { part_change_type(r>>8,x+rx,y+ry,PT_SPRK); @@ -167,6 +159,15 @@ int update_SPRK(UPDATE_FUNC_ARGS) { if (parts[r>>8].temp+10.0f<673.0f&&!legacy_enable&&(rt==PT_METL||rt==PT_BMTL||rt==PT_BRMT||rt==PT_PSCN||rt==PT_NSCN||rt==PT_ETRD||rt==PT_NBLE||rt==PT_IRON)) parts[r>>8].temp = parts[r>>8].temp+10.0f; } + else if (ct==PT_ETRD && parts[i].life==5) + { + part_change_type(i,x,y,ct); + parts[i].ctype = PT_NONE; + parts[i].life = 20; + parts[r>>8].life = 4; + parts[r>>8].ctype = rt; + part_change_type(r>>8,x+rx,y+ry,PT_SPRK); + } } } return 0; @@ -550,19 +550,7 @@ int parse_save(void *save, int size, int replace, int x0, int y0) gravityMode = 0; airMode = 0; } - memset(bmap, 0, sizeof(bmap)); - memset(emap, 0, sizeof(emap)); - memset(signs, 0, sizeof(signs)); - memset(parts, 0, sizeof(particle)*NPART); - memset(pmap, 0, sizeof(pmap)); - memset(vx, 0, sizeof(vx)); - memset(vy, 0, sizeof(vy)); - memset(pv, 0, sizeof(pv)); - memset(photons, 0, sizeof(photons)); - memset(wireless, 0, sizeof(wireless)); - memset(gol2, 0, sizeof(gol2)); - memset(portal, 0, sizeof(portal)); - death = death2 = ISSPAWN1 = ISSPAWN2 = 0; + clear_sim(); } // make a catalog of free parts @@ -894,13 +882,35 @@ corrupt: if (replace) { legacy_enable = 0; - memset(signs, 0, sizeof(signs)); - memset(parts, 0, sizeof(particle)*NPART); - memset(bmap, 0, sizeof(bmap)); + clear_sim(); } return 1; } +void clear_sim(void) +{ + memset(bmap, 0, sizeof(bmap)); + memset(emap, 0, sizeof(emap)); + memset(signs, 0, sizeof(signs)); + memset(parts, 0, sizeof(particle)*NPART); + memset(pmap, 0, sizeof(pmap)); + memset(pv, 0, sizeof(pv)); + memset(vx, 0, sizeof(vx)); + memset(vy, 0, sizeof(vy)); + memset(fvx, 0, sizeof(fvx)); + memset(fvy, 0, sizeof(fvy)); + memset(photons, 0, sizeof(photons)); + memset(wireless, 0, sizeof(wireless)); + memset(gol2, 0, sizeof(gol2)); + memset(portal, 0, sizeof(portal)); + death = death2 = ISSPAWN1 = ISSPAWN2 = 0; + memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE); + memset(fire_bg, 0, XRES*YRES*PIXELSIZE); + memset(fire_r, 0, sizeof(fire_r)); + memset(fire_g, 0, sizeof(fire_g)); + memset(fire_b, 0, sizeof(fire_b)); +} + // stamps library stamp stamps[STAMP_MAX];//[STAMP_X*STAMP_Y]; @@ -1185,6 +1195,7 @@ int main(int argc, char *argv[]) int pastFPS = 0; int past = 0; pixel *vid_buf=calloc((XRES+BARSIZE)*(YRES+MENUSIZE), PIXELSIZE); + pers_bg = calloc((XRES+BARSIZE)*YRES, PIXELSIZE); void *http_ver_check; void *http_session_check = NULL; char *ver_data=NULL, *check_data=NULL, *tmp; @@ -1236,8 +1247,7 @@ int main(int argc, char *argv[]) parts[NPART-1].life = -1; pfree = 0; fire_bg=calloc(XRES*YRES, PIXELSIZE); - pers_bg=calloc((XRES+BARSIZE)*YRES, PIXELSIZE); - memset(signs, 0, sizeof(signs)); + clear_sim(); //fbi_img = render_packed_rgb(fbi, FBI_W, FBI_H, FBI_CMP); @@ -1437,8 +1447,8 @@ int main(int argc, char *argv[]) { svf_admin = 0; svf_mod = 1; - } - } + } + } } else { @@ -1523,7 +1533,7 @@ int main(int argc, char *argv[]) free(load_data); } } - if (sdl_key=='s' && (sdl_mod & (KMOD_CTRL)) || (sdl_key=='s' && !isplayer2)) + if ((sdl_key=='s' && (sdl_mod & (KMOD_CTRL))) || (sdl_key=='s' && !isplayer2)) { if (it > 50) it = 50; @@ -1657,7 +1667,7 @@ int main(int argc, char *argv[]) bsy = 0; } } - if (sdl_key=='d'&&(sdl_mod & (KMOD_CTRL)) || (sdl_key=='d' && !isplayer2)) + if ((sdl_key=='d'&&(sdl_mod & (KMOD_CTRL))) || (sdl_key=='d' && !isplayer2)) DEBUG_MODE = !DEBUG_MODE; if (sdl_key=='i') { @@ -2256,19 +2266,7 @@ int main(int argc, char *argv[]) } if (x>=(XRES+BARSIZE-(510-367)) && x<=(XRES+BARSIZE-(510-383)) && !bq) { - memset(signs, 0, sizeof(signs)); - memset(pv, 0, sizeof(pv)); - memset(vx, 0, sizeof(vx)); - memset(vy, 0, sizeof(vy)); - memset(fvx, 0, sizeof(fvx)); - memset(fvy, 0, sizeof(fvy)); - memset(bmap, 0, sizeof(bmap)); - memset(emap, 0, sizeof(emap)); - memset(parts, 0, sizeof(particle)*NPART); - memset(photons, 0, sizeof(photons)); - memset(wireless, 0, sizeof(wireless)); - memset(gol2, 0, sizeof(gol2)); - memset(portal, 0, sizeof(portal)); + clear_sim(); for (i=0; i<NPART-1; i++) parts[i].life = i+1; parts[NPART-1].life = -1; @@ -2285,17 +2283,8 @@ int main(int argc, char *argv[]) svf_description[0] = 0; gravityMode = 0; airMode = 0; - death = death2 = 0; isplayer2 = 0; isplayer = 0; - ISSPAWN1 = 0; - ISSPAWN2 = 0; - - memset(fire_bg, 0, XRES*YRES*PIXELSIZE); - memset(pers_bg, 0, (XRES+BARSIZE)*YRES*PIXELSIZE); - memset(fire_r, 0, sizeof(fire_r)); - memset(fire_g, 0, sizeof(fire_g)); - memset(fire_b, 0, sizeof(fire_b)); } if (x>=(XRES+BARSIZE-(510-385)) && x<=(XRES+BARSIZE-(510-476))) { @@ -2738,7 +2727,7 @@ int main(int argc, char *argv[]) console = console_ui(vid_buf,console_error); console = mystrdup(console); strcpy(console_error,""); - if(process_command(vid_buf,console,&console_error)==-1) + if(process_command(vid_buf,console,console_error)==-1) { free(console); break; @@ -2788,7 +2777,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { { return -1; } - else if(strcmp(console2, "file")==0 && console3) + else if(strcmp(console2, "file")==0) { if(file_script){ FILE *f=fopen(console3, "r"); @@ -2802,8 +2791,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { ny = 0; j = 0; m = 0; - if(console4) - console_parse_coords(console4, &nx , &ny, console_error); + console_parse_coords(console4, &nx , &ny, console_error); memset(pch,0,sizeof(pch)); memset(fileread,0,sizeof(fileread)); fread(fileread,1,5000,f); @@ -2878,12 +2866,12 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { } } - else if(strcmp(console2, "sound")==0 && console3) + else if(strcmp(console2, "sound")==0) { if (sound_enable) play_sound(console3); else strcpy(console_error, "Audio device not available - cannot play sounds"); } - else if(strcmp(console2, "load")==0 && console3) + else if(strcmp(console2, "load")==0) { j = atoi(console3); if(j) @@ -2892,7 +2880,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { console_mode = 0; } } - else if(strcmp(console2, "if")==0 && console3) + else if(strcmp(console2, "if")==0) { if(strcmp(console3, "type")==0)//TODO: add more than just type, and be able to check greater/less than { @@ -2908,7 +2896,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { return 0; } } - else if (strcmp(console2, "create")==0 && console3 && console4) + else if (strcmp(console2, "create")==0) { if (console_parse_type(console3, &j, console_error) && console_parse_coords(console4, &nx, &ny, console_error)) @@ -2919,12 +2907,12 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { strcpy(console_error, "Could not create particle"); } } - else if ((strcmp(console2, "delete")==0 || strcmp(console2, "kill")==0) && console3) + else if (strcmp(console2, "delete")==0 || strcmp(console2, "kill")==0) { if (console_parse_partref(console3, &i, console_error)) kill_part(i); } - else if(strcmp(console2, "reset")==0 && console3) + else if(strcmp(console2, "reset")==0) { if(strcmp(console3, "pressure")==0) { @@ -2965,7 +2953,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { } } } - else if(strcmp(console2, "set")==0 && console3 && console4 && console5) + else if(strcmp(console2, "set")==0) { if(strcmp(console3, "life")==0) { @@ -3230,7 +3218,7 @@ int process_command(pixel *vid_buf,char *console,char *console_error) { } } else - sprintf(console_error, "Invalid Command", console2); + strcpy(console_error, "Invalid Command"); } return 1; } diff --git a/src/powder.c b/src/powder.c index 55c1233..dbbfe0c 100644 --- a/src/powder.c +++ b/src/powder.c @@ -488,7 +488,7 @@ inline int create_n_parts(int n, int x, int y, float vx, float vy, int t) if (x<0 || y<0 || x>=XRES || y>=YRES || t<0 || t>=PT_NUM) return -1; - for (c; c<n; c++) { + for (c=0; c<n; c++) { float r = (rand()%128+128)/127.0f; float a = (rand()%360)*3.14159f/180.0f; if (pfree == -1) @@ -741,7 +741,7 @@ inline int create_part(int p, int x, int y, int t) { if (isplayer==0) { - if (pmap[y][x]&0xFF==PT_SPAWN) + if ((pmap[y][x]&0xFF)==PT_SPAWN) { parts[pmap[y][x]>>8].type = PT_STKM; parts[pmap[y][x]>>8].vx = 0; @@ -799,7 +799,7 @@ inline int create_part(int p, int x, int y, int t) { if (isplayer2==0) { - if (pmap[y][x]&0xFF==PT_SPAWN2) + if ((pmap[y][x]&0xFF)==PT_SPAWN2) { parts[pmap[y][x]>>8].type = PT_STKM2; parts[pmap[y][x]>>8].vx = 0; @@ -1339,7 +1339,7 @@ void update_particles_i(pixel *vid, int start, int inc) { r = pmap[ny][nx]; neighbors = gol2[nx][ny][0]; - if(neighbors==0 || !(ptypes[r&0xFF].properties&PROP_LIFE || !r&0xFF) || (r>>8)>=NPART) + if(neighbors==0 || !(ptypes[r&0xFF].properties&PROP_LIFE || !(r&0xFF)) || (r>>8)>=NPART) continue; for ( golnum = 1; golnum<=NGOL; golnum++) for ( goldelete = 0; goldelete<9; goldelete++) @@ -2939,10 +2939,12 @@ int create_parts(int x, int y, int rx, int ry, int c) for (j=-ry; j<=ry; j++) for (i=-rx; i<=rx; i++) if ((CURRENT_BRUSH==CIRCLE_BRUSH && (pow(i,2))/(pow(rx,2))+(pow(j,2))/(pow(ry,2))<=1)||(CURRENT_BRUSH==SQUARE_BRUSH&&i*j<=ry*rx)) + { if (!REPLACE_MODE) create_part(-2, x+i, y+j, c); else if ((pmap[y+j][x+i]&0xFF)==SLALT&&SLALT!=0) create_part(-2, x+i, y+j, c); + } return 1; } |
