Check photon map in Lua functions, and allow any ctype

Also add some extra checks on ctype in the rest of the game
This commit is contained in:
jacksonmj 2011-06-24 22:55:59 +01:00 committed by Simon Robertshaw
parent c18009dd9c
commit 34d76f8680
6 changed files with 25 additions and 20 deletions

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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