File: SAIInterfaceLibrary.h

package info (click to toggle)
spring 98.0%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie, jessie-kfreebsd
  • size: 41,928 kB
  • ctags: 60,665
  • sloc: cpp: 356,167; ansic: 39,434; python: 12,228; java: 12,203; awk: 5,856; sh: 1,719; xml: 997; perl: 405; php: 253; objc: 194; makefile: 72; sed: 2
file content (271 lines) | stat: -rw-r--r-- 7,828 bytes parent folder | download | duplicates (2)
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
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
/* This file is part of the Spring engine (GPL v2 or later), see LICENSE.html */

#ifndef S_AI_INTERFACE_LIBRARY_H
#define S_AI_INTERFACE_LIBRARY_H

/*
 * All this is not needed when building an AI,
 * as it is strictly AI Interface related,
 * and therefore only matters to the engine and AI Interfaces.
 */
#if !defined BUILDING_SKIRMISH_AI

#ifdef	__cplusplus
extern "C" {
#endif

/**
 * [string]
 * Absolute data dir containing the AIs AIInfo.lua file.
 * This property is set by the engine, not read from any file.
 * example: "/home/john/spring/AI/Interfaces/C/0.1"
 */
#define AI_INTERFACE_PROPERTY_DATA_DIR               "dataDir"

/**
 * [string]
 * Absolute, version independent data dir.
 * This property is set by the engine, not read from any file.
 * example: "/home/john/spring/AI/Interfaces/C/common"
 */
#define AI_INTERFACE_PROPERTY_DATA_DIR_COMMON        "dataDirCommon"

/**
 * [string: [a-zA-Z0-9_.]*]
 * example: "C"
 */
#define AI_INTERFACE_PROPERTY_SHORT_NAME             "shortName"

/**
 * [string: [a-zA-Z0-9_.]*]
 * example: "0.1"
 */
#define AI_INTERFACE_PROPERTY_VERSION                "version"

/**
 * [string]
 * example: "C/C++"
 */
#define AI_INTERFACE_PROPERTY_NAME                   "name"

/**
 * [string]
 * example: "supports loading native AIs written in C and/or C++"
 */
#define AI_INTERFACE_PROPERTY_DESCRIPTION            "description"

/**
 * [string]
 * example: "http://springrts.com/wiki/AIInterface:C"
 */
#define AI_INTERFACE_PROPERTY_URL                    "url"

/**
 * [string]
 * example: "C, C++"
 */
#define AI_INTERFACE_PROPERTY_SUPPORTED_LANGUAGES    "supportedLanguages"

/**
 * [int]
 * The engine version number the AI Interface was compiled for,
 * though it may work with newer or older engine versions too.
 */
#define AI_INTERFACE_PROPERTY_ENGINE_VERSION         "engineVersion"

/**
 * [bool]
 * Whether the AI Interface suports dynamic (at runtime) lookup of available
 * Skirmish AIs through the list* functions, in addition to the ones defined
 * through AIInfo.lua files.
 * example: "0", "1", "false", "true"
 */
#define AI_INTERFACE_PROPERTY_SUPPORTS_LOOKUP    "supportsLookup"

/*
 * Everything following is (code wise) only interesting for the engine,
 * not for AI Interfaces.
 */
#if !defined BUILDING_AI

#include "System/exportdefines.h"
//#include "ELevelOfSupport.h"

//enum ELevelOfSupport;
struct SSkirmishAILibrary;
struct SStaticGlobalData;

/**
 * @brief Artificial Intelligence Interface library interface
 *
 * This is the interface between the engine and an implementation of
 * an AI Interface.
 * The engine will address AI Interfaces through this interface,
 * but AI Interfaces will not actually implement it. It is the job
 * of the engine, to make sure it can address AI Interface
 * implementations through instances of this struct.
 *
 * An example of loading the C AI Interface:
 * The C AI Interface library exports functions fitting the
 * function pointers in this struct. When the engine needs therefore
 * C AI Interface, it loads the shared library, eg C-AI-Interface.dll,
 * creates a new instance of this struct, and sets the member function
 * pointers to the addresses of the fitting functions exported
 * by the shared library. The functions of the AI Interface are then
 * allways called through this struct.
 */
struct SAIInterfaceLibrary {

	// static AI interface library functions

	/**
	 * This function is called right after the library is dynamically loaded.
	 * It can be used to initialize variables and to check or prepare
	 * the environment (os, engine, filesystem, ...).
	 * @see releaseStatic()
	 *
	 * [optional]
	 * An AI Interface not exporting this function is still valid.
	 *
	 * @param	staticGlobalData contains global data about the engine and the
	 *                           environment; is guaranteed to be valid till
	 *                           releaseStatic() is called.
	 * @return     0: ok
	 *          != 0: error
	 */
	int (CALLING_CONV *initStatic)(int interfaceId,
			const struct SAIInterfaceCallback* const);

	/**
	 * This function is called right right before the library is unloaded.
	 * It can be used to deinitialize variables and to cleanup the environment,
	 * for example the filesystem.
	 *
	 * See also initStatic().
	 *
	 * [optional]
	 * An AI Interface not exporting this function is still valid.
	 *
	 * @return     0: ok
	 *          != 0: error
	 */
	int (CALLING_CONV *releaseStatic)();

//	/**
//	 * Level of Support for a specific engine version.
//	 *
//	 * [optional]
//	 * An AI Interface not exporting this function is still valid.
//	 */
//	enum LevelOfSupport (CALLING_CONV *getLevelOfSupportFor)(
//			const char* engineVersionString, int engineVersionNumber);


	// skirmish AI methods

	/**
	 * Loads the specified Skirmish AI.
	 *
	 * @return     0: ok
	 *          != 0: error
	 */
	const struct SSkirmishAILibrary* (CALLING_CONV *loadSkirmishAILibrary)(
			const char* const shortName,
			const char* const version);

	/**
	 * Unloads the specified Skirmish AI.
	 *
	 * @return     0: ok
	 *          != 0: error
	 */
	int (CALLING_CONV *unloadSkirmishAILibrary)(
			const char* const shortName,
			const char* const version);

	/**
	 * Unloads all Skirmish AI libraries currently loaded by this interface.
	 *
	 * @return     0: ok
	 *          != 0: error
	 */
	int (CALLING_CONV *unloadAllSkirmishAILibraries)();

	/**
	 * Dynamic Skirmish AI library lookup system entry method.
	 * This system works as an alternative/addition to AIInfo.lua and
	 * AIOptions.lua files.
	 *
	 * [optional]
	 * An AI Interface not exporting this function is still valid.
	 *
	 * @see AI_INTERFACE_PROPERTY_SUPPORTS_LOOKUP
	 * @see listSkirmishAILibraryInfos
	 * @see listSkirmishAILibraryOptions
	 * @return the number of Skirmish AI libraries available through this
	 *   interface through the dynamic lookup system
	 */
	int (CALLING_CONV *listSkirmishAILibraries)(int interfaceId);

	/**
	 * Returns the number of info key-value pairs for a certain Skirmish AI
	 * library.
	 *
	 * [optional]
	 * An AI Interface not exporting this function is still valid.
	 *
	 * @see listSkirmishAILibraries
	 * @see listSkirmishAILibraryInfoKey
	 * @see listSkirmishAILibraryInfoValue
	 * @return the number of info key-value pairs for a certain Skirmish AI
	 *   library.
	 */
	int (CALLING_CONV *listSkirmishAILibraryInfos)(int interfaceId,
			int aiIndex);
	/**
	 * Returns the key of an info item for a certain Skirmish AI library.
	 *
	 * [optional]
	 * An AI Interface not exporting this function is still valid.
	 *
	 * @see listSkirmishAILibraryInfos
	 * @see listSkirmishAILibraryInfoValue
	 * @return the key of an info item for a certain Skirmish AI library.
	 */
	const char* (CALLING_CONV *listSkirmishAILibraryInfoKey)(int interfaceId,
			int aiIndex, int infoIndex);
	/**
	 * Returns the value of an info item for a certain Skirmish AI library.
	 *
	 * [optional]
	 * An AI Interface not exporting this function is still valid.
	 *
	 * @see listSkirmishAILibraryInfos
	 * @see listSkirmishAILibraryInfoKey
	 * @return the value of an info item for a certain Skirmish AI library.
	 */
	const char* (CALLING_CONV *listSkirmishAILibraryInfoValue)(int interfaceId,
			int aiIndex, int infoIndex);

	/**
	 * Returns a string consisting of Lua code, that returns an options table.
	 *
	 * [optional]
	 * An AI Interface not exporting this function is still valid.
	 *
	 * @see listSkirmishAILibraries
	 * @return NULL for no options, otherwise
	 *   a string consisting of Lua code that returns an options table
	 */
	const char* (CALLING_CONV *listSkirmishAILibraryOptions)(int interfaceId,
			int aiIndex);
};

#endif // !defined BUILDING_AI

#ifdef	__cplusplus
} // extern "C"
#endif

#endif // !defined BUILDING_SKIRMISH_AI
#endif // S_AI_INTERFACE_LIBRARY_H