add collection cache (#216)

This commit is contained in:
Gregor Zeitlinger 2025-04-16 22:01:22 +02:00 • committed by GitHub
commit 8a03c47869
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
93 changed files with 1254 additions and 263 deletions

1
.gitignore vendored
View file

@ -6,5 +6,6 @@ wbindgen/
.history/
*.cmd/
*.result.json
failure*.json
game.json
node_modules/

118
client/Cargo.lock generated
View file

@ -29,6 +29,21 @@ version = "0.2.21"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "683d7910e743518b0e34f1186f92494becacb047c7b6bf616c96772180fef923"
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "anyhow"
version = "1.0.97"
@ -251,6 +266,20 @@ version = "0.2.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "613afe47fcd5fac7ccf1db93babcb082c5994d996f20b8b159f2ad1658eb5724"
[[package]]
name = "chrono"
version = "0.4.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-link",
]
[[package]]
name = "client"
version = "0.1.0"
@ -298,6 +327,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "cpp_demangle"
version = "0.4.4"
@ -716,6 +751,30 @@ dependencies = [
"tracing",
]
[[package]]
name = "iana-time-zone"
version = "0.1.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"log",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "icu_collections"
version = "1.5.0"
@ -1569,6 +1628,17 @@ dependencies = [
"getrandom 0.3.2",
]
[[package]]
name = "readonly"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2a62d85ed81ca5305dc544bd42c8804c5060b78ffa5ad3c64b0fb6a8c13d062"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.100",
]
[[package]]
name = "redox_syscall"
version = "0.5.11"
@ -1807,6 +1877,7 @@ name = "server"
version = "0.1.0"
dependencies = [
"async-std",
"chrono",
"console_error_panic_hook",
"hex2d",
"itertools 0.14.0",
@ -1815,6 +1886,7 @@ dependencies = [
"num_cpus",
"pathfinding",
"quad-rand",
"readonly",
"serde",
"serde-wasm-bindgen",
"serde_json",
@ -2314,6 +2386,41 @@ version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "712e227841d057c1ee1cd2fb22fa7e5a5461ae8e48fa2ca79ec42cfc1931183f"
[[package]]
name = "windows-core"
version = "0.61.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980"
dependencies = [
"windows-implement",
"windows-interface",
"windows-link",
"windows-result",
"windows-strings 0.4.0",
]
[[package]]
name = "windows-implement"
version = "0.60.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.100",
]
[[package]]
name = "windows-interface"
version = "0.59.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8"
dependencies = [
"proc-macro2",
"quote",
"syn 2.0.100",
]
[[package]]
name = "windows-link"
version = "0.1.1"
@ -2327,7 +2434,7 @@ source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4286ad90ddb45071efd1a66dfa43eb02dd0dfbae1545ad6cc3c51cf34d7e8ba3"
dependencies = [
"windows-result",
"windows-strings",
"windows-strings 0.3.1",
"windows-targets 0.53.0",
]
@ -2349,6 +2456,15 @@ dependencies = [
"windows-link",
]
[[package]]
name = "windows-strings"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-sys"
version = "0.52.0"

View file

@ -78,13 +78,10 @@ fn building_icons<'a>(rc: &'a RenderContext, city: &'a City) -> IconActionVec<'a
if !city.can_activate() || !rc.can_play_action(&PlayingActionType::Construct) {
return vec![];
}
let owner = rc.shown_player;
available_buildings(rc.game, rc.shown_player.index, city.position)
.into_iter()
.map(|(b, pos)| {
.map(|(b, cost_info, pos)| {
let name = b.name();
let cost_info = owner.construct_cost(rc.game, b, None);
let tooltip = format!(
"Built {}{} for {}{}",
name,
@ -106,6 +103,7 @@ fn building_icons<'a>(rc: &'a RenderContext, city: &'a City) -> IconActionVec<'a
city,
name,
ConstructionProject::Building(b, pos),
&cost_info,
),
))
}),

View file

@ -77,22 +77,23 @@ pub fn collect_dialog(rc: &RenderContext, collect: &CollectResources) -> StateUp
let game = rc.game;
let city = game.city(collect.player_index, collect.city_position);
let tooltip = get_total_collection(
let result = get_total_collection(
game,
collect.player_index,
collect.city_position,
&collect.collections,
true,
)
.map_or(
);
let tooltip = result.as_ref().map_or(
OkTooltip::Invalid("Too many resources selected".to_string()),
|i| OkTooltip::Valid(format!("Collect {}", i.total)),
);
let total = result.map_or(ResourcePile::empty(), |i| i.total);
if ok_button(rc, tooltip) {
let extra = collect.extra_resources();
let c = Collect::new(collect.city_position, collect.collections.clone());
let c = Collect::new(collect.city_position, collect.collections.clone(), total);
return StateUpdate::execute_activation(
collect_action(&collect.custom.action_type, c),

View file

@ -6,9 +6,9 @@ use server::action::Action;
use server::city::City;
use server::city_pieces::Building;
use server::construct::Construct;
use server::player_events::CostInfo;
use server::playing_actions::{PlayingAction, Recruit};
use server::position::Position;
use server::recruit::recruit_cost;
pub fn pay_construction_dialog(rc: &RenderContext, cp: &ConstructionPayment) -> StateUpdate {
let city = rc.game.get_any_city(cp.city_position);
@ -66,28 +66,13 @@ impl ConstructionPayment {
city: &City,
name: &str,
project: ConstructionProject,
cost: &CostInfo,
) -> ConstructionPayment {
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(
rc.shown_player,
&sel.amount.units,
city.position,
sel.amount.leader_name.as_ref(),
&sel.replaced_units,
None,
)
.unwrap(),
}
.cost;
let payment = rc.new_payment(&cost, name, false);
ConstructionPayment {
player_index: city.player_index,
city_position: city.position,
project,
payment,
payment: rc.new_payment(&cost.cost, name, false),
}
}
}

View file

@ -274,6 +274,15 @@ pub fn select_dialog(rc: &RenderContext, a: &RecruitAmount) -> StateUpdate {
fn open_dialog(rc: &RenderContext, city: Position, sel: RecruitSelection) -> StateUpdate {
let p = rc.shown_player.index;
let cost = recruit_cost(
rc.shown_player,
&sel.amount.units,
city,
sel.amount.leader_name.as_ref(),
&sel.replaced_units,
None,
)
.unwrap();
StateUpdate::OpenDialog(ActiveDialog::ConstructionPayment(ConstructionPayment::new(
rc,
rc.game.city(p, city),
@ -287,6 +296,7 @@ fn open_dialog(rc: &RenderContext, city: Position, sel: RecruitSelection) -> Sta
city
),
ConstructionProject::Units(sel),
&cost,
)))
}

146
server/Cargo.lock generated
View file

@ -17,6 +17,21 @@ version = "2.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "512761e0bb2578dd7380c6baaa0f4ce03e84f95e960231d1dec8bf4d7d6e2627"
[[package]]
name = "android-tzdata"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "e999941b234f3131b00bc13c22d06e8c5ff726d1b6318ac7eb276997bbb4fef0"
[[package]]
name = "android_system_properties"
version = "0.1.5"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "819e7219dbd41043ac279b19830f2efc897156490d7fd6ea916720117ee66311"
dependencies = [
"libc",
]
[[package]]
name = "async-channel"
version = "1.9.0"
@ -188,12 +203,35 @@ version = "1.10.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "d71b6127be86fdcfddb610f7182ac57211d4b18a3e9c82eb2d17662f2227ad6a"
[[package]]
name = "cc"
version = "1.2.19"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "8e3a13707ac958681c13b39b458c073d0d9bc8a22cb1b2f4c8e55eb72c13f362"
dependencies = [
"shlex",
]
[[package]]
name = "cfg-if"
version = "1.0.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "baf1de4339761588bc0619e3cbc0120ee582ebb74b53b4efbf79117bd2da40fd"
[[package]]
name = "chrono"
version = "0.4.40"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "1a7964611d71df112cb1730f2ee67324fcf4d0fc6606acbbe9bfe06df124637c"
dependencies = [
"android-tzdata",
"iana-time-zone",
"js-sys",
"num-traits",
"wasm-bindgen",
"windows-link",
]
[[package]]
name = "concurrent-queue"
version = "2.5.0"
@ -213,6 +251,12 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "core-foundation-sys"
version = "0.8.7"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "773648b94d0e5d620f64f280777445740e61fe701025087ec8b57f45c791888b"
[[package]]
name = "crossbeam-utils"
version = "0.8.21"
@ -367,6 +411,30 @@ dependencies = [
"serde_derive",
]
[[package]]
name = "iana-time-zone"
version = "0.1.63"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "b0c919e5debc312ad217002b8048a17b7d83f80703865bbfcfebb0458b0b27d8"
dependencies = [
"android_system_properties",
"core-foundation-sys",
"iana-time-zone-haiku",
"js-sys",
"log",
"wasm-bindgen",
"windows-core",
]
[[package]]
name = "iana-time-zone-haiku"
version = "0.1.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f31827a206f56af32e590ba56d5d2d085f558508192593743f16b2306495269f"
dependencies = [
"cc",
]
[[package]]
name = "indexmap"
version = "2.9.0"
@ -702,6 +770,17 @@ dependencies = [
"proc-macro2",
]
[[package]]
name = "readonly"
version = "0.2.13"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "f2a62d85ed81ca5305dc544bd42c8804c5060b78ffa5ad3c64b0fb6a8c13d062"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "redox_syscall"
version = "0.5.11"
@ -808,6 +887,7 @@ name = "server"
version = "0.1.0"
dependencies = [
"async-std",
"chrono",
"console_error_panic_hook",
"hex2d",
"itertools",
@ -816,6 +896,7 @@ dependencies = [
"num_cpus",
"pathfinding",
"quad-rand",
"readonly",
"serde",
"serde-wasm-bindgen",
"serde_json",
@ -824,6 +905,12 @@ dependencies = [
"wasm-bindgen-futures",
]
[[package]]
name = "shlex"
version = "1.3.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "0fda2ff0d084019ba4d7c6f371c95d8fd75ce3524c3cb8fb653a3023f6323e64"
[[package]]
name = "signal-hook-registry"
version = "1.4.2"
@ -1053,6 +1140,65 @@ dependencies = [
"wasm-bindgen",
]
[[package]]
name = "windows-core"
version = "0.61.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "4763c1de310c86d75a878046489e2e5ba02c649d185f21c67d4cf8a56d098980"
dependencies = [
"windows-implement",
"windows-interface",
"windows-link",
"windows-result",
"windows-strings",
]
[[package]]
name = "windows-implement"
version = "0.60.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "a47fddd13af08290e67f4acabf4b459f647552718f683a7b415d290ac744a836"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "windows-interface"
version = "0.59.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "bd9211b69f8dcdfa817bfd14bf1c97c9188afa36f4750130fcdf3f400eca9fa8"
dependencies = [
"proc-macro2",
"quote",
"syn",
]
[[package]]
name = "windows-link"
version = "0.1.1"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "76840935b766e1b0a05c0066835fb9ec80071d4c09a16f6bd5f7e655e3c14c38"
[[package]]
name = "windows-result"
version = "0.3.2"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "c64fd11a4fd95df68efcfee5f44a294fe71b8bc6a91993e2791938abcc712252"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-strings"
version = "0.4.0"
source = "registry+https://github.com/rust-lang/crates.io-index"
checksum = "7a2ba9642430ee452d5a7aa78d72907ebe8cfda358e8cb7918a2050581322f97"
dependencies = [
"windows-link",
]
[[package]]
name = "windows-sys"
version = "0.52.0"

View file

@ -30,3 +30,5 @@ json-patch = "4.0.0"
pathfinding = "4.14.0"
tokio = { version = "1.44.2", features = ["full"] }
num_cpus = "1.16.0"
readonly = "0.2.13"
chrono = "0.4.40"

View file

@ -1,4 +1,5 @@
use crate::card::HandCard;
use crate::collect::reset_collection_stats;
use crate::combat::{Combat, update_combat_strength};
use crate::combat_listeners::CombatStrength;
use crate::content::persistent_events::{
@ -124,6 +125,7 @@ impl AbilityInitializerBuilder {
}
}
#[must_use]
pub(crate) trait AbilityInitializerSetup: Sized {
fn builder(&mut self) -> &mut AbilityInitializerBuilder;
@ -180,6 +182,12 @@ pub(crate) trait AbilityInitializerSetup: Sized {
)
}
fn with_reset_collect_stats(self) -> Self {
self.add_one_time_ability_initializer(|game, player_index| {
reset_collection_stats(game.player_mut(player_index));
})
}
fn add_combat_round_start_listener(
self,
priority: i32,

View file

@ -1,7 +1,7 @@
use crate::action_card::on_play_action_card;
use crate::advance::on_advance;
use crate::city::{MoodState, on_found_city};
use crate::collect::on_collect;
use crate::collect::{on_collect, set_city_collections};
use crate::combat::{
combat_loop, move_with_possible_combat, on_capture_undefended_position, start_combat,
};
@ -153,6 +153,7 @@ fn execute_without_undo(
_ => execute_regular_action(&mut game, action, player_index),
}?;
check_for_waste(&mut game);
update_stats(&mut game);
if game
.player(player_index)
@ -366,3 +367,18 @@ pub(crate) fn execute_movement_action(
}
Ok(())
}
pub(crate) fn update_stats(game: &mut Game) {
let update = game
.players
.iter()
.flat_map(|p| {
p.cities
.iter()
.filter_map(|c| c.possible_collections.is_empty().then_some(c.position))
})
.collect_vec();
for p in update {
set_city_collections(game, p);
}
}

View file

@ -1,10 +1,7 @@
use crate::action::{Action, ActionType};
use crate::card::validate_card_selection;
use crate::city::{City, MoodState};
use crate::collect::{
CollectInfo, PositionCollection, add_collect, available_collect_actions, collect_action,
get_total_collection, possible_resource_collections,
};
use crate::collect::{available_collect_actions, collect_action};
use crate::construct::{Construct, available_buildings};
use crate::content::advances;
use crate::content::advances::economy::tax_options;
@ -22,11 +19,9 @@ use crate::happiness::{available_happiness_actions, happiness_action, increase_h
use crate::payment::PaymentOptions;
use crate::player::Player;
use crate::playing_actions::{
Collect, IncreaseHappiness, PlayingAction, PlayingActionType, Recruit, base_and_custom_action,
IncreaseHappiness, PlayingAction, PlayingActionType, Recruit, base_and_custom_action,
};
use crate::position::Position;
use crate::recruit::recruit_cost;
use crate::resource::ResourceType;
use crate::resource_pile::ResourcePile;
use crate::status_phase::{ChangeGovernment, ChangeGovernmentType, government_advances};
use crate::unit::{UnitType, Units};
@ -186,6 +181,10 @@ fn available_action_cards(game: &Game, p: &Player) -> Vec<Action> {
// todo great prophet is buggy
return None;
}
if *card == 13 || *card == 14 {
// todo mercenaries is buggy
return None;
}
if *card == 124 {
// todo great warlord needs movement to work
return None;
@ -249,9 +248,13 @@ fn collect_actions(p: &Player, game: &Game) -> Vec<Action> {
.iter()
.filter(|city| city.can_activate())
.flat_map(|city| {
city_collections(game, p, city)
.into_iter()
.map(|c| collect_action(&action_type, c))
city.possible_collections.iter().filter_map({
let value = action_type.clone();
move |c| {
p.can_gain(c.total.clone())
.then_some(collect_action(&value, c.clone()))
}
})
})
.collect_vec()
}
@ -376,8 +379,18 @@ fn responses(event: &PersistentEventState, player: &Player, game: &Game) -> Vec<
let h = event.player.handler.as_ref().expect("handler");
match h.request.clone() {
PersistentEventRequest::Payment(p) => {
let mut available = player.resources.clone();
vec![EventResponse::Payment(
p.into_iter().map(|p| payment(&p.cost, player)).collect(),
p.into_iter()
.map(|p| {
let o = &p.cost;
let pile = o
.first_valid_payment(&available)
.unwrap_or(ResourcePile::empty());
available -= pile.clone();
pile
})
.collect(),
)]
}
PersistentEventRequest::ResourceReward(r) => {
@ -516,101 +529,6 @@ fn select_multi<T: Clone>(
}
}
#[must_use]
pub fn city_collections(game: &Game, player: &Player, city: &City) -> Vec<Collect> {
let info = possible_resource_collections(game, city.position, player.index, &[], &[], false);
let all = ResourceType::all()
.into_iter()
.filter(|r| {
info.choices
.iter()
.any(|(_, choices)| choices.iter().any(|pile| pile.get(r) > 0))
&& can_gain_resource(player, *r)
})
.collect_vec();
let l = all.len();
all.into_iter()
.permutations(l)
.map(|priority| city_collection(game, player, city, &priority))
.unique_by(Collect::total)
.filter(|c| c.total().amount() > 0) // todo check earlier?
.collect_vec()
}
fn can_gain_resource(p: &Player, r: ResourceType) -> bool {
match r {
ResourceType::MoodTokens | ResourceType::CultureTokens => true,
_ => p.resources.get(&r) < p.resource_limit.get(&r),
}
}
fn city_collection(
game: &Game,
player: &Player,
city: &City,
priority: &[ResourceType],
) -> Collect {
let mut c: Vec<PositionCollection> = vec![];
loop {
let info = possible_resource_collections(game, city.position, player.index, &c, &c, false);
let Some((pos, pile)) = pick_resource(player, &info, &c, priority) else {
break;
};
let new = add_collect(&info, pos, &pile, &c);
if get_total_collection(game, player.index, city.position, &new, false).is_err() {
break;
}
c = new;
}
Collect::new(city.position, c)
}
fn pick_resource(
player: &Player,
info: &CollectInfo,
collected: &[PositionCollection],
priority: &[ResourceType],
) -> Option<(Position, ResourcePile)> {
let used = collected
.iter()
.chunk_by(|c| c.position)
.into_iter()
.map(|(p, group)| (p, group.map(|c| c.times).sum::<u32>()))
.collect_vec();
let available = info
.choices
.iter()
// .sorted_by_key(|(pos, _)| **pos)
.filter(|(pos, _)| {
let u = used
.iter()
.find_map(|(p, u)| (*p == **pos).then_some(*u))
.unwrap_or(0);
u < info.max_per_tile
})
.collect_vec();
priority.iter().find_map(|r| {
if !can_gain_resource(player, *r) {
return None;
}
available.iter().find_map(|(pos, choices)| {
choices
.iter()
.find_map(|pile| (pile.get(r) > 0).then_some((**pos, pile.clone())))
})
})
}
#[must_use]
fn calculate_influence(game: &Game, player: &Player) -> Option<SelectedStructure> {
available_influence_culture(game, player.index)
@ -625,7 +543,7 @@ fn construct(p: &Player, game: &Game) -> Vec<Action> {
p.cities
.iter()
.flat_map(|city| {
if city.can_activate() {
if !city.can_activate() {
return vec![];
}
get_construct_actions(game, p, city)
@ -636,14 +554,10 @@ fn construct(p: &Player, game: &Game) -> Vec<Action> {
pub(crate) fn get_construct_actions(game: &Game, p: &Player, city: &City) -> Vec<Action> {
available_buildings(game, p.index, city.position)
.iter()
.map(|(building, port)| {
.map(|(building, cost, port)| {
Action::Playing(PlayingAction::Construct(
Construct::new(
city.position,
*building,
payment(&p.construct_cost(game, *building, None).cost, p),
)
.with_port_position(*port),
Construct::new(city.position, *building, payment(&cost.cost, p))
.with_port_position(*port),
))
})
.collect()

View file

@ -1,5 +1,6 @@
use crate::ability_initializer::AbilityInitializerSetup;
use crate::city::City;
use crate::collect::reset_collect_within_range_for_all;
use crate::combat::move_with_possible_combat;
use crate::consts::STACK_LIMIT;
use crate::content::advances::theocracy::cities_that_can_add_units;
@ -372,6 +373,7 @@ fn add_barbarians_city(builder: IncidentBuilder) -> IncidentBuilder {
let p = game.player_mut(b);
p.cities.push(City::new(b, pos));
p.add_unit(pos, UnitType::Infantry);
reset_collect_within_range_for_all(game, pos);
},
)
}

View file

@ -3,6 +3,7 @@ use std::ops::{Add, Sub};
use crate::content::custom_actions::CustomActionType::ForcedLabor;
use crate::content::persistent_events::PersistentEventType;
use crate::playing_actions::Collect;
use crate::utils;
use crate::{
city_pieces::{CityPieces, CityPiecesData},
@ -13,14 +14,17 @@ use crate::{
use MoodState::*;
use num::Zero;
#[readonly::make]
pub struct City {
pub pieces: CityPieces,
#[readonly]
pub mood_state: MoodState,
pub activations: u32,
pub angry_activation: bool,
pub player_index: usize,
pub position: Position,
pub port_position: Option<Position>,
pub(crate) possible_collections: Vec<Collect>,
}
impl City {
@ -34,6 +38,7 @@ impl City {
player_index,
position: data.position,
port_position: data.port_position,
possible_collections: data.possible_collections,
}
}
@ -46,6 +51,7 @@ impl City {
self.angry_activation,
self.position,
self.port_position,
self.possible_collections,
)
}
@ -58,6 +64,7 @@ impl City {
self.angry_activation,
self.position,
self.port_position,
self.possible_collections.clone(),
)
}
@ -71,6 +78,7 @@ impl City {
player_index,
position,
port_position: None,
possible_collections: vec![],
}
}
@ -141,13 +149,20 @@ impl City {
Angry => Neutral,
};
self.angry_activation = false;
self.possible_collections.clear();
}
pub fn decrease_mood_state(&mut self) {
self.mood_state = match self.mood_state {
Happy => Neutral,
Neutral | Angry => Angry,
}
};
self.possible_collections.clear();
}
pub fn set_mood_state(&mut self, mood_state: MoodState) {
self.mood_state = mood_state;
self.possible_collections.clear();
}
#[must_use]
@ -175,6 +190,9 @@ pub struct CityData {
#[serde(skip_serializing_if = "Option::is_none")]
#[serde(default)]
port_position: Option<Position>,
#[serde(default)]
#[serde(skip_serializing)]
pub(crate) possible_collections: Vec<Collect>, // only for AI performance
}
impl CityData {
@ -186,6 +204,7 @@ impl CityData {
angry_activation: bool,
position: Position,
port_position: Option<Position>,
possible_collections: Vec<Collect>,
) -> Self {
Self {
city_pieces,
@ -194,6 +213,7 @@ impl CityData {
angry_activation,
position,
port_position,
possible_collections,
}
}
}

View file

@ -1,4 +1,7 @@
use crate::ability_initializer::AbilityInitializerSetup;
use crate::action::Action;
use crate::city::City;
use crate::content::builtin::Builtin;
use crate::content::custom_actions::{CustomAction, CustomActionType};
use crate::content::persistent_events::PersistentEventType;
use crate::events::EventOrigin;
@ -9,6 +12,7 @@ use crate::player::Player;
use crate::player_events::ActionInfo;
use crate::playing_actions::{Collect, PlayingAction, PlayingActionType, base_or_custom_available};
use crate::position::Position;
use crate::resource::ResourceType;
use crate::resource_pile::ResourcePile;
use itertools::Itertools;
use serde::{Deserialize, Serialize};
@ -65,7 +69,7 @@ pub fn get_total_collection(
return Err("Not your city".to_string());
}
let mut i = possible_resource_collections(
let i = possible_resource_collections(
game,
city_position,
player_index,
@ -75,7 +79,7 @@ pub fn get_total_collection(
);
if i.max_selection < tiles_used(collections) {
return Err(format!(
"You can only collect {} resources - got {}",
"You can only collect {} resources at {city_position} - got {}",
i.max_selection,
tiles_used(collections)
));
@ -102,17 +106,27 @@ pub fn get_total_collection(
}
}
collections
apply_total_collect(collections, player, i, game)
}
fn apply_total_collect(
collections: &[PositionCollection],
player: &Player,
mut i: CollectInfo,
game: &Game,
) -> Result<CollectInfo, String> {
let Some(total) = collections
.iter()
.cloned()
.map(|c| c.total())
.reduce(std::ops::Add::add)
.map(|pile| {
i.total = pile;
player.trigger_event(|e| &e.collect_total, &mut i, &(), &());
i
})
.ok_or("Nothing collected".to_string())
else {
return Err("Nothing collected".to_string());
};
i.total = total;
player.trigger_event(|e| &e.collect_total, &mut i, game, &());
Ok(i)
}
#[must_use]
@ -349,3 +363,138 @@ pub fn collect_action(action: &PlayingActionType, collect: Collect) -> Action {
_ => panic!("illegal type {action:?}"),
}
}
pub fn set_city_collections(game: &mut Game, city_position: Position) {
let city = game.get_any_city(city_position);
let player = city.player_index;
let p = city_collections_uncached(game, game.player(player), city);
game.player_mut(player)
.get_city_mut(city_position)
.possible_collections
.clone_from(&p);
}
#[must_use]
pub fn city_collections_uncached(game: &Game, player: &Player, city: &City) -> Vec<Collect> {
let info = possible_resource_collections(game, city.position, player.index, &[], &[], false);
let all = ResourceType::all()
.into_iter()
.filter(|r| {
info.choices
.iter()
.any(|(_, choices)| choices.iter().any(|pile| pile.get(r) > 0))
})
.collect_vec();
let l = all.len();
all.into_iter()
.permutations(l)
.filter_map(|priority| city_collection_uncached(game, player, city, &priority))
.unique_by(|c| c.total.clone())
.collect_vec()
}
fn city_collection_uncached(
game: &Game,
player: &Player,
city: &City,
priority: &[ResourceType],
) -> Option<Collect> {
let mut c: Vec<PositionCollection> = vec![];
loop {
let info = possible_resource_collections(game, city.position, player.index, &c, &c, false);
let Some((pos, pile)) = pick_resource(&info, &c, priority) else {
return apply_total_collect(&c, player, info, game)
.ok()
.map(|i| Collect::new(city.position, c, i.total));
};
c = add_collect(&info, pos, &pile, &c);
}
}
fn pick_resource(
info: &CollectInfo,
collected: &[PositionCollection],
priority: &[ResourceType],
) -> Option<(Position, ResourcePile)> {
if info.max_selection == tiles_used(collected) {
return None;
}
let used = collected
.iter()
.chunk_by(|c| c.position)
.into_iter()
.map(|(p, group)| (p, group.map(|c| c.times).sum::<u32>()))
.collect_vec();
let available = info
.choices
.iter()
// .sorted_by_key(|(pos, _)| **pos)
.filter(|(pos, _)| {
let u = used
.iter()
.find_map(|(p, u)| (*p == **pos).then_some(*u))
.unwrap_or(0);
u < info.max_per_tile
})
.collect_vec();
priority.iter().find_map(|r| {
available.iter().find_map(|(pos, choices)| {
choices
.iter()
.find_map(|pile| (pile.get(r) > 0).then_some((**pos, pile.clone())))
})
})
}
pub(crate) fn invalidate_collect_cache() -> Builtin {
Builtin::builder("InvalidateCollectCache", "-")
.add_transient_event_listener(
|event| &mut event.before_move,
1,
|game, i, ()| {
for p in &mut game.players {
if p.index != i.player {
reset_collect_within_range(p, i.from);
reset_collect_within_range(p, i.to);
}
}
},
)
.add_simple_persistent_event_listener(
|event| &mut event.found_city,
1,
|game, player, _, p| {
reset_collect_within_range(game.player_mut(player), *p);
},
)
.build()
}
pub(crate) fn reset_collect_within_range(p: &mut Player, position: Position) {
let has_husbandry = p.has_advance("Husbandry");
let range = if has_husbandry { 2 } else { 1 };
for c in &mut p.cities {
if c.position.distance(position) <= range {
c.possible_collections.clear();
}
}
}
pub(crate) fn reset_collect_within_range_for_all(game: &mut Game, pos: Position) {
for p in &mut game.players {
reset_collect_within_range(p, pos);
}
}
pub(crate) fn reset_collection_stats(p: &mut Player) {
for c in &mut p.cities {
c.possible_collections.clear();
}
}

View file

@ -343,7 +343,7 @@ pub(crate) fn conquer_city(
if take_over {
city.player_index = new_player_index;
city.mood_state = Angry;
city.set_mood_state(Angry);
if attacker_is_human {
for wonder in &city.pieces.wonders {
wonder.listeners.deinit(game, old_player_index);

View file

@ -5,6 +5,7 @@ use crate::content::persistent_events::PersistentEventType;
use crate::game::Game;
use crate::map::Terrain;
use crate::player::Player;
use crate::player_events::CostInfo;
use crate::position::Position;
use crate::resource_pile::ResourcePile;
use serde::{Deserialize, Serialize};
@ -43,7 +44,7 @@ pub fn can_construct(
building: Building,
player: &Player,
game: &Game,
) -> Result<(), String> {
) -> Result<CostInfo, String> {
can_construct_anything(city, player)?;
if !city.can_activate() {
return Err("Can't activate".to_string());
@ -64,11 +65,12 @@ pub fn can_construct(
if !player.is_building_available(building, game) {
return Err("All non-destroyed buildings are built".to_string());
}
if !player.can_afford(&player.construct_cost(game, building, None).cost) {
let cost_info = player.construct_cost(game, building, None);
if !player.can_afford(&cost_info.cost) {
// construct cost event listener?
return Err("Not enough resources".to_string());
}
Ok(())
Ok(cost_info)
}
pub(crate) fn can_construct_anything(city: &City, player: &Player) -> Result<(), String> {
@ -78,7 +80,7 @@ pub(crate) fn can_construct_anything(city: &City, player: &Player) -> Result<(),
if city.pieces.amount() >= MAX_CITY_SIZE {
return Err("City is full".to_string());
}
if city.pieces.amount() >= player.cities.len() {
if city.size() >= player.cities.len() {
return Err("Need more cities".to_string());
}
@ -88,8 +90,7 @@ pub(crate) fn can_construct_anything(city: &City, player: &Player) -> Result<(),
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));
can_construct(city, c.city_piece, player, game)?;
let cost = 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!(
@ -124,24 +125,27 @@ pub fn available_buildings(
game: &Game,
player: usize,
city: Position,
) -> Vec<(Building, Option<Position>)> {
) -> Vec<(Building, CostInfo, Option<Position>)> {
let player = game.player(player);
let city = player.get_city(city);
Building::all()
.into_iter()
.filter_map(|b| can_construct(city, b, player, game).ok().map(|()| b))
.flat_map(|b| new_building_positions(game, b, city))
.flat_map(|b| {
can_construct(city, b, player, game)
.map_or(Vec::new(), |i| new_building_positions(game, b, city, &i))
})
.collect()
}
#[must_use]
pub fn new_building_positions(
fn new_building_positions(
game: &Game,
building: Building,
city: &City,
) -> Vec<(Building, Option<Position>)> {
cost_info: &CostInfo,
) -> Vec<(Building, CostInfo, Option<Position>)> {
if building != Building::Port {
return vec![(building, None)];
return vec![(building, cost_info.clone(), None)];
}
game.map
@ -149,7 +153,7 @@ pub fn new_building_positions(
.iter()
.filter_map(|(p, t)| {
if *t == Terrain::Water && city.position.is_neighbor(*p) {
Some((building, Some(*p)))
Some((building, cost_info.clone(), Some(*p)))
} else {
None
}

View file

@ -1,5 +1,6 @@
use crate::ability_initializer::AbilityInitializerSetup;
use crate::action_card::ActionCard;
use crate::collect::reset_collection_stats;
use crate::content::action_cards::cultural_takeover::cultural_takeover;
use crate::content::action_cards::mercenaries::mercenaries;
use crate::content::builtin::Builtin;
@ -71,13 +72,14 @@ fn production_focus(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
.add_simple_persistent_event_listener(
|e| &mut e.play_action_card,
0,
|game, _player, _name, _| {
|game, player, _name, _| {
game.permanent_effects
.push(PermanentEffect::Collect(CollectEffect::ProductionFocus));
game.actions_left += 1; // to offset the action spent for collecting
game.add_info_log_item(
"Production Focus: You may collect multiple times from the same tile.",
);
reset_collection_stats(game.player_mut(player));
},
)
.build()
@ -122,10 +124,14 @@ pub(crate) fn collect_only() -> Builtin {
.add_simple_persistent_event_listener(
|event| &mut event.collect,
2,
|game, _, _, _| {
remove_element_by(&mut game.permanent_effects, |e| {
|game, player, _, _| {
if remove_element_by(&mut game.permanent_effects, |e| {
matches!(e, &PermanentEffect::Collect(_))
});
})
.is_some()
{
reset_collection_stats(game.player_mut(player));
}
},
)
.build()

View file

@ -34,7 +34,7 @@ pub(crate) fn mercenaries(id: u8, tactics_card: TacticsCardFactory) -> ActionCar
.tactics_card(tactics_card)
.add_position_request(
|e| &mut e.play_action_card,
100,
2,
|game, player, _| {
let p = game.player(player);
let r = barbarian_army_positions_in_range2(game, p);
@ -59,7 +59,7 @@ pub(crate) fn mercenaries(id: u8, tactics_card: TacticsCardFactory) -> ActionCar
)
.add_payment_request_listener(
|e| &mut e.play_action_card,
99,
1,
|_game, _player, a| {
Some(vec![PaymentRequest::new(
PaymentOptions::sum(
@ -93,9 +93,10 @@ pub(crate) fn mercenaries(id: u8, tactics_card: TacticsCardFactory) -> ActionCar
}
fn move_army(b: ActionCardBuilder, i: i32) -> ActionCardBuilder {
let src_prio = i * 3 + 2;
let dst_prio = i * 3 + 1;
let reinforce_prio = i * 3;
let base_prio = i * -5;
let src_prio = base_prio - 2;
let dst_prio = base_prio - 4;
let reinforce_prio = base_prio - 6;
let b = b
.add_position_request(
|e| &mut e.play_action_card,

View file

@ -2,6 +2,7 @@ use crate::ability_initializer::AbilityInitializerSetup;
use crate::action::Action;
use crate::action_card::ActionCard;
use crate::city::City;
use crate::collect::reset_collection_stats;
use crate::content::builtin::Builtin;
use crate::content::effects::{CollectEffect, PermanentEffect};
use crate::content::incidents::great_diplomat::{DiplomaticRelations, Negotiations};
@ -237,13 +238,14 @@ fn overproduction(id: u8, tactics_card: TacticsCardFactory) -> ActionCard {
.add_simple_persistent_event_listener(
|e| &mut e.play_action_card,
0,
|game, _player_index, player_name, _| {
|game, player_index, player_name, _| {
game.permanent_effects
.push(PermanentEffect::Collect(CollectEffect::Overproduction));
game.actions_left += 1; // to offset the action spent for collecting
game.add_info_log_item(&format!(
"{player_name} can use Overproduction to collect from 2 additional tiles."
));
reset_collection_stats(game.player_mut(player_index));
},
)
.build()

View file

@ -30,6 +30,7 @@ fn storage() -> AdvanceBuilder {
.add_one_time_ability_initializer(|game, player_index| {
game.players[player_index].resource_limit.food = 7;
})
.with_reset_collect_stats()
.with_advance_bonus(MoodToken)
}
@ -38,6 +39,7 @@ fn irrigation() -> AdvanceBuilder {
IRRIGATION,
"Your cities may Collect food from Barren spaces, Ignore Famine events",
)
.with_reset_collect_stats()
.add_transient_event_listener(
|event| &mut event.terrain_collect_options,
0,
@ -57,6 +59,7 @@ fn husbandry() -> AdvanceBuilder {
spaces away. This Advance can only be used once per turn.",
)
.with_advance_bonus(MoodToken)
.with_reset_collect_stats()
.add_once_per_turn_listener(
|event| &mut event.collect_options,
0,

View file

@ -1,4 +1,4 @@
use crate::ability_initializer::{AbilityInitializerSetup, do_once_per_turn};
use crate::ability_initializer::AbilityInitializerSetup;
use crate::advance::Bonus::{CultureToken, MoodToken};
use crate::advance::{Advance, AdvanceBuilder};
use crate::city_pieces::Building;
@ -41,27 +41,19 @@ fn public_education() -> AdvanceBuilder {
"Once per turn, when you collect resources in a city with an Academy, gain 1 idea",
)
.with_advance_bonus(MoodToken)
.add_simple_persistent_event_listener(
|event| &mut event.collect,
0,
|game, player_index, _player_name, i| {
do_once_per_turn(
"Public Education",
i,
game,
&(),
|i| &mut i.info.info,
move |i, game, ()| {
let player = game.player(player_index);
if player.get_city(i.city).pieces.academy.is_some() {
i.total += ResourcePile::ideas(1);
i.info
.log
.push("Public Education gained 1 idea".to_string());
}
},
);
.add_once_per_turn_listener(
|event| &mut event.collect_total,
1,
|i, game, ()| {
let city = game.get_any_city(i.city);
if city.pieces.academy.is_some() {
i.total += ResourcePile::ideas(1);
i.info
.log
.push("Public Education gained 1 idea".to_string());
}
},
|e| &mut e.info.info,
)
}

View file

@ -99,7 +99,7 @@ fn metallurgy() -> AdvanceBuilder {
.add_transient_event_listener(
|event| &mut event.collect_total,
0,
|i, (), ()| {
|i, _, ()| {
if i.total.ore >= 2 {
i.total.ore -= 1;
i.total.gold += 1;

View file

@ -18,6 +18,7 @@ pub(crate) fn seafaring() -> AdvanceGroup {
fn fishing() -> AdvanceBuilder {
Advance::builder("Fishing", "Your cities may Collect food from one Sea space")
.with_reset_collect_stats()
.add_transient_event_listener(|event| &mut event.collect_options, 1, fishing_collect)
.with_advance_bonus(MoodToken)
.with_unlocked_building(Port)

View file

@ -2,6 +2,7 @@ use crate::ability_initializer::AbilityInitializerSetup;
use crate::ability_initializer::{AbilityInitializerBuilder, AbilityListeners};
use crate::barbarians::barbarians_bonus;
use crate::cache;
use crate::collect::invalidate_collect_cache;
use crate::combat_listeners::{
choose_fighter_casualties, combat_stats, offer_retreat, place_settler,
};
@ -97,6 +98,7 @@ pub fn get_all_uncached() -> Vec<Builtin> {
build_wonder(),
choose_carried_units_to_remove(),
select_objectives(),
invalidate_collect_cache(),
// combat related
place_settler(),
choose_fighter_casualties(),

View file

@ -27,6 +27,7 @@ pub fn get_all() -> Vec<Civilization> {
vec![
// todo add other effects
SpecialAdvance::builder("Terrace", IRRIGATION)
.with_reset_collect_stats()
.add_transient_event_listener(
|events| &mut events.terrain_collect_options,
2,

View file

@ -208,7 +208,7 @@ fn great_artist() -> ActionCard {
));
game.player_mut(s.player_index)
.get_city_mut(position)
.mood_state = MoodState::Happy;
.set_mood_state(MoodState::Happy);
},
)
.build()

View file

@ -28,6 +28,7 @@ pub fn get_all_uncached() -> Vec<Wonder> {
PaymentOptions::resources(ResourcePile::new(5, 5, 2, 0, 0, 0, 5)),
vec![IRRIGATION],
)
.with_reset_collect_stats()
.add_transient_event_listener(
|events| &mut events.terrain_collect_options,
1,

View file

@ -1,4 +1,5 @@
use crate::ability_initializer::AbilityListeners;
use crate::action::update_stats;
use crate::combat_roll::{COMBAT_DIE_SIDES, CombatDieRoll};
use crate::consts::ACTIONS;
use crate::content::effects::PermanentEffect;
@ -113,6 +114,7 @@ impl Game {
for player in data.players {
Player::initialize_player(player, &mut game);
}
update_stats(&mut game);
game
}

View file

@ -1,3 +1,4 @@
use crate::action::update_stats;
use crate::action_card::gain_action_card_from_pile;
use crate::consts::{ACTIONS, NON_HUMAN_PLAYERS};
use crate::content::civilizations::{BARBARIANS, PIRATES};
@ -100,6 +101,7 @@ pub fn setup_game(player_amount: usize, seed: String, setup: bool) -> Game {
gain_objective_card_from_pile(&mut game, player_index);
}
update_stats(&mut game);
game.next_age();
game
}

View file

@ -4,6 +4,7 @@ use crate::action_card::ActionCard;
use crate::barbarians::{barbarians_move, barbarians_spawn};
use crate::card::{HandCard, draw_card_from_pile};
use crate::city::MoodState;
use crate::collect::reset_collect_within_range_for_all;
use crate::content::incidents;
use crate::content::incidents::great_persons::GREAT_PERSON_OFFSET;
use crate::content::persistent_events::{
@ -697,6 +698,7 @@ fn exhausted_land(builder: IncidentBuilder) -> IncidentBuilder {
));
let t = game.map.tiles.get_mut(&pos).expect("tile should exist");
*t = Terrain::Exhausted(Box::new(t.clone()));
reset_collect_within_range_for_all(game, pos);
},
)
}
@ -745,7 +747,9 @@ pub(crate) fn decrease_mod_and_log(
}
MoodModifier::MakeAngry => {
game.add_info_log_item(&format!("{name} made city {pos} Angry"));
game.player_mut(s.player_index).get_city_mut(pos).mood_state = MoodState::Angry;
game.player_mut(s.player_index)
.get_city_mut(pos)
.set_mood_state(MoodState::Angry);
}
}
}

View file

@ -3,8 +3,7 @@ use itertools::Itertools;
use serde::{Deserialize, Serialize};
use std::collections::HashMap;
use crate::city::City;
use crate::city::MoodState::Happy;
use crate::city::{City, MoodState};
use crate::consts::NON_HUMAN_PLAYERS;
use crate::player::Player;
use crate::position::Position;
@ -494,7 +493,7 @@ pub(crate) fn get_map_setup(player_count: usize) -> MapSetup {
pub fn setup_home_city(player: &mut Player, pos: Position) {
let mut city = City::new(player.index, pos);
city.mood_state = Happy;
city.set_mood_state(MoodState::Happy);
player.cities.push(city);
player.add_unit(pos, UnitType::Settler);
}

View file

@ -426,6 +426,17 @@ impl Player {
self.resources -= resources;
}
pub(crate) fn can_gain_resource(&self, r: ResourceType, amount: u32) -> bool {
match r {
ResourceType::MoodTokens | ResourceType::CultureTokens => true,
_ => self.resources.get(&r) + amount <= self.resource_limit.get(&r),
}
}
pub(crate) fn can_gain(&self, r: ResourcePile) -> bool {
r.into_iter().all(|(t, a)| self.can_gain_resource(t, a))
}
#[must_use]
pub fn can_advance_in_change_government(&self, advance: &Advance) -> bool {
if self.has_advance(&advance.name) {

View file

@ -58,7 +58,7 @@ pub(crate) struct TransientEvents {
pub terrain_collect_options: Event<HashMap<Terrain, HashSet<ResourcePile>>>,
pub collect_options: Event<CollectInfo, CollectContext, Game>,
pub collect_total: Event<CollectInfo>,
pub collect_total: Event<CollectInfo, Game>,
}
impl TransientEvents {

View file

@ -26,24 +26,22 @@ use crate::{
pub struct Collect {
pub city_position: Position,
pub collections: Vec<PositionCollection>,
pub total: ResourcePile,
}
impl Collect {
#[must_use]
pub fn new(city_position: Position, collections: Vec<PositionCollection>) -> Self {
pub fn new(
city_position: Position,
collections: Vec<PositionCollection>,
total: ResourcePile,
) -> Self {
Self {
city_position,
collections,
total,
}
}
#[must_use]
pub fn total(&self) -> ResourcePile {
self.collections
.iter()
.map(PositionCollection::total)
.fold(ResourcePile::empty(), |a, b| a + b)
}
}
#[derive(Serialize, Deserialize, Clone, PartialEq, Eq, Debug)]

View file

@ -310,6 +310,43 @@ impl Sum for ResourcePile {
}
}
impl IntoIterator for ResourcePile {
type Item = (ResourceType, u32);
type IntoIter = ResourceIntoIterator;
fn into_iter(self) -> Self::IntoIter {
ResourceIntoIterator {
pile: self,
index: 0,
}
}
}
pub struct ResourceIntoIterator {
pile: ResourcePile,
index: u8,
}
impl Iterator for ResourceIntoIterator {
type Item = (ResourceType, u32);
fn next(&mut self) -> Option<Self::Item> {
let index = self.index;
self.index += 1;
let p = &self.pile;
match index {
0 => Some((ResourceType::Food, p.food)),
1 => Some((ResourceType::Wood, p.wood)),
2 => Some((ResourceType::Ore, p.ore)),
3 => Some((ResourceType::Ideas, p.ideas)),
4 => Some((ResourceType::Gold, p.gold)),
5 => Some((ResourceType::MoodTokens, p.mood_tokens)),
6 => Some((ResourceType::CultureTokens, p.culture_tokens)),
_ => None,
}
}
}
impl Display for ResourcePile {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
let mut resources = Vec::new();

View file

@ -204,9 +204,9 @@ fn test_production_focus() {
.without_json_comparison(),
TestAction::undoable(
0,
Action::Playing(PlayingAction::Collect(playing_actions::Collect {
city_position: Position::from_offset("C2"),
collections: vec![
Action::Playing(PlayingAction::Collect(playing_actions::Collect::new(
Position::from_offset("C2"),
vec![
PositionCollection::new(Position::from_offset("B1"), ResourcePile::ore(1))
.times(2),
PositionCollection::new(
@ -216,7 +216,8 @@ fn test_production_focus() {
.times(2),
PositionCollection::new(Position::from_offset("C3"), ResourcePile::gold(1)),
],
})),
ResourcePile::mood_tokens(1) + ResourcePile::ore(1) + ResourcePile::gold(1),
))),
),
],
);
@ -321,9 +322,9 @@ fn test_overproduction() {
.without_json_comparison(),
TestAction::undoable(
0,
Action::Playing(PlayingAction::Collect(playing_actions::Collect {
city_position: Position::from_offset("C2"),
collections: vec![
Action::Playing(PlayingAction::Collect(playing_actions::Collect::new(
Position::from_offset("C2"),
vec![
PositionCollection::new(Position::from_offset("B1"), ResourcePile::ore(1)),
PositionCollection::new(Position::from_offset("B2"), ResourcePile::wood(1)),
PositionCollection::new(
@ -331,7 +332,8 @@ fn test_overproduction() {
ResourcePile::mood_tokens(1),
),
],
})),
ResourcePile::mood_tokens(1) + ResourcePile::ore(1) + ResourcePile::wood(1),
))),
),
],
);

View file

@ -257,13 +257,14 @@ fn test_forced_labor() {
TestAction::undoable(0, Action::Playing(Custom(ForcedLabor))),
TestAction::undoable(
0,
Action::Playing(Collect(playing_actions::Collect {
city_position: Position::from_offset("A1"),
collections: vec![
Action::Playing(Collect(playing_actions::Collect::new(
Position::from_offset("A1"),
vec![
PositionCollection::new(Position::from_offset("A1"), ResourcePile::food(1)),
PositionCollection::new(Position::from_offset("A2"), ResourcePile::wood(1)),
],
})),
ResourcePile::food(1) + ResourcePile::wood(1),
))),
),
],
);
@ -520,13 +521,14 @@ fn test_free_education() {
#[test]
fn test_collect_husbandry() {
let action = Action::Playing(Collect(playing_actions::Collect {
city_position: Position::from_offset("B3"),
collections: vec![PositionCollection::new(
let action = Action::Playing(Collect(playing_actions::Collect::new(
Position::from_offset("B3"),
vec![PositionCollection::new(
Position::from_offset("B5"),
ResourcePile::food(1),
)],
}));
ResourcePile::food(1),
)));
JSON.test(
"collect_husbandry",
vec![
@ -543,13 +545,14 @@ fn test_collect_free_economy() {
vec![TestAction::undoable(
0,
Action::Playing(Custom(CustomAction::FreeEconomyCollect(
playing_actions::Collect {
city_position: Position::from_offset("C2"),
collections: vec![
playing_actions::Collect::new(
Position::from_offset("C2"),
vec![
PositionCollection::new(Position::from_offset("B1"), ResourcePile::ore(1)),
PositionCollection::new(Position::from_offset("B2"), ResourcePile::ore(1)),
],
},
ResourcePile::ore(2),
),
))),
)],
);

View file

@ -1,8 +1,8 @@
use crate::common::JsonTest;
use itertools::Itertools;
use server::action::{Action, ActionType};
use server::ai_actions::{city_collections, get_available_actions};
use server::collect::PositionCollection;
use server::ai_actions::get_available_actions;
use server::collect::{PositionCollection, city_collections_uncached};
use server::playing_actions::{
Collect, IncreaseHappiness, PlayingAction, PlayingActionType, Recruit,
};
@ -20,17 +20,18 @@ const JSON: JsonTest = JsonTest::new("ai");
fn collect_city() {
let game = &JSON.load_game("collect");
let p = game.player(0);
let mut collect = city_collections(game, p, p.get_city(Position::from_offset("C2")));
let mut collect = city_collections_uncached(game, p, p.get_city(Position::from_offset("C2")));
for c in &mut collect {
c.collections.sort_by_key(|x| x.position);
}
assert_eq!(collect.len(), 2);
let got = collect.into_iter().map(|c| c.total()).collect_vec();
assert_eq!(collect.len(), 3);
let got = collect.into_iter().map(|c| c.total).collect_vec();
assert_eq!(
got,
vec![
ResourcePile::wood(1) + ResourcePile::gold(1),
ResourcePile::wood(1) + ResourcePile::mood_tokens(1),
ResourcePile::wood(1) + ResourcePile::food(2),
ResourcePile::food(1) + ResourcePile::wood(1) + ResourcePile::gold(1),
ResourcePile::food(1) + ResourcePile::wood(1) + ResourcePile::mood_tokens(1),
]
)
}
@ -64,14 +65,16 @@ fn all_actions() {
vec![PositionCollection::new(
Position::from_offset("E8"),
ResourcePile::wood(1)
)]
)],
ResourcePile::wood(1)
))),
Action::Playing(PlayingAction::Collect(Collect::new(
Position::from_offset("D8"),
vec![PositionCollection::new(
Position::from_offset("C8"),
ResourcePile::ore(1)
)]
)],
ResourcePile::ore(1)
)))
]
),

View file

@ -133,7 +133,7 @@ fn clean_json(expected: &str) -> String {
expected.replace([' ', '\t', '\n', '\r'], "")
}
fn write_result(actual: &str, result_path: &GamePath) {
pub(crate) fn write_result(actual: &str, result_path: &GamePath) {
let mut file = OpenOptions::new()
.write(true)
.create(true)
@ -355,7 +355,7 @@ fn assert_illegal_action(game: Game, player: usize, action: Action) {
assert!(err.is_err(), "execute action should panic");
}
fn to_json(game: &Game) -> String {
pub(crate) fn to_json(game: &Game) -> String {
serde_json::to_string_pretty(&game.cloned_data()).expect("game data should be serializable")
}

View file

@ -132,10 +132,11 @@ fn basic_actions() {
let tile_position = Position::new(1, 0);
game.map.tiles.insert(tile_position, Mountain);
game.map.tiles.insert(city_position, Fertile);
let collect_action = Action::Playing(Collect(playing_actions::Collect {
let collect_action = Action::Playing(Collect(playing_actions::Collect::new(
city_position,
collections: vec![PositionCollection::new(tile_position, ResourcePile::ore(1))],
}));
vec![PositionCollection::new(tile_position, ResourcePile::ore(1))],
ResourcePile::ore(1),
)));
let game = game_api::execute(game, collect_action, 0);
let player = &game.players[0];
assert_eq!(
@ -426,13 +427,14 @@ fn test_collect() {
"collect",
vec![TestAction::undoable(
0,
Action::Playing(Collect(playing_actions::Collect {
city_position: Position::from_offset("C2"),
collections: vec![
Action::Playing(Collect(playing_actions::Collect::new(
Position::from_offset("C2"),
vec![
PositionCollection::new(Position::from_offset("B1"), ResourcePile::ore(1)),
PositionCollection::new(Position::from_offset("B2"), ResourcePile::wood(1)),
],
})),
ResourcePile::ore(1) + ResourcePile::wood(1),
))),
)],
);
}

View file

@ -238,6 +238,13 @@ fn test_great_architect() {
.without_json_comparison(),
TestAction::undoable(0, Action::Playing(PlayingAction::ActionCard(155)))
.without_json_comparison(),
TestAction::undoable(
0,
Action::Response(EventResponse::SelectPositions(vec![Position::from_offset(
"A1",
)])),
)
.without_json_comparison(),
TestAction::undoable(
0,
Action::Response(EventResponse::Payment(vec![ResourcePile::new(

View file

@ -1,4 +1,6 @@
use crate::common::{GamePath, to_json, write_result};
use async_std::task;
use server::game::Game;
use server::{
action::{self, Action},
ai_actions,
@ -7,6 +9,9 @@ use server::{
playing_actions::PlayingAction,
utils::{Rng, Shuffle},
};
use std::panic::{AssertUnwindSafe, catch_unwind};
mod common;
const ITERATIONS: usize = 96;
@ -38,6 +43,7 @@ fn random_actions_iterations(mut rng: Rng) {
let seed = rng.range(0, 10_usize.pow(15)).to_string();
let mut game = game_setup::setup_game(2, seed, true);
game.supports_undo = false;
build_adjacent_cities(&mut game);
loop {
if matches!(game.state, GameState::Finished) {
break;
@ -52,6 +58,35 @@ fn random_actions_iterations(mut rng: Rng) {
let action = actions
.take_random_element(&mut rng)
.unwrap_or(Action::Playing(PlayingAction::EndTurn));
game = action::execute_action(game, action, player_index);
game = catch_unwind(AssertUnwindSafe(|| {
action::execute_action(game.clone(), action.clone(), player_index)
}))
.unwrap_or_else(move |e| {
use chrono::Utc;
let rfc_format = Utc::now().to_rfc3339();
let file = format!("failure{rfc_format}");
write_result(&to_json(&game), &GamePath::new(".", &file));
panic!("action {action:?}\nresult stored in {file}.json: {e:?}")
});
}
}
fn build_adjacent_cities(_game: &mut Game) {
// only until move works
// this way we can test constructing buildings
// todo makes it too slow
// for i in game.human_players(0) {
// let city = &game.player(i).cities[0];
// let pos = city
// .position
// .neighbors()
// .into_iter()
// .find(|p| game.map.get(*p) == Some(&Terrain::Barren))
// .expect("no barren space");
// game.player_mut(i).cities.push(City::new(i, pos));
// }
}

View file

@ -327,7 +327,7 @@
"origin": {
"CivilCard": 13
},
"priority": 79,
"priority": -9,
"request": {
"SelectPositions": {
"choices": [
@ -342,7 +342,7 @@
}
}
},
"last_priority_used": 79,
"last_priority_used": -9,
"player": 0
}
]

View file

@ -260,7 +260,12 @@
},
"times": 1
}
]
],
"total": {
"wood": 1,
"ore": 1,
"mood_tokens": 1
}
}
}
},

View file

@ -261,7 +261,12 @@
},
"times": 1
}
]
],
"total": {
"ore": 1,
"gold": 1,
"mood_tokens": 1
}
}
}
},

View file

@ -137,6 +137,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -136,6 +136,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -217,7 +217,10 @@
},
"times": 1
}
]
],
"total": {
"ore": 2
}
}
}
}

View file

@ -288,7 +288,10 @@
},
"times": 1
}
]
],
"total": {
"food": 1
}
}
}
},

View file

@ -183,6 +183,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -184,6 +184,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -228,6 +228,16 @@
"event_info": {
"State Religion": "used"
}
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -214,6 +214,16 @@
"event_info": {
"State Religion": "used"
}
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -191,6 +191,16 @@
"event_info": {
"State Religion": "used"
}
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -270,7 +270,11 @@
},
"times": 1
}
]
],
"total": {
"food": 1,
"wood": 1
}
}
}
},

View file

@ -184,6 +184,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -189,6 +189,16 @@
"event_info": {
"Priesthood": "used"
}
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -190,6 +190,16 @@
"event_info": {
"Priesthood": "used"
}
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -7,7 +7,7 @@
"food": 1,
"wood": 7,
"ore": 7,
"ideas": 5,
"ideas": 6,
"gold": 7,
"mood_tokens": 6,
"culture_tokens": 7
@ -215,7 +215,11 @@
},
"times": 1
}
]
],
"total": {
"wood": 1,
"ore": 1
}
}
}
},
@ -229,6 +233,11 @@
"op": "remove",
"path": "/players/0/cities/1/activations"
},
{
"op": "replace",
"path": "/players/0/resources/ideas",
"value": 5
},
{
"op": "replace",
"path": "/players/0/resources/wood",

View file

@ -131,6 +131,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -135,6 +135,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -26,6 +26,11 @@
"city_pieces": {},
"mood_state": "Happy",
"position": "A1"
},
{
"city_pieces": {},
"mood_state": "Happy",
"position": "A2"
}
],
"units": [

View file

@ -29,6 +29,11 @@
},
"mood_state": "Happy",
"position": "A1"
},
{
"city_pieces": {},
"mood_state": "Happy",
"position": "A2"
}
],
"units": [
@ -244,6 +249,50 @@
}
]
},
{
"action": {
"Response": {
"SelectPositions": [
"A1"
]
}
},
"undo": [
{
"op": "remove",
"path": "/events/1/event_type/WonderCard/selected_position"
},
{
"op": "replace",
"path": "/events/1/handler/priority",
"value": 11
},
{
"op": "add",
"path": "/events/1/handler/request/SelectPositions",
"value": {
"choices": [
"A1",
"A2"
],
"description": "Select city to build wonder",
"needed": {
"end": 1,
"start": 1
}
}
},
{
"op": "remove",
"path": "/events/1/handler/request/Payment"
},
{
"op": "replace",
"path": "/events/1/last_priority_used",
"value": 11
}
]
},
{
"action": {
"Response": {
@ -395,7 +444,7 @@
]
}
],
"action_log_index": 4,
"action_log_index": 5,
"log": [
[
"Player1 paid 2 food to get the Storage advance",
@ -410,7 +459,9 @@
"Player1 gained Great Architect for 1 culture token"
],
[
"Player1 played the action card Great Architect",
"Player1 played the action card Great Architect"
],
[
"Player1 decided to build Pyramids in city A1"
],
[

View file

@ -86,6 +86,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -92,6 +92,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -90,6 +90,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -93,6 +93,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -130,6 +130,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -93,6 +93,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -100,6 +100,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -93,6 +93,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -92,6 +92,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -93,6 +93,16 @@
"event_info": {
"Cartography": "0"
}
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -101,6 +101,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -87,6 +87,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -101,6 +101,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -131,6 +131,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -101,6 +101,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -161,6 +161,16 @@
"Pyramids"
],
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -166,6 +166,16 @@
"Pyramids"
],
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -155,6 +155,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -129,6 +129,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -183,6 +183,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -183,6 +183,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -183,6 +183,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -221,6 +221,16 @@
],
"incident_tokens": 3,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -225,6 +225,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -224,6 +224,16 @@
19
],
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -162,6 +162,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -159,6 +159,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -162,6 +162,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -164,6 +164,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {

View file

@ -160,6 +160,16 @@
],
"incident_tokens": 2,
"next_unit_id": 2
},
{
"id": 2,
"civilization": "Barbarians",
"next_unit_id": 0
},
{
"id": 3,
"civilization": "Pirates",
"next_unit_id": 0
}
],
"map": {