Unverified Commit 342fea6f authored by Juon Kawakami's avatar Juon Kawakami 🥗
Browse files

init

parent 54f6cedf
/*
* Last change: $Date: 2004/08/03 03:25:04 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueConstants;
public class KAHear extends Command {
private int toID;
private int fromID;
private int length;
private byte[] msg;
private byte channel;
public KAHear(int to, int from, int length, byte[] data, byte channel) {
super(RescueConstants.KA_HEAR);
toID = to;
fromID = from;
this.length = length;
msg = new byte[length];
System.arraycopy(data,0,msg,0,length);
this.channel = channel;
}
public KAHear(InputBuffer in) {
super(RescueConstants.KA_HEAR);
read(in);
}
public void read(InputBuffer in) {
toID = in.readInt();
fromID = in.readInt();
channel = (byte)in.readInt();
length = in.readInt();
msg = new byte[length];
in.readBytes(msg);
}
public void write(OutputBuffer out) {
out.writeInt(toID);
out.writeInt(fromID);
out.writeInt(channel);
out.writeInt(length);
out.writeBytes(msg);
}
public int getToID() {
return toID;
}
public int getFromID() {
return fromID;
}
public int getLength() {
return length;
}
public byte[] getData() {
return msg;
}
public byte getChannel() {
return channel;
}
public String toString() {
return super.toString()+" from "+fromID+" to "+toID+": "+length+" bytes on channel "+channel;
}
}
/*
* Last change: $Date: 2004/05/20 23:42:00 $
* $Revision: 1.1 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueObject;
import rescuecore.RescueConstants;
public class KASense extends Command {
private int id;
private int time;
private RescueObject[] updates;
public KASense(int id, int time, RescueObject[] updates) {
super(RescueConstants.KA_SENSE);
this.id = id;
this.time = time;
this.updates = updates;
}
public KASense(InputBuffer in) {
super(RescueConstants.KA_SENSE);
read(in);
}
public void read(InputBuffer in) {
id = in.readInt();
time = in.readInt();
updates = in.readObjects(time,RescueConstants.SOURCE_SENSE);
}
public void write(OutputBuffer out) {
out.writeInt(id);
out.writeInt(time);
out.writeObjects(updates);
}
public int getID() {
return id;
}
public int getTime() {
return time;
}
public RescueObject[] getUpdatedObjects() {
return updates;
}
}
/*
* Last change: $Date: 2004/05/20 23:42:00 $
* $Revision: 1.1 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueConstants;
public class KSConnectError extends Command {
private String reason;
public KSConnectError(String reason) {
super(RescueConstants.KS_CONNECT_ERROR);
this.reason = reason;
}
public KSConnectError(InputBuffer in) {
super(RescueConstants.KS_CONNECT_ERROR);
read(in);
}
public void read(InputBuffer in) {
reason = in.readString();
}
public void write(OutputBuffer out) {
out.writeString(reason);
}
public String getReason() {
return reason;
}
}
/*
* Last change: $Date: 2005/06/14 21:55:52 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueConstants;
import rescuecore.RescueObject;
public class KSConnectOK extends Command {
private int id;
private RescueObject[] knowledge;
public KSConnectOK(int id, RescueObject[] knowledge) {
super(RescueConstants.KS_CONNECT_OK);
this.knowledge = knowledge;
this.id = id;
}
public KSConnectOK(InputBuffer in) {
super(RescueConstants.KS_CONNECT_OK);
read(in);
}
public void read(InputBuffer in) {
id = in.readInt();
knowledge = in.readObjects(0,null);
}
public void write(OutputBuffer out) {
out.writeInt(id);
out.writeObjects(knowledge);
}
public int getSimulatorID() {
return id;
}
public RescueObject[] getKnowledge() {
return knowledge;
}
}
/*
* Last change: $Date: 2004/05/20 23:42:00 $
* $Revision: 1.1 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueConstants;
public class KVConnectError extends Command {
private String reason;
public KVConnectError(String reason) {
super(RescueConstants.KV_CONNECT_ERROR);
this.reason = reason;
}
public KVConnectError(InputBuffer in) {
super(RescueConstants.KV_CONNECT_ERROR);
read(in);
}
public void read(InputBuffer in) {
reason = in.readString();
}
public void write(OutputBuffer out) {
out.writeString(reason);
}
public String getReason() {
return reason;
}
}
/*
* Last change: $Date: 2005/06/14 21:55:52 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueConstants;
import rescuecore.RescueObject;
public class KVConnectOK extends Command {
private RescueObject[] knowledge;
public KVConnectOK(RescueObject[] knowledge) {
super(RescueConstants.KV_CONNECT_OK);
this.knowledge = knowledge;
}
public KVConnectOK(InputBuffer in) {
super(RescueConstants.KV_CONNECT_OK);
read(in);
}
public void read(InputBuffer in) {
knowledge = in.readObjects(0,null);
}
public void write(OutputBuffer out) {
out.writeObjects(knowledge);
}
public RescueObject[] getKnowledge() {
return knowledge;
}
}
/*
* Last change: $Date: 2004/05/27 03:41:02 $
* $Revision: 1.2 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
public class Nozzle implements java.io.Serializable {
private int target, direction, x, y, water;
public Nozzle(int target, int direction, int x, int y, int water) {
this.target = target;
this.direction = direction;
this.x = x;
this.y = y;
this.water = water;
}
public int getTarget() {return target;}
public int getDirection() {return direction;}
public int getX() {return x;}
public int getY() {return y;}
public int getWater() {return water;}
}
/*
* Last change: $Date: 2004/05/20 23:42:00 $
* $Revision: 1.1 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueConstants;
public class SKAcknowledge extends Command {
private int id;
public SKAcknowledge(int id) {
super(RescueConstants.SK_ACKNOWLEDGE);
this.id = id;
}
public SKAcknowledge(InputBuffer in) {
super(RescueConstants.SK_ACKNOWLEDGE);
read(in);
}
public void read(InputBuffer in) {
id = in.readInt();
}
public void write(OutputBuffer out) {
out.writeInt(id);
}
}
/*
* Last change: $Date: 2004/05/20 23:42:00 $
* $Revision: 1.1 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueObject;
import rescuecore.RescueConstants;
public class SKConnect extends Command {
private int version;
private String name;
public SKConnect(String name) {
this(0, name);
}
public SKConnect(int version, String name) {
super(RescueConstants.SK_CONNECT);
this.version = version;
this.name = name;
}
public SKConnect(InputBuffer in) {
super(RescueConstants.SK_CONNECT);
read(in);
}
public void read(InputBuffer in) {
version = in.readInt();
name = in.readString();
}
public void write(OutputBuffer out) {
out.writeInt(version);
out.writeString(name);
}
public int getVersion() {
return version;
}
}
/*
* Last change: $Date: 2004/05/20 23:42:00 $
* $Revision: 1.1 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueConstants;
import rescuecore.RescueObject;
public class SKUpdate extends Command {
private int id;
private int time;
private RescueObject[] changed;
public SKUpdate(int id, int time, RescueObject[] changed) {
super(RescueConstants.SK_UPDATE);
this.id = id;
this.time = time;
this.changed = changed;
}
public SKUpdate(InputBuffer in) {
super(RescueConstants.SK_UPDATE);
read(in);
}
public void read(InputBuffer in) {
id = in.readInt();
time = in.readInt();
changed = in.readObjects(time,null);
}
public void write(OutputBuffer out) {
out.writeInt(id);
out.writeInt(time);
out.writeObjects(changed);
}
public RescueObject[] getChangedObjects() {
return changed;
}
public int getSimulatorID() {
return id;
}
public int getTime() {
return time;
}
}
/*
* Last change: $Date: 2004/05/20 23:42:00 $
* $Revision: 1.1 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueConstants;
import rescuecore.RescueObject;
public class Update extends Command {
private int time;
private RescueObject[] changed;
public Update(int time, RescueObject[] changed) {
super(RescueConstants.UPDATE);
this.time = time;
this.changed = changed;
}
public Update(InputBuffer in) {
super(RescueConstants.UPDATE);
read(in);
}
public void read(InputBuffer in) {
time = in.readInt();
changed = in.readObjects(time,RescueConstants.SOURCE_UPDATE);
}
public void write(OutputBuffer out) {
out.writeInt(time);
out.writeObjects(changed);
}
public int getTime() {
return time;
}
public RescueObject[] getUpdatedObjects() {
return changed;
}
}
/*
* Last change: $Date: 2004/05/20 23:42:00 $
* $Revision: 1.1 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueConstants;
public class VKAcknowledge extends Command {
public VKAcknowledge() {
super(RescueConstants.VK_ACKNOWLEDGE);
}
public VKAcknowledge(InputBuffer in) {
super(RescueConstants.VK_ACKNOWLEDGE);
}
public void read(InputBuffer in) {
}
public void write(OutputBuffer out) {
}
}
/*
* Last change: $Date: 2004/05/20 23:42:00 $
* $Revision: 1.1 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.commands;
import rescuecore.InputBuffer;
import rescuecore.OutputBuffer;
import rescuecore.RescueObject;
import rescuecore.RescueConstants;
public class VKConnect extends Command {
private int version;
private String name;
public VKConnect(String name) {
this(0, name);
}
public VKConnect(int version, String name) {
super(RescueConstants.VK_CONNECT);
this.version = version;
this.name = name;
}
public VKConnect(InputBuffer in) {
super(RescueConstants.VK_CONNECT);
read(in);
}
public void read(InputBuffer in) {
version = in.readInt();
name = in.readString();
}
public void write(OutputBuffer out) {
out.writeInt(version);
out.writeString(name);
}
public int getVersion() {
return version;
}
}
package rescuecore.config;
import java.io.IOException;
import java.io.FileReader;
import java.io.BufferedReader;
import java.io.PrintWriter;
import java.io.File;
import java.util.Map;
import java.util.HashMap;
import java.util.Collections;
import java.util.Set;
/**
This class represents a config file and any other config files that might have been included with a !include directive. Config files must be defined relative to a base directory so that includes can be resolved.
*/
public class Config {
private static final String INCLUDE = "!include";
/**
The raw data and caches of int/float/boolean interpretations.
*/
private Map<String, String> data;
private Map<String, Integer> intData;
private Map<String, Double> floatData;
private Map<String, Boolean> booleanData;
/**
Create an empty config.
*/
public Config() {
data = new HashMap<String, String>();
intData = new HashMap<String, Integer>();
floatData = new HashMap<String, Double>();
booleanData = new HashMap<String, Boolean>();
}
/**
Create a config that reads from a given file. Additional config files can be read later with the {@link read(String)} method.
@param file The config file to read. Must not be null.
@throws IOException If there is an error reading the file.
@throws ConfigException If there is an error parsing the config file or one of its descendants.
*/
public Config(File file) throws IOException, ConfigException {
this();
read(file);
}
/**
Read a config file and add its contents. Existing entries with the same name will be overwritten.
@param file The config file to read. Must not be null. If this is a directory then all files in the directory will be read.
@throws IOException If there is an error reading the file.
@throws ConfigException If there is an error parsing the config file or one of its descendants.
*/
public void read(File file) throws IOException, ConfigException {
if (file == null) {
throw new IllegalArgumentException("File cannot be null");
}
if (!file.exists()) {
throw new IllegalArgumentException("File " + file.getAbsolutePath() + " does not exist");
}
if (file.isDirectory()) {
for (File next : file.listFiles()) {
read(next);
}
}
else {
readConfigFile(file);
}
}
/**
Read config information from a Reader and add its contents. Existing entries with the same name will be overwritten.
@param in The Reader to read from. Must not be null.
@throws IOException If there is an error reading the file.
@throws ConfigException If there is an error parsing the config file or one of its descendants.
*/
private void readConfigFile(File in) throws IOException, ConfigException {
BufferedReader reader = new BufferedReader(new FileReader(in));
String name = in.getAbsolutePath();
String line = "";
int lineNumber = 0;
try {
while (line != null) {
line = reader.readLine();
++lineNumber;
if (line != null) {
line = line.trim();
// Ignore empty lines
if ("".equals(line)) {
continue;
}
// Ignore lines that start with #
if (line.startsWith("#")) {
continue;
}
// Look for a !include
else if (line.startsWith(INCLUDE)) {
if (INCLUDE.equals(line)) {
throw new ConfigException(name, "Line " + lineNumber + ": Empty include directive");
}
String includeName = line.substring(INCLUDE.length() + 1).trim();
if ("".equals(includeName)) {
throw new ConfigException(name, "Line " + lineNumber + ": Empty include directive");
}
read(new File(in.getParentFile(), includeName));
}
else {
int index = line.indexOf(':');
if (index == -1) {
throw new ConfigException(name, "Line " + lineNumber + ": No ':' found");
}
if (index == line.length() - 1) {
throw new ConfigException(name, "Line " + lineNumber + ": No value found");
}
if (index == 0) {
throw new ConfigException(name, "Line " + lineNumber + ": No key found");
}
String key = line.substring(0, index).trim();
String value = line.substring(index + 1).trim();
data.put(key, value);
intData.remove(key);
floatData.remove(key);
booleanData.remove(key);
}
}
}
}
finally {
reader.close();
}
}
/**
Write this config to a PrintWriter.
@param out The PrintWriter to write to. Must not be null.
@throws IOException If there is an error writing to the stream.
*/
public void write(PrintWriter out) throws IOException {
if (out == null) {
throw new IllegalArgumentException("Output cannot be null");
}
for (Map.Entry<String, String> next : data.entrySet()) {
out.print(next.getKey());
out.print(" : ");
out.println(next.getValue());
}
}
/**
Get all keys in this config.
@return An immutable view of all keys.
*/
public Set<String> getAllKeys() {
return Collections.unmodifiableSet(data.keySet());
}
/**
Get the value of a key as a String.
@param key The key to look up. Must not be null.
@return The value associated with that key.
@throws NoSuchConfigOptionException If the key is not defined.
*/
public String getValue(String key) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null");
}
if (!data.containsKey(key)) {
throw new NoSuchConfigOptionException(key);
}
return data.get(key);
}
/**
Get the value of a key as an integer.
@param key The key to look up. Must not be null.
@return The value associated with that key interpreted as an integer.
@throws NoSuchConfigOptionException If the key is not defined.
@throws NumberFormatException If the value of the key cannot be interpreted as an integer.
*/
public int getIntValue(String key) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null");
}
if (intData.containsKey(key)) {
return intData.get(key);
}
int result = Integer.parseInt(getValue(key));
intData.put(key, result);
return result;
}
/**
Get the value of a key as a floating point number.
@param key The key to look up. Must not be null.
@return The value associated with that key interpreted as a floating point number.
@throws NoSuchConfigOptionException If the key is not defined.
@throws NumberFormatException If the value of the key cannot be interpreted as a floating point number.
*/
public double getFloatValue(String key) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null");
}
if (floatData.containsKey(key)) {
return floatData.get(key);
}
double result = Double.parseDouble(getValue(key));
floatData.put(key, result);
return result;
}
/**
Get the value of a key as a boolean. "true", "t", "yes", "y" and "1" (case insensitive) are all interpreted as true, all other values are false.
@param key The key to look up. Must not be null.
@return The value associated with that key interpreted as a boolean.
@throws NoSuchConfigOptionException If the key is not defined.
*/
public boolean getBooleanValue(String key) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null");
}
if (booleanData.containsKey(key)) {
return booleanData.get(key);
}
boolean result = false;
String value = getValue(key);
if ("true".equalsIgnoreCase(value)
|| "t".equalsIgnoreCase(value)
|| "yes".equalsIgnoreCase(value)
|| "y".equalsIgnoreCase(value)
|| "1".equalsIgnoreCase(value)) {
result = true;
}
booleanData.put(key, result);
return result;
}
/**
Set the value of a key.
@param key The key to set. Must not be null.
@param value The new value. If this is null then {@link #removeKey(String)} is called with the given key.
*/
public void setValue(String key, String value) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null");
}
if (value == null) {
removeKey(key);
return;
}
data.put(key, value);
intData.remove(key);
floatData.remove(key);
booleanData.remove(key);
}
/**
Set the value of a key as an integer.
@param key The key to set. Must not be null.
@param value The new value.
*/
public void setIntValue(String key, int value) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null");
}
data.put(key, Integer.valueOf(value).toString());
intData.put(key, value);
floatData.remove(key);
booleanData.remove(key);
}
/**
Set the value of a key as a floating point number.
@param key The key to set. Must not be null.
@param value The new value.
*/
public void setFloatValue(String key, double value) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null");
}
data.put(key, Double.valueOf(value).toString());
intData.remove(key);
floatData.put(key, value);
booleanData.remove(key);
}
/**
Set the value of a key as a boolean.
@param key The key to set. Must not be null.
@param value The new value.
*/
public void setBooleanValue(String key, boolean value) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null");
}
data.put(key, value ? "true" : "false");
intData.remove(key);
floatData.remove(key);
booleanData.put(key, value);
}
/**
Remove a key from the config.
@param key The key to remove. Must not be null.
*/
public void removeKey(String key) {
if (key == null) {
throw new IllegalArgumentException("Key cannot be null");
}
data.remove(key);
intData.remove(key);
floatData.remove(key);
booleanData.remove(key);
}
/**
Remove all keys.
*/
public void removeAllKeys() {
data.clear();
intData.clear();
floatData.clear();
booleanData.clear();
}
}
package rescuecore.config;
/**
Exception class for problems with config files.
*/
public class ConfigException extends Exception {
/**
Construct an exception with just a filename, no message or underlying cause.
@param filename The name of the config file that caused the problem.
*/
public ConfigException(final String filename) {
super(filename + ": unknown error");
}
/**
Construct an exception with a filename and error message.
@param filename The name of the config file that caused the problem.
@param msg A message describing the problem.
*/
public ConfigException(final String filename, final String msg) {
super(filename + ": " + msg);
}
/**
Construct an exception with a filename and an underlying cause.
@param filename The name of the config file that caused the problem.
@param cause The underlying cause of this exception.
*/
public ConfigException(final String filename, final Throwable cause) {
super(filename + ": " + cause.toString(), cause);
}
/**
Construct an exception with a filename, error message and underlying cause.
@param filename The name of the config file that caused the problem.
@param msg A message describing the problem.
@param cause The underlying cause of this exception.
*/
public ConfigException(final String filename, final String msg, final Throwable cause) {
super(filename + ": " + msg, cause);
}
}
package rescuecore.config;
/**
An unchecked exception that is thrown when an application attempts to read an undefined config option.
*/
public class NoSuchConfigOptionException extends RuntimeException {
/**
Construct an exception.
@param key The name of the key that does not exist in the config.
*/
public NoSuchConfigOptionException(final String key) {
super(key);
}
}
package rescuecore.debug;
import java.util.*;
import javax.swing.*;
import java.awt.*;
import rescuecore.view.*;
import rescuecore.*;
public class CollectionHandler implements Handler {
private Collection current;
private Layer layer;
private CollectionView component;
public JComponent getComponent() {
if (component==null) {
component = new CollectionView();
component.setObjects(current);
}
return component;
}
public Layer getLayer() {
if (layer==null) {
layer = new Layer("Collection handler");
layer.addObjects(current);
}
return layer;
}
public boolean handle(Object o, int timeStep) {
if (o instanceof Collection) {
current = (Collection)o;
if (layer!=null) layer.setObjects(current);
if (component != null) component.setObjects(current);
return true;
}
return false;
}
public void setMemory(Memory m) {
}
private static class CollectionView extends JPanel {
private CollectionModel model;
public CollectionView() {
super(new BorderLayout());
model = new CollectionModel();
add(new JScrollPane(new JList(model)),BorderLayout.CENTER);
}
public void setObjects(Collection c) {
model.setObjects(c);
}
private static class CollectionModel extends AbstractListModel {
private String[] data;
public CollectionModel() {
data = new String[0];
}
public int getSize() {
return data.length;
}
public Object getElementAt(int index) {
return data[index];
}
public void setObjects(Collection c) {
data = new String[c.size()];
int i=0;
for (Iterator it = c.iterator();it.hasNext();++i) {
Object next = it.next();
data[i] = next==null?"null":next.toString();
}
fireContentsChanged(this,0,data.length);
}
}
}
}
/*
* Last change: $Date: 2004/06/10 01:17:51 $
* $Revision: 1.11 $
*
* Copyright (c) 2004, The Black Sheep, Department of Computer Science, The University of Auckland
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
* Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
* Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
* Neither the name of The Black Sheep, The Department of Computer Science or The University of Auckland nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
package rescuecore.debug;
import rescuecore.*;
import rescuecore.objects.*;
import rescuecore.view.*;
import rescuecore.commands.*;
import javax.swing.*;
import javax.swing.border.*;
import java.awt.*;
public class CommandHandler implements Handler {
private Layer commandLayer;
private DefaultListModel messages;
private JScrollPane messagePane;
private int timeStep = -1;
private Memory memory;
public CommandHandler(){
JPanel messagePanel = new JPanel(new BorderLayout());
Border bord = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.BLACK),"Commands");
messagePanel.setBorder(bord);
messages = new DefaultListModel();
JList messageList = new JList(messages);
messagePanel.add(messageList,BorderLayout.CENTER);
messagePane = new JScrollPane(messagePanel);
messagePane.setPreferredSize(new Dimension(DebugPane.HANDLER_WIDTH,80));
}
public void setMemory(Memory m){
memory = m;
}
public JComponent getComponent(){
return messagePane;
}
public Layer getLayer(){
if(commandLayer == null){
commandLayer = new Layer("Move Commands");
commandLayer.addRenderer(RescueObject[].class,OutlineRenderer.ORANGE);
commandLayer.addRenderer(Humanoid.class,HumanoidRenderer.outlinedHumanoidRenderer(ViewConstants.FILL_MODE_SOLID, new Color(255,255,255,96)));
commandLayer.addRenderer(ExtinguishCommand.class, new ExtinguishCommandRenderer());
}
return commandLayer;
}
public boolean handle(Object o, int timeStep){
if(this.timeStep != timeStep){
commandLayer.removeAllObjects();
messages.clear();
this.timeStep = timeStep;
}
if(!(o instanceof Command))
return false;
Command c = (Command)o;
if(c == null)
return true;
int id;
switch(c.getType()){
case RescueConstants.AK_MOVE:
int[] path = ((AKMove)c).getPath();
RescueObject[] rs = new RescueObject[path.length];
rs[0] = memory.lookup(path[0]);
RescueObject last = null;
for (int i=0;i<rs.length;++i){
rs[i] = memory.lookup(path[i]);
if(rs[i] == null)
messages.addElement("Bad ID in path. Index "+i+". ID "+path[i]);
else if(rs[i].isNode()){
if(last != null)
commandLayer.addObject(new RescueObject[]{last,rs[i]});
last = rs[i];
}
}
break;
case RescueConstants.AK_SAY:
messages.addElement("Say of "+((AKSay)c).getMessage().length+" bytes.");
break;
case RescueConstants.AK_TELL:
messages.addElement("Tell of "+((AKTell)c).getMessage().length+" bytes.");
break;
case RescueConstants.AK_EXTINGUISH:
AKExtinguish ex = (AKExtinguish)c;
id = ex.getSender();
Nozzle[] nozzles = ex.getNozzles();
for (int i=0;i<nozzles.length;++i) {
int targetID = nozzles[i].getTarget();
messages.addElement("Extinguishing building "+targetID);
try {
commandLayer.addObject(new ExtinguishCommand((Building)memory.lookup(targetID),(Humanoid)memory.lookup(id),memory));
}
catch (CannotFindLocationException e) {
e.printStackTrace();
}
}
break;
case RescueConstants.AK_CLEAR:
id = ((AKClear)c).getSender();
commandLayer.addObject(memory.lookup(id));
messages.addElement("Clearing road.");
break;
case RescueConstants.AK_RESCUE:
id = ((AKRescue)c).getSender();
commandLayer.addObject(memory.lookup(id));
messages.addElement("Rescuing.");
break;
case RescueConstants.AK_LOAD:
id = ((AKLoad)c).getSender();
commandLayer.addObject(memory.lookup(id));
messages.addElement("Loading.");
break;
case RescueConstants.AK_UNLOAD:
id = ((AKUnload)c).getSender();
commandLayer.addObject(memory.lookup(id));
messages.addElement("Unloading.");
break;
}
return true;
}
}
package rescuecore.debug;
import java.io.Serializable;
import rescuecore.RescueObject;
import java.util.*;
public abstract class DebugEntry implements Serializable {
private int time;
protected DebugEntry(int time) {
this.time = time;
}
public int getTimestep() {
return time;
}
public static class RescueObjectEntry extends DebugEntry {
private RescueObject object;
public RescueObjectEntry(RescueObject object, int time) {
super(time);
this.object = object;
}
public RescueObject getObject() {
return object;
}
public String toString() {
return "Object added: "+object;
}
}
public static class RescueObjectCollectionEntry extends DebugEntry {
private Collection<RescueObject> objects;
public RescueObjectCollectionEntry(Collection<RescueObject> objects, int time) {
super(time);
this.objects = new HashSet<RescueObject>(objects);
}
public Collection<RescueObject> getObjects() {
return objects;
}
public String toString() {
return "Object collection: "+objects.size()+" objects";
}
}
public static abstract class PropertyUpdateEntry extends DebugEntry {
protected int property;
protected int objectID;
protected PropertyUpdateEntry(int objectID, int property, int time) {
super(time);
this.property = property;
this.objectID = objectID;
}
public int getProperty() {
return property;
}
public int getObjectID() {
return objectID;
}
}
public static class IntPropertyUpdateEntry extends PropertyUpdateEntry {
private int newValue;
public IntPropertyUpdateEntry(int id, int property, int value, int time) {
super(id,property,time);
newValue = value;
}
public int getNewValue() {
return newValue;
}
public String toString() {
return "Integer update: Object: "+objectID+" Property: "+property;
}
}
public static class ArrayPropertyUpdateEntry extends PropertyUpdateEntry {
private int[] newValue;
public ArrayPropertyUpdateEntry(int id, int property, int[] value, int time) {
super(id,property,time);
newValue = value;
}
public int[] getNewValue() {
return newValue;
}
public String toString() {
return "Array update: Object: "+objectID+" Property: "+property;
}
}
public static class ObjectDebugEntry extends DebugEntry {
private final static long serialVersionUID = -7542261088352191771l;
private Object object;
public ObjectDebugEntry(Object object, int time) {
super(time);
this.object = object;
}
public Object getObject() {
return object;
}
public String toString() {
return "User object: "+object;
}
}
}
package rescuecore.debug;
import java.io.*;
import java.util.*;
import rescuecore.*;
public class DebugLog {
private final static Collection<DebugEntry> NO_ENTRIES = Collections.emptySet();
private Map<String,List<List<DebugEntry>>> nameToEntries;
private int maxTimestep;
public DebugLog(String fileName) throws IOException, ClassNotFoundException {
this(new File(fileName));
}
public DebugLog(File file) throws IOException, ClassNotFoundException {
nameToEntries = new HashMap<String,List<List<DebugEntry>>>();
maxTimestep = 0;
try {
ObjectInputStream in = new ObjectInputStream(new BufferedInputStream(new FileInputStream(file)));
while (true) {
String name = in.readUTF();
DebugEntry next = (DebugEntry)in.readObject();
System.out.println(next);
addEntry(name,next);
maxTimestep = Math.max(maxTimestep,next.getTimestep());
}
}
catch (EOFException e) {
}
}
public Collection<String> getAllNames() {
return nameToEntries.keySet();
}
public int getMaxTimestep(String name) {
List<List<DebugEntry>> listOfLists = nameToEntries.get(name);
if (listOfLists==null) return -1;
return listOfLists.size()-1;
}
public int getMaxTimestep() {
return maxTimestep;
}
public Collection<DebugEntry> getEntriesForTime(String name, int time) {
List<List<DebugEntry>> listOfLists = nameToEntries.get(name);
if (listOfLists==null) return NO_ENTRIES;
if (time >= listOfLists.size()) return NO_ENTRIES;
List<DebugEntry> result = listOfLists.get(time);
if (result==null) return NO_ENTRIES;
return Collections.unmodifiableCollection(result);
}
private void addEntry(String name, DebugEntry next) {
List<List<DebugEntry>> listOfLists = nameToEntries.get(name);
if (listOfLists==null) {
listOfLists = new ArrayList<List<DebugEntry>>();
nameToEntries.put(name,listOfLists);
}
int time = next.getTimestep();
while (time >= listOfLists.size()) listOfLists.add(new ArrayList<DebugEntry>());
List<DebugEntry> thisList = listOfLists.get(time);
thisList.add(next);
}
}
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment