From 6c4f63be3b003f55360e690c7bac9d3dd536408f Mon Sep 17 00:00:00 2001 From: jacob1 Date: Mon, 2 Sep 2013 21:58:52 -0400 Subject: proton collision reaction (might need to be modified). Also some ways to go to/from protons diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp index 2287920..abf107d 100644 --- a/src/simulation/Simulation.cpp +++ b/src/simulation/Simulation.cpp @@ -2024,7 +2024,8 @@ void Simulation::init_can_move() if (destinationType == PT_GLAS || destinationType == PT_PHOT || destinationType == PT_FILT || destinationType == PT_INVIS || destinationType == PT_CLNE || destinationType == PT_PCLN || destinationType == PT_BCLN || destinationType == PT_PBCN || destinationType == PT_WATR || destinationType == PT_DSTW || destinationType == PT_SLTW || destinationType == PT_GLOW - || destinationType == PT_ISOZ || destinationType == PT_ISZS || destinationType == PT_QRTZ || destinationType == PT_PQRT) + || destinationType == PT_ISOZ || destinationType == PT_ISZS || destinationType == PT_QRTZ || destinationType == PT_PQRT + || destinationType == PT_H2) can_move[PT_PHOT][destinationType] = 2; if (destinationType != PT_DMND && destinationType != PT_INSL && destinationType != PT_VOID && destinationType != PT_PVOD) can_move[PT_PROT][destinationType] = 2; @@ -2165,7 +2166,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) if ((r & 0xFF) < PT_NUM && elements[r&0xFF].HeatConduct && ((r&0xFF)!=PT_HSWC||parts[r>>8].life==10) && (r&0xFF)!=PT_FILT) parts[i].temp = parts[r>>8].temp = restrict_flt((parts[r>>8].temp+parts[i].temp)/2, MIN_TEMP, MAX_TEMP); } - if ((parts[i].type==PT_NEUT || parts[i].type==PT_ELEC) && ((r&0xFF)==PT_CLNE || (r&0xFF)==PT_PCLN || (r&0xFF)==PT_BCLN || (r&0xFF)==PT_PBCN)) { + else if ((parts[i].type==PT_NEUT || parts[i].type==PT_ELEC) && ((r&0xFF)==PT_CLNE || (r&0xFF)==PT_PCLN || (r&0xFF)==PT_BCLN || (r&0xFF)==PT_PBCN)) { if (!parts[r>>8].ctype) parts[r>>8].ctype = parts[i].type; } @@ -2194,49 +2195,64 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) if (e == 2) //if occupy same space { - if (parts[i].type == PT_PHOT && (r&0xFF)==PT_GLOW && !parts[r>>8].life) - if (rand() < RAND_MAX/30) + if (parts[i].type == PT_PHOT) + { + if ((r&0xFF) == PT_GLOW) { - parts[r>>8].life = 120; - create_gain_photon(i); + if (!parts[r>>8].life && rand() < RAND_MAX/30) + { + parts[r>>8].life = 120; + create_gain_photon(i); + } + } + else if ((r&0xFF) == PT_FILT) + parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype); + else if ((r&0xFF) == PT_INVIS) + { + if (pv[ny/CELL][nx/CELL]<=4.0f && pv[ny/CELL][nx/CELL]>=-4.0f) + { + part_change_type(i,x,y,PT_NEUT); + parts[i].ctype = 0; + } + } + else if ((r&0xFF)==PT_BIZR || (r&0xFF)==PT_BIZRG || (r&0xFF)==PT_BIZRS) + { + part_change_type(i, x, y, PT_ELEC); + parts[i].ctype = 0; + } + else if ((r&0xFF) == PT_H2) + { + part_change_type(i, x, y, PT_PROT); + parts[i].ctype = 0; } - if (parts[i].type == PT_PHOT && (r&0xFF)==PT_FILT) - { - parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype); - } - if (parts[i].type == PT_NEUT && (r&0xFF)==PT_GLAS) { - if (rand() < RAND_MAX/10) - create_cherenkov_photon(i); } - if (parts[i].type == PT_PHOT && (r&0xFF)==PT_INVIS && pv[ny/CELL][nx/CELL]<=4.0f && pv[ny/CELL][nx/CELL]>=-4.0f) { - part_change_type(i,x,y,PT_NEUT); - parts[i].ctype = 0; + else if (parts[i].type == PT_NEUT) + { + if ((r&0xFF) == PT_GLAS) + if (rand() < RAND_MAX/10) + create_cherenkov_photon(i); } - if ((parts[i].type==PT_BIZR||parts[i].type==PT_BIZRG) && (r&0xFF)==PT_FILT) + else if (parts[i].type == PT_PROT) { - parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype); + if ((r&0xFF) == PT_INVIS) + part_change_type(i, x, y, PT_NEUT); } - if (((r&0xFF)==PT_BIZR || (r&0xFF)==PT_BIZRG || (r&0xFF)==PT_BIZRS) && parts[i].type==PT_PHOT) + else if ((parts[i].type==PT_BIZR || parts[i].type==PT_BIZRG)) { - part_change_type(i, x, y, PT_ELEC); - parts[i].ctype = 0; + if ((r&0xFF) == PT_FILT) + parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype); } return 1; } //else e=1 , we are trying to swap the particles, return 0 no swap/move, 1 is still overlap/move, because the swap takes place later - if (parts[i].type == PT_NEUT && (elements[r & 0xFF].Properties & PROP_NEUTABSORB)) - { - kill_part(i); - return 0; - } if ((r&0xFF)==PT_VOID || (r&0xFF)==PT_PVOD) //this is where void eats particles { //void ctype already checked in eval_move kill_part(i); return 0; } - if ((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) //this is where blackhole eats particles + else if ((r&0xFF)==PT_BHOL || (r&0xFF)==PT_NBHL) //this is where blackhole eats particles { if (!legacy_enable) { @@ -2245,39 +2261,61 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny) kill_part(i); return 0; } - if (((r&0xFF)==PT_WHOL||(r&0xFF)==PT_NWHL) && parts[i].type==PT_ANAR) //whitehole eats anar + else if (((r&0xFF)==PT_WHOL || (r&0xFF)==PT_NWHL)) //whitehole eats anar { - if (!legacy_enable) + if (parts[i].type == PT_ANAR) { - parts[r>>8].temp = restrict_flt(parts[r>>8].temp- (MAX_TEMP-parts[i].temp)/2, MIN_TEMP, MAX_TEMP); + if (!legacy_enable) + { + parts[r>>8].temp = restrict_flt(parts[r>>8].temp- (MAX_TEMP-parts[i].temp)/2, MIN_TEMP, MAX_TEMP); + } + kill_part(i); + return 0; } - kill_part(i); - return 0; } - if ((r&0xFF)==PT_DEUT && parts[i].type==PT_ELEC) + else if ((r&0xFF)==PT_DEUT) { - if(parts[r>>8].life < 6000) - parts[r>>8].life += 1; - parts[r>>8].temp = 0; - kill_part(i); - return 0; + if (parts[i].type == PT_ELEC) + { + if(parts[r>>8].life < 6000) + parts[r>>8].life += 1; + parts[r>>8].temp = 0; + kill_part(i); + return 0; + } } - if (((r&0xFF)==PT_VIBR || (r&0xFF)==PT_BVBR) && (elements[parts[i].type].Properties & TYPE_ENERGY)) + if (((r&0xFF)==PT_VIBR || (r&0xFF)==PT_BVBR)) { - parts[r>>8].tmp += 20; - kill_part(i); - return 0; + if ((elements[parts[i].type].Properties & TYPE_ENERGY)) + { + parts[r>>8].tmp += 20; + kill_part(i); + return 0; + } } - if (parts[i].type==PT_CNCT && y0) + return 0; + } if ((bmap[y/CELL][x/CELL]==WL_EHOLE && !emap[y/CELL][x/CELL]) && !(bmap[ny/CELL][nx/CELL]==WL_EHOLE && !emap[ny/CELL][nx/CELL])) return 0; - if(parts[i].type==PT_GBMB&&parts[i].life>0) - return 0; - e = r >> 8; //e is now the particle number at r (pmap[ny][nx]) if (r)//the swap part, if we make it this far, swap { @@ -2980,7 +3018,7 @@ int Simulation::create_part(int p, int x, int y, int tv) } case PT_PROT: { - float a = (rand()%72)* 0.08727f; + float a = (rand()%36)* 0.17453f; parts[i].life = 680; parts[i].vx = 2.0f*cosf(a); parts[i].vy = 2.0f*sinf(a); diff --git a/src/simulation/elements/PROT.cpp b/src/simulation/elements/PROT.cpp index 87f8e4c..133be65 100644 --- a/src/simulation/elements/PROT.cpp +++ b/src/simulation/elements/PROT.cpp @@ -49,7 +49,7 @@ Element_PROT::Element_PROT() //#TPT-Directive ElementHeader Element_PROT static int update(UPDATE_FUNC_ARGS) int Element_PROT::update(UPDATE_FUNC_ARGS) { - sim->pv[y/CELL][x/CELL] -= .005f; + sim->pv[y/CELL][x/CELL] -= .003f; int under = pmap[y][x]; //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[under&0xFF].Flammable || sim->elements[under&0xFF].Explosive || (under&0xFF) == PT_BANG)) @@ -81,6 +81,47 @@ int Element_PROT::update(UPDATE_FUNC_ARGS) //else, slowly kill it if it's not inside an element else parts[i].life--; + + //if this proton has collided with another last frame, change it into a heavier element + if (parts[i].tmp) + { + int newID, element; + if (parts[i].tmp > 4250) + element = PT_SING; //particle accelerators are known to create earth-destroying black holes + else if (parts[i].tmp > 275) + element = PT_PLUT; + else if (parts[i].tmp > 170) + element = PT_URAN; + else if (parts[i].tmp > 100) + element = PT_PLSM; + else if (parts[i].tmp > 40) + element = PT_O2; + else if (parts[i].tmp > 20) + element = PT_CO2; + else + element = PT_NBLE; + newID = sim->create_part(-1, x+rand()%3-1, y+rand()%3-1, element); + parts[newID].temp = restrict_flt(100.0f*parts[i].tmp, MIN_TEMP, MAX_TEMP); + sim->kill_part(i); + return 1; + } + //collide with other protons to make heavier materials + int ahead = sim->photons[y][x]; + if ((ahead>>8) != i && (ahead&0xFF) == PT_PROT) + { + float velocity1 = powf(parts[i].vx, 2.0f)+powf(parts[i].vy, 2.0f); + float velocity2 = powf(parts[ahead>>8].vx, 2.0f)+powf(parts[ahead>>8].vy, 2.0f); + float direction1 = atan2f(-parts[i].vy, parts[i].vx); + float direction2 = atan2f(-parts[ahead>>8].vy, parts[ahead>>8].vx); + float difference = direction1 - direction2; if (difference < 0) difference += 6.28319f; + + if (difference > 3.12659f && difference < 3.15659f && velocity1 + velocity2 > 10.0f) + { + parts[ahead>>8].tmp += (int)(velocity1 + velocity2); + sim->kill_part(i); + return 1; + } + } return 0; } -- cgit v0.9.2-21-gd62e