View Javadoc

1   /* 
2    * DEFCON API Java Bot
3    * This is the java extension to the DEFCON AI API.
4    * Please see the project homepage for more general information about the api:
5    * http://www.doc.ic.ac.uk/~rb1006/projects:api and http://www.introversion.co.uk/defcon/bots/
6    * 
7    * By default, a JDK compiler compliance level of java version 1.6 is expected by the API. 
8    * By giving the command line option javaversion="1.4", java 1.4 compliance can be activated.
9    * 
10   * The functions called by the api are initialise, update, and addEvent.
11   * 
12   * Feel free to modify and change the code as you see fit.
13   * 
14   * Author: Robin Baumgarten (see website above for contact details)
15   * February 2009
16   * 
17   */
18  
19  package javabot;
20  
21  import java.util.LinkedList;
22  import java.util.List;
23  
24  
25  /**
26   * Based on DefCon JavaBot v0.9
27   * 
28   * @author Robin Baumgarten
29   * @author Jimmy
30   * @author Radek 'Black_Hand' Pibil
31   */
32  public class JBot {
33  	// the following declarations are functions implemented in the C++ API of DEFCON,
34  	// they have been exposed by the Java Native Interface. For more information on what
35  	// each function does, please refer to the function list at the project homepage:
36  	// http://www.doc.ic.ac.uk/~rb1006/projects:api:documentation
37  	
38  	/**
39  	 * Current Defcon Stage, game starts with 5
40  	 * @return int Defcon stage
41  	 */
42      public static native int GetDefcon();
43      /**
44       * Current Game Time, measured in seconds. Each tick, the game progresses by 0.1 sec * GameSpeed
45       * @return game time
46       */
47      public static native float GetGameTime();
48      /**
49       * Amount of update cycles (ticks) passed since game start
50       * @return number of game ticks
51       */
52      public static native int GetGameTick();
53      /**
54       * Current speed-up factor of the game over the real time passed. Usually has values
55       * from 0 (paused), 1 (real time), 5, 10, 20, see enum GAMESPEED (GameSpeed class)
56       * @return
57       */
58      public static native int GetGameSpeed();
59      /**
60       * Time remaining in game, if victory timer was started. Test this with 
61       * IsVictoryTimerStarted
62       * @return
63       */
64      public static native float GetVictoryTimer();
65      /**
66       * True iff the victory-timer has been started
67       * @return
68       */
69      public static native boolean IsVictoryTimerActive();
70      /**
71       * Value of certain option
72       * @param name
73       * @return
74       */
75      public static native int GetOptionValue( String name );
76      /**
77       * Array of City Ids. The amount of cities does not change during a game.
78       * @return
79       */
80      public static native int[] GetCityIds();
81      /**
82       * Population (in millions)
83       * @param cityId
84       * @return
85       */
86      public static native int GetCityPopulation( int cityId );
87      /**
88       * Remaining population of given team
89       * @param teamId
90       * @return
91       */
92      public static native int GetRemainingPopulation( int teamId );
93      /**
94       * True if the given coordinates belong to the given Team. If seaArea is set to true, then
95       * Coordinates must be on sea area, otherwise land. If teamId = -1, then function 
96       * returns if coordinates are land or sea terrain respectively. Note that there can be 
97       * coordinates which are neither land nor sea
98       * @param teamId
99       * @param longitude
100      * @param latitude
101      * @param seaArea
102      * @return
103      */
104     public static native boolean IsValidTerritory( int teamId, float longitude, float latitude, boolean seaArea );
105     /**
106      * True if given coordinates are on the border. Compare "data/earth/coastlines.bmp".
107      * @param longitude
108      * @param latitude
109      * @return
110      */
111     public static native boolean IsBorder( float longitude, float latitude );
112     /**
113      * Territory Id of territory at given coordinates.
114      * @param longitude
115      * @param latitude
116      * @return
117      */
118     public static native int GetTerritoryId( float longitude, float latitude );
119     /**
120      * Own team id.
121      * @return
122      */
123     public static native int GetOwnTeamId();
124     /**
125      * List of Team Ids in the game.
126      * @return
127      */
128     public static native int[] GetTeamIds();
129     /**
130     * Number of territories for given team, usually 1.
131     */        
132     public static native int GetTeamTerritoriesCount( int teamId );
133     /**
134      * 
135      * Territory Ids of territories that the given team owns. The enum TERRITORY_* relates 
136      * the ids to starting positions
137      * @param teamId
138      * @return territories belonging to the team
139      */
140     public static native int[] GetTeamTerritories( int teamId );
141     /**
142      * Id of alliance. Each team belongs to exactly one alliance.
143      * @param teamId
144      * @return
145      */
146     public static native int GetAllianceId( int teamId );
147     /**
148      * Currently requested game speed of given team.
149      * @param teamId
150      * @return
151      */
152     public static native int GetDesiredGameSpeed( int teamId );
153     /**
154      * Sum of enemy kills of the given team (for scoring).
155      * @param teamId
156      * @return
157      */
158     public static native int GetEnemyKills( int teamId );
159     /**
160      * Sum of friendly deaths (deaths in allied populations) of the given team.
161      * @param teamId
162      * @return
163      */
164     public static native int GetFriendlyDeaths( int teamId );
165     /**
166      * Sum of collateral damage deaths (deaths in own population) of the given team.
167      * @param teamId
168      * @return
169      */
170     public static native int GetCollateralDamage( int teamId );
171     /**
172      * Name of the given team.
173      * @param teamId
174      * @return
175      */
176     public static native String GetTeamName( int teamId );
177     /**
178      * True iff the first team is sharing its radar with the second team.
179      * @param teamId1
180      * @param teamId2
181      * @return
182      */
183     public static native boolean IsSharingRadar( int teamId1, int teamId2 );
184     /**
185      * True iff the first team is in cease fire mode with the second team.
186      * @param teamId1
187      * @param teamId2
188      * @return
189      */
190     public static native boolean IsCeaseFire( int teamId1, int teamId2 );
191     /**
192      * Sends requests to the alliance members to join alliance. Replies are handled by the
193      * event system.
194      * @param allianceId
195      */
196     public static native void RequestAlliance( int allianceId );
197     /**
198      * Send request to cease fire with given team.
199      * @param teamId
200      */
201     public static native void RequestCeaseFire( int teamId );
202     /**
203      * Send request to share radar with given team.
204      * @param teamId
205      */
206     public static native void RequestShareRadar( int teamId );
207     /**
208      * Send request to change game speed to given speed. Must be one of the values 
209      * specified in GAMESPEED.
210      * @param requestedSpeedIdentifier
211      */
212     public static native void RequestGameSpeed( int requestedSpeedIdentifier );
213     /**
214      * All visible unit ids.
215      * @return
216      */
217     public static native int[] GetAllUnits();
218     /**
219      * All own unit ids.
220      * @return
221      */
222     public static native int[] GetOwnUnits();
223     /**
224      * All visible units of a given team.
225      * @param teamId
226      * @return
227      */
228     public static native int[] GetTeamUnits( int teamId );
229     /**
230      * Data about all visible units, contained in the struct unitData (see enums). This 
231      * function is for convenience only, as all data can be gathered through other functions, 
232      * too.
233      * @return
234      */
235     private static native float[] _GetAllUnitData();
236     /**
237      * Type of unit, event or team, specified in enum TYPE_*, EVENT_* or TEAM_TYPE_*.
238      * @param id
239      * @return
240      */
241     public static native int GetType( int id );
242     /**
243      * Team Id of given unit.
244      * @param id
245      * @return
246      */
247     public static native int GetTeamId( int id );
248     /**
249      * Own fleet ids.
250      * @return
251      */
252     public static native int[] GetOwnFleets();
253     /**
254      * Fleet ids of given team. Only fleets ids with visible members are returned.
255      * @param teamId
256      * @return
257      */
258     public static native int[] GetFleets( int teamId );
259     /**
260      * Ids of ships in given fleet.
261      * @param _fleetId
262      * @return
263      */
264     public static native int[] GetFleetMembers( int _fleetId );
265     /**
266      * Id of fleet of given unit.
267      * @param unitId
268      * @return
269      */
270     public static native int GetFleetId( int unitId );
271     
272     ///**
273     // * Ids of all visible shots (projectiles like gunfire and depth charges).
274     // * @return
275     // */    
276     //public static native int[] GetShots();
277     ///**
278     // * UnitId of originator of given shot, if visible at shooting time
279     // * @param shotId
280     // * @return
281     // */
282     //public static native int GetShotOrigin(int shotId);
283     ///**
284     // * Location where shot has been first seen.
285     // * @param shotId
286     // * @return
287     // */
288     //public static native int[] GetShotOriginLocation(int shotId);
289     /**
290      * State of unit, specified in enum STATE_*.
291      * @param unitId
292      * @return
293     */
294     public static native int GetCurrentState( int unitId );
295     ///**
296     // * Number of activations of current state in given unit, i.e., number of nukes in a sub or 
297     // * silo, number of planes available in a carrier or airbase
298     // */
299     // TODO: MISSING!
300     // public static native int GetCurrentStateCount( int unitId );
301     /**
302      * Number of activations of given state in given unit
303      * @param unitId
304      * @param stateId
305      * @return
306      */
307     public static native int GetStateCount( int unitId, int stateId );
308     /**
309      * Time until current state is active.
310      * @param unitId
311      * @return
312      */
313     public static native float GetStateTimer( int unitId );
314     /**
315      * Array of unitIds of currently queued actions, for example nukes in a silo or planes on a 
316      * carrier
317      * @param unitId
318      * @return
319      */
320     public static native int[] GetActionQueue( int unitId ); 
321     /**
322      * Current target id. -1 if no target is set or target is location. If track of target is lost, the 
323      * last known location is used instead
324      * @param unitId
325      * @return
326      */
327     public static native int GetCurrentTargetId( int unitId );
328     /**
329      * Current target location. (0,0) if no target location is set.
330      * @param unitId
331      * @return
332      */
333     public static native float[] GetMovementTargetLocation( int unitId );
334     /**
335      * Number of available nukes.
336      * @param _unitId
337      * @return
338      */
339     public static native int GetNukeSupply( int _unitId );
340     /**
341      * Target of the nuke carried by given bomber.
342      * @param _unitId
343      * @return
344      */
345     public static native float[] GetBomberNukeTarget( int _unitId );
346     /**
347      * True iff given unit is automatically retaliating an earlier attack.
348      * @param _unitId
349      * @return
350      */
351     public static native boolean IsRetaliating( int _unitId );
352     /**
353      * True iff given unit is visible to given team. In full information mode, visibility 
354      * information about other teams is available. In limited information mode, only visible 
355      * units are accessible.
356      * @param _unitId
357      * @param _byTeamId
358      * @return
359      */
360     public static native boolean IsVisible( int _unitId, int _byTeamId );
361     /**
362      * Set state of given unit. See STATE_*
363      * @param unitId
364      * @param stateId
365      * @return
366      */
367     public static native void SetState( int unitId, int stateId );
368     /**
369      * TODO: do the movement? same as SetTargetLocation?
370      * @param unitId
371      * @param longitude
372      * @param latitude
373      */
374     public static native void SetMovementTarget( int unitId, float longitude, float latitude );
375     /**
376      * Set target location for given unit. If target id is also given, the id overrides the 
377      * location.
378      * TODO: different name in documentation SetTargetLocation(unitId, longitude, latitude) ?
379      * TODO: also should be used for SetTargetId() (missing...)
380      * @param _unitId
381      * @param _targetUnitId
382      * @param _longitude
383      * @param _latitude
384      */
385     public static native void SetActionTarget( int _unitId, int _targetUnitId, float _longitude, float _latitude );
386     /**
387      * TODO: what's this?
388      * @param _unitId
389      * @param _targetUnitId
390      */
391     public static native void SetLandingTarget( int _unitId, int _targetUnitId );
392     /**
393      * Longitude of given unit, city, or event.
394      * @param id
395      * @return
396      */
397     public static native float GetLongitude( int id );
398     /**
399      * Latitude of given unit, city, or event.
400      * @param id
401      * @return
402      */
403     public static native float GetLatitude( int id );
404     /**
405      * Movement direction of given unit, in longitude and latitude parts. The vector has the 
406      * length of the unit speed (see also SPEED_*).
407      * @param unitId
408      * @return
409      */
410     public static native float[] GetVelocity( int unitId );
411     /**
412      * Remaining range of unit. If unlimited, -1 is returned.
413      * @param unitId
414      * @return
415      */
416     public static native float GetRange( int unitId );
417     /**
418      * Amount of remaining units of given type that can be placed.
419      * @param typeId
420      * @return
421      */
422     public static native int GetRemainingUnits( int typeId );
423     /**
424      * True iff given location is valid for placement of given type. For fleets use 
425   	 * getFleetMemberOffset to get offset from fleet center.
426      * @param longitude
427      * @param latitude
428      * @param typeId
429      * @return
430      */
431     public static native boolean IsValidPlacementLocation( float longitude, float latitude, int typeId );
432     /**
433      * Offset of ship number memberId from center of fleet, given fleet has memberCount 
434      * ships
435      * @param memberCount
436      * @param memberId
437      * @return
438      */
439     public static native float[] GetFleetMemberOffset( int memberCount, int memberId );
440     /**
441      * Tries to place a given structure to the given coordinates. Use IsValidStructureLocation 
442      * to test if valid.
443      * @param typeId
444      * @param longitude
445      * @param latitude
446      */
447     public static native void PlaceStructure( int typeId, float longitude, float latitude );
448     /**
449      * Tries to place a given amount of battlecruisers, carriers and subs into a fleet at the 
450      * given location. Use IsValidFleedLocation to test.
451      * @param longitude
452      * @param latitude
453      * @param typeShip1
454      */
455     public static native void PlaceFleet( float longitude, float latitude, int[] shipTypes);
456     /**
457      * Credits available for placement (if in variable unit mode).
458      * @return
459      */
460     public static native int GetUnitCredits();
461     /**
462      * Value of given unit type (if in variable unit mode).
463      * @param _typeId
464      * @return
465      */
466     public static native int GetUnitValue( int _typeId );
467     /**
468      * TODO: documentation?
469      * @param _voteId
470      * @param _vote
471      */
472     public static native void SendVote( int _voteId, int _vote );
473     /**
474      * Sends a chat message.
475      * TODO: documentation for second param?
476      * @param chatMessage
477      * @param receiverId
478      */
479     public static native void SendChatMessage( String chatMessage, int receiverId );
480     /**
481      * Distance in game between given coordinates.
482      * @param longitude1
483      * @param latitude1
484      * @param longitude2
485      * @param latitude2
486      * @return
487      */
488     public static native float GetDistance( float longitude1, float latitude1, float longitude2, float latitude2 );
489     /**
490      * Distance in game between given coordinates on sea (performs pathfinding).
491      * @param longitude1
492      * @param latitude1
493      * @param longitude2
494      * @param latitude2
495      * @return
496      */
497     public static native float GetSailDistance( float longitude1, float latitude1, float longitude2, float latitude2 );
498     /**
499      * Prints a line in the debug console in the specified color
500      * @param entry
501      */
502     public static native void DebugLog(String entry);
503     /**
504      * Prints a line in the debug console in the specified color.
505      * @param entry
506      * @param objectId
507      */
508     public static native void DebugLog(String entry, int objectId);
509     /**
510      * Prints a line in the debug console.
511      * TODO: param tags? objectId?
512      * @param entry
513      * @param objectId
514      * @param tags
515      */
516     public static native void DebugLog(String entry, int objectId, String tags);
517     /**
518      * Prints a line in the debug console in the specified color.
519      * @param entry
520      * @param objectId
521      * @param tags
522      * @param colorR
523      * @param colorG
524      * @param colorB
525      */
526     public static native void DebugLog(String entry, int objectId, String tags, int colorR, int colorG, int colorB);
527     /**
528      * Prints a line in the debug console in the specified color.
529      * @param entry
530      * @param objectId
531      * @param tags
532      * @param colorR
533      * @param colorG
534      * @param colorB
535      * @param colorAlpha
536      */
537     public static native void DebugLog(String entry, int objectId, String tags, int colorR, int colorG, int colorB, int colorAlpha);
538     /**
539      * True if the game is currently replayed (Timeline has been clicked).
540      * TODO: e.g. game has been paused?
541      * @return
542      */
543     public static native boolean DebugIsReplayingGame();
544     /**
545      * Draws a line on the whiteboard.
546      * @param longitude1
547      * @param latitude1
548      * @param longitude2
549      * @param latitude2
550      */
551     public static native void WhiteboardDraw(float longitude1, float latitude1, float longitude2, float latitude2);
552     /**
553      * Clears the whiteboard.
554      */
555     public static native void WhiteboardClear();
556     /**
557      * CommandIds of all commands that have been executed in previous cycle.
558      * @return
559      */
560     public static native int[] GetSuccessfulCommands();
561     
562     ///**
563     // * Moves the camera to a given location
564     // */
565     // TODO: MISSING!
566     // public static native void DebugMoveCamera( float longitude, float latitude, float zoom );
567     
568     /**
569      * Outputs a string to console
570      * @param logLine
571      */
572     public static native void WriteToConsole(String logLine);
573     
574     private static String[][] commandLineOptions;
575 
576     public static class UnitData
577     {
578     	public int m_objectId;
579     	public int m_type;
580     	public int m_teamId;
581     	public int m_currentState;
582     	public boolean m_visible;
583     	public float m_longitude;
584     	public float m_latitude;
585 
586 		@Override
587 		public String toString() {
588 			StringBuilder builder = new StringBuilder();
589 
590 			builder.append("objectId: ");
591 			builder.append(m_objectId);
592 			builder.append("; type: ");
593 			builder.append(m_type);
594 			builder.append("; teamId: ");
595 			builder.append(m_teamId);
596 			builder.append("; currentState: ");
597 			builder.append(m_currentState);
598 			builder.append("; visible: ");
599 			builder.append(m_visible);
600 			builder.append("; longitude: ");
601 			builder.append(m_longitude);
602 			builder.append("; latitude: ");
603 			builder.append(m_latitude);
604 
605 			return builder.toString();
606 		}
607     }
608     
609 	public static class FleetData {
610 		public int m_fleetId;
611 		public int m_teamId;
612 		public boolean m_visible;
613 		public float m_longitude;
614 		public float m_latitude;
615 		public int[] m_fleetMembers;
616 
617 		@Override
618 		public String toString() {
619 			StringBuilder builder = new StringBuilder();
620 
621 			builder.append("objectId: ");
622 			builder.append(m_fleetId);
623 			builder.append("; teamId: ");
624 			builder.append(m_teamId);
625 			builder.append("; visible: ");
626 			builder.append(m_visible);
627 			builder.append("; longitude: ");
628 			builder.append(m_longitude);
629 			builder.append("; latitude: ");
630 			builder.append(m_latitude);
631 			builder.append("; fleetMembers: ");
632 			builder.append(m_fleetMembers);
633 
634 			return builder.toString();
635 		}
636 
637 		public FleetData(int m_fleetId, int m_teamId, boolean m_visible,
638 				float m_longitude, float m_latitude, int[] m_fleetMembers) {
639 			this.m_fleetId = m_fleetId;
640 			this.m_teamId = m_teamId;
641 			this.m_visible = m_visible;
642 			this.m_longitude = m_longitude;
643 			this.m_latitude = m_latitude;
644 			this.m_fleetMembers = m_fleetMembers;
645 		}
646 	}
647 
648     public static class EventData
649     {
650     	public int m_eventType;
651     	public int m_causeObjectId;
652     	public int m_targetObjectId;
653 		public int m_unitType;
654 		public float m_longitude;
655 		public float m_latitude;
656 
657 		@Override
658 		public String toString() {
659 			StringBuilder builder = new StringBuilder();
660 
661 			builder.append("eventType: ");
662 			builder.append(m_eventType);
663 			builder.append("; causeObjectId: ");
664 			builder.append(m_causeObjectId);
665 			builder.append("; targetObjectId: ");
666 			builder.append(m_targetObjectId);
667 			builder.append("; unitType: ");
668 			builder.append(m_unitType);
669 			builder.append("; longitude: ");
670 			builder.append(m_longitude);
671 			builder.append("; latitude: ");
672 			builder.append(m_latitude);
673 
674 			return builder.toString();
675 		}
676     }
677     
678     public static final int STATE_AIRBASEFIGHTERLAUNCH = 0;
679     public static final int STATE_AIRBASEBOMBERLAUNCH = 1;
680 
681     public static final int STATE_BATTLESHIPATTACK = 0;
682 
683     public static final int STATE_BOMBERATTACK = 0;    
684     public static final int STATE_BOMBERNUKE = 1;      
685     public static final int STATE_BOMBERINQUEUE = 2;   
686 
687     public static final int STATE_CARRIERFIGHTERLAUNCH = 0;
688     public static final int STATE_CARRIERBOMBERLAUNCH = 1;
689     public static final int STATE_CARRIERANTISUB = 2;  
690 
691     public static final int STATE_FIGHTERATTACK = 0;   
692     public static final int STATE_FIGHTERINQUEUE = 2;    //2 instead of 1 makes handling easier when looking for STATE_s of items in queues
693 
694     public static final int STATE_NUKEONTARGET = 0;    
695     public static final int STATE_NUKEDISARM = 1;      
696 
697     public static final int STATE_RADARACTIVE = 0;     
698 
699     public static final int STATE_SILONUKE = 0;        
700     public static final int STATE_SILOAIRDEFENSE = 1;  
701 
702     public static final int STATE_SUBPASSIVESONAR = 0; 
703     public static final int STATE_SUBACTIVESONAR = 1;  
704     public static final int STATE_SUBNUKE = 2;         
705 
706     public static final int CHATCHANNEL_PUBLIC      = 100;
707     public static final int CHATCHANNEL_ALLIANCE    = 101;
708     public static final int CHATCHANNEL_SPECTATORS  = 102;
709 
710     // These were enums in C++, but to keep the JNI interface clean have been
711     // converted to static ints here. Thus the somewhat inconsistent naming scheme 
712     // to the above constants. Feel free to use enums instead, with an adequate
713     // conversion of the return values from the API functions.    
714     public static final int TerritoryNorthAmerica = 0;
715     public static final int TerritorySouthAmerica = 1;
716     public static final int TerritoryEurope = 2;
717     public static final int TerritoryRussia = 3;
718     public static final int TerritorySouthAsia = 4;
719     public static final int TerritoryAfrica = 5;
720     public static final int NumTerritories = 6;
721     
722     public static final int EventPingSub            = 0;
723     public static final int EventPingCarrier        = 1;
724     public static final int EventNukeLaunchSilo     = 2;
725     public static final int EventNukeLaunchSub      = 3;
726     public static final int EventHit                = 4;
727     public static final int EventDestroyed          = 5;
728     public static final int EventPingDetection      = 6;
729     public static final int EventCeasedFire         = 7;
730     public static final int EventUnceasedFire       = 8;
731     public static final int EventSharedRadar        = 9;
732     public static final int EventUnsharedRadar      = 10;
733     public static final int EventNewVote            = 11;
734     public static final int EventTeamVoted          = 12;
735     public static final int EventTeamRetractedVote  = 13;
736     public static final int EventVoteFinishedYes    = 14;
737     public static final int EventVoteFinishedNo     = 15;
738     
739     public static final int TypeInvalid      = 0;
740     public static final int TypeCity         = 1;
741     public static final int TypeSilo         = 2;
742     public static final int TypeRadarStation = 3;
743     public static final int TypeNuke         = 4;
744     public static final int TypeExplosion    = 5;
745     public static final int TypeSub          = 6;
746     public static final int TypeBattleShip   = 7;
747     public static final int TypeAirBase      = 8;
748     public static final int TypeFighter      = 9;
749     public static final int TypeBomber       = 10;
750     public static final int TypeCarrier      = 11;
751     public static final int TypeTornado      = 12;
752     public static final int TypeSaucer       = 13;
753     public static final int TypeFleet        = 14;
754     public static final int TypeGunshot      = 15;
755     public static final int TypeQueueItem    = 16;
756     public static final int NumObjectTypes   = 17;
757     
758     public static final int VoteTypeInvalid      = 0;
759     public static final int VoteTypeJoinAlliance = 1;
760     public static final int VoteTypeKickPlayer   = 2;
761     public static final int VoteTypeLeaveAlliance = 3;
762     
763     public static final int VoteUnknown = 0;
764     public static final int VoteYes     = 1;
765     public static final int VoteNo      = 2;
766     public static final int VoteAbstain = 3;
767  
768     /**
769      * Data about all visible units, contained in the struct unitData (see enums). This 
770      * function is for convenience only, as all data can be gathered through other functions, 
771      * too.
772      * <p><p>
773      * Parse the unit data into a proper object array.
774      * @return
775      */
776     public static List<UnitData> GetAllUnitData()
777     {
778     	float[] data = _GetAllUnitData();
779     	LinkedList<UnitData> javaData = new LinkedList<UnitData>();
780     	int counter = 0;
781     	int limit = (int)Math.floor(data.length / 7);
782     	for (int i = 0; i < limit; i++)
783     	{
784     		UnitData unit_data = new UnitData();
785     		unit_data.m_objectId = (int) data[counter++];
786     		unit_data.m_type = (int) data[counter++];
787     		unit_data.m_teamId = (int) data[counter++];
788     		unit_data.m_currentState = (int) data[counter++];
789     		unit_data.m_visible = Math.round( data[counter++] ) != 0;
790     		unit_data.m_longitude = data[counter++];
791     		unit_data.m_latitude = data[counter++];
792     		
793 
794     		javaData.add(unit_data);
795 		}
796 
797 
798 		return javaData;
799 	}
800 
801 	/**
802 	 * Data about all visible fleets, contained in the struct fleetData (see
803 	 * enums). This function is for convenience only, as all data can be
804 	 * gathered through other functions, too.
805 	 * <p>
806 	 * <p>
807 	 * Parse the unit data into a proper object array.
808 	 * 
809 	 * @return
810 	 */
811 	public static List<FleetData> GetAllFleetData() {
812     	
813     	LinkedList<FleetData> javaData = new LinkedList<FleetData>();
814     	
815 		for (int teamId : GetTeamIds()) {
816 			int[] fleets = GetFleets(teamId);
817 			
818 			for (int fleetId : fleets) {
819 				
820 				int[] fleetMembers = GetFleetMembers(fleetId);
821 				float[] fleetOffset = GetFleetMemberOffset(fleetMembers.length, 0);
822 				float fleetLongitude = GetLongitude(fleetMembers[0])
823 						- fleetOffset[0];
824 				float fleetLatitude = GetLatitude(fleetMembers[0])
825 						- fleetOffset[1];
826 
827 				FleetData fleet_data = new FleetData(fleetId, teamId, true,
828 						fleetLongitude, fleetLatitude,
829 						fleetMembers);
830 				
831 				javaData.add(fleet_data);
832 			}
833     	}
834     	
835 		return javaData;
836     }
837     
838     // update is called every tick of the game
839     public static boolean update()
840     {
841     	try {
842     		return PogamutJBotSupport.update();
843     	} catch (Exception e) {
844     		PogamutJBotSupport.logInitException(e);
845     		return false;
846     	}
847     }
848         
849     // this is called when the dll is initialised, usually in the host/join dialog of the game
850     public static boolean initialise(String[][] _commandLineOptions)
851     {    
852     	//saveCommandLineOptions(_commandLineOptions);
853     	commandLineOptions = _commandLineOptions;
854     	Boolean returnvalue = false;
855     	try {
856     		returnvalue = PogamutJBotSupport.initialise(commandLineOptions);
857     	} catch (Exception e) {
858     		PogamutJBotSupport.writeToConsole("FAIL!!!");
859     		PogamutJBotSupport.writeToConsole(e.getMessage());
860     		PogamutJBotSupport.logInitException(e);
861     		return false;
862     	}
863     	WriteToConsole("Initialise finished");
864     	return returnvalue;
865     }
866     /*
867     private static void saveCommandLineOptions(String[][] commandLineOptions)
868     {
869     	JBot.commandLineOptions = new String[commandLineOptions.length][2];
870     	for (int i = 0; i < commandLineOptions.length; ++i) {
871     		String[] parameter = new String[2];
872     		parameter[0] = commandLineOptions[i][0];
873     		parameter[1] = commandLineOptions[i][1];
874     		JBot.commandLineOptions[i] = parameter;
875     	}
876     }
877     */
878     // Whenever an event occurs, this function is called by the dll. This should be used to collect these events only,
879     // with the main processing taking place in the update() function.
880     public static void addEvent(int _eventType, int _causeObjectId, int _targetObjectId,
881     		int _unitType, float _longitude, float _latitude)
882     {
883 		try {
884     		EventData data = new EventData();
885     		data.m_eventType = _eventType;
886     		data.m_causeObjectId = _causeObjectId;
887     		data.m_targetObjectId = _targetObjectId;
888 			// unitType is screwed up
889     		data.m_unitType = _unitType;
890     		data.m_longitude = _longitude;
891     		data.m_latitude = _latitude;
892 
893     		PogamutJBotSupport.addEvent(data);
894     	} catch (Exception e) {
895     		PogamutJBotSupport.logInitException(e);
896     		return;
897     	}
898     }
899     
900 }