Add ptypes.enabled checks to a few more places

This commit is contained in:
jacksonmj 2012-07-09 20:09:29 +01:00
parent 3e1d3cd5a6
commit 61f39f5464
10 changed files with 15 additions and 15 deletions

View File

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

View File

@ -16,7 +16,7 @@
#include <element.h>
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++)

View File

@ -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].ctype<PT_NUM && parts[i].ctype!=PT_CONV) {
else if(parts[i].ctype>0 && parts[i].ctype<PT_NUM && ptypes[parts[i].ctype].enabled && parts[i].ctype!=PT_CONV) {
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)

View File

@ -26,7 +26,7 @@ int create_n_parts(int n, int x, int y, float vx, float vy, float temp, int t)//
if (n>340) {
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<n; c++) {

View File

@ -32,7 +32,7 @@ int update_PBCN(UPDATE_FUNC_ARGS) {
return 1;
}
}
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++)
if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
@ -72,7 +72,7 @@ int update_PBCN(UPDATE_FUNC_ARGS) {
}
}
}
if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && parts[i].life==10) {
if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && ptypes[parts[i].ctype].enabled && 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

@ -41,7 +41,7 @@ int update_PCLN(UPDATE_FUNC_ARGS) {
parts[i].life = 10;
}
}
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++)
if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES)
@ -62,7 +62,7 @@ int update_PCLN(UPDATE_FUNC_ARGS) {
parts[i].tmp = parts[r>>8].ctype;
}
}
if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && parts[i].life==10) {
if (parts[i].ctype>0 && parts[i].ctype<PT_NUM && ptypes[parts[i].ctype].enabled && 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

@ -23,7 +23,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<=0 || ct>=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;

View File

@ -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].ctype<PT_NUM && ptypes[parts[i].ctype].falldown>0) || 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].ctype<PT_NUM && ptypes[parts[i].ctype].enabled && ptypes[parts[i].ctype].falldown>0) || 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++;

View File

@ -1548,7 +1548,7 @@ int main(int argc, char *argv[])
for (i=0; i<NPART; i++)
if (parts[i].type==PT_SPRK)
{
if (parts[i].ctype >= 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 ((sr<PT_NUM && ptypes[sr].falldown>0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH)
if ((sr>0 && sr<PT_NUM && ptypes[sr].enabled && ptypes[sr].falldown>0) || 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 ((sr<PT_NUM && ptypes[sr].falldown>0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH)
if ((sr>0 && sr<PT_NUM && ptypes[sr].enabled && ptypes[sr].falldown>0) || sr==SPC_AIR || sr == PT_NEUT || sr == PT_PHOT || sr == PT_LIGH)
player2.elem = sr;
else
player2.elem = PT_DUST;

View File

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