src/ai/api/ai_sign.hpp
author rubidium
Thu, 22 Mar 2007 09:52:12 +0000
branchnoai
changeset 9511 f767ad06e86b
child 9513 258f78c74b0c
permissions -rw-r--r--
(svn r9407) [NoAI] -Add: placing of signs.
/* $Id$ */

/** @file ai_sign.hpp Everything to query and build signs */

#ifndef AI_SIGN_HPP
#define AI_SIGN_HPP

#include "ai_object.hpp"

/**
 * Class that handles all town related functions.
 */
class AISign : public AIObject {
public:
	/**
	 * Gets the maximum sign index; there are no valid signs with a higher index.
	 * @return the maximum town index.
	 * @post return value is always non-negative.
	 */
	SignID GetMaxSignID();

	/**
	 * Gets the number of signs. This is different than GetSignTownID()
	 *   because of the way OpenTTD works internally.
	 * @return the number of signs.
	 * @post return value is always non-negative.
	 */
	int32 GetSignCount();

	/**
	 * Checks whether the given sign index is valid.
	 * @param sign_id the index to check.
	 * @return true if and only if the sign is valid.
	 */
	static bool IsValidSign(SignID sign_id);

	/**
	 * Get the text on the sign.
	 * @param sign_id the sign to get the text of.
	 * @pre sign_id has to be valid (use IsValidSign()).
	 * @return the text on the sign.
	 * @note the returned name must be free'd (C++ only).
	 */
	char *GetText(SignID sign_id);

	/**
	 * Gets the location of the sign.
	 * @param sign_id the sign to get the location of.
	 * @pre sign_id has to be valid (use IsValidSign()).
	 * @return the location of the sign.
	 * @post return value is always positive and below AIMap::GetMapSize().
	 */
	TileIndex GetLocation(SignID sign_id);

	/**
	 * Removes a sign from the map.
	 * @param sign_id the sign to remove.
	 * @pre sign_id has to be valid (use IsValidSign()).
	 * @return true if and only if the sign has been removed.
	 */
	bool RemoveSign(SignID sign_id);

	/**
	 * Builds a sign on the map.
	 * @param location the place to build the sign.
	 * @param text     the text to place on the sign.
	 * @pre location is always positive and below AIMap::GetMapSize()
	 * @pre text is not NULL and non-empty, i.e. length is positive.
	 * @return the SignID of the build sign (use IsValidSign() to check for validity).
	 */
	SignID BuildSign(TileIndex location, const char *text);
};

#ifdef DEFINE_SQUIRREL_CLASS
void SQAISignRegister(Squirrel *engine) {
	DefSQClass <AISign> SQAISign("AISign");
	SQAISign.PreRegister(engine);
	SQAISign.AddConstructor(engine);
	SQAISign.DefSQFunction(engine, &AISign::GetMaxSignID, "GetMaxSignID");
	SQAISign.DefSQFunction(engine, &AISign::GetSignCount, "GetSignCount");
	SQAISign.DefSQFunction(engine, &AISign::IsValidSign,  "IsValidSign");
	SQAISign.DefSQFunction(engine, &AISign::GetText,      "GetText");
	SQAISign.DefSQFunction(engine, &AISign::GetLocation,  "GetLocation");
	SQAISign.DefSQFunction(engine, &AISign::RemoveSign,   "RemoveSign");
	SQAISign.DefSQFunction(engine, &AISign::BuildSign,    "BuildSign");
	SQAISign.PostRegister(engine);
}
#endif /* SQUIRREL_CLASS */

#endif /* AI_SIGN_HPP */