src/ai/api/ai_cargo.hpp
author rubidium
Sun, 25 Mar 2007 22:21:12 +0000
branchnoai
changeset 9541 4bb34cea7fad
parent 9532 539c48d64eea
child 9594 5009a30f320a
permissions -rw-r--r--
(svn r9463) [NoAI] -Codechange: update squirrel export script to generate the correct amount and type of parameters, so that can be checked.
/* $Id$ */

/** @file ai_cargo.hpp Everything to query about cargos */

#ifndef AI_CARGO_HPP
#define AI_CARGO_HPP

#include "ai_object.hpp"

/**
 * Class that handles all cargo related functions.
 */
class AICargo : public AIObject {
public:
	/**
	 * The name of the class, needed by several sub-processes.
	 */
	static const char *GetClassName() { return "AICargo"; }

	/**
	 * Checks whether the given cargo type is valid.
	 * @param cargo_type the cargo to check.
	 * @return true if and only if the cargo type is valid.
	 */
	static bool IsValidCargo(CargoID cargo_type);

	/**
	 * Gets the string representation of the cargo label.
	 * @param cargo_type to get the string representation of.
	 * @return the cargo label.
	 * @note the returned cargo label must be free'd (C++ only).
	 */
	char *GetCargoLabel(CargoID cargo_type);

	/**
	 * Checks whether the give cargo is a freight or not.
	 * @param cargo_type is this cargo freight or not?
	 * @return true if and only if the cargo is freight.
	 */
	bool IsFreight(CargoID cargo_type);

	/**
	 * Get the income for transporting a piece of cargo over the
	 *   given distance within the specified time.
	 * @param distance the distance the cargo travels from begin to end.
	 * @param days_in_transit amount of (game) days the cargo is in transit.
	 * @param cargo_type the cargo to transport.
	 * @return the amount of money that would be earned by this trip.
	 */
	int32 GetCargoIncome(uint32 distance, uint32 days_in_transit, CargoID cargo_type);
};

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

void SQAICargoRegister(Squirrel *engine) {
	DefSQClass <AICargo> SQAICargo("AICargo");
	SQAICargo.PreRegister(engine);
	SQAICargo.AddConstructor(engine);

	SQAICargo.DefSQStaticMethod(engine, &AICargo::GetClassName, "GetClassName", 1, "x");
	SQAICargo.DefSQStaticMethod(engine, &AICargo::IsValidCargo, "IsValidCargo", 2, "xi");

	SQAICargo.DefSQMethod(engine, &AICargo::GetCargoLabel,  "GetCargoLabel",  2, "xi");
	SQAICargo.DefSQMethod(engine, &AICargo::IsFreight,      "IsFreight",      2, "xi");
	SQAICargo.DefSQMethod(engine, &AICargo::GetCargoIncome, "GetCargoIncome", 4, "xiii");

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

#endif /* AI_CARGO_HPP */