mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
carrier operations WIP[2]
This commit is contained in:
parent
3d0babf65f
commit
6e9baa4944
@ -50,9 +50,21 @@ class GroundInterceptEvent(Event):
|
||||
TARGET_AMOUNT_FACTOR = 3
|
||||
TARGET_VARIETY = 3
|
||||
STRENGTH_INFLUENCE = 0.1
|
||||
SUCCESS_TARGETS_HIT_PERCENTAGE = 0.7
|
||||
|
||||
targets = None # type: db.ArmorDict
|
||||
|
||||
def __str__(self):
|
||||
return "Ground intercept at {} ({})".format(self.to_cp, "*" * self.difficulty)
|
||||
return "Ground intercept from {} at {} ({})".format(self.from_cp, self.to_cp, "*" * self.difficulty)
|
||||
|
||||
def is_successfull(self, debriefing: Debriefing):
|
||||
total_targets = sum(self.targets.values())
|
||||
destroyed_targets = 0
|
||||
for unit, count in debriefing.destroyed_units[self.defender.name].items():
|
||||
if unit in self.targets:
|
||||
destroyed_targets += count
|
||||
|
||||
return (float(destroyed_targets) / float(total_targets)) > self.SUCCESS_TARGETS_HIT_PERCENTAGE
|
||||
|
||||
def commit(self, debriefing: Debriefing):
|
||||
super(GroundInterceptEvent, self).commit(debriefing)
|
||||
@ -76,8 +88,8 @@ class GroundInterceptEvent(Event):
|
||||
random.shuffle(suitable_unittypes)
|
||||
unittypes = suitable_unittypes[:self.TARGET_VARIETY]
|
||||
typecount = max(math.floor(self.difficulty * self.TARGET_AMOUNT_FACTOR), 1)
|
||||
targets = {unittype: typecount for unittype in unittypes}
|
||||
|
||||
self.targets = {unittype: typecount for unittype in unittypes}
|
||||
self.operation = GroundInterceptOperation(mission=self.mission,
|
||||
attacker=self.attacker,
|
||||
defender=self.defender,
|
||||
@ -85,7 +97,7 @@ class GroundInterceptEvent(Event):
|
||||
defender_clients={},
|
||||
from_cp=self.from_cp,
|
||||
position=position,
|
||||
target=targets,
|
||||
target=self.targets,
|
||||
strikegroup=strikegroup)
|
||||
|
||||
|
||||
@ -95,11 +107,21 @@ class InterceptEvent(Event):
|
||||
STRENGTH_INFLUENCE = 0.25
|
||||
AIRDEFENSE_COUNT = 3
|
||||
|
||||
transport_unit = None # type: FlyingType
|
||||
|
||||
def __str__(self):
|
||||
return "Intercept at {} ({})".format(self.to_cp, "*" * self.difficulty)
|
||||
return "Intercept from {} at {} ({})".format(self.from_cp, self.to_cp, "*" * self.difficulty)
|
||||
|
||||
def is_successfull(self, debriefing: Debriefing):
|
||||
intercepted = self.transport_unit in debriefing.destroyed_units[self.defender.name].keys()
|
||||
if self.from_cp.captured:
|
||||
return intercepted
|
||||
else:
|
||||
return not intercepted
|
||||
|
||||
def commit(self, debriefing: Debriefing):
|
||||
super(InterceptEvent, self).commit(debriefing)
|
||||
|
||||
if self.is_successfull(debriefing):
|
||||
self.to_cp.base.affect_strength(self.STRENGTH_INFLUENCE * float(self.from_cp.captured and -1 or 1))
|
||||
else:
|
||||
@ -111,8 +133,8 @@ class InterceptEvent(Event):
|
||||
|
||||
def player_attacking(self, interceptors: db.PlaneDict, clients: db.PlaneDict):
|
||||
escort = self.to_cp.base.scramble_sweep(self.to_cp)
|
||||
transport_unit = random.choice(db.find_unittype(Transport, self.defender.name))
|
||||
assert transport_unit is not None
|
||||
self.transport_unit = random.choice(db.find_unittype(Transport, self.defender.name))
|
||||
assert self.transport_unit is not None
|
||||
|
||||
airdefense_unit = db.find_unittype(AirDefence, self.defender.name)[0]
|
||||
|
||||
@ -124,14 +146,14 @@ class InterceptEvent(Event):
|
||||
from_cp=self.from_cp,
|
||||
to_cp=self.to_cp,
|
||||
escort=escort,
|
||||
transport={transport_unit: 1},
|
||||
transport={self.transport_unit: 1},
|
||||
airdefense={airdefense_unit: self.AIRDEFENSE_COUNT},
|
||||
interceptors=interceptors)
|
||||
|
||||
def player_defending(self, escort: db.PlaneDict, clients: db.PlaneDict):
|
||||
interceptors = self.from_cp.base.scramble_interceptors_count(self.difficulty * self.ESCORT_AMOUNT_FACTOR)
|
||||
transport_unit = random.choice(db.find_unittype(Transport, self.defender.name))
|
||||
assert transport_unit is not None
|
||||
self.transport_unit = random.choice(db.find_unittype(Transport, self.defender.name))
|
||||
assert self.transport_unit is not None
|
||||
|
||||
self.operation = InterceptOperation(mission=self.mission,
|
||||
attacker=self.attacker,
|
||||
@ -141,7 +163,7 @@ class InterceptEvent(Event):
|
||||
from_cp=self.from_cp,
|
||||
to_cp=self.to_cp,
|
||||
escort=escort,
|
||||
transport={transport_unit: 1},
|
||||
transport={self.transport_unit: 1},
|
||||
interceptors=interceptors,
|
||||
airdefense={})
|
||||
|
||||
@ -152,7 +174,14 @@ class CaptureEvent(Event):
|
||||
STRENGTH_RECOVERY = 0.35
|
||||
|
||||
def __str__(self):
|
||||
return "Capture {} ({})".format(self.to_cp, "*" * self.difficulty)
|
||||
return "Attack from {} to {} ({})".format(self.from_cp, self.to_cp, "*" * self.difficulty)
|
||||
|
||||
def is_successfull(self, debriefing: Debriefing):
|
||||
attackers_success = len(debriefing.destroyed_units[self.defender.name]) > len(debriefing.destroyed_units[self.attacker.name])
|
||||
if self.from_cp.captured:
|
||||
return attackers_success
|
||||
else:
|
||||
return not attackers_success
|
||||
|
||||
def commit(self, debriefing: Debriefing):
|
||||
super(CaptureEvent, self).commit(debriefing)
|
||||
|
||||
12
game/game.py
12
game/game.py
@ -28,6 +28,7 @@ ENEMY_CAPTURE_PROBABILITY_BASE = 3
|
||||
|
||||
PLAYER_INTERCEPT_PROBABILITY_BASE = 30
|
||||
PLAYER_GROUNDINTERCEPT_PROBABILITY_BASE = 30
|
||||
PLAYER_GLOBALINTERCEPT_PROBABILITY_BASE = 100
|
||||
|
||||
PLAYER_BUDGET_BASE = 25
|
||||
PLAYER_BUDGET_IMPORTANCE_LOG = 2
|
||||
@ -96,6 +97,16 @@ class Game:
|
||||
to_cp=to_cp))
|
||||
break
|
||||
|
||||
def _generate_global(self):
|
||||
for cp in self.theater.player_points():
|
||||
if cp.is_global:
|
||||
if self._roll(PLAYER_GLOBALINTERCEPT_PROBABILITY_BASE, cp.base.strength):
|
||||
enemy_points = list(set(self.theater.enemy_bases()) - set(self.theater.conflicts(False)))
|
||||
self.events.append(InterceptEvent(attacker_name=self.player,
|
||||
defender_name=self.enemy,
|
||||
from_cp=cp,
|
||||
to_cp=random.choice(enemy_points)))
|
||||
|
||||
def _commision_units(self, cp: ControlPoint):
|
||||
for for_task in [CAP, CAS, FighterSweep, AirDefence]:
|
||||
limit = COMMISION_LIMITS_FACTORS[for_task] * math.pow(cp.importance, COMMISION_LIMITS_SCALE)
|
||||
@ -159,4 +170,5 @@ class Game:
|
||||
self._generate_enemy_caps()
|
||||
self._generate_interceptions()
|
||||
self._generate_groundinterceptions()
|
||||
self._generate_global()
|
||||
|
||||
|
||||
@ -89,11 +89,15 @@ class InterceptOperation(Operation):
|
||||
transport: db.PlaneDict,
|
||||
airdefense: db.AirDefenseDict,
|
||||
interceptors: db.PlaneDict):
|
||||
heading = from_cp.position.heading_between_point(to_cp.position)
|
||||
distance = from_cp.position.distance_to_point(to_cp.position)
|
||||
position = from_cp.position.point_from_heading(heading, distance/2)
|
||||
|
||||
conflict = Conflict.intercept_conflict(
|
||||
attacker=attacker,
|
||||
defender=defender,
|
||||
position=to_cp.position,
|
||||
heading=randint(0, 360),
|
||||
position=position,
|
||||
heading=heading,
|
||||
radials=ALL_RADIALS
|
||||
)
|
||||
|
||||
|
||||
@ -106,10 +106,10 @@ class AircraftConflictGenerator:
|
||||
def _generate_group(self, name: str, side: Country, unit_type: FlyingType, count: int, client_count: int, at: db.StartingPosition):
|
||||
if isinstance(at, Point):
|
||||
return self._generate_inflight(name, side, unit_type, count, client_count, at)
|
||||
elif issubclass(at, Airport):
|
||||
return self._generate_at_airport(name, side, unit_type, count, client_count, at)
|
||||
elif isinstance(at, ShipGroup):
|
||||
return self._generate_at_carrier(name, side, unit_type, count, client_count, at)
|
||||
elif issubclass(at, Airport):
|
||||
return self._generate_at_airport(name, side, unit_type, count, client_count, at)
|
||||
else:
|
||||
assert False
|
||||
|
||||
|
||||
@ -61,7 +61,7 @@ UNIT_BY_COUNTRY = {
|
||||
}
|
||||
|
||||
UnitsDict = typing.Dict[UnitType, int]
|
||||
PlaneDict = typing.Dict[PlaneType, int]
|
||||
PlaneDict = typing.Dict[FlyingType, int]
|
||||
ArmorDict = typing.Dict[VehicleType, int]
|
||||
AirDefenseDict = typing.Dict[AirDefence, int]
|
||||
StartingPosition = typing.Optional[typing.Union[ShipGroup, Airport, Point]]
|
||||
|
||||
@ -80,6 +80,7 @@ class EventResultsMenu(Menu):
|
||||
}
|
||||
|
||||
self.finished = True
|
||||
self.debriefing = debriefing
|
||||
self.game.finish_event(self.event, debriefing)
|
||||
self.display()
|
||||
self.game.pass_turn()
|
||||
|
||||
@ -32,26 +32,28 @@ class MainMenu(Menu):
|
||||
Label(self.frame, text=text).grid(row=row, sticky=NW)
|
||||
row += 1
|
||||
|
||||
def event_button(event, text):
|
||||
def event_button(event):
|
||||
nonlocal row
|
||||
Button(self.frame, text=text, command=self.start_event(event)).grid(row=row, sticky=N)
|
||||
Message(self.frame, text="{}{}".format(
|
||||
event.defender.name == self.game.player and "Enemy attacking: " or "",
|
||||
event
|
||||
), aspect=500).grid(column=0, row=row, sticky=NW)
|
||||
Button(self.frame, text=">", command=self.start_event(event)).grid(column=0, row=row, sticky=NE+S)
|
||||
row += 1
|
||||
Separator(self.frame, orient='horizontal').grid(row=row, sticky=EW); row += 1
|
||||
|
||||
Button(self.frame, text="Pass turn", command=self.pass_turn).grid(column=0, row=0, sticky=NE)
|
||||
Label(self.frame, text="Budget: {}m (+{}m)".format(self.game.budget, self.game.budget_reward_amount)).grid(column=0, row=0, sticky=NW)
|
||||
Separator(self.frame, orient='horizontal').grid(row=row, sticky=EW); row += 1
|
||||
|
||||
for event in self.game.events:
|
||||
if not event.informational:
|
||||
continue
|
||||
events = self.game.events
|
||||
events.sort(key=lambda x: x.informational and 2 or (self.game.is_player_attack(x) and 1 or 0))
|
||||
|
||||
label(str(event))
|
||||
|
||||
for event in self.game.events:
|
||||
for event in events:
|
||||
if event.informational:
|
||||
continue
|
||||
|
||||
event_button(event, "{} {}".format(event.attacker.name != self.game.player and "!" or " ", event))
|
||||
label(str(event))
|
||||
else:
|
||||
event_button(event)
|
||||
|
||||
def pass_turn(self):
|
||||
self.game.pass_turn(no_action=True)
|
||||
|
||||
@ -15,7 +15,7 @@ class Window:
|
||||
self.frame = Frame(self.tk)
|
||||
self.frame.grid(column=0, row=0, sticky=NSEW)
|
||||
self.frame.grid_columnconfigure(0, minsize=300)
|
||||
self.frame.grid_columnconfigure(1, minsize=300)
|
||||
self.frame.grid_columnconfigure(1, minsize=400)
|
||||
|
||||
self.frame.grid_columnconfigure(0, weight=0)
|
||||
self.frame.grid_columnconfigure(1, weight=1)
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user