fix negotiations (#324)

This commit is contained in:
Gregor Zeitlinger 2025-08-15 18:31:21 +02:00 • committed by GitHub
commit 08cd71c4ea
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
7 changed files with 51 additions and 30 deletions

View file

@ -13,7 +13,7 @@ use crate::content::persistent_events::{
use crate::content::tactics_cards::TacticsCardFactory;
use crate::events::{EventOrigin, EventPlayer};
use crate::game::Game;
use crate::log::{current_player_turn_log, current_player_turn_log_mut};
use crate::log::{current_player_turn_log_mut, current_player_turn_log_without_redo};
use crate::player::Player;
use crate::position::Position;
use crate::tactics_card::TacticsCard;
@ -322,15 +322,18 @@ pub fn combat_requirement_met(
action_card_id + 1
};
current_player_turn_log(game).actions.iter().position(|a| {
if let Some(stats) = &a.combat_stats
&& requirement(stats, game.player(player))
&& !stats.claimed_action_cards.contains(&sister_card)
{
return true;
}
false
})
current_player_turn_log_without_redo(game)
.actions
.iter()
.position(|a| {
if let Some(stats) = &a.combat_stats
&& requirement(stats, game.player(player))
&& !stats.claimed_action_cards.contains(&sister_card)
{
return true;
}
false
})
}
pub(crate) fn can_play_civil_card(game: &Game, p: &Player, id: u8) -> Result<(), String> {

View file

@ -10,7 +10,7 @@ use crate::content::tactics_cards::{
TacticsCardFactory, archers, defensive_formation, encircled, high_ground, martyr, scout,
};
use crate::game::Game;
use crate::log::current_player_turn_log;
use crate::log::current_player_turn_log_without_redo;
use crate::playing_actions::PlayingAction;
use crate::utils::remove_element_by;
@ -31,11 +31,11 @@ fn negotiations(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
ActionCard::builder(
id,
"Negotiations",
"Select another player. This turn, you may not attack that player. \
In their next turn, they may not attack you.",
"At the start of your turn: Select another player. \
This turn, you may not attack that player. In their next turn, they may not attack you.",
|c| c.free_action().culture_tokens(1),
move |game, _player, _| {
!current_player_turn_log(game)
!current_player_turn_log_without_redo(game)
.actions
.iter()
.any(|i| match &i.action {

View file

@ -8,7 +8,7 @@ use crate::content::custom_actions::CustomActionType::{
};
use crate::content::persistent_events::PositionRequest;
use crate::game::GameOptions;
use crate::log::current_player_turn_log;
use crate::log::current_player_turn_log_without_redo;
use crate::playing_actions::{PlayingAction, PlayingActionType};
use crate::resource_pile::ResourcePile;
@ -115,10 +115,13 @@ fn free_economy() -> AdvanceBuilder {
}
PlayingActionType::Custom(i)
if *i == FreeEconomyCollect
&& current_player_turn_log(game).actions.iter().any(|item| {
matches!(&item.action, Action::Playing(PlayingAction::Collect(c)) if
&& current_player_turn_log_without_redo(game)
.actions
.iter()
.any(|item| {
matches!(&item.action, Action::Playing(PlayingAction::Collect(c)) if
c.action_type == PlayingActionType::Collect)
}) =>
}) =>
{
*available =
Err("Cannot use Free Economy Collect when Collect was used".to_string());

View file

@ -3,7 +3,7 @@ use crate::combat_stats::Battleground;
use crate::content::advances::AdvanceGroup;
use crate::content::advances::trade_routes::find_trade_route_for_unit;
use crate::game::Game;
use crate::log::current_player_turn_log;
use crate::log::current_player_turn_log_without_redo;
use crate::objective_card::{Objective, objective_is_ready};
use crate::player::Player;
use crate::unit::{Unit, UnitType};
@ -41,7 +41,8 @@ pub(crate) fn warmonger() -> Objective {
|event| &mut event.combat_end,
2,
|game, player, _e| {
let stat = current_player_turn_log(game)
let log = current_player_turn_log_without_redo(game);
let stat = log
.actions
.iter()
.filter_map(|i| i.combat_stats.as_ref().filter(|s| s.battleground.is_land()))
@ -411,7 +412,7 @@ pub(crate) fn sea_cleansing() -> Objective {
16,
|game, p, _e| {
let player = p.index;
let battles = current_player_turn_log(game)
let battles = current_player_turn_log_without_redo(game)
.actions
.iter()
.filter_map(|i| {

View file

@ -8,7 +8,7 @@ use crate::content::custom_actions::custom_action_modifier_event_origin;
use crate::content::persistent_events::{PaymentRequest, PersistentEventType, SelectedStructure};
use crate::events::{EventOrigin, EventPlayer};
use crate::game::Game;
use crate::log::current_player_turn_log;
use crate::log::current_player_turn_log_without_redo;
use crate::payment::PaymentOptions;
use crate::player::Player;
use crate::player_events::ActionInfo;
@ -205,7 +205,7 @@ fn roll_boost_paid(
payment: &ResourcePile,
info: &mut InfluenceCultureInfo,
) {
let a = current_player_turn_log(game)
let a = current_player_turn_log_without_redo(game)
.actions
.iter()
.rev()

View file

@ -234,14 +234,18 @@ pub(crate) fn linear_action_log(game: &Game) -> Vec<Action> {
pub(crate) fn add_log_action(game: &mut Game, item: Action) {
let i = game.action_log_index;
let l = &mut current_player_turn_log_mut(game).actions;
if i < l.len() {
// remove items from undo
l.drain(i..);
}
remove_redo_actions(l, i);
l.push(ActionLogAction::new(item));
game.action_log_index += 1;
}
fn remove_redo_actions(l: &mut Vec<ActionLogAction>, action_log_index: usize) {
if action_log_index < l.len() {
// remove items from undo
l.drain(action_log_index..);
}
}
pub(crate) fn add_action_log_item(
game: &mut Game,
player: usize,
@ -262,7 +266,17 @@ pub(crate) fn add_action_log_item(
/// # Panics
/// Panics if the log entry does not exist
#[must_use]
pub fn current_player_turn_log(game: &Game) -> &ActionLogPlayer {
pub(crate) fn current_player_turn_log_without_redo(game: &Game) -> ActionLogPlayer {
let mut log = current_player_turn_log(game).clone();
remove_redo_actions(&mut log.actions, game.action_log_index);
log
}
///
/// # Panics
/// Panics if the log entry does not exist
#[must_use]
pub(crate) fn current_player_turn_log(game: &Game) -> &ActionLogPlayer {
game.action_log
.last()
.expect("state should exist")

View file

@ -89,8 +89,8 @@
"incident_tokens": 2,
"next_unit_id": 2,
"event_info": {
"Cartography-navigation": "0",
"Cartography": "0"
"Cartography": "0",
"Cartography-navigation": "0"
}
},
{