Xonotic
scripting.qc File Reference
+ Include dependency graph for scripting.qc:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Functions

void bot_clearqueue (entity bot)
 
float bot_cmd_aim (entity this)
 
float bot_cmd_aimtarget (entity this)
 
float bot_cmd_barrier (entity this)
 
float bot_cmd_cc (entity this)
 
float bot_cmd_continue (entity this)
 
float bot_cmd_debug_assert_canfire (entity this)
 
float bot_cmd_else (entity this)
 
float bot_cmd_eval (entity this, string expr)
 
float bot_cmd_fi (entity this)
 
float bot_cmd_if (entity this)
 
float bot_cmd_impulse (entity this)
 
float bot_cmd_keypress_handler (entity this, string key, float enabled)
 
float bot_cmd_moveto (entity this)
 
float bot_cmd_movetotarget (entity this)
 
float bot_cmd_pause (entity this)
 
float bot_cmd_presskey (entity this)
 
float bot_cmd_releasekey (entity this)
 
float bot_cmd_resetaim (entity this)
 
float bot_cmd_resetgoal (entity this)
 
float bot_cmd_select_weapon (entity this)
 
float bot_cmd_sound (entity this)
 
float bot_cmd_turn (entity this)
 
float bot_cmd_wait (entity this)
 
float bot_cmd_wait_until (entity this)
 
void bot_cmdhelp (string scmd)
 
void bot_command_executed (entity this, bool rm)
 
void bot_commands_init ()
 
float bot_decodecommand (string cmdstring)
 
void bot_dequeuecommand (entity bot, float idx)
 
int bot_execute_commands (entity this)
 
float bot_execute_commands_once (entity this)
 
entity bot_getplace (entity this, string placename)
 
bool bot_havecommand (entity this, int idx)
 
bool bot_ispaused (entity this)
 
void bot_list_commands ()
 
bool bot_presskeys (entity this)
 
void bot_queuecommand (entity bot, string cmdstring)
 
string bot_readcommand (entity bot, float idx)
 
void bot_resetqueues ()
 
void bot_setcurrentcommand (entity this)
 
entity find_bot_by_name (string name)
 
entity find_bot_by_number (float number)
 

Variables

vector bot_cmd_aim_begin
 
float bot_cmd_aim_begintime
 
vector bot_cmd_aim_end
 
float bot_cmd_aim_endtime
 
int bot_cmd_condition_status
 
const int BOT_CMD_KEY_ATTACK1 = BIT(5)
 
const int BOT_CMD_KEY_ATTACK2 = BIT(6)
 
const int BOT_CMD_KEY_BACKWARD = BIT(1)
 
const int BOT_CMD_KEY_CHAT = BIT(10)
 
const int BOT_CMD_KEY_CROUCH = BIT(9)
 
const int BOT_CMD_KEY_FORWARD = BIT(0)
 
const int BOT_CMD_KEY_HOOK = BIT(8)
 
const int BOT_CMD_KEY_JUMP = BIT(4)
 
const int BOT_CMD_KEY_LEFT = BIT(3)
 
const int BOT_CMD_KEY_NONE = 0
 
const int BOT_CMD_KEY_RIGHT = BIT(2)
 
const int BOT_CMD_KEY_USE = BIT(7)
 
int bot_cmd_keys
 
float bot_cmd_wait_time
 
float bot_cmdqueuebuf
 
float bot_cmdqueuebuf_allocated
 
float bot_cmdqueuebuf_end
 
float bot_cmdqueuebuf_start
 
int bot_exec_status
 
string bot_placenames [MAX_BOT_PLACES]
 
entity bot_places [MAX_BOT_PLACES]
 
float bot_places_count
 
const int CMD_CONDITION_false = 2
 
const int CMD_CONDITION_false_BLOCK = 8
 
const int CMD_CONDITION_NONE = 0
 
const int CMD_CONDITION_true = 1
 
const int CMD_CONDITION_true_BLOCK = 4
 
const int MAX_BOT_PLACES = 4
 
int state
 
entity tuba_note
 

Function Documentation

◆ bot_clearqueue()

void bot_clearqueue ( entity  bot)

Definition at line 21 of file scripting.qc.

References LOG_TRACE.

Referenced by bot_clientdisconnect(), bot_cmd_if(), and bot_dequeuecommand().

22 {
23  if(!bot.bot_cmdqueuebuf_allocated)
24  return;
25  buf_del(bot.bot_cmdqueuebuf);
26  bot.bot_cmdqueuebuf_allocated = false;
27  LOG_TRACE("bot ", bot.netname, " queue cleared");
28 }
#define LOG_TRACE(...)
Definition: log.qh:81
+ Here is the caller graph for this function:

◆ bot_cmd_aim()

float bot_cmd_aim ( entity  this)

Definition at line 730 of file scripting.qc.

References argv(), bot_cmd, bot_cmd_aim_begin, bot_cmd_aim_begintime, bot_cmd_aim_end, bot_cmd_aim_endtime, CMD_STATUS_ERROR, CMD_STATUS_EXECUTING, CMD_STATUS_FINISHED, min(), stof(), time, tokenizebyseparator, and v_angle.

Referenced by bot_cmd_aimtarget(), and bot_execute_commands_once().

731 {
732  // Current direction
733  if(this.bot_cmd_aim_endtime)
734  {
735  float progress;
736 
737  progress = min(1 - (this.bot_cmd_aim_endtime - time) / (this.bot_cmd_aim_endtime - this.bot_cmd_aim_begintime),1);
738  this.v_angle = this.bot_cmd_aim_begin + ((this.bot_cmd_aim_end - this.bot_cmd_aim_begin) * progress);
739 
740  if(time>=this.bot_cmd_aim_endtime)
741  {
742  this.bot_cmd_aim_endtime = 0;
743  return CMD_STATUS_FINISHED;
744  }
745  else
746  return CMD_STATUS_EXECUTING;
747  }
748 
749  // New aiming direction
750  string parms;
751  float tokens, step;
752 
753  parms = bot_cmd.bot_cmd_parm_string;
754 
755  tokens = tokenizebyseparator(parms, " ");
756 
757  if(tokens<2||tokens>3)
758  return CMD_STATUS_ERROR;
759 
760  step = (tokens == 3) ? stof(argv(2)) : 0;
761 
762  if(step == 0)
763  {
764  this.v_angle_x -= stof(argv(1));
765  this.v_angle_y += stof(argv(0));
766  return CMD_STATUS_FINISHED;
767  }
768 
769  this.bot_cmd_aim_begin = this.v_angle;
770 
771  this.bot_cmd_aim_end_x = this.v_angle.x - stof(argv(1));
772  this.bot_cmd_aim_end_y = this.v_angle.y + stof(argv(0));
773  this.bot_cmd_aim_end_z = 0;
774 
776  this.bot_cmd_aim_endtime = time + step;
777 
778  return CMD_STATUS_EXECUTING;
779 }
float bot_cmd_aim_endtime
Definition: scripting.qc:726
vector bot_cmd_aim_begin
Definition: scripting.qc:727
vector v_angle
Definition: progsdefs.qc:161
#define CMD_STATUS_ERROR
Definition: scripting.qh:9
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
vector bot_cmd_aim_end
Definition: scripting.qc:728
entity bot_cmd
Definition: scripting.qh:59
float bot_cmd_aim_begintime
Definition: scripting.qc:725
#define CMD_STATUS_EXECUTING
Definition: scripting.qh:7
#define tokenizebyseparator
Definition: dpextensions.qh:21
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_aimtarget()

float bot_cmd_aimtarget ( entity  this)

Definition at line 781 of file scripting.qc.

References argv(), bot_cmd, bot_cmd_aim(), bot_cmd_aim_begin, bot_cmd_aim_begintime, bot_cmd_aim_end, bot_cmd_aim_endtime, bot_getplace(), CMD_STATUS_ERROR, CMD_STATUS_EXECUTING, CMD_STATUS_FINISHED, entity(), origin, stof(), time, tokenizebyseparator, v, v_angle, vectoangles(), vector(), and view_ofs.

Referenced by bot_execute_commands_once().

782 {
783  if(this.bot_cmd_aim_endtime)
784  {
785  return bot_cmd_aim(this);
786  }
787 
788  entity e;
789  string parms;
790  vector v;
791  float tokens, step;
792 
793  parms = bot_cmd.bot_cmd_parm_string;
794 
795  tokens = tokenizebyseparator(parms, " ");
796 
797  e = bot_getplace(this, argv(0));
798  if(!e)
799  return CMD_STATUS_ERROR;
800 
801  v = e.origin + (e.mins + e.maxs) * 0.5;
802 
803  if(tokens==1)
804  {
805  this.v_angle = vectoangles(v - (this.origin + this.view_ofs));
806  this.v_angle_x = -this.v_angle.x;
807  return CMD_STATUS_FINISHED;
808  }
809 
810  if(tokens<1||tokens>2)
811  return CMD_STATUS_ERROR;
812 
813  step = stof(argv(1));
814 
815  this.bot_cmd_aim_begin = this.v_angle;
816  this.bot_cmd_aim_end = vectoangles(v - (this.origin + this.view_ofs));
817  this.bot_cmd_aim_end_x = -this.bot_cmd_aim_end.x;
818 
820  this.bot_cmd_aim_endtime = time + step;
821 
822  return CMD_STATUS_EXECUTING;
823 }
float bot_cmd_aim_endtime
Definition: scripting.qc:726
vector view_ofs
Definition: progsdefs.qc:151
vector bot_cmd_aim_begin
Definition: scripting.qc:727
entity() spawn
vector v_angle
Definition: progsdefs.qc:161
#define CMD_STATUS_ERROR
Definition: scripting.qh:9
origin
Definition: ent_cs.qc:114
float bot_cmd_aim(entity this)
Definition: scripting.qc:730
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
vector bot_cmd_aim_end
Definition: scripting.qc:728
entity bot_cmd
Definition: scripting.qh:59
float bot_cmd_aim_begintime
Definition: scripting.qc:725
#define CMD_STATUS_EXECUTING
Definition: scripting.qh:7
entity bot_getplace(entity this, string placename)
Definition: scripting.qc:113
vector(float skel, float bonenum) _skel_get_boneabs_hidden
vector v
Definition: ent_cs.qc:116
#define tokenizebyseparator
Definition: dpextensions.qh:21
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_barrier()

float bot_cmd_barrier ( entity  this)

Definition at line 531 of file scripting.qc.

References bot_barrier, bot_barriertime, CMD_STATUS_FINISHED, FOREACH_CLIENT, and time.

Referenced by bot_execute_commands_once().

532 {
533  // 0 = no barrier, 1 = waiting, 2 = waiting finished
534 
535  if(this.bot_barrier == 0) // initialization
536  {
537  this.bot_barrier = 1;
538 
539  //this.colormod = '4 4 0';
540  }
541 
542  if(this.bot_barrier == 1) // find other bots
543  {
544  FOREACH_CLIENT(it.isbot, {
545  if(it.bot_cmdqueuebuf_allocated)
546  if(it.bot_barrier != 1)
547  return CMD_STATUS_EXECUTING; // not all are at the barrier yet
548  });
549 
550  // all bots hit the barrier!
551 
552  // acknowledge barrier
553  FOREACH_CLIENT(it.isbot, { it.bot_barrier = 2; });
554 
556  }
557 
558  // if we get here, the barrier is finished
559  // so end it...
560  this.bot_barrier = 0;
561  //this.colormod = '0 0 0';
562 
563  return CMD_STATUS_FINISHED;
564 }
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
float bot_barriertime
Definition: scripting.qh:68
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
float bot_barrier
Definition: scripting.qh:69
float time
Definition: csprogsdefs.qc:16
+ Here is the caller graph for this function:

