package thing.ground;
import simmasto0.C_ContextCreator;
import thing.C_Rodent;
import thing.I_situated_thing;
/** a trap may be opened, closed, full;
it can catch rodent
*
@author J.Le Fur and M.Diakhate, july
2013, rev. 27.09.13 */
public class C_Trap extends C_BurrowSystem implements data.I_Bandia_constants {
// FIELDS
private boolean open = true;
// CONSTRUCTOR
// METHODS
/** Add rodent in agentList of
trap if :
* 1° Trap is open, 2° Rodent is not
within the trap or a burrow,
* 3° Trap is not full of rodents, 4°
TRAP_LOADING_PROBA >= randomProbability */
public void trapRodent(C_Rodent rodent) {
if (this.open &&
!rodent.trappedOnBoard &&
TRAP_MAX_LOAD >= this.getRodentLoad() &&
C_ContextCreator.randomGeneratorForDeathProb.nextDouble() <= TRAP_LOADING_PROBA) {
this.agentList.add(rodent);
rodent.trappedOnBoard = true;
open = false;
}
else agentLeaving(rodent);// put rodent besides the trap.
}
public void openTrap() {
this.open = true;
}
public void closeTrap() {
this.open = false;
}
public int getRodentLoad() {
int nbRodents = 0;
for (I_situated_thing thing : agentList)
if (thing instanceof C_Rodent)
nbRodents++;
return nbRodents;
}
@Override
public String toString() {
return ("trap
" + this.getMyID());
}
// GETTERS AND SETTERS
public boolean isOpen() {
return open;
}
public boolean hasToChange() {
return !open;// change color only if trap is closed
}
@Override
public int getCarryingCapacity() {
return TRAP_MAX_LOAD;
}
}