mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
Fix type of Game.budget.
This *is* a float, since the income multiplier is a float. The type annotations were wrong.
This commit is contained in:
parent
9671542bdf
commit
6cbc2b707a
@ -69,16 +69,18 @@ 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):
|
class TurnState(Enum):
|
||||||
WIN = 0
|
WIN = 0
|
||||||
LOSS = 1
|
LOSS = 1
|
||||||
CONTINUE = 2
|
CONTINUE = 2
|
||||||
|
|
||||||
|
|
||||||
class Game:
|
class Game:
|
||||||
def __init__(self, player_name: str, enemy_name: str,
|
def __init__(self, player_name: str, enemy_name: str,
|
||||||
theater: ConflictTheater, start_date: datetime,
|
theater: ConflictTheater, start_date: datetime,
|
||||||
settings: Settings, player_budget: int,
|
settings: Settings, player_budget: float,
|
||||||
enemy_budget: int) -> None:
|
enemy_budget: float) -> None:
|
||||||
self.settings = settings
|
self.settings = settings
|
||||||
self.events: List[Event] = []
|
self.events: List[Event] = []
|
||||||
self.theater = theater
|
self.theater = theater
|
||||||
|
|||||||
@ -5,7 +5,6 @@ import random
|
|||||||
from dataclasses import dataclass
|
from dataclasses import dataclass
|
||||||
from typing import Iterator, List, Optional, TYPE_CHECKING, Type
|
from typing import Iterator, List, Optional, TYPE_CHECKING, Type
|
||||||
|
|
||||||
from dcs.task import CAP, CAS
|
|
||||||
from dcs.unittype import FlyingType, VehicleType
|
from dcs.unittype import FlyingType, VehicleType
|
||||||
|
|
||||||
from game import db
|
from game import db
|
||||||
@ -52,8 +51,8 @@ class ProcurementAi:
|
|||||||
self.threat_zones = self.game.threat_zone_for(not self.is_player)
|
self.threat_zones = self.game.threat_zone_for(not self.is_player)
|
||||||
|
|
||||||
def spend_budget(
|
def spend_budget(
|
||||||
self, budget: int,
|
self, budget: float,
|
||||||
aircraft_requests: List[AircraftProcurementRequest]) -> int:
|
aircraft_requests: List[AircraftProcurementRequest]) -> float:
|
||||||
if self.manage_runways:
|
if self.manage_runways:
|
||||||
budget = self.repair_runways(budget)
|
budget = self.repair_runways(budget)
|
||||||
if self.manage_front_line:
|
if self.manage_front_line:
|
||||||
@ -69,7 +68,7 @@ class ProcurementAi:
|
|||||||
budget = self.purchase_aircraft(budget, aircraft_requests)
|
budget = self.purchase_aircraft(budget, aircraft_requests)
|
||||||
return budget
|
return budget
|
||||||
|
|
||||||
def sell_incomplete_squadrons(self) -> int:
|
def sell_incomplete_squadrons(self) -> float:
|
||||||
# Selling incomplete squadrons gives us more money to spend on the next
|
# Selling incomplete squadrons gives us more money to spend on the next
|
||||||
# turn. This serves as a short term fix for
|
# turn. This serves as a short term fix for
|
||||||
# https://github.com/Khopa/dcs_liberation/issues/41.
|
# https://github.com/Khopa/dcs_liberation/issues/41.
|
||||||
@ -80,7 +79,7 @@ class ProcurementAi:
|
|||||||
#
|
#
|
||||||
# This option is only used by the AI since players cannot cancel sales
|
# This option is only used by the AI since players cannot cancel sales
|
||||||
# (https://github.com/Khopa/dcs_liberation/issues/365).
|
# (https://github.com/Khopa/dcs_liberation/issues/365).
|
||||||
total = 0
|
total = 0.0
|
||||||
for cp in self.game.theater.control_points_for(self.is_player):
|
for cp in self.game.theater.control_points_for(self.is_player):
|
||||||
inventory = self.game.aircraft_inventory.for_control_point(cp)
|
inventory = self.game.aircraft_inventory.for_control_point(cp)
|
||||||
for aircraft, available in inventory.all_aircraft:
|
for aircraft, available in inventory.all_aircraft:
|
||||||
@ -92,7 +91,7 @@ class ProcurementAi:
|
|||||||
total += db.PRICES[aircraft]
|
total += db.PRICES[aircraft]
|
||||||
return total
|
return total
|
||||||
|
|
||||||
def repair_runways(self, budget: int) -> int:
|
def repair_runways(self, budget: float) -> float:
|
||||||
for control_point in self.owned_points:
|
for control_point in self.owned_points:
|
||||||
if budget < db.RUNWAY_REPAIR_COST:
|
if budget < db.RUNWAY_REPAIR_COST:
|
||||||
break
|
break
|
||||||
@ -112,7 +111,8 @@ class ProcurementAi:
|
|||||||
return budget
|
return budget
|
||||||
|
|
||||||
def random_affordable_ground_unit(
|
def random_affordable_ground_unit(
|
||||||
self, budget: int, cp: ControlPoint) -> Optional[Type[VehicleType]]:
|
self, budget: float,
|
||||||
|
cp: ControlPoint) -> Optional[Type[VehicleType]]:
|
||||||
affordable_units = [u for u in self.faction.frontline_units + self.faction.artillery_units if
|
affordable_units = [u for u in self.faction.frontline_units + self.faction.artillery_units if
|
||||||
db.PRICES[u] <= budget]
|
db.PRICES[u] <= budget]
|
||||||
|
|
||||||
@ -129,7 +129,7 @@ class ProcurementAi:
|
|||||||
return None
|
return None
|
||||||
return random.choice(affordable_units)
|
return random.choice(affordable_units)
|
||||||
|
|
||||||
def reinforce_front_line(self, budget: int) -> int:
|
def reinforce_front_line(self, budget: float) -> float:
|
||||||
if not self.faction.frontline_units and not self.faction.artillery_units:
|
if not self.faction.frontline_units and not self.faction.artillery_units:
|
||||||
return budget
|
return budget
|
||||||
|
|
||||||
@ -151,7 +151,7 @@ class ProcurementAi:
|
|||||||
|
|
||||||
def _affordable_aircraft_of_types(
|
def _affordable_aircraft_of_types(
|
||||||
self, types: List[Type[FlyingType]], airbase: ControlPoint,
|
self, types: List[Type[FlyingType]], airbase: ControlPoint,
|
||||||
number: int, max_price: int) -> Optional[Type[FlyingType]]:
|
number: int, max_price: float) -> Optional[Type[FlyingType]]:
|
||||||
best_choice: Optional[Type[FlyingType]] = None
|
best_choice: Optional[Type[FlyingType]] = None
|
||||||
for unit in [u for u in self.faction.aircrafts if u in types]:
|
for unit in [u for u in self.faction.aircrafts if u in types]:
|
||||||
if db.PRICES[unit] * number > max_price:
|
if db.PRICES[unit] * number > max_price:
|
||||||
@ -169,14 +169,14 @@ class ProcurementAi:
|
|||||||
|
|
||||||
def affordable_aircraft_for(
|
def affordable_aircraft_for(
|
||||||
self, request: AircraftProcurementRequest,
|
self, request: AircraftProcurementRequest,
|
||||||
airbase: ControlPoint, budget: int) -> Optional[Type[FlyingType]]:
|
airbase: ControlPoint, budget: float) -> Optional[Type[FlyingType]]:
|
||||||
return self._affordable_aircraft_of_types(
|
return self._affordable_aircraft_of_types(
|
||||||
aircraft_for_task(request.task_capability),
|
aircraft_for_task(request.task_capability),
|
||||||
airbase, request.number, budget)
|
airbase, request.number, budget)
|
||||||
|
|
||||||
def purchase_aircraft(
|
def purchase_aircraft(
|
||||||
self, budget: int,
|
self, budget: float,
|
||||||
aircraft_requests: List[AircraftProcurementRequest]) -> int:
|
aircraft_requests: List[AircraftProcurementRequest]) -> float:
|
||||||
for request in aircraft_requests:
|
for request in aircraft_requests:
|
||||||
for airbase in self.best_airbases_for(request):
|
for airbase in self.best_airbases_for(request):
|
||||||
unit = self.affordable_aircraft_for(request, airbase, budget)
|
unit = self.affordable_aircraft_for(request, airbase, budget)
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user