// Find and rate waypoints around it
found = false;
entity best = NULL;
- float bestvalue = 99999999999;
+ float bestvalue = FLOAT_MAX;
entity des = it;
- for(float radius = 0; radius < 1500 && !found; radius += 500)
+ for (float radius = 500; radius <= 1500 && !found; radius += 500)
{
FOREACH_ENTITY_RADIUS(p, radius, it.classname == "waypoint" && !(it.wpflags & WAYPOINTFLAG_GENERATED),
{
if (navigation_goalrating_timeout(this))
{
+ // role: offense
navigation_goalrating_start(this);
- havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
+ havocbot_goalrating_enemyplayers(this, 10000, this.origin, 650);
havocbot_goalrating_ast_targets(this, 20000);
- havocbot_goalrating_items(this, 15000, this.origin, 10000);
+ havocbot_goalrating_items(this, 30000, this.origin, 10000);
navigation_goalrating_end(this);
navigation_goalrating_timeout_set(this);
if (navigation_goalrating_timeout(this))
{
+ // role: defense
navigation_goalrating_start(this);
- havocbot_goalrating_enemyplayers(this, 20000, this.origin, 3000);
+ havocbot_goalrating_enemyplayers(this, 10000, this.origin, 3000);
havocbot_goalrating_ast_targets(this, 20000);
- havocbot_goalrating_items(this, 15000, this.origin, 10000);
+ havocbot_goalrating_items(this, 30000, this.origin, 10000);
navigation_goalrating_end(this);
navigation_goalrating_timeout_set(this);
{
case HAVOCBOT_AST_ROLE_DEFENSE:
this.havocbot_role = havocbot_role_ast_defense;
- this.havocbot_role_flags = HAVOCBOT_AST_ROLE_DEFENSE;
this.havocbot_role_timeout = 0;
break;
case HAVOCBOT_AST_ROLE_OFFENSE:
this.havocbot_role = havocbot_role_ast_offense;
- this.havocbot_role_flags = HAVOCBOT_AST_ROLE_OFFENSE;
this.havocbot_role_timeout = 0;
break;
}
const int HAVOCBOT_AST_ROLE_DEFENSE = 2;
const int HAVOCBOT_AST_ROLE_OFFENSE = 4;
-.int havocbot_role_flags;
.float havocbot_attack_time;
void(entity this) havocbot_role_ast_defense;
flag.solid = SOLID_TRIGGER;
flag.ctf_dropper = player;
flag.ctf_droptime = time;
- navigation_dynamicgoal_set(flag);
flag.flags = FL_ITEM | FL_NOTARGET; // clear FL_ONGROUND for MOVETYPE_TOSS
flag_velocity = (('0 0 1' * autocvar_g_ctf_throw_velocity_up) + ((v_forward * autocvar_g_ctf_throw_velocity_forward) * ((player.items & ITEM_Strength.m_itemid) ? autocvar_g_ctf_throw_strengthmultiplier : 1)));
flag.velocity = W_CalculateProjectileVelocity(player, player.velocity, flag_velocity, false);
ctf_Handle_Drop(flag, player, droptype);
+ navigation_dynamicgoal_set(flag, player);
break;
}
{
flag.velocity = W_CalculateProjectileVelocity(player, player.velocity, (('0 0 1' * autocvar_g_ctf_drop_velocity_up) + ((('0 1 0' * crandom()) + ('1 0 0' * crandom())) * autocvar_g_ctf_drop_velocity_side)), false);
ctf_Handle_Drop(flag, player, droptype);
+ navigation_dynamicgoal_set(flag, player);
break;
}
}
head = head.ctf_worldflagnext;
}
if (head)
+ {
+ if (head.ctf_status == FLAG_CARRY)
+ {
+ // adjust rating of our flag carrier depending on his health
+ head = head.tag_entity;
+ float f = bound(0, (head.health + head.armorvalue) / 100, 2) - 1;
+ ratingscale += ratingscale * f * 0.1;
+ }
navigation_routerating(this, head, ratingscale, 10000);
+ }
}
void havocbot_goalrating_ctf_enemybase(entity this, float ratingscale)
{
+ // disabled because we always spawn waypoints for flags with waypoint_spawnforitem_force
+ /*
if (!bot_waypoints_for_items)
{
havocbot_goalrating_ctf_enemyflag(this, ratingscale);
return;
}
-
+ */
entity head;
head = havocbot_ctf_find_enemy_flag(this);
}
}
-void havocbot_goalrating_ctf_carrieritems(entity this, float ratingscale, vector org, float sradius)
-{
- IL_EACH(g_items, it.bot_pickup,
- {
- // gather health and armor only
- if (it.solid)
- if (GetResourceAmount(it, RESOURCE_HEALTH) || GetResourceAmount(it, RESOURCE_ARMOR))
- if (vdist(it.origin - org, <, sradius))
- {
- // get the value of the item
- float t = it.bot_pickupevalfunc(this, it) * 0.0001;
- if (t > 0)
- navigation_routerating(this, it, t * ratingscale, 500);
- }
- });
-}
-
void havocbot_ctf_reset_role(entity this)
{
float cdefense, cmiddle, coffense;
entity mf, ef;
- float c;
if(IS_DEAD(this))
return;
return;
}
- // if there is only me on the team switch to offense
- c = 0;
- FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, this), { ++c; });
+ // if there is no one else on the team switch to offense
+ int count = 0;
+ // don't check if this bot is a player since it isn't true when the bot is added to the server
+ FOREACH_CLIENT(it != this && IS_PLAYER(it) && SAME_TEAM(it, this), { ++count; });
- if(c==1)
+ if (count == 0)
{
havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_OFFENSE);
return;
}
+ else if (time < CS(this).jointime + 1)
+ {
+ // if bots spawn all at once set good default roles
+ if (count == 1)
+ {
+ havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_DEFENSE);
+ return;
+ }
+ else if (count == 2)
+ {
+ havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_MIDDLE);
+ return;
+ }
+ }
// Evaluate best position to take
// Count mates on middle position
havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_OFFENSE);
else
havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_MIDDLE);
+
+ // if bots spawn all at once assign them a more appropriated role after a while
+ if (time < CS(this).jointime + 1 && count > 2)
+ this.havocbot_role_timeout = time + 10 + random() * 10;
+}
+
+bool havocbot_ctf_is_basewaypoint(entity item)
+{
+ if (item.classname != "waypoint")
+ return false;
+
+ entity head = ctf_worldflaglist;
+ while (head)
+ {
+ if (item == head.bot_basewaypoint)
+ return true;
+ head = head.ctf_worldflagnext;
+ }
+ return false;
}
void havocbot_role_ctf_carrier(entity this)
{
navigation_goalrating_start(this);
+ // role: carrier
+ entity mf = havocbot_ctf_find_flag(this);
+ vector base_org = mf.dropped_origin;
+ float base_rating = (mf.ctf_status == FLAG_BASE) ? 10000 : (vdist(this.origin - base_org, >, 100) ? 2000 : 1000);
if(ctf_oneflag)
- havocbot_goalrating_ctf_enemybase(this, 50000);
+ havocbot_goalrating_ctf_enemybase(this, base_rating);
else
- havocbot_goalrating_ctf_ourbase(this, 50000);
+ havocbot_goalrating_ctf_ourbase(this, base_rating);
+
+ // start collecting items very close to the bot but only inside of own base radius
+ if (vdist(this.origin - base_org, <, havocbot_middlepoint_radius))
+ havocbot_goalrating_items(this, 15000, this.origin, min(500, havocbot_middlepoint_radius * 0.5));
- if(GetResourceAmount(this, RESOURCE_HEALTH) < 100)
- havocbot_goalrating_ctf_carrieritems(this, 1000, this.origin, 1000);
+ havocbot_goalrating_items(this, 10000, base_org, havocbot_middlepoint_radius * 0.5);
navigation_goalrating_end(this);
navigation_goalrating_timeout_set(this);
- entity head = ctf_worldflaglist;
- while (head)
- {
- if (this.goalentity == head.bot_basewaypoint)
- {
- this.goalentity_lock_timeout = time + 5;
- break;
- }
- head = head.ctf_worldflagnext;
- }
+ entity goal = this.goalentity;
+ if (havocbot_ctf_is_basewaypoint(goal) && vdist(goal.origin - this.origin, <, 100))
+ this.goalentity_lock_timeout = time + ((this.bot_aimtarg) ? 2 : 3);
- if (this.goalentity)
+ if (goal)
this.havocbot_cantfindflag = time + 10;
else if (time > this.havocbot_cantfindflag)
{
this.havocbot_role_timeout = 0;
return;
}
+ if (ef.ctf_status == FLAG_DROPPED)
+ {
+ navigation_goalrating_timeout_expire(this, 1);
+ return;
+ }
// If the flag carrier reached the base switch to defense
mf = havocbot_ctf_find_flag(this);
- if(mf.ctf_status!=FLAG_BASE)
- if(vdist(ef.origin - mf.dropped_origin, <, 300))
+ if (mf.ctf_status != FLAG_BASE && vdist(ef.origin - mf.dropped_origin, <, 900))
{
havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_DEFENSE);
return;
{
navigation_goalrating_start(this);
- havocbot_goalrating_ctf_enemyflag(this, 30000);
- havocbot_goalrating_ctf_ourstolenflag(this, 40000);
- havocbot_goalrating_items(this, 10000, this.origin, 10000);
+ // role: escort
+ havocbot_goalrating_ctf_enemyflag(this, 10000);
+ havocbot_goalrating_ctf_ourstolenflag(this, 6000);
+ havocbot_goalrating_items(this, 21000, this.origin, 10000);
navigation_goalrating_end(this);
}
}
- // About to fail, switch to middlefield
- if(GetResourceAmount(this, RESOURCE_HEALTH) < 50)
- {
- havocbot_role_ctf_setrole(this, HAVOCBOT_CTF_ROLE_MIDDLE);
- return;
- }
-
// Set the role timeout if necessary
if (!this.havocbot_role_timeout)
this.havocbot_role_timeout = time + 120;
{
navigation_goalrating_start(this);
- havocbot_goalrating_ctf_ourstolenflag(this, 50000);
- havocbot_goalrating_ctf_enemybase(this, 20000);
- havocbot_goalrating_items(this, 5000, this.origin, 1000);
- havocbot_goalrating_items(this, 1000, this.origin, 10000);
+ // role: offense
+ havocbot_goalrating_ctf_ourstolenflag(this, 10000);
+ havocbot_goalrating_ctf_enemybase(this, 10000);
+ havocbot_goalrating_items(this, 22000, this.origin, 10000);
navigation_goalrating_end(this);
if (navigation_goalrating_timeout(this))
{
- float rt_radius;
- rt_radius = 10000;
+ const float RT_RADIUS = 10000;
navigation_goalrating_start(this);
- havocbot_goalrating_ctf_ourstolenflag(this, 50000);
- havocbot_goalrating_ctf_droppedflags(this, 40000, this.origin, rt_radius);
- havocbot_goalrating_ctf_enemybase(this, 30000);
- havocbot_goalrating_items(this, 500, this.origin, rt_radius);
+ // role: retriever
+ havocbot_goalrating_ctf_ourstolenflag(this, 10000);
+ havocbot_goalrating_ctf_droppedflags(this, 12000, this.origin, RT_RADIUS);
+ havocbot_goalrating_ctf_enemybase(this, 8000);
+ entity ef = havocbot_ctf_find_enemy_flag(this);
+ vector enemy_base_org = ef.dropped_origin;
+ // start collecting items very close to the bot but only inside of enemy base radius
+ if (vdist(this.origin - enemy_base_org, <, havocbot_middlepoint_radius))
+ havocbot_goalrating_items(this, 27000, this.origin, min(500, havocbot_middlepoint_radius * 0.5));
+ havocbot_goalrating_items(this, 18000, this.origin, havocbot_middlepoint_radius);
navigation_goalrating_end(this);
navigation_goalrating_start(this);
- havocbot_goalrating_ctf_ourstolenflag(this, 50000);
- havocbot_goalrating_ctf_droppedflags(this, 30000, this.origin, 10000);
- havocbot_goalrating_enemyplayers(this, 10000, org, havocbot_middlepoint_radius * 0.5);
- havocbot_goalrating_items(this, 5000, org, havocbot_middlepoint_radius * 0.5);
- havocbot_goalrating_items(this, 2500, this.origin, 10000);
- havocbot_goalrating_ctf_enemybase(this, 2500);
+ // role: middle
+ havocbot_goalrating_ctf_ourstolenflag(this, 8000);
+ havocbot_goalrating_ctf_droppedflags(this, 9000, this.origin, 10000);
+ havocbot_goalrating_enemyplayers(this, 25000, org, havocbot_middlepoint_radius * 0.5);
+ havocbot_goalrating_items(this, 25000, org, havocbot_middlepoint_radius * 0.5);
+ havocbot_goalrating_items(this, 18000, this.origin, 10000);
+ havocbot_goalrating_ctf_enemybase(this, 3000);
navigation_goalrating_end(this);
+ entity goal = this.goalentity;
+ if (havocbot_ctf_is_basewaypoint(goal) && vdist(goal.origin - this.origin, <, 100))
+ this.goalentity_lock_timeout = time + 2;
+
navigation_goalrating_timeout_set(this);
}
}
}
});
+ // role: defense
if(closestplayer)
if(DIFF_TEAM(closestplayer, this))
if(vdist(org - this.origin, >, 1000))
if(checkpvs(this.origin,closestplayer)||random()<0.5)
- havocbot_goalrating_ctf_ourbase(this, 30000);
+ havocbot_goalrating_ctf_ourbase(this, 10000);
- havocbot_goalrating_ctf_ourstolenflag(this, 20000);
- havocbot_goalrating_ctf_droppedflags(this, 20000, org, havocbot_middlepoint_radius);
- havocbot_goalrating_enemyplayers(this, 15000, org, havocbot_middlepoint_radius);
- havocbot_goalrating_items(this, 10000, org, havocbot_middlepoint_radius);
- havocbot_goalrating_items(this, 5000, this.origin, 10000);
+ havocbot_goalrating_ctf_ourstolenflag(this, 5000);
+ havocbot_goalrating_ctf_droppedflags(this, 6000, org, havocbot_middlepoint_radius);
+ havocbot_goalrating_enemyplayers(this, 25000, org, havocbot_middlepoint_radius);
+ havocbot_goalrating_items(this, 25000, org, havocbot_middlepoint_radius);
+ havocbot_goalrating_items(this, 18000, this.origin, 10000);
navigation_goalrating_end(this);
if(it.cnt > -1) // this is just being fought
navigation_routerating(this, it, ratingscale, 5000);
else if(it.goalentity.cnt == 0) // unclaimed
- navigation_routerating(this, it, ratingscale * 0.5, 5000);
+ navigation_routerating(this, it, ratingscale, 5000);
else if(it.goalentity.team != this.team) // other team's point
- navigation_routerating(this, it, ratingscale * 0.2, 5000);
+ navigation_routerating(this, it, ratingscale, 5000);
});
}
{
navigation_goalrating_start(this);
havocbot_goalrating_controlpoints(this, 10000, this.origin, 15000);
- havocbot_goalrating_items(this, 8000, this.origin, 8000);
- //havocbot_goalrating_enemyplayers(this, 3000, this.origin, 2000);
+ havocbot_goalrating_items(this, 20000, this.origin, 8000);
+ //havocbot_goalrating_enemyplayers(this, 1500, this.origin, 2000);
havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
navigation_goalrating_end(this);
void(entity this) havocbot_role_ft_freeing;
void(entity this) havocbot_role_ft_offense;
-void havocbot_goalrating_freeplayers(entity this, float ratingscale, vector org, float sradius)
+void havocbot_goalrating_ft_freeplayers(entity this, float ratingscale, vector org, float sradius)
{
- float t;
+ entity best_pl = NULL;
+ float best_dist2 = FLOAT_MAX;
FOREACH_CLIENT(IS_PLAYER(it) && it != this && SAME_TEAM(it, this), {
if (STAT(FROZEN, it) == 1)
{
continue;
navigation_routerating(this, it, ratingscale, 2000);
}
- else if(vdist(it.origin - org, >, 400)) // avoid gathering all teammates in one place
+ else if (best_dist2
+ && GetResourceAmount(it, RESOURCE_HEALTH) < GetResourceAmount(this, RESOURCE_HEALTH) + 30
+ && vlen2(it.origin - org) < best_dist2)
{
// If teamate is not frozen still seek them out as fight better
// in a group.
- t = 0.2 * 150 / (GetResourceAmount(this, RESOURCE_HEALTH) + GetResourceAmount(this, RESOURCE_ARMOR));
- navigation_routerating(this, it, t * ratingscale, 2000);
+ best_dist2 = vlen2(it.origin - org);
+ if (best_dist2 < 700 ** 2)
+ {
+ best_pl = NULL;
+ best_dist2 = 0; // already close to a teammate
+ }
+ else
+ best_pl = it;
}
});
+ if (best_pl)
+ navigation_routerating(this, best_pl, ratingscale / 2, 2000);
}
void havocbot_role_ft_offense(entity this)
// Count how many players on team are unfrozen.
int unfrozen = 0;
- FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, this) && !(STAT(FROZEN, it) != 1), { unfrozen++; });
+ FOREACH_CLIENT(IS_PLAYER(it) && SAME_TEAM(it, this) && !STAT(FROZEN, it), { unfrozen++; });
// If only one left on team or if role has timed out then start trying to free players.
- if (((unfrozen == 0) && (!STAT(FROZEN, this))) || (time > this.havocbot_role_timeout))
+ if ((unfrozen == 0 && !STAT(FROZEN, this)) || time > this.havocbot_role_timeout)
{
LOG_TRACE("changing role to freeing");
this.havocbot_role = havocbot_role_ft_freeing;
if (navigation_goalrating_timeout(this))
{
navigation_goalrating_start(this);
- havocbot_goalrating_items(this, 10000, this.origin, 10000);
- havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
- havocbot_goalrating_freeplayers(this, 9000, this.origin, 10000);
+ havocbot_goalrating_items(this, 12000, this.origin, 10000);
+ havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
+ havocbot_goalrating_ft_freeplayers(this, 9000, this.origin, 10000);
havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
navigation_goalrating_end(this);
if (navigation_goalrating_timeout(this))
{
navigation_goalrating_start(this);
- havocbot_goalrating_items(this, 8000, this.origin, 10000);
- havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
- havocbot_goalrating_freeplayers(this, 20000, this.origin, 10000);
+ havocbot_goalrating_items(this, 10000, this.origin, 10000);
+ havocbot_goalrating_enemyplayers(this, 5000, this.origin, 10000);
+ havocbot_goalrating_ft_freeplayers(this, 20000, this.origin, 10000);
havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
navigation_goalrating_end(this);
bot.havocbot_role = havocbot_role_ft_offense;
}
+ // if bots spawn all at once assign them a more appropriated role after a while
+ if (time < CS(bot).jointime + 1)
+ bot.havocbot_role_timeout = time + 10 + random() * 10;
+
return true;
}
settouch(this, ka_TouchEvent);
setthink(this, ka_RespawnBall);
this.nextthink = time + autocvar_g_keepawayball_respawntime;
- navigation_dynamicgoal_set(this);
+ navigation_dynamicgoal_set(this, NULL);
Send_Effect(EFFECT_ELECTRO_COMBO, oldballorigin, '0 0 0', 1);
Send_Effect(EFFECT_ELECTRO_COMBO, this.origin, '0 0 0', 1);
setorigin(ball, plyr.origin + '0 0 10');
ball.velocity = '0 0 200' + '0 100 0'*crandom() + '100 0 0'*crandom();
ball.owner = NULL;
- navigation_dynamicgoal_set(ball);
+ navigation_dynamicgoal_set(ball, plyr);
// messages and sounds
ka_EventLog("dropped", plyr);
void havocbot_goalrating_ball(entity this, float ratingscale, vector org)
{
- float t;
entity ball_owner;
ball_owner = ka_ball.owner;
if (ball_owner == this)
return;
- // If ball is carried by player then hunt them down.
if (ball_owner)
- {
- t = (GetResourceAmount(this, RESOURCE_HEALTH) + GetResourceAmount(this, RESOURCE_ARMOR)) / (GetResourceAmount(ball_owner, RESOURCE_HEALTH) + GetResourceAmount(ball_owner, RESOURCE_ARMOR));
- navigation_routerating(this, ball_owner, t * ratingscale, 2000);
- }
- else // Ball has been dropped so collect.
+ navigation_routerating(this, ball_owner, ratingscale, 2000);
+ else
navigation_routerating(this, ka_ball, ratingscale, 2000);
}
{
navigation_goalrating_start(this);
havocbot_goalrating_items(this, 10000, this.origin, 10000);
- havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
+ havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
navigation_goalrating_end(this);
{
navigation_goalrating_start(this);
havocbot_goalrating_items(this, 10000, this.origin, 10000);
- havocbot_goalrating_enemyplayers(this, 1000, this.origin, 10000);
- havocbot_goalrating_ball(this, 20000, this.origin);
+ havocbot_goalrating_enemyplayers(this, 500, this.origin, 10000);
+ havocbot_goalrating_ball(this, 8000, this.origin);
navigation_goalrating_end(this);
navigation_goalrating_timeout_set(this);
key.takedamage = DAMAGE_YES;
// let key.team stay
key.modelindex = kh_key_dropped;
- navigation_dynamicgoal_set(key);
+ navigation_dynamicgoal_set(key, key.owner);
key.kh_previous_owner = key.owner;
key.kh_previous_owner_playerid = key.owner.playerid;
}
navigation_goalrating_start(this);
if(kh_Key_AllOwnedByWhichTeam() == this.team)
- havocbot_goalrating_kh(this, 10, 0.1, 0.1); // bring home
+ havocbot_goalrating_kh(this, 10, 0.1, 0.05); // bring home
else
- havocbot_goalrating_kh(this, 4, 4, 1); // play defensively
+ havocbot_goalrating_kh(this, 4, 4, 0.5); // play defensively
navigation_goalrating_end(this);
key_owner_team = kh_Key_AllOwnedByWhichTeam();
if(key_owner_team == this.team)
- havocbot_goalrating_kh(this, 10, 0.1, 0.1); // defend key carriers
+ havocbot_goalrating_kh(this, 10, 0.1, 0.05); // defend key carriers
else if(key_owner_team == -1)
- havocbot_goalrating_kh(this, 4, 1, 0.1); // play defensively
+ havocbot_goalrating_kh(this, 4, 1, 0.05); // play defensively
else
- havocbot_goalrating_kh(this, 0.1, 0.1, 10); // ATTACK ANYWAY
+ havocbot_goalrating_kh(this, 0.1, 0.1, 5); // ATTACK ANYWAY
navigation_goalrating_end(this);
key_owner_team = kh_Key_AllOwnedByWhichTeam();
if(key_owner_team == this.team)
- havocbot_goalrating_kh(this, 10, 0.1, 0.1); // defend anyway
+ havocbot_goalrating_kh(this, 10, 0.1, 0.05); // defend anyway
else if(key_owner_team == -1)
- havocbot_goalrating_kh(this, 0.1, 1, 4); // play offensively
+ havocbot_goalrating_kh(this, 0.1, 1, 2); // play offensively
else
- havocbot_goalrating_kh(this, 0.1, 0.1, 10); // ATTACK! EMERGENCY!
+ havocbot_goalrating_kh(this, 0.1, 0.1, 5); // ATTACK! EMERGENCY!
navigation_goalrating_end(this);
int key_owner_team = kh_Key_AllOwnedByWhichTeam();
if(key_owner_team == this.team)
- havocbot_goalrating_kh(this, 10, 0.1, 0.1); // defend anyway
+ havocbot_goalrating_kh(this, 10, 0.1, 0.05); // defend anyway
else if(key_owner_team == -1)
- havocbot_goalrating_kh(this, 1, 10, 4); // prefer dropped keys
+ havocbot_goalrating_kh(this, 1, 10, 2); // prefer dropped keys
else
- havocbot_goalrating_kh(this, 0.1, 0.1, 10); // ATTACK ANYWAY
+ havocbot_goalrating_kh(this, 0.1, 0.1, 5); // ATTACK ANYWAY
navigation_goalrating_end(this);
// NOTE: LEGACY CODE, needs to be re-written!
-void havocbot_goalrating_ons_offenseitems(entity this, float ratingscale, vector org, float sradius)
-{
- bool needarmor = false, needweapons = false;
-
- // Needs armor/health?
- if(GetResourceAmount(this, RESOURCE_HEALTH) < 100)
- needarmor = true;
-
- // Needs weapons?
- int c = 0;
- FOREACH(Weapons, it != WEP_Null, {
- if(STAT(WEAPONS, this) & (it.m_wepset))
- if(++c >= 4)
- break;
- });
-
- if(c<4)
- needweapons = true;
-
- if(!needweapons && !needarmor)
- return;
-
- LOG_DEBUG(this.netname, " needs weapons ", ftos(needweapons));
- LOG_DEBUG(this.netname, " needs armor ", ftos(needarmor));
-
- // See what is around
- IL_EACH(g_items, it.bot_pickup,
- {
- // gather health and armor only
- if (it.solid)
- if ( ((GetResourceAmount(it, RESOURCE_HEALTH) || GetResourceAmount(it, RESOURCE_ARMOR)) && needarmor) || (STAT(WEAPONS, it) && needweapons ) )
- if (vdist(it.origin - org, <, sradius))
- {
- int t = it.bot_pickupevalfunc(this, it);
- if (t > 0)
- navigation_routerating(this, it, t * ratingscale, 500);
- }
- });
-}
-
void havocbot_role_ons_setrole(entity this, int role)
{
- LOG_DEBUG(this.netname," switched to ");
switch(role)
{
case HAVOCBOT_ONS_ROLE_DEFENSE:
- LOG_DEBUG("defense");
+ LOG_DEBUG(this.netname, " switched to defense");
this.havocbot_role = havocbot_role_ons_defense;
- this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_DEFENSE;
this.havocbot_role_timeout = 0;
break;
case HAVOCBOT_ONS_ROLE_ASSISTANT:
- LOG_DEBUG("assistant");
+ LOG_DEBUG(this.netname, " switched to assistant");
this.havocbot_role = havocbot_role_ons_assistant;
- this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_ASSISTANT;
this.havocbot_role_timeout = 0;
break;
case HAVOCBOT_ONS_ROLE_OFFENSE:
- LOG_DEBUG("offense");
+ LOG_DEBUG(this.netname, " switched to offense");
this.havocbot_role = havocbot_role_ons_offense;
- this.havocbot_role_flags = HAVOCBOT_ONS_ROLE_OFFENSE;
this.havocbot_role_timeout = 0;
break;
}
- LOG_DEBUG("");
}
void havocbot_goalrating_ons_controlpoints_attack(entity this, float ratingscale)
// Count team mates interested in this control point
// (easier and cleaner than keeping counters per cp and teams)
- FOREACH_CLIENT(IS_PLAYER(it), {
+ FOREACH_CLIENT(it != this && IS_PLAYER(it), {
if(SAME_TEAM(it, this))
- if(it.havocbot_role_flags & HAVOCBOT_ONS_ROLE_OFFENSE)
+ if(it.havocbot_role == havocbot_role_ons_offense)
if(it.havocbot_ons_target == cp2)
++c;
});
}
// We'll consider only the best case
- bestvalue = 99999999999;
+ bestvalue = FLOAT_MAX;
cp = NULL;
for(cp1 = ons_worldcplist; cp1; cp1 = cp1.ons_worldcpnext)
{
// Rate waypoints near it
found = false;
best = NULL;
- bestvalue = 99999999999;
- for(radius=0; radius<1000 && !found; radius+=500)
+ bestvalue = FLOAT_MAX;
+ for (radius = 500; radius <= 1000 && !found; radius += 500)
{
- for(wp=findradius(cp.origin,radius); wp; wp=wp.chain)
+ IL_EACH(g_waypoints, vdist(cp.origin - it.origin, <, radius),
{
- if(!(wp.wpflags & WAYPOINTFLAG_GENERATED))
- if(wp.classname=="waypoint")
- if(checkpvs(wp.origin,cp))
+ if (!(it.wpflags & WAYPOINTFLAG_GENERATED) && checkpvs(it.origin, cp))
{
found = true;
- if(wp.cnt<bestvalue)
+ if (it.cnt < bestvalue)
{
- best = wp;
- bestvalue = wp.cnt;
+ best = it;
+ bestvalue = it.cnt;
}
}
- }
+ });
}
if(best)
{
// Should be touched
LOG_DEBUG(this.netname, " found a touchable controlpoint at ", vtos(cp.origin));
- found = false;
-
- // Look for auto generated waypoint
- if (!bot_waypoints_for_items)
- for (wp = findradius(cp.origin,100); wp; wp = wp.chain)
- {
- if(wp.classname=="waypoint")
- {
- navigation_routerating(this, wp, ratingscale, 10000);
- found = true;
- }
- }
-
- // Nothing found, rate the controlpoint itself
- if (!found)
- navigation_routerating(this, cp, ratingscale, 10000);
+ navigation_routerating(this, cp, ratingscale * 2, 10000);
}
}
{
entity g, wp, bestwp;
bool found;
- int best;
+ int bestvalue;
for(g = ons_worldgeneratorlist; g; g = g.ons_worldgeneratornext)
{
// Rate waypoints near it
found = false;
bestwp = NULL;
- best = 99999999999;
+ bestvalue = FLOAT_MAX;
- for(wp=findradius(g.origin,400); wp; wp=wp.chain)
+ IL_EACH(g_waypoints, vdist(g.origin - it.origin, <, 400),
{
- if(wp.classname=="waypoint")
- if(checkpvs(wp.origin,g))
+ if (checkpvs(it.origin, g))
{
found = true;
- if(wp.cnt<best)
+ if (it.cnt < bestvalue)
{
- bestwp = wp;
- best = wp.cnt;
+ bestwp = it;
+ bestvalue = it.cnt;
}
}
- }
+ });
if(bestwp)
{
{
navigation_goalrating_start(this);
havocbot_goalrating_enemyplayers(this, 20000, this.origin, 650);
- if(!havocbot_goalrating_ons_generator_attack(this, 20000))
- havocbot_goalrating_ons_controlpoints_attack(this, 20000);
- havocbot_goalrating_ons_offenseitems(this, 10000, this.origin, 10000);
+ if(!havocbot_goalrating_ons_generator_attack(this, 10000))
+ havocbot_goalrating_ons_controlpoints_attack(this, 10000);
+ havocbot_goalrating_items(this, 25000, this.origin, 10000);
navigation_goalrating_end(this);
navigation_goalrating_timeout_set(this);
.entity havocbot_ons_target;
-.int havocbot_role_flags;
.float havocbot_attack_time;
void havocbot_role_ons_defense(entity this);
#ifdef SVQC
ATTRIB(Powerup, m_mins, vector, '-16 -16 0');
ATTRIB(Powerup, m_maxs, vector, '16 16 80');
- ATTRIB(Powerup, m_botvalue, int, 20000);
+ ATTRIB(Powerup, m_botvalue, int, 11000);
ATTRIB(Powerup, m_itemflags, int, FL_POWERUP);
ATTRIB(Powerup, m_respawntime, float(), GET(g_pickup_respawntime_powerup));
ATTRIB(Powerup, m_respawntimejitter, float(), GET(g_pickup_respawntimejitter_powerup));
.entity bot_basewaypoint;
.bool navigation_dynamicgoal;
void navigation_dynamicgoal_init(entity this, bool initially_static);
-void navigation_dynamicgoal_set(entity this);
+void navigation_dynamicgoal_set(entity this, entity dropper);
void navigation_dynamicgoal_unset(entity this);
entity navigation_findnearestwaypoint(entity ent, float walkfromwp);
void navigation_goalrating_end(entity this);
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)
- {
- this.bot_aimtarg = NULL;
- return;
- }
this.bot_aimtarg = e1;
this.bot_aimlatency = CS(this).ping; // FIXME? Shouldn't this be in the lag item?
//this.bot_aimorigin = v1;
float dist, delta_t, blend;
vector desiredang, diffang;
+ this.bot_aimdir_executed = true;
+
//dprint("aim ", this.netname, ": old:", vtos(this.v_angle));
// make sure v_angle is sane first
this.v_angle_y = this.v_angle.y - floor(this.v_angle.y / 360) * 360;
+ this.bot_4th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_4th
+ this.bot_5th_order_aimfilter * autocvar_bot_ai_aimskill_order_mix_5th
);
+ desiredang.x = bound(-90, desiredang.x, 90);
// calculate turn angles
diffang = desiredang - this.bot_mouseaim;
.vector lag5_vec3;
.vector lag5_vec4;
+.bool bot_aimdir_executed;
.float bot_badaimtime;
.float bot_aimthinktime;
.float bot_prevaimtime;
// if dead, just wait until we can respawn
if (IS_DEAD(this))
{
+ if (bot_waypoint_queue_owner == this)
+ bot_waypoint_queue_owner = NULL;
+ this.aistatus = 0;
CS(this).movement = '0 0 0';
if (this.deadflag == DEAD_DEAD)
{
#include <common/items/_mod.qh>
#include <common/wepent.qh>
+#include <common/mapobjects/func/ladder.qh>
#include <common/mapobjects/teleporters.qh>
#include <common/mapobjects/trigger/jumppads.qh>
}
havocbot_aim(this);
lag_update(this);
+
+ this.bot_aimdir_executed = false;
+
if (this.bot_aimtarg)
{
this.aistatus |= AI_STATUS_ATTACKING;
{
this.aistatus |= AI_STATUS_ROAMING;
this.aistatus &= ~AI_STATUS_ATTACKING;
-
- vector now, next;
- float aimdistance,skillblend,distanceblend,blend;
-
- vector v = get_closer_dest(this.goalcurrent, this.origin);
- if(this.goalcurrent.wpisbox)
- {
- // avoid a glitch when bot is teleported but teleport waypoint isn't removed yet
- if(this.goalstack02 && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT
- && this.lastteleporttime > 0 && time - this.lastteleporttime < 0.15)
- v = (this.goalstack02.absmin + this.goalstack02.absmax) * 0.5;
- // aim to teleport origin if bot is inside teleport waypoint but hasn't touched the real teleport yet
- else if(boxesoverlap(this.goalcurrent.absmin, this.goalcurrent.absmax, this.origin, this.origin))
- v = this.goalcurrent.origin;
- }
- next = now = v - (this.origin + this.view_ofs);
- aimdistance = vlen(now);
-
- //dprint(this.goalstack01.classname,etos(this.goalstack01),"\n");
- if(
- this.goalstack01 != this && this.goalstack01 && !wasfreed(this.goalstack01) && ((this.aistatus & AI_STATUS_RUNNING) == 0) &&
- !(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
- )
- next = ((this.goalstack01.absmin + this.goalstack01.absmax) * 0.5) - (this.origin + this.view_ofs);
-
- 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(this), " ");
- //dprint(vtos(now), ":", vtos(next), "=", vtos(v), " (blend ", ftos(blend), ")\n");
- //v = now * (distanceblend) + next * (1-distanceblend);
- if (this.waterlevel < WATERLEVEL_SWIMMING)
- v.z = 0;
- //dprint("walk at:", vtos(v), "\n");
- //te_lightning2(NULL, this.origin, this.goalcurrent.origin);
- bot_aimdir(this, v, -1);
}
+
havocbot_movetogoal(this);
+ if (!this.bot_aimdir_executed && this.goalcurrent)
+ {
+ // Heading
+ vector dir = get_closer_dest(this.goalcurrent, this.origin);
+ dir -= this.origin + this.view_ofs;
+ dir.z = 0;
+ bot_aimdir(this, dir, -1);
+ }
// if the bot is not attacking, consider reloading weapons
if (!(this.aistatus & AI_STATUS_ATTACKING))
vector flatdir;
vector evadeobstacle;
vector evadelava;
+ float dodge_enemy_factor = 1;
float maxspeed;
//float dist;
vector dodge;
if(this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
{
this.aistatus |= AI_STATUS_OUT_JUMPPAD;
- navigation_poptouchedgoals(this);
- return;
+ if(navigation_poptouchedgoals(this))
+ return;
}
else if(this.aistatus & AI_STATUS_OUT_JUMPPAD)
{
return;
}
- else if(GetResourceAmount(this, RESOURCE_HEALTH) + GetResourceAmount(this, RESOURCE_ARMOR) > ROCKETJUMP_DAMAGE())
+ else if(!this.jumppadcount && !this.goalcurrent.wphardwired
+ && GetResourceAmount(this, RESOURCE_HEALTH) + GetResourceAmount(this, RESOURCE_ARMOR) > ROCKETJUMP_DAMAGE())
{
if(this.velocity.z < 0)
{
if (this.goalcurrent == this.goalentity && this.goalentity_lock_timeout > time)
locked_goal = true;
- navigation_shortenpath(this);
+ if (navigation_shortenpath(this))
+ {
+ if (vdist(this.origin - this.goalcurrent_prev.origin, <, 50)
+ && navigation_goalrating_timeout_can_be_anticipated(this))
+ navigation_goalrating_timeout_force(this);
+ }
- if (IS_MOVABLE(this.goalcurrent))
+ bool goalcurrent_can_be_removed = false;
+ if (IS_PLAYER(this.goalcurrent) || IS_MONSTER(this.goalcurrent))
{
- if (IS_DEAD(this.goalcurrent))
+ bool freeze_state_changed = (boolean(STAT(FROZEN, this.goalentity)) != this.goalentity_shouldbefrozen);
+ if (IS_DEAD(this.goalcurrent) || (this.goalentity == this.goalcurrent && freeze_state_changed))
{
+ goalcurrent_can_be_removed = true;
+ // don't remove if not visible
if (checkpvs(this.origin + this.view_ofs, this.goalcurrent))
{
navigation_goalrating_timeout_force(this);
return;
}
}
- else if (this.bot_tracewalk_time < time)
+ else if (!(STAT(FROZEN, this.goalentity)) && this.bot_tracewalk_time < time)
{
set_tracewalk_dest(this.goalcurrent, this.origin, true);
if (!(trace_ent == this || tracewalk(this, this.origin, this.mins, this.maxs,
this.bot_tracewalk_time = max(time, this.bot_tracewalk_time) + 0.25;
}
}
+
if(!locked_goal)
{
// optimize path finding by anticipating goalrating when bot is near a waypoint;
{
if (this.goalcurrent)
{
- if (IS_MOVABLE(this.goalcurrent) && IS_DEAD(this.goalcurrent))
+ if (goalcurrent_can_be_removed)
{
// remove even if not visible
navigation_goalrating_timeout_force(this);
bool bunnyhop_forbidden = false;
vector destorg = get_closer_dest(this.goalcurrent, this.origin);
-
- // in case bot ends up inside the teleport waypoint without touching
- // the teleport itself, head to the teleport origin
- if(this.goalcurrent.wpisbox && boxesoverlap(this.goalcurrent.absmin, this.goalcurrent.absmax, this.origin + eZ * this.mins.z, this.origin + eZ * this.maxs.z))
+ if (this.jumppadcount && this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
{
- bunnyhop_forbidden = true;
+ // if bot used the jumppad, push towards jumppad origin until jumppad waypoint gets removed
destorg = this.goalcurrent.origin;
- if(destorg.z > this.origin.z)
- PHYS_INPUT_BUTTON_JUMP(this) = true;
+ }
+ else if (this.goalcurrent.wpisbox)
+ {
+ // if bot is inside the teleport waypoint, head to teleport origin until teleport gets used
+ // do it even if bot is on a ledge above a teleport/jumppad so it doesn't get stuck
+ if (boxesoverlap(this.goalcurrent.absmin, this.goalcurrent.absmax, this.origin + eZ * this.mins.z, this.origin + eZ * this.maxs.z)
+ || (this.absmin.z > destorg.z && destorg.x == this.origin.x && destorg.y == this.origin.y))
+ {
+ bunnyhop_forbidden = true;
+ destorg = this.goalcurrent.origin;
+ if(destorg.z > this.origin.z)
+ PHYS_INPUT_BUTTON_JUMP(this) = true;
+ }
}
diff = destorg - this.origin;
- // 1. stop if too close to target player (even if frozen)
- // 2. stop if the locked goal has been reached
- if ((IS_PLAYER(this.goalcurrent) && vdist(diff, <, 80))
- || (this.goalcurrent == this.goalentity && time < this.goalentity_lock_timeout && vdist(diff, <, 10)))
+ if (this.goalcurrent == this.goalentity && time < this.goalentity_lock_timeout && vdist(diff, <, 10))
{
+ // stop if the locked goal has been reached
destorg = this.origin;
- diff = '0 0 0';
+ diff = dir = '0 0 0';
}
-
- dir = normalize(diff);
+ else if (IS_PLAYER(this.goalcurrent) || IS_MONSTER(this.goalcurrent))
+ {
+ if (vdist(diff, <, 80))
+ {
+ // stop if too close to target player (even if frozen)
+ destorg = this.origin;
+ diff = dir = '0 0 0';
+ }
+ else
+ {
+ // move destorg out of target players, otherwise bot will consider them
+ // an obstacle that needs to be jumped (especially if frozen)
+ dir = normalize(diff);
+ destorg -= dir * PL_MAX_CONST.x * M_SQRT2;
+ diff = destorg - this.origin;
+ }
+ }
+ else
+ dir = normalize(diff);
flatdir = (diff.z == 0) ? dir : normalize(vec2(diff));
//if (this.bot_dodgevector_time < time)
this.aistatus &= ~AI_STATUS_DANGER_AHEAD;
makevectors(this.v_angle.y * '0 1 0');
- if (this.waterlevel)
+ if (this.waterlevel > WATERLEVEL_WETFEET)
{
- if(this.waterlevel>WATERLEVEL_SWIMMING)
+ if (this.waterlevel > WATERLEVEL_SWIMMING)
{
if(!this.goalcurrent)
this.aistatus |= AI_STATUS_OUT_WATER;
{
dir = flatdir;
if(this.velocity.z >= 0 && !(this.watertype == CONTENT_WATER && destorg.z < this.origin.z) &&
- ( !(this.waterlevel == WATERLEVEL_WETFEET && this.watertype == CONTENT_WATER) || this.aistatus & AI_STATUS_OUT_WATER))
+ (this.aistatus & AI_STATUS_OUT_WATER))
PHYS_INPUT_BUTTON_JUMP(this) = true;
else
PHYS_INPUT_BUTTON_JUMP(this) = false;
// jump if going toward an obstacle that doesn't look like stairs we
// can walk up directly
vector deviation = '0 0 0';
- if (this.velocity)
+ float current_speed = vlen(vec2(this.velocity));
+ if (current_speed < maxspeed * 0.2)
+ current_speed = maxspeed * 0.2;
+ else
{
deviation = vectoangles(diff) - vectoangles(this.velocity);
while (deviation.y < -180) deviation.y += 360;
while (deviation.y > 180) deviation.y -= 360;
}
+ float turning = false;
vector flat_diff = vec2(diff);
- offset = max(32, vlen(vec2(this.velocity)) * cos(deviation.y * DEG2RAD) * 0.2) * flatdir;
+ offset = max(32, current_speed * cos(deviation.y * DEG2RAD) * 0.3) * flatdir;
vector actual_destorg = this.origin + offset;
- if (!this.goalstack01 || this.goalcurrent.wpflags & WAYPOINTFLAG_TELEPORT)
+ if (!this.goalstack01 || this.goalcurrent.wpflags & (WAYPOINTFLAG_TELEPORT | WAYPOINTFLAG_LADDER))
{
if (vlen2(flat_diff) < vlen2(offset))
{
{
vector next_goal_org = (this.goalstack01.absmin + this.goalstack01.absmax) * 0.5;
vector next_dir = normalize(vec2(next_goal_org - destorg));
- float next_dist = vlen(vec2(this.origin + offset - destorg));
- actual_destorg = vec2(destorg) + next_dist * next_dir;
+ float dist = vlen(vec2(this.origin + offset - destorg));
+ // if current and next goal are close to each other make sure
+ // actual_destorg isn't set beyond next_goal_org
+ if (dist ** 2 > vlen2(vec2(next_goal_org - destorg)))
+ actual_destorg = next_goal_org;
+ else
+ actual_destorg = vec2(destorg) + dist * next_dir;
actual_destorg.z = this.origin.z;
+ turning = true;
}
- tracebox(this.origin, this.mins, this.maxs, actual_destorg, false, this);
- if (trace_fraction < 1)
- if (trace_plane_normal.z < 0.7)
+ LABEL(jump_check);
+ dir = flatdir = normalize(actual_destorg - this.origin);
+
+ if (turning || fabs(deviation.y) < 50) // don't even try to jump if deviation is too high
{
- s = trace_fraction;
- tracebox(this.origin + stepheightvec, this.mins, this.maxs, actual_destorg + stepheightvec, false, this);
- if (trace_fraction < s + 0.01)
- if (trace_plane_normal.z < 0.7)
+ tracebox(this.origin, this.mins, this.maxs, actual_destorg, false, this);
+ if (trace_fraction < 1 && trace_plane_normal.z < 0.7)
{
s = trace_fraction;
- tracebox(this.origin + jumpstepheightvec, this.mins, this.maxs, actual_destorg + jumpstepheightvec, false, this);
- if (trace_fraction > s)
- PHYS_INPUT_BUTTON_JUMP(this) = true;
+ tracebox(this.origin + stepheightvec, this.mins, this.maxs, actual_destorg + stepheightvec, false, this);
+ if (trace_fraction < s + 0.01 && trace_plane_normal.z < 0.7)
+ {
+ // found an obstacle
+ if (turning && fabs(deviation.y) > 5)
+ {
+ // check if the obstacle is still there without turning
+ actual_destorg = destorg;
+ turning = false;
+ this.bot_tracewalk_time = time + 0.25;
+ goto jump_check;
+ }
+ s = trace_fraction;
+ // don't artificially reduce max jump height in real-time
+ // (jumpstepheightvec is reduced a bit to make the jumps easy in tracewalk)
+ vector jump_height = (IS_ONGROUND(this)) ? stepheightvec + jumpheight_vec : jumpstepheightvec;
+ tracebox(this.origin + jump_height, this.mins, this.maxs, actual_destorg + jump_height, false, this);
+ if (trace_fraction > s)
+ PHYS_INPUT_BUTTON_JUMP(this) = true;
+ else
+ {
+ jump_height = stepheightvec + jumpheight_vec / 2;
+ tracebox(this.origin + jump_height, this.mins, this.maxs, actual_destorg + jump_height, false, this);
+ if (trace_fraction > s)
+ PHYS_INPUT_BUTTON_JUMP(this) = true;
+ }
+ }
}
}
if(IS_PLAYER(this.goalcurrent))
unreachable = true;
}
+
+ // slow down if bot is in the air and goal is under it
+ if (!this.goalcurrent.wphardwired
+ && vdist(flat_diff, <, 250) && this.origin.z - destorg.z > 120
+ && (!IS_ONGROUND(this) || vdist(vec2(this.velocity), >, maxspeed * 0.3)))
+ {
+ // tracebox wouldn't work when bot is still on the ledge
+ traceline(this.origin, this.origin - '0 0 200', true, this);
+ if (this.origin.z - trace_endpos.z > 120)
+ evadeobstacle = normalize(this.velocity) * -1;
+ }
+
if(unreachable)
{
navigation_clearroute(this);
}
dodge = havocbot_dodge(this);
- dodge = dodge * bound(0,0.5+(skill+this.bot_dodgeskill)*0.1,1);
+ if (dodge)
+ dodge *= bound(0, 0.5 + (skill + this.bot_dodgeskill) * 0.1, 1);
+ dodge += evadeobstacle + evadelava;
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, NULL);
- if(IS_PLAYER(trace_ent))
- dir = dir * bound(0,(skill+this.bot_dodgeskill)/7,1);
-
- dir = normalize(dir + dodge + evadeobstacle + evadelava);
+ if (this.enemy)
+ {
+ traceline(this.origin, (this.enemy.absmin + this.enemy.absmax) * 0.5, true, NULL);
+ if (IS_PLAYER(trace_ent))
+ dodge_enemy_factor = bound(0, (skill + this.bot_dodgeskill) / 7, 1);
+ }
// this.bot_dodgevector = dir;
// this.bot_dodgevector_jumpbutton = PHYS_INPUT_BUTTON_JUMP(this);
}
+ float ladder_zdir = 0;
if(time < this.ladder_time)
{
if(this.goalcurrent.origin.z + this.goalcurrent.mins.z > this.origin.z + this.mins.z)
{
if(this.origin.z + this.mins.z < this.ladder_entity.origin.z + this.ladder_entity.maxs.z)
- dir.z = 1;
+ ladder_zdir = 1;
}
else
{
if(this.origin.z + this.mins.z > this.ladder_entity.origin.z + this.ladder_entity.mins.z)
- dir.z = -1;
+ ladder_zdir = -1;
+ }
+ if (ladder_zdir)
+ {
+ if (vdist(flatdir, <, 15))
+ dir = ladder_zdir * '0 0 1';
+ else
+ {
+ dir.z = ladder_zdir * 1.3;
+ dir = normalize(dir);
+ }
}
}
+ if (this.goalcurrent.wpisbox
+ && boxesoverlap(this.goalcurrent.absmin, this.goalcurrent.absmax, this.origin, this.origin))
+ {
+ // bot is inside teleport waypoint but hasn't touched the real teleport yet
+ // head to teleport origin
+ dir = (this.goalcurrent.origin - this.origin);
+ dir.z = 0;
+ dir = normalize(dir);
+ }
+
+ if (!this.bot_aimdir_executed)
+ bot_aimdir(this, dir, -1);
+
+ if (!ladder_zdir)
+ {
+ dir *= dodge_enemy_factor;
+ dir = normalize(dir + dodge);
+ }
+
//dir = this.bot_dodgevector;
//if (this.bot_dodgevector_jumpbutton)
// PHYS_INPUT_BUTTON_JUMP(this) = true;
if(autocvar_bot_debug_goalstack)
debuggoalstack(this);
- // Heading
- vector dir = get_closer_dest(this.goalcurrent, this.origin);
- dir = dir - (this.origin + this.view_ofs);
- dir.z = 0;
- bot_aimdir(this, dir, -1);
// Go!
havocbot_movetogoal(this);
+ if (!this.bot_aimdir_executed && this.goalcurrent)
+ {
+ // Heading
+ vector dir = get_closer_dest(this.goalcurrent, this.origin);
+ dir -= this.origin + this.view_ofs;
+ dir.z = 0;
+ bot_aimdir(this, dir, -1);
+ }
+
if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_REACHED)
{
// Step 5: Waypoint reached
this.cmd_moveto = havocbot_moveto;
this.cmd_resetgoal = havocbot_resetgoal;
+ // NOTE: bot is not player yet
havocbot_chooserole(this);
}
*/
.entity draggedby;
-.float ladder_time;
-.entity ladder_entity;
float enemy_distance = FLOAT_MAX;
float dist;
- FOREACH_CLIENT(IS_PLAYER(it) && it != this && !IS_DEAD(it),
+ FOREACH_CLIENT(IS_PLAYER(it) && it != this && !(IS_DEAD(it) || STAT(FROZEN, it)),
{
if (it.team == this.team)
{
{
float rating;
vector o;
- ratingscale = ratingscale * 0.0001; // items are rated around 10000 already
+ ratingscale = ratingscale * 0.0001;
IL_EACH(g_items, it.bot_pickup,
{
// NOTE: this code assumes each bot rates items in a different frame
if(it.bot_ratingscale_time == time && ratingscale < it.bot_ratingscale)
continue;
- it.bot_ratingscale_time = time;
- it.bot_ratingscale = ratingscale;
if(!it.solid)
{
if(!havocbot_goalrating_item_pickable_check_players(this, org, it, o))
continue;
+ it.bot_ratingscale_time = time;
+ it.bot_ratingscale = ratingscale;
rating = it.bot_pickupevalfunc(this, it);
if(rating > 0)
navigation_routerating(this, it, rating * ratingscale, 2000);
if(this.waterlevel>WATERLEVEL_WETFEET)
return;
- ratingscale = ratingscale * 0.00005; // enemies are rated around 20000 already
+ ratingscale = ratingscale * 0.0001;
float t;
FOREACH_CLIENT(IS_PLAYER(it) && bot_shouldattack(this, it), {
{
navigation_goalrating_start(this);
havocbot_goalrating_items(this, 10000, this.origin, 10000);
- havocbot_goalrating_enemyplayers(this, 20000, this.origin, 10000);
+ havocbot_goalrating_enemyplayers(this, 10000, this.origin, 10000);
havocbot_goalrating_waypoints(this, 1, this.origin, 3000);
navigation_goalrating_end(this);
#include <common/constants.qh>
#include <common/net_linked.qh>
+#include <common/mapobjects/func/ladder.qh>
#include <common/mapobjects/trigger/jumppads.qh>
.float speed;
#define MAX_CHASE_DISTANCE 700
bool navigation_goalrating_timeout_can_be_anticipated(entity this)
{
- if(time > this.bot_strategytime - (IS_MOVABLE(this.goalentity) ? 3 : 2))
+ vector gco = (this.goalentity.absmin + this.goalentity.absmax) * 0.5;
+ if (vdist(gco - this.origin, >, autocvar_sv_maxspeed * 1.5)
+ && time > this.bot_strategytime - (IS_MOVABLE(this.goalentity) ? 3 : 2))
+ {
return true;
+ }
if (this.goalentity.bot_pickup && time > this.bot_strategytime - 5)
{
- vector gco = (this.goalentity.absmin + this.goalentity.absmax) * 0.5;
if(!havocbot_goalrating_item_pickable_check_players(this, this.origin, this.goalentity, gco))
{
this.ignoregoal = this.goalentity;
this.nearestwaypointtimeout = time;
}
-void navigation_dynamicgoal_set(entity this)
+void navigation_dynamicgoal_set(entity this, entity dropper)
{
this.nearestwaypointtimeout = time;
+ if (dropper && dropper.nearestwaypointtimeout && dropper.nearestwaypointtimeout < time + 2)
+ this.nearestwaypoint = dropper.nearestwaypoint;
if (this.nearestwaypoint)
this.nearestwaypointtimeout += 2;
}
// z coord is set to ent's min height
tracewalk_dest.x = bound(wm1.x, org.x, wm2.x);
tracewalk_dest.y = bound(wm1.y, org.y, wm2.y);
- tracewalk_dest.z = wm1.z;
- tracewalk_dest_height = wm2.z - wm1.z; // destination height
+ if ((IS_PLAYER(ent) || IS_MONSTER(ent))
+ && org.x == tracewalk_dest.x && org.y == tracewalk_dest.y && org.z > tracewalk_dest.z)
+ {
+ tracewalk_dest.z = wm2.z - PL_MIN_CONST.z;
+ tracewalk_dest_height = 0;
+ fix_player_dest = false;
+ }
+ else
+ {
+ tracewalk_dest.z = wm1.z;
+ tracewalk_dest_height = wm2.z - wm1.z;
+ }
}
else
{
int nav_action;
// Analyze starting point
- traceline(start, start, MOVE_NORMAL, e);
- if (trace_dpstartcontents & (DPCONTENTS_SLIME | DPCONTENTS_LAVA))
+ if (IN_LAVA(start))
ignorehazards = true;
tracebox(start, m1, m2, start, MOVE_NOMONSTERS, e);
this.goalcurrent_distance_z = FLOAT_MAX;
this.goalcurrent_distance_time = 0;
this.goalentity_lock_timeout = 0;
+ this.goalentity_shouldbefrozen = false;
this.goalentity = NULL;
this.goalcurrent = NULL;
this.goalstack01 = NULL;
vector pm2 = ent.origin + ent.maxs;
// do two scans, because box test is cheaper
- IL_EACH(g_waypoints, it != ent && it != except,
+ IL_EACH(g_waypoints, it != ent && it != except && !(it.wpflags & WAYPOINTFLAG_TELEPORT),
{
if(boxesoverlap(pm1, pm2, it.absmin, it.absmax))
{
// updates the best goal according to a weighted calculation of travel cost and item value of a new proposed item
void navigation_routerating(entity this, entity e, float f, float rangebias)
{
- if (!e)
- return;
-
- if(e.blacklisted)
- return;
+ if (!e || e.blacklisted) { return; }
rangebias = waypoint_getlinearcost(rangebias);
f = waypoint_getlinearcost(f);
if (IS_PLAYER(e))
{
bool rate_wps = false;
- if((e.flags & FL_INWATER) || (e.flags & FL_PARTIALGROUND))
+ if (e.watertype < CONTENT_WATER || (e.waterlevel > WATERLEVEL_WETFEET && !STAT(FROZEN, e))
+ || (e.flags & FL_PARTIALGROUND))
+ {
rate_wps = true;
+ }
if(!IS_ONGROUND(e))
{
nwp = e.nearestwaypoint;
}
- LOG_DEBUG("-- checking ", e.classname, " (with cost ", ftos(nwp.wpcost), ")");
if (nwp && nwp.wpcost < 10000000)
{
//te_wizspike(nwp.wpnearestpoint);
else
nwptoitem_cost = waypoint_gettravelcost(nwp.wpnearestpoint, goal_org, nwp, e);
float cost = nwp.wpcost + nwptoitem_cost;
- LOG_DEBUG(e.classname, " ", ftos(f), "/(1+", ftos(cost), "/", ftos(rangebias), ") = ");
+ LOG_DEBUG("checking ^5", e.classname, "^7 with base rating ^xf04", ftos(f), "^7 and rangebias ^xf40", ftos(rangebias));
f = f * rangebias / (rangebias + cost);
- LOG_DEBUG("considering ", e.classname, " (with rating ", ftos(f), ")");
+ LOG_DEBUG(" ^5", e.classname, "^7 with cost ^6", ftos(cost), "^7 and final rating ^2", ftos(f));
if (navigation_bestrating < f)
{
- LOG_DEBUG("ground path: added goal ", e.classname, " (with rating ", ftos(f), ")");
+ LOG_DEBUG(" ground path: ^3added goal ^5", e.classname);
navigation_bestrating = f;
navigation_bestgoal = e;
}
}
// shorten path by removing intermediate goals
-void navigation_shortenpath(entity this)
+bool navigation_shortenpath(entity this)
{
if (!this.goalstack01 || wasfreed(this.goalstack01))
- return;
+ return false;
if (this.bot_tracewalk_time > time)
- return;
+ return false;
this.bot_tracewalk_time = max(time, this.bot_tracewalk_time) + 0.25;
bool cut_allowed = false;
navigation_poproute(this);
}
while (this.goalcurrent != next);
+ return true;
}
- return;
+ return false;
}
}
{
LOG_DEBUG("path optimized for ", this.netname, ", removed a goal from the queue");
navigation_poproute(this);
+ return true;
}
}
+ return false;
}
// removes any currently touching waypoints from the goal stack
this.aistatus &= ~AI_STATUS_WAYPOINT_PERSONAL_GOING;
this.aistatus |= AI_STATUS_WAYPOINT_PERSONAL_REACHED;
}
+ if(this.jumppadcount)
+ {
+ // remove jumppad waypoint after a random delay to prevent bots getting
+ // stuck on certain jumppads that require an extra initial horizontal speed
+ float max_delay = 0.1;
+ if (vdist(vec2(this.velocity), >, 2 * autocvar_sv_maxspeed))
+ max_delay = 0.05;
+ if (time - this.lastteleporttime < random() * max_delay)
+ return removed_goals;
+ }
navigation_poproute(this);
this.lastteleporttime = 0;
++removed_goals;
gc_min = this.goalcurrent.origin - '1 1 1' * 12;
gc_max = this.goalcurrent.origin + '1 1 1' * 12;
}
- if(!boxesoverlap(this.absmin, this.absmax, gc_min, gc_max))
- break;
+ if (time < this.ladder_time)
+ {
+ if (!boxesoverlap(this.absmin, this.absmax - eZ * STAT(PL_MAX, this).z, gc_min, gc_max))
+ break;
+ }
+ else
+ {
+ if (!boxesoverlap(this.absmin, this.absmax, gc_min, gc_max))
+ break;
+ }
// Detect personal waypoints
if(this.aistatus & AI_STATUS_WAYPOINT_PERSONAL_GOING)
this.aistatus |= AI_STATUS_STUCK;
}
}
+ this.goalentity_shouldbefrozen = boolean(STAT(FROZEN, this.goalentity));
}
void botframe_updatedangerousobjects(float maxupdate)
bot_waypoint_queue_bestgoal = bot_waypoint_queue_goal;
}
}
+
+ // move to a random waypoint while bot is searching for a walkable path;
+ // this is usually sufficient to unstuck bots from bad spots or when other
+ // bots of the same team block all their ways
+ if (!bot_waypoint_queue_bestgoal && (!this.goalentity || random() < 0.1))
+ {
+ navigation_clearroute(this);
+ navigation_routetogoal(this, bot_waypoint_queue_goal, this.origin);
+ navigation_goalrating_timeout_expire(this, 1 + random() * 2);
+ }
+
bot_waypoint_queue_goal = bot_waypoint_queue_goal.bot_waypoint_queue_nextgoal;
if (!bot_waypoint_queue_goal)
if (bot_waypoint_queue_bestgoal)
{
LOG_DEBUG(this.netname, " stuck, reachable waypoint found, heading to it");
+ navigation_clearroute(this);
navigation_routetogoal(this, bot_waypoint_queue_bestgoal, this.origin);
navigation_goalrating_timeout_set(this);
this.aistatus &= ~AI_STATUS_STUCK;
.float goalcurrent_distance_time;
.float goalentity_lock_timeout;
+.bool goalentity_shouldbefrozen;
.entity nearestwaypoint;
.float nearestwaypointtimeout;
.entity bot_basewaypoint;
.bool navigation_dynamicgoal;
void navigation_dynamicgoal_init(entity this, bool initially_static);
-void navigation_dynamicgoal_set(entity this);
+void navigation_dynamicgoal_set(entity this, entity dropper);
void navigation_dynamicgoal_unset(entity this);
.int nav_submerged_state;
void navigation_markroutes(entity this, entity fixed_source_waypoint);
void navigation_markroutes_inverted(entity fixed_source_waypoint);
void navigation_routerating(entity this, entity e, float f, float rangebias);
-void navigation_shortenpath(entity this);
+bool navigation_shortenpath(entity this);
int navigation_poptouchedgoals(entity this);
void navigation_goalrating_start(entity this);
void navigation_goalrating_end(entity this);
set g_hitplots 0 "when set to 1, hitplots are stored by the server to provide a means of proving that a triggerbot was used"
set g_hitplots_individuals "" "the individuals, by IP, that should have their hitplots recorded"
+// set it to 1 to "fix bot moveto command and routing... now all bots can get to their seats" (Nexuiz repo, commit 2c9873e6)
set bot_navigation_ignoreplayers 0 // FIXME remove this once the issue is solved
set bot_sound_monopoly 0 "when enabled, only bots can make any noise"