◆ bot_cmd_cc()

float bot_cmd_cc ( entity  this)

Definition at line 482 of file scripting.qc.

References bot_cmd, CMD_STATUS_FINISHED, and SV_ParseClientCommand().

Referenced by bot_execute_commands_once().

483 {
484  SV_ParseClientCommand(this, bot_cmd.bot_cmd_parm_string);
485  return CMD_STATUS_FINISHED;
486 }
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
void SV_ParseClientCommand(entity this, string command)
Definition: cmd.qc:866
entity bot_cmd
Definition: scripting.qh:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_continue()

float bot_cmd_continue ( entity  this)

Definition at line 494 of file scripting.qc.

References bot_exec_status, BOT_EXEC_STATUS_PAUSED, bot_relinkplayerlist(), and CMD_STATUS_FINISHED.

Referenced by bot_execute_commands_once().

495 {
498  return CMD_STATUS_FINISHED;
499 }
void bot_relinkplayerlist()
Definition: bot.qc:381
#define BOT_EXEC_STATUS_PAUSED
Definition: scripting.qh:4
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
int bot_exec_status
Definition: scripting.qc:480
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_debug_assert_canfire()

float bot_cmd_debug_assert_canfire ( entity  this)

Definition at line 1075 of file scripting.qc.

References ATTACK_FINISHED, bot_cmd, CMD_STATUS_FINISHED, colormod, ftos(), LOG_INFO, netname, state, time, tuba_note, weaponentities, and WS_READY.

Referenced by bot_execute_commands_once().

1076 {
1077  float f = bot_cmd.bot_cmd_parm_float;
1078 
1079  int slot = 0; // TODO: unhardcode?
1080  .entity weaponentity = weaponentities[slot];
1081  if(this.(weaponentity).state != WS_READY)
1082  {
1083  if(f)
1084  {
1085  this.colormod = '0 8 8';
1086  LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, inhibited by weaponentity state");
1087  }
1088  }
1089  else if(ATTACK_FINISHED(this, weaponentity) > time)
1090  {
1091  if(f)
1092  {
1093  this.colormod = '8 0 8';
1094  LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, inhibited by ATTACK_FINISHED (", ftos(ATTACK_FINISHED(this, weaponentity) - time), " seconds left)");
1095  }
1096  }
1097  else if(this.(weaponentity).tuba_note)
1098  {
1099  if(f)
1100  {
1101  this.colormod = '8 0 0';
1102  LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " wants to fire, bot still has an active tuba note");
1103  }
1104  }
1105  else
1106  {
1107  if(!f)
1108  {
1109  this.colormod = '8 8 0';
1110  LOG_INFO("Bot ", this.netname, " using ", this.(weaponentity).weaponname, " thinks it has fired, but apparently did not; ATTACK_FINISHED says ", ftos(ATTACK_FINISHED(this, weaponentity) - time), " seconds left");
1111  }
1112  }
1113 
1114  return CMD_STATUS_FINISHED;
1115 }
vector colormod
Definition: powerups.qc:21
string netname
Definition: powerups.qc:20
const int WS_READY
idle frame
Definition: weapon.qh:38
entity tuba_note
Definition: scripting.qc:1074
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
entity bot_cmd
Definition: scripting.qh:59
int state
Definition: scripting.qc:14
#define LOG_INFO(...)
Definition: log.qh:70
entity weaponentities[MAX_WEAPONSLOTS]
Definition: weapon.qh:14
#define ATTACK_FINISHED(ent, w)
Definition: weaponsystem.qh:42
float time
Definition: csprogsdefs.qc:16
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_else()

float bot_cmd_else ( entity  this)

Definition at line 706 of file scripting.qc.

References bot_cmd_condition_status, CMD_CONDITION_false_BLOCK, CMD_CONDITION_true_BLOCK, and CMD_STATUS_FINISHED.

Referenced by bot_execute_commands_once().

707 {
710  return CMD_STATUS_FINISHED;
711 }
const int CMD_CONDITION_false_BLOCK
Definition: scripting.qc:607
int bot_cmd_condition_status
Definition: scripting.qc:601
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
const int CMD_CONDITION_true_BLOCK
Definition: scripting.qc:606
+ Here is the caller graph for this function:

◆ bot_cmd_eval()

float bot_cmd_eval ( entity  this,
string  expr 
)

Definition at line 609 of file scripting.qc.

References cvar(), flagcarried, GetResource(), IS_DIGIT, LOG_INFO, NULL, RES_HEALTH, stof(), strlen(), substring(), velocity, and vlen().

Referenced by bot_cmd_if().

610 {
611  // Search for numbers
612  if(IS_DIGIT(substring(expr, 0, 1)))
613  return stof(expr);
614 
615  // Search for cvars
616  if(substring(expr, 0, 5)=="cvar.")
617  return cvar(substring(expr, 5, strlen(expr)));
618 
619  // Search for fields
620  // TODO: expand with support for more fields (key carrier, ball carrier, armor etc)
621  switch(expr)
622  {
623  case "health":
624  return GetResource(this, RES_HEALTH);
625  case "speed":
626  return vlen(this.velocity);
627  case "flagcarrier":
628  return ((this.flagcarried!=NULL));
629  }
630 
631  LOG_INFO("ERROR: Unable to convert the expression '", expr, "' into a numeric value");
632  return 0;
633 }
entity flagcarried
Definition: sv_ctf.qh:82
RES_HEALTH
Definition: ent_cs.qc:126
#define NULL
Definition: post.qh:17
#define LOG_INFO(...)
Definition: log.qh:70
#define IS_DIGIT(d)
Definition: string.qh:507
float GetResource(entity e, Resource res_type)
Returns the current amount of resource the given entity has.
Definition: cl_resources.qc:10
vector velocity
Definition: csprogsdefs.qc:103
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_fi()

float bot_cmd_fi ( entity  this)

Definition at line 713 of file scripting.qc.

References bot_cmd_condition_status, CMD_CONDITION_NONE, and CMD_STATUS_FINISHED.

Referenced by bot_execute_commands_once().

714 {
716  return CMD_STATUS_FINISHED;
717 }
int bot_cmd_condition_status
Definition: scripting.qc:601
const int CMD_CONDITION_NONE
Definition: scripting.qc:603
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
+ Here is the caller graph for this function:

◆ bot_cmd_if()

float bot_cmd_if ( entity  this)

Definition at line 635 of file scripting.qc.

References bot_clearqueue(), bot_cmd, bot_cmd_condition_status, bot_cmd_eval(), CMD_CONDITION_false, CMD_CONDITION_NONE, CMD_CONDITION_true, CMD_CONDITION_true_BLOCK, CMD_STATUS_ERROR, CMD_STATUS_FINISHED, LOG_INFO, strlen(), strstrofs, and substring().

Referenced by bot_execute_commands_once().

636 {
637  string expr, val_a, val_b;
638  float cmpofs;
639 
641  {
642  // Only one "if" block is allowed at time
643  LOG_INFO("ERROR: Only one conditional block can be processed at time");
644  bot_clearqueue(this);
645  return CMD_STATUS_ERROR;
646  }
647 
649 
650  // search for operators
651  expr = bot_cmd.bot_cmd_parm_string;
652 
653  cmpofs = strstrofs(expr,"=",0);
654 
655  if(cmpofs>0)
656  {
657  val_a = substring(expr,0,cmpofs);
658  val_b = substring(expr,cmpofs+1,strlen(expr));
659 
660  if(bot_cmd_eval(this, val_a)==bot_cmd_eval(this, val_b))
662  else
664 
665  return CMD_STATUS_FINISHED;
666  }
667 
668  cmpofs = strstrofs(expr,">",0);
669 
670  if(cmpofs>0)
671  {
672  val_a = substring(expr,0,cmpofs);
673  val_b = substring(expr,cmpofs+1,strlen(expr));
674 
675  if(bot_cmd_eval(this, val_a)>bot_cmd_eval(this, val_b))
677  else
679 
680  return CMD_STATUS_FINISHED;
681  }
682 
683  cmpofs = strstrofs(expr,"<",0);
684 
685  if(cmpofs>0)
686  {
687  val_a = substring(expr,0,cmpofs);
688  val_b = substring(expr,cmpofs+1,strlen(expr));
689 
690  if(bot_cmd_eval(this, val_a)<bot_cmd_eval(this, val_b))
692  else
694 
695  return CMD_STATUS_FINISHED;
696  }
697 
698  if(bot_cmd_eval(this, expr))
700  else
702 
703  return CMD_STATUS_FINISHED;
704 }
int bot_cmd_condition_status
Definition: scripting.qc:601
float bot_cmd_eval(entity this, string expr)
Definition: scripting.qc:609
#define CMD_STATUS_ERROR
Definition: scripting.qh:9
const int CMD_CONDITION_NONE
Definition: scripting.qc:603
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
const int CMD_CONDITION_false
Definition: scripting.qc:605
void bot_clearqueue(entity bot)
Definition: scripting.qc:21
entity bot_cmd
Definition: scripting.qh:59
const int CMD_CONDITION_true
Definition: scripting.qc:604
#define LOG_INFO(...)
Definition: log.qh:70
#define strstrofs
Definition: dpextensions.qh:42
const int CMD_CONDITION_true_BLOCK
Definition: scripting.qc:606
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_impulse()

float bot_cmd_impulse ( entity  this)

Definition at line 488 of file scripting.qc.

References bot_cmd, CMD_STATUS_FINISHED, and CS().

Referenced by bot_execute_commands_once().

489 {
490  CS(this).impulse = bot_cmd.bot_cmd_parm_float;
491  return CMD_STATUS_FINISHED;
492 }
ClientState CS(Client this)
Definition: state.qh:47
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
entity bot_cmd
Definition: scripting.qh:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_keypress_handler()

float bot_cmd_keypress_handler ( entity  this,
string  key,
float  enabled 
)

Definition at line 889 of file scripting.qc.

References BOT_CMD_KEY_ATTACK1, BOT_CMD_KEY_ATTACK2, BOT_CMD_KEY_BACKWARD, BOT_CMD_KEY_CHAT, BOT_CMD_KEY_CROUCH, BOT_CMD_KEY_FORWARD, BOT_CMD_KEY_HOOK, BOT_CMD_KEY_JUMP, BOT_CMD_KEY_LEFT, BOT_CMD_KEY_NONE, BOT_CMD_KEY_RIGHT, BOT_CMD_KEY_USE, bot_cmd_keys, and CMD_STATUS_FINISHED.

Referenced by bot_cmd_presskey(), and bot_cmd_releasekey().

