]> de.git.xonotic.org Git - xonotic/xonotic-data.pk3dir.git/blob - qcsrc/server/bot/scripting.qc
Revert "Merge branch 'TimePath/bot_api' into 'master'\r"
[xonotic/xonotic-data.pk3dir.git] / qcsrc / server / bot / scripting.qc
1 #include "scripting.qh"
2 #include "../_all.qh"
3
4 #include "bot.qh"
5
6 .float bot_cmdqueuebuf_allocated;
7 .float bot_cmdqueuebuf;
8 .float bot_cmdqueuebuf_start;
9 .float bot_cmdqueuebuf_end;
10
11 void bot_clearqueue(entity bot)
12 {
13         if(!bot.bot_cmdqueuebuf_allocated)
14                 return;
15         buf_del(bot.bot_cmdqueuebuf);
16         bot.bot_cmdqueuebuf_allocated = false;
17         LOG_TRACE("bot ", bot.netname, " queue cleared\n");
18 }
19
20 void bot_queuecommand(entity bot, string cmdstring)
21 {
22         if(!bot.bot_cmdqueuebuf_allocated)
23         {
24                 bot.bot_cmdqueuebuf = buf_create();
25                 bot.bot_cmdqueuebuf_allocated = true;
26                 bot.bot_cmdqueuebuf_start = 0;
27                 bot.bot_cmdqueuebuf_end = 0;
28         }
29
30         bufstr_set(bot.bot_cmdqueuebuf, bot.bot_cmdqueuebuf_end, cmdstring);
31
32         // if the command was a "sound" command, precache the sound NOW
33         // this prevents lagging!
34         {
35                 float sp;
36                 string parm;
37                 string cmdstr;
38
39                 sp = strstrofs(cmdstring, " ", 0);
40                 if(sp >= 0)
41                 {
42                         parm = substring(cmdstring, sp + 1, -1);
43                         cmdstr = substring(cmdstring, 0, sp);
44                         if(cmdstr == "sound")
45                         {
46                                 // find the LAST word
47                                 for (;;)
48                                 {
49                                         sp = strstrofs(parm, " ", 0);
50                                         if(sp < 0)
51                                                 break;
52                                         parm = substring(parm, sp + 1, -1);
53                                 }
54                                 precache_sound(parm);
55                         }
56                 }
57         }
58
59         bot.bot_cmdqueuebuf_end += 1;
60 }
61
62 void bot_dequeuecommand(entity bot, float idx)
63 {
64         if(!bot.bot_cmdqueuebuf_allocated)
65                 error("dequeuecommand but no queue allocated");
66         if(idx < bot.bot_cmdqueuebuf_start)
67                 error("dequeueing a command in the past");
68         if(idx >= bot.bot_cmdqueuebuf_end)
69                 error("dequeueing a command in the future");
70         bufstr_set(bot.bot_cmdqueuebuf, idx, "");
71         if(idx == bot.bot_cmdqueuebuf_start)
72                 bot.bot_cmdqueuebuf_start += 1;
73         if(bot.bot_cmdqueuebuf_start >= bot.bot_cmdqueuebuf_end)
74                 bot_clearqueue(bot);
75 }
76
77 string bot_readcommand(entity bot, float idx)
78 {
79         if(!bot.bot_cmdqueuebuf_allocated)
80                 error("readcommand but no queue allocated");
81         if(idx < bot.bot_cmdqueuebuf_start)
82                 error("reading a command in the past");
83         if(idx >= bot.bot_cmdqueuebuf_end)
84                 error("reading a command in the future");
85         return bufstr_get(bot.bot_cmdqueuebuf, idx);
86 }
87
88 float bot_havecommand(entity bot, float idx)
89 {
90         if(!bot.bot_cmdqueuebuf_allocated)
91                 return 0;
92         if(idx < bot.bot_cmdqueuebuf_start)
93                 return 0;
94         if(idx >= bot.bot_cmdqueuebuf_end)
95                 return 0;
96         return 1;
97 }
98
99 const int MAX_BOT_PLACES = 4;
100 .float bot_places_count;
101 .entity bot_places[MAX_BOT_PLACES];
102 .string bot_placenames[MAX_BOT_PLACES];
103 entity bot_getplace(string placename)
104 {SELFPARAM();
105         entity e;
106         if(substring(placename, 0, 1) == "@")
107         {
108                 int i, p;
109                 placename = substring(placename, 1, -1);
110                 string s, s2;
111                 for(i = 0; i < self.bot_places_count; ++i)
112                         if(self.(bot_placenames[i]) == placename)
113                                 return self.(bot_places[i]);
114                 // now: i == self.bot_places_count
115                 s = s2 = cvar_string(placename);
116                 p = strstrofs(s2, " ", 0);
117                 if(p >= 0)
118                 {
119                         s = substring(s2, 0, p);
120                         //print("places: ", placename, " -> ", cvar_string(placename), "\n");
121                         cvar_set(placename, strcat(substring(s2, p+1, -1), " ", s));
122                         //print("places: ", placename, " := ", cvar_string(placename), "\n");
123                 }
124                 e = find(world, targetname, s);
125                 if(!e)
126                         LOG_INFO("invalid place ", s, "\n");
127                 if(i < MAX_BOT_PLACES)
128                 {
129                         self.(bot_placenames[i]) = strzone(placename);
130                         self.(bot_places[i]) = e;
131                         self.bot_places_count += 1;
132                 }
133                 return e;
134         }
135         else
136         {
137                 e = find(world, targetname, placename);
138                 if(!e)
139                         LOG_INFO("invalid place ", placename, "\n");
140                 return e;
141         }
142 }
143
144
145 // Initialize global commands list
146 // NOTE: New commands should be initialized here
147 void bot_commands_init()
148 {
149         bot_cmd_string[BOT_CMD_NULL] = "";
150         bot_cmd_parm_type[BOT_CMD_NULL] = BOT_CMD_PARAMETER_NONE;
151
152         bot_cmd_string[BOT_CMD_PAUSE] = "pause";
153         bot_cmd_parm_type[BOT_CMD_PAUSE] = BOT_CMD_PARAMETER_NONE;
154
155         bot_cmd_string[BOT_CMD_CONTINUE] = "continue";
156         bot_cmd_parm_type[BOT_CMD_CONTINUE] = BOT_CMD_PARAMETER_NONE;
157
158         bot_cmd_string[BOT_CMD_WAIT] = "wait";
159         bot_cmd_parm_type[BOT_CMD_WAIT] = BOT_CMD_PARAMETER_FLOAT;
160
161         bot_cmd_string[BOT_CMD_TURN] = "turn";
162         bot_cmd_parm_type[BOT_CMD_TURN] = BOT_CMD_PARAMETER_FLOAT;
163
164         bot_cmd_string[BOT_CMD_MOVETO] = "moveto";
165         bot_cmd_parm_type[BOT_CMD_MOVETO] = BOT_CMD_PARAMETER_VECTOR;
166
167         bot_cmd_string[BOT_CMD_MOVETOTARGET] = "movetotarget";
168         bot_cmd_parm_type[BOT_CMD_MOVETOTARGET] = BOT_CMD_PARAMETER_STRING;
169
170         bot_cmd_string[BOT_CMD_RESETGOAL] = "resetgoal";
171         bot_cmd_parm_type[BOT_CMD_RESETGOAL] = BOT_CMD_PARAMETER_NONE;
172
173         bot_cmd_string[BOT_CMD_CC] = "cc";
174         bot_cmd_parm_type[BOT_CMD_CC] = BOT_CMD_PARAMETER_STRING;
175
176         bot_cmd_string[BOT_CMD_IF] = "if";
177         bot_cmd_parm_type[BOT_CMD_IF] = BOT_CMD_PARAMETER_STRING;
178
179         bot_cmd_string[BOT_CMD_ELSE] = "else";
180         bot_cmd_parm_type[BOT_CMD_ELSE] = BOT_CMD_PARAMETER_NONE;
181
182         bot_cmd_string[BOT_CMD_FI] = "fi";
183         bot_cmd_parm_type[BOT_CMD_FI] = BOT_CMD_PARAMETER_NONE;
184
185         bot_cmd_string[BOT_CMD_RESETAIM] = "resetaim";
186         bot_cmd_parm_type[BOT_CMD_RESETAIM] = BOT_CMD_PARAMETER_NONE;
187
188         bot_cmd_string[BOT_CMD_AIM] = "aim";
189         bot_cmd_parm_type[BOT_CMD_AIM] = BOT_CMD_PARAMETER_STRING;
190
191         bot_cmd_string[BOT_CMD_AIMTARGET] = "aimtarget";
192         bot_cmd_parm_type[BOT_CMD_AIMTARGET] = BOT_CMD_PARAMETER_STRING;
193
194         bot_cmd_string[BOT_CMD_PRESSKEY] = "presskey";
195         bot_cmd_parm_type[BOT_CMD_PRESSKEY] = BOT_CMD_PARAMETER_STRING;
196
197         bot_cmd_string[BOT_CMD_RELEASEKEY] = "releasekey";
198         bot_cmd_parm_type[BOT_CMD_RELEASEKEY] = BOT_CMD_PARAMETER_STRING;
199
200         bot_cmd_string[BOT_CMD_SELECTWEAPON] = "selectweapon";
201         bot_cmd_parm_type[BOT_CMD_SELECTWEAPON] = BOT_CMD_PARAMETER_FLOAT;
202
203         bot_cmd_string[BOT_CMD_IMPULSE] = "impulse";
204         bot_cmd_parm_type[BOT_CMD_IMPULSE] = BOT_CMD_PARAMETER_FLOAT;
205
206         bot_cmd_string[BOT_CMD_WAIT_UNTIL] = "wait_until";
207         bot_cmd_parm_type[BOT_CMD_WAIT_UNTIL] = BOT_CMD_PARAMETER_FLOAT;
208
209         bot_cmd_string[BOT_CMD_BARRIER] = "barrier";
210         bot_cmd_parm_type[BOT_CMD_BARRIER] = BOT_CMD_PARAMETER_NONE;
211
212         bot_cmd_string[BOT_CMD_CONSOLE] = "console";
213         bot_cmd_parm_type[BOT_CMD_CONSOLE] = BOT_CMD_PARAMETER_STRING;
214
215         bot_cmd_string[BOT_CMD_SOUND] = "sound";
216         bot_cmd_parm_type[BOT_CMD_SOUND] = BOT_CMD_PARAMETER_STRING;
217
218         bot_cmd_string[BOT_CMD_DEBUG_ASSERT_CANFIRE] = "debug_assert_canfire";
219         bot_cmd_parm_type[BOT_CMD_DEBUG_ASSERT_CANFIRE] = BOT_CMD_PARAMETER_FLOAT;
220
221         bot_cmds_initialized = true;
222 }
223
224 // Returns first bot with matching name
225 entity find_bot_by_name(string name)
226 {
227         entity bot;
228
229         bot = findchainflags(flags, FL_CLIENT);
230         while (bot)
231         {
232                 if(IS_BOT_CLIENT(bot))
233                 if(bot.netname==name)
234                         return bot;
235
236                 bot = bot.chain;
237         }
238
239         return world;
240 }
241
242 // Returns a bot by number on list
243 entity find_bot_by_number(float number)
244 {
245         entity bot;
246         float c = 0;
247
248         if(!number)
249                 return world;
250
251         bot = findchainflags(flags, FL_CLIENT);
252         while (bot)
253         {
254                 if(IS_BOT_CLIENT(bot))
255                 {
256                         if(++c==number)
257                                 return bot;
258                 }
259                 bot = bot.chain;
260         }
261
262         return world;
263 }
264
265 float bot_decodecommand(string cmdstring)
266 {
267         float cmd_parm_type;
268         float sp;
269         string parm;
270
271         sp = strstrofs(cmdstring, " ", 0);
272         if(sp < 0)
273         {
274                 parm = "";
275         }
276         else
277         {
278                 parm = substring(cmdstring, sp + 1, -1);
279                 cmdstring = substring(cmdstring, 0, sp);
280         }
281
282         if(!bot_cmds_initialized)
283                 bot_commands_init();
284
285         int i;
286         for(i=1;i<BOT_CMD_COUNTER;++i)
287         {
288                 if(bot_cmd_string[i]!=cmdstring)
289                         continue;
290
291                 cmd_parm_type = bot_cmd_parm_type[i];
292
293                 if(cmd_parm_type!=BOT_CMD_PARAMETER_NONE&&parm=="")
294                 {
295                         LOG_INFO("ERROR: A parameter is required for this command\n");
296                         return 0;
297                 }
298
299                 // Load command into queue
300                 bot_cmd.bot_cmd_type = i;
301
302                 // Attach parameter
303                 switch(cmd_parm_type)
304                 {
305                         case BOT_CMD_PARAMETER_FLOAT:
306                                 bot_cmd.bot_cmd_parm_float = stof(parm);
307                                 break;
308                         case BOT_CMD_PARAMETER_STRING:
309                                 if(bot_cmd.bot_cmd_parm_string)
310                                         strunzone(bot_cmd.bot_cmd_parm_string);
311                                 bot_cmd.bot_cmd_parm_string = strzone(parm);
312                                 break;
313                         case BOT_CMD_PARAMETER_VECTOR:
314                                 bot_cmd.bot_cmd_parm_vector = stov(parm);
315                                 break;
316                         default:
317                                 break;
318                 }
319                 return 1;
320         }
321         LOG_INFO("ERROR: No such command '", cmdstring, "'\n");
322         return 0;
323 }
324
325 void bot_cmdhelp(string scmd)
326 {
327         int i, ntype;
328         string stype;
329
330         if(!bot_cmds_initialized)
331                 bot_commands_init();
332
333         for(i=1;i<BOT_CMD_COUNTER;++i)
334         {
335                 if(bot_cmd_string[i]!=scmd)
336                         continue;
337
338                 ntype = bot_cmd_parm_type[i];
339
340                 switch(ntype)
341                 {
342                         case BOT_CMD_PARAMETER_FLOAT:
343                                 stype = "float number";
344                                 break;
345                         case BOT_CMD_PARAMETER_STRING:
346                                 stype = "string";
347                                 break;
348                         case BOT_CMD_PARAMETER_VECTOR:
349                                 stype = "vector";
350                                 break;
351                         default:
352                                 stype = "none";
353                                 break;
354                 }
355
356                 LOG_INFO(strcat("Command: ",bot_cmd_string[i],"\nParameter: <",stype,"> \n"));
357
358                 LOG_INFO("Description: ");
359                 switch(i)
360                 {
361                         case BOT_CMD_PAUSE:
362                                 LOG_INFO("Stops the bot completely. Any command other than 'continue' will be ignored.");
363                                 break;
364                         case BOT_CMD_CONTINUE:
365                                 LOG_INFO("Disable paused status");
366                                 break;
367                         case BOT_CMD_WAIT:
368                                 LOG_INFO("Pause command parsing and bot ai for N seconds. Pressed key will remain pressed");
369                                 break;
370                         case BOT_CMD_WAIT_UNTIL:
371                                 LOG_INFO("Pause command parsing and bot ai until time is N from the last barrier. Pressed key will remain pressed");
372                                 break;
373                         case BOT_CMD_BARRIER:
374                                 LOG_INFO("Waits till all bots that have a command queue reach this command. Pressed key will remain pressed");
375                                 break;
376                         case BOT_CMD_TURN:
377                                 LOG_INFO("Look to the right or left N degrees. For turning to the left use positive numbers.");
378                                 break;
379                         case BOT_CMD_MOVETO:
380                                 LOG_INFO("Walk to an specific coordinate on the map. Usage: moveto \"x y z\"");
381                                 break;
382                         case BOT_CMD_MOVETOTARGET:
383                                 LOG_INFO("Walk to the specific target on the map");
384                                 break;
385                         case BOT_CMD_RESETGOAL:
386                                 LOG_INFO("Resets the goal stack");
387                                 break;
388                         case BOT_CMD_CC:
389                                 LOG_INFO("Execute client command. Examples: cc \"say something\"; cc god; cc \"name newnickname\"; cc kill;");
390                                 break;
391                         case BOT_CMD_IF:
392                                 LOG_INFO("Perform simple conditional execution.\n");
393                                 LOG_INFO("Syntax: \n");
394                                 LOG_INFO("        sv_cmd .. if \"condition\"\n");
395                                 LOG_INFO("        sv_cmd ..     <instruction if true>\n");
396                                 LOG_INFO("        sv_cmd ..     <instruction if true>\n");
397                                 LOG_INFO("        sv_cmd .. else\n");
398                                 LOG_INFO("        sv_cmd ..     <instruction if false>\n");
399                                 LOG_INFO("        sv_cmd ..     <instruction if false>\n");
400                                 LOG_INFO("        sv_cmd .. fi\n");
401                                 LOG_INFO("Conditions: a=b, a>b, a<b, a\t\t(spaces not allowed)\n");
402                                 LOG_INFO("            Values in conditions can be numbers, cvars in the form cvar.cvar_string or special fields\n");
403                                 LOG_INFO("Fields: health, speed, flagcarrier\n");
404                                 LOG_INFO("Examples: if health>50; if health>cvar.g_balance_laser_primary_damage; if flagcarrier;");
405                                 break;
406                         case BOT_CMD_RESETAIM:
407                                 LOG_INFO("Points the aim to the coordinates x,y 0,0");
408                                 break;
409                         case BOT_CMD_AIM:
410                                 LOG_INFO("Move the aim x/y (horizontal/vertical) degrees relatives to the bot\n");
411                                 LOG_INFO("There is a 3rd optional parameter telling in how many seconds the aim has to reach the new position\n");
412                                 LOG_INFO("Examples: aim \"90 0\"        // Turn 90 degrees inmediately (positive numbers move to the left/up)\n");
413                                 LOG_INFO("          aim \"0 90 2\"      // Will gradually look to the sky in the next two seconds");
414                                 break;
415                         case BOT_CMD_AIMTARGET:
416                                 LOG_INFO("Points the aim to given target");
417                                 break;
418                         case BOT_CMD_PRESSKEY:
419                                 LOG_INFO("Press one of the following keys: forward, backward, left, right, jump, crouch, attack1, attack2, use\n");
420                                 LOG_INFO("Multiple keys can be pressed at time (with many presskey calls) and it will remain pressed until the command \"releasekey\" is called");
421                                 LOG_INFO("Note: The script will not return the control to the bot ai until all keys are released");
422                                 break;
423                         case BOT_CMD_RELEASEKEY:
424                                 LOG_INFO("Release previoulsy used keys. Use the parameter \"all\" to release all keys");
425                                 break;
426                         case BOT_CMD_SOUND:
427                                 LOG_INFO("play sound file at bot location");
428                                 break;
429                         case BOT_CMD_DEBUG_ASSERT_CANFIRE:
430                                 LOG_INFO("verify the state of the weapon entity");
431                                 break;
432                         default:
433                                 LOG_INFO("This command has no description yet.");
434                                 break;
435                 }
436                 LOG_INFO("\n");
437         }
438 }
439
440 void bot_list_commands()
441 {
442         int i;
443         string ptype;
444
445         if(!bot_cmds_initialized)
446                 bot_commands_init();
447
448         LOG_INFO("List of all available commands:\n");
449         LOG_INFO("  Command - Parameter Type\n");
450
451         for(i=1;i<BOT_CMD_COUNTER;++i)
452         {
453                 switch(bot_cmd_parm_type[i])
454                 {
455                         case BOT_CMD_PARAMETER_FLOAT:
456                                 ptype = "float number";
457                                 break;
458                         case BOT_CMD_PARAMETER_STRING:
459                                 ptype = "string";
460                                 break;
461                         case BOT_CMD_PARAMETER_VECTOR:
462                                 ptype = "vector";
463                                 break;
464                         default:
465                                 ptype = "none";
466                                 break;
467                 }
468                 LOG_INFO(strcat("  ",bot_cmd_string[i]," - <",ptype,"> \n"));
469         }
470 }
471
472 // Commands code
473 .int bot_exec_status;
474
475 void SV_ParseClientCommand(string s);
476 float bot_cmd_cc()
477 {
478         SV_ParseClientCommand(bot_cmd.bot_cmd_parm_string);
479         return CMD_STATUS_FINISHED;
480 }
481
482 float bot_cmd_impulse()
483 {SELFPARAM();
484         self.impulse = bot_cmd.bot_cmd_parm_float;
485         return CMD_STATUS_FINISHED;
486 }
487
488 float bot_cmd_continue()
489 {SELFPARAM();
490         self.bot_exec_status &= ~BOT_EXEC_STATUS_PAUSED;
491         return CMD_STATUS_FINISHED;
492 }
493
494 .float bot_cmd_wait_time;
495 float bot_cmd_wait()
496 {SELFPARAM();
497         if(self.bot_exec_status & BOT_EXEC_STATUS_WAITING)
498         {
499                 if(time>=self.bot_cmd_wait_time)
500                 {
501                         self.bot_exec_status &= ~BOT_EXEC_STATUS_WAITING;
502                         return CMD_STATUS_FINISHED;
503                 }
504                 else
505                         return CMD_STATUS_EXECUTING;
506         }
507
508         self.bot_cmd_wait_time = time + bot_cmd.bot_cmd_parm_float;
509         self.bot_exec_status |= BOT_EXEC_STATUS_WAITING;
510         return CMD_STATUS_EXECUTING;
511 }
512
513 float bot_cmd_wait_until()
514 {SELFPARAM();
515         if(time < bot_cmd.bot_cmd_parm_float + bot_barriertime)
516         {
517                 self.bot_exec_status |= BOT_EXEC_STATUS_WAITING;
518                 return CMD_STATUS_EXECUTING;
519         }
520         self.bot_exec_status &= ~BOT_EXEC_STATUS_WAITING;
521         return CMD_STATUS_FINISHED;
522 }
523
524 float bot_cmd_barrier()
525 {SELFPARAM();
526         entity cl;
527
528         // 0 = no barrier, 1 = waiting, 2 = waiting finished
529
530         if(self.bot_barrier == 0) // initialization
531         {
532                 self.bot_barrier = 1;
533
534                 //self.colormod = '4 4 0';
535         }
536
537         if(self.bot_barrier == 1) // find other bots
538         {
539                 FOR_EACH_CLIENT(cl) if(cl.isbot)
540                 {
541                         if(cl.bot_cmdqueuebuf_allocated)
542                                 if(cl.bot_barrier != 1)
543                                         return CMD_STATUS_EXECUTING; // not all are at the barrier yet
544                 }
545
546                 // all bots hit the barrier!
547                 FOR_EACH_CLIENT(cl) if(cl.isbot)
548                 {
549                         cl.bot_barrier = 2; // acknowledge barrier
550                 }
551
552                 bot_barriertime = time;
553         }
554
555         // if we get here, the barrier is finished
556         // so end it...
557         self.bot_barrier = 0;
558         //self.colormod = '0 0 0';
559
560         return CMD_STATUS_FINISHED;
561 }
562
563 float bot_cmd_turn()
564 {SELFPARAM();
565         self.v_angle_y = self.v_angle.y + bot_cmd.bot_cmd_parm_float;
566         self.v_angle_y = self.v_angle.y - floor(self.v_angle.y / 360) * 360;
567         return CMD_STATUS_FINISHED;
568 }
569
570 float bot_cmd_select_weapon()
571 {SELFPARAM();
572         float id;
573
574         id = bot_cmd.bot_cmd_parm_float;
575
576         if(id < WEP_FIRST || id > WEP_LAST)
577                 return CMD_STATUS_ERROR;
578
579         if(client_hasweapon(self, id, true, false))
580                 self.switchweapon = id;
581         else
582                 return CMD_STATUS_ERROR;
583
584         return CMD_STATUS_FINISHED;
585 }
586
587 .int bot_cmd_condition_status;
588
589 const int CMD_CONDITION_NONE = 0;
590 const int CMD_CONDITION_true = 1;
591 const int CMD_CONDITION_false = 2;
592 const int CMD_CONDITION_true_BLOCK = 4;
593 const int CMD_CONDITION_false_BLOCK = 8;
594
595 float bot_cmd_eval(string expr)
596 {SELFPARAM();
597         // Search for numbers
598         if(strstrofs("0123456789", substring(expr, 0, 1), 0) >= 0)
599         {
600                 return stof(expr);
601         }
602
603         // Search for cvars
604         if(substring(expr, 0, 5)=="cvar.")
605         {
606                 return cvar(substring(expr, 5, strlen(expr)));
607         }
608
609         // Search for fields
610         switch(expr)
611         {
612                 case "health":
613                         return self.health;
614                 case "speed":
615                         return vlen(self.velocity);
616                 case "flagcarrier":
617                         return ((self.flagcarried!=world));
618         }
619
620         LOG_INFO(strcat("ERROR: Unable to convert the expression '",expr,"' into a numeric value\n"));
621         return 0;
622 }
623
624 float bot_cmd_if()
625 {SELFPARAM();
626         string expr, val_a, val_b;
627         float cmpofs;
628
629         if(self.bot_cmd_condition_status != CMD_CONDITION_NONE)
630         {
631                 // Only one "if" block is allowed at time
632                 LOG_INFO("ERROR: Only one conditional block can be processed at time");
633                 bot_clearqueue(self);
634                 return CMD_STATUS_ERROR;
635         }
636
637         self.bot_cmd_condition_status |= CMD_CONDITION_true_BLOCK;
638
639         // search for operators
640         expr = bot_cmd.bot_cmd_parm_string;
641
642         cmpofs = strstrofs(expr,"=",0);
643
644         if(cmpofs>0)
645         {
646                 val_a = substring(expr,0,cmpofs);
647                 val_b = substring(expr,cmpofs+1,strlen(expr));
648
649                 if(bot_cmd_eval(val_a)==bot_cmd_eval(val_b))
650                         self.bot_cmd_condition_status |= CMD_CONDITION_true;
651                 else
652                         self.bot_cmd_condition_status |= CMD_CONDITION_false;
653
654                 return CMD_STATUS_FINISHED;
655         }
656
657         cmpofs = strstrofs(expr,">",0);
658
659         if(cmpofs>0)
660         {
661                 val_a = substring(expr,0,cmpofs);
662                 val_b = substring(expr,cmpofs+1,strlen(expr));
663
664                 if(bot_cmd_eval(val_a)>bot_cmd_eval(val_b))
665                         self.bot_cmd_condition_status |= CMD_CONDITION_true;
666                 else
667                         self.bot_cmd_condition_status |= CMD_CONDITION_false;
668
669                 return CMD_STATUS_FINISHED;
670         }
671
672         cmpofs = strstrofs(expr,"<",0);
673
674         if(cmpofs>0)
675         {
676                 val_a = substring(expr,0,cmpofs);
677                 val_b = substring(expr,cmpofs+1,strlen(expr));
678
679                 if(bot_cmd_eval(val_a)<bot_cmd_eval(val_b))
680                         self.bot_cmd_condition_status |= CMD_CONDITION_true;
681                 else
682                         self.bot_cmd_condition_status |= CMD_CONDITION_false;
683
684                 return CMD_STATUS_FINISHED;
685         }
686
687         if(bot_cmd_eval(expr))
688                 self.bot_cmd_condition_status |= CMD_CONDITION_true;
689         else
690                 self.bot_cmd_condition_status |= CMD_CONDITION_false;
691
692         return CMD_STATUS_FINISHED;
693 }
694
695 float bot_cmd_else()
696 {SELFPARAM();
697         self.bot_cmd_condition_status &= ~CMD_CONDITION_true_BLOCK;
698         self.bot_cmd_condition_status |= CMD_CONDITION_false_BLOCK;
699         return CMD_STATUS_FINISHED;
700 }
701
702 float bot_cmd_fi()
703 {SELFPARAM();
704         self.bot_cmd_condition_status = CMD_CONDITION_NONE;
705         return CMD_STATUS_FINISHED;
706 }
707
708 float bot_cmd_resetaim()
709 {SELFPARAM();
710         self.v_angle = '0 0 0';
711         return CMD_STATUS_FINISHED;
712 }
713
714 .float bot_cmd_aim_begintime;
715 .float bot_cmd_aim_endtime;
716 .vector bot_cmd_aim_begin;
717 .vector bot_cmd_aim_end;
718
719 float bot_cmd_aim()
720 {SELFPARAM();
721         // Current direction
722         if(self.bot_cmd_aim_endtime)
723         {
724                 float progress;
725
726                 progress = min(1 - (self.bot_cmd_aim_endtime - time) / (self.bot_cmd_aim_endtime - self.bot_cmd_aim_begintime),1);
727                 self.v_angle = self.bot_cmd_aim_begin + ((self.bot_cmd_aim_end - self.bot_cmd_aim_begin) * progress);
728
729                 if(time>=self.bot_cmd_aim_endtime)
730                 {
731                         self.bot_cmd_aim_endtime = 0;
732                         return CMD_STATUS_FINISHED;
733                 }
734                 else
735                         return CMD_STATUS_EXECUTING;
736         }
737
738         // New aiming direction
739         string parms;
740         float tokens, step;
741
742         parms = bot_cmd.bot_cmd_parm_string;
743
744         tokens = tokenizebyseparator(parms, " ");
745
746         if(tokens<2||tokens>3)
747                 return CMD_STATUS_ERROR;
748
749         step = (tokens == 3) ? stof(argv(2)) : 0;
750
751         if(step == 0)
752         {
753                 self.v_angle_x -= stof(argv(1));
754                 self.v_angle_y += stof(argv(0));
755                 return CMD_STATUS_FINISHED;
756         }
757
758         self.bot_cmd_aim_begin = self.v_angle;
759
760         self.bot_cmd_aim_end_x = self.v_angle.x - stof(argv(1));
761         self.bot_cmd_aim_end_y = self.v_angle.y + stof(argv(0));
762         self.bot_cmd_aim_end_z = 0;
763
764         self.bot_cmd_aim_begintime = time;
765         self.bot_cmd_aim_endtime = time + step;
766
767         return CMD_STATUS_EXECUTING;
768 }
769
770 float bot_cmd_aimtarget()
771 {SELFPARAM();
772         if(self.bot_cmd_aim_endtime)
773         {
774                 return bot_cmd_aim();
775         }
776
777         entity e;
778         string parms;
779         vector v;
780         float tokens, step;
781
782         parms = bot_cmd.bot_cmd_parm_string;
783
784         tokens = tokenizebyseparator(parms, " ");
785
786         e = bot_getplace(argv(0));
787         if(!e)
788                 return CMD_STATUS_ERROR;
789
790         v = e.origin + (e.mins + e.maxs) * 0.5;
791
792         if(tokens==1)
793         {
794                 self.v_angle = vectoangles(v - (self.origin + self.view_ofs));
795                 self.v_angle_x = -self.v_angle.x;
796                 return CMD_STATUS_FINISHED;
797         }
798
799         if(tokens<1||tokens>2)
800                 return CMD_STATUS_ERROR;
801
802         step = stof(argv(1));
803
804         self.bot_cmd_aim_begin = self.v_angle;
805         self.bot_cmd_aim_end = vectoangles(v - (self.origin + self.view_ofs));
806         self.bot_cmd_aim_end_x = -self.bot_cmd_aim_end.x;
807
808         self.bot_cmd_aim_begintime = time;
809         self.bot_cmd_aim_endtime = time + step;
810
811         return CMD_STATUS_EXECUTING;
812 }
813
814 .int bot_cmd_keys;
815
816 const int BOT_CMD_KEY_NONE              = 0;
817 const int BOT_CMD_KEY_FORWARD   = 1;
818 const int BOT_CMD_KEY_BACKWARD  = 2;
819 const int BOT_CMD_KEY_RIGHT     = 4;
820 const int BOT_CMD_KEY_LEFT              = 8;
821 const int BOT_CMD_KEY_JUMP              = 16;
822 const int BOT_CMD_KEY_ATTACK1   = 32;
823 const int BOT_CMD_KEY_ATTACK2   = 64;
824 const int BOT_CMD_KEY_USE               = 128;
825 const int BOT_CMD_KEY_HOOK              = 256;
826 const int BOT_CMD_KEY_CROUCH    = 512;
827 const int BOT_CMD_KEY_CHAT              = 1024;
828
829 float bot_presskeys()
830 {SELFPARAM();
831         self.movement = '0 0 0';
832         self.BUTTON_JUMP = false;
833         self.BUTTON_CROUCH = false;
834         self.BUTTON_ATCK = false;
835         self.BUTTON_ATCK2 = false;
836         self.BUTTON_USE = false;
837         self.BUTTON_HOOK = false;
838         self.BUTTON_CHAT = false;
839
840         if(self.bot_cmd_keys == BOT_CMD_KEY_NONE)
841                 return false;
842
843         if(self.bot_cmd_keys & BOT_CMD_KEY_FORWARD)
844                 self.movement_x = autocvar_sv_maxspeed;
845         else if(self.bot_cmd_keys & BOT_CMD_KEY_BACKWARD)
846                 self.movement_x = -autocvar_sv_maxspeed;
847
848         if(self.bot_cmd_keys & BOT_CMD_KEY_RIGHT)
849                 self.movement_y = autocvar_sv_maxspeed;
850         else if(self.bot_cmd_keys & BOT_CMD_KEY_LEFT)
851                 self.movement_y = -autocvar_sv_maxspeed;
852
853         if(self.bot_cmd_keys & BOT_CMD_KEY_JUMP)
854                 self.BUTTON_JUMP = true;
855
856         if(self.bot_cmd_keys & BOT_CMD_KEY_CROUCH)
857                 self.BUTTON_CROUCH = true;
858
859         if(self.bot_cmd_keys & BOT_CMD_KEY_ATTACK1)
860                 self.BUTTON_ATCK = true;
861
862         if(self.bot_cmd_keys & BOT_CMD_KEY_ATTACK2)
863                 self.BUTTON_ATCK2 = true;
864
865         if(self.bot_cmd_keys & BOT_CMD_KEY_USE)
866                 self.BUTTON_USE = true;
867
868         if(self.bot_cmd_keys & BOT_CMD_KEY_HOOK)
869                 self.BUTTON_HOOK = true;
870
871         if(self.bot_cmd_keys & BOT_CMD_KEY_CHAT)
872                 self.BUTTON_CHAT = true;
873
874         return true;
875 }
876
877
878 float bot_cmd_keypress_handler(string key, float enabled)
879 {SELFPARAM();
880         switch(key)
881         {
882                 case "all":
883                         if(enabled)
884                                 self.bot_cmd_keys = power2of(20) - 1; // >:)
885                         else
886                                 self.bot_cmd_keys = BOT_CMD_KEY_NONE;
887                 case "forward":
888                         if(enabled)
889                         {
890                                 self.bot_cmd_keys |= BOT_CMD_KEY_FORWARD;
891                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_BACKWARD;
892                         }
893                         else
894                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_FORWARD;
895                         break;
896                 case "backward":
897                         if(enabled)
898                         {
899                                 self.bot_cmd_keys |= BOT_CMD_KEY_BACKWARD;
900                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_FORWARD;
901                         }
902                         else
903                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_BACKWARD;
904                         break;
905                 case "left":
906                         if(enabled)
907                         {
908                                 self.bot_cmd_keys |= BOT_CMD_KEY_LEFT;
909                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_RIGHT;
910                         }
911                         else
912                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_LEFT;
913                         break;
914                 case "right":
915                         if(enabled)
916                         {
917                                 self.bot_cmd_keys |= BOT_CMD_KEY_RIGHT;
918                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_LEFT;
919                         }
920                         else
921                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_RIGHT;
922                         break;
923                 case "jump":
924                         if(enabled)
925                                 self.bot_cmd_keys |= BOT_CMD_KEY_JUMP;
926                         else
927                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_JUMP;
928                         break;
929                 case "crouch":
930                         if(enabled)
931                                 self.bot_cmd_keys |= BOT_CMD_KEY_CROUCH;
932                         else
933                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_CROUCH;
934                         break;
935                 case "attack1":
936                         if(enabled)
937                                 self.bot_cmd_keys |= BOT_CMD_KEY_ATTACK1;
938                         else
939                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_ATTACK1;
940                         break;
941                 case "attack2":
942                         if(enabled)
943                                 self.bot_cmd_keys |= BOT_CMD_KEY_ATTACK2;
944                         else
945                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_ATTACK2;
946                         break;
947                 case "use":
948                         if(enabled)
949                                 self.bot_cmd_keys |= BOT_CMD_KEY_USE;
950                         else
951                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_USE;
952                         break;
953                 case "hook":
954                         if(enabled)
955                                 self.bot_cmd_keys |= BOT_CMD_KEY_HOOK;
956                         else
957                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_HOOK;
958                         break;
959                 case "chat":
960                         if(enabled)
961                                 self.bot_cmd_keys |= BOT_CMD_KEY_CHAT;
962                         else
963                                 self.bot_cmd_keys &= ~BOT_CMD_KEY_CHAT;
964                         break;
965                 default:
966                         break;
967         }
968
969         return CMD_STATUS_FINISHED;
970 }
971
972 float bot_cmd_presskey()
973 {
974         string key;
975
976         key = bot_cmd.bot_cmd_parm_string;
977
978         bot_cmd_keypress_handler(key,true);
979
980         return CMD_STATUS_FINISHED;
981 }
982
983 float bot_cmd_releasekey()
984 {
985         string key;
986
987         key = bot_cmd.bot_cmd_parm_string;
988
989         return bot_cmd_keypress_handler(key,false);
990 }
991
992 float bot_cmd_pause()
993 {SELFPARAM();
994         self.button1        = 0;
995         self.button8        = 0;
996         self.BUTTON_USE     = 0;
997         self.BUTTON_ATCK    = 0;
998         self.BUTTON_JUMP    = 0;
999         self.BUTTON_HOOK    = 0;
1000         self.BUTTON_CHAT    = 0;
1001         self.BUTTON_ATCK2   = 0;
1002         self.BUTTON_CROUCH  = 0;
1003
1004         self.movement = '0 0 0';
1005         self.bot_cmd_keys = BOT_CMD_KEY_NONE;
1006
1007         self.bot_exec_status |= BOT_EXEC_STATUS_PAUSED;
1008         return CMD_STATUS_FINISHED;
1009 }
1010
1011 float bot_cmd_moveto()
1012 {SELFPARAM();
1013         return self.cmd_moveto(bot_cmd.bot_cmd_parm_vector);
1014 }
1015
1016 float bot_cmd_movetotarget()
1017 {SELFPARAM();
1018         entity e;
1019         e = bot_getplace(bot_cmd.bot_cmd_parm_string);
1020         if(!e)
1021                 return CMD_STATUS_ERROR;
1022         return self.cmd_moveto(e.origin + (e.mins + e.maxs) * 0.5);
1023 }
1024
1025 float bot_cmd_resetgoal()
1026 {SELFPARAM();
1027         return self.cmd_resetgoal();
1028 }
1029
1030
1031 float bot_cmd_sound()
1032 {SELFPARAM();
1033         string f;
1034         f = bot_cmd.bot_cmd_parm_string;
1035
1036         float n = tokenizebyseparator(f, " ");
1037
1038         string sample = f;
1039         float chan = CH_WEAPON_B;
1040         float vol = VOL_BASE;
1041         float atten = ATTEN_MIN;
1042
1043         if(n >= 1)
1044                 sample = argv(n - 1);
1045         if(n >= 2)
1046                 chan = stof(argv(0));
1047         if(n >= 3)
1048                 vol = stof(argv(1));
1049         if(n >= 4)
1050                 atten = stof(argv(2));
1051
1052         precache_sound(f);
1053         _sound(self, chan, sample, vol, atten);
1054
1055         return CMD_STATUS_FINISHED;
1056 }
1057
1058 .entity tuba_note;
1059 float bot_cmd_debug_assert_canfire()
1060 {SELFPARAM();
1061         float f;
1062         f = bot_cmd.bot_cmd_parm_float;
1063
1064         if(self.weaponentity.state != WS_READY)
1065         {
1066                 if(f)
1067                 {
1068                         self.colormod = '0 8 8';
1069                         LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " wants to fire, inhibited by weaponentity state\n");
1070                 }
1071         }
1072         else if(ATTACK_FINISHED(self) > time)
1073         {
1074                 if(f)
1075                 {
1076                         self.colormod = '8 0 8';
1077                         LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " wants to fire, inhibited by ATTACK_FINISHED (", ftos(ATTACK_FINISHED(self) - time), " seconds left)\n");
1078                 }
1079         }
1080         else if(self.tuba_note)
1081         {
1082                 if(f)
1083                 {
1084                         self.colormod = '8 0 0';
1085                         LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " wants to fire, bot still has an active tuba note\n");
1086                 }
1087         }
1088         else
1089         {
1090                 if(!f)
1091                 {
1092                         self.colormod = '8 8 0';
1093                         LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " thinks it has fired, but apparently did not; ATTACK_FINISHED says ", ftos(ATTACK_FINISHED(self) - time), " seconds left\n");
1094                 }
1095         }
1096
1097         return CMD_STATUS_FINISHED;
1098 }
1099
1100 //
1101
1102 void bot_command_executed(float rm)
1103 {SELFPARAM();
1104         entity cmd;
1105
1106         cmd = bot_cmd;
1107
1108         if(rm)
1109                 bot_dequeuecommand(self, self.bot_cmd_execution_index);
1110
1111         self.bot_cmd_execution_index++;
1112 }
1113
1114 void bot_setcurrentcommand()
1115 {SELFPARAM();
1116         bot_cmd = world;
1117
1118         if(!self.bot_cmd_current)
1119         {
1120                 self.bot_cmd_current = spawn();
1121                 self.bot_cmd_current.classname = "bot_cmd";
1122                 self.bot_cmd_current.is_bot_cmd = 1;
1123         }
1124
1125         bot_cmd = self.bot_cmd_current;
1126         if(bot_cmd.bot_cmd_index != self.bot_cmd_execution_index || self.bot_cmd_execution_index == 0)
1127         {
1128                 if(bot_havecommand(self, self.bot_cmd_execution_index))
1129                 {
1130                         string cmdstring;
1131                         cmdstring = bot_readcommand(self, self.bot_cmd_execution_index);
1132                         if(bot_decodecommand(cmdstring))
1133                         {
1134                                 bot_cmd.owner = self;
1135                                 bot_cmd.bot_cmd_index = self.bot_cmd_execution_index;
1136                         }
1137                         else
1138                         {
1139                                 // Invalid command, remove from queue
1140                                 bot_cmd = world;
1141                                 bot_dequeuecommand(self, self.bot_cmd_execution_index);
1142                                 self.bot_cmd_execution_index++;
1143                         }
1144                 }
1145                 else
1146                         bot_cmd = world;
1147         }
1148 }
1149
1150 void bot_resetqueues()
1151 {
1152         entity cl;
1153
1154         FOR_EACH_CLIENT(cl) if(cl.isbot)
1155         {
1156                 cl.bot_cmd_execution_index = 0;
1157                 bot_clearqueue(cl);
1158                 // also, cancel all barriers
1159                 cl.bot_barrier = 0;
1160                 for(int i = 0; i < cl.bot_places_count; ++i)
1161                 {
1162                         strunzone(cl.(bot_placenames[i]));
1163                         cl.(bot_placenames[i]) = string_null;
1164                 }
1165                 cl.bot_places_count = 0;
1166         }
1167
1168         bot_barriertime = time;
1169 }
1170
1171 // Here we map commands to functions and deal with complex interactions between commands and execution states
1172 // NOTE: Of course you need to include your commands here too :)
1173 float bot_execute_commands_once()
1174 {SELFPARAM();
1175         float status, ispressingkey;
1176
1177         // Find command
1178         bot_setcurrentcommand();
1179
1180         // if we have no bot command, better return
1181         // old logic kept pressing previously pressed keys, but that has problems
1182         // (namely, it means you cannot make a bot "normal" ever again)
1183         // to keep a bot walking for a while, use the "wait" bot command
1184         if(bot_cmd == world)
1185                 return false;
1186
1187         // Ignore all commands except continue when the bot is paused
1188         if(self.bot_exec_status & BOT_EXEC_STATUS_PAUSED)
1189         if(bot_cmd.bot_cmd_type!=BOT_CMD_CONTINUE)
1190         {
1191                 if(bot_cmd.bot_cmd_type!=BOT_CMD_NULL)
1192                 {
1193                         bot_command_executed(true);
1194                         LOG_INFO( "WARNING: Commands are ignored while the bot is paused. Use the command 'continue' instead.\n");
1195                 }
1196                 return 1;
1197         }
1198
1199         // Keep pressing keys raised by the "presskey" command
1200         ispressingkey = !!bot_presskeys();
1201
1202         // Handle conditions
1203         if (!(bot_cmd.bot_cmd_type==BOT_CMD_FI||bot_cmd.bot_cmd_type==BOT_CMD_ELSE))
1204         if(self.bot_cmd_condition_status & CMD_CONDITION_true && self.bot_cmd_condition_status & CMD_CONDITION_false_BLOCK)
1205         {
1206                 bot_command_executed(true);
1207                 return -1;
1208         }
1209         else if(self.bot_cmd_condition_status & CMD_CONDITION_false && self.bot_cmd_condition_status & CMD_CONDITION_true_BLOCK)
1210         {
1211                 bot_command_executed(true);
1212                 return -1;
1213         }
1214
1215         // Map commands to functions
1216         switch(bot_cmd.bot_cmd_type)
1217         {
1218                 case BOT_CMD_NULL:
1219                         return ispressingkey;
1220                         //break;
1221                 case BOT_CMD_PAUSE:
1222                         status = bot_cmd_pause();
1223                         break;
1224                 case BOT_CMD_CONTINUE:
1225                         status = bot_cmd_continue();
1226                         break;
1227                 case BOT_CMD_WAIT:
1228                         status = bot_cmd_wait();
1229                         break;
1230                 case BOT_CMD_WAIT_UNTIL:
1231                         status = bot_cmd_wait_until();
1232                         break;
1233                 case BOT_CMD_TURN:
1234                         status = bot_cmd_turn();
1235                         break;
1236                 case BOT_CMD_MOVETO:
1237                         status = bot_cmd_moveto();
1238                         break;
1239                 case BOT_CMD_MOVETOTARGET:
1240                         status = bot_cmd_movetotarget();
1241                         break;
1242                 case BOT_CMD_RESETGOAL:
1243                         status = bot_cmd_resetgoal();
1244                         break;
1245                 case BOT_CMD_CC:
1246                         status = bot_cmd_cc();
1247                         break;
1248                 case BOT_CMD_IF:
1249                         status = bot_cmd_if();
1250                         break;
1251                 case BOT_CMD_ELSE:
1252                         status = bot_cmd_else();
1253                         break;
1254                 case BOT_CMD_FI:
1255                         status = bot_cmd_fi();
1256                         break;
1257                 case BOT_CMD_RESETAIM:
1258                         status = bot_cmd_resetaim();
1259                         break;
1260                 case BOT_CMD_AIM:
1261                         status = bot_cmd_aim();
1262                         break;
1263                 case BOT_CMD_AIMTARGET:
1264                         status = bot_cmd_aimtarget();
1265                         break;
1266                 case BOT_CMD_PRESSKEY:
1267                         status = bot_cmd_presskey();
1268                         break;
1269                 case BOT_CMD_RELEASEKEY:
1270                         status = bot_cmd_releasekey();
1271                         break;
1272                 case BOT_CMD_SELECTWEAPON:
1273                         status = bot_cmd_select_weapon();
1274                         break;
1275                 case BOT_CMD_IMPULSE:
1276                         status = bot_cmd_impulse();
1277                         break;
1278                 case BOT_CMD_BARRIER:
1279                         status = bot_cmd_barrier();
1280                         break;
1281                 case BOT_CMD_CONSOLE:
1282                         localcmd(strcat(bot_cmd.bot_cmd_parm_string, "\n"));
1283                         status = CMD_STATUS_FINISHED;
1284                         break;
1285                 case BOT_CMD_SOUND:
1286                         status = bot_cmd_sound();
1287                         break;
1288                 case BOT_CMD_DEBUG_ASSERT_CANFIRE:
1289                         status = bot_cmd_debug_assert_canfire();
1290                         break;
1291                 default:
1292                         LOG_INFO(strcat("ERROR: Invalid command on queue with id '",ftos(bot_cmd.bot_cmd_type),"'\n"));
1293                         return 0;
1294         }
1295
1296         if (status==CMD_STATUS_ERROR)
1297                 LOG_INFO(strcat("ERROR: The command '",bot_cmd_string[bot_cmd.bot_cmd_type],"' returned an error status\n"));
1298
1299         // Move execution pointer
1300         if(status==CMD_STATUS_EXECUTING)
1301         {
1302                 return 1;
1303         }
1304         else
1305         {
1306                 if(autocvar_g_debug_bot_commands)
1307                 {
1308                         string parms;
1309
1310                         switch(bot_cmd_parm_type[bot_cmd.bot_cmd_type])
1311                         {
1312                                 case BOT_CMD_PARAMETER_FLOAT:
1313                                         parms = ftos(bot_cmd.bot_cmd_parm_float);
1314                                         break;
1315                                 case BOT_CMD_PARAMETER_STRING:
1316                                         parms = bot_cmd.bot_cmd_parm_string;
1317                                         break;
1318                                 case BOT_CMD_PARAMETER_VECTOR:
1319                                         parms = vtos(bot_cmd.bot_cmd_parm_vector);
1320                                         break;
1321                                 default:
1322                                         parms = "";
1323                                         break;
1324                         }
1325                         clientcommand(self,strcat("say ^7", bot_cmd_string[bot_cmd.bot_cmd_type]," ",parms,"\n"));
1326                 }
1327
1328                 bot_command_executed(true);
1329         }
1330
1331         if(status == CMD_STATUS_FINISHED)
1332                 return -1;
1333
1334         return CMD_STATUS_ERROR;
1335 }
1336
1337 // This function should be (the only) called directly from the bot ai loop
1338 float bot_execute_commands()
1339 {
1340         float f;
1341         do
1342         {
1343                 f = bot_execute_commands_once();
1344         }
1345         while(f < 0);
1346         return f;
1347 }