mirror of
https://github.com/dcs-liberation/dcs_liberation.git
synced 2025-11-10 14:22:26 +00:00
a
This commit is contained in:
parent
0fc4d40b78
commit
ae03aa0d47
14
game/game.py
14
game/game.py
@ -23,7 +23,7 @@ COMMISION_AMOUNTS_FACTORS = {
|
||||
}
|
||||
|
||||
|
||||
ENEMY_INTERCEPT_PROBABILITY_BASE = 25
|
||||
ENEMY_INTERCEPT_PROBABILITY_BASE = 15
|
||||
ENEMY_CAPTURE_PROBABILITY_BASE = 5
|
||||
|
||||
PLAYER_INTERCEPT_PROBABILITY_BASE = 30
|
||||
@ -107,12 +107,17 @@ class Game:
|
||||
unit_type = random.choice(db.find_unittype(for_task, self.enemy))
|
||||
cp.base.commision_units({unit_type: points_to_spend})
|
||||
|
||||
def _budget_player(self):
|
||||
@property
|
||||
def budget_reward_amount(self):
|
||||
if len(self.theater.player_points()) > 0:
|
||||
total_importance = sum([x.importance for x in self.theater.player_points()])
|
||||
total_strength = sum([x.base.strength for x in self.theater.player_points()]) / len(self.theater.player_points())
|
||||
return math.ceil(math.log(total_importance * total_strength + 1, PLAYER_BUDGET_IMPORTANCE_LOG) * PLAYER_BUDGET_BASE)
|
||||
else:
|
||||
return 0
|
||||
|
||||
self.budget += math.ceil(math.log(total_importance * total_strength + 1, PLAYER_BUDGET_IMPORTANCE_LOG) * PLAYER_BUDGET_BASE)
|
||||
def _budget_player(self):
|
||||
self.budget += self.budget_reward_amount
|
||||
|
||||
def units_delivery_event(self, to_cp: ControlPoint) -> UnitsDeliveryEvent:
|
||||
event = UnitsDeliveryEvent(attacker_name=self.player,
|
||||
@ -122,6 +127,9 @@ class Game:
|
||||
self.events.append(event)
|
||||
return event
|
||||
|
||||
def units_delivery_remove(self, event: Event):
|
||||
self.events.remove(event)
|
||||
|
||||
def initiate_event(self, event: Event):
|
||||
event.operation.generate()
|
||||
event.mission.save("build/next_mission.miz")
|
||||
|
||||
Binary file not shown.
|
Before Width: | Height: | Size: 186 KiB After Width: | Height: | Size: 157 KiB |
@ -1,8 +1,10 @@
|
||||
import typing
|
||||
import dcs
|
||||
import math
|
||||
import random
|
||||
import itertools
|
||||
|
||||
import dcs
|
||||
|
||||
from shop import db
|
||||
from theater.controlpoint import ControlPoint
|
||||
|
||||
|
||||
@ -49,6 +49,12 @@ class BaseMenu(Menu):
|
||||
for unit_type in units:
|
||||
purchase_row(unit_type, db.PRICES[unit_type])
|
||||
|
||||
def dismiss(self):
|
||||
if sum([x for x in self.event.units.values()]) == 0:
|
||||
self.game.units_delivery_remove(self.event)
|
||||
|
||||
super(BaseMenu, self).dismiss()
|
||||
|
||||
def buy(self, unit_type):
|
||||
def action():
|
||||
price = db.PRICES[unit_type]
|
||||
|
||||
@ -10,6 +10,8 @@ from game.game import *
|
||||
|
||||
|
||||
class MainMenu(Menu):
|
||||
basemenu = None # type: BaseMenu
|
||||
|
||||
def __init__(self, window: Window, parent, game: Game):
|
||||
super(MainMenu, self).__init__(window, parent, game)
|
||||
|
||||
@ -17,7 +19,7 @@ class MainMenu(Menu):
|
||||
#map = Label(window.left_pane, image=self.image)
|
||||
#map.grid()
|
||||
|
||||
self.upd = OverviewCanvas(self.window.left_pane, game)
|
||||
self.upd = OverviewCanvas(self.window.left_pane, self, game)
|
||||
self.upd.update()
|
||||
|
||||
self.frame = self.window.right_pane
|
||||
@ -39,23 +41,14 @@ class MainMenu(Menu):
|
||||
Button(self.frame, text=text, command=self.start_event(event)).grid(row=row, sticky=N)
|
||||
row += 1
|
||||
|
||||
def cp_button(cp):
|
||||
nonlocal row
|
||||
title = "{}{}{}{}".format(
|
||||
cp.name,
|
||||
"^" * cp.base.total_planes,
|
||||
"." * cp.base.total_armor,
|
||||
"*" * cp.base.total_aa)
|
||||
Button(self.frame, text=title, command=self.go_cp(cp)).grid(row=row, sticky=NW)
|
||||
row += 1
|
||||
|
||||
Label(self.frame, text="Budget: {}m".format(self.game.budget)).grid(column=0, row=0, sticky=NW)
|
||||
Button(self.frame, text="Pass turn", command=self.pass_turn).grid(column=1, row=0, sticky=NE)
|
||||
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
|
||||
|
||||
label(str(event))
|
||||
|
||||
for event in self.game.events:
|
||||
@ -64,10 +57,6 @@ class MainMenu(Menu):
|
||||
|
||||
event_button(event, "{} {}".format(event.attacker.name != self.game.player and "!" or " ", event))
|
||||
|
||||
Separator(self.frame, orient='horizontal').grid(row=row, sticky=EW); row += 1
|
||||
for cp in self.game.theater.player_points():
|
||||
cp_button(cp)
|
||||
|
||||
def pass_turn(self):
|
||||
self.game.pass_turn(no_action=True)
|
||||
self.display()
|
||||
@ -75,5 +64,10 @@ class MainMenu(Menu):
|
||||
def start_event(self, event) -> typing.Callable:
|
||||
return lambda: EventMenu(self.window, self, self.game, event).display()
|
||||
|
||||
def go_cp(self, cp: ControlPoint) -> typing.Callable:
|
||||
return lambda: BaseMenu(self.window, self, self.game, cp).display()
|
||||
def go_cp(self, cp: ControlPoint):
|
||||
if self.basemenu:
|
||||
self.basemenu.dismiss()
|
||||
self.basemenu = None
|
||||
|
||||
self.basemenu = BaseMenu(self.window, self, self.game, cp)
|
||||
self.basemenu.display()
|
||||
|
||||
@ -7,19 +7,22 @@ from game.game import *
|
||||
|
||||
|
||||
class OverviewCanvas:
|
||||
def __init__(self, frame: Frame, game: Game):
|
||||
self.canvas = Canvas(frame, width=600, height=400)
|
||||
mainmenu = None # type: ui.mainmenu.MainMenu
|
||||
|
||||
def __init__(self, frame: Frame, parent, game: Game):
|
||||
self.canvas = Canvas(frame, width=616, height=350)
|
||||
self.canvas.grid(column=0, row=0, sticky=NSEW)
|
||||
self.image = PhotoImage(file="resources/caumap.gif")
|
||||
self.parent = parent
|
||||
|
||||
self.game = game
|
||||
|
||||
def cp_coordinates(self, cp: ControlPoint) -> (int, int):
|
||||
point_a = (-317948.32727306, 635639.37385346)
|
||||
point_a_img = 361 - 60, 306 + 20
|
||||
point_a_img = 282.5, 319
|
||||
|
||||
point_b = (-355692.3067714, 617269.96285781)
|
||||
point_b_img = 345 - 59.5, 339 + 19.5
|
||||
point_b_img = 269, 352
|
||||
|
||||
x_dist = point_a_img[0] - point_b_img[0]
|
||||
lon_dist = point_a[1] - point_b[1]
|
||||
@ -36,6 +39,13 @@ class OverviewCanvas:
|
||||
|
||||
return point_b_img[1] + y_offset * y_scale, point_a_img[0] - x_offset * x_scale
|
||||
|
||||
def create_cp_title(self, coords, cp: ControlPoint):
|
||||
title = cp.name
|
||||
font = ("Helvetica", 13)
|
||||
|
||||
self.canvas.create_text(coords[0]+1, coords[1]+1, text=title, fill='white', font=font)
|
||||
self.canvas.create_text(coords[0], coords[1], text=title, font=font)
|
||||
|
||||
def update(self):
|
||||
self.canvas.delete(ALL)
|
||||
self.canvas.create_image((self.image.width()/2, self.image.height()/2), image=self.image)
|
||||
@ -51,12 +61,28 @@ class OverviewCanvas:
|
||||
else:
|
||||
color = "black"
|
||||
|
||||
self.canvas.create_line((coords[0], coords[1], connected_coords[0], connected_coords[1]), width=3, fill=color)
|
||||
self.canvas.create_line((coords[0], coords[1], connected_coords[0], connected_coords[1]), width=2, fill=color)
|
||||
|
||||
for cp in self.game.theater.controlpoints:
|
||||
coords = self.cp_coordinates(cp)
|
||||
arc_size = 12 * math.pow(cp.importance, 1)
|
||||
self.canvas.create_arc((coords[0] - arc_size/2, coords[1] - arc_size/2),
|
||||
(coords[0]+arc_size, coords[1]+arc_size),
|
||||
fill='red')
|
||||
arc_size = 18 * math.pow(cp.importance, 1)
|
||||
extent = max(cp.base.strength * 180, 10)
|
||||
start = (180 - extent) / 2
|
||||
color = cp.captured and 'blue' or 'red'
|
||||
|
||||
cp_id = self.canvas.create_arc((coords[0] - arc_size/2, coords[1] - arc_size/2),
|
||||
(coords[0]+arc_size/2, coords[1]+arc_size/2),
|
||||
fill=color,
|
||||
style=PIESLICE,
|
||||
start=start,
|
||||
extent=extent)
|
||||
self.canvas.tag_bind(cp_id, "<Button-1>", self.display(cp))
|
||||
self.create_cp_title((coords[0] + arc_size/2, coords[1] + arc_size/2), cp)
|
||||
self.canvas.create_text(coords[0], coords[1] - arc_size / 1.5, text="8/4/2", font=("Helvetica", 10))
|
||||
|
||||
def display(self, cp: ControlPoint):
|
||||
def action(_):
|
||||
return self.parent.go_cp(cp)
|
||||
|
||||
return action
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user