890 {
891  switch(key)
892  {
893  case "all":
894  if(enabled)
895  this.bot_cmd_keys = (2 ** 20) - 1; // >:)
896  else
898  case "forward":
899  if(enabled)
900  {
903  }
904  else
906  break;
907  case "backward":
908  if(enabled)
909  {
912  }
913  else
915  break;
916  case "left":
917  if(enabled)
918  {
921  }
922  else
924  break;
925  case "right":
926  if(enabled)
927  {
930  }
931  else
933  break;
934  case "jump":
935  if(enabled)
937  else
939  break;
940  case "crouch":
941  if(enabled)
943  else
945  break;
946  case "attack1":
947  if(enabled)
949  else
951  break;
952  case "attack2":
953  if(enabled)
955  else
957  break;
958  case "use":
959  if(enabled)
961  else
962  this.bot_cmd_keys &= ~BOT_CMD_KEY_USE;
963  break;
964  case "hook":
965  if(enabled)
967  else
969  break;
970  case "chat":
971  if(enabled)
973  else
975  break;
976  default:
977  break;
978  }
979 
980  return CMD_STATUS_FINISHED;
981 }
const int BOT_CMD_KEY_NONE
Definition: scripting.qc:827
const int BOT_CMD_KEY_RIGHT
Definition: scripting.qc:830
const int BOT_CMD_KEY_ATTACK1
Definition: scripting.qc:833
const int BOT_CMD_KEY_ATTACK2
Definition: scripting.qc:834
int bot_cmd_keys
Definition: scripting.qc:825
const int BOT_CMD_KEY_JUMP
Definition: scripting.qc:832
const int BOT_CMD_KEY_USE
Definition: scripting.qc:835
const int BOT_CMD_KEY_BACKWARD
Definition: scripting.qc:829
const int BOT_CMD_KEY_HOOK
Definition: scripting.qc:836
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
const int BOT_CMD_KEY_FORWARD
Definition: scripting.qc:828
const int BOT_CMD_KEY_CROUCH
Definition: scripting.qc:837
const int BOT_CMD_KEY_LEFT
Definition: scripting.qc:831
const int BOT_CMD_KEY_CHAT
Definition: scripting.qc:838
+ Here is the caller graph for this function:

◆ bot_cmd_moveto()

float bot_cmd_moveto ( entity  this)

Definition at line 1027 of file scripting.qc.

References bot_cmd.

Referenced by bot_execute_commands_once().

1028 {
1029  return this.cmd_moveto(this, bot_cmd.bot_cmd_parm_vector);
1030 }
entity bot_cmd
Definition: scripting.qh:59
+ Here is the caller graph for this function:

◆ bot_cmd_movetotarget()

float bot_cmd_movetotarget ( entity  this)

Definition at line 1032 of file scripting.qc.

References bot_cmd, bot_getplace(), CMD_STATUS_ERROR, and entity().

Referenced by bot_execute_commands_once().

1033 {
1034  entity e;
1035  e = bot_getplace(this, bot_cmd.bot_cmd_parm_string);
1036  if(!e)
1037  return CMD_STATUS_ERROR;
1038  return this.cmd_moveto(this, e.origin + (e.mins + e.maxs) * 0.5);
1039 }
entity() spawn
#define CMD_STATUS_ERROR
Definition: scripting.qh:9
entity bot_cmd
Definition: scripting.qh:59
entity bot_getplace(entity this, string placename)
Definition: scripting.qc:113
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_pause()

float bot_cmd_pause ( entity  this)

Definition at line 1008 of file scripting.qc.

References BOT_CMD_KEY_NONE, bot_cmd_keys, bot_exec_status, BOT_EXEC_STATUS_PAUSED, bot_relinkplayerlist(), CMD_STATUS_FINISHED, CS(), PHYS_INPUT_BUTTON_ATCK, PHYS_INPUT_BUTTON_ATCK2, PHYS_INPUT_BUTTON_CHAT, PHYS_INPUT_BUTTON_CROUCH, PHYS_INPUT_BUTTON_DRAG, PHYS_INPUT_BUTTON_HOOK, PHYS_INPUT_BUTTON_JUMP, and PHYS_INPUT_BUTTON_USE.

Referenced by bot_execute_commands_once().

1009 {
1010  PHYS_INPUT_BUTTON_DRAG(this) = false;
1011  PHYS_INPUT_BUTTON_USE(this) = false;
1012  PHYS_INPUT_BUTTON_ATCK(this) = false;
1013  PHYS_INPUT_BUTTON_JUMP(this) = false;
1014  PHYS_INPUT_BUTTON_HOOK(this) = false;
1015  PHYS_INPUT_BUTTON_CHAT(this) = false;
1016  PHYS_INPUT_BUTTON_ATCK2(this) = false;
1017  PHYS_INPUT_BUTTON_CROUCH(this) = false;
1018 
1019  CS(this).movement = '0 0 0';
1021 
1024  return CMD_STATUS_FINISHED;
1025 }
#define PHYS_INPUT_BUTTON_ATCK2(s)
Definition: player.qh:148
#define PHYS_INPUT_BUTTON_JUMP(s)
Definition: player.qh:147
#define PHYS_INPUT_BUTTON_CHAT(s)
Definition: player.qh:155
#define PHYS_INPUT_BUTTON_CROUCH(s)
Definition: player.qh:150
#define PHYS_INPUT_BUTTON_DRAG(s)
Definition: player.qh:153
#define PHYS_INPUT_BUTTON_HOOK(s)
Definition: player.qh:151
const int BOT_CMD_KEY_NONE
Definition: scripting.qc:827
void bot_relinkplayerlist()
Definition: bot.qc:381
#define BOT_EXEC_STATUS_PAUSED
Definition: scripting.qh:4
ClientState CS(Client this)
Definition: state.qh:47
int bot_cmd_keys
Definition: scripting.qc:825
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
#define PHYS_INPUT_BUTTON_USE(s)
Definition: player.qh:154
#define PHYS_INPUT_BUTTON_ATCK(s)
Definition: player.qh:146
int bot_exec_status
Definition: scripting.qc:480
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_presskey()

float bot_cmd_presskey ( entity  this)

Definition at line 983 of file scripting.qc.

References bot_cmd, bot_cmd_keypress_handler(), and CMD_STATUS_FINISHED.

Referenced by bot_execute_commands_once().

984 {
985  string key;
986 
987  key = bot_cmd.bot_cmd_parm_string;
988 
989  bot_cmd_keypress_handler(this, key,true);
990 
991  return CMD_STATUS_FINISHED;
992 }
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
float bot_cmd_keypress_handler(entity this, string key, float enabled)
Definition: scripting.qc:889
entity bot_cmd
Definition: scripting.qh:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_releasekey()

float bot_cmd_releasekey ( entity  this)

Definition at line 994 of file scripting.qc.

References bot_cmd, and bot_cmd_keypress_handler().

Referenced by bot_execute_commands_once().

995 {
996  string key;
997 
998  key = bot_cmd.bot_cmd_parm_string;
999 
1000  return bot_cmd_keypress_handler(this, key,false);
1001 }
float bot_cmd_keypress_handler(entity this, string key, float enabled)
Definition: scripting.qc:889
entity bot_cmd
Definition: scripting.qh:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_resetaim()

float bot_cmd_resetaim ( entity  this)

Definition at line 719 of file scripting.qc.

References CMD_STATUS_FINISHED, and v_angle.

Referenced by bot_execute_commands_once().

720 {
721  this.v_angle = '0 0 0';
722  return CMD_STATUS_FINISHED;
723 }
vector v_angle
Definition: progsdefs.qc:161
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
+ Here is the caller graph for this function:

◆ bot_cmd_resetgoal()

float bot_cmd_resetgoal ( entity  this)

Definition at line 1041 of file scripting.qc.

Referenced by bot_execute_commands_once().

1042 {
1043  return this.cmd_resetgoal(this);
1044 }
+ Here is the caller graph for this function:

◆ bot_cmd_select_weapon()

float bot_cmd_select_weapon ( entity  this)

Definition at line 573 of file scripting.qc.

References bot_cmd, client_hasweapon(), CMD_STATUS_ERROR, CMD_STATUS_FINISHED, MAX_WEAPONSLOTS, REGISTRY_GET, weaponentities, and WEP_LAST.

Referenced by bot_execute_commands_once().

574 {
575  float id = bot_cmd.bot_cmd_parm_float;
576 
577  if(id < WEP_FIRST || id > WEP_LAST)
578  return CMD_STATUS_ERROR;
579 
580  bool success = false;
581 
582  for(int slot = 0; slot < MAX_WEAPONSLOTS; ++slot)
583  {
584  .entity weaponentity = weaponentities[slot];
585  if(this.(weaponentity).m_weapon == WEP_Null && slot != 0)
586  continue;
587 
588  if(client_hasweapon(this, REGISTRY_GET(Weapons, id), weaponentity, true, false))
589  {
590  success = true;
591  this.(weaponentity).m_switchweapon = REGISTRY_GET(Weapons, id);
592  }
593  }
594 
595  if(!success)
596  return CMD_STATUS_ERROR;
597 
598  return CMD_STATUS_FINISHED;
599 }
#define REGISTRY_GET(id, i)
Definition: registry.qh:43
#define CMD_STATUS_ERROR
Definition: scripting.qh:9
#define WEP_LAST
Definition: all.qh:305
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
const int MAX_WEAPONSLOTS
Definition: weapon.qh:13
entity bot_cmd
Definition: scripting.qh:59
entity weaponentities[MAX_WEAPONSLOTS]
Definition: weapon.qh:14
bool client_hasweapon(entity this, Weapon wpn,.entity weaponentity, float andammo, bool complain)
Definition: selection.qc:48
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_sound()

float bot_cmd_sound ( entity  this)

Definition at line 1047 of file scripting.qc.

References _sound, argv(), atten, ATTEN_MIN, bot_cmd, CH_WEAPON_B, CMD_STATUS_FINISHED, precache_sound(), stof(), tokenizebyseparator, and VOL_BASE.

Referenced by bot_execute_commands_once().

1048 {
1049  string f;
1050  f = bot_cmd.bot_cmd_parm_string;
1051 
1052  float n = tokenizebyseparator(f, " ");
1053 
1054  string sample = f;
1055  float chan = CH_WEAPON_B;
1056  float vol = VOL_BASE;
1057  float atten = ATTEN_MIN;
1058 
1059  if(n >= 1)
1060  sample = argv(n - 1);
1061  if(n >= 2)
1062  chan = stof(argv(0));
1063  if(n >= 3)
1064  vol = stof(argv(1));
1065  if(n >= 4)
1066  atten = stof(argv(2));
1067 
1068  precache_sound(f);
1069  _sound(this, chan, sample, vol, atten);
1070 
1071  return CMD_STATUS_FINISHED;
1072 }
const float ATTEN_MIN
Definition: sound.qh:28
float atten
Definition: triggers.qh:47
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
entity bot_cmd
Definition: scripting.qh:59
const float VOL_BASE
Definition: sound.qh:36
#define _sound(e, c, s, v, a)
Definition: sound.qh:50
#define tokenizebyseparator
Definition: dpextensions.qh:21
const int CH_WEAPON_B
Definition: sound.qh:8
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_turn()

float bot_cmd_turn ( entity  this)

Definition at line 566 of file scripting.qc.

References bot_cmd, CMD_STATUS_FINISHED, floor(), and v_angle.

Referenced by bot_execute_commands_once().

567 {
568  this.v_angle_y = this.v_angle.y + bot_cmd.bot_cmd_parm_float;
569  this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360;
570  return CMD_STATUS_FINISHED;
571 }
vector v_angle
Definition: progsdefs.qc:161
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
entity bot_cmd
Definition: scripting.qh:59
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_cmd_wait()

float bot_cmd_wait ( entity  this)

Definition at line 502 of file scripting.qc.

References bot_cmd, bot_cmd_wait_time, bot_exec_status, BOT_EXEC_STATUS_WAITING, CMD_STATUS_EXECUTING, CMD_STATUS_FINISHED, and time.

Referenced by bot_execute_commands_once().

503 {
505  {
506  if(time>=this.bot_cmd_wait_time)
507  {
508  this.bot_exec_status &= ~BOT_EXEC_STATUS_WAITING;
509  return CMD_STATUS_FINISHED;
510  }
511  else
512  return CMD_STATUS_EXECUTING;
513  }
514 
515  this.bot_cmd_wait_time = time + bot_cmd.bot_cmd_parm_float;
517  return CMD_STATUS_EXECUTING;
518 }
#define BOT_EXEC_STATUS_WAITING
Definition: scripting.qh:5
float bot_cmd_wait_time
Definition: scripting.qc:501
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
entity bot_cmd
Definition: scripting.qh:59
#define CMD_STATUS_EXECUTING
Definition: scripting.qh:7
int bot_exec_status
Definition: scripting.qc:480
float time
Definition: csprogsdefs.qc:16
+ Here is the caller graph for this function:

◆ bot_cmd_wait_until()

float bot_cmd_wait_until ( entity  this)

Definition at line 520 of file scripting.qc.

References bot_barriertime, bot_cmd, bot_exec_status, BOT_EXEC_STATUS_WAITING, CMD_STATUS_EXECUTING, CMD_STATUS_FINISHED, and time.

Referenced by bot_execute_commands_once().

521 {
522  if(time < bot_cmd.bot_cmd_parm_float + bot_barriertime)
523  {
525  return CMD_STATUS_EXECUTING;
526  }
528  return CMD_STATUS_FINISHED;
529 }
#define BOT_EXEC_STATUS_WAITING
Definition: scripting.qh:5
float bot_barriertime
Definition: scripting.qh:68
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
entity bot_cmd
Definition: scripting.qh:59
#define CMD_STATUS_EXECUTING
Definition: scripting.qh:7
int bot_exec_status
Definition: scripting.qc:480
float time
Definition: csprogsdefs.qc:16
+ Here is the caller graph for this function:

◆ bot_cmdhelp()

void bot_cmdhelp ( string  scmd)

Definition at line 331 of file scripting.qc.

References BOT_CMD_AIM, BOT_CMD_AIMTARGET, BOT_CMD_BARRIER, BOT_CMD_CC, BOT_CMD_CONTINUE, BOT_CMD_COUNTER, BOT_CMD_DEBUG_ASSERT_CANFIRE, BOT_CMD_IF, BOT_CMD_MOVETO, BOT_CMD_MOVETOTARGET, BOT_CMD_PARAMETER_FLOAT, BOT_CMD_PARAMETER_STRING, BOT_CMD_PARAMETER_VECTOR, bot_cmd_parm_type, BOT_CMD_PAUSE, BOT_CMD_PRESSKEY, BOT_CMD_RELEASEKEY, BOT_CMD_RESETAIM, BOT_CMD_RESETGOAL, BOT_CMD_SOUND, bot_cmd_string, BOT_CMD_TURN, BOT_CMD_WAIT, BOT_CMD_WAIT_UNTIL, bot_cmds_initialized, bot_commands_init(), and LOG_HELP.

Referenced by GameCommand_bot_cmd().

332 {
333  int i, ntype;
334  string stype;
335 
338 
339  for(i=1;i<BOT_CMD_COUNTER;++i)
340  {
341  if(bot_cmd_string[i]!=scmd)
342  continue;
343 
344  ntype = bot_cmd_parm_type[i];
345 
346  switch(ntype)
347  {
349  stype = "float";
350  break;
352  stype = "string";
353  break;
355  stype = "vector";
356  break;
357  default:
358  stype = "none";
359  break;
360  }
361 
362  string desc = "";
363  switch(i)
364  {
365  case BOT_CMD_PAUSE:
366  desc = "Stops the bot completely. Any command other than 'continue' will be ignored.";
367  break;
368  case BOT_CMD_CONTINUE:
369  desc = "Disable paused status";
370  break;
371  case BOT_CMD_WAIT:
372  desc = "Pause command parsing and bot ai for N seconds. Pressed key will remain pressed";
373  break;
374  case BOT_CMD_WAIT_UNTIL:
375  desc = "Pause command parsing and bot ai until time is N from the last barrier. Pressed key will remain pressed";
376  break;
377  case BOT_CMD_BARRIER:
378  desc = "Waits till all bots that have a command queue reach this command. Pressed key will remain pressed";
379  break;
380  case BOT_CMD_TURN:
381  desc = "Look to the right or left N degrees. For turning to the left use positive numbers.";
382  break;
383  case BOT_CMD_MOVETO:
384  desc = "Walk to an specific coordinate on the map. Usage: moveto \'x y z\'";
385  break;
387  desc = "Walk to the specific target on the map";
388  break;
389  case BOT_CMD_RESETGOAL:
390  desc = "Resets the goal stack";
391  break;
392  case BOT_CMD_CC:
393  desc = "Execute client command. Examples: cc \"say something\"; cc god; cc \"name newnickname\"; cc kill;";
394  break;
395  case BOT_CMD_IF:
396  desc = "Perform simple conditional execution.\n"
397  "Syntax: \n"
398  " sv_cmd .. if \"condition\"\n"
399  " sv_cmd .. <instruction if true>\n"
400  " sv_cmd .. <instruction if true>\n"
401  " sv_cmd .. else\n"
402  " sv_cmd .. <instruction if false>\n"
403  " sv_cmd .. <instruction if false>\n"
404  " sv_cmd .. fi\n"
405  "Conditions: a=b, a>b, a<b, a\t\t(spaces not allowed)\n"
406  " Values in conditions can be numbers, cvars in the form cvar.cvar_string or special fields\n"
407  "Fields: health, speed, flagcarrier\n"
408  "Examples: if health>50; if health>cvar.g_balance_laser_primary_damage; if flagcarrier;";
409  break;
410  case BOT_CMD_RESETAIM:
411  desc = "Points the aim to the coordinates x,y 0,0";
412  break;
413  case BOT_CMD_AIM:
414  desc = "Move the aim x/y (horizontal/vertical) degrees relatives to the bot\n"
415  "There is a 3rd optional parameter telling in how many seconds the aim has to reach the new position\n"
416  "Examples: aim \"90 0\" // Turn 90 degrees inmediately (positive numbers move to the left/up)\n"
417  " aim \"0 90 2\" // Will gradually look to the sky in the next two seconds";
418  break;
419  case BOT_CMD_AIMTARGET:
420  desc = "Points the aim to given target";
421  break;
422  case BOT_CMD_PRESSKEY:
423  desc = "Press one of the following keys: forward, backward, left, right, jump, crouch, attack1, attack2, use"
424  "Multiple keys can be pressed at time (with many presskey calls) and it will remain pressed until the command \"releasekey\" is called"
425  "Note: The script will not return the control to the bot ai until all keys are released";
426  break;
427  case BOT_CMD_RELEASEKEY:
428  desc = "Release previoulsy used keys. Use the parameter \"all\" to release all keys";
429  break;
430  case BOT_CMD_SOUND:
431  desc = "play sound file at bot location";
432  break;
434  desc = "verify the state of the weapon entity";
435  break;
436  default:
437  desc = "This command has no description yet.";
438  break;
439  }
440  LOG_HELP("Command: ", bot_cmd_string[i], "\nParameter: <", stype, ">", "\nDescription: ", desc);
441  }
442 }
string bot_cmd_string[BOT_CMD_COUNTER]
Definition: scripting.qh:56
const int BOT_CMD_MOVETOTARGET
Definition: scripting.qh:31
const int BOT_CMD_SOUND
Definition: scripting.qh:35
const int BOT_CMD_AIMTARGET
Definition: scripting.qh:32
const int BOT_CMD_AIM
Definition: scripting.qh:25
int bot_cmd_parm_type[BOT_CMD_COUNTER]
Definition: scripting.qh:55
void bot_commands_init()
Definition: scripting.qc:157
const int BOT_CMD_RESETAIM
Definition: scripting.qh:24
const int BOT_CMD_MOVETO
Definition: scripting.qh:18
const int BOT_CMD_CC
Definition: scripting.qh:20
const int BOT_CMD_CONTINUE
Definition: scripting.qh:15
#define LOG_HELP(...)
Definition: log.qh:95
const int BOT_CMD_PAUSE
Definition: scripting.qh:14
const int BOT_CMD_PRESSKEY
Definition: scripting.qh:26
const int BOT_CMD_DEBUG_ASSERT_CANFIRE
Definition: scripting.qh:36
const int BOT_CMD_PARAMETER_VECTOR
Definition: scripting.qh:52
const int BOT_CMD_RESETGOAL
Definition: scripting.qh:19
const int BOT_CMD_WAIT_UNTIL
Definition: scripting.qh:30
const int BOT_CMD_COUNTER
Definition: scripting.qh:41
const int BOT_CMD_RELEASEKEY
Definition: scripting.qh:27
const int BOT_CMD_IF
Definition: scripting.qh:21
const int BOT_CMD_BARRIER
Definition: scripting.qh:33
const int BOT_CMD_PARAMETER_FLOAT
Definition: scripting.qh:50
float bot_cmds_initialized
Definition: scripting.qh:54
const int BOT_CMD_WAIT
Definition: scripting.qh:16
const int BOT_CMD_TURN
Definition: scripting.qh:17
const int BOT_CMD_PARAMETER_STRING
Definition: scripting.qh:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_command_executed()

void bot_command_executed ( entity  this,
bool  rm 
)

Definition at line 1119 of file scripting.qc.

References bot_cmd, bot_cmd_execution_index, bot_dequeuecommand(), cmd(), and entity().

Referenced by bot_execute_commands_once().

1120 {
1121  entity cmd;
1122 
1123  cmd = bot_cmd;
1124 
1125  if(rm)
1127 
1128  this.bot_cmd_execution_index++;
1129 }
entity() spawn
float bot_cmd_execution_index
Definition: scripting.qh:71
entity bot_cmd
Definition: scripting.qh:59
void bot_dequeuecommand(entity bot, float idx)
Definition: scripting.qc:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_commands_init()

void bot_commands_init ( )

Definition at line 157 of file scripting.qc.

References BOT_CMD_AIM, BOT_CMD_AIMTARGET, BOT_CMD_BARRIER, BOT_CMD_CC, BOT_CMD_CONSOLE, BOT_CMD_CONTINUE, BOT_CMD_DEBUG_ASSERT_CANFIRE, BOT_CMD_ELSE, BOT_CMD_FI, BOT_CMD_IF, BOT_CMD_IMPULSE, BOT_CMD_MOVETO, BOT_CMD_MOVETOTARGET, BOT_CMD_NULL, BOT_CMD_PARAMETER_FLOAT, BOT_CMD_PARAMETER_NONE, BOT_CMD_PARAMETER_STRING, BOT_CMD_PARAMETER_VECTOR, bot_cmd_parm_type, BOT_CMD_PAUSE, BOT_CMD_PRESSKEY, BOT_CMD_RELEASEKEY, BOT_CMD_RESETAIM, BOT_CMD_RESETGOAL, BOT_CMD_SELECTWEAPON, BOT_CMD_SOUND, bot_cmd_string, BOT_CMD_TURN, BOT_CMD_WAIT, BOT_CMD_WAIT_UNTIL, and bot_cmds_initialized.

Referenced by bot_cmdhelp(), bot_decodecommand(), and bot_list_commands().

