This commit is contained in:
INeedBots 2020-11-22 00:40:07 -06:00
parent d57d38d478
commit b5a535842b

View File

@ -1711,6 +1711,9 @@ start_bot_threads()
self thread bot_cap(); self thread bot_cap();
self thread bot_sab(); self thread bot_sab();
self thread bot_sd_defenders();
self thread bot_sd_attackers();
} }
/* /*
@ -3116,7 +3119,7 @@ bot_turret_think()
if(!isDefined(turret)) if(!isDefined(turret))
continue; continue;
self SetScriptEnemy( turret, (0, 0, 15) ); self SetScriptEnemy( turret, (0, 0, 25) );
self bot_turret_attack(turret); self bot_turret_attack(turret);
self ClearScriptEnemy(); self ClearScriptEnemy();
} }
@ -3212,7 +3215,7 @@ bot_crate_think()
if (path != "new_goal") if (path != "new_goal")
self ClearScriptGoal(); self ClearScriptGoal();
if (path != "goal") if (path != "goal" || DistanceSquared(self.origin, crate.origin) > 64*64)
continue; continue;
self _DisableWeapon(); self _DisableWeapon();
@ -4385,10 +4388,12 @@ bot_cap()
if(DistanceSquared(origin, self.origin) <= 1024*1024) if(DistanceSquared(origin, self.origin) <= 1024*1024)
{ {
wait 4; wait 4;
self notify("bot_inc_bots"); theirzone.bots--;
continue; continue;
} }
self SetScriptGoal( origin, 256 ); self SetScriptGoal( origin, 256 );
self thread bot_inc_bots(theirzone);
self thread bot_escort_obj(myflag, carrier); self thread bot_escort_obj(myflag, carrier);
if(self waittill_any( "goal", "bad_path", "new_goal" ) != "new_goal") if(self waittill_any( "goal", "bad_path", "new_goal" ) != "new_goal")
@ -4600,7 +4605,7 @@ bot_sab()
if(!level.bombPlanted) if(!level.bombPlanted)
{ {
//kill bomb carrier //kill bomb carrier
if(site.bots > 2) if(site.bots > 2 || randomInt(100) < 45)
{ {
if(self HasScriptGoal()) if(self HasScriptGoal())
continue; continue;
@ -4627,6 +4632,7 @@ bot_sab()
{ {
self.bot_lock_goal = true; self.bot_lock_goal = true;
self SetScriptGoal( origin, 64 ); self SetScriptGoal( origin, 64 );
self thread bot_inc_bots(site);
self thread bot_defend_site(site); self thread bot_defend_site(site);
@ -4641,13 +4647,13 @@ bot_sab()
if(DistanceSquared(origin, self.origin) <= 1024*1024) if(DistanceSquared(origin, self.origin) <= 1024*1024)
{ {
wait 4; wait 4;
self notify("bot_inc_bots"); self notify("bot_inc_bots"); site.bots--;
site.bots--;
continue; continue;
} }
self.bot_lock_goal = true; self.bot_lock_goal = true;
self SetScriptGoal( origin, 256 ); self SetScriptGoal( origin, 256 );
self thread bot_inc_bots(site);
if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal") if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearScriptGoal(); self ClearScriptGoal();
@ -4668,6 +4674,7 @@ bot_sab()
continue; continue;
self SetScriptGoal( origin, 256 ); self SetScriptGoal( origin, 256 );
self thread bot_go_defuse(site);
if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal") if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearScriptGoal(); self ClearScriptGoal();
@ -4676,10 +4683,9 @@ bot_sab()
// lets go defuse // lets go defuse
self.bot_lock_goal = true; self.bot_lock_goal = true;
self thread bot_inc_bots(site);
self SetScriptGoal( origin, 1 ); self SetScriptGoal( origin, 1 );
self thread bot_inc_bots(site);
self thread bot_go_defuse(site); self thread bot_go_defuse(site);
event = self waittill_any_return( "goal", "bad_path", "new_goal" ); event = self waittill_any_return( "goal", "bad_path", "new_goal" );
@ -4703,7 +4709,7 @@ bot_sab()
} }
else // we need to go get the bomb! else // we need to go get the bomb!
{ {
origin = ( bomb.curorigin[0], bomb.curorigin[1], bomb.curorigin[2]+32 ); origin = ( bomb.curorigin[0], bomb.curorigin[1], bomb.curorigin[2]+5 );
self.bot_lock_goal = true; self.bot_lock_goal = true;
self SetScriptGoal( origin, 64 ); self SetScriptGoal( origin, 64 );
@ -4718,3 +4724,412 @@ bot_sab()
} }
} }
} }
/*
Gets the object thats the closest in the array
*/
bot_array_nearest_curorigin(array)
{
result = undefined;
for(i = 0; i < array.size; i++)
if(!isDefined(result) || DistanceSquared(self.origin,array[i].curorigin) < DistanceSquared(self.origin,result.curorigin))
result = array[i];
return result;
}
/*
Bots play sd defenders
*/
bot_sd_defenders()
{
self endon( "death" );
self endon( "disconnect" );
level endon("game_ended");
if ( level.gametype != "sd" )
return;
myTeam = self.pers[ "team" ];
otherTeam = getOtherTeam( myTeam );
if(myTeam == game["attackers"])
return;
rand = self BotGetRandom();
for ( ;; )
{
wait( randomintrange( 3, 5 ) );
if ( self IsUsingRemote() || self.bot_lock_goal )
{
continue;
}
if (self IsPlanting() || self isDefusing())
continue;
// bomb not planted, lets protect our sites
if(!level.bombPlanted)
{
timeleft = maps\mp\gametypes\_gamelogic::getTimeRemaining()/1000;
if(timeleft >= 90)
continue;
// check for a bomb carrier, and camp the bomb
if(!level.multiBomb && isDefined(level.sdBomb))
{
bomb = level.sdBomb;
carrier = level.sdBomb.carrier;
if(!isDefined(carrier))
{
origin = ( bomb.curorigin[0], bomb.curorigin[1], bomb.curorigin[2]+5 );
//hang around the bomb
if(self HasScriptGoal())
continue;
if(DistanceSquared(origin, self.origin) <= 1024*1024)
continue;
self SetScriptGoal( origin, 256 );
self thread bot_get_obj(bomb);
if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearScriptGoal();
continue;
}
}
// pick a site to protect
if(!isDefined(level.bombZones) || !level.bombZones.size)
continue;
sites = [];
for(i = 0; i < level.bombZones.size; i++)
{
sites[sites.size] = level.bombZones[i];
}
if(!sites.size)
continue;
if (rand > 50)
site = self bot_array_nearest_curorigin(sites);
else
site = random(sites);
if(!isDefined(site))
continue;
origin = ( site.curorigin[0]+50, site.curorigin[1]+50, site.curorigin[2]+5 );
if(site isInUse())//somebody is planting
{
self.bot_lock_goal = true;
self SetScriptGoal( origin, 64 );
self thread bot_defend_site(site);
if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearScriptGoal();
self.bot_lock_goal = false;
continue;
}
//else hang around the site
if(DistanceSquared(origin, self.origin) <= 1024*1024)
continue;
self.bot_lock_goal = true;
self SetScriptGoal( origin, 256 );
if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearScriptGoal();
self.bot_lock_goal = false;
continue;
}
// bomb is planted, we need to defuse
if(!isDefined(level.defuseObject))
continue;
defuse = level.defuseObject;
if(!isDefined(defuse.bots))
defuse.bots = 0;
origin = ( defuse.curorigin[0], defuse.curorigin[1], defuse.curorigin[2]+5 );
// someone is going to go defuse ,lets just hang around
if(defuse.bots > 1)
{
if(self HasScriptGoal())
continue;
if(DistanceSquared(origin, self.origin) <= 1024*1024)
continue;
self SetScriptGoal( origin, 256 );
self thread bot_go_defuse(defuse);
if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearScriptGoal();
continue;
}
// lets defuse
self.bot_lock_goal = true;
self SetScriptGoal( origin, 1 );
self thread bot_inc_bots(defuse);
self thread bot_go_defuse(defuse);
event = self waittill_any_return( "goal", "bad_path", "new_goal" );
if (event != "new_goal")
self ClearScriptGoal();
if(event != "goal" || !level.bombPlanted || defuse isInUse() || !self isTouching(defuse.trigger) || self InLastStand() || self HasThreat())
{
self.bot_lock_goal = false;
continue;
}
self SetScriptGoal( self.origin, 64 );
self bot_use_bomb_thread(defuse);
wait 1;
self ClearScriptGoal();
self.bot_lock_goal = false;
}
}
/*
Bots play sd attackers
*/
bot_sd_attackers()
{
self endon( "death" );
self endon( "disconnect" );
level endon("game_ended");
if ( level.gametype != "sd" )
return;
myTeam = self.pers[ "team" ];
otherTeam = getOtherTeam( myTeam );
if(myTeam != game["attackers"])
return;
first = true;
for ( ;; )
{
if(first)
first = false;
else
wait( randomintrange( 3, 5 ) );
if ( self IsUsingRemote() || self.bot_lock_goal )
{
continue;
}
//bomb planted
if(level.bombPlanted)
{
if(!isDefined(level.defuseObject))
continue;
site = level.defuseObject;
origin = ( site.curorigin[0], site.curorigin[1], site.curorigin[2]+5 );
if(site IsInUse())//somebody is defusing
{
self.bot_lock_goal = true;
self SetScriptGoal( origin, 64 );
self thread bot_defend_site(site);
if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearScriptGoal();
self.bot_lock_goal = false;
continue;
}
//else hang around the site
if(DistanceSquared(origin, self.origin) <= 1024*1024)
continue;
self.bot_lock_goal = true;
self SetScriptGoal( origin, 256 );
if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearScriptGoal();
self.bot_lock_goal = false;
continue;
}
timeleft = maps\mp\gametypes\_gamelogic::getTimeRemaining()/1000;
timepassed = getTimePassed()/1000;
//dont have a bomb
if(!self IsBombCarrier() && !level.multiBomb)
{
if(!isDefined(level.sdBomb))
continue;
bomb = level.sdBomb;
carrier = level.sdBomb.carrier;
//bomb is picked up
if(isDefined(carrier))
{
//escort the bomb carrier
if(self HasScriptGoal())
continue;
origin = carrier.origin;
if(DistanceSquared(origin, self.origin) <= 1024*1024)
continue;
self SetScriptGoal( origin, 256 );
self thread bot_escort_obj(bomb, carrier);
if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearScriptGoal();
continue;
}
if(!isDefined(bomb.bots))
bomb.bots = 0;
origin = ( bomb.curorigin[0], bomb.curorigin[1], bomb.curorigin[2]+32 );
//hang around the bomb if other is going to go get it
if(bomb.bots > 1)
{
if(self HasScriptGoal())
continue;
if(DistanceSquared(origin, self.origin) <= 1024*1024)
continue;
self.did = "bot_sd_attackers(bomb_hang)";
self SetScriptGoal( origin, 256 );
if(DistanceSquared(origin, self.origin) > 256*256)
{
self thread bot_get_obj(bomb);
self waittill_any( "goal", "bad_path" );
}
self ClearScriptGoal();
continue;
}
self.bot_lock_goal = true;
self notify("bot_check_unreachable");
self notify("bad_path");
self thread bot_inc_bots(bomb);
wait 0.05;
self.did = "bot_sd_attackers(bomb_get)";
self SetScriptGoal( origin, 64 );
if(!self isTouching(bomb.trigger))
{
self thread bot_get_obj(bomb);
self waittill_any( "goal", "bad_path" );
}
self notify("bot_inc_bots");
self ClearScriptGoal();
self.bot_lock_goal = false;
continue;
}
if(timepassed < 120 && timeleft >= 90 && randomInt(100) < 98)
continue;
if(!isDefined(level.bombZones) || !level.bombZones.size)
continue;
sites = [];
for(i = 0; i < level.bombZones.size; i++)
{
sites[sites.size] = level.bombZones[i];
}
if(!sites.size)
continue;
if(randomint(2))
plant = self bot_array_nearest_curorigin(sites);
else
plant = random(sites);
if(!isDefined(plant))
continue;
origin = ( plant.curorigin[0]+50, plant.curorigin[1]+50, plant.curorigin[2]+32 );
self.bot_lock_goal = true;
self notify("bot_check_unreachable");
self notify("bad_path");
wait 0.05;
if(!self isTouching(plant.trigger))
{
self.did = "bot_sd_attackers";
self SetScriptGoal( origin, 64 );
self thread bot_go_plant(plant);
event = self waittill_any_return( "goal", "bad_path" );
self ClearScriptGoal();
if (event == "bad_path")
{
self.bot_lock_goal = false;
continue;
}
}
if(level.bombPlanted || plant.visibleTeam == "none" || !self isTouching(plant.trigger) || (isDefined(self.laststand) && self.laststand) || isDefined(self getThreat()))
{
self.bot_lock_goal = false;
continue;
}
self.did = "bot_sd_attackers(2)";
self SetScriptGoal( self.origin, 64 );
self bot_use_bomb_thread(plant);
wait 1;
self ClearScriptGoal();
self.bot_lock_goal = false;
}
}