ai.h
00001
00002
00003 #ifndef AI_H
00004 #define AI_H
00005
00006 #include "../network/network.h"
00007 #include "../command_type.h"
00008 #include "../core/random_func.hpp"
00009 #include "../settings_type.h"
00010
00011
00012 struct AICommand {
00013 uint32 tile;
00014 uint32 p1;
00015 uint32 p2;
00016 uint32 procc;
00017 CommandCallback *callback;
00018
00019 char *text;
00020 uint uid;
00021
00022 AICommand *next;
00023 };
00024
00025
00026 struct AIPlayer {
00027 bool active;
00028 AICommand *queue;
00029 AICommand *queue_tail;
00030 };
00031
00032
00033 struct AIStruct {
00034
00035 bool enabled;
00036 uint tick;
00037 };
00038
00039 extern AIStruct _ai;
00040 extern AIPlayer _ai_player[MAX_PLAYERS];
00041
00042
00043 void AI_StartNewAI(PlayerID player);
00044 void AI_PlayerDied(PlayerID player);
00045 void AI_RunGameLoop();
00046 void AI_Initialize();
00047 void AI_Uninitialize();
00048 CommandCost AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);
00049 CommandCost AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback);
00050
00055 static inline bool AI_AllowNewAI()
00056 {
00057
00058 if (!_ai.enabled)
00059 return false;
00060
00061
00062 if (_networking && !_network_server)
00063 return false;
00064
00065
00066 if (_networking && _network_server) {
00067
00068 if (!_patches.ai_in_multiplayer)
00069 return false;
00070
00071
00072
00073
00074
00075 if (!_patches.ainew_active)
00076 return false;
00077 }
00078
00079 return true;
00080 }
00081
00082 #define AI_CHANCE16(a, b) ((uint16) AI_Random() <= (uint16)((65536 * a) / b))
00083 #define AI_CHANCE16R(a, b, r) ((uint16)(r = AI_Random()) <= (uint16)((65536 * a) / b))
00084
00088 static inline uint AI_RandomRange(uint max)
00089 {
00090
00091
00092
00093 if (_networking)
00094 return InteractiveRandomRange(max);
00095 else
00096 return RandomRange(max);
00097 }
00098
00102 static inline uint32 AI_Random()
00103 {
00104
00105
00106
00107 if (_networking)
00108 return InteractiveRandom();
00109 else
00110 return Random();
00111 }
00112
00113 #endif