greatly reduce var usage

This commit is contained in:
ineedbots 2021-05-26 22:25:05 -06:00
parent bb74baec06
commit 30eae3d3d9
3 changed files with 2977 additions and 2691 deletions

View File

@ -365,12 +365,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");
@ -440,17 +436,26 @@ diffBots()
player.pers["bots"]["skill"]["base"] = var_skill;
}
}
}
/*
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");
@ -569,22 +574,26 @@ 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)
@ -684,6 +693,22 @@ addBots()
if (isDefined(tempBot))
tempBot RemoveTestClient();
}
}
/*
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

@ -207,19 +207,8 @@ onPlayerSpawned()
/*
Bot moves towards the point
*/
doBotMovement()
doBotMovement_loop(data)
{
self endon("disconnect");
self endon("death");
FORWARDAMOUNT = 25;
wasMantling = false;
for (i=0;;i+=0.05)
{
wait 0.05;
waittillframeend;
move_To = self.bot.moveTo;
angles = self GetPlayerAngles();
dir = (0, 0, 0);
@ -247,35 +236,35 @@ doBotMovement()
// climb through windows
if (self isMantling())
{
wasMantling = true;
data.wasMantling = true;
self crouch();
}
else if (wasMantling)
else if (data.wasMantling)
{
wasMantling = false;
data.wasMantling = false;
self stand();
}
startPos = self.origin + (0, 0, 50);
startPosForward = startPos + anglesToForward((0, angles[1], 0)) * FORWARDAMOUNT;
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 && i > 1.5 && !self isOnLadder())
if (bt["fraction"] < 1 && bt["normal"][2] > 0.9 && data.i > 1.5 && !self isOnLadder())
{
i = 0;
data.i = 0;
self thread jump();
}
}
// check if need to knife glass
else if (bt["surfacetype"] == "glass")
{
if (i > 1.5)
if (data.i > 1.5)
{
i = 0;
data.i = 0;
self thread knife();
}
}
@ -288,6 +277,25 @@ doBotMovement()
// move!
self botMovement(int(dir[0]), int(dir[1]));
}
/*
Bot moves towards the point
*/
doBotMovement()
{
self endon("disconnect");
self endon("death");
data = spawnStruct();
data.wasMantling = false;
for (data.i = 0; true; data.i += 0.05)
{
wait 0.05;
waittillframeend;
self doBotMovement_loop(data);
}
}
@ -374,8 +382,7 @@ watchC4Thrown(c4)
break;
}
weap = self getCurrentWeapon();
if ( weap != "satchel_charge_mp" )
if ( self getCurrentWeapon() != "satchel_charge_mp" )
self notify( "alt_detonate" );
else
self thread pressFire();
@ -438,13 +445,8 @@ watchHoldBreath()
/*
When the bot enters laststand, we fix the weapons
*/
onLastStand()
onLastStand_loop()
{
self endon("disconnect");
self endon("death");
while (true)
{
while (!self inLastStand())
wait 0.05;
@ -469,6 +471,19 @@ onLastStand()
waittillframeend;
if (isDefined(self.previousPrimary) && self.previousPrimary != "none")
self changeToWeap(self.previousPrimary);
}
/*
When the bot enters laststand, we fix the weapons
*/
onLastStand()
{
self endon("disconnect");
self endon("death");
while (true)
{
self onLastStand_loop();
}
}
@ -524,14 +539,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)
@ -550,25 +559,33 @@ reload_watch()
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)
@ -607,21 +624,36 @@ 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();
}
}
@ -849,18 +881,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 isFlared())
continue;
myEye = self GetEyePos();
theTime = getTime();
myAngles = self GetPlayerAngles();
@ -1016,7 +1038,7 @@ target()
}
if(hasTarget && isDefined(bestTargets[self.bot.target.entity getEntityNumber()+""]))
continue;
return;
closest = 2147483647;
toBeTarget = undefined;
@ -1044,6 +1066,24 @@ target()
self.bot.target = toBeTarget;
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 isFlared())
continue;
self target_loop();
}
}
@ -1103,11 +1143,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)
@ -1119,8 +1158,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"])
@ -1128,7 +1166,7 @@ watchToLook()
if(self getStance() != "stand")
continue;
self.bot.jump_time = thetime;
self.bot.jump_time = getTime();
self jump();
}
else
@ -1136,7 +1174,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;
@ -1145,7 +1183,6 @@ watchToLook()
}
}
/*
Assigns the bot's after target (bot will keep firing at a target after no sight or death)
*/
@ -1177,18 +1214,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 isFlared())
continue;
aimspeed = self.pers["bots"]["skill"]["aim_time"];
if(self IsGased() || self isArtShocked())
@ -1278,7 +1305,7 @@ aim()
}
self thread bot_lookat(last_pos + (0, 0, self getEyeHeight() + nadeAimOffset), aimspeed);
continue;
return;
}
if (trace_time)
@ -1286,12 +1313,12 @@ aim()
if(isplay)
{
if (!target IsPlayerModelOK())
continue;
return;
aimpos = target getTagOrigin( bone );
if (!isDefined(aimpos))
continue;
return;
aimpos += offset;
aimpos += aimoffset;
@ -1320,13 +1347,11 @@ aim()
{
self clear_bot_after_target();
self thread knife();
continue;
return;
}
if(!self canFire(curweap) || !self isInRange(dist, curweap))
continue;
//c4 logic here, but doesnt work anyway
return;
canADS = (self canAds(dist, curweap) && conedot > 0.75);
if (canADS)
@ -1353,7 +1378,7 @@ aim()
self thread start_bot_after_target(target);
}
continue;
return;
}
}
}
@ -1375,7 +1400,7 @@ aim()
self thread bot_lookat(aimpos, aimspeed);
if(!self canFire(curweap) || !self isInRange(dist, curweap))
continue;
return;
canADS = (self canAds(dist, curweap) && conedot > 0.75);
if (canADS)
@ -1396,7 +1421,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)
@ -1421,6 +1446,24 @@ aim()
if(isDefined(lookat))
self thread bot_lookat(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 isFlared())
continue;
self aim_loop();
}
}
@ -1529,52 +1572,29 @@ 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 isFlared())
{
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)
{
curweap = self getCurrentWeapon();
if ((isPlayer(self.bot.target.entity) && self.bot.target.entity isInVehicle()) || self.bot.target.entity.classname == "script_vehicle")
continue;
return;
if(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;
}
}
@ -1639,6 +1659,37 @@ walk()
self.bot.towards_goal = undefined;
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 isFlared())
{
self.bot.last_next_wp = -1;
self.bot.last_second_next_wp = -1;
self botMoveTo(self.origin + self GetVelocity()*500);
continue;
}
self walk_loop();
}
}
@ -1770,12 +1821,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
@ -1785,9 +1836,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)
{
@ -1811,7 +1860,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;
@ -1821,7 +1870,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