Added ctf

This commit is contained in:
INeedBots 2021-02-16 19:12:46 -06:00
parent 0093e1bdf8
commit 801b758644
2 changed files with 230 additions and 3 deletions

View File

@ -361,9 +361,8 @@ bot_spawn()
self thread bot_dom_def_think(); self thread bot_dom_def_think();
self thread bot_dom_spawn_kill_think(); self thread bot_dom_spawn_kill_think();
/* self thread bot_hq(); self thread bot_cap();/*
self thread bot_hq();
self thread bot_cap();
self thread bot_sab(); self thread bot_sab();
@ -427,6 +426,56 @@ bots_watch_touch_obj(obj)
} }
} }
/*
Watches while the obj is being carried, calls 'goal' when complete
*/
bot_escort_obj(obj, carrier)
{
self endon( "death" );
self endon( "disconnect" );
self endon( "goal" );
self endon( "bad_path" );
self endon( "new_goal" );
for (;;)
{
wait 0.5;
if (!isDefined(obj))
break;
if (!isDefined(obj.carrier) || carrier == obj.carrier)
break;
}
self notify("goal");
}
/*
Watches while the obj is not being carried, calls 'goal' when complete
*/
bot_get_obj(obj)
{
self endon( "death" );
self endon( "disconnect" );
self endon( "goal" );
self endon( "bad_path" );
self endon( "new_goal" );
for (;;)
{
wait 0.5;
if (!isDefined(obj))
break;
if (isDefined(obj.carrier))
break;
}
self notify("goal");
}
/* /*
Changes to the weap Changes to the weap
*/ */
@ -2943,3 +2992,173 @@ bot_dom_go_cap_flag(flag, myteam)
else else
self notify("goal"); self notify("goal");
} }
/*
Bots play capture the flag
*/
bot_cap()
{
self endon( "death" );
self endon( "disconnect" );
level endon("game_ended");
if ( level.gametype != "ctf" )
return;
myTeam = self.pers[ "team" ];
otherTeam = getOtherTeam( myTeam );
for ( ;; )
{
wait( randomintrange( 3, 5 ) );
if ( self IsRemoteControlling() || self.bot_lock_goal )
{
continue;
}
if(!isDefined(level.teamFlagZones))
continue;
if(!isDefined(level.teamFlags))
continue;
myflag = level.teamFlags[myteam];
myzone = level.teamFlagZones[myteam];
theirflag = level.teamFlags[otherTeam];
theirzone = level.teamFlagZones[otherTeam];
if(myflag maps\mp\gametypes\_gameobjects::isObjectAwayFromHome())
{
carrier = myflag.carrier;
if(!isDefined(carrier))//someone doesnt has our flag
{
if(!isDefined(theirflag.carrier) && DistanceSquared(self.origin, theirflag.curorigin) < DistanceSquared(self.origin, myflag.curorigin)) //no one has their flag and its closer
self bot_cap_get_flag(theirflag);
else//go get it
self bot_cap_get_flag(myflag);
continue;
}
else
{
if(!theirflag maps\mp\gametypes\_gameobjects::isObjectAwayFromHome() && randomint(100) < 50)
{ //take their flag
self bot_cap_get_flag(theirflag);
}
else
{
if(self HasScriptGoal())
continue;
if(!isDefined(theirzone.bots))
theirzone.bots = 0;
origin = theirzone.curorigin;
if(theirzone.bots > 2 || randomInt(100) < 45)
{
//kill carrier
if(carrier hasPerk( "specialty_gpsjammer" ))
continue;
origin = carrier.origin;
self SetBotGoal( origin, 64 );
self thread bot_escort_obj(myflag, carrier);
if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearBotGoal();
continue;
}
self thread bot_inc_bots(theirzone);
//camp their zone
if(DistanceSquared(origin, self.origin) <= 1024*1024)
{
wait 4;
self notify("bot_inc_bots"); theirzone.bots--;
continue;
}
self SetBotGoal( origin, 256 );
self thread bot_inc_bots(theirzone);
self thread bot_escort_obj(myflag, carrier);
if(self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearBotGoal();
}
}
}
else//our flag is ok
{
if(self isFlagCarrier())//if have flag
{
//go cap
origin = myzone.curorigin;
self.bot_lock_goal = true;
self SetBotGoal( origin, 32 );
self thread bot_get_obj(myflag);
evt = self waittill_any_return( "goal", "bad_path", "new_goal" );
wait 1;
if (evt != "new_goal")
self ClearBotGoal();
self.bot_lock_goal = false;
continue;
}
carrier = theirflag.carrier;
if(!isDefined(carrier))//if no one has enemy flag
{
self bot_cap_get_flag(theirflag);
continue;
}
//escort them
if(self HasScriptGoal())
continue;
origin = carrier.origin;
if(DistanceSquared(origin, self.origin) <= 1024*1024)
continue;
self SetBotGoal( origin, 256 );
self thread bot_escort_obj(theirflag, carrier);
if (self waittill_any_return( "goal", "bad_path", "new_goal" ) != "new_goal")
self ClearBotGoal();
}
}
}
/*
Bots go and get the flag
*/
bot_cap_get_flag(flag)
{
origin = flag.curorigin;
//go get it
self.bot_lock_goal = true;
self SetBotGoal( origin, 32 );
self thread bot_get_obj(flag);
evt = self waittill_any_return( "goal", "bad_path", "new_goal" );
wait 1;
self.bot_lock_goal = false;
if (evt != "new_goal")
self ClearBotGoal();
}

View File

@ -94,6 +94,14 @@ inLastStand()
return (isDefined(self.laststand) && self.laststand); return (isDefined(self.laststand) && self.laststand);
} }
/*
Is they the flag carrier men?
*/
isFlagCarrier()
{
return (isDefined(self.isFlagCarrier) && self.isFlagCarrier);
}
/* /*
Gets the bot's difficulty number Gets the bot's difficulty number
*/ */