mirror of
https://github.com/The-Powder-Toy/The-Powder-Toy.git
synced 2025-08-23 16:33:00 +02:00
fixes to rndstore in VIBR/VIRS, remove goto in PROT
This commit is contained in:
@@ -87,7 +87,7 @@ int Element_PROT::update(UPDATE_FUNC_ARGS)
|
|||||||
else if (parts[i].temp > 373.15f) change = 100.0f;
|
else if (parts[i].temp > 373.15f) change = 100.0f;
|
||||||
else change = 0.0f;
|
else change = 0.0f;
|
||||||
parts[under>>8].temp = restrict_flt(parts[under>>8].temp + change, MIN_TEMP, MAX_TEMP);
|
parts[under>>8].temp = restrict_flt(parts[under>>8].temp + change, MIN_TEMP, MAX_TEMP);
|
||||||
goto no_temp_change;
|
break;
|
||||||
case PT_NONE:
|
case PT_NONE:
|
||||||
//slowly kill if it's not inside an element
|
//slowly kill if it's not inside an element
|
||||||
if (parts[i].life)
|
if (parts[i].life)
|
||||||
@@ -95,7 +95,7 @@ int Element_PROT::update(UPDATE_FUNC_ARGS)
|
|||||||
if (!--parts[i].life)
|
if (!--parts[i].life)
|
||||||
sim->kill_part(i);
|
sim->kill_part(i);
|
||||||
}
|
}
|
||||||
goto no_temp_change;
|
break;
|
||||||
default:
|
default:
|
||||||
//set off explosives (only when hot because it wasn't as fun when it made an entire save explode)
|
//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))
|
if (parts[i].temp > 273.15f + 500.0f && (sim->elements[utype].Flammable || sim->elements[utype].Explosive || utype == PT_BANG))
|
||||||
@@ -112,9 +112,8 @@ int Element_PROT::update(UPDATE_FUNC_ARGS)
|
|||||||
break;
|
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
|
//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);
|
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);
|
||||||
no_temp_change:
|
|
||||||
|
|
||||||
|
|
||||||
//if this proton has collided with another last frame, change it into a heavier element
|
//if this proton has collided with another last frame, change it into a heavier element
|
||||||
|
@@ -48,7 +48,7 @@ Element_VIBR::Element_VIBR()
|
|||||||
|
|
||||||
//#TPT-Directive ElementHeader Element_VIBR static int update(UPDATE_FUNC_ARGS)
|
//#TPT-Directive ElementHeader Element_VIBR static int update(UPDATE_FUNC_ARGS)
|
||||||
int Element_VIBR::update(UPDATE_FUNC_ARGS) {
|
int Element_VIBR::update(UPDATE_FUNC_ARGS) {
|
||||||
int r, rx, ry, random;
|
int r, rx, ry, rndstore;
|
||||||
int trade, transfer;
|
int trade, transfer;
|
||||||
if (!parts[i].life) //if not exploding
|
if (!parts[i].life) //if not exploding
|
||||||
{
|
{
|
||||||
@@ -83,9 +83,10 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) {
|
|||||||
//Release sparks before explode
|
//Release sparks before explode
|
||||||
if (parts[i].life < 300)
|
if (parts[i].life < 300)
|
||||||
{
|
{
|
||||||
random = rand();
|
rndstore = rand();
|
||||||
rx = random%3-1;
|
rx = rndstore%3-1;
|
||||||
ry = (random>>2)%3-1;
|
ry = (rndstore>>2)%3-1;
|
||||||
|
rndstore = rndstore >> 4;
|
||||||
r = pmap[y+ry][x+rx];
|
r = pmap[y+ry][x+rx];
|
||||||
if ((r&0xFF) && (r&0xFF) != PT_BREC && (sim->elements[r&0xFF].Properties&PROP_CONDUCTS) && !parts[r>>8].life)
|
if ((r&0xFF) && (r&0xFF) != PT_BREC && (sim->elements[r&0xFF].Properties&PROP_CONDUCTS) && !parts[r>>8].life)
|
||||||
{
|
{
|
||||||
@@ -97,9 +98,8 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) {
|
|||||||
//Release all heat
|
//Release all heat
|
||||||
if (parts[i].life < 500)
|
if (parts[i].life < 500)
|
||||||
{
|
{
|
||||||
random = rand();
|
rx = rndstore%7-1;
|
||||||
rx = random%7-3;
|
ry = (rndstore>>3)%7-1;
|
||||||
ry = (random>>3)%7-3;
|
|
||||||
if(BOUNDS_CHECK)
|
if(BOUNDS_CHECK)
|
||||||
{
|
{
|
||||||
r = pmap[y+ry][x+rx];
|
r = pmap[y+ry][x+rx];
|
||||||
@@ -115,19 +115,19 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) {
|
|||||||
{
|
{
|
||||||
if (!parts[i].tmp2)
|
if (!parts[i].tmp2)
|
||||||
{
|
{
|
||||||
int index;
|
rndstore = rand();
|
||||||
random = rand();
|
|
||||||
sim->create_part(i, x, y, PT_EXOT);
|
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)
|
if (index != -1)
|
||||||
parts[index].temp = 7000;
|
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)
|
if (index != -1)
|
||||||
parts[index].temp = 7000;
|
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)
|
if (index != -1)
|
||||||
parts[index].temp = 7000;
|
parts[index].temp = 7000;
|
||||||
parts[i].tmp2 = (random>>16) % 1000;
|
parts[i].tmp2 = (rndstore>>16) % 1000;
|
||||||
parts[i].temp=9000;
|
parts[i].temp=9000;
|
||||||
sim->pv[y/CELL][x/CELL] += 50;
|
sim->pv[y/CELL][x/CELL] += 50;
|
||||||
|
|
||||||
@@ -174,7 +174,7 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) {
|
|||||||
if ((r&0xFF) == PT_EXOT && !(rand()%25))
|
if ((r&0xFF) == PT_EXOT && !(rand()%25))
|
||||||
{
|
{
|
||||||
sim->part_change_type(i, x, y, PT_EXOT);
|
sim->part_change_type(i, x, y, PT_EXOT);
|
||||||
return 0;
|
return 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//VIBR+ANAR=BVBR
|
//VIBR+ANAR=BVBR
|
||||||
@@ -186,12 +186,12 @@ int Element_VIBR::update(UPDATE_FUNC_ARGS) {
|
|||||||
}
|
}
|
||||||
for (trade = 0; trade < 9; trade++)
|
for (trade = 0; trade < 9; trade++)
|
||||||
{
|
{
|
||||||
if (!(trade%5))
|
if (!(trade%2))
|
||||||
random = rand();
|
rndstore = rand();
|
||||||
rx = random%7-3;
|
rx = rndstore%7-3;
|
||||||
random >>= 3;
|
rndstore >>= 3;
|
||||||
ry = random%7-3;
|
ry = rndstore%7-3;
|
||||||
random >>= 3;
|
rndstore >>= 3;
|
||||||
if (BOUNDS_CHECK && (rx || ry))
|
if (BOUNDS_CHECK && (rx || ry))
|
||||||
{
|
{
|
||||||
r = pmap[y+ry][x+rx];
|
r = pmap[y+ry][x+rx];
|
||||||
|
@@ -69,24 +69,15 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS)
|
|||||||
//decrease pavg[1] so it slowly dies
|
//decrease pavg[1] so it slowly dies
|
||||||
if (parts[i].pavg[1])
|
if (parts[i].pavg[1])
|
||||||
{
|
{
|
||||||
if (!(rndstore & 0x7))
|
if (!(rndstore & 0x7) && --parts[i].pavg[1] <= 0)
|
||||||
{
|
{
|
||||||
parts[i].pavg[1]--;
|
sim->kill_part(i);
|
||||||
//if pavg[1] is now 0, kill it
|
return 1;
|
||||||
if (!parts[i].pavg[1])
|
|
||||||
{
|
|
||||||
sim->kill_part(i);
|
|
||||||
return 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
rndstore >>= 3;
|
rndstore >>= 3;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (rx=-1; rx<2; rx++)
|
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++)
|
for (ry=-1; ry<2; ry++)
|
||||||
{
|
{
|
||||||
if (BOUNDS_CHECK && (rx || ry))
|
if (BOUNDS_CHECK && (rx || ry))
|
||||||
@@ -122,14 +113,10 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS)
|
|||||||
{
|
{
|
||||||
if (!(rndstore & 0x7))
|
if (!(rndstore & 0x7))
|
||||||
{
|
{
|
||||||
rndstore >>= 3;
|
|
||||||
parts[r>>8].tmp2 = (r&0xFF);
|
parts[r>>8].tmp2 = (r&0xFF);
|
||||||
parts[r>>8].pavg[0] = 0;
|
parts[r>>8].pavg[0] = 0;
|
||||||
if (parts[i].pavg[1])
|
if (parts[i].pavg[1])
|
||||||
{
|
parts[r>>8].pavg[1] = parts[i].pavg[1] + 1;
|
||||||
parts[r>>8].pavg[1] = parts[i].pavg[1] + ((rndstore % 3) ? 1 : 0);
|
|
||||||
rndstore >>= 2;
|
|
||||||
}
|
|
||||||
else
|
else
|
||||||
parts[r>>8].pavg[1] = 0;
|
parts[r>>8].pavg[1] = 0;
|
||||||
if (parts[r>>8].temp < 305.0f)
|
if (parts[r>>8].temp < 305.0f)
|
||||||
@@ -139,8 +126,7 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS)
|
|||||||
else
|
else
|
||||||
sim->part_change_type(r>>8, x+rx, y+ry, PT_VIRS);
|
sim->part_change_type(r>>8, x+rx, y+ry, PT_VIRS);
|
||||||
}
|
}
|
||||||
else
|
rndstore >>= 3;
|
||||||
rndstore >>= 3;
|
|
||||||
}
|
}
|
||||||
//protons make VIRS last forever
|
//protons make VIRS last forever
|
||||||
else if ((sim->photons[y+ry][x+rx]&0xFF) == PT_PROT)
|
else if ((sim->photons[y+ry][x+rx]&0xFF) == PT_PROT)
|
||||||
@@ -148,8 +134,10 @@ int Element_VIRS::update(UPDATE_FUNC_ARGS)
|
|||||||
parts[i].pavg[1] = 0;
|
parts[i].pavg[1] = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
//reset rndstore only once, halfway through
|
||||||
|
else if (!rx && !ry)
|
||||||
|
rndstore = rand();
|
||||||
}
|
}
|
||||||
}
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Reference in New Issue
Block a user