-
Notifications
You must be signed in to change notification settings - Fork 285
Expand file tree
/
Copy pathGame.h
More file actions
1934 lines (1774 loc) · 81 KB
/
Copy pathGame.h
File metadata and controls
1934 lines (1774 loc) · 81 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#pragma once
#include <cstdarg>
#include <list>
#include <map>
#include <memory>
#include <set>
#include <sstream>
#include <string>
#include <BWAPI/Error.h>
#include <BWAPI/Filters.h>
#include <BWAPI/UnaryFilter.h>
#include <BWAPI/Input.h>
#include <BWAPI/CoordinateType.h>
#include <BWAPI/Position.h>
#include <BWAPI/IDs.h>
#include <BWAPI/Client/GameData.h>
#include <BWAPI/Client/UnitData.h>
#include <BWAPI/Client/PlayerData.h>
#include <BWAPI/Client/RegionData.h>
#include <BWAPI/Client/ForceData.h>
#include <BWAPI/Client/BulletData.h>
#include <BWAPI/Unit.h>
#include <BWAPI/Player.h>
#include <BWAPI/Region.h>
#include <BWAPI/Force.h>
#include <BWAPI/Bullet.h>
#include <BWAPI/Unitset.h>
#include <BWAPI/Forceset.h>
#include <BWAPI/Playerset.h>
#include <BWAPI/Bulletset.h>
#include <BWAPI/Regionset.h>
#include <BWAPI/Event.h>
#include <BWAPI/CommandOptimizer.h>
#include <BWAPI/UnitFinder.h>
#include <BWAPI/FPSCounter.h>
#include <BWAPI/APMCounter.h>
namespace BWAPI
{
// Forward Declarations
class Client;
class Color;
class GameType;
class TechType;
class UnitCommand;
class UpgradeType;
/// <summary>The abstract Game class is implemented by BWAPI and is the primary means of obtaining all
/// game state information from Starcraft Broodwar.</summary> Game state information includes all units,
/// resources, players, forces, bullets, terrain, fog of war, regions, etc.
///
/// @ingroup Interface
class Game {
public:
Game &operator =(Game const &other) = delete;
Game &operator =(Game &&other) = delete;
Game(Client& newClient);
UnitData const *getUnitData(UnitID unit) const
{
if (auto const it = units.find(unit); it != units.end())
return &it->getData();
else return nullptr;
}
UnitData const *getInitialData(UnitID unit) const
{
if (auto const it = initialUnits.find(unit); it != units.end())
return &it->getData();
else return nullptr;
}
PlayerData const *getPlayerData(PlayerID player) const
{
if (auto const it = players.find(player); it != players.end())
return &it->getData();
else return nullptr;
}
RegionData const *getRegionData(RegionID region) const
{
if (auto const it = regions.find(region); it != regions.end())
return &it->getData();
else return nullptr;
}
ForceData const *getForceData(ForceID force) const
{
if (auto const it = forces.find(force); it != forces.end())
return &it->getData();
else return nullptr;
}
BulletData const *getBulletData(BulletID bullet) const
{
if (auto const it = bullets.find(bullet); it != bullets.end())
return &it->getData();
else return nullptr;
}
/// <summary>Initializes the members of GameData.</summary> Prepares the Game object for
/// the start of a new game.
void initGameData();
/// <summary>Retrieves the set of all teams/forces.</summary> Forces are commonly seen in @UMS
/// game types and some others such as @TvB and the team versions of game types.
///
/// @returns Forceset containing all forces in the game.
const Forceset& getForces() const;
/// <summary>Retrieves the set of all players in the match.</summary> This includes the neutral
/// player, which owns all the resources and critters by default.
///
/// @returns Playerset containing all players in the game.
const Playerset& getPlayers() const;
/// <summary>Retrieves the set of all accessible units.</summary> If
/// Flag::CompleteMapInformation is enabled, then the set also includes units that are not
/// visible to the player.
///
/// @note Units that are inside refineries are not included in this set.
///
/// @returns Unitset containing all known units in the game.
const Unitset& getAllUnits() const;
/// <summary>Retrieves the set of all accessible @minerals in the game.</summary>
///
/// @returns Unitset containing @minerals
const Unitset& getMinerals() const;
/// <summary>Retrieves the set of all accessible @geysers in the game.</summary>
///
/// @returns Unitset containing @geysers
const Unitset& getGeysers() const;
/// <summary>Retrieves the set of all accessible neutral units in the game.</summary> This
/// includes @minerals, @geysers, and @critters.
///
/// @returns Unitset containing all neutral units.
const Unitset& getNeutralUnits() const;
/// <summary>Retrieves the set of all @minerals that were available at the beginning of the
/// game.</summary>
///
/// @note This set includes resources that have been mined out or are inaccessible.
///
/// @returns Unitset containing static @minerals
const Unitset& getStaticMinerals() const;
/// <summary>Retrieves the set of all @geysers that were available at the beginning of the
/// game.</summary>
///
/// @note This set includes resources that are inaccessible.
///
/// @returns Unitset containing static @geysers
const Unitset& getStaticGeysers() const;
/// <summary>Retrieves the set of all units owned by the neutral player (resources, critters,
/// etc.) that were available at the beginning of the game.</summary>
///
/// @note This set includes units that are inaccessible.
///
/// @returns Unitset containing static neutral units
const Unitset& getStaticNeutralUnits() const;
/// <summary>Retrieves the set of all accessible bullets.</summary>
///
/// @returns Bulletset containing all accessible Bullet objects.
const Bulletset& getBullets() const;
/// <summary>Retrieves the set of all accessible @Nuke dots.</summary>
///
/// @note Nuke dots are the red dots painted by a @Ghost when using the nuclear strike ability.
///
/// @returns Set of Positions giving the coordinates of nuke locations.
const Position::list& getNukeDots() const;
/// <summary>Retrieves the list of all unhandled game events.</summary>
///
/// @returns std::list containing Event objects.
const std::list< Event >& getEvents() const;
const void addEvent(const Event& e) { events.push_back(e); }
/// <summary>Retrieves the Force interface object associated with a given identifier.</summary>
///
/// <param name="forceID">
/// The identifier for the Force object.
/// </param>
///
/// @returns Force interface object mapped to the given \p forceID.
/// @retval nullptr if the given identifier is invalid.
Force getForce(ForceID forceID) const
{
if (auto const fp = getForceData(forceID); fp)
return *fp;
else return nullptr;
}
/// <summary>Retrieves the Player interface object associated with a given identifier.</summary>
///
/// <param name="playerID">
/// The identifier for the Player object.
/// </param>
///
/// @returns Player interface object mapped to the given \p playerID.
/// @retval nullptr if the given identifier is invalid.
Player getPlayer(PlayerID playerID) const
{
if (auto const pp = getPlayerData(playerID); pp)
return *pp;
else return nullptr;
};
/// <summary>Retrieves the Unit interface object associated with a given identifier.</summary>
///
/// <param name="unitID">
/// The identifier for the Unit object.
/// </param>
///
/// @returns Unit interface object mapped to the given \p unitID.
/// @retval nullptr if the given identifier is invalid.
Unit getUnit(UnitID unitID) const
{
if (auto const up = getUnitData(unitID); up)
return *up;
else return nullptr;
}
/// <summary>Retrieves the Region interface object associated with a given identifier.</summary>
///
/// <param name="regionID">
/// The identifier for the Region object.
/// </param>
///
/// @returns Region interface object mapped to the given \p regionID.
/// @retval nullptr if the given ID is invalid.
Region getRegion(int regionID) const;
/// <summary>Retrieves the GameType of the current game.</summary>
///
/// @returns GameType indicating the rules of the match.
/// @see GameType
GameType getGameType() const;
/// <summary>Retrieves the number of logical frames since the beginning of the match.</summary>
/// If the game is paused, then getFrameCount will not increase.
///
/// @returns Number of logical frames that have elapsed since the game started as an integer.
int getFrameCount() const;
/// <summary>Retrieves the logical frame rate of the game in frames per second (FPS).</summary>
///
/// Example:
/// @code{.cpp}
/// game.setLocalSpeed(0);
///
/// // Log and display the best logical FPS seen in the game
/// static int bestFPS = 0;
/// bestFPS = std::max(bestFPS, game.getFPS());
/// game.drawTextScreen(BWAPI::Positions::Origin, "%cBest: %d GFPS\nCurrent: %d GFPS", BWAPI::Text::White, bestFPS, BWAPI::Broodwar->getFPS());
/// @endcode
/// @returns Logical frames per second that the game is currently running at as an integer.
/// @see getAverageFPS
int getFPS() const;
/// <summary>Retrieves the average logical frame rate of the game in frames per second (FPS).</summary>
///
/// @returns Average logical frames per second that the game is currently running at as a
/// double.
/// @see getFPS
double getAverageFPS() const;
/// <summary>Retrieves the position of the user's mouse on the screen, in Position coordinates.</summary>
///
/// @returns Position indicating the location of the mouse.
/// @retval Positions::Unknown if Flag::UserInput is disabled.
Position getMousePosition() const;
/// <summary>Retrieves the state of the given mouse button.</summary>
///
/// <param name="button">
/// A MouseButton enum member indicating which button on the mouse to check.
/// </param>
///
/// @return A bool indicating the state of the given \p button. true if the button was pressed
/// and false if it was not.
/// @retval false always if Flag::UserInput is disabled.
///
/// @see MouseButton
bool getMouseState(MouseButton button) const;
/// <summary>Retrieves the state of the given keyboard key.</summary>
///
/// <param name="key">
/// A Key enum member indicating which key on the keyboard to check.
/// </param>
///
/// @return A bool indicating the state of the given \p key. true if the key was pressed
/// and false if it was not.
/// @retval false always if Flag::UserInput is disabled.
///
/// @see Key
bool getKeyState(Key key) const;
/// <summary>Retrieves the top left position of the viewport from the top left corner of the
/// map, in pixels.</summary>
///
/// @returns Position containing the coordinates of the top left corner of the game's viewport.
/// @retval Positions::Unknown always if Flag::UserInput is disabled.
/// @see setScreenPosition
BWAPI::Position getScreenPosition() const;
/// <summary>Moves the top left corner of the viewport to the provided position relative to
/// the map's origin (top left (0,0)).</summary>
///
/// <param name="x">
/// The x coordinate to move the screen to, in pixels.
/// </param>
/// <param name="y">
/// The y coordinate to move the screen to, in pixels.
/// </param>
/// @see getScreenPosition
void setScreenPosition(int x, int y);
/// @overload
void setScreenPosition(BWAPI::Position p);
/// <summary>Pings the minimap at the given position.</summary> Minimap pings are visible to
/// allied players.
///
/// <param name="x">
/// The x coordinate to ping at, in pixels, from the map's origin (left).
/// </param>
/// <param name="y">
/// The y coordinate to ping at, in pixels, from the map's origin (top).
/// </param>
void pingMinimap(int x, int y);
/// @overload
void pingMinimap(BWAPI::Position p);
/// <summary>Checks if the state of the given flag is enabled or not.</summary>
///
/// @note Flags may only be enabled at the start of the match during the AIModule::onStart
/// callback.
///
/// <param name="flag">
/// The Flag::Enum entry describing the flag's effects on BWAPI.
/// </param>
///
/// @returns true if the given \p flag is enabled, false if the flag is disabled.
///
/// @see Flag::Enum
///
/// @todo Take Flag::Enum as parameter instead of int
bool isFlagEnabled(int flag) const;
/// <summary>Retrieves the set of accessible units that are on a given build tile.</summary>
///
/// <param name="tileX">
/// The X position, in tiles.
/// </param>
/// <param name="tileY">
/// The Y position, in tiles.
/// </param>
/// <param name="pred"> (optional)
/// A function predicate that indicates which units are included in the returned set.
/// </param>
///
/// @returns A Unitset object consisting of all the units that have any part of them on the
/// given build tile.
Unitset getUnitsOnTile(int tileX, int tileY, const UnitFilter &pred = nullptr) const;
/// @overload
Unitset getUnitsOnTile(BWAPI::TilePosition tile, const UnitFilter &pred = nullptr) const;
/// <summary>Retrieves the set of accessible units that are in a given rectangle.</summary>
///
/// <param name="left">
/// The X coordinate of the left position of the bounding box, in pixels.
/// </param>
/// <param name="top">
/// The Y coordinate of the top position of the bounding box, in pixels.
/// </param>
/// <param name="right">
/// The X coordinate of the right position of the bounding box, in pixels.
/// </param>
/// <param name="bottom">
/// The Y coordinate of the bottom position of the bounding box, in pixels.
/// </param>
/// <param name="pred"> (optional)
/// A function predicate that indicates which units are included in the returned set.
/// </param>
///
/// @returns A Unitset object consisting of all the units that have any part of them within the
/// given rectangle bounds.
Unitset getUnitsInRectangle(int left, int top, int right, int bottom, const UnitFilter &pred = nullptr) const;
/// @overload
Unitset getUnitsInRectangle(BWAPI::Position topLeft, BWAPI::Position bottomRight, const UnitFilter &pred = nullptr) const;
/// <summary>Retrieves the set of accessible units that are within a given radius of a
/// position.</summary>
///
/// <param name="x">
/// The x coordinate of the center, in pixels.
/// </param>
/// <param name="y">
/// The y coordinate of the center, in pixels.
/// </param>
/// <param name="radius">
/// The radius from the center, in pixels, to include units.
/// </param>
/// <param name="pred"> (optional)
/// A function predicate that indicates which units are included in the returned set.
/// </param>
///
/// @returns A Unitset object consisting of all the units that have any part of them within the
/// given radius from the center position.
Unitset getUnitsInRadius(int x, int y, int radius, const UnitFilter &pred = nullptr) const;
/// @overload
Unitset getUnitsInRadius(BWAPI::Position center, int radius, const UnitFilter &pred = nullptr) const;
/// <summary>Retrieves the closest unit to center that matches the criteria of the callback
/// pred within an optional radius.</summary>
///
/// <param name="center">
/// The position to start searching for the closest unit.
/// </param>
/// <param name="pred"> (optional)
/// The UnitFilter predicate to determine which units should be included. This includes
/// all units by default.
/// </param>
/// <param name="radius"> (optional)
/// The radius to search in. If omitted, the entire map will be searched.
/// </param>
///
/// @returns The desired unit that is closest to center.
/// @retval nullptr If a suitable unit was not found.
///
/// @see getBestUnit, UnitFilter
Unit getClosestUnit(Position center, const UnitFilter &pred = nullptr, int radius = 999999) const;
/// <summary>Retrieves the closest unit to center that matches the criteria of the callback
/// pred within an optional rectangle.</summary>
///
/// <param name="center">
/// The position to start searching for the closest unit.
/// </param>
/// <param name="pred"> (optional)
/// The UnitFilter predicate to determine which units should be included. This includes
/// all units by default.
/// </param>
/// <param name="left"> (optional)
/// The left position of the rectangle. This value is 0 by default.
/// </param>
/// <param name="top"> (optional)
/// The top position of the rectangle. This value is 0 by default.
/// </param>
/// <param name="right"> (optional)
/// The right position of the rectangle. This value includes the entire map width by default.
/// </param>
/// <param name="bottom"> (optional)
/// The bottom position of the rectangle. This value includes the entire map height by default.
/// </param>
///
/// @see UnitFilter
Unit getClosestUnitInRectangle(Position center, const UnitFilter &pred = nullptr, int left = 0, int top = 0, int right = 999999, int bottom = 999999) const;
/// <summary>Compares all units with pred to determine which of them is the best.</summary>
/// All units are checked. If center and radius are specified, then it will check all units
/// that are within the radius of the position.
///
/// <param name="best">
/// A BestUnitFilter that determines which parameters should be considered when calculating
/// which units are better than others.
/// </param>
/// <param name="pred">
/// A UnitFilter that determines which units to include in calculations.
/// </param>
/// <param name="center"> (optional)
/// The position to use in the search. If omitted, then the entire map is searched.
/// </param>
/// <param name="radius"> (optional)
/// The distance from \p center to search for units. If omitted, then the entire map is
/// searched.
/// </param>
///
/// @returns The desired unit that best matches the given criteria.
/// @retval nullptr if a suitable unit was not found.
///
/// @see getClosestUnit, BestUnitFilter, UnitFilter
Unit getBestUnit(const BestUnitFilter &best, const UnitFilter &pred, Position center = Positions::Origin, int radius = 999999) const;
/// <summary>Returns the last error that was set using setLastError.</summary> If a function
/// call in BWAPI has failed, you can use this function to retrieve the reason it failed.
///
/// @returns Error type containing the reason for failure.
///
/// @see setLastError, Errors
Error getLastError() const;
/// <summary>Sets the last error so that future calls to getLastError will return the value
/// that was set.</summary>
///
/// <param name="e"> (optional)
/// The error code to set. If omitted, then the last error will be cleared.
/// </param>
///
/// @retval true If the type passed was Errors::None, clearing the last error.
/// @retval false If any other error type was passed.
/// @see getLastError, Errors
bool setLastError(BWAPI::Error e = Errors::None) const;
/// <summary>Retrieves the width of the map in build tile units.</summary>
///
/// @returns Width of the map in tiles.
/// @see mapHeight
int mapWidth() const;
/// <summary>Retrieves the height of the map in build tile units.</summary>
///
/// @returns Height of the map in tiles.
/// @see mapHeight
int mapHeight() const;
/// <summary>Retrieves the file name of the currently loaded map.</summary>
///
/// @returns Map file name as std::string object.
///
/// @see mapPathName, mapName
///
/// @TODO: Note on campaign files.
std::string mapFileName() const;
/// <summary>Retrieves the full path name of the currently loaded map.</summary>
///
/// @returns Map file name as std::string object.
///
/// @see mapFileName, mapName
///
/// @TODO: Note on campaign files.
std::string mapPathName() const;
/// <summary>Retrieves the title of the currently loaded map.</summary>
///
/// @returns Map title as std::string object.
///
/// @see mapFileName, mapPathName
std::string mapName() const;
/// <summary>Calculates the SHA-1 hash of the currently loaded map file.</summary>
///
/// @returns std::string object containing SHA-1 hash.
///
/// @note Campaign maps will return a hash of their internal map chunk components(.chk), while
/// standard maps will return a hash of their entire map archive (.scm,.scx).
///
/// @TODO: Note on replays.
std::string mapHash() const;
/// <summary>Checks if the given mini-tile position is walkable.</summary>
///
/// @note This function only checks if the static terrain is walkable. Its current occupied
/// state is excluded from this check. To see if the space is currently occupied or not, then
/// see #getUnitsInRectangle .
///
/// <param name="walkX">
/// The x coordinate of the mini-tile, in mini-tile units (8 pixels).
/// </param>
/// <param name="walkY">
/// The y coordinate of the mini-tile, in mini-tile units (8 pixels).
/// </param>
///
/// @returns true if the mini-tile is walkable and false if it is impassable for ground units.
bool isWalkable(int walkX, int walkY) const;
/// @overload
bool isWalkable(BWAPI::WalkPosition position) const;
/// <summary>Returns the ground height at the given tile position.</summary>
///
/// <param name="tileX">
/// X position to query, in tiles
/// </param>
/// <param name="tileY">
/// Y position to query, in tiles
/// </param>
///
/// @returns The tile height as an integer. Possible values are:
/// - 0: Low ground
/// - 1: Low ground doodad
/// - 2: High ground
/// - 3: High ground doodad
/// - 4: Very high ground
/// - 5: Very high ground doodad
int getGroundHeight(int tileX, int tileY) const;
/// @overload
int getGroundHeight(TilePosition position) const;
/// <summary>Checks if a given tile position is buildable.</summary> This means that, if all
/// other requirements are met, a structure can be placed on this tile. This function uses
/// static map data.
///
/// <param name="tileX">
/// The x value of the tile to check.
/// </param>
/// <param name="tileY">
/// The y value of the tile to check.
/// </param>
/// <param name="includeBuildings"> (optional)
/// If this is true, then this function will also check if any visible structures are
/// occupying the space. If this value is false, then it only checks the static map data
/// for tile buildability. This value is false by default.
/// </param>
///
/// @returns boolean identifying if the given tile position is buildable (true) or not (false).
/// If \p includeBuildings was provided, then it will return false if a structure is currently
/// occupying the tile.
bool isBuildable(int tileX, int tileY, bool includeBuildings = false) const {
return isBuildable({ tileX, tileY }, includeBuildings);
}
/// @overload
bool isBuildable(TilePosition position, bool includeBuildings = false) const {
return isValid(position) &&
gameData->map.isBuildable[position.x][position.y] &&
(includeBuildings
? !(isVisible(position) &&
gameData->map.isOccupied[position.x][position.y])
: true);
}
/// <summary>Checks if a given tile position is visible to the current player.</summary>
///
/// <param name="tileX">
/// The x value of the tile to check.
/// </param>
/// <param name="tileY">
/// The y value of the tile to check.
/// </param>
///
/// @returns boolean identifying the visibility of the tile. If the given tile is visible, then
/// the value is true. If the given tile is concealed by the fog of war, then this value will
/// be false.
bool isVisible(int tileX, int tileY) const {
return isVisible({tileX, tileY});
}
/// @overload
bool isVisible(TilePosition position) const {
return isValid(position) ? gameData->map.isVisible[position.x][position.y]
: false;
}
/// <summary>Checks if a given tile position has been explored by the player.</summary> An
/// explored tile position indicates that the player has seen the location at some point in the
/// match, partially revealing the fog of war for the remainder of the match.
///
/// <param name="tileX">
/// The x tile coordinate to check.
/// </param>
/// <param name="tileY">
/// The y tile coordinate to check.
/// </param>
///
/// @retval true If the player has explored the given tile position (partially revealed fog).
/// @retval false If the tile position was never explored (completely black fog).
///
/// @see isVisible
bool isExplored(int tileX, int tileY) const {
return isExplored({tileX, tileY});
}
/// @overload
bool isExplored(TilePosition position) const {
return isValid(position) ? gameData->map.isExplored[position.x][position.y]
: false;
}
/// <summary>Checks if the given tile position has @Zerg creep on it.</summary>
///
/// <param name="tileX">
/// The x tile coordinate to check.
/// </param>
/// <param name="tileY">
/// The y tile coordinate to check.
/// </param>
///
/// @retval true If the given tile has creep on it.
/// @retval false If the given tile does not have creep, or if it is concealed by the fog of war.
bool hasCreep(int tileX, int tileY) const {
return hasCreep({tileX, tileY});
}
/// @overload
bool hasCreep(TilePosition position) const {
return isValid(position) ? gameData->map.hasCreep[position.x][position.y]
: false;
}
/// <summary>Checks if the given pixel position is powered by an owned @Protoss_Pylon for an
/// optional unit type.</summary>
///
/// <param name="x">
/// The x pixel coordinate to check.
/// </param>
/// <param name="y">
/// The y pixel coordinate to check.
/// </param>
/// <param name="unitType"> (optional)
/// Checks if the given UnitType requires power or not. If ommitted, then it will assume
/// that the position requires power for any unit type.
/// </param>
///
/// @retval true if the type at the given position will have power.
/// @retval false if the type at the given position will be unpowered.
bool hasPowerPrecise(int x, int y, UnitType unitType = UnitTypes::None ) const;
/// @overload
bool hasPowerPrecise(Position position, UnitType unitType = UnitTypes::None) const;
/// <summary>Checks if the given tile position if powered by an owned @Protoss_Pylon for an
/// optional unit type.</summary>
///
/// <param name="tileX">
/// The x tile coordinate to check.
/// </param>
/// <param name="tileY">
/// The y tile coordinate to check.
/// </param>
/// <param name="unitType"> (optional)
/// Checks if the given UnitType will be powered if placed at the given tile position. If
/// omitted, then only the immediate tile position is checked for power, and the function
/// will assume that the location requires power for any unit type.
/// </param>
///
/// @retval true if the type at the given tile position will receive power.
/// @retval false if the type will be unpowered at the given tile position.
bool hasPower(int tileX, int tileY, UnitType unitType = UnitTypes::None) const;
/// @overload
bool hasPower(TilePosition position, UnitType unitType = UnitTypes::None) const;
/// @overload
bool hasPower(int tileX, int tileY, int tileWidth, int tileHeight, UnitType unitType = UnitTypes::None) const;
/// @overload
bool hasPower(TilePosition position, int tileWidth, int tileHeight, UnitType unitType = UnitTypes::None) const;
/// <summary>Checks if the given unit type can be built at the given build tile position.</summary>
/// This function checks for creep, power, and resource distance requirements in addition to
/// the tiles' buildability and possible units obstructing the build location.
///
/// @note If the type is an addon and a builer is provided, then the location of the addon will
/// be placed 4 tiles to the right and 1 tile down from the given \p position. If the builder
/// is not given, then the check for the addon will be conducted at position.
///
/// @note If \p type is UnitTypes::Special_Start_Location, then the area for a resource depot
/// (@Command_Center, @Hatchery, @Nexus) is checked as normal, but any potential obstructions
/// (existing structures, creep, units, etc.) are ignored.
///
/// <param name="position">
/// Indicates the tile position that the top left corner of the structure is intended to go.
/// </param>
/// <param name="type">
/// The UnitType to check for.
/// </param>
/// <param name="builder"> (optional)
/// The intended unit that will build the structure. If specified, then this function will
/// also check if there is a path to the build site and exclude the builder from the set of
/// units that may be blocking the build site.
/// </param>
/// <param name="checkExplored"> (optional)
/// If this parameter is true, it will also check if the target position has been explored
/// by the current player. This value is false by default, ignoring the explored state of
/// the build site.
/// </param>
///
/// @returns true indicating that the structure can be placed at the given tile position, and
/// false if something may be obstructing the build location.
bool canBuildHere(TilePosition position, UnitType type, Unit builder = nullptr, bool checkExplored = false) const;
/// <summary>Checks all the requirements in order to make a given unit type for the current
/// player.</summary> These include resources, supply, technology tree, availability, and
/// required units.
///
/// <param name="type">
/// The UnitType to check.
/// </param>
/// <param name="builder"> (optional)
/// The Unit that will be used to build/train the provided unit \p type. If this value is
/// nullptr or excluded, then the builder will be excluded in the check.
/// </param>
///
/// @returns true indicating that the type can be made. If \p builder is provided, then it is
/// only true if \p builder can make the \p type. Otherwise it will return false, indicating
/// that the unit type can not be made.
bool canMake(UnitType type, Unit builder = nullptr) const;
/// <summary>Checks all the requirements in order to research a given technology type for the
/// current player.</summary> These include resources, technology tree, availability, and
/// required units.
///
/// <param name="type">
/// The TechType to check.
/// </param>
/// <param name="unit"> (optional)
/// The Unit that will be used to research the provided technology \p type. If this value is
/// nullptr or excluded, then the unit will be excluded in the check.
/// </param>
/// <param name="checkCanIssueCommandType"> (optional)
/// TODO fill this in
/// </param>
///
/// @returns true indicating that the type can be researched. If \p unit is provided, then it is
/// only true if \p unit can research the \p type. Otherwise it will return false, indicating
/// that the technology can not be researched.
bool canResearch(TechType type, Unit unit = nullptr, bool checkCanIssueCommandType = true) const;
/// <summary>Checks all the requirements in order to upgrade a given upgrade type for the
/// current player.</summary> These include resources, technology tree, availability, and
/// required units.
///
/// <param name="type">
/// The UpgradeType to check.
/// </param>
/// <param name="unit"> (optional)
/// The Unit that will be used to upgrade the provided upgrade \p type. If this value is
/// nullptr or excluded, then the unit will be excluded in the check.
/// </param>
/// <param name="checkCanIssueCommandType"> (optional)
/// TODO fill this in
/// </param>
///
/// @returns true indicating that the type can be upgraded. If \p unit is provided, then it is
/// only true if \p unit can upgrade the \p type. Otherwise it will return false, indicating
/// that the upgrade can not be upgraded.
bool canUpgrade(UpgradeType type, Unit unit = nullptr, bool checkCanIssueCommandType = true) const;
/// <summary>Retrieves the set of all starting locations for the current map.</summary> A
/// starting location is essentially a candidate for a player's spawn point.
///
/// @returns A TilePosition::list containing all the TilePosition objects that indicate a start
/// location.
/// @see Player::getStartLocation
const TilePosition::list& getStartLocations() const;
/// <summary>Prints text to the screen as a notification.</summary> This function allows text
/// formatting using Text::Enum members. The behaviour of this function is the same as printf,
/// located in header cstdio.
///
/// @note That text printed through this function is not seen by other players or in replays.
///
/// <param name="format">
/// Text formatting. See std::printf for more information. Refrain from passing non-constant
/// strings directly in this parameter.
/// </param>
/// <param name="...">
/// The arguments that will be formatted using the given text formatting.
/// </param>
///
/// @see Text::Enum, std::printf
void printf(const char *format, ...);
/// @copydoc printf
///
/// This function is intended to forward an already-existing argument list.
///
/// <param name="args">
/// The argument list that will be formatted.
/// </param>
///
/// @see printf
void vPrintf(const char *format, va_list args);
/// <summary>Sends a text message to all other players in the game.</summary> The behaviour of
/// this function is the same as std::printf, located in header cstdio.
///
/// @note In a single player game this function can be used to execute cheat codes.
///
/// <param name="format">
/// Text formatting. See std::printf for more information. Refrain from passing non-constant
/// strings directly in this parameter.
/// </param>
///
/// @see sendTextEx, std::printf
void sendText(const char *format, ...);
/// @copydoc sendText
///
/// This function is intended to forward an already-existing argument list.
///
/// <param name="args">
/// The argument list that will be formatted.
/// </param>
///
/// @see sendText
void vSendText(const char *format, va_list args);
/// <summary>An extended version of Game::sendText which allows messages to be forwarded to
/// allies.</summary> The behaviour of this function is the same as std::printf, located in
/// header cstdio.
///
/// <param name="toAllies">
/// If this parameter is set to true, then the message is only sent to allied players,
/// otherwise it will be sent to all players.
/// </param>
/// <param name="format">
/// Text formatting. See std::printf for more information. Refrain from passing non-constant
/// strings directly in this parameter.
/// </param>
///
/// @see sendText, std::printf
void sendTextEx(bool toAllies, const char *format, ...);
/// @copydoc sendTextEx
///
/// This function is intended to forward an already-existing argument list.
///
/// <param name="args">
/// The argument list that will be formatted.
/// </param>
///
/// @see sendTextEx
void vSendTextEx(bool toAllies, const char *format, va_list args);
/// <summary>Checks if the current client is inside a game.</summary>
///
/// @returns true if the client is in a game, and false if it is not.
bool isInGame() const { return gameData->isInGame; }
/// <summary>Checks if the current client is inside a multiplayer game.</summary>
///
/// @returns true if the client is in a multiplayer game, and false if it is a single player
/// game, a replay, or some other state.
bool isMultiplayer() const { return gameData->isMultiplayer; }
/// <summary>Checks if the client is in a game that was created through the Battle.net
/// multiplayer gaming service.</summary>
///
/// @returns true if the client is in a multiplayer Battle.net game and false if it is not.
bool isBattleNet() const { return gameData->isBattleNet; }
/// <summary>Checks if the current game is paused.</summary> While paused, AIModule::onFrame
/// will still be called.
///
/// @returns true if the game is paused and false otherwise
/// @see pauseGame, resumeGame
bool isPaused() const { return gameData->isPaused; }
/// <summary>Checks if the client is watching a replay.</summary>
///
/// @returns true if the client is watching a replay and false otherwise
bool isReplay() const { return gameData->isReplay; }
/// <summary>Pauses the game.</summary> While paused, AIModule::onFrame will still be called.
/// @see resumeGame
void pauseGame();
/// <summary>Resumes the game from a paused state.</summary>
/// @see pauseGame
void resumeGame();
/// <summary>Leaves the current game by surrendering and enters the post-game statistics/score
/// screen.</summary>
void leaveGame();
/// <summary>Restarts the match.</summary> Works the same as if the match was restarted from
/// the in-game menu (F10). This option is only available in single player games.
///
/// @returns false if not in game, or if isMultiPlayer is true.
bool restartGame();
/// <summary>Sets the number of milliseconds Broodwar spends in each frame.</summary> The
/// default values are as follows:
/// - Fastest: 42ms/frame
/// - Faster: 48ms/frame
/// - Fast: 56ms/frame
/// - Normal: 67ms/frame
/// - Slow: 83ms/frame
/// - Slower: 111ms/frame
/// - Slowest: 167ms/frame
///
/// @note Specifying a value of 0 will not guarantee that logical frames are executed as fast
/// as possible. If that is the intention, use this in combination with #setFrameSkip.
///
/// @bug Changing this value will cause the execution of @UMS scenario triggers to glitch.
/// This will only happen in campaign maps and custom scenarios (non-melee).
///
/// <param name="speed">
/// The time spent per frame, in milliseconds. A value of 0 indicates that frames are
/// executed immediately with no delay. Negative values will restore the default value
/// as listed above.
/// </param>
///
/// @see setFrameSkip, getFPS
void setLocalSpeed(int speed);
/// <summary>Issues a given command to a set of units.</summary> This function automatically
/// splits the set into groups of 12 and issues the same command to each of them. If a unit
/// is not capable of executing the command, then it is simply ignored.
///
/// <param name="units">