mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
You Won message #419
This commit is contained in:
parent
6296896471
commit
2ea3f914f0
24
game/game.py
24
game/game.py
@ -2,6 +2,7 @@ import logging
|
|||||||
import random
|
import random
|
||||||
import sys
|
import sys
|
||||||
from datetime import date, datetime, timedelta
|
from datetime import date, datetime, timedelta
|
||||||
|
from enum import Enum
|
||||||
from typing import Dict, List
|
from typing import Dict, List
|
||||||
|
|
||||||
from dcs.action import Coalition
|
from dcs.action import Coalition
|
||||||
@ -64,6 +65,10 @@ AWACS_BUDGET_COST = 4
|
|||||||
# Bonus multiplier logarithm base
|
# Bonus multiplier logarithm base
|
||||||
PLAYER_BUDGET_IMPORTANCE_LOG = 2
|
PLAYER_BUDGET_IMPORTANCE_LOG = 2
|
||||||
|
|
||||||
|
class TurnState(Enum):
|
||||||
|
WIN = 0
|
||||||
|
LOSS = 1
|
||||||
|
CONTINUE = 2
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self, player_name: str, enemy_name: str,
|
def __init__(self, player_name: str, enemy_name: str,
|
||||||
@ -256,6 +261,14 @@ class Game:
|
|||||||
# Autosave progress
|
# Autosave progress
|
||||||
persistency.autosave(self)
|
persistency.autosave(self)
|
||||||
|
|
||||||
|
def check_win_loss(self):
|
||||||
|
cps = {i.captured: i for i in self.theater.controlpoints}
|
||||||
|
if True not in cps.keys():
|
||||||
|
return TurnState.LOSS
|
||||||
|
if False not in cps.keys():
|
||||||
|
return TurnState.WIN
|
||||||
|
return TurnState.CONTINUE
|
||||||
|
|
||||||
def initialize_turn(self) -> None:
|
def initialize_turn(self) -> None:
|
||||||
self.events = []
|
self.events = []
|
||||||
self._generate_events()
|
self._generate_events()
|
||||||
@ -268,6 +281,11 @@ class Game:
|
|||||||
cp.pending_unit_deliveries = self.units_delivery_event(cp)
|
cp.pending_unit_deliveries = self.units_delivery_event(cp)
|
||||||
self.aircraft_inventory.set_from_control_point(cp)
|
self.aircraft_inventory.set_from_control_point(cp)
|
||||||
|
|
||||||
|
# Check for win or loss condition
|
||||||
|
turn_state = self.check_win_loss()
|
||||||
|
if turn_state in (TurnState.LOSS,TurnState.WIN):
|
||||||
|
return self.process_win_loss(turn_state)
|
||||||
|
|
||||||
# Plan flights & combat for next turn
|
# Plan flights & combat for next turn
|
||||||
self.compute_conflicts_position()
|
self.compute_conflicts_position()
|
||||||
self.ground_planners = {}
|
self.ground_planners = {}
|
||||||
@ -427,3 +445,9 @@ class Game:
|
|||||||
|
|
||||||
def get_enemy_color(self):
|
def get_enemy_color(self):
|
||||||
return "red"
|
return "red"
|
||||||
|
|
||||||
|
def process_win_loss(self, turn_state: TurnState):
|
||||||
|
if turn_state is TurnState.WIN:
|
||||||
|
return self.message("Congratulations, you are victorious! Start a new campaign to continue.")
|
||||||
|
elif turn_state is TurnState.LOSS:
|
||||||
|
return self.message("Game Over, you lose. Start a new campaign to continue.")
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user