Fix electrode when in replace mode or specific delete mode

Also fix bomb when SLALT != 0
This commit is contained in:
jacksonmj 2011-08-20 20:41:39 +01:00 committed by Simon Robertshaw
parent 27a95c7684
commit 75cb924bd9
8 changed files with 81 additions and 68 deletions

View File

@ -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);

View File

@ -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) {

View File

@ -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)<i && parts[i].life<4))) {

View File

@ -240,7 +240,7 @@ int run_stickman(float* playerp, UPDATE_FUNC_ARGS) {
{
int np = -1;
if (playerp[2] == SPC_AIR)
create_parts(rx + 3*((((int)playerp[1])&0x02) == 0x02) - 3*((((int)playerp[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR);
create_parts(rx + 3*((((int)playerp[1])&0x02) == 0x02) - 3*((((int)playerp[1])&0x01) == 0x01), ry, 4, 4, SPC_AIR, 0);
else
np = create_part(-1, rx, ry, playerp[2]);
if ( (np < NPART) && np>=0 && playerp[2] != PT_PHOT && playerp[2] != SPC_AIR)

View File

@ -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");

View File

@ -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<YRES/CELL; j++)
for (i=0; i<XRES/CELL; i++)
if (bmap[j][i] == WL_FANHELPER)
@ -3113,7 +3113,7 @@ int main(int argc, char *argv[])
}
else
{
create_line(lx, ly, x, y, bsx, bsy, c);
create_line(lx, ly, x, y, bsx, bsy, c, get_brush_flags());
}
lx = x;
ly = y;
@ -3143,9 +3143,9 @@ int main(int argc, char *argv[])
if (sdl_mod & (KMOD_CAPS))
c = 0;
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);
flood_parts(x, y, c, -1, -1, get_brush_flags());
if (c==SPC_HEAT || c==SPC_COOL)
create_parts(x, y, bsx, bsy, c);
create_parts(x, y, bsx, bsy, c, get_brush_flags());
lx = x;
ly = y;
lb = 0;
@ -3198,7 +3198,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);
create_parts(x, y, bsx, bsy, c, get_brush_flags());
lx = x;
ly = y;
lb = b;
@ -3218,10 +3218,10 @@ int main(int argc, char *argv[])
if (lm == 1)//line
{
if (c!=WL_FAN+100 || lx<0 || ly<0 || lx>=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;

View File

@ -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; cx<area_w; cx++)
{
bmap[(cy+area_y)/CELL][(cx+area_x)/CELL] = 0;
delete_part(cx+area_x, cy+area_y);
delete_part(cx+area_x, cy+area_y, 0);
}
}
}
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 i, j;
if (x1>x2)
@ -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<PT_NUM)?1:CELL;
@ -2524,7 +2524,7 @@ int flood_parts(int x, int y, int fullc, int cm, int bm)
cm = pmap[y][x]&0xFF;
if (!cm)
return 0;
if (REPLACE_MODE && cm!=SLALT)
if ((flags&BRUSH_REPLACEMODE) && cm!=SLALT)
return 0;
}
else
@ -2544,7 +2544,7 @@ int flood_parts(int x, int y, int fullc, int cm, int bm)
bm = 0;
}
if (((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm )||( (sdl_mod & (KMOD_CAPS)) && cm!=SLALT && !(cm==PT_INST&&co==PT_SPRK)))
if (((pmap[y][x]&0xFF)!=cm || bmap[y/CELL][x/CELL]!=bm )||( (flags&BRUSH_SPECIFIC_DELETE) && cm!=SLALT))
return 1;
// go left as far as possible
@ -2574,7 +2574,7 @@ int flood_parts(int x, int y, int fullc, int cm, int bm)
if (create_part(-1,x, y, fullc)==-1)
return 0;
}
else if (!create_parts(x, y, 0, 0, fullc))
else if (!create_parts(x, y, 0, 0, fullc, flags))
return 0;
}
// fill children
@ -2583,7 +2583,7 @@ int flood_parts(int x, int y, int fullc, int cm, int bm)
if (y>=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<YRES-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<YRES-CELL-dy)
for (x=x1; x<=x2; x++)
if ((pmap[y+1][x]&0xFF)!=PT_SPRK)
@ -2606,7 +2606,7 @@ int flood_parts(int x, int y, int fullc, int cm, int bm)
if (x==x1 || x==x2 || y<0 ||
(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);
}
}
@ -2615,12 +2615,12 @@ int flood_parts(int x, int y, int fullc, int cm, int bm)
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 (y<YRES-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 (!(cm==PT_INST&&co==PT_SPRK))
@ -2628,7 +2628,7 @@ int flood_parts(int x, int y, int fullc, int cm, int bm)
}
//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 create_parts(int x, int y, int rx, int ry, int c, int flags)
{
int i, j, r, f = 0, u, v, oy, ox, b = 0, dw = 0, stemp = 0;//n;
@ -2672,7 +2672,7 @@ int create_parts(int x, int y, int rx, int ry, int c)
{
i = ox;
j = oy;
if (((sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL))|| ((sdl_mod & (KMOD_CAPS)) && b!=WL_FANHELPER) ))
if ((flags&BRUSH_SPECIFIC_DELETE) && b!=WL_FANHELPER)
{
if (bmap[j][i]==SLALT-100)
{
@ -2708,18 +2708,33 @@ int create_parts(int x, int y, int rx, int ry, int c)
return 1;
}
//if CTRL+ALT or CAPSLOCK is on, specific delete
if (((sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL))|| sdl_mod & (KMOD_CAPS) )&& !REPLACE_MODE)
//eraser
if (c == 0 && !(flags&BRUSH_REPLACEMODE))
{
if (rx==0&&ry==0)
{
delete_part(x, y);
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);
delete_part(x+i, y+j, 0);
return 1;
}
//specific deletion
if ((flags&BRUSH_SPECIFIC_DELETE)&& !(flags&BRUSH_REPLACEMODE))
{
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;
}
@ -2745,24 +2760,7 @@ int create_parts(int x, int y, int rx, int ry, int c)
return 1;
}
//eraser
if (c == 0 && !REPLACE_MODE)
{
stemp = SLALT;
SLALT = 0;//temporarily clear specific deletion element
if (rx==0&&ry==0)
{
delete_part(x, y);
}
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);
SLALT = stemp;
return 1;
}
if (REPLACE_MODE)
if (flags&BRUSH_REPLACEMODE)
{
if (rx==0&&ry==0)
{
@ -2770,7 +2768,7 @@ int create_parts(int x, int y, int rx, int ry, int c)
{
if ((pmap[y][x]))
{
delete_part(x, y);
delete_part(x, y, 0);
if (c!=0)
create_part(-2, x, y, c);
}
@ -2787,7 +2785,7 @@ int create_parts(int x, int y, int rx, int ry, int c)
continue;
if ((pmap[y+j][x+i]))
{
delete_part(x+i, y+j);
delete_part(x+i, y+j, 0);
if (c!=0)
create_part(-2, x+i, y+j, c);
}
@ -2827,7 +2825,18 @@ int InCurrentBrush(int i, int j, int rx, int ry)
break;
}
}
void create_line(int x1, int y1, int x2, int y2, int rx, int ry, int c)
int get_brush_flags()
{
int flags = 0;
if (REPLACE_MODE)
flags |= BRUSH_REPLACEMODE;
if (sdl_mod & (KMOD_CAPS))
flags |= BRUSH_SPECIFIC_DELETE;
if (sdl_mod & (KMOD_LALT) && sdl_mod & (KMOD_CTRL))
flags |= BRUSH_SPECIFIC_DELETE;
return 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;
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;
}

View File

@ -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);
}