mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +00:00
new game ui; random weather and time
This commit is contained in:
parent
1c67a2e4cf
commit
8a783625ce
28
__init__.py
28
__init__.py
@ -4,21 +4,35 @@ import sys
|
|||||||
import theater.caucasus
|
import theater.caucasus
|
||||||
import ui.window
|
import ui.window
|
||||||
import ui.mainmenu
|
import ui.mainmenu
|
||||||
|
import ui.newgamemenu
|
||||||
|
|
||||||
from game.game import Game
|
from game.game import Game
|
||||||
from theater import start_generator
|
from theater import start_generator
|
||||||
from userdata import persistency
|
from userdata import persistency
|
||||||
|
|
||||||
game = persistency.restore_game()
|
|
||||||
if not game:
|
|
||||||
theater = theater.caucasus.CaucasusTheater()
|
|
||||||
start_generator.generate_initial(theater, "Russia")
|
|
||||||
|
|
||||||
game = Game(theater=theater)
|
def proceed_to_main_menu(game: Game):
|
||||||
|
|
||||||
w = ui.window.Window()
|
|
||||||
m = ui.mainmenu.MainMenu(w, None, game)
|
m = ui.mainmenu.MainMenu(w, None, game)
|
||||||
m.display()
|
m.display()
|
||||||
|
|
||||||
|
|
||||||
|
w = ui.window.Window()
|
||||||
|
game = persistency.restore_game()
|
||||||
|
if not game:
|
||||||
|
new_game_menu = None # type: NewGameMenu
|
||||||
|
|
||||||
|
def start_new_game(player_name: str, enemy_name: str):
|
||||||
|
conflicttheater = theater.caucasus.CaucasusTheater()
|
||||||
|
start_generator.generate_initial(conflicttheater, enemy_name)
|
||||||
|
|
||||||
|
proceed_to_main_menu(Game(player_name=player_name,
|
||||||
|
enemy_name=enemy_name,
|
||||||
|
theater=conflicttheater))
|
||||||
|
|
||||||
|
new_game_menu = ui.newgamemenu.NewGameMenu(w, start_new_game)
|
||||||
|
new_game_menu.display()
|
||||||
|
else:
|
||||||
|
proceed_to_main_menu(game)
|
||||||
|
|
||||||
w.run()
|
w.run()
|
||||||
|
|
||||||
|
|||||||
@ -37,11 +37,11 @@ class Game:
|
|||||||
events = None # type: typing.List[Event]
|
events = None # type: typing.List[Event]
|
||||||
pending_transfers = None # type: typing.Dict[]
|
pending_transfers = None # type: typing.Dict[]
|
||||||
|
|
||||||
def __init__(self, theater: ConflictTheater):
|
def __init__(self, player_name: str, enemy_name: str, theater: ConflictTheater):
|
||||||
self.events = []
|
self.events = []
|
||||||
self.theater = theater
|
self.theater = theater
|
||||||
self.player = "USA"
|
self.player = player_name
|
||||||
self.enemy = "Russia"
|
self.enemy = enemy_name
|
||||||
|
|
||||||
def _roll(self, prob, mult):
|
def _roll(self, prob, mult):
|
||||||
return random.randint(0, 100) <= prob * mult
|
return random.randint(0, 100) <= prob * mult
|
||||||
|
|||||||
@ -7,6 +7,7 @@ from gen.aircraft import *
|
|||||||
from gen.aaa import *
|
from gen.aaa import *
|
||||||
from gen.shipgen import *
|
from gen.shipgen import *
|
||||||
from gen.conflictgen import *
|
from gen.conflictgen import *
|
||||||
|
from gen.envsettingsgen import *
|
||||||
|
|
||||||
|
|
||||||
class Operation:
|
class Operation:
|
||||||
@ -16,7 +17,9 @@ class Operation:
|
|||||||
armorgen = None # type: ArmorConflictGenerator
|
armorgen = None # type: ArmorConflictGenerator
|
||||||
airgen = None # type: AircraftConflictGenerator
|
airgen = None # type: AircraftConflictGenerator
|
||||||
aagen = None # type: AAConflictGenerator
|
aagen = None # type: AAConflictGenerator
|
||||||
|
extra_aagen = None # type: ExtraAAConflictGenerator
|
||||||
shipgen = None # type: ShipGenerator
|
shipgen = None # type: ShipGenerator
|
||||||
|
envgen = None # type: EnvironmentSettingsGenerator
|
||||||
|
|
||||||
def __init__(self,
|
def __init__(self,
|
||||||
theater: ConflictTheater,
|
theater: ConflictTheater,
|
||||||
@ -42,6 +45,7 @@ class Operation:
|
|||||||
self.airgen = AircraftConflictGenerator(mission, conflict)
|
self.airgen = AircraftConflictGenerator(mission, conflict)
|
||||||
self.aagen = AAConflictGenerator(mission, conflict)
|
self.aagen = AAConflictGenerator(mission, conflict)
|
||||||
self.shipgen = ShipGenerator(mission, conflict)
|
self.shipgen = ShipGenerator(mission, conflict)
|
||||||
|
self.envgen = EnvironmentSettingsGenerator(mission)
|
||||||
|
|
||||||
player_name = self.from_cp.captured and self.attacker_name or self.defender_name
|
player_name = self.from_cp.captured and self.attacker_name or self.defender_name
|
||||||
enemy_name = self.from_cp.captured and self.defender_name or self.attacker_name
|
enemy_name = self.from_cp.captured and self.defender_name or self.attacker_name
|
||||||
@ -52,6 +56,7 @@ class Operation:
|
|||||||
|
|
||||||
def generate(self):
|
def generate(self):
|
||||||
self.extra_aagen.generate()
|
self.extra_aagen.generate()
|
||||||
|
self.envgen.generate()
|
||||||
|
|
||||||
def units_of(self, country_name: str) -> typing.Collection[UnitType]:
|
def units_of(self, country_name: str) -> typing.Collection[UnitType]:
|
||||||
return []
|
return []
|
||||||
|
|||||||
@ -44,7 +44,7 @@ class AircraftConflictGenerator:
|
|||||||
aircraft_type=unit_type,
|
aircraft_type=unit_type,
|
||||||
airport=self.m.terrain.airport_by_id(airport.id),
|
airport=self.m.terrain.airport_by_id(airport.id),
|
||||||
maintask=None,
|
maintask=None,
|
||||||
start_type=StartType.Cold,
|
start_type=StartType.Warm,
|
||||||
group_size=count,
|
group_size=count,
|
||||||
parking_slots=None)
|
parking_slots=None)
|
||||||
|
|
||||||
|
|||||||
28
gen/envsettingsgen.py
Normal file
28
gen/envsettingsgen.py
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
import typing
|
||||||
|
import random
|
||||||
|
|
||||||
|
from dcs.mission import Mission
|
||||||
|
|
||||||
|
from theater.weatherforecast import WeatherForecast
|
||||||
|
|
||||||
|
|
||||||
|
RANDOM_TIME = {
|
||||||
|
"night": 5,
|
||||||
|
"dusk": 25,
|
||||||
|
"down": 50,
|
||||||
|
"noon": 75,
|
||||||
|
"day": 100,
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
class EnvironmentSettingsGenerator:
|
||||||
|
def __init__(self, mission: Mission):
|
||||||
|
self.mission = mission
|
||||||
|
|
||||||
|
def generate(self):
|
||||||
|
self.mission.random_weather = True
|
||||||
|
|
||||||
|
time_roll = random.randint(0, 100)
|
||||||
|
time_period = [k for k, v in RANDOM_TIME.items() if v > time_roll][-1]
|
||||||
|
self.mission.random_daytime(time_period)
|
||||||
|
|
||||||
4
theater/weatherforecast.py
Normal file
4
theater/weatherforecast.py
Normal file
@ -0,0 +1,4 @@
|
|||||||
|
|
||||||
|
|
||||||
|
class WeatherForecast:
|
||||||
|
pass
|
||||||
41
ui/newgamemenu.py
Normal file
41
ui/newgamemenu.py
Normal file
@ -0,0 +1,41 @@
|
|||||||
|
from tkinter import *
|
||||||
|
from tkinter.ttk import *
|
||||||
|
|
||||||
|
from ui.window import *
|
||||||
|
|
||||||
|
|
||||||
|
class NewGameMenu(Menu):
|
||||||
|
selected_country = None # type: IntVar
|
||||||
|
|
||||||
|
def __init__(self, window: Window, callback: typing.Callable):
|
||||||
|
super(NewGameMenu, self).__init__(window, None, None)
|
||||||
|
self.frame = window.right_pane
|
||||||
|
self.callback = callback
|
||||||
|
|
||||||
|
self.selected_country = IntVar()
|
||||||
|
self.selected_country.set(0)
|
||||||
|
|
||||||
|
@property
|
||||||
|
def player_country_name(self):
|
||||||
|
if self.selected_country.get() == 0:
|
||||||
|
return "USA"
|
||||||
|
else:
|
||||||
|
return "Russia"
|
||||||
|
|
||||||
|
@property
|
||||||
|
def enemy_country_name(self):
|
||||||
|
if self.selected_country.get() == 1:
|
||||||
|
return "USA"
|
||||||
|
else:
|
||||||
|
return "Russia"
|
||||||
|
|
||||||
|
def display(self):
|
||||||
|
self.window.clear_right_pane()
|
||||||
|
|
||||||
|
Label(self.frame, text="Player country").grid(row=0, column=0)
|
||||||
|
Radiobutton(self.frame, text="USA", variable=self.selected_country, value=0).grid(row=1, column=0)
|
||||||
|
Radiobutton(self.frame, text="Russia", variable=self.selected_country, value=1).grid(row=2, column=0)
|
||||||
|
Button(self.frame, text="Proceed", command=self.proceed).grid(row=3, column=0)
|
||||||
|
|
||||||
|
def proceed(self):
|
||||||
|
self.callback(self.player_country_name, self.enemy_country_name)
|
||||||
@ -44,6 +44,7 @@ class Window:
|
|||||||
|
|
||||||
class Menu:
|
class Menu:
|
||||||
parent = None # type: Menu
|
parent = None # type: Menu
|
||||||
|
|
||||||
def __init__(self, window: Window, parent, game: Game):
|
def __init__(self, window: Window, parent, game: Game):
|
||||||
self.window = window
|
self.window = window
|
||||||
self.parent = parent
|
self.parent = parent
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user