src/ai/api/ai_base.hpp
author truelight
Sun, 18 Mar 2007 18:02:27 +0000
branchnoai
changeset 9452 4c5eedbc3ba9
parent 9447 8f3c1bc72204
child 9520 f7cf8bea10db
permissions -rw-r--r--
(svn r9282) [NoAI] -Add: added AIAccounting, which tracks the cost of your buying/selling.
DoCommand no longer returns the cost, it returns a bool.
Costs are available via this Accounting class.
/* $Id$ */

/** @file ai_base.hpp declaration of class for AIBase class */

#ifndef AI_BASE_HPP
#define AI_BASE_HPP

#include "ai_object.hpp"

/**
 * Class that handles some basic functions.
 *
 * @note The random functions are not called Random and RandomRange, because
 *       when including them the RANDOM_DEBUG stuff messes with their names.
 *       However, because in MP we cannot use Random because that will cause
 *       desyncs (AIs are ran locally, not on all clients). This means that
 *       we use InteractiveRandom in MP, thus the whole random debugging is
 *       pointless for the AIs. Therefor the random functions are called
 *       differently.
 */
class AIBase : public AIObject {
public:
	/**
	 * Get a random value.
	 * @return a random value between 0 and MAX(uint32).
	 */
	uint32 Rand();

	/**
	 * Get a random value in a range.
	 * @param max the maximum value it will return.
	 * @return a random value between 0 .. max.
	 */
	uint RandRange(uint max);

	/**
	 * Returns approximatelly 'out' times true when called 'max' times.
	 *   After all, it is a random function.
	 * @return true if the chance worked out.
	 */
	bool Chance(uint out, uint max);
};

#ifdef DEFINE_SQUIRREL_CLASS
void SQAIBaseRegister(Squirrel *engine) {
	DefSQClass <AIBase> SQAIBase("AIBase");
	SQAIBase.PreRegister(engine);
	SQAIBase.AddConstructor(engine);
	SQAIBase.DefSQFunction(engine, &AIBase::Rand,      "Rand");
	SQAIBase.DefSQFunction(engine, &AIBase::RandRange, "RandRange");
	SQAIBase.DefSQFunction(engine, &AIBase::Chance,    "Chance");
	SQAIBase.PostRegister(engine);
}
#endif /* SQUIRREL_CLASS */

#endif /* AI_BASE_HPP */