src/ai/api/ai_cargo.hpp
author rubidium
Sat, 14 Apr 2007 20:38:10 +0000
branchnoai
changeset 9594 5009a30f320a
parent 9541 4bb34cea7fad
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.
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
     1
/* $Id$ */
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
     2
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
     3
/** @file ai_cargo.hpp Everything to query about cargos */
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
     4
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
     5
#ifndef AI_CARGO_HPP
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
     6
#define AI_CARGO_HPP
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
     7
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
     8
#include "ai_object.hpp"
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
     9
9447
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    10
/**
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    11
 * Class that handles all cargo related functions.
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    12
 */
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    13
class AICargo : public AIObject {
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    14
public:
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
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 "AICargo"; }
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
	/**
9472
063c3f50972a (svn r9312) [NoAI] -Codechange: add IsValidCargo.
rubidium
parents: 9447
diff changeset
    21
	 * Checks whether the given cargo type is valid.
063c3f50972a (svn r9312) [NoAI] -Codechange: add IsValidCargo.
rubidium
parents: 9447
diff changeset
    22
	 * @param cargo_type the cargo to check.
063c3f50972a (svn r9312) [NoAI] -Codechange: add IsValidCargo.
rubidium
parents: 9447
diff changeset
    23
	 * @return true if and only if the cargo type is valid.
063c3f50972a (svn r9312) [NoAI] -Codechange: add IsValidCargo.
rubidium
parents: 9447
diff changeset
    24
	 */
9490
999eb7531205 (svn r9360) [NoAI] -Add: class-functions can now be static and still be added to SQ. There they behave as they are non-static, which is fine for that level of coding.
truelight
parents: 9472
diff changeset
    25
	static bool IsValidCargo(CargoID cargo_type);
9472
063c3f50972a (svn r9312) [NoAI] -Codechange: add IsValidCargo.
rubidium
parents: 9447
diff changeset
    26
063c3f50972a (svn r9312) [NoAI] -Codechange: add IsValidCargo.
rubidium
parents: 9447
diff changeset
    27
	/**
9447
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    28
	 * Gets the string representation of the cargo label.
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    29
	 * @param cargo_type to get the string representation of.
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    30
	 * @return the cargo label.
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    31
	 * @note the returned cargo label must be free'd (C++ only).
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    32
	 */
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    33
	char *GetCargoLabel(CargoID cargo_type);
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    34
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    35
	/**
9447
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    36
	 * Checks whether the give cargo is a freight or not.
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    37
	 * @param cargo_type is this cargo freight or not?
9447
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    38
	 * @return true if and only if the cargo is freight.
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    39
	 */
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    40
	bool IsFreight(CargoID cargo_type);
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    41
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    42
	/**
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    43
	 * Get the income for transporting a piece of cargo over the
9447
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    44
	 *   given distance within the specified time.
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    45
	 * @param distance the distance the cargo travels from begin to end.
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    46
	 * @param days_in_transit amount of (game) days the cargo is in transit.
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    47
	 * @param cargo_type the cargo to transport.
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9427
diff changeset
    48
	 * @return the amount of money that would be earned by this trip.
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    49
	 */
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    50
	int32 GetCargoIncome(uint32 distance, uint32 days_in_transit, CargoID cargo_type);
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    51
};
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    52
9425
8eec6d10844a (svn r9227) [NoAI] -Change: renamed SQUIRREL_CLASS to DEFINE_SQUIRREL_CLASS
truelight
parents: 9422
diff changeset
    53
#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
    54
namespace SQConvert {
283d23931bb4 (svn r9444) [NoAI] -Codechange: allow all API-class-instances to be used as parameters in Squirrel.
rubidium
parents: 9520
diff changeset
    55
	/* Allow AICargo to be used as Squirrel parameter */
9594
5009a30f320a (svn r9627) [NoAI] -Fix: let the squirrel export script export all needed (and a few more) types of references to structs and classes.
rubidium
parents: 9541
diff changeset
    56
	template <> AICargo *GetParam(ForceType<AICargo *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AICargo *)instance; }
