📄 disasterspace.java
字号:
public ArrayList getAround(RealObject obj, Set motionlessObjectSet, int radius) { KdTree kdTree = (KdTree) m_objSetKdTreeMap.get(motionlessObjectSet); Map objNeighboursMap = (Map) m_objSetObjNeighboursMapMap.get(motionlessObjectSet); if (kdTree == null) { kdTree = new KdTree(motionlessObjectSet); m_objSetKdTreeMap.put(motionlessObjectSet, kdTree); objNeighboursMap = new HashMap(); m_objSetObjNeighboursMapMap .put(motionlessObjectSet, objNeighboursMap); } ArrayList result = (ArrayList) objNeighboursMap.get(obj); if (result == null) { result = kdTree.search(obj, radius); objNeighboursMap.put(obj, result); } return result; } // Omid Aghazadeh// public int getAgentCountLockedInPath(Path path){// return Utils.getConditionCount(lockedBBAgents.values(),path.IS_CONTAINING_C);// } public List getPossibleHearedBuildings(int x , int y , int distance){ Building bldg; List res = new ArrayList(); for(Iterator it = unvisitedBuildings.iterator();it.hasNext();){ bldg = (Building) it.next(); if(Util.distance(bldg.x(),bldg.y(),x,y) > distance) continue; res.add(bldg); } return res; }// public List getPossibleHearedBuildings(MotionlessObject mo , boolean forDelete){// List res = null;// if (!(mo instanceof Road)) {// if(forDelete){// res = mo.distancePrp.lte(// Civilian.SEARCH_DIST).extract(unvisitedBuildings);// }// else{// res = mo.distancePrp.lte(// Civilian.SEARCH_DIST).extract(unvisitedBuildings);// }//// } else {// if(forDelete){// int roadLength = Civilian.SEARCH_DIST -((Road) mo).length();// if(roadLength > 0){// res = mo.distancePrp.lte(// roadLength).extract(unvisitedBuildings);// }// else res = new ArrayList();// }// else{// int roadLength = Civilian.SEARCH_DIST +((Road) mo).length();// res = mo.distancePrp.lte(// roadLength).extract(unvisitedBuildings);//// }// }// return res;//// } public final Collection lostCivs = new HashSet(); public void correctNeedCheck(Collection inp) { Civilian civ; Building bldg; for (Iterator it = inp.iterator(); it.hasNext(); ) { civ = (Civilian) it.next(); if (self.motionlessPosition() == civ.motionlessPosition() && !civ.isVisible() ) { lostCivs.add(civ); it.remove(); continue; } if (civ.motionlessPosition() instanceof Building) { bldg = (Building) civ.motionlessPosition(); if (bldg.isBurned() || civ.position() instanceof Refuge) { lostCivs.add(civ); it.remove(); continue; } } else { lostCivs.add(civ); it.remove(); continue; } } } public void addReportedBICToPaths(){ for(Iterator it = paths.iterator();it.hasNext();){ ((Path)it.next()).addReportedBICTRB(); } } public Civilian AddCivilian(int ID) { add(new Civilian(ID, this)); Civilian civ = (Civilian) get(ID);// int [] hp = {9000};// updateProperty(civ, ProtocolConstants.PROPERTY_HP, hp);// updateAndDetermHumHP(civ); if (civ == null)throw new Error("WHA"); return civ; } public Civilian getNearestPossibleHearedCivilian(Map inp){ if(inp.isEmpty()) return null; int dist , best = Integer.MAX_VALUE; Civilian civ,res=null; MotionlessObject mo; for(Iterator it = inp.keySet().iterator();it.hasNext();){ civ = (Civilian) it.next(); mo = (MotionlessObject) inp.get(civ); dist = self.distance(mo); if(dist < best){ best = dist; res = civ; } } return res; } public Civilian getNearestPossibleHearedCivilian(List inp){ if(inp.isEmpty()) return null; int dist , best = Integer.MAX_VALUE; Civilian civ,res=null; Building bldg; for(Iterator it = inp.iterator();it.hasNext();){ civ = (Civilian) it.next(); if(civ.possibleBuildings.isEmpty()) civ.updatePossiblePoses(); if(civ.possibleBuildings.isEmpty()){ if(MRL.MRLConstants.CIV_DEBUG_MODE) System.err.println("*** Civ's Possible Poses Is Empty"); continue; } bldg = (Building) self.distancePrp.min(civ.possibleBuildings); dist = self.distance(bldg); if(dist < best){ best = dist; res = civ; } } return res; } protected HashMap m_civHpUpdTimeMap = new HashMap(); public void updateAndDetermHumHP(Humanoid hum) { /// A Determination For Current Civilian HP int updCivHP = 0, prevUpdTime, prevUpdatedTime; if (m_civHpUpdTimeMap.containsKey(hum)) { prevUpdTime = ((Integer) m_civHpUpdTimeMap.get(hum)).intValue(); prevUpdatedTime = (prevUpdTime > hum.time() ? prevUpdTime : hum.time()); int hp = hum.hp() - hum.damage() * (time() - prevUpdatedTime);// updCivHP = (hum.hp() ==0 ? 0 : hum.hp() - hum.damage()*(time()-prevUpdatedTime)); updCivHP = hp < 0 ? 0 : hp; m_civHpUpdTimeMap.remove(hum); } else { updCivHP = (hum.hp() == 0 ? 10000 : hum.hp()) - hum.damage() * (time() - hum.time()); } m_civHpUpdTimeMap.put(hum, new Integer(time())); if (hum.position() instanceof Building) { Building civpos = (Building) hum.position(); if (civpos.isBurned()) updCivHP = 0; } int val[] = new int[1]; val[0] = updCivHP; updateProperty(time(), hum, ProtocolConstants.PROPERTY_HP, val); } public void updateProperty(int time, RealObject obj, int type, int[] val) { obj.setProperty(time, type, val);}// public void updateLockedBB() {// Collection cleanRoads;// cleanRoads = SHOULD_CHECK_ROAD_CND.not().extract(lockedBBAgents.// values());// lockedBBAgents.values().removeAll(cleanRoads);// cleanRoads = SHOULD_CHECK_ROAD_CND.not().extract(m_lockedCivPos_Map.// values());// m_lockedCivPos_Map.values().removeAll(cleanRoads);// } // ADDED 2006_04_11 public void setPathCleared(Path path , int time){ Road road; for(Iterator it = path.iterator();it.hasNext();){ road = (Road) it.next(); if(SHOULD_CHECK_ROAD_CND.eval(road)){ //road.passableLines() == 0 || ! road.hasBeenSeen() setRoadCleared(road,time); } } if(!path.checkPathIsOpen()) System.err.println(self + " , Error , Path Didn't Update "); } public void setRoadCleared(Road road , int time){ road.setBlock(0,time); road.setTime(time); } // ADDED 2006_04_11 // Omid Aghazadeh //--------------Ashkan added int FIRE_PASSING_DISTANCE = 50000; int RAY_DOMAIN = 3; public void setBuildingConnections() { for(Iterator it = buildings.iterator();it.hasNext();) { setConnectedNeighbours((Building)it.next()); } } private void setConnectedNeighbours(Building building) { ArrayList nearBuildings = new ArrayList(); ArrayList edges = new ArrayList(); for (int i = 0; i < buildings.size(); ++i) { Building b = (Building) buildings.get(i); int dist = building.distance(b); if (dist < FIRE_PASSING_DISTANCE && building != b) { nearBuildings.add(b); b.counter = 0; int[] apexes = b.buildingApexes(); for (int j = 0; j < apexes.length - 2; j += 2) { edges.add(new Wall(apexes[j], apexes[j + 1], apexes[j + 2],apexes[j + 3], b)); } } } HashSet connected = new HashSet(64); for (int i = 0; i < 180; i += RAY_DOMAIN) { double ang = (double) i * Math.PI / 180; double tg = Math.tan(ang + Math.PI / 2); ArrayList rightN = new ArrayList(); ArrayList leftN = new ArrayList(); for (int j = 0; j < edges.size(); ++j) { Wall edg = (Wall) edges.get(j); if (Util.Position(building.x(), building.y(), ang, tg, edg)) { if (edg.right) { rightN.add(edg); } else { leftN.add(edg); } } } if (rightN.size() > 0) { Wall minEdg = (Wall) rightN.get(0); for (int k = 1; k < rightN.size(); ++k) { Wall edg = (Wall) rightN.get(k); if (minEdg.distance > edg.distance) { minEdg = edg; } } if (minEdg.distance > 0) { connected.add(minEdg.b); minEdg.b.counter++; } } if (leftN.size() > 0) { Wall minEdg = (Wall) leftN.get(0); for (int k = 1; k < leftN.size(); ++k) { Wall edg = (Wall) leftN.get(k); if (minEdg.distance > edg.distance) { minEdg = edg; } } if (minEdg.distance > 0) { connected.add(minEdg.b); minEdg.b.counter++; } } } building.connectedBuildings.clear(); building.connectedBuildings.addAll(connected); building.connectionValues = new float[building.connectedBuildings.size()]; for(int i=building.connectedBuildings.size()-1; i>=0; --i) { building.connectionValues[i] = ((Building)building.connectedBuildings.get(i)).counter* RAY_DOMAIN / 450f; } } private Partition searchingPartition=null; public Partition getSearchingPartition(){ return searchingPartition; } public void setSearchingPartition(Partition partition){ searchingPartition = partition; } private final Comparator pathValComp = new Comparator() { float val1, val2; Path prPrevPath = null; final float prevPathAdd = 2f; final float prevPathCoef = 1.5f; Path path1,path2; boolean shCh = false; public int compare(Object obj1, Object obj2) { path1 = (Path) obj1; val1 = path1.getValue(); path2= (Path) obj2; val2 = path2.getValue(); if(prPrevPath != prevPath){ prPrevPath = prevPath; shCh = ! prevPath.checkPathIsOpen(); } if(prevPath != null && shCh){ if(obj1 == prevPath){// if (path1.getReportedBlockadesInCycle() >=// path2.getReportedBlockadesInCycle())// val1 *= prevPathCoef; val1 += prevPathAdd; } else if(obj2 == prevPath ) {// if (path2.getReportedBlockadesInCycle() >=// path1.getReportedBlockadesInCycle())// val2 *= prevPathCoef; val2 += prevPathAdd; } } return (int) ((val2 - val1) * 1000000f); } };}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -