Skip to content

Commit

Permalink
More fixes to fix fixes and new fixes to fix stuff.
Browse files Browse the repository at this point in the history
  • Loading branch information
pilihp64 committed Mar 1, 2013
1 parent 5873d69 commit 0d70547
Show file tree
Hide file tree
Showing 22 changed files with 457 additions and 392 deletions.
12 changes: 7 additions & 5 deletions src/simulation/elements/CO2.cpp
Expand Up @@ -56,7 +56,14 @@ int Element_CO2::update(UPDATE_FUNC_ARGS)
{
r = pmap[y+ry][x+rx];
if (!r)
{
if (parts[i].ctype==5 && !(rand()%83))
{
if (sim->create_part(-1, x+rx, y+ry, PT_WATR)>=0)
parts[i].ctype = 0;
}
continue;
}
if ((r&0xFF)==PT_FIRE){
sim->kill_part(r>>8);
if(!(rand()%150)){
Expand All @@ -79,11 +86,6 @@ int Element_CO2::update(UPDATE_FUNC_ARGS)
}
}
}
if (parts[i].ctype==5 && !(rand()%83))
{
if (sim->create_part(-1, x+rx, y+ry, PT_WATR)>=0)
parts[i].ctype = 0;
}
if (parts[i].temp > 9773.15 && sim->pv[y/CELL][x/CELL] > 200.0f)
{
if (!(rand()%5))
Expand Down
22 changes: 14 additions & 8 deletions src/simulation/elements/DLAY.cpp
Expand Up @@ -68,17 +68,23 @@ int Element_DLAY::update(UPDATE_FUNC_ARGS)
}
else if ((r&0xFF)==PT_DLAY)
{
if(!parts[i].life && parts[r>>8].life)
if (!parts[i].life)
{
parts[i].life = parts[r>>8].life;
if((r>>8)>i) //If the other particle hasn't been life updated
parts[i].life--;
if (parts[r>>8].life)
{
parts[i].life = parts[r>>8].life;
if((r>>8)>i) //If the other particle hasn't been life updated
parts[i].life--;
}
}
else if(parts[i].life && !parts[r>>8].life)
else
{
parts[r>>8].life = parts[i].life;
if((r>>8)>i) //If the other particle hasn't been life updated
parts[r>>8].life++;
if (!parts[r>>8].life)
{
parts[r>>8].life = parts[i].life;
if((r>>8)>i) //If the other particle hasn't been life updated
parts[r>>8].life++;
}
}
}
else if((r&0xFF)==PT_NSCN && oldl==1)
Expand Down
4 changes: 0 additions & 4 deletions src/simulation/elements/DMG.cpp
Expand Up @@ -76,15 +76,11 @@ int Element_DMG::update(UPDATE_FUNC_ARGS)
angle = atan2((float)nxj, nxi);
fx = cos(angle) * 7.0f;
fy = sin(angle) * 7.0f;

parts[rr>>8].vx += fx;
parts[rr>>8].vy += fy;

sim->vx[(y+nxj)/CELL][(x+nxi)/CELL] += fx;
sim->vy[(y+nxj)/CELL][(x+nxi)/CELL] += fy;

sim->pv[(y+nxj)/CELL][(x+nxi)/CELL] += 1.0f;

