src/ai/api/ai_sign.hpp
author rubidium
Sat, 14 Apr 2007 20:38:10 +0000
branchnoai
changeset 9594 5009a30f320a
parent 9562 2f4087d63527
child 9596 8af5a1399842
permissions -rw-r--r--
(svn r9627) [NoAI] -Fix: let the squirrel export script export all needed (and a few more) types of references to structs and classes.
/* $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 sign related functions.
 */
class AISign : public AIObject {
public:
	/**
	 * The name of the class, needed by several sub-processes.
	 */
	static const char *GetClassName() { return "AISign"; }

	/**
	 * Gets the maximum sign index; there are no valid signs with a higher index.
	 * @return the maximum sign index.
	 * @post return value is always non-negative.
	 */
	SignID GetMaxSignID();

	/**
	 * Gets the number of signs. This is different than GetMaxSignID()
	 *   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).
	 *   In test-mode it returns 0 if successful, or any other value to indicate
	 *   failure.
	 */
	SignID BuildSign(TileIndex location, const char *text);
};

#ifdef DEFINE_SQUIRREL_CLASS
namespace SQConvert {
	/* Allow AISign to be used as Squirrel parameter */
	template <> AISign *GetParam(ForceType<AISign *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AISign *)instance; }
	template <> AISign &GetParam(ForceType<AISign &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AISign *)instance; }
	template <> const AISign *GetParam(ForceType<const AISign *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AISign *)instance; }
	template <> const AISign &GetParam(ForceType<const AISign &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AISign *)instance; }
}; // namespace SQConvert

void SQAISignRegister(Squirrel *engine) {
	DefSQClass <AISign> SQAISign("AISign");
	SQAISign.PreRegister(engine);
	SQAISign.AddConstructor(engine);

	SQAISign.DefSQStaticMethod(engine, &AISign::GetClassName, "GetClassName", 1, "x");
	SQAISign.DefSQStaticMethod(engine, &AISign::IsValidSign,  "IsValidSign",  2, "xi");

	SQAISign.DefSQMethod(engine, &AISign::GetMaxSignID, "GetMaxSignID", 1, "x");
	SQAISign.DefSQMethod(engine, &AISign::GetSignCount, "GetSignCount", 1, "x");
	SQAISign.DefSQMethod(engine, &AISign::GetText,      "GetText",      2, "xi");
	SQAISign.DefSQMethod(engine, &AISign::GetLocation,  "GetLocation",  2, "xi");
	SQAISign.DefSQMethod(engine, &AISign::RemoveSign,   "RemoveSign",   2, "xi");
	SQAISign.DefSQMethod(engine, &AISign::BuildSign,    "BuildSign",    3, "xis");

	SQAISign.PostRegister(engine);
}
#endif /* DEFINE_SQUIRREL_CLASS */

#endif /* AI_SIGN_HPP */