Show all players (#57)
* show all players * show all players * settlers can't attack * fix movement dialog, player status * fix movement dialog, player status * fix movement * add "back to modal dialog" * fmt
This commit is contained in:
parent
22b52c7c9c
commit
6d112e5fc3
23 changed files with 467 additions and 270 deletions
|
|
@ -11,7 +11,7 @@ use server::playing_actions::PlayingAction;
|
|||
use server::resource_pile::AdvancePaymentOptions;
|
||||
use server::status_phase::{StatusPhaseAction, StatusPhaseState};
|
||||
|
||||
use crate::client_state::{can_play_action, ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, ShownPlayer, StateUpdate};
|
||||
use crate::dialog_ui::dialog_window;
|
||||
use crate::payment_ui::{payment_dialog, HasPayment, Payment, ResourcePayment};
|
||||
use crate::resource_ui::{new_resource_map, ResourceType};
|
||||
|
|
@ -76,18 +76,18 @@ impl HasPayment for AdvancePayment {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn show_advance_menu(game: &Game, player_index: usize) -> StateUpdate {
|
||||
show_generic_advance_menu("Advances", game, player_index, true, |name| {
|
||||
pub fn show_advance_menu(game: &Game, player: &ShownPlayer) -> StateUpdate {
|
||||
show_generic_advance_menu("Advances", game, player, true, |name| {
|
||||
StateUpdate::SetDialog(ActiveDialog::AdvancePayment(AdvancePayment::new(
|
||||
game,
|
||||
player_index,
|
||||
player.index,
|
||||
&name,
|
||||
)))
|
||||
})
|
||||
}
|
||||
|
||||
pub fn show_free_advance_menu(game: &Game, player_index: usize) -> StateUpdate {
|
||||
show_generic_advance_menu("Select a free advance", game, player_index, false, |name| {
|
||||
pub fn show_free_advance_menu(game: &Game, player: &ShownPlayer) -> StateUpdate {
|
||||
show_generic_advance_menu("Select a free advance", game, player, false, |name| {
|
||||
StateUpdate::status_phase(StatusPhaseAction::FreeAdvance(name))
|
||||
})
|
||||
}
|
||||
|
|
@ -95,14 +95,14 @@ pub fn show_free_advance_menu(game: &Game, player_index: usize) -> StateUpdate {
|
|||
pub fn show_generic_advance_menu(
|
||||
title: &str,
|
||||
game: &Game,
|
||||
player_index: usize,
|
||||
player: &ShownPlayer,
|
||||
close_button: bool,
|
||||
new_update: impl Fn(String) -> StateUpdate,
|
||||
) -> StateUpdate {
|
||||
dialog_window(title, close_button, |ui| {
|
||||
dialog_window(player, title, close_button, |ui| {
|
||||
for a in get_all() {
|
||||
let name = a.name;
|
||||
let p = game.get_player(player_index);
|
||||
let p = player.get(game);
|
||||
if p.has_advance(&name) {
|
||||
ui.label(None, &name);
|
||||
} else {
|
||||
|
|
@ -112,7 +112,7 @@ pub fn show_generic_advance_menu(
|
|||
) {
|
||||
p.can_advance_free(&name)
|
||||
} else {
|
||||
can_play_action(game) && p.can_advance(&name)
|
||||
player.can_control && p.can_advance(&name)
|
||||
};
|
||||
if can && ui.button(None, name.clone()) {
|
||||
return new_update(name);
|
||||
|
|
@ -123,8 +123,9 @@ pub fn show_generic_advance_menu(
|
|||
})
|
||||
}
|
||||
|
||||
pub fn pay_advance_dialog(ap: &AdvancePayment) -> StateUpdate {
|
||||
pub fn pay_advance_dialog(ap: &AdvancePayment, player: &ShownPlayer) -> StateUpdate {
|
||||
payment_dialog(
|
||||
player,
|
||||
&format!("Pay for advance {}", ap.name),
|
||||
ap,
|
||||
AdvancePayment::valid,
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use server::player::Player;
|
|||
use server::position::Position;
|
||||
use server::unit::Units;
|
||||
|
||||
use crate::client_state::{can_play_action, ActiveDialog, State, StateUpdate, StateUpdates};
|
||||
use crate::client_state::{ActiveDialog, ShownPlayer, State, StateUpdate, StateUpdates};
|
||||
use crate::collect_ui::{possible_resource_collections, CollectResources};
|
||||
use crate::construct_ui::{add_construct_button, add_wonder_buttons};
|
||||
use crate::hex_ui::draw_hex_center_text;
|
||||
|
|
@ -17,34 +17,30 @@ use crate::recruit_unit_ui::RecruitAmount;
|
|||
use crate::{hex_ui, influence_ui, player_ui};
|
||||
|
||||
pub struct CityMenu {
|
||||
pub player_index: usize,
|
||||
pub player: ShownPlayer,
|
||||
pub city_owner_index: usize,
|
||||
pub city_position: Position,
|
||||
}
|
||||
|
||||
impl CityMenu {
|
||||
pub fn new(player_index: usize, city_owner_index: usize, city_position: Position) -> Self {
|
||||
pub fn new(player: &ShownPlayer, city_owner_index: usize, city_position: Position) -> Self {
|
||||
CityMenu {
|
||||
player_index,
|
||||
player: player.clone(),
|
||||
city_owner_index,
|
||||
city_position,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn get_player<'a>(&self, game: &'a Game) -> &'a Player {
|
||||
game.get_player(self.player_index)
|
||||
}
|
||||
|
||||
pub fn get_city_owner<'a>(&self, game: &'a Game) -> &'a Player {
|
||||
game.get_player(self.city_owner_index)
|
||||
}
|
||||
|
||||
pub fn get_city<'a>(&self, game: &'a Game) -> &'a City {
|
||||
return game.get_city(self.city_owner_index, self.city_position);
|
||||
game.get_city(self.city_owner_index, self.city_position)
|
||||
}
|
||||
|
||||
pub fn is_city_owner(&self) -> bool {
|
||||
self.player_index == self.city_owner_index
|
||||
self.player.index == self.city_owner_index
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -52,13 +48,13 @@ pub fn show_city_menu(game: &Game, menu: &CityMenu) -> StateUpdate {
|
|||
let position = menu.city_position;
|
||||
let city = menu.get_city(game);
|
||||
|
||||
show_generic_tile_menu(game, position, city_label(game, city), |ui| {
|
||||
let can_play = can_play_action(game) && menu.is_city_owner() && city.can_activate();
|
||||
show_generic_tile_menu(game, position, &menu.player, city_label(game, city), |ui| {
|
||||
let can_play = menu.player.can_play_action && menu.is_city_owner() && city.can_activate();
|
||||
if can_play {
|
||||
if ui.button(None, "Collect Resources") {
|
||||
return StateUpdate::SetDialog(ActiveDialog::CollectResources(
|
||||
CollectResources::new(
|
||||
menu.player_index,
|
||||
menu.player.index,
|
||||
menu.city_position,
|
||||
possible_resource_collections(
|
||||
game,
|
||||
|
|
@ -71,7 +67,7 @@ pub fn show_city_menu(game: &Game, menu: &CityMenu) -> StateUpdate {
|
|||
if ui.button(None, "Recruit Units") {
|
||||
return RecruitAmount::new_selection(
|
||||
game,
|
||||
menu.player_index,
|
||||
menu.player.index,
|
||||
menu.city_position,
|
||||
Units::empty(),
|
||||
None,
|
||||
|
|
@ -127,11 +123,10 @@ fn city_label(game: &Game, city: &City) -> Vec<String> {
|
|||
}
|
||||
|
||||
fn add_building_actions(game: &Game, menu: &CityMenu, ui: &mut Ui) -> StateUpdate {
|
||||
let closest_city_pos = influence_ui::closest_city(game, menu);
|
||||
|
||||
if !can_play_action(game) {
|
||||
if !menu.player.can_play_action {
|
||||
return StateUpdate::None;
|
||||
}
|
||||
let closest_city_pos = influence_ui::closest_city(game, menu);
|
||||
|
||||
let mut updates = StateUpdates::new();
|
||||
for (building, name) in building_names() {
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use server::status_phase::StatusPhaseAction;
|
|||
|
||||
use crate::advance_ui::{pay_advance_dialog, show_advance_menu, show_free_advance_menu};
|
||||
use crate::client_state::{
|
||||
ActiveDialog, ControlPlayers, PendingUpdate, State, StateUpdate, StateUpdates,
|
||||
ActiveDialog, PendingUpdate, ShownPlayer, State, StateUpdate, StateUpdates,
|
||||
};
|
||||
use crate::collect_ui::{click_collect_option, collect_resources_dialog};
|
||||
use crate::construct_ui::pay_construction_dialog;
|
||||
|
|
@ -33,20 +33,6 @@ pub fn render_and_update(
|
|||
sync_result: &GameSyncResult,
|
||||
features: &Features,
|
||||
) -> GameSyncRequest {
|
||||
match state.control_players {
|
||||
ControlPlayers::None => {
|
||||
// todo add spectator mode
|
||||
return GameSyncRequest::None;
|
||||
}
|
||||
ControlPlayers::All => {}
|
||||
ControlPlayers::Own(p) => {
|
||||
if game.active_player() != p {
|
||||
// todo add spectator mode
|
||||
return GameSyncRequest::None;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
match sync_result {
|
||||
GameSyncResult::None => {}
|
||||
GameSyncResult::Update => {
|
||||
|
|
@ -63,21 +49,31 @@ pub fn render_and_update(
|
|||
|
||||
fn render(game: &Game, state: &State, features: &Features) -> StateUpdate {
|
||||
let player_index = game.active_player();
|
||||
let player = &state.shown_player(game);
|
||||
clear_background(WHITE);
|
||||
|
||||
draw_map(game, state);
|
||||
let mut updates = StateUpdates::new();
|
||||
show_globals(game);
|
||||
let update = show_globals(game, player);
|
||||
updates.add(update);
|
||||
show_resources(game, player_index);
|
||||
show_wonders(game, player_index);
|
||||
|
||||
if root_ui().button(vec2(1200., 130.), "Log") {
|
||||
return StateUpdate::OpenDialog(ActiveDialog::Log);
|
||||
};
|
||||
if root_ui().button(vec2(1200., 100.), "Advances") {
|
||||
return StateUpdate::OpenDialog(ActiveDialog::AdvanceMenu);
|
||||
};
|
||||
if features.import_export {
|
||||
if root_ui().button(vec2(1200., 130.), "Log") {
|
||||
return StateUpdate::OpenDialog(ActiveDialog::Log);
|
||||
};
|
||||
let d = state.game_state_dialog(game, &ActiveDialog::None);
|
||||
if !matches!(d, ActiveDialog::None)
|
||||
&& d.title() != state.active_dialog.title()
|
||||
&& root_ui().button(vec2(1200., 160.), format!("Back to {}", d.title()))
|
||||
{
|
||||
return StateUpdate::OpenDialog(d);
|
||||
}
|
||||
|
||||
if features.import_export && player.can_control {
|
||||
if root_ui().button(vec2(1200., 290.), "Import") {
|
||||
return StateUpdate::Import;
|
||||
};
|
||||
|
|
@ -85,13 +81,14 @@ fn render(game: &Game, state: &State, features: &Features) -> StateUpdate {
|
|||
return StateUpdate::Export;
|
||||
};
|
||||
}
|
||||
|
||||
if let Some(u) = &state.pending_update {
|
||||
updates.add(show_pending_update(u));
|
||||
return updates.result();
|
||||
if player.can_control {
|
||||
if let Some(u) = &state.pending_update {
|
||||
updates.add(show_pending_update(u, player));
|
||||
return updates.result();
|
||||
}
|
||||
}
|
||||
|
||||
if game.state == server::game::GameState::Playing {
|
||||
if player.can_play_action {
|
||||
updates.add(show_increase_happiness(game, player_index));
|
||||
}
|
||||
updates.add(show_global_controls(game, state));
|
||||
|
|
@ -99,46 +96,50 @@ fn render(game: &Game, state: &State, features: &Features) -> StateUpdate {
|
|||
updates.add(match &state.active_dialog {
|
||||
ActiveDialog::None => StateUpdate::None,
|
||||
ActiveDialog::Log => show_log(game),
|
||||
ActiveDialog::TileMenu(p) => show_tile_menu(game, *p),
|
||||
ActiveDialog::TileMenu(p) => show_tile_menu(game, *p, player),
|
||||
ActiveDialog::WaitingForUpdate => {
|
||||
active_dialog_window("Waiting for update", |_ui| StateUpdate::None)
|
||||
active_dialog_window(player, "Waiting for update", |_ui| StateUpdate::None)
|
||||
}
|
||||
|
||||
// playing actions
|
||||
ActiveDialog::IncreaseHappiness(h) => increase_happiness_menu(h),
|
||||
ActiveDialog::AdvanceMenu => show_advance_menu(game, player_index),
|
||||
ActiveDialog::AdvancePayment(p) => pay_advance_dialog(p),
|
||||
ActiveDialog::ConstructionPayment(p) => pay_construction_dialog(game, p),
|
||||
ActiveDialog::CollectResources(c) => collect_resources_dialog(game, c),
|
||||
ActiveDialog::RecruitUnitSelection(s) => recruit_unit_ui::select_dialog(game, s),
|
||||
ActiveDialog::ReplaceUnits(r) => recruit_unit_ui::replace_dialog(game, r),
|
||||
ActiveDialog::MoveUnits(s) => move_ui::move_units_dialog(game, s),
|
||||
ActiveDialog::IncreaseHappiness(h) => increase_happiness_menu(h, player),
|
||||
ActiveDialog::AdvanceMenu => show_advance_menu(game, player),
|
||||
ActiveDialog::AdvancePayment(p) => pay_advance_dialog(p, player),
|
||||
ActiveDialog::ConstructionPayment(p) => pay_construction_dialog(game, p, player),
|
||||
ActiveDialog::CollectResources(c) => collect_resources_dialog(game, c, player),
|
||||
ActiveDialog::RecruitUnitSelection(s) => recruit_unit_ui::select_dialog(game, s, player),
|
||||
ActiveDialog::ReplaceUnits(r) => recruit_unit_ui::replace_dialog(game, r, player),
|
||||
ActiveDialog::MoveUnits(s) => move_ui::move_units_dialog(game, s, player),
|
||||
ActiveDialog::CulturalInfluenceResolution(c) => {
|
||||
influence_ui::cultural_influence_resolution_dialog(c)
|
||||
influence_ui::cultural_influence_resolution_dialog(c, player)
|
||||
}
|
||||
|
||||
//status phase
|
||||
ActiveDialog::FreeAdvance => show_free_advance_menu(game, player_index),
|
||||
ActiveDialog::RaseSize1City => status_phase_ui::raze_city_dialog(),
|
||||
ActiveDialog::DetermineFirstPlayer => status_phase_ui::determine_first_player_dialog(game),
|
||||
ActiveDialog::ChangeGovernmentType => status_phase_ui::change_government_type_dialog(game),
|
||||
ActiveDialog::FreeAdvance => show_free_advance_menu(game, player),
|
||||
ActiveDialog::RazeSize1City => status_phase_ui::raze_city_dialog(player),
|
||||
ActiveDialog::DetermineFirstPlayer => {
|
||||
status_phase_ui::determine_first_player_dialog(game, player)
|
||||
}
|
||||
ActiveDialog::ChangeGovernmentType => {
|
||||
status_phase_ui::change_government_type_dialog(game, player)
|
||||
}
|
||||
ActiveDialog::ChooseAdditionalAdvances(a) => {
|
||||
status_phase_ui::choose_additional_advances_dialog(game, a)
|
||||
status_phase_ui::choose_additional_advances_dialog(game, a, player)
|
||||
}
|
||||
|
||||
//combat
|
||||
ActiveDialog::PlaceSettler => combat_ui::place_settler_dialog(),
|
||||
ActiveDialog::Retreat => combat_ui::retreat_dialog(),
|
||||
ActiveDialog::RemoveCasualties(s) => combat_ui::remove_casualties_dialog(game, s),
|
||||
ActiveDialog::PlaceSettler => combat_ui::place_settler_dialog(player),
|
||||
ActiveDialog::Retreat => combat_ui::retreat_dialog(player),
|
||||
ActiveDialog::RemoveCasualties(s) => combat_ui::remove_casualties_dialog(game, s, player),
|
||||
});
|
||||
|
||||
updates.add(try_click(game, state, player_index));
|
||||
updates.add(try_click(game, state, player));
|
||||
|
||||
updates.result()
|
||||
}
|
||||
|
||||
fn show_pending_update(update: &PendingUpdate) -> StateUpdate {
|
||||
active_dialog_window("Are you sure?", |ui| {
|
||||
fn show_pending_update(update: &PendingUpdate, player: &ShownPlayer) -> StateUpdate {
|
||||
active_dialog_window(player, "Are you sure?", |ui| {
|
||||
ui.label(None, &format!("Warning: {}", update.warning.join(", ")));
|
||||
if ui.button(None, "OK") {
|
||||
return StateUpdate::ResolvePendingUpdate(true);
|
||||
|
|
@ -150,7 +151,7 @@ fn show_pending_update(update: &PendingUpdate) -> StateUpdate {
|
|||
})
|
||||
}
|
||||
|
||||
pub fn try_click(game: &Game, state: &State, player_index: usize) -> StateUpdate {
|
||||
pub fn try_click(game: &Game, state: &State, player: &ShownPlayer) -> StateUpdate {
|
||||
if !is_mouse_button_pressed(MouseButton::Left) {
|
||||
return StateUpdate::None;
|
||||
}
|
||||
|
|
@ -161,38 +162,42 @@ pub fn try_click(game: &Game, state: &State, player_index: usize) -> StateUpdate
|
|||
return StateUpdate::None;
|
||||
}
|
||||
|
||||
match &state.active_dialog {
|
||||
ActiveDialog::MoveUnits(s) => move_ui::click(pos, s),
|
||||
ActiveDialog::ReplaceUnits(r) => recruit_unit_ui::click_replace(pos, r),
|
||||
ActiveDialog::RemoveCasualties(_s) => StateUpdate::None,
|
||||
ActiveDialog::CollectResources(col) => click_collect_option(col, pos),
|
||||
ActiveDialog::RaseSize1City => {
|
||||
if game.players[player_index].can_raze_city(pos) {
|
||||
StateUpdate::status_phase(StatusPhaseAction::RaseSize1City(Some(pos)))
|
||||
} else {
|
||||
StateUpdate::None
|
||||
if player.can_control {
|
||||
match &state.active_dialog {
|
||||
ActiveDialog::MoveUnits(s) => move_ui::click(pos, s),
|
||||
ActiveDialog::ReplaceUnits(r) => recruit_unit_ui::click_replace(pos, r),
|
||||
ActiveDialog::RemoveCasualties(_s) => StateUpdate::None,
|
||||
ActiveDialog::CollectResources(col) => click_collect_option(col, pos),
|
||||
ActiveDialog::RazeSize1City => {
|
||||
if player.get(game).can_raze_city(pos) {
|
||||
StateUpdate::status_phase(StatusPhaseAction::RaseSize1City(Some(pos)))
|
||||
} else {
|
||||
StateUpdate::None
|
||||
}
|
||||
}
|
||||
}
|
||||
ActiveDialog::PlaceSettler => {
|
||||
if game.players[player_index].get_city(pos).is_some() {
|
||||
StateUpdate::Execute(Action::PlaceSettler(pos))
|
||||
} else {
|
||||
StateUpdate::None
|
||||
ActiveDialog::PlaceSettler => {
|
||||
if player.get(game).get_city(pos).is_some() {
|
||||
StateUpdate::Execute(Action::PlaceSettler(pos))
|
||||
} else {
|
||||
StateUpdate::None
|
||||
}
|
||||
}
|
||||
}
|
||||
ActiveDialog::IncreaseHappiness(h) => {
|
||||
if let Some(city) = game.players[player_index].get_city(pos) {
|
||||
StateUpdate::SetDialog(ActiveDialog::IncreaseHappiness(add_increase_happiness(
|
||||
&game.players[player_index],
|
||||
city,
|
||||
pos,
|
||||
h,
|
||||
)))
|
||||
} else {
|
||||
StateUpdate::None
|
||||
ActiveDialog::IncreaseHappiness(h) => {
|
||||
if let Some(city) = player.get(game).get_city(pos) {
|
||||
StateUpdate::SetDialog(ActiveDialog::IncreaseHappiness(add_increase_happiness(
|
||||
player.get(game),
|
||||
city,
|
||||
pos,
|
||||
h,
|
||||
)))
|
||||
} else {
|
||||
StateUpdate::None
|
||||
}
|
||||
}
|
||||
_ => StateUpdate::OpenDialog(ActiveDialog::TileMenu(pos)),
|
||||
}
|
||||
_ => StateUpdate::OpenDialog(ActiveDialog::TileMenu(pos)),
|
||||
} else {
|
||||
StateUpdate::OpenDialog(ActiveDialog::TileMenu(pos))
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -1,9 +1,10 @@
|
|||
use macroquad::prelude::*;
|
||||
|
||||
use server::action::{Action, CombatAction};
|
||||
use server::action::Action;
|
||||
use server::city::{City, MoodState};
|
||||
use server::combat::{active_attackers, active_defenders, CombatPhase};
|
||||
use server::game::{CulturalInfluenceResolution, Game, GameState};
|
||||
use server::player::Player;
|
||||
use server::position::Position;
|
||||
use server::status_phase::{StatusPhaseAction, StatusPhaseState};
|
||||
|
||||
|
|
@ -38,7 +39,7 @@ pub enum ActiveDialog {
|
|||
|
||||
// status phase
|
||||
FreeAdvance,
|
||||
RaseSize1City,
|
||||
RazeSize1City,
|
||||
DetermineFirstPlayer,
|
||||
ChangeGovernmentType,
|
||||
ChooseAdditionalAdvances(ChooseAdditionalAdvances),
|
||||
|
|
@ -49,6 +50,35 @@ pub enum ActiveDialog {
|
|||
RemoveCasualties(RemoveCasualtiesSelection),
|
||||
}
|
||||
|
||||
impl ActiveDialog {
|
||||
#[must_use]
|
||||
pub fn title(&self) -> &str {
|
||||
match self {
|
||||
ActiveDialog::None => "none",
|
||||
ActiveDialog::TileMenu(_) => "tile menu",
|
||||
ActiveDialog::Log => "log",
|
||||
ActiveDialog::WaitingForUpdate => "waiting for update",
|
||||
ActiveDialog::IncreaseHappiness(_) => "increase happiness",
|
||||
ActiveDialog::AdvanceMenu => "advance menu",
|
||||
ActiveDialog::AdvancePayment(_) => "advance payment",
|
||||
ActiveDialog::ConstructionPayment(_) => "construction payment",
|
||||
ActiveDialog::CollectResources(_) => "collect resources",
|
||||
ActiveDialog::RecruitUnitSelection(_) => "recruit unit selection",
|
||||
ActiveDialog::ReplaceUnits(_) => "replace units",
|
||||
ActiveDialog::MoveUnits(_) => "move units",
|
||||
ActiveDialog::CulturalInfluenceResolution(_) => "cultural influence resolution",
|
||||
ActiveDialog::FreeAdvance => "free advance",
|
||||
ActiveDialog::RazeSize1City => "raze size 1 city",
|
||||
ActiveDialog::DetermineFirstPlayer => "determine first player",
|
||||
ActiveDialog::ChangeGovernmentType => "change government type",
|
||||
ActiveDialog::ChooseAdditionalAdvances(_) => "choose additional advances",
|
||||
ActiveDialog::PlaceSettler => "place settler",
|
||||
ActiveDialog::Retreat => "retreat",
|
||||
ActiveDialog::RemoveCasualties(_) => "remove casualties",
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
pub struct PendingUpdate {
|
||||
pub action: Action,
|
||||
pub warning: Vec<String>,
|
||||
|
|
@ -66,6 +96,7 @@ pub enum StateUpdate {
|
|||
ExecuteWithWarning(PendingUpdate),
|
||||
Import,
|
||||
Export,
|
||||
SetShownPlayer(usize),
|
||||
}
|
||||
|
||||
impl StateUpdate {
|
||||
|
|
@ -142,15 +173,24 @@ impl StateUpdates {
|
|||
}
|
||||
}
|
||||
|
||||
pub enum ControlPlayers {
|
||||
None,
|
||||
All,
|
||||
Own(usize),
|
||||
#[derive(Clone)]
|
||||
pub struct ShownPlayer {
|
||||
pub index: usize,
|
||||
pub can_control: bool,
|
||||
pub can_play_action: bool,
|
||||
}
|
||||
|
||||
impl ShownPlayer {
|
||||
#[must_use]
|
||||
pub fn get<'a>(&self, game: &'a Game) -> &'a Player {
|
||||
game.get_player(self.index)
|
||||
}
|
||||
}
|
||||
|
||||
pub struct State {
|
||||
pub assets: Assets,
|
||||
pub control_players: ControlPlayers,
|
||||
pub control_player: Option<usize>,
|
||||
pub show_player: usize,
|
||||
pub active_dialog: ActiveDialog,
|
||||
dialog_stack: Vec<ActiveDialog>,
|
||||
pub pending_update: Option<PendingUpdate>,
|
||||
|
|
@ -163,7 +203,19 @@ impl State {
|
|||
dialog_stack: vec![],
|
||||
pending_update: None,
|
||||
assets: Assets::new(features).await,
|
||||
control_players: ControlPlayers::None,
|
||||
control_player: None,
|
||||
show_player: 0,
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn shown_player(&self, game: &Game) -> ShownPlayer {
|
||||
let a = game.active_player();
|
||||
let control = self.control_player == Some(a) && self.show_player == a;
|
||||
ShownPlayer {
|
||||
index: self.show_player,
|
||||
can_control: control,
|
||||
can_play_action: control && game.state == GameState::Playing && game.actions_left > 0,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -182,8 +234,11 @@ impl State {
|
|||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn has_dialog(&self) -> bool {
|
||||
!matches!(self.active_dialog, ActiveDialog::None)
|
||||
pub fn has_modal_dialog(&self) -> bool {
|
||||
!matches!(
|
||||
self.active_dialog,
|
||||
ActiveDialog::None | ActiveDialog::TileMenu(_) | ActiveDialog::Log
|
||||
)
|
||||
}
|
||||
|
||||
pub fn update(&mut self, game: &Game, update: StateUpdate) -> GameSyncRequest {
|
||||
|
|
@ -222,6 +277,10 @@ impl State {
|
|||
}
|
||||
StateUpdate::Import => GameSyncRequest::Import,
|
||||
StateUpdate::Export => GameSyncRequest::Export,
|
||||
StateUpdate::SetShownPlayer(p) => {
|
||||
self.show_player = p;
|
||||
GameSyncRequest::None
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -249,33 +308,47 @@ impl State {
|
|||
}
|
||||
|
||||
pub fn update_from_game(&mut self, game: &Game) -> GameSyncRequest {
|
||||
let last_dialog = self.active_dialog.clone();
|
||||
self.clear();
|
||||
|
||||
self.active_dialog = match &game.state {
|
||||
self.active_dialog = self.game_state_dialog(game, &last_dialog);
|
||||
GameSyncRequest::None
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn game_state_dialog(&self, game: &Game, last_dialog: &ActiveDialog) -> ActiveDialog {
|
||||
match &game.state {
|
||||
GameState::Movement { .. } => {
|
||||
ActiveDialog::MoveUnits(MoveSelection::new(game.active_player()))
|
||||
let start = if let ActiveDialog::TileMenu(p) = last_dialog {
|
||||
Some(*p)
|
||||
} else {
|
||||
None
|
||||
};
|
||||
ActiveDialog::MoveUnits(MoveSelection::new(game.active_player(), start))
|
||||
}
|
||||
GameState::CulturalInfluenceResolution(c) => {
|
||||
ActiveDialog::CulturalInfluenceResolution(c.clone())
|
||||
}
|
||||
GameState::StatusPhase(state) => match state {
|
||||
StatusPhaseState::CompleteObjectives => {
|
||||
self.execute_status_phase(game, StatusPhaseAction::CompleteObjectives(vec![]))
|
||||
// todo implement
|
||||
// self.execute_status_phase(game, StatusPhaseAction::CompleteObjectives(vec![]))
|
||||
ActiveDialog::None
|
||||
}
|
||||
StatusPhaseState::FreeAdvance => ActiveDialog::FreeAdvance,
|
||||
StatusPhaseState::RaseSize1City => ActiveDialog::RaseSize1City,
|
||||
StatusPhaseState::RaseSize1City => ActiveDialog::RazeSize1City,
|
||||
StatusPhaseState::ChangeGovernmentType => ActiveDialog::ChangeGovernmentType,
|
||||
StatusPhaseState::DetermineFirstPlayer => ActiveDialog::DetermineFirstPlayer,
|
||||
},
|
||||
GameState::PlaceSettler { .. } => ActiveDialog::PlaceSettler,
|
||||
GameState::Combat(c) => match c.phase {
|
||||
CombatPhase::PlayActionCard(_) => {
|
||||
self.update(
|
||||
game,
|
||||
StateUpdate::Execute(Action::Combat(CombatAction::PlayActionCard(None))),
|
||||
);
|
||||
// self.update(
|
||||
// game,
|
||||
// StateUpdate::Execute(Action::Combat(CombatAction::PlayActionCard(None))),
|
||||
// );
|
||||
ActiveDialog::None
|
||||
} //todo(gregor)
|
||||
} //todo implement
|
||||
CombatPhase::RemoveCasualties {
|
||||
player, casualties, ..
|
||||
} => {
|
||||
|
|
@ -299,17 +372,11 @@ impl State {
|
|||
CombatPhase::Retreat => ActiveDialog::Retreat,
|
||||
},
|
||||
_ => ActiveDialog::None,
|
||||
};
|
||||
GameSyncRequest::None
|
||||
}
|
||||
}
|
||||
|
||||
fn execute_status_phase(&mut self, game: &Game, action: StatusPhaseAction) -> ActiveDialog {
|
||||
self.update(game, StateUpdate::status_phase(action));
|
||||
ActiveDialog::None
|
||||
}
|
||||
}
|
||||
|
||||
#[must_use]
|
||||
pub fn can_play_action(game: &Game) -> bool {
|
||||
game.state == GameState::Playing && game.actions_left > 0
|
||||
// fn execute_status_phase(&mut self, game: &Game, action: StatusPhaseAction) -> ActiveDialog {
|
||||
// self.update(game, StateUpdate::status_phase(action));
|
||||
// ActiveDialog::None
|
||||
// }
|
||||
}
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use server::playing_actions::{get_total_collection, PlayingAction};
|
|||
use server::position::Position;
|
||||
use server::resource_pile::ResourcePile;
|
||||
|
||||
use crate::client_state::{ActiveDialog, State, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, ShownPlayer, State, StateUpdate};
|
||||
use crate::dialog_ui::active_dialog_window;
|
||||
use crate::hex_ui;
|
||||
use crate::resource_ui::resource_pile_string;
|
||||
|
|
@ -47,8 +47,12 @@ impl CollectResources {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn collect_resources_dialog(game: &Game, collect: &CollectResources) -> StateUpdate {
|
||||
active_dialog_window("Collect Resources", |ui| {
|
||||
pub fn collect_resources_dialog(
|
||||
game: &Game,
|
||||
collect: &CollectResources,
|
||||
player: &ShownPlayer,
|
||||
) -> StateUpdate {
|
||||
active_dialog_window(player, "Collect Resources", |ui| {
|
||||
let r: ResourcePile = collect
|
||||
.collections
|
||||
.clone()
|
||||
|
|
|
|||
|
|
@ -3,14 +3,14 @@ use server::game::Game;
|
|||
use server::position::Position;
|
||||
use server::unit::Unit;
|
||||
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, ShownPlayer, StateUpdate};
|
||||
use crate::dialog_ui::active_dialog_window;
|
||||
use crate::select_ui::{ConfirmSelection, SelectionConfirm};
|
||||
use crate::unit_ui;
|
||||
use crate::unit_ui::UnitSelection;
|
||||
|
||||
pub fn retreat_dialog() -> StateUpdate {
|
||||
active_dialog_window("Do you want to retreat?", |ui| {
|
||||
pub fn retreat_dialog(player: &ShownPlayer) -> StateUpdate {
|
||||
active_dialog_window(player, "Do you want to retreat?", |ui| {
|
||||
if ui.button(None, "Retreat") {
|
||||
return retreat(true);
|
||||
}
|
||||
|
|
@ -25,8 +25,8 @@ fn retreat(retreat: bool) -> StateUpdate {
|
|||
StateUpdate::Execute(Action::Combat(CombatAction::Retreat(retreat)))
|
||||
}
|
||||
|
||||
pub fn place_settler_dialog() -> StateUpdate {
|
||||
active_dialog_window("Select a city to place a settler in.", |_| {
|
||||
pub fn place_settler_dialog(player: &ShownPlayer) -> StateUpdate {
|
||||
active_dialog_window(player, "Select a city to place a settler in.", |_| {
|
||||
StateUpdate::None
|
||||
})
|
||||
}
|
||||
|
|
@ -82,9 +82,14 @@ impl ConfirmSelection for RemoveCasualtiesSelection {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn remove_casualties_dialog(game: &Game, sel: &RemoveCasualtiesSelection) -> StateUpdate {
|
||||
pub fn remove_casualties_dialog(
|
||||
game: &Game,
|
||||
sel: &RemoveCasualtiesSelection,
|
||||
player: &ShownPlayer,
|
||||
) -> StateUpdate {
|
||||
unit_ui::unit_selection_dialog::<RemoveCasualtiesSelection>(
|
||||
game,
|
||||
player,
|
||||
"Remove casualties",
|
||||
sel,
|
||||
|new| StateUpdate::SetDialog(ActiveDialog::RemoveCasualties(new.clone())),
|
||||
|
|
|
|||
|
|
@ -15,7 +15,7 @@ use server::position::Position;
|
|||
use server::resource_pile::PaymentOptions;
|
||||
use server::unit::UnitType;
|
||||
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, ShownPlayer, StateUpdate};
|
||||
use crate::payment_ui::{payment_dialog, HasPayment, Payment, ResourcePayment};
|
||||
use crate::recruit_unit_ui::RecruitSelection;
|
||||
use crate::resource_ui::{new_resource_map, ResourceType};
|
||||
|
|
@ -30,7 +30,7 @@ pub fn add_construct_button(
|
|||
) -> StateUpdate {
|
||||
let owner = menu.get_city_owner(game);
|
||||
let city = menu.get_city(game);
|
||||
if (menu.is_city_owner()) && city.can_construct(building, owner) {
|
||||
if menu.is_city_owner() && menu.player.can_play_action && city.can_construct(building, owner) {
|
||||
for pos in building_positions(building, city, &game.map) {
|
||||
if ui.button(
|
||||
None,
|
||||
|
|
@ -44,7 +44,7 @@ pub fn add_construct_button(
|
|||
ConstructionPayment::new(
|
||||
game,
|
||||
name,
|
||||
menu.player_index,
|
||||
menu.player.index,
|
||||
menu.city_position,
|
||||
ConstructionProject::Building(building.clone(), pos),
|
||||
),
|
||||
|
|
@ -83,7 +83,7 @@ pub fn add_wonder_buttons(game: &Game, menu: &CityMenu, ui: &mut Ui) -> StateUpd
|
|||
ConstructionPayment::new(
|
||||
game,
|
||||
&w.name,
|
||||
menu.player_index,
|
||||
menu.player.index,
|
||||
menu.city_position,
|
||||
ConstructionProject::Wonder(w.name.clone()),
|
||||
),
|
||||
|
|
@ -93,8 +93,13 @@ pub fn add_wonder_buttons(game: &Game, menu: &CityMenu, ui: &mut Ui) -> StateUpd
|
|||
StateUpdate::None
|
||||
}
|
||||
|
||||
pub fn pay_construction_dialog(game: &Game, payment: &ConstructionPayment) -> StateUpdate {
|
||||
pub fn pay_construction_dialog(
|
||||
game: &Game,
|
||||
payment: &ConstructionPayment,
|
||||
player: &ShownPlayer,
|
||||
) -> StateUpdate {
|
||||
payment_dialog(
|
||||
player,
|
||||
&format!("Pay for {}", payment.name),
|
||||
payment,
|
||||
|cp| cp.payment.get(ResourceType::Discount).selectable.current == 0,
|
||||
|
|
|
|||
|
|
@ -3,23 +3,36 @@ use macroquad::math::vec2;
|
|||
use macroquad::ui::widgets::Window;
|
||||
use macroquad::ui::{root_ui, Ui};
|
||||
|
||||
use crate::client_state::StateUpdate;
|
||||
use crate::client_state::{ShownPlayer, StateUpdate};
|
||||
|
||||
pub fn active_dialog_window<F>(title: &str, f: F) -> StateUpdate
|
||||
pub fn active_dialog_window<F>(player: &ShownPlayer, title: &str, f: F) -> StateUpdate
|
||||
where
|
||||
F: FnOnce(&mut Ui) -> StateUpdate,
|
||||
{
|
||||
dialog_window(title, false, f)
|
||||
dialog_window(player, title, false, f)
|
||||
}
|
||||
|
||||
pub fn closeable_dialog_window<F>(title: &str, f: F) -> StateUpdate
|
||||
where
|
||||
F: FnOnce(&mut Ui) -> StateUpdate,
|
||||
{
|
||||
dialog_window(title, true, f)
|
||||
dialog(title, true, f)
|
||||
}
|
||||
|
||||
pub fn dialog_window<F>(title: &str, close_button: bool, f: F) -> StateUpdate
|
||||
pub fn dialog_window<F>(player: &ShownPlayer, title: &str, close_button: bool, f: F) -> StateUpdate
|
||||
where
|
||||
F: FnOnce(&mut Ui) -> StateUpdate,
|
||||
{
|
||||
dialog(title, close_button, |ui| {
|
||||
if player.can_control {
|
||||
f(ui)
|
||||
} else {
|
||||
StateUpdate::None
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
fn dialog<F>(title: &str, close_button: bool, f: F) -> StateUpdate
|
||||
where
|
||||
F: FnOnce(&mut Ui) -> StateUpdate,
|
||||
{
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ use server::playing_actions::PlayingAction;
|
|||
use server::position::Position;
|
||||
use server::resource_pile::ResourcePile;
|
||||
|
||||
use crate::client_state::{can_play_action, ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, ShownPlayer, StateUpdate};
|
||||
use crate::dialog_ui::active_dialog_window;
|
||||
|
||||
#[derive(Clone)]
|
||||
|
|
@ -88,8 +88,8 @@ fn increase_happiness_new_steps(
|
|||
None
|
||||
}
|
||||
|
||||
pub fn increase_happiness_menu(h: &IncreaseHappiness) -> StateUpdate {
|
||||
active_dialog_window("Increase Happiness", |ui| {
|
||||
pub fn increase_happiness_menu(h: &IncreaseHappiness, player: &ShownPlayer) -> StateUpdate {
|
||||
active_dialog_window(player, "Increase Happiness", |ui| {
|
||||
ui.label(None, &format!("Cost: {:?}", h.cost));
|
||||
if ui.button(None, "Cancel") {
|
||||
return StateUpdate::Cancel;
|
||||
|
|
@ -104,7 +104,7 @@ pub fn increase_happiness_menu(h: &IncreaseHappiness) -> StateUpdate {
|
|||
}
|
||||
|
||||
pub fn show_increase_happiness(game: &Game, player_index: usize) -> StateUpdate {
|
||||
if can_play_action(game) && root_ui().button(vec2(1200., 60.), "Increase Happiness") {
|
||||
if root_ui().button(vec2(1200., 60.), "Increase Happiness") {
|
||||
return StateUpdate::SetDialog(ActiveDialog::IncreaseHappiness(IncreaseHappiness::new(
|
||||
game.get_player(player_index)
|
||||
.cities
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
use crate::city_ui::{building_name, CityMenu};
|
||||
use crate::client_state::StateUpdate;
|
||||
use crate::client_state::{ShownPlayer, StateUpdate};
|
||||
use crate::dialog_ui::active_dialog_window;
|
||||
use macroquad::ui::Ui;
|
||||
use server::action::Action;
|
||||
|
|
@ -23,7 +23,7 @@ pub fn add_influence_button(
|
|||
closest_city_pos
|
||||
};
|
||||
if let Some(cost) = game.influence_culture_boost_cost(
|
||||
menu.player_index,
|
||||
menu.player.index,
|
||||
start_position,
|
||||
menu.city_owner_index,
|
||||
menu.city_position,
|
||||
|
|
@ -48,7 +48,8 @@ pub fn add_influence_button(
|
|||
}
|
||||
|
||||
pub fn closest_city(game: &Game, menu: &CityMenu) -> Position {
|
||||
menu.get_player(game)
|
||||
menu.player
|
||||
.get(game)
|
||||
.cities
|
||||
.iter()
|
||||
.min_by_key(|c| c.position.distance(menu.city_position))
|
||||
|
|
@ -56,8 +57,11 @@ pub fn closest_city(game: &Game, menu: &CityMenu) -> Position {
|
|||
.position
|
||||
}
|
||||
|
||||
pub fn cultural_influence_resolution_dialog(c: &CulturalInfluenceResolution) -> StateUpdate {
|
||||
active_dialog_window("Cultural Influence Resolution", |ui| {
|
||||
pub fn cultural_influence_resolution_dialog(
|
||||
c: &CulturalInfluenceResolution,
|
||||
player: &ShownPlayer,
|
||||
) -> StateUpdate {
|
||||
active_dialog_window(player, "Cultural Influence Resolution", |ui| {
|
||||
if ui.button(
|
||||
None,
|
||||
format!(
|
||||
|
|
|
|||
|
|
@ -6,9 +6,9 @@ use std::fs::File;
|
|||
use std::io::BufReader;
|
||||
|
||||
use crate::client::{Features, GameSyncRequest, GameSyncResult};
|
||||
use crate::client_state::ControlPlayers;
|
||||
use server::city::City;
|
||||
use server::game::{Game, GameData};
|
||||
use server::leader::Leader;
|
||||
use server::map::Terrain;
|
||||
use server::position::Position;
|
||||
use server::resource_pile::ResourcePile;
|
||||
|
|
@ -16,20 +16,24 @@ use server::unit::UnitType;
|
|||
|
||||
pub async fn run(mut game: Game, features: &Features) {
|
||||
let mut state = client::init(features).await;
|
||||
state.control_players = ControlPlayers::All;
|
||||
|
||||
let mut sync_result = GameSyncResult::None;
|
||||
state.show_player = game.active_player();
|
||||
loop {
|
||||
state.control_player = Some(game.active_player());
|
||||
|
||||
let message = client::render_and_update(&game, &mut state, &sync_result, features);
|
||||
sync_result = GameSyncResult::None;
|
||||
match message {
|
||||
GameSyncRequest::None => {}
|
||||
GameSyncRequest::ExecuteAction(a) => {
|
||||
game.execute_action(a, game.active_player());
|
||||
state.show_player = game.active_player();
|
||||
sync_result = GameSyncResult::Update;
|
||||
}
|
||||
GameSyncRequest::Import => {
|
||||
game = import();
|
||||
state.show_player = game.active_player();
|
||||
sync_result = GameSyncResult::Update;
|
||||
}
|
||||
GameSyncRequest::Export => {
|
||||
|
|
@ -85,6 +89,8 @@ pub fn setup_local_game() -> Game {
|
|||
add_unit(&mut game, "C2", player_index1, UnitType::Settler);
|
||||
add_unit(&mut game, "C2", player_index1, UnitType::Settler);
|
||||
add_unit(&mut game, "C2", player_index1, UnitType::Settler);
|
||||
game.players[player_index1].active_leader =
|
||||
Some(Leader::builder("Alexander", "", "", "", "").build());
|
||||
|
||||
add_unit(&mut game, "C1", player_index2, UnitType::Infantry);
|
||||
add_unit(&mut game, "C1", player_index2, UnitType::Infantry);
|
||||
|
|
|
|||
|
|
@ -1,9 +1,11 @@
|
|||
use client::client::Features;
|
||||
use client::local_client;
|
||||
use macroquad::window::set_fullscreen;
|
||||
use server::game::Game;
|
||||
|
||||
#[macroquad::main("Clash")]
|
||||
async fn main() {
|
||||
set_fullscreen(true);
|
||||
let wasm = cfg!(feature = "wasm");
|
||||
|
||||
let features = Features {
|
||||
|
|
|
|||
|
|
@ -12,7 +12,7 @@ use server::position::Position;
|
|||
use server::unit::{MovementRestriction, Unit};
|
||||
|
||||
use crate::city_ui::{draw_city, show_city_menu, CityMenu};
|
||||
use crate::client_state::{can_play_action, ActiveDialog, State, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, ShownPlayer, State, StateUpdate};
|
||||
use crate::dialog_ui::closeable_dialog_window;
|
||||
use crate::{collect_ui, hex_ui, unit_ui};
|
||||
|
||||
|
|
@ -79,7 +79,7 @@ fn alpha(game: &Game, state: &State, pos: Position) -> f32 {
|
|||
}
|
||||
}
|
||||
ActiveDialog::ReplaceUnits(s) => highlight_if(s.current_city.is_some_and(|p| p == pos)),
|
||||
ActiveDialog::RaseSize1City => {
|
||||
ActiveDialog::RazeSize1City => {
|
||||
highlight_if(game.players[game.active_player()].can_raze_city(pos))
|
||||
}
|
||||
ActiveDialog::PlaceSettler => {
|
||||
|
|
@ -111,20 +111,18 @@ fn highlight_if(b: bool) -> f32 {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn show_tile_menu(game: &Game, position: Position) -> StateUpdate {
|
||||
pub fn show_tile_menu(game: &Game, position: Position, player: &ShownPlayer) -> StateUpdate {
|
||||
if let Some(c) = game.get_any_city(position) {
|
||||
show_city_menu(
|
||||
game,
|
||||
&CityMenu::new(game.active_player(), c.player_index, position),
|
||||
)
|
||||
show_city_menu(game, &CityMenu::new(player, c.player_index, position))
|
||||
} else {
|
||||
show_generic_tile_menu(game, position, vec![], |_| StateUpdate::None)
|
||||
show_generic_tile_menu(game, position, player, vec![], |_| StateUpdate::None)
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_generic_tile_menu(
|
||||
game: &Game,
|
||||
position: Position,
|
||||
player: &ShownPlayer,
|
||||
suffix: Vec<String>,
|
||||
additional: impl FnOnce(&mut Ui) -> StateUpdate,
|
||||
) -> StateUpdate {
|
||||
|
|
@ -164,7 +162,7 @@ pub fn show_generic_tile_menu(
|
|||
})
|
||||
.collect::<Vec<_>>();
|
||||
|
||||
if can_play_action(game) && !settlers.is_empty() && ui.button(None, "Settle") {
|
||||
if player.can_play_action && !settlers.is_empty() && ui.button(None, "Settle") {
|
||||
let settler = settlers
|
||||
.iter()
|
||||
.find(|u| u.movement_restriction != MovementRestriction::None)
|
||||
|
|
|
|||
|
|
@ -2,18 +2,19 @@ use macroquad::math::u32;
|
|||
|
||||
use crate::select_ui::{ConfirmSelection, SelectionConfirm};
|
||||
use server::action::Action;
|
||||
use server::game::Game;
|
||||
use server::game::GameState::Movement;
|
||||
use server::game::{Game, GameState};
|
||||
use server::position::Position;
|
||||
use server::unit::{MovementAction, Unit};
|
||||
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, ShownPlayer, StateUpdate};
|
||||
use crate::unit_ui;
|
||||
use crate::unit_ui::UnitSelection;
|
||||
|
||||
pub fn move_units_dialog(game: &Game, sel: &MoveSelection) -> StateUpdate {
|
||||
pub fn move_units_dialog(game: &Game, sel: &MoveSelection, player: &ShownPlayer) -> StateUpdate {
|
||||
unit_ui::unit_selection_dialog::<MoveSelection>(
|
||||
game,
|
||||
player,
|
||||
"Move Units",
|
||||
sel,
|
||||
|new| update_possible_destinations(game, new.clone()),
|
||||
|
|
@ -27,10 +28,7 @@ pub fn move_units_dialog(game: &Game, sel: &MoveSelection) -> StateUpdate {
|
|||
panic!("game is not in movement")
|
||||
};
|
||||
|
||||
if ui.button(
|
||||
None,
|
||||
format!("End Move Units - {movement_actions_left} actions left"),
|
||||
) {
|
||||
if ui.button(None, "End Move Units") {
|
||||
StateUpdate::execute_with_warning(
|
||||
Action::Movement(MovementAction::Stop),
|
||||
if movement_actions_left > 0 {
|
||||
|
|
@ -62,7 +60,7 @@ fn possible_destinations(
|
|||
player_index: usize,
|
||||
units: &Vec<u32>,
|
||||
) -> Vec<Position> {
|
||||
if let GameState::Movement {
|
||||
if let Movement {
|
||||
movement_actions_left,
|
||||
moved_units,
|
||||
} = &game.state
|
||||
|
|
@ -117,11 +115,11 @@ pub struct MoveSelection {
|
|||
}
|
||||
|
||||
impl MoveSelection {
|
||||
pub fn new(player_index: usize) -> MoveSelection {
|
||||
pub fn new(player_index: usize, start: Option<Position>) -> MoveSelection {
|
||||
MoveSelection {
|
||||
player_index,
|
||||
units: vec![],
|
||||
start: None,
|
||||
start,
|
||||
destinations: vec![],
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2,7 +2,7 @@ use macroquad::math::bool;
|
|||
|
||||
use server::resource_pile::ResourcePile;
|
||||
|
||||
use crate::client_state::StateUpdate;
|
||||
use crate::client_state::{ShownPlayer, StateUpdate};
|
||||
use crate::resource_ui::{resource_name, ResourceType};
|
||||
use crate::select_ui;
|
||||
use crate::select_ui::{CountSelector, HasCountSelectableObject};
|
||||
|
|
@ -76,7 +76,9 @@ pub trait HasPayment {
|
|||
fn payment(&self) -> &Payment;
|
||||
}
|
||||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn payment_dialog<T: HasPayment>(
|
||||
player: &ShownPlayer,
|
||||
title: &str,
|
||||
has_payment: &T,
|
||||
is_valid: impl FnOnce(&T) -> bool,
|
||||
|
|
@ -86,6 +88,7 @@ pub fn payment_dialog<T: HasPayment>(
|
|||
minus: impl Fn(&T, ResourceType) -> StateUpdate,
|
||||
) -> StateUpdate {
|
||||
select_ui::count_dialog(
|
||||
player,
|
||||
title,
|
||||
has_payment,
|
||||
|p| p.payment().resources.clone(),
|
||||
|
|
|
|||
|
|
@ -3,43 +3,108 @@ use macroquad::math::vec2;
|
|||
use macroquad::prelude::*;
|
||||
use macroquad::text::draw_text;
|
||||
use macroquad::ui::root_ui;
|
||||
|
||||
use macroquad::ui::widgets::Button;
|
||||
use server::action::Action;
|
||||
use server::game::{Game, GameState};
|
||||
use server::player::Player;
|
||||
use server::playing_actions::PlayingAction;
|
||||
use server::resource_pile::ResourcePile;
|
||||
|
||||
use crate::client_state::{can_play_action, State, StateUpdate};
|
||||
use crate::client_state::{ShownPlayer, State, StateUpdate};
|
||||
|
||||
pub fn show_globals(game: &Game) {
|
||||
draw_text(&format!("Age {}", game.age), 30., 30., 20., BLACK);
|
||||
draw_text(&format!("Round {}", game.round), 30., 60., 20., BLACK);
|
||||
draw_text(
|
||||
&format!("Player {}", game.players[game.active_player()].get_name()),
|
||||
1400.,
|
||||
60.,
|
||||
20.,
|
||||
BLACK,
|
||||
);
|
||||
let status = match &game.state {
|
||||
GameState::Playing => String::from("Play Actions"),
|
||||
GameState::StatusPhase(ref p) => format!("Status Phase: {p:?}"),
|
||||
GameState::Movement { .. } => String::from("Movement"),
|
||||
GameState::CulturalInfluenceResolution(_) => String::from("Cultural Influence Resolution"),
|
||||
GameState::Combat(c) => {
|
||||
format!("Combat Round {} Phase {:?}", c.round, c.phase)
|
||||
pub fn show_globals(game: &Game, shown_player: &ShownPlayer) -> StateUpdate {
|
||||
draw_text(&format!("Age {}", game.age), 1400., 60., 20., BLACK);
|
||||
draw_text(&format!("Round {}", game.round), 1400., 90., 20., BLACK);
|
||||
|
||||
let i = game
|
||||
.players
|
||||
.iter()
|
||||
.position(|p| p.index == game.starting_player_index)
|
||||
.unwrap();
|
||||
let mut players: Vec<_> = game.players.iter().map(|p| p.index).collect();
|
||||
players.rotate_left(i);
|
||||
|
||||
for (i, &p) in players.iter().enumerate() {
|
||||
let player = game.get_player(p);
|
||||
let shown = shown_player.index == p;
|
||||
let prefix = if shown { "* " } else { "" };
|
||||
let suffix = &player_suffix(game, player);
|
||||
let name = player.get_name();
|
||||
let y = 180. + i as f32 * 50.;
|
||||
let x = 1400.;
|
||||
let label = format!("{prefix}{name}{suffix}");
|
||||
if shown {
|
||||
draw_text(&label, x, y, 20., BLACK);
|
||||
} else if Button::new(label)
|
||||
.position(vec2(x, y - 10.))
|
||||
.ui(&mut root_ui())
|
||||
{
|
||||
return StateUpdate::SetShownPlayer(p);
|
||||
}
|
||||
GameState::PlaceSettler { .. } => String::from("Place Settler"),
|
||||
GameState::Finished => String::from("Finished"),
|
||||
}
|
||||
StateUpdate::None
|
||||
}
|
||||
|
||||
fn player_suffix(game: &Game, player: &Player) -> String {
|
||||
let actions_left = if game.current_player_index == player.index {
|
||||
match &game.state {
|
||||
GameState::StatusPhase(_) | GameState::Finished => "",
|
||||
_ => &format!("{} actions Left", game.actions_left),
|
||||
}
|
||||
} else {
|
||||
""
|
||||
};
|
||||
draw_text(&status, 30., 90., 20., BLACK);
|
||||
draw_text(
|
||||
&format!("Actions Left {}", game.actions_left),
|
||||
1400.,
|
||||
30.,
|
||||
20.,
|
||||
BLACK,
|
||||
);
|
||||
|
||||
let moves_left = if game.current_player_index == player.index {
|
||||
match moves_left(&game.state) {
|
||||
None => "",
|
||||
Some(m) => &format!("{m} moves left"),
|
||||
}
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
let active_player = if player.index == game.active_player() {
|
||||
match &game.state {
|
||||
GameState::Playing => "Play Actions",
|
||||
GameState::StatusPhase(ref p) => &format!("Status Phase: {p:?}"),
|
||||
GameState::Movement { .. } => "Movement",
|
||||
GameState::CulturalInfluenceResolution(_) => "Cultural Influence Resolution",
|
||||
GameState::Combat(c) => &format!("Combat Round {} Phase {:?}", c.round, c.phase),
|
||||
GameState::PlaceSettler { .. } => "Place Settler",
|
||||
GameState::Finished => "Finished",
|
||||
}
|
||||
} else {
|
||||
""
|
||||
};
|
||||
|
||||
let status = vec![active_player, actions_left, moves_left]
|
||||
.into_iter()
|
||||
.filter(|s| !s.is_empty())
|
||||
.collect::<Vec<_>>()
|
||||
.join(", ");
|
||||
|
||||
if status.is_empty() {
|
||||
String::new()
|
||||
} else {
|
||||
format!(" ({status})")
|
||||
}
|
||||
}
|
||||
|
||||
fn moves_left(state: &GameState) -> Option<u32> {
|
||||
match state {
|
||||
GameState::Combat(c) => moves_left(&c.initiation),
|
||||
GameState::Movement {
|
||||
movement_actions_left,
|
||||
..
|
||||
} => Some(*movement_actions_left),
|
||||
GameState::PlaceSettler {
|
||||
player_index: _player_index,
|
||||
movement_actions_left,
|
||||
..
|
||||
} => Some(*movement_actions_left),
|
||||
_ => None,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn show_wonders(game: &Game, player_index: usize) {
|
||||
|
|
@ -91,6 +156,7 @@ pub fn show_resources(game: &Game, player_index: usize) {
|
|||
}
|
||||
|
||||
pub fn show_global_controls(game: &Game, state: &State) -> StateUpdate {
|
||||
let player = state.shown_player(game);
|
||||
if game.can_undo() && root_ui().button(vec2(1200., 320.), "Undo") {
|
||||
return StateUpdate::Execute(Action::Undo);
|
||||
}
|
||||
|
|
@ -103,15 +169,15 @@ pub fn show_global_controls(game: &Game, state: &State) -> StateUpdate {
|
|||
StateUpdate::execute_with_warning(
|
||||
Action::Playing(PlayingAction::EndTurn),
|
||||
if left > 0 {
|
||||
vec![(format!("{left} actions left"))]
|
||||
vec![format!("{left} actions left")]
|
||||
} else {
|
||||
vec![]
|
||||
},
|
||||
)
|
||||
}
|
||||
GameState::Playing
|
||||
if !state.has_dialog()
|
||||
&& can_play_action(game)
|
||||
if !state.has_modal_dialog()
|
||||
&& player.can_play_action
|
||||
&& root_ui().button(vec2(1200., 30.), "Move Units") =>
|
||||
{
|
||||
StateUpdate::execute(Action::Playing(PlayingAction::MoveUnits))
|
||||
|
|
|
|||
|
|
@ -5,7 +5,7 @@ use server::player::Player;
|
|||
use server::position::Position;
|
||||
use server::unit::{Unit, UnitType, Units};
|
||||
|
||||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, ShownPlayer, StateUpdate};
|
||||
use crate::construct_ui::{ConstructionPayment, ConstructionProject};
|
||||
use crate::select_ui::{
|
||||
ConfirmSelection, CountSelector, HasCountSelectableObject, SelectionConfirm,
|
||||
|
|
@ -210,8 +210,9 @@ impl ConfirmSelection for RecruitSelection {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn select_dialog(game: &Game, a: &RecruitAmount) -> StateUpdate {
|
||||
pub fn select_dialog(game: &Game, a: &RecruitAmount, player: &ShownPlayer) -> StateUpdate {
|
||||
select_ui::count_dialog(
|
||||
player,
|
||||
"Recruit units",
|
||||
a,
|
||||
|s| s.selectable.clone(),
|
||||
|
|
@ -271,9 +272,10 @@ fn update_selection(
|
|||
)
|
||||
}
|
||||
|
||||
pub fn replace_dialog(game: &Game, sel: &RecruitSelection) -> StateUpdate {
|
||||
pub fn replace_dialog(game: &Game, sel: &RecruitSelection, player: &ShownPlayer) -> StateUpdate {
|
||||
unit_ui::unit_selection_dialog::<RecruitSelection>(
|
||||
game,
|
||||
player,
|
||||
"Replace units",
|
||||
sel,
|
||||
|new| StateUpdate::SetDialog(ActiveDialog::ReplaceUnits(new.clone())),
|
||||
|
|
|
|||
|
|
@ -3,7 +3,7 @@ use server::game::Game;
|
|||
use macroquad::prelude::next_frame;
|
||||
|
||||
use client::client::{init, render_and_update, Features, GameSyncRequest, GameSyncResult};
|
||||
use client::client_state::ControlPlayers;
|
||||
use client::client_state::State;
|
||||
use server::action::Action;
|
||||
use wasm_bindgen::prelude::*;
|
||||
|
||||
|
|
@ -32,7 +32,7 @@ extern "C" {
|
|||
fn send_ready(this: &Control);
|
||||
}
|
||||
|
||||
enum RemoteClientState {
|
||||
enum SyncState {
|
||||
New,
|
||||
WaitingForUpdate,
|
||||
Playing,
|
||||
|
|
@ -41,8 +41,10 @@ enum RemoteClientState {
|
|||
#[wasm_bindgen]
|
||||
struct RemoteClient {
|
||||
control: Control,
|
||||
state: RemoteClientState,
|
||||
state: State,
|
||||
sync_state: SyncState,
|
||||
game: Option<Game>,
|
||||
features: Features,
|
||||
}
|
||||
|
||||
#[macroquad::main("Clash")]
|
||||
|
|
@ -53,32 +55,35 @@ async fn main() {
|
|||
#[wasm_bindgen]
|
||||
impl RemoteClient {
|
||||
pub async fn start() {
|
||||
let features = Features {
|
||||
import_export: false,
|
||||
local_assets: false,
|
||||
};
|
||||
let state = init(&features).await;
|
||||
|
||||
let mut client = RemoteClient {
|
||||
control: get_control(),
|
||||
state: RemoteClientState::New,
|
||||
state,
|
||||
sync_state: SyncState::New,
|
||||
game: None,
|
||||
features,
|
||||
};
|
||||
client.run().await;
|
||||
}
|
||||
|
||||
pub async fn run(&mut self) {
|
||||
let features = Features {
|
||||
import_export: false,
|
||||
local_assets: false,
|
||||
};
|
||||
|
||||
let mut client_state = init(&features).await;
|
||||
|
||||
loop {
|
||||
let p = self.control.receive_player_index().as_f64();
|
||||
if let Some(p) = p {
|
||||
client_state.control_players = ControlPlayers::Own(p as usize);
|
||||
self.state.control_player = Some(p as usize);
|
||||
self.state.show_player = p as usize;
|
||||
}
|
||||
|
||||
let sync_result = self.update_state();
|
||||
|
||||
if let Some(game) = &self.game {
|
||||
let message = render_and_update(game, &mut client_state, &sync_result, &features);
|
||||
let message =
|
||||
render_and_update(game, &mut self.state, &sync_result, &self.features);
|
||||
|
||||
if let GameSyncRequest::ExecuteAction(a) = message {
|
||||
let _ = &mut self.execute_action(&a);
|
||||
|
|
@ -94,26 +99,27 @@ impl RemoteClient {
|
|||
let s = self.control.receive_state();
|
||||
if s.is_object() {
|
||||
log("received state");
|
||||
let game1 = Game::from_data(
|
||||
let g = Game::from_data(
|
||||
serde_wasm_bindgen::from_value(s).expect("game should be of type game data"),
|
||||
);
|
||||
self.game = Some(game1);
|
||||
self.state = RemoteClientState::Playing;
|
||||
self.state.show_player = g.active_player();
|
||||
self.game = Some(g);
|
||||
self.sync_state = SyncState::Playing;
|
||||
self.control.send_ready();
|
||||
return GameSyncResult::Update;
|
||||
}
|
||||
match &self.state {
|
||||
RemoteClientState::New => GameSyncResult::None,
|
||||
RemoteClientState::WaitingForUpdate => GameSyncResult::WaitingForUpdate,
|
||||
RemoteClientState::Playing => GameSyncResult::None,
|
||||
match &self.sync_state {
|
||||
SyncState::New => GameSyncResult::None,
|
||||
SyncState::WaitingForUpdate => GameSyncResult::WaitingForUpdate,
|
||||
SyncState::Playing => GameSyncResult::None,
|
||||
}
|
||||
}
|
||||
|
||||
fn execute_action(&mut self, a: &Action) {
|
||||
if let RemoteClientState::Playing = &self.state {
|
||||
if let SyncState::Playing = &self.sync_state {
|
||||
self.control
|
||||
.send_move(serde_json::to_string(&a).unwrap().as_str());
|
||||
self.state = RemoteClientState::WaitingForUpdate;
|
||||
self.sync_state = SyncState::WaitingForUpdate;
|
||||
} else {
|
||||
log("cannot execute action");
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::client_state::{StateUpdate, StateUpdates};
|
||||
use crate::client_state::{ShownPlayer, StateUpdate, StateUpdates};
|
||||
use crate::dialog_ui::active_dialog_window;
|
||||
use macroquad::hash;
|
||||
use macroquad::math::{bool, Vec2};
|
||||
|
|
@ -20,6 +20,7 @@ pub trait HasCountSelectableObject {
|
|||
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn count_dialog<C, O: HasCountSelectableObject>(
|
||||
player: &ShownPlayer,
|
||||
title: &str,
|
||||
container: &C,
|
||||
get_objects: impl Fn(&C) -> Vec<O>,
|
||||
|
|
@ -30,7 +31,7 @@ pub fn count_dialog<C, O: HasCountSelectableObject>(
|
|||
plus: impl Fn(&C, &O) -> StateUpdate,
|
||||
minus: impl Fn(&C, &O) -> StateUpdate,
|
||||
) -> StateUpdate {
|
||||
active_dialog_window(title, |ui| {
|
||||
active_dialog_window(player, title, |ui| {
|
||||
let mut updates = StateUpdates::new();
|
||||
for (i, p) in get_objects(container).iter().enumerate() {
|
||||
if show(container, p) {
|
||||
|
|
@ -81,12 +82,13 @@ pub trait Selection: ConfirmSelection {
|
|||
|
||||
pub fn selection_dialog<T: Selection>(
|
||||
game: &Game,
|
||||
player: &ShownPlayer,
|
||||
title: &str,
|
||||
sel: &T,
|
||||
on_change: impl Fn(T) -> StateUpdate,
|
||||
on_ok: impl FnOnce(T) -> StateUpdate,
|
||||
) -> StateUpdate {
|
||||
active_dialog_window(title, |ui| {
|
||||
active_dialog_window(player, title, |ui| {
|
||||
for name in sel.all() {
|
||||
let can_sel = sel.can_select(game, name);
|
||||
let is_selected = sel.selected().contains(name);
|
||||
|
|
|
|||
|
|
@ -1,4 +1,4 @@
|
|||
use crate::client_state::{ActiveDialog, StateUpdate};
|
||||
use crate::client_state::{ActiveDialog, ShownPlayer, StateUpdate};
|
||||
use crate::dialog_ui::active_dialog_window;
|
||||
use crate::select_ui;
|
||||
use crate::select_ui::{ConfirmSelection, Selection, SelectionConfirm};
|
||||
|
|
@ -6,22 +6,28 @@ use server::content::advances;
|
|||
use server::game::Game;
|
||||
use server::status_phase::{ChangeGovernmentType, StatusPhaseAction};
|
||||
|
||||
pub fn determine_first_player_dialog(game: &Game) -> StateUpdate {
|
||||
active_dialog_window("Who should be the first player in the next age?", |ui| {
|
||||
for p in &game.players {
|
||||
if ui.button(
|
||||
None,
|
||||
format!("Player {} - {}", p.index, p.civilization.name),
|
||||
) {
|
||||
return StateUpdate::status_phase(StatusPhaseAction::DetermineFirstPlayer(p.index));
|
||||
pub fn determine_first_player_dialog(game: &Game, player: &ShownPlayer) -> StateUpdate {
|
||||
active_dialog_window(
|
||||
player,
|
||||
"Who should be the first player in the next age?",
|
||||
|ui| {
|
||||
for p in &game.players {
|
||||
if ui.button(
|
||||
None,
|
||||
format!("Player {} - {}", p.index, p.civilization.name),
|
||||
) {
|
||||
return StateUpdate::status_phase(StatusPhaseAction::DetermineFirstPlayer(
|
||||
p.index,
|
||||
));
|
||||
}
|
||||
}
|
||||
}
|
||||
StateUpdate::None
|
||||
})
|
||||
StateUpdate::None
|
||||
},
|
||||
)
|
||||
}
|
||||
|
||||
pub fn raze_city_dialog() -> StateUpdate {
|
||||
active_dialog_window("Select a city to raze - or decline.", |ui| {
|
||||
pub fn raze_city_dialog(player: &ShownPlayer) -> StateUpdate {
|
||||
active_dialog_window(player, "Select a city to raze - or decline.", |ui| {
|
||||
if ui.button(None, "Decline") {
|
||||
return StateUpdate::status_phase(StatusPhaseAction::RaseSize1City(None));
|
||||
}
|
||||
|
|
@ -82,10 +88,10 @@ impl ConfirmSelection for ChooseAdditionalAdvances {
|
|||
}
|
||||
}
|
||||
|
||||
pub fn change_government_type_dialog(game: &Game) -> StateUpdate {
|
||||
active_dialog_window("Select additional advances", |ui| {
|
||||
let current = game
|
||||
.get_player(game.active_player())
|
||||
pub fn change_government_type_dialog(game: &Game, player: &ShownPlayer) -> StateUpdate {
|
||||
active_dialog_window(player, "Select additional advances", |ui| {
|
||||
let current = player
|
||||
.get(game)
|
||||
.government()
|
||||
.expect("should have government");
|
||||
for (g, _) in advances::get_governments()
|
||||
|
|
@ -114,9 +120,11 @@ pub fn change_government_type_dialog(game: &Game) -> StateUpdate {
|
|||
pub fn choose_additional_advances_dialog(
|
||||
game: &Game,
|
||||
additional_advances: &ChooseAdditionalAdvances,
|
||||
player: &ShownPlayer,
|
||||
) -> StateUpdate {
|
||||
select_ui::selection_dialog(
|
||||
game,
|
||||
player,
|
||||
"Select additional advances:",
|
||||
additional_advances,
|
||||
|a| StateUpdate::SetDialog(ActiveDialog::ChooseAdditionalAdvances(a)),
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ use server::game::Game;
|
|||
use server::position::Position;
|
||||
use server::unit::{Unit, UnitType};
|
||||
|
||||
use crate::client_state::StateUpdate;
|
||||
use crate::client_state::{ShownPlayer, StateUpdate};
|
||||
use crate::dialog_ui::active_dialog_window;
|
||||
use crate::select_ui::{confirm_update, ConfirmSelection};
|
||||
use crate::{hex_ui, player_ui};
|
||||
|
|
@ -74,19 +74,20 @@ pub fn draw_units(game: &Game) {
|
|||
pub trait UnitSelection: ConfirmSelection {
|
||||
fn selected_units(&self) -> &[u32];
|
||||
fn selected_units_mut(&mut self) -> &mut Vec<u32>;
|
||||
fn can_select(&self, game: &Game, unit: &Unit) -> bool;
|
||||
fn can_select(&self, game: &Game, unit: &Unit) -> bool; // todo return Option<String> for why not
|
||||
fn current_tile(&self) -> Option<Position>;
|
||||
}
|
||||
|
||||
pub fn unit_selection_dialog<T: UnitSelection>(
|
||||
game: &Game,
|
||||
player: &ShownPlayer,
|
||||
title: &str,
|
||||
sel: &T,
|
||||
on_change: impl Fn(T) -> StateUpdate,
|
||||
on_ok: impl FnOnce(T) -> StateUpdate,
|
||||
additional: impl FnOnce(&mut Ui) -> StateUpdate,
|
||||
) -> StateUpdate {
|
||||
active_dialog_window(title, |ui| {
|
||||
active_dialog_window(player, title, |ui| {
|
||||
if let Some(current_tile) = sel.current_tile() {
|
||||
for (p, unit_id) in units_on_tile(game, current_tile) {
|
||||
let unit = game.get_player(p).get_unit(unit_id).unwrap();
|
||||
|
|
@ -142,7 +143,7 @@ pub fn name(u: &UnitType) -> &str {
|
|||
|
||||
pub fn label(unit: &Unit) -> String {
|
||||
let name = name(&unit.unit_type);
|
||||
let res = if !unit.can_move() {
|
||||
let res = if !unit.can_move() || (unit.unit_type == UnitType::Settler && !unit.can_attack()) {
|
||||
" (can't move) "
|
||||
} else if !unit.can_attack() {
|
||||
" (can't attack) "
|
||||
|
|
|
|||
|
|
@ -39,7 +39,7 @@ pub struct Game {
|
|||
pub players: Vec<Player>,
|
||||
pub map: Map,
|
||||
pub starting_player_index: usize,
|
||||
current_player_index: usize,
|
||||
pub current_player_index: usize,
|
||||
pub action_log: Vec<ActionLogItem>,
|
||||
pub action_log_index: usize,
|
||||
pub log: Vec<String>,
|
||||
|
|
@ -672,9 +672,11 @@ impl Game {
|
|||
};
|
||||
}
|
||||
|
||||
fn enemy_player(&self, player_index: usize, position: Position) -> Option<usize> {
|
||||
#[must_use]
|
||||
pub fn enemy_player(&self, player_index: usize, position: Position) -> Option<usize> {
|
||||
self.players.iter().position(|player| {
|
||||
player.index != player_index && !player.get_units(position).is_empty()
|
||||
player.index != player_index
|
||||
&& (!player.get_units(position).is_empty() || player.get_city(position).is_some())
|
||||
})
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -794,6 +794,10 @@ impl Player {
|
|||
}
|
||||
}
|
||||
|
||||
if stack_size == 0 && game.enemy_player(self.index, destination).is_some() {
|
||||
return Err("the stack should contain at least one army unit".to_string());
|
||||
}
|
||||
|
||||
if land_movement
|
||||
&& self
|
||||
.get_units(destination)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue