Skip to content

Commit 47fc609

Browse files
authored
Command (#151)
1 parent ada2036 commit 47fc609

File tree

140 files changed

+2342
-17635
lines changed

Some content is hidden

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

140 files changed

+2342
-17635
lines changed

client/src/action_buttons.rs

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ use crate::render_context::RenderContext;
77
use server::action::Action;
88
use server::content::advances::get_advance_by_name;
99
use server::content::custom_actions::{CustomAction, CustomActionType};
10+
use server::game::GameState;
1011
use server::playing_actions::{PlayingAction, PlayingActionType};
1112
use server::resource::ResourceType;
1213

@@ -80,7 +81,7 @@ fn global_move(rc: &RenderContext) -> StateUpdate {
8081
fn custom_action_tooltip(custom_action_type: &CustomActionType) -> String {
8182
match custom_action_type {
8283
CustomActionType::ConstructWonder => "Construct a wonder".to_string(),
83-
CustomActionType::ForcedLabor => get_advance_by_name("Absolute Power").description,
84+
CustomActionType::AbsolutePower => get_advance_by_name("Absolute Power").description,
8485
CustomActionType::VotingIncreaseHappiness => get_advance_by_name("Voting").description,
8586
CustomActionType::FreeEconomyCollect => get_advance_by_name("Free Economy").description,
8687
}
@@ -94,7 +95,7 @@ fn generic_custom_action(custom_action_type: &CustomActionType) -> Option<Custom
9495
// handled explicitly
9596
None
9697
}
97-
CustomActionType::ForcedLabor => Some(CustomAction::ForcedLabor),
98+
CustomActionType::AbsolutePower => Some(CustomAction::ForcedLabor),
9899
}
99100
}
100101

@@ -104,10 +105,11 @@ pub fn base_or_custom_available(
104105
custom: &CustomActionType,
105106
) -> bool {
106107
rc.can_play_action(action)
107-
|| rc
108-
.game
109-
.get_available_custom_actions(rc.shown_player.index)
110-
.contains(custom)
108+
|| (rc.game.state == GameState::Playing
109+
&& rc
110+
.game
111+
.get_available_custom_actions(rc.shown_player.index)
112+
.contains(custom))
111113
}
112114

