Example #1
0
  public void step(SimState iModel) {
    Model aModel = (Model) iModel;
    if (!vivant()) {
      this.getStp().stop();
      aModel.getYard().remove(this);
      aModel.decNbFiremen();
    } else if (aModel.schedule.getSteps() % 5 == 0) // petite régénération
    {
      this.setResistance(getResistance() + 1);
    }

    AgentFeu aAgentFeu = null;
    int i;

    for (i = 0; i < aModel.getYard().getHeight(); i++) {
      Bag aAgents =
          aModel
              .getYard()
              .getNeighborsMaxDistance(this.getX(), this.getY(), i, false, null, null, null);
      ArrayList<AgentFeu> agentsFeu = new ArrayList<AgentFeu>();
      for (Object item : aAgents) {
        if (item instanceof AgentFeu && ((AgentFeu) item).getResistance() > 0)
          agentsFeu.add((AgentFeu) item);
      }
      if (agentsFeu.size() > 0) {
        Random random = new Random();
        int index = random.nextInt(agentsFeu.size());
        aAgentFeu = agentsFeu.get(index);
        break;
      }
    }

    if (i == 0 || i == 1) eteindreFeu(aModel, aAgentFeu);
    else if (aAgentFeu != null) deplace(aAgentFeu, aModel, i);
  }
Example #2
0
 public boolean deplacementPossible(Model iModel, int x, int y) {
   try {
     for (Object item : iModel.getYard().getObjectsAtLocation(x, y)) {
       if (item instanceof AgentPieton) {
         return false;
       }
     }
   } catch (Exception e) {
     //			System.out.println("["+x+","+y+"]");
     //			System.exit(0);
     return false;
   }
   return true;
 }
Example #3
0
 public void deplace(Model iModel, int x, int y) {
   this.setX(x);
   this.setY(y);
   iModel.getYard().setObjectLocation(this, x, y);
 }