Пример #1
0
 public boolean isReachableTo(StandardEntity se) {
   if (se instanceof Human) {
     Human hum = (Human) se;
     if (agent.getVisibleEntities(Human.class).contains(hum)
         && hum.isPositionDefined()
         && hum.getAreaPosition().isBlockadesDefined()) {
       for (Blockade blockade : hum.getAreaPosition().getBlockades()) {
         if (blockade.getShape().contains(hum.getPositionPoint().toGeomPoint())) return false;
       }
     }
     if (!hum.getImReachableToEdges().isEmpty())
       return agent
           .move
           .getMoveType(PoliceReachablityMove.class)
           .isReallyReachableTo(hum.getImReachableToEdges());
   }
   return isReachableTo(se.getPositionPair());
 }
Пример #2
0
  private void chooseHumanMessages() {
    PriorityQueue<Human> validHumans =
        new PriorityQueue<Human>(
            50,
            new Comparator<Human>() {
              @Override
              public int compare(Human o1, Human o2) {
                return o2.updatedtime() - o1.updatedtime();
              }
            });
    for (Human hm : agent.model().humans()) {

      if ((hm.isHPDefined() && hm.isPositionDefined())
          && (hm.getRescueInfo().getIgnoredUntil() == 1000
              || (hm.getHP() < 10000 && hm.getPositionArea() instanceof Refuge)
              || hm.getHP() == 0)) {

        if (agent instanceof SOSAgent<?>) {
          SOSAgent<?> sosAgent = ((SOSAgent<?>) agent);
          sosAgent.sosLogger.noComunication.debug(
              hm
                  + " ignoreUntil:"
                  + hm.getRescueInfo().getIgnoredUntil()
                  + " "
                  + hm.getRescueInfo().getIgnoreReason()
                  + " "
                  + hm.fullDescription());
        }

        MessageBlock messageBlock = new MessageBlock(HEADER_IGNORED_TARGET);
        messageBlock.addData(DATA_ID, hm.getID().getValue());
        messageBlock.setPriority(8);

        sayMessages.add(messageBlock);
      } else if (hm.isPositionDefined()
          && ((hm.isDamageDefined() && hm.getDamage() > 0)
              || (hm.isBuriednessDefined() && hm.getBuriedness() > 0))
          && hm.getHP() > 0
          && !hm.getRescueInfo().isIgnored()) {
        int deathTime;
        if (agent instanceof AmbulanceTeamAgent) {
          deathTime = hm.getRescueInfo().getDeathTime();
        } else
          deathTime = SimpleDeathTime.getEasyLifeTime(hm.getHP(), hm.getDamage(), hm.updatedtime());

        if (deathTime - hm.getBuriedness() / 2 > agent.model().time()) validHumans.add(hm);
      }
    }
    //		Collections.sort(validHumans, new Comparator<Human>() {
    //			@Override
    //			public int compare(Human o1, Human o2) {
    //				return o2.updatedtime() - o1.updatedtime();
    //			}
    //		});
    int priority = 10;
    int count = 0;
    for (Human hm : validHumans) {
      count++;
      if (priority > 0 && count % 10 == 0) priority--;

      if (hm instanceof Civilian) {
        MessageBlock messageBlock = new MessageBlock(HEADER_SENSED_CIVILIAN);
        messageBlock.addData(DATA_ID, hm.getID().getValue());
        messageBlock.addData(DATA_AREA_INDEX, hm.getPositionArea().getAreaIndex());
        messageBlock.addData(DATA_HP, hm.getHP() / 322);
        int damage = hm.getDamage();
        if (damage > 1200) damage = 1200;
        messageBlock.addData(DATA_DAMAGE, damage / 10);
        int buried = hm.getBuriedness();
        if (buried > 126) buried = 126;
        messageBlock.addData(DATA_BURIEDNESS, buried);
        messageBlock.addData(DATA_TIME, hm.updatedtime());
        boolean isReallyReachable;
        if (agent instanceof SOSAgent<?>)
          isReallyReachable =
              !((SOSAgent<?>) agent)
                  .move.isReallyUnreachableXYPolice(hm.getPositionArea().getPositionPair());
        else isReallyReachable = false;

        messageBlock.addData(DATA_IS_REALLY_REACHABLE, isReallyReachable ? 1 : 0);
        messageBlock.setPriority(priority);
        sayMessages.add(messageBlock);
      } else {
        MessageBlock messageBlock = new MessageBlock(HEADER_SENSED_AGENT);
        messageBlock.addData(DATA_AGENT_INDEX, hm.getAgentIndex());
        messageBlock.addData(DATA_AREA_INDEX, hm.getPositionArea().getAreaIndex());
        messageBlock.addData(DATA_HP, hm.getHP() / 322);
        int damage = hm.getDamage();
        if (damage > 1200) damage = 1200;
        messageBlock.addData(DATA_DAMAGE, damage / 10);
        int buried = hm.getBuriedness();
        if (buried > 126) buried = 126;
        messageBlock.addData(DATA_BURIEDNESS, buried);
        messageBlock.addData(DATA_TIME, hm.updatedtime());
        messageBlock.setPriority(priority);
        sayMessages.add(messageBlock);
      }
    }
  }