pub struct Economy {
pub tax_system: TaxSystem,
/* private fields */
}Expand description
The global economy — tracks supply, demand, and prices for all items.
Fields§
§tax_system: TaxSystemImplementations§
Source§impl Economy
impl Economy
pub fn new() -> Self
Sourcepub fn register_item(
&mut self,
item_id: impl Into<String>,
base_price_copper: u64,
)
pub fn register_item( &mut self, item_id: impl Into<String>, base_price_copper: u64, )
Register an item with a base price (in copper).
Sourcepub fn current_price(&self, item_id: &str) -> Option<u64>
pub fn current_price(&self, item_id: &str) -> Option<u64>
Get the current equilibrium price for an item (in copper).
Sourcepub fn current_price_currency(&self, item_id: &str) -> Option<Currency>
pub fn current_price_currency(&self, item_id: &str) -> Option<Currency>
Get the current price as Currency.
Sourcepub fn average_price(&self, item_id: &str) -> Option<f32>
pub fn average_price(&self, item_id: &str) -> Option<f32>
Get the moving average price for an item.
Sourcepub fn demand_factor(&self, item_id: &str) -> f32
pub fn demand_factor(&self, item_id: &str) -> f32
Get the demand factor for an item.
Sourcepub fn record_sale(&mut self, item_id: &str, qty: u32, _price_copper: u64)
pub fn record_sale(&mut self, item_id: &str, qty: u32, _price_copper: u64)
Record a sale event (player buys item), increasing demand pressure.
Sourcepub fn record_purchase(&mut self, item_id: &str, qty: u32)
pub fn record_purchase(&mut self, item_id: &str, qty: u32)
Record a supply event (item produced or imported), increasing supply pressure.
Sourcepub fn update_prices(&mut self, dt: f32)
pub fn update_prices(&mut self, dt: f32)
Update all item prices based on supply/demand, called each game tick.
Sourcepub fn price_modifier(
&self,
item_id: &str,
player_rep_factor: f32,
) -> PriceModifier
pub fn price_modifier( &self, item_id: &str, player_rep_factor: f32, ) -> PriceModifier
Build a PriceModifier for an item and player reputation factor.
Sourcepub fn register_defaults(&mut self)
pub fn register_defaults(&mut self)
Populate the economy with default items and prices.
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 UnsafeUnpin 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
Mutably borrows from an owned value. Read more
impl<ST, DT> CastableFrom<ST, Initialized, Initialized> for DT
impl<ST, DT> CastableFrom<ST, Uninit, Uninit> for DT
Source§impl<T> CloneToUninit for Twhere
T: Clone,
impl<T> CloneToUninit for Twhere
T: Clone,
Source§impl<T> Downcast for Twhere
T: Any,
impl<T> Downcast for Twhere
T: Any,
Source§fn into_any(self: Box<T>) -> Box<dyn Any>
fn into_any(self: Box<T>) -> Box<dyn Any>
Convert
Box<dyn Trait> (where Trait: Downcast) to Box<dyn Any>. Box<dyn Any> can
then be further downcast into Box<ConcreteType> where ConcreteType implements Trait.Source§fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
fn into_any_rc(self: Rc<T>) -> Rc<dyn Any>
Convert
Rc<Trait> (where Trait: Downcast) to Rc<Any>. Rc<Any> can then be
further downcast into Rc<ConcreteType> where ConcreteType implements Trait.Source§fn as_any(&self) -> &(dyn Any + 'static)
fn as_any(&self) -> &(dyn Any + 'static)
Convert
&Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &Any’s vtable from &Trait’s.Source§fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
fn as_any_mut(&mut self) -> &mut (dyn Any + 'static)
Convert
&mut Trait (where Trait: Downcast) to &Any. This is needed since Rust cannot
generate &mut Any’s vtable from &mut Trait’s.