equal
deleted
inserted
replaced
6 #include "../command.h" |
6 #include "../command.h" |
7 #include "../network.h" |
7 #include "../network.h" |
8 #include "../debug.h" |
8 #include "../debug.h" |
9 #include "ai.h" |
9 #include "ai.h" |
10 #include "default/default.h" |
10 #include "default/default.h" |
|
11 #include "../string.h" |
11 |
12 |
12 /* Here we define the events */ |
13 /* Here we define the events */ |
13 #define DEF_EVENTS |
14 #define DEF_EVENTS |
14 #include "ai_event.h" |
15 #include "ai_event.h" |
15 #undef DEF_EVENTS |
16 #undef DEF_EVENTS |
198 _current_player = OWNER_NONE; |
199 _current_player = OWNER_NONE; |
199 } |
200 } |
200 |
201 |
201 #ifdef GPMI |
202 #ifdef GPMI |
202 |
203 |
203 void (*ottd_GetNextAIData)(char **library, char **param); |
|
204 |
|
205 void AI_ShutdownAIControl(bool with_error) |
204 void AI_ShutdownAIControl(bool with_error) |
206 { |
205 { |
207 if (_ai.gpmi_mod != NULL) |
206 if (_ai.gpmi_mod != NULL) |
208 gpmi_mod_unload(_ai.gpmi_mod); |
207 gpmi_mod_unload(_ai.gpmi_mod); |
209 if (_ai.gpmi_pkg != NULL) |
208 if (_ai.gpmi_pkg != NULL) |
213 DEBUG(ai, 0)("[AI] Failed to load AI Control, switching back to built-in AIs.."); |
212 DEBUG(ai, 0)("[AI] Failed to load AI Control, switching back to built-in AIs.."); |
214 _ai.gpmi = false; |
213 _ai.gpmi = false; |
215 } |
214 } |
216 } |
215 } |
217 |
216 |
|
217 void (*ottd_GetNextAIData)(char **library, char **param); |
|
218 void (*ottd_SetAIParam)(char *param); |
|
219 |
218 void AI_LoadAIControl(void) |
220 void AI_LoadAIControl(void) |
219 { |
221 { |
220 /* Load module */ |
222 /* Load module */ |
221 _ai.gpmi_mod = gpmi_mod_load("ottd_ai_control_mod", NULL); |
223 _ai.gpmi_mod = gpmi_mod_load("ottd_ai_control_mod", NULL); |
222 if (_ai.gpmi_mod == NULL) { |
224 if (_ai.gpmi_mod == NULL) { |
231 } |
233 } |
232 |
234 |
233 /* Now link all the functions */ |
235 /* Now link all the functions */ |
234 { |
236 { |
235 ottd_GetNextAIData = gpmi_pkg_resolve(_ai.gpmi_pkg, "ottd_GetNextAIData"); |
237 ottd_GetNextAIData = gpmi_pkg_resolve(_ai.gpmi_pkg, "ottd_GetNextAIData"); |
236 |
238 ottd_SetAIParam = gpmi_pkg_resolve(_ai.gpmi_pkg, "ottd_SetAIParam"); |
237 if (ottd_GetNextAIData == NULL) |
239 |
|
240 if (ottd_GetNextAIData == NULL || ottd_SetAIParam == NULL) |
238 AI_ShutdownAIControl(true); |
241 AI_ShutdownAIControl(true); |
239 } |
242 } |
|
243 |
|
244 ottd_SetAIParam(_ai.gpmi_param); |
240 } |
245 } |
241 #endif /* GPMI */ |
246 #endif /* GPMI */ |
242 |
247 |
243 /** |
248 /** |
244 * A new AI sees the day of light. You can do here what ever you think is needed. |
249 * A new AI sees the day of light. You can do here what ever you think is needed. |
296 */ |
301 */ |
297 void AI_Initialize(void) |
302 void AI_Initialize(void) |
298 { |
303 { |
299 bool tmp_ai_network_client = _ai.network_client; |
304 bool tmp_ai_network_client = _ai.network_client; |
300 bool tmp_ai_gpmi = _ai.gpmi; |
305 bool tmp_ai_gpmi = _ai.gpmi; |
|
306 #ifdef GPMI |
|
307 char *tmp_ai_gpmi_param = strdup(_ai.gpmi_param); |
|
308 #endif /* GPMI */ |
301 |
309 |
302 memset(&_ai, 0, sizeof(_ai)); |
310 memset(&_ai, 0, sizeof(_ai)); |
303 memset(&_ai_player, 0, sizeof(_ai_player)); |
311 memset(&_ai_player, 0, sizeof(_ai_player)); |
304 |
312 |
305 _ai.network_client = tmp_ai_network_client; |
313 _ai.network_client = tmp_ai_network_client; |
306 _ai.network_playas = OWNER_SPECTATOR; |
314 _ai.network_playas = OWNER_SPECTATOR; |
307 _ai.enabled = true; |
315 _ai.enabled = true; |
308 _ai.gpmi = tmp_ai_gpmi; |
316 _ai.gpmi = tmp_ai_gpmi; |
|
317 #ifdef GPMI |
|
318 ttd_strlcpy(_ai.gpmi_param, tmp_ai_gpmi_param, sizeof(_ai.gpmi_param)); |
|
319 free(tmp_ai_gpmi_param); |
|
320 #endif /* GPMI */ |
309 } |
321 } |
310 |
322 |
311 /** |
323 /** |
312 * Deinitializer for AI-related stuff. |
324 * Deinitializer for AI-related stuff. |
313 */ |
325 */ |