mirror of
https://github.com/dcs-retribution/dcs-retribution.git
synced 2025-11-10 15:41:24 +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
|
ENEMY_CAPTURE_PROBABILITY_BASE = 5
|
||||||
|
|
||||||
PLAYER_INTERCEPT_PROBABILITY_BASE = 30
|
PLAYER_INTERCEPT_PROBABILITY_BASE = 30
|
||||||
@ -107,12 +107,17 @@ class Game:
|
|||||||
unit_type = random.choice(db.find_unittype(for_task, self.enemy))
|
unit_type = random.choice(db.find_unittype(for_task, self.enemy))
|
||||||
cp.base.commision_units({unit_type: points_to_spend})
|
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:
|
if len(self.theater.player_points()) > 0:
|
||||||
total_importance = sum([x.importance for x in self.theater.player_points()])
|
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())
|
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:
|
def units_delivery_event(self, to_cp: ControlPoint) -> UnitsDeliveryEvent:
|
||||||
event = UnitsDeliveryEvent(attacker_name=self.player,
|
event = UnitsDeliveryEvent(attacker_name=self.player,
|
||||||
@ -122,6 +127,9 @@ class Game:
|
|||||||
self.events.append(event)
|
self.events.append(event)
|
||||||
return event
|
return event
|
||||||
|
|
||||||
|
def units_delivery_remove(self, event: Event):
|
||||||
|
self.events.remove(event)
|
||||||
|
|
||||||
def initiate_event(self, event: Event):
|
def initiate_event(self, event: Event):
|
||||||
event.operation.generate()
|
event.operation.generate()
|
||||||
event.mission.save("build/next_mission.miz")
|
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 typing
|
||||||
import dcs
|
|
||||||
import math
|
import math
|
||||||
|
import random
|
||||||
import itertools
|
import itertools
|
||||||
|
|
||||||
|
import dcs
|
||||||
|
|
||||||
from shop import db
|
from shop import db
|
||||||
from theater.controlpoint import ControlPoint
|
from theater.controlpoint import ControlPoint
|
||||||
|
|
||||||
|
|||||||
@ -49,6 +49,12 @@ class BaseMenu(Menu):
|
|||||||
for unit_type in units:
|
for unit_type in units:
|
||||||
purchase_row(unit_type, db.PRICES[unit_type])
|
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 buy(self, unit_type):
|
||||||
def action():
|
def action():
|
||||||
price = db.PRICES[unit_type]
|
price = db.PRICES[unit_type]
|
||||||
|
|||||||
@ -10,6 +10,8 @@ from game.game import *
|
|||||||
|
|
||||||
|
|
||||||
class MainMenu(Menu):
|
class MainMenu(Menu):
|
||||||
|
basemenu = None # type: BaseMenu
|
||||||
|
|
||||||
def __init__(self, window: Window, parent, game: Game):
|
def __init__(self, window: Window, parent, game: Game):
|
||||||
super(MainMenu, self).__init__(window, parent, game)
|
super(MainMenu, self).__init__(window, parent, game)
|
||||||
|
|
||||||
@ -17,7 +19,7 @@ class MainMenu(Menu):
|
|||||||
#map = Label(window.left_pane, image=self.image)
|
#map = Label(window.left_pane, image=self.image)
|
||||||
#map.grid()
|
#map.grid()
|
||||||
|
|
||||||
self.upd = OverviewCanvas(self.window.left_pane, game)
|
self.upd = OverviewCanvas(self.window.left_pane, self, game)
|
||||||
self.upd.update()
|
self.upd.update()
|
||||||
|
|
||||||
self.frame = self.window.right_pane
|
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)
|
Button(self.frame, text=text, command=self.start_event(event)).grid(row=row, sticky=N)
|
||||||
row += 1
|
row += 1
|
||||||
|
|
||||||
def cp_button(cp):
|
Button(self.frame, text="Pass turn", command=self.pass_turn).grid(column=0, row=0, sticky=NE)
|
||||||
nonlocal row
|
Label(self.frame, text="Budget: {}m (+{}m)".format(self.game.budget, self.game.budget_reward_amount)).grid(column=0, row=0, sticky=NW)
|
||||||
title = "{}{}{}{}".format(
|
Separator(self.frame, orient='horizontal').grid(row=row, sticky=EW); row += 1
|
||||||
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
|
|
||||||
|
|
||||||
for event in self.game.events:
|
for event in self.game.events:
|
||||||
if not event.informational:
|
if not event.informational:
|
||||||
continue
|
continue
|
||||||
|
|
||||||
label(str(event))
|
label(str(event))
|
||||||
|
|
||||||
for event in self.game.events:
|
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))
|
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):
|
def pass_turn(self):
|
||||||
self.game.pass_turn(no_action=True)
|
self.game.pass_turn(no_action=True)
|
||||||
self.display()
|
self.display()
|
||||||
@ -75,5 +64,10 @@ class MainMenu(Menu):
|
|||||||
def start_event(self, event) -> typing.Callable:
|
def start_event(self, event) -> typing.Callable:
|
||||||
return lambda: EventMenu(self.window, self, self.game, event).display()
|
return lambda: EventMenu(self.window, self, self.game, event).display()
|
||||||
|
|
||||||
def go_cp(self, cp: ControlPoint) -> typing.Callable:
|
def go_cp(self, cp: ControlPoint):
|
||||||
return lambda: BaseMenu(self.window, self, self.game, cp).display()
|
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:
|
class OverviewCanvas:
|
||||||
def __init__(self, frame: Frame, game: Game):
|
mainmenu = None # type: ui.mainmenu.MainMenu
|
||||||
self.canvas = Canvas(frame, width=600, height=400)
|
|
||||||
|
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.canvas.grid(column=0, row=0, sticky=NSEW)
|
||||||
self.image = PhotoImage(file="resources/caumap.gif")
|
self.image = PhotoImage(file="resources/caumap.gif")
|
||||||
|
self.parent = parent
|
||||||
|
|
||||||
self.game = game
|
self.game = game
|
||||||
|
|
||||||
def cp_coordinates(self, cp: ControlPoint) -> (int, int):
|
def cp_coordinates(self, cp: ControlPoint) -> (int, int):
|
||||||
point_a = (-317948.32727306, 635639.37385346)
|
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 = (-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]
|
x_dist = point_a_img[0] - point_b_img[0]
|
||||||
lon_dist = point_a[1] - point_b[1]
|
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
|
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):
|
def update(self):
|
||||||
self.canvas.delete(ALL)
|
self.canvas.delete(ALL)
|
||||||
self.canvas.create_image((self.image.width()/2, self.image.height()/2), image=self.image)
|
self.canvas.create_image((self.image.width()/2, self.image.height()/2), image=self.image)
|
||||||
@ -51,12 +61,28 @@ class OverviewCanvas:
|
|||||||
else:
|
else:
|
||||||
color = "black"
|
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:
|
for cp in self.game.theater.controlpoints:
|
||||||
coords = self.cp_coordinates(cp)
|
coords = self.cp_coordinates(cp)
|
||||||
arc_size = 12 * math.pow(cp.importance, 1)
|
arc_size = 18 * math.pow(cp.importance, 1)
|
||||||
self.canvas.create_arc((coords[0] - arc_size/2, coords[1] - arc_size/2),
|
extent = max(cp.base.strength * 180, 10)
|
||||||
(coords[0]+arc_size, coords[1]+arc_size),
|
start = (180 - extent) / 2
|
||||||
fill='red')
|
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