1
0
mirror of https://git.ngram.ca/OpenJam/rc-servers synced 2026-08-23 23:08:52 +00:00

Add configurable team selection for #44

This commit is contained in:
NG (Graham)
2026-03-23 21:07:14 -04:00
parent 0a93432783
commit 56e4239c08
19 changed files with 214 additions and 26 deletions

View File

@@ -89,12 +89,13 @@ impl std::convert::From<Vote> for crate::data::voting::Vote {
}
}
#[derive(Serialize, Deserialize, Clone, Debug, Copy)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct GameMode {
pub respawn_heal_duration: f32,
pub respawn_full_heal_duration: f32,
pub kill_limit: i32,
pub game_time_m: i32,
pub team_chooser: super::TeamChooser,
}
impl std::convert::From<GameMode> for crate::data::game_mode::GameModeConfig {
@@ -108,7 +109,7 @@ impl std::convert::From<GameMode> for crate::data::game_mode::GameModeConfig {
}
}
#[derive(Serialize, Deserialize, Clone, Debug, Copy)]
#[derive(Serialize, Deserialize, Clone, Debug)]
pub struct GameModes {
pub battle_arena: GameMode,
pub elimination: GameMode,
@@ -337,24 +338,28 @@ fn default_game_modes() -> GameModes {
respawn_full_heal_duration: 0.5,
kill_limit: 0,
game_time_m: 20,
team_chooser: super::TeamChooser::Alternating,
},
elimination: GameMode {
respawn_heal_duration: 10.0,
respawn_full_heal_duration: 0.5,
kill_limit: 10,
game_time_m: 10,
team_chooser: super::TeamChooser::Alternating,
},
pit: GameMode {
respawn_heal_duration: 20.0,
respawn_full_heal_duration: 0.5,
kill_limit: 0,
game_time_m: 15,
team_chooser: super::TeamChooser::OneOnAll,
},
team_deathmatch: GameMode {
respawn_heal_duration: 10.0,
respawn_full_heal_duration: 0.5,
kill_limit: 10,
game_time_m: 10,
team_chooser: super::TeamChooser::Alternating,
},
}
}

View File

@@ -241,7 +241,7 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
}
fn game_mode_config(&self) -> Typed<C> {
let game_mode_data: crate::data::game_mode::GameModeConfigs = self.battle.games.into();
let game_mode_data: crate::data::game_mode::GameModeConfigs = self.battle.games.clone().into();
game_mode_data.as_transmissible()
}
@@ -347,7 +347,7 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
}
fn gamemodes(&self) -> crate::data::game_mode::GameModeConfigs {
self.battle.games.into()
self.battle.games.clone().into()
}
fn singleplayer_details(&self) -> super::SingleplayerConfig {
@@ -569,4 +569,13 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
fn garage_slot_limit(&self) -> i32 {
self.settings.gameplay.garages_limit
}
fn team_choosers(&self) -> super::TeamChoosers {
super::TeamChoosers {
battle_arena: self.battle.games.battle_arena.team_chooser.clone(),
elimination: self.battle.games.elimination.team_chooser.clone(),
pit: self.battle.games.pit.team_chooser.clone(),
team_deathmatch: self.battle.games.team_deathmatch.team_chooser.clone(),
}
}
}

View File

@@ -2,7 +2,7 @@ mod cubes_json;
pub use cubes_json::CubeConfig;
mod traits;
pub use traits::{ConfigProvider, DevMessageProvider, ServerConfig, GarageUpgrades, GarageUpgradeIncrement, ChatSystemConfig, GameEventSequence, GameEvents, GameRotationStrategy, GameEvent, GameMap, GameVisibility, GameType, SingleplayerConfig, VehicleInfo, VehicleDescriptor, QueueChangeMode, Point, Sphere, MapConfig, LinksConfig, FakePlayer, ClientEmulator, EnergyConfig, BattleArenaResolver, PitSettings, PitWinCondition, TeamDeathMatchSettings, ShopEntriesResolver, ShopAction, ShopGain, PromoCode, MultiplayerSettings, BattleArenaCrystalParams, VehicleValidators};
pub use traits::{ConfigProvider, DevMessageProvider, ServerConfig, GarageUpgrades, GarageUpgradeIncrement, ChatSystemConfig, GameEventSequence, GameEvents, GameRotationStrategy, GameEvent, GameMap, GameVisibility, GameType, SingleplayerConfig, VehicleInfo, VehicleDescriptor, QueueChangeMode, Point, Sphere, MapConfig, LinksConfig, FakePlayer, ClientEmulator, EnergyConfig, BattleArenaResolver, PitSettings, PitWinCondition, TeamDeathMatchSettings, ShopEntriesResolver, ShopAction, ShopGain, PromoCode, MultiplayerSettings, BattleArenaCrystalParams, VehicleValidators, TeamChoosers};
mod validation;
pub use validation::{SelfValidator, ValidationInfo, ValidationMessage};

