public MessageBlock(String header, DataArrayList data) { super(header, data); setPriority(ReadXml.blocks.get(header).getPriority()); }
public MessageBlock(AbstractMessageBlock messageBlock) { super(messageBlock); setPriority(ReadXml.blocks.get(header).getPriority()); }
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); } } }
public MessageBlock(String header) { super(header); setPriority(ReadXml.blocks.get(header).getPriority()); }
private void chooseFireMessages() { for (Pair<ArrayList<SOSRealFireZone>, SOSEstimatedFireZone> fz : model().sosAgent().fireSiteManager.getFireSites()) { for (SOSRealFireZone firezone : fz.first()) { ArrayList<Building> outers = firezone.getOuter(); if (outers.isEmpty()) outers = firezone.getFires(); if (!outers.isEmpty()) { Building b = outers.get(0); MessageBlock messageBlock = new MessageBlock(HEADER_FIRE); messageBlock.setPriority(11); messageBlock.addData(DATA_BUILDING_INDEX, b.getBuildingIndex()); messageBlock.addData(DATA_FIERYNESS, b.getFieryness()); messageBlock.addData(DATA_HEAT, b.getTemperature() / 3); messageBlock.addData(DATA_TIME, b.updatedtime()); sayMessages.add(messageBlock); } } } try { for (Building sensed : model().sosAgent().getVisibleEntities(Building.class)) { if (sensed.isTemperatureDefined() && sensed.getTemperature() == 0) { Building b = sensed; MessageBlock messageBlock = new MessageBlock(HEADER_FIRE); messageBlock.setPriority(11); messageBlock.addData(DATA_BUILDING_INDEX, b.getBuildingIndex()); messageBlock.addData(DATA_FIERYNESS, b.getFieryness()); messageBlock.addData(DATA_HEAT, 0); messageBlock.addData(DATA_TIME, b.updatedtime()); sayMessages.add(messageBlock); } } } catch (Exception e) { e.printStackTrace(); } PriorityQueue<Building> buildings = new PriorityQueue<Building>( 100, new Comparator<Building>() { @Override public int compare(Building o1, Building o2) { if (o1.getFieryness() != o2.getFieryness()) { if (o1.getFieryness() == 1) return -1; if (o2.getFieryness() == 1) return 1; if (o1.getFieryness() == 2) return -1; if (o2.getFieryness() == 2) return 1; if (o1.getFieryness() == 3) return -1; if (o2.getFieryness() == 3) return 1; } return 0; } }); for (Building b : agent.model().buildings()) { if (b.getFieryness() == 0) continue; buildings.add(b); } int priority = 10; int count = 0; for (Building b : buildings) { if (b.getFieryness() == 0) continue; count++; if (priority > 0 && count % 10 == 0) priority--; if (agent.model().time() - b.updatedtime() < 100) { MessageBlock messageBlock = new MessageBlock(HEADER_FIRE); messageBlock.addData(DATA_BUILDING_INDEX, b.getBuildingIndex()); messageBlock.addData(DATA_FIERYNESS, b.getFieryness()); messageBlock.addData(DATA_HEAT, b.getTemperature() / 3); messageBlock.addData(DATA_TIME, b.updatedtime()); CommunicationlessSearch<?> nocommSearch = b.model().sosAgent().newSearch.strategyChooser.noCommunication; if (nocommSearch.getCenteralMan() != null && nocommSearch.getCenteralMan().equals(b.model().me())) { sayMessages.add(messageBlock); } else { if (b.getSOSEstimateFireSite() != null && b.getSOSEstimateFireSite().shouldBeReported()) { sayMessages.add(messageBlock); } else if (agent.model().time() - b.updatedtime() < 30) { sayMessages.add(messageBlock); } } } } }