From 013df98f79866a75f367853c9e436f3c5c79f645 Mon Sep 17 00:00:00 2001 From: rubidium Date: Tue, 2 Jan 2007 19:19:48 +0000 Subject: (svn r7759) -Merge: makefile rewrite. This merge features: - A proper ./configure, so everything needs to be configured only once, not for every make. - Usage of makedepend when available. This greatly reduces the time needed for generating the dependencies. - A generator for all project files. There is a single file with sources, which is used to generate Makefiles and the project files for MSVC. - Proper support for OSX universal binaries. - Object files for non-MSVC compiles are also placed in separate directories, making is faster to switch between debug and release compiles and it does not touch the directory with the source files. - Functionality to make a bundle of all needed files for for example a nightly or distribution of a binary with all needed GRFs and language files. Note: as this merge moves almost all files, it is recommended to make a backup of your working copy before updating your working copy. --- src/ai/ai.h | 111 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 111 insertions(+) create mode 100644 src/ai/ai.h (limited to 'src/ai/ai.h') diff --git a/src/ai/ai.h b/src/ai/ai.h new file mode 100644 index 000000000..6123970ac --- /dev/null +++ b/src/ai/ai.h @@ -0,0 +1,111 @@ +#ifndef AI_H +#define AI_H + +#include "../functions.h" +#include "../network/network.h" +#include "../player.h" +#include "../command.h" + +/* How DoCommands look like for an AI */ +typedef struct AICommand { + uint32 tile; + uint32 p1; + uint32 p2; + uint32 procc; + CommandCallback* callback; + + char *text; + uint uid; + + struct AICommand *next; +} AICommand; + +/* The struct for an AIScript Player */ +typedef struct AIPlayer { + bool active; ///< Is this AI active? + AICommand *queue; ///< The commands that he has in his queue + AICommand *queue_tail; ///< The tail of this queue +} AIPlayer; + +/* The struct to keep some data about the AI in general */ +typedef struct AIStruct { + /* General */ + bool enabled; ///< Is AI enabled? + uint tick; ///< The current tick (something like _frame_counter, only for AIs) +} AIStruct; + +VARDEF AIStruct _ai; +VARDEF AIPlayer _ai_player[MAX_PLAYERS]; + +// ai.c +void AI_StartNewAI(PlayerID player); +void AI_PlayerDied(PlayerID player); +void AI_RunGameLoop(void); +void AI_Initialize(void); +void AI_Uninitialize(void); +int32 AI_DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc); +int32 AI_DoCommandCc(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc, CommandCallback* callback); + +/** Is it allowed to start a new AI. + * This function checks some boundries to see if we should launch a new AI. + * @return True if we can start a new AI. + */ +static inline bool AI_AllowNewAI(void) +{ + /* If disabled, no AI */ + if (!_ai.enabled) + return false; + + /* If in network, but no server, no AI */ + if (_networking && !_network_server) + return false; + + /* If in network, and server, possible AI */ + if (_networking && _network_server) { + /* Do we want AIs in multiplayer? */ + if (!_patches.ai_in_multiplayer) + return false; + + /* Only the NewAI is allowed... sadly enough the old AI just doesn't support this + * system, because all commands are delayed by at least 1 tick, which causes + * a big problem, because it uses variables that are only set AFTER the command + * is really executed... */ + if (!_patches.ainew_active) + return false; + } + + return true; +} + +#define AI_CHANCE16(a,b) ((uint16) AI_Random() <= (uint16)((65536 * a) / b)) +#define AI_CHANCE16R(a,b,r) ((uint16)(r = AI_Random()) <= (uint16)((65536 * a) / b)) + +/** + * The random-function that should be used by ALL AIs. + */ +static inline uint AI_RandomRange(uint max) +{ + /* We pick RandomRange if we are in SP (so when saved, we do the same over and over) + * but we pick InteractiveRandomRange if we are a network_server or network-client. + */ + if (_networking) + return InteractiveRandomRange(max); + else + return RandomRange(max); +} + +/** + * The random-function that should be used by ALL AIs. + */ +static inline uint32 AI_Random(void) +{ +/* We pick RandomRange if we are in SP (so when saved, we do the same over and over) + * but we pick InteractiveRandomRange if we are a network_server or network-client. + */ + if (_networking) + return InteractiveRandom(); + else + return Random(); +} + +#endif /* AI_H */ -- cgit v1.2.3-70-g09d2