-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconstruct_ui.rs
133 lines (126 loc) · 4.02 KB
/
construct_ui.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
use crate::client_state::{ActiveDialog, StateUpdate};
use crate::payment_ui::{payment_dialog, Payment};
use crate::recruit_unit_ui::RecruitSelection;
use crate::render_context::RenderContext;
use server::action::Action;
use server::city::City;
use server::city_pieces::Building;
use server::content::custom_actions::CustomAction;
use server::map::Terrain;
use server::playing_actions::{Construct, PlayingAction, Recruit};
use server::position::Position;
use server::recruit::recruit_cost;
pub fn new_building_positions(
building: Building,
rc: &RenderContext,
city: &City,
) -> Vec<(Building, Option<Position>)> {
if building != Building::Port {
return vec![(building, None)];
}
rc.game
.map
.tiles
.iter()
.filter_map(|(p, t)| {
if *t == Terrain::Water && city.position.is_neighbor(*p) {
Some((building, Some(*p)))
} else {
None
}
})
.collect()
}
pub fn pay_construction_dialog(rc: &RenderContext, cp: &ConstructionPayment) -> StateUpdate {
let city = rc.game.get_any_city(cp.city_position).unwrap();
payment_dialog(
rc,
&cp.payment.clone(),
true,
|p| {
let mut new = cp.clone();
new.payment = p;
ActiveDialog::ConstructionPayment(new)
},
|payment| match &cp.project {
ConstructionProject::Building(b, pos) => StateUpdate::execute_activation(
Action::Playing(PlayingAction::Construct(Construct {
city_position: cp.city_position,
city_piece: *b,
payment,
port_position: *pos,
})),
vec![],
city,
),
ConstructionProject::Wonder(w) => StateUpdate::execute_activation(
Action::Playing(PlayingAction::Custom(CustomAction::ConstructWonder {
city_position: cp.city_position,
payment,
wonder: w.clone(),
})),
vec![],
city,
),
ConstructionProject::Units(r) => StateUpdate::execute_activation(
Action::Playing(PlayingAction::Recruit(Recruit {
city_position: cp.city_position,
units: r.amount.units.clone(),
payment,
replaced_units: r.replaced_units.clone(),
leader_name: r.amount.leader_name.clone(),
})),
vec![],
city,
),
},
)
}
#[derive(Clone)]
pub enum ConstructionProject {
Building(Building, Option<Position>),
Wonder(String),
Units(RecruitSelection),
}
#[derive(Clone)]
pub struct ConstructionPayment {
pub player_index: usize,
pub city_position: Position,
pub project: ConstructionProject,
pub payment: Payment,
}
impl ConstructionPayment {
pub fn new(
rc: &RenderContext,
city: &City,
name: &str,
project: ConstructionProject,
) -> ConstructionPayment {
let p = rc.game.get_player(city.player_index);
let cost = match &project {
ConstructionProject::Building(b, _) => p.construct_cost(*b, city, None),
ConstructionProject::Wonder(name) => p.wonder_cost(
p.wonder_cards.iter().find(|w| w.name == *name).unwrap(),
city,
None,
),
ConstructionProject::Units(sel) => recruit_cost(
rc.shown_player,
&sel.amount.units,
city.position,
sel.amount.leader_name.as_ref(),
&sel.replaced_units,
None,
)
.unwrap(),
}
.cost;
let payment = rc.new_payment(&cost, name, false);
ConstructionPayment {
player_index: city.player_index,
city_position: city.position,
project,
payment,
}
}
}