2020-08-13 19:22:47 +00:00
|
|
|
use crate::{
|
2020-09-16 03:17:56 +00:00
|
|
|
comp::{humanoid, quadruped_low, quadruped_medium, quadruped_small, Body},
|
2021-02-23 02:16:07 +00:00
|
|
|
path::Chaser,
|
2020-11-12 21:31:28 +00:00
|
|
|
rtsim::RtSimController,
|
2021-04-07 20:11:29 +00:00
|
|
|
trade::{PendingTrade, ReducedInventory, SiteId, SitePrices, TradeId, TradeResult},
|
2020-12-13 17:11:55 +00:00
|
|
|
uid::Uid,
|
2020-08-13 19:22:47 +00:00
|
|
|
};
|
2020-04-26 17:03:19 +00:00
|
|
|
use specs::{Component, Entity as EcsEntity};
|
2020-07-06 05:56:02 +00:00
|
|
|
use specs_idvs::IdvStorage;
|
2021-01-31 20:29:50 +00:00
|
|
|
use std::collections::VecDeque;
|
2019-07-29 19:54:58 +00:00
|
|
|
use vek::*;
|
2021-01-31 20:29:50 +00:00
|
|
|
|
2021-04-07 20:11:29 +00:00
|
|
|
use super::dialogue::Subject;
|
2021-03-29 14:47:42 +00:00
|
|
|
|
2021-01-31 20:29:50 +00:00
|
|
|
pub const DEFAULT_INTERACTION_TIME: f32 = 3.0;
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
pub const TRADE_INTERACTION_TIME: f32 = 300.0;
|
2021-01-31 20:29:50 +00:00
|
|
|
|
2020-04-26 17:03:19 +00:00
|
|
|
#[derive(Copy, Clone, Debug, PartialEq)]
|
2020-01-24 21:24:57 +00:00
|
|
|
pub enum Alignment {
|
2020-05-26 02:45:13 +00:00
|
|
|
/// Wild animals and gentle giants
|
2020-01-24 21:24:57 +00:00
|
|
|
Wild,
|
2020-05-26 02:45:13 +00:00
|
|
|
/// Dungeon cultists and bandits
|
2020-01-24 21:24:57 +00:00
|
|
|
Enemy,
|
2020-05-26 02:45:13 +00:00
|
|
|
/// Friendly folk in villages
|
2020-01-24 21:24:57 +00:00
|
|
|
Npc,
|
2020-05-26 02:45:13 +00:00
|
|
|
/// Farm animals and pets of villagers
|
|
|
|
Tame,
|
|
|
|
/// Pets you've tamed with a collar
|
2020-07-07 00:01:39 +00:00
|
|
|
Owned(Uid),
|
2020-08-13 19:22:47 +00:00
|
|
|
/// Passive objects like training dummies
|
|
|
|
Passive,
|
2019-04-16 21:06:33 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 21:24:57 +00:00
|
|
|
impl Alignment {
|
2020-01-27 15:51:07 +00:00
|
|
|
// Always attacks
|
2020-01-24 21:24:57 +00:00
|
|
|
pub fn hostile_towards(self, other: Alignment) -> bool {
|
|
|
|
match (self, other) {
|
2020-01-27 15:51:07 +00:00
|
|
|
(Alignment::Enemy, Alignment::Enemy) => false,
|
2020-08-13 19:22:47 +00:00
|
|
|
(Alignment::Enemy, Alignment::Wild) => false,
|
|
|
|
(Alignment::Wild, Alignment::Enemy) => false,
|
|
|
|
(Alignment::Wild, Alignment::Wild) => false,
|
2020-08-14 21:55:03 +00:00
|
|
|
(Alignment::Npc, Alignment::Wild) => false,
|
|
|
|
(Alignment::Npc, Alignment::Enemy) => true,
|
2020-01-27 15:51:07 +00:00
|
|
|
(_, Alignment::Enemy) => true,
|
2020-08-13 19:22:47 +00:00
|
|
|
(Alignment::Enemy, _) => true,
|
2020-01-27 15:51:07 +00:00
|
|
|
_ => false,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
// Never attacks
|
|
|
|
pub fn passive_towards(self, other: Alignment) -> bool {
|
|
|
|
match (self, other) {
|
2020-04-19 11:50:25 +00:00
|
|
|
(Alignment::Enemy, Alignment::Enemy) => true,
|
2020-01-27 15:51:07 +00:00
|
|
|
(Alignment::Owned(a), Alignment::Owned(b)) if a == b => true,
|
2020-05-26 02:45:13 +00:00
|
|
|
(Alignment::Npc, Alignment::Npc) => true,
|
|
|
|
(Alignment::Npc, Alignment::Tame) => true,
|
2020-08-13 19:22:47 +00:00
|
|
|
(Alignment::Enemy, Alignment::Wild) => true,
|
|
|
|
(Alignment::Wild, Alignment::Enemy) => true,
|
2020-05-26 02:45:13 +00:00
|
|
|
(Alignment::Tame, Alignment::Npc) => true,
|
|
|
|
(Alignment::Tame, Alignment::Tame) => true,
|
2020-08-13 19:22:47 +00:00
|
|
|
(_, Alignment::Passive) => true,
|
2020-01-27 15:51:07 +00:00
|
|
|
_ => false,
|
2019-08-02 18:56:37 +00:00
|
|
|
}
|
|
|
|
}
|
2020-07-06 20:18:30 +00:00
|
|
|
|
|
|
|
// TODO: Remove this hack
|
|
|
|
pub fn is_friendly_to_players(&self) -> bool {
|
2020-08-17 09:08:11 +00:00
|
|
|
matches!(self, Alignment::Npc | Alignment::Tame | Alignment::Owned(_))
|
2020-07-06 20:18:30 +00:00
|
|
|
}
|
2020-01-24 21:24:57 +00:00
|
|
|
}
|
2020-01-22 03:12:17 +00:00
|
|
|
|
2020-01-24 21:24:57 +00:00
|
|
|
impl Component for Alignment {
|
2020-04-26 17:03:19 +00:00
|
|
|
type Storage = IdvStorage<Self>;
|
2020-01-24 21:24:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-07 20:11:29 +00:00
|
|
|
bitflags::bitflags! {
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct BehaviorCapability: u8 {
|
|
|
|
const SPEAK = 0b00000001;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
bitflags::bitflags! {
|
|
|
|
#[derive(Default)]
|
|
|
|
pub struct BehaviorState: u8 {
|
|
|
|
const TRADING = 0b00000001;
|
|
|
|
const TRADING_ISSUER = 0b00000010;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/// # Behavior Component
|
|
|
|
/// This component allow an Entity to register one or more behavior tags.
|
|
|
|
/// These tags act as flags of what an Entity can do, or what it is doing.
|
|
|
|
/// Behaviors Tags can be added and removed as the Entity lives, to update its
|
|
|
|
/// state when needed
|
|
|
|
#[derive(Default, Copy, Clone, Debug)]
|
|
|
|
pub struct Behavior {
|
|
|
|
capabilities: BehaviorCapability,
|
|
|
|
state: BehaviorState,
|
|
|
|
pub trade_site: Option<SiteId>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl From<BehaviorCapability> for Behavior {
|
|
|
|
fn from(capabilities: BehaviorCapability) -> Self {
|
|
|
|
Behavior {
|
|
|
|
capabilities,
|
|
|
|
state: BehaviorState::default(),
|
|
|
|
trade_site: None,
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Behavior {
|
2021-04-08 16:33:00 +00:00
|
|
|
/// Builder function
|
|
|
|
/// Set capabilities if Option is Some
|
|
|
|
pub fn maybe_with_capabilities(
|
|
|
|
mut self,
|
|
|
|
maybe_capabilities: Option<BehaviorCapability>,
|
|
|
|
) -> Self {
|
|
|
|
if let Some(capabilities) = maybe_capabilities {
|
|
|
|
self.allow(capabilities)
|
|
|
|
}
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Builder function
|
2021-04-08 17:06:57 +00:00
|
|
|
/// Set trade_site if Option is Some
|
2021-04-08 16:33:00 +00:00
|
|
|
pub fn with_trade_site(mut self, trade_site: Option<SiteId>) -> Self {
|
|
|
|
self.trade_site = trade_site;
|
|
|
|
self
|
|
|
|
}
|
|
|
|
|
2021-04-07 20:11:29 +00:00
|
|
|
/// Set capabilities to the Behavior
|
|
|
|
pub fn allow(&mut self, capabilities: BehaviorCapability) {
|
|
|
|
self.capabilities.set(capabilities, true)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Unset capabilities to the Behavior
|
|
|
|
pub fn deny(&mut self, capabilities: BehaviorCapability) {
|
|
|
|
self.capabilities.set(capabilities, false)
|
|
|
|
}
|
|
|
|
|
|
|
|
/// Check if the Behavior is able to do something
|
|
|
|
pub fn can(&self, capabilities: BehaviorCapability) -> bool {
|
|
|
|
self.capabilities.contains(capabilities)
|
|
|
|
}
|
|
|
|
|
2021-04-08 17:06:57 +00:00
|
|
|
/// Check if the Behavior is able to trade
|
|
|
|
pub fn can_trade(&self) -> bool { self.trade_site.is_some() }
|
|
|
|
|
2021-04-07 20:11:29 +00:00
|
|
|
/// Set a state to the Behavior
|
|
|
|
pub fn set(&mut self, state: BehaviorState) { self.state.set(state, true) }
|
|
|
|
|
|
|
|
/// Unset a state to the Behavior
|
|
|
|
pub fn unset(&mut self, state: BehaviorState) { self.state.set(state, false) }
|
|
|
|
|
|
|
|
/// Check if the Behavior has a specific state
|
|
|
|
pub fn is(&self, state: BehaviorState) -> bool { self.state.contains(state) }
|
|
|
|
}
|
|
|
|
|
2020-07-29 19:58:14 +00:00
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
pub struct Psyche {
|
2020-08-13 19:22:47 +00:00
|
|
|
pub aggro: f32, // 0.0 = always flees, 1.0 = always attacks, 0.5 = flee at 50% health
|
2020-07-29 19:58:14 +00:00
|
|
|
}
|
2020-11-12 21:31:28 +00:00
|
|
|
|
2020-07-29 19:58:14 +00:00
|
|
|
impl<'a> From<&'a Body> for Psyche {
|
|
|
|
fn from(body: &'a Body) -> Self {
|
|
|
|
Self {
|
|
|
|
aggro: match body {
|
2020-08-13 19:22:47 +00:00
|
|
|
Body::Humanoid(humanoid) => match humanoid.species {
|
|
|
|
humanoid::Species::Danari => 0.9,
|
2020-11-22 08:09:43 +00:00
|
|
|
humanoid::Species::Dwarf => 0.8,
|
|
|
|
humanoid::Species::Elf => 0.7,
|
|
|
|
humanoid::Species::Human => 0.6,
|
|
|
|
humanoid::Species::Orc => 0.9,
|
|
|
|
humanoid::Species::Undead => 0.9,
|
2020-08-13 19:22:47 +00:00
|
|
|
},
|
|
|
|
Body::QuadrupedSmall(quadruped_small) => match quadruped_small.species {
|
2020-08-14 01:22:25 +00:00
|
|
|
quadruped_small::Species::Pig => 0.5,
|
2020-11-22 08:09:43 +00:00
|
|
|
quadruped_small::Species::Fox => 0.3,
|
2020-08-14 01:22:25 +00:00
|
|
|
quadruped_small::Species::Sheep => 0.5,
|
2020-11-22 08:09:43 +00:00
|
|
|
quadruped_small::Species::Boar => 0.8,
|
2020-08-13 19:22:47 +00:00
|
|
|
quadruped_small::Species::Jackalope => 0.4,
|
2020-11-22 08:09:43 +00:00
|
|
|
quadruped_small::Species::Skunk => 0.6,
|
2020-08-13 19:22:47 +00:00
|
|
|
quadruped_small::Species::Cat => 0.2,
|
2020-11-22 08:09:43 +00:00
|
|
|
quadruped_small::Species::Batfox => 0.6,
|
2020-08-13 19:22:47 +00:00
|
|
|
quadruped_small::Species::Raccoon => 0.4,
|
2020-11-22 08:09:43 +00:00
|
|
|
quadruped_small::Species::Quokka => 0.4,
|
2020-08-13 19:22:47 +00:00
|
|
|
quadruped_small::Species::Dodarock => 0.9,
|
|
|
|
quadruped_small::Species::Holladon => 1.0,
|
|
|
|
quadruped_small::Species::Hyena => 0.4,
|
|
|
|
quadruped_small::Species::Rabbit => 0.1,
|
|
|
|
quadruped_small::Species::Truffler => 0.8,
|
2020-11-22 08:09:43 +00:00
|
|
|
quadruped_small::Species::Frog => 0.4,
|
2020-11-17 00:13:59 +00:00
|
|
|
quadruped_small::Species::Hare => 0.2,
|
2021-03-12 00:20:05 +00:00
|
|
|
quadruped_small::Species::Goat => 0.5,
|
2020-11-22 08:09:43 +00:00
|
|
|
_ => 0.0,
|
2020-08-13 19:22:47 +00:00
|
|
|
},
|
|
|
|
Body::QuadrupedMedium(quadruped_medium) => match quadruped_medium.species {
|
2020-11-22 08:09:43 +00:00
|
|
|
quadruped_medium::Species::Tuskram => 0.7,
|
2020-08-13 19:22:47 +00:00
|
|
|
quadruped_medium::Species::Frostfang => 0.9,
|
2020-11-22 08:09:43 +00:00
|
|
|
quadruped_medium::Species::Mouflon => 0.7,
|
2020-08-13 19:22:47 +00:00
|
|
|
quadruped_medium::Species::Catoblepas => 0.8,
|
2020-09-20 15:58:54 +00:00
|
|
|
quadruped_medium::Species::Deer => 0.6,
|
|
|
|
quadruped_medium::Species::Hirdrasil => 0.7,
|
2020-11-17 21:54:12 +00:00
|
|
|
quadruped_medium::Species::Donkey => 0.7,
|
|
|
|
quadruped_medium::Species::Camel => 0.7,
|
|
|
|
quadruped_medium::Species::Zebra => 0.7,
|
|
|
|
quadruped_medium::Species::Antelope => 0.6,
|
2020-11-22 08:09:43 +00:00
|
|
|
quadruped_medium::Species::Horse => 0.7,
|
2021-01-12 22:35:59 +00:00
|
|
|
quadruped_medium::Species::Cattle => 0.7,
|
|
|
|
quadruped_medium::Species::Darkhound => 0.9,
|
2021-03-12 00:20:05 +00:00
|
|
|
quadruped_medium::Species::Dreadhorn => 0.8,
|
|
|
|
quadruped_medium::Species::Snowleopard => 0.7,
|
2020-11-22 08:09:43 +00:00
|
|
|
_ => 0.5,
|
2020-08-13 19:22:47 +00:00
|
|
|
},
|
|
|
|
Body::QuadrupedLow(quadruped_low) => match quadruped_low.species {
|
2020-11-22 08:09:43 +00:00
|
|
|
quadruped_low::Species::Salamander => 0.7,
|
|
|
|
quadruped_low::Species::Monitor => 0.7,
|
2020-08-13 19:22:47 +00:00
|
|
|
quadruped_low::Species::Asp => 0.9,
|
2020-11-22 08:09:43 +00:00
|
|
|
quadruped_low::Species::Pangolin => 0.4,
|
|
|
|
_ => 0.6,
|
2020-08-13 19:22:47 +00:00
|
|
|
},
|
2020-12-23 06:24:44 +00:00
|
|
|
Body::BipedSmall(_) => 0.5,
|
2020-11-22 08:09:43 +00:00
|
|
|
Body::BirdMedium(_) => 0.5,
|
2021-04-20 22:36:40 +00:00
|
|
|
Body::BirdLarge(_) => 0.9,
|
2020-07-29 19:58:14 +00:00
|
|
|
Body::FishMedium(_) => 0.15,
|
|
|
|
Body::FishSmall(_) => 0.0,
|
|
|
|
Body::BipedLarge(_) => 1.0,
|
2020-08-13 19:22:47 +00:00
|
|
|
Body::Object(_) => 1.0,
|
2020-07-29 19:58:14 +00:00
|
|
|
Body::Golem(_) => 1.0,
|
2020-09-18 02:58:02 +00:00
|
|
|
Body::Theropod(_) => 1.0,
|
2020-07-29 19:58:14 +00:00
|
|
|
Body::Dragon(_) => 1.0,
|
2021-03-11 16:48:59 +00:00
|
|
|
Body::Ship(_) => 1.0,
|
2020-07-29 19:58:14 +00:00
|
|
|
},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-01-31 20:29:50 +00:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
/// Events that affect agent behavior from other entities/players/environment
|
|
|
|
pub enum AgentEvent {
|
|
|
|
/// Engage in conversation with entity with Uid
|
2021-03-29 14:47:42 +00:00
|
|
|
Talk(Uid, Subject),
|
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
|
|
|
TradeInvite(Uid),
|
2021-03-29 14:47:42 +00:00
|
|
|
TradeAccepted(Uid),
|
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
|
|
|
FinishedTrade(TradeResult),
|
|
|
|
UpdatePendingTrade(
|
|
|
|
// this data structure is large so box it to keep AgentEvent small
|
|
|
|
Box<(
|
|
|
|
TradeId,
|
|
|
|
PendingTrade,
|
|
|
|
SitePrices,
|
|
|
|
[Option<ReducedInventory>; 2],
|
|
|
|
)>,
|
|
|
|
),
|
2021-01-31 20:29:50 +00:00
|
|
|
// Add others here
|
|
|
|
}
|
|
|
|
|
2021-02-10 20:57:47 +00:00
|
|
|
#[derive(Clone, Debug)]
|
|
|
|
pub struct Target {
|
|
|
|
pub target: EcsEntity,
|
|
|
|
pub hostile: bool,
|
2021-03-24 03:00:05 +00:00
|
|
|
pub selected_at: f64,
|
2021-02-10 20:57:47 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 21:24:57 +00:00
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
pub struct Agent {
|
2020-11-12 21:31:28 +00:00
|
|
|
pub rtsim_controller: RtSimController,
|
2020-01-24 21:24:57 +00:00
|
|
|
pub patrol_origin: Option<Vec3<f32>>,
|
2021-02-10 20:57:47 +00:00
|
|
|
pub target: Option<Target>,
|
2021-02-23 02:16:07 +00:00
|
|
|
pub chaser: Chaser,
|
2021-04-07 19:37:48 +00:00
|
|
|
pub behavior: Behavior,
|
2020-07-29 19:58:14 +00:00
|
|
|
pub psyche: Psyche,
|
2021-01-31 20:29:50 +00:00
|
|
|
pub inbox: VecDeque<AgentEvent>,
|
2021-04-28 01:17:56 +00:00
|
|
|
pub action_state: ActionState,
|
2021-02-10 20:57:47 +00:00
|
|
|
pub bearing: Vec2<f32>,
|
2020-01-24 21:24:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-28 01:17:56 +00:00
|
|
|
#[derive(Clone, Debug, Default)]
|
|
|
|
pub struct ActionState {
|
2021-04-28 22:41:04 +00:00
|
|
|
pub timer: f32,
|
|
|
|
pub counter: f32,
|
|
|
|
pub condition: bool,
|
2021-04-28 01:17:56 +00:00
|
|
|
}
|
|
|
|
|
2020-01-24 21:24:57 +00:00
|
|
|
impl Agent {
|
2021-04-08 16:33:00 +00:00
|
|
|
pub fn with_patrol_origin(mut self, origin: Vec3<f32>) -> Self {
|
2020-01-25 02:15:15 +00:00
|
|
|
self.patrol_origin = Some(origin);
|
|
|
|
self
|
|
|
|
}
|
2020-05-26 02:45:13 +00:00
|
|
|
|
2021-04-08 16:33:00 +00:00
|
|
|
pub fn with_destination(mut self, pos: Vec3<f32>) -> Self {
|
|
|
|
self.psyche = Psyche { aggro: 1.0 };
|
|
|
|
self.rtsim_controller = RtSimController::with_destination(pos);
|
|
|
|
self.behavior.allow(BehaviorCapability::SPEAK);
|
|
|
|
self
|
2021-03-12 02:58:57 +00:00
|
|
|
}
|
|
|
|
|
2021-04-07 19:37:48 +00:00
|
|
|
pub fn new(
|
|
|
|
patrol_origin: Option<Vec3<f32>>,
|
|
|
|
body: &Body,
|
|
|
|
behavior: Behavior,
|
|
|
|
no_flee: bool,
|
|
|
|
) -> Self {
|
2020-05-26 02:45:13 +00:00
|
|
|
Agent {
|
|
|
|
patrol_origin,
|
2020-11-25 20:19:11 +00:00
|
|
|
psyche: if no_flee {
|
|
|
|
Psyche { aggro: 1.0 }
|
|
|
|
} else {
|
|
|
|
Psyche::from(body)
|
|
|
|
},
|
2021-04-07 19:37:48 +00:00
|
|
|
behavior,
|
2020-05-26 02:45:13 +00:00
|
|
|
..Default::default()
|
|
|
|
}
|
|
|
|
}
|
2019-08-02 18:56:37 +00:00
|
|
|
}
|
|
|
|
|
2019-04-16 21:06:33 +00:00
|
|
|
impl Component for Agent {
|
2020-07-06 05:56:02 +00:00
|
|
|
type Storage = IdvStorage<Self>;
|
2019-04-16 21:06:33 +00:00
|
|
|
}
|
2021-04-07 20:11:29 +00:00
|
|
|
|
|
|
|
#[cfg(test)]
|
|
|
|
mod tests {
|
|
|
|
use super::{Behavior, BehaviorCapability, BehaviorState};
|
|
|
|
|
|
|
|
/// Test to verify that Behavior is working correctly at its most basic
|
|
|
|
/// usages
|
|
|
|
#[test]
|
|
|
|
pub fn behavior_basic() {
|
|
|
|
let mut b = Behavior::default();
|
|
|
|
// test capabilities
|
|
|
|
assert!(!b.can(BehaviorCapability::SPEAK));
|
|
|
|
b.allow(BehaviorCapability::SPEAK);
|
|
|
|
assert!(b.can(BehaviorCapability::SPEAK));
|
|
|
|
b.deny(BehaviorCapability::SPEAK);
|
|
|
|
assert!(!b.can(BehaviorCapability::SPEAK));
|
|
|
|
// test states
|
|
|
|
assert!(!b.is(BehaviorState::TRADING));
|
|
|
|
b.set(BehaviorState::TRADING);
|
|
|
|
assert!(b.is(BehaviorState::TRADING));
|
|
|
|
b.unset(BehaviorState::TRADING);
|
|
|
|
assert!(!b.is(BehaviorState::TRADING));
|
|
|
|
// test `from`
|
2021-04-08 17:06:57 +00:00
|
|
|
let b = Behavior::from(BehaviorCapability::SPEAK);
|
2021-04-07 20:11:29 +00:00
|
|
|
assert!(b.can(BehaviorCapability::SPEAK));
|
|
|
|
}
|
|
|
|
}
|