113115
pub fn base_or_custom_action(

client/src/assets.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -217,7 +217,7 @@ impl Assets {
217217

218218
fn custom_actions() -> HashMap<CustomActionType, Texture2D> {
219219
[(
220-
CustomActionType::ForcedLabor,
220+
CustomActionType::AbsolutePower,
221221
load_png(include_bytes!("../assets/slavery-whip-svgrepo-com.png")),
222222
)]
223223
.iter()

server/src/ability_initializer.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
157157
let player_name = game.players[player_index].get_name();
158158
let mut ctx = game.custom_phase_state.clone();
159159
ctx.current.as_mut().expect("current missing").response = None;
160-
game.undo_context_stack
161-
.push(UndoContext::CustomPhaseEvent(ctx));
160+
game.push_undo_context(UndoContext::CustomPhaseEvent(ctx));
162161
let r = state.request.clone();
163162
let a = action.clone();
164163
game.custom_phase_state = CustomPhaseEventState::new();

server/src/content/advances.rs

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -249,24 +249,30 @@ fn cartography() -> AdvanceBuilder {
249249
.with_advance_bonus(CultureToken)
250250
.add_player_event_listener(
251251
|event| &mut event.before_move,
252-
|player, units, destination| {
253-
//todo only for first move
254-
//todo undo
252+
|player, g, i| {
253+
// info is the action that we last used this ability for
254+
let key = g.actions_left.to_string();
255+
if player.info.get("Cartography").is_some_and(|info| info == &key) {
256+
return;
257+
}
255258
let mut ship = false;
256259
let mut navigation = false;
257-
for id in units {
258-
let unit = player.get_unit(*id).expect("unit should exist");
260+
for id in &i.units {
261+
let unit = g.get_player(i.player).get_unit(*id).expect("unit should exist");
259262
if unit.unit_type.is_ship() {
260263
ship = true;
261-
if !unit.position.is_neighbor(*destination) {
264+
if !unit.position.is_neighbor(i.to) {
262265
navigation = true;
263266
}
264267
}
265268
}
266269
if ship {
270+
player.info.insert("Cartography".to_string(), key);
267271
player.gain_resources(ResourcePile::ideas(1));
272+
player.add_to_last_log_item(". Cartography gained 1 idea");
268273
if navigation {
269274
player.gain_resources(ResourcePile::culture_tokens(1));
275+
player.add_to_last_log_item(" and 1 culture token (for using navigation)");
270276
}
271277
}
272278
},
@@ -706,7 +712,7 @@ fn autocracy() -> Vec<Advance> {
706712
.leading_government_advance("Autocracy")
707713
.with_contradicting_advance(&["Voting", "Dogma"])
708714
, Advance::builder("Absolute Power", "Once per turn, as a free action, you may spend 2 mood tokens to get an additional action")
709-
.add_custom_action(ForcedLabor)
715+
.add_custom_action(AbsolutePower)
710716
, ],
711717
)
712718
}

server/src/content/custom_actions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ pub enum CustomAction {
2727
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Hash)]
2828
pub enum CustomActionType {
2929
ConstructWonder,
30-
ForcedLabor,
30+
AbsolutePower,
3131
VotingIncreaseHappiness,
3232
FreeEconomyCollect,
3333
}
@@ -61,7 +61,7 @@ impl CustomAction {
6161
pub fn custom_action_type(&self) -> CustomActionType {
6262
match self {
6363
CustomAction::ConstructWonder { .. } => CustomActionType::ConstructWonder,
64-
CustomAction::ForcedLabor => CustomActionType::ForcedLabor,
64+
CustomAction::ForcedLabor => CustomActionType::AbsolutePower,
6565
CustomAction::VotingIncreaseHappiness(_) => CustomActionType::VotingIncreaseHappiness,
6666
CustomAction::FreeEconomyCollect(_) => CustomActionType::FreeEconomyCollect,
6767
}
@@ -114,7 +114,7 @@ impl CustomActionType {
114114
pub fn action_type(&self) -> ActionType {
115115
match self {
116116
CustomActionType::ConstructWonder => ActionType::default(),
117-
CustomActionType::ForcedLabor => {
117+
CustomActionType::AbsolutePower => {
118118
ActionType::free_and_once_per_turn(ResourcePile::mood_tokens(2))
119119
}
120120
CustomActionType::VotingIncreaseHappiness => {
@@ -131,7 +131,7 @@ impl CustomActionType {
131131
match self {
132132
CustomActionType::FreeEconomyCollect => !current_turn_log(game)
133133
.iter()
134-
.any(|action| matches!(action, Action::Playing(PlayingAction::Collect(_)))),
134+
.any(|item| matches!(item.action, Action::Playing(PlayingAction::Collect(_)))),
135135
_ => true,
136136
}
137137
}

server/src/content/custom_phase_actions.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ impl CustomPhaseEventAction {
8585
player.loose_resources(r);
8686
}
8787
}
88-
let Some(UndoContext::CustomPhaseEvent(e)) = game.undo_context_stack.pop() else {
88+
let Some(UndoContext::CustomPhaseEvent(e)) = game.pop_undo_context() else {
8989
panic!("when undoing custom phase event, the undo context stack should have a custom phase event")
9090
};
9191
game.custom_phase_state = e;

server/src/explore.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ pub(crate) fn explore_resolution(game: &mut Game, r: &ExploreResolutionState, ro
284284
}
285285

286286
pub(crate) fn undo_explore_resolution(game: &mut Game, player_index: usize) {
287-
let Some(UndoContext::ExploreResolution(s)) = game.undo_context_stack.pop() else {
287+
let Some(UndoContext::ExploreResolution(s)) = game.pop_undo_context() else {
288288
panic!("when undoing explore resolution, the undo context stack should have an explore resolution")
289289
};
290290

0 commit comments

Comments
 (0)