From 5e56850682e033a202f633319c08965b0ed1ac69 Mon Sep 17 00:00:00 2001 From: Philip Date: Thu, 18 Nov 2010 16:23:24 -0500 Subject: [PATCH] Added element replacement ability. hit insert. capslock is shift-alt so you can do lines/boxes with specific element erase. read post for other changes --- includes/defines.h | 1 + includes/powder.h | 4 +- src/graphics.c | 2 +- src/main.c | 11 ++++- src/powder.c | 108 +++++++++++++++++++++++---------------------- 5 files changed, 70 insertions(+), 56 deletions(-) diff --git a/includes/defines.h b/includes/defines.h index 173bc2bbe..e7b9be181 100644 --- a/includes/defines.h +++ b/includes/defines.h @@ -115,6 +115,7 @@ int gol[XRES][YRES]; int gol2[XRES][YRES][NGOL]; int SEC; int SEC2; +int REPLACE_MODE; extern sign signs[MAXSIGNS]; extern stamp stamps[STAMP_MAX]; extern int stamp_count; diff --git a/includes/powder.h b/includes/powder.h index cf92906fd..56381185c 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -255,7 +255,7 @@ static const part_type ptypes[PT_NUM] = {"ACID", PIXPACK(0xED55FF), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 40, 0, 0, 1, 1, 10, SC_LIQUID, R_TEMP+0.0f +273.15f, 34, "Dissolves almost everything.", TYPE_LIQUID}, {"VOID", PIXPACK(0x790B0B), 0.0f, 0.00f * CFDS, 1.00f, 0.00f, 0.0f, 0.0f, 0.00f, -0.0003f* CFDS, 0, 0, 0, 0, 0, 1, 100, SC_SPECIAL, R_TEMP+0.0f +273.15f, 251, "Hole, will drain away any particles.", TYPE_SOLID}, {"WTRV", PIXPACK(0xA0A0FF), 1.0f, 0.01f * CFDS, 0.99f, 0.30f, -0.1f, -0.1f, 0.75f, 0.0003f * CFDS, 0, 0, 0, 0, 4, 1, 1, SC_GAS, R_TEMP+100.0f+273.15f, 48, "Steam, heats up air, produced from hot water.", TYPE_GAS}, - {"CNCT", PIXPACK(0xC0C0C0), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 2, 25, 1, 55, SC_POWDERS, R_TEMP+0.0f +273.15f, 100, "Concrete, stronger than stone.", TYPE_PART}, + {"CNCT", PIXPACK(0xC0C0C0), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 2, 2, 1, 55, SC_POWDERS, R_TEMP+0.0f +273.15f, 100, "Concrete, stronger than stone.", TYPE_PART}, {"DSTW", PIXPACK(0x1020C0), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 30, SC_LIQUID, R_TEMP-2.0f +273.15f, 23, "Distilled water, does not conduct electricity.", TYPE_LIQUID|PROP_NEUTPENETRATE}, {"SALT", PIXPACK(0xFFFFFF), 0.4f, 0.04f * CFDS, 0.94f, 0.95f, -0.1f, 0.3f, 0.00f, 0.000f * CFDS, 1, 0, 0, 5, 1, 1, 75, SC_POWDERS, R_TEMP+0.0f +273.15f, 110, "Salt, dissolves in water.", TYPE_PART}, {"SLTW", PIXPACK(0x4050F0), 0.6f, 0.01f * CFDS, 0.98f, 0.95f, 0.0f, 0.1f, 0.00f, 0.000f * CFDS, 2, 0, 0, 0, 20, 1, 35, SC_LIQUID, R_TEMP+0.0f +273.15f, 75, "Saltwater, conducts electricity, difficult to freeze.", TYPE_LIQUID|PROP_CONDUCTS|PROP_NEUTPENETRATE}, @@ -330,7 +330,7 @@ static const part_type ptypes[PT_NUM] = {"WARP", PIXPACK(0x000000), 0.8f, 0.00f * CFDS, 0.9f, 0.70f, -0.1f, 0.0f, 3.00f, 0.000f * CFDS, 0, 0, 0, 0, 30, 1, 1, SC_GAS, R_TEMP +273.15f, 100, "This is what happens to your mind when catelite descibes an element.",TYPE_GAS}, {"PUMP", PIXPACK(0x9EA3B6), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, 0.1f * CFDS, 0, 7, 0, 0, 10, 1, 100, SC_SPECIAL, 273.15f, 0, "Changes pressure to its temp (use HEAT/COOL).", TYPE_SOLID}, {"FWRK", PIXPACK(0x666666), 0.4f, 0.01f * CFDS, 0.99f, 0.95f, 0.0f, 0.4f, 0.00f, 0.000f * CFDS, 1, 0, 0, 0, 0, 1, 97, SC_EXPLOSIVE, R_TEMP+0.0f+273.15f, 100, "First fireworks made, activated by heat/neutrons."}, - {"PIPE", PIXPACK(0x444444), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_SPECIAL, 273.15f, 0, "probably doesn't work", TYPE_SOLID}, + {"PIPE", PIXPACK(0x444444), 0.0f, 0.00f * CFDS, 0.95f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 0, 0, 1, 100, SC_SPECIAL, 273.15f, 0, "Moves elements around, read the post on how to use.", TYPE_SOLID}, //Name Colour Advec Airdrag Airloss Loss Collid Grav Diffus Hotair Fal Burn Exp Mel Hrd M Weights Section H Ins(real world, by triclops200) Description }; diff --git a/src/graphics.c b/src/graphics.c index 1f8ef9176..c58d4f260 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -1391,7 +1391,7 @@ void draw_parts(pixel *vid) isplayer = 1; //It's a secret. Tssss... } - if(cmode==CM_NOTHING)//nothing display + if(cmode==CM_NOTHING && t!=PT_PIPE && t!=PT_SWCH && t!=PT_LCRY)//nothing display but show needed color changes { cr = PIXR(ptypes[t].pcolors); cg = PIXG(ptypes[t].pcolors); diff --git a/src/main.c b/src/main.c index 506e97621..17ccbab3e 100644 --- a/src/main.c +++ b/src/main.c @@ -1320,6 +1320,8 @@ int main(int argc, char *argv[]) bs = 0; } } + if(sdl_key==SDLK_INSERT) + REPLACE_MODE = !REPLACE_MODE; if(sdl_key==SDLK_SPACE) sys_pause = !sys_pause; if(sdl_key=='h') @@ -1863,6 +1865,8 @@ int main(int argc, char *argv[]) } else if((sdl_mod & (KMOD_LCTRL|KMOD_RCTRL)) && (sdl_mod & (KMOD_LSHIFT|KMOD_RSHIFT)) && !(sdl_mod & (KMOD_LALT))) { + if(sdl_mod & (KMOD_CAPS)) + c = 0; if(c!=125&&c!=SPC_AIR&&c!=SPC_HEAT&&c!=SPC_COOL&&c!=SPC_VACUUM) flood_parts(x, y, c, -1, -1); lx = x; @@ -2070,7 +2074,12 @@ int main(int argc, char *argv[]) if(currentTime-pastFPS>=1000) { #ifdef BETA - sprintf(uitext, "Cracker's Version %d (Beta %d) FPS:%d", SAVE_VERSION, MINOR_VERSION, FPS); + if(REPLACE_MODE) + sprintf(uitext, "Cracker's Version %d FPS:%d REPLACE MODE", SAVE_VERSION,FPS); + else if(sdl_mod&(KMOD_CAPS)) + sprintf(uitext, "Cracker's Version %d FPS:%d CAPS LOCK ON", SAVE_VERSION, FPS); + else + sprintf(uitext, "Cracker's Version %d (Beta %d) FPS:%d", SAVE_VERSION, MINOR_VERSION, FPS); //printf("%s\n", uitext); #else sprintf(uitext, "Version %d.%d FPS:%d", SAVE_VERSION, MINOR_VERSION, FPS); diff --git a/src/powder.c b/src/powder.c index eee2bace3..2adf88067 100644 --- a/src/powder.c +++ b/src/powder.c @@ -499,7 +499,7 @@ inline int create_part(int p, int x, int y, int t) parts[i].tmp = 50; } if(t==PT_PIPE) - parts[i].life = 100; + parts[i].life = 60; if(t==PT_BCOL) parts[i].life = 110; if(t==PT_FIRE) @@ -1196,8 +1196,10 @@ void update_particles_i(pixel *vid, int start, int inc) t = parts[i].type = PT_BRMT; if(t==PT_BMTL && pv[y/CELL][x/CELL]>1.0f && parts[i].tmp==1) t = parts[i].type = PT_BRMT; - if(t==PT_BRCK && pv[y/CELL][x/CELL]>2.8f) + if(t==PT_BRCK && pv[y/CELL][x/CELL]>8.8f) t = parts[i].type = PT_STNE; + if(t==PT_PIPE && pv[y/CELL][x/CELL]>10.0f) + t = parts[i].type = PT_BRMT; //if(t==PT_GLAS && pv[y/CELL][x/CELL]>4.0f) // t = parts[i].type = PT_BGLA; if(t==PT_GLAS) @@ -1803,6 +1805,8 @@ void update_particles_i(pixel *vid, int start, int inc) { parts[r>>8].type = PT_SLTW; } + if((r&0xFF)==PT_PLNT&&5>(rand()%1000)) + parts[r>>8].type = PT_NONE; if(((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && pt>12.0f && 1>(rand()%500)) { parts[i].life = 4; @@ -2136,21 +2140,21 @@ void update_particles_i(pixel *vid, int start, int inc) maxlife ++; if(parts[i].life < maxlife) { - for(nx=-1; nx<2; nx++) - for(ny=-1; ny<2; ny++) - if(x+nx>=0 && y+ny>0 && x+nx>8)>=NPART || !r || (parts[i].life >=maxlife)) - continue; - if(parts[r>>8].type==PT_WTF&&33>=rand()/(RAND_MAX/100)+1) + for(nx=-1; nx<2; nx++) + for(ny=-1; ny<2; ny++) + if(x+nx>=0 && y+ny>0 && x+nx>8)>=NPART || !r || (parts[i].life >=maxlife)) + continue; + if(parts[r>>8].type==PT_WTF&&33>=rand()/(RAND_MAX/100)+1) + { + if((parts[i].life + parts[r>>8].life + 1) <= maxlife) { - if((parts[i].life + parts[r>>8].life + 1) <= maxlife) - { - parts[i].life += parts[r>>8].life + 1; - parts[r>>8].type=PT_NONE; - } - } + parts[i].life += parts[r>>8].life + 1; + parts[r>>8].type=PT_NONE; + } + } } } else @@ -2168,33 +2172,33 @@ void update_particles_i(pixel *vid, int start, int inc) { create_part(-1,x+nx,y+ny,PT_WTF); parts[i].life--; - parts[pmap[y+ny][x+nx]>>8].temp = parts[i].temp; + parts[pmap[y+ny][x+nx]>>8].temp = parts[i].temp; } - } + } for(int trade = 0; trade<4;trade ++) { - nx = rand()%5-2; - ny = rand()%5-2; - if(x+nx>=0 && y+ny>0 && x+nx>8)>=NPART || !r) - continue; - if(parts[r>>8].type==t&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0&&!((r>>8)>=NPART || !r))//diffusion - { - int temp = parts[i].life - parts[r>>8].life; - if(temp ==1) + nx = rand()%5-2; + ny = rand()%5-2; + if(x+nx>=0 && y+ny>0 && x+nx>8)>=NPART || !r) + continue; + if(parts[r>>8].type==t&&(parts[i].life>parts[r>>8].life)&&parts[i].life>0&&!((r>>8)>=NPART || !r))//diffusion { - parts[r>>8].life ++; - parts[i].life --; - } - else if(temp>0) - { - parts[r>>8].life += temp/2; - parts[i].life -= temp/2; + int temp = parts[i].life - parts[r>>8].life; + if(temp ==1) + { + parts[r>>8].life ++; + parts[i].life --; + } + else if(temp>0) + { + parts[r>>8].life += temp/2; + parts[i].life -= temp/2; + } } } - } } } else if(t==PT_WARP) @@ -2226,7 +2230,6 @@ void update_particles_i(pixel *vid, int start, int inc) { if((parts[i].temp>400&&(9+parts[i].temp/40)>rand()%100000&&parts[i].life==0&&!pmap[y-1][x])||parts[i].ctype==PT_DUST) { - create_part(-1, x , y-1 , PT_FWRK); r = pmap[y-1][x]; if(parts[r>>8].type==PT_FWRK) @@ -2312,7 +2315,7 @@ void update_particles_i(pixel *vid, int start, int inc) } else if(t==PT_PIPE) { - if(!parts[i].ctype && parts[i].life<=50) + if(!parts[i].ctype && parts[i].life<=10) { if(parts[i].temp<272.15) { @@ -2342,7 +2345,7 @@ void update_particles_i(pixel *vid, int start, int inc) if((r>>8)>=NPART ) continue; if(!r) - create_part(-1,x+nx,y+ny,PT_DMND); + create_part(-1,x+nx,y+ny,PT_BRCK); } if(parts[i].life==1) parts[i].ctype = 1; @@ -2388,18 +2391,10 @@ void update_particles_i(pixel *vid, int start, int inc) continue; if(parts[r>>8].type==PT_PIPE&&parts[r>>8].ctype==1) { - //parts[r>>8].ctype = (((ctype-1)%3)+2);//forward parts[r>>8].ctype = (((ctype)%3)+2);//reverse parts[r>>8].life = 6; } } - //if(created == 0) - //{ - // parts[i].ctype = (((ctype)%3)+2); - // parts[i].life = 6; //causes trippyness - //} - //else - // parts[i].life = 0; } else { @@ -2418,7 +2413,7 @@ void update_particles_i(pixel *vid, int start, int inc) } else if(!r) continue; - else if(parts[r>>8].type!=PT_PIPE && parts[r>>8].type!=PT_DMND && parts[i].tmp == 0 && (ptypes[parts[r>>8].type].falldown!= 0 || pstates[parts[r>>8].type].state == ST_GAS)) + else if(parts[i].tmp == 0 && (ptypes[parts[r>>8].type].falldown!= 0 || pstates[parts[r>>8].type].state == ST_GAS)) { parts[i].tmp = parts[r>>8].type; parts[r>>8].type = PT_NONE; @@ -4193,7 +4188,7 @@ int flood_parts(int x, int y, int c, int cm, int bm) bm = 0; } - if((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm) + if((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm ||( (sdl_mod & (KMOD_CAPS)) && cm!=SLALT)) return 1; // go left as far as possible @@ -4343,7 +4338,7 @@ int create_parts(int x, int y, int r, int c) } return 1; } - if(sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_SHIFT)) + if(((sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_SHIFT))|| sdl_mod & (KMOD_CAPS) )&& !REPLACE_MODE) { for(j=-r; j<=r; j++) for(i=-r; i<=r; i++) @@ -4351,6 +4346,15 @@ int create_parts(int x, int y, int r, int c) delete_part(x+i, y+j); return 1; } + if(REPLACE_MODE) + { + for(j=-r; j<=r; j++) + for(i=-r; i<=r; i++) + if(i*i+j*j<=r*r) + delete_part(x+i, y+j); + if(c==0) + return 1; + } if(c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM) { for(j=-r; j<=r; j++) @@ -4371,7 +4375,7 @@ int create_parts(int x, int y, int r, int c) SLALT = stemp; return 1; } - + for(j=-r; j<=r; j++) for(i=-r; i<=r; i++) if(i*i+j*j<=r*r)