Rome (#255)
This commit is contained in:
parent
a576e9d3ec
commit
bb444118ea
140 changed files with 12441 additions and 2658 deletions
BIN
client/assets/aqueduct-svgrepo-com.png
Normal file
BIN
client/assets/aqueduct-svgrepo-com.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 4.6 KiB |
BIN
client/assets/augustus-of-prima-porta-svgrepo-com.png
Normal file
BIN
client/assets/augustus-of-prima-porta-svgrepo-com.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 13 KiB |
|
|
@ -7,12 +7,13 @@ use crate::influence_ui::new_cultural_influence_dialog;
|
|||
use crate::layout_ui::{bottom_left_texture, icon_pos};
|
||||
use crate::move_ui::MoveIntent;
|
||||
use crate::render_context::RenderContext;
|
||||
use itertools::Itertools;
|
||||
use server::action::Action;
|
||||
use server::city::City;
|
||||
use server::content::custom_actions::{CustomActionType, CustomEventAction};
|
||||
use server::content::custom_actions::{CustomAction, CustomActionType};
|
||||
use server::cultural_influence::available_influence_actions;
|
||||
use server::happiness::available_happiness_actions;
|
||||
use server::playing_actions::{PlayingAction, PlayingActionType, base_and_custom_action};
|
||||
use server::playing_actions::{PlayingAction, PlayingActionType};
|
||||
use server::resource::ResourceType;
|
||||
|
||||
pub fn action_buttons(rc: &RenderContext) -> StateUpdate {
|
||||
|
|
@ -28,7 +29,7 @@ pub fn action_buttons(rc: &RenderContext) -> StateUpdate {
|
|||
&["Increase happiness".to_string()],
|
||||
)
|
||||
{
|
||||
return open_increase_happiness_dialog(rc, happiness, |h| h);
|
||||
return open_increase_happiness_dialog(rc, &happiness, |h| h);
|
||||
}
|
||||
|
||||
if rc.can_play_action(&PlayingActionType::MoveUnits)
|
||||
|
|
@ -63,13 +64,13 @@ pub fn action_buttons(rc: &RenderContext) -> StateUpdate {
|
|||
&["Cultural Influence".to_string()],
|
||||
)
|
||||
{
|
||||
return base_or_custom_action(rc, influence, "Influence culture", |d| {
|
||||
return base_or_custom_action(rc, &influence, "Influence culture", |d| {
|
||||
new_cultural_influence_dialog(rc.game, rc.shown_player.index, d)
|
||||
});
|
||||
}
|
||||
let mut i = 0;
|
||||
for (a, origin) in game.available_custom_actions(rc.shown_player.index) {
|
||||
if let Some(action) = generic_custom_action(rc, a.clone(), None) {
|
||||
if let Some(action) = generic_custom_action(rc, a, None) {
|
||||
if bottom_left_texture(
|
||||
rc,
|
||||
&assets.custom_actions[&a],
|
||||
|
|
@ -97,7 +98,7 @@ pub fn custom_action_buttons<'a>(
|
|||
.available_custom_actions(rc.shown_player.index)
|
||||
.into_iter()
|
||||
.filter_map(|(a, origin)| {
|
||||
generic_custom_action(rc, a.clone(), city).map(|action| {
|
||||
generic_custom_action(rc, a, city).map(|action| {
|
||||
IconAction::new(
|
||||
&rc.assets().custom_actions[&a],
|
||||
event_help(rc, &origin),
|
||||
|
|
@ -130,47 +131,44 @@ fn generic_custom_action(
|
|||
return custom_action_type
|
||||
.is_available_city(rc.shown_player, city)
|
||||
.then_some(StateUpdate::execute(Action::Playing(
|
||||
PlayingAction::Custom(CustomEventAction::new(
|
||||
custom_action_type,
|
||||
Some(city.position),
|
||||
)),
|
||||
PlayingAction::Custom(CustomAction::new(custom_action_type, Some(city.position))),
|
||||
)));
|
||||
}
|
||||
|
||||
(!custom_action_type.is_city_bound()).then_some(StateUpdate::execute(Action::Playing(
|
||||
PlayingAction::Custom(CustomEventAction::new(custom_action_type, None)),
|
||||
PlayingAction::Custom(CustomAction::new(custom_action_type, None)),
|
||||
)))
|
||||
}
|
||||
|
||||
pub fn base_or_custom_action(
|
||||
rc: &RenderContext,
|
||||
actions: Vec<PlayingActionType>,
|
||||
action_types: &[PlayingActionType],
|
||||
title: &str,
|
||||
execute: impl Fn(BaseOrCustomDialog) -> ActiveDialog,
|
||||
) -> StateUpdate {
|
||||
let (action, custom) = base_and_custom_action(actions);
|
||||
|
||||
let base = action.map(|action_type| {
|
||||
execute(BaseOrCustomDialog {
|
||||
action_type,
|
||||
title: title.to_string(),
|
||||
})
|
||||
});
|
||||
|
||||
let special = custom.map(|a| {
|
||||
let origin = &rc.shown_player.custom_actions[&a];
|
||||
let dialog = execute(BaseOrCustomDialog {
|
||||
action_type: PlayingActionType::Custom(a),
|
||||
title: format!("{title} with {}", origin.name(rc.game)),
|
||||
});
|
||||
|
||||
StateUpdate::dialog_chooser(
|
||||
&format!("Use special action from {}?", origin.name(rc.game)),
|
||||
Some(dialog),
|
||||
base.clone(),
|
||||
)
|
||||
});
|
||||
special
|
||||
.or_else(|| base.map(StateUpdate::OpenDialog))
|
||||
.unwrap_or(StateUpdate::None)
|
||||
StateUpdate::dialog_chooser(
|
||||
&format!("Choose action: {title}"),
|
||||
action_types
|
||||
.iter()
|
||||
.map(|action_type| match action_type {
|
||||
PlayingActionType::Custom(c) => {
|
||||
let origin = rc.shown_player.custom_action_origin(c);
|
||||
(
|
||||
Some(origin.clone()),
|
||||
execute(BaseOrCustomDialog {
|
||||
action_type: action_type.clone(),
|
||||
title: format!("{title} with {}", origin.name(rc.game)),
|
||||
}),
|
||||
)
|
||||
}
|
||||
_ => (
|
||||
None,
|
||||
execute(BaseOrCustomDialog {
|
||||
action_type: action_type.clone(),
|
||||
title: title.to_string(),
|
||||
}),
|
||||
),
|
||||
})
|
||||
.collect_vec(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,10 +9,10 @@ use itertools::Itertools;
|
|||
use macroquad::color::Color;
|
||||
use macroquad::math::vec2;
|
||||
use macroquad::prelude::{
|
||||
BLACK, BLUE, GRAY, Rect, WHITE, YELLOW, draw_rectangle, draw_rectangle_lines,
|
||||
BLACK, BLUE, GRAY, GREEN, Rect, WHITE, YELLOW, draw_rectangle, draw_rectangle_lines,
|
||||
};
|
||||
use server::action::Action;
|
||||
use server::advance::{Advance, AdvanceInfo, Bonus};
|
||||
use server::advance::{Advance, AdvanceAction, AdvanceInfo, Bonus, find_special_advance};
|
||||
use server::game::GameState;
|
||||
use server::player::{CostTrigger, Player};
|
||||
use server::playing_actions::PlayingAction;
|
||||
|
|
@ -98,22 +98,25 @@ pub fn show_advance_menu(
|
|||
);
|
||||
state.draw_text(name, pos.x + 10., pos.y + 22.);
|
||||
|
||||
let thickness = match &state.active_dialog {
|
||||
ActiveDialog::AdvancePayment(p) => {
|
||||
if p.name == *name {
|
||||
8.
|
||||
} else {
|
||||
4.
|
||||
}
|
||||
}
|
||||
_ => 4.,
|
||||
};
|
||||
if find_special_advance(a.advance, rc.game, rc.shown_player.index).is_some() {
|
||||
draw_rectangle_lines(rect.x, rect.y, rect.w, rect.h, 12., GREEN);
|
||||
}
|
||||
|
||||
draw_rectangle_lines(
|
||||
rect.x,
|
||||
rect.y,
|
||||
rect.w,
|
||||
rect.h,
|
||||
thickness,
|
||||
match &state.active_dialog {
|
||||
ActiveDialog::AdvancePayment(p) => {
|
||||
if p.name == *name {
|
||||
8.
|
||||
} else {
|
||||
4.
|
||||
}
|
||||
}
|
||||
_ => 4.,
|
||||
},
|
||||
border_color(a),
|
||||
);
|
||||
} else {
|
||||
|
|
@ -197,6 +200,12 @@ fn description(rc: &RenderContext, a: &AdvanceInfo) -> Vec<String> {
|
|||
add_unit_description(&mut parts, UnitType::Elephant);
|
||||
}
|
||||
|
||||
if let Some(a) = find_special_advance(a.advance, rc.game, rc.shown_player.index) {
|
||||
let s = a.info(rc.game);
|
||||
parts.push(format!("Special advance: {}", s.name));
|
||||
add_tooltip_description(&mut parts, &s.description);
|
||||
}
|
||||
|
||||
parts
|
||||
}
|
||||
|
||||
|
|
@ -208,10 +217,9 @@ pub fn pay_advance_dialog(ap: &Payment<Advance>, rc: &RenderContext) -> StateUpd
|
|||
}
|
||||
payment_dialog(rc, ap, true, ActiveDialog::AdvancePayment, |payment| {
|
||||
StateUpdate::execute_with_warning(
|
||||
Action::Playing(PlayingAction::Advance {
|
||||
advance: ap.value,
|
||||
payment,
|
||||
}),
|
||||
Action::Playing(PlayingAction::Advance(AdvanceAction::new(
|
||||
ap.value, payment,
|
||||
))),
|
||||
if rc.shown_player.incident_tokens == 1 {
|
||||
vec!["A game event will be triggered".to_string()]
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -321,6 +321,17 @@ impl Assets {
|
|||
"../assets/statue-of-david-1-svgrepo-com.png"
|
||||
)),
|
||||
),
|
||||
//Rome
|
||||
(
|
||||
CustomActionType::Aqueduct,
|
||||
load_png(include_bytes!("../assets/aqueduct-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
CustomActionType::Princeps,
|
||||
load_png(include_bytes!(
|
||||
"../assets/augustus-of-prima-porta-svgrepo-com.png"
|
||||
)),
|
||||
),
|
||||
]
|
||||
.iter()
|
||||
.cloned()
|
||||
|
|
|
|||
|
|
@ -262,8 +262,8 @@ fn action_card_object(rc: &RenderContext, id: u8) -> HandCardObject {
|
|||
}
|
||||
.to_string(),
|
||||
);
|
||||
let cost = &action_type.cost;
|
||||
if !cost.is_empty() {
|
||||
let cost = &action_type.payment_options(rc.shown_player);
|
||||
if !cost.is_free() {
|
||||
description.push(format!("Cost: {cost}"));
|
||||
}
|
||||
break_text(a.civil_card.description.as_str(), 30, &mut description);
|
||||
|
|
|
|||
|
|
@ -97,7 +97,7 @@ fn increase_happiness_button<'a>(rc: &'a RenderContext, city: &'a City) -> Optio
|
|||
&rc.assets().resources[&ResourceType::MoodTokens],
|
||||
vec!["Increase happiness".to_string()],
|
||||
Box::new(move || {
|
||||
open_increase_happiness_dialog(rc, actions.clone(), |mut happiness| {
|
||||
open_increase_happiness_dialog(rc, &actions, |mut happiness| {
|
||||
let mut target = city.mood_state.clone();
|
||||
while target != MoodState::Happy {
|
||||
happiness = add_increase_happiness(rc, city, happiness)
|
||||
|
|
@ -200,7 +200,7 @@ fn collect_resources_button<'a>(rc: &'a RenderContext, city: &'a City) -> Option
|
|||
&rc.assets().resources[&ResourceType::Food],
|
||||
vec!["Collect Resources".to_string()],
|
||||
Box::new(move || {
|
||||
base_or_custom_action(rc, actions.clone(), "Collect resources", |custom| {
|
||||
base_or_custom_action(rc, &actions, "Collect resources", |custom| {
|
||||
let i = possible_resource_collections(
|
||||
rc.game,
|
||||
city.position,
|
||||
|
|
|
|||
|
|
@ -13,11 +13,13 @@ use crate::client_state::{
|
|||
};
|
||||
use crate::collect_ui::collect_dialog;
|
||||
use crate::construct_ui::pay_construction_dialog;
|
||||
use crate::dialog_ui::{OkTooltip, cancel_button, ok_button};
|
||||
use crate::event_ui::custom_phase_event_origin;
|
||||
use crate::event_ui::{custom_phase_event_origin, event_help};
|
||||
use crate::happiness_ui::{increase_happiness_click, increase_happiness_menu};
|
||||
use crate::hex_ui::pixel_to_coordinate;
|
||||
use crate::layout_ui::{bottom_centered_text, icon_pos, top_right_texture};
|
||||
use crate::layout_ui::{
|
||||
ICON_SIZE, bottom_center_anchor, bottom_centered_text_with_offset,
|
||||
draw_scaled_icon_with_tooltip, icon_pos, top_right_texture,
|
||||
};
|
||||
use crate::log_ui::show_log;
|
||||
use crate::map_ui::{draw_map, explore_dialog, show_tile_menu};
|
||||
use crate::player_ui::{player_select, show_global_controls, show_top_center, show_top_left};
|
||||
|
|
@ -184,14 +186,33 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
|
|||
}
|
||||
|
||||
fn dialog_chooser(rc: &RenderContext, c: &DialogChooser) -> StateUpdate {
|
||||
bottom_centered_text(rc, &c.title);
|
||||
if ok_button(rc, OkTooltip::Valid("OK".to_string())) {
|
||||
StateUpdate::OpenDialog(c.yes.clone())
|
||||
} else if cancel_button(rc) {
|
||||
StateUpdate::OpenDialog(c.no.clone())
|
||||
} else {
|
||||
StateUpdate::None
|
||||
let h = -50.;
|
||||
bottom_centered_text_with_offset(
|
||||
rc,
|
||||
&c.title,
|
||||
vec2(0., c.options.len() as f32 * h + 50.),
|
||||
&[],
|
||||
);
|
||||
|
||||
for (i, (origin, d)) in c.options.iter().enumerate() {
|
||||
let offset = vec2(0., i as f32 * h + 35.);
|
||||
let (name, tooltip) = origin.as_ref().map_or_else(
|
||||
|| ("standard action".to_string(), vec![]),
|
||||
|o| (o.name(rc.game), event_help(rc, o)),
|
||||
);
|
||||
|
||||
bottom_centered_text_with_offset(rc, &name, offset, &tooltip);
|
||||
if draw_scaled_icon_with_tooltip(
|
||||
rc,
|
||||
&rc.assets().ok,
|
||||
&tooltip,
|
||||
bottom_center_anchor(rc) + offset + vec2(100., -70.),
|
||||
ICON_SIZE,
|
||||
) {
|
||||
return StateUpdate::OpenDialog(d.clone());
|
||||
}
|
||||
}
|
||||
StateUpdate::None
|
||||
}
|
||||
|
||||
pub fn try_click(rc: &RenderContext) -> StateUpdate {
|
||||
|
|
@ -229,7 +250,9 @@ fn controlling_player_click(rc: &RenderContext, mouse_pos: Vec2, pos: Position)
|
|||
ActiveDialog::UnitsRequest(s) => unit_selection_click(rc, pos, mouse_pos, s, |new| {
|
||||
StateUpdate::OpenDialog(ActiveDialog::UnitsRequest(new.clone()))
|
||||
}),
|
||||
ActiveDialog::IncreaseHappiness(h) => increase_happiness_click(rc, pos, h),
|
||||
ActiveDialog::IncreaseHappiness(h) if h.city_restriction.is_none_or(|r| r == pos) => {
|
||||
increase_happiness_click(rc, pos, h)
|
||||
}
|
||||
_ => StateUpdate::SetFocusedTile(pos),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -143,7 +143,7 @@ impl ActiveDialog {
|
|||
let v = vec!["Click on a building to influence its culture".to_string()];
|
||||
if let PlayingActionType::Custom(c) = &b.action_type {
|
||||
let mut r = v.clone();
|
||||
r.extend(event_help(rc, &rc.shown_player.custom_actions[c]));
|
||||
r.extend(event_help(rc, &rc.shown_player.custom_action_origin(c)));
|
||||
}
|
||||
v
|
||||
} else {
|
||||
|
|
@ -219,8 +219,7 @@ pub struct PendingUpdate {
|
|||
#[derive(Clone)]
|
||||
pub struct DialogChooser {
|
||||
pub title: String,
|
||||
pub yes: ActiveDialog,
|
||||
pub no: ActiveDialog,
|
||||
pub options: Vec<(Option<EventOrigin>, ActiveDialog)>,
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
@ -288,26 +287,17 @@ impl StateUpdate {
|
|||
|
||||
pub fn dialog_chooser(
|
||||
title: &str,
|
||||
yes: Option<ActiveDialog>,
|
||||
no: Option<ActiveDialog>,
|
||||
options: Vec<(Option<EventOrigin>, ActiveDialog)>,
|
||||
) -> StateUpdate {
|
||||
match yes {
|
||||
Some(yes) => match no {
|
||||
Some(no) => {
|
||||
StateUpdate::OpenDialog(ActiveDialog::DialogChooser(Box::new(DialogChooser {
|
||||
title: title.to_string(),
|
||||
yes,
|
||||
no,
|
||||
})))
|
||||
}
|
||||
_ => StateUpdate::OpenDialog(yes),
|
||||
},
|
||||
_ => match no {
|
||||
Some(no) => StateUpdate::OpenDialog(no),
|
||||
_ => {
|
||||
panic!("no dialog to open")
|
||||
}
|
||||
},
|
||||
match options.len() {
|
||||
0 => {
|
||||
panic!("no dialog options provided");
|
||||
}
|
||||
1 => StateUpdate::OpenDialog(options[0].1.clone()),
|
||||
_ => StateUpdate::OpenDialog(ActiveDialog::DialogChooser(Box::new(DialogChooser {
|
||||
title: title.to_string(),
|
||||
options,
|
||||
}))),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -379,6 +369,7 @@ pub enum CameraMode {
|
|||
|
||||
#[cfg(not(target_arch = "wasm32"))]
|
||||
use server::ai::AI;
|
||||
use server::events::EventOrigin;
|
||||
|
||||
pub struct State {
|
||||
pub assets: Assets,
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ pub fn show_pending_update(update: &PendingUpdate, rc: &RenderContext) -> StateU
|
|||
} else {
|
||||
&format!("Warning: {}", update.warning.join(", "))
|
||||
};
|
||||
bottom_centered_text_with_offset(rc, t, vec2(0., 30.));
|
||||
bottom_centered_text_with_offset(rc, t, vec2(0., 30.), &[]);
|
||||
|
||||
if ok_button(rc, OkTooltip::Valid("OK".to_string())) {
|
||||
return StateUpdate::ResolvePendingUpdate(true);
|
||||
|
|
|
|||
|
|
@ -15,24 +15,10 @@ pub fn event_help(rc: &RenderContext, origin: &EventOrigin) -> Vec<String> {
|
|||
EventOrigin::TacticsCard(id) => vec![cache.get_tactics_card(*id).description.clone()],
|
||||
EventOrigin::Incident(id) => cache.get_incident(*id).description(rc.game),
|
||||
EventOrigin::Objective(name) => vec![cache.get_objective(name).description.clone()],
|
||||
EventOrigin::Leader(l) => vec![{
|
||||
let l = rc.shown_player.get_leader(l).unwrap();
|
||||
// todo: leader should have a 2 event sources - no each event source should have a description
|
||||
format!(
|
||||
"{}, {}",
|
||||
l.first_ability_description, l.second_ability_description
|
||||
)
|
||||
}],
|
||||
EventOrigin::SpecialAdvance(s) => vec![{
|
||||
let s = rc
|
||||
.shown_player
|
||||
.civilization
|
||||
.special_advances
|
||||
.iter()
|
||||
.find(|sa| &sa.advance == s)
|
||||
.unwrap();
|
||||
s.description.clone()
|
||||
}],
|
||||
EventOrigin::LeaderAbility(l) => {
|
||||
vec![rc.shown_player.get_leader_ability(l).description.clone()]
|
||||
}
|
||||
EventOrigin::SpecialAdvance(s) => vec![s.info(rc.game).description.clone()],
|
||||
};
|
||||
h.extend(d);
|
||||
h
|
||||
|
|
@ -48,11 +34,17 @@ pub fn custom_phase_event_help(rc: &RenderContext, description: &str) -> Vec<Str
|
|||
#[must_use]
|
||||
pub fn custom_phase_event_origin(rc: &RenderContext) -> EventOrigin {
|
||||
rc.game
|
||||
.current_event_handler()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.origin
|
||||
.current_event()
|
||||
.origin_override
|
||||
.clone()
|
||||
.unwrap_or_else(|| {
|
||||
rc.game
|
||||
.current_event_handler()
|
||||
.as_ref()
|
||||
.unwrap()
|
||||
.origin
|
||||
.clone()
|
||||
})
|
||||
}
|
||||
|
||||
pub fn pay_help<T: Clone>(rc: &RenderContext, p: &Payment<T>) -> Vec<String> {
|
||||
|
|
|
|||
|
|
@ -3,10 +3,11 @@ use crate::client_state::{ActiveDialog, StateUpdate};
|
|||
use crate::dialog_ui::BaseOrCustomDialog;
|
||||
use crate::payment_ui::{Payment, payment_dialog};
|
||||
use crate::render_context::RenderContext;
|
||||
use itertools::Itertools;
|
||||
use server::action::Action;
|
||||
use server::city::{City, MoodState};
|
||||
use server::game::Game;
|
||||
use server::happiness::{available_happiness_actions, happiness_cost};
|
||||
use server::happiness::{available_happiness_actions, happiness_city_restriction, happiness_cost};
|
||||
use server::player::CostTrigger;
|
||||
use server::playing_actions::{IncreaseHappiness, PlayingAction, PlayingActionType};
|
||||
use server::position::Position;
|
||||
|
|
@ -16,17 +17,20 @@ pub struct IncreaseHappinessConfig {
|
|||
pub steps: Vec<(Position, u8)>,
|
||||
pub payment: Payment<String>,
|
||||
pub custom: BaseOrCustomDialog,
|
||||
pub city_restriction: Option<Position>,
|
||||
}
|
||||
|
||||
impl IncreaseHappinessConfig {
|
||||
pub fn new(rc: &RenderContext, custom: BaseOrCustomDialog) -> IncreaseHappinessConfig {
|
||||
let p = rc.shown_player;
|
||||
let steps = p.cities.iter().map(|c| (c.position, 0)).collect();
|
||||
let city_restriction = happiness_city_restriction(rc.shown_player, &custom.action_type);
|
||||
IncreaseHappinessConfig {
|
||||
steps,
|
||||
payment: Self::happiness_payment(rc, 0, &custom)
|
||||
.expect("Happiness payment should be available"),
|
||||
custom,
|
||||
city_restriction,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -55,7 +59,7 @@ impl IncreaseHappinessConfig {
|
|||
|
||||
pub fn open_increase_happiness_dialog(
|
||||
rc: &RenderContext,
|
||||
actions: Vec<PlayingActionType>,
|
||||
actions: &[PlayingActionType],
|
||||
init: impl Fn(IncreaseHappinessConfig) -> IncreaseHappinessConfig,
|
||||
) -> StateUpdate {
|
||||
base_or_custom_action(rc, actions, "Increase happiness", |custom| {
|
||||
|
|
@ -172,9 +176,15 @@ pub fn available_happiness_actions_for_city(
|
|||
player: usize,
|
||||
position: Position,
|
||||
) -> Vec<PlayingActionType> {
|
||||
let city = game.player(player).get_city(position);
|
||||
let p = game.player(player);
|
||||
let city = p.get_city(position);
|
||||
if city.can_activate() && city.mood_state != MoodState::Happy {
|
||||
available_happiness_actions(game, player)
|
||||
.into_iter()
|
||||
.filter(|action_type| {
|
||||
happiness_city_restriction(p, action_type).is_none_or(|r| r == position)
|
||||
})
|
||||
.collect_vec()
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
|
|
@ -190,6 +200,7 @@ pub fn increase_happiness_menu(rc: &RenderContext, h: &IncreaseHappinessConfig)
|
|||
steps: h.steps.clone(),
|
||||
payment,
|
||||
custom: h.custom.clone(),
|
||||
city_restriction: h.city_restriction,
|
||||
})
|
||||
},
|
||||
|payment| {
|
||||
|
|
|
|||
|
|
@ -59,13 +59,29 @@ pub fn bottom_center_texture(
|
|||
draw_icon(rc, texture, tooltip, anchor + p)
|
||||
}
|
||||
|
||||
pub fn bottom_centered_text_with_offset(rc: &RenderContext, text: &str, offset: Vec2) {
|
||||
pub fn bottom_centered_text_with_offset(
|
||||
rc: &RenderContext,
|
||||
text: &str,
|
||||
offset: Vec2,
|
||||
tooltip: &[String],
|
||||
) {
|
||||
let dimensions = rc.state.measure_text(text);
|
||||
bottom_center_text(rc, text, vec2(-dimensions.width / 2., -50.) + offset);
|
||||
let p = vec2(-dimensions.width / 2., -50.) + offset;
|
||||
bottom_center_text(rc, text, p);
|
||||
if !tooltip.is_empty() {
|
||||
let p = bottom_center_anchor(rc) + p;
|
||||
let rect = Rect::new(
|
||||
p.x,
|
||||
p.y - dimensions.offset_y,
|
||||
dimensions.width,
|
||||
dimensions.height,
|
||||
);
|
||||
tooltip::show_tooltip_for_rect(rc, tooltip, rect, 50.);
|
||||
}
|
||||
}
|
||||
|
||||
pub fn bottom_centered_text(rc: &RenderContext, text: &str) {
|
||||
bottom_centered_text_with_offset(rc, text, vec2(0., 0.));
|
||||
bottom_centered_text_with_offset(rc, text, vec2(0., 0.), &[]);
|
||||
}
|
||||
|
||||
pub fn bottom_center_text(rc: &RenderContext, text: &str, p: Vec2) {
|
||||
|
|
|
|||
|
|
@ -65,7 +65,7 @@ async fn main() {
|
|||
undo: UndoOption::SamePlayer,
|
||||
})
|
||||
.build(),
|
||||
) // todo make configurable
|
||||
)
|
||||
};
|
||||
|
||||
run(game, &mut features).await;
|
||||
|
|
@ -149,8 +149,6 @@ fn ai_autoplay(game: Game, _: &mut Features, _: &mut State) -> Game {
|
|||
fn ai_autoplay(mut game: Game, f: &mut Features, state: &mut State) -> Game {
|
||||
if f.ai {
|
||||
while state.ai_autoplay && game.state != server::game::GameState::Finished {
|
||||
// todo does this block the ui?
|
||||
// state.ai_autoplay = false;
|
||||
let active_player = game.active_player();
|
||||
let ai = &mut state.ai_players[active_player];
|
||||
let action = ai.next_action(&game);
|
||||
|
|
|
|||
|
|
@ -163,6 +163,7 @@ pub fn multi_payment_dialog<T: Clone>(
|
|||
rc,
|
||||
&format!("{name} for {cost}{suffix}"),
|
||||
offset + vec2(0., -30.),
|
||||
&[],
|
||||
);
|
||||
let result = select_ui::count_dialog(
|
||||
rc,
|
||||
|
|
|
|||
|
|
@ -202,8 +202,8 @@ pub fn show_top_left(rc: &RenderContext) {
|
|||
|
||||
label(&format!(
|
||||
"Leader {}",
|
||||
if let Some(l) = &player.active_leader() {
|
||||
&l.name
|
||||
if let Some(l) = &player.active_leader {
|
||||
l
|
||||
} else {
|
||||
"-"
|
||||
}
|
||||
|
|
|
|||
|
|
@ -51,7 +51,7 @@ impl RecruitAmount {
|
|||
let player = game.player(player_index);
|
||||
let selectable: Vec<SelectableUnit> = new_units(player)
|
||||
.into_iter()
|
||||
.map(|u| selectable_unit(city_position, &units, leader_name, player, &u))
|
||||
.map(|u| selectable_unit(city_position, &units, leader_name, player, &u, game))
|
||||
.collect();
|
||||
|
||||
StateUpdate::OpenDialog(ActiveDialog::RecruitUnitSelection(RecruitAmount {
|
||||
|
|
@ -70,6 +70,7 @@ fn selectable_unit(
|
|||
leader_name: Option<&String>,
|
||||
player: &Player,
|
||||
unit: &NewUnit,
|
||||
game: &Game,
|
||||
) -> SelectableUnit {
|
||||
let mut all = units.clone();
|
||||
all += &unit.unit_type;
|
||||
|
|
@ -81,6 +82,7 @@ fn selectable_unit(
|
|||
};
|
||||
|
||||
let cost = recruit_cost_without_replaced(
|
||||
game,
|
||||
player,
|
||||
&all,
|
||||
city_position,
|
||||
|
|
@ -165,6 +167,7 @@ impl RecruitSelection {
|
|||
|
||||
pub fn confirm(&self, game: &Game) -> OkTooltip {
|
||||
recruit_cost(
|
||||
game,
|
||||
game.player(self.amount.player_index),
|
||||
&self.amount.units,
|
||||
self.amount.city_position,
|
||||
|
|
@ -270,6 +273,7 @@ pub fn select_dialog(rc: &RenderContext, a: &RecruitAmount) -> StateUpdate {
|
|||
fn open_dialog(rc: &RenderContext, city: Position, sel: RecruitSelection) -> StateUpdate {
|
||||
let p = rc.shown_player.index;
|
||||
let cost = recruit_cost(
|
||||
rc.game,
|
||||
rc.shown_player,
|
||||
&sel.amount.units,
|
||||
city,
|
||||
|
|
@ -282,13 +286,8 @@ fn open_dialog(rc: &RenderContext, city: Position, sel: RecruitSelection) -> Sta
|
|||
rc,
|
||||
rc.game.city(p, city),
|
||||
&format!(
|
||||
"Recruit {}{} in {}",
|
||||
sel.amount.units,
|
||||
sel.amount
|
||||
.leader_name
|
||||
.clone()
|
||||
.map_or(String::new(), |name| format!(" ({name})")),
|
||||
city
|
||||
"Recruit {} in {city}",
|
||||
sel.amount.units.to_string(sel.amount.leader_name.as_ref()),
|
||||
),
|
||||
ConstructionProject::Units(sel),
|
||||
&cost,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
[tools."cargo:cargo-nextest"]
|
||||
version = "0.9.94"
|
||||
version = "0.9.97-b.2"
|
||||
backend = "cargo:cargo-nextest"
|
||||
|
||||
[tools."cargo:wasm-bindgen-cli"]
|
||||
|
|
@ -15,5 +15,5 @@ version = "14.21.3"
|
|||
backend = "core:node"
|
||||
|
||||
[tools.rust]
|
||||
version = "1.86.0"
|
||||
version = "1.87.0"
|
||||
backend = "core:rust"
|
||||
|
|
|
|||
|
|
@ -35,6 +35,7 @@ run = [
|
|||
[tasks.ci]
|
||||
description = "Run CI tasks server"
|
||||
run = [
|
||||
"rustup component add rustfmt", # should be dony by `tools` section, but doesn't work in CI
|
||||
"cargo build",
|
||||
"cargo fmt --check",
|
||||
"cargo clippy",
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::advance::Advance;
|
||||
use crate::card::HandCard;
|
||||
use crate::card::{HandCard, validate_card_selection_for_origin};
|
||||
use crate::combat::{Combat, update_combat_strength};
|
||||
use crate::combat_listeners::CombatStrength;
|
||||
use crate::content::persistent_events::{
|
||||
|
|
@ -632,6 +632,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone + Sync + Send,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
let origin = self.get_key().clone();
|
||||
self.add_multi_choice_reward_request_listener::<E, HandCard, HandCardsRequest, V>(
|
||||
event,
|
||||
priority,
|
||||
|
|
@ -646,7 +647,11 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
panic!("Hand Cards request expected");
|
||||
},
|
||||
request,
|
||||
cards_selected,
|
||||
move |game, c, details| {
|
||||
validate_card_selection_for_origin(&c.choice, game, &origin)
|
||||
.expect("Invalid card selection - this should not happen");
|
||||
cards_selected(game, c, details);
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -865,11 +870,11 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
}
|
||||
|
||||
fn add_custom_action(self, action: CustomActionType) -> Self {
|
||||
let deinitializer_action = action.clone();
|
||||
let deinitializer_action = action;
|
||||
let key = self.get_key().clone();
|
||||
self.add_ability_initializer(move |game, player_index, _prio_delta| {
|
||||
let player = &mut game.players[player_index];
|
||||
player.custom_actions.insert(action.clone(), key.clone());
|
||||
player.custom_actions.insert(action, key.clone());
|
||||
})
|
||||
.add_ability_deinitializer(move |game, player_index| {
|
||||
let player = &mut game.players[player_index];
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use crate::action_card::on_play_action_card;
|
||||
use crate::advance::on_advance;
|
||||
use crate::barbarians::on_stop_barbarian_movement;
|
||||
use crate::city::{MoodState, on_found_city};
|
||||
use crate::collect::on_collect;
|
||||
use crate::combat::{combat_loop, move_with_possible_combat, start_combat};
|
||||
|
|
@ -244,7 +245,11 @@ pub(crate) fn execute_custom_phase_action(
|
|||
}
|
||||
StatusPhase(s) => play_status_phase(game, s),
|
||||
TurnStart => game.on_start_turn(),
|
||||
PayAction(a) => a.on_pay_action(game, player_index)?,
|
||||
PayAction(a) => a.on_pay_action(
|
||||
game,
|
||||
player_index,
|
||||
game.current_event().origin_override.clone(),
|
||||
)?,
|
||||
Advance(a) => {
|
||||
on_advance(game, player_index, a);
|
||||
}
|
||||
|
|
@ -256,6 +261,7 @@ pub(crate) fn execute_custom_phase_action(
|
|||
}
|
||||
FoundCity(p) => on_found_city(game, player_index, p),
|
||||
Incident(i) => on_trigger_incident(game, i),
|
||||
StopBarbarianMovement(movable) => on_stop_barbarian_movement(game, movable),
|
||||
ActionCard(a) => on_play_action_card(game, player_index, a),
|
||||
WonderCard(w) => on_play_wonder_card(game, player_index, w),
|
||||
SelectObjectives(c) => {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ use crate::ability_initializer::{
|
|||
use crate::advance::Advance;
|
||||
use crate::card::{discard_card, draw_card_from_pile};
|
||||
use crate::combat_stats::CombatStats;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::content::persistent_events::{
|
||||
PersistentEventType, TriggerPersistentEventParams, trigger_persistent_event_with_listener,
|
||||
};
|
||||
use crate::content::tactics_cards::TacticsCardFactory;
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
|
|
@ -183,14 +185,14 @@ pub(crate) fn on_play_action_card(game: &mut Game, player_index: usize, i: Actio
|
|||
CivilCardTarget::AllPlayers => game.human_players(player_index),
|
||||
};
|
||||
|
||||
let _ = game.trigger_persistent_event_with_listener(
|
||||
let _ = trigger_persistent_event_with_listener(
|
||||
game,
|
||||
&players,
|
||||
|e| &mut e.play_action_card,
|
||||
&game.cache.get_civil_card(i.id).listeners.clone(),
|
||||
i,
|
||||
PersistentEventType::ActionCard,
|
||||
None,
|
||||
|_| {},
|
||||
TriggerPersistentEventParams::default(),
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -302,3 +304,23 @@ pub fn combat_requirement_met(
|
|||
false
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn can_play_action_card(game: &Game, p: &Player, id: u8) -> Result<(), String> {
|
||||
if !p.action_cards.contains(&id) {
|
||||
return Err("Action card not available".to_string());
|
||||
}
|
||||
|
||||
let civil_card = game.cache.get_civil_card(id);
|
||||
let mut satisfying_action: Option<usize> = None;
|
||||
if let Some(r) = &civil_card.combat_requirement {
|
||||
if let Some(action_log_index) = combat_requirement_met(game, p.index, id, r) {
|
||||
satisfying_action = Some(action_log_index);
|
||||
} else {
|
||||
return Err("Requirement not met".to_string());
|
||||
}
|
||||
}
|
||||
if !(civil_card.can_play)(game, p, &ActionCardInfo::new(id, satisfying_action, None)) {
|
||||
return Err("Cannot play action card".to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,19 @@
|
|||
use crate::ability_initializer::{AbilityInitializerBuilder, AbilityListeners};
|
||||
use crate::city_pieces::Building;
|
||||
use crate::consts::ADVANCE_COST;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
use crate::incident::trigger_incident;
|
||||
use crate::player::gain_resources;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::{Player, gain_resources};
|
||||
use crate::player_events::OnAdvanceInfo;
|
||||
use crate::special_advance::SpecialAdvance;
|
||||
use crate::resource::ResourceType;
|
||||
use crate::special_advance::{SpecialAdvance, SpecialAdvanceRequirement};
|
||||
use crate::{ability_initializer::AbilityInitializerSetup, resource_pile::ResourcePile};
|
||||
use Bonus::*;
|
||||
use enumset::EnumSetType;
|
||||
use enumset::{EnumSet, EnumSetType};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::mem;
|
||||
|
||||
// id / 4 = advance group
|
||||
#[derive(EnumSetType, Serialize, Deserialize, Debug, Ord, PartialOrd, Hash)]
|
||||
|
|
@ -87,9 +89,6 @@ pub enum Advance {
|
|||
Devotion = 45,
|
||||
Conversion = 46,
|
||||
Fanaticism = 47,
|
||||
|
||||
// Civ specific
|
||||
Terrace = 48,
|
||||
}
|
||||
|
||||
impl Advance {
|
||||
|
|
@ -119,6 +118,7 @@ pub struct AdvanceInfo {
|
|||
pub contradicting: Vec<Advance>,
|
||||
pub unlocked_building: Option<Building>,
|
||||
pub government: Option<String>,
|
||||
pub leading_government: bool,
|
||||
pub listeners: AbilityListeners,
|
||||
}
|
||||
|
||||
|
|
@ -144,6 +144,7 @@ pub(crate) struct AdvanceBuilder {
|
|||
contradicting_advance: Vec<Advance>,
|
||||
unlocked_building: Option<Building>,
|
||||
government: Option<String>,
|
||||
leading_government: bool,
|
||||
builder: AbilityInitializerBuilder,
|
||||
}
|
||||
|
||||
|
|
@ -158,6 +159,7 @@ impl AdvanceBuilder {
|
|||
contradicting_advance: vec![],
|
||||
unlocked_building: None,
|
||||
government: None,
|
||||
leading_government: false,
|
||||
builder: AbilityInitializerBuilder::new(),
|
||||
}
|
||||
}
|
||||
|
|
@ -187,8 +189,9 @@ impl AdvanceBuilder {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_government(mut self, government: &str) -> Self {
|
||||
pub fn with_government(mut self, government: &str, leading: bool) -> Self {
|
||||
self.government = Some(government.to_string());
|
||||
self.leading_government = leading;
|
||||
self
|
||||
}
|
||||
|
||||
|
|
@ -203,6 +206,7 @@ impl AdvanceBuilder {
|
|||
contradicting: self.contradicting_advance,
|
||||
unlocked_building: self.unlocked_building,
|
||||
government: self.government,
|
||||
leading_government: self.leading_government,
|
||||
listeners: self.builder.build(),
|
||||
}
|
||||
}
|
||||
|
|
@ -243,24 +247,11 @@ pub fn do_advance(game: &mut Game, advance: Advance, player_index: usize) {
|
|||
let info = advance.info(game).clone();
|
||||
let bonus = info.bonus.clone();
|
||||
info.listeners.one_time_init(game, player_index);
|
||||
for i in 0..game.players[player_index]
|
||||
.civilization
|
||||
.special_advances
|
||||
.len()
|
||||
{
|
||||
if game.players[player_index].civilization.special_advances[i].required_advance == advance {
|
||||
let special_advance = game.players[player_index]
|
||||
.civilization
|
||||
.special_advances
|
||||
.remove(i);
|
||||
unlock_special_advance(game, &special_advance, player_index);
|
||||
game.players[player_index]
|
||||
.civilization
|
||||
.special_advances
|
||||
.insert(i, special_advance);
|
||||
break;
|
||||
}
|
||||
|
||||
if let Some(special_advance) = find_special_advance(advance, game, player_index) {
|
||||
unlock_special_advance(game, special_advance, player_index);
|
||||
}
|
||||
|
||||
if let Some(advance_bonus) = &bonus {
|
||||
gain_resources(
|
||||
game,
|
||||
|
|
@ -273,6 +264,60 @@ pub fn do_advance(game: &mut Game, advance: Advance, player_index: usize) {
|
|||
player.advances.insert(advance);
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn find_special_advance(
|
||||
advance: Advance,
|
||||
game: &Game,
|
||||
player_index: usize,
|
||||
) -> Option<SpecialAdvance> {
|
||||
if advance.info(game).leading_government {
|
||||
find_government_special_advance(game, player_index)
|
||||
} else {
|
||||
find_non_government_special_advance(advance, game.player(player_index))
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn find_non_government_special_advance(
|
||||
advance: Advance,
|
||||
p: &Player,
|
||||
) -> Option<SpecialAdvance> {
|
||||
p.civilization
|
||||
.special_advances
|
||||
.iter()
|
||||
.find_map(|s| match s.requirement {
|
||||
SpecialAdvanceRequirement::Advance(a) if a == advance => Some(s.advance),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn find_government_special_advance(
|
||||
game: &Game,
|
||||
player: usize,
|
||||
) -> Option<SpecialAdvance> {
|
||||
let p = game.player(player);
|
||||
p.civilization
|
||||
.special_advances
|
||||
.iter()
|
||||
.find_map(|s| match s.requirement {
|
||||
SpecialAdvanceRequirement::AnyGovernment => Some(s.advance),
|
||||
SpecialAdvanceRequirement::Advance(_) => None,
|
||||
})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_special_advance_active(
|
||||
advance: SpecialAdvance,
|
||||
advances: EnumSet<Advance>,
|
||||
game: &Game,
|
||||
) -> bool {
|
||||
match advance.info(game).requirement {
|
||||
SpecialAdvanceRequirement::AnyGovernment => player_government(game, advances).is_some(),
|
||||
SpecialAdvanceRequirement::Advance(a) => advances.contains(a),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn gain_advance_without_payment(
|
||||
game: &mut Game,
|
||||
advance: Advance,
|
||||
|
|
@ -318,24 +363,12 @@ pub(crate) fn remove_advance(game: &mut Game, advance: Advance, player_index: us
|
|||
let bonus = info.bonus.clone();
|
||||
info.listeners.clone().undo(game, player_index);
|
||||
|
||||
for i in 0..game.players[player_index]
|
||||
.civilization
|
||||
.special_advances
|
||||
.len()
|
||||
if let Some(special_advance) =
|
||||
find_non_government_special_advance(advance, game.player(player_index))
|
||||
{
|
||||
if game.players[player_index].civilization.special_advances[i].required_advance == advance {
|
||||
let special_advance = game.players[player_index]
|
||||
.civilization
|
||||
.special_advances
|
||||
.remove(i);
|
||||
undo_unlock_special_advance(game, &special_advance, player_index);
|
||||
game.players[player_index]
|
||||
.civilization
|
||||
.special_advances
|
||||
.insert(i, special_advance);
|
||||
break;
|
||||
}
|
||||
undo_unlock_special_advance(game, special_advance, player_index);
|
||||
}
|
||||
|
||||
let player = &mut game.players[player_index];
|
||||
if let Some(advance_bonus) = &bonus {
|
||||
player.lose_resources(advance_bonus.resources());
|
||||
|
|
@ -343,49 +376,87 @@ pub(crate) fn remove_advance(game: &mut Game, advance: Advance, player_index: us
|
|||
game.player_mut(player_index).advances.remove(advance);
|
||||
}
|
||||
|
||||
fn unlock_special_advance(game: &mut Game, special_advance: &SpecialAdvance, player_index: usize) {
|
||||
special_advance.listeners.one_time_init(game, player_index);
|
||||
fn unlock_special_advance(game: &mut Game, special_advance: SpecialAdvance, player_index: usize) {
|
||||
game.add_info_log_item(&format!(
|
||||
"{} unlocked {}",
|
||||
game.player_name(player_index),
|
||||
special_advance.info(game).name
|
||||
));
|
||||
special_advance
|
||||
.info(game)
|
||||
.listeners
|
||||
.clone()
|
||||
.one_time_init(game, player_index);
|
||||
game.players[player_index]
|
||||
.unlocked_special_advances
|
||||
.push(special_advance.name.clone());
|
||||
.special_advances
|
||||
.insert(special_advance);
|
||||
}
|
||||
|
||||
fn undo_unlock_special_advance(
|
||||
pub(crate) fn undo_unlock_special_advance(
|
||||
game: &mut Game,
|
||||
special_advance: &SpecialAdvance,
|
||||
special_advance: SpecialAdvance,
|
||||
player_index: usize,
|
||||
) {
|
||||
special_advance.listeners.undo(game, player_index);
|
||||
game.players[player_index].unlocked_special_advances.pop();
|
||||
special_advance
|
||||
.info(game)
|
||||
.listeners
|
||||
.clone()
|
||||
.undo(game, player_index);
|
||||
game.players[player_index]
|
||||
.special_advances
|
||||
.remove(special_advance);
|
||||
}
|
||||
|
||||
pub(crate) fn init_player(game: &mut Game, player_index: usize) {
|
||||
let advances = mem::take(&mut game.player_mut(player_index).advances);
|
||||
for advance in advances.iter() {
|
||||
let info = advance.info(game);
|
||||
info.listeners.clone().init(game, player_index);
|
||||
for i in 0..game
|
||||
.player(player_index)
|
||||
.civilization
|
||||
.special_advances
|
||||
.len()
|
||||
{
|
||||
if game.players[player_index].civilization.special_advances[i].required_advance
|
||||
== advance
|
||||
{
|
||||
let special_advance = game
|
||||
.player_mut(player_index)
|
||||
.civilization
|
||||
.special_advances
|
||||
.remove(i);
|
||||
special_advance.listeners.init(game, player_index);
|
||||
game.players[player_index]
|
||||
.civilization
|
||||
.special_advances
|
||||
.insert(i, special_advance);
|
||||
break;
|
||||
for advance in game.player(player_index).advances {
|
||||
advance
|
||||
.info(game)
|
||||
.listeners
|
||||
.clone()
|
||||
.init(game, player_index);
|
||||
|
||||
for s in game.player(player_index).special_advances {
|
||||
if is_special_advance_active(s, game.player(player_index).advances, game) {
|
||||
s.info(game).listeners.clone().init(game, player_index);
|
||||
}
|
||||
}
|
||||
}
|
||||
game.player_mut(player_index).advances = advances;
|
||||
}
|
||||
|
||||
pub(crate) fn init_great_library(game: &mut Game, player_index: usize) {
|
||||
if let Some(advance) = game.player(player_index).great_library_advance {
|
||||
advance
|
||||
.info(game)
|
||||
.listeners
|
||||
.clone()
|
||||
.init(game, player_index);
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn base_advance_cost(player: &Player) -> PaymentOptions {
|
||||
PaymentOptions::sum(
|
||||
player,
|
||||
PaymentReason::GainAdvance,
|
||||
ADVANCE_COST,
|
||||
&[ResourceType::Ideas, ResourceType::Food, ResourceType::Gold],
|
||||
)
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
|
||||
pub struct AdvanceAction {
|
||||
pub advance: Advance,
|
||||
pub payment: ResourcePile,
|
||||
}
|
||||
|
||||
impl AdvanceAction {
|
||||
#[must_use]
|
||||
pub fn new(advance: Advance, payment: ResourcePile) -> Self {
|
||||
Self { advance, payment }
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn player_government(game: &Game, advances: EnumSet<Advance>) -> Option<String> {
|
||||
advances
|
||||
.iter()
|
||||
.find_map(|advance| advance.info(game).government.clone())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use crate::action::{Action, ActionType};
|
||||
use crate::advance::AdvanceAction;
|
||||
use crate::ai_collect::{possible_collections, total_collect};
|
||||
use crate::card::validate_card_selection;
|
||||
use crate::city::{City, MoodState};
|
||||
use crate::collect::{available_collect_actions, possible_resource_collections};
|
||||
use crate::construct::{Construct, available_buildings, new_building_positions};
|
||||
use crate::content::custom_actions::CustomEventAction;
|
||||
use crate::content::custom_actions::CustomAction;
|
||||
use crate::content::persistent_events::{
|
||||
EventResponse, HandCardsRequest, MultiRequest, PersistentEventRequest, PersistentEventState,
|
||||
PositionRequest, SelectedStructure, is_selected_structures_valid,
|
||||
|
|
@ -18,7 +19,7 @@ use crate::happiness::{available_happiness_actions, happiness_cost};
|
|||
use crate::payment::PaymentOptions;
|
||||
use crate::player::{CostTrigger, Player};
|
||||
use crate::playing_actions::{
|
||||
Collect, IncreaseHappiness, PlayingAction, PlayingActionType, Recruit, base_and_custom_action,
|
||||
Collect, IncreaseHappiness, PlayingAction, PlayingActionType, Recruit,
|
||||
};
|
||||
use crate::position::Position;
|
||||
use crate::recruit::recruit_cost;
|
||||
|
|
@ -141,10 +142,8 @@ fn base_actions(ai: &mut AiActions, game: &Game) -> Vec<(ActionType, Vec<Action>
|
|||
|
||||
// IncreaseHappiness
|
||||
let happiness = available_happiness_actions(game, p.index);
|
||||
// if !happiness.is_empty() {
|
||||
// let action_type = prefer_custom_action(happiness); // todo custom action is buggy
|
||||
if let Some(action_type) = base_and_custom_action(happiness).0 {
|
||||
if let Some(h) = calculate_increase_happiness(p, &action_type, game) {
|
||||
if !happiness.is_empty() {
|
||||
if let Some(h) = calculate_increase_happiness(p, &prefer_custom_action(&happiness), game) {
|
||||
actions.push((
|
||||
ActionType::Playing(PlayingActionType::IncreaseHappiness),
|
||||
vec![Action::Playing(PlayingAction::IncreaseHappiness(h))],
|
||||
|
|
@ -153,9 +152,7 @@ fn base_actions(ai: &mut AiActions, game: &Game) -> Vec<(ActionType, Vec<Action>
|
|||
}
|
||||
|
||||
// InfluenceCultureAttempt,
|
||||
let influence = available_influence_actions(game, p.index);
|
||||
if !influence.is_empty() {
|
||||
let action_type = prefer_custom_action(influence);
|
||||
for action_type in available_influence_actions(game, p.index) {
|
||||
if let Some(i) = calculate_influence(game, p, &action_type) {
|
||||
actions.push((
|
||||
ActionType::Playing(PlayingActionType::Collect),
|
||||
|
|
@ -207,10 +204,10 @@ fn base_actions(ai: &mut AiActions, game: &Game) -> Vec<(ActionType, Vec<Action>
|
|||
|
||||
for c in cities {
|
||||
actions.push((
|
||||
ActionType::Playing(PlayingActionType::Custom(a.clone())),
|
||||
vec![Action::Playing(PlayingAction::Custom(
|
||||
CustomEventAction::new(a.clone(), c),
|
||||
))],
|
||||
ActionType::Playing(PlayingActionType::Custom(a)),
|
||||
vec![Action::Playing(PlayingAction::Custom(CustomAction::new(
|
||||
a, c,
|
||||
)))],
|
||||
));
|
||||
}
|
||||
}
|
||||
|
|
@ -219,8 +216,7 @@ fn base_actions(ai: &mut AiActions, game: &Game) -> Vec<(ActionType, Vec<Action>
|
|||
}
|
||||
|
||||
fn available_action_cards(game: &Game, p: &Player) -> Vec<Action> {
|
||||
let action_cards = p
|
||||
.action_cards
|
||||
p.action_cards
|
||||
.iter()
|
||||
.filter_map(|card| {
|
||||
if *card == 126 || *card == 17 || *card == 18 {
|
||||
|
|
@ -253,8 +249,7 @@ fn available_action_cards(game: &Game, p: &Player) -> Vec<Action> {
|
|||
.is_ok()
|
||||
.then_some(Action::Playing(PlayingAction::ActionCard(*card)))
|
||||
})
|
||||
.collect_vec();
|
||||
action_cards
|
||||
.collect_vec()
|
||||
}
|
||||
|
||||
fn payment(ai_actions: &mut AiActions, o: &PaymentOptions, p: &Player) -> ResourcePile {
|
||||
|
|
@ -308,12 +303,7 @@ fn advances(ai_actions: &mut AiActions, p: &Player, game: &Game) -> Vec<Action>
|
|||
&p.advance_cost(a, game, CostTrigger::NoModifiers).cost,
|
||||
p,
|
||||
)
|
||||
.map(|r| {
|
||||
Action::Playing(PlayingAction::Advance {
|
||||
advance: a,
|
||||
payment: r,
|
||||
})
|
||||
})
|
||||
.map(|r| Action::Playing(PlayingAction::Advance(AdvanceAction::new(a, r))))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
|
@ -323,7 +313,7 @@ fn collect_actions(p: &Player, game: &Game) -> Vec<Action> {
|
|||
if collect.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
let action_type = prefer_custom_action(collect);
|
||||
let action_type = prefer_custom_action(&collect);
|
||||
|
||||
p.cities
|
||||
.iter()
|
||||
|
|
@ -375,12 +365,12 @@ fn recruit_strategies() -> Vec<Vec<UnitType>> {
|
|||
]
|
||||
}
|
||||
|
||||
fn recruit(ai_actions: &mut AiActions, p: &Player, _game: &Game) -> Vec<Action> {
|
||||
fn recruit(ai_actions: &mut AiActions, p: &Player, game: &Game) -> Vec<Action> {
|
||||
p.cities
|
||||
.iter()
|
||||
.flat_map(|city| {
|
||||
if city.can_activate() {
|
||||
recruit_actions(ai_actions, p, city)
|
||||
recruit_actions(ai_actions, p, city, game)
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
|
|
@ -388,7 +378,12 @@ fn recruit(ai_actions: &mut AiActions, p: &Player, _game: &Game) -> Vec<Action>
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn recruit_actions(ai_actions: &mut AiActions, player: &Player, city: &City) -> Vec<Action> {
|
||||
fn recruit_actions(
|
||||
ai_actions: &mut AiActions,
|
||||
player: &Player,
|
||||
city: &City,
|
||||
game: &Game,
|
||||
) -> Vec<Action> {
|
||||
recruit_strategies()
|
||||
.iter()
|
||||
.map(|strategy| {
|
||||
|
|
@ -404,6 +399,7 @@ fn recruit_actions(ai_actions: &mut AiActions, player: &Player, city: &City) ->
|
|||
let mut next = units.clone();
|
||||
next += &unit_type;
|
||||
match recruit_cost(
|
||||
game,
|
||||
player,
|
||||
&next,
|
||||
city.position,
|
||||
|
|
@ -481,11 +477,17 @@ fn calculate_increase_happiness(
|
|||
))
|
||||
}
|
||||
|
||||
fn prefer_custom_action(actions: Vec<PlayingActionType>) -> PlayingActionType {
|
||||
let (action, custom) = base_and_custom_action(actions);
|
||||
action.unwrap_or_else(|| {
|
||||
PlayingActionType::Custom(custom.expect("custom action should be present"))
|
||||
})
|
||||
fn prefer_custom_action(actions: &[PlayingActionType]) -> PlayingActionType {
|
||||
actions
|
||||
.iter()
|
||||
.find(|a| matches!(a, PlayingActionType::Custom(_)))
|
||||
.or_else(|| {
|
||||
actions
|
||||
.iter()
|
||||
.find(|a| !matches!(a, PlayingActionType::Custom(_)))
|
||||
})
|
||||
.cloned()
|
||||
.expect("expected at least one action type, either custom or base")
|
||||
}
|
||||
|
||||
#[allow(clippy::match_same_arms)]
|
||||
|
|
|
|||
|
|
@ -4,7 +4,9 @@ use crate::combat::move_with_possible_combat;
|
|||
use crate::consts::STACK_LIMIT;
|
||||
use crate::content::advances::theocracy::cities_that_can_add_units;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::persistent_events::{PositionRequest, ResourceRewardRequest, UnitTypeRequest};
|
||||
use crate::content::persistent_events::{
|
||||
PersistentEventType, PositionRequest, ResourceRewardRequest, UnitTypeRequest,
|
||||
};
|
||||
use crate::game::Game;
|
||||
use crate::incident::{BASE_EFFECT_PRIORITY, IncidentBuilder, IncidentFilter, play_base_effect};
|
||||
use crate::map::Terrain;
|
||||
|
|
@ -125,8 +127,13 @@ pub(crate) fn barbarians_spawn(mut builder: IncidentBuilder) -> IncidentBuilder
|
|||
|e| &mut e.incident,
|
||||
BASE_EFFECT_PRIORITY,
|
||||
|game, p, i| {
|
||||
IncidentFilter::new(IncidentTarget::ActivePlayer, BASE_EFFECT_PRIORITY, None)
|
||||
.is_active(game, i, p)
|
||||
IncidentFilter::new(
|
||||
IncidentTarget::ActivePlayer,
|
||||
BASE_EFFECT_PRIORITY,
|
||||
None,
|
||||
None,
|
||||
)
|
||||
.is_active(game, i, p)
|
||||
},
|
||||
|i| {
|
||||
i.barbarians
|
||||
|
|
@ -169,12 +176,55 @@ where
|
|||
move |game, s, v| {
|
||||
let position = get_barbarian_city2(v).expect("barbarians should exist");
|
||||
let units = Units::from_iter(vec![s.choice]);
|
||||
game.add_info_log_item(&format!("Barbarians reinforced with {units} at {position}",));
|
||||
game.add_info_log_item(&format!(
|
||||
"Barbarians reinforced with {} at {position}",
|
||||
units.to_string(None)
|
||||
));
|
||||
add_unit(get_barbarians_player(game).index, position, s.choice, game);
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn on_stop_barbarian_movement(game: &mut Game, movable: Vec<Position>) {
|
||||
let old_movable = movable.clone();
|
||||
match game.trigger_persistent_event(
|
||||
&game.human_players(0),
|
||||
|events| &mut events.stop_barbarian_movement,
|
||||
movable,
|
||||
PersistentEventType::StopBarbarianMovement,
|
||||
) {
|
||||
None => (),
|
||||
Some(movable) => {
|
||||
if movable == old_movable {
|
||||
// nothing changed, so we can skip the rest
|
||||
return;
|
||||
}
|
||||
|
||||
let mut event_state = game.events.pop().expect("event should exist");
|
||||
if let PersistentEventType::Incident(i) = &mut event_state.event_type {
|
||||
let state = i.get_barbarian_state();
|
||||
for pos in old_movable {
|
||||
if !movable.contains(&pos) {
|
||||
// if the position was not selected, it means the unit cannot move
|
||||
let units = get_barbarians_player(game)
|
||||
.get_units(pos)
|
||||
.iter()
|
||||
.map(|u| u.id)
|
||||
.collect_vec();
|
||||
state.moved_units.extend(units);
|
||||
}
|
||||
}
|
||||
game.events.push(event_state);
|
||||
} else {
|
||||
panic!(
|
||||
"StopBarbarianMovement should only be triggered from an Incident, not {:?}",
|
||||
game.current_event().event_type
|
||||
)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn barbarians_move(mut builder: IncidentBuilder) -> IncidentBuilder {
|
||||
let event_name = "Barbarians move";
|
||||
builder = set_info(builder, event_name, |state, game, human| {
|
||||
|
|
@ -184,7 +234,19 @@ pub(crate) fn barbarians_move(mut builder: IncidentBuilder) -> IncidentBuilder {
|
|||
state.move_units = true;
|
||||
}
|
||||
});
|
||||
builder = add_barbarians_city(builder, event_name);
|
||||
builder = add_barbarians_city(builder, event_name).add_simple_incident_listener(
|
||||
IncidentTarget::ActivePlayer,
|
||||
BASE_EFFECT_PRIORITY + 99,
|
||||
|game, _, _, i| {
|
||||
let movable = get_movable_units(game, i.active_player, i.get_barbarian_state());
|
||||
if movable.is_empty() {
|
||||
return;
|
||||
}
|
||||
|
||||
on_stop_barbarian_movement(game, movable);
|
||||
},
|
||||
);
|
||||
|
||||
for army in 0..18 {
|
||||
builder = builder
|
||||
.add_incident_position_request(
|
||||
|
|
@ -242,7 +304,8 @@ pub(crate) fn barbarians_move(mut builder: IncidentBuilder) -> IncidentBuilder {
|
|||
state.moved_units.extend(units.iter());
|
||||
let unit_types = ids.iter().map(|u| u.unit_type).collect::<Units>();
|
||||
game.add_info_log_item(&format!(
|
||||
"Barbarians move from {from} to {to}: {unit_types}"
|
||||
"Barbarians move from {from} to {to}: {}",
|
||||
unit_types.to_string(None)
|
||||
));
|
||||
move_with_possible_combat(
|
||||
game,
|
||||
|
|
@ -286,8 +349,12 @@ fn reinforce_after_move(game: &mut Game, player_index: usize) {
|
|||
}
|
||||
}
|
||||
|
||||
fn get_movable_units(game: &Game, human: usize, state: &BarbariansEventState) -> Vec<Position> {
|
||||
let human = game.player(human);
|
||||
pub(crate) fn get_movable_units(
|
||||
game: &Game,
|
||||
target_player: usize,
|
||||
state: &BarbariansEventState,
|
||||
) -> Vec<Position> {
|
||||
let target = game.player(target_player);
|
||||
let barbarian = get_barbarians_player(game);
|
||||
|
||||
game.map
|
||||
|
|
@ -300,8 +367,9 @@ fn get_movable_units(game: &Game, human: usize, state: &BarbariansEventState) ->
|
|||
.iter()
|
||||
.filter(|u| !state.moved_units.contains(&u.id))
|
||||
.count();
|
||||
stack > 0 && !barbarian_march_steps(game, human, *pos, stack).is_empty()
|
||||
stack > 0 && !barbarian_march_steps(game, target, *pos, stack).is_empty()
|
||||
})
|
||||
.sorted()
|
||||
.copied()
|
||||
.collect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,18 @@
|
|||
use crate::action_card::{ActionCard, CivilCard};
|
||||
use crate::advance::{Advance, AdvanceInfo};
|
||||
use crate::city_pieces::Building;
|
||||
use crate::civilization::Civilization;
|
||||
use crate::content::advances::AdvanceGroup;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_actions::custom_action_builtins;
|
||||
use crate::content::{
|
||||
action_cards, advances, builtin, incidents, objective_cards, objectives, wonders,
|
||||
action_cards, advances, builtin, civilizations, incidents, objective_cards, objectives, wonders,
|
||||
};
|
||||
use crate::game::Game;
|
||||
use crate::incident::Incident;
|
||||
use crate::leader::{Leader, LeaderAbility};
|
||||
use crate::objective_card::{Objective, ObjectiveCard};
|
||||
use crate::special_advance::{SpecialAdvance, SpecialAdvanceInfo};
|
||||
use crate::status_phase::StatusPhaseState::{ChangeGovernmentType, DetermineFirstPlayer};
|
||||
use crate::status_phase::{
|
||||
StatusPhaseState, complete_objectives, determine_first_player, draw_cards, free_advance,
|
||||
|
|
@ -45,6 +48,9 @@ pub struct Cache {
|
|||
|
||||
all_incidents: Vec<Incident>,
|
||||
incidents_by_id: HashMap<u8, Incident>,
|
||||
|
||||
civilizations_by_name: HashMap<String, Civilization>,
|
||||
all_special_advances: Vec<SpecialAdvanceInfo>,
|
||||
}
|
||||
|
||||
impl Default for Cache {
|
||||
|
|
@ -69,7 +75,6 @@ impl Cache {
|
|||
.collect(),
|
||||
status_phase_handlers: status_phase_handlers(),
|
||||
|
||||
// todo special advances
|
||||
all_advances: advances::get_all_uncached(),
|
||||
|
||||
all_advance_groups: advances::get_groups_uncached(),
|
||||
|
|
@ -127,6 +132,16 @@ impl Cache {
|
|||
.into_iter()
|
||||
.map(|incident| (incident.id, incident))
|
||||
.collect(),
|
||||
|
||||
civilizations_by_name: civilizations::get_all_uncached()
|
||||
.into_iter()
|
||||
.map(|c| (c.name.clone(), c))
|
||||
.collect(),
|
||||
all_special_advances: civilizations::get_all_uncached()
|
||||
.into_iter()
|
||||
.flat_map(|c| c.special_advances)
|
||||
.sorted_by_key(|s| s.advance)
|
||||
.collect(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -140,6 +155,11 @@ impl Cache {
|
|||
&self.all_advances[a as usize]
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_special_advance(&self, a: SpecialAdvance) -> &SpecialAdvanceInfo {
|
||||
&self.all_special_advances[a as usize]
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_advance_groups(&self) -> &Vec<AdvanceGroup> {
|
||||
&self.all_advance_groups
|
||||
|
|
@ -218,6 +238,7 @@ impl Cache {
|
|||
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if action card does not exist
|
||||
#[must_use]
|
||||
pub fn get_action_card(&self, id: u8) -> &ActionCard {
|
||||
|
|
@ -293,11 +314,47 @@ impl Cache {
|
|||
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if incident does not exist
|
||||
#[must_use]
|
||||
pub fn get_incident(&self, id: u8) -> &Incident {
|
||||
self.incidents_by_id.get(&id).expect("incident not found")
|
||||
}
|
||||
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if civilization does not exist
|
||||
#[must_use]
|
||||
pub fn get_civilization(&self, name: &str) -> Civilization {
|
||||
match name {
|
||||
// "Maya" => maya::maya(), // still needs to be implemented
|
||||
// for integration testing
|
||||
"test0" => Civilization::new(
|
||||
"test0",
|
||||
vec![],
|
||||
vec![
|
||||
Leader::new(
|
||||
"Alexander",
|
||||
LeaderAbility::builder("", "").build(),
|
||||
LeaderAbility::builder("", "").build(),
|
||||
),
|
||||
Leader::new(
|
||||
"Kleopatra",
|
||||
LeaderAbility::builder("", "").build(),
|
||||
LeaderAbility::builder("", "").build(),
|
||||
),
|
||||
],
|
||||
), // for testing
|
||||
"test1" => Civilization::new("test1", vec![], vec![]),
|
||||
"test2" => Civilization::new("test2", vec![], vec![]),
|
||||
_ => self
|
||||
.civilizations_by_name
|
||||
.get(name)
|
||||
.cloned()
|
||||
.expect("civilization not found"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn status_phase_handlers() -> HashMap<StatusPhaseState, Builtin> {
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use crate::content::action_cards::spy::validate_spy_cards;
|
||||
use crate::content::action_cards::synergies::validate_new_plans;
|
||||
use crate::content::civilizations::rome::validate_princeps_cards;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
|
|
@ -128,7 +129,15 @@ pub fn validate_card_selection(
|
|||
let Some(h) = &game.current_event().player.handler.as_ref() else {
|
||||
return Err("no selection handler".to_string());
|
||||
};
|
||||
match &h.origin {
|
||||
validate_card_selection_for_origin(cards, game, &h.origin)
|
||||
}
|
||||
|
||||
pub(crate) fn validate_card_selection_for_origin(
|
||||
cards: &[HandCard],
|
||||
game: &Game,
|
||||
o: &EventOrigin,
|
||||
) -> Result<Vec<(u8, String)>, String> {
|
||||
match o {
|
||||
EventOrigin::CivilCard(id) if *id == 7 || *id == 8 => {
|
||||
validate_spy_cards(cards, game).map(|()| Vec::new())
|
||||
}
|
||||
|
|
@ -142,6 +151,24 @@ pub fn validate_card_selection(
|
|||
|
||||
match_objective_cards(cards, &c.objective_opportunities, game)
|
||||
}
|
||||
EventOrigin::Builtin(b) if b == "Princeps" => {
|
||||
validate_princeps_cards(cards).map(|()| Vec::new())
|
||||
}
|
||||
_ => Ok(Vec::new()),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn all_action_hand_cards(p: &Player) -> Vec<HandCard> {
|
||||
p.action_cards
|
||||
.iter()
|
||||
.map(|a| HandCard::ActionCard(*a))
|
||||
.collect_vec()
|
||||
}
|
||||
|
||||
pub(crate) fn all_objective_hand_cards(player: &Player) -> Vec<HandCard> {
|
||||
player
|
||||
.objective_cards
|
||||
.iter()
|
||||
.map(|&a| HandCard::ObjectiveCard(a))
|
||||
.collect_vec()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,15 +1,20 @@
|
|||
use crate::content::civilizations::{BARBARIANS, PIRATES};
|
||||
use crate::{leader::Leader, special_advance::SpecialAdvance};
|
||||
use crate::{leader::Leader, special_advance::SpecialAdvanceInfo};
|
||||
|
||||
//todo add optional special starting tile
|
||||
#[derive(Clone)]
|
||||
pub struct Civilization {
|
||||
pub name: String,
|
||||
pub special_advances: Vec<SpecialAdvance>,
|
||||
pub special_advances: Vec<SpecialAdvanceInfo>,
|
||||
pub leaders: Vec<Leader>,
|
||||
}
|
||||
|
||||
impl Civilization {
|
||||
pub fn new(name: &str, special_advances: Vec<SpecialAdvance>, leaders: Vec<Leader>) -> Self {
|
||||
pub fn new(
|
||||
name: &str,
|
||||
special_advances: Vec<SpecialAdvanceInfo>,
|
||||
leaders: Vec<Leader>,
|
||||
) -> Self {
|
||||
Self {
|
||||
name: name.to_string(),
|
||||
special_advances,
|
||||
|
|
|
|||
|
|
@ -322,6 +322,6 @@ pub fn available_collect_actions(game: &Game, player: usize) -> Vec<PlayingActio
|
|||
game,
|
||||
player,
|
||||
PlayingActionType::Collect,
|
||||
&CustomActionType::FreeEconomyCollect,
|
||||
vec![CustomActionType::FreeEconomyCollect],
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::barbarians::get_barbarians_player;
|
||||
use crate::city::City;
|
||||
use crate::city::MoodState::Angry;
|
||||
use crate::city_pieces::{Building, remove_building};
|
||||
|
|
@ -155,6 +156,19 @@ impl Combat {
|
|||
CombatRole::Defender => self.defender(),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn has_leader(&self, role: CombatRole, game: &Game) -> bool {
|
||||
let p = self.player(role);
|
||||
self.fighting_units(game, p)
|
||||
.iter()
|
||||
.any(|&unit_id| game.player(p).get_unit(unit_id).unit_type == UnitType::Leader)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_barbarian_battle(&self, role: CombatRole, game: &Game) -> bool {
|
||||
self.opponent(self.player(role)) == get_barbarians_player(game).index
|
||||
}
|
||||
}
|
||||
|
||||
pub fn initiate_combat(
|
||||
|
|
@ -197,6 +211,7 @@ pub(crate) fn log_round(game: &mut Game, c: &Combat) {
|
|||
.collect_vec()
|
||||
})
|
||||
.collect::<Units>()
|
||||
.to_string(game.player(c.attacker()).active_leader.as_ref())
|
||||
));
|
||||
game.add_info_log_item(&format!(
|
||||
"Defenders: {}",
|
||||
|
|
@ -205,6 +220,7 @@ pub(crate) fn log_round(game: &mut Game, c: &Combat) {
|
|||
.iter()
|
||||
.map(|u| u.unit_type)
|
||||
.collect::<Units>()
|
||||
.to_string(game.player(c.defender()).active_leader.as_ref())
|
||||
));
|
||||
}
|
||||
|
||||
|
|
@ -529,6 +545,7 @@ pub mod tests {
|
|||
use crate::action::Action;
|
||||
|
||||
use crate::cache::Cache;
|
||||
use crate::civilization::Civilization;
|
||||
use crate::game::{GameContext, GameOptions, GameState};
|
||||
use crate::log::{ActionLogAge, ActionLogItem, ActionLogPlayer, ActionLogRound};
|
||||
use crate::movement::MovementAction;
|
||||
|
|
@ -537,7 +554,6 @@ pub mod tests {
|
|||
use crate::{
|
||||
city::{City, MoodState::*},
|
||||
city_pieces::Building::*,
|
||||
content::civilizations,
|
||||
map::Map,
|
||||
player::Player,
|
||||
position::Position,
|
||||
|
|
@ -590,8 +606,8 @@ pub mod tests {
|
|||
|
||||
#[test]
|
||||
fn conquer_test() {
|
||||
let old = Player::new(civilizations::tests::get_test_civilization(), 0);
|
||||
let new = Player::new(civilizations::tests::get_test_civilization(), 1);
|
||||
let old = Player::new(get_test_civilization(), 0);
|
||||
let new = Player::new(get_test_civilization(), 1);
|
||||
|
||||
let mut game = test_game();
|
||||
game.add_info_log_group("combat".into()); // usually filled in combat
|
||||
|
|
@ -623,4 +639,9 @@ pub mod tests {
|
|||
assert_eq!(1, old.owned_buildings(&game));
|
||||
assert_eq!(1, new.owned_buildings(&game));
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_test_civilization() -> Civilization {
|
||||
Civilization::new("test", vec![], vec![])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -626,6 +626,7 @@ fn kill_fighters(game: &mut Game, player: usize, killed_unit_ids: &[u32], c: &mu
|
|||
.iter()
|
||||
.map(|id| p.get_unit(*id).unit_type)
|
||||
.collect::<Units>()
|
||||
.to_string(p.active_leader.as_ref())
|
||||
));
|
||||
|
||||
kill_combat_units(game, c, player, killed_unit_ids);
|
||||
|
|
|
|||
|
|
@ -8,7 +8,6 @@ use crate::unit::{UnitType, Units};
|
|||
use crate::utils;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::mem;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct CombatPlayerStats {
|
||||
|
|
@ -34,7 +33,7 @@ impl CombatPlayerStats {
|
|||
}
|
||||
|
||||
pub fn add_losses(&mut self, units: &[UnitType]) {
|
||||
let mut losses = mem::replace(&mut self.losses, Units::empty());
|
||||
let mut losses = std::mem::take(&mut self.losses);
|
||||
for t in units {
|
||||
losses += t;
|
||||
}
|
||||
|
|
@ -234,7 +233,8 @@ pub(crate) fn new_combat_stats(
|
|||
let d = game.player(defender);
|
||||
let attacker_position = a.get_unit(attackers[0]).position;
|
||||
assert_ne!(defender_position, attacker_position);
|
||||
let stats = CombatStats::new(
|
||||
|
||||
CombatStats::new(
|
||||
battleground,
|
||||
battleground.is_land() && game.map.is_sea(attacker_position),
|
||||
CombatPlayerStats::new(attacker, to_units(attackers, a), attacker_position),
|
||||
|
|
@ -247,8 +247,7 @@ pub(crate) fn new_combat_stats(
|
|||
defender_position,
|
||||
),
|
||||
result,
|
||||
);
|
||||
stats
|
||||
)
|
||||
}
|
||||
|
||||
fn to_units(units: &[u32], p: &Player) -> Units {
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ use crate::barbarians::{barbarian_reinforcement, get_barbarians_player};
|
|||
use crate::combat::move_with_possible_combat;
|
||||
use crate::consts::STACK_LIMIT;
|
||||
use crate::content::action_cards::inspiration::player_positions;
|
||||
use crate::content::civilizations::rome::owner_of_sulla_in_range;
|
||||
use crate::content::persistent_events::{PaymentRequest, PositionRequest};
|
||||
use crate::content::tactics_cards::TacticsCardFactory;
|
||||
use crate::game::Game;
|
||||
|
|
@ -29,7 +30,8 @@ pub(crate) fn mercenaries(id: u8, tactics_card: TacticsCardFactory) -> ActionCar
|
|||
Reinforce all Barbarian cities where you moved units out of according to the usual rules.",
|
||||
ActionCost::regular(),
|
||||
|game, p, _| {
|
||||
!barbarian_army_positions_in_range2(game, p).is_empty() && max_mercenary_payment(p) > 0
|
||||
!barbarian_army_positions_in_range2(game, p).0.is_empty()
|
||||
&& max_mercenary_payment(p) > 0
|
||||
},
|
||||
)
|
||||
.tactics_card(tactics_card)
|
||||
|
|
@ -37,12 +39,14 @@ pub(crate) fn mercenaries(id: u8, tactics_card: TacticsCardFactory) -> ActionCar
|
|||
|e| &mut e.play_action_card,
|
||||
2,
|
||||
|game, player, _| {
|
||||
let p = game.player(player);
|
||||
let r = barbarian_army_positions_in_range2(game, p);
|
||||
let (r, log) = barbarian_army_positions_in_range2(game, game.player(player));
|
||||
for l in log {
|
||||
game.add_info_log_item(&l);
|
||||
}
|
||||
if r.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let max = (r.len() as u8).min(max_mercenary_payment(p));
|
||||
let max = (r.len() as u8).min(max_mercenary_payment(game.player(player)));
|
||||
Some(PositionRequest::new(
|
||||
r,
|
||||
1..=max,
|
||||
|
|
@ -178,15 +182,39 @@ fn move_army(b: ActionCardBuilder, i: i32) -> ActionCardBuilder {
|
|||
)
|
||||
}
|
||||
|
||||
fn barbarian_army_positions_in_range2(game: &Game, player: &Player) -> Vec<Position> {
|
||||
fn barbarian_army_positions_in_range2(
|
||||
game: &Game,
|
||||
player: &Player,
|
||||
) -> (Vec<Position>, Vec<String>) {
|
||||
let my = player_positions(player);
|
||||
let mut log = Vec::new();
|
||||
|
||||
get_barbarians_player(game)
|
||||
let positions = get_barbarians_player(game)
|
||||
.units
|
||||
.iter()
|
||||
.map(|u| u.position)
|
||||
.filter(|b| my.iter().any(|my_pos| my_pos.distance(*b) <= 2))
|
||||
.collect()
|
||||
.filter(|&p| {
|
||||
my.iter().any(|my_pos| {
|
||||
if my_pos.distance(p) > 2 {
|
||||
return false;
|
||||
}
|
||||
if owner_of_sulla_in_range(p, game)
|
||||
.is_some_and(|sulla_owner| player.index != sulla_owner)
|
||||
{
|
||||
log.push(format!(
|
||||
"{player} cannot move Barbarian army at {p} because Sulla is in range",
|
||||
));
|
||||
return false;
|
||||
}
|
||||
true
|
||||
})
|
||||
})
|
||||
.collect();
|
||||
|
||||
log.sort();
|
||||
log.dedup();
|
||||
|
||||
(positions, log)
|
||||
}
|
||||
|
||||
fn max_mercenary_payment(player: &Player) -> u8 {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ pub(crate) fn advance_group_builder(name: &str, advances: Vec<AdvanceBuilder>) -
|
|||
.enumerate()
|
||||
.map(|(index, builder)| {
|
||||
let builder = if let Some(g) = &government {
|
||||
builder.with_government(g.name)
|
||||
builder.with_government(g.name, index == 0)
|
||||
} else {
|
||||
builder
|
||||
};
|
||||
|
|
|
|||
|
|
@ -28,20 +28,16 @@ fn nationalism() -> AdvanceBuilder {
|
|||
|event| &mut event.recruit,
|
||||
1,
|
||||
|_game, _player_index, recruit| {
|
||||
if recruit
|
||||
recruit
|
||||
.units
|
||||
.clone()
|
||||
.to_vec()
|
||||
.iter()
|
||||
.any(|u| u.is_army_unit() || u.is_ship())
|
||||
{
|
||||
Some(ResourceRewardRequest::new(
|
||||
.then_some(ResourceRewardRequest::new(
|
||||
ResourceReward::tokens(1),
|
||||
"Select token to gain".to_string(),
|
||||
))
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
|_game, resource, _| {
|
||||
vec![format!(
|
||||
|
|
@ -77,17 +73,16 @@ fn totalitarianism() -> AdvanceBuilder {
|
|||
)
|
||||
}
|
||||
|
||||
const ABSOLUTE_POWER: &str =
|
||||
"Once per turn, as a free action, you may spend 2 mood tokens to get an additional action";
|
||||
|
||||
fn absolute_power() -> AdvanceBuilder {
|
||||
AdvanceInfo::builder(
|
||||
Advance::AbsolutePower,
|
||||
"Absolute Power",
|
||||
"Once per turn, as a free action, you may spend 2 mood tokens to get an additional action",
|
||||
)
|
||||
.add_custom_action(AbsolutePower)
|
||||
AdvanceInfo::builder(Advance::AbsolutePower, "Absolute Power", ABSOLUTE_POWER)
|
||||
.add_custom_action(AbsolutePower)
|
||||
}
|
||||
|
||||
pub(crate) fn use_absolute_power() -> Builtin {
|
||||
Builtin::builder("Absolute Power", "")
|
||||
Builtin::builder("Absolute Power", ABSOLUTE_POWER)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.custom_action,
|
||||
0,
|
||||
|
|
@ -101,17 +96,16 @@ pub(crate) fn use_absolute_power() -> Builtin {
|
|||
.build()
|
||||
}
|
||||
|
||||
const FORCED_LABOR: &str = "Once per turn, as a free action, \
|
||||
you may spend 1 mood token to treat your Angry cities as neutral for the rest of the turn";
|
||||
|
||||
fn forced_labor() -> AdvanceBuilder {
|
||||
AdvanceInfo::builder(
|
||||
Advance::ForcedLabor,
|
||||
"Forced Labor",
|
||||
"Once per turn, as a free action, you may spend 1 mood token to treat your Angry cities as neutral for the rest of the turn",
|
||||
)
|
||||
AdvanceInfo::builder(Advance::ForcedLabor, "Forced Labor", FORCED_LABOR)
|
||||
.add_custom_action(ForcedLabor)
|
||||
}
|
||||
|
||||
pub(crate) fn use_forced_labor() -> Builtin {
|
||||
Builtin::builder("Forced Labor", "")
|
||||
Builtin::builder("Forced Labor", FORCED_LABOR)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.custom_action,
|
||||
0,
|
||||
|
|
|
|||
|
|
@ -24,7 +24,7 @@ fn arts() -> AdvanceBuilder {
|
|||
Advance::Arts,
|
||||
"Arts",
|
||||
"Once per turn, as a free action, you may spend \
|
||||
1 culture token to get an influence culture action",
|
||||
1 culture token to get an influence culture action",
|
||||
)
|
||||
.with_advance_bonus(CultureToken)
|
||||
.with_unlocked_building(Obelisk)
|
||||
|
|
@ -100,7 +100,7 @@ pub(crate) fn use_sports() -> Builtin {
|
|||
0,
|
||||
|game, player_index, a| {
|
||||
let p = game.player(player_index);
|
||||
let options = sports_options(p, p.get_city(a.city.expect("city not found")))
|
||||
let options = sports_options(p, p.get_city(a.action.city.expect("city not found")))
|
||||
.expect("Invalid options for sports");
|
||||
Some(vec![PaymentRequest::mandatory(
|
||||
options,
|
||||
|
|
@ -108,7 +108,7 @@ pub(crate) fn use_sports() -> Builtin {
|
|||
)])
|
||||
},
|
||||
|game, s, a| {
|
||||
let position = a.city.expect("city not found");
|
||||
let position = a.action.city.expect("city not found");
|
||||
let pile = s.choice[0].clone();
|
||||
let steps = pile.amount();
|
||||
increase_happiness(
|
||||
|
|
@ -116,8 +116,9 @@ pub(crate) fn use_sports() -> Builtin {
|
|||
s.player_index,
|
||||
&[(position, steps)],
|
||||
None,
|
||||
&a.action.playing_action_type(),
|
||||
);
|
||||
&a.action.action.playing_action_type(),
|
||||
)
|
||||
.expect("Failed to increase happiness");
|
||||
game.add_info_log_item(&format!(
|
||||
"{} paid {pile} for Sports to increase the happiness of {position} \
|
||||
by {steps} steps, making it {}",
|
||||
|
|
|
|||
|
|
@ -28,7 +28,7 @@ fn voting() -> AdvanceBuilder {
|
|||
AdvanceInfo::builder(
|
||||
Advance::Voting,
|
||||
"Voting",
|
||||
"As a free action, you may spend 1 mood token to gain an action 'Increase happiness'",
|
||||
"As a free action, you may spend 1 mood token to use 'Increase happiness'",
|
||||
)
|
||||
.add_custom_action(VotingIncreaseHappiness)
|
||||
}
|
||||
|
|
@ -52,18 +52,16 @@ fn separation_of_power() -> AdvanceBuilder {
|
|||
)
|
||||
}
|
||||
|
||||
const CIVIL_LIBERTIES: &str = "As an action, you may gain 3 mood tokens. \
|
||||
The cost of Draft is increased to 2 mood token";
|
||||
|
||||
fn civil_liberties() -> AdvanceBuilder {
|
||||
AdvanceInfo::builder(
|
||||
Advance::CivilLiberties,
|
||||
"Civil Liberties",
|
||||
"As an action, you may gain 3 mood tokens. \
|
||||
The cost of Draft is increased to 2 mood token",
|
||||
)
|
||||
.add_custom_action(CivilLiberties)
|
||||
AdvanceInfo::builder(Advance::CivilLiberties, "Civil Liberties", CIVIL_LIBERTIES)
|
||||
.add_custom_action(CivilLiberties)
|
||||
}
|
||||
|
||||
pub(crate) fn use_civil_liberties() -> Builtin {
|
||||
Builtin::builder("Civil Liberties", "")
|
||||
Builtin::builder("Civil Liberties", CIVIL_LIBERTIES)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.custom_action,
|
||||
0,
|
||||
|
|
@ -84,7 +82,7 @@ fn free_economy() -> AdvanceBuilder {
|
|||
Advance::FreeEconomy,
|
||||
"Free Economy",
|
||||
"As a free action, you may spend 1 mood token to collect \
|
||||
resources in one city. This must be your only collect action this turn",
|
||||
resources in one city. This must be your only collect action this turn",
|
||||
)
|
||||
.add_custom_action(FreeEconomyCollect)
|
||||
.add_transient_event_listener(
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::ability_initializer::AbilityInitializerSetup;
|
|||
use crate::action_card::discard_action_card;
|
||||
use crate::advance::Bonus::{CultureToken, MoodToken};
|
||||
use crate::advance::{Advance, AdvanceBuilder, AdvanceInfo};
|
||||
use crate::card::HandCard;
|
||||
use crate::card::{HandCard, all_action_hand_cards};
|
||||
use crate::city_pieces::Building::Market;
|
||||
use crate::content::advances::trade_routes::{TradeRoute, trade_route_log, trade_route_reward};
|
||||
use crate::content::advances::{AdvanceGroup, advance_group_builder};
|
||||
|
|
@ -50,15 +50,8 @@ pub(crate) fn use_bartering() -> Builtin {
|
|||
|event| &mut event.custom_action,
|
||||
1,
|
||||
|game, player_index, _| {
|
||||
let cards = game
|
||||
.player(player_index)
|
||||
.action_cards
|
||||
.iter()
|
||||
.map(|a| HandCard::ActionCard(*a))
|
||||
.collect_vec();
|
||||
|
||||
Some(HandCardsRequest::new(
|
||||
cards,
|
||||
all_action_hand_cards(game.player(player_index)),
|
||||
1..=1,
|
||||
"Select an action card to discard",
|
||||
))
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@ fn state_religion() -> AdvanceBuilder {
|
|||
)
|
||||
.with_advance_bonus(MoodToken)
|
||||
.add_transient_event_listener(
|
||||
|event| &mut event.construct_cost,
|
||||
|event| &mut event.building_cost,
|
||||
0,
|
||||
|i, &b, _| {
|
||||
if matches!(b, Temple) {
|
||||
|
|
|
|||
|
|
@ -1,10 +1,9 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::advance::{Advance, AdvanceBuilder, AdvanceInfo};
|
||||
use crate::city_pieces::Building::Temple;
|
||||
use crate::consts::STACK_LIMIT;
|
||||
use crate::content::advances::{AdvanceGroup, advance_group_builder};
|
||||
use crate::content::persistent_events::{AdvanceRequest, PositionRequest};
|
||||
use crate::player::{Player, add_unit, gain_resources};
|
||||
use crate::player::{Player, add_unit, can_add_army_unit, gain_resources};
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::unit::UnitType;
|
||||
|
|
@ -187,13 +186,7 @@ pub(crate) fn cities_that_can_add_units(p: &Player) -> Vec<Position> {
|
|||
let choices: Vec<Position> = p
|
||||
.cities
|
||||
.iter()
|
||||
.filter(|c| {
|
||||
p.get_units(c.position)
|
||||
.iter()
|
||||
.filter(|u| u.unit_type.is_army_unit())
|
||||
.count()
|
||||
< STACK_LIMIT
|
||||
})
|
||||
.filter(|c| can_add_army_unit(p, c.position))
|
||||
.map(|c| c.position)
|
||||
.collect();
|
||||
choices
|
||||
|
|
|
|||
|
|
@ -1,133 +1,63 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::advance::Advance;
|
||||
use crate::map::Terrain;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::special_advance::SpecialAdvance;
|
||||
use crate::{civilization::Civilization, leader::Leader};
|
||||
pub(crate) mod maya;
|
||||
pub(crate) mod rome;
|
||||
|
||||
use crate::civilization::Civilization;
|
||||
use crate::leader::{Leader, LeaderAbility};
|
||||
|
||||
pub const BARBARIANS: &str = "Barbarians";
|
||||
pub const PIRATES: &str = "Pirates";
|
||||
|
||||
#[must_use]
|
||||
pub fn get_all() -> Vec<Civilization> {
|
||||
pub fn get_all_uncached() -> Vec<Civilization> {
|
||||
vec![
|
||||
Civilization::new(BARBARIANS, vec![], vec![]),
|
||||
Civilization::new(PIRATES, vec![], vec![]),
|
||||
rome::rome(),
|
||||
// not finished yet: maya
|
||||
// until the real civilizations are implemented
|
||||
Civilization::new(
|
||||
"Federation",
|
||||
vec![],
|
||||
vec![
|
||||
Leader::builder("James T. Kirk", "", "", "", "").build(),
|
||||
Leader::builder("Kathryn Janeway", "", "", "", "").build(),
|
||||
Leader::builder("Spock", "", "", "", "").build(),
|
||||
test_leader("James T. Kirk"),
|
||||
test_leader("Kathryn Janeway"),
|
||||
test_leader("Spock"),
|
||||
],
|
||||
),
|
||||
Civilization::new(
|
||||
"Borg",
|
||||
vec![],
|
||||
vec![
|
||||
Leader::builder("Borg Queen", "", "", "", "").build(),
|
||||
Leader::builder("Seven of Nine", "", "", "", "").build(),
|
||||
Leader::builder("Jean Luc Picard", "", "", "", "").build(),
|
||||
test_leader("Borg Queen"),
|
||||
test_leader("Seven of Nine"),
|
||||
test_leader("Jean Luc Picard"),
|
||||
],
|
||||
),
|
||||
Civilization::new(
|
||||
"Klingons",
|
||||
vec![],
|
||||
vec![
|
||||
Leader::builder("Khan", "", "", "", "").build(),
|
||||
Leader::builder("Kahless", "", "", "", "").build(),
|
||||
Leader::builder("Worf", "", "", "", "").build(),
|
||||
test_leader("Khan"),
|
||||
test_leader("Kahless"),
|
||||
test_leader("Worf"),
|
||||
],
|
||||
),
|
||||
Civilization::new(
|
||||
"Romulans",
|
||||
vec![],
|
||||
vec![
|
||||
Leader::builder("Sela", "", "", "", "").build(),
|
||||
Leader::builder("Narek", "", "", "", "").build(),
|
||||
Leader::builder("Tomalak", "", "", "", "").build(),
|
||||
test_leader("Sela"),
|
||||
test_leader("Narek"),
|
||||
test_leader("Tomalak"),
|
||||
],
|
||||
),
|
||||
]
|
||||
}
|
||||
|
||||
fn maya() -> Civilization {
|
||||
Civilization::new(
|
||||
"Maya",
|
||||
vec![
|
||||
// todo add other effects
|
||||
SpecialAdvance::builder(Advance::Terrace, "Terrace", Advance::Irrigation)
|
||||
.add_transient_event_listener(
|
||||
|events| &mut events.terrain_collect_options,
|
||||
2,
|
||||
|m, (), ()| {
|
||||
m.insert(
|
||||
Terrain::Mountain,
|
||||
std::collections::HashSet::from([
|
||||
ResourcePile::food(1),
|
||||
ResourcePile::wood(1),
|
||||
ResourcePile::ore(1),
|
||||
]),
|
||||
);
|
||||
},
|
||||
)
|
||||
.build(),
|
||||
],
|
||||
vec![
|
||||
Leader::builder(
|
||||
"Kʼinich Janaab Pakal I",
|
||||
"Shield of the sun",
|
||||
"ignore the first hit in a battle with an Obelisk",
|
||||
"",
|
||||
"",
|
||||
)
|
||||
.add_combat_round_start_listener(4, |game, c, s, _role| {
|
||||
if c.first_round()
|
||||
&& game
|
||||
.try_get_any_city(c.defender_position())
|
||||
.is_some_and(|city| city.pieces.obelisk.is_some())
|
||||
{
|
||||
s.roll_log.push(
|
||||
"Kʼinich Janaab Pakal I ignores the first hit in a battle with an Obelisk"
|
||||
.to_string(),
|
||||
);
|
||||
s.hit_cancels += 1;
|
||||
}
|
||||
})
|
||||
.build(),
|
||||
],
|
||||
fn test_leader(name: &str) -> Leader {
|
||||
Leader::new(
|
||||
name,
|
||||
LeaderAbility::builder("", "").build(),
|
||||
LeaderAbility::builder("", "").build(),
|
||||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_civilization(name: &str) -> Option<Civilization> {
|
||||
match name {
|
||||
"Maya" => Some(maya()), // still needs to be implemented
|
||||
// for integration testing
|
||||
"test0" => Some(Civilization::new(
|
||||
"test0",
|
||||
vec![],
|
||||
vec![
|
||||
Leader::builder("Alexander", "", "", "", "").build(),
|
||||
Leader::builder("Kleopatra", "", "", "", "").build(),
|
||||
],
|
||||
)), // for testing
|
||||
"test1" => Some(Civilization::new("test1", vec![], vec![])),
|
||||
"test2" => Some(Civilization::new("test2", vec![], vec![])),
|
||||
_ => get_all()
|
||||
.into_iter()
|
||||
.find(|civilization| civilization.name == name),
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
pub mod tests {
|
||||
use crate::civilization::Civilization;
|
||||
|
||||
#[must_use]
|
||||
pub fn get_test_civilization() -> Civilization {
|
||||
Civilization::new("test", vec![], vec![])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
60
server/src/content/civilizations/maya.rs
Normal file
60
server/src/content/civilizations/maya.rs
Normal file
|
|
@ -0,0 +1,60 @@
|
|||
// use crate::ability_initializer::AbilityInitializerSetup;
|
||||
// use crate::advance::Advance;
|
||||
// use crate::civilization::Civilization;
|
||||
// use crate::leader::Leader;
|
||||
// use crate::map::Terrain;
|
||||
// use crate::resource_pile::ResourcePile;
|
||||
// use crate::special_advance::{SpecialAdvance, SpecialAdvanceInfo};
|
||||
//
|
||||
// pub(crate) fn maya() -> Civilization {
|
||||
// Civilization::new(
|
||||
// "Maya",
|
||||
// vec![
|
||||
// // todo add other effects
|
||||
// SpecialAdvanceInfo::builder(
|
||||
// SpecialAdvance::Terrace,
|
||||
// Advance::Irrigation,
|
||||
// "Terrace",
|
||||
// "todo",
|
||||
// )
|
||||
// .add_transient_event_listener(
|
||||
// |events| &mut events.terrain_collect_options,
|
||||
// 2,
|
||||
// |m, (), ()| {
|
||||
// m.insert(
|
||||
// Terrain::Mountain,
|
||||
// std::collections::HashSet::from([
|
||||
// ResourcePile::food(1),
|
||||
// ResourcePile::wood(1),
|
||||
// ResourcePile::ore(1),
|
||||
// ]),
|
||||
// );
|
||||
// },
|
||||
// )
|
||||
// .build(),
|
||||
// ],
|
||||
// vec![
|
||||
// Leader::builder(
|
||||
// "Kʼinich Janaab Pakal I",
|
||||
// "Shield of the sun",
|
||||
// "ignore the first hit in a battle with an Obelisk",
|
||||
// "",
|
||||
// "",
|
||||
// )
|
||||
// .add_combat_round_start_listener(4, |game, c, s, _role| {
|
||||
// if c.first_round()
|
||||
// && game
|
||||
// .try_get_any_city(c.defender_position())
|
||||
// .is_some_and(|city| city.pieces.obelisk.is_some())
|
||||
// {
|
||||
// s.roll_log.push(
|
||||
// "Kʼinich Janaab Pakal I ignores the first hit in a battle with an Obelisk"
|
||||
// .to_string(),
|
||||
// );
|
||||
// s.hit_cancels += 1;
|
||||
// }
|
||||
// })
|
||||
// .build(),
|
||||
// ],
|
||||
// )
|
||||
// }
|
||||
412
server/src/content/civilizations/rome.rs
Normal file
412
server/src/content/civilizations/rome.rs
Normal file
|
|
@ -0,0 +1,412 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action_card::{discard_action_card, gain_action_card_from_pile};
|
||||
use crate::advance::{Advance, gain_advance_without_payment};
|
||||
use crate::card::{HandCard, all_action_hand_cards, all_objective_hand_cards};
|
||||
use crate::city::MoodState;
|
||||
use crate::civilization::Civilization;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_actions::CustomActionType;
|
||||
use crate::content::persistent_events::{HandCardsRequest, PaymentRequest, PositionRequest};
|
||||
use crate::game::Game;
|
||||
use crate::leader::{Leader, LeaderAbility, LeaderAbilityBuilder, leader_position};
|
||||
use crate::map::{block_for_position, block_has_player_city};
|
||||
use crate::objective_card::{discard_objective_card, gain_objective_card_from_pile};
|
||||
use crate::payment::{
|
||||
PaymentConversion, PaymentConversionType, PaymentOptions, PaymentReason, base_resources,
|
||||
};
|
||||
use crate::player::{add_unit, can_add_army_unit, gain_resources};
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::special_advance::{SpecialAdvance, SpecialAdvanceInfo, SpecialAdvanceRequirement};
|
||||
use crate::unit::UnitType;
|
||||
use crate::utils::remove_element;
|
||||
use itertools::Itertools;
|
||||
|
||||
pub(crate) fn rome() -> Civilization {
|
||||
Civilization::new(
|
||||
"Rome",
|
||||
vec![aqueduct(), roman_roads(), captivi(), provinces()],
|
||||
vec![augustus(), ceasar(), sulla()],
|
||||
)
|
||||
}
|
||||
|
||||
fn aqueduct() -> SpecialAdvanceInfo {
|
||||
SpecialAdvanceInfo::builder(
|
||||
SpecialAdvance::Aqueduct,
|
||||
SpecialAdvanceRequirement::Advance(Advance::Engineering),
|
||||
"Aqueduct",
|
||||
"Ignore Famine events. \
|
||||
Sanitation cost is reduced to 0 resources or a free action",
|
||||
)
|
||||
.add_custom_action(CustomActionType::Aqueduct)
|
||||
.add_transient_event_listener(
|
||||
|event| &mut event.advance_cost,
|
||||
3,
|
||||
|i, &a, _| {
|
||||
if a == Advance::Sanitation {
|
||||
i.set_zero();
|
||||
i.info
|
||||
.log
|
||||
.push("Aqueduct reduced the cost to 0".to_string());
|
||||
}
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn use_aqueduct() -> Builtin {
|
||||
Builtin::builder("Aqueduct", "Gain Sanitation as a free action")
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.custom_action,
|
||||
0,
|
||||
|game, player, name, a| {
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} uses Aqueduct to gain Sanitation as a free action",
|
||||
));
|
||||
gain_advance_without_payment(
|
||||
game,
|
||||
Advance::Sanitation,
|
||||
player,
|
||||
a.payment.clone(),
|
||||
true,
|
||||
);
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn roman_roads() -> SpecialAdvanceInfo {
|
||||
SpecialAdvanceInfo::builder(
|
||||
SpecialAdvance::RomanRoads,
|
||||
SpecialAdvanceRequirement::Advance(Advance::Roads),
|
||||
"Roman Roads",
|
||||
"Roads distance is increased to 4 if travelling between your cities",
|
||||
)
|
||||
// is checked explicitly
|
||||
.build()
|
||||
}
|
||||
|
||||
fn captivi() -> SpecialAdvanceInfo {
|
||||
SpecialAdvanceInfo::builder(
|
||||
SpecialAdvance::Captivi,
|
||||
SpecialAdvanceRequirement::Advance(Advance::Bartering),
|
||||
"Captivi",
|
||||
"Gain 1 gold and 1 mood token when you win a battle. \
|
||||
You may replace any resources with mood tokens when paying for buildings.",
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.combat_end,
|
||||
20,
|
||||
|game, player, _, s| {
|
||||
if s.is_winner(player) && s.is_battle() {
|
||||
gain_resources(
|
||||
game,
|
||||
player,
|
||||
ResourcePile::gold(1) + ResourcePile::mood_tokens(1),
|
||||
|name, pile| format!("{name} gained {pile} for Captivi"),
|
||||
);
|
||||
}
|
||||
},
|
||||
)
|
||||
.add_transient_event_listener(
|
||||
|event| &mut event.building_cost,
|
||||
2,
|
||||
|i, _b, _| {
|
||||
i.cost.conversions.push(PaymentConversion::new(
|
||||
base_resources(),
|
||||
ResourcePile::mood_tokens(1),
|
||||
PaymentConversionType::Unlimited,
|
||||
));
|
||||
i.info
|
||||
.log
|
||||
.push("Captivi allows to replace resources with mood tokens".to_string());
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn provinces() -> SpecialAdvanceInfo {
|
||||
SpecialAdvanceInfo::builder(
|
||||
SpecialAdvance::Provinces,
|
||||
SpecialAdvanceRequirement::AnyGovernment,
|
||||
"Provinces",
|
||||
"You can recruit Cavalry units in any city \
|
||||
that is at least 3 spaces away from your capital. \
|
||||
Captured cities become Neutral instead of Angry - or Happy if you pay 1 culture token.",
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|event| &mut event.combat_end,
|
||||
21,
|
||||
|game, player, s| {
|
||||
s.captured_city(player, game)
|
||||
.then_some(vec![PaymentRequest::optional(
|
||||
PaymentOptions::resources(
|
||||
game.player(player),
|
||||
PaymentReason::AdvanceAbility,
|
||||
ResourcePile::culture_tokens(1),
|
||||
),
|
||||
"Pay 1 culture token to make the city happy",
|
||||
)])
|
||||
},
|
||||
|game, c, s| {
|
||||
let pile = &c.choice[0];
|
||||
if pile.is_empty() {
|
||||
game.add_info_log_item("Provinces made the city Neutral instead of Angry");
|
||||
} else {
|
||||
game.add_info_log_item(&format!(
|
||||
"Provinces made the city Happy instead of Angry for {pile}"
|
||||
));
|
||||
}
|
||||
|
||||
game.player_mut(s.attacker.player)
|
||||
.get_city_mut(s.defender.position)
|
||||
.set_mood_state(if pile.is_empty() {
|
||||
MoodState::Neutral
|
||||
} else {
|
||||
MoodState::Happy
|
||||
});
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn augustus() -> Leader {
|
||||
Leader::new(
|
||||
"Augustus",
|
||||
LeaderAbility::builder("Princeps", PRINCEPS)
|
||||
.add_custom_action(CustomActionType::Princeps)
|
||||
.build(),
|
||||
LeaderAbility::builder(
|
||||
"Imperator",
|
||||
"If you don't own a city in the region: \
|
||||
Gain 2 combat value in every combat round",
|
||||
)
|
||||
.add_combat_round_start_listener(6, |game, c, s, r| {
|
||||
if c.has_leader(r, game)
|
||||
&& !block_has_player_city(
|
||||
game,
|
||||
&block_for_position(game, c.defender_position()),
|
||||
c.player(r),
|
||||
)
|
||||
{
|
||||
s.extra_combat_value += 2;
|
||||
s.roll_log.push("Imperator adds 2 combat value".to_string());
|
||||
}
|
||||
})
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
|
||||
const PRINCEPS: &str = "As an action, pay 1 culture token and \
|
||||
activate the city where Augustus is: \
|
||||
Draw 1 action and 1 objective card. \
|
||||
Then discard 1 action and 1 objective card.";
|
||||
|
||||
pub(crate) fn use_princeps() -> Builtin {
|
||||
Builtin::builder("Princeps", PRINCEPS)
|
||||
.add_hand_card_request(
|
||||
|event| &mut event.custom_action,
|
||||
0,
|
||||
|game, player, _| {
|
||||
let p = game.player_mut(player);
|
||||
let position = leader_position(p);
|
||||
p.get_city_mut(position).activate();
|
||||
game.add_info_log_item(&format!(
|
||||
"{} activates the city {position} \
|
||||
to draw 1 action and 1 objective card using Princeps",
|
||||
game.player_name(player)
|
||||
));
|
||||
gain_action_card_from_pile(game, player);
|
||||
gain_objective_card_from_pile(game, player);
|
||||
|
||||
let p = game.player(player);
|
||||
Some(HandCardsRequest::new(
|
||||
all_action_hand_cards(p)
|
||||
.into_iter()
|
||||
.chain(all_objective_hand_cards(p))
|
||||
.collect_vec(),
|
||||
2..=2,
|
||||
"Select 1 action and 1 objective card from your hand",
|
||||
))
|
||||
},
|
||||
|game, s, _| {
|
||||
let p = s.player_index;
|
||||
for c in &s.choice {
|
||||
match c {
|
||||
HandCard::ActionCard(card) => {
|
||||
game.add_info_log_item(&format!(
|
||||
"{} discarded action card {} for Princeps",
|
||||
s.player_name,
|
||||
game.cache.get_action_card(*card).name()
|
||||
));
|
||||
discard_action_card(game, p, *card);
|
||||
}
|
||||
HandCard::ObjectiveCard(card) => {
|
||||
game.add_info_log_item(&format!(
|
||||
"{} discarded objective card {} for Princeps",
|
||||
s.player_name,
|
||||
game.cache.get_objective_card(*card).name()
|
||||
));
|
||||
discard_objective_card(game, p, *card);
|
||||
}
|
||||
HandCard::Wonder(_) => panic!("Invalid hand card type"),
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn validate_princeps_cards(cards: &[HandCard]) -> Result<(), String> {
|
||||
match cards.len() {
|
||||
2 => {
|
||||
if cards
|
||||
.iter()
|
||||
.filter(|c| matches!(c, HandCard::ObjectiveCard(_)))
|
||||
.count()
|
||||
== 1
|
||||
{
|
||||
Ok(())
|
||||
} else {
|
||||
Err("must select 1 action and 1 objective card from your hand".to_string())
|
||||
}
|
||||
}
|
||||
_ => Err("must select 2 cards".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
fn ceasar() -> Leader {
|
||||
Leader::new(
|
||||
"Gaius Julius Caesar",
|
||||
LeaderAbility::builder(
|
||||
"Statesman",
|
||||
"As a free action, you may use 'Increase happiness' \
|
||||
to increase happiness in the city where Caesar is.",
|
||||
)
|
||||
.add_custom_action(CustomActionType::StatesmanIncreaseHappiness)
|
||||
.build(),
|
||||
LeaderAbility::builder(
|
||||
"Proconsul",
|
||||
"When capturing a city, you may spend 1 gold to gain 1 infantry",
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|event| &mut event.combat_end,
|
||||
22,
|
||||
|game, player, s| {
|
||||
let p = game.player(player);
|
||||
if p.available_units().infantry == 0 || !can_add_army_unit(p, leader_position(p)) {
|
||||
return None;
|
||||
}
|
||||
s.captured_city(player, game)
|
||||
.then_some(vec![PaymentRequest::optional(
|
||||
PaymentOptions::resources(
|
||||
p,
|
||||
PaymentReason::LeaderAbility,
|
||||
ResourcePile::gold(1),
|
||||
),
|
||||
"Pay 1 gold to gain 1 infantry",
|
||||
)])
|
||||
},
|
||||
|game, c, _| {
|
||||
if !c.choice.is_empty() {
|
||||
let p = c.player_index;
|
||||
let position = leader_position(game.player(p));
|
||||
add_unit(p, position, UnitType::Infantry, game);
|
||||
game.add_info_log_item(&format!(
|
||||
"{} used Proconsul to gain 1 infantry in {position} for {}",
|
||||
game.player_name(p),
|
||||
c.choice[0]
|
||||
));
|
||||
}
|
||||
},
|
||||
)
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
|
||||
fn sulla() -> Leader {
|
||||
Leader::new(
|
||||
"Sulla",
|
||||
add_barbarian_control(
|
||||
LeaderAbility::builder(
|
||||
"Dictator",
|
||||
"The city where Sulla is may not be the target of influence culture attempts.\
|
||||
Barbarians within 2 spaces of Sulla may only move if you agree to it.",
|
||||
)
|
||||
.add_transient_event_listener(
|
||||
|event| &mut event.on_influence_culture_attempt,
|
||||
6,
|
||||
|r, city, game| {
|
||||
if let Ok(info) = r {
|
||||
if info.is_defender
|
||||
&& leader_position(game.player(city.player_index)) == city.position
|
||||
{
|
||||
*r = Err("Sulla prevents influence culture attempts in this city"
|
||||
.to_string());
|
||||
}
|
||||
}
|
||||
},
|
||||
),
|
||||
)
|
||||
.build(),
|
||||
LeaderAbility::builder(
|
||||
"Civilizer",
|
||||
"In every combat round against barbarians: Gain 2 combat value",
|
||||
)
|
||||
.add_combat_round_start_listener(5, |game, c, s, r| {
|
||||
if c.has_leader(r, game) && c.is_barbarian_battle(r, game) {
|
||||
s.extra_combat_value += 2;
|
||||
s.roll_log.push("Sulla adds 2 combat value".to_string());
|
||||
}
|
||||
})
|
||||
.build(),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn owner_of_sulla_in_range(position: Position, game: &Game) -> Option<usize> {
|
||||
// Check if Sulla is within 2 spaces of the given position
|
||||
game.players.iter().find_map(|p| {
|
||||
p.active_leader
|
||||
.as_ref()
|
||||
.is_some_and(|l| l == "Sulla" && leader_position(p).distance(position) <= 2)
|
||||
.then_some(p.index)
|
||||
})
|
||||
}
|
||||
|
||||
fn add_barbarian_control(builder: LeaderAbilityBuilder) -> LeaderAbilityBuilder {
|
||||
builder.add_position_request(
|
||||
|event| &mut event.stop_barbarian_movement,
|
||||
0,
|
||||
|game, _player_index, movable| {
|
||||
let units = movable
|
||||
.clone()
|
||||
.into_iter()
|
||||
.filter(|&pos| owner_of_sulla_in_range(pos, game).is_some())
|
||||
.collect_vec();
|
||||
if units.is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(PositionRequest::new(
|
||||
units.clone(),
|
||||
0..=units.len() as u8,
|
||||
"Select Barbarian Armies that may NOT move",
|
||||
))
|
||||
},
|
||||
|game, s, movable| {
|
||||
let may_not_move = &s.choice;
|
||||
game.add_info_log_item(&format!(
|
||||
"{} selected Barbarian Armies that may NOT move: {}",
|
||||
s.player_name,
|
||||
may_not_move
|
||||
.iter()
|
||||
.map(ToString::to_string)
|
||||
.collect_vec()
|
||||
.join(", ")
|
||||
));
|
||||
for pos in may_not_move {
|
||||
remove_element(movable, pos);
|
||||
}
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -1,32 +1,59 @@
|
|||
use crate::city::City;
|
||||
use crate::advance::{Advance, base_advance_cost};
|
||||
use crate::city::{City, MoodState};
|
||||
use crate::content::advances::autocracy::{use_absolute_power, use_forced_labor};
|
||||
use crate::content::advances::culture::{sports_options, use_sports, use_theaters};
|
||||
use crate::content::advances::democracy::use_civil_liberties;
|
||||
use crate::content::advances::economy::{use_bartering, use_taxes};
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::content::wonders::{use_great_library, use_great_lighthouse, use_great_statue};
|
||||
use crate::content::civilizations::rome::{use_aqueduct, use_princeps};
|
||||
use crate::content::persistent_events::{
|
||||
PersistentEventType, TriggerPersistentEventParams, trigger_persistent_event_with_listener,
|
||||
};
|
||||
use crate::content::wonders::{
|
||||
great_lighthouse_city, great_lighthouse_spawns, use_great_library, use_great_lighthouse,
|
||||
use_great_statue,
|
||||
};
|
||||
use crate::leader::leader_position;
|
||||
use crate::player::Player;
|
||||
use crate::playing_actions::PlayingActionType;
|
||||
use crate::playing_actions::{ActionResourceCost, PlayingActionType};
|
||||
use crate::position::Position;
|
||||
use crate::wonder::Wonder;
|
||||
use crate::{game::Game, playing_actions::ActionCost, resource_pile::ResourcePile};
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
use std::fmt::Display;
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
|
||||
pub struct CustomEventAction {
|
||||
pub struct CustomAction {
|
||||
pub action: CustomActionType,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub city: Option<Position>,
|
||||
}
|
||||
|
||||
impl CustomEventAction {
|
||||
impl CustomAction {
|
||||
#[must_use]
|
||||
pub fn new(action: CustomActionType, city: Option<Position>) -> Self {
|
||||
Self { action, city }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
|
||||
pub struct CustomActionActivation {
|
||||
#[serde(flatten)]
|
||||
pub action: CustomAction,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "ResourcePile::is_empty")]
|
||||
pub payment: ResourcePile,
|
||||
}
|
||||
|
||||
impl CustomActionActivation {
|
||||
#[must_use]
|
||||
pub fn new(action: CustomAction, payment: ResourcePile) -> Self {
|
||||
Self { action, payment }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct CustomActionInfo {
|
||||
pub action_type: ActionCost,
|
||||
|
|
@ -35,7 +62,7 @@ pub struct CustomActionInfo {
|
|||
|
||||
impl CustomActionInfo {
|
||||
#[must_use]
|
||||
fn new(free: bool, once_per_turn: bool, cost: ResourcePile) -> CustomActionInfo {
|
||||
fn new(free: bool, once_per_turn: bool, cost: ActionResourceCost) -> CustomActionInfo {
|
||||
CustomActionInfo {
|
||||
action_type: ActionCost::new(free, cost),
|
||||
once_per_turn,
|
||||
|
|
@ -43,8 +70,9 @@ impl CustomActionInfo {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Hash, Debug)]
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Copy, Hash, Debug)]
|
||||
pub enum CustomActionType {
|
||||
// Advances
|
||||
AbsolutePower,
|
||||
ForcedLabor,
|
||||
CivilLiberties,
|
||||
|
|
@ -55,9 +83,17 @@ pub enum CustomActionType {
|
|||
Sports,
|
||||
Taxes,
|
||||
Theaters,
|
||||
|
||||
// Wonders
|
||||
GreatLibrary,
|
||||
GreatLighthouse,
|
||||
GreatStatue,
|
||||
|
||||
// Civilizations,
|
||||
// Rome
|
||||
Aqueduct,
|
||||
Princeps,
|
||||
StatesmanIncreaseHappiness,
|
||||
}
|
||||
|
||||
impl CustomActionType {
|
||||
|
|
@ -70,7 +106,9 @@ impl CustomActionType {
|
|||
CustomActionType::CivilLiberties | CustomActionType::Sports => {
|
||||
CustomActionType::regular()
|
||||
}
|
||||
CustomActionType::GreatLighthouse => CustomActionType::free(ResourcePile::empty()),
|
||||
CustomActionType::GreatLighthouse | CustomActionType::StatesmanIncreaseHappiness => {
|
||||
CustomActionType::free(ResourcePile::empty())
|
||||
}
|
||||
CustomActionType::Bartering
|
||||
| CustomActionType::Theaters
|
||||
| CustomActionType::GreatLibrary
|
||||
|
|
@ -83,12 +121,16 @@ impl CustomActionType {
|
|||
CustomActionType::VotingIncreaseHappiness => {
|
||||
CustomActionType::cost(ResourcePile::mood_tokens(1))
|
||||
}
|
||||
CustomActionType::Princeps => CustomActionType::cost(ResourcePile::culture_tokens(1)),
|
||||
CustomActionType::FreeEconomyCollect | CustomActionType::ForcedLabor => {
|
||||
CustomActionType::free_and_once_per_turn(ResourcePile::mood_tokens(1))
|
||||
}
|
||||
CustomActionType::Taxes => {
|
||||
CustomActionType::once_per_turn(ResourcePile::mood_tokens(1))
|
||||
}
|
||||
CustomActionType::Aqueduct => {
|
||||
CustomActionType::free_and_advance_cost_without_discounts()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -116,32 +158,48 @@ impl CustomActionType {
|
|||
|
||||
#[must_use]
|
||||
pub fn playing_action_type(&self) -> PlayingActionType {
|
||||
PlayingActionType::Custom(self.clone())
|
||||
PlayingActionType::Custom(*self)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn regular() -> CustomActionInfo {
|
||||
CustomActionInfo::new(false, false, ResourcePile::empty())
|
||||
CustomActionInfo::new(false, false, ActionResourceCost::free())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn cost(cost: ResourcePile) -> CustomActionInfo {
|
||||
CustomActionInfo::new(true, false, cost)
|
||||
CustomActionInfo::new(true, false, ActionResourceCost::resources(cost))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn once_per_turn(cost: ResourcePile) -> CustomActionInfo {
|
||||
CustomActionInfo::new(false, true, cost)
|
||||
CustomActionInfo::new(false, true, ActionResourceCost::resources(cost))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn free(cost: ResourcePile) -> CustomActionInfo {
|
||||
CustomActionInfo::new(true, false, cost)
|
||||
CustomActionInfo::new(true, false, ActionResourceCost::resources(cost))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn free_and_once_per_turn(cost: ResourcePile) -> CustomActionInfo {
|
||||
CustomActionInfo::new(true, true, cost)
|
||||
CustomActionInfo::new(true, true, ActionResourceCost::resources(cost))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn free_and_advance_cost_without_discounts() -> CustomActionInfo {
|
||||
CustomActionInfo::new(true, false, ActionResourceCost::AdvanceCostWithoutDiscount)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_modifier(&self) -> bool {
|
||||
matches!(
|
||||
self,
|
||||
CustomActionType::ArtsInfluenceCultureAttempt
|
||||
| CustomActionType::FreeEconomyCollect
|
||||
| CustomActionType::VotingIncreaseHappiness
|
||||
| CustomActionType::StatesmanIncreaseHappiness
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -153,18 +211,21 @@ impl Display for CustomActionType {
|
|||
CustomActionType::CivilLiberties => write!(f, "Civil Liberties"),
|
||||
CustomActionType::Bartering => write!(f, "Bartering"),
|
||||
CustomActionType::ArtsInfluenceCultureAttempt => {
|
||||
write!(f, "Arts Influence Culture Attempt")
|
||||
write!(f, "Arts")
|
||||
}
|
||||
CustomActionType::VotingIncreaseHappiness => {
|
||||
write!(f, "Voting Increase Happiness")
|
||||
write!(f, "Voting")
|
||||
}
|
||||
CustomActionType::FreeEconomyCollect => write!(f, "Free Economy Collect"),
|
||||
CustomActionType::FreeEconomyCollect => write!(f, "Free Economy"),
|
||||
CustomActionType::Sports => write!(f, "Sports"),
|
||||
CustomActionType::Taxes => write!(f, "Taxes"),
|
||||
CustomActionType::Theaters => write!(f, "Theaters"),
|
||||
CustomActionType::GreatLibrary => write!(f, "Great Library"),
|
||||
CustomActionType::GreatLighthouse => write!(f, "Great Lighthouse"),
|
||||
CustomActionType::GreatStatue => write!(f, "Great Statue"),
|
||||
CustomActionType::Aqueduct => write!(f, "Aqueduct"),
|
||||
CustomActionType::Princeps => write!(f, "Princeps"),
|
||||
CustomActionType::StatesmanIncreaseHappiness => write!(f, "Statesman"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -181,21 +242,85 @@ pub(crate) fn custom_action_builtins() -> HashMap<CustomActionType, Builtin> {
|
|||
(CustomActionType::GreatLibrary, use_great_library()),
|
||||
(CustomActionType::GreatLighthouse, use_great_lighthouse()),
|
||||
(CustomActionType::GreatStatue, use_great_statue()),
|
||||
(CustomActionType::Aqueduct, use_aqueduct()),
|
||||
(CustomActionType::Princeps, use_princeps()),
|
||||
])
|
||||
}
|
||||
|
||||
pub(crate) fn execute_custom_action(
|
||||
game: &mut Game,
|
||||
player_index: usize,
|
||||
action: CustomEventAction,
|
||||
a: CustomActionActivation,
|
||||
) {
|
||||
let _ = game.trigger_persistent_event_with_listener(
|
||||
let _ = trigger_persistent_event_with_listener(
|
||||
game,
|
||||
&[player_index],
|
||||
|e| &mut e.custom_action,
|
||||
&custom_action_builtins()[&action.action.clone()].listeners,
|
||||
action,
|
||||
&custom_action_builtins()[&a.action.action.clone()].listeners,
|
||||
a,
|
||||
PersistentEventType::CustomAction,
|
||||
None,
|
||||
|_| {},
|
||||
TriggerPersistentEventParams::default(),
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn can_play_custom_action(
|
||||
game: &Game,
|
||||
p: &Player,
|
||||
c: CustomActionType,
|
||||
) -> Result<(), String> {
|
||||
if !p.custom_actions.contains_key(&c) {
|
||||
return Err("Custom action not available".to_string());
|
||||
}
|
||||
|
||||
if c.info().once_per_turn && p.played_once_per_turn_actions.contains(&c) {
|
||||
return Err("Custom action already played this turn".to_string());
|
||||
}
|
||||
|
||||
let can_play = match c {
|
||||
CustomActionType::Bartering => !p.action_cards.is_empty(),
|
||||
CustomActionType::Sports => can_use_sports(p),
|
||||
CustomActionType::Theaters => p.resources.culture_tokens > 0 || p.resources.mood_tokens > 0,
|
||||
CustomActionType::ForcedLabor => any_angry(p),
|
||||
CustomActionType::GreatStatue => !p.objective_cards.is_empty(),
|
||||
CustomActionType::GreatLighthouse => {
|
||||
great_lighthouse_city(p).can_activate()
|
||||
&& p.available_units().ships > 0
|
||||
&& !great_lighthouse_spawns(game, p.index).is_empty()
|
||||
}
|
||||
CustomActionType::Aqueduct => {
|
||||
!p.has_advance(Advance::Sanitation) && p.can_afford(&base_advance_cost(p))
|
||||
}
|
||||
CustomActionType::Princeps => game
|
||||
.try_get_any_city(leader_position(p))
|
||||
.is_some_and(City::can_activate),
|
||||
_ => true,
|
||||
};
|
||||
if !can_play {
|
||||
return Err("Cannot play custom action".to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn can_use_sports(p: &Player) -> bool {
|
||||
if !any_non_happy(p) {
|
||||
return false;
|
||||
}
|
||||
if p.resources.culture_tokens > 0 {
|
||||
return true;
|
||||
}
|
||||
p.wonders_owned.contains(Wonder::Colosseum) && p.resources.mood_tokens > 0
|
||||
}
|
||||
|
||||
fn any_non_happy(player: &Player) -> bool {
|
||||
player
|
||||
.cities
|
||||
.iter()
|
||||
.any(|city| city.mood_state != MoodState::Happy)
|
||||
}
|
||||
|
||||
fn any_angry(player: &Player) -> bool {
|
||||
player
|
||||
.cities
|
||||
.iter()
|
||||
.any(|city| city.mood_state == MoodState::Angry)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,6 +12,7 @@ use crate::player_events::IncidentTarget;
|
|||
use crate::playing_actions::PlayingActionType;
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::special_advance::SpecialAdvance;
|
||||
use crate::unit::kill_units;
|
||||
use itertools::Itertools;
|
||||
use std::vec;
|
||||
|
|
@ -215,6 +216,7 @@ pub(crate) fn famine(
|
|||
let city_pred2 = city_pred.clone();
|
||||
Incident::builder(id, name, description, incident_base_effect)
|
||||
.with_protection_advance(Advance::Irrigation)
|
||||
.with_protection_special_advance(SpecialAdvance::Aqueduct)
|
||||
.add_simple_incident_listener(target, 11, move |game, player_index, player_name, i| {
|
||||
// we lose the food regardless of the outcome
|
||||
let p = game.player(player_index);
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@ pub(crate) fn construct_only() -> Builtin {
|
|||
},
|
||||
)
|
||||
.add_transient_event_listener(
|
||||
|event| &mut event.construct_cost,
|
||||
|event| &mut event.building_cost,
|
||||
1,
|
||||
|c, _, game| {
|
||||
if game
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::content::incidents::great_persons::{
|
|||
use crate::content::persistent_events::{PaymentRequest, PositionRequest};
|
||||
use crate::explore::move_to_unexplored_block;
|
||||
use crate::game::Game;
|
||||
use crate::map::{BlockPosition, UNEXPLORED_BLOCK, get_map_setup};
|
||||
use crate::map::{BlockPosition, block_has_player_city, block_tiles, get_map_setup};
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::Player;
|
||||
use crate::playing_actions::ActionCost;
|
||||
|
|
@ -99,10 +99,10 @@ pub(crate) fn explore_adjacent_block(builder: ActionCardBuilder) -> ActionCardBu
|
|||
.map
|
||||
.unexplored_blocks
|
||||
.iter()
|
||||
.find(|b| tiles(&b.position).iter().any(|p| *p == position))
|
||||
.find(|b| block_tiles(&b.position).contains(&position))
|
||||
.cloned()
|
||||
.expect("Block not found");
|
||||
a.selected_positions = tiles(&dest.position);
|
||||
a.selected_positions = block_tiles(&dest.position);
|
||||
move_to_unexplored_block(game, s.player_index, &dest, &[], position, None);
|
||||
},
|
||||
)
|
||||
|
|
@ -145,7 +145,7 @@ pub(crate) fn action_explore_request(game: &Game, player_index: usize) -> Positi
|
|||
.map(|b| b.position)
|
||||
.filter_map(|b| {
|
||||
free.iter()
|
||||
.any(|p| has_any_city(game, p, player_index) && block_adjacent(&b, p))
|
||||
.any(|p| block_has_player_city(game, p, player_index) && block_adjacent(&b, p))
|
||||
.then_some(b.top_tile)
|
||||
})
|
||||
.collect_vec();
|
||||
|
|
@ -153,21 +153,7 @@ pub(crate) fn action_explore_request(game: &Game, player_index: usize) -> Positi
|
|||
}
|
||||
|
||||
fn block_adjacent(p1: &BlockPosition, p2: &BlockPosition) -> bool {
|
||||
let v1 = tiles(p1);
|
||||
let v2 = tiles(p2);
|
||||
let v1 = block_tiles(p1);
|
||||
let v2 = block_tiles(p2);
|
||||
v1.iter().any(|p| v2.iter().any(|p2| p.is_neighbor(*p2)))
|
||||
}
|
||||
|
||||
fn tiles(p1: &BlockPosition) -> Vec<Position> {
|
||||
UNEXPLORED_BLOCK
|
||||
.tiles(p1, p1.rotation)
|
||||
.into_iter()
|
||||
.map(|(p, _)| p)
|
||||
.collect_vec()
|
||||
}
|
||||
|
||||
fn has_any_city(game: &Game, p: &BlockPosition, player: usize) -> bool {
|
||||
tiles(p)
|
||||
.iter()
|
||||
.any(|p| game.player(player).try_get_city(*p).is_some())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::advance::remove_advance;
|
||||
use crate::advance::undo_unlock_special_advance;
|
||||
use crate::advance::{find_government_special_advance, remove_advance};
|
||||
use crate::combat::{Combat, CombatModifier, CombatRetreatState};
|
||||
use crate::combat_listeners::CombatResult;
|
||||
use crate::content::builtin::Builtin;
|
||||
|
|
@ -173,6 +174,12 @@ fn anarchy() -> Incident {
|
|||
remove_advance(game, a, player_index);
|
||||
}
|
||||
|
||||
if game.player(player_index).government(game).is_some() {
|
||||
if let Some(special_advance) = find_government_special_advance(game, player_index) {
|
||||
undo_unlock_special_advance(game, special_advance, player_index);
|
||||
}
|
||||
}
|
||||
|
||||
let p = game.player_mut(player_index);
|
||||
let lost = old - p.advances.len();
|
||||
p.event_victory_points += lost as f32;
|
||||
|
|
|
|||
|
|
@ -3,10 +3,8 @@ use crate::advance::Advance;
|
|||
use crate::content::advances::warfare::draft_cost;
|
||||
use crate::game::Game;
|
||||
use crate::log::{ActionLogItem, ActionLogPlayer};
|
||||
use crate::map::get_map_setup;
|
||||
use crate::map::home_position;
|
||||
use crate::objective_card::{Objective, objective_is_ready};
|
||||
use crate::player::Player;
|
||||
use crate::position::Position;
|
||||
use itertools::Itertools;
|
||||
|
||||
pub(crate) fn draft() -> Objective {
|
||||
|
|
@ -102,9 +100,3 @@ fn last_round(game: &Game) -> Vec<&ActionLogPlayer> {
|
|||
.flat_map(|r| r.players.iter())
|
||||
.collect_vec()
|
||||
}
|
||||
|
||||
pub(crate) fn home_position(game: &Game, player: &Player) -> Position {
|
||||
let setup = get_map_setup(game.human_players_count());
|
||||
let h = &setup.home_positions[player.index];
|
||||
h.block.tiles(&h.position, h.position.rotation)[0].0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use crate::content::advances::trade_routes::find_trade_routes;
|
||||
use crate::content::objectives::city_objectives::leading_player;
|
||||
use crate::content::objectives::non_combat::{home_position, last_player_round};
|
||||
use crate::content::objectives::non_combat::last_player_round;
|
||||
use crate::map::home_position;
|
||||
use crate::objective_card::Objective;
|
||||
use crate::player::Player;
|
||||
use crate::unit::UnitType;
|
||||
|
|
|
|||
|
|
@ -1,3 +1,4 @@
|
|||
use crate::ability_initializer::AbilityListeners;
|
||||
use crate::action::execute_custom_phase_action;
|
||||
use crate::action_card::ActionCardInfo;
|
||||
use crate::advance::Advance;
|
||||
|
|
@ -8,17 +9,20 @@ use crate::combat::Combat;
|
|||
use crate::combat_listeners::{CombatRoundEnd, CombatRoundStart};
|
||||
use crate::combat_stats::CombatStats;
|
||||
use crate::construct::ConstructInfo;
|
||||
use crate::content::custom_actions::CustomEventAction;
|
||||
use crate::content::custom_actions::CustomActionActivation;
|
||||
use crate::cultural_influence::InfluenceCultureInfo;
|
||||
use crate::events::EventOrigin;
|
||||
use crate::explore::ExploreResolutionState;
|
||||
use crate::game::Game;
|
||||
use crate::map::Rotation;
|
||||
use crate::objective_card::SelectObjectivesInfo;
|
||||
use crate::objective_card::{SelectObjectivesInfo, present_instant_objective_cards};
|
||||
use crate::payment::{PaymentOptions, ResourceReward};
|
||||
use crate::player::Player;
|
||||
use crate::player_events::{IncidentInfo, OnAdvanceInfo};
|
||||
use crate::playing_actions::{PlayingAction, Recruit};
|
||||
use crate::player_events::{
|
||||
IncidentInfo, OnAdvanceInfo, PersistentEvent, PersistentEventInfo, PersistentEvents,
|
||||
trigger_event_with_game_value,
|
||||
};
|
||||
use crate::playing_actions::{ActionPayment, Recruit};
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::status_phase::{ChangeGovernment, StatusPhaseState};
|
||||
|
|
@ -106,17 +110,18 @@ pub enum PersistentEventType {
|
|||
CombatEnd(CombatStats),
|
||||
StatusPhase(StatusPhaseState),
|
||||
TurnStart,
|
||||
PayAction(PlayingAction),
|
||||
PayAction(ActionPayment),
|
||||
Advance(OnAdvanceInfo),
|
||||
Construct(ConstructInfo),
|
||||
Recruit(Recruit),
|
||||
FoundCity(Position),
|
||||
Incident(IncidentInfo),
|
||||
StopBarbarianMovement(Vec<Position>),
|
||||
ActionCard(ActionCardInfo),
|
||||
WonderCard(WonderCardInfo),
|
||||
DrawWonderCard,
|
||||
SelectObjectives(SelectObjectivesInfo),
|
||||
CustomAction(CustomEventAction),
|
||||
CustomAction(CustomActionActivation),
|
||||
ChooseActionCard,
|
||||
ChooseIncident(IncidentInfo),
|
||||
}
|
||||
|
|
@ -125,20 +130,27 @@ pub enum PersistentEventType {
|
|||
pub struct PersistentEventState {
|
||||
pub event_type: PersistentEventType,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub origin_override: Option<EventOrigin>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub players_used: Vec<usize>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub player: PersistentEventPlayer,
|
||||
}
|
||||
|
||||
impl PersistentEventState {
|
||||
#[must_use]
|
||||
pub fn new(current_player: usize, event_type: PersistentEventType) -> Self {
|
||||
pub fn new(
|
||||
current_player: usize,
|
||||
event_type: PersistentEventType,
|
||||
origin_override: Option<EventOrigin>,
|
||||
) -> Self {
|
||||
Self {
|
||||
event_type,
|
||||
players_used: vec![],
|
||||
player: PersistentEventPlayer::new(current_player),
|
||||
origin_override,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -367,3 +379,118 @@ impl EventResponse {
|
|||
execute_custom_phase_action(game, player_index, details)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Debug, Clone)]
|
||||
pub struct TriggerPersistentEventParams<V> {
|
||||
pub log: Option<String>,
|
||||
pub next_player: fn(&mut V) -> (),
|
||||
pub origin_override: Option<EventOrigin>,
|
||||
}
|
||||
|
||||
impl<V> Default for TriggerPersistentEventParams<V> {
|
||||
fn default() -> Self {
|
||||
Self {
|
||||
log: None,
|
||||
next_player: |_| {},
|
||||
origin_override: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fn remaining_persistent_event_players(
|
||||
players: &[usize],
|
||||
state: &PersistentEventState,
|
||||
) -> Vec<usize> {
|
||||
players
|
||||
.iter()
|
||||
.filter(|p| !state.players_used.contains(p))
|
||||
.copied()
|
||||
.collect_vec()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn trigger_persistent_event_ext<V>(
|
||||
game: &mut Game,
|
||||
players: &[usize],
|
||||
event: fn(&mut PersistentEvents) -> &mut PersistentEvent<V>,
|
||||
mut value: V,
|
||||
to_event_type: impl Fn(V) -> PersistentEventType,
|
||||
params: TriggerPersistentEventParams<V>,
|
||||
) -> Option<V>
|
||||
where
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
let current_event_type = to_event_type(value.clone());
|
||||
if game
|
||||
.events
|
||||
.last()
|
||||
.is_none_or(|s| s.event_type != current_event_type)
|
||||
{
|
||||
if let Some(log) = params.log {
|
||||
game.add_info_log_group(log.to_string());
|
||||
}
|
||||
game.events.push(PersistentEventState::new(
|
||||
players[0],
|
||||
current_event_type,
|
||||
params.origin_override,
|
||||
));
|
||||
}
|
||||
|
||||
let event_index = game.events.len() - 1;
|
||||
|
||||
for player_index in remaining_persistent_event_players(players, game.current_event()) {
|
||||
let info = PersistentEventInfo {
|
||||
player: player_index,
|
||||
};
|
||||
trigger_event_with_game_value(
|
||||
game,
|
||||
player_index,
|
||||
move |e| event(&mut e.persistent),
|
||||
&info,
|
||||
&(),
|
||||
&mut value,
|
||||
);
|
||||
|
||||
if game.current_event().player.handler.is_some() {
|
||||
game.events[event_index].event_type = to_event_type(value);
|
||||
return None;
|
||||
}
|
||||
let state = game.current_event_mut();
|
||||
state.players_used.push(player_index);
|
||||
if let Some(&p) = remaining_persistent_event_players(players, state).first() {
|
||||
state.player = PersistentEventPlayer::new(p);
|
||||
(params.next_player)(&mut value);
|
||||
}
|
||||
}
|
||||
game.events.pop();
|
||||
|
||||
if game.events.is_empty() {
|
||||
present_instant_objective_cards(game);
|
||||
}
|
||||
|
||||
Some(value)
|
||||
}
|
||||
|
||||
pub(crate) fn trigger_persistent_event_with_listener<V>(
|
||||
game: &mut Game,
|
||||
players: &[usize],
|
||||
event: fn(&mut PersistentEvents) -> &mut PersistentEvent<V>,
|
||||
listeners: &AbilityListeners,
|
||||
event_type: V,
|
||||
store_type: impl Fn(V) -> PersistentEventType,
|
||||
params: TriggerPersistentEventParams<V>,
|
||||
) -> Option<V>
|
||||
where
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
for p in players {
|
||||
listeners.init(game, *p);
|
||||
}
|
||||
|
||||
let result = trigger_persistent_event_ext(game, players, event, event_type, store_type, params);
|
||||
|
||||
for p in players {
|
||||
listeners.deinit(game, *p);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action_card::do_gain_action_card_from_pile;
|
||||
use crate::advance::Advance;
|
||||
use crate::card::HandCard;
|
||||
use crate::advance::{Advance, init_great_library};
|
||||
use crate::card::{HandCard, all_objective_hand_cards};
|
||||
use crate::city::{City, MoodState};
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_actions::CustomActionType;
|
||||
|
|
@ -95,11 +95,7 @@ pub(crate) fn use_great_statue() -> Builtin {
|
|||
|game, player_index, _| {
|
||||
let player = game.player(player_index);
|
||||
Some(HandCardsRequest::new(
|
||||
player
|
||||
.objective_cards
|
||||
.iter()
|
||||
.map(|&a| HandCard::ObjectiveCard(a))
|
||||
.collect_vec(),
|
||||
all_objective_hand_cards(player),
|
||||
1..=1,
|
||||
"Select an objective card to discard",
|
||||
))
|
||||
|
|
@ -267,59 +263,52 @@ pub(crate) fn use_great_lighthouse() -> Builtin {
|
|||
.build()
|
||||
}
|
||||
|
||||
const GREAT_LIBRARY: &str = "Once per turn, as a free action, \
|
||||
you may choose a non-government, non-civilization advance: \
|
||||
Use the effect until the end of your turn.";
|
||||
|
||||
fn library() -> WonderInfo {
|
||||
WonderInfo::builder(
|
||||
Wonder::GreatLibrary,
|
||||
"Great Library",
|
||||
"Once per turn, as a free action, \
|
||||
you may choose a non-government, non-civilization advance: \
|
||||
Use the effect until the end of your turn.",
|
||||
GREAT_LIBRARY,
|
||||
PaymentOptions::fixed_resources(ResourcePile::new(3, 6, 3, 0, 0, 0, 5)),
|
||||
Advance::Philosophy,
|
||||
)
|
||||
.add_custom_action(CustomActionType::GreatLibrary)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn use_great_library() -> Builtin {
|
||||
Builtin::builder(
|
||||
"Great Library",
|
||||
"Use the effect of a non-government, non-civilization advance",
|
||||
)
|
||||
.add_advance_request(
|
||||
|event| &mut event.custom_action,
|
||||
0,
|
||||
|game, player_index, _| {
|
||||
let player = game.player(player_index);
|
||||
Some(AdvanceRequest::new(
|
||||
game.cache
|
||||
.get_advances()
|
||||
.iter()
|
||||
.filter_map(
|
||||
// todo special advances
|
||||
|a| {
|
||||
Builtin::builder("Great Library", GREAT_LIBRARY)
|
||||
.add_advance_request(
|
||||
|event| &mut event.custom_action,
|
||||
0,
|
||||
|game, player_index, _| {
|
||||
let player = game.player(player_index);
|
||||
Some(AdvanceRequest::new(
|
||||
game.cache
|
||||
.get_advances()
|
||||
.iter()
|
||||
.filter_map(|a| {
|
||||
(a.government.is_none() && !player.has_advance(a.advance))
|
||||
.then_some(a.advance)
|
||||
},
|
||||
)
|
||||
.collect_vec(),
|
||||
))
|
||||
},
|
||||
|game, s, _| {
|
||||
let advance = s.choice;
|
||||
game.add_info_log_item(&format!(
|
||||
"{} used the Great Library to use {} for the turn",
|
||||
s.player_name,
|
||||
advance.name(game)
|
||||
));
|
||||
advance
|
||||
.info(game)
|
||||
.listeners
|
||||
.clone()
|
||||
.init(game, s.player_index);
|
||||
game.player_mut(s.player_index).great_library_advance = Some(advance);
|
||||
},
|
||||
)
|
||||
.build()
|
||||
})
|
||||
.collect_vec(),
|
||||
))
|
||||
},
|
||||
|game, s, _| {
|
||||
let advance = s.choice;
|
||||
game.add_info_log_item(&format!(
|
||||
"{} used the Great Library to use {} for the turn",
|
||||
s.player_name,
|
||||
advance.name(game)
|
||||
));
|
||||
game.player_mut(s.player_index).great_library_advance = Some(advance);
|
||||
init_great_library(game, s.player_index);
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn great_gardens() -> WonderInfo {
|
||||
|
|
|
|||
|
|
@ -450,7 +450,7 @@ fn affordable_start_city(
|
|||
let mut tokens = available.culture_tokens;
|
||||
if let Some(t) = action_type {
|
||||
// either none or both can use Colosseum
|
||||
let cost = t.cost(game).cost;
|
||||
let cost = t.cost(game).payment_options(player).default;
|
||||
let c = cost.culture_tokens;
|
||||
assert_eq!(c, cost.amount());
|
||||
tokens -= c;
|
||||
|
|
@ -542,6 +542,6 @@ pub fn available_influence_actions(game: &Game, player: usize) -> Vec<PlayingAct
|
|||
game,
|
||||
player,
|
||||
PlayingActionType::InfluenceCultureAttempt,
|
||||
&CustomActionType::ArtsInfluenceCultureAttempt,
|
||||
vec![CustomActionType::ArtsInfluenceCultureAttempt],
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@
|
|||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum EventOrigin {
|
||||
Advance(Advance),
|
||||
SpecialAdvance(Advance),
|
||||
Leader(String),
|
||||
SpecialAdvance(SpecialAdvance),
|
||||
LeaderAbility(String),
|
||||
Wonder(Wonder),
|
||||
Builtin(String),
|
||||
Incident(u8),
|
||||
|
|
@ -17,11 +17,11 @@ impl EventOrigin {
|
|||
#[must_use]
|
||||
pub fn id(&self) -> String {
|
||||
match self {
|
||||
EventOrigin::Wonder(name) => format!("{name:?}"),
|
||||
| EventOrigin::Advance(name)
|
||||
// can't call to_string, because cache is not constructed
|
||||
| EventOrigin::SpecialAdvance(name) => format!("{name:?}"),
|
||||
| EventOrigin::Leader(name)
|
||||
EventOrigin::Wonder(name) => format!("{name:?}"),
|
||||
EventOrigin::Advance(name) => format!("{name:?}"),
|
||||
EventOrigin::SpecialAdvance(name) => format!("{name:?}"),
|
||||
EventOrigin::LeaderAbility(name)
|
||||
| EventOrigin::Objective(name)
|
||||
| EventOrigin::Builtin(name) => name.to_string(),
|
||||
EventOrigin::CivilCard(id)
|
||||
|
|
@ -34,11 +34,10 @@ impl EventOrigin {
|
|||
pub fn name(&self, game: &Game) -> String {
|
||||
let cache = &game.cache;
|
||||
match self {
|
||||
EventOrigin::Advance(name) | EventOrigin::SpecialAdvance(name) => {
|
||||
name.name(game).to_string()
|
||||
}
|
||||
EventOrigin::Advance(name) => name.name(game).to_string(),
|
||||
EventOrigin::SpecialAdvance(name) => name.name(game).to_string(),
|
||||
EventOrigin::Wonder(name) => name.name(game).to_string(),
|
||||
EventOrigin::Leader(name)
|
||||
EventOrigin::LeaderAbility(name)
|
||||
| EventOrigin::Objective(name)
|
||||
| EventOrigin::Builtin(name) => name.to_string(),
|
||||
EventOrigin::CivilCard(id) => cache.get_civil_card(*id).name.clone(),
|
||||
|
|
@ -51,6 +50,7 @@ impl EventOrigin {
|
|||
use crate::advance::Advance;
|
||||
use crate::game::Game;
|
||||
use crate::player::CostTrigger;
|
||||
use crate::special_advance::SpecialAdvance;
|
||||
use crate::wonder::Wonder;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use crate::ability_initializer::AbilityListeners;
|
||||
use crate::cache::Cache;
|
||||
use crate::combat_roll::{COMBAT_DIE_SIDES, CombatDieRoll};
|
||||
use crate::consts::ACTIONS;
|
||||
use crate::content::effects::PermanentEffect;
|
||||
use crate::content::persistent_events::{
|
||||
PersistentEventHandler, PersistentEventPlayer, PersistentEventState, PersistentEventType,
|
||||
PersistentEventHandler, PersistentEventState, PersistentEventType,
|
||||
TriggerPersistentEventParams, trigger_persistent_event_ext,
|
||||
};
|
||||
use crate::events::{Event, EventOrigin};
|
||||
use crate::game_data::GameData;
|
||||
|
|
@ -13,11 +13,10 @@ use crate::log::{
|
|||
current_player_turn_log_mut,
|
||||
};
|
||||
use crate::movement::MoveState;
|
||||
use crate::objective_card::present_instant_objective_cards;
|
||||
use crate::pirates::get_pirates_player;
|
||||
use crate::player::{CostTrigger, end_turn};
|
||||
use crate::player_events::{
|
||||
PersistentEvent, PersistentEventInfo, PersistentEvents, PlayerEvents, TransientEvents,
|
||||
PersistentEvent, PersistentEvents, TransientEvents, trigger_event_with_game_value,
|
||||
};
|
||||
use crate::resource::check_for_waste;
|
||||
use crate::status_phase::enter_status_phase;
|
||||
|
|
@ -208,38 +207,6 @@ impl Game {
|
|||
.and_then(|s| s.player.handler.as_mut())
|
||||
}
|
||||
|
||||
pub(crate) fn trigger_persistent_event_with_listener<V>(
|
||||
&mut self,
|
||||
players: &[usize],
|
||||
event: fn(&mut PersistentEvents) -> &mut PersistentEvent<V>,
|
||||
listeners: &AbilityListeners,
|
||||
event_type: V,
|
||||
store_type: impl Fn(V) -> PersistentEventType,
|
||||
log: Option<&str>,
|
||||
next_player: fn(&mut V) -> (),
|
||||
) -> Option<V>
|
||||
where
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
for p in players {
|
||||
listeners.init(self, *p);
|
||||
}
|
||||
|
||||
let result = self.trigger_persistent_event_ext(
|
||||
players,
|
||||
event,
|
||||
event_type,
|
||||
store_type,
|
||||
log,
|
||||
next_player,
|
||||
);
|
||||
|
||||
for p in players {
|
||||
listeners.deinit(self, *p);
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn trigger_persistent_event<V>(
|
||||
&mut self,
|
||||
|
|
@ -251,79 +218,14 @@ impl Game {
|
|||
where
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.trigger_persistent_event_ext(players, event, value, to_event_type, None, |_| {})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn trigger_persistent_event_ext<V>(
|
||||
&mut self,
|
||||
players: &[usize],
|
||||
event: fn(&mut PersistentEvents) -> &mut PersistentEvent<V>,
|
||||
mut value: V,
|
||||
to_event_type: impl Fn(V) -> PersistentEventType,
|
||||
log: Option<&str>,
|
||||
next_player: fn(&mut V) -> (),
|
||||
) -> Option<V>
|
||||
where
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
let current_event_type = to_event_type(value.clone());
|
||||
if self
|
||||
.events
|
||||
.last()
|
||||
.is_none_or(|s| s.event_type != current_event_type)
|
||||
{
|
||||
if let Some(log) = log {
|
||||
self.add_info_log_group(log.to_string());
|
||||
}
|
||||
self.events
|
||||
.push(PersistentEventState::new(players[0], current_event_type));
|
||||
}
|
||||
|
||||
let event_index = self.events.len() - 1;
|
||||
|
||||
for player_index in Self::remaining_persistent_event_players(players, self.current_event())
|
||||
{
|
||||
let info = PersistentEventInfo {
|
||||
player: player_index,
|
||||
};
|
||||
self.trigger_event_with_game_value(
|
||||
player_index,
|
||||
move |e| event(&mut e.persistent),
|
||||
&info,
|
||||
&(),
|
||||
&mut value,
|
||||
);
|
||||
|
||||
if self.current_event().player.handler.is_some() {
|
||||
self.events[event_index].event_type = to_event_type(value);
|
||||
return None;
|
||||
}
|
||||
let state = self.current_event_mut();
|
||||
state.players_used.push(player_index);
|
||||
if let Some(&p) = Self::remaining_persistent_event_players(players, state).first() {
|
||||
state.player = PersistentEventPlayer::new(p);
|
||||
next_player(&mut value);
|
||||
}
|
||||
}
|
||||
self.events.pop();
|
||||
|
||||
if self.events.is_empty() {
|
||||
present_instant_objective_cards(self);
|
||||
}
|
||||
|
||||
Some(value)
|
||||
}
|
||||
|
||||
fn remaining_persistent_event_players(
|
||||
players: &[usize],
|
||||
state: &PersistentEventState,
|
||||
) -> Vec<usize> {
|
||||
players
|
||||
.iter()
|
||||
.filter(|p| !state.players_used.contains(p))
|
||||
.copied()
|
||||
.collect_vec()
|
||||
trigger_persistent_event_ext(
|
||||
self,
|
||||
players,
|
||||
event,
|
||||
value,
|
||||
to_event_type,
|
||||
TriggerPersistentEventParams::default(),
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn trigger_transient_event_with_game_value<U, V>(
|
||||
|
|
@ -333,7 +235,8 @@ impl Game {
|
|||
info: &U,
|
||||
details: &V,
|
||||
) {
|
||||
self.trigger_event_with_game_value(
|
||||
trigger_event_with_game_value(
|
||||
self,
|
||||
player_index,
|
||||
move |e| event(&mut e.transient),
|
||||
info,
|
||||
|
|
@ -342,21 +245,6 @@ impl Game {
|
|||
);
|
||||
}
|
||||
|
||||
fn trigger_event_with_game_value<U, V, W>(
|
||||
&mut self,
|
||||
player_index: usize,
|
||||
event: impl Fn(&mut PlayerEvents) -> &mut Event<Game, U, V, W>,
|
||||
info: &U,
|
||||
details: &V,
|
||||
extra_value: &mut W,
|
||||
) where
|
||||
W: Clone + PartialEq,
|
||||
{
|
||||
let e = event(&mut self.players[player_index].events).take();
|
||||
e.trigger(self, info, details, extra_value);
|
||||
event(&mut self.players[player_index].events).set(e);
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn execute_cost_trigger(&self) -> CostTrigger {
|
||||
if self.context == GameContext::AI {
|
||||
|
|
@ -616,12 +504,7 @@ impl Game {
|
|||
.clone()
|
||||
.into_iter()
|
||||
.filter(|(t, _)| {
|
||||
if matches!(
|
||||
t,
|
||||
CustomActionType::ArtsInfluenceCultureAttempt
|
||||
| CustomActionType::FreeEconomyCollect
|
||||
| CustomActionType::VotingIncreaseHappiness
|
||||
) {
|
||||
if t.is_modifier() {
|
||||
// returned as part of "base_or_custom_available"
|
||||
return false;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,12 +1,12 @@
|
|||
use crate::advance::Advance;
|
||||
use crate::advance::{Advance, is_special_advance_active};
|
||||
use crate::cache::Cache;
|
||||
use crate::city::{City, CityData};
|
||||
use crate::city_pieces::{DestroyedStructures, DestroyedStructuresData};
|
||||
use crate::content::builtin;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_actions::CustomActionType;
|
||||
use crate::content::effects::PermanentEffect;
|
||||
use crate::content::persistent_events::PersistentEventState;
|
||||
use crate::content::{builtin, civilizations};
|
||||
use crate::game::{Game, GameContext, GameOptions, GameState};
|
||||
use crate::log::ActionLogAge;
|
||||
use crate::map::{Map, MapData};
|
||||
|
|
@ -248,9 +248,6 @@ pub struct PlayerData {
|
|||
great_library_advance: Option<Advance>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
unlocked_special_advance: Vec<String>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
wonders_built: Vec<Wonder>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "u8::is_zero")]
|
||||
|
|
@ -293,7 +290,7 @@ pub struct PlayerData {
|
|||
fn initialize_player(data: PlayerData, game: &mut Game, all: &[Builtin]) {
|
||||
let leader = data.active_leader.clone();
|
||||
let objective_cards = data.objective_cards.clone();
|
||||
let player = player_from_data(data);
|
||||
let player = player_from_data(data, game);
|
||||
let player_index = player.index;
|
||||
game.players.push(player);
|
||||
builtin::init_player(game, player_index, all);
|
||||
|
|
@ -322,7 +319,7 @@ fn initialize_player(data: PlayerData, game: &mut Game, all: &[Builtin]) {
|
|||
game.players[player_index].cities = cities;
|
||||
}
|
||||
|
||||
fn player_from_data(data: PlayerData) -> Player {
|
||||
fn player_from_data(data: PlayerData, game: &Game) -> Player {
|
||||
let units = data
|
||||
.units
|
||||
.into_iter()
|
||||
|
|
@ -345,6 +342,8 @@ fn player_from_data(data: PlayerData) -> Player {
|
|||
.into_iter()
|
||||
.map(|d| City::from_data(d, data.id))
|
||||
.collect_vec();
|
||||
let advances = EnumSet::from_iter(data.advances);
|
||||
let civilization = game.cache.get_civilization(&data.civilization);
|
||||
Player {
|
||||
name: data.name,
|
||||
index: data.id,
|
||||
|
|
@ -354,13 +353,17 @@ fn player_from_data(data: PlayerData) -> Player {
|
|||
events: PlayerEvents::new(),
|
||||
destroyed_structures: DestroyedStructures::from_data(data.destroyed_structures),
|
||||
units,
|
||||
civilization: civilizations::get_civilization(&data.civilization)
|
||||
.expect("player data should have a valid civilization"),
|
||||
active_leader: data.active_leader,
|
||||
available_leaders: data.available_leaders,
|
||||
advances: EnumSet::from_iter(data.advances),
|
||||
great_library_advance: data.great_library_advance,
|
||||
unlocked_special_advances: data.unlocked_special_advance,
|
||||
special_advances: civilization
|
||||
.special_advances
|
||||
.iter()
|
||||
.filter(|s| is_special_advance_active(s.advance, advances, game))
|
||||
.map(|s| s.advance)
|
||||
.collect(),
|
||||
civilization,
|
||||
advances,
|
||||
wonders_built: data.wonders_built,
|
||||
wonders_owned: cities
|
||||
.iter()
|
||||
|
|
@ -412,13 +415,8 @@ pub fn player_data(player: Player) -> PlayerData {
|
|||
civilization: player.civilization.name,
|
||||
active_leader: player.active_leader,
|
||||
available_leaders: player.available_leaders.into_iter().collect(),
|
||||
advances: player
|
||||
.advances
|
||||
.into_iter()
|
||||
.sorted_by_key(Advance::id)
|
||||
.collect(),
|
||||
advances: player.advances.iter().sorted_by_key(Advance::id).collect(),
|
||||
great_library_advance: player.great_library_advance,
|
||||
unlocked_special_advance: player.unlocked_special_advances,
|
||||
wonders_built: player.wonders_built,
|
||||
incident_tokens: player.incident_tokens,
|
||||
completed_objectives: player.completed_objectives,
|
||||
|
|
@ -456,7 +454,6 @@ pub fn cloned_player_data(player: &Player) -> PlayerData {
|
|||
available_leaders: player.available_leaders.clone(),
|
||||
advances: player.advances.iter().sorted_by_key(Advance::id).collect(),
|
||||
great_library_advance: player.great_library_advance,
|
||||
unlocked_special_advance: player.unlocked_special_advances.clone(),
|
||||
wonders_built: player.wonders_built.clone(),
|
||||
incident_tokens: player.incident_tokens,
|
||||
completed_objectives: player.completed_objectives.clone(),
|
||||
|
|
|
|||
|
|
@ -93,18 +93,15 @@ pub fn setup_game(setup: GameSetup) -> Game {
|
|||
pub fn setup_game_with_cache(setup: GameSetup, cache: Cache) -> Game {
|
||||
let mut rng = init_rng(setup.seed.clone());
|
||||
|
||||
let mut players = init_human_players(&setup, &mut rng);
|
||||
let mut players = init_human_players(&setup, &mut rng, &cache);
|
||||
|
||||
let starting_player = rng.range(0, players.len());
|
||||
|
||||
players.push(Player::new(
|
||||
civilizations::get_civilization(BARBARIANS).expect("civ not found"),
|
||||
players.len(),
|
||||
));
|
||||
players.push(Player::new(
|
||||
civilizations::get_civilization(PIRATES).expect("civ not found"),
|
||||
cache.get_civilization(BARBARIANS),
|
||||
players.len(),
|
||||
));
|
||||
players.push(Player::new(cache.get_civilization(PIRATES), players.len()));
|
||||
|
||||
let map = if setup.random_map {
|
||||
Map::random_map(&mut players, &mut rng)
|
||||
|
|
@ -210,16 +207,15 @@ fn init_rng(seed: String) -> Rng {
|
|||
Rng::from_seed(seed)
|
||||
}
|
||||
|
||||
fn init_human_players(setup: &GameSetup, rng: &mut Rng) -> Vec<Player> {
|
||||
fn init_human_players(setup: &GameSetup, rng: &mut Rng, cache: &Cache) -> Vec<Player> {
|
||||
let mut players = Vec::new();
|
||||
let mut civilizations = civilizations::get_all();
|
||||
let mut civilizations = civilizations::get_all_uncached();
|
||||
for player_index in 0..setup.player_amount {
|
||||
let civilization = if setup.civilizations.is_empty() {
|
||||
civilizations.remove(rng.range(NON_HUMAN_PLAYERS, civilizations.len()))
|
||||
} else {
|
||||
rng.next_seed(); // need to call next_seed to have the same number of calls to rng
|
||||
civilizations::get_civilization(&setup.civilizations[player_index])
|
||||
.expect("civilization not found")
|
||||
cache.get_civilization(&setup.civilizations[player_index])
|
||||
};
|
||||
let mut player = Player::new(civilization, player_index);
|
||||
player.resource_limit = ResourcePile::new(2, 7, 7, 7, 7, 0, 0);
|
||||
|
|
|
|||
|
|
@ -1,8 +1,9 @@
|
|||
use crate::city::MoodState;
|
||||
use crate::content::custom_actions::CustomActionType;
|
||||
use crate::game::Game;
|
||||
use crate::leader::leader_position;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::CostTrigger;
|
||||
use crate::player::{CostTrigger, Player};
|
||||
use crate::player_events::CostInfo;
|
||||
use crate::playing_actions::{PlayingActionType, base_or_custom_available};
|
||||
use crate::position::Position;
|
||||
|
|
@ -15,26 +16,49 @@ pub fn available_happiness_actions(game: &Game, player: usize) -> Vec<PlayingAct
|
|||
game,
|
||||
player,
|
||||
PlayingActionType::IncreaseHappiness,
|
||||
&CustomActionType::VotingIncreaseHappiness,
|
||||
vec![
|
||||
CustomActionType::VotingIncreaseHappiness,
|
||||
CustomActionType::StatesmanIncreaseHappiness,
|
||||
],
|
||||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn happiness_city_restriction(player: &Player, action: &PlayingActionType) -> Option<Position> {
|
||||
match action {
|
||||
PlayingActionType::Custom(custom)
|
||||
if custom == &CustomActionType::StatesmanIncreaseHappiness =>
|
||||
{
|
||||
Some(leader_position(player))
|
||||
}
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn increase_happiness(
|
||||
game: &mut Game,
|
||||
player_index: usize,
|
||||
happiness_increases: &[(Position, u8)],
|
||||
payment: Option<ResourcePile>,
|
||||
action_type: &PlayingActionType,
|
||||
) {
|
||||
) -> Result<(), String> {
|
||||
let trigger = game.execute_cost_trigger();
|
||||
let player = &mut game.players[player_index];
|
||||
let restriction = happiness_city_restriction(player, action_type);
|
||||
let mut angry_activations = vec![];
|
||||
let mut step_sum = 0;
|
||||
for &(city_position, steps) in happiness_increases {
|
||||
let city = player.get_city(city_position);
|
||||
if steps == 0 {
|
||||
continue;
|
||||
}
|
||||
if restriction.is_some_and(|r| r != city_position) {
|
||||
return Err(format!(
|
||||
"Cannot increase happiness in city {city_position}, \
|
||||
only in {restriction:?} with {action_type:?}"
|
||||
));
|
||||
}
|
||||
|
||||
let city = player.get_city(city_position);
|
||||
step_sum += steps * city.size() as u8;
|
||||
|
||||
if city.mood_state == MoodState::Angry {
|
||||
|
|
@ -49,25 +73,26 @@ pub(crate) fn increase_happiness(
|
|||
if let Some(r) = payment {
|
||||
happiness_cost(player_index, step_sum, trigger, action_type, game).pay(game, &r);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn happiness_cost(
|
||||
p: usize,
|
||||
player: usize,
|
||||
city_size_steps: u8, // for each city: size * steps in that city
|
||||
execute: CostTrigger,
|
||||
action_type: &PlayingActionType,
|
||||
game: &Game,
|
||||
) -> CostInfo {
|
||||
let p = game.player(player);
|
||||
let mut payment_options = PaymentOptions::sum(
|
||||
game.player(p),
|
||||
p,
|
||||
PaymentReason::IncreaseHappiness,
|
||||
city_size_steps,
|
||||
&[ResourceType::MoodTokens],
|
||||
);
|
||||
// either none or both can use Colosseum
|
||||
payment_options.default += action_type.cost(game).cost;
|
||||
payment_options.default += action_type.cost(game).payment_options(p).default;
|
||||
|
||||
game.player(p)
|
||||
.trigger_cost_event(|e| &e.happiness_cost, &payment_options, &(), &(), execute)
|
||||
p.trigger_cost_event(|e| &e.happiness_cost, &payment_options, &(), &(), execute)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ use crate::city::{MoodState, is_valid_city_terrain};
|
|||
use crate::content::incidents::great_persons::GREAT_PERSON_OFFSET;
|
||||
use crate::content::persistent_events::{
|
||||
HandCardsRequest, PaymentRequest, PersistentEventType, PlayerRequest, PositionRequest,
|
||||
ResourceRewardRequest, SelectedStructure, StructuresRequest, UnitsRequest,
|
||||
ResourceRewardRequest, SelectedStructure, StructuresRequest, TriggerPersistentEventParams,
|
||||
UnitsRequest, trigger_persistent_event_with_listener,
|
||||
};
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
|
|
@ -22,6 +23,7 @@ use crate::player_events::{IncidentInfo, IncidentPlayerInfo, IncidentTarget};
|
|||
use crate::position::Position;
|
||||
use crate::resource::ResourceType;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::special_advance::SpecialAdvance;
|
||||
use crate::wonder::Wonder;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -37,6 +39,7 @@ pub struct Incident {
|
|||
pub name: String,
|
||||
description: String,
|
||||
protection_advance: Option<Advance>,
|
||||
protection_special_advance: Option<SpecialAdvance>,
|
||||
pub base_effect: IncidentBaseEffect,
|
||||
pub listeners: AbilityListeners,
|
||||
pub(crate) action_card: Option<ActionCard>,
|
||||
|
|
@ -63,6 +66,9 @@ impl Incident {
|
|||
if let Some(p) = &self.protection_advance {
|
||||
h.push(format!("Protection advance: {}", p.name(game)));
|
||||
}
|
||||
if let Some(p) = &self.protection_special_advance {
|
||||
h.push(format!("Protection advance: {}", p.name(game)));
|
||||
}
|
||||
h.push(self.description.clone());
|
||||
h
|
||||
}
|
||||
|
|
@ -102,14 +108,21 @@ pub(crate) struct IncidentFilter {
|
|||
role: IncidentTarget,
|
||||
priority: i32,
|
||||
protection_advance: Option<Advance>,
|
||||
protection_special_advance: Option<SpecialAdvance>,
|
||||
}
|
||||
|
||||
impl IncidentFilter {
|
||||
pub fn new(role: IncidentTarget, priority: i32, protection_advance: Option<Advance>) -> Self {
|
||||
pub fn new(
|
||||
role: IncidentTarget,
|
||||
priority: i32,
|
||||
protection_advance: Option<Advance>,
|
||||
protection_special_advance: Option<SpecialAdvance>,
|
||||
) -> Self {
|
||||
Self {
|
||||
role,
|
||||
priority,
|
||||
protection_advance,
|
||||
protection_special_advance,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -117,6 +130,7 @@ impl IncidentFilter {
|
|||
pub fn is_active(&self, game: &Game, i: &IncidentInfo, player: usize) -> bool {
|
||||
is_active(
|
||||
&self.protection_advance,
|
||||
&self.protection_special_advance,
|
||||
self.priority,
|
||||
game,
|
||||
i,
|
||||
|
|
@ -161,6 +175,7 @@ pub struct IncidentBuilder {
|
|||
description: String,
|
||||
base_effect: IncidentBaseEffect,
|
||||
protection_advance: Option<Advance>,
|
||||
protection_special_advance: Option<SpecialAdvance>,
|
||||
action_card: Option<ActionCard>,
|
||||
builder: AbilityInitializerBuilder,
|
||||
}
|
||||
|
|
@ -175,6 +190,7 @@ impl IncidentBuilder {
|
|||
base_effect,
|
||||
builder: AbilityInitializerBuilder::new(),
|
||||
protection_advance: None,
|
||||
protection_special_advance: None,
|
||||
action_card: None,
|
||||
}
|
||||
}
|
||||
|
|
@ -199,6 +215,7 @@ impl IncidentBuilder {
|
|||
base_effect: builder.base_effect,
|
||||
listeners: builder.builder.build(),
|
||||
protection_advance: builder.protection_advance,
|
||||
protection_special_advance: builder.protection_special_advance,
|
||||
action_card: builder.action_card,
|
||||
}
|
||||
}
|
||||
|
|
@ -209,6 +226,12 @@ impl IncidentBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_protection_special_advance(mut self, advance: SpecialAdvance) -> Self {
|
||||
self.protection_special_advance = Some(advance);
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn with_action_card(mut self, action_card: ActionCard) -> Self {
|
||||
self.action_card = Some(action_card);
|
||||
|
|
@ -371,7 +394,12 @@ impl IncidentBuilder {
|
|||
}
|
||||
|
||||
fn new_filter(&self, role: IncidentTarget, priority: i32) -> IncidentFilter {
|
||||
IncidentFilter::new(role, priority, self.protection_advance)
|
||||
IncidentFilter::new(
|
||||
role,
|
||||
priority,
|
||||
self.protection_advance,
|
||||
self.protection_special_advance,
|
||||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
@ -621,14 +649,18 @@ pub(crate) fn on_trigger_incident(game: &mut Game, mut info: IncidentInfo) {
|
|||
"A new game event has been triggered: {}",
|
||||
game.cache.get_incident(info.incident_id).name
|
||||
));
|
||||
info = match game.trigger_persistent_event_with_listener(
|
||||
info = match trigger_persistent_event_with_listener(
|
||||
game,
|
||||
&game.human_players(info.active_player),
|
||||
|events| &mut events.incident,
|
||||
&game.cache.get_incident(info.incident_id).listeners.clone(),
|
||||
info,
|
||||
PersistentEventType::Incident,
|
||||
log.as_deref(),
|
||||
|i| i.player = IncidentPlayerInfo::new(),
|
||||
TriggerPersistentEventParams {
|
||||
log,
|
||||
next_player: |i| i.player = IncidentPlayerInfo::new(),
|
||||
..Default::default()
|
||||
},
|
||||
) {
|
||||
Some(p) => p,
|
||||
None => return,
|
||||
|
|
@ -693,6 +725,7 @@ fn passed_to_player(game: &mut Game, i: &mut IncidentInfo) -> bool {
|
|||
#[must_use]
|
||||
pub fn is_active(
|
||||
protection_advance: &Option<Advance>,
|
||||
protection_special_advance: &Option<SpecialAdvance>,
|
||||
priority: i32,
|
||||
game: &Game,
|
||||
i: &IncidentInfo,
|
||||
|
|
@ -711,6 +744,11 @@ pub fn is_active(
|
|||
return false;
|
||||
}
|
||||
}
|
||||
if let Some(advance) = protection_special_advance {
|
||||
if game.player(player).has_special_advance(*advance) {
|
||||
return false;
|
||||
}
|
||||
}
|
||||
true
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,81 +1,80 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::ability_initializer::{AbilityInitializerBuilder, AbilityListeners};
|
||||
use crate::events::EventOrigin;
|
||||
use crate::player::Player;
|
||||
use crate::position::Position;
|
||||
use crate::unit::UnitType;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Leader {
|
||||
pub name: String,
|
||||
pub first_ability: String,
|
||||
pub first_ability_description: String,
|
||||
pub second_ability: String,
|
||||
pub second_ability_description: String,
|
||||
pub listeners: AbilityListeners,
|
||||
pub abilities: Vec<LeaderAbility>,
|
||||
}
|
||||
|
||||
impl Leader {
|
||||
#[must_use]
|
||||
pub fn builder(
|
||||
name: &str,
|
||||
first_ability: &str,
|
||||
first_ability_description: &str,
|
||||
second_ability: &str,
|
||||
second_ability_description: &str,
|
||||
) -> LeaderBuilder {
|
||||
LeaderBuilder::new(
|
||||
name.to_string(),
|
||||
first_ability.to_string(),
|
||||
first_ability_description.to_string(),
|
||||
second_ability.to_string(),
|
||||
second_ability_description.to_string(),
|
||||
)
|
||||
pub fn new(name: &str, first_ability: LeaderAbility, second_ability: LeaderAbility) -> Leader {
|
||||
Self {
|
||||
name: name.to_string(),
|
||||
abilities: vec![first_ability, second_ability],
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LeaderBuilder {
|
||||
#[derive(Clone)]
|
||||
pub struct LeaderAbility {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub listeners: AbilityListeners,
|
||||
}
|
||||
|
||||
impl LeaderAbility {
|
||||
#[must_use]
|
||||
pub fn builder(name: &str, description: &str) -> LeaderAbilityBuilder {
|
||||
LeaderAbilityBuilder::new(name.to_string(), description.to_string())
|
||||
}
|
||||
}
|
||||
|
||||
pub struct LeaderAbilityBuilder {
|
||||
name: String,
|
||||
first_ability: String,
|
||||
first_ability_description: String,
|
||||
second_ability: String,
|
||||
second_ability_description: String,
|
||||
description: String,
|
||||
builder: AbilityInitializerBuilder,
|
||||
}
|
||||
|
||||
impl LeaderBuilder {
|
||||
fn new(
|
||||
name: String,
|
||||
first_ability: String,
|
||||
first_ability_description: String,
|
||||
second_ability: String,
|
||||
second_ability_description: String,
|
||||
) -> Self {
|
||||
impl LeaderAbilityBuilder {
|
||||
fn new(name: String, description: String) -> Self {
|
||||
Self {
|
||||
name,
|
||||
first_ability,
|
||||
first_ability_description,
|
||||
second_ability,
|
||||
second_ability_description,
|
||||
description,
|
||||
builder: AbilityInitializerBuilder::new(),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn build(self) -> Leader {
|
||||
Leader {
|
||||
pub fn build(self) -> LeaderAbility {
|
||||
LeaderAbility {
|
||||
name: self.name,
|
||||
first_ability: self.first_ability,
|
||||
first_ability_description: self.first_ability_description,
|
||||
second_ability: self.second_ability,
|
||||
second_ability_description: self.second_ability_description,
|
||||
description: self.description,
|
||||
listeners: self.builder.build(),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl AbilityInitializerSetup for LeaderBuilder {
|
||||
impl AbilityInitializerSetup for LeaderAbilityBuilder {
|
||||
fn builder(&mut self) -> &mut AbilityInitializerBuilder {
|
||||
&mut self.builder
|
||||
}
|
||||
|
||||
fn get_key(&self) -> EventOrigin {
|
||||
EventOrigin::Leader(self.name.clone())
|
||||
EventOrigin::LeaderAbility(self.name.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn leader_position(player: &Player) -> Position {
|
||||
player
|
||||
.units
|
||||
.iter()
|
||||
.find_map(|unit| (unit.unit_type == UnitType::Leader).then_some(unit.position))
|
||||
.expect("unit not found")
|
||||
}
|
||||
|
|
|
|||
|
|
@ -144,10 +144,11 @@ fn format_playing_action_log_item(action: &PlayingAction, game: &Game) -> String
|
|||
let player = &game.players[game.active_player()];
|
||||
let player_name = player.get_name();
|
||||
match action {
|
||||
PlayingAction::Advance { advance, payment } => {
|
||||
PlayingAction::Advance(a) => {
|
||||
format!(
|
||||
"{player} paid {payment} to get the {} advance",
|
||||
advance.name(game)
|
||||
"{player} paid {} to get the {} advance",
|
||||
a.payment,
|
||||
a.advance.name(game)
|
||||
)
|
||||
}
|
||||
PlayingAction::FoundCity { settler } => format!(
|
||||
|
|
@ -216,10 +217,10 @@ pub fn format_happiness_increase(
|
|||
}
|
||||
})
|
||||
.collect_vec();
|
||||
let suffix = if let PlayingActionType::Custom(_) = i.action_type {
|
||||
" using Voting"
|
||||
let suffix = if let PlayingActionType::Custom(c) = i.action_type {
|
||||
format!(" using {c}")
|
||||
} else {
|
||||
""
|
||||
String::new()
|
||||
};
|
||||
|
||||
format!(
|
||||
|
|
@ -241,22 +242,10 @@ pub(crate) fn format_city_happiness_increase(
|
|||
}
|
||||
|
||||
fn format_recruit_log_item(player: &Player, player_name: &String, r: &Recruit) -> String {
|
||||
let leader_name = r.leader_name.clone();
|
||||
let city_position = &r.city_position;
|
||||
let units = &r.units;
|
||||
let payment = &r.payment;
|
||||
let replaced_units = &r.replaced_units;
|
||||
let leader_str = leader_name.map_or(String::new(), |leader_name| {
|
||||
format!(
|
||||
" {} {} as their leader",
|
||||
if player.available_leaders.len() > 1 {
|
||||
"choosing"
|
||||
} else {
|
||||
"getting"
|
||||
},
|
||||
&leader_name
|
||||
)
|
||||
});
|
||||
let mood = format_mood_change(player, *city_position);
|
||||
let replace_str = match replaced_units.len() {
|
||||
0 => "",
|
||||
|
|
@ -272,7 +261,8 @@ fn format_recruit_log_item(player: &Player, player_name: &String, r: &Recruit) -
|
|||
"",
|
||||
);
|
||||
format!(
|
||||
"{player_name} paid {payment} to recruit {units}{leader_str} in the city at {city_position}{mood}{replace_str}{replace_pos}"
|
||||
"{player_name} paid {payment} to recruit {} in the city at {city_position}{mood}{replace_str}{replace_pos}",
|
||||
units.to_string(r.leader_name.as_ref())
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -375,7 +365,8 @@ pub(crate) fn move_action_log(game: &Game, player: &Player, m: &MoveUnits) -> St
|
|||
.units
|
||||
.iter()
|
||||
.map(|unit| player.get_unit(*unit).unit_type)
|
||||
.collect::<Units>();
|
||||
.collect::<Units>()
|
||||
.to_string(player.active_leader.as_ref());
|
||||
let start = player.get_unit(m.units[0]).position;
|
||||
let start_is_water = game.map.is_sea(start);
|
||||
let dest = m.destination;
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use crate::city::{City, MoodState};
|
||||
use crate::consts::NON_HUMAN_PLAYERS;
|
||||
use crate::game::Game;
|
||||
use crate::player::Player;
|
||||
use crate::position::Position;
|
||||
use crate::utils::{Rng, Shuffle};
|
||||
|
|
@ -550,3 +551,38 @@ pub fn setup_home_city(player: &mut Player, pos: Position) {
|
|||
city.set_mood_state(MoodState::Happy);
|
||||
player.cities.push(city);
|
||||
}
|
||||
|
||||
pub(crate) fn home_position(game: &Game, player: &Player) -> Position {
|
||||
let setup = get_map_setup(game.human_players_count());
|
||||
let h = &setup.home_positions[player.index];
|
||||
h.block.tiles(&h.position, h.position.rotation)[0].0
|
||||
}
|
||||
|
||||
pub(crate) fn block_tiles(p1: &BlockPosition) -> Vec<Position> {
|
||||
UNEXPLORED_BLOCK
|
||||
.tiles(p1, p1.rotation)
|
||||
.into_iter()
|
||||
.map(|(p, _)| p)
|
||||
.collect_vec()
|
||||
}
|
||||
|
||||
pub(crate) fn block_has_player_city(game: &Game, p: &BlockPosition, player: usize) -> bool {
|
||||
block_tiles(p)
|
||||
.iter()
|
||||
.any(|p| game.player(player).try_get_city(*p).is_some())
|
||||
}
|
||||
|
||||
pub(crate) fn block_for_position(game: &Game, position: Position) -> BlockPosition {
|
||||
let setup = get_map_setup(game.human_players_count());
|
||||
for p in &setup.free_positions {
|
||||
if block_tiles(p).contains(&position) {
|
||||
return p.clone();
|
||||
}
|
||||
}
|
||||
let h = setup
|
||||
.home_positions
|
||||
.iter()
|
||||
.find(|h| block_tiles(&h.position).contains(&position))
|
||||
.expect("Position not found in home positions");
|
||||
h.position.clone()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@ use crate::game::{Game, GameState};
|
|||
use crate::player::Player;
|
||||
use crate::player_events::MoveInfo;
|
||||
use crate::position::Position;
|
||||
use crate::special_advance::SpecialAdvance;
|
||||
use crate::unit::{carried_units, get_current_move};
|
||||
use crate::wonder::Wonder;
|
||||
use itertools::Itertools;
|
||||
use pathfinding::prelude::astar;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
|
||||
|
|
@ -231,7 +233,7 @@ pub(crate) fn move_units_destinations(
|
|||
}
|
||||
|
||||
Ok(
|
||||
move_routes(start, player, unit_ids, game, embark_carrier_id)
|
||||
move_routes(start, player, unit_ids, game, embark_carrier_id, stack_size)
|
||||
.into_iter()
|
||||
.map(|route| {
|
||||
let result = move_route_result(
|
||||
|
|
@ -285,7 +287,6 @@ fn move_route_result(
|
|||
.filter(|unit| unit.unit_type.is_army_unit() && !unit.is_transported())
|
||||
.count()
|
||||
+ stack_size
|
||||
+ route.stack_size_used
|
||||
> STACK_LIMIT
|
||||
{
|
||||
return Err("stack limit exceeded".to_string());
|
||||
|
|
@ -343,9 +344,7 @@ fn is_move_restricted(
|
|||
&& game
|
||||
.try_get_any_city(dest)
|
||||
.is_some_and(|city| city.pieces.wonders.contains(&Wonder::GreatGardens))
|
||||
&& movement_restrictions
|
||||
.iter()
|
||||
.any(|&r| r == &MovementRestriction::Fertile)
|
||||
&& movement_restrictions.contains(&(&MovementRestriction::Fertile))
|
||||
{
|
||||
return Err("fertile movement attack great gardens restriction".to_string());
|
||||
}
|
||||
|
|
@ -380,7 +379,6 @@ fn check_can_move(
|
|||
pub struct MoveRoute {
|
||||
pub destination: Position,
|
||||
pub cost: PaymentOptions,
|
||||
pub stack_size_used: usize,
|
||||
pub ignore_terrain_movement_restrictions: bool,
|
||||
}
|
||||
|
||||
|
|
@ -391,7 +389,6 @@ impl MoveRoute {
|
|||
Self {
|
||||
destination,
|
||||
cost: options,
|
||||
stack_size_used: 0,
|
||||
ignore_terrain_movement_restrictions: false,
|
||||
}
|
||||
}
|
||||
|
|
@ -428,6 +425,7 @@ pub(crate) fn move_routes(
|
|||
units: &[u32],
|
||||
game: &Game,
|
||||
embark_carrier_id: Option<u32>,
|
||||
stack_size: usize,
|
||||
) -> Vec<MoveRoute> {
|
||||
let mut base: Vec<MoveRoute> = starting
|
||||
.neighbors()
|
||||
|
|
@ -439,7 +437,7 @@ pub(crate) fn move_routes(
|
|||
base.extend(reachable_with_navigation(player, units, &game.map));
|
||||
}
|
||||
if player.can_use_advance(Advance::Roads) && embark_carrier_id.is_none() {
|
||||
base.extend(reachable_with_roads(player, units, game));
|
||||
base.extend(reachable_with_roads(player, units, game, stack_size));
|
||||
}
|
||||
add_diplomatic_relations(player, game, &mut base);
|
||||
add_negotiations(player, game, &mut base);
|
||||
|
|
@ -466,7 +464,12 @@ fn add_negotiations(player: &Player, game: &Game, base: &mut Vec<MoveRoute>) {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
fn reachable_with_roads(player: &Player, units: &[u32], game: &Game) -> Vec<MoveRoute> {
|
||||
fn reachable_with_roads(
|
||||
player: &Player,
|
||||
units: &[u32],
|
||||
game: &Game,
|
||||
stack_size: usize,
|
||||
) -> Vec<MoveRoute> {
|
||||
let start = units.iter().find_map(|&id| {
|
||||
let unit = player.get_unit(id);
|
||||
if unit.unit_type.is_land_based() {
|
||||
|
|
@ -483,71 +486,140 @@ fn reachable_with_roads(player: &Player, units: &[u32], game: &Game) -> Vec<Move
|
|||
return vec![];
|
||||
}
|
||||
|
||||
return start
|
||||
.neighbors()
|
||||
let roman_roads = player.has_special_advance(SpecialAdvance::RomanRoads);
|
||||
let mut routes: Vec<MoveRoute> = next_road_step(player, game, start, stack_size)
|
||||
.into_iter()
|
||||
.flat_map(|middle| {
|
||||
// don't move over enemy units or cities
|
||||
let stack_size_used = player
|
||||
.get_units(middle)
|
||||
.iter()
|
||||
.filter(|unit| unit.unit_type.is_army_unit())
|
||||
.count();
|
||||
|
||||
if map.is_land(middle) && game.enemy_player(player.index, middle).is_none() {
|
||||
let mut dest: Vec<(Position, usize)> = middle
|
||||
.neighbors()
|
||||
.into_iter()
|
||||
.map(move |n| (n, stack_size_used))
|
||||
.collect();
|
||||
dest.push((middle, stack_size_used));
|
||||
dest.retain(|&(p, _)| p != start);
|
||||
dest
|
||||
} else {
|
||||
vec![]
|
||||
}
|
||||
})
|
||||
.into_group_map_by(|&(p, _)| p)
|
||||
.into_iter()
|
||||
.filter_map(|(destination, stack_sizes_used)| {
|
||||
if destination.distance(start) == 1 {
|
||||
// can go directly without using roads
|
||||
return None;
|
||||
}
|
||||
|
||||
// but can stop on enemy units
|
||||
if map.is_land(destination)
|
||||
&& (
|
||||
// from or to owned city
|
||||
player.try_get_city(start).is_some()
|
||||
|| player.try_get_city(destination).is_some()
|
||||
)
|
||||
{
|
||||
let stack_size_used =
|
||||
stack_sizes_used.iter().map(|&(_, s)| s).min().expect("min");
|
||||
let mut cost = PaymentOptions::resources(
|
||||
player,
|
||||
PaymentReason::Move,
|
||||
ResourcePile::ore(1) + ResourcePile::food(1),
|
||||
);
|
||||
let origin = EventOrigin::Advance(Advance::Roads);
|
||||
cost.modifiers = vec![origin.clone()];
|
||||
let route = MoveRoute {
|
||||
destination,
|
||||
cost,
|
||||
stack_size_used,
|
||||
ignore_terrain_movement_restrictions: true,
|
||||
};
|
||||
Some(route)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
.flat_map(|middle| next_road_step(player, game, middle, stack_size))
|
||||
.unique()
|
||||
.filter_map(|destination| {
|
||||
road_route(
|
||||
player,
|
||||
start,
|
||||
destination,
|
||||
roman_roads,
|
||||
vec![EventOrigin::Advance(Advance::Roads)],
|
||||
)
|
||||
})
|
||||
.collect();
|
||||
|
||||
if roman_roads {
|
||||
routes.extend(roman_roads_routes(player, game, start, stack_size));
|
||||
}
|
||||
|
||||
return routes;
|
||||
}
|
||||
vec![]
|
||||
}
|
||||
|
||||
const ROMAN_ROADS_LENGTH: u8 = 4;
|
||||
|
||||
fn roman_roads_routes(
|
||||
player: &Player,
|
||||
game: &Game,
|
||||
start: Position,
|
||||
stack_size: usize,
|
||||
) -> Vec<MoveRoute> {
|
||||
if game.try_get_any_city(start).is_none() {
|
||||
return vec![];
|
||||
}
|
||||
|
||||
player
|
||||
.cities
|
||||
.iter()
|
||||
.filter_map(|city| {
|
||||
let distance = city.position.distance(start) as u8;
|
||||
if distance > ROMAN_ROADS_LENGTH {
|
||||
return None;
|
||||
}
|
||||
let dst = city.position;
|
||||
|
||||
let len = astar(
|
||||
&start,
|
||||
|p| {
|
||||
next_road_step(player, game, *p, stack_size)
|
||||
.iter()
|
||||
.map(|&n| (n, 1))
|
||||
.collect_vec()
|
||||
},
|
||||
|p| p.distance(dst),
|
||||
|&p| p == dst,
|
||||
)
|
||||
.map_or(u8::MAX, |(_path, len)| len as u8);
|
||||
if len > ROMAN_ROADS_LENGTH {
|
||||
return None;
|
||||
}
|
||||
road_route(
|
||||
player,
|
||||
start,
|
||||
dst,
|
||||
false,
|
||||
vec![
|
||||
EventOrigin::Advance(Advance::Roads),
|
||||
EventOrigin::SpecialAdvance(SpecialAdvance::RomanRoads),
|
||||
],
|
||||
)
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn road_route(
|
||||
player: &Player,
|
||||
start: Position,
|
||||
destination: Position,
|
||||
ignore_city_to_city: bool,
|
||||
modifiers: Vec<EventOrigin>,
|
||||
) -> Option<MoveRoute> {
|
||||
if destination.distance(start) <= 1 {
|
||||
// can go directly without using roads
|
||||
return None;
|
||||
}
|
||||
|
||||
// but can stop on enemy units
|
||||
|
||||
let from_city = player.try_get_city(start).is_some();
|
||||
let to_city = player.try_get_city(destination).is_some();
|
||||
if !from_city && !to_city {
|
||||
return None;
|
||||
}
|
||||
if from_city && to_city && ignore_city_to_city {
|
||||
return None;
|
||||
}
|
||||
|
||||
let mut cost = PaymentOptions::resources(
|
||||
player,
|
||||
PaymentReason::Move,
|
||||
ResourcePile::ore(1) + ResourcePile::food(1),
|
||||
);
|
||||
cost.modifiers = modifiers;
|
||||
Some(MoveRoute {
|
||||
destination,
|
||||
cost,
|
||||
ignore_terrain_movement_restrictions: true,
|
||||
})
|
||||
}
|
||||
|
||||
fn next_road_step(
|
||||
player: &Player,
|
||||
game: &Game,
|
||||
from: Position,
|
||||
stack_size: usize,
|
||||
) -> Vec<Position> {
|
||||
// don't move over enemy units or cities
|
||||
from.neighbors()
|
||||
.into_iter()
|
||||
.filter(|to| {
|
||||
let on_target = player
|
||||
.get_units(*to)
|
||||
.iter()
|
||||
.filter(|unit| unit.unit_type.is_army_unit())
|
||||
.count();
|
||||
game.map.is_land(*to)
|
||||
&& game.enemy_player(player.index, *to).is_none()
|
||||
&& on_target + stack_size <= STACK_LIMIT
|
||||
})
|
||||
.collect_vec()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn reachable_with_navigation(player: &Player, units: &[u32], map: &Map) -> Vec<MoveRoute> {
|
||||
if !player.can_use_advance(Advance::Navigation) {
|
||||
|
|
|
|||
|
|
@ -23,6 +23,7 @@ pub enum PaymentReason {
|
|||
InfluenceCulture,
|
||||
Move,
|
||||
ChangeGovernment,
|
||||
LeaderAbility,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug, Hash)]
|
||||
|
|
@ -77,6 +78,19 @@ pub struct PaymentOptions {
|
|||
}
|
||||
|
||||
impl PaymentOptions {
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
default: ResourcePile,
|
||||
conversions: Vec<PaymentConversion>,
|
||||
modifiers: Vec<EventOrigin>,
|
||||
) -> Self {
|
||||
PaymentOptions {
|
||||
default,
|
||||
conversions,
|
||||
modifiers,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn first_valid_payment(&self, available: &ResourcePile) -> Option<ResourcePile> {
|
||||
let discount_left = self
|
||||
|
|
@ -149,15 +163,15 @@ impl PaymentOptions {
|
|||
) -> PaymentOptions {
|
||||
let max = r.clone().max().expect("range empty");
|
||||
let d = max - r.min().expect("range empty");
|
||||
PaymentOptions {
|
||||
default: ResourcePile::of(t, max),
|
||||
conversions: vec![PaymentConversion::new(
|
||||
PaymentOptions::new(
|
||||
ResourcePile::of(t, max),
|
||||
vec![PaymentConversion::new(
|
||||
vec![ResourcePile::of(t, 1)],
|
||||
ResourcePile::empty(),
|
||||
PaymentConversionType::MayOverpay(d),
|
||||
)],
|
||||
modifiers: vec![],
|
||||
}
|
||||
vec![],
|
||||
)
|
||||
.add_extra_options(player, reason)
|
||||
}
|
||||
|
||||
|
|
@ -190,31 +204,22 @@ impl PaymentOptions {
|
|||
cost: ResourcePile,
|
||||
discount_type: PaymentConversionType,
|
||||
) -> Self {
|
||||
let base_resources = vec![
|
||||
ResourcePile::food(1),
|
||||
ResourcePile::wood(1),
|
||||
ResourcePile::ore(1),
|
||||
ResourcePile::ideas(1),
|
||||
];
|
||||
let base = base_resources();
|
||||
|
||||
let mut conversions = vec![PaymentConversion {
|
||||
from: base_resources.clone(),
|
||||
to: ResourcePile::gold(1),
|
||||
payment_conversion_type: PaymentConversionType::Unlimited,
|
||||
}];
|
||||
let mut conversions = vec![PaymentConversion::new(
|
||||
base.clone(),
|
||||
ResourcePile::gold(1),
|
||||
PaymentConversionType::Unlimited,
|
||||
)];
|
||||
if !matches!(discount_type, PaymentConversionType::Unlimited) {
|
||||
conversions.push(PaymentConversion::new(
|
||||
base_resources.clone(),
|
||||
base.clone(),
|
||||
ResourcePile::empty(),
|
||||
discount_type,
|
||||
));
|
||||
}
|
||||
|
||||
PaymentOptions {
|
||||
default: cost,
|
||||
conversions,
|
||||
modifiers: vec![],
|
||||
}
|
||||
PaymentOptions::new(cost, conversions, vec![])
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
@ -374,7 +379,10 @@ pub fn can_convert(
|
|||
None
|
||||
}
|
||||
|
||||
fn payment_options_sum(cost: u8, types_by_preference: &[ResourceType]) -> PaymentOptions {
|
||||
pub(crate) fn payment_options_sum(
|
||||
cost: u8,
|
||||
types_by_preference: &[ResourceType],
|
||||
) -> PaymentOptions {
|
||||
let mut conversions = vec![];
|
||||
types_by_preference.windows(2).for_each(|pair| {
|
||||
conversions.push(PaymentConversion::unlimited(
|
||||
|
|
@ -382,11 +390,20 @@ fn payment_options_sum(cost: u8, types_by_preference: &[ResourceType]) -> Paymen
|
|||
ResourcePile::of(pair[1], 1),
|
||||
));
|
||||
});
|
||||
PaymentOptions {
|
||||
default: ResourcePile::of(types_by_preference[0], cost),
|
||||
PaymentOptions::new(
|
||||
ResourcePile::of(types_by_preference[0], cost),
|
||||
conversions,
|
||||
modifiers: vec![],
|
||||
}
|
||||
vec![],
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn base_resources() -> Vec<ResourcePile> {
|
||||
vec![
|
||||
ResourcePile::food(1),
|
||||
ResourcePile::wood(1),
|
||||
ResourcePile::ore(1),
|
||||
ResourcePile::ideas(1),
|
||||
]
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
|
|
@ -458,15 +475,15 @@ mod tests {
|
|||
|
||||
#[test]
|
||||
fn test_find_valid_payment() {
|
||||
let cost = PaymentOptions {
|
||||
default: ResourcePile::food(1),
|
||||
conversions: vec![PaymentConversion {
|
||||
from: vec![ResourcePile::food(1)],
|
||||
to: ResourcePile::wood(1),
|
||||
payment_conversion_type: PaymentConversionType::Unlimited,
|
||||
}],
|
||||
modifiers: vec![],
|
||||
};
|
||||
let cost = PaymentOptions::new(
|
||||
ResourcePile::food(1),
|
||||
vec![PaymentConversion::new(
|
||||
vec![ResourcePile::food(1)],
|
||||
ResourcePile::wood(1),
|
||||
PaymentConversionType::Unlimited,
|
||||
)],
|
||||
vec![],
|
||||
);
|
||||
let available = ResourcePile::wood(1) + ResourcePile::ore(1);
|
||||
assert_eq!(
|
||||
cost.first_valid_payment(&available),
|
||||
|
|
@ -480,39 +497,35 @@ mod tests {
|
|||
let test_cases = vec![
|
||||
ValidPaymentTestCase {
|
||||
name: "no conversions".to_string(),
|
||||
options: PaymentOptions {
|
||||
default: ResourcePile::food(1),
|
||||
conversions: vec![],
|
||||
modifiers: vec![],
|
||||
},
|
||||
options: PaymentOptions::new(ResourcePile::food(1), vec![], vec![]),
|
||||
valid: vec![ResourcePile::food(1)],
|
||||
invalid: vec![ResourcePile::food(2)],
|
||||
},
|
||||
ValidPaymentTestCase {
|
||||
name: "food to wood".to_string(),
|
||||
options: PaymentOptions {
|
||||
default: ResourcePile::food(1),
|
||||
conversions: vec![PaymentConversion {
|
||||
from: vec![ResourcePile::food(1)],
|
||||
to: ResourcePile::wood(1),
|
||||
payment_conversion_type: PaymentConversionType::Unlimited,
|
||||
}],
|
||||
modifiers: vec![],
|
||||
},
|
||||
options: PaymentOptions::new(
|
||||
ResourcePile::food(1),
|
||||
vec![PaymentConversion::new(
|
||||
vec![ResourcePile::food(1)],
|
||||
ResourcePile::wood(1),
|
||||
PaymentConversionType::Unlimited,
|
||||
)],
|
||||
vec![],
|
||||
),
|
||||
valid: vec![ResourcePile::food(1), ResourcePile::wood(1)],
|
||||
invalid: vec![ResourcePile::food(2), ResourcePile::ore(1)],
|
||||
},
|
||||
ValidPaymentTestCase {
|
||||
name: "food to wood with amount".to_string(),
|
||||
options: PaymentOptions {
|
||||
default: ResourcePile::food(2),
|
||||
conversions: vec![PaymentConversion {
|
||||
from: vec![ResourcePile::food(1)],
|
||||
to: ResourcePile::wood(1),
|
||||
payment_conversion_type: PaymentConversionType::Unlimited,
|
||||
}],
|
||||
modifiers: vec![],
|
||||
},
|
||||
options: PaymentOptions::new(
|
||||
ResourcePile::food(2),
|
||||
vec![PaymentConversion::new(
|
||||
vec![ResourcePile::food(1)],
|
||||
ResourcePile::wood(1),
|
||||
PaymentConversionType::Unlimited,
|
||||
)],
|
||||
vec![],
|
||||
),
|
||||
valid: vec![
|
||||
ResourcePile::food(2),
|
||||
ResourcePile::food(1) + ResourcePile::wood(1),
|
||||
|
|
@ -522,15 +535,15 @@ mod tests {
|
|||
},
|
||||
ValidPaymentTestCase {
|
||||
name: "food to wood with limit".to_string(),
|
||||
options: PaymentOptions {
|
||||
default: ResourcePile::food(2),
|
||||
conversions: vec![PaymentConversion {
|
||||
from: vec![ResourcePile::food(1)],
|
||||
to: ResourcePile::wood(1),
|
||||
payment_conversion_type: PaymentConversionType::MayNotOverpay(1),
|
||||
}],
|
||||
modifiers: vec![],
|
||||
},
|
||||
options: PaymentOptions::new(
|
||||
ResourcePile::food(2),
|
||||
vec![PaymentConversion::new(
|
||||
vec![ResourcePile::food(1)],
|
||||
ResourcePile::wood(1),
|
||||
PaymentConversionType::MayNotOverpay(1),
|
||||
)],
|
||||
vec![],
|
||||
),
|
||||
valid: vec![
|
||||
ResourcePile::food(2),
|
||||
ResourcePile::wood(1) + ResourcePile::food(1),
|
||||
|
|
@ -539,15 +552,15 @@ mod tests {
|
|||
},
|
||||
ValidPaymentTestCase {
|
||||
name: "3 infantry with draft".to_string(),
|
||||
options: PaymentOptions {
|
||||
default: ResourcePile::food(3) + ResourcePile::ore(3),
|
||||
conversions: vec![PaymentConversion {
|
||||
from: vec![ResourcePile::food(1) + ResourcePile::ore(1)],
|
||||
to: ResourcePile::mood_tokens(1),
|
||||
payment_conversion_type: PaymentConversionType::MayNotOverpay(1),
|
||||
}],
|
||||
modifiers: vec![],
|
||||
},
|
||||
options: PaymentOptions::new(
|
||||
ResourcePile::food(3) + ResourcePile::ore(3),
|
||||
vec![PaymentConversion::new(
|
||||
vec![ResourcePile::food(1) + ResourcePile::ore(1)],
|
||||
ResourcePile::mood_tokens(1),
|
||||
PaymentConversionType::MayNotOverpay(1),
|
||||
)],
|
||||
vec![],
|
||||
),
|
||||
valid: vec![
|
||||
ResourcePile::food(3) + ResourcePile::ore(3),
|
||||
ResourcePile::food(2) + ResourcePile::ore(2) + ResourcePile::mood_tokens(1),
|
||||
|
|
@ -559,29 +572,29 @@ mod tests {
|
|||
},
|
||||
ValidPaymentTestCase {
|
||||
name: "discount must be used".to_string(),
|
||||
options: PaymentOptions {
|
||||
default: ResourcePile::food(3),
|
||||
conversions: vec![PaymentConversion {
|
||||
from: vec![ResourcePile::food(1)],
|
||||
to: ResourcePile::empty(),
|
||||
payment_conversion_type: PaymentConversionType::MayNotOverpay(2),
|
||||
}],
|
||||
modifiers: vec![],
|
||||
},
|
||||
options: PaymentOptions::new(
|
||||
ResourcePile::food(3),
|
||||
vec![PaymentConversion::new(
|
||||
vec![ResourcePile::food(1)],
|
||||
ResourcePile::empty(),
|
||||
PaymentConversionType::MayNotOverpay(2),
|
||||
)],
|
||||
vec![],
|
||||
),
|
||||
valid: vec![ResourcePile::food(1)],
|
||||
invalid: vec![ResourcePile::food(2)],
|
||||
},
|
||||
ValidPaymentTestCase {
|
||||
name: "discount with overpay".to_string(),
|
||||
options: PaymentOptions {
|
||||
default: ResourcePile::food(3),
|
||||
conversions: vec![PaymentConversion {
|
||||
from: vec![ResourcePile::food(1)],
|
||||
to: ResourcePile::empty(),
|
||||
payment_conversion_type: PaymentConversionType::MayOverpay(2),
|
||||
}],
|
||||
modifiers: vec![],
|
||||
},
|
||||
options: PaymentOptions::new(
|
||||
ResourcePile::food(3),
|
||||
vec![PaymentConversion::new(
|
||||
vec![ResourcePile::food(1)],
|
||||
ResourcePile::empty(),
|
||||
PaymentConversionType::MayOverpay(2),
|
||||
)],
|
||||
vec![],
|
||||
),
|
||||
valid: vec![
|
||||
ResourcePile::food(1),
|
||||
ResourcePile::food(2),
|
||||
|
|
@ -591,22 +604,22 @@ mod tests {
|
|||
},
|
||||
ValidPaymentTestCase {
|
||||
name: "food to wood to ore".to_string(),
|
||||
options: PaymentOptions {
|
||||
default: ResourcePile::food(1),
|
||||
conversions: vec![
|
||||
PaymentConversion {
|
||||
from: vec![ResourcePile::food(1)],
|
||||
to: ResourcePile::wood(1),
|
||||
payment_conversion_type: PaymentConversionType::Unlimited,
|
||||
},
|
||||
PaymentConversion {
|
||||
from: vec![ResourcePile::wood(1)],
|
||||
to: ResourcePile::ore(1),
|
||||
payment_conversion_type: PaymentConversionType::Unlimited,
|
||||
},
|
||||
options: PaymentOptions::new(
|
||||
ResourcePile::food(1),
|
||||
vec![
|
||||
PaymentConversion::new(
|
||||
vec![ResourcePile::food(1)],
|
||||
ResourcePile::wood(1),
|
||||
PaymentConversionType::Unlimited,
|
||||
),
|
||||
PaymentConversion::new(
|
||||
vec![ResourcePile::wood(1)],
|
||||
ResourcePile::ore(1),
|
||||
PaymentConversionType::Unlimited,
|
||||
),
|
||||
],
|
||||
modifiers: vec![],
|
||||
},
|
||||
vec![],
|
||||
),
|
||||
valid: vec![
|
||||
ResourcePile::food(1),
|
||||
ResourcePile::wood(1),
|
||||
|
|
@ -616,22 +629,22 @@ mod tests {
|
|||
},
|
||||
ValidPaymentTestCase {
|
||||
name: "food to wood to ore with reversed conversion order".to_string(),
|
||||
options: PaymentOptions {
|
||||
default: ResourcePile::food(1),
|
||||
conversions: vec![
|
||||
PaymentConversion {
|
||||
from: vec![ResourcePile::wood(1)],
|
||||
to: ResourcePile::ore(1),
|
||||
payment_conversion_type: PaymentConversionType::Unlimited,
|
||||
},
|
||||
PaymentConversion {
|
||||
from: vec![ResourcePile::food(1)],
|
||||
to: ResourcePile::wood(1),
|
||||
payment_conversion_type: PaymentConversionType::Unlimited,
|
||||
},
|
||||
options: PaymentOptions::new(
|
||||
ResourcePile::food(1),
|
||||
vec![
|
||||
PaymentConversion::new(
|
||||
vec![ResourcePile::wood(1)],
|
||||
ResourcePile::ore(1),
|
||||
PaymentConversionType::Unlimited,
|
||||
),
|
||||
PaymentConversion::new(
|
||||
vec![ResourcePile::food(1)],
|
||||
ResourcePile::wood(1),
|
||||
PaymentConversionType::Unlimited,
|
||||
),
|
||||
],
|
||||
modifiers: vec![],
|
||||
},
|
||||
vec![],
|
||||
),
|
||||
valid: vec![
|
||||
ResourcePile::food(1),
|
||||
ResourcePile::wood(1),
|
||||
|
|
@ -641,22 +654,20 @@ mod tests {
|
|||
},
|
||||
ValidPaymentTestCase {
|
||||
name: "gold can replace anything but mood and culture tokens".to_string(),
|
||||
options: PaymentOptions {
|
||||
default: ResourcePile::food(1)
|
||||
+ ResourcePile::wood(1)
|
||||
+ ResourcePile::mood_tokens(1),
|
||||
conversions: vec![PaymentConversion {
|
||||
from: vec![
|
||||
options: PaymentOptions::new(
|
||||
ResourcePile::food(1) + ResourcePile::wood(1) + ResourcePile::mood_tokens(1),
|
||||
vec![PaymentConversion::new(
|
||||
vec![
|
||||
ResourcePile::food(1),
|
||||
ResourcePile::wood(1),
|
||||
ResourcePile::ore(1),
|
||||
ResourcePile::ideas(1),
|
||||
],
|
||||
to: ResourcePile::gold(1),
|
||||
payment_conversion_type: PaymentConversionType::Unlimited,
|
||||
}],
|
||||
modifiers: vec![],
|
||||
},
|
||||
ResourcePile::gold(1),
|
||||
PaymentConversionType::Unlimited,
|
||||
)],
|
||||
vec![],
|
||||
),
|
||||
valid: vec![
|
||||
ResourcePile::food(1) + ResourcePile::wood(1) + ResourcePile::mood_tokens(1),
|
||||
ResourcePile::food(1) + ResourcePile::gold(1) + ResourcePile::mood_tokens(1),
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use crate::advance::Advance;
|
||||
use crate::advance::{Advance, base_advance_cost, player_government};
|
||||
use crate::city_pieces::DestroyedStructures;
|
||||
use crate::consts::{UNIT_LIMIT_BARBARIANS, UNIT_LIMIT_PIRATES};
|
||||
use crate::consts::{STACK_LIMIT, UNIT_LIMIT_BARBARIANS, UNIT_LIMIT_PIRATES};
|
||||
use crate::events::{Event, EventOrigin};
|
||||
use crate::leader::LeaderAbility;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player_events::{CostInfo, TransientEvents};
|
||||
use crate::resource::ResourceType;
|
||||
use crate::special_advance::SpecialAdvance;
|
||||
use crate::unit::UnitType;
|
||||
use crate::wonder::{Wonder, wonders_built_points, wonders_owned_points};
|
||||
use crate::{
|
||||
|
|
@ -12,7 +13,7 @@ use crate::{
|
|||
city_pieces::Building::{self},
|
||||
civilization::Civilization,
|
||||
consts::{
|
||||
ADVANCE_COST, ADVANCE_VICTORY_POINTS, BUILDING_COST, BUILDING_VICTORY_POINTS,
|
||||
ADVANCE_VICTORY_POINTS, BUILDING_COST, BUILDING_VICTORY_POINTS,
|
||||
CAPTURED_LEADER_VICTORY_POINTS, CITY_LIMIT, CITY_PIECE_LIMIT, OBJECTIVE_VICTORY_POINTS,
|
||||
UNIT_LIMIT,
|
||||
},
|
||||
|
|
@ -53,7 +54,7 @@ pub struct Player {
|
|||
pub available_leaders: Vec<String>,
|
||||
pub advances: EnumSet<Advance>,
|
||||
pub great_library_advance: Option<Advance>,
|
||||
pub unlocked_special_advances: Vec<String>,
|
||||
pub special_advances: EnumSet<SpecialAdvance>,
|
||||
pub wonders_built: Vec<Wonder>,
|
||||
pub wonders_owned: EnumSet<Wonder>, // transient
|
||||
pub incident_tokens: u8,
|
||||
|
|
@ -109,7 +110,7 @@ impl Player {
|
|||
.collect(),
|
||||
civilization,
|
||||
advances: EnumSet::empty(),
|
||||
unlocked_special_advances: Vec::new(),
|
||||
special_advances: EnumSet::empty(),
|
||||
great_library_advance: None,
|
||||
incident_tokens: 0,
|
||||
completed_objectives: Vec::new(),
|
||||
|
|
@ -131,26 +132,37 @@ impl Player {
|
|||
}
|
||||
}
|
||||
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the leader does not exist
|
||||
#[must_use]
|
||||
pub fn active_leader(&self) -> Option<&Leader> {
|
||||
self.active_leader
|
||||
.as_ref()
|
||||
.and_then(|name| self.get_leader(name))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_leader(&self, name: &String) -> Option<&Leader> {
|
||||
pub fn get_leader(&self, name: &str) -> &Leader {
|
||||
self.civilization
|
||||
.leaders
|
||||
.iter()
|
||||
.find(|leader| &leader.name == name)
|
||||
.find(|leader| leader.name == name)
|
||||
.unwrap_or_else(|| panic!("Leader {name} not found"))
|
||||
}
|
||||
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the leader ability does not exist
|
||||
#[must_use]
|
||||
pub fn get_leader_ability(&self, name: &str) -> &LeaderAbility {
|
||||
self.civilization
|
||||
.leaders
|
||||
.iter()
|
||||
.find_map(|leader| leader.abilities.iter().find(|l| l.name == name))
|
||||
.unwrap_or_else(|| panic!("Leader ability {name} not found"))
|
||||
}
|
||||
|
||||
pub(crate) fn with_leader(
|
||||
leader: &str,
|
||||
game: &mut Game,
|
||||
player_index: usize,
|
||||
f: impl FnOnce(&mut Game, &Leader),
|
||||
f: impl FnOnce(&mut Game, &LeaderAbility) + Clone,
|
||||
) {
|
||||
let pos = game.players[player_index]
|
||||
.civilization
|
||||
|
|
@ -159,7 +171,9 @@ impl Player {
|
|||
.position(|l| l.name == leader)
|
||||
.expect("player should have the leader");
|
||||
let l = game.players[player_index].civilization.leaders.remove(pos);
|
||||
f(game, &l);
|
||||
for a in &l.abilities {
|
||||
(f.clone())(game, a);
|
||||
}
|
||||
game.players[player_index]
|
||||
.civilization
|
||||
.leaders
|
||||
|
|
@ -170,7 +184,7 @@ impl Player {
|
|||
pub fn available_leaders(&self) -> Vec<&Leader> {
|
||||
self.available_leaders
|
||||
.iter()
|
||||
.filter_map(|name| self.get_leader(name))
|
||||
.map(|name| self.get_leader(name))
|
||||
.collect()
|
||||
}
|
||||
|
||||
|
|
@ -196,9 +210,7 @@ impl Player {
|
|||
/// Panics if the player has advances which don't exist
|
||||
#[must_use]
|
||||
pub fn government(&self, game: &Game) -> Option<String> {
|
||||
self.advances
|
||||
.iter()
|
||||
.find_map(|advance| advance.info(game).government.clone())
|
||||
player_government(game, self.advances)
|
||||
}
|
||||
|
||||
pub fn gain_resources(&mut self, resources: ResourcePile) {
|
||||
|
|
@ -273,6 +285,11 @@ impl Player {
|
|||
self.advances.contains(advance)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn has_special_advance(&self, advance: SpecialAdvance) -> bool {
|
||||
self.special_advances.contains(advance)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn can_use_advance(&self, advance: Advance) -> bool {
|
||||
self.has_advance(advance) || self.great_library_advance.is_some_and(|a| a == advance)
|
||||
|
|
@ -292,8 +309,7 @@ impl Player {
|
|||
),
|
||||
(
|
||||
"Advances",
|
||||
(self.advances.len() + self.unlocked_special_advances.len()) as f32
|
||||
* ADVANCE_VICTORY_POINTS,
|
||||
(self.advances.len() + self.special_advances.len()) as f32 * ADVANCE_VICTORY_POINTS,
|
||||
),
|
||||
(
|
||||
"Objectives",
|
||||
|
|
@ -405,7 +421,7 @@ impl Player {
|
|||
#[must_use]
|
||||
pub fn building_cost(&self, game: &Game, building: Building, execute: CostTrigger) -> CostInfo {
|
||||
self.trigger_cost_event(
|
||||
|e| &e.construct_cost,
|
||||
|e| &e.building_cost,
|
||||
&PaymentOptions::resources(self, PaymentReason::Building, BUILDING_COST),
|
||||
&building,
|
||||
game,
|
||||
|
|
@ -417,12 +433,7 @@ impl Player {
|
|||
pub fn advance_cost(&self, advance: Advance, game: &Game, execute: CostTrigger) -> CostInfo {
|
||||
self.trigger_cost_event(
|
||||
|e| &e.advance_cost,
|
||||
&PaymentOptions::sum(
|
||||
self,
|
||||
PaymentReason::GainAdvance,
|
||||
ADVANCE_COST,
|
||||
&[ResourceType::Ideas, ResourceType::Food, ResourceType::Gold],
|
||||
),
|
||||
&base_advance_cost(self),
|
||||
&advance,
|
||||
game,
|
||||
execute,
|
||||
|
|
@ -575,6 +586,22 @@ impl Player {
|
|||
}
|
||||
cost_info
|
||||
}
|
||||
|
||||
///
|
||||
/// # Panics
|
||||
/// Panics if the custom action type does not exist for this player
|
||||
#[must_use]
|
||||
pub fn custom_action_origin(&self, custom_action_type: &CustomActionType) -> EventOrigin {
|
||||
self.custom_actions
|
||||
.get(custom_action_type)
|
||||
.cloned()
|
||||
.unwrap_or_else(|| {
|
||||
panic!(
|
||||
"Custom action {} not found for player {}",
|
||||
custom_action_type, self.index
|
||||
)
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
pub fn add_unit(player: usize, position: Position, unit_type: UnitType, game: &mut Game) {
|
||||
|
|
@ -592,13 +619,13 @@ pub fn add_unit(player: usize, position: Position, unit_type: UnitType, game: &m
|
|||
pub(crate) fn remove_unit(player: usize, id: u32, game: &mut Game) -> Unit {
|
||||
// carried units can be transferred to another ship - which has to be selected later
|
||||
let p = game.player_mut(player);
|
||||
let u = p.units.remove(
|
||||
|
||||
p.units.remove(
|
||||
p.units
|
||||
.iter()
|
||||
.position(|unit| unit.id == id)
|
||||
.expect("unit should exist"),
|
||||
);
|
||||
u
|
||||
)
|
||||
}
|
||||
|
||||
pub fn end_turn(game: &mut Game, player: usize) {
|
||||
|
|
@ -625,3 +652,11 @@ pub fn gain_resources(
|
|||
game.add_info_log_item(&log(&game.player_name(player), &resources));
|
||||
game.player_mut(player).gain_resources(resources);
|
||||
}
|
||||
|
||||
pub(crate) fn can_add_army_unit(p: &Player, position: Position) -> bool {
|
||||
p.get_units(position)
|
||||
.iter()
|
||||
.filter(|u| u.unit_type.is_army_unit())
|
||||
.count()
|
||||
< STACK_LIMIT
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::combat::Combat;
|
|||
use crate::combat_listeners::{CombatRoundEnd, CombatRoundStart};
|
||||
use crate::combat_stats::CombatStats;
|
||||
use crate::construct::ConstructInfo;
|
||||
use crate::content::custom_actions::CustomEventAction;
|
||||
use crate::content::custom_actions::CustomActionActivation;
|
||||
use crate::content::persistent_events::KilledUnits;
|
||||
use crate::cultural_influence::{InfluenceCultureInfo, InfluenceCultureOutcome};
|
||||
use crate::events::Event;
|
||||
|
|
@ -16,7 +16,7 @@ use crate::incident::PassedIncident;
|
|||
use crate::map::Terrain;
|
||||
use crate::objective_card::SelectObjectivesInfo;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::playing_actions::{PlayingAction, PlayingActionType, Recruit};
|
||||
use crate::playing_actions::{ActionPayment, PlayingActionType, Recruit};
|
||||
use crate::status_phase::StatusPhaseState;
|
||||
use crate::unit::Units;
|
||||
use crate::utils;
|
||||
|
|
@ -51,7 +51,7 @@ pub(crate) struct TransientEvents {
|
|||
pub on_influence_culture_resolve: Event<Game, InfluenceCultureOutcome>,
|
||||
pub before_move: Event<Game, MoveInfo>,
|
||||
|
||||
pub construct_cost: Event<CostInfo, Building, Game>,
|
||||
pub building_cost: Event<CostInfo, Building, Game>,
|
||||
pub advance_cost: Event<CostInfo, Advance, Game>,
|
||||
pub happiness_cost: Event<CostInfo>,
|
||||
pub recruit_cost: Event<CostInfo, Units, Player>,
|
||||
|
|
@ -70,7 +70,7 @@ impl TransientEvents {
|
|||
on_influence_culture_resolve: Event::new("on_influence_culture_resolve"),
|
||||
before_move: Event::new("before_move"),
|
||||
|
||||
construct_cost: Event::new("construct_cost"),
|
||||
building_cost: Event::new("building_cost"),
|
||||
advance_cost: Event::new("advance_cost"),
|
||||
happiness_cost: Event::new("happiness_cost"),
|
||||
recruit_cost: Event::new("recruit_cost"),
|
||||
|
|
@ -93,13 +93,14 @@ pub(crate) struct PersistentEvents {
|
|||
pub found_city: PersistentEvent<Position>,
|
||||
pub influence_culture: PersistentEvent<InfluenceCultureInfo>,
|
||||
pub explore_resolution: PersistentEvent<ExploreResolutionState>,
|
||||
pub pay_action: PersistentEvent<PlayingAction>,
|
||||
pub pay_action: PersistentEvent<ActionPayment>,
|
||||
pub play_action_card: PersistentEvent<ActionCardInfo>,
|
||||
pub play_wonder_card: PersistentEvent<WonderCardInfo>,
|
||||
|
||||
pub status_phase: PersistentEvent<StatusPhaseState>,
|
||||
pub turn_start: PersistentEvent,
|
||||
pub incident: PersistentEvent<IncidentInfo>,
|
||||
pub stop_barbarian_movement: PersistentEvent<Vec<Position>>,
|
||||
pub combat_start: PersistentEvent<Combat>,
|
||||
pub combat_round_start: PersistentEvent<CombatRoundStart>,
|
||||
pub combat_round_start_reveal_tactics: PersistentEvent<CombatRoundStart>,
|
||||
|
|
@ -109,7 +110,7 @@ pub(crate) struct PersistentEvents {
|
|||
pub combat_end: PersistentEvent<CombatStats>,
|
||||
pub units_killed: PersistentEvent<KilledUnits>,
|
||||
pub select_objective_cards: PersistentEvent<SelectObjectivesInfo>,
|
||||
pub custom_action: PersistentEvent<CustomEventAction>,
|
||||
pub custom_action: PersistentEvent<CustomActionActivation>,
|
||||
pub choose_incident: PersistentEvent<IncidentInfo>,
|
||||
pub choose_action_card: PersistentEvent,
|
||||
}
|
||||
|
|
@ -133,6 +134,7 @@ impl PersistentEvents {
|
|||
status_phase: Event::new("status_phase"),
|
||||
turn_start: Event::new("turn_start"),
|
||||
incident: Event::new("incident"),
|
||||
stop_barbarian_movement: Event::new("stop_barbarian_movement"),
|
||||
combat_start: Event::new("combat_start"),
|
||||
combat_round_start: Event::new("combat_round_start"),
|
||||
combat_round_start_reveal_tactics: Event::new("combat_round_start_reveal_tactics"),
|
||||
|
|
@ -339,3 +341,18 @@ pub struct PlayingActionInfo {
|
|||
pub player: usize,
|
||||
pub action_type: PlayingActionType,
|
||||
}
|
||||
|
||||
pub(crate) fn trigger_event_with_game_value<U, V, W>(
|
||||
game: &mut Game,
|
||||
player_index: usize,
|
||||
event: impl Fn(&mut PlayerEvents) -> &mut Event<Game, U, V, W>,
|
||||
info: &U,
|
||||
details: &V,
|
||||
extra_value: &mut W,
|
||||
) where
|
||||
W: Clone + PartialEq,
|
||||
{
|
||||
let e = event(&mut game.players[player_index].events).take();
|
||||
e.trigger(game, info, details, extra_value);
|
||||
event(&mut game.players[player_index].events).set(e);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
use itertools::{Either, Itertools};
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action_card::{ActionCardInfo, combat_requirement_met, play_action_card};
|
||||
use crate::advance::{Advance, gain_advance_without_payment};
|
||||
use crate::city::{MoodState, found_city};
|
||||
use crate::action_card::{can_play_action_card, play_action_card};
|
||||
use crate::advance::{AdvanceAction, base_advance_cost, gain_advance_without_payment};
|
||||
use crate::city::found_city;
|
||||
use crate::collect::{PositionCollection, collect};
|
||||
use crate::construct::Construct;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_actions::{CustomActionType, CustomEventAction, execute_custom_action};
|
||||
use crate::content::persistent_events::{PaymentRequest, PersistentEventType};
|
||||
use crate::content::wonders::{great_lighthouse_city, great_lighthouse_spawns};
|
||||
use crate::content::custom_actions::{
|
||||
CustomAction, CustomActionActivation, CustomActionType, can_play_custom_action,
|
||||
execute_custom_action,
|
||||
};
|
||||
use crate::content::persistent_events::{
|
||||
PaymentRequest, PersistentEventType, TriggerPersistentEventParams, trigger_persistent_event_ext,
|
||||
};
|
||||
use crate::cultural_influence::{InfluenceCultureAttempt, influence_culture_attempt};
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::GameState;
|
||||
use crate::happiness::increase_happiness;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
|
|
@ -137,57 +141,10 @@ impl PlayingActionType {
|
|||
|
||||
match self {
|
||||
PlayingActionType::Custom(c) => {
|
||||
let info = c.info();
|
||||
if !p.custom_actions.contains_key(c) {
|
||||
return Err("Custom action not available".to_string());
|
||||
}
|
||||
|
||||
if info.once_per_turn && p.played_once_per_turn_actions.contains(c) {
|
||||
return Err("Custom action already played this turn".to_string());
|
||||
}
|
||||
|
||||
let can_play = match c {
|
||||
CustomActionType::Bartering => !p.action_cards.is_empty(),
|
||||
CustomActionType::Sports => can_use_sports(p),
|
||||
CustomActionType::Theaters => {
|
||||
p.resources.culture_tokens > 0 || p.resources.mood_tokens > 0
|
||||
}
|
||||
CustomActionType::ForcedLabor => any_angry(p),
|
||||
CustomActionType::GreatStatue => !p.objective_cards.is_empty(),
|
||||
CustomActionType::GreatLighthouse => {
|
||||
great_lighthouse_city(p).can_activate()
|
||||
&& p.available_units().ships > 0
|
||||
&& !great_lighthouse_spawns(game, p.index).is_empty()
|
||||
}
|
||||
_ => true,
|
||||
};
|
||||
if !can_play {
|
||||
return Err("Cannot play custom action".to_string());
|
||||
}
|
||||
can_play_custom_action(game, p, *c)?;
|
||||
}
|
||||
PlayingActionType::ActionCard(id) => {
|
||||
if !p.action_cards.contains(id) {
|
||||
return Err("Action card not available".to_string());
|
||||
}
|
||||
|
||||
let civil_card = game.cache.get_civil_card(*id);
|
||||
let mut satisfying_action: Option<usize> = None;
|
||||
if let Some(r) = &civil_card.combat_requirement {
|
||||
if let Some(action_log_index) =
|
||||
combat_requirement_met(game, player_index, *id, r)
|
||||
{
|
||||
satisfying_action = Some(action_log_index);
|
||||
} else {
|
||||
return Err("Requirement not met".to_string());
|
||||
}
|
||||
}
|
||||
if !(civil_card.can_play)(
|
||||
game,
|
||||
p,
|
||||
&ActionCardInfo::new(*id, satisfying_action, None),
|
||||
) {
|
||||
return Err("Cannot play action card".to_string());
|
||||
}
|
||||
can_play_action_card(game, p, *id)?;
|
||||
}
|
||||
PlayingActionType::WonderCard(name) => {
|
||||
if !p.wonder_cards.contains(name) {
|
||||
|
|
@ -227,19 +184,14 @@ impl PlayingActionType {
|
|||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
|
||||
pub enum PlayingAction {
|
||||
Advance {
|
||||
advance: Advance,
|
||||
payment: ResourcePile,
|
||||
},
|
||||
FoundCity {
|
||||
settler: u32,
|
||||
},
|
||||
Advance(AdvanceAction),
|
||||
FoundCity { settler: u32 },
|
||||
Construct(Construct),
|
||||
Collect(Collect),
|
||||
Recruit(Recruit),
|
||||
IncreaseHappiness(IncreaseHappiness),
|
||||
InfluenceCultureAttempt(InfluenceCultureAttempt),
|
||||
Custom(CustomEventAction),
|
||||
Custom(CustomAction),
|
||||
ActionCard(u8),
|
||||
WonderCard(Wonder),
|
||||
EndTurn,
|
||||
|
|
@ -261,46 +213,40 @@ impl PlayingAction {
|
|||
game.actions_left -= 1;
|
||||
}
|
||||
|
||||
if let PlayingActionType::Custom(c) = playing_action_type {
|
||||
if c.info().once_per_turn {
|
||||
game.players[player_index]
|
||||
.played_once_per_turn_actions
|
||||
.push(c);
|
||||
let origin_override = match playing_action_type {
|
||||
PlayingActionType::Custom(c) => {
|
||||
if c.info().once_per_turn {
|
||||
game.players[player_index]
|
||||
.played_once_per_turn_actions
|
||||
.push(c);
|
||||
}
|
||||
Some(game.player(player_index).custom_action_origin(&c))
|
||||
}
|
||||
}
|
||||
|
||||
self.on_pay_action(game, player_index)
|
||||
}
|
||||
|
||||
pub(crate) fn on_pay_action(self, game: &mut Game, player_index: usize) -> Result<(), String> {
|
||||
let Some(a) = game.trigger_persistent_event(
|
||||
&[player_index],
|
||||
|e| &mut e.pay_action,
|
||||
self,
|
||||
PersistentEventType::PayAction,
|
||||
) else {
|
||||
return Ok(());
|
||||
PlayingActionType::ActionCard(c) => Some(EventOrigin::CivilCard(c)),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
a.execute_without_cost(game, player_index)
|
||||
ActionPayment::new(self).on_pay_action(game, player_index, origin_override)
|
||||
}
|
||||
|
||||
pub(crate) fn execute_without_cost(
|
||||
self,
|
||||
game: &mut Game,
|
||||
player_index: usize,
|
||||
action_payment: ResourcePile,
|
||||
) -> Result<(), String> {
|
||||
use crate::construct;
|
||||
use PlayingAction::*;
|
||||
match self {
|
||||
Advance { advance, payment } => {
|
||||
Advance(a) => {
|
||||
let advance = a.advance;
|
||||
if !game.player(player_index).can_advance(advance, game) {
|
||||
return Err("Cannot advance".to_string());
|
||||
}
|
||||
game.player(player_index)
|
||||
.advance_cost(advance, game, game.execute_cost_trigger())
|
||||
.pay(game, &payment);
|
||||
gain_advance_without_payment(game, advance, player_index, payment, true);
|
||||
.pay(game, &a.payment);
|
||||
gain_advance_without_payment(game, advance, player_index, a.payment, true);
|
||||
}
|
||||
FoundCity { settler } => {
|
||||
let settler = remove_unit(player_index, settler, game);
|
||||
|
|
@ -312,15 +258,13 @@ impl PlayingAction {
|
|||
Construct(c) => construct::construct(game, player_index, &c)?,
|
||||
Collect(c) => collect(game, player_index, &c)?,
|
||||
Recruit(r) => recruit(game, player_index, r)?,
|
||||
IncreaseHappiness(i) => {
|
||||
increase_happiness(
|
||||
game,
|
||||
player_index,
|
||||
&i.happiness_increases,
|
||||
Some(i.payment),
|
||||
&i.action_type,
|
||||
);
|
||||
}
|
||||
IncreaseHappiness(i) => increase_happiness(
|
||||
game,
|
||||
player_index,
|
||||
&i.happiness_increases,
|
||||
Some(i.payment),
|
||||
&i.action_type,
|
||||
)?,
|
||||
InfluenceCultureAttempt(c) => {
|
||||
influence_culture_attempt(game, player_index, &c.selected_structure)?;
|
||||
}
|
||||
|
|
@ -333,7 +277,11 @@ impl PlayingAction {
|
|||
);
|
||||
}
|
||||
Custom(custom_action) => {
|
||||
execute_custom_action(game, player_index, custom_action);
|
||||
execute_custom_action(
|
||||
game,
|
||||
player_index,
|
||||
CustomActionActivation::new(custom_action, action_payment),
|
||||
);
|
||||
}
|
||||
EndTurn => game.next_turn(),
|
||||
}
|
||||
|
|
@ -343,7 +291,7 @@ impl PlayingAction {
|
|||
#[must_use]
|
||||
pub fn playing_action_type(&self) -> PlayingActionType {
|
||||
match self {
|
||||
PlayingAction::Advance { .. } => PlayingActionType::Advance,
|
||||
PlayingAction::Advance(_) => PlayingActionType::Advance,
|
||||
PlayingAction::FoundCity { .. } => PlayingActionType::FoundCity,
|
||||
PlayingAction::Construct(_) => PlayingActionType::Construct,
|
||||
PlayingAction::Collect(c) => allowed_types(
|
||||
|
|
@ -359,6 +307,7 @@ impl PlayingAction {
|
|||
&[
|
||||
PlayingActionType::IncreaseHappiness,
|
||||
PlayingActionType::Custom(CustomActionType::VotingIncreaseHappiness),
|
||||
PlayingActionType::Custom(CustomActionType::StatesmanIncreaseHappiness),
|
||||
],
|
||||
),
|
||||
PlayingAction::InfluenceCultureAttempt(i) => allowed_types(
|
||||
|
|
@ -370,7 +319,7 @@ impl PlayingAction {
|
|||
),
|
||||
PlayingAction::ActionCard(a) => PlayingActionType::ActionCard(*a),
|
||||
PlayingAction::WonderCard(name) => PlayingActionType::WonderCard(*name),
|
||||
PlayingAction::Custom(c) => PlayingActionType::Custom(c.action.clone()),
|
||||
PlayingAction::Custom(c) => PlayingActionType::Custom(c.action),
|
||||
PlayingAction::EndTurn => PlayingActionType::EndTurn,
|
||||
}
|
||||
}
|
||||
|
|
@ -384,10 +333,28 @@ fn allowed_types(
|
|||
playing_action_type.clone()
|
||||
}
|
||||
|
||||
#[derive(Default, Clone, Debug, PartialEq)]
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub enum ActionResourceCost {
|
||||
Resources(ResourcePile),
|
||||
AdvanceCostWithoutDiscount,
|
||||
}
|
||||
|
||||
impl ActionResourceCost {
|
||||
#[must_use]
|
||||
pub fn free() -> Self {
|
||||
ActionResourceCost::Resources(ResourcePile::empty())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn resources(cost: ResourcePile) -> Self {
|
||||
ActionResourceCost::Resources(cost)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq)]
|
||||
pub struct ActionCost {
|
||||
pub free: bool,
|
||||
pub cost: ResourcePile,
|
||||
pub cost: ActionResourceCost,
|
||||
}
|
||||
|
||||
impl ActionCost {
|
||||
|
|
@ -402,52 +369,43 @@ impl ActionCost {
|
|||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn payment_options(&self, player: &Player) -> PaymentOptions {
|
||||
match &self.cost {
|
||||
ActionResourceCost::Resources(c) => {
|
||||
PaymentOptions::resources(player, PaymentReason::ActionCard, c.clone())
|
||||
}
|
||||
ActionResourceCost::AdvanceCostWithoutDiscount => base_advance_cost(player),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
impl ActionCost {
|
||||
#[must_use]
|
||||
pub fn cost(cost: ResourcePile) -> Self {
|
||||
Self::new(true, cost)
|
||||
Self::new(true, ActionResourceCost::resources(cost))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn regular() -> Self {
|
||||
Self::new(false, ResourcePile::empty())
|
||||
Self::new(false, ActionResourceCost::free())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn regular_with_cost(cost: ResourcePile) -> Self {
|
||||
Self::new(false, cost)
|
||||
Self::new(false, ActionResourceCost::resources(cost))
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn free() -> Self {
|
||||
Self::new(true, ResourcePile::empty())
|
||||
Self::new(true, ActionResourceCost::free())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn new(free: bool, cost: ResourcePile) -> Self {
|
||||
pub fn new(free: bool, cost: ActionResourceCost) -> Self {
|
||||
Self { free, cost }
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn payment_options(&self, player: &Player) -> PaymentOptions {
|
||||
PaymentOptions::resources(player, PaymentReason::ActionCard, self.cost.clone())
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn base_and_custom_action(
|
||||
actions: Vec<PlayingActionType>,
|
||||
) -> (Option<PlayingActionType>, Option<CustomActionType>) {
|
||||
let (mut custom, mut action): (Vec<_>, Vec<_>) = actions.into_iter().partition_map(|a| {
|
||||
if let PlayingActionType::Custom(c) = a {
|
||||
Either::Left(c.clone())
|
||||
} else {
|
||||
Either::Right(a.clone())
|
||||
}
|
||||
});
|
||||
(action.pop(), custom.pop())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
@ -455,26 +413,54 @@ pub(crate) fn base_or_custom_available(
|
|||
game: &Game,
|
||||
player: usize,
|
||||
action: PlayingActionType,
|
||||
custom: &CustomActionType,
|
||||
custom: Vec<CustomActionType>,
|
||||
) -> Vec<PlayingActionType> {
|
||||
vec![action, custom.playing_action_type()]
|
||||
vec![action]
|
||||
.into_iter()
|
||||
.chain(custom.into_iter().map(|c| c.playing_action_type()))
|
||||
.filter_map(|a| a.is_available(game, player).map(|()| a).ok())
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn any_non_happy(player: &Player) -> bool {
|
||||
player
|
||||
.cities
|
||||
.iter()
|
||||
.any(|city| city.mood_state != MoodState::Happy)
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct ActionPayment {
|
||||
pub action: PlayingAction,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "ResourcePile::is_empty")]
|
||||
pub payment: ResourcePile,
|
||||
}
|
||||
|
||||
fn any_angry(player: &Player) -> bool {
|
||||
player
|
||||
.cities
|
||||
.iter()
|
||||
.any(|city| city.mood_state == MoodState::Angry)
|
||||
impl ActionPayment {
|
||||
#[must_use]
|
||||
pub fn new(action: PlayingAction) -> Self {
|
||||
Self {
|
||||
action,
|
||||
payment: ResourcePile::empty(),
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn on_pay_action(
|
||||
self,
|
||||
game: &mut Game,
|
||||
player_index: usize,
|
||||
origin_override: Option<EventOrigin>,
|
||||
) -> Result<(), String> {
|
||||
let Some(a) = trigger_persistent_event_ext(
|
||||
game,
|
||||
&[player_index],
|
||||
|e| &mut e.pay_action,
|
||||
self,
|
||||
PersistentEventType::PayAction,
|
||||
TriggerPersistentEventParams {
|
||||
origin_override,
|
||||
..Default::default()
|
||||
},
|
||||
) else {
|
||||
return Ok(());
|
||||
};
|
||||
|
||||
a.action.execute_without_cost(game, player_index, a.payment)
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn pay_for_action() -> Builtin {
|
||||
|
|
@ -483,12 +469,13 @@ pub(crate) fn pay_for_action() -> Builtin {
|
|||
|e| &mut e.pay_action,
|
||||
0,
|
||||
|game, player_index, a| {
|
||||
if matches!(a, PlayingAction::IncreaseHappiness(_)) {
|
||||
if matches!(a.action, PlayingAction::IncreaseHappiness(_)) {
|
||||
// handled in the happiness action
|
||||
return None;
|
||||
}
|
||||
|
||||
let payment_options = a
|
||||
.action
|
||||
.playing_action_type()
|
||||
.cost(game)
|
||||
.payment_options(game.player(player_index));
|
||||
|
|
@ -501,7 +488,8 @@ pub(crate) fn pay_for_action() -> Builtin {
|
|||
"Pay for action",
|
||||
)])
|
||||
},
|
||||
|game, s, _| {
|
||||
|game, s, a| {
|
||||
a.payment = s.choice[0].clone();
|
||||
game.add_info_log_item(&format!(
|
||||
"{} paid {} for the action",
|
||||
s.player_name, s.choice[0]
|
||||
|
|
@ -510,13 +498,3 @@ pub(crate) fn pay_for_action() -> Builtin {
|
|||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn can_use_sports(p: &Player) -> bool {
|
||||
if !any_non_happy(p) {
|
||||
return false;
|
||||
}
|
||||
if p.resources.culture_tokens > 0 {
|
||||
return true;
|
||||
}
|
||||
p.wonders_owned.contains(Wonder::Colosseum) && p.resources.mood_tokens > 0
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,16 +2,19 @@ use crate::combat;
|
|||
use crate::consts::STACK_LIMIT;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::game::Game;
|
||||
use crate::map::home_position;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::{CostTrigger, Player, add_unit};
|
||||
use crate::player_events::CostInfo;
|
||||
use crate::playing_actions::Recruit;
|
||||
use crate::position::Position;
|
||||
use crate::special_advance::SpecialAdvance;
|
||||
use crate::unit::{UnitType, Units, kill_units, set_unit_position};
|
||||
use itertools::Itertools;
|
||||
|
||||
pub(crate) fn recruit(game: &mut Game, player_index: usize, r: Recruit) -> Result<(), String> {
|
||||
let cost = recruit_cost(
|
||||
game,
|
||||
game.player(player_index),
|
||||
&r.units,
|
||||
r.city_position,
|
||||
|
|
@ -112,6 +115,7 @@ pub(crate) fn on_recruit(game: &mut Game, player_index: usize, r: Recruit) {
|
|||
///
|
||||
/// Errors if the cost cannot be paid
|
||||
pub fn recruit_cost(
|
||||
game: &Game,
|
||||
player: &Player,
|
||||
units: &Units,
|
||||
city_position: Position,
|
||||
|
|
@ -133,7 +137,7 @@ pub fn recruit_cost(
|
|||
if require_replace != replaced_units {
|
||||
return Err("Invalid replacement".to_string());
|
||||
}
|
||||
recruit_cost_without_replaced(player, units, city_position, leader_name, execute)
|
||||
recruit_cost_without_replaced(game, player, units, city_position, leader_name, execute)
|
||||
}
|
||||
|
||||
///
|
||||
|
|
@ -141,6 +145,7 @@ pub fn recruit_cost(
|
|||
///
|
||||
/// Errors if the cost cannot be paid
|
||||
pub fn recruit_cost_without_replaced(
|
||||
game: &Game,
|
||||
player: &Player,
|
||||
units: &Units,
|
||||
city_position: Position,
|
||||
|
|
@ -148,7 +153,10 @@ pub fn recruit_cost_without_replaced(
|
|||
execute: CostTrigger,
|
||||
) -> Result<CostInfo, String> {
|
||||
let city = player.get_city(city_position);
|
||||
if (units.cavalry > 0 || units.elephants > 0) && city.pieces.market.is_none() {
|
||||
if city.pieces.market.is_none()
|
||||
&& (units.elephants > 0
|
||||
|| (units.cavalry > 0 && !is_cavalry_province_city(player, city_position, game)))
|
||||
{
|
||||
return Err("No market".to_string());
|
||||
}
|
||||
if units.ships > 0 && city.pieces.port.is_none() {
|
||||
|
|
@ -204,3 +212,8 @@ pub fn recruit_cost_without_replaced(
|
|||
}
|
||||
Ok(cost)
|
||||
}
|
||||
|
||||
fn is_cavalry_province_city(player: &Player, city: Position, game: &Game) -> bool {
|
||||
player.has_special_advance(SpecialAdvance::Provinces)
|
||||
&& home_position(game, player).distance(city) >= 3
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,67 +2,113 @@ use crate::ability_initializer::AbilityInitializerSetup;
|
|||
use crate::ability_initializer::{AbilityInitializerBuilder, AbilityListeners};
|
||||
use crate::advance::Advance;
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
use enumset::EnumSetType;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
pub struct SpecialAdvance {
|
||||
pub advance: Advance,
|
||||
#[derive(EnumSetType, Serialize, Deserialize, Debug, Ord, PartialOrd, Hash)]
|
||||
pub enum SpecialAdvance {
|
||||
// Maya
|
||||
// Terrace,
|
||||
|
||||
// Rome
|
||||
Aqueduct,
|
||||
RomanRoads,
|
||||
Captivi,
|
||||
Provinces,
|
||||
}
|
||||
|
||||
#[allow(clippy::trivially_copy_pass_by_ref)]
|
||||
impl SpecialAdvance {
|
||||
#[must_use]
|
||||
pub fn info<'a>(&self, game: &'a Game) -> &'a SpecialAdvanceInfo {
|
||||
game.cache.get_special_advance(*self)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn name<'a>(&self, game: &'a Game) -> &'a str {
|
||||
self.info(game).name.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub enum SpecialAdvanceRequirement {
|
||||
AnyGovernment,
|
||||
Advance(Advance),
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SpecialAdvanceInfo {
|
||||
pub advance: SpecialAdvance,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub required_advance: Advance,
|
||||
pub requirement: SpecialAdvanceRequirement,
|
||||
pub listeners: AbilityListeners,
|
||||
}
|
||||
|
||||
impl SpecialAdvance {
|
||||
impl SpecialAdvanceInfo {
|
||||
#[must_use]
|
||||
pub fn builder(
|
||||
advance: Advance,
|
||||
advance: SpecialAdvance,
|
||||
requirement: SpecialAdvanceRequirement,
|
||||
name: &str,
|
||||
required_advance: Advance,
|
||||
description: &str,
|
||||
) -> SpecialAdvanceBuilder {
|
||||
SpecialAdvanceBuilder::new(advance, name.to_string(), required_advance)
|
||||
SpecialAdvanceBuilder::new(
|
||||
advance,
|
||||
requirement,
|
||||
name.to_string(),
|
||||
description.to_string(),
|
||||
)
|
||||
}
|
||||
|
||||
fn new(
|
||||
advance: Advance,
|
||||
advance: SpecialAdvance,
|
||||
name: String,
|
||||
description: String,
|
||||
required_advance: Advance,
|
||||
requirement: SpecialAdvanceRequirement,
|
||||
listeners: AbilityListeners,
|
||||
) -> Self {
|
||||
Self {
|
||||
advance,
|
||||
name,
|
||||
description,
|
||||
required_advance,
|
||||
requirement,
|
||||
listeners,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct SpecialAdvanceBuilder {
|
||||
advance: Advance,
|
||||
advance: SpecialAdvance,
|
||||
name: String,
|
||||
descriptions: Vec<String>,
|
||||
required_advance: Advance,
|
||||
description: String,
|
||||
requirement: SpecialAdvanceRequirement,
|
||||
builder: AbilityInitializerBuilder,
|
||||
}
|
||||
|
||||
impl SpecialAdvanceBuilder {
|
||||
fn new(advance: Advance, name: String, required_advance: Advance) -> Self {
|
||||
fn new(
|
||||
advance: SpecialAdvance,
|
||||
requirement: SpecialAdvanceRequirement,
|
||||
name: String,
|
||||
description: String,
|
||||
) -> Self {
|
||||
Self {
|
||||
advance,
|
||||
name,
|
||||
descriptions: Vec::new(),
|
||||
required_advance,
|
||||
description,
|
||||
requirement,
|
||||
builder: AbilityInitializerBuilder::new(),
|
||||
}
|
||||
}
|
||||
|
||||
pub fn build(self) -> SpecialAdvance {
|
||||
SpecialAdvance::new(
|
||||
pub fn build(self) -> SpecialAdvanceInfo {
|
||||
SpecialAdvanceInfo::new(
|
||||
self.advance,
|
||||
self.name,
|
||||
String::from("✦ ") + &self.descriptions.join("\n✦ "),
|
||||
self.required_advance,
|
||||
self.description,
|
||||
self.requirement,
|
||||
self.builder.build(),
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,8 @@ use crate::consts::AGES;
|
|||
use crate::content::builtin::Builtin;
|
||||
use crate::content::persistent_events::{
|
||||
AdvanceRequest, EventResponse, PaymentRequest, PersistentEventRequest, PersistentEventType,
|
||||
PlayerRequest, PositionRequest,
|
||||
PlayerRequest, PositionRequest, TriggerPersistentEventParams,
|
||||
trigger_persistent_event_with_listener,
|
||||
};
|
||||
use crate::objective_card::{
|
||||
gain_objective_card_from_pile, present_objective_cards, status_phase_completable,
|
||||
|
|
@ -80,14 +81,14 @@ pub(crate) fn play_status_phase(game: &mut Game, mut phase: StatusPhaseState) {
|
|||
use StatusPhaseState::*;
|
||||
|
||||
loop {
|
||||
phase = match game.trigger_persistent_event_with_listener(
|
||||
phase = match trigger_persistent_event_with_listener(
|
||||
game,
|
||||
&game.human_players(game.starting_player_index),
|
||||
|events| &mut events.status_phase,
|
||||
&game.cache.status_phase_handler(&phase).listeners.clone(),
|
||||
phase,
|
||||
PersistentEventType::StatusPhase,
|
||||
None,
|
||||
|_| {},
|
||||
TriggerPersistentEventParams::default(),
|
||||
) {
|
||||
Some(s) => s,
|
||||
None => return,
|
||||
|
|
@ -494,10 +495,9 @@ fn player_that_chooses_next_first_player(players: &[&Player]) -> usize {
|
|||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use crate::content;
|
||||
use crate::civilization::Civilization;
|
||||
use crate::player::Player;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use content::civilizations::tests as civ;
|
||||
|
||||
fn assert_next_player(
|
||||
name: &str,
|
||||
|
|
@ -506,11 +506,11 @@ mod tests {
|
|||
player2_mood: u8,
|
||||
expected_player_index: usize,
|
||||
) {
|
||||
let mut player0 = Player::new(civ::get_test_civilization(), 0);
|
||||
let mut player0 = Player::new(get_test_civilization(), 0);
|
||||
player0.gain_resources(ResourcePile::mood_tokens(player0_mood));
|
||||
let mut player1 = Player::new(civ::get_test_civilization(), 1);
|
||||
let mut player1 = Player::new(get_test_civilization(), 1);
|
||||
player1.gain_resources(ResourcePile::mood_tokens(player1_mood));
|
||||
let mut player2 = Player::new(civ::get_test_civilization(), 2);
|
||||
let mut player2 = Player::new(get_test_civilization(), 2);
|
||||
player2.gain_resources(ResourcePile::mood_tokens(player2_mood));
|
||||
let players = vec![&player2, &player1, &player0];
|
||||
let got = super::player_that_chooses_next_first_player(&players);
|
||||
|
|
@ -530,4 +530,9 @@ mod tests {
|
|||
2,
|
||||
);
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_test_civilization() -> Civilization {
|
||||
Civilization::new("test", vec![], vec![])
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -353,6 +353,54 @@ impl Units {
|
|||
}
|
||||
units_to_replace
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn to_string(&self, leader_name: Option<&String>) -> String {
|
||||
let mut unit_types = Vec::new();
|
||||
if self.settlers > 0 {
|
||||
unit_types.push(format!(
|
||||
"{} {}",
|
||||
self.settlers,
|
||||
if self.settlers == 1 {
|
||||
"settler"
|
||||
} else {
|
||||
"settlers"
|
||||
}
|
||||
));
|
||||
}
|
||||
if self.infantry > 0 {
|
||||
unit_types.push(format!("{} infantry", self.infantry,));
|
||||
}
|
||||
if self.ships > 0 {
|
||||
unit_types.push(format!(
|
||||
"{} {}",
|
||||
self.ships,
|
||||
if self.ships == 1 { "ship" } else { "ships" }
|
||||
));
|
||||
}
|
||||
if self.cavalry > 0 {
|
||||
unit_types.push(format!("{} cavalry", self.cavalry,));
|
||||
}
|
||||
if self.elephants > 0 {
|
||||
unit_types.push(format!(
|
||||
"{} {}",
|
||||
self.elephants,
|
||||
if self.elephants == 1 {
|
||||
"elephant"
|
||||
} else {
|
||||
"elephants"
|
||||
}
|
||||
));
|
||||
}
|
||||
if self.leaders > 0 {
|
||||
unit_types.push(if self.leaders == 1 {
|
||||
leader_name.map_or("a leader", |v| v).to_string()
|
||||
} else {
|
||||
format!("{} leaders", self.leaders)
|
||||
});
|
||||
}
|
||||
utils::format_and(&unit_types, "no units")
|
||||
}
|
||||
}
|
||||
|
||||
impl Default for Units {
|
||||
|
|
@ -433,55 +481,6 @@ impl Iterator for UnitsIntoIterator {
|
|||
}
|
||||
}
|
||||
|
||||
impl Display for Units {
|
||||
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
|
||||
let mut unit_types = Vec::new();
|
||||
if self.settlers > 0 {
|
||||
unit_types.push(format!(
|
||||
"{} {}",
|
||||
self.settlers,
|
||||
if self.settlers == 1 {
|
||||
"settler"
|
||||
} else {
|
||||
"settlers"
|
||||
}
|
||||
));
|
||||
}
|
||||
if self.infantry > 0 {
|
||||
unit_types.push(format!("{} infantry", self.infantry,));
|
||||
}
|
||||
if self.ships > 0 {
|
||||
unit_types.push(format!(
|
||||
"{} {}",
|
||||
self.ships,
|
||||
if self.ships == 1 { "ship" } else { "ships" }
|
||||
));
|
||||
}
|
||||
if self.cavalry > 0 {
|
||||
unit_types.push(format!("{} cavalry", self.cavalry,));
|
||||
}
|
||||
if self.elephants > 0 {
|
||||
unit_types.push(format!(
|
||||
"{} {}",
|
||||
self.elephants,
|
||||
if self.elephants == 1 {
|
||||
"elephant"
|
||||
} else {
|
||||
"elephants"
|
||||
}
|
||||
));
|
||||
}
|
||||
if self.leaders > 0 {
|
||||
unit_types.push(if self.leaders == 1 {
|
||||
String::from("a leader")
|
||||
} else {
|
||||
format!("{} leaders", self.leaders)
|
||||
});
|
||||
}
|
||||
write!(f, "{}", utils::format_and(&unit_types, "no units"))
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn carried_units(carrier: u32, player: &Player) -> Vec<u32> {
|
||||
player
|
||||
|
|
@ -668,7 +667,10 @@ pub(crate) fn choose_carried_units_to_remove() -> Builtin {
|
|||
game.add_info_log_item(&format!(
|
||||
"{} killed carried units: {}",
|
||||
s.player_name,
|
||||
units.into_iter().collect::<Units>()
|
||||
units
|
||||
.into_iter()
|
||||
.collect::<Units>()
|
||||
.to_string(game.player(s.player_index).active_leader.as_ref())
|
||||
));
|
||||
}
|
||||
kill_units_without_event(game, &s.choice, s.player_index, e.killer);
|
||||
|
|
|
|||
|
|
@ -96,7 +96,7 @@ pub fn median(list: &[f64]) -> f64 {
|
|||
sorted_list.sort_by(f64::total_cmp);
|
||||
let len = sorted_list.len();
|
||||
if len % 2 == 0 {
|
||||
(sorted_list[len / 2 - 1] + sorted_list[len / 2]) / 2.0
|
||||
f64::midpoint(sorted_list[len / 2 - 1], sorted_list[len / 2])
|
||||
} else {
|
||||
sorted_list[len / 2]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -79,7 +79,7 @@ impl WonderInfo {
|
|||
pub struct WonderBuilder {
|
||||
wonder: Wonder,
|
||||
name: String,
|
||||
descriptions: Vec<String>,
|
||||
description: String,
|
||||
cost: PaymentOptions,
|
||||
required_advance: Advance,
|
||||
placement_requirement: Option<PlacementChecker>,
|
||||
|
|
@ -99,7 +99,7 @@ impl WonderBuilder {
|
|||
Self {
|
||||
wonder,
|
||||
name: name.to_string(),
|
||||
descriptions: vec![description.to_string()],
|
||||
description: description.to_string(),
|
||||
cost,
|
||||
required_advance,
|
||||
placement_requirement: None,
|
||||
|
|
@ -132,7 +132,7 @@ impl WonderBuilder {
|
|||
WonderInfo {
|
||||
wonder: self.wonder,
|
||||
name: self.name,
|
||||
description: String::from("✦ ") + &self.descriptions.join("\n✦ "),
|
||||
description: self.description,
|
||||
cost: self.cost,
|
||||
required_advance: self.required_advance,
|
||||
placement_requirement: self.placement_requirement,
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::common::{TestAction, move_action};
|
||||
use crate::common::{TestAction, move_action, payment_response};
|
||||
use common::JsonTest;
|
||||
use server::action::Action;
|
||||
use server::card::HandCard;
|
||||
|
|
@ -21,15 +21,8 @@ fn test_advance() {
|
|||
JSON.test(
|
||||
"advance",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(2)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(2))).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Storage)),
|
||||
|
|
@ -58,22 +51,17 @@ fn test_hero_general() {
|
|||
0,
|
||||
move_action(vec![0, 1, 2, 3, 4, 5], Position::from_offset("C1")),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(0, Action::Response(EventResponse::SelectHandCards(vec![]))),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(5)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(5))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
"C1",
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::mood_tokens(1)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::mood_tokens(1))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
|
|
@ -89,15 +77,9 @@ fn test_spy() {
|
|||
JSON.test(
|
||||
"spy",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(7)))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(7))).skip_json(),
|
||||
TestAction::not_undoable(0, payment_response(ResourcePile::culture_tokens(1)))
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
@ -129,7 +111,7 @@ fn test_great_ideas() {
|
|||
0,
|
||||
move_action(vec![0, 1, 2, 3, 4, 5], Position::from_offset("C1")),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(11))),
|
||||
],
|
||||
);
|
||||
|
|
@ -140,34 +122,15 @@ fn test_mercenaries() {
|
|||
JSON.test(
|
||||
"mercenaries",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(13)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectPositions(vec![
|
||||
Position::from_offset("A3"),
|
||||
Position::from_offset("B3"),
|
||||
])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::ore(2)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
"A3",
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(13))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
"B2",
|
||||
"B3",
|
||||
)])),
|
||||
),
|
||||
)
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(0, payment_response(ResourcePile::ore(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -177,8 +140,7 @@ fn test_cultural_takeover() {
|
|||
JSON.test(
|
||||
"cultural_takeover",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(15)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(15))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(PlayingAction::InfluenceCultureAttempt(
|
||||
|
|
@ -188,13 +150,8 @@ fn test_cultural_takeover() {
|
|||
),
|
||||
)),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
2,
|
||||
)])),
|
||||
),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(0, payment_response(ResourcePile::culture_tokens(2))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -204,15 +161,8 @@ fn test_city_development() {
|
|||
JSON.test(
|
||||
"city_development",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(17)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(17))).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Construct(construct::Construct::new(
|
||||
|
|
@ -230,8 +180,7 @@ fn test_production_focus() {
|
|||
JSON.test(
|
||||
"production_focus",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(19)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(19))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(PlayingAction::Collect(playing_actions::Collect::new(
|
||||
|
|
@ -258,24 +207,17 @@ fn test_explorer() {
|
|||
JSON.test(
|
||||
"explorer",
|
||||
vec![
|
||||
TestAction::undoable(1, Action::Playing(PlayingAction::ActionCard(21)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(1, Action::Playing(PlayingAction::ActionCard(21))).skip_json(),
|
||||
TestAction::undoable(1, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
"B6",
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(1, Action::Response(EventResponse::ExploreResolution(0)))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
|
|
@ -291,15 +233,8 @@ fn test_negotiations() {
|
|||
JSON.test(
|
||||
"negotiations",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(23)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(23))).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::not_undoable(0, Action::Playing(PlayingAction::EndTurn))
|
||||
.with_pre_assert(|game| {
|
||||
assert!(
|
||||
|
|
@ -316,7 +251,7 @@ fn test_negotiations() {
|
|||
.any(|r| r.destination == Position::from_offset("B1")))
|
||||
);
|
||||
})
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(1, Action::Playing(PlayingAction::EndTurn))
|
||||
.with_pre_assert(|game| {
|
||||
assert!(
|
||||
|
|
@ -333,7 +268,7 @@ fn test_negotiations() {
|
|||
.any(|r| r.destination == Position::from_offset("C2")))
|
||||
);
|
||||
})
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(0, move_action(vec![0], Position::from_offset("B1"))),
|
||||
],
|
||||
);
|
||||
|
|
@ -344,17 +279,9 @@ fn test_assassination() {
|
|||
JSON.test(
|
||||
"assassination",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(27)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(0, Action::Playing(PlayingAction::EndTurn))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(27))).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::not_undoable(0, Action::Playing(PlayingAction::EndTurn)).skip_json(),
|
||||
TestAction::not_undoable(1, Action::Playing(PlayingAction::EndTurn)).with_pre_assert(
|
||||
|game| {
|
||||
assert_eq!(game.actions_left, 2);
|
||||
|
|
@ -369,8 +296,7 @@ fn test_overproduction() {
|
|||
JSON.test(
|
||||
"overproduction",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(29)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(29))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(PlayingAction::Collect(playing_actions::Collect::new(
|
||||
|
|
@ -395,15 +321,9 @@ fn test_new_plans() {
|
|||
JSON.test(
|
||||
"new_plans",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(31)))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(31))).skip_json(),
|
||||
TestAction::not_undoable(0, payment_response(ResourcePile::culture_tokens(1)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
@ -420,27 +340,19 @@ fn test_synergies() {
|
|||
JSON.test(
|
||||
"synergies",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(34)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(34))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Cartography)),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::ideas(2)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::ideas(2))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::WarShips)),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::ideas(2)])),
|
||||
),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::ideas(2))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -454,7 +366,7 @@ fn test_teach_us() {
|
|||
0,
|
||||
move_action(vec![0, 1, 2, 3, 4, 5], Position::from_offset("C1")),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
|
|
@ -470,14 +382,8 @@ fn test_militia() {
|
|||
JSON.test(
|
||||
"militia",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(37)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(37))).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -487,14 +393,8 @@ fn test_tech_trade() {
|
|||
JSON.test(
|
||||
"tech_trade",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(39)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(39))).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -504,17 +404,13 @@ fn test_new_ideas() {
|
|||
JSON.test(
|
||||
"new_ideas",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(41)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(41))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Storage)),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::food(2)])),
|
||||
),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::food(2))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,10 +1,14 @@
|
|||
use crate::common::{JsonTest, TestAction, illegal_action_test, influence_action};
|
||||
use crate::common::{
|
||||
JsonTest, TestAction, advance_action, custom_action, illegal_action_test, influence_action,
|
||||
payment_response,
|
||||
};
|
||||
use advance::Advance;
|
||||
use server::action::{Action, execute_action};
|
||||
use server::city_pieces::Building::{Academy, Fortress, Temple};
|
||||
use server::collect::{PositionCollection, possible_resource_collections};
|
||||
use server::consts::BUILDING_COST;
|
||||
use server::content::advances::trade_routes::find_trade_routes;
|
||||
use server::content::custom_actions::{CustomActionType, CustomEventAction};
|
||||
use server::content::custom_actions::{CustomAction, CustomActionType};
|
||||
use server::content::persistent_events::{EventResponse, SelectedStructure, Structure};
|
||||
use server::cultural_influence::InfluenceCultureAttempt;
|
||||
use server::events::EventOrigin;
|
||||
|
|
@ -13,7 +17,7 @@ use server::movement::MovementAction::Move;
|
|||
use server::movement::{MoveUnits, possible_move_units_destinations};
|
||||
use server::player::CostTrigger;
|
||||
use server::playing_actions::PlayingAction::{
|
||||
Advance, Collect, Construct, Custom, EndTurn, Recruit, WonderCard,
|
||||
Collect, Construct, Custom, EndTurn, Recruit, WonderCard,
|
||||
};
|
||||
use server::playing_actions::{PlayingAction, PlayingActionType};
|
||||
use server::position::Position;
|
||||
|
|
@ -48,6 +52,7 @@ fn test_sanitation_and_draft() {
|
|||
)
|
||||
.with_pre_assert(move |game| {
|
||||
let options = recruit_cost_without_replaced(
|
||||
&game,
|
||||
&game.players[0],
|
||||
&units,
|
||||
city_position,
|
||||
|
|
@ -61,8 +66,8 @@ fn test_sanitation_and_draft() {
|
|||
assert_eq!(ResourcePile::mood_tokens(1), options.conversions[1].to);
|
||||
assert_eq!(
|
||||
vec![
|
||||
EventOrigin::Advance(advance::Advance::Sanitation),
|
||||
EventOrigin::Advance(advance::Advance::Draft)
|
||||
EventOrigin::Advance(Advance::Sanitation),
|
||||
EventOrigin::Advance(Advance::Draft)
|
||||
],
|
||||
options.modifiers
|
||||
);
|
||||
|
|
@ -79,10 +84,10 @@ fn test_separation_of_power() {
|
|||
if test.fail {
|
||||
game = execute_action(
|
||||
game,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::SeparationOfPower,
|
||||
payment: ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
}),
|
||||
advance_action(
|
||||
Advance::SeparationOfPower,
|
||||
ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
|
@ -100,10 +105,10 @@ fn test_devotion() {
|
|||
if test.fail {
|
||||
game = execute_action(
|
||||
game,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Devotion,
|
||||
payment: ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
}),
|
||||
advance_action(
|
||||
Advance::Devotion,
|
||||
ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
|
@ -125,10 +130,10 @@ fn test_totalitarianism() {
|
|||
if test.fail {
|
||||
game = execute_action(
|
||||
game,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Totalitarianism,
|
||||
payment: ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
}),
|
||||
advance_action(
|
||||
Advance::Totalitarianism,
|
||||
ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
|
@ -146,10 +151,10 @@ fn test_monuments() {
|
|||
if test.fail {
|
||||
game = execute_action(
|
||||
game,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Monuments,
|
||||
payment: ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
}),
|
||||
advance_action(
|
||||
Advance::Monuments,
|
||||
ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
|
@ -164,9 +169,7 @@ fn test_monuments() {
|
|||
);
|
||||
game = execute_action(
|
||||
game,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::new(
|
||||
2, 3, 6, 0, 1, 0, 5,
|
||||
)])),
|
||||
payment_response(ResourcePile::new(2, 3, 6, 0, 1, 0, 5)),
|
||||
0,
|
||||
);
|
||||
game = execute_action(game, Action::Playing(EndTurn), 0);
|
||||
|
|
@ -182,18 +185,13 @@ fn test_increase_happiness_sports() {
|
|||
vec![
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Custom(CustomEventAction::new(
|
||||
Action::Playing(Custom(CustomAction::new(
|
||||
CustomActionType::Sports,
|
||||
Some(Position::from_offset("C2")),
|
||||
))),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -205,18 +203,13 @@ fn test_increase_happiness_sports2() {
|
|||
vec![
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Custom(CustomEventAction::new(
|
||||
Action::Playing(Custom(CustomAction::new(
|
||||
CustomActionType::Sports,
|
||||
Some(Position::from_offset("C2")),
|
||||
))),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
2,
|
||||
)])),
|
||||
),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(2))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -266,18 +259,8 @@ fn test_absolute_power() {
|
|||
JSON.test(
|
||||
"absolute_power",
|
||||
vec![
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Custom(CustomEventAction::new(
|
||||
CustomActionType::AbsolutePower,
|
||||
None,
|
||||
))),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::mood_tokens(2)])),
|
||||
),
|
||||
TestAction::undoable(0, custom_action(CustomActionType::AbsolutePower)).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::mood_tokens(2))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -287,19 +270,8 @@ fn test_forced_labor() {
|
|||
JSON.test(
|
||||
"forced_labor",
|
||||
vec![
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Custom(CustomEventAction::new(
|
||||
CustomActionType::ForcedLabor,
|
||||
None,
|
||||
))),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::mood_tokens(1)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, custom_action(CustomActionType::ForcedLabor)).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::mood_tokens(1))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Collect(playing_actions::Collect::new(
|
||||
|
|
@ -320,13 +292,7 @@ fn test_civil_liberties() {
|
|||
JSON.test(
|
||||
"civil_liberties",
|
||||
vec![
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Custom(CustomEventAction::new(
|
||||
CustomActionType::CivilLiberties,
|
||||
None,
|
||||
))),
|
||||
),
|
||||
TestAction::undoable(0, custom_action(CustomActionType::CivilLiberties)),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Recruit(playing_actions::Recruit::new(
|
||||
|
|
@ -344,14 +310,7 @@ fn test_bartering() {
|
|||
JSON.test(
|
||||
"bartering",
|
||||
vec![
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Custom(CustomEventAction::new(
|
||||
CustomActionType::Bartering,
|
||||
None,
|
||||
))),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, custom_action(CustomActionType::Bartering)).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::ResourceReward(ResourcePile::gold(1))),
|
||||
|
|
@ -368,12 +327,12 @@ fn test_movement_on_roads_from_city() {
|
|||
"movement_on_roads_from_city",
|
||||
vec![TestAction::undoable(
|
||||
1,
|
||||
Action::Movement(Move(MoveUnits {
|
||||
Action::Movement(Move(MoveUnits::new(
|
||||
units,
|
||||
destination,
|
||||
embark_carrier_id: None,
|
||||
payment: ResourcePile::food(1) + ResourcePile::ore(1),
|
||||
})),
|
||||
None,
|
||||
ResourcePile::food(1) + ResourcePile::ore(1),
|
||||
))),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -386,12 +345,12 @@ fn test_movement_on_roads_to_city() {
|
|||
"movement_on_roads_to_city",
|
||||
vec![TestAction::undoable(
|
||||
1,
|
||||
Action::Movement(Move(MoveUnits {
|
||||
Action::Movement(Move(MoveUnits::new(
|
||||
units,
|
||||
destination,
|
||||
embark_carrier_id: None,
|
||||
payment: ResourcePile::food(1) + ResourcePile::ore(1),
|
||||
})),
|
||||
None,
|
||||
ResourcePile::food(1) + ResourcePile::ore(1),
|
||||
))),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -410,6 +369,7 @@ fn test_road_coordinates() {
|
|||
// so only 2 can move over them towards F7
|
||||
assert!(get_destinations(game, &[0, 1], "D8").contains(&"F7".to_string()));
|
||||
let city_dest = get_destinations(game, &[0, 1, 2], "D8");
|
||||
// all 3 units could move around E8 if we had roman roads
|
||||
assert!(!city_dest.contains(&"F7".to_string()));
|
||||
|
||||
// all 3 city units can move around the mountain to C7
|
||||
|
|
@ -437,20 +397,8 @@ fn test_theaters() {
|
|||
JSON.test(
|
||||
"theaters",
|
||||
vec![
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Custom(CustomEventAction::new(
|
||||
CustomActionType::Theaters,
|
||||
None,
|
||||
))),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
),
|
||||
TestAction::undoable(0, custom_action(CustomActionType::Theaters)).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -460,19 +408,8 @@ fn test_taxes() {
|
|||
JSON.test(
|
||||
"taxes",
|
||||
vec![
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Custom(CustomEventAction::new(
|
||||
CustomActionType::Taxes,
|
||||
None,
|
||||
))),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::mood_tokens(1)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, custom_action(CustomActionType::Taxes)).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::mood_tokens(1))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::ResourceReward(ResourcePile::new(
|
||||
|
|
@ -527,14 +464,8 @@ fn test_dogma_with_anarchy() {
|
|||
JSON.test(
|
||||
"dogma",
|
||||
vec![
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Dogma,
|
||||
payment: ResourcePile::ideas(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(1, advance_action(Advance::Dogma, ResourcePile::ideas(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Playing(Construct(construct::Construct::new(
|
||||
|
|
@ -543,17 +474,17 @@ fn test_dogma_with_anarchy() {
|
|||
ResourcePile::new(0, 1, 1, 0, 0, 0, 0),
|
||||
))),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::ResourceReward(ResourcePile::culture_tokens(
|
||||
1,
|
||||
))),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Fanaticism)),
|
||||
Action::Response(EventResponse::SelectAdvance(Advance::Fanaticism)),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
@ -564,27 +495,9 @@ fn test_priesthood() {
|
|||
JSON.test(
|
||||
"priesthood",
|
||||
vec![
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Math,
|
||||
payment: ResourcePile::empty(),
|
||||
}),
|
||||
),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Astronomy,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::illegal(
|
||||
1,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Astronomy,
|
||||
payment: ResourcePile::empty(),
|
||||
}),
|
||||
),
|
||||
TestAction::undoable(1, advance_action(Advance::Math, ResourcePile::empty())),
|
||||
TestAction::undoable(1, advance_action(Advance::Astronomy, ResourcePile::gold(2))),
|
||||
TestAction::illegal(1, advance_action(Advance::Astronomy, ResourcePile::empty())),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -596,12 +509,12 @@ fn test_writing() {
|
|||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Writing,
|
||||
payment: ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
}),
|
||||
advance_action(
|
||||
Advance::Writing,
|
||||
ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Construct(construct::Construct::new(
|
||||
|
|
@ -620,19 +533,52 @@ fn test_free_education() {
|
|||
vec![
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Draft,
|
||||
payment: ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
}),
|
||||
),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::ideas(1)])),
|
||||
advance_action(
|
||||
Advance::Draft,
|
||||
ResourcePile::food(1) + ResourcePile::gold(1),
|
||||
),
|
||||
),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::ideas(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collect_fishing() {
|
||||
JSON.test(
|
||||
"collect_fishing",
|
||||
vec![TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Collect(playing_actions::Collect::new(
|
||||
Position::from_offset("C2"),
|
||||
vec![PositionCollection::new(
|
||||
Position::from_offset("C3"),
|
||||
ResourcePile::food(1),
|
||||
)],
|
||||
PlayingActionType::Collect,
|
||||
))),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collect_port() {
|
||||
JSON.test(
|
||||
"collect_port",
|
||||
vec![TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Collect(playing_actions::Collect::new(
|
||||
Position::from_offset("C2"),
|
||||
vec![PositionCollection::new(
|
||||
Position::from_offset("C3"),
|
||||
ResourcePile::mood_tokens(1),
|
||||
)],
|
||||
PlayingActionType::Collect,
|
||||
))),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_collect_husbandry() {
|
||||
let action = Action::Playing(Collect(playing_actions::Collect::new(
|
||||
|
|
@ -668,17 +614,14 @@ fn test_collect_free_economy() {
|
|||
PlayingActionType::Custom(CustomActionType::FreeEconomyCollect),
|
||||
))),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::mood_tokens(1)])),
|
||||
)
|
||||
.with_post_assert(|game| {
|
||||
// no production focus
|
||||
let result =
|
||||
PlayingActionType::ActionCard(19).is_available(&game, game.active_player());
|
||||
assert!(result.is_err());
|
||||
}),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::mood_tokens(1)))
|
||||
.with_post_assert(|game| {
|
||||
// no production focus
|
||||
let result =
|
||||
PlayingActionType::ActionCard(19).is_available(&game, game.active_player());
|
||||
assert!(result.is_err());
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -700,13 +643,8 @@ fn test_cultural_influence_instant_with_arts() {
|
|||
),
|
||||
)),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(1, payment_response(ResourcePile::culture_tokens(1))),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
|
@ -716,20 +654,10 @@ fn test_cultural_influence_with_conversion() {
|
|||
JSON.test(
|
||||
"cultural_influence_with_conversion",
|
||||
vec![
|
||||
TestAction::undoable(1, influence_action()).without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
3,
|
||||
)])),
|
||||
),
|
||||
TestAction::undoable(1, influence_action()).skip_json(),
|
||||
TestAction::not_undoable(1, payment_response(ResourcePile::culture_tokens(1)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(1, payment_response(ResourcePile::culture_tokens(3))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -765,7 +693,7 @@ fn test_husbandry() {
|
|||
PlayingActionType::Collect,
|
||||
))),
|
||||
)
|
||||
.without_json_comparison()
|
||||
.skip_json()
|
||||
.with_post_assert(|game| {
|
||||
// but not again
|
||||
assert!(has_husbandry_field(&game))
|
||||
|
|
@ -782,7 +710,7 @@ fn test_husbandry() {
|
|||
PlayingActionType::Collect,
|
||||
))),
|
||||
)
|
||||
.without_json_comparison()
|
||||
.skip_json()
|
||||
.with_post_assert(|game| {
|
||||
// but not again
|
||||
assert!(!has_husbandry_field(&game))
|
||||
|
|
|
|||
19
server/tests/civ_maya_tests.rs
Normal file
19
server/tests/civ_maya_tests.rs
Normal file
|
|
@ -0,0 +1,19 @@
|
|||
mod common;
|
||||
|
||||
// const JSON: JsonTest = JsonTest::child("civilizations", "maya");
|
||||
|
||||
#[test]
|
||||
fn leader_pakal_and_place_settler() {
|
||||
// JSON.test(
|
||||
// "civ_maya_leader_pakal",
|
||||
// vec![
|
||||
// TestAction::not_undoable(0, move_action(vec![10], Position::from_offset("B1"))),
|
||||
// TestAction::not_undoable(
|
||||
// 1,
|
||||
// Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
// "B2",
|
||||
// )])),
|
||||
// ),
|
||||
// ],
|
||||
// );
|
||||
}
|
||||
141
server/tests/civ_rome_tests.rs
Normal file
141
server/tests/civ_rome_tests.rs
Normal file
|
|
@ -0,0 +1,141 @@
|
|||
use crate::common::{
|
||||
JsonTest, TestAction, advance_action, custom_action, move_action, payment_response,
|
||||
};
|
||||
use server::action::Action;
|
||||
use server::advance::Advance;
|
||||
use server::city_pieces::Building;
|
||||
use server::construct::Construct;
|
||||
use server::content::custom_actions::CustomActionType;
|
||||
use server::movement::{MoveUnits, MovementAction};
|
||||
use server::playing_actions::{IncreaseHappiness, PlayingAction, PlayingActionType};
|
||||
use server::position::Position;
|
||||
use server::resource_pile::ResourcePile;
|
||||
|
||||
mod common;
|
||||
|
||||
const JSON: JsonTest = JsonTest::child("civilizations", "rome");
|
||||
|
||||
#[test]
|
||||
fn aqueduct_discount() {
|
||||
JSON.test(
|
||||
"aqueduct_discount",
|
||||
vec![TestAction::undoable(
|
||||
0,
|
||||
advance_action(Advance::Sanitation, ResourcePile::empty()),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn aqueduct_free_action() {
|
||||
JSON.test(
|
||||
"aqueduct_free_action",
|
||||
vec![
|
||||
TestAction::undoable(0, custom_action(CustomActionType::Aqueduct)).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::food(2))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn roman_roads() {
|
||||
JSON.test(
|
||||
"roman_roads",
|
||||
vec![TestAction::undoable(
|
||||
0,
|
||||
Action::Movement(MovementAction::Move(MoveUnits::new(
|
||||
vec![0, 1, 2, 3, 4, 5],
|
||||
Position::from_offset("A1"),
|
||||
None,
|
||||
ResourcePile::food(1) + ResourcePile::ore(1),
|
||||
))),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn captivi() {
|
||||
JSON.test(
|
||||
"captivi",
|
||||
vec![TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(PlayingAction::Construct(Construct::new(
|
||||
Position::from_offset("A1"),
|
||||
Building::Market,
|
||||
ResourcePile::new(1, 1, 0, 0, 0, 1, 0),
|
||||
))),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn provinces() {
|
||||
JSON.test(
|
||||
"provinces",
|
||||
vec![
|
||||
TestAction::undoable(0, advance_action(Advance::Voting, ResourcePile::food(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("B2"))).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn princeps() {
|
||||
JSON.test(
|
||||
"princeps",
|
||||
vec![
|
||||
TestAction::undoable(0, custom_action(CustomActionType::Princeps)).skip_json(),
|
||||
TestAction::not_undoable(0, payment_response(ResourcePile::culture_tokens(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn imperator() {
|
||||
JSON.test(
|
||||
"imperator",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
move_action(vec![0], Position::from_offset("D8")),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn statesman() {
|
||||
JSON.test(
|
||||
"statesman",
|
||||
vec![TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(PlayingAction::IncreaseHappiness(IncreaseHappiness::new(
|
||||
vec![(Position::from_offset("A1"), 1)],
|
||||
ResourcePile::mood_tokens(2),
|
||||
PlayingActionType::Custom(CustomActionType::StatesmanIncreaseHappiness),
|
||||
))),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn proconsul() {
|
||||
JSON.test(
|
||||
"proconsul",
|
||||
vec![
|
||||
TestAction::not_undoable(0, move_action(vec![0], Position::from_offset("D8")))
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::gold(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
#[test]
|
||||
fn civilizer() {
|
||||
JSON.test(
|
||||
"civilizer",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
move_action(vec![0], Position::from_offset("D8")),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -1,24 +0,0 @@
|
|||
use crate::common::{JsonTest, TestAction, move_action};
|
||||
use server::action::Action;
|
||||
use server::content::persistent_events::EventResponse;
|
||||
use server::position::Position;
|
||||
|
||||
mod common;
|
||||
|
||||
const JSON: JsonTest = JsonTest::new("civ");
|
||||
|
||||
#[test]
|
||||
fn test_civ_maya_leader_pakal_and_place_settler() {
|
||||
JSON.test(
|
||||
"civ_maya_leader_pakal",
|
||||
vec![
|
||||
TestAction::not_undoable(0, move_action(vec![10], Position::from_offset("B1"))),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
"B2",
|
||||
)])),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -1,6 +1,6 @@
|
|||
// combat
|
||||
|
||||
use crate::common::{TestAction, move_action};
|
||||
use crate::common::{TestAction, move_action, payment_response};
|
||||
use common::JsonTest;
|
||||
use server::action::Action;
|
||||
use server::card::HandCard;
|
||||
|
|
@ -81,12 +81,8 @@ fn test_combat_all_modifiers() {
|
|||
0,
|
||||
move_action(vec![0, 1, 2, 3, 4, 5], Position::from_offset("C1")),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::ore(1)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::ore(1))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![
|
||||
|
|
@ -94,19 +90,15 @@ fn test_combat_all_modifiers() {
|
|||
ResourcePile::ore(2),
|
||||
])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::ore(1)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(1, payment_response(ResourcePile::ore(1))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
|
|
|
|||
|
|
@ -1,18 +1,20 @@
|
|||
#![allow(dead_code)]
|
||||
|
||||
use server::action::Action;
|
||||
use server::advance::AdvanceAction;
|
||||
use server::cache::Cache;
|
||||
use server::city_pieces::Building::Temple;
|
||||
use server::content::persistent_events::{SelectedStructure, Structure};
|
||||
use server::content::custom_actions::{CustomAction, CustomActionType};
|
||||
use server::content::persistent_events::{EventResponse, SelectedStructure, Structure};
|
||||
use server::game::{Game, GameContext};
|
||||
use server::log::current_player_turn_log_mut;
|
||||
use server::movement::MoveUnits;
|
||||
use server::movement::MovementAction::Move;
|
||||
use server::playing_actions::PlayingAction::InfluenceCultureAttempt;
|
||||
use server::playing_actions::PlayingActionType;
|
||||
use server::playing_actions::PlayingAction::{Advance, InfluenceCultureAttempt};
|
||||
use server::playing_actions::{PlayingAction, PlayingActionType};
|
||||
use server::position::Position;
|
||||
use server::resource_pile::ResourcePile;
|
||||
use server::{cultural_influence, game_api};
|
||||
use server::{advance, cultural_influence, game_api};
|
||||
use std::fmt::Display;
|
||||
use std::panic::{AssertUnwindSafe, catch_unwind};
|
||||
use std::{
|
||||
|
|
@ -197,7 +199,7 @@ impl TestAction {
|
|||
self
|
||||
}
|
||||
|
||||
pub fn without_json_comparison(mut self) -> Self {
|
||||
pub fn skip_json(mut self) -> Self {
|
||||
self.compare_json = false;
|
||||
self
|
||||
}
|
||||
|
|
@ -436,6 +438,14 @@ pub fn move_action(units: Vec<u32>, destination: Position) -> Action {
|
|||
}))
|
||||
}
|
||||
|
||||
pub fn advance_action(advance: advance::Advance, payment: ResourcePile) -> Action {
|
||||
Action::Playing(Advance(AdvanceAction::new(advance, payment)))
|
||||
}
|
||||
|
||||
pub fn custom_action(action: CustomActionType) -> Action {
|
||||
Action::Playing(PlayingAction::Custom(CustomAction::new(action, None)))
|
||||
}
|
||||
|
||||
pub fn influence_action() -> Action {
|
||||
Action::Playing(InfluenceCultureAttempt(
|
||||
cultural_influence::InfluenceCultureAttempt::new(
|
||||
|
|
@ -444,3 +454,7 @@ pub fn influence_action() -> Action {
|
|||
),
|
||||
))
|
||||
}
|
||||
|
||||
pub fn payment_response(payment: ResourcePile) -> Action {
|
||||
Action::Response(EventResponse::Payment(vec![payment]))
|
||||
}
|
||||
|
|
|
|||
|
|
@ -36,26 +36,31 @@ fn new_game() {
|
|||
|
||||
#[test]
|
||||
fn basic_actions() {
|
||||
let mut game = setup_game(GameSetupBuilder::new(1).skip_random_map().build());
|
||||
let mut game = setup_game(
|
||||
GameSetupBuilder::new(1)
|
||||
.civilizations(vec!["Klingons".to_string(), "Romulans".to_string()])
|
||||
.skip_random_map()
|
||||
.build(),
|
||||
);
|
||||
|
||||
game.wonders_left.retain(|w| *w == Wonder::Pyramids);
|
||||
let founded_city_position = Position::new(0, 1);
|
||||
game.map.tiles = HashMap::from([(founded_city_position, Forest)]);
|
||||
let advance_action = Action::Playing(Advance {
|
||||
advance: advance::Advance::Math,
|
||||
payment: ResourcePile::food(2),
|
||||
});
|
||||
let game = game_api::execute(game, advance_action, 0);
|
||||
let game = game_api::execute(
|
||||
game,
|
||||
advance_action(advance::Advance::Math, ResourcePile::food(2)),
|
||||
0,
|
||||
);
|
||||
let player = &game.players[0];
|
||||
|
||||
assert_eq!(ResourcePile::culture_tokens(1), player.resources);
|
||||
assert_eq!(2, game.actions_left);
|
||||
|
||||
let advance_action = Action::Playing(Advance {
|
||||
advance: advance::Advance::Engineering,
|
||||
payment: ResourcePile::empty(),
|
||||
});
|
||||
let mut game = game_api::execute(game, advance_action, 0);
|
||||
let mut game = game_api::execute(
|
||||
game,
|
||||
advance_action(advance::Advance::Engineering, ResourcePile::empty()),
|
||||
0,
|
||||
);
|
||||
let player = &game.players[0];
|
||||
|
||||
assert_eq!(
|
||||
|
|
@ -117,9 +122,7 @@ fn basic_actions() {
|
|||
game = game_api::execute(game, Action::Playing(WonderCard(Wonder::Pyramids)), 0);
|
||||
game = game_api::execute(
|
||||
game,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::new(
|
||||
2, 3, 6, 0, 1, 0, 5,
|
||||
)])),
|
||||
payment_response(ResourcePile::new(2, 3, 6, 0, 1, 0, 5)),
|
||||
0,
|
||||
);
|
||||
let player = &game.players[0];
|
||||
|
|
@ -255,20 +258,20 @@ fn undo() {
|
|||
assert_undo(&game, false, true, 2, 0, 0);
|
||||
assert_eq!(Angry, game.players[0].cities[0].mood_state);
|
||||
|
||||
let advance_action = Action::Playing(Advance {
|
||||
advance: advance::Advance::Math,
|
||||
payment: ResourcePile::food(2),
|
||||
});
|
||||
let game = game_api::execute(game, advance_action, 0);
|
||||
let game = game_api::execute(
|
||||
game,
|
||||
advance_action(advance::Advance::Math, ResourcePile::food(2)),
|
||||
0,
|
||||
);
|
||||
assert_undo(&game, true, false, 1, 1, 0);
|
||||
let game = game_api::execute(game, Action::Undo, 0);
|
||||
assert_undo(&game, false, true, 1, 0, 0);
|
||||
assert_eq!(2, game.players[0].advances.len());
|
||||
let advance_action = Action::Playing(Advance {
|
||||
advance: advance::Advance::Engineering,
|
||||
payment: ResourcePile::food(2),
|
||||
});
|
||||
let game = game_api::execute(game, advance_action, 0);
|
||||
let game = game_api::execute(
|
||||
game,
|
||||
advance_action(advance::Advance::Engineering, ResourcePile::food(2)),
|
||||
0,
|
||||
);
|
||||
assert_undo(&game, false, false, 1, 1, 1);
|
||||
}
|
||||
|
||||
|
|
@ -296,20 +299,10 @@ fn test_cultural_influence() {
|
|||
JSON.test(
|
||||
"cultural_influence",
|
||||
vec![
|
||||
TestAction::undoable(1, influence_action()).without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
4,
|
||||
)])),
|
||||
),
|
||||
TestAction::undoable(1, influence_action()).skip_json(),
|
||||
TestAction::not_undoable(1, payment_response(ResourcePile::culture_tokens(1)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(1, payment_response(ResourcePile::culture_tokens(4))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -319,8 +312,7 @@ fn test_found_city() {
|
|||
JSON.test(
|
||||
"found_city",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(FoundCity { settler: 4 }))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(FoundCity { settler: 4 })).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
|
|||
|
|
@ -1,10 +1,11 @@
|
|||
use crate::common::{JsonTest, TestAction, move_action};
|
||||
use crate::common::{JsonTest, TestAction, advance_action, move_action, payment_response};
|
||||
use advance::Advance;
|
||||
use server::action::Action;
|
||||
use server::card::HandCard;
|
||||
use server::city_pieces::Building::Fortress;
|
||||
use server::content::persistent_events::EventResponse;
|
||||
use server::movement::{MoveUnits, MovementAction};
|
||||
use server::playing_actions::PlayingAction::{Advance, Construct};
|
||||
use server::playing_actions::PlayingAction::Construct;
|
||||
use server::playing_actions::{PlayingAction, PlayingActionType};
|
||||
use server::position::Position;
|
||||
use server::resource_pile::ResourcePile;
|
||||
|
|
@ -19,43 +20,27 @@ fn test_great_explorer() {
|
|||
GREAT_PERSONS.test(
|
||||
"great_explorer",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::food(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(1, Action::Playing(PlayingAction::ActionCard(118)))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(1, advance_action(Advance::Storage, ResourcePile::food(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(1, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::undoable(1, Action::Playing(PlayingAction::ActionCard(118))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
"B6",
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(1, Action::Response(EventResponse::ExploreResolution(0)))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
"A7",
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::food(2)])),
|
||||
),
|
||||
.skip_json(),
|
||||
TestAction::undoable(1, payment_response(ResourcePile::food(2))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -65,19 +50,8 @@ fn test_great_artist() {
|
|||
GREAT_PERSONS.test(
|
||||
"great_artist",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::food(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
2,
|
||||
)])),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::food(2))),
|
||||
TestAction::not_undoable(1, payment_response(ResourcePile::culture_tokens(2))),
|
||||
TestAction::not_undoable(0, Action::Playing(PlayingAction::EndTurn)),
|
||||
TestAction::undoable(1, Action::Playing(PlayingAction::ActionCard(119))),
|
||||
],
|
||||
|
|
@ -89,34 +63,18 @@ fn test_great_prophet() {
|
|||
GREAT_PERSONS.test(
|
||||
"great_prophet",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::food(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(120)))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::food(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(120))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
"C1",
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::gold(2)])),
|
||||
),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::gold(2))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -126,23 +84,10 @@ fn test_great_warlord() {
|
|||
GREAT_PERSONS.test(
|
||||
"great_warlord",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::food(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(1, Action::Playing(PlayingAction::ActionCard(124)))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(1, advance_action(Advance::Storage, ResourcePile::food(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(1, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::undoable(1, Action::Playing(PlayingAction::ActionCard(124))).skip_json(),
|
||||
TestAction::not_undoable(1, move_action(vec![0], Position::from_offset("C8"))),
|
||||
],
|
||||
);
|
||||
|
|
@ -153,23 +98,10 @@ fn test_great_merchant() {
|
|||
GREAT_PERSONS.test(
|
||||
"great_merchant",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::food(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(125)))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::food(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(125))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::ResourceReward(ResourcePile::gold(1))),
|
||||
|
|
@ -183,30 +115,16 @@ fn test_great_engineer() {
|
|||
GREAT_PERSONS.test(
|
||||
"great_engineer",
|
||||
vec![
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::food(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(126))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::food(2),
|
||||
}),
|
||||
Action::Response(EventResponse::SelectAdvance(Advance::Engineering)),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(126)))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Engineering)),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::Bool(true)))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::Bool(true))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Construct(construct::Construct::new(
|
||||
|
|
@ -228,36 +146,18 @@ fn test_great_architect() {
|
|||
GREAT_PERSONS.test(
|
||||
"great_architect",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::food(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(155)))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::food(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(155))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
"A1",
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::new(
|
||||
2, 3, 6, 0, 1, 0, 2,
|
||||
)])),
|
||||
),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::new(2, 3, 6, 0, 1, 0, 2))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -267,31 +167,12 @@ fn test_great_athlete() {
|
|||
GREAT_PERSONS.test(
|
||||
"great_athlete",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::food(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(156)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::Bool(true)))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::food(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(156))).skip_json(),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::Bool(true))).skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -303,29 +184,17 @@ fn test_great_diplomat() {
|
|||
GREAT_PERSONS.test(
|
||||
"great_diplomat",
|
||||
vec![
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::food(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::food(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Movement(MovementAction::Move(MoveUnits {
|
||||
Action::Movement(MovementAction::Move(MoveUnits::new(
|
||||
units,
|
||||
destination,
|
||||
embark_carrier_id: None,
|
||||
payment: ResourcePile::culture_tokens(2),
|
||||
})),
|
||||
None,
|
||||
ResourcePile::culture_tokens(2),
|
||||
))),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
@ -336,38 +205,20 @@ fn test_great_seer() {
|
|||
GREAT_PERSONS.test(
|
||||
"great_seer",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::food(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::food(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::culture_tokens(1))).skip_json(),
|
||||
TestAction::not_undoable(0, Action::Playing(PlayingAction::ActionCard(158)))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
HandCard::ObjectiveCard(21),
|
||||
])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
// the player already knows the card - but we treat all designated cards as unknown
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Writing,
|
||||
payment: ResourcePile::food(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Writing, ResourcePile::food(2))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use crate::common::{JsonTest, TestAction, move_action};
|
||||
use crate::common::{JsonTest, TestAction, advance_action, move_action, payment_response};
|
||||
use advance::Advance;
|
||||
use server::action::Action;
|
||||
use server::card::HandCard;
|
||||
use server::city_pieces::Building::Fortress;
|
||||
use server::content::persistent_events::{EventResponse, SelectedStructure, Structure};
|
||||
use server::playing_actions::PlayingAction::{Advance, Construct};
|
||||
use server::playing_actions::PlayingAction::Construct;
|
||||
use server::position::Position;
|
||||
use server::resource_pile::ResourcePile;
|
||||
use server::status_phase::ChangeGovernment;
|
||||
|
|
@ -23,7 +24,7 @@ fn test_barbarians_spawn() {
|
|||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Storage)),
|
||||
Action::Response(EventResponse::SelectAdvance(Advance::Storage)),
|
||||
),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
|
|
@ -46,12 +47,13 @@ fn test_barbarians_move() {
|
|||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Storage)),
|
||||
),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(Advance::Storage)),
|
||||
)
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
"B3",
|
||||
"A3",
|
||||
)])),
|
||||
),
|
||||
],
|
||||
|
|
@ -65,7 +67,7 @@ fn test_pirates_spawn() {
|
|||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Storage)),
|
||||
Action::Response(EventResponse::SelectAdvance(Advance::Storage)),
|
||||
),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::SelectUnits(vec![7]))),
|
||||
TestAction::undoable(
|
||||
|
|
@ -80,10 +82,7 @@ fn test_pirates_spawn() {
|
|||
"D2",
|
||||
)])),
|
||||
),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::ore(1)])),
|
||||
),
|
||||
TestAction::not_undoable(0, payment_response(ResourcePile::ore(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -94,7 +93,7 @@ fn test_barbarians_attack() {
|
|||
"barbarians_attack",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Storage)),
|
||||
Action::Response(EventResponse::SelectAdvance(Advance::Storage)),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -117,7 +116,7 @@ fn test_exhausted_land() {
|
|||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Storage)),
|
||||
Action::Response(EventResponse::SelectAdvance(Advance::Storage)),
|
||||
),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
|
|
@ -141,38 +140,23 @@ fn test_pestilence() {
|
|||
FAMINE.test(
|
||||
"pestilence",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::mood_tokens(1)])),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::mood_tokens(1))),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
"A1",
|
||||
)])),
|
||||
),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::mood_tokens(1)])),
|
||||
),
|
||||
TestAction::illegal(0, cons.clone()).without_json_comparison(),
|
||||
TestAction::not_undoable(1, payment_response(ResourcePile::mood_tokens(1))),
|
||||
TestAction::illegal(0, cons.clone()).skip_json(),
|
||||
TestAction::undoable(
|
||||
//no compare
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Sanitation,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
advance_action(Advance::Sanitation, ResourcePile::gold(2)),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, cons).without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, cons).skip_json(),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -183,10 +167,7 @@ fn test_famine() {
|
|||
"famine",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
advance_action(Advance::Storage, ResourcePile::gold(2)),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -196,13 +177,7 @@ fn test_epidemics() {
|
|||
FAMINE.test(
|
||||
"epidemics",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::SelectUnits(vec![7]))),
|
||||
],
|
||||
);
|
||||
|
|
@ -217,9 +192,9 @@ fn test_good_year_with_player_select() {
|
|||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Storage)),
|
||||
Action::Response(EventResponse::SelectAdvance(Advance::Storage)),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectUnitType(UnitType::Elephant)),
|
||||
|
|
@ -234,7 +209,7 @@ fn test_successful_year() {
|
|||
"successful_year",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectAdvance(advance::Advance::Storage)),
|
||||
Action::Response(EventResponse::SelectAdvance(Advance::Storage)),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -246,13 +221,7 @@ fn test_volcano() {
|
|||
EARTHQUAKE.test(
|
||||
"volcano",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
|
|
@ -268,13 +237,7 @@ fn test_flood() {
|
|||
EARTHQUAKE.test(
|
||||
"flood",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
|
|
@ -296,14 +259,8 @@ fn test_earthquake() {
|
|||
EARTHQUAKE.test(
|
||||
"earthquake",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectStructures(vec![
|
||||
|
|
@ -318,12 +275,8 @@ fn test_earthquake() {
|
|||
),
|
||||
])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::mood_tokens(1)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(0, payment_response(ResourcePile::mood_tokens(1))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectStructures(vec![
|
||||
|
|
@ -347,10 +300,7 @@ fn test_migration() {
|
|||
"migration",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
advance_action(Advance::Storage, ResourcePile::gold(2)),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -361,10 +311,7 @@ fn test_civil_war() {
|
|||
"civil_war",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
advance_action(Advance::Storage, ResourcePile::gold(2)),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -374,18 +321,12 @@ fn test_revolution() {
|
|||
CIVIL_WAR.test(
|
||||
"revolution",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::SelectUnits(vec![3])))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::SelectUnits(vec![])))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::ChangeGovernmentType(ChangeGovernment::new(
|
||||
|
|
@ -402,18 +343,10 @@ fn test_uprising() {
|
|||
CIVIL_WAR.test(
|
||||
"uprising",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![
|
||||
ResourcePile::mood_tokens(1) + ResourcePile::culture_tokens(1),
|
||||
])),
|
||||
payment_response(ResourcePile::culture_tokens(1) + ResourcePile::mood_tokens(1)),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
@ -424,20 +357,8 @@ fn test_envoy() {
|
|||
CIVIL_WAR.test(
|
||||
"envoy",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Monuments,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::undoable(0, advance_action(Advance::Monuments, ResourcePile::gold(2))),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::Bool(true))),
|
||||
],
|
||||
);
|
||||
|
|
@ -450,24 +371,16 @@ fn test_trojan_horse() {
|
|||
TROJAN.test(
|
||||
"trojan_horse",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2)))
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
move_action(vec![0, 1, 2, 3, 4, 5], Position::from_offset("C1")),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![
|
||||
ResourcePile::culture_tokens(1) + ResourcePile::gold(1),
|
||||
])),
|
||||
payment_response(ResourcePile::culture_tokens(1) + ResourcePile::gold(1)),
|
||||
),
|
||||
],
|
||||
);
|
||||
|
|
@ -478,19 +391,13 @@ fn test_solar_eclipse() {
|
|||
TROJAN.test(
|
||||
"solar_eclipse",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2)))
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
move_action(vec![0, 1, 2, 3, 4, 5], Position::from_offset("C1")),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
|
|
@ -506,20 +413,8 @@ fn test_anarchy() {
|
|||
TROJAN.test(
|
||||
"anarchy",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Dogma,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::undoable(0, advance_action(Advance::Dogma, ResourcePile::gold(2))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -532,10 +427,7 @@ fn test_scientific_trade() {
|
|||
"scientific_trade",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
advance_action(Advance::Storage, ResourcePile::gold(2)),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -546,10 +438,7 @@ fn test_flourishing_trade() {
|
|||
"flourishing_trade",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
advance_action(Advance::Storage, ResourcePile::gold(2)),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -559,13 +448,7 @@ fn test_era_of_stability() {
|
|||
TRADE.test(
|
||||
"era_of_stability",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::ResourceReward(ResourcePile::culture_tokens(
|
||||
|
|
@ -587,13 +470,7 @@ fn test_reformation() {
|
|||
TRADE.test(
|
||||
"reformation",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::not_undoable(2, Action::Response(EventResponse::SelectPlayer(1))),
|
||||
],
|
||||
);
|
||||
|
|
@ -606,13 +483,7 @@ fn test_pandemics() {
|
|||
PANDEMICS.test(
|
||||
"pandemics",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::SelectUnits(vec![0]))),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
|
|
@ -620,12 +491,7 @@ fn test_pandemics() {
|
|||
1,
|
||||
)])),
|
||||
),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
|
||||
1,
|
||||
)])),
|
||||
),
|
||||
TestAction::not_undoable(1, payment_response(ResourcePile::culture_tokens(1))),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
@ -635,13 +501,7 @@ fn test_black_death() {
|
|||
PANDEMICS.test(
|
||||
"black_death",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::SelectUnits(vec![0]))),
|
||||
],
|
||||
);
|
||||
|
|
@ -653,10 +513,7 @@ fn test_vermin() {
|
|||
"vermin",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
advance_action(Advance::Storage, ResourcePile::gold(2)),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -667,10 +524,7 @@ fn test_drought() {
|
|||
"drought",
|
||||
vec![TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
advance_action(Advance::Storage, ResourcePile::gold(2)),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -680,13 +534,7 @@ fn test_fire() {
|
|||
PANDEMICS.test(
|
||||
"fire",
|
||||
vec![
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Playing(Advance {
|
||||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
TestAction::not_undoable(0, advance_action(Advance::Storage, ResourcePile::gold(2))),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
|
|
|
|||
|
|
@ -108,12 +108,12 @@ fn test_ship_embark() {
|
|||
"ship_embark",
|
||||
vec![TestAction::undoable(
|
||||
0,
|
||||
Action::Movement(Move(MoveUnits {
|
||||
units: vec![3, 4],
|
||||
destination: Position::from_offset("C3"),
|
||||
embark_carrier_id: Some(8),
|
||||
payment: ResourcePile::empty(),
|
||||
})),
|
||||
Action::Movement(Move(MoveUnits::new(
|
||||
vec![3, 4],
|
||||
Position::from_offset("C3"),
|
||||
Some(8),
|
||||
ResourcePile::empty(),
|
||||
))),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -124,12 +124,12 @@ fn test_ship_embark_continue() {
|
|||
"ship_embark_continue",
|
||||
vec![TestAction::undoable(
|
||||
0,
|
||||
Action::Movement(Move(MoveUnits {
|
||||
units: vec![5, 6],
|
||||
destination: Position::from_offset("C3"),
|
||||
embark_carrier_id: Some(9),
|
||||
payment: ResourcePile::empty(),
|
||||
})),
|
||||
Action::Movement(Move(MoveUnits::new(
|
||||
vec![5, 6],
|
||||
Position::from_offset("C3"),
|
||||
Some(9),
|
||||
ResourcePile::empty(),
|
||||
))),
|
||||
)],
|
||||
);
|
||||
}
|
||||
|
|
@ -151,7 +151,7 @@ fn test_ship_disembark_capture_empty_city() {
|
|||
"ship_disembark_capture_empty_city",
|
||||
vec![
|
||||
TestAction::undoable(0, move_action(vec![1, 2], Position::from_offset("B2")))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
|
|||
|
|
@ -22,8 +22,8 @@ fn test_draft() {
|
|||
JSON.test(
|
||||
"draft",
|
||||
vec![
|
||||
TestAction::undoable(0, r.clone()).without_json_comparison(),
|
||||
TestAction::undoable(0, r).without_json_comparison(),
|
||||
TestAction::undoable(0, r.clone()).skip_json(),
|
||||
TestAction::undoable(0, r).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
@ -43,7 +43,7 @@ fn test_conqueror() {
|
|||
0,
|
||||
move_action(vec![0, 1, 2, 3], Position::from_offset("C1")),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
@ -62,9 +62,8 @@ fn test_defiance() {
|
|||
"defiance",
|
||||
vec![
|
||||
TestAction::not_undoable(0, move_action(vec![0], Position::from_offset("C1")))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(0, Action::Response(EventResponse::Bool(false)))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(0, Action::Response(EventResponse::Bool(false))).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
@ -81,9 +80,9 @@ fn test_warmonger() {
|
|||
"warmonger",
|
||||
vec![
|
||||
TestAction::not_undoable(0, move_action(vec![0, 1], Position::from_offset("C1")))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(0, move_action(vec![2, 3], Position::from_offset("B1")))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
@ -117,7 +116,7 @@ fn test_scavenger() {
|
|||
"scavenger",
|
||||
vec![
|
||||
TestAction::not_undoable(0, move_action(vec![0, 1], Position::from_offset("E7")))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
|
|||
|
|
@ -13,8 +13,7 @@ fn test_large_civ() {
|
|||
JSON.test(
|
||||
"large_civ",
|
||||
vec![
|
||||
TestAction::not_undoable(1, Action::Playing(PlayingAction::EndTurn))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(1, Action::Playing(PlayingAction::EndTurn)).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
@ -54,8 +53,7 @@ fn test_colony() {
|
|||
JSON.test(
|
||||
"colony",
|
||||
vec![
|
||||
TestAction::not_undoable(0, Action::Playing(PlayingAction::EndTurn))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(0, Action::Playing(PlayingAction::EndTurn)).skip_json(),
|
||||
TestAction::undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
@ -72,8 +70,7 @@ fn test_standing_army() {
|
|||
JSON.test(
|
||||
"standing_army",
|
||||
vec![
|
||||
TestAction::not_undoable(1, Action::Playing(PlayingAction::EndTurn))
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(1, Action::Playing(PlayingAction::EndTurn)).skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::common::TestAction;
|
||||
use crate::common::{TestAction, payment_response};
|
||||
use common::JsonTest;
|
||||
use server::action::Action;
|
||||
use server::advance;
|
||||
|
|
@ -93,14 +93,12 @@ fn test_change_government() {
|
|||
"change_government",
|
||||
vec![
|
||||
TestAction::not_undoable(1, Action::Response(EventResponse::SelectPositions(vec![])))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![
|
||||
ResourcePile::culture_tokens(1) + ResourcePile::mood_tokens(1),
|
||||
])),
|
||||
payment_response(ResourcePile::culture_tokens(1) + ResourcePile::mood_tokens(1)),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::ChangeGovernmentType(ChangeGovernment::new(
|
||||
|
|
@ -118,11 +116,8 @@ fn test_keep_government() {
|
|||
"keep_government",
|
||||
vec![
|
||||
TestAction::not_undoable(1, Action::Response(EventResponse::SelectPositions(vec![])))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::empty()])),
|
||||
),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, payment_response(ResourcePile::empty())),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -46,8 +46,7 @@ fn test_wedge_formation() {
|
|||
JSON.test(
|
||||
"wedge_formation",
|
||||
vec![
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1")))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1"))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
|
|
@ -63,8 +62,7 @@ fn test_high_morale() {
|
|||
JSON.test(
|
||||
"high_morale",
|
||||
vec![
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1")))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1"))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
|
|
@ -81,7 +79,7 @@ fn test_heavy_resistance() {
|
|||
"heavy_resistance",
|
||||
vec![
|
||||
TestAction::not_undoable(0, move_action(vec![0], Position::from_offset("C1")))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
|
|
@ -97,15 +95,14 @@ fn test_high_ground() {
|
|||
JSON.test(
|
||||
"high_ground",
|
||||
vec![
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1")))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1"))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
|
|
@ -122,7 +119,7 @@ fn test_surprise() {
|
|||
"surprise",
|
||||
vec![
|
||||
TestAction::not_undoable(0, move_action(vec![0], Position::from_offset("C1")))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
|
|
@ -138,8 +135,7 @@ fn test_siege() {
|
|||
JSON.test(
|
||||
"siege",
|
||||
vec![
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1")))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1"))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
|
|
@ -155,15 +151,14 @@ fn test_scout() {
|
|||
JSON.test(
|
||||
"scout",
|
||||
vec![
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1")))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1"))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
1,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
|
|
@ -180,23 +175,23 @@ fn test_martyr() {
|
|||
"martyr",
|
||||
vec![
|
||||
TestAction::undoable(0, move_action(vec![7, 8], Position::from_offset("D2")))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
6,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
24,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::undoable(0, Action::Response(EventResponse::SelectUnits(vec![7])))
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(0, Action::Response(EventResponse::SelectUnits(vec![2]))),
|
||||
],
|
||||
);
|
||||
|
|
@ -207,15 +202,14 @@ fn test_archers() {
|
|||
JSON.test(
|
||||
"archers",
|
||||
vec![
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1")))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1"))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
26,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
.skip_json(),
|
||||
TestAction::not_undoable(1, Action::Response(EventResponse::SelectUnits(vec![1]))),
|
||||
],
|
||||
);
|
||||
|
|
@ -226,8 +220,7 @@ fn test_flanking() {
|
|||
JSON.test(
|
||||
"flanking",
|
||||
vec![
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1")))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(0, move_action(vec![0], Position::from_offset("C1"))).skip_json(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![HandCard::ActionCard(
|
||||
|
|
|
|||
|
|
@ -217,7 +217,9 @@
|
|||
"op": "add",
|
||||
"path": "/events/0/event_type/PayAction",
|
||||
"value": {
|
||||
"ActionCard": 2
|
||||
"action": {
|
||||
"ActionCard": 2
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
|
|
@ -274,6 +276,13 @@
|
|||
"op": "remove",
|
||||
"path": "/events/0/handler/request/SelectAdvance"
|
||||
},
|
||||
{
|
||||
"op": "add",
|
||||
"path": "/events/0/origin_override",
|
||||
"value": {
|
||||
"CivilCard": 2
|
||||
}
|
||||
},
|
||||
{
|
||||
"op": "add",
|
||||
"path": "/players/0/action_cards",
|
||||
|
|
|
|||
|
|
@ -256,7 +256,9 @@
|
|||
{
|
||||
"event_type": {
|
||||
"PayAction": {
|
||||
"ActionCard": 17
|
||||
"action": {
|
||||
"ActionCard": 17
|
||||
}
|
||||
}
|
||||
},
|
||||
"handler": {
|
||||
|
|
@ -301,6 +303,9 @@
|
|||
}
|
||||
},
|
||||
"last_priority_used": 0,
|
||||
"origin_override": {
|
||||
"CivilCard": 17
|
||||
},
|
||||
"player": 0
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -117,8 +117,8 @@
|
|||
],
|
||||
"units": [
|
||||
{
|
||||
"position": "C1",
|
||||
"unit_type": "Infantry",
|
||||
"position": "A1",
|
||||
"unit_type": "Leader",
|
||||
"id": 0
|
||||
},
|
||||
{
|
||||
|
|
@ -127,7 +127,8 @@
|
|||
"id": 1
|
||||
}
|
||||
],
|
||||
"civilization": "test1",
|
||||
"civilization": "Rome",
|
||||
"active_leader": "Sulla",
|
||||
"advances": [
|
||||
"Farming",
|
||||
"Mining"
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@
|
|||
"resources": {
|
||||
"food": 1,
|
||||
"wood": 6,
|
||||
"ore": 4,
|
||||
"ore": 5,
|
||||
"ideas": 5,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
|
|
@ -109,8 +109,8 @@
|
|||
],
|
||||
"units": [
|
||||
{
|
||||
"position": "C1",
|
||||
"unit_type": "Infantry",
|
||||
"position": "A1",
|
||||
"unit_type": "Leader",
|
||||
"id": 0
|
||||
},
|
||||
{
|
||||
|
|
@ -119,7 +119,8 @@
|
|||
"id": 1
|
||||
}
|
||||
],
|
||||
"civilization": "test1",
|
||||
"civilization": "Rome",
|
||||
"active_leader": "Sulla",
|
||||
"advances": [
|
||||
"Farming",
|
||||
"Mining"
|
||||
|
|
@ -144,12 +145,9 @@
|
|||
],
|
||||
"units": [
|
||||
{
|
||||
"position": "B2",
|
||||
"unit_type": "Infantry",
|
||||
"movement_restrictions": [
|
||||
"Forest"
|
||||
],
|
||||
"id": 0
|
||||
"position": "A3",
|
||||
"unit_type": "Elephant",
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"position": "B2",
|
||||
|
|
@ -160,19 +158,13 @@
|
|||
"id": 2
|
||||
},
|
||||
{
|
||||
"position": "B2",
|
||||
"position": "A3",
|
||||
"unit_type": "Infantry",
|
||||
"movement_restrictions": [
|
||||
"Forest"
|
||||
],
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"position": "B2",
|
||||
"position": "A3",
|
||||
"unit_type": "Infantry",
|
||||
"movement_restrictions": [
|
||||
"Forest"
|
||||
],
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
|
|
@ -251,7 +243,6 @@
|
|||
"action": {
|
||||
"Response": {
|
||||
"SelectPositions": [
|
||||
"A3",
|
||||
"B3"
|
||||
]
|
||||
}
|
||||
|
|
@ -262,32 +253,22 @@
|
|||
"Response": {
|
||||
"Payment": [
|
||||
{
|
||||
"ore": 2
|
||||
"ore": 1
|
||||
}
|
||||
]
|
||||
}
|
||||
}
|
||||
},
|
||||
{
|
||||
"action": {
|
||||
"Response": {
|
||||
"SelectPositions": [
|
||||
"A3"
|
||||
]
|
||||
}
|
||||
},
|
||||
"combat_stats": {
|
||||
"round": 1,
|
||||
"battleground": "Land",
|
||||
"attacker": {
|
||||
"position": "A3",
|
||||
"position": "B3",
|
||||
"player": 2,
|
||||
"present": {
|
||||
"infantry": 2,
|
||||
"elephants": 1
|
||||
"infantry": 2
|
||||
},
|
||||
"losses": {
|
||||
"elephants": 1
|
||||
"infantry": 1
|
||||
}
|
||||
},
|
||||
"defender": {
|
||||
|
|
@ -302,79 +283,6 @@
|
|||
},
|
||||
"result": "AttackerWins"
|
||||
}
|
||||
},
|
||||
{
|
||||
"action": {
|
||||
"Response": {
|
||||
"SelectPositions": [
|
||||
"B2"
|
||||
]
|
||||
}
|
||||
},
|
||||
"undo": [
|
||||
{
|
||||
"op": "add",
|
||||
"path": "/events",
|
||||
"value": [
|
||||
{
|
||||
"event_type": {
|
||||
"ActionCard": {
|
||||
"id": 13,
|
||||
"selected_position": "B3"
|
||||
}
|
||||
},
|
||||
"handler": {
|
||||
"origin": {
|
||||
"CivilCard": 13
|
||||
},
|
||||
"priority": -9,
|
||||
"request": {
|
||||
"SelectPositions": {
|
||||
"choices": [
|
||||
"A3",
|
||||
"B2"
|
||||
],
|
||||
"description": "Select destination for Barbarian army",
|
||||
"needed": {
|
||||
"end": 1,
|
||||
"start": 1
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"last_priority_used": -9,
|
||||
"player": 0
|
||||
}
|
||||
]
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/players/2/next_unit_id",
|
||||
"value": 5
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/players/2/units/0/position",
|
||||
"value": "B3"
|
||||
},
|
||||
{
|
||||
"op": "remove",
|
||||
"path": "/players/2/units/0/movement_restrictions"
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/players/2/units/1/position",
|
||||
"value": "B3"
|
||||
},
|
||||
{
|
||||
"op": "remove",
|
||||
"path": "/players/2/units/1/movement_restrictions"
|
||||
},
|
||||
{
|
||||
"op": "remove",
|
||||
"path": "/players/2/units/4"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
|
|
@ -383,42 +291,36 @@
|
|||
]
|
||||
}
|
||||
],
|
||||
"action_log_index": 5,
|
||||
"action_log_index": 3,
|
||||
"log": [
|
||||
[
|
||||
"Player1 played the action card Mercenaries as a regular action"
|
||||
"Player1 played the action card Mercenaries as a regular action",
|
||||
"Player1 cannot move Barbarian army at A3 because Sulla is in range"
|
||||
],
|
||||
[
|
||||
"Player1 selected Barbarian armies to move: A3, B3"
|
||||
"Player1 selected Barbarian armies to move: B3"
|
||||
],
|
||||
[
|
||||
"Player1 paid for mercenaries: 2 ore"
|
||||
],
|
||||
[
|
||||
"Player1 selected Barbarian army to move: A3",
|
||||
"Player1 paid for mercenaries: 1 ore",
|
||||
"Player1 selected Barbarian army to move: B3",
|
||||
"Player1 selected destination for Barbarian army: B2",
|
||||
"Barbarians marched 2 infantry and 1 elephant from A3 to B2"
|
||||
"Barbarians marched 2 infantry from B3 to B2"
|
||||
],
|
||||
[
|
||||
"Combat round 1",
|
||||
"Attackers: 2 infantry and 1 elephant",
|
||||
"Attackers: 2 infantry",
|
||||
"Defenders: 1 infantry",
|
||||
"Barbarians rolled 6 (infantry, +1 combat value), 6 (infantry, +1 combat value), 6 (infantry, no bonus) for combined combat value of 20 and gets 1 hits against defending units.",
|
||||
"Barbarians rolled 6 (infantry, +1 combat value), 6 (infantry, +1 combat value) for combined combat value of 14 and gets 1 hits against defending units.",
|
||||
"Player1 rolled 6 (infantry, +1 combat value) for combined combat value of 7 and gets 1 hits against attacking units.",
|
||||
"Barbarians has to remove 1 of their attacking units",
|
||||
"Barbarians removed 1 elephant",
|
||||
"Barbarians removed 1 infantry",
|
||||
"Player1 has to remove all of their defending units",
|
||||
"Player1 removed 1 infantry",
|
||||
"Attacker wins",
|
||||
"Player1 selected Barbarian army to move: B3"
|
||||
],
|
||||
[
|
||||
"Player1 selected destination for Barbarian army: B2",
|
||||
"Barbarians marched 2 infantry from B3 to B2",
|
||||
"Barbarians reinforced with 1 infantry at B3"
|
||||
]
|
||||
],
|
||||
"undo_limit": 4,
|
||||
"undo_limit": 3,
|
||||
"actions_left": 2,
|
||||
"round": 1,
|
||||
"age": 1,
|
||||
|
|
@ -430,13 +332,13 @@
|
|||
1,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
10
|
||||
],
|
||||
"dice_roll_log": [
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
10
|
||||
],
|
||||
"wonders_left": [
|
||||
|
|
@ -221,7 +221,9 @@
|
|||
{
|
||||
"event_type": {
|
||||
"PayAction": {
|
||||
"ActionCard": 37
|
||||
"action": {
|
||||
"ActionCard": 37
|
||||
}
|
||||
}
|
||||
},
|
||||
"handler": {
|
||||
|
|
@ -266,6 +268,9 @@
|
|||
}
|
||||
},
|
||||
"last_priority_used": 0,
|
||||
"origin_override": {
|
||||
"CivilCard": 37
|
||||
},
|
||||
"player": 0
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -233,7 +233,9 @@
|
|||
{
|
||||
"event_type": {
|
||||
"PayAction": {
|
||||
"ActionCard": 39
|
||||
"action": {
|
||||
"ActionCard": 39
|
||||
}
|
||||
}
|
||||
},
|
||||
"handler": {
|
||||
|
|
@ -278,6 +280,9 @@
|
|||
}
|
||||
},
|
||||
"last_priority_used": 0,
|
||||
"origin_override": {
|
||||
"CivilCard": 39
|
||||
},
|
||||
"player": 0
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -233,8 +233,7 @@
|
|||
"action": {
|
||||
"Playing": {
|
||||
"Custom": {
|
||||
"action": "AbsolutePower",
|
||||
"city": null
|
||||
"action": "AbsolutePower"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -272,9 +271,10 @@
|
|||
{
|
||||
"event_type": {
|
||||
"PayAction": {
|
||||
"Custom": {
|
||||
"action": "AbsolutePower",
|
||||
"city": null
|
||||
"action": {
|
||||
"Custom": {
|
||||
"action": "AbsolutePower"
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -320,6 +320,9 @@
|
|||
}
|
||||
},
|
||||
"last_priority_used": 0,
|
||||
"origin_override": {
|
||||
"Advance": "AbsolutePower"
|
||||
},
|
||||
"player": 0
|
||||
}
|
||||
]
|
||||
|
|
|
|||
|
|
@ -199,8 +199,7 @@
|
|||
"action": {
|
||||
"Playing": {
|
||||
"Custom": {
|
||||
"action": "Bartering",
|
||||
"city": null
|
||||
"action": "Bartering"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
@ -242,8 +241,7 @@
|
|||
{
|
||||
"event_type": {
|
||||
"CustomAction": {
|
||||
"action": "Bartering",
|
||||
"city": null
|
||||
"action": "Bartering"
|
||||
}
|
||||
},
|
||||
"handler": {
|
||||
|
|
|
|||
|
|
@ -196,8 +196,7 @@
|
|||
"action": {
|
||||
"Playing": {
|
||||
"Custom": {
|
||||
"action": "CivilLiberties",
|
||||
"city": null
|
||||
"action": "CivilLiberties"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -202,8 +202,7 @@
|
|||
"action": {
|
||||
"Playing": {
|
||||
"Custom": {
|
||||
"action": "CivilLiberties",
|
||||
"city": null
|
||||
"action": "CivilLiberties"
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,79 +1,57 @@
|
|||
{
|
||||
"options": {},
|
||||
"state": "Playing",
|
||||
"events": [
|
||||
{
|
||||
"event_type": {
|
||||
"StatusPhase": "FreeAdvance"
|
||||
},
|
||||
"player": 0,
|
||||
"last_priority_used": 0
|
||||
},
|
||||
{
|
||||
"event_type": {
|
||||
"Incident": {
|
||||
"incident_id": 28,
|
||||
"active_player": 0,
|
||||
"barbarians": {
|
||||
"move_units": true
|
||||
}
|
||||
}
|
||||
},
|
||||
"player": 0,
|
||||
"last_priority_used": 136,
|
||||
"handler": {
|
||||
"priority": 136,
|
||||
"request": {
|
||||
"SelectPositions": {
|
||||
"choices": [
|
||||
"A3",
|
||||
"B3"
|
||||
],
|
||||
"needed": {
|
||||
"start": 1,
|
||||
"end": 1
|
||||
},
|
||||
"description": "Select a Barbarian Army to move next"
|
||||
}
|
||||
},
|
||||
"origin": {
|
||||
"Incident": 28
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"players": [
|
||||
{
|
||||
"id": 0,
|
||||
"resources": {
|
||||
"food": 1,
|
||||
"wood": 6,
|
||||
"ore": 6,
|
||||
"ideas": 5,
|
||||
"gold": 7,
|
||||
"mood_tokens": 8,
|
||||
"culture_tokens": 7
|
||||
"food": 2,
|
||||
"wood": 5,
|
||||
"ore": 5,
|
||||
"ideas": 3,
|
||||
"gold": 5,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 9
|
||||
},
|
||||
"resource_limit": {
|
||||
"food": 7,
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
"gold": 7
|
||||
},
|
||||
"cities": [
|
||||
{
|
||||
"city_pieces": {
|
||||
"market": 1
|
||||
},
|
||||
"mood_state": "Happy",
|
||||
"position": "A1"
|
||||
},
|
||||
{
|
||||
"city_pieces": {
|
||||
"fortress": 1
|
||||
"academy": 1,
|
||||
"port": 1
|
||||
},
|
||||
"mood_state": "Angry",
|
||||
"position": "C2"
|
||||
"activations": 6,
|
||||
"position": "C2",
|
||||
"port_position": "C3"
|
||||
},
|
||||
{
|
||||
"city_pieces": {
|
||||
"obelisk": 1,
|
||||
"observatory": 1,
|
||||
"fortress": 1,
|
||||
"temple": 1
|
||||
},
|
||||
"mood_state": "Neutral",
|
||||
"position": "B1"
|
||||
},
|
||||
{
|
||||
"mood_state": "Happy",
|
||||
"activations": 4,
|
||||
"position": "B3"
|
||||
}
|
||||
],
|
||||
"units": [
|
||||
|
|
@ -83,75 +61,98 @@
|
|||
"id": 0
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"position": "C3",
|
||||
"unit_type": "Cavalry",
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Leader",
|
||||
"position": "C3",
|
||||
"unit_type": "Elephant",
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Elephant",
|
||||
"position": "B3",
|
||||
"unit_type": "Settler",
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"position": "B3",
|
||||
"unit_type": "Settler",
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"position": "B3",
|
||||
"unit_type": "Settler",
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"position": "B3",
|
||||
"unit_type": "Settler",
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Settler",
|
||||
"position": "C3",
|
||||
"unit_type": "Ship",
|
||||
"id": 7
|
||||
},
|
||||
{
|
||||
"position": "C3",
|
||||
"unit_type": "Ship",
|
||||
"id": 8
|
||||
},
|
||||
{
|
||||
"position": "C3",
|
||||
"unit_type": "Ship",
|
||||
"id": 9
|
||||
}
|
||||
],
|
||||
"civilization": "test0",
|
||||
"available_leaders": [
|
||||
"Alexander",
|
||||
"Kleopatra"
|
||||
],
|
||||
"advances": [
|
||||
"Farming",
|
||||
"Mining",
|
||||
"Storage",
|
||||
"Tactics"
|
||||
"Fishing",
|
||||
"Mining"
|
||||
],
|
||||
"incident_tokens": 3,
|
||||
"next_unit_id": 8
|
||||
"wonder_cards": [
|
||||
"Pyramids"
|
||||
],
|
||||
"next_unit_id": 10
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"resources": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
"wood": 5,
|
||||
"ore": 5,
|
||||
"ideas": 5,
|
||||
"gold": 5,
|
||||
"mood_tokens": 9,
|
||||
"culture_tokens": 9
|
||||
},
|
||||
"resource_limit": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
"gold": 7
|
||||
},
|
||||
"cities": [
|
||||
{
|
||||
"mood_state": "Angry",
|
||||
"activations": 2,
|
||||
"position": "C1"
|
||||
},
|
||||
{
|
||||
"city_pieces": {
|
||||
"port": 1
|
||||
},
|
||||
"mood_state": "Neutral",
|
||||
"position": "B2",
|
||||
"port_position": "C3"
|
||||
}
|
||||
],
|
||||
"units": [
|
||||
|
|
@ -176,49 +177,13 @@
|
|||
},
|
||||
{
|
||||
"id": 2,
|
||||
"resource_limit": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7
|
||||
},
|
||||
"cities": [
|
||||
{
|
||||
"mood_state": "Neutral",
|
||||
"position": "B3"
|
||||
}
|
||||
],
|
||||
"units": [
|
||||
{
|
||||
"position": "B3",
|
||||
"unit_type": "Infantry",
|
||||
"id": 0
|
||||
},
|
||||
{
|
||||
"position": "A3",
|
||||
"unit_type": "Elephant",
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"position": "B3",
|
||||
"unit_type": "Infantry",
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"position": "A3",
|
||||
"unit_type": "Infantry",
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"position": "A3",
|
||||
"unit_type": "Infantry",
|
||||
"id": 4
|
||||
}
|
||||
],
|
||||
"civilization": "Barbarians",
|
||||
"incident_tokens": 3,
|
||||
"next_unit_id": 5
|
||||
"next_unit_id": 0
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"civilization": "Pirates",
|
||||
"next_unit_id": 0
|
||||
}
|
||||
],
|
||||
"map": {
|
||||
|
|
@ -233,8 +198,18 @@
|
|||
],
|
||||
[
|
||||
"A3",
|
||||
{
|
||||
"Exhausted": "Forest"
|
||||
}
|
||||
],
|
||||
[
|
||||
"A4",
|
||||
"Mountain"
|
||||
],
|
||||
[
|
||||
"A5",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"B1",
|
||||
"Mountain"
|
||||
|
|
@ -247,6 +222,18 @@
|
|||
"B3",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"B4",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"B5",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"B6",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"C1",
|
||||
"Barren"
|
||||
|
|
@ -259,9 +246,25 @@
|
|||
"C3",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"C4",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"C5",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"D1",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"D2",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"E2",
|
||||
"Fertile"
|
||||
]
|
||||
]
|
||||
},
|
||||
|
|
@ -274,35 +277,18 @@
|
|||
"players": [
|
||||
{
|
||||
"index": 0,
|
||||
"items": [
|
||||
{
|
||||
"action": {
|
||||
"Response": {
|
||||
"SelectAdvance": "Storage"
|
||||
}
|
||||
}
|
||||
}
|
||||
]
|
||||
"items": []
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"action_log_index": 1,
|
||||
"log": [
|
||||
[
|
||||
"Player1 advanced Storage for free",
|
||||
"Player1 gained 1 mood token as advance bonus"
|
||||
],
|
||||
[
|
||||
"A new game event has been triggered: Population Boom",
|
||||
"Base effect: Barbarians move"
|
||||
]
|
||||
],
|
||||
"undo_limit": 1,
|
||||
"actions_left": 3,
|
||||
"round": 1,
|
||||
"action_log_index": 0,
|
||||
"log": [],
|
||||
"undo_limit": 0,
|
||||
"actions_left": 2,
|
||||
"round": 6,
|
||||
"age": 1,
|
||||
"messages": [
|
||||
"The game has started"
|
||||
|
|
@ -316,15 +302,8 @@
|
|||
10,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
10
|
||||
],
|
||||
"dice_roll_log": [
|
||||
10
|
||||
],
|
||||
"wonders_left": [
|
||||
"Pyramids"
|
||||
],
|
||||
"incidents_discarded": [
|
||||
28
|
||||
]
|
||||
"rng": "234162992961072890508432380903651342097"
|
||||
}
|
||||
351
server/tests/test_games/advances/collect_fishing.outcome.json
Normal file
351
server/tests/test_games/advances/collect_fishing.outcome.json
Normal file
|
|
@ -0,0 +1,351 @@
|
|||
{
|
||||
"options": {},
|
||||
"state": "Playing",
|
||||
"players": [
|
||||
{
|
||||
"id": 0,
|
||||
"resources": {
|
||||
"food": 2,
|
||||
"wood": 5,
|
||||
"ore": 5,
|
||||
"ideas": 3,
|
||||
"gold": 5,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 9
|
||||
},
|
||||
"resource_limit": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7
|
||||
},
|
||||
"cities": [
|
||||
{
|
||||
"city_pieces": {
|
||||
"market": 1
|
||||
},
|
||||
"mood_state": "Happy",
|
||||
"position": "A1"
|
||||
},
|
||||
{
|
||||
"city_pieces": {
|
||||
"academy": 1,
|
||||
"port": 1
|
||||
},
|
||||
"mood_state": "Angry",
|
||||
"activations": 7,
|
||||
"angry_activation": true,
|
||||
"position": "C2",
|
||||
"port_position": "C3"
|
||||
},
|
||||
{
|
||||
"city_pieces": {
|
||||
"obelisk": 1,
|
||||
"observatory": 1,
|
||||
"fortress": 1,
|
||||
"temple": 1
|
||||
},
|
||||
"mood_state": "Neutral",
|
||||
"position": "B1"
|
||||
},
|
||||
{
|
||||
"mood_state": "Happy",
|
||||
"activations": 4,
|
||||
"position": "B3"
|
||||
}
|
||||
],
|
||||
"units": [
|
||||
{
|
||||
"position": "C2",
|
||||
"unit_type": "Infantry",
|
||||
"id": 0
|
||||
},
|
||||
{
|
||||
"position": "C3",
|
||||
"unit_type": "Cavalry",
|
||||
"id": 1
|
||||
},
|
||||
{
|
||||
"position": "C3",
|
||||
"unit_type": "Elephant",
|
||||
"id": 2
|
||||
},
|
||||
{
|
||||
"position": "B3",
|
||||
"unit_type": "Settler",
|
||||
"id": 3
|
||||
},
|
||||
{
|
||||
"position": "B3",
|
||||
"unit_type": "Settler",
|
||||
"id": 4
|
||||
},
|
||||
{
|
||||
"position": "B3",
|
||||
"unit_type": "Settler",
|
||||
"id": 5
|
||||
},
|
||||
{
|
||||
"position": "B3",
|
||||
"unit_type": "Settler",
|
||||
"id": 6
|
||||
},
|
||||
{
|
||||
"position": "C3",
|
||||
"unit_type": "Ship",
|
||||
"id": 7
|
||||
},
|
||||
{
|
||||
"position": "C3",
|
||||
"unit_type": "Ship",
|
||||
"id": 8
|
||||
},
|
||||
{
|
||||
"position": "C3",
|
||||
"unit_type": "Ship",
|
||||
"id": 9
|
||||
}
|
||||
],
|
||||
"civilization": "test0",
|
||||
"available_leaders": [
|
||||
"Alexander",
|
||||
"Kleopatra"
|
||||
],
|
||||
"advances": [
|
||||
"Farming",
|
||||
"Fishing",
|
||||
"Mining"
|
||||
],
|
||||
"incident_tokens": 3,
|
||||
"wonder_cards": [
|
||||
"Pyramids"
|
||||
],
|
||||
"next_unit_id": 10
|
||||
},
|
||||
{
|
||||
"id": 1,
|
||||
"resources": {
|
||||
"food": 2,
|
||||
"wood": 5,
|
||||
"ore": 5,
|
||||
"ideas": 5,
|
||||
"gold": 5,
|
||||
"mood_tokens": 9,
|
||||
"culture_tokens": 9
|
||||
},
|
||||
"resource_limit": {
|
||||
"food": 2,
|
||||
"wood": 7,
|
||||
"ore": 7,
|
||||
"ideas": 7,
|
||||
"gold": 7
|
||||
},
|
||||
"cities": [
|
||||
{
|
||||
"mood_state": "Angry",
|
||||
"activations": 2,
|
||||
"position": "C1"
|
||||
},
|
||||
{
|
||||
"city_pieces": {
|
||||
"port": 1
|
||||
},
|
||||
"mood_state": "Neutral",
|
||||
"position": "B2",
|
||||
"port_position": "C3"
|
||||
}
|
||||
],
|
||||
"units": [
|
||||
{
|
||||
"position": "C1",
|
||||
"unit_type": "Infantry",
|
||||
"id": 0
|
||||
},
|
||||
{
|
||||
"position": "C1",
|
||||
"unit_type": "Infantry",
|
||||
"id": 1
|
||||
}
|
||||
],
|
||||
"civilization": "test1",
|
||||
"advances": [
|
||||
"Farming",
|
||||
"Mining"
|
||||
],
|
||||
"incident_tokens": 3,
|
||||
"next_unit_id": 2
|
||||
},
|
||||
{
|
||||
"id": 2,
|
||||
"civilization": "Barbarians",
|
||||
"next_unit_id": 0
|
||||
},
|
||||
{
|
||||
"id": 3,
|
||||
"civilization": "Pirates",
|
||||
"next_unit_id": 0
|
||||
}
|
||||
],
|
||||
"map": {
|
||||
"tiles": [
|
||||
[
|
||||
"A1",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"A2",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"A3",
|
||||
{
|
||||
"Exhausted": "Forest"
|
||||
}
|
||||
],
|
||||
[
|
||||
"A4",
|
||||
"Mountain"
|
||||
],
|
||||
[
|
||||
"A5",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"B1",
|
||||
"Mountain"
|
||||
],
|
||||
[
|
||||
"B2",
|
||||
"Forest"
|
||||
],
|
||||
[
|
||||
"B3",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"B4",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"B5",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"B6",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"C1",
|
||||
"Barren"
|
||||
],
|
||||
[
|
||||
"C2",
|
||||
"Forest"
|
||||
],
|
||||
[
|
||||
"C3",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"C4",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"C5",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"D1",
|
||||
"Fertile"
|
||||
],
|
||||
[
|
||||
"D2",
|
||||
"Water"
|
||||
],
|
||||
[
|
||||
"E2",
|
||||
"Fertile"
|
||||
]
|
||||
]
|
||||
},
|
||||
"starting_player_index": 0,
|
||||
"current_player_index": 0,
|
||||
"action_log": [
|
||||
{
|
||||
"rounds": [
|
||||
{
|
||||
"players": [
|
||||
{
|
||||
"index": 0,
|
||||
"items": [
|
||||
{
|
||||
"action": {
|
||||
"Playing": {
|
||||
"Collect": {
|
||||
"city_position": "C2",
|
||||
"collections": [
|
||||
{
|
||||
"position": "C3",
|
||||
"pile": {
|
||||
"food": 1
|
||||
},
|
||||
"times": 1
|
||||
}
|
||||
],
|
||||
"action_type": "Collect"
|
||||
}
|
||||
}
|
||||
},
|
||||
"undo": [
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/actions_left",
|
||||
"value": 2
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/players/0/cities/1/activations",
|
||||
"value": 6
|
||||
},
|
||||
{
|
||||
"op": "remove",
|
||||
"path": "/players/0/cities/1/angry_activation"
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"action_log_index": 1,
|
||||
"log": [
|
||||
[
|
||||
"Player1 collects 1 food in the city at C2 making it Angry",
|
||||
"Player1 could not store 1 food"
|
||||
]
|
||||
],
|
||||
"undo_limit": 0,
|
||||
"actions_left": 1,
|
||||
"round": 6,
|
||||
"age": 1,
|
||||
"messages": [
|
||||
"The game has started"
|
||||
],
|
||||
"dice_roll_outcomes": [
|
||||
1,
|
||||
1,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
10,
|
||||
10
|
||||
],
|
||||
"rng": "234162992961072890508432380903651342097"
|
||||
}
|
||||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue