reduce rand() chances to 5x the old values in elements that were changed to 3x3 loop checks instead of 5x5. Also some other fixes I found when looking at what had been changed.

This commit is contained in:
jacob1 2013-05-20 11:26:51 -04:00
parent 77bf649fb4
commit 826b966668
14 changed files with 64 additions and 229 deletions

View File

@ -60,7 +60,7 @@ int Element_ANAR::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_CFLM && !(rand()%7))
if ((r&0xFF)==PT_CFLM && !(rand()%4))
{
sim->part_change_type(i,x,y,PT_CFLM);
parts[i].life = rand()%150+50;

View File

@ -42,82 +42,8 @@ Element_BCOL::Element_BCOL()
HighTemperature = ITH;
HighTemperatureTransition = NT;
Update = &Element_BCOL::update;
Graphics = &Element_BCOL::graphics;
Update = &Element_COAL::update;
Graphics = &Element_COAL::graphics;
}
//#TPT-Directive ElementHeader Element_BCOL static int update(UPDATE_FUNC_ARGS)
int Element_BCOL::update(UPDATE_FUNC_ARGS)
{
int r, rx, ry, trade, temp;
if (parts[i].life<=0) {
sim->create_part(i, x, y, PT_FIRE);
return 1;
} else if (parts[i].life < 100) {
parts[i].life--;
sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE);
}
/*if(100-parts[i].life > parts[i].tmp2)
parts[i].tmp2 = 100-parts[i].life;
if(parts[i].tmp2 < 0) parts[i].tmp2 = 0;
for ( trade = 0; trade<4; trade ++)
{
rx = rand()%5-2;
ry = rand()%5-2;
if (BOUNDS_CHECK && (rx || ry))
{
r = pmap[y+ry][x+rx];
if (!r)
continue;
if (((r&0xFF)==PT_COAL || (r&0xFF)==PT_BCOL)&&(parts[i].tmp2>parts[r>>8].tmp2)&&parts[i].tmp2>0)//diffusion
{
int temp = parts[i].tmp2 - parts[r>>8].tmp2;
if(temp < 10)
continue;
if (temp ==1)
{
parts[r>>8].tmp2 ++;
parts[i].tmp2 --;
}
else if (temp>0)
{
parts[r>>8].tmp2 += temp/2;
parts[i].tmp2 -= temp/2;
}
}
}
}*/
if(parts[i].temp > parts[i].tmp2)
parts[i].tmp2 = parts[i].temp;
return 0;
}
//#TPT-Directive ElementHeader Element_BCOL static int graphics(GRAPHICS_FUNC_ARGS)
int Element_BCOL::graphics(GRAPHICS_FUNC_ARGS)
//Both COAL and Broken Coal
{
*colr += (cpart->tmp2-295.15f)/3;
if (*colr > 170)
*colr = 170;
if (*colr < *colg)
*colr = *colg;
*colg = *colb = *colr;
if((cpart->temp-295.15f) > 300.0f-200.0f)
{
float frequency = 3.1415/(2*300.0f-(300.0f-200.0f));
int q = ((cpart->temp-295.15f)>300.0f)?300.0f-(300.0f-200.0f):(cpart->temp-295.15f)-(300.0f-200.0f);
*colr += sin(frequency*q) * 226;
*colg += sin(frequency*q*4.55 +3.14) * 34;
*colb += sin(frequency*q*2.22 +3.14) * 64;
}
return 0;
}
Element_BCOL::~Element_BCOL() {}

View File

@ -96,7 +96,7 @@ int Element_CBNW::update(UPDATE_FUNC_ARGS)
//Start explode
parts[i].tmp = rand()%25;//(rand()%100)+50;
}
else if((sim->elements[r&0xFF].Properties&TYPE_SOLID) && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_GLAS && parts[i].tmp == 0 && (2-sim->pv[y/CELL][x/CELL])>(rand()%13333))
else if((sim->elements[r&0xFF].Properties&TYPE_SOLID) && (r&0xFF)!=PT_DMND && (r&0xFF)!=PT_GLAS && parts[i].tmp == 0 && (2-sim->pv[y/CELL][x/CELL])>(rand()%6667))
{
sim->part_change_type(i,x,y,PT_CO2);
parts[i].ctype = 5;
@ -131,7 +131,7 @@ int Element_CBNW::update(UPDATE_FUNC_ARGS)
}
else if ((r&0xFF)==PT_FIRE && parts[r>>8].ctype!=PT_WATR){
sim->kill_part(r>>8);
if(1>(rand()%50)){
if(!(rand()%50)){
sim->kill_part(i);
return 1;
}

View File

@ -57,7 +57,7 @@ int Element_CO2::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx];
if (!r)
{
if (parts[i].ctype==5 && !(rand()%27))
if (parts[i].ctype==5 && !(rand()%2000))
{
if (sim->create_part(-1, x+rx, y+ry, PT_WATR)>=0)
parts[i].ctype = 0;
@ -66,12 +66,12 @@ int Element_CO2::update(UPDATE_FUNC_ARGS)
}
if ((r&0xFF)==PT_FIRE){
sim->kill_part(r>>8);
if(!(rand()%50)){
if(!(rand()%30)){
sim->kill_part(i);
return 1;
}
}
else if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && !(rand()%83))
else if (((r&0xFF)==PT_WATR || (r&0xFF)==PT_DSTW) && !(rand()%50))
{
sim->part_change_type(r>>8, x+rx, y+ry, PT_CBNW);
if (parts[i].ctype==5) //conserve number of water particles - ctype=5 means this CO2 hasn't released the water particle from BUBW yet

View File

@ -49,7 +49,7 @@ Element_COAL::Element_COAL()
//#TPT-Directive ElementHeader Element_COAL static int update(UPDATE_FUNC_ARGS)
int Element_COAL::update(UPDATE_FUNC_ARGS)
{
int r, rx, ry, trade, temp;
int r, rx, ry, trade, temp, t = parts[i].type;
if (parts[i].life<=0) {
sim->create_part(i, x, y, PT_FIRE);
return 1;
@ -57,6 +57,8 @@ int Element_COAL::update(UPDATE_FUNC_ARGS)
parts[i].life--;
sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, PT_FIRE);
}
if (t == PT_COAL)
{
if ((sim->pv[y/CELL][x/CELL] > 4.3f)&&parts[i].tmp>40)
parts[i].tmp=39;
else if (parts[i].tmp<40&&parts[i].tmp>0)
@ -65,6 +67,7 @@ int Element_COAL::update(UPDATE_FUNC_ARGS)
sim->create_part(i, x, y, PT_BCOL);
return 1;
}
}
/*if(100-parts[i].life > parts[i].tmp2)
parts[i].tmp2 = 100-parts[i].life;
if(parts[i].tmp2 < 0) parts[i].tmp2 = 0;

View File

@ -58,7 +58,7 @@ int Element_DSTW::update(UPDATE_FUNC_ARGS)
switch (r&0xFF)
{
case PT_SALT:
if (!(rand()%83))
if (!(rand()%50))
{
sim->part_change_type(i,x,y,PT_SLTW);
// on average, convert 3 DSTW to SLTW before SALT turns into SLTW
@ -67,20 +67,24 @@ int Element_DSTW::update(UPDATE_FUNC_ARGS)
}
break;
case PT_SLTW:
if (!(rand()%3333))
if (!(rand()%100))
{
sim->part_change_type(i,x,y,PT_WATR);
}
if (!(rand()%2000))
{
sim->part_change_type(i,x,y,PT_SLTW);
break;
}
case PT_WATR:
if (!(rand()%166))
if (!(rand()%100))
{
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()%166))
if ((sim->legacy_enable||parts[i].temp>12.0f) && !(rand()%100))
{
sim->part_change_type(i,x,y,PT_FIRE);
parts[i].life = 4;
@ -88,7 +92,7 @@ int Element_DSTW::update(UPDATE_FUNC_ARGS)
break;
case PT_FIRE:
sim->kill_part(r>>8);
if(!(rand()%50)){
if(!(rand()%30)){
sim->kill_part(i);
return 1;
}

View File

@ -63,14 +63,14 @@ int Element_ICEI::update(UPDATE_FUNC_ARGS)
continue;
if ((r&0xFF)==PT_SALT || (r&0xFF)==PT_SLTW)
{
if (parts[i].temp > sim->elements[PT_SLTW].LowTemperature && !(rand()%333))
if (parts[i].temp > sim->elements[PT_SLTW].LowTemperature && !(rand()%200))
{
sim->part_change_type(i,x,y,PT_SLTW);
sim->part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
return 0;
}
}
else if (((r&0xFF)==PT_FRZZ) && (parts[i].ctype=PT_FRZW) && !(rand()%333))
else if (((r&0xFF)==PT_FRZZ) && (parts[i].ctype=PT_FRZW) && !(rand()%200))
sim->part_change_type(r>>8,x+rx,y+ry,PT_ICEI);
}
return 0;

View File

@ -58,7 +58,7 @@ int Element_PLNT::update(UPDATE_FUNC_ARGS)
switch (r&0xFF)
{
case PT_WATR:
if (!(rand()%83))
if (!(rand()%50))
{
np = sim->create_part(r>>8,x+rx,y+ry,PT_PLNT);
if (np<0) continue;
@ -66,7 +66,7 @@ int Element_PLNT::update(UPDATE_FUNC_ARGS)
}
break;
case PT_LAVA:
if (!(rand()%83))
if (!(rand()%50))
{
sim->part_change_type(i,x,y,PT_FIRE);
parts[i].life = 4;
@ -74,14 +74,14 @@ int Element_PLNT::update(UPDATE_FUNC_ARGS)
break;
case PT_SMKE:
case PT_CO2:
if (!(rand()%83))
if (!(rand()%50))
{
sim->kill_part(r>>8);
parts[i].life = rand()%60 + 60;
}
break;
case PT_WOOD:
if (surround_space && !(rand()%7) && (abs(rx+ry)<=2) && (sim->VINE_MODE || parts[i].tmp==1))
if (surround_space && !(rand()%4) && (abs(rx+ry)<=2) && (sim->VINE_MODE || parts[i].tmp==1))
{
int nnx = rand()%3 -1;
int nny = rand()%3 -1;

View File

@ -26,7 +26,7 @@ Element_PQRT::Element_PQRT()
Weight = 90;
Temperature = R_TEMP+0.0f +273.15f;
Temperature = R_TEMP+273.15f;
HeatConduct = 3;
Description = "Powdered quartz, broken form of QRTZ.";
@ -42,113 +42,8 @@ Element_PQRT::Element_PQRT()
HighTemperature = 2573.15f;
HighTemperatureTransition = PT_LAVA;
Update = &Element_PQRT::update;
Graphics = &Element_PQRT::graphics;
Update = &Element_QRTZ::update;
Graphics = &Element_QRTZ::graphics;
}
//#TPT-Directive ElementHeader Element_PQRT static int update(UPDATE_FUNC_ARGS)
int Element_PQRT::update(UPDATE_FUNC_ARGS)
{
int r, tmp, trade, rx, ry, np;
// absorb SLTW
if (parts[i].ctype!=-1)
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
if (BOUNDS_CHECK && (rx || ry))
{
r = pmap[y+ry][x+rx];
if (!r)
continue;
else if ((r&0xFF)==PT_SLTW && !(rand()%833))
{
sim->kill_part(r>>8);
parts[i].ctype ++;
}
}
// grow and diffuse
if (parts[i].ctype>0)
{
bool stopgrow=false;
int rnd, sry, srx;
for ( trade = 0; trade<9; trade ++)
{
rnd = rand()%0x3FF;
rx = (rnd%5)-2;
srx = (rnd%3)-1;
rnd = rnd>>3;
ry = (rnd%5)-2;
sry = (rnd%3)-1;
if (BOUNDS_CHECK && (rx || ry))
{
if (!stopgrow)//try to grow
{
if (!pmap[y+sry][x+srx] && parts[i].ctype!=0)
{
np = sim->create_part(-1,x+srx,y+sry,PT_QRTZ);
if (np>-1)
{
parts[np].tmp = parts[i].tmp;
parts[i].ctype--;
if (rand()%2)
{
parts[np].ctype=-1;//dead qrtz
}
else if (!parts[i].ctype && !(rand()%15))
{
parts[i].ctype=-1;
}
stopgrow=true;
}
}
}
//diffusion
r = pmap[y+ry][x+rx];
if (!r)
continue;
else if ((r&0xFF)==PT_PQRT && (parts[i].ctype>parts[r>>8].ctype) && parts[r>>8].ctype>=0 )
{
tmp = parts[i].ctype - parts[r>>8].ctype;
if (tmp ==1)
{
parts[r>>8].ctype ++;
parts[i].ctype --;
break;
}
if (tmp>0)
{
parts[r>>8].ctype += tmp/2;
parts[i].ctype -= tmp/2;
break;
}
}
}
}
}
return 0;
}
//#TPT-Directive ElementHeader Element_PQRT static int graphics(GRAPHICS_FUNC_ARGS)
int Element_PQRT::graphics(GRAPHICS_FUNC_ARGS)
//QRTZ and PQRT
{
int t = cpart->type, z = cpart->tmp - 5;//speckles!
/*if (cpart->temp>(ptransitions[t].thv-800.0f))//hotglow for quartz
{
float frequency = 3.1415/(2*ptransitions[t].thv-(ptransitions[t].thv-800.0f));
int q = (cpart->temp>ptransitions[t].thv)?ptransitions[t].thv-(ptransitions[t].thv-800.0f):cpart->temp-(ptransitions[t].thv-800.0f);
*colr += sin(frequency*q) * 226 + (z * 16);
*colg += sin(frequency*q*4.55 +3.14) * 34 + (z * 16);
*colb += sin(frequency*q*2.22 +3.14) * 64 + (z * 16);
}
else*/
{
*colr += z * 16;
*colg += z * 16;
*colb += z * 16;
}
return 0;
}
Element_PQRT::~Element_PQRT() {}

View File

@ -26,7 +26,7 @@ Element_QRTZ::Element_QRTZ()
Weight = 100;
Temperature = R_TEMP+0.0f +273.15f;
Temperature = R_TEMP+273.15f;
HeatConduct = 3;
Description = "Quartz, breakable mineral. Conducts but becomes brittle at lower temperatures.";
@ -49,23 +49,26 @@ Element_QRTZ::Element_QRTZ()
//#TPT-Directive ElementHeader Element_QRTZ static int update(UPDATE_FUNC_ARGS)
int Element_QRTZ::update(UPDATE_FUNC_ARGS)
{
int r, tmp, trade, rx, ry, np;
int r, tmp, trade, rx, ry, np, t = parts[i].type;
if (t == PT_QRTZ)
{
parts[i].pavg[0] = parts[i].pavg[1];
parts[i].pavg[1] = sim->pv[y/CELL][x/CELL];
if (parts[i].pavg[1]-parts[i].pavg[0] > 0.05*(parts[i].temp/3) || parts[i].pavg[1]-parts[i].pavg[0] < -0.05*(parts[i].temp/3))
{
sim->part_change_type(i,x,y,PT_PQRT);
}
}
// absorb SLTW
if (parts[i].ctype!=-1)
for (rx=-2; rx<3; rx++)
for (ry=-2; ry<3; ry++)
for (rx=-1; rx<2; rx++)
for (ry=-1; ry<2; ry++)
if (BOUNDS_CHECK && (rx || ry))
{
r = pmap[y+ry][x+rx];
if (!r)
continue;
else if ((r&0xFF)==PT_SLTW && !(rand()%2500))
else if ((r&0xFF)==PT_SLTW && !(rand()%500))
{
sim->kill_part(r>>8);
parts[i].ctype ++;

View File

@ -58,16 +58,16 @@ int Element_SLTW::update(UPDATE_FUNC_ARGS)
switch (r&0xFF)
{
case PT_SALT:
if (!(rand()%3333))
if (!(rand()%2000))
sim->part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
break;
case PT_PLNT:
if (!(rand()%66))
if (!(rand()%40))
sim->kill_part(r>>8);
break;
case PT_RBDM:
case PT_LRBD:
if ((sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && !(rand()%166))
if ((sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && !(rand()%100))
{
sim->part_change_type(i,x,y,PT_FIRE);
parts[i].life = 4;
@ -78,7 +78,7 @@ int Element_SLTW::update(UPDATE_FUNC_ARGS)
if (parts[r>>8].ctype!=PT_WATR)
{
sim->kill_part(r>>8);
if(!(rand()%150)){
if(!(rand()%30)){
sim->kill_part(i);
return 1;
}

View File

@ -57,14 +57,14 @@ int Element_WATR::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_SALT && !(rand()%83))
if ((r&0xFF)==PT_SALT && !(rand()%50))
{
sim->part_change_type(i,x,y,PT_SLTW);
// on average, convert 3 WATR to SLTW before SALT turns into SLTW
if (!(rand()%3))
sim->part_change_type(r>>8,x+rx,y+ry,PT_SLTW);
}
else if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && !(rand()%166))
else if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && (sim->legacy_enable||parts[i].temp>(273.15f+12.0f)) && !(rand()%100))
{
sim->part_change_type(i,x,y,PT_FIRE);
parts[i].life = 4;
@ -72,12 +72,16 @@ int Element_WATR::update(UPDATE_FUNC_ARGS)
}
else if ((r&0xFF)==PT_FIRE && parts[r>>8].ctype!=PT_WATR){
sim->kill_part(r>>8);
if(!(rand()%50)){
if(!(rand()%30)){
sim->kill_part(i);
return 1;
}
}
/*if ((r&0xFF)==PT_CNCT && 1>(rand()%500)) Concrete+Water to paste, not very popular
else if ((r&0xFF)==PT_SLTW && !(rand()%2000))
{
sim->part_change_type(i,x,y,PT_SLTW);
}
/*if ((r&0xFF)==PT_CNCT && !(rand()%100)) Concrete+Water to paste, not very popular
{
part_change_type(i,x,y,PT_PSTE);
sim.kill_part(r>>8);

View File

@ -57,7 +57,7 @@ int Element_WTRV::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx];
if (!r)
continue;
if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && !sim->legacy_enable && parts[i].temp>(273.15f+12.0f) && !(rand()%166))
if (((r&0xFF)==PT_RBDM||(r&0xFF)==PT_LRBD) && !sim->legacy_enable && parts[i].temp>(273.15f+12.0f) && !(rand()%100))
{
sim->part_change_type(i,x,y,PT_FIRE);
parts[i].life = 4;

View File

@ -57,7 +57,7 @@ int Element_YEST::update(UPDATE_FUNC_ARGS)
r = pmap[y+ry][x+rx];
if (!r)
continue;
if ((r&0xFF)==PT_DYST && !(rand()%10) && !sim->legacy_enable)
if ((r&0xFF)==PT_DYST && !(rand()%6) && !sim->legacy_enable)
{
sim->part_change_type(i,x,y,PT_DYST);
}