Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

pirates #166

Merged
merged 1 commit into from
Feb 26, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions client/Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion client/src/action_buttons.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ fn global_move(rc: &RenderContext) -> StateUpdate {
StateUpdate::move_units(
rc,
pos,
if pos.is_some_and(|t| rc.game.map.is_water(t)) {
if pos.is_some_and(|t| rc.game.map.is_sea(t)) {
MoveIntent::Sea
} else {
MoveIntent::Land
Expand Down
1 change: 1 addition & 0 deletions client/src/client.rs
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ fn render_active_dialog(rc: &RenderContext) -> StateUpdate {
ActiveDialog::Theaters(p) => custom_actions_ui::theaters(rc, p),

ActiveDialog::PaymentRequest(c) => custom_phase_ui::custom_phase_payment_dialog(rc, c),
ActiveDialog::PlayerRequest(r) => custom_phase_ui::player_request_dialog(rc, r),
ActiveDialog::ResourceRewardRequest(p) => custom_phase_ui::payment_reward_dialog(rc, p),
ActiveDialog::AdvanceRewardRequest(r) => {
custom_phase_ui::advance_reward_dialog(rc, r, &custom_phase_event_origin(rc).name())
Expand Down
21 changes: 16 additions & 5 deletions client/src/client_state.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,12 @@ use macroquad::prelude::*;
use server::action::Action;
use server::city::{City, MoodState};
use server::content::custom_phase_actions::{
AdvanceRewardRequest, CustomPhaseRequest, PositionRequest, UnitTypeRequest,
AdvanceRewardRequest, CustomPhaseRequest, PlayerRequest, PositionRequest, UnitTypeRequest,
};
use server::cultural_influence::CulturalInfluenceResolution;
use server::events::EventOrigin;
use server::game::{CulturalInfluenceResolution, CurrentMove, Game, GameState};
use server::game::{Game, GameState};
use server::move_units::CurrentMove;
use server::position::Position;
use server::status_phase::{StatusPhaseAction, StatusPhaseState};

Expand Down Expand Up @@ -60,6 +62,7 @@ pub enum ActiveDialog {
ResourceRewardRequest(Payment),
AdvanceRewardRequest(AdvanceRewardRequest),
PaymentRequest(Vec<Payment>),
PlayerRequest(PlayerRequest),
PositionRequest(PositionRequest),
UnitTypeRequest(UnitTypeRequest),
UnitsRequest(UnitsSelection),
Expand Down Expand Up @@ -98,6 +101,7 @@ impl ActiveDialog {
ActiveDialog::ResourceRewardRequest(_) => "trade route selection",
ActiveDialog::AdvanceRewardRequest(_) => "advance selection",
ActiveDialog::PaymentRequest(_) => "custom phase payment request",
ActiveDialog::PlayerRequest(_) => "custom phase player request",
ActiveDialog::PositionRequest(_) => "custom phase position request",
ActiveDialog::UnitTypeRequest(_) => "custom phase unit request",
ActiveDialog::UnitsRequest(_) => "custom phase units request",
Expand Down Expand Up @@ -176,6 +180,7 @@ impl ActiveDialog {
ActiveDialog::PositionRequest(r) => custom_phase_event_help(rc, r.description.as_ref()),
ActiveDialog::UnitTypeRequest(r) => custom_phase_event_help(rc, r.description.as_ref()),
ActiveDialog::UnitsRequest(r) => custom_phase_event_help(rc, r.description.as_ref()),
ActiveDialog::PlayerRequest(r) => custom_phase_event_help(rc, Some(&r.description)),
}
}

Expand Down Expand Up @@ -541,9 +546,15 @@ impl State {
}
CustomPhaseRequest::SelectPosition(r) => ActiveDialog::PositionRequest(r.clone()),
CustomPhaseRequest::SelectUnitType(r) => ActiveDialog::UnitTypeRequest(r.clone()),
CustomPhaseRequest::SelectUnits(r) => ActiveDialog::UnitsRequest(
UnitsSelection::new(r.needed, r.choices.clone(), r.description.clone()),
),
CustomPhaseRequest::SelectUnits(r) => {
ActiveDialog::UnitsRequest(UnitsSelection::new(
r.player,
r.needed,
r.choices.clone(),
r.description.clone(),
))
}
CustomPhaseRequest::SelectPlayer(r) => ActiveDialog::PlayerRequest(r.clone()),
CustomPhaseRequest::BoolRequest => ActiveDialog::BoolRequest,
};
}
Expand Down
20 changes: 10 additions & 10 deletions client/src/construct_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ use server::content::custom_actions::CustomAction;
use server::map::Terrain;
use server::playing_actions::{Construct, PlayingAction, Recruit};
use server::position::Position;
use server::recruit::recruit_cost;

pub fn new_building_positions(
building: Building,
Expand Down Expand Up @@ -109,16 +110,15 @@ impl ConstructionPayment {
city,
None,
),
ConstructionProject::Units(sel) => rc
.shown_player
.recruit_cost(
&sel.amount.units,
city.position,
sel.amount.leader_name.as_ref(),
&sel.replaced_units,
None,
)
.unwrap(),
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;

Expand Down
28 changes: 23 additions & 5 deletions client/src/custom_phase_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,15 @@ use crate::dialog_ui::{cancel_button_with_tooltip, ok_button, OkTooltip};
use crate::hex_ui::Point;
use crate::layout_ui::{bottom_center_anchor, icon_pos};
use crate::payment_ui::{multi_payment_dialog, payment_dialog, Payment};
use crate::player_ui::choose_player_dialog;
use crate::render_context::RenderContext;
use crate::select_ui::ConfirmSelection;
use crate::unit_ui;
use crate::unit_ui::{draw_unit_type, UnitHighlightType, UnitSelection};
use macroquad::math::vec2;
use server::action::Action;
use server::content::custom_phase_actions::{
AdvanceRewardRequest, CustomPhaseEventAction, UnitTypeRequest,
AdvanceRewardRequest, CustomPhaseEventAction, PlayerRequest, UnitTypeRequest,
};
use server::game::Game;
use server::unit::Unit;
Expand Down Expand Up @@ -77,7 +78,7 @@ pub fn unit_request_dialog(rc: &RenderContext, r: &UnitTypeRequest) -> StateUpda

if draw_unit_type(
rc,
&UnitHighlightType::None,
UnitHighlightType::None,
Point::from_vec2(p),
*u,
r.player_index,
Expand All @@ -96,14 +97,21 @@ pub fn unit_request_dialog(rc: &RenderContext, r: &UnitTypeRequest) -> StateUpda
#[derive(Clone)]
pub struct UnitsSelection {
pub needed: u8,
pub player: usize,
pub selectable: Vec<u32>,
pub units: Vec<u32>,
pub description: Option<String>,
}

impl UnitsSelection {
pub fn new(needed: u8, selectable: Vec<u32>, description: Option<String>) -> Self {
pub fn new(
player: usize,
needed: u8,
selectable: Vec<u32>,
description: Option<String>,
) -> Self {
UnitsSelection {
player,
needed,
units: Vec::new(),
selectable,
Expand All @@ -120,6 +128,10 @@ impl UnitSelection for UnitsSelection {
fn can_select(&self, _game: &Game, unit: &Unit) -> bool {
self.selectable.contains(&unit.id)
}

fn player_index(&self) -> usize {
self.player
}
}

impl ConfirmSelection for UnitsSelection {
Expand All @@ -133,7 +145,7 @@ impl ConfirmSelection for UnitsSelection {
} else {
OkTooltip::Invalid(format!(
"Need to select {} units",
self.needed - self.units.len() as u8
self.needed as i8 - self.units.len() as i8
))
}
}
Expand All @@ -147,7 +159,7 @@ pub fn select_units_dialog(rc: &RenderContext, sel: &UnitsSelection) -> StateUpd
})
}

pub(crate) fn bool_request_dialog(rc: &RenderContext) -> StateUpdate {
pub fn bool_request_dialog(rc: &RenderContext) -> StateUpdate {
if ok_button(rc, OkTooltip::Valid("OK".to_string())) {
return bool_answer(true);
}
Expand All @@ -162,3 +174,9 @@ fn bool_answer(answer: bool) -> StateUpdate {
answer,
)))
}

pub fn player_request_dialog(rc: &RenderContext, r: &PlayerRequest) -> StateUpdate {
choose_player_dialog(rc, &r.choices, |p| {
Action::CustomPhaseEvent(CustomPhaseEventAction::SelectPlayer(p))
})
}
2 changes: 1 addition & 1 deletion client/src/event_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ pub fn event_help(rc: &RenderContext, origin: &EventOrigin, do_break: bool) -> V
EventOrigin::Incident(id) => get_incident(*id).description(),
EventOrigin::Leader(l) => {
let l = rc.shown_player.get_leader(l).unwrap();
// todo: leader should have a 2 event sources
// todo: leader should have a 2 event sources - no each event source should have a description
format!(
"{}, {}",
l.first_ability_description, l.second_ability_description
Expand Down
5 changes: 3 additions & 2 deletions client/src/influence_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ use macroquad::prelude::{draw_circle_lines, WHITE};
use server::action::Action;
use server::city::City;
use server::content::custom_actions::CustomAction;
use server::game::CulturalInfluenceResolution;
use server::cultural_influence::{influence_culture_boost_cost, CulturalInfluenceResolution};
use server::player::Player;
use server::player_events::InfluenceCulturePossible;
use server::playing_actions::{InfluenceCultureAttempt, PlayingAction};
Expand Down Expand Up @@ -78,7 +78,8 @@ fn show_city(
closest_city_pos
};

let info = rc.game.influence_culture_boost_cost(
let info = influence_culture_boost_cost(
rc.game,
player.index,
start_position,
city.player_index,
Expand Down
21 changes: 12 additions & 9 deletions client/src/local_client/bin/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@ use client::client::{init, render_and_update, Features, GameSyncRequest, GameSyn
use macroquad::miniquad::window::set_window_size;
use macroquad::prelude::{next_frame, screen_width, vec2};
use macroquad::window::screen_height;
use server::action::execute_action;
use server::advance::do_advance;
use server::city::City;
use server::content::advances::get_advance;
use server::game::{Game, GameData};
use server::map::Terrain;
use server::position::Position;
use server::resource_pile::ResourcePile;
use server::unit::{UnitType, Units};
use server::unit::UnitType;
use std::env;
use std::fs::File;
use std::io::BufReader;
Expand Down Expand Up @@ -52,8 +55,9 @@ pub async fn run(mut game: Game, features: &Features) {
match message {
GameSyncRequest::None => {}
GameSyncRequest::ExecuteAction(a) => {
game.execute_action(a, game.active_player());
state.show_player = game.active_player();
let player_index = game.active_player();
execute_action(&mut game, a, player_index);
state.show_player = player_index;
sync_result = GameSyncResult::Update;
}
GameSyncRequest::Import => {
Expand All @@ -75,9 +79,8 @@ pub fn setup_local_game() -> Game {
game.round = 6;
game.dice_roll_outcomes = vec![1, 1, 10, 10, 10, 10, 10, 10, 10, 10];
let add_unit = |game: &mut Game, pos: &str, player_index: usize, unit_type: UnitType| {
let mut units = Units::empty();
units += &unit_type;
game.recruit(player_index, units, Position::from_offset(pos), None, &[]);
game.get_player_mut(player_index)
.add_unit(Position::from_offset(pos), unit_type);
};

let player_index1 = 0;
Expand Down Expand Up @@ -240,9 +243,9 @@ pub fn setup_local_game() -> Game {
.pieces
.market = Some(1);

game.advance("Voting", player_index1);
game.advance("Free Economy", player_index1);
game.advance("Storage", player_index1);
do_advance(&mut game, &get_advance("Voting"), player_index1);
do_advance(&mut game, &get_advance("Free Economy"), player_index1);
do_advance(&mut game, &get_advance("Storage"), player_index1);
game.players[player_index1].gain_resources(ResourcePile::food(5));

game
Expand Down
20 changes: 9 additions & 11 deletions client/src/move_ui.rs
Original file line number Diff line number Diff line change
@@ -1,21 +1,21 @@
use crate::client_state::{ActiveDialog, StateUpdate};
use crate::dialog_ui::cancel_button_with_tooltip;
use crate::payment_ui::{payment_dialog, Payment};
use crate::render_context::RenderContext;
use crate::unit_ui::{click_unit, unit_selection_clicked};
use macroquad::math::{u32, Vec2};
use macroquad::prelude::Texture2D;
use server::action::Action;
use server::events::EventOrigin;
use server::game::{CurrentMove, Game, GameState};
use server::game::{Game, GameState};
use server::move_units::{move_units_destinations, CurrentMove};
use server::payment::PaymentOptions;
use server::player::Player;
use server::position::Position;
use server::resource_pile::ResourcePile;
use server::unit::{MoveUnits, MovementAction, Unit, UnitType};
use std::collections::HashSet;

use crate::client_state::{ActiveDialog, StateUpdate};
use crate::dialog_ui::cancel_button_with_tooltip;
use crate::payment_ui::{payment_dialog, Payment};
use crate::render_context::RenderContext;
use crate::unit_ui::{click_unit, unit_selection_clicked};

#[derive(Clone, Copy)]
pub enum MoveIntent {
Land,
Expand Down Expand Up @@ -64,8 +64,7 @@ pub fn possible_destinations(
let player = game.get_player(player_index);
let mut modifiers = HashSet::new();

let mut res = player
.move_units_destinations(game, units, start, None)
let mut res = move_units_destinations(player, game, units, start, None)
.unwrap_or_default()
.into_iter()
.map(|route| {
Expand All @@ -78,8 +77,7 @@ pub fn possible_destinations(

player.units.iter().for_each(|u| {
if u.unit_type.is_ship()
&& player
.move_units_destinations(game, units, start, Some(u.id))
&& move_units_destinations(player, game, units, start, Some(u.id))
.is_ok_and(|v| v.iter().any(|route| route.destination == u.position))
{
res.push(MoveDestination::Carrier(u.id));
Expand Down
23 changes: 20 additions & 3 deletions client/src/player_ui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,10 @@ use crate::action_buttons::action_buttons;
use crate::city_ui::city_labels;
use crate::client::Features;
use crate::client_state::StateUpdate;
use crate::dialog_ui::{ok_button, OkTooltip};
use crate::layout_ui::{
bottom_center_texture, bottom_right_texture, icon_pos, left_mouse_button_pressed_in_rect,
top_center_texture, ICON_SIZE,
bottom_center_texture, bottom_centered_text, bottom_right_texture, icon_pos,
left_mouse_button_pressed_in_rect, top_center_texture, ICON_SIZE,
};
use crate::map_ui::terrain_name;
use crate::render_context::RenderContext;
Expand All @@ -15,7 +16,8 @@ use macroquad::math::vec2;
use macroquad::prelude::*;
use server::action::Action;
use server::consts::ARMY_MOVEMENT_REQUIRED_ADVANCE;
use server::game::{CurrentMove, Game, GameState, MoveState};
use server::game::{Game, GameState};
use server::move_units::{CurrentMove, MoveState};
use server::playing_actions::PlayingAction;
use server::resource::ResourceType;
use server::unit::MovementAction;
Expand Down Expand Up @@ -326,3 +328,18 @@ fn end_move(game: &Game) -> StateUpdate {
},
)
}

pub fn choose_player_dialog(
rc: &RenderContext,
choices: &[usize],
execute: impl Fn(usize) -> Action,
) -> StateUpdate {
let player = rc.shown_player.index;
if rc.can_control_active_player() && choices.contains(&player) {
bottom_centered_text(rc, &format!("Select {}", rc.shown_player.get_name()));
if ok_button(rc, OkTooltip::Valid("Select".to_string())) {
return StateUpdate::execute(execute(player));
}
}
StateUpdate::None
}
Loading