1 /* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */ 2 3 #ifndef I_GLOBAL_AI_H 4 #define I_GLOBAL_AI_H 5 6 #include <cstdlib> 7 #include <cstring> 8 9 #include "aibase.h" 10 #include "Command.h" 11 #include "System/float3.h" 12 13 #define GLOBAL_AI_INTERFACE_VERSION (19 + AI_INTERFACE_GENERATED_VERSION) 14 15 #define AI_EVENT_UNITGIVEN 1 // ChangeTeamEvent 16 #define AI_EVENT_UNITCAPTURED 2 // ChangeTeamEvent 17 #define AI_EVENT_WEAPON_FIRED 3 // WeaponFireEvent 18 #define AI_EVENT_PLAYER_COMMAND 4 // PlayerCommandEvent 19 #define AI_EVENT_SEISMIC_PING 5 // SeismicPingEvent 20 21 22 namespace springLegacyAI { 23 24 class IGlobalAICallback; 25 struct WeaponDef; 26 27 class IGlobalAI 28 { 29 public: 30 struct ChangeTeamEvent { 31 int unit, newteam, oldteam; 32 }; 33 struct WeaponFireEvent { 34 int unit; 35 const WeaponDef* def; 36 }; 37 struct PlayerCommandEvent { 38 std::vector<int> units; 39 Command command; 40 int player; 41 }; 42 struct SeismicPingEvent { 43 float3 pos; 44 float strength; 45 }; 46 47 /// Called only once, right after the constructor was called 48 virtual void InitAI(IGlobalAICallback* callback, int team) = 0; 49 /// Called only once, right before the destructor is called ReleaseAI()50 virtual void ReleaseAI() {} 51 52 /// called when a new unit is created on ai team 53 virtual void UnitCreated(int unit, int builder) = 0; 54 /// called when an unit has finished building 55 virtual void UnitFinished(int unit) = 0; 56 /// called when a unit is destroyed 57 virtual void UnitDestroyed(int unit, int attacker) = 0; 58 59 /// called when a new enemy unit is created EnemyCreated(int enemy)60 virtual void EnemyCreated(int enemy) {} 61 /// called when a new enemy unit has finished building EnemyFinished(int enemy)62 virtual void EnemyFinished(int enemy) {} 63 64 virtual void EnemyEnterLOS(int enemy) = 0; 65 virtual void EnemyLeaveLOS(int enemy) = 0; 66 67 /** 68 * called when an enemy enter radar coverage 69 * (los always count as radar coverage to) 70 */ 71 virtual void EnemyEnterRadar(int enemy) = 0; 72 /** 73 * called when an enemy leave radar coverage 74 * (los always count as radar coverage to) 75 */ 76 virtual void EnemyLeaveRadar(int enemy) = 0; 77 78 /// called when an enemy inside los or radar is damaged 79 virtual void EnemyDamaged(int damaged, int attacker, float damage, float3 dir) = 0; 80 /** 81 * will be called if an enemy inside los or radar dies 82 * (note that leave los etc will not be called then) 83 */ 84 virtual void EnemyDestroyed(int enemy, int attacker) = 0; 85 86 /// called when a unit go idle and is not assigned to any group 87 virtual void UnitIdle(int unit) = 0; 88 89 90 /** 91 * @deprecated 92 * @see #RecvChatMessage 93 */ GotChatMsg(const char * message,int player)94 virtual void GotChatMsg(const char* message, int player) {} 95 96 97 /// called when a player sends a chat message RecvChatMessage(const char * message,int player)98 virtual void RecvChatMessage(const char* message, int player) { GotChatMsg(message, player); } 99 100 /// called when a Lua widget or unsynced gadget sends a message to this AI 101 /// do not use outData, it is always NULL for interface-technical reasons RecvLuaMessage(const char * inData,const char ** outData)102 virtual void RecvLuaMessage(const char* inData, const char** outData) { /* *outData = inData; */ } 103 104 105 /// called when one of your units are damaged 106 virtual void UnitDamaged(int damaged, int attacker, float damage, float3 dir) = 0; 107 /// called when a ground unit failed to reach it's destination 108 virtual void UnitMoveFailed(int unit) = 0; 109 110 /// general messaging function to be used for future API extensions. 111 virtual int HandleEvent(int msg, const void *data) = 0; 112 113 /// called every frame 114 virtual void Update() = 0; 115 116 /// load ai from file Load(IGlobalAICallback * callback,std::istream * s)117 virtual void Load(IGlobalAICallback* callback, std::istream* s) {} 118 /// save ai to file Save(std::ostream * s)119 virtual void Save(std::ostream* s) {} 120 121 // use virtual instead of pure virtual, 122 // because pure virtual is not well supported 123 // among different OSs and compilers, 124 // and pure virtual has no advantage 125 // if we have other pure virtual functions 126 // in the class ~IGlobalAI()127 virtual ~IGlobalAI() {} 128 }; 129 130 } // namespace springLegacyAI 131 132 #endif // I_GLOBAL_AI_H 133