📄 road.java
字号:
// Copyright (C) 2002 Takeshi Morimoto <morimoto@takopen.cs.uec.ac.jp>// All rights reserved.// Edited By Omid Aghazadehpackage yab.agent.object;import yab.agent.*;import yab.io.object.*;import java.util.*;public class Road extends Edge { public Road(int id, DisasterSpace world) { super(id, new BaseRoad(id), world); setIsReportedAsClear (false); } private BaseRoad obj() { return (BaseRoad) object; } public int width() { return obj().width(); } public int block() { return obj().block(); } public int repairCost() { return obj().repairCost(); } public int repairCost (int time) { return obj ().repairArray(time); } public int linesToHead() { return obj().linesToHead(); } public int linesToTail() { return obj().linesToTail(); } public int minLines() { return Util.min(linesToHead(),linesToTail()); } private float lineWidth() { return ((float) width()) / ((float) linesToHead() + linesToTail()); } private int blockedLines() { return (int) Math.floor(block() / (2f * lineWidth()) + 0.5f); } public int passableLinesToHead() { return Util.max(0, linesToHead() - blockedLines()); } public int passableLinesToTail() { return Util.max(0, linesToTail() - blockedLines()); } public int passableLinesTo(PointObject to) { return to == head() ? passableLinesToHead() : passableLinesToTail(); } public int passableLinesFrom(PointObject from) { return from == tail() ? passableLinesToHead() : passableLinesToTail(); } public int passableLines() { return Util.min(passableLinesToHead(), passableLinesToTail()); } public boolean isMovableBothDirections() { return passableLines() >=1; } public boolean isNotMovableBothDirections() { return passableLinesToHead() ==0 && passableLinesToTail() == 0; } public boolean isMovableAtLeastOneDirection() { return passableLinesToHead() >= 1 || passableLinesToTail() >= 1; } public boolean isNotMovableAtLeastOneDirection() { return passableLines() == 0; } public boolean isClearable() { return (blockedLines() >= 1); } private List m_ConnectedRoads = null; public List getConnectedRoads(){ if(m_ConnectedRoads==null){ m_ConnectedRoads = new ArrayList(); List hCol = new ArrayList(((Node)this.head()).getConnectedRoads()); List tCol = new ArrayList(((Node)this.tail()).getConnectedRoads()); tCol.removeAll(hCol); hCol.remove(this); m_ConnectedRoads.addAll(hCol); m_ConnectedRoads.addAll(tCol); } return m_ConnectedRoads; } private List m_ConnectedBuildings = null; public List getConnectedBuildings(){ if(m_ConnectedBuildings==null){ m_ConnectedBuildings = new ArrayList(); List hCol = new ArrayList(((Node)this.head()).getConnectedBuildings()); List tCol = new ArrayList(((Node)this.tail()).getConnectedBuildings()); m_ConnectedBuildings.addAll(hCol); m_ConnectedBuildings.addAll(tCol); } return m_ConnectedBuildings; } private int getHumanoidsCount(){ return MRL.Utilities.ConstantConditions.POSITION_PRP.eq(id).extract(MRL.Utilities.ConstantConditions.MO_POS_SET_C.extract(world.humanoids)).size(); } //Ashkan added public void setBlock (int mblok, int time) { obj ().setBlock (mblok, time); } private boolean m_isReportedAsClear; public boolean isReportedAsClear () { return m_isReportedAsClear; } public void setIsReportedAsClear (boolean isReportedAsClear) { this.m_isReportedAsClear = isReportedAsClear; } public int block (int time) { return obj ().blockArray(time); } private int blockedLines (int time) { return (int) Math.floor (block (time) / (2f * lineWidth ()) + 0.5f); } public int passableLinesToHead (int time) { return Util.max (0, linesToHead () - blockedLines (time)); } public int passableLinesToTail (int time) { return Util.max (0, linesToTail () - blockedLines (time)); } public int passableLines (int time) { return Util.min (passableLinesToHead (time), passableLinesToTail (time)); } int BLOCK_CYCLES = 27; public boolean mustBeBlocked (int t) { if (isReportedAsClear ()) return false; return (hasBeenSeen () && passableLines () < 1 && t - this.time () <= BLOCK_CYCLES); } public final Report reportBlock = new Report(); public final Report reportUnclear = new Report(); public final Report reportClear = new Report(); //Ashkan added public boolean isOneWay(){ return linesToHead() == 0 || linesToTail() == 0; } public int getRemainingCyclesToBePassable(){ if(isOneWay()){ if(linesToHead() == 0 ){ if( passableLinesToTail() > 0) return 0; int bl = linesToTail() - 1; int nb = (int) Math.ceil( bl * (( 2f * lineWidth()) + 0.5f)); if(block() < nb) throw new Error (this + " NB : " + nb + " Block : " + block()); } if(linesToTail() == 0 && passableLinesToHead() > 0) return 0; } else{ if(passableLines() > 0 ) return 0; if(linesToHead() > linesToTail()){ } else{ } } return -1; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -