Skip to content

Commit

Permalink
dont consider winner when killing non-water units
Browse files Browse the repository at this point in the history
  • Loading branch information
kazzmir committed Feb 9, 2025
1 parent 8a1736a commit 31f0571
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
12 changes: 7 additions & 5 deletions game/magic/game/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -4461,8 +4461,10 @@ func (game *Game) doCombat(yield coroutine.YieldFunc, attacker *playerlib.Player

// ebiten.SetCursorMode(ebiten.CursorModeVisible)

// FIXME: handle spells like recall hero

// remove dead units
killUnits := func (player *playerlib.Player, stack *playerlib.UnitStack, winner bool, landscape combat.CombatLandscape){
killUnits := func (player *playerlib.Player, stack *playerlib.UnitStack, landscape combat.CombatLandscape){
// first remove sailing units
for _, unit := range stack.Units() {
if unit.IsSailing() && unit.GetHealth() <= 0 {
Expand All @@ -4475,9 +4477,9 @@ func (game *Game) doCombat(yield coroutine.YieldFunc, attacker *playerlib.Player
for _, unit := range stack.Units() {
dead := unit.GetHealth() <= 0

// if combat was on water and this player won but there are no sailing ships left then all units should die
// if combat was on water and there are no sailing ships left then all units should die
// FIXME: handle the case that there were originally two ships and one died, thus not being able to transport some units
if winner && landscape == combat.CombatLandscapeWater && unit.IsLandWalker() && !transport {
if landscape == combat.CombatLandscapeWater && unit.IsLandWalker() && !transport {
dead = true
}

Expand All @@ -4492,8 +4494,8 @@ func (game *Game) doCombat(yield coroutine.YieldFunc, attacker *playerlib.Player
}
}

killUnits(attacker, attackerStack, state == combat.CombatStateAttackerWin, landscape)
killUnits(defender, defenderStack, state == combat.CombatStateDefenderWin, landscape)
killUnits(attacker, attackerStack, landscape)
killUnits(defender, defenderStack, landscape)

if showHeroNotice {
game.doNotice(yield, "One or more heroes died in combat. You must redistribute their equipment.")
Expand Down
12 changes: 6 additions & 6 deletions test/overworld/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3471,19 +3471,20 @@ func createScenario41(cache *lbx.LbxCache) *gamelib.Game {
ex, ey, _ := game.FindValidCityLocation(game.Plane)

city2 := citylib.MakeCity("Test City", ex, ey, data.RaceHighElf, enemy1.Wizard.Banner, enemy1.TaxRate, game.BuildingInfo, game.CurrentMap(), game)
city2.Population = 14000
city2.Population = 20000
city2.Plane = data.PlaneArcanus
city2.Banner = enemy1.Wizard.Banner
city2.Buildings.Insert(buildinglib.BuildingSummoningCircle)
city2.ProducingBuilding = buildinglib.BuildingGranary
city2.ProducingUnit = units.UnitNone
city2.Race = wizard.Race
city2.Farmers = 11
city2.Farmers = 17
city2.Workers = 3
city2.Wall = false

city2.AddBuilding(buildinglib.BuildingShrine)
city2.AddBuilding(buildinglib.BuildingGranary)
city2.AddBuilding(buildinglib.BuildingFarmersMarket)

city2.ResetCitizens(nil)

Expand All @@ -3507,10 +3508,9 @@ func createScenario41(cache *lbx.LbxCache) *gamelib.Game {
return game
}

for range 6 {
use := candidates[rand.N(len(candidates))]
enemy1.AddUnit(units.MakeOverworldUnitFromUnit(units.Warship, use.X, use.Y, data.PlaneArcanus, enemy1.Wizard.Banner, nil))
}
use := candidates[rand.N(len(candidates))]
enemy1.AddUnit(units.MakeOverworldUnitFromUnit(units.Warship, use.X, use.Y, data.PlaneArcanus, enemy1.Wizard.Banner, nil))
enemy1.AddUnit(units.MakeOverworldUnitFromUnit(units.Warship, use.X, use.Y, data.PlaneArcanus, enemy1.Wizard.Banner, nil))

game.Camera.Center(x, y)

Expand Down

0 comments on commit 31f0571

Please sign in to comment.