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