lgbot: never take over or kick a human named lgbot; live values in show; direction debug

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
esefandClaude Opus 5.5 committed 2026-10-15 14:37:30 +03:00
1 parent d2fb4be349
commit aac104206b
3 files changed
+81 -13

No files matched your search

+27 -6
View File
@@ -30,6 +30,11 @@ def is_bot(steam_id):
return steam_id == 0 or steam_id >= BOT_STEAM_ID
def is_lgbot(name, steam_id):
"""The training bot: named lgbot AND a bot (a human can't take it over by renaming)."""
return name.lower() == "lgbot" and is_bot(steam_id)
def to_int(text):
"""Cvar text -> int, None when unset or junk (so a typo falls back to the preset)."""
try:
@@ -131,6 +136,7 @@ if minqlx:
self.settings, self.read_at, self.log_at = None, 0.0, 0.0
self.debug = self.target_bots = False
self.failed = False
self.last_cmd, self.slow_frames, self.stuck = None, 0, 0 # debug stats
self.add_hook("frame", self.handle_frame)
def handle_frame(self):
@@ -152,7 +158,7 @@ if minqlx:
def tick(self):
players = self.players()
bot = next((p for p in players if p.clean_name.lower() == "lgbot"), None)
bot = next((p for p in players if is_lgbot(p.clean_name, p.steam_id)), None)
if bot is None or not bot.is_alive:
return
now = time.time()
@@ -175,9 +181,24 @@ if minqlx:
vx, vy = steer((bpos.x, bpos.y), (tpos.x, tpos.y), direction, s, want)
vel = bot.velocity()
bot.velocity(x=vx, y=vy, z=fix_z(vel.z))
if self.debug and now - self.log_at >= 1.0:
if self.debug:
self.debug_line(now, vel, (vx, vy), tpos, bpos, want, direction)
def debug_line(self, now, vel, cmd, tpos, bpos, want, direction):
# cos = how well last frame's command survived the frame (1 = exactly our direction);
# stuck = times actual speed stayed under half the command for > 0.5 s (walls)
actual = math.hypot(vel.x, vel.y)
cos = 0.0
if self.last_cmd:
lc = math.hypot(*self.last_cmd)
if lc > 1 and actual > 1:
cos = (vel.x * self.last_cmd[0] + vel.y * self.last_cmd[1]) / (lc * actual)
self.slow_frames = self.slow_frames + 1 if actual < lc / 2 else 0
if self.slow_frames == 20:
self.stuck += 1
self.last_cmd = cmd
if now - self.log_at >= 1.0:
self.log_at = now
dist = math.hypot(tpos.x - bpos.x, tpos.y - bpos.y)
self.logger.info("lgbot dist=%d want=%d dir=%d cmd=%d actual=%d z=%d",
dist, want, direction, math.hypot(vx, vy),
math.hypot(vel.x, vel.y), vel.z)
self.logger.info("lgbot dist=%d want=%d dir=%d cmd=%d actual=%d cos=%.2f stuck=%d z=%d",
math.hypot(tpos.x - bpos.x, tpos.y - bpos.y), want, direction,
math.hypot(*cmd), actual, cos, self.stuck, vel.z)