2021-03-16 01:30:35 +00:00
|
|
|
use crate::rtsim::{Entity as RtSimData, RtSim};
|
2020-12-01 00:28:00 +00:00
|
|
|
use common::{
|
2020-04-18 18:28:19 +00:00
|
|
|
comp::{
|
|
|
|
self,
|
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
|
|
|
agent::{AgentEvent, Tactic, Target, DEFAULT_INTERACTION_TIME, TRADE_INTERACTION_TIME},
|
2021-03-16 19:17:08 +00:00
|
|
|
buff::{BuffKind, Buffs},
|
2021-03-29 14:47:42 +00:00
|
|
|
compass::{Direction, Distance},
|
|
|
|
dialogue::{MoodContext, MoodState, Subject},
|
2020-04-26 17:03:19 +00:00
|
|
|
group,
|
2021-03-30 22:37:38 +00:00
|
|
|
inventory::{item::ItemTag, slot::EquipSlot},
|
2021-03-29 14:47:42 +00:00
|
|
|
invite::{InviteKind, InviteResponse},
|
2020-11-06 17:39:49 +00:00
|
|
|
item::{
|
2021-04-30 19:25:08 +00:00
|
|
|
tool::{AbilitySpec, ToolKind},
|
2021-04-11 23:47:29 +00:00
|
|
|
Item, ItemDesc, ItemKind,
|
2020-11-06 17:39:49 +00:00
|
|
|
},
|
2021-01-08 20:53:52 +00:00
|
|
|
skills::{AxeSkill, BowSkill, HammerSkill, Skill, StaffSkill, SwordSkill},
|
2021-04-19 19:13:43 +00:00
|
|
|
Agent, Alignment, BehaviorCapability, BehaviorState, Body, CharacterAbility,
|
|
|
|
CharacterState, ControlAction, ControlEvent, Controller, Energy, Health, HealthChange,
|
|
|
|
InputKind, Inventory, InventoryAction, LightEmitter, MountState, Ori, PhysicsState, Pos,
|
|
|
|
Scale, SkillSet, Stats, UnresolvedChatMsg, Vel,
|
2020-04-18 18:28:19 +00:00
|
|
|
},
|
2021-03-23 09:51:53 +00:00
|
|
|
consts::GRAVITY,
|
2021-04-11 23:47:29 +00:00
|
|
|
effect::{BuffEffect, Effect},
|
2021-02-07 07:22:06 +00:00
|
|
|
event::{Emitter, EventBus, ServerEvent},
|
|
|
|
path::TraversalConfig,
|
2021-03-16 01:30:35 +00:00
|
|
|
resources::{DeltaTime, Time, TimeOfDay},
|
|
|
|
rtsim::{Memory, MemoryItem, RtSimEntity, RtSimEvent},
|
2021-03-29 14:44:46 +00:00
|
|
|
states::utils::StageSection,
|
2020-09-26 13:55:01 +00:00
|
|
|
terrain::{Block, TerrainGrid},
|
2020-10-07 02:23:20 +00:00
|
|
|
time::DayPeriod,
|
2021-03-25 04:35:33 +00:00
|
|
|
trade::{TradeAction, TradePhase, TradeResult},
|
2020-12-13 17:40:15 +00:00
|
|
|
uid::{Uid, UidAllocator},
|
2020-03-28 01:31:22 +00:00
|
|
|
util::Dir,
|
2020-01-27 10:02:36 +00:00
|
|
|
vol::ReadVol,
|
2020-01-24 21:24:57 +00:00
|
|
|
};
|
2021-03-13 06:48:30 +00:00
|
|
|
use common_base::prof_span;
|
2021-03-09 10:52:57 +00:00
|
|
|
use common_ecs::{Job, Origin, ParMode, Phase, System};
|
2020-01-27 15:51:07 +00:00
|
|
|
use rand::{thread_rng, Rng};
|
2020-11-25 22:47:16 +00:00
|
|
|
use rayon::iter::ParallelIterator;
|
2020-01-24 21:24:57 +00:00
|
|
|
use specs::{
|
|
|
|
saveload::{Marker, MarkerAllocator},
|
2021-02-07 07:22:06 +00:00
|
|
|
shred::ResourceId,
|
2021-03-04 14:00:16 +00:00
|
|
|
Entities, Entity as EcsEntity, Join, ParJoin, Read, ReadExpect, ReadStorage, SystemData, World,
|
2021-03-16 01:30:35 +00:00
|
|
|
Write, WriteExpect, WriteStorage,
|
2020-01-24 21:24:57 +00:00
|
|
|
};
|
2021-03-29 14:44:46 +00:00
|
|
|
use std::{f32::consts::PI, sync::Arc, time::Duration};
|
2019-04-16 21:06:33 +00:00
|
|
|
use vek::*;
|
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
struct AgentData<'a> {
|
|
|
|
entity: &'a EcsEntity,
|
2021-03-16 01:30:35 +00:00
|
|
|
rtsim_entity: Option<&'a RtSimData>,
|
2021-02-07 07:22:06 +00:00
|
|
|
uid: &'a Uid,
|
|
|
|
pos: &'a Pos,
|
|
|
|
vel: &'a Vel,
|
|
|
|
ori: &'a Ori,
|
|
|
|
energy: &'a Energy,
|
|
|
|
body: Option<&'a Body>,
|
|
|
|
inventory: &'a Inventory,
|
2021-04-14 15:35:34 +00:00
|
|
|
skill_set: &'a SkillSet,
|
2021-02-07 07:22:06 +00:00
|
|
|
physics_state: &'a PhysicsState,
|
|
|
|
alignment: Option<&'a Alignment>,
|
|
|
|
traversal_config: TraversalConfig,
|
|
|
|
scale: f32,
|
|
|
|
flees: bool,
|
|
|
|
damage: f32,
|
|
|
|
light_emitter: Option<&'a LightEmitter>,
|
|
|
|
glider_equipped: bool,
|
|
|
|
is_gliding: bool,
|
2021-03-23 15:02:15 +00:00
|
|
|
health: Option<&'a Health>,
|
2021-03-21 18:22:14 +00:00
|
|
|
char_state: &'a CharacterState,
|
2021-04-21 17:10:13 +00:00
|
|
|
cached_spatial_grid: &'a common::CachedSpatialGrid,
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#[derive(SystemData)]
|
|
|
|
pub struct ReadData<'a> {
|
|
|
|
entities: Entities<'a>,
|
|
|
|
uid_allocator: Read<'a, UidAllocator>,
|
|
|
|
dt: Read<'a, DeltaTime>,
|
2021-03-16 01:30:35 +00:00
|
|
|
time: Read<'a, Time>,
|
2021-04-21 17:10:13 +00:00
|
|
|
cached_spatial_grid: Read<'a, common::CachedSpatialGrid>,
|
2021-02-07 07:22:06 +00:00
|
|
|
group_manager: Read<'a, group::GroupManager>,
|
|
|
|
energies: ReadStorage<'a, Energy>,
|
|
|
|
positions: ReadStorage<'a, Pos>,
|
|
|
|
velocities: ReadStorage<'a, Vel>,
|
|
|
|
orientations: ReadStorage<'a, Ori>,
|
|
|
|
scales: ReadStorage<'a, Scale>,
|
|
|
|
healths: ReadStorage<'a, Health>,
|
|
|
|
inventories: ReadStorage<'a, Inventory>,
|
|
|
|
stats: ReadStorage<'a, Stats>,
|
2021-04-14 15:35:34 +00:00
|
|
|
skill_set: ReadStorage<'a, SkillSet>,
|
2021-02-07 07:22:06 +00:00
|
|
|
physics_states: ReadStorage<'a, PhysicsState>,
|
|
|
|
char_states: ReadStorage<'a, CharacterState>,
|
|
|
|
uids: ReadStorage<'a, Uid>,
|
|
|
|
groups: ReadStorage<'a, group::Group>,
|
|
|
|
terrain: ReadExpect<'a, TerrainGrid>,
|
|
|
|
alignments: ReadStorage<'a, Alignment>,
|
|
|
|
bodies: ReadStorage<'a, Body>,
|
|
|
|
mount_states: ReadStorage<'a, MountState>,
|
|
|
|
time_of_day: Read<'a, TimeOfDay>,
|
|
|
|
light_emitter: ReadStorage<'a, LightEmitter>,
|
2021-04-15 18:07:46 +00:00
|
|
|
#[cfg(feature = "worldgen")]
|
2021-03-12 18:53:06 +00:00
|
|
|
world: ReadExpect<'a, Arc<world::World>>,
|
2021-03-16 01:30:35 +00:00
|
|
|
rtsim_entities: ReadStorage<'a, RtSimEntity>,
|
2021-03-16 19:17:08 +00:00
|
|
|
buffs: ReadStorage<'a, Buffs>,
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
|
2021-01-31 20:29:50 +00:00
|
|
|
// This is 3.1 to last longer than the last damage timer (3.0 seconds)
|
2021-03-03 03:55:28 +00:00
|
|
|
const DAMAGE_MEMORY_DURATION: f64 = 0.1;
|
|
|
|
const FLEE_DURATION: f32 = 3.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
const MAX_FOLLOW_DIST: f32 = 12.0;
|
2021-03-06 15:50:04 +00:00
|
|
|
const MAX_CHASE_DIST: f32 = 250.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
const MAX_FLEE_DIST: f32 = 20.0;
|
|
|
|
const LISTEN_DIST: f32 = 16.0;
|
|
|
|
const SEARCH_DIST: f32 = 48.0;
|
|
|
|
const SIGHT_DIST: f32 = 80.0;
|
|
|
|
const SNEAK_COEFFICIENT: f32 = 0.25;
|
|
|
|
const AVG_FOLLOW_DIST: f32 = 6.0;
|
2021-03-24 03:00:05 +00:00
|
|
|
const RETARGETING_THRESHOLD_SECONDS: f64 = 10.0;
|
2021-04-11 23:47:29 +00:00
|
|
|
const HEALING_ITEM_THRESHOLD: f32 = 0.5;
|
2021-01-31 20:29:50 +00:00
|
|
|
|
2019-06-09 19:33:20 +00:00
|
|
|
/// This system will allow NPCs to modify their controller
|
2021-03-04 14:00:16 +00:00
|
|
|
#[derive(Default)]
|
2019-04-16 21:06:33 +00:00
|
|
|
pub struct Sys;
|
2021-03-08 11:13:59 +00:00
|
|
|
impl<'a> System<'a> for Sys {
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::type_complexity)]
|
2019-04-16 21:06:33 +00:00
|
|
|
type SystemData = (
|
2021-02-07 07:22:06 +00:00
|
|
|
ReadData<'a>,
|
2020-06-04 07:11:35 +00:00
|
|
|
Write<'a, EventBus<ServerEvent>>,
|
2019-08-02 20:25:33 +00:00
|
|
|
WriteStorage<'a, Agent>,
|
2019-06-09 14:20:20 +00:00
|
|
|
WriteStorage<'a, Controller>,
|
2021-03-16 01:30:35 +00:00
|
|
|
WriteExpect<'a, RtSim>,
|
2019-04-16 21:06:33 +00:00
|
|
|
);
|
|
|
|
|
2021-03-04 14:00:16 +00:00
|
|
|
const NAME: &'static str = "agent";
|
|
|
|
const ORIGIN: Origin = Origin::Server;
|
|
|
|
const PHASE: Phase = Phase::Create;
|
|
|
|
|
2020-06-10 19:47:36 +00:00
|
|
|
#[allow(clippy::or_fun_call)] // TODO: Pending review in #587
|
2019-08-04 08:21:29 +00:00
|
|
|
fn run(
|
2021-03-09 10:52:57 +00:00
|
|
|
job: &mut Job<Self>,
|
2021-03-16 01:30:35 +00:00
|
|
|
(read_data, event_bus, mut agents, mut controllers, mut rtsim): Self::SystemData,
|
2019-08-04 08:21:29 +00:00
|
|
|
) {
|
2021-03-16 01:30:35 +00:00
|
|
|
let rtsim = &mut *rtsim;
|
2021-03-09 10:52:57 +00:00
|
|
|
job.cpu_stats.measure(ParMode::Rayon);
|
2020-11-25 22:47:16 +00:00
|
|
|
(
|
2021-02-07 07:22:06 +00:00
|
|
|
&read_data.entities,
|
2021-03-22 17:37:15 +00:00
|
|
|
(&read_data.energies, read_data.healths.maybe()),
|
2021-03-29 20:30:09 +00:00
|
|
|
(
|
|
|
|
&read_data.positions,
|
|
|
|
&read_data.velocities,
|
|
|
|
&read_data.orientations,
|
|
|
|
),
|
2021-02-07 07:22:06 +00:00
|
|
|
read_data.bodies.maybe(),
|
|
|
|
&read_data.inventories,
|
2021-04-14 15:35:34 +00:00
|
|
|
&read_data.skill_set,
|
2021-02-07 07:22:06 +00:00
|
|
|
&read_data.physics_states,
|
|
|
|
&read_data.uids,
|
2019-09-09 19:11:40 +00:00
|
|
|
&mut agents,
|
|
|
|
&mut controllers,
|
2021-02-07 07:22:06 +00:00
|
|
|
read_data.light_emitter.maybe(),
|
|
|
|
read_data.groups.maybe(),
|
|
|
|
read_data.mount_states.maybe(),
|
2021-03-21 18:22:14 +00:00
|
|
|
&read_data.char_states,
|
2019-09-09 19:11:40 +00:00
|
|
|
)
|
2020-11-25 22:47:16 +00:00
|
|
|
.par_join()
|
2021-04-07 19:37:48 +00:00
|
|
|
.filter(|(_, _, _, _, _, _, _, _, _, _, _, _, mount_state, _)| {
|
2021-03-29 20:30:09 +00:00
|
|
|
// Skip mounted entities
|
|
|
|
mount_state
|
|
|
|
.map(|ms| *ms == MountState::Unmounted)
|
|
|
|
.unwrap_or(true)
|
|
|
|
})
|
2021-03-13 06:48:30 +00:00
|
|
|
.for_each_init(
|
|
|
|
|| {
|
|
|
|
prof_span!(guard, "agent rayon job");
|
|
|
|
guard
|
|
|
|
},
|
|
|
|
|_guard,
|
|
|
|
(
|
2021-02-07 07:22:06 +00:00
|
|
|
entity,
|
|
|
|
(energy, health),
|
2021-03-29 20:30:09 +00:00
|
|
|
(pos, vel, ori),
|
2021-02-07 07:22:06 +00:00
|
|
|
body,
|
|
|
|
inventory,
|
2021-04-14 15:35:34 +00:00
|
|
|
skill_set,
|
2021-02-07 07:22:06 +00:00
|
|
|
physics_state,
|
|
|
|
uid,
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
light_emitter,
|
|
|
|
groups,
|
|
|
|
_,
|
2021-03-21 18:22:14 +00:00
|
|
|
char_state,
|
2021-02-07 07:22:06 +00:00
|
|
|
)| {
|
|
|
|
//// Hack, replace with better system when groups are more sophisticated
|
|
|
|
//// Override alignment if in a group unless entity is owned already
|
|
|
|
let alignment = if !matches!(
|
|
|
|
&read_data.alignments.get(entity),
|
|
|
|
&Some(Alignment::Owned(_))
|
|
|
|
) {
|
|
|
|
groups
|
|
|
|
.and_then(|g| read_data.group_manager.group_info(*g))
|
|
|
|
.and_then(|info| read_data.uids.get(info.leader))
|
|
|
|
.copied()
|
|
|
|
.map(Alignment::Owned)
|
|
|
|
.or(read_data.alignments.get(entity).copied())
|
|
|
|
} else {
|
|
|
|
read_data.alignments.get(entity).copied()
|
|
|
|
};
|
2019-09-09 19:11:40 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.reset();
|
|
|
|
let mut event_emitter = event_bus.emitter();
|
2021-02-22 00:57:25 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
// Default to looking in orientation direction (can be overridden below)
|
|
|
|
controller.inputs.look_dir = ori.look_dir();
|
2021-02-22 00:57:25 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
let scale = read_data.scales.get(entity).map(|s| s.0).unwrap_or(1.0);
|
2020-01-25 18:49:47 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
let glider_equipped = inventory
|
|
|
|
.equipped(EquipSlot::Glider)
|
|
|
|
.as_ref()
|
|
|
|
.map_or(false, |item| {
|
|
|
|
matches!(item.kind(), comp::item::ItemKind::Glider(_))
|
|
|
|
});
|
|
|
|
let is_gliding = matches!(
|
|
|
|
read_data.char_states.get(entity),
|
2021-04-27 14:41:48 +00:00
|
|
|
Some(CharacterState::GlideWield) | Some(CharacterState::Glide(_))
|
2021-02-07 07:22:06 +00:00
|
|
|
) && !physics_state.on_ground;
|
2020-11-12 21:31:28 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
// This controls how picky NPCs are about their pathfinding. Giants are larger
|
|
|
|
// and so can afford to be less precise when trying to move around
|
|
|
|
// the world (especially since they would otherwise get stuck on
|
|
|
|
// obstacles that smaller entities would not).
|
|
|
|
let node_tolerance = scale * 1.5;
|
|
|
|
let slow_factor = body.map(|b| b.base_accel() / 250.0).unwrap_or(0.0).min(1.0);
|
|
|
|
let traversal_config = TraversalConfig {
|
|
|
|
node_tolerance,
|
|
|
|
slow_factor,
|
|
|
|
on_ground: physics_state.on_ground,
|
2021-03-23 09:51:53 +00:00
|
|
|
in_liquid: physics_state.in_liquid().is_some(),
|
2021-02-07 07:22:06 +00:00
|
|
|
min_tgt_dist: 1.0,
|
|
|
|
can_climb: body.map(|b| b.can_climb()).unwrap_or(false),
|
2021-03-23 09:51:53 +00:00
|
|
|
can_fly: body.map(|b| b.fly_thrust().is_some()).unwrap_or(false),
|
2021-02-07 07:22:06 +00:00
|
|
|
};
|
2020-01-26 12:47:41 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
let flees = alignment
|
|
|
|
.map(|a| !matches!(a, Alignment::Enemy | Alignment::Owned(_)))
|
|
|
|
.unwrap_or(true);
|
2021-03-22 17:37:15 +00:00
|
|
|
let damage = health.map_or(1.0, |h| h.current() as f32 / h.maximum() as f32);
|
2021-03-16 01:30:35 +00:00
|
|
|
let rtsim_entity = read_data
|
|
|
|
.rtsim_entities
|
|
|
|
.get(entity)
|
|
|
|
.and_then(|rtsim_ent| rtsim.get_entity(rtsim_ent.0));
|
2020-11-23 19:27:18 +00:00
|
|
|
|
2021-04-28 02:31:51 +00:00
|
|
|
if traversal_config.can_fly && rtsim_entity.is_some() {
|
|
|
|
// hack (kinda): Never turn off flight for rtsim entities that can fly
|
|
|
|
// at all, since it results in stuttering and falling back to the ground.
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Fly));
|
|
|
|
}
|
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
// Package all this agent's data into a convenient struct
|
|
|
|
let data = AgentData {
|
|
|
|
entity: &entity,
|
2021-03-16 01:30:35 +00:00
|
|
|
rtsim_entity,
|
2021-02-07 07:22:06 +00:00
|
|
|
uid,
|
|
|
|
pos,
|
|
|
|
vel,
|
|
|
|
ori,
|
|
|
|
energy,
|
|
|
|
body,
|
|
|
|
inventory,
|
2021-04-14 15:35:34 +00:00
|
|
|
skill_set,
|
2021-02-07 07:22:06 +00:00
|
|
|
physics_state,
|
|
|
|
alignment: alignment.as_ref(),
|
|
|
|
traversal_config,
|
|
|
|
scale,
|
|
|
|
flees,
|
|
|
|
damage,
|
|
|
|
light_emitter,
|
|
|
|
glider_equipped,
|
|
|
|
is_gliding,
|
2021-03-23 15:02:15 +00:00
|
|
|
health: read_data.healths.get(entity),
|
2021-03-21 18:22:14 +00:00
|
|
|
char_state,
|
2021-04-21 17:10:13 +00:00
|
|
|
cached_spatial_grid: &read_data.cached_spatial_grid,
|
2021-02-07 07:22:06 +00:00
|
|
|
};
|
2021-01-24 04:00:57 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
///////////////////////////////////////////////////////////
|
|
|
|
// Behavior tree
|
|
|
|
///////////////////////////////////////////////////////////
|
2021-03-30 00:25:59 +00:00
|
|
|
// The behavior tree is meant to make decisions for agents
|
|
|
|
// *but should not* mutate any data (only action nodes
|
|
|
|
// should do that). Each path should lead to one (and only
|
|
|
|
// one) action node. This makes bugfinding much easier and
|
|
|
|
// debugging way easier. If you don't think so, try
|
|
|
|
// debugging the agent code before this MR
|
|
|
|
// (https://gitlab.com/veloren/veloren/-/merge_requests/1801).
|
|
|
|
// Each tick should arrive at one (1) action node which
|
|
|
|
// then determines what the agent does. If this makes you
|
|
|
|
// uncomfortable, consider dt the response time of the
|
|
|
|
// NPC. To make the tree easier to read, subtrees can be
|
|
|
|
// created as methods on `AgentData`. Action nodes are
|
|
|
|
// also methods on the `AgentData` struct. Action nodes
|
|
|
|
// are the only parts of this tree that should provide
|
|
|
|
// inputs.
|
2020-01-25 23:39:38 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
// If falling fast and can glide, save yourself!
|
2021-03-30 00:25:59 +00:00
|
|
|
if data.glider_equipped && !data.physics_state.on_ground {
|
|
|
|
// toggle glider when vertical velocity is above some threshold (here ~
|
2021-02-07 07:22:06 +00:00
|
|
|
// glider fall vertical speed)
|
2021-03-30 00:25:59 +00:00
|
|
|
data.glider_fall(agent, controller, &read_data);
|
2021-03-24 03:00:05 +00:00
|
|
|
} else if let Some(Target {
|
2021-03-30 00:25:59 +00:00
|
|
|
target, hostile, ..
|
2021-03-24 03:00:05 +00:00
|
|
|
}) = agent.target
|
|
|
|
{
|
2021-03-03 03:55:28 +00:00
|
|
|
if let Some(tgt_health) = read_data.healths.get(target) {
|
|
|
|
// If the target is hostile (either based on alignment or if
|
|
|
|
// the target just attacked
|
|
|
|
if !tgt_health.is_dead {
|
|
|
|
if hostile {
|
|
|
|
data.hostile_tree(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data,
|
|
|
|
&mut event_emitter,
|
|
|
|
);
|
|
|
|
// Target is something worth following methinks
|
|
|
|
} else if let Some(Alignment::Owned(_)) = data.alignment {
|
|
|
|
if let Some(tgt_pos) = read_data.positions.get(target) {
|
|
|
|
let dist_sqrd = pos.0.distance_squared(tgt_pos.0);
|
|
|
|
// If really far away drop everything and follow
|
|
|
|
if dist_sqrd > (2.0 * MAX_FOLLOW_DIST).powi(2) {
|
|
|
|
agent.bearing = Vec2::zero();
|
|
|
|
data.follow(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data.terrain,
|
|
|
|
tgt_pos,
|
|
|
|
);
|
|
|
|
// Attack target's attacker
|
|
|
|
} else if tgt_health.last_change.0 < 5.0
|
|
|
|
&& tgt_health.last_change.1.amount < 0
|
2021-02-07 07:22:06 +00:00
|
|
|
{
|
2021-03-03 03:55:28 +00:00
|
|
|
if let comp::HealthSource::Damage {
|
|
|
|
by: Some(by), ..
|
|
|
|
} = tgt_health.last_change.1.cause
|
|
|
|
{
|
|
|
|
if let Some(attacker) = read_data
|
|
|
|
.uid_allocator
|
|
|
|
.retrieve_entity_internal(by.id())
|
2021-02-07 07:22:06 +00:00
|
|
|
{
|
|
|
|
agent.target = Some(Target {
|
2021-03-03 03:55:28 +00:00
|
|
|
target: attacker,
|
|
|
|
hostile: true,
|
2021-03-24 03:00:05 +00:00
|
|
|
selected_at: read_data.time.0,
|
2021-02-07 07:22:06 +00:00
|
|
|
});
|
2021-03-16 19:17:08 +00:00
|
|
|
if let Some(tgt_pos) =
|
|
|
|
read_data.positions.get(attacker)
|
|
|
|
{
|
|
|
|
if should_stop_attacking(
|
|
|
|
read_data.healths.get(attacker),
|
|
|
|
read_data.buffs.get(attacker),
|
|
|
|
) {
|
2021-03-03 03:55:28 +00:00
|
|
|
agent.target = Some(Target {
|
|
|
|
target,
|
|
|
|
hostile: false,
|
2021-03-24 03:00:05 +00:00
|
|
|
selected_at: read_data.time.0,
|
2021-03-03 03:55:28 +00:00
|
|
|
});
|
|
|
|
data.idle(
|
|
|
|
agent, controller, &read_data,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
data.attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data.terrain,
|
|
|
|
tgt_pos,
|
|
|
|
read_data.bodies.get(attacker),
|
|
|
|
&read_data.dt,
|
2021-03-21 03:28:13 +00:00
|
|
|
&read_data,
|
2021-03-03 03:55:28 +00:00
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2021-01-31 20:29:50 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-03 03:55:28 +00:00
|
|
|
// Follow owner if too far away and not
|
|
|
|
// fighting
|
|
|
|
} else if dist_sqrd > MAX_FOLLOW_DIST.powi(2) {
|
|
|
|
data.follow(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data.terrain,
|
|
|
|
tgt_pos,
|
|
|
|
);
|
|
|
|
|
|
|
|
// Otherwise just idle
|
|
|
|
} else {
|
|
|
|
data.idle_tree(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data,
|
|
|
|
&mut event_emitter,
|
|
|
|
);
|
2021-01-31 20:29:50 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2021-02-07 07:22:06 +00:00
|
|
|
data.idle_tree(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data,
|
|
|
|
&mut event_emitter,
|
|
|
|
);
|
2021-01-31 20:29:50 +00:00
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-03-03 03:55:28 +00:00
|
|
|
agent.target = None;
|
2021-02-07 07:22:06 +00:00
|
|
|
data.idle_tree(agent, controller, &read_data, &mut event_emitter);
|
|
|
|
}
|
|
|
|
} else {
|
2021-03-03 03:55:28 +00:00
|
|
|
agent.target = None;
|
2021-02-07 07:22:06 +00:00
|
|
|
data.idle_tree(agent, controller, &read_data, &mut event_emitter);
|
|
|
|
}
|
|
|
|
} else {
|
2021-03-22 17:37:15 +00:00
|
|
|
// Target an entity that's attacking us if the attack was recent and we
|
|
|
|
// have a health component
|
|
|
|
match health {
|
|
|
|
Some(health) if health.last_change.0 < DAMAGE_MEMORY_DURATION => {
|
|
|
|
if let comp::HealthSource::Damage { by: Some(by), .. } =
|
|
|
|
health.last_change.1.cause
|
2021-02-07 07:22:06 +00:00
|
|
|
{
|
2021-03-22 17:37:15 +00:00
|
|
|
if let Some(attacker) =
|
|
|
|
read_data.uid_allocator.retrieve_entity_internal(by.id())
|
|
|
|
{
|
|
|
|
if let Some(tgt_pos) = read_data.positions.get(attacker) {
|
|
|
|
// If the target is dead or in a safezone, remove the
|
|
|
|
// target
|
|
|
|
// and idle.
|
|
|
|
if should_stop_attacking(
|
|
|
|
read_data.healths.get(attacker),
|
|
|
|
read_data.buffs.get(attacker),
|
|
|
|
) {
|
|
|
|
agent.target = None;
|
|
|
|
data.idle_tree(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data,
|
|
|
|
&mut event_emitter,
|
|
|
|
);
|
|
|
|
} else {
|
|
|
|
agent.target = Some(Target {
|
|
|
|
target: attacker,
|
|
|
|
hostile: true,
|
2021-03-24 03:00:05 +00:00
|
|
|
selected_at: read_data.time.0,
|
2021-03-22 17:37:15 +00:00
|
|
|
});
|
|
|
|
data.attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data.terrain,
|
|
|
|
tgt_pos,
|
|
|
|
read_data.bodies.get(attacker),
|
|
|
|
&read_data.dt,
|
2021-03-21 03:28:13 +00:00
|
|
|
&read_data,
|
2021-03-22 17:37:15 +00:00
|
|
|
);
|
|
|
|
// Remember this encounter if an RtSim entity
|
|
|
|
if let Some(tgt_stats) =
|
|
|
|
read_data.stats.get(attacker)
|
|
|
|
{
|
|
|
|
if data.rtsim_entity.is_some() {
|
|
|
|
agent.rtsim_controller.events.push(
|
|
|
|
RtSimEvent::AddMemory(Memory {
|
|
|
|
item: MemoryItem::CharacterFight {
|
|
|
|
name: tgt_stats.name.clone(),
|
|
|
|
},
|
|
|
|
time_to_forget: read_data.time.0
|
|
|
|
+ 300.0,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2021-03-03 03:55:28 +00:00
|
|
|
agent.target = None;
|
|
|
|
data.idle_tree(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data,
|
|
|
|
&mut event_emitter,
|
|
|
|
);
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
2021-03-22 17:37:15 +00:00
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
data.idle_tree(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data,
|
|
|
|
&mut event_emitter,
|
|
|
|
);
|
2020-01-26 12:47:41 +00:00
|
|
|
}
|
2021-03-22 17:37:15 +00:00
|
|
|
},
|
|
|
|
_ => {
|
2021-02-07 07:22:06 +00:00
|
|
|
data.idle_tree(agent, controller, &read_data, &mut event_emitter);
|
2021-03-22 17:37:15 +00:00
|
|
|
},
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-11 04:36:40 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
debug_assert!(controller.inputs.move_dir.map(|e| !e.is_nan()).reduce_and());
|
|
|
|
debug_assert!(controller.inputs.look_dir.map(|e| !e.is_nan()).reduce_and());
|
|
|
|
},
|
|
|
|
);
|
2021-03-16 01:30:35 +00:00
|
|
|
for (agent, rtsim_entity) in (&mut agents, &read_data.rtsim_entities).join() {
|
|
|
|
// Entity must be loaded in as it has an agent component :)
|
|
|
|
// React to all events in the controller
|
|
|
|
for event in core::mem::take(&mut agent.rtsim_controller.events) {
|
2021-03-29 14:47:42 +00:00
|
|
|
match event {
|
|
|
|
RtSimEvent::AddMemory(memory) => {
|
|
|
|
rtsim.insert_entity_memory(rtsim_entity.0, memory.clone())
|
|
|
|
},
|
|
|
|
RtSimEvent::SetMood(memory) => {
|
|
|
|
rtsim.set_entity_mood(rtsim_entity.0, memory.clone())
|
|
|
|
},
|
|
|
|
_ => {},
|
2021-03-16 01:30:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
2020-03-17 17:27:52 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
impl<'a> AgentData<'a> {
|
2021-03-30 00:25:59 +00:00
|
|
|
////////////////////////////////////////
|
|
|
|
// Subtrees
|
|
|
|
////////////////////////////////////////
|
2021-02-07 07:22:06 +00:00
|
|
|
fn idle_tree(
|
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
read_data: &ReadData,
|
|
|
|
event_emitter: &mut Emitter<'_, ServerEvent>,
|
|
|
|
) {
|
2021-03-03 03:55:28 +00:00
|
|
|
// Set owner if no target
|
|
|
|
if agent.target.is_none() && thread_rng().gen_bool(0.1) {
|
|
|
|
if let Some(Alignment::Owned(owner)) = self.alignment {
|
|
|
|
if let Some(owner) = read_data.uid_allocator.retrieve_entity_internal(owner.id()) {
|
|
|
|
agent.target = Some(Target {
|
|
|
|
target: owner,
|
|
|
|
hostile: false,
|
2021-03-24 03:00:05 +00:00
|
|
|
selected_at: read_data.time.0,
|
2021-03-03 03:55:28 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
// Interact if incoming messages
|
|
|
|
if !agent.inbox.is_empty() {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.1;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer > 0.0 {
|
|
|
|
if agent.action_state.action_timer
|
2021-04-07 19:37:48 +00:00
|
|
|
< (if agent.behavior.is(BehaviorState::TRADING) {
|
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_INTERACTION_TIME
|
|
|
|
} else {
|
|
|
|
DEFAULT_INTERACTION_TIME
|
|
|
|
})
|
|
|
|
{
|
2021-03-03 03:55:28 +00:00
|
|
|
self.interact(agent, controller, &read_data, event_emitter);
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
agent.target = None;
|
2021-03-03 03:55:28 +00:00
|
|
|
controller.actions.push(ControlAction::Stand);
|
2021-02-07 07:22:06 +00:00
|
|
|
self.idle(agent, controller, &read_data);
|
|
|
|
}
|
|
|
|
} else if thread_rng().gen::<f32>() < 0.1 {
|
2021-03-16 01:30:35 +00:00
|
|
|
self.choose_target(agent, controller, &read_data, event_emitter);
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
|
|
|
self.idle(agent, controller, &read_data);
|
|
|
|
}
|
|
|
|
}
|
2020-07-29 19:58:14 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
fn hostile_tree(
|
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
read_data: &ReadData,
|
|
|
|
event_emitter: &mut Emitter<'_, ServerEvent>,
|
|
|
|
) {
|
2021-04-11 23:47:29 +00:00
|
|
|
if self.damage < HEALING_ITEM_THRESHOLD && self.heal_self(agent, controller) {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.01;
|
2021-04-11 23:47:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-03-30 00:25:59 +00:00
|
|
|
if let Some(Target {
|
|
|
|
target,
|
|
|
|
selected_at,
|
|
|
|
..
|
|
|
|
}) = agent.target
|
|
|
|
{
|
2021-03-16 19:17:08 +00:00
|
|
|
if let Some(tgt_pos) = read_data.positions.get(target) {
|
2021-02-07 07:22:06 +00:00
|
|
|
let dist_sqrd = self.pos.0.distance_squared(tgt_pos.0);
|
|
|
|
// Should the agent flee?
|
|
|
|
if 1.0 - agent.psyche.aggro > self.damage && self.flees {
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer == 0.0
|
|
|
|
&& agent.behavior.can(BehaviorCapability::SPEAK)
|
|
|
|
{
|
2021-02-07 07:22:06 +00:00
|
|
|
let msg = "npc.speech.villager_under_attack".to_string();
|
|
|
|
event_emitter
|
|
|
|
.emit(ServerEvent::Chat(UnresolvedChatMsg::npc(*self.uid, msg)));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.01;
|
|
|
|
} else if agent.action_state.action_timer < FLEE_DURATION
|
|
|
|
|| dist_sqrd < MAX_FLEE_DIST
|
|
|
|
{
|
2021-02-07 07:22:06 +00:00
|
|
|
self.flee(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data.terrain,
|
|
|
|
tgt_pos,
|
|
|
|
&read_data.dt,
|
|
|
|
);
|
|
|
|
} else {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
agent.target = None;
|
|
|
|
self.idle(agent, controller, &read_data);
|
|
|
|
}
|
2021-01-31 20:29:50 +00:00
|
|
|
|
2021-04-25 21:24:06 +00:00
|
|
|
// If not fleeing, attack the hostile entity!
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-04-25 21:24:06 +00:00
|
|
|
// If the hostile entity is dead or has an invulnerability buff (eg, those
|
|
|
|
// applied in safezones), return to idle
|
2021-03-16 19:17:08 +00:00
|
|
|
if should_stop_attacking(
|
|
|
|
read_data.healths.get(target),
|
|
|
|
read_data.buffs.get(target),
|
|
|
|
) {
|
2021-04-07 19:37:48 +00:00
|
|
|
if agent.behavior.can(BehaviorCapability::SPEAK) {
|
2021-04-07 11:26:15 +00:00
|
|
|
let msg = "npc.speech.villager_enemy_killed".to_string();
|
2021-02-07 07:22:06 +00:00
|
|
|
event_emitter
|
|
|
|
.emit(ServerEvent::Chat(UnresolvedChatMsg::npc(*self.uid, msg)));
|
|
|
|
}
|
2021-04-25 21:24:06 +00:00
|
|
|
|
|
|
|
agent.target = None;
|
2021-04-11 23:47:29 +00:00
|
|
|
// Choose a new target every 10 seconds, but only for
|
|
|
|
// enemies
|
2021-04-25 21:24:06 +00:00
|
|
|
// TODO: This should be more
|
|
|
|
// principled. Consider factoring
|
2021-04-11 23:47:29 +00:00
|
|
|
// health, combat rating, wielded weapon, etc, into the
|
|
|
|
// decision to change target.
|
|
|
|
} else if read_data.time.0 - selected_at > RETARGETING_THRESHOLD_SECONDS
|
|
|
|
&& matches!(self.alignment, Some(Alignment::Enemy))
|
|
|
|
{
|
2021-03-30 00:25:59 +00:00
|
|
|
self.choose_target(agent, controller, &read_data, event_emitter);
|
2021-02-07 07:22:06 +00:00
|
|
|
} else if dist_sqrd < SIGHT_DIST.powi(2) {
|
|
|
|
self.attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data.terrain,
|
|
|
|
tgt_pos,
|
|
|
|
read_data.bodies.get(target),
|
|
|
|
&read_data.dt,
|
2021-03-21 03:28:13 +00:00
|
|
|
&read_data,
|
2021-02-07 07:22:06 +00:00
|
|
|
);
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
self.idle(agent, controller, &read_data);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2021-03-30 00:25:59 +00:00
|
|
|
////////////////////////////////////////
|
|
|
|
// Action Nodes
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
|
|
|
fn glider_fall(&self, agent: &mut Agent, controller: &mut Controller, read_data: &ReadData) {
|
|
|
|
if self.vel.0.z < -26.0 {
|
|
|
|
controller.actions.push(ControlAction::GlideWield);
|
|
|
|
if let Some(Target { target, .. }) = agent.target {
|
|
|
|
if let Some(tgt_pos) = read_data.positions.get(target) {
|
|
|
|
controller.inputs.move_dir = (self.pos.0 - tgt_pos.0)
|
|
|
|
.xy()
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::zero);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
fn idle(&self, agent: &mut Agent, controller: &mut Controller, read_data: &ReadData) {
|
|
|
|
// Light lanterns at night
|
|
|
|
// TODO Add a method to turn on NPC lanterns underground
|
|
|
|
let lantern_equipped = self
|
|
|
|
.inventory
|
|
|
|
.equipped(EquipSlot::Lantern)
|
|
|
|
.as_ref()
|
|
|
|
.map_or(false, |item| {
|
|
|
|
matches!(item.kind(), comp::item::ItemKind::Lantern(_))
|
|
|
|
});
|
|
|
|
let lantern_turned_on = self.light_emitter.is_some();
|
|
|
|
let day_period = DayPeriod::from(read_data.time_of_day.0);
|
|
|
|
// Only emit event for agents that have a lantern equipped
|
2021-03-03 03:55:28 +00:00
|
|
|
if lantern_equipped && thread_rng().gen_bool(0.001) {
|
2021-02-07 07:22:06 +00:00
|
|
|
if day_period.is_dark() && !lantern_turned_on {
|
|
|
|
// Agents with turned off lanterns turn them on randomly once it's
|
|
|
|
// nighttime and keep them on
|
|
|
|
// Only emit event for agents that sill need to
|
|
|
|
// turn on their lantern
|
2021-03-03 03:55:28 +00:00
|
|
|
controller.events.push(ControlEvent::EnableLantern)
|
2021-02-07 07:22:06 +00:00
|
|
|
} else if lantern_turned_on && day_period.is_light() {
|
|
|
|
// agents with turned on lanterns turn them off randomly once it's
|
|
|
|
// daytime and keep them off
|
2021-03-03 03:55:28 +00:00
|
|
|
controller.events.push(ControlEvent::DisableLantern)
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
};
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2021-04-11 23:47:29 +00:00
|
|
|
if self.damage < HEALING_ITEM_THRESHOLD && self.heal_self(agent, controller) {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.01;
|
2021-04-11 23:47:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
if let Some((travel_to, _destination)) = &agent.rtsim_controller.travel_to {
|
|
|
|
// if it has an rtsim destination and can fly then it should
|
|
|
|
// if it is flying and bumps something above it then it should move down
|
2021-03-14 18:42:39 +00:00
|
|
|
if self.traversal_config.can_fly
|
|
|
|
&& !read_data
|
|
|
|
.terrain
|
|
|
|
.ray(self.pos.0, self.pos.0 + (Vec3::unit_z() * 3.0))
|
|
|
|
.until(Block::is_solid)
|
|
|
|
.cast()
|
|
|
|
.1
|
|
|
|
.map_or(true, |b| b.is_some())
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Fly));
|
2021-03-14 18:42:39 +00:00
|
|
|
} else {
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::CancelInput(InputKind::Fly))
|
|
|
|
}
|
2021-04-21 17:10:13 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*read_data.terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
*travel_to,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero)
|
|
|
|
* speed.min(agent.rtsim_controller.speed_factor);
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5 || self.traversal_config.can_fly);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.climb = Some(comp::Climb::Up);
|
2021-03-23 09:51:53 +00:00
|
|
|
//.filter(|_| bearing.z > 0.1 || self.physics_state.in_liquid().is_some());
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z
|
|
|
|
+ if self.traversal_config.can_fly {
|
2021-04-21 17:10:13 +00:00
|
|
|
// NOTE: costs 4 us (imbris)
|
2021-03-12 22:14:08 +00:00
|
|
|
let obstacle_ahead = read_data
|
2021-02-07 07:22:06 +00:00
|
|
|
.terrain
|
|
|
|
.ray(
|
|
|
|
self.pos.0 + Vec3::unit_z(),
|
|
|
|
self.pos.0
|
2021-03-12 02:58:57 +00:00
|
|
|
+ bearing.try_normalized().unwrap_or_else(Vec3::unit_y) * 80.0
|
2021-02-07 07:22:06 +00:00
|
|
|
+ Vec3::unit_z(),
|
|
|
|
)
|
|
|
|
.until(Block::is_solid)
|
|
|
|
.cast()
|
|
|
|
.1
|
2021-03-12 22:14:08 +00:00
|
|
|
.map_or(true, |b| b.is_some());
|
2021-04-21 17:10:13 +00:00
|
|
|
|
2021-03-24 19:42:37 +00:00
|
|
|
let mut ground_too_close = self
|
2021-03-12 22:14:08 +00:00
|
|
|
.body
|
|
|
|
.map(|body| {
|
2021-04-15 18:07:46 +00:00
|
|
|
#[cfg(feature = "worldgen")]
|
2021-03-12 22:14:08 +00:00
|
|
|
let height_approx = self.pos.0.y
|
|
|
|
- read_data
|
|
|
|
.world
|
|
|
|
.sim()
|
|
|
|
.get_alt_approx(self.pos.0.xy().map(|x: f32| x as i32))
|
|
|
|
.unwrap_or(0.0);
|
2021-04-15 18:07:46 +00:00
|
|
|
#[cfg(not(feature = "worldgen"))]
|
|
|
|
let height_approx = self.pos.0.y;
|
2021-03-12 18:53:06 +00:00
|
|
|
|
2021-03-12 22:14:08 +00:00
|
|
|
height_approx < body.flying_height()
|
|
|
|
})
|
|
|
|
.unwrap_or(false);
|
|
|
|
|
2021-03-24 19:42:37 +00:00
|
|
|
const NUM_RAYS: usize = 5;
|
2021-04-21 17:10:13 +00:00
|
|
|
|
|
|
|
// NOTE: costs 15-20 us (imbris)
|
2021-03-24 19:42:37 +00:00
|
|
|
for i in 0..=NUM_RAYS {
|
|
|
|
let magnitude = self.body.map_or(20.0, |b| b.flying_height());
|
|
|
|
// Lerp between a line straight ahead and straight down to detect a
|
|
|
|
// wedge of obstacles we might fly into (inclusive so that both vectors
|
|
|
|
// are sampled)
|
|
|
|
if let Some(dir) = Lerp::lerp(
|
|
|
|
-Vec3::unit_z(),
|
|
|
|
Vec3::new(bearing.x, bearing.y, 0.0),
|
|
|
|
i as f32 / NUM_RAYS as f32,
|
|
|
|
)
|
|
|
|
.try_normalized()
|
|
|
|
{
|
|
|
|
ground_too_close |= read_data
|
|
|
|
.terrain
|
|
|
|
.ray(self.pos.0, self.pos.0 + magnitude * dir)
|
|
|
|
.until(|b: &Block| b.is_solid() || b.is_liquid())
|
|
|
|
.cast()
|
|
|
|
.1
|
|
|
|
.map_or(false, |b| b.is_some())
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-12 22:14:08 +00:00
|
|
|
if obstacle_ahead || ground_too_close {
|
2021-02-07 07:22:06 +00:00
|
|
|
1.0 //fly up when approaching obstacles
|
|
|
|
} else {
|
|
|
|
-0.1
|
|
|
|
} //flying things should slowly come down from the stratosphere
|
|
|
|
} else {
|
|
|
|
0.05 //normal land traveller offset
|
|
|
|
};
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
// Put away weapon
|
2021-03-03 03:55:28 +00:00
|
|
|
if thread_rng().gen_bool(0.1)
|
2021-02-07 07:22:06 +00:00
|
|
|
&& matches!(
|
|
|
|
read_data.char_states.get(*self.entity),
|
|
|
|
Some(CharacterState::Wielding)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
controller.actions.push(ControlAction::Unwield);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.bearing += Vec2::new(
|
|
|
|
thread_rng().gen::<f32>() - 0.5,
|
|
|
|
thread_rng().gen::<f32>() - 0.5,
|
|
|
|
) * 0.1
|
|
|
|
- agent.bearing * 0.003
|
|
|
|
- agent.patrol_origin.map_or(Vec2::zero(), |patrol_origin| {
|
|
|
|
(self.pos.0 - patrol_origin).xy() * 0.0002
|
|
|
|
});
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
// Stop if we're too close to a wall
|
2021-04-21 17:10:13 +00:00
|
|
|
// NOTE: costs 1 us (imbris)
|
2021-02-07 07:22:06 +00:00
|
|
|
agent.bearing *= 0.1
|
|
|
|
+ if read_data
|
|
|
|
.terrain
|
|
|
|
.ray(
|
|
|
|
self.pos.0 + Vec3::unit_z(),
|
|
|
|
self.pos.0
|
|
|
|
+ Vec3::from(agent.bearing)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec3::unit_y)
|
|
|
|
* 5.0
|
|
|
|
+ Vec3::unit_z(),
|
|
|
|
)
|
|
|
|
.until(Block::is_solid)
|
|
|
|
.cast()
|
|
|
|
.1
|
|
|
|
.map_or(true, |b| b.is_none())
|
|
|
|
{
|
|
|
|
0.9
|
|
|
|
} else {
|
|
|
|
0.0
|
|
|
|
};
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
if agent.bearing.magnitude_squared() > 0.5f32.powi(2) {
|
|
|
|
controller.inputs.move_dir = agent.bearing * 0.65;
|
|
|
|
}
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
// Put away weapon
|
2021-03-03 03:55:28 +00:00
|
|
|
if thread_rng().gen_bool(0.1)
|
2021-02-07 07:22:06 +00:00
|
|
|
&& matches!(
|
|
|
|
read_data.char_states.get(*self.entity),
|
|
|
|
Some(CharacterState::Wielding)
|
|
|
|
)
|
|
|
|
{
|
|
|
|
controller.actions.push(ControlAction::Unwield);
|
|
|
|
}
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
// Sit
|
|
|
|
if thread_rng().gen::<f32>() < 0.0035 {
|
|
|
|
controller.actions.push(ControlAction::Sit);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
fn interact(
|
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
read_data: &ReadData,
|
|
|
|
event_emitter: &mut Emitter<'_, ServerEvent>,
|
|
|
|
) {
|
|
|
|
// TODO: Process group invites
|
|
|
|
// TODO: Add Group AgentEvent
|
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 accept = false; // set back to "matches!(alignment, Alignment::Npc)"
|
|
|
|
// when we got better NPC recruitment mechanics if accept {
|
|
|
|
// // Clear agent comp
|
|
|
|
// //*agent = Agent::default();
|
|
|
|
// controller
|
|
|
|
// .events
|
|
|
|
// .push(ControlEvent::InviteResponse(InviteResponse::Accept));
|
|
|
|
// } else {
|
|
|
|
// controller
|
|
|
|
// .events
|
|
|
|
// .push(ControlEvent::InviteResponse(InviteResponse::Decline));
|
|
|
|
// }
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += read_data.dt.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
|
|
|
let msg = agent.inbox.pop_back();
|
|
|
|
match msg {
|
2021-03-29 14:47:42 +00:00
|
|
|
Some(AgentEvent::Talk(by, subject)) => {
|
2021-04-07 19:37:48 +00:00
|
|
|
if agent.behavior.can(BehaviorCapability::SPEAK) {
|
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 let Some(target) = read_data.uid_allocator.retrieve_entity_internal(by.id())
|
|
|
|
{
|
|
|
|
agent.target = Some(Target {
|
|
|
|
target,
|
|
|
|
hostile: false,
|
2021-03-24 03:00:05 +00:00
|
|
|
selected_at: read_data.time.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
|
|
|
});
|
2021-03-29 14:47:42 +00:00
|
|
|
|
|
|
|
if self.look_toward(controller, read_data, &target) {
|
2021-04-01 17:13:08 +00:00
|
|
|
controller.actions.push(ControlAction::Stand);
|
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
|
|
|
controller.actions.push(ControlAction::Talk);
|
2021-03-29 14:47:42 +00:00
|
|
|
match subject {
|
|
|
|
Subject::Regular => {
|
|
|
|
if let (
|
|
|
|
Some((_travel_to, destination_name)),
|
|
|
|
Some(rtsim_entity),
|
|
|
|
) = (&agent.rtsim_controller.travel_to, &self.rtsim_entity)
|
|
|
|
{
|
|
|
|
let msg =
|
|
|
|
if let Some(tgt_stats) = read_data.stats.get(target) {
|
|
|
|
agent.rtsim_controller.events.push(
|
|
|
|
RtSimEvent::AddMemory(Memory {
|
|
|
|
item: MemoryItem::CharacterInteraction {
|
|
|
|
name: tgt_stats.name.clone(),
|
|
|
|
},
|
|
|
|
time_to_forget: read_data.time.0 + 600.0,
|
|
|
|
}),
|
|
|
|
);
|
|
|
|
if rtsim_entity
|
|
|
|
.brain
|
|
|
|
.remembers_character(&tgt_stats.name)
|
|
|
|
{
|
2021-04-03 02:27:30 +00:00
|
|
|
format!(
|
|
|
|
"Greetings fair {}! It has been far too \
|
|
|
|
long since last I saw you. I'm going to \
|
|
|
|
{} right now.",
|
|
|
|
&tgt_stats.name, destination_name
|
|
|
|
)
|
2021-03-29 14:47:42 +00:00
|
|
|
} else {
|
|
|
|
format!(
|
|
|
|
"I'm heading to {}! Want to come along?",
|
|
|
|
destination_name
|
|
|
|
)
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
format!(
|
|
|
|
"I'm heading to {}! Want to come along?",
|
|
|
|
destination_name
|
|
|
|
)
|
|
|
|
};
|
|
|
|
event_emitter.emit(ServerEvent::Chat(
|
|
|
|
UnresolvedChatMsg::npc(*self.uid, msg),
|
|
|
|
));
|
2021-04-08 17:06:57 +00:00
|
|
|
} else if agent.behavior.can_trade() {
|
2021-03-31 17:06:41 +00:00
|
|
|
let msg = "npc.speech.merchant_advertisement".to_string();
|
2021-03-29 14:47:42 +00:00
|
|
|
event_emitter.emit(ServerEvent::Chat(
|
|
|
|
UnresolvedChatMsg::npc(*self.uid, msg),
|
|
|
|
));
|
2021-03-16 01:30:35 +00:00
|
|
|
} else {
|
2021-03-29 14:47:42 +00:00
|
|
|
let msg = "npc.speech.villager".to_string();
|
|
|
|
event_emitter.emit(ServerEvent::Chat(
|
|
|
|
UnresolvedChatMsg::npc(*self.uid, msg),
|
|
|
|
));
|
2021-03-16 01:30:35 +00:00
|
|
|
}
|
2021-03-29 14:47:42 +00:00
|
|
|
},
|
|
|
|
Subject::Trade => {
|
2021-04-08 17:06:57 +00:00
|
|
|
if agent.behavior.can_trade() {
|
2021-04-07 19:37:48 +00:00
|
|
|
if !agent.behavior.is(BehaviorState::TRADING) {
|
2021-03-31 17:06:41 +00:00
|
|
|
controller.events.push(ControlEvent::InitiateInvite(
|
|
|
|
by,
|
|
|
|
InviteKind::Trade,
|
|
|
|
));
|
|
|
|
let msg =
|
|
|
|
"npc.speech.merchant_advertisement".to_string();
|
|
|
|
event_emitter.emit(ServerEvent::Chat(
|
|
|
|
UnresolvedChatMsg::npc(*self.uid, msg),
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
event_emitter.emit(ServerEvent::Chat(
|
|
|
|
UnresolvedChatMsg::npc(
|
|
|
|
*self.uid,
|
|
|
|
"npc.speech.merchant_busy".to_string(),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
2021-03-29 14:47:42 +00:00
|
|
|
} else {
|
|
|
|
// TODO: maybe make some travellers willing to trade with
|
|
|
|
// simpler goods like potions
|
|
|
|
event_emitter.emit(ServerEvent::Chat(
|
|
|
|
UnresolvedChatMsg::npc(
|
|
|
|
*self.uid,
|
2021-03-31 17:06:41 +00:00
|
|
|
"npc.speech.villager_decline_trade".to_string(),
|
2021-03-29 14:47:42 +00:00
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Subject::Mood => {
|
|
|
|
if let Some(rtsim_entity) = self.rtsim_entity {
|
|
|
|
if !rtsim_entity.brain.remembers_mood() {
|
|
|
|
// TODO: the following code will need a rework to
|
|
|
|
// implement more mood contexts
|
|
|
|
// This require that town NPCs becomes rtsim_entities to
|
|
|
|
// work fully.
|
|
|
|
match rand::random::<u32>() % 3 {
|
|
|
|
0 => agent.rtsim_controller.events.push(
|
|
|
|
RtSimEvent::SetMood(Memory {
|
|
|
|
item: MemoryItem::Mood {
|
|
|
|
state: MoodState::Good(
|
|
|
|
MoodContext::GoodWeather,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
time_to_forget: read_data.time.0 + 21200.0,
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
1 => agent.rtsim_controller.events.push(
|
|
|
|
RtSimEvent::SetMood(Memory {
|
|
|
|
item: MemoryItem::Mood {
|
|
|
|
state: MoodState::Neutral(
|
|
|
|
MoodContext::EverydayLife,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
time_to_forget: read_data.time.0 + 21200.0,
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
2 => agent.rtsim_controller.events.push(
|
|
|
|
RtSimEvent::SetMood(Memory {
|
|
|
|
item: MemoryItem::Mood {
|
|
|
|
state: MoodState::Bad(
|
|
|
|
MoodContext::GoodWeather,
|
|
|
|
),
|
|
|
|
},
|
|
|
|
time_to_forget: read_data.time.0 + 86400.0,
|
|
|
|
}),
|
|
|
|
),
|
|
|
|
_ => {}, // will never happen
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some(memory) = rtsim_entity.brain.get_mood() {
|
|
|
|
let msg = match &memory.item {
|
|
|
|
MemoryItem::Mood { state } => state.describe(),
|
|
|
|
_ => "".to_string(),
|
|
|
|
};
|
|
|
|
event_emitter.emit(ServerEvent::Chat(
|
|
|
|
UnresolvedChatMsg::npc(*self.uid, msg),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Subject::Location(location) => {
|
|
|
|
if let Some(tgt_pos) = read_data.positions.get(target) {
|
|
|
|
event_emitter.emit(ServerEvent::Chat(
|
|
|
|
UnresolvedChatMsg::npc(
|
|
|
|
*self.uid,
|
|
|
|
format!(
|
|
|
|
"{} ? I think it's {} {} from here!",
|
|
|
|
location.name,
|
|
|
|
Distance::from_dir(
|
|
|
|
location.origin.as_::<f32>()
|
|
|
|
- tgt_pos.0.xy()
|
|
|
|
)
|
|
|
|
.name(),
|
|
|
|
Direction::from_dir(
|
|
|
|
location.origin.as_::<f32>()
|
|
|
|
- tgt_pos.0.xy()
|
|
|
|
)
|
|
|
|
.name()
|
|
|
|
),
|
|
|
|
),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Subject::Person(person) => {
|
|
|
|
if let Some(src_pos) = read_data.positions.get(target) {
|
|
|
|
let msg = if let Some(person_pos) = person.origin {
|
|
|
|
let distance = Distance::from_dir(
|
|
|
|
person_pos.xy() - src_pos.0.xy(),
|
|
|
|
);
|
|
|
|
match distance {
|
|
|
|
Distance::NextTo | Distance::Near => {
|
|
|
|
format!(
|
|
|
|
"{} ? I think he's {} {} from here!",
|
|
|
|
person.name(),
|
|
|
|
distance.name(),
|
|
|
|
Direction::from_dir(
|
|
|
|
person_pos.xy() - src_pos.0.xy(),
|
|
|
|
)
|
|
|
|
.name()
|
|
|
|
)
|
|
|
|
},
|
|
|
|
_ => {
|
|
|
|
format!(
|
|
|
|
"{} ? I think he's gone visiting another \
|
|
|
|
town. Come back later!",
|
|
|
|
person.name()
|
|
|
|
)
|
|
|
|
},
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
format!(
|
|
|
|
"{} ? Sorry, I don't know where you can find him.",
|
|
|
|
person.name()
|
|
|
|
)
|
|
|
|
};
|
|
|
|
event_emitter.emit(ServerEvent::Chat(
|
|
|
|
UnresolvedChatMsg::npc(*self.uid, msg),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Subject::Work => {},
|
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-03 03:55:28 +00:00
|
|
|
}
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
2021-03-16 23:22:48 +00:00
|
|
|
Some(AgentEvent::TradeInvite(with)) => {
|
2021-04-08 17:06:57 +00:00
|
|
|
if agent.behavior.can_trade() {
|
2021-04-07 19:37:48 +00:00
|
|
|
if !agent.behavior.is(BehaviorState::TRADING) {
|
2021-03-31 17:06:41 +00:00
|
|
|
// stand still and looking towards the trading player
|
2021-04-01 17:13:08 +00:00
|
|
|
controller.actions.push(ControlAction::Stand);
|
2021-03-31 17:06:41 +00:00
|
|
|
controller.actions.push(ControlAction::Talk);
|
|
|
|
if let Some(target) =
|
|
|
|
read_data.uid_allocator.retrieve_entity_internal(with.id())
|
|
|
|
{
|
|
|
|
agent.target = Some(Target {
|
|
|
|
target,
|
|
|
|
hostile: false,
|
|
|
|
selected_at: read_data.time.0,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
controller
|
|
|
|
.events
|
|
|
|
.push(ControlEvent::InviteResponse(InviteResponse::Accept));
|
2021-04-07 19:37:48 +00:00
|
|
|
agent.behavior.unset(BehaviorState::TRADING_ISSUER);
|
|
|
|
agent.behavior.set(BehaviorState::TRADING);
|
2021-03-31 17:06:41 +00:00
|
|
|
} else {
|
|
|
|
controller
|
|
|
|
.events
|
|
|
|
.push(ControlEvent::InviteResponse(InviteResponse::Decline));
|
2021-04-07 19:37:48 +00:00
|
|
|
if agent.behavior.can(BehaviorCapability::SPEAK) {
|
2021-03-31 17:06:41 +00:00
|
|
|
event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc(
|
|
|
|
*self.uid,
|
|
|
|
"npc.speech.merchant_busy".to_string(),
|
|
|
|
)));
|
|
|
|
}
|
2021-03-16 23:22:48 +00:00
|
|
|
}
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
} else {
|
|
|
|
// TODO: Provide a hint where to find the closest merchant?
|
|
|
|
controller
|
|
|
|
.events
|
|
|
|
.push(ControlEvent::InviteResponse(InviteResponse::Decline));
|
2021-04-07 19:37:48 +00:00
|
|
|
if agent.behavior.can(BehaviorCapability::SPEAK) {
|
2021-03-29 14:47:42 +00:00
|
|
|
event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc(
|
|
|
|
*self.uid,
|
2021-03-31 17:06:41 +00:00
|
|
|
"npc.speech.villager_decline_trade".to_string(),
|
2021-03-29 14:47:42 +00:00
|
|
|
)));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Some(AgentEvent::TradeAccepted(with)) => {
|
2021-04-07 19:37:48 +00:00
|
|
|
if !agent.behavior.is(BehaviorState::TRADING) {
|
2021-03-29 14:47:42 +00:00
|
|
|
if let Some(target) =
|
|
|
|
read_data.uid_allocator.retrieve_entity_internal(with.id())
|
|
|
|
{
|
|
|
|
agent.target = Some(Target {
|
|
|
|
target,
|
|
|
|
hostile: false,
|
|
|
|
selected_at: read_data.time.0,
|
|
|
|
});
|
|
|
|
}
|
2021-04-07 19:37:48 +00:00
|
|
|
agent.behavior.set(BehaviorState::TRADING);
|
|
|
|
agent.behavior.set(BehaviorState::TRADING_ISSUER);
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
Some(AgentEvent::FinishedTrade(result)) => {
|
2021-04-07 19:37:48 +00:00
|
|
|
if agent.behavior.is(BehaviorState::TRADING) {
|
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
|
|
|
match result {
|
|
|
|
TradeResult::Completed => {
|
2021-03-16 23:22:48 +00:00
|
|
|
event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc(
|
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
|
|
|
*self.uid,
|
2021-03-31 17:06:41 +00:00
|
|
|
"npc.speech.merchant_trade_successful".to_string(),
|
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-16 23:22:48 +00:00
|
|
|
_ => event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc(
|
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
|
|
|
*self.uid,
|
2021-03-31 17:06:41 +00:00
|
|
|
"npc.speech.merchant_trade_declined".to_string(),
|
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-07 19:37:48 +00:00
|
|
|
agent.behavior.unset(BehaviorState::TRADING);
|
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
|
|
|
}
|
|
|
|
},
|
|
|
|
Some(AgentEvent::UpdatePendingTrade(boxval)) => {
|
|
|
|
let (tradeid, pending, prices, inventories) = *boxval;
|
2021-04-07 19:37:48 +00:00
|
|
|
if agent.behavior.is(BehaviorState::TRADING) {
|
|
|
|
let who: usize = if agent.behavior.is(BehaviorState::TRADING_ISSUER) {
|
2021-03-29 20:30:09 +00:00
|
|
|
0
|
|
|
|
} else {
|
|
|
|
1
|
|
|
|
};
|
2021-03-30 22:37:38 +00:00
|
|
|
let balance0: f32 =
|
|
|
|
prices.balance(&pending.offers, &inventories, 1 - who, true);
|
|
|
|
let balance1: f32 = prices.balance(&pending.offers, &inventories, who, false);
|
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 balance0 >= balance1 {
|
2021-03-23 02:53:53 +00:00
|
|
|
// If the trade is favourable to us, only send an accept message if we're
|
|
|
|
// not already accepting (since otherwise, spamclicking the accept button
|
|
|
|
// results in lagging and moving to the review phase of an unfavorable trade
|
|
|
|
// (although since the phase is included in the message, this shouldn't
|
|
|
|
// result in fully accepting an unfavourable trade))
|
2021-03-29 14:47:42 +00:00
|
|
|
if !pending.accept_flags[who] {
|
2021-03-23 02:53:53 +00:00
|
|
|
event_emitter.emit(ServerEvent::ProcessTradeAction(
|
|
|
|
*self.entity,
|
|
|
|
tradeid,
|
|
|
|
TradeAction::Accept(pending.phase),
|
|
|
|
));
|
2021-04-08 21:52:12 +00:00
|
|
|
tracing::trace!(?tradeid, ?balance0, ?balance1, "Accept Pending Trade");
|
2021-03-23 02:53:53 +00:00
|
|
|
}
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
} else {
|
|
|
|
if balance1 > 0.0 {
|
|
|
|
let msg = format!(
|
|
|
|
"That only covers {:.1}% of my costs!",
|
|
|
|
balance0 / balance1 * 100.0
|
|
|
|
);
|
2021-03-16 01:30:35 +00:00
|
|
|
event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc_say(
|
|
|
|
*self.uid, msg,
|
|
|
|
)));
|
2021-03-03 03:55:28 +00:00
|
|
|
}
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
if pending.phase != TradePhase::Mutate {
|
|
|
|
// we got into the review phase but without balanced goods, decline
|
2021-04-07 19:37:48 +00:00
|
|
|
agent.behavior.unset(BehaviorState::TRADING);
|
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
|
|
|
event_emitter.emit(ServerEvent::ProcessTradeAction(
|
|
|
|
*self.entity,
|
|
|
|
tradeid,
|
|
|
|
TradeAction::Decline,
|
|
|
|
));
|
|
|
|
}
|
2021-03-03 03:55:28 +00:00
|
|
|
}
|
|
|
|
}
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
},
|
|
|
|
None => {
|
2021-04-07 19:37:48 +00:00
|
|
|
if agent.behavior.can(BehaviorCapability::SPEAK) {
|
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
|
|
|
// no new events, continue looking towards the last interacting player for some
|
|
|
|
// time
|
|
|
|
if let Some(Target { target, .. }) = &agent.target {
|
2021-03-29 14:47:42 +00:00
|
|
|
self.look_toward(controller, read_data, target);
|
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
|
|
|
} else {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
Implement /price_list (work in progress), stub for /buy and /sell
remove outdated economic simulation code
remove old values, document
add natural resources to economy
Remove NaturalResources from Place (now in Economy)
find closest site to each chunk
implement natural resources (the distance scale is wrong)
cargo fmt
working distance calculation
this collection of natural resources seem to make sense, too much Wheat though
use natural resources and controlled area to replenish goods
increase the amount of chunks controlled by one guard to 50
add new professions and goods to the list
implement multiple products per worker
remove the old code and rename the new code to the previous name
correctly determine which goods guards will give you access to
correctly estimate the amount of natural resources controlled
adapt to new server API
instrument tooltips
Now I just need to figure out how to store a (reference to) a closure
closures for tooltip content generation
pass site/cave id to the client
Add economic information to the client structure
(not yet exchanged with the server)
Send SiteId to the client, prepare messages for economy request
Make client::sites a HashMap
Specialize the Crafter into Brewer,Bladesmith and Blacksmith
working server request for economic info from within tooltip
fully operational economic tooltips
I need to fix the id clash between caves and towns though
fix overlapping ids between caves and sites
display stock amount
correctly handle invalid (cave) ids in the request
some initial balancing, turn off most info logging
less intrusive way of implementing the dynamic tool tips in map
further tooltip cleanup
further cleanup, dynamic tooltip not fully working as intended
correctly working tooltip visibility logic
cleanup, display labor value
separate economy info request in a separate translation unit
display values as well
nicer display format for economy
add last_exports and coin to the new economy
do not allocate natural resources to Dungeons (making town so much larger)
balancing attempt
print town size statistics
cargo fmt (dead code)
resource tweaks, csv debugging
output a more interesting town (and then all sites)
fix the labor value logic (now we have meaningful prices)
load professions from ron (WIP)
use assets manager in economy
loading professions works
use professions from ron file
fix Labor debug logic
count chunks per type separately
(preparing for better resource control)
better structured resource data
traders, more professions (WIP)
fix exception when starting the simulation
fix replenish function
TODO:
- use area_ratio for resource usage (chunks should be added to stock, ratio on usage?)
- fix trading
documentation clean up
fix merge artifact
Revise trader mechanic
start Coin with a reasonable default
remove the outdated economy code
preserve documentation from removed old structure
output neighboring sites (preparation)
pass list of neighbors to economy
add trade structures
trading stub
Description of purpose by zesterer on Discord
remember prices (needed for planning)
avoid growing the order vector unboundedly
into_iter doesn't clear the Vec, so clear it manually
use drain to process Vecs, avoid clone
fix the test server
implement a test stub (I need to get it faster than 30 seconds to be more useful)
enable info output in test
debug missing and extra goods
use the same logging extension as water, activate feature
update dependencies
determine good prices, good exchange goods
a working set of revisions
a cozy world which economy tests in 2s
first order planning version
fun with package version
buy according to value/priority, not missing amount
introduce min price constant, fix order priority
in depth debugging
with a correct sign the trading plans start to make sense
move the trade planning to a separate function
rename new function
reorganize code into subroutines (much cleaner)
each trading step now has its own function
cut down the number of debugging output
introduce RoadSecurity and Transportation
transport capacity bookkeeping
only plan to pay with valuable goods, you can no longer stockpile unused options
(which interestingly shows a huge impact, to be investigated)
Coin is now listed as a payment (although not used)
proper transportation estimation (although 0)
remove more left overs uncovered by viewing the code in a merge request
use the old default values, handle non-pileable stocks directly before increasing it
(as economy is based on last year's products)
don't order the missing good multiple times
also it uses coin to buy things!
fix warnings and use the transportation from stock again
cargo fmt
prepare evaluation of trade
don't count transportation multiple times
fix merge artifact
operational trade planning
trade itself is still misleading
make clippy happy
clean up
correct labor ratio of merchants (no need to multiply with amount produced)
incomplete merchant labor_value computation
correct last commit
make economy of scale more explicit
make clippy happy (and code cleaner)
more merchant tweaks (more pop=better)
beginning of real trading code
revert the update of dependencies
remove stale comments/unused code
trading implementation complete (but untested)
something is still strange ...
fix sign in trading
another sign fix
some bugfixes and plenty of debugging code
another bug fixed, more to go
fix another invariant (rounding will lead to very small negative value)
introduce Terrain and Territory
fix merge mistakes
2021-03-14 03:18:32 +00:00
|
|
|
},
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
2020-01-26 00:06:03 +00:00
|
|
|
|
2021-03-29 14:47:42 +00:00
|
|
|
fn look_toward(
|
|
|
|
&self,
|
|
|
|
controller: &mut Controller,
|
|
|
|
read_data: &ReadData,
|
|
|
|
target: &EcsEntity,
|
|
|
|
) -> bool {
|
|
|
|
if let Some(tgt_pos) = read_data.positions.get(*target) {
|
|
|
|
let eye_offset = self.body.map_or(0.0, |b| b.eye_height());
|
|
|
|
let tgt_eye_offset = read_data
|
|
|
|
.bodies
|
|
|
|
.get(*target)
|
|
|
|
.map_or(0.0, |b| b.eye_height());
|
|
|
|
if let Some(dir) = Dir::from_unnormalized(
|
|
|
|
Vec3::new(tgt_pos.0.x, tgt_pos.0.y, tgt_pos.0.z + tgt_eye_offset)
|
|
|
|
- Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset),
|
|
|
|
) {
|
|
|
|
controller.inputs.look_dir = dir;
|
|
|
|
}
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
fn flee(
|
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
terrain: &TerrainGrid,
|
|
|
|
tgt_pos: &Pos,
|
|
|
|
dt: &DeltaTime,
|
|
|
|
) {
|
|
|
|
if let Some(body) = self.body {
|
|
|
|
if body.can_strafe() && !self.is_gliding {
|
|
|
|
controller.actions.push(ControlAction::Unwield);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
// Away from the target (ironically)
|
|
|
|
self.pos.0
|
|
|
|
+ (self.pos.0 - tgt_pos.0)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec3::unit_y)
|
|
|
|
* 50.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
|
2021-04-11 23:47:29 +00:00
|
|
|
/// Attempt to consume a healing item, and return whether any healing items
|
|
|
|
/// were queued. Callers should use this to implement a delay so that
|
|
|
|
/// the healing isn't interrupted.
|
|
|
|
fn heal_self(&self, _agent: &mut Agent, controller: &mut Controller) -> bool {
|
|
|
|
let healing_value = |item: &Item| {
|
|
|
|
let mut value = 0;
|
|
|
|
#[allow(clippy::single_match)]
|
|
|
|
match item.kind() {
|
|
|
|
ItemKind::Consumable { effect, .. } => {
|
|
|
|
for e in effect.iter() {
|
|
|
|
use BuffKind::*;
|
|
|
|
match e {
|
|
|
|
Effect::Health(HealthChange { amount, .. }) => {
|
|
|
|
value += *amount;
|
|
|
|
},
|
|
|
|
Effect::Buff(BuffEffect { kind, data, .. })
|
|
|
|
if matches!(kind, Regeneration | Saturation | Potion) =>
|
|
|
|
{
|
|
|
|
value += (data.strength
|
|
|
|
* data.duration.map_or(0.0, |d| d.as_secs() as f32))
|
|
|
|
as i32;
|
|
|
|
}
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
value
|
|
|
|
};
|
|
|
|
|
|
|
|
let mut consumables: Vec<_> = self
|
|
|
|
.inventory
|
|
|
|
.slots_with_id()
|
|
|
|
.filter_map(|(id, slot)| match slot {
|
|
|
|
Some(item) if healing_value(item) > 0 => Some((id, item)),
|
|
|
|
_ => None,
|
|
|
|
})
|
|
|
|
.collect();
|
|
|
|
|
|
|
|
consumables.sort_by_key(|(_, item)| healing_value(item));
|
|
|
|
|
|
|
|
if let Some((id, _)) = consumables.last() {
|
|
|
|
use comp::inventory::slot::Slot;
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::InventoryAction(InventoryAction::Use(
|
|
|
|
Slot::Inventory(*id),
|
|
|
|
)));
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-16 01:30:35 +00:00
|
|
|
fn choose_target(
|
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
read_data: &ReadData,
|
|
|
|
event_emitter: &mut Emitter<'_, ServerEvent>,
|
|
|
|
) {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
|
2021-04-21 17:10:13 +00:00
|
|
|
// Search area
|
|
|
|
let target = self.cached_spatial_grid.0
|
|
|
|
.in_circle_aabr(self.pos.0.xy(), SEARCH_DIST)
|
|
|
|
.filter_map(|entity| {
|
|
|
|
read_data.positions
|
|
|
|
.get(entity)
|
|
|
|
.and_then(|l| read_data.healths.get(entity).map(|r| (l, r)))
|
|
|
|
.and_then(|l| read_data.stats.get(entity).map(|r| (l, r)))
|
|
|
|
.and_then(|l| read_data.inventories.get(entity).map(|r| (l, r)))
|
|
|
|
.map(|(((pos, health), stats), inventory)| {
|
|
|
|
(entity, pos, health, stats, inventory, read_data.alignments.get(entity), read_data.char_states.get(entity))
|
|
|
|
})
|
|
|
|
})
|
2021-03-16 01:30:35 +00:00
|
|
|
.filter(|(e, e_pos, e_health, e_stats, e_inventory, e_alignment, char_state)| {
|
2021-02-07 07:22:06 +00:00
|
|
|
let mut search_dist = SEARCH_DIST;
|
|
|
|
let mut listen_dist = LISTEN_DIST;
|
|
|
|
if char_state.map_or(false, |c_s| c_s.is_stealthy()) {
|
|
|
|
// TODO: make sneak more effective based on a stat like e_stats.fitness
|
|
|
|
search_dist *= SNEAK_COEFFICIENT;
|
|
|
|
listen_dist *= SNEAK_COEFFICIENT;
|
2021-02-22 00:57:25 +00:00
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
((e_pos.0.distance_squared(self.pos.0) < search_dist.powi(2) &&
|
|
|
|
// Within our view
|
|
|
|
(e_pos.0 - self.pos.0).try_normalized().map(|v| v.dot(*controller.inputs.look_dir) > 0.15).unwrap_or(true))
|
|
|
|
// Within listen distance
|
|
|
|
|| e_pos.0.distance_squared(self.pos.0) < listen_dist.powi(2)) // TODO implement proper sound system for agents
|
|
|
|
&& e != self.entity
|
|
|
|
&& !e_health.is_dead
|
2021-04-25 21:24:06 +00:00
|
|
|
&& !invulnerability_is_in_buffs(read_data.buffs.get(*e))
|
2021-03-23 22:41:17 +00:00
|
|
|
&& (try_owner_alignment(self.alignment, &read_data).and_then(|a| try_owner_alignment(*e_alignment, &read_data).map(|b| a.hostile_towards(*b))).unwrap_or(false) || (
|
2021-03-16 01:30:35 +00:00
|
|
|
if let Some(rtsim_entity) = &self.rtsim_entity {
|
|
|
|
if rtsim_entity.brain.remembers_fight_with_character(&e_stats.name) {
|
|
|
|
agent.rtsim_controller.events.push(
|
|
|
|
RtSimEvent::AddMemory(Memory {
|
|
|
|
item: MemoryItem::CharacterFight { name: e_stats.name.clone() },
|
|
|
|
time_to_forget: read_data.time.0 + 300.0,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
let msg = format!("{}! How dare you cross me again!", e_stats.name.clone());
|
2021-03-16 23:22:48 +00:00
|
|
|
event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc(*self.uid, msg)));
|
2021-03-16 01:30:35 +00:00
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
) ||
|
|
|
|
(
|
|
|
|
self.alignment.map_or(false, |alignment| {
|
|
|
|
if matches!(alignment, Alignment::Npc) && e_inventory.equipped_items().filter(|item| item.tags().contains(&ItemTag::Cultist)).count() > 2 {
|
2021-04-07 19:37:48 +00:00
|
|
|
if agent.behavior.can(BehaviorCapability::SPEAK) {
|
2021-03-16 01:30:35 +00:00
|
|
|
if self.rtsim_entity.is_some() {
|
|
|
|
agent.rtsim_controller.events.push(
|
|
|
|
RtSimEvent::AddMemory(Memory {
|
|
|
|
item: MemoryItem::CharacterFight { name: e_stats.name.clone() },
|
|
|
|
time_to_forget: read_data.time.0 + 300.0,
|
|
|
|
})
|
|
|
|
);
|
|
|
|
}
|
|
|
|
let msg = "npc.speech.villager_cultist_alarm".to_string();
|
|
|
|
event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc(*self.uid, msg)));
|
|
|
|
}
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
})
|
|
|
|
))
|
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
})
|
|
|
|
// Can we even see them?
|
2021-03-16 01:30:35 +00:00
|
|
|
.filter(|(_, e_pos, _, _, _, _, _)| read_data.terrain
|
2021-02-07 07:22:06 +00:00
|
|
|
.ray(self.pos.0 + Vec3::unit_z(), e_pos.0 + Vec3::unit_z())
|
|
|
|
.until(Block::is_opaque)
|
|
|
|
.cast()
|
|
|
|
.0 >= e_pos.0.distance(self.pos.0))
|
2021-03-16 01:30:35 +00:00
|
|
|
.min_by_key(|(_, e_pos, _, _, _, _, _)| (e_pos.0.distance_squared(self.pos.0) * 100.0) as i32) // TODO choose target by more than just distance
|
|
|
|
.map(|(e, _, _, _, _, _, _)| e);
|
2021-04-21 17:10:13 +00:00
|
|
|
|
|
|
|
agent.target = target.map(|target| Target {
|
|
|
|
target,
|
|
|
|
hostile: true,
|
|
|
|
selected_at: read_data.time.0,
|
|
|
|
});
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
2021-02-22 00:57:25 +00:00
|
|
|
|
2021-03-18 22:54:23 +00:00
|
|
|
fn jump_if(&self, controller: &mut Controller, condition: bool) {
|
|
|
|
if condition {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Jump));
|
2021-03-18 22:54:23 +00:00
|
|
|
} else {
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::CancelInput(InputKind::Jump))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-21 03:28:13 +00:00
|
|
|
#[allow(clippy::too_many_arguments)]
|
2021-02-07 07:22:06 +00:00
|
|
|
fn attack(
|
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
terrain: &TerrainGrid,
|
|
|
|
tgt_pos: &Pos,
|
|
|
|
tgt_body: Option<&Body>,
|
|
|
|
dt: &DeltaTime,
|
2021-03-21 18:22:14 +00:00
|
|
|
read_data: &ReadData,
|
2021-02-07 07:22:06 +00:00
|
|
|
) {
|
|
|
|
let min_attack_dist = self.body.map_or(3.0, |b| b.radius() * self.scale + 2.0);
|
2021-04-30 19:25:08 +00:00
|
|
|
|
|
|
|
let tool_tactic = |tool_kind| match tool_kind {
|
|
|
|
ToolKind::Bow => Tactic::Bow,
|
|
|
|
ToolKind::Staff => Tactic::Staff,
|
|
|
|
ToolKind::Hammer => Tactic::Hammer,
|
|
|
|
ToolKind::Sword | ToolKind::Spear => Tactic::Sword,
|
|
|
|
ToolKind::Axe => Tactic::Axe,
|
|
|
|
_ => Tactic::Melee,
|
|
|
|
};
|
|
|
|
|
|
|
|
let tactic = self
|
2021-02-07 07:22:06 +00:00
|
|
|
.inventory
|
|
|
|
.equipped(EquipSlot::Mainhand)
|
|
|
|
.as_ref()
|
2021-04-30 19:25:08 +00:00
|
|
|
.map(|item| {
|
2021-05-01 13:25:38 +00:00
|
|
|
if let Some(ability_spec) = item.ability_spec() {
|
|
|
|
match ability_spec {
|
2021-04-30 19:25:08 +00:00
|
|
|
AbilitySpec::Custom(spec) => match spec.as_str() {
|
|
|
|
"Axe Simple" | "Sword Simple" => Tactic::Sword,
|
|
|
|
"Staff Simple" => Tactic::Staff,
|
|
|
|
"Bow Simple" => Tactic::Bow,
|
|
|
|
"Stone Golem" => Tactic::StoneGolem,
|
|
|
|
"Quad Med Quick" => Tactic::CircleCharge {
|
|
|
|
radius: 3,
|
|
|
|
circle_time: 2,
|
|
|
|
},
|
|
|
|
"Quad Med Jump" => Tactic::QuadMedJump,
|
|
|
|
"Quad Med Charge" => Tactic::CircleCharge {
|
|
|
|
radius: 12,
|
|
|
|
circle_time: 1,
|
|
|
|
},
|
|
|
|
"Quad Med Basic" => Tactic::QuadMedBasic,
|
|
|
|
"Quad Low Ranged" => Tactic::QuadLowRanged,
|
|
|
|
"Quad Low Breathe" | "Quad Low Beam" => Tactic::Lavadrake,
|
|
|
|
"Quad Low Tail" => Tactic::TailSlap,
|
|
|
|
"Quad Low Quick" => Tactic::QuadLowQuick,
|
|
|
|
"Quad Low Basic" => Tactic::QuadLowBasic,
|
|
|
|
"Theropod Basic" | "Theropod Bird" => Tactic::Theropod,
|
|
|
|
"Theropod Charge" => Tactic::CircleCharge {
|
|
|
|
radius: 6,
|
|
|
|
circle_time: 1,
|
|
|
|
},
|
|
|
|
"Turret" => Tactic::Turret,
|
|
|
|
"Bird Large Breathe" => Tactic::BirdLargeBreathe,
|
|
|
|
"Bird Large Fire" => Tactic::BirdLargeFire,
|
|
|
|
"Mindflayer" => Tactic::Mindflayer,
|
2021-04-28 02:33:24 +00:00
|
|
|
"Minotaur" => Tactic::Minotaur,
|
2021-04-30 19:25:08 +00:00
|
|
|
_ => Tactic::Melee,
|
|
|
|
},
|
|
|
|
AbilitySpec::Tool(tool_kind) => tool_tactic(*tool_kind),
|
|
|
|
}
|
|
|
|
} else if let ItemKind::Tool(tool) = &item.kind() {
|
|
|
|
tool_tactic(tool.kind)
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-04-30 19:25:08 +00:00
|
|
|
Tactic::Melee
|
2020-01-26 00:06:03 +00:00
|
|
|
}
|
2021-04-30 19:25:08 +00:00
|
|
|
})
|
|
|
|
.unwrap_or(Tactic::Melee);
|
2020-01-25 18:49:47 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
// Wield the weapon as running towards the target
|
|
|
|
controller.actions.push(ControlAction::Wield);
|
2020-07-30 19:26:49 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
let eye_offset = self.body.map_or(0.0, |b| b.eye_height());
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
let tgt_eye_offset = tgt_body.map_or(0.0, |b| b.eye_height()) +
|
|
|
|
// Special case for jumping attacks to jump at the body
|
|
|
|
// of the target and not the ground around the target
|
|
|
|
// For the ranged it is to shoot at the feet and not
|
|
|
|
// the head to get splash damage
|
|
|
|
if tactic == Tactic::QuadMedJump {
|
|
|
|
1.0
|
|
|
|
} else if matches!(tactic, Tactic::QuadLowRanged) {
|
|
|
|
-1.0
|
|
|
|
} else {
|
|
|
|
0.0
|
|
|
|
};
|
2021-01-31 20:29:50 +00:00
|
|
|
|
2021-03-23 09:51:53 +00:00
|
|
|
let dist_sqrd = self.pos.0.distance_squared(tgt_pos.0);
|
2021-04-24 19:56:33 +00:00
|
|
|
let angle = self
|
|
|
|
.ori
|
|
|
|
.look_vec()
|
|
|
|
.angle_between(tgt_pos.0 - self.pos.0)
|
|
|
|
.to_degrees();
|
2021-02-07 07:22:06 +00:00
|
|
|
|
2021-03-23 09:51:53 +00:00
|
|
|
// FIXME: Retrieve actual projectile speed!
|
|
|
|
// We have to assume projectiles are faster than base speed because there are
|
|
|
|
// skills that increase it, and in most cases this will cause agents to
|
|
|
|
// overshoot
|
|
|
|
if let Some(dir) = match tactic {
|
|
|
|
Tactic::Bow
|
|
|
|
| Tactic::FixedTurret
|
|
|
|
| Tactic::QuadLowRanged
|
|
|
|
| Tactic::QuadMedJump
|
|
|
|
| Tactic::RotatingTurret
|
|
|
|
| Tactic::Staff
|
|
|
|
| Tactic::Turret
|
|
|
|
if dist_sqrd > 0.0 =>
|
|
|
|
{
|
|
|
|
aim_projectile(
|
|
|
|
90.0, // + self.vel.0.magnitude(),
|
|
|
|
Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset),
|
|
|
|
Vec3::new(tgt_pos.0.x, tgt_pos.0.y, tgt_pos.0.z + tgt_eye_offset),
|
|
|
|
)
|
|
|
|
}
|
|
|
|
_ => Dir::from_unnormalized(
|
|
|
|
Vec3::new(tgt_pos.0.x, tgt_pos.0.y, tgt_pos.0.z + tgt_eye_offset)
|
|
|
|
- Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset),
|
|
|
|
),
|
|
|
|
} {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.look_dir = dir;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Match on tactic. Each tactic has different controls
|
|
|
|
// depending on the distance from the agent to the target
|
|
|
|
match tactic {
|
|
|
|
Tactic::Melee => {
|
2021-04-24 19:56:33 +00:00
|
|
|
if dist_sqrd < min_attack_dist.powi(2) && angle < 45.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
|
|
|
|
if self.body.map(|b| b.is_humanoid()).unwrap_or(false)
|
|
|
|
&& dist_sqrd < 16.0f32.powi(2)
|
|
|
|
&& thread_rng().gen::<f32>() < 0.02
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Roll));
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::Axe => {
|
2021-04-24 19:56:33 +00:00
|
|
|
if dist_sqrd < min_attack_dist.powi(2) && angle < 45.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer > 6.0 {
|
2021-03-13 00:38:20 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::CancelInput(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
|
|
|
} else if agent.action_state.action_timer > 4.0 && self.energy.current() > 10 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-04-14 15:35:34 +00:00
|
|
|
} else if self.skill_set.has_skill(Skill::Axe(AxeSkill::UnlockLeap))
|
2021-02-07 07:22:06 +00:00
|
|
|
&& self.energy.current() > 800
|
|
|
|
&& thread_rng().gen_bool(0.5)
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
if self.body.map(|b| b.is_humanoid()).unwrap_or(false)
|
|
|
|
&& dist_sqrd < 16.0f32.powi(2)
|
|
|
|
&& thread_rng().gen::<f32>() < 0.02
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Roll));
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::Hammer => {
|
2021-04-24 19:56:33 +00:00
|
|
|
if dist_sqrd < min_attack_dist.powi(2) && angle < 45.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer > 4.0 {
|
2021-03-13 00:38:20 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::CancelInput(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
|
|
|
} else if agent.action_state.action_timer > 2.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else if self
|
|
|
|
.skill_set
|
|
|
|
.has_skill(Skill::Hammer(HammerSkill::UnlockLeap))
|
|
|
|
&& self.energy.current() > 700
|
|
|
|
&& thread_rng().gen_bool(0.9)
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
2021-04-24 19:56:33 +00:00
|
|
|
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 45.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
|
|
|
if self
|
|
|
|
.skill_set
|
|
|
|
.has_skill(Skill::Hammer(HammerSkill::UnlockLeap))
|
2021-04-28 01:17:56 +00:00
|
|
|
&& agent.action_state.action_timer > 5.0
|
2021-02-07 07:22:06 +00:00
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2020-01-25 18:49:47 +00:00
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
2020-01-25 18:49:47 +00:00
|
|
|
}
|
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
if self.body.map(|b| b.is_humanoid()).unwrap_or(false)
|
|
|
|
&& dist_sqrd < 16.0f32.powi(2)
|
|
|
|
&& thread_rng().gen::<f32>() < 0.02
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Roll));
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
2020-01-25 18:49:47 +00:00
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
},
|
|
|
|
Tactic::Sword => {
|
2021-04-24 19:56:33 +00:00
|
|
|
if dist_sqrd < min_attack_dist.powi(2) && angle < 45.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
|
|
|
if self
|
|
|
|
.skill_set
|
|
|
|
.has_skill(Skill::Sword(SwordSkill::UnlockSpin))
|
2021-04-28 01:17:56 +00:00
|
|
|
&& agent.action_state.action_timer < 2.0
|
2021-02-07 07:22:06 +00:00
|
|
|
&& self.energy.current() > 600
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
|
|
|
} else if agent.action_state.action_timer > 2.0 {
|
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer > 4.0 && angle < 45.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
2020-11-25 22:47:16 +00:00
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
if self.body.map(|b| b.is_humanoid()).unwrap_or(false)
|
|
|
|
&& dist_sqrd < 16.0f32.powi(2)
|
|
|
|
&& thread_rng().gen::<f32>() < 0.02
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Roll));
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::Bow => {
|
2021-04-19 19:13:43 +00:00
|
|
|
if dist_sqrd < (2.0 * min_attack_dist).powi(2) {
|
|
|
|
if self.body.map(|b| b.is_humanoid()).unwrap_or(false)
|
|
|
|
&& self.energy.current()
|
|
|
|
> CharacterAbility::default_roll().get_energy_cost()
|
|
|
|
{
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Roll));
|
|
|
|
} else {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
// Away from the target (ironically)
|
|
|
|
self.pos.0
|
|
|
|
+ (self.pos.0 - tgt_pos.0)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec3::unit_y)
|
|
|
|
* 50.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
2021-04-24 19:56:33 +00:00
|
|
|
if angle < 15.0 {
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
|
|
|
}
|
2021-04-19 19:13:43 +00:00
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
2021-04-24 19:56:33 +00:00
|
|
|
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 45.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = bearing
|
|
|
|
.xy()
|
|
|
|
.rotated_z(thread_rng().gen_range(0.5..1.57))
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::zero)
|
|
|
|
* speed;
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer > 4.0 {
|
2021-03-13 00:38:20 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::CancelInput(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
|
|
|
} else if agent.action_state.action_timer > 2.0
|
|
|
|
&& self.energy.current() > 300
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else if self
|
|
|
|
.skill_set
|
|
|
|
.has_skill(Skill::Bow(BowSkill::UnlockRepeater))
|
|
|
|
&& self.energy.current() > 400
|
|
|
|
&& thread_rng().gen_bool(0.8)
|
2020-11-25 22:47:16 +00:00
|
|
|
{
|
2021-03-13 00:38:20 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::CancelInput(InputKind::Secondary));
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-03-13 00:38:20 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::CancelInput(InputKind::Secondary));
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2020-01-25 18:49:47 +00:00
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
2020-01-25 18:49:47 +00:00
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
if self.body.map(|b| b.is_humanoid()).unwrap_or(false)
|
|
|
|
&& dist_sqrd < 16.0f32.powi(2)
|
|
|
|
&& thread_rng().gen::<f32>() < 0.02
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Roll));
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
2020-11-25 22:47:16 +00:00
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
},
|
|
|
|
Tactic::Staff => {
|
|
|
|
if self.body.map(|b| b.is_humanoid()).unwrap_or(false)
|
2021-03-23 22:41:17 +00:00
|
|
|
&& dist_sqrd < min_attack_dist.powi(2)
|
2021-02-07 07:22:06 +00:00
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Roll));
|
2021-04-24 19:56:33 +00:00
|
|
|
} else if dist_sqrd < (5.0 * min_attack_dist).powi(2) && angle < 15.0 {
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer < 1.5 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
|
|
|
|
.xy()
|
|
|
|
.rotated_z(0.47 * PI)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::unit_y);
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
|
|
|
} else if agent.action_state.action_timer < 3.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
|
|
|
|
.xy()
|
|
|
|
.rotated_z(-0.47 * PI)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::unit_y);
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
if self
|
|
|
|
.skill_set
|
|
|
|
.has_skill(Skill::Staff(StaffSkill::UnlockShockwave))
|
|
|
|
&& self.energy.current() > 800
|
|
|
|
&& thread_rng().gen::<f32>() > 0.8
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
2021-02-07 07:22:06 +00:00
|
|
|
} else if self.energy.current() > 10 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
2021-04-24 19:56:33 +00:00
|
|
|
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = bearing
|
|
|
|
.xy()
|
|
|
|
.rotated_z(thread_rng().gen_range(-1.57..-0.5))
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::zero)
|
|
|
|
* speed;
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
if self.body.map(|b| b.is_humanoid()).unwrap_or(false)
|
|
|
|
&& dist_sqrd < 16.0f32.powi(2)
|
|
|
|
&& thread_rng().gen::<f32>() < 0.02
|
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Roll));
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
2021-04-30 19:25:08 +00:00
|
|
|
Tactic::StoneGolem => {
|
2021-04-28 02:31:51 +00:00
|
|
|
if dist_sqrd < min_attack_dist.powi(2) && angle < 90.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
// 2.0 is temporary correction factor to allow them to melee with their
|
|
|
|
// large hitbox
|
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-03-05 06:09:56 +00:00
|
|
|
//controller.inputs.primary.set_state(true);
|
2021-02-07 07:22:06 +00:00
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if self.vel.0.is_approx_zero() {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
2021-04-28 02:31:51 +00:00
|
|
|
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 90.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer > 5.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::CircleCharge {
|
|
|
|
radius,
|
|
|
|
circle_time,
|
|
|
|
} => {
|
2021-04-28 02:31:51 +00:00
|
|
|
if dist_sqrd < min_attack_dist.powi(2) && thread_rng().gen_bool(0.5) {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-03-23 22:41:17 +00:00
|
|
|
} else if dist_sqrd < (radius as f32 * min_attack_dist).powi(2) {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = (self.pos.0 - tgt_pos.0)
|
|
|
|
.xy()
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::unit_y);
|
2021-03-23 22:41:17 +00:00
|
|
|
} else if dist_sqrd < ((radius as f32 + 1.0) * min_attack_dist).powi(2)
|
|
|
|
&& dist_sqrd > (radius as f32 * min_attack_dist).powi(2)
|
2021-02-07 07:22:06 +00:00
|
|
|
{
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer < circle_time as f32 {
|
2021-04-27 17:57:31 +00:00
|
|
|
let move_dir = (tgt_pos.0 - self.pos.0)
|
2021-02-07 07:22:06 +00:00
|
|
|
.xy()
|
|
|
|
.rotated_z(0.47 * PI)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::unit_y);
|
2021-04-27 17:57:31 +00:00
|
|
|
let obstacle_left = read_data
|
|
|
|
.terrain
|
|
|
|
.ray(
|
|
|
|
self.pos.0 + Vec3::unit_z(),
|
|
|
|
self.pos.0 + move_dir.with_z(0.0) * 2.0 + Vec3::unit_z(),
|
|
|
|
)
|
|
|
|
.until(Block::is_solid)
|
|
|
|
.cast()
|
|
|
|
.1
|
|
|
|
.map_or(true, |b| b.is_some());
|
|
|
|
if obstacle_left {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = circle_time as f32;
|
2021-04-27 17:57:31 +00:00
|
|
|
}
|
|
|
|
controller.inputs.move_dir = move_dir;
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
|
|
|
} else if agent.action_state.action_timer < circle_time as f32 + 0.5 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
|
|
|
} else if agent.action_state.action_timer < 2.0 * circle_time as f32 + 0.5 {
|
2021-04-27 17:57:31 +00:00
|
|
|
let move_dir = (tgt_pos.0 - self.pos.0)
|
2021-02-07 07:22:06 +00:00
|
|
|
.xy()
|
|
|
|
.rotated_z(-0.47 * PI)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::unit_y);
|
2021-04-27 17:57:31 +00:00
|
|
|
let obstacle_right = read_data
|
|
|
|
.terrain
|
|
|
|
.ray(
|
|
|
|
self.pos.0 + Vec3::unit_z(),
|
|
|
|
self.pos.0 + move_dir.with_z(0.0) * 2.0 + Vec3::unit_z(),
|
|
|
|
)
|
|
|
|
.until(Block::is_solid)
|
|
|
|
.cast()
|
|
|
|
.1
|
|
|
|
.map_or(true, |b| b.is_some());
|
|
|
|
if obstacle_right {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 2.0 * circle_time as f32 + 0.5;
|
2021-04-27 17:57:31 +00:00
|
|
|
}
|
|
|
|
controller.inputs.move_dir = move_dir;
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
|
|
|
} else if agent.action_state.action_timer < 2.0 * circle_time as f32 + 1.0 {
|
|
|
|
if agent.action_state.action_timer < 2.0 * circle_time as f32 {
|
|
|
|
agent.action_state.action_timer = 2.0 * circle_time as f32;
|
2021-04-27 17:57:31 +00:00
|
|
|
}
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::QuadLowRanged => {
|
2021-04-28 02:31:51 +00:00
|
|
|
if dist_sqrd < (3.0 * min_attack_dist).powi(2) && angle < 90.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
|
|
|
|
.xy()
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::unit_y);
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-02-07 07:22:06 +00:00
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
2021-04-24 19:56:33 +00:00
|
|
|
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer > 5.0 {
|
|
|
|
agent.action_state.action_timer = 0.0;
|
|
|
|
} else if agent.action_state.action_timer > 2.5 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
|
|
|
|
.xy()
|
|
|
|
.rotated_z(1.75 * PI)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::zero)
|
|
|
|
* speed;
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
|
|
|
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
|
|
|
|
.xy()
|
|
|
|
.rotated_z(0.25 * PI)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::zero)
|
|
|
|
* speed;
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
} else {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::TailSlap => {
|
2021-04-28 02:31:51 +00:00
|
|
|
if dist_sqrd < (1.5 * min_attack_dist).powi(2) && angle < 90.0 {
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer > 4.0 {
|
2021-03-12 04:53:25 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::CancelInput(InputKind::Primary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
|
|
|
} else if agent.action_state.action_timer > 1.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
|
|
|
|
.xy()
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::unit_y)
|
|
|
|
* 0.1;
|
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::QuadLowQuick => {
|
2021-04-28 02:31:51 +00:00
|
|
|
if dist_sqrd < (1.5 * min_attack_dist).powi(2) && angle < 90.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-03-23 22:41:17 +00:00
|
|
|
} else if dist_sqrd < (3.0 * min_attack_dist).powi(2)
|
|
|
|
&& dist_sqrd > (2.0 * min_attack_dist).powi(2)
|
2021-04-28 02:31:51 +00:00
|
|
|
&& angle < 90.0
|
2021-02-07 07:22:06 +00:00
|
|
|
{
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
|
|
|
|
.xy()
|
|
|
|
.rotated_z(-0.47 * PI)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::unit_y);
|
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::QuadLowBasic => {
|
2021-03-23 22:41:17 +00:00
|
|
|
if dist_sqrd < (1.5 * min_attack_dist).powi(2) {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer > 5.0 {
|
|
|
|
agent.action_state.action_timer = 0.0;
|
|
|
|
} else if agent.action_state.action_timer > 2.0 && angle < 90.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-04-28 02:31:51 +00:00
|
|
|
} else if angle < 90.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::QuadMedJump => {
|
2021-04-28 02:31:51 +00:00
|
|
|
if dist_sqrd < (1.5 * min_attack_dist).powi(2) && angle < 90.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-24 19:56:33 +00:00
|
|
|
} else if dist_sqrd < (5.0 * min_attack_dist).powi(2) && angle < 15.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
2021-02-07 07:22:06 +00:00
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
2021-04-24 19:56:33 +00:00
|
|
|
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
|
|
|
} else {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::QuadMedBasic => {
|
2021-04-28 02:31:51 +00:00
|
|
|
if dist_sqrd < min_attack_dist.powi(2) && angle < 90.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer < 2.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
|
|
|
} else if agent.action_state.action_timer < 3.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
2021-03-03 03:55:28 +00:00
|
|
|
Tactic::Lavadrake | Tactic::QuadLowBeam => {
|
2021-04-28 02:31:51 +00:00
|
|
|
if dist_sqrd < (2.5 * min_attack_dist).powi(2) && angle < 90.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-24 19:56:33 +00:00
|
|
|
} else if dist_sqrd < (7.0 * min_attack_dist).powi(2) && angle < 15.0 {
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_timer < 2.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
|
|
|
|
.xy()
|
|
|
|
.rotated_z(0.47 * PI)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::unit_y);
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
|
|
|
} else if agent.action_state.action_timer < 4.0 && angle < 15.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = (tgt_pos.0 - self.pos.0)
|
|
|
|
.xy()
|
|
|
|
.rotated_z(-0.47 * PI)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::unit_y);
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
|
|
|
} else if agent.action_state.action_timer < 6.0 && angle < 15.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::Theropod => {
|
2021-04-28 02:31:51 +00:00
|
|
|
if dist_sqrd < (2.0 * min_attack_dist).powi(2) && angle < 90.0 {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_dir = Vec2::zero();
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-02-07 07:22:06 +00:00
|
|
|
} else if dist_sqrd < MAX_CHASE_DIST.powi(2) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::Turret => {
|
2021-04-24 19:56:33 +00:00
|
|
|
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::FixedTurret => {
|
|
|
|
controller.inputs.look_dir = self.ori.look_dir();
|
2021-04-24 19:56:33 +00:00
|
|
|
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Tactic::RotatingTurret => {
|
|
|
|
controller.inputs.look_dir = Dir::new(
|
|
|
|
Quaternion::from_xyzw(self.ori.look_dir().x, self.ori.look_dir().y, 0.0, 0.0)
|
2021-03-03 03:55:28 +00:00
|
|
|
.rotated_z(6.0 * dt.0 as f32)
|
|
|
|
.into_vec3()
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_default(),
|
2021-02-07 07:22:06 +00:00
|
|
|
);
|
2021-04-24 19:56:33 +00:00
|
|
|
if can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd) && angle < 15.0 {
|
2021-03-21 16:09:16 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-03-21 17:45:01 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
}
|
|
|
|
},
|
2021-03-21 18:22:14 +00:00
|
|
|
Tactic::Mindflayer => {
|
2021-03-29 14:44:46 +00:00
|
|
|
const MINDFLAYER_ATTACK_DIST: f32 = 16.0;
|
2021-03-26 16:48:25 +00:00
|
|
|
const MINION_SUMMON_THRESHOLD: f32 = 0.20;
|
2021-03-23 15:02:15 +00:00
|
|
|
let health_fraction = self.health.map_or(0.5, |h| h.fraction());
|
2021-04-28 02:33:24 +00:00
|
|
|
// Sets action_float at start of combat
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_float < MINION_SUMMON_THRESHOLD
|
2021-03-26 16:48:25 +00:00
|
|
|
&& health_fraction > MINION_SUMMON_THRESHOLD
|
|
|
|
{
|
2021-04-28 02:33:24 +00:00
|
|
|
agent.action_state.action_float = 1.0 - MINION_SUMMON_THRESHOLD;
|
2021-03-24 17:09:06 +00:00
|
|
|
}
|
|
|
|
let mindflayer_is_far = dist_sqrd > MINDFLAYER_ATTACK_DIST.powi(2);
|
2021-04-28 01:17:56 +00:00
|
|
|
if agent.action_state.action_float > health_fraction {
|
2021-03-24 17:09:06 +00:00
|
|
|
// Summon minions at particular thresholds of health
|
2021-03-29 14:44:46 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(1)));
|
|
|
|
if matches!(self.char_state, CharacterState::BasicSummon(c) if matches!(c.stage_section, StageSection::Recover))
|
|
|
|
{
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_float -= MINION_SUMMON_THRESHOLD;
|
2021-03-21 18:22:14 +00:00
|
|
|
}
|
|
|
|
} else if mindflayer_is_far {
|
2021-03-23 15:02:15 +00:00
|
|
|
// If too far from target, blink to them.
|
2021-03-21 18:22:14 +00:00
|
|
|
controller.actions.push(ControlAction::StartInput {
|
|
|
|
input: InputKind::Ability(0),
|
|
|
|
target_entity: agent
|
|
|
|
.target
|
|
|
|
.as_ref()
|
|
|
|
.and_then(|t| read_data.uids.get(t.target))
|
|
|
|
.copied(),
|
|
|
|
select_pos: None,
|
|
|
|
});
|
|
|
|
} else {
|
2021-03-23 15:02:15 +00:00
|
|
|
// If close to target, use either primary or secondary ability
|
2021-03-29 14:44:46 +00:00
|
|
|
if matches!(self.char_state, CharacterState::BasicBeam(c) if c.timer < Duration::from_secs(10) && !matches!(c.stage_section, StageSection::Recover))
|
|
|
|
{
|
|
|
|
// If already using primary, keep using primary until 10 consecutive seconds
|
2021-03-23 15:02:15 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-03-29 14:44:46 +00:00
|
|
|
} else if matches!(self.char_state, CharacterState::SpinMelee(c) if c.consecutive_spins < 50 && !matches!(c.stage_section, StageSection::Recover))
|
|
|
|
{
|
|
|
|
// If already using secondary, keep using secondary until 10 consecutive
|
|
|
|
// seconds
|
2021-03-23 15:02:15 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 02:33:24 +00:00
|
|
|
} else if thread_rng().gen_bool(health_fraction.into()) {
|
2021-03-23 15:02:15 +00:00
|
|
|
// Else if at high health, use primary
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
|
|
|
} else {
|
|
|
|
// Else use secondary
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
|
|
|
}
|
2021-03-21 18:22:14 +00:00
|
|
|
}
|
2021-03-29 14:44:46 +00:00
|
|
|
|
|
|
|
// Move towards target
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
2021-03-21 18:22:14 +00:00
|
|
|
},
|
2021-04-20 22:36:40 +00:00
|
|
|
Tactic::BirdLargeFire => {
|
2021-04-22 03:55:02 +00:00
|
|
|
if dist_sqrd > 30.0_f32.powi(2) {
|
2021-04-22 23:34:37 +00:00
|
|
|
// If random chance and can see target
|
2021-04-22 03:55:02 +00:00
|
|
|
if thread_rng().gen_bool(0.05)
|
|
|
|
&& can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd)
|
2021-04-26 02:19:30 +00:00
|
|
|
&& angle < 15.0
|
2021-04-22 03:55:02 +00:00
|
|
|
{
|
2021-04-22 23:34:37 +00:00
|
|
|
// Fireball
|
2021-04-22 03:55:02 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-04-22 23:34:37 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-22 03:55:02 +00:00
|
|
|
}
|
2021-04-22 23:34:37 +00:00
|
|
|
// If some target
|
2021-04-22 03:55:02 +00:00
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
2021-04-22 23:34:37 +00:00
|
|
|
// Walk to target
|
2021-04-22 03:55:02 +00:00
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
2021-04-22 23:34:37 +00:00
|
|
|
// If less than 20 blocks higher than target
|
2021-04-22 03:55:02 +00:00
|
|
|
if (self.pos.0.z - tgt_pos.0.z) < 20.0 {
|
2021-04-22 23:34:37 +00:00
|
|
|
// Fly upward
|
2021-04-20 22:36:40 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Fly));
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Jump));
|
2021-04-22 03:55:02 +00:00
|
|
|
controller.inputs.move_z = 1.0;
|
|
|
|
} else {
|
2021-04-22 23:34:37 +00:00
|
|
|
// Jump
|
2021-04-22 03:55:02 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
|
|
|
controller.inputs.move_z = bearing.z;
|
2021-04-20 22:36:40 +00:00
|
|
|
}
|
2021-04-22 03:55:02 +00:00
|
|
|
}
|
2021-04-22 23:34:37 +00:00
|
|
|
}
|
|
|
|
// If higher than 2 blocks
|
|
|
|
else if !read_data
|
|
|
|
.terrain
|
|
|
|
.ray(self.pos.0, self.pos.0 - (Vec3::unit_z() * 2.0))
|
|
|
|
.until(Block::is_solid)
|
|
|
|
.cast()
|
|
|
|
.1
|
|
|
|
.map_or(true, |b| b.is_some())
|
|
|
|
{
|
2021-04-22 03:55:02 +00:00
|
|
|
// Do not increment the timer during this movement
|
|
|
|
// The next stage shouldn't trigger until the entity
|
|
|
|
// is on the ground
|
2021-04-22 23:34:37 +00:00
|
|
|
// Fly to target
|
2021-04-22 03:55:02 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Fly));
|
|
|
|
let move_dir = tgt_pos.0 - self.pos.0;
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0;
|
|
|
|
controller.inputs.move_z = move_dir.z - 0.5;
|
2021-04-22 23:34:37 +00:00
|
|
|
// If further than 4 blocks and random chance
|
2021-04-26 02:19:30 +00:00
|
|
|
if thread_rng().gen_bool(0.05)
|
|
|
|
&& dist_sqrd > (4.0 * min_attack_dist).powi(2)
|
|
|
|
&& angle < 15.0
|
|
|
|
{
|
2021-04-22 23:34:37 +00:00
|
|
|
// Fireball
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-20 22:36:40 +00:00
|
|
|
}
|
2021-04-22 03:55:02 +00:00
|
|
|
}
|
2021-04-22 23:34:37 +00:00
|
|
|
// If further than 4 blocks and random chance
|
2021-04-26 02:19:30 +00:00
|
|
|
else if thread_rng().gen_bool(0.05)
|
|
|
|
&& dist_sqrd > (4.0 * min_attack_dist).powi(2)
|
|
|
|
&& angle < 15.0
|
2021-04-22 23:34:37 +00:00
|
|
|
{
|
|
|
|
// Fireball
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
|
|
|
}
|
|
|
|
// If random chance and less than 20 blocks higher than target and further than 4
|
|
|
|
// blocks
|
|
|
|
else if thread_rng().gen_bool(0.5)
|
|
|
|
&& (self.pos.0.z - tgt_pos.0.z) < 15.0
|
|
|
|
&& dist_sqrd > (4.0 * min_attack_dist).powi(2)
|
|
|
|
{
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Fly));
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Jump));
|
|
|
|
controller.inputs.move_z = 1.0;
|
|
|
|
}
|
|
|
|
// If further than 2.5 blocks and random chance
|
|
|
|
else if dist_sqrd > (2.5 * min_attack_dist).powi(2) {
|
|
|
|
// If some target
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
// Walk to target
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
2021-04-22 03:55:02 +00:00
|
|
|
}
|
2021-04-22 23:34:37 +00:00
|
|
|
// If energy higher than 600 and random chance
|
|
|
|
else if self.energy.current() > 600 && thread_rng().gen_bool(0.4) {
|
|
|
|
// Shockwave
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
2021-04-28 02:31:51 +00:00
|
|
|
} else if angle < 90.0 {
|
2021-04-22 23:34:37 +00:00
|
|
|
// Triple strike
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
|
|
|
}
|
|
|
|
},
|
|
|
|
// Mostly identical to BirdLargeFire but tweaked for flamethrower instead of shockwave
|
|
|
|
Tactic::BirdLargeBreathe => {
|
|
|
|
// Set fly to false
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::CancelInput(InputKind::Fly));
|
|
|
|
if dist_sqrd > 30.0_f32.powi(2) {
|
|
|
|
if thread_rng().gen_bool(0.05)
|
|
|
|
&& can_see_tgt(&*terrain, self.pos, tgt_pos, dist_sqrd)
|
2021-04-26 02:19:30 +00:00
|
|
|
&& angle < 15.0
|
2021-04-20 22:36:40 +00:00
|
|
|
{
|
2021-04-22 23:34:37 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
2021-04-20 22:36:40 +00:00
|
|
|
}
|
2021-04-22 23:34:37 +00:00
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
|
|
|
if (self.pos.0.z - tgt_pos.0.z) < 20.0 {
|
2021-04-20 22:36:40 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-04-22 23:34:37 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Fly));
|
2021-04-20 22:36:40 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-04-22 23:34:37 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Jump));
|
|
|
|
controller.inputs.move_z = 1.0;
|
2021-04-20 22:36:40 +00:00
|
|
|
} else {
|
2021-04-22 23:34:37 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
|
|
|
controller.inputs.move_z = bearing.z;
|
2021-04-20 22:36:40 +00:00
|
|
|
}
|
|
|
|
}
|
2021-04-22 23:34:37 +00:00
|
|
|
} else if !read_data
|
|
|
|
.terrain
|
|
|
|
.ray(self.pos.0, self.pos.0 - (Vec3::unit_z() * 2.0))
|
|
|
|
.until(Block::is_solid)
|
|
|
|
.cast()
|
|
|
|
.1
|
|
|
|
.map_or(true, |b| b.is_some())
|
|
|
|
{
|
|
|
|
// Do not increment the timer during this movement
|
|
|
|
// The next stage shouldn't trigger until the entity
|
|
|
|
// is on the ground
|
2021-04-20 22:36:40 +00:00
|
|
|
controller
|
|
|
|
.actions
|
2021-04-22 23:34:37 +00:00
|
|
|
.push(ControlAction::basic_input(InputKind::Fly));
|
|
|
|
let move_dir = tgt_pos.0 - self.pos.0;
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
move_dir.xy().try_normalized().unwrap_or_else(Vec2::zero) * 2.0;
|
|
|
|
controller.inputs.move_z = move_dir.z - 0.5;
|
2021-04-26 02:19:30 +00:00
|
|
|
if thread_rng().gen_bool(0.05)
|
|
|
|
&& dist_sqrd > (4.0 * min_attack_dist).powi(2)
|
|
|
|
&& angle < 15.0
|
|
|
|
{
|
2021-04-20 22:36:40 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
|
|
|
}
|
2021-04-26 02:19:30 +00:00
|
|
|
} else if thread_rng().gen_bool(0.05)
|
|
|
|
&& dist_sqrd > (4.0 * min_attack_dist).powi(2)
|
|
|
|
&& angle < 15.0
|
2021-04-22 23:34:37 +00:00
|
|
|
{
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
|
|
|
} else if thread_rng().gen_bool(0.5)
|
|
|
|
&& (self.pos.0.z - tgt_pos.0.z) < 15.0
|
|
|
|
&& dist_sqrd > (4.0 * min_attack_dist).powi(2)
|
|
|
|
{
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Fly));
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Jump));
|
|
|
|
controller.inputs.move_z = 1.0;
|
|
|
|
} else if dist_sqrd > (3.0 * min_attack_dist).powi(2) {
|
2021-04-20 22:36:40 +00:00
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
2021-04-28 01:17:56 +00:00
|
|
|
} else if self.energy.current() > 600
|
|
|
|
&& agent.action_state.action_timer < 3.0
|
|
|
|
&& angle < 15.0
|
|
|
|
{
|
2021-04-22 23:34:37 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
|
|
|
} else if agent.action_state.action_timer < 6.0 && angle < 90.0 {
|
2021-04-22 23:34:37 +00:00
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer += dt.0;
|
2021-04-20 22:36:40 +00:00
|
|
|
} else {
|
2021-04-28 01:17:56 +00:00
|
|
|
agent.action_state.action_timer = 0.0;
|
2021-04-20 22:36:40 +00:00
|
|
|
}
|
|
|
|
},
|
2021-04-28 02:33:24 +00:00
|
|
|
Tactic::Minotaur => {
|
|
|
|
const MINOTAUR_FRENZY_THRESHOLD: f32 = 0.5;
|
|
|
|
const MINOTAUR_ATTACK_RANGE: f32 = 5.0;
|
|
|
|
const MINOTAUR_CHARGE_DISTANCE: f32 = 15.0;
|
|
|
|
let minotaur_attack_distance =
|
|
|
|
self.body.map_or(0.0, |b| b.radius()) + MINOTAUR_ATTACK_RANGE;
|
|
|
|
let health_fraction = self.health.map_or(1.0, |h| h.fraction());
|
|
|
|
// Sets action float at start of combat
|
|
|
|
if agent.action_state.action_float < MINOTAUR_FRENZY_THRESHOLD
|
|
|
|
&& health_fraction > MINOTAUR_FRENZY_THRESHOLD
|
|
|
|
{
|
|
|
|
agent.action_state.action_float = MINOTAUR_FRENZY_THRESHOLD;
|
|
|
|
}
|
|
|
|
if health_fraction < agent.action_state.action_float {
|
|
|
|
// Makes minotaur buff itself with frenzy
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(1)));
|
|
|
|
if matches!(self.char_state, CharacterState::SelfBuff(c) if matches!(c.stage_section, StageSection::Recover))
|
|
|
|
{
|
|
|
|
agent.action_state.action_float = 0.0;
|
|
|
|
}
|
|
|
|
} else if matches!(self.char_state, CharacterState::DashMelee(c) if !matches!(c.stage_section, StageSection::Recover))
|
|
|
|
{
|
|
|
|
// If already charging, keep charging if not in recover
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
|
|
|
} else if matches!(self.char_state, CharacterState::ChargedMelee(c) if matches!(c.stage_section, StageSection::Charge) && c.timer < c.static_data.charge_duration)
|
|
|
|
{
|
|
|
|
// If already charging a melee attack, keep charging it if charging
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
|
|
|
} else if dist_sqrd > MINOTAUR_CHARGE_DISTANCE.powi(2) {
|
|
|
|
// Charges at target if they are far enough away
|
|
|
|
if angle < 60.0 {
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Ability(0)));
|
|
|
|
}
|
|
|
|
} else if dist_sqrd < minotaur_attack_distance.powi(2) {
|
|
|
|
if agent.action_state.action_bool && !self.char_state.is_attack() {
|
|
|
|
// Cripple target if not just used cripple
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Secondary));
|
|
|
|
agent.action_state.action_bool = false;
|
|
|
|
} else if !self.char_state.is_attack() {
|
|
|
|
// Cleave target if not just used cleave
|
|
|
|
controller
|
|
|
|
.actions
|
|
|
|
.push(ControlAction::basic_input(InputKind::Primary));
|
|
|
|
agent.action_state.action_bool = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Make minotaur move towards target
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed;
|
|
|
|
}
|
|
|
|
},
|
2020-08-07 01:59:28 +00:00
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
2021-02-06 06:15:25 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
fn follow(
|
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
terrain: &TerrainGrid,
|
|
|
|
tgt_pos: &Pos,
|
|
|
|
) {
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
tgt_pos.0,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: AVG_FOLLOW_DIST,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
let dist_sqrd = self.pos.0.distance_squared(tgt_pos.0);
|
|
|
|
controller.inputs.move_dir = bearing.xy().try_normalized().unwrap_or_else(Vec2::zero)
|
|
|
|
* speed.min(0.2 + (dist_sqrd - AVG_FOLLOW_DIST.powi(2)) / 8.0);
|
2021-03-18 22:54:23 +00:00
|
|
|
self.jump_if(controller, bearing.z > 1.5);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
2019-04-16 21:06:33 +00:00
|
|
|
}
|
|
|
|
}
|
2020-11-23 19:27:18 +00:00
|
|
|
|
|
|
|
fn can_see_tgt(terrain: &TerrainGrid, pos: &Pos, tgt_pos: &Pos, dist_sqrd: f32) -> bool {
|
|
|
|
terrain
|
|
|
|
.ray(pos.0 + Vec3::unit_z(), tgt_pos.0 + Vec3::unit_z())
|
|
|
|
.until(Block::is_opaque)
|
|
|
|
.cast()
|
|
|
|
.0
|
2020-11-25 00:28:24 +00:00
|
|
|
.powi(2)
|
2020-11-23 19:27:18 +00:00
|
|
|
>= dist_sqrd
|
|
|
|
}
|
2021-03-16 19:17:08 +00:00
|
|
|
|
|
|
|
// If target is dead or has invulnerability buff, returns true
|
|
|
|
fn should_stop_attacking(health: Option<&Health>, buffs: Option<&Buffs>) -> bool {
|
2021-04-25 21:24:06 +00:00
|
|
|
health.map_or(true, |a| a.is_dead) || invulnerability_is_in_buffs(buffs)
|
|
|
|
}
|
|
|
|
|
|
|
|
fn invulnerability_is_in_buffs(buffs: Option<&Buffs>) -> bool {
|
|
|
|
buffs.map_or(false, |b| b.kinds.contains_key(&BuffKind::Invulnerability))
|
2021-03-16 19:17:08 +00:00
|
|
|
}
|
2021-03-23 22:41:17 +00:00
|
|
|
|
|
|
|
/// Attempts to get alignment of owner if entity has Owned alignment
|
|
|
|
fn try_owner_alignment<'a>(
|
|
|
|
alignment: Option<&'a Alignment>,
|
|
|
|
read_data: &'a ReadData,
|
|
|
|
) -> Option<&'a Alignment> {
|
|
|
|
if let Some(Alignment::Owned(owner_uid)) = alignment {
|
|
|
|
if let Some(owner) = read_data
|
|
|
|
.uid_allocator
|
|
|
|
.retrieve_entity_internal(owner_uid.id())
|
|
|
|
{
|
|
|
|
return read_data.alignments.get(owner);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
alignment
|
|
|
|
}
|
2021-03-23 09:51:53 +00:00
|
|
|
|
|
|
|
/// Projectile motion: Returns the direction to aim for the projectile to reach
|
|
|
|
/// target position. Does not take any forces but gravity into account.
|
|
|
|
fn aim_projectile(speed: f32, pos: Vec3<f32>, tgt: Vec3<f32>) -> Option<Dir> {
|
|
|
|
let mut to_tgt = tgt - pos;
|
|
|
|
let dist_sqrd = to_tgt.xy().magnitude_squared();
|
|
|
|
let u_sqrd = speed.powi(2);
|
|
|
|
to_tgt.z = (u_sqrd
|
|
|
|
- (u_sqrd.powi(2) - GRAVITY * (GRAVITY * dist_sqrd + 2.0 * to_tgt.z * u_sqrd))
|
|
|
|
.sqrt()
|
|
|
|
.max(0.0))
|
|
|
|
/ GRAVITY;
|
|
|
|
|
|
|
|
Dir::from_unnormalized(to_tgt)
|
|
|
|
}
|