Skip to content

Commit

Permalink
fixes to rndstore in VIBR/VIRS, remove goto in PROT
Browse files Browse the repository at this point in the history
  • Loading branch information
jacob1 committed Jan 8, 2015
1 parent 34c85c2 commit be6551c
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 45 deletions.
9 changes: 4 additions & 5 deletions src/simulation/elements/PROT.cpp
Expand Up @@ -87,15 +87,15 @@ int Element_PROT::update(UPDATE_FUNC_ARGS)
else if (parts[i].temp > 373.15f) change = 100.0f;
else change = 0.0f;
parts[under>>8].temp = restrict_flt(parts[under>>8].temp + change, MIN_TEMP, MAX_TEMP);
goto no_temp_change;
break;
case PT_NONE:
//slowly kill if it's not inside an element
if (parts[i].life)
{
if (!--parts[i].life)
sim->kill_part(i);
}
goto no_temp_change;
break;
default:
//set off explosives (only when hot because it wasn't as fun when it made an entire save explode)
if (parts[i].temp > 273.15f + 500.0f && (sim->elements[utype].Flammable || sim->elements[utype].Explosive || utype == PT_BANG))
Expand All @@ -112,9 +112,8 @@ int Element_PROT::update(UPDATE_FUNC_ARGS)
break;
}
//make temp of other things closer to it's own temperature. This will change temp of things that don't conduct, and won't change the PROT's temperature
parts[under>>8].temp = restrict_flt(parts[under>>8].temp - (parts[under>>8].temp - parts[i].temp) / 4.0f, MIN_TEMP, MAX_TEMP);

no_temp_change:
if (utype && utype != PT_WIFI)
parts[under>>8].temp = restrict_flt(parts[under>>8].temp-(parts[under>>8].temp-parts[i].temp)/4.0f, MIN_TEMP, MAX_TEMP);


//if this proton has collided with another last frame, change it into a heavier element
Expand Down
40 changes: 20 additions & 20 deletions src/simulation/elements/VIBR.cpp
Expand Up @@ -48,7 +48,7 @@ Element_VIBR::Element_VIBR()

//#TPT-Directive ElementHeader Element_VIBR static int update(UPDATE_FUNC_ARGS)
int Element_VIBR::update(UPDATE_FUNC_ARGS) {
int r, rx, ry, random;
int r, rx, ry, rndstore;
int trade, transfer;
if (!parts[i].life) //if not exploding
{
Expand Down Expand Up @@ -83,9 +83,10 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) {
//Release sparks before explode
if (parts[i].life < 300)
{
random = rand();
rx = random%3-1;
ry = (random>>2)%3-1;
rndstore = rand();
rx = rndstore%3-1;
ry = (rndstore>>2)%3-1;
rndstore = rndstore >> 4;
r = pmap[y+ry][x+rx];
if ((r&0xFF) && (r&0xFF) != PT_BREC && (sim->elements[r&0xFF].Properties&PROP_CONDUCTS) && !parts[r>>8].life)
{
Expand All @@ -97,9 +98,8 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) {
//Release all heat
if (parts[i].life < 500)
{
random = rand();
rx = random%7-3;
ry = (random>>3)%7-3;
rx = rndstore%7-1;
ry = (rndstore>>3)%7-1;
if(BOUNDS_CHECK)
{
r = pmap[y+ry][x+rx];
Expand All @@ -115,19 +115,19 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) {
{
if (!parts[i].tmp2)
{
int index;
random = rand();
rndstore = rand();
sim->create_part(i, x, y, PT_EXOT);
index = sim->create_part(-3,x+((random>>4)&3)-1,y+((random>>6)&3)-1,PT_ELEC);
parts[i].tmp2 = rand()%1000;
int index = sim->create_part(-3,x+((rndstore>>4)&3)-1,y+((rndstore>>6)&3)-1,PT_ELEC);
if (index != -1)
parts[index].temp = 7000;
index = sim->create_part(-3,x+((random>>8)&3)-1,y+((random>>10)&3)-1,PT_PHOT);
index = sim->create_part(-3,x+((rndstore>>8)&3)-1,y+((rndstore>>10)&3)-1,PT_PHOT);
if (index != -1)
parts[index].temp = 7000;
index = sim->create_part(-1,x+((random>>12)&3)-1,y+(random>>14)%3-1,PT_BREC);
index = sim->create_part(-1,x+((rndstore>>12)&3)-1,y+rand()%3-1,PT_BREC);
if (index != -1)
parts[index].temp = 7000;
parts[i].tmp2 = (random>>16) % 1000;
parts[i].tmp2 = (rndstore>>16) % 1000;
parts[i].temp=9000;
sim->pv[y/CELL][x/CELL] += 50;

Expand Down Expand Up @@ -174,7 +174,7 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) {
if ((r&0xFF) == PT_EXOT && !(rand()%25))
{
sim->part_change_type(i, x, y, PT_EXOT);
return 0;
return 1;
}
}
//VIBR+ANAR=BVBR
Expand All @@ -186,12 +186,12 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) {
}
for (trade = 0; trade < 9; trade++)
{
if (!(trade%5))
random = rand();
rx = random%7-3;
random >>= 3;
ry = random%7-3;
random >>= 3;
if (!(trade%2))
rndstore = rand();
rx = rndstore%7-3;
rndstore >>= 3;
ry = rndstore%7-3;
rndstore >>= 3;
if (BOUNDS_CHECK && (rx || ry))
{
r = pmap[y+ry][x+rx];
Expand Down
28 changes: 8 additions & 20 deletions src/simulation/elements/VIRS.cpp
Expand Up @@ -69,24 +69,15 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS)
//decrease pavg[1] so it slowly dies
if (parts[i].pavg[1])
{
if (!(rndstore & 0x7))
if (!(rndstore & 0x7) && --parts[i].pavg[1] <= 0)
{
parts[i].pavg[1]--;
//if pavg[1] is now 0, kill it
if (!parts[i].pavg[1])
{
sim->kill_part(i);
return 1;
}
sim->kill_part(i);
return 1;
}
rndstore >>= 3;
}

for (rx=-1; rx<2; rx++)
{
//reset rndstore once, 1st rand has possible 3+15 bits max, this one has 30 max.
if (!rx)
rndstore = rand();
for (ry=-1; ry<2; ry++)
{
if (BOUNDS_CHECK && (rx || ry))
Expand Down Expand Up @@ -122,14 +113,10 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS)
{
if (!(rndstore & 0x7))
{
rndstore >>= 3;
parts[r>>8].tmp2 = (r&0xFF);
parts[r>>8].pavg[0] = 0;
if (parts[i].pavg[1])
{
parts[r>>8].pavg[1] = parts[i].pavg[1] + ((rndstore % 3) ? 1 : 0);
rndstore >>= 2;
}
parts[r>>8].pavg[1] = parts[i].pavg[1] + 1;
else
parts[r>>8].pavg[1] = 0;
if (parts[r>>8].temp < 305.0f)
Expand All @@ -139,17 +126,18 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS)
else
sim->part_change_type(r>>8, x+rx, y+ry, PT_VIRS);
}
else
rndstore >>= 3;
rndstore >>= 3;
}
//protons make VIRS last forever
else if ((sim->photons[y+ry][x+rx]&0xFF) == PT_PROT)
{
parts[i].pavg[1] = 0;
}
}
//reset rndstore only once, halfway through
else if (!rx && !ry)
rndstore = rand();
}
}
return 0;
}

Expand Down

0 comments on commit be6551c

Please sign in to comment.