src/ai/core/ai_factory.hpp
author truelight
Thu, 15 Mar 2007 11:53:41 +0000
branchnoai
changeset 9402 45581b218c98
parent 9401 04502c3557f2
permissions -rw-r--r--
(svn r9197) [NoAI] -Fix: std::map.end() is the item AFTER the last valid item, not the last item
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
     1
/* $Id$ */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
     2
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
     3
/** @file ai_factory.hpp declaration of class for AIFactory class */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
     4
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
     5
#ifndef AI_FACTORY_HPP
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
     6
#define AI_FACTORY_HPP
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
     7
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
     8
#include <string>
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
     9
#include <map>
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    10
#include <assert.h>
9401
04502c3557f2 (svn r9196) [NoAI] -Fix: avoid include-magic by including needed includes directly
truelight
parents: 9400
diff changeset
    11
#include "../../stdafx.h"
04502c3557f2 (svn r9196) [NoAI] -Fix: avoid include-magic by including needed includes directly
truelight
parents: 9400
diff changeset
    12
#include "../../functions.h"
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    13
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    14
class AIController;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    15
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    16
class AIFactoryBase {
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    17
private:
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    18
	const char *name;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    19
	typedef std::map<std::string, AIFactoryBase *> Factories;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    20
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    21
	static Factories &GetFactories()
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    22
	{
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    23
		static Factories s_factories;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    24
		return s_factories;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    25
	}
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    26
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    27
protected:
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    28
	/**
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    29
	 * This registers your AI to the main system so we know about you.
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    30
	 */
9392
7791ceeea57b (svn r9184) [NoAI] -Revert r9183: now that was a bullshit commit
truelight
parents: 9391
diff changeset
    31
	void RegisterFactory(const char *name)
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    32
	{
9400
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    33
		this->name = name;
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    34
		/* Don't register nameless Factories */
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    35
		if (name == NULL) return;
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    36
9392
7791ceeea57b (svn r9184) [NoAI] -Revert r9183: now that was a bullshit commit
truelight
parents: 9391
diff changeset
    37
		std::pair<Factories::iterator, bool> P = GetFactories().insert(Factories::value_type(name, this));
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    38
		assert(P.second);
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    39
	}
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    40
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    41
public:
9400
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    42
	virtual ~AIFactoryBase() { if (this->name != NULL) GetFactories().erase(this->name); }
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    43
9400
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    44
	/**
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    45
	 * Run all initializers.
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    46
	 */
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    47
	static void RunInitializers()
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    48
	{
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    49
		/* Protect this function from being run several times */
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    50
		static bool run_once = false;
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    51
		if (run_once) return;
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    52
		run_once = true;
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    53
		if (GetFactories().size() == 0) return;
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    54
		Factories::iterator it = GetFactories().begin();
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    55
		for (; it != GetFactories().end(); it++) {
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    56
			AIFactoryBase *f = (*it).second;
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    57
			f->Initializer();
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    58
		}
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    59
	}
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    60
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    61
	/**
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    62
	 * Select a random AI from all known AIs.
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
    63
	 */
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    64
	static AIController *SelectRandomAI()
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    65
	{
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    66
		if (GetFactories().size() == 0) return NULL;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    67
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    68
		/* Find a random AI */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    69
		uint i;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    70
		if (_networking) i = InteractiveRandomRange(GetFactories().size());
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    71
		else             i =            RandomRange(GetFactories().size());
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    72
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    73
		/* Find the Nth item from the array */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    74
		Factories::iterator it = GetFactories().begin();
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    75
		Factories::iterator first_it;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    76
		for (; i > 0; i--) it++;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    77
		first_it = it;
9402
45581b218c98 (svn r9197) [NoAI] -Fix: std::map.end() is the item AFTER the last valid item, not the last item
truelight
parents: 9401
diff changeset
    78
		AIFactoryBase *f = it->second;
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    79
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    80
		if (!f->AllowStartup()) {
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    81
			/* We can't start this AI, try to find the next best */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    82
			do {
9402
45581b218c98 (svn r9197) [NoAI] -Fix: std::map.end() is the item AFTER the last valid item, not the last item
truelight
parents: 9401
diff changeset
    83
				it++;
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    84
				if (it == GetFactories().end()) it = GetFactories().begin();
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    85
				/* Back at the beginning? Drop out! */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    86
				if (first_it == it) break;
9402
45581b218c98 (svn r9197) [NoAI] -Fix: std::map.end() is the item AFTER the last valid item, not the last item
truelight
parents: 9401
diff changeset
    87
				f = it->second;
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    88
			} while (!f->AllowStartup());
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    89
			/* Unable to start any AI */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    90
			if (first_it == it) return NULL;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    91
		}
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    92
		return f->CreateInstance();
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    93
	}
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    94
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    95
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    96
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    97
	/**
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    98
	 * Get the author of the AI.
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
    99
	 */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   100
	virtual const char *GetAuthor() = 0;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   101
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   102
	/**
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   103
	 * Get a description of the AI.
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   104
	 */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   105
	virtual const char *GetDescription() = 0;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   106
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   107
	/**
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   108
	 * Get the version of this AI.
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   109
	 */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   110
	virtual int GetVersion() = 0;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   111
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   112
	/**
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   113
	 * Get the date of the version.
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   114
	 * @return A string like '2007-08-29'.
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   115
	 */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   116
	virtual const char *GetDate() = 0;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   117
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   118
	/**
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   119
	 * Create an instance of your AI.
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   120
	 */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   121
	virtual AIController *CreateInstance() = 0;
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   122
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   123
	/**
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   124
	 * In this function you can do some very limited querying of the game.
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   125
	 *  If you for example only supply road-vehicle-based AI, and RVs are
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   126
	 *  disabled, you return 'false', so you won't boot.
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   127
	 */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   128
	virtual bool AllowStartup() { return true; }
9400
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   129
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   130
	/**
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   131
	 * Normally you just make a static instance of AIFactory, and you
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   132
	 *  will be registered. In very limited cases, like Squirrel-module,
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   133
	 *  it is needed to be called when OpenTTD is launched (so not as
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   134
	 *  constructor). Then you can use this function.
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   135
	 * @note Avoid using it!
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   136
	 */
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   137
	virtual void Initializer() { }
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   138
};
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   139
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   140
/**
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   141
 * The template to define your AIFactory. This makes sure RegisterFactory
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   142
 *  works correctly on initialization.
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   143
 * Example: class FYourClass: public AIFactory<FYourClass> { }
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   144
 */
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   145
template <class T>
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   146
class AIFactory: public AIFactoryBase {
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   147
public:
9392
7791ceeea57b (svn r9184) [NoAI] -Revert r9183: now that was a bullshit commit
truelight
parents: 9391
diff changeset
   148
	AIFactory() { this->RegisterFactory(((T *)this)->GetName()); }
9400
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   149
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   150
	/**
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   151
	 * Get a short name for the AI.
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   152
	 */
6da42d57fda2 (svn r9195) [NoAI] -Fix: move GetName to AIFactory template, as otherwise GetName()
truelight
parents: 9392
diff changeset
   153
	const char *GetName();
9390
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   154
};
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   155
4042c17c8055 (svn r9182) [NoAI] -Add: added AIFactory template which all AIs must define, as this
truelight
parents:
diff changeset
   156
#endif /* AI_FACTORY_HPP */