Greatly reduce var usage

This commit is contained in:
ineedbots 2021-05-26 10:47:29 -06:00
parent 589fe63bc8
commit 3b7669dbd0
3 changed files with 2656 additions and 2395 deletions

View File

@ -370,12 +370,8 @@ add_bot()
/*
A server thread for monitoring all bot's difficulty levels for custom server settings.
*/
diffBots()
diffBots_loop()
{
for(;;)
{
wait 1.5;
var_allies_hard = getDVarInt("bots_skill_allies_hard");
var_allies_med = getDVarInt("bots_skill_allies_med");
var_axis_hard = getDVarInt("bots_skill_axis_hard");
@ -446,16 +442,25 @@ diffBots()
}
}
}
/*
A server thread for monitoring all bot's difficulty levels for custom server settings.
*/
diffBots()
{
for(;;)
{
wait 1.5;
diffBots_loop();
}
}
/*
A server thread for monitoring all bot's teams for custom server settings.
*/
teamBots()
teamBots_loop()
{
for(;;)
{
wait 1.5;
teamAmount = getDvarInt("bots_team_amount");
toTeam = getDvar("bots_team");
@ -575,21 +580,25 @@ teamBots()
}
}
}
/*
A server thread for monitoring all bot's teams for custom server settings.
*/
teamBots()
{
for(;;)
{
wait 1.5;
teamBots_loop();
}
}
/*
A server thread for monitoring all bot's in game. Will add and kick bots according to server settings.
*/
addBots()
addBots_loop()
{
level endon("game_ended");
bot_wait_for_host();
for(;;)
{
wait 1.5;
botsToAdd = GetDvarInt("bots_manage_add");
if(botsToAdd > 0)
@ -688,6 +697,22 @@ addBots()
RemoveTestClient(); //cod4x
}
}
/*
A server thread for monitoring all bot's in game. Will add and kick bots according to server settings.
*/
addBots()
{
level endon("game_ended");
bot_wait_for_host();
for(;;)
{
wait 1.5;
addBots_loop();
}
}
/*

View File

@ -287,13 +287,62 @@ watchC4Thrown(c4)
break;
}
weap = self getCurrentWeapon();
if ( weap != "c4_mp" )
if ( self getCurrentWeapon() != "c4_mp" )
self notify( "alt_detonate" );
else
self thread pressFire();
}
/*
Bot moves towards the point
*/
doBotMovement_loop(data)
{
angles = self GetPlayerAngles();
// climb through windows
if (self isMantling())
{
data.wasMantling = true;
self crouch();
}
else if (data.wasMantling)
{
data.wasMantling = false;
self stand();
}
startPos = self.origin + (0, 0, 50);
startPosForward = startPos + anglesToForward((0, angles[1], 0)) * 25;
bt = bulletTrace(startPos, startPosForward, false, self);
if (bt["fraction"] >= 1)
{
// check if need to jump
bt = bulletTrace(startPosForward, startPosForward - (0, 0, 40), false, self);
if (bt["fraction"] < 1 && bt["normal"][2] > 0.9 && data.i > 1.5 && !self isOnLadder())
{
data.i = 0;
self thread jump();
}
}
// check if need to knife glass
else if (bt["surfacetype"] == "glass")
{
if (data.i > 1.5)
{
data.i = 0;
self thread knife();
}
}
else
{
// check if need to crouch
if (bulletTracePassed(startPos - (0, 0, 25), startPosForward - (0, 0, 25), false, self) && !self.bot.climbing)
self crouch();
}
}
/*
Bot moves towards the point
*/
@ -302,56 +351,14 @@ doBotMovement()
self endon("disconnect");
self endon("death");
FORWARDAMOUNT = 25;
wasMantling = false;
data = spawnStruct();
data.wasMantling = false;
for (i = 0;;i+=0.05)
for (data.i = 0; true; data.i += 0.05)
{
wait 0.05;
angles = self GetPlayerAngles();
// climb through windows
if (self isMantling())
{
wasMantling = true;
self crouch();
}
else if (wasMantling)
{
wasMantling = false;
self stand();
}
startPos = self.origin + (0, 0, 50);
startPosForward = startPos + anglesToForward((0, angles[1], 0)) * FORWARDAMOUNT;
bt = bulletTrace(startPos, startPosForward, false, self);
if (bt["fraction"] >= 1)
{
// check if need to jump
bt = bulletTrace(startPosForward, startPosForward - (0, 0, 40), false, self);
if (bt["fraction"] < 1 && bt["normal"][2] > 0.9 && i > 1.5 && !self isOnLadder())
{
i = 0;
self thread jump();
}
}
// check if need to knife glass
else if (bt["surfacetype"] == "glass")
{
if (i > 1.5)
{
i = 0;
self thread knife();
}
}
else
{
// check if need to crouch
if (bulletTracePassed(startPos - (0, 0, 25), startPosForward - (0, 0, 25), false, self) && !self.bot.climbing)
self crouch();
}
self doBotMovement_loop(data);
}
}
@ -412,12 +419,7 @@ watchHoldBreath()
/*
When the bot enters laststand, we fix the weapons
*/
onLastStand()
{
self endon("disconnect");
self endon("death");
while (true)
onLastStand_loop()
{
while (!self inLastStand())
wait 0.05;
@ -440,6 +442,19 @@ onLastStand()
while (self inLastStand())
wait 0.05;
}
/*
When the bot enters laststand, we fix the weapons
*/
onLastStand()
{
self endon("disconnect");
self endon("death");
while (true)
{
self onLastStand_loop();
}
}
/*
@ -494,14 +509,8 @@ sprint_watch()
/*
Update's the bot if it is reloading.
*/
reload_watch()
reload_watch_loop()
{
self endon("disconnect");
self endon("death");
for(;;)
{
self waittill("reload_start");
self.bot.isreloading = true;
while(true)
@ -512,29 +521,41 @@ reload_watch()
break;
weap = self GetCurrentWeapon();
if (weap == "none")
break;
if (self GetWeaponAmmoClip(weap) >= WeaponClipSize(weap))
break;
}
self.bot.isreloading = false;
}
}
/*
Bots will update its needed stance according to the nodes on the level. Will also allow the bot to sprint when it can.
Update's the bot if it is reloading.
*/
stance()
reload_watch()
{
self endon("disconnect");
self endon("death");
for(;;)
{
self waittill_either("finished_static_waypoints", "new_static_waypoint");
self waittill("reload_start");
self reload_watch_loop();
}
}
/*
Bots will update its needed stance according to the nodes on the level. Will also allow the bot to sprint when it can.
*/
stance_loop()
{
self.bot.climbing = false;
if(self.bot.isfrozen)
continue;
return;
toStance = "stand";
if(self.bot.next_wp != -1)
@ -573,22 +594,37 @@ stance()
chance *= 2;
if(toStance != "stand" || self.bot.isreloading || self.bot.issprinting || self.bot.isfraggingafter || self.bot.issmokingafter)
continue;
return;
if(randomInt(100) > chance)
continue;
return;
if(isDefined(self.bot.target) && self canFire(curweap) && self isInRange(self.bot.target.dist, curweap))
continue;
return;
if(self.bot.sprintendtime != -1 && time - self.bot.sprintendtime < 2000)
continue;
return;
if(!isDefined(self.bot.towards_goal) || DistanceSquared(self.origin, self.bot.towards_goal) < level.bots_minSprintDistance || getConeDot(self.bot.towards_goal, self.origin, self GetPlayerAngles()) < 0.75)
continue;
return;
self thread sprint();
}
/*
Bots will update its needed stance according to the nodes on the level. Will also allow the bot to sprint when it can.
*/
stance()
{
self endon("disconnect");
self endon("death");
for(;;)
{
self waittill_either("finished_static_waypoints", "new_static_waypoint");
self stance_loop();
}
}
/*
@ -815,18 +851,8 @@ targetObjUpdateNoTrace(obj)
/*
The main target thread, will update the bot's main target. Will auto target enemy players and handle script targets.
*/
target()
target_loop()
{
self endon("disconnect");
self endon("death");
for(;;)
{
wait 0.05;
if(self maps\mp\_flashgrenades::isFlashbanged())
continue;
myEye = self GetEyePos();
theTime = getTime();
myAngles = self GetPlayerAngles();
@ -982,7 +1008,7 @@ target()
}
if(hasTarget && isDefined(bestTargets[self.bot.target.entity getEntityNumber()+""]))
continue;
return;
closest = 2147483647;
toBeTarget = undefined;
@ -1011,6 +1037,24 @@ target()
self notify("new_enemy");
}
}
/*
The main target thread, will update the bot's main target. Will auto target enemy players and handle script targets.
*/
target()
{
self endon("disconnect");
self endon("death");
for(;;)
{
wait 0.05;
if(self maps\mp\_flashgrenades::isFlashbanged())
continue;
self target_loop();
}
}
/*
@ -1069,11 +1113,10 @@ watchToLook()
if(self.bot.target.dist <= level.bots_maxKnifeDistance)
continue;
curweap = self getCurrentWEapon();
if(!self canFire(curweap))
if(!self canFire(self getCurrentWEapon()))
continue;
if(!self isInRange(self.bot.target.dist, curweap))
if(!self isInRange(self.bot.target.dist, self getCurrentWEapon()))
continue;
if (self.bot.is_cur_sniper)
@ -1085,8 +1128,7 @@ watchToLook()
if (!getDvarInt("bots_play_jumpdrop"))
continue;
thetime = getTime();
if(isDefined(self.bot.jump_time) && thetime - self.bot.jump_time <= 5000)
if(isDefined(self.bot.jump_time) && getTime() - self.bot.jump_time <= 5000)
continue;
if(self.bot.target.rand <= self.pers["bots"]["behavior"]["strafe"])
@ -1094,7 +1136,7 @@ watchToLook()
if(self getStance() != "stand")
continue;
self.bot.jump_time = thetime;
self.bot.jump_time = getTime();
self jump();
}
else
@ -1102,7 +1144,7 @@ watchToLook()
if(getConeDot(self.bot.target.last_seen_pos, self.origin, self getPlayerAngles()) < 0.8 || self.bot.target.dist <= level.bots_noADSDistance)
continue;
self.bot.jump_time = thetime;
self.bot.jump_time = getTime();
self prone();
self notify("kill_goal");
wait 2.5;
@ -1111,7 +1153,6 @@ watchToLook()
}
}
/*
Assigns the bot's after target (bot will keep firing at a target after no sight or death)
*/
@ -1143,18 +1184,8 @@ clear_bot_after_target()
/*
This is the bot's main aimming thread. The bot will aim at its targets or a node its going towards. Bots will aim, fire, ads, grenade.
*/
aim()
aim_loop()
{
self endon("disconnect");
self endon("death");
for(;;)
{
wait 0.05;
if(level.inPrematchPeriod || level.gameEnded || self.bot.isfrozen || self maps\mp\_flashgrenades::isFlashbanged())
continue;
aimspeed = self.pers["bots"]["skill"]["aim_time"];
if(self IsStunned() || self isArtShocked())
@ -1240,7 +1271,7 @@ aim()
}
self botLookAt(last_pos + (0, 0, self getEyeHeight() + nadeAimOffset), aimspeed);
continue;
return;
}
if (trace_time)
@ -1248,12 +1279,12 @@ aim()
if(isplay)
{
if (!target IsPlayerModelOK())
continue;
return;
aimpos = target getTagOrigin( bone );
if (!isDefined(aimpos))
continue;
return;
aimpos += offset;
aimpos += aimoffset;
@ -1282,11 +1313,11 @@ aim()
{
self clear_bot_after_target();
self thread knife();
continue;
return;
}
if(!self canFire(curweap) || !self isInRange(dist, curweap))
continue;
return;
canADS = (self canAds(dist, curweap) && conedot > 0.75);
if (canADS)
@ -1313,7 +1344,7 @@ aim()
self thread start_bot_after_target(target);
}
continue;
return;
}
}
}
@ -1335,7 +1366,7 @@ aim()
self botLookAt(aimpos, aimspeed);
if(!self canFire(curweap) || !self isInRange(dist, curweap))
continue;
return;
canADS = (self canAds(dist, curweap) && conedot > 0.75);
if (canADS)
@ -1356,7 +1387,7 @@ aim()
if((!canADS || adsAmount >= 1.0 || self InLastStand() || self GetStance() == "prone") && (conedot > 0.95 || dist < level.bots_maxKnifeDistance) && getDvarInt("bots_play_fire"))
self botFire();
continue;
return;
}
if (self.bot.next_wp != -1 && isDefined(level.waypoints[self.bot.next_wp].angles) && false)
@ -1382,6 +1413,24 @@ aim()
self botLookAt(lookat + (0, 0, self getEyeHeight()), aimspeed);
}
}
/*
This is the bot's main aimming thread. The bot will aim at its targets or a node its going towards. Bots will aim, fire, ads, grenade.
*/
aim()
{
self endon("disconnect");
self endon("death");
for(;;)
{
wait 0.05;
if(level.inPrematchPeriod || level.gameEnded || self.bot.isfrozen || self maps\mp\_flashgrenades::isFlashbanged())
continue;
self aim_loop();
}
}
/*
@ -1486,31 +1535,8 @@ killWalkCauseNoWaypoints()
/*
This is the main walking logic for the bot.
*/
walk()
walk_loop()
{
self endon("disconnect");
self endon("death");
for(;;)
{
wait 0.05;
self botMoveTo(self.origin);
if (!getDvarInt("bots_play_move"))
continue;
if(level.inPrematchPeriod || level.gameEnded || self.bot.isfrozen || self.bot.stop_move)
continue;
if(self maps\mp\_flashgrenades::isFlashbanged())
{
self.bot.last_next_wp = -1;
self.bot.last_second_next_wp = -1;
self botMoveTo(self.origin + self GetVelocity()*500);
continue;
}
hasTarget = isDefined(self.bot.target) && isDefined(self.bot.target.entity);
if(hasTarget)
{
@ -1518,17 +1544,17 @@ walk()
if(self.bot.target.entity.classname == "script_vehicle" || self.bot.isfraggingafter || self.bot.issmokingafter)
{
continue;
return;
}
if(self.bot.target.isplay && self.bot.target.trace_time && self canFire(curweap) && self isInRange(self.bot.target.dist, curweap))
{
if (self InLastStand() || self GetStance() == "prone" || (self.bot.is_cur_sniper && self PlayerADS() > 0))
continue;
return;
if(self.bot.target.rand <= self.pers["bots"]["behavior"]["strafe"])
self strafe(self.bot.target.entity);
continue;
return;
}
}
@ -1594,6 +1620,37 @@ walk()
self.bot.next_wp = -1;
self.bot.second_next_wp = -1;
}
/*
This is the main walking logic for the bot.
*/
walk()
{
self endon("disconnect");
self endon("death");
for(;;)
{
wait 0.05;
self botMoveTo(self.origin);
if (!getDvarInt("bots_play_move"))
continue;
if(level.inPrematchPeriod || level.gameEnded || self.bot.isfrozen || self.bot.stop_move)
continue;
if(self maps\mp\_flashgrenades::isFlashbanged())
{
self.bot.last_next_wp = -1;
self.bot.last_second_next_wp = -1;
self botMoveTo(self.origin + self GetVelocity()*500);
continue;
}
self walk_loop();
}
}
/*
@ -1724,12 +1781,12 @@ doWalk(goal, dist, isScriptGoal)
self endon("kill_goal");
self endon("goal_internal");//so that the watchOnGoal notify can happen same frame, not a frame later
distsq = dist*dist;
dist *= dist;
if (isScriptGoal)
self thread doWalkScriptNotify();
self thread killWalkOnEvents();
self thread watchOnGoal(goal, distsq);
self thread watchOnGoal(goal, dist);
current = self initAStar(goal);
// skip waypoints we already completed to prevent rubber banding
@ -1739,9 +1796,7 @@ doWalk(goal, dist, isScriptGoal)
if (current >= 0)
{
// check if a waypoint is closer than the goal
wpOrg = level.waypoints[self.bot.astar[current]].origin;
ppt = PlayerPhysicsTrace(self.origin + (0,0,32), wpOrg, false, self);
if (DistanceSquared(self.origin, wpOrg) < DistanceSquared(self.origin, goal) || DistanceSquared(wpOrg, ppt) > 1.0)
if (DistanceSquared(self.origin, level.waypoints[self.bot.astar[current]].origin) < DistanceSquared(self.origin, goal) || DistanceSquared(level.waypoints[self.bot.astar[current]].origin, PlayerPhysicsTrace(self.origin + (0,0,32), level.waypoints[self.bot.astar[current]].origin, false, self)) > 1.0)
{
while(current >= 0)
{
@ -1765,7 +1820,7 @@ doWalk(goal, dist, isScriptGoal)
self.bot.second_next_wp = -1;
self notify("finished_static_waypoints");
if(DistanceSquared(self.origin, goal) > distsq)
if(DistanceSquared(self.origin, goal) > dist)
{
self.bot.last_next_wp = -1;
self.bot.last_second_next_wp = -1;
@ -1775,7 +1830,7 @@ doWalk(goal, dist, isScriptGoal)
self notify("finished_goal");
wait 1;
if(DistanceSquared(self.origin, goal) > distsq)
if(DistanceSquared(self.origin, goal) > dist)
self notify("bad_path_internal");
}

File diff suppressed because it is too large Load Diff