truelight@2395: #ifndef AI_H truelight@2395: #define AI_H truelight@2395: truelight@2395: #include "../functions.h" truelight@2395: truelight@2395: /* How DoCommands look like for an AI */ truelight@2395: typedef struct AICommand { truelight@2395: uint32 tile; truelight@2395: uint32 p1; truelight@2395: uint32 p2; truelight@2395: uint32 procc; truelight@2395: truelight@2395: uint32 dp[20]; truelight@2395: truelight@2395: struct AICommand *next; truelight@2395: } AICommand; truelight@2395: truelight@2395: /* The struct for an AIScript Player */ truelight@2395: typedef struct AIPlayer { truelight@2395: bool active; //! Is this AI active? truelight@2395: AICommand *queue; //! The commands that he has in his queue truelight@2395: AICommand *queue_tail; //! The tail of this queue truelight@2395: } AIPlayer; truelight@2395: truelight@2395: /* The struct to keep some data about the AI in general */ truelight@2395: typedef struct AIStruct { truelight@2395: /* General */ truelight@2395: bool enabled; //! Is AI enabled? truelight@2395: uint tick; //! The current tick (something like _frame_counter, only for AIs) truelight@2395: truelight@2395: /* For network-clients (a OpenTTD client who acts as an AI connected to a server) */ truelight@2395: bool network_client; //! Are we a network_client? truelight@2395: uint8 network_player; //! The current network player we are connected as truelight@2395: } AIStruct; truelight@2395: truelight@2395: VARDEF AIStruct _ai; truelight@2395: VARDEF AIPlayer _ai_player[MAX_PLAYERS]; truelight@2395: truelight@2395: // ai.c tron@2551: void AI_StartNewAI(PlayerID player); tron@2551: void AI_PlayerDied(PlayerID player); truelight@2395: void AI_RunGameLoop(void); truelight@2395: void AI_Initialize(void); truelight@2395: void AI_Uninitialize(void); truelight@2395: int32 AI_DoCommand(uint tile, uint32 p1, uint32 p2, uint32 flags, uint procc); truelight@2395: truelight@2395: #define AI_CHANCE16(a,b) ((uint16) AI_Random() <= (uint16)((65536 * a) / b)) truelight@2395: #define AI_CHANCE16R(a,b,r) ((uint16)(r = AI_Random()) <= (uint16)((65536 * a) / b)) truelight@2395: truelight@2395: /** truelight@2395: * The random-function that should be used by ALL AIs. truelight@2395: */ truelight@2395: static inline uint AI_RandomRange(uint max) truelight@2395: { truelight@2395: /* We pick RandomRange if we are in SP (so when saved, we do the same over and over) truelight@2395: * but we pick InteractiveRandomRange if we are a network_server or network-client. truelight@2395: */ truelight@2395: if (_networking) truelight@2395: return InteractiveRandomRange(max); truelight@2395: else truelight@2395: return RandomRange(max); truelight@2395: } truelight@2395: truelight@2395: /** truelight@2395: * The random-function that should be used by ALL AIs. truelight@2395: */ truelight@2395: static inline uint32 AI_Random(void) truelight@2395: { truelight@2395: /* We pick RandomRange if we are in SP (so when saved, we do the same over and over) truelight@2395: * but we pick InteractiveRandomRange if we are a network_server or network-client. truelight@2395: */ truelight@2395: if (_networking) truelight@2395: return InteractiveRandom(); truelight@2395: else truelight@2395: return Random(); truelight@2395: } truelight@2395: truelight@2395: #endif /* AI_H */