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

DONOTREPLY at icculus.org DONOTREPLY at icculus.org
Wed Jun 10 03:07:05 EDT 2009


Author: div0
Date: 2009-06-10 03:07:02 -0400 (Wed, 10 Jun 2009)
New Revision: 6953

Modified:
   trunk/data/qcsrc/server/bots_scripting.qc
Log:
bot scripting: new commands movetotarget, aimtarget.

With specially made maps (with targets having a defined targetname), this allows scripting e.g. shooting buttons


Modified: trunk/data/qcsrc/server/bots_scripting.qc
===================================================================
--- trunk/data/qcsrc/server/bots_scripting.qc	2009-06-10 06:52:05 UTC (rev 6952)
+++ trunk/data/qcsrc/server/bots_scripting.qc	2009-06-10 07:07:02 UTC (rev 6953)
@@ -18,11 +18,13 @@
 #define BOT_CMD_IMPULSE			16
 #define BOT_CMD_WAIT_UNTIL		17
 #define BOT_CMD_RESETQUEUE		18
-#define BOT_CMD_WHILE			19	// TODO: Not implemented yet
-#define BOT_CMD_WEND			20	// TODO: Not implemented yet
-#define BOT_CMD_CHASE			20	// TODO: Not implemented yet
+#define BOT_CMD_MOVETOTARGET    19
+#define BOT_CMD_AIMTARGET       20
+#define BOT_CMD_WHILE			21	// TODO: Not implemented yet
+#define BOT_CMD_WEND			22	// TODO: Not implemented yet
+#define BOT_CMD_CHASE			23	// TODO: Not implemented yet
 
-#define BOT_CMD_COUNTER			19	// Update this value if you add/remove a command
+#define BOT_CMD_COUNTER			21	// Update this value if you add/remove a command
 
 // NOTE: Following commands should be implemented on the bot ai
 //		 If a new command should be handled by the target ai(s) please declare it here
@@ -79,6 +81,9 @@
 	bot_cmd_string[BOT_CMD_MOVETO]			= "moveto";
 	bot_cmd_parm_type[BOT_CMD_MOVETO]		= BOT_CMD_PARAMETER_VECTOR;
 
+	bot_cmd_string[BOT_CMD_MOVETOTARGET]			= "movetotarget";
+	bot_cmd_parm_type[BOT_CMD_MOVETOTARGET]		= BOT_CMD_PARAMETER_STRING;
+
 	bot_cmd_string[BOT_CMD_RESETGOAL]		= "resetgoal";
 	bot_cmd_parm_type[BOT_CMD_RESETGOAL]		= BOT_CMD_PARAMETER_NONE;
 
@@ -100,6 +105,9 @@
 	bot_cmd_string[BOT_CMD_AIM]			= "aim";
 	bot_cmd_parm_type[BOT_CMD_AIM]			= BOT_CMD_PARAMETER_STRING;
 
+	bot_cmd_string[BOT_CMD_AIMTARGET]			= "aimtarget";
+	bot_cmd_parm_type[BOT_CMD_AIMTARGET]			= BOT_CMD_PARAMETER_STRING;
+
 	bot_cmd_string[BOT_CMD_PRESSKEY]		= "presskey";
 	bot_cmd_parm_type[BOT_CMD_PRESSKEY]		= BOT_CMD_PARAMETER_STRING;
 
@@ -318,6 +326,9 @@
 			case BOT_CMD_MOVETO:
 				print("Walk to an specific coordinate on the map. Usage: moveto \"x y z\"");
 				break;
+			case BOT_CMD_MOVETOTARGET:
+				print("Walk to the specific target on the map");
+				break;
 			case BOT_CMD_RESETGOAL:
 				print("Resets the goal stack");
 				break;
@@ -348,6 +359,9 @@
 				print("Examples: aim \"90 0\"	// Turn 90 degrees inmediately (positive numbers move to the left/up)\n");
 				print("          aim \"0 90 2\"	// Will gradually look to the sky in the next two seconds");
 				break;
+			case BOT_CMD_AIMTARGET:
+				print("Points the aim to given target");
+				break;
 			case BOT_CMD_PRESSKEY:
 				print("Press one of the following keys: forward, backward, left, right, jump, crouch, attack1, attack2, use\n");
 				print("Multiple keys can be pressed at time (with many presskey calls) and it will remain pressed until the command \"releasekey\" is called");
@@ -644,7 +658,7 @@
 		return CMD_STATUS_FINISHED;
 	}
 
-	if(tokens<1||tokens>3)
+	if(tokens<2||tokens>3)
 		return CMD_STATUS_ERROR;
 
 	step = stof(argv(2));
@@ -661,6 +675,48 @@
 	return CMD_STATUS_EXECUTING;
 }
 
+float bot_cmd_aimtarget()
+{
+	if(self.bot_cmd_aim_endtime)
+	{
+		return bot_cmd_aim();
+	}
+
+	local entity e;
+	local string parms;
+	local vector v;
+	local float tokens, step;
+
+	parms = bot_cmd.bot_cmd_parm_string;
+
+	tokens = tokenizebyseparator(parms, " ");
+
+	e = find(world, targetname, argv(0));
+	if(!e)
+		return CMD_STATUS_ERROR;
+
+	v = (e.absmin + e.absmax) * 0.5;
+
+	if(tokens==1)
+	{
+		self.v_angle = vectoangles(v - (self.origin + self.view_ofs));
+		return CMD_STATUS_FINISHED;
+	}
+
+	if(tokens<1||tokens>2)
+		return CMD_STATUS_ERROR;
+
+	step = stof(argv(1));
+
+	self.bot_cmd_aim_begin = self.v_angle;
+	self.bot_cmd_aim_end = vectoangles(v - (self.origin + self.view_ofs));
+
+	self.bot_cmd_aim_begintime = time;
+	self.bot_cmd_aim_endtime = time + step;
+
+	return CMD_STATUS_EXECUTING;
+}
+
 .float bot_cmd_keys;
 
 #define BOT_CMD_KEY_NONE	0
@@ -837,6 +893,15 @@
 	return self.cmd_moveto(bot_cmd.bot_cmd_parm_vector);
 }
 
+float bot_cmd_movetotarget()
+{
+	entity e;
+	e = find(world, targetname, argv(0));
+	if(!e)
+		return CMD_STATUS_ERROR;
+	return self.cmd_moveto((e.absmin + e.absmax) * 0.5);
+}
+
 float bot_cmd_resetgoal()
 {
 	return self.cmd_resetgoal();
@@ -986,6 +1051,9 @@
 		case BOT_CMD_MOVETO:
 			status = bot_cmd_moveto();
 			break;
+		case BOT_CMD_MOVETOTARGET:
+			status = bot_cmd_movetotarget();
+			break;
 		case BOT_CMD_RESETGOAL:
 			status = bot_cmd_resetgoal();
 			break;
@@ -1007,6 +1075,9 @@
 		case BOT_CMD_AIM:
 			status = bot_cmd_aim();
 			break;
+		case BOT_CMD_AIMTARGET:
+			status = bot_cmd_aimtarget();
+			break;
 		case BOT_CMD_PRESSKEY:
 			status = bot_cmd_presskey();
 			break;



More information about the nexuiz-commits mailing list