mirror of
https://git.ngram.ca/OpenJam/rc-servers
synced 2026-08-23 23:08:52 +00:00
Implement tech tree cube unlock
This commit is contained in:
@@ -187,30 +187,28 @@ impl <C: Clone + Send> super::ConfigProvider<C> for CubeConfig {
|
||||
Typed::IntArr(keys_vec.into())
|
||||
}
|
||||
|
||||
fn tech_tree_nodes(&self, unlocked_cubes: &std::collections::HashSet<u32>) -> Typed<C> {
|
||||
let mut seen_cubes = std::collections::HashSet::with_capacity(self.cubes.len());
|
||||
let mut needed_cubes = std::collections::HashSet::with_capacity(self.cubes.len());
|
||||
let mut typed_nodes = Vec::new();
|
||||
fn tech_tree_nodes(&self) -> super::TechTreeNodeProvider {
|
||||
let mut nodes = indexmap::IndexMap::with_capacity(self.cubes.len());
|
||||
for cube in self.cubes.values() {
|
||||
if let Some(tree_data) = &cube.tree {
|
||||
let is_unlocked = unlocked_cubes.contains(&cube.id);
|
||||
let is_unlockable = tree_data.requires.iter().all(|id| unlocked_cubes.contains(id));
|
||||
tree_data.neighbours.iter().for_each(|id| { needed_cubes.insert(*id); });
|
||||
seen_cubes.insert(cube.id);
|
||||
let node_data = tree_data.to_owned().into_data(cube.id, is_unlocked, is_unlockable);
|
||||
typed_nodes.push(node_data.as_transmissible_key_val());
|
||||
nodes.insert(cube.id, tree_data.to_owned());
|
||||
}
|
||||
}
|
||||
for needed_cube_id in needed_cubes {
|
||||
if !seen_cubes.contains(&needed_cube_id) {
|
||||
log::warn!("Tech tree needs cube {} but it doesn't have tree info", needed_cube_id);
|
||||
nodes.shrink_to_fit();
|
||||
super::TechTreeNodeProvider {
|
||||
tree: nodes,
|
||||
}
|
||||
}
|
||||
|
||||
fn tech_tree_costs(&self) -> std::collections::HashMap<String, u32> { // cube id (hex) -> tech point cost
|
||||
let mut costs = std::collections::HashMap::with_capacity(self.cubes.len());
|
||||
for cube in self.cubes.values() {
|
||||
if let Some(tree_data) = &cube.tree {
|
||||
costs.insert(hex::encode(cube.id.to_be_bytes()), tree_data.tech_points);
|
||||
}
|
||||
}
|
||||
Typed::Dict(Dict {
|
||||
key_ty: TypePrefix::Str,
|
||||
val_ty: TypePrefix::HashMap,
|
||||
items: typed_nodes,
|
||||
})
|
||||
costs.shrink_to_fit(); // probably unnecessary, but free memory usage reduction!
|
||||
costs
|
||||
}
|
||||
|
||||
fn ids(&self) -> Vec<u32> {
|
||||
|
||||
@@ -10,6 +10,9 @@ pub use validation::{SelfValidator, ValidationInfo, ValidationMessage};
|
||||
mod campaign;
|
||||
pub use campaign::{CampaignResolver, CompleteCampaignProvider};
|
||||
|
||||
mod tech_tree;
|
||||
pub use tech_tree::TechTreeNodeProvider;
|
||||
|
||||
pub type ConfigImpl = CubeConfig;
|
||||
|
||||
fn __must_impl<T: ConfigProvider<()>>() {}
|
||||
|
||||
33
rc_core/src/persist/config/tech_tree.rs
Normal file
33
rc_core/src/persist/config/tech_tree.rs
Normal file
@@ -0,0 +1,33 @@
|
||||
use polariton::operation::{Typed, Dict};
|
||||
use polariton::serdes::TypePrefix;
|
||||
|
||||
pub struct TechTreeNodeProvider {
|
||||
// the order of this probably doesn't matter but for consistency... let's do it this way
|
||||
pub(super) tree: indexmap::IndexMap<u32, crate::persist::TechTreeData>,
|
||||
}
|
||||
|
||||
impl TechTreeNodeProvider {
|
||||
pub fn tech_tree_nodes<C>(&self, unlocked_cubes: &std::collections::HashSet<u32>) -> Typed<C> {
|
||||
let mut seen_cubes = std::collections::HashSet::with_capacity(self.tree.len());
|
||||
let mut needed_cubes = std::collections::HashSet::with_capacity(self.tree.len());
|
||||
let mut typed_nodes = Vec::new();
|
||||
for (cube_id, tree_data) in self.tree.iter() {
|
||||
let is_unlocked = unlocked_cubes.contains(&cube_id);
|
||||
let is_unlockable = tree_data.requires.iter().all(|id| unlocked_cubes.contains(id));
|
||||
tree_data.neighbours.iter().for_each(|id| { needed_cubes.insert(*id); });
|
||||
seen_cubes.insert(cube_id);
|
||||
let node_data = tree_data.to_owned().into_data(*cube_id, is_unlocked, is_unlockable);
|
||||
typed_nodes.push(node_data.as_transmissible_key_val());
|
||||
}
|
||||
for needed_cube_id in needed_cubes {
|
||||
if !seen_cubes.contains(&needed_cube_id) {
|
||||
log::warn!("Tech tree needs cube {} but it doesn't have tree info", needed_cube_id);
|
||||
}
|
||||
}
|
||||
Typed::Dict(Dict {
|
||||
key_ty: TypePrefix::Str,
|
||||
val_ty: TypePrefix::HashMap,
|
||||
items: typed_nodes,
|
||||
})
|
||||
}
|
||||
}
|
||||
@@ -7,7 +7,8 @@ pub trait ConfigProvider<C: Clone> {
|
||||
fn weapon_list(&self) -> Typed<C>;
|
||||
fn weapon_upgrade_list(&self) -> Typed<C>;
|
||||
fn weapon_keys(&self) -> Typed<C>;
|
||||
fn tech_tree_nodes(&self, unlocked_cubes: &std::collections::HashSet<u32>) -> Typed<C>;
|
||||
fn tech_tree_nodes(&self) -> super::TechTreeNodeProvider;
|
||||
fn tech_tree_costs(&self) -> std::collections::HashMap<String, u32>; // cube id (hex) -> tech point cost
|
||||
fn ids(&self) -> Vec<u32>;
|
||||
fn regen_config(&self) -> Typed<C>;
|
||||
fn after_battle_vote_config(&self) -> Typed<C>;
|
||||
|
||||
Reference in New Issue
Block a user