src/ai/api/ai_town.hpp
author rubidium
Sun, 25 Mar 2007 17:43:40 +0000
branchnoai
changeset 9532 539c48d64eea
parent 9530 5b93bc87cc5e
child 9541 4bb34cea7fad
permissions -rw-r--r--
(svn r9453) [NoAI] -Codechange: make a difference between static and non-static methods in the squirrel export script.
9380
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
     1
/* $Id$ */
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
     2
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
     3
/** @file ai_town.hpp Everything to query towns */
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
     4
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
     5
#ifndef AI_TOWN_HPP
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
     6
#define AI_TOWN_HPP
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
     7
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
     8
#include "ai_object.hpp"
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
     9
9448
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    10
/**
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    11
 * Class that handles all town related functions.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    12
 */
9380
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    13
class AITown : public AIObject {
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    14
public:
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    15
	/**
9529
5f26f4bc574b (svn r9450) [NoAI] -Fix: don't allow static-method calls from SQ to non-static functions
truelight
parents: 9526
diff changeset
    16
	 * The name of the class, needed by several sub-processes.
5f26f4bc574b (svn r9450) [NoAI] -Fix: don't allow static-method calls from SQ to non-static functions
truelight
parents: 9526
diff changeset
    17
	 */
5f26f4bc574b (svn r9450) [NoAI] -Fix: don't allow static-method calls from SQ to non-static functions
truelight
parents: 9526
diff changeset
    18
	static const char *GetClassName() { return "AITown"; }
5f26f4bc574b (svn r9450) [NoAI] -Fix: don't allow static-method calls from SQ to non-static functions
truelight
parents: 9526
diff changeset
    19
5f26f4bc574b (svn r9450) [NoAI] -Fix: don't allow static-method calls from SQ to non-static functions
truelight
parents: 9526
diff changeset
    20
	/**
9448
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    21
	 * Gets the maximum town index; there are no valid towns with a higher index.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    22
	 * @return the maximum town index.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    23
	 * @post return value is always non-negative.
9380
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    24
	 */
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    25
	TownID GetMaxTownID();
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    26
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    27
	/**
9448
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    28
	 * Gets the number of towns. This is different than GetMaxTownID()
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    29
	 *   because of the way OpenTTD works internally.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    30
	 * @return the number of towns.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    31
	 * @post return value is always non-negative.
9380
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    32
	 */
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    33
	int32 GetTownCount();
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    34
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    35
	/**
9448
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    36
	 * Checks whether the given town index is valid.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    37
	 * @param town_id the index to check.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    38
	 * @return true if and only if the town is valid.
9380
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    39
	 */
9497
f6678533ccba (svn r9369) [NoAI] -Codechange: make some IsValidXXX() function static, so they can be used by the other classes without the need for an instance.
rubidium
parents: 9448
diff changeset
    40
	static bool IsValidTown(TownID town_id);
9380
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    41
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    42
	/**
9448
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    43
	 * Get the name of the town.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    44
	 * @param town_id the town to get the name of.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    45
	 * @pre town_id has to be valid (use IsValidTown()).
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    46
	 * @return the name of the town.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    47
	 * @note the returned name must be free'd (C++ only).
9380
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    48
	 */
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    49
	char *GetName(TownID town_id);
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    50
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    51
	/**
9448
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    52
	 * Gets the number of inhabitants in the town.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    53
	 * @param town_id the town to get the name of.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    54
	 * @pre town_id has to be valid (use IsValidTown()).
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    55
	 * @return the number of inhabitants.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    56
	 * @post return value is always non-negative.
9380
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    57
	 */
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    58
	int32 GetPopulation(TownID town_id);
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    59
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    60
	/**
9448
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    61
	 * Gets the location of the town.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    62
	 * @param town_id the location of the town.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    63
	 * @pre town_id has to be valid (use IsValidTown()).
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    64
	 * @return the location of the town.
2a4c4340233d (svn r9273) [NoAI] -Documentation: finished documenting the last few files; they should now be readable for any non-programmer.
truelight
parents: 9427
diff changeset
    65
	 * @post return value is always positive and below AIMap::GetMapSize().
9380
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    66
	 */
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    67
	TileIndex GetLocation(TownID town_id);
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    68
};
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    69
9425
8eec6d10844a (svn r9227) [NoAI] -Change: renamed SQUIRREL_CLASS to DEFINE_SQUIRREL_CLASS
truelight
parents: 9422
diff changeset
    70
#ifdef DEFINE_SQUIRREL_CLASS
9524
283d23931bb4 (svn r9444) [NoAI] -Codechange: allow all API-class-instances to be used as parameters in Squirrel.
rubidium
parents: 9520
diff changeset
    71
namespace SQConvert {
283d23931bb4 (svn r9444) [NoAI] -Codechange: allow all API-class-instances to be used as parameters in Squirrel.
rubidium
parents: 9520
diff changeset
    72
	/* Allow AITown to be used as Squirrel parameter */
283d23931bb4 (svn r9444) [NoAI] -Codechange: allow all API-class-instances to be used as parameters in Squirrel.
rubidium
parents: 9520
diff changeset
    73
	template <> AITown *GetParam(ForceType<AITown *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return (AITown *)instance; }
283d23931bb4 (svn r9444) [NoAI] -Codechange: allow all API-class-instances to be used as parameters in Squirrel.
rubidium
parents: 9520
diff changeset
    74
}; // namespace SQConvert
283d23931bb4 (svn r9444) [NoAI] -Codechange: allow all API-class-instances to be used as parameters in Squirrel.
rubidium
parents: 9520
diff changeset
    75
9422
33efcc5f1b09 (svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents: 9405
diff changeset
    76
void SQAITownRegister(Squirrel *engine) {
9387
4255a0a2d272 (svn r9179) [NoAI] -Add: added templates that makes adding classes to squirrel very easy
truelight
parents: 9380
diff changeset
    77
	DefSQClass <AITown> SQAITown("AITown");
9397
d8f8db9c1a2e (svn r9189) [NoAI] -Cleanup: cleaned up DefSQClass a bit by using the SquirrelEngine
truelight
parents: 9387
diff changeset
    78
	SQAITown.PreRegister(engine);
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9397
diff changeset
    79
	SQAITown.AddConstructor(engine);
9526
a4ad60ba03be (svn r9446) [NoAI] -Add: simple script to make changing/adding classes to export a little simpler.
rubidium
parents: 9524
diff changeset
    80
9532
539c48d64eea (svn r9453) [NoAI] -Codechange: make a difference between static and non-static methods in the squirrel export script.
rubidium
parents: 9530
diff changeset
    81
	SQAITown.DefSQStaticMethod(engine, &AITown::GetClassName, "GetClassName");
539c48d64eea (svn r9453) [NoAI] -Codechange: make a difference between static and non-static methods in the squirrel export script.
rubidium
parents: 9530
diff changeset
    82
	SQAITown.DefSQStaticMethod(engine, &AITown::IsValidTown,  "IsValidTown");
539c48d64eea (svn r9453) [NoAI] -Codechange: make a difference between static and non-static methods in the squirrel export script.
rubidium
parents: 9530
diff changeset
    83
9530
5b93bc87cc5e (svn r9451) [NoAI] -Add: allow static and non-static members for SQ
truelight
parents: 9529
diff changeset
    84
	SQAITown.DefSQMethod(engine, &AITown::GetMaxTownID,  "GetMaxTownID");
5b93bc87cc5e (svn r9451) [NoAI] -Add: allow static and non-static members for SQ
truelight
parents: 9529
diff changeset
    85
	SQAITown.DefSQMethod(engine, &AITown::GetTownCount,  "GetTownCount");
5b93bc87cc5e (svn r9451) [NoAI] -Add: allow static and non-static members for SQ
truelight
parents: 9529
diff changeset
    86
	SQAITown.DefSQMethod(engine, &AITown::GetName,       "GetName");
5b93bc87cc5e (svn r9451) [NoAI] -Add: allow static and non-static members for SQ
truelight
parents: 9529
diff changeset
    87
	SQAITown.DefSQMethod(engine, &AITown::GetPopulation, "GetPopulation");
5b93bc87cc5e (svn r9451) [NoAI] -Add: allow static and non-static members for SQ
truelight
parents: 9529
diff changeset
    88
	SQAITown.DefSQMethod(engine, &AITown::GetLocation,   "GetLocation");
9526
a4ad60ba03be (svn r9446) [NoAI] -Add: simple script to make changing/adding classes to export a little simpler.
rubidium
parents: 9524
diff changeset
    89
9397
d8f8db9c1a2e (svn r9189) [NoAI] -Cleanup: cleaned up DefSQClass a bit by using the SquirrelEngine
truelight
parents: 9387
diff changeset
    90
	SQAITown.PostRegister(engine);
9387
4255a0a2d272 (svn r9179) [NoAI] -Add: added templates that makes adding classes to squirrel very easy
truelight
parents: 9380
diff changeset
    91
}
9520
f7cf8bea10db (svn r9440) [NoAI] -Codechange: use the identifier used for the #ifdef in the #endif not something that looks like the identifier.
rubidium
parents: 9497
diff changeset
    92
#endif /* DEFINE_SQUIRREL_CLASS */
9387
4255a0a2d272 (svn r9179) [NoAI] -Add: added templates that makes adding classes to squirrel very easy
truelight
parents: 9380
diff changeset
    93
9380
f4c7eb98b43d (svn r9169) [NoAI] -Add: some wrapper functions for town related queries.
rubidium
parents:
diff changeset
    94
#endif /* AI_TOWN_HPP */