truelight@9361: /* $Id$ */ truelight@9361: truebrain@9829: /** @file ai_controller.hpp The controller of the AI. */ truelight@9361: truelight@9361: #ifndef AI_CONTROLLER_HPP truelight@9361: #define AI_CONTROLLER_HPP truelight@9361: truelight@9361: #include "../../stdafx.h" truelight@9361: truelight@9448: /** truelight@9448: * Class that handles the core of every AI. Each AI needs to extend this class truelight@9448: * in order to work. The OpenTTD core makes sure GetTick gets increased when truelight@9448: * needed. truelight@9448: */ truelight@9361: class AIController { truelight@9372: private: truelight@9361: uint tick; truelight@9361: truelight@9372: public: truelight@9448: /** truelight@9448: * Initializer of the AIController. truelight@9448: */ truelight@9361: AIController() : truelight@9361: tick(0) truelight@9361: {} truelight@9361: truelight@9448: /** truelight@9448: * Destructor of the AIController. truelight@9448: */ truelight@9361: virtual ~AIController() { } truelight@9361: truelight@9361: /** truelight@9448: * This function is called to start your AI. Your AI starts here. If you truelight@9448: * return from this function, your AI dies, so make sure that doesn't truelight@9448: * happen. It is okay to use while() {} loops, as long as you put a truelight@9448: * Sleep() in it to give the rest of the game time to do things. Also truelight@9448: * don't keep the system busy for too long, as people will consider truelight@9448: * that annoying. truelight@9448: * @note Cannot be called from within your AI. truelight@9361: */ truelight@9441: virtual void Start() = 0; truelight@9361: truelight@9361: /** truelight@9448: * When this function is called, the AI must stop as soon as possible. truelight@9448: * It may not call any function that might suspend, like DoCommand() truelight@9448: * and Sleep(). truelight@9448: * @note Cannot be called from within your AI. rubidium@9444: */ rubidium@9444: virtual void Stop() = 0; rubidium@9444: rubidium@9444: /** truelight@9448: * Increase the internal ticker. You should never call this yourself, truelight@9448: * as it is called by the OpenTTD system itself. truelight@9448: * @note Cannot be called from within your AI. truelight@9361: */ truelight@9361: void IncreaseTick() { this->tick++; } truelight@9372: truelight@9372: /** truelight@9448: * Find at which tick your AI currently is. truelight@9448: * @return returns the current tick. truelight@9372: */ truelight@9372: uint GetTick() { return this->tick; } truelight@9441: truelight@9441: /** truelight@9441: * Sleep for X ticks. The code continues after this line when the X AI ticks truelight@9448: * are passed. Mind that an AI tick is different from in-game ticks and truelight@9448: * differ per AI speed. truelight@9448: * @param ticks the ticks to wait truelight@9448: * @post the value of GetTick() will be changed exactly 'ticks' in value after truelight@9448: * calling this. truelight@9441: */ truebrain@9782: static void Sleep(uint ticks); truebrain@9782: truebrain@9782: /** truebrain@9851: * When Squirrel triggers a print, this function is called. truebrain@9851: * Squirrel calls this when 'print' is used, or when the script made an error. truebrain@9851: * @param error_msg If true, it is a Squirrel error message. truebrain@9851: * @param message The message Squirrel logged. truebrain@9851: * @note Use AILog.Info/Warning/Error instead of 'print'. truebrain@9782: */ truebrain@9782: static void Print(bool error_msg, const char *message); truelight@9361: }; truelight@9361: rubidium@9439: #endif /* AI_CONTROLLER_HPP */