158 {
161 
162  bot_cmd_string[BOT_CMD_PAUSE] = "pause";
164 
165  bot_cmd_string[BOT_CMD_CONTINUE] = "continue";
167 
168  bot_cmd_string[BOT_CMD_WAIT] = "wait";
170 
171  bot_cmd_string[BOT_CMD_TURN] = "turn";
173 
174  bot_cmd_string[BOT_CMD_MOVETO] = "moveto";
176 
177  bot_cmd_string[BOT_CMD_MOVETOTARGET] = "movetotarget";
179 
180  bot_cmd_string[BOT_CMD_RESETGOAL] = "resetgoal";
182 
183  bot_cmd_string[BOT_CMD_CC] = "cc";
185 
186  bot_cmd_string[BOT_CMD_IF] = "if";
188 
189  bot_cmd_string[BOT_CMD_ELSE] = "else";
191 
192  bot_cmd_string[BOT_CMD_FI] = "fi";
194 
195  bot_cmd_string[BOT_CMD_RESETAIM] = "resetaim";
197 
198  bot_cmd_string[BOT_CMD_AIM] = "aim";
200 
201  bot_cmd_string[BOT_CMD_AIMTARGET] = "aimtarget";
203 
204  bot_cmd_string[BOT_CMD_PRESSKEY] = "presskey";
206 
207  bot_cmd_string[BOT_CMD_RELEASEKEY] = "releasekey";
209 
210  bot_cmd_string[BOT_CMD_SELECTWEAPON] = "selectweapon";
212 
213  bot_cmd_string[BOT_CMD_IMPULSE] = "impulse";
215 
216  bot_cmd_string[BOT_CMD_WAIT_UNTIL] = "wait_until";
218 
219  bot_cmd_string[BOT_CMD_BARRIER] = "barrier";
221 
222  bot_cmd_string[BOT_CMD_CONSOLE] = "console";
224 
225  bot_cmd_string[BOT_CMD_SOUND] = "sound";
227 
228  bot_cmd_string[BOT_CMD_DEBUG_ASSERT_CANFIRE] = "debug_assert_canfire";
230 
231  bot_cmds_initialized = true;
232 }
string bot_cmd_string[BOT_CMD_COUNTER]
Definition: scripting.qh:56
const int BOT_CMD_MOVETOTARGET
Definition: scripting.qh:31
const int BOT_CMD_SOUND
Definition: scripting.qh:35
const int BOT_CMD_ELSE
Definition: scripting.qh:22
const int BOT_CMD_AIMTARGET
Definition: scripting.qh:32
const int BOT_CMD_AIM
Definition: scripting.qh:25
int bot_cmd_parm_type[BOT_CMD_COUNTER]
Definition: scripting.qh:55
const int BOT_CMD_RESETAIM
Definition: scripting.qh:24
const int BOT_CMD_MOVETO
Definition: scripting.qh:18
const int BOT_CMD_CC
Definition: scripting.qh:20
const int BOT_CMD_CONTINUE
Definition: scripting.qh:15
const int BOT_CMD_FI
Definition: scripting.qh:23
const int BOT_CMD_PAUSE
Definition: scripting.qh:14
const int BOT_CMD_PRESSKEY
Definition: scripting.qh:26
const int BOT_CMD_DEBUG_ASSERT_CANFIRE
Definition: scripting.qh:36
const int BOT_CMD_CONSOLE
Definition: scripting.qh:34
const int BOT_CMD_PARAMETER_VECTOR
Definition: scripting.qh:52
const int BOT_CMD_RESETGOAL
Definition: scripting.qh:19
const int BOT_CMD_WAIT_UNTIL
Definition: scripting.qh:30
const int BOT_CMD_IMPULSE
Definition: scripting.qh:29
const int BOT_CMD_RELEASEKEY
Definition: scripting.qh:27
const int BOT_CMD_PARAMETER_NONE
Definition: scripting.qh:49
const int BOT_CMD_IF
Definition: scripting.qh:21
const int BOT_CMD_BARRIER
Definition: scripting.qh:33
const int BOT_CMD_PARAMETER_FLOAT
Definition: scripting.qh:50
const int BOT_CMD_SELECTWEAPON
Definition: scripting.qh:28
float bot_cmds_initialized
Definition: scripting.qh:54
const int BOT_CMD_WAIT
Definition: scripting.qh:16
const int BOT_CMD_TURN
Definition: scripting.qh:17
const int BOT_CMD_PARAMETER_STRING
Definition: scripting.qh:51
const int BOT_CMD_NULL
Definition: scripting.qh:13
+ Here is the caller graph for this function:

◆ bot_decodecommand()

float bot_decodecommand ( string  cmdstring)

Definition at line 268 of file scripting.qc.

References bot_cmd, BOT_CMD_COUNTER, BOT_CMD_PARAMETER_FLOAT, BOT_CMD_PARAMETER_NONE, BOT_CMD_PARAMETER_STRING, BOT_CMD_PARAMETER_VECTOR, bot_cmd_parm_type, bot_cmd_string, bot_cmds_initialized, bot_commands_init(), LOG_INFO, LOG_INFOF, stof(), stov(), strcpy, strstrofs, and substring().

Referenced by bot_setcurrentcommand().

269 {
270  float cmd_parm_type;
271  float sp;
272  string parm;
273 
274  sp = strstrofs(cmdstring, " ", 0);
275  if(sp < 0)
276  {
277  parm = "";
278  }
279  else
280  {
281  parm = substring(cmdstring, sp + 1, -1);
282  cmdstring = substring(cmdstring, 0, sp);
283  }
284 
287 
288  int i;
289  for(i=1;i<BOT_CMD_COUNTER;++i)
290  {
291  if(bot_cmd_string[i]!=cmdstring)
292  continue;
293 
294  cmd_parm_type = bot_cmd_parm_type[i];
295 
296  if(cmd_parm_type!=BOT_CMD_PARAMETER_NONE&&parm=="")
297  {
298  LOG_INFO("ERROR: A parameter is required for this command");
299  return 0;
300  }
301 
302  // Load command into queue
303  bot_cmd.bot_cmd_type = i;
304 
305  // Attach parameter
306  switch(cmd_parm_type)
307  {
309  bot_cmd.bot_cmd_parm_float = stof(parm);
310  break;
312  strcpy(bot_cmd.bot_cmd_parm_string, parm);
313  break;
315  if(substring(parm, 0, 1) != "\'")
316  {
317  LOG_INFOF("ERROR: expected vector type \'x y z\', got %s", parm);
318  return 0;
319  }
320  bot_cmd.bot_cmd_parm_vector = stov(parm);
321  break;
322  default:
323  break;
324  }
325  return 1;
326  }
327  LOG_INFO("ERROR: No such command '", cmdstring, "'");
328  return 0;
329 }
string bot_cmd_string[BOT_CMD_COUNTER]
Definition: scripting.qh:56
int bot_cmd_parm_type[BOT_CMD_COUNTER]
Definition: scripting.qh:55
void bot_commands_init()
Definition: scripting.qc:157
#define strcpy(this, s)
Definition: string.qh:49
#define LOG_INFOF(...)
Definition: log.qh:71
entity bot_cmd
Definition: scripting.qh:59
#define LOG_INFO(...)
Definition: log.qh:70
#define strstrofs
Definition: dpextensions.qh:42
const int BOT_CMD_PARAMETER_VECTOR
Definition: scripting.qh:52
const int BOT_CMD_COUNTER
Definition: scripting.qh:41
const int BOT_CMD_PARAMETER_NONE
Definition: scripting.qh:49
const int BOT_CMD_PARAMETER_FLOAT
Definition: scripting.qh:50
float bot_cmds_initialized
Definition: scripting.qh:54
const int BOT_CMD_PARAMETER_STRING
Definition: scripting.qh:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_dequeuecommand()

void bot_dequeuecommand ( entity  bot,
float  idx 
)

Definition at line 72 of file scripting.qc.

References bot_clearqueue(), and error().

Referenced by bot_command_executed(), and bot_setcurrentcommand().

73 {
74  if(!bot.bot_cmdqueuebuf_allocated)
75  error("dequeuecommand but no queue allocated");
76  if(idx < bot.bot_cmdqueuebuf_start)
77  error("dequeueing a command in the past");
78  if(idx >= bot.bot_cmdqueuebuf_end)
79  error("dequeueing a command in the future");
80  bufstr_set(bot.bot_cmdqueuebuf, idx, "");
81  if(idx == bot.bot_cmdqueuebuf_start)
82  bot.bot_cmdqueuebuf_start += 1;
83  if(bot.bot_cmdqueuebuf_start >= bot.bot_cmdqueuebuf_end)
84  bot_clearqueue(bot);
85 }
void bot_clearqueue(entity bot)
Definition: scripting.qc:21
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_execute_commands()

int bot_execute_commands ( entity  this)

Definition at line 1350 of file scripting.qc.

References bot_execute_commands_once().

Referenced by havocbot_ai().

1351 {
1352  int f;
1353  do
1354  {
1355  f = bot_execute_commands_once(this);
1356  }
1357  while(f < 0);
1358  return f;
1359 }
float bot_execute_commands_once(entity this)
Definition: scripting.qc:1184
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_execute_commands_once()

float bot_execute_commands_once ( entity  this)

Definition at line 1184 of file scripting.qc.

References autocvar_g_debug_bot_commands, boolean, bot_cmd, BOT_CMD_AIM, bot_cmd_aim(), BOT_CMD_AIMTARGET, bot_cmd_aimtarget(), BOT_CMD_BARRIER, bot_cmd_barrier(), BOT_CMD_CC, bot_cmd_cc(), bot_cmd_condition_status, BOT_CMD_CONSOLE, BOT_CMD_CONTINUE, bot_cmd_continue(), BOT_CMD_DEBUG_ASSERT_CANFIRE, bot_cmd_debug_assert_canfire(), BOT_CMD_ELSE, bot_cmd_else(), BOT_CMD_FI, bot_cmd_fi(), BOT_CMD_IF, bot_cmd_if(), BOT_CMD_IMPULSE, bot_cmd_impulse(), BOT_CMD_MOVETO, bot_cmd_moveto(), BOT_CMD_MOVETOTARGET, bot_cmd_movetotarget(), BOT_CMD_NULL, BOT_CMD_PARAMETER_FLOAT, BOT_CMD_PARAMETER_STRING, BOT_CMD_PARAMETER_VECTOR, bot_cmd_parm_type, BOT_CMD_PAUSE, bot_cmd_pause(), BOT_CMD_PRESSKEY, bot_cmd_presskey(), BOT_CMD_RELEASEKEY, bot_cmd_releasekey(), BOT_CMD_RESETAIM, bot_cmd_resetaim(), BOT_CMD_RESETGOAL, bot_cmd_resetgoal(), bot_cmd_select_weapon(), BOT_CMD_SELECTWEAPON, BOT_CMD_SOUND, bot_cmd_sound(), bot_cmd_string, BOT_CMD_TURN, bot_cmd_turn(), BOT_CMD_WAIT, bot_cmd_wait(), BOT_CMD_WAIT_UNTIL, bot_cmd_wait_until(), bot_command_executed(), bot_exec_status, BOT_EXEC_STATUS_PAUSED, bot_presskeys(), bot_setcurrentcommand(), clientcommand(), CMD_CONDITION_false, CMD_CONDITION_false_BLOCK, CMD_CONDITION_true, CMD_CONDITION_true_BLOCK, CMD_STATUS_ERROR, CMD_STATUS_EXECUTING, CMD_STATUS_FINISHED, ftos(), localcmd, LOG_INFO, LOG_INFOF, strcat(), vtos(), and world.

