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