Greatly reduce var usage

This commit is contained in:
ineedbots 2021-05-27 14:14:49 -06:00
parent 40d5b03bcf
commit 06bedd0df9
3 changed files with 4136 additions and 3785 deletions

View File

@ -309,11 +309,8 @@ fixKoth()
/*
Adds a notify when the airdrop is dropped
*/
addNotifyOnAirdrops()
addNotifyOnAirdrops_loop()
{
for (;;)
{
wait 1;
dropCrates = getEntArray( "care_package", "targetname" );
for (i = dropCrates.size - 1; i >= 0; i--)
@ -329,6 +326,17 @@ addNotifyOnAirdrops()
airdrop.doingPhysics = true;
airdrop thread doNotifyOnAirdrop();
}
}
/*
Adds a notify when the airdrop is dropped
*/
addNotifyOnAirdrops()
{
for (;;)
{
wait 1;
addNotifyOnAirdrops_loop();
}
}
@ -365,12 +373,8 @@ onPlayerConnect()
/*
Watches players with scrambler perk
*/
watchScrabler()
watchScrabler_loop()
{
for (;;)
{
wait 1;
for ( i = level.players.size - 1; i >= 0; i-- )
{
player = level.players[i];
@ -403,6 +407,18 @@ watchScrabler()
player2.bot_isScrambled = true;
}
}
}
/*
Watches players with scrambler perk
*/
watchScrabler()
{
for (;;)
{
wait 1;
watchScrabler_loop();
}
}
@ -479,12 +495,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");
@ -554,17 +566,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");
@ -683,22 +704,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)
@ -798,6 +822,22 @@ addBots()
if (isDefined(tempBot))
kick( tempBot getEntityNumber(), "EXE_PLAYERKICKED" );
}
}
/*
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

@ -238,14 +238,8 @@ onWeaponChange()
/*
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)
@ -264,6 +258,20 @@ reload_watch()
break;
}
self.bot.isreloading = false;
}
/*
Update's the bot if it is reloading.
*/
reload_watch()
{
self endon("disconnect");
self endon("death");
for(;;)
{
self waittill("reload_start");
self reload_watch_loop();
}
}
@ -288,13 +296,8 @@ sprint_watch()
/*
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;
@ -317,6 +320,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();
}
}
@ -509,8 +525,7 @@ watchC4Thrown(c4)
break;
}
weap = self getCurrentWeapon();
if ( weap != "c4_mp" )
if ( self getCurrentWeapon() != "c4_mp" )
self notify( "alt_detonate" );
else
self thread pressFire();
@ -519,19 +534,8 @@ watchC4Thrown(c4)
/*
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);
@ -559,35 +563,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();
}
}
@ -600,6 +604,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);
}
}
@ -622,6 +645,33 @@ watchHoldBreath()
}
}
/*
Throws back frag grenades
*/
grenade_danager_loop()
{
myEye = self getEye();
for (i = level.bots_fragList.count-1; i >= 0; i--)
{
frag = level.bots_fragList.data[i];
if (level.teamBased && frag.team == self.team)
continue;
if (lengthSquared(frag.velocity) > 10000)
continue;
if(DistanceSquared(self.origin, frag.origin) > 20000)
continue;
if (!bulletTracePassed( myEye, frag.origin, false, frag.grenade ))
continue;
self thread frag();
break;
}
}
/*
Throws back frag grenades
*/
@ -649,46 +699,15 @@ grenade_danager()
if (!getDvarInt("bots_play_nade"))
continue;
myEye = self getEye();
for (i = level.bots_fragList.count-1; i >= 0; i--)
{
frag = level.bots_fragList.data[i];
if (level.teamBased && frag.team == self.team)
continue;
if (lengthSquared(frag.velocity) > 10000)
continue;
if(DistanceSquared(self.origin, frag.origin) > 20000)
continue;
if (!bulletTracePassed( myEye, frag.origin, false, frag.grenade ))
continue;
self thread frag();
break;
}
self grenade_danager_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()
stance_loop()
{
self endon("disconnect");
self endon("death");
for(;;)
{
self waittill_either("finished_static_waypoints", "new_static_waypoint");
self.bot.climbing = false;
if(self.bot.isfrozen || self IsUsingRemote())
continue;
toStance = "stand";
if(self.bot.next_wp != -1)
toStance = level.waypoints[self.bot.next_wp].type;
@ -715,32 +734,50 @@ stance()
else
self prone();
curweap = self getCurrentWeapon();
time = getTime();
chance = self.pers["bots"]["behavior"]["sprint"];
if (time - self.lastSpawnTime < 5000)
if (getTime() - self.lastSpawnTime < 5000)
chance *= 2;
if(isDefined(self.bot.script_goal) && DistanceSquared(self.origin, self.bot.script_goal) > 256*256)
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;
if(isDefined(self.bot.target) && self canFire(self getCurrentWeapon()) && self isInRange(self.bot.target.dist, self getCurrentWeapon()))
return;
if(self.bot.sprintendtime != -1 && time - self.bot.sprintendtime < 2000)
continue;
if(self.bot.sprintendtime != -1 && getTime() - self.bot.sprintendtime < 2000)
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.bot.climbing = false;
if(self.bot.isfrozen || self IsUsingRemote())
continue;
self stance_loop();
}
}
@ -911,21 +948,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("spawned_player");
for(;;)
{
wait 0.05;
if (!isAlive(self))
return;
if(self maps\mp\_flashgrenades::isFlashbanged())
continue;
myEye = self GetEye();
theTime = getTime();
myAngles = self GetPlayerAngles();
@ -1105,7 +1129,7 @@ target()
}
if(hasTarget && isDefined(bestTargets[self.bot.target.entity getEntityNumber()+""]))
continue;
return;
closest = 2147483647;
toBeTarget = undefined;
@ -1133,6 +1157,27 @@ 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("spawned_player");
for(;;)
{
wait 0.05;
if (!isAlive(self))
return;
if(self maps\mp\_flashgrenades::isFlashbanged())
continue;
self target_loop();
}
}
@ -1192,11 +1237,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)
@ -1208,8 +1252,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"])
@ -1217,7 +1260,7 @@ watchToLook()
if(self getStance() != "stand")
continue;
self.bot.jump_time = thetime;
self.bot.jump_time = getTime();
self thread jump();
}
else
@ -1225,7 +1268,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;
@ -1265,21 +1308,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("spawned_player"); // for remote killstreaks.
for(;;)
{
wait 0.05;
if (!isAlive(self))
return;
if(!gameFlag( "prematch_done" ) || level.gameEnded || self.bot.isfrozen || self maps\mp\_flashgrenades::isFlashbanged())
continue;
aimspeed = self.pers["bots"]["skill"]["aim_time"];
if(self IsStunned() || self isArtShocked())
aimspeed = 1;
@ -1306,7 +1336,7 @@ aim()
if (curweap == "javelin_mp" && getDvarInt("bots_play_fire"))
self botFire(curweap);
continue;
return;
}
if(isDefined(self.bot.target) && isDefined(self.bot.target.entity))
@ -1384,7 +1414,7 @@ aim()
self thread bot_lookat(last_pos + (0, 0, self getEyeHeight() + nadeAimOffset), aimspeed);
else
self thread bot_lookat(last_pos, aimspeed);
continue;
return;
}
if (trace_time)
@ -1425,11 +1455,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)
@ -1448,7 +1478,7 @@ aim()
}
if(curweap == "at4_mp" && entIsVehicle(self.bot.target.entity) && (!IsDefined( self.stingerStage ) || self.stingerStage != 2))
continue;
return;
if (trace_time > reaction_time)
{
@ -1459,7 +1489,7 @@ aim()
self thread start_bot_after_target(target);
}
continue;
return;
}
}
}
@ -1483,7 +1513,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)
@ -1504,7 +1534,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(curweap);
continue;
return;
}
if (self.bot.next_wp != -1 && isDefined(level.waypoints[self.bot.next_wp].angles) && false)
@ -1529,6 +1559,27 @@ 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("spawned_player"); // for remote killstreaks.
for(;;)
{
wait 0.05;
if (!isAlive(self))
return;
if(!gameFlag( "prematch_done" ) || level.gameEnded || self.bot.isfrozen || self maps\mp\_flashgrenades::isFlashbanged())
continue;
self aim_loop();
}
}
@ -1657,34 +1708,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.gameEnded || !gameFlag( "prematch_done" ) || self.bot.isfrozen || self.bot.stop_move)
continue;
if (self IsUsingRemote())
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)) || isDefined(self.bot.jav_loc));
if(hasTarget)
{
@ -1692,17 +1717,17 @@ walk()
if(isDefined(self.bot.jav_loc) || entIsVehicle(self.bot.target.entity) || 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;
}
}
@ -1767,6 +1792,40 @@ 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.gameEnded || !gameFlag( "prematch_done" ) || self.bot.isfrozen || self.bot.stop_move)
continue;
if (self IsUsingRemote())
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();
}
}
@ -1898,12 +1957,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
@ -1913,9 +1972,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)
{
@ -1939,7 +1996,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;
@ -1949,7 +2006,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