diff options
| author | Simon Robertshaw <simon@hardwired.org.uk> | 2012-03-15 01:52:23 (GMT) |
|---|---|---|
| committer | Simon Robertshaw <simon@hardwired.org.uk> | 2012-03-15 01:52:23 (GMT) |
| commit | 7a454d4d729a5715a7c1e71dfbaf303471bf8d1f (patch) | |
| tree | 234cb5ba80e5227ecc5dc7c7e9b4845444e5f1a9 /src | |
| parent | b4a06df0b2264c690f0161b099c2c5a2c11f8b3b (diff) | |
| parent | bf5484ca63f0ee5165b394f98d91e16089f657a2 (diff) | |
| download | powder-7a454d4d729a5715a7c1e71dfbaf303471bf8d1f.zip powder-7a454d4d729a5715a7c1e71dfbaf303471bf8d1f.tar.gz | |
Merge pull request #57 from jacob1/test
Bug fixes + Some stuff from jacob1's mod
Diffstat (limited to 'src')
| -rw-r--r-- | src/elementdata.c | 4 | ||||
| -rw-r--r-- | src/elements/co2.c | 15 | ||||
| -rw-r--r-- | src/elements/elec.c | 2 | ||||
| -rw-r--r-- | src/elements/h2.c | 56 | ||||
| -rw-r--r-- | src/elements/nble.c | 26 | ||||
| -rw-r--r-- | src/elements/newgraphics.c | 3 | ||||
| -rw-r--r-- | src/elements/prti.c | 4 | ||||
| -rw-r--r-- | src/elements/prto.c | 9 | ||||
| -rw-r--r-- | src/elements/pyro.c | 1 | ||||
| -rw-r--r-- | src/elements/sprk.c | 10 | ||||
| -rw-r--r-- | src/elements/stkm.c | 2 | ||||
| -rw-r--r-- | src/graphics.c | 160 | ||||
| -rw-r--r-- | src/interface.c | 25 | ||||
| -rw-r--r-- | src/luaconsole.c | 8 | ||||
| -rw-r--r-- | src/main.c | 19 | ||||
| -rw-r--r-- | src/powder.c | 236 | ||||
| -rw-r--r-- | src/save.c | 270 |
17 files changed, 502 insertions, 348 deletions
diff --git a/src/elementdata.c b/src/elementdata.c index a64b0b4..5058931 100644 --- a/src/elementdata.c +++ b/src/elementdata.c @@ -62,7 +62,7 @@ part_type ptypes[PT_NUM] = {"PLSM", PIXPACK(0xBB99FF), 0.9f, 0.04f * CFDS, 0.97f, 0.20f, 0.0f, -0.1f, 0.30f, 0.001f * CFDS, 0, 0, 0, 0, 0, 1, 1, 1, SC_GAS, 10000.0f +273.15f, 5, "Plasma, extremely hot.", ST_NONE, TYPE_GAS|PROP_LIFE_DEC|PROP_LIFE_KILL, &update_PYRO, &graphics_PLSM}, {"ETRD", PIXPACK(0x404040), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Electrode. Creates a surface that allows Plasma arcs. (Use sparingly)", ST_NONE, TYPE_SOLID|PROP_CONDUCTS|PROP_LIFE_DEC, NULL, NULL}, {"NICE", PIXPACK(0xC0E0FF), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, -0.0005f* CFDS, 0, 0, 0, 0, 20, 1, 1, 100, SC_SOLIDS, 35.0f, 46, "Nitrogen Ice.", ST_SOLID, TYPE_SOLID, NULL, NULL}, - {"NBLE", PIXPACK(0xEB4917), 1.0f, 0.01f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 0.75f, 0.001f * CFDS, 0, 0, 0, 0, 1, 1, 1, 1, SC_GAS, R_TEMP+2.0f +273.15f, 106, "Noble Gas. Diffuses. Conductive. Ionizes into plasma when introduced to electricity", ST_GAS, TYPE_GAS|PROP_CONDUCTS|PROP_LIFE_DEC, NULL, NULL}, + {"NBLE", PIXPACK(0xEB4917), 1.0f, 0.01f * CFDS, 0.99f, 0.30f, -0.1f, 0.0f, 0.75f, 0.001f * CFDS, 0, 0, 0, 0, 1, 1, 1, 1, SC_GAS, R_TEMP+2.0f +273.15f, 106, "Noble Gas. Diffuses. Conductive. Ionizes into plasma when introduced to electricity", ST_GAS, TYPE_GAS|PROP_CONDUCTS|PROP_LIFE_DEC, &update_NBLE, NULL}, {"BTRY", PIXPACK(0x858505), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_ELEC, R_TEMP+0.0f +273.15f, 251, "Solid. Generates Electricity.", ST_SOLID, TYPE_SOLID, &update_BTRY, NULL}, {"LCRY", PIXPACK(0x505050), 0.0f, 0.00f * CFDS, 0.90f, 0.00f, 0.0f, 0.0f, 0.00f, 0.000f * CFDS, 0, 0, 0, 1, 1, 1, 1, 100, SC_POWERED, R_TEMP+0.0f +273.15f, 251, "Liquid Crystal. Changes colour when charged. (PSCN Charges, NSCN Discharges)", ST_SOLID, TYPE_SOLID, &update_LCRY, &graphics_LCRY}, {"STKM", PIXPACK(0x000000), 0.5f, 0.00f * CFDS, 0.2f, 1.0f, 0.0f, 0.0f, 0.0f, 0.00f * CFDS, 0, 0, 0, 0, 0, 1, 1, 50, SC_SPECIAL, R_TEMP+14.6f+273.15f, 0, "Stickman. Don't kill him!", ST_NONE, 0, &update_STKM, &graphics_STKM}, @@ -353,4 +353,4 @@ part_transition ptransitions[PT_NUM] = #undef ITL #undef ITH #undef NT -#undef ST
\ No newline at end of file +#undef ST diff --git a/src/elements/co2.c b/src/elements/co2.c index f820425..3356397 100644 --- a/src/elements/co2.c +++ b/src/elements/co2.c @@ -27,5 +27,20 @@ int update_CO2(UPDATE_FUNC_ARGS) { kill_part(r>>8); } } + if (parts[i].temp > 9773.15 && pv[y/CELL][x/CELL] > 200.0f) + { + if (rand()%5 < 1) + { + int j; + kill_part(i); + j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1) parts[j].temp = 15000; + j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); if (j != -1) parts[j].temp = 15000; + j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_O2); if (j != -1) parts[j].temp = 15000; + j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_SING); if (j != -1) { parts[j].temp = 15000; parts[i].life = rand()%100+450; } + + parts[i].temp += 15000; + pv[y/CELL][x/CELL] += 100; + } + } return 0; } diff --git a/src/elements/elec.c b/src/elements/elec.c index 6acbbab..a5c254f 100644 --- a/src/elements/elec.c +++ b/src/elements/elec.c @@ -79,7 +79,7 @@ int update_ELEC(UPDATE_FUNC_ARGS) { kill_part(i); return 1; } - if (ptypes[r&0xFF].properties & PROP_CONDUCTS) + if (ptypes[r&0xFF].properties & PROP_CONDUCTS && ((r&0xFF)!=PT_H2||parts[i].tmp!=1)) { create_part(-1, x+rx, y+ry, PT_SPRK); kill_part(i); diff --git a/src/elements/h2.c b/src/elements/h2.c index c601108..e80f04a 100644 --- a/src/elements/h2.c +++ b/src/elements/h2.c @@ -3,6 +3,8 @@ int update_H2(UPDATE_FUNC_ARGS) { int r,rx,ry,rt; + if (parts[i].temp > 2273.15 && pv[y/CELL][x/CELL] > 50.0f) + parts[i].tmp = 1; for (rx=-2; rx<3; rx++) for (ry=-2; ry<3; ry++) if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry)) @@ -16,19 +18,51 @@ int update_H2(UPDATE_FUNC_ARGS) part_change_type(r>>8,x+rx,y+ry,PT_WATR); part_change_type(i,x,y,PT_OIL); } - if ((r&0xFF)==PT_FIRE) - { - parts[r>>8].temp=2473.15; - if(parts[r>>8].tmp&0x02) - parts[r>>8].temp=3473; - parts[r>>8].tmp |= 1; - } - if ((r&0xFF)==PT_FIRE || (r&0xFF)==PT_PLSM || (r&0xFF)==PT_LAVA) + if (parts[r>>8].temp > 2273.15)// && pv[y/CELL][x/CELL] > 50.0f) + continue; + if (parts[i].tmp != 1) { - create_part(i,x,y,PT_FIRE); - parts[i].temp+=(rand()/(RAND_MAX/100)); - parts[i].tmp |= 1; + if (rt==PT_FIRE) + { + parts[r>>8].temp=2473.15; + if(parts[r>>8].tmp&0x02) + parts[r>>8].temp=3473; + parts[r>>8].tmp |= 1; + } + if (rt==PT_FIRE || rt==PT_PLSM || rt==PT_LAVA) + { + create_part(i,x,y,PT_FIRE); + parts[i].temp+=(rand()/(RAND_MAX/100)); + parts[i].tmp |= 1; + } } } + if (parts[i].temp > 2273.15 && pv[y/CELL][x/CELL] > 50.0f) + { + parts[i].tmp = 1; + if (rand()%5 < 1) + { + int j; + float temp = parts[i].temp; + part_change_type(i,x,y,PT_PLSM); + parts[i].life = rand()%150+50; + create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); + create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); + j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PHOT); + if (j != -1) { parts[j].ctype = 0xFFFF00; parts[j].temp = temp; } + + j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NBLE); + if (j != -1) { parts[j].tmp = 1; parts[j].temp = temp; } + + if (rand()%2) + { + j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NBLE); + if (j != -1) { parts[j].tmp = 1; parts[j].temp = temp; } + } + + parts[i].temp += 6000; + pv[y/CELL][x/CELL] += 30; + } + } return 0; } diff --git a/src/elements/nble.c b/src/elements/nble.c new file mode 100644 index 0000000..43264b4 --- /dev/null +++ b/src/elements/nble.c @@ -0,0 +1,26 @@ +#include <element.h> + +int update_NBLE(UPDATE_FUNC_ARGS) +{ + if (parts[i].temp > 5273.15 && pv[y/CELL][x/CELL] > 100.0f) + { + if (rand()%5 < 1) + { + int j; + float temp = parts[i].temp; + part_change_type(i,x,y,PT_PLSM); + parts[i].life = rand()%150+50; + j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_NEUT); if (j != -1) + j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_ELEC); if (j != -1) + j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_PHOT); + if (j != -1) { parts[j].ctype = 0xFF0000; parts[j].temp = temp; } + + j = create_part(-3,x+rand()%3-1,y+rand()%3-1,PT_CO2); + if (j != -1) parts[j].temp = temp - 1000; + + parts[i].temp += 10000; + pv[y/CELL][x/CELL] += 30; + } + } + return 0; +} diff --git a/src/elements/newgraphics.c b/src/elements/newgraphics.c index 8957df9..4c9225c 100644 --- a/src/elements/newgraphics.c +++ b/src/elements/newgraphics.c @@ -164,6 +164,7 @@ int graphics_WIFI(GRAPHICS_FUNC_ARGS) *colr = sin(frequency*q + 0) * 127 + 128; *colg = sin(frequency*q + 2) * 127 + 128; *colb = sin(frequency*q + 4) * 127 + 128; + *pixel_mode |= EFFECT_LINES; return 0; } int graphics_PRTI(GRAPHICS_FUNC_ARGS) @@ -173,6 +174,7 @@ int graphics_PRTI(GRAPHICS_FUNC_ARGS) *fireg = 0; *fireb = 0; *pixel_mode |= EFFECT_GRAVIN; + *pixel_mode |= EFFECT_LINES; *pixel_mode &= ~PMODE; *pixel_mode |= PMODE_ADD; return 1; @@ -184,6 +186,7 @@ int graphics_PRTO(GRAPHICS_FUNC_ARGS) *fireg = 0; *fireb = 255; *pixel_mode |= EFFECT_GRAVOUT; + *pixel_mode |= EFFECT_LINES; *pixel_mode &= ~PMODE; *pixel_mode |= PMODE_ADD; return 1; diff --git a/src/elements/prti.c b/src/elements/prti.c index 8d8f685..8b15598 100644 --- a/src/elements/prti.c +++ b/src/elements/prti.c @@ -55,8 +55,8 @@ int update_PRTI(UPDATE_FUNC_ARGS) { if (fe) { int orbd[4] = {0, 0, 0, 0}; //Orbital distances int orbl[4] = {0, 0, 0, 0}; //Orbital locations - if (!parts[i].life) parts[i].life = rand(); - if (!parts[i].ctype) parts[i].ctype = rand(); + if (!parts[i].life) parts[i].life = rand()*rand()*rand(); + if (!parts[i].ctype) parts[i].ctype = rand()*rand()*rand(); orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); for (r = 0; r < 4; r++) { if (orbd[r]>1) { diff --git a/src/elements/prto.c b/src/elements/prto.c index 1e7cde0..1dd00d4 100644 --- a/src/elements/prto.c +++ b/src/elements/prto.c @@ -85,8 +85,8 @@ int update_PRTO(UPDATE_FUNC_ARGS) { if (fe) { int orbd[4] = {0, 0, 0, 0}; //Orbital distances int orbl[4] = {0, 0, 0, 0}; //Orbital locations - if (!parts[i].life) parts[i].life = rand(); - if (!parts[i].ctype) parts[i].life = rand(); + if (!parts[i].life) parts[i].life = rand()*rand()*rand(); + if (!parts[i].ctype) parts[i].ctype = rand()*rand()*rand(); orbitalparts_get(parts[i].life, parts[i].ctype, orbd, orbl); for (r = 0; r < 4; r++) { if (orbd[r]<254) { @@ -94,9 +94,10 @@ int update_PRTO(UPDATE_FUNC_ARGS) { if (orbd[r]>254) { orbd[r] = 0; orbl[r] = rand()%255; + } else { + orbl[r] += 1; + orbl[r] = orbl[r]%255; } - //orbl[r] += 1; - //orbl[r] = orbl[r]%255; } else { orbd[r] = 0; orbl[r] = rand()%255; diff --git a/src/elements/pyro.c b/src/elements/pyro.c index dc51e76..003c8f8 100644 --- a/src/elements/pyro.c +++ b/src/elements/pyro.c @@ -46,6 +46,7 @@ int update_PYRO(UPDATE_FUNC_ARGS) { (t!=PT_SPRK || (rt!=PT_RBDM && rt!=PT_LRBD && rt!=PT_INSL)) && (t!=PT_PHOT || rt!=PT_INSL) && (rt!=PT_SPNG || parts[r>>8].life==0) && + (rt!=PT_H2 || (parts[r>>8].temp < 2273.15 && pv[y/CELL][x/CELL] < 50.0f)) && ptypes[rt].flammable && (ptypes[rt].flammable + (int)(pv[(y+ry)/CELL][(x+rx)/CELL]*10.0f))>(rand()%1000)) { part_change_type(r>>8,x+rx,y+ry,PT_FIRE); diff --git a/src/elements/sprk.c b/src/elements/sprk.c index 67b8132..00279f5 100644 --- a/src/elements/sprk.c +++ b/src/elements/sprk.c @@ -44,7 +44,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) { parts[nearp].ctype = PT_ETRD; } } - else if (ct==PT_NBLE&&parts[i].life<=1) + else if (ct==PT_NBLE&&parts[i].life<=1&&parts[i].tmp!=1) { parts[i].life = rand()%150+50; part_change_type(i,x,y,PT_PLSM); @@ -179,6 +179,8 @@ int update_SPRK(UPDATE_FUNC_ARGS) { conduct_sprk = 0; if (rt==PT_INST&&ct!=PT_PSCN) conduct_sprk = 0; + if (rt == PT_NBLE && parts[r>>8].tmp == 1) + conduct_sprk = 0; if (conduct_sprk) { if (rt==PT_WATR||rt==PT_SLTW) { @@ -221,9 +223,9 @@ int graphics_SPRK(GRAPHICS_FUNC_ARGS) { *firea = 80; - *firer = *colr = 170; - *fireg = *colg = 200; - *fireb = *colb = 220; + *firer = 170; + *fireg = 200; + *fireb = 220; //*pixel_mode |= FIRE_ADD; *pixel_mode |= FIRE_ADD; return 1; diff --git a/src/elements/stkm.c b/src/elements/stkm.c index d8286d5..7a67b65 100644 --- a/src/elements/stkm.c +++ b/src/elements/stkm.c @@ -257,7 +257,7 @@ int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS) { { int np = -1; if (playerp->elem == SPC_AIR) - create_parts(rx + 3*((((int)playerp->pcomm)&0x02) == 0x02) - 3*((((int)playerp->pcomm)&0x01) == 0x01), ry, 4, 4, SPC_AIR, 0); + create_parts(rx + 3*((((int)playerp->pcomm)&0x02) == 0x02) - 3*((((int)playerp->pcomm)&0x01) == 0x01), ry, 4, 4, SPC_AIR, 0, 1); else if (playerp->elem==PT_LIGH && playerp->frames<30)//limit lightning creation rate np = -1; else diff --git a/src/graphics.c b/src/graphics.c index a384340..cf5a760 100644 --- a/src/graphics.c +++ b/src/graphics.c @@ -887,11 +887,7 @@ inline int drawchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a) return x + w; } -#if defined(WIN32) && !defined(__GNUC__) -_inline int addchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a) -#else -inline int addchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a) -#endif +int addchar(pixel *vid, int x, int y, int c, int r, int g, int b, int a) { int i, j, w, bn = 0, ba = 0; char *rp = font_data + font_ptrs[c]; @@ -1318,14 +1314,19 @@ void draw_air(pixel *vid) clamp_flt(pv[y][x], 0.0f, 8.0f),//pressure adds green clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue } - else if (display_mode & DISPLAY_AIRH) + else if ((display_mode & DISPLAY_AIRH)) { - float ttemp = hv[y][x]+(-MIN_TEMP); - int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); - c = PIXRGB((int)((unsigned char)color_data[caddress]*0.7f), (int)((unsigned char)color_data[caddress+1]*0.7f), (int)((unsigned char)color_data[caddress+2]*0.7f)); - //c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red - // clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green - // clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue + if (aheat_enable) + { + float ttemp = hv[y][x]+(-MIN_TEMP); + int caddress = restrict_flt((int)( restrict_flt(ttemp, 0.0f, MAX_TEMP+(-MIN_TEMP)) / ((MAX_TEMP+(-MIN_TEMP))/1024) ) *3, 0.0f, (1024.0f*3)-3); + c = PIXRGB((int)((unsigned char)color_data[caddress]*0.7f), (int)((unsigned char)color_data[caddress+1]*0.7f), (int)((unsigned char)color_data[caddress+2]*0.7f)); + //c = PIXRGB(clamp_flt(fabsf(vx[y][x]), 0.0f, 8.0f),//vx adds red + // clamp_flt(hv[y][x], 0.0f, 1600.0f),//heat adds green + // clamp_flt(fabsf(vy[y][x]), 0.0f, 8.0f));//vy adds blue + } + else + c = PIXRGB(0,0,0); } else if (display_mode & DISPLAY_AIRC) { @@ -1934,6 +1935,11 @@ void render_parts(pixel *vid) #endif //Pixel rendering + if (t==PT_SOAP) + { + if ((parts[i].ctype&7) == 7) + draw_line(vid, nx, ny, (int)(parts[parts[i].tmp].x+0.5f), (int)(parts[parts[i].tmp].y+0.5f), 245, 245, 220, XRES+BARSIZE); + } if(pixel_mode & PSPEC_STICKMAN) { char buff[20]; //Buffer for HP @@ -2403,9 +2409,9 @@ void render_parts(pixel *vid) for (r = 0; r < 4; r++) { ddist = ((float)orbd[r])/16.0f; drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; - nxo = ddist*cos(drad); - nyo = ddist*sin(drad); - if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES) + nxo = (int)(ddist*cos(drad)); + nyo = (int)(ddist*sin(drad)); + if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES && (pmap[ny+nyo][nx+nxo]&0xFF) != PT_PRTI) addpixel(vid, nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]); } } @@ -2421,12 +2427,31 @@ void render_parts(pixel *vid) for (r = 0; r < 4; r++) { ddist = ((float)orbd[r])/16.0f; drad = (M_PI * ((float)orbl[r]) / 180.0f)*1.41f; - nxo = ddist*cos(drad); - nyo = ddist*sin(drad); - if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES) + nxo = (int)(ddist*cos(drad)); + nyo = (int)(ddist*sin(drad)); + if (ny+nyo>0 && ny+nyo<YRES && nx+nxo>0 && nx+nxo<XRES && (pmap[ny+nyo][nx+nxo]&0xFF) != PT_PRTO) addpixel(vid, nx+nxo, ny+nyo, colr, colg, colb, 255-orbd[r]); } } + if ((pixel_mode & EFFECT_LINES) && DEBUG_MODE) + { + if (mousex==(nx) && mousey==(ny))//draw lines connecting wifi/portal channels + { + int z; + int type = parts[i].type; + if (type == PT_PRTI) + type = PT_PRTO; + else if (type == PT_PRTO) + type = PT_PRTI; + for (z = 0; z<NPART; z++) { + if (parts[z].type) + { + if (parts[z].type==type&&parts[z].tmp==parts[i].tmp) + xor_line(nx,ny,(int)(parts[z].x+0.5f),(int)(parts[z].y+0.5f),vid); + } + } + } + } //Fire effects if(firea && (pixel_mode & FIRE_BLEND)) { @@ -2917,7 +2942,7 @@ void create_decorations(int x, int y, int rx, int ry, int r, int g, int b, int c } void create_decoration(int x, int y, int r, int g, int b, int click, int tool) { - int rp, tr,tg,tb; + int rp, tr = 0, tg = 0, tb = 0; rp = pmap[y][x]; if (!rp) return; @@ -2946,6 +2971,31 @@ void create_decoration(int x, int y, int r, int g, int b, int click, int tool) tb = (parts[rp>>8].dcolour)&0xFF; parts[rp>>8].dcolour = ((parts[rp>>8].dcolour&0xFF000000)|(clamp_flt(tr-(tr)*0.02, 0,255)<<16)|(clamp_flt(tg-(tg)*0.02, 0,255)<<8)|clamp_flt(tb-(tb)*0.02, 0,255)); } + else if (tool == DECO_SMUDGE) + { + int rx, ry, num = 0, ta = 0; + for (rx=-2; rx<3; rx++) + for (ry=-2; ry<3; ry++) + { + if ((pmap[y+ry][x+rx]&0xFF) && parts[pmap[y+ry][x+rx]>>8].dcolour) + { + num++; + ta += (parts[pmap[y+ry][x+rx]>>8].dcolour>>24)&0xFF; + tr += (parts[pmap[y+ry][x+rx]>>8].dcolour>>16)&0xFF; + tg += (parts[pmap[y+ry][x+rx]>>8].dcolour>>8)&0xFF; + tb += (parts[pmap[y+ry][x+rx]>>8].dcolour)&0xFF; + } + } + if (num == 0) + return; + ta = min(255,(int)((float)ta/num+.5)); + tr = min(255,(int)((float)tr/num+.5)); + tg = min(255,(int)((float)tg/num+.5)); + tb = min(255,(int)((float)tb/num+.5)); + if (!parts[rp>>8].dcolour) + ta = max(0,ta-3); + parts[rp>>8].dcolour = ((ta<<24)|(tr<<16)|(tg<<8)|tb); + } } void line_decorations(int x1, int y1, int x2, int y2, int rx, int ry, int r, int g, int b, int click, int tool) { @@ -3588,7 +3638,7 @@ void render_cursor(pixel *vid, int x, int y, int t, int rx, int ry) { #ifdef OGLR int i; - if (t<PT_NUM||(t&0xFF)==PT_LIFE||t==SPC_AIR||t==SPC_HEAT||t==SPC_COOL||t==SPC_VACUUM||t==SPC_WIND||t==SPC_PGRV||t==SPC_NGRV) + if (t<PT_NUM||(t&0xFF)==PT_LIFE||t==SPC_AIR||t==SPC_HEAT||t==SPC_COOL||t==SPC_VACUUM||t==SPC_WIND||t==SPC_PGRV||t==SPC_NGRV||t==SPC_PROP) { glBindFramebuffer(GL_DRAW_FRAMEBUFFER, partsFbo); glEnable(GL_COLOR_LOGIC_OP); @@ -3628,49 +3678,39 @@ void render_cursor(pixel *vid, int x, int y, int t, int rx, int ry) } #else int i,j,c; - if (t<PT_NUM||(t&0xFF)==PT_LIFE||t==SPC_AIR||t==SPC_HEAT||t==SPC_COOL||t==SPC_VACUUM||t==SPC_WIND||t==SPC_PGRV||t==SPC_NGRV) + if (t<PT_NUM||(t&0xFF)==PT_LIFE||t==SPC_AIR||t==SPC_HEAT||t==SPC_COOL||t==SPC_VACUUM||t==SPC_WIND||t==SPC_PGRV||t==SPC_NGRV||t==SPC_PROP) { if (rx<=0) - xor_pixel(x, y, vid); - else if (ry<=0) - xor_pixel(x, y, vid); - if (rx+ry<=0) - xor_pixel(x, y, vid); - else if (CURRENT_BRUSH==SQUARE_BRUSH) - { - for (j=0; j<=ry; j++) - for (i=0; i<=rx; i++) - if (i*j<=ry*rx && ((i+1)>rx || (j+1)>ry)) - { - xor_pixel(x+i, y+j, vid); - xor_pixel(x-i, y-j, vid); - if (i&&j)xor_pixel(x+i, y-j, vid); - if (i&&j)xor_pixel(x-i, y+j, vid); - } - } - else if (CURRENT_BRUSH==CIRCLE_BRUSH) + for (j = y - ry; j <= y + ry; j++) + xor_pixel(x, j, vid); + else { - for (j=0; j<=ry; j++) - for (i=0; i<=rx; i++) - if (pow(i,2)*pow(ry,2)+pow(j,2)*pow(rx,2)<=pow(rx,2)*pow(ry,2) && - (pow(i+1,2)*pow(ry,2)+pow(j,2)*pow(rx,2)>pow(rx,2)*pow(ry,2) || - pow(i,2)*pow(ry,2)+pow(j+1,2)*pow(rx,2)>pow(rx,2)*pow(ry,2))) - { - xor_pixel(x+i, y+j, vid); - if (j) xor_pixel(x+i, y-j, vid); - if (i) xor_pixel(x-i, y+j, vid); - if (i&&j) xor_pixel(x-i, y-j, vid); - } - } - else if (CURRENT_BRUSH==TRI_BRUSH) - { - for (j=-ry; j<=ry; j++) - for (i=-rx; i<=0; i++) - if ((j <= ry ) && ( j >= (((-2.0*ry)/(rx))*i)-ry ) && (j+1>ry || ( j-1 < (((-2.0*ry)/(rx))*i)-ry )) ) - { - xor_pixel(x+i, y+j, vid); - if (i) xor_pixel(x-i, y+j, vid); - } + int tempy = y, i, j, jmax, oldy; + if (CURRENT_BRUSH == TRI_BRUSH) + tempy = y + ry; + for (i = x - rx; i <= x; i++) { + oldy = tempy; + while (InCurrentBrush(i-x,tempy-y,rx,ry)) + tempy = tempy - 1; + tempy = tempy + 1; + jmax = 2*y - tempy; + if (oldy != tempy && CURRENT_BRUSH != SQUARE_BRUSH) + oldy--; + if (CURRENT_BRUSH == TRI_BRUSH) + oldy = tempy; + for (j = tempy; j <= oldy; j++) { + int i2 = 2*x-i, j2 = 2*y-j; + if (CURRENT_BRUSH == TRI_BRUSH) + j2 = y+ry; + xor_pixel(i, j, vid); + if (i2 != i) + xor_pixel(i2, j, vid); + if (j2 != j) + xor_pixel(i, j2, vid); + if (i2 != i && j2 != j) + xor_pixel(i2, j2, vid); + } + } } } else //wall cursor diff --git a/src/interface.c b/src/interface.c index dfba6bd..eede146 100644 --- a/src/interface.c +++ b/src/interface.c @@ -2219,7 +2219,7 @@ void menu_ui(pixel *vid_buf, int i, int *sl, int *sr) } */ //current menu function -void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *dae, int b, int bq, int mx, int my) +void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *su, int *dae, int b, int bq, int mx, int my) { int h,x,y,n=0,height,width,sy,rows=0,xoff=0,fwidth; SEC = SEC2; @@ -2458,7 +2458,7 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *dae, int b, int bq SEC2 = -1; } else { - *sl = h; + *sl = *su = h; *dae = 51; } } @@ -2478,7 +2478,7 @@ void menu_ui_v3(pixel *vid_buf, int i, int *sl, int *sr, int *dae, int b, int bq SEC2 = -1; } else { - *sr = h; + *sr = *su = h; *dae = 51; } } @@ -2537,7 +2537,7 @@ int color_menu_ui(pixel *vid_buf, int i, int *cr, int *cg, int *cb, int b, int b float overflow = fwidth-(XRES-BARSIZE), location = ((float)XRES-BARSIZE)/((float)(mx-(XRES-BARSIZE))); xoff = (int)(overflow / location); } - for (n = 0; n<3; n++) + for (n = 0; n<4; n++) { for (a=1; a<15; a++) { @@ -2547,6 +2547,8 @@ int color_menu_ui(pixel *vid_buf, int i, int *cr, int *cg, int *cb, int b, int b vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = PIXRGB(PIXR(toollist[n].colour)-10*a, PIXG(toollist[n].colour)-10*a, PIXB(toollist[n].colour)-10*a); else if (n == DECO_DARKEN) vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = PIXRGB(PIXR(toollist[n].colour)+10*a, PIXG(toollist[n].colour)+10*a, PIXB(toollist[n].colour)+10*a); + else if (n == DECO_SMUDGE) + vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = PIXRGB(PIXR(toollist[n].colour), PIXG(toollist[n].colour)-5*c, PIXB(toollist[n].colour)+5*c); else if (n == DECO_DRAW) vid_buf[(XRES+BARSIZE)*(y+a)+((x-xoff)+c)] = PIXRGB(*cr,*cg,*cb); else @@ -2619,7 +2621,15 @@ void quickoptions_menu(pixel *vid_buf, int b, int bq, int x, int y) quickoptions_tooltip_y = (i*16)+5; if(b && !bq) { - *(quickmenu[i].variable) = !(*(quickmenu[i].variable)); + if (!strcmp(quickmenu[i].name,"Newtonian gravity")) + { + if(!ngrav_enable) + start_grav_async(); + else + stop_grav_async(); + } + else + *(quickmenu[i].variable) = !(*(quickmenu[i].variable)); } } } @@ -2884,6 +2894,11 @@ void set_cmode(int cm) // sets to given view mode { colour_mode = COLOUR_HEAT; strcpy(itc_msg, "Heat Display"); + free(display_modes); + display_modes = calloc(2, sizeof(unsigned int)); + display_mode |= DISPLAY_AIRH; + display_modes[0] = DISPLAY_AIRH; + display_modes[1] = 0; } else if (cmode==CM_FANCY) { diff --git a/src/luaconsole.c b/src/luaconsole.c index 6fb90df..1d5446f 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -1286,9 +1286,9 @@ int luatpt_set_property(lua_State* l) } i = r>>8; if(format==2){ - *((float*)(((void*)&parts[i])+offset)) = f; + *((float*)(((char*)&parts[i])+offset)) = f; } else { - *((int*)(((void*)&parts[i])+offset)) = t; + *((int*)(((char*)&parts[i])+offset)) = t; } } } else { @@ -1310,9 +1310,9 @@ int luatpt_set_property(lua_State* l) if (partsel && partsel != parts[i].type) return 0; if(format==2){ - *((float*)(((void*)&parts[i])+offset)) = f; + *((float*)(((char*)&parts[i])+offset)) = f; } else { - *((int*)(((void*)&parts[i])+offset)) = t; + *((int*)(((char*)&parts[i])+offset)) = t; } } return 0; @@ -355,6 +355,12 @@ void stamp_update(void) { fwrite(stamps[i].name, 1, 10, f); } + else + { + char name[30] = {0}; + sprintf(name,"stamps%s%s.stm",PATH_SEP,stamps[i].name); + remove(name); + } } fclose(f); } @@ -1755,7 +1761,7 @@ int main(int argc, char *argv[]) active_menu = i; } } - menu_ui_v3(vid_buf, active_menu, &sl, &sr, &dae, b, bq, x, y); //draw the elements in the current menu + menu_ui_v3(vid_buf, active_menu, &sl, &sr, &su, &dae, b, bq, x, y); //draw the elements in the current menu if (zoom_en && x>=sdl_scale*zoom_wx && y>=sdl_scale*zoom_wy //change mouse position while it is in a zoom window && x<sdl_scale*(zoom_wx+ZFACTOR*ZSIZE) && y<sdl_scale*(zoom_wy+ZFACTOR*ZSIZE)) @@ -1833,7 +1839,10 @@ int main(int argc, char *argv[]) sprintf(heattext, "Empty, Pressure: %3.2f", pv[(y/sdl_scale)/CELL][(x/sdl_scale)/CELL]); if (DEBUG_MODE) { - sprintf(coordtext, "X:%d Y:%d. GX: %.2f GY: %.2f", x/sdl_scale, y/sdl_scale, gravx[(((y/sdl_scale)/CELL)*(XRES/CELL))+((x/sdl_scale)/CELL)], gravy[(((y/sdl_scale)/CELL)*(XRES/CELL))+((x/sdl_scale)/CELL)]); + if (ngrav_enable) + sprintf(coordtext, "X:%d Y:%d. GX: %.2f GY: %.2f", x/sdl_scale, y/sdl_scale, gravx[(((y/sdl_scale)/CELL)*(XRES/CELL))+((x/sdl_scale)/CELL)], gravy[(((y/sdl_scale)/CELL)*(XRES/CELL))+((x/sdl_scale)/CELL)]); + else + sprintf(coordtext, "X:%d Y:%d", x/sdl_scale, y/sdl_scale); } } } @@ -2221,7 +2230,7 @@ int main(int argc, char *argv[]) } if (x>=(XRES+BARSIZE-(510-476)) && x<=(XRES+BARSIZE-(510-491)) && !bq) { - render_ui(vid_buf, XRES+BARSIZE-(510-491), YRES+(MENUSIZE-19), 3); + render_ui(vid_buf, XRES+BARSIZE-(510-491), YRES-2, 3); } if (x>=(XRES+BARSIZE-(510-494)) && x<=(XRES+BARSIZE-(510-509)) && !bq) sys_pause = !sys_pause; @@ -2365,7 +2374,7 @@ int main(int argc, char *argv[]) if (c!=WL_STREAM+100&&c!=SPC_AIR&&c!=SPC_HEAT&&c!=SPC_COOL&&c!=SPC_VACUUM&&!REPLACE_MODE&&c!=SPC_WIND&&c!=SPC_PGRV&&c!=SPC_NGRV) flood_parts(x, y, c, -1, -1, get_brush_flags()); if (c==SPC_HEAT || c==SPC_COOL) - create_parts(x, y, bsx, bsy, c, get_brush_flags()); + create_parts(x, y, bsx, bsy, c, get_brush_flags(), 1); lx = x; ly = y; lb = 0; @@ -2418,7 +2427,7 @@ int main(int argc, char *argv[]) cb_bmap[cby][cbx] = bmap[cby][cbx]; cb_emap[cby][cbx] = emap[cby][cbx]; } - create_parts(x, y, bsx, bsy, c, get_brush_flags()); + create_parts(x, y, bsx, bsy, c, get_brush_flags(), 1); lx = x; ly = y; lb = b; diff --git a/src/powder.c b/src/powder.c index 91a478d..233fa32 100644 --- a/src/powder.c +++ b/src/powder.c @@ -318,43 +318,17 @@ int try_move(int i, int x, int y, int nx, int ny) if (parts[i].type==PT_NEUT && (ptypes[r&0xFF].properties&PROP_NEUTABSORB)) { - parts[i].type=PT_NONE; + kill_part(i); return 0; } if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_PVOD) //this is where void eats particles { - if (parts[i].type == PT_STKM) - { - player.spwn = 0; - } - if (parts[i].type == PT_STKM2) - { - player2.spwn = 0; - } - if (parts[i].type == PT_FIGH) - { - fighters[(unsigned char)parts[i].tmp].spwn = 0; - fighcount--; - } - parts[i].type=PT_NONE; + kill_part(i); return 0; } if ((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) //this is where blackhole eats particles { - if (parts[i].type == PT_STKM) - { - player.spwn = 0; - } - if (parts[i].type == PT_STKM2) - { - player2.spwn = 0; - } - if (parts[i].type == PT_FIGH) - { - fighters[(unsigned char)parts[i].tmp].spwn = 0; - fighcount--; - } - parts[i].type=PT_NONE; + kill_part(i); if (!legacy_enable) { parts[r>>8].temp = restrict_flt(parts[r>>8].temp+parts[i].temp/2, MIN_TEMP, MAX_TEMP);//3.0f; @@ -364,7 +338,7 @@ int try_move(int i, int x, int y, int nx, int ny) } if (((r&0xFF)==PT_WHOL||(r&0xFF)==PT_NWHL) && parts[i].type==PT_ANAR) //whitehole eats anar { - parts[i].type=PT_NONE; + kill_part(i); if (!legacy_enable) { parts[r>>8].temp = restrict_flt(parts[r>>8].temp- (MAX_TEMP-parts[i].temp)/2, MIN_TEMP, MAX_TEMP); @@ -415,8 +389,10 @@ int try_move(int i, int x, int y, int nx, int ny) // try to move particle, and if successful update pmap and parts[i].x,y int do_move(int i, int x, int y, float nxf, float nyf) { - int nx = (int)(nxf+0.5f), ny = (int)(nyf+0.5f); - int result = try_move(i, x, y, nx, ny); + int nx = (int)(nxf+0.5f), ny = (int)(nyf+0.5f), result; + if (parts[i].type == PT_NONE) + return 0; + result = try_move(i, x, y, nx, ny); if (result) { int t = parts[i].type; @@ -613,6 +589,9 @@ void kill_part(int i)//kills particle number i { int x, y; + if (parts[i].type == PT_NONE) //This shouldn't happen anymore, but it's here just in case + return; + x = (int)(parts[i].x+0.5f); y = (int)(parts[i].y+0.5f); if (parts[i].type == PT_STKM) @@ -2284,13 +2263,15 @@ killed: if (stagnant)//FLAG_STAGNANT set, was reflected on previous frame { // cast coords as int then back to float for compatibility with existing saves - if (!do_move(i, x, y, (float)fin_x, (float)fin_y)) { + if (!do_move(i, x, y, (float)fin_x, (float)fin_y) && parts[i].type) { kill_part(i); continue; } } else if (!do_move(i, x, y, fin_xf, fin_yf)) { + if (parts[i].type == PT_NONE) + continue; // reflection parts[i].flags |= FLAG_STAGNANT; if (t==PT_NEUT && 100>(rand()%1000)) @@ -2350,6 +2331,8 @@ killed: // gasses and solids (but not powders) if (!do_move(i, x, y, fin_xf, fin_yf)) { + if (parts[i].type == PT_NONE) + continue; // can't move there, so bounce off // TODO if (fin_x>x+ISTP) fin_x=x+ISTP; @@ -2381,6 +2364,8 @@ killed: // liquids and powders if (!do_move(i, x, y, fin_xf, fin_yf)) { + if (parts[i].type == PT_NONE) + continue; if (fin_x!=x && do_move(i, x, y, fin_xf, clear_yf)) { parts[i].vx *= ptypes[t].collision; @@ -2724,7 +2709,7 @@ void create_box(int x1, int y1, int x2, int y2, int c, int flags) } for (j=y1; j<=y2; j++) for (i=x1; i<=x2; i++) - create_parts(i, j, 0, 0, c, flags); + create_parts(i, j, 0, 0, c, flags, 1); } int flood_prop_2(int x, int y, size_t propoffset, void * propvalue, int proptype, int parttype, char * bitmap) @@ -2849,7 +2834,7 @@ int flood_parts(int x, int y, int fullc, int cm, int bm, int flags) if (create_part(-1,x, y, fullc)==-1) return 0; } - else if (!create_parts(x, y, 0, 0, fullc, flags)) + else if (!create_parts(x, y, 0, 0, fullc, flags, 1)) return 0; } // fill children @@ -2972,9 +2957,9 @@ int create_part_add_props(int p, int x, int y, int tv, int rx, int ry) } //this creates particles from a brush, don't use if you want to create one particle -int create_parts(int x, int y, int rx, int ry, int c, int flags) +int create_parts(int x, int y, int rx, int ry, int c, int flags, int fill) { - int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0, p;//n; + int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0, p, fn; int wall = c - 100; if (c==SPC_WIND || c==PT_FIGH) @@ -2984,6 +2969,8 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags) prop_edit_ui(vid_buf, x, y); return 0; } + if (c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM || c == SPC_PGRV || c == SPC_NGRV) + fill = 1; for (r=UI_ACTUALSTART; r<=UI_ACTUALSTART+UI_WALLCOUNT; r++) { if (wall==r) @@ -3075,114 +3062,102 @@ int create_parts(int x, int y, int rx, int ry, int c, int flags) return 1; } - //eraser - if (c == 0 && !(flags&BRUSH_REPLACEMODE)) - { - if (rx==0&&ry==0) - { - delete_part(x, y, 0); - } - else - for (j=-ry; j<=ry; j++) - for (i=-rx; i<=rx; i++) - if (InCurrentBrush(i ,j ,rx ,ry)) - delete_part(x+i, y+j, 0); - return 1; - } + if (c == 0 && !(flags&BRUSH_REPLACEMODE)) // delete + fn = 0; + else if ((flags&BRUSH_SPECIFIC_DELETE) && !(flags&BRUSH_REPLACEMODE)) // specific delete + fn = 1; + else if (flags&BRUSH_REPLACEMODE) // replace + fn = 2; + else // normal draw + fn = 3; - //specific deletion - if ((flags&BRUSH_SPECIFIC_DELETE)&& !(flags&BRUSH_REPLACEMODE)) + if (rx<=0) //workaround for rx == 0 crashing. todo: find a better fix later. { - if (rx==0&&ry==0) - { - delete_part(x, y, flags); - } - else - for (j=-ry; j<=ry; j++) - for (i=-rx; i<=rx; i++) - if (InCurrentBrush(i ,j ,rx ,ry)) - delete_part(x+i, y+j, flags); - return 1; + for (j = y - ry; j <= y + ry; j++) + if (create_parts2(fn,x,j,c,rx,ry,flags)) + f = 1; } - - //why do these need a special if - if (c == SPC_AIR || c == SPC_HEAT || c == SPC_COOL || c == SPC_VACUUM || c == SPC_PGRV || c == SPC_NGRV) + else { - if (rx==0&&ry==0) - { - create_part(-2, x, y, c); + int tempy = y, i, j, jmax, oldy; + if (CURRENT_BRUSH == TRI_BRUSH) + tempy = y + ry; + for (i = x - rx; i <= x; i++) { + oldy = tempy; + while (InCurrentBrush(i-x,tempy-y,rx,ry)) + tempy = tempy - 1; + tempy = tempy + 1; + jmax = 2*y - tempy; + if (CURRENT_BRUSH == TRI_BRUSH) + jmax = y + ry; + if (fill) + { + for (j = tempy; j <= jmax; j++) { + if (create_parts2(fn,i,j,c,rx,ry,flags)) + f = 1; + if (create_parts2(fn,2*x-i,j,c,rx,ry,flags)) + f = 1; + } + } + else + { + if ((oldy != tempy && CURRENT_BRUSH != SQUARE_BRUSH) || i == x-rx) + oldy--; + if (CURRENT_BRUSH == TRI_BRUSH) + oldy = tempy; + for (j = tempy; j <= oldy+1; j++) { + int i2 = 2*x-i, j2 = 2*y-j; + if (CURRENT_BRUSH == TRI_BRUSH) + j2 = y+ry; + if (create_parts2(fn,i,j,c,rx,ry,flags)) + f = 1; + if (create_parts2(fn,i2,j,c,rx,ry,flags)) + f = 1; + if (create_parts2(fn,i,j2,c,rx,ry,flags)) + f = 1; + if (create_parts2(fn,i2,j2,c,rx,ry,flags)) + f = 1; + } + } } - else - for (j=-ry; j<=ry; j++) - for (i=-rx; i<=rx; i++) - if (InCurrentBrush(i ,j ,rx ,ry)) - { - if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) - continue; - 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; } + return !f; +} - if (flags&BRUSH_REPLACEMODE) +int create_parts2(int f, int x, int y, int c, int rx, int ry, int flags) +{ + if (f == 0) //delete + delete_part(x, y, 0); + else if (f == 1) //specific delete + delete_part(x, y, flags); + else if (f == 2) //replace mode { - if (rx==0&&ry==0) + if (x<0 || y<0 || x>=XRES || y>=YRES) + return 0; + if ((pmap[y][x]&0xFF)!=SLALT&&SLALT!=0) + return 0; + if ((pmap[y][x])) { - if ((pmap[y][x]&0xFF)==SLALT || SLALT==0) - { - if ((pmap[y][x])) - { - delete_part(x, y, 0); - if (c!=0) - create_part_add_props(-2, x, y, c, rx, ry); - } - } + delete_part(x, y, 0); + if (c!=0) + create_part_add_props(-2, x, y, c, rx, ry); } - else - for (j=-ry; j<=ry; j++) - for (i=-rx; i<=rx; i++) - if (InCurrentBrush(i ,j ,rx ,ry)) - { - if ( x+i<0 || y+j<0 || x+i>=XRES || y+j>=YRES) - continue; - if ((pmap[y+j][x+i]&0xFF)!=SLALT&&SLALT!=0) - continue; - if ((pmap[y+j][x+i])) - { - delete_part(x+i, y+j, 0); - if (c!=0) - create_part_add_props(-2, x+i, y+j, c, rx, ry); - } - } - return 1; - } - //else, no special modes, draw element like normal. - if (rx==0&&ry==0)//workaround for 1pixel brush/floodfill crashing. todo: find a better fix later. - { + else if (f == 3) //normal draw if (create_part_add_props(-2, x, y, c, rx, ry)==-1) - f = 1; - } - else - for (j=-ry; j<=ry; j++) - for (i=-rx; i<=rx; i++) - if (InCurrentBrush(i ,j ,rx ,ry)) - if (create_part_add_props(-2, x+i, y+j, c, rx, ry)==-1) - f = 1; - return !f; + return 1; + return 0; } + int InCurrentBrush(int i, int j, int rx, int ry) { switch(CURRENT_BRUSH) { case CIRCLE_BRUSH: - return (pow(i,2)*pow(ry,2)+pow(j,2)*pow(rx,2)<=pow(rx,2)*pow(ry,2)); + return (pow((double)i,2)*pow((double)ry,2)+pow((double)j,2)*pow((double)rx,2)<=pow((double)rx,2)*pow((double)ry,2)); break; case SQUARE_BRUSH: - return (i*j<=ry*rx); + return (abs(i) <= rx && abs(j) <= ry); break; case TRI_BRUSH: return (j <= ry ) && ( j >= (((-2.0*ry)/rx)*i) -ry) && ( j >= (((-2.0*ry)/(-rx))*i)-ry ) ; @@ -3205,7 +3180,7 @@ int get_brush_flags() } void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags) { - int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy; + int cp=abs(y2-y1)>abs(x2-x1), x, y, dx, dy, sy, fill = 1; float e, de; if (c==SPC_PROP) return; @@ -3239,9 +3214,10 @@ void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flag for (x=x1; x<=x2; x++) { if (cp) - create_parts(y, x, rx, ry, c, flags); + create_parts(y, x, rx, ry, c, flags, fill); else - create_parts(x, y, rx, ry, c, flags); + create_parts(x, y, rx, ry, c, flags, fill); + fill = 0; e += de; if (e >= 0.5f) { @@ -3250,9 +3226,9 @@ void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flag && ((y1<y2) ? (y<=y2) : (y>=y2))) { if (cp) - create_parts(y, x, rx, ry, c, flags); + create_parts(y, x, rx, ry, c, flags, fill); else - create_parts(x, y, rx, ry, c, flags); + create_parts(x, y, rx, ry, c, flags, fill); } e -= 1.0f; } @@ -52,11 +52,42 @@ int parse_save(void *save, int size, int replace, int x0, int y0, unsigned char return 1; } +int change_wall(int wt) +{ + if (wt == 1) + return WL_WALL; + else if (wt == 2) + return WL_DESTROYALL; + else if (wt == 3) + return WL_ALLOWLIQUID; + else if (wt == 4) + return WL_FAN; + else if (wt == 5) + return WL_STREAM; + else if (wt == 6) + return WL_DETECT; + else if (wt == 7) + return WL_EWALL; + else if (wt == 8) + return WL_WALLELEC; + else if (wt == 9) + return WL_ALLOWAIR; + else if (wt == 10) + return WL_ALLOWSOLID; + else if (wt == 11) + return WL_ALLOWALLELEC; + else if (wt == 12) + return WL_EHOLE; + else if (wt == 13) + return WL_ALLOWGAS; + return wt; +} + pixel *prerender_save_OPS(void *save, int size, int *width, int *height) { unsigned char * inputData = save, *bsonData = NULL, *partsData = NULL, *partsPosData = NULL, *wallData = NULL; int inputDataLen = size, bsonDataLen = 0, partsDataLen, partsPosDataLen, wallDataLen; - int i, x, y, j; + int i, x, y, j, wt, pc, gc; int blockX, blockY, blockW, blockH, fullX, fullY, fullW, fullH; int bsonInitialised = 0; pixel * vidBuf = NULL; @@ -177,14 +208,65 @@ pixel *prerender_save_OPS(void *save, int size, int *width, int *height) { if(wallData[y*blockW+x]) { - for(i = 0; i < CELL; i++) + wt = wallData[y*blockW+x]; + pc = wtypes[wt-UI_ACTUALSTART].colour; + gc = wtypes[wt-UI_ACTUALSTART].eglow; + if (wtypes[wt-UI_ACTUALSTART].drawstyle==1) { - for(j = 0; j < CELL; j++) - { - vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = PIXPACK(0xCCCCCC); - } + for (i=0; i<CELL; i+=2) + for (j=(i>>1)&1; j<CELL; j+=2) + vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc; + } + else if (wtypes[wt-UI_ACTUALSTART].drawstyle==2) + { + for (i=0; i<CELL; i+=2) + for (j=0; j<CELL; j+=2) + vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc; + } + else if (wtypes[wt-UI_ACTUALSTART].drawstyle==3) + { + for (i=0; i<CELL; i++) + for (j=0; j<CELL; j++) + vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc; } - }; + else if (wtypes[wt-UI_ACTUALSTART].drawstyle==4) + { + for (i=0; i<CELL; i++) + for (j=0; j<CELL; j++) + if(i == j) + vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc; + else if (j == i+1 || (j == 0 && i == CELL-1)) + vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = gc; + else + vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = PIXPACK(0x202020); + } + + // special rendering for some walls + if (wt==WL_EWALL) + { + for (i=0; i<CELL; i++) + for (j=0; j<CELL; j++) + if (!(i&j&1)) + vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc; + } + else if (wt==WL_WALLELEC) + { + for (i=0; i<CELL; i++) + for (j=0; j<CELL; j++) + { + if (!((y*CELL+j)%2) && !((x*CELL+i)%2)) + vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = pc; + else + vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = PIXPACK(0x808080); + } + } + else if (wt==WL_EHOLE) + { + for (i=0; i<CELL; i+=2) + for (j=0; j<CELL; j+=2) + vidBuf[(fullY+i+(y*CELL))*fullW+(fullX+j+(x*CELL))] = PIXPACK(0x242424); + } + } } } } @@ -392,7 +474,7 @@ void *build_save_OPS(int *size, int orig_x0, int orig_y0, int orig_w, int orig_h wallData[(y-blockY)*blockW+(x-blockX)] = bmap[y][x]; if(bmap[y][x] && !wallDataFound) wallDataFound = 1; - if(bmap[y][x]==WL_FAN || bmap[y][x]==4) + if(bmap[y][x]==WL_FAN) { i = (int)(fvx[y][x]*64.0f+127.5f); if (i<0) i=0; @@ -990,8 +1072,9 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c { for(y = 0; y < blockH; y++) { - bmap[blockY+y][blockX+x] = wallData[y*blockW+x]; - if((bmap[blockY+y][blockX+x]==WL_FAN || bmap[blockY+y][blockX+x]==4) && fanData) + if (wallData[y*blockW+x]) + bmap[blockY+y][blockX+x] = wallData[y*blockW+x]; + if (wallData[y*blockW+x] == WL_FAN && fanData) { if(j+1 >= fanDataLen) { @@ -1222,7 +1305,7 @@ fin: pixel *prerender_save_PSv(void *save, int size, int *width, int *height) { unsigned char *d,*c=save; - int i,j,k,x,y,rx,ry,p=0; + int i,j,k,x,y,rx,ry,p=0, wt, pc, gc; int bw,bh,w,h,new_format = 0; pixel *fb; @@ -1269,93 +1352,68 @@ pixel *prerender_save_PSv(void *save, int size, int *width, int *height) for (y=0; y<bh; y++) for (x=0; x<bw; x++) { + int wt = change_wall(d[p]); rx = x*CELL; ry = y*CELL; - switch (d[p]) + pc = wtypes[wt-UI_ACTUALSTART].colour; + gc = wtypes[wt-UI_ACTUALSTART].eglow; + if (wtypes[wt-UI_ACTUALSTART].drawstyle==1) { - case 1: - for (j=0; j<CELL; j++) - for (i=0; i<CELL; i++) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080); - break; - case 2: - for (j=0; j<CELL; j+=2) - for (i=(j>>1)&1; i<CELL; i+=2) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080); - break; - case 3: - for (j=0; j<CELL; j++) - for (i=0; i<CELL; i++) - if (!(j%2) && !(i%2)) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0xC0C0C0); - break; - case 4: - for (j=0; j<CELL; j+=2) - for (i=(j>>1)&1; i<CELL; i+=2) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0x8080FF); - k++; - break; - case 6: - for (j=0; j<CELL; j+=2) - for (i=(j>>1)&1; i<CELL; i+=2) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0xFF8080); - break; - case 7: - for (j=0; j<CELL; j++) - for (i=0; i<CELL; i++) - if (!(i&j&1)) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080); - break; - case 8: - for (j=0; j<CELL; j++) - for (i=0; i<CELL; i++) - if (!(j%2) && !(i%2)) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0xC0C0C0); - else - fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080); - break; - case WL_WALL: - for (j=0; j<CELL; j++) - for (i=0; i<CELL; i++) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080); - break; - case WL_DESTROYALL: - for (j=0; j<CELL; j+=2) - for (i=(j>>1)&1; i<CELL; i+=2) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080); - break; - case WL_ALLOWLIQUID: - for (j=0; j<CELL; j++) - for (i=0; i<CELL; i++) - if (!(j%2) && !(i%2)) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0xC0C0C0); - break; - case WL_FAN: - for (j=0; j<CELL; j+=2) - for (i=(j>>1)&1; i<CELL; i+=2) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0x8080FF); - k++; - break; - case WL_DETECT: - for (j=0; j<CELL; j+=2) - for (i=(j>>1)&1; i<CELL; i+=2) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0xFF8080); - break; - case WL_EWALL: - for (j=0; j<CELL; j++) - for (i=0; i<CELL; i++) + for (i=0; i<CELL; i+=2) + for (j=(i>>1)&1; j<CELL; j+=2) + fb[(i+ry)*w+(j+rx)] = pc; + } + else if (wtypes[wt-UI_ACTUALSTART].drawstyle==2) + { + for (i=0; i<CELL; i+=2) + for (j=0; j<CELL; j+=2) + fb[(i+ry)*w+(j+rx)] = pc; + } + else if (wtypes[wt-UI_ACTUALSTART].drawstyle==3) + { + for (i=0; i<CELL; i++) + for (j=0; j<CELL; j++) + fb[(i+ry)*w+(j+rx)] = pc; + } + else if (wtypes[wt-UI_ACTUALSTART].drawstyle==4) + { + for (i=0; i<CELL; i++) + for (j=0; j<CELL; j++) + if(i == j) + fb[(i+ry)*w+(j+rx)] = pc; + else if (j == i+1 || (j == 0 && i == CELL-1)) + fb[(i+ry)*w+(j+rx)] = gc; + else + fb[(i+ry)*w+(j+rx)] = PIXPACK(0x202020); + } + + // special rendering for some walls + if (wt==WL_EWALL) + { + for (i=0; i<CELL; i++) + for (j=0; j<CELL; j++) if (!(i&j&1)) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080); - break; - case WL_WALLELEC: - for (j=0; j<CELL; j++) - for (i=0; i<CELL; i++) - if (!(j%2) && !(i%2)) - fb[(ry+j)*w+(rx+i)] = PIXPACK(0xC0C0C0); + fb[(i+ry)*w+(j+rx)] = pc; + } + else if (wt==WL_WALLELEC) + { + for (i=0; i<CELL; i++) + for (j=0; j<CELL; j++) + { + if (!((y*CELL+j)%2) && !((x*CELL+i)%2)) + fb[(i+ry)*w+(j+rx)] = pc; else - fb[(ry+j)*w+(rx+i)] = PIXPACK(0x808080); - break; + fb[(i+ry)*w+(j+rx)] = PIXPACK(0x808080); + } + } + else if (wt==WL_EHOLE) + { + for (i=0; i<CELL; i+=2) + for (j=0; j<CELL; j+=2) + fb[(i+ry)*w+(j+rx)] = PIXPACK(0x242424); } + else if (wt==WL_FAN) + k++; p++; } p += 2*k; @@ -1757,33 +1815,7 @@ int parse_save_PSv(void *save, int size, int replace, int x0, int y0, unsigned c continue; } - bmap[y][x] = d[p]; - if (bmap[y][x]==1) - bmap[y][x]=WL_WALL; - if (bmap[y][x]==2) - bmap[y][x]=WL_DESTROYALL; - if (bmap[y][x]==3) - bmap[y][x]=WL_ALLOWLIQUID; - if (bmap[y][x]==4) - bmap[y][x]=WL_FAN; - if (bmap[y][x]==5) - bmap[y][x]=WL_STREAM; - if (bmap[y][x]==6) - bmap[y][x]=WL_DETECT; - if (bmap[y][x]==7) - bmap[y][x]=WL_EWALL; - if (bmap[y][x]==8) - bmap[y][x]=WL_WALLELEC; - if (bmap[y][x]==9) - bmap[y][x]=WL_ALLOWAIR; - if (bmap[y][x]==10) - bmap[y][x]=WL_ALLOWSOLID; - if (bmap[y][x]==11) - bmap[y][x]=WL_ALLOWALLELEC; - if (bmap[y][x]==12) - bmap[y][x]=WL_EHOLE; - if (bmap[y][x]==13) - bmap[y][x]=WL_ALLOWGAS; + bmap[y][x] = change_wall(d[p]); } p++; |
