src/ai/api/ai_object.hpp
author rubidium
Sun, 25 Mar 2007 13:50:19 +0000
branchnoai
changeset 9524 283d23931bb4
parent 9511 f767ad06e86b
child 9629 66dde6412125
permissions -rw-r--r--
(svn r9444) [NoAI] -Codechange: allow all API-class-instances to be used as parameters in Squirrel.
/* $Id$ */

/** @file ai_object.hpp declaration of class for AIObject class */

#ifndef AI_OBJECT_HPP
#define AI_OBJECT_HPP

#include "../../stdafx.h"
#include "../../functions.h"

/**
 * The callback function for Mode-classes.
 */
typedef bool (AIModeProc)(TileIndex tile, uint32 p1, uint32 p2, uint procc, int32 costs);

/**
 * Uper-parent object of all API classes. You should never use this class in
 *   your AI, as it doesn't publish any public functions. It is used
 *   internally to have a common place to handle general things, like internal
 *   command processing, and command-validation checks.
 */
class AIObject {
private:
	struct AIDoCommandStruct {
		AIModeProc *mode;
		AIObject *mode_instance;
		uint delay;
		int32 costs;
		VehicleID new_vehicle_id;
		SignID new_sign_id;
	};

	/**
	 * The current mode of the AI players.
	 */
	static AIDoCommandStruct *GetDoCommandStruct(PlayerID player);

protected:
	/**
	 * Executes a raw DoCommand for the AI.
	 */
	static bool DoCommand(TileIndex tile, uint32 p1, uint32 p2, uint procc);

	/**
	 * Sets the DoCommand costs counter to a value.
	 */
	static void SetDoCommandCosts(int32 value);

	/**
	 * Increase the current value of the DoCommand costs counter.
	 */
	static void IncreaseDoCommandCosts(int32 value);

	/**
	 * Get the current DoCommand costs counter.
	 */
	static int32 GetDoCommandCosts();

	/**
	 * Set the current mode of your AI to this proc.
	 */
	static void SetDoCommandMode(AIModeProc *proc, AIObject *instance);

	/**
	 * Get the current mode your AI is currently under.
	 */
	static AIModeProc *GetDoCommandMode();

	/**
	 * Get the instance of the current mode your AI is currently under.
	 */
	static AIObject *GetDoCommandModeInstance();

	/**
	 * Set the delay of the DoCommand.
	 */
	static void SetDoCommandDelay(uint ticks);

	/**
	 * Get the delay of the DoCommand.
	 */
	static uint GetDoCommandDelay();

	/**
	 * Get the latest stored new_vehicle_id.
	 */
	static VehicleID GetNewVehicleID();

	/**
	 * Get the latest stored new_sign_id.
	 */
	static SignID GetNewSignID();

public:
	/**
	 * Store a new_vehicle_id per player.
	 * @note NEVER use this yourself in your AI!
	 */
	static void SetNewVehicleID(VehicleID vehicle);

	/**
	 * Store a new_sign_id per player.
	 * @note NEVER use this yourself in your AI!
	 */
	static void SetNewSignID(SignID vehicle);

	/**
	 * If an AI starts, some internals needs to be resetted. This function
	 *   takes care of that.
	 * @note NEVER use this yourself in your AI!
	 */
	static void ResetInternalPlayerData();
};

#endif /* AI_OBJECT_HPP */