t = rr&0xFF;
if(t && sim->elements[t].HighPressureTransition>-1 && sim->elements[t].HighPressureTransition<PT_NUM)
sim->part_change_type(rr>>8, x+nxi, y+nxj, sim->elements[t].HighPressureTransition);
Expand Down
57 changes: 34 additions & 23 deletions src/simulation/elements/DSTW.cpp
Expand Up @@ -55,35 +55,46 @@ int Element_DSTW::update(UPDATE_FUNC_ARGS)
if (x+rx>=0 && y+ry>0 && x+rx<XRES && y+ry<YRES && (rx || ry))
{
r = pmap[y+ry][x+rx];
if (!r)
continue;
rt = r&0xFF;
if (rt==PT_SALT && !(rand()%250))
{
sim->part_change_type(i,x,y,PT_SLTW);
// on average, convert 3 DSTW to SLTW before SALT turns into SLTW
if (!(rand()%3))
sim->part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
}
if ((rt==PT_WATR||rt==PT_SLTW) && !(rand()%500))
{
sim->part_change_type(i,x,y,PT_WATR);
}
if (rt==PT_SLTW && !(rand()%10000))
{
sim->part_change_type(i,x,y,PT_SLTW);
}
if ((rt==PT_RBDM||rt==PT_LRBD) && (sim->legacy_enable||parts[i].temp>12.0f) && !(rand()%500))
switch (r&0xFF)
{
sim->part_change_type(i,x,y,PT_FIRE);
parts[i].life = 4;
}
if (rt==PT_FIRE){
case PT_SALT:
if (!(rand()%250))
{
sim->part_change_type(i,x,y,PT_SLTW);
// on average, convert 3 DSTW to SLTW before SALT turns into SLTW
if (!(rand()%3))
sim->part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
}
break;
case PT_SLTW:
if (!(rand()%10000))
{
sim->part_change_type(i,x,y,PT_SLTW);
break;
}
case PT_WATR:
if (!(rand()%500))
{
sim->part_change_type(i,x,y,PT_WATR);
}
break;
case PT_RBDM:
case PT_LRBD:
if ((sim->legacy_enable||parts[i].temp>12.0f) && !(rand()%500))
{
sim->part_change_type(i,x,y,PT_FIRE);
parts[i].life = 4;
}
break;
case PT_FIRE:
sim->kill_part(r>>8);
if(!(rand()%150)){
sim->kill_part(i);
return 1;
}
break;
default:
continue;
}
}
return 0;
Expand Down
56 changes: 21 additions & 35 deletions src/simulation/elements/ELEC.cpp
Expand Up @@ -66,12 +66,11 @@ int Element_ELEC::update(UPDATE_FUNC_ARGS)
if (!r)
continue;
rt = r&0xFF;
if (rt==PT_GLAS)
switch (rt)
{
case PT_GLAS:
for (rrx=-1; rrx<=1; rrx++)
{
for (rry=-1; rry<=1; rry++)
{
if (x+rx+rrx>=0 && y+ry+rry>=0 && x+rx+rrx<XRES && y+ry+rry<YRES) {
nb = sim->create_part(-1, x+rx+rrx, y+ry+rry, PT_EMBR);
if (nb!=-1) {
Expand All @@ -82,56 +81,43 @@ int Element_ELEC::update(UPDATE_FUNC_ARGS)
parts[nb].vy = rand()%20-10;
}
}
}
}
//fire_r[y/CELL][x/CELL] += rand()%200; //D: Doesn't work with OpenGL, also shouldn't be here
//fire_g[y/CELL][x/CELL] += rand()%200;
//fire_b[y/CELL][x/CELL] += rand()%200;
/* possible alternative, but doesn't work well at the moment because FIRE_ADD divides firea by 8, so the glow isn't strong enough
create_part(i, x, y, PT_EMBR);
parts[i].tmp = 2;
parts[i].life = 2;
parts[i].ctype = ((rand()%200)<<16) | ((rand()%200)<<8) | (rand()%200);
*/
sim->kill_part(i);
return 1;
}
if (rt==PT_LCRY)
{
case PT_LCRY:
parts[r>>8].tmp2 = 5+rand()%5;
}
if (rt==PT_WATR || rt==PT_DSTW || rt==PT_SLTW || rt==PT_CBNW)
{
break;
case PT_WATR:
case PT_DSTW:
case PT_SLTW:
case PT_CBNW:
if(!(rand()%3))
sim->create_part(r>>8, x+rx, y+ry, PT_O2);
else
sim->create_part(r>>8, x+rx, y+ry, PT_H2);
return 1;
}
if (rt==PT_NEUT)
{
case PT_NEUT:
sim->part_change_type(r>>8, x+rx, y+ry, PT_H2);
parts[r>>8].life = 0;
parts[r>>8].ctype = 0;
}
if (rt==PT_DEUT)
{
break;
case PT_DEUT:
if(parts[r>>8].life < 6000)
parts[r>>8].life += 1;
parts[r>>8].temp = 0;
sim->kill_part(i);
return 1;
}
if (rt==PT_EXOT)
{
case PT_EXOT:
parts[r>>8].tmp2 += 5;
parts[r>>8].life = 1000;
}
if ((sim->elements[rt].Properties & PROP_CONDUCTS) && (rt!=PT_NBLE||parts[i].temp<2273.15))
{
sim->create_part(-1, x+rx, y+ry, PT_SPRK);
sim->kill_part(i);
return 1;
break;
default:
if ((sim->elements[rt].Properties & PROP_CONDUCTS) && (rt!=PT_NBLE||parts[i].temp<2273.15))
{
sim->create_part(-1, x+rx, y+ry, PT_SPRK);
sim->kill_part(i);
return 1;
}
continue;
}
}
return 0;
Expand Down
97 changes: 56 additions & 41 deletions src/simulation/elements/EMP.cpp
Expand Up @@ -48,8 +48,8 @@ Element_EMP::Element_EMP()

