@@ -198,23 +198,75 @@ void AI_RunGameLoop(void)
_current_player = OWNER_NONE;
}
#ifdef GPMI
void (*ottd_GetNextAIData)(char **library, char **param);
void AI_ShutdownAIControl(bool with_error)
{
if (_ai.gpmi_mod != NULL)
gpmi_mod_unload(_ai.gpmi_mod);
if (_ai.gpmi_pkg != NULL)
gpmi_pkg_unload(_ai.gpmi_pkg);
if (with_error) {
DEBUG(ai, 0)("[AI] Failed to load AI Control, switching back to built-in AIs..");
_ai.gpmi = false;
void AI_LoadAIControl(void)
/* Load module */
_ai.gpmi_mod = gpmi_mod_load("ottd_ai_control_mod", NULL);
if (_ai.gpmi_mod == NULL) {
AI_ShutdownAIControl(true);
return;
/* Load package */
if (gpmi_pkg_load("ottd_ai_control_pkg", 0, NULL, NULL, &_ai.gpmi_pkg)) {
/* Now link all the functions */
ottd_GetNextAIData = gpmi_pkg_resolve(_ai.gpmi_pkg, "ottd_GetNextAIData");
if (ottd_GetNextAIData == NULL)
#endif /* GPMI */
/**
* A new AI sees the day of light. You can do here what ever you think is needed.
*/
void AI_StartNewAI(PlayerID player)
char library[80];
char params[80];
/* Keep this in a different IF, because the function can turn _ai.gpmi off!! */
if (_ai.gpmi && _ai.gpmi_mod == NULL)
AI_LoadAIControl();
if (_ai.gpmi) {
char *library = NULL;
char *params = NULL;
ottd_GetNextAIData(&library, ¶ms);
/* XXX -- Todo, make a nice assign for library and params from a nice GUI :) */
snprintf(library, sizeof(library), "php");
snprintf(params, sizeof(params), "daeb");
if (library != NULL) {
_ai_player[player].module = gpmi_mod_load(library, params);
free(library);
if (params != NULL)
free(params);
if (_ai_player[player].module == NULL) {
DEBUG(ai, 0)("[AI] Failed to load AI, aborting..");
@@ -234,7 +286,8 @@ void AI_PlayerDied(PlayerID player)
_ai_player[player].active = false;
gpmi_mod_unload(_ai_player[player].module);
if (_ai_player[player].module != NULL)
@@ -265,4 +318,8 @@ void AI_Uninitialize(void)
FOR_ALL_PLAYERS(p) {
if (p->is_active && p->is_ai && _ai_player[p->index].active) AI_PlayerDied(p->index);
AI_ShutdownAIControl(false);
@@ -40,6 +40,10 @@ typedef struct AIStruct {
uint8 network_playas; //! The current network player we are connected as
bool gpmi; //! True if we want GPMI AIs
gpmi_module *gpmi_mod; //! The module controller for GPMI based AIs (Event-handling)
gpmi_package *gpmi_pkg; //! The package controller for GPMI based AIs (Functions)
} AIStruct;
VARDEF AIStruct _ai;
Status change: