ai/ai.c
changeset 2760 ebe2caeec116
parent 2759 9a5079782c67
child 2761 69013279fe69
equal deleted inserted replaced
2759:9a5079782c67 2760:ebe2caeec116
   238 void AI_CommandResult(bool succeeded)
   238 void AI_CommandResult(bool succeeded)
   239 {
   239 {
   240 	if (_ai_current_uid == 0)
   240 	if (_ai_current_uid == 0)
   241 		return;
   241 		return;
   242 
   242 
   243 	ai_event(_current_player, succeeded ? ottd_Event_CommandSucceeded : ottd_Event_CommandFailed, _ai_current_tile);
   243 	ai_event(_current_player, succeeded ? ttai_Event_CommandSucceeded : ttai_Event_CommandFailed, _ai_current_tile);
   244 }
   244 }
   245 
   245 
   246 /**
   246 /**
   247  * Run 1 tick of the AI. Don't overdo it, keep it realistic.
   247  * Run 1 tick of the AI. Don't overdo it, keep it realistic.
   248  */
   248  */
   333 		DEBUG(ai, 0)("[AI] Failed to load AI Control, switching back to built-in AIs..");
   333 		DEBUG(ai, 0)("[AI] Failed to load AI Control, switching back to built-in AIs..");
   334 		_ai.gpmi = false;
   334 		_ai.gpmi = false;
   335 	}
   335 	}
   336 }
   336 }
   337 
   337 
   338 void (*ottd_GetNextAIData)(char **library, char **param);
   338 void (*ttai_GetNextAIData)(char **library, char **param);
   339 void (*ottd_SetAIParam)(char *param);
   339 void (*ttai_SetAIParam)(char *param);
   340 
   340 
   341 void AI_LoadAIControl(void)
   341 void AI_LoadAIControl(void)
   342 {
   342 {
   343 	/* Load module */
   343 	/* Load module */
   344 	_ai.gpmi_mod = gpmi_mod_load("ottd_ai_control_mod", NULL);
   344 	_ai.gpmi_mod = gpmi_mod_load("ttai_control_mod", NULL);
   345 	if (_ai.gpmi_mod == NULL) {
   345 	if (_ai.gpmi_mod == NULL) {
   346 		AI_ShutdownAIControl(true);
   346 		AI_ShutdownAIControl(true);
   347 		return;
   347 		return;
   348 	}
   348 	}
   349 
   349 
   350 	/* Load package */
   350 	/* Load package */
   351 	if (gpmi_pkg_load("ottd_ai_control_pkg", 0, NULL, NULL, &_ai.gpmi_pkg)) {
   351 	if (gpmi_pkg_load("ttai_control_pkg", 0, NULL, NULL, &_ai.gpmi_pkg)) {
   352 		AI_ShutdownAIControl(true);
   352 		AI_ShutdownAIControl(true);
   353 		return;
   353 		return;
   354 	}
   354 	}
   355 
   355 
   356 	/* Now link all the functions */
   356 	/* Now link all the functions */
   357 	{
   357 	{
   358 		ottd_GetNextAIData = gpmi_pkg_resolve(_ai.gpmi_pkg, "ottd_GetNextAIData");
   358 		ttai_GetNextAIData = gpmi_pkg_resolve(_ai.gpmi_pkg, "ttai_GetNextAIData");
   359 		ottd_SetAIParam = gpmi_pkg_resolve(_ai.gpmi_pkg, "ottd_SetAIParam");
   359 		ttai_SetAIParam = gpmi_pkg_resolve(_ai.gpmi_pkg, "ttai_SetAIParam");
   360 
   360 
   361 		if (ottd_GetNextAIData == NULL || ottd_SetAIParam == NULL)
   361 		if (ttai_GetNextAIData == NULL || ttai_SetAIParam == NULL)
   362 			AI_ShutdownAIControl(true);
   362 			AI_ShutdownAIControl(true);
   363 	}
   363 	}
   364 
   364 
   365 	ottd_SetAIParam(_ai.gpmi_param);
   365 	ttai_SetAIParam(_ai.gpmi_param);
   366 }
   366 }
   367 
   367 
   368 /**
   368 /**
   369  * Dump an entry of the GPMI error stack (callback routine). This helps the user to trace errors back to their roots.
   369  * Dump an entry of the GPMI error stack (callback routine). This helps the user to trace errors back to their roots.
   370  */
   370  */
   389 
   389 
   390 	if (_ai.gpmi) {
   390 	if (_ai.gpmi) {
   391 		char *library = NULL;
   391 		char *library = NULL;
   392 		char *params = NULL;
   392 		char *params = NULL;
   393 
   393 
   394 		ottd_GetNextAIData(&library, &params);
   394 		ttai_GetNextAIData(&library, &params);
   395 		gpmi_error_stack_enable = 1;
   395 		gpmi_error_stack_enable = 1;
   396 
   396 
   397 		if (library != NULL) {
   397 		if (library != NULL) {
   398 			_ai_player[player].module = gpmi_mod_load(library, params);
   398 			_ai_player[player].module = gpmi_mod_load(library, params);
   399 			free(library);
   399 			free(library);