mirror of
https://gitlab.com/veloren/veloren.git
synced 2024-08-30 18:12:32 +00:00
create economy tree graph
This commit is contained in:
parent
d39d11d2fa
commit
3a9e070ec0
90
world/examples/economy_tree.rs
Normal file
90
world/examples/economy_tree.rs
Normal file
@ -0,0 +1,90 @@
|
||||
use common::trade::Good;
|
||||
use std::io::Write;
|
||||
use veloren_world::site::economy::{self, good_list, Economy};
|
||||
//use regex::Regex::replace_all;
|
||||
|
||||
fn good_name(g: Good) -> String {
|
||||
let res = format!("{:?}", g);
|
||||
let res = res.replace("(", "_");
|
||||
let res = res.replace(")", "_");
|
||||
res
|
||||
}
|
||||
|
||||
fn labor_name(l: economy::Labor) -> String {
|
||||
let res = format!("{:?}", l);
|
||||
let res = res.replace(" ", "_");
|
||||
res
|
||||
}
|
||||
|
||||
fn main() -> Result<(), std::io::Error> {
|
||||
let eco = Economy::default();
|
||||
let o = eco.get_orders();
|
||||
let p = eco.get_productivity();
|
||||
|
||||
let mut f = std::fs::File::create("economy.gv")?;
|
||||
writeln!(f, "digraph economy {{")?;
|
||||
for i in good_list().iter() {
|
||||
let color = if economy::direct_use_goods().contains(i) {
|
||||
"green"
|
||||
} else {
|
||||
"orange"
|
||||
};
|
||||
writeln!(f, "{:?} [color=\"{}\"];", good_name(*i), color)?; // shape doubleoctagon ?
|
||||
}
|
||||
|
||||
writeln!(f, "")?;
|
||||
writeln!(f, "// Professions")?;
|
||||
writeln!(f, "Everyone [shape=doubleoctagon];")?;
|
||||
for i in economy::Labor::list() {
|
||||
writeln!(f, "{:?} [shape=box];", labor_name(i))?;
|
||||
}
|
||||
|
||||
writeln!(f, "")?;
|
||||
writeln!(f, "// Orders")?;
|
||||
for i in o.iter() {
|
||||
for j in i.1.iter() {
|
||||
if i.0.is_some() {
|
||||
let style = if matches!(j.0, Good::Tools)
|
||||
|| matches!(j.0, Good::Armor)
|
||||
|| matches!(j.0, Good::Potions)
|
||||
{
|
||||
", style=dashed, color=orange"
|
||||
} else {
|
||||
""
|
||||
};
|
||||
writeln!(
|
||||
f,
|
||||
"{:?} -> {:?} [label=\"{:.1}\"{}];",
|
||||
good_name(j.0),
|
||||
labor_name(i.0.unwrap()),
|
||||
j.1,
|
||||
style
|
||||
)?;
|
||||
} else {
|
||||
writeln!(
|
||||
f,
|
||||
"{:?} -> Everyone [label=\"{:.1}\"];",
|
||||
good_name(j.0),
|
||||
j.1
|
||||
)?;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(f, "")?;
|
||||
writeln!(f, "// Products")?;
|
||||
for i in p.iter() {
|
||||
for j in i.1.iter() {
|
||||
writeln!(
|
||||
f,
|
||||
"{:?} -> {:?} [label=\"{:.1}\"];",
|
||||
labor_name(i.0),
|
||||
good_name(j.0),
|
||||
j.1
|
||||
)?;
|
||||
}
|
||||
}
|
||||
|
||||
writeln!(f, "}}")?;
|
||||
Ok(())
|
||||
}
|
@ -1,68 +0,0 @@
|
||||
digraph economy {
|
||||
Farmland [color="green"];
|
||||
Flour [color="orange"];
|
||||
Meat [color="orange"];
|
||||
Fish [color="green"];
|
||||
Game [color="green"];
|
||||
Food [color="orange"];
|
||||
Logs [color="green"];
|
||||
Wood [color="orange"];
|
||||
Rock [color="green"];
|
||||
Stone [color="orange"];
|
||||
Tools [color="orange"];
|
||||
Armor [color="orange"];
|
||||
Ingredients [color="green"];
|
||||
Potions [color="orange"];
|
||||
ControlledArea [color="green", shape=doubleoctagon];
|
||||
|
||||
// Professions
|
||||
Everyone [shape=doubleoctagon];
|
||||
Farmer [shape=box];
|
||||
Lumberjack [shape=box];
|
||||
Miner [shape=box];
|
||||
Fisher [shape=box];
|
||||
Hunter [shape=box];
|
||||
Cook [shape=box];
|
||||
Brewer [shape=box];
|
||||
Blacksmith [shape=box];
|
||||
Bladesmith [shape=box];
|
||||
Guard [shape=box];
|
||||
|
||||
// Orders
|
||||
Food -> Everyone [label= "0.5", style=dashed, weight=4];
|
||||
Flour -> Cook [label="12.0", penwidth=2.0];
|
||||
Meat -> Cook [label="4.0", penwidth=1.5];
|
||||
Wood -> Cook [label="1.5"];
|
||||
Stone -> Cook [label="1.0"];
|
||||
Logs -> Lumberjack [label="0.5", style=dashed, weight=4];
|
||||
Tools -> Lumberjack [label="0.1", color="orange", style=dashed];
|
||||
Rock -> Miner [label="0.5", style=dashed, weight=4];
|
||||
Tools -> Miner [label="0.1", color="orange", style=dashed];
|
||||
Fish -> Fisher [label="4.0", penwidth=1.5, weight=4];
|
||||
Tools -> Fisher [label="0.02", color="orange", style=dotted];
|
||||
Game -> Hunter [label="1.0", weight=4];
|
||||
Tools -> Hunter [label="0.1", color="orange", style=dashed];
|
||||
Farmland -> Farmer [label="2.0", weight=4];
|
||||
Tools -> Farmer [label="0.05", color="orange", style=dotted];
|
||||
Ingredients -> Brewer [label="2.0", penwidth=1.0];
|
||||
Flour -> Brewer [label="2.0", penwidth=1.0];
|
||||
Ingredients -> Blacksmith [label="8.0", penwidth=2.0];
|
||||
Wood -> Blacksmith [label="2.0", penwidth=1.0];
|
||||
Ingredients -> Bladesmith [label="4.0", penwidth=1.5];
|
||||
Wood -> Bladesmith [label="1.0", penwidth=1.0];
|
||||
Armor -> Guard [label="0.5", style=dashed];
|
||||
Tools -> Guard [label="0.3", color="orange", style=dashed];
|
||||
Potions -> Guard [label="3.0", penwidth=1.5];
|
||||
|
||||
// Products
|
||||
Farmer -> Flour [label="2.0"];
|
||||
Lumberjack -> Wood [label="0.5", style=dashed];
|
||||
Miner -> Stone [label="0.5", style=dashed];
|
||||
Fisher -> Meat [label="4.0", penwidth=1.5];
|
||||
Hunter -> Meat [label="1.0"];
|
||||
Cook -> Food [label="16.0", penwidth=2.0];
|
||||
Blacksmith -> Armor [label="4.0"];
|
||||
Bladesmith -> Tools [label="2.0", color="orange"];
|
||||
Brewer -> Potions [label="6.0"];
|
||||
Guard -> ControlledArea [label="50.0", penwidth=2.0];
|
||||
}
|
Loading…
Reference in New Issue
Block a user