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.
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     1
/* $Id$ */
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     2
9388
032008c3f6e3 (svn r9180) [NoAI] -Fix: copy/pasting can be nasty: wrong @file headers
truelight
parents: 9387
diff changeset
     3
/** @file ai_base.hpp declaration of class for AIBase class */
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     4
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     5
#ifndef AI_BASE_HPP
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     6
#define AI_BASE_HPP
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     7
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents: 9360
diff changeset
     8
#include "ai_object.hpp"
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
     9
9440
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    10
/**
9447
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9440
diff changeset
    11
 * Class that handles some basic functions.
9440
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    12
 *
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    13
 * @note The random functions are not called Random and RandomRange, because
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    14
 *       when including them the RANDOM_DEBUG stuff messes with their names.
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    15
 *       However, because in MP we cannot use Random because that will cause
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    16
 *       desyncs (AIs are ran locally, not on all clients). This means that
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    17
 *       we use InteractiveRandom in MP, thus the whole random debugging is
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    18
 *       pointless for the AIs. Therefor the random functions are called
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    19
 *       differently.
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    20
 */
9436
e28503f827a5 (svn r9247) [NoAI] -Fix: some small coding-style/double inclusion issues.
rubidium
parents: 9427
diff changeset
    21
class AIBase : public AIObject {
9361
7bb2bd22b16e (svn r9144) [NoAI] -Change: moved command functions to AIObject, and made AIBase depend on AIObject
truelight
parents: 9360
diff changeset
    22
public:
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    23
	/**
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    24
	 * Get a random value.
9447
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9440
diff changeset
    25
	 * @return a random value between 0 and MAX(uint32).
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    26
	 */
9440
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    27
	uint32 Rand();
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    28
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    29
	/**
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    30
	 * Get a random value in a range.
9447
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9440
diff changeset
    31
	 * @param max the maximum value it will return.
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9440
diff changeset
    32
	 * @return a random value between 0 .. max.
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    33
	 */
9440
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    34
	uint RandRange(uint max);
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    35
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    36
	/**
9447
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9440
diff changeset
    37
	 * Returns approximatelly 'out' times true when called 'max' times.
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9440
diff changeset
    38
	 *   After all, it is a random function.
8f3c1bc72204 (svn r9272) [NoAI] -Documentation: made the documentation of the first 3 API files more readable for non-programmers
truelight
parents: 9440
diff changeset
    39
	 * @return true if the chance worked out.
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    40
	 */
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    41
	bool Chance(uint out, uint max);
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    42
};
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    43
9425
8eec6d10844a (svn r9227) [NoAI] -Change: renamed SQUIRREL_CLASS to DEFINE_SQUIRREL_CLASS
truelight
parents: 9422
diff changeset
    44
#ifdef DEFINE_SQUIRREL_CLASS
9422
33efcc5f1b09 (svn r9223) [NoAI] -Change: moved squirrel/engine.cpp to squirrel.cpp in root
truelight
parents: 9404
diff changeset
    45
void SQAIBaseRegister(Squirrel *engine) {
9387
4255a0a2d272 (svn r9179) [NoAI] -Add: added templates that makes adding classes to squirrel very easy
truelight
parents: 9362
diff changeset
    46
	DefSQClass <AIBase> SQAIBase("AIBase");
9397
d8f8db9c1a2e (svn r9189) [NoAI] -Cleanup: cleaned up DefSQClass a bit by using the SquirrelEngine
truelight
parents: 9388
diff changeset
    47
	SQAIBase.PreRegister(engine);
9404
ef9e171617a3 (svn r9201) [NoAI] -Change: make adding a default-constructor for DefSQClass optional
truelight
parents: 9397
diff changeset
    48
	SQAIBase.AddConstructor(engine);
9440
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    49
	SQAIBase.DefSQFunction(engine, &AIBase::Rand,      "Rand");
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    50
	SQAIBase.DefSQFunction(engine, &AIBase::RandRange, "RandRange");
0986434f3af8 (svn r9252) [NoAI] -Codechange: rename Random and RandomRange to a non-conflicting name, especially because the sematics differ with respect to the core Random and RandomRange.
rubidium
parents: 9436
diff changeset
    51
	SQAIBase.DefSQFunction(engine, &AIBase::Chance,    "Chance");
9397
d8f8db9c1a2e (svn r9189) [NoAI] -Cleanup: cleaned up DefSQClass a bit by using the SquirrelEngine
truelight
parents: 9388
diff changeset
    52
	SQAIBase.PostRegister(engine);
9387
4255a0a2d272 (svn r9179) [NoAI] -Add: added templates that makes adding classes to squirrel very easy
truelight
parents: 9362
diff changeset
    53
}
4255a0a2d272 (svn r9179) [NoAI] -Add: added templates that makes adding classes to squirrel very easy
truelight
parents: 9362
diff changeset
    54
#endif /* SQUIRREL_CLASS */
4255a0a2d272 (svn r9179) [NoAI] -Add: added templates that makes adding classes to squirrel very easy
truelight
parents: 9362
diff changeset
    55
9360
c20d0a9e0a5c (svn r9142) [NoAI] -Add: added initial code for AI-layer system
truelight
parents:
diff changeset
    56
#endif /* AI_BASE_HPP */