From 34d76f86803138699b46f7e6252c11985ef481cf Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Fri, 24 Jun 2011 22:55:59 +0100 Subject: [PATCH] Check photon map in Lua functions, and allow any ctype Also add some extra checks on ctype in the rest of the game --- src/elements/aray.c | 2 +- src/elements/bcln.c | 2 +- src/elements/clne.c | 2 +- src/elements/pcln.c | 4 ++-- src/elements/sprk.c | 2 +- src/luaconsole.c | 33 +++++++++++++++++++-------------- 6 files changed, 25 insertions(+), 20 deletions(-) diff --git a/src/elements/aray.c b/src/elements/aray.c index 4f94f009b..94729f456 100644 --- a/src/elements/aray.c +++ b/src/elements/aray.c @@ -49,7 +49,7 @@ int update_ARAY(UPDATE_FUNC_ARGS) { if (nyy!=0 || nxx!=0) { create_part(-1, x+nxi+nxx, y+nyi+nyy, PT_SPRK); } - if (!(nostop && (ptypes[parts[r>>8].ctype].properties&PROP_CONDUCTS))) { + if (!(nostop && (ptypes[r&0xFF].properties&PROP_CONDUCTS))) {//don't need to check r&0xFF>8)>=NPART docontinue = 0; } else { docontinue = 1; diff --git a/src/elements/bcln.c b/src/elements/bcln.c index aaf4afced..5d95d97e7 100644 --- a/src/elements/bcln.c +++ b/src/elements/bcln.c @@ -9,7 +9,7 @@ int update_BCLN(UPDATE_FUNC_ARGS) { parts[i].vx += advection*vx[y/CELL][x/CELL]; parts[i].vy += advection*vy[y/CELL][x/CELL]; } - if (!parts[i].ctype) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM) { int r, rx, ry; for (rx=-1; rx<2; rx++) diff --git a/src/elements/clne.c b/src/elements/clne.c index 295974ada..adc9a18d3 100644 --- a/src/elements/clne.c +++ b/src/elements/clne.c @@ -1,7 +1,7 @@ #include int update_CLNE(UPDATE_FUNC_ARGS) { - if (!parts[i].ctype) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM) { int r, rx, ry; for (rx=-1; rx<2; rx++) diff --git a/src/elements/pcln.c b/src/elements/pcln.c index 8afa65643..3ba431c3a 100644 --- a/src/elements/pcln.c +++ b/src/elements/pcln.c @@ -26,7 +26,7 @@ int update_PCLN(UPDATE_FUNC_ARGS) { parts[i].life = 10; } } - if (!parts[i].ctype) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM) for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>=0 && x+rx0 && parts[i].ctype=PT_NUM) ct = PT_METL; part_change_type(i,x,y,ct); parts[i].ctype = PT_NONE; diff --git a/src/luaconsole.c b/src/luaconsole.c index 93cd407ae..ba8529de3 100644 --- a/src/luaconsole.c +++ b/src/luaconsole.c @@ -345,7 +345,7 @@ int luatpt_reset_spark(lua_State* l) int luatpt_set_property(lua_State* l) { char *prop, *name; - int i, x, y, w, h, t, format, nx, ny, partsel = 0, acount; + int r, i, x, y, w, h, t, format, nx, ny, partsel = 0, acount; float f; size_t offset; acount = lua_gettop(l); @@ -374,7 +374,7 @@ int luatpt_set_property(lua_State* l) format = 1; } else if (strcmp(prop,"ctype")==0){ offset = offsetof(particle, ctype); - format = 3; + format = 4; } else if (strcmp(prop,"temp")==0){ offset = offsetof(particle, temp); format = 2; @@ -409,8 +409,6 @@ int luatpt_set_property(lua_State* l) } else { t = luaL_optint(l, 2, 0); } - if (format == 3 && t==OLD_PT_WIND) - return 0; if (format == 3 && (t<0 || t>=PT_NUM)) return luaL_error(l, "Unrecognised element number '%d'", t); } else { @@ -435,9 +433,14 @@ int luatpt_set_property(lua_State* l) h = YRES-y; for (nx = x; nx>8; - if (!(pmap[ny][nx]&0xFF) || i < 0 || i >= NPART || (partsel && partsel != parts[i].type)) - continue; + r = pmap[ny][nx]; + if (!r || (r>>8) >= NPART || (partsel && partsel != parts[r>>8].type)) + { + r = photons[ny][nx]; + if (!r || (partsel && partsel != parts[r>>8].type)) + continue; + } + i = r>>8; if(format==2){ *((float*)(((void*)&parts[i])+offset)) = f; } else { @@ -449,9 +452,10 @@ int luatpt_set_property(lua_State* l) if(i != -1 && y != -1){ if (i>=XRES || y>=YRES) return luaL_error(l, "Coordinates out of range (%d,%d)", i, y); - i = pmap[y][i]>>8; - if (i >= NPART) - return 0; + r = pmap[y][i]; + if (!r || (r>>8)>=NPART || (partsel && partsel != parts[r>>8].type)) + r = photons[y][i]; + i = r>>8; } if (i < 0 || i >= NPART) return luaL_error(l, "Invalid particle ID '%d'", i); @@ -470,15 +474,16 @@ int luatpt_set_property(lua_State* l) int luatpt_get_property(lua_State* l) { - int i, y; + int i, r, y; char *prop; prop = luaL_optstring(l, 1, ""); i = luaL_optint(l, 2, 0); y = luaL_optint(l, 3, -1); if(y!=-1 && y < YRES && y >= 0 && i < XRES && i >= 0){ - i = pmap[y][i]>>8; - if (i >= NPART) - return 0; + r = pmap[y][i]; + if (!r || (r>>8)>=NPART) + r = photons[y][i]; + i = r>>8; } else if (y!=-1) return luaL_error(l, "Coordinates out of range (%d,%d)", i, y);