コード例 #1
0
ファイル: Move.java プロジェクト: jpollo/rcrss
  private void sendStockMessage(Path path) {
    if (me instanceof PoliceForceAgent) return;

    if (!(me.me() instanceof Human)) return;

    if (me.time() < 50) return;

    Human meEntity = (Human) me.me();

    if (meEntity.isBuriednessDefined() && meEntity.getBuriedness() > 0) return;

    if (meEntity.getImReachableToEdges().isEmpty()) return;

    if (me.isTimeToActFinished()) return;

    if (me.lastException != null) return;

    try {
      //			if (me.getMyClusterData().isCoverer())
      //				return;

      if (me.me().getAreaPosition().isBlockadesDefined()
          && me.me().getAreaPosition().getBlockadesID().isEmpty()) {
        boolean haveBlock = false;
        for (Area neighbour : me.me().getAreaPosition().getNeighbours()) {
          if (neighbour.isBlockadesDefined() && !neighbour.getBlockadesID().isEmpty())
            haveBlock = true;
        }
        if (!haveBlock) return;
      }
    } catch (Exception e) {
      e.printStackTrace();
    }
    log().debug("Sending Stock Message");
    me.messageBlock = new MessageBlock(MessageXmlConstant.HEADER_AGENT_STOCK);
    me.messageBlock.addData(
        MessageXmlConstant.DATA_AREA_INDEX, me.me().getAreaPosition().getAreaIndex());
    me.messages.add(me.messageBlock);
    me.lowCommunicationMessages.add(me.messageBlock);
  }
コード例 #2
0
ファイル: No_Comm.java プロジェクト: jpollo/rcrss
  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);
      }
    }
  }