Repository navigation
Added capturing of non-combat units with related bugfixes - #1137
Open
zack-the-coding-actuary wants to merge 5 commits into
Open
zack-the-coding-actuary wants to merge 5 commits into
zack-the-coding-actuary wants to merge 5 commits into
Conversation
- Await each CAPTURE animation before removing the unit, so the animations play one after another instead of the unit disappearing immediately - Iterate over a copy of the tile's unit list in Fight(), since RemoveFromPlay() removes units from location.unitsOnTile and the modified collection threw an InvalidOperationException that stopped Move() before the attacker took the defeated unit's tile
- Play each CAPTURE animation in sequence (awaited) before the unit is removed or transferred, so the animation is visible instead of the unit vanishing immediately - Iterate over a copy of the tile's unit list in Fight(), since RemoveFromPlay() modifies location.unitsOnTile and the modified collection threw an InvalidOperationException that stopped Move() before the attacker advanced - Captured settlers are removed and replaced with workers for the attacker, one per population cost (minimum 1), using the cheapest worker prototype the attacker can build and keeping the settler's original nationality - Other non-combat units, including workers, are transferred to the attacker if the attacker has the required tech: they are removed from the previous owner's unit list and AI, added to the attacker's list, and both players' active tiles are recomputed. Units the attacker can't build are destroyed - Barbarians still destroy non-combat units rather than capturing them - In Move(), only hostile defenders now block the attacker from advancing after a win, so captured units and spawned workers left on the tile no longer stop it from taking the tile - GameData.SpawnUnit now returns the spawned MapUnit; its parameters are unchanged
…ng, and add capture tests - A non-combat unit is now only captured if the attacker knows its required tech and the attacker's civ can produce it (producibleBy); otherwise it is destroyed, e.g. an Egyptian attacker cannot capture a Portuguese scout - Non-combat units can no longer retreat from battle, so units with more than one movement point such as scouts are always captured or killed instead of sometimes escaping barbarians - Add NonCombatUnitCaptureTest covering captured workers (ownership, nationality, AI detachment, slave work speed and recapture by the original civ), settlers becoming one worker per population cost (minimum 1) using the cheapest buildable worker, and capture requiring both the tech and producibility regardless of missing resources - The tests also cover barbarians destroying non-combat units instead of capturing them, mixed stacks, combat units protecting non-combat units, and the attacker advancing onto the tile after every outcome without being blocked by friendly units
…defender retreating - Move the capture/destroy logic into a private CaptureOrDestroyNonCombatUnits method, which only affects non-combat units hostile to the attacker - Call it when an attacker moves onto a tile holding only non-combat units, and also after an attacker wins a battle and no hostile combat unit able to defend the tile remains, so surviving non-combat units surrender and the attacker takes the tile - Barbarians now use the same path but always destroy non-combat units (DEATH animation) instead of capturing them, replacing the special case that sent them through a regular battle - A combat defender can no longer retreat if it is the last land combat unit on its tile, so it cannot leave non-combat units undefended - Add tests for capture after the last combat unit dies (workers captured, settlers converted, uncapturable units destroyed, barbarians destroying everything), friendly units being left alone, nothing happening when the attacker loses or another combat unit still defends, and the retreat rule
- Replace the "more than one land combat unit on the tile" requirement for retreating, which stopped a lone defender from ever retreating, with a check that only blocks the retreat when it would leave non-combat units on the tile without a land combat unit protecting them - Add a test that a lone combat defender with nothing to protect still retreats
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Added all the mechanics I think we should need for proper non-combat unit capture, including addressing the bug in #395. Total changes include:
Capturing
FightmethodRetreat logic
Future TODOs
Threw in a lot of tests too since there were a lot of edge cases to go over, lmk if you guys have questions or changes, thanks!