📄 platoonagent.java
字号:
// road = (Road) (PASSABLE_C.not().extract(cpath).iterator().next());//// if (MRL.MRLConstants.ROUTING_DEBUG_MODE) System.out.println(self() +// " Is Locked In " + road + " In : " + time() + " , Containing Path : " +// world.getContainingPath(road));// messageManager.reportLockedByBlockade(road); MotionlessObject mp = self().motionlessPosition(); if((self().HasMovedInLastCycle() && ! self().getWereLockedByBlockade() )|| self().submittedAction()) return; if(self().position() instanceof AmbulanceTeam) return; if(mp instanceof Building) return; Road road; if(mp instanceof Road){ road = (Road) mp; if(NOT_PASSABLE_C.eval(road)){ messageManager.reportLockedByBlockade(road); } } else if(mp instanceof Node){ Node node = (Node) mp; for(Iterator it = node.getConnectedRoads().iterator();it.hasNext();){ road = (Road) it.next(); if(NOT_PASSABLE_C.eval(road)){ messageManager.reportLockedByBlockade(road); } } } } protected boolean isLockedBySomeone() { // Can Be Improved Much More . if (!self().HasMovedInLastCycle() && submittedMoveAct) { Collection humsHere = VISIBLE_C.extract(world.updatedmovingobjects); humsHere.remove(self());// Humanoid near; if (humsHere.isEmpty())return false; else return true; } return false; }// protected boolean isLockedToTargetByBlockade() { // Returns false for CrossWays// if (acted || !submittedMoveAct || self().HasMovedInLastCycle())return false;// Path cpath = world.getCurrentPath();// if (cpath == null) {// return (isLockedInBlockades(self()));//// return false;// } else {// MotionlessObject pos = self().motionlessPosition();// Road road = null;// if (pos instanceof Road) {// road = (Road) self().motionlessPosition();// } else {// Node node;// if (pos instanceof Building) node = (Node) ((Building) pos).entrance();// else node = (Node) pos;// Collection col = node.getConnectedRoads();// Iterator it = col.iterator();// if (col.size() == 1) {// road = (Road) it.next();// } else {// Road r1 = (Road) it.next(), r2 = (Road) it.next();// if (r1.passableLines() == 0) road = r1;// else if (r2.passableLines() == 0) road = r2;// }// if (road == null)return false;// }// if (road.passableLines() == 0)return true; // !acted &&// }// return false;// } protected boolean isLockedInBlockades(MovingObject mo) {// if(time() > 100 ) return false; if (mo.position() == null || mo.position() instanceof AmbulanceTeam)return false; if(mo instanceof PoliceForce) return false; Node op = HumanoidAgent.outsidePosition(mo); Path path = world.getContainingPath(mo.motionlessPosition()); if (path == null) { for (Iterator it = op.getConnectedRoads().iterator(); it.hasNext(); ) { path = world.getContainingPath((Road) it.next()); if (!path.isPathWithOneJunction() && path.passableLines()>0)return false; }// for (Iterator it = op.getConnectedRoads().iterator(); it.hasNext(); ) {// path = world.getContainingPath((Road) it.next());// if (!path.isLockedByBlockade(op) && ! path.isPathWithOneJunction())return false;// } return true; }// Path np = (Path)mo.distancePrp.max(path.getConnectedPaths());// Route rt = Router.get(mo.motionlessPosition(),np,RELIABILITY_COST_FUNCTION);// return rt.cost >= IN_BLOCKS; /** * todo : BAYAD Chizi Benivisim Ke Beine Chand Ta Path Ro Ham Betoone Begarde . */ return path.isLockedByBlockade(op); } public Partition workingPartition() { return world.getWorkingPartition(); } public Partition searchingPartition(){ if(world.getSearchingPartition() != null) return world.getSearchingPartition(); return workingPartition(); } protected void gotoPossibleCivBuildings(Collection poses) throws ActionCommandException { if (poses.isEmpty())return; List bldgs = SPECIAL_BUILDING_C.not().and( BURNING_C.not()).and(BURNED_C.not()).extract(world. //HAS_NOT_BEEN_SEEN_CND.or( getConnectedBuildings(poses)); bldgs.retainAll(world.unvisitedBuildings); if (bldgs.isEmpty())return;// moveRandomBuilding(bldgs); move(bldgs);// MotionlessObject mo;// List bldgs = new ArrayList();// List tmp;// for (Iterator it = poses.iterator(); it.hasNext(); ) {// mo = (MotionlessObject) it.next();// if(!(mo instanceof Road)){// tmp = SPECIAL_BUILDING_C.not().and(// BURNING_C.not()).and(BURNED_C.not()).and(mo.distancePrp.lte(// MAX_HEARING_DISTANCE)).extract(world.// unvisitedBuildings);//// }// else{// int roadLength = MAX_HEARING_DISTANCE + ((Road)mo).length() /2;// tmp = SPECIAL_BUILDING_C.not().and(// BURNING_C.not()).and(BURNED_C.not()).and(mo.distancePrp.lte(// roadLength)).extract(world.// unvisitedBuildings);//// }//// tmp.removeAll(bldgs);// bldgs.addAll(tmp);// }// bldgs.removeAll(world.messagepool.reportedBuildings);//// if (bldgs.isEmpty())return;//// System.out.println(self() +// " Moving To Possible Civilian Positions In Time : " +// time());// moveFirstToNearsThenToFarers(bldgs);// moveToBrokensFirst(bldgs);// move(bldgs); /* List broken = BROKEN_CND.extract(bldgs); if (self() instanceof PoliceForce) { if (!broken.isEmpty()) move(broken);// moveRandomBuilding(broken);// moveRandomBuilding(bldgs); move(bldgs); } else { if (!broken.isEmpty()) if (time() > TIME_STARTING_TO_SEARCH_BY_AVAILABILITY) moveAvailableBldgs(broken);// else moveRandomBuilding(broken); else move(broken); if (time() > TIME_STARTING_TO_SEARCH_BY_AVAILABILITY) moveAvailableBldgs( bldgs);// else moveRandomBuilding(bldgs); else move(bldgs); } */ } private Civilian m_lastHearedCivTarget = null; private final Set m_ignoredHearedCivs = new HashSet(); protected void gotoPossibleCivBuildings(boolean onlyInPartition) throws ActionCommandException { if(onlyInPartition && searchingPartition()== null) return; List heared = POSITION_PRP.eq(null).extract(world.civilians); heared.removeAll(m_ignoredHearedCivs); if(heared.isEmpty()) return; if(m_lastHearedCivTarget != null && heared.contains(m_lastHearedCivTarget) ){ if(m_lastHearedCivTarget.getCyclesSearched() > MAX_TIME_TO_SEARCH_FOR_HEARED_CIV){ m_ignoredHearedCivs.add(m_lastHearedCivTarget); System.out.println(self() + " Ignoring Because Of Timeout : " + m_lastHearedCivTarget + " In Time : " + time()); } else{ if(m_lastHearedCivTarget.guessedPosition() != null){ // if(searchingPartition() == null || searchingPartition().ML_OBJS_IN_PART_CND.eval(m_lastHearedCivTarget.guessedPosition())){ // System.out.println(self() + " , Continuing To Search For Target : " + m_lastHearedCivTarget + " , Start Time : " + m_lastHearedCivTarget.getSearchStartTime() + " , Time : " + time()); moveHearedCivilian(m_lastHearedCivTarget); // } } else{ m_ignoredHearedCivs.add(m_lastHearedCivTarget); // System.out.println(self() + " Ignoring Because Of Null GuessedPos : " + m_lastHearedCivTarget + " In Time : " + time()); } } } m_lastHearedCivTarget=null; Civilian civ , tmp=null; int dist , best = Integer.MAX_VALUE; List res ; do{ tmp = null; for(Iterator it = heared.iterator();it.hasNext();){ civ = (Civilian) it.next(); civ.updatePossiblePoses(); if(civ.guessedPosition() == null){ m_ignoredHearedCivs.add(civ); // System.out.println(self() + " Ignoring Because Of Null GuessedPos In gotoPoss : " + civ + " In Time : " + time()); it.remove(); continue; } if(onlyInPartition && searchingPartition() != null && ! searchingPartition().ML_OBJS_IN_PART_CND.eval(civ.getMostProbableBldg())) continue; dist = self().distance(civ.guessedPosition()); if(dist < best){ tmp = civ; best = dist; } } if(tmp == null) return; heared.remove(tmp); res = correctListToCheck(tmp.possibleBuildings); } while( res.isEmpty()); m_lastHearedCivTarget = tmp; // System.out.println(self() + " , Selected Search Target : " + m_lastHearedCivTarget + " , Start Time : " + time()); moveHearedCivilian(m_lastHearedCivTarget); } private void moveHearedCivilian(Civilian civ) throws ActionCommandException{ // update Should Be Run First. if(civ.position() != null) { throw new Error("WTF"); } civ.updatePossiblePoses(); Building bldg = m_lastHearedCivTarget.guessedPosition(); if(bldg == null){ System.err.println(self() + " , Null Guessed Pos For : " + civ); return; } civ.setSearchTime(); if(NOT_IN_TRAFFIC_C.eval(bldg) && ! bldg.isBurning() && !fullBuildings.contains(bldg) && world.unvisitedBuildings.contains(bldg)) move(bldg); else { List avBldgs = correctListToCheck(civ.possibleBuildings); avBldgs.removeAll(fullBuildings); moveFirstToNearsThenToFarers(avBldgs,HEARED_CIVILIAN_SEARCH); } } protected void moveFirstToNotInTrafficThenToTrafficOnes(Collection poses) throws ActionCommandException{ if(poses.isEmpty()) return; List notInTraffic = NOT_IN_TRAFFIC_C.extract(poses); if(!notInTraffic.isEmpty()) move(notInTraffic); else move(poses); } protected List correctListToCheck(Collection bldgs){ Building tmp; List res = new ArrayList(); for(Iterator it = bldgs.iterator();it.hasNext();){ tmp = (Building) it.next(); if(tmp.isBurning() || tmp.isBurned() || ! world.unvisitedBuildings.contains(tmp) || FULL_BUILDING_C.eval(tmp) ) continue; res.add(tmp); } return res; } protected void updatePrevRoads() { // SHOULD BE CAREFULL ABOUT THIS ************* if (time() < 4)return; List roads = self().getPosHistRoads(); Road road; for (Iterator it = roads.iterator(); it.hasNext(); ) { road = (Road) it.next();// if(!road.hasBeenSeen()) {// road.setTime(time()); if (NOT_PASSABLE_C.eval(road)) { // road.passableLines() == 0 { road.setBlock(0,time()); } } else if (!road.hasBeenSeen()) road.setTime(time());// world.travAndNotUpdatedRoads.add(road);// } } } protected void reportHearedHumansInRefuge(){ if(! (self() instanceof AmbulanceTeam || self() instanceof FireBrigade)) return; if(! (self().motionlessPosition() instanceof Refuge)) return; Humanoid hum; for(Iterator it = world.m_HearedCivPossPosMap.keySet().iterator();it.hasNext();){ hum = (Humanoid) it.next(); if(hum.isVisible()) //world.messagepool.ReportHumanoid(hum); messageManager.reportVictim(hum); } } /* protected Map m_Road_OrigBlockMap = new HashMap(); protected void assumeRoadIsBlocked(Road road){ Integer origBlock = new Integer( road.block()); m_Road_OrigBlockMap.put(road,origBlock); setRoadBlocked(road,1000000,road.time()); } protected void assumeRoadIsUnBlocked(Road road) { Integer origBlock = (Integer)m_Road_OrigBlockMap.get(road); if(road.block() == 1000000) setRoadBlocked(road,origBlock.intValue(),road.time()); // Might Be Updated Already .. } */ private int m_prevTimeRoamed = -1; protected boolean roamed = false; protected void roam() throws ActionCommandException { Road road; if (workingPartition() != null) { int rnd; do{ rnd = random.nextInt(workingPartition().getRoads(). size()); road = (Road) workingPartition().getRoads().get(rnd); }while (world.isInTraffic(road)); } else { int rnd;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -