1 #ifndef _AIFramework_h_ 2 #define _AIFramework_h_ 3 4 #include "../../python/CommonFramework.h" 5 6 #include <string> 7 #include <vector> 8 9 #ifdef FREEORION_MACOSX 10 // Bugfix for https://github.com/freeorion/freeorion/issues/1228 11 12 // The problem on OSX is that the boost/python/str.hpp redefines toupper() and 13 // similar functions if they are not already defined. 14 15 // This includes iostream before the boost/python/str.hpp to fix this issue. 16 // If the subsequent #include <boost/python/str.hpp> is removed then so can this workaround. 17 #include <iostream> 18 #endif 19 20 #include <boost/python/str.hpp> 21 22 class DiplomaticMessage; 23 struct DiplomaticStatusUpdateInfo; 24 25 26 /** @brief Class allowing AI to recieve basic game events. 27 */ 28 class PythonAI : public PythonBase { 29 public: 30 bool Initialize(); 31 32 /** Initializes AI Python imports. */ 33 bool InitImports() override; 34 /** Initializes AI Python modules. */ 35 bool InitModules() override; 36 37 /** @brief Call when the server has sent a new turn update. 38 * 39 * The AI subclass should review the new gamestate and send orders for 40 * this turn. 41 */ 42 void GenerateOrders(); 43 44 /** @brief Called when another player sends a chat message to this AI. 45 * 46 * The AI subclass should respond or react to the message in a meaningful 47 * way. 48 * 49 * @param sender_id The player identifier representing the player, who sent 50 * the message. 51 * @param msg The text body of the sent message. 52 */ 53 void HandleChatMessage(int sender_id, const std::string& msg); 54 55 /** @brief Called when another player sends a diplomatic message that 56 * affects this player 57 * 58 * The AI subclass should respond or react to the message in a meaningful 59 * way. 60 * 61 * @param msg The diplomatic message sent. 62 */ 63 void HandleDiplomaticMessage(const DiplomaticMessage& msg); 64 65 /** @brief Called when two empires diplomatic status changes 66 * 67 * The AI subclass should respond or react to the change in a meaningful 68 * way. 69 * 70 * @param u The diplomatic status changed. 71 */ 72 void HandleDiplomaticStatusUpdate(const DiplomaticStatusUpdateInfo& u); 73 74 /** @brief Called when a new game (not loaded) is started 75 * 76 * The AI subclass should clear its state and prepare to start for a new 77 * game. 78 */ 79 void StartNewGame(); 80 81 /** @brief Called when a game is loaded from a save 82 * 83 * The AI subclass should extract any state information stored in 84 * @a save_state so it is able to continue generating orders when 85 * asked to do so. 86 * 87 * @param save_state The serialized state information from a previous game 88 * run. 89 */ 90 void ResumeLoadedGame(const std::string& save_state_string); 91 92 /** @brief Called when the server is saving the game 93 * 94 * The AI should store any state information it will need to resume at any 95 * later time, and return this information. 96 * 97 * @return The serialized state information of the game running. 98 */ 99 const std::string& GetSaveStateString() const; 100 101 /** @brief Set the aggressiveness of this AI 102 * 103 * The AI should change their behaviour when setting another aggression 104 * level. 105 * 106 * @param aggr The new aggression level. The value should be one of 107 * Aggression. 108 */ 109 void SetAggression(int aggr); 110 111 private: 112 // reference to imported Python AI module 113 boost::python::object m_python_module_ai; 114 115 /** @brief The current aggressiveness of this AI 116 * 117 * The value should be one of Aggression. 118 */ 119 int m_aggression; 120 }; 121 122 #endif // _AIFramework_h_ 123