From a9126f7e25886f8195eabf7c56cd8a8291b194ea Mon Sep 17 00:00:00 2001 From: Joshua Barretto Date: Tue, 14 Jul 2020 23:32:25 +0100 Subject: [PATCH] Simulation improvements, removed block glows --- common/src/terrain/block.rs | 5 +++-- world/src/sim2/mod.rs | 33 +++++++++++++++++++++++---------- world/src/site/dungeon/mod.rs | 10 ++++++---- world/src/site/economy.rs | 6 +++--- 4 files changed, 35 insertions(+), 19 deletions(-) diff --git a/common/src/terrain/block.rs b/common/src/terrain/block.rs index 3a87f8f767..cc0188d266 100644 --- a/common/src/terrain/block.rs +++ b/common/src/terrain/block.rs @@ -204,8 +204,9 @@ impl BlockKind { pub fn get_glow(&self) -> Option { match self { - BlockKind::StreetLamp | BlockKind::StreetLampTall => Some(20), - BlockKind::Velorite | BlockKind::VeloriteFrag => Some(10), + // TODO: When we have proper volumetric lighting + //BlockKind::StreetLamp | BlockKind::StreetLampTall => Some(20), + //BlockKind::Velorite | BlockKind::VeloriteFrag => Some(10), _ => None, } } diff --git a/world/src/sim2/mod.rs b/world/src/sim2/mod.rs index ad0d8b4ca9..1a45d48511 100644 --- a/world/src/sim2/mod.rs +++ b/world/src/sim2/mod.rs @@ -56,7 +56,7 @@ pub fn simulate(index: &mut Index, world: &mut WorldSim) { write!(f, "{:?},", site.economy.values[*g].unwrap_or(-1.0)).unwrap(); } for g in Good::list() { - write!(f, "{:?},", site.economy.labor_values[*g]).unwrap(); + write!(f, "{:?},", site.economy.labor_values[*g].unwrap_or(-1.0)).unwrap(); } for g in Good::list() { write!(f, "{:?},", site.economy.stocks[*g]).unwrap(); @@ -121,7 +121,7 @@ pub fn tick_site_economy(index: &mut Index, site: Id, dt: f32) { } } - let mut supply = MapVec::from_default(0.0); + let mut supply = site.economy.stocks.clone();//MapVec::from_default(0.0); for (labor, (output_good, _)) in productivity.iter() { supply[*output_good] += site.economy.yields[labor] * site.economy.labors[labor] * site.economy.pop; @@ -170,7 +170,8 @@ pub fn tick_site_economy(index: &mut Index, site: Id, dt: f32) { // Redistribute workforce according to relative good values let labor_ratios = productivity.clone().map(|labor, (output_good, _)| { - site.economy.values[output_good].unwrap_or(0.0) * site.economy.yields[labor] + site.economy.values[output_good].unwrap_or(0.0) + * site.economy.productivity[labor] //(site.economy.prices[output_good] - site.economy.material_costs[output_good]) * site.economy.yields[labor] //* demand[output_good] / supply[output_good].max(0.001) }); @@ -184,7 +185,8 @@ pub fn tick_site_economy(index: &mut Index, site: Id, dt: f32) { // Production let stocks_before = site.economy.stocks.clone(); - site.economy.labor_values = Default::default(); + let mut total_labor_values = MapVec::<_, f32>::default(); + let mut total_outputs = MapVec::<_, f32>::default(); for (labor, orders) in orders.iter() { let scale = if let Some(labor) = labor { site.economy.labors[*labor] @@ -218,7 +220,7 @@ pub fn tick_site_economy(index: &mut Index, site: Id, dt: f32) { let used = quantity * labor_productivity; // Material cost of each factor of production - total_materials_cost += used * site.economy.labor_values[*good]; + total_materials_cost += used * site.economy.labor_values[*good].unwrap_or(0.0); // Deplete stocks accordingly site.economy.stocks[*good] = (site.economy.stocks[*good] - used).max(0.0); @@ -229,22 +231,33 @@ pub fn tick_site_economy(index: &mut Index, site: Id, dt: f32) { let (stock, rate) = productivity[*labor]; let workers = site.economy.labors[*labor] * site.economy.pop; let final_rate = rate; - let yield_per_worker = labor_productivity * final_rate * (1.0 + workers / 100.0); + let yield_per_worker = labor_productivity * final_rate * (1.0 + workers / 100.0).min(3.0); site.economy.yields[*labor] = yield_per_worker; site.economy.productivity[*labor] = labor_productivity; let total_output = yield_per_worker * workers; site.economy.stocks[stock] += total_output; // Materials cost per unit - let material_cost_per_unit = total_materials_cost / total_output.max(0.001); - site.economy.material_costs[stock] = material_cost_per_unit; - site.economy.labor_values[stock] += material_cost_per_unit; + site.economy.material_costs[stock] = total_materials_cost / total_output.max(0.001); // Labor costs let wages = 1.0; - site.economy.labor_values[stock] += workers * wages / total_output.max(0.001); + let total_labor_cost = workers * wages; + + total_labor_values[stock] += total_materials_cost + total_labor_cost; + total_outputs[stock] += total_output; } } + // Update labour values per unit + site.economy.labor_values = total_labor_values.map(|stock, tlv| { + let total_output = total_outputs[stock]; + if total_output > 0.01 { + Some(tlv / total_outputs[stock]) + } else { + None + } + }); + // Decay stocks site.economy .stocks diff --git a/world/src/site/dungeon/mod.rs b/world/src/site/dungeon/mod.rs index 201b06d371..3e8d7ecc5e 100644 --- a/world/src/site/dungeon/mod.rs +++ b/world/src/site/dungeon/mod.rs @@ -396,17 +396,19 @@ impl Floor { origin: Vec3, supplement: &mut ChunkSupplement, ) { - let stair_rcenter = Vec3::from((self.stair_tile + self.tile_offset) - .map(|e| e * TILE_SIZE + TILE_SIZE / 2)); + let stair_rcenter = + Vec3::from((self.stair_tile + self.tile_offset).map(|e| e * TILE_SIZE + TILE_SIZE / 2)); if area.contains_point(stair_rcenter.xy()) { let offs = Vec2::new(rng.gen_range(-1.0, 1.0), rng.gen_range(-1.0, 1.0)) .try_normalized() .unwrap_or(Vec2::unit_y()) - * FLOOR_SIZE.x as f32 / 2.0 - 8.0; + * FLOOR_SIZE.x as f32 + / 2.0 + - 8.0; supplement.add_entity( EntityInfo::at((origin + stair_rcenter).map(|e| e as f32) + Vec3::from(offs)) - .into_waypoint() + .into_waypoint(), ); } diff --git a/world/src/site/economy.rs b/world/src/site/economy.rs index 26dae4c831..2c59d5c31b 100644 --- a/world/src/site/economy.rs +++ b/world/src/site/economy.rs @@ -36,7 +36,7 @@ pub struct Economy { pub marginal_surplus: MapVec, pub values: MapVec>, - pub labor_values: MapVec, + pub labor_values: MapVec>, pub material_costs: MapVec, pub labors: MapVec, @@ -91,7 +91,7 @@ impl Economy { (Farmer, (Flour, 2.0)), (Lumberjack, (Wood, 0.5)), (Miner, (Stone, 0.5)), - (Fisher, (Meat, 3.0)), + (Fisher, (Meat, 4.0)), (Hunter, (Meat, 1.0)), (Cook, (Food, 16.0)), ], @@ -102,7 +102,7 @@ impl Economy { pub fn replenish(&mut self, time: f32) { use rand::Rng; - for (i, (g, v)) in [(Wheat, 195.0), (Logs, 120.0), (Rock, 120.0), (Game, 20.0)] + for (i, (g, v)) in [(Wheat, 50.0), (Logs, 20.0), (Rock, 120.0), (Game, 12.0), (Fish, 10.0)] .iter() .enumerate() {