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