This is the source code to version 1.0 of ModdedBot. It is included within the .jar, which you can obtain here: http://www.robocoderepository.com/BotDetail.jsp?id=1831 |
This is the source code to version 1.1 of ModdedBot. It is included within the .jar, which you can obtain here: http://www.robocoderepository.com/BotDetail.jsp?id=1831 |
* Last edited on November 7, 2003 |
* version 1.1 * Last edited on December 5, 2003 |
import java.util.Vector; import java.util.Iterator; |
import java.util.*; import robocode.exception.EventInterruptedException?; |
//These? are private variables that hold needed info |
//These? are pr ivate variables that hold needed info |
private Vector events; //Holds? all robot events |
private Vector events; //Holds? all robot events |
|
|
* onBla(BlaEvent?) methods. |
* onXXX(XXXEvent) methods. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//create new RobotDeathEvent? Event newevent = new RobotDeathEvent?(hit.getName()); //DON'T FORGET to set the priority and time of the event! newevent.setPriority(getEventPriority?("RobotDeathEvent?")); newevent.setTime(getTime()); |
//create new RobotDeathEvent? and add to fakes eventsfake.add(new RobotDeathEvent?(hit.getName())); |
//add RobotDeathEvent? to eventsfake (NOT events) eventsfake.add(newevent); |
|
|
|
|
Collections.sort(events); |
/* These variables handle prioritization. */ private boolean isHandlingEvents? = false; private int currentEventPriority? = Integer.MIN_VALUE; private boolean[] interruptible = new boolean[101]; /* This method handles setting interruptibility. Since we hold all blocking * calls from the robot, we have to handle interruptibility manually. */ public void setInterruptible(boolean interruptible) { init(); if (!isHandlingEvents?) return; this.interruptible[currentEventPriority?] = interruptible; } |
/* This event parses the events and calls the proper event handlers.*/ |
/* This event parses the events and calls the proper event handlers. * * This method is configured to automatically handle interruptibility the * same way Robocode does. An error is thrown through the robot's event * handler and caught by ModdedBot to interrupt an event. */ |
//set this to true. we shouldn't have to worry about setting it false // again because from then on we always handle events. isHandlingEvents? = true; |
for (int i = 0; i < events.size(); i++) { |
while (events.size() > 0) { |
Event event = (Event)events.firstElement(); //since the list is sorted, all events remaining are lower priority // than the current one, so we cannot interrupt it and so we can // stop dumping events. if (event.getPriority() < currentEventPriority?) break; //we need to interrupt the current event if (event.getPriority() == currentEventPriority? && interruptible[currentEventPriority?]) { interruptible[currentEventPriority?] = false; throw new EventInterruptedException?(event.getPriority()); } //we haven't interrupted the current event; since the list is // sorted, all events after this one will have the same or lower // priority, so we can stop dumping events. if (event.getPriority() == currentEventPriority?) break; //we can now remove the event from the vector. we remove it after // interrupting so that we don't remove the event that we // want to interrupt with! events.remove(0); |
//If? you have created any of your own custom event classes, add them // here BEFORE the rest of the events get parsed, and change the // next line to else if so that any events you have extended won't // fire twice. //If? you haven't created any custom event classes, you don't need // to modify this method. |
int oldEventPriority? = currentEventPriority?; currentEventPriority? = event.getPriority(); try { //If? you have created any of your own custom event classes, add them // here BEFORE the rest of the events get parsed, and change the // next line to else if so that any events you have extended won't // fire twice. //If? you haven't created any custom event classes, you don't need // to modify this method. if (event instanceof ScannedRobotEvent) onScannedRobot((ScannedRobotEvent)event); else if (event instanceof RobotDeathEvent?) onRobotDeath?((RobotDeathEvent?)event); else if (event instanceof HitRobotEvent?) onHitRobot?((HitRobotEvent?)event); else if (event instanceof HitWallEvent?) onHitWall?((HitWallEvent?)event); else if (event instanceof HitByBulletEvent?) onHitByBullet?((HitByBulletEvent?)event); else if (event instanceof BulletHitEvent?) onBulletHit?((BulletHitEvent?)event); else if (event instanceof BulletMissedEvent?) onBulletMissed?((BulletMissedEvent?)event); else if (event instanceof BulletHitBulletEvent?) onBulletHitBullet?((BulletHitBulletEvent?)event); else if (event instanceof CustomEvent) onCustomEvent((CustomEvent)event); else if (event instanceof SkippedTurnEvent?) onSkippedTurn((SkippedTurnEvent?)event); else if (event instanceof WinEvent?) onWin((WinEvent?)event); else if (event instanceof DeathEvent?) onDeath((DeathEvent?)event); else printError("Unknown Event!! This event is unhandled: " + event.getClass().getName()); } catch (EventInterruptedException? e) { //we dropped down the stack, and we resume event dumping with // the new events vector using the old dump method. } |
currentEventPriority? = oldEventPriority?; |
if (events.get(i) instanceof ScannedRobotEvent) onScannedRobot((ScannedRobotEvent)events.get(i)); else if (events.get(i) instanceof RobotDeathEvent?) onRobotDeath?((RobotDeathEvent?)events.get(i)); else if (events.get(i) instanceof HitRobotEvent?) onHitRobot?((HitRobotEvent?)events.get(i)); else if (events.get(i) instanceof HitWallEvent?) onHitWall?((HitWallEvent?)events.get(i)); else if (events.get(i) instanceof HitByBulletEvent?) onHitByBullet?((HitByBulletEvent?)events.get(i)); else if (events.get(i) instanceof BulletHitEvent?) onBulletHit?((BulletHitEvent?)events.get(i)); else if (events.get(i) instanceof BulletMissedEvent?) onBulletMissed?((BulletMissedEvent?)events.get(i)); else if (events.get(i) instanceof BulletHitBulletEvent?) onBulletHitBullet?((BulletHitBulletEvent?)events.get(i)); else if (events.get(i) instanceof CustomEvent) onCustomEvent((CustomEvent)events.get(i)); else if (events.get(i) instanceof SkippedTurnEvent?) onSkippedTurn((SkippedTurnEvent?)events.get(i)); else if (events.get(i) instanceof WinEvent?) onWin((WinEvent?)events.get(i)); else if (events.get(i) instanceof DeathEvent?) onDeath((DeathEvent?)events.get(i)); else printError("Unknown Event!! This event is unhandled: " + events.get(i).getClass().getName()); |
|
|
|
//This? is just a debugger method; it will call whenever an error occurs // within the mod. You can call this or remove this or do whatever you want // with it; debug your mod however you like. |
/* This is just a debugger method; it will call whenever an error occurs * within the mod. You can call this or remove this or do whatever you want * with it; debug your mod however you like. */ |
|
</pre> |
</pre> |