TPT: Separate loop for updating life, and add SPRK life checks to most electronics 6bdc05cc40

This commit is contained in:
Simon Robertshaw 2012-04-17 17:14:23 +01:00
parent 75f6212751
commit ca1690efe1
9 changed files with 31 additions and 19 deletions

View File

@ -11,7 +11,7 @@ int update_ARAY(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_SPRK) {
if ((r&0xFF)==PT_SPRK && parts[r>>8].life<4) {
int destroy = (parts[r>>8].ctype==PT_PSCN)?1:0;
int nostop = (parts[r>>8].ctype==PT_INST)?1:0;
for (docontinue = 1, nxx = 0, nyy = 0, nxi = rx*-1, nyi = ry*-1; docontinue; nyy+=nyi, nxx+=nxi) {

View File

@ -19,7 +19,7 @@ int update_DLAY(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_SPRK && parts[i].life==0 && parts[r>>8].ctype==PT_PSCN)
if ((r&0xFF)==PT_SPRK && parts[i].life==0 && parts[r>>8].life<4 && parts[r>>8].ctype==PT_PSCN)
{
parts[i].life = (int)(parts[i].temp-273.15);
}

View File

@ -11,7 +11,7 @@ int update_EMP(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_SPRK)
if ((r&0xFF)==PT_SPRK && parts[r>>8].life<4)
{
ok=1;
break;

View File

@ -11,7 +11,7 @@ int update_PCLN(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_SPRK)
if ((r&0xFF)==PT_SPRK && parts[r>>8].life<4)
{
if (parts[r>>8].ctype==PT_PSCN)
parts[i].life = 10;

View File

@ -11,7 +11,7 @@ int update_PVOD(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_SPRK)
if ((r&0xFF)==PT_SPRK && parts[r>>8].life<4)
{
if (parts[r>>8].ctype==PT_PSCN)
parts[i].life = 10;

View File

@ -119,7 +119,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
pavg = sim->parts_avg(r>>8, i,PT_INSL);
if ((rt==PT_SWCH||(rt==PT_SPRK&&parts[r>>8].ctype==PT_SWCH)) && pavg!=PT_INSL) // make sparked SWCH turn off correctly
if ((rt==PT_SWCH||(rt==PT_SPRK&&parts[r>>8].ctype==PT_SWCH)) && pavg!=PT_INSL && parts[i].life<4) // make sparked SWCH turn off correctly
{
if (rt==PT_SWCH&&ct==PT_PSCN&&parts[r>>8].life<10) {
parts[r>>8].life = 10;
@ -130,12 +130,12 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
parts[r>>8].life = 9;
}
}
else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_PUMP||rt==PT_GPMP||rt==PT_HSWC||rt==PT_PBCN)) // PROP_PTOGGLE, Maybe? We seem to use 2 different methods for handling actived elements, this one seems better. Yes, use this one for new elements, PCLN is different for compatibility with existing saves
else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_PUMP||rt==PT_GPMP||rt==PT_HSWC||rt==PT_PBCN) && parts[i].life<4) // PROP_PTOGGLE, Maybe? We seem to use 2 different methods for handling actived elements, this one seems better. Yes, use this one for new elements, PCLN is different for compatibility with existing saves
{
if (ct==PT_PSCN) parts[r>>8].life = 10;
else if (ct==PT_NSCN && parts[r>>8].life>=10) parts[r>>8].life = 9;
}
else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_LCRY&&abs(rx)<2&&abs(ry)<2))
else if ((ct==PT_PSCN||ct==PT_NSCN) && (rt==PT_LCRY&&abs(rx)<2&&abs(ry)<2) && parts[i].life<4)
{
if (ct==PT_PSCN && parts[r>>8].tmp == 0) parts[r>>8].tmp = 2;
else if (ct==PT_NSCN && parts[r>>8].tmp == 3) parts[r>>8].tmp = 1;
@ -150,7 +150,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
conduct_sprk = 0;
if (ct==PT_METL && (rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR||(rt==PT_SPRK&&(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT))) && pavg!=PT_INSL)
if (ct==PT_METL && (rt==PT_NTCT||rt==PT_PTCT||rt==PT_INWR||(rt==PT_SPRK&&(parts[r>>8].ctype==PT_NTCT||parts[r>>8].ctype==PT_PTCT))) && pavg!=PT_INSL && parts[i].life<4)
{
parts[r>>8].temp = 473.0f;
if (rt==PT_NTCT||rt==PT_PTCT)
@ -182,7 +182,7 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
if (conduct_sprk) {
if (rt==PT_WATR||rt==PT_SLTW) {
if (parts[r>>8].life==0 && (parts[i].life<2 || ((r>>8)<i && parts[i].life<3)))
if (parts[r>>8].life==0 && parts[i].life<3)
{
sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK);
if (rt==PT_WATR) parts[r>>8].life = 6;
@ -191,12 +191,12 @@ int update_SPRK(UPDATE_FUNC_ARGS) {
}
}
else if (rt==PT_INST) {
if (parts[i].life>=3&&parts[r>>8].life==0)
if (parts[r>>8].life==0 && parts[i].life<4)
{
sim->flood_parts(x+rx,y+ry,PT_SPRK,PT_INST,-1, 0);//spark the wire
}
}
else if (parts[r>>8].life==0 && (parts[i].life<3 || ((r>>8)<i && parts[i].life<4))) {
else if (parts[r>>8].life==0 && parts[i].life<4) {
parts[r>>8].life = 4;
parts[r>>8].ctype = rt;
sim->part_change_type(r>>8,x+rx,y+ry,PT_SPRK);

View File

@ -20,7 +20,7 @@ int update_STOR(UPDATE_FUNC_ARGS) {
parts[i].pavg[1] = parts[r>>8].ctype;
sim->kill_part(r>>8);
}
if(parts[i].tmp && (r&0xFF)==PT_SPRK && parts[r>>8].ctype==PT_PSCN)
if(parts[i].tmp && (r&0xFF)==PT_SPRK && parts[r>>8].ctype==PT_PSCN && parts[r>>8].life<4)
{
for(ry1 = 1; ry1 >= -1; ry1--){
for(rx1 = 0; rx1 >= -1 && rx1 <= 1; rx1 = -rx1-rx1+1){ // Oscilate the X starting at 0, 1, -1, 3, -5, etc (Though stop at -1)

View File

@ -29,7 +29,12 @@ int update_WIRE(UPDATE_FUNC_ARGS) {
r = pmap[y+ry][x+rx];
if (!r)
continue;
if((r&0xFF)==PT_SPRK && parts[r>>8].ctype==PT_PSCN){parts[i].ctype=1; parts[r>>8].life=0; return 0;}
if((r&0xFF)==PT_SPRK && parts[r>>8].life<4 && parts[r>>8].ctype==PT_PSCN)
{
parts[i].ctype=1;
parts[r>>8].life=0;
return 0;
}
else if((r&0xFF)==PT_NSCN && parts[i].tmp==1){sim->create_part(-1, x+rx, y+ry, PT_SPRK);}
else if((r&0xFF)==PT_WIRE && parts[r>>8].tmp==1 && !parts[i].tmp){count++;}
}

View File

@ -2278,6 +2278,7 @@ void Simulation::update_particles_i(int start, int inc)
int surround[8];
int surround_hconduct[8];
int lighting_ok=1;
unsigned int elem_properties;
float pGravX, pGravY, pGravD;
if (lighting_recreate>0)
@ -2410,7 +2411,6 @@ void Simulation::update_particles_i(int start, int inc)
else
wireless[q][1] = 0;
}
//the main particle loop function, goes over all particles.
for (i=0; i<=parts_lastActiveIndex; i++)
if (parts[i].type)
{
@ -2420,25 +2420,32 @@ void Simulation::update_particles_i(int start, int inc)
kill_part(i);
continue;
}
//printf("parts[%d].type: %d\n", i, parts[i].type);
if (parts[i].life>0 && (ptypes[t].properties&PROP_LIFE_DEC))
elem_properties = ptypes[t].properties;
if (parts[i].life>0 && (elem_properties&PROP_LIFE_DEC))
{
// automatically decrease life
parts[i].life--;
if (parts[i].life<=0 && (ptypes[t].properties&(PROP_LIFE_KILL_DEC|PROP_LIFE_KILL)))
if (parts[i].life<=0 && (elem_properties&(PROP_LIFE_KILL_DEC|PROP_LIFE_KILL)))
{
// kill on change to no life
kill_part(i);
continue;
}
}
else if (parts[i].life<=0 && (ptypes[t].properties&PROP_LIFE_KILL))
else if (parts[i].life<=0 && (elem_properties&PROP_LIFE_KILL))
{
// kill if no life
kill_part(i);
continue;
}
}
//the main particle loop function, goes over all particles.
for (i=0; i<=parts_lastActiveIndex; i++)
if (parts[i].type)
{
t = parts[i].type;
x = (int)(parts[i].x+0.5f);
y = (int)(parts[i].y+0.5f);