From 75cb924bd9d0525646bbdabf8959b58e149b7442 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Sat, 20 Aug 2011 20:41:39 +0100 Subject: [PATCH] Fix electrode when in replace mode or specific delete mode Also fix bomb when SLALT != 0 --- includes/powder.h | 16 ++++--- src/elements/bomb.c | 2 +- src/elements/sprk.c | 4 +- src/elements/stkm.c | 2 +- src/luaconsole.c | 2 +- src/main.c | 14 +++--- src/powder.c | 107 ++++++++++++++++++++++++-------------------- src/pythonconsole.c | 2 +- 8 files changed, 81 insertions(+), 68 deletions(-) diff --git a/includes/powder.h b/includes/powder.h index 791988c3c..c9e96531e 100644 --- a/includes/powder.h +++ b/includes/powder.h @@ -20,6 +20,8 @@ #define CM_PRESS 1 #define CM_VEL 0 +#define BRUSH_REPLACEMODE 0x1 +#define BRUSH_SPECIFIC_DELETE 0x2 #define UI_WALLSTART 222 #define UI_ACTUALSTART 122 @@ -990,9 +992,11 @@ void part_change_type(int i, int x, int y, int t); int InCurrentBrush(int i, int j, int rx, int ry); +int get_brush_flags(); + int create_part(int p, int x, int y, int t); -void delete_part(int x, int y); +void delete_part(int x, int y, int flags); int is_wire(int x, int y); @@ -1002,7 +1006,7 @@ void set_emap(int x, int y); int parts_avg(int ci, int ni, int t); -void create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int type); +void create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int type, int flags); int nearest_part(int ci, int t); @@ -1014,13 +1018,13 @@ void rotate_area(int area_x, int area_y, int area_w, int area_h, int invert); void clear_area(int area_x, int area_y, int area_w, int area_h); -void create_box(int x1, int y1, int x2, int y2, int c); +void create_box(int x1, int y1, int x2, int y2, int c, int flags); -int flood_parts(int x, int y, int c, int cm, int bm); +int flood_parts(int x, int y, int c, int cm, int bm, int flags); -int create_parts(int x, int y, int rx, int ry, int c); +int create_parts(int x, int y, int rx, int ry, int c, int flags); -void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c); +void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c, int flags); void *transform_save(void *odata, int *size, matrix2d transform, vector2d translate); diff --git a/src/elements/bomb.c b/src/elements/bomb.c index 8115a88ad..de10fccf0 100644 --- a/src/elements/bomb.c +++ b/src/elements/bomb.c @@ -44,7 +44,7 @@ int update_BOMB(UPDATE_FUNC_ARGS) { for (nxi=-rad; nxi<=rad; nxi++) if ((pow(nxi,2))/(pow(rad,2))+(pow(nxj,2))/(pow(rad,2))<=1) if ((pmap[y+nxj][x+nxi]&0xFF)!=PT_DMND && (pmap[y+nxj][x+nxi]&0xFF)!=PT_CLNE && (pmap[y+nxj][x+nxi]&0xFF)!=PT_PCLN && (pmap[y+nxj][x+nxi]&0xFF)!=PT_BCLN) { - delete_part(x+nxi, y+nxj);//it SHOULD kill anything but the exceptions above, doesn't seem to always work + delete_part(x+nxi, y+nxj, 0);//it SHOULD kill anything but the exceptions above, doesn't seem to always work pv[(y+nxj)/CELL][(x+nxi)/CELL] += 0.1f; nb = create_part(-1, x+nxi, y+nxj, PT_BOMB); if (nb!=-1) { diff --git a/src/elements/sprk.c b/src/elements/sprk.c index 039453fa0..0f3d8e9f2 100644 --- a/src/elements/sprk.c +++ b/src/elements/sprk.c @@ -35,7 +35,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) { nearp = nearest_part(i, PT_ETRD); if (nearp!=-1&&parts_avg(i, nearp, PT_INSL)!=PT_INSL) { - create_line(x, y, (int)(parts[nearp].x+0.5f), (int)(parts[nearp].y+0.5f), 0, 0, PT_PLSM); + create_line(x, y, (int)(parts[nearp].x+0.5f), (int)(parts[nearp].y+0.5f), 0, 0, PT_PLSM, 0); part_change_type(i,x,y,ct); ct = parts[i].ctype = PT_NONE; parts[i].life = 20; @@ -152,7 +152,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) { else if (rt==PT_INST) { if (parts[i].life>=3&&parts[r>>8].life==0) { - flood_parts(x+rx,y+ry,PT_SPRK,PT_INST,-1);//spark the wire + flood_parts(x+rx,y+ry,PT_SPRK,PT_INST,-1, 0);//spark the wire } } else if (parts[r>>8].life==0 && (parts[i].life<3 || ((r>>8)=0 && playerp[2] != PT_PHOT && playerp[2] != SPC_AIR) diff --git a/src/luaconsole.c b/src/luaconsole.c index 1376252c4..dc1da07d8 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -751,7 +751,7 @@ int luatpt_delete(lua_State* l) } arg2 = abs(arg2); if(arg2 < YRES && arg1 < XRES){ - delete_part(arg1, arg2); + delete_part(arg1, arg2, 0); return 0; } return luaL_error(l,"Invalid coordinates or particle ID"); diff --git a/src/main.c b/src/main.c index 9dd4ace4d..9bff1e501 100644 --- a/src/main.c +++ b/src/main.c @@ -3071,7 +3071,7 @@ int main(int argc, char *argv[]) { nfvx = (line_x-lx)*0.005f; nfvy = (line_y-ly)*0.005f; - flood_parts(lx, ly, WL_FANHELPER, -1, WL_FAN); + flood_parts(lx, ly, WL_FANHELPER, -1, WL_FAN, 0); for (j=0; j=XRES || ly>=YRES || bmap[ly/CELL][lx/CELL]!=WL_FAN) - create_line(lx, ly, line_x, line_y, bsx, bsy, c); + create_line(lx, ly, line_x, line_y, bsx, bsy, c, get_brush_flags()); } else//box - create_box(lx, ly, x, y, c); + create_box(lx, ly, x, y, c, get_brush_flags()); lm = 0; } lb = 0; diff --git a/src/powder.c b/src/powder.c index 36f10e725..bdbc1b704 100644 --- a/src/powder.c +++ b/src/powder.c @@ -1068,9 +1068,9 @@ static void create_cherenkov_photon(int pp)//photons from NEUT going through GLA } #if defined(WIN32) && !defined(__GNUC__) -_inline void delete_part(int x, int y) +_inline void delete_part(int x, int y, int flags)//calls kill_part with the particle located at x,y #else -inline void delete_part(int x, int y)//calls kill_part with the particle located at x,y +inline void delete_part(int x, int y, int flags)//calls kill_part with the particle located at x,y #endif { unsigned i; @@ -1085,7 +1085,7 @@ inline void delete_part(int x, int y)//calls kill_part with the particle located if (!i || (i>>8)>=NPART) return; - if ((parts[i>>8].type==SLALT)||SLALT==0)//specific deletiom + if (!(flags&BRUSH_SPECIFIC_DELETE) || parts[i>>8].type==SLALT || SLALT==0)//specific deletiom { kill_part(i>>8); } @@ -1249,7 +1249,7 @@ int nearest_part(int ci, int t) return id; } -void create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int type) +void create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int type, int flags) { int i; float xint, yint; @@ -1277,7 +1277,7 @@ void create_arc(int sx, int sy, int dx, int dy, int midpoints, int variance, int xmid[i+1] += (rand()%variance)-voffset; ymid[i+1] += (rand()%variance)-voffset; } - create_line(xmid[i], ymid[i], xmid[i+1], ymid[i+1], 0, 0, type); + create_line(xmid[i], ymid[i], xmid[i+1], ymid[i+1], 0, 0, type, flags); } free(xmid); free(ymid); @@ -2484,12 +2484,12 @@ void clear_area(int area_x, int area_y, int area_w, int area_h) for (cx=0; cxx2) @@ -2506,10 +2506,10 @@ void create_box(int x1, int y1, int x2, int y2, int c) } for (j=y1; j<=y2; j++) for (i=x1; i<=x2; i++) - create_parts(i, j, 0, 0, c); + create_parts(i, j, 0, 0, c, flags); } -int flood_parts(int x, int y, int fullc, int cm, int bm) +int flood_parts(int x, int y, int fullc, int cm, int bm, int flags) { int c = fullc&0xFF; int x1, x2, dy = (c=CELL+dy && x1==x2 && ((pmap[y-1][x1-1]&0xFF)==PT_INST||(pmap[y-1][x1-1]&0xFF)==PT_SPRK) && ((pmap[y-1][x1]&0xFF)==PT_INST||(pmap[y-1][x1]&0xFF)==PT_SPRK) && ((pmap[y-1][x1+1]&0xFF)==PT_INST || (pmap[y-1][x1+1]&0xFF)==PT_SPRK) && (pmap[y-2][x1-1]&0xFF)!=PT_INST && ((pmap[y-2][x1]&0xFF)==PT_INST ||(pmap[y-2][x1]&0xFF)==PT_SPRK) && (pmap[y-2][x1+1]&0xFF)!=PT_INST) - flood_parts(x1, y-2, fullc, cm, bm); + flood_parts(x1, y-2, fullc, cm, bm, flags); else if (y>=CELL+dy) for (x=x1; x<=x2; x++) if ((pmap[y-1][x]&0xFF)!=PT_SPRK) @@ -2591,14 +2591,14 @@ int flood_parts(int x, int y, int fullc, int cm, int bm) if (x==x1 || x==x2 || y>=YRES-CELL-1 || (pmap[y-1][x-1]&0xFF)==PT_INST || (pmap[y-1][x+1]&0xFF)==PT_INST || (pmap[y+1][x-1]&0xFF)==PT_INST || ((pmap[y+1][x]&0xFF)!=PT_INST&&(pmap[y+1][x]&0xFF)!=PT_SPRK) || (pmap[y+1][x+1]&0xFF)==PT_INST) - flood_parts(x, y-dy, fullc, cm, bm); + flood_parts(x, y-dy, fullc, cm, bm, flags); } if (y=CELL+dy) for (x=x1; x<=x2; x++) if ((pmap[y-dy][x]&0xFF)==cm && bmap[(y-dy)/CELL][x/CELL]==bm) - if (!flood_parts(x, y-dy, fullc, cm, bm)) + if (!flood_parts(x, y-dy, fullc, cm, bm, flags)) return 0; if (yabs(x2-x1), x, y, dx, dy, sy; float e, de; @@ -2861,9 +2870,9 @@ void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c) for (x=x1; x<=x2; x++) { if (cp) - create_parts(y, x, rx, ry, c); + create_parts(y, x, rx, ry, c, flags); else - create_parts(x, y, rx, ry, c); + create_parts(x, y, rx, ry, c, flags); e += de; if (e >= 0.5f) { @@ -2871,9 +2880,9 @@ void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c) if (c==WL_EHOLE || c==WL_ALLOWGAS || c==WL_ALLOWALLELEC || c==WL_ALLOWSOLID || c==WL_ALLOWAIR || c==WL_WALL || c==WL_DESTROYALL || c==WL_ALLOWLIQUID || c==WL_FAN || c==WL_STREAM || c==WL_DETECT || c==WL_EWALL || c==WL_WALLELEC || !(rx+ry)) { if (cp) - create_parts(y, x, rx, ry, c); + create_parts(y, x, rx, ry, c, flags); else - create_parts(x, y, rx, ry, c); + create_parts(x, y, rx, ry, c, flags); } e -= 1.0f; } diff --git a/src/pythonconsole.c b/src/pythonconsole.c index 4dc507245..c7d7d5128 100644 --- a/src/pythonconsole.c +++ b/src/pythonconsole.c @@ -847,7 +847,7 @@ static PyObject* emb_delete(PyObject *self, PyObject *args) int x,y; if (!PyArg_ParseTuple(args, "ii:delete",&x,&y)) return NULL; - delete_part(x,y); + delete_part(x,y, 0); return Py_BuildValue("i",1); }