Luigi commited on
Commit
e22fa58
·
1 Parent(s): 726e858

debug: Add extensive logging for unit movement bug investigation

Browse files

- Log when move_unit command is received
- Log unit IDs and targets being set
- Log actual movement with positions
- Log when units reach destination
- Added DEBUG_MOVEMENT_BUG.md with investigation guide

Files changed (1) hide show
  1. app.py +12 -0
app.py CHANGED
@@ -676,11 +676,17 @@ class ConnectionManager:
676
  dist = (dx*dx + dy*dy) ** 0.5
677
 
678
  if dist > 5:
 
679
  unit.position.x += (dx / dist) * unit.speed
680
  unit.position.y += (dy / dist) * unit.speed
681
  # Apply dispersion after movement
682
  self.apply_unit_dispersion(unit)
 
 
 
 
683
  else:
 
684
  unit.target = None
685
  unit.manual_order = False # Clear manual order flag when destination reached
686
  # If Harvester reached manual destination, resume AI
@@ -1133,16 +1139,20 @@ class ConnectionManager:
1133
  if cmd_type == "move_unit":
1134
  unit_ids = command.get("unit_ids", [])
1135
  target = command.get("target")
 
1136
  if target and "x" in target and "y" in target:
1137
  base_target = Position(target["x"], target["y"])
 
1138
 
1139
  # If multiple units, spread them in a formation
1140
  if len(unit_ids) > 1:
 
1141
  # Formation pattern: circular spread around target
1142
  radius = 30.0 # Distance between units in formation
1143
  for idx, uid in enumerate(unit_ids):
1144
  if uid in self.game_state.units:
1145
  unit = self.game_state.units[uid]
 
1146
 
1147
  # Calculate offset position in circular formation
1148
  angle = (idx * 360.0 / len(unit_ids)) * (3.14159 / 180.0)
@@ -1167,9 +1177,11 @@ class ConnectionManager:
1167
  unit.ore_target = None
1168
  else:
1169
  # Single unit - move to exact target
 
1170
  for uid in unit_ids:
1171
  if uid in self.game_state.units:
1172
  unit = self.game_state.units[uid]
 
1173
  unit.target = base_target
1174
 
1175
  # FIX: Clear combat target and set manual order flag
 
676
  dist = (dx*dx + dy*dy) ** 0.5
677
 
678
  if dist > 5:
679
+ old_x, old_y = unit.position.x, unit.position.y
680
  unit.position.x += (dx / dist) * unit.speed
681
  unit.position.y += (dy / dist) * unit.speed
682
  # Apply dispersion after movement
683
  self.apply_unit_dispersion(unit)
684
+
685
+ # Debug log for movement (only log occasionally to avoid spam)
686
+ if self.game_state.tick % 20 == 0: # Every second (20 ticks/sec)
687
+ print(f" 🚶 Unit {unit.id} ({unit.type}) moving: ({old_x:.1f},{old_y:.1f}) -> ({unit.position.x:.1f},{unit.position.y:.1f}), dist={dist:.1f}")
688
  else:
689
+ print(f" ✅ Unit {unit.id} ({unit.type}) reached destination ({unit.position.x:.1f},{unit.position.y:.1f})")
690
  unit.target = None
691
  unit.manual_order = False # Clear manual order flag when destination reached
692
  # If Harvester reached manual destination, resume AI
 
1139
  if cmd_type == "move_unit":
1140
  unit_ids = command.get("unit_ids", [])
1141
  target = command.get("target")
1142
+ print(f"🎮 MOVE_UNIT command received: unit_ids={unit_ids}, target={target}")
1143
  if target and "x" in target and "y" in target:
1144
  base_target = Position(target["x"], target["y"])
1145
+ print(f" Moving to position ({base_target.x:.1f}, {base_target.y:.1f})")
1146
 
1147
  # If multiple units, spread them in a formation
1148
  if len(unit_ids) > 1:
1149
+ print(f" Setting formation for {len(unit_ids)} units")
1150
  # Formation pattern: circular spread around target
1151
  radius = 30.0 # Distance between units in formation
1152
  for idx, uid in enumerate(unit_ids):
1153
  if uid in self.game_state.units:
1154
  unit = self.game_state.units[uid]
1155
+ print(f" Unit {uid} ({unit.type}) - setting target")
1156
 
1157
  # Calculate offset position in circular formation
1158
  angle = (idx * 360.0 / len(unit_ids)) * (3.14159 / 180.0)
 
1177
  unit.ore_target = None
1178
  else:
1179
  # Single unit - move to exact target
1180
+ print(f" Setting single unit target")
1181
  for uid in unit_ids:
1182
  if uid in self.game_state.units:
1183
  unit = self.game_state.units[uid]
1184
+ print(f" Unit {uid} ({unit.type}) at ({unit.position.x:.1f},{unit.position.y:.1f}) -> ({base_target.x:.1f},{base_target.y:.1f})")
1185
  unit.target = base_target
1186
 
1187
  # FIX: Clear combat target and set manual order flag