summaryrefslogtreecommitdiff
path: root/src/simulation
diff options
context:
space:
mode:
Diffstat (limited to 'src/simulation')
-rw-r--r--src/simulation/Simulation.cpp18
-rw-r--r--src/simulation/elements/ARAY.cpp2
-rw-r--r--src/simulation/elements/CRAY.cpp2
-rw-r--r--src/simulation/elements/DTEC.cpp26
-rw-r--r--src/simulation/elements/FILT.cpp63
5 files changed, 85 insertions, 26 deletions
diff --git a/src/simulation/Simulation.cpp b/src/simulation/Simulation.cpp
index c1cf22e..64371ac 100644
--- a/src/simulation/Simulation.cpp
+++ b/src/simulation/Simulation.cpp
@@ -2200,18 +2200,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
}
if (parts[i].type == PT_PHOT && (r&0xFF)==PT_FILT)
{
- int temp_bin = (int)((parts[r>>8].temp-273.0f)*0.025f);
- if (temp_bin < 0) temp_bin = 0;
- if (temp_bin > 25) temp_bin = 25;
- if(!parts[r>>8].tmp){
- parts[i].ctype = 0x1F << temp_bin; //Assign Colour
- } else if(parts[r>>8].tmp==1){
- parts[i].ctype &= 0x1F << temp_bin; //Filter Colour
- } else if(parts[r>>8].tmp==2){
- parts[i].ctype |= 0x1F << temp_bin; //Add Colour
- } else if(parts[r>>8].tmp==3){
- parts[i].ctype &= ~(0x1F << temp_bin); //Subtract Colour
- }
+ 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)
@@ -2223,10 +2212,7 @@ int Simulation::try_move(int i, int x, int y, int nx, int ny)
}
if ((parts[i].type==PT_BIZR||parts[i].type==PT_BIZRG) && (r&0xFF)==PT_FILT)
{
- int temp_bin = (int)((parts[r>>8].temp-273.0f)*0.025f);
- if (temp_bin < 0) temp_bin = 0;
- if (temp_bin > 25) temp_bin = 25;
- parts[i].ctype = 0x1F << temp_bin;
+ parts[i].ctype = Element_FILT::interactWavelengths(&parts[r>>8], parts[i].ctype);
}
if (((r&0xFF)==PT_BIZR || (r&0xFF)==PT_BIZRG || (r&0xFF)==PT_BIZRS) && parts[i].type==PT_PHOT)
{
diff --git a/src/simulation/elements/ARAY.cpp b/src/simulation/elements/ARAY.cpp
index ac28834..16bff2d 100644
--- a/src/simulation/elements/ARAY.cpp
+++ b/src/simulation/elements/ARAY.cpp
@@ -98,7 +98,7 @@ int Element_ARAY::update(UPDATE_FUNC_ARGS)
break;
}
} else if ((r&0xFF)==PT_FILT) {//get color if passed through FILT
- colored = parts[r>>8].ctype;
+ colored = Element_FILT::interactWavelengths(&parts[r>>8], colored);
//this if prevents BRAY from stopping on certain materials
} else if ((r&0xFF)!=PT_STOR && (r&0xFF)!=PT_INWR && ((r&0xFF)!=PT_SPRK || parts[r>>8].ctype!=PT_INWR) && (r&0xFF)!=PT_ARAY && (r&0xFF)!=PT_WIFI && !((r&0xFF)==PT_SWCH && parts[r>>8].life>=10)) {
if (nyy!=0 || nxx!=0) {
diff --git a/src/simulation/elements/CRAY.cpp b/src/simulation/elements/CRAY.cpp
index 2933dcf..b906c33 100644
--- a/src/simulation/elements/CRAY.cpp
+++ b/src/simulation/elements/CRAY.cpp
@@ -102,7 +102,7 @@ int Element_CRAY::update(UPDATE_FUNC_ARGS)
docontinue = 0;
}
} else if ((r&0xFF)==PT_FILT) { // get color if passed through FILT
- colored = wavelengthToDecoColour(parts[r>>8].ctype);
+ colored = wavelengthToDecoColour(Element_FILT::getWavelengths(&parts[r>>8]));
} else if ((r&0xFF) == PT_CRAY || nostop) {
docontinue = 1;
} else if(destroy && r && ((r&0xFF) != PT_DMND)) {
diff --git a/src/simulation/elements/DTEC.cpp b/src/simulation/elements/DTEC.cpp
index 8ecaf2e..ed894a2 100644
--- a/src/simulation/elements/DTEC.cpp
+++ b/src/simulation/elements/DTEC.cpp
@@ -73,6 +73,7 @@ int Element_DTEC::update(UPDATE_FUNC_ARGS)
}
}
}
+ int photonWl = 0;
for (rx=-rd; rx<rd+1; rx++)
for (ry=-rd; ry<rd+1; ry++)
if (x+rx>=0 && y+ry>=0 && x+rx<XRES && y+ry<YRES && (rx || ry))
@@ -84,7 +85,32 @@ int Element_DTEC::update(UPDATE_FUNC_ARGS)
continue;
if (parts[r>>8].type == parts[i].ctype && (parts[i].ctype != PT_LIFE || parts[i].tmp == parts[r>>8].ctype || !parts[i].tmp))
parts[i].life = 1;
+ if (parts[r>>8].type == PT_PHOT)
+ photonWl = parts[r>>8].ctype;
}
+ if (photonWl)
+ {
+ int nx, ny;
+ 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;
+ nx = x+rx;
+ ny = y+ry;
+ while ((r&0xFF)==PT_FILT)
+ {
+ parts[r>>8].ctype = photonWl;
+ nx += rx;
+ ny += ry;
+ if (nx<0 || ny<0 || nx>=XRES || ny>=YRES)
+ break;
+ r = pmap[ny][nx];
+ }
+ }
+ }
return 0;
}
diff --git a/src/simulation/elements/FILT.cpp b/src/simulation/elements/FILT.cpp
index d6b82f2..62c3afc 100644
--- a/src/simulation/elements/FILT.cpp
+++ b/src/simulation/elements/FILT.cpp
@@ -48,21 +48,17 @@ Element_FILT::Element_FILT()
//#TPT-Directive ElementHeader Element_FILT static int graphics(GRAPHICS_FUNC_ARGS)
int Element_FILT::graphics(GRAPHICS_FUNC_ARGS)
-
{
- int x, temp_bin = (int)((cpart->temp-273.0f)*0.025f);
- if (temp_bin < 0) temp_bin = 0;
- if (temp_bin > 25) temp_bin = 25;
- cpart->ctype = 0x1F << temp_bin;
+ int x, wl = Element_FILT::getWavelengths(cpart);
*colg = 0;
*colb = 0;
*colr = 0;
for (x=0; x<12; x++) {
- *colr += (cpart->ctype >> (x+18)) & 1;
- *colb += (cpart->ctype >> x) & 1;
+ *colr += (wl >> (x+18)) & 1;
+ *colb += (wl >> x) & 1;
}
for (x=0; x<12; x++)
- *colg += (cpart->ctype >> (x+9)) & 1;
+ *colg += (wl >> (x+9)) & 1;
x = 624/(*colr+*colg+*colb+1);
*cola = 127;
*colr *= x;
@@ -73,5 +69,56 @@ int Element_FILT::graphics(GRAPHICS_FUNC_ARGS)
return 0;
}
+//#TPT-Directive ElementHeader Element_FILT static int interactWavelengths(Particle* cpart, int origWl)
+// Returns the wavelengths in a particle after FILT interacts with it (e.g. a photon)
+// cpart is the FILT particle, origWl the original wavelengths in the interacting particle
+int Element_FILT::interactWavelengths(Particle* cpart, int origWl)
+{
+ const int mask = 0x3FFFFFFF;
+ int filtWl = getWavelengths(cpart);
+ switch (cpart->tmp)
+ {
+ case 0:
+ return filtWl; //Assign Colour
+ case 1:
+ return origWl & filtWl; //Filter Colour
+ case 2:
+ return origWl | filtWl; //Add Colour
+ case 3:
+ return origWl & (~filtWl); //Subtract colour of filt from colour of photon
+ case 4:
+ {
+ int shift = int((cpart->temp-273.0f)*0.025f);
+ if (shift<=0) shift = 1;
+ return (origWl << shift) & mask; // red shift
+ }
+ case 5:
+ {
+ int shift = int((cpart->temp-273.0f)*0.025f);
+ if (shift<=0) shift = 1;
+ return (origWl >> shift) & mask; // blue shift
+ }
+ case 6:
+ return origWl; // No change
+ default:
+ return filtWl;
+ }
+}
+
+//#TPT-Directive ElementHeader Element_FILT static int getWavelengths(Particle* cpart)
+int Element_FILT::getWavelengths(Particle* cpart)
+{
+ if (cpart->ctype)
+ {
+ return cpart->ctype;
+ }
+ else
+ {
+ int temp_bin = (int)((cpart->temp-273.0f)*0.025f);
+ if (temp_bin < 0) temp_bin = 0;
+ if (temp_bin > 25) temp_bin = 25;
+ return (0x1F << temp_bin);
+ }
+}
Element_FILT::~Element_FILT() {}