Skip to content

Commit 51c619c

Browse files
authored
Trade routes (#141)
1 parent 6a86e95 commit 51c619c

31 files changed

+5133
-124
lines changed

client/src/advance_ui.rs

+5-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::client_state::{ActiveDialog, StateUpdate};
22
use crate::layout_ui::{left_mouse_button_pressed_in_rect, top_centered_text};
33
use crate::log_ui::break_text;
4-
use crate::payment_ui::{new_payment, payment_dialog, Payment};
4+
use crate::payment_ui::{payment_dialog, Payment};
55
use crate::player_ui::player_color;
66
use crate::render_context::RenderContext;
77
use crate::tooltip::show_tooltip_for_rect;
@@ -30,7 +30,9 @@ pub enum AdvanceState {
3030

3131
fn new_advance_payment(rc: &RenderContext, name: &str) -> Payment {
3232
let p = rc.shown_player;
33-
new_payment(&p.advance_cost(name), &p.resources, name, false)
33+
let model = &p.advance_cost(name);
34+
let available = &p.resources;
35+
Payment::new(model, available, name, false)
3436
}
3537

3638
pub fn show_paid_advance_menu(rc: &RenderContext) -> StateUpdate {
@@ -212,7 +214,7 @@ pub fn pay_advance_dialog(ap: &Payment, rc: &RenderContext) -> StateUpdate {
212214
// select a different advance
213215
return update;
214216
};
215-
payment_dialog(rc, ap, ActiveDialog::AdvancePayment, true, |payment| {
217+
payment_dialog(rc, ap, ActiveDialog::AdvancePayment, |payment| {
216218
StateUpdate::Execute(Action::Playing(PlayingAction::Advance {
217219
advance: ap.name.to_string(),
218220
payment,

client/src/client.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ use crate::render_context::RenderContext;
2323
use crate::status_phase_ui::raze_city_confirm_dialog;
2424
use crate::unit_ui::unit_selection_click;
2525
use crate::{
26-
combat_ui, dialog_ui, influence_ui, map_ui, move_ui, recruit_unit_ui, status_phase_ui, tooltip,
26+
combat_ui, custom_actions_ui, dialog_ui, influence_ui, map_ui, move_ui, recruit_unit_ui,
27+
status_phase_ui, tooltip,
2728
};
2829

2930
fn render_with_mutable_state(game: &Game, state: &mut State, features: &Features) -> StateUpdate {
@@ -155,6 +156,9 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
155156
status_phase_ui::choose_additional_advances_dialog(rc, a)
156157
}
157158
ActiveDialog::DetermineFirstPlayer => status_phase_ui::determine_first_player_dialog(rc),
159+
ActiveDialog::TradeRouteSelection(p) => {
160+
custom_actions_ui::trade_route_selection_dialog(rc, p)
161+
}
158162

159163
//combat
160164
ActiveDialog::PlayActionCard => combat_ui::play_action_card_dialog(rc),

client/src/client_state.rs

+13-20
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
use macroquad::prelude::*;
22
use server::action::Action;
33
use server::city::{City, MoodState};
4-
use server::combat::{active_attackers, active_defenders, Combat, CombatPhase};
4+
use server::combat::{active_attackers, active_defenders, CombatPhase};
55
use server::content::advances::{NAVIGATION, ROADS, SIEGECRAFT, STEEL_WEAPONS};
6-
use server::content::custom_phase_actions::{steel_weapons_cost, CustomPhaseState};
6+
use server::content::custom_phase_actions::CustomPhaseState;
77
use server::game::{CulturalInfluenceResolution, CurrentMove, Game, GameState};
88
use server::position::Position;
99
use server::status_phase::{StatusPhaseAction, StatusPhaseState};
@@ -12,14 +12,17 @@ use crate::assets::Assets;
1212
use crate::city_ui::building_name;
1313
use crate::client::{Features, GameSyncRequest};
1414
use crate::collect_ui::CollectResources;
15-
use crate::combat_ui::{RemoveCasualtiesSelection, SiegecraftPaymentDialog, SteelWeaponDialog};
15+
use crate::combat_ui::{
16+
steel_weapons_dialog, RemoveCasualtiesSelection, SiegecraftPaymentDialog, SteelWeaponDialog,
17+
};
1618
use crate::construct_ui::ConstructionPayment;
19+
use crate::custom_actions_ui::trade_route_dialog;
1720
use crate::happiness_ui::IncreaseHappinessConfig;
1821
use crate::layout_ui::FONT_SIZE;
1922
use crate::log_ui::{add_advance_help, advance_help};
2023
use crate::map_ui::ExploreResolutionConfig;
2124
use crate::move_ui::{MoveDestination, MoveIntent, MoveSelection};
22-
use crate::payment_ui::{new_payment, Payment};
25+
use crate::payment_ui::Payment;
2326
use crate::recruit_unit_ui::{RecruitAmount, RecruitSelection};
2427
use crate::render_context::RenderContext;
2528
use crate::status_phase_ui::ChooseAdditionalAdvances;
@@ -59,6 +62,7 @@ pub enum ActiveDialog {
5962
RemoveCasualties(RemoveCasualtiesSelection),
6063
SiegecraftPayment(SiegecraftPaymentDialog),
6164
SteelWeaponPayment(SteelWeaponDialog),
65+
TradeRouteSelection(Payment), // it's actually a gain
6266
}
6367

6468
impl ActiveDialog {
@@ -92,6 +96,7 @@ impl ActiveDialog {
9296
ActiveDialog::RemoveCasualties(_) => "remove casualties",
9397
ActiveDialog::SiegecraftPayment(_) => "siegecraft payment",
9498
ActiveDialog::SteelWeaponPayment(_) => "steel weapon payment",
99+
ActiveDialog::TradeRouteSelection(_) => "trade route selection",
95100
}
96101
}
97102

@@ -185,6 +190,7 @@ impl ActiveDialog {
185190
add_advance_help(rc, &mut result, STEEL_WEAPONS);
186191
result
187192
}
193+
ActiveDialog::TradeRouteSelection(_) => vec!["Select trade route reward".to_string()],
188194
}
189195
}
190196

@@ -557,29 +563,16 @@ impl State {
557563
ActiveDialog::SiegecraftPayment(SiegecraftPaymentDialog::new(game))
558564
}
559565
CustomPhaseState::SteelWeaponsAttacker(c) => {
560-
Self::steel_weapons_dialog(game, c, c.attacker)
566+
steel_weapons_dialog(game, c, c.attacker)
561567
}
562568
CustomPhaseState::SteelWeaponsDefender(c) => {
563-
Self::steel_weapons_dialog(game, c, c.defender)
569+
steel_weapons_dialog(game, c, c.defender)
564570
}
571+
CustomPhaseState::TradeRouteSelection => trade_route_dialog(game),
565572
},
566573
}
567574
}
568575

569-
fn steel_weapons_dialog(game: &Game, c: &Combat, player_index: usize) -> ActiveDialog {
570-
let payment = new_payment(
571-
&steel_weapons_cost(game, c, player_index),
572-
&game.get_player(player_index).resources,
573-
"Use steel weapons",
574-
true,
575-
);
576-
ActiveDialog::SteelWeaponPayment(SteelWeaponDialog {
577-
attacker: player_index == c.attacker,
578-
payment,
579-
combat: c.clone(),
580-
})
581-
}
582-
583576
#[must_use]
584577
pub fn measure_text(&self, text: &str) -> TextDimensions {
585578
measure_text(text, Some(&self.assets.font), FONT_SIZE, 1.0)

client/src/combat_ui.rs

+16-5
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
use crate::client_state::{ActiveDialog, StateUpdate};
22
use crate::dialog_ui::{cancel_button_with_tooltip, ok_button, OkTooltip};
3-
use crate::payment_ui::{multi_payment_dialog, new_payment, payment_dialog, Payment};
3+
use crate::payment_ui::{multi_payment_dialog, payment_dialog, Payment};
44
use crate::render_context::RenderContext;
55
use crate::select_ui::ConfirmSelection;
66
use crate::unit_ui;
77
use crate::unit_ui::UnitSelection;
88
use server::action::{Action, CombatAction, PlayActionCard};
99
use server::combat::Combat;
1010
use server::content::custom_phase_actions::{
11-
CustomPhaseAction, SiegecraftPayment, SIEGECRAFT_EXTRA_DIE, SIEGECRAFT_IGNORE_HIT,
11+
steel_weapons_cost, CustomPhaseAction, SiegecraftPayment, SIEGECRAFT_EXTRA_DIE,
12+
SIEGECRAFT_IGNORE_HIT,
1213
};
1314
use server::game::Game;
1415
use server::position::Position;
@@ -108,13 +109,13 @@ impl SiegecraftPaymentDialog {
108109
pub fn new(game: &Game) -> SiegecraftPaymentDialog {
109110
let available = game.get_player(game.active_player()).resources.clone();
110111
SiegecraftPaymentDialog {
111-
extra_die: new_payment(
112+
extra_die: Payment::new(
112113
&SIEGECRAFT_EXTRA_DIE,
113114
&available,
114115
"Cancel fortress extra die in first round of combat",
115116
true,
116117
),
117-
ignore_hit: new_payment(
118+
ignore_hit: Payment::new(
118119
&SIEGECRAFT_IGNORE_HIT,
119120
&available,
120121
"Cancel fortress ignore hit in first round of combat",
@@ -153,6 +154,17 @@ pub struct SteelWeaponDialog {
153154
pub combat: Combat,
154155
}
155156

157+
pub fn steel_weapons_dialog(game: &Game, c: &Combat, player_index: usize) -> ActiveDialog {
158+
let model = &steel_weapons_cost(game, c, player_index);
159+
let available = &game.get_player(player_index).resources;
160+
let payment = Payment::new(model, available, "Use steel weapons", true);
161+
ActiveDialog::SteelWeaponPayment(SteelWeaponDialog {
162+
attacker: player_index == c.attacker,
163+
payment,
164+
combat: c.clone(),
165+
})
166+
}
167+
156168
pub(crate) fn pay_steel_weapons_dialog(
157169
rc: &RenderContext,
158170
dialog: &SteelWeaponDialog,
@@ -167,7 +179,6 @@ pub(crate) fn pay_steel_weapons_dialog(
167179
n.payment = p;
168180
ActiveDialog::SteelWeaponPayment(n)
169181
},
170-
false,
171182
|p| {
172183
if attacker {
173184
StateUpdate::Execute(Action::CustomPhase(

client/src/construct_ui.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
use crate::client_state::{ActiveDialog, StateUpdate};
2-
use crate::payment_ui::{new_payment, payment_dialog, Payment};
2+
use crate::payment_ui::{payment_dialog, Payment};
33
use crate::recruit_unit_ui::RecruitSelection;
44
use crate::render_context::RenderContext;
55
use server::action::Action;
@@ -45,7 +45,6 @@ pub fn pay_construction_dialog(rc: &RenderContext, cp: &ConstructionPayment) ->
4545
new.payment = p;
4646
ActiveDialog::ConstructionPayment(new)
4747
},
48-
true,
4948
|payment| match &cp.project {
5049
ConstructionProject::Building(b, pos) => StateUpdate::execute_activation(
5150
Action::Playing(PlayingAction::Construct(Construct {
@@ -125,7 +124,8 @@ impl ConstructionPayment {
125124
),
126125
};
127126

128-
let payment = new_payment(&cost, &rc.shown_player.resources, name, false);
127+
let available = &rc.shown_player.resources;
128+
let payment = Payment::new(&cost, available, name, false);
129129

130130
ConstructionPayment {
131131
player_index: city.player_index,

client/src/custom_actions_ui.rs

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
use crate::client_state::{ActiveDialog, StateUpdate};
2+
use crate::payment_ui::{payment_dialog, Payment};
3+
use crate::render_context::RenderContext;
4+
use server::action::Action;
5+
use server::content::custom_phase_actions::CustomPhaseAction;
6+
use server::content::trade_routes::trade_route_reward;
7+
use server::game::Game;
8+
9+
pub fn trade_route_dialog(game: &Game) -> ActiveDialog {
10+
let model = trade_route_reward(game).unwrap().0;
11+
ActiveDialog::TradeRouteSelection(Payment::new_gain(model, "Select trade route reward"))
12+
}
13+
14+
pub fn trade_route_selection_dialog(rc: &RenderContext, payment: &Payment) -> StateUpdate {
15+
payment_dialog(
16+
rc,
17+
payment,
18+
|p| ActiveDialog::TradeRouteSelection(p.clone()),
19+
|p| {
20+
StateUpdate::Execute(Action::CustomPhase(
21+
CustomPhaseAction::TradeRouteSelectionAction(p),
22+
))
23+
},
24+
)
25+
}

client/src/happiness_ui.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
use crate::action_buttons::{base_or_custom_action, base_or_custom_available};
22
use crate::client_state::{ActiveDialog, StateUpdate};
33
use crate::dialog_ui::{BaseOrCustomAction, BaseOrCustomDialog};
4-
use crate::payment_ui::{new_payment, payment_dialog, Payment};
4+
use crate::payment_ui::{payment_dialog, Payment};
55
use crate::render_context::RenderContext;
66
use server::action::Action;
77
use server::city::City;
@@ -37,7 +37,8 @@ impl IncreaseHappinessConfig {
3737
.reduce(|a, b| a + b)
3838
.unwrap();
3939

40-
new_payment(&payment, &p.resources, "Increase happiness", false)
40+
let available = &p.resources;
41+
Payment::new(&payment, available, "Increase happiness", false)
4142
}
4243
}
4344

@@ -135,7 +136,6 @@ pub fn increase_happiness_menu(rc: &RenderContext, h: &IncreaseHappinessConfig)
135136
custom: h.custom.clone(),
136137
})
137138
},
138-
true,
139139
|payment| {
140140
let i = IncreaseHappiness {
141141
happiness_increases: h.steps.clone(),

client/src/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ pub mod client_state;
1818
mod collect_ui;
1919
mod combat_ui;
2020
mod construct_ui;
21+
mod custom_actions_ui;
2122
mod dialog_ui;
2223
mod happiness_ui;
2324
mod hex_ui;

0 commit comments

Comments
 (0)