View File

@@ -42,6 +42,7 @@ pub trait ConfigProvider<C: Clone> {
fn promo_codes(&self) -> std::collections::HashMap<String, PromoCode>;
fn vehicle_validation(&self) -> VehicleValidators;
fn garage_slot_limit(&self) -> i32;
fn team_choosers(&self) -> TeamChoosers;
}
pub struct DevMessageProvider<C: Clone> {
@@ -547,3 +548,10 @@ pub struct VehicleValidators {
pub singleplayer: crate::persist::VehicleValidator,
pub campaigns: std::collections::HashMap<String, crate::persist::VehicleValidator>,
}
pub struct TeamChoosers {
pub battle_arena: crate::persist::TeamChooser,
pub elimination: crate::persist::TeamChooser,
pub pit: crate::persist::TeamChooser,
pub team_deathmatch: crate::persist::TeamChooser,
}

View File

@@ -44,6 +44,9 @@ pub use maps::{MapsConfig, MapConfig};
mod item_shop;
pub use item_shop::{ItemShopConfig, ItemBundle};
mod team_chooser;
pub use team_chooser::TeamChooser;
mod vehicle_validator;
pub use vehicle_validator::VehicleValidator;

View File

@@ -0,0 +1,17 @@
use serde::{Serialize, Deserialize};
#[derive(Serialize, Deserialize, Clone, Debug)]
#[serde(tag = "choice")]
pub enum TeamChooser {
Alternating,
AllOnOne {
team: u8,
},
#[serde(alias = "Pit")]
OneOnAll,
// TODO more built-in choosers
Custom {
#[serde(alias = "library")]
path: String,
},
}

View File

@@ -22,17 +22,9 @@ impl super::LobbyUser for UserData {
} else {
polariton_server::operations::SimpleOpError::with_code(crate::data::error_codes::LobbyReasonCode::from_service_error(e.error_code()) as i16)
}
})
}
async fn team_chooser(&self, game: &super::GameDescriptor) -> super::StandardTeamChooser {
match game.mode {
crate::data::game_mode::GameMode::Pit => super::StandardTeamChooser::OnePer,
_ => super::StandardTeamChooser::alternating(),
}
}
async fn start_game(
&self,
game: super::GameDescriptor,

View File

@@ -9,7 +9,7 @@ pub enum StandardTeamChooser {
AllOn(u8),
/// Each player will be put on their own team (like in Pit mode)
OnePer,
//Custom(Box<dyn TeamChooser>),
Custom(Box<dyn TeamChooser>),
}
impl StandardTeamChooser {
@@ -24,7 +24,7 @@ impl TeamChooser for StandardTeamChooser {
Self::Alternating(t) => t.choose_team(game, index, player),
Self::AllOn(team) => *team as i32,
Self::OnePer => index as i32,
//Self::Custom(t) => t.choose_team(game, index, player),
Self::Custom(t) => t.choose_team(game, index, player),
}
}
}

View File

@@ -279,7 +279,6 @@ pub enum UserRole {
pub trait LobbyUser {
fn user_id(&self) -> i32;
async fn player_data(&self, cpu_counter: &crate::cubes::CpuListParser) -> Result<crate::data::player_data::PlayerData, polariton_server::operations::SimpleOpError>;
async fn team_chooser(&self, game: &GameDescriptor) -> super::StandardTeamChooser;
#[allow(clippy::too_many_arguments)]
async fn start_game(&self, game: GameDescriptor, players: Vec<PlayerLobbyDescriptor>, factory: &dyn oj_rc_factory::VehicleFactoryAdapter, cpu_counter: &crate::cubes::CpuListParser, weapon_lister: &crate::cubes::WeaponListParser, team_chooser: &dyn super::TeamChooser, missing_players: usize) -> Result<FakePlayers, polariton_server::operations::SimpleOpError>;
#[allow(clippy::too_many_arguments)]