action cards (#193)
This commit is contained in:
parent
150315271c
commit
df380638db
126 changed files with 5581 additions and 1892 deletions
1
.github/workflows/check.yml
vendored
1
.github/workflows/check.yml
vendored
|
|
@ -18,6 +18,7 @@ jobs:
|
|||
|
||||
steps:
|
||||
- uses: actions/checkout@v4
|
||||
- uses: jdx/mise-action@v2
|
||||
- name: Install dependencies
|
||||
uses: awalsh128/cache-apt-pkgs-action@latest
|
||||
with:
|
||||
|
|
|
|||
94
client/Cargo.lock
generated
94
client/Cargo.lock
generated
|
|
@ -90,7 +90,7 @@ version = "3.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18"
|
||||
dependencies = [
|
||||
"event-listener 5.3.1",
|
||||
"event-listener 5.4.0",
|
||||
"event-listener-strategy",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
|
@ -147,9 +147,9 @@ checksum = "bef38d45163c2f1dde094a7dfd33ccf595c92905c8f8f4fdc18d06fb1037718a"
|
|||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.6.0"
|
||||
version = "2.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
|
||||
|
||||
[[package]]
|
||||
name = "blocking"
|
||||
|
|
@ -166,15 +166,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.16.0"
|
||||
version = "3.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
|
||||
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
|
||||
|
||||
[[package]]
|
||||
name = "bytemuck"
|
||||
version = "1.21.0"
|
||||
version = "1.22.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ef657dfab802224e671f5818e9a4935f9b1957ed18e58292690cc39e7a4092a3"
|
||||
checksum = "b6b1fc10dbac614ebc03540c9dbd60e83887fda27794998c6528f1782047d540"
|
||||
|
||||
[[package]]
|
||||
name = "byteorder"
|
||||
|
|
@ -250,9 +250,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
|||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.13.0"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
|
|
@ -278,9 +278,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
|
|||
|
||||
[[package]]
|
||||
name = "event-listener"
|
||||
version = "5.3.1"
|
||||
version = "5.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba"
|
||||
checksum = "3492acde4c3fc54c845eaab3eed8bd00c7a7d881f78bfc801e43a93dec1331ae"
|
||||
dependencies = [
|
||||
"concurrent-queue",
|
||||
"parking",
|
||||
|
|
@ -289,11 +289,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "event-listener-strategy"
|
||||
version = "0.5.3"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c3e4e0dd3673c1139bf041f3008816d9cf2946bbfac2945c09e523b8d7b05b2"
|
||||
checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93"
|
||||
dependencies = [
|
||||
"event-listener 5.3.1",
|
||||
"event-listener 5.4.0",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
|
|
@ -314,9 +314,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "flate2"
|
||||
version = "1.0.35"
|
||||
version = "1.1.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "c936bfdafb507ebbf50b8074c54fa31c5be9a1e7e5f467dd659697041407d07c"
|
||||
checksum = "11faaf5a5236997af9848be0bef4db95824b1d534ebc64d0f0c6cf3e67bd38dc"
|
||||
dependencies = [
|
||||
"crc32fast",
|
||||
"miniz_oxide",
|
||||
|
|
@ -361,9 +361,9 @@ checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
|
|||
|
||||
[[package]]
|
||||
name = "futures-lite"
|
||||
version = "2.5.0"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cef40d21ae2c515b51041df9ed313ed21e572df340ea58a922a0aefe7e8891a1"
|
||||
checksum = "f5edaec856126859abb19ed65f39e90fea3a9574b9707f13539acf4abf7eb532"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"futures-core",
|
||||
|
|
@ -442,9 +442,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.14"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
|
|
@ -495,15 +495,15 @@ checksum = "bbd2bcb4c963f2ddae06a2efc7e9f3591312473c50c6685e1f298068316e66fe"
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.169"
|
||||
version = "0.2.171"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||
checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.14"
|
||||
version = "0.4.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
|
||||
checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
|
|
@ -563,9 +563,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "miniz_oxide"
|
||||
version = "0.8.2"
|
||||
version = "0.8.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4ffbe83022cedc1d264172192511ae958937694cd57ce297164951b8b3568394"
|
||||
checksum = "8e3e04debbb59698c15bacbb6d93584a8c0ca9cc3213cb423d31f760d8843ce5"
|
||||
dependencies = [
|
||||
"adler2",
|
||||
"simd-adler32",
|
||||
|
|
@ -661,9 +661,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.20.2"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "parking"
|
||||
|
|
@ -673,9 +673,9 @@ checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
|
|||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.15"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff"
|
||||
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
|
|
@ -724,9 +724,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.92"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
|
||||
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
|
@ -739,20 +739,20 @@ checksum = "5a651516ddc9168ebd67b24afd085a718be02f8858fe406591b013d101ce2f40"
|
|||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.38"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.42"
|
||||
version = "0.38.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85"
|
||||
checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154"
|
||||
dependencies = [
|
||||
"bitflags 2.6.0",
|
||||
"bitflags 2.9.0",
|
||||
"errno",
|
||||
"libc",
|
||||
"linux-raw-sys",
|
||||
|
|
@ -761,15 +761,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.19"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4"
|
||||
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.18"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
|
|
@ -849,9 +849,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.91"
|
||||
version = "2.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035"
|
||||
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -902,15 +902,15 @@ checksum = "2c591d83f69777866b9126b24c6dd9a18351f177e49d625920d19f989fd31cf8"
|
|||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.14"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
|
||||
[[package]]
|
||||
name = "value-bag"
|
||||
version = "1.10.0"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ef4c4aa54d5d05a279399bfa921ec387b7aba77caf7a682ae8d86785b8fdad2"
|
||||
checksum = "943ce29a8a743eb10d6082545d861b24f9d1b160b7d741e0f2cdf726bec909c5"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "client"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
default-run = "local_client"
|
||||
license = "MIT"
|
||||
repository = "git@github.com:boardgamers/clash.git"
|
||||
|
|
|
|||
BIN
client/assets/pirate-symbol-mark-svgrepo-com.png
Normal file
BIN
client/assets/pirate-symbol-mark-svgrepo-com.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 19 KiB |
|
|
@ -63,7 +63,7 @@ pub fn action_buttons(rc: &RenderContext) -> StateUpdate {
|
|||
);
|
||||
}
|
||||
let mut i = 0;
|
||||
for (a, origin) in &game.get_available_custom_actions(rc.shown_player.index) {
|
||||
for (a, origin) in &game.available_custom_actions(rc.shown_player.index) {
|
||||
if let Some(action) = generic_custom_action(rc, a, None) {
|
||||
if bottom_left_texture(
|
||||
rc,
|
||||
|
|
@ -89,7 +89,7 @@ pub fn custom_action_buttons<'a>(
|
|||
city: Option<&'a City>,
|
||||
) -> IconActionVec<'a> {
|
||||
rc.game
|
||||
.get_available_custom_actions(rc.shown_player.index)
|
||||
.available_custom_actions(rc.shown_player.index)
|
||||
.into_iter()
|
||||
.filter_map(|(a, origin)| {
|
||||
generic_custom_action(rc, &a, city).map(|action| {
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
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_dialog, Payment};
|
||||
use crate::payment_ui::{Payment, payment_dialog};
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::tooltip::show_tooltip_for_rect;
|
||||
use macroquad::color::Color;
|
||||
use macroquad::math::vec2;
|
||||
use macroquad::prelude::{
|
||||
draw_rectangle, draw_rectangle_lines, Rect, BLACK, BLUE, GRAY, WHITE, YELLOW,
|
||||
BLACK, BLUE, GRAY, Rect, WHITE, YELLOW, draw_rectangle, draw_rectangle_lines,
|
||||
};
|
||||
use server::action::Action;
|
||||
use server::advance::{Advance, Bonus};
|
||||
|
|
@ -87,14 +87,15 @@ pub fn show_advance_menu(
|
|||
);
|
||||
state.draw_text(name, pos.x + 10., pos.y + 22.);
|
||||
|
||||
let thickness = if let ActiveDialog::AdvancePayment(p) = &state.active_dialog {
|
||||
if p.name == *name {
|
||||
8.
|
||||
} else {
|
||||
4.
|
||||
let thickness = match &state.active_dialog {
|
||||
ActiveDialog::AdvancePayment(p) => {
|
||||
if p.name == *name {
|
||||
8.
|
||||
} else {
|
||||
4.
|
||||
}
|
||||
}
|
||||
} else {
|
||||
4.
|
||||
_ => 4.,
|
||||
};
|
||||
draw_rectangle_lines(
|
||||
rect.x,
|
||||
|
|
|
|||
|
|
@ -1,17 +1,21 @@
|
|||
use crate::client::Features;
|
||||
use macroquad::prelude::{load_texture, load_ttf_font, Font, ImageFormat};
|
||||
use macroquad::prelude::{Font, ImageFormat, load_texture, load_ttf_font};
|
||||
use macroquad::texture::Texture2D;
|
||||
use server::city_pieces::Building;
|
||||
use server::content::custom_actions::CustomActionType;
|
||||
use server::map::Terrain;
|
||||
use server::player::Player;
|
||||
use server::resource::ResourceType;
|
||||
use server::unit::UnitType;
|
||||
use std::collections::HashMap;
|
||||
|
||||
pub struct CivAssets {
|
||||
pub units: HashMap<UnitType, Texture2D>,
|
||||
}
|
||||
|
||||
pub struct Assets {
|
||||
pub terrain: HashMap<Terrain, Texture2D>,
|
||||
pub exhausted: Texture2D,
|
||||
pub units: HashMap<UnitType, Texture2D>,
|
||||
pub font: Font,
|
||||
|
||||
// mood icons
|
||||
|
|
@ -46,6 +50,8 @@ pub struct Assets {
|
|||
pub buildings: HashMap<Building, Texture2D>,
|
||||
pub wonders: HashMap<String, Texture2D>,
|
||||
pub custom_actions: HashMap<CustomActionType, Texture2D>,
|
||||
pub civ: HashMap<String, CivAssets>,
|
||||
pub default_civ: CivAssets,
|
||||
}
|
||||
|
||||
impl Assets {
|
||||
|
|
@ -55,11 +61,12 @@ impl Assets {
|
|||
font: load_ttf_font(&font_name).await.unwrap(), // can't share font - causes panic
|
||||
terrain: Self::terrain(features).await,
|
||||
exhausted: load_png(include_bytes!("../assets/cross-svgrepo-com.png")),
|
||||
units: Self::units(),
|
||||
|
||||
angry: load_png(include_bytes!("../assets/angry-face-svgrepo-com.png")),
|
||||
resources: Self::resources(),
|
||||
buildings: Self::buildings(),
|
||||
civ: Self::new_civ_assets(),
|
||||
default_civ: Self::new_default_civ(),
|
||||
wonders: Self::wonders(),
|
||||
custom_actions: Self::custom_actions(),
|
||||
|
||||
|
|
@ -107,36 +114,46 @@ impl Assets {
|
|||
.collect()
|
||||
}
|
||||
|
||||
fn units() -> HashMap<UnitType, Texture2D> {
|
||||
[
|
||||
fn units() -> Vec<(UnitType, Option<String>, Texture2D)> {
|
||||
vec![
|
||||
(
|
||||
UnitType::Infantry,
|
||||
None,
|
||||
load_png(include_bytes!("../assets/warrior-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
UnitType::Settler,
|
||||
None,
|
||||
load_png(include_bytes!("../assets/wagon-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
UnitType::Cavalry,
|
||||
None,
|
||||
load_png(include_bytes!("../assets/horse-head-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
UnitType::Elephant,
|
||||
None,
|
||||
load_png(include_bytes!("../assets/elephant-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
UnitType::Ship,
|
||||
None,
|
||||
load_png(include_bytes!("../assets/ship-svgrepo-com.png")),
|
||||
),
|
||||
(
|
||||
UnitType::Ship,
|
||||
Some("Pirates".to_string()),
|
||||
load_png(include_bytes!(
|
||||
"../assets/pirate-symbol-mark-svgrepo-com.png"
|
||||
)),
|
||||
),
|
||||
(
|
||||
UnitType::Leader,
|
||||
None,
|
||||
load_png(include_bytes!("../assets/flag-svgrepo-com.png")),
|
||||
),
|
||||
]
|
||||
.iter()
|
||||
.cloned()
|
||||
.collect()
|
||||
}
|
||||
|
||||
fn resources() -> HashMap<ResourceType, Texture2D> {
|
||||
|
|
@ -265,6 +282,39 @@ impl Assets {
|
|||
}
|
||||
map
|
||||
}
|
||||
|
||||
fn new_civ_assets() -> HashMap<String, CivAssets> {
|
||||
let mut result = HashMap::new();
|
||||
for (unit, civ, t) in Self::units() {
|
||||
if let Some(civ) = civ {
|
||||
result
|
||||
.entry(civ)
|
||||
.or_insert_with(|| CivAssets {
|
||||
units: HashMap::new(),
|
||||
})
|
||||
.units
|
||||
.insert(unit, t);
|
||||
}
|
||||
}
|
||||
result
|
||||
}
|
||||
|
||||
fn new_default_civ() -> CivAssets {
|
||||
let mut units = HashMap::new();
|
||||
for (unit, civ, t) in Self::units() {
|
||||
if civ.is_none() {
|
||||
units.insert(unit, t);
|
||||
}
|
||||
}
|
||||
CivAssets { units }
|
||||
}
|
||||
|
||||
pub fn unit(&self, unit_type: UnitType, player: &Player) -> &Texture2D {
|
||||
self.civ
|
||||
.get(&player.civilization.name)
|
||||
.and_then(|c| c.units.get(&unit_type))
|
||||
.unwrap_or(&self.default_civ.units[&unit_type])
|
||||
}
|
||||
}
|
||||
|
||||
fn load_png(bytes: &[u8]) -> Texture2D {
|
||||
|
|
|
|||
|
|
@ -9,13 +9,13 @@ use crate::select_ui::HighlightType;
|
|||
use crate::tooltip::show_tooltip_for_rect;
|
||||
use itertools::Itertools;
|
||||
use macroquad::color::BLACK;
|
||||
use macroquad::math::{vec2, Rect, Vec2};
|
||||
use macroquad::prelude::{draw_rectangle, draw_rectangle_lines, Color, GREEN, RED, YELLOW};
|
||||
use macroquad::math::{Rect, Vec2, vec2};
|
||||
use macroquad::prelude::{Color, GREEN, RED, YELLOW, draw_rectangle, draw_rectangle_lines};
|
||||
use server::action::Action;
|
||||
use server::card::{hand_cards, HandCard, HandCardType};
|
||||
use server::card::{HandCard, HandCardType, hand_cards};
|
||||
use server::content::action_cards::spy::validate_if_spy;
|
||||
use server::content::action_cards::{get_action_card, get_civil_card};
|
||||
use server::content::custom_phase_actions::EventResponse;
|
||||
use server::content::persistent_events::EventResponse;
|
||||
use server::content::wonders::get_wonder;
|
||||
use server::playing_actions::{PlayingAction, PlayingActionType};
|
||||
use server::tactics_card::CombatRole;
|
||||
|
|
@ -46,10 +46,9 @@ pub(crate) fn show_cards(rc: &RenderContext) -> StateUpdate {
|
|||
let cards = hand_cards(p, &HandCardType::get_all());
|
||||
let size = vec2(180., 30.);
|
||||
|
||||
let selection = if let ActiveDialog::HandCardsRequest(r) = &rc.state.active_dialog {
|
||||
Some(r)
|
||||
} else {
|
||||
None
|
||||
let selection = match &rc.state.active_dialog {
|
||||
ActiveDialog::HandCardsRequest(r) => Some(r),
|
||||
_ => None,
|
||||
};
|
||||
|
||||
let swap_cards = selection
|
||||
|
|
@ -207,14 +206,15 @@ fn get_card_object(rc: &RenderContext, card: &HandCard) -> HandCardObject {
|
|||
fn action_card_object(rc: &RenderContext, id: u8) -> HandCardObject {
|
||||
let a = get_action_card(id);
|
||||
|
||||
let name = if let Some(t) = &a.tactics_card {
|
||||
if get_combat(rc.game).is_some() {
|
||||
t.name.clone()
|
||||
} else {
|
||||
a.civil_card.name.clone()
|
||||
let name = match &a.tactics_card {
|
||||
Some(t) => {
|
||||
if get_combat(rc.game).is_some() {
|
||||
t.name.clone()
|
||||
} else {
|
||||
a.civil_card.name.clone()
|
||||
}
|
||||
}
|
||||
} else {
|
||||
a.civil_card.name.clone()
|
||||
_ => a.civil_card.name.clone(),
|
||||
};
|
||||
|
||||
let mut description = vec![format!("Civil: {}", a.civil_card.name)];
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::action_buttons::{
|
|||
};
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::collect_ui::CollectResources;
|
||||
use crate::construct_ui::{new_building_positions, ConstructionPayment, ConstructionProject};
|
||||
use crate::construct_ui::{ConstructionPayment, ConstructionProject, new_building_positions};
|
||||
use crate::custom_phase_ui::{SelectedStructureInfo, SelectedStructureStatus};
|
||||
use crate::happiness_ui::{
|
||||
add_increase_happiness, can_play_increase_happiness, open_increase_happiness_dialog,
|
||||
|
|
@ -22,7 +22,7 @@ use server::city_pieces::Building;
|
|||
use server::collect::possible_resource_collections;
|
||||
use server::construct::can_construct;
|
||||
use server::content::custom_actions::CustomActionType;
|
||||
use server::content::custom_phase_actions::Structure;
|
||||
use server::content::persistent_events::Structure;
|
||||
use server::events::EventOrigin;
|
||||
use server::game::Game;
|
||||
use server::playing_actions::PlayingActionType;
|
||||
|
|
@ -129,7 +129,7 @@ fn recruit_button<'a>(rc: &'a RenderContext, city: &'a City) -> Option<IconActio
|
|||
return None;
|
||||
}
|
||||
Some((
|
||||
&rc.assets().units[&UnitType::Infantry],
|
||||
rc.assets().unit(UnitType::Infantry, rc.shown_player),
|
||||
"Recruit Units".to_string(),
|
||||
Box::new(|| {
|
||||
RecruitAmount::new_selection(
|
||||
|
|
@ -293,15 +293,16 @@ pub fn draw_city(rc: &RenderContext, city: &City) -> Option<StateUpdate> {
|
|||
|
||||
fn draw_mood_state(rc: &RenderContext, city: &City, c: Vec2) {
|
||||
let state = &rc.state;
|
||||
let mood = if let ActiveDialog::IncreaseHappiness(increase) = &state.active_dialog {
|
||||
let steps = increase
|
||||
.steps
|
||||
.iter()
|
||||
.find(|(p, _)| p == &city.position)
|
||||
.map_or(&0, |(_, s)| s);
|
||||
&city.mood_state.clone().add(*steps)
|
||||
} else {
|
||||
&city.mood_state
|
||||
let mood = match &state.active_dialog {
|
||||
ActiveDialog::IncreaseHappiness(increase) => {
|
||||
let steps = increase
|
||||
.steps
|
||||
.iter()
|
||||
.find(|(p, _)| p == &city.position)
|
||||
.map_or(&0, |(_, s)| s);
|
||||
&city.mood_state.clone().add(*steps)
|
||||
}
|
||||
_ => &city.mood_state,
|
||||
};
|
||||
let t = match mood {
|
||||
MoodState::Happy => Some(&rc.assets().resources[&ResourceType::MoodTokens]),
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use macroquad::input::{is_mouse_button_pressed, MouseButton};
|
||||
use macroquad::input::{MouseButton, is_mouse_button_pressed};
|
||||
use macroquad::prelude::clear_background;
|
||||
use macroquad::prelude::*;
|
||||
|
||||
|
|
@ -13,7 +13,7 @@ use crate::client_state::{
|
|||
};
|
||||
use crate::collect_ui::collect_dialog;
|
||||
use crate::construct_ui::pay_construction_dialog;
|
||||
use crate::dialog_ui::{cancel_button, ok_button, OkTooltip};
|
||||
use crate::dialog_ui::{OkTooltip, cancel_button, ok_button};
|
||||
use crate::event_ui::custom_phase_event_origin;
|
||||
use crate::happiness_ui::{increase_happiness_click, increase_happiness_menu};
|
||||
use crate::hex_ui::pixel_to_coordinate;
|
||||
|
|
|
|||
|
|
@ -19,9 +19,9 @@ use macroquad::prelude::*;
|
|||
use server::action::Action;
|
||||
use server::card::HandCard;
|
||||
use server::city::{City, MoodState};
|
||||
use server::content::custom_phase_actions::{
|
||||
AdvanceRequest, ChangeGovernmentRequest, CurrentEventRequest, CurrentEventType, EventResponse,
|
||||
MultiRequest, PlayerRequest, UnitTypeRequest,
|
||||
use server::content::persistent_events::{
|
||||
AdvanceRequest, ChangeGovernmentRequest, EventResponse, MultiRequest, PersistentEventRequest,
|
||||
PersistentEventType, PlayerRequest, UnitTypeRequest,
|
||||
};
|
||||
use server::events::EventOrigin;
|
||||
use server::game::{Game, GameState};
|
||||
|
|
@ -303,20 +303,23 @@ impl StateUpdate {
|
|||
yes: Option<ActiveDialog>,
|
||||
no: Option<ActiveDialog>,
|
||||
) -> StateUpdate {
|
||||
if let Some(yes) = yes {
|
||||
if let Some(no) = no {
|
||||
StateUpdate::OpenDialog(ActiveDialog::DialogChooser(Box::new(DialogChooser {
|
||||
title: title.to_string(),
|
||||
yes,
|
||||
no,
|
||||
})))
|
||||
} else {
|
||||
StateUpdate::OpenDialog(yes)
|
||||
}
|
||||
} else if let Some(no) = no {
|
||||
StateUpdate::OpenDialog(no)
|
||||
} else {
|
||||
panic!("no dialog to open")
|
||||
match yes {
|
||||
Some(yes) => match no {
|
||||
Some(no) => {
|
||||
StateUpdate::OpenDialog(ActiveDialog::DialogChooser(Box::new(DialogChooser {
|
||||
title: title.to_string(),
|
||||
yes,
|
||||
no,
|
||||
})))
|
||||
}
|
||||
_ => StateUpdate::OpenDialog(yes),
|
||||
},
|
||||
_ => match no {
|
||||
Some(no) => StateUpdate::OpenDialog(no),
|
||||
_ => {
|
||||
panic!("no dialog to open")
|
||||
}
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -431,7 +434,7 @@ impl State {
|
|||
#[must_use]
|
||||
pub fn render_context<'a>(&'a self, game: &'a Game) -> RenderContext<'a> {
|
||||
RenderContext {
|
||||
shown_player: game.get_player(self.show_player),
|
||||
shown_player: game.player(self.show_player),
|
||||
game,
|
||||
state: self,
|
||||
camera_mode: CameraMode::Screen,
|
||||
|
|
@ -519,30 +522,32 @@ impl State {
|
|||
pub fn game_state_dialog(&self, game: &Game) -> ActiveDialog {
|
||||
if let Some(e) = &game.current_event_handler() {
|
||||
return match &e.request {
|
||||
CurrentEventRequest::Payment(r) => ActiveDialog::PaymentRequest(
|
||||
PersistentEventRequest::Payment(r) => ActiveDialog::PaymentRequest(
|
||||
r.iter()
|
||||
.map(|p| {
|
||||
Payment::new(
|
||||
&p.cost,
|
||||
&game.get_player(game.active_player()).resources,
|
||||
&game.player(game.active_player()).resources,
|
||||
&p.name,
|
||||
p.optional,
|
||||
)
|
||||
})
|
||||
.collect(),
|
||||
),
|
||||
CurrentEventRequest::ResourceReward(r) => {
|
||||
PersistentEventRequest::ResourceReward(r) => {
|
||||
ActiveDialog::ResourceRewardRequest(Payment::new_gain(&r.reward, &r.name))
|
||||
}
|
||||
CurrentEventRequest::SelectAdvance(r) => ActiveDialog::AdvanceRequest(r.clone()),
|
||||
CurrentEventRequest::SelectPositions(r) => {
|
||||
PersistentEventRequest::SelectAdvance(r) => ActiveDialog::AdvanceRequest(r.clone()),
|
||||
PersistentEventRequest::SelectPositions(r) => {
|
||||
ActiveDialog::PositionRequest(MultiSelection::new(r.request.clone()))
|
||||
}
|
||||
CurrentEventRequest::SelectUnitType(r) => ActiveDialog::UnitTypeRequest(r.clone()),
|
||||
CurrentEventRequest::SelectUnits(r) => {
|
||||
PersistentEventRequest::SelectUnitType(r) => {
|
||||
ActiveDialog::UnitTypeRequest(r.clone())
|
||||
}
|
||||
PersistentEventRequest::SelectUnits(r) => {
|
||||
ActiveDialog::UnitsRequest(UnitsSelection::new(r))
|
||||
}
|
||||
CurrentEventRequest::SelectStructures(r) => ActiveDialog::StructuresRequest(
|
||||
PersistentEventRequest::SelectStructures(r) => ActiveDialog::StructuresRequest(
|
||||
None,
|
||||
MultiSelection::new(MultiRequest::new(
|
||||
r.choices
|
||||
|
|
@ -561,23 +566,25 @@ impl State {
|
|||
&r.description,
|
||||
)),
|
||||
),
|
||||
CurrentEventRequest::SelectPlayer(r) => ActiveDialog::PlayerRequest(r.clone()),
|
||||
CurrentEventRequest::BoolRequest(d) => ActiveDialog::BoolRequest(d.clone()),
|
||||
CurrentEventRequest::ChangeGovernment(r) => {
|
||||
PersistentEventRequest::SelectPlayer(r) => ActiveDialog::PlayerRequest(r.clone()),
|
||||
PersistentEventRequest::BoolRequest(d) => ActiveDialog::BoolRequest(d.clone()),
|
||||
PersistentEventRequest::ChangeGovernment(r) => {
|
||||
ActiveDialog::ChangeGovernmentType(r.clone())
|
||||
}
|
||||
CurrentEventRequest::ExploreResolution => {
|
||||
if let CurrentEventType::ExploreResolution(r) = &game.current_event().event_type
|
||||
{
|
||||
ActiveDialog::ExploreResolution(ExploreResolutionConfig {
|
||||
block: r.block.clone(),
|
||||
rotation: r.block.position.rotation,
|
||||
})
|
||||
} else {
|
||||
panic!("ExploreResolution expected");
|
||||
PersistentEventRequest::ExploreResolution => {
|
||||
match &game.current_event().event_type {
|
||||
PersistentEventType::ExploreResolution(r) => {
|
||||
ActiveDialog::ExploreResolution(ExploreResolutionConfig {
|
||||
block: r.block.clone(),
|
||||
rotation: r.block.position.rotation,
|
||||
})
|
||||
}
|
||||
_ => {
|
||||
panic!("ExploreResolution expected");
|
||||
}
|
||||
}
|
||||
}
|
||||
CurrentEventRequest::SelectHandCards(r) => {
|
||||
PersistentEventRequest::SelectHandCards(r) => {
|
||||
ActiveDialog::HandCardsRequest(MultiSelection::new(r.request.clone()))
|
||||
}
|
||||
};
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::dialog_ui::{
|
||||
cancel_button, ok_button, BaseOrCustomAction, BaseOrCustomDialog, OkTooltip,
|
||||
BaseOrCustomAction, BaseOrCustomDialog, OkTooltip, cancel_button, ok_button,
|
||||
};
|
||||
use crate::event_ui::event_help;
|
||||
use crate::hex_ui;
|
||||
|
|
@ -9,13 +9,13 @@ use crate::render_context::RenderContext;
|
|||
use crate::resource_ui::{new_resource_map, resource_name, show_resource_pile};
|
||||
use itertools::Itertools;
|
||||
use macroquad::color::BLACK;
|
||||
use macroquad::math::{vec2, Vec2};
|
||||
use macroquad::math::{Vec2, vec2};
|
||||
use macroquad::prelude::WHITE;
|
||||
use macroquad::shapes::draw_circle;
|
||||
use server::action::Action;
|
||||
use server::collect::{
|
||||
get_total_collection, possible_resource_collections, tiles_used, CollectInfo,
|
||||
PositionCollection,
|
||||
CollectInfo, PositionCollection, get_total_collection, possible_resource_collections,
|
||||
tiles_used,
|
||||
};
|
||||
use server::content::custom_actions::CustomAction;
|
||||
use server::game::Game;
|
||||
|
|
@ -64,8 +64,8 @@ impl CollectResources {
|
|||
}
|
||||
|
||||
pub fn extra_resources(&self, game: &Game) -> i8 {
|
||||
let city = game.get_city(self.player_index, self.city_position);
|
||||
city.mood_modified_size(game.get_player(self.player_index)) as i8
|
||||
let city = game.city(self.player_index, self.city_position);
|
||||
city.mood_modified_size(game.player(self.player_index)) as i8
|
||||
- tiles_used(&self.collections) as i8
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ pub fn collect_dialog(rc: &RenderContext, collect: &CollectResources) -> StateUp
|
|||
show_resource_pile(rc, &collect.collected());
|
||||
|
||||
let game = rc.game;
|
||||
let city = game.get_city(collect.player_index, collect.city_position);
|
||||
let city = game.city(collect.player_index, collect.city_position);
|
||||
|
||||
let tooltip = get_total_collection(
|
||||
game,
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::payment_ui::{payment_dialog, Payment};
|
||||
use crate::payment_ui::{Payment, payment_dialog};
|
||||
use crate::recruit_unit_ui::RecruitSelection;
|
||||
use crate::render_context::RenderContext;
|
||||
use server::action::Action;
|
||||
|
|
@ -35,7 +35,7 @@ pub fn new_building_positions(
|
|||
}
|
||||
|
||||
pub fn pay_construction_dialog(rc: &RenderContext, cp: &ConstructionPayment) -> StateUpdate {
|
||||
let city = rc.game.get_any_city(cp.city_position);
|
||||
let city = rc.game.any_city(cp.city_position);
|
||||
payment_dialog(
|
||||
rc,
|
||||
&cp.payment.clone(),
|
||||
|
|
@ -89,7 +89,7 @@ impl ConstructionPayment {
|
|||
name: &str,
|
||||
project: ConstructionProject,
|
||||
) -> ConstructionPayment {
|
||||
let p = rc.game.get_player(city.player_index);
|
||||
let p = rc.game.player(city.player_index);
|
||||
let cost = match &project {
|
||||
ConstructionProject::Building(b, _) => p.construct_cost(rc.game, *b, None),
|
||||
ConstructionProject::Units(sel) => recruit_cost(
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::payment_ui::{payment_dialog, Payment};
|
||||
use crate::payment_ui::{Payment, payment_dialog};
|
||||
use crate::render_context::RenderContext;
|
||||
use server::action::Action;
|
||||
use server::content::custom_actions::CustomAction;
|
||||
|
|
|
|||
|
|
@ -1,22 +1,22 @@
|
|||
use crate::advance_ui::{show_advance_menu, AdvanceState};
|
||||
use crate::advance_ui::{AdvanceState, show_advance_menu};
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::dialog_ui::{
|
||||
cancel_button_with_tooltip, ok_button, BaseOrCustomAction, BaseOrCustomDialog, OkTooltip,
|
||||
BaseOrCustomAction, BaseOrCustomDialog, OkTooltip, cancel_button_with_tooltip, ok_button,
|
||||
};
|
||||
use crate::layout_ui::{bottom_center_anchor, bottom_centered_text, icon_pos};
|
||||
use crate::payment_ui::{multi_payment_dialog, payment_dialog, Payment};
|
||||
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::{draw_unit_type, UnitSelection};
|
||||
use crate::unit_ui::{UnitSelection, draw_unit_type};
|
||||
use itertools::Itertools;
|
||||
use macroquad::math::vec2;
|
||||
use server::action::Action;
|
||||
use server::content::custom_actions::CustomAction;
|
||||
use server::content::custom_phase_actions::{
|
||||
is_selected_structures_valid, AdvanceRequest, EventResponse, MultiRequest, PlayerRequest,
|
||||
SelectedStructure, Structure, UnitTypeRequest, UnitsRequest,
|
||||
use server::content::persistent_events::{
|
||||
AdvanceRequest, EventResponse, MultiRequest, PlayerRequest, SelectedStructure, Structure,
|
||||
UnitTypeRequest, UnitsRequest, is_selected_structures_valid,
|
||||
};
|
||||
use server::game::Game;
|
||||
use server::playing_actions::PlayingAction;
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::action_buttons::{base_or_custom_action, base_or_custom_available};
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::dialog_ui::{BaseOrCustomAction, BaseOrCustomDialog};
|
||||
use crate::payment_ui::{payment_dialog, Payment};
|
||||
use crate::payment_ui::{Payment, payment_dialog};
|
||||
use crate::render_context::RenderContext;
|
||||
use server::action::Action;
|
||||
use server::city::City;
|
||||
|
|
|
|||
|
|
@ -4,9 +4,9 @@ use crate::layout_ui::draw_scaled_icon;
|
|||
use crate::render_context::RenderContext;
|
||||
use hex2d::{Coordinate, Spacing};
|
||||
use macroquad::color::Color;
|
||||
use macroquad::math::{f32, vec2, Vec2};
|
||||
use macroquad::math::{Vec2, f32, vec2};
|
||||
use macroquad::prelude::{
|
||||
draw_texture_ex, DrawTextureParams, Rect, Texture2D, BEIGE, DARKGRAY, WHITE,
|
||||
BEIGE, DARKGRAY, DrawTextureParams, Rect, Texture2D, WHITE, draw_texture_ex,
|
||||
};
|
||||
use macroquad::shapes::draw_hexagon;
|
||||
use server::position::Position;
|
||||
|
|
|
|||
|
|
@ -6,7 +6,7 @@ use crate::render_context::RenderContext;
|
|||
use itertools::Itertools;
|
||||
use server::city::City;
|
||||
use server::content::custom_actions::CustomActionType;
|
||||
use server::content::custom_phase_actions::{MultiRequest, SelectedStructure, Structure};
|
||||
use server::content::persistent_events::{MultiRequest, SelectedStructure, Structure};
|
||||
use server::cultural_influence::influence_culture_boost_cost;
|
||||
use server::game::Game;
|
||||
use server::playing_actions::PlayingActionType;
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::log_ui::break_text;
|
|||
use crate::render_context::RenderContext;
|
||||
use crate::tooltip;
|
||||
use macroquad::color::WHITE;
|
||||
use macroquad::math::{f32, vec2, Vec2};
|
||||
use macroquad::math::{Vec2, f32, vec2};
|
||||
use macroquad::prelude::*;
|
||||
|
||||
pub const ICON_SIZE: f32 = 30.;
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
#![allow(clippy::missing_panics_doc)]
|
||||
|
||||
use client::client::{init, render_and_update, Features, GameSyncRequest, GameSyncResult};
|
||||
use client::client::{Features, GameSyncRequest, GameSyncResult, init, render_and_update};
|
||||
use macroquad::miniquad::window::set_window_size;
|
||||
use macroquad::prelude::{next_frame, screen_width, vec2};
|
||||
use macroquad::window::screen_height;
|
||||
|
|
@ -80,7 +80,7 @@ pub fn setup_local_game() -> Game {
|
|||
game.round = 6;
|
||||
game.dice_roll_outcomes = vec![1, 1, 10, 10, 10, 10, 10, 10, 10, 10];
|
||||
let add_unit = |game: &mut Game, pos: &str, player_index: usize, unit_type: UnitType| {
|
||||
game.get_player_mut(player_index)
|
||||
game.player_mut(player_index)
|
||||
.add_unit(Position::from_offset(pos), unit_type);
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::city_ui::{draw_city, show_city_menu, IconAction, IconActionVec};
|
||||
use crate::client_state::{ActiveDialog, State, StateUpdate, MAX_OFFSET, MIN_OFFSET, ZOOM};
|
||||
use crate::dialog_ui::{cancel_button_pos, ok_button, OkTooltip};
|
||||
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::move_ui::{movable_units, MoveDestination, MoveIntent};
|
||||
use crate::move_ui::{MoveDestination, MoveIntent, movable_units};
|
||||
use crate::player_ui::get_combat;
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::select_ui::HighlightType;
|
||||
|
|
@ -11,7 +11,7 @@ use macroquad::math::{f32, vec2};
|
|||
use macroquad::prelude::*;
|
||||
use server::action::Action;
|
||||
use server::combat::Combat;
|
||||
use server::content::custom_phase_actions::EventResponse;
|
||||
use server::content::persistent_events::EventResponse;
|
||||
use server::map::{Rotation, Terrain, UnexploredBlock};
|
||||
use server::playing_actions::{PlayingAction, PlayingActionType};
|
||||
use server::position::Position;
|
||||
|
|
@ -94,15 +94,15 @@ pub fn draw_map(rc: &RenderContext) -> StateUpdate {
|
|||
}
|
||||
|
||||
fn get_overlay(rc: &RenderContext) -> HashMap<Position, Terrain> {
|
||||
if let ActiveDialog::ExploreResolution(r) = &rc.state.active_dialog {
|
||||
r.block
|
||||
match &rc.state.active_dialog {
|
||||
ActiveDialog::ExploreResolution(r) => r
|
||||
.block
|
||||
.block
|
||||
.tiles(&r.block.position, r.rotation)
|
||||
.iter()
|
||||
.map(|(pos, t)| (*pos, t.clone()))
|
||||
.collect()
|
||||
} else {
|
||||
HashMap::new()
|
||||
.collect(),
|
||||
_ => HashMap::new(),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -235,7 +235,7 @@ fn found_city_button<'a>(rc: &'a RenderContext<'a>, pos: Position) -> Option<Ico
|
|||
.find(|(_, unit)| unit.can_found_city(game))
|
||||
.map(|(_index, unit)| {
|
||||
let action: IconAction<'a> = (
|
||||
&rc.assets().units[&UnitType::Settler],
|
||||
rc.assets().unit(UnitType::Settler, rc.shown_player),
|
||||
"Found a new city".to_string(),
|
||||
Box::new(move || {
|
||||
StateUpdate::execute(Action::Playing(PlayingAction::FoundCity {
|
||||
|
|
|
|||
|
|
@ -1,19 +1,19 @@
|
|||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::dialog_ui::cancel_button_with_tooltip;
|
||||
use crate::payment_ui::{payment_dialog, Payment};
|
||||
use crate::payment_ui::{Payment, payment_dialog};
|
||||
use crate::render_context::RenderContext;
|
||||
use crate::unit_ui::{click_unit, unit_selection_clicked};
|
||||
use macroquad::math::{u32, Vec2};
|
||||
use macroquad::math::{Vec2, u32};
|
||||
use macroquad::prelude::Texture2D;
|
||||
use server::action::Action;
|
||||
use server::events::EventOrigin;
|
||||
use server::game::{Game, GameState};
|
||||
use server::movement::{move_units_destinations, CurrentMove};
|
||||
use server::movement::{CurrentMove, MoveUnits, MovementAction, move_units_destinations};
|
||||
use server::payment::PaymentOptions;
|
||||
use server::player::Player;
|
||||
use server::position::Position;
|
||||
use server::resource_pile::ResourcePile;
|
||||
use server::unit::{MoveUnits, MovementAction, Unit, UnitType};
|
||||
use server::unit::{Unit, UnitType};
|
||||
use std::collections::HashSet;
|
||||
|
||||
#[derive(Clone, Copy)]
|
||||
|
|
@ -49,7 +49,7 @@ impl MoveIntent {
|
|||
pub fn icon<'a>(self, rc: &'a RenderContext) -> &'a Texture2D {
|
||||
match self {
|
||||
MoveIntent::Land => &rc.assets().move_units,
|
||||
MoveIntent::Sea => &rc.assets().units[&UnitType::Ship],
|
||||
MoveIntent::Sea => rc.assets().unit(UnitType::Ship, rc.shown_player),
|
||||
MoveIntent::Disembark => &rc.assets().export,
|
||||
}
|
||||
}
|
||||
|
|
@ -61,7 +61,7 @@ pub fn possible_destinations(
|
|||
player_index: usize,
|
||||
units: &[u32],
|
||||
) -> MoveDestinations {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
let mut modifiers = HashSet::new();
|
||||
|
||||
let mut res = move_units_destinations(player, game, units, start, None)
|
||||
|
|
@ -89,9 +89,9 @@ pub fn possible_destinations(
|
|||
|
||||
pub fn click(rc: &RenderContext, pos: Position, s: &MoveSelection, mouse_pos: Vec2) -> StateUpdate {
|
||||
let game = rc.game;
|
||||
let p = game.get_player(s.player_index);
|
||||
let p = game.player(s.player_index);
|
||||
let carrier = click_unit(rc, pos, mouse_pos, p, false);
|
||||
if let Some((destination, embark_carrier_id, cost)) = s
|
||||
match s
|
||||
.clone()
|
||||
.destinations
|
||||
.list
|
||||
|
|
@ -102,31 +102,35 @@ pub fn click(rc: &RenderContext, pos: Position, s: &MoveSelection, mouse_pos: Ve
|
|||
Some((pos, Some(id), PaymentOptions::free()))
|
||||
}
|
||||
_ => None,
|
||||
})
|
||||
{
|
||||
let units = s.units.clone();
|
||||
let action = MovementAction::Move(MoveUnits::new(
|
||||
units,
|
||||
destination,
|
||||
embark_carrier_id,
|
||||
ResourcePile::empty(),
|
||||
));
|
||||
}) {
|
||||
Some((destination, embark_carrier_id, cost)) => {
|
||||
let units = s.units.clone();
|
||||
let action = MovementAction::Move(MoveUnits::new(
|
||||
units,
|
||||
destination,
|
||||
embark_carrier_id,
|
||||
ResourcePile::empty(),
|
||||
));
|
||||
|
||||
if !cost.is_free() {
|
||||
return StateUpdate::OpenDialog(ActiveDialog::MovePayment(MovePayment {
|
||||
action,
|
||||
payment: rc.new_payment(&cost, "Move units", true),
|
||||
}));
|
||||
if !cost.is_free() {
|
||||
return StateUpdate::OpenDialog(ActiveDialog::MovePayment(MovePayment {
|
||||
action,
|
||||
payment: rc.new_payment(&cost, "Move units", true),
|
||||
}));
|
||||
}
|
||||
StateUpdate::execute(Action::Movement(action))
|
||||
}
|
||||
_ => {
|
||||
if s.start.is_some_and(|p| p != pos) {
|
||||
// first need to deselect units
|
||||
StateUpdate::None
|
||||
} else {
|
||||
click_unit(rc, pos, mouse_pos, p, true).map_or_else(
|
||||
|| tile_clicked(pos, s, game, p),
|
||||
|unit_id| unit_clicked(pos, s, game, p, unit_id),
|
||||
)
|
||||
}
|
||||
}
|
||||
StateUpdate::execute(Action::Movement(action))
|
||||
} else if s.start.is_some_and(|p| p != pos) {
|
||||
// first need to deselect units
|
||||
StateUpdate::None
|
||||
} else {
|
||||
click_unit(rc, pos, mouse_pos, p, true).map_or_else(
|
||||
|| tile_clicked(pos, s, game, p),
|
||||
|unit_id| unit_clicked(pos, s, game, p, unit_id),
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +222,7 @@ impl MoveSelection {
|
|||
current_move: &CurrentMove,
|
||||
) -> MoveSelection {
|
||||
if let CurrentMove::Fleet { units } = current_move {
|
||||
let fleet_pos = game.get_player(player_index).get_unit(units[0]).position;
|
||||
let fleet_pos = game.player(player_index).get_unit(units[0]).position;
|
||||
return MoveSelection {
|
||||
player_index,
|
||||
start: Some(fleet_pos),
|
||||
|
|
@ -232,7 +236,7 @@ impl MoveSelection {
|
|||
let movable_units = movable_units(
|
||||
pos,
|
||||
game,
|
||||
game.get_player(player_index),
|
||||
game.player(player_index),
|
||||
move_intent.to_predicate(),
|
||||
);
|
||||
if movable_units.is_empty() {
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ use crate::action_buttons::action_buttons;
|
|||
use crate::city_ui::city_labels;
|
||||
use crate::client::Features;
|
||||
use crate::client_state::StateUpdate;
|
||||
use crate::dialog_ui::{ok_button, OkTooltip};
|
||||
use crate::dialog_ui::{OkTooltip, ok_button};
|
||||
use crate::event_ui::event_help;
|
||||
use crate::layout_ui::{
|
||||
bottom_center_texture, bottom_centered_text, bottom_right_texture, icon_pos,
|
||||
left_mouse_button_pressed_in_rect, top_center_texture, ICON_SIZE,
|
||||
ICON_SIZE, bottom_center_texture, bottom_centered_text, bottom_right_texture, icon_pos,
|
||||
left_mouse_button_pressed_in_rect, top_center_texture,
|
||||
};
|
||||
use crate::log_ui::multiline_label;
|
||||
use crate::map_ui::terrain_name;
|
||||
|
|
@ -14,20 +14,20 @@ use crate::render_context::RenderContext;
|
|||
use crate::resource_ui::{new_resource_map, resource_name};
|
||||
use crate::tooltip::show_tooltip_for_rect;
|
||||
use crate::unit_ui;
|
||||
use itertools::Itertools;
|
||||
use macroquad::math::vec2;
|
||||
use macroquad::prelude::*;
|
||||
use server::action::Action;
|
||||
use server::combat::Combat;
|
||||
use server::consts::ARMY_MOVEMENT_REQUIRED_ADVANCE;
|
||||
use server::content::custom_phase_actions::CurrentEventType;
|
||||
use server::content::persistent_events::PersistentEventType;
|
||||
use server::game::{Game, GameState};
|
||||
use server::movement::CurrentMove;
|
||||
use server::movement::{CurrentMove, MovementAction};
|
||||
use server::player::Player;
|
||||
use server::playing_actions::PlayingAction;
|
||||
use server::position::Position;
|
||||
use server::resource::ResourceType;
|
||||
use server::status_phase::get_status_phase;
|
||||
use server::unit::MovementAction;
|
||||
|
||||
pub fn player_select(rc: &RenderContext) -> StateUpdate {
|
||||
let game = rc.game;
|
||||
|
|
@ -37,7 +37,7 @@ pub fn player_select(rc: &RenderContext) -> StateUpdate {
|
|||
let mut y = (players.len() as f32 * -size) / 2.;
|
||||
|
||||
for player_index in players {
|
||||
let pl = game.get_player(player_index);
|
||||
let pl = game.player(player_index);
|
||||
let shown = rc.shown_player.index == pl.index;
|
||||
let screen = rc.state.screen_size;
|
||||
let pos = vec2(screen.x, screen.y / 2.0) + vec2(-size, y);
|
||||
|
|
@ -254,10 +254,13 @@ fn show_focused_tile(label: &mut impl FnMut(&str), game: &Game, position: Positi
|
|||
}
|
||||
}
|
||||
|
||||
for (p, unit) in unit_ui::units_on_tile(game, position) {
|
||||
let army_move = game
|
||||
.get_player(p)
|
||||
.has_advance(ARMY_MOVEMENT_REQUIRED_ADVANCE);
|
||||
let units = unit_ui::units_on_tile(game, position).collect_vec();
|
||||
if !units.is_empty() {
|
||||
label(&format!("Controlled by: {}", game.player_name(units[0].0)));
|
||||
}
|
||||
|
||||
for (p, unit) in units {
|
||||
let army_move = game.player(p).has_advance(ARMY_MOVEMENT_REQUIRED_ADVANCE);
|
||||
label(&unit_ui::unit_label(&unit, army_move));
|
||||
}
|
||||
}
|
||||
|
|
@ -285,10 +288,10 @@ fn show_permanent_effects(
|
|||
|
||||
pub fn get_combat(game: &Game) -> Option<&Combat> {
|
||||
game.events.last().and_then(|e| match &e.event_type {
|
||||
CurrentEventType::CombatStart(c) => Some(c),
|
||||
CurrentEventType::CombatRoundStart(s) => Some(&s.combat),
|
||||
CurrentEventType::CombatRoundEnd(e) => Some(&e.combat),
|
||||
CurrentEventType::CombatEnd(e) => Some(&e.combat),
|
||||
PersistentEventType::CombatStart(c) => Some(c),
|
||||
PersistentEventType::CombatRoundStart(s) => Some(&s.combat),
|
||||
PersistentEventType::CombatRoundEnd(e) => Some(&e.combat),
|
||||
PersistentEventType::CombatEnd(e) => Some(&e.combat),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -8,11 +8,11 @@ use server::unit::{Unit, UnitType, Units};
|
|||
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::construct_ui::{ConstructionPayment, ConstructionProject};
|
||||
use crate::dialog_ui::{cancel_button, ok_button, OkTooltip};
|
||||
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::{draw_unit_type, UnitSelection};
|
||||
use crate::{select_ui, unit_ui};
|
||||
use crate::unit_ui::{UnitSelection, draw_unit_type};
|
||||
|
||||
#[derive(Clone)]
|
||||
pub struct SelectableUnit {
|
||||
|
|
@ -46,7 +46,7 @@ impl RecruitAmount {
|
|||
leader_name: Option<&String>,
|
||||
must_show_units: &[SelectableUnit],
|
||||
) -> StateUpdate {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
let selectable: Vec<SelectableUnit> = new_units(player)
|
||||
.into_iter()
|
||||
.filter_map(|u| {
|
||||
|
|
@ -138,9 +138,9 @@ impl NewUnit {
|
|||
}
|
||||
|
||||
fn new_units(player: &Player) -> Vec<NewUnit> {
|
||||
unit_ui::non_leader_names()
|
||||
UnitType::get_all()
|
||||
.into_iter()
|
||||
.map(|(u, n)| NewUnit::new(u, n, None::<String>))
|
||||
.map(|u| NewUnit::new(u, u.name(), None::<String>))
|
||||
.chain(
|
||||
player
|
||||
.available_leaders
|
||||
|
|
@ -166,7 +166,7 @@ impl RecruitSelection {
|
|||
amount: RecruitAmount,
|
||||
replaced_units: Vec<u32>,
|
||||
) -> RecruitSelection {
|
||||
let available_units = game.get_player(amount.player_index).available_units();
|
||||
let available_units = game.player(amount.player_index).available_units();
|
||||
let need_replacement = available_units.get_units_to_replace(&amount.units);
|
||||
|
||||
RecruitSelection {
|
||||
|
|
@ -184,7 +184,7 @@ impl RecruitSelection {
|
|||
|
||||
pub fn confirm(&self, game: &Game) -> OkTooltip {
|
||||
if recruit_cost(
|
||||
game.get_player(self.amount.player_index),
|
||||
game.player(self.amount.player_index),
|
||||
&self.amount.units,
|
||||
self.amount.city_position,
|
||||
self.amount.leader_name.as_ref(),
|
||||
|
|
@ -278,7 +278,7 @@ fn open_dialog(rc: &RenderContext, city: Position, sel: RecruitSelection) -> Sta
|
|||
let p = rc.shown_player.index;
|
||||
StateUpdate::OpenDialog(ActiveDialog::ConstructionPayment(ConstructionPayment::new(
|
||||
rc,
|
||||
rc.game.get_city(p, city),
|
||||
rc.game.city(p, city),
|
||||
&format!(
|
||||
"Recruit {}{} in {}",
|
||||
sel.amount.units,
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use server::game::Game;
|
|||
use macroquad::prelude::next_frame;
|
||||
|
||||
extern crate console_error_panic_hook;
|
||||
use client::client::{init, render_and_update, Features, GameSyncRequest, GameSyncResult};
|
||||
use client::client::{Features, GameSyncRequest, GameSyncResult, init, render_and_update};
|
||||
use client::client_state::State;
|
||||
use macroquad::math::vec2;
|
||||
use server::action::Action;
|
||||
|
|
|
|||
|
|
@ -4,8 +4,8 @@ use crate::payment_ui::Payment;
|
|||
use macroquad::camera::set_default_camera;
|
||||
use macroquad::color::{Color, PINK, YELLOW};
|
||||
use macroquad::input::mouse_position;
|
||||
use macroquad::math::{bool, Vec2};
|
||||
use macroquad::prelude::{set_camera, GRAY, WHITE};
|
||||
use macroquad::math::{Vec2, bool};
|
||||
use macroquad::prelude::{BLACK, GRAY, LIME, SKYBLUE, set_camera};
|
||||
use server::game::Game;
|
||||
use server::payment::PaymentOptions;
|
||||
use server::player::Player;
|
||||
|
|
@ -88,16 +88,18 @@ impl RenderContext<'_> {
|
|||
}
|
||||
|
||||
pub fn player_color(&self, player_index: usize) -> Color {
|
||||
let c = &self.game.get_player(player_index).civilization;
|
||||
let c = &self.game.player(player_index).civilization;
|
||||
if c.is_barbarian() {
|
||||
return GRAY;
|
||||
}
|
||||
if c.is_pirates() {
|
||||
return WHITE;
|
||||
return BLACK;
|
||||
}
|
||||
match player_index {
|
||||
0 => YELLOW,
|
||||
1 => PINK,
|
||||
2 => SKYBLUE,
|
||||
3 => LIME,
|
||||
_ => panic!("unexpected player index"),
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::client_state::StateUpdate;
|
||||
use crate::dialog_ui::{cancel_button, ok_button, OkTooltip};
|
||||
use crate::layout_ui::{bottom_center_anchor, bottom_center_texture, ICON_SIZE};
|
||||
use crate::dialog_ui::{OkTooltip, cancel_button, ok_button};
|
||||
use crate::layout_ui::{ICON_SIZE, bottom_center_anchor, bottom_center_texture};
|
||||
use crate::render_context::RenderContext;
|
||||
use macroquad::color::{Color, BLACK, BLUE, WHITE};
|
||||
use macroquad::math::{bool, vec2, Vec2};
|
||||
use macroquad::color::{BLACK, BLUE, Color, WHITE};
|
||||
use macroquad::math::{Vec2, bool, vec2};
|
||||
use macroquad::prelude::{GRAY, RED};
|
||||
|
||||
#[derive(PartialEq, Eq, Debug, Clone)]
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::advance_ui::{show_advance_menu, AdvanceState};
|
||||
use crate::advance_ui::{AdvanceState, show_advance_menu};
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::dialog_ui::{cancel_button_with_tooltip, ok_button, OkTooltip};
|
||||
use crate::dialog_ui::{OkTooltip, cancel_button_with_tooltip, ok_button};
|
||||
use crate::render_context::RenderContext;
|
||||
use server::content::advances::{get_government, get_governments};
|
||||
use server::content::custom_phase_actions::{ChangeGovernmentRequest, EventResponse};
|
||||
use server::content::persistent_events::{ChangeGovernmentRequest, EventResponse};
|
||||
use server::status_phase::{ChangeGovernment, ChangeGovernmentType};
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::client_state::{CameraMode, MousePosition, State, StateUpdate};
|
|||
use crate::render_context::RenderContext;
|
||||
use macroquad::color::{Color, GRAY};
|
||||
use macroquad::input::mouse_position;
|
||||
use macroquad::math::{bool, f32, f64, vec2, Rect, Vec2};
|
||||
use macroquad::math::{Rect, Vec2, bool, f32, f64, vec2};
|
||||
use macroquad::prelude::{draw_circle, draw_rectangle, get_time};
|
||||
|
||||
const TOOLTIP_DELAY: f64 = 0.5;
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use macroquad::math::{u32, vec2, Vec2};
|
||||
use macroquad::math::{Vec2, u32, vec2};
|
||||
use macroquad::shapes::draw_circle;
|
||||
|
||||
use server::game::Game;
|
||||
use server::position::Position;
|
||||
use server::unit::{carried_units, MovementRestriction, Unit, UnitType};
|
||||
use server::unit::{Unit, UnitType, carried_units};
|
||||
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::hex_ui;
|
||||
|
|
@ -15,6 +15,7 @@ use crate::render_context::RenderContext;
|
|||
use crate::tooltip::show_tooltip_for_circle;
|
||||
use itertools::Itertools;
|
||||
use server::consts::ARMY_MOVEMENT_REQUIRED_ADVANCE;
|
||||
use server::movement::MovementRestriction;
|
||||
use server::player::Player;
|
||||
|
||||
pub struct UnitPlace {
|
||||
|
|
@ -48,7 +49,7 @@ pub fn draw_unit_type(
|
|||
let icon_size = size * 1.1;
|
||||
draw_scaled_icon(
|
||||
rc,
|
||||
&rc.assets().units[&unit_type],
|
||||
rc.assets().unit(unit_type, rc.game.player(player_index)),
|
||||
tooltip,
|
||||
vec2(center.x - icon_size / 2., center.y - icon_size / 2.),
|
||||
icon_size,
|
||||
|
|
@ -110,16 +111,6 @@ pub fn click_unit(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn non_leader_names() -> [(UnitType, &'static str); 5] {
|
||||
[
|
||||
(UnitType::Settler, "Settler"),
|
||||
(UnitType::Infantry, "Infantry"),
|
||||
(UnitType::Ship, "Ship"),
|
||||
(UnitType::Elephant, "Elephant"),
|
||||
(UnitType::Cavalry, "Cavalry"),
|
||||
]
|
||||
}
|
||||
|
||||
pub fn draw_units(rc: &RenderContext, tooltip: bool) {
|
||||
let player = rc.shown_player.index;
|
||||
let highlighted_units = match rc.state.active_dialog {
|
||||
|
|
@ -176,7 +167,7 @@ pub fn draw_units(rc: &RenderContext, tooltip: bool) {
|
|||
|
||||
draw_unit(rc, tooltip, &highlighted_units, *p, u, &place);
|
||||
|
||||
let player = rc.game.get_player(*p);
|
||||
let player = rc.game.player(*p);
|
||||
let game = rc.game;
|
||||
let player_index = *p;
|
||||
let carrier = u.id;
|
||||
|
|
@ -223,7 +214,7 @@ fn draw_unit(
|
|||
let game = &rc.game;
|
||||
if tooltip {
|
||||
let army_move = game
|
||||
.get_player(player_index)
|
||||
.player(player_index)
|
||||
.has_advance(ARMY_MOVEMENT_REQUIRED_ADVANCE);
|
||||
show_tooltip_for_circle(rc, &unit_label(unit, army_move), center, radius);
|
||||
} else {
|
||||
|
|
@ -257,7 +248,7 @@ pub fn unit_selection_click<T: UnitSelection + Clone>(
|
|||
sel: &T,
|
||||
on_change: impl Fn(T) -> StateUpdate,
|
||||
) -> StateUpdate {
|
||||
let p = rc.game.get_player(sel.player_index());
|
||||
let p = rc.game.player(sel.player_index());
|
||||
if let Some(unit_id) = click_unit(rc, pos, mouse_pos, p, true) {
|
||||
if sel.can_select(rc.game, p.get_unit(unit_id)) {
|
||||
let mut new = sel.clone();
|
||||
|
|
@ -284,11 +275,7 @@ pub fn name(u: &UnitType) -> &str {
|
|||
if let UnitType::Leader = u {
|
||||
return "Leader";
|
||||
}
|
||||
non_leader_names()
|
||||
.into_iter()
|
||||
.find(|(unit_type, _)| unit_type == u)
|
||||
.unwrap()
|
||||
.1
|
||||
u.name()
|
||||
}
|
||||
|
||||
pub fn unit_label(unit: &Unit, army_move: bool) -> String {
|
||||
|
|
|
|||
3
mise.lock
Normal file
3
mise.lock
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
[tools.rust]
|
||||
version = "1.85.1"
|
||||
backend = "core:rust"
|
||||
|
|
@ -23,3 +23,6 @@ dir = "client"
|
|||
[tasks.format-and-lint]
|
||||
depends = ["server-format-and-lint", "client-format-and-lint"]
|
||||
|
||||
[tools]
|
||||
rust = { version = "latest", components = "clippy,rustfmt" }
|
||||
|
||||
|
|
|
|||
84
server/Cargo.lock
generated
84
server/Cargo.lock
generated
|
|
@ -78,7 +78,7 @@ version = "3.4.0"
|
|||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ff6e472cdea888a4bd64f342f09b3f50e1886d32afe8df3d663c01140b811b18"
|
||||
dependencies = [
|
||||
"event-listener 5.3.1",
|
||||
"event-listener 5.4.0",
|
||||
"event-listener-strategy",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
|
@ -129,9 +129,9 @@ checksum = "ace50bade8e6234aa140d9a2f552bbee1db4d353f69b8217bc503490fc1a9f26"
|
|||
|
||||
[[package]]
|
||||
name = "bitflags"
|
||||
version = "2.6.0"
|
||||
version = "2.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b048fb63fd8b5923fc5aa7b340d8e156aec7ec02f0c78fa8a6ddc2613f6f71de"
|
||||
checksum = "5c8214115b7bf84099f1309324e63141d4c5d7cc26862f97a0a857dbefe165bd"
|
||||
|
||||
[[package]]
|
||||
name = "blocking"
|
||||
|
|
@ -148,9 +148,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.16.0"
|
||||
version = "3.17.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "79296716171880943b8470b5f8d03aa55eb2e645a4874bdbb28adb49162e012c"
|
||||
checksum = "1628fb46dfa0b37568d12e5edd512553eccf6a22a78e8bde00bb4aed84d5bdbf"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
|
|
@ -185,9 +185,9 @@ checksum = "d0a5c400df2834b80a4c3327b3aad3a4c4cd4de0629063962b03235697506a28"
|
|||
|
||||
[[package]]
|
||||
name = "either"
|
||||
version = "1.13.0"
|
||||
version = "1.15.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "60b1af1c220855b6ceac025d3f6ecdd2b7c4894bfe9cd9bda4fbb4bc7c0d4cf0"
|
||||
checksum = "48c757948c5ede0e46177b7add2e67155f70e33c07fea8284df6576da70b3719"
|
||||
|
||||
[[package]]
|
||||
name = "errno"
|
||||
|
|
@ -207,9 +207,9 @@ checksum = "0206175f82b8d6bf6652ff7d71a1e27fd2e4efde587fd368662814d6ec1d9ce0"
|
|||
|
||||
[[package]]
|
||||
name = "event-listener"
|
||||
version = "5.3.1"
|
||||
version = "5.4.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6032be9bd27023a771701cc49f9f053c751055f71efb2e0ae5c15809093675ba"
|
||||
checksum = "3492acde4c3fc54c845eaab3eed8bd00c7a7d881f78bfc801e43a93dec1331ae"
|
||||
dependencies = [
|
||||
"concurrent-queue",
|
||||
"parking",
|
||||
|
|
@ -218,11 +218,11 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "event-listener-strategy"
|
||||
version = "0.5.3"
|
||||
version = "0.5.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3c3e4e0dd3673c1139bf041f3008816d9cf2946bbfac2945c09e523b8d7b05b2"
|
||||
checksum = "8be9f3dfaaffdae2972880079a491a1a8bb7cbed0b8dd7a347f668b4150a3b93"
|
||||
dependencies = [
|
||||
"event-listener 5.3.1",
|
||||
"event-listener 5.4.0",
|
||||
"pin-project-lite",
|
||||
]
|
||||
|
||||
|
|
@ -255,9 +255,9 @@ checksum = "9e5c1b78ca4aae1ac06c48a526a655760685149f0d465d21f37abfe57ce075c6"
|
|||
|
||||
[[package]]
|
||||
name = "futures-lite"
|
||||
version = "2.5.0"
|
||||
version = "2.6.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cef40d21ae2c515b51041df9ed313ed21e572df340ea58a922a0aefe7e8891a1"
|
||||
checksum = "f5edaec856126859abb19ed65f39e90fea3a9574b9707f13539acf4abf7eb532"
|
||||
dependencies = [
|
||||
"fastrand",
|
||||
"futures-core",
|
||||
|
|
@ -306,9 +306,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.14"
|
||||
version = "1.0.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d75a2a4b1b190afb6f5425f10f6a8f959d2ea0b9c2b1d79553551850539e4674"
|
||||
checksum = "4a5f13b858c8d314ee3e8f639011f7ccefe71f97f96e50151fb991f267928e2c"
|
||||
|
||||
[[package]]
|
||||
name = "js-sys"
|
||||
|
|
@ -353,21 +353,21 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "libc"
|
||||
version = "0.2.169"
|
||||
version = "0.2.171"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "b5aba8db14291edd000dfcc4d620c7ebfb122c613afb886ca8803fa4e128a20a"
|
||||
checksum = "c19937216e9d3aa9956d9bb8dfc0b0c8beb6058fc4f7a4dc4d850edf86a237d6"
|
||||
|
||||
[[package]]
|
||||
name = "linux-raw-sys"
|
||||
version = "0.4.14"
|
||||
version = "0.4.15"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "78b3ae25bc7c8c38cec158d1f2757ee79e9b3740fbc7ccf0e59e4b08d793fa89"
|
||||
checksum = "d26c52dbd32dccf2d10cac7725f8eae5296885fb5703b261f7d0a0739ec807ab"
|
||||
|
||||
[[package]]
|
||||
name = "log"
|
||||
version = "0.4.22"
|
||||
version = "0.4.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a7a70ba024b9dc04c27ea2f0c0548feb474ec5c54bba33a7f72f873a39d07b24"
|
||||
checksum = "13dc2df351e3202783a1fe0d44375f7295ffb4049267b0f3018346dc122a1d94"
|
||||
dependencies = [
|
||||
"value-bag",
|
||||
]
|
||||
|
|
@ -453,9 +453,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.20.2"
|
||||
version = "1.21.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1261fe7e33c73b354eab43b1273a57c8f967d0391e80353e51f764ac02cf6775"
|
||||
checksum = "42f5e15c9953c5e4ccceeb2e7382a716482c34515315f7b03532b8b4e8393d2d"
|
||||
|
||||
[[package]]
|
||||
name = "parking"
|
||||
|
|
@ -465,9 +465,9 @@ checksum = "f38d5652c16fde515bb1ecef450ab0f6a219d619a7274976324d5e377f7dceba"
|
|||
|
||||
[[package]]
|
||||
name = "pin-project-lite"
|
||||
version = "0.2.15"
|
||||
version = "0.2.16"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "915a1e146535de9163f3987b8944ed8cf49a18bb0056bcebcdcece385cece4ff"
|
||||
checksum = "3b3cff922bd51709b605d9ead9aa71031d81447142d828eb4a6eba76fe619f9b"
|
||||
|
||||
[[package]]
|
||||
name = "pin-utils"
|
||||
|
|
@ -503,9 +503,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.92"
|
||||
version = "1.0.94"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "37d3544b3f2748c54e147655edb5025752e2303145b5aefb3c3ea2c78b973bb0"
|
||||
checksum = "a31971752e70b8b2686d7e46ec17fb38dad4051d94024c88df49b667caea9c84"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
|
@ -518,18 +518,18 @@ checksum = "5a651516ddc9168ebd67b24afd085a718be02f8858fe406591b013d101ce2f40"
|
|||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.38"
|
||||
version = "1.0.40"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "0e4dccaaaf89514f546c693ddc140f729f958c247918a13380cccc6078391acc"
|
||||
checksum = "1885c039570dc00dcb4ff087a89e185fd56bae234ddc7f056a945bf36467248d"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustix"
|
||||
version = "0.38.42"
|
||||
version = "0.38.44"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f93dc38ecbab2eb790ff964bb77fa94faf256fd3e73285fd7ba0903b76bedb85"
|
||||
checksum = "fdb5bc1ae2baa591800df16c9ca78619bf65c0488b41b96ccec5d11220d8c154"
|
||||
dependencies = [
|
||||
"bitflags",
|
||||
"errno",
|
||||
|
|
@ -540,15 +540,15 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.19"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f7c45b9784283f1b2e7fb61b42047c2fd678ef0960d4f6f1eba131594cc369d4"
|
||||
checksum = "eded382c5f5f786b989652c49544c4877d9f015cc22e145a5ea8ea66c2921cd2"
|
||||
|
||||
[[package]]
|
||||
name = "ryu"
|
||||
version = "1.0.18"
|
||||
version = "1.0.20"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f3cb5ba0dc43242ce17de99c180e96db90b235b8a9fdc9543c96d2209116bd9f"
|
||||
checksum = "28d3b2b1366ec20994f1fd18c3c594f05c5dd4bc44d8bb0c1c632c8d6829481f"
|
||||
|
||||
[[package]]
|
||||
name = "serde"
|
||||
|
|
@ -622,9 +622,9 @@ dependencies = [
|
|||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "2.0.91"
|
||||
version = "2.0.100"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d53cbcb5a243bd33b7858b1d7f4aca2153490815872d86d955d6ea29f743c035"
|
||||
checksum = "b09a44accad81e1ba1cd74a32461ba89dee89095ba17b32f5d03683b1b1fc2a0"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
|
|
@ -669,15 +669,15 @@ checksum = "e672c95779cf947c5311f83787af4fa8fffd12fb27e4993211a84bdfd9610f9c"
|
|||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.14"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "adb9e6ca4f869e1180728b7950e35922a7fc6397f7b641499e8f3ef06e50dc83"
|
||||
checksum = "5a5f39404a5da50712a4c1eecf25e90dd62b613502b7e925fd4e4d19b5c96512"
|
||||
|
||||
[[package]]
|
||||
name = "value-bag"
|
||||
version = "1.10.0"
|
||||
version = "1.11.1"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "3ef4c4aa54d5d05a279399bfa921ec387b7aba77caf7a682ae8d86785b8fdad2"
|
||||
checksum = "943ce29a8a743eb10d6082545d861b24f9d1b160b7d741e0f2cdf726bec909c5"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
[package]
|
||||
name = "server"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
edition = "2024"
|
||||
license = "MIT"
|
||||
repository = "git@github.com:boardgamers/clash.git"
|
||||
homepage = "https://www.boardgamers.space/"
|
||||
|
|
|
|||
|
|
@ -1,13 +1,13 @@
|
|||
use crate::card::HandCard;
|
||||
use crate::combat::{update_combat_strength, Combat};
|
||||
use crate::combat::{Combat, update_combat_strength};
|
||||
use crate::combat_listeners::CombatStrength;
|
||||
use crate::content::custom_phase_actions::{
|
||||
AdvanceRequest, CurrentEventHandler, CurrentEventRequest, EventResponse, HandCardsRequest,
|
||||
MultiRequest, PaymentRequest, PlayerRequest, PositionRequest, ResourceRewardRequest,
|
||||
SelectedStructure, StructuresRequest, UnitTypeRequest, UnitsRequest,
|
||||
use crate::content::persistent_events::{
|
||||
AdvanceRequest, EventResponse, HandCardsRequest, MultiRequest, PaymentRequest,
|
||||
PersistentEventHandler, PersistentEventRequest, PlayerRequest, PositionRequest,
|
||||
ResourceRewardRequest, SelectedStructure, StructuresRequest, UnitTypeRequest, UnitsRequest,
|
||||
};
|
||||
use crate::events::{Event, EventOrigin};
|
||||
use crate::player_events::{CurrentEvent, PersistentEvents, TransientEvents};
|
||||
use crate::player_events::{PersistentEvent, PersistentEvents, TransientEvents};
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::tactics_card::CombatRole;
|
||||
|
|
@ -186,7 +186,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
listener: impl Fn(&Game, &Combat, &mut CombatStrength, CombatRole) + Clone + 'static,
|
||||
) -> Self {
|
||||
self.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_combat_round_start,
|
||||
|event| &mut event.combat_round_start,
|
||||
priority,
|
||||
move |game, p, _, s| {
|
||||
update_combat_strength(game, p, s, {
|
||||
|
|
@ -215,19 +215,19 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
})
|
||||
}
|
||||
|
||||
fn add_current_event_listener<E, V>(
|
||||
fn add_persistent_event_listener<E, V>(
|
||||
self,
|
||||
event: E,
|
||||
priority: i32,
|
||||
start_custom_phase: impl Fn(&mut Game, usize, &str, &mut V) -> Option<CurrentEventRequest>
|
||||
+ 'static
|
||||
+ Clone,
|
||||
end_custom_phase: impl Fn(&mut Game, usize, &str, EventResponse, CurrentEventRequest, &mut V)
|
||||
+ 'static
|
||||
+ Clone,
|
||||
start_custom_phase: impl Fn(&mut Game, usize, &str, &mut V) -> Option<PersistentEventRequest>
|
||||
+ 'static
|
||||
+ Clone,
|
||||
end_custom_phase: impl Fn(&mut Game, usize, &str, EventResponse, PersistentEventRequest, &mut V)
|
||||
+ 'static
|
||||
+ Clone,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
let origin = self.get_key();
|
||||
|
|
@ -273,6 +273,12 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
}
|
||||
}
|
||||
|
||||
if game.current_event().player.skip_first_priority {
|
||||
game.current_event_mut().player.last_priority_used = Some(priority);
|
||||
// already handled before
|
||||
return;
|
||||
}
|
||||
|
||||
if game
|
||||
.current_event()
|
||||
.player
|
||||
|
|
@ -287,7 +293,7 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
{
|
||||
let s = game.current_event_mut();
|
||||
s.player.last_priority_used = Some(priority);
|
||||
s.player.handler = Some(CurrentEventHandler {
|
||||
s.player.handler = Some(PersistentEventHandler {
|
||||
priority,
|
||||
request: request.clone(),
|
||||
response: None,
|
||||
|
|
@ -305,11 +311,11 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
listener: F,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
F: Fn(&mut Game, usize, &str, &mut V) + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.add_current_event_listener(
|
||||
self.add_persistent_event_listener(
|
||||
event,
|
||||
priority,
|
||||
move |game, player_index, player_name, details| {
|
||||
|
|
@ -329,22 +335,22 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
gain_reward: impl Fn(&mut Game, &SelectedChoice<Vec<ResourcePile>>, &mut V) + 'static + Clone,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.add_current_event_listener(
|
||||
self.add_persistent_event_listener(
|
||||
event,
|
||||
priority,
|
||||
move |game, player_index, _player_name, details| {
|
||||
request(game, player_index, details)
|
||||
.filter(|r| {
|
||||
r.iter()
|
||||
.any(|r| game.get_player(player_index).can_afford(&r.cost))
|
||||
.any(|r| game.player(player_index).can_afford(&r.cost))
|
||||
})
|
||||
.map(CurrentEventRequest::Payment)
|
||||
.map(PersistentEventRequest::Payment)
|
||||
},
|
||||
move |game, player_index, player_name, action, request, details| {
|
||||
if let CurrentEventRequest::Payment(requests) = &request {
|
||||
if let PersistentEventRequest::Payment(requests) = &request {
|
||||
if let EventResponse::Payment(payments) = action {
|
||||
assert_eq!(requests.len(), payments.len());
|
||||
for (request, payment) in requests.iter().zip(payments.iter()) {
|
||||
|
|
@ -372,15 +378,15 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
priority: i32,
|
||||
request: impl Fn(&mut Game, usize, &mut V) -> Option<ResourceRewardRequest> + 'static + Clone,
|
||||
gain_reward_log: impl Fn(&Game, &SelectedChoice<ResourcePile>, &mut V) -> Vec<String>
|
||||
+ 'static
|
||||
+ Clone,
|
||||
+ 'static
|
||||
+ Clone,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
let g = gain_reward_log.clone();
|
||||
self.add_current_event_listener(
|
||||
self.add_persistent_event_listener(
|
||||
event,
|
||||
priority,
|
||||
move |game, player_index, _player_name, details| {
|
||||
|
|
@ -400,10 +406,10 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
return None;
|
||||
}
|
||||
}
|
||||
req.map(CurrentEventRequest::ResourceReward)
|
||||
req.map(PersistentEventRequest::ResourceReward)
|
||||
},
|
||||
move |game, player_index, player_name, action, request, details| {
|
||||
if let CurrentEventRequest::ResourceReward(request) = &request {
|
||||
if let PersistentEventRequest::ResourceReward(request) = &request {
|
||||
if let EventResponse::ResourceReward(reward) = action {
|
||||
assert!(request.reward.is_valid_payment(&reward), "Invalid reward");
|
||||
for log in &gain_reward_log(
|
||||
|
|
@ -430,17 +436,17 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
gain_reward: impl Fn(&mut Game, &SelectedChoice<bool>, &mut V) + 'static + Clone,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.add_current_event_listener(
|
||||
self.add_persistent_event_listener(
|
||||
event,
|
||||
priority,
|
||||
move |game, player_index, _player_name, details| {
|
||||
request(game, player_index, details).map(CurrentEventRequest::BoolRequest)
|
||||
request(game, player_index, details).map(PersistentEventRequest::BoolRequest)
|
||||
},
|
||||
move |game, player_index, player_name, action, request, details| {
|
||||
if let CurrentEventRequest::BoolRequest(_) = &request {
|
||||
if let PersistentEventRequest::BoolRequest(_) = &request {
|
||||
if let EventResponse::Bool(reward) = action {
|
||||
gain_reward(
|
||||
game,
|
||||
|
|
@ -463,16 +469,16 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
gain_reward: impl Fn(&mut Game, &SelectedChoice<String>, &mut V) + 'static + Clone,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.add_choice_reward_request_listener::<E, String, AdvanceRequest, V>(
|
||||
event,
|
||||
priority,
|
||||
|r| &r.choices,
|
||||
CurrentEventRequest::SelectAdvance,
|
||||
PersistentEventRequest::SelectAdvance,
|
||||
|request, action| {
|
||||
if let CurrentEventRequest::SelectAdvance(request) = &request {
|
||||
if let PersistentEventRequest::SelectAdvance(request) = &request {
|
||||
if let EventResponse::SelectAdvance(reward) = action {
|
||||
return (request.choices.clone(), reward);
|
||||
}
|
||||
|
|
@ -492,16 +498,16 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
gain_reward: impl Fn(&mut Game, &SelectedChoice<Vec<Position>>, &mut V) + 'static + Clone,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.add_multi_choice_reward_request_listener::<E, Position, PositionRequest, V>(
|
||||
event,
|
||||
priority,
|
||||
|r| &r.request,
|
||||
CurrentEventRequest::SelectPositions,
|
||||
PersistentEventRequest::SelectPositions,
|
||||
|request, action| {
|
||||
if let CurrentEventRequest::SelectPositions(request) = &request {
|
||||
if let PersistentEventRequest::SelectPositions(request) = &request {
|
||||
if let EventResponse::SelectPositions(reward) = action {
|
||||
return (
|
||||
request.request.choices.clone(),
|
||||
|
|
@ -525,16 +531,16 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
gain_reward: impl Fn(&mut Game, &SelectedChoice<usize>, &mut V) + 'static + Clone,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.add_choice_reward_request_listener::<E, usize, PlayerRequest, V>(
|
||||
event,
|
||||
priority,
|
||||
|r| &r.choices,
|
||||
CurrentEventRequest::SelectPlayer,
|
||||
PersistentEventRequest::SelectPlayer,
|
||||
|request, action| {
|
||||
if let CurrentEventRequest::SelectPlayer(request) = &request {
|
||||
if let PersistentEventRequest::SelectPlayer(request) = &request {
|
||||
if let EventResponse::SelectPlayer(reward) = action {
|
||||
return (request.choices.clone(), reward);
|
||||
}
|
||||
|
|
@ -554,16 +560,16 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
gain_reward: impl Fn(&mut Game, &SelectedChoice<UnitType>, &mut V) + 'static + Clone,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.add_choice_reward_request_listener::<E, UnitType, UnitTypeRequest, V>(
|
||||
event,
|
||||
priority,
|
||||
|r| &r.choices,
|
||||
CurrentEventRequest::SelectUnitType,
|
||||
PersistentEventRequest::SelectUnitType,
|
||||
|request, action| {
|
||||
if let CurrentEventRequest::SelectUnitType(request) = &request {
|
||||
if let PersistentEventRequest::SelectUnitType(request) = &request {
|
||||
if let EventResponse::SelectUnitType(reward) = action {
|
||||
return (request.choices.clone(), reward);
|
||||
}
|
||||
|
|
@ -583,16 +589,16 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
cards_selected: impl Fn(&mut Game, &SelectedChoice<Vec<HandCard>>, &mut V) + 'static + Clone,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.add_multi_choice_reward_request_listener::<E, HandCard, HandCardsRequest, V>(
|
||||
event,
|
||||
priority,
|
||||
|r| &r.request,
|
||||
CurrentEventRequest::SelectHandCards,
|
||||
PersistentEventRequest::SelectHandCards,
|
||||
|request, action| {
|
||||
if let CurrentEventRequest::SelectHandCards(request) = &request {
|
||||
if let PersistentEventRequest::SelectHandCards(request) = &request {
|
||||
if let EventResponse::SelectHandCards(choices) = action {
|
||||
return (
|
||||
request.request.choices.clone(),
|
||||
|
|
@ -616,16 +622,16 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
units_selected: impl Fn(&mut Game, &SelectedChoice<Vec<u32>>, &mut V) + 'static + Clone,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.add_multi_choice_reward_request_listener::<E, u32, UnitsRequest, V>(
|
||||
event,
|
||||
priority,
|
||||
|r| &r.request,
|
||||
CurrentEventRequest::SelectUnits,
|
||||
PersistentEventRequest::SelectUnits,
|
||||
|request, action| {
|
||||
if let CurrentEventRequest::SelectUnits(request) = &request {
|
||||
if let PersistentEventRequest::SelectUnits(request) = &request {
|
||||
if let EventResponse::SelectUnits(choices) = action {
|
||||
return (
|
||||
request.request.choices.clone(),
|
||||
|
|
@ -649,20 +655,20 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
priority: i32,
|
||||
request: impl Fn(&mut Game, usize, &mut V) -> Option<StructuresRequest> + 'static + Clone,
|
||||
structures_selected: impl Fn(&mut Game, &SelectedChoice<Vec<SelectedStructure>>, &mut V)
|
||||
+ 'static
|
||||
+ Clone,
|
||||
+ 'static
|
||||
+ Clone,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.add_multi_choice_reward_request_listener::<E, SelectedStructure, StructuresRequest, V>(
|
||||
event,
|
||||
priority,
|
||||
|r| r,
|
||||
CurrentEventRequest::SelectStructures,
|
||||
PersistentEventRequest::SelectStructures,
|
||||
|request, action| {
|
||||
if let CurrentEventRequest::SelectStructures(request) = &request {
|
||||
if let PersistentEventRequest::SelectStructures(request) = &request {
|
||||
if let EventResponse::SelectStructures(choices) = action {
|
||||
return (request.choices.clone(), choices, request.needed.clone());
|
||||
}
|
||||
|
|
@ -679,18 +685,18 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
event: E,
|
||||
priority: i32,
|
||||
get_choices: impl Fn(&R) -> &Vec<C> + 'static + Clone,
|
||||
to_request: impl Fn(R) -> CurrentEventRequest + 'static + Clone,
|
||||
from_request: impl Fn(&CurrentEventRequest, EventResponse) -> (Vec<C>, C) + 'static + Clone,
|
||||
to_request: impl Fn(R) -> PersistentEventRequest + 'static + Clone,
|
||||
from_request: impl Fn(&PersistentEventRequest, EventResponse) -> (Vec<C>, C) + 'static + Clone,
|
||||
request: impl Fn(&mut Game, usize, &mut V) -> Option<R> + 'static + Clone,
|
||||
gain_reward: impl Fn(&mut Game, &SelectedChoice<C>, &mut V) + 'static + Clone,
|
||||
) -> Self
|
||||
where
|
||||
C: Clone + PartialEq,
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
let g = gain_reward.clone();
|
||||
self.add_current_event_listener(
|
||||
self.add_persistent_event_listener(
|
||||
event,
|
||||
priority,
|
||||
move |game, player_index, player_name, details| {
|
||||
|
|
@ -733,20 +739,23 @@ pub(crate) trait AbilityInitializerSetup: Sized {
|
|||
event: E,
|
||||
priority: i32,
|
||||
get_request: impl Fn(&R) -> &MultiRequest<C> + 'static + Clone,
|
||||
to_request: impl Fn(R) -> CurrentEventRequest + 'static + Clone,
|
||||
from_request: impl Fn(&CurrentEventRequest, EventResponse) -> (Vec<C>, Vec<C>, RangeInclusive<u8>)
|
||||
+ 'static
|
||||
+ Clone,
|
||||
to_request: impl Fn(R) -> PersistentEventRequest + 'static + Clone,
|
||||
from_request: impl Fn(
|
||||
&PersistentEventRequest,
|
||||
EventResponse,
|
||||
) -> (Vec<C>, Vec<C>, RangeInclusive<u8>)
|
||||
+ 'static
|
||||
+ Clone,
|
||||
request: impl Fn(&mut Game, usize, &mut V) -> Option<R> + 'static + Clone,
|
||||
gain_reward: impl Fn(&mut Game, &SelectedChoice<Vec<C>>, &mut V) + 'static + Clone,
|
||||
) -> Self
|
||||
where
|
||||
C: Clone + PartialEq,
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
let g = gain_reward.clone();
|
||||
self.add_current_event_listener(
|
||||
self.add_persistent_event_listener(
|
||||
event,
|
||||
priority,
|
||||
move |game, player_index, _player_name, details| {
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::collect::on_collect;
|
|||
use crate::combat::{combat_loop, move_with_possible_combat, start_combat};
|
||||
use crate::combat_listeners::{combat_round_end, combat_round_start, end_combat};
|
||||
use crate::construct::on_construct;
|
||||
use crate::content::custom_phase_actions::{CurrentEventType, EventResponse};
|
||||
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};
|
||||
use crate::game::GameState::{Finished, Movement, Playing};
|
||||
|
|
@ -13,8 +13,10 @@ use crate::incident::on_trigger_incident;
|
|||
use crate::log;
|
||||
use crate::log::{add_action_log_item, current_player_turn_log_mut};
|
||||
use crate::map::Terrain::Unexplored;
|
||||
use crate::movement::MovementAction::{Move, Stop};
|
||||
use crate::movement::{
|
||||
get_move_state, has_movable_units, move_units_destinations, CurrentMove, MoveState,
|
||||
CurrentMove, MoveState, MovementAction, get_move_state, has_movable_units,
|
||||
move_units_destinations,
|
||||
};
|
||||
use crate::playing_actions::PlayingAction;
|
||||
use crate::recruit::on_recruit;
|
||||
|
|
@ -22,8 +24,7 @@ use crate::resource::check_for_waste;
|
|||
use crate::resource_pile::ResourcePile;
|
||||
use crate::status_phase::play_status_phase;
|
||||
use crate::undo::{clean_patch, redo, to_serde_value, undo};
|
||||
use crate::unit::MovementAction::{Move, Stop};
|
||||
use crate::unit::{get_current_move, MovementAction};
|
||||
use crate::unit::{get_current_move, units_killed};
|
||||
use crate::wonder::{draw_wonder_card, on_play_wonder_card};
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -76,7 +77,7 @@ pub fn execute_action(mut game: Game, action: Action, player_index: usize) -> Ga
|
|||
let add_undo = !matches!(&action, Action::Undo);
|
||||
let old = to_serde_value(&game);
|
||||
let old_player = game.active_player();
|
||||
game = execute_without_undo(game, action, player_index);
|
||||
game = execute_without_undo(game, action, player_index).expect("action should be executed");
|
||||
let new = to_serde_value(&game);
|
||||
let new_player = game.active_player();
|
||||
let patch = json_patch::diff(&new, &old);
|
||||
|
|
@ -89,42 +90,50 @@ pub fn execute_action(mut game: Game, action: Action, player_index: usize) -> Ga
|
|||
game
|
||||
}
|
||||
|
||||
fn execute_without_undo(mut game: Game, action: Action, player_index: usize) -> Game {
|
||||
assert!(player_index == game.active_player(), "Illegal action");
|
||||
fn execute_without_undo(
|
||||
mut game: Game,
|
||||
action: Action,
|
||||
player_index: usize,
|
||||
) -> Result<Game, String> {
|
||||
if player_index != game.active_player() {
|
||||
return Err("Not your turn".to_string());
|
||||
}
|
||||
if let Action::Undo = action {
|
||||
assert!(
|
||||
game.can_undo(),
|
||||
"actions revealing new information can't be undone"
|
||||
);
|
||||
if !game.can_undo() {
|
||||
return Err("actions revealing new information can't be undone".to_string());
|
||||
}
|
||||
return undo(game);
|
||||
}
|
||||
|
||||
if matches!(action, Action::Redo) {
|
||||
assert!(game.can_redo(), "action can't be redone");
|
||||
redo(&mut game, player_index);
|
||||
return game;
|
||||
if !game.can_redo() {
|
||||
return Err("action can't be redone".to_string());
|
||||
}
|
||||
redo(&mut game, player_index)?;
|
||||
return Ok(game);
|
||||
}
|
||||
|
||||
add_log_item_from_action(&mut game, &action);
|
||||
add_action_log_item(&mut game, action.clone());
|
||||
|
||||
if let Some(s) = game.current_event_handler_mut() {
|
||||
s.response = action.response();
|
||||
let details = game.current_event().event_type.clone();
|
||||
execute_custom_phase_action(&mut game, player_index, details);
|
||||
} else {
|
||||
execute_regular_action(&mut game, action, player_index);
|
||||
}
|
||||
match game.current_event_handler_mut() {
|
||||
Some(s) => {
|
||||
s.response = action.response();
|
||||
let details = game.current_event().event_type.clone();
|
||||
execute_custom_phase_action(&mut game, player_index, details)
|
||||
}
|
||||
_ => execute_regular_action(&mut game, action, player_index),
|
||||
}?;
|
||||
check_for_waste(&mut game);
|
||||
game
|
||||
Ok(game)
|
||||
}
|
||||
|
||||
pub(crate) fn execute_custom_phase_action(
|
||||
game: &mut Game,
|
||||
player_index: usize,
|
||||
details: CurrentEventType,
|
||||
) {
|
||||
use CurrentEventType::*;
|
||||
details: PersistentEventType,
|
||||
) -> Result<(), String> {
|
||||
use PersistentEventType::*;
|
||||
match details {
|
||||
Collect(i) => on_collect(game, player_index, i),
|
||||
DrawWonderCard => {
|
||||
|
|
@ -136,6 +145,7 @@ pub(crate) fn execute_custom_phase_action(
|
|||
InfluenceCultureResolution(r) => {
|
||||
ask_for_cultural_influence_payment(game, player_index, r);
|
||||
}
|
||||
UnitsKilled(k) => units_killed(game, player_index, k),
|
||||
CombatStart(c) => {
|
||||
start_combat(game, c);
|
||||
}
|
||||
|
|
@ -172,45 +182,54 @@ pub(crate) fn execute_custom_phase_action(
|
|||
if s.player.handler.is_none() {
|
||||
if let Some(l) = s.player.last_priority_used.as_mut() {
|
||||
*l -= 1;
|
||||
} else {
|
||||
s.player.skip_first_priority = true;
|
||||
}
|
||||
let p = s.player.index;
|
||||
let event_type = s.event_type.clone();
|
||||
game.events.push(s);
|
||||
execute_custom_phase_action(game, p, event_type);
|
||||
execute_custom_phase_action(game, p, event_type)?;
|
||||
} else {
|
||||
game.events.push(s);
|
||||
}
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn add_log_item_from_action(game: &mut Game, action: &Action) {
|
||||
game.log.push(log::format_action_log_item(action, game));
|
||||
}
|
||||
|
||||
fn execute_regular_action(game: &mut Game, action: Action, player_index: usize) {
|
||||
fn execute_regular_action(
|
||||
game: &mut Game,
|
||||
action: Action,
|
||||
player_index: usize,
|
||||
) -> Result<(), String> {
|
||||
match game.state {
|
||||
Playing => {
|
||||
if let Some(m) = action.clone().movement() {
|
||||
if let MovementAction::Move(_) = m {
|
||||
} else {
|
||||
panic!("Illegal action");
|
||||
return Err("Expected move action".to_string());
|
||||
}
|
||||
if game.actions_left == 0 {
|
||||
return Err("No actions left".to_string());
|
||||
}
|
||||
assert_ne!(game.actions_left, 0, "Illegal action");
|
||||
game.actions_left -= 1;
|
||||
game.state = GameState::Movement(MoveState::new());
|
||||
execute_movement_action(game, m, player_index);
|
||||
execute_movement_action(game, m, player_index)
|
||||
} else {
|
||||
let action = action.playing().expect("action should be a playing action");
|
||||
action.execute(game, player_index, false);
|
||||
action.execute(game, player_index, false)
|
||||
}
|
||||
}
|
||||
Movement(_) => {
|
||||
let action = action
|
||||
.movement()
|
||||
.expect("action should be a movement action");
|
||||
execute_movement_action(game, action, player_index);
|
||||
execute_movement_action(game, action, player_index)
|
||||
}
|
||||
Finished => panic!("actions can't be executed when the game is finished"),
|
||||
Finished => Err("actions can't be executed when the game is finished".to_string()),
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -218,7 +237,7 @@ pub(crate) fn execute_movement_action(
|
|||
game: &mut Game,
|
||||
action: MovementAction,
|
||||
player_index: usize,
|
||||
) {
|
||||
) -> Result<(), String> {
|
||||
match action {
|
||||
Move(m) => {
|
||||
let player = &game.players[player_index];
|
||||
|
|
@ -227,28 +246,22 @@ pub(crate) fn execute_movement_action(
|
|||
"instead of providing no units to move a stop movement actions should be done",
|
||||
))
|
||||
.position;
|
||||
match move_units_destinations(
|
||||
let destinations = move_units_destinations(
|
||||
player,
|
||||
game,
|
||||
&m.units,
|
||||
starting_position,
|
||||
m.embark_carrier_id,
|
||||
) {
|
||||
Ok(destinations) => {
|
||||
let c = &destinations
|
||||
.iter()
|
||||
.find(|route| route.destination == m.destination)
|
||||
.expect("destination should be a valid destination")
|
||||
.cost;
|
||||
if c.is_free() {
|
||||
assert_eq!(m.payment, ResourcePile::empty(), "payment should be empty");
|
||||
} else {
|
||||
game.players[player_index].pay_cost(c, &m.payment);
|
||||
}
|
||||
}
|
||||
Err(e) => {
|
||||
panic!("cannot move units to destination: {e}");
|
||||
}
|
||||
)?;
|
||||
let c = &destinations
|
||||
.iter()
|
||||
.find(|route| route.destination == m.destination)
|
||||
.expect("destination should be a valid destination")
|
||||
.cost;
|
||||
if c.is_free() {
|
||||
assert_eq!(m.payment, ResourcePile::empty(), "payment should be empty");
|
||||
} else {
|
||||
game.players[player_index].pay_cost(c, &m.payment);
|
||||
}
|
||||
|
||||
let current_move = get_current_move(
|
||||
|
|
@ -285,23 +298,24 @@ pub(crate) fn execute_movement_action(
|
|||
starting_position,
|
||||
m.destination,
|
||||
);
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
|
||||
if move_with_possible_combat(game, player_index, starting_position, &m) {
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
}
|
||||
Stop => {
|
||||
game.state = GameState::Playing;
|
||||
return;
|
||||
return Ok(());
|
||||
}
|
||||
};
|
||||
|
||||
let state = get_move_state(game);
|
||||
let all_moves_used =
|
||||
state.movement_actions_left == 0 && state.current_move == CurrentMove::None;
|
||||
if all_moves_used || !has_movable_units(game, game.get_player(game.current_player_index)) {
|
||||
if all_moves_used || !has_movable_units(game, game.player(game.current_player_index)) {
|
||||
game.state = GameState::Playing;
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,11 +4,11 @@ use crate::ability_initializer::{
|
|||
use crate::card::draw_card_from_pile;
|
||||
use crate::content::action_cards;
|
||||
use crate::content::action_cards::get_civil_card;
|
||||
use crate::content::custom_phase_actions::CurrentEventType;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::content::tactics_cards::TacticsCardFactory;
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
use crate::log::{current_player_turn_log, current_player_turn_log_mut, ActionLogItem};
|
||||
use crate::log::{ActionLogItem, current_player_turn_log, current_player_turn_log_mut};
|
||||
use crate::player::Player;
|
||||
use crate::playing_actions::ActionType;
|
||||
use crate::position::Position;
|
||||
|
|
@ -136,12 +136,12 @@ pub(crate) fn play_action_card(game: &mut Game, player_index: usize, id: u8) {
|
|||
}
|
||||
|
||||
pub(crate) fn on_play_action_card(game: &mut Game, player_index: usize, i: ActionCardInfo) {
|
||||
let _ = game.trigger_current_event_with_listener(
|
||||
let _ = game.trigger_persistent_event_with_listener(
|
||||
&[player_index],
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
&get_civil_card(i.id).listeners,
|
||||
i,
|
||||
CurrentEventType::ActionCard,
|
||||
PersistentEventType::ActionCard,
|
||||
None,
|
||||
|_| {},
|
||||
);
|
||||
|
|
@ -169,14 +169,12 @@ fn draw_action_card_from_pile(game: &mut Game) -> Option<ActionCard> {
|
|||
.map(get_action_card)
|
||||
}
|
||||
|
||||
fn gain_action_card(game: &mut Game, player_index: usize, action_card: &ActionCard) {
|
||||
pub(crate) fn gain_action_card(game: &mut Game, player_index: usize, action_card: &ActionCard) {
|
||||
game.players[player_index].action_cards.push(action_card.id);
|
||||
}
|
||||
|
||||
pub(crate) fn discard_action_card(game: &mut Game, player: usize, card: u8) {
|
||||
remove_element_by(&mut game.get_player_mut(player).action_cards, |&id| {
|
||||
id == card
|
||||
});
|
||||
remove_element_by(&mut game.player_mut(player).action_cards, |&id| id == card);
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::{ability_initializer::AbilityInitializerSetup, resource_pile::Resourc
|
|||
use crate::ability_initializer::{AbilityInitializerBuilder, AbilityListeners};
|
||||
use crate::city_pieces::Building;
|
||||
use crate::content::advances::get_advance;
|
||||
use crate::content::custom_phase_actions::CurrentEventType;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
use crate::incident::on_trigger_incident;
|
||||
|
|
@ -188,18 +188,18 @@ pub(crate) fn gain_advance(
|
|||
}
|
||||
|
||||
pub(crate) fn on_advance(game: &mut Game, player_index: usize, info: AdvanceInfo) {
|
||||
let info = match game.trigger_current_event(
|
||||
let info = match game.trigger_persistent_event(
|
||||
&[player_index],
|
||||
|e| &mut e.on_advance,
|
||||
|e| &mut e.advance,
|
||||
info,
|
||||
CurrentEventType::Advance,
|
||||
PersistentEventType::Advance,
|
||||
) {
|
||||
None => return,
|
||||
Some(i) => i,
|
||||
};
|
||||
|
||||
if info.take_incident_token {
|
||||
let player = game.get_player_mut(player_index);
|
||||
let player = game.player_mut(player_index);
|
||||
player.incident_tokens -= 1;
|
||||
if player.incident_tokens == 0 {
|
||||
player.incident_tokens = 3;
|
||||
|
|
|
|||
|
|
@ -3,19 +3,18 @@ use crate::city::City;
|
|||
use crate::combat::move_with_possible_combat;
|
||||
use crate::consts::STACK_LIMIT;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_phase_actions::{
|
||||
PositionRequest, ResourceRewardRequest, UnitTypeRequest,
|
||||
};
|
||||
use crate::content::persistent_events::{PositionRequest, ResourceRewardRequest, UnitTypeRequest};
|
||||
use crate::game::Game;
|
||||
use crate::incident::{play_base_effect, IncidentBuilder, IncidentFilter, BASE_EFFECT_PRIORITY};
|
||||
use crate::incident::{BASE_EFFECT_PRIORITY, IncidentBuilder, IncidentFilter, play_base_effect};
|
||||
use crate::map::Terrain;
|
||||
use crate::movement::MoveUnits;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::player::Player;
|
||||
use crate::player_events::{CurrentEvent, IncidentTarget, PersistentEvents};
|
||||
use crate::player_events::{IncidentTarget, PersistentEvent, PersistentEvents};
|
||||
use crate::position::Position;
|
||||
use crate::resource::ResourceType;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::unit::{MoveUnits, UnitType, Units};
|
||||
use crate::unit::{UnitType, Units};
|
||||
use crate::utils;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -63,12 +62,12 @@ impl BarbariansEventState {
|
|||
pub(crate) fn barbarians_bonus() -> Builtin {
|
||||
Builtin::builder("Barbarians bonus", "-")
|
||||
.add_resource_request(
|
||||
|event| &mut event.on_combat_end,
|
||||
|event| &mut event.combat_end,
|
||||
5,
|
||||
|game, player_index, i| {
|
||||
if i.is_winner(player_index)
|
||||
&& game
|
||||
.get_player(i.opponent(player_index))
|
||||
.player(i.opponent(player_index))
|
||||
.civilization
|
||||
.is_barbarian()
|
||||
{
|
||||
|
|
@ -121,7 +120,7 @@ pub(crate) fn barbarians_spawn(mut builder: IncidentBuilder) -> IncidentBuilder
|
|||
);
|
||||
barbarian_reinforcement(
|
||||
builder,
|
||||
|e| &mut e.on_incident,
|
||||
|e| &mut e.incident,
|
||||
BASE_EFFECT_PRIORITY,
|
||||
|game, p, i| {
|
||||
IncidentFilter::new(IncidentTarget::ActivePlayer, BASE_EFFECT_PRIORITY, None)
|
||||
|
|
@ -144,7 +143,7 @@ pub(crate) fn barbarian_reinforcement<E, S, V>(
|
|||
get_barbarian_city: impl Fn(&V) -> Option<Position> + 'static + Clone,
|
||||
) -> S
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
S: AbilityInitializerSetup,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
|
|
@ -168,7 +167,7 @@ where
|
|||
let position = get_barbarian_city2(v).expect("barbarians should exist");
|
||||
let units = Units::from_iter(vec![s.choice]);
|
||||
game.add_info_log_item(&format!("Barbarians reinforced with {units} at {position}",));
|
||||
game.get_player_mut(get_barbarians_player(game).index)
|
||||
game.player_mut(get_barbarians_player(game).index)
|
||||
.add_unit(position, s.choice);
|
||||
},
|
||||
)
|
||||
|
|
@ -209,7 +208,7 @@ pub(crate) fn barbarians_move(mut builder: IncidentBuilder) -> IncidentBuilder {
|
|||
if let Some(army) = state.selected_position {
|
||||
let choices = barbarian_march_steps(
|
||||
game,
|
||||
game.get_player(player_index),
|
||||
game.player(player_index),
|
||||
army,
|
||||
0, // stack size was already checked in last step
|
||||
);
|
||||
|
|
@ -256,7 +255,7 @@ pub(crate) fn barbarians_move(mut builder: IncidentBuilder) -> IncidentBuilder {
|
|||
// after all moves are done
|
||||
reinforce_after_move(game, player);
|
||||
// clear movement restrictions
|
||||
game.get_player_mut(get_barbarians_player(game).index)
|
||||
game.player_mut(get_barbarians_player(game).index)
|
||||
.end_turn();
|
||||
}
|
||||
},
|
||||
|
|
@ -264,7 +263,7 @@ pub(crate) fn barbarians_move(mut builder: IncidentBuilder) -> IncidentBuilder {
|
|||
}
|
||||
|
||||
fn reinforce_after_move(game: &mut Game, player_index: usize) {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
let barbarian = get_barbarians_player(game).index;
|
||||
let available = player.available_units().get(&UnitType::Infantry) as usize;
|
||||
|
||||
|
|
@ -277,14 +276,13 @@ fn reinforce_after_move(game: &mut Game, player_index: usize) {
|
|||
.take(available)
|
||||
.collect();
|
||||
for pos in cities {
|
||||
game.get_player_mut(barbarian)
|
||||
.add_unit(pos, UnitType::Infantry);
|
||||
game.player_mut(barbarian).add_unit(pos, UnitType::Infantry);
|
||||
game.add_info_log_item(&format!("Barbarians spawned a new Infantry unit at {pos}",));
|
||||
}
|
||||
}
|
||||
|
||||
fn get_movable_units(game: &Game, human: usize, state: &BarbariansEventState) -> Vec<Position> {
|
||||
let human = game.get_player(human);
|
||||
let human = game.player(human);
|
||||
let barbarian = get_barbarians_player(game);
|
||||
|
||||
game.map
|
||||
|
|
@ -353,7 +351,7 @@ fn add_barbarians_city(builder: IncidentBuilder) -> IncidentBuilder {
|
|||
return None;
|
||||
}
|
||||
|
||||
let choices = possible_barbarians_spawns(game, game.get_player(player_index));
|
||||
let choices = possible_barbarians_spawns(game, game.player(player_index));
|
||||
if choices.is_empty() {
|
||||
game.add_info_log_item("Barbarians cannot spawn a new city");
|
||||
}
|
||||
|
|
@ -370,7 +368,7 @@ fn add_barbarians_city(builder: IncidentBuilder) -> IncidentBuilder {
|
|||
"Barbarians spawned a new city and a new Infantry unit at {pos}"
|
||||
));
|
||||
let b = get_barbarians_player(game).index;
|
||||
let p = game.get_player_mut(b);
|
||||
let p = game.player_mut(b);
|
||||
p.cities.push(City::new(b, pos));
|
||||
p.add_unit(pos, UnitType::Infantry);
|
||||
},
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use serde::{Deserialize, Serialize};
|
||||
|
||||
use crate::{content::wonders, wonder::Wonder};
|
||||
use num::Zero;
|
||||
use Building::*;
|
||||
use num::Zero;
|
||||
|
||||
#[derive(Default)]
|
||||
pub struct CityPieces {
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::content::custom_phase_actions::CurrentEventType;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
use crate::map::Terrain;
|
||||
|
|
@ -95,7 +95,7 @@ pub fn get_total_collection(
|
|||
.reduce(std::ops::Add::add)
|
||||
.map(|pile| {
|
||||
i.total = pile;
|
||||
let _ = player.trigger_event(|e| &e.collect_total, &mut i, &(), &());
|
||||
player.trigger_event(|e| &e.collect_total, &mut i, &(), &());
|
||||
i
|
||||
})
|
||||
.ok_or("Nothing collected".to_string())
|
||||
|
|
@ -106,23 +106,25 @@ pub fn tiles_used(collections: &[PositionCollection]) -> u32 {
|
|||
collections.iter().map(|c| c.times).sum()
|
||||
}
|
||||
|
||||
pub(crate) fn collect(game: &mut Game, player_index: usize, c: &Collect) {
|
||||
let i = get_total_collection(game, player_index, c.city_position, &c.collections)
|
||||
.unwrap_or_else(|e| panic!("{e}"));
|
||||
pub(crate) fn collect(game: &mut Game, player_index: usize, c: &Collect) -> Result<(), String> {
|
||||
let i = get_total_collection(game, player_index, c.city_position, &c.collections)?;
|
||||
let city = game.players[player_index].get_city_mut(c.city_position);
|
||||
assert!(city.can_activate(), "Illegal action");
|
||||
if !city.can_activate() {
|
||||
return Err("City can't be activated".to_string());
|
||||
}
|
||||
city.activate();
|
||||
game.players[player_index].gain_resources(i.total.clone());
|
||||
|
||||
on_collect(game, player_index, i);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn on_collect(game: &mut Game, player_index: usize, i: CollectInfo) {
|
||||
let Some(info) = game.trigger_current_event(
|
||||
let Some(info) = game.trigger_persistent_event(
|
||||
&[player_index],
|
||||
|e| &mut e.on_collect,
|
||||
|e| &mut e.collect,
|
||||
i,
|
||||
CurrentEventType::Collect,
|
||||
PersistentEventType::Collect,
|
||||
) else {
|
||||
return;
|
||||
};
|
||||
|
|
@ -181,12 +183,14 @@ pub fn possible_resource_collections(
|
|||
(Forest, HashSet::from([ResourcePile::wood(1)])),
|
||||
];
|
||||
let mut terrain_options = HashMap::from(set);
|
||||
let modifiers = game.get_player(player_index).trigger_event(
|
||||
|e| &e.terrain_collect_options,
|
||||
&mut terrain_options,
|
||||
&(),
|
||||
&(),
|
||||
);
|
||||
let event = &game
|
||||
.player(player_index)
|
||||
.events
|
||||
.transient
|
||||
.terrain_collect_options;
|
||||
let modifiers = event
|
||||
.get()
|
||||
.trigger_with_modifiers(&mut terrain_options, &(), &(), &mut ());
|
||||
|
||||
let collect_options = city_pos
|
||||
.neighbors()
|
||||
|
|
|
|||
|
|
@ -3,19 +3,19 @@ use crate::city::City;
|
|||
use crate::city::MoodState::Angry;
|
||||
use crate::city_pieces::Building;
|
||||
use crate::combat_listeners::{
|
||||
combat_round_end, combat_round_start, Casualties, CombatEventPhase, CombatRoundEnd,
|
||||
CombatRoundStart, CombatStrength,
|
||||
Casualties, CombatEventPhase, CombatRoundEnd, CombatRoundStart, CombatStrength,
|
||||
combat_round_end, combat_round_start,
|
||||
};
|
||||
use crate::combat_roll::CombatStats;
|
||||
use crate::consts::SHIP_CAPACITY;
|
||||
use crate::content::custom_phase_actions::CurrentEventType;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::game::Game;
|
||||
use crate::log::current_player_turn_log_mut;
|
||||
use crate::movement::{move_units, stop_current_move};
|
||||
use crate::movement::{MoveUnits, MovementRestriction, move_units, stop_current_move};
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::tactics_card::CombatRole;
|
||||
use crate::unit::{MoveUnits, MovementRestriction, UnitType};
|
||||
use crate::unit::UnitType;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
@ -139,7 +139,7 @@ impl Combat {
|
|||
#[must_use]
|
||||
pub fn carried_units_casualties(&self, game: &Game, player: usize, casualties: u8) -> u8 {
|
||||
if self.is_sea_battle(game) {
|
||||
let units = game.players[player].get_units(self.position(player));
|
||||
let units = game.player(player).get_units(self.position(player));
|
||||
let carried_units = units.iter().filter(|u| u.carrier_id.is_some()).count() as u8;
|
||||
let carrier_capacity_left =
|
||||
(units.len() as u8 - carried_units - casualties) * SHIP_CAPACITY;
|
||||
|
|
@ -220,11 +220,11 @@ pub(crate) fn start_combat(game: &mut Game, combat: Combat) {
|
|||
game.lock_undo(); // combat should not be undoable
|
||||
stop_current_move(game);
|
||||
|
||||
let c = match game.trigger_current_event(
|
||||
let c = match game.trigger_persistent_event(
|
||||
&combat.players(),
|
||||
|events| &mut events.on_combat_start,
|
||||
|events| &mut events.combat_start,
|
||||
combat,
|
||||
CurrentEventType::CombatStart,
|
||||
PersistentEventType::CombatStart,
|
||||
) {
|
||||
None => return,
|
||||
Some(c) => c,
|
||||
|
|
@ -334,7 +334,7 @@ pub(crate) fn conquer_city(
|
|||
" and captured {}'s city at {position}",
|
||||
game.player_name(old_player_index)
|
||||
));
|
||||
let attacker_is_human = game.get_player(new_player_index).is_human();
|
||||
let attacker_is_human = game.player(new_player_index).is_human();
|
||||
let size = city.mood_modified_size(&game.players[new_player_index]);
|
||||
if attacker_is_human {
|
||||
game.players[new_player_index].gain_resources(ResourcePile::gold(size as u32));
|
||||
|
|
@ -350,7 +350,7 @@ pub(crate) fn conquer_city(
|
|||
m.replace(&mut CivilCardMatch::new(CivilCardOpportunity::CaptureCity));
|
||||
}
|
||||
}
|
||||
let take_over = game.get_player(new_player_index).is_city_available();
|
||||
let take_over = game.player(new_player_index).is_city_available();
|
||||
|
||||
if take_over {
|
||||
city.player_index = new_player_index;
|
||||
|
|
@ -402,7 +402,7 @@ pub fn capture_position(game: &mut Game, old_player: usize, position: Position,
|
|||
for id in captured_settlers {
|
||||
game.players[old_player].remove_unit(id);
|
||||
}
|
||||
if game.get_player(old_player).try_get_city(position).is_some() {
|
||||
if game.player(old_player).try_get_city(position).is_some() {
|
||||
conquer_city(game, position, new_player, old_player);
|
||||
}
|
||||
}
|
||||
|
|
@ -447,7 +447,7 @@ fn move_to_enemy_player_tile(
|
|||
player_index,
|
||||
starting_position,
|
||||
units.clone(),
|
||||
game.get_player(player_index).is_human(),
|
||||
game.player(player_index).is_human(),
|
||||
);
|
||||
return true;
|
||||
}
|
||||
|
|
@ -492,13 +492,13 @@ pub(crate) fn move_with_possible_combat(
|
|||
pub mod tests {
|
||||
use std::collections::HashMap;
|
||||
|
||||
use super::{conquer_city, Game};
|
||||
use super::{Game, conquer_city};
|
||||
|
||||
use crate::action::Action;
|
||||
use crate::game::GameState;
|
||||
use crate::log::{ActionLogAge, ActionLogItem, ActionLogPlayer, ActionLogRound};
|
||||
use crate::movement::MovementAction;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::unit::MovementAction;
|
||||
use crate::utils::tests::FloatEq;
|
||||
use crate::wonder::construct_wonder;
|
||||
use crate::{
|
||||
|
|
|
|||
|
|
@ -1,21 +1,19 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action_card::{CivilCardMatch, CivilCardOpportunity};
|
||||
use crate::combat::{capture_position, Combat, CombatRetreatState};
|
||||
use crate::consts::SHIP_CAPACITY;
|
||||
use crate::content::builtin::{Builtin, BuiltinBuilder};
|
||||
use crate::content::custom_phase_actions::{CurrentEventType, PositionRequest, UnitsRequest};
|
||||
use crate::combat::{Combat, CombatRetreatState, capture_position};
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::persistent_events::{PersistentEventType, PositionRequest, UnitsRequest};
|
||||
use crate::content::tactics_cards;
|
||||
use crate::game::Game;
|
||||
use crate::log::current_player_turn_log_mut;
|
||||
use crate::movement::move_units;
|
||||
use crate::player_events::{CurrentEvent, PersistentEvents};
|
||||
use crate::player_events::{PersistentEvent, PersistentEvents};
|
||||
use crate::position::Position;
|
||||
use crate::tactics_card::{CombatRole, TacticsCard, TacticsCardTarget};
|
||||
use crate::unit::{UnitType, Units};
|
||||
use crate::unit::{UnitType, Units, kill_units};
|
||||
use crate::utils;
|
||||
use num::Zero;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::HashMap;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct CombatStrength {
|
||||
|
|
@ -293,12 +291,12 @@ pub(crate) fn combat_round_start(
|
|||
event_with_tactics(
|
||||
game,
|
||||
start,
|
||||
CurrentEventType::CombatRoundStart,
|
||||
PersistentEventType::CombatRoundStart,
|
||||
ROUND_START_TYPES,
|
||||
|phase| match phase {
|
||||
CombatEventPhase::Default => |e| &mut e.on_combat_round_start,
|
||||
CombatEventPhase::RevealTacticsCard => |e| &mut e.on_combat_round_start_reveal_tactics,
|
||||
CombatEventPhase::TacticsCard => |e| &mut e.on_combat_round_start_tactics,
|
||||
CombatEventPhase::Default => |e| &mut e.combat_round_start,
|
||||
CombatEventPhase::RevealTacticsCard => |e| &mut e.combat_round_start_reveal_tactics,
|
||||
CombatEventPhase::TacticsCard => |e| &mut e.combat_round_start_tactics,
|
||||
CombatEventPhase::Done => panic!("Invalid round type"),
|
||||
},
|
||||
|s| &mut s.phase,
|
||||
|
|
@ -315,11 +313,11 @@ pub(crate) fn combat_round_end(game: &mut Game, r: CombatRoundEnd) -> Option<Com
|
|||
let e = event_with_tactics(
|
||||
game,
|
||||
r,
|
||||
CurrentEventType::CombatRoundEnd,
|
||||
PersistentEventType::CombatRoundEnd,
|
||||
ROUND_END_TYPES,
|
||||
|phase| match phase {
|
||||
CombatEventPhase::Default => |e| &mut e.on_combat_round_end,
|
||||
CombatEventPhase::TacticsCard => |e| &mut e.on_combat_round_end_tactics,
|
||||
CombatEventPhase::Default => |e| &mut e.combat_round_end,
|
||||
CombatEventPhase::TacticsCard => |e| &mut e.combat_round_end_tactics,
|
||||
_ => panic!("Invalid round type"),
|
||||
},
|
||||
|s| &mut s.phase,
|
||||
|
|
@ -374,21 +372,21 @@ pub(crate) fn draw(game: &mut Game, c: Combat) {
|
|||
pub(crate) fn end_combat(game: &mut Game, info: CombatEnd) {
|
||||
let c = &info.combat;
|
||||
|
||||
let _ = game.trigger_current_event(
|
||||
let _ = game.trigger_persistent_event(
|
||||
&c.players(),
|
||||
|events| &mut events.on_combat_end,
|
||||
|events| &mut events.combat_end,
|
||||
info,
|
||||
CurrentEventType::CombatEnd,
|
||||
PersistentEventType::CombatEnd,
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) type GetCombatEvent<T> = fn(&mut PersistentEvents) -> &mut CurrentEvent<T>;
|
||||
pub(crate) type GetCombatEvent<T> = fn(&mut PersistentEvents) -> &mut PersistentEvent<T>;
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(crate) fn event_with_tactics<T: Clone + PartialEq>(
|
||||
game: &mut Game,
|
||||
mut event_type: T,
|
||||
store_type: impl Fn(T) -> CurrentEventType + Clone + 'static,
|
||||
store_type: impl Fn(T) -> PersistentEventType + Clone + 'static,
|
||||
round_types: &[CombatEventPhase],
|
||||
event: fn(&CombatEventPhase) -> GetCombatEvent<T>,
|
||||
get_round_type: impl Fn(&mut T) -> &mut CombatEventPhase,
|
||||
|
|
@ -409,7 +407,7 @@ pub(crate) fn event_with_tactics<T: Clone + PartialEq>(
|
|||
let reveal_card = matches!(t, CombatEventPhase::RevealTacticsCard);
|
||||
|
||||
event_type = (match t {
|
||||
CombatEventPhase::Default => game.trigger_current_event(
|
||||
CombatEventPhase::Default => game.trigger_persistent_event(
|
||||
&get_combat(&event_type).players(),
|
||||
event,
|
||||
event_type,
|
||||
|
|
@ -437,11 +435,11 @@ pub(crate) fn event_with_tactics<T: Clone + PartialEq>(
|
|||
pub(crate) fn trigger_tactics_event<T>(
|
||||
game: &mut Game,
|
||||
event_type: T,
|
||||
event: fn(&mut PersistentEvents) -> &mut CurrentEvent<T>,
|
||||
event: fn(&mut PersistentEvents) -> &mut PersistentEvent<T>,
|
||||
get_combat: impl Fn(&T) -> &Combat,
|
||||
get_attacker_tactics_card: impl Fn(&T) -> Option<&u8>,
|
||||
get_defender_tactics_card: impl Fn(&T) -> Option<&u8>,
|
||||
store_type: impl Fn(T) -> CurrentEventType,
|
||||
store_type: impl Fn(T) -> PersistentEventType,
|
||||
reveal_card: bool,
|
||||
) -> Option<T>
|
||||
where
|
||||
|
|
@ -474,7 +472,7 @@ where
|
|||
);
|
||||
|
||||
let players = &combat.players();
|
||||
let result = game.trigger_current_event(players, event, event_type, store_type);
|
||||
let result = game.trigger_persistent_event(players, event, event_type, store_type);
|
||||
|
||||
if let Some(card) = attacker_card {
|
||||
for p in players {
|
||||
|
|
@ -518,45 +516,67 @@ fn add_tactics_listener(
|
|||
}
|
||||
|
||||
pub(crate) fn choose_fighter_casualties() -> Builtin {
|
||||
choose_casualties(
|
||||
Builtin::builder("Choose Casualties", "Choose which carried units to remove."),
|
||||
1,
|
||||
|c, _, _, _| c.fighters,
|
||||
|game, player, c| c.fighting_units(game, player),
|
||||
kill_units,
|
||||
)
|
||||
}
|
||||
Builtin::builder("Choose Casualties", "Choose which carried units to remove.")
|
||||
.add_units_request(
|
||||
|event| &mut event.combat_round_end,
|
||||
1,
|
||||
move |game, player, r| {
|
||||
let choices = r.combat.fighting_units(game, player).clone();
|
||||
|
||||
pub(crate) fn choose_carried_units_casualties() -> Builtin {
|
||||
choose_casualties(
|
||||
Builtin::builder(
|
||||
"Choose Casualties (carried units)",
|
||||
"Choose which carried units to remove.",
|
||||
),
|
||||
2,
|
||||
|c, p, game, combat| combat.carried_units_casualties(game, p, c.fighters),
|
||||
|game, player, c| {
|
||||
let pos = c.position(player);
|
||||
let carried: Vec<u32> = game
|
||||
.get_player(player)
|
||||
.get_units(pos)
|
||||
.into_iter()
|
||||
.filter(|u| u.carrier_id.is_some())
|
||||
.map(|u| u.id)
|
||||
.collect();
|
||||
carried
|
||||
},
|
||||
|game, player, units, c| {
|
||||
kill_units(game, player, units, c);
|
||||
save_carried_units(units, game, player, c.position(player));
|
||||
},
|
||||
)
|
||||
let role = r.combat.role(player);
|
||||
let role_str = if role.is_attacker() {
|
||||
"attacking"
|
||||
} else {
|
||||
"defending"
|
||||
};
|
||||
let casualties = r.casualties(role).fighters;
|
||||
if casualties == 0 {
|
||||
return None;
|
||||
}
|
||||
let p = game.player(player);
|
||||
let name = p.get_name();
|
||||
if casualties == choices.len() as u8 {
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} has to remove all of their {role_str} units",
|
||||
));
|
||||
kill_fighters(game, player, &choices, &mut r.combat);
|
||||
return None;
|
||||
}
|
||||
|
||||
let first_type = p.get_unit(*choices.first().expect("no units")).unit_type;
|
||||
if choices
|
||||
.iter()
|
||||
.all(|u| p.get_unit(*u).unit_type == first_type)
|
||||
|| !p.is_human()
|
||||
{
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} has to remove {casualties} of their {role_str} units",
|
||||
));
|
||||
kill_fighters(game, player, &choices[..casualties as usize], &mut r.combat);
|
||||
return None;
|
||||
}
|
||||
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} has to remove {casualties} of their {role_str} units",
|
||||
));
|
||||
Some(UnitsRequest::new(
|
||||
player,
|
||||
choices,
|
||||
casualties..=casualties,
|
||||
&format!("Remove {casualties} {role_str} units"),
|
||||
))
|
||||
},
|
||||
move |game, s, e| {
|
||||
kill_fighters(game, s.player_index, &s.choice, &mut e.combat);
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn offer_retreat() -> Builtin {
|
||||
Builtin::builder("Offer Retreat", "Do you want to retreat?")
|
||||
.add_bool_request(
|
||||
|event| &mut event.on_combat_round_end,
|
||||
|event| &mut event.combat_round_end,
|
||||
0,
|
||||
|game, player, r| {
|
||||
let c = &r.combat;
|
||||
|
|
@ -583,80 +603,16 @@ pub(crate) fn offer_retreat() -> Builtin {
|
|||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn choose_casualties(
|
||||
builder: BuiltinBuilder,
|
||||
priority: i32,
|
||||
get_casualties: impl Fn(&Casualties, usize, &Game, &Combat) -> u8 + 'static + Clone,
|
||||
get_choices: impl Fn(&Game, usize, &Combat) -> Vec<u32> + 'static + Clone,
|
||||
kill_units: impl Fn(&mut Game, usize, &[u32], &mut Combat) + 'static + Copy,
|
||||
) -> Builtin {
|
||||
builder
|
||||
.add_units_request(
|
||||
|event| &mut event.on_combat_round_end,
|
||||
priority,
|
||||
move |game, player, r| {
|
||||
let choices = get_choices(game, player, &mut r.combat).clone();
|
||||
|
||||
let role = r.combat.role(player);
|
||||
let role_str = if role.is_attacker() {
|
||||
"attacking"
|
||||
} else {
|
||||
"defending"
|
||||
};
|
||||
let casualties = get_casualties(r.casualties(role), player, game, &r.combat);
|
||||
if casualties == 0 {
|
||||
return None;
|
||||
}
|
||||
let p = game.get_player(player);
|
||||
let name = p.get_name();
|
||||
if casualties == choices.len() as u8 {
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} has to remove all of their {role_str} units",
|
||||
));
|
||||
kill_units(game, player, &choices, &mut r.combat);
|
||||
return None;
|
||||
}
|
||||
|
||||
let first_type = p.get_unit(*choices.first().expect("no units")).unit_type;
|
||||
if choices
|
||||
.iter()
|
||||
.all(|u| p.get_unit(*u).unit_type == first_type)
|
||||
|| !p.is_human()
|
||||
{
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} has to remove {casualties} of their {role_str} units",
|
||||
));
|
||||
kill_units(game, player, &choices[..casualties as usize], &mut r.combat);
|
||||
return None;
|
||||
}
|
||||
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} has to remove {casualties} of their {role_str} units",
|
||||
));
|
||||
Some(UnitsRequest::new(
|
||||
player,
|
||||
choices,
|
||||
casualties..=casualties,
|
||||
&format!("Remove {casualties} {role_str} units"),
|
||||
))
|
||||
},
|
||||
move |game, s, e| {
|
||||
kill_units(game, s.player_index, &s.choice, &mut e.combat);
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn place_settler() -> Builtin {
|
||||
Builtin::builder(
|
||||
"Place Settler",
|
||||
"After losing a city, place a settler in another city.",
|
||||
)
|
||||
.add_position_request(
|
||||
|event| &mut event.on_combat_end,
|
||||
|event| &mut event.combat_end,
|
||||
0,
|
||||
|game, player_index, i| {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
if i.is_defender(player_index)
|
||||
&& i.is_loser(player_index)
|
||||
&& game.try_get_any_city(i.combat.defender_position).is_some()
|
||||
|
|
@ -681,15 +637,15 @@ pub(crate) fn place_settler() -> Builtin {
|
|||
"{} gained 1 free Settler Unit at {} for losing a city",
|
||||
s.player_name, pos
|
||||
));
|
||||
game.get_player_mut(s.player_index)
|
||||
game.player_mut(s.player_index)
|
||||
.add_unit(pos, UnitType::Settler);
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn kill_units(game: &mut Game, player: usize, killed_unit_ids: &[u32], c: &mut Combat) {
|
||||
let p = game.get_player(player);
|
||||
fn kill_fighters(game: &mut Game, player: usize, killed_unit_ids: &[u32], c: &mut Combat) {
|
||||
let p = game.player(player);
|
||||
game.add_info_log_item(&format!(
|
||||
"{} removed {}",
|
||||
p.get_name(),
|
||||
|
|
@ -699,46 +655,19 @@ fn kill_units(game: &mut Game, player: usize, killed_unit_ids: &[u32], c: &mut C
|
|||
.collect::<Units>()
|
||||
));
|
||||
|
||||
let killer = c.opponent(player);
|
||||
|
||||
for unit in killed_unit_ids {
|
||||
game.kill_unit(*unit, player, Some(killer));
|
||||
if player == c.attacker {
|
||||
c.attackers.retain(|id| id != unit);
|
||||
}
|
||||
}
|
||||
kill_combat_units(game, c, player, killed_unit_ids);
|
||||
}
|
||||
|
||||
fn save_carried_units(killed_unit_ids: &[u32], game: &mut Game, player: usize, pos: Position) {
|
||||
let mut carried_units: HashMap<u32, u8> = HashMap::new();
|
||||
|
||||
for unit in game.get_player(player).clone().get_units(pos) {
|
||||
if killed_unit_ids.contains(&unit.id) {
|
||||
continue;
|
||||
}
|
||||
if let Some(carrier) = unit.carrier_id {
|
||||
carried_units
|
||||
.entry(carrier)
|
||||
.and_modify(|e| *e += 1)
|
||||
.or_insert(1);
|
||||
} else {
|
||||
carried_units.entry(unit.id).or_insert(0);
|
||||
}
|
||||
}
|
||||
|
||||
// embark to surviving ships
|
||||
for unit in game.get_player(player).clone().get_units(pos) {
|
||||
let unit = game.players[player].get_unit_mut(unit.id);
|
||||
if unit
|
||||
.carrier_id
|
||||
.is_some_and(|id| killed_unit_ids.contains(&id))
|
||||
{
|
||||
let (&carrier_id, &carried) = carried_units
|
||||
.iter()
|
||||
.find(|(_carrier_id, carried)| **carried < SHIP_CAPACITY)
|
||||
.expect("no carrier found to save carried units");
|
||||
carried_units.insert(carrier_id, carried + 1);
|
||||
unit.carrier_id = Some(carrier_id);
|
||||
pub(crate) fn kill_combat_units(
|
||||
game: &mut Game,
|
||||
c: &mut Combat,
|
||||
player: usize,
|
||||
killed_unit_ids: &[u32],
|
||||
) {
|
||||
kill_units(game, killed_unit_ids, player, Some(c.opponent(player)));
|
||||
for unit in killed_unit_ids {
|
||||
if player == c.attacker {
|
||||
c.attackers.retain(|id| id != unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -746,7 +675,7 @@ fn save_carried_units(killed_unit_ids: &[u32], game: &mut Game, player: usize, p
|
|||
pub(crate) fn combat_stats() -> Builtin {
|
||||
Builtin::builder("Combat stats", "")
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_combat_round_end,
|
||||
|event| &mut event.combat_round_end,
|
||||
11,
|
||||
|game, _player, _name, e| {
|
||||
if let Some(r) = &e.final_result {
|
||||
|
|
|
|||
|
|
@ -203,7 +203,7 @@ fn add_roll_log_effect(roll_log: &mut [String], effect: &str) {
|
|||
}
|
||||
|
||||
fn roll_die(game: &mut Game, roll_log: &mut Vec<String>) -> CombatDieRoll {
|
||||
let roll = game.get_next_dice_roll();
|
||||
let roll = game.next_dice_roll();
|
||||
roll_log.push(format!("{} ({:?}, ", roll.value, roll.bonus));
|
||||
roll.clone()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::city::{City, MoodState};
|
||||
use crate::city_pieces::Building;
|
||||
use crate::consts::MAX_CITY_SIZE;
|
||||
use crate::content::custom_phase_actions::CurrentEventType;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::game::Game;
|
||||
use crate::player::Player;
|
||||
use crate::position::Position;
|
||||
|
|
@ -81,11 +81,11 @@ pub(crate) fn can_construct_anything(city: &City, player: &Player) -> Result<(),
|
|||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn construct(game: &mut Game, player_index: usize, c: &Construct) {
|
||||
pub(crate) fn construct(game: &mut Game, player_index: usize, c: &Construct) -> Result<(), String> {
|
||||
let player = &game.players[player_index];
|
||||
let city = player.get_city(c.city_position);
|
||||
let cost = player.construct_cost(game, c.city_piece, Some(&c.payment));
|
||||
let _ = can_construct(city, c.city_piece, player, game).map_err(|e| panic!("{e}"));
|
||||
can_construct(city, c.city_piece, player, game)?;
|
||||
if matches!(c.city_piece, Building::Port) {
|
||||
let port_position = c.port_position.as_ref().expect("Illegal action");
|
||||
assert!(
|
||||
|
|
@ -95,7 +95,7 @@ pub(crate) fn construct(game: &mut Game, player_index: usize, c: &Construct) {
|
|||
} else if c.port_position.is_some() {
|
||||
panic!("Illegal action");
|
||||
}
|
||||
game.get_player_mut(player_index).construct(
|
||||
game.player_mut(player_index).construct(
|
||||
c.city_piece,
|
||||
c.city_position,
|
||||
c.port_position,
|
||||
|
|
@ -103,13 +103,14 @@ pub(crate) fn construct(game: &mut Game, player_index: usize, c: &Construct) {
|
|||
);
|
||||
cost.pay(game, &c.payment);
|
||||
on_construct(game, player_index, c.city_piece);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub(crate) fn on_construct(game: &mut Game, player_index: usize, building: Building) {
|
||||
let _ = game.trigger_current_event(
|
||||
let _ = game.trigger_persistent_event(
|
||||
&[player_index],
|
||||
|e| &mut e.on_construct,
|
||||
|e| &mut e.construct,
|
||||
building,
|
||||
CurrentEventType::Construct,
|
||||
PersistentEventType::Construct,
|
||||
);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ pub mod advances;
|
|||
pub mod builtin;
|
||||
pub mod civilizations;
|
||||
pub mod custom_actions;
|
||||
pub mod custom_phase_actions;
|
||||
pub mod effects;
|
||||
pub mod incidents;
|
||||
pub mod persistent_events;
|
||||
pub mod tactics_cards;
|
||||
pub mod wonders;
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ pub(crate) mod cultural_takeover;
|
|||
pub(crate) mod development;
|
||||
mod inspiration;
|
||||
mod mercenaries;
|
||||
pub(crate) mod negotiation;
|
||||
pub mod spy;
|
||||
|
||||
use crate::action_card::{ActionCard, CivilCard};
|
||||
use crate::content::action_cards::inspiration::inspiration_action_cards;
|
||||
use crate::content::action_cards::negotiation::negotiation_action_cards;
|
||||
use crate::content::incidents;
|
||||
use crate::content::tactics_cards::martyr;
|
||||
use crate::playing_actions::ActionType;
|
||||
use development::development_action_cards;
|
||||
use itertools::Itertools;
|
||||
|
||||
|
|
@ -17,7 +17,7 @@ pub(crate) fn get_all() -> Vec<ActionCard> {
|
|||
let all = vec![
|
||||
inspiration_action_cards(),
|
||||
development_action_cards(),
|
||||
park_here(),
|
||||
negotiation_action_cards(),
|
||||
]
|
||||
.into_iter()
|
||||
.flatten()
|
||||
|
|
@ -30,17 +30,6 @@ pub(crate) fn get_all() -> Vec<ActionCard> {
|
|||
all
|
||||
}
|
||||
|
||||
fn park_here() -> Vec<ActionCard> {
|
||||
// todo move to separate file
|
||||
vec![
|
||||
ActionCard::builder(24, "todo", "todo", ActionType::free(), |_game, _player| {
|
||||
true
|
||||
})
|
||||
.tactics_card(martyr)
|
||||
.build(),
|
||||
]
|
||||
}
|
||||
|
||||
///
|
||||
/// # Panics
|
||||
/// Panics if action card does not exist
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action_card::{on_play_action_card, ActionCard, ActionCardInfo};
|
||||
use crate::action_card::{ActionCard, ActionCardInfo, on_play_action_card};
|
||||
use crate::barbarians::get_barbarians_player;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_actions::CustomActionType;
|
||||
use crate::content::custom_phase_actions::{Structure, UnitTypeRequest};
|
||||
use crate::content::effects::PermanentEffect;
|
||||
use crate::content::persistent_events::{Structure, UnitTypeRequest};
|
||||
use crate::content::tactics_cards::TacticsCardFactory;
|
||||
use crate::game::Game;
|
||||
use crate::player_events::{InfluenceCultureInfo, PlayingActionInfo};
|
||||
|
|
@ -25,19 +25,19 @@ pub(crate) fn cultural_takeover(id: u8, tactics_card: TacticsCardFactory) -> Act
|
|||
|_game, _p| true,
|
||||
)
|
||||
.add_unit_type_request(
|
||||
|event| &mut event.on_play_action_card,
|
||||
|event| &mut event.play_action_card,
|
||||
1,
|
||||
|game, player, a| {
|
||||
if let Some(position) = a.selected_position {
|
||||
//set in use_cultural_takeover
|
||||
let b = game.get_player_mut(get_barbarians_player(game).index);
|
||||
let b = game.player_mut(get_barbarians_player(game).index);
|
||||
let units = b.get_units(position).iter().map(|u| u.id).collect_vec();
|
||||
let len = units.len();
|
||||
for id in units {
|
||||
b.remove_unit(id);
|
||||
}
|
||||
if len > 0 {
|
||||
let p = game.get_player_mut(player);
|
||||
let p = game.player_mut(player);
|
||||
let u = p.available_units();
|
||||
let mut t = vec![];
|
||||
if u.settlers > 0 {
|
||||
|
|
@ -60,12 +60,12 @@ pub(crate) fn cultural_takeover(id: u8, tactics_card: TacticsCardFactory) -> Act
|
|||
"{} selected unit to gain: {:?}",
|
||||
s.player_name, s.choice,
|
||||
));
|
||||
game.get_player_mut(s.player_index)
|
||||
game.player_mut(s.player_index)
|
||||
.add_unit(a.selected_position.expect("unit position"), s.choice);
|
||||
},
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_play_action_card,
|
||||
|event| &mut event.play_action_card,
|
||||
0,
|
||||
|game, _player, _name, a| {
|
||||
if a.selected_position.is_none() {
|
||||
|
|
@ -131,7 +131,7 @@ pub(crate) fn use_cultural_takeover() -> Builtin {
|
|||
}
|
||||
|
||||
fn is_barbarian_takeover(game: &Game, c: &InfluenceCultureInfo) -> bool {
|
||||
let city = game.get_any_city(c.position);
|
||||
let city = game.any_city(c.position);
|
||||
city.player_index == get_barbarians_player(game).index
|
||||
&& city.size() == 1
|
||||
&& game
|
||||
|
|
|
|||
|
|
@ -5,13 +5,16 @@ use crate::content::action_cards::mercenaries::mercenaries;
|
|||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_actions::CustomActionType;
|
||||
use crate::content::effects::{CollectEffect, ConstructEffect, PermanentEffect};
|
||||
use crate::content::incidents::great_explorer::{action_explore_request, explore_adjacent_block};
|
||||
use crate::content::persistent_events::PositionRequest;
|
||||
use crate::content::tactics_cards::{
|
||||
for_the_people, heavy_resistance, improved_defenses, peltasts, tactical_retreat,
|
||||
TacticsCardFactory,
|
||||
TacticsCardFactory, defensive_formation, encircled, for_the_people, heavy_resistance,
|
||||
improved_defenses, peltasts, tactical_retreat,
|
||||
};
|
||||
use crate::player_events::PlayingActionInfo;
|
||||
use crate::playing_actions::{ActionType, PlayingActionType};
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::unit::UnitType;
|
||||
use crate::utils::remove_element_by;
|
||||
|
||||
pub(crate) fn development_action_cards() -> Vec<ActionCard> {
|
||||
|
|
@ -24,6 +27,8 @@ pub(crate) fn development_action_cards() -> Vec<ActionCard> {
|
|||
city_development(18, peltasts),
|
||||
production_focus(19, tactical_retreat),
|
||||
production_focus(20, peltasts),
|
||||
explorer(21, encircled),
|
||||
explorer(22, defensive_formation),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
@ -37,7 +42,7 @@ fn city_development(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
)
|
||||
.tactics_card(tactics_card)
|
||||
.add_simple_persistent_event_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, _player, _name, _| {
|
||||
game.permanent_effects
|
||||
|
|
@ -63,7 +68,7 @@ fn production_focus(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
)
|
||||
.tactics_card(tactics_card)
|
||||
.add_simple_persistent_event_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, _player, _name, _| {
|
||||
game.permanent_effects
|
||||
|
|
@ -103,14 +108,14 @@ pub(crate) fn collect_only() -> Builtin {
|
|||
.any(|e| matches!(e, &PermanentEffect::Collect(CollectEffect::ProductionFocus)))
|
||||
{
|
||||
c.max_per_tile = game
|
||||
.get_any_city(context.city_position)
|
||||
.mood_modified_size(game.get_player(context.player_index))
|
||||
.any_city(context.city_position)
|
||||
.mood_modified_size(game.player(context.player_index))
|
||||
as u32;
|
||||
}
|
||||
},
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_collect,
|
||||
|event| &mut event.collect,
|
||||
2,
|
||||
|game, _, _, _| {
|
||||
remove_element_by(&mut game.permanent_effects, |e| {
|
||||
|
|
@ -132,3 +137,53 @@ fn is_collect(i: &PlayingActionInfo) -> bool {
|
|||
_ => false,
|
||||
}
|
||||
}
|
||||
|
||||
fn explorer(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
||||
let b = ActionCard::builder(
|
||||
id,
|
||||
"Explorer",
|
||||
"Construct a building without paying resources.",
|
||||
ActionType::regular_with_cost(ResourcePile::culture_tokens(1)),
|
||||
|game, player| {
|
||||
!action_explore_request(game, player.index)
|
||||
.request
|
||||
.choices
|
||||
.is_empty()
|
||||
},
|
||||
)
|
||||
.tactics_card(tactics_card);
|
||||
|
||||
explore_adjacent_block(b)
|
||||
.add_position_request(
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player_index, _| {
|
||||
let p = game.player(player_index);
|
||||
if p.available_units().settlers == 0 {
|
||||
return None;
|
||||
}
|
||||
Some(PositionRequest::new(
|
||||
p.cities.iter().map(|c| c.position).collect(),
|
||||
0..=1,
|
||||
"Gain a free settler",
|
||||
))
|
||||
},
|
||||
|game, s, _a| {
|
||||
if s.choice.is_empty() {
|
||||
game.add_info_log_item(&format!(
|
||||
"{} decided not to gain a free settler",
|
||||
s.player_name
|
||||
));
|
||||
} else {
|
||||
let pos = s.choice[0];
|
||||
game.add_info_log_item(&format!(
|
||||
"{} decided to gain a free settler at {}",
|
||||
s.player_name, pos
|
||||
));
|
||||
game.player_mut(s.player_index)
|
||||
.add_unit(pos, UnitType::Settler);
|
||||
}
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,10 @@ use crate::advance::gain_advance;
|
|||
use crate::city::MoodState;
|
||||
use crate::content::action_cards::spy::spy;
|
||||
use crate::content::advances;
|
||||
use crate::content::custom_phase_actions::{AdvanceRequest, PaymentRequest, PositionRequest};
|
||||
use crate::content::persistent_events::{AdvanceRequest, PaymentRequest, PositionRequest};
|
||||
use crate::content::tactics_cards::{
|
||||
encircled, heavy_resistance, high_ground, high_morale, peltasts, siege, surprise,
|
||||
wedge_formation, TacticsCardFactory,
|
||||
TacticsCardFactory, encircled, heavy_resistance, high_ground, high_morale, peltasts, siege,
|
||||
surprise, wedge_formation,
|
||||
};
|
||||
use crate::game::Game;
|
||||
use crate::payment::PaymentOptions;
|
||||
|
|
@ -49,13 +49,9 @@ fn advance(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
)
|
||||
.tactics_card(tactics_card)
|
||||
.add_advance_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player, _| {
|
||||
Some(AdvanceRequest::new(possible_advances(
|
||||
game.get_player(player),
|
||||
)))
|
||||
},
|
||||
|game, player, _| Some(AdvanceRequest::new(possible_advances(game.player(player)))),
|
||||
|game, sel, _| {
|
||||
let advance = sel.choice.clone();
|
||||
gain_advance(
|
||||
|
|
@ -93,12 +89,12 @@ fn inspiration(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
)
|
||||
.tactics_card(tactics_card)
|
||||
.add_advance_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player, _| {
|
||||
Some(AdvanceRequest::new(possible_inspiration_advances(
|
||||
game,
|
||||
game.get_player(player),
|
||||
game.player(player),
|
||||
)))
|
||||
},
|
||||
|game, sel, _| {
|
||||
|
|
@ -122,7 +118,7 @@ fn inspiration(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
fn possible_inspiration_advances(game: &Game, player: &Player) -> Vec<String> {
|
||||
let players = players_in_range2(game, player)
|
||||
.iter()
|
||||
.map(|&i| game.get_player(i))
|
||||
.map(|&i| game.player(i))
|
||||
.collect_vec();
|
||||
|
||||
advances::get_all()
|
||||
|
|
@ -176,10 +172,10 @@ fn hero_general(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
|
||||
b = increase_mood(b, 2, false);
|
||||
b = b.add_payment_request_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
1,
|
||||
|game, player, _| {
|
||||
if cities_where_mood_can_increase(game.get_player(player)).is_empty() {
|
||||
if cities_where_mood_can_increase(game.player(player)).is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
@ -205,13 +201,13 @@ fn hero_general(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
|
||||
fn increase_mood(b: ActionCardBuilder, priority: i32, need_payment: bool) -> ActionCardBuilder {
|
||||
b.add_position_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
priority,
|
||||
move |game, player, a| {
|
||||
if need_payment && a.answer.is_none() {
|
||||
return None;
|
||||
}
|
||||
let choices = cities_where_mood_can_increase(game.get_player(player));
|
||||
let choices = cities_where_mood_can_increase(game.player(player));
|
||||
let needed = 1..=1;
|
||||
Some(PositionRequest::new(
|
||||
choices,
|
||||
|
|
@ -226,7 +222,7 @@ fn increase_mood(b: ActionCardBuilder, priority: i32, need_payment: bool) -> Act
|
|||
"{} selected city {} to increase the mood by 1",
|
||||
s.player_name, pos
|
||||
));
|
||||
game.get_player_mut(player)
|
||||
game.player_mut(player)
|
||||
.get_city_mut(pos)
|
||||
.increase_mood_state();
|
||||
},
|
||||
|
|
@ -252,10 +248,10 @@ fn ideas(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
)
|
||||
.tactics_card(tactics_card)
|
||||
.add_simple_persistent_event_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player, name, _| {
|
||||
let p = game.get_player_mut(player);
|
||||
let p = game.player_mut(player);
|
||||
let pile = ResourcePile::ideas(academies(p));
|
||||
p.gain_resources(pile.clone());
|
||||
game.add_info_log_item(&format!("{name} gained {pile} (1 for each Academy)"));
|
||||
|
|
@ -289,10 +285,10 @@ fn great_ideas(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
))
|
||||
.tactics_card(tactics_card)
|
||||
.add_simple_persistent_event_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player, name, _| {
|
||||
let p = game.get_player_mut(player);
|
||||
let p = game.player_mut(player);
|
||||
let pile = ResourcePile::ideas(2);
|
||||
p.gain_resources(pile.clone());
|
||||
game.add_info_log_item(&format!("{name} gained {pile} for Great Ideas"));
|
||||
|
|
|
|||
|
|
@ -4,17 +4,17 @@ use crate::barbarians::{barbarian_reinforcement, get_barbarians_player};
|
|||
use crate::combat::move_with_possible_combat;
|
||||
use crate::consts::STACK_LIMIT;
|
||||
use crate::content::action_cards::inspiration::player_positions;
|
||||
use crate::content::custom_phase_actions::{PaymentRequest, PositionRequest};
|
||||
use crate::content::persistent_events::{PaymentRequest, PositionRequest};
|
||||
use crate::content::tactics_cards::TacticsCardFactory;
|
||||
use crate::game::Game;
|
||||
use crate::log::move_action_log;
|
||||
use crate::movement::MoveUnits;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::player::Player;
|
||||
use crate::playing_actions::ActionType;
|
||||
use crate::position::Position;
|
||||
use crate::resource::ResourceType;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::unit::MoveUnits;
|
||||
use crate::utils::remove_element;
|
||||
use itertools::Itertools;
|
||||
|
||||
|
|
@ -33,10 +33,10 @@ pub(crate) fn mercenaries(id: u8, tactics_card: TacticsCardFactory) -> ActionCar
|
|||
)
|
||||
.tactics_card(tactics_card)
|
||||
.add_position_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
100,
|
||||
|game, player, _| {
|
||||
let p = game.get_player(player);
|
||||
let p = game.player(player);
|
||||
let r = barbarian_army_positions_in_range2(game, p);
|
||||
if r.is_empty() {
|
||||
return None;
|
||||
|
|
@ -58,7 +58,7 @@ pub(crate) fn mercenaries(id: u8, tactics_card: TacticsCardFactory) -> ActionCar
|
|||
},
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
99,
|
||||
|_game, _player, a| {
|
||||
Some(vec![PaymentRequest::new(
|
||||
|
|
@ -98,7 +98,7 @@ fn move_army(b: ActionCardBuilder, i: i32) -> ActionCardBuilder {
|
|||
let reinforce_prio = i * 3;
|
||||
let b = b
|
||||
.add_position_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
src_prio,
|
||||
|_game, _player, a| {
|
||||
a.selected_position = None;
|
||||
|
|
@ -120,7 +120,7 @@ fn move_army(b: ActionCardBuilder, i: i32) -> ActionCardBuilder {
|
|||
},
|
||||
)
|
||||
.add_position_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
dst_prio,
|
||||
|game, _player, a| {
|
||||
let from = a.selected_position?;
|
||||
|
|
@ -164,7 +164,7 @@ fn move_army(b: ActionCardBuilder, i: i32) -> ActionCardBuilder {
|
|||
|
||||
barbarian_reinforcement(
|
||||
b,
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
reinforce_prio,
|
||||
|game, _, a| {
|
||||
a.selected_position
|
||||
|
|
|
|||
107
server/src/content/action_cards/negotiation.rs
Normal file
107
server/src/content/action_cards/negotiation.rs
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action::Action;
|
||||
use crate::action_card::ActionCard;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::effects::PermanentEffect;
|
||||
use crate::content::incidents::great_diplomat::{DiplomaticRelations, Negotiations};
|
||||
use crate::content::persistent_events::PlayerRequest;
|
||||
use crate::content::tactics_cards::{TacticsCardFactory, martyr, scout};
|
||||
use crate::game::Game;
|
||||
use crate::log::current_player_turn_log;
|
||||
use crate::playing_actions::{ActionType, PlayingAction};
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::utils::remove_element_by;
|
||||
|
||||
pub(crate) fn negotiation_action_cards() -> Vec<ActionCard> {
|
||||
vec![negotiations(23, scout), negotiations(24, martyr)]
|
||||
}
|
||||
|
||||
fn negotiations(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
||||
ActionCard::builder(
|
||||
id,
|
||||
"Negotiations",
|
||||
"Select another player. This turn, you may not attack that player. \
|
||||
In their next turn, they may not attack you.",
|
||||
ActionType::cost(ResourcePile::culture_tokens(1)),
|
||||
move |game, _player| {
|
||||
!current_player_turn_log(game)
|
||||
.items
|
||||
.iter()
|
||||
.any(|i| match &i.action {
|
||||
Action::Playing(PlayingAction::ActionCard(i)) if *i == id => false,
|
||||
Action::Playing(_) | Action::Movement(_) => true,
|
||||
_ => false,
|
||||
})
|
||||
},
|
||||
)
|
||||
.add_player_request(
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player_index, _| {
|
||||
Some(PlayerRequest::new(
|
||||
game.players
|
||||
.iter()
|
||||
.filter(|p| p.index != player_index && p.is_human())
|
||||
.map(|p| p.index)
|
||||
.collect(),
|
||||
"Select a player to negotiate with",
|
||||
))
|
||||
},
|
||||
|game, s, _| {
|
||||
game.permanent_effects
|
||||
.push(PermanentEffect::Negotiations(Negotiations {
|
||||
relations: DiplomaticRelations::new(s.player_index, s.choice),
|
||||
remaining_turns: 2,
|
||||
}));
|
||||
game.add_info_log_item(&format!(
|
||||
"{} and {} are in negotiations.",
|
||||
s.player_name,
|
||||
game.player_name(s.choice)
|
||||
));
|
||||
},
|
||||
)
|
||||
.tactics_card(tactics_card)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn use_negotiations() -> Builtin {
|
||||
Builtin::builder("Negotiations", "")
|
||||
.add_simple_persistent_event_listener(
|
||||
|e| &mut e.turn_start,
|
||||
1,
|
||||
|game, player_index, player_name, ()| {
|
||||
if let Some(negotiations_partner) = negotiations_partner(game, player_index) {
|
||||
let partner_name = game.player_name(negotiations_partner);
|
||||
for e in &mut game.permanent_effects {
|
||||
if let PermanentEffect::Negotiations(d) = e {
|
||||
d.remaining_turns -= 1;
|
||||
if d.remaining_turns == 0 {
|
||||
game.add_info_log_item(&format!(
|
||||
"{player_name} may attack {partner_name} again.",
|
||||
));
|
||||
remove_element_by(&mut game.permanent_effects, |e| {
|
||||
matches!(e, PermanentEffect::Negotiations(_))
|
||||
});
|
||||
} else {
|
||||
game.add_info_log_item(&format!(
|
||||
"{player_name} may not attack {partner_name} this turn.",
|
||||
));
|
||||
}
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn negotiations_partner(game: &Game, p: usize) -> Option<usize> {
|
||||
game.permanent_effects.iter().find_map(|e| {
|
||||
if let PermanentEffect::Negotiations(d) = e {
|
||||
d.relations.partner(p)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action_card::ActionCard;
|
||||
use crate::card::{hand_cards, HandCard, HandCardType};
|
||||
use crate::card::{HandCard, HandCardType, hand_cards};
|
||||
use crate::content::action_cards::get_action_card;
|
||||
use crate::content::custom_phase_actions::{CurrentEventType, HandCardsRequest, PlayerRequest};
|
||||
use crate::content::persistent_events::{HandCardsRequest, PersistentEventType, PlayerRequest};
|
||||
use crate::content::tactics_cards::TacticsCardFactory;
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
|
|
@ -22,7 +22,7 @@ pub(crate) fn spy(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
|game, player| !players_with_cards(game, player.index).is_empty(),
|
||||
)
|
||||
.add_player_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
1,
|
||||
|game, player, _| {
|
||||
Some(PlayerRequest::new(
|
||||
|
|
@ -41,13 +41,13 @@ pub(crate) fn spy(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
},
|
||||
)
|
||||
.add_hand_card_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player, a| {
|
||||
game.lock_undo(); // you've seen the cards
|
||||
|
||||
let p = game.get_player(player);
|
||||
let other = game.get_player(a.selected_player.expect("player not found"));
|
||||
let p = game.player(player);
|
||||
let other = game.player(a.selected_player.expect("player not found"));
|
||||
|
||||
let all = HandCardType::get_all();
|
||||
let mut cards = hand_cards(other, &all);
|
||||
|
|
@ -58,7 +58,7 @@ pub(crate) fn spy(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
|
|||
}
|
||||
|
||||
let secrets = get_swap_secrets(other);
|
||||
game.get_player_mut(player).secrets.extend(secrets);
|
||||
game.player_mut(player).secrets.extend(secrets);
|
||||
|
||||
Some(HandCardsRequest::new(
|
||||
cards,
|
||||
|
|
@ -110,8 +110,8 @@ fn swap_cards(
|
|||
return Err("must select 2 cards".to_string());
|
||||
}
|
||||
|
||||
let p = game.get_player(player);
|
||||
let o = game.get_player(other);
|
||||
let p = game.player(player);
|
||||
let o = game.player(other);
|
||||
let our_card = get_swap_card(swap, p);
|
||||
let other_card = get_swap_card(swap, o);
|
||||
|
||||
|
|
@ -150,13 +150,13 @@ fn swap_card<T: PartialEq + Ord>(
|
|||
other_id: &T,
|
||||
get_list: impl Fn(&mut Player) -> &mut Vec<T>,
|
||||
) {
|
||||
let card = remove_element(get_list(game.get_player_mut(player)), id).expect("card not found");
|
||||
let o = game.get_player_mut(other);
|
||||
let card = remove_element(get_list(game.player_mut(player)), id).expect("card not found");
|
||||
let o = game.player_mut(other);
|
||||
let other_card = remove_element(get_list(o), other_id).expect("card not found");
|
||||
|
||||
get_list(o).push(card);
|
||||
get_list(o).sort();
|
||||
let p = game.get_player_mut(player);
|
||||
let p = game.player_mut(player);
|
||||
get_list(p).push(other_card);
|
||||
get_list(p).sort();
|
||||
}
|
||||
|
|
@ -213,7 +213,7 @@ pub fn validate_if_spy(cards: &[HandCard], game: &Game) -> bool {
|
|||
match h.origin {
|
||||
EventOrigin::CivilCard(id) if id == 7 || id == 8 => {
|
||||
let mut g = game.clone();
|
||||
let CurrentEventType::ActionCard(c) = &s.event_type else {
|
||||
let PersistentEventType::ActionCard(c) = &s.event_type else {
|
||||
panic!("wrong event type");
|
||||
};
|
||||
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::ability_initializer::AbilityInitializerSetup;
|
|||
use crate::advance::Bonus::MoodToken;
|
||||
use crate::advance::{Advance, AdvanceBuilder};
|
||||
use crate::collect::{CollectContext, CollectInfo};
|
||||
use crate::content::advances::{advance_group_builder, AdvanceGroup, IRRIGATION, ROADS};
|
||||
use crate::content::advances::{AdvanceGroup, IRRIGATION, ROADS, advance_group_builder};
|
||||
use crate::game::Game;
|
||||
use crate::map::Terrain::Barren;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::advance::{Advance, AdvanceBuilder};
|
||||
use crate::content::advances::{advance_group_builder, AdvanceGroup};
|
||||
use crate::content::advances::{AdvanceGroup, advance_group_builder};
|
||||
use crate::content::custom_actions::CustomActionType::{AbsolutePower, ForcedLabor};
|
||||
use crate::content::custom_phase_actions::ResourceRewardRequest;
|
||||
use crate::content::persistent_events::ResourceRewardRequest;
|
||||
use crate::payment::PaymentOptions;
|
||||
|
||||
pub(crate) fn autocracy() -> AdvanceGroup {
|
||||
|
|
@ -23,7 +23,7 @@ fn nationalism() -> AdvanceBuilder {
|
|||
"Gain 1 mood or culture token when you recruit an army or ship unit.",
|
||||
)
|
||||
.add_resource_request(
|
||||
|event| &mut event.on_recruit,
|
||||
|event| &mut event.recruit,
|
||||
1,
|
||||
|_game, _player_index, recruit| {
|
||||
if recruit
|
||||
|
|
@ -61,7 +61,7 @@ fn totalitarianism() -> AdvanceBuilder {
|
|||
|info, city, game| {
|
||||
if info.is_defender
|
||||
&& game
|
||||
.get_player(city.player_index)
|
||||
.player(city.player_index)
|
||||
.get_units(city.position)
|
||||
.iter()
|
||||
.any(|u| u.unit_type.is_army_unit())
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::advance::Bonus::{CultureToken, MoodToken};
|
||||
use crate::advance::{Advance, AdvanceBuilder};
|
||||
use crate::content::advances::{advance_group_builder, AdvanceGroup, ROADS};
|
||||
use crate::content::advances::{AdvanceGroup, ROADS, advance_group_builder};
|
||||
use crate::payment::PaymentConversion;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::unit::UnitType;
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::advance::Bonus::{CultureToken, MoodToken};
|
|||
use crate::advance::{Advance, AdvanceBuilder};
|
||||
use crate::city::{City, MoodState};
|
||||
use crate::city_pieces::Building::Obelisk;
|
||||
use crate::content::advances::{advance_group_builder, AdvanceGroup};
|
||||
use crate::content::advances::{AdvanceGroup, advance_group_builder};
|
||||
use crate::content::custom_actions::CustomActionType;
|
||||
use crate::game::Game;
|
||||
use crate::payment::PaymentOptions;
|
||||
|
|
@ -88,7 +88,7 @@ pub(crate) fn execute_sports(
|
|||
pos: Position,
|
||||
payment: &ResourcePile,
|
||||
) {
|
||||
let options = sports_options(game.get_city(player_index, pos));
|
||||
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);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use crate::ability_initializer::AbilityInitializerSetup;
|
|||
use crate::action::Action;
|
||||
use crate::advance::{Advance, AdvanceBuilder};
|
||||
use crate::city::MoodState;
|
||||
use crate::content::advances::{advance_group_builder, AdvanceGroup};
|
||||
use crate::content::advances::{AdvanceGroup, advance_group_builder};
|
||||
use crate::content::custom_actions::CustomActionType::{
|
||||
CivilLiberties, FreeEconomyCollect, VotingIncreaseHappiness,
|
||||
};
|
||||
|
|
@ -64,7 +64,7 @@ fn free_economy() -> AdvanceBuilder {
|
|||
|event| &mut event.is_playing_action_available,
|
||||
0,
|
||||
|available, game, i| {
|
||||
let p = game.get_player(i.player);
|
||||
let p = game.player(i.player);
|
||||
match &i.action_type {
|
||||
PlayingActionType::Collect
|
||||
if p.played_once_per_turn_actions.contains(&FreeEconomyCollect) =>
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ use crate::ability_initializer::AbilityInitializerSetup;
|
|||
use crate::advance::Bonus::{CultureToken, MoodToken};
|
||||
use crate::advance::{Advance, AdvanceBuilder};
|
||||
use crate::city_pieces::Building::Market;
|
||||
use crate::content::advances::trade_routes::{trade_route_log, trade_route_reward, TradeRoute};
|
||||
use crate::content::advances::{advance_group_builder, AdvanceGroup, CURRENCY};
|
||||
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::custom_actions::CustomActionType::Taxes;
|
||||
use crate::content::custom_phase_actions::ResourceRewardRequest;
|
||||
use crate::content::persistent_events::ResourceRewardRequest;
|
||||
use crate::game::Game;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::player::Player;
|
||||
use crate::player_events::{CurrentEvent, PersistentEvents};
|
||||
use crate::player_events::{PersistentEvent, PersistentEvents};
|
||||
use crate::resource::ResourceType;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use itertools::Itertools;
|
||||
|
|
@ -53,7 +53,7 @@ pub fn tax_options(player: &Player) -> PaymentOptions {
|
|||
|
||||
pub(crate) fn collect_taxes(game: &mut Game, player_index: usize, gain: ResourcePile) {
|
||||
assert!(
|
||||
tax_options(game.get_player(player_index)).is_valid_payment(&gain),
|
||||
tax_options(game.player(player_index)).is_valid_payment(&gain),
|
||||
"Invalid gain for Taxes"
|
||||
);
|
||||
game.players[player_index].gain_resources(gain);
|
||||
|
|
@ -71,13 +71,13 @@ fn trade_routes() -> AdvanceBuilder {
|
|||
a different Settler or Ship. In other words, to gain X food you must have at least \
|
||||
X Units (Settlers or Ships), each paired with X different enemy cities.",
|
||||
),
|
||||
|event| &mut event.on_turn_start,
|
||||
|event| &mut event.turn_start,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn add_trade_routes<E, S, V>(b: S, event: E) -> S
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
S: AbilityInitializerSetup,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
|
|
@ -85,7 +85,7 @@ where
|
|||
event,
|
||||
0,
|
||||
|game, player_index, _| {
|
||||
if !game.get_player(player_index).has_advance("Trade Routes") {
|
||||
if !game.player(player_index).has_advance("Trade Routes") {
|
||||
return None;
|
||||
}
|
||||
|
||||
|
|
@ -126,6 +126,6 @@ fn gain_market_bonus(game: &mut Game, routes: &[TradeRoute]) {
|
|||
game.add_info_log_item(&format!(
|
||||
"{name} gains 1 gold for using a Market in a trade route",
|
||||
));
|
||||
game.get_player_mut(p).gain_resources(ResourcePile::gold(1));
|
||||
game.player_mut(p).gain_resources(ResourcePile::gold(1));
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::ability_initializer::{do_once_per_turn, AbilityInitializerSetup};
|
||||
use crate::ability_initializer::{AbilityInitializerSetup, do_once_per_turn};
|
||||
use crate::advance::Bonus::{CultureToken, MoodToken};
|
||||
use crate::advance::{Advance, AdvanceBuilder};
|
||||
use crate::city_pieces::Building;
|
||||
use crate::content::advances::{advance_group_builder, get_group, AdvanceGroup};
|
||||
use crate::content::custom_phase_actions::PaymentRequest;
|
||||
use crate::content::advances::{AdvanceGroup, advance_group_builder, get_group};
|
||||
use crate::content::persistent_events::PaymentRequest;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
|
||||
|
|
@ -24,7 +24,7 @@ fn writing() -> AdvanceBuilder {
|
|||
.with_advance_bonus(CultureToken)
|
||||
.with_unlocked_building(Building::Academy)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_construct,
|
||||
|event| &mut event.construct,
|
||||
3,
|
||||
|game, player_index, _player_name, b| {
|
||||
if matches!(b, Building::Academy) {
|
||||
|
|
@ -42,7 +42,7 @@ fn public_education() -> AdvanceBuilder {
|
|||
)
|
||||
.with_advance_bonus(MoodToken)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_collect,
|
||||
|event| &mut event.collect,
|
||||
0,
|
||||
|game, player_index, _player_name, i| {
|
||||
do_once_per_turn(
|
||||
|
|
@ -52,7 +52,7 @@ fn public_education() -> AdvanceBuilder {
|
|||
&(),
|
||||
|i| &mut i.info.info,
|
||||
move |i, game, ()| {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
if player.get_city(i.city).pieces.academy.is_some() {
|
||||
i.total += ResourcePile::ideas(1);
|
||||
i.info
|
||||
|
|
@ -73,7 +73,7 @@ fn free_education() -> AdvanceBuilder {
|
|||
)
|
||||
.with_advance_bonus(MoodToken)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.on_advance,
|
||||
|e| &mut e.advance,
|
||||
1,
|
||||
|_game, _player_index, i| {
|
||||
if i.name == "Free Education" {
|
||||
|
|
@ -103,7 +103,7 @@ fn free_education() -> AdvanceBuilder {
|
|||
"{} paid {} for free education to gain 1 mood token",
|
||||
s.player_name, pile
|
||||
));
|
||||
game.get_player_mut(s.player_index)
|
||||
game.player_mut(s.player_index)
|
||||
.gain_resources(ResourcePile::mood_tokens(1));
|
||||
},
|
||||
)
|
||||
|
|
@ -118,7 +118,7 @@ fn philosophy() -> AdvanceBuilder {
|
|||
game.players[player_index].gain_resources(ResourcePile::ideas(1));
|
||||
})
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_advance,
|
||||
|event| &mut event.advance,
|
||||
0,
|
||||
|game, player_index, player_name, advance| {
|
||||
if get_group("Science")
|
||||
|
|
@ -126,7 +126,7 @@ fn philosophy() -> AdvanceBuilder {
|
|||
.iter()
|
||||
.any(|a| a.name == advance.name)
|
||||
{
|
||||
let player = game.get_player_mut(player_index);
|
||||
let player = game.player_mut(player_index);
|
||||
player.gain_resources(ResourcePile::ideas(1));
|
||||
game.add_info_log_item(&format!("{player_name} gained 1 idea from Philosophy"));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ use crate::ability_initializer::AbilityInitializerSetup;
|
|||
use crate::advance::Bonus::CultureToken;
|
||||
use crate::advance::{Advance, AdvanceBuilder};
|
||||
use crate::city_pieces::Building::Observatory;
|
||||
use crate::content::advances::{advance_group_builder, AdvanceGroup, METALLURGY};
|
||||
use crate::content::custom_phase_actions::ResourceRewardRequest;
|
||||
use crate::content::advances::{AdvanceGroup, METALLURGY, advance_group_builder};
|
||||
use crate::content::persistent_events::ResourceRewardRequest;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::resource::ResourceType;
|
||||
|
||||
|
|
@ -60,7 +60,7 @@ fn medicine() -> AdvanceBuilder {
|
|||
)
|
||||
.with_advance_bonus(CultureToken)
|
||||
.add_resource_request(
|
||||
|event| &mut event.on_recruit,
|
||||
|event| &mut event.recruit,
|
||||
0,
|
||||
|_game, _player_index, recruit| {
|
||||
let types: Vec<ResourceType> = ResourceType::all()
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::advance::Bonus::{CultureToken, MoodToken};
|
|||
use crate::advance::{Advance, AdvanceBuilder};
|
||||
use crate::city_pieces::Building::Port;
|
||||
use crate::collect::{CollectContext, CollectInfo};
|
||||
use crate::content::advances::{advance_group_builder, AdvanceGroup, NAVIGATION};
|
||||
use crate::content::advances::{AdvanceGroup, NAVIGATION, advance_group_builder};
|
||||
use crate::game::Game;
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
|
|
@ -60,13 +60,13 @@ fn cartography() -> AdvanceBuilder {
|
|||
|game, i, ()| {
|
||||
// info is the action that we last used this ability for
|
||||
let key = game.actions_left.to_string();
|
||||
if game.get_player(i.player).event_info.get("Cartography").is_some_and(|info| info == &key) {
|
||||
if game.player(i.player).event_info.get("Cartography").is_some_and(|info| info == &key) {
|
||||
return;
|
||||
}
|
||||
let mut ship = false;
|
||||
let mut navigation = false;
|
||||
for id in &i.units {
|
||||
let unit = game.get_player(i.player).get_unit(*id);
|
||||
let unit = game.player(i.player).get_unit(*id);
|
||||
if unit.unit_type.is_ship() {
|
||||
ship = true;
|
||||
if !unit.position.is_neighbor(i.to) {
|
||||
|
|
@ -75,12 +75,12 @@ fn cartography() -> AdvanceBuilder {
|
|||
}
|
||||
}
|
||||
if ship {
|
||||
let player = game.get_player_mut(i.player);
|
||||
let player = game.player_mut(i.player);
|
||||
player.event_info.insert("Cartography".to_string(), key);
|
||||
player.gain_resources(ResourcePile::ideas(1));
|
||||
game.add_info_log_item("Cartography gained 1 idea");
|
||||
if navigation {
|
||||
game.get_player_mut(i.player).gain_resources(ResourcePile::culture_tokens(1));
|
||||
game.player_mut(i.player).gain_resources(ResourcePile::culture_tokens(1));
|
||||
game.add_info_log_item(" and 1 culture token (for using navigation)");
|
||||
}
|
||||
}
|
||||
|
|
@ -94,7 +94,7 @@ fn is_enemy_player_or_pirate_zone(game: &Game, player_index: usize, position: Po
|
|||
}
|
||||
|
||||
fn fishing_collect(i: &mut CollectInfo, c: &CollectContext, game: &Game) {
|
||||
let city = game.get_any_city(c.city_position);
|
||||
let city = game.any_city(c.city_position);
|
||||
let port = city.port_position;
|
||||
if let Some(position) = port
|
||||
.filter(|p| !is_enemy_player_or_pirate_zone(game, c.player_index, *p))
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ use crate::ability_initializer::AbilityInitializerSetup;
|
|||
use crate::advance::Bonus::{CultureToken, MoodToken};
|
||||
use crate::advance::{Advance, AdvanceBuilder};
|
||||
use crate::city_pieces::Building::Temple;
|
||||
use crate::content::advances::{advance_group_builder, get_group, AdvanceGroup};
|
||||
use crate::content::custom_phase_actions::ResourceRewardRequest;
|
||||
use crate::content::advances::{AdvanceGroup, advance_group_builder, get_group};
|
||||
use crate::content::persistent_events::ResourceRewardRequest;
|
||||
use crate::payment::{PaymentConversion, PaymentOptions};
|
||||
use crate::resource::ResourceType;
|
||||
use crate::resource::ResourceType::{CultureTokens, MoodTokens};
|
||||
|
|
@ -21,7 +21,7 @@ fn myths() -> AdvanceBuilder {
|
|||
.with_advance_bonus(MoodToken)
|
||||
.with_unlocked_building(Temple)
|
||||
.add_resource_request(
|
||||
|event| &mut event.on_construct,
|
||||
|event| &mut event.construct,
|
||||
1,
|
||||
|_game, _player_index, building| {
|
||||
if matches!(building, Temple) {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::advance::{gain_advance, Advance, AdvanceBuilder};
|
||||
use crate::advance::{Advance, AdvanceBuilder, gain_advance};
|
||||
use crate::city_pieces::Building::Temple;
|
||||
use crate::consts::STACK_LIMIT;
|
||||
use crate::content::advances::{advance_group_builder, get_group, AdvanceGroup};
|
||||
use crate::content::custom_phase_actions::{AdvanceRequest, PositionRequest};
|
||||
use crate::content::advances::{AdvanceGroup, advance_group_builder, get_group};
|
||||
use crate::content::persistent_events::{AdvanceRequest, PositionRequest};
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::unit::UnitType;
|
||||
|
|
@ -36,11 +36,11 @@ fn dogma() -> AdvanceBuilder {
|
|||
game.players[player_index].resource_limit.ideas = 7;
|
||||
})
|
||||
.add_advance_request(
|
||||
|event| &mut event.on_construct,
|
||||
|event| &mut event.construct,
|
||||
0,
|
||||
|game, player_index, building| {
|
||||
if matches!(building, Temple) {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
let choices: Vec<String> = get_group("Theocracy")
|
||||
.advances
|
||||
.iter()
|
||||
|
|
@ -108,7 +108,7 @@ fn conversion() -> AdvanceBuilder {
|
|||
0,
|
||||
|game, outcome, ()| {
|
||||
if outcome.success {
|
||||
game.get_player_mut(outcome.player)
|
||||
game.player_mut(outcome.player)
|
||||
.gain_resources(ResourcePile::culture_tokens(1));
|
||||
game.add_info_log_item(
|
||||
"Player gained 1 culture token for a successful \
|
||||
|
|
@ -135,14 +135,14 @@ fn fanaticism() -> AdvanceBuilder {
|
|||
}
|
||||
})
|
||||
.add_position_request(
|
||||
|event| &mut event.on_combat_end,
|
||||
|event| &mut event.combat_end,
|
||||
4,
|
||||
|game, player_index, i| {
|
||||
if i.is_loser(player_index)
|
||||
&& !game.get_player(player_index).cities.is_empty()
|
||||
&& game.get_player(player_index).available_units().infantry > 0
|
||||
&& !game.player(player_index).cities.is_empty()
|
||||
&& game.player(player_index).available_units().infantry > 0
|
||||
{
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
let choices: Vec<Position> = p
|
||||
.cities
|
||||
.iter()
|
||||
|
|
@ -171,7 +171,7 @@ fn fanaticism() -> AdvanceBuilder {
|
|||
"{} gained 1 free Infantry Unit at {} for Fanaticism Advance",
|
||||
s.player_name, pos
|
||||
));
|
||||
game.get_player_mut(s.player_index)
|
||||
game.player_mut(s.player_index)
|
||||
.add_unit(pos, UnitType::Infantry);
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -8,14 +8,14 @@ use crate::combat::CombatModifier::{
|
|||
use crate::combat::{Combat, CombatModifier};
|
||||
use crate::combat_listeners::CombatStrength;
|
||||
use crate::content::advances::{
|
||||
advance_group_builder, AdvanceGroup, METALLURGY, STEEL_WEAPONS, TACTICS,
|
||||
AdvanceGroup, METALLURGY, STEEL_WEAPONS, TACTICS, advance_group_builder,
|
||||
};
|
||||
use crate::content::custom_phase_actions::PaymentRequest;
|
||||
use crate::content::persistent_events::PaymentRequest;
|
||||
use crate::game::Game;
|
||||
use crate::payment::{PaymentConversion, PaymentOptions};
|
||||
use crate::resource::ResourceType;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::tactics_card::{play_tactics_card, CombatRole};
|
||||
use crate::tactics_card::{CombatRole, play_tactics_card};
|
||||
use crate::unit::UnitType;
|
||||
|
||||
pub(crate) fn warfare() -> AdvanceGroup {
|
||||
|
|
@ -43,7 +43,7 @@ fn siegecraft() -> AdvanceBuilder {
|
|||
"When attacking a city with a Fortress, pay 2 wood to cancel the Fortress’ ability to add +1 die and/or pay 2 ore to ignore its ability to cancel a hit.",
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.on_combat_start,
|
||||
|e| &mut e.combat_start,
|
||||
0,
|
||||
|game, player, c| {
|
||||
let extra_die = PaymentOptions::sum(2, &[ResourceType::Wood, ResourceType::Gold]);
|
||||
|
|
@ -104,7 +104,7 @@ fn steel_weapons() -> AdvanceBuilder {
|
|||
"Immediately before a Land battle starts, you may pay 1 ore to get +2 combat value in every Combat Round against an enemy that does not have the Steel Weapons advance, but only +1 combat value against an enemy that does have it (regardless if they use it or not this battle).",
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.on_combat_start,
|
||||
|e| &mut e.combat_start,
|
||||
1,
|
||||
|game, player_index, c| {
|
||||
let player = &game.players[player_index];
|
||||
|
|
@ -206,8 +206,8 @@ fn fortress(game: &Game, c: &Combat, s: &mut CombatStrength, role: CombatRole) {
|
|||
}
|
||||
|
||||
fn use_steel_weapons(game: &Game, c: &Combat, s: &mut CombatStrength, role: CombatRole) {
|
||||
let steel_weapon_value = if game.get_player(c.attacker).has_advance(STEEL_WEAPONS)
|
||||
&& game.get_player(c.defender).has_advance(STEEL_WEAPONS)
|
||||
let steel_weapon_value = if game.player(c.attacker).has_advance(STEEL_WEAPONS)
|
||||
&& game.player(c.defender).has_advance(STEEL_WEAPONS)
|
||||
{
|
||||
1
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ use crate::ability_initializer::AbilityInitializerSetup;
|
|||
use crate::ability_initializer::{AbilityInitializerBuilder, AbilityListeners};
|
||||
use crate::barbarians::barbarians_bonus;
|
||||
use crate::combat_listeners::{
|
||||
choose_carried_units_casualties, choose_fighter_casualties, combat_stats, offer_retreat,
|
||||
place_settler,
|
||||
choose_fighter_casualties, combat_stats, offer_retreat, place_settler,
|
||||
};
|
||||
use crate::content::action_cards::cultural_takeover::use_cultural_takeover;
|
||||
use crate::content::action_cards::development::collect_only;
|
||||
use crate::content::action_cards::negotiation::use_negotiations;
|
||||
use crate::content::incidents::famine::pestilence_permanent_effect;
|
||||
use crate::content::incidents::great_builders::construct_only;
|
||||
use crate::content::incidents::great_diplomat::use_diplomatic_relations;
|
||||
|
|
@ -20,9 +20,10 @@ use crate::explore::explore_resolution;
|
|||
use crate::game::Game;
|
||||
use crate::pirates::{pirates_bonus, pirates_round_bonus};
|
||||
use crate::status_phase::{
|
||||
complete_objectives, determine_first_player, draw_cards, free_advance, get_status_phase,
|
||||
may_change_government, raze_city, StatusPhaseState,
|
||||
StatusPhaseState, complete_objectives, determine_first_player, draw_cards, free_advance,
|
||||
get_status_phase, may_change_government, raze_city,
|
||||
};
|
||||
use crate::unit::choose_carried_units_casualties;
|
||||
use crate::wonder::{build_wonder, on_draw_wonder_card};
|
||||
|
||||
pub struct Builtin {
|
||||
|
|
@ -96,10 +97,11 @@ pub fn get_all() -> Vec<Builtin> {
|
|||
anarchy_advance(),
|
||||
use_great_warlord(),
|
||||
construct_only(),
|
||||
collect_only(),
|
||||
use_diplomatic_relations(),
|
||||
// action card related
|
||||
collect_only(),
|
||||
use_cultural_takeover(),
|
||||
use_negotiations(),
|
||||
]
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -43,27 +43,29 @@ pub fn get_all() -> Vec<Civilization> {
|
|||
)
|
||||
.build(),
|
||||
],
|
||||
vec![Leader::builder(
|
||||
"Kʼinich Janaab Pakal I",
|
||||
"Shield of the sun",
|
||||
"ignore the first hit in a battle with an Obelisk",
|
||||
"",
|
||||
"",
|
||||
)
|
||||
.add_combat_round_start_listener(4, |game, c, s, _role| {
|
||||
if c.round == 1
|
||||
&& game
|
||||
.try_get_any_city(c.defender_position)
|
||||
.is_some_and(|city| city.pieces.obelisk.is_some())
|
||||
{
|
||||
s.roll_log.push(
|
||||
vec![
|
||||
Leader::builder(
|
||||
"Kʼinich Janaab Pakal I",
|
||||
"Shield of the sun",
|
||||
"ignore the first hit in a battle with an Obelisk",
|
||||
"",
|
||||
"",
|
||||
)
|
||||
.add_combat_round_start_listener(4, |game, c, s, _role| {
|
||||
if c.round == 1
|
||||
&& game
|
||||
.try_get_any_city(c.defender_position)
|
||||
.is_some_and(|city| city.pieces.obelisk.is_some())
|
||||
{
|
||||
s.roll_log.push(
|
||||
"Kʼinich Janaab Pakal I ignores the first hit in a battle with an Obelisk"
|
||||
.to_string(),
|
||||
);
|
||||
s.hit_cancels += 1;
|
||||
}
|
||||
})
|
||||
.build()],
|
||||
s.hit_cancels += 1;
|
||||
}
|
||||
})
|
||||
.build(),
|
||||
],
|
||||
),
|
||||
]
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use serde::{Deserialize, Serialize};
|
|||
use crate::collect::collect;
|
||||
use crate::content::advances::culture::{execute_sports, execute_theaters};
|
||||
use crate::content::advances::economy::collect_taxes;
|
||||
use crate::content::custom_phase_actions::SelectedStructure;
|
||||
use crate::content::persistent_events::SelectedStructure;
|
||||
use crate::cultural_influence::{
|
||||
format_cultural_influence_attempt_log_item, influence_culture_attempt,
|
||||
};
|
||||
|
|
@ -11,7 +11,7 @@ use crate::log::{
|
|||
format_city_happiness_increase, format_collect_log_item, format_happiness_increase,
|
||||
};
|
||||
use crate::player::Player;
|
||||
use crate::playing_actions::{increase_happiness, Collect, IncreaseHappiness, PlayingActionType};
|
||||
use crate::playing_actions::{Collect, IncreaseHappiness, PlayingActionType, increase_happiness};
|
||||
use crate::{
|
||||
game::Game, playing_actions::ActionType, position::Position, resource_pile::ResourcePile,
|
||||
};
|
||||
|
|
@ -69,12 +69,7 @@ pub enum CustomActionType {
|
|||
}
|
||||
|
||||
impl CustomAction {
|
||||
///
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if action is illegal
|
||||
pub fn execute(self, game: &mut Game, player_index: usize) {
|
||||
pub(crate) fn execute(self, game: &mut Game, player_index: usize) -> Result<(), String> {
|
||||
match self {
|
||||
CustomAction::AbsolutePower => game.actions_left += 1,
|
||||
CustomAction::ForcedLabor => {
|
||||
|
|
@ -89,7 +84,7 @@ impl CustomAction {
|
|||
CustomAction::VotingIncreaseHappiness(i) => {
|
||||
increase_happiness(game, player_index, &i.happiness_increases, Some(i.payment));
|
||||
}
|
||||
CustomAction::FreeEconomyCollect(c) => collect(game, player_index, &c),
|
||||
CustomAction::FreeEconomyCollect(c) => collect(game, player_index, &c)?,
|
||||
CustomAction::Sports {
|
||||
city_position,
|
||||
payment,
|
||||
|
|
@ -99,6 +94,7 @@ impl CustomAction {
|
|||
CustomAction::Taxes(r) => collect_taxes(game, player_index, r),
|
||||
CustomAction::Theaters(r) => execute_theaters(game, player_index, &r),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::content::incidents::great_diplomat::{DiplomaticRelations, DIPLOMAT_ID};
|
||||
use crate::content::incidents::great_diplomat::{DIPLOMAT_ID, DiplomaticRelations, Negotiations};
|
||||
use crate::events::EventOrigin;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
|
|
@ -31,6 +31,7 @@ pub enum PermanentEffect {
|
|||
Collect(CollectEffect),
|
||||
CulturalTakeover,
|
||||
DiplomaticRelations(DiplomaticRelations),
|
||||
Negotiations(Negotiations),
|
||||
}
|
||||
|
||||
impl PermanentEffect {
|
||||
|
|
@ -51,6 +52,7 @@ impl PermanentEffect {
|
|||
PermanentEffect::TrojanHorse => EventOrigin::Incident(42),
|
||||
PermanentEffect::Anarchy(_) => EventOrigin::Incident(44),
|
||||
PermanentEffect::DiplomaticRelations(_) => EventOrigin::Incident(DIPLOMAT_ID),
|
||||
PermanentEffect::Negotiations(_) => EventOrigin::CivilCard(23), // also 24
|
||||
// can also be 16, but that doesn't matter for the help text
|
||||
PermanentEffect::CulturalTakeover => EventOrigin::CivilCard(15),
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ pub(crate) mod famine;
|
|||
mod good_year;
|
||||
pub(crate) mod great_builders;
|
||||
pub(crate) mod great_diplomat;
|
||||
mod great_explorer;
|
||||
pub(crate) mod great_explorer;
|
||||
pub(crate) mod great_persons;
|
||||
pub(crate) mod great_warlord;
|
||||
mod pandemics;
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use crate::city::MoodState;
|
||||
use crate::content::custom_phase_actions::{PaymentRequest, PositionRequest, UnitsRequest};
|
||||
use crate::content::effects::PermanentEffect;
|
||||
use crate::content::incidents::famine::kill_incident_units;
|
||||
use crate::content::incidents::good_year::select_player_to_gain_settler;
|
||||
use crate::content::persistent_events::{PaymentRequest, PositionRequest, UnitsRequest};
|
||||
use crate::game::Game;
|
||||
use crate::incident::{
|
||||
decrease_mod_and_log, Incident, IncidentBaseEffect, IncidentBuilder, MoodModifier,
|
||||
Incident, IncidentBaseEffect, IncidentBuilder, MoodModifier, decrease_mod_and_log,
|
||||
};
|
||||
use crate::payment::{PaymentConversion, PaymentConversionType, PaymentOptions};
|
||||
use crate::player::Player;
|
||||
|
|
@ -15,7 +15,7 @@ use crate::resource_pile::ResourcePile;
|
|||
use crate::status_phase::{
|
||||
add_change_government, can_change_government_for_free, get_status_phase,
|
||||
};
|
||||
use crate::unit::UnitType;
|
||||
use crate::unit::{UnitType, kill_units};
|
||||
use crate::wonder::draw_wonder_from_pile;
|
||||
use itertools::Itertools;
|
||||
|
||||
|
|
@ -80,7 +80,7 @@ fn civil_war(id: u8) -> Incident {
|
|||
IncidentTarget::ActivePlayer,
|
||||
0,
|
||||
|game, player_index, i| {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
let suffix = if !non_angry_cites(p).is_empty() && i.player.payment.is_empty() {
|
||||
" and decrease the mood"
|
||||
} else {
|
||||
|
|
@ -94,12 +94,12 @@ fn civil_war(id: u8) -> Incident {
|
|||
},
|
||||
|game, s, i| {
|
||||
let position = s.choice[0];
|
||||
let mood = game.get_any_city(position).mood_state.clone();
|
||||
let mood = game.any_city(position).mood_state.clone();
|
||||
if i.player.payment.is_empty() && !matches!(mood, MoodState::Angry) {
|
||||
decrease_mod_and_log(game, s, MoodModifier::Decrease);
|
||||
}
|
||||
let unit = game
|
||||
.get_player(s.player_index)
|
||||
.player(s.player_index)
|
||||
.get_units(position)
|
||||
.iter()
|
||||
.filter(|u| matches!(u.unit_type, UnitType::Infantry))
|
||||
|
|
@ -111,7 +111,7 @@ fn civil_war(id: u8) -> Incident {
|
|||
"{} killed an Infantry in {}",
|
||||
s.player_name, position
|
||||
));
|
||||
game.kill_unit(unit, s.player_index, None);
|
||||
kill_units(game, &[unit], s.player_index, None);
|
||||
},
|
||||
)
|
||||
.build()
|
||||
|
|
@ -156,12 +156,7 @@ fn revolution() -> Incident {
|
|||
"Kill a unit to avoid changing government",
|
||||
|_game, player| can_change_government_for_free(player),
|
||||
);
|
||||
b = add_change_government(
|
||||
b,
|
||||
|event| &mut event.on_incident,
|
||||
false,
|
||||
ResourcePile::empty(),
|
||||
);
|
||||
b = add_change_government(b, |event| &mut event.incident, false, ResourcePile::empty());
|
||||
b.build()
|
||||
}
|
||||
|
||||
|
|
@ -178,7 +173,7 @@ fn kill_unit_for_revolution(
|
|||
move |game, player_index, i| {
|
||||
i.player.sacrifice = 0;
|
||||
let units = game
|
||||
.get_player(player_index)
|
||||
.player(player_index)
|
||||
.units
|
||||
.iter()
|
||||
.filter(|u| u.unit_type.is_army_unit())
|
||||
|
|
@ -186,7 +181,7 @@ fn kill_unit_for_revolution(
|
|||
.collect_vec();
|
||||
Some(UnitsRequest::new(
|
||||
player_index,
|
||||
if pred(game, game.get_player(player_index)) {
|
||||
if pred(game, game.player(player_index)) {
|
||||
units
|
||||
} else {
|
||||
vec![]
|
||||
|
|
@ -233,7 +228,7 @@ fn uprising() -> Incident {
|
|||
IncidentTarget::ActivePlayer,
|
||||
0,
|
||||
|game, player_index, _incident| {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
let mut cost = PaymentOptions::tokens(4);
|
||||
cost.conversions.push(PaymentConversion::new(
|
||||
vec![
|
||||
|
|
@ -250,7 +245,7 @@ fn uprising() -> Incident {
|
|||
)])
|
||||
},
|
||||
|game, s, _| {
|
||||
let player = game.get_player_mut(s.player_index);
|
||||
let player = game.player_mut(s.player_index);
|
||||
let pile = &s.choice[0];
|
||||
let v = pile.amount() as f32 / 2_f32;
|
||||
player.event_victory_points += v;
|
||||
|
|
@ -281,7 +276,7 @@ fn envoy() -> Incident {
|
|||
1,
|
||||
|game, player, player_name, _| {
|
||||
game.add_info_log_item(&format!("{player_name} gained 1 idea and 1 culture token"));
|
||||
game.get_player_mut(player)
|
||||
game.player_mut(player)
|
||||
.gain_resources(ResourcePile::culture_tokens(1) + ResourcePile::ideas(1));
|
||||
|
||||
if let Some(wonder) = draw_wonder_from_pile(game) {
|
||||
|
|
@ -305,7 +300,7 @@ fn envoy() -> Incident {
|
|||
"{} was selected to gain 1 culture token.",
|
||||
game.player_name(p)
|
||||
));
|
||||
game.get_player_mut(p)
|
||||
game.player_mut(p)
|
||||
.gain_resources(ResourcePile::culture_tokens(1));
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,8 +2,8 @@ use crate::ability_initializer::SelectedChoice;
|
|||
use crate::city::{City, MoodState};
|
||||
use crate::city_pieces::Building;
|
||||
use crate::consts::WONDER_VICTORY_POINTS;
|
||||
use crate::content::custom_phase_actions::{
|
||||
is_selected_structures_valid, PositionRequest, SelectedStructure, Structure, StructuresRequest,
|
||||
use crate::content::persistent_events::{
|
||||
PositionRequest, SelectedStructure, Structure, StructuresRequest, is_selected_structures_valid,
|
||||
};
|
||||
use crate::content::wonders::get_wonder;
|
||||
use crate::game::Game;
|
||||
|
|
@ -39,7 +39,7 @@ fn volcano() -> Incident {
|
|||
IncidentTarget::ActivePlayer,
|
||||
0,
|
||||
|game, player_index, _incident| {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
let cities = p.cities.iter().map(|c| c.position).collect_vec();
|
||||
let needed = 1..=1;
|
||||
(cities.len() >= 4).then_some(PositionRequest::new(
|
||||
|
|
@ -55,7 +55,7 @@ fn volcano() -> Incident {
|
|||
"{} selected city {} to be destroyed",
|
||||
s.player_name, pos
|
||||
));
|
||||
let city = game.get_player(player_index).get_city(pos);
|
||||
let city = game.player(player_index).get_city(pos);
|
||||
let buildings = city.pieces.buildings(None);
|
||||
let wonders = city
|
||||
.pieces
|
||||
|
|
@ -92,7 +92,7 @@ fn earthquake(id: u8, name: &str, target: IncidentTarget) -> Incident {
|
|||
target,
|
||||
11,
|
||||
|game, player_index, _incident| {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
let cities = &p.cities;
|
||||
(cities.len() >= 3).then_some(structures_request(cities))
|
||||
},
|
||||
|
|
@ -175,9 +175,9 @@ fn destroyable_structures(city: &City) -> Vec<SelectedStructure> {
|
|||
}
|
||||
|
||||
fn destroy_city_center(game: &mut Game, position: Position) {
|
||||
let city = game.get_any_city(position);
|
||||
let city = game.any_city(position);
|
||||
let owner = city.player_index;
|
||||
let p = game.get_player_mut(owner);
|
||||
let p = game.player_mut(owner);
|
||||
p.cities.remove(
|
||||
p.cities
|
||||
.iter()
|
||||
|
|
@ -194,16 +194,16 @@ fn destroy_city_center(game: &mut Game, position: Position) {
|
|||
}
|
||||
|
||||
fn destroy_building(game: &mut Game, b: Building, position: Position) {
|
||||
let city = game.get_any_city(position);
|
||||
let city = game.any_city(position);
|
||||
let city_owner = city.player_index;
|
||||
let owner = city
|
||||
.pieces
|
||||
.building_owner(b)
|
||||
.expect("building should exist");
|
||||
let o = game.get_player_mut(owner);
|
||||
let o = game.player_mut(owner);
|
||||
o.event_victory_points += 2.0;
|
||||
o.destroyed_structures.add_building(b);
|
||||
game.get_player_mut(city_owner)
|
||||
game.player_mut(city_owner)
|
||||
.get_city_mut(position)
|
||||
.pieces
|
||||
.remove_building(b);
|
||||
|
|
@ -216,12 +216,12 @@ fn destroy_building(game: &mut Game, b: Building, position: Position) {
|
|||
}
|
||||
|
||||
fn destroy_wonder(game: &mut Game, position: Position, name: &str) {
|
||||
let owner = game.get_any_city(position).player_index;
|
||||
let owner = game.any_city(position).player_index;
|
||||
let wonder = get_wonder(name);
|
||||
wonder.listeners.deinit(game, owner);
|
||||
|
||||
let a = WONDER_VICTORY_POINTS / 2.0;
|
||||
let p = game.get_player_mut(owner);
|
||||
let p = game.player_mut(owner);
|
||||
p.get_city_mut(position)
|
||||
.pieces
|
||||
.wonders
|
||||
|
|
@ -251,7 +251,7 @@ fn flood(id: u8, name: &str, target: IncidentTarget) -> Incident {
|
|||
}
|
||||
|
||||
fn non_angry_shore_cites(game: &Game, player_index: usize) -> Vec<Position> {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
p.cities
|
||||
.iter()
|
||||
.filter(|c| {
|
||||
|
|
|
|||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::ability_initializer::{AbilityInitializerSetup, SelectedChoice};
|
||||
use crate::city::{City, MoodState};
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_phase_actions::UnitsRequest;
|
||||
use crate::content::effects::PermanentEffect;
|
||||
use crate::content::incidents::civil_war::non_angry_cites;
|
||||
use crate::content::persistent_events::UnitsRequest;
|
||||
use crate::game::Game;
|
||||
use crate::incident::{Incident, IncidentBaseEffect, MoodModifier};
|
||||
use crate::player::Player;
|
||||
|
|
@ -11,6 +11,7 @@ use crate::player_events::IncidentTarget;
|
|||
use crate::playing_actions::PlayingActionType;
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::unit::kill_units;
|
||||
use itertools::Itertools;
|
||||
use std::vec;
|
||||
|
||||
|
|
@ -72,7 +73,7 @@ pub(crate) fn pestilence_permanent_effect() -> Builtin {
|
|||
|event| &mut event.is_playing_action_available,
|
||||
1,
|
||||
|available, game, i| {
|
||||
let player = game.get_player(i.player);
|
||||
let player = game.player(i.player);
|
||||
if game
|
||||
.permanent_effects
|
||||
.contains(&PermanentEffect::Pestilence)
|
||||
|
|
@ -102,7 +103,7 @@ fn epidemics() -> Incident {
|
|||
IncidentTarget::AllPlayers,
|
||||
0,
|
||||
|game, player_index, _incident| {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
let units = p.units.iter().map(|u| u.id).collect_vec();
|
||||
let needed = if additional_sanitation_damage(p) {
|
||||
2
|
||||
|
|
@ -133,7 +134,7 @@ pub(crate) fn kill_incident_units(game: &mut Game, s: &SelectedChoice<Vec<u32>>)
|
|||
return;
|
||||
}
|
||||
|
||||
let p = game.get_player(s.player_index);
|
||||
let p = game.player(s.player_index);
|
||||
game.add_info_log_item(&format!(
|
||||
"{} killed units: {}",
|
||||
p.get_name(),
|
||||
|
|
@ -145,9 +146,7 @@ pub(crate) fn kill_incident_units(game: &mut Game, s: &SelectedChoice<Vec<u32>>)
|
|||
})
|
||||
.join(", ")
|
||||
));
|
||||
for u in &s.choice {
|
||||
game.kill_unit(*u, s.player_index, None);
|
||||
}
|
||||
kill_units(game, &s.choice, s.player_index, None);
|
||||
}
|
||||
|
||||
fn famines() -> Vec<Incident> {
|
||||
|
|
@ -199,7 +198,7 @@ pub(crate) fn famine(
|
|||
.with_protection_advance("Irrigation")
|
||||
.add_simple_incident_listener(target, 11, move |game, player_index, player_name, i| {
|
||||
// we lose the food regardless of the outcome
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
if !player_pred.clone()(p) {
|
||||
return;
|
||||
}
|
||||
|
|
@ -212,7 +211,7 @@ pub(crate) fn famine(
|
|||
i.player.payment = ResourcePile::food(lost);
|
||||
}
|
||||
|
||||
game.get_player_mut(player_index)
|
||||
game.player_mut(player_index)
|
||||
.lose_resources(ResourcePile::food(lost));
|
||||
|
||||
game.add_info_log_item(&format!("{player_name} lost {lost} food to Famine",));
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::content::custom_phase_actions::{PositionRequest, ResourceRewardRequest};
|
||||
use crate::content::persistent_events::{PositionRequest, ResourceRewardRequest};
|
||||
use crate::incident::{Incident, IncidentBaseEffect, IncidentBuilder};
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::player_events::IncidentTarget;
|
||||
|
|
@ -159,7 +159,7 @@ fn good_year(mut builder: IncidentBuilder, amount: u32, good_year_type: &GoodYea
|
|||
game.player_name(c.choice),
|
||||
n.clone(),
|
||||
));
|
||||
game.get_player_mut(c.choice)
|
||||
game.player_mut(c.choice)
|
||||
.gain_resources(ResourcePile::food(1));
|
||||
},
|
||||
);
|
||||
|
|
@ -210,7 +210,7 @@ fn select_settler(b: IncidentBuilder, priority: i32, target: IncidentTarget) ->
|
|||
target,
|
||||
priority,
|
||||
move |game, player_index, _| {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
if p.available_units().settlers > 0 {
|
||||
let choices = p.cities.iter().map(|c| c.position).collect();
|
||||
let needed = 1..=1;
|
||||
|
|
@ -226,7 +226,7 @@ fn select_settler(b: IncidentBuilder, priority: i32, target: IncidentTarget) ->
|
|||
|game, s, _| {
|
||||
let pos = s.choice[0];
|
||||
game.add_info_log_item(&format!("{} gained 1 settler in {}", s.player_name, pos));
|
||||
game.get_player_mut(s.player_index)
|
||||
game.player_mut(s.player_index)
|
||||
.add_unit(pos, UnitType::Settler);
|
||||
},
|
||||
)
|
||||
|
|
|
|||
|
|
@ -2,18 +2,18 @@ use crate::ability_initializer::AbilityInitializerSetup;
|
|||
use crate::action_card::ActionCard;
|
||||
use crate::card::HandCard;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_phase_actions::HandCardsRequest;
|
||||
use crate::content::effects::ConstructEffect;
|
||||
use crate::content::effects::PermanentEffect::Construct;
|
||||
use crate::content::incidents::great_persons::{
|
||||
great_person_action_card, great_person_description, GREAT_PERSON_DESCRIPTION,
|
||||
GREAT_PERSON_DESCRIPTION, great_person_action_card, great_person_description,
|
||||
};
|
||||
use crate::content::persistent_events::HandCardsRequest;
|
||||
use crate::game::Game;
|
||||
use crate::player::Player;
|
||||
use crate::playing_actions::{ActionType, PlayingActionType};
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::utils::remove_element_by;
|
||||
use crate::wonder::{cities_for_wonder, on_play_wonder_card, WonderCardInfo, WonderDiscount};
|
||||
use crate::wonder::{WonderCardInfo, WonderDiscount, cities_for_wonder, on_play_wonder_card};
|
||||
|
||||
pub(crate) fn great_engineer() -> ActionCard {
|
||||
let groups = &["Construction"];
|
||||
|
|
@ -29,7 +29,7 @@ pub(crate) fn great_engineer() -> ActionCard {
|
|||
|_game, _player| true,
|
||||
)
|
||||
.add_bool_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|_, _, _| Some("Build a building in a city without spending an action and without activating it?".to_string()),
|
||||
|game, s, _| {
|
||||
|
|
@ -81,7 +81,7 @@ pub(crate) fn construct_only() -> Builtin {
|
|||
},
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_construct,
|
||||
|event| &mut event.construct,
|
||||
2,
|
||||
|game, _, _, _| {
|
||||
remove_element_by(&mut game.permanent_effects, |e| matches!(e, &Construct(_)));
|
||||
|
|
@ -106,11 +106,11 @@ pub(crate) fn great_architect() -> ActionCard {
|
|||
|game, player| !playable_wonders(game, player).is_empty(),
|
||||
)
|
||||
.add_hand_card_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player, _| {
|
||||
Some(HandCardsRequest::new(
|
||||
playable_wonders(game, game.get_player(player))
|
||||
playable_wonders(game, game.player(player))
|
||||
.iter()
|
||||
.map(|name| HandCard::Wonder(name.clone()))
|
||||
.collect(),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use crate::action_card::ActionCard;
|
|||
use crate::content::builtin::Builtin;
|
||||
use crate::content::effects::PermanentEffect;
|
||||
use crate::content::incidents::great_persons::{
|
||||
great_person_action_card, GREAT_PERSON_DESCRIPTION,
|
||||
GREAT_PERSON_DESCRIPTION, great_person_action_card,
|
||||
};
|
||||
use crate::game::Game;
|
||||
use crate::incident::IncidentBuilder;
|
||||
|
|
@ -29,7 +29,7 @@ pub(crate) fn great_diplomat() -> ActionCard {
|
|||
|_game, _player| true,
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, _player_index, player_name, _| {
|
||||
game.add_info_log_item(&format!("{player_name} ended diplomatic relations.",));
|
||||
|
|
@ -48,6 +48,13 @@ pub struct DiplomaticRelations {
|
|||
}
|
||||
|
||||
impl DiplomaticRelations {
|
||||
pub fn new(active_player: usize, passive_player: usize) -> Self {
|
||||
Self {
|
||||
active_player,
|
||||
passive_player,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn partner(&self, player: usize) -> Option<usize> {
|
||||
if player == self.passive_player {
|
||||
Some(self.active_player)
|
||||
|
|
@ -59,6 +66,13 @@ impl DiplomaticRelations {
|
|||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Debug)]
|
||||
pub struct Negotiations {
|
||||
#[serde(flatten)]
|
||||
pub relations: DiplomaticRelations,
|
||||
pub remaining_turns: usize,
|
||||
}
|
||||
|
||||
pub(crate) fn choose_diplomat_partner(b: IncidentBuilder) -> IncidentBuilder {
|
||||
b.add_incident_player_request(
|
||||
IncidentTarget::AllPlayers,
|
||||
|
|
@ -72,10 +86,9 @@ pub(crate) fn choose_diplomat_partner(b: IncidentBuilder) -> IncidentBuilder {
|
|||
game.player_name(s.choice),
|
||||
));
|
||||
game.permanent_effects
|
||||
.push(PermanentEffect::DiplomaticRelations(DiplomaticRelations {
|
||||
active_player: s.player_index,
|
||||
passive_player: s.choice,
|
||||
}));
|
||||
.push(PermanentEffect::DiplomaticRelations(
|
||||
DiplomaticRelations::new(s.player_index, s.choice),
|
||||
));
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
@ -83,11 +96,10 @@ pub(crate) fn choose_diplomat_partner(b: IncidentBuilder) -> IncidentBuilder {
|
|||
pub(crate) fn use_diplomatic_relations() -> Builtin {
|
||||
Builtin::builder("Diplomatic Relations", "")
|
||||
.add_simple_persistent_event_listener(
|
||||
|e| &mut e.on_combat_start,
|
||||
|e| &mut e.combat_start,
|
||||
2,
|
||||
|game, player_index, player_name, _| {
|
||||
let partner = diplomatic_relations_partner(game, player_index);
|
||||
if let Some(partner) = partner {
|
||||
if let Some(partner) = diplomatic_relations_partner(game, player_index) {
|
||||
game.add_info_log_item(&format!(
|
||||
"{} paid 2 culture tokens to end diplomatic relations with {} using a surprise attack.",
|
||||
player_name,
|
||||
|
|
|
|||
|
|
@ -1,23 +1,23 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action::Action;
|
||||
use crate::action_card::ActionCard;
|
||||
use crate::content::custom_phase_actions::{EventResponse, PaymentRequest, PositionRequest};
|
||||
use crate::action_card::{ActionCard, ActionCardBuilder};
|
||||
use crate::content::incidents::great_persons::{
|
||||
great_person_action_card, great_person_description,
|
||||
};
|
||||
use crate::content::persistent_events::{EventResponse, PaymentRequest, PositionRequest};
|
||||
use crate::explore::move_to_unexplored_block;
|
||||
use crate::game::Game;
|
||||
use crate::log::current_player_turn_log;
|
||||
use crate::map::{get_map_setup, BlockPosition, UNEXPLORED_BLOCK};
|
||||
use crate::map::{BlockPosition, UNEXPLORED_BLOCK, get_map_setup};
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::playing_actions::{build_city, ActionType};
|
||||
use crate::playing_actions::{ActionType, build_city};
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use itertools::Itertools;
|
||||
|
||||
pub(crate) fn great_explorer() -> ActionCard {
|
||||
let groups = &["Seafaring"];
|
||||
great_person_action_card(
|
||||
let mut builder = great_person_action_card(
|
||||
18,
|
||||
"Great Explorer",
|
||||
&format!(
|
||||
|
|
@ -28,12 +28,63 @@ pub(crate) fn great_explorer() -> ActionCard {
|
|||
),
|
||||
ActionType::regular(),
|
||||
groups,
|
||||
|_game, _player| true,
|
||||
)
|
||||
.add_position_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|game, player| {
|
||||
!action_explore_request(game, player.index)
|
||||
.request
|
||||
.choices
|
||||
.is_empty()
|
||||
},
|
||||
);
|
||||
builder = explore_adjacent_block(builder);
|
||||
builder
|
||||
.add_position_request(
|
||||
|e| &mut e.play_action_card,
|
||||
8,
|
||||
|game, player_index, _| Some(place_city_request(game, player_index)),
|
||||
|game, s, a| {
|
||||
let pos = s.choice.first().copied();
|
||||
if let Some(pos) = pos {
|
||||
game.add_info_log_item(&format!(
|
||||
"{} decided to build a city at {pos}",
|
||||
s.player_name
|
||||
));
|
||||
} else {
|
||||
game.add_info_log_item(&format!(
|
||||
"{} decided not to build a city",
|
||||
s.player_name
|
||||
));
|
||||
}
|
||||
a.selected_position = pos;
|
||||
},
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.play_action_card,
|
||||
7,
|
||||
|_game, _player, a| {
|
||||
a.selected_position?;
|
||||
Some(vec![PaymentRequest::new(
|
||||
city_cost(),
|
||||
"Pay to build the city",
|
||||
false,
|
||||
)])
|
||||
},
|
||||
|game, s, a| {
|
||||
let pos = a.selected_position.expect("position not found");
|
||||
build_city(game.player_mut(s.player_index), pos);
|
||||
game.add_info_log_item(&format!(
|
||||
"{} built a city at {pos} for {}",
|
||||
s.player_name, s.choice[0]
|
||||
));
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn explore_adjacent_block(builder: ActionCardBuilder) -> ActionCardBuilder {
|
||||
let builder1 = builder.add_position_request(
|
||||
|e| &mut e.play_action_card,
|
||||
9,
|
||||
|game, player_index, _| Some(explore_choices(game, player_index)),
|
||||
|game, player_index, _| Some(action_explore_request(game, player_index)),
|
||||
|game, s, _| {
|
||||
let position = s.choice[0];
|
||||
game.add_info_log_item(&format!("{} explored {}", s.player_name, position));
|
||||
|
|
@ -46,86 +97,46 @@ pub(crate) fn great_explorer() -> ActionCard {
|
|||
.expect("Block not found");
|
||||
move_to_unexplored_block(game, s.player_index, &dest, &[], position, None);
|
||||
},
|
||||
)
|
||||
.add_position_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
8,
|
||||
|game, player_index, _| {
|
||||
if !game.get_player(player_index).can_afford(&city_cost()) {
|
||||
game.add_info_log_item("Player cannot afford to build a city");
|
||||
}
|
||||
);
|
||||
builder1
|
||||
}
|
||||
|
||||
let a = current_player_turn_log(game)
|
||||
.items
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|l| {
|
||||
if let Action::Response(EventResponse::SelectPositions(p)) = &l.action {
|
||||
Some(p[0])
|
||||
} else {
|
||||
None
|
||||
}
|
||||
})
|
||||
.expect("position not found");
|
||||
fn place_city_request(game: &mut Game, player_index: usize) -> PositionRequest {
|
||||
if !game.player(player_index).can_afford(&city_cost()) {
|
||||
game.add_info_log_item("Player cannot afford to build a city");
|
||||
}
|
||||
|
||||
let setup = get_map_setup(game.human_players_count());
|
||||
let choices = setup
|
||||
.free_positions
|
||||
.into_iter()
|
||||
.find_map(|p| {
|
||||
let t = tiles(&p);
|
||||
t.contains(&a).then_some(t)
|
||||
})
|
||||
.expect("position not found");
|
||||
|
||||
let needed = 0..=1;
|
||||
Some(PositionRequest::new(
|
||||
choices,
|
||||
needed,
|
||||
"Place a city for 2 food",
|
||||
))
|
||||
},
|
||||
|game, s, a| {
|
||||
let pos = s.choice.first().copied();
|
||||
if let Some(pos) = pos {
|
||||
game.add_info_log_item(&format!(
|
||||
"{} decided to build a city at {pos}",
|
||||
s.player_name
|
||||
));
|
||||
let a = current_player_turn_log(game)
|
||||
.items
|
||||
.iter()
|
||||
.rev()
|
||||
.find_map(|l| {
|
||||
if let Action::Response(EventResponse::SelectPositions(p)) = &l.action {
|
||||
Some(p[0])
|
||||
} else {
|
||||
game.add_info_log_item(&format!("{} decided not to build a city", s.player_name));
|
||||
None
|
||||
}
|
||||
a.selected_position = pos;
|
||||
},
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
7,
|
||||
|_game, _player, a| {
|
||||
a.selected_position?;
|
||||
Some(vec![PaymentRequest::new(
|
||||
city_cost(),
|
||||
"Pay to build the city",
|
||||
false,
|
||||
)])
|
||||
},
|
||||
|game, s, a| {
|
||||
let pos = a.selected_position.expect("position not found");
|
||||
build_city(game.get_player_mut(s.player_index), pos);
|
||||
game.add_info_log_item(&format!(
|
||||
"{} built a city at {pos} for {}",
|
||||
s.player_name, s.choice[0]
|
||||
));
|
||||
},
|
||||
)
|
||||
.build()
|
||||
})
|
||||
.expect("position not found");
|
||||
|
||||
let setup = get_map_setup(game.human_players_count());
|
||||
let choices = setup
|
||||
.free_positions
|
||||
.into_iter()
|
||||
.find_map(|p| {
|
||||
let t = tiles(&p);
|
||||
t.contains(&a).then_some(t)
|
||||
})
|
||||
.expect("position not found");
|
||||
|
||||
PositionRequest::new(choices, 0..=1, "Place a city for 2 food")
|
||||
}
|
||||
|
||||
fn city_cost() -> PaymentOptions {
|
||||
PaymentOptions::resources(ResourcePile::food(2))
|
||||
}
|
||||
|
||||
fn explore_choices(game: &mut Game, player_index: usize) -> PositionRequest {
|
||||
pub(crate) fn action_explore_request(game: &Game, player_index: usize) -> PositionRequest {
|
||||
let setup = get_map_setup(game.human_players_count());
|
||||
let free = &setup
|
||||
.free_positions
|
||||
|
|
@ -144,11 +155,7 @@ fn explore_choices(game: &mut Game, player_index: usize) -> PositionRequest {
|
|||
.then_some(b.top_tile)
|
||||
})
|
||||
.collect_vec();
|
||||
if choices.is_empty() {
|
||||
game.add_info_log_item("No valid positions to explore");
|
||||
}
|
||||
let needed = 0..=1;
|
||||
PositionRequest::new(choices, needed, "Choose a region to explore")
|
||||
PositionRequest::new(choices, 0..=1, "Choose a region to explore")
|
||||
}
|
||||
|
||||
fn block_adjacent(p1: &BlockPosition, p2: &BlockPosition) -> bool {
|
||||
|
|
@ -165,8 +172,8 @@ fn tiles(p1: &BlockPosition) -> Vec<Position> {
|
|||
.collect_vec()
|
||||
}
|
||||
|
||||
fn has_any_city(game: &mut Game, p: &BlockPosition, player: usize) -> bool {
|
||||
fn has_any_city(game: &Game, p: &BlockPosition, player: usize) -> bool {
|
||||
tiles(p)
|
||||
.iter()
|
||||
.any(|p| game.get_player(player).try_get_city(*p).is_some())
|
||||
.any(|p| game.player(player).try_get_city(*p).is_some())
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,16 +1,16 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action_card::{gain_action_card_from_pile, ActionCard, ActionCardBuilder};
|
||||
use crate::action_card::{ActionCard, ActionCardBuilder, gain_action_card_from_pile};
|
||||
use crate::advance::gain_advance;
|
||||
use crate::city::MoodState;
|
||||
use crate::city_pieces::Building;
|
||||
use crate::construct::{construct, Construct};
|
||||
use crate::construct::{Construct, construct};
|
||||
use crate::content::advances;
|
||||
use crate::content::advances::{economy, get_governments};
|
||||
use crate::content::custom_phase_actions::{AdvanceRequest, PaymentRequest, PositionRequest};
|
||||
use crate::content::incidents::great_builders::{great_architect, great_engineer};
|
||||
use crate::content::incidents::great_diplomat::{choose_diplomat_partner, great_diplomat};
|
||||
use crate::content::incidents::great_explorer::great_explorer;
|
||||
use crate::content::incidents::great_warlord::great_warlord;
|
||||
use crate::content::persistent_events::{AdvanceRequest, PaymentRequest, PositionRequest};
|
||||
use crate::game::Game;
|
||||
use crate::incident::{Incident, IncidentBaseEffect, IncidentBuilder};
|
||||
use crate::payment::PaymentOptions;
|
||||
|
|
@ -84,7 +84,7 @@ fn incident(
|
|||
2
|
||||
};
|
||||
let options = PaymentOptions::resources(ResourcePile::culture_tokens(cost));
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
if p.can_afford(&options) {
|
||||
Some(vec![PaymentRequest::new(
|
||||
options,
|
||||
|
|
@ -109,9 +109,7 @@ fn incident(
|
|||
return;
|
||||
}
|
||||
game.add_info_log_item(&format!("{} gained {name2} for {pile}", s.player_name));
|
||||
game.get_player_mut(s.player_index)
|
||||
.action_cards
|
||||
.push(card_id);
|
||||
game.player_mut(s.player_index).action_cards.push(card_id);
|
||||
i.selected_player = Some(s.player_index);
|
||||
},
|
||||
)
|
||||
|
|
@ -152,10 +150,10 @@ where
|
|||
can_play,
|
||||
)
|
||||
.add_advance_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
10,
|
||||
move |game, player_index, _| {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
let choices = groups
|
||||
.iter()
|
||||
.flat_map(|g| advances::get_group(g.as_ref()).advances)
|
||||
|
|
@ -186,10 +184,10 @@ fn great_artist() -> ActionCard {
|
|||
|_game, _player| true,
|
||||
)
|
||||
.add_position_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player_index, _| {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
let cities = player
|
||||
.cities
|
||||
.iter()
|
||||
|
|
@ -208,7 +206,7 @@ fn great_artist() -> ActionCard {
|
|||
"{} made city at {} Happy",
|
||||
s.player_name, position
|
||||
));
|
||||
game.get_player_mut(s.player_index)
|
||||
game.player_mut(s.player_index)
|
||||
.get_city_mut(position)
|
||||
.mood_state = MoodState::Happy;
|
||||
},
|
||||
|
|
@ -230,10 +228,10 @@ fn great_prophet() -> ActionCard {
|
|||
|_game, _player| true,
|
||||
)
|
||||
.add_position_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
1,
|
||||
|game, player_index, _| {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
if !player.is_building_available(Building::Temple, game) {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -267,12 +265,12 @@ fn great_prophet() -> ActionCard {
|
|||
},
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player, a| {
|
||||
a.selected_position?;
|
||||
Some(vec![PaymentRequest::new(
|
||||
temple_cost(game, game.get_player(player)),
|
||||
temple_cost(game, game.player(player)),
|
||||
"Pay to build the Temple",
|
||||
true,
|
||||
)])
|
||||
|
|
@ -288,11 +286,12 @@ fn great_prophet() -> ActionCard {
|
|||
let pos = a.selected_position.expect("position not found");
|
||||
game.add_info_log_item(&format!("{name} built a Temple at {pos} for {pile}",));
|
||||
|
||||
construct(
|
||||
let () = construct(
|
||||
game,
|
||||
s.player_index,
|
||||
&Construct::new(pos, Building::Temple, pile),
|
||||
);
|
||||
)
|
||||
.expect("Cannot build Temple");
|
||||
},
|
||||
)
|
||||
.build()
|
||||
|
|
@ -321,11 +320,11 @@ fn great_philosopher() -> ActionCard {
|
|||
|_game, _player| true,
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player_index, player_name, _| {
|
||||
game.add_info_log_item(&format!("{player_name} gained 2 ideas",));
|
||||
game.get_player_mut(player_index)
|
||||
game.player_mut(player_index)
|
||||
.gain_resources(ResourcePile::ideas(2));
|
||||
},
|
||||
)
|
||||
|
|
@ -346,11 +345,11 @@ fn great_scientist() -> ActionCard {
|
|||
|_game, _player| true,
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player_index, player_name, _| {
|
||||
game.add_info_log_item(&format!("{player_name} gained 1 idea",));
|
||||
game.get_player_mut(player_index)
|
||||
game.player_mut(player_index)
|
||||
.gain_resources(ResourcePile::ideas(1));
|
||||
gain_action_card_from_pile(game, player_index);
|
||||
},
|
||||
|
|
@ -375,7 +374,7 @@ fn elder_statesman() -> ActionCard {
|
|||
|_game, _player| true,
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player_index, _player_name, _| {
|
||||
gain_action_card_from_pile(game, player_index);
|
||||
|
|
@ -399,7 +398,7 @@ fn great_merchant() -> ActionCard {
|
|||
groups,
|
||||
|_game, _player| true,
|
||||
),
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
|
@ -418,10 +417,10 @@ fn great_athlete() -> ActionCard {
|
|||
|_game, player| player.resources.culture_tokens > 0 || player.resources.mood_tokens > 0,
|
||||
)
|
||||
.add_bool_request(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
1,
|
||||
|game, player_index, _| {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
if p.resources.culture_tokens > 0 && p.resources.mood_tokens > 0 {
|
||||
Some("Convert culture to mood tokens?".to_string())
|
||||
} else {
|
||||
|
|
@ -444,10 +443,10 @@ fn great_athlete() -> ActionCard {
|
|||
},
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, player, a| {
|
||||
let p = game.get_player(player);
|
||||
let p = game.player(player);
|
||||
let culture_to_mood = if p.resources.culture_tokens > 0 && p.resources.mood_tokens > 0 {
|
||||
a.answer.expect("answer not found")
|
||||
} else {
|
||||
|
|
@ -483,7 +482,7 @@ fn great_athlete() -> ActionCard {
|
|||
ResourcePile::culture_tokens(from.mood_tokens)
|
||||
};
|
||||
game.add_info_log_item(&format!("{} converted {from} mood to {to}", s.player_name));
|
||||
game.get_player_mut(s.player_index).gain_resources(to);
|
||||
game.player_mut(s.player_index).gain_resources(to);
|
||||
},
|
||||
)
|
||||
.build()
|
||||
|
|
|
|||
|
|
@ -26,7 +26,7 @@ pub(crate) fn great_warlord() -> ActionCard {
|
|||
|_game, _player| true,
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|e| &mut e.on_play_action_card,
|
||||
|e| &mut e.play_action_card,
|
||||
0,
|
||||
|game, _player_index, _player_name, _| {
|
||||
game.state = GameState::Movement(MoveState {
|
||||
|
|
@ -41,7 +41,7 @@ pub(crate) fn great_warlord() -> ActionCard {
|
|||
pub(crate) fn use_great_warlord() -> Builtin {
|
||||
Builtin::builder("great_warlord", "-")
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_combat_start,
|
||||
|event| &mut event.combat_start,
|
||||
9,
|
||||
|game, _player_index, _name, c| {
|
||||
if let Movement(m) = &mut game.state {
|
||||
|
|
@ -52,7 +52,7 @@ pub(crate) fn use_great_warlord() -> Builtin {
|
|||
},
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_combat_round_start,
|
||||
|event| &mut event.combat_round_start,
|
||||
9,
|
||||
|_game, player_index, _name, r| {
|
||||
if r.combat.modifiers.contains(&CombatModifier::GreatWarlord)
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
use crate::card::{hand_cards, HandCard, HandCardType};
|
||||
use crate::card::{HandCard, HandCardType, hand_cards};
|
||||
use crate::city::City;
|
||||
use crate::content::custom_phase_actions::{
|
||||
HandCardsRequest, PaymentRequest, PositionRequest, ResourceRewardRequest, UnitsRequest,
|
||||
};
|
||||
use crate::content::incidents::famine::{
|
||||
additional_sanitation_damage, famine, kill_incident_units,
|
||||
};
|
||||
use crate::content::persistent_events::{
|
||||
HandCardsRequest, PaymentRequest, PositionRequest, ResourceRewardRequest, UnitsRequest,
|
||||
};
|
||||
use crate::game::Game;
|
||||
use crate::incident::{Incident, IncidentBaseEffect, MoodModifier};
|
||||
use crate::map::{Map, Terrain};
|
||||
|
|
@ -44,10 +44,10 @@ fn pandemics() -> Incident {
|
|||
game.add_info_log_item(&format!(
|
||||
"{} has to lose a total of {} units, cards, and resources",
|
||||
game.player_name(p),
|
||||
pandemics_cost(game.get_player(p))
|
||||
pandemics_cost(game.player(p))
|
||||
));
|
||||
|
||||
let player = game.get_player(p);
|
||||
let player = game.player(p);
|
||||
Some(UnitsRequest::new(
|
||||
p,
|
||||
player.units.iter().map(|u| u.id).collect_vec(),
|
||||
|
|
@ -64,7 +64,7 @@ fn pandemics() -> Incident {
|
|||
IncidentTarget::AllPlayers,
|
||||
1,
|
||||
|game, p, i| {
|
||||
let player = game.get_player(p);
|
||||
let player = game.player(p);
|
||||
Some(HandCardsRequest::new(
|
||||
// todo also objective cards
|
||||
hand_cards(player, &[HandCardType::Action]),
|
||||
|
|
@ -76,7 +76,7 @@ fn pandemics() -> Incident {
|
|||
for id in &s.choice {
|
||||
match id {
|
||||
HandCard::ActionCard(a) => {
|
||||
game.get_player_mut(s.player_index)
|
||||
game.player_mut(s.player_index)
|
||||
.action_cards
|
||||
.retain(|c| c != a);
|
||||
game.add_info_log_item(&format!(
|
||||
|
|
@ -94,7 +94,7 @@ fn pandemics() -> Incident {
|
|||
IncidentTarget::AllPlayers,
|
||||
0,
|
||||
|game, p, i| {
|
||||
let player = game.get_player(p);
|
||||
let player = game.player(p);
|
||||
let needed = PandemicsContributions::range(player, i, 2)
|
||||
.min()
|
||||
.expect("min not found");
|
||||
|
|
@ -166,7 +166,7 @@ fn black_death() -> Incident {
|
|||
IncidentTarget::AllPlayers,
|
||||
0,
|
||||
|game, p, _i| {
|
||||
let player = game.get_player(p);
|
||||
let player = game.player(p);
|
||||
let units = player.units.iter().map(|u| u.id).collect_vec();
|
||||
if units.len() < 4 {
|
||||
return None;
|
||||
|
|
@ -188,33 +188,41 @@ fn black_death() -> Incident {
|
|||
kill_incident_units(game, s);
|
||||
let vp = s.choice.len() as f32;
|
||||
game.add_info_log_item(&format!("{} gained {} victory points", s.player_name, vp));
|
||||
game.get_player_mut(s.player_index).event_victory_points += vp;
|
||||
game.player_mut(s.player_index).event_victory_points += vp;
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
fn vermin() -> Incident {
|
||||
famine(51,
|
||||
"Famine: Vermin",
|
||||
"Every player with Storage: Pay 1 food (gold not allowed). If you cannot pay, make 1 city Angry.",
|
||||
IncidentTarget::AllPlayers,
|
||||
IncidentBaseEffect::None,
|
||||
|_, _| 1,
|
||||
|p| p.has_advance("Storage"),
|
||||
|_, _| true,
|
||||
famine(
|
||||
51,
|
||||
"Famine: Vermin",
|
||||
"Every player with Storage: Pay 1 food (gold not allowed). If you cannot pay, make 1 city Angry.",
|
||||
IncidentTarget::AllPlayers,
|
||||
IncidentBaseEffect::None,
|
||||
|_, _| 1,
|
||||
|p| p.has_advance("Storage"),
|
||||
|_, _| true,
|
||||
)
|
||||
}
|
||||
|
||||
fn draught() -> Incident {
|
||||
famine(52,
|
||||
"Famine: Draught",
|
||||
"Pay 1 food for every city on or adjacent to Barren Land (up to 3 food, gold not allowed). If you cannot pay the full amount, make 1 of those cities Angry.",
|
||||
IncidentTarget::ActivePlayer,
|
||||
IncidentBaseEffect::None,
|
||||
|p, game| p.cities.iter().filter(|c| on_or_adjacent_to_barren(c, game)).count().min(3) as u8,
|
||||
|_| true,
|
||||
on_or_adjacent_to_barren,
|
||||
famine(
|
||||
52,
|
||||
"Famine: Draught",
|
||||
"Pay 1 food for every city on or adjacent to Barren Land (up to 3 food, gold not allowed). If you cannot pay the full amount, make 1 of those cities Angry.",
|
||||
IncidentTarget::ActivePlayer,
|
||||
IncidentBaseEffect::None,
|
||||
|p, game| {
|
||||
p.cities
|
||||
.iter()
|
||||
.filter(|c| on_or_adjacent_to_barren(c, game))
|
||||
.count()
|
||||
.min(3) as u8
|
||||
},
|
||||
|_| true,
|
||||
on_or_adjacent_to_barren,
|
||||
)
|
||||
}
|
||||
|
||||
|
|
@ -239,7 +247,7 @@ fn fire() -> Incident {
|
|||
IncidentTarget::ActivePlayer,
|
||||
11,
|
||||
|game, p, _i| {
|
||||
let player = game.get_player(p);
|
||||
let player = game.player(p);
|
||||
let cities = player
|
||||
.cities
|
||||
.iter()
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::city::City;
|
||||
use crate::city_pieces::Building;
|
||||
use crate::content::custom_phase_actions::{PositionRequest, ResourceRewardRequest};
|
||||
use crate::content::persistent_events::{PositionRequest, ResourceRewardRequest};
|
||||
use crate::game::Game;
|
||||
use crate::incident::{Incident, IncidentBaseEffect, PassedIncident};
|
||||
use crate::payment::PaymentOptions;
|
||||
|
|
@ -26,7 +26,7 @@ fn scientific_trade() -> Incident {
|
|||
IncidentBaseEffect::PiratesSpawnAndRaid,
|
||||
)
|
||||
.add_simple_incident_listener(IncidentTarget::AllPlayers, 0, |game, p, name, i| {
|
||||
let player = game.get_player_mut(p);
|
||||
let player = game.player_mut(p);
|
||||
let mut ideas = player
|
||||
.cities
|
||||
.iter()
|
||||
|
|
@ -55,7 +55,7 @@ fn flourishing_trade() -> Incident {
|
|||
IncidentBaseEffect::PiratesSpawnAndRaid,
|
||||
)
|
||||
.add_simple_incident_listener(IncidentTarget::AllPlayers, 0, |game, p, name, i| {
|
||||
let player = game.get_player_mut(p);
|
||||
let player = game.player_mut(p);
|
||||
let mut gold = player
|
||||
.cities
|
||||
.iter()
|
||||
|
|
@ -91,7 +91,7 @@ fn era_of_stability() -> Incident {
|
|||
IncidentTarget::AllPlayers,
|
||||
0,
|
||||
|game, p, i| {
|
||||
let player = game.get_player(p);
|
||||
let player = game.player(p);
|
||||
let mut tokens = player
|
||||
.cities
|
||||
.iter()
|
||||
|
|
@ -176,7 +176,7 @@ fn reformation() -> Incident {
|
|||
|game, _p, i| {
|
||||
let donor = i.active_player;
|
||||
let choices = game
|
||||
.get_player(donor)
|
||||
.player(donor)
|
||||
.cities
|
||||
.iter()
|
||||
.filter(|c| city_has_temple(c, donor))
|
||||
|
|
@ -194,7 +194,7 @@ fn reformation() -> Incident {
|
|||
.current_event()
|
||||
.active_player()
|
||||
.expect("should have active player");
|
||||
let donor = game.get_player_mut(p);
|
||||
let donor = game.player_mut(p);
|
||||
let pos = s.choice[0];
|
||||
donor
|
||||
.get_city_mut(pos)
|
||||
|
|
@ -211,7 +211,7 @@ fn reformation() -> Incident {
|
|||
}
|
||||
|
||||
fn has_temple(game: &Game, player: usize) -> bool {
|
||||
game.get_player(player)
|
||||
game.player(player)
|
||||
.cities
|
||||
.iter()
|
||||
.any(|c| city_has_temple(c, player))
|
||||
|
|
|
|||
|
|
@ -3,8 +3,8 @@ use crate::combat::{Combat, CombatModifier, CombatRetreatState};
|
|||
use crate::combat_listeners::CombatResult;
|
||||
use crate::content::advances::get_advance;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_phase_actions::PaymentRequest;
|
||||
use crate::content::effects::{Anarchy, PermanentEffect};
|
||||
use crate::content::persistent_events::PaymentRequest;
|
||||
use crate::game::Game;
|
||||
use crate::incident::{Incident, IncidentBaseEffect};
|
||||
use crate::payment::PaymentOptions;
|
||||
|
|
@ -38,7 +38,7 @@ fn trojan_cost() -> PaymentOptions {
|
|||
pub(crate) fn decide_trojan_horse() -> Builtin {
|
||||
Builtin::builder("Trojan Horse", TROJAN_DESCRIPTION)
|
||||
.add_payment_request_listener(
|
||||
|event| &mut event.on_combat_start,
|
||||
|event| &mut event.combat_start,
|
||||
10,
|
||||
|game, player_index, c| {
|
||||
if is_land_battle_against_defended_city(game, player_index, c) {
|
||||
|
|
@ -58,7 +58,7 @@ pub(crate) fn decide_trojan_horse() -> Builtin {
|
|||
s.player_name
|
||||
));
|
||||
} else {
|
||||
let player = game.get_player_mut(s.player_index);
|
||||
let player = game.player_mut(s.player_index);
|
||||
player.event_victory_points += 1_f32;
|
||||
game.add_info_log_item(&format!(
|
||||
"{} activated the Trojan Horse and gained 1 victory point",
|
||||
|
|
@ -96,7 +96,7 @@ fn solar_eclipse() -> Incident {
|
|||
pub(crate) fn solar_eclipse_end_combat() -> Builtin {
|
||||
Builtin::builder("Solar Eclipse", "-")
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_combat_round_end,
|
||||
|event| &mut event.combat_round_end,
|
||||
10,
|
||||
|game, _player, name, r| {
|
||||
if let Some(p) = game
|
||||
|
|
@ -112,7 +112,7 @@ pub(crate) fn solar_eclipse_end_combat() -> Builtin {
|
|||
Some(CombatResult::AttackerWins) => r.combat.attacker,
|
||||
_ => r.combat.defender,
|
||||
};
|
||||
let p = game.get_player_mut(p);
|
||||
let p = game.player_mut(p);
|
||||
p.event_victory_points += 1_f32;
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} gained 1 victory point for the Solar Eclipse",
|
||||
|
|
@ -157,7 +157,7 @@ fn anarchy() -> Incident {
|
|||
IncidentTarget::ActivePlayer,
|
||||
0,
|
||||
|game, player_index, player_name, _| {
|
||||
let p = game.get_player_mut(player_index);
|
||||
let p = game.player_mut(player_index);
|
||||
let old = p.advances.len();
|
||||
p.advances.retain(|a| a.government.is_none());
|
||||
let lost = old - p.advances.len();
|
||||
|
|
@ -182,7 +182,7 @@ fn anarchy() -> Incident {
|
|||
pub(crate) fn anarchy_advance() -> Builtin {
|
||||
Builtin::builder("Anarchy", "-")
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_advance,
|
||||
|event| &mut event.advance,
|
||||
10,
|
||||
|game, player_index, player_name, i| {
|
||||
if get_advance(&i.name).government.is_none() {
|
||||
|
|
@ -201,7 +201,7 @@ pub(crate) fn anarchy_advance() -> Builtin {
|
|||
"{player_name} gained a government advance, taking a game event token \
|
||||
instead of triggering a game event (and losing 1 victory point)",
|
||||
));
|
||||
let p = game.get_player_mut(player_index);
|
||||
let p = game.player_mut(player_index);
|
||||
p.incident_tokens += 1;
|
||||
p.event_victory_points -= 1_f32;
|
||||
a.advances_lost -= 1;
|
||||
|
|
|
|||
|
|
@ -17,11 +17,145 @@ use crate::position::Position;
|
|||
use crate::resource_pile::ResourcePile;
|
||||
use crate::status_phase::{ChangeGovernmentType, StatusPhaseState};
|
||||
use crate::unit::UnitType;
|
||||
use crate::utils;
|
||||
use crate::wonder::WonderCardInfo;
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::ops::RangeInclusive;
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum PersistentEventRequest {
|
||||
Payment(Vec<PaymentRequest>),
|
||||
ResourceReward(ResourceRewardRequest),
|
||||
SelectAdvance(AdvanceRequest),
|
||||
SelectPlayer(PlayerRequest),
|
||||
SelectPositions(PositionRequest),
|
||||
SelectUnitType(UnitTypeRequest),
|
||||
SelectUnits(UnitsRequest),
|
||||
SelectStructures(StructuresRequest),
|
||||
SelectHandCards(HandCardsRequest),
|
||||
BoolRequest(String),
|
||||
ChangeGovernment(ChangeGovernmentRequest),
|
||||
ExploreResolution,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum EventResponse {
|
||||
Payment(Vec<ResourcePile>),
|
||||
ResourceReward(ResourcePile),
|
||||
SelectAdvance(String),
|
||||
SelectPlayer(usize),
|
||||
SelectPositions(Vec<Position>),
|
||||
SelectUnitType(UnitType),
|
||||
SelectUnits(Vec<u32>),
|
||||
SelectHandCards(Vec<HandCard>),
|
||||
SelectStructures(Vec<SelectedStructure>),
|
||||
Bool(bool),
|
||||
ChangeGovernmentType(ChangeGovernmentType),
|
||||
ExploreResolution(Rotation),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct PersistentEventHandler {
|
||||
pub priority: i32,
|
||||
pub request: PersistentEventRequest,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub response: Option<EventResponse>,
|
||||
pub origin: EventOrigin,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct PersistentEventPlayer {
|
||||
#[serde(rename = "player")]
|
||||
pub index: usize,
|
||||
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub last_priority_used: Option<i32>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "utils::is_false")]
|
||||
pub skip_first_priority: bool,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub handler: Option<PersistentEventHandler>,
|
||||
}
|
||||
|
||||
impl PersistentEventPlayer {
|
||||
#[must_use]
|
||||
pub fn new(current_player: usize) -> Self {
|
||||
Self {
|
||||
index: current_player,
|
||||
last_priority_used: None,
|
||||
skip_first_priority: false,
|
||||
handler: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum PersistentEventType {
|
||||
Collect(CollectInfo),
|
||||
ExploreResolution(ExploreResolutionState),
|
||||
InfluenceCultureResolution(ResourcePile),
|
||||
UnitsKilled(KilledUnits),
|
||||
CombatStart(Combat),
|
||||
CombatRoundStart(CombatRoundStart),
|
||||
CombatRoundEnd(CombatRoundEnd),
|
||||
CombatEnd(CombatEnd),
|
||||
StatusPhase(StatusPhaseState),
|
||||
TurnStart,
|
||||
Advance(AdvanceInfo),
|
||||
Construct(Building),
|
||||
Recruit(Recruit),
|
||||
Incident(IncidentInfo),
|
||||
ActionCard(ActionCardInfo),
|
||||
WonderCard(WonderCardInfo),
|
||||
DrawWonderCard,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct PersistentEventState {
|
||||
pub event_type: PersistentEventType,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub players_used: Vec<usize>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub player: PersistentEventPlayer,
|
||||
}
|
||||
|
||||
impl PersistentEventState {
|
||||
#[must_use]
|
||||
pub fn new(current_player: usize, event_type: PersistentEventType) -> Self {
|
||||
Self {
|
||||
event_type,
|
||||
players_used: vec![],
|
||||
player: PersistentEventPlayer::new(current_player),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn active_player(&self) -> Option<&usize> {
|
||||
self.players_used.first()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct KilledUnits {
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub killer: Option<usize>,
|
||||
pub position: Position,
|
||||
}
|
||||
|
||||
impl KilledUnits {
|
||||
#[must_use]
|
||||
pub fn new(position: Position, killer: Option<usize>) -> Self {
|
||||
Self { killer, position }
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct PaymentRequest {
|
||||
pub cost: PaymentOptions,
|
||||
|
|
@ -108,126 +242,13 @@ pub fn is_selected_structures_valid(game: &Game, selected: &[SelectedStructure])
|
|||
.into_iter()
|
||||
.all(|(p, g)| {
|
||||
let v = g.collect_vec();
|
||||
v.len() == game.get_any_city(p).size()
|
||||
v.len() == game.any_city(p).size()
|
||||
|| !v
|
||||
.iter()
|
||||
.any(|s| matches!(s.structure, Structure::CityCenter))
|
||||
})
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum CurrentEventRequest {
|
||||
Payment(Vec<PaymentRequest>),
|
||||
ResourceReward(ResourceRewardRequest),
|
||||
SelectAdvance(AdvanceRequest),
|
||||
SelectPlayer(PlayerRequest),
|
||||
SelectPositions(PositionRequest),
|
||||
SelectUnitType(UnitTypeRequest),
|
||||
SelectUnits(UnitsRequest),
|
||||
SelectStructures(StructuresRequest),
|
||||
SelectHandCards(HandCardsRequest),
|
||||
BoolRequest(String),
|
||||
ChangeGovernment(ChangeGovernmentRequest),
|
||||
ExploreResolution,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum EventResponse {
|
||||
Payment(Vec<ResourcePile>),
|
||||
ResourceReward(ResourcePile),
|
||||
SelectAdvance(String),
|
||||
SelectPlayer(usize),
|
||||
SelectPositions(Vec<Position>),
|
||||
SelectUnitType(UnitType),
|
||||
SelectUnits(Vec<u32>),
|
||||
SelectHandCards(Vec<HandCard>),
|
||||
SelectStructures(Vec<SelectedStructure>),
|
||||
Bool(bool),
|
||||
ChangeGovernmentType(ChangeGovernmentType),
|
||||
ExploreResolution(Rotation),
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct CurrentEventHandler {
|
||||
pub priority: i32,
|
||||
pub request: CurrentEventRequest,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub response: Option<EventResponse>,
|
||||
pub origin: EventOrigin,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct CurrentEventPlayer {
|
||||
#[serde(rename = "player")]
|
||||
pub index: usize,
|
||||
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub last_priority_used: Option<i32>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub handler: Option<CurrentEventHandler>,
|
||||
}
|
||||
|
||||
impl CurrentEventPlayer {
|
||||
#[must_use]
|
||||
pub fn new(current_player: usize) -> Self {
|
||||
Self {
|
||||
index: current_player,
|
||||
last_priority_used: None,
|
||||
handler: None,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub enum CurrentEventType {
|
||||
Collect(CollectInfo),
|
||||
ExploreResolution(ExploreResolutionState),
|
||||
InfluenceCultureResolution(ResourcePile),
|
||||
CombatStart(Combat),
|
||||
CombatRoundStart(CombatRoundStart),
|
||||
CombatRoundEnd(CombatRoundEnd),
|
||||
CombatEnd(CombatEnd),
|
||||
StatusPhase(StatusPhaseState),
|
||||
TurnStart,
|
||||
Advance(AdvanceInfo),
|
||||
Construct(Building),
|
||||
Recruit(Recruit),
|
||||
Incident(IncidentInfo),
|
||||
ActionCard(ActionCardInfo),
|
||||
WonderCard(WonderCardInfo),
|
||||
DrawWonderCard,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct CurrentEventState {
|
||||
pub event_type: CurrentEventType,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
pub players_used: Vec<usize>,
|
||||
|
||||
#[serde(flatten)]
|
||||
pub player: CurrentEventPlayer,
|
||||
}
|
||||
|
||||
impl CurrentEventState {
|
||||
#[must_use]
|
||||
pub fn new(current_player: usize, event_type: CurrentEventType) -> Self {
|
||||
Self {
|
||||
event_type,
|
||||
players_used: vec![],
|
||||
player: CurrentEventPlayer::new(current_player),
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn active_player(&self) -> Option<&usize> {
|
||||
self.players_used.first()
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]
|
||||
pub struct PositionRequest {
|
||||
#[serde(flatten)]
|
||||
|
|
@ -355,12 +376,12 @@ impl ChangeGovernmentRequest {
|
|||
}
|
||||
|
||||
impl EventResponse {
|
||||
pub(crate) fn redo(self, game: &mut Game, player_index: usize) {
|
||||
pub(crate) fn redo(self, game: &mut Game, player_index: usize) -> Result<(), String> {
|
||||
let Some(s) = game.current_event_handler_mut() else {
|
||||
panic!("current custom phase event should be set")
|
||||
};
|
||||
s.response = Some(self.clone());
|
||||
let details = game.current_event().event_type.clone();
|
||||
execute_custom_phase_action(game, player_index, details);
|
||||
execute_custom_phase_action(game, player_index, details)
|
||||
}
|
||||
}
|
||||
|
|
@ -1,9 +1,9 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::action_card::gain_action_card_from_pile;
|
||||
use crate::combat::{update_combat_strength, Combat};
|
||||
use crate::combat_listeners::{CombatResult, CombatRoundStart, CombatStrength};
|
||||
use crate::action_card::{gain_action_card, gain_action_card_from_pile};
|
||||
use crate::combat::{Combat, update_combat_strength};
|
||||
use crate::combat_listeners::{CombatResult, CombatRoundStart, CombatStrength, kill_combat_units};
|
||||
use crate::content::action_cards::get_action_card;
|
||||
use crate::content::custom_phase_actions::{PaymentRequest, PositionRequest};
|
||||
use crate::content::persistent_events::{PaymentRequest, PositionRequest, UnitsRequest};
|
||||
use crate::game::Game;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::position::Position;
|
||||
|
|
@ -11,6 +11,7 @@ use crate::resource_pile::ResourcePile;
|
|||
use crate::tactics_card::{
|
||||
CombatLocation, CombatRole, FighterRequirement, TacticsCard, TacticsCardTarget,
|
||||
};
|
||||
use crate::utils::a_or_an;
|
||||
use std::vec;
|
||||
|
||||
///
|
||||
|
|
@ -34,7 +35,7 @@ pub(crate) fn peltasts(id: u8) -> TacticsCard {
|
|||
.fighter_requirement(FighterRequirement::Army)
|
||||
.add_reveal_listener(0, |player, game, combat, s| {
|
||||
for _ in &combat.fighting_units(game, player) {
|
||||
let roll = game.get_next_dice_roll().value;
|
||||
let roll = game.next_dice_roll().value;
|
||||
if roll >= 5 {
|
||||
s.roll_log
|
||||
.push(format!("Peltasts rolled a {roll} and ignored a hit",));
|
||||
|
|
@ -69,7 +70,7 @@ pub(crate) fn encircled(id: u8) -> TacticsCard {
|
|||
return;
|
||||
}
|
||||
|
||||
let roll = game.get_next_dice_roll().value;
|
||||
let roll = game.next_dice_roll().value;
|
||||
if roll >= 5 {
|
||||
game.add_info_log_item(
|
||||
"Encircled rolled a 5 or 6 and added a hit that cannot be ignored",
|
||||
|
|
@ -189,12 +190,12 @@ pub(crate) fn siege(id: u8) -> TacticsCard {
|
|||
s.roll_log.push("Siege added 1 to combat value".to_string());
|
||||
})
|
||||
.add_payment_request_listener(
|
||||
|event| &mut event.on_combat_round_start_tactics,
|
||||
|event| &mut event.combat_round_start_tactics,
|
||||
0,
|
||||
move |game, p, s| {
|
||||
if s.is_active(p, id, TacticsCardTarget::Opponent) {
|
||||
let cost = PaymentOptions::resources(ResourcePile::food(2));
|
||||
if game.get_player(p).can_afford(&cost) {
|
||||
if game.player(p).can_afford(&cost) {
|
||||
return Some(vec![PaymentRequest::new(
|
||||
cost,
|
||||
"Pay 2 food to use combat abilities this round",
|
||||
|
|
@ -234,37 +235,29 @@ fn apply_siege(game: &mut Game, r: &mut CombatRoundStart, player: usize) {
|
|||
}
|
||||
|
||||
pub(crate) fn for_the_people(id: u8) -> TacticsCard {
|
||||
TacticsCard::builder(
|
||||
id,
|
||||
"For the People",
|
||||
"When defending a city: Add 1 die to your roll.",
|
||||
)
|
||||
.role_requirement(CombatRole::Defender)
|
||||
.location_requirement(CombatLocation::City)
|
||||
.target(TacticsCardTarget::ActivePlayer)
|
||||
.add_reveal_listener(0, |_player, _game, _c, s| {
|
||||
s.extra_dies += 1;
|
||||
s.roll_log
|
||||
.push("For The People added 1 extra die".to_string());
|
||||
})
|
||||
.build()
|
||||
TacticsCard::builder(id, "For the People", "Add 1 die to your roll.")
|
||||
.role_requirement(CombatRole::Defender)
|
||||
.location_requirement(CombatLocation::City)
|
||||
.target(TacticsCardTarget::ActivePlayer)
|
||||
.add_reveal_listener(0, |_player, _game, _c, s| {
|
||||
s.extra_dies += 1;
|
||||
s.roll_log
|
||||
.push("For The People added 1 extra die".to_string());
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn improved_defenses(id: u8) -> TacticsCard {
|
||||
TacticsCard::builder(
|
||||
id,
|
||||
"Improved Defenses",
|
||||
"When defending a city: Ignore 1 hit.",
|
||||
)
|
||||
.role_requirement(CombatRole::Defender)
|
||||
.location_requirement(CombatLocation::City)
|
||||
.target(TacticsCardTarget::ActivePlayer)
|
||||
.add_reveal_listener(0, |_player, _game, _c, s| {
|
||||
s.hit_cancels += 1;
|
||||
s.roll_log
|
||||
.push("Improved Defenses ignored 1 hit.".to_string());
|
||||
})
|
||||
.build()
|
||||
TacticsCard::builder(id, "Improved Defenses", "Ignore 1 hit.")
|
||||
.role_requirement(CombatRole::Defender)
|
||||
.location_requirement(CombatLocation::City)
|
||||
.target(TacticsCardTarget::ActivePlayer)
|
||||
.add_reveal_listener(0, |_player, _game, _c, s| {
|
||||
s.hit_cancels += 1;
|
||||
s.roll_log
|
||||
.push("Improved Defenses ignored 1 hit.".to_string());
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn tactical_retreat(id: u8) -> TacticsCard {
|
||||
|
|
@ -280,7 +273,7 @@ pub(crate) fn tactical_retreat(id: u8) -> TacticsCard {
|
|||
.checker(|_, game, c| !tactical_retreat_targets(c, game).is_empty())
|
||||
.target(TacticsCardTarget::ActivePlayer)
|
||||
.add_position_request(
|
||||
|event| &mut event.on_combat_round_start_tactics,
|
||||
|event| &mut event.combat_round_start_tactics,
|
||||
0,
|
||||
move |game, p, s| {
|
||||
(p == s.combat.defender).then_some(PositionRequest::new(
|
||||
|
|
@ -298,7 +291,7 @@ pub(crate) fn tactical_retreat(id: u8) -> TacticsCard {
|
|||
to
|
||||
));
|
||||
for unit in game
|
||||
.get_player_mut(s.player_index)
|
||||
.player_mut(s.player_index)
|
||||
.get_units_mut(r.combat.defender_position)
|
||||
{
|
||||
unit.position = to;
|
||||
|
|
@ -317,17 +310,82 @@ fn tactical_retreat_targets(c: &Combat, game: &Game) -> Vec<Position> {
|
|||
.collect()
|
||||
}
|
||||
|
||||
pub(crate) fn martyr(id: u8) -> TacticsCard {
|
||||
TacticsCard::builder(id, "Martyr", "todo")
|
||||
.fighter_any_requirement(&[FighterRequirement::Army, FighterRequirement::Ship])
|
||||
.target(TacticsCardTarget::Opponent)
|
||||
//todo add sacrifice effect, add test
|
||||
.add_veto_tactics_listener(0, move |p, game, _c, s| {
|
||||
game.add_info_log_item(&format!(
|
||||
"{} ignores the enemy tactics",
|
||||
game.player_name(p)
|
||||
));
|
||||
s.tactics_card = None;
|
||||
pub(crate) fn defensive_formation(id: u8) -> TacticsCard {
|
||||
TacticsCard::builder(id, "Defensive Formation", "Roll 1 extra die.")
|
||||
.role_requirement(CombatRole::Defender)
|
||||
.target(TacticsCardTarget::ActivePlayer)
|
||||
.add_reveal_listener(0, |_player, _game, _c, s| {
|
||||
s.extra_dies += 1;
|
||||
s.roll_log
|
||||
.push("Defensive Formation added 1 extra die.".to_string());
|
||||
})
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn scout(id: u8) -> TacticsCard {
|
||||
TacticsCard::builder(
|
||||
id,
|
||||
"Scout",
|
||||
"Ignore the enemy tactics card and take it to your hand.",
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.combat_round_start_reveal_tactics,
|
||||
0,
|
||||
move |game, p, name, s| {
|
||||
if s.is_active(p, id, TacticsCardTarget::ActivePlayer) {
|
||||
update_combat_strength(game, s.combat.opponent(p), s, |game, _combat, st, _role| {
|
||||
if let Some(tactics_card) = st.tactics_card.take() {
|
||||
let card = get_action_card(tactics_card);
|
||||
gain_action_card(game, p, &card);
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} ignores the enemy tactics {} and takes it to their hand using Scout",
|
||||
card.tactics_card.expect("tactics card not found").name
|
||||
));
|
||||
} else {
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} cannot use Scout - opponent didn't play a tactics card",
|
||||
));
|
||||
}
|
||||
});
|
||||
}
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
||||
pub(crate) fn martyr(id: u8) -> TacticsCard {
|
||||
TacticsCard::builder(id, "Martyr", "todo")
|
||||
.fighter_any_requirement(&[FighterRequirement::Army, FighterRequirement::Ship])
|
||||
.target(TacticsCardTarget::AllPlayers)
|
||||
.add_units_request(
|
||||
|event| &mut event.combat_round_start_tactics,
|
||||
0,
|
||||
move |game, p, s| {
|
||||
Some(UnitsRequest::new(p, s.combat.fighting_units(game, p), 1..=1, "Select a unit to sacrifice"))
|
||||
},
|
||||
move |game, s, r| {
|
||||
let unit = s.choice[0];
|
||||
game.add_info_log_item(&format!(
|
||||
"{} sacrifices {} using Martyr",
|
||||
game.player_name(s.player_index),
|
||||
a_or_an(game.player(s.player_index).get_unit(unit).unit_type.name())
|
||||
));
|
||||
kill_combat_units(game, &mut r.combat, s.player_index, &[unit]);
|
||||
},
|
||||
)
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.combat_round_start_reveal_tactics,
|
||||
0,
|
||||
move |game, p, name, s| {
|
||||
if s.is_active(p, id, TacticsCardTarget::Opponent) {
|
||||
update_combat_strength(game, p, s, |game, _combat, st, _role| {
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} cannot use their tactics card using Martyr (but it is still discarded)",
|
||||
));
|
||||
st.tactics_card = None;
|
||||
});
|
||||
}
|
||||
},
|
||||
)
|
||||
.build()
|
||||
}
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@ use crate::action::Action;
|
|||
use crate::city::City;
|
||||
use crate::city_pieces::Building;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_phase_actions::{
|
||||
CurrentEventType, PaymentRequest, SelectedStructure, Structure,
|
||||
use crate::content::persistent_events::{
|
||||
PaymentRequest, PersistentEventType, SelectedStructure, Structure,
|
||||
};
|
||||
use crate::game::Game;
|
||||
use crate::log::current_player_turn_log;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::player_events::{ActionInfo, InfluenceCultureInfo, InfluenceCultureOutcome};
|
||||
use crate::playing_actions::{roll_boost_cost, PlayingAction};
|
||||
use crate::playing_actions::{PlayingAction, roll_boost_cost};
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
|
||||
|
|
@ -20,7 +20,7 @@ pub(crate) fn influence_culture_attempt(
|
|||
c: &SelectedStructure,
|
||||
) {
|
||||
let target_city_position = c.position;
|
||||
let target_city = game.get_any_city(target_city_position);
|
||||
let target_city = game.any_city(target_city_position);
|
||||
|
||||
let info = influence_culture_boost_cost(game, player_index, c);
|
||||
assert!(info.blockers.is_empty(), "Impossible to influence culture");
|
||||
|
|
@ -32,7 +32,7 @@ pub(crate) fn influence_culture_attempt(
|
|||
|
||||
// currently, there is no way to have different costs for this
|
||||
game.players[player_index].lose_resources(info.range_boost_cost.default.clone());
|
||||
let roll = game.get_next_dice_roll().value + info.roll_boost;
|
||||
let roll = game.next_dice_roll().value + info.roll_boost;
|
||||
let success = roll >= 5;
|
||||
if success {
|
||||
game.add_to_last_log_item(&format!(" and succeeded (rolled {roll})"));
|
||||
|
|
@ -68,11 +68,11 @@ pub(crate) fn ask_for_cultural_influence_payment(
|
|||
player_index: usize,
|
||||
roll_boost_cost: ResourcePile,
|
||||
) {
|
||||
let _ = game.trigger_current_event(
|
||||
let _ = game.trigger_persistent_event(
|
||||
&[player_index],
|
||||
|e| &mut e.on_influence_culture_resolution,
|
||||
|e| &mut e.influence_culture_resolution,
|
||||
roll_boost_cost,
|
||||
CurrentEventType::InfluenceCultureResolution,
|
||||
PersistentEventType::InfluenceCultureResolution,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -82,7 +82,7 @@ pub(crate) fn cultural_influence_resolution() -> Builtin {
|
|||
"Pay culture tokens to increase the dice roll",
|
||||
)
|
||||
.add_payment_request_listener(
|
||||
|e| &mut e.on_influence_culture_resolution,
|
||||
|e| &mut e.influence_culture_resolution,
|
||||
0,
|
||||
|_game, _player_index, cost| {
|
||||
Some(vec![PaymentRequest::new(
|
||||
|
|
@ -168,10 +168,10 @@ pub fn influence_culture_boost_cost(
|
|||
) -> InfluenceCultureInfo {
|
||||
let target_city_position = selected.position;
|
||||
let structure = &selected.structure;
|
||||
let target_city = game.get_any_city(target_city_position);
|
||||
let target_city = game.any_city(target_city_position);
|
||||
let target_player_index = target_city.player_index;
|
||||
|
||||
let attacker = game.get_player(player_index);
|
||||
let attacker = game.player(player_index);
|
||||
|
||||
let Some((starting_city_position, range_boost)) = start_city(game, player_index, target_city)
|
||||
else {
|
||||
|
|
@ -184,7 +184,7 @@ pub fn influence_culture_boost_cost(
|
|||
i.add_blocker("No starting city available");
|
||||
return i;
|
||||
};
|
||||
let starting_city = game.get_any_city(starting_city_position);
|
||||
let starting_city = game.any_city(starting_city_position);
|
||||
|
||||
let self_influence = starting_city_position == target_city_position;
|
||||
let target_city_owner = target_city.player_index;
|
||||
|
|
@ -194,7 +194,7 @@ pub fn influence_culture_boost_cost(
|
|||
Structure::Wonder(_) => panic!("Wonder is not allowed here"),
|
||||
};
|
||||
|
||||
let defender = game.get_player(target_player_index);
|
||||
let defender = game.player(target_player_index);
|
||||
let start_city_is_eligible = !starting_city.influenced() || self_influence;
|
||||
|
||||
let mut info = InfluenceCultureInfo::new(
|
||||
|
|
@ -203,14 +203,14 @@ pub fn influence_culture_boost_cost(
|
|||
target_city_position,
|
||||
structure.clone(),
|
||||
);
|
||||
let _ = attacker.trigger_event(
|
||||
attacker.trigger_event(
|
||||
|e| &e.on_influence_culture_attempt,
|
||||
&mut info,
|
||||
target_city,
|
||||
game,
|
||||
);
|
||||
info.is_defender = true;
|
||||
let _ = defender.trigger_event(
|
||||
defender.trigger_event(
|
||||
|e| &e.on_influence_culture_attempt,
|
||||
&mut info,
|
||||
target_city,
|
||||
|
|
@ -248,18 +248,18 @@ pub fn influence_culture_boost_cost(
|
|||
|
||||
fn influence_culture(game: &mut Game, influencer_index: usize, structure: &SelectedStructure) {
|
||||
let city_position = structure.position;
|
||||
let city_owner = game.get_any_city(city_position).player_index;
|
||||
let city_owner = game.any_city(city_position).player_index;
|
||||
match structure.structure {
|
||||
Structure::CityCenter => {
|
||||
let mut city = game
|
||||
.get_player_mut(city_owner)
|
||||
.player_mut(city_owner)
|
||||
.take_city(city_position)
|
||||
.expect("city should be taken");
|
||||
city.player_index = influencer_index;
|
||||
game.get_player_mut(influencer_index).cities.push(city);
|
||||
game.player_mut(influencer_index).cities.push(city);
|
||||
}
|
||||
Structure::Building(b) => game
|
||||
.get_player_mut(city_owner)
|
||||
.player_mut(city_owner)
|
||||
.get_city_mut(city_position)
|
||||
.pieces
|
||||
.set_building(b, influencer_index),
|
||||
|
|
@ -288,7 +288,7 @@ fn start_city(game: &Game, player_index: usize, target_city: &City) -> Option<(P
|
|||
if target_city.player_index == player_index {
|
||||
Some((target_city.position, 0))
|
||||
} else {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
let position = target_city.position;
|
||||
player
|
||||
.cities
|
||||
|
|
@ -310,7 +310,7 @@ pub(crate) fn format_cultural_influence_attempt_log_item(
|
|||
c: &SelectedStructure,
|
||||
) -> String {
|
||||
let target_city_position = c.position;
|
||||
let target_city = game.get_any_city(target_city_position);
|
||||
let target_city = game.any_city(target_city_position);
|
||||
let target_player_index = target_city.player_index;
|
||||
let starting_city_position = start_city(game, player_index, target_city)
|
||||
.expect("there should be a starting city")
|
||||
|
|
@ -338,5 +338,7 @@ pub(crate) fn format_cultural_influence_attempt_log_item(
|
|||
Structure::Building(b) => b.name(),
|
||||
Structure::Wonder(_) => panic!("Wonder is not allowed here"),
|
||||
};
|
||||
format!("{player_name} tried to influence culture the {city_piece} in the city at {target_city_position} by {player}{city}{cost}")
|
||||
format!(
|
||||
"{player_name} tried to influence culture the {city_piece} in the city at {target_city_position} by {player}{city}{cost}"
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -106,7 +106,7 @@ where
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn trigger(
|
||||
pub(crate) fn trigger_with_modifiers(
|
||||
&self,
|
||||
value: &mut T,
|
||||
info: &U,
|
||||
|
|
@ -116,6 +116,12 @@ where
|
|||
self.trigger_with_exclude(value, info, details, extra_value, &[])
|
||||
}
|
||||
|
||||
pub(crate) fn trigger(&self, value: &mut T, info: &U, details: &V, extra_value: &mut W) {
|
||||
for (listener, _, _, _) in &self.listeners {
|
||||
listener(value, info, details, extra_value);
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn trigger_with_exclude(
|
||||
&self,
|
||||
|
|
@ -153,7 +159,8 @@ where
|
|||
T: Clone + PartialEq,
|
||||
{
|
||||
let mut initial_value = value.clone();
|
||||
let initial_modifiers = self.trigger(&mut initial_value, info, details, extra_value);
|
||||
let initial_modifiers =
|
||||
self.trigger_with_modifiers(&mut initial_value, info, details, extra_value);
|
||||
// to see what's possible
|
||||
is_ok(&initial_value);
|
||||
|
||||
|
|
@ -234,7 +241,7 @@ mod tests {
|
|||
let mut item = 0;
|
||||
let addend = 2;
|
||||
let multiplier = 3;
|
||||
let modifiers = event.trigger(&mut item, &addend, &multiplier, &mut ());
|
||||
let modifiers = event.trigger_with_modifiers(&mut item, &addend, &multiplier, &mut ());
|
||||
assert_eq!(6, item);
|
||||
assert_eq!(
|
||||
vec![
|
||||
|
|
@ -247,7 +254,7 @@ mod tests {
|
|||
event.remove_listener_mut_by_key(&EventOrigin::Advance("multiply value".to_string()));
|
||||
let mut item = 0;
|
||||
let addend = 3;
|
||||
let modifiers = event.trigger(&mut item, &addend, &0, &mut ());
|
||||
let modifiers = event.trigger_with_modifiers(&mut item, &addend, &0, &mut ());
|
||||
assert_eq!(3, item);
|
||||
assert_eq!(
|
||||
vec![EventOrigin::Advance("add constant".to_string())],
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
use crate::ability_initializer::AbilityInitializerSetup;
|
||||
use crate::content::advances::NAVIGATION;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_phase_actions::{CurrentEventRequest, CurrentEventType, EventResponse};
|
||||
use crate::content::persistent_events::{
|
||||
EventResponse, PersistentEventRequest, PersistentEventType,
|
||||
};
|
||||
use crate::game::Game;
|
||||
use crate::map::{Block, BlockPosition, Map, Rotation, UnexploredBlock};
|
||||
use crate::movement::{move_units, stop_current_move};
|
||||
|
|
@ -143,11 +145,11 @@ pub(crate) fn ask_explore_resolution(
|
|||
player_index: usize,
|
||||
resolution_state: ExploreResolutionState,
|
||||
) {
|
||||
let _ = game.trigger_current_event(
|
||||
let _ = game.trigger_persistent_event(
|
||||
&[player_index],
|
||||
|events| &mut events.on_explore_resolution,
|
||||
|events| &mut events.explore_resolution,
|
||||
resolution_state,
|
||||
CurrentEventType::ExploreResolution,
|
||||
PersistentEventType::ExploreResolution,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -163,7 +165,7 @@ fn move_to_explored_tile(
|
|||
add_block_tiles_with_log(game, &block.position, &block.block, rotation);
|
||||
|
||||
if is_any_ship(game, player_index, units) && game.map.is_land(destination) {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
let used_navigation = player.has_advance(NAVIGATION)
|
||||
&& !player.get_unit(units[0]).position.is_neighbor(destination);
|
||||
|
||||
|
|
@ -183,7 +185,7 @@ fn move_to_explored_tile(
|
|||
}
|
||||
|
||||
pub fn is_any_ship(game: &Game, player_index: usize, units: &[u32]) -> bool {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
units.iter().any(|&id| p.get_unit(id).unit_type.is_ship())
|
||||
}
|
||||
|
||||
|
|
@ -273,11 +275,11 @@ pub(crate) fn explore_resolution() -> Builtin {
|
|||
"Explore Resolution",
|
||||
"Select a rotation for the unexplored tiles",
|
||||
)
|
||||
.add_current_event_listener(
|
||||
|e| &mut e.on_explore_resolution,
|
||||
.add_persistent_event_listener(
|
||||
|e| &mut e.explore_resolution,
|
||||
0,
|
||||
move |_game, _player_index, _player_name, _state| {
|
||||
Some(CurrentEventRequest::ExploreResolution)
|
||||
Some(PersistentEventRequest::ExploreResolution)
|
||||
},
|
||||
move |game, _player_index, player_name, action, _request, r| {
|
||||
let EventResponse::ExploreResolution(rotation) = action else {
|
||||
|
|
|
|||
|
|
@ -1,27 +1,26 @@
|
|||
use crate::ability_initializer::AbilityListeners;
|
||||
use crate::action_card::gain_action_card_from_pile;
|
||||
use crate::combat_roll::{CombatDieRoll, COMBAT_DIE_SIDES};
|
||||
use crate::combat_roll::{COMBAT_DIE_SIDES, CombatDieRoll};
|
||||
use crate::consts::{ACTIONS, NON_HUMAN_PLAYERS};
|
||||
use crate::content::civilizations::{BARBARIANS, PIRATES};
|
||||
use crate::content::custom_phase_actions::{
|
||||
CurrentEventHandler, CurrentEventPlayer, CurrentEventState, CurrentEventType,
|
||||
};
|
||||
use crate::content::effects::PermanentEffect;
|
||||
use crate::content::persistent_events::{
|
||||
PersistentEventHandler, PersistentEventPlayer, PersistentEventState, PersistentEventType,
|
||||
};
|
||||
use crate::content::{action_cards, advances, builtin, incidents};
|
||||
use crate::events::{Event, EventOrigin};
|
||||
use crate::log::{
|
||||
current_player_turn_log, current_player_turn_log_mut, ActionLogAge, ActionLogPlayer,
|
||||
ActionLogRound,
|
||||
ActionLogAge, ActionLogPlayer, ActionLogRound, current_player_turn_log,
|
||||
current_player_turn_log_mut,
|
||||
};
|
||||
use crate::movement::{CurrentMove, MoveState};
|
||||
use crate::movement::MoveState;
|
||||
use crate::pirates::get_pirates_player;
|
||||
use crate::player_events::{
|
||||
CurrentEvent, CurrentEventInfo, PersistentEvents, PlayerEvents, TransientEvents,
|
||||
PersistentEvent, PersistentEventInfo, PersistentEvents, PlayerEvents, TransientEvents,
|
||||
};
|
||||
use crate::resource::check_for_waste;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::status_phase::enter_status_phase;
|
||||
use crate::unit::UnitType;
|
||||
use crate::utils;
|
||||
use crate::utils::Rng;
|
||||
use crate::utils::Shuffle;
|
||||
|
|
@ -39,7 +38,7 @@ use std::vec;
|
|||
|
||||
pub struct Game {
|
||||
pub state: GameState,
|
||||
pub events: Vec<CurrentEventState>,
|
||||
pub events: Vec<PersistentEventState>,
|
||||
// in turn order starting from starting_player_index and wrapping around
|
||||
pub players: Vec<Player>,
|
||||
pub map: Map,
|
||||
|
|
@ -178,7 +177,7 @@ impl Game {
|
|||
}
|
||||
|
||||
for player_index in 0..player_amount {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
game.add_info_log_group(format!(
|
||||
"{} is playing as {}",
|
||||
p.get_name(),
|
||||
|
|
@ -290,17 +289,17 @@ impl Game {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_player(&self, player_index: usize) -> &Player {
|
||||
pub fn player(&self, player_index: usize) -> &Player {
|
||||
&self.players[player_index]
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn player_name(&self, player_index: usize) -> String {
|
||||
self.get_player(player_index).get_name()
|
||||
self.player(player_index).get_name()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_player_mut(&mut self, player_index: usize) -> &mut Player {
|
||||
pub fn player_mut(&mut self, player_index: usize) -> &mut Player {
|
||||
&mut self.players[player_index]
|
||||
}
|
||||
|
||||
|
|
@ -312,15 +311,15 @@ impl Game {
|
|||
///
|
||||
/// if you want to get an option instead, use `Player::get_city` function
|
||||
#[must_use]
|
||||
pub fn get_city(&self, player_index: usize, position: Position) -> &City {
|
||||
self.get_player(player_index).get_city(position)
|
||||
pub fn city(&self, player_index: usize, position: Position) -> &City {
|
||||
self.player(player_index).get_city(position)
|
||||
}
|
||||
|
||||
///
|
||||
/// # Panics
|
||||
/// Panics if the city does not exist
|
||||
#[must_use]
|
||||
pub fn get_any_city(&self, position: Position) -> &City {
|
||||
pub fn any_city(&self, position: Position) -> &City {
|
||||
self.try_get_any_city(position).expect("city not found")
|
||||
}
|
||||
|
||||
|
|
@ -340,33 +339,33 @@ impl Game {
|
|||
/// # Panics
|
||||
/// Panics if the player does not have events
|
||||
#[must_use]
|
||||
pub fn current_event(&self) -> &CurrentEventState {
|
||||
pub fn current_event(&self) -> &PersistentEventState {
|
||||
self.events.last().expect("state should exist")
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn current_event_mut(&mut self) -> &mut CurrentEventState {
|
||||
pub(crate) fn current_event_mut(&mut self) -> &mut PersistentEventState {
|
||||
self.events.last_mut().expect("state should exist")
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn current_event_handler(&self) -> Option<&CurrentEventHandler> {
|
||||
pub fn current_event_handler(&self) -> Option<&PersistentEventHandler> {
|
||||
self.events.last().and_then(|s| s.player.handler.as_ref())
|
||||
}
|
||||
|
||||
pub fn current_event_handler_mut(&mut self) -> Option<&mut CurrentEventHandler> {
|
||||
pub fn current_event_handler_mut(&mut self) -> Option<&mut PersistentEventHandler> {
|
||||
self.events
|
||||
.last_mut()
|
||||
.and_then(|s| s.player.handler.as_mut())
|
||||
}
|
||||
|
||||
pub(crate) fn trigger_current_event_with_listener<V>(
|
||||
pub(crate) fn trigger_persistent_event_with_listener<V>(
|
||||
&mut self,
|
||||
players: &[usize],
|
||||
event: fn(&mut PersistentEvents) -> &mut CurrentEvent<V>,
|
||||
event: fn(&mut PersistentEvents) -> &mut PersistentEvent<V>,
|
||||
listeners: &AbilityListeners,
|
||||
event_type: V,
|
||||
store_type: impl Fn(V) -> CurrentEventType,
|
||||
store_type: impl Fn(V) -> PersistentEventType,
|
||||
log: Option<&str>,
|
||||
next_player: fn(&mut V) -> (),
|
||||
) -> Option<V>
|
||||
|
|
@ -377,7 +376,7 @@ impl Game {
|
|||
listeners.init(self, *p);
|
||||
}
|
||||
|
||||
let result = self.trigger_current_event_ext(
|
||||
let result = self.trigger_persistent_event_ext(
|
||||
players,
|
||||
event,
|
||||
event_type,
|
||||
|
|
@ -393,26 +392,26 @@ impl Game {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn trigger_current_event<V>(
|
||||
pub(crate) fn trigger_persistent_event<V>(
|
||||
&mut self,
|
||||
players: &[usize],
|
||||
event: fn(&mut PersistentEvents) -> &mut CurrentEvent<V>,
|
||||
event: fn(&mut PersistentEvents) -> &mut PersistentEvent<V>,
|
||||
value: V,
|
||||
to_event_type: impl Fn(V) -> CurrentEventType,
|
||||
to_event_type: impl Fn(V) -> PersistentEventType,
|
||||
) -> Option<V>
|
||||
where
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
self.trigger_current_event_ext(players, event, value, to_event_type, None, |_| {})
|
||||
self.trigger_persistent_event_ext(players, event, value, to_event_type, None, |_| {})
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn trigger_current_event_ext<V>(
|
||||
pub(crate) fn trigger_persistent_event_ext<V>(
|
||||
&mut self,
|
||||
players: &[usize],
|
||||
event: fn(&mut PersistentEvents) -> &mut CurrentEvent<V>,
|
||||
event: fn(&mut PersistentEvents) -> &mut PersistentEvent<V>,
|
||||
mut value: V,
|
||||
to_event_type: impl Fn(V) -> CurrentEventType,
|
||||
to_event_type: impl Fn(V) -> PersistentEventType,
|
||||
log: Option<&str>,
|
||||
next_player: fn(&mut V) -> (),
|
||||
) -> Option<V>
|
||||
|
|
@ -429,18 +428,19 @@ impl Game {
|
|||
self.add_info_log_group(log.to_string());
|
||||
}
|
||||
self.events
|
||||
.push(CurrentEventState::new(players[0], current_event_type));
|
||||
.push(PersistentEventState::new(players[0], current_event_type));
|
||||
}
|
||||
|
||||
let event_index = self.events.len() - 1;
|
||||
|
||||
for player_index in Self::remaining_current_event_players(players, self.current_event()) {
|
||||
let info = CurrentEventInfo {
|
||||
for player_index in Self::remaining_persistent_event_players(players, self.current_event())
|
||||
{
|
||||
let info = PersistentEventInfo {
|
||||
player: player_index,
|
||||
};
|
||||
self.trigger_persistent_event_with_game_value(
|
||||
self.trigger_event_with_game_value(
|
||||
player_index,
|
||||
event,
|
||||
move |e| event(&mut e.persistent),
|
||||
&info,
|
||||
&(),
|
||||
&mut value,
|
||||
|
|
@ -452,8 +452,8 @@ impl Game {
|
|||
}
|
||||
let state = self.current_event_mut();
|
||||
state.players_used.push(player_index);
|
||||
if let Some(&p) = Self::remaining_current_event_players(players, state).first() {
|
||||
state.player = CurrentEventPlayer::new(p);
|
||||
if let Some(&p) = Self::remaining_persistent_event_players(players, state).first() {
|
||||
state.player = PersistentEventPlayer::new(p);
|
||||
next_player(&mut value);
|
||||
}
|
||||
}
|
||||
|
|
@ -461,7 +461,10 @@ impl Game {
|
|||
Some(value)
|
||||
}
|
||||
|
||||
fn remaining_current_event_players(players: &[usize], state: &CurrentEventState) -> Vec<usize> {
|
||||
fn remaining_persistent_event_players(
|
||||
players: &[usize],
|
||||
state: &PersistentEventState,
|
||||
) -> Vec<usize> {
|
||||
players
|
||||
.iter()
|
||||
.filter(|p| !state.players_used.contains(p))
|
||||
|
|
@ -469,25 +472,6 @@ impl Game {
|
|||
.collect_vec()
|
||||
}
|
||||
|
||||
fn trigger_persistent_event_with_game_value<U, V, W>(
|
||||
&mut self,
|
||||
player_index: usize,
|
||||
event: fn(&mut PersistentEvents) -> &mut Event<Game, U, V, W>,
|
||||
info: &U,
|
||||
details: &V,
|
||||
extra_value: &mut W,
|
||||
) where
|
||||
W: Clone + PartialEq,
|
||||
{
|
||||
self.trigger_event_with_game_value(
|
||||
player_index,
|
||||
move |e| event(&mut e.persistent),
|
||||
info,
|
||||
details,
|
||||
extra_value,
|
||||
);
|
||||
}
|
||||
|
||||
pub(crate) fn trigger_transient_event_with_game_value<U, V>(
|
||||
&mut self,
|
||||
player_index: usize,
|
||||
|
|
@ -515,7 +499,7 @@ impl Game {
|
|||
W: Clone + PartialEq,
|
||||
{
|
||||
let e = event(&mut self.players[player_index].events).take();
|
||||
let _ = e.trigger(self, info, details, extra_value);
|
||||
e.trigger(self, info, details, extra_value);
|
||||
event(&mut self.players[player_index].events).set(e);
|
||||
}
|
||||
|
||||
|
|
@ -602,11 +586,11 @@ impl Game {
|
|||
}
|
||||
|
||||
pub(crate) fn on_start_turn(&mut self) {
|
||||
let _ = self.trigger_current_event(
|
||||
let _ = self.trigger_persistent_event(
|
||||
&[self.current_player_index],
|
||||
|e| &mut e.on_turn_start,
|
||||
|e| &mut e.turn_start,
|
||||
(),
|
||||
|()| CurrentEventType::TurnStart,
|
||||
|()| PersistentEventType::TurnStart,
|
||||
);
|
||||
}
|
||||
|
||||
|
|
@ -672,7 +656,7 @@ impl Game {
|
|||
}
|
||||
|
||||
pub fn next_turn(&mut self) {
|
||||
self.get_player_mut(self.current_player_index).end_turn();
|
||||
self.player_mut(self.current_player_index).end_turn();
|
||||
for i in &mut current_player_turn_log_mut(self).items {
|
||||
i.undo.clear();
|
||||
i.civil_card_match = None;
|
||||
|
|
@ -726,7 +710,7 @@ impl Game {
|
|||
self.add_message("The game has ended");
|
||||
}
|
||||
|
||||
pub(crate) fn get_next_dice_roll(&mut self) -> CombatDieRoll {
|
||||
pub(crate) fn next_dice_roll(&mut self) -> CombatDieRoll {
|
||||
self.lock_undo(); // dice rolls are not undoable
|
||||
let dice_roll = if self.dice_roll_outcomes.is_empty() {
|
||||
self.rng.range(0, 12) as u8
|
||||
|
|
@ -760,11 +744,11 @@ impl Game {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn get_available_custom_actions(
|
||||
pub fn available_custom_actions(
|
||||
&self,
|
||||
player_index: usize,
|
||||
) -> Vec<(CustomActionType, EventOrigin)> {
|
||||
self.get_player(self.current_player_index)
|
||||
self.player(self.current_player_index)
|
||||
.custom_actions
|
||||
.clone()
|
||||
.into_iter()
|
||||
|
|
@ -783,35 +767,6 @@ impl Game {
|
|||
.expect("player should have this city");
|
||||
city.raze(self, player_index);
|
||||
}
|
||||
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if the player does not have the unit
|
||||
pub fn kill_unit(&mut self, unit_id: u32, player_index: usize, killer: Option<usize>) {
|
||||
let unit = self.players[player_index].remove_unit(unit_id);
|
||||
if matches!(unit.unit_type, UnitType::Leader) {
|
||||
let leader = self.players[player_index]
|
||||
.active_leader
|
||||
.take()
|
||||
.expect("A player should have an active leader when having a leader unit");
|
||||
Player::with_leader(&leader, self, player_index, |game, leader| {
|
||||
leader.listeners.deinit(game, player_index);
|
||||
});
|
||||
if let Some(killer) = killer {
|
||||
self.players[killer].captured_leaders.push(leader);
|
||||
}
|
||||
}
|
||||
if let GameState::Movement(m) = &mut self.state {
|
||||
if let CurrentMove::Fleet { units } = &mut m.current_move {
|
||||
units.retain(|&id| id != unit_id);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub fn set_player_index(&mut self, current_player_index: usize) {
|
||||
self.current_player_index = current_player_index;
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, PartialEq)]
|
||||
|
|
@ -819,7 +774,7 @@ pub struct GameData {
|
|||
state: GameState,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Vec::is_empty")]
|
||||
events: Vec<CurrentEventState>,
|
||||
events: Vec<PersistentEventState>,
|
||||
players: Vec<PlayerData>,
|
||||
map: MapData,
|
||||
starting_player_index: usize,
|
||||
|
|
|
|||
|
|
@ -1,7 +1,9 @@
|
|||
use std::{cmp::Ordering::*, mem};
|
||||
|
||||
use crate::action::execute_action;
|
||||
use crate::content::custom_phase_actions::{CurrentEventRequest, CurrentEventType, EventResponse};
|
||||
use crate::content::persistent_events::{
|
||||
EventResponse, PersistentEventRequest, PersistentEventType,
|
||||
};
|
||||
use crate::log::current_player_turn_log_mut;
|
||||
use crate::utils::Shuffle;
|
||||
use crate::{
|
||||
|
|
@ -114,7 +116,7 @@ pub fn strip_secret(mut game: Game, player_index: Option<usize>) -> Game {
|
|||
}
|
||||
game.map.strip_secret();
|
||||
for s in &mut game.events {
|
||||
if let CurrentEventType::CombatRoundStart(r) = &mut s.event_type {
|
||||
if let PersistentEventType::CombatRoundStart(r) = &mut s.event_type {
|
||||
if r.attacker_strength.tactics_card.is_some() {
|
||||
// defender shouldn't see attacker's tactics card
|
||||
r.attacker_strength.tactics_card = Some(0);
|
||||
|
|
@ -123,7 +125,7 @@ pub fn strip_secret(mut game: Game, player_index: Option<usize>) -> Game {
|
|||
let current_event_player = &mut s.player;
|
||||
if player_index != Some(current_event_player.index) {
|
||||
if let Some(handler) = &mut current_event_player.handler {
|
||||
if let CurrentEventRequest::SelectHandCards(c) = &mut handler.request {
|
||||
if let PersistentEventRequest::SelectHandCards(c) = &mut handler.request {
|
||||
// player shouldn't see other player's hand cards
|
||||
c.request.choices.clear();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,14 +2,14 @@ use crate::ability_initializer::{AbilityInitializerBuilder, AbilityListeners};
|
|||
use crate::ability_initializer::{AbilityInitializerSetup, SelectedChoice};
|
||||
use crate::action_card::ActionCard;
|
||||
use crate::barbarians::{barbarians_move, barbarians_spawn};
|
||||
use crate::card::{draw_card_from_pile, HandCard};
|
||||
use crate::card::{HandCard, draw_card_from_pile};
|
||||
use crate::city::MoodState;
|
||||
use crate::content::custom_phase_actions::{
|
||||
CurrentEventType, HandCardsRequest, PaymentRequest, PlayerRequest, PositionRequest,
|
||||
ResourceRewardRequest, SelectedStructure, StructuresRequest, UnitsRequest,
|
||||
};
|
||||
use crate::content::incidents;
|
||||
use crate::content::incidents::great_persons::GREAT_PERSON_OFFSET;
|
||||
use crate::content::persistent_events::{
|
||||
HandCardsRequest, PaymentRequest, PersistentEventType, PlayerRequest, PositionRequest,
|
||||
ResourceRewardRequest, SelectedStructure, StructuresRequest, UnitsRequest,
|
||||
};
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
use crate::map::Terrain;
|
||||
|
|
@ -197,7 +197,7 @@ impl IncidentBuilder {
|
|||
F: Fn(&mut Game, usize, &str, &mut IncidentInfo) + 'static + Clone,
|
||||
{
|
||||
self.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_incident,
|
||||
|event| &mut event.incident,
|
||||
priority,
|
||||
move |game, player_index, player_name, i| {
|
||||
if i.is_active(role, player_index) {
|
||||
|
|
@ -213,15 +213,15 @@ impl IncidentBuilder {
|
|||
role: IncidentTarget,
|
||||
priority: i32,
|
||||
request: impl Fn(&mut Game, usize, &mut IncidentInfo) -> Option<PositionRequest>
|
||||
+ 'static
|
||||
+ Clone,
|
||||
+ 'static
|
||||
+ Clone,
|
||||
gain_reward: impl Fn(&mut Game, &SelectedChoice<Vec<Position>>, &mut IncidentInfo)
|
||||
+ 'static
|
||||
+ Clone,
|
||||
+ 'static
|
||||
+ Clone,
|
||||
) -> Self {
|
||||
let f = self.new_filter(role, priority);
|
||||
self.add_position_request(
|
||||
|event| &mut event.on_incident,
|
||||
|event| &mut event.incident,
|
||||
priority,
|
||||
move |game, player_index, i| {
|
||||
if f.is_active(game, i, player_index) {
|
||||
|
|
@ -246,7 +246,7 @@ impl IncidentBuilder {
|
|||
) -> Self {
|
||||
let f = self.new_filter(role, priority);
|
||||
self.add_units_request(
|
||||
|event| &mut event.on_incident,
|
||||
|event| &mut event.incident,
|
||||
priority,
|
||||
move |game, player_index, i| {
|
||||
if f.is_active(game, i, player_index) {
|
||||
|
|
@ -267,13 +267,17 @@ impl IncidentBuilder {
|
|||
role: IncidentTarget,
|
||||
priority: i32,
|
||||
request: impl Fn(&mut Game, usize, &IncidentInfo) -> Option<StructuresRequest> + 'static + Clone,
|
||||
structures_selected: impl Fn(&mut Game, &SelectedChoice<Vec<SelectedStructure>>, &mut IncidentInfo)
|
||||
+ 'static
|
||||
+ Clone,
|
||||
structures_selected: impl Fn(
|
||||
&mut Game,
|
||||
&SelectedChoice<Vec<SelectedStructure>>,
|
||||
&mut IncidentInfo,
|
||||
)
|
||||
+ 'static
|
||||
+ Clone,
|
||||
) -> Self {
|
||||
let f = self.new_filter(role, priority);
|
||||
self.add_structures_request(
|
||||
|event| &mut event.on_incident,
|
||||
|event| &mut event.incident,
|
||||
priority,
|
||||
move |game, player_index, i| {
|
||||
if f.is_active(game, i, player_index) {
|
||||
|
|
@ -294,13 +298,13 @@ impl IncidentBuilder {
|
|||
role: IncidentTarget,
|
||||
priority: i32,
|
||||
request: impl Fn(&mut Game, usize, &IncidentInfo) -> Option<ResourceRewardRequest>
|
||||
+ 'static
|
||||
+ Clone,
|
||||
+ 'static
|
||||
+ Clone,
|
||||
gain_reward_log: impl Fn(&Game, &SelectedChoice<ResourcePile>) -> Vec<String> + 'static + Clone,
|
||||
) -> Self {
|
||||
let f = self.new_filter(role, priority);
|
||||
self.add_resource_request(
|
||||
|event| &mut event.on_incident,
|
||||
|event| &mut event.incident,
|
||||
priority,
|
||||
move |game, player_index, i| {
|
||||
if f.is_active(game, i, player_index) {
|
||||
|
|
@ -323,15 +327,15 @@ impl IncidentBuilder {
|
|||
role: IncidentTarget,
|
||||
priority: i32,
|
||||
request: impl Fn(&mut Game, usize, &mut IncidentInfo) -> Option<Vec<PaymentRequest>>
|
||||
+ 'static
|
||||
+ Clone,
|
||||
+ 'static
|
||||
+ Clone,
|
||||
gain_reward: impl Fn(&mut Game, &SelectedChoice<Vec<ResourcePile>>, &mut IncidentInfo)
|
||||
+ 'static
|
||||
+ Clone,
|
||||
+ 'static
|
||||
+ Clone,
|
||||
) -> Self {
|
||||
let f = self.new_filter(role, priority);
|
||||
self.add_payment_request_listener(
|
||||
|event| &mut event.on_incident,
|
||||
|event| &mut event.incident,
|
||||
priority,
|
||||
move |game, player_index, i| {
|
||||
if f.is_active(game, i, player_index) {
|
||||
|
|
@ -353,12 +357,12 @@ impl IncidentBuilder {
|
|||
priority: i32,
|
||||
request: impl Fn(&mut Game, usize, &IncidentInfo) -> Option<HandCardsRequest> + 'static + Clone,
|
||||
cards_selected: impl Fn(&mut Game, &SelectedChoice<Vec<HandCard>>, &mut IncidentInfo)
|
||||
+ 'static
|
||||
+ Clone,
|
||||
+ 'static
|
||||
+ Clone,
|
||||
) -> Self {
|
||||
let f = self.new_filter(role, priority);
|
||||
self.add_hand_card_request(
|
||||
|event| &mut event.on_incident,
|
||||
|event| &mut event.incident,
|
||||
priority,
|
||||
move |game, player_index, i| {
|
||||
if f.is_active(game, i, player_index) {
|
||||
|
|
@ -385,7 +389,7 @@ impl IncidentBuilder {
|
|||
let f = self.new_filter(target, priority);
|
||||
let d = description.to_string();
|
||||
self.add_player_request(
|
||||
|event| &mut event.on_incident,
|
||||
|event| &mut event.incident,
|
||||
priority,
|
||||
move |game, player_index, i| {
|
||||
if f.is_active(game, i, player_index) {
|
||||
|
|
@ -436,7 +440,7 @@ impl IncidentBuilder {
|
|||
target,
|
||||
10,
|
||||
move |game, player_index, i| {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
if p.has_advance("Myths") {
|
||||
let needed = amount(game, p, i);
|
||||
if needed == 0 {
|
||||
|
|
@ -484,7 +488,7 @@ impl IncidentBuilder {
|
|||
target,
|
||||
9,
|
||||
move |game, p, i| {
|
||||
let (cities, mut needed) = cities(game.get_player(p), game, i);
|
||||
let (cities, mut needed) = cities(game.player(p), game, i);
|
||||
needed -= i.player.myths_payment;
|
||||
|
||||
let action = match mood_modifier {
|
||||
|
|
@ -542,12 +546,12 @@ pub(crate) fn on_trigger_incident(game: &mut Game, mut info: IncidentInfo) {
|
|||
"A new game event has been triggered: {}",
|
||||
incident.name
|
||||
));
|
||||
info = match game.trigger_current_event_with_listener(
|
||||
info = match game.trigger_persistent_event_with_listener(
|
||||
&game.human_players(info.active_player),
|
||||
|events| &mut events.on_incident,
|
||||
|events| &mut events.incident,
|
||||
&incident.listeners,
|
||||
info,
|
||||
CurrentEventType::Incident,
|
||||
PersistentEventType::Incident,
|
||||
log.as_deref(),
|
||||
|i| i.player = IncidentPlayerInfo::new(),
|
||||
) {
|
||||
|
|
@ -558,7 +562,7 @@ pub(crate) fn on_trigger_incident(game: &mut Game, mut info: IncidentInfo) {
|
|||
if !game
|
||||
.events
|
||||
.iter()
|
||||
.any(|e| matches!(e.event_type, CurrentEventType::Incident(_)))
|
||||
.any(|e| matches!(e.event_type, PersistentEventType::Incident(_)))
|
||||
{
|
||||
if passed_to_player(game, &mut info) {
|
||||
continue;
|
||||
|
|
@ -618,7 +622,7 @@ fn exhausted_land(builder: IncidentBuilder) -> IncidentBuilder {
|
|||
IncidentTarget::ActivePlayer,
|
||||
BASE_EFFECT_PRIORITY,
|
||||
|game, player_index, _incident| {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
let positions = p
|
||||
.cities
|
||||
.iter()
|
||||
|
|
@ -678,10 +682,10 @@ pub(crate) fn decrease_mod_and_log(
|
|||
let name = &s.player_name;
|
||||
match mood_modifier {
|
||||
MoodModifier::Decrease => {
|
||||
game.get_player_mut(s.player_index)
|
||||
game.player_mut(s.player_index)
|
||||
.get_city_mut(pos)
|
||||
.decrease_mood_state();
|
||||
let mood_state = &game.get_player(s.player_index).get_city(pos).mood_state;
|
||||
let mood_state = &game.player(s.player_index).get_city(pos).mood_state;
|
||||
if s.actively_selected {
|
||||
game.add_info_log_item(&format!(
|
||||
"{name} selected to decrease the mood in city {pos} to {mood_state:?}",
|
||||
|
|
@ -694,9 +698,7 @@ pub(crate) fn decrease_mod_and_log(
|
|||
}
|
||||
MoodModifier::MakeAngry => {
|
||||
game.add_info_log_item(&format!("{name} made city {pos} Angry"));
|
||||
game.get_player_mut(s.player_index)
|
||||
.get_city_mut(pos)
|
||||
.mood_state = MoodState::Angry;
|
||||
game.player_mut(s.player_index).get_city_mut(pos).mood_state = MoodState::Angry;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -5,16 +5,11 @@ use crate::player::Player;
|
|||
|
||||
use super::collect::PositionCollection;
|
||||
use crate::action_card::CivilCardMatch;
|
||||
use crate::movement::{MoveUnits, MovementAction};
|
||||
use crate::playing_actions::{Collect, IncreaseHappiness, Recruit};
|
||||
use crate::unit::MoveUnits;
|
||||
use crate::{
|
||||
action::Action,
|
||||
game::Game,
|
||||
playing_actions::PlayingAction,
|
||||
position::Position,
|
||||
resource_pile::ResourcePile,
|
||||
unit::{MovementAction, Units},
|
||||
utils,
|
||||
action::Action, game::Game, playing_actions::PlayingAction, position::Position,
|
||||
resource_pile::ResourcePile, unit::Units, utils,
|
||||
};
|
||||
use itertools::Itertools;
|
||||
use json_patch::PatchOperation;
|
||||
|
|
@ -308,7 +303,9 @@ fn format_construct_log_item(
|
|||
let city_position = c.city_position;
|
||||
|
||||
let mood = format_mood_change(player, city_position);
|
||||
format!("{player_name} paid {payment} to construct a {city_piece:?} in the city at {city_position}{port_pos}{mood}")
|
||||
format!(
|
||||
"{player_name} paid {payment} to construct a {city_piece:?} in the city at {city_position}{port_pos}{mood}"
|
||||
)
|
||||
}
|
||||
|
||||
fn format_mood_change(player: &Player, city_position: Position) -> String {
|
||||
|
|
|
|||
|
|
@ -8,16 +8,59 @@ use crate::unit::Unit;
|
|||
use crate::utils;
|
||||
|
||||
use crate::consts::{ARMY_MOVEMENT_REQUIRED_ADVANCE, MOVEMENT_ACTIONS, SHIP_CAPACITY, STACK_LIMIT};
|
||||
use crate::content::incidents::great_diplomat::{diplomatic_relations_partner, DIPLOMAT_ID};
|
||||
use crate::content::action_cards::negotiation::negotiations_partner;
|
||||
use crate::content::incidents::great_diplomat::{DIPLOMAT_ID, diplomatic_relations_partner};
|
||||
use crate::game::GameState::Movement;
|
||||
use crate::game::{Game, GameState};
|
||||
use crate::player::Player;
|
||||
use crate::player_events::MoveInfo;
|
||||
use crate::position::Position;
|
||||
use crate::unit::{carried_units, get_current_move, MovementRestriction};
|
||||
use crate::unit::{carried_units, get_current_move};
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq)]
|
||||
pub struct MoveUnits {
|
||||
pub units: Vec<u32>,
|
||||
pub destination: Position,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "Option::is_none")]
|
||||
pub embark_carrier_id: Option<u32>,
|
||||
#[serde(default)]
|
||||
#[serde(skip_serializing_if = "ResourcePile::is_empty")]
|
||||
pub payment: ResourcePile,
|
||||
}
|
||||
|
||||
impl MoveUnits {
|
||||
#[must_use]
|
||||
pub fn new(
|
||||
units: Vec<u32>,
|
||||
destination: Position,
|
||||
embark_carrier_id: Option<u32>,
|
||||
payment: ResourcePile,
|
||||
) -> Self {
|
||||
Self {
|
||||
units,
|
||||
destination,
|
||||
embark_carrier_id,
|
||||
payment,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq)]
|
||||
pub enum MovementAction {
|
||||
Move(MoveUnits),
|
||||
Stop,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug, Hash)]
|
||||
pub enum MovementRestriction {
|
||||
Battle,
|
||||
Mountain,
|
||||
Forest,
|
||||
}
|
||||
|
||||
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug, Default)]
|
||||
pub enum CurrentMove {
|
||||
#[default]
|
||||
|
|
@ -96,7 +139,7 @@ pub(crate) fn move_units(
|
|||
to: Position,
|
||||
embark_carrier_id: Option<u32>,
|
||||
) {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
let from = p.get_unit(units[0]).position;
|
||||
let info = MoveInfo::new(player_index, units.to_vec(), from, to);
|
||||
game.trigger_transient_event_with_game_value(player_index, |e| &mut e.before_move, &info, &());
|
||||
|
|
@ -334,13 +377,13 @@ pub(crate) fn move_routes(
|
|||
base.extend(reachable_with_roads(player, units, game));
|
||||
}
|
||||
add_diplomatic_relations(player, game, &mut base);
|
||||
add_negotiations(player, game, &mut base);
|
||||
base
|
||||
}
|
||||
|
||||
fn add_diplomatic_relations(player: &Player, game: &Game, base: &mut Vec<MoveRoute>) {
|
||||
let partner = diplomatic_relations_partner(game, player.index);
|
||||
if let Some(partner) = partner {
|
||||
let partner = game.get_player(partner);
|
||||
if let Some(partner) = diplomatic_relations_partner(game, player.index) {
|
||||
let partner = game.player(partner);
|
||||
for r in base {
|
||||
if !partner.get_units(r.destination).is_empty() {
|
||||
r.cost.default += ResourcePile::culture_tokens(2);
|
||||
|
|
@ -350,6 +393,13 @@ fn add_diplomatic_relations(player: &Player, game: &Game, base: &mut Vec<MoveRou
|
|||
}
|
||||
}
|
||||
|
||||
fn add_negotiations(player: &Player, game: &Game, base: &mut Vec<MoveRoute>) {
|
||||
if let Some(partner) = negotiations_partner(game, player.index) {
|
||||
let partner = game.player(partner);
|
||||
base.retain(|r| partner.get_units(r.destination).is_empty());
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
fn reachable_with_roads(player: &Player, units: &[u32], game: &Game) -> Vec<MoveRoute> {
|
||||
let start = units.iter().find_map(|&id| {
|
||||
|
|
|
|||
|
|
@ -2,11 +2,11 @@ use crate::ability_initializer::AbilityInitializerSetup;
|
|||
use crate::barbarians;
|
||||
use crate::city::MoodState;
|
||||
use crate::content::builtin::Builtin;
|
||||
use crate::content::custom_phase_actions::{
|
||||
use crate::content::persistent_events::{
|
||||
PaymentRequest, PositionRequest, ResourceRewardRequest, UnitsRequest,
|
||||
};
|
||||
use crate::game::Game;
|
||||
use crate::incident::{IncidentBuilder, BASE_EFFECT_PRIORITY};
|
||||
use crate::incident::{BASE_EFFECT_PRIORITY, IncidentBuilder};
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::player::Player;
|
||||
use crate::player_events::IncidentTarget;
|
||||
|
|
@ -19,7 +19,7 @@ use itertools::Itertools;
|
|||
pub(crate) fn pirates_round_bonus() -> Builtin {
|
||||
Builtin::builder("Pirates bonus", "-")
|
||||
.add_resource_request(
|
||||
|event| &mut event.on_combat_round_end,
|
||||
|event| &mut event.combat_round_end,
|
||||
3,
|
||||
|game, player_index, r| {
|
||||
let c = &r.combat;
|
||||
|
|
@ -51,11 +51,11 @@ pub(crate) fn pirates_bonus() -> Builtin {
|
|||
"Select a reward for fighting the Pirates",
|
||||
)
|
||||
.add_resource_request(
|
||||
|event| &mut event.on_combat_end,
|
||||
|event| &mut event.combat_end,
|
||||
3,
|
||||
|game, player_index, i| {
|
||||
if game
|
||||
.get_player(i.opponent(player_index))
|
||||
.player(i.opponent(player_index))
|
||||
.civilization
|
||||
.is_pirates()
|
||||
{
|
||||
|
|
@ -88,7 +88,7 @@ pub(crate) fn pirates_spawn_and_raid(mut builder: IncidentBuilder) -> IncidentBu
|
|||
IncidentTarget::AllPlayers,
|
||||
BASE_EFFECT_PRIORITY + 2,
|
||||
|game, player_index, i| {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
if cities_with_adjacent_pirates(player, game).is_empty() {
|
||||
return None;
|
||||
}
|
||||
|
|
@ -125,7 +125,7 @@ pub(crate) fn pirates_spawn_and_raid(mut builder: IncidentBuilder) -> IncidentBu
|
|||
return None;
|
||||
}
|
||||
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
let choices = cities_with_adjacent_pirates(player, game)
|
||||
.into_iter()
|
||||
.filter(|&pos| !matches!(player.get_city(pos).mood_state, MoodState::Angry))
|
||||
|
|
@ -152,7 +152,7 @@ pub(crate) fn pirates_spawn_and_raid(mut builder: IncidentBuilder) -> IncidentBu
|
|||
"{} reduced Mood in the city at {}",
|
||||
s.player_name, pos
|
||||
));
|
||||
game.get_player_mut(s.player_index)
|
||||
game.player_mut(s.player_index)
|
||||
.get_city_mut(pos)
|
||||
.decrease_mood_state();
|
||||
},
|
||||
|
|
@ -161,7 +161,7 @@ pub(crate) fn pirates_spawn_and_raid(mut builder: IncidentBuilder) -> IncidentBu
|
|||
|
||||
fn remove_pirate_ships(builder: IncidentBuilder) -> IncidentBuilder {
|
||||
builder.add_units_request(
|
||||
|event| &mut event.on_incident,
|
||||
|event| &mut event.incident,
|
||||
BASE_EFFECT_PRIORITY + 5,
|
||||
|game, player_index, i| {
|
||||
if !i.is_active(IncidentTarget::ActivePlayer, player_index) {
|
||||
|
|
@ -191,11 +191,11 @@ fn remove_pirate_ships(builder: IncidentBuilder) -> IncidentBuilder {
|
|||
s.player_name,
|
||||
s.choice
|
||||
.iter()
|
||||
.map(|u| game.get_player(pirates).get_unit(*u).position.to_string())
|
||||
.map(|u| game.player(pirates).get_unit(*u).position.to_string())
|
||||
.join(", ")
|
||||
));
|
||||
for unit in &s.choice {
|
||||
game.get_player_mut(pirates).remove_unit(*unit);
|
||||
game.player_mut(pirates).remove_unit(*unit);
|
||||
}
|
||||
},
|
||||
)
|
||||
|
|
@ -207,7 +207,7 @@ fn place_pirate_ship(builder: IncidentBuilder, priority: i32, blockade: bool) ->
|
|||
priority,
|
||||
move |game, player_index, _i| {
|
||||
let pirates = get_pirates_player(game).index;
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
let mut sea_spaces = game
|
||||
.map
|
||||
.tiles
|
||||
|
|
@ -249,7 +249,7 @@ fn place_pirate_ship(builder: IncidentBuilder, priority: i32, blockade: bool) ->
|
|||
let pirate = get_pirates_player(game).index;
|
||||
let pos = s.choice[0];
|
||||
game.add_info_log_item(&format!("Pirates spawned a Pirate Ship at {pos}"));
|
||||
game.get_player_mut(pirate).add_unit(pos, UnitType::Ship);
|
||||
game.player_mut(pirate).add_unit(pos, UnitType::Ship);
|
||||
},
|
||||
)
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,7 +7,7 @@ use crate::events::{Event, EventOrigin};
|
|||
use crate::payment::PaymentOptions;
|
||||
use crate::player_events::{CostInfo, TransientEvents};
|
||||
use crate::resource::ResourceType;
|
||||
use crate::unit::{carried_units, UnitData, UnitType};
|
||||
use crate::unit::{UnitData, UnitType};
|
||||
use crate::{
|
||||
city::{City, CityData},
|
||||
city_pieces::Building::{self},
|
||||
|
|
@ -698,6 +698,11 @@ impl Player {
|
|||
self.next_unit_id += 1;
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn try_get_unit(&self, id: u32) -> Option<&Unit> {
|
||||
self.units.iter().find(|unit| unit.id == id)
|
||||
}
|
||||
|
||||
///
|
||||
/// # Panics
|
||||
/// Panics if unit does not exist
|
||||
|
|
@ -706,7 +711,7 @@ impl Player {
|
|||
self.units
|
||||
.iter()
|
||||
.find(|unit| unit.id == id)
|
||||
.expect("unit should exist")
|
||||
.unwrap_or_else(|| panic!("unit should exist {id}"))
|
||||
}
|
||||
|
||||
///
|
||||
|
|
@ -717,14 +722,11 @@ impl Player {
|
|||
self.units
|
||||
.iter_mut()
|
||||
.find(|unit| unit.id == id)
|
||||
.expect("unit should exist")
|
||||
.unwrap_or_else(|| panic!("unit should exist {id}"))
|
||||
}
|
||||
|
||||
pub(crate) fn remove_unit(&mut self, id: u32) -> Unit {
|
||||
for id in carried_units(id, self) {
|
||||
self.remove_unit(id);
|
||||
}
|
||||
|
||||
// carried units can be transferred to another ship - which has to be selected later
|
||||
self.units.remove(
|
||||
self.units
|
||||
.iter()
|
||||
|
|
@ -749,19 +751,17 @@ impl Player {
|
|||
.collect()
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub(crate) fn trigger_event<T, U, V>(
|
||||
&self,
|
||||
event: fn(&TransientEvents) -> &Event<T, U, V, ()>,
|
||||
value: &mut T,
|
||||
info: &U,
|
||||
details: &V,
|
||||
) -> Vec<EventOrigin>
|
||||
where
|
||||
) where
|
||||
T: Clone + PartialEq,
|
||||
{
|
||||
let e = event(&self.events.transient);
|
||||
e.get().trigger(value, info, details, &mut ())
|
||||
e.get().trigger(value, info, details, &mut ());
|
||||
}
|
||||
|
||||
pub(crate) fn trigger_cost_event<U, V>(
|
||||
|
|
@ -794,7 +794,7 @@ impl Player {
|
|||
|i, m| i.cost.modifiers = m,
|
||||
)
|
||||
} else {
|
||||
let m = event.trigger(&mut cost_info, info, details, &mut ());
|
||||
let m = event.trigger_with_modifiers(&mut cost_info, info, details, &mut ());
|
||||
cost_info.cost.modifiers = m;
|
||||
cost_info
|
||||
}
|
||||
|
|
|
|||
|
|
@ -4,7 +4,7 @@ use crate::barbarians::BarbariansEventState;
|
|||
use crate::collect::{CollectContext, CollectInfo};
|
||||
use crate::combat::Combat;
|
||||
use crate::combat_listeners::{CombatEnd, CombatRoundEnd, CombatRoundStart};
|
||||
use crate::content::custom_phase_actions::Structure;
|
||||
use crate::content::persistent_events::{KilledUnits, Structure};
|
||||
use crate::events::Event;
|
||||
use crate::explore::ExploreResolutionState;
|
||||
use crate::game::Game;
|
||||
|
|
@ -25,7 +25,7 @@ use num::Zero;
|
|||
use serde::{Deserialize, Serialize};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
|
||||
pub(crate) type CurrentEvent<V = ()> = Event<Game, CurrentEventInfo, (), V>;
|
||||
pub(crate) type PersistentEvent<V = ()> = Event<Game, PersistentEventInfo, (), V>;
|
||||
|
||||
#[derive(Default)]
|
||||
pub(crate) struct PlayerEvents {
|
||||
|
|
@ -52,28 +52,28 @@ pub(crate) struct TransientEvents {
|
|||
}
|
||||
|
||||
#[derive(Default)]
|
||||
#[allow(clippy::struct_field_names)]
|
||||
pub(crate) struct PersistentEvents {
|
||||
pub on_collect: CurrentEvent<CollectInfo>,
|
||||
pub on_construct: CurrentEvent<Building>,
|
||||
pub on_draw_wonder_card: CurrentEvent,
|
||||
pub on_advance: CurrentEvent<AdvanceInfo>,
|
||||
pub on_recruit: CurrentEvent<Recruit>,
|
||||
pub on_influence_culture_resolution: CurrentEvent<ResourcePile>,
|
||||
pub on_explore_resolution: CurrentEvent<ExploreResolutionState>,
|
||||
pub on_play_action_card: CurrentEvent<ActionCardInfo>,
|
||||
pub on_play_wonder_card: CurrentEvent<WonderCardInfo>,
|
||||
pub collect: PersistentEvent<CollectInfo>,
|
||||
pub construct: PersistentEvent<Building>,
|
||||
pub draw_wonder_card: PersistentEvent,
|
||||
pub advance: PersistentEvent<AdvanceInfo>,
|
||||
pub recruit: PersistentEvent<Recruit>,
|
||||
pub influence_culture_resolution: PersistentEvent<ResourcePile>,
|
||||
pub explore_resolution: PersistentEvent<ExploreResolutionState>,
|
||||
pub play_action_card: PersistentEvent<ActionCardInfo>,
|
||||
pub play_wonder_card: PersistentEvent<WonderCardInfo>,
|
||||
|
||||
pub on_status_phase: CurrentEvent<StatusPhaseState>,
|
||||
pub on_turn_start: CurrentEvent,
|
||||
pub on_incident: CurrentEvent<IncidentInfo>,
|
||||
pub on_combat_start: CurrentEvent<Combat>,
|
||||
pub on_combat_round_start: CurrentEvent<CombatRoundStart>,
|
||||
pub on_combat_round_start_reveal_tactics: CurrentEvent<CombatRoundStart>,
|
||||
pub on_combat_round_start_tactics: CurrentEvent<CombatRoundStart>,
|
||||
pub on_combat_round_end: CurrentEvent<CombatRoundEnd>,
|
||||
pub on_combat_round_end_tactics: CurrentEvent<CombatRoundEnd>,
|
||||
pub on_combat_end: CurrentEvent<CombatEnd>,
|
||||
pub status_phase: PersistentEvent<StatusPhaseState>,
|
||||
pub turn_start: PersistentEvent,
|
||||
pub incident: PersistentEvent<IncidentInfo>,
|
||||
pub combat_start: PersistentEvent<Combat>,
|
||||
pub combat_round_start: PersistentEvent<CombatRoundStart>,
|
||||
pub combat_round_start_reveal_tactics: PersistentEvent<CombatRoundStart>,
|
||||
pub combat_round_start_tactics: PersistentEvent<CombatRoundStart>,
|
||||
pub combat_round_end: PersistentEvent<CombatRoundEnd>,
|
||||
pub combat_round_end_tactics: PersistentEvent<CombatRoundEnd>,
|
||||
pub combat_end: PersistentEvent<CombatEnd>,
|
||||
pub units_killed: PersistentEvent<KilledUnits>,
|
||||
}
|
||||
|
||||
impl PlayerEvents {
|
||||
|
|
@ -102,7 +102,7 @@ impl ActionInfo {
|
|||
for l in self.log.iter().unique() {
|
||||
game.add_info_log_item(l);
|
||||
}
|
||||
let player = game.get_player_mut(self.player);
|
||||
let player = game.player_mut(self.player);
|
||||
for (k, v) in self.info.clone() {
|
||||
player.event_info.insert(k, v);
|
||||
}
|
||||
|
|
@ -241,7 +241,7 @@ pub struct AdvanceInfo {
|
|||
}
|
||||
|
||||
#[derive(Clone, PartialEq)]
|
||||
pub struct CurrentEventInfo {
|
||||
pub struct PersistentEventInfo {
|
||||
pub player: usize, // player currently handling the event
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -3,19 +3,19 @@ use serde::{Deserialize, Serialize};
|
|||
use crate::action_card::play_action_card;
|
||||
use crate::advance::gain_advance;
|
||||
use crate::city::MoodState;
|
||||
use crate::collect::{collect, PositionCollection};
|
||||
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;
|
||||
use crate::content::custom_phase_actions::SelectedStructure;
|
||||
use crate::content::persistent_events::SelectedStructure;
|
||||
use crate::cultural_influence::influence_culture_attempt;
|
||||
use crate::game::GameState;
|
||||
use crate::player::Player;
|
||||
use crate::player_events::PlayingActionInfo;
|
||||
use crate::recruit::{recruit, recruit_cost};
|
||||
use crate::unit::Units;
|
||||
use crate::wonder::{cities_for_wonder, on_play_wonder_card, WonderCardInfo, WonderDiscount};
|
||||
use crate::wonder::{WonderCardInfo, WonderDiscount, cities_for_wonder, on_play_wonder_card};
|
||||
use crate::{
|
||||
city::City, content::custom_actions::CustomAction, game::Game, position::Position,
|
||||
resource_pile::ResourcePile,
|
||||
|
|
@ -73,7 +73,7 @@ impl PlayingActionType {
|
|||
|
||||
self.action_type().is_available(game, player_index)?;
|
||||
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
|
||||
match self {
|
||||
PlayingActionType::Custom(c) => {
|
||||
|
|
@ -116,7 +116,7 @@ impl PlayingActionType {
|
|||
}
|
||||
|
||||
let mut possible = Ok(());
|
||||
let _ = p.trigger_event(
|
||||
p.trigger_event(
|
||||
|e| &e.is_playing_action_available,
|
||||
&mut possible,
|
||||
game,
|
||||
|
|
@ -160,44 +160,43 @@ pub enum PlayingAction {
|
|||
}
|
||||
|
||||
impl PlayingAction {
|
||||
///
|
||||
///
|
||||
/// # Panics
|
||||
///
|
||||
/// Panics if action is illegal
|
||||
pub fn execute(self, game: &mut Game, player_index: usize, redo: bool) {
|
||||
pub(crate) fn execute(
|
||||
self,
|
||||
game: &mut Game,
|
||||
player_index: usize,
|
||||
redo: bool,
|
||||
) -> Result<(), String> {
|
||||
use crate::construct;
|
||||
use PlayingAction::*;
|
||||
let playing_action_type = self.playing_action_type();
|
||||
if !redo {
|
||||
let _ = playing_action_type
|
||||
.is_available(game, player_index)
|
||||
.map_err(|e| panic!("{e}"));
|
||||
playing_action_type.is_available(game, player_index)?;
|
||||
}
|
||||
playing_action_type.action_type().pay(game, player_index);
|
||||
|
||||
match self {
|
||||
Advance { advance, payment } => {
|
||||
let a = get_advance(&advance);
|
||||
assert!(
|
||||
game.get_player(player_index).can_advance(&a),
|
||||
"Illegal action"
|
||||
);
|
||||
game.get_player(player_index)
|
||||
if !game.player(player_index).can_advance(&a) {
|
||||
return Err("Cannot advance".to_string());
|
||||
}
|
||||
game.player(player_index)
|
||||
.advance_cost(&a, Some(&payment))
|
||||
.pay(game, &payment);
|
||||
gain_advance(game, &advance, player_index, payment, true);
|
||||
}
|
||||
FoundCity { settler } => {
|
||||
let settler = game.players[player_index].remove_unit(settler);
|
||||
assert!(settler.can_found_city(game), "Illegal action");
|
||||
build_city(game.get_player_mut(player_index), settler.position);
|
||||
if !settler.can_found_city(game) {
|
||||
return Err("Cannot found city".to_string());
|
||||
}
|
||||
build_city(game.player_mut(player_index), settler.position);
|
||||
}
|
||||
Construct(c) => {
|
||||
construct::construct(game, player_index, &c);
|
||||
construct::construct(game, player_index, &c)?;
|
||||
}
|
||||
Collect(c) => {
|
||||
collect(game, player_index, &c);
|
||||
collect(game, player_index, &c)?;
|
||||
}
|
||||
Recruit(r) => {
|
||||
let player = &mut game.players[player_index];
|
||||
|
|
@ -211,7 +210,7 @@ impl PlayingAction {
|
|||
) {
|
||||
cost.pay(game, &r.payment);
|
||||
} else {
|
||||
panic!("Cannot pay for units")
|
||||
return Err("Cannot pay for units".to_string());
|
||||
}
|
||||
recruit(game, player_index, r);
|
||||
}
|
||||
|
|
@ -230,10 +229,11 @@ impl PlayingAction {
|
|||
);
|
||||
}
|
||||
Custom(custom_action) => {
|
||||
custom(game, player_index, custom_action);
|
||||
custom(game, player_index, custom_action)?;
|
||||
}
|
||||
EndTurn => game.next_turn(),
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
|
|
@ -262,7 +262,7 @@ pub struct ActionType {
|
|||
|
||||
impl ActionType {
|
||||
pub(crate) fn is_available(&self, game: &Game, player_index: usize) -> Result<(), String> {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
if !p.resources.has_at_least(&self.cost) {
|
||||
return Err("Not enough resources for action type".to_string());
|
||||
}
|
||||
|
|
@ -274,7 +274,7 @@ impl ActionType {
|
|||
}
|
||||
|
||||
pub(crate) fn pay(&self, game: &mut Game, player_index: usize) {
|
||||
let p = game.get_player_mut(player_index);
|
||||
let p = game.player_mut(player_index);
|
||||
let cost = self.cost.clone();
|
||||
p.lose_resources(cost.clone());
|
||||
if !self.free {
|
||||
|
|
@ -347,14 +347,14 @@ pub(crate) fn roll_boost_cost(roll: u8) -> ResourcePile {
|
|||
ResourcePile::culture_tokens(5 - roll as u32)
|
||||
}
|
||||
|
||||
fn custom(game: &mut Game, player_index: usize, custom_action: CustomAction) {
|
||||
fn custom(game: &mut Game, player_index: usize, custom_action: CustomAction) -> Result<(), String> {
|
||||
let c = custom_action.custom_action_type();
|
||||
if c.info().once_per_turn {
|
||||
game.players[player_index]
|
||||
.played_once_per_turn_actions
|
||||
.push(c);
|
||||
}
|
||||
custom_action.execute(game, player_index);
|
||||
custom_action.execute(game, player_index)
|
||||
}
|
||||
|
||||
pub(crate) fn build_city(player: &mut Player, position: Position) {
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
use crate::combat;
|
||||
use crate::consts::STACK_LIMIT;
|
||||
use crate::content::custom_phase_actions::CurrentEventType;
|
||||
use crate::content::persistent_events::PersistentEventType;
|
||||
use crate::game::Game;
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::player::Player;
|
||||
|
|
@ -8,9 +8,13 @@ use crate::player_events::CostInfo;
|
|||
use crate::playing_actions::Recruit;
|
||||
use crate::position::Position;
|
||||
use crate::resource_pile::ResourcePile;
|
||||
use crate::unit::{UnitType, Units};
|
||||
use crate::unit::{UnitType, Units, kill_units};
|
||||
|
||||
pub(crate) fn recruit(game: &mut Game, player_index: usize, r: Recruit) {
|
||||
for unit in &r.replaced_units {
|
||||
// kill separately, because they may be on different positions
|
||||
kill_units(game, &[*unit], player_index, None);
|
||||
}
|
||||
if let Some(leader_name) = &r.leader_name {
|
||||
if let Some(previous_leader) = game.players[player_index].active_leader.take() {
|
||||
Player::with_leader(
|
||||
|
|
@ -24,18 +28,7 @@ pub(crate) fn recruit(game: &mut Game, player_index: usize, r: Recruit) {
|
|||
}
|
||||
set_active_leader(game, leader_name.clone(), player_index);
|
||||
}
|
||||
let mut replaced_units_undo_context = Vec::new();
|
||||
for unit in &r.replaced_units {
|
||||
let player = game.get_player_mut(player_index);
|
||||
let u = player.remove_unit(*unit);
|
||||
if u.carrier_id.is_some_and(|c| r.replaced_units.contains(&c)) {
|
||||
// will be removed when the carrier is removed
|
||||
continue;
|
||||
}
|
||||
let unit = u.data(game.get_player(player_index));
|
||||
replaced_units_undo_context.push(unit);
|
||||
}
|
||||
let player = game.get_player_mut(player_index);
|
||||
let player = game.player_mut(player_index);
|
||||
let vec = r.units.clone().to_vec();
|
||||
player.units.reserve_exact(vec.len());
|
||||
for unit_type in vec {
|
||||
|
|
@ -60,17 +53,17 @@ fn set_active_leader(game: &mut Game, leader_name: String, player_index: usize)
|
|||
Player::with_leader(&leader_name, game, player_index, |game, leader| {
|
||||
leader.listeners.one_time_init(game, player_index);
|
||||
});
|
||||
game.get_player_mut(player_index).active_leader = Some(leader_name);
|
||||
game.player_mut(player_index).active_leader = Some(leader_name);
|
||||
}
|
||||
|
||||
pub(crate) fn on_recruit(game: &mut Game, player_index: usize, r: Recruit) {
|
||||
let city_position = r.city_position;
|
||||
if game
|
||||
.trigger_current_event(
|
||||
.trigger_persistent_event(
|
||||
&[player_index],
|
||||
|events| &mut events.on_recruit,
|
||||
|events| &mut events.recruit,
|
||||
r,
|
||||
CurrentEventType::Recruit,
|
||||
PersistentEventType::Recruit,
|
||||
)
|
||||
.is_none()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -2,13 +2,13 @@ use crate::ability_initializer::AbilityInitializerSetup;
|
|||
use crate::action_card::gain_action_card_from_pile;
|
||||
use crate::advance::{do_advance, gain_advance, remove_advance};
|
||||
use crate::consts::AGES;
|
||||
use crate::content::builtin::{status_phase_handler, Builtin};
|
||||
use crate::content::custom_phase_actions::{
|
||||
AdvanceRequest, ChangeGovernmentRequest, CurrentEventRequest, CurrentEventType, EventResponse,
|
||||
PlayerRequest, PositionRequest,
|
||||
use crate::content::builtin::{Builtin, status_phase_handler};
|
||||
use crate::content::persistent_events::{
|
||||
AdvanceRequest, ChangeGovernmentRequest, EventResponse, PersistentEventRequest,
|
||||
PersistentEventType, PlayerRequest, PositionRequest,
|
||||
};
|
||||
use crate::payment::PaymentOptions;
|
||||
use crate::player_events::{CurrentEvent, PersistentEvents};
|
||||
use crate::player_events::{PersistentEvent, PersistentEvents};
|
||||
use crate::{content::advances, game::Game, player::Player, resource_pile::ResourcePile, utils};
|
||||
use itertools::Itertools;
|
||||
use serde::{Deserialize, Serialize};
|
||||
|
|
@ -40,12 +40,9 @@ pub const CHANGE_GOVERNMENT_COST: ResourcePile = ResourcePile::new(0, 0, 0, 0, 0
|
|||
|
||||
#[must_use]
|
||||
pub fn get_status_phase(game: &Game) -> Option<&StatusPhaseState> {
|
||||
game.events.iter().find_map(|e| {
|
||||
if let CurrentEventType::StatusPhase(s) = &e.event_type {
|
||||
Some(s)
|
||||
} else {
|
||||
None
|
||||
}
|
||||
game.events.iter().find_map(|e| match &e.event_type {
|
||||
PersistentEventType::StatusPhase(s) => Some(s),
|
||||
_ => None,
|
||||
})
|
||||
}
|
||||
|
||||
|
|
@ -61,12 +58,12 @@ pub(crate) fn play_status_phase(game: &mut Game, mut phase: StatusPhaseState) {
|
|||
use StatusPhaseState::*;
|
||||
|
||||
loop {
|
||||
phase = match game.trigger_current_event_with_listener(
|
||||
phase = match game.trigger_persistent_event_with_listener(
|
||||
&game.human_players(game.starting_player_index),
|
||||
|events| &mut events.on_status_phase,
|
||||
|events| &mut events.status_phase,
|
||||
&status_phase_handler(&phase).listeners,
|
||||
phase,
|
||||
CurrentEventType::StatusPhase,
|
||||
PersistentEventType::StatusPhase,
|
||||
None,
|
||||
|_| {},
|
||||
) {
|
||||
|
|
@ -95,7 +92,7 @@ pub(crate) fn play_status_phase(game: &mut Game, mut phase: StatusPhaseState) {
|
|||
&game
|
||||
.human_players(game.starting_player_index)
|
||||
.into_iter()
|
||||
.map(|p| game.get_player(p))
|
||||
.map(|p| game.player(p))
|
||||
.collect_vec(),
|
||||
)),
|
||||
DetermineFirstPlayer(_) => {
|
||||
|
|
@ -114,12 +111,12 @@ pub(crate) fn complete_objectives() -> Builtin {
|
|||
pub(crate) fn free_advance() -> Builtin {
|
||||
Builtin::builder("Free Advance", "Advance for free")
|
||||
.add_advance_request(
|
||||
|event| &mut event.on_status_phase,
|
||||
|event| &mut event.status_phase,
|
||||
0,
|
||||
|game, player_index, _player_name| {
|
||||
let choices = advances::get_all()
|
||||
.into_iter()
|
||||
.filter(|advance| game.get_player(player_index).can_advance_free(advance))
|
||||
.filter(|advance| game.player(player_index).can_advance_free(advance))
|
||||
.map(|a| a.name)
|
||||
.collect_vec();
|
||||
Some(AdvanceRequest::new(choices))
|
||||
|
|
@ -138,7 +135,7 @@ pub(crate) fn free_advance() -> Builtin {
|
|||
pub(crate) fn draw_cards() -> Builtin {
|
||||
Builtin::builder("Draw Cards", "-")
|
||||
.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_status_phase,
|
||||
|event| &mut event.status_phase,
|
||||
0,
|
||||
|game, p, _name, _s| {
|
||||
gain_action_card_from_pile(game, p);
|
||||
|
|
@ -151,10 +148,10 @@ pub(crate) fn draw_cards() -> Builtin {
|
|||
pub(crate) fn raze_city() -> Builtin {
|
||||
Builtin::builder("Raze city", "Raze size 1 city for 1 gold")
|
||||
.add_position_request(
|
||||
|event| &mut event.on_status_phase,
|
||||
|event| &mut event.status_phase,
|
||||
0,
|
||||
|game, player_index, _player_name| {
|
||||
let player = game.get_player(player_index);
|
||||
let player = game.player(player_index);
|
||||
let cities = player
|
||||
.cities
|
||||
.iter()
|
||||
|
|
@ -191,7 +188,7 @@ pub(crate) fn raze_city() -> Builtin {
|
|||
pub(crate) fn may_change_government() -> Builtin {
|
||||
add_change_government(
|
||||
Builtin::builder("Change Government", "Change your government"),
|
||||
|event| &mut event.on_status_phase,
|
||||
|event| &mut event.status_phase,
|
||||
true,
|
||||
CHANGE_GOVERNMENT_COST,
|
||||
)
|
||||
|
|
@ -205,24 +202,24 @@ pub(crate) fn add_change_government<A, E, V>(
|
|||
cost: ResourcePile,
|
||||
) -> A
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<V> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<V> + 'static + Clone,
|
||||
A: AbilityInitializerSetup,
|
||||
V: Clone + PartialEq,
|
||||
{
|
||||
let cost2 = cost.clone();
|
||||
a.add_current_event_listener(
|
||||
a.add_persistent_event_listener(
|
||||
event,
|
||||
0,
|
||||
move |game, player_index, _, _| {
|
||||
let p = game.get_player(player_index);
|
||||
let p = game.player(player_index);
|
||||
(can_change_government_for_free(p)
|
||||
&& p.can_afford(&PaymentOptions::resources(cost.clone())))
|
||||
.then_some(CurrentEventRequest::ChangeGovernment(
|
||||
.then_some(PersistentEventRequest::ChangeGovernment(
|
||||
ChangeGovernmentRequest::new(optional, cost.clone()),
|
||||
))
|
||||
},
|
||||
move |game, player_index, player_name, action, request, _| {
|
||||
if let CurrentEventRequest::ChangeGovernment(r) = &request {
|
||||
if let PersistentEventRequest::ChangeGovernment(r) = &request {
|
||||
if let EventResponse::ChangeGovernmentType(t) = action {
|
||||
match t {
|
||||
ChangeGovernmentType::ChangeGovernment(c) => {
|
||||
|
|
@ -319,7 +316,7 @@ pub(crate) fn can_change_government_for_free(player: &Player) -> bool {
|
|||
pub(crate) fn determine_first_player() -> Builtin {
|
||||
Builtin::builder("Determine First Player", "Determine the first player")
|
||||
.add_player_request(
|
||||
|event| &mut event.on_status_phase,
|
||||
|event| &mut event.status_phase,
|
||||
0,
|
||||
|game, player_index, phase| {
|
||||
if let StatusPhaseState::DetermineFirstPlayer(want) = phase {
|
||||
|
|
|
|||
|
|
@ -5,13 +5,13 @@ use crate::action_card;
|
|||
use crate::action_card::ActionCard;
|
||||
use crate::advance::AdvanceBuilder;
|
||||
use crate::card::HandCard;
|
||||
use crate::combat::{update_combat_strength, Combat, CombatModifier};
|
||||
use crate::combat::{Combat, CombatModifier, update_combat_strength};
|
||||
use crate::combat_listeners::{CombatRoundEnd, CombatRoundStart, CombatStrength};
|
||||
use crate::content::action_cards;
|
||||
use crate::content::custom_phase_actions::HandCardsRequest;
|
||||
use crate::content::persistent_events::HandCardsRequest;
|
||||
use crate::events::EventOrigin;
|
||||
use crate::game::Game;
|
||||
use crate::player_events::{CurrentEvent, PersistentEvents};
|
||||
use crate::player_events::{PersistentEvent, PersistentEvents};
|
||||
use action_card::discard_action_card;
|
||||
use action_cards::get_action_card;
|
||||
|
||||
|
|
@ -157,25 +157,13 @@ impl TacticsCardBuilder {
|
|||
self
|
||||
}
|
||||
|
||||
pub(crate) fn add_veto_tactics_listener(
|
||||
self,
|
||||
priority: i32,
|
||||
listener: impl Fn(usize, &mut Game, &Combat, &mut CombatStrength) + Clone + 'static,
|
||||
) -> Self {
|
||||
self.add_combat_strength_listener(
|
||||
|event| &mut event.on_combat_round_start_reveal_tactics,
|
||||
priority,
|
||||
listener,
|
||||
)
|
||||
}
|
||||
|
||||
pub(crate) fn add_reveal_listener(
|
||||
self,
|
||||
priority: i32,
|
||||
listener: impl Fn(usize, &mut Game, &Combat, &mut CombatStrength) + Clone + 'static,
|
||||
) -> Self {
|
||||
self.add_combat_strength_listener(
|
||||
|event| &mut event.on_combat_round_start_tactics,
|
||||
|event| &mut event.combat_round_start_tactics,
|
||||
priority,
|
||||
listener,
|
||||
)
|
||||
|
|
@ -188,7 +176,7 @@ impl TacticsCardBuilder {
|
|||
listener: impl Fn(usize, &mut Game, &Combat, &mut CombatStrength) + Clone + 'static,
|
||||
) -> Self
|
||||
where
|
||||
E: Fn(&mut PersistentEvents) -> &mut CurrentEvent<CombatRoundStart> + 'static + Clone,
|
||||
E: Fn(&mut PersistentEvents) -> &mut PersistentEvent<CombatRoundStart> + 'static + Clone,
|
||||
{
|
||||
let target = self.target;
|
||||
let id = self.id;
|
||||
|
|
@ -210,7 +198,7 @@ impl TacticsCardBuilder {
|
|||
let target = self.target;
|
||||
let id = self.id;
|
||||
self.add_simple_persistent_event_listener(
|
||||
|event| &mut event.on_combat_round_end_tactics,
|
||||
|event| &mut event.combat_round_end_tactics,
|
||||
priority,
|
||||
move |game, p, _, s| {
|
||||
if s.is_active(p, id, target) {
|
||||
|
|
@ -247,7 +235,7 @@ impl AbilityInitializerSetup for TacticsCardBuilder {
|
|||
|
||||
pub(crate) fn play_tactics_card(b: AdvanceBuilder) -> AdvanceBuilder {
|
||||
b.add_hand_card_request(
|
||||
|e| &mut e.on_combat_round_start,
|
||||
|e| &mut e.combat_round_start,
|
||||
0,
|
||||
|game, player, s| {
|
||||
let cards = available_tactics_cards(game, player, &s.combat);
|
||||
|
|
@ -300,35 +288,36 @@ fn available_tactics_cards(game: &Game, player: usize, combat: &Combat) -> Vec<H
|
|||
}
|
||||
|
||||
fn can_play_tactics_card(game: &Game, player: usize, card: &ActionCard, combat: &Combat) -> bool {
|
||||
if let Some(card) = &card.tactics_card {
|
||||
let position_met = card
|
||||
.role_requirement
|
||||
.as_ref()
|
||||
.is_none_or(|&r| combat.role(player) == r);
|
||||
match &card.tactics_card {
|
||||
Some(card) => {
|
||||
let position_met = card
|
||||
.role_requirement
|
||||
.as_ref()
|
||||
.is_none_or(|&r| combat.role(player) == r);
|
||||
|
||||
let fighter_met = card.fighter_requirement.is_empty()
|
||||
|| card.fighter_requirement.iter().any(|r| match r {
|
||||
FighterRequirement::Army => !combat.is_sea_battle(game),
|
||||
FighterRequirement::Fortress => {
|
||||
combat.defender_fortress(game) && combat.defender == player
|
||||
}
|
||||
FighterRequirement::Ship => combat.is_sea_battle(game),
|
||||
let fighter_met = card.fighter_requirement.is_empty()
|
||||
|| card.fighter_requirement.iter().any(|r| match r {
|
||||
FighterRequirement::Army => !combat.is_sea_battle(game),
|
||||
FighterRequirement::Fortress => {
|
||||
combat.defender_fortress(game) && combat.defender == player
|
||||
}
|
||||
FighterRequirement::Ship => combat.is_sea_battle(game),
|
||||
});
|
||||
|
||||
let location_met = card.location_requirement.as_ref().is_none_or(|l| match l {
|
||||
// city is also land!
|
||||
CombatLocation::City => combat.defender_city(game).is_some(),
|
||||
CombatLocation::Sea => combat.is_sea_battle(game),
|
||||
CombatLocation::Land => !combat.is_sea_battle(game),
|
||||
});
|
||||
|
||||
let location_met = card.location_requirement.as_ref().is_none_or(|l| match l {
|
||||
// city is also land!
|
||||
CombatLocation::City => combat.defender_city(game).is_some(),
|
||||
CombatLocation::Sea => combat.is_sea_battle(game),
|
||||
CombatLocation::Land => !combat.is_sea_battle(game),
|
||||
});
|
||||
let checker_met = card
|
||||
.checker
|
||||
.as_ref()
|
||||
.is_none_or(|c| c(player, game, combat));
|
||||
|
||||
let checker_met = card
|
||||
.checker
|
||||
.as_ref()
|
||||
.is_none_or(|c| c(player, game, combat));
|
||||
|
||||
position_met && fighter_met && location_met && checker_met
|
||||
} else {
|
||||
false
|
||||
position_met && fighter_met && location_met && checker_met
|
||||
}
|
||||
_ => false,
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
use crate::action::{add_log_item_from_action, execute_movement_action, Action};
|
||||
use crate::action::{Action, add_log_item_from_action, execute_movement_action};
|
||||
use crate::game::Game;
|
||||
use crate::log::{current_player_turn_log, current_player_turn_log_mut};
|
||||
use crate::resource::check_for_waste;
|
||||
use json_patch::{patch, PatchOperation};
|
||||
use json_patch::{PatchOperation, patch};
|
||||
use serde_json::Value;
|
||||
|
||||
const IGNORE_PATHS: [&str; 3] = ["/action_log/", "/action_log_index", "/log/"];
|
||||
|
|
@ -16,30 +16,31 @@ pub(crate) fn clean_patch(mut patch: Vec<PatchOperation>) -> Vec<PatchOperation>
|
|||
patch
|
||||
}
|
||||
|
||||
pub(crate) fn undo(mut game: Game) -> Game {
|
||||
pub(crate) fn undo(mut game: Game) -> Result<Game, String> {
|
||||
game.action_log_index -= 1;
|
||||
game.log.remove(game.log.len() - 1);
|
||||
|
||||
let l = &mut current_player_turn_log_mut(&mut game).items;
|
||||
let option = l
|
||||
.iter()
|
||||
.rposition(|a| !a.undo.is_empty())
|
||||
.expect("should have undoable action");
|
||||
let Some(i) = l.iter().rposition(|a| !a.undo.is_empty()) else {
|
||||
return Err("No undoable action".to_string());
|
||||
};
|
||||
|
||||
let item = l.get_mut(option).expect("should have undoable action");
|
||||
let item = l.get_mut(i).expect("should have undoable action");
|
||||
let p = std::mem::take(&mut item.undo);
|
||||
|
||||
match &item.action {
|
||||
Action::Undo => panic!("undo action can't be undone"),
|
||||
Action::Redo => panic!("redo action can't be undone"),
|
||||
Action::Undo => return Err("undo action can't be undone".to_string()),
|
||||
Action::Redo => return Err("redo action can't be undone".to_string()),
|
||||
_ => {}
|
||||
}
|
||||
|
||||
let mut v = to_serde_value(&game);
|
||||
|
||||
patch(&mut v, &p).expect("could not patch game data");
|
||||
patch(&mut v, &p).map_err(|e| format!("Failed to apply patch: {e}"))?;
|
||||
|
||||
Game::from_data(serde_json::from_value(v).expect("should be able to deserialize game"))
|
||||
Ok(Game::from_data(
|
||||
serde_json::from_value(v).map_err(|e| format!("Failed to deserialize game: {e}"))?,
|
||||
))
|
||||
}
|
||||
|
||||
pub(crate) fn to_serde_value(game: &Game) -> Value {
|
||||
|
|
@ -47,18 +48,17 @@ pub(crate) fn to_serde_value(game: &Game) -> Value {
|
|||
serde_json::from_str(&s).expect("game should be serializable")
|
||||
}
|
||||
|
||||
pub fn redo(game: &mut Game, player_index: usize) {
|
||||
pub fn redo(game: &mut Game, player_index: usize) -> Result<(), String> {
|
||||
let copy = current_player_turn_log(game).item(game).clone();
|
||||
add_log_item_from_action(game, ©.action);
|
||||
match ¤t_player_turn_log(game).item(game).action.clone() {
|
||||
Action::Playing(action) => action.clone().execute(game, player_index, true),
|
||||
Action::Movement(action) => {
|
||||
execute_movement_action(game, action.clone(), player_index);
|
||||
}
|
||||
Action::Movement(action) => execute_movement_action(game, action.clone(), player_index),
|
||||
Action::Response(action) => action.clone().redo(game, player_index),
|
||||
Action::Undo => panic!("undo action can't be redone"),
|
||||
Action::Redo => panic!("redo action can't be redone"),
|
||||
}
|
||||
Action::Undo => return Err("undo action can't be redone".to_string()),
|
||||
Action::Redo => return Err("redo action can't be redone".to_string()),
|
||||
}?;
|
||||
game.action_log_index += 1;
|
||||
check_for_waste(game);
|
||||
Ok(())
|
||||
}
|
||||
|
|
|
|||
Some files were not shown because too many files have changed in this diff Show more
Loading…
Add table
Add a link
Reference in a new issue