⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 heardcivilianmessage.java

📁 2004年robotcup世界冠军源代码
💻 JAVA
字号:
package MRL.Utilities.MessageManagement;

import yab.agent.DisasterSpace;
import yab.agent.object.*;

import java.util.Map;

public class HeardCivilianMessage extends Message
{
    static final int realIdSize = 32;
    static final int posExtraSize = 6;

    int realId;
    int posId;
    int posExtra;

    public HeardCivilianMessage(Humanoid civilian, MotionlessObject position , int posEx)
    {
        super(Type.HEARDCIVILIAN_REPORT, civilian);
        realId = civilian.id;
        posId = position.id;
        posExtra = posEx / 1000;
    }

    public HeardCivilianMessage(char[] message, Map virtualIdToId)
    {
        super(Type.HEARDCIVILIAN_REPORT, null);

        this.realId = Util.charArrayToint(message, 0, realIdSize);
        this.posId = ((Integer) virtualIdToId.get(new Integer(Util.charArrayToint(message, realIdSize, idSize)))).intValue();
        this.posExtra = Util.charArrayToint(message, realIdSize + idSize, posExtraSize);
    }

    static protected int staticLength()
    {
        return realIdSize + idSize + posExtraSize;
    }

    public boolean equals(Object m)
    {
        if (!(m instanceof HeardCivilianMessage)) return false;
        return realId == ((HeardCivilianMessage) m).realId && posId == ((HeardCivilianMessage) m).posId;
    }

    public int getCivilianId()
    {
        return realId;
    }

    public int hashCode()
    {
        return realId;
    }


    void updateWorld(DisasterSpace world, int time)
    {
        obj = world.get(realId);
        if (obj == null)
        {
            obj = RCRObject.produce(TYPE_CIVILIAN, realId, world);
            world.add((RealObject) obj);
            obj.setTime(0);
            obj.setHearTime(time); /// ?????? omid Gh
        }


        //System.out.println(" I am 4022 in Heard Civilian message and the Civilian is:"+ obj.id + "  Position:"+((Civilian)obj).position()       );
        MotionlessObject mo = (MotionlessObject) world.get(posId);
        if (obj instanceof Civilian&& ((Civilian)obj).position() == null && world.self instanceof Humanoid)
        {
            Civilian civ = (Civilian)obj;
            world.hearData.addHearedCivilian(civ,mo,posExtra*1000, time,false);
            civ.updatePossiblePoses();
//            System.out.println(world.self + " , Heared Position Updating From Message : " + civ + " , MP : " + mo + " , Time : " + time );
        }
    }

    char[] toCharArray(Map idToVirtualIds) // buildingId - firestart - threshold //- time
    {
        char[] result = new char[length()];
        char[] temp;

        temp = Util.intToCharArray(obj.id, realIdSize);
        Util.copyArray(temp, result, 0, 0, realIdSize);

        temp = Util.intToCharArray(((Integer) idToVirtualIds.get(new Integer(posId))).intValue(), idSize);
        Util.copyArray(temp, result, 0, realIdSize, idSize);

        temp = Util.intToCharArray(posExtra,posExtraSize);
        Util.copyArray(temp, result, 0, realIdSize+ idSize,posExtraSize);

        return result;
    }

    protected int length()
    {
        return staticLength();
    }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -