]> 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         this.bot_exec_status &= ~BOT_EXEC_STATUS_PAUSED;
490         return CMD_STATUS_FINISHED;
491 }
492
493 .float bot_cmd_wait_time;
494 float bot_cmd_wait(entity this)
495 {
496         if(this.bot_exec_status & BOT_EXEC_STATUS_WAITING)
497         {
498                 if(time>=this.bot_cmd_wait_time)
499                 {
500                         this.bot_exec_status &= ~BOT_EXEC_STATUS_WAITING;
501                         return CMD_STATUS_FINISHED;
502                 }
503                 else
504                         return CMD_STATUS_EXECUTING;
505         }
506
507         this.bot_cmd_wait_time = time + bot_cmd.bot_cmd_parm_float;
508         this.bot_exec_status |= BOT_EXEC_STATUS_WAITING;
509         return CMD_STATUS_EXECUTING;
510 }
511
512 float bot_cmd_wait_until(entity this)
513 {
514         if(time < bot_cmd.bot_cmd_parm_float + bot_barriertime)
515         {
516                 this.bot_exec_status |= BOT_EXEC_STATUS_WAITING;
517                 return CMD_STATUS_EXECUTING;
518         }
519         this.bot_exec_status &= ~BOT_EXEC_STATUS_WAITING;
520         return CMD_STATUS_FINISHED;
521 }
522
523 float bot_cmd_barrier(entity this)
524 {
525         // 0 = no barrier, 1 = waiting, 2 = waiting finished
526
527         if(this.bot_barrier == 0) // initialization
528         {
529                 this.bot_barrier = 1;
530
531                 //this.colormod = '4 4 0';
532         }
533
534         if(this.bot_barrier == 1) // find other bots
535         {
536                 FOREACH_CLIENT(it.isbot, LAMBDA(
537                         if(it.bot_cmdqueuebuf_allocated)
538                         if(it.bot_barrier != 1)
539                                 return CMD_STATUS_EXECUTING; // not all are at the barrier yet
540                 ));
541
542                 // all bots hit the barrier!
543
544                 // acknowledge barrier
545                 FOREACH_CLIENT(it.isbot, LAMBDA(it.bot_barrier = 2));
546
547                 bot_barriertime = time;
548         }
549
550         // if we get here, the barrier is finished
551         // so end it...
552         this.bot_barrier = 0;
553         //this.colormod = '0 0 0';
554
555         return CMD_STATUS_FINISHED;
556 }
557
558 float bot_cmd_turn(entity this)
559 {
560         this.v_angle_y = this.v_angle.y + bot_cmd.bot_cmd_parm_float;
561         this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360;
562         return CMD_STATUS_FINISHED;
563 }
564
565 float bot_cmd_select_weapon(entity this)
566 {
567         float id = bot_cmd.bot_cmd_parm_float;
568
569         if(id < WEP_FIRST || id > WEP_LAST)
570                 return CMD_STATUS_ERROR;
571
572         bool success = false;
573
574         for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
575         {
576                 .entity weaponentity = weaponentities[slot];
577                 if(this.(weaponentity).m_weapon == WEP_Null && slot != 0)
578                         continue;
579
580                 if(client_hasweapon(this, Weapons_from(id), weaponentity, true, false))
581                 {
582                         success = true;
583                         this.(weaponentity).m_switchweapon = Weapons_from(id);
584                 }
585         }
586
587         if(!success)
588                 return CMD_STATUS_ERROR;
589
590         return CMD_STATUS_FINISHED;
591 }
592
593 .int bot_cmd_condition_status;
594
595 const int CMD_CONDITION_NONE = 0;
596 const int CMD_CONDITION_true = 1;
597 const int CMD_CONDITION_false = 2;
598 const int CMD_CONDITION_true_BLOCK = 4;
599 const int CMD_CONDITION_false_BLOCK = 8;
600
601 float bot_cmd_eval(entity this, string expr)
602 {
603         // Search for numbers
604         if(IS_DIGIT(substring(expr, 0, 1)))
605                 return stof(expr);
606
607         // Search for cvars
608         if(substring(expr, 0, 5)=="cvar.")
609                 return cvar(substring(expr, 5, strlen(expr)));
610
611         // Search for fields
612         switch(expr)
613         {
614                 case "health":
615                         return this.health;
616                 case "speed":
617                         return vlen(this.velocity);
618                 case "flagcarrier":
619                         return ((this.flagcarried!=NULL));
620         }
621
622         LOG_INFO(strcat("ERROR: Unable to convert the expression '",expr,"' into a numeric value\n"));
623         return 0;
624 }
625
626 float bot_cmd_if(entity this)
627 {
628         string expr, val_a, val_b;
629         float cmpofs;
630
631         if(this.bot_cmd_condition_status != CMD_CONDITION_NONE)
632         {
633                 // Only one "if" block is allowed at time
634                 LOG_INFO("ERROR: Only one conditional block can be processed at time");
635                 bot_clearqueue(this);
636                 return CMD_STATUS_ERROR;
637         }
638
639         this.bot_cmd_condition_status |= CMD_CONDITION_true_BLOCK;
640
641         // search for operators
642         expr = bot_cmd.bot_cmd_parm_string;
643
644         cmpofs = strstrofs(expr,"=",0);
645
646         if(cmpofs>0)
647         {
648                 val_a = substring(expr,0,cmpofs);
649                 val_b = substring(expr,cmpofs+1,strlen(expr));
650
651                 if(bot_cmd_eval(this, val_a)==bot_cmd_eval(this, val_b))
652                         this.bot_cmd_condition_status |= CMD_CONDITION_true;
653                 else
654                         this.bot_cmd_condition_status |= CMD_CONDITION_false;
655
656                 return CMD_STATUS_FINISHED;
657         }
658
659         cmpofs = strstrofs(expr,">",0);
660
661         if(cmpofs>0)
662         {
663                 val_a = substring(expr,0,cmpofs);
664                 val_b = substring(expr,cmpofs+1,strlen(expr));
665
666                 if(bot_cmd_eval(this, val_a)>bot_cmd_eval(this, val_b))
667                         this.bot_cmd_condition_status |= CMD_CONDITION_true;
668                 else
669                         this.bot_cmd_condition_status |= CMD_CONDITION_false;
670
671                 return CMD_STATUS_FINISHED;
672         }
673
674         cmpofs = strstrofs(expr,"<",0);
675
676         if(cmpofs>0)
677         {
678                 val_a = substring(expr,0,cmpofs);
679                 val_b = substring(expr,cmpofs+1,strlen(expr));
680
681                 if(bot_cmd_eval(this, val_a)<bot_cmd_eval(this, val_b))
682                         this.bot_cmd_condition_status |= CMD_CONDITION_true;
683                 else
684                         this.bot_cmd_condition_status |= CMD_CONDITION_false;
685
686                 return CMD_STATUS_FINISHED;
687         }
688
689         if(bot_cmd_eval(this, expr))
690                 this.bot_cmd_condition_status |= CMD_CONDITION_true;
691         else
692                 this.bot_cmd_condition_status |= CMD_CONDITION_false;
693
694         return CMD_STATUS_FINISHED;
695 }
696
697 float bot_cmd_else(entity this)
698 {
699         this.bot_cmd_condition_status &= ~CMD_CONDITION_true_BLOCK;
700         this.bot_cmd_condition_status |= CMD_CONDITION_false_BLOCK;
701         return CMD_STATUS_FINISHED;
702 }
703
704 float bot_cmd_fi(entity this)
705 {
706         this.bot_cmd_condition_status = CMD_CONDITION_NONE;
707         return CMD_STATUS_FINISHED;
708 }
709
710 float bot_cmd_resetaim(entity this)
711 {
712         this.v_angle = '0 0 0';
713         return CMD_STATUS_FINISHED;
714 }
715
716 .float bot_cmd_aim_begintime;
717 .float bot_cmd_aim_endtime;
718 .vector bot_cmd_aim_begin;
719 .vector bot_cmd_aim_end;
720
721 float bot_cmd_aim(entity this)
722 {
723         // Current direction
724         if(this.bot_cmd_aim_endtime)
725         {
726                 float progress;
727
728                 progress = min(1 - (this.bot_cmd_aim_endtime - time) / (this.bot_cmd_aim_endtime - this.bot_cmd_aim_begintime),1);
729                 this.v_angle = this.bot_cmd_aim_begin + ((this.bot_cmd_aim_end - this.bot_cmd_aim_begin) * progress);
730
731                 if(time>=this.bot_cmd_aim_endtime)
732                 {
733                         this.bot_cmd_aim_endtime = 0;
734                         return CMD_STATUS_FINISHED;
735                 }
736                 else
737                         return CMD_STATUS_EXECUTING;
738         }
739
740         // New aiming direction
741         string parms;
742         float tokens, step;
743
744         parms = bot_cmd.bot_cmd_parm_string;
745
746         tokens = tokenizebyseparator(parms, " ");
747
748         if(tokens<2||tokens>3)
749                 return CMD_STATUS_ERROR;
750
751         step = (tokens == 3) ? stof(argv(2)) : 0;
752
753         if(step == 0)
754         {
755                 this.v_angle_x -= stof(argv(1));
756                 this.v_angle_y += stof(argv(0));
757                 return CMD_STATUS_FINISHED;
758         }
759
760         this.bot_cmd_aim_begin = this.v_angle;
761
762         this.bot_cmd_aim_end_x = this.v_angle.x - stof(argv(1));
763         this.bot_cmd_aim_end_y = this.v_angle.y + stof(argv(0));
764         this.bot_cmd_aim_end_z = 0;
765
766         this.bot_cmd_aim_begintime = time;
767         this.bot_cmd_aim_endtime = time + step;
768
769         return CMD_STATUS_EXECUTING;
770 }
771
772 float bot_cmd_aimtarget(entity this)
773 {
774         if(this.bot_cmd_aim_endtime)
775         {
776                 return bot_cmd_aim(this);
777         }
778
779         entity e;
780         string parms;
781         vector v;
782         float tokens, step;
783
784         parms = bot_cmd.bot_cmd_parm_string;
785
786         tokens = tokenizebyseparator(parms, " ");
787
788         e = bot_getplace(this, argv(0));
789         if(!e)
790                 return CMD_STATUS_ERROR;
791
792         v = e.origin + (e.mins + e.maxs) * 0.5;
793
794         if(tokens==1)
795         {
796                 this.v_angle = vectoangles(v - (this.origin + this.view_ofs));
797                 this.v_angle_x = -this.v_angle.x;
798                 return CMD_STATUS_FINISHED;
799         }
800
801         if(tokens<1||tokens>2)
802                 return CMD_STATUS_ERROR;
803
804         step = stof(argv(1));
805
806         this.bot_cmd_aim_begin = this.v_angle;
807         this.bot_cmd_aim_end = vectoangles(v - (this.origin + this.view_ofs));
808         this.bot_cmd_aim_end_x = -this.bot_cmd_aim_end.x;
809
810         this.bot_cmd_aim_begintime = time;
811         this.bot_cmd_aim_endtime = time + step;
812
813         return CMD_STATUS_EXECUTING;
814 }
815
816 .int bot_cmd_keys;
817
818 const int BOT_CMD_KEY_NONE              = 0;
819 const int BOT_CMD_KEY_FORWARD   = BIT(0);
820 const int BOT_CMD_KEY_BACKWARD  = BIT(1);
821 const int BOT_CMD_KEY_RIGHT     = BIT(2);
822 const int BOT_CMD_KEY_LEFT              = BIT(3);
823 const int BOT_CMD_KEY_JUMP              = BIT(4);
824 const int BOT_CMD_KEY_ATTACK1   = BIT(5);
825 const int BOT_CMD_KEY_ATTACK2   = BIT(6);
826 const int BOT_CMD_KEY_USE               = BIT(7);
827 const int BOT_CMD_KEY_HOOK              = BIT(8);
828 const int BOT_CMD_KEY_CROUCH    = BIT(9);
829 const int BOT_CMD_KEY_CHAT              = BIT(10);
830
831 bool bot_presskeys(entity this)
832 {
833         this.movement = '0 0 0';
834         PHYS_INPUT_BUTTON_JUMP(this) = false;
835         PHYS_INPUT_BUTTON_CROUCH(this) = false;
836         PHYS_INPUT_BUTTON_ATCK(this) = false;
837         PHYS_INPUT_BUTTON_ATCK2(this) = false;
838         PHYS_INPUT_BUTTON_USE(this) = false;
839         PHYS_INPUT_BUTTON_HOOK(this) = false;
840         PHYS_INPUT_BUTTON_CHAT(this) = false;
841
842         if(this.bot_cmd_keys == BOT_CMD_KEY_NONE)
843                 return false;
844
845         if(this.bot_cmd_keys & BOT_CMD_KEY_FORWARD)
846                 this.movement_x = autocvar_sv_maxspeed;
847         else if(this.bot_cmd_keys & BOT_CMD_KEY_BACKWARD)
848                 this.movement_x = -autocvar_sv_maxspeed;
849
850         if(this.bot_cmd_keys & BOT_CMD_KEY_RIGHT)
851                 this.movement_y = autocvar_sv_maxspeed;
852         else if(this.bot_cmd_keys & BOT_CMD_KEY_LEFT)
853                 this.movement_y = -autocvar_sv_maxspeed;
854
855         if(this.bot_cmd_keys & BOT_CMD_KEY_JUMP)
856                 PHYS_INPUT_BUTTON_JUMP(this) = true;
857
858         if(this.bot_cmd_keys & BOT_CMD_KEY_CROUCH)
859                 PHYS_INPUT_BUTTON_CROUCH(this) = true;
860
861         if(this.bot_cmd_keys & BOT_CMD_KEY_ATTACK1)
862                 PHYS_INPUT_BUTTON_ATCK(this) = true;
863
864         if(this.bot_cmd_keys & BOT_CMD_KEY_ATTACK2)
865                 PHYS_INPUT_BUTTON_ATCK2(this) = true;
866
867         if(this.bot_cmd_keys & BOT_CMD_KEY_USE)
868                 PHYS_INPUT_BUTTON_USE(this) = true;
869
870         if(this.bot_cmd_keys & BOT_CMD_KEY_HOOK)
871                 PHYS_INPUT_BUTTON_HOOK(this) = true;
872
873         if(this.bot_cmd_keys & BOT_CMD_KEY_CHAT)
874                 PHYS_INPUT_BUTTON_CHAT(this) = true;
875
876         return true;
877 }
878
879
880 float bot_cmd_keypress_handler(entity this, string key, float enabled)
881 {
882         switch(key)
883         {
884                 case "all":
885                         if(enabled)
886                                 this.bot_cmd_keys = power2of(20) - 1; // >:)
887                         else
888                                 this.bot_cmd_keys = BOT_CMD_KEY_NONE;
889                 case "forward":
890                         if(enabled)
891                         {
892                                 this.bot_cmd_keys |= BOT_CMD_KEY_FORWARD;
893                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_BACKWARD;
894                         }
895                         else
896                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_FORWARD;
897                         break;
898                 case "backward":
899                         if(enabled)
900                         {
901                                 this.bot_cmd_keys |= BOT_CMD_KEY_BACKWARD;
902                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_FORWARD;
903                         }
904                         else
905                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_BACKWARD;
906                         break;
907                 case "left":
908                         if(enabled)
909                         {
910                                 this.bot_cmd_keys |= BOT_CMD_KEY_LEFT;
911                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_RIGHT;
912                         }
913                         else
914                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_LEFT;
915                         break;
916                 case "right":
917                         if(enabled)
918                         {
919                                 this.bot_cmd_keys |= BOT_CMD_KEY_RIGHT;
920                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_LEFT;
921                         }
922                         else
923                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_RIGHT;
924                         break;
925                 case "jump":
926                         if(enabled)
927                                 this.bot_cmd_keys |= BOT_CMD_KEY_JUMP;
928                         else
929                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_JUMP;
930                         break;
931                 case "crouch":
932                         if(enabled)
933                                 this.bot_cmd_keys |= BOT_CMD_KEY_CROUCH;
934                         else
935                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_CROUCH;
936                         break;
937                 case "attack1":
938                         if(enabled)
939                                 this.bot_cmd_keys |= BOT_CMD_KEY_ATTACK1;
940                         else
941                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_ATTACK1;
942                         break;
943                 case "attack2":
944                         if(enabled)
945                                 this.bot_cmd_keys |= BOT_CMD_KEY_ATTACK2;
946                         else
947                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_ATTACK2;
948                         break;
949                 case "use":
950                         if(enabled)
951                                 this.bot_cmd_keys |= BOT_CMD_KEY_USE;
952                         else
953                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_USE;
954                         break;
955                 case "hook":
956                         if(enabled)
957                                 this.bot_cmd_keys |= BOT_CMD_KEY_HOOK;
958                         else
959                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_HOOK;
960                         break;
961                 case "chat":
962                         if(enabled)
963                                 this.bot_cmd_keys |= BOT_CMD_KEY_CHAT;
964                         else
965                                 this.bot_cmd_keys &= ~BOT_CMD_KEY_CHAT;
966                         break;
967                 default:
968                         break;
969         }
970
971         return CMD_STATUS_FINISHED;
972 }
973
974 float bot_cmd_presskey(entity this)
975 {
976         string key;
977
978         key = bot_cmd.bot_cmd_parm_string;
979
980         bot_cmd_keypress_handler(this, key,true);
981
982         return CMD_STATUS_FINISHED;
983 }
984
985 float bot_cmd_releasekey(entity this)
986 {
987         string key;
988
989         key = bot_cmd.bot_cmd_parm_string;
990
991         return bot_cmd_keypress_handler(this, key,false);
992 }
993
994 float bot_cmd_pause(entity this)
995 {
996         PHYS_INPUT_BUTTON_DRAG(this) = false;
997         PHYS_INPUT_BUTTON_USE(this) = false;
998         PHYS_INPUT_BUTTON_ATCK(this) = false;
999         PHYS_INPUT_BUTTON_JUMP(this) = false;
1000         PHYS_INPUT_BUTTON_HOOK(this) = false;
1001         PHYS_INPUT_BUTTON_CHAT(this) = false;
1002         PHYS_INPUT_BUTTON_ATCK2(this) = false;
1003         PHYS_INPUT_BUTTON_CROUCH(this) = false;
1004
1005         this.movement = '0 0 0';
1006         this.bot_cmd_keys = BOT_CMD_KEY_NONE;
1007
1008         this.bot_exec_status |= BOT_EXEC_STATUS_PAUSED;
1009         return CMD_STATUS_FINISHED;
1010 }
1011
1012 float bot_cmd_moveto(entity this)
1013 {
1014         return this.cmd_moveto(this, bot_cmd.bot_cmd_parm_vector);
1015 }
1016
1017 float bot_cmd_movetotarget(entity this)
1018 {
1019         entity e;
1020         e = bot_getplace(this, bot_cmd.bot_cmd_parm_string);
1021         if(!e)
1022                 return CMD_STATUS_ERROR;
1023         return this.cmd_moveto(this, e.origin + (e.mins + e.maxs) * 0.5);
1024 }
1025
1026 float bot_cmd_resetgoal(entity this)
1027 {
1028         return this.cmd_resetgoal(this);
1029 }
1030
1031
1032 float bot_cmd_sound(entity this)
1033 {
1034         string f;
1035         f = bot_cmd.bot_cmd_parm_string;
1036
1037         float n = tokenizebyseparator(f, " ");
1038
1039         string sample = f;
1040         float chan = CH_WEAPON_B;
1041         float vol = VOL_BASE;
1042         float atten = ATTEN_MIN;
1043
1044         if(n >= 1)
1045                 sample = argv(n - 1);
1046         if(n >= 2)
1047                 chan = stof(argv(0));
1048         if(n >= 3)
1049                 vol = stof(argv(1));
1050         if(n >= 4)
1051                 atten = stof(argv(2));
1052
1053         precache_sound(f);
1054         _sound(this, chan, sample, vol, atten);
1055
1056         return CMD_STATUS_FINISHED;
1057 }
1058
1059 .entity tuba_note;
1060 float bot_cmd_debug_assert_canfire(entity this)
1061 {
1062         float f = bot_cmd.bot_cmd_parm_float;
1063
1064         int slot = 0; // TODO: unhardcode?
1065         .entity weaponentity = weaponentities[slot];
1066         if(this.(weaponentity).state != WS_READY)
1067         {
1068                 if(f)
1069                 {
1070                         this.colormod = '0 8 8';
1071                         LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, inhibited by weaponentity state\n");
1072                 }
1073         }
1074         else if(ATTACK_FINISHED(this, slot) > time)
1075         {
1076                 if(f)
1077                 {
1078                         this.colormod = '8 0 8';
1079                         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");
1080                 }
1081         }
1082         else if(this.(weaponentity).tuba_note)
1083         {
1084                 if(f)
1085                 {
1086                         this.colormod = '8 0 0';
1087                         LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, bot still has an active tuba note\n");
1088                 }
1089         }
1090         else
1091         {
1092                 if(!f)
1093                 {
1094                         this.colormod = '8 8 0';
1095                         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");
1096                 }
1097         }
1098
1099         return CMD_STATUS_FINISHED;
1100 }
1101
1102 //
1103
1104 void bot_command_executed(entity this, bool rm)
1105 {
1106         entity cmd;
1107
1108         cmd = bot_cmd;
1109
1110         if(rm)
1111                 bot_dequeuecommand(this, this.bot_cmd_execution_index);
1112
1113         this.bot_cmd_execution_index++;
1114 }
1115
1116 void bot_setcurrentcommand(entity this)
1117 {
1118         bot_cmd = NULL;
1119
1120         if(!this.bot_cmd_current)
1121         {
1122                 this.bot_cmd_current = new_pure(bot_cmd);
1123         }
1124
1125         bot_cmd = this.bot_cmd_current;
1126         if(bot_cmd.bot_cmd_index != this.bot_cmd_execution_index || this.bot_cmd_execution_index == 0)
1127         {
1128                 if(bot_havecommand(this, this.bot_cmd_execution_index))
1129                 {
1130                         string cmdstring;
1131                         cmdstring = bot_readcommand(this, this.bot_cmd_execution_index);
1132                         if(bot_decodecommand(cmdstring))
1133                         {
1134                                 bot_cmd.owner = this;
1135                                 bot_cmd.bot_cmd_index = this.bot_cmd_execution_index;
1136                         }
1137                         else
1138                         {
1139                                 // Invalid command, remove from queue
1140                                 bot_cmd = NULL;
1141                                 bot_dequeuecommand(this, this.bot_cmd_execution_index);
1142                                 this.bot_cmd_execution_index++;
1143                         }
1144                 }
1145                 else
1146                         bot_cmd = NULL;
1147         }
1148 }
1149
1150 void bot_resetqueues()
1151 {
1152         FOREACH_CLIENT(it.isbot, LAMBDA(
1153                 it.bot_cmd_execution_index = 0;
1154                 bot_clearqueue(it);
1155                 // also, cancel all barriers
1156                 it.bot_barrier = 0;
1157                 for(int i = 0; i < it.bot_places_count; ++i)
1158                 {
1159                         strunzone(it.(bot_placenames[i]));
1160                         it.(bot_placenames[i]) = string_null;
1161                 }
1162                 it.bot_places_count = 0;
1163         ));
1164
1165         bot_barriertime = time;
1166 }
1167
1168 // Here we map commands to functions and deal with complex interactions between commands and execution states
1169 // NOTE: Of course you need to include your commands here too :)
1170 float bot_execute_commands_once(entity this)
1171 {
1172         float status, ispressingkey;
1173
1174         // Find command
1175         bot_setcurrentcommand(this);
1176
1177         // if we have no bot command, better return
1178         // old logic kept pressing previously pressed keys, but that has problems
1179         // (namely, it means you cannot make a bot "normal" ever again)
1180         // to keep a bot walking for a while, use the "wait" bot command
1181         if(bot_cmd == NULL)
1182                 return false;
1183
1184         // Ignore all commands except continue when the bot is paused
1185         if(this.bot_exec_status & BOT_EXEC_STATUS_PAUSED)
1186         if(bot_cmd.bot_cmd_type!=BOT_CMD_CONTINUE)
1187         {
1188                 if(bot_cmd.bot_cmd_type!=BOT_CMD_NULL)
1189                 {
1190                         bot_command_executed(this, true);
1191                         LOG_INFO( "WARNING: Commands are ignored while the bot is paused. Use the command 'continue' instead.\n");
1192                 }
1193                 return 1;
1194         }
1195
1196         // Keep pressing keys raised by the "presskey" command
1197         ispressingkey = boolean(bot_presskeys(this));
1198
1199         // Handle conditions
1200         if (!(bot_cmd.bot_cmd_type==BOT_CMD_FI||bot_cmd.bot_cmd_type==BOT_CMD_ELSE))
1201         if(this.bot_cmd_condition_status & CMD_CONDITION_true && this.bot_cmd_condition_status & CMD_CONDITION_false_BLOCK)
1202         {
1203                 bot_command_executed(this, true);
1204                 return -1;
1205         }
1206         else if(this.bot_cmd_condition_status & CMD_CONDITION_false && this.bot_cmd_condition_status & CMD_CONDITION_true_BLOCK)
1207         {
1208                 bot_command_executed(this, true);
1209                 return -1;
1210         }
1211
1212         // Map commands to functions
1213         switch(bot_cmd.bot_cmd_type)
1214         {
1215                 case BOT_CMD_NULL:
1216                         return ispressingkey;
1217                         //break;
1218                 case BOT_CMD_PAUSE:
1219                         status = bot_cmd_pause(this);
1220                         break;
1221                 case BOT_CMD_CONTINUE:
1222                         status = bot_cmd_continue(this);
1223                         break;
1224                 case BOT_CMD_WAIT:
1225                         status = bot_cmd_wait(this);
1226                         break;
1227                 case BOT_CMD_WAIT_UNTIL:
1228                         status = bot_cmd_wait_until(this);
1229                         break;
1230                 case BOT_CMD_TURN:
1231                         status = bot_cmd_turn(this);
1232                         break;
1233                 case BOT_CMD_MOVETO:
1234                         status = bot_cmd_moveto(this);
1235                         break;
1236                 case BOT_CMD_MOVETOTARGET:
1237                         status = bot_cmd_movetotarget(this);
1238                         break;
1239                 case BOT_CMD_RESETGOAL:
1240                         status = bot_cmd_resetgoal(this);
1241                         break;
1242                 case BOT_CMD_CC:
1243                         status = bot_cmd_cc(this);
1244                         break;
1245                 case BOT_CMD_IF:
1246                         status = bot_cmd_if(this);
1247                         break;
1248                 case BOT_CMD_ELSE:
1249                         status = bot_cmd_else(this);
1250                         break;
1251                 case BOT_CMD_FI:
1252                         status = bot_cmd_fi(this);
1253                         break;
1254                 case BOT_CMD_RESETAIM:
1255                         status = bot_cmd_resetaim(this);
1256                         break;
1257                 case BOT_CMD_AIM:
1258                         status = bot_cmd_aim(this);
1259                         break;
1260                 case BOT_CMD_AIMTARGET:
1261                         status = bot_cmd_aimtarget(this);
1262                         break;
1263                 case BOT_CMD_PRESSKEY:
1264                         status = bot_cmd_presskey(this);
1265                         break;
1266                 case BOT_CMD_RELEASEKEY:
1267                         status = bot_cmd_releasekey(this);
1268                         break;
1269                 case BOT_CMD_SELECTWEAPON:
1270                         status = bot_cmd_select_weapon(this);
1271                         break;
1272                 case BOT_CMD_IMPULSE:
1273                         status = bot_cmd_impulse(this);
1274                         break;
1275                 case BOT_CMD_BARRIER:
1276                         status = bot_cmd_barrier(this);
1277                         break;
1278                 case BOT_CMD_CONSOLE:
1279                         localcmd(strcat(bot_cmd.bot_cmd_parm_string, "\n"));
1280                         status = CMD_STATUS_FINISHED;
1281                         break;
1282                 case BOT_CMD_SOUND:
1283                         status = bot_cmd_sound(this);
1284                         break;
1285                 case BOT_CMD_DEBUG_ASSERT_CANFIRE:
1286                         status = bot_cmd_debug_assert_canfire(this);
1287                         break;
1288                 default:
1289                         LOG_INFO(strcat("ERROR: Invalid command on queue with id '",ftos(bot_cmd.bot_cmd_type),"'\n"));
1290                         return 0;
1291         }
1292
1293         if (status==CMD_STATUS_ERROR)
1294                 LOG_INFO(strcat("ERROR: The command '",bot_cmd_string[bot_cmd.bot_cmd_type],"' returned an error status\n"));
1295
1296         // Move execution pointer
1297         if(status==CMD_STATUS_EXECUTING)
1298         {
1299                 return 1;
1300         }
1301         else
1302         {
1303                 if(autocvar_g_debug_bot_commands)
1304                 {
1305                         string parms;
1306
1307                         switch(bot_cmd_parm_type[bot_cmd.bot_cmd_type])
1308                         {
1309                                 case BOT_CMD_PARAMETER_FLOAT:
1310                                         parms = ftos(bot_cmd.bot_cmd_parm_float);
1311                                         break;
1312                                 case BOT_CMD_PARAMETER_STRING:
1313                                         parms = bot_cmd.bot_cmd_parm_string;
1314                                         break;
1315                                 case BOT_CMD_PARAMETER_VECTOR:
1316                                         parms = vtos(bot_cmd.bot_cmd_parm_vector);
1317                                         break;
1318                                 default:
1319                                         parms = "";
1320                                         break;
1321                         }
1322                         clientcommand(this,strcat("say ^7", bot_cmd_string[bot_cmd.bot_cmd_type]," ",parms,"\n"));
1323                 }
1324
1325                 bot_command_executed(this, true);
1326         }
1327
1328         if(status == CMD_STATUS_FINISHED)
1329                 return -1;
1330
1331         return CMD_STATUS_ERROR;
1332 }
1333
1334 // This function should be (the only) called directly from the bot ai loop
1335 int bot_execute_commands(entity this)
1336 {
1337         int f;
1338         do
1339         {
1340                 f = bot_execute_commands_once(this);
1341         }
1342         while(f < 0);
1343         return f;
1344 }