fix(game): release a banished race's assets during turn generation
TurnWipeExtinctRaces iterated only non-extinct races, so an administratively banished race (flagged extinct, TTL untouched) was never wiped: its planets stayed owned and its ships lingered, while the race itself could no longer act. The loop now covers every race and wipes when either an active race's TTL has run out (idle / quit) or an extinct race still holds assets (banish). The asset check makes repeated passes idempotent. wipeRace already matched the rules for exclusion (ships removed, planets uninhabited, industry and capital cleared, material retained), so the behaviour is just documented in game/README.md. Tests: banish releases planets and ships on the next turn (and is idempotent); idle-timeout wipe still fires under the new iterator. Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -117,13 +117,34 @@ func (c *Cache) raceTechLevel(ri int, t game.Tech, v float64) {
|
||||
}
|
||||
|
||||
func (c *Cache) TurnWipeExtinctRaces() {
|
||||
for i := range c.listRaceActingIdx() {
|
||||
if (c.g.Race[i].Extinct && c.g.Race[i].TTL > 0) || (!c.g.Race[i].Extinct && c.g.Race[i].TTL == 0) {
|
||||
for i := range c.listRaceIdx() {
|
||||
r := &c.g.Race[i]
|
||||
// Idle timeout or voluntary quit: a still-active race whose TTL ran
|
||||
// out. Administrative banish: a race already flagged extinct that
|
||||
// still holds assets to release. Once a race is wiped it owns nothing,
|
||||
// so the asset check keeps this idempotent across later turns.
|
||||
if (!r.Extinct && r.TTL == 0) || (r.Extinct && c.raceHasAssets(i)) {
|
||||
c.wipeRace(i)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// raceHasAssets reports whether the race still owns a planet or a ship group.
|
||||
func (c *Cache) raceHasAssets(ri int) bool {
|
||||
id := c.g.Race[ri].ID
|
||||
for i := range c.g.Map.Planet {
|
||||
if c.g.Map.Planet[i].OwnedBy(id) {
|
||||
return true
|
||||
}
|
||||
}
|
||||
for i := range c.g.ShipGroups {
|
||||
if c.g.ShipGroups[i].OwnerID == id {
|
||||
return true
|
||||
}
|
||||
}
|
||||
return false
|
||||
}
|
||||
|
||||
func (c *Cache) wipeRace(ri int) {
|
||||
c.validateRaceIndex(ri)
|
||||
r := &c.g.Race[ri]
|
||||
|
||||
Reference in New Issue
Block a user