1 // NOTE: New commands should be added here. Do not forget to update BOT_CMD_COUNTER
3 #define BOT_CMD_PAUSE 1
4 #define BOT_CMD_CONTINUE 2
7 #define BOT_CMD_MOVETO 5 // Not implemented yet
8 #define BOT_CMD_RESETGOAL 6 // Not implemented yet
11 #define BOT_CMD_ELSE 9
13 #define BOT_CMD_RESETAIM 11
14 #define BOT_CMD_AIM 12
15 #define BOT_CMD_PRESSKEY 13
16 #define BOT_CMD_RELEASEKEY 14
17 #define BOT_CMD_SELECTWEAPON 15
18 #define BOT_CMD_IMPULSE 16
19 #define BOT_CMD_WAIT_UNTIL 17
20 #define BOT_CMD_RESETQUEUE 18
21 #define BOT_CMD_WHILE 19 // TODO: Not implemented yet
22 #define BOT_CMD_WEND 20 // TODO: Not implemented yet
23 #define BOT_CMD_CHASE 20 // TODO: Not implemented yet
25 #define BOT_CMD_COUNTER 19 // Update this value if you add/remove a command
27 // NOTE: Following commands should be implemented on the bot ai
28 // If a new command should be handled by the target ai(s) please declare it here
29 .float(vector) cmd_moveto;
30 .float() cmd_resetgoal;
33 #define BOT_CMD_PARAMETER_NONE 0
34 #define BOT_CMD_PARAMETER_FLOAT 1
35 #define BOT_CMD_PARAMETER_STRING 2
36 #define BOT_CMD_PARAMETER_VECTOR 3
37 #define BOT_CMD_PARAMETER_FLOAT_RELATIVE_TO_TIME 4
39 float bot_cmds_initialized;
40 float bot_cmd_parm_type[BOT_CMD_COUNTER];
41 string bot_cmd_string[BOT_CMD_COUNTER];
44 entity bot_cmd; // Current command
46 .float is_bot_cmd; // Tells if the entity is a bot command
47 .float bot_cmd_index; // Position of the command in the queue
48 .float bot_cmd_type; // If of command (see the BOT_CMD_* defines)
49 .float bot_cmd_parm_float; // Field to store a float parameter
50 .string bot_cmd_parm_string; // Field to store a string parameter
51 .vector bot_cmd_parm_vector; // Field to store a vector parameter
52 .float bot_cmd_execution_counter; // How many times this command on the queue was executed
54 .float bot_cmd_execution_index; // Position in the queue of the command to be executed
55 .float bot_cmd_queue_index; // Position of the last command in the queue
57 // Initialize global commands list
58 // NOTE: New commands should be initialized here
59 void bot_commands_init()
61 bot_cmd_string[BOT_CMD_NULL] = "";
62 bot_cmd_parm_type[BOT_CMD_NULL] = BOT_CMD_PARAMETER_NONE;
64 bot_cmd_string[BOT_CMD_PAUSE] = "pause";
65 bot_cmd_parm_type[BOT_CMD_PAUSE] = BOT_CMD_PARAMETER_NONE;
67 bot_cmd_string[BOT_CMD_CONTINUE] = "continue";
68 bot_cmd_parm_type[BOT_CMD_CONTINUE] = BOT_CMD_PARAMETER_NONE;
70 bot_cmd_string[BOT_CMD_WAIT] = "wait";
71 bot_cmd_parm_type[BOT_CMD_WAIT] = BOT_CMD_PARAMETER_FLOAT;
73 bot_cmd_string[BOT_CMD_TURN] = "turn";
74 bot_cmd_parm_type[BOT_CMD_TURN] = BOT_CMD_PARAMETER_FLOAT;
76 bot_cmd_string[BOT_CMD_MOVETO] = "moveto";
77 bot_cmd_parm_type[BOT_CMD_MOVETO] = BOT_CMD_PARAMETER_VECTOR;
79 bot_cmd_string[BOT_CMD_RESETGOAL] = "resetgoal";
80 bot_cmd_parm_type[BOT_CMD_RESETGOAL] = BOT_CMD_PARAMETER_NONE;
82 bot_cmd_string[BOT_CMD_CC] = "cc";
83 bot_cmd_parm_type[BOT_CMD_CC] = BOT_CMD_PARAMETER_STRING;
85 bot_cmd_string[BOT_CMD_IF] = "if";
86 bot_cmd_parm_type[BOT_CMD_IF] = BOT_CMD_PARAMETER_STRING;
88 bot_cmd_string[BOT_CMD_ELSE] = "else";
89 bot_cmd_parm_type[BOT_CMD_ELSE] = BOT_CMD_PARAMETER_NONE;
91 bot_cmd_string[BOT_CMD_FI] = "fi";
92 bot_cmd_parm_type[BOT_CMD_FI] = BOT_CMD_PARAMETER_NONE;
94 bot_cmd_string[BOT_CMD_RESETAIM] = "resetaim";
95 bot_cmd_parm_type[BOT_CMD_RESETAIM] = BOT_CMD_PARAMETER_NONE;
97 bot_cmd_string[BOT_CMD_AIM] = "aim";
98 bot_cmd_parm_type[BOT_CMD_AIM] = BOT_CMD_PARAMETER_STRING;
100 bot_cmd_string[BOT_CMD_PRESSKEY] = "presskey";
101 bot_cmd_parm_type[BOT_CMD_PRESSKEY] = BOT_CMD_PARAMETER_STRING;
103 bot_cmd_string[BOT_CMD_RELEASEKEY] = "releasekey";
104 bot_cmd_parm_type[BOT_CMD_RELEASEKEY] = BOT_CMD_PARAMETER_STRING;
106 bot_cmd_string[BOT_CMD_SELECTWEAPON] = "selectweapon";
107 bot_cmd_parm_type[BOT_CMD_SELECTWEAPON] = BOT_CMD_PARAMETER_FLOAT;
109 bot_cmd_string[BOT_CMD_IMPULSE] = "impulse";
110 bot_cmd_parm_type[BOT_CMD_IMPULSE] = BOT_CMD_PARAMETER_FLOAT;
112 bot_cmd_string[BOT_CMD_WAIT_UNTIL] = "wait_until";
113 bot_cmd_parm_type[BOT_CMD_WAIT_UNTIL] = BOT_CMD_PARAMETER_FLOAT_RELATIVE_TO_TIME;
115 bot_cmd_string[BOT_CMD_RESETQUEUE] = "resetqueue";
116 bot_cmd_parm_type[BOT_CMD_RESETQUEUE] = BOT_CMD_PARAMETER_NONE;
118 bot_cmds_initialized = TRUE;
121 // Returns first bot with matching name
122 entity find_bot_by_name(string name)
126 bot = findchainflags(flags, FL_CLIENT);
129 if(clienttype(bot) == CLIENTTYPE_BOT)
130 if(bot.netname==name)
139 // Returns a bot by number on list
140 entity find_bot_by_number(float number)
145 bot = findchainflags(flags, FL_CLIENT);
148 if(clienttype(bot) == CLIENTTYPE_BOT)
159 void bot_clearqueue()
161 entity head, newhead;
163 head = findchainfloat(is_bot_cmd, TRUE);
168 newhead = head.chain;
176 self.bot_cmd_queue_index = 0;
177 self.bot_cmd_execution_index = 0;
180 entity bot_spawncmd(entity bot, float type)
184 bot.bot_cmd_queue_index++;
188 cmd.is_bot_cmd = TRUE;
189 cmd.bot_cmd_type = type;
190 cmd.bot_cmd_index = bot.bot_cmd_queue_index;
195 void bot_debugcmd(entity cmd)
197 print(strcat("Owner: ",cmd.owner.netname, "\n"));
198 print(strcat("Cmd Type: ",ftos(cmd.bot_cmd_type), "\n"));
199 print(strcat("Cmd Index: ",ftos(cmd.bot_cmd_index), "\n"));
201 print(strcat("Param Float: ",ftos(cmd.bot_cmd_parm_float), "\n"));
202 print(strcat("Param String: ",cmd.bot_cmd_parm_string, "\n"));
203 print(strcat("Param Vector: ",vtos(cmd.bot_cmd_parm_vector), "\n"));
205 print(strcat("Bot queue index: ", ftos(cmd.owner.bot_cmd_queue_index), "\n"));
206 print(strcat("Bot execution index: ", ftos(cmd.owner.bot_cmd_execution_index), "\n\n"));
209 void bot_queuecommand(entity bot, string cmdstring, string parm)
212 local float cmd_parm_type, i;
217 if(!bot_cmds_initialized)
220 for(i=1;i<BOT_CMD_COUNTER;++i)
222 if(bot_cmd_string[i]!=cmdstring)
225 cmd_parm_type = bot_cmd_parm_type[i];
227 if(cmd_parm_type!=BOT_CMD_PARAMETER_NONE&&parm=="")
229 print("ERROR: A parameter is required for this command\n");
233 // Load command into queue
234 cmd = bot_spawncmd(bot, i);
237 switch(cmd_parm_type)
239 case BOT_CMD_PARAMETER_FLOAT:
240 cmd.bot_cmd_parm_float = stof(parm);
242 case BOT_CMD_PARAMETER_FLOAT_RELATIVE_TO_TIME:
243 cmd.bot_cmd_parm_float = stof(parm) + time;
245 case BOT_CMD_PARAMETER_STRING:
246 cmd.bot_cmd_parm_string = strzone(parm);
248 case BOT_CMD_PARAMETER_VECTOR:
249 cmd.bot_cmd_parm_vector = stov(parm);
256 print("ERROR: No such command\n");
259 void bot_cmdhelp(string scmd)
261 local float i, ntype;
264 if(!bot_cmds_initialized)
267 for(i=1;i<BOT_CMD_COUNTER;++i)
269 if(bot_cmd_string[i]!=scmd)
272 ntype = bot_cmd_parm_type[i];
276 case BOT_CMD_PARAMETER_FLOAT:
277 case BOT_CMD_PARAMETER_FLOAT_RELATIVE_TO_TIME:
278 stype = "float number";
280 case BOT_CMD_PARAMETER_STRING:
283 case BOT_CMD_PARAMETER_VECTOR:
291 print(strcat("Command: ",bot_cmd_string[i],"\nParameter: <",stype,"> \n"));
293 print("Description: ");
297 print("Stops the bot completely. Any command other than 'continue' will be ignored.");
299 case BOT_CMD_CONTINUE:
300 print("Disable paused status");
303 print("Pause command parsing and bot ai for N seconds. Pressed key will remain pressed");
305 case BOT_CMD_WAIT_UNTIL:
306 print("Pause command parsing and bot ai until time is N from NOW (when the command is added). Pressed key will remain pressed");
309 print("Look to the right or left N degrees. For turning to the left use positive numbers.");
312 print("Walk to an specific coordinate on the map. Usage: moveto \"x y z\"");
314 case BOT_CMD_RESETGOAL:
315 print("Resets the goal stack");
318 print("Execute client command. Examples: cc \"say something\"; cc god; cc \"name newnickname\"; cc kill;");
321 print("Perform simple conditional execution.\n");
323 print(" sv_cmd .. if \"condition\"\n");
324 print(" sv_cmd .. <instruction if true>\n");
325 print(" sv_cmd .. <instruction if true>\n");
326 print(" sv_cmd .. else\n");
327 print(" sv_cmd .. <instruction if false>\n");
328 print(" sv_cmd .. <instruction if false>\n");
329 print(" sv_cmd .. fi\n");
330 print("Conditions: a=b, a>b, a<b, a\t\t(spaces not allowed)\n");
331 print(" Values in conditions can be numbers, cvars in the form cvar.cvar_string or special fields\n");
332 print("Fields: health, speed, flagcarrier\n");
333 print("Examples: if health>50; if health>cvar.g_balance_laser_primary_damage; if flagcarrier;");
335 case BOT_CMD_RESETAIM:
336 print("Points the aim to the coordinates x,y 0,0");
339 print("Move the aim x/y (horizontal/vertical) degrees relatives to the bot\n");
340 print("There is a 3rd optional parameter telling in how many seconds the aim has to reach the new position\n");
341 print("Examples: aim \"90 0\" // Turn 90 degrees inmediately (positive numbers move to the left/up)\n");
342 print(" aim \"0 90 2\" // Will gradually look to the sky in the next two seconds");
344 case BOT_CMD_PRESSKEY:
345 print("Press one of the following keys: forward, backward, left, right, jump, crouch, attack1, attack2, use\n");
346 print("Multiple keys can be pressed at time (with many presskey calls) and it will remain pressed until the command \"releasekey\" is called");
347 print("Note: The script will not return the control to the bot ai until all keys are released");
349 case BOT_CMD_RELEASEKEY:
350 print("Release previoulsy used keys. Use the parameter \"all\" to release all keys");
353 print("This command has no description yet.");
360 void bot_list_commands()
365 if(!bot_cmds_initialized)
368 print("List of all available commands:\n");
369 print(" Command\t\t\t\tParameter Type\n");
371 for(i=1;i<BOT_CMD_COUNTER;++i)
373 switch(bot_cmd_parm_type[i])
375 case BOT_CMD_PARAMETER_FLOAT:
376 case BOT_CMD_PARAMETER_FLOAT_RELATIVE_TO_TIME:
377 ptype = "float number";
379 case BOT_CMD_PARAMETER_STRING:
382 case BOT_CMD_PARAMETER_VECTOR:
389 print(strcat(" ",bot_cmd_string[i],"\t\t\t\t<",ptype,"> \n"));
394 .float bot_exec_status;
396 #define BOT_EXEC_STATUS_IDLE 0
397 #define BOT_EXEC_STATUS_PAUSED 1
398 #define BOT_EXEC_STATUS_WAITING 2
400 #define CMD_STATUS_EXECUTING 0
401 #define CMD_STATUS_FINISHED 1
402 #define CMD_STATUS_ERROR 2
406 clientcommand(self,bot_cmd.bot_cmd_parm_string);
407 return CMD_STATUS_FINISHED;
410 float bot_cmd_impulse()
412 self.impulse = bot_cmd.bot_cmd_parm_float;
413 return CMD_STATUS_FINISHED;
416 float bot_cmd_continue()
418 self.bot_exec_status &~= BOT_EXEC_STATUS_PAUSED;
419 return CMD_STATUS_FINISHED;
422 .float bot_cmd_wait_time;
425 if(self.bot_exec_status & BOT_EXEC_STATUS_WAITING)
427 if(time>=self.bot_cmd_wait_time)
429 self.bot_exec_status &~= BOT_EXEC_STATUS_WAITING;
430 return CMD_STATUS_FINISHED;
433 return CMD_STATUS_EXECUTING;
436 self.bot_cmd_wait_time = time + bot_cmd.bot_cmd_parm_float;
437 self.bot_exec_status |= BOT_EXEC_STATUS_WAITING;
438 return CMD_STATUS_EXECUTING;
441 float bot_cmd_wait_until()
443 if(time < bot_cmd.bot_cmd_parm_float)
445 self.bot_exec_status |= BOT_EXEC_STATUS_WAITING;
446 return CMD_STATUS_EXECUTING;
448 self.bot_exec_status &~= BOT_EXEC_STATUS_WAITING;
449 return CMD_STATUS_FINISHED;
454 self.v_angle_y = self.v_angle_y + bot_cmd.bot_cmd_parm_float;
455 self.v_angle_y = self.v_angle_y - floor(self.v_angle_y / 360) * 360;
456 return CMD_STATUS_FINISHED;
459 float bot_cmd_select_weapon()
463 id = bot_cmd.bot_cmd_parm_float;
465 if(id < WEP_FIRST || id > WEP_LAST)
466 return CMD_STATUS_ERROR;
468 if(client_hasweapon(self, id, TRUE, FALSE))
469 self.switchweapon = id;
471 return CMD_STATUS_FINISHED;
474 .float bot_cmd_condition_status;
476 #define CMD_CONDITION_NONE 0
477 #define CMD_CONDITION_TRUE 1
478 #define CMD_CONDITION_FALSE 2
479 #define CMD_CONDITION_TRUE_BLOCK 4
480 #define CMD_CONDITION_FALSE_BLOCK 8
482 float bot_cmd_eval(string expr)
484 // Search for numbers
485 if(strstrofs("0123456789", substring(expr, 0, 1), 0) >= 0)
491 if(substring(expr, 0, 5)=="cvar.")
493 return cvar(substring(expr, 5, strlen(expr)));
502 return vlen(self.velocity);
504 return ((self.flagcarried!=world));
507 print(strcat("ERROR: Unable to convert the expression '",expr,"' into a numeric value\n"));
513 local string expr, val_a, val_b;
516 if(self.bot_cmd_condition_status != CMD_CONDITION_NONE)
518 // Only one "if" block is allowed at time
519 print("ERROR: Only one conditional block can be processed at time");
521 return CMD_STATUS_ERROR;
524 self.bot_cmd_condition_status |= CMD_CONDITION_TRUE_BLOCK;
526 // search for operators
527 expr = bot_cmd.bot_cmd_parm_string;
529 cmpofs = strstrofs(expr,"=",0);
533 val_a = substring(expr,0,cmpofs);
534 val_b = substring(expr,cmpofs+1,strlen(expr));
536 if(bot_cmd_eval(val_a)==bot_cmd_eval(val_b))
537 self.bot_cmd_condition_status |= CMD_CONDITION_TRUE;
539 self.bot_cmd_condition_status |= CMD_CONDITION_FALSE;
541 return CMD_STATUS_FINISHED;
544 cmpofs = strstrofs(expr,">",0);
548 val_a = substring(expr,0,cmpofs);
549 val_b = substring(expr,cmpofs+1,strlen(expr));
551 if(bot_cmd_eval(val_a)>bot_cmd_eval(val_b))
552 self.bot_cmd_condition_status |= CMD_CONDITION_TRUE;
554 self.bot_cmd_condition_status |= CMD_CONDITION_FALSE;
556 return CMD_STATUS_FINISHED;
559 cmpofs = strstrofs(expr,"<",0);
563 val_a = substring(expr,0,cmpofs);
564 val_b = substring(expr,cmpofs+1,strlen(expr));
566 if(bot_cmd_eval(val_a)<bot_cmd_eval(val_b))
567 self.bot_cmd_condition_status |= CMD_CONDITION_TRUE;
569 self.bot_cmd_condition_status |= CMD_CONDITION_FALSE;
571 return CMD_STATUS_FINISHED;
574 if(bot_cmd_eval(expr))
575 self.bot_cmd_condition_status |= CMD_CONDITION_TRUE;
577 self.bot_cmd_condition_status |= CMD_CONDITION_FALSE;
579 return CMD_STATUS_FINISHED;
584 self.bot_cmd_condition_status &~= CMD_CONDITION_TRUE_BLOCK;
585 self.bot_cmd_condition_status |= CMD_CONDITION_FALSE_BLOCK;
586 return CMD_STATUS_FINISHED;
591 self.bot_cmd_condition_status = CMD_CONDITION_NONE;
592 return CMD_STATUS_FINISHED;
595 float bot_cmd_resetaim()
597 self.v_angle = '0 0 0';
598 return CMD_STATUS_FINISHED;
601 .float bot_cmd_aim_begintime;
602 .float bot_cmd_aim_endtime;
603 .vector bot_cmd_aim_begin;
604 .vector bot_cmd_aim_end;
609 if(self.bot_cmd_aim_endtime)
611 local float progress;
613 progress = min(1 - (self.bot_cmd_aim_endtime - time) / (self.bot_cmd_aim_endtime - self.bot_cmd_aim_begintime),1);
614 self.v_angle = self.bot_cmd_aim_begin + ((self.bot_cmd_aim_end - self.bot_cmd_aim_begin) * progress);
616 if(time>=self.bot_cmd_aim_endtime)
618 self.bot_cmd_aim_endtime = 0;
619 return CMD_STATUS_FINISHED;
622 return CMD_STATUS_EXECUTING;
625 // New aiming direction
627 local float tokens, step;
629 parms = bot_cmd.bot_cmd_parm_string;
631 tokens = tokenizebyseparator(parms, " ");
635 self.v_angle_x -= stof(argv(1));
636 self.v_angle_y += stof(argv(0));
637 return CMD_STATUS_FINISHED;
640 if(tokens<1||tokens>3)
641 return CMD_STATUS_ERROR;
643 step = stof(argv(2));
645 self.bot_cmd_aim_begin = self.v_angle;
647 self.bot_cmd_aim_end_x = self.v_angle_x - stof(argv(1));
648 self.bot_cmd_aim_end_y = self.v_angle_y + stof(argv(0));
649 self.bot_cmd_aim_end_z = 0;
651 self.bot_cmd_aim_begintime = time;
652 self.bot_cmd_aim_endtime = time + step;
654 return CMD_STATUS_EXECUTING;
659 #define BOT_CMD_KEY_NONE 0
660 #define BOT_CMD_KEY_FORWARD 1
661 #define BOT_CMD_KEY_BACKWARD 2
662 #define BOT_CMD_KEY_RIGHT 4
663 #define BOT_CMD_KEY_LEFT 8
664 #define BOT_CMD_KEY_JUMP 16
665 #define BOT_CMD_KEY_ATTACK1 32
666 #define BOT_CMD_KEY_ATTACK2 64
667 #define BOT_CMD_KEY_USE 128
668 #define BOT_CMD_KEY_HOOK 256
669 #define BOT_CMD_KEY_CROUCH 512
671 float bot_presskeys()
673 self.movement = '0 0 0';
675 if(self.bot_cmd_keys == BOT_CMD_KEY_NONE)
678 if(self.bot_cmd_keys & BOT_CMD_KEY_FORWARD)
679 self.movement_x = cvar("sv_maxspeed");
680 else if(self.bot_cmd_keys & BOT_CMD_KEY_BACKWARD)
681 self.movement_x = -cvar("sv_maxspeed");
683 if(self.bot_cmd_keys & BOT_CMD_KEY_RIGHT)
684 self.movement_y = cvar("sv_maxspeed");
685 else if(self.bot_cmd_keys & BOT_CMD_KEY_LEFT)
686 self.movement_y = -cvar("sv_maxspeed");
688 if(self.bot_cmd_keys & BOT_CMD_KEY_JUMP)
689 self.BUTTON_JUMP = TRUE;
691 if(self.bot_cmd_keys & BOT_CMD_KEY_CROUCH)
692 self.BUTTON_CROUCH = TRUE;
694 if(self.bot_cmd_keys & BOT_CMD_KEY_ATTACK1)
695 self.BUTTON_ATCK = TRUE;
697 if(self.bot_cmd_keys & BOT_CMD_KEY_ATTACK2)
698 self.BUTTON_ATCK2 = TRUE;
700 if(self.bot_cmd_keys & BOT_CMD_KEY_USE)
701 self.BUTTON_USE = TRUE;
707 float bot_cmd_keypress_handler(string key, float enabled)
713 self.bot_cmd_keys = power2of(20) - 1; // >:)
715 self.bot_cmd_keys = BOT_CMD_KEY_NONE;
719 self.bot_cmd_keys |= BOT_CMD_KEY_FORWARD;
720 self.bot_cmd_keys &~= BOT_CMD_KEY_BACKWARD;
723 self.bot_cmd_keys &~= BOT_CMD_KEY_FORWARD;
728 self.bot_cmd_keys |= BOT_CMD_KEY_BACKWARD;
729 self.bot_cmd_keys &~= BOT_CMD_KEY_FORWARD;
732 self.bot_cmd_keys &~= BOT_CMD_KEY_BACKWARD;
737 self.bot_cmd_keys |= BOT_CMD_KEY_LEFT;
738 self.bot_cmd_keys &~= BOT_CMD_KEY_RIGHT;
741 self.bot_cmd_keys &~= BOT_CMD_KEY_LEFT;
746 self.bot_cmd_keys |= BOT_CMD_KEY_RIGHT;
747 self.bot_cmd_keys &~= BOT_CMD_KEY_LEFT;
750 self.bot_cmd_keys &~= BOT_CMD_KEY_RIGHT;
754 self.bot_cmd_keys |= BOT_CMD_KEY_JUMP;
756 self.bot_cmd_keys &~= BOT_CMD_KEY_JUMP;
760 self.bot_cmd_keys |= BOT_CMD_KEY_CROUCH;
762 self.bot_cmd_keys &~= BOT_CMD_KEY_CROUCH;
766 self.bot_cmd_keys |= BOT_CMD_KEY_ATTACK1;
768 self.bot_cmd_keys &~= BOT_CMD_KEY_ATTACK1;
772 self.bot_cmd_keys |= BOT_CMD_KEY_ATTACK2;
774 self.bot_cmd_keys &~= BOT_CMD_KEY_ATTACK2;
778 self.bot_cmd_keys |= BOT_CMD_KEY_USE;
780 self.bot_cmd_keys &~= BOT_CMD_KEY_USE;
786 return CMD_STATUS_FINISHED;
789 float bot_cmd_presskey()
793 key = bot_cmd.bot_cmd_parm_string;
795 bot_cmd_keypress_handler(key,TRUE);
797 return CMD_STATUS_FINISHED;
800 float bot_cmd_releasekey()
804 key = bot_cmd.bot_cmd_parm_string;
806 return bot_cmd_keypress_handler(key,FALSE);
809 float bot_cmd_pause()
814 self.BUTTON_ATCK = 0;
815 self.BUTTON_JUMP = 0;
816 self.BUTTON_HOOK = 0;
817 self.BUTTON_CHAT = 0;
818 self.BUTTON_ATCK2 = 0;
819 self.BUTTON_CROUCH = 0;
821 self.movement = '0 0 0';
822 self.bot_cmd_keys = BOT_CMD_KEY_NONE;
824 self.bot_exec_status = self.bot_exec_status | BOT_EXEC_STATUS_PAUSED;
825 return CMD_STATUS_FINISHED;
828 float bot_cmd_moveto()
830 return self.cmd_moveto(bot_cmd.bot_cmd_parm_vector);
833 float bot_cmd_resetgoal()
835 return self.cmd_resetgoal();
838 void bot_command_executed(float rm)
844 self.bot_cmd_execution_index++;
848 if(bot_cmd_parm_type[cmd.bot_cmd_type]==BOT_CMD_PARAMETER_STRING)
850 strunzone(cmd.bot_cmd_parm_string);
856 cmd.bot_cmd_execution_counter++;
859 void bot_setcurrentcommand()
865 if(self.bot_cmd_execution_index==0)
866 self.bot_cmd_execution_index=1;
868 for (cmd = findchainfloat(bot_cmd_index, self.bot_cmd_execution_index); cmd; cmd = cmd.chain)
878 // This function should be (the only) called directly from the bot ai loop
879 // It maps commands to functions and deal with complex interactions between commands and execution states
880 // NOTE: Of course you need to include your commands here too :)
881 float bot_execute_commands()
883 local float status, ispressingkey;
887 bot_setcurrentcommand();
889 // Keep pressing keys raised by the "presskey" command
890 ispressingkey = bot_presskeys();
893 return ispressingkey;
895 // Ignore all commands except continue when the bot is paused
896 if(self.bot_exec_status & BOT_EXEC_STATUS_PAUSED)
897 if(bot_cmd.bot_cmd_type!=BOT_CMD_CONTINUE)
899 if(bot_cmd.bot_cmd_type!=BOT_CMD_NULL)
901 bot_command_executed(TRUE);
902 print( "WARNING: Commands are ignored while the bot is paused. Use the command 'continue' instead.\n");
908 if not(bot_cmd.bot_cmd_type==BOT_CMD_FI||bot_cmd.bot_cmd_type==BOT_CMD_ELSE)
909 if(self.bot_cmd_condition_status & CMD_CONDITION_TRUE && self.bot_cmd_condition_status & CMD_CONDITION_FALSE_BLOCK)
911 bot_command_executed(TRUE);
914 else if(self.bot_cmd_condition_status & CMD_CONDITION_FALSE && self.bot_cmd_condition_status & CMD_CONDITION_TRUE_BLOCK)
916 bot_command_executed(TRUE);
920 // Map commands to functions
921 switch(bot_cmd.bot_cmd_type)
924 return ispressingkey;
927 status = bot_cmd_pause();
929 case BOT_CMD_CONTINUE:
930 status = bot_cmd_continue();
933 status = bot_cmd_wait();
935 case BOT_CMD_WAIT_UNTIL:
936 status = bot_cmd_wait_until();
939 status = bot_cmd_turn();
942 status = bot_cmd_moveto();
944 case BOT_CMD_RESETGOAL:
945 status = bot_cmd_resetgoal();
948 status = bot_cmd_cc();
951 status = bot_cmd_if();
954 status = bot_cmd_else();
957 status = bot_cmd_fi();
959 case BOT_CMD_RESETAIM:
960 status = bot_cmd_resetaim();
963 status = bot_cmd_aim();
965 case BOT_CMD_PRESSKEY:
966 status = bot_cmd_presskey();
968 case BOT_CMD_RELEASEKEY:
969 status = bot_cmd_releasekey();
971 case BOT_CMD_SELECTWEAPON:
972 status = bot_cmd_select_weapon();
974 case BOT_CMD_IMPULSE:
975 status = bot_cmd_impulse();
977 case BOT_CMD_RESETQUEUE:
979 status = CMD_STATUS_FINISHED;
982 print(strcat("ERROR: Invalid command on queue with id '",ftos(bot_cmd.bot_cmd_type),"'\n"));
986 if (status==CMD_STATUS_ERROR)
987 print(strcat("ERROR: The command '",bot_cmd_string[bot_cmd.bot_cmd_type],"' returned an error status\n"));
989 // Move execution pointer
990 if(status==CMD_STATUS_EXECUTING)
996 if(cvar("g_debug_bot_commands"))
1000 switch(bot_cmd_parm_type[bot_cmd.bot_cmd_type])
1002 case BOT_CMD_PARAMETER_FLOAT:
1003 case BOT_CMD_PARAMETER_FLOAT_RELATIVE_TO_TIME:
1004 parms = ftos(bot_cmd.bot_cmd_parm_float);
1006 case BOT_CMD_PARAMETER_STRING:
1007 parms = bot_cmd.bot_cmd_parm_string;
1009 case BOT_CMD_PARAMETER_VECTOR:
1010 parms = vtos(bot_cmd.bot_cmd_parm_vector);
1016 clientcommand(self,strcat("say ^7", bot_cmd_string[bot_cmd.bot_cmd_type]," ",parms,"\n"));
1019 bot_command_executed(TRUE);
1022 if(status>-1) // Always true, just to fix a compiler warning