mirror of
https://github.com/simon987/Much-Assembly-Required.git
synced 2025-04-10 14:26:45 +00:00
Add Beta and Gamma particles; added suggestions
This commit is contained in:
parent
2aeca6c9ce
commit
0c3a3f06f0
@ -22,6 +22,13 @@ public class RadiationDetector extends HardwareModule {
|
||||
*/
|
||||
public static final char HWID = 0x010F;
|
||||
|
||||
/**
|
||||
* Radiation Constants
|
||||
*/
|
||||
private static final int ALPHA_BLOCKED_VALUE = 5;
|
||||
private static final int BETA_BLOCKED_VALUE = 2;
|
||||
private static final int GAMMA_BLOCKED_VALUE = 1;
|
||||
|
||||
/**
|
||||
* Helper class for getTiles
|
||||
*/
|
||||
@ -50,9 +57,9 @@ public class RadiationDetector extends HardwareModule {
|
||||
|
||||
ArrayList<Tuple> ret = new ArrayList<>();
|
||||
double slope;
|
||||
if (x1 > x0)
|
||||
if (x1 > x0) {
|
||||
slope = (y1 - y0) / (double) (x1 - x0);
|
||||
else {
|
||||
} else {
|
||||
slope = (y0 - y1) / (double) (x0 - x1);
|
||||
|
||||
// Swap values so that x0 < x1. This preps the following code where y is
|
||||
@ -69,15 +76,15 @@ public class RadiationDetector extends HardwareModule {
|
||||
// If slope is zero or undefined, return tiles directly along the
|
||||
// appropriate cardinal direction.
|
||||
if (x0 == x1) {
|
||||
int smaller = y0 < y1 ? y0 : y1;
|
||||
int larger = y0 > y1 ? y0 : y1;
|
||||
int smaller = Math.min(y0, y1);
|
||||
int larger = Math.max(y0, y1);
|
||||
System.out.printf("%d %d", smaller, larger);
|
||||
for (int i = smaller + 1; i < larger; i++) {
|
||||
ret.add(new Tuple(x0, i));
|
||||
}
|
||||
} else if (y0 == y1) {
|
||||
int smaller = x0 < x1 ? x0 : x1;
|
||||
int larger = x0 > x1 ? x0 : x1;
|
||||
int smaller = Math.min(x0, x1);
|
||||
int larger = Math.max(x0, x1);
|
||||
for (int i = smaller + 1; i < larger; i++) {
|
||||
ret.add(new Tuple(i, y0));
|
||||
}
|
||||
@ -129,25 +136,37 @@ public class RadiationDetector extends HardwareModule {
|
||||
|
||||
// Check for alpha particles by finding Radioactive entities
|
||||
int alphaParticles = 0;
|
||||
int betaParticles = 0;
|
||||
int gammaParticles = 0;
|
||||
for (GameObject entity : entities) {
|
||||
if (entity instanceof Radioactive) {
|
||||
// Calculate distance between object and cubot
|
||||
double pathLength = getDistanceOfCoords(unit.getX(), unit.getY(), entity.getX(), entity.getY());
|
||||
alphaParticles += ((Radioactive) entity).getAlphaCounts(pathLength);
|
||||
betaParticles += ((Radioactive) entity).getBetaCounts(pathLength);
|
||||
gammaParticles += ((Radioactive) entity).getGammaCounts(pathLength);
|
||||
|
||||
// Get all tiles in between cubot and Radioactive entity
|
||||
ArrayList<Tuple> tiles = getTiles(unit.getX(), unit.getY(), entity.getX(), entity.getY());
|
||||
for (Tuple tup : tiles) {
|
||||
// If intermediary tile is blocked, reduce alphaParticles by 5
|
||||
if (unit.getWorld().isTileBlocked(tup.x, tup.y)) {
|
||||
alphaParticles -= 5;
|
||||
alphaParticles -= ALPHA_BLOCKED_VALUE;
|
||||
betaParticles -= BETA_BLOCKED_VALUE;
|
||||
gammaParticles -= GAMMA_BLOCKED_VALUE;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Save Alpha Radioactive Particles to register B
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(alphaParticles);
|
||||
// Save Alpha Radioactive Particles to register A
|
||||
getCpu().getRegisterSet().getRegister("A").setValue(alphaParticles);
|
||||
|
||||
// Save Beta Radioactive Particles to register B
|
||||
getCpu().getRegisterSet().getRegister("B").setValue(betaParticles);
|
||||
|
||||
// Save Gamma Radioactive Particles to register C
|
||||
getCpu().getRegisterSet().getRegister("C").setValue(gammaParticles);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -9,4 +9,12 @@ public interface Radioactive {
|
||||
public default int getAlphaCounts(double distance) {
|
||||
return (int) (1000 * 1.0 / (distance * distance));
|
||||
}
|
||||
|
||||
public default int getBetaCounts(double distance) {
|
||||
return (int) (2000 * 1.0 / (distance * distance));
|
||||
}
|
||||
|
||||
public default int getGammaCounts(double distance) {
|
||||
return (int) (5000 * 1.0 / (distance * distance));
|
||||
}
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user