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