Skip to content

Commit

Permalink
electricity affect productivity and show info about that in UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Uriopass committed Jan 17, 2024
1 parent febadad commit bc78f3d
Show file tree
Hide file tree
Showing 24 changed files with 542 additions and 169 deletions.
37 changes: 28 additions & 9 deletions base_mod/companies.lua
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ data:extend {
size = 10.0,
asset_location = "bakery.glb",
price = 1000,
power_consumption = "200W",
},
{
type = "goods-company",
Expand All @@ -41,6 +42,7 @@ data:extend {
size = 80.0,
asset_location = "flour_factory.glb",
price = 1000,
power_consumption = "10kW",
},
{
type = "goods-company",
Expand All @@ -66,6 +68,7 @@ data:extend {
price_per_area = 100,
randomize_filler = true,
},
power_consumption = "100W",
},
{
type = "solar-panel",
Expand All @@ -77,13 +80,7 @@ data:extend {
kind = "centered_door",
vertical_factor = 1.0,
},
kind = "network",
recipe = {
consumption = {},
production = {},
complexity = 1,
storage_multiplier = 5,
},
kind = "factory",
n_workers = 0,
size = 120.0,
asset_location = "assets/sprites/cement.jpg",
Expand All @@ -93,6 +90,7 @@ data:extend {
filler = "solarpanel.glb",
price_per_area = 10,
},
power_production = "10kW",
},
{
type = "goods-company",
Expand All @@ -103,18 +101,18 @@ data:extend {
kind = "centered_door",
vertical_factor = 1.0,
},
kind = "network",
kind = "factory",
recipe = {
consumption = {{"coal", 1}},
production = {},
complexity = 100,
storage_multiplier = 5,
power_generation = "2.46MW",
},
n_workers = 10,
size = 165.0,
asset_location = "coal_power_plant.glb",
price = 1000,
power_production = "2.46MW",
},
{
type = "goods-company",
Expand All @@ -136,6 +134,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/supermarket.png",
price = 1000,
power_consumption = "1kW",
},
{
type = "goods-company",
Expand All @@ -157,6 +156,7 @@ data:extend {
size = 10.0,
asset_location = "assets/sprites/clothes_store.png",
price = 1000,
power_consumption = "1kW",
},
{
type = "goods-company",
Expand All @@ -179,6 +179,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/cloth_factory.png",
price = 1000,
power_consumption = "10kW",
},
{
type = "goods-company",
Expand All @@ -201,6 +202,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/textile_processing_facility.png",
price = 1000,
power_consumption = "1kW",
},
{
type = "goods-company",
Expand All @@ -223,6 +225,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/polyester_refinery.png",
price = 1000,
power_consumption = "10kW",
},
{
type = "goods-company",
Expand All @@ -245,6 +248,7 @@ data:extend {
size = 20.0,
asset_location = "assets/sprites/oil_pump.png",
price = 1000,
power_consumption = "10kW",
},
{
type = "goods-company",
Expand Down Expand Up @@ -289,6 +293,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/wool_farm.png",
price = 1000,
power_consumption = "100W",
},
{
type = "goods-company",
Expand All @@ -310,6 +315,7 @@ data:extend {
size = 10.0,
asset_location = "assets/sprites/florist.png",
price = 1000,
power_consumption = "100W",
},
{
type = "goods-company",
Expand All @@ -332,6 +338,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/horticulturalist.png",
price = 1000,
power_consumption = "500W",
},
{
type = "goods-company",
Expand All @@ -353,6 +360,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/hightech_store.png",
price = 1000,
power_consumption = "2kW",
},
{
type = "goods-company",
Expand All @@ -375,6 +383,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/hightech_facility.png",
price = 1000,
power_consumption = "100kW",
},
{
type = "goods-company",
Expand All @@ -397,6 +406,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/iron_mine.png",
price = 1000,
power_consumption = "1kW",
},
{
type = "goods-company",
Expand All @@ -419,6 +429,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/rare_metal_mine.png",
price = 1000,
power_consumption = "1kW",
},
{
type = "goods-company",
Expand All @@ -438,6 +449,7 @@ data:extend {
size = 200.0,
asset_location = "assets/sprites/lumber_yard.png",
price = 1000,
power_consumption = "100W",
},
{
type = "goods-company",
Expand All @@ -460,6 +472,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/woodmill.png",
price = 1000,
power_consumption = "5kW",
},
{
type = "goods-company",
Expand All @@ -481,6 +494,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/furniture_store.png",
price = 1000,
power_consumption = "500W",
},
{
type = "goods-company",
Expand All @@ -503,6 +517,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/foundry.png",
price = 1000,
power_consumption = "10kW",
},
{
type = "goods-company",
Expand All @@ -525,6 +540,7 @@ data:extend {
size = 50.0,
asset_location = "assets/sprites/slaughterhouse.png",
price = 1000,
power_consumption = "1kW",
},
{
type = "goods-company",
Expand All @@ -544,6 +560,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/animal_farm.png",
price = 1000,
power_consumption = "100W",
},
{
type = "goods-company",
Expand All @@ -566,6 +583,7 @@ data:extend {
size = 80.0,
asset_location = "assets/sprites/meat_facility.png",
price = 1000,
power_consumption = "1kW",
},
{
type = "goods-company",
Expand All @@ -590,5 +608,6 @@ data:extend {
filler = "salad.glb",
price_per_area = 100,
},
power_consumption = "100W",
},
}
55 changes: 47 additions & 8 deletions native_app/src/gui/inspect/inspect_building.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ use simulation::{Simulation, SoulID};
use crate::gui::inspect::entity_link;
use crate::gui::item_icon;
use egui_inspect::{Inspect, InspectArgs, InspectVec2Rotation};
use prototypes::{ItemID, Recipe};
use prototypes::{ItemID, Power, Recipe};
use simulation::map::{Building, BuildingID, BuildingKind, Zone, MAX_ZONE_AREA};
use simulation::map_dynamic::BuildingInfos;
use simulation::map_dynamic::{BuildingInfos, ElectricityFlow};
use simulation::souls::freight_station::FreightTrainState;

/// Inspect a specific building, showing useful information about it
Expand Down Expand Up @@ -136,8 +136,12 @@ fn render_goodscompany(ui: &mut Ui, uiworld: &mut UiWorld, sim: &Simulation, b:
};
let goods = &c.comp;
let workers = &c.workers;
let proto = c.comp.proto.prototype();

let market = &*sim.read::<Market>();
let map = &*sim.map();
let elec_flow = &*sim.read::<ElectricityFlow>();

let market = sim.read::<Market>();
let max_workers = goods.max_workers;
egui::ProgressBar::new(workers.0.len() as f32 / max_workers as f32)
.text(format!("workers: {}/{}", workers.0.len(), max_workers))
Expand All @@ -149,16 +153,51 @@ fn render_goodscompany(ui: &mut Ui, uiworld: &mut UiWorld, sim: &Simulation, b:
entity_link(uiworld, sim, ui, driver);
});
}
let productivity = goods.productivity(workers.0.len(), b.zone.as_ref());
let productivity = (productivity * 100.0).round();
if productivity < 100.0 {
let productivity = c.productivity(proto, b.zone.as_ref(), map, elec_flow);
if productivity < 1.0 {
egui::ProgressBar::new(productivity)
.text(format!("productivity: {productivity:.0}%"))
.text(format!(
"productivity: {:.0}%",
(productivity * 100.0).round()
))
.desired_width(200.0)
.ui(ui);
}

render_recipe(ui, uiworld, &goods.proto.prototype().recipe);
if let Some(ref r) = proto.recipe {
render_recipe(ui, uiworld, r);
}

if let Some(net_id) = map.electricity.net_id(b.id) {
let elec_productivity = elec_flow.productivity(net_id);

if proto.power_consumption > Power::ZERO {
egui::ProgressBar::new(productivity * elec_productivity)
.text(format!(
"power: {}/{}",
(productivity * elec_productivity) as f64 * proto.power_consumption,
proto.power_consumption
))
.desired_width(200.0)
.ui(ui);
}

if proto.power_production > Power::ZERO {
ui.label(format!(
"producing power: {}",
proto.power_production * productivity as f64
));

let stats = elec_flow.network_stats(net_id);
egui::ProgressBar::new(elec_productivity)
.text(format!(
"Network health: {}/{}",
stats.produced_power, stats.consumed_power
))
.desired_width(200.0)
.ui(ui);
}
}

egui::ProgressBar::new(goods.progress)
.show_percentage()
Expand Down
46 changes: 31 additions & 15 deletions native_app/src/gui/topgui.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ use egui_inspect::{Inspect, InspectArgs};
use geom::{Polygon, Vec2};
use prototypes::{
prototypes_iter, BuildingGen, FreightStationPrototype, GoodsCompanyPrototype, ItemID, Money,
Power,
};
use serde::{Deserialize, Serialize};
use simulation::economy::Government;
Expand Down Expand Up @@ -620,26 +621,41 @@ impl Gui {
.resizable(false)
.show(ui.ctx(), |ui| {
ui.label(format!("workers: {}", descr.n_workers));
ui.add_space(10.0);
if !descr.recipe.consumption.is_empty() {
ui.label("consumption:");
for item in &descr.recipe.consumption {
item_icon(ui, uiworld, item.id, item.amount);

if let Some(ref recipe) = descr.recipe {
ui.add_space(10.0);
if !recipe.consumption.is_empty() {
ui.label("consumption:");
for item in &recipe.consumption {
item_icon(ui, uiworld, item.id, item.amount);
}
ui.add_space(10.0);
}
if !recipe.production.is_empty() {
ui.label("production:");
for item in &recipe.production {
item_icon(ui, uiworld, item.id, item.amount);
}
ui.add_space(10.0);
}
ui.label(format!("time: {}s", recipe.complexity));
ui.label(format!(
"storage multiplier: {}",
recipe.storage_multiplier
));
}

if descr.power_consumption > Power::ZERO {
ui.add_space(10.0);
ui.label(format!("Power: {}", descr.power_consumption));
}
if !descr.recipe.production.is_empty() {
ui.label("production:");
for item in &descr.recipe.production {
item_icon(ui, uiworld, item.id, item.amount);
}
if descr.power_production > Power::ZERO {
ui.add_space(10.0);
ui.label(format!(
"Power production: {}",
descr.power_production
));
}
ui.label(format!("time: {}s", descr.recipe.complexity));
ui.label(format!(
"storage multiplier: {}",
descr.recipe.storage_multiplier
));
});
}
});
Expand Down
2 changes: 1 addition & 1 deletion prototypes/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ pub fn try_prototype<ID: PrototypeID>(id: ID) -> Option<&'static <ID as Prototyp
where
ID::Prototype: ConcretePrototype,
{
<ID as PrototypeID>::Prototype::storage(try_prototypes()?).get(&id)
<ID as PrototypeID>::Prototype::storage(prototypes()).get(&id)
}

#[inline]
Expand Down
1 change: 1 addition & 0 deletions prototypes/src/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@ macro_rules! gen_prototypes {
&prototypes.orderings.$name
}

#[inline]
fn storage(prototypes: &Prototypes) -> &common::TransparentMap<Self::ID, Self> {
&prototypes.$name
}
Expand Down
Loading

0 comments on commit bc78f3d

Please sign in to comment.