PageRenderTime 65ms CodeModel.GetById 21ms RepoModel.GetById 1ms app.codeStats 0ms

/AI/Skirmish/AAI/AAIBrain.h

http://github.com/spring/spring
C Header | 139 lines | 59 code | 44 blank | 36 comment | 0 complexity | 3e5840fbe5438766170b33b523ab180a MD5 | raw file
Possible License(s): BSD-3-Clause, GPL-3.0
  1. // -------------------------------------------------------------------------
  2. // AAI
  3. //
  4. // A skirmish AI for the Spring engine.
  5. // Copyright Alexander Seizinger
  6. //
  7. // Released under GPL license: see LICENSE.html for more information.
  8. // -------------------------------------------------------------------------
  9. #ifndef AAI_BRAIN_H
  10. #define AAI_BRAIN_H
  11. class AAI;
  12. class AAIBuildTable;
  13. class AAIExecute;
  14. class AIIMap;
  15. class AAISector;
  16. #include "aidef.h"
  17. enum SectorType {UNKNOWN_SECTOR, LAND_SECTOR, LAND_WATER_SECTOR, WATER_SECTOR};
  18. class AAIBrain
  19. {
  20. public:
  21. AAIBrain(AAI *ai);
  22. ~AAIBrain(void);
  23. // adds/removes sector to the base
  24. void AddSector(AAISector *sector);
  25. void RemoveSector(AAISector *sector);
  26. // returns dest attack sector
  27. AAISector* GetAttackDest(bool land, bool water);
  28. // returns a sector to proceed with attack
  29. AAISector* GetNextAttackDest(AAISector *current_sector, bool land, bool water);
  30. // checks for new neighbours (and removes old ones if necessary)
  31. void UpdateNeighbouringSectors();
  32. // recalculates the center of the base
  33. void UpdateBaseCenter();
  34. // updates max units spotted
  35. void UpdateMaxCombatUnitsSpotted(vector<unsigned short>& units_spotted);
  36. void UpdateAttackedByValues();
  37. void AttackedBy(int combat_category_id);
  38. // recalculates def capabilities of all units
  39. void UpdateDefenceCapabilities();
  40. // adds/subtracts def. cap. for a single unit
  41. void AddDefenceCapabilities(int def_id, UnitCategory category);
  42. // void SubtractDefenceCapabilities(int def_id, UnitCategory category);
  43. // returns pos where scout schould be sent to
  44. void GetNewScoutDest(float3 *dest, int scout);
  45. // adds new sectors to base
  46. bool ExpandBase(SectorType sectorType);
  47. // returns how much ressources can be spent for unit construction atm
  48. float Affordable();
  49. // returns true if commander is allowed for construction at the specified position in the sector
  50. bool CommanderAllowedForConstructionAt(AAISector *sector, float3 *pos);
  51. // returns true if AAI may build a mex in this sector (e.g. safe sector)
  52. bool MexConstructionAllowedInSector(AAISector *sector);
  53. void DefendCommander(int attacker);
  54. void BuildUnits();
  55. // returns game period
  56. int GetGamePeriod();
  57. void UpdatePressureByEnemy();
  58. // returns the probability that units of specified combat category will be used to attack (determine value with respect to game period, current and learning data)
  59. float GetAttacksBy(int combat_category, int game_period);
  60. // 0 = sectors the ai uses to build its base, 1 = direct neighbours etc.
  61. vector<list<AAISector*> > sectors;
  62. // ratio of flat land/water cells in all base sectors
  63. float baseLandRatio;
  64. float baseWaterRatio;
  65. int max_distance;
  66. // center of base (mean value of centers of all base sectors)
  67. float3 base_center;
  68. // are there any free metal spots within the base
  69. bool freeBaseSpots;
  70. bool expandable;
  71. // holding max number of units of a category spotted at the same time
  72. vector<float> max_combat_units_spotted;
  73. // current estimations of game situation , values ranging from 0 (min) to 1 max
  74. float enemy_pressure_estimation; // how much pressure done to the ai by enemy units
  75. // pos where com spawned
  76. float3 start_pos;
  77. private:
  78. // returns true if sufficient ressources to build unit are availbale
  79. bool RessourcesForConstr(int unit, int workertime = 175);
  80. // returns true if enough metal for constr.
  81. bool MetalForConstr(int unit, int workertime = 175);
  82. // returns true if enough energy for constr.
  83. bool EnergyForConstr(int unit, int wokertime = 175);
  84. // returns true if sector is considered to be safe
  85. bool IsSafeSector(AAISector *sector);
  86. void BuildUnitOfMovementType(unsigned int allowed_move_type, float cost, float ground_eff, float air_eff, float hover_eff, float sea_eff, float submarine_eff, float stat_eff, bool urgent);
  87. // returns ratio of cells in the current base sectors that match movement_type (e.g. 0.3 if 30% of base is covered with water and building is naval)
  88. float GetBaseBuildspaceRatio(unsigned int building_move_type);
  89. bool SectorInList(list<AAISector*> mylist, AAISector *sector);
  90. list<AAISector*> GetSectors();
  91. vector<float> defence_power_vs;
  92. vector<float> attacked_by;
  93. AAI *ai;
  94. };
  95. #endif