colosseum (#233)
|
Before Width: | Height: | Size: 11 KiB |
BIN
client/assets/angry-svgrepo-com.png
Normal file
|
After Width: | Height: | Size: 15 KiB |
BIN
client/assets/colosseum-rome-svgrepo-com.png
Normal file
|
After Width: | Height: | Size: 7.8 KiB |
BIN
client/assets/fountain-svgrepo-com.png
Normal file
|
After Width: | Height: | Size: 10 KiB |
BIN
client/assets/great-wall-of-china-chinese-svgrepo-com.png
Normal file
|
After Width: | Height: | Size: 13 KiB |
BIN
client/assets/library-14-svgrepo-com.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
client/assets/lighthouse-svgrepo-com.png
Normal file
|
After Width: | Height: | Size: 7.4 KiB |
BIN
client/assets/mausoleum-svgrepo-com.png
Normal file
|
After Width: | Height: | Size: 5.6 KiB |
BIN
client/assets/statue-of-david-1-svgrepo-com.png
Normal file
|
After Width: | Height: | Size: 9.9 KiB |
|
|
@ -7,6 +7,7 @@ use server::map::Terrain;
|
|||
use server::player::Player;
|
||||
use server::resource::ResourceType;
|
||||
use server::unit::UnitType;
|
||||
use server::wonder::Wonder;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct CivAssets {
|
||||
|
|
@ -51,7 +52,7 @@ pub struct Assets {
|
|||
|
||||
pub resources: HashMap<ResourceType, Texture2D>,
|
||||
pub buildings: HashMap<Building, Texture2D>,
|
||||
pub wonders: HashMap<String, Texture2D>,
|
||||
pub wonders: HashMap<Wonder, Texture2D>,
|
||||
pub custom_actions: HashMap<CustomActionType, Texture2D>,
|
||||
pub civ: HashMap<String, CivAssets>,
|
||||
pub default_civ: CivAssets,
|
||||
|
|
@ -65,7 +66,7 @@ impl Assets {
|
|||
terrain: Self::terrain(features).await,
|
||||
exhausted: load_png(include_bytes!("../assets/cross-svgrepo-com.png")),
|
||||
|
||||
angry: load_png(include_bytes!("../assets/angry-face-svgrepo-com.png")),
|
||||
angry: load_png(include_bytes!("../assets/angry-svgrepo-com.png")),
|
||||
resources: Self::resources(),
|
||||
buildings: Self::buildings(),
|
||||
civ: Self::new_civ_assets(),
|
||||
|
|
@ -105,16 +106,43 @@ impl Assets {
|
|||
}
|
||||
}
|
||||
|
||||
fn wonders() -> HashMap<String, Texture2D> {
|
||||
fn wonders() -> HashMap<Wonder, Texture2D> {
|
||||
[
|
||||
(
|
||||
"Pyramids".to_string(),
|
||||
Wonder::Colosseum,
|
||||
load_png(include_bytes!("../assets/colosseum-rome-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
Wonder::GreatGardens,
|
||||
load_png(include_bytes!("../assets/fountain-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
Wonder::GreatLibrary,
|
||||
load_png(include_bytes!("../assets/library-14-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
Wonder::GreatLighthouse,
|
||||
load_png(include_bytes!("../assets/lighthouse-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
Wonder::GreatMausoleum,
|
||||
load_png(include_bytes!("../assets/mausoleum-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
Wonder::Pyramids,
|
||||
load_png(include_bytes!("../assets/pyramid-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
"Great Gardens".to_string(),
|
||||
// todo find a better icon
|
||||
load_png(include_bytes!("../assets/pyramid-svgrepo-com.png")),
|
||||
Wonder::Colossus,
|
||||
load_png(include_bytes!(
|
||||
"../assets/statue-of-david-1-svgrepo-com.png"
|
||||
)),
|
||||
),
|
||||
(
|
||||
Wonder::GreatWall,
|
||||
load_png(include_bytes!(
|
||||
"../assets/great-wall-of-china-chinese-svgrepo-com.png"
|
||||
)),
|
||||
),
|
||||
]
|
||||
.iter()
|
||||
|
|
|
|||
|
|
@ -156,7 +156,7 @@ fn draw_card(
|
|||
fn can_play_card(rc: &RenderContext, card: &HandCard) -> bool {
|
||||
match card {
|
||||
HandCard::ActionCard(id) => rc.can_play_action(&PlayingActionType::ActionCard(*id)),
|
||||
HandCard::Wonder(name) => rc.can_play_action(&PlayingActionType::WonderCard(name.clone())),
|
||||
HandCard::Wonder(name) => rc.can_play_action(&PlayingActionType::WonderCard(*name)),
|
||||
HandCard::ObjectiveCard(_) => false,
|
||||
}
|
||||
}
|
||||
|
|
@ -171,8 +171,8 @@ fn play_card(rc: &RenderContext, card: &HandCard) -> StateUpdate {
|
|||
Action::Playing(PlayingAction::ActionCard(*a)),
|
||||
),
|
||||
HandCard::Wonder(name) => StateUpdate::execute_with_confirm(
|
||||
vec![format!("Play Wonder Card: {name}")],
|
||||
Action::Playing(PlayingAction::WonderCard(name.clone())),
|
||||
vec![format!("Play Wonder Card: {}", name.name(rc.game))],
|
||||
Action::Playing(PlayingAction::WonderCard(*name)),
|
||||
),
|
||||
HandCard::ObjectiveCard(_) => panic!("objective cards are not played as actions"),
|
||||
}
|
||||
|
|
@ -216,14 +216,8 @@ fn get_card_object(
|
|||
vec!["Hidden Objective Card".to_string()],
|
||||
),
|
||||
HandCard::ObjectiveCard(id) => objective_card_object(rc, *id, selection),
|
||||
HandCard::Wonder(n) if n.is_empty() => HandCardObject::new(
|
||||
card.clone(),
|
||||
WONDER_CARD_COLOR,
|
||||
"Wonder Card",
|
||||
vec!["Hidden Wonder Card".to_string()],
|
||||
),
|
||||
HandCard::Wonder(name) => {
|
||||
let w = rc.game.cache.get_wonder(name);
|
||||
let w = rc.game.cache.get_wonder(*name);
|
||||
HandCardObject::new(
|
||||
card.clone(),
|
||||
WONDER_CARD_COLOR,
|
||||
|
|
@ -231,13 +225,7 @@ fn get_card_object(
|
|||
vec![
|
||||
w.description.clone(),
|
||||
format!("Cost: {}", w.cost.to_string()),
|
||||
format!(
|
||||
"Required advances: {}",
|
||||
w.required_advances
|
||||
.iter()
|
||||
.map(|a| a.name(rc.game))
|
||||
.join(", ")
|
||||
),
|
||||
format!("Required advance: {}", w.required_advance.name(rc.game)),
|
||||
],
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -426,7 +426,7 @@ fn draw_wonders(
|
|||
draw_scaled_icon(
|
||||
rc,
|
||||
&rc.assets().wonders[w],
|
||||
w,
|
||||
w.name(rc.game),
|
||||
p + vec2(-size / 2., -size / 2.),
|
||||
size,
|
||||
);
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ pub fn event_help(rc: &RenderContext, origin: &EventOrigin) -> Vec<String> {
|
|||
let cache = &rc.game.cache;
|
||||
let d = match origin {
|
||||
EventOrigin::Advance(a) => vec![a.info(rc.game).description.clone()],
|
||||
EventOrigin::Wonder(w) => vec![rc.game.cache.get_wonder(w).description.clone()],
|
||||
EventOrigin::Wonder(w) => vec![rc.game.cache.get_wonder(*w).description.clone()],
|
||||
EventOrigin::Builtin(b) => vec![cache.get_builtin(b, rc.game).description.clone()],
|
||||
EventOrigin::CivilCard(id) => vec![cache.get_civil_card(*id).description.clone()],
|
||||
EventOrigin::TacticsCard(id) => vec![cache.get_tactics_card(*id).description.clone()],
|
||||
|
|
|
|||
|
|
@ -15,9 +15,11 @@ use server::game_setup::setup_game;
|
|||
use server::map::Terrain;
|
||||
use server::player::add_unit;
|
||||
use server::position::Position;
|
||||
use server::profiling::start_profiling;
|
||||
use server::resource_pile::ResourcePile;
|
||||
use server::unit::{UnitType, set_unit_position};
|
||||
use server::utils::remove_element;
|
||||
use server::wonder::Wonder;
|
||||
use std::fs::File;
|
||||
use std::io::BufReader;
|
||||
use std::time::Duration;
|
||||
|
|
@ -30,28 +32,6 @@ enum Mode {
|
|||
Test,
|
||||
}
|
||||
|
||||
#[cfg(not(feature = "profiling"))]
|
||||
pub fn start_profiling() {
|
||||
// do nothing
|
||||
}
|
||||
|
||||
#[cfg(feature = "profiling")]
|
||||
pub fn start_profiling() {
|
||||
println!("start profiling");
|
||||
|
||||
use pyroscope::PyroscopeAgent;
|
||||
use pyroscope_pprofrs::{PprofConfig, pprof_backend};
|
||||
|
||||
let pprof_config = PprofConfig::new().sample_rate(100);
|
||||
let backend_impl = pprof_backend(pprof_config);
|
||||
|
||||
let agent = PyroscopeAgent::builder("http://localhost:4040", "clash")
|
||||
.backend(backend_impl)
|
||||
.build()
|
||||
.expect("Failed to initialize pyroscope");
|
||||
let _ = agent.start().unwrap();
|
||||
}
|
||||
|
||||
#[macroquad::main("Clash")]
|
||||
async fn main() {
|
||||
start_profiling();
|
||||
|
|
@ -235,7 +215,7 @@ fn setup_local_game() -> Game {
|
|||
|
||||
game.players[player_index1]
|
||||
.wonder_cards
|
||||
.push(remove_element(&mut game.wonders_left, &"Great Gardens".to_string()).unwrap());
|
||||
.push(remove_element(&mut game.wonders_left, &Wonder::GreatGardens).unwrap());
|
||||
game.players[player_index1]
|
||||
.get_city_mut(Position::from_offset("C2"))
|
||||
.increase_mood_state();
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use macroquad::prelude::Texture2D;
|
|||
use server::action::Action;
|
||||
use server::events::EventOrigin;
|
||||
use server::game::{Game, GameState};
|
||||
use server::movement::{CurrentMove, MoveUnits, MovementAction, move_units_destinations};
|
||||
use server::movement::{CurrentMove, MoveUnits, MovementAction, possible_move_units_destinations};
|
||||
use server::payment::PaymentOptions;
|
||||
use server::player::Player;
|
||||
use server::position::Position;
|
||||
|
|
@ -64,7 +64,7 @@ pub fn possible_destinations(
|
|||
let player = game.player(player_index);
|
||||
let mut modifiers = HashSet::new();
|
||||
|
||||
let mut res = move_units_destinations(player, game, units, start, None)
|
||||
let mut res = possible_move_units_destinations(player, game, units, start, None)
|
||||
.unwrap_or_default()
|
||||
.into_iter()
|
||||
.map(|route| {
|
||||
|
|
@ -75,7 +75,7 @@ pub fn possible_destinations(
|
|||
|
||||
player.units.iter().for_each(|u| {
|
||||
if u.unit_type.is_ship()
|
||||
&& move_units_destinations(player, game, units, start, Some(u.id))
|
||||
&& possible_move_units_destinations(player, game, units, start, Some(u.id))
|
||||
.is_ok_and(|v| v.iter().any(|route| route.destination == u.position))
|
||||
{
|
||||
res.push(MoveDestination::Carrier(u.id));
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::select_ui::{CountSelector, HasCountSelectableObject};
|
|||
use crate::tooltip::show_tooltip_for_circle;
|
||||
use itertools::Itertools;
|
||||
use macroquad::math::{bool, vec2};
|
||||
use server::payment::PaymentOptions;
|
||||
use server::payment::{PaymentOptions, ResourceReward};
|
||||
use server::resource::ResourceType;
|
||||
use server::resource_pile::ResourcePile;
|
||||
|
||||
|
|
@ -102,7 +102,8 @@ where
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn new_gain(options: &PaymentOptions, name: &str) -> Payment<String> {
|
||||
pub fn new_gain(reward: &ResourceReward, name: &str) -> Payment<String> {
|
||||
let options = &reward.payment_options;
|
||||
let a = options.default.amount();
|
||||
let mut available = ResourcePile::empty();
|
||||
for r in options.possible_resource_types() {
|
||||
|
|
|
|||
|
|
@ -282,7 +282,7 @@ fn show_focused_tile(label: &mut impl FnMut(&str), game: &Game, position: Positi
|
|||
|
||||
for (p, unit) in units {
|
||||
let army_move = game.player(p).has_advance(ARMY_MOVEMENT_REQUIRED_ADVANCE);
|
||||
label(&unit_ui::unit_label(&unit, army_move));
|
||||
label(&unit_ui::unit_label(&unit, army_move, game));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -17,6 +17,7 @@ use itertools::Itertools;
|
|||
use server::consts::ARMY_MOVEMENT_REQUIRED_ADVANCE;
|
||||
use server::movement::MovementRestriction;
|
||||
use server::player::Player;
|
||||
use server::wonder::Wonder;
|
||||
|
||||
pub struct UnitPlace {
|
||||
pub center: Vec2,
|
||||
|
|
@ -226,7 +227,7 @@ fn draw_unit(
|
|||
let army_move = game
|
||||
.player(player_index)
|
||||
.has_advance(ARMY_MOVEMENT_REQUIRED_ADVANCE);
|
||||
let mut tooltip = vec![unit_label(unit, army_move)];
|
||||
let mut tooltip = vec![unit_label(unit, army_move, game)];
|
||||
add_unit_description(&mut tooltip, unit.unit_type);
|
||||
show_tooltip_for_circle(rc, &tooltip, center, radius);
|
||||
} else {
|
||||
|
|
@ -289,7 +290,7 @@ pub fn name(u: &UnitType) -> &str {
|
|||
u.name()
|
||||
}
|
||||
|
||||
pub fn unit_label(unit: &Unit, army_move: bool) -> String {
|
||||
pub fn unit_label(unit: &Unit, army_move: bool, game: &Game) -> String {
|
||||
let name = name(&unit.unit_type);
|
||||
let mut notes = vec![];
|
||||
|
||||
|
|
@ -307,6 +308,14 @@ pub fn unit_label(unit: &Unit, army_move: bool) -> String {
|
|||
MovementRestriction::Forest => {
|
||||
notes.push("can't attack from a Forest this turn");
|
||||
}
|
||||
MovementRestriction::Fertile => {
|
||||
if game.players.iter().any(|p| {
|
||||
p.index != unit.player_index
|
||||
&& p.wonders_owned.contains(Wonder::GreatGardens)
|
||||
}) {
|
||||
notes.push("can't move into the city with Great Gardens this turn");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -16,12 +16,12 @@ dir = "server"
|
|||
|
||||
[tasks.test]
|
||||
description = "Run server tests"
|
||||
run = 'cargo nextest run {{arg(name="test", default="")}}'
|
||||
run = 'cargo test {{arg(name="test", default="")}}'
|
||||
dir = "server"
|
||||
|
||||
[tasks.update-tests]
|
||||
description = "Run server tests and update JSON files"
|
||||
run = 'cargo nextest run {{arg(name="test", default="")}}'
|
||||
run = 'cargo test --jobs 2 {{arg(name="test", default="")}}'
|
||||
env = { UPDATE_EXPECTED = "true" }
|
||||
dir = "server"
|
||||
|
||||
|
|
|
|||
|
|
@ -397,9 +397,9 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
move |game, player_index, _player_name, details| {
|
||||
let req = request(game, player_index, details);
|
||||
if let Some(r) = &req {
|
||||
if r.reward.possible_resource_types().len() == 1 {
|
||||
if r.reward.payment_options.possible_resource_types().len() == 1 {
|
||||
let player_name = game.player_name(player_index);
|
||||
let r = r.reward.default_payment();
|
||||
let r = r.reward.payment_options.default_payment();
|
||||
for log in g(
|
||||
game,
|
||||
&SelectedChoice::new(player_index, &player_name, false, r.clone()),
|
||||
|
|
@ -416,7 +416,10 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
move |game, player_index, player_name, action, request, details| {
|
||||
if let PersistentEventRequest::ResourceReward(request) = &request {
|
||||
if let EventResponse::ResourceReward(reward) = action {
|
||||
assert!(request.reward.is_valid_payment(&reward), "Invalid reward");
|
||||
assert!(
|
||||
request.reward.payment_options.is_valid_payment(&reward),
|
||||
"Invalid reward"
|
||||
);
|
||||
for log in &gain_reward_log(
|
||||
game,
|
||||
&SelectedChoice::new(player_index, player_name, true, reward.clone()),
|
||||
|
|
|
|||
|
|
@ -318,11 +318,14 @@ fn execute_move_action(game: &mut Game, player_index: usize, m: &MoveUnits) -> R
|
|||
starting_position,
|
||||
m.embark_carrier_id,
|
||||
)?;
|
||||
let c = &destinations
|
||||
.iter()
|
||||
.find(|route| route.destination == m.destination)
|
||||
.expect("destination should be a valid destination")
|
||||
.cost;
|
||||
|
||||
let (dest, result) = destinations
|
||||
.into_iter()
|
||||
.find(|(route, _)| route.destination == m.destination)
|
||||
.expect("destination should be a valid destination");
|
||||
result?;
|
||||
|
||||
let c = &dest.cost;
|
||||
if c.is_free() {
|
||||
assert_eq!(m.payment, ResourcePile::empty(), "payment should be empty");
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -26,6 +26,7 @@ use crate::resource::ResourceType;
|
|||
use crate::resource_pile::ResourcePile;
|
||||
use crate::status_phase::{ChangeGovernment, ChangeGovernmentType, government_advances};
|
||||
use crate::unit::{UnitType, Units};
|
||||
use crate::wonder::Wonder;
|
||||
use itertools::Itertools;
|
||||
use rustc_hash::FxHashMap;
|
||||
use std::vec;
|
||||
|
|
@ -180,16 +181,16 @@ fn base_actions(ai: &mut AiActions, game: &Game) -> Vec<(ActionType, Vec<Action>
|
|||
.wonder_cards
|
||||
.iter()
|
||||
.filter_map(|card| {
|
||||
PlayingActionType::WonderCard(card.clone())
|
||||
PlayingActionType::WonderCard(*card)
|
||||
.is_available(game, p.index)
|
||||
.is_ok()
|
||||
.then_some(Action::Playing(PlayingAction::WonderCard(card.clone())))
|
||||
.then_some(Action::Playing(PlayingAction::WonderCard(*card)))
|
||||
})
|
||||
.collect_vec();
|
||||
|
||||
if !wonder_cards.is_empty() {
|
||||
actions.push((
|
||||
ActionType::Playing(PlayingActionType::WonderCard(String::new())),
|
||||
ActionType::Playing(PlayingActionType::WonderCard(Wonder::Pyramids)),
|
||||
wonder_cards,
|
||||
));
|
||||
}
|
||||
|
|
@ -235,11 +236,7 @@ fn available_action_cards(game: &Game, p: &Player) -> Vec<Action> {
|
|||
return None;
|
||||
}
|
||||
if *card == 19 || *card == 20 || *card == 29 || *card == 30 {
|
||||
// todo collect only is buggy
|
||||
return None;
|
||||
}
|
||||
if *card == 15 || *card == 16 {
|
||||
// todo influence only is buggy
|
||||
// todo collect only is possible even if resources are wasted
|
||||
return None;
|
||||
}
|
||||
if *card == 7 || *card == 8 {
|
||||
|
|
@ -516,7 +513,9 @@ fn responses(event: &PersistentEventState, player: &Player, game: &Game) -> Vec<
|
|||
)]
|
||||
}
|
||||
PersistentEventRequest::ResourceReward(r) => {
|
||||
vec![EventResponse::ResourceReward(r.reward.default)]
|
||||
vec![EventResponse::ResourceReward(
|
||||
r.reward.payment_options.default,
|
||||
)]
|
||||
}
|
||||
PersistentEventRequest::SelectAdvance(a) => a
|
||||
.choices
|
||||
|
|
|
|||
|
|
@ -12,10 +12,9 @@ pub(crate) fn possible_collections(info: &CollectInfo) -> Vec<Vec<PositionCollec
|
|||
let tiles = list.len(); // production focus is not considered
|
||||
let mut max_tiles = tiles;
|
||||
|
||||
// avoid husbandry
|
||||
list.sort_by_key(|(pos, _)| (pos.distance(info.city), *(*pos)));
|
||||
if info.max_range2_tiles > 0 {
|
||||
// avoid husbandry
|
||||
list.sort_by_key(|(pos, _)| (pos.distance(info.city), *(*pos)));
|
||||
|
||||
let range2_tiles = list
|
||||
.iter()
|
||||
.filter(|(pos, _)| pos.distance(info.city) > 1)
|
||||
|
|
@ -40,7 +39,12 @@ pub(crate) fn possible_collections(info: &CollectInfo) -> Vec<Vec<PositionCollec
|
|||
.count()
|
||||
<= info.max_range2_tiles as usize
|
||||
})
|
||||
.unique_by(total_collect)
|
||||
.filter_map(|c| {
|
||||
let t = total_collect(&c);
|
||||
(t.amount() > 0).then_some((c, t))
|
||||
})
|
||||
.unique_by(|(_, t)| t.clone())
|
||||
.map(|(c, _)| c)
|
||||
.collect_vec()
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -570,8 +570,8 @@ impl Mission {
|
|||
}
|
||||
|
||||
fn next_movement(&self, game: &Game) -> Option<MovementAction> {
|
||||
//todo: settlers and scouts should avoid enemy combat troupes in their path
|
||||
let route = movement::move_units_destinations(
|
||||
//todo: settlers and scouts should avoid enemy combat troops in their path
|
||||
let route = movement::possible_move_units_destinations(
|
||||
&game.players[self.player_index],
|
||||
game,
|
||||
&self.units,
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::game::Game;
|
|||
use crate::incident::{BASE_EFFECT_PRIORITY, IncidentBuilder, IncidentFilter, play_base_effect};
|
||||
use crate::map::Terrain;
|
||||
use crate::movement::MoveUnits;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::ResourceReward;
|
||||
use crate::player::{Player, add_unit};
|
||||
use crate::player_events::{IncidentTarget, PersistentEvent, PersistentEvents};
|
||||
use crate::position::Position;
|
||||
|
|
@ -78,7 +78,7 @@ pub(crate) fn barbarians_bonus() -> Builtin {
|
|||
1
|
||||
};
|
||||
Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::sum(sum, &[ResourceType::Gold]),
|
||||
ResourceReward::sum(sum, &[ResourceType::Gold]),
|
||||
"-".to_string(),
|
||||
))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -16,7 +16,7 @@ use crate::status_phase::{
|
|||
get_status_phase, may_change_government, raze_city,
|
||||
};
|
||||
use crate::tactics_card::TacticsCard;
|
||||
use crate::wonder::Wonder;
|
||||
use crate::wonder::{Wonder, WonderInfo};
|
||||
use itertools::Itertools;
|
||||
use std::collections::HashMap;
|
||||
|
||||
|
|
@ -41,8 +41,7 @@ pub struct Cache {
|
|||
all_objectives: Vec<Objective>,
|
||||
objectives_by_name: HashMap<String, Objective>,
|
||||
|
||||
all_wonders: Vec<Wonder>,
|
||||
wonders_by_name: HashMap<String, Wonder>,
|
||||
all_wonders: Vec<WonderInfo>,
|
||||
|
||||
all_incidents: Vec<Incident>,
|
||||
incidents_by_id: HashMap<u8, Incident>,
|
||||
|
|
@ -118,11 +117,10 @@ impl Cache {
|
|||
.map(|objective| (objective.name.clone(), objective))
|
||||
.collect(),
|
||||
|
||||
all_wonders: wonders::get_all_uncached(),
|
||||
wonders_by_name: wonders::get_all_uncached()
|
||||
all_wonders: wonders::get_all_uncached()
|
||||
.into_iter()
|
||||
.map(|wonder| (wonder.name.clone(), wonder))
|
||||
.collect(),
|
||||
.sorted_by_key(|w| w.wonder)
|
||||
.collect_vec(),
|
||||
|
||||
all_incidents: incidents::get_all_uncached(),
|
||||
incidents_by_id: incidents::get_all_uncached()
|
||||
|
|
@ -278,19 +276,13 @@ impl Cache {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_wonders(&self) -> &Vec<Wonder> {
|
||||
pub fn get_wonders(&self) -> &Vec<WonderInfo> {
|
||||
&self.all_wonders
|
||||
}
|
||||
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if wonder does not exist
|
||||
#[must_use]
|
||||
pub fn get_wonder(&self, name: &str) -> &Wonder {
|
||||
self.wonders_by_name
|
||||
.get(name)
|
||||
.unwrap_or_else(|| panic!("wonder not found: {name}"))
|
||||
pub fn get_wonder(&self, w: Wonder) -> &WonderInfo {
|
||||
&self.all_wonders[w as usize]
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
|
|||
|
|
@ -5,6 +5,7 @@ use crate::game::Game;
|
|||
use crate::objective_card::match_objective_cards;
|
||||
use crate::player::Player;
|
||||
use crate::utils::Shuffle;
|
||||
use crate::wonder::Wonder;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
@ -30,7 +31,7 @@ impl HandCardType {
|
|||
pub enum HandCard {
|
||||
ActionCard(u8),
|
||||
ObjectiveCard(u8),
|
||||
Wonder(String),
|
||||
Wonder(Wonder),
|
||||
}
|
||||
|
||||
pub(crate) fn draw_card_from_pile<T>(
|
||||
|
|
@ -91,7 +92,7 @@ pub fn hand_cards(player: &Player, types: &[HandCardType]) -> Vec<HandCard> {
|
|||
HandCardType::Wonder => player
|
||||
.wonder_cards
|
||||
.iter()
|
||||
.map(|n| HandCard::Wonder(n.clone()))
|
||||
.map(|n| HandCard::Wonder(*n))
|
||||
.collect(),
|
||||
})
|
||||
.collect()
|
||||
|
|
|
|||
|
|
@ -111,12 +111,12 @@ impl City {
|
|||
pub fn raze(self, game: &mut Game, player_index: usize) {
|
||||
for wonder in &self.pieces.wonders {
|
||||
game.cache
|
||||
.get_wonder(wonder)
|
||||
.get_wonder(*wonder)
|
||||
.listeners
|
||||
.clone()
|
||||
.deinit(game, player_index);
|
||||
}
|
||||
for wonder in &self.pieces.wonders {
|
||||
for wonder in self.pieces.wonders {
|
||||
for p in &mut game.players {
|
||||
p.remove_wonder(wonder);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::city::City;
|
||||
use crate::wonder::Wonder;
|
||||
use Building::*;
|
||||
use num::Zero;
|
||||
|
||||
|
|
@ -13,7 +14,7 @@ pub struct CityPieces {
|
|||
pub fortress: Option<usize>,
|
||||
pub port: Option<usize>,
|
||||
pub temple: Option<usize>,
|
||||
pub wonders: Vec<String>,
|
||||
pub wonders: Vec<Wonder>,
|
||||
}
|
||||
|
||||
impl CityPieces {
|
||||
|
|
@ -174,7 +175,7 @@ pub struct CityPiecesData {
|
|||
temple: Option<usize>,
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
#[serde(default)]
|
||||
wonders: Vec<String>,
|
||||
wonders: Vec<Wonder>,
|
||||
}
|
||||
|
||||
pub struct DestroyedStructures {
|
||||
|
|
|
|||
|
|
@ -2,10 +2,10 @@ use crate::city::City;
|
|||
use crate::city::MoodState::Angry;
|
||||
use crate::city_pieces::{Building, remove_building};
|
||||
use crate::combat_listeners::{
|
||||
Casualties, CombatEventPhase, CombatResult, CombatRoundEnd, CombatRoundStart, CombatStrength,
|
||||
CombatEventPhase, CombatResult, CombatRoundEnd, CombatRoundStart, CombatStrength,
|
||||
combat_round_end, combat_round_start,
|
||||
};
|
||||
use crate::combat_roll::CombatRoundStats;
|
||||
use crate::combat_roll::{CombatHits, CombatRoundStats};
|
||||
use crate::combat_stats;
|
||||
use crate::combat_stats::{CombatStats, active_defenders, new_combat_stats};
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
|
|
@ -275,11 +275,9 @@ pub(crate) fn combat_loop(game: &mut Game, mut s: CombatRoundStart) {
|
|||
|
||||
let result = if let Some(result) = s.final_result {
|
||||
let mut round_end = CombatRoundEnd::new(
|
||||
Casualties::new(0, None),
|
||||
Casualties::new(0, None),
|
||||
false,
|
||||
CombatHits::new(None, 0, 0, 0),
|
||||
CombatHits::new(None, 0, 0, 0),
|
||||
c,
|
||||
game,
|
||||
);
|
||||
round_end.final_result = Some(result);
|
||||
round_end.phase = CombatEventPhase::Default;
|
||||
|
|
@ -288,19 +286,10 @@ pub(crate) fn combat_loop(game: &mut Game, mut s: CombatRoundStart) {
|
|||
let mut a = CombatRoundStats::roll(c.attacker, &c, game, s.attacker_strength);
|
||||
let mut d = CombatRoundStats::roll(c.defender, &c, game, s.defender_strength);
|
||||
|
||||
a.determine_hits(&d, game);
|
||||
d.determine_hits(&a, game);
|
||||
|
||||
let can_retreat = matches!(c.retreat, CombatRetreatState::CanRetreat)
|
||||
&& a.hits < d.fighters
|
||||
&& d.hits < a.fighters;
|
||||
|
||||
CombatRoundEnd::new(
|
||||
Casualties::new(d.hits, a_t),
|
||||
Casualties::new(a.hits, d_t),
|
||||
can_retreat,
|
||||
a.determine_hits(&d, game, a_t),
|
||||
d.determine_hits(&a, game, d_t),
|
||||
c,
|
||||
game,
|
||||
)
|
||||
};
|
||||
|
||||
|
|
@ -346,10 +335,16 @@ pub(crate) fn conquer_city(
|
|||
city.player_index = new_player_index;
|
||||
city.set_mood_state(Angry);
|
||||
if attacker_is_human {
|
||||
for wonder in &city.pieces.wonders {
|
||||
for wonder in city.pieces.wonders.clone() {
|
||||
let listeners = game.cache.get_wonder(wonder).listeners.clone();
|
||||
listeners.deinit(game, old_player_index);
|
||||
listeners.init(game, new_player_index);
|
||||
game.player_mut(old_player_index)
|
||||
.wonders_owned
|
||||
.remove(wonder);
|
||||
game.player_mut(new_player_index)
|
||||
.wonders_owned
|
||||
.insert(wonder);
|
||||
}
|
||||
|
||||
for (building, owner) in city.pieces.building_owners() {
|
||||
|
|
@ -506,7 +501,7 @@ pub mod tests {
|
|||
use crate::log::{ActionLogAge, ActionLogItem, ActionLogPlayer, ActionLogRound};
|
||||
use crate::movement::MovementAction;
|
||||
use crate::utils::tests::FloatEq;
|
||||
use crate::wonder::construct_wonder;
|
||||
use crate::wonder::{Wonder, construct_wonder, wonders_owned_points};
|
||||
use crate::{
|
||||
city::{City, MoodState::*},
|
||||
city_pieces::Building::*,
|
||||
|
|
@ -570,7 +565,7 @@ pub mod tests {
|
|||
|
||||
let position = Position::new(0, 0);
|
||||
game.players[old].cities.push(City::new(old, position));
|
||||
construct_wonder(&mut game, "Pyramids", position, old);
|
||||
construct_wonder(&mut game, Wonder::GreatGardens, position, old);
|
||||
game.players[old].construct(Academy, position, None, true);
|
||||
game.players[old].construct(Obelisk, position, None, true);
|
||||
|
||||
|
|
@ -586,8 +581,8 @@ pub mod tests {
|
|||
let new = &game.players[new];
|
||||
old.victory_points(&game).assert_eq(3.0);
|
||||
new.victory_points(&game).assert_eq(4.0);
|
||||
assert_eq!(0, old.wonders_owned());
|
||||
assert_eq!(1, new.wonders_owned());
|
||||
assert_eq!(0, wonders_owned_points(old, &game));
|
||||
assert_eq!(2, wonders_owned_points(new, &game));
|
||||
assert_eq!(1, old.owned_buildings(&game));
|
||||
assert_eq!(1, new.owned_buildings(&game));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::combat::{Combat, CombatRetreatState, capture_position};
|
||||
use crate::combat_roll::CombatHits;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::persistent_events::{PersistentEventType, PositionRequest, UnitsRequest};
|
||||
use crate::game::Game;
|
||||
|
|
@ -17,9 +18,17 @@ use serde::{Deserialize, Serialize};
|
|||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct CombatStrength {
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "u8::is_zero")]
|
||||
pub extra_dies: u8,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "i8::is_zero")]
|
||||
pub extra_combat_value: i8,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "u8::is_zero")]
|
||||
pub hit_cancels: u8,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub roll_log: Vec<String>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
|
|
@ -185,35 +194,13 @@ impl CombatEnd {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct Casualties {
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "u8::is_zero")]
|
||||
pub fighters: u8,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tactics_card: Option<u8>,
|
||||
}
|
||||
|
||||
impl Casualties {
|
||||
#[must_use]
|
||||
pub fn new(fighters: u8, tactics_card: Option<u8>) -> Self {
|
||||
Self {
|
||||
fighters,
|
||||
tactics_card,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct CombatRoundEnd {
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "CombatEventPhase::is_default")]
|
||||
pub phase: CombatEventPhase,
|
||||
pub attacker_casualties: Casualties,
|
||||
pub defender_casualties: Casualties,
|
||||
#[serde(default)]
|
||||
pub can_retreat: bool,
|
||||
pub(crate) attacker: CombatHits,
|
||||
pub(crate) defender: CombatHits,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub final_result: Option<CombatResult>,
|
||||
|
|
@ -222,32 +209,27 @@ pub struct CombatRoundEnd {
|
|||
|
||||
impl CombatRoundEnd {
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
attacker_casualties: Casualties,
|
||||
defender_casualties: Casualties,
|
||||
can_retreat: bool,
|
||||
combat: Combat,
|
||||
game: &Game,
|
||||
) -> Self {
|
||||
pub(crate) fn new(attacker: CombatHits, defender: CombatHits, combat: Combat) -> Self {
|
||||
let mut combat_round_end = Self {
|
||||
attacker_casualties,
|
||||
defender_casualties,
|
||||
can_retreat,
|
||||
attacker,
|
||||
defender,
|
||||
final_result: None,
|
||||
combat,
|
||||
phase: CombatEventPhase::TacticsCard,
|
||||
};
|
||||
combat_round_end.set_final_result(game);
|
||||
combat_round_end.set_final_result();
|
||||
combat_round_end
|
||||
}
|
||||
|
||||
pub(crate) fn set_final_result(&mut self, game: &Game) {
|
||||
let attackers_dead = self.combat.active_attackers(game).len()
|
||||
- self.attacker_casualties.fighters as usize
|
||||
== 0;
|
||||
let defenders_dead = self.combat.active_defenders(game).len()
|
||||
- self.defender_casualties.fighters as usize
|
||||
== 0;
|
||||
pub(crate) fn can_retreat(&self) -> bool {
|
||||
self.combat.retreat == CombatRetreatState::CanRetreat
|
||||
&& !self.attacker.all_opponents_killed()
|
||||
&& !self.defender.all_opponents_killed()
|
||||
}
|
||||
|
||||
pub(crate) fn set_final_result(&mut self) {
|
||||
let attackers_dead = self.defender.all_opponents_killed();
|
||||
let defenders_dead = self.attacker.all_opponents_killed();
|
||||
|
||||
self.final_result = if attackers_dead && defenders_dead {
|
||||
Some(CombatResult::Draw)
|
||||
|
|
@ -266,29 +248,41 @@ impl CombatRoundEnd {
|
|||
player,
|
||||
&self.combat,
|
||||
card,
|
||||
self.attacker_casualties.tactics_card.as_ref(),
|
||||
self.attacker.tactics_card.as_ref(),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
impl CombatRoundEnd {
|
||||
#[must_use]
|
||||
pub fn casualties(&self, role: CombatRole) -> &Casualties {
|
||||
pub fn hits(&self, role: CombatRole) -> u8 {
|
||||
if role.is_attacker() {
|
||||
&self.attacker_casualties
|
||||
self.attacker.hits()
|
||||
} else {
|
||||
&self.defender_casualties
|
||||
self.defender.hits()
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn casualties_mut(&mut self, role: CombatRole) -> &mut Casualties {
|
||||
pub fn losses(&self, role: CombatRole) -> u8 {
|
||||
if role.is_attacker() {
|
||||
&mut self.attacker_casualties
|
||||
self.defender.hits()
|
||||
} else {
|
||||
&mut self.defender_casualties
|
||||
self.attacker.hits()
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn hits_mut(&mut self, role: CombatRole) -> &mut CombatHits {
|
||||
if role.is_attacker() {
|
||||
&mut self.attacker
|
||||
} else {
|
||||
&mut self.defender
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn role(&self, player: usize) -> CombatRole {
|
||||
self.combat.role(player)
|
||||
}
|
||||
}
|
||||
|
||||
const ROUND_START_TYPES: &[CombatEventPhase; 3] = &[
|
||||
|
|
@ -335,8 +329,8 @@ pub(crate) fn combat_round_end(game: &mut Game, r: CombatRoundEnd) -> Option<Com
|
|||
},
|
||||
|s| &mut s.phase,
|
||||
|s| &s.combat,
|
||||
|s| s.attacker_casualties.tactics_card.as_ref(),
|
||||
|s| s.defender_casualties.tactics_card.as_ref(),
|
||||
|s| s.attacker.tactics_card.as_ref(),
|
||||
|s| s.defender.tactics_card.as_ref(),
|
||||
);
|
||||
let e = e?;
|
||||
|
||||
|
|
@ -542,13 +536,13 @@ pub(crate) fn choose_fighter_casualties() -> Builtin {
|
|||
move |game, player, r| {
|
||||
let choices = r.combat.fighting_units(game, player).clone();
|
||||
|
||||
let role = r.combat.role(player);
|
||||
let role = r.role(player);
|
||||
let role_str = if role.is_attacker() {
|
||||
"attacking"
|
||||
} else {
|
||||
"defending"
|
||||
};
|
||||
let casualties = r.casualties(role).fighters;
|
||||
let casualties = r.losses(role);
|
||||
if casualties == 0 {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -599,7 +593,7 @@ pub(crate) fn offer_retreat() -> Builtin {
|
|||
0,
|
||||
|game, player, r| {
|
||||
let c = &r.combat;
|
||||
if c.attacker == player && r.can_retreat {
|
||||
if c.attacker == player && r.can_retreat() {
|
||||
let name = game.player_name(player);
|
||||
game.add_info_log_item(&format!("{name} can retreat",));
|
||||
Some("Do you want to retreat?".to_string())
|
||||
|
|
|
|||
|
|
@ -3,6 +3,56 @@ use crate::combat_listeners::CombatStrength;
|
|||
use crate::game::Game;
|
||||
use crate::unit::UnitType::{Cavalry, Elephant, Infantry, Leader};
|
||||
use crate::unit::{UnitType, Units};
|
||||
use num::Zero;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub(crate) struct CombatHits {
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub tactics_card: Option<u8>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "u8::is_zero")]
|
||||
pub opponent_hit_cancels: u8,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "u8::is_zero")]
|
||||
pub opponent_fighters: u8,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "u8::is_zero")]
|
||||
pub combat_value: u8,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "u8::is_zero")]
|
||||
pub extra_hits: u8, // that cannot be cancelled
|
||||
}
|
||||
|
||||
impl CombatHits {
|
||||
#[must_use]
|
||||
pub(crate) fn new(
|
||||
tactics_card: Option<u8>,
|
||||
opponent_hit_cancels: u8,
|
||||
opponent_fighters: u8,
|
||||
combat_value: u8,
|
||||
) -> CombatHits {
|
||||
CombatHits {
|
||||
tactics_card,
|
||||
opponent_hit_cancels,
|
||||
opponent_fighters,
|
||||
combat_value,
|
||||
extra_hits: 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn hits(&self) -> u8 {
|
||||
let hits =
|
||||
(self.combat_value / 5).saturating_sub(self.opponent_hit_cancels) + self.extra_hits;
|
||||
hits.min(self.opponent_fighters)
|
||||
}
|
||||
|
||||
pub(crate) fn all_opponents_killed(&self) -> bool {
|
||||
self.hits() == self.opponent_fighters
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) struct CombatRoundStats {
|
||||
player: usize,
|
||||
|
|
@ -11,7 +61,6 @@ pub(crate) struct CombatRoundStats {
|
|||
log_str: String,
|
||||
combat_value: u8,
|
||||
hit_cancels: u8,
|
||||
pub(crate) hits: u8,
|
||||
strength: CombatStrength,
|
||||
}
|
||||
|
||||
|
|
@ -51,21 +100,29 @@ impl CombatRoundStats {
|
|||
log_str,
|
||||
combat_value,
|
||||
hit_cancels,
|
||||
hits: 0,
|
||||
fighters: fighting.len() as u8,
|
||||
}
|
||||
}
|
||||
|
||||
pub(crate) fn determine_hits(&mut self, opponent: &CombatRoundStats, game: &mut Game) {
|
||||
self.hits = (self.combat_value / 5)
|
||||
.saturating_sub(opponent.hit_cancels)
|
||||
.min(opponent.fighters);
|
||||
pub(crate) fn determine_hits(
|
||||
&mut self,
|
||||
opponent: &CombatRoundStats,
|
||||
game: &mut Game,
|
||||
a_t: Option<u8>,
|
||||
) -> CombatHits {
|
||||
let combat_hits = CombatHits::new(
|
||||
a_t,
|
||||
opponent.hit_cancels,
|
||||
opponent.fighters,
|
||||
self.combat_value,
|
||||
);
|
||||
let hits = combat_hits.hits();
|
||||
|
||||
let name = game.player_name(self.player);
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} rolled {} for combined combat value of {} and gets {} hits \
|
||||
against {} units.",
|
||||
self.log_str, self.combat_value, self.hits, self.opponent_str,
|
||||
self.log_str, self.combat_value, hits, self.opponent_str,
|
||||
));
|
||||
|
||||
if !self.strength.roll_log.is_empty() {
|
||||
|
|
@ -74,6 +131,7 @@ impl CombatRoundStats {
|
|||
self.strength.roll_log.join(", ")
|
||||
));
|
||||
}
|
||||
combat_hits
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ pub const ADVANCE_COST: u8 = 2;
|
|||
pub const BUILDING_VICTORY_POINTS: f32 = 1.0;
|
||||
pub const ADVANCE_VICTORY_POINTS: f32 = 0.5;
|
||||
pub const OBJECTIVE_VICTORY_POINTS: f32 = 2.0;
|
||||
pub const WONDER_VICTORY_POINTS: f32 = 4.0;
|
||||
pub const WONDER_VICTORY_POINTS: u8 = 4;
|
||||
pub const CAPTURED_LEADER_VICTORY_POINTS: f32 = 2.0;
|
||||
pub const STACK_LIMIT: usize = 4;
|
||||
pub const SHIP_CAPACITY: u8 = 2;
|
||||
|
|
|
|||
|
|
@ -4,11 +4,13 @@ use crate::barbarians::get_barbarians_player;
|
|||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_actions::CustomActionType;
|
||||
use crate::content::effects::PermanentEffect;
|
||||
use crate::content::persistent_events::{Structure, UnitTypeRequest};
|
||||
use crate::content::persistent_events::{SelectedStructure, Structure, UnitTypeRequest};
|
||||
use crate::content::tactics_cards::TacticsCardFactory;
|
||||
use crate::cultural_influence::InfluenceCultureInfo;
|
||||
use crate::cultural_influence::{
|
||||
InfluenceCultureInfo, available_influence_actions, influence_culture_boost_cost,
|
||||
};
|
||||
use crate::game::Game;
|
||||
use crate::player::{add_unit, remove_unit};
|
||||
use crate::player::{Player, add_unit, remove_unit};
|
||||
use crate::player_events::PlayingActionInfo;
|
||||
use crate::playing_actions::{ActionCost, PlayingActionType};
|
||||
use crate::unit::UnitType;
|
||||
|
|
@ -24,7 +26,7 @@ pub(crate) fn cultural_takeover(id: u8, tactics_card: TacticsCardFactory) -> Act
|
|||
Replace one of the Barbarian units with a Settler or Infantry of your color. \
|
||||
Remove the other Barbarian units.",
|
||||
ActionCost::free(),
|
||||
|_game, _p, _| true,
|
||||
|game, p, _| any_barbarian_city_can_be_influenced(game, p),
|
||||
)
|
||||
.add_unit_type_request(
|
||||
|event| &mut event.play_action_card,
|
||||
|
|
@ -94,6 +96,26 @@ pub(crate) fn cultural_takeover(id: u8, tactics_card: TacticsCardFactory) -> Act
|
|||
.build()
|
||||
}
|
||||
|
||||
fn any_barbarian_city_can_be_influenced(game: &Game, p: &Player) -> bool {
|
||||
let influence = available_influence_actions(game, p.index);
|
||||
if influence.is_empty() {
|
||||
return false;
|
||||
}
|
||||
get_barbarians_player(game).cities.iter().any(|c| {
|
||||
c.size() == 1
|
||||
&& influence.iter().any(|i| {
|
||||
influence_culture_boost_cost(
|
||||
game,
|
||||
p.index,
|
||||
&SelectedStructure::new(c.position, Structure::CityCenter),
|
||||
Some(i),
|
||||
true,
|
||||
)
|
||||
.is_ok()
|
||||
})
|
||||
})
|
||||
}
|
||||
|
||||
pub(crate) fn use_cultural_takeover() -> Builtin {
|
||||
Builtin::builder("cultural_takeover", "-")
|
||||
.add_transient_event_listener(
|
||||
|
|
@ -116,7 +138,7 @@ pub(crate) fn use_cultural_takeover() -> Builtin {
|
|||
|c, _, game| {
|
||||
if let Ok(i) = c {
|
||||
if matches!(i.structure, Structure::CityCenter)
|
||||
&& !is_barbarian_takeover(game, i)
|
||||
&& !(is_barbarian_takeover(game, i) || i.barbarian_takeover_check)
|
||||
{
|
||||
*c = Err("City center can't be influenced".to_string());
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action_card::ActionCard;
|
||||
use crate::collect::available_collect_actions_for_city;
|
||||
use crate::content::action_cards::cultural_takeover::cultural_takeover;
|
||||
use crate::content::action_cards::mercenaries::mercenaries;
|
||||
use crate::content::builtin::Builtin;
|
||||
|
|
@ -12,7 +13,8 @@ use crate::content::tactics_cards::{
|
|||
TacticsCardFactory, defensive_formation, encircled, for_the_people, heavy_resistance,
|
||||
improved_defenses, peltasts, tactical_retreat,
|
||||
};
|
||||
use crate::player::add_unit;
|
||||
use crate::game::Game;
|
||||
use crate::player::{Player, add_unit};
|
||||
use crate::player_events::PlayingActionInfo;
|
||||
use crate::playing_actions::{ActionCost, PlayingActionType};
|
||||
use crate::resource_pile::ResourcePile;
|
||||
|
|
@ -66,7 +68,7 @@ fn production_focus(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
"For the next collect action, you may collect multiple times from the same tile. \
|
||||
The total amount of resources does not change.",
|
||||
ActionCost::regular(),
|
||||
|_game, _player, _| true,
|
||||
|game, player, _| collect_special_action(game, player),
|
||||
)
|
||||
.tactics_card(tactics_card)
|
||||
.add_simple_persistent_event_listener(
|
||||
|
|
@ -84,6 +86,17 @@ fn production_focus(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn collect_special_action(game: &Game, player: &Player) -> bool {
|
||||
!game
|
||||
.permanent_effects
|
||||
.iter()
|
||||
.any(|e| matches!(e, PermanentEffect::Collect(_)))
|
||||
&& player
|
||||
.cities
|
||||
.iter()
|
||||
.any(|c| !available_collect_actions_for_city(game, player.index, c.position).is_empty())
|
||||
}
|
||||
|
||||
pub(crate) fn collect_only() -> Builtin {
|
||||
Builtin::builder("collect only", "-")
|
||||
.add_transient_event_listener(
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::content::tactics_cards::{
|
|||
surprise, wedge_formation,
|
||||
};
|
||||
use crate::game::Game;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::Player;
|
||||
use crate::playing_actions::ActionCost;
|
||||
use crate::position::Position;
|
||||
|
|
@ -40,10 +40,8 @@ fn advance(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
id,
|
||||
"Advance",
|
||||
"Pay 1 culture token: Gain 1 advance without changing the Game Event counter.",
|
||||
ActionCost::free(),
|
||||
|game, player, _| {
|
||||
player.resources.culture_tokens >= 1 && !possible_advances(player, game).is_empty()
|
||||
},
|
||||
ActionCost::cost(ResourcePile::culture_tokens(1)),
|
||||
|game, player, _| !possible_advances(player, game).is_empty(),
|
||||
)
|
||||
.tactics_card(tactics_card)
|
||||
.add_advance_request(
|
||||
|
|
@ -66,7 +64,7 @@ fn advance(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
);
|
||||
let name = &sel.player_name;
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} gained {} for 1 culture token using the Advance action card.",
|
||||
"{name} gained {} using the Advance action card.",
|
||||
advance.name(game)
|
||||
));
|
||||
},
|
||||
|
|
@ -177,14 +175,18 @@ fn hero_general(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
|e| &mut e.play_action_card,
|
||||
1,
|
||||
|game, player, _| {
|
||||
if cities_where_mood_can_increase(game.player(player)).is_empty() {
|
||||
let p = game.player(player);
|
||||
if cities_where_mood_can_increase(p).is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(vec![PaymentRequest::new(
|
||||
PaymentOptions::resources(ResourcePile::mood_tokens(1)),
|
||||
Some(vec![PaymentRequest::optional(
|
||||
PaymentOptions::resources(
|
||||
p,
|
||||
PaymentReason::ActionCard,
|
||||
ResourcePile::mood_tokens(1),
|
||||
),
|
||||
"Pay 1 mood token to increase the mood in a city by 1",
|
||||
true,
|
||||
)])
|
||||
},
|
||||
|game, s, a| {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::content::tactics_cards::TacticsCardFactory;
|
|||
use crate::game::Game;
|
||||
use crate::log::move_action_log;
|
||||
use crate::movement::MoveUnits;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::Player;
|
||||
use crate::playing_actions::ActionCost;
|
||||
use crate::position::Position;
|
||||
|
|
@ -60,9 +60,11 @@ pub(crate) fn mercenaries(id: u8, tactics_card: TacticsCardFactory) -> ActionCar
|
|||
.add_payment_request_listener(
|
||||
|e| &mut e.play_action_card,
|
||||
1,
|
||||
|_game, _player, a| {
|
||||
Some(vec![PaymentRequest::new(
|
||||
|game, player, a| {
|
||||
Some(vec![PaymentRequest::mandatory(
|
||||
PaymentOptions::sum(
|
||||
game.player(player),
|
||||
PaymentReason::Incident,
|
||||
a.selected_positions.len() as u8,
|
||||
&[
|
||||
ResourceType::Food,
|
||||
|
|
@ -73,7 +75,6 @@ pub(crate) fn mercenaries(id: u8, tactics_card: TacticsCardFactory) -> ActionCar
|
|||
],
|
||||
),
|
||||
"Pay for mercenaries",
|
||||
false,
|
||||
)])
|
||||
},
|
||||
|game, s, _| {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action::Action;
|
||||
use crate::action_card::ActionCard;
|
||||
use crate::city::City;
|
||||
use crate::content::action_cards::development::collect_special_action;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::effects::{CollectEffect, PermanentEffect};
|
||||
use crate::content::incidents::great_diplomat::{DiplomaticRelations, Negotiations};
|
||||
|
|
@ -225,13 +225,7 @@ fn overproduction(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
"You may collect from 2 additional tiles this turn. \
|
||||
(Cannot combine with Production Focus or another Overproduction.)",
|
||||
ActionCost::regular(),
|
||||
move |game, p, _| {
|
||||
!game
|
||||
.permanent_effects
|
||||
.iter()
|
||||
.any(|e| matches!(e, PermanentEffect::Collect(_)))
|
||||
&& p.cities.iter().any(City::can_activate)
|
||||
},
|
||||
move |game, p, _| collect_special_action(game, p),
|
||||
)
|
||||
.tactics_card(tactics_card)
|
||||
.add_simple_persistent_event_listener(
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::playing_actions::ActionCost;
|
|||
use crate::resource_pile::ResourcePile;
|
||||
use crate::utils::remove_element;
|
||||
use itertools::Itertools;
|
||||
use std::fmt::Display;
|
||||
use std::fmt::Debug;
|
||||
|
||||
pub(crate) fn spy(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
||||
ActionCard::builder(
|
||||
|
|
@ -150,7 +150,7 @@ fn swap_cards(
|
|||
Ok(())
|
||||
}
|
||||
|
||||
fn swap_card<T: PartialEq + Ord + Display>(
|
||||
fn swap_card<T: PartialEq + Ord + Debug>(
|
||||
game: &mut Game,
|
||||
player: usize,
|
||||
other: usize,
|
||||
|
|
@ -159,10 +159,10 @@ fn swap_card<T: PartialEq + Ord + Display>(
|
|||
get_list: impl Fn(&mut Player) -> &mut Vec<T>,
|
||||
) {
|
||||
let card = remove_element(get_list(game.player_mut(player)), id)
|
||||
.unwrap_or_else(|| panic!("card not found {id}"));
|
||||
.unwrap_or_else(|| panic!("card not found {id:?}"));
|
||||
let o = game.player_mut(other);
|
||||
let other_card = remove_element(get_list(o), other_id)
|
||||
.unwrap_or_else(|| panic!("other card not found {other_id}"));
|
||||
.unwrap_or_else(|| panic!("other card not found {other_id:?}"));
|
||||
|
||||
get_list(o).push(card);
|
||||
get_list(o).sort();
|
||||
|
|
@ -218,11 +218,7 @@ fn get_swap_secrets(other: &Player, game: &Game) -> Vec<String> {
|
|||
format!(
|
||||
"{} has the following wonder cards: {}",
|
||||
other.get_name(),
|
||||
other
|
||||
.wonder_cards
|
||||
.iter()
|
||||
.map(std::string::ToString::to_string)
|
||||
.join(", ")
|
||||
other.wonder_cards.iter().map(|w| w.name(game)).join(", ")
|
||||
),
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,11 +106,10 @@ fn pay_for_advance(b: ActionCardBuilder, priority: i32) -> ActionCardBuilder {
|
|||
|game, player_index, i| {
|
||||
let p = game.player(player_index);
|
||||
let advance = i.selected_advance.expect("advance not found");
|
||||
Some(vec![PaymentRequest::new(
|
||||
Some(vec![PaymentRequest::mandatory(
|
||||
p.advance_cost(advance, game, game.execute_cost_trigger())
|
||||
.cost,
|
||||
&format!("Pay for {}", advance.name(game)),
|
||||
false,
|
||||
)])
|
||||
},
|
||||
|game, s, i| {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::content::advances::{AdvanceGroup, advance_group_builder};
|
|||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_actions::CustomActionType::{AbsolutePower, ForcedLabor};
|
||||
use crate::content::persistent_events::ResourceRewardRequest;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::ResourceReward;
|
||||
|
||||
pub(crate) fn autocracy() -> AdvanceGroup {
|
||||
advance_group_builder(
|
||||
|
|
@ -36,7 +36,7 @@ fn nationalism() -> AdvanceBuilder {
|
|||
.any(|u| u.is_army_unit() || u.is_ship())
|
||||
{
|
||||
Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::tokens(1),
|
||||
ResourceReward::tokens(1),
|
||||
"Select token to gain".to_string(),
|
||||
))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ use crate::content::builtin::Builtin;
|
|||
use crate::content::custom_actions::CustomActionType;
|
||||
use crate::content::persistent_events::PaymentRequest;
|
||||
use crate::happiness::increase_happiness;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::Player;
|
||||
use crate::resource::ResourceType;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::wonder::draw_wonder_card;
|
||||
|
|
@ -74,11 +75,18 @@ fn theaters() -> AdvanceBuilder {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn sports_options(city: &City) -> Option<PaymentOptions> {
|
||||
pub fn sports_options(player: &Player, city: &City) -> Option<PaymentOptions> {
|
||||
match city.mood_state {
|
||||
MoodState::Happy => None,
|
||||
MoodState::Neutral => Some(PaymentOptions::sum(1, &[ResourceType::CultureTokens])),
|
||||
MoodState::Neutral => Some(PaymentOptions::sum(
|
||||
player,
|
||||
PaymentReason::CustomAction,
|
||||
1,
|
||||
&[ResourceType::CultureTokens],
|
||||
)),
|
||||
MoodState::Angry => Some(PaymentOptions::single_type(
|
||||
player,
|
||||
PaymentReason::CustomAction,
|
||||
ResourceType::CultureTokens,
|
||||
1..=2,
|
||||
)),
|
||||
|
|
@ -90,52 +98,43 @@ pub(crate) fn use_sports() -> Builtin {
|
|||
.add_payment_request_listener(
|
||||
|event| &mut event.custom_action,
|
||||
0,
|
||||
|game, _player_index, a| {
|
||||
let options = sports_options(game.get_any_city(a.city.expect("city not found")))
|
||||
|game, player_index, a| {
|
||||
let p = game.player(player_index);
|
||||
let options = sports_options(p, p.get_city(a.city.expect("city not found")))
|
||||
.expect("Invalid options for sports");
|
||||
Some(vec![PaymentRequest::new(
|
||||
Some(vec![PaymentRequest::mandatory(
|
||||
options,
|
||||
"Each culture token increases the happiness by 1 step",
|
||||
false,
|
||||
)])
|
||||
},
|
||||
|game, s, a| {
|
||||
let position = a.city.expect("city not found");
|
||||
let steps = s.choice[0].culture_tokens;
|
||||
increase_happiness(
|
||||
game,
|
||||
s.player_index,
|
||||
&[(position, steps)],
|
||||
None,
|
||||
);
|
||||
game.add_info_log_item(
|
||||
&format!(
|
||||
"{} used Sports to increase the happiness of {} by {steps} steps, making it {:?}",
|
||||
s.player_name,
|
||||
position,
|
||||
game.get_any_city(position).mood_state
|
||||
),
|
||||
);
|
||||
let pile = s.choice[0].clone();
|
||||
let steps = pile.amount();
|
||||
increase_happiness(game, s.player_index, &[(position, steps)], None);
|
||||
game.add_info_log_item(&format!(
|
||||
"{} paid {pile} for Sports to increase the happiness of {position} \
|
||||
by {steps} steps, making it {:?}",
|
||||
s.player_name,
|
||||
game.get_any_city(position).mood_state
|
||||
));
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn theaters_options() -> PaymentOptions {
|
||||
PaymentOptions::sum(1, &[ResourceType::CultureTokens, ResourceType::MoodTokens])
|
||||
}
|
||||
|
||||
pub(crate) fn use_theaters() -> Builtin {
|
||||
Builtin::builder("Theaters", THEATERS_DESC)
|
||||
.add_payment_request_listener(
|
||||
|event| &mut event.custom_action,
|
||||
0,
|
||||
|_game, _player_index, _| {
|
||||
Some(vec![PaymentRequest::new(
|
||||
theaters_options(),
|
||||
|game, player, _| {
|
||||
Some(vec![PaymentRequest::mandatory(
|
||||
PaymentOptions::sum(
|
||||
game.player(player),
|
||||
PaymentReason::CustomAction,
|
||||
1, &[ResourceType::CultureTokens, ResourceType::MoodTokens]),
|
||||
"Convert 1 culture token into 1 mood token, or 1 mood token into 1 culture token",
|
||||
false,
|
||||
)])
|
||||
},
|
||||
|game, s, _| {
|
||||
|
|
|
|||
|
|
@ -11,7 +11,7 @@ use crate::content::custom_actions::CustomActionType;
|
|||
use crate::content::custom_actions::CustomActionType::Taxes;
|
||||
use crate::content::persistent_events::{HandCardsRequest, ResourceRewardRequest};
|
||||
use crate::game::Game;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::ResourceReward;
|
||||
use crate::player::Player;
|
||||
use crate::player_events::{PersistentEvent, PersistentEvents};
|
||||
use crate::resource::ResourceType;
|
||||
|
|
@ -79,7 +79,7 @@ pub(crate) fn use_bartering() -> Builtin {
|
|||
0,
|
||||
|_game, _player_index, _| {
|
||||
Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::sum(1, &[ResourceType::Gold, ResourceType::CultureTokens]),
|
||||
ResourceReward::sum(1, &[ResourceType::Gold, ResourceType::CultureTokens]),
|
||||
"Select a resource to gain".to_string(),
|
||||
))
|
||||
},
|
||||
|
|
@ -124,12 +124,12 @@ pub(crate) fn use_taxes() -> Builtin {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn tax_options(player: &Player) -> PaymentOptions {
|
||||
pub fn tax_options(player: &Player) -> ResourceReward {
|
||||
let mut c = vec![ResourceType::Food, ResourceType::Wood, ResourceType::Ore];
|
||||
if player.has_advance(Advance::Currency) {
|
||||
c.insert(0, ResourceType::Gold);
|
||||
}
|
||||
PaymentOptions::sum(player.cities.len() as u8, &c)
|
||||
ResourceReward::sum(player.cities.len() as u8, &c)
|
||||
}
|
||||
|
||||
fn trade_routes() -> AdvanceBuilder {
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::city_pieces::Building;
|
|||
use crate::content::advances::{AdvanceGroup, advance_group_builder};
|
||||
use crate::content::persistent_events::PaymentRequest;
|
||||
use crate::objective_card::draw_and_log_objective_card_from_pile;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::resource_pile::ResourcePile;
|
||||
|
||||
pub(crate) fn education() -> AdvanceGroup {
|
||||
|
|
@ -90,17 +90,20 @@ fn free_education() -> AdvanceBuilder {
|
|||
.add_payment_request_listener(
|
||||
|e| &mut e.advance,
|
||||
1,
|
||||
|_game, _player_index, i| {
|
||||
|game, player_index, i| {
|
||||
if i.advance == Advance::FreeEducation {
|
||||
None
|
||||
} else if i.payment.has_at_least(&ResourcePile::gold(1))
|
||||
|| i.payment.has_at_least(&ResourcePile::ideas(1))
|
||||
{
|
||||
Some(vec![PaymentRequest {
|
||||
cost: PaymentOptions::resources(ResourcePile::ideas(1)),
|
||||
name: "Pay extra 1 idea for a mood token".to_string(),
|
||||
optional: true,
|
||||
}])
|
||||
Some(vec![PaymentRequest::optional(
|
||||
PaymentOptions::resources(
|
||||
game.player(player_index),
|
||||
PaymentReason::AdvanceAbility,
|
||||
ResourcePile::ideas(1),
|
||||
),
|
||||
"Pay extra 1 idea for a mood token",
|
||||
)])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use crate::advance::{Advance, AdvanceBuilder, AdvanceInfo};
|
|||
use crate::city_pieces::Building;
|
||||
use crate::content::advances::{AdvanceGroup, advance_group_builder};
|
||||
use crate::content::persistent_events::ResourceRewardRequest;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::ResourceReward;
|
||||
use crate::resource::ResourceType;
|
||||
|
||||
pub(crate) fn science() -> AdvanceGroup {
|
||||
|
|
@ -87,7 +87,7 @@ fn medicine() -> AdvanceBuilder {
|
|||
}
|
||||
|
||||
Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::sum(1, &types),
|
||||
ResourceReward::sum(1, &types),
|
||||
"Select resource to gain back".to_string(),
|
||||
))
|
||||
},
|
||||
|
|
|
|||
|
|
@ -4,9 +4,8 @@ use crate::advance::{Advance, AdvanceBuilder, AdvanceInfo};
|
|||
use crate::city_pieces::Building::Temple;
|
||||
use crate::content::advances::{AdvanceGroup, advance_group_builder};
|
||||
use crate::content::persistent_events::ResourceRewardRequest;
|
||||
use crate::payment::{PaymentConversion, PaymentOptions};
|
||||
use crate::payment::{PaymentConversion, ResourceReward};
|
||||
use crate::resource::ResourceType;
|
||||
use crate::resource::ResourceType::{CultureTokens, MoodTokens};
|
||||
use crate::resource_pile::ResourcePile;
|
||||
|
||||
pub(crate) fn spirituality() -> AdvanceGroup {
|
||||
|
|
@ -31,7 +30,7 @@ fn myths() -> AdvanceBuilder {
|
|||
|_game, _player_index, building| {
|
||||
if matches!(building.building, Temple) {
|
||||
return Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::sum(1, &[MoodTokens, CultureTokens]),
|
||||
ResourceReward::tokens(1),
|
||||
"Select Temple bonus".to_string(),
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::advance::Advance;
|
||||
use crate::city::{City, MoodState};
|
||||
use crate::game::Game;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::ResourceReward;
|
||||
use crate::player::Player;
|
||||
use crate::position::Position;
|
||||
use crate::resource::ResourceType;
|
||||
|
|
@ -16,7 +16,7 @@ pub struct TradeRoute {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn trade_route_reward(game: &Game) -> Option<(PaymentOptions, Vec<TradeRoute>)> {
|
||||
pub fn trade_route_reward(game: &Game) -> Option<(ResourceReward, Vec<TradeRoute>)> {
|
||||
let p = game.current_player_index;
|
||||
let trade_routes = find_trade_routes(game, &game.players[p], false);
|
||||
if trade_routes.is_empty() {
|
||||
|
|
@ -25,12 +25,12 @@ pub fn trade_route_reward(game: &Game) -> Option<(PaymentOptions, Vec<TradeRoute
|
|||
|
||||
Some((
|
||||
if game.players[p].has_advance(Advance::Currency) {
|
||||
PaymentOptions::sum(
|
||||
ResourceReward::sum(
|
||||
trade_routes.len() as u8,
|
||||
&[ResourceType::Gold, ResourceType::Food],
|
||||
)
|
||||
} else {
|
||||
PaymentOptions::sum(trade_routes.len() as u8, &[ResourceType::Food])
|
||||
ResourceReward::sum(trade_routes.len() as u8, &[ResourceType::Food])
|
||||
},
|
||||
trade_routes,
|
||||
))
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::combat_listeners::CombatStrength;
|
|||
use crate::content::advances::{AdvanceGroup, advance_group_builder};
|
||||
use crate::content::persistent_events::PaymentRequest;
|
||||
use crate::game::Game;
|
||||
use crate::payment::{PaymentConversion, PaymentOptions};
|
||||
use crate::payment::{PaymentConversion, PaymentOptions, PaymentReason};
|
||||
use crate::player::Player;
|
||||
use crate::resource::ResourceType;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
|
|
@ -44,60 +44,76 @@ fn siegecraft() -> AdvanceBuilder {
|
|||
"When attacking a city with a Fortress, pay 2 wood to cancel the Fortress’ \
|
||||
ability to add +1 die and/or pay 2 ore to ignore its ability to cancel a hit.",
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.combat_start,
|
||||
0,
|
||||
|game, player, c| {
|
||||
let extra_die = PaymentOptions::sum(2, &[ResourceType::Wood, ResourceType::Gold]);
|
||||
let ignore_hit = PaymentOptions::sum(2, &[ResourceType::Ore, ResourceType::Gold]);
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.combat_start,
|
||||
0,
|
||||
|game, player, c| {
|
||||
let p = game.player(player);
|
||||
let extra_die = PaymentOptions::sum(
|
||||
p,
|
||||
PaymentReason::AdvanceAbility,
|
||||
2,
|
||||
&[ResourceType::Wood, ResourceType::Gold],
|
||||
);
|
||||
let ignore_hit = PaymentOptions::sum(
|
||||
p,
|
||||
PaymentReason::AdvanceAbility,
|
||||
2,
|
||||
&[ResourceType::Ore, ResourceType::Gold],
|
||||
);
|
||||
|
||||
let player = &game.players[player];
|
||||
if game
|
||||
.try_get_any_city(c.defender_position)
|
||||
.is_some_and(|c| c.pieces.fortress.is_some())
|
||||
&& (player.can_afford(&extra_die) || player.can_afford(&ignore_hit))
|
||||
{
|
||||
Some(vec![
|
||||
PaymentRequest {
|
||||
cost: extra_die,
|
||||
name: "Cancel fortress ability to add an extra die in the first round of combat".to_string(),
|
||||
optional: true,
|
||||
},
|
||||
PaymentRequest {
|
||||
cost: ignore_hit,
|
||||
name: "Cancel fortress ability to ignore the first hit in the first round of combat".to_string(),
|
||||
optional: true,
|
||||
},
|
||||
])
|
||||
} else {
|
||||
None
|
||||
let player = &game.players[player];
|
||||
if game
|
||||
.try_get_any_city(c.defender_position)
|
||||
.is_some_and(|c| c.pieces.fortress.is_some())
|
||||
&& (player.can_afford(&extra_die) || player.can_afford(&ignore_hit))
|
||||
{
|
||||
Some(vec![
|
||||
PaymentRequest::optional(
|
||||
extra_die,
|
||||
"Cancel fortress ability to add an extra die \
|
||||
in the first round of combat",
|
||||
),
|
||||
PaymentRequest::optional(
|
||||
ignore_hit,
|
||||
"Cancel fortress ability to ignore the first hit \
|
||||
in the first round of combat",
|
||||
),
|
||||
])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
},
|
||||
|game, s, c| {
|
||||
game.add_info_log_item(&format!("{} paid for siegecraft: ", s.player_name));
|
||||
let mut paid = false;
|
||||
let mut modifiers: Vec<CombatModifier> = Vec::new();
|
||||
let payment = &s.choice;
|
||||
if !payment[0].is_empty() {
|
||||
modifiers.push(CancelFortressExtraDie);
|
||||
game.add_to_last_log_item(&format!(
|
||||
"{} to cancel the fortress ability to add an extra die",
|
||||
payment[0]
|
||||
));
|
||||
paid = true;
|
||||
}
|
||||
if !payment[1].is_empty() {
|
||||
modifiers.push(CancelFortressIgnoreHit);
|
||||
if paid {
|
||||
game.add_to_last_log_item(" and ");
|
||||
}
|
||||
},
|
||||
|game, s, c| {
|
||||
game.add_info_log_item(
|
||||
&format!("{} paid for siegecraft: ", s.player_name));
|
||||
let mut paid = false;
|
||||
let mut modifiers: Vec<CombatModifier> = Vec::new();
|
||||
let payment = &s.choice;
|
||||
if !payment[0].is_empty() {
|
||||
modifiers.push(CancelFortressExtraDie);
|
||||
game.add_to_last_log_item(&format!("{} to cancel the fortress ability to add an extra die", payment[0]));
|
||||
paid = true;
|
||||
}
|
||||
if !payment[1].is_empty() {
|
||||
modifiers.push(CancelFortressIgnoreHit);
|
||||
if paid {
|
||||
game.add_to_last_log_item(" and ");
|
||||
}
|
||||
game.add_to_last_log_item(&format!("{} to cancel the fortress ability to ignore a hit", payment[1]));
|
||||
paid = true;
|
||||
}
|
||||
if !paid {
|
||||
game.add_to_last_log_item("nothing");
|
||||
}
|
||||
c.modifiers.extend(modifiers);
|
||||
},
|
||||
)
|
||||
game.add_to_last_log_item(&format!(
|
||||
"{} to cancel the fortress ability to ignore a hit",
|
||||
payment[1]
|
||||
));
|
||||
paid = true;
|
||||
}
|
||||
if !paid {
|
||||
game.add_to_last_log_item("nothing");
|
||||
}
|
||||
c.modifiers.extend(modifiers);
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
fn steel_weapons() -> AdvanceBuilder {
|
||||
|
|
@ -123,11 +139,7 @@ fn steel_weapons() -> AdvanceBuilder {
|
|||
}
|
||||
|
||||
if player.can_afford(&cost) {
|
||||
Some(vec![PaymentRequest {
|
||||
cost,
|
||||
name: "Use steel weapons".to_string(),
|
||||
optional: true,
|
||||
}])
|
||||
Some(vec![PaymentRequest::optional(cost, "Use steel weapons")])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
|
|
@ -198,7 +210,12 @@ fn steel_weapons_cost(game: &Game, combat: &Combat, player_index: usize) -> Paym
|
|||
let both_steel_weapons =
|
||||
attacker.has_advance(Advance::SteelWeapons) && defender.has_advance(Advance::SteelWeapons);
|
||||
let cost = u8::from(!player.has_advance(Advance::Metallurgy) || both_steel_weapons);
|
||||
PaymentOptions::sum(cost, &[ResourceType::Ore, ResourceType::Gold])
|
||||
PaymentOptions::sum(
|
||||
player,
|
||||
PaymentReason::AdvanceAbility,
|
||||
cost,
|
||||
&[ResourceType::Ore, ResourceType::Gold],
|
||||
)
|
||||
}
|
||||
|
||||
fn fortress(game: &Game, c: &Combat, s: &mut CombatStrength, role: CombatRole) {
|
||||
|
|
|
|||
|
|
@ -95,7 +95,7 @@ impl CustomActionType {
|
|||
pub fn is_available_city(&self, player: &Player, city: &City) -> bool {
|
||||
match self {
|
||||
CustomActionType::Sports => {
|
||||
sports_options(city).is_some_and(|c| c.can_afford(&player.resources))
|
||||
sports_options(player, city).is_some_and(|c| c.can_afford(&player.resources))
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,5 +1,6 @@
|
|||
use crate::content::incidents::great_diplomat::{DIPLOMAT_ID, DiplomaticRelations, Negotiations};
|
||||
use crate::events::EventOrigin;
|
||||
use crate::wonder::Wonder;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
|
||||
|
|
@ -24,7 +25,7 @@ pub enum CollectEffect {
|
|||
pub enum PermanentEffect {
|
||||
Pestilence,
|
||||
LoseAction(usize),
|
||||
PublicWonderCard(String),
|
||||
PublicWonderCard(Wonder),
|
||||
TrojanHorse,
|
||||
SolarEclipse,
|
||||
Anarchy(Anarchy),
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use crate::game::Game;
|
|||
use crate::incident::{
|
||||
DecreaseMood, Incident, IncidentBaseEffect, IncidentBuilder, MoodModifier, decrease_mod_and_log,
|
||||
};
|
||||
use crate::payment::{PaymentConversion, PaymentConversionType, PaymentOptions};
|
||||
use crate::payment::{PaymentConversion, PaymentConversionType, PaymentOptions, PaymentReason};
|
||||
use crate::player::Player;
|
||||
use crate::player_events::IncidentTarget;
|
||||
use crate::position::Position;
|
||||
|
|
@ -222,7 +222,7 @@ fn uprising() -> Incident {
|
|||
0,
|
||||
|game, player_index, _incident| {
|
||||
let player = game.player(player_index);
|
||||
let mut cost = PaymentOptions::tokens(4);
|
||||
let mut cost = PaymentOptions::tokens(player, PaymentReason::Incident, 4);
|
||||
cost.conversions.push(PaymentConversion::new(
|
||||
vec![
|
||||
ResourcePile::mood_tokens(1),
|
||||
|
|
@ -231,11 +231,12 @@ fn uprising() -> Incident {
|
|||
ResourcePile::empty(),
|
||||
PaymentConversionType::MayOverpay(3),
|
||||
));
|
||||
player.can_afford(&cost).then_some(vec![PaymentRequest::new(
|
||||
cost,
|
||||
"Pay 1-4 mood or culture tokens",
|
||||
false,
|
||||
)])
|
||||
player
|
||||
.can_afford(&cost)
|
||||
.then_some(vec![PaymentRequest::mandatory(
|
||||
cost,
|
||||
"Pay 1-4 mood or culture tokens",
|
||||
)])
|
||||
},
|
||||
|game, s, _| {
|
||||
let player = game.player_mut(s.player_index);
|
||||
|
|
@ -273,7 +274,10 @@ fn envoy() -> Incident {
|
|||
.gain_resources(ResourcePile::culture_tokens(1) + ResourcePile::ideas(1));
|
||||
|
||||
if let Some(wonder) = draw_wonder_from_pile(game) {
|
||||
game.add_info_log_item(&format!("{wonder} is now available to be taken by anyone"));
|
||||
game.add_info_log_item(&format!(
|
||||
"{} is now available to be taken by anyone",
|
||||
wonder.name(game)
|
||||
));
|
||||
game.permanent_effects
|
||||
.push(PermanentEffect::PublicWonderCard(wonder));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
use crate::ability_initializer::SelectedChoice;
|
||||
use crate::city::{City, MoodState};
|
||||
use crate::city_pieces::{Building, remove_building};
|
||||
use crate::consts::WONDER_VICTORY_POINTS;
|
||||
use crate::content::persistent_events::{
|
||||
PositionRequest, SelectedStructure, Structure, StructuresRequest, is_selected_structures_valid,
|
||||
};
|
||||
|
|
@ -9,6 +8,7 @@ use crate::game::Game;
|
|||
use crate::incident::{DecreaseMood, Incident, IncidentBaseEffect, MoodModifier};
|
||||
use crate::player_events::{IncidentInfo, IncidentTarget};
|
||||
use crate::position::Position;
|
||||
use crate::wonder::Wonder;
|
||||
use itertools::Itertools;
|
||||
|
||||
pub(crate) fn earthquake_incidents() -> Vec<Incident> {
|
||||
|
|
@ -56,12 +56,12 @@ fn volcano() -> Incident {
|
|||
));
|
||||
let city = game.player(player_index).get_city(pos);
|
||||
let buildings = city.pieces.buildings(None);
|
||||
let wonders = city.pieces.wonders.iter().cloned().collect_vec();
|
||||
let wonders = city.pieces.wonders.iter().copied().collect_vec();
|
||||
for b in buildings {
|
||||
destroy_building(game, b, pos);
|
||||
}
|
||||
for wonder in wonders {
|
||||
destroy_wonder(game, pos, &wonder);
|
||||
destroy_wonder(game, pos, wonder);
|
||||
}
|
||||
destroy_city_center(game, pos);
|
||||
},
|
||||
|
|
@ -126,7 +126,7 @@ fn apply_earthquake(
|
|||
let position = st.position;
|
||||
match st.structure {
|
||||
Structure::Building(b) => destroy_building(game, b, position),
|
||||
Structure::Wonder(name) => destroy_wonder(game, position, &name),
|
||||
Structure::Wonder(name) => destroy_wonder(game, position, name),
|
||||
Structure::CityCenter => destroy_city_center(game, position),
|
||||
}
|
||||
}
|
||||
|
|
@ -158,7 +158,7 @@ fn destroyable_structures(city: &City) -> Vec<SelectedStructure> {
|
|||
let w = pieces
|
||||
.wonders
|
||||
.iter()
|
||||
.map(|w| SelectedStructure::new(city.position, Structure::Wonder(w.clone())))
|
||||
.map(|w| SelectedStructure::new(city.position, Structure::Wonder(*w)))
|
||||
.collect_vec();
|
||||
let b = pieces
|
||||
.buildings(None)
|
||||
|
|
@ -206,21 +206,22 @@ fn destroy_building(game: &mut Game, b: Building, position: Position) {
|
|||
));
|
||||
}
|
||||
|
||||
fn destroy_wonder(game: &mut Game, position: Position, name: &str) {
|
||||
fn destroy_wonder(game: &mut Game, position: Position, name: Wonder) {
|
||||
let owner = game.get_any_city(position).player_index;
|
||||
let wonder = game.cache.get_wonder(name);
|
||||
wonder.listeners.clone().deinit(game, owner);
|
||||
|
||||
let a = WONDER_VICTORY_POINTS / 2.0;
|
||||
let a = name.info(game).owned_victory_points;
|
||||
let p = game.player_mut(owner);
|
||||
p.wonders_owned.remove(name);
|
||||
let city = p.get_city_mut(position);
|
||||
city.pieces.wonders.retain(|w| w != name);
|
||||
p.event_victory_points += a;
|
||||
city.pieces.wonders.retain(|w| *w != name);
|
||||
p.event_victory_points += a as f32;
|
||||
game.add_info_log_item(&format!(
|
||||
"{} gained {} points for the {} at {}",
|
||||
game.player_name(owner),
|
||||
a,
|
||||
name,
|
||||
name.name(game),
|
||||
position
|
||||
));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::content::persistent_events::{PositionRequest, ResourceRewardRequest};
|
||||
use crate::incident::{Incident, IncidentBaseEffect, IncidentBuilder};
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::ResourceReward;
|
||||
use crate::player::add_unit;
|
||||
use crate::player_events::IncidentTarget;
|
||||
use crate::resource::ResourceType;
|
||||
|
|
@ -139,7 +139,7 @@ fn good_year(mut builder: IncidentBuilder, amount: u8, good_year_type: &GoodYear
|
|||
10,
|
||||
move |_game, _player_index, _incident| {
|
||||
Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::sum(amount, &[ResourceType::Food]),
|
||||
ResourceReward::sum(amount, &[ResourceType::Food]),
|
||||
"-".to_string(),
|
||||
))
|
||||
},
|
||||
|
|
@ -256,7 +256,7 @@ pub(crate) fn successful_year() -> Incident {
|
|||
let max_cities = player_to_city_num.iter().max().unwrap_or(&0);
|
||||
if min_cities == max_cities {
|
||||
return Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::sum(1, &[ResourceType::Food]),
|
||||
ResourceReward::sum(1, &[ResourceType::Food]),
|
||||
"-".to_string(),
|
||||
));
|
||||
}
|
||||
|
|
@ -264,7 +264,7 @@ pub(crate) fn successful_year() -> Incident {
|
|||
let cities = game.players[player_index].cities.len();
|
||||
if cities == *min_cities {
|
||||
Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::sum((max_cities - min_cities) as u8, &[ResourceType::Food]),
|
||||
ResourceReward::sum((max_cities - min_cities) as u8, &[ResourceType::Food]),
|
||||
"-".to_string(),
|
||||
))
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ use crate::player::Player;
|
|||
use crate::playing_actions::{ActionCost, PlayingActionType};
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::utils::remove_element_by;
|
||||
use crate::wonder::{WonderCardInfo, WonderDiscount, cities_for_wonder, on_play_wonder_card};
|
||||
use crate::wonder::{
|
||||
Wonder, WonderCardInfo, WonderDiscount, cities_for_wonder, on_play_wonder_card,
|
||||
};
|
||||
|
||||
pub(crate) fn great_engineer() -> ActionCard {
|
||||
let groups = &["Construction"];
|
||||
|
|
@ -122,7 +124,7 @@ pub(crate) fn great_architect() -> ActionCard {
|
|||
Some(HandCardsRequest::new(
|
||||
playable_wonders(game, game.player(player))
|
||||
.iter()
|
||||
.map(|name| HandCard::Wonder(name.clone()))
|
||||
.map(|name| HandCard::Wonder(*name))
|
||||
.collect(),
|
||||
1..=1,
|
||||
"Great Architect: Select a wonder to build",
|
||||
|
|
@ -135,18 +137,18 @@ pub(crate) fn great_architect() -> ActionCard {
|
|||
on_play_wonder_card(
|
||||
game,
|
||||
s.player_index,
|
||||
WonderCardInfo::new(name.clone(), ARCHITECT_DISCOUNT),
|
||||
WonderCardInfo::new(*name, ARCHITECT_DISCOUNT),
|
||||
);
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn playable_wonders(game: &Game, player: &Player) -> Vec<String> {
|
||||
fn playable_wonders(game: &Game, player: &Player) -> Vec<Wonder> {
|
||||
player
|
||||
.wonder_cards
|
||||
.iter()
|
||||
.filter(|name| !cities_for_wonder(name, game, player, &ARCHITECT_DISCOUNT).is_empty())
|
||||
.cloned()
|
||||
.filter(|name| !cities_for_wonder(**name, game, player, &ARCHITECT_DISCOUNT).is_empty())
|
||||
.copied()
|
||||
.collect()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,8 @@ 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::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::Player;
|
||||
use crate::playing_actions::ActionCost;
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
|
|
@ -64,12 +65,11 @@ pub(crate) fn great_explorer() -> ActionCard {
|
|||
.add_payment_request_listener(
|
||||
|e| &mut e.play_action_card,
|
||||
7,
|
||||
|_game, _player, a| {
|
||||
|game, player, a| {
|
||||
a.selected_position?;
|
||||
Some(vec![PaymentRequest::new(
|
||||
city_cost(),
|
||||
Some(vec![PaymentRequest::mandatory(
|
||||
city_cost(game.player(player)),
|
||||
"Pay to build the city",
|
||||
false,
|
||||
)])
|
||||
},
|
||||
|game, s, a| {
|
||||
|
|
@ -113,7 +113,8 @@ fn place_city_request(
|
|||
player_index: usize,
|
||||
positions: Vec<Position>,
|
||||
) -> PositionRequest {
|
||||
if !game.player(player_index).can_afford(&city_cost()) {
|
||||
let p = game.player(player_index);
|
||||
if !p.can_afford(&city_cost(p)) {
|
||||
game.add_info_log_item("Player cannot afford to build a city");
|
||||
}
|
||||
|
||||
|
|
@ -125,8 +126,8 @@ fn place_city_request(
|
|||
PositionRequest::new(choices, 0..=1, "Place a city for 2 food")
|
||||
}
|
||||
|
||||
fn city_cost() -> PaymentOptions {
|
||||
PaymentOptions::resources(ResourcePile::food(2))
|
||||
fn city_cost(player: &Player) -> PaymentOptions {
|
||||
PaymentOptions::resources(player, PaymentReason::ActionCard, ResourcePile::food(2))
|
||||
}
|
||||
|
||||
pub(crate) fn action_explore_request(game: &Game, player_index: usize) -> PositionRequest {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::content::incidents::great_warlord::great_warlord;
|
|||
use crate::content::persistent_events::{AdvanceRequest, PaymentRequest, PositionRequest};
|
||||
use crate::game::Game;
|
||||
use crate::incident::{Incident, IncidentBaseEffect, IncidentBuilder};
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::Player;
|
||||
use crate::player_events::IncidentTarget;
|
||||
use crate::playing_actions::ActionCost;
|
||||
|
|
@ -82,13 +82,16 @@ fn incident(
|
|||
} else {
|
||||
2
|
||||
};
|
||||
let options = PaymentOptions::resources(ResourcePile::culture_tokens(cost));
|
||||
let p = game.player(player_index);
|
||||
let options = PaymentOptions::resources(
|
||||
p,
|
||||
PaymentReason::ActionCard,
|
||||
ResourcePile::culture_tokens(cost),
|
||||
);
|
||||
if p.can_afford(&options) {
|
||||
Some(vec![PaymentRequest::new(
|
||||
Some(vec![PaymentRequest::optional(
|
||||
options,
|
||||
"Pay to gain the Action Card",
|
||||
true,
|
||||
)])
|
||||
} else {
|
||||
game.add_info_log_item(&format!(
|
||||
|
|
@ -268,10 +271,9 @@ fn great_prophet() -> ActionCard {
|
|||
0,
|
||||
|game, player, a| {
|
||||
a.selected_position?;
|
||||
Some(vec![PaymentRequest::new(
|
||||
Some(vec![PaymentRequest::optional(
|
||||
temple_cost(game, game.player(player)),
|
||||
"Pay to build the Temple",
|
||||
true,
|
||||
)])
|
||||
},
|
||||
|game, s, a| {
|
||||
|
|
@ -455,18 +457,21 @@ fn great_athlete() -> ActionCard {
|
|||
};
|
||||
let options = if culture_to_mood {
|
||||
PaymentOptions::single_type(
|
||||
p,
|
||||
PaymentReason::ActionCard,
|
||||
ResourceType::CultureTokens,
|
||||
0..=p.resources.culture_tokens,
|
||||
)
|
||||
} else {
|
||||
PaymentOptions::single_type(ResourceType::MoodTokens, 0..=p.resources.mood_tokens)
|
||||
PaymentOptions::single_type(
|
||||
p,
|
||||
PaymentReason::ActionCard,
|
||||
ResourceType::MoodTokens,
|
||||
0..=p.resources.mood_tokens,
|
||||
)
|
||||
};
|
||||
|
||||
Some(vec![PaymentRequest::new(
|
||||
options,
|
||||
"Convert resources",
|
||||
true,
|
||||
)])
|
||||
Some(vec![PaymentRequest::optional(options, "Convert resources")])
|
||||
},
|
||||
|game, s, _| {
|
||||
let from = &s.choice[0];
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use crate::game::Game;
|
|||
use crate::incident::{DecreaseMood, Incident, IncidentBaseEffect, MoodModifier};
|
||||
use crate::map::{Map, Terrain};
|
||||
use crate::objective_card::discard_objective_card;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::Player;
|
||||
use crate::player_events::{IncidentInfo, IncidentTarget};
|
||||
use crate::position::Position;
|
||||
|
|
@ -103,10 +103,14 @@ fn pandemics() -> Incident {
|
|||
return None;
|
||||
}
|
||||
|
||||
Some(vec![PaymentRequest::new(
|
||||
PaymentOptions::sum(needed, &ResourceType::all()),
|
||||
Some(vec![PaymentRequest::mandatory(
|
||||
PaymentOptions::sum(
|
||||
player,
|
||||
PaymentReason::Incident,
|
||||
needed,
|
||||
&ResourceType::all(),
|
||||
),
|
||||
"Select resources to lose",
|
||||
false,
|
||||
)])
|
||||
},
|
||||
|game, s, _| {
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::city_pieces::Building;
|
|||
use crate::content::persistent_events::{PositionRequest, ResourceRewardRequest};
|
||||
use crate::game::Game;
|
||||
use crate::incident::{Incident, IncidentBaseEffect, PassedIncident};
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::ResourceReward;
|
||||
use crate::player::Player;
|
||||
use crate::player_events::IncidentTarget;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
|
|
@ -107,7 +107,7 @@ fn era_of_stability() -> Incident {
|
|||
tokens = tokens.max(1);
|
||||
}
|
||||
Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::tokens(tokens as u8),
|
||||
ResourceReward::tokens(tokens as u8),
|
||||
"Select token to gain".to_string(),
|
||||
))
|
||||
},
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::content::effects::{Anarchy, PermanentEffect};
|
|||
use crate::content::persistent_events::PaymentRequest;
|
||||
use crate::game::Game;
|
||||
use crate::incident::{Incident, IncidentBaseEffect};
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player_events::IncidentTarget;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::utils::remove_and_map_element_by;
|
||||
|
|
@ -32,10 +32,6 @@ fn trojan_horse() -> Incident {
|
|||
.build()
|
||||
}
|
||||
|
||||
fn trojan_cost() -> PaymentOptions {
|
||||
PaymentOptions::resources(ResourcePile::wood(1) + ResourcePile::culture_tokens(1))
|
||||
}
|
||||
|
||||
pub(crate) fn decide_trojan_horse() -> Builtin {
|
||||
Builtin::builder("Trojan Horse", TROJAN_DESCRIPTION)
|
||||
.add_payment_request_listener(
|
||||
|
|
@ -45,7 +41,14 @@ pub(crate) fn decide_trojan_horse() -> Builtin {
|
|||
if is_land_battle_against_defended_city(game, player_index, c) {
|
||||
game.permanent_effects.iter().find_map(|e| {
|
||||
matches!(e, PermanentEffect::TrojanHorse).then_some(vec![
|
||||
PaymentRequest::new(trojan_cost(), "Activate the Trojan Horse?", true),
|
||||
PaymentRequest::optional(
|
||||
PaymentOptions::resources(
|
||||
game.player(player_index),
|
||||
PaymentReason::AdvanceAbility,
|
||||
ResourcePile::wood(1) + ResourcePile::culture_tokens(1),
|
||||
),
|
||||
"Activate the Trojan Horse?",
|
||||
),
|
||||
])
|
||||
})
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ use crate::explore::ExploreResolutionState;
|
|||
use crate::game::Game;
|
||||
use crate::map::Rotation;
|
||||
use crate::objective_card::SelectObjectivesInfo;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, ResourceReward};
|
||||
use crate::player::Player;
|
||||
use crate::player_events::{IncidentInfo, OnAdvanceInfo};
|
||||
use crate::playing_actions::Recruit;
|
||||
|
|
@ -22,7 +22,7 @@ use crate::position::Position;
|
|||
use crate::resource_pile::ResourcePile;
|
||||
use crate::status_phase::{ChangeGovernmentType, StatusPhaseState};
|
||||
use crate::unit::UnitType;
|
||||
use crate::wonder::WonderCardInfo;
|
||||
use crate::wonder::{Wonder, WonderCardInfo};
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::ops::RangeInclusive;
|
||||
|
|
@ -169,24 +169,34 @@ pub struct PaymentRequest {
|
|||
|
||||
impl PaymentRequest {
|
||||
#[must_use]
|
||||
pub fn new(cost: PaymentOptions, name: &str, optional: bool) -> Self {
|
||||
fn new(cost: PaymentOptions, name: &str, optional: bool) -> Self {
|
||||
Self {
|
||||
cost,
|
||||
name: name.to_string(),
|
||||
optional,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn mandatory(cost: PaymentOptions, name: &str) -> Self {
|
||||
Self::new(cost, name, false)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn optional(cost: PaymentOptions, name: &str) -> Self {
|
||||
Self::new(cost, name, true)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct ResourceRewardRequest {
|
||||
pub reward: PaymentOptions,
|
||||
pub reward: ResourceReward,
|
||||
pub name: String,
|
||||
}
|
||||
|
||||
impl ResourceRewardRequest {
|
||||
#[must_use]
|
||||
pub fn new(reward: PaymentOptions, name: String) -> Self {
|
||||
pub fn new(reward: ResourceReward, name: String) -> Self {
|
||||
Self { reward, name }
|
||||
}
|
||||
}
|
||||
|
|
@ -288,7 +298,7 @@ impl UnitsRequest {
|
|||
pub enum Structure {
|
||||
CityCenter,
|
||||
Building(Building),
|
||||
Wonder(String),
|
||||
Wonder(Wonder),
|
||||
}
|
||||
|
||||
impl Structure {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::combat::{Combat, update_combat_strength};
|
|||
use crate::combat_listeners::{CombatResult, CombatRoundStart, CombatStrength, kill_combat_units};
|
||||
use crate::content::persistent_events::{PaymentRequest, PositionRequest, UnitsRequest};
|
||||
use crate::game::Game;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::tactics_card::{
|
||||
|
|
@ -54,8 +54,8 @@ pub(crate) fn encircled(id: u8) -> TacticsCard {
|
|||
let role = combat.role(player);
|
||||
let opponent_role = combat.role(opponent);
|
||||
|
||||
let player_losses = e.casualties(role).fighters;
|
||||
let opponent_losses = e.casualties(opponent_role).fighters;
|
||||
let player_losses = e.losses(role);
|
||||
let opponent_losses = e.losses(opponent_role);
|
||||
if opponent_losses >= player_losses {
|
||||
if opponent_losses == combat.fighting_units(game, opponent).len() as u8 {
|
||||
game.add_info_log_item("Encircled cannot do damage - all units already die");
|
||||
|
|
@ -67,8 +67,8 @@ pub(crate) fn encircled(id: u8) -> TacticsCard {
|
|||
game.add_info_log_item(
|
||||
"Encircled rolled a 5 or 6 and added a hit that cannot be ignored",
|
||||
);
|
||||
e.casualties_mut(opponent_role).fighters += 1;
|
||||
e.set_final_result(game);
|
||||
e.hits_mut(role).extra_hits += 1;
|
||||
e.set_final_result();
|
||||
} else {
|
||||
game.add_info_log_item("Encircled rolled no 5 or 6");
|
||||
}
|
||||
|
|
@ -155,8 +155,7 @@ pub(crate) fn surprise(id: u8) -> TacticsCard {
|
|||
.push("Surprise added 1 to combat value".to_string());
|
||||
})
|
||||
.add_resolve_listener(1, |player, game, e| {
|
||||
let c = &e.combat;
|
||||
if e.casualties(c.role(c.opponent(player))).fighters > 0 {
|
||||
if e.hits(e.role(player)) > 0 {
|
||||
game.add_info_log_item(&format!(
|
||||
"{} draws 1 action card for Surprise tactics",
|
||||
game.player_name(player)
|
||||
|
|
@ -184,17 +183,21 @@ pub(crate) fn siege(id: u8) -> TacticsCard {
|
|||
.add_payment_request_listener(
|
||||
|event| &mut event.combat_round_start_tactics,
|
||||
0,
|
||||
move |game, p, s| {
|
||||
if s.is_active(p, id, TacticsCardTarget::Opponent) {
|
||||
let cost = PaymentOptions::resources(ResourcePile::food(2));
|
||||
if game.player(p).can_afford(&cost) {
|
||||
return Some(vec![PaymentRequest::new(
|
||||
move |game, player, s| {
|
||||
if s.is_active(player, id, TacticsCardTarget::Opponent) {
|
||||
let p = game.player(player);
|
||||
let cost = PaymentOptions::resources(
|
||||
p,
|
||||
PaymentReason::AdvanceAbility,
|
||||
ResourcePile::food(2),
|
||||
);
|
||||
if p.can_afford(&cost) {
|
||||
return Some(vec![PaymentRequest::optional(
|
||||
cost,
|
||||
"Pay 2 food to use combat abilities this round",
|
||||
true,
|
||||
)]);
|
||||
}
|
||||
apply_siege(game, s, p);
|
||||
apply_siege(game, s, player);
|
||||
}
|
||||
None
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,41 +1,112 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::advance::Advance;
|
||||
use crate::content::persistent_events::PaymentRequest;
|
||||
use crate::map::Terrain::Fertile;
|
||||
use crate::payment::{PaymentConversionType, PaymentOptions};
|
||||
use crate::{resource_pile::ResourcePile, wonder::Wonder};
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::wonder::Wonder;
|
||||
use crate::{resource_pile::ResourcePile, wonder::WonderInfo};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[must_use]
|
||||
pub fn get_all_uncached() -> Vec<Wonder> {
|
||||
vec![
|
||||
// todo add effects
|
||||
Wonder::builder(
|
||||
"Pyramids",
|
||||
"todo",
|
||||
PaymentOptions::resources_with_discount(ResourcePile::new(3, 3, 3, 0, 0, 0, 4), PaymentConversionType::MayNotOverpay(1)),
|
||||
vec![],
|
||||
)
|
||||
.build(),
|
||||
// add other effects
|
||||
Wonder::builder(
|
||||
"Great Gardens",
|
||||
"The city with this wonder may Collect any type of resource from Grassland spaces including ideas and gold.",
|
||||
PaymentOptions::resources(ResourcePile::new(5, 5, 2, 0, 0, 0, 5)),
|
||||
vec![Advance::Irrigation],
|
||||
)
|
||||
.add_transient_event_listener(
|
||||
|events| &mut events.terrain_collect_options,
|
||||
1,
|
||||
|m,(),()| {
|
||||
m.insert(Fertile, HashSet::from([
|
||||
ResourcePile::food(1),
|
||||
ResourcePile::wood(1),
|
||||
ResourcePile::ore(1),
|
||||
ResourcePile::ideas(1),
|
||||
ResourcePile::gold(1),
|
||||
]));
|
||||
}
|
||||
)
|
||||
.build(),
|
||||
]
|
||||
pub fn get_all_uncached() -> Vec<WonderInfo> {
|
||||
vec![colosseum(), pyramids(), great_gardens()]
|
||||
}
|
||||
|
||||
fn great_gardens() -> WonderInfo {
|
||||
WonderInfo::builder(
|
||||
Wonder::GreatGardens,
|
||||
"Great Gardens",
|
||||
"The city with this wonder may Collect any type of resource from \
|
||||
Grassland spaces including ideas and gold. \
|
||||
Enemies cannot enter the city if they have entered a Grassland space this turn.",
|
||||
PaymentOptions::fixed_resources(ResourcePile::new(5, 5, 2, 0, 0, 0, 5)),
|
||||
Advance::Irrigation,
|
||||
)
|
||||
.add_transient_event_listener(
|
||||
|events| &mut events.terrain_collect_options,
|
||||
1,
|
||||
|m, (), ()| {
|
||||
m.insert(
|
||||
Fertile,
|
||||
HashSet::from([
|
||||
ResourcePile::food(1),
|
||||
ResourcePile::wood(1),
|
||||
ResourcePile::ore(1),
|
||||
ResourcePile::ideas(1),
|
||||
ResourcePile::gold(1),
|
||||
]),
|
||||
);
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn pyramids() -> WonderInfo {
|
||||
WonderInfo::builder(
|
||||
Wonder::Pyramids,
|
||||
"Pyramids",
|
||||
"Counts as 5.1 victory points (instead of 4). \
|
||||
All victory points are awarded to the player who built the wonder \
|
||||
(owning does not grant any points).",
|
||||
PaymentOptions::fixed_resources(ResourcePile::new(2, 3, 7, 0, 0, 0, 5)),
|
||||
Advance::Rituals,
|
||||
)
|
||||
.built_victory_points(5.1) // because it breaks the tie
|
||||
.owned_victory_points(0)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn colosseum() -> WonderInfo {
|
||||
WonderInfo::builder(
|
||||
Wonder::Colosseum,
|
||||
"Colosseum",
|
||||
"May pay culture tokens with mood tokens (or vice versa) - \
|
||||
except for the building wonders.\
|
||||
May increase the combat value in a land battle by 1 for 1 culture or mood token.",
|
||||
PaymentOptions::fixed_resources(ResourcePile::new(3, 4, 5, 0, 0, 0, 5)),
|
||||
Advance::Sports,
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.combat_round_end,
|
||||
90,
|
||||
|game, player_index, e| {
|
||||
let player = &game.player(player_index);
|
||||
|
||||
let cost = PaymentOptions::tokens(player, PaymentReason::WonderAbility, 1);
|
||||
|
||||
if !player.can_afford(&cost) {
|
||||
return None;
|
||||
}
|
||||
|
||||
let h = e.hits_mut(e.role(player_index));
|
||||
let mut with_increase = h.clone();
|
||||
with_increase.combat_value += 1;
|
||||
if h.hits() == with_increase.hits() {
|
||||
game.add_info_log_item(&format!(
|
||||
"Combat value is already at maximum, cannot increase combat value for {}",
|
||||
game.player_name(player_index)
|
||||
));
|
||||
return None;
|
||||
}
|
||||
|
||||
Some(vec![PaymentRequest::optional(
|
||||
cost,
|
||||
"Add 1 to the combat value?",
|
||||
)])
|
||||
},
|
||||
|game, s, e| {
|
||||
let pile = &s.choice[0];
|
||||
let name = &s.player_name;
|
||||
if pile.is_empty() {
|
||||
game.add_info_log_item(&format!("{name} declined to pay for the combat value",));
|
||||
} else {
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} paid {pile} to increase the combat value by 1, scoring an extra hit",
|
||||
));
|
||||
e.hits_mut(e.role(s.player_index)).combat_value += 1;
|
||||
e.set_final_result();
|
||||
}
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use crate::content::persistent_events::{
|
|||
};
|
||||
use crate::game::Game;
|
||||
use crate::log::current_player_turn_log;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player_events::ActionInfo;
|
||||
use crate::playing_actions::{
|
||||
PlayingAction, PlayingActionType, base_or_custom_available, remaining_resources_for_action,
|
||||
|
|
@ -47,6 +47,7 @@ pub struct InfluenceCultureInfo {
|
|||
pub roll_boost: u8,
|
||||
pub position: Position,
|
||||
pub starting_city_position: Position,
|
||||
pub barbarian_takeover_check: bool,
|
||||
}
|
||||
|
||||
impl InfluenceCultureInfo {
|
||||
|
|
@ -57,6 +58,7 @@ impl InfluenceCultureInfo {
|
|||
position: Position,
|
||||
structure: Structure,
|
||||
starting_city_position: Position,
|
||||
barbarian_takeover_check: bool,
|
||||
) -> InfluenceCultureInfo {
|
||||
InfluenceCultureInfo {
|
||||
prevent_boost: false,
|
||||
|
|
@ -67,6 +69,7 @@ impl InfluenceCultureInfo {
|
|||
is_defender: false,
|
||||
position,
|
||||
starting_city_position,
|
||||
barbarian_takeover_check,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -99,11 +102,11 @@ pub(crate) fn influence_culture_attempt(
|
|||
c: &SelectedStructure,
|
||||
) -> Result<(), String> {
|
||||
let target_city_position = c.position;
|
||||
let info = influence_culture_boost_cost(game, player_index, c, None)?;
|
||||
let info = influence_culture_boost_cost(game, player_index, c, None, false)?;
|
||||
let self_influence = info.starting_city_position == target_city_position;
|
||||
|
||||
// currently, there is no way to have different costs for this
|
||||
game.players[player_index].lose_resources(info.range_boost_cost.default.clone());
|
||||
game.players[player_index].lose_resources(info.range_boost_cost.default.clone()); // todo colosseum
|
||||
let roll = game.next_dice_roll().value + info.roll_boost;
|
||||
let success = roll >= 5;
|
||||
if success {
|
||||
|
|
@ -119,8 +122,12 @@ pub(crate) fn influence_culture_attempt(
|
|||
attempt_failed(game, player_index, target_city_position);
|
||||
return Ok(());
|
||||
}
|
||||
if let Some(roll_boost_cost) = PaymentOptions::resources(roll_boost_cost(roll))
|
||||
.first_valid_payment(&game.players[player_index].resources)
|
||||
if let Some(roll_boost_cost) = PaymentOptions::resources(
|
||||
game.player(player_index),
|
||||
PaymentReason::InfluenceCulture,
|
||||
roll_boost_cost(roll),
|
||||
)
|
||||
.first_valid_payment(&game.players[player_index].resources)
|
||||
{
|
||||
game.add_to_last_log_item(&format!(" and rolled a {roll}"));
|
||||
info.info.execute(game);
|
||||
|
|
@ -157,11 +164,14 @@ pub(crate) fn cultural_influence_resolution() -> Builtin {
|
|||
.add_payment_request_listener(
|
||||
|e| &mut e.influence_culture_resolution,
|
||||
0,
|
||||
|_game, _player_index, cost| {
|
||||
Some(vec![PaymentRequest::new(
|
||||
PaymentOptions::resources(cost.clone()),
|
||||
|game, player_index, cost| {
|
||||
Some(vec![PaymentRequest::optional(
|
||||
PaymentOptions::resources(
|
||||
game.player(player_index),
|
||||
PaymentReason::InfluenceCulture,
|
||||
cost.clone(),
|
||||
),
|
||||
&format!("Pay {cost} to increase the dice roll"),
|
||||
true,
|
||||
)])
|
||||
},
|
||||
|game, s, _| {
|
||||
|
|
@ -233,6 +243,7 @@ pub fn influence_culture_boost_cost(
|
|||
player_index: usize,
|
||||
selected: &SelectedStructure,
|
||||
action_type: Option<&PlayingActionType>,
|
||||
barbarian_takeover_check: bool,
|
||||
) -> Result<InfluenceCultureInfo, String> {
|
||||
let target_city_position = selected.position;
|
||||
let structure = &selected.structure;
|
||||
|
|
@ -266,11 +277,16 @@ pub fn influence_culture_boost_cost(
|
|||
let (start, range_boost) = affordable_start_city(game, player_index, target_city, action_type)?;
|
||||
|
||||
let mut info = Ok(InfluenceCultureInfo::new(
|
||||
PaymentOptions::resources(ResourcePile::culture_tokens(range_boost)),
|
||||
PaymentOptions::resources(
|
||||
attacker,
|
||||
PaymentReason::InfluenceCulture,
|
||||
ResourcePile::culture_tokens(range_boost),
|
||||
),
|
||||
ActionInfo::new(attacker),
|
||||
target_city_position,
|
||||
structure.clone(),
|
||||
start,
|
||||
barbarian_takeover_check,
|
||||
));
|
||||
attacker.trigger_event(
|
||||
|e| &e.on_influence_culture_attempt,
|
||||
|
|
@ -313,8 +329,13 @@ pub fn available_influence_culture(
|
|||
structures(city)
|
||||
.into_iter()
|
||||
.map(|s| {
|
||||
let result =
|
||||
influence_culture_boost_cost(game, player, &s, Some(action_type));
|
||||
let result = influence_culture_boost_cost(
|
||||
game,
|
||||
player,
|
||||
&s,
|
||||
Some(action_type),
|
||||
false,
|
||||
);
|
||||
(s, result)
|
||||
})
|
||||
.collect_vec()
|
||||
|
|
@ -398,6 +419,7 @@ fn affordable_start_city(
|
|||
.position
|
||||
.distance(target_city.position)
|
||||
.saturating_sub(c.size() as u32) as u8;
|
||||
// todo also mood with colosseum
|
||||
if min_cost > available.culture_tokens {
|
||||
// avoid unnecessary calculations
|
||||
return None;
|
||||
|
|
@ -425,7 +447,7 @@ pub(crate) fn format_cultural_influence_attempt_log_item(
|
|||
let target_city_position = s.position;
|
||||
let target_city = game.get_any_city(target_city_position);
|
||||
let target_player_index = target_city.player_index;
|
||||
let info = influence_culture_boost_cost(game, player_index, s, Some(&i.action_type))
|
||||
let info = influence_culture_boost_cost(game, player_index, s, Some(&i.action_type), false)
|
||||
.expect("this should be a valid action");
|
||||
|
||||
let player = if target_player_index == game.active_player() {
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ pub enum EventOrigin {
|
|||
Advance(Advance),
|
||||
SpecialAdvance(Advance),
|
||||
Leader(String),
|
||||
Wonder(String),
|
||||
Wonder(Wonder),
|
||||
Builtin(String),
|
||||
Incident(u8),
|
||||
CivilCard(u8),
|
||||
|
|
@ -17,10 +17,10 @@ impl EventOrigin {
|
|||
#[must_use]
|
||||
pub fn id(&self) -> String {
|
||||
match self {
|
||||
EventOrigin::Advance(name)
|
||||
EventOrigin::Wonder(name) => format!("{name:?}"),
|
||||
| EventOrigin::Advance(name)
|
||||
// can't call to_string, because cache is not constructed
|
||||
| EventOrigin::SpecialAdvance(name) => format!("{name:?}"),
|
||||
| EventOrigin::Wonder(name)
|
||||
| EventOrigin::Leader(name)
|
||||
| EventOrigin::Objective(name)
|
||||
| EventOrigin::Builtin(name) => name.to_string(),
|
||||
|
|
@ -37,8 +37,8 @@ impl EventOrigin {
|
|||
EventOrigin::Advance(name) | EventOrigin::SpecialAdvance(name) => {
|
||||
name.name(game).to_string()
|
||||
}
|
||||
EventOrigin::Wonder(name)
|
||||
| EventOrigin::Leader(name)
|
||||
EventOrigin::Wonder(name) => name.name(game).to_string(),
|
||||
EventOrigin::Leader(name)
|
||||
| EventOrigin::Objective(name)
|
||||
| EventOrigin::Builtin(name) => name.to_string(),
|
||||
EventOrigin::CivilCard(id) => cache.get_civil_card(*id).name.clone(),
|
||||
|
|
@ -51,6 +51,7 @@ impl EventOrigin {
|
|||
use crate::advance::Advance;
|
||||
use crate::game::Game;
|
||||
use crate::player::CostTrigger;
|
||||
use crate::wonder::Wonder;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
|
|
|
|||
|
|
@ -22,6 +22,7 @@ use crate::resource::check_for_waste;
|
|||
use crate::status_phase::enter_status_phase;
|
||||
use crate::utils;
|
||||
use crate::utils::Rng;
|
||||
use crate::wonder::Wonder;
|
||||
use crate::{
|
||||
city::City,
|
||||
content::custom_actions::CustomActionType,
|
||||
|
|
@ -57,7 +58,7 @@ pub struct Game {
|
|||
pub dice_roll_outcomes: Vec<u8>, // for testing
|
||||
pub dice_roll_log: Vec<u8>,
|
||||
pub dropped_players: Vec<usize>,
|
||||
pub wonders_left: Vec<String>,
|
||||
pub wonders_left: Vec<Wonder>,
|
||||
pub action_cards_left: Vec<u8>,
|
||||
pub objective_cards_left: Vec<u8>,
|
||||
pub incidents_left: Vec<u8>,
|
||||
|
|
@ -726,7 +727,7 @@ pub struct GameData {
|
|||
dropped_players: Vec<usize>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
wonders_left: Vec<String>,
|
||||
wonders_left: Vec<Wonder>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
action_cards_left: Vec<u8>,
|
||||
|
|
|
|||
|
|
@ -59,7 +59,7 @@ pub fn setup_game_with_cache(
|
|||
let wonders_left = cache
|
||||
.get_wonders()
|
||||
.iter()
|
||||
.map(|w| w.name.clone())
|
||||
.map(|w| w.wonder)
|
||||
.collect_vec()
|
||||
.shuffled(&mut rng);
|
||||
let action_cards_left = cache
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::city::MoodState;
|
||||
use crate::content::custom_actions::CustomActionType;
|
||||
use crate::game::Game;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::{CostTrigger, Player};
|
||||
use crate::player_events::CostInfo;
|
||||
use crate::playing_actions::{PlayingActionType, base_or_custom_available};
|
||||
|
|
@ -56,6 +56,11 @@ pub fn happiness_cost(
|
|||
city_size_steps: u8, // for each city: size * steps in that city
|
||||
execute: CostTrigger,
|
||||
) -> CostInfo {
|
||||
let payment_options = PaymentOptions::sum(city_size_steps, &[ResourceType::MoodTokens]);
|
||||
let payment_options = PaymentOptions::sum(
|
||||
p,
|
||||
PaymentReason::IncreaseHappiness,
|
||||
city_size_steps,
|
||||
&[ResourceType::MoodTokens],
|
||||
);
|
||||
p.trigger_cost_event(|e| &e.happiness_cost, &payment_options, &(), &(), execute)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -13,7 +13,9 @@ use crate::content::persistent_events::{
|
|||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
use crate::map::Terrain;
|
||||
use crate::payment::{PaymentConversion, PaymentConversionType, PaymentOptions};
|
||||
use crate::payment::{
|
||||
PaymentConversion, PaymentConversionType, PaymentOptions, PaymentReason, ResourceReward,
|
||||
};
|
||||
use crate::pirates::pirates_spawn_and_raid;
|
||||
use crate::player::Player;
|
||||
use crate::player_events::{IncidentInfo, IncidentPlayerInfo, IncidentTarget};
|
||||
|
|
@ -508,7 +510,12 @@ impl IncidentBuilder {
|
|||
if needed == 0 {
|
||||
return None;
|
||||
}
|
||||
let mut options = PaymentOptions::sum(needed, &[ResourceType::MoodTokens]);
|
||||
let mut options = PaymentOptions::sum(
|
||||
p,
|
||||
PaymentReason::Incident,
|
||||
needed,
|
||||
&[ResourceType::MoodTokens],
|
||||
);
|
||||
options.conversions.push(PaymentConversion::new(
|
||||
vec![ResourcePile::mood_tokens(1)],
|
||||
ResourcePile::empty(),
|
||||
|
|
@ -520,10 +527,10 @@ impl IncidentBuilder {
|
|||
MoodModifier::MakeAngry => "making it Angry",
|
||||
};
|
||||
|
||||
Some(vec![PaymentRequest::new(
|
||||
// mandatory - but may be 0
|
||||
Some(vec![PaymentRequest::mandatory(
|
||||
options,
|
||||
&format!("You may pay 1 mood token for each city to avoid {action}"),
|
||||
false,
|
||||
)])
|
||||
} else {
|
||||
None
|
||||
|
|
@ -719,7 +726,7 @@ fn gold_deposits(b: IncidentBuilder) -> IncidentBuilder {
|
|||
BASE_EFFECT_PRIORITY,
|
||||
|_game, _player_index, _incident| {
|
||||
Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::sum(2, &[ResourceType::Gold]),
|
||||
ResourceReward::sum(2, &[ResourceType::Gold]),
|
||||
"-".to_string(),
|
||||
))
|
||||
},
|
||||
|
|
|
|||
|
|
@ -6,6 +6,7 @@ use super::collect::PositionCollection;
|
|||
use crate::combat_stats::CombatStats;
|
||||
use crate::movement::{MoveUnits, MovementAction};
|
||||
use crate::playing_actions::{Collect, IncreaseHappiness, PlayingActionType, Recruit};
|
||||
use crate::wonder::Wonder;
|
||||
use crate::{
|
||||
action::Action, game::Game, playing_actions::PlayingAction, position::Position,
|
||||
resource_pile::ResourcePile, unit::Units, utils,
|
||||
|
|
@ -77,7 +78,7 @@ pub struct ActionLogItem {
|
|||
pub combat_stats: Option<CombatStats>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub wonder_built: Option<String>,
|
||||
pub wonder_built: Option<Wonder>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub completed_objectives: Vec<String>,
|
||||
|
|
@ -176,7 +177,9 @@ fn format_playing_action_log_item(action: &PlayingAction, game: &Game) -> String
|
|||
card.name,
|
||||
)
|
||||
}
|
||||
PlayingAction::WonderCard(name) => format!("{player_name} played the wonder card {name}",),
|
||||
PlayingAction::WonderCard(name) => {
|
||||
format!("{player_name} played the wonder card {}", name.name(game))
|
||||
}
|
||||
PlayingAction::EndTurn => format!(
|
||||
"{player_name} ended their turn{}",
|
||||
match game.actions_left {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::events::EventOrigin;
|
||||
use crate::map::Map;
|
||||
use crate::map::Terrain::{Forest, Mountain};
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::map::Terrain::{Fertile, Forest, Mountain};
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::unit::{Unit, set_unit_position};
|
||||
use crate::utils;
|
||||
|
|
@ -16,6 +16,7 @@ use crate::player::Player;
|
|||
use crate::player_events::MoveInfo;
|
||||
use crate::position::Position;
|
||||
use crate::unit::{carried_units, get_current_move};
|
||||
use crate::wonder::Wonder;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
@ -59,6 +60,7 @@ pub enum MovementRestriction {
|
|||
Battle,
|
||||
Mountain,
|
||||
Forest,
|
||||
Fertile,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug, Default)]
|
||||
|
|
@ -167,13 +169,33 @@ fn move_unit(
|
|||
/// # Panics
|
||||
///
|
||||
/// Panics if destination tile does not exist
|
||||
pub fn move_units_destinations(
|
||||
pub fn possible_move_units_destinations(
|
||||
player: &Player,
|
||||
game: &Game,
|
||||
unit_ids: &[u32],
|
||||
start: Position,
|
||||
embark_carrier_id: Option<u32>,
|
||||
) -> Result<Vec<MoveRoute>, String> {
|
||||
let destinations = move_units_destinations(player, game, unit_ids, start, embark_carrier_id)?;
|
||||
|
||||
if destinations.is_empty() {
|
||||
return Err("no valid destinations".to_string());
|
||||
}
|
||||
Ok(destinations
|
||||
.into_iter()
|
||||
.filter_map(|(route, r)| r.is_ok().then_some(route))
|
||||
.collect_vec())
|
||||
}
|
||||
|
||||
pub(crate) type MoveDestinations = Vec<(MoveRoute, Result<(), String>)>;
|
||||
|
||||
pub(crate) fn move_units_destinations(
|
||||
player: &Player,
|
||||
game: &Game,
|
||||
unit_ids: &[u32],
|
||||
start: Position,
|
||||
embark_carrier_id: Option<u32>,
|
||||
) -> Result<MoveDestinations, String> {
|
||||
let (moved_units, movement_actions_left, current_move) = if let Movement(m) = &game.state {
|
||||
(&m.moved_units, m.movement_actions_left, &m.current_move)
|
||||
} else {
|
||||
|
|
@ -208,78 +230,126 @@ pub fn move_units_destinations(
|
|||
}
|
||||
}
|
||||
|
||||
let destinations: Vec<MoveRoute> =
|
||||
Ok(
|
||||
move_routes(start, player, unit_ids, game, embark_carrier_id)
|
||||
.iter()
|
||||
.filter(|route| {
|
||||
if !player.can_afford(&route.cost) {
|
||||
return false;
|
||||
}
|
||||
if movement_restrictions.contains(&&MovementRestriction::Battle) {
|
||||
return false;
|
||||
}
|
||||
let dest = route.destination;
|
||||
let attack = game.enemy_player(player.index, dest).is_some();
|
||||
if attack && game.map.is_land(dest) && stack_size == 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
if !route.ignore_terrain_movement_restrictions {
|
||||
if movement_restrictions
|
||||
.iter()
|
||||
.contains(&&MovementRestriction::Mountain)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if attack
|
||||
&& movement_restrictions
|
||||
.iter()
|
||||
.contains(&&MovementRestriction::Forest)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
if game.map.is_land(start)
|
||||
&& player
|
||||
.get_units(dest)
|
||||
.iter()
|
||||
.filter(|unit| unit.unit_type.is_army_unit() && !unit.is_transported())
|
||||
.count()
|
||||
+ stack_size
|
||||
+ route.stack_size_used
|
||||
> STACK_LIMIT
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
if !is_valid_movement_type(game, &units, carrier_position, dest) {
|
||||
return false;
|
||||
}
|
||||
|
||||
if !matches!(current_move, CurrentMove::None)
|
||||
&& *current_move
|
||||
== get_current_move(game, unit_ids, start, dest, embark_carrier_id)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
if movement_actions_left == 0 {
|
||||
return false;
|
||||
}
|
||||
|
||||
if unit_ids.iter().any(|id| moved_units.contains(id)) {
|
||||
return false;
|
||||
}
|
||||
true
|
||||
.into_iter()
|
||||
.map(|route| {
|
||||
let result = move_route_result(
|
||||
player,
|
||||
game,
|
||||
unit_ids,
|
||||
start,
|
||||
embark_carrier_id,
|
||||
moved_units,
|
||||
movement_actions_left,
|
||||
current_move,
|
||||
&units,
|
||||
carrier_position,
|
||||
stack_size,
|
||||
&mut movement_restrictions,
|
||||
&route,
|
||||
);
|
||||
(route, result)
|
||||
})
|
||||
.cloned()
|
||||
.collect();
|
||||
.collect_vec(),
|
||||
)
|
||||
}
|
||||
|
||||
if destinations.is_empty() {
|
||||
return Err("no valid destinations".to_string());
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
fn move_route_result(
|
||||
player: &Player,
|
||||
game: &Game,
|
||||
unit_ids: &[u32],
|
||||
start: Position,
|
||||
embark_carrier_id: Option<u32>,
|
||||
moved_units: &[u32],
|
||||
movement_actions_left: u32,
|
||||
current_move: &CurrentMove,
|
||||
units: &Vec<&Unit>,
|
||||
carrier_position: Option<Position>,
|
||||
stack_size: usize,
|
||||
movement_restrictions: &mut Vec<&MovementRestriction>,
|
||||
route: &MoveRoute,
|
||||
) -> Result<(), String> {
|
||||
if !player.can_afford(&route.cost) {
|
||||
return Err("not enough resources".to_string());
|
||||
}
|
||||
Ok(destinations)
|
||||
|
||||
is_move_restricted(player, game, stack_size, movement_restrictions, route)?;
|
||||
|
||||
let dest = route.destination;
|
||||
if game.map.is_land(start)
|
||||
&& player
|
||||
.get_units(dest)
|
||||
.iter()
|
||||
.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());
|
||||
}
|
||||
|
||||
is_valid_movement_type(game, units, carrier_position, dest)?;
|
||||
|
||||
if matches!(current_move, CurrentMove::None)
|
||||
|| *current_move != get_current_move(game, unit_ids, start, dest, embark_carrier_id)
|
||||
{
|
||||
if movement_actions_left == 0 {
|
||||
return Err("no movement actions left".to_string());
|
||||
}
|
||||
|
||||
if unit_ids.iter().any(|id| moved_units.contains(id)) {
|
||||
return Err("some units already moved".to_string());
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn is_move_restricted(
|
||||
player: &Player,
|
||||
game: &Game,
|
||||
stack_size: usize,
|
||||
movement_restrictions: &Vec<&MovementRestriction>,
|
||||
route: &MoveRoute,
|
||||
) -> Result<(), String> {
|
||||
if movement_restrictions.contains(&&MovementRestriction::Battle) {
|
||||
return Err("battle movement restriction".to_string());
|
||||
}
|
||||
let dest = route.destination;
|
||||
let attack = game.enemy_player(player.index, dest).is_some();
|
||||
if attack && game.map.is_land(dest) && stack_size == 0 {
|
||||
return Err("no army units to attack".to_string());
|
||||
}
|
||||
|
||||
if !route.ignore_terrain_movement_restrictions {
|
||||
if movement_restrictions
|
||||
.iter()
|
||||
.contains(&&MovementRestriction::Mountain)
|
||||
{
|
||||
return Err("mountain movement restriction".to_string());
|
||||
}
|
||||
if attack
|
||||
&& movement_restrictions
|
||||
.iter()
|
||||
.contains(&&MovementRestriction::Forest)
|
||||
{
|
||||
return Err("forest movement attack restriction".to_string());
|
||||
}
|
||||
}
|
||||
// this restriction can't be ignored
|
||||
if attack
|
||||
&& game
|
||||
.try_get_any_city(dest)
|
||||
.is_some_and(|city| city.pieces.wonders.contains(&Wonder::GreatGardens))
|
||||
&& movement_restrictions
|
||||
.iter()
|
||||
.any(|&r| r == &MovementRestriction::Fertile)
|
||||
{
|
||||
return Err("fertile movement attack great gardens restriction".to_string());
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn check_can_move(
|
||||
|
|
@ -293,7 +363,7 @@ fn check_can_move(
|
|||
}
|
||||
if let Some(embark_carrier_id) = embark_carrier_id {
|
||||
if !unit.unit_type.is_land_based() {
|
||||
return Err("the unit should be land based to embark".to_string());
|
||||
return Err("the unit should be land-based to embark".to_string());
|
||||
}
|
||||
let carrier = player.get_unit(embark_carrier_id);
|
||||
if !carrier.unit_type.is_ship() {
|
||||
|
|
@ -332,19 +402,23 @@ pub(crate) fn is_valid_movement_type(
|
|||
units: &Vec<&Unit>,
|
||||
embark_position: Option<Position>,
|
||||
dest: Position,
|
||||
) -> bool {
|
||||
) -> Result<(), String> {
|
||||
if let Some(embark_position) = embark_position {
|
||||
return dest == embark_position;
|
||||
return if dest == embark_position {
|
||||
Ok(())
|
||||
} else {
|
||||
Err("the destination should be the carrier position".to_string())
|
||||
};
|
||||
}
|
||||
units.iter().all(|unit| {
|
||||
for unit in units {
|
||||
if unit.unit_type.is_land_based() && game.map.is_sea(dest) {
|
||||
return false;
|
||||
return Err("the destination should be land".to_string());
|
||||
}
|
||||
if unit.unit_type.is_ship() && game.map.is_land(dest) {
|
||||
return false;
|
||||
return Err("the destination should be sea".to_string());
|
||||
}
|
||||
true
|
||||
})
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
@ -451,8 +525,11 @@ fn reachable_with_roads(player: &Player, units: &[u32], game: &Game) -> Vec<Move
|
|||
{
|
||||
let stack_size_used =
|
||||
stack_sizes_used.iter().map(|&(_, s)| s).min().expect("min");
|
||||
let mut cost =
|
||||
PaymentOptions::resources(ResourcePile::ore(1) + ResourcePile::food(1));
|
||||
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 {
|
||||
|
|
@ -538,6 +615,7 @@ pub(crate) fn terrain_movement_restriction(
|
|||
.get(destination)
|
||||
.expect("the destination position should exist on the map");
|
||||
match terrain {
|
||||
Fertile => Some(MovementRestriction::Fertile),
|
||||
Mountain => Some(MovementRestriction::Mountain),
|
||||
Forest if unit.unit_type.is_army_unit() => Some(MovementRestriction::Forest),
|
||||
_ => None,
|
||||
|
|
@ -546,8 +624,9 @@ pub(crate) fn terrain_movement_restriction(
|
|||
|
||||
pub(crate) fn has_movable_units(game: &Game, player: &Player) -> bool {
|
||||
player.units.iter().any(|unit| {
|
||||
move_units_destinations(player, game, &[unit.id], unit.position, None).is_ok()
|
||||
|| can_embark(game, player, unit)
|
||||
let result =
|
||||
possible_move_units_destinations(player, game, &[unit.id], unit.position, None);
|
||||
result.is_ok_and(|r| !r.is_empty()) || can_embark(game, player, unit)
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -556,6 +635,13 @@ pub fn can_embark(game: &Game, player: &Player, unit: &Unit) -> bool {
|
|||
unit.unit_type.is_land_based()
|
||||
&& player.units.iter().any(|u| {
|
||||
u.unit_type.is_ship()
|
||||
&& move_units_destinations(player, game, &[unit.id], u.position, Some(u.id)).is_ok()
|
||||
&& possible_move_units_destinations(
|
||||
player,
|
||||
game,
|
||||
&[unit.id],
|
||||
u.position,
|
||||
Some(u.id),
|
||||
)
|
||||
.is_ok()
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,30 @@
|
|||
use crate::events::EventOrigin;
|
||||
use crate::player::Player;
|
||||
use crate::resource::ResourceType;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::wonder::Wonder;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt::Display;
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
// not used right now - but might be useful for statistics
|
||||
#[derive(Clone, PartialEq, Eq, Debug)]
|
||||
pub enum PaymentReason {
|
||||
Recruit,
|
||||
IncreaseHappiness,
|
||||
GainAdvance,
|
||||
Building,
|
||||
Incident,
|
||||
AdvanceAbility,
|
||||
WonderAbility,
|
||||
ActionCard,
|
||||
CustomAction,
|
||||
InfluenceCulture,
|
||||
Move,
|
||||
ChangeGovernment,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum PaymentConversionType {
|
||||
Unlimited,
|
||||
|
|
@ -108,27 +127,26 @@ impl PaymentOptions {
|
|||
|
||||
#[must_use]
|
||||
pub fn free() -> Self {
|
||||
Self::resources(ResourcePile::empty())
|
||||
Self::fixed_resources(ResourcePile::empty())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn sum(cost: u8, types_by_preference: &[ResourceType]) -> Self {
|
||||
let mut conversions = vec![];
|
||||
types_by_preference.windows(2).for_each(|pair| {
|
||||
conversions.push(PaymentConversion::unlimited(
|
||||
ResourcePile::of(pair[0], 1),
|
||||
ResourcePile::of(pair[1], 1),
|
||||
));
|
||||
});
|
||||
PaymentOptions {
|
||||
default: ResourcePile::of(types_by_preference[0], cost),
|
||||
conversions,
|
||||
modifiers: vec![],
|
||||
}
|
||||
pub(crate) fn sum(
|
||||
player: &Player,
|
||||
reason: PaymentReason,
|
||||
cost: u8,
|
||||
types_by_preference: &[ResourceType],
|
||||
) -> Self {
|
||||
payment_options_sum(cost, types_by_preference).add_extra_options(player, reason)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn single_type(t: ResourceType, r: RangeInclusive<u8>) -> PaymentOptions {
|
||||
pub(crate) fn single_type(
|
||||
player: &Player,
|
||||
reason: PaymentReason,
|
||||
t: ResourceType,
|
||||
r: RangeInclusive<u8>,
|
||||
) -> PaymentOptions {
|
||||
let max = r.clone().max().expect("range empty");
|
||||
let d = max - r.min().expect("range empty");
|
||||
PaymentOptions {
|
||||
|
|
@ -140,18 +158,35 @@ impl PaymentOptions {
|
|||
)],
|
||||
modifiers: vec![],
|
||||
}
|
||||
.add_extra_options(player, reason)
|
||||
}
|
||||
|
||||
fn add_extra_options(mut self, player: &Player, _reason: PaymentReason) -> Self {
|
||||
if player.wonders_owned.contains(Wonder::Colosseum) {
|
||||
self.conversions.push(PaymentConversion::unlimited(
|
||||
ResourcePile::of(ResourceType::CultureTokens, 1),
|
||||
ResourcePile::of(ResourceType::MoodTokens, 1),
|
||||
));
|
||||
self.conversions.push(PaymentConversion::unlimited(
|
||||
ResourcePile::of(ResourceType::MoodTokens, 1),
|
||||
ResourcePile::of(ResourceType::CultureTokens, 1),
|
||||
));
|
||||
}
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn tokens(cost: u8) -> Self {
|
||||
pub(crate) fn tokens(player: &Player, reason: PaymentReason, cost: u8) -> Self {
|
||||
Self::sum(
|
||||
player,
|
||||
reason,
|
||||
cost,
|
||||
&[ResourceType::MoodTokens, ResourceType::CultureTokens],
|
||||
)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn resources_with_discount(
|
||||
pub(self) fn resources_with_discount(
|
||||
cost: ResourcePile,
|
||||
discount_type: PaymentConversionType,
|
||||
) -> Self {
|
||||
|
|
@ -183,7 +218,13 @@ impl PaymentOptions {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn resources(cost: ResourcePile) -> Self {
|
||||
pub(crate) fn resources(player: &Player, reason: PaymentReason, cost: ResourcePile) -> Self {
|
||||
Self::resources_with_discount(cost, PaymentConversionType::Unlimited)
|
||||
.add_extra_options(player, reason)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn fixed_resources(cost: ResourcePile) -> Self {
|
||||
Self::resources_with_discount(cost, PaymentConversionType::Unlimited)
|
||||
}
|
||||
|
||||
|
|
@ -236,6 +277,29 @@ impl Display for PaymentOptions {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub struct ResourceReward {
|
||||
#[serde(flatten)]
|
||||
pub payment_options: PaymentOptions,
|
||||
}
|
||||
|
||||
impl ResourceReward {
|
||||
#[must_use]
|
||||
pub(crate) fn sum(cost: u8, types_by_preference: &[ResourceType]) -> Self {
|
||||
Self {
|
||||
payment_options: payment_options_sum(cost, types_by_preference),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn tokens(cost: u8) -> Self {
|
||||
Self::sum(
|
||||
cost,
|
||||
&[ResourceType::MoodTokens, ResourceType::CultureTokens],
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn can_convert(
|
||||
available: &ResourcePile,
|
||||
|
|
@ -310,6 +374,21 @@ pub fn can_convert(
|
|||
None
|
||||
}
|
||||
|
||||
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(
|
||||
ResourcePile::of(pair[0], 1),
|
||||
ResourcePile::of(pair[1], 1),
|
||||
));
|
||||
});
|
||||
PaymentOptions {
|
||||
default: ResourcePile::of(types_by_preference[0], cost),
|
||||
conversions,
|
||||
modifiers: vec![],
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
|
@ -321,6 +400,62 @@ mod tests {
|
|||
invalid: Vec<ResourcePile>,
|
||||
}
|
||||
|
||||
fn assert_can_afford(name: &str, cost: &ResourcePile, discount: u8) {
|
||||
let player_has = ResourcePile::new(1, 2, 3, 4, 5, 6, 7);
|
||||
let can_afford = PaymentOptions::resources_with_discount(
|
||||
cost.clone(),
|
||||
PaymentConversionType::MayNotOverpay(discount),
|
||||
)
|
||||
.can_afford(&player_has);
|
||||
assert!(can_afford, "{name}");
|
||||
}
|
||||
|
||||
fn assert_cannot_afford(name: &str, cost: &ResourcePile, discount: u8) {
|
||||
let player_has = ResourcePile::new(1, 2, 3, 4, 5, 6, 7);
|
||||
let can_afford = PaymentOptions::resources_with_discount(
|
||||
cost.clone(),
|
||||
PaymentConversionType::MayNotOverpay(discount),
|
||||
)
|
||||
.can_afford(&player_has);
|
||||
assert!(!can_afford, "{name}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_afford_test() {
|
||||
assert_can_afford("use 6 gold as wood", &ResourcePile::wood(7), 0);
|
||||
assert_cannot_afford("6 gold is not enough", &ResourcePile::wood(8), 0);
|
||||
|
||||
assert_cannot_afford(
|
||||
"gold cannot be converted to mood",
|
||||
&ResourcePile::mood_tokens(7),
|
||||
0,
|
||||
);
|
||||
assert_cannot_afford(
|
||||
"gold cannot be converted to culture",
|
||||
&ResourcePile::culture_tokens(8),
|
||||
0,
|
||||
);
|
||||
|
||||
assert_can_afford("negative gold means rebate", &(ResourcePile::wood(9)), 2);
|
||||
assert_cannot_afford(
|
||||
"discount cannot rebate mood",
|
||||
&(ResourcePile::mood_tokens(9)),
|
||||
2,
|
||||
);
|
||||
assert_cannot_afford(
|
||||
"discount cannot rebate culture",
|
||||
&(ResourcePile::mood_tokens(8)),
|
||||
2,
|
||||
);
|
||||
|
||||
assert_can_afford("payment costs gold", &ResourcePile::wood(5), 0);
|
||||
assert_cannot_afford(
|
||||
"gold cannot be converted, because it's already used for payment",
|
||||
&(ResourcePile::wood(7) + ResourcePile::gold(1)),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_find_valid_payment() {
|
||||
let cost = PaymentOptions {
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::content::persistent_events::{
|
|||
};
|
||||
use crate::game::Game;
|
||||
use crate::incident::{BASE_EFFECT_PRIORITY, IncidentBuilder};
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason, ResourceReward};
|
||||
use crate::player::{Player, add_unit, remove_unit};
|
||||
use crate::player_events::IncidentTarget;
|
||||
use crate::position::Position;
|
||||
|
|
@ -26,9 +26,8 @@ pub(crate) fn pirates_round_bonus() -> Builtin {
|
|||
if c.is_sea_battle(game)
|
||||
&& c.opponent(player_index) == get_pirates_player(game).index
|
||||
{
|
||||
let hits = r.casualties(CombatRole::Defender).fighters as u32;
|
||||
Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::sum(hits as u8, &[ResourceType::Gold]),
|
||||
ResourceReward::sum(r.hits(CombatRole::Attacker), &[ResourceType::Gold]),
|
||||
"-".to_string(),
|
||||
))
|
||||
} else {
|
||||
|
|
@ -60,7 +59,7 @@ pub(crate) fn pirates_bonus() -> Builtin {
|
|||
.is_pirates()
|
||||
{
|
||||
Some(ResourceRewardRequest::new(
|
||||
PaymentOptions::tokens(1),
|
||||
ResourceReward::tokens(1),
|
||||
"Select a reward for fighting the Pirates".to_string(),
|
||||
))
|
||||
} else {
|
||||
|
|
@ -98,10 +97,14 @@ pub(crate) fn pirates_spawn_and_raid(mut builder: IncidentBuilder) -> IncidentBu
|
|||
"{} must pay 1 resource or token to bribe the pirates",
|
||||
player.get_name()
|
||||
));
|
||||
Some(vec![PaymentRequest::new(
|
||||
PaymentOptions::sum(1, &ResourceType::all()),
|
||||
Some(vec![PaymentRequest::mandatory(
|
||||
PaymentOptions::sum(
|
||||
game.player(player_index),
|
||||
PaymentReason::Incident,
|
||||
1,
|
||||
&ResourceType::all(),
|
||||
),
|
||||
"Pay 1 Resource or token to bribe the pirates",
|
||||
false,
|
||||
)])
|
||||
} else {
|
||||
let state = i.get_barbarian_state();
|
||||
|
|
|
|||
|
|
@ -5,10 +5,11 @@ use crate::content::builtin;
|
|||
use crate::content::builtin::Builtin;
|
||||
use crate::events::{Event, EventOrigin};
|
||||
use crate::objective_card::init_objective_card;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player_events::{CostInfo, TransientEvents};
|
||||
use crate::resource::ResourceType;
|
||||
use crate::unit::{UnitData, UnitType};
|
||||
use crate::wonder::{Wonder, wonders_built_points, wonders_owned_points};
|
||||
use crate::{
|
||||
advance,
|
||||
city::{City, CityData},
|
||||
|
|
@ -17,7 +18,7 @@ use crate::{
|
|||
consts::{
|
||||
ADVANCE_COST, ADVANCE_VICTORY_POINTS, BUILDING_COST, BUILDING_VICTORY_POINTS,
|
||||
CAPTURED_LEADER_VICTORY_POINTS, CITY_LIMIT, CITY_PIECE_LIMIT, OBJECTIVE_VICTORY_POINTS,
|
||||
UNIT_LIMIT, WONDER_VICTORY_POINTS,
|
||||
UNIT_LIMIT,
|
||||
},
|
||||
content::{civilizations, custom_actions::CustomActionType},
|
||||
game::Game,
|
||||
|
|
@ -60,13 +61,14 @@ pub struct Player {
|
|||
pub available_leaders: Vec<String>,
|
||||
pub advances: EnumSet<Advance>,
|
||||
pub unlocked_special_advances: Vec<String>,
|
||||
pub wonders_build: Vec<String>,
|
||||
pub wonders_built: Vec<Wonder>,
|
||||
pub wonders_owned: EnumSet<Wonder>, // transient
|
||||
pub incident_tokens: u8,
|
||||
pub completed_objectives: Vec<String>,
|
||||
pub captured_leaders: Vec<String>,
|
||||
pub event_victory_points: f32,
|
||||
pub custom_actions: HashMap<CustomActionType, EventOrigin>,
|
||||
pub wonder_cards: Vec<String>,
|
||||
pub wonder_cards: Vec<Wonder>,
|
||||
pub action_cards: Vec<u8>,
|
||||
pub objective_cards: Vec<u8>,
|
||||
pub next_unit_id: u32,
|
||||
|
|
@ -125,7 +127,7 @@ impl Player {
|
|||
let mut cities = mem::take(&mut game.players[player_index].cities);
|
||||
for city in &mut cities {
|
||||
for wonder in &city.pieces.wonders {
|
||||
let listeners = game.cache.get_wonder(wonder).listeners.clone();
|
||||
let listeners = game.cache.get_wonder(*wonder).listeners.clone();
|
||||
listeners.init(game, player_index);
|
||||
}
|
||||
}
|
||||
|
|
@ -149,6 +151,11 @@ impl Player {
|
|||
data.id
|
||||
);
|
||||
});
|
||||
let cities = data
|
||||
.cities
|
||||
.into_iter()
|
||||
.map(|d| City::from_data(d, data.id))
|
||||
.collect_vec();
|
||||
Self {
|
||||
name: data.name,
|
||||
index: data.id,
|
||||
|
|
@ -156,11 +163,6 @@ impl Player {
|
|||
resource_limit: data.resource_limit,
|
||||
wasted_resources: ResourcePile::empty(),
|
||||
events: PlayerEvents::new(),
|
||||
cities: data
|
||||
.cities
|
||||
.into_iter()
|
||||
.map(|d| City::from_data(d, data.id))
|
||||
.collect(),
|
||||
destroyed_structures: DestroyedStructures::from_data(data.destroyed_structures),
|
||||
units,
|
||||
civilization: civilizations::get_civilization(&data.civilization)
|
||||
|
|
@ -169,7 +171,12 @@ impl Player {
|
|||
available_leaders: data.available_leaders,
|
||||
advances: EnumSet::from_iter(data.advances),
|
||||
unlocked_special_advances: data.unlocked_special_advance,
|
||||
wonders_build: data.wonders_build,
|
||||
wonders_built: data.wonders_built,
|
||||
wonders_owned: cities
|
||||
.iter()
|
||||
.flat_map(|city| city.pieces.wonders.iter().copied())
|
||||
.collect(),
|
||||
cities,
|
||||
incident_tokens: data.incident_tokens,
|
||||
completed_objectives: data.completed_objectives,
|
||||
captured_leaders: data.captured_leaders,
|
||||
|
|
@ -220,7 +227,7 @@ impl Player {
|
|||
.sorted_by_key(Advance::id)
|
||||
.collect(),
|
||||
unlocked_special_advance: self.unlocked_special_advances,
|
||||
wonders_build: self.wonders_build,
|
||||
wonders_built: self.wonders_built,
|
||||
incident_tokens: self.incident_tokens,
|
||||
completed_objectives: self.completed_objectives,
|
||||
captured_leaders: self.captured_leaders,
|
||||
|
|
@ -257,7 +264,7 @@ impl Player {
|
|||
available_leaders: self.available_leaders.clone(),
|
||||
advances: self.advances.iter().sorted_by_key(Advance::id).collect(),
|
||||
unlocked_special_advance: self.unlocked_special_advances.clone(),
|
||||
wonders_build: self.wonders_build.clone(),
|
||||
wonders_built: self.wonders_built.clone(),
|
||||
incident_tokens: self.incident_tokens,
|
||||
completed_objectives: self.completed_objectives.clone(),
|
||||
captured_leaders: self.captured_leaders.clone(),
|
||||
|
|
@ -304,7 +311,8 @@ impl Player {
|
|||
wonder_cards: Vec::new(),
|
||||
action_cards: Vec::new(),
|
||||
objective_cards: Vec::new(),
|
||||
wonders_build: Vec::new(),
|
||||
wonders_built: Vec::new(),
|
||||
wonders_owned: EnumSet::new(),
|
||||
next_unit_id: 0,
|
||||
played_once_per_turn_actions: Vec::new(),
|
||||
event_info: HashMap::new(),
|
||||
|
|
@ -501,8 +509,7 @@ impl Player {
|
|||
),
|
||||
(
|
||||
"Wonders",
|
||||
(self.wonders_owned() + self.wonders_build.len()) as f32 * WONDER_VICTORY_POINTS
|
||||
/ 2.0,
|
||||
wonders_owned_points(self, game) as f32 + wonders_built_points(self, game),
|
||||
),
|
||||
("Events", self.event_victory_points),
|
||||
(
|
||||
|
|
@ -521,14 +528,6 @@ impl Player {
|
|||
.sum()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn wonders_owned(&self) -> usize {
|
||||
self.cities
|
||||
.iter()
|
||||
.map(|city| city.pieces.wonders.len())
|
||||
.sum::<usize>()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn is_building_available(&self, building: Building, game: &Game) -> bool {
|
||||
game.players
|
||||
|
|
@ -570,12 +569,13 @@ impl Player {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn remove_wonder(&mut self, wonder: &String) {
|
||||
utils::remove_element(&mut self.wonders_build, wonder);
|
||||
pub fn remove_wonder(&mut self, wonder: Wonder) {
|
||||
utils::remove_element(&mut self.wonders_built, &wonder);
|
||||
self.wonders_owned.remove(wonder);
|
||||
}
|
||||
|
||||
pub fn strip_secret(&mut self) {
|
||||
self.wonder_cards = self.wonder_cards.iter().map(|_| String::new()).collect();
|
||||
self.wonder_cards = self.wonder_cards.iter().map(|_| Wonder::Pyramids).collect();
|
||||
self.action_cards = self.action_cards.iter().map(|_| 0).collect();
|
||||
self.objective_cards = self.objective_cards.iter().map(|_| 0).collect();
|
||||
self.secrets = Vec::new();
|
||||
|
|
@ -614,7 +614,7 @@ impl Player {
|
|||
pub fn building_cost(&self, game: &Game, building: Building, execute: CostTrigger) -> CostInfo {
|
||||
self.trigger_cost_event(
|
||||
|e| &e.construct_cost,
|
||||
&PaymentOptions::resources(BUILDING_COST),
|
||||
&PaymentOptions::resources(self, PaymentReason::Building, BUILDING_COST),
|
||||
&building,
|
||||
game,
|
||||
execute,
|
||||
|
|
@ -626,6 +626,8 @@ impl Player {
|
|||
self.trigger_cost_event(
|
||||
|e| &e.advance_cost,
|
||||
&PaymentOptions::sum(
|
||||
self,
|
||||
PaymentReason::GainAdvance,
|
||||
ADVANCE_COST,
|
||||
&[ResourceType::Ideas, ResourceType::Food, ResourceType::Gold],
|
||||
),
|
||||
|
|
@ -843,7 +845,7 @@ pub struct PlayerData {
|
|||
unlocked_special_advance: Vec<String>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
wonders_build: Vec<String>,
|
||||
wonders_built: Vec<Wonder>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "u8::is_zero")]
|
||||
incident_tokens: u8,
|
||||
|
|
@ -858,7 +860,7 @@ pub struct PlayerData {
|
|||
event_victory_points: f32,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
wonder_cards: Vec<String>,
|
||||
wonder_cards: Vec<Wonder>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
action_cards: Vec<u8>,
|
||||
|
|
|
|||
|
|
@ -14,7 +14,9 @@ use crate::player::{Player, remove_unit};
|
|||
use crate::player_events::PlayingActionInfo;
|
||||
use crate::recruit::recruit;
|
||||
use crate::unit::Units;
|
||||
use crate::wonder::{WonderCardInfo, WonderDiscount, cities_for_wonder, on_play_wonder_card};
|
||||
use crate::wonder::{
|
||||
Wonder, WonderCardInfo, WonderDiscount, cities_for_wonder, on_play_wonder_card,
|
||||
};
|
||||
use crate::{game::Game, position::Position, resource_pile::ResourcePile};
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
|
||||
|
|
@ -110,7 +112,7 @@ pub enum PlayingActionType {
|
|||
IncreaseHappiness,
|
||||
InfluenceCultureAttempt,
|
||||
ActionCard(u8),
|
||||
WonderCard(String),
|
||||
WonderCard(Wonder),
|
||||
Custom(CustomActionType),
|
||||
EndTurn,
|
||||
}
|
||||
|
|
@ -180,7 +182,7 @@ impl PlayingActionType {
|
|||
return Err("Wonder card not available".to_string());
|
||||
}
|
||||
|
||||
if cities_for_wonder(name, game, p, &WonderDiscount::default()).is_empty() {
|
||||
if cities_for_wonder(*name, game, p, &WonderDiscount::default()).is_empty() {
|
||||
return Err("no cities for wonder".to_string());
|
||||
}
|
||||
}
|
||||
|
|
@ -234,7 +236,7 @@ pub enum PlayingAction {
|
|||
InfluenceCultureAttempt(InfluenceCultureAttempt),
|
||||
Custom(CustomEventAction),
|
||||
ActionCard(u8),
|
||||
WonderCard(String),
|
||||
WonderCard(Wonder),
|
||||
EndTurn,
|
||||
}
|
||||
|
||||
|
|
@ -332,7 +334,7 @@ impl PlayingAction {
|
|||
],
|
||||
),
|
||||
PlayingAction::ActionCard(a) => PlayingActionType::ActionCard(*a),
|
||||
PlayingAction::WonderCard(name) => PlayingActionType::WonderCard(name.clone()),
|
||||
PlayingAction::WonderCard(name) => PlayingActionType::WonderCard(*name),
|
||||
PlayingAction::Custom(c) => PlayingActionType::Custom(c.action.clone()),
|
||||
PlayingAction::EndTurn => PlayingActionType::EndTurn,
|
||||
}
|
||||
|
|
@ -369,7 +371,7 @@ impl ActionCost {
|
|||
pub(crate) fn pay(&self, game: &mut Game, player_index: usize) {
|
||||
let p = game.player_mut(player_index);
|
||||
let cost = self.cost.clone();
|
||||
p.lose_resources(cost.clone());
|
||||
p.lose_resources(cost.clone()); // todo colosseum
|
||||
if !self.free {
|
||||
game.actions_left -= 1;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::combat;
|
|||
use crate::consts::STACK_LIMIT;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::game::Game;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player::{CostTrigger, Player, add_unit};
|
||||
use crate::player_events::CostInfo;
|
||||
use crate::playing_actions::Recruit;
|
||||
|
|
@ -174,7 +174,11 @@ pub fn recruit_cost_without_replaced(
|
|||
}
|
||||
let cost = player.trigger_cost_event(
|
||||
|e| &e.recruit_cost,
|
||||
&PaymentOptions::resources(units.clone().to_vec().iter().map(UnitType::cost).sum()),
|
||||
&PaymentOptions::resources(
|
||||
player,
|
||||
PaymentReason::Recruit,
|
||||
units.clone().to_vec().iter().map(UnitType::cost).sum(),
|
||||
),
|
||||
units,
|
||||
player,
|
||||
execute,
|
||||
|
|
|
|||
|
|
@ -441,27 +441,6 @@ impl CostWithDiscount {
|
|||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::ResourcePile;
|
||||
use crate::payment::{PaymentConversionType, PaymentOptions};
|
||||
|
||||
fn assert_can_afford(name: &str, cost: &ResourcePile, discount: u8) {
|
||||
let player_has = ResourcePile::new(1, 2, 3, 4, 5, 6, 7);
|
||||
let can_afford = PaymentOptions::resources_with_discount(
|
||||
cost.clone(),
|
||||
PaymentConversionType::MayNotOverpay(discount),
|
||||
)
|
||||
.can_afford(&player_has);
|
||||
assert!(can_afford, "{name}");
|
||||
}
|
||||
|
||||
fn assert_cannot_afford(name: &str, cost: &ResourcePile, discount: u8) {
|
||||
let player_has = ResourcePile::new(1, 2, 3, 4, 5, 6, 7);
|
||||
let can_afford = PaymentOptions::resources_with_discount(
|
||||
cost.clone(),
|
||||
PaymentConversionType::MayNotOverpay(discount),
|
||||
)
|
||||
.can_afford(&player_has);
|
||||
assert!(!can_afford, "{name}");
|
||||
}
|
||||
|
||||
fn assert_to_string(resource_pile: &ResourcePile, expected: &str) {
|
||||
assert_eq!(
|
||||
|
|
@ -471,42 +450,6 @@ mod tests {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn can_afford_test() {
|
||||
assert_can_afford("use 6 gold as wood", &ResourcePile::wood(7), 0);
|
||||
assert_cannot_afford("6 gold is not enough", &ResourcePile::wood(8), 0);
|
||||
|
||||
assert_cannot_afford(
|
||||
"gold cannot be converted to mood",
|
||||
&ResourcePile::mood_tokens(7),
|
||||
0,
|
||||
);
|
||||
assert_cannot_afford(
|
||||
"gold cannot be converted to culture",
|
||||
&ResourcePile::culture_tokens(8),
|
||||
0,
|
||||
);
|
||||
|
||||
assert_can_afford("negative gold means rebate", &(ResourcePile::wood(9)), 2);
|
||||
assert_cannot_afford(
|
||||
"discount cannot rebate mood",
|
||||
&(ResourcePile::mood_tokens(9)),
|
||||
2,
|
||||
);
|
||||
assert_cannot_afford(
|
||||
"discount cannot rebate culture",
|
||||
&(ResourcePile::mood_tokens(8)),
|
||||
2,
|
||||
);
|
||||
|
||||
assert_can_afford("payment costs gold", &ResourcePile::wood(5), 0);
|
||||
assert_cannot_afford(
|
||||
"gold cannot be converted, because it's already used for payment",
|
||||
&(ResourcePile::wood(7) + ResourcePile::gold(1)),
|
||||
0,
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn resource_limit_test() {
|
||||
let mut resources = ResourcePile::new(3, 6, 9, 9, 0, 10, 6);
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use crate::content::persistent_events::{
|
|||
use crate::objective_card::{
|
||||
gain_objective_card_from_pile, present_objective_cards, status_phase_completable,
|
||||
};
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::payment::{PaymentOptions, PaymentReason};
|
||||
use crate::player_events::{PersistentEvent, PersistentEvents};
|
||||
use crate::{game::Game, player::Player, resource_pile::ResourcePile, utils};
|
||||
use itertools::Itertools;
|
||||
|
|
@ -254,7 +254,11 @@ where
|
|||
move |game, player_index, _, _| {
|
||||
let p = game.player(player_index);
|
||||
(can_change_government_for_free(p, game)
|
||||
&& p.can_afford(&PaymentOptions::resources(cost.clone())))
|
||||
&& p.can_afford(&PaymentOptions::resources(
|
||||
p,
|
||||
PaymentReason::ChangeGovernment,
|
||||
cost.clone(),
|
||||
)))
|
||||
.then_some(PersistentEventRequest::ChangeGovernment(
|
||||
ChangeGovernmentRequest::new(optional, cost.clone()),
|
||||
))
|
||||
|
|
@ -282,7 +286,7 @@ where
|
|||
.join(", ")
|
||||
}
|
||||
));
|
||||
game.players[player_index].lose_resources(cost2.clone());
|
||||
game.players[player_index].lose_resources(cost2.clone()); // todo colosseum
|
||||
change_government_type(game, player_index, &c);
|
||||
}
|
||||
ChangeGovernmentType::KeepGovernment => {
|
||||
|
|
|
|||
|
|
@ -3,6 +3,7 @@ use crate::advance::Advance;
|
|||
use crate::card::draw_card_from_pile;
|
||||
use crate::city::{City, MoodState};
|
||||
use crate::construct::can_construct_anything;
|
||||
use crate::consts::WONDER_VICTORY_POINTS;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::effects::PermanentEffect;
|
||||
use crate::content::persistent_events::{PaymentRequest, PersistentEventType, PositionRequest};
|
||||
|
|
@ -12,74 +13,131 @@ use crate::payment::PaymentOptions;
|
|||
use crate::player::Player;
|
||||
use crate::utils::remove_element;
|
||||
use crate::{ability_initializer::AbilityInitializerSetup, game::Game, position::Position};
|
||||
use enumset::EnumSetType;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::sync::Arc;
|
||||
|
||||
type PlacementChecker = Arc<dyn Fn(Position, &Game) -> bool + Sync + Send>;
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct Wonder {
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub cost: PaymentOptions,
|
||||
pub required_advances: Vec<Advance>,
|
||||
pub placement_requirement: Option<PlacementChecker>,
|
||||
pub listeners: AbilityListeners,
|
||||
#[derive(EnumSetType, Serialize, Deserialize, Debug, Ord, PartialOrd, Hash)]
|
||||
pub enum Wonder {
|
||||
Colosseum = 0,
|
||||
Pyramids,
|
||||
GreatGardens,
|
||||
GreatLibrary,
|
||||
GreatWall,
|
||||
GreatLighthouse,
|
||||
Colossus,
|
||||
GreatMausoleum,
|
||||
}
|
||||
|
||||
impl Wonder {
|
||||
#[must_use]
|
||||
pub fn info<'a>(&self, game: &'a Game) -> &'a WonderInfo {
|
||||
game.cache.get_wonder(*self)
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn id(&self) -> String {
|
||||
format!("{self:?}")
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn name<'a>(&self, game: &'a Game) -> &'a str {
|
||||
self.info(game).name.as_str()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct WonderInfo {
|
||||
pub wonder: Wonder,
|
||||
pub name: String,
|
||||
pub description: String,
|
||||
pub cost: PaymentOptions,
|
||||
pub required_advance: Advance,
|
||||
pub placement_requirement: Option<PlacementChecker>,
|
||||
pub listeners: AbilityListeners,
|
||||
pub owned_victory_points: u8,
|
||||
pub built_victory_points: f32,
|
||||
}
|
||||
|
||||
impl WonderInfo {
|
||||
#[must_use]
|
||||
pub fn builder(
|
||||
wonder: Wonder,
|
||||
name: &str,
|
||||
description: &str,
|
||||
cost: PaymentOptions,
|
||||
required_advances: Vec<Advance>,
|
||||
required_advance: Advance,
|
||||
) -> WonderBuilder {
|
||||
WonderBuilder::new(name, description, cost, required_advances)
|
||||
WonderBuilder::new(wonder, name, description, cost, required_advance)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct WonderBuilder {
|
||||
wonder: Wonder,
|
||||
name: String,
|
||||
descriptions: Vec<String>,
|
||||
cost: PaymentOptions,
|
||||
required_advances: Vec<Advance>,
|
||||
required_advance: Advance,
|
||||
placement_requirement: Option<PlacementChecker>,
|
||||
builder: AbilityInitializerBuilder,
|
||||
pub owned_victory_points: u8,
|
||||
pub built_victory_points: f32,
|
||||
}
|
||||
|
||||
impl WonderBuilder {
|
||||
fn new(
|
||||
wonder: Wonder,
|
||||
name: &str,
|
||||
description: &str,
|
||||
cost: PaymentOptions,
|
||||
required_advances: Vec<Advance>,
|
||||
required_advance: Advance,
|
||||
) -> Self {
|
||||
Self {
|
||||
wonder,
|
||||
name: name.to_string(),
|
||||
descriptions: vec![description.to_string()],
|
||||
cost,
|
||||
required_advances,
|
||||
required_advance,
|
||||
placement_requirement: None,
|
||||
builder: AbilityInitializerBuilder::new(),
|
||||
built_victory_points: WONDER_VICTORY_POINTS as f32 / 2.0,
|
||||
owned_victory_points: WONDER_VICTORY_POINTS / 2,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn placement_requirement(&mut self, placement_requirement: PlacementChecker) -> &mut Self {
|
||||
#[must_use]
|
||||
pub fn placement_requirement(mut self, placement_requirement: PlacementChecker) -> Self {
|
||||
self.placement_requirement = Some(placement_requirement);
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn build(self) -> Wonder {
|
||||
Wonder {
|
||||
pub fn built_victory_points(mut self, points: f32) -> Self {
|
||||
self.built_victory_points = points;
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn owned_victory_points(mut self, points: u8) -> Self {
|
||||
self.owned_victory_points = points;
|
||||
self
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn build(self) -> WonderInfo {
|
||||
WonderInfo {
|
||||
wonder: self.wonder,
|
||||
name: self.name,
|
||||
description: String::from("✦ ") + &self.descriptions.join("\n✦ "),
|
||||
cost: self.cost,
|
||||
required_advances: self.required_advances,
|
||||
required_advance: self.required_advance,
|
||||
placement_requirement: self.placement_requirement,
|
||||
listeners: self.builder.build(),
|
||||
owned_victory_points: self.owned_victory_points,
|
||||
built_victory_points: self.built_victory_points,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -90,7 +148,7 @@ impl AbilityInitializerSetup for WonderBuilder {
|
|||
}
|
||||
|
||||
fn get_key(&self) -> EventOrigin {
|
||||
EventOrigin::Wonder(self.name.clone())
|
||||
EventOrigin::Wonder(self.wonder)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -103,7 +161,7 @@ pub(crate) fn draw_wonder_card(game: &mut Game, player_index: usize) {
|
|||
);
|
||||
}
|
||||
|
||||
pub(crate) fn draw_wonder_from_pile(game: &mut Game) -> Option<String> {
|
||||
pub(crate) fn draw_wonder_from_pile(game: &mut Game) -> Option<Wonder> {
|
||||
draw_card_from_pile(
|
||||
game,
|
||||
"Wonders",
|
||||
|
|
@ -114,7 +172,7 @@ pub(crate) fn draw_wonder_from_pile(game: &mut Game) -> Option<String> {
|
|||
)
|
||||
}
|
||||
|
||||
fn gain_wonder(game: &mut Game, player_index: usize, wonder: String) {
|
||||
fn gain_wonder(game: &mut Game, player_index: usize, wonder: Wonder) {
|
||||
game.players[player_index].wonder_cards.push(wonder);
|
||||
}
|
||||
|
||||
|
|
@ -127,7 +185,8 @@ pub(crate) fn on_draw_wonder_card() -> Builtin {
|
|||
let public_wonder = find_public_wonder(game);
|
||||
if let Some(public_wonder) = public_wonder {
|
||||
Some(format!(
|
||||
"Do you want to draw the public wonder card {public_wonder}?"
|
||||
"Do you want to draw the public wonder card {}?",
|
||||
public_wonder.name(game)
|
||||
))
|
||||
} else {
|
||||
gain_wonder_from_pile(game, player_index);
|
||||
|
|
@ -136,12 +195,11 @@ pub(crate) fn on_draw_wonder_card() -> Builtin {
|
|||
},
|
||||
|game, s, ()| {
|
||||
if s.choice {
|
||||
let name = find_public_wonder(game)
|
||||
.expect("public wonder card not found")
|
||||
.clone();
|
||||
let name = *find_public_wonder(game).expect("public wonder card not found");
|
||||
game.add_info_log_item(&format!(
|
||||
"{} drew the public wonder card {}",
|
||||
s.player_name, name
|
||||
s.player_name,
|
||||
name.name(game)
|
||||
));
|
||||
gain_wonder(game, s.player_index, name);
|
||||
game.permanent_effects
|
||||
|
|
@ -164,7 +222,7 @@ fn gain_wonder_from_pile(game: &mut Game, player: usize) {
|
|||
}
|
||||
}
|
||||
|
||||
fn find_public_wonder(game: &Game) -> Option<&String> {
|
||||
fn find_public_wonder(game: &Game) -> Option<&Wonder> {
|
||||
game.permanent_effects.iter().find_map(|e| match e {
|
||||
PermanentEffect::PublicWonderCard(name) => Some(name),
|
||||
_ => None,
|
||||
|
|
@ -173,7 +231,7 @@ fn find_public_wonder(game: &Game) -> Option<&String> {
|
|||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct WonderCardInfo {
|
||||
pub name: String,
|
||||
pub name: Wonder,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub selected_position: Option<Position>,
|
||||
|
|
@ -182,7 +240,7 @@ pub struct WonderCardInfo {
|
|||
|
||||
impl WonderCardInfo {
|
||||
#[must_use]
|
||||
pub fn new(name: String, discount: WonderDiscount) -> Self {
|
||||
pub fn new(name: Wonder, discount: WonderDiscount) -> Self {
|
||||
Self {
|
||||
name,
|
||||
selected_position: None,
|
||||
|
|
@ -193,16 +251,18 @@ impl WonderCardInfo {
|
|||
|
||||
pub(crate) fn can_construct_wonder(
|
||||
city: &City,
|
||||
wonder: &Wonder,
|
||||
wonder: Wonder,
|
||||
player: &Player,
|
||||
game: &Game,
|
||||
discount: &WonderDiscount,
|
||||
) -> Result<PaymentOptions, String> {
|
||||
can_construct_anything(city, player)?;
|
||||
|
||||
if !player.wonder_cards.contains(&wonder.name) {
|
||||
if !player.wonder_cards.contains(&wonder) {
|
||||
return Err("Wonder card not owned".to_string());
|
||||
}
|
||||
let info = wonder.info(game);
|
||||
|
||||
if city.mood_state != MoodState::Happy {
|
||||
return Err("City is not happy".to_string());
|
||||
}
|
||||
|
|
@ -210,18 +270,17 @@ pub(crate) fn can_construct_wonder(
|
|||
return Err("Engineering advance missing".to_string());
|
||||
}
|
||||
if !discount.ignore_required_advances {
|
||||
for advance in &wonder.required_advances {
|
||||
if !player.has_advance(*advance) {
|
||||
return Err(format!("Advance missing: {}", advance.name(game)));
|
||||
}
|
||||
let a = info.required_advance;
|
||||
if !player.has_advance(a) {
|
||||
return Err(format!("Advance missing: {a:?}"));
|
||||
}
|
||||
}
|
||||
if let Some(placement_requirement) = &wonder.placement_requirement {
|
||||
if let Some(placement_requirement) = &info.placement_requirement {
|
||||
if !placement_requirement(city.position, game) {
|
||||
return Err("Placement requirement not met".to_string());
|
||||
}
|
||||
}
|
||||
let mut cost = wonder.cost.clone();
|
||||
let mut cost = info.cost.clone();
|
||||
cost.default.culture_tokens = cost
|
||||
.default
|
||||
.culture_tokens
|
||||
|
|
@ -272,7 +331,7 @@ pub(crate) fn build_wonder() -> Builtin {
|
|||
11,
|
||||
move |game, player_index, i| {
|
||||
let p = game.player(player_index);
|
||||
let choices = cities_for_wonder(&i.name, game, p, &i.discount);
|
||||
let choices = cities_for_wonder(i.name, game, p, &i.discount);
|
||||
|
||||
let needed = 1..=1;
|
||||
Some(PositionRequest::new(
|
||||
|
|
@ -286,7 +345,9 @@ pub(crate) fn build_wonder() -> Builtin {
|
|||
i.selected_position = Some(position);
|
||||
game.add_info_log_item(&format!(
|
||||
"{} decided to build {} in city {}",
|
||||
s.player_name, i.name, position
|
||||
s.player_name,
|
||||
i.name.name(game),
|
||||
position
|
||||
));
|
||||
},
|
||||
)
|
||||
|
|
@ -296,25 +357,22 @@ pub(crate) fn build_wonder() -> Builtin {
|
|||
move |game, player_index, i| {
|
||||
let p = game.player(player_index);
|
||||
let city = p.get_city(i.selected_position.expect("city not selected"));
|
||||
let wonder = game.cache.get_wonder(&i.name);
|
||||
let cost = can_construct_wonder(city, wonder, p, game, &i.discount)
|
||||
let cost = can_construct_wonder(city, i.name, p, game, &i.discount)
|
||||
.expect("can't construct wonder");
|
||||
Some(vec![PaymentRequest::new(
|
||||
cost,
|
||||
"Pay to build wonder",
|
||||
false,
|
||||
)])
|
||||
Some(vec![PaymentRequest::mandatory(cost, "Pay to build wonder")])
|
||||
},
|
||||
|game, s, i| {
|
||||
let pos = i.selected_position.expect("city not selected");
|
||||
let name = &i.name;
|
||||
let name = i.name;
|
||||
|
||||
game.add_info_log_item(&format!(
|
||||
"{} built {} in city {pos} for {}",
|
||||
s.player_name, name, s.choice[0]
|
||||
s.player_name,
|
||||
name.name(game),
|
||||
s.choice[0]
|
||||
));
|
||||
current_action_log_item(game).wonder_built = Some(name.clone());
|
||||
remove_element(&mut game.player_mut(s.player_index).wonder_cards, name);
|
||||
current_action_log_item(game).wonder_built = Some(name);
|
||||
remove_element(&mut game.player_mut(s.player_index).wonder_cards, &name);
|
||||
construct_wonder(game, name, pos, s.player_index);
|
||||
},
|
||||
)
|
||||
|
|
@ -322,7 +380,7 @@ pub(crate) fn build_wonder() -> Builtin {
|
|||
}
|
||||
|
||||
pub(crate) fn cities_for_wonder(
|
||||
name: &str,
|
||||
name: Wonder,
|
||||
game: &Game,
|
||||
p: &Player,
|
||||
discount: &WonderDiscount,
|
||||
|
|
@ -330,7 +388,7 @@ pub(crate) fn cities_for_wonder(
|
|||
p.cities
|
||||
.iter()
|
||||
.filter_map(|c| {
|
||||
can_construct_wonder(c, game.cache.get_wonder(name), p, game, discount)
|
||||
can_construct_wonder(c, name, p, game, discount)
|
||||
.ok()
|
||||
.map(|_| c.position)
|
||||
})
|
||||
|
|
@ -339,17 +397,32 @@ pub(crate) fn cities_for_wonder(
|
|||
|
||||
pub(crate) fn construct_wonder(
|
||||
game: &mut Game,
|
||||
name: &str,
|
||||
name: Wonder,
|
||||
city_position: Position,
|
||||
player_index: usize,
|
||||
) {
|
||||
let listeners = game.cache.get_wonder(name).listeners.clone();
|
||||
listeners.one_time_init(game, player_index);
|
||||
let player = &mut game.players[player_index];
|
||||
player.wonders_build.push(name.to_string());
|
||||
player
|
||||
.get_city_mut(city_position)
|
||||
.pieces
|
||||
.wonders
|
||||
.push(name.to_string());
|
||||
player.wonders_built.push(name);
|
||||
player.wonders_owned.insert(name);
|
||||
player.get_city_mut(city_position).pieces.wonders.push(name);
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn wonders_owned_points(player: &Player, game: &Game) -> u8 {
|
||||
player
|
||||
.wonders_owned
|
||||
.iter()
|
||||
.map(|wonder| wonder.info(game).owned_victory_points)
|
||||
.sum::<u8>()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn wonders_built_points(player: &Player, game: &Game) -> f32 {
|
||||
player
|
||||
.wonders_built
|
||||
.iter()
|
||||
.map(|wonder| wonder.info(game).built_victory_points)
|
||||
.sum::<f32>()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use server::card::HandCard;
|
|||
use server::city_pieces::Building::Fortress;
|
||||
use server::collect::PositionCollection;
|
||||
use server::content::persistent_events::{EventResponse, SelectedStructure, Structure};
|
||||
use server::movement::move_units_destinations;
|
||||
use server::movement::possible_move_units_destinations;
|
||||
use server::playing_actions::PlayingAction::Construct;
|
||||
use server::playing_actions::{PlayingAction, PlayingActionType};
|
||||
use server::position::Position;
|
||||
|
|
@ -262,9 +262,9 @@ fn test_negotiations() {
|
|||
TestAction::not_undoable(0, Action::Playing(PlayingAction::EndTurn))
|
||||
.with_pre_assert(|game| {
|
||||
assert!(
|
||||
!move_units_destinations(
|
||||
!possible_move_units_destinations(
|
||||
game.player(0),
|
||||
game,
|
||||
&game,
|
||||
&[0],
|
||||
Position::from_offset("C2"),
|
||||
None,
|
||||
|
|
@ -279,9 +279,9 @@ fn test_negotiations() {
|
|||
TestAction::not_undoable(1, Action::Playing(PlayingAction::EndTurn))
|
||||
.with_pre_assert(|game| {
|
||||
assert!(
|
||||
!move_units_destinations(
|
||||
!possible_move_units_destinations(
|
||||
game.player(1),
|
||||
game,
|
||||
&game,
|
||||
&[0],
|
||||
Position::from_offset("B1"),
|
||||
None,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@ use server::cultural_influence::InfluenceCultureAttempt;
|
|||
use server::events::EventOrigin;
|
||||
use server::game::Game;
|
||||
use server::movement::MovementAction::Move;
|
||||
use server::movement::{MoveUnits, move_units_destinations};
|
||||
use server::movement::{MoveUnits, possible_move_units_destinations};
|
||||
use server::player::CostTrigger;
|
||||
use server::playing_actions::PlayingAction::{
|
||||
Advance, Collect, Construct, Custom, EndTurn, Recruit, WonderCard,
|
||||
|
|
@ -20,6 +20,7 @@ use server::position::Position;
|
|||
use server::recruit::recruit_cost_without_replaced;
|
||||
use server::resource_pile::ResourcePile;
|
||||
use server::unit::Units;
|
||||
use server::wonder::Wonder;
|
||||
use server::{advance, construct, playing_actions};
|
||||
use std::vec;
|
||||
|
||||
|
|
@ -153,7 +154,7 @@ fn test_monuments() {
|
|||
);
|
||||
}
|
||||
|
||||
game = execute_action(game, Action::Playing(WonderCard("Pyramids".to_string())), 0);
|
||||
game = execute_action(game, Action::Playing(WonderCard(Wonder::Pyramids)), 0);
|
||||
game = execute_action(
|
||||
game,
|
||||
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
|
||||
|
|
@ -164,7 +165,7 @@ fn test_monuments() {
|
|||
game = execute_action(
|
||||
game,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::new(
|
||||
2, 3, 3, 0, 0, 0, 4,
|
||||
2, 3, 6, 0, 1, 0, 5,
|
||||
)])),
|
||||
0,
|
||||
);
|
||||
|
|
@ -411,7 +412,7 @@ fn test_road_coordinates() {
|
|||
|
||||
fn get_destinations(game: &Game, units: &[u32], position: &str) -> Vec<String> {
|
||||
let player = game.player(1);
|
||||
move_units_destinations(player, game, units, Position::from_offset(position), None)
|
||||
possible_move_units_destinations(player, game, units, Position::from_offset(position), None)
|
||||
.unwrap()
|
||||
.into_iter()
|
||||
.map(|r| r.destination.to_string())
|
||||
|
|
@ -637,17 +638,25 @@ fn test_collect_husbandry() {
|
|||
fn test_collect_free_economy() {
|
||||
JSON.test(
|
||||
"collect_free_economy",
|
||||
vec![TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Collect(playing_actions::Collect::new(
|
||||
Position::from_offset("C2"),
|
||||
vec![
|
||||
PositionCollection::new(Position::from_offset("B1"), ResourcePile::ore(1)),
|
||||
PositionCollection::new(Position::from_offset("B2"), ResourcePile::ore(1)),
|
||||
],
|
||||
PlayingActionType::Custom(CustomActionType::FreeEconomyCollect),
|
||||
))),
|
||||
)],
|
||||
vec![
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Playing(Collect(playing_actions::Collect::new(
|
||||
Position::from_offset("C2"),
|
||||
vec![
|
||||
PositionCollection::new(Position::from_offset("B1"), ResourcePile::ore(1)),
|
||||
PositionCollection::new(Position::from_offset("B2"), ResourcePile::ore(1)),
|
||||
],
|
||||
PlayingActionType::Custom(CustomActionType::FreeEconomyCollect),
|
||||
))),
|
||||
)
|
||||
.with_post_assert(|game| {
|
||||
// no production focus
|
||||
let result =
|
||||
PlayingActionType::ActionCard(19).is_available(&game, game.active_player());
|
||||
assert!(result.is_err());
|
||||
}),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -720,7 +729,7 @@ fn test_husbandry() {
|
|||
.without_json_comparison()
|
||||
.with_post_assert(|game| {
|
||||
// but not again
|
||||
assert!(has_husbandry_field(game))
|
||||
assert!(has_husbandry_field(&game))
|
||||
}),
|
||||
// can use husbandry - because it was not used in the previous action
|
||||
TestAction::undoable(
|
||||
|
|
@ -737,7 +746,7 @@ fn test_husbandry() {
|
|||
.without_json_comparison()
|
||||
.with_post_assert(|game| {
|
||||
// but not again
|
||||
assert!(!has_husbandry_field(game))
|
||||
assert!(!has_husbandry_field(&game))
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -43,19 +43,19 @@ fn all_actions() {
|
|||
Action::Playing(PlayingAction::Collect(Collect::new(
|
||||
Position::from_offset("D8"),
|
||||
vec![PositionCollection::new(
|
||||
Position::from_offset("E8"),
|
||||
ResourcePile::wood(1)
|
||||
Position::from_offset("C8"),
|
||||
ResourcePile::ore(1)
|
||||
)],
|
||||
PlayingActionType::Collect,
|
||||
))),
|
||||
Action::Playing(PlayingAction::Collect(Collect::new(
|
||||
Position::from_offset("D8"),
|
||||
vec![PositionCollection::new(
|
||||
Position::from_offset("C8"),
|
||||
ResourcePile::ore(1)
|
||||
Position::from_offset("E8"),
|
||||
ResourcePile::wood(1)
|
||||
)],
|
||||
PlayingActionType::Collect,
|
||||
)))
|
||||
))),
|
||||
]
|
||||
),
|
||||
(
|
||||
|
|
|
|||
|
|
@ -146,7 +146,7 @@ pub(crate) fn write_result(actual: &str, result_path: &GamePath) {
|
|||
.expect("Failed to write output file");
|
||||
}
|
||||
|
||||
pub(crate) type TestAssert = Vec<Box<dyn FnOnce(&Game)>>;
|
||||
pub(crate) type TestAssert = Vec<Box<dyn FnOnce(Game)>>;
|
||||
|
||||
pub struct TestAction {
|
||||
action: Action,
|
||||
|
|
@ -187,12 +187,12 @@ impl TestAction {
|
|||
Self::new(action, false, false, player_index)
|
||||
}
|
||||
|
||||
pub fn with_pre_assert(mut self, pre_assert: impl FnOnce(&Game) + 'static) -> Self {
|
||||
pub fn with_pre_assert(mut self, pre_assert: impl FnOnce(Game) + 'static) -> Self {
|
||||
self.pre_asserts.push(Box::new(pre_assert));
|
||||
self
|
||||
}
|
||||
|
||||
pub fn with_post_assert(mut self, post_assert: impl FnOnce(&Game) + 'static) -> Self {
|
||||
pub fn with_post_assert(mut self, post_assert: impl FnOnce(Game) + 'static) -> Self {
|
||||
self.post_asserts.push(Box::new(post_assert));
|
||||
self
|
||||
}
|
||||
|
|
@ -277,7 +277,7 @@ fn test_action_internal(
|
|||
let a = serde_json::to_string(&action).expect("action should be serializable");
|
||||
let a2 = serde_json::from_str(&a).expect("action should be deserializable");
|
||||
for pre_assert in test.pre_asserts {
|
||||
pre_assert(&game);
|
||||
pre_assert(game.clone());
|
||||
}
|
||||
|
||||
if test.illegal_action_test {
|
||||
|
|
@ -301,7 +301,7 @@ fn test_action_internal(
|
|||
return game;
|
||||
}
|
||||
for post_assert in test.post_asserts {
|
||||
post_assert(&game);
|
||||
post_assert(game.clone());
|
||||
}
|
||||
let compare_json = test.compare_json && last_json_compare;
|
||||
undo_redo(
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ use server::content::persistent_events::{EventResponse, SelectedStructure, Struc
|
|||
use server::game_setup::setup_game;
|
||||
use server::log::current_player_turn_log;
|
||||
use server::unit::Units;
|
||||
use server::wonder::Wonder;
|
||||
use server::{
|
||||
action::Action,
|
||||
advance,
|
||||
|
|
@ -39,7 +40,7 @@ fn basic_actions() {
|
|||
let seed = String::new();
|
||||
let mut game = setup_game(1, seed, false);
|
||||
|
||||
game.wonders_left.retain(|w| w == "Pyramids");
|
||||
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 {
|
||||
|
|
@ -74,6 +75,7 @@ fn basic_actions() {
|
|||
game.players[0].gain_resources(ResourcePile::new(2, 4, 4, 0, 2, 2, 3));
|
||||
let city_position = Position::new(0, 0);
|
||||
game.players[0].cities.push(City::new(0, city_position));
|
||||
game.players[0].advances.insert(advance::Advance::Rituals);
|
||||
game.players[0]
|
||||
.cities
|
||||
.push(City::new(0, Position::new(0, 3)));
|
||||
|
|
@ -112,19 +114,21 @@ fn basic_actions() {
|
|||
assert!(matches!(player.get_city(city_position).mood_state, Happy));
|
||||
assert_eq!(2, game.actions_left);
|
||||
|
||||
game = game_api::execute(game, Action::Playing(WonderCard("Pyramids".to_string())), 0);
|
||||
game.players[0].resources = ResourcePile::new(3, 3, 6, 0, 1, 0, 5);
|
||||
|
||||
game = game_api::execute(game, Action::Playing(WonderCard(Wonder::Pyramids)), 0);
|
||||
game = game_api::execute(
|
||||
game,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::new(
|
||||
0, 3, 3, 0, 2, 0, 4,
|
||||
2, 3, 6, 0, 1, 0, 5,
|
||||
)])),
|
||||
0,
|
||||
);
|
||||
let player = &game.players[0];
|
||||
|
||||
assert_eq!(10.0, player.victory_points(&game));
|
||||
assert_eq!(11.6, player.victory_points(&game));
|
||||
assert_eq!(ResourcePile::food(1), player.resources);
|
||||
assert_eq!(vec![String::from("Pyramids")], player.wonders_build);
|
||||
assert_eq!(vec![Wonder::Pyramids], player.wonders_built);
|
||||
assert_eq!(1, player.get_city(city_position).pieces.wonders.len());
|
||||
assert_eq!(4, player.get_city(city_position).mood_modified_size(player));
|
||||
assert_eq!(1, game.actions_left);
|
||||
|
|
@ -322,30 +326,6 @@ fn test_found_city() {
|
|||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_wonder() {
|
||||
JSON.test(
|
||||
"wonder",
|
||||
vec![
|
||||
TestAction::undoable(0, Action::Playing(WonderCard("Pyramids".to_string())))
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::new(
|
||||
2, 3, 3, 0, 0, 0, 4,
|
||||
)])),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectHandCards(vec![
|
||||
HandCard::ObjectiveCard(32),
|
||||
])),
|
||||
),
|
||||
],
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn test_increase_happiness() {
|
||||
JSON.test(
|
||||
|
|
|
|||
|
|
@ -216,7 +216,7 @@ fn test_great_engineer() {
|
|||
)
|
||||
.with_pre_assert(|game| {
|
||||
// must do construct
|
||||
assert!(PlayingActionType::Advance.is_available(game, 0).is_err())
|
||||
assert!(PlayingActionType::Advance.is_available(&game, 0).is_err())
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
|
@ -254,7 +254,7 @@ fn test_great_architect() {
|
|||
TestAction::undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::new(
|
||||
2, 3, 3, 0, 0, 0, 1,
|
||||
2, 3, 6, 0, 1, 0, 2,
|
||||
)])),
|
||||
),
|
||||
],
|
||||
|
|
|
|||
|
|
@ -8,6 +8,7 @@ use server::position::Position;
|
|||
use server::resource_pile::ResourcePile;
|
||||
use server::status_phase::{ChangeGovernment, ChangeGovernmentType};
|
||||
use server::unit::UnitType;
|
||||
use server::wonder::Wonder;
|
||||
use server::{advance, construct};
|
||||
use std::vec;
|
||||
|
||||
|
|
@ -301,7 +302,8 @@ fn test_earthquake() {
|
|||
advance: advance::Advance::Storage,
|
||||
payment: ResourcePile::gold(2),
|
||||
}),
|
||||
),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::SelectStructures(vec![
|
||||
|
|
@ -312,14 +314,16 @@ fn test_earthquake() {
|
|||
),
|
||||
SelectedStructure::new(
|
||||
Position::from_offset("C2"),
|
||||
Structure::Wonder("Pyramids".to_string()),
|
||||
Structure::Wonder(Wonder::GreatGardens),
|
||||
),
|
||||
])),
|
||||
),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
0,
|
||||
Action::Response(EventResponse::Payment(vec![ResourcePile::mood_tokens(1)])),
|
||||
),
|
||||
)
|
||||
.without_json_comparison(),
|
||||
TestAction::not_undoable(
|
||||
1,
|
||||
Action::Response(EventResponse::SelectStructures(vec![
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use server::content::persistent_events::EventResponse;
|
|||
use server::game::Game;
|
||||
use server::movement::MoveUnits;
|
||||
use server::movement::MovementAction::Move;
|
||||
use server::movement::move_units_destinations;
|
||||
use server::movement::possible_move_units_destinations;
|
||||
use server::position::Position;
|
||||
use server::resource_pile::ResourcePile;
|
||||
use server::unit::set_unit_position;
|
||||
|
|
@ -228,7 +228,7 @@ fn test_ship_navigate_coordinates() {
|
|||
|
||||
fn assert_navigate(game: &mut Game, from: Position, to: Position) {
|
||||
set_unit_position(1, 1, from, game);
|
||||
let result = move_units_destinations(game.player(1), game, &[1], from, None)
|
||||
let result = possible_move_units_destinations(game.player(1), game, &[1], from, None)
|
||||
.is_ok_and(|d| d.iter().any(|route| route.destination == to));
|
||||
assert!(
|
||||
result,
|
||||
|
|
|
|||
|
|
@ -105,7 +105,7 @@ fn test_warmonger() {
|
|||
};
|
||||
//can't fulfill both objectives with same name
|
||||
assert_eq!(c.choices.len(), 2);
|
||||
assert!(validate_card_selection(&c.choices, game).is_err());
|
||||
assert!(validate_card_selection(&c.choices, &game).is_err());
|
||||
}),
|
||||
],
|
||||
);
|
||||
|
|
|
|||
|
|
@ -42,7 +42,7 @@ fn test_large_civ() {
|
|||
};
|
||||
//can't fulfill all objectives with same name
|
||||
assert_eq!(c.choices.len(), 8);
|
||||
assert!(validate_card_selection(&c.choices, game).is_err());
|
||||
assert!(validate_card_selection(&c.choices, &game).is_err());
|
||||
}),
|
||||
],
|
||||
)
|
||||
|
|
@ -95,7 +95,7 @@ fn test_standing_army() {
|
|||
};
|
||||
//can't fulfill all objectives with same name
|
||||
assert_eq!(c.choices.len(), 2);
|
||||
assert!(validate_card_selection(&c.choices, game).is_err());
|
||||
assert!(validate_card_selection(&c.choices, &game).is_err());
|
||||
}),
|
||||
],
|
||||
)
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use server::action::ActionType;
|
|||
use server::ai_actions::AiActions;
|
||||
use server::cache::Cache;
|
||||
use server::game::Game;
|
||||
use server::movement::{MoveUnits, MovementAction, move_units_destinations};
|
||||
use server::movement::{MoveUnits, MovementAction, possible_move_units_destinations};
|
||||
use server::playing_actions::PlayingActionType;
|
||||
use server::profiling::start_profiling;
|
||||
use server::{
|
||||
|
|
@ -123,7 +123,7 @@ pub fn get_movement_actions(
|
|||
.into_iter()
|
||||
.flat_map(|(pos, units)| {
|
||||
let unit_ids = units.into_iter().map(|u| u.id).collect_vec();
|
||||
let destinations = move_units_destinations(p, game, &unit_ids, pos, None);
|
||||
let destinations = possible_move_units_destinations(p, game, &unit_ids, pos, None);
|
||||
destinations
|
||||
.map(|d| {
|
||||
d.iter()
|
||||
|
|
|
|||
|
|
@ -48,7 +48,7 @@
|
|||
"ideas": 3,
|
||||
"gold": 7,
|
||||
"mood_tokens": 7,
|
||||
"culture_tokens": 7
|
||||
"culture_tokens": 6
|
||||
},
|
||||
"resource_limit": {
|
||||
"food": 2,
|
||||
|
|
@ -242,6 +242,11 @@
|
|||
2
|
||||
]
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/players/0/resources/culture_tokens",
|
||||
"value": 7
|
||||
},
|
||||
{
|
||||
"op": "remove",
|
||||
"path": "/events"
|
||||
|
|
@ -258,7 +263,7 @@
|
|||
"action_log_index": 1,
|
||||
"log": [
|
||||
[
|
||||
"Player1 played the action card Advance"
|
||||
"Player1 played the action card Advance for 1 culture token"
|
||||
]
|
||||
],
|
||||
"undo_limit": 0,
|
||||
|
|
|
|||
|
|
@ -10,7 +10,7 @@
|
|||
"ideas": 3,
|
||||
"gold": 7,
|
||||
"mood_tokens": 8,
|
||||
"culture_tokens": 7
|
||||
"culture_tokens": 6
|
||||
},
|
||||
"resource_limit": {
|
||||
"food": 7,
|
||||
|
|
@ -205,6 +205,11 @@
|
|||
2
|
||||
]
|
||||
},
|
||||
{
|
||||
"op": "replace",
|
||||
"path": "/players/0/resources/culture_tokens",
|
||||
"value": 7
|
||||
},
|
||||
{
|
||||
"op": "remove",
|
||||
"path": "/events"
|
||||
|
|
@ -291,11 +296,11 @@
|
|||
"action_log_index": 2,
|
||||
"log": [
|
||||
[
|
||||
"Player1 played the action card Advance"
|
||||
"Player1 played the action card Advance for 1 culture token"
|
||||
],
|
||||
[
|
||||
"Player gained 1 mood token as advance bonus",
|
||||
"Player1 gained Storage for 1 culture token using the Advance action card."
|
||||
"Player1 gained Storage using the Advance action card."
|
||||
]
|
||||
],
|
||||
"undo_limit": 0,
|
||||
|
|
|
|||
|
|
@ -86,6 +86,9 @@
|
|||
"Mining"
|
||||
],
|
||||
"incident_tokens": 2,
|
||||
"action_cards": [
|
||||
19
|
||||
],
|
||||
"next_unit_id": 8
|
||||
},
|
||||
{
|
||||
|
|
|
|||
|
|
@ -87,6 +87,9 @@
|
|||
"Mining"
|
||||
],
|
||||
"incident_tokens": 2,
|
||||
"action_cards": [
|
||||
19
|
||||
],
|
||||
"next_unit_id": 8,
|
||||
"played_once_per_turn_actions": [
|
||||
"FreeEconomyCollect"
|
||||
|
|
@ -276,4 +279,4 @@
|
|||
"wonders_left": [
|
||||
"Pyramids"
|
||||
]
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@
|
|||
],
|
||||
"incident_tokens": 3,
|
||||
"wonder_cards": [
|
||||
"Great Gardens"
|
||||
"GreatGardens"
|
||||
],
|
||||
"next_unit_id": 10
|
||||
},
|
||||
|
|
|
|||
|
|
@ -120,7 +120,7 @@
|
|||
],
|
||||
"incident_tokens": 3,
|
||||
"wonder_cards": [
|
||||
"Great Gardens"
|
||||
"GreatGardens"
|
||||
],
|
||||
"next_unit_id": 10
|
||||
},
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@
|
|||
],
|
||||
"incident_tokens": 2,
|
||||
"wonder_cards": [
|
||||
"Great Gardens"
|
||||
"GreatGardens"
|
||||
],
|
||||
"next_unit_id": 10
|
||||
},
|
||||
|
|
|
|||
|
|
@ -182,7 +182,7 @@
|
|||
],
|
||||
"incident_tokens": 2,
|
||||
"wonder_cards": [
|
||||
"Great Gardens"
|
||||
"GreatGardens"
|
||||
],
|
||||
"next_unit_id": 10
|
||||
},
|
||||
|
|
|
|||
|
|
@ -124,7 +124,7 @@
|
|||
],
|
||||
"incident_tokens": 1,
|
||||
"wonder_cards": [
|
||||
"Great Gardens"
|
||||
"GreatGardens"
|
||||
],
|
||||
"next_unit_id": 10
|
||||
},
|
||||
|
|
|
|||
|
|
@ -108,7 +108,7 @@
|
|||
],
|
||||
"incident_tokens": 2,
|
||||
"wonder_cards": [
|
||||
"Great Gardens"
|
||||
"GreatGardens"
|
||||
],
|
||||
"next_unit_id": 10
|
||||
},
|
||||
|
|
|
|||
|
|
@ -366,7 +366,7 @@
|
|||
"Player1 started Sports at C2"
|
||||
],
|
||||
[
|
||||
"Player1 used Sports to increase the happiness of C2 by 1 steps, making it Neutral"
|
||||
"Player1 paid 1 culture token for Sports to increase the happiness of C2 by 1 steps, making it Neutral"
|
||||
]
|
||||
],
|
||||
"undo_limit": 0,
|
||||
|
|
|
|||