Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Myths #138

Merged
merged 2 commits into from
Jan 25, 2025
Merged

Myths #138

Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions server/src/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -142,9 +142,9 @@ fn format_cultural_influence_attempt_log_item(
pub fn format_happiness_increase(
player: &Player,
player_name: &str,
happiness_increases: &IncreaseHappiness,
i: &IncreaseHappiness,
) -> String {
let happiness_increases = happiness_increases
let happiness_increases = i
.happiness_increases
.iter()
.filter_map(|(position, steps)| {
Expand All @@ -164,7 +164,8 @@ pub fn format_happiness_increase(
})
.collect::<Vec<String>>();
format!(
"{player_name} increased happiness in {}",
"{player_name} paid {} to increase happiness in {}",
i.payment,
utils::format_list(&happiness_increases, "no city")
)
}
Expand Down
9 changes: 4 additions & 5 deletions server/src/playing_actions.rs
Original file line number Diff line number Diff line change
Expand Up @@ -497,7 +497,9 @@ pub(crate) fn increase_happiness(game: &mut Game, player_index: usize, i: Increa
let cost = player
.increase_happiness_cost(city, steps)
.expect("Illegal action");
assert!(steps > 0, "Illegal action");
if steps == 0 {
continue;
}
if city.mood_state == MoodState::Angry {
angry_activations.push(city_position);
}
Expand All @@ -520,17 +522,14 @@ pub(crate) fn increase_happiness(game: &mut Game, player_index: usize, i: Increa
}

pub(crate) fn undo_increase_happiness(game: &mut Game, player_index: usize, i: IncreaseHappiness) {
let mut cost = 0;
let player = &mut game.players[player_index];
for (city_position, steps) in i.happiness_increases {
let city = player.get_city(city_position).expect("Illegal action");
cost += city.size() as u32 * steps;
let city = player.get_city_mut(city_position).expect("Illegal action");
for _ in 0..steps {
city.decrease_mood_state();
}
}
player.gain_resources(ResourcePile::mood_tokens(cost));
player.gain_resources(i.payment);

if let Some(UndoContext::IncreaseHappiness { angry_activations }) =
game.undo_context_stack.pop()
Expand Down
19 changes: 19 additions & 0 deletions server/tests/game_api_tests.rs
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,25 @@ fn test_increase_happiness_voting() {
);
}

#[test]
fn test_increase_happiness_voting_rituals() {
test_action(
"increase_happiness_voting_rituals",
Action::Playing(Custom(CustomAction::VotingIncreaseHappiness(
playing_actions::IncreaseHappiness {
happiness_increases: vec![
(Position::from_offset("C2"), 1),
(Position::from_offset("B3"), 2),
],
payment: ResourcePile::new(1, 0, 1, 1, 1, 1, 0),
},
))),
0,
true,
false,
);
}

#[test]
fn test_custom_action_forced_labor() {
test_action(
Expand Down
4 changes: 2 additions & 2 deletions server/tests/test_games/increase_happiness.outcome.json
Original file line number Diff line number Diff line change
Expand Up @@ -369,7 +369,7 @@
"The game has started",
"Age 1 has started",
"Round 1/3",
"Player1 increased happiness in the city at C2 by 1 steps, making it Neutral and the city at B3 by 2 steps, making it Happy"
"Player1 paid 5 mood tokens to increase happiness in the city at C2 by 1 steps, making it Neutral and the city at B3 by 2 steps, making it Happy"
],
"undo_limit": 0,
"actions_left": 2,
Expand Down Expand Up @@ -444,4 +444,4 @@
}
}
]
}
}
28 changes: 14 additions & 14 deletions server/tests/test_games/increase_happiness_voting.outcome.json
Original file line number Diff line number Diff line change
Expand Up @@ -348,30 +348,30 @@
"Playing": {
"Custom": {
"VotingIncreaseHappiness": {
"happiness_increases": [
[
"C2",
1
"happiness_increases": [
[
"C2",
1
],
[
"B3",
2
]
],
[
"B3",
2
]
],
"payment": {
"mood_tokens": 5
"payment": {
"mood_tokens": 5
}
}
}
}
}
}
],
"action_log_index": 1,
"log": [
"The game has started",
"Age 1 has started",
"Round 1/3",
"Player1 increased happiness in the city at C2 by 1 steps, making it Neutral and the city at B3 by 2 steps, making it Happy using Voting"
"Player1 paid 5 mood tokens to increase happiness in the city at C2 by 1 steps, making it Neutral and the city at B3 by 2 steps, making it Happy using Voting"
],
"undo_limit": 0,
"actions_left": 3,
Expand Down Expand Up @@ -446,4 +446,4 @@
}
}
]
}
}
Loading
Loading