From 61f39f5464f4f5d39c76f8427127e8998cc8e618 Mon Sep 17 00:00:00 2001 From: jacksonmj Date: Mon, 9 Jul 2012 20:09:29 +0100 Subject: [PATCH] Add ptypes.enabled checks to a few more places --- src/elements/bcln.c | 2 +- src/elements/clne.c | 2 +- src/elements/conv.c | 4 ++-- src/elements/neut.c | 2 +- src/elements/pbcn.c | 4 ++-- src/elements/pcln.c | 4 ++-- src/elements/sprk.c | 2 +- src/elements/stkm.c | 2 +- src/main.c | 6 +++--- src/save.c | 2 +- 10 files changed, 15 insertions(+), 15 deletions(-) diff --git a/src/elements/bcln.c b/src/elements/bcln.c index 053df1841..63a2bbcbe 100644 --- a/src/elements/bcln.c +++ b/src/elements/bcln.c @@ -24,7 +24,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<=0 || parts[i].ctype>=PT_NUM || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !ptypes[parts[i].ctype].enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) { int r, rx, ry; for (rx=-1; rx<2; rx++) diff --git a/src/elements/clne.c b/src/elements/clne.c index e84252ac7..05834b05a 100644 --- a/src/elements/clne.c +++ b/src/elements/clne.c @@ -16,7 +16,7 @@ #include int update_CLNE(UPDATE_FUNC_ARGS) { - if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !ptypes[parts[i].ctype].enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) { int r, rx, ry; for (rx=-1; rx<2; rx++) diff --git a/src/elements/conv.c b/src/elements/conv.c index 9696d983d..bdba3693f 100644 --- a/src/elements/conv.c +++ b/src/elements/conv.c @@ -17,7 +17,7 @@ int update_CONV(UPDATE_FUNC_ARGS) { int r, rx, ry; - if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !ptypes[parts[i].ctype].enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) { for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) @@ -39,7 +39,7 @@ int update_CONV(UPDATE_FUNC_ARGS) { } } } - else if(parts[i].ctype>0 && parts[i].ctype0 && parts[i].ctype=0 && y+ry>=0 && x+rx340) { n = 340; } - if (x<0 || y<0 || x>=XRES || y>=YRES || t<0 || t>=PT_NUM) + if (x<0 || y<0 || x>=XRES || y>=YRES || t<0 || t>=PT_NUM || !ptypes[t].enabled) return -1; for (c=0; c=PT_NUM || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !ptypes[parts[i].ctype].enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>=0 && x+rx0 && parts[i].ctype0 && parts[i].ctype=PT_NUM || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) + if (parts[i].ctype<=0 || parts[i].ctype>=PT_NUM || !ptypes[parts[i].ctype].enabled || (parts[i].ctype==PT_LIFE && (parts[i].tmp<0 || parts[i].tmp>=NGOLALT))) for (rx=-1; rx<2; rx++) for (ry=-1; ry<2; ry++) if (x+rx>=0 && y+ry>=0 && x+rx>8].ctype; } } - if (parts[i].ctype>0 && parts[i].ctype0 && parts[i].ctype=PT_NUM) + if (ct<=0 || ct>=PT_NUM || !ptypes[ct].enabled) ct = PT_METL; part_change_type(i,x,y,ct); parts[i].ctype = PT_NONE; diff --git a/src/elements/stkm.c b/src/elements/stkm.c index a72f83917..9271c5447 100644 --- a/src/elements/stkm.c +++ b/src/elements/stkm.c @@ -54,7 +54,7 @@ int run_stickman(playerst* playerp, UPDATE_FUNC_ARGS) { float gvx, gvy; float gx, gy, dl, dr; - if ((parts[i].ctype>0 && parts[i].ctype0) || parts[i].ctype==SPC_AIR || parts[i].ctype == PT_NEUT || parts[i].ctype == PT_PHOT || parts[i].ctype == PT_LIGH) + if ((parts[i].ctype>0 && parts[i].ctype0) || parts[i].ctype==SPC_AIR || parts[i].ctype == PT_NEUT || parts[i].ctype == PT_PHOT || parts[i].ctype == PT_LIGH) playerp->elem = parts[i].ctype; playerp->frames++; diff --git a/src/main.c b/src/main.c index 4aae2f488..ec1122316 100644 --- a/src/main.c +++ b/src/main.c @@ -1548,7 +1548,7 @@ int main(int argc, char *argv[]) for (i=0; i= 0 && parts[i].ctype < PT_NUM) + if (parts[i].ctype >= 0 && parts[i].ctype < PT_NUM && ptypes[parts[i].ctype].enabled) { parts[i].type = parts[i].ctype; parts[i].life = 0; @@ -2797,14 +2797,14 @@ int main(int argc, char *argv[]) //Setting an element for the stick man if (player.spwn==0) { - if ((sr0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH) + if ((sr>0 && sr0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH) player.elem = sr; else player.elem = PT_DUST; } if (player2.spwn==0) { - if ((sr0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH) + if ((sr>0 && sr0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH) player2.elem = sr; else player2.elem = PT_DUST; diff --git a/src/save.c b/src/save.c index 1fcfe7adf..3f852cac2 100644 --- a/src/save.c +++ b/src/save.c @@ -1237,7 +1237,7 @@ int parse_save_OPS(void *save, int size, int replace, int x0, int y0, unsigned c fprintf(stderr, "Out of range [%d]: %d %d, [%d, %d], [%d, %d]\n", i, x, y, (unsigned)partsData[i+1], (unsigned)partsData[i+2], (unsigned)partsData[i+3], (unsigned)partsData[i+4]); goto fail; } - if(partsData[i] >= PT_NUM) + if(partsData[i] >= PT_NUM || !ptypes[partsData[i]].enabled) partsData[i] = PT_DMND; //Replace all invalid elements with diamond if(pmap[y][x] && posCount==0) // Check posCount to make sure an existing particle is not replaced twice if two particles are saved in that position {