1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19 package javabot;
20
21 import java.util.LinkedList;
22 import java.util.List;
23
24
25
26
27
28
29
30
31
32 public class JBot {
33
34
35
36
37
38
39
40
41
42 public static native int GetDefcon();
43
44
45
46
47 public static native float GetGameTime();
48
49
50
51
52 public static native int GetGameTick();
53
54
55
56
57
58 public static native int GetGameSpeed();
59
60
61
62
63
64 public static native float GetVictoryTimer();
65
66
67
68
69 public static native boolean IsVictoryTimerActive();
70
71
72
73
74
75 public static native int GetOptionValue( String name );
76
77
78
79
80 public static native int[] GetCityIds();
81
82
83
84
85
86 public static native int GetCityPopulation( int cityId );
87
88
89
90
91
92 public static native int GetRemainingPopulation( int teamId );
93
94
95
96
97
98
99
100
101
102
103
104 public static native boolean IsValidTerritory( int teamId, float longitude, float latitude, boolean seaArea );
105
106
107
108
109
110
111 public static native boolean IsBorder( float longitude, float latitude );
112
113
114
115
116
117
118 public static native int GetTerritoryId( float longitude, float latitude );
119
120
121
122
123 public static native int GetOwnTeamId();
124
125
126
127
128 public static native int[] GetTeamIds();
129
130
131
132 public static native int GetTeamTerritoriesCount( int teamId );
133
134
135
136
137
138
139
140 public static native int[] GetTeamTerritories( int teamId );
141
142
143
144
145
146 public static native int GetAllianceId( int teamId );
147
148
149
150
151
152 public static native int GetDesiredGameSpeed( int teamId );
153
154
155
156
157
158 public static native int GetEnemyKills( int teamId );
159
160
161
162
163
164 public static native int GetFriendlyDeaths( int teamId );
165
166
167
168
169
170 public static native int GetCollateralDamage( int teamId );
171
172
173
174
175
176 public static native String GetTeamName( int teamId );
177
178
179
180
181
182
183 public static native boolean IsSharingRadar( int teamId1, int teamId2 );
184
185
186
187
188
189
190 public static native boolean IsCeaseFire( int teamId1, int teamId2 );
191
192
193
194
195
196 public static native void RequestAlliance( int allianceId );
197
198
199
200
201 public static native void RequestCeaseFire( int teamId );
202
203
204
205
206 public static native void RequestShareRadar( int teamId );
207
208
209
210
211
212 public static native void RequestGameSpeed( int requestedSpeedIdentifier );
213
214
215
216
217 public static native int[] GetAllUnits();
218
219
220
221
222 public static native int[] GetOwnUnits();
223
224
225
226
227
228 public static native int[] GetTeamUnits( int teamId );
229
230
231
232
233
234
235 private static native float[] _GetAllUnitData();
236
237
238
239
240
241 public static native int GetType( int id );
242
243
244
245
246
247 public static native int GetTeamId( int id );
248
249
250
251
252 public static native int[] GetOwnFleets();
253
254
255
256
257
258 public static native int[] GetFleets( int teamId );
259
260
261
262
263
264 public static native int[] GetFleetMembers( int _fleetId );
265
266
267
268
269
270 public static native int GetFleetId( int unitId );
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294 public static native int GetCurrentState( int unitId );
295
296
297
298
299
300
301
302
303
304
305
306
307 public static native int GetStateCount( int unitId, int stateId );
308
309
310
311
312
313 public static native float GetStateTimer( int unitId );
314
315
316
317
318
319
320 public static native int[] GetActionQueue( int unitId );
321
322
323
324
325
326
327 public static native int GetCurrentTargetId( int unitId );
328
329
330
331
332
333 public static native float[] GetMovementTargetLocation( int unitId );
334
335
336
337
338
339 public static native int GetNukeSupply( int _unitId );
340
341
342
343
344
345 public static native float[] GetBomberNukeTarget( int _unitId );
346
347
348
349
350
351 public static native boolean IsRetaliating( int _unitId );
352
353
354
355
356
357
358
359
360 public static native boolean IsVisible( int _unitId, int _byTeamId );
361
362
363
364
365
366
367 public static native void SetState( int unitId, int stateId );
368
369
370
371
372
373
374 public static native void SetMovementTarget( int unitId, float longitude, float latitude );
375
376
377
378
379
380
381
382
383
384
385 public static native void SetActionTarget( int _unitId, int _targetUnitId, float _longitude, float _latitude );
386
387
388
389
390
391 public static native void SetLandingTarget( int _unitId, int _targetUnitId );
392
393
394
395
396
397 public static native float GetLongitude( int id );
398
399
400
401
402
403 public static native float GetLatitude( int id );
404
405
406
407
408
409
410 public static native float[] GetVelocity( int unitId );
411
412
413
414
415
416 public static native float GetRange( int unitId );
417
418
419
420
421
422 public static native int GetRemainingUnits( int typeId );
423
424
425
426
427
428
429
430
431 public static native boolean IsValidPlacementLocation( float longitude, float latitude, int typeId );
432
433
434
435
436
437
438
439 public static native float[] GetFleetMemberOffset( int memberCount, int memberId );
440
441
442
443
444
445
446
447 public static native void PlaceStructure( int typeId, float longitude, float latitude );
448
449
450
451
452
453
454
455 public static native void PlaceFleet( float longitude, float latitude, int[] shipTypes);
456
457
458
459
460 public static native int GetUnitCredits();
461
462
463
464
465
466 public static native int GetUnitValue( int _typeId );
467
468
469
470
471
472 public static native void SendVote( int _voteId, int _vote );
473
474
475
476
477
478
479 public static native void SendChatMessage( String chatMessage, int receiverId );
480
481
482
483
484
485
486
487
488 public static native float GetDistance( float longitude1, float latitude1, float longitude2, float latitude2 );
489
490
491
492
493
494
495
496
497 public static native float GetSailDistance( float longitude1, float latitude1, float longitude2, float latitude2 );
498
499
500
501
502 public static native void DebugLog(String entry);
503
504
505
506
507
508 public static native void DebugLog(String entry, int objectId);
509
510
511
512
513
514
515
516 public static native void DebugLog(String entry, int objectId, String tags);
517
518
519
520
521
522
523
524
525
526 public static native void DebugLog(String entry, int objectId, String tags, int colorR, int colorG, int colorB);
527
528
529
530
531
532
533
534
535
536
537 public static native void DebugLog(String entry, int objectId, String tags, int colorR, int colorG, int colorB, int colorAlpha);
538
539
540
541
542
543 public static native boolean DebugIsReplayingGame();
544
545
546
547
548
549
550
551 public static native void WhiteboardDraw(float longitude1, float latitude1, float longitude2, float latitude2);
552
553
554
555 public static native void WhiteboardClear();
556
557
558
559
560 public static native int[] GetSuccessfulCommands();
561
562
563
564
565
566
567
568
569
570
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;
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
711
712
713
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
770
771
772
773
774
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
803
804
805
806
807
808
809
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
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
850 public static boolean initialise(String[][] _commandLineOptions)
851 {
852
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
868
869
870
871
872
873
874
875
876
877
878
879
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
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 }