[nexuiz-commits] r7011 - trunk/data/qcsrc/server

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Fri Jun 12 14:51:04 EDT 2009


Author: div0
Date: 2009-06-12 14:51:04 -0400 (Fri, 12 Jun 2009)
New Revision: 7011

Modified:
   trunk/data/qcsrc/server/bots_scripting.qc
   trunk/data/qcsrc/server/cl_weaponsystem.qc
   trunk/data/qcsrc/server/gamecommand.qc
Log:
yay! dynamic assignment of places for bot scripting :)


Modified: trunk/data/qcsrc/server/bots_scripting.qc
===================================================================
--- trunk/data/qcsrc/server/bots_scripting.qc	2009-06-12 15:04:06 UTC (rev 7010)
+++ trunk/data/qcsrc/server/bots_scripting.qc	2009-06-12 18:51:04 UTC (rev 7011)
@@ -63,7 +63,52 @@
 	return 1;
 }
 
+#define MAX_BOT_PLACES 4
+.float bot_places_count;
+.entity bot_places[MAX_BOT_PLACES];
+.string bot_placenames[MAX_BOT_PLACES];
+entity bot_getplace(string placename)
+{
+	entity e;
+	if(substring(placename, 0, 1) == "$")
+	{
+		float i, p;
+		placename = substring(placename, 1, -1);
+		string s, s2;
+		for(i = 0; i < self.bot_places_count; ++i)
+			if(self.(bot_placenames[i]) == placename)
+				return self.(bot_places[i]);
+		// now: i == self.bot_places_count
+		s = s2 = cvar_string(placename);
+		p = strstrofs(s2, " ", 0);
+		if(p >= 0)
+		{
+			s = substring(s2, 0, p);
+			//print("places: ", placename, " -> ", cvar_string(placename), "\n");
+			cvar_set(placename, strcat(substring(s2, p+1, -1), " ", s));
+			//print("places: ", placename, " := ", cvar_string(placename), "\n");
+		}
+		e = find(world, targetname, s);
+		if(!e)
+			print("invalid place ", s, "\n");
+		if(i < MAX_BOT_PLACES)
+		{
+			self.(bot_placenames[i]) = strzone(placename);
+			self.(bot_places[i]) = e;
+			self.bot_places_count += 1;
+		}
+		return e;
+	}
+	else
+	{
+		e = find(world, targetname, placename);
+		if(!e)
+			print("invalid place ", s, "\n");
+		return e;
+	}
+}
 
+
 // NOTE: New commands should be added here. Do not forget to update BOT_CMD_COUNTER
 #define BOT_CMD_NULL			0
 #define BOT_CMD_PAUSE			1
@@ -757,7 +802,7 @@
 
 	tokens = tokenizebyseparator(parms, " ");
 
-	e = find(world, targetname, argv(0));
+	e = bot_getplace(argv(0));
 	if(!e)
 		return CMD_STATUS_ERROR;
 
@@ -983,7 +1028,7 @@
 float bot_cmd_movetotarget()
 {
 	entity e;
-	e = find(world, targetname, bot_cmd.bot_cmd_parm_string);
+	e = bot_getplace(bot_cmd.bot_cmd_parm_string);
 	if(!e)
 		return CMD_STATUS_ERROR;
 	return self.cmd_moveto(e.origin + (e.mins + e.maxs) * 0.5);
@@ -1052,15 +1097,19 @@
 void bot_resetqueues()
 {
 	entity cl;
+	float i;
 
 	FOR_EACH_CLIENT(cl) if(cl.isbot)
 	{
 		bot_clearqueue(cl);
 		// also, cancel all barriers
-		FOR_EACH_CLIENT(cl) if(cl.isbot)
+		cl.bot_barrier = 0;
+		for(i = 0; i < cl.bot_places_count; ++i)
 		{
-			cl.bot_barrier = 0;
+			strunzone(cl.(bot_placenames[i]));
+			cl.(bot_placenames[i]) = string_null;
 		}
+		cl.bot_places_count = 0;
 	}
 
 	bot_barriertime = time;

Modified: trunk/data/qcsrc/server/cl_weaponsystem.qc
===================================================================
--- trunk/data/qcsrc/server/cl_weaponsystem.qc	2009-06-12 15:04:06 UTC (rev 7010)
+++ trunk/data/qcsrc/server/cl_weaponsystem.qc	2009-06-12 18:51:04 UTC (rev 7011)
@@ -902,6 +902,7 @@
 			if (!f)
 			{
 				if (complain)
+				if(clienttype(cl) == CLIENTTYPE_REAL)
 				{
 					play2(cl, "weapons/unavailable.wav");
 					sprint(cl, strcat("You don't have any ammo for the ^2", W_Name(wpn), "\n"));

Modified: trunk/data/qcsrc/server/gamecommand.qc
===================================================================
--- trunk/data/qcsrc/server/gamecommand.qc	2009-06-12 15:04:06 UTC (rev 7010)
+++ trunk/data/qcsrc/server/gamecommand.qc	2009-06-12 18:51:04 UTC (rev 7011)
@@ -959,12 +959,19 @@
 			while((s = fgets(fh)))
 			{
 				argc = tokenize_console(s);
-				// let's start at token 2 so we can skip sv_cmd bot_cmd
-				bot = find_bot_by_name(argv(2));
-				if(bot == world)
-					bot = find_bot_by_number(stof(argv(2)));
-				if(bot)
-					bot_queuecommand(bot, strcat(argv(3), " ", argv(4)));
+
+				if(argc >= 3 && argv(0) == "sv_cmd" && argv(1) == "bot_cmd")
+				{
+					// let's start at token 2 so we can skip sv_cmd bot_cmd
+					bot = find_bot_by_name(argv(2));
+					if(bot == world)
+						bot = find_bot_by_number(stof(argv(2)));
+					if(bot)
+						bot_queuecommand(bot, strcat(argv(3), " ", argv(4)));
+				}
+				else
+					localcmd(s, "\n");
+
 				++i;
 			}
 



More information about the nexuiz-commits mailing list