Skip to content

Commit 3b696e0

Browse files
authored
remaining base tech (not civ specific) (#159)
1 parent 64fe466 commit 3b696e0

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+2877
-557
lines changed

client/src/client.rs

+7-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use macroquad::prelude::clear_background;
33
use macroquad::prelude::*;
44

55
use server::action::Action;
6+
use server::content::custom_phase_actions::CustomPhaseEventAction;
67
use server::game::Game;
78
use server::position::Position;
89

@@ -130,7 +131,7 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
130131
ActiveDialog::None
131132
| ActiveDialog::WaitingForUpdate
132133
| ActiveDialog::CulturalInfluence(_)
133-
| ActiveDialog::PlaceSettler => StateUpdate::None,
134+
| ActiveDialog::CustomPhasePositionRequest(_) => StateUpdate::None,
134135
ActiveDialog::DialogChooser(d) => dialog_chooser(rc, d),
135136
ActiveDialog::Log => show_log(rc),
136137

@@ -230,9 +231,11 @@ fn controlling_player_click(rc: &RenderContext, mouse_pos: Vec2, pos: Position)
230231
StateUpdate::OpenDialog(ActiveDialog::ReplaceUnits(new.clone()))
231232
}),
232233
ActiveDialog::RazeSize1City => raze_city_confirm_dialog(rc, pos),
233-
ActiveDialog::PlaceSettler => {
234-
if rc.shown_player.get_city(pos).is_some() {
235-
StateUpdate::Execute(Action::PlaceSettler(pos))
234+
ActiveDialog::CustomPhasePositionRequest(choices) => {
235+
if choices.contains(&pos) {
236+
StateUpdate::Execute(Action::CustomPhaseEvent(
237+
CustomPhaseEventAction::SelectPosition(pos),
238+
))
236239
} else {
237240
StateUpdate::None
238241
}

client/src/client_state.rs

+7-5
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ pub enum ActiveDialog {
5555

5656
// combat
5757
PlayActionCard,
58-
PlaceSettler,
5958
Retreat,
6059
RemoveCasualties(RemoveCasualtiesSelection),
6160

@@ -66,6 +65,7 @@ pub enum ActiveDialog {
6665
CustomPhaseResourceRewardRequest(Payment),
6766
CustomPhaseAdvanceRewardRequest(CustomPhaseAdvanceRewardRequest),
6867
CustomPhasePaymentRequest(Vec<Payment>),
68+
CustomPhasePositionRequest(Vec<Position>),
6969
}
7070

7171
impl ActiveDialog {
@@ -95,7 +95,6 @@ impl ActiveDialog {
9595
ActiveDialog::ChangeGovernmentType => "change government type",
9696
ActiveDialog::ChooseAdditionalAdvances(_) => "choose additional advances",
9797
ActiveDialog::PlayActionCard => "play action card",
98-
ActiveDialog::PlaceSettler => "place settler",
9998
ActiveDialog::Retreat => "retreat",
10099
ActiveDialog::RemoveCasualties(_) => "remove casualties",
101100
ActiveDialog::Sports(_) => "sports",
@@ -104,6 +103,7 @@ impl ActiveDialog {
104103
ActiveDialog::CustomPhaseResourceRewardRequest(_) => "trade route selection",
105104
ActiveDialog::CustomPhaseAdvanceRewardRequest(_) => "advance selection",
106105
ActiveDialog::CustomPhasePaymentRequest(_) => "custom phase payment request",
106+
ActiveDialog::CustomPhasePositionRequest(_) => "custom phase position request",
107107
}
108108
}
109109

@@ -162,7 +162,6 @@ impl ActiveDialog {
162162
vec!["Click on an advance to choose it".to_string()]
163163
}
164164
ActiveDialog::PlayActionCard => vec!["Click on an action card to play it".to_string()],
165-
ActiveDialog::PlaceSettler => vec!["Click on a tile to place a settler".to_string()],
166165
ActiveDialog::Retreat => vec!["Do you want to retreat?".to_string()],
167166
ActiveDialog::RemoveCasualties(r) => vec![format!(
168167
"Remove {} units: click on a unit to remove it",
@@ -184,7 +183,8 @@ impl ActiveDialog {
184183
}
185184
ActiveDialog::CustomPhaseResourceRewardRequest(_)
186185
| ActiveDialog::CustomPhaseAdvanceRewardRequest(_)
187-
| ActiveDialog::CustomPhasePaymentRequest(_) => {
186+
| ActiveDialog::CustomPhasePaymentRequest(_)
187+
| ActiveDialog::CustomPhasePositionRequest(_) => {
188188
event_help(rc, &custom_phase_event_origin(rc), true)
189189
}
190190
}
@@ -552,6 +552,9 @@ impl State {
552552
CustomPhaseRequest::AdvanceReward(r) => {
553553
ActiveDialog::CustomPhaseAdvanceRewardRequest(r.clone())
554554
}
555+
CustomPhaseRequest::SelectPosition(r) => {
556+
ActiveDialog::CustomPhasePositionRequest(r.choices.clone())
557+
}
555558
};
556559
}
557560
match &game.state {
@@ -573,7 +576,6 @@ impl State {
573576
StatusPhaseState::ChangeGovernmentType => ActiveDialog::ChangeGovernmentType,
574577
StatusPhaseState::DetermineFirstPlayer => ActiveDialog::DetermineFirstPlayer,
575578
},
576-
GameState::PlaceSettler { .. } => ActiveDialog::PlaceSettler,
577579
GameState::Combat(c) => match &c.phase {
578580
CombatPhase::PlayActionCard(_) => ActiveDialog::PlayActionCard,
579581
CombatPhase::RemoveCasualties(r) => {

client/src/collect_ui.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ use macroquad::math::vec2;
1313
use macroquad::prelude::WHITE;
1414
use macroquad::shapes::draw_circle;
1515
use server::action::Action;
16-
use server::collect::{get_total_collection, possible_resource_collections, CollectOptionsInfo};
16+
use server::collect::{get_total_collection, possible_resource_collections, CollectInfo};
1717
use server::content::custom_actions::CustomAction;
1818
use server::game::Game;
1919
use server::playing_actions::{Collect, PlayingAction};
@@ -27,15 +27,15 @@ pub struct CollectResources {
2727
city_position: Position,
2828
collections: Vec<(Position, ResourcePile)>,
2929
custom: BaseOrCustomDialog,
30-
pub info: CollectOptionsInfo,
30+
pub info: CollectInfo,
3131
}
3232

3333
impl CollectResources {
3434
pub fn new(
3535
player_index: usize,
3636
city_position: Position,
3737
custom: BaseOrCustomDialog,
38-
info: CollectOptionsInfo,
38+
info: CollectInfo,
3939
) -> CollectResources {
4040
CollectResources {
4141
player_index,
@@ -92,7 +92,7 @@ pub fn collect_dialog(rc: &RenderContext, collect: &CollectResources) -> StateUp
9292
)
9393
.map_or(
9494
OkTooltip::Invalid("Too many resources selected".to_string()),
95-
|(_, p)| OkTooltip::Valid(format!("Collect {p}")),
95+
|i| OkTooltip::Valid(format!("Collect {}", i.total)),
9696
);
9797
if ok_button(rc, tooltip) {
9898
let extra = collect.extra_resources(game);

client/src/event_ui.rs

+2
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ use crate::log_ui::break_text;
22
use crate::payment_ui::Payment;
33
use crate::render_context::RenderContext;
44
use server::content::advances::get_advance;
5+
use server::content::builtin::get_builtin;
56
use server::content::wonders::get_wonder;
67
use server::events::EventOrigin;
78

@@ -10,6 +11,7 @@ pub fn event_help(rc: &RenderContext, origin: &EventOrigin, do_break: bool) -> V
1011
let h = match origin {
1112
EventOrigin::Advance(a) => get_advance(a).description,
1213
EventOrigin::Wonder(w) => get_wonder(w).description,
14+
EventOrigin::Builtin(b) => get_builtin(b).description,
1315
EventOrigin::Leader(l) => {
1416
let l = rc.shown_player.get_leader(l).unwrap();
1517
// todo: leader should have a 2 event sources

client/src/map_ui.rs

+2-3
Original file line numberDiff line numberDiff line change
@@ -138,6 +138,7 @@ pub fn pan_and_zoom(state: &mut State) {
138138
fn overlay_color(rc: &RenderContext, pos: Position) -> Color {
139139
let game = rc.game;
140140
let state = &rc.state;
141+
141142
match &state.active_dialog {
142143
ActiveDialog::MoveUnits(s) => {
143144
if let Some(start) = s.start {
@@ -160,9 +161,7 @@ fn overlay_color(rc: &RenderContext, pos: Position) -> Color {
160161
ActiveDialog::RazeSize1City => {
161162
highlight_if(game.players[game.active_player()].can_raze_city(pos))
162163
}
163-
ActiveDialog::PlaceSettler => {
164-
highlight_if(game.players[game.active_player()].get_city(pos).is_some())
165-
}
164+
ActiveDialog::CustomPhasePositionRequest(choices) => highlight_if(choices.contains(&pos)),
166165
_ => {
167166
if let Some(p) = state.focused_tile {
168167
highlight_if(p == pos)

client/src/player_ui.rs

-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,6 @@ fn move_state(state: &GameState) -> Option<&MoveState> {
254254
GameState::Combat(c) => move_state(&c.initiation),
255255
GameState::ExploreResolution(r) => Some(&r.move_state),
256256
GameState::Movement(m) => Some(m),
257-
GameState::PlaceSettler(p) => Some(&p.move_state),
258257
_ => None,
259258
}
260259
}

server/src/ability_initializer.rs

+50-7
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,12 @@
11
use crate::content::custom_phase_actions::{
22
CurrentCustomPhaseEvent, CustomPhaseAdvanceRewardRequest, CustomPhaseEventAction,
3-
CustomPhasePaymentRequest, CustomPhaseRequest, CustomPhaseResourceRewardRequest,
3+
CustomPhasePaymentRequest, CustomPhasePositionRequest, CustomPhaseRequest,
4+
CustomPhaseResourceRewardRequest,
45
};
56
use crate::events::{Event, EventOrigin};
67
use crate::game::UndoContext;
7-
use crate::player_events::{CustomPhaseInfo, PlayerCommands};
8+
use crate::player_events::{CustomPhaseEvent, PlayerCommands};
9+
use crate::position::Position;
810
use crate::resource_pile::ResourcePile;
911
use crate::{content::custom_actions::CustomActionType, game::Game, player_events::PlayerEvents};
1012
use std::collections::HashMap;
@@ -90,7 +92,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
9092
+ Clone,
9193
) -> Self
9294
where
93-
E: Fn(&mut PlayerEvents) -> &mut Event<Game, CustomPhaseInfo, V> + 'static + Clone,
95+
E: Fn(&mut PlayerEvents) -> &mut CustomPhaseEvent<V> + 'static + Clone,
9496
{
9597
let origin = self.get_key();
9698
self.add_player_event_listener(
@@ -156,7 +158,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
156158
gain_reward: impl Fn(&mut PlayerCommands, &Game, &Vec<ResourcePile>) + 'static + Clone,
157159
) -> Self
158160
where
159-
E: Fn(&mut PlayerEvents) -> &mut Event<Game, CustomPhaseInfo, V> + 'static + Clone,
161+
E: Fn(&mut PlayerEvents) -> &mut CustomPhaseEvent<V> + 'static + Clone,
160162
{
161163
self.add_payment_request_listener(
162164
event,
@@ -180,7 +182,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
180182
gain_reward: impl Fn(&mut Game, usize, &str, &Vec<ResourcePile>) + 'static + Clone,
181183
) -> Self
182184
where
183-
E: Fn(&mut PlayerEvents) -> &mut Event<Game, CustomPhaseInfo, V> + 'static + Clone,
185+
E: Fn(&mut PlayerEvents) -> &mut CustomPhaseEvent<V> + 'static + Clone,
184186
{
185187
self.add_state_change_event_listener(
186188
event,
@@ -217,7 +219,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
217219
gain_reward_log: impl Fn(&Game, usize, &str, &ResourcePile, bool) -> String + 'static + Clone,
218220
) -> Self
219221
where
220-
E: Fn(&mut PlayerEvents) -> &mut Event<Game, CustomPhaseInfo, V> + 'static + Clone,
222+
E: Fn(&mut PlayerEvents) -> &mut CustomPhaseEvent<V> + 'static + Clone,
221223
{
222224
let g = gain_reward_log.clone();
223225
self.add_state_change_event_listener(
@@ -266,7 +268,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
266268
gain_reward: impl Fn(&mut Game, usize, &str, &str, bool) + 'static + Clone,
267269
) -> Self
268270
where
269-
E: Fn(&mut PlayerEvents) -> &mut Event<Game, CustomPhaseInfo, V> + 'static + Clone,
271+
E: Fn(&mut PlayerEvents) -> &mut CustomPhaseEvent<V> + 'static + Clone,
270272
{
271273
let g = gain_reward.clone();
272274
self.add_state_change_event_listener(
@@ -302,6 +304,47 @@ pub(crate) trait AbilityInitializerSetup: Sized {
302304
)
303305
}
304306

307+
fn add_position_reward_request_listener<E, V>(
308+
self,
309+
event: E,
310+
priority: i32,
311+
request: impl Fn(&mut Game, usize, &V) -> Option<CustomPhasePositionRequest> + 'static + Clone,
312+
gain_reward: impl Fn(&mut PlayerCommands, &Game, &Position) + 'static + Clone,
313+
) -> Self
314+
where
315+
E: Fn(&mut PlayerEvents) -> &mut CustomPhaseEvent<V> + 'static + Clone,
316+
{
317+
let g = gain_reward.clone();
318+
self.add_state_change_event_listener(
319+
event,
320+
priority,
321+
move |game, player_index, _player_name, details| {
322+
let req = request(game, player_index, details);
323+
if let Some(r) = &req {
324+
if r.choices.len() == 1 {
325+
game.with_commands(player_index, |commands, game| {
326+
g(commands, game, &r.choices[0]);
327+
});
328+
return None;
329+
}
330+
}
331+
req.map(CustomPhaseRequest::SelectPosition)
332+
},
333+
move |game, player_index, _player_name, action, request| {
334+
if let CustomPhaseRequest::SelectPosition(request) = &request {
335+
if let CustomPhaseEventAction::SelectPosition(reward) = action {
336+
assert!(request.choices.contains(&reward), "Invalid position");
337+
game.with_commands(player_index, |commands, game| {
338+
gain_reward(commands, game, &reward);
339+
});
340+
return;
341+
}
342+
}
343+
panic!("Invalid state");
344+
},
345+
)
346+
}
347+
305348
fn add_custom_action(self, action: CustomActionType) -> Self {
306349
let deinitializer_action = action.clone();
307350
let key = self.get_key().clone();

server/src/action.rs

-11
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
use crate::content::custom_phase_actions::CustomPhaseEventAction;
22
use crate::map::Rotation;
33
use crate::playing_actions::PlayingAction;
4-
use crate::position::Position;
54
use crate::status_phase::StatusPhaseAction;
65
use crate::unit::MovementAction;
76
use serde::{Deserialize, Serialize};
@@ -13,7 +12,6 @@ pub enum Action {
1312
Movement(MovementAction),
1413
CulturalInfluenceResolution(bool),
1514
Combat(CombatAction),
16-
PlaceSettler(Position),
1715
ExploreResolution(Rotation),
1816
CustomPhaseEvent(CustomPhaseEventAction),
1917
Undo,
@@ -75,15 +73,6 @@ impl Action {
7573
}
7674
}
7775

78-
#[must_use]
79-
pub fn place_settler(self) -> Option<Position> {
80-
if let Self::PlaceSettler(v) = self {
81-
Some(v)
82-
} else {
83-
None
84-
}
85-
}
86-
8776
#[must_use]
8877
pub fn explore_resolution(self) -> Option<Rotation> {
8978
if let Self::ExploreResolution(v) = self {

server/src/city.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ impl City {
9696

9797
pub fn undo_activate(&mut self) {
9898
self.activations -= 1;
99-
self.angry_activation = false;
100-
if self.is_activated() {
99+
if self.angry_activation {
100+
self.angry_activation = false;
101+
} else if self.is_activated() {
101102
self.increase_mood_state();
102103
}
103104
}

0 commit comments

Comments
 (0)