summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorjacksonmj <mj-pt@jacksonmj.co.uk>2011-06-24 21:55:59 (GMT)
committer Simon Robertshaw <simon@hardwired.org.uk>2011-06-25 14:59:30 (GMT)
commit34d76f86803138699b46f7e6252c11985ef481cf (patch)
tree99c962bea2e407f70a20b1d69f1c453f2abfc04c /src
parentc18009dd9c87343178e808565d815b454bd2b585 (diff)
downloadpowder-34d76f86803138699b46f7e6252c11985ef481cf.zip
powder-34d76f86803138699b46f7e6252c11985ef481cf.tar.gz
Check photon map in Lua functions, and allow any ctype
Also add some extra checks on ctype in the rest of the game
Diffstat (limited to 'src')
-rw-r--r--src/elements/aray.c2
-rw-r--r--src/elements/bcln.c2
-rw-r--r--src/elements/clne.c2
-rw-r--r--src/elements/pcln.c4
-rw-r--r--src/elements/sprk.c2
-rw-r--r--src/luaconsole.c33
6 files changed, 25 insertions, 20 deletions
diff --git a/src/elements/aray.c b/src/elements/aray.c
index 4f94f00..94729f4 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<PT_NUM here because it should have been excluded by (r>>8)>=NPART
docontinue = 0;
} else {
docontinue = 1;
diff --git a/src/elements/bcln.c b/src/elements/bcln.c
index aaf4afc..5d95d97 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 295974a..adc9a18 100644
--- a/src/elements/clne.c
+++ b/src/elements/clne.c
@@ -1,7 +1,7 @@
#include <element.h>
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 8afa656..3ba431c 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+rx<XRES && y+ry<YRES)
@@ -43,7 +43,7 @@ int update_PCLN(UPDATE_FUNC_ARGS) {
(r&0xFF)<PT_NUM)
parts[i].ctype = r&0xFF;
}
- if (parts[i].ctype && parts[i].life==10) {
+ if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && parts[i].life==10) {
if (parts[i].ctype==PT_PHOT) {//create photons a different way
for (rx=-1; rx<2; rx++) {
for (ry=-1; ry<2; ry++) {
diff --git a/src/elements/sprk.c b/src/elements/sprk.c
index 004d6e8..0d579f5 100644
--- a/src/elements/sprk.c
+++ b/src/elements/sprk.c
@@ -8,7 +8,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
{
if (ct==PT_WATR||ct==PT_SLTW||ct==PT_PSCN||ct==PT_NSCN||ct==PT_ETRD||ct==PT_INWR)
parts[i].temp = R_TEMP + 273.15f;
- if (!ct)
+ if (ct<=0 || ct>=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 93cd407..ba8529d 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<x+w; nx++)
for (ny = y; ny<y+h; ny++){
- i = pmap[ny][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);