//#TPT-Directive ElementHeader Element_EMP static int update(UPDATE_FUNC_ARGS)
int Element_EMP::update(UPDATE_FUNC_ARGS)
{
int r,rx,ry,t,n,nx,ny;
{
int r,rx,ry,t,n,nx,ny,ntype;
if (parts[i].life)
return 0;
for (rx=-2; rx<3; rx++)
Expand All @@ -76,71 +76,86 @@ int Element_EMP::update(UPDATE_FUNC_ARGS)
if (t==PT_SPRK || (t==PT_SWCH && parts[r].life!=0 && parts[r].life!=10) || (t==PT_WIRE && parts[r].ctype>0))
{
int is_elec=0;
if ((parts[r].ctype==PT_PSCN || parts[r].ctype==PT_NSCN || parts[r].ctype==PT_PTCT ||
parts[r].ctype==PT_NTCT || parts[r].ctype==PT_INST || parts[r].ctype==PT_SWCH) || t==PT_WIRE || t==PT_SWCH)
if (parts[r].ctype==PT_PSCN || parts[r].ctype==PT_NSCN || parts[r].ctype==PT_PTCT ||
parts[r].ctype==PT_NTCT || parts[r].ctype==PT_INST || parts[r].ctype==PT_SWCH || t==PT_WIRE || t==PT_SWCH)
{
is_elec=1;
if (sim->elements[parts[r].type].HeatConduct && !(rand()%100))
if (!(rand()%100))
parts[r].temp = restrict_flt(parts[r].temp+3000.0f, MIN_TEMP, MAX_TEMP);
if (!(rand()%80))
sim->part_change_type(r, rx, ry, PT_BREC);
else if (!(rand()%120))
sim->part_change_type(r, rx, ry, PT_NTCT);
}

for (nx=-2; nx<3; nx++)
for (ny=-2; ny<3; ny++)
if (rx+nx>=0 && ry+ny>=0 && rx+nx<XRES && ry+ny<YRES && (rx || ry))
{
n = pmap[ry+ny][rx+nx];
if (!n)
continue;
nt = n&0xFF;
ntype = n&0xFF;
//Some elements should only be affected by wire/swch, or by a spark on inst/semiconductor
//So not affected by spark on metl, watr etc
if (is_elec)
{
if ((nt==PT_METL || nt==PT_BMTL) && !(rand()%280))
switch (ntype)
{
parts[n>>8].temp = restrict_flt(parts[n>>8].temp+3000.0f, MIN_TEMP, MAX_TEMP);
case PT_METL:
if (!(rand()%280))
parts[n>>8].temp = restrict_flt(parts[n>>8].temp+3000.0f, MIN_TEMP, MAX_TEMP);
if (!(rand()%300))
sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL);
continue;
case PT_BMTL:
if (!(rand()%280))
parts[n>>8].temp = restrict_flt(parts[n>>8].temp+3000.0f, MIN_TEMP, MAX_TEMP);
if (!(rand()%160))
{
sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BRMT);
parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
}
continue;
case PT_WIFI:
if (!(rand()%8))
{
//Randomise channel
parts[n>>8].temp = rand()%MAX_TEMP;
}
if (!(rand()%16))
{
sim->create_part(n>>8, rx+nx, ry+ny, PT_BREC);
parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
}
continue;
default:
break;
}
if (nt==PT_BMTL && !(rand()%160))
}
switch (ntype)
{
case PT_SWCH:
if (!(rand()%100))
sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BREC);
if (!(rand()%100))
parts[n>>8].temp = restrict_flt(parts[n>>8].temp+2000.0f, MIN_TEMP, MAX_TEMP);
break;
case PT_ARAY:
if (!(rand()%60))
{
sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BRMT);
sim->create_part(n>>8, rx+nx, ry+ny, PT_BREC);
parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
}
if (nt==PT_METL && !(rand()%300))
break;
case PT_DLAY:
if (!(rand()%70))
{
sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BMTL);
}
if (nt==PT_WIFI && !(rand()%8))
{
//Randomise channel
parts[n>>8].temp = rand()%MAX_TEMP;
}
if (nt==PT_WIFI && !(rand()%16))
{
sim->create_part(n>>8, rx+nx, ry+ny, PT_BREC);
parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
//Randomise delay
parts[n>>8].temp = (rand()%256) + 273.15f;
}
}
if (nt==PT_SWCH && !(rand()%100))
{
sim->part_change_type(n>>8, rx+nx, ry+ny, PT_BREC);
}
if (nt==PT_SWCH && !(rand()%100))
{
parts[n>>8].temp = restrict_flt(parts[n>>8].temp+2000.0f, MIN_TEMP, MAX_TEMP);
}
if (nt==PT_ARAY && !(rand()%60))
{
sim->create_part(n>>8, rx+nx, ry+ny, PT_BREC);
parts[n>>8].temp = restrict_flt(parts[n>>8].temp+1000.0f, MIN_TEMP, MAX_TEMP);
}
if (nt==PT_DLAY && !(rand()%70))
{
//Randomise delay
parts[n>>8].temp = (rand()%256) + 273.15f;
break;
default:
break;
}
}
}
Expand Down
7 changes: 5 additions & 2 deletions src/simulation/elements/EXOT.cpp
Expand Up @@ -63,8 +63,11 @@ int Element_EXOT::update(UPDATE_FUNC_ARGS) {
parts[i].tmp2 += 100;
}
}
else if (rt == PT_EXOT && parts[r>>8].life == 1500 && !(rand()%1000))
parts[i].life = 1500;
else if (rt == PT_EXOT)
{
if (parts[r>>8].life == 1500 && !(rand()%1000))
parts[i].life = 1500;
}
else if (rt == PT_LAVA)
{
if (parts[r>>8].ctype == PT_TTAN && !(rand()%10))
Expand Down

0 comments on commit 0d70547

Please sign in to comment.