selfdamage = selfdamage + d;
else if(targ.team == self.team && teamplay)
teamdamage = teamdamage + d;
- else if(bot_shouldattack(targ))
+ else if(bot_shouldattack(self, targ))
enemydamage = enemydamage + d;
targ = targ.chain;
}
selfdamage = selfdamage + d;
else if(targ.team == self.team && teamplay)
teamdamage = teamdamage + d;
- else if(bot_shouldattack(targ))
+ else if(bot_shouldattack(self, targ))
enemydamage = enemydamage + d;
targ = targ.chain;
}
return false;
}
-void lag_update()
-{SELFPARAM();
- if (self.lag1_time) if (time > self.lag1_time) {self.lag_func(self.lag1_time, self.lag1_float1, self.lag1_float2, self.lag1_entity1, self.lag1_vec1, self.lag1_vec2, self.lag1_vec3, self.lag1_vec4);self.lag1_time = 0;}
- if (self.lag2_time) if (time > self.lag2_time) {self.lag_func(self.lag2_time, self.lag2_float1, self.lag2_float2, self.lag2_entity1, self.lag2_vec1, self.lag2_vec2, self.lag2_vec3, self.lag2_vec4);self.lag2_time = 0;}
- if (self.lag3_time) if (time > self.lag3_time) {self.lag_func(self.lag3_time, self.lag3_float1, self.lag3_float2, self.lag3_entity1, self.lag3_vec1, self.lag3_vec2, self.lag3_vec3, self.lag3_vec4);self.lag3_time = 0;}
- if (self.lag4_time) if (time > self.lag4_time) {self.lag_func(self.lag4_time, self.lag4_float1, self.lag4_float2, self.lag4_entity1, self.lag4_vec1, self.lag4_vec2, self.lag4_vec3, self.lag4_vec4);self.lag4_time = 0;}
- if (self.lag5_time) if (time > self.lag5_time) {self.lag_func(self.lag5_time, self.lag5_float1, self.lag5_float2, self.lag5_entity1, self.lag5_vec1, self.lag5_vec2, self.lag5_vec3, self.lag5_vec4);self.lag5_time = 0;}
+void lag_update(entity this)
+{
+ if (this.lag1_time) if (time > this.lag1_time) {this.lag_func(this, this.lag1_time, this.lag1_float1, this.lag1_float2, this.lag1_entity1, this.lag1_vec1, this.lag1_vec2, this.lag1_vec3, this.lag1_vec4);this.lag1_time = 0;}
+ if (this.lag2_time) if (time > this.lag2_time) {this.lag_func(this, this.lag2_time, this.lag2_float1, this.lag2_float2, this.lag2_entity1, this.lag2_vec1, this.lag2_vec2, this.lag2_vec3, this.lag2_vec4);this.lag2_time = 0;}
+ if (this.lag3_time) if (time > this.lag3_time) {this.lag_func(this, this.lag3_time, this.lag3_float1, this.lag3_float2, this.lag3_entity1, this.lag3_vec1, this.lag3_vec2, this.lag3_vec3, this.lag3_vec4);this.lag3_time = 0;}
+ if (this.lag4_time) if (time > this.lag4_time) {this.lag_func(this, this.lag4_time, this.lag4_float1, this.lag4_float2, this.lag4_entity1, this.lag4_vec1, this.lag4_vec2, this.lag4_vec3, this.lag4_vec4);this.lag4_time = 0;}
+ if (this.lag5_time) if (time > this.lag5_time) {this.lag_func(this, this.lag5_time, this.lag5_float1, this.lag5_float2, this.lag5_entity1, this.lag5_vec1, this.lag5_vec2, this.lag5_vec3, this.lag5_vec4);this.lag5_time = 0;}
}
-float lag_additem(float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4)
-{SELFPARAM();
- if (self.lag1_time == 0) {self.lag1_time = t;self.lag1_float1 = f1;self.lag1_float2 = f2;self.lag1_entity1 = e1;self.lag1_vec1 = v1;self.lag1_vec2 = v2;self.lag1_vec3 = v3;self.lag1_vec4 = v4;return true;}
- if (self.lag2_time == 0) {self.lag2_time = t;self.lag2_float1 = f1;self.lag2_float2 = f2;self.lag2_entity1 = e1;self.lag2_vec1 = v1;self.lag2_vec2 = v2;self.lag2_vec3 = v3;self.lag2_vec4 = v4;return true;}
- if (self.lag3_time == 0) {self.lag3_time = t;self.lag3_float1 = f1;self.lag3_float2 = f2;self.lag3_entity1 = e1;self.lag3_vec1 = v1;self.lag3_vec2 = v2;self.lag3_vec3 = v3;self.lag3_vec4 = v4;return true;}
- if (self.lag4_time == 0) {self.lag4_time = t;self.lag4_float1 = f1;self.lag4_float2 = f2;self.lag4_entity1 = e1;self.lag4_vec1 = v1;self.lag4_vec2 = v2;self.lag4_vec3 = v3;self.lag4_vec4 = v4;return true;}
- if (self.lag5_time == 0) {self.lag5_time = t;self.lag5_float1 = f1;self.lag5_float2 = f2;self.lag5_entity1 = e1;self.lag5_vec1 = v1;self.lag5_vec2 = v2;self.lag5_vec3 = v3;self.lag5_vec4 = v4;return true;}
+float lag_additem(entity this, float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4)
+{
+ if (this.lag1_time == 0) {this.lag1_time = t;this.lag1_float1 = f1;this.lag1_float2 = f2;this.lag1_entity1 = e1;this.lag1_vec1 = v1;this.lag1_vec2 = v2;this.lag1_vec3 = v3;this.lag1_vec4 = v4;return true;}
+ if (this.lag2_time == 0) {this.lag2_time = t;this.lag2_float1 = f1;this.lag2_float2 = f2;this.lag2_entity1 = e1;this.lag2_vec1 = v1;this.lag2_vec2 = v2;this.lag2_vec3 = v3;this.lag2_vec4 = v4;return true;}
+ if (this.lag3_time == 0) {this.lag3_time = t;this.lag3_float1 = f1;this.lag3_float2 = f2;this.lag3_entity1 = e1;this.lag3_vec1 = v1;this.lag3_vec2 = v2;this.lag3_vec3 = v3;this.lag3_vec4 = v4;return true;}
+ if (this.lag4_time == 0) {this.lag4_time = t;this.lag4_float1 = f1;this.lag4_float2 = f2;this.lag4_entity1 = e1;this.lag4_vec1 = v1;this.lag4_vec2 = v2;this.lag4_vec3 = v3;this.lag4_vec4 = v4;return true;}
+ if (this.lag5_time == 0) {this.lag5_time = t;this.lag5_float1 = f1;this.lag5_float2 = f2;this.lag5_entity1 = e1;this.lag5_vec1 = v1;this.lag5_vec2 = v2;this.lag5_vec3 = v3;this.lag5_vec4 = v4;return true;}
// no room for it (what is the best thing to do here??)
return false;
}
-float bot_shouldattack(entity e)
-{SELFPARAM();
- if (e.team == self.team)
+bool bot_shouldattack(entity this, entity targ)
+{
+ if (targ.team == this.team)
{
- if (e == self)
+ if (targ == this)
return false;
if (teamplay)
- if (e.team != 0)
+ if (targ.team != 0)
return false;
}
- if(STAT(FROZEN, e))
+ if(STAT(FROZEN, targ))
return false;
if(teamplay)
{
- if(e.team==0)
+ if(targ.team==0)
return false;
}
else if(bot_ignore_bots)
- if(IS_BOT_CLIENT(e))
+ if(IS_BOT_CLIENT(targ))
return false;
- if (!e.takedamage)
+ if (!targ.takedamage)
return false;
- if (IS_DEAD(e))
+ if (IS_DEAD(targ))
return false;
- if (PHYS_INPUT_BUTTON_CHAT(e))
+ if (PHYS_INPUT_BUTTON_CHAT(targ))
return false;
- if(e.flags & FL_NOTARGET)
+ if(targ.flags & FL_NOTARGET)
return false;
- if(MUTATOR_CALLHOOK(BotShouldAttack, e))
+ if(MUTATOR_CALLHOOK(BotShouldAttack, this, targ))
return false;
return true;
}
-void bot_lagfunc(float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4)
-{SELFPARAM();
- if(self.flags & FL_INWATER)
+void bot_lagfunc(entity this, float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4)
+{
+ if(this.flags & FL_INWATER)
{
- self.bot_aimtarg = world;
+ this.bot_aimtarg = world;
return;
}
- self.bot_aimtarg = e1;
- self.bot_aimlatency = self.ping; // FIXME? Shouldn't this be in the lag item?
- self.bot_aimselforigin = v1;
- self.bot_aimselfvelocity = v2;
- self.bot_aimtargorigin = v3;
- self.bot_aimtargvelocity = v4;
+ this.bot_aimtarg = e1;
+ this.bot_aimlatency = this.ping; // FIXME? Shouldn't this be in the lag item?
+ this.bot_aimselforigin = v1;
+ this.bot_aimselfvelocity = v2;
+ this.bot_aimtargorigin = v3;
+ this.bot_aimtargvelocity = v4;
if(skill <= 0)
- self.bot_canfire = (random() < 0.8);
+ this.bot_canfire = (random() < 0.8);
else if(skill <= 1)
- self.bot_canfire = (random() < 0.9);
+ this.bot_canfire = (random() < 0.9);
else if(skill <= 2)
- self.bot_canfire = (random() < 0.95);
+ this.bot_canfire = (random() < 0.95);
else
- self.bot_canfire = 1;
+ this.bot_canfire = 1;
}
-float bot_aimdir(vector v, float maxfiredeviation)
-{SELFPARAM();
+float bot_aimdir(entity this, vector v, float maxfiredeviation)
+{
float dist, delta_t, blend;
vector desiredang, diffang;
- //dprint("aim ", self.netname, ": old:", vtos(self.v_angle));
+ //dprint("aim ", this.netname, ": old:", vtos(this.v_angle));
// make sure v_angle is sane first
- self.v_angle_y = self.v_angle.y - floor(self.v_angle.y / 360) * 360;
- self.v_angle_z = 0;
+ this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360;
+ this.v_angle_z = 0;
// get the desired angles to aim at
//dprint(" at:", vtos(v));
v = normalize(v);
- //te_lightning2(world, self.origin + self.view_ofs, self.origin + self.view_ofs + v * 200);
- if (time >= self.bot_badaimtime)
+ //te_lightning2(world, this.origin + this.view_ofs, this.origin + this.view_ofs + v * 200);
+ if (time >= this.bot_badaimtime)
{
- self.bot_badaimtime = max(self.bot_badaimtime + 0.3, time);
- self.bot_badaimoffset = randomvec() * bound(0, 5 - 0.5 * (skill+self.bot_offsetskill), 5) * autocvar_bot_ai_aimskill_offset;
+ this.bot_badaimtime = max(this.bot_badaimtime + 0.3, time);
+ this.bot_badaimoffset = randomvec() * bound(0, 5 - 0.5 * (skill+this.bot_offsetskill), 5) * autocvar_bot_ai_aimskill_offset;
}
- desiredang = vectoangles(v) + self.bot_badaimoffset;
+ desiredang = vectoangles(v) + this.bot_badaimoffset;
//dprint(" desired:", vtos(desiredang));
if (desiredang.x >= 180)
desiredang.x = desiredang.x - 360;
desiredang.x = bound(-90, 0 - desiredang.x, 90);
- desiredang.z = self.v_angle.z;
+ desiredang.z = this.v_angle.z;
//dprint(" / ", vtos(desiredang));
//// pain throws off aim
- //if (self.bot_painintensity)
+ //if (this.bot_painintensity)
//{
// // shake from pain
- // desiredang = desiredang + randomvec() * self.bot_painintensity * 0.2;
+ // desiredang = desiredang + randomvec() * this.bot_painintensity * 0.2;
//}
// calculate turn angles
- diffang = (desiredang - self.bot_olddesiredang);
+ diffang = (desiredang - this.bot_olddesiredang);
// wrap yaw turn
diffang.y = diffang.y - floor(diffang.y / 360) * 360;
if (diffang.y >= 180)
diffang.y = diffang.y - 360;
- self.bot_olddesiredang = desiredang;
+ this.bot_olddesiredang = desiredang;
//dprint(" diff:", vtos(diffang));
- delta_t = time-self.bot_prevaimtime;
- self.bot_prevaimtime = time;
+ delta_t = time-this.bot_prevaimtime;
+ this.bot_prevaimtime = time;
// Here we will try to anticipate the comming aiming direction
- self.bot_1st_order_aimfilter= self.bot_1st_order_aimfilter
- + (diffang * (1 / delta_t) - self.bot_1st_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_1st,1);
- self.bot_2nd_order_aimfilter= self.bot_2nd_order_aimfilter
- + (self.bot_1st_order_aimfilter - self.bot_2nd_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_2nd,1);
- self.bot_3th_order_aimfilter= self.bot_3th_order_aimfilter
- + (self.bot_2nd_order_aimfilter - self.bot_3th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_3th,1);
- self.bot_4th_order_aimfilter= self.bot_4th_order_aimfilter
- + (self.bot_3th_order_aimfilter - self.bot_4th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_4th,1);
- self.bot_5th_order_aimfilter= self.bot_5th_order_aimfilter
- + (self.bot_4th_order_aimfilter - self.bot_5th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_5th,1);
+ this.bot_1st_order_aimfilter= this.bot_1st_order_aimfilter
+ + (diffang * (1 / delta_t) - this.bot_1st_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_1st,1);
+ this.bot_2nd_order_aimfilter= this.bot_2nd_order_aimfilter
+ + (this.bot_1st_order_aimfilter - this.bot_2nd_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_2nd,1);
+ this.bot_3th_order_aimfilter= this.bot_3th_order_aimfilter
+ + (this.bot_2nd_order_aimfilter - this.bot_3th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_3th,1);
+ this.bot_4th_order_aimfilter= this.bot_4th_order_aimfilter
+ + (this.bot_3th_order_aimfilter - this.bot_4th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_4th,1);
+ this.bot_5th_order_aimfilter= this.bot_5th_order_aimfilter
+ + (this.bot_4th_order_aimfilter - this.bot_5th_order_aimfilter) * bound(0, autocvar_bot_ai_aimskill_order_filter_5th,1);
//blend = (bound(0,skill,10)*0.1)*pow(1-bound(0,skill,10)*0.05,2.5)*5.656854249; //Plot formule before changing !
- blend = bound(0,skill+self.bot_aimskill,10)*0.1;
+ blend = bound(0,skill+this.bot_aimskill,10)*0.1;
desiredang = desiredang + blend *
(
- self.bot_1st_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_1st
- + self.bot_2nd_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_2nd
- + self.bot_3th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_3th
- + self.bot_4th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_4th
- + self.bot_5th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_5th
+ this.bot_1st_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_1st
+ + this.bot_2nd_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_2nd
+ + this.bot_3th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_3th
+ + this.bot_4th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_4th
+ + this.bot_5th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_5th
);
// calculate turn angles
- diffang = desiredang - self.bot_mouseaim;
+ diffang = desiredang - this.bot_mouseaim;
// wrap yaw turn
diffang.y = diffang.y - floor(diffang.y / 360) * 360;
if (diffang.y >= 180)
diffang.y = diffang.y - 360;
//dprint(" diff:", vtos(diffang));
- if (time >= self.bot_aimthinktime)
+ if (time >= this.bot_aimthinktime)
{
- self.bot_aimthinktime = max(self.bot_aimthinktime + 0.5 - 0.05*(skill+self.bot_thinkskill), time);
- self.bot_mouseaim = self.bot_mouseaim + diffang * (1-random()*0.1*bound(1,10-(skill+self.bot_thinkskill),10));
+ this.bot_aimthinktime = max(this.bot_aimthinktime + 0.5 - 0.05*(skill+this.bot_thinkskill), time);
+ this.bot_mouseaim = this.bot_mouseaim + diffang * (1-random()*0.1*bound(1,10-(skill+this.bot_thinkskill),10));
}
- //self.v_angle = self.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1);
+ //this.v_angle = this.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1);
- diffang = self.bot_mouseaim - desiredang;
+ diffang = this.bot_mouseaim - desiredang;
// wrap yaw turn
diffang.y = diffang.y - floor(diffang.y / 360) * 360;
if (diffang.y >= 180)
desiredang = desiredang + diffang * bound(0,autocvar_bot_ai_aimskill_think,1);
// calculate turn angles
- diffang = desiredang - self.v_angle;
+ diffang = desiredang - this.v_angle;
// wrap yaw turn
diffang.y = diffang.y - floor(diffang.y / 360) * 360;
if (diffang.y >= 180)
fixedrate = autocvar_bot_ai_aimskill_fixedrate / bound(1,dist,1000);
blendrate = autocvar_bot_ai_aimskill_blendrate;
r = max(fixedrate, blendrate);
- //self.v_angle = self.v_angle + diffang * bound(frametime, r * frametime * (2+skill*skill*0.05-random()*0.05*(10-skill)), 1);
- self.v_angle = self.v_angle + diffang * bound(delta_t, r * delta_t * (2+pow(skill+self.bot_mouseskill,3)*0.005-random()), 1);
- self.v_angle = self.v_angle * bound(0,autocvar_bot_ai_aimskill_mouse,1) + desiredang * bound(0,(1-autocvar_bot_ai_aimskill_mouse),1);
- //self.v_angle = self.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1);
- //self.v_angle = self.v_angle + diffang * (1/ blendrate);
- self.v_angle_z = 0;
- self.v_angle_y = self.v_angle.y - floor(self.v_angle.y / 360) * 360;
- //dprint(" turn:", vtos(self.v_angle));
-
- makevectors(self.v_angle);
- shotorg = self.origin + self.view_ofs;
+ //this.v_angle = this.v_angle + diffang * bound(frametime, r * frametime * (2+skill*skill*0.05-random()*0.05*(10-skill)), 1);
+ this.v_angle = this.v_angle + diffang * bound(delta_t, r * delta_t * (2+pow(skill+this.bot_mouseskill,3)*0.005-random()), 1);
+ this.v_angle = this.v_angle * bound(0,autocvar_bot_ai_aimskill_mouse,1) + desiredang * bound(0,(1-autocvar_bot_ai_aimskill_mouse),1);
+ //this.v_angle = this.v_angle + diffang * bound(0, r * frametime * (skill * 0.5 + 2), 1);
+ //this.v_angle = this.v_angle + diffang * (1/ blendrate);
+ this.v_angle_z = 0;
+ this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360;
+ //dprint(" turn:", vtos(this.v_angle));
+
+ makevectors(this.v_angle);
+ shotorg = this.origin + this.view_ofs;
shotdir = v_forward;
//dprint(" dir:", vtos(v_forward));
//te_lightning2(world, shotorg, shotorg + shotdir * 100);
// calculate turn angles again
- //diffang = desiredang - self.v_angle;
+ //diffang = desiredang - this.v_angle;
//diffang_y = diffang_y - floor(diffang_y / 360) * 360;
//if (diffang_y >= 180)
// diffang_y = diffang_y - 360;
// note the maxfiredeviation is in degrees so this has to convert to radians first
//if ((normalize(v) * shotdir) >= cos(maxfiredeviation * (3.14159265358979323846 / 180)))
if ((normalize(v) * shotdir) >= cos(maxfiredeviation * (3.14159265358979323846 / 180)))
- if(vdist(trace_endpos-shotorg, <, 500 + 500 * bound(0, skill + self.bot_aggresskill, 10)) || random()*random()>bound(0,(skill+self.bot_aggresskill)*0.05,1))
- self.bot_firetimer = time + bound(0.1, 0.5-(skill+self.bot_aggresskill)*0.05, 0.5);
+ if(vdist(trace_endpos-shotorg, <, 500 + 500 * bound(0, skill + this.bot_aggresskill, 10)) || random()*random()>bound(0,(skill+this.bot_aggresskill)*0.05,1))
+ this.bot_firetimer = time + bound(0.1, 0.5-(skill+this.bot_aggresskill)*0.05, 0.5);
//traceline(shotorg,shotorg+shotdir*1000,false,world);
//dprint(ftos(maxfiredeviation),"\n");
//dprint(" diff:", vtos(diffang), "\n");
- return self.bot_canfire && (time < self.bot_firetimer);
+ return this.bot_canfire && (time < this.bot_firetimer);
}
vector bot_shotlead(vector targorigin, vector targvelocity, float shotspeed, float shotdelay)
return false;
}
- f = bot_aimdir(findtrajectory_velocity - shotspeedupward * '0 0 1', r);
+ f = bot_aimdir(self, findtrajectory_velocity - shotspeedupward * '0 0 1', r);
}
else
{
- f = bot_aimdir(v - shotorg, r);
+ f = bot_aimdir(self, v - shotorg, r);
//dprint("AIM: ");dprint(vtos(self.bot_aimtargorigin));dprint(" + ");dprint(vtos(self.bot_aimtargvelocity));dprint(" * ");dprint(ftos(self.bot_aimlatency + vlen(self.bot_aimtargorigin - shotorg) / shotspeed));dprint(" = ");dprint(vtos(v));dprint(" : aimdir = ");dprint(vtos(normalize(v - shotorg)));dprint(" : ");dprint(vtos(shotdir));dprint("\n");
//traceline(shotorg, shotorg + shotdir * 10000, false, self);
//if (trace_ent.takedamage)
//if (trace_fraction < 1)
- //if (!bot_shouldattack(trace_ent))
+ //if (!bot_shouldattack(self, trace_ent))
// return false;
traceline(shotorg, self.bot_aimtargorigin, false, self);
if (trace_fraction < 1)
if (trace_ent != self.enemy)
- if (!bot_shouldattack(trace_ent))
+ if (!bot_shouldattack(self, trace_ent))
{
self.dphitcontentsmask = hf;
return false;
* Functions
*/
-float lag_additem(float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4);
-void lag_update();
-void bot_lagfunc(float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4);
+float lag_additem(entity this, float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4);
+void lag_update(entity this);
+void bot_lagfunc(entity this, float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4);
-float bot_shouldattack(entity e);
-float bot_aimdir(vector v, float maxfiredeviation);
+float bot_shouldattack(entity this, entity targ);
+float bot_aimdir(entity this, vector v, float maxfiredeviation);
float bot_aim(float shotspeed, float shotspeedupward, float maxshottime, float applygravity);
float findtrajectorywithleading(vector org, vector m1, vector m2, entity targ, float shotspeed, float shotspeedupward, float maxtime, float shotdelay, entity ignore);
vector bot_shotlead(vector targorigin, vector targvelocity, float shotspeed, float shotdelay);
-.void(float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) lag_func;
+.void(entity this, float t, float f1, float f2, entity e1, vector v1, vector v2, vector v3, vector v4) lag_func;
navigation_unstuck();
// now call the current bot AI (havocbot for example)
- self.bot_ai();
+ self.bot_ai(self);
}
void bot_setnameandstuff()
void autoskill(float factor);
void bot_serverframe();
-.void() bot_ai;
+.void(entity this) bot_ai;
.float(entity player, entity item) bot_pickupevalfunc;
/*
.float speed;
-void havocbot_ai()
-{SELFPARAM();
- if(self.draggedby)
+void havocbot_ai(entity this)
+{
+ if(this.draggedby)
return;
- if(bot_execute_commands())
+ if(bot_execute_commands(this))
return;
- if (bot_strategytoken == self)
+ if (bot_strategytoken == this)
if (!bot_strategytoken_taken)
{
- if(self.havocbot_blockhead)
+ if(this.havocbot_blockhead)
{
- self.havocbot_blockhead = false;
+ this.havocbot_blockhead = false;
}
else
{
- if (!self.jumppadcount)
- self.havocbot_role();
+ if (!this.jumppadcount)
+ WITH(entity, self, this, this.havocbot_role()); // little too far down the rabbit hole
}
// TODO: tracewalk() should take care of this job (better path finding under water)
// if we don't have a goal and we're under water look for a waypoint near the "shore" and push it
- if(IS_DEAD(self))
- if(self.goalcurrent==world)
- if(self.waterlevel==WATERLEVEL_SWIMMING || (self.aistatus & AI_STATUS_OUT_WATER))
+ if(IS_DEAD(this))
+ if(this.goalcurrent==world)
+ if(this.waterlevel==WATERLEVEL_SWIMMING || (this.aistatus & AI_STATUS_OUT_WATER))
{
// Look for the closest waypoint out of water
entity newgoal, head;
bestdistance = 10000;
for (head = findchain(classname, "waypoint"); head; head = head.chain)
{
- distance = vlen(head.origin - self.origin);
+ distance = vlen(head.origin - this.origin);
if(distance>10000)
continue;
- if(head.origin.z < self.origin.z)
+ if(head.origin.z < this.origin.z)
continue;
- if(head.origin.z - self.origin.z - self.view_ofs.z > 100)
+ if(head.origin.z - this.origin.z - this.view_ofs.z > 100)
continue;
if (pointcontents(head.origin + head.maxs + '0 0 1') != CONTENT_EMPTY)
continue;
- traceline(self.origin + self.view_ofs , head.origin, true, head);
+ traceline(this.origin + this.view_ofs , head.origin, true, head);
if(trace_fraction<1)
continue;
if(newgoal)
{
// te_wizspike(newgoal.origin);
- navigation_pushroute(newgoal);
+ navigation_pushroute(this, newgoal);
}
}
bot_strategytoken_taken = true;
}
- if(IS_DEAD(self))
+ if(IS_DEAD(this))
return;
- havocbot_chooseenemy();
- if (self.bot_chooseweapontime < time )
+ havocbot_chooseenemy(this);
+ if (this.bot_chooseweapontime < time )
{
- self.bot_chooseweapontime = time + autocvar_bot_ai_chooseweaponinterval;
- havocbot_chooseweapon();
+ this.bot_chooseweapontime = time + autocvar_bot_ai_chooseweaponinterval;
+ havocbot_chooseweapon(this);
}
- havocbot_aim();
- lag_update();
- if (self.bot_aimtarg)
+ havocbot_aim(this);
+ lag_update(this);
+ if (this.bot_aimtarg)
{
- self.aistatus |= AI_STATUS_ATTACKING;
- self.aistatus &= ~AI_STATUS_ROAMING;
+ this.aistatus |= AI_STATUS_ATTACKING;
+ this.aistatus &= ~AI_STATUS_ROAMING;
- if(self.weapons)
+ if(this.weapons)
{
- Weapon w = PS(self).m_weapon;
+ Weapon w = PS(this).m_weapon;
w.wr_aim(w);
- if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(self))
+ if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(this))
{
- PHYS_INPUT_BUTTON_ATCK(self) = false;
- PHYS_INPUT_BUTTON_ATCK2(self) = false;
+ PHYS_INPUT_BUTTON_ATCK(this) = false;
+ PHYS_INPUT_BUTTON_ATCK2(this) = false;
}
else
{
- if(PHYS_INPUT_BUTTON_ATCK(self) || PHYS_INPUT_BUTTON_ATCK2(self))
- self.lastfiredweapon = PS(self).m_weapon.m_id;
+ if(PHYS_INPUT_BUTTON_ATCK(this) || PHYS_INPUT_BUTTON_ATCK2(this))
+ this.lastfiredweapon = PS(this).m_weapon.m_id;
}
}
else
{
- if(IS_PLAYER(self.bot_aimtarg))
- bot_aimdir(self.bot_aimtarg.origin + self.bot_aimtarg.view_ofs - self.origin - self.view_ofs , -1);
+ if(IS_PLAYER(this.bot_aimtarg))
+ bot_aimdir(this, this.bot_aimtarg.origin + this.bot_aimtarg.view_ofs - this.origin - this.view_ofs , -1);
}
}
- else if (self.goalcurrent)
+ else if (this.goalcurrent)
{
- self.aistatus |= AI_STATUS_ROAMING;
- self.aistatus &= ~AI_STATUS_ATTACKING;
+ this.aistatus |= AI_STATUS_ROAMING;
+ this.aistatus &= ~AI_STATUS_ATTACKING;
vector now,v,next;//,heading;
float aimdistance,skillblend,distanceblend,blend;
- next = now = ( (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5) - (self.origin + self.view_ofs);
+ next = now = ( (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5) - (this.origin + this.view_ofs);
aimdistance = vlen(now);
- //heading = self.velocity;
- //dprint(self.goalstack01.classname,etos(self.goalstack01),"\n");
+ //heading = this.velocity;
+ //dprint(this.goalstack01.classname,etos(this.goalstack01),"\n");
if(
- self.goalstack01 != self && self.goalstack01 != world && ((self.aistatus & AI_STATUS_RUNNING) == 0) &&
- !(self.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
+ this.goalstack01 != this && this.goalstack01 != world && ((this.aistatus & AI_STATUS_RUNNING) == 0) &&
+ !(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
)
- next = ((self.goalstack01.absmin + self.goalstack01.absmax) * 0.5) - (self.origin + self.view_ofs);
+ next = ((this.goalstack01.absmin + this.goalstack01.absmax) * 0.5) - (this.origin + this.view_ofs);
- skillblend=bound(0,(skill+self.bot_moveskill-2.5)*0.5,1); //lower skill player can't preturn
+ skillblend=bound(0,(skill+this.bot_moveskill-2.5)*0.5,1); //lower skill player can't preturn
distanceblend=bound(0,aimdistance/autocvar_bot_ai_keyboard_distance,1);
blend = skillblend * (1-distanceblend);
//v = (now * (distanceblend) + next * (1-distanceblend)) * (skillblend) + now * (1-skillblend);
//v = now * (distanceblend) * (skillblend) + next * (1-distanceblend) * (skillblend) + now * (1-skillblend);
//v = now * ((1-skillblend) + (distanceblend) * (skillblend)) + next * (1-distanceblend) * (skillblend);
v = now + blend * (next - now);
- //dprint(etos(self), " ");
+ //dprint(etos(this), " ");
//dprint(vtos(now), ":", vtos(next), "=", vtos(v), " (blend ", ftos(blend), ")\n");
//v = now * (distanceblend) + next * (1-distanceblend);
- if (self.waterlevel < WATERLEVEL_SWIMMING)
+ if (this.waterlevel < WATERLEVEL_SWIMMING)
v.z = 0;
//dprint("walk at:", vtos(v), "\n");
- //te_lightning2(world, self.origin, self.goalcurrent.origin);
- bot_aimdir(v, -1);
+ //te_lightning2(world, this.origin, this.goalcurrent.origin);
+ bot_aimdir(this, v, -1);
}
- havocbot_movetogoal();
+ havocbot_movetogoal(this);
// if the bot is not attacking, consider reloading weapons
- if (!(self.aistatus & AI_STATUS_ATTACKING))
+ if (!(this.aistatus & AI_STATUS_ATTACKING))
{
// we are currently holding a weapon that's not fully loaded, reload it
if(skill >= 2) // bots can only reload the held weapon on purpose past this skill
- if(self.clip_load < self.clip_size)
- self.impulse = 20; // "press" the reload button, not sure if this is done right
+ if(this.clip_load < this.clip_size)
+ this.impulse = 20; // "press" the reload button, not sure if this is done right
// if we're not reloading a weapon, switch to any weapon in our invnetory that's not fully loaded to reload it next
// the code above executes next frame, starting the reloading then
if(skill >= 5) // bots can only look for unloaded weapons past this skill
- if(self.clip_load >= 0) // only if we're not reloading a weapon already
+ if(this.clip_load >= 0) // only if we're not reloading a weapon already
{
FOREACH(Weapons, it != WEP_Null, LAMBDA(
- if((self.weapons & (it.m_wepset)) && (it.spawnflags & WEP_FLAG_RELOADABLE) && (self.weapon_load[it.m_id] < it.reloading_ammo))
- PS(self).m_switchweapon = it;
+ if((this.weapons & (it.m_wepset)) && (it.spawnflags & WEP_FLAG_RELOADABLE) && (this.weapon_load[it.m_id] < it.reloading_ammo))
+ PS(this).m_switchweapon = it;
));
}
}
}
-void havocbot_keyboard_movement(vector destorg)
-{SELFPARAM();
+void havocbot_keyboard_movement(entity this, vector destorg)
+{
vector keyboard;
float blend, maxspeed;
float sk;
- sk = skill + self.bot_moveskill;
+ sk = skill + this.bot_moveskill;
maxspeed = autocvar_sv_maxspeed;
- if (time < self.havocbot_keyboardtime)
+ if (time < this.havocbot_keyboardtime)
return;
- self.havocbot_keyboardtime =
+ this.havocbot_keyboardtime =
max(
- self.havocbot_keyboardtime
- + 0.05/max(1, sk+self.havocbot_keyboardskill)
- + random()*0.025/max(0.00025, skill+self.havocbot_keyboardskill)
+ this.havocbot_keyboardtime
+ + 0.05/max(1, sk+this.havocbot_keyboardskill)
+ + random()*0.025/max(0.00025, skill+this.havocbot_keyboardskill)
, time);
- keyboard = self.movement * (1.0 / maxspeed);
+ keyboard = this.movement * (1.0 / maxspeed);
float trigger, trigger1;
blend = bound(0,sk*0.1,1);
else
keyboard.z = 0;
- self.havocbot_keyboard = keyboard * maxspeed;
- if (self.havocbot_ducktime>time) PHYS_INPUT_BUTTON_CROUCH(self) = true;
+ this.havocbot_keyboard = keyboard * maxspeed;
+ if (this.havocbot_ducktime>time) PHYS_INPUT_BUTTON_CROUCH(this) = true;
- keyboard = self.havocbot_keyboard;
- blend = bound(0,vlen(destorg-self.origin)/autocvar_bot_ai_keyboard_distance,1); // When getting close move with 360 degree
- //dprint("movement ", vtos(self.movement), " keyboard ", vtos(keyboard), " blend ", ftos(blend), "\n");
- self.movement = self.movement + (keyboard - self.movement) * blend;
+ keyboard = this.havocbot_keyboard;
+ blend = bound(0,vlen(destorg-this.origin)/autocvar_bot_ai_keyboard_distance,1); // When getting close move with 360 degree
+ //dprint("movement ", vtos(this.movement), " keyboard ", vtos(keyboard), " blend ", ftos(blend), "\n");
+ this.movement = this.movement + (keyboard - this.movement) * blend;
}
-void havocbot_bunnyhop(vector dir)
-{SELFPARAM();
+void havocbot_bunnyhop(entity this, vector dir)
+{
float bunnyhopdistance;
vector deviation;
float maxspeed;
vector gco, gno;
// Don't jump when attacking
- if(self.aistatus & AI_STATUS_ATTACKING)
+ if(this.aistatus & AI_STATUS_ATTACKING)
return;
- if(IS_PLAYER(self.goalcurrent))
+ if(IS_PLAYER(this.goalcurrent))
return;
maxspeed = autocvar_sv_maxspeed;
- if(self.aistatus & AI_STATUS_DANGER_AHEAD)
+ if(this.aistatus & AI_STATUS_DANGER_AHEAD)
{
- self.aistatus &= ~AI_STATUS_RUNNING;
- PHYS_INPUT_BUTTON_JUMP(self) = false;
- self.bot_canruntogoal = 0;
- self.bot_timelastseengoal = 0;
+ this.aistatus &= ~AI_STATUS_RUNNING;
+ PHYS_INPUT_BUTTON_JUMP(this) = false;
+ this.bot_canruntogoal = 0;
+ this.bot_timelastseengoal = 0;
return;
}
- if(self.waterlevel > WATERLEVEL_WETFEET)
+ if(this.waterlevel > WATERLEVEL_WETFEET)
{
- self.aistatus &= ~AI_STATUS_RUNNING;
+ this.aistatus &= ~AI_STATUS_RUNNING;
return;
}
- if(self.bot_lastseengoal != self.goalcurrent && !(self.aistatus & AI_STATUS_RUNNING))
+ if(this.bot_lastseengoal != this.goalcurrent && !(this.aistatus & AI_STATUS_RUNNING))
{
- self.bot_canruntogoal = 0;
- self.bot_timelastseengoal = 0;
+ this.bot_canruntogoal = 0;
+ this.bot_timelastseengoal = 0;
}
- gco = (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5;
- bunnyhopdistance = vlen(self.origin - gco);
+ gco = (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5;
+ bunnyhopdistance = vlen(this.origin - gco);
// Run only to visible goals
- if(IS_ONGROUND(self))
- if(self.speed==maxspeed)
- if(checkpvs(self.origin + self.view_ofs, self.goalcurrent))
+ if(IS_ONGROUND(this))
+ if(this.speed==maxspeed)
+ if(checkpvs(this.origin + this.view_ofs, this.goalcurrent))
{
- self.bot_lastseengoal = self.goalcurrent;
+ this.bot_lastseengoal = this.goalcurrent;
// seen it before
- if(self.bot_timelastseengoal)
+ if(this.bot_timelastseengoal)
{
// for a period of time
- if(time - self.bot_timelastseengoal > autocvar_bot_ai_bunnyhop_firstjumpdelay)
+ if(time - this.bot_timelastseengoal > autocvar_bot_ai_bunnyhop_firstjumpdelay)
{
float checkdistance;
checkdistance = true;
// don't run if it is too close
- if(self.bot_canruntogoal==0)
+ if(this.bot_canruntogoal==0)
{
if(bunnyhopdistance > autocvar_bot_ai_bunnyhop_startdistance)
- self.bot_canruntogoal = 1;
+ this.bot_canruntogoal = 1;
else
- self.bot_canruntogoal = -1;
+ this.bot_canruntogoal = -1;
}
- if(self.bot_canruntogoal != 1)
+ if(this.bot_canruntogoal != 1)
return;
- if(self.aistatus & AI_STATUS_ROAMING)
- if(self.goalcurrent.classname=="waypoint")
- if (!(self.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL))
- if(fabs(gco.z - self.origin.z) < self.maxs.z - self.mins.z)
- if(self.goalstack01!=world)
+ if(this.aistatus & AI_STATUS_ROAMING)
+ if(this.goalcurrent.classname=="waypoint")
+ if (!(this.goalcurrent.wpflags & WAYPOINTFLAG_PERSONAL))
+ if(fabs(gco.z - this.origin.z) < this.maxs.z - this.mins.z)
+ if(this.goalstack01!=world)
{
- gno = (self.goalstack01.absmin + self.goalstack01.absmax) * 0.5;
- deviation = vectoangles(gno - self.origin) - vectoangles(gco - self.origin);
+ gno = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
+ deviation = vectoangles(gno - this.origin) - vectoangles(gco - this.origin);
while (deviation.y < -180) deviation.y = deviation.y + 360;
while (deviation.y > 180) deviation.y = deviation.y - 360;
if(fabs(deviation.y) < 20)
- if(bunnyhopdistance < vlen(self.origin - gno))
- if(fabs(gno.z - gco.z) < self.maxs.z - self.mins.z)
+ if(bunnyhopdistance < vlen(this.origin - gno))
+ if(fabs(gno.z - gco.z) < this.maxs.z - this.mins.z)
{
- if(vlen(gco - gno) > autocvar_bot_ai_bunnyhop_startdistance)
- if(checkpvs(self.origin + self.view_ofs, self.goalstack01))
+ if(vdist(gco - gno, >, autocvar_bot_ai_bunnyhop_startdistance))
+ if(checkpvs(this.origin + this.view_ofs, this.goalstack01))
{
checkdistance = false;
}
if(checkdistance)
{
- self.aistatus &= ~AI_STATUS_RUNNING;
+ this.aistatus &= ~AI_STATUS_RUNNING;
if(bunnyhopdistance > autocvar_bot_ai_bunnyhop_stopdistance)
- PHYS_INPUT_BUTTON_JUMP(self) = true;
+ PHYS_INPUT_BUTTON_JUMP(this) = true;
}
else
{
- self.aistatus |= AI_STATUS_RUNNING;
- PHYS_INPUT_BUTTON_JUMP(self) = true;
+ this.aistatus |= AI_STATUS_RUNNING;
+ PHYS_INPUT_BUTTON_JUMP(this) = true;
}
}
}
else
{
- self.bot_timelastseengoal = time;
+ this.bot_timelastseengoal = time;
}
}
else
{
- self.bot_timelastseengoal = 0;
+ this.bot_timelastseengoal = 0;
}
#if 0
// Release jump button
if(!cvar("sv_pogostick"))
- if((IS_ONGROUND(self)) == 0)
+ if((IS_ONGROUND(this)) == 0)
{
- if(self.velocity.z < 0 || vlen(self.velocity)<maxspeed)
- PHYS_INPUT_BUTTON_JUMP(self) = false;
+ if(this.velocity.z < 0 || vlen(this.velocity)<maxspeed)
+ PHYS_INPUT_BUTTON_JUMP(this) = false;
// Strafe
- if(self.aistatus & AI_STATUS_RUNNING)
- if(vlen(self.velocity)>maxspeed)
+ if(this.aistatus & AI_STATUS_RUNNING)
+ if(vlen(this.velocity)>maxspeed)
{
- deviation = vectoangles(dir) - vectoangles(self.velocity);
+ deviation = vectoangles(dir) - vectoangles(this.velocity);
while (deviation.y < -180) deviation.y = deviation.y + 360;
while (deviation.y > 180) deviation.y = deviation.y - 360;
if(fabs(deviation.y)>10)
- self.movement_x = 0;
+ this.movement_x = 0;
if(deviation.y>10)
- self.movement_y = maxspeed * -1;
+ this.movement_y = maxspeed * -1;
else if(deviation.y<10)
- self.movement_y = maxspeed;
+ this.movement_y = maxspeed;
}
}
#endif
}
-void havocbot_movetogoal()
-{SELFPARAM();
+void havocbot_movetogoal(entity this)
+{
vector destorg;
vector diff;
vector dir;
vector gco;
//float dist;
vector dodge;
- //if (self.goalentity)
- // te_lightning2(self, self.origin, (self.goalentity.absmin + self.goalentity.absmax) * 0.5);
- self.movement = '0 0 0';
+ //if (this.goalentity)
+ // te_lightning2(this, this.origin, (this.goalentity.absmin + this.goalentity.absmax) * 0.5);
+ this.movement = '0 0 0';
maxspeed = autocvar_sv_maxspeed;
// Jetpack navigation
- if(self.goalcurrent)
- if(self.navigation_jetpack_goal)
- if(self.goalcurrent==self.navigation_jetpack_goal)
- if(self.ammo_fuel)
+ if(this.goalcurrent)
+ if(this.navigation_jetpack_goal)
+ if(this.goalcurrent==this.navigation_jetpack_goal)
+ if(this.ammo_fuel)
{
if(autocvar_bot_debug_goalstack)
{
- debuggoalstack();
- te_wizspike(self.navigation_jetpack_point);
+ debuggoalstack(this);
+ te_wizspike(this.navigation_jetpack_point);
}
// Take off
- if (!(self.aistatus & AI_STATUS_JETPACK_FLYING))
+ if (!(this.aistatus & AI_STATUS_JETPACK_FLYING))
{
// Brake almost completely so it can get a good direction
- if(vlen(self.velocity)>10)
+ if(vdist(this.velocity, >, 10))
return;
- self.aistatus |= AI_STATUS_JETPACK_FLYING;
+ this.aistatus |= AI_STATUS_JETPACK_FLYING;
}
- makevectors(self.v_angle.y * '0 1 0');
- dir = normalize(self.navigation_jetpack_point - self.origin);
+ makevectors(this.v_angle.y * '0 1 0');
+ dir = normalize(this.navigation_jetpack_point - this.origin);
// Landing
- if(self.aistatus & AI_STATUS_JETPACK_LANDING)
+ if(this.aistatus & AI_STATUS_JETPACK_LANDING)
{
// Calculate brake distance in xy
float db, v, d;
vector dxy;
- dxy = self.origin - ( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ); dxy.z = 0;
+ dxy = this.origin - ( ( this.goalcurrent.absmin + this.goalcurrent.absmax ) * 0.5 ); dxy.z = 0;
d = vlen(dxy);
- v = vlen(self.velocity - self.velocity.z * '0 0 1');
+ v = vlen(this.velocity - this.velocity.z * '0 0 1');
db = (pow(v,2) / (autocvar_g_jetpack_acceleration_side * 2)) + 100;
// dprint("distance ", ftos(ceil(d)), " velocity ", ftos(ceil(v)), " brake at ", ftos(ceil(db)), "\n");
if(d < db || d < 500)
{
// Brake
- if(fabs(self.velocity.x)>maxspeed*0.3)
+ if(fabs(this.velocity.x)>maxspeed*0.3)
{
- self.movement_x = dir * v_forward * -maxspeed;
+ this.movement_x = dir * v_forward * -maxspeed;
return;
}
// Switch to normal mode
- self.navigation_jetpack_goal = world;
- self.aistatus &= ~AI_STATUS_JETPACK_LANDING;
- self.aistatus &= ~AI_STATUS_JETPACK_FLYING;
+ this.navigation_jetpack_goal = world;
+ this.aistatus &= ~AI_STATUS_JETPACK_LANDING;
+ this.aistatus &= ~AI_STATUS_JETPACK_FLYING;
return;
}
}
- else if(checkpvs(self.origin,self.goalcurrent))
+ else if(checkpvs(this.origin,this.goalcurrent))
{
// If I can see the goal switch to landing code
- self.aistatus &= ~AI_STATUS_JETPACK_FLYING;
- self.aistatus |= AI_STATUS_JETPACK_LANDING;
+ this.aistatus &= ~AI_STATUS_JETPACK_FLYING;
+ this.aistatus |= AI_STATUS_JETPACK_LANDING;
return;
}
// Flying
- PHYS_INPUT_BUTTON_HOOK(self) = true;
- if(self.navigation_jetpack_point.z - STAT(PL_MAX, NULL).z + STAT(PL_MIN, NULL).z < self.origin.z)
+ PHYS_INPUT_BUTTON_HOOK(this) = true;
+ if(this.navigation_jetpack_point.z - STAT(PL_MAX, NULL).z + STAT(PL_MIN, NULL).z < this.origin.z)
{
- self.movement_x = dir * v_forward * maxspeed;
- self.movement_y = dir * v_right * maxspeed;
+ this.movement_x = dir * v_forward * maxspeed;
+ this.movement_y = dir * v_right * maxspeed;
}
return;
}
// Handling of jump pads
- if(self.jumppadcount)
+ if(this.jumppadcount)
{
// If got stuck on the jump pad try to reach the farthest visible waypoint
- if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
+ if(this.aistatus & AI_STATUS_OUT_JUMPPAD)
{
- if(fabs(self.velocity.z)<50)
+ if(fabs(this.velocity.z)<50)
{
entity head, newgoal = world;
float distance, bestdistance = 0;
for (head = findchain(classname, "waypoint"); head; head = head.chain)
{
- distance = vlen(head.origin - self.origin);
+ distance = vlen(head.origin - this.origin);
if(distance>1000)
continue;
- traceline(self.origin + self.view_ofs , ( ( head.absmin + head.absmax ) * 0.5 ), true, world);
+ traceline(this.origin + this.view_ofs , ( ( head.absmin + head.absmax ) * 0.5 ), true, world);
if(trace_fraction<1)
continue;
if(newgoal)
{
- self.ignoregoal = self.goalcurrent;
- self.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
- navigation_clearroute();
- navigation_routetogoal(newgoal, self.origin);
- self.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
+ this.ignoregoal = this.goalcurrent;
+ this.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
+ navigation_clearroute(this);
+ navigation_routetogoal(this, newgoal, this.origin);
+ this.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
}
}
else
}
else
{
- if(self.velocity.z>0)
+ if(this.velocity.z>0)
{
- float threshold, sxy;
- vector velxy = self.velocity; velxy_z = 0;
- sxy = vlen(velxy);
+ float threshold;
+ vector velxy = this.velocity; velxy_z = 0;
threshold = maxspeed * 0.2;
- if(sxy < threshold)
+ if(vdist(velxy, <, threshold))
{
- LOG_TRACE("Warning: ", self.netname, " got stuck on a jumppad (velocity in xy is ", ftos(sxy), "), trying to get out of it now\n");
- self.aistatus |= AI_STATUS_OUT_JUMPPAD;
+ LOG_TRACE("Warning: ", this.netname, " got stuck on a jumppad (velocity in xy is ", vtos(velxy), "), trying to get out of it now\n");
+ this.aistatus |= AI_STATUS_OUT_JUMPPAD;
}
return;
}
// Don't chase players while using a jump pad
- if(IS_PLAYER(self.goalcurrent) || IS_PLAYER(self.goalstack01))
+ if(IS_PLAYER(this.goalcurrent) || IS_PLAYER(this.goalstack01))
return;
}
}
- else if(self.aistatus & AI_STATUS_OUT_JUMPPAD)
- self.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
+ else if(this.aistatus & AI_STATUS_OUT_JUMPPAD)
+ this.aistatus &= ~AI_STATUS_OUT_JUMPPAD;
// If there is a trigger_hurt right below try to use the jetpack or make a rocketjump
if(skill>6)
- if (!(IS_ONGROUND(self)))
+ if (!(IS_ONGROUND(this)))
{
- tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 -65536', MOVE_NOMONSTERS, self);
- if(tracebox_hits_trigger_hurt(self.origin, self.mins, self.maxs, trace_endpos ))
- if(self.items & IT_JETPACK)
+ tracebox(this.origin, this.mins, this.maxs, this.origin + '0 0 -65536', MOVE_NOMONSTERS, this);
+ if(tracebox_hits_trigger_hurt(this.origin, this.mins, this.maxs, trace_endpos ))
+ if(this.items & IT_JETPACK)
{
- tracebox(self.origin, self.mins, self.maxs, self.origin + '0 0 65536', MOVE_NOMONSTERS, self);
- if(tracebox_hits_trigger_hurt(self.origin, self.mins, self.maxs, trace_endpos + '0 0 1' ))
+ tracebox(this.origin, this.mins, this.maxs, this.origin + '0 0 65536', MOVE_NOMONSTERS, this);
+ if(tracebox_hits_trigger_hurt(this.origin, this.mins, this.maxs, trace_endpos + '0 0 1' ))
{
- if(self.velocity.z<0)
+ if(this.velocity.z<0)
{
- PHYS_INPUT_BUTTON_HOOK(self) = true;
+ PHYS_INPUT_BUTTON_HOOK(this) = true;
}
}
else
- PHYS_INPUT_BUTTON_HOOK(self) = true;
+ PHYS_INPUT_BUTTON_HOOK(this) = true;
// If there is no goal try to move forward
- if(self.goalcurrent==world)
+ if(this.goalcurrent==world)
dir = v_forward;
else
- dir = normalize(( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ) - self.origin);
+ dir = normalize(( ( this.goalcurrent.absmin + this.goalcurrent.absmax ) * 0.5 ) - this.origin);
- vector xyvelocity = self.velocity; xyvelocity_z = 0;
+ vector xyvelocity = this.velocity; xyvelocity_z = 0;
float xyspeed = xyvelocity * dir;
if(xyspeed < (maxspeed / 2))
{
- makevectors(self.v_angle.y * '0 1 0');
- tracebox(self.origin, self.mins, self.maxs, self.origin + (dir * maxspeed * 3), MOVE_NOMONSTERS, self);
+ makevectors(this.v_angle.y * '0 1 0');
+ tracebox(this.origin, this.mins, this.maxs, this.origin + (dir * maxspeed * 3), MOVE_NOMONSTERS, this);
if(trace_fraction==1)
{
- self.movement_x = dir * v_forward * maxspeed;
- self.movement_y = dir * v_right * maxspeed;
+ this.movement_x = dir * v_forward * maxspeed;
+ this.movement_y = dir * v_right * maxspeed;
if (skill < 10)
- havocbot_keyboard_movement(self.origin + dir * 100);
+ havocbot_keyboard_movement(this, this.origin + dir * 100);
}
}
- self.havocbot_blockhead = true;
+ this.havocbot_blockhead = true;
return;
}
- else if(self.health>WEP_CVAR(devastator, damage)*0.5)
+ else if(this.health>WEP_CVAR(devastator, damage)*0.5)
{
- if(self.velocity.z < 0)
- if(client_hasweapon(self, WEP_DEVASTATOR, true, false))
+ if(this.velocity.z < 0)
+ if(client_hasweapon(this, WEP_DEVASTATOR, true, false))
{
- self.movement_x = maxspeed;
+ this.movement_x = maxspeed;
- if(self.rocketjumptime)
+ if(this.rocketjumptime)
{
- if(time > self.rocketjumptime)
+ if(time > this.rocketjumptime)
{
- PHYS_INPUT_BUTTON_ATCK2(self) = true;
- self.rocketjumptime = 0;
+ PHYS_INPUT_BUTTON_ATCK2(this) = true;
+ this.rocketjumptime = 0;
}
return;
}
- PS(self).m_switchweapon = WEP_DEVASTATOR;
- self.v_angle_x = 90;
- PHYS_INPUT_BUTTON_ATCK(self) = true;
- self.rocketjumptime = time + WEP_CVAR(devastator, detonatedelay);
+ PS(this).m_switchweapon = WEP_DEVASTATOR;
+ this.v_angle_x = 90;
+ PHYS_INPUT_BUTTON_ATCK(this) = true;
+ this.rocketjumptime = time + WEP_CVAR(devastator, detonatedelay);
return;
}
}
else
{
// If there is no goal try to move forward
- if(self.goalcurrent==world)
- self.movement_x = maxspeed;
+ if(this.goalcurrent==world)
+ this.movement_x = maxspeed;
}
}
// If we are under water with no goals, swim up
- if(self.waterlevel)
- if(self.goalcurrent==world)
+ if(this.waterlevel)
+ if(this.goalcurrent==world)
{
dir = '0 0 0';
- if(self.waterlevel>WATERLEVEL_SWIMMING)
+ if(this.waterlevel>WATERLEVEL_SWIMMING)
dir.z = 1;
- else if(self.velocity.z >= 0 && !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER))
- PHYS_INPUT_BUTTON_JUMP(self) = true;
+ else if(this.velocity.z >= 0 && !(this.waterlevel == WATERLEVEL_WETFEET && this.watertype == CONTENT_WATER))
+ PHYS_INPUT_BUTTON_JUMP(this) = true;
else
- PHYS_INPUT_BUTTON_JUMP(self) = false;
- makevectors(self.v_angle.y * '0 1 0');
- self.movement_x = dir * v_forward * maxspeed;
- self.movement_y = dir * v_right * maxspeed;
- self.movement_z = dir * v_up * maxspeed;
+ PHYS_INPUT_BUTTON_JUMP(this) = false;
+ makevectors(this.v_angle.y * '0 1 0');
+ this.movement_x = dir * v_forward * maxspeed;
+ this.movement_y = dir * v_right * maxspeed;
+ this.movement_z = dir * v_up * maxspeed;
}
// if there is nowhere to go, exit
- if (self.goalcurrent == world)
+ if (this.goalcurrent == world)
return;
- if (self.goalcurrent)
+ if (this.goalcurrent)
navigation_poptouchedgoals();
// if ran out of goals try to use an alternative goal or get a new strategy asap
- if(self.goalcurrent == world)
+ if(this.goalcurrent == world)
{
- self.bot_strategytime = 0;
+ this.bot_strategytime = 0;
return;
}
if(autocvar_bot_debug_goalstack)
- debuggoalstack();
+ debuggoalstack(this);
- m1 = self.goalcurrent.origin + self.goalcurrent.mins;
- m2 = self.goalcurrent.origin + self.goalcurrent.maxs;
- destorg = self.origin;
+ m1 = this.goalcurrent.origin + this.goalcurrent.mins;
+ m2 = this.goalcurrent.origin + this.goalcurrent.maxs;
+ destorg = this.origin;
destorg.x = bound(m1_x, destorg.x, m2_x);
destorg.y = bound(m1_y, destorg.y, m2_y);
destorg.z = bound(m1_z, destorg.z, m2_z);
- diff = destorg - self.origin;
+ diff = destorg - this.origin;
//dist = vlen(diff);
dir = normalize(diff);
flatdir = diff;flatdir.z = 0;
flatdir = normalize(flatdir);
- gco = (self.goalcurrent.absmin + self.goalcurrent.absmax) * 0.5;
+ gco = (this.goalcurrent.absmin + this.goalcurrent.absmax) * 0.5;
- //if (self.bot_dodgevector_time < time)
+ //if (this.bot_dodgevector_time < time)
{
- // self.bot_dodgevector_time = time + cvar("bot_ai_dodgeupdateinterval");
- // self.bot_dodgevector_jumpbutton = 1;
+ // this.bot_dodgevector_time = time + cvar("bot_ai_dodgeupdateinterval");
+ // this.bot_dodgevector_jumpbutton = 1;
evadeobstacle = '0 0 0';
evadelava = '0 0 0';
- if (self.waterlevel)
+ if (this.waterlevel)
{
- if(self.waterlevel>WATERLEVEL_SWIMMING)
+ if(this.waterlevel>WATERLEVEL_SWIMMING)
{
// flatdir_z = 1;
- self.aistatus |= AI_STATUS_OUT_WATER;
+ this.aistatus |= AI_STATUS_OUT_WATER;
}
else
{
- if(self.velocity.z >= 0 && !(self.watertype == CONTENT_WATER && gco.z < self.origin.z) &&
- ( !(self.waterlevel == WATERLEVEL_WETFEET && self.watertype == CONTENT_WATER) || self.aistatus & AI_STATUS_OUT_WATER))
- PHYS_INPUT_BUTTON_JUMP(self) = true;
+ if(this.velocity.z >= 0 && !(this.watertype == CONTENT_WATER && gco.z < this.origin.z) &&
+ ( !(this.waterlevel == WATERLEVEL_WETFEET && this.watertype == CONTENT_WATER) || this.aistatus & AI_STATUS_OUT_WATER))
+ PHYS_INPUT_BUTTON_JUMP(this) = true;
else
- PHYS_INPUT_BUTTON_JUMP(self) = false;
+ PHYS_INPUT_BUTTON_JUMP(this) = false;
}
dir = normalize(flatdir);
- makevectors(self.v_angle.y * '0 1 0');
+ makevectors(this.v_angle.y * '0 1 0');
}
else
{
- if(self.aistatus & AI_STATUS_OUT_WATER)
- self.aistatus &= ~AI_STATUS_OUT_WATER;
+ if(this.aistatus & AI_STATUS_OUT_WATER)
+ this.aistatus &= ~AI_STATUS_OUT_WATER;
// jump if going toward an obstacle that doesn't look like stairs we
// can walk up directly
- tracebox(self.origin, self.mins, self.maxs, self.origin + self.velocity * 0.2, false, self);
+ tracebox(this.origin, this.mins, this.maxs, this.origin + this.velocity * 0.2, false, this);
if (trace_fraction < 1)
if (trace_plane_normal.z < 0.7)
{
s = trace_fraction;
- tracebox(self.origin + stepheightvec, self.mins, self.maxs, self.origin + self.velocity * 0.2 + stepheightvec, false, self);
+ tracebox(this.origin + stepheightvec, this.mins, this.maxs, this.origin + this.velocity * 0.2 + stepheightvec, false, this);
if (trace_fraction < s + 0.01)
if (trace_plane_normal.z < 0.7)
{
s = trace_fraction;
- tracebox(self.origin + jumpstepheightvec, self.mins, self.maxs, self.origin + self.velocity * 0.2 + jumpstepheightvec, false, self);
+ tracebox(this.origin + jumpstepheightvec, this.mins, this.maxs, this.origin + this.velocity * 0.2 + jumpstepheightvec, false, this);
if (trace_fraction > s)
- PHYS_INPUT_BUTTON_JUMP(self) = true;
+ PHYS_INPUT_BUTTON_JUMP(this) = true;
}
}
// avoiding dangers and obstacles
vector dst_ahead, dst_down;
- makevectors(self.v_angle.y * '0 1 0');
- dst_ahead = self.origin + self.view_ofs + (self.velocity * 0.4) + (v_forward * 32 * 3);
+ makevectors(this.v_angle.y * '0 1 0');
+ dst_ahead = this.origin + this.view_ofs + (this.velocity * 0.4) + (v_forward * 32 * 3);
dst_down = dst_ahead - '0 0 1500';
// Look ahead
- traceline(self.origin + self.view_ofs, dst_ahead, true, world);
+ traceline(this.origin + this.view_ofs, dst_ahead, true, world);
// Check head-banging against walls
- if(vlen(self.origin + self.view_ofs - trace_endpos) < 25 && !(self.aistatus & AI_STATUS_OUT_WATER))
+ if(vlen(this.origin + this.view_ofs - trace_endpos) < 25 && !(this.aistatus & AI_STATUS_OUT_WATER))
{
- PHYS_INPUT_BUTTON_JUMP(self) = true;
- if(self.facingwalltime && time > self.facingwalltime)
+ PHYS_INPUT_BUTTON_JUMP(this) = true;
+ if(this.facingwalltime && time > this.facingwalltime)
{
- self.ignoregoal = self.goalcurrent;
- self.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
- self.bot_strategytime = 0;
+ this.ignoregoal = this.goalcurrent;
+ this.ignoregoaltime = time + autocvar_bot_ai_ignoregoal_timeout;
+ this.bot_strategytime = 0;
return;
}
else
{
- self.facingwalltime = time + 0.05;
+ this.facingwalltime = time + 0.05;
}
}
else
{
- self.facingwalltime = 0;
+ this.facingwalltime = 0;
- if(self.ignoregoal != world && time > self.ignoregoaltime)
+ if(this.ignoregoal != world && time > this.ignoregoaltime)
{
- self.ignoregoal = world;
- self.ignoregoaltime = 0;
+ this.ignoregoal = world;
+ this.ignoregoaltime = 0;
}
}
// Check for water/slime/lava and dangerous edges
// (only when the bot is on the ground or jumping intentionally)
- self.aistatus &= ~AI_STATUS_DANGER_AHEAD;
+ this.aistatus &= ~AI_STATUS_DANGER_AHEAD;
- if(trace_fraction == 1 && self.jumppadcount == 0 && !self.goalcurrent.wphardwired )
- if((IS_ONGROUND(self)) || (self.aistatus & AI_STATUS_RUNNING) || PHYS_INPUT_BUTTON_JUMP(self))
+ if(trace_fraction == 1 && this.jumppadcount == 0 && !this.goalcurrent.wphardwired )
+ if((IS_ONGROUND(this)) || (this.aistatus & AI_STATUS_RUNNING) || PHYS_INPUT_BUTTON_JUMP(this))
{
// Look downwards
traceline(dst_ahead , dst_down, true, world);
- // te_lightning2(world, self.origin, dst_ahead); // Draw "ahead" look
+ // te_lightning2(world, this.origin, dst_ahead); // Draw "ahead" look
// te_lightning2(world, dst_ahead, dst_down); // Draw "downwards" look
- if(trace_endpos.z < self.origin.z + self.mins.z)
+ if(trace_endpos.z < this.origin.z + this.mins.z)
{
s = pointcontents(trace_endpos + '0 0 1');
if (s != CONTENT_SOLID)
if (s == CONTENT_LAVA || s == CONTENT_SLIME)
- evadelava = normalize(self.velocity) * -1;
+ evadelava = normalize(this.velocity) * -1;
else if (s == CONTENT_SKY)
- evadeobstacle = normalize(self.velocity) * -1;
- else if (!boxesoverlap(dst_ahead - self.view_ofs + self.mins, dst_ahead - self.view_ofs + self.maxs,
- self.goalcurrent.absmin, self.goalcurrent.absmax))
+ evadeobstacle = normalize(this.velocity) * -1;
+ else if (!boxesoverlap(dst_ahead - this.view_ofs + this.mins, dst_ahead - this.view_ofs + this.maxs,
+ this.goalcurrent.absmin, this.goalcurrent.absmax))
{
// if ain't a safe goal with "holes" (like the jumpad on soylent)
// and there is a trigger_hurt below
- if(tracebox_hits_trigger_hurt(dst_ahead, self.mins, self.maxs, trace_endpos))
+ if(tracebox_hits_trigger_hurt(dst_ahead, this.mins, this.maxs, trace_endpos))
{
// Remove dangerous dynamic goals from stack
- LOG_TRACE("bot ", self.netname, " avoided the goal ", self.goalcurrent.classname, " ", etos(self.goalcurrent), " because it led to a dangerous path; goal stack cleared\n");
- navigation_clearroute();
+ LOG_TRACE("bot ", this.netname, " avoided the goal ", this.goalcurrent.classname, " ", etos(this.goalcurrent), " because it led to a dangerous path; goal stack cleared\n");
+ navigation_clearroute(this);
return;
}
}
dir = flatdir;
evadeobstacle.z = 0;
evadelava.z = 0;
- makevectors(self.v_angle.y * '0 1 0');
+ makevectors(this.v_angle.y * '0 1 0');
if(evadeobstacle!='0 0 0'||evadelava!='0 0 0')
- self.aistatus |= AI_STATUS_DANGER_AHEAD;
+ this.aistatus |= AI_STATUS_DANGER_AHEAD;
}
dodge = havocbot_dodge();
- dodge = dodge * bound(0,0.5+(skill+self.bot_dodgeskill)*0.1,1);
- evadelava = evadelava * bound(1,3-(skill+self.bot_dodgeskill),3); //Noobs fear lava a lot and take more distance from it
- traceline(self.origin, ( ( self.enemy.absmin + self.enemy.absmax ) * 0.5 ), true, world);
+ dodge = dodge * bound(0,0.5+(skill+this.bot_dodgeskill)*0.1,1);
+ evadelava = evadelava * bound(1,3-(skill+this.bot_dodgeskill),3); //Noobs fear lava a lot and take more distance from it
+ traceline(this.origin, ( ( this.enemy.absmin + this.enemy.absmax ) * 0.5 ), true, world);
if(IS_PLAYER(trace_ent))
- dir = dir * bound(0,(skill+self.bot_dodgeskill)/7,1);
+ dir = dir * bound(0,(skill+this.bot_dodgeskill)/7,1);
dir = normalize(dir + dodge + evadeobstacle + evadelava);
- // self.bot_dodgevector = dir;
- // self.bot_dodgevector_jumpbutton = PHYS_INPUT_BUTTON_JUMP(self);
+ // this.bot_dodgevector = dir;
+ // this.bot_dodgevector_jumpbutton = PHYS_INPUT_BUTTON_JUMP(this);
}
- if(time < self.ladder_time)
+ if(time < this.ladder_time)
{
- if(self.goalcurrent.origin.z + self.goalcurrent.mins.z > self.origin.z + self.mins.z)
+ if(this.goalcurrent.origin.z + this.goalcurrent.mins.z > this.origin.z + this.mins.z)
{
- if(self.origin.z + self.mins.z < self.ladder_entity.origin.z + self.ladder_entity.maxs.z)
+ if(this.origin.z + this.mins.z < this.ladder_entity.origin.z + this.ladder_entity.maxs.z)
dir.z = 1;
}
else
{
- if(self.origin.z + self.mins.z > self.ladder_entity.origin.z + self.ladder_entity.mins.z)
+ if(this.origin.z + this.mins.z > this.ladder_entity.origin.z + this.ladder_entity.mins.z)
dir.z = -1;
}
}
- //dir = self.bot_dodgevector;
- //if (self.bot_dodgevector_jumpbutton)
- // PHYS_INPUT_BUTTON_JUMP(self) = true;
- self.movement_x = dir * v_forward * maxspeed;
- self.movement_y = dir * v_right * maxspeed;
- self.movement_z = dir * v_up * maxspeed;
+ //dir = this.bot_dodgevector;
+ //if (this.bot_dodgevector_jumpbutton)
+ // PHYS_INPUT_BUTTON_JUMP(this) = true;
+ this.movement_x = dir * v_forward * maxspeed;
+ this.movement_y = dir * v_right * maxspeed;
+ this.movement_z = dir * v_up * maxspeed;
// Emulate keyboard interface
if (skill < 10)
- havocbot_keyboard_movement(destorg);
+ havocbot_keyboard_movement(this, destorg);
// Bunnyhop!
-// if(self.aistatus & AI_STATUS_ROAMING)
- if(self.goalcurrent)
- if(skill+self.bot_moveskill >= autocvar_bot_ai_bunnyhop_skilloffset)
- havocbot_bunnyhop(dir);
-
- if ((dir * v_up) >= autocvar_sv_jumpvelocity*0.5 && (IS_ONGROUND(self))) PHYS_INPUT_BUTTON_JUMP(self) = true;
- if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill-self.bot_dodgeskill)*0.1,1)) PHYS_INPUT_BUTTON_JUMP(self) = true;
- if (((dodge * v_up) < 0) && random()*frametime >= 0.5*bound(0,(10-skill-self.bot_dodgeskill)*0.1,1)) self.havocbot_ducktime=time+0.3/bound(0.1,skill+self.bot_dodgeskill,10);
+// if(this.aistatus & AI_STATUS_ROAMING)
+ if(this.goalcurrent)
+ if(skill+this.bot_moveskill >= autocvar_bot_ai_bunnyhop_skilloffset)
+ havocbot_bunnyhop(this, dir);
+
+ if ((dir * v_up) >= autocvar_sv_jumpvelocity*0.5 && (IS_ONGROUND(this))) PHYS_INPUT_BUTTON_JUMP(this) = true;
+ if (((dodge * v_up) > 0) && random()*frametime >= 0.2*bound(0,(10-skill-this.bot_dodgeskill)*0.1,1)) PHYS_INPUT_BUTTON_JUMP(this) = true;
+ if (((dodge * v_up) < 0) && random()*frametime >= 0.5*bound(0,(10-skill-this.bot_dodgeskill)*0.1,1)) this.havocbot_ducktime=time+0.3/bound(0.1,skill+this.bot_dodgeskill,10);
}
-void havocbot_chooseenemy()
-{SELFPARAM();
+void havocbot_chooseenemy(entity this)
+{
entity head, best, head2;
float rating, bestrating, hf;
vector eye, v;
- if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(self))
+ if (autocvar_bot_nofire || IS_INDEPENDENT_PLAYER(this))
{
- self.enemy = world;
+ this.enemy = world;
return;
}
- if (self.enemy)
+ if (this.enemy)
{
- if (!bot_shouldattack(self.enemy))
+ if (!bot_shouldattack(this, this.enemy))
{
// enemy died or something, find a new target
- self.enemy = world;
- self.havocbot_chooseenemy_finished = time;
+ this.enemy = world;
+ this.havocbot_chooseenemy_finished = time;
}
- else if (self.havocbot_stickenemy)
+ else if (this.havocbot_stickenemy)
{
// tracking last chosen enemy
// if enemy is visible
// and not really really far away
// and we're not severely injured
// then keep tracking for a half second into the future
- traceline(self.origin+self.view_ofs, ( self.enemy.absmin + self.enemy.absmax ) * 0.5,false,world);
- if (trace_ent == self.enemy || trace_fraction == 1)
- if (vlen((( self.enemy.absmin + self.enemy.absmax ) * 0.5) - self.origin) < 1000)
- if (self.health > 30)
+ traceline(this.origin+this.view_ofs, ( this.enemy.absmin + this.enemy.absmax ) * 0.5,false,world);
+ if (trace_ent == this.enemy || trace_fraction == 1)
+ if (vdist(((this.enemy.absmin + this.enemy.absmax) * 0.5) - this.origin, <, 1000))
+ if (this.health > 30)
{
// remain tracking him for a shot while (case he went after a small corner or pilar
- self.havocbot_chooseenemy_finished = time + 0.5;
+ this.havocbot_chooseenemy_finished = time + 0.5;
return;
}
// enemy isn't visible, or is far away, or we're injured severely
// so stop preferring this enemy
// (it will still take a half second until a new one is chosen)
- self.havocbot_stickenemy = 0;
+ this.havocbot_stickenemy = 0;
}
}
- if (time < self.havocbot_chooseenemy_finished)
+ if (time < this.havocbot_chooseenemy_finished)
return;
- self.havocbot_chooseenemy_finished = time + autocvar_bot_ai_enemydetectioninterval;
- eye = self.origin + self.view_ofs;
+ this.havocbot_chooseenemy_finished = time + autocvar_bot_ai_enemydetectioninterval;
+ eye = this.origin + this.view_ofs;
best = world;
bestrating = 100000000;
head = head2 = findchainfloat(bot_attack, true);
// Backup hit flags
- hf = self.dphitcontentsmask;
+ hf = this.dphitcontentsmask;
// Search for enemies, if no enemy can be seen directly try to look through transparent objects
- self.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
+ this.dphitcontentsmask = DPCONTENTS_SOLID | DPCONTENTS_BODY | DPCONTENTS_CORPSE;
bool scan_transparent = false;
bool scan_secondary_targets = false;
rating = vlen(v - eye);
if (rating<autocvar_bot_ai_enemydetectionradius)
if (bestrating > rating)
- if (bot_shouldattack(head))
+ if (bot_shouldattack(this, head))
{
- traceline(eye, v, true, self);
+ traceline(eye, v, true, this);
if (trace_ent == head || trace_fraction >= 1)
{
best = head;
// I want to do a second scan if no enemy was found or I don't have weapons
// TODO: Perform the scan when using the rifle (requires changes on the rifle code)
- if(best || self.weapons) // || self.weapon == WEP_RIFLE.m_id
+ if(best || this.weapons) // || this.weapon == WEP_RIFLE.m_id
break;
if(scan_transparent)
break;
// Set flags to see through transparent objects
- self.dphitcontentsmask |= DPCONTENTS_OPAQUE;
+ this.dphitcontentsmask |= DPCONTENTS_OPAQUE;
head = head2;
scan_transparent = true;
}
// Restore hit flags
- self.dphitcontentsmask = hf;
+ this.dphitcontentsmask = hf;
- self.enemy = best;
- self.havocbot_stickenemy = true;
+ this.enemy = best;
+ this.havocbot_stickenemy = true;
if(best && best.classname == "misc_breakablemodel")
- self.havocbot_stickenemy = false;
+ this.havocbot_stickenemy = false;
}
-float havocbot_chooseweapon_checkreload(int new_weapon)
-{SELFPARAM();
+float havocbot_chooseweapon_checkreload(entity this, int new_weapon)
+{
// bots under this skill cannot find unloaded weapons to reload idly when not in combat,
// so skip this for them, or they'll never get to reload their weapons at all.
// this also allows bots under this skill to be more stupid, and reload more often during combat :)
return false;
// if this weapon is scheduled for reloading, don't switch to it during combat
- if (self.weapon_load[new_weapon] < 0)
+ if (this.weapon_load[new_weapon] < 0)
{
bool other_weapon_available = false;
FOREACH(Weapons, it != WEP_Null, LAMBDA(
return false;
}
-void havocbot_chooseweapon()
-{SELFPARAM();
+void havocbot_chooseweapon(entity this)
+{
int i;
// ;)
if(g_weaponarena_weapons == WEPSET(TUBA))
{
- PS(self).m_switchweapon = WEP_TUBA;
+ PS(this).m_switchweapon = WEP_TUBA;
return;
}
// TODO: clean this up by moving it to weapon code
- if(self.enemy==world)
+ if(this.enemy==world)
{
// If no weapon was chosen get the first available weapon
- if(PS(self).m_weapon==WEP_Null)
+ if(PS(this).m_weapon==WEP_Null)
FOREACH(Weapons, it != WEP_Null, LAMBDA(
- if(client_hasweapon(self, it, true, false))
+ if(client_hasweapon(this, it, true, false))
{
- PS(self).m_switchweapon = it;
+ PS(this).m_switchweapon = it;
return;
}
));
}
// Do not change weapon during the next second after a combo
- float f = time - self.lastcombotime;
+ float f = time - this.lastcombotime;
if(f < 1)
return;
float w;
- float distance; distance=bound(10,vlen(self.origin-self.enemy.origin)-200,10000);
+ float distance; distance=bound(10,vlen(this.origin-this.enemy.origin)-200,10000);
// Should it do a weapon combo?
float af, ct, combo_time, combo;
- af = ATTACK_FINISHED(self, 0);
+ af = ATTACK_FINISHED(this, 0);
ct = autocvar_bot_ai_weapon_combo_threshold;
// Bots with no skill will be 4 times more slower than "godlike" bots when doing weapon combos
// Ideally this 4 should be calculated as longest_weapon_refire / bot_ai_weapon_combo_threshold
- combo_time = time + ct + (ct * ((-0.3*(skill+self.bot_weaponskill))+3));
+ combo_time = time + ct + (ct * ((-0.3*(skill+this.bot_weaponskill))+3));
combo = false;
if(autocvar_bot_ai_weapon_combo)
- if(PS(self).m_weapon.m_id == self.lastfiredweapon)
+ if(PS(this).m_weapon.m_id == this.lastfiredweapon)
if(af > combo_time)
{
combo = true;
- self.lastcombotime = time;
+ this.lastcombotime = time;
}
- distance *= pow(2, self.bot_rangepreference);
+ distance *= pow(2, this.bot_rangepreference);
// Custom weapon list based on distance to the enemy
if(bot_custom_weapon){
if ( distance > bot_distance_far ) {
for(i=0; i < Weapons_COUNT && bot_weapons_far[i] != -1 ; ++i){
w = bot_weapons_far[i];
- if ( client_hasweapon(self, Weapons_from(w), true, false) )
+ if ( client_hasweapon(this, Weapons_from(w), true, false) )
{
- if ((PS(self).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(w))
+ if ((PS(this).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(this, w))
continue;
- PS(self).m_switchweapon = Weapons_from(w);
+ PS(this).m_switchweapon = Weapons_from(w);
return;
}
}
if ( distance > bot_distance_close) {
for(i=0; i < Weapons_COUNT && bot_weapons_mid[i] != -1 ; ++i){
w = bot_weapons_mid[i];
- if ( client_hasweapon(self, Weapons_from(w), true, false) )
+ if ( client_hasweapon(this, Weapons_from(w), true, false) )
{
- if ((PS(self).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(w))
+ if ((PS(this).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(this, w))
continue;
- PS(self).m_switchweapon = Weapons_from(w);
+ PS(this).m_switchweapon = Weapons_from(w);
return;
}
}
// Choose weapons for close distance
for(i=0; i < Weapons_COUNT && bot_weapons_close[i] != -1 ; ++i){
w = bot_weapons_close[i];
- if ( client_hasweapon(self, Weapons_from(w), true, false) )
+ if ( client_hasweapon(this, Weapons_from(w), true, false) )
{
- if ((PS(self).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(w))
+ if ((PS(this).m_weapon.m_id == w && combo) || havocbot_chooseweapon_checkreload(this, w))
continue;
- PS(self).m_switchweapon = Weapons_from(w);
+ PS(this).m_switchweapon = Weapons_from(w);
return;
}
}
}
}
-void havocbot_aim()
-{SELFPARAM();
+void havocbot_aim(entity this)
+{
vector selfvel, enemyvel;
-// if(self.flags & FL_INWATER)
+// if(this.flags & FL_INWATER)
// return;
- if (time < self.nextaim)
+ if (time < this.nextaim)
return;
- self.nextaim = time + 0.1;
- selfvel = self.velocity;
- if (!self.waterlevel)
+ this.nextaim = time + 0.1;
+ selfvel = this.velocity;
+ if (!this.waterlevel)
selfvel.z = 0;
- if (self.enemy)
+ if (this.enemy)
{
- enemyvel = self.enemy.velocity;
- if (!self.enemy.waterlevel)
+ enemyvel = this.enemy.velocity;
+ if (!this.enemy.waterlevel)
enemyvel.z = 0;
- lag_additem(time + self.ping, 0, 0, self.enemy, self.origin, selfvel, (self.enemy.absmin + self.enemy.absmax) * 0.5, enemyvel);
+ lag_additem(this, time + this.ping, 0, 0, this.enemy, this.origin, selfvel, (this.enemy.absmin + this.enemy.absmax) * 0.5, enemyvel);
}
else
- lag_additem(time + self.ping, 0, 0, world, self.origin, selfvel, ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5, '0 0 0');
+ lag_additem(this, time + this.ping, 0, 0, world, this.origin, selfvel, ( this.goalcurrent.absmin + this.goalcurrent.absmax ) * 0.5, '0 0 0');
}
-float havocbot_moveto_refresh_route()
-{SELFPARAM();
+float havocbot_moveto_refresh_route(entity this)
+{
// Refresh path to goal if necessary
entity wp;
- wp = self.havocbot_personal_waypoint;
- navigation_goalrating_start();
- navigation_routerating(wp, 10000, 10000);
- navigation_goalrating_end();
- return self.navigation_hasgoals;
+ wp = this.havocbot_personal_waypoint;
+ WITH(entity, self, this, navigation_goalrating_start());
+ WITH(entity, self, this, navigation_routerating(wp, 10000, 10000));
+ WITH(entity, self, this, navigation_goalrating_end());
+ return this.navigation_hasgoals;
}
-float havocbot_moveto(vector pos)
-{SELFPARAM();
+float havocbot_moveto(entity this, vector pos)
+{
entity wp;
- if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
+ if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
{
// Step 4: Move to waypoint
- if(self.havocbot_personal_waypoint==world)
+ if(this.havocbot_personal_waypoint==world)
{
- LOG_TRACE("Error: ", self.netname, " trying to walk to a non existent personal waypoint\n");
- self.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
+ LOG_TRACE("Error: ", this.netname, " trying to walk to a non existent personal waypoint\n");
+ this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
return CMD_STATUS_ERROR;
}
if (!bot_strategytoken_taken)
- if(self.havocbot_personal_waypoint_searchtime<time)
+ if(this.havocbot_personal_waypoint_searchtime<time)
{
bot_strategytoken_taken = true;
- if(havocbot_moveto_refresh_route())
+ if(havocbot_moveto_refresh_route(this))
{
- LOG_TRACE(self.netname, " walking to its personal waypoint (after ", ftos(self.havocbot_personal_waypoint_failcounter), " failed attempts)\n");
- self.havocbot_personal_waypoint_searchtime = time + 10;
- self.havocbot_personal_waypoint_failcounter = 0;
+ LOG_TRACE(this.netname, " walking to its personal waypoint (after ", ftos(this.havocbot_personal_waypoint_failcounter), " failed attempts)\n");
+ this.havocbot_personal_waypoint_searchtime = time + 10;
+ this.havocbot_personal_waypoint_failcounter = 0;
}
else
{
- self.havocbot_personal_waypoint_failcounter += 1;
- self.havocbot_personal_waypoint_searchtime = time + 2;
- if(self.havocbot_personal_waypoint_failcounter >= 30)
+ this.havocbot_personal_waypoint_failcounter += 1;
+ this.havocbot_personal_waypoint_searchtime = time + 2;
+ if(this.havocbot_personal_waypoint_failcounter >= 30)
{
- LOG_TRACE("Warning: can't walk to the personal waypoint located at ", vtos(self.havocbot_personal_waypoint.origin),"\n");
- self.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_LINKING;
- remove(self.havocbot_personal_waypoint);
+ LOG_TRACE("Warning: can't walk to the personal waypoint located at ", vtos(this.havocbot_personal_waypoint.origin),"\n");
+ this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_LINKING;
+ remove(this.havocbot_personal_waypoint);
return CMD_STATUS_ERROR;
}
else
- LOG_TRACE(self.netname, " can't walk to its personal waypoint (after ", ftos(self.havocbot_personal_waypoint_failcounter), " failed attempts), trying later\n");
+ LOG_TRACE(this.netname, " can't walk to its personal waypoint (after ", ftos(this.havocbot_personal_waypoint_failcounter), " failed attempts), trying later\n");
}
}
if(autocvar_bot_debug_goalstack)
- debuggoalstack();
+ debuggoalstack(this);
// Heading
- vector dir = ( ( self.goalcurrent.absmin + self.goalcurrent.absmax ) * 0.5 ) - (self.origin + self.view_ofs);
+ vector dir = ( ( this.goalcurrent.absmin + this.goalcurrent.absmax ) * 0.5 ) - (this.origin + this.view_ofs);
dir.z = 0;
- bot_aimdir(dir, -1);
+ bot_aimdir(this, dir, -1);
// Go!
- havocbot_movetogoal();
+ havocbot_movetogoal(this);
- if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_REACHED)
+ if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_REACHED)
{
// Step 5: Waypoint reached
- LOG_TRACE(self.netname, "'s personal waypoint reached\n");
- remove(self.havocbot_personal_waypoint);
- self.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_REACHED;
+ LOG_TRACE(this.netname, "'s personal waypoint reached\n");
+ remove(this.havocbot_personal_waypoint);
+ this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_REACHED;
return CMD_STATUS_FINISHED;
}
}
// Step 2: Linking waypoint
- if(self.aistatus & AI_STATUS_WAYPOINT_PERSONAL_LINKING)
+ if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_LINKING)
{
// Wait until it is linked
- if(!self.havocbot_personal_waypoint.wplinked)
+ if(!this.havocbot_personal_waypoint.wplinked)
{
- LOG_TRACE(self.netname, " waiting for personal waypoint to be linked\n");
+ LOG_TRACE(this.netname, " waiting for personal waypoint to be linked\n");
return CMD_STATUS_EXECUTING;
}
- self.havocbot_personal_waypoint_searchtime = time; // so we set the route next frame
- self.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_LINKING;
- self.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_GOING;
+ this.havocbot_personal_waypoint_searchtime = time; // so we set the route next frame
+ this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_LINKING;
+ this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_GOING;
// Step 3: Route to waypoint
- LOG_TRACE(self.netname, " walking to its personal waypoint\n");
+ LOG_TRACE(this.netname, " walking to its personal waypoint\n");
return CMD_STATUS_EXECUTING;
}
// Step 1: Spawning waypoint
- wp = waypoint_spawnpersonal(pos);
+ wp = waypoint_spawnpersonal(this, pos);
if(wp==world)
{
LOG_TRACE("Error: Can't spawn personal waypoint at ",vtos(pos),"\n");
return CMD_STATUS_ERROR;
}
- self.havocbot_personal_waypoint = wp;
- self.havocbot_personal_waypoint_failcounter = 0;
- self.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
+ this.havocbot_personal_waypoint = wp;
+ this.havocbot_personal_waypoint_failcounter = 0;
+ this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_LINKING;
// if pos is inside a teleport, then let's mark it as teleport waypoint
entity head;
if(WarpZoneLib_BoxTouchesBrush(pos, pos, head, world))
{
wp.wpflags |= WAYPOINTFLAG_TELEPORT;
- self.lastteleporttime = 0;
+ this.lastteleporttime = 0;
}
}
return CMD_STATUS_EXECUTING;
}
-float havocbot_resetgoal()
+float havocbot_resetgoal(entity this)
{
- navigation_clearroute();
+ navigation_clearroute(this);
return CMD_STATUS_FINISHED;
}
* Functions
*/
-void havocbot_ai();
-void havocbot_aim();
+void havocbot_ai(entity this);
+void havocbot_aim(entity this);
void havocbot_setupbot();
-void havocbot_movetogoal();
+void havocbot_movetogoal(entity this);
void havocbot_chooserole();
-void havocbot_chooseenemy();
-void havocbot_chooseweapon();
-void havocbot_bunnyhop(vector dir);
-void havocbot_keyboard_movement(vector destorg);
+void havocbot_chooseenemy(entity this);
+void havocbot_chooseweapon(entity this);
+void havocbot_bunnyhop(entity this, vector dir);
+void havocbot_keyboard_movement(entity this, vector destorg);
-float havocbot_resetgoal();
-float havocbot_moveto(vector pos);
-float havocbot_moveto_refresh_route();
+float havocbot_resetgoal(entity this);
+float havocbot_moveto(entity this, vector pos);
+float havocbot_moveto_refresh_route(entity this);
vector havocbot_dodge();
if(self.waterlevel>WATERLEVEL_WETFEET)
return;
- float distance;
int t;
- FOREACH_CLIENT(IS_PLAYER(it) && bot_shouldattack(it), LAMBDA(
+ FOREACH_CLIENT(IS_PLAYER(it) && bot_shouldattack(self, it), LAMBDA(
// TODO: Merge this logic with the bot_shouldattack function
- distance = vlen(it.origin - org);
- if (distance < 100 || distance > sradius)
+ if(vdist(it.origin - org, <, 100) || vdist(it.origin - org, >, sradius))
continue;
// rate only visible enemies
/////////////////////////////////////////////////////////////////////////////
// completely empty the goal stack, used when deciding where to go
-void navigation_clearroute()
-{SELFPARAM();
- //print("bot ", etos(self), " clear\n");
- self.navigation_hasgoals = false;
- self.goalcurrent = world;
- self.goalstack01 = world;
- self.goalstack02 = world;
- self.goalstack03 = world;
- self.goalstack04 = world;
- self.goalstack05 = world;
- self.goalstack06 = world;
- self.goalstack07 = world;
- self.goalstack08 = world;
- self.goalstack09 = world;
- self.goalstack10 = world;
- self.goalstack11 = world;
- self.goalstack12 = world;
- self.goalstack13 = world;
- self.goalstack14 = world;
- self.goalstack15 = world;
- self.goalstack16 = world;
- self.goalstack17 = world;
- self.goalstack18 = world;
- self.goalstack19 = world;
- self.goalstack20 = world;
- self.goalstack21 = world;
- self.goalstack22 = world;
- self.goalstack23 = world;
- self.goalstack24 = world;
- self.goalstack25 = world;
- self.goalstack26 = world;
- self.goalstack27 = world;
- self.goalstack28 = world;
- self.goalstack29 = world;
- self.goalstack30 = world;
- self.goalstack31 = world;
+void navigation_clearroute(entity this)
+{
+ //print("bot ", etos(this), " clear\n");
+ this.navigation_hasgoals = false;
+ this.goalcurrent = world;
+ this.goalstack01 = world;
+ this.goalstack02 = world;
+ this.goalstack03 = world;
+ this.goalstack04 = world;
+ this.goalstack05 = world;
+ this.goalstack06 = world;
+ this.goalstack07 = world;
+ this.goalstack08 = world;
+ this.goalstack09 = world;
+ this.goalstack10 = world;
+ this.goalstack11 = world;
+ this.goalstack12 = world;
+ this.goalstack13 = world;
+ this.goalstack14 = world;
+ this.goalstack15 = world;
+ this.goalstack16 = world;
+ this.goalstack17 = world;
+ this.goalstack18 = world;
+ this.goalstack19 = world;
+ this.goalstack20 = world;
+ this.goalstack21 = world;
+ this.goalstack22 = world;
+ this.goalstack23 = world;
+ this.goalstack24 = world;
+ this.goalstack25 = world;
+ this.goalstack26 = world;
+ this.goalstack27 = world;
+ this.goalstack28 = world;
+ this.goalstack29 = world;
+ this.goalstack30 = world;
+ this.goalstack31 = world;
}
// add a new goal at the beginning of the stack
// next-closest WP on the shortest path to the WP
// That means, if the stack overflows, the bot will know how to do the FIRST 32
// steps to the goal, and then recalculate the path.
-void navigation_pushroute(entity e)
-{SELFPARAM();
- //print("bot ", etos(self), " push ", etos(e), "\n");
- self.goalstack31 = self.goalstack30;
- self.goalstack30 = self.goalstack29;
- self.goalstack29 = self.goalstack28;
- self.goalstack28 = self.goalstack27;
- self.goalstack27 = self.goalstack26;
- self.goalstack26 = self.goalstack25;
- self.goalstack25 = self.goalstack24;
- self.goalstack24 = self.goalstack23;
- self.goalstack23 = self.goalstack22;
- self.goalstack22 = self.goalstack21;
- self.goalstack21 = self.goalstack20;
- self.goalstack20 = self.goalstack19;
- self.goalstack19 = self.goalstack18;
- self.goalstack18 = self.goalstack17;
- self.goalstack17 = self.goalstack16;
- self.goalstack16 = self.goalstack15;
- self.goalstack15 = self.goalstack14;
- self.goalstack14 = self.goalstack13;
- self.goalstack13 = self.goalstack12;
- self.goalstack12 = self.goalstack11;
- self.goalstack11 = self.goalstack10;
- self.goalstack10 = self.goalstack09;
- self.goalstack09 = self.goalstack08;
- self.goalstack08 = self.goalstack07;
- self.goalstack07 = self.goalstack06;
- self.goalstack06 = self.goalstack05;
- self.goalstack05 = self.goalstack04;
- self.goalstack04 = self.goalstack03;
- self.goalstack03 = self.goalstack02;
- self.goalstack02 = self.goalstack01;
- self.goalstack01 = self.goalcurrent;
- self.goalcurrent = e;
+void navigation_pushroute(entity this, entity e)
+{
+ //print("bot ", etos(this), " push ", etos(e), "\n");
+ this.goalstack31 = this.goalstack30;
+ this.goalstack30 = this.goalstack29;
+ this.goalstack29 = this.goalstack28;
+ this.goalstack28 = this.goalstack27;
+ this.goalstack27 = this.goalstack26;
+ this.goalstack26 = this.goalstack25;
+ this.goalstack25 = this.goalstack24;
+ this.goalstack24 = this.goalstack23;
+ this.goalstack23 = this.goalstack22;
+ this.goalstack22 = this.goalstack21;
+ this.goalstack21 = this.goalstack20;
+ this.goalstack20 = this.goalstack19;
+ this.goalstack19 = this.goalstack18;
+ this.goalstack18 = this.goalstack17;
+ this.goalstack17 = this.goalstack16;
+ this.goalstack16 = this.goalstack15;
+ this.goalstack15 = this.goalstack14;
+ this.goalstack14 = this.goalstack13;
+ this.goalstack13 = this.goalstack12;
+ this.goalstack12 = this.goalstack11;
+ this.goalstack11 = this.goalstack10;
+ this.goalstack10 = this.goalstack09;
+ this.goalstack09 = this.goalstack08;
+ this.goalstack08 = this.goalstack07;
+ this.goalstack07 = this.goalstack06;
+ this.goalstack06 = this.goalstack05;
+ this.goalstack05 = this.goalstack04;
+ this.goalstack04 = this.goalstack03;
+ this.goalstack03 = this.goalstack02;
+ this.goalstack02 = this.goalstack01;
+ this.goalstack01 = this.goalcurrent;
+ this.goalcurrent = e;
}
// remove first goal from stack
}
// adds an item to the the goal stack with the path to a given item
-float navigation_routetogoal(entity e, vector startposition)
-{SELFPARAM();
- self.goalentity = e;
+bool navigation_routetogoal(entity this, entity e, vector startposition)
+{
+ this.goalentity = e;
// if there is no goal, just exit
if (!e)
return false;
- self.navigation_hasgoals = true;
+ this.navigation_hasgoals = true;
// put the entity on the goal stack
//print("routetogoal ", etos(e), "\n");
- navigation_pushroute(e);
+ navigation_pushroute(this, e);
if(g_jetpack)
- if(e==self.navigation_jetpack_goal)
+ if(e==this.navigation_jetpack_goal)
return true;
// if it can reach the goal there is nothing more to do
- if (tracewalk(self, startposition, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), (e.absmin + e.absmax) * 0.5, bot_navigation_movemode))
+ if (tracewalk(this, startposition, STAT(PL_MIN, NULL), STAT(PL_MAX, NULL), (e.absmin + e.absmax) * 0.5, bot_navigation_movemode))
return true;
// see if there are waypoints describing a path to the item
for (;;)
{
// add the spawnfunc_waypoint to the path
- navigation_pushroute(e);
+ navigation_pushroute(this, e);
e = e.enemy;
if(e==world)
self.navigation_jetpack_goal = world;
navigation_bestrating = -1;
self.navigation_hasgoals = false;
- navigation_clearroute();
+ navigation_clearroute(self);
navigation_bestgoal = world;
navigation_markroutes(world);
}
if(self.aistatus & AI_STATUS_STUCK)
return;
- navigation_routetogoal(navigation_bestgoal, self.origin);
+ navigation_routetogoal(self, navigation_bestgoal, self.origin);
LOG_DEBUG(strcat("best goal ", self.goalcurrent.classname , "\n"));
// If the bot got stuck then try to reach the farthest waypoint
if (bot_waypoint_queue_bestgoal)
{
LOG_DEBUG(strcat(self.netname, " stuck, reachable waypoint found, heading to it\n"));
- navigation_routetogoal(bot_waypoint_queue_bestgoal, self.origin);
+ navigation_routetogoal(self, bot_waypoint_queue_bestgoal, self.origin);
self.bot_strategytime = time + autocvar_bot_ai_strategyinterval;
self.aistatus &= ~AI_STATUS_STUCK;
}
.vector lastposition;
// Debug the goal stack visually
-void debuggoalstack()
-{SELFPARAM();
+void debuggoalstack(entity this)
+{
entity goal;
vector org, go;
- if(self.goalcounter==0)goal=self.goalcurrent;
- else if(self.goalcounter==1)goal=self.goalstack01;
- else if(self.goalcounter==2)goal=self.goalstack02;
- else if(self.goalcounter==3)goal=self.goalstack03;
- else if(self.goalcounter==4)goal=self.goalstack04;
- else if(self.goalcounter==5)goal=self.goalstack05;
- else if(self.goalcounter==6)goal=self.goalstack06;
- else if(self.goalcounter==7)goal=self.goalstack07;
- else if(self.goalcounter==8)goal=self.goalstack08;
- else if(self.goalcounter==9)goal=self.goalstack09;
- else if(self.goalcounter==10)goal=self.goalstack10;
- else if(self.goalcounter==11)goal=self.goalstack11;
- else if(self.goalcounter==12)goal=self.goalstack12;
- else if(self.goalcounter==13)goal=self.goalstack13;
- else if(self.goalcounter==14)goal=self.goalstack14;
- else if(self.goalcounter==15)goal=self.goalstack15;
- else if(self.goalcounter==16)goal=self.goalstack16;
- else if(self.goalcounter==17)goal=self.goalstack17;
- else if(self.goalcounter==18)goal=self.goalstack18;
- else if(self.goalcounter==19)goal=self.goalstack19;
- else if(self.goalcounter==20)goal=self.goalstack20;
- else if(self.goalcounter==21)goal=self.goalstack21;
- else if(self.goalcounter==22)goal=self.goalstack22;
- else if(self.goalcounter==23)goal=self.goalstack23;
- else if(self.goalcounter==24)goal=self.goalstack24;
- else if(self.goalcounter==25)goal=self.goalstack25;
- else if(self.goalcounter==26)goal=self.goalstack26;
- else if(self.goalcounter==27)goal=self.goalstack27;
- else if(self.goalcounter==28)goal=self.goalstack28;
- else if(self.goalcounter==29)goal=self.goalstack29;
- else if(self.goalcounter==30)goal=self.goalstack30;
- else if(self.goalcounter==31)goal=self.goalstack31;
+ if(this.goalcounter==0)goal=this.goalcurrent;
+ else if(this.goalcounter==1)goal=this.goalstack01;
+ else if(this.goalcounter==2)goal=this.goalstack02;
+ else if(this.goalcounter==3)goal=this.goalstack03;
+ else if(this.goalcounter==4)goal=this.goalstack04;
+ else if(this.goalcounter==5)goal=this.goalstack05;
+ else if(this.goalcounter==6)goal=this.goalstack06;
+ else if(this.goalcounter==7)goal=this.goalstack07;
+ else if(this.goalcounter==8)goal=this.goalstack08;
+ else if(this.goalcounter==9)goal=this.goalstack09;
+ else if(this.goalcounter==10)goal=this.goalstack10;
+ else if(this.goalcounter==11)goal=this.goalstack11;
+ else if(this.goalcounter==12)goal=this.goalstack12;
+ else if(this.goalcounter==13)goal=this.goalstack13;
+ else if(this.goalcounter==14)goal=this.goalstack14;
+ else if(this.goalcounter==15)goal=this.goalstack15;
+ else if(this.goalcounter==16)goal=this.goalstack16;
+ else if(this.goalcounter==17)goal=this.goalstack17;
+ else if(this.goalcounter==18)goal=this.goalstack18;
+ else if(this.goalcounter==19)goal=this.goalstack19;
+ else if(this.goalcounter==20)goal=this.goalstack20;
+ else if(this.goalcounter==21)goal=this.goalstack21;
+ else if(this.goalcounter==22)goal=this.goalstack22;
+ else if(this.goalcounter==23)goal=this.goalstack23;
+ else if(this.goalcounter==24)goal=this.goalstack24;
+ else if(this.goalcounter==25)goal=this.goalstack25;
+ else if(this.goalcounter==26)goal=this.goalstack26;
+ else if(this.goalcounter==27)goal=this.goalstack27;
+ else if(this.goalcounter==28)goal=this.goalstack28;
+ else if(this.goalcounter==29)goal=this.goalstack29;
+ else if(this.goalcounter==30)goal=this.goalstack30;
+ else if(this.goalcounter==31)goal=this.goalstack31;
else goal=world;
if(goal==world)
{
- self.goalcounter = 0;
- self.lastposition='0 0 0';
+ this.goalcounter = 0;
+ this.lastposition='0 0 0';
return;
}
- if(self.lastposition=='0 0 0')
- org = self.origin;
+ if(this.lastposition=='0 0 0')
+ org = this.origin;
else
- org = self.lastposition;
+ org = this.lastposition;
go = ( goal.absmin + goal.absmax ) * 0.5;
te_lightning2(world, org, go);
- self.lastposition = go;
+ this.lastposition = go;
- self.goalcounter++;
+ this.goalcounter++;
}
void debugnode(vector node);
void debugnodestatus(vector position, float status);
-void debuggoalstack();
+void debuggoalstack(entity this);
float tracewalk(entity e, vector start, vector m1, vector m2, vector end, float movemode);
float navigation_markroutes_nearestwaypoints(entity waylist, float maxdist);
-float navigation_routetogoal(entity e, vector startposition);
+float navigation_routetogoal(entity this, entity e, vector startposition);
-void navigation_clearroute();
-void navigation_pushroute(entity e);
+void navigation_clearroute(entity this);
+void navigation_pushroute(entity this, entity e);
void navigation_poproute();
void navigation_markroutes_checkwaypoint(entity w, entity wp, float cost2, vector p);
void navigation_markroutes(entity fixed_source_waypoint);
return bufstr_get(bot.bot_cmdqueuebuf, idx);
}
-float bot_havecommand(entity bot, float idx)
+bool bot_havecommand(entity this, int idx)
{
- if(!bot.bot_cmdqueuebuf_allocated)
- return 0;
- if(idx < bot.bot_cmdqueuebuf_start)
- return 0;
- if(idx >= bot.bot_cmdqueuebuf_end)
- return 0;
- return 1;
+ if(!this.bot_cmdqueuebuf_allocated)
+ return false;
+ if(idx < this.bot_cmdqueuebuf_start)
+ return false;
+ if(idx >= this.bot_cmdqueuebuf_end)
+ return false;
+ return true;
}
const int MAX_BOT_PLACES = 4;
.float bot_places_count;
.entity bot_places[MAX_BOT_PLACES];
.string bot_placenames[MAX_BOT_PLACES];
-entity bot_getplace(string placename)
-{SELFPARAM();
+entity bot_getplace(entity this, string placename)
+{
entity e;
if(substring(placename, 0, 1) == "@")
{
int i, p;
placename = substring(placename, 1, -1);
string s, s2;
- for(i = 0; i < self.bot_places_count; ++i)
- if(self.(bot_placenames[i]) == placename)
- return self.(bot_places[i]);
- // now: i == self.bot_places_count
+ for(i = 0; i < this.bot_places_count; ++i)
+ if(this.(bot_placenames[i]) == placename)
+ return this.(bot_places[i]);
+ // now: i == this.bot_places_count
s = s2 = cvar_string(placename);
p = strstrofs(s2, " ", 0);
if(p >= 0)
LOG_INFO("invalid place ", s, "\n");
if(i < MAX_BOT_PLACES)
{
- self.(bot_placenames[i]) = strzone(placename);
- self.(bot_places[i]) = e;
- self.bot_places_count += 1;
+ this.(bot_placenames[i]) = strzone(placename);
+ this.(bot_places[i]) = e;
+ this.bot_places_count += 1;
}
return e;
}
.int bot_exec_status;
void SV_ParseClientCommand(string s);
-float bot_cmd_cc()
+float bot_cmd_cc(entity this)
{
- SV_ParseClientCommand(bot_cmd.bot_cmd_parm_string);
+ WITH(entity, self, this, SV_ParseClientCommand(bot_cmd.bot_cmd_parm_string));
return CMD_STATUS_FINISHED;
}
-float bot_cmd_impulse()
-{SELFPARAM();
- self.impulse = bot_cmd.bot_cmd_parm_float;
+float bot_cmd_impulse(entity this)
+{
+ this.impulse = bot_cmd.bot_cmd_parm_float;
return CMD_STATUS_FINISHED;
}
-float bot_cmd_continue()
-{SELFPARAM();
- self.bot_exec_status &= ~BOT_EXEC_STATUS_PAUSED;
+float bot_cmd_continue(entity this)
+{
+ this.bot_exec_status &= ~BOT_EXEC_STATUS_PAUSED;
return CMD_STATUS_FINISHED;
}
.float bot_cmd_wait_time;
-float bot_cmd_wait()
-{SELFPARAM();
- if(self.bot_exec_status & BOT_EXEC_STATUS_WAITING)
+float bot_cmd_wait(entity this)
+{
+ if(this.bot_exec_status & BOT_EXEC_STATUS_WAITING)
{
- if(time>=self.bot_cmd_wait_time)
+ if(time>=this.bot_cmd_wait_time)
{
- self.bot_exec_status &= ~BOT_EXEC_STATUS_WAITING;
+ this.bot_exec_status &= ~BOT_EXEC_STATUS_WAITING;
return CMD_STATUS_FINISHED;
}
else
return CMD_STATUS_EXECUTING;
}
- self.bot_cmd_wait_time = time + bot_cmd.bot_cmd_parm_float;
- self.bot_exec_status |= BOT_EXEC_STATUS_WAITING;
+ this.bot_cmd_wait_time = time + bot_cmd.bot_cmd_parm_float;
+ this.bot_exec_status |= BOT_EXEC_STATUS_WAITING;
return CMD_STATUS_EXECUTING;
}
-float bot_cmd_wait_until()
-{SELFPARAM();
+float bot_cmd_wait_until(entity this)
+{
if(time < bot_cmd.bot_cmd_parm_float + bot_barriertime)
{
- self.bot_exec_status |= BOT_EXEC_STATUS_WAITING;
+ this.bot_exec_status |= BOT_EXEC_STATUS_WAITING;
return CMD_STATUS_EXECUTING;
}
- self.bot_exec_status &= ~BOT_EXEC_STATUS_WAITING;
+ this.bot_exec_status &= ~BOT_EXEC_STATUS_WAITING;
return CMD_STATUS_FINISHED;
}
-float bot_cmd_barrier()
-{SELFPARAM();
+float bot_cmd_barrier(entity this)
+{
// 0 = no barrier, 1 = waiting, 2 = waiting finished
- if(self.bot_barrier == 0) // initialization
+ if(this.bot_barrier == 0) // initialization
{
- self.bot_barrier = 1;
+ this.bot_barrier = 1;
- //self.colormod = '4 4 0';
+ //this.colormod = '4 4 0';
}
- if(self.bot_barrier == 1) // find other bots
+ if(this.bot_barrier == 1) // find other bots
{
FOREACH_CLIENT(it.isbot, LAMBDA(
if(it.bot_cmdqueuebuf_allocated)
// if we get here, the barrier is finished
// so end it...
- self.bot_barrier = 0;
- //self.colormod = '0 0 0';
+ this.bot_barrier = 0;
+ //this.colormod = '0 0 0';
return CMD_STATUS_FINISHED;
}
-float bot_cmd_turn()
-{SELFPARAM();
- self.v_angle_y = self.v_angle.y + bot_cmd.bot_cmd_parm_float;
- self.v_angle_y = self.v_angle.y - floor(self.v_angle.y / 360) * 360;
+float bot_cmd_turn(entity this)
+{
+ this.v_angle_y = this.v_angle.y + bot_cmd.bot_cmd_parm_float;
+ this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360;
return CMD_STATUS_FINISHED;
}
-float bot_cmd_select_weapon()
-{SELFPARAM();
+float bot_cmd_select_weapon(entity this)
+{
float id = bot_cmd.bot_cmd_parm_float;
if(id < WEP_FIRST || id > WEP_LAST)
return CMD_STATUS_ERROR;
- if(client_hasweapon(self, Weapons_from(id), true, false))
- PS(self).m_switchweapon = Weapons_from(id);
+ if(client_hasweapon(this, Weapons_from(id), true, false))
+ PS(this).m_switchweapon = Weapons_from(id);
else
return CMD_STATUS_ERROR;
const int CMD_CONDITION_true_BLOCK = 4;
const int CMD_CONDITION_false_BLOCK = 8;
-float bot_cmd_eval(string expr)
-{SELFPARAM();
+float bot_cmd_eval(entity this, string expr)
+{
// Search for numbers
if(strstrofs("0123456789", substring(expr, 0, 1), 0) >= 0)
{
switch(expr)
{
case "health":
- return self.health;
+ return this.health;
case "speed":
- return vlen(self.velocity);
+ return vlen(this.velocity);
case "flagcarrier":
- return ((self.flagcarried!=world));
+ return ((this.flagcarried!=world));
}
LOG_INFO(strcat("ERROR: Unable to convert the expression '",expr,"' into a numeric value\n"));
return 0;
}
-float bot_cmd_if()
-{SELFPARAM();
+float bot_cmd_if(entity this)
+{
string expr, val_a, val_b;
float cmpofs;
- if(self.bot_cmd_condition_status != CMD_CONDITION_NONE)
+ if(this.bot_cmd_condition_status != CMD_CONDITION_NONE)
{
// Only one "if" block is allowed at time
LOG_INFO("ERROR: Only one conditional block can be processed at time");
- bot_clearqueue(self);
+ bot_clearqueue(this);
return CMD_STATUS_ERROR;
}
- self.bot_cmd_condition_status |= CMD_CONDITION_true_BLOCK;
+ this.bot_cmd_condition_status |= CMD_CONDITION_true_BLOCK;
// search for operators
expr = bot_cmd.bot_cmd_parm_string;
val_a = substring(expr,0,cmpofs);
val_b = substring(expr,cmpofs+1,strlen(expr));
- if(bot_cmd_eval(val_a)==bot_cmd_eval(val_b))
- self.bot_cmd_condition_status |= CMD_CONDITION_true;
+ if(bot_cmd_eval(this, val_a)==bot_cmd_eval(this, val_b))
+ this.bot_cmd_condition_status |= CMD_CONDITION_true;
else
- self.bot_cmd_condition_status |= CMD_CONDITION_false;
+ this.bot_cmd_condition_status |= CMD_CONDITION_false;
return CMD_STATUS_FINISHED;
}
val_a = substring(expr,0,cmpofs);
val_b = substring(expr,cmpofs+1,strlen(expr));
- if(bot_cmd_eval(val_a)>bot_cmd_eval(val_b))
- self.bot_cmd_condition_status |= CMD_CONDITION_true;
+ if(bot_cmd_eval(this, val_a)>bot_cmd_eval(this, val_b))
+ this.bot_cmd_condition_status |= CMD_CONDITION_true;
else
- self.bot_cmd_condition_status |= CMD_CONDITION_false;
+ this.bot_cmd_condition_status |= CMD_CONDITION_false;
return CMD_STATUS_FINISHED;
}
val_a = substring(expr,0,cmpofs);
val_b = substring(expr,cmpofs+1,strlen(expr));
- if(bot_cmd_eval(val_a)<bot_cmd_eval(val_b))
- self.bot_cmd_condition_status |= CMD_CONDITION_true;
+ if(bot_cmd_eval(this, val_a)<bot_cmd_eval(this, val_b))
+ this.bot_cmd_condition_status |= CMD_CONDITION_true;
else
- self.bot_cmd_condition_status |= CMD_CONDITION_false;
+ this.bot_cmd_condition_status |= CMD_CONDITION_false;
return CMD_STATUS_FINISHED;
}
- if(bot_cmd_eval(expr))
- self.bot_cmd_condition_status |= CMD_CONDITION_true;
+ if(bot_cmd_eval(this, expr))
+ this.bot_cmd_condition_status |= CMD_CONDITION_true;
else
- self.bot_cmd_condition_status |= CMD_CONDITION_false;
+ this.bot_cmd_condition_status |= CMD_CONDITION_false;
return CMD_STATUS_FINISHED;
}
-float bot_cmd_else()
-{SELFPARAM();
- self.bot_cmd_condition_status &= ~CMD_CONDITION_true_BLOCK;
- self.bot_cmd_condition_status |= CMD_CONDITION_false_BLOCK;
+float bot_cmd_else(entity this)
+{
+ this.bot_cmd_condition_status &= ~CMD_CONDITION_true_BLOCK;
+ this.bot_cmd_condition_status |= CMD_CONDITION_false_BLOCK;
return CMD_STATUS_FINISHED;
}
-float bot_cmd_fi()
-{SELFPARAM();
- self.bot_cmd_condition_status = CMD_CONDITION_NONE;
+float bot_cmd_fi(entity this)
+{
+ this.bot_cmd_condition_status = CMD_CONDITION_NONE;
return CMD_STATUS_FINISHED;
}
-float bot_cmd_resetaim()
-{SELFPARAM();
- self.v_angle = '0 0 0';
+float bot_cmd_resetaim(entity this)
+{
+ this.v_angle = '0 0 0';
return CMD_STATUS_FINISHED;
}
.vector bot_cmd_aim_begin;
.vector bot_cmd_aim_end;
-float bot_cmd_aim()
-{SELFPARAM();
+float bot_cmd_aim(entity this)
+{
// Current direction
- if(self.bot_cmd_aim_endtime)
+ if(this.bot_cmd_aim_endtime)
{
float progress;
- progress = min(1 - (self.bot_cmd_aim_endtime - time) / (self.bot_cmd_aim_endtime - self.bot_cmd_aim_begintime),1);
- self.v_angle = self.bot_cmd_aim_begin + ((self.bot_cmd_aim_end - self.bot_cmd_aim_begin) * progress);
+ progress = min(1 - (this.bot_cmd_aim_endtime - time) / (this.bot_cmd_aim_endtime - this.bot_cmd_aim_begintime),1);
+ this.v_angle = this.bot_cmd_aim_begin + ((this.bot_cmd_aim_end - this.bot_cmd_aim_begin) * progress);
- if(time>=self.bot_cmd_aim_endtime)
+ if(time>=this.bot_cmd_aim_endtime)
{
- self.bot_cmd_aim_endtime = 0;
+ this.bot_cmd_aim_endtime = 0;
return CMD_STATUS_FINISHED;
}
else
if(step == 0)
{
- self.v_angle_x -= stof(argv(1));
- self.v_angle_y += stof(argv(0));
+ this.v_angle_x -= stof(argv(1));
+ this.v_angle_y += stof(argv(0));
return CMD_STATUS_FINISHED;
}
- self.bot_cmd_aim_begin = self.v_angle;
+ this.bot_cmd_aim_begin = this.v_angle;
- self.bot_cmd_aim_end_x = self.v_angle.x - stof(argv(1));
- self.bot_cmd_aim_end_y = self.v_angle.y + stof(argv(0));
- self.bot_cmd_aim_end_z = 0;
+ this.bot_cmd_aim_end_x = this.v_angle.x - stof(argv(1));
+ this.bot_cmd_aim_end_y = this.v_angle.y + stof(argv(0));
+ this.bot_cmd_aim_end_z = 0;
- self.bot_cmd_aim_begintime = time;
- self.bot_cmd_aim_endtime = time + step;
+ this.bot_cmd_aim_begintime = time;
+ this.bot_cmd_aim_endtime = time + step;
return CMD_STATUS_EXECUTING;
}
-float bot_cmd_aimtarget()
-{SELFPARAM();
- if(self.bot_cmd_aim_endtime)
+float bot_cmd_aimtarget(entity this)
+{
+ if(this.bot_cmd_aim_endtime)
{
- return bot_cmd_aim();
+ return bot_cmd_aim(this);
}
entity e;
tokens = tokenizebyseparator(parms, " ");
- e = bot_getplace(argv(0));
+ e = bot_getplace(this, argv(0));
if(!e)
return CMD_STATUS_ERROR;
if(tokens==1)
{
- self.v_angle = vectoangles(v - (self.origin + self.view_ofs));
- self.v_angle_x = -self.v_angle.x;
+ this.v_angle = vectoangles(v - (this.origin + this.view_ofs));
+ this.v_angle_x = -this.v_angle.x;
return CMD_STATUS_FINISHED;
}
step = stof(argv(1));
- self.bot_cmd_aim_begin = self.v_angle;
- self.bot_cmd_aim_end = vectoangles(v - (self.origin + self.view_ofs));
- self.bot_cmd_aim_end_x = -self.bot_cmd_aim_end.x;
+ this.bot_cmd_aim_begin = this.v_angle;
+ this.bot_cmd_aim_end = vectoangles(v - (this.origin + this.view_ofs));
+ this.bot_cmd_aim_end_x = -this.bot_cmd_aim_end.x;
- self.bot_cmd_aim_begintime = time;
- self.bot_cmd_aim_endtime = time + step;
+ this.bot_cmd_aim_begintime = time;
+ this.bot_cmd_aim_endtime = time + step;
return CMD_STATUS_EXECUTING;
}
}
-float bot_cmd_keypress_handler(string key, float enabled)
-{SELFPARAM();
+float bot_cmd_keypress_handler(entity this, string key, float enabled)
+{
switch(key)
{
case "all":
if(enabled)
- self.bot_cmd_keys = power2of(20) - 1; // >:)
+ this.bot_cmd_keys = power2of(20) - 1; // >:)
else
- self.bot_cmd_keys = BOT_CMD_KEY_NONE;
+ this.bot_cmd_keys = BOT_CMD_KEY_NONE;
case "forward":
if(enabled)
{
- self.bot_cmd_keys |= BOT_CMD_KEY_FORWARD;
- self.bot_cmd_keys &= ~BOT_CMD_KEY_BACKWARD;
+ this.bot_cmd_keys |= BOT_CMD_KEY_FORWARD;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_BACKWARD;
}
else
- self.bot_cmd_keys &= ~BOT_CMD_KEY_FORWARD;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_FORWARD;
break;
case "backward":
if(enabled)
{
- self.bot_cmd_keys |= BOT_CMD_KEY_BACKWARD;
- self.bot_cmd_keys &= ~BOT_CMD_KEY_FORWARD;
+ this.bot_cmd_keys |= BOT_CMD_KEY_BACKWARD;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_FORWARD;
}
else
- self.bot_cmd_keys &= ~BOT_CMD_KEY_BACKWARD;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_BACKWARD;
break;
case "left":
if(enabled)
{
- self.bot_cmd_keys |= BOT_CMD_KEY_LEFT;
- self.bot_cmd_keys &= ~BOT_CMD_KEY_RIGHT;
+ this.bot_cmd_keys |= BOT_CMD_KEY_LEFT;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_RIGHT;
}
else
- self.bot_cmd_keys &= ~BOT_CMD_KEY_LEFT;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_LEFT;
break;
case "right":
if(enabled)
{
- self.bot_cmd_keys |= BOT_CMD_KEY_RIGHT;
- self.bot_cmd_keys &= ~BOT_CMD_KEY_LEFT;
+ this.bot_cmd_keys |= BOT_CMD_KEY_RIGHT;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_LEFT;
}
else
- self.bot_cmd_keys &= ~BOT_CMD_KEY_RIGHT;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_RIGHT;
break;
case "jump":
if(enabled)
- self.bot_cmd_keys |= BOT_CMD_KEY_JUMP;
+ this.bot_cmd_keys |= BOT_CMD_KEY_JUMP;
else
- self.bot_cmd_keys &= ~BOT_CMD_KEY_JUMP;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_JUMP;
break;
case "crouch":
if(enabled)
- self.bot_cmd_keys |= BOT_CMD_KEY_CROUCH;
+ this.bot_cmd_keys |= BOT_CMD_KEY_CROUCH;
else
- self.bot_cmd_keys &= ~BOT_CMD_KEY_CROUCH;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_CROUCH;
break;
case "attack1":
if(enabled)
- self.bot_cmd_keys |= BOT_CMD_KEY_ATTACK1;
+ this.bot_cmd_keys |= BOT_CMD_KEY_ATTACK1;
else
- self.bot_cmd_keys &= ~BOT_CMD_KEY_ATTACK1;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_ATTACK1;
break;
case "attack2":
if(enabled)
- self.bot_cmd_keys |= BOT_CMD_KEY_ATTACK2;
+ this.bot_cmd_keys |= BOT_CMD_KEY_ATTACK2;
else
- self.bot_cmd_keys &= ~BOT_CMD_KEY_ATTACK2;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_ATTACK2;
break;
case "use":
if(enabled)
- self.bot_cmd_keys |= BOT_CMD_KEY_USE;
+ this.bot_cmd_keys |= BOT_CMD_KEY_USE;
else
- self.bot_cmd_keys &= ~BOT_CMD_KEY_USE;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_USE;
break;
case "hook":
if(enabled)
- self.bot_cmd_keys |= BOT_CMD_KEY_HOOK;
+ this.bot_cmd_keys |= BOT_CMD_KEY_HOOK;
else
- self.bot_cmd_keys &= ~BOT_CMD_KEY_HOOK;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_HOOK;
break;
case "chat":
if(enabled)
- self.bot_cmd_keys |= BOT_CMD_KEY_CHAT;
+ this.bot_cmd_keys |= BOT_CMD_KEY_CHAT;
else
- self.bot_cmd_keys &= ~BOT_CMD_KEY_CHAT;
+ this.bot_cmd_keys &= ~BOT_CMD_KEY_CHAT;
break;
default:
break;
return CMD_STATUS_FINISHED;
}
-float bot_cmd_presskey()
+float bot_cmd_presskey(entity this)
{
string key;
key = bot_cmd.bot_cmd_parm_string;
- bot_cmd_keypress_handler(key,true);
+ bot_cmd_keypress_handler(this, key,true);
return CMD_STATUS_FINISHED;
}
-float bot_cmd_releasekey()
+float bot_cmd_releasekey(entity this)
{
string key;
key = bot_cmd.bot_cmd_parm_string;
- return bot_cmd_keypress_handler(key,false);
+ return bot_cmd_keypress_handler(this, key,false);
}
-float bot_cmd_pause()
-{SELFPARAM();
- PHYS_INPUT_BUTTON_DRAG(self) = false;
- PHYS_INPUT_BUTTON_USE(self) = false;
- PHYS_INPUT_BUTTON_ATCK(self) = false;
- PHYS_INPUT_BUTTON_JUMP(self) = false;
- PHYS_INPUT_BUTTON_HOOK(self) = false;
- PHYS_INPUT_BUTTON_CHAT(self) = false;
- PHYS_INPUT_BUTTON_ATCK2(self) = false;
- PHYS_INPUT_BUTTON_CROUCH(self) = false;
-
- self.movement = '0 0 0';
- self.bot_cmd_keys = BOT_CMD_KEY_NONE;
-
- self.bot_exec_status |= BOT_EXEC_STATUS_PAUSED;
+float bot_cmd_pause(entity this)
+{
+ PHYS_INPUT_BUTTON_DRAG(this) = false;
+ PHYS_INPUT_BUTTON_USE(this) = false;
+ PHYS_INPUT_BUTTON_ATCK(this) = false;
+ PHYS_INPUT_BUTTON_JUMP(this) = false;
+ PHYS_INPUT_BUTTON_HOOK(this) = false;
+ PHYS_INPUT_BUTTON_CHAT(this) = false;
+ PHYS_INPUT_BUTTON_ATCK2(this) = false;
+ PHYS_INPUT_BUTTON_CROUCH(this) = false;
+
+ this.movement = '0 0 0';
+ this.bot_cmd_keys = BOT_CMD_KEY_NONE;
+
+ this.bot_exec_status |= BOT_EXEC_STATUS_PAUSED;
return CMD_STATUS_FINISHED;
}
-float bot_cmd_moveto()
-{SELFPARAM();
- return self.cmd_moveto(bot_cmd.bot_cmd_parm_vector);
+float bot_cmd_moveto(entity this)
+{
+ return this.cmd_moveto(this, bot_cmd.bot_cmd_parm_vector);
}
-float bot_cmd_movetotarget()
-{SELFPARAM();
+float bot_cmd_movetotarget(entity this)
+{
entity e;
- e = bot_getplace(bot_cmd.bot_cmd_parm_string);
+ e = bot_getplace(this, bot_cmd.bot_cmd_parm_string);
if(!e)
return CMD_STATUS_ERROR;
- return self.cmd_moveto(e.origin + (e.mins + e.maxs) * 0.5);
+ return this.cmd_moveto(this, e.origin + (e.mins + e.maxs) * 0.5);
}
-float bot_cmd_resetgoal()
-{SELFPARAM();
- return self.cmd_resetgoal();
+float bot_cmd_resetgoal(entity this)
+{
+ return this.cmd_resetgoal(this);
}
-float bot_cmd_sound()
-{SELFPARAM();
+float bot_cmd_sound(entity this)
+{
string f;
f = bot_cmd.bot_cmd_parm_string;
atten = stof(argv(2));
precache_sound(f);
- _sound(self, chan, sample, vol, atten);
+ _sound(this, chan, sample, vol, atten);
return CMD_STATUS_FINISHED;
}
.entity tuba_note;
-float bot_cmd_debug_assert_canfire()
-{SELFPARAM();
+float bot_cmd_debug_assert_canfire(entity this)
+{
float f = bot_cmd.bot_cmd_parm_float;
int slot = 0;
.entity weaponentity = weaponentities[slot];
- if(self.(weaponentity).state != WS_READY)
+ if(this.(weaponentity).state != WS_READY)
{
if(f)
{
- self.colormod = '0 8 8';
- LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " wants to fire, inhibited by weaponentity state\n");
+ this.colormod = '0 8 8';
+ LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " wants to fire, inhibited by weaponentity state\n");
}
}
- else if(ATTACK_FINISHED(self, slot) > time)
+ else if(ATTACK_FINISHED(this, slot) > time)
{
if(f)
{
- self.colormod = '8 0 8';
- LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " wants to fire, inhibited by ATTACK_FINISHED (", ftos(ATTACK_FINISHED(self, slot) - time), " seconds left)\n");
+ this.colormod = '8 0 8';
+ LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " wants to fire, inhibited by ATTACK_FINISHED (", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left)\n");
}
}
- else if(self.tuba_note)
+ else if(this.tuba_note)
{
if(f)
{
- self.colormod = '8 0 0';
- LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " wants to fire, bot still has an active tuba note\n");
+ this.colormod = '8 0 0';
+ LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " wants to fire, bot still has an active tuba note\n");
}
}
else
{
if(!f)
{
- self.colormod = '8 8 0';
- LOG_INFO("Bot ", self.netname, " using ", self.weaponname, " thinks it has fired, but apparently did not; ATTACK_FINISHED says ", ftos(ATTACK_FINISHED(self, slot) - time), " seconds left\n");
+ this.colormod = '8 8 0';
+ LOG_INFO("Bot ", this.netname, " using ", this.weaponname, " thinks it has fired, but apparently did not; ATTACK_FINISHED says ", ftos(ATTACK_FINISHED(this, slot) - time), " seconds left\n");
}
}
//
-void bot_command_executed(float rm)
-{SELFPARAM();
+void bot_command_executed(entity this, bool rm)
+{
entity cmd;
cmd = bot_cmd;
if(rm)
- bot_dequeuecommand(self, self.bot_cmd_execution_index);
+ bot_dequeuecommand(this, this.bot_cmd_execution_index);
- self.bot_cmd_execution_index++;
+ this.bot_cmd_execution_index++;
}
-void bot_setcurrentcommand()
-{SELFPARAM();
+void bot_setcurrentcommand(entity this)
+{
bot_cmd = world;
- if(!self.bot_cmd_current)
+ if(!this.bot_cmd_current)
{
- self.bot_cmd_current = new_pure(bot_cmd);
- self.bot_cmd_current.is_bot_cmd = true;
+ this.bot_cmd_current = new_pure(bot_cmd);
+ this.bot_cmd_current.is_bot_cmd = true;
}
- bot_cmd = self.bot_cmd_current;
- if(bot_cmd.bot_cmd_index != self.bot_cmd_execution_index || self.bot_cmd_execution_index == 0)
+ bot_cmd = this.bot_cmd_current;
+ if(bot_cmd.bot_cmd_index != this.bot_cmd_execution_index || this.bot_cmd_execution_index == 0)
{
- if(bot_havecommand(self, self.bot_cmd_execution_index))
+ if(bot_havecommand(this, this.bot_cmd_execution_index))
{
string cmdstring;
- cmdstring = bot_readcommand(self, self.bot_cmd_execution_index);
+ cmdstring = bot_readcommand(this, this.bot_cmd_execution_index);
if(bot_decodecommand(cmdstring))
{
- bot_cmd.owner = self;
- bot_cmd.bot_cmd_index = self.bot_cmd_execution_index;
+ bot_cmd.owner = this;
+ bot_cmd.bot_cmd_index = this.bot_cmd_execution_index;
}
else
{
// Invalid command, remove from queue
bot_cmd = world;
- bot_dequeuecommand(self, self.bot_cmd_execution_index);
- self.bot_cmd_execution_index++;
+ bot_dequeuecommand(this, this.bot_cmd_execution_index);
+ this.bot_cmd_execution_index++;
}
}
else
// Here we map commands to functions and deal with complex interactions between commands and execution states
// NOTE: Of course you need to include your commands here too :)
-float bot_execute_commands_once()
-{SELFPARAM();
+float bot_execute_commands_once(entity this)
+{
float status, ispressingkey;
// Find command
- bot_setcurrentcommand();
+ bot_setcurrentcommand(this);
// if we have no bot command, better return
// old logic kept pressing previously pressed keys, but that has problems
return false;
// Ignore all commands except continue when the bot is paused
- if(self.bot_exec_status & BOT_EXEC_STATUS_PAUSED)
+ if(this.bot_exec_status & BOT_EXEC_STATUS_PAUSED)
if(bot_cmd.bot_cmd_type!=BOT_CMD_CONTINUE)
{
if(bot_cmd.bot_cmd_type!=BOT_CMD_NULL)
{
- bot_command_executed(true);
+ bot_command_executed(this, true);
LOG_INFO( "WARNING: Commands are ignored while the bot is paused. Use the command 'continue' instead.\n");
}
return 1;
// Handle conditions
if (!(bot_cmd.bot_cmd_type==BOT_CMD_FI||bot_cmd.bot_cmd_type==BOT_CMD_ELSE))
- if(self.bot_cmd_condition_status & CMD_CONDITION_true && self.bot_cmd_condition_status & CMD_CONDITION_false_BLOCK)
+ if(this.bot_cmd_condition_status & CMD_CONDITION_true && this.bot_cmd_condition_status & CMD_CONDITION_false_BLOCK)
{
- bot_command_executed(true);
+ bot_command_executed(this, true);
return -1;
}
- else if(self.bot_cmd_condition_status & CMD_CONDITION_false && self.bot_cmd_condition_status & CMD_CONDITION_true_BLOCK)
+ else if(this.bot_cmd_condition_status & CMD_CONDITION_false && this.bot_cmd_condition_status & CMD_CONDITION_true_BLOCK)
{
- bot_command_executed(true);
+ bot_command_executed(this, true);
return -1;
}
return ispressingkey;
//break;
case BOT_CMD_PAUSE:
- status = bot_cmd_pause();
+ status = bot_cmd_pause(this);
break;
case BOT_CMD_CONTINUE:
- status = bot_cmd_continue();
+ status = bot_cmd_continue(this);
break;
case BOT_CMD_WAIT:
- status = bot_cmd_wait();
+ status = bot_cmd_wait(this);
break;
case BOT_CMD_WAIT_UNTIL:
- status = bot_cmd_wait_until();
+ status = bot_cmd_wait_until(this);
break;
case BOT_CMD_TURN:
- status = bot_cmd_turn();
+ status = bot_cmd_turn(this);
break;
case BOT_CMD_MOVETO:
- status = bot_cmd_moveto();
+ status = bot_cmd_moveto(this);
break;
case BOT_CMD_MOVETOTARGET:
- status = bot_cmd_movetotarget();
+ status = bot_cmd_movetotarget(this);
break;
case BOT_CMD_RESETGOAL:
- status = bot_cmd_resetgoal();
+ status = bot_cmd_resetgoal(this);
break;
case BOT_CMD_CC:
- status = bot_cmd_cc();
+ status = bot_cmd_cc(this);
break;
case BOT_CMD_IF:
- status = bot_cmd_if();
+ status = bot_cmd_if(this);
break;
case BOT_CMD_ELSE:
- status = bot_cmd_else();
+ status = bot_cmd_else(this);
break;
case BOT_CMD_FI:
- status = bot_cmd_fi();
+ status = bot_cmd_fi(this);
break;
case BOT_CMD_RESETAIM:
- status = bot_cmd_resetaim();
+ status = bot_cmd_resetaim(this);
break;
case BOT_CMD_AIM:
- status = bot_cmd_aim();
+ status = bot_cmd_aim(this);
break;
case BOT_CMD_AIMTARGET:
- status = bot_cmd_aimtarget();
+ status = bot_cmd_aimtarget(this);
break;
case BOT_CMD_PRESSKEY:
- status = bot_cmd_presskey();
+ status = bot_cmd_presskey(this);
break;
case BOT_CMD_RELEASEKEY:
- status = bot_cmd_releasekey();
+ status = bot_cmd_releasekey(this);
break;
case BOT_CMD_SELECTWEAPON:
- status = bot_cmd_select_weapon();
+ status = bot_cmd_select_weapon(this);
break;
case BOT_CMD_IMPULSE:
- status = bot_cmd_impulse();
+ status = bot_cmd_impulse(this);
break;
case BOT_CMD_BARRIER:
- status = bot_cmd_barrier();
+ status = bot_cmd_barrier(this);
break;
case BOT_CMD_CONSOLE:
localcmd(strcat(bot_cmd.bot_cmd_parm_string, "\n"));
status = CMD_STATUS_FINISHED;
break;
case BOT_CMD_SOUND:
- status = bot_cmd_sound();
+ status = bot_cmd_sound(this);
break;
case BOT_CMD_DEBUG_ASSERT_CANFIRE:
- status = bot_cmd_debug_assert_canfire();
+ status = bot_cmd_debug_assert_canfire(this);
break;
default:
LOG_INFO(strcat("ERROR: Invalid command on queue with id '",ftos(bot_cmd.bot_cmd_type),"'\n"));
parms = "";
break;
}
- clientcommand(self,strcat("say ^7", bot_cmd_string[bot_cmd.bot_cmd_type]," ",parms,"\n"));
+ clientcommand(this,strcat("say ^7", bot_cmd_string[bot_cmd.bot_cmd_type]," ",parms,"\n"));
}
- bot_command_executed(true);
+ bot_command_executed(this, true);
}
if(status == CMD_STATUS_FINISHED)
}
// This function should be (the only) called directly from the bot ai loop
-float bot_execute_commands()
+int bot_execute_commands(entity this)
{
- float f;
+ int f;
do
{
- f = bot_execute_commands_once();
+ f = bot_execute_commands_once(this);
}
while(f < 0);
return f;
// NOTE: Following commands should be implemented on the bot ai
// If a new command should be handled by the target ai(s) please declare it here
-.float(vector) cmd_moveto;
-.float() cmd_resetgoal;
+.float(entity, vector) cmd_moveto;
+.float(entity) cmd_resetgoal;
//
const int BOT_CMD_PARAMETER_NONE = 0;
void bot_queuecommand(entity bot, string cmdstring);
void bot_cmdhelp(string scmd);
void bot_list_commands();
-float bot_execute_commands();
+float bot_execute_commands(entity this);
entity find_bot_by_name(string name);
entity find_bot_by_number(float number);
waypoint_spawnforteleporter_boxes(e, e.absmin, e.absmax, destination, destination, timetaken);
}
-entity waypoint_spawnpersonal(vector position)
-{SELFPARAM();
+entity waypoint_spawnpersonal(entity this, vector position)
+{
entity w;
// drop the waypoint to a proper location:
w = waypoint_spawn(position, position, WAYPOINTFLAG_GENERATED | WAYPOINTFLAG_PERSONAL);
w.nearestwaypoint = world;
w.nearestwaypointtimeout = 0;
- w.owner = self;
+ w.owner = this;
waypoint_schedulerelink(w);
float waypoint_load_links();
entity waypoint_spawn(vector m1, vector m2, float f);
-entity waypoint_spawnpersonal(vector position);
+entity waypoint_spawnpersonal(entity this, vector position);
vector waypoint_fixorigin(vector position);
/** called when a bot checks a target to attack */
#define EV_BotShouldAttack(i, o) \
+ /**/ i(entity, __self) \
/**/ i(entity, checkentity) \
/**/
entity checkentity;