Referenced by bot_execute_commands().

1185 {
1186  float status, ispressingkey;
1187 
1188  // Find command
1189  bot_setcurrentcommand(this);
1190 
1191  // Ignore all commands except continue when the bot is paused
1193  {
1194  // if we have no bot command, better return
1195  // old logic kept pressing previously pressed keys, but that has problems
1196  // (namely, it means you cannot make a bot "normal" ever again)
1197  // to keep a bot walking for a while, use the "wait" bot command
1198  if(bot_cmd == world)
1199  return 0;
1200  }
1201  else if(bot_cmd.bot_cmd_type != BOT_CMD_CONTINUE)
1202  {
1203  if(bot_cmd.bot_cmd_type!=BOT_CMD_NULL)
1204  {
1205  bot_command_executed(this, true);
1206  LOG_INFO("WARNING: Commands are ignored while the bot is paused. Use the command 'continue' instead.");
1207  }
1208  return 1;
1209  }
1210 
1211  // Keep pressing keys raised by the "presskey" command
1212  ispressingkey = boolean(bot_presskeys(this));
1213 
1214  // Handle conditions
1215  if (!(bot_cmd.bot_cmd_type==BOT_CMD_FI||bot_cmd.bot_cmd_type==BOT_CMD_ELSE))
1217  {
1218  bot_command_executed(this, true);
1219  return -1;
1220  }
1222  {
1223  bot_command_executed(this, true);
1224  return -1;
1225  }
1226 
1227  // Map commands to functions
1228  switch(bot_cmd.bot_cmd_type)
1229  {
1230  case BOT_CMD_NULL:
1231  return ispressingkey;
1232  //break;
1233  case BOT_CMD_PAUSE:
1234  status = bot_cmd_pause(this);
1235  break;
1236  case BOT_CMD_CONTINUE:
1237  status = bot_cmd_continue(this);
1238  break;
1239  case BOT_CMD_WAIT:
1240  status = bot_cmd_wait(this);
1241  break;
1242  case BOT_CMD_WAIT_UNTIL:
1243  status = bot_cmd_wait_until(this);
1244  break;
1245  case BOT_CMD_TURN:
1246  status = bot_cmd_turn(this);
1247  break;
1248  case BOT_CMD_MOVETO:
1249  status = bot_cmd_moveto(this);
1250  break;
1251  case BOT_CMD_MOVETOTARGET:
1252  status = bot_cmd_movetotarget(this);
1253  break;
1254  case BOT_CMD_RESETGOAL:
1255  status = bot_cmd_resetgoal(this);
1256  break;
1257  case BOT_CMD_CC:
1258  status = bot_cmd_cc(this);
1259  break;
1260  case BOT_CMD_IF:
1261  status = bot_cmd_if(this);
1262  break;
1263  case BOT_CMD_ELSE:
1264  status = bot_cmd_else(this);
1265  break;
1266  case BOT_CMD_FI:
1267  status = bot_cmd_fi(this);
1268  break;
1269  case BOT_CMD_RESETAIM:
1270  status = bot_cmd_resetaim(this);
1271  break;
1272  case BOT_CMD_AIM:
1273  status = bot_cmd_aim(this);
1274  break;
1275  case BOT_CMD_AIMTARGET:
1276  status = bot_cmd_aimtarget(this);
1277  break;
1278  case BOT_CMD_PRESSKEY:
1279  status = bot_cmd_presskey(this);
1280  break;
1281  case BOT_CMD_RELEASEKEY:
1282  status = bot_cmd_releasekey(this);
1283  break;
1284  case BOT_CMD_SELECTWEAPON:
1285  status = bot_cmd_select_weapon(this);
1286  break;
1287  case BOT_CMD_IMPULSE:
1288  status = bot_cmd_impulse(this);
1289  break;
1290  case BOT_CMD_BARRIER:
1291  status = bot_cmd_barrier(this);
1292  break;
1293  case BOT_CMD_CONSOLE:
1294  localcmd(strcat(bot_cmd.bot_cmd_parm_string, "\n"));
1295  status = CMD_STATUS_FINISHED;
1296  break;
1297  case BOT_CMD_SOUND:
1298  status = bot_cmd_sound(this);
1299  break;
1301  status = bot_cmd_debug_assert_canfire(this);
1302  break;
1303  default:
1304  LOG_INFOF("ERROR: Invalid command on queue with id '%s'", ftos(bot_cmd.bot_cmd_type));
1305  return 0;
1306  }
1307 
1308  if (status==CMD_STATUS_ERROR)
1309  LOG_INFOF("ERROR: The command '%s' returned an error status", bot_cmd_string[bot_cmd.bot_cmd_type]);
1310 
1311  // Move execution pointer
1312  if(status==CMD_STATUS_EXECUTING)
1313  {
1314  return 1;
1315  }
1316  else
1317  {
1319  {
1320  string parms;
1321 
1322  switch(bot_cmd_parm_type[bot_cmd.bot_cmd_type])
1323  {
1325  parms = ftos(bot_cmd.bot_cmd_parm_float);
1326  break;
1328  parms = bot_cmd.bot_cmd_parm_string;
1329  break;
1331  parms = vtos(bot_cmd.bot_cmd_parm_vector);
1332  break;
1333  default:
1334  parms = "";
1335  break;
1336  }
1337  clientcommand(this,strcat("say ^7", bot_cmd_string[bot_cmd.bot_cmd_type]," ",parms,"\n"));
1338  }
1339 
1340  bot_command_executed(this, true);
1341  }
1342 
1343  if(status == CMD_STATUS_FINISHED)
1344  return -1;
1345 
1346  return CMD_STATUS_ERROR;
1347 }
string bot_cmd_string[BOT_CMD_COUNTER]
Definition: scripting.qh:56
const int CMD_CONDITION_false_BLOCK
Definition: scripting.qc:607
entity world
Definition: csprogsdefs.qc:15
float bot_cmd_continue(entity this)
Definition: scripting.qc:494
const int BOT_CMD_MOVETOTARGET
Definition: scripting.qh:31
const int BOT_CMD_SOUND
Definition: scripting.qh:35
const int BOT_CMD_ELSE
Definition: scripting.qh:22
float bot_cmd_impulse(entity this)
Definition: scripting.qc:488
float bot_cmd_resetaim(entity this)
Definition: scripting.qc:719
const int BOT_CMD_AIMTARGET
Definition: scripting.qh:32
float bot_cmd_sound(entity this)
Definition: scripting.qc:1047
bool autocvar_g_debug_bot_commands
Definition: cvars.qh:62
const int BOT_CMD_AIM
Definition: scripting.qh:25
int bot_cmd_parm_type[BOT_CMD_COUNTER]
Definition: scripting.qh:55
int bot_cmd_condition_status
Definition: scripting.qc:601
void bot_command_executed(entity this, bool rm)
Definition: scripting.qc:1119
float bot_cmd_moveto(entity this)
Definition: scripting.qc:1027
#define BOT_EXEC_STATUS_PAUSED
Definition: scripting.qh:4
float bot_cmd_wait_until(entity this)
Definition: scripting.qc:520
float bot_cmd_else(entity this)
Definition: scripting.qc:706
float bot_cmd_barrier(entity this)
Definition: scripting.qc:531
const int BOT_CMD_RESETAIM
Definition: scripting.qh:24
float bot_cmd_cc(entity this)
Definition: scripting.qc:482
const int BOT_CMD_MOVETO
Definition: scripting.qh:18
const int BOT_CMD_CC
Definition: scripting.qh:20
#define CMD_STATUS_ERROR
Definition: scripting.qh:9
const int BOT_CMD_CONTINUE
Definition: scripting.qh:15
float bot_cmd_aim(entity this)
Definition: scripting.qc:730
const int BOT_CMD_FI
Definition: scripting.qh:23
float bot_cmd_releasekey(entity this)
Definition: scripting.qc:994
float bot_cmd_aimtarget(entity this)
Definition: scripting.qc:781
const int BOT_CMD_PAUSE
Definition: scripting.qh:14
float bot_cmd_debug_assert_canfire(entity this)
Definition: scripting.qc:1075
#define CMD_STATUS_FINISHED
Definition: scripting.qh:8
float bot_cmd_select_weapon(entity this)
Definition: scripting.qc:573
float bot_cmd_fi(entity this)
Definition: scripting.qc:713
const int BOT_CMD_PRESSKEY
Definition: scripting.qh:26
float bot_cmd_movetotarget(entity this)
Definition: scripting.qc:1032
const int CMD_CONDITION_false
Definition: scripting.qc:605
#define LOG_INFOF(...)
Definition: log.qh:71
float bot_cmd_wait(entity this)
Definition: scripting.qc:502
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
float bot_cmd_pause(entity this)
Definition: scripting.qc:1008
entity bot_cmd
Definition: scripting.qh:59
const int CMD_CONDITION_true
Definition: scripting.qc:604
#define LOG_INFO(...)
Definition: log.qh:70
#define CMD_STATUS_EXECUTING
Definition: scripting.qh:7
float bot_cmd_resetgoal(entity this)
Definition: scripting.qc:1041
const int BOT_CMD_DEBUG_ASSERT_CANFIRE
Definition: scripting.qh:36
const int BOT_CMD_CONSOLE
Definition: scripting.qh:34
int bot_exec_status
Definition: scripting.qc:480
const int BOT_CMD_PARAMETER_VECTOR
Definition: scripting.qh:52
const int BOT_CMD_RESETGOAL
Definition: scripting.qh:19
const int BOT_CMD_WAIT_UNTIL
Definition: scripting.qh:30
const int BOT_CMD_IMPULSE
Definition: scripting.qh:29
const int CMD_CONDITION_true_BLOCK
Definition: scripting.qc:606
float bot_cmd_turn(entity this)
Definition: scripting.qc:566
const int BOT_CMD_RELEASEKEY
Definition: scripting.qh:27
bool bot_presskeys(entity this)
Definition: scripting.qc:840
float bot_cmd_presskey(entity this)
Definition: scripting.qc:983
const int BOT_CMD_IF
Definition: scripting.qh:21
float bot_cmd_if(entity this)
Definition: scripting.qc:635
void bot_setcurrentcommand(entity this)
Definition: scripting.qc:1131
const int BOT_CMD_BARRIER
Definition: scripting.qh:33
const int BOT_CMD_PARAMETER_FLOAT
Definition: scripting.qh:50
const int BOT_CMD_SELECTWEAPON
Definition: scripting.qh:28
#define boolean(value)
Definition: bool.qh:9
const int BOT_CMD_WAIT
Definition: scripting.qh:16
const int BOT_CMD_TURN
Definition: scripting.qh:17
const int BOT_CMD_PARAMETER_STRING
Definition: scripting.qh:51
const int BOT_CMD_NULL
Definition: scripting.qh:13
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_getplace()

entity bot_getplace ( entity  this,
string  placename 
)

Definition at line 113 of file scripting.qc.

References bot_placenames, bot_places, bot_places_count, cvar_set(), cvar_string(), entity(), find(), LOG_INFO, MAX_BOT_PLACES, NULL, s2, strcat(), strstrofs, strzone(), substring(), and targetname.

Referenced by bot_cmd_aimtarget(), and bot_cmd_movetotarget().

