📄 positionmessage.java
字号:
package MRL.Utilities.MessageManagement;import yab.agent.*;import yab.agent.object.*;import java.util.Map;import java.util.Collections;/** * Created by IntelliJ IDEA. * User: Maryam * Date: Jun 26, 2005 * Time: 9:17:57 AM * To change this template use File | Settings | File Templates. *///saeed 85-2-3public class PositionMessage extends Message{ int positionId; boolean isOPHead = false; int index; static final int indexSize = 6; static final int flagSize = 1; public PositionMessage(MovingObject position, int index) { super(Type.POSITION_REPORT, position); MotionlessObject mp = position.motionlessPosition(); this.positionId = mp.id; this.index = index; if(mp instanceof Road){ Road rd = (Road) mp; if(MRL.Utilities.ConstantConditions.NOT_PASSABLE_C.eval(rd)){ Node op = HumanoidAgent.outsidePosition(position); if(op == rd.head()) isOPHead = true; else isOPHead = false; } }else isOPHead = false; } char[] toCharArray(Map idToVirtualId) { char[] result = new char[length()]; char[] temp = Util.intToCharArray(((Integer) (idToVirtualId.get(new Integer(positionId)))).intValue(), idSize); Util.copyArray(temp, result, 0, 0, idSize); temp = Util.intToCharArray(index, indexSize); Util.copyArray(temp, result, 0, idSize, indexSize); temp = new char[1]; if(isOPHead) temp[0] = '1'; else temp[0] = '0'; Util.copyArray(temp,result,0,idSize + indexSize , flagSize); return result; } protected int length() { return staticLength(); } protected static int staticLength() { return idSize + indexSize + flagSize; } public boolean equals(Object m) { if (!(m instanceof PositionMessage)) return false; return ((PositionMessage) m).index == index; } public int hashCode() { return index; } void updateWorld(DisasterSpace world, int time) { Collections.sort(world.agents, yab.agent.Util.idComparator); Humanoid human = (Humanoid) world.agents.get(index); //if (human.id == world.self.id) // return; if (human.getAliveTime() < time - 2) { human.setAliveTime(time); human.setProperty(world.time(), PROPERTY_POSITION, new int[]{positionId}); MotionlessObject mo = (MotionlessObject)world.get(positionId); if(mo instanceof Road){ Road rd = (Road) mo; if(isOPHead){ human.setProperty(world.time(), PROPERTY_POSITION_EXTRA, new int[]{0}); } else{ human.setProperty(world.time(), PROPERTY_POSITION_EXTRA, new int[]{rd.length() -1}); } } } //human.setHearTime(time); //human.setTime(time); //todo: update agent's position } public PositionMessage(char[] message, Map virtualIdToId) { super(Type.POSITION_REPORT, null); this.positionId = ((Integer) virtualIdToId.get(new Integer(Util.charArrayToint(message, 0, idSize)))).intValue(); this.index = Util.charArrayToint(message, idSize, indexSize); this.isOPHead = message[idSize + indexSize] == '1'; }}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -