1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
|
/* $Id$ */
/*
* This file is part of OpenTTD.
* OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
* OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
* See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
*/
/** @file ai.hpp Base functions for all AIs. */
#ifndef AI_HPP
#define AI_HPP
#ifdef ENABLE_AI
#include "api/ai_event_types.hpp"
#include "../date_type.h"
#include "../core/string_compare_type.hpp"
#include <map>
typedef std::map<const char *, class AIInfo *, StringCompare> AIInfoList;
class AI {
public:
/**
* The default months AIs start after eachother.
*/
enum StartNext {
START_NEXT_EASY = DAYS_IN_YEAR * 2,
START_NEXT_MEDIUM = DAYS_IN_YEAR,
START_NEXT_HARD = DAYS_IN_YEAR / 2,
START_NEXT_MIN = 1,
START_NEXT_MAX = 3600,
START_NEXT_DEVIATION = 60,
};
/**
* Is it possible to start a new AI company?
* @return True if a new AI company can be started.
*/
static bool CanStartNew();
/**
* Start a new AI company.
* @param company At which slot the AI company should start.
* @param rerandomise_ai Whether to rerandomise the configured AI.
*/
static void StartNew(CompanyID company, bool rerandomise_ai = true);
/**
* Called every game-tick to let AIs do something.
*/
static void GameLoop();
/**
* Get the current AI tick.
*/
static uint GetTick();
/**
* Stop a company to be controlled by an AI.
* @param company The company from which the AI needs to detach.
* @pre Company::IsValidAiID(company)
*/
static void Stop(CompanyID company);
/**
* Kill any and all AIs we manage.
*/
static void KillAll();
/**
* Initialize the AI system.
*/
static void Initialize();
/**
* Uninitialize the AI system
* @param keepConfig Should we keep AIConfigs, or can we free that memory?
*/
static void Uninitialize(bool keepConfig);
/**
* Reset all AIConfigs, and make them reload their AIInfo.
* If the AIInfo could no longer be found, an error is reported to the user.
*/
static void ResetConfig();
/**
* Queue a new event for an AI.
*/
static void NewEvent(CompanyID company, AIEvent *event);
/**
* Broadcast a new event to all active AIs.
*/
static void BroadcastNewEvent(AIEvent *event, CompanyID skip_company = MAX_COMPANIES);
/**
* Save data from an AI to a savegame.
*/
static void Save(CompanyID company);
/**
* Load data for an AI from a savegame.
*/
static void Load(CompanyID company, int version);
/**
* Get the number of days before the next AI should start.
*/
static int GetStartNextTime();
static char *GetConsoleList(char *p, const char *last);
static const AIInfoList *GetInfoList();
static const AIInfoList *GetUniqueInfoList();
static AIInfo *FindInfo(const char *name, int version, bool force_exact_match);
static bool ImportLibrary(const char *library, const char *class_name, int version, HSQUIRRELVM vm);
static void Rescan();
#if defined(ENABLE_NETWORK)
static bool HasAI(const struct ContentInfo *ci, bool md5sum);
#endif
private:
static uint frame_counter;
static class AIScanner *ai_scanner;
};
#else /* ENABLE_AI */
#include "../company_type.h"
#define NewEvent(cid, event) nop()
#define BroadcastNewEvent(...) nop()
class AI {
public:
static void StartNew(CompanyID company, bool rerandomise_ai = true) {}
static void Stop(CompanyID company) {}
static void Initialize() {}
static void Uninitialize(bool keepConfig) {}
static void KillAll() {}
static void GameLoop() {}
static bool HasAI(const struct ContentInfo *ci, bool md5sum) { return false; }
static void Rescan() {}
static char *GetConsoleList(char *p, const char *last) { return p; }
static void nop() { }
};
#endif /* ENABLE_AI */
#endif /* AI_HPP */
|