2021-02-13 23:32:55 +00:00
|
|
|
use crate::Server;
|
2021-02-11 19:35:36 +00:00
|
|
|
use common::{
|
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
|
|
|
comp::{
|
|
|
|
agent::{Agent, AgentEvent},
|
2021-04-29 23:34:14 +00:00
|
|
|
inventory::{
|
|
|
|
item::{tool::AbilityMap, MaterialStatManifest},
|
|
|
|
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
|
|
|
},
|
|
|
|
trade::{PendingTrade, ReducedInventory, TradeAction, TradeId, TradeResult, Trades},
|
2021-02-11 19:35:36 +00:00
|
|
|
};
|
2021-02-28 02:44:57 +00:00
|
|
|
use common_net::{
|
|
|
|
msg::ServerGeneral,
|
|
|
|
sync::{Uid, WorldSyncExt},
|
|
|
|
};
|
2021-07-05 10:34:03 +00:00
|
|
|
use hashbrown::{hash_map::Entry, HashMap};
|
2021-02-11 19:35:36 +00:00
|
|
|
use specs::{world::WorldExt, Entity as EcsEntity};
|
2021-02-12 20:47:45 +00:00
|
|
|
use std::cmp::Ordering;
|
2021-02-13 23:32:55 +00:00
|
|
|
use tracing::{error, trace};
|
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
|
|
|
use world::IndexOwned;
|
|
|
|
|
|
|
|
fn notify_agent_simple(
|
|
|
|
mut agents: specs::WriteStorage<Agent>,
|
|
|
|
entity: EcsEntity,
|
|
|
|
event: AgentEvent,
|
|
|
|
) {
|
|
|
|
if let Some(agent) = agents.get_mut(entity) {
|
2021-05-15 19:36:27 +00:00
|
|
|
agent.inbox.push_back(event);
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn notify_agent_prices(
|
|
|
|
mut agents: specs::WriteStorage<Agent>,
|
|
|
|
index: &IndexOwned,
|
|
|
|
entity: EcsEntity,
|
|
|
|
event: AgentEvent,
|
|
|
|
) {
|
2021-04-08 16:33:00 +00:00
|
|
|
if let Some((Some(site_id), agent)) = agents.get_mut(entity).map(|a| (a.behavior.trade_site, a))
|
|
|
|
{
|
|
|
|
let prices = index.get_site_prices(site_id);
|
|
|
|
if let AgentEvent::UpdatePendingTrade(boxval) = event {
|
|
|
|
// Box<(tid, pend, _, inventories)>) = event {
|
|
|
|
agent
|
|
|
|
.inbox
|
2021-05-15 19:36:27 +00:00
|
|
|
.push_back(AgentEvent::UpdatePendingTrade(Box::new((
|
2021-04-08 16:33:00 +00:00
|
|
|
// Prefer using this Agent's price data, but use the counterparty's price
|
|
|
|
// data if we don't have price data
|
|
|
|
boxval.0,
|
|
|
|
boxval.1,
|
|
|
|
prices.unwrap_or(boxval.2),
|
|
|
|
boxval.3,
|
|
|
|
))));
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-11 19:35:36 +00:00
|
|
|
|
2021-02-12 20:47:45 +00:00
|
|
|
/// Invoked when the trade UI is up, handling item changes, accepts, etc
|
2021-02-12 02:53:25 +00:00
|
|
|
pub fn handle_process_trade_action(
|
|
|
|
server: &mut Server,
|
|
|
|
entity: EcsEntity,
|
2021-02-13 23:32:55 +00:00
|
|
|
trade_id: TradeId,
|
|
|
|
action: TradeAction,
|
2021-02-12 02:53:25 +00:00
|
|
|
) {
|
2021-02-11 19:35:36 +00:00
|
|
|
if let Some(uid) = server.state.ecs().uid_from_entity(entity) {
|
|
|
|
let mut trades = server.state.ecs().write_resource::<Trades>();
|
2021-02-13 23:32:55 +00:00
|
|
|
if let TradeAction::Decline = action {
|
2021-02-11 19:35:36 +00:00
|
|
|
let to_notify = trades.decline_trade(trade_id, uid);
|
|
|
|
to_notify
|
|
|
|
.and_then(|u| server.state.ecs().entity_from_uid(u.0))
|
2021-02-12 23:09:18 +00:00
|
|
|
.map(|e| {
|
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
|
|
|
server.notify_client(e, ServerGeneral::FinishedTrade(TradeResult::Declined));
|
|
|
|
notify_agent_simple(
|
|
|
|
server.state.ecs().write_storage::<Agent>(),
|
|
|
|
e,
|
|
|
|
AgentEvent::FinishedTrade(TradeResult::Declined),
|
|
|
|
);
|
2021-02-12 23:09:18 +00:00
|
|
|
});
|
2021-02-11 19:35:36 +00:00
|
|
|
} else {
|
2021-02-28 02:44:57 +00:00
|
|
|
{
|
|
|
|
let ecs = server.state.ecs();
|
|
|
|
let inventories = ecs.read_component::<Inventory>();
|
|
|
|
let get_inventory = |uid: Uid| {
|
|
|
|
if let Some(entity) = ecs.entity_from_uid(uid.0) {
|
|
|
|
inventories.get(entity)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
};
|
|
|
|
trades.process_trade_action(trade_id, uid, action, get_inventory);
|
2021-02-12 10:51:32 +00:00
|
|
|
}
|
2021-02-13 23:32:55 +00:00
|
|
|
if let Entry::Occupied(entry) = trades.trades.entry(trade_id) {
|
|
|
|
let parties = entry.get().parties;
|
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
|
|
|
if entry.get().should_commit() {
|
2021-02-13 23:32:55 +00:00
|
|
|
let result = commit_trade(server.state.ecs(), entry.get());
|
|
|
|
entry.remove();
|
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
|
|
|
for party in parties.iter() {
|
|
|
|
if let Some(e) = server.state.ecs().entity_from_uid(party.0) {
|
|
|
|
server.notify_client(e, ServerGeneral::FinishedTrade(result.clone()));
|
|
|
|
notify_agent_simple(
|
|
|
|
server.state.ecs().write_storage::<Agent>(),
|
|
|
|
e,
|
|
|
|
AgentEvent::FinishedTrade(result.clone()),
|
|
|
|
);
|
|
|
|
}
|
2021-10-01 21:17:19 +00:00
|
|
|
trades.entity_trades.remove_entry(party);
|
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
|
|
|
}
|
2021-02-13 23:32:55 +00:00
|
|
|
} else {
|
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
|
|
|
let mut entities: [Option<specs::Entity>; 2] = [None, None];
|
|
|
|
let mut inventories: [Option<ReducedInventory>; 2] = [None, None];
|
2021-03-25 04:35:33 +00:00
|
|
|
let mut prices = None;
|
|
|
|
let agents = server.state.ecs().read_storage::<Agent>();
|
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
|
|
|
// sadly there is no map and collect on arrays
|
|
|
|
for i in 0..2 {
|
|
|
|
// parties.len()) {
|
|
|
|
entities[i] = server.state.ecs().entity_from_uid(parties[i].0);
|
|
|
|
if let Some(e) = entities[i] {
|
|
|
|
inventories[i] = server
|
|
|
|
.state
|
|
|
|
.ecs()
|
|
|
|
.read_component::<Inventory>()
|
|
|
|
.get(e)
|
2021-11-24 09:09:22 +00:00
|
|
|
.map(ReducedInventory::from);
|
2021-03-25 04:35:33 +00:00
|
|
|
// Get price info from the first Agent in the trade (currently, an
|
|
|
|
// Agent will never initiate a trade with another agent though)
|
2021-04-15 18:07:46 +00:00
|
|
|
#[cfg(feature = "worldgen")]
|
|
|
|
{
|
|
|
|
prices = prices.or_else(|| {
|
|
|
|
agents
|
|
|
|
.get(e)
|
|
|
|
.and_then(|a| a.behavior.trade_site)
|
|
|
|
.and_then(|id| server.index.get_site_prices(id))
|
|
|
|
});
|
|
|
|
}
|
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
|
|
|
}
|
|
|
|
}
|
2021-03-25 04:35:33 +00:00
|
|
|
drop(agents);
|
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
|
|
|
for party in entities.iter() {
|
|
|
|
if let Some(e) = *party {
|
|
|
|
server.notify_client(
|
|
|
|
e,
|
2021-03-25 04:35:33 +00:00
|
|
|
ServerGeneral::UpdatePendingTrade(
|
|
|
|
trade_id,
|
|
|
|
entry.get().clone(),
|
|
|
|
prices.clone(),
|
|
|
|
),
|
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
|
|
|
);
|
2021-04-15 18:07:46 +00:00
|
|
|
#[cfg(feature = "worldgen")]
|
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
|
|
|
notify_agent_prices(
|
|
|
|
server.state.ecs().write_storage::<Agent>(),
|
|
|
|
&server.index,
|
|
|
|
e,
|
|
|
|
AgentEvent::UpdatePendingTrade(Box::new((
|
|
|
|
trade_id,
|
|
|
|
entry.get().clone(),
|
2021-03-25 04:35:33 +00:00
|
|
|
prices.clone().unwrap_or_default(),
|
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
|
|
|
inventories.clone(),
|
|
|
|
))),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-02-11 19:35:36 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-12 20:47:45 +00:00
|
|
|
|
2021-04-12 23:00:38 +00:00
|
|
|
//Cancel all trades registered for a given UID.
|
|
|
|
pub fn cancel_trade_for(server: &mut Server, entity: EcsEntity) {
|
|
|
|
if let Some(uid) = server.state().ecs().uid_from_entity(entity) {
|
|
|
|
let mut trades = server.state.ecs().write_resource::<Trades>();
|
|
|
|
|
|
|
|
let active_trade = match trades.entity_trades.get(&uid) {
|
|
|
|
Some(n) => *n,
|
|
|
|
None => {
|
|
|
|
return;
|
|
|
|
},
|
|
|
|
};
|
|
|
|
|
|
|
|
let to_notify = trades.decline_trade(active_trade, uid);
|
|
|
|
to_notify
|
|
|
|
.and_then(|u| server.state.ecs().entity_from_uid(u.0))
|
|
|
|
.map(|e| {
|
|
|
|
server.notify_client(e, ServerGeneral::FinishedTrade(TradeResult::Declined));
|
|
|
|
notify_agent_simple(
|
|
|
|
server.state.ecs().write_storage::<Agent>(),
|
|
|
|
e,
|
|
|
|
AgentEvent::FinishedTrade(TradeResult::Declined),
|
|
|
|
);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 23:09:18 +00:00
|
|
|
/// Commit a trade that both parties have agreed to, modifying their respective
|
|
|
|
/// inventories
|
2021-02-12 20:47:45 +00:00
|
|
|
fn commit_trade(ecs: &specs::World, trade: &PendingTrade) -> TradeResult {
|
2021-02-13 23:32:55 +00:00
|
|
|
let mut entities = Vec::new();
|
|
|
|
for party in trade.parties.iter() {
|
|
|
|
match ecs.entity_from_uid(party.0) {
|
2021-02-12 20:47:45 +00:00
|
|
|
Some(entity) => entities.push(entity),
|
|
|
|
None => return TradeResult::Declined,
|
|
|
|
}
|
|
|
|
}
|
2021-04-09 07:34:58 +00:00
|
|
|
let mut inventories = ecs.write_storage::<Inventory>();
|
2021-02-13 23:32:55 +00:00
|
|
|
for entity in entities.iter() {
|
|
|
|
if inventories.get_mut(*entity).is_none() {
|
2021-02-12 20:47:45 +00:00
|
|
|
return TradeResult::Declined;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
let invmsg = "inventories.get_mut(entities[who]).is_none() should have returned already";
|
|
|
|
trace!("committing trade: {:?}", trade);
|
2021-02-12 23:09:18 +00:00
|
|
|
// Compute the net change in slots of each player during the trade, to detect
|
|
|
|
// out-of-space-ness before transferring any items
|
2021-07-05 10:34:03 +00:00
|
|
|
let mut delta_slots: [i64; 2] = [0, 0];
|
|
|
|
|
|
|
|
// local struct used to calculate delta_slots for stackable items.
|
|
|
|
// Uses u128 as an intermediate value to prevent overflow.
|
|
|
|
#[derive(Default)]
|
|
|
|
struct ItemQuantities {
|
|
|
|
full_stacks: u64,
|
|
|
|
quantity_sold: u128,
|
|
|
|
freed_capacity: u128,
|
|
|
|
unusable_capacity: u128,
|
|
|
|
}
|
|
|
|
|
|
|
|
// local struct used to calculate delta_slots for stackable items
|
|
|
|
struct TradeQuantities {
|
|
|
|
max_stack_size: u32,
|
|
|
|
trade_quantities: [ItemQuantities; 2],
|
|
|
|
}
|
|
|
|
|
|
|
|
impl TradeQuantities {
|
|
|
|
fn new(max_stack_size: u32) -> Self {
|
|
|
|
Self {
|
|
|
|
max_stack_size,
|
|
|
|
trade_quantities: [ItemQuantities::default(), ItemQuantities::default()],
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Hashmap to compute merged stackable stacks, including overflow checks
|
|
|
|
// TODO: add a ComponentKey struct to compare items properly, see issue #1226
|
|
|
|
let mut stackable_items: HashMap<String, TradeQuantities> = HashMap::new();
|
2021-02-12 20:47:45 +00:00
|
|
|
for who in [0, 1].iter().cloned() {
|
|
|
|
for (slot, quantity) in trade.offers[who].iter() {
|
|
|
|
let inventory = inventories.get_mut(entities[who]).expect(invmsg);
|
|
|
|
let item = match inventory.get(*slot) {
|
|
|
|
Some(item) => item,
|
|
|
|
None => {
|
2021-02-12 23:09:18 +00:00
|
|
|
error!(
|
|
|
|
"PendingTrade invariant violation in trade {:?}: slots offered in a trade \
|
|
|
|
should be non-empty",
|
|
|
|
trade
|
|
|
|
);
|
2021-02-12 20:47:45 +00:00
|
|
|
return TradeResult::Declined;
|
|
|
|
},
|
|
|
|
};
|
2021-07-05 10:34:03 +00:00
|
|
|
|
|
|
|
// assuming the quantity is never 0
|
|
|
|
match item.amount().cmp(quantity) {
|
2021-02-12 20:47:45 +00:00
|
|
|
Ordering::Less => {
|
2021-02-12 23:09:18 +00:00
|
|
|
error!(
|
|
|
|
"PendingTrade invariant violation in trade {:?}: party {} offered more of \
|
|
|
|
an item than they have",
|
|
|
|
trade, who
|
|
|
|
);
|
2021-02-12 20:47:45 +00:00
|
|
|
return TradeResult::Declined;
|
|
|
|
},
|
|
|
|
Ordering::Equal => {
|
2021-07-05 10:34:03 +00:00
|
|
|
if item.is_stackable() {
|
|
|
|
// Marks a full stack to remove. Can no longer accept items from the other
|
|
|
|
// party, and therefore adds the remaining capacity it holds to
|
|
|
|
// `unusable_capacity`.
|
|
|
|
let TradeQuantities {
|
|
|
|
max_stack_size,
|
|
|
|
trade_quantities,
|
|
|
|
} = stackable_items
|
|
|
|
.entry(item.item_definition_id().to_string())
|
|
|
|
.or_insert_with(|| TradeQuantities::new(item.max_amount()));
|
|
|
|
|
|
|
|
trade_quantities[who].full_stacks += 1;
|
|
|
|
trade_quantities[who].quantity_sold += *quantity as u128;
|
|
|
|
trade_quantities[who].unusable_capacity +=
|
|
|
|
*max_stack_size as u128 - item.amount() as u128;
|
|
|
|
} else {
|
|
|
|
delta_slots[who] -= 1; // exact, removes the whole stack
|
|
|
|
delta_slots[1 - who] += 1; // item is not stackable, so the stacks won't merge
|
|
|
|
}
|
2021-02-12 20:47:45 +00:00
|
|
|
},
|
|
|
|
Ordering::Greater => {
|
2021-07-05 10:34:03 +00:00
|
|
|
if item.is_stackable() {
|
|
|
|
// Marks a partial stack to remove, able to accepts items from the other
|
|
|
|
// party, and therefore adds the additional capacity freed after the item
|
|
|
|
// exchange to `freed_capacity`.
|
|
|
|
let TradeQuantities {
|
|
|
|
max_stack_size: _,
|
|
|
|
trade_quantities,
|
|
|
|
} = stackable_items
|
|
|
|
.entry(item.item_definition_id().to_string())
|
|
|
|
.or_insert_with(|| TradeQuantities::new(item.max_amount()));
|
|
|
|
|
|
|
|
trade_quantities[who].quantity_sold += *quantity as u128;
|
|
|
|
trade_quantities[who].freed_capacity += *quantity as u128;
|
|
|
|
} else {
|
|
|
|
// unreachable in theory
|
|
|
|
error!(
|
|
|
|
"Inventory invariant violation in trade {:?}: party {} has a stack \
|
|
|
|
larger than 1 of an unstackable item",
|
|
|
|
trade, who
|
|
|
|
);
|
|
|
|
return TradeResult::Declined;
|
|
|
|
}
|
2021-02-12 20:47:45 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-05 10:34:03 +00:00
|
|
|
// at this point delta_slots only contains the slot variations for unstackable
|
|
|
|
// items. The following loops calculates capacity for stackable items and
|
|
|
|
// computes the final delta_slots in consequence.
|
|
|
|
|
|
|
|
for (
|
|
|
|
item_id,
|
|
|
|
TradeQuantities {
|
|
|
|
max_stack_size,
|
|
|
|
trade_quantities,
|
|
|
|
},
|
|
|
|
) in stackable_items.iter()
|
|
|
|
{
|
|
|
|
for who in [0, 1].iter().cloned() {
|
|
|
|
// removes all exchanged full stacks.
|
|
|
|
delta_slots[who] -= trade_quantities[who].full_stacks as i64;
|
|
|
|
|
|
|
|
// calculates the available item capacity in the other party's inventory,
|
|
|
|
// substracting the unusable space calculated previously,
|
|
|
|
// and adding the capacity freed by the trade.
|
|
|
|
let other_party_capacity = inventories
|
|
|
|
.get_mut(entities[1 - who])
|
|
|
|
.expect(invmsg)
|
|
|
|
.slots()
|
|
|
|
.flatten()
|
|
|
|
.filter_map(|it| {
|
|
|
|
if it.item_definition_id() == item_id {
|
|
|
|
Some(*max_stack_size as u128 - it.amount() as u128)
|
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
})
|
|
|
|
.sum::<u128>()
|
|
|
|
- trade_quantities[1 - who].unusable_capacity
|
|
|
|
+ trade_quantities[1 - who].freed_capacity;
|
|
|
|
|
|
|
|
// checks if the capacity in remaining partial stacks of the other party is
|
|
|
|
// enough to contain everything, creates more stacks otherwise
|
|
|
|
if other_party_capacity < trade_quantities[who].quantity_sold {
|
|
|
|
let surplus = trade_quantities[who].quantity_sold - other_party_capacity;
|
|
|
|
// the total amount of exchanged slots can never exceed the max inventory size
|
|
|
|
// (around 4 * 2^32 slots), so the cast to i64 should be safe
|
|
|
|
delta_slots[1 - who] += (surplus / *max_stack_size as u128) as i64 + 1;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-12 20:47:45 +00:00
|
|
|
trace!("delta_slots: {:?}", delta_slots);
|
|
|
|
for who in [0, 1].iter().cloned() {
|
2021-07-05 10:34:03 +00:00
|
|
|
// Inventories should never exceed 2^{63} slots, so the usize -> i64
|
2021-02-12 23:09:18 +00:00
|
|
|
// conversions here should be safe
|
2021-02-12 20:47:45 +00:00
|
|
|
let inv = inventories.get_mut(entities[who]).expect(invmsg);
|
2021-07-05 10:34:03 +00:00
|
|
|
if inv.populated_slots() as i64 + delta_slots[who] > inv.capacity() as i64 {
|
2021-02-12 20:47:45 +00:00
|
|
|
return TradeResult::NotEnoughSpace;
|
|
|
|
}
|
|
|
|
}
|
2021-07-05 10:34:03 +00:00
|
|
|
|
2021-02-13 23:32:55 +00:00
|
|
|
let mut items = [Vec::new(), Vec::new()];
|
2021-04-29 23:34:14 +00:00
|
|
|
let ability_map = ecs.read_resource::<AbilityMap>();
|
2021-02-23 20:29:27 +00:00
|
|
|
let msm = ecs.read_resource::<MaterialStatManifest>();
|
2021-02-12 20:47:45 +00:00
|
|
|
for who in [0, 1].iter().cloned() {
|
|
|
|
for (slot, quantity) in trade.offers[who].iter() {
|
2021-02-13 23:32:55 +00:00
|
|
|
// Take the items one by one, to benefit from Inventory's stack handling
|
2021-02-12 20:47:45 +00:00
|
|
|
for _ in 0..*quantity {
|
2021-02-12 23:09:18 +00:00
|
|
|
inventories
|
|
|
|
.get_mut(entities[who])
|
|
|
|
.expect(invmsg)
|
2021-04-29 23:34:14 +00:00
|
|
|
.take(*slot, &ability_map, &msm)
|
2021-02-12 23:09:18 +00:00
|
|
|
.map(|item| items[who].push(item));
|
2021-02-12 20:47:45 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-05 10:34:03 +00:00
|
|
|
|
2021-02-12 20:47:45 +00:00
|
|
|
for who in [0, 1].iter().cloned() {
|
2021-02-12 23:09:18 +00:00
|
|
|
if let Err(leftovers) = inventories
|
|
|
|
.get_mut(entities[1 - who])
|
|
|
|
.expect(invmsg)
|
|
|
|
.push_all(items[who].drain(..))
|
|
|
|
{
|
2021-02-13 23:32:55 +00:00
|
|
|
// This should only happen if the arithmetic above for delta_slots says there's
|
2021-02-12 23:09:18 +00:00
|
|
|
// enough space and there isn't (i.e. underapproximates)
|
2021-02-13 23:32:55 +00:00
|
|
|
panic!(
|
|
|
|
"Not enough space for all the items, leftovers are {:?}",
|
2021-02-12 23:09:18 +00:00
|
|
|
leftovers
|
|
|
|
);
|
2021-02-12 20:47:45 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-05 10:34:03 +00:00
|
|
|
|
2021-02-12 20:47:45 +00:00
|
|
|
TradeResult::Completed
|
|
|
|
}
|
2021-07-05 10:34:03 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use hashbrown::HashMap;
|
|
|
|
|
|
|
|
use super::*;
|
|
|
|
use common::{comp::slot::InvSlotId, uid::UidAllocator};
|
|
|
|
|
|
|
|
use specs::{Builder, World};
|
|
|
|
|
|
|
|
// Creates a specs World containing two Entities which have Inventory
|
|
|
|
// components. Left over inventory size is determined by input. Mapping to the
|
|
|
|
// returned Entities. Any input over the maximum default inventory size will
|
|
|
|
// result in maximum left over space.
|
|
|
|
fn create_mock_trading_world(
|
|
|
|
player_inv_size: usize,
|
|
|
|
merchant_inv_size: usize,
|
|
|
|
) -> (World, EcsEntity, EcsEntity) {
|
|
|
|
let mut mockworld = World::new();
|
|
|
|
mockworld.insert(UidAllocator::new());
|
|
|
|
mockworld.insert(MaterialStatManifest::default());
|
|
|
|
mockworld.insert(AbilityMap::default());
|
|
|
|
mockworld.register::<Inventory>();
|
|
|
|
mockworld.register::<Uid>();
|
|
|
|
|
2021-12-21 20:19:23 +00:00
|
|
|
let player: EcsEntity = mockworld
|
2021-07-05 10:34:03 +00:00
|
|
|
.create_entity()
|
|
|
|
.with(Inventory::new_empty())
|
|
|
|
.build();
|
|
|
|
|
2021-12-21 20:19:23 +00:00
|
|
|
let merchant: EcsEntity = mockworld
|
2021-07-05 10:34:03 +00:00
|
|
|
.create_entity()
|
|
|
|
.with(Inventory::new_empty())
|
|
|
|
.build();
|
|
|
|
|
|
|
|
{
|
|
|
|
use specs::saveload::MarkerAllocator;
|
|
|
|
let mut uids = mockworld.write_component::<Uid>();
|
|
|
|
let mut uid_allocator = mockworld.write_resource::<UidAllocator>();
|
|
|
|
uids.insert(player, uid_allocator.allocate(player, None))
|
|
|
|
.expect("inserting player uid failed");
|
|
|
|
uids.insert(merchant, uid_allocator.allocate(merchant, None))
|
|
|
|
.expect("inserting merchant uid failed");
|
|
|
|
}
|
|
|
|
|
|
|
|
let invmsg = "inventories.get_mut().is_none() should have returned already";
|
|
|
|
let capmsg = "There should be enough space here";
|
|
|
|
let mut inventories = mockworld.write_component::<Inventory>();
|
|
|
|
let mut playerinv = inventories.get_mut(player).expect(invmsg);
|
|
|
|
if player_inv_size < playerinv.capacity() {
|
|
|
|
for _ in player_inv_size..playerinv.capacity() {
|
|
|
|
playerinv
|
|
|
|
.push(common::comp::Item::new_from_asset_expect(
|
|
|
|
"common.items.npc_armor.pants.plate_red",
|
|
|
|
))
|
|
|
|
.expect(capmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
let mut merchantinv = inventories.get_mut(merchant).expect(invmsg);
|
|
|
|
if merchant_inv_size < merchantinv.capacity() {
|
|
|
|
for _ in merchant_inv_size..merchantinv.capacity() {
|
|
|
|
merchantinv
|
|
|
|
.push(common::comp::Item::new_from_asset_expect(
|
|
|
|
"common.items.armor.cloth_purple.foot",
|
|
|
|
))
|
|
|
|
.expect(capmsg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
drop(inventories);
|
|
|
|
|
|
|
|
(mockworld, player, merchant)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn prepare_merchant_inventory(mockworld: &World, merchant: EcsEntity) {
|
|
|
|
let mut inventories = mockworld.write_component::<Inventory>();
|
|
|
|
let invmsg = "inventories.get_mut().is_none() should have returned already";
|
|
|
|
let capmsg = "There should be enough space here";
|
|
|
|
let mut merchantinv = inventories.get_mut(merchant).expect(invmsg);
|
|
|
|
for _ in 0..10 {
|
|
|
|
merchantinv
|
|
|
|
.push(common::comp::Item::new_from_asset_expect(
|
|
|
|
"common.items.consumable.potion_minor",
|
|
|
|
))
|
|
|
|
.expect(capmsg);
|
|
|
|
merchantinv
|
|
|
|
.push(common::comp::Item::new_from_asset_expect(
|
|
|
|
"common.items.food.meat.fish_cooked",
|
|
|
|
))
|
|
|
|
.expect(capmsg);
|
|
|
|
}
|
|
|
|
drop(inventories);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn commit_trade_with_stackable_item_test() {
|
2021-11-21 02:52:51 +00:00
|
|
|
use common::{assets::AssetExt, comp::item::ItemDef};
|
|
|
|
use std::sync::Arc;
|
|
|
|
|
2021-07-05 10:34:03 +00:00
|
|
|
let (mockworld, player, merchant) = create_mock_trading_world(1, 20);
|
|
|
|
|
|
|
|
prepare_merchant_inventory(&mockworld, merchant);
|
|
|
|
|
|
|
|
let invmsg = "inventories.get_mut().is_none() should have returned already";
|
|
|
|
let capmsg = "There should be enough space here";
|
|
|
|
let mut inventories = mockworld.write_component::<Inventory>();
|
|
|
|
|
|
|
|
let mut playerinv = inventories.get_mut(player).expect(invmsg);
|
|
|
|
playerinv
|
|
|
|
.push(common::comp::Item::new_from_asset_expect(
|
|
|
|
"common.items.consumable.potion_minor",
|
|
|
|
))
|
|
|
|
.expect(capmsg);
|
|
|
|
|
2021-11-21 02:52:51 +00:00
|
|
|
let potion_asset = "common.items.consumable.potion_minor";
|
|
|
|
|
|
|
|
let potion = common::comp::Item::new_from_asset_expect(potion_asset);
|
|
|
|
let potion_def = Arc::<ItemDef>::load_expect_cloned(potion_asset);
|
|
|
|
|
2021-07-05 10:34:03 +00:00
|
|
|
let merchantinv = inventories.get_mut(merchant).expect(invmsg);
|
|
|
|
|
|
|
|
let potioninvid = merchantinv
|
|
|
|
.get_slot_of_item(&potion)
|
|
|
|
.expect("expected get_slot_of_item to return");
|
|
|
|
|
|
|
|
let playerid = mockworld
|
|
|
|
.uid_from_entity(player)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
let merchantid = mockworld
|
|
|
|
.uid_from_entity(merchant)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
|
|
|
|
let playeroffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
let mut merchantoffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
merchantoffers.insert(potioninvid, 1);
|
|
|
|
|
|
|
|
let trade = PendingTrade {
|
|
|
|
parties: [playerid, merchantid],
|
|
|
|
accept_flags: [true, true],
|
|
|
|
offers: [playeroffers, merchantoffers],
|
|
|
|
phase: common::trade::TradePhase::Review,
|
|
|
|
};
|
|
|
|
|
|
|
|
drop(inventories);
|
|
|
|
|
|
|
|
let traderes = commit_trade(&mockworld, &trade);
|
|
|
|
assert_eq!(traderes, TradeResult::Completed);
|
|
|
|
|
|
|
|
let mut inventories = mockworld.write_component::<Inventory>();
|
|
|
|
let playerinv = inventories.get_mut(player).expect(invmsg);
|
2021-11-21 02:52:51 +00:00
|
|
|
let potioncount = playerinv.item_count(&potion_def);
|
2021-07-05 10:34:03 +00:00
|
|
|
assert_eq!(potioncount, 2);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn commit_trade_with_full_inventory_test() {
|
|
|
|
let (mockworld, player, merchant) = create_mock_trading_world(1, 20);
|
|
|
|
|
|
|
|
prepare_merchant_inventory(&mockworld, merchant);
|
|
|
|
|
|
|
|
let invmsg = "inventories.get_mut().is_none() should have returned already";
|
|
|
|
let capmsg = "There should be enough space here";
|
|
|
|
let mut inventories = mockworld.write_component::<Inventory>();
|
|
|
|
|
|
|
|
let mut playerinv = inventories.get_mut(player).expect(invmsg);
|
|
|
|
playerinv
|
|
|
|
.push(common::comp::Item::new_from_asset_expect(
|
|
|
|
"common.items.consumable.potion_minor",
|
|
|
|
))
|
|
|
|
.expect(capmsg);
|
|
|
|
|
|
|
|
let fish = common::comp::Item::new_from_asset_expect("common.items.food.meat.fish_cooked");
|
|
|
|
let merchantinv = inventories.get_mut(merchant).expect(invmsg);
|
|
|
|
|
|
|
|
let fishinvid = merchantinv
|
|
|
|
.get_slot_of_item(&fish)
|
|
|
|
.expect("expected get_slot_of_item to return");
|
|
|
|
|
|
|
|
let playerid = mockworld
|
|
|
|
.uid_from_entity(player)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
let merchantid = mockworld
|
|
|
|
.uid_from_entity(merchant)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
|
|
|
|
let playeroffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
let mut merchantoffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
merchantoffers.insert(fishinvid, 1);
|
|
|
|
let trade = PendingTrade {
|
|
|
|
parties: [playerid, merchantid],
|
|
|
|
accept_flags: [true, true],
|
|
|
|
offers: [playeroffers, merchantoffers],
|
|
|
|
phase: common::trade::TradePhase::Review,
|
|
|
|
};
|
|
|
|
|
|
|
|
drop(inventories);
|
|
|
|
|
|
|
|
let traderes = commit_trade(&mockworld, &trade);
|
|
|
|
assert_eq!(traderes, TradeResult::NotEnoughSpace);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn commit_trade_with_empty_inventory_test() {
|
|
|
|
let (mockworld, player, merchant) = create_mock_trading_world(20, 20);
|
|
|
|
|
|
|
|
prepare_merchant_inventory(&mockworld, merchant);
|
|
|
|
|
|
|
|
let invmsg = "inventories.get_mut().is_none() should have returned already";
|
|
|
|
let mut inventories = mockworld.write_component::<Inventory>();
|
|
|
|
|
|
|
|
let fish = common::comp::Item::new_from_asset_expect("common.items.food.meat.fish_cooked");
|
|
|
|
let merchantinv = inventories.get_mut(merchant).expect(invmsg);
|
|
|
|
|
|
|
|
let fishinvid = merchantinv
|
|
|
|
.get_slot_of_item(&fish)
|
|
|
|
.expect("expected get_slot_of_item to return");
|
|
|
|
|
|
|
|
let playerid = mockworld
|
|
|
|
.uid_from_entity(player)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
let merchantid = mockworld
|
|
|
|
.uid_from_entity(merchant)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
|
|
|
|
let playeroffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
let mut merchantoffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
merchantoffers.insert(fishinvid, 1);
|
|
|
|
let trade = PendingTrade {
|
|
|
|
parties: [playerid, merchantid],
|
|
|
|
accept_flags: [true, true],
|
|
|
|
offers: [playeroffers, merchantoffers],
|
|
|
|
phase: common::trade::TradePhase::Review,
|
|
|
|
};
|
|
|
|
|
|
|
|
drop(inventories);
|
|
|
|
|
|
|
|
let traderes = commit_trade(&mockworld, &trade);
|
|
|
|
assert_eq!(traderes, TradeResult::Completed);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn commit_trade_with_both_full_inventories_test() {
|
|
|
|
let (mockworld, player, merchant) = create_mock_trading_world(2, 2);
|
|
|
|
|
|
|
|
prepare_merchant_inventory(&mockworld, merchant);
|
|
|
|
|
|
|
|
let invmsg = "inventories.get_mut().is_none() should have returned already";
|
|
|
|
let capmsg = "There should be enough space here";
|
|
|
|
let mut inventories = mockworld.write_component::<Inventory>();
|
|
|
|
|
|
|
|
let fish = common::comp::Item::new_from_asset_expect("common.items.food.meat.fish_cooked");
|
|
|
|
let merchantinv = inventories.get_mut(merchant).expect(invmsg);
|
|
|
|
let fishinvid = merchantinv
|
|
|
|
.get_slot_of_item(&fish)
|
|
|
|
.expect("expected get_slot_of_item to return");
|
|
|
|
|
|
|
|
let potion =
|
|
|
|
common::comp::Item::new_from_asset_expect("common.items.consumable.potion_minor");
|
|
|
|
let mut playerinv = inventories.get_mut(player).expect(invmsg);
|
|
|
|
playerinv
|
|
|
|
.push(common::comp::Item::new_from_asset_expect(
|
|
|
|
"common.items.consumable.potion_minor",
|
|
|
|
))
|
|
|
|
.expect(capmsg);
|
|
|
|
let potioninvid = playerinv
|
|
|
|
.get_slot_of_item(&potion)
|
|
|
|
.expect("expected get_slot_of_item to return");
|
|
|
|
|
|
|
|
let playerid = mockworld
|
|
|
|
.uid_from_entity(player)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
let merchantid = mockworld
|
|
|
|
.uid_from_entity(merchant)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
|
|
|
|
let mut playeroffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
playeroffers.insert(potioninvid, 1);
|
|
|
|
|
|
|
|
let mut merchantoffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
merchantoffers.insert(fishinvid, 10);
|
|
|
|
let trade = PendingTrade {
|
|
|
|
parties: [playerid, merchantid],
|
|
|
|
accept_flags: [true, true],
|
|
|
|
offers: [playeroffers, merchantoffers],
|
|
|
|
phase: common::trade::TradePhase::Review,
|
|
|
|
};
|
|
|
|
|
|
|
|
drop(inventories);
|
|
|
|
|
|
|
|
let traderes = commit_trade(&mockworld, &trade);
|
|
|
|
assert_eq!(traderes, TradeResult::Completed);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn commit_trade_with_overflow() {
|
|
|
|
let (mockworld, player, merchant) = create_mock_trading_world(2, 20);
|
|
|
|
|
|
|
|
prepare_merchant_inventory(&mockworld, merchant);
|
|
|
|
|
|
|
|
let invmsg = "inventories.get_mut().is_none() should have returned already";
|
|
|
|
let capmsg = "There should be enough space here";
|
|
|
|
let mut inventories = mockworld.write_component::<Inventory>();
|
|
|
|
|
|
|
|
let mut playerinv = inventories.get_mut(player).expect(invmsg);
|
|
|
|
let mut potion =
|
|
|
|
common::comp::Item::new_from_asset_expect("common.items.consumable.potion_minor");
|
|
|
|
potion
|
|
|
|
.set_amount(potion.max_amount() - 2)
|
|
|
|
.expect("Should be below the max amount");
|
|
|
|
playerinv.push(potion).expect(capmsg);
|
|
|
|
|
|
|
|
let potion =
|
|
|
|
common::comp::Item::new_from_asset_expect("common.items.consumable.potion_minor");
|
|
|
|
let merchantinv = inventories.get_mut(merchant).expect(invmsg);
|
|
|
|
|
|
|
|
let potioninvid = merchantinv
|
|
|
|
.get_slot_of_item(&potion)
|
|
|
|
.expect("expected get_slot_of_item to return");
|
|
|
|
|
|
|
|
let playerid = mockworld
|
|
|
|
.uid_from_entity(player)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
let merchantid = mockworld
|
|
|
|
.uid_from_entity(merchant)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
|
|
|
|
let playeroffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
let mut merchantoffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
merchantoffers.insert(potioninvid, 10);
|
|
|
|
let trade = PendingTrade {
|
|
|
|
parties: [playerid, merchantid],
|
|
|
|
accept_flags: [true, true],
|
|
|
|
offers: [playeroffers, merchantoffers],
|
|
|
|
phase: common::trade::TradePhase::Review,
|
|
|
|
};
|
|
|
|
|
|
|
|
drop(inventories);
|
|
|
|
|
|
|
|
let traderes = commit_trade(&mockworld, &trade);
|
|
|
|
assert_eq!(traderes, TradeResult::Completed);
|
|
|
|
|
|
|
|
let mut inventories = mockworld.write_component::<Inventory>();
|
|
|
|
let mut playerinv = inventories.get_mut(player).expect(invmsg);
|
|
|
|
|
|
|
|
let slot1 = playerinv
|
|
|
|
.get_slot_of_item(&potion)
|
|
|
|
.expect("There should be a slot here");
|
|
|
|
let item1 = playerinv
|
|
|
|
.remove(slot1)
|
|
|
|
.expect("The slot should not be empty");
|
|
|
|
|
|
|
|
let slot2 = playerinv
|
|
|
|
.get_slot_of_item(&potion)
|
|
|
|
.expect("There should be a slot here");
|
|
|
|
let item2 = playerinv
|
|
|
|
.remove(slot2)
|
|
|
|
.expect("The slot should not be empty");
|
|
|
|
|
|
|
|
assert_eq!(item1.amount(), potion.max_amount());
|
|
|
|
assert_eq!(item2.amount(), 8);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn commit_trade_with_inventory_overflow_failure() {
|
|
|
|
let (mockworld, player, merchant) = create_mock_trading_world(2, 20);
|
|
|
|
|
|
|
|
prepare_merchant_inventory(&mockworld, merchant);
|
|
|
|
|
|
|
|
let invmsg = "inventories.get_mut().is_none() should have returned already";
|
|
|
|
let capmsg = "There should be enough space here";
|
|
|
|
let mut inventories = mockworld.write_component::<Inventory>();
|
|
|
|
|
|
|
|
let mut playerinv = inventories.get_mut(player).expect(invmsg);
|
|
|
|
let mut potion =
|
|
|
|
common::comp::Item::new_from_asset_expect("common.items.consumable.potion_minor");
|
|
|
|
potion
|
|
|
|
.set_amount(potion.max_amount() - 2)
|
|
|
|
.expect("Should be below the max amount");
|
|
|
|
playerinv.push(potion).expect(capmsg);
|
|
|
|
let mut potion =
|
|
|
|
common::comp::Item::new_from_asset_expect("common.items.consumable.potion_minor");
|
|
|
|
potion
|
|
|
|
.set_amount(potion.max_amount() - 2)
|
|
|
|
.expect("Should be below the max amount");
|
|
|
|
playerinv.push(potion).expect(capmsg);
|
|
|
|
|
|
|
|
let potion =
|
|
|
|
common::comp::Item::new_from_asset_expect("common.items.consumable.potion_minor");
|
|
|
|
let merchantinv = inventories.get_mut(merchant).expect(invmsg);
|
|
|
|
|
|
|
|
let potioninvid = merchantinv
|
|
|
|
.get_slot_of_item(&potion)
|
|
|
|
.expect("expected get_slot_of_item to return");
|
|
|
|
|
|
|
|
let playerid = mockworld
|
|
|
|
.uid_from_entity(player)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
let merchantid = mockworld
|
|
|
|
.uid_from_entity(merchant)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
|
|
|
|
let playeroffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
let mut merchantoffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
merchantoffers.insert(potioninvid, 5);
|
|
|
|
let trade = PendingTrade {
|
|
|
|
parties: [playerid, merchantid],
|
|
|
|
accept_flags: [true, true],
|
|
|
|
offers: [playeroffers, merchantoffers],
|
|
|
|
phase: common::trade::TradePhase::Review,
|
|
|
|
};
|
|
|
|
|
|
|
|
drop(inventories);
|
|
|
|
|
|
|
|
let traderes = commit_trade(&mockworld, &trade);
|
|
|
|
assert_eq!(traderes, TradeResult::NotEnoughSpace);
|
|
|
|
}
|
|
|
|
|
|
|
|
#[test]
|
|
|
|
fn commit_trade_with_inventory_overflow_success() {
|
|
|
|
let (mockworld, player, merchant) = create_mock_trading_world(2, 20);
|
|
|
|
|
|
|
|
prepare_merchant_inventory(&mockworld, merchant);
|
|
|
|
|
|
|
|
let invmsg = "inventories.get_mut().is_none() should have returned already";
|
|
|
|
let capmsg = "There should be enough space here";
|
|
|
|
let mut inventories = mockworld.write_component::<Inventory>();
|
|
|
|
|
|
|
|
let mut playerinv = inventories.get_mut(player).expect(invmsg);
|
|
|
|
let mut potion =
|
|
|
|
common::comp::Item::new_from_asset_expect("common.items.consumable.potion_minor");
|
|
|
|
potion
|
|
|
|
.set_amount(potion.max_amount() - 2)
|
|
|
|
.expect("Should be below the max amount");
|
|
|
|
playerinv.push(potion).expect(capmsg);
|
|
|
|
let mut potion =
|
|
|
|
common::comp::Item::new_from_asset_expect("common.items.consumable.potion_minor");
|
|
|
|
potion
|
|
|
|
.set_amount(potion.max_amount() - 2)
|
|
|
|
.expect("Should be below the max amount");
|
|
|
|
playerinv.push(potion).expect(capmsg);
|
|
|
|
|
|
|
|
let potion =
|
|
|
|
common::comp::Item::new_from_asset_expect("common.items.consumable.potion_minor");
|
|
|
|
let merchantinv = inventories.get_mut(merchant).expect(invmsg);
|
|
|
|
|
|
|
|
let potioninvid = merchantinv
|
|
|
|
.get_slot_of_item(&potion)
|
|
|
|
.expect("expected get_slot_of_item to return");
|
|
|
|
|
|
|
|
let playerid = mockworld
|
|
|
|
.uid_from_entity(player)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
let merchantid = mockworld
|
|
|
|
.uid_from_entity(merchant)
|
|
|
|
.expect("mockworld.uid_from_entity(player) should have returned");
|
|
|
|
|
|
|
|
let playeroffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
let mut merchantoffers: HashMap<InvSlotId, u32> = HashMap::new();
|
|
|
|
merchantoffers.insert(potioninvid, 4);
|
|
|
|
let trade = PendingTrade {
|
|
|
|
parties: [playerid, merchantid],
|
|
|
|
accept_flags: [true, true],
|
|
|
|
offers: [playeroffers, merchantoffers],
|
|
|
|
phase: common::trade::TradePhase::Review,
|
|
|
|
};
|
|
|
|
|
|
|
|
drop(inventories);
|
|
|
|
|
|
|
|
let traderes = commit_trade(&mockworld, &trade);
|
|
|
|
assert_eq!(traderes, TradeResult::Completed);
|
|
|
|
}
|
|
|
|
}
|