Struct veloren_world::site::economy::Economy
source · pub struct Economy {Show 19 fields
pop: f32,
population_limited_by: GoodIndex,
stocks: GoodMap<f32>,
surplus: GoodMap<f32>,
marginal_surplus: GoodMap<f32>,
unconsumed_stock: GoodMap<f32>,
values: GoodMap<Option<f32>>,
last_exports: GoodMap<f32>,
active_exports: GoodMap<f32>,
labor_values: GoodMap<Option<f32>>,
material_costs: GoodMap<f32>,
labors: LaborMap<f32>,
yields: LaborMap<f32>,
productivity: LaborMap<f32>,
limited_by: LaborMap<GoodIndex>,
natural_resources: NaturalResources,
neighbors: Vec<NeighborInformation>,
orders: DHashMap<Id<Site>, Vec<TradeOrder>>,
deliveries: Vec<TradeDelivery>,
}
Fields§
§pop: f32
Population
population_limited_by: GoodIndex
§stocks: GoodMap<f32>
Total available amount of each good
surplus: GoodMap<f32>
Surplus stock compared to demand orders
marginal_surplus: GoodMap<f32>
change rate (derivative) of stock in the current situation
unconsumed_stock: GoodMap<f32>
amount of wares not needed by the economy (helps with trade planning)
values: GoodMap<Option<f32>>
Local availability of a good, 4.0 = starved, 2.0 = balanced, 0.1 = extra, NULL = way too much
last_exports: GoodMap<f32>
amount of goods exported/imported during the last cycle
active_exports: GoodMap<f32>
§labor_values: GoodMap<Option<f32>>
amount of labor that went into a good, [1 man cycle=1.0]
material_costs: GoodMap<f32>
§labors: LaborMap<f32>
Proportion of individuals dedicated to an industry (sums to roughly 1.0)
yields: LaborMap<f32>
§productivity: LaborMap<f32>
[0.0..1.0]
limited_by: LaborMap<GoodIndex>
Missing raw material which limits production
natural_resources: NaturalResources
§neighbors: Vec<NeighborInformation>
Neighboring sites to trade with
orders: DHashMap<Id<Site>, Vec<TradeOrder>>
outgoing trade, per provider
deliveries: Vec<TradeDelivery>
incoming trade - only towards this site
Implementations§
source§impl Economy
impl Economy
const MINIMUM_PRICE: f32 = 0.100000001f32
const STARTING_COIN: f32 = 1000f32
const _NATURAL_RESOURCE_SCALE: f32 = 0.111111112f32
pub fn population(&self) -> f32
pub fn get_available_stock(&self) -> HashMap<Good, f32>
pub fn get_information(&self, id: Id<Site>) -> EconomyInfo
pub fn cache_economy(&mut self)
sourcefn get_orders(&self) -> &'static LaborMap<Vec<(GoodIndex, f32)>>
fn get_orders(&self) -> &'static LaborMap<Vec<(GoodIndex, f32)>>
orders per profession (excluding everyone)
sourcefn get_orders_everyone(&self) -> impl Iterator<Item = &'static (GoodIndex, f32)>
fn get_orders_everyone(&self) -> impl Iterator<Item = &'static (GoodIndex, f32)>
resources consumed by everyone (no matter which profession)
fn get_production(&self) -> LaborMap<(GoodIndex, f32)>
fn replenish(&mut self, _time: f32)
pub fn add_chunk(&mut self, ch: &SimChunk, distance_squared: i64)
pub fn add_neighbor(&mut self, id: Id<Site>, _distance: usize)
pub fn get_site_prices(&self) -> SitePrices
sourcefn plan_trade_for_site(
&mut self,
site_id: &Id<Site>,
transportation_capacity: f32,
potential_trade: &mut GoodMap<f32>,
) -> GoodMap<f32>
fn plan_trade_for_site( &mut self, site_id: &Id<Site>, transportation_capacity: f32, potential_trade: &mut GoodMap<f32>, ) -> GoodMap<f32>
plan the trading according to missing goods and prices at neighboring sites (1st step of trading)
sourcepub fn trade_at_site(
&mut self,
site_id: Id<Site>,
orders: &mut Vec<TradeOrder>,
deliveries: &mut DHashMap<Id<Site>, Vec<TradeDelivery>>,
)
pub fn trade_at_site( &mut self, site_id: Id<Site>, orders: &mut Vec<TradeOrder>, deliveries: &mut DHashMap<Id<Site>, Vec<TradeDelivery>>, )
perform trade using neighboring orders (2nd step of trading)
sourcefn collect_deliveries(&mut self)
fn collect_deliveries(&mut self)
3rd step of trading
sourcepub fn tick(&mut self, site_id: Id<Site>, dt: f32)
pub fn tick(&mut self, site_id: Id<Site>, dt: f32)
Simulate one step of economic interaction:
- collect returned goods from trade
- calculate demand, production and their ratio
- reassign workers based on missing goods
- change stock due to raw material use and production
- send out traders with goods and orders
- calculate good decay and population change
Simulate a site’s economy. This simulation is roughly equivalent to the Lange-Lerner model’s solution to the socialist calculation problem. The simulation begins by assigning arbitrary values to each commodity and then incrementally updates them according to the final scarcity of the commodity at the end of the tick. This results in the formulation of values that are roughly analogous to prices for each commodity. The workforce is then reassigned according to the respective commodity values. The simulation also includes damping terms that prevent cyclical inconsistencies in value rationalisation magnifying enough to crash the economy. We also ensure that a small number of workers are allocated to every industry (even inactive ones) each tick. This is not an accident: a small amount of productive capacity in one industry allows the economy to quickly pivot to a different production configuration should an additional commodity that acts as production input become available. This means that the economy will dynamically react to environmental changes. If a product becomes available through a mechanism such as trade, an entire arm of the economy may materialise to take advantage of this.
pub fn csv_entry(f: &mut File, site: &Site) -> Result<(), Error>
fn csv_header(f: &mut File) -> Result<(), Error>
pub fn csv_open() -> Option<File>
Trait Implementations§
Auto Trait Implementations§
impl Freeze for Economy
impl RefUnwindSafe for Economy
impl Send for Economy
impl Sync for Economy
impl Unpin for Economy
impl UnwindSafe for Economy
Blanket Implementations§
source§impl<T> BorrowMut<T> for Twhere
T: ?Sized,
impl<T> BorrowMut<T> for Twhere
T: ?Sized,
source§fn borrow_mut(&mut self) -> &mut T
fn borrow_mut(&mut self) -> &mut T
source§impl<T> CheckedAs for T
impl<T> CheckedAs for T
source§fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
fn checked_as<Dst>(self) -> Option<Dst>where
T: CheckedCast<Dst>,
source§impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
impl<Src, Dst> CheckedCastFrom<Src> for Dstwhere
Src: CheckedCast<Dst>,
source§fn checked_cast_from(src: Src) -> Option<Dst>
fn checked_cast_from(src: Src) -> Option<Dst>
§impl<T> Conv for T
impl<T> Conv for T
§impl<T> FmtForward for T
impl<T> FmtForward for T
§fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
fn fmt_binary(self) -> FmtBinary<Self>where
Self: Binary,
self
to use its Binary
implementation when Debug
-formatted.§fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
fn fmt_display(self) -> FmtDisplay<Self>where
Self: Display,
self
to use its Display
implementation when
Debug
-formatted.§fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
fn fmt_lower_exp(self) -> FmtLowerExp<Self>where
Self: LowerExp,
self
to use its LowerExp
implementation when
Debug
-formatted.§fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
fn fmt_lower_hex(self) -> FmtLowerHex<Self>where
Self: LowerHex,
self
to use its LowerHex
implementation when
Debug
-formatted.§fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
fn fmt_octal(self) -> FmtOctal<Self>where
Self: Octal,
self
to use its Octal
implementation when Debug
-formatted.§fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
fn fmt_pointer(self) -> FmtPointer<Self>where
Self: Pointer,
self
to use its Pointer
implementation when
Debug
-formatted.§fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
fn fmt_upper_exp(self) -> FmtUpperExp<Self>where
Self: UpperExp,
self
to use its UpperExp
implementation when
Debug
-formatted.§fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
fn fmt_upper_hex(self) -> FmtUpperHex<Self>where
Self: UpperHex,
self
to use its UpperHex
implementation when
Debug
-formatted.§fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
fn fmt_list(self) -> FmtList<Self>where
&'a Self: for<'a> IntoIterator,
§impl<T> Instrument for T
impl<T> Instrument for T
§fn instrument(self, span: Span) -> Instrumented<Self>
fn instrument(self, span: Span) -> Instrumented<Self>
§fn in_current_span(self) -> Instrumented<Self>
fn in_current_span(self) -> Instrumented<Self>
source§impl<T> IntoEither for T
impl<T> IntoEither for T
source§fn into_either(self, into_left: bool) -> Either<Self, Self>
fn into_either(self, into_left: bool) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left
is true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
fn into_either_with<F>(self, into_left: F) -> Either<Self, Self>
self
into a Left
variant of Either<Self, Self>
if into_left(&self)
returns true
.
Converts self
into a Right
variant of Either<Self, Self>
otherwise. Read moresource§impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
impl<Src, Dst> LosslessTryInto<Dst> for Srcwhere
Dst: LosslessTryFrom<Src>,
source§fn lossless_try_into(self) -> Option<Dst>
fn lossless_try_into(self) -> Option<Dst>
source§impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
impl<Src, Dst> LossyInto<Dst> for Srcwhere
Dst: LossyFrom<Src>,
source§fn lossy_into(self) -> Dst
fn lossy_into(self) -> Dst
source§impl<T> OverflowingAs for T
impl<T> OverflowingAs for T
source§fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
fn overflowing_as<Dst>(self) -> (Dst, bool)where
T: OverflowingCast<Dst>,
source§impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
impl<Src, Dst> OverflowingCastFrom<Src> for Dstwhere
Src: OverflowingCast<Dst>,
source§fn overflowing_cast_from(src: Src) -> (Dst, bool)
fn overflowing_cast_from(src: Src) -> (Dst, bool)
§impl<T> Pipe for Twhere
T: ?Sized,
impl<T> Pipe for Twhere
T: ?Sized,
§fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
fn pipe<R>(self, func: impl FnOnce(Self) -> R) -> Rwhere
Self: Sized,
§fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref<'a, R>(&'a self, func: impl FnOnce(&'a Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
fn pipe_ref_mut<'a, R>(&'a mut self, func: impl FnOnce(&'a mut Self) -> R) -> Rwhere
R: 'a,
self
and passes that borrow into the pipe function. Read more§fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
fn pipe_borrow<'a, B, R>(&'a self, func: impl FnOnce(&'a B) -> R) -> R
§fn pipe_borrow_mut<'a, B, R>(
&'a mut self,
func: impl FnOnce(&'a mut B) -> R,
) -> R
fn pipe_borrow_mut<'a, B, R>( &'a mut self, func: impl FnOnce(&'a mut B) -> R, ) -> R
§fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
fn pipe_as_ref<'a, U, R>(&'a self, func: impl FnOnce(&'a U) -> R) -> R
self
, then passes self.as_ref()
into the pipe function.§fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
fn pipe_as_mut<'a, U, R>(&'a mut self, func: impl FnOnce(&'a mut U) -> R) -> R
self
, then passes self.as_mut()
into the pipe
function.§fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
fn pipe_deref<'a, T, R>(&'a self, func: impl FnOnce(&'a T) -> R) -> R
self
, then passes self.deref()
into the pipe function.§impl<T> Pointable for T
impl<T> Pointable for T
source§impl<T> SaturatingAs for T
impl<T> SaturatingAs for T
source§fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
fn saturating_as<Dst>(self) -> Dstwhere
T: SaturatingCast<Dst>,
source§impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
impl<Src, Dst> SaturatingCastFrom<Src> for Dstwhere
Src: SaturatingCast<Dst>,
source§fn saturating_cast_from(src: Src) -> Dst
fn saturating_cast_from(src: Src) -> Dst
§impl<Context> SubContext<Context> for Context
impl<Context> SubContext<Context> for Context
fn sub_context(self) -> Context
§impl<T> Tap for T
impl<T> Tap for T
§fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow<B>(self, func: impl FnOnce(&B)) -> Self
Borrow<B>
of a value. Read more§fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut<B>(self, func: impl FnOnce(&mut B)) -> Self
BorrowMut<B>
of a value. Read more§fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref<R>(self, func: impl FnOnce(&R)) -> Self
AsRef<R>
view of a value. Read more§fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut<R>(self, func: impl FnOnce(&mut R)) -> Self
AsMut<R>
view of a value. Read more§fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref<T>(self, func: impl FnOnce(&T)) -> Self
Deref::Target
of a value. Read more§fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
fn tap_deref_mut<T>(self, func: impl FnOnce(&mut T)) -> Self
Deref::Target
of a value. Read more§fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
fn tap_dbg(self, func: impl FnOnce(&Self)) -> Self
.tap()
only in debug builds, and is erased in release builds.§fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
fn tap_mut_dbg(self, func: impl FnOnce(&mut Self)) -> Self
.tap_mut()
only in debug builds, and is erased in release
builds.§fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
fn tap_borrow_dbg<B>(self, func: impl FnOnce(&B)) -> Self
.tap_borrow()
only in debug builds, and is erased in release
builds.§fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
fn tap_borrow_mut_dbg<B>(self, func: impl FnOnce(&mut B)) -> Self
.tap_borrow_mut()
only in debug builds, and is erased in release
builds.§fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
fn tap_ref_dbg<R>(self, func: impl FnOnce(&R)) -> Self
.tap_ref()
only in debug builds, and is erased in release
builds.§fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
fn tap_ref_mut_dbg<R>(self, func: impl FnOnce(&mut R)) -> Self
.tap_ref_mut()
only in debug builds, and is erased in release
builds.§fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
fn tap_deref_dbg<T>(self, func: impl FnOnce(&T)) -> Self
.tap_deref()
only in debug builds, and is erased in release
builds.§impl<T> TryConv for T
impl<T> TryConv for T
§impl<T> TryDefault for Twhere
T: Default,
impl<T> TryDefault for Twhere
T: Default,
§fn try_default() -> Result<T, String>
fn try_default() -> Result<T, String>
§fn unwrap_default() -> Self
fn unwrap_default() -> Self
try_default
and panics on an error case.