truelight@9361: /* $Id$ */ truelight@9361: truebrain@9829: /** @file ai_object.hpp Main object, on which all objects depend. */ truelight@9361: truelight@9361: #ifndef AI_OBJECT_HPP truelight@9361: #define AI_OBJECT_HPP truelight@9361: truelight@9441: #include "../../stdafx.h" rubidium@9837: #include "../../openttd.h" truelight@9679: #include "../../misc/countedptr.hpp" rubidium@9837: #include "../../signs_type.h" truebrain@9844: #include "../../strings_type.h" rubidium@9837: #include "../../command_type.h" rubidium@9837: #include "../../vehicle_type.h" rubidium@9837: #include "../../tile_type.h" rubidium@9837: #include "../../player_type.h" truelight@9361: truebrain@9814: #ifndef _SQUIRREL_H_ truebrain@9814: /* Life becomes easier when we can tell about a function it needs the VM, but truebrain@9814: * without really including 'squirrel.h'. */ truebrain@9829: typedef void *HSQUIRRELVM; truebrain@9814: typedef int SQInteger; truebrain@9814: #endif truebrain@9814: truelight@9475: /** rubidium@9864: * The type (an alias) for all errors the AI API knows. rubidium@9864: */ rubidium@9864: typedef uint AIErrorType; rubidium@9864: rubidium@9864: /** truelight@9475: * The callback function for Mode-classes. truelight@9475: */ glx@9629: typedef bool (AIModeProc)(TileIndex tile, uint32 p1, uint32 p2, uint procc, CommandCost costs); truelight@9450: truelight@9448: /** truelight@9448: * Uper-parent object of all API classes. You should never use this class in truelight@9448: * your AI, as it doesn't publish any public functions. It is used truelight@9448: * internally to have a common place to handle general things, like internal truelight@9448: * command processing, and command-validation checks. truelight@9448: */ truelight@9679: class AIObject : public SimpleCountedObject { truelight@9450: private: truelight@9450: struct AIDoCommandStruct { truelight@9450: AIModeProc *mode; truelight@9473: AIObject *mode_instance; truelight@9450: uint delay; glx@9629: CommandCost costs; rubidium@9863: uint last_error; truebrain@9760: bool last_command_res; truelight@9496: VehicleID new_vehicle_id; rubidium@9511: SignID new_sign_id; truelight@9680: void *event_data; truebrain@9851: void *log_data; truelight@9450: }; truelight@9450: truelight@9450: /** truelight@9450: * The current mode of the AI players. truelight@9450: */ truelight@9450: static AIDoCommandStruct *GetDoCommandStruct(PlayerID player); truelight@9450: truelight@9361: protected: truelight@9361: /** truelight@9361: * Executes a raw DoCommand for the AI. truelight@9361: */ truelight@9695: static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint procc, bool water_protection = true); truelight@9414: truelight@9414: /** truelight@9452: * Sets the DoCommand costs counter to a value. truelight@9414: */ glx@9629: static void SetDoCommandCosts(Money value); truelight@9414: truelight@9414: /** truelight@9452: * Increase the current value of the DoCommand costs counter. truelight@9414: */ glx@9629: static void IncreaseDoCommandCosts(Money value); truelight@9452: truelight@9452: /** truelight@9452: * Get the current DoCommand costs counter. truelight@9452: */ glx@9629: static Money GetDoCommandCosts(); truelight@9450: truelight@9450: /** truebrain@9844: * Set the DoCommand last error. truebrain@9844: */ rubidium@9864: static void SetLastError(AIErrorType last_error); truebrain@9844: truebrain@9844: /** truebrain@9844: * Get the DoCommand last error. truebrain@9844: */ rubidium@9864: static AIErrorType GetLastError(); truebrain@9844: truebrain@9844: /** truelight@9450: * Set the current mode of your AI to this proc. truelight@9450: */ truelight@9473: static void SetDoCommandMode(AIModeProc *proc, AIObject *instance); truelight@9450: truelight@9450: /** truelight@9450: * Get the current mode your AI is currently under. truelight@9450: */ truelight@9473: static AIModeProc *GetDoCommandMode(); truelight@9473: truelight@9473: /** truelight@9473: * Get the instance of the current mode your AI is currently under. truelight@9473: */ truelight@9473: static AIObject *GetDoCommandModeInstance(); truelight@9450: truelight@9450: /** truelight@9450: * Set the delay of the DoCommand. truelight@9450: */ truelight@9473: static void SetDoCommandDelay(uint ticks); truelight@9450: truelight@9450: /** truelight@9450: * Get the delay of the DoCommand. truelight@9450: */ truelight@9473: static uint GetDoCommandDelay(); truelight@9454: truelight@9496: /** truebrain@9760: * Get the latest result of a DoCommand. truebrain@9760: */ truebrain@9760: static bool GetLastCommandRes(); truebrain@9760: truebrain@9760: /** truelight@9496: * Get the latest stored new_vehicle_id. truelight@9496: */ truelight@9496: static VehicleID GetNewVehicleID(); truelight@9496: rubidium@9511: /** rubidium@9511: * Get the latest stored new_sign_id. rubidium@9511: */ rubidium@9511: static SignID GetNewSignID(); rubidium@9511: truelight@9680: /** truelight@9680: * Get the pointer to store event data in. truelight@9680: */ truelight@9682: static void *&GetEventPointer(); truelight@9680: truelight@9454: public: truelight@9454: /** truebrain@9760: * Store the latest result of a DoCommand per player. truebrain@9760: * @note NEVER use this yourself in your AI! truebrain@9841: * @param res The result of the last command. truebrain@9760: */ truebrain@9760: static void SetLastCommandRes(bool res); truebrain@9760: truebrain@9760: /** truelight@9496: * Store a new_vehicle_id per player. truelight@9496: * @note NEVER use this yourself in your AI! truebrain@9841: * @param vehicle_id The new VehicleID. truelight@9496: */ truebrain@9841: static void SetNewVehicleID(VehicleID vehicle_id); truelight@9496: truelight@9496: /** rubidium@9511: * Store a new_sign_id per player. rubidium@9511: * @note NEVER use this yourself in your AI! truebrain@9841: * @param sign_id The new SignID. rubidium@9511: */ truebrain@9841: static void SetNewSignID(SignID sign_id); rubidium@9511: rubidium@9511: /** truelight@9454: * If an AI starts, some internals needs to be resetted. This function truelight@9454: * takes care of that. truelight@9496: * @note NEVER use this yourself in your AI! truelight@9454: */ truelight@9454: static void ResetInternalPlayerData(); truebrain@9851: truebrain@9851: /** truebrain@9851: * Get the pointer to store log message in. truebrain@9851: * @note NEVER use this yourself in your AI! truebrain@9851: */ truebrain@9851: static void *&GetLogPointer(); truelight@9361: }; truelight@9361: truelight@9361: #endif /* AI_OBJECT_HPP */