📄 setpartitionmessage.java
字号:
package MRL.Utilities.MessageManagement;
import yab.agent.DisasterSpace;
import yab.agent.object.*;
import java.util.Map;
import java.util.Collections;
import MRL.Utilities.Partitioning.Partition;
import MRL.Police.EPoliceForce;
//saeed 85-2-3
public class SetPartitionMessage extends Message
{
int policeIdx;
int partId;
static final int indexSize = 6;
public SetPartitionMessage(int policeIdx, int partId)
{
super(Type.SETPARTITION_REPORT, null);
this.policeIdx = policeIdx;
this.partId = partId;
}
char[] toCharArray(Map ids)
{
char[] result = new char[length()];
char[] temp = Util.intToCharArray(policeIdx, indexSize);
Util.copyArray(temp, result, 0, 0, indexSize);
temp = Util.intToCharArray(partId, indexSize);
Util.copyArray(temp, result, 0, indexSize, indexSize);
return result;
}
protected int length()
{
return staticLength();
}
protected static int staticLength()
{
return indexSize + indexSize;
}
public boolean equals(Object m)
{
if (!(m instanceof SetPartitionMessage)) return false;
return ((SetPartitionMessage) m).policeIdx == policeIdx;
}
public int hashCode()
{
return policeIdx;
}
void updateWorld(DisasterSpace world, int time)
{
if (world.self instanceof PoliceForce)
{
EPoliceForce me = (EPoliceForce)world.self;
Collections.sort(world.policeForces, yab.agent.Util.idComparator);
Humanoid agent = (Humanoid) world.policeForces.get(policeIdx);
Partition workingPartition = world.partitioner.getPartition(partId);
me.polPartMap.put(agent,workingPartition);
if (agent != me)
{
return;
}
if (workingPartition == null) {
System.err.println("Error , Cannot Assign To Null Partition");
} else
{
if (me.prevWorkingPartition != null)if (me.toReport == false) {
me.toReport = true;
world.shouldUpdateAlphas = false;
}
me.prevWorkingPartition = world.workingPartition;
world.setWorkingPartition(workingPartition);
me.reportedBlockadesIP.clear();
// me.reportedBlockadesIP.addAll(workingPartition.ML_OBJS_IN_PART_CND.extract(me.reportedBlockades));
if (MRL.MRLConstants.PARTITION_DEBUG_MODE) System.out.println(
"Police Force : " + me.id + " , Partition SET : " +
world.workingPartition.getID());
}
}
}
public SetPartitionMessage(char[] message)
{
super(Type.SETPARTITION_REPORT, null);
this.policeIdx = Util.charArrayToint(message, 0, indexSize);
this.partId = Util.charArrayToint(message, indexSize, indexSize);
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -