src/ai/api/ai_object.hpp
author truelight
Sun, 18 Mar 2007 18:37:45 +0000
branchnoai
changeset 9454 ee6a65b37b82
parent 9452 4c5eedbc3ba9
child 9473 dcbcd1c4496d
permissions -rw-r--r--
(svn r9284) [NoAI] -Fix: reset internal static AIObject data per AI on AI startup
/* $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"

typedef bool (AIModeProc)(TileIndex tile, uint32 p1, uint32 p2, uint32 flags, uint procc);

/**
 * 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;
		uint delay;
		int32 costs;
	};

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

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

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

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

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

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

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

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

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

public:
	/**
	 * If an AI starts, some internals needs to be resetted. This function
	 *   takes care of that.
	 */
	static void ResetInternalPlayerData();
};

#endif /* AI_OBJECT_HPP */