mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Make power bar configurable
This commit is contained in:
@@ -16,6 +16,8 @@ pub struct BattleConfig {
|
|||||||
pub multiplayer: super::MultiplayerConfig,
|
pub multiplayer: super::MultiplayerConfig,
|
||||||
#[serde(default = "default_maps")]
|
#[serde(default = "default_maps")]
|
||||||
pub maps: super::MapsConfig,
|
pub maps: super::MapsConfig,
|
||||||
|
#[serde(default = "default_energy")]
|
||||||
|
pub energy: EnergyConfig,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Serialize, Deserialize, Clone, Debug)]
|
#[derive(Serialize, Deserialize, Clone, Debug)]
|
||||||
@@ -234,6 +236,12 @@ impl GameType {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Serialize, Deserialize, Clone, Debug, Copy)]
|
||||||
|
pub struct EnergyConfig {
|
||||||
|
pub refill_rate_per_s: f32,
|
||||||
|
pub total: u32,
|
||||||
|
}
|
||||||
|
|
||||||
fn default_game_modes() -> GameModes {
|
fn default_game_modes() -> GameModes {
|
||||||
GameModes {
|
GameModes {
|
||||||
battle_arena: GameMode {
|
battle_arena: GameMode {
|
||||||
@@ -498,3 +506,10 @@ fn default_maps() -> super::MapsConfig {
|
|||||||
map: super::maps::default_map(),
|
map: super::maps::default_map(),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn default_energy() -> EnergyConfig {
|
||||||
|
EnergyConfig {
|
||||||
|
refill_rate_per_s: 0.1, // should take 10s to refill
|
||||||
|
total: 12_550,
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
@@ -434,4 +434,11 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
|
|||||||
implementation: player.implementation.clone().to_config(),
|
implementation: player.implementation.clone().to_config(),
|
||||||
}).collect()
|
}).collect()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn energy(&self) -> super::EnergyConfig {
|
||||||
|
super::EnergyConfig {
|
||||||
|
refill_rate: self.battle.energy.refill_rate_per_s,
|
||||||
|
total: self.battle.energy.total,
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -2,7 +2,7 @@ mod cubes_json;
|
|||||||
pub use cubes_json::CubeConfig;
|
pub use cubes_json::CubeConfig;
|
||||||
|
|
||||||
mod traits;
|
mod traits;
|
||||||
pub use traits::{ConfigProvider, CompleteCampaignProvider, DevMessageProvider, ServerConfig, GarageUpgrades, GarageUpgradeIncrement, ChatSystemConfig, GameEventSequence, GameEvents, GameRotationStrategy, GameEvent, GameMap, GameVisibility, GameType, SingleplayerConfig, VehicleInfo, VehicleDescriptor, QueueChangeMode, Point, Sphere, MapConfig, LinksConfig, FakePlayer, ClientEmulator};
|
pub use traits::{ConfigProvider, CompleteCampaignProvider, DevMessageProvider, ServerConfig, GarageUpgrades, GarageUpgradeIncrement, ChatSystemConfig, GameEventSequence, GameEvents, GameRotationStrategy, GameEvent, GameMap, GameVisibility, GameType, SingleplayerConfig, VehicleInfo, VehicleDescriptor, QueueChangeMode, Point, Sphere, MapConfig, LinksConfig, FakePlayer, ClientEmulator, EnergyConfig};
|
||||||
|
|
||||||
pub type ConfigImpl = CubeConfig;
|
pub type ConfigImpl = CubeConfig;
|
||||||
|
|
||||||
|
|||||||
@@ -34,6 +34,7 @@ pub trait ConfigProvider<C: Clone> {
|
|||||||
fn maps(&self) -> std::collections::HashMap<GameMap, MapConfig>;
|
fn maps(&self) -> std::collections::HashMap<GameMap, MapConfig>;
|
||||||
fn url_links(&self) -> LinksConfig;
|
fn url_links(&self) -> LinksConfig;
|
||||||
fn fake_players(&self) -> Vec<FakePlayer>;
|
fn fake_players(&self) -> Vec<FakePlayer>;
|
||||||
|
fn energy(&self) -> EnergyConfig;
|
||||||
}
|
}
|
||||||
|
|
||||||
pub struct CompleteCampaignProvider {
|
pub struct CompleteCampaignProvider {
|
||||||
@@ -379,3 +380,9 @@ pub struct FakePlayer {
|
|||||||
pub enum ClientEmulator {
|
pub enum ClientEmulator {
|
||||||
Experiment,
|
Experiment,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[derive(Clone, Debug)]
|
||||||
|
pub struct EnergyConfig {
|
||||||
|
pub refill_rate: f32,
|
||||||
|
pub total: u32,
|
||||||
|
}
|
||||||
|
|||||||
@@ -123,7 +123,7 @@ pub fn handler(init_ctx: &crate::InitConfig) -> OperationsHandler<crate::UserTy>
|
|||||||
.add(crf_config::crf_config_provider())
|
.add(crf_config::crf_config_provider())
|
||||||
.add(weapon_stats::weapon_config_provider(&init_ctx.cubes))
|
.add(weapon_stats::weapon_config_provider(&init_ctx.cubes))
|
||||||
.add(movement_stats::movement_config_provider(&init_ctx.cubes))
|
.add(movement_stats::movement_config_provider(&init_ctx.cubes))
|
||||||
.add(power_bar_stats::power_bar_provider())
|
.add(power_bar_stats::power_bar_provider(&init_ctx.cubes))
|
||||||
.add(damage_boost_stats::damage_boost_provider())
|
.add(damage_boost_stats::damage_boost_provider())
|
||||||
.add(battle_arena_config::battle_arena_config_provider())
|
.add(battle_arena_config::battle_arena_config_provider())
|
||||||
.add(cpu_limits_config::cpu_config_provider())
|
.add(cpu_limits_config::cpu_config_provider())
|
||||||
|
|||||||
@@ -1,16 +1,17 @@
|
|||||||
use polariton_server::operations::SimpleFunc;
|
use polariton_server::operations::Immediate;
|
||||||
use polariton::operation::{ParameterTable, Typed};
|
use polariton::operation::{ParameterTable, Typed};
|
||||||
|
|
||||||
const PARAM_KEY: u8 = 61;
|
const PARAM_KEY: u8 = 61;
|
||||||
|
|
||||||
pub(super) fn power_bar_provider() -> SimpleFunc<51, crate::UserTy, impl (Fn(ParameterTable, &crate::UserTy) -> Result<ParameterTable, i16>) + Sync + Sync> {
|
pub(super) fn power_bar_provider(conf: &oj_rc_core::ConfigImpl) -> Immediate<51, crate::UserTy> {
|
||||||
SimpleFunc::new(|params, _| {
|
let energy_conf = <oj_rc_core::ConfigImpl as oj_rc_core::ConfigProvider<()>>::energy(conf);
|
||||||
let mut params = params.to_dict();
|
Immediate::new(|| {
|
||||||
|
let mut params = ParameterTable::with_capacity(2);
|
||||||
params.insert(PARAM_KEY, Typed::HashMap(vec![
|
params.insert(PARAM_KEY, Typed::HashMap(vec![
|
||||||
(Typed::Str("refillRatePerSecond".into()), Typed::Float(0.10)), // should take 10s to refill
|
(Typed::Str("refillRatePerSecond".into()), Typed::Float(energy_conf.refill_rate)),
|
||||||
(Typed::Str("powerForAllRobots".into()), Typed::Int(12_550 /* converted to u32 */)),
|
(Typed::Str("powerForAllRobots".into()), Typed::Int(energy_conf.total as _)),
|
||||||
].into()
|
].into()
|
||||||
));
|
));
|
||||||
Ok(params.into())
|
params
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user