(svn r3245) -Add: allow OpenTTD to give his GPMI-params to the GPMI modules
authortruelight
Tue, 29 Nov 2005 15:53:15 +0000
changeset 2701 210933e3fe4d
parent 2700 976daceadac5
child 2702 9172e3030a35
(svn r3245) -Add: allow OpenTTD to give his GPMI-params to the GPMI modules
ai/ai.c
ai/ai.h
openttd.c
--- a/ai/ai.c	Mon Nov 28 14:02:36 2005 +0000
+++ b/ai/ai.c	Tue Nov 29 15:53:15 2005 +0000
@@ -8,6 +8,7 @@
 #include "../debug.h"
 #include "ai.h"
 #include "default/default.h"
+#include "../string.h"
 
 /* Here we define the events */
 #define DEF_EVENTS
@@ -200,8 +201,6 @@
 
 #ifdef GPMI
 
-void (*ottd_GetNextAIData)(char **library, char **param);
-
 void AI_ShutdownAIControl(bool with_error)
 {
 	if (_ai.gpmi_mod != NULL)
@@ -215,6 +214,9 @@
 	}
 }
 
+void (*ottd_GetNextAIData)(char **library, char **param);
+void (*ottd_SetAIParam)(char *param);
+
 void AI_LoadAIControl(void)
 {
 	/* Load module */
@@ -233,10 +235,13 @@
 	/* Now link all the functions */
 	{
 		ottd_GetNextAIData = gpmi_pkg_resolve(_ai.gpmi_pkg, "ottd_GetNextAIData");
+		ottd_SetAIParam = gpmi_pkg_resolve(_ai.gpmi_pkg, "ottd_SetAIParam");
 
-		if (ottd_GetNextAIData == NULL)
+		if (ottd_GetNextAIData == NULL || ottd_SetAIParam == NULL)
 			AI_ShutdownAIControl(true);
 	}
+
+	ottd_SetAIParam(_ai.gpmi_param);
 }
 #endif /* GPMI */
 
@@ -298,6 +303,9 @@
 {
 	bool tmp_ai_network_client = _ai.network_client;
 	bool tmp_ai_gpmi = _ai.gpmi;
+#ifdef GPMI
+	char *tmp_ai_gpmi_param = strdup(_ai.gpmi_param);
+#endif /* GPMI */
 
 	memset(&_ai, 0, sizeof(_ai));
 	memset(&_ai_player, 0, sizeof(_ai_player));
@@ -306,6 +314,10 @@
 	_ai.network_playas = OWNER_SPECTATOR;
 	_ai.enabled = true;
 	_ai.gpmi = tmp_ai_gpmi;
+#ifdef GPMI
+	ttd_strlcpy(_ai.gpmi_param, tmp_ai_gpmi_param, sizeof(_ai.gpmi_param));
+	free(tmp_ai_gpmi_param);
+#endif /* GPMI */
 }
 
 /**
--- a/ai/ai.h	Mon Nov 28 14:02:36 2005 +0000
+++ b/ai/ai.h	Tue Nov 29 15:53:15 2005 +0000
@@ -43,6 +43,7 @@
 #ifdef GPMI
 	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)
+	char gpmi_param[128];   //! The params given to the gpmi_mod
 #endif /* GPMI */
 } AIStruct;
 
--- a/openttd.c	Mon Nov 28 14:02:36 2005 +0000
+++ b/openttd.c	Tue Nov 29 15:53:15 2005 +0000
@@ -316,6 +316,9 @@
 	uint startdate = -1;
 	bool dedicated;
 
+#ifdef GPMI
+	_ai.gpmi_param[0] = 0;
+#endif /* GPMI */
 	musicdriver[0] = sounddriver[0] = videodriver[0] = 0;
 
 	_game_mode = GM_MENU;
@@ -330,9 +333,9 @@
 	//   a ':' behind it means: it need a param (e.g.: -m<driver>)
 	//   a '::' behind it means: it can optional have a param (e.g.: -d<debug>)
 	#if !defined(__MORPHOS__) && !defined(__AMIGA__) && !defined(WIN32)
-		optformat = "bm:s:v:hDfn::l:eit:d::r:g::G:p:c:";
+		optformat = "a:bm:s:v:hDfn::l:eit:d::r:g::G:p:c:";
 	#else
-		optformat = "bm:s:v:hDn::l:eit:d::r:g::G:p:c:"; // no fork option
+		optformat = "a:bm:s:v:hDn::l:eit:d::r:g::G:p:c:"; // no fork option
 	#endif
 
 	MyGetOptInit(&mgo, argc-1, argv+1, optformat);
@@ -358,6 +361,11 @@
 				else
 					network_conn = NULL;
 			} break;
+#ifdef GPMI
+		case 'a': ttd_strlcpy(_ai.gpmi_param, mgo.opt, sizeof(_ai.gpmi_param)); break;
+#else
+		case 'a': DEBUG(misc, 0)("The -a option only works if GPMI is compiled with OpenTTD."); break;
+#endif /* GPMI */
 		case 'b': _ai.network_client = true; break;
 		case 'r': ParseResolution(resolution, mgo.opt); break;
 		case 'l': language = mgo.opt; break;