add missing advances, show unit/building descriptions, refactor custom actions, fix happiness cost (#219)

This commit is contained in:
Gregor Zeitlinger 2025-04-19 15:22:53 +02:00 • committed by GitHub
commit 6e62650d2c
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
54 changed files with 1940 additions and 665 deletions

Binary file not shown.

After

Width:  |  Height:  |  Size: 11 KiB

View file

@ -6,13 +6,10 @@ use crate::happiness_ui::open_increase_happiness_dialog;
use crate::influence_ui::new_cultural_influence_dialog;
use crate::layout_ui::{bottom_left_texture, icon_pos};
use crate::move_ui::MoveIntent;
use crate::payment_ui::Payment;
use crate::render_context::RenderContext;
use server::action::Action;
use server::city::City;
use server::content::advances::culture::{sports_options, theaters_options};
use server::content::advances::economy::tax_options;
use server::content::custom_actions::{CustomAction, CustomActionType};
use server::content::custom_actions::{CustomActionType, CustomEventAction};
use server::cultural_influence::available_influence_actions;
use server::happiness::available_happiness_actions;
use server::playing_actions::{PlayingAction, PlayingActionType, base_and_custom_action};
@ -61,22 +58,22 @@ pub fn action_buttons(rc: &RenderContext) -> StateUpdate {
});
}
let mut i = 0;
for (a, origin) in &game.available_custom_actions(rc.shown_player.index) {
if let Some(action) = generic_custom_action(rc, a, None) {
for (a, origin) in game.available_custom_actions(rc.shown_player.index) {
if let Some(action) = generic_custom_action(rc, a.clone(), None) {
if bottom_left_texture(
rc,
&assets.custom_actions[a],
&assets.custom_actions[&a],
icon_pos(i as i8, -1),
&event_help(rc, origin)[0],
&event_help(rc, &origin)[0],
) {
return action;
}
i += 1;
}
}
for (i, (icon, tooltip, action)) in custom_action_buttons(rc, None).iter().enumerate() {
if bottom_left_texture(rc, icon, icon_pos(i as i8, -1), tooltip) {
return action();
for (i, icon) in custom_action_buttons(rc, None).iter().enumerate() {
if bottom_left_texture(rc, icon.texture, icon_pos(i as i8, -1), &icon.tooltip) {
return (icon.action)();
}
}
StateUpdate::None
@ -90,13 +87,12 @@ pub fn custom_action_buttons<'a>(
.available_custom_actions(rc.shown_player.index)
.into_iter()
.filter_map(|(a, origin)| {
generic_custom_action(rc, &a, city).map(|action| {
let a: IconAction<'a> = (
generic_custom_action(rc, a.clone(), city).map(|action| {
IconAction::new(
&rc.assets().custom_actions[&a],
event_help(rc, &origin)[0].clone(),
Box::new(move || action.clone()),
);
a
)
})
})
.collect()
@ -117,45 +113,23 @@ fn global_move(rc: &RenderContext) -> StateUpdate {
fn generic_custom_action(
rc: &RenderContext,
custom_action_type: &CustomActionType,
custom_action_type: CustomActionType,
city: Option<&City>,
) -> Option<StateUpdate> {
if let Some(city) = city {
if matches!(custom_action_type, CustomActionType::Sports) {
if let Some(options) = sports_options(city) {
return Some(StateUpdate::OpenDialog(ActiveDialog::Sports((
Payment::new_gain(&options, "Increase happiness using sports"),
city.position,
))));
}
}
return None;
return custom_action_type
.is_available_city(rc.shown_player, city)
.then_some(StateUpdate::execute(Action::Playing(
PlayingAction::CustomEvent(CustomEventAction::new(
custom_action_type,
Some(city.position),
)),
)));
}
match custom_action_type {
CustomActionType::ArtsInfluenceCultureAttempt
| CustomActionType::VotingIncreaseHappiness
| CustomActionType::FreeEconomyCollect
| CustomActionType::Sports => {
// handled explicitly
None
}
CustomActionType::AbsolutePower => Some(StateUpdate::execute(Action::Playing(
PlayingAction::Custom(CustomAction::AbsolutePower),
))),
CustomActionType::ForcedLabor => Some(StateUpdate::execute(Action::Playing(
PlayingAction::Custom(CustomAction::ForcedLabor),
))),
CustomActionType::CivilLiberties => Some(StateUpdate::execute(Action::Playing(
PlayingAction::Custom(CustomAction::CivilLiberties),
))),
CustomActionType::Taxes => Some(StateUpdate::OpenDialog(ActiveDialog::Taxes(
Payment::new_gain(&tax_options(rc.shown_player), "Collect taxes"),
))),
CustomActionType::Theaters => Some(StateUpdate::OpenDialog(ActiveDialog::Theaters(
Payment::new_gain(&theaters_options(), "Convert Resources"),
))),
}
(!custom_action_type.is_city_bound()).then_some(StateUpdate::execute(Action::Playing(
PlayingAction::CustomEvent(CustomEventAction::new(custom_action_type, None)),
)))
}
pub fn base_or_custom_action(

View file

@ -1,9 +1,10 @@
use crate::city_ui::add_building_description;
use crate::client_state::{ActiveDialog, StateUpdate};
use crate::layout_ui::{left_mouse_button_pressed_in_rect, top_centered_text};
use crate::log_ui::break_text;
use crate::payment_ui::{Payment, payment_dialog};
use crate::render_context::RenderContext;
use crate::tooltip::show_tooltip_for_rect;
use crate::tooltip::{add_tooltip_description, show_tooltip_for_rect};
use crate::unit_ui::add_unit_description;
use macroquad::color::Color;
use macroquad::math::vec2;
use macroquad::prelude::{
@ -15,6 +16,7 @@ use server::content::advances;
use server::game::GameState;
use server::player::Player;
use server::playing_actions::PlayingAction;
use server::unit::UnitType;
use std::ops::Rem;
const COLUMNS: usize = 6;
@ -107,7 +109,7 @@ pub fn show_advance_menu(
);
} else {
// tooltip should be shown on top of everything
show_tooltip_for_rect(rc, &description(p, a), rect, 50.);
show_tooltip_for_rect(rc, &description(rc, a), rect, 50.);
if rc.can_control_shown_player()
&& matches!(
@ -144,13 +146,14 @@ fn border_color(a: &Advance) -> Color {
}
}
fn description(p: &Player, a: &Advance) -> Vec<String> {
let desc = &a.description;
fn description(rc: &RenderContext, a: &Advance) -> Vec<String> {
let mut parts: Vec<String> = vec![];
parts.push(a.name.clone());
break_text(desc, 70, &mut parts);
parts.push(format!("Cost: {}", p.advance_cost(a, None).cost));
add_tooltip_description(&mut parts, &a.description);
parts.push(format!(
"Cost: {}",
rc.shown_player.advance_cost(a, None).cost
));
if let Some(r) = &a.required {
parts.push(format!("Required: {r}"));
}
@ -169,8 +172,15 @@ fn description(p: &Player, a: &Advance) -> Vec<String> {
if let Some(g) = &a.government {
parts.push(format!("Government: {g}"));
}
if let Some(u) = &a.unlocked_building {
parts.push(format!("Unlocks: {}", u.name()));
if let Some(b) = &a.unlocked_building {
parts.push(format!("Unlocks building: {}", b.name()));
add_building_description(rc, &mut parts, *b);
}
if a.name == "Bartering" {
parts.push("Can build in a city with a Market: cavalry".to_string());
add_unit_description(&mut parts, UnitType::Cavalry);
parts.push("Can build in a city with a Market: elephant".to_string());
add_unit_description(&mut parts, UnitType::Elephant);
}
parts

View file

@ -261,6 +261,10 @@ impl Assets {
CustomActionType::CivilLiberties,
load_png(include_bytes!("../assets/justice-hammer-svgrepo-com.png")),
),
(
CustomActionType::Bartering,
load_png(include_bytes!("../assets/card-discard-svgrepo-com.png")),
),
(
CustomActionType::Taxes,
load_png(include_bytes!("../assets/tax-svgrepo-com.png")),

View file

@ -3,30 +3,59 @@ use crate::client_state::{ActiveDialog, StateUpdate};
use crate::collect_ui::CollectResources;
use crate::construct_ui::{ConstructionPayment, ConstructionProject};
use crate::custom_phase_ui::{SelectedStructureInfo, SelectedStructureStatus};
use crate::happiness_ui::{add_increase_happiness, open_increase_happiness_dialog};
use crate::happiness_ui::{
add_increase_happiness, available_happiness_actions_for_city, increase_happiness_cost,
open_increase_happiness_dialog,
};
use crate::hex_ui;
use crate::layout_ui::{draw_scaled_icon, is_in_circle};
use crate::layout_ui::{draw_scaled_icon, draw_scaled_icon_with_tooltip, is_in_circle};
use crate::map_ui::{move_units_buttons, show_map_action_buttons};
use crate::recruit_unit_ui::RecruitAmount;
use crate::render_context::RenderContext;
use crate::select_ui::HighlightType;
use crate::tooltip::show_tooltip_for_circle;
use crate::tooltip::{add_tooltip_description, show_tooltip_for_circle};
use itertools::Itertools;
use macroquad::math::f32;
use macroquad::prelude::*;
use server::city::{City, MoodState};
use server::city_pieces::Building;
use server::collect::{available_collect_actions_for_city, possible_resource_collections};
use server::construct::available_buildings;
use server::construct::{can_construct, new_building_positions};
use server::consts::BUILDING_COST;
use server::content::persistent_events::Structure;
use server::game::Game;
use server::happiness::{available_happiness_actions_for_city, increase_happiness_cost};
use server::playing_actions::PlayingActionType;
use server::resource::ResourceType;
use server::unit::{UnitType, Units};
use std::ops::Add;
pub type IconAction<'a> = (&'a Texture2D, String, Box<dyn Fn() -> StateUpdate + 'a>);
pub struct IconAction<'a> {
pub texture: &'a Texture2D,
pub tooltip: String,
pub warning: bool,
pub action: Box<dyn Fn() -> StateUpdate + 'a>,
}
impl<'a> IconAction<'a> {
#[must_use]
pub fn new(
texture: &'a Texture2D,
tooltip: String,
action: Box<dyn Fn() -> StateUpdate + 'a>,
) -> IconAction<'a> {
IconAction {
texture,
tooltip,
warning: false,
action,
}
}
#[must_use]
pub fn with_warning(self, warning: bool) -> IconAction<'a> {
IconAction { warning, ..self }
}
}
pub type IconActionVec<'a> = Vec<IconAction<'a>>;
@ -63,7 +92,7 @@ fn increase_happiness_button<'a>(rc: &'a RenderContext, city: &'a City) -> Optio
return None;
}
Some((
Some(IconAction::new(
&rc.assets().resources[&ResourceType::MoodTokens],
"Increase happiness".to_string(),
Box::new(move || {
@ -84,37 +113,56 @@ fn building_icons<'a>(rc: &'a RenderContext, city: &'a City) -> IconActionVec<'a
if !city.can_activate() || !rc.can_play_action(&PlayingActionType::Construct) {
return vec![];
}
available_buildings(rc.game, rc.shown_player.index, city.position)
let game = rc.game;
Building::all()
.into_iter()
.map(|(b, cost_info, pos)| {
.flat_map(|b| {
let can = can_construct(city, b, rc.shown_player, game);
new_building_positions(game, b, city)
.into_iter()
.map(|pos| (b, can.clone(), pos))
.collect_vec()
})
.map(|(b, can, pos)| {
let name = b.name();
let warn = can.is_err();
let suffix = match &can {
Ok(c) => format!(
" for {}{}",
c.cost,
if c.activate_city {
""
} else {
" (without city activation)"
}
),
Err(e) => format!(" ({e})"),
};
let tooltip = format!(
"Built {}{} for {}{}",
"Built {}{}{}",
name,
pos.map_or(String::new(), |p| format!(" at {p}")),
cost_info.cost,
if cost_info.activate_city {
""
} else {
" (without city activation)"
}
suffix
);
let a: IconAction<'a> = (
IconAction::new(
&rc.assets().buildings[&b],
tooltip,
Box::new(move || {
StateUpdate::OpenDialog(ActiveDialog::ConstructionPayment(
ConstructionPayment::new(
rc,
city,
name,
ConstructionProject::Building(b, pos),
&cost_info,
),
))
can.clone().map_or(StateUpdate::None, |cost_info| {
StateUpdate::OpenDialog(ActiveDialog::ConstructionPayment(
ConstructionPayment::new(
rc,
city,
name,
ConstructionProject::Building(b, pos),
&cost_info,
),
))
})
}),
);
a
)
.with_warning(warn)
})
.collect()
}
@ -123,7 +171,7 @@ fn recruit_button<'a>(rc: &'a RenderContext, city: &'a City) -> Option<IconActio
if !city.can_activate() || !rc.can_play_action(&PlayingActionType::Recruit) {
return None;
}
Some((
Some(IconAction::new(
rc.assets().unit(UnitType::Infantry, rc.shown_player),
"Recruit Units".to_string(),
Box::new(|| {
@ -133,7 +181,6 @@ fn recruit_button<'a>(rc: &'a RenderContext, city: &'a City) -> Option<IconActio
city.position,
Units::empty(),
None,
&[],
)
}),
))
@ -145,7 +192,7 @@ fn collect_resources_button<'a>(rc: &'a RenderContext, city: &'a City) -> Option
return None;
}
Some((
Some(IconAction::new(
&rc.assets().resources[&ResourceType::Food],
"Collect Resources".to_string(),
Box::new(move || {
@ -220,7 +267,7 @@ fn draw_selected_state(
draw_circle_lines(center.x, center.y, size, 3., t.color());
if let Some(tooltip) = &info.tooltip {
show_tooltip_for_circle(rc, tooltip, center, size);
show_tooltip_for_circle(rc, &[tooltip.clone()], center, size);
}
if info.status != SelectedStructureStatus::Invalid
@ -311,10 +358,13 @@ fn draw_buildings(
let p = building_position(city, center, i, *b);
draw_circle(p.x, p.y, BUILDING_SIZE, rc.player_color(player_index));
draw_scaled_icon(
let mut tooltip = vec![b.name().to_string()];
add_building_description(rc, &mut tooltip, *b);
draw_scaled_icon_with_tooltip(
rc,
&rc.assets().buildings[b],
b.name(),
&tooltip,
p + vec2(-8., -8.),
16.,
);
@ -333,6 +383,22 @@ fn draw_buildings(
None
}
pub fn add_building_description(rc: &RenderContext, parts: &mut Vec<String>, b: Building) {
let pile = rc
.shown_player
.building_cost(rc.game, b, None)
.cost
.first_valid_payment(&BUILDING_COST)
.expect("Building cost should be valid");
if pile == BUILDING_COST {
parts.push(format!("Cost: {BUILDING_COST}"));
} else {
parts.push(format!("Base cost: {BUILDING_COST}"));
parts.push(format!("Current cost: {pile}"));
}
add_tooltip_description(parts, b.description());
}
#[allow(clippy::result_large_err)]
fn draw_wonders(
rc: &RenderContext,

View file

@ -25,8 +25,8 @@ use crate::player_ui::{player_select, show_global_controls, show_top_center, sho
use crate::render_context::RenderContext;
use crate::unit_ui::unit_selection_click;
use crate::{
cards_ui, custom_actions_ui, custom_phase_ui, dialog_ui, map_ui, move_ui, recruit_unit_ui,
status_phase_ui, tooltip,
cards_ui, custom_phase_ui, dialog_ui, map_ui, move_ui, recruit_unit_ui, status_phase_ui,
tooltip,
};
fn render_with_mutable_state(game: &Game, state: &mut State, features: &Features) -> StateUpdate {
@ -167,10 +167,6 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
ActiveDialog::ChooseAdditionalAdvances(a) => {
status_phase_ui::choose_additional_advances_dialog(rc, a)
}
ActiveDialog::Sports((p, pos)) => custom_actions_ui::sports(rc, p, *pos),
ActiveDialog::Taxes(p) => custom_actions_ui::taxes(rc, p),
ActiveDialog::Theaters(p) => custom_actions_ui::theaters(rc, p),
ActiveDialog::PaymentRequest(c) => custom_phase_ui::custom_phase_payment_dialog(rc, c),
ActiveDialog::PlayerRequest(r) => custom_phase_ui::player_request_dialog(rc, r),
ActiveDialog::ResourceRewardRequest(p) => custom_phase_ui::payment_reward_dialog(rc, p),

View file

@ -23,7 +23,6 @@ use server::content::persistent_events::{
AdvanceRequest, ChangeGovernmentRequest, EventResponse, MultiRequest, PersistentEventRequest,
PersistentEventType, PlayerRequest, UnitTypeRequest,
};
use server::events::EventOrigin;
use server::game::{Game, GameState};
use server::movement::CurrentMove;
use server::playing_actions::PlayingActionType;
@ -49,9 +48,6 @@ pub enum ActiveDialog {
ExploreResolution(ExploreResolutionConfig),
// custom
Sports((Payment, Position)),
Theaters(Payment),
Taxes(Payment),
ResourceRewardRequest(Payment),
AdvanceRequest(AdvanceRequest),
PaymentRequest(Vec<Payment>),
@ -89,9 +85,6 @@ impl ActiveDialog {
ActiveDialog::ExploreResolution(_) => "explore resolution",
ActiveDialog::ChangeGovernmentType(_) => "change government type",
ActiveDialog::ChooseAdditionalAdvances(_) => "choose additional advances",
ActiveDialog::Sports(_) => "sports",
ActiveDialog::Theaters(_) => "theaters",
ActiveDialog::Taxes(_) => "collect taxes",
ActiveDialog::ResourceRewardRequest(_) => "trade route selection",
ActiveDialog::AdvanceRequest(_) => "advance selection",
ActiveDialog::PaymentRequest(_) => "custom phase payment request",
@ -139,11 +132,6 @@ impl ActiveDialog {
vec!["Click on an advance to choose it".to_string()]
}
ActiveDialog::WaitingForUpdate => vec!["Waiting for server update".to_string()],
ActiveDialog::Sports(_) => event_help(rc, &EventOrigin::Advance("Sports".to_string())),
ActiveDialog::Taxes(_) => event_help(rc, &EventOrigin::Advance("Taxes".to_string())),
ActiveDialog::Theaters(_) => {
event_help(rc, &EventOrigin::Advance("Theaters".to_string()))
}
ActiveDialog::ResourceRewardRequest(_)
| ActiveDialog::AdvanceRequest(_)
| ActiveDialog::PaymentRequest(_) => event_help(rc, &custom_phase_event_origin(rc)),

View file

@ -1,52 +0,0 @@
use crate::client_state::{ActiveDialog, StateUpdate};
use crate::payment_ui::{Payment, payment_dialog};
use crate::render_context::RenderContext;
use server::action::Action;
use server::content::custom_actions::CustomAction;
use server::playing_actions::PlayingAction;
use server::position::Position;
pub fn sports(rc: &RenderContext, payment: &Payment, pos: Position) -> StateUpdate {
payment_dialog(
rc,
payment,
false,
|p| ActiveDialog::Sports((p.clone(), pos)),
|p| {
StateUpdate::Execute(Action::Playing(PlayingAction::Custom(
CustomAction::Sports {
city_position: pos,
payment: p,
},
)))
},
)
}
pub fn taxes(rc: &RenderContext, payment: &Payment) -> StateUpdate {
payment_dialog(
rc,
payment,
false,
|p| ActiveDialog::Taxes(p.clone()),
|p| {
StateUpdate::Execute(Action::Playing(PlayingAction::Custom(CustomAction::Taxes(
p,
))))
},
)
}
pub fn theaters(rc: &RenderContext, payment: &Payment) -> StateUpdate {
payment_dialog(
rc,
payment,
false,
|p| ActiveDialog::Theaters(p.clone()),
|p| {
StateUpdate::Execute(Action::Playing(PlayingAction::Custom(
CustomAction::Theaters(p),
)))
},
)
}

View file

@ -6,8 +6,8 @@ use crate::payment_ui::{Payment, multi_payment_dialog, payment_dialog};
use crate::player_ui::choose_player_dialog;
use crate::render_context::RenderContext;
use crate::select_ui::HighlightType;
use crate::unit_ui;
use crate::unit_ui::{UnitSelection, draw_unit_type};
use crate::tooltip::show_tooltip_for_circle;
use crate::unit_ui::{UnitSelection, add_unit_description, draw_unit_type};
use itertools::Itertools;
use macroquad::math::vec2;
use server::action::Action;
@ -68,23 +68,24 @@ pub fn unit_request_dialog(rc: &RenderContext, r: &UnitTypeRequest) -> StateUpda
let c = &r.choices;
let anchor = bottom_center_anchor(rc) + vec2(0., 60.);
for (i, u) in c.iter().enumerate() {
let x = (c.len() - i) as i8 - 1;
let p = icon_pos(x, -2) + anchor;
for pass in 0..2 {
for (i, u) in c.iter().enumerate() {
let x = (c.len() - i) as i8 - 1;
let center = icon_pos(x, -2) + anchor;
if draw_unit_type(
rc,
HighlightType::None,
p,
*u,
r.player_index,
unit_ui::name(u),
20.,
) {
return StateUpdate::Execute(Action::Response(EventResponse::SelectUnitType(*u)));
if pass == 0 {
if draw_unit_type(rc, HighlightType::None, center, *u, r.player_index, 20.) {
return StateUpdate::Execute(Action::Response(EventResponse::SelectUnitType(
*u,
)));
}
} else {
let mut tooltip = vec![u.name().to_string()];
add_unit_description(&mut tooltip, *u);
show_tooltip_for_circle(rc, &tooltip, center, 20.);
}
}
}
StateUpdate::None
}

View file

@ -3,9 +3,11 @@ use crate::client_state::{ActiveDialog, StateUpdate};
use crate::dialog_ui::BaseOrCustomDialog;
use crate::payment_ui::{Payment, payment_dialog};
use crate::render_context::RenderContext;
use server::city::City;
use server::happiness::{happiness_action, happiness_cost_for_all_cities, increase_happiness_cost};
use server::city::{City, MoodState};
use server::game::Game;
use server::happiness::{available_happiness_actions, happiness_action, happiness_cost};
use server::player::Player;
use server::player_events::CostInfo;
use server::playing_actions::{IncreaseHappiness, PlayingActionType};
use server::position::Position;
@ -21,7 +23,7 @@ impl IncreaseHappinessConfig {
let steps = p.cities.iter().map(|c| (c.position, 0)).collect();
IncreaseHappinessConfig {
steps,
payment: Self::happiness_payment(p, &[(p.cities[0].position, 0)], &custom)
payment: Self::happiness_payment(p, 0, &custom)
.expect("Happiness payment should be available"),
custom,
}
@ -29,17 +31,17 @@ impl IncreaseHappinessConfig {
fn happiness_payment(
p: &Player,
new_steps: &[(Position, u32)],
new_steps: u32,
custom: &BaseOrCustomDialog,
) -> Option<Payment> {
happiness_cost_for_all_cities(p, new_steps, &custom.action_type).map(|cost| {
Payment::new(
&cost,
let c = happiness_cost(p, new_steps, None).cost;
c.can_afford(&custom.action_type.remaining_resources(p))
.then_some(Payment::new(
&c,
&custom.action_type.remaining_resources(p),
"Increase happiness",
false,
)
})
))
}
}
@ -94,9 +96,14 @@ pub fn add_increase_happiness(
})
.collect();
let step_sum = new_steps
.iter()
.map(|(p, steps)| rc.shown_player.get_city(*p).size() as u32 * steps)
.sum::<u32>();
IncreaseHappinessConfig::happiness_payment(
rc.shown_player,
&new_steps,
step_sum,
&increase_happiness.custom,
)
.map(|payment| {
@ -130,6 +137,36 @@ fn increase_happiness_new_steps(
increase_happiness_cost(rc.shown_player, city, new_steps, action_type).map(|_| new_steps)
}
#[must_use]
pub fn increase_happiness_cost(
player: &Player,
city: &City,
steps: u32,
action_type: &PlayingActionType,
) -> Option<CostInfo> {
let total_cost = happiness_cost(player, steps * city.size() as u32, None);
let max_steps = 2 - city.mood_state.clone() as u32;
(total_cost
.cost
.can_afford(&action_type.remaining_resources(player))
&& steps <= max_steps)
.then_some(total_cost)
}
#[must_use]
pub fn available_happiness_actions_for_city(
game: &Game,
player: usize,
position: Position,
) -> Vec<PlayingActionType> {
let city = game.player(player).get_city(position);
if city.can_activate() && city.mood_state != MoodState::Happy {
available_happiness_actions(game, player)
} else {
vec![]
}
}
pub fn increase_happiness_menu(rc: &RenderContext, h: &IncreaseHappinessConfig) -> StateUpdate {
payment_dialog(
rc,

View file

@ -100,6 +100,24 @@ pub fn draw_scaled_icon(
tooltip: &str,
origin: Vec2,
size: f32,
) -> bool {
let t = if tooltip.is_empty() {
vec![]
} else {
let mut parts: Vec<String> = vec![];
break_text(tooltip, 70, &mut parts);
parts
};
draw_scaled_icon_with_tooltip(rc, texture, &t, origin, size)
}
pub fn draw_scaled_icon_with_tooltip(
rc: &RenderContext,
texture: &Texture2D,
tooltip: &[String],
origin: Vec2,
size: f32,
) -> bool {
draw_texture_ex(
texture,
@ -114,9 +132,7 @@ pub fn draw_scaled_icon(
let rect = Rect::new(origin.x, origin.y, size, size);
if !tooltip.is_empty() {
let mut parts: Vec<String> = vec![];
break_text(tooltip, 70, &mut parts);
tooltip::show_tooltip_for_rect(rc, &parts, rect, 50.);
tooltip::show_tooltip_for_rect(rc, tooltip, rect, 50.);
}
left_mouse_button_pressed_in_rect(rect, rc)
}

View file

@ -18,7 +18,6 @@ pub mod client;
pub mod client_state;
mod collect_ui;
mod construct_ui;
mod custom_actions_ui;
mod custom_phase_ui;
mod dialog_ui;
mod event_ui;

View file

@ -1,11 +1,14 @@
use crate::city_ui::{IconAction, IconActionVec, draw_city, show_city_menu};
use crate::client_state::{ActiveDialog, MAX_OFFSET, MIN_OFFSET, State, StateUpdate, ZOOM};
use crate::dialog_ui::{OkTooltip, cancel_button_pos, ok_button};
use crate::layout_ui::{bottom_center_texture, bottom_right_texture, icon_pos};
use crate::layout_ui::{
bottom_center_anchor, bottom_center_texture, bottom_right_texture, icon_pos,
};
use crate::move_ui::{MoveDestination, MoveIntent, movable_units};
use crate::player_ui::get_combat;
use crate::render_context::RenderContext;
use crate::select_ui::HighlightType;
use crate::tooltip::show_tooltip_for_circle;
use crate::{collect_ui, hex_ui, unit_ui};
use macroquad::math::{f32, vec2};
use macroquad::prelude::*;
@ -234,7 +237,7 @@ fn found_city_button<'a>(rc: &'a RenderContext<'a>, pos: Position) -> Option<Ico
unit_ui::units_on_tile(game, pos)
.find(|(_, unit)| unit.can_found_city(game))
.map(|(_index, unit)| {
let action: IconAction<'a> = (
IconAction::new(
rc.assets().unit(UnitType::Settler, rc.shown_player),
"Found a new city".to_string(),
Box::new(move || {
@ -242,8 +245,7 @@ fn found_city_button<'a>(rc: &'a RenderContext<'a>, pos: Position) -> Option<Ico
settler: unit.id,
}))
}),
);
action
)
})
}
@ -257,7 +259,7 @@ pub fn move_units_button<'a>(
{
return None;
}
Some((
Some(IconAction::new(
move_intent.icon(rc),
move_intent.toolip().to_string(),
Box::new(move || StateUpdate::move_units(rc, Some(pos), move_intent)),
@ -279,14 +281,21 @@ pub fn move_units_buttons<'a>(rc: &'a RenderContext, pos: Position) -> Vec<IconA
}
pub fn show_map_action_buttons(rc: &RenderContext, icons: &IconActionVec) -> StateUpdate {
for (i, (icon, tooltip, action)) in icons.iter().enumerate() {
if bottom_center_texture(
rc,
icon,
icon_pos(-(icons.len() as i8) / 2 + i as i8, -1),
tooltip,
) {
return action();
for pass in 0..2 {
for (i, icon) in icons.iter().enumerate() {
let p = icon_pos(-(icons.len() as i8) / 2 + i as i8, -1);
let center = bottom_center_anchor(rc) + p + vec2(15., 15.);
let radius = 20.;
if pass == 0 {
if icon.warning {
draw_circle(center.x, center.y, radius, RED);
}
if bottom_center_texture(rc, icon.texture, p, "") {
return (icon.action)();
}
} else {
show_tooltip_for_circle(rc, &[icon.tooltip.clone()], center, radius);
}
}
}
StateUpdate::None

View file

@ -1,11 +1,14 @@
use crate::client_state::{ActiveDialog, StateUpdate};
use crate::dialog_ui::OkTooltip;
use crate::event_ui::event_help;
use crate::layout_ui::{bottom_centered_text_with_offset, draw_icon};
use crate::layout_ui::{
ICON_SIZE, bottom_centered_text_with_offset, draw_scaled_icon_with_tooltip,
};
use crate::render_context::RenderContext;
use crate::resource_ui::{new_resource_map, resource_name};
use crate::select_ui;
use crate::select_ui::{CountSelector, HasCountSelectableObject};
use crate::tooltip::show_tooltip_for_circle;
use macroquad::math::{bool, vec2};
use server::payment::PaymentOptions;
use server::resource::ResourceType;
@ -158,11 +161,20 @@ pub fn multi_payment_dialog(
payment,
|p| p.current.clone(),
|s, p| {
let _ = draw_icon(
let _ = draw_scaled_icon_with_tooltip(
rc,
&rc.assets().resources[&s.resource],
resource_name(s.resource),
&[],
p + vec2(0., -10.),
ICON_SIZE,
);
},
|s, p| {
show_tooltip_for_circle(
rc,
&[resource_name(s.resource).to_string()],
p + vec2(0., -10.),
ICON_SIZE,
);
},
|| tooltip.clone(),

View file

@ -3,6 +3,7 @@ use macroquad::prelude::*;
use server::game::Game;
use server::player::Player;
use server::player_events::CostInfo;
use server::position::Position;
use server::recruit::{recruit_cost, recruit_cost_without_replaced};
use server::unit::{Unit, UnitType, Units};
@ -13,14 +14,15 @@ use crate::dialog_ui::{OkTooltip, cancel_button, ok_button};
use crate::render_context::RenderContext;
use crate::select_ui;
use crate::select_ui::{CountSelector, HasCountSelectableObject, HighlightType};
use crate::unit_ui::{UnitSelection, draw_unit_type};
use crate::tooltip::show_tooltip_for_circle;
use crate::unit_ui::{UnitSelection, add_unit_description, draw_unit_type};
#[derive(Clone)]
pub struct SelectableUnit {
pub unit_type: UnitType,
pub selectable: CountSelector,
name: String,
leader_name: Option<String>,
cost: Result<CostInfo, String>,
}
#[derive(Clone)]
@ -45,21 +47,11 @@ impl RecruitAmount {
city_position: Position,
units: Units,
leader_name: Option<&String>,
must_show_units: &[SelectableUnit],
) -> StateUpdate {
let player = game.player(player_index);
let selectable: Vec<SelectableUnit> = new_units(player)
.into_iter()
.filter_map(|u| {
selectable_unit(
city_position,
&units,
leader_name,
must_show_units,
player,
&u,
)
})
.map(|u| selectable_unit(city_position, &units, leader_name, player, &u))
.collect();
StateUpdate::OpenDialog(ActiveDialog::RecruitUnitSelection(RecruitAmount {
@ -76,10 +68,9 @@ fn selectable_unit(
city_position: Position,
units: &Units,
leader_name: Option<&String>,
must_show_units: &[SelectableUnit],
player: &Player,
unit: &NewUnit,
) -> Option<SelectableUnit> {
) -> SelectableUnit {
let mut all = units.clone();
all += &unit.unit_type;
@ -89,50 +80,39 @@ fn selectable_unit(
units.get(&unit.unit_type)
};
let max = if recruit_cost_without_replaced(
let cost = recruit_cost_without_replaced(
player,
&all,
city_position,
unit.leader_name.as_ref().or(leader_name),
None,
)
.is_ok()
{
);
let max = if cost.is_ok() {
u32::from(current + 1)
} else {
u32::from(current)
};
if max == 0
&& !must_show_units
.iter()
.any(|u| u.unit_type == unit.unit_type)
{
None
} else {
Some(SelectableUnit {
name: unit.name.to_string(),
unit_type: unit.unit_type,
selectable: CountSelector {
current: u32::from(current),
min: 0,
max,
},
leader_name: unit.leader_name.clone(),
})
SelectableUnit {
unit_type: unit.unit_type,
cost,
selectable: CountSelector {
current: u32::from(current),
min: 0,
max,
},
leader_name: unit.leader_name.clone(),
}
}
struct NewUnit {
unit_type: UnitType,
name: String,
leader_name: Option<String>,
}
impl NewUnit {
fn new(unit_type: UnitType, name: &str, leader_name: Option<String>) -> NewUnit {
fn new(unit_type: UnitType, leader_name: Option<String>) -> NewUnit {
NewUnit {
unit_type,
name: name.to_string(),
leader_name,
}
}
@ -146,10 +126,10 @@ fn new_units(player: &Player) -> Vec<NewUnit> {
player
.available_leaders
.iter()
.map(|l| NewUnit::new(UnitType::Leader, l.as_str(), Some(l.to_string())))
.map(|l| NewUnit::new(UnitType::Leader, Some(l.to_string())))
.collect_vec()
} else {
vec![NewUnit::new(u, u.name(), None::<String>)]
vec![NewUnit::new(u, None::<String>)]
}
})
.collect()
@ -219,6 +199,7 @@ impl UnitSelection for RecruitSelection {
pub fn select_dialog(rc: &RenderContext, a: &RecruitAmount) -> StateUpdate {
let game = rc.game;
let radius = 20.;
select_ui::count_dialog(
rc,
a,
@ -226,17 +207,30 @@ pub fn select_dialog(rc: &RenderContext, a: &RecruitAmount) -> StateUpdate {
|s, p| {
draw_unit_type(
rc,
HighlightType::None,
if s.cost.is_ok() {
HighlightType::None
} else {
HighlightType::Warn
},
p,
s.unit_type,
rc.shown_player.index,
&format!(
"{} ({} available with current resources)",
s.name, s.selectable.max
),
20.,
radius,
);
},
|s, p| {
let suffix = match &s.cost {
Ok(_) => format!(" ({} available with current resources)", s.selectable.max),
Err(e) => format!(" ({e})"),
};
let name = match s.leader_name.as_ref() {
None => s.unit_type.name().to_string(),
Some(n) => n.to_string(),
};
let mut tooltip = vec![format!("Recruit {}{}", name, suffix)];
add_unit_description(&mut tooltip, s.unit_type);
show_tooltip_for_circle(rc, &tooltip, p, radius);
},
|| OkTooltip::Valid("Recruit units".to_string()),
|| {
let sel = RecruitSelection::new(game, rc.shown_player.index, a.clone(), vec![]);
@ -311,14 +305,7 @@ fn update_selection(
units: Units,
leader_name: Option<&String>,
) -> StateUpdate {
RecruitAmount::new_selection(
game,
s.player_index,
s.city_position,
units,
leader_name,
s.selectable.as_slice(),
)
RecruitAmount::new_selection(game, s.player_index, s.city_position, units, leader_name)
}
pub fn replace_dialog(rc: &RenderContext, sel: &RecruitSelection) -> StateUpdate {

View file

@ -23,6 +23,7 @@ pub fn count_dialog<C, O: HasCountSelectableObject>(
container: &C,
get_objects: impl Fn(&C) -> Vec<O>,
draw: impl Fn(&O, Vec2),
draw_tooltip: impl Fn(&O, Vec2),
is_valid: impl FnOnce() -> OkTooltip,
execute_action: impl FnOnce() -> StateUpdate,
show: impl Fn(&C, &O) -> bool,
@ -37,37 +38,44 @@ pub fn count_dialog<C, O: HasCountSelectableObject>(
.collect::<Vec<_>>();
let start_x = objects.len() as f32 * -1. / 2.;
let anchor = bottom_center_anchor(rc);
for (i, o) in objects.iter().enumerate() {
let x = (start_x + i as f32) * ICON_SIZE * 2.;
let c = o.counter();
for pass in 0..2 {
for (i, o) in objects.iter().enumerate() {
let x = (start_x + i as f32) * ICON_SIZE * 2.;
let c = o.counter();
draw(o, vec2(x + 7., -60.) + anchor + offset);
let current_pos = vec2(x + 13., -ICON_SIZE) + anchor + offset;
rc.state.draw_text_with_color(
&format!("{}", c.current),
current_pos.x,
current_pos.y,
BLACK,
);
if c.current > c.min
&& bottom_center_texture(
rc,
&rc.assets().minus,
vec2(x - 15., -ICON_SIZE) + offset,
"Remove one",
)
{
return minus(container, o);
}
if c.current < c.max
&& bottom_center_texture(
rc,
&rc.assets().plus,
vec2(x + 15., -ICON_SIZE) + offset,
"Add one",
)
{
return plus(container, o);
let point = vec2(x + 7., -60.) + anchor + offset;
if pass == 0 {
draw(o, point);
let current_pos = vec2(x + 13., -ICON_SIZE) + anchor + offset;
rc.state.draw_text_with_color(
&format!("{}", c.current),
current_pos.x,
current_pos.y,
BLACK,
);
if c.current > c.min
&& bottom_center_texture(
rc,
&rc.assets().minus,
vec2(x - 15., -ICON_SIZE) + offset,
"Remove one",
)
{
return minus(container, o);
}
if c.current < c.max
&& bottom_center_texture(
rc,
&rc.assets().plus,
vec2(x + 15., -ICON_SIZE) + offset,
"Add one",
)
{
return plus(container, o);
}
} else {
draw_tooltip(o, point);
}
}
}
@ -81,7 +89,7 @@ pub fn count_dialog<C, O: HasCountSelectableObject>(
StateUpdate::None
}
#[derive(Clone, Copy)]
#[derive(Clone, Copy, PartialEq, Eq, Debug)]
pub enum HighlightType {
None,
Primary,

View file

@ -1,4 +1,5 @@
use crate::client_state::{CameraMode, MousePosition, State, StateUpdate};
use crate::log_ui::break_text;
use crate::render_context::RenderContext;
use macroquad::color::{Color, GRAY};
use macroquad::input::mouse_position;
@ -55,17 +56,12 @@ fn is_circle_tooltip_active(rc: &RenderContext, center: Vec2, radius: f32) -> bo
.all(|mp| (center - rc.screen_to_world(mp.position)).length() < radius)
}
pub fn show_tooltip_for_circle(rc: &RenderContext, tooltip: &str, center: Vec2, radius: f32) {
pub fn show_tooltip_for_circle(rc: &RenderContext, tooltip: &[String], center: Vec2, radius: f32) {
let screen_center = rc.world_to_screen(center);
if is_circle_tooltip_active(rc, center, radius) {
draw_circle(center.x, center.y, radius, Color::new(0.0, 0.0, 0.0, 0.5));
let _ = rc.with_camera(CameraMode::Screen, |rc| {
show_tooltip_text(
rc,
&[tooltip.to_string()],
screen_center + vec2(radius, radius),
50.,
);
show_tooltip_text(rc, tooltip, screen_center + vec2(radius, radius), 50.);
StateUpdate::None
});
}
@ -82,9 +78,15 @@ fn show_tooltip_text(rc: &RenderContext, tooltip: &[String], origin: Vec2, right
let w = tooltip_rect.size().x + 10.;
let sx = state.screen_size.x - right_offset;
let x = tooltip_rect.left().min(sx - w);
let y = (tooltip_rect.top() - 10.).max(40.);
let y = (tooltip_rect.top() - 10.)
.max(40.)
.min(state.screen_size.y - tooltip_rect.h - 40.);
draw_rectangle(x, y, w, tooltip_rect.size().y + 10., GRAY);
for (i, line) in tooltip.iter().enumerate() {
state.draw_text(line, x + 5., y + 20. + i as f32 * 20.);
}
}
pub fn add_tooltip_description(parts: &mut Vec<String>, label: &str) {
break_text(label, 70, parts);
}

View file

@ -9,10 +9,10 @@ use crate::client_state::{ActiveDialog, StateUpdate};
use crate::hex_ui;
use crate::select_ui::HighlightType;
use crate::layout_ui::{draw_scaled_icon, is_in_circle};
use crate::layout_ui::{draw_scaled_icon_with_tooltip, is_in_circle};
use crate::move_ui::MoveDestination;
use crate::render_context::RenderContext;
use crate::tooltip::show_tooltip_for_circle;
use crate::tooltip::{add_tooltip_description, show_tooltip_for_circle};
use itertools::Itertools;
use server::consts::ARMY_MOVEMENT_REQUIRED_ADVANCE;
use server::movement::MovementRestriction;
@ -41,16 +41,26 @@ pub fn draw_unit_type(
center: Vec2,
unit_type: UnitType,
player_index: usize,
tooltip: &str,
size: f32,
radius: f32,
) -> bool {
draw_circle(center.x, center.y, size, unit_highlight_type.color());
draw_circle(center.x, center.y, size - 2., rc.player_color(player_index));
let icon_size = size * 1.1;
draw_scaled_icon(
let r = if unit_highlight_type == HighlightType::None {
radius
} else {
radius + 2.
};
draw_circle(center.x, center.y, r, unit_highlight_type.color());
draw_circle(
center.x,
center.y,
radius - 2.,
rc.player_color(player_index),
);
let icon_size = radius * 1.1;
draw_scaled_icon_with_tooltip(
rc,
rc.assets().unit(unit_type, rc.game.player(player_index)),
tooltip,
&[],
vec2(center.x - icon_size / 2., center.y - icon_size / 2.),
icon_size,
)
@ -203,7 +213,7 @@ fn highlight_units(
fn draw_unit(
rc: &RenderContext,
tooltip: bool,
draw_tooltip: bool,
selected_units: &[UnitHighlight],
player_index: usize,
unit: &Unit,
@ -212,11 +222,13 @@ fn draw_unit(
let center = place.center;
let radius = place.radius;
let game = &rc.game;
if tooltip {
if draw_tooltip {
let army_move = game
.player(player_index)
.has_advance(ARMY_MOVEMENT_REQUIRED_ADVANCE);
show_tooltip_for_circle(rc, &unit_label(unit, army_move), center, radius);
let mut tooltip = vec![unit_label(unit, army_move)];
add_unit_description(&mut tooltip, unit.unit_type);
show_tooltip_for_circle(rc, &tooltip, center, radius);
} else {
let highlight = selected_units
.iter()
@ -229,7 +241,6 @@ fn draw_unit(
center,
unit.unit_type,
unit.player_index,
"",
radius,
);
}
@ -316,3 +327,8 @@ pub fn unit_selection_clicked(unit_id: u32, units: &mut Vec<u32>) {
units.push(unit_id);
}
}
pub fn add_unit_description(parts: &mut Vec<String>, u: UnitType) {
parts.push(format!("Cost: {}", u.cost()));
add_tooltip_description(parts, &u.description());
}

View file

@ -7,6 +7,7 @@ use crate::combat::{
};
use crate::combat_listeners::{combat_round_end, combat_round_start, end_combat};
use crate::construct::on_construct;
use crate::content::custom_actions::execute_custom_action;
use crate::content::persistent_events::{EventResponse, PersistentEventType};
use crate::cultural_influence::ask_for_cultural_influence_payment;
use crate::explore::{ask_explore_resolution, move_to_unexplored_tile};
@ -223,6 +224,7 @@ pub(crate) fn execute_custom_phase_action(
SelectObjectives(c) => {
on_objective_cards(game, player_index, c);
}
CustomAction(a) => execute_custom_action(game, player_index, a),
}
if let Some(s) = game.events.pop() {

View file

@ -2,10 +2,9 @@ use crate::action::{Action, ActionType};
use crate::card::validate_card_selection;
use crate::city::{City, MoodState};
use crate::collect::{available_collect_actions, collect_action};
use crate::construct::{Construct, available_buildings};
use crate::construct::{Construct, available_buildings, new_building_positions};
use crate::content::advances;
use crate::content::advances::economy::tax_options;
use crate::content::custom_actions::{CustomAction, CustomActionType};
use crate::content::custom_actions::CustomEventAction;
use crate::content::persistent_events::{
ChangeGovernmentRequest, EventResponse, HandCardsRequest, MultiRequest, PersistentEventRequest,
PersistentEventState, PositionRequest, SelectedStructure, is_selected_structures_valid,
@ -15,9 +14,7 @@ use crate::cultural_influence::{
};
use crate::events::EventOrigin;
use crate::game::Game;
use crate::happiness::{
available_happiness_actions, happiness_action, happiness_cost_for_all_cities,
};
use crate::happiness::{available_happiness_actions, happiness_action, happiness_cost};
use crate::payment::PaymentOptions;
use crate::player::Player;
use crate::playing_actions::{
@ -149,21 +146,21 @@ fn base_actions(game: &Game) -> Vec<(ActionType, Vec<Action>)> {
}
for (a, _) in game.available_custom_actions(p.index) {
let option = match a {
CustomActionType::Sports | CustomActionType::Theaters | // todo
CustomActionType::ArtsInfluenceCultureAttempt
| CustomActionType::VotingIncreaseHappiness
| CustomActionType::FreeEconomyCollect => None, // handled above
CustomActionType::AbsolutePower => Some(CustomAction::AbsolutePower),
CustomActionType::ForcedLabor => Some(CustomAction::ForcedLabor),
CustomActionType::CivilLiberties => Some(CustomAction::CivilLiberties),
CustomActionType::Taxes => try_payment(&tax_options(p), p).map(CustomAction::Taxes),
let cities = if a.is_city_bound() {
p.cities
.iter()
.filter_map(|city| a.is_available_city(p, city).then_some(Some(city.position)))
.collect_vec()
} else {
vec![None]
};
if let Some(action) = option {
for c in cities {
actions.push((
ActionType::Playing(PlayingActionType::Custom(a.clone().info())),
vec![Action::Playing(PlayingAction::Custom(action))],
vec![Action::Playing(PlayingAction::CustomEvent(
CustomEventAction::new(a.clone(), c),
))],
));
}
}
@ -357,7 +354,9 @@ fn calculate_increase_happiness(
) -> Option<IncreaseHappiness> {
// try to make the biggest cities happy - that's usually the best choice
let mut all_steps: Vec<(Position, u32)> = vec![];
let mut step_sum = 0;
let mut cost = PaymentOptions::free();
let available = action_type.remaining_resources(player);
for c in player
.cities
@ -370,14 +369,15 @@ fn calculate_increase_happiness(
MoodState::Neutral => 1,
MoodState::Happy => 0,
};
let mut new_steps = all_steps.clone();
new_steps.push((c.position, steps));
let new_steps_sum = step_sum + steps * c.size() as u32;
let Some(new_cost) = happiness_cost_for_all_cities(player, &new_steps, action_type) else {
let info = happiness_cost(player, new_steps_sum, None);
if !info.cost.can_afford(&available) {
break;
};
all_steps = new_steps;
cost = new_cost;
}
all_steps.push((c.position, steps));
step_sum = new_steps_sum;
cost = info.cost;
}
(!all_steps.is_empty()).then_some(IncreaseHappiness::new(
@ -579,11 +579,16 @@ fn construct(p: &Player, game: &Game) -> Vec<Action> {
pub(crate) fn get_construct_actions(game: &Game, p: &Player, city: &City) -> Vec<Action> {
available_buildings(game, p.index, city.position)
.iter()
.map(|(building, cost, port)| {
Action::Playing(PlayingAction::Construct(
Construct::new(city.position, *building, payment(&cost.cost, p))
.with_port_position(*port),
))
.flat_map(|(building, cost)| {
new_building_positions(game, *building, city)
.iter()
.map(|port| {
Action::Playing(PlayingAction::Construct(
Construct::new(city.position, *building, payment(&cost.cost, p))
.with_port_position(*port),
))
})
.collect_vec()
})
.collect()
}

View file

@ -186,7 +186,7 @@ fn dice_roll_with_leader_reroll(
*unit_types -= &Leader;
// if used, the leader grants unlimited rerolls of 1s and 2s
// if used, the leader grants unlimited rerolls of 1s
loop {
add_roll_log_effect(roll_log, "re-roll");
let side = roll_die(game, roll_log);

View file

@ -1,6 +1,7 @@
use crate::city::{City, MoodState};
use crate::city_pieces::Building;
use crate::consts::MAX_CITY_SIZE;
use crate::consts::MAX_CITY_PIECES;
use crate::content::advances;
use crate::content::persistent_events::PersistentEventType;
use crate::game::Game;
use crate::map::Terrain;
@ -39,12 +40,23 @@ impl Construct {
///
/// # Errors
/// Returns an error if the building cannot be built
///
/// # Panics
/// Panics if the required advance is not found
pub fn can_construct(
city: &City,
building: Building,
player: &Player,
game: &Game,
) -> Result<CostInfo, String> {
let advance = advances::get_all()
.iter()
.find(|a| a.unlocked_building == Some(building))
.expect("Advance not found");
if !player.advances.contains(&advance) {
return Err(format!("Missing advance: {}", advance.name));
}
can_construct_anything(city, player)?;
if !city.can_activate() {
return Err("Can't activate".to_string());
@ -55,17 +67,10 @@ pub fn can_construct(
if !city.pieces.can_add_building(building) {
return Err("Building already exists".to_string());
}
if !player
.advances
.iter()
.any(|a| a.unlocked_building == Some(building))
{
return Err("Building not researched".to_string());
}
if !player.is_building_available(building, game) {
return Err("All non-destroyed buildings are built".to_string());
}
let cost_info = player.construct_cost(game, building, None);
let cost_info = player.building_cost(game, building, None);
if !player.can_afford(&cost_info.cost) {
// construct cost event listener?
return Err("Not enough resources".to_string());
@ -77,7 +82,7 @@ pub(crate) fn can_construct_anything(city: &City, player: &Player) -> Result<(),
if city.player_index != player.index {
return Err("Not your city".to_string());
}
if city.pieces.amount() >= MAX_CITY_SIZE {
if city.pieces.amount() >= MAX_CITY_PIECES {
return Err("City is full".to_string());
}
if city.size() >= player.cities.len() {
@ -125,27 +130,23 @@ pub fn available_buildings(
game: &Game,
player: usize,
city: Position,
) -> Vec<(Building, CostInfo, Option<Position>)> {
) -> Vec<(Building, CostInfo)> {
let player = game.player(player);
let city = player.get_city(city);
Building::all()
.into_iter()
.flat_map(|b| {
can_construct(city, b, player, game)
.map_or(Vec::new(), |i| new_building_positions(game, b, city, &i))
})
.filter_map(|b| can_construct(city, b, player, game).ok().map(|i| (b, i)))
.collect()
}
#[must_use]
fn new_building_positions(
pub fn new_building_positions(
game: &Game,
building: Building,
city: &City,
cost_info: &CostInfo,
) -> Vec<(Building, CostInfo, Option<Position>)> {
) -> Vec<Option<Position>> {
if building != Building::Port {
return vec![(building, cost_info.clone(), None)];
return vec![None];
}
game.map
@ -153,7 +154,7 @@ fn new_building_positions(
.iter()
.filter_map(|(p, t)| {
if *t == Terrain::Water && city.position.is_neighbor(*p) {
Some((building, cost_info.clone(), Some(*p)))
Some(Some(*p))
} else {
None
}

View file

@ -1,7 +1,7 @@
use crate::content::advances::TACTICS;
use crate::{resource_pile::ResourcePile, unit::Units};
pub const MAX_CITY_SIZE: usize = 4;
pub const MAX_CITY_PIECES: usize = 4; // i.e. city size 5
pub const AGES: u32 = 6;
pub const ADVANCE_COST: u32 = 2;
pub const BUILDING_VICTORY_POINTS: f32 = 1.0;
@ -42,7 +42,7 @@ pub const UNIT_LIMIT_PIRATES: Units = Units {
elephants: 0,
leaders: 0,
};
pub const CONSTRUCT_COST: ResourcePile = ResourcePile {
pub const BUILDING_COST: ResourcePile = ResourcePile {
food: 1,
wood: 1,
ore: 1,

View file

@ -1,8 +1,8 @@
mod agriculture;
mod autocracy;
pub(crate) mod autocracy;
mod construction;
pub mod culture;
mod democracy;
pub(crate) mod democracy;
pub mod economy;
mod education;
mod science;

View file

@ -1,6 +1,7 @@
use crate::ability_initializer::AbilityInitializerSetup;
use crate::advance::{Advance, AdvanceBuilder};
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;
@ -82,6 +83,21 @@ fn absolute_power() -> AdvanceBuilder {
.add_custom_action(AbsolutePower)
}
pub(crate) fn use_absolute_power() -> Builtin {
Builtin::builder("Absolute Power", "")
.add_simple_persistent_event_listener(
|event| &mut event.custom_action,
0,
|game, _, player_name, _| {
game.actions_left += 1;
game.add_info_log_item(&format!(
"{player_name} paid 2 mood tokens to get an extra action using Absolute Power",
));
},
)
.build()
}
fn forced_labor() -> AdvanceBuilder {
Advance::builder(
"Forced Labor",
@ -89,3 +105,18 @@ fn forced_labor() -> AdvanceBuilder {
)
.add_custom_action(ForcedLabor)
}
pub(crate) fn use_forced_labor() -> Builtin {
Builtin::builder("Forced Labor", "")
.add_simple_persistent_event_listener(
|event| &mut event.custom_action,
0,
|game, _, player_name, _| {
// we check that the action was played
game.add_info_log_item(&format!(
"{player_name} paid 1 mood token to treat Angry cities as neutral"
));
},
)
.build()
}

View file

@ -4,11 +4,11 @@ use crate::advance::{Advance, AdvanceBuilder};
use crate::city::{City, MoodState};
use crate::city_pieces::Building::Obelisk;
use crate::content::advances::{AdvanceGroup, advance_group_builder};
use crate::content::builtin::Builtin;
use crate::content::custom_actions::CustomActionType;
use crate::game::Game;
use crate::content::persistent_events::PaymentRequest;
use crate::happiness::increase_happiness;
use crate::payment::PaymentOptions;
use crate::position::Position;
use crate::resource::ResourceType;
use crate::resource_pile::ResourcePile;
use crate::wonder::draw_wonder_card;
@ -29,14 +29,13 @@ fn arts() -> AdvanceBuilder {
.add_custom_action(CustomActionType::ArtsInfluenceCultureAttempt)
}
const SPORTS_DESC: &str = "As an action, you may spend \
1 or 2 culture tokens to increase the happiness of a city by 1 or 2, respectively";
fn sports() -> AdvanceBuilder {
Advance::builder(
"Sports",
"As an action, you may spend \
1 or 2 culture tokens to increase the happiness of a city by 1 or 2, respectively",
)
.with_advance_bonus(MoodToken)
.add_custom_action(CustomActionType::Sports)
Advance::builder("Sports", SPORTS_DESC)
.with_advance_bonus(MoodToken)
.add_custom_action(CustomActionType::Sports)
}
fn monuments() -> AdvanceBuilder {
@ -63,14 +62,13 @@ fn monuments() -> AdvanceBuilder {
)
}
const THEATERS_DESC: &str = "Once per turn, as a free action, you may convert 1 culture token \
into 1 mood token, or 1 mood token into 1 culture token";
fn theaters() -> AdvanceBuilder {
Advance::builder(
"Theaters",
"Once per turn, as a free action, you may convert 1 culture token \
into 1 mood token, or 1 mood token into 1 culture token",
)
.with_advance_bonus(MoodToken)
.add_custom_action(CustomActionType::Theaters)
Advance::builder("Theaters", THEATERS_DESC)
.with_advance_bonus(MoodToken)
.add_custom_action(CustomActionType::Theaters)
}
#[must_use]
@ -85,15 +83,40 @@ pub fn sports_options(city: &City) -> Option<PaymentOptions> {
}
}
pub(crate) fn execute_sports(
game: &mut Game,
player_index: usize,
pos: Position,
payment: &ResourcePile,
) {
let options = sports_options(game.city(player_index, pos));
game.players[player_index].pay_cost(&options.expect("sports not possible"), payment);
increase_happiness(game, player_index, &[(pos, payment.culture_tokens)], None);
pub(crate) fn use_sports() -> Builtin {
Builtin::builder("Sports", SPORTS_DESC)
.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")))
.expect("Invalid options for sports");
Some(vec![PaymentRequest::new(
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
),
);
},
)
.build()
}
#[must_use]
@ -101,9 +124,32 @@ pub fn theaters_options() -> PaymentOptions {
PaymentOptions::sum(1, &[ResourceType::CultureTokens, ResourceType::MoodTokens])
}
pub(crate) fn execute_theaters(game: &mut Game, player_index: usize, payment: &ResourcePile) {
game.players[player_index].gain_resources(theater_opposite(payment));
game.players[player_index].pay_cost(&theaters_options(), payment);
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(),
"Convert 1 culture token into 1 mood token, or 1 mood token into 1 culture token",
false,
)])
},
|game, s, _| {
let reward = theater_opposite(&s.choice[0]);
game.players[s.player_index].gain_resources(reward.clone());
game.add_info_log_item(
&format!(
"{} used Theaters to convert {} into {}",
s.player_name,
s.choice[0],
reward
),
);
},
)
.build()
}
fn theater_opposite(payment: &ResourcePile) -> ResourcePile {

View file

@ -3,11 +3,13 @@ use crate::action::Action;
use crate::advance::{Advance, AdvanceBuilder};
use crate::city::MoodState;
use crate::content::advances::{AdvanceGroup, advance_group_builder};
use crate::content::builtin::Builtin;
use crate::content::custom_actions::CustomActionType::{
CivilLiberties, FreeEconomyCollect, VotingIncreaseHappiness,
};
use crate::log::current_player_turn_log;
use crate::playing_actions::{PlayingAction, PlayingActionType};
use crate::resource_pile::ResourcePile;
pub(crate) fn democracy() -> AdvanceGroup {
advance_group_builder(
@ -56,6 +58,22 @@ fn civil_liberties() -> AdvanceBuilder {
.add_custom_action(CivilLiberties)
}
pub(crate) fn use_civil_liberties() -> Builtin {
Builtin::builder("Civil Liberties", "")
.add_simple_persistent_event_listener(
|event| &mut event.custom_action,
0,
|game, player_index, player_name, _| {
game.player_mut(player_index)
.gain_resources(ResourcePile::mood_tokens(3));
game.add_info_log_item(&format!(
"{player_name} gained 3 mood tokens using Civil Liberties"
));
},
)
.build()
}
fn free_economy() -> AdvanceBuilder {
Advance::builder(
"Free Economy",

View file

@ -1,11 +1,15 @@
use crate::ability_initializer::AbilityInitializerSetup;
use crate::action_card::discard_action_card;
use crate::advance::Bonus::{CultureToken, MoodToken};
use crate::advance::{Advance, AdvanceBuilder};
use crate::card::HandCard;
use crate::city_pieces::Building::Market;
use crate::content::advances::trade_routes::{TradeRoute, trade_route_log, trade_route_reward};
use crate::content::advances::{AdvanceGroup, CURRENCY, advance_group_builder};
use crate::content::builtin::Builtin;
use crate::content::custom_actions::CustomActionType;
use crate::content::custom_actions::CustomActionType::Taxes;
use crate::content::persistent_events::ResourceRewardRequest;
use crate::content::persistent_events::{HandCardsRequest, ResourceRewardRequest};
use crate::game::Game;
use crate::payment::PaymentOptions;
use crate::player::Player;
@ -29,20 +33,93 @@ fn currency() -> AdvanceBuilder {
.with_advance_bonus(CultureToken)
}
const BARTER_DESC: &str = "Once per turn, as a free action, \
you may spend discard an action card for 1 gold or 1 culture token.";
fn bartering() -> AdvanceBuilder {
Advance::builder("Bartering", "todo")
Advance::builder("Bartering", BARTER_DESC)
.with_advance_bonus(MoodToken)
.add_custom_action(CustomActionType::Bartering)
.with_unlocked_building(Market)
}
fn taxes() -> AdvanceBuilder {
Advance::builder(
"Taxes",
"Once per turn, as an action, you may spend 1 mood token to gain \
pub(crate) fn use_bartering() -> Builtin {
Builtin::builder("Bartering", BARTER_DESC)
.add_hand_card_request(
|event| &mut event.custom_action,
1,
|game, player_index, _| {
let cards = game
.player(player_index)
.action_cards
.iter()
.map(|a| HandCard::ActionCard(*a))
.collect_vec();
Some(HandCardsRequest::new(
cards,
1..=1,
"Select an action card to discard",
))
},
|game, s, _e| {
let HandCard::ActionCard(card) = s.choice[0] else {
panic!("Invalid type");
};
game.add_info_log_item(&format!(
"{} discarded an action card for 1 gold or 1 culture token",
s.player_name
));
discard_action_card(game, s.player_index, card);
},
)
.add_resource_request(
|event| &mut event.custom_action,
0,
|_game, _player_index, _| {
Some(ResourceRewardRequest::new(
PaymentOptions::sum(1, &[ResourceType::Gold, ResourceType::CultureTokens]),
"Select a resource to gain".to_string(),
))
},
|_game, s, _| {
vec![format!(
"{} gained {} for discarding an action card",
s.player_name, s.choice
)]
},
)
.build()
}
const TAXES_DESCRIPTION: &str = "Once per turn, as an action, you may spend 1 mood token to gain \
food, wood, or ore equal to the number of cities you control. \
If you have the Currency advance, you may gain gold instead of food, wood, or ore.",
)
.add_custom_action(Taxes)
If you have the Currency advance, you may gain gold instead of food, wood, or ore.";
fn taxes() -> AdvanceBuilder {
Advance::builder("Taxes", TAXES_DESCRIPTION).add_custom_action(Taxes)
}
pub(crate) fn use_taxes() -> Builtin {
Builtin::builder("Taxes", TAXES_DESCRIPTION)
.add_resource_request(
|event| &mut event.custom_action,
0,
|game, player_index, _| {
let options = tax_options(game.player(player_index));
Some(ResourceRewardRequest::new(
options,
"Select a resource to gain".to_string(),
))
},
|_game, s, _| {
vec![format!(
"{} gained {} for using Taxes",
s.player_name, s.choice
)]
},
)
.build()
}
#[must_use]
@ -54,14 +131,6 @@ pub fn tax_options(player: &Player) -> PaymentOptions {
PaymentOptions::sum(player.cities.len() as u32, &c)
}
pub(crate) fn collect_taxes(game: &mut Game, player_index: usize, gain: ResourcePile) {
assert!(
tax_options(game.player(player_index)).is_valid_payment(&gain),
"Invalid gain for Taxes"
);
game.players[player_index].gain_resources(gain);
}
fn trade_routes() -> AdvanceBuilder {
add_trade_routes(
Advance::builder(

View file

@ -1,9 +1,11 @@
use crate::ability_initializer::{AbilityInitializerSetup, do_once_per_turn};
use crate::action_card::gain_action_card_from_pile;
use crate::advance::Bonus::{CultureToken, MoodToken};
use crate::advance::{Advance, AdvanceBuilder};
use crate::city_pieces::Building;
use crate::content::advances::{AdvanceGroup, advance_group_builder, get_group};
use crate::content::persistent_events::PaymentRequest;
use crate::objective_card::gain_objective_card_from_pile;
use crate::payment::PaymentOptions;
use crate::resource_pile::ResourcePile;
@ -20,9 +22,13 @@ pub(crate) fn education() -> AdvanceGroup {
}
fn writing() -> AdvanceBuilder {
Advance::builder("Writing", "todo")
Advance::builder("Writing", "Gain 1 action and 1 objective card")
.with_advance_bonus(CultureToken)
.with_unlocked_building(Building::Academy)
.add_one_time_ability_initializer(|game, player_index| {
gain_action_card_from_pile(game, player_index);
gain_objective_card_from_pile(game, player_index);
})
.add_simple_persistent_event_listener(
|event| &mut event.construct,
3,

View file

@ -1,36 +1,41 @@
use serde::{Deserialize, Serialize};
use crate::city::City;
use crate::collect::collect;
use crate::content::advances::culture::{execute_sports, execute_theaters};
use crate::content::advances::economy::collect_taxes;
use crate::content::persistent_events::SelectedStructure;
use crate::content::advances::autocracy::{use_absolute_power, use_forced_labor};
use crate::content::advances::culture::{sports_options, use_sports, use_theaters};
use crate::content::advances::democracy::use_civil_liberties;
use crate::content::advances::economy::{use_bartering, use_taxes};
use crate::content::builtin::Builtin;
use crate::content::persistent_events::{PersistentEventType, SelectedStructure};
use crate::cultural_influence::{
format_cultural_influence_attempt_log_item, influence_culture_attempt,
};
use crate::happiness::increase_happiness;
use crate::log::{
format_city_happiness_increase, format_collect_log_item, format_happiness_increase,
};
use crate::log::{format_collect_log_item, format_happiness_increase};
use crate::player::Player;
use crate::playing_actions::{Collect, IncreaseHappiness, PlayingActionType};
use crate::{
game::Game, playing_actions::ActionCost, position::Position, resource_pile::ResourcePile,
};
use crate::position::Position;
use crate::{game::Game, playing_actions::ActionCost, resource_pile::ResourcePile};
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
pub struct CustomEventAction {
pub action: CustomActionType,
pub city: Option<Position>,
}
impl CustomEventAction {
#[must_use]
pub fn new(action: CustomActionType, city: Option<Position>) -> Self {
Self { action, city }
}
}
#[derive(Serialize, Deserialize, PartialEq, Eq, Clone, Debug)]
pub enum CustomAction {
AbsolutePower,
ForcedLabor,
CivilLiberties,
ArtsInfluenceCultureAttempt(SelectedStructure),
VotingIncreaseHappiness(IncreaseHappiness),
FreeEconomyCollect(Collect),
Sports {
city_position: Position,
payment: ResourcePile,
},
Taxes(ResourcePile),
Theaters(ResourcePile),
}
#[derive(Clone, Debug, PartialEq)]
@ -61,6 +66,7 @@ pub enum CustomActionType {
AbsolutePower,
ForcedLabor,
CivilLiberties,
Bartering,
ArtsInfluenceCultureAttempt,
VotingIncreaseHappiness,
FreeEconomyCollect,
@ -72,13 +78,6 @@ pub enum CustomActionType {
impl CustomAction {
pub(crate) fn execute(self, game: &mut Game, player_index: usize) -> Result<(), String> {
match self {
CustomAction::AbsolutePower => game.actions_left += 1,
CustomAction::ForcedLabor => {
// we check that the action was played
}
CustomAction::CivilLiberties => {
game.players[player_index].gain_resources(ResourcePile::mood_tokens(3));
}
CustomAction::ArtsInfluenceCultureAttempt(c) => {
influence_culture_attempt(
game,
@ -91,14 +90,6 @@ impl CustomAction {
increase_happiness(game, player_index, &i.happiness_increases, Some(i.payment));
}
CustomAction::FreeEconomyCollect(c) => collect(game, player_index, &c)?,
CustomAction::Sports {
city_position,
payment,
} => {
execute_sports(game, player_index, city_position, &payment);
}
CustomAction::Taxes(r) => collect_taxes(game, player_index, r),
CustomAction::Theaters(r) => execute_theaters(game, player_index, &r),
}
Ok(())
}
@ -106,32 +97,17 @@ impl CustomAction {
#[must_use]
pub fn custom_action_type(&self) -> CustomActionType {
match self {
CustomAction::AbsolutePower => CustomActionType::AbsolutePower,
CustomAction::ForcedLabor => CustomActionType::ForcedLabor,
CustomAction::CivilLiberties => CustomActionType::CivilLiberties,
CustomAction::ArtsInfluenceCultureAttempt(_) => {
CustomActionType::ArtsInfluenceCultureAttempt
}
CustomAction::VotingIncreaseHappiness(_) => CustomActionType::VotingIncreaseHappiness,
CustomAction::FreeEconomyCollect(_) => CustomActionType::FreeEconomyCollect,
CustomAction::Sports { .. } => CustomActionType::Sports,
CustomAction::Taxes(_) => CustomActionType::Taxes,
CustomAction::Theaters(_) => CustomActionType::Theaters,
}
}
#[must_use]
pub fn format_log_item(&self, game: &Game, player: &Player, player_name: &str) -> String {
match self {
CustomAction::AbsolutePower => format!(
"{player_name} paid 2 mood tokens to get an extra action using Forced Labor"
),
CustomAction::ForcedLabor => {
format!("{player_name} paid 1 mood token to treat Angry cities as neutral")
}
CustomAction::CivilLiberties => {
format!("{player_name} gained 3 mood tokens using Civil Liberties")
}
CustomAction::ArtsInfluenceCultureAttempt(c) => format!(
"{} using Arts",
format_cultural_influence_attempt_log_item(
@ -150,19 +126,6 @@ impl CustomAction {
"{} using Free Economy",
format_collect_log_item(player, player_name, c)
),
CustomAction::Sports {
city_position,
payment,
} => format!(
"{player_name} paid {payment} to increase the happiness in {} using Sports",
format_city_happiness_increase(player, *city_position, payment.amount())
),
CustomAction::Taxes(r) => {
format!("{player_name} paid 1 mood token to collect {r} using Taxes")
}
CustomAction::Theaters(r) => {
format!("{player_name} paid {r} to convert resources using Theaters")
}
}
}
}
@ -175,6 +138,9 @@ impl CustomActionType {
self.free_and_once_per_turn(ResourcePile::mood_tokens(2))
}
CustomActionType::CivilLiberties | CustomActionType::Sports => self.regular(),
CustomActionType::Bartering | CustomActionType::Theaters => {
self.free_and_once_per_turn(ResourcePile::empty())
}
CustomActionType::ArtsInfluenceCultureAttempt => {
self.free_and_once_per_turn(ResourcePile::culture_tokens(1))
}
@ -183,7 +149,6 @@ impl CustomActionType {
self.free_and_once_per_turn(ResourcePile::mood_tokens(1))
}
CustomActionType::Taxes => self.once_per_turn(ResourcePile::mood_tokens(1)),
CustomActionType::Theaters => self.free_and_once_per_turn(ResourcePile::empty()),
}
}
@ -194,6 +159,21 @@ impl CustomActionType {
.is_ok()
}
#[must_use]
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))
}
_ => false,
}
}
#[must_use]
pub fn is_city_bound(&self) -> bool {
matches!(self, CustomActionType::Sports)
}
#[must_use]
pub fn playing_action_type(&self) -> PlayingActionType {
PlayingActionType::Custom(self.info())
@ -218,4 +198,36 @@ impl CustomActionType {
fn free_and_once_per_turn(&self, cost: ResourcePile) -> CustomActionInfo {
CustomActionInfo::new(self, true, true, cost)
}
#[must_use]
pub(crate) fn execute_builtin(&self) -> Builtin {
match self {
CustomActionType::Sports => use_sports(),
CustomActionType::Theaters => use_theaters(),
CustomActionType::Taxes => use_taxes(),
CustomActionType::Bartering => use_bartering(),
CustomActionType::AbsolutePower => use_absolute_power(),
CustomActionType::ForcedLabor => use_forced_labor(),
CustomActionType::CivilLiberties => use_civil_liberties(),
_ => {
panic!("CustomActionType::execute_builtin called on non-builtin action")
}
}
}
}
pub(crate) fn execute_custom_action(
game: &mut Game,
player_index: usize,
action: CustomEventAction,
) {
let _ = game.trigger_persistent_event_with_listener(
&[player_index],
|e| &mut e.custom_action,
&action.action.execute_builtin().listeners,
action,
PersistentEventType::CustomAction,
None,
|_| {},
);
}

View file

@ -298,7 +298,7 @@ fn great_prophet() -> ActionCard {
}
fn temple_cost(game: &Game, player: &Player) -> PaymentOptions {
player.construct_cost(game, Building::Temple, None).cost
player.building_cost(game, Building::Temple, None).cost
}
pub(crate) fn great_person_description<S: AsRef<str>>(free_advance_groups: &[S]) -> String {

View file

@ -6,6 +6,7 @@ use crate::collect::CollectInfo;
use crate::combat::Combat;
use crate::combat_listeners::{CombatEnd, CombatRoundEnd, CombatRoundStart};
use crate::combat_stats::CombatStats;
use crate::content::custom_actions::CustomEventAction;
use crate::events::EventOrigin;
use crate::explore::ExploreResolutionState;
use crate::game::Game;
@ -112,6 +113,7 @@ pub enum PersistentEventType {
WonderCard(WonderCardInfo),
DrawWonderCard,
SelectObjectives(SelectObjectivesInfo),
CustomAction(CustomEventAction),
}
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]

View file

@ -646,7 +646,19 @@ impl Game {
.custom_actions
.clone()
.into_iter()
.filter(|(t, _)| t.is_available(self, player_index))
.filter(|(t, _)| {
if matches!(
t,
CustomActionType::ArtsInfluenceCultureAttempt
| CustomActionType::FreeEconomyCollect
| CustomActionType::VotingIncreaseHappiness
) {
// returned as part of "base_or_custom_available"
return false;
}
t.is_available(self, player_index)
})
.collect()
}

View file

@ -1,5 +1,5 @@
use crate::action::Action;
use crate::city::{City, MoodState};
use crate::city::MoodState;
use crate::content::custom_actions::{CustomAction, CustomActionType};
use crate::game::Game;
use crate::payment::PaymentOptions;
@ -12,20 +12,6 @@ use crate::position::Position;
use crate::resource::ResourceType;
use crate::resource_pile::ResourcePile;
#[must_use]
pub fn available_happiness_actions_for_city(
game: &Game,
player: usize,
position: Position,
) -> Vec<PlayingActionType> {
let city = game.player(player).get_city(position);
if city.can_activate() && city.mood_state != MoodState::Happy {
available_happiness_actions(game, player)
} else {
vec![]
}
}
#[must_use]
pub fn available_happiness_actions(game: &Game, player: usize) -> Vec<PlayingActionType> {
base_or_custom_available(
@ -68,14 +54,13 @@ pub(crate) fn increase_happiness(
) {
let player = &mut game.players[player_index];
let mut angry_activations = vec![];
let mut count = 0;
let mut step_sum = 0;
for &(city_position, steps) in happiness_increases {
let city = player.get_city(city_position);
if steps == 0 {
continue;
}
count += steps * city.size() as u32;
step_sum += steps * city.size() as u32;
if city.mood_state == MoodState::Angry {
angry_activations.push(city_position);
@ -87,56 +72,16 @@ pub(crate) fn increase_happiness(
}
if let Some(r) = payment {
increase_happiness_total_cost(player, count, Some(&r)).pay(game, &r);
happiness_cost(player, step_sum, Some(&r)).pay(game, &r);
}
}
#[must_use]
pub fn happiness_cost_for_all_cities(
pub fn happiness_cost(
p: &Player,
new_steps: &[(Position, u32)],
action_type: &PlayingActionType,
) -> Option<PaymentOptions> {
new_steps
.iter()
.filter_map(|(pos, steps)| {
let city = p.get_city(*pos);
increase_happiness_cost(p, city, *steps, action_type).map(|c| c.cost.clone())
})
.reduce(|mut a, b| {
a.default += b.default;
a
})
}
#[must_use]
pub fn increase_happiness_cost(
player: &Player,
city: &City,
steps: u32,
action_type: &PlayingActionType,
) -> Option<CostInfo> {
let max_steps = 2 - city.mood_state.clone() as u32;
let mood_tokens = city.size() as u32 * steps;
let total_cost = increase_happiness_total_cost(player, mood_tokens, None);
(total_cost
.cost
.can_afford(&action_type.remaining_resources(player))
&& steps <= max_steps)
.then_some(total_cost)
}
#[must_use]
fn increase_happiness_total_cost(
player: &Player,
cost: u32,
city_size_steps: u32, // for each city: size * steps in that city
execute: Option<&ResourcePile>,
) -> CostInfo {
player.trigger_cost_event(
|e| &e.happiness_cost,
&PaymentOptions::sum(cost, &[ResourceType::MoodTokens]),
&(),
&(),
execute,
)
let payment_options = PaymentOptions::sum(city_size_steps, &[ResourceType::MoodTokens]);
p.trigger_cost_event(|e| &e.happiness_cost, &payment_options, &(), &(), execute)
}

View file

@ -149,6 +149,17 @@ fn format_playing_action_log_item(action: &PlayingAction, game: &Game) -> String
&PlayingActionType::InfluenceCultureAttempt,
),
PlayingAction::Custom(action) => action.format_log_item(game, player, &player_name),
PlayingAction::CustomEvent(action) => {
format!(
"{player_name} started {:?}{}",
action.action,
if let Some(p) = action.city {
format!(" at {p}")
} else {
String::new()
}
)
}
PlayingAction::ActionCard(a) => {
let card = get_civil_card(*a);
let pile = &card.action_type.cost;

View file

@ -16,9 +16,9 @@ use crate::{
city_pieces::Building::{self},
civilization::Civilization,
consts::{
ADVANCE_COST, ADVANCE_VICTORY_POINTS, BUILDING_VICTORY_POINTS,
CAPTURED_LEADER_VICTORY_POINTS, CITY_LIMIT, CITY_PIECE_LIMIT, CONSTRUCT_COST,
OBJECTIVE_VICTORY_POINTS, UNIT_LIMIT, WONDER_VICTORY_POINTS,
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,
},
content::{civilizations, custom_actions::CustomActionType},
game::Game,
@ -592,7 +592,7 @@ impl Player {
}
#[must_use]
pub fn construct_cost(
pub fn building_cost(
&self,
game: &Game,
building: Building,
@ -600,7 +600,7 @@ impl Player {
) -> CostInfo {
self.trigger_cost_event(
|e| &e.construct_cost,
&PaymentOptions::resources(CONSTRUCT_COST),
&PaymentOptions::resources(BUILDING_COST),
&building,
game,
execute,

View file

@ -5,6 +5,7 @@ use crate::collect::{CollectContext, CollectInfo};
use crate::combat::Combat;
use crate::combat_listeners::{CombatEnd, CombatRoundEnd, CombatRoundStart};
use crate::combat_stats::CombatStats;
use crate::content::custom_actions::CustomEventAction;
use crate::content::persistent_events::KilledUnits;
use crate::cultural_influence::{InfluenceCultureInfo, InfluenceCultureOutcome};
use crate::events::Event;
@ -107,6 +108,7 @@ pub(crate) struct PersistentEvents {
pub capture_undefended_position: PersistentEvent<CombatStats>,
pub units_killed: PersistentEvent<KilledUnits>,
pub select_objective_cards: PersistentEvent<SelectObjectivesInfo>,
pub custom_action: PersistentEvent<CustomEventAction>,
}
impl PersistentEvents {
@ -137,6 +139,8 @@ impl PersistentEvents {
capture_undefended_position: Event::new("capture_undefended_position"),
units_killed: Event::new("units_killed"),
select_objective_cards: Event::new("select_objective_cards"),
custom_action: Event::new("custom_action_bartering"),
}
}
}

View file

@ -3,12 +3,14 @@ use serde::{Deserialize, Serialize};
use crate::action_card::{ActionCardInfo, land_battle_won_action, play_action_card};
use crate::advance::gain_advance_without_payment;
use crate::city::found_city;
use crate::city::{MoodState, found_city};
use crate::collect::{PositionCollection, collect};
use crate::construct::Construct;
use crate::content::action_cards::get_civil_card;
use crate::content::advances::get_advance;
use crate::content::custom_actions::{CustomActionInfo, CustomActionType};
use crate::content::custom_actions::{
CustomActionInfo, CustomActionType, CustomEventAction, execute_custom_action,
};
use crate::content::persistent_events::SelectedStructure;
use crate::cultural_influence::influence_culture_attempt;
use crate::game::GameState;
@ -130,16 +132,27 @@ impl PlayingActionType {
match self {
PlayingActionType::Custom(c) => {
if !p.custom_actions.contains_key(&c.custom_action_type) {
let t = &c.custom_action_type;
if !p.custom_actions.contains_key(t) {
return Err("Custom action not available".to_string());
}
if c.once_per_turn
&& p.played_once_per_turn_actions
.contains(&c.custom_action_type)
{
if c.once_per_turn && p.played_once_per_turn_actions.contains(t) {
return Err("Custom action already played this turn".to_string());
}
let can_play = match t {
CustomActionType::Bartering => !p.action_cards.is_empty(),
CustomActionType::Sports => p.resources.culture_tokens > 0 && any_non_happy(p),
CustomActionType::Theaters => {
p.resources.culture_tokens > 0 || p.resources.mood_tokens > 0
}
CustomActionType::ForcedLabor => any_angry(p),
_ => true,
};
if !can_play {
return Err("Cannot play custom action".to_string());
}
}
PlayingActionType::ActionCard(id) => {
if !p.action_cards.contains(id) {
@ -222,6 +235,7 @@ pub enum PlayingAction {
IncreaseHappiness(IncreaseHappiness),
InfluenceCultureAttempt(SelectedStructure),
Custom(CustomAction),
CustomEvent(CustomEventAction),
ActionCard(u8),
WonderCard(String),
EndTurn,
@ -281,6 +295,7 @@ impl PlayingAction {
);
}
Custom(custom_action) => custom(game, player_index, custom_action)?,
CustomEvent(custom_action) => custom_event(game, player_index, custom_action),
EndTurn => game.next_turn(),
}
Ok(())
@ -299,6 +314,7 @@ impl PlayingAction {
PlayingAction::ActionCard(a) => PlayingActionType::ActionCard(*a),
PlayingAction::WonderCard(name) => PlayingActionType::WonderCard(name.clone()),
PlayingAction::Custom(c) => PlayingActionType::Custom(c.custom_action_type().info()),
PlayingAction::CustomEvent(c) => PlayingActionType::Custom(c.action.info()),
PlayingAction::EndTurn => PlayingActionType::EndTurn,
}
}
@ -365,13 +381,21 @@ pub(crate) fn roll_boost_cost(roll: u8) -> ResourcePile {
}
fn custom(game: &mut Game, player_index: usize, custom_action: CustomAction) -> Result<(), String> {
let c = custom_action.custom_action_type();
save_once_per_turn(game, player_index, custom_action.custom_action_type());
custom_action.execute(game, player_index)
}
fn custom_event(game: &mut Game, player_index: usize, action: CustomEventAction) {
save_once_per_turn(game, player_index, action.action.clone());
execute_custom_action(game, player_index, action);
}
fn save_once_per_turn(game: &mut Game, player_index: usize, c: CustomActionType) {
if c.info().once_per_turn {
game.players[player_index]
.played_once_per_turn_actions
.push(c);
}
custom_action.execute(game, player_index)
}
#[must_use]
@ -400,3 +424,17 @@ pub(crate) fn base_or_custom_available(
.filter_map(|a| a.is_available(game, player).map(|()| a).ok())
.collect()
}
fn any_non_happy(player: &Player) -> bool {
player
.cities
.iter()
.any(|city| city.mood_state != MoodState::Happy)
}
fn any_angry(player: &Player) -> bool {
player
.cities
.iter()
.any(|city| city.mood_state == MoodState::Angry)
}

View file

@ -156,14 +156,20 @@ pub fn recruit_cost_without_replaced(
leader_name: Option<&String>,
execute: Option<&ResourcePile>,
) -> Result<CostInfo, String> {
let city = player.get_city(city_position);
if (units.cavalry > 0 || units.elephants > 0) && city.pieces.market.is_none() {
return Err("No market".to_string());
}
if units.ships > 0 && city.pieces.port.is_none() {
return Err("No port".to_string());
}
for (t, a) in units.clone() {
let avail = player.unit_limit().get(&t);
if a > avail {
return Err(format!("Only have {avail} {t:?} - not {a}"));
}
}
let city = player.get_city(city_position);
if !city.can_activate() {
return Err("City cannot be activated".to_string());
}
@ -180,12 +186,6 @@ pub fn recruit_cost_without_replaced(
if units.amount() > city.mood_modified_size(player) as u8 {
return Err("Too many units".to_string());
}
if (units.cavalry > 0 || units.elephants > 0) && city.pieces.market.is_none() {
return Err("No market".to_string());
}
if units.ships > 0 && city.pieces.port.is_none() {
return Err("No port".to_string());
}
if player
.get_units(city_position)
.iter()

View file

@ -10,6 +10,7 @@ use std::{
use crate::ability_initializer::AbilityInitializerSetup;
use crate::city::is_valid_city_terrain;
use crate::collect::reset_collect_within_range_for_all;
use crate::combat_roll::COMBAT_DIE_SIDES;
use crate::consts::SHIP_CAPACITY;
use crate::content::builtin::Builtin;
use crate::content::persistent_events::{KilledUnits, PersistentEventType, UnitsRequest};
@ -161,7 +162,7 @@ impl UnitType {
}
#[must_use]
pub fn name(&self) -> &str {
pub fn name(&self) -> &'static str {
match self {
Settler => "settler",
Infantry => "infantry",
@ -183,6 +184,39 @@ impl UnitType {
}
}
#[must_use]
pub fn description(&self) -> String {
match self {
Settler => "A unit that can found cities.".to_string(),
Ship => "Can fight ships. Can carry 2 land units.".to_string(),
Infantry => format!(
"Army unit. Combat abilities: +1 combat values on {}",
Self::sides(Infantry)
),
Cavalry => format!(
"Army unit. Combat abilities: +2 combat values on {}",
Self::sides(Cavalry)
),
Elephant => format!(
"Army unit. Combat abilities: -1 hit but no combat value on {}",
Self::sides(Elephant)
),
Leader => format!(
"Army unit. Combat abilities: Reroll the die until you get a \
non-leader roll on {}",
Self::sides(Leader)
),
}
}
fn sides(unit_type: UnitType) -> String {
COMBAT_DIE_SIDES
.iter()
.filter(|d| d.bonus == unit_type)
.map(|d| d.value.to_string())
.join(", ")
}
#[must_use]
pub fn is_land_based(&self) -> bool {
!matches!(self, Ship)

View file

@ -2,26 +2,26 @@ use crate::common::{JsonTest, TestAction, illegal_action_test, influence_action}
use server::action::{Action, execute_action};
use server::city_pieces::Building::{Academy, Fortress, Temple};
use server::collect::PositionCollection;
use server::consts::CONSTRUCT_COST;
use server::consts::BUILDING_COST;
use server::content::advances::trade_routes::find_trade_routes;
use server::content::custom_actions::CustomAction;
use server::content::custom_actions::CustomAction::{
AbsolutePower, ArtsInfluenceCultureAttempt, CivilLiberties, ForcedLabor, Sports, Taxes,
Theaters, VotingIncreaseHappiness,
ArtsInfluenceCultureAttempt, VotingIncreaseHappiness,
};
use server::content::custom_actions::{CustomAction, CustomActionType, CustomEventAction};
use server::content::persistent_events::{EventResponse, SelectedStructure, Structure};
use server::events::EventOrigin;
use server::game::Game;
use server::movement::MovementAction::Move;
use server::movement::{MoveUnits, move_units_destinations};
use server::playing_actions::PlayingAction::{
Advance, Collect, Construct, Custom, EndTurn, Recruit, WonderCard,
Advance, Collect, Construct, Custom, CustomEvent, EndTurn, Recruit, WonderCard,
};
use server::position::Position;
use server::recruit::recruit_cost_without_replaced;
use server::resource_pile::ResourcePile;
use server::unit::Units;
use server::{construct, playing_actions};
use std::vec;
mod common;
@ -176,13 +176,22 @@ fn test_monuments() {
fn test_increase_happiness_sports() {
JSON.test(
"increase_happiness_sports",
vec![TestAction::undoable(
0,
Action::Playing(Custom(Sports {
payment: ResourcePile::culture_tokens(1),
city_position: Position::from_offset("C2"),
})),
)],
vec![
TestAction::undoable(
0,
Action::Playing(CustomEvent(CustomEventAction::new(
CustomActionType::Sports,
Some(Position::from_offset("C2")),
))),
)
.without_json_comparison(),
TestAction::undoable(
0,
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
1,
)])),
),
],
);
}
@ -190,13 +199,22 @@ fn test_increase_happiness_sports() {
fn test_increase_happiness_sports2() {
JSON.test(
"increase_happiness_sports2",
vec![TestAction::undoable(
0,
Action::Playing(Custom(Sports {
payment: ResourcePile::culture_tokens(2),
city_position: Position::from_offset("C2"),
})),
)],
vec![
TestAction::undoable(
0,
Action::Playing(CustomEvent(CustomEventAction::new(
CustomActionType::Sports,
Some(Position::from_offset("C2")),
))),
)
.without_json_comparison(),
TestAction::undoable(
0,
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
2,
)])),
),
],
);
}
@ -244,7 +262,10 @@ fn test_absolute_power() {
"absolute_power",
vec![TestAction::undoable(
0,
Action::Playing(Custom(AbsolutePower)),
Action::Playing(CustomEvent(CustomEventAction::new(
CustomActionType::AbsolutePower,
None,
))),
)],
);
}
@ -254,7 +275,13 @@ fn test_forced_labor() {
JSON.test(
"forced_labor",
vec![
TestAction::undoable(0, Action::Playing(Custom(ForcedLabor))),
TestAction::undoable(
0,
Action::Playing(CustomEvent(CustomEventAction::new(
CustomActionType::ForcedLabor,
None,
))),
),
TestAction::undoable(
0,
Action::Playing(Collect(playing_actions::Collect::new(
@ -275,7 +302,13 @@ fn test_civil_liberties() {
JSON.test(
"civil_liberties",
vec![
TestAction::undoable(0, Action::Playing(Custom(CivilLiberties))),
TestAction::undoable(
0,
Action::Playing(CustomEvent(CustomEventAction::new(
CustomActionType::CivilLiberties,
None,
))),
),
TestAction::undoable(
0,
Action::Playing(Recruit(playing_actions::Recruit::new(
@ -288,6 +321,27 @@ fn test_civil_liberties() {
);
}
#[test]
fn test_bartering() {
JSON.test(
"bartering",
vec![
TestAction::undoable(
0,
Action::Playing(CustomEvent(CustomEventAction::new(
CustomActionType::Bartering,
None,
))),
)
.without_json_comparison(),
TestAction::undoable(
0,
Action::Response(EventResponse::ResourceReward(ResourcePile::gold(1))),
),
],
);
}
#[test]
fn test_movement_on_roads_from_city() {
let units = vec![0];
@ -364,10 +418,22 @@ fn get_destinations(game: &Game, units: &[u32], position: &str) -> Vec<String> {
fn test_theaters() {
JSON.test(
"theaters",
vec![TestAction::undoable(
0,
Action::Playing(Custom(Theaters(ResourcePile::culture_tokens(1)))),
)],
vec![
TestAction::undoable(
0,
Action::Playing(CustomEvent(CustomEventAction::new(
CustomActionType::Theaters,
None,
))),
)
.without_json_comparison(),
TestAction::undoable(
0,
Action::Response(EventResponse::Payment(vec![ResourcePile::culture_tokens(
1,
)])),
),
],
);
}
@ -375,10 +441,22 @@ fn test_theaters() {
fn test_taxes() {
JSON.test(
"taxes",
vec![TestAction::undoable(
0,
Action::Playing(Custom(Taxes(ResourcePile::new(1, 1, 1, 0, 1, 0, 0)))),
)],
vec![
TestAction::undoable(
0,
Action::Playing(CustomEvent(CustomEventAction::new(
CustomActionType::Taxes,
None,
))),
)
.without_json_comparison(),
TestAction::undoable(
0,
Action::Response(EventResponse::ResourceReward(ResourcePile::new(
1, 1, 1, 0, 1, 0, 0,
))),
),
],
);
}
@ -489,14 +567,24 @@ fn test_priesthood() {
fn test_writing() {
JSON.test(
"writing",
vec![TestAction::undoable(
0,
Action::Playing(Construct(construct::Construct::new(
Position::from_offset("A1"),
Academy,
CONSTRUCT_COST.clone(),
))),
)],
vec![
TestAction::not_undoable(
0,
Action::Playing(Advance {
advance: String::from("Writing"),
payment: ResourcePile::food(1) + ResourcePile::gold(1),
}),
)
.without_json_comparison(),
TestAction::undoable(
0,
Action::Playing(Construct(construct::Construct::new(
Position::from_offset("A1"),
Academy,
BUILDING_COST.clone(),
))),
),
],
);
}
#[test]

View file

@ -233,7 +233,10 @@
{
"action": {
"Playing": {
"Custom": "AbsolutePower"
"CustomEvent": {
"action": "AbsolutePower",
"city": null
}
}
},
"undo": [
@ -263,7 +266,8 @@
"action_log_index": 1,
"log": [
[
"Player1 paid 2 mood tokens to get an extra action using Forced Labor"
"Player1 started AbsolutePower",
"Player1 paid 2 mood tokens to get an extra action using Absolute Power"
]
],
"undo_limit": 0,

View file

@ -0,0 +1,229 @@
{
"state": "Playing",
"players": [
{
"id": 0,
"resources": {
"food": 1,
"wood": 6,
"ore": 7,
"ideas": 5,
"gold": 7,
"mood_tokens": 6,
"culture_tokens": 7
},
"resource_limit": {
"food": 2,
"wood": 7,
"ore": 7,
"ideas": 7,
"gold": 7,
"mood_tokens": 7,
"culture_tokens": 7
},
"cities": [
{
"city_pieces": {},
"mood_state": "Happy",
"position": "A1"
},
{
"city_pieces": {
"academy": 0
},
"mood_state": "Neutral",
"position": "C2"
}
],
"units": [
{
"position": "C2",
"unit_type": "Infantry",
"id": 0
},
{
"position": "C2",
"unit_type": "Cavalry",
"id": 1
},
{
"position": "C2",
"unit_type": "Leader",
"id": 2
},
{
"position": "C2",
"unit_type": "Elephant",
"id": 3
},
{
"position": "C2",
"unit_type": "Settler",
"id": 4
},
{
"position": "C2",
"unit_type": "Settler",
"id": 5
},
{
"position": "C2",
"unit_type": "Settler",
"id": 6
},
{
"position": "C2",
"unit_type": "Settler",
"id": 7
}
],
"civilization": "test0",
"advances": [
"Bartering",
"Draft",
"Farming",
"Math",
"Mining",
"Public Education"
],
"incident_tokens": 2,
"action_cards": [
1
],
"next_unit_id": 8
},
{
"id": 1,
"resources": {
"food": 2,
"wood": 7,
"ore": 7,
"ideas": 7,
"gold": 7,
"mood_tokens": 7,
"culture_tokens": 7
},
"resource_limit": {
"food": 2,
"wood": 7,
"ore": 7,
"ideas": 7,
"gold": 7,
"mood_tokens": 7,
"culture_tokens": 7
},
"cities": [
{
"city_pieces": {},
"mood_state": "Angry",
"position": "C1"
}
],
"units": [
{
"position": "C1",
"unit_type": "Infantry",
"id": 0
},
{
"position": "C1",
"unit_type": "Infantry",
"id": 1
}
],
"civilization": "test1",
"advances": [
"Farming",
"Mining"
],
"incident_tokens": 3,
"next_unit_id": 2
}
],
"map": {
"tiles": [
[
"A1",
"Fertile"
],
[
"A2",
"Water"
],
[
"A3",
{
"Exhausted": "Forest"
}
],
[
"B1",
"Mountain"
],
[
"B2",
"Forest"
],
[
"B3",
"Fertile"
],
[
"C1",
"Barren"
],
[
"C2",
"Forest"
],
[
"C3",
"Water"
],
[
"D2",
"Water"
]
]
},
"starting_player_index": 0,
"current_player_index": 0,
"action_log": [
{
"rounds": [
{
"players": [
{
"index": 0,
"items": []
}
]
}
]
}
],
"action_log_index": 0,
"log": [],
"undo_limit": 0,
"actions_left": 3,
"round": 2,
"age": 1,
"messages": [
"The game has started"
],
"dice_roll_outcomes": [
1,
1,
10,
10,
10,
10,
10,
10,
10,
10
],
"wonders_left": [
"Pyramids"
]
}

View file

@ -0,0 +1,322 @@
{
"state": "Playing",
"players": [
{
"id": 0,
"resources": {
"food": 1,
"wood": 6,
"ore": 7,
"ideas": 5,
"gold": 7,
"mood_tokens": 6,
"culture_tokens": 7
},
"resource_limit": {
"food": 2,
"wood": 7,
"ore": 7,
"ideas": 7,
"gold": 7,
"mood_tokens": 7,
"culture_tokens": 7
},
"cities": [
{
"city_pieces": {},
"mood_state": "Happy",
"position": "A1"
},
{
"city_pieces": {
"academy": 0
},
"mood_state": "Neutral",
"position": "C2"
}
],
"units": [
{
"position": "C2",
"unit_type": "Infantry",
"id": 0
},
{
"position": "C2",
"unit_type": "Cavalry",
"id": 1
},
{
"position": "C2",
"unit_type": "Leader",
"id": 2
},
{
"position": "C2",
"unit_type": "Elephant",
"id": 3
},
{
"position": "C2",
"unit_type": "Settler",
"id": 4
},
{
"position": "C2",
"unit_type": "Settler",
"id": 5
},
{
"position": "C2",
"unit_type": "Settler",
"id": 6
},
{
"position": "C2",
"unit_type": "Settler",
"id": 7
}
],
"civilization": "test0",
"advances": [
"Bartering",
"Draft",
"Farming",
"Math",
"Mining",
"Public Education"
],
"incident_tokens": 2,
"next_unit_id": 8,
"played_once_per_turn_actions": [
"Bartering"
]
},
{
"id": 1,
"resources": {
"food": 2,
"wood": 7,
"ore": 7,
"ideas": 7,
"gold": 7,
"mood_tokens": 7,
"culture_tokens": 7
},
"resource_limit": {
"food": 2,
"wood": 7,
"ore": 7,
"ideas": 7,
"gold": 7,
"mood_tokens": 7,
"culture_tokens": 7
},
"cities": [
{
"city_pieces": {},
"mood_state": "Angry",
"position": "C1"
}
],
"units": [
{
"position": "C1",
"unit_type": "Infantry",
"id": 0
},
{
"position": "C1",
"unit_type": "Infantry",
"id": 1
}
],
"civilization": "test1",
"advances": [
"Farming",
"Mining"
],
"incident_tokens": 3,
"next_unit_id": 2
}
],
"map": {
"tiles": [
[
"A1",
"Fertile"
],
[
"A2",
"Water"
],
[
"A3",
{
"Exhausted": "Forest"
}
],
[
"B1",
"Mountain"
],
[
"B2",
"Forest"
],
[
"B3",
"Fertile"
],
[
"C1",
"Barren"
],
[
"C2",
"Forest"
],
[
"C3",
"Water"
],
[
"D2",
"Water"
]
]
},
"starting_player_index": 0,
"current_player_index": 0,
"action_log": [
{
"rounds": [
{
"players": [
{
"index": 0,
"items": [
{
"action": {
"Playing": {
"CustomEvent": {
"action": "Bartering",
"city": null
}
}
},
"undo": [
{
"op": "add",
"path": "/players/0/action_cards",
"value": [
1
]
},
{
"op": "remove",
"path": "/players/0/played_once_per_turn_actions"
},
{
"op": "remove",
"path": "/events"
}
]
},
{
"action": {
"Response": {
"ResourceReward": {
"gold": 1
}
}
},
"undo": [
{
"op": "add",
"path": "/events",
"value": [
{
"event_type": {
"CustomAction": {
"action": "Bartering",
"city": null
}
},
"handler": {
"origin": {
"Builtin": "Bartering"
},
"priority": 0,
"request": {
"ResourceReward": {
"name": "Select a resource to gain",
"reward": {
"conversions": [
{
"from": [
{
"gold": 1
}
],
"to": {
"culture_tokens": 1
},
"type": "Unlimited"
}
],
"default": {
"gold": 1
}
}
}
}
},
"last_priority_used": 0,
"player": 0
}
]
}
]
}
]
}
]
}
]
}
],
"action_log_index": 2,
"log": [
[
"Player1 started Bartering",
"Player1 discarded an action card for 1 gold or 1 culture token"
],
[
"Player1 gained 1 gold for discarding an action card",
"Player1 could not store 1 gold"
]
],
"undo_limit": 0,
"actions_left": 3,
"round": 2,
"age": 1,
"messages": [
"The game has started"
],
"dice_roll_outcomes": [
1,
1,
10,
10,
10,
10,
10,
10,
10,
10
],
"wonders_left": [
"Pyramids"
]
}

View file

@ -196,7 +196,10 @@
{
"action": {
"Playing": {
"Custom": "CivilLiberties"
"CustomEvent": {
"action": "CivilLiberties",
"city": null
}
}
},
"undo": [
@ -222,6 +225,7 @@
"action_log_index": 1,
"log": [
[
"Player1 started CivilLiberties",
"Player1 gained 3 mood tokens using Civil Liberties"
]
],

View file

@ -202,7 +202,10 @@
{
"action": {
"Playing": {
"Custom": "CivilLiberties"
"CustomEvent": {
"action": "CivilLiberties",
"city": null
}
}
},
"undo": [
@ -268,6 +271,7 @@
"action_log_index": 2,
"log": [
[
"Player1 started CivilLiberties",
"Player1 gained 3 mood tokens using Civil Liberties"
],
[

View file

@ -233,7 +233,10 @@
{
"action": {
"Playing": {
"Custom": "ForcedLabor"
"CustomEvent": {
"action": "ForcedLabor",
"city": null
}
}
},
"undo": [
@ -258,6 +261,7 @@
"action_log_index": 1,
"log": [
[
"Player1 started ForcedLabor",
"Player1 paid 1 mood token to treat Angry cities as neutral"
]
],

View file

@ -235,7 +235,10 @@
{
"action": {
"Playing": {
"Custom": "ForcedLabor"
"CustomEvent": {
"action": "ForcedLabor",
"city": null
}
}
},
"undo": [
@ -304,6 +307,7 @@
"action_log_index": 2,
"log": [
[
"Player1 started ForcedLabor",
"Player1 paid 1 mood token to treat Angry cities as neutral"
],
[

View file

@ -259,13 +259,9 @@
{
"action": {
"Playing": {
"Custom": {
"Sports": {
"city_position": "C2",
"payment": {
"culture_tokens": 1
}
}
"CustomEvent": {
"action": "Sports",
"city": "C2"
}
}
},
@ -275,6 +271,71 @@
"path": "/actions_left",
"value": 3
},
{
"op": "remove",
"path": "/events"
}
]
},
{
"action": {
"Response": {
"Payment": [
{
"culture_tokens": 1
}
]
}
},
"undo": [
{
"op": "add",
"path": "/events",
"value": [
{
"event_type": {
"CustomAction": {
"action": "Sports",
"city": "C2"
}
},
"handler": {
"origin": {
"Builtin": "Sports"
},
"priority": 0,
"request": {
"Payment": [
{
"cost": {
"conversions": [
{
"from": [
{
"culture_tokens": 1
}
],
"to": {},
"type": {
"MayOverpay": 1
}
}
],
"default": {
"culture_tokens": 2
}
},
"name": "Each culture token increases the happiness by 1 step",
"optional": false
}
]
}
},
"last_priority_used": 0,
"player": 0
}
]
},
{
"op": "add",
"path": "/players/0/cities/1/angry_activation",
@ -299,10 +360,13 @@
]
}
],
"action_log_index": 1,
"action_log_index": 2,
"log": [
[
"Player1 paid 1 culture token to increase the happiness in the city at C2 by 1 steps, making it Neutral using Sports"
"Player1 started Sports at C2"
],
[
"Player1 used Sports to increase the happiness of C2 by 1 steps, making it Neutral"
]
],
"undo_limit": 0,

View file

@ -259,13 +259,9 @@
{
"action": {
"Playing": {
"Custom": {
"Sports": {
"city_position": "C2",
"payment": {
"culture_tokens": 2
}
}
"CustomEvent": {
"action": "Sports",
"city": "C2"
}
}
},
@ -275,6 +271,71 @@
"path": "/actions_left",
"value": 3
},
{
"op": "remove",
"path": "/events"
}
]
},
{
"action": {
"Response": {
"Payment": [
{
"culture_tokens": 2
}
]
}
},
"undo": [
{
"op": "add",
"path": "/events",
"value": [
{
"event_type": {
"CustomAction": {
"action": "Sports",
"city": "C2"
}
},
"handler": {
"origin": {
"Builtin": "Sports"
},
"priority": 0,
"request": {
"Payment": [
{
"cost": {
"conversions": [
{
"from": [
{
"culture_tokens": 1
}
],
"to": {},
"type": {
"MayOverpay": 1
}
}
],
"default": {
"culture_tokens": 2
}
},
"name": "Each culture token increases the happiness by 1 step",
"optional": false
}
]
}
},
"last_priority_used": 0,
"player": 0
}
]
},
{
"op": "add",
"path": "/players/0/cities/1/angry_activation",
@ -299,10 +360,13 @@
]
}
],
"action_log_index": 1,
"action_log_index": 2,
"log": [
[
"Player1 paid 2 culture tokens to increase the happiness in the city at C2 by 2 steps, making it Happy using Sports"
"Player1 started Sports at C2"
],
[
"Player1 used Sports to increase the happiness of C2 by 2 steps, making it Happy"
]
],
"undo_limit": 0,

View file

@ -284,13 +284,9 @@
{
"action": {
"Playing": {
"Custom": {
"Taxes": {
"food": 1,
"wood": 1,
"ore": 1,
"gold": 1
}
"CustomEvent": {
"action": "Taxes",
"city": null
}
}
},
@ -302,13 +298,102 @@
},
{
"op": "replace",
"path": "/players/0/resources/gold",
"value": 5
"path": "/players/0/resources/mood_tokens",
"value": 11
},
{
"op": "remove",
"path": "/players/0/played_once_per_turn_actions"
},
{
"op": "remove",
"path": "/events"
}
]
},
{
"action": {
"Response": {
"ResourceReward": {
"food": 1,
"wood": 1,
"ore": 1,
"gold": 1
}
}
},
"undo": [
{
"op": "add",
"path": "/events",
"value": [
{
"event_type": {
"CustomAction": {
"action": "Taxes",
"city": null
}
},
"handler": {
"origin": {
"Builtin": "Taxes"
},
"priority": 0,
"request": {
"ResourceReward": {
"name": "Select a resource to gain",
"reward": {
"conversions": [
{
"from": [
{
"gold": 1
}
],
"to": {
"food": 1
},
"type": "Unlimited"
},
{
"from": [
{
"food": 1
}
],
"to": {
"wood": 1
},
"type": "Unlimited"
},
{
"from": [
{
"wood": 1
}
],
"to": {
"ore": 1
},
"type": "Unlimited"
}
],
"default": {
"gold": 4
}
}
}
}
},
"last_priority_used": 0,
"player": 0
}
]
},
{
"op": "replace",
"path": "/players/0/resources/mood_tokens",
"value": 11
"path": "/players/0/resources/gold",
"value": 5
},
{
"op": "replace",
@ -319,10 +404,6 @@
"op": "replace",
"path": "/players/0/resources/wood",
"value": 5
},
{
"op": "remove",
"path": "/players/0/played_once_per_turn_actions"
}
]
}
@ -333,10 +414,13 @@
]
}
],
"action_log_index": 1,
"action_log_index": 2,
"log": [
[
"Player1 paid 1 mood token to collect 1 food, 1 wood, 1 ore and 1 gold using Taxes",
"Player1 started Taxes"
],
[
"Player1 gained 1 food, 1 wood, 1 ore and 1 gold for using Taxes",
"Player1 could not store 1 food"
]
],

View file

@ -284,14 +284,82 @@
{
"action": {
"Playing": {
"Custom": {
"Theaters": {
"culture_tokens": 1
}
"CustomEvent": {
"action": "Theaters",
"city": null
}
}
},
"undo": [
{
"op": "remove",
"path": "/players/0/played_once_per_turn_actions"
},
{
"op": "remove",
"path": "/events"
}
]
},
{
"action": {
"Response": {
"Payment": [
{
"culture_tokens": 1
}
]
}
},
"undo": [
{
"op": "add",
"path": "/events",
"value": [
{
"event_type": {
"CustomAction": {
"action": "Theaters",
"city": null
}
},
"handler": {
"origin": {
"Builtin": "Theaters"
},
"priority": 0,
"request": {
"Payment": [
{
"cost": {
"conversions": [
{
"from": [
{
"culture_tokens": 1
}
],
"to": {
"mood_tokens": 1
},
"type": "Unlimited"
}
],
"default": {
"culture_tokens": 1
}
},
"name": "Convert 1 culture token into 1 mood token, or 1 mood token into 1 culture token",
"optional": false
}
]
}
},
"last_priority_used": 0,
"player": 0
}
]
},
{
"op": "replace",
"path": "/players/0/resources/culture_tokens",
@ -301,10 +369,6 @@
"op": "replace",
"path": "/players/0/resources/mood_tokens",
"value": 10
},
{
"op": "remove",
"path": "/players/0/played_once_per_turn_actions"
}
]
}
@ -315,10 +379,13 @@
]
}
],
"action_log_index": 1,
"action_log_index": 2,
"log": [
[
"Player1 paid 1 culture token to convert resources using Theaters"
"Player1 started Theaters"
],
[
"Player1 used Theaters to convert 1 culture token into 1 mood token"
]
],
"undo_limit": 0,
@ -344,4 +411,4 @@
"wonders_left": [
"Pyramids"
]
}
}

View file

@ -110,9 +110,6 @@
"available_leaders": [
"Kʼinich Janaab Pakal I"
],
"advances": [
"Writing"
],
"incident_tokens": 2,
"wonder_cards": [
"Great Gardens"
@ -275,7 +272,7 @@
"action_log_index": 0,
"log": [],
"undo_limit": 0,
"actions_left": 1,
"actions_left": 2,
"round": 6,
"age": 1,
"messages": [
@ -296,5 +293,11 @@
"rng": "46312381643103681595563341886777350953",
"wonders_left": [
"Pyramids"
],
"action_cards_left": [
1
],
"objective_cards_left": [
1
]
}

View file

@ -4,13 +4,13 @@
{
"id": 0,
"resources": {
"food": 6,
"food": 5,
"wood": 5,
"ore": 5,
"ideas": 3,
"gold": 6,
"gold": 5,
"mood_tokens": 10,
"culture_tokens": 10
"culture_tokens": 11
},
"resource_limit": {
"food": 7,
@ -116,10 +116,16 @@
"advances": [
"Writing"
],
"incident_tokens": 2,
"incident_tokens": 1,
"wonder_cards": [
"Great Gardens"
],
"action_cards": [
1
],
"objective_cards": [
1
],
"next_unit_id": 10
},
{
@ -269,6 +275,19 @@
{
"index": 0,
"items": [
{
"action": {
"Playing": {
"Advance": {
"advance": "Writing",
"payment": {
"food": 1,
"gold": 1
}
}
}
}
},
{
"action": {
"Playing": {
@ -301,7 +320,7 @@
{
"op": "replace",
"path": "/players/0/resources/food",
"value": 7
"value": 6
},
{
"op": "replace",
@ -327,14 +346,20 @@
]
}
],
"action_log_index": 1,
"action_log_index": 2,
"log": [
[
"Player1 paid 1 food and 1 gold to get the Writing advance",
"Player1 gained an action card from the pile",
"Player1 gained an objective card from the pile",
"Player gained 1 culture token as advance bonus"
],
[
"Player1 paid 1 food, 1 wood and 1 ore to construct a Academy in the city at A1",
"Academy gained 2 ideas"
]
],
"undo_limit": 0,
"undo_limit": 1,
"actions_left": 0,
"round": 6,
"age": 1,