2022-03-06 22:39:01 +00:00
|
|
|
use std::cmp::Ordering;
|
2022-03-06 06:18:25 +00:00
|
|
|
|
2021-02-12 10:51:32 +00:00
|
|
|
use crate::{
|
2021-03-30 22:37:38 +00:00
|
|
|
comp::inventory::{slot::InvSlotId, trade_pricing::TradePricing, Inventory},
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
terrain::BiomeKind,
|
2021-02-12 10:51:32 +00:00
|
|
|
uid::Uid,
|
|
|
|
};
|
2021-02-11 04:54:31 +00:00
|
|
|
use hashbrown::HashMap;
|
|
|
|
use serde::{Deserialize, Serialize};
|
2021-05-28 18:42:29 +00:00
|
|
|
use strum_macros::EnumIter;
|
2021-02-12 23:09:18 +00:00
|
|
|
use tracing::{trace, warn};
|
2021-02-11 04:54:31 +00:00
|
|
|
|
2021-02-13 23:32:55 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub enum TradePhase {
|
|
|
|
Mutate,
|
|
|
|
Review,
|
|
|
|
Complete,
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Clients submit `TradeAction` to the server, which adds the Uid of the
|
2021-02-11 04:54:31 +00:00
|
|
|
/// player out-of-band (i.e. without trusting the client to say who it's
|
|
|
|
/// accepting on behalf of)
|
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
2021-02-13 23:32:55 +00:00
|
|
|
pub enum TradeAction {
|
|
|
|
AddItem {
|
|
|
|
item: InvSlotId,
|
|
|
|
quantity: u32,
|
2021-02-28 02:44:57 +00:00
|
|
|
ours: bool,
|
2021-02-13 23:32:55 +00:00
|
|
|
},
|
|
|
|
RemoveItem {
|
|
|
|
item: InvSlotId,
|
|
|
|
quantity: u32,
|
2021-02-28 02:44:57 +00:00
|
|
|
ours: bool,
|
2021-02-13 23:32:55 +00:00
|
|
|
},
|
|
|
|
/// Accept needs the phase indicator to avoid progressing too far in the
|
|
|
|
/// trade if there's latency and a player presses the accept button
|
|
|
|
/// multiple times
|
|
|
|
Accept(TradePhase),
|
2021-02-11 19:35:36 +00:00
|
|
|
Decline,
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
2022-03-06 22:39:01 +00:00
|
|
|
|
2021-02-12 20:47:45 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub enum TradeResult {
|
|
|
|
Completed,
|
|
|
|
Declined,
|
|
|
|
NotEnoughSpace,
|
|
|
|
}
|
|
|
|
|
2021-02-11 04:54:31 +00:00
|
|
|
/// Items are not removed from the inventory during a PendingTrade: all the
|
|
|
|
/// items are moved atomically (if there's space and both parties agree) upon
|
|
|
|
/// completion
|
2021-02-12 23:09:18 +00:00
|
|
|
///
|
|
|
|
/// Since this stores `InvSlotId`s (i.e. references into inventories) instead of
|
|
|
|
/// items themselves, there aren't any duplication/loss risks from things like
|
|
|
|
/// dropped connections or declines, since the server doesn't have to move items
|
|
|
|
/// from a trade back into a player's inventory.
|
|
|
|
///
|
|
|
|
/// On the flip side, since they are references to *slots*, if a player could
|
2021-02-13 23:32:55 +00:00
|
|
|
/// swap items in their inventory during a trade, they could mutate the trade,
|
2021-02-12 23:09:18 +00:00
|
|
|
/// enabling them to remove an item from the trade even after receiving the
|
|
|
|
/// counterparty's phase2 accept. To prevent this, we disallow all
|
|
|
|
/// forms of inventory manipulation in `server::events::inventory_manip` if
|
|
|
|
/// there's a pending trade that's past phase1 (in phase1, the trade should be
|
|
|
|
/// mutable anyway).
|
|
|
|
///
|
|
|
|
/// Inventory manipulation in phase1 may be beneficial to trade (e.g. splitting
|
|
|
|
/// a stack of items, once that's implemented), but should reset both phase1
|
|
|
|
/// accept flags to make the changes more visible.
|
|
|
|
///
|
|
|
|
/// Another edge case prevented by using `InvSlotId`s is that it disallows
|
|
|
|
/// trading currently-equipped items (since `EquipSlot`s are disjoint from
|
|
|
|
/// `InvSlotId`s), which avoids the issues associated with trading equipped bags
|
|
|
|
/// that may still have contents.
|
2021-02-11 04:54:31 +00:00
|
|
|
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
|
|
|
|
pub struct PendingTrade {
|
|
|
|
/// `parties[0]` is the entity that initiated the trade, parties[1] is the
|
|
|
|
/// other entity that's being traded with
|
|
|
|
pub parties: [Uid; 2],
|
|
|
|
/// `offers[i]` represents the items and quantities of the party i's items
|
|
|
|
/// being offered
|
2021-02-12 02:53:25 +00:00
|
|
|
pub offers: [HashMap<InvSlotId, u32>; 2],
|
2021-02-13 23:32:55 +00:00
|
|
|
/// The current phase of the trade
|
|
|
|
pub phase: TradePhase,
|
|
|
|
/// `accept_flags` indicate that which parties wish to proceed to the next
|
|
|
|
/// phase of the trade
|
|
|
|
pub accept_flags: [bool; 2],
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TradePhase {
|
|
|
|
fn next(self) -> TradePhase {
|
|
|
|
match self {
|
|
|
|
TradePhase::Mutate => TradePhase::Review,
|
|
|
|
TradePhase::Review => TradePhase::Complete,
|
|
|
|
TradePhase::Complete => TradePhase::Complete,
|
|
|
|
}
|
|
|
|
}
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
|
2022-03-06 06:18:25 +00:00
|
|
|
impl TradeAction {
|
2022-03-06 22:39:01 +00:00
|
|
|
pub fn item(item: InvSlotId, delta: i32, ours: bool) -> Option<Self> {
|
2022-03-06 06:18:25 +00:00
|
|
|
match delta.cmp(&0) {
|
|
|
|
Ordering::Equal => None,
|
|
|
|
Ordering::Less => Some(TradeAction::RemoveItem {
|
|
|
|
item,
|
|
|
|
ours,
|
2022-03-06 22:39:01 +00:00
|
|
|
quantity: -delta as u32,
|
2022-03-06 06:18:25 +00:00
|
|
|
}),
|
|
|
|
Ordering::Greater => Some(TradeAction::AddItem {
|
|
|
|
item,
|
|
|
|
ours,
|
|
|
|
quantity: delta as u32,
|
|
|
|
}),
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-11 04:54:31 +00:00
|
|
|
impl PendingTrade {
|
|
|
|
pub fn new(party: Uid, counterparty: Uid) -> PendingTrade {
|
|
|
|
PendingTrade {
|
|
|
|
parties: [party, counterparty],
|
|
|
|
offers: [HashMap::new(), HashMap::new()],
|
2021-02-13 23:32:55 +00:00
|
|
|
phase: TradePhase::Mutate,
|
|
|
|
accept_flags: [false, false],
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 23:32:55 +00:00
|
|
|
pub fn phase(&self) -> TradePhase { self.phase }
|
2021-02-11 04:54:31 +00:00
|
|
|
|
2021-02-13 23:32:55 +00:00
|
|
|
pub fn should_commit(&self) -> bool { matches!(self.phase, TradePhase::Complete) }
|
2021-02-11 04:54:31 +00:00
|
|
|
|
|
|
|
pub fn which_party(&self, party: Uid) -> Option<usize> {
|
|
|
|
self.parties
|
|
|
|
.iter()
|
|
|
|
.enumerate()
|
|
|
|
.find(|(_, x)| **x == party)
|
|
|
|
.map(|(i, _)| i)
|
|
|
|
}
|
|
|
|
|
2022-02-16 21:41:26 +00:00
|
|
|
pub fn is_empty_trade(&self) -> bool { self.offers[0].is_empty() && self.offers[1].is_empty() }
|
|
|
|
|
2021-02-12 10:51:32 +00:00
|
|
|
/// Invariants:
|
|
|
|
/// - A party is never shown as offering more of an item than they own
|
|
|
|
/// - Offers with a quantity of zero get removed from the trade
|
|
|
|
/// - Modifications can only happen in phase 1
|
2021-02-12 23:09:18 +00:00
|
|
|
/// - Whenever a trade is modified, both accept flags get reset
|
2021-02-12 10:51:32 +00:00
|
|
|
/// - Accept flags only get set for the current phase
|
2021-02-28 02:44:57 +00:00
|
|
|
pub fn process_trade_action(
|
|
|
|
&mut self,
|
|
|
|
mut who: usize,
|
|
|
|
action: TradeAction,
|
|
|
|
inventories: &[&Inventory],
|
|
|
|
) {
|
2021-02-13 23:32:55 +00:00
|
|
|
use TradeAction::*;
|
|
|
|
match action {
|
2021-02-12 10:51:32 +00:00
|
|
|
AddItem {
|
|
|
|
item,
|
|
|
|
quantity: delta,
|
2021-02-28 02:44:57 +00:00
|
|
|
ours,
|
2021-02-12 10:51:32 +00:00
|
|
|
} => {
|
2021-02-13 23:32:55 +00:00
|
|
|
if self.phase() == TradePhase::Mutate && delta > 0 {
|
2021-02-28 02:44:57 +00:00
|
|
|
if !ours {
|
|
|
|
who = 1 - who;
|
|
|
|
}
|
2021-02-12 23:09:18 +00:00
|
|
|
let total = self.offers[who].entry(item).or_insert(0);
|
2021-02-28 02:44:57 +00:00
|
|
|
let owned_quantity =
|
|
|
|
inventories[who].get(item).map(|i| i.amount()).unwrap_or(0);
|
2021-02-12 23:09:18 +00:00
|
|
|
*total = total.saturating_add(delta).min(owned_quantity);
|
2021-02-13 23:32:55 +00:00
|
|
|
self.accept_flags = [false, false];
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
},
|
2021-02-12 10:51:32 +00:00
|
|
|
RemoveItem {
|
|
|
|
item,
|
|
|
|
quantity: delta,
|
2021-02-28 02:44:57 +00:00
|
|
|
ours,
|
2021-02-12 10:51:32 +00:00
|
|
|
} => {
|
2021-02-13 23:32:55 +00:00
|
|
|
if self.phase() == TradePhase::Mutate {
|
2021-02-28 02:44:57 +00:00
|
|
|
if !ours {
|
|
|
|
who = 1 - who;
|
|
|
|
}
|
2021-02-12 10:51:32 +00:00
|
|
|
self.offers[who]
|
|
|
|
.entry(item)
|
|
|
|
.and_replace_entry_with(|_, mut total| {
|
|
|
|
total = total.saturating_sub(delta);
|
|
|
|
if total > 0 { Some(total) } else { None }
|
|
|
|
});
|
2021-02-13 23:32:55 +00:00
|
|
|
self.accept_flags = [false, false];
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
},
|
2021-02-13 23:32:55 +00:00
|
|
|
Accept(phase) => {
|
2022-02-16 21:41:26 +00:00
|
|
|
if self.phase == phase && !self.is_empty_trade() {
|
2021-02-13 23:32:55 +00:00
|
|
|
self.accept_flags[who] = true;
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
2021-02-13 23:32:55 +00:00
|
|
|
if self.accept_flags[0] && self.accept_flags[1] {
|
|
|
|
self.phase = self.phase.next();
|
|
|
|
self.accept_flags = [false, false];
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
},
|
2022-03-06 06:18:25 +00:00
|
|
|
_ => {},
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 23:32:55 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Serialize, Deserialize, PartialEq, Eq, Hash)]
|
|
|
|
pub struct TradeId(usize);
|
|
|
|
|
2021-02-11 04:54:31 +00:00
|
|
|
pub struct Trades {
|
2021-02-13 23:32:55 +00:00
|
|
|
pub next_id: TradeId,
|
|
|
|
pub trades: HashMap<TradeId, PendingTrade>,
|
|
|
|
pub entity_trades: HashMap<Uid, TradeId>,
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Trades {
|
2021-02-13 23:32:55 +00:00
|
|
|
pub fn begin_trade(&mut self, party: Uid, counterparty: Uid) -> TradeId {
|
2021-02-11 04:54:31 +00:00
|
|
|
let id = self.next_id;
|
2021-02-13 23:32:55 +00:00
|
|
|
self.next_id = TradeId(id.0.wrapping_add(1));
|
2021-02-11 04:54:31 +00:00
|
|
|
self.trades
|
|
|
|
.insert(id, PendingTrade::new(party, counterparty));
|
2021-02-12 23:09:18 +00:00
|
|
|
self.entity_trades.insert(party, id);
|
|
|
|
self.entity_trades.insert(counterparty, id);
|
2021-02-11 04:54:31 +00:00
|
|
|
id
|
|
|
|
}
|
|
|
|
|
2021-02-28 02:44:57 +00:00
|
|
|
pub fn process_trade_action<'a, F: Fn(Uid) -> Option<&'a Inventory>>(
|
2021-02-12 10:51:32 +00:00
|
|
|
&mut self,
|
2021-02-13 23:32:55 +00:00
|
|
|
id: TradeId,
|
2021-02-12 10:51:32 +00:00
|
|
|
who: Uid,
|
2021-02-13 23:32:55 +00:00
|
|
|
action: TradeAction,
|
2021-02-28 02:44:57 +00:00
|
|
|
get_inventory: F,
|
2021-02-12 10:51:32 +00:00
|
|
|
) {
|
2021-02-13 23:32:55 +00:00
|
|
|
trace!("for trade id {:?}, message {:?}", id, action);
|
2021-02-11 04:54:31 +00:00
|
|
|
if let Some(trade) = self.trades.get_mut(&id) {
|
|
|
|
if let Some(party) = trade.which_party(who) {
|
2021-02-28 02:44:57 +00:00
|
|
|
let mut inventories = Vec::new();
|
|
|
|
for party in trade.parties.iter() {
|
|
|
|
match get_inventory(*party) {
|
|
|
|
Some(inventory) => inventories.push(inventory),
|
|
|
|
None => return,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
trade.process_trade_action(party, action, &*inventories);
|
2021-02-11 04:54:31 +00:00
|
|
|
} else {
|
2021-02-11 19:35:36 +00:00
|
|
|
warn!(
|
2021-02-13 23:32:55 +00:00
|
|
|
"An entity who is not a party to trade {:?} tried to modify it",
|
2021-02-11 19:35:36 +00:00
|
|
|
id
|
|
|
|
);
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-02-13 23:32:55 +00:00
|
|
|
warn!("Attempt to modify nonexistent trade id {:?}", id);
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-13 23:32:55 +00:00
|
|
|
pub fn decline_trade(&mut self, id: TradeId, who: Uid) -> Option<Uid> {
|
2021-02-11 19:35:36 +00:00
|
|
|
let mut to_notify = None;
|
2021-02-11 04:54:31 +00:00
|
|
|
if let Some(trade) = self.trades.remove(&id) {
|
2021-02-11 19:35:36 +00:00
|
|
|
match trade.which_party(who) {
|
|
|
|
Some(i) => {
|
2021-02-12 23:09:18 +00:00
|
|
|
self.entity_trades.remove(&trade.parties[0]);
|
|
|
|
self.entity_trades.remove(&trade.parties[1]);
|
2021-02-11 19:35:36 +00:00
|
|
|
// let the other person know the trade was declined
|
|
|
|
to_notify = Some(trade.parties[1 - i])
|
|
|
|
},
|
|
|
|
None => {
|
|
|
|
warn!(
|
2021-02-13 23:32:55 +00:00
|
|
|
"An entity who is not a party to trade {:?} tried to decline it",
|
2021-02-11 19:35:36 +00:00
|
|
|
id
|
|
|
|
);
|
|
|
|
// put it back
|
|
|
|
self.trades.insert(id, trade);
|
|
|
|
},
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
} else {
|
2021-02-13 23:32:55 +00:00
|
|
|
warn!("Attempt to decline nonexistent trade id {:?}", id);
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
2021-02-11 19:35:36 +00:00
|
|
|
to_notify
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
2021-02-12 23:09:18 +00:00
|
|
|
|
|
|
|
/// See the doc comment on `common::trade::PendingTrade` for the
|
|
|
|
/// significance of these checks
|
|
|
|
pub fn in_trade_with_property<F: FnOnce(&PendingTrade) -> bool>(
|
|
|
|
&self,
|
|
|
|
uid: &Uid,
|
|
|
|
f: F,
|
|
|
|
) -> bool {
|
|
|
|
self.entity_trades
|
|
|
|
.get(uid)
|
|
|
|
.and_then(|trade_id| self.trades.get(trade_id))
|
|
|
|
.map(f)
|
|
|
|
// if any of the option lookups failed, we're not in any trade
|
|
|
|
.unwrap_or(false)
|
|
|
|
}
|
|
|
|
|
|
|
|
pub fn in_immutable_trade(&self, uid: &Uid) -> bool {
|
2021-02-13 23:32:55 +00:00
|
|
|
self.in_trade_with_property(uid, |trade| trade.phase() != TradePhase::Mutate)
|
2021-02-12 23:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn in_mutable_trade(&self, uid: &Uid) -> bool {
|
2021-02-13 23:32:55 +00:00
|
|
|
self.in_trade_with_property(uid, |trade| trade.phase() == TradePhase::Mutate)
|
2021-02-12 23:09:18 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
pub fn implicit_mutation_occurred(&mut self, uid: &Uid) {
|
|
|
|
if let Some(trade_id) = self.entity_trades.get(uid) {
|
|
|
|
self.trades
|
|
|
|
.get_mut(trade_id)
|
2021-02-13 23:32:55 +00:00
|
|
|
.map(|trade| trade.accept_flags = [false, false]);
|
2021-02-12 23:09:18 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Trades {
|
|
|
|
fn default() -> Trades {
|
|
|
|
Trades {
|
2021-02-13 23:32:55 +00:00
|
|
|
next_id: TradeId(0),
|
2021-02-11 04:54:31 +00:00
|
|
|
trades: HashMap::new(),
|
2021-02-12 23:09:18 +00:00
|
|
|
entity_trades: HashMap::new(),
|
2021-02-11 04:54:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
|
|
|
|
// we need this declaration in common for Merchant loadout creation, it is not
|
|
|
|
// directly related to trade between entities, but between sites (more abstract)
|
|
|
|
// economical information
|
2021-05-28 18:42:29 +00:00
|
|
|
#[derive(Clone, Copy, Debug, Eq, Hash, PartialEq, Serialize, Deserialize, EnumIter)]
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
pub enum Good {
|
|
|
|
Territory(BiomeKind),
|
|
|
|
Flour,
|
|
|
|
Meat,
|
|
|
|
Terrain(BiomeKind),
|
|
|
|
Transportation,
|
|
|
|
Food,
|
|
|
|
Wood,
|
|
|
|
Stone,
|
|
|
|
Tools, // weapons, farming tools
|
|
|
|
Armor,
|
|
|
|
Ingredients, // raw material for Armor+Tools+Potions
|
|
|
|
Potions,
|
|
|
|
Coin, // exchange material across sites
|
|
|
|
RoadSecurity,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Default for Good {
|
|
|
|
fn default() -> Self {
|
|
|
|
Good::Terrain(crate::terrain::BiomeKind::Void) // Arbitrary
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-25 04:35:33 +00:00
|
|
|
impl Good {
|
|
|
|
/// The discounting factor applied when selling goods back to a merchant
|
|
|
|
pub fn trade_margin(&self) -> f32 {
|
|
|
|
match self {
|
|
|
|
Good::Tools | Good::Armor => 0.5,
|
|
|
|
Good::Food | Good::Potions | Good::Ingredients => 0.75,
|
|
|
|
Good::Coin => 1.0,
|
|
|
|
// Certain abstract goods (like Territory) shouldn't be attached to concrete items;
|
|
|
|
// give a sale price of 0 if the player is trying to sell a concrete item that somehow
|
|
|
|
// has one of these categories
|
|
|
|
_ => 0.0,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
// ideally this would be a real Id<Site> but that is from the world crate
|
|
|
|
pub type SiteId = u64;
|
|
|
|
|
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct SiteInformation {
|
|
|
|
pub id: SiteId,
|
|
|
|
pub unconsumed_stock: HashMap<Good, f32>,
|
|
|
|
}
|
|
|
|
|
2021-03-25 04:35:33 +00:00
|
|
|
#[derive(Clone, Debug, Default, Serialize, Deserialize)]
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
pub struct SitePrices {
|
|
|
|
pub values: HashMap<Good, f32>,
|
|
|
|
}
|
|
|
|
|
2021-03-30 22:37:38 +00:00
|
|
|
impl SitePrices {
|
|
|
|
pub fn balance(
|
|
|
|
&self,
|
|
|
|
offers: &[HashMap<InvSlotId, u32>; 2],
|
|
|
|
inventories: &[Option<ReducedInventory>; 2],
|
|
|
|
who: usize,
|
|
|
|
reduce: bool,
|
|
|
|
) -> f32 {
|
|
|
|
offers[who]
|
|
|
|
.iter()
|
|
|
|
.map(|(slot, amount)| {
|
|
|
|
inventories[who]
|
|
|
|
.as_ref()
|
2021-12-21 20:19:23 +00:00
|
|
|
.and_then(|ri| {
|
2021-03-30 22:37:38 +00:00
|
|
|
ri.inventory.get(slot).map(|item| {
|
2022-03-03 02:32:34 +00:00
|
|
|
if let Some(vec) = TradePricing::get_materials(&item.name) {
|
|
|
|
vec.iter()
|
|
|
|
.map(|(amount2, material)| {
|
|
|
|
self.values.get(material).copied().unwrap_or_default()
|
|
|
|
* *amount2
|
|
|
|
* (if reduce { material.trade_margin() } else { 1.0 })
|
|
|
|
})
|
|
|
|
.sum::<f32>()
|
|
|
|
* (*amount as f32)
|
|
|
|
} else {
|
|
|
|
0.0
|
|
|
|
}
|
2021-03-30 22:37:38 +00:00
|
|
|
})
|
|
|
|
})
|
|
|
|
.unwrap_or_default()
|
|
|
|
})
|
|
|
|
.sum()
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
pub struct ReducedInventoryItem {
|
|
|
|
pub name: String,
|
|
|
|
pub amount: u32,
|
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
pub struct ReducedInventory {
|
|
|
|
pub inventory: HashMap<InvSlotId, ReducedInventoryItem>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl ReducedInventory {
|
|
|
|
pub fn from(inventory: &Inventory) -> Self {
|
|
|
|
let items = inventory
|
|
|
|
.slots_with_id()
|
|
|
|
.filter(|(_, it)| it.is_some())
|
|
|
|
.map(|(sl, it)| {
|
|
|
|
(sl, ReducedInventoryItem {
|
|
|
|
name: it.as_ref().unwrap().item_definition_id().to_string(),
|
|
|
|
amount: it.as_ref().unwrap().amount(),
|
|
|
|
})
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
Self { inventory: items }
|
|
|
|
}
|
|
|
|
}
|