114 {
115  entity e;
116  if(substring(placename, 0, 1) == "@")
117  {
118  int i, p;
119  placename = substring(placename, 1, -1);
120  string s, s2;
121  for(i = 0; i < this.bot_places_count; ++i)
122  if(this.(bot_placenames[i]) == placename)
123  return this.(bot_places[i]);
124  // now: i == this.bot_places_count
125  s = s2 = cvar_string(placename);
126  p = strstrofs(s2, " ", 0);
127  if(p >= 0)
128  {
129  s = substring(s2, 0, p);
130  //print("places: ", placename, " -> ", cvar_string(placename), "\n");
131  cvar_set(placename, strcat(substring(s2, p+1, -1), " ", s));
132  //print("places: ", placename, " := ", cvar_string(placename), "\n");
133  }
134  e = find(NULL, targetname, s);
135  if(!e)
136  LOG_INFO("invalid place ", s);
137  if(i < MAX_BOT_PLACES)
138  {
139  this.(bot_placenames[i]) = strzone(placename);
140  this.(bot_places[i]) = e;
141  this.bot_places_count += 1;
142  }
143  return e;
144  }
145  else
146  {
147  e = find(NULL, targetname, placename);
148  if(!e)
149  LOG_INFO("invalid place ", placename);
150  return e;
151  }
152 }
spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 spree_inf s1 s2 s3loc s2 s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2loc s1 s2 f1 f1points s1 s2
Definition: all.inc:438
entity() spawn
string bot_placenames[MAX_BOT_PLACES]
Definition: scripting.qc:112
spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 spree_cen s1 f1 s1 strcat(_("Level %s: "), "^BG%s\3\, _("^BGPress ^F2%s^BG to enter the game"))
entity bot_places[MAX_BOT_PLACES]
Definition: scripting.qc:111
#define NULL
Definition: post.qh:17
#define LOG_INFO(...)
Definition: log.qh:70
#define strstrofs
Definition: dpextensions.qh:42
float bot_places_count
Definition: scripting.qc:110
string targetname
Definition: progsdefs.qc:194
const int MAX_BOT_PLACES
Definition: scripting.qc:109
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_havecommand()

bool bot_havecommand ( entity  this,
int  idx 
)

Definition at line 98 of file scripting.qc.

References bot_cmdqueuebuf_allocated, bot_cmdqueuebuf_end, and bot_cmdqueuebuf_start.

Referenced by bot_setcurrentcommand().

99 {
100  if(!this.bot_cmdqueuebuf_allocated)
101  return false;
102  if(idx < this.bot_cmdqueuebuf_start)
103  return false;
104  if(idx >= this.bot_cmdqueuebuf_end)
105  return false;
106  return true;
107 }
float bot_cmdqueuebuf_start
Definition: scripting.qc:18
float bot_cmdqueuebuf_end
Definition: scripting.qc:19
float bot_cmdqueuebuf_allocated
Definition: scripting.qc:16
+ Here is the caller graph for this function:

◆ bot_ispaused()

bool bot_ispaused ( entity  this)

Definition at line 1003 of file scripting.qc.

References bot_exec_status, and BOT_EXEC_STATUS_PAUSED.

Referenced by bot_relinkplayerlist(), and havocbot_ai().

1004 {
1005  return(this.bot_exec_status & BOT_EXEC_STATUS_PAUSED);
1006 }
#define BOT_EXEC_STATUS_PAUSED
Definition: scripting.qh:4
int bot_exec_status
Definition: scripting.qc:480
+ Here is the caller graph for this function:

◆ bot_list_commands()

void bot_list_commands ( )

Definition at line 444 of file scripting.qc.

References BOT_CMD_COUNTER, BOT_CMD_PARAMETER_FLOAT, BOT_CMD_PARAMETER_STRING, BOT_CMD_PARAMETER_VECTOR, bot_cmd_parm_type, bot_cmd_string, bot_cmds_initialized, bot_commands_init(), and LOG_HELP.

Referenced by GameCommand_bot_cmd().

445 {
446  int i;
447  string ptype;
448 
451 
452  LOG_HELP("Bot commands:");
453 
454  for(i=1;i<BOT_CMD_COUNTER;++i)
455  {
456  switch(bot_cmd_parm_type[i])
457  {
459  ptype = "float";
460  break;
462  ptype = "string";
463  break;
465  ptype = "vector";
466  break;
467  default:
468  ptype = "none";
469  break;
470  }
471  if (ptype != "none")
472  LOG_HELP(" ^2", bot_cmd_string[i]," ^7<", ptype, ">");
473  else
474  LOG_HELP(" ^2", bot_cmd_string[i]);
475  }
476  LOG_HELP("For help about a specific command, type bot_cmd help <command>");
477 }
string bot_cmd_string[BOT_CMD_COUNTER]
Definition: scripting.qh:56
int bot_cmd_parm_type[BOT_CMD_COUNTER]
Definition: scripting.qh:55
void bot_commands_init()
Definition: scripting.qc:157
#define LOG_HELP(...)
Definition: log.qh:95
const int BOT_CMD_PARAMETER_VECTOR
Definition: scripting.qh:52
const int BOT_CMD_COUNTER
Definition: scripting.qh:41
const int BOT_CMD_PARAMETER_FLOAT
Definition: scripting.qh:50
float bot_cmds_initialized
Definition: scripting.qh:54
const int BOT_CMD_PARAMETER_STRING
Definition: scripting.qh:51
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_presskeys()

bool bot_presskeys ( entity  this)

Definition at line 840 of file scripting.qc.

References BOT_CMD_KEY_ATTACK1, BOT_CMD_KEY_ATTACK2, BOT_CMD_KEY_BACKWARD, BOT_CMD_KEY_CHAT, BOT_CMD_KEY_CROUCH, BOT_CMD_KEY_FORWARD, BOT_CMD_KEY_HOOK, BOT_CMD_KEY_JUMP, BOT_CMD_KEY_LEFT, BOT_CMD_KEY_NONE, BOT_CMD_KEY_RIGHT, BOT_CMD_KEY_USE, bot_cmd_keys, CS(), PHYS_INPUT_BUTTON_ATCK, PHYS_INPUT_BUTTON_ATCK2, PHYS_INPUT_BUTTON_CHAT, PHYS_INPUT_BUTTON_CROUCH, PHYS_INPUT_BUTTON_HOOK, PHYS_INPUT_BUTTON_JUMP, and PHYS_INPUT_BUTTON_USE.

Referenced by bot_execute_commands_once().

841 {
842  CS(this).movement = '0 0 0';
843  PHYS_INPUT_BUTTON_JUMP(this) = false;
844  PHYS_INPUT_BUTTON_CROUCH(this) = false;
845  PHYS_INPUT_BUTTON_ATCK(this) = false;
846  PHYS_INPUT_BUTTON_ATCK2(this) = false;
847  PHYS_INPUT_BUTTON_USE(this) = false;
848  PHYS_INPUT_BUTTON_HOOK(this) = false;
849  PHYS_INPUT_BUTTON_CHAT(this) = false;
850 
851  if(this.bot_cmd_keys == BOT_CMD_KEY_NONE)
852  return false;
853 
855  CS(this).movement_x = autocvar_sv_maxspeed;
856  else if(this.bot_cmd_keys & BOT_CMD_KEY_BACKWARD)
857  CS(this).movement_x = -autocvar_sv_maxspeed;
858 
860  CS(this).movement_y = autocvar_sv_maxspeed;
861  else if(this.bot_cmd_keys & BOT_CMD_KEY_LEFT)
862  CS(this).movement_y = -autocvar_sv_maxspeed;
863 
864  if(this.bot_cmd_keys & BOT_CMD_KEY_JUMP)
865  PHYS_INPUT_BUTTON_JUMP(this) = true;
866 
868  PHYS_INPUT_BUTTON_CROUCH(this) = true;
869 
871  PHYS_INPUT_BUTTON_ATCK(this) = true;
872 
874  PHYS_INPUT_BUTTON_ATCK2(this) = true;
875 
876  if(this.bot_cmd_keys & BOT_CMD_KEY_USE)
877  PHYS_INPUT_BUTTON_USE(this) = true;
878 
879  if(this.bot_cmd_keys & BOT_CMD_KEY_HOOK)
880  PHYS_INPUT_BUTTON_HOOK(this) = true;
881 
882  if(this.bot_cmd_keys & BOT_CMD_KEY_CHAT)
883  PHYS_INPUT_BUTTON_CHAT(this) = true;
884 
885  return true;
886 }
#define PHYS_INPUT_BUTTON_ATCK2(s)
Definition: player.qh:148
#define PHYS_INPUT_BUTTON_JUMP(s)
Definition: player.qh:147
#define PHYS_INPUT_BUTTON_CHAT(s)
Definition: player.qh:155
#define PHYS_INPUT_BUTTON_CROUCH(s)
Definition: player.qh:150
#define PHYS_INPUT_BUTTON_HOOK(s)
Definition: player.qh:151
const int BOT_CMD_KEY_NONE
Definition: scripting.qc:827
const int BOT_CMD_KEY_RIGHT
Definition: scripting.qc:830
ClientState CS(Client this)
Definition: state.qh:47
const int BOT_CMD_KEY_ATTACK1
Definition: scripting.qc:833
const int BOT_CMD_KEY_ATTACK2
Definition: scripting.qc:834
int bot_cmd_keys
Definition: scripting.qc:825
const int BOT_CMD_KEY_JUMP
Definition: scripting.qc:832
const int BOT_CMD_KEY_USE
Definition: scripting.qc:835
const int BOT_CMD_KEY_BACKWARD
Definition: scripting.qc:829
const int BOT_CMD_KEY_HOOK
Definition: scripting.qc:836
#define PHYS_INPUT_BUTTON_USE(s)
Definition: player.qh:154
#define PHYS_INPUT_BUTTON_ATCK(s)
Definition: player.qh:146
const int BOT_CMD_KEY_FORWARD
Definition: scripting.qc:828
const int BOT_CMD_KEY_CROUCH
Definition: scripting.qc:837
const int BOT_CMD_KEY_LEFT
Definition: scripting.qc:831
const int BOT_CMD_KEY_CHAT
Definition: scripting.qc:838
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_queuecommand()

void bot_queuecommand ( entity  bot,
string  cmdstring 
)

Definition at line 30 of file scripting.qc.

References buf_create, precache_sound(), strstrofs, and substring().

Referenced by GameCommand_bot_cmd().

31 {
32  if(!bot.bot_cmdqueuebuf_allocated)
33  {
34  bot.bot_cmdqueuebuf = buf_create();
35  bot.bot_cmdqueuebuf_allocated = true;
36  bot.bot_cmdqueuebuf_start = 0;
37  bot.bot_cmdqueuebuf_end = 0;
38  }
39 
40  bufstr_set(bot.bot_cmdqueuebuf, bot.bot_cmdqueuebuf_end, cmdstring);
41 
42  // if the command was a "sound" command, precache the sound NOW
43  // this prevents lagging!
44  {
45  float sp;
46  string parm;
47  string cmdstr;
48 
49  sp = strstrofs(cmdstring, " ", 0);
50  if(sp >= 0)
51  {
52  parm = substring(cmdstring, sp + 1, -1);
53  cmdstr = substring(cmdstring, 0, sp);
54  if(cmdstr == "sound")
55  {
56  // find the LAST word
57  for (;;)
58  {
59  sp = strstrofs(parm, " ", 0);
60  if(sp < 0)
61  break;
62  parm = substring(parm, sp + 1, -1);
63  }
64  precache_sound(parm);
65  }
66  }
67  }
68 
69  bot.bot_cmdqueuebuf_end += 1;
70 }
#define buf_create
Definition: dpextensions.qh:63
#define strstrofs
Definition: dpextensions.qh:42
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_readcommand()

string bot_readcommand ( entity  bot,
float  idx 
)

Definition at line 87 of file scripting.qc.

References error().

Referenced by bot_setcurrentcommand().

88 {
89  if(!bot.bot_cmdqueuebuf_allocated)
90  error("readcommand but no queue allocated");
91  if(idx < bot.bot_cmdqueuebuf_start)
92  error("reading a command in the past");
93  if(idx >= bot.bot_cmdqueuebuf_end)
94  error("reading a command in the future");
95  return bufstr_get(bot.bot_cmdqueuebuf, idx);
96 }
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bot_resetqueues()

void bot_resetqueues ( )

Definition at line 1165 of file scripting.qc.

References FOREACH_CLIENT.

Referenced by GameCommand_bot_cmd().

1166 {
1167  FOREACH_CLIENT(it.isbot, {
1168  it.bot_cmd_execution_index = 0;
1169  bot_clearqueue(it);
1170  // also, cancel all barriers
1171  it.bot_barrier = 0;
1172  for(int i = 0; i < it.bot_places_count; ++i)
1173  {
1174  strfree(it.(bot_placenames[i]));
1175  }
1176  it.bot_places_count = 0;
1177  });
1178 
1180 }
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
float bot_barriertime
Definition: scripting.qh:68
float time
Definition: csprogsdefs.qc:16
+ Here is the caller graph for this function:

◆ bot_setcurrentcommand()

void bot_setcurrentcommand ( entity  this)

Definition at line 1131 of file scripting.qc.

References bot_cmd, bot_cmd_current, bot_cmd_execution_index, bot_decodecommand(), bot_dequeuecommand(), bot_havecommand(), bot_readcommand(), new_pure, and NULL.

Referenced by bot_execute_commands_once().

1132 {
1133  bot_cmd = NULL;
1134 
1135  if(!this.bot_cmd_current)
1136  {
1138  }
1139 
1140  bot_cmd = this.bot_cmd_current;
1141  if(bot_cmd.bot_cmd_index != this.bot_cmd_execution_index || this.bot_cmd_execution_index == 0)
1142  {
1144  {
1145  string cmdstring;
1146  cmdstring = bot_readcommand(this, this.bot_cmd_execution_index);
1147  if(bot_decodecommand(cmdstring))
1148  {
1149  bot_cmd.owner = this;
1150  bot_cmd.bot_cmd_index = this.bot_cmd_execution_index;
1151  }
1152  else
1153  {
1154  // Invalid command, remove from queue
1155  bot_cmd = NULL;
1157  this.bot_cmd_execution_index++;
1158  }
1159  }
1160  else
1161  bot_cmd = NULL;
1162  }
1163 }
string bot_readcommand(entity bot, float idx)
Definition: scripting.qc:87
entity bot_cmd_current
Definition: scripting.qh:60
float bot_decodecommand(string cmdstring)
Definition: scripting.qc:268
bool bot_havecommand(entity this, int idx)
Definition: scripting.qc:98
float bot_cmd_execution_index
Definition: scripting.qh:71
entity bot_cmd
Definition: scripting.qh:59
#define NULL
Definition: post.qh:17
#define new_pure(class)
purely logical entities (.origin doesn&#39;t work)
Definition: oo.qh:62
void bot_dequeuecommand(entity bot, float idx)
Definition: scripting.qc:72
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ find_bot_by_name()

entity find_bot_by_name ( string  name)

Definition at line 235 of file scripting.qc.

References FOREACH_CLIENT, IS_BOT_CLIENT, and NULL.

Referenced by GameCommand_bot_cmd().

236 {
237  FOREACH_CLIENT(IS_BOT_CLIENT(it) && it.netname == name,
238  {
239  return it;
240  });
241 
242  return NULL;
243 }
#define FOREACH_CLIENT(cond, body)
Definition: utils.qh:49
#define NULL
Definition: post.qh:17
#define IS_BOT_CLIENT(v)
want: (IS_CLIENT(v) && !IS_REAL_CLIENT(v))
Definition: utils.qh:15
+ Here is the caller graph for this function:

◆ find_bot_by_number()

entity find_bot_by_number ( float  number)

Definition at line 246 of file scripting.qc.

References entity(), findchainflags(), FL_CLIENT, flags, IS_BOT_CLIENT, and NULL.

Referenced by GameCommand_bot_cmd().

247 {
248  entity bot;
249  float c = 0;
250 
251  if(!number)
252  return NULL;
253 
254  bot = findchainflags(flags, FL_CLIENT); // TODO: doesn't findchainflags loop backwards through entities?
255  while (bot)
256  {
257  if(IS_BOT_CLIENT(bot))
258  {
259  if(++c==number)
260  return bot;
261  }
262  bot = bot.chain;
263  }
264 
265  return NULL;
266 }
int int number
Definition: impulse.qc:89
entity() spawn
#define NULL
Definition: post.qh:17
float flags
Definition: csprogsdefs.qc:129
#define IS_BOT_CLIENT(v)
want: (IS_CLIENT(v) && !IS_REAL_CLIENT(v))
Definition: utils.qh:15
float FL_CLIENT
Definition: progsdefs.qc:234
+ Here is the call graph for this function:
+ Here is the caller graph for this function:

Variable Documentation

◆ bot_cmd_aim_begin

vector bot_cmd_aim_begin

Definition at line 727 of file scripting.qc.

Referenced by bot_cmd_aim(), and bot_cmd_aimtarget().

◆ bot_cmd_aim_begintime

float bot_cmd_aim_begintime

Definition at line 725 of file scripting.qc.

Referenced by bot_cmd_aim(), and bot_cmd_aimtarget().

◆ bot_cmd_aim_end

vector bot_cmd_aim_end

Definition at line 728 of file scripting.qc.

Referenced by bot_cmd_aim(), and bot_cmd_aimtarget().

◆ bot_cmd_aim_endtime

float bot_cmd_aim_endtime

Definition at line 726 of file scripting.qc.

Referenced by bot_cmd_aim(), and bot_cmd_aimtarget().

◆ bot_cmd_condition_status

int bot_cmd_condition_status

Definition at line 601 of file scripting.qc.

Referenced by bot_cmd_else(), bot_cmd_fi(), bot_cmd_if(), and bot_execute_commands_once().

◆ BOT_CMD_KEY_ATTACK1

const int BOT_CMD_KEY_ATTACK1 = BIT(5)

Definition at line 833 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), and bot_presskeys().

◆ BOT_CMD_KEY_ATTACK2

const int BOT_CMD_KEY_ATTACK2 = BIT(6)

Definition at line 834 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), and bot_presskeys().