5009a30f320a (svn r9627) [NoAI] -Fix: let the squirrel export script export all needed (and a few more) types of references to structs and classes.
rubidium
parents: 9541
diff changeset
    57
	template <> AICargo &GetParam(ForceType<AICargo &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AICargo *)instance; }
5009a30f320a (svn r9627) [NoAI] -Fix: let the squirrel export script export all needed (and a few more) types of references to structs and classes.
rubidium
parents: 9541
diff changeset
    58
	template <> const AICargo *GetParam(ForceType<const AICargo *>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return  (AICargo *)instance; }
5009a30f320a (svn r9627) [NoAI] -Fix: let the squirrel export script export all needed (and a few more) types of references to structs and classes.
rubidium
parents: 9541
diff changeset
    59
	template <> const AICargo &GetParam(ForceType<const AICargo &>, HSQUIRRELVM vm, int index) { SQUserPointer instance; sq_getinstanceup(vm, index, &instance, 0); return *(AICargo *)instance; }
9524
283d23931bb4 (svn r9444) [NoAI] -Codechange: allow all API-class-instances to be used as parameters in Squirrel.
rubidium
parents: 9520
diff changeset
    60
}; // namespace SQConvert
283d23931bb4 (svn r9444) [NoAI] -Codechange: allow all API-class-instances to be used as parameters in Squirrel.
rubidium
parents: 9520
diff changeset
    61
9422
33efcc5f1b09 (svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents: 9405
diff changeset
    62
void SQAICargoRegister(Squirrel *engine) {
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    63
	DefSQClass <AICargo> SQAICargo("AICargo");
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    64
	SQAICargo.PreRegister(engine);
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    65
	SQAICargo.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
    66
9541
4bb34cea7fad (svn r9463) [NoAI] -Codechange: update squirrel export script to generate the correct amount and type of parameters, so that can be checked.
rubidium
parents: 9532
diff changeset
    67
	SQAICargo.DefSQStaticMethod(engine, &AICargo::GetClassName, "GetClassName", 1, "x");
4bb34cea7fad (svn r9463) [NoAI] -Codechange: update squirrel export script to generate the correct amount and type of parameters, so that can be checked.
rubidium
parents: 9532
diff changeset
    68
	SQAICargo.DefSQStaticMethod(engine, &AICargo::IsValidCargo, "IsValidCargo", 2, "xi");
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
    69
9541
4bb34cea7fad (svn r9463) [NoAI] -Codechange: update squirrel export script to generate the correct amount and type of parameters, so that can be checked.
rubidium
parents: 9532
diff changeset
    70
	SQAICargo.DefSQMethod(engine, &AICargo::GetCargoLabel,  "GetCargoLabel",  2, "xi");
4bb34cea7fad (svn r9463) [NoAI] -Codechange: update squirrel export script to generate the correct amount and type of parameters, so that can be checked.
rubidium
parents: 9532
diff changeset
    71
	SQAICargo.DefSQMethod(engine, &AICargo::IsFreight,      "IsFreight",      2, "xi");
4bb34cea7fad (svn r9463) [NoAI] -Codechange: update squirrel export script to generate the correct amount and type of parameters, so that can be checked.
rubidium
parents: 9532
diff changeset
    72
	SQAICargo.DefSQMethod(engine, &AICargo::GetCargoIncome, "GetCargoIncome", 4, "xiii");
9526
a4ad60ba03be (svn r9446) [NoAI] -Add: simple script to make changing/adding classes to export a little simpler.
rubidium
parents: 9524
diff changeset
    73
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    74
	SQAICargo.PostRegister(engine);
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    75
}
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: 9490
diff changeset
    76
#endif /* DEFINE_SQUIRREL_CLASS */
9405
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    77
df6f3b4b0038 (svn r9202) [NoAI] -Add: some initial functions for cargo and industries.
rubidium
parents:
diff changeset
    78
#endif /* AI_CARGO_HPP */