extends RefCounted ## Outcome rules: scarecrow destruction, a stripped farm (all three categories; only those in ## play count; supplies only when thieves emptied the shed), completing the vacation, the ## failure-before-completion tie policy, failure in every phase, and terminal phases staying ## terminal. const O := CampaignController.Outcome const P := CampaignController.Phase func run(r: GameTestRunner) -> void: var cfg := (load("res://game/resources/game_config.tres") as GameConfig).duplicate() as GameConfig var n := cfg.campaign_nights var fresh := FarmState.create(cfg) r.check(CampaignController.check_outcome(fresh, n) == O.CONTINUE, "a fresh farm continues") var s := FarmState.create(cfg) s.scarecrow_hp = 0 r.check(CampaignController.check_outcome(s, n) == O.GAME_OVER_SCARECROW, "0 HP is a Game Over") s = FarmState.create(cfg) s.animals_total = 0 s.supplies_total = 0 s.lose_all_crops() r.check(CampaignController.check_outcome(s, n) == O.GAME_OVER_STRIPPED, "with only crops in play, no crops left is a stripped farm") s = FarmState.create(cfg) s.lose_all_crops() r.check(CampaignController.check_outcome(s, n) == O.CONTINUE, "losing every crop alone does not end the game") s.lose_all_animals() r.check(CampaignController.check_outcome(s, n) == O.CONTINUE, "losing crops and animals with supplies left does not end the game") for m in ResourceStore.MATERIALS: s.resources.shed[m] = 0 r.check(CampaignController.check_outcome(s, n) == O.CONTINUE, "spending the last supplies doesn't strip the farm") s.shed_raided = true s.supplies_in_transit = 5 r.check(CampaignController.check_outcome(s, n) == O.CONTINUE, "a sack of supplies still on the farm keeps it going") s.supplies_in_transit = 0 r.check(CampaignController.check_outcome(s, n) == O.GAME_OVER_STRIPPED, "losing every category ends the game (thieves emptied the shed)") s.resources.shed["straw"] = 2 s.settle_supplies() s.resources.shed["straw"] = 0 r.check(not s.shed_raided and CampaignController.check_outcome(s, n) == O.CONTINUE, "storing anything clears the raid: spending it again doesn't strip the farm") s = FarmState.create(cfg) s.crops_total = 0 s.animals_total = 0 s.supplies_total = 0 r.check(not s.is_stripped(), "a farm with nothing in play is not 'stripped'") s = FarmState.create(cfg) s.nights_survived = n - 1 r.check(CampaignController.check_outcome(s, n) == O.CONTINUE, "%d nights survived continues" % (n - 1)) s.nights_survived = n r.check(CampaignController.check_outcome(s, n) == O.VACATION_COMPLETE, "%d nights survived completes the vacation" % n) # Tie policy: any failure beats completion; scarecrow destruction is reported first. s.scarecrow_hp = 0 r.check(CampaignController.check_outcome(s, n) == O.GAME_OVER_SCARECROW, "tie: scarecrow destroyed on the final night loses") s.scarecrow_hp = 1 s.strip() r.check(CampaignController.check_outcome(s, n) == O.GAME_OVER_STRIPPED, "tie: farm stripped on the final night loses") s.scarecrow_hp = 0 r.check(CampaignController.check_outcome(s, n) == O.GAME_OVER_SCARECROW, "scarecrow destruction is reported before a stripped farm") _failure_in_every_phase(r) _final_dawn_tie(r) _terminal(r) func _failure_in_every_phase(r: GameTestRunner) -> void: for phase: CampaignController.Phase in [P.MORNING, P.DAY, P.DUSK, P.NIGHT, P.DAWN]: var c := r.make_campaign() var ended: Array[CampaignController.Outcome] = [] c.campaign_ended.connect(func(o: CampaignController.Outcome) -> void: ended.append(o)) GameTestRunner.run_until(c, phase) c.state.scarecrow_hp = 0 c.tick(GameTestRunner.TICK) r.check(c.state.phase == P.GAME_OVER and c.outcome == O.GAME_OVER_SCARECROW and ended == [O.GAME_OVER_SCARECROW], "scarecrow destroyed during %s ends the game once" % P.keys()[phase]) c = r.make_campaign() GameTestRunner.run_until(c, phase) c.state.strip() c.tick(GameTestRunner.TICK) r.check(c.state.phase == P.GAME_OVER and c.outcome == O.GAME_OVER_STRIPPED, "farm stripped during %s ends the game" % P.keys()[phase]) ## The scarecrow is destroyed on the very tick the final dawn ends: a loss, not a victory. func _final_dawn_tie(r: GameTestRunner) -> void: var c := r.make_campaign() for i in c.config.campaign_nights - 1: GameTestRunner.run_until(c, P.DAWN) GameTestRunner.run_until(c, P.MORNING) GameTestRunner.run_until(c, P.DAWN) r.check(c.state.night == c.config.campaign_nights, "reached the final dawn") c.state.phase_time_left = GameTestRunner.TICK * 0.5 c.state.scarecrow_hp = 0 c.tick(GameTestRunner.TICK) r.check(c.state.phase == P.GAME_OVER and c.outcome == O.GAME_OVER_SCARECROW, "tie on the final dawn tick resolves as a loss (got %s)" % P.keys()[c.state.phase]) func _terminal(r: GameTestRunner) -> void: var c := r.make_campaign() GameTestRunner.run_until(c, P.NIGHT) c.state.scarecrow_hp = 0 c.tick(GameTestRunner.TICK) var before := c.state.to_dict() c.tick(1000.0) c.advance_phase() r.check(not c.begin_day(), "begin_day does nothing after Game Over") c.state.scarecrow_hp = 5 c.tick(GameTestRunner.TICK) before["scarecrow_hp"] = 5 r.check(c.state.to_dict() == before and c.state.phase == P.GAME_OVER, "Game Over is terminal: ticks and phase skips change nothing")