◆ BOT_CMD_KEY_BACKWARD

const int BOT_CMD_KEY_BACKWARD = BIT(1)

Definition at line 829 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), and bot_presskeys().

◆ BOT_CMD_KEY_CHAT

const int BOT_CMD_KEY_CHAT = BIT(10)

Definition at line 838 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), and bot_presskeys().

◆ BOT_CMD_KEY_CROUCH

const int BOT_CMD_KEY_CROUCH = BIT(9)

Definition at line 837 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), and bot_presskeys().

◆ BOT_CMD_KEY_FORWARD

const int BOT_CMD_KEY_FORWARD = BIT(0)

Definition at line 828 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), and bot_presskeys().

◆ BOT_CMD_KEY_HOOK

const int BOT_CMD_KEY_HOOK = BIT(8)

Definition at line 836 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), and bot_presskeys().

◆ BOT_CMD_KEY_JUMP

const int BOT_CMD_KEY_JUMP = BIT(4)

Definition at line 832 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), and bot_presskeys().

◆ BOT_CMD_KEY_LEFT

const int BOT_CMD_KEY_LEFT = BIT(3)

Definition at line 831 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), and bot_presskeys().

◆ BOT_CMD_KEY_NONE

const int BOT_CMD_KEY_NONE = 0

Definition at line 827 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), bot_cmd_pause(), and bot_presskeys().

◆ BOT_CMD_KEY_RIGHT

const int BOT_CMD_KEY_RIGHT = BIT(2)

Definition at line 830 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), and bot_presskeys().

◆ BOT_CMD_KEY_USE

const int BOT_CMD_KEY_USE = BIT(7)

Definition at line 835 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), and bot_presskeys().

◆ bot_cmd_keys

int bot_cmd_keys

Definition at line 825 of file scripting.qc.

Referenced by bot_cmd_keypress_handler(), bot_cmd_pause(), and bot_presskeys().

◆ bot_cmd_wait_time

float bot_cmd_wait_time

Definition at line 501 of file scripting.qc.

Referenced by bot_cmd_wait().

◆ bot_cmdqueuebuf

float bot_cmdqueuebuf

Definition at line 17 of file scripting.qc.

◆ bot_cmdqueuebuf_allocated

float bot_cmdqueuebuf_allocated

Definition at line 16 of file scripting.qc.

Referenced by bot_havecommand().

◆ bot_cmdqueuebuf_end

float bot_cmdqueuebuf_end

Definition at line 19 of file scripting.qc.

Referenced by bot_havecommand().

◆ bot_cmdqueuebuf_start

float bot_cmdqueuebuf_start

Definition at line 18 of file scripting.qc.

Referenced by bot_havecommand().

◆ bot_exec_status

◆ bot_placenames

string bot_placenames[MAX_BOT_PLACES]

Definition at line 112 of file scripting.qc.

Referenced by bot_getplace().

◆ bot_places

entity bot_places[MAX_BOT_PLACES]

Definition at line 111 of file scripting.qc.

Referenced by bot_getplace().

◆ bot_places_count

float bot_places_count

Definition at line 110 of file scripting.qc.

Referenced by bot_getplace().

◆ CMD_CONDITION_false

const int CMD_CONDITION_false = 2

Definition at line 605 of file scripting.qc.

Referenced by bot_cmd_if(), and bot_execute_commands_once().

◆ CMD_CONDITION_false_BLOCK

const int CMD_CONDITION_false_BLOCK = 8

Definition at line 607 of file scripting.qc.

Referenced by bot_cmd_else(), and bot_execute_commands_once().

◆ CMD_CONDITION_NONE

const int CMD_CONDITION_NONE = 0

Definition at line 603 of file scripting.qc.

Referenced by bot_cmd_fi(), and bot_cmd_if().

◆ CMD_CONDITION_true

const int CMD_CONDITION_true = 1

Definition at line 604 of file scripting.qc.

Referenced by bot_cmd_if(), and bot_execute_commands_once().

◆ CMD_CONDITION_true_BLOCK

const int CMD_CONDITION_true_BLOCK = 4

Definition at line 606 of file scripting.qc.

Referenced by bot_cmd_else(), bot_cmd_if(), and bot_execute_commands_once().

◆ MAX_BOT_PLACES

const int MAX_BOT_PLACES = 4

Definition at line 109 of file scripting.qc.

Referenced by bot_getplace().

◆ state

int state

Definition at line 14 of file scripting.qc.

Referenced by bot_cmd_debug_assert_canfire().

◆ tuba_note

entity tuba_note

Definition at line 1074 of file scripting.qc.

Referenced by bot_cmd_debug_assert_canfire().