feat: remove unreachable routes

This commit is contained in:
Ilia Denisov
2026-01-23 00:43:21 +02:00
parent 812e0d4afd
commit abf72c16b4
3 changed files with 50 additions and 5 deletions
+20 -1
View File
@@ -92,7 +92,7 @@ func (c *Cache) RemovePlanetRoute(rt game.RouteType, origin uint) {
}
// TODO: NOT IN THIS FUNC: remove routes if planet became uninhabited (bombing, quit game, etc)
func (c *Cache) EnrouteGroups() {
func (c *Cache) SendRoutedGroups() {
for pi := range c.g.Map.Planet {
if len(c.g.Map.Planet[pi].Route) == 0 {
continue
@@ -200,6 +200,25 @@ func (c *Cache) TurnUnloadEnroutedGroups() {
for _, rt := range []game.RouteType{game.RouteMaterial, game.RouteCapital} {
c.doUnload(c.listRoutedUnloadShipGroupIds(p.Number, rt))
}
p.UnpackColonists()
p.UnpackCapital()
}
}
func (c *Cache) RemoveUnreachableRoutes() {
for i := range c.g.Map.Planet {
p1 := &c.g.Map.Planet[i]
if p1.Owner == uuid.Nil {
continue
}
ri := c.RaceIndex(p1.Owner)
for rt, destination := range p1.Route {
p2 := c.MustPlanet(destination)
rangeToDestination := util.ShortDistance(c.g.Map.Width, c.g.Map.Height, p1.X, p1.Y, p2.X, p2.Y)
if rangeToDestination > c.g.Race[ri].FlightDistance() {
delete(p1.Route, rt)
}
}
}
}