2022-01-18 03:02:43 +00:00
|
|
|
pub mod attack;
|
|
|
|
pub mod consts;
|
|
|
|
pub mod data;
|
|
|
|
pub mod util;
|
|
|
|
|
|
|
|
use crate::{
|
2022-03-07 23:03:18 +00:00
|
|
|
rtsim::{entity::PersonalityTrait, RtSim},
|
2022-01-18 03:02:43 +00:00
|
|
|
sys::agent::{
|
|
|
|
consts::{
|
2022-03-09 17:31:35 +00:00
|
|
|
AVG_FOLLOW_DIST, DAMAGE_MEMORY_DURATION, DEFAULT_ATTACK_RANGE, FLEE_DURATION,
|
|
|
|
HEALING_ITEM_THRESHOLD, IDLE_HEALING_ITEM_THRESHOLD, MAX_FLEE_DIST, MAX_FOLLOW_DIST,
|
|
|
|
PARTIAL_PATH_DIST, RETARGETING_THRESHOLD_SECONDS, SEPARATION_BIAS, SEPARATION_DIST,
|
2022-01-18 03:02:43 +00:00
|
|
|
},
|
2022-02-25 20:35:35 +00:00
|
|
|
data::{AgentData, AttackData, Path, ReadData, Tactic, TargetData},
|
2022-01-18 03:02:43 +00:00
|
|
|
util::{
|
2022-04-28 00:29:10 +00:00
|
|
|
aim_projectile, are_our_owners_hostile, entities_have_line_of_sight, get_attacker,
|
|
|
|
get_entity_by_id, is_dead, is_dead_or_invulnerable, is_dressed_as_cultist,
|
|
|
|
is_invulnerable, is_village_guard, is_villager, stop_pursuing,
|
2022-01-18 03:02:43 +00:00
|
|
|
},
|
|
|
|
},
|
|
|
|
};
|
2020-12-01 00:28:00 +00:00
|
|
|
use common::{
|
2022-04-28 00:29:10 +00:00
|
|
|
combat::compute_stealth_coefficient,
|
2020-04-18 18:28:19 +00:00
|
|
|
comp::{
|
|
|
|
self,
|
2021-05-15 19:36:27 +00:00
|
|
|
agent::{
|
2021-08-04 13:04:56 +00:00
|
|
|
AgentEvent, Sound, SoundKind, Target, TimerAction, DEFAULT_INTERACTION_TIME,
|
|
|
|
TRADE_INTERACTION_TIME,
|
2021-05-15 19:36:27 +00:00
|
|
|
},
|
2022-01-18 03:02:43 +00:00
|
|
|
buff::BuffKind,
|
2021-03-29 14:47:42 +00:00
|
|
|
compass::{Direction, Distance},
|
|
|
|
dialogue::{MoodContext, MoodState, Subject},
|
2022-03-30 00:04:20 +00:00
|
|
|
inventory::slot::EquipSlot,
|
2021-03-29 14:47:42 +00:00
|
|
|
invite::{InviteKind, InviteResponse},
|
2020-11-06 17:39:49 +00:00
|
|
|
item::{
|
2021-08-02 23:22:22 +00:00
|
|
|
tool::{AbilitySpec, ToolKind},
|
2021-07-14 15:26:29 +00:00
|
|
|
ConsumableKind, Item, ItemDesc, ItemKind,
|
2020-11-06 17:39:49 +00:00
|
|
|
},
|
2021-10-27 18:01:21 +00:00
|
|
|
projectile::ProjectileConstructor,
|
2022-01-18 03:02:43 +00:00
|
|
|
Agent, Alignment, BehaviorState, Body, CharacterState, ControlAction, ControlEvent,
|
2022-03-30 00:04:20 +00:00
|
|
|
Controller, Health, HealthChange, InputKind, InventoryAction, Pos, Scale,
|
2022-01-18 03:02:43 +00:00
|
|
|
UnresolvedChatMsg, UtteranceKind,
|
2020-04-18 18:28:19 +00:00
|
|
|
},
|
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,
|
2022-01-18 03:02:43 +00:00
|
|
|
rtsim::{Memory, MemoryItem, RtSimEvent},
|
|
|
|
states::basic_beam,
|
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-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},
|
2022-05-09 19:58:13 +00:00
|
|
|
Entity as EcsEntity, Join, ParJoin, Read, WriteExpect, WriteStorage,
|
2020-01-24 21:24:57 +00:00
|
|
|
};
|
2019-04-16 21:06:33 +00:00
|
|
|
use vek::*;
|
|
|
|
|
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 {
|
2019-04-16 21:06:33 +00:00
|
|
|
type SystemData = (
|
2021-02-07 07:22:06 +00:00
|
|
|
ReadData<'a>,
|
2022-05-09 19:58:13 +00:00
|
|
|
Read<'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;
|
|
|
|
|
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);
|
2021-07-12 15:40:29 +00:00
|
|
|
|
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-11-12 03:37:37 +00:00
|
|
|
(
|
|
|
|
&read_data.char_states,
|
|
|
|
&read_data.skill_set,
|
|
|
|
&read_data.active_abilities,
|
|
|
|
),
|
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(),
|
2022-01-15 18:22:28 +00:00
|
|
|
!&read_data.is_mounts,
|
2019-09-09 19:11:40 +00:00
|
|
|
)
|
2020-11-25 22:47:16 +00:00
|
|
|
.par_join()
|
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-11-12 03:37:37 +00:00
|
|
|
(char_state, skill_set, active_abilities),
|
2021-02-07 07:22:06 +00:00
|
|
|
physics_state,
|
|
|
|
uid,
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
light_emitter,
|
2021-07-12 15:40:29 +00:00
|
|
|
group,
|
2021-02-07 07:22:06 +00:00
|
|
|
_,
|
|
|
|
)| {
|
2022-01-18 03:02:43 +00:00
|
|
|
let mut event_emitter = event_bus.emitter();
|
|
|
|
let mut rng = thread_rng();
|
|
|
|
|
2021-07-12 15:40:29 +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!(
|
2021-02-07 07:22:06 +00:00
|
|
|
&read_data.alignments.get(entity),
|
|
|
|
&Some(Alignment::Owned(_))
|
|
|
|
) {
|
2021-07-12 15:40:29 +00:00
|
|
|
read_data.alignments.get(entity).copied()
|
|
|
|
} else {
|
|
|
|
group
|
2021-02-07 07:22:06 +00:00
|
|
|
.and_then(|g| read_data.group_manager.group_info(*g))
|
|
|
|
.and_then(|info| read_data.uids.get(info.leader))
|
|
|
|
.copied()
|
2021-07-12 15:40:29 +00:00
|
|
|
.map_or_else(
|
|
|
|
|| read_data.alignments.get(entity).copied(),
|
|
|
|
|uid| Some(Alignment::Owned(uid)),
|
|
|
|
)
|
2021-02-07 07:22:06 +00:00
|
|
|
};
|
2019-09-09 19:11:40 +00:00
|
|
|
|
2021-07-14 01:40:56 +00:00
|
|
|
if !matches!(char_state, CharacterState::LeapMelee(_)) {
|
2021-07-14 10:22:47 +00:00
|
|
|
// Default to looking in orientation direction
|
|
|
|
// (can be overridden below)
|
|
|
|
//
|
|
|
|
// This definetly breaks LeapMelee and
|
2021-07-14 19:04:42 +00:00
|
|
|
// probably not only that, do we really need this at all?
|
2021-07-14 01:40:56 +00:00
|
|
|
controller.reset();
|
|
|
|
controller.inputs.look_dir = ori.look_dir();
|
|
|
|
}
|
2021-02-22 00:57:25 +00:00
|
|
|
|
2021-07-12 15:40:29 +00:00
|
|
|
let scale = read_data.scales.get(entity).map_or(1.0, |Scale(s)| *s);
|
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(_))
|
|
|
|
});
|
2021-07-12 15:40:29 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
let is_gliding = matches!(
|
|
|
|
read_data.char_states.get(entity),
|
2021-08-01 11:20:46 +00:00
|
|
|
Some(CharacterState::GlideWield(_) | CharacterState::Glide(_))
|
2021-06-20 03:51:04 +00:00
|
|
|
) && physics_state.on_ground.is_none();
|
2020-11-12 21:31:28 +00:00
|
|
|
|
2021-05-30 15:38:47 +00:00
|
|
|
if let Some(pid) = agent.position_pid_controller.as_mut() {
|
2021-05-29 18:45:46 +00:00
|
|
|
pid.add_measurement(read_data.time.0, pos.0);
|
|
|
|
}
|
|
|
|
|
2021-07-12 15:40:29 +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
|
2021-02-07 07:22:06 +00:00
|
|
|
// obstacles that smaller entities would not).
|
|
|
|
let node_tolerance = scale * 1.5;
|
2021-07-12 15:40:29 +00:00
|
|
|
let slow_factor = body.map_or(0.0, |b| b.base_accel() / 250.0).min(1.0);
|
2021-02-07 07:22:06 +00:00
|
|
|
let traversal_config = TraversalConfig {
|
|
|
|
node_tolerance,
|
|
|
|
slow_factor,
|
2021-06-20 03:51:04 +00:00
|
|
|
on_ground: physics_state.on_ground.is_some(),
|
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,
|
2021-07-12 15:40:29 +00:00
|
|
|
can_climb: body.map_or(false, Body::can_climb),
|
|
|
|
can_fly: body.map_or(false, |b| b.fly_thrust().is_some()),
|
2021-02-07 07:22:06 +00:00
|
|
|
};
|
2021-07-12 15:40:29 +00:00
|
|
|
let health_fraction = health.map_or(1.0, Health::fraction);
|
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-07-14 19:04:42 +00:00
|
|
|
if traversal_config.can_fly && matches!(body, Some(Body::Ship(_))) {
|
|
|
|
// hack (kinda): Never turn off flight airships
|
2021-07-12 15:40:29 +00:00
|
|
|
// since it results in stuttering and falling back to the ground.
|
2021-07-14 19:04:42 +00:00
|
|
|
//
|
|
|
|
// TODO: look into `controller.reset()` line above
|
|
|
|
// and see if it fixes it
|
2022-01-26 19:09:59 +00:00
|
|
|
controller.push_basic_input(InputKind::Fly);
|
2021-04-28 02:31:51 +00:00
|
|
|
}
|
|
|
|
|
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,
|
2021-07-12 15:40:29 +00:00
|
|
|
damage: health_fraction,
|
2021-02-07 07:22:06 +00:00
|
|
|
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-11-12 03:37:37 +00:00
|
|
|
active_abilities,
|
2021-04-21 17:10:13 +00:00
|
|
|
cached_spatial_grid: &read_data.cached_spatial_grid,
|
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-07-22 14:02:43 +00:00
|
|
|
// Falling damage starts from 30.0 as of time of writing
|
|
|
|
// But keep in mind our 25 m/s gravity
|
|
|
|
let is_falling_dangerous = data.vel.0.z < -20.0;
|
|
|
|
|
2022-02-15 08:28:37 +00:00
|
|
|
let is_on_fire = read_data
|
|
|
|
.buffs
|
|
|
|
.get(entity)
|
|
|
|
.map_or(false, |b| b.kinds.contains_key(&BuffKind::Burning));
|
|
|
|
|
2021-07-22 14:02:43 +00:00
|
|
|
// If falling velocity is critical, throw everything
|
|
|
|
// and save yourself!
|
|
|
|
//
|
|
|
|
// If can fly - fly.
|
|
|
|
// If have glider - glide.
|
|
|
|
// Else, rest in peace.
|
|
|
|
if is_falling_dangerous && data.traversal_config.can_fly {
|
|
|
|
data.fly_upward(controller)
|
|
|
|
} else if is_falling_dangerous && data.glider_equipped {
|
2021-07-13 20:54:16 +00:00
|
|
|
data.glider_fall(controller);
|
2022-02-15 08:28:37 +00:00
|
|
|
// If on fire and able, stop, drop, and roll
|
|
|
|
} else if is_on_fire
|
|
|
|
&& data.body.map_or(false, |b| b.is_humanoid())
|
|
|
|
&& data.physics_state.on_ground.is_some()
|
|
|
|
&& rng.gen_bool((2.0 * read_data.dt.0).into())
|
|
|
|
{
|
|
|
|
controller.inputs.move_dir = ori
|
|
|
|
.look_vec()
|
|
|
|
.xy()
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec2::zero);
|
|
|
|
controller.push_basic_input(InputKind::Roll);
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2022-04-05 02:07:23 +00:00
|
|
|
// Target an entity that's attacking us if the attack was recent and we have
|
|
|
|
// a health component
|
2021-03-22 17:37:15 +00:00
|
|
|
match health {
|
2021-11-13 20:46:45 +00:00
|
|
|
Some(health)
|
|
|
|
if read_data.time.0 - health.last_change.time.0
|
|
|
|
< DAMAGE_MEMORY_DURATION =>
|
|
|
|
{
|
|
|
|
if let Some(by) = health.last_change.damage_by() {
|
2021-07-31 19:33:28 +00:00
|
|
|
if let Some(attacker) =
|
2021-11-13 20:46:45 +00:00
|
|
|
read_data.uid_allocator.retrieve_entity_internal(by.uid().0)
|
2021-07-31 19:33:28 +00:00
|
|
|
{
|
2021-10-22 22:11:09 +00:00
|
|
|
// If target is dead or invulnerable (for now, this only
|
|
|
|
// means safezone), untarget them and idle.
|
|
|
|
if is_dead_or_invulnerable(attacker, &read_data) {
|
2021-07-31 19:33:28 +00:00
|
|
|
agent.target = None;
|
2022-04-05 02:07:23 +00:00
|
|
|
} else {
|
2021-07-31 19:33:28 +00:00
|
|
|
if agent.target.is_none() {
|
|
|
|
controller.push_event(ControlEvent::Utterance(
|
|
|
|
UtteranceKind::Angry,
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
// Determine whether the new target should be a priority
|
2021-10-22 22:11:09 +00:00
|
|
|
// over the old one (i.e: because it's either close or
|
2022-04-05 02:07:23 +00:00
|
|
|
// because they attacked us).
|
|
|
|
if agent.target.map_or(true, |target| {
|
2022-04-26 18:22:55 +00:00
|
|
|
data.is_more_dangerous_than_target(
|
2022-04-05 02:07:23 +00:00
|
|
|
attacker, target, &read_data,
|
|
|
|
)
|
|
|
|
}) {
|
2021-07-31 19:33:28 +00:00
|
|
|
agent.target = Some(Target {
|
|
|
|
target: attacker,
|
|
|
|
hostile: true,
|
|
|
|
selected_at: read_data.time.0,
|
|
|
|
aggro_on: true,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
// Remember this attack if we're an RtSim entity
|
2022-04-05 02:07:23 +00:00
|
|
|
if let Some(attacker_stats) =
|
2021-07-31 19:33:28 +00:00
|
|
|
data.rtsim_entity.and(read_data.stats.get(attacker))
|
|
|
|
{
|
2022-05-01 15:06:43 +00:00
|
|
|
agent.add_fight_to_memory(
|
2022-04-05 02:07:23 +00:00
|
|
|
&attacker_stats.name,
|
|
|
|
read_data.time.0,
|
|
|
|
);
|
2021-07-31 19:33:28 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-01-26 12:47:41 +00:00
|
|
|
}
|
2021-11-24 09:09:22 +00:00
|
|
|
},
|
2021-07-31 19:33:28 +00:00
|
|
|
_ => {},
|
|
|
|
}
|
|
|
|
|
|
|
|
if let Some(target_info) = agent.target {
|
2022-01-18 03:02:43 +00:00
|
|
|
data.react_to_target(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data,
|
|
|
|
&mut event_emitter,
|
|
|
|
target_info,
|
|
|
|
&mut rng,
|
|
|
|
);
|
2021-07-31 19:33:28 +00:00
|
|
|
} else {
|
2022-01-18 03:02:43 +00:00
|
|
|
data.idle_tree(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&read_data,
|
|
|
|
&mut event_emitter,
|
|
|
|
&mut rng,
|
|
|
|
);
|
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) => {
|
2021-07-12 15:40:29 +00:00
|
|
|
rtsim.insert_entity_memory(rtsim_entity.0, memory.clone());
|
2021-03-29 14:47:42 +00:00
|
|
|
},
|
2021-07-14 15:26:29 +00:00
|
|
|
RtSimEvent::ForgetEnemy(name) => {
|
|
|
|
rtsim.forget_entity_enemy(rtsim_entity.0, &name);
|
|
|
|
},
|
2021-03-29 14:47:42 +00:00
|
|
|
RtSimEvent::SetMood(memory) => {
|
2021-07-12 15:40:29 +00:00
|
|
|
rtsim.set_entity_mood(rtsim_entity.0, memory.clone());
|
2021-03-29 14:47:42 +00:00
|
|
|
},
|
2021-07-12 15:40:29 +00:00
|
|
|
RtSimEvent::PrintMemories => {},
|
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
|
|
|
|
////////////////////////////////////////
|
2022-01-18 03:02:43 +00:00
|
|
|
fn react_to_target(
|
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
read_data: &ReadData,
|
|
|
|
event_emitter: &mut Emitter<'_, ServerEvent>,
|
|
|
|
target_info: Target,
|
|
|
|
rng: &mut impl Rng,
|
|
|
|
) {
|
|
|
|
let Target {
|
|
|
|
target, hostile, ..
|
|
|
|
} = target_info;
|
|
|
|
if let Some(tgt_health) = read_data.healths.get(target) {
|
|
|
|
// If target is dead, forget them
|
|
|
|
if tgt_health.is_dead {
|
|
|
|
if let Some(tgt_stats) = self.rtsim_entity.and(read_data.stats.get(target)) {
|
|
|
|
agent.forget_enemy(&tgt_stats.name);
|
|
|
|
}
|
|
|
|
agent.target = None;
|
|
|
|
// Else, if target is hostile, hostile tree
|
|
|
|
} else if hostile {
|
|
|
|
self.hostile_tree(agent, controller, read_data, event_emitter, rng);
|
|
|
|
// Else, if owned, act as pet to them
|
|
|
|
} else if let Some(Alignment::Owned(uid)) = self.alignment {
|
|
|
|
if read_data.uids.get(target) == Some(uid) {
|
|
|
|
self.react_as_pet(agent, controller, read_data, event_emitter, target, rng);
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
self.idle_tree(agent, controller, read_data, event_emitter, rng);
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
self.idle_tree(agent, controller, read_data, event_emitter, rng);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
agent.target = None;
|
|
|
|
self.idle_tree(agent, controller, read_data, event_emitter, rng);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn react_as_pet(
|
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
read_data: &ReadData,
|
|
|
|
event_emitter: &mut Emitter<'_, ServerEvent>,
|
|
|
|
target: EcsEntity,
|
|
|
|
rng: &mut impl Rng,
|
|
|
|
) {
|
|
|
|
if let Some(tgt_pos) = read_data.positions.get(target) {
|
|
|
|
let dist_sqrd = self.pos.0.distance_squared(tgt_pos.0);
|
|
|
|
|
|
|
|
let owner_recently_attacked = if let Some(target_health) = read_data.healths.get(target)
|
|
|
|
{
|
|
|
|
read_data.time.0 - target_health.last_change.time.0 < 5.0
|
|
|
|
&& target_health.last_change.amount < 0.0
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
};
|
|
|
|
|
|
|
|
// If too far away, then follow
|
|
|
|
if dist_sqrd > (MAX_FOLLOW_DIST).powi(2) {
|
|
|
|
self.follow(agent, controller, &read_data.terrain, tgt_pos);
|
|
|
|
// Else, attack target's attacker (if there is one)
|
|
|
|
// Target is the owner in this case
|
|
|
|
} else if owner_recently_attacked {
|
|
|
|
self.attack_target_attacker(agent, read_data, controller, rng);
|
|
|
|
// Otherwise, just idle
|
|
|
|
} else {
|
|
|
|
self.idle_tree(agent, controller, read_data, event_emitter, rng);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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>,
|
2022-01-18 03:02:43 +00:00
|
|
|
rng: &mut impl Rng,
|
2021-02-07 07:22:06 +00:00
|
|
|
) {
|
2022-03-19 17:02:29 +00:00
|
|
|
// TODO: Awareness currently doesn't influence anything.
|
|
|
|
//agent.decrement_awareness(read_data.dt.0);
|
2021-05-15 19:36:27 +00:00
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
let small_chance = rng.gen_bool(0.1);
|
2021-03-03 03:55:28 +00:00
|
|
|
// Set owner if no target
|
2021-10-22 22:11:09 +00:00
|
|
|
if agent.target.is_none() && small_chance {
|
2021-03-03 03:55:28 +00:00
|
|
|
if let Some(Alignment::Owned(owner)) = self.alignment {
|
2021-07-14 07:40:43 +00:00
|
|
|
if let Some(owner) = get_entity_by_id(owner.id(), read_data) {
|
2022-01-18 03:02:43 +00:00
|
|
|
agent.target = Some(Target::new(owner, false, read_data.time.0, false));
|
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-06-17 05:49:09 +00:00
|
|
|
if matches!(
|
|
|
|
agent.inbox.front(),
|
|
|
|
Some(AgentEvent::ServerSound(_)) | Some(AgentEvent::Hurt)
|
|
|
|
) {
|
|
|
|
let sound = agent.inbox.pop_front();
|
|
|
|
match sound {
|
|
|
|
Some(AgentEvent::ServerSound(sound)) => {
|
|
|
|
agent.sounds_heard.push(sound);
|
|
|
|
},
|
|
|
|
Some(AgentEvent::Hurt) => {
|
|
|
|
// Hurt utterances at random upon receiving damage
|
2022-01-18 03:02:43 +00:00
|
|
|
if rng.gen::<f32>() < 0.4 {
|
2022-01-26 20:12:19 +00:00
|
|
|
controller.push_utterance(UtteranceKind::Hurt);
|
2021-06-17 05:49:09 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
//Note: this should be unreachable
|
|
|
|
Some(_) | None => return,
|
|
|
|
}
|
|
|
|
} else {
|
2021-05-15 19:36:27 +00:00
|
|
|
agent.action_state.timer = 0.1;
|
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
2021-08-04 13:04:56 +00:00
|
|
|
|
|
|
|
// If we receive a new interaction, start the interaction timer
|
2022-01-18 03:02:43 +00:00
|
|
|
if agent.allowed_to_speak()
|
2021-10-22 22:11:09 +00:00
|
|
|
&& self.recv_interaction(agent, controller, read_data, event_emitter)
|
|
|
|
{
|
2021-08-04 13:04:56 +00:00
|
|
|
agent.timer.start(read_data.time.0, TimerAction::Interact);
|
|
|
|
}
|
|
|
|
|
|
|
|
let timeout = if agent.behavior.is(BehaviorState::TRADING) {
|
|
|
|
TRADE_INTERACTION_TIME
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-08-04 13:04:56 +00:00
|
|
|
DEFAULT_INTERACTION_TIME
|
|
|
|
};
|
|
|
|
|
|
|
|
match agent
|
|
|
|
.timer
|
|
|
|
.timeout_elapsed(read_data.time.0, TimerAction::Interact, timeout as f64)
|
|
|
|
{
|
|
|
|
None => {
|
|
|
|
// Look toward the interacting entity for a while
|
|
|
|
if let Some(Target { target, .. }) = &agent.target {
|
|
|
|
self.look_toward(controller, read_data, *target);
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::Talk);
|
2021-08-04 13:04:56 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
Some(just_ended) => {
|
|
|
|
if just_ended {
|
|
|
|
agent.target = None;
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::Stand);
|
2021-08-04 13:04:56 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
if rng.gen::<f32>() < 0.1 {
|
2022-04-26 18:22:55 +00:00
|
|
|
self.choose_target(agent, controller, read_data);
|
2021-08-04 13:04:56 +00:00
|
|
|
} else {
|
2022-03-09 17:31:35 +00:00
|
|
|
self.handle_sounds_heard(agent, controller, read_data, rng);
|
2021-08-04 13:04:56 +00:00
|
|
|
}
|
|
|
|
},
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
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>,
|
2022-01-18 03:02:43 +00:00
|
|
|
rng: &mut impl Rng,
|
2021-02-07 07:22:06 +00:00
|
|
|
) {
|
2022-01-15 22:44:16 +00:00
|
|
|
if self.damage < HEALING_ITEM_THRESHOLD && self.heal_self(agent, controller, false) {
|
2021-04-28 22:41:04 +00:00
|
|
|
agent.action_state.timer = 0.01;
|
2021-04-11 23:47:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-06-17 05:49:09 +00:00
|
|
|
if let Some(AgentEvent::Hurt) = agent.inbox.pop_front() {
|
|
|
|
// Hurt utterances at random upon receiving damage
|
2022-01-18 03:02:43 +00:00
|
|
|
if rng.gen::<f32>() < 0.4 {
|
2022-01-26 20:12:19 +00:00
|
|
|
controller.push_utterance(UtteranceKind::Hurt);
|
2021-06-17 05:49:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-03-30 00:25:59 +00:00
|
|
|
if let Some(Target {
|
|
|
|
target,
|
|
|
|
selected_at,
|
2021-07-31 19:33:28 +00:00
|
|
|
aggro_on,
|
2021-03-30 00:25:59 +00:00
|
|
|
..
|
2021-07-31 19:33:28 +00:00
|
|
|
}) = &mut agent.target
|
2021-03-30 00:25:59 +00:00
|
|
|
{
|
2021-07-31 19:33:28 +00:00
|
|
|
let target = *target;
|
|
|
|
let selected_at = *selected_at;
|
2021-03-16 19:17:08 +00:00
|
|
|
if let Some(tgt_pos) = read_data.positions.get(target) {
|
2022-01-18 03:02:43 +00:00
|
|
|
let dist_sqrd = self.pos.0.distance_squared(tgt_pos.0);
|
2022-02-27 13:30:31 +00:00
|
|
|
let origin_dist_sqrd = match agent.patrol_origin {
|
|
|
|
Some(pos) => pos.distance_squared(self.pos.0),
|
|
|
|
None => 1.0,
|
|
|
|
};
|
|
|
|
|
|
|
|
let own_health_fraction = match self.health {
|
|
|
|
Some(val) => val.fraction(),
|
|
|
|
None => 1.0,
|
|
|
|
};
|
|
|
|
let target_health_fraction = match read_data.healths.get(target) {
|
|
|
|
Some(val) => val.fraction(),
|
|
|
|
None => 1.0,
|
|
|
|
};
|
|
|
|
|
2021-07-31 19:33:28 +00:00
|
|
|
let in_aggro_range = agent
|
|
|
|
.psyche
|
|
|
|
.aggro_dist
|
2022-01-18 03:02:43 +00:00
|
|
|
.map_or(true, |ad| dist_sqrd < ad.powi(2));
|
2021-10-22 22:11:09 +00:00
|
|
|
|
2021-07-31 19:33:28 +00:00
|
|
|
if in_aggro_range {
|
|
|
|
*aggro_on = true;
|
|
|
|
}
|
|
|
|
let aggro_on = *aggro_on;
|
|
|
|
|
2022-03-12 22:50:55 +00:00
|
|
|
if self.below_flee_health(agent) {
|
2021-10-22 22:11:09 +00:00
|
|
|
let has_opportunity_to_flee = agent.action_state.timer < FLEE_DURATION;
|
2022-01-18 03:02:43 +00:00
|
|
|
let within_flee_distance = dist_sqrd < MAX_FLEE_DIST.powi(2);
|
2021-10-22 22:11:09 +00:00
|
|
|
|
2022-03-30 21:54:03 +00:00
|
|
|
// FIXME: Using action state timer to see if allowed to speak is a hack.
|
2021-10-22 22:11:09 +00:00
|
|
|
if agent.action_state.timer == 0.0 {
|
2022-05-01 15:06:43 +00:00
|
|
|
self.cry_out(agent, event_emitter, read_data);
|
2021-04-28 22:41:04 +00:00
|
|
|
agent.action_state.timer = 0.01;
|
2021-10-22 22:11:09 +00:00
|
|
|
} else if within_flee_distance && has_opportunity_to_flee {
|
2022-04-29 20:23:07 +00:00
|
|
|
self.flee(agent, controller, tgt_pos, &read_data.terrain);
|
2021-05-15 19:36:27 +00:00
|
|
|
agent.action_state.timer += read_data.dt.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-04-28 22:41:04 +00:00
|
|
|
agent.action_state.timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
agent.target = None;
|
2022-01-18 03:02:43 +00:00
|
|
|
self.idle(agent, controller, read_data, rng);
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
2021-10-22 22:11:09 +00:00
|
|
|
} else if is_dead(target, read_data) {
|
|
|
|
self.exclaim_relief_about_enemy_dead(agent, event_emitter);
|
|
|
|
agent.target = None;
|
2022-01-18 03:02:43 +00:00
|
|
|
self.idle(agent, controller, read_data, rng);
|
2022-02-27 13:30:31 +00:00
|
|
|
} else if is_invulnerable(target, read_data)
|
|
|
|
|| stop_pursuing(
|
|
|
|
dist_sqrd,
|
|
|
|
origin_dist_sqrd,
|
|
|
|
own_health_fraction,
|
|
|
|
target_health_fraction,
|
|
|
|
read_data.time.0 - selected_at,
|
|
|
|
&agent.psyche,
|
|
|
|
)
|
|
|
|
{
|
2021-07-31 19:33:28 +00:00
|
|
|
agent.target = None;
|
2022-01-18 03:02:43 +00:00
|
|
|
self.idle(agent, controller, read_data, rng);
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-10-22 22:11:09 +00:00
|
|
|
let is_time_to_retarget =
|
|
|
|
read_data.time.0 - selected_at > RETARGETING_THRESHOLD_SECONDS;
|
|
|
|
|
|
|
|
if !in_aggro_range && is_time_to_retarget {
|
2022-04-26 18:22:55 +00:00
|
|
|
self.choose_target(agent, controller, read_data);
|
2021-07-31 19:33:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
if aggro_on {
|
2022-01-18 03:02:43 +00:00
|
|
|
let target_data = TargetData::new(
|
|
|
|
tgt_pos,
|
|
|
|
read_data.bodies.get(target),
|
|
|
|
read_data.scales.get(target),
|
|
|
|
);
|
2022-05-01 15:06:43 +00:00
|
|
|
let tgt_name = read_data.stats.get(target).map(|stats| stats.name.clone());
|
|
|
|
|
|
|
|
tgt_name
|
|
|
|
.map(|tgt_name| agent.add_fight_to_memory(&tgt_name, read_data.time.0));
|
2022-01-18 03:02:43 +00:00
|
|
|
self.attack(agent, controller, &target_data, read_data, rng);
|
2021-07-31 19:33:28 +00:00
|
|
|
} else {
|
2022-05-01 15:06:43 +00:00
|
|
|
self.menacing(agent, controller, target, read_data, event_emitter, rng);
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2021-03-30 00:25:59 +00:00
|
|
|
////////////////////////////////////////
|
|
|
|
// Action Nodes
|
|
|
|
////////////////////////////////////////
|
|
|
|
|
2021-07-13 20:54:16 +00:00
|
|
|
fn glider_fall(&self, controller: &mut Controller) {
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::GlideWield);
|
2021-07-13 20:54:16 +00:00
|
|
|
|
2021-07-22 14:02:43 +00:00
|
|
|
let flight_direction =
|
|
|
|
Vec3::from(self.vel.0.xy().try_normalized().unwrap_or_else(Vec2::zero));
|
|
|
|
let flight_ori = Quaternion::from_scalar_and_vec3((1.0, flight_direction));
|
2021-07-13 20:54:16 +00:00
|
|
|
|
2021-07-22 14:02:43 +00:00
|
|
|
let ori = self.ori.look_vec();
|
|
|
|
let look_dir = if ori.z > 0.0 {
|
|
|
|
flight_ori.rotated_x(-0.1)
|
|
|
|
} else {
|
|
|
|
flight_ori.rotated_x(0.1)
|
|
|
|
};
|
2021-07-13 20:54:16 +00:00
|
|
|
|
2021-07-22 14:02:43 +00:00
|
|
|
let (_, look_dir) = look_dir.into_scalar_and_vec3();
|
|
|
|
controller.inputs.look_dir = Dir::from_unnormalized(look_dir).unwrap_or_else(Dir::forward);
|
|
|
|
}
|
|
|
|
|
|
|
|
fn fly_upward(&self, controller: &mut Controller) {
|
2022-01-26 19:09:59 +00:00
|
|
|
controller.push_basic_input(InputKind::Fly);
|
2021-07-22 14:02:43 +00:00
|
|
|
controller.inputs.move_z = 1.0;
|
2021-03-30 00:25:59 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
fn idle(
|
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
read_data: &ReadData,
|
|
|
|
rng: &mut impl Rng,
|
|
|
|
) {
|
2021-02-07 07:22:06 +00:00
|
|
|
// 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
|
2022-01-18 03:02:43 +00:00
|
|
|
if lantern_equipped && rng.gen_bool(0.001) {
|
2021-02-07 07:22:06 +00:00
|
|
|
if day_period.is_dark() && !lantern_turned_on {
|
2022-04-26 18:22:55 +00:00
|
|
|
// Agents with turned off lanterns turn them on randomly once it's
|
|
|
|
// nighttime and keep them on.
|
2021-02-07 07:22:06 +00:00
|
|
|
// Only emit event for agents that sill need to
|
2022-03-30 00:04:20 +00:00
|
|
|
// turn on their lantern.
|
2022-01-26 18:40:18 +00:00
|
|
|
controller.push_event(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
|
2022-03-30 00:04:20 +00:00
|
|
|
// daytime and keep them off.
|
2022-01-26 18:40:18 +00:00
|
|
|
controller.push_event(ControlEvent::DisableLantern)
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
};
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2022-01-15 22:44:16 +00:00
|
|
|
if self.damage < IDLE_HEALING_ITEM_THRESHOLD && self.heal_self(agent, controller, true) {
|
2021-04-28 22:41:04 +00:00
|
|
|
agent.action_state.timer = 0.01;
|
2021-04-11 23:47:29 +00:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2021-04-28 22:41:04 +00:00
|
|
|
agent.action_state.timer = 0.0;
|
2021-02-07 07:22:06 +00:00
|
|
|
if let Some((travel_to, _destination)) = &agent.rtsim_controller.travel_to {
|
2022-03-30 00:04:20 +00:00
|
|
|
// 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())
|
|
|
|
{
|
2022-01-26 19:09:59 +00:00
|
|
|
controller.push_basic_input(InputKind::Fly);
|
2021-03-14 18:42:39 +00:00
|
|
|
} else {
|
2022-01-26 19:15:40 +00:00
|
|
|
controller.push_cancel_input(InputKind::Fly)
|
2021-03-14 18:42:39 +00:00
|
|
|
}
|
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);
|
2022-03-30 21:54:03 +00:00
|
|
|
self.jump_if(bearing.z > 1.5 || self.traversal_config.can_fly, controller);
|
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-05-29 18:45:46 +00:00
|
|
|
let height_offset = bearing.z
|
2021-02-07 07:22:06 +00:00
|
|
|
+ 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-05-29 18:45:46 +00:00
|
|
|
let height_approx = self.pos.0.z
|
2021-03-12 22:14:08 +00:00
|
|
|
- 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"))]
|
2021-05-29 18:45:46 +00:00
|
|
|
let height_approx = self.pos.0.z;
|
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-05-29 18:45:46 +00:00
|
|
|
5.0 //fly up when approaching obstacles
|
2021-02-07 07:22:06 +00:00
|
|
|
} else {
|
2021-05-29 18:45:46 +00:00
|
|
|
-2.0
|
2021-02-07 07:22:06 +00:00
|
|
|
} //flying things should slowly come down from the stratosphere
|
|
|
|
} else {
|
|
|
|
0.05 //normal land traveller offset
|
|
|
|
};
|
2021-05-30 15:38:47 +00:00
|
|
|
if let Some(pid) = agent.position_pid_controller.as_mut() {
|
2021-05-29 18:45:46 +00:00
|
|
|
pid.sp = self.pos.0.z + height_offset * Vec3::unit_z();
|
|
|
|
controller.inputs.move_z = pid.calc_err();
|
|
|
|
} else {
|
|
|
|
controller.inputs.move_z = height_offset;
|
|
|
|
}
|
2021-02-07 07:22:06 +00:00
|
|
|
// Put away weapon
|
2022-01-18 03:02:43 +00:00
|
|
|
if rng.gen_bool(0.1)
|
2021-02-07 07:22:06 +00:00
|
|
|
&& matches!(
|
|
|
|
read_data.char_states.get(*self.entity),
|
2021-10-05 00:15:58 +00:00
|
|
|
Some(CharacterState::Wielding(_))
|
2021-02-07 07:22:06 +00:00
|
|
|
)
|
|
|
|
{
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::Unwield);
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
} else {
|
2022-01-18 03:02:43 +00:00
|
|
|
agent.bearing += Vec2::new(rng.gen::<f32>() - 0.5, rng.gen::<f32>() - 0.5) * 0.1
|
2021-02-07 07:22:06 +00:00
|
|
|
- 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
|
2022-01-25 16:25:40 +00:00
|
|
|
// or about to walk off a cliff
|
|
|
|
// NOTE: costs 1 us (imbris) <- before cliff raycast added
|
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())
|
2022-01-25 16:25:40 +00:00
|
|
|
&& read_data
|
|
|
|
.terrain
|
|
|
|
.ray(
|
|
|
|
self.pos.0
|
|
|
|
+ Vec3::from(agent.bearing)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec3::unit_y),
|
|
|
|
self.pos.0
|
|
|
|
+ Vec3::from(agent.bearing)
|
|
|
|
.try_normalized()
|
|
|
|
.unwrap_or_else(Vec3::unit_y)
|
|
|
|
- Vec3::unit_z() * 4.0,
|
|
|
|
)
|
|
|
|
.until(Block::is_solid)
|
|
|
|
.cast()
|
|
|
|
.0
|
|
|
|
< 3.0
|
2021-02-07 07:22:06 +00:00
|
|
|
{
|
|
|
|
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
|
2022-01-18 03:02:43 +00:00
|
|
|
if rng.gen_bool(0.1)
|
2021-02-07 07:22:06 +00:00
|
|
|
&& matches!(
|
|
|
|
read_data.char_states.get(*self.entity),
|
2021-10-05 00:15:58 +00:00
|
|
|
Some(CharacterState::Wielding(_))
|
2021-02-07 07:22:06 +00:00
|
|
|
)
|
|
|
|
{
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::Unwield);
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
if rng.gen::<f32>() < 0.0015 {
|
2022-01-26 20:12:19 +00:00
|
|
|
controller.push_utterance(UtteranceKind::Calm);
|
2021-06-16 12:49:43 +00:00
|
|
|
}
|
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
// Sit
|
2022-01-18 03:02:43 +00:00
|
|
|
if rng.gen::<f32>() < 0.0035 {
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::Sit);
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2020-11-25 22:47:16 +00:00
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
pub 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);
|
2022-03-30 21:54:03 +00:00
|
|
|
self.jump_if(bearing.z > 1.5, controller);
|
2022-01-18 03:02:43 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-04 13:04:56 +00:00
|
|
|
fn recv_interaction(
|
2021-02-07 07:22:06 +00:00
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
read_data: &ReadData,
|
|
|
|
event_emitter: &mut Emitter<'_, ServerEvent>,
|
2021-08-04 13:04:56 +00:00
|
|
|
) -> bool {
|
2021-02-07 07:22:06 +00:00
|
|
|
// 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
|
2022-01-26 18:40:18 +00:00
|
|
|
// .push_event(ControlEvent::InviteResponse(InviteResponse::Accept));
|
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 {
|
|
|
|
// controller
|
2022-01-26 18:40:18 +00:00
|
|
|
// .push_event(ControlEvent::InviteResponse(InviteResponse::Decline));
|
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-28 22:41:04 +00:00
|
|
|
agent.action_state.timer += read_data.dt.0;
|
2021-05-15 19:36:27 +00:00
|
|
|
|
|
|
|
let msg = agent.inbox.pop_front();
|
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 msg {
|
2021-03-29 14:47:42 +00:00
|
|
|
Some(AgentEvent::Talk(by, subject)) => {
|
2022-01-18 03:02:43 +00:00
|
|
|
if agent.allowed_to_speak() {
|
2021-07-14 07:40:43 +00:00
|
|
|
if let Some(target) = get_entity_by_id(by.id(), read_data) {
|
2022-01-18 03:02:43 +00:00
|
|
|
agent.target = Some(Target::new(target, false, read_data.time.0, false));
|
2021-03-29 14:47:42 +00:00
|
|
|
|
2021-07-31 19:33:28 +00:00
|
|
|
if self.look_toward(controller, read_data, target) {
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::Stand);
|
|
|
|
controller.push_action(ControlAction::Talk);
|
2022-01-26 20:12:19 +00:00
|
|
|
controller.push_utterance(UtteranceKind::Greeting);
|
2021-06-16 12:49:43 +00:00
|
|
|
|
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)
|
|
|
|
{
|
2022-03-07 23:03:18 +00:00
|
|
|
let personality = &rtsim_entity.brain.personality;
|
|
|
|
let standard_response_msg = || -> String {
|
|
|
|
if personality
|
|
|
|
.personality_traits
|
|
|
|
.contains(PersonalityTrait::Extroverted)
|
|
|
|
{
|
|
|
|
format!(
|
|
|
|
"I'm heading to {}! Want to come along?",
|
|
|
|
destination_name
|
|
|
|
)
|
|
|
|
} else if personality
|
|
|
|
.personality_traits
|
|
|
|
.contains(PersonalityTrait::Disagreeable)
|
|
|
|
{
|
|
|
|
"Hrm.".to_string()
|
|
|
|
} else {
|
|
|
|
"Hello!".to_string()
|
|
|
|
}
|
|
|
|
};
|
2021-03-29 14:47:42 +00:00
|
|
|
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)
|
|
|
|
{
|
2022-03-07 23:03:18 +00:00
|
|
|
if personality
|
|
|
|
.personality_traits
|
|
|
|
.contains(PersonalityTrait::Extroverted)
|
|
|
|
{
|
|
|
|
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
|
|
|
|
)
|
|
|
|
} else if personality
|
|
|
|
.personality_traits
|
|
|
|
.contains(PersonalityTrait::Disagreeable)
|
|
|
|
{
|
|
|
|
"Oh. It's you again.".to_string()
|
|
|
|
} else {
|
|
|
|
format!(
|
|
|
|
"Hi again {}! Unfortunately I'm in a \
|
|
|
|
hurry right now. See you!",
|
|
|
|
&tgt_stats.name
|
|
|
|
)
|
|
|
|
}
|
2021-03-29 14:47:42 +00:00
|
|
|
} else {
|
2022-03-07 23:03:18 +00:00
|
|
|
standard_response_msg()
|
2021-03-29 14:47:42 +00:00
|
|
|
}
|
|
|
|
} else {
|
2022-03-07 23:03:18 +00:00
|
|
|
standard_response_msg()
|
2021-03-29 14:47:42 +00:00
|
|
|
};
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc(msg, event_emitter);
|
2021-04-08 17:06:57 +00:00
|
|
|
} else if agent.behavior.can_trade() {
|
2021-10-09 19:14:01 +00:00
|
|
|
if !agent.behavior.is(BehaviorState::TRADING) {
|
2022-01-26 20:23:37 +00:00
|
|
|
controller.push_initiate_invite(by, InviteKind::Trade);
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc(
|
2021-10-09 19:14:01 +00:00
|
|
|
"npc.speech.merchant_advertisement",
|
|
|
|
event_emitter,
|
|
|
|
);
|
|
|
|
} else {
|
2022-03-07 23:03:18 +00:00
|
|
|
let default_msg = "npc.speech.merchant_busy";
|
|
|
|
let msg = self.rtsim_entity.map_or(default_msg, |e| {
|
|
|
|
if e.brain
|
|
|
|
.personality
|
|
|
|
.personality_traits
|
|
|
|
.contains(PersonalityTrait::Disagreeable)
|
|
|
|
{
|
|
|
|
"npc.speech.merchant_busy_rude"
|
|
|
|
} else {
|
|
|
|
default_msg
|
|
|
|
}
|
|
|
|
});
|
|
|
|
self.chat_npc(msg, event_emitter);
|
2021-10-09 19:14:01 +00:00
|
|
|
}
|
2021-03-16 01:30:35 +00:00
|
|
|
} else {
|
2022-03-07 23:03:18 +00:00
|
|
|
let mut rng = rand::thread_rng();
|
|
|
|
if let Some(extreme_trait) =
|
|
|
|
self.rtsim_entity.and_then(|e| {
|
|
|
|
e.brain.personality.random_chat_trait(&mut rng)
|
|
|
|
})
|
|
|
|
{
|
|
|
|
let msg = match extreme_trait {
|
|
|
|
PersonalityTrait::Open => {
|
|
|
|
"npc.speech.villager_open"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Adventurous => {
|
|
|
|
"npc.speech.villager_adventurous"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Closed => {
|
|
|
|
"npc.speech.villager_closed"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Conscientious => {
|
|
|
|
"npc.speech.villager_conscientious"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Busybody => {
|
|
|
|
"npc.speech.villager_busybody"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Unconscientious => {
|
|
|
|
"npc.speech.villager_unconscientious"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Extroverted => {
|
|
|
|
"npc.speech.villager_extroverted"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Introverted => {
|
|
|
|
"npc.speech.villager_introverted"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Agreeable => {
|
|
|
|
"npc.speech.villager_agreeable"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Sociable => {
|
|
|
|
"npc.speech.villager_sociable"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Disagreeable => {
|
|
|
|
"npc.speech.villager_disagreeable"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Neurotic => {
|
|
|
|
"npc.speech.villager_neurotic"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Seeker => {
|
|
|
|
"npc.speech.villager_seeker"
|
|
|
|
},
|
|
|
|
PersonalityTrait::SadLoner => {
|
|
|
|
"npc.speech.villager_sad_loner"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Worried => {
|
|
|
|
"npc.speech.villager_worried"
|
|
|
|
},
|
|
|
|
PersonalityTrait::Stable => {
|
|
|
|
"npc.speech.villager_stable"
|
|
|
|
},
|
|
|
|
};
|
|
|
|
self.chat_npc(msg, event_emitter);
|
|
|
|
} else {
|
|
|
|
self.chat_npc("npc.speech.villager", event_emitter);
|
|
|
|
}
|
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) {
|
2022-01-26 20:23:37 +00:00
|
|
|
controller.push_initiate_invite(by, InviteKind::Trade);
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc(
|
2021-07-31 19:33:28 +00:00
|
|
|
"npc.speech.merchant_advertisement",
|
|
|
|
event_emitter,
|
|
|
|
);
|
2021-03-31 17:06:41 +00:00
|
|
|
} else {
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc(
|
2021-07-31 19:33:28 +00:00
|
|
|
"npc.speech.merchant_busy",
|
|
|
|
event_emitter,
|
|
|
|
);
|
2021-03-31 17:06:41 +00:00
|
|
|
}
|
2021-03-29 14:47:42 +00:00
|
|
|
} else {
|
|
|
|
// TODO: maybe make some travellers willing to trade with
|
|
|
|
// simpler goods like potions
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc(
|
2021-07-31 19:33:28 +00:00
|
|
|
"npc.speech.villager_decline_trade",
|
|
|
|
event_emitter,
|
|
|
|
);
|
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(),
|
|
|
|
};
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc(msg, event_emitter);
|
2021-03-29 14:47:42 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
},
|
|
|
|
Subject::Location(location) => {
|
|
|
|
if let Some(tgt_pos) = read_data.positions.get(target) {
|
2021-07-14 07:40:43 +00:00
|
|
|
let raw_dir = location.origin.as_::<f32>() - tgt_pos.0.xy();
|
|
|
|
let dist = Distance::from_dir(raw_dir).name();
|
|
|
|
let dir = Direction::from_dir(raw_dir).name();
|
|
|
|
|
|
|
|
let msg = format!(
|
|
|
|
"{} ? I think it's {} {} from here!",
|
|
|
|
location.name, dist, dir
|
|
|
|
);
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc(msg, event_emitter);
|
2021-03-29 14:47:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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()
|
|
|
|
)
|
|
|
|
};
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc(msg, event_emitter);
|
2021-03-29 14:47:42 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
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
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::Stand);
|
|
|
|
controller.push_action(ControlAction::Talk);
|
2021-07-14 07:40:43 +00:00
|
|
|
if let Some(target) = get_entity_by_id(with.id(), read_data) {
|
2022-01-18 03:02:43 +00:00
|
|
|
agent.target =
|
|
|
|
Some(Target::new(target, false, read_data.time.0, false));
|
2021-03-31 17:06:41 +00:00
|
|
|
}
|
2022-01-26 20:16:29 +00:00
|
|
|
controller.push_invite_response(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 {
|
2022-01-26 20:16:29 +00:00
|
|
|
controller.push_invite_response(InviteResponse::Decline);
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc_if_allowed_to_speak(
|
2021-07-31 19:33:28 +00:00
|
|
|
"npc.speech.merchant_busy",
|
2021-10-22 22:11:09 +00:00
|
|
|
agent,
|
2021-07-31 19:33:28 +00:00
|
|
|
event_emitter,
|
|
|
|
);
|
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?
|
2022-01-26 20:16:29 +00:00
|
|
|
controller.push_invite_response(InviteResponse::Decline);
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc_if_allowed_to_speak(
|
2021-07-31 19:33:28 +00:00
|
|
|
"npc.speech.villager_decline_trade",
|
2021-10-22 22:11:09 +00:00
|
|
|
agent,
|
2021-07-31 19:33:28 +00:00
|
|
|
event_emitter,
|
|
|
|
);
|
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-07-14 07:40:43 +00:00
|
|
|
if let Some(target) = get_entity_by_id(with.id(), read_data) {
|
2022-01-18 03:02:43 +00:00
|
|
|
agent.target = Some(Target::new(target, false, read_data.time.0, false));
|
2021-03-29 14:47:42 +00:00
|
|
|
}
|
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-10-22 22:11:09 +00:00
|
|
|
self.chat_npc("npc.speech.merchant_trade_successful", event_emitter);
|
2021-07-14 07:40:43 +00:00
|
|
|
},
|
|
|
|
_ => {
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc("npc.speech.merchant_trade_declined", event_emitter);
|
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))
|
2022-02-16 21:41:26 +00:00
|
|
|
if !pending.accept_flags[who] && !pending.is_empty_trade() {
|
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!(
|
2021-11-25 01:32:20 +00:00
|
|
|
"That only covers {:.0}% of my costs!",
|
|
|
|
(balance0 / balance1 * 100.0).floor()
|
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-05-11 17:26:22 +00:00
|
|
|
if let Some(tgt_data) = &agent.target {
|
2021-07-14 07:40:43 +00:00
|
|
|
// If talking with someone in particular, "tell" it only to them
|
2021-05-11 17:26:22 +00:00
|
|
|
if let Some(with) = read_data.uids.get(tgt_data.target) {
|
|
|
|
event_emitter.emit(ServerEvent::Chat(
|
|
|
|
UnresolvedChatMsg::npc_tell(*self.uid, *with, msg),
|
|
|
|
));
|
|
|
|
} else {
|
|
|
|
event_emitter.emit(ServerEvent::Chat(
|
|
|
|
UnresolvedChatMsg::npc_say(*self.uid, msg),
|
|
|
|
));
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
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
|
|
|
},
|
2021-08-04 13:04:56 +00:00
|
|
|
Some(AgentEvent::ServerSound(_)) => {},
|
|
|
|
Some(AgentEvent::Hurt) => {},
|
|
|
|
None => return false,
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
2021-08-04 13:04:56 +00:00
|
|
|
true
|
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,
|
2021-07-31 19:33:28 +00:00
|
|
|
target: EcsEntity,
|
2021-03-29 14:47:42 +00:00
|
|
|
) -> bool {
|
2021-07-31 19:33:28 +00:00
|
|
|
if let Some(tgt_pos) = read_data.positions.get(target) {
|
2021-03-29 14:47:42 +00:00
|
|
|
let eye_offset = self.body.map_or(0.0, |b| b.eye_height());
|
2021-07-31 19:33:28 +00:00
|
|
|
let tgt_eye_offset = read_data.bodies.get(target).map_or(0.0, |b| b.eye_height());
|
2021-03-29 14:47:42 +00:00
|
|
|
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-07-31 19:33:28 +00:00
|
|
|
fn menacing(
|
|
|
|
&self,
|
2022-05-01 15:06:43 +00:00
|
|
|
agent: &mut Agent,
|
2021-07-31 19:33:28 +00:00
|
|
|
controller: &mut Controller,
|
2022-05-01 15:06:43 +00:00
|
|
|
target: EcsEntity,
|
2021-07-31 19:33:28 +00:00
|
|
|
read_data: &ReadData,
|
2021-10-22 22:11:09 +00:00
|
|
|
event_emitter: &mut Emitter<ServerEvent>,
|
2022-01-18 03:02:43 +00:00
|
|
|
rng: &mut impl Rng,
|
2021-07-31 19:33:28 +00:00
|
|
|
) {
|
2021-10-22 22:11:09 +00:00
|
|
|
let max_move = 0.5;
|
|
|
|
let move_dir = controller.inputs.move_dir;
|
|
|
|
let move_dir_mag = move_dir.magnitude();
|
2022-01-18 03:02:43 +00:00
|
|
|
let small_chance = rng.gen::<f32>() < read_data.dt.0 * 0.25;
|
2022-05-01 15:06:43 +00:00
|
|
|
let mut chat = |msg: &str| {
|
|
|
|
self.chat_npc_if_allowed_to_speak(msg.to_string(), agent, event_emitter);
|
|
|
|
};
|
|
|
|
let mut chat_villager_remembers_fighting = || {
|
|
|
|
let tgt_name = read_data.stats.get(target).map(|stats| stats.name.clone());
|
|
|
|
|
|
|
|
if let Some(tgt_name) = tgt_name {
|
|
|
|
chat(format!("{}! How dare you cross me again!", &tgt_name).as_str());
|
|
|
|
} else {
|
|
|
|
chat("You! How dare you cross me again!");
|
|
|
|
}
|
|
|
|
};
|
2021-10-22 22:11:09 +00:00
|
|
|
|
2021-07-31 19:33:28 +00:00
|
|
|
self.look_toward(controller, read_data, target);
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::Wield);
|
2021-07-31 19:33:28 +00:00
|
|
|
|
|
|
|
if move_dir_mag > max_move {
|
2021-10-22 22:11:09 +00:00
|
|
|
controller.inputs.move_dir = max_move * move_dir / move_dir_mag;
|
|
|
|
}
|
|
|
|
|
|
|
|
if small_chance {
|
2022-01-26 20:12:19 +00:00
|
|
|
controller.push_utterance(UtteranceKind::Angry);
|
2022-05-01 15:06:43 +00:00
|
|
|
if is_villager(self.alignment) {
|
|
|
|
if self.remembers_fight_with(target, read_data) {
|
|
|
|
chat_villager_remembers_fighting();
|
2022-04-17 18:50:50 +00:00
|
|
|
} else if is_dressed_as_cultist(target, read_data) {
|
2022-05-01 15:06:43 +00:00
|
|
|
chat("npc.speech.villager_cultist_alarm");
|
|
|
|
} else {
|
|
|
|
chat("npc.speech.menacing");
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
chat("npc.speech.menacing");
|
|
|
|
}
|
2021-07-31 19:33:28 +00:00
|
|
|
}
|
2022-03-30 00:04:20 +00:00
|
|
|
|
|
|
|
// Remember target.
|
|
|
|
self.rtsim_entity.is_some().then(|| {
|
|
|
|
read_data
|
|
|
|
.stats
|
|
|
|
.get(target)
|
|
|
|
.map(|stats| agent.add_fight_to_memory(&stats.name, read_data.time.0))
|
|
|
|
});
|
2021-07-31 19:33:28 +00:00
|
|
|
}
|
|
|
|
|
2022-04-26 18:22:55 +00:00
|
|
|
fn flee(
|
2021-02-07 07:22:06 +00:00
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
2022-04-29 20:23:07 +00:00
|
|
|
tgt_pos: &Pos,
|
2021-02-07 07:22:06 +00:00
|
|
|
terrain: &TerrainGrid,
|
|
|
|
) {
|
|
|
|
if let Some(body) = self.body {
|
|
|
|
if body.can_strafe() && !self.is_gliding {
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::Unwield);
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
|
|
|
}
|
2022-03-30 21:54:03 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
// Away from the target (ironically)
|
|
|
|
self.pos.0
|
2022-04-26 18:22:55 +00:00
|
|
|
+ (self.pos.0 - tgt_pos.0)
|
2021-02-07 07:22:06 +00:00
|
|
|
.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;
|
2022-03-30 21:54:03 +00:00
|
|
|
self.jump_if(bearing.z > 1.5, controller);
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
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
|
2022-01-16 17:06:35 +00:00
|
|
|
/// the healing isn't interrupted. If `relaxed` is `true`, we allow eating
|
|
|
|
/// food and prioritise healing.
|
2022-01-15 22:44:16 +00:00
|
|
|
fn heal_self(&self, _agent: &mut Agent, controller: &mut Controller, relaxed: bool) -> bool {
|
2021-04-11 23:47:29 +00:00
|
|
|
let healing_value = |item: &Item| {
|
2021-09-09 04:07:17 +00:00
|
|
|
let mut value = 0.0;
|
2021-07-14 12:23:51 +00:00
|
|
|
|
2022-01-16 17:06:35 +00:00
|
|
|
if let ItemKind::Consumable { kind, effects, .. } = &item.kind {
|
|
|
|
if matches!(kind, ConsumableKind::Drink)
|
|
|
|
|| (relaxed && matches!(kind, ConsumableKind::Food))
|
|
|
|
{
|
2022-01-15 22:44:16 +00:00
|
|
|
for effect in effects.iter() {
|
|
|
|
use BuffKind::*;
|
|
|
|
match effect {
|
|
|
|
Effect::Health(HealthChange { amount, .. }) => {
|
|
|
|
value += *amount;
|
|
|
|
},
|
|
|
|
Effect::Buff(BuffEffect { kind, data, .. })
|
|
|
|
if matches!(kind, Regeneration | Saturation | Potion) =>
|
|
|
|
{
|
2022-01-16 17:06:35 +00:00
|
|
|
value += data.strength
|
|
|
|
* data.duration.map_or(0.0, |d| d.as_secs() as f32);
|
2022-01-15 22:44:16 +00:00
|
|
|
},
|
|
|
|
_ => {},
|
|
|
|
}
|
2021-04-11 23:47:29 +00:00
|
|
|
}
|
2021-07-14 12:23:51 +00:00
|
|
|
}
|
2021-04-11 23:47:29 +00:00
|
|
|
}
|
2021-09-09 04:07:17 +00:00
|
|
|
value as i32
|
2021-04-11 23:47:29 +00:00
|
|
|
};
|
|
|
|
|
2022-01-16 21:13:13 +00:00
|
|
|
let item = self
|
2021-04-11 23:47:29 +00:00
|
|
|
.inventory
|
|
|
|
.slots_with_id()
|
|
|
|
.filter_map(|(id, slot)| match slot {
|
|
|
|
Some(item) if healing_value(item) > 0 => Some((id, item)),
|
|
|
|
_ => None,
|
|
|
|
})
|
2022-01-16 21:13:13 +00:00
|
|
|
.max_by_key(|(_, item)| {
|
|
|
|
if relaxed {
|
|
|
|
-healing_value(item)
|
|
|
|
} else {
|
|
|
|
healing_value(item)
|
|
|
|
}
|
|
|
|
});
|
2021-04-11 23:47:29 +00:00
|
|
|
|
2022-01-16 21:13:13 +00:00
|
|
|
if let Some((id, _)) = item {
|
2021-04-11 23:47:29 +00:00
|
|
|
use comp::inventory::slot::Slot;
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::InventoryAction(InventoryAction::Use(
|
|
|
|
Slot::Inventory(id),
|
|
|
|
)));
|
2021-04-11 23:47:29 +00:00
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-26 18:22:55 +00:00
|
|
|
fn choose_target(&self, agent: &mut Agent, controller: &mut Controller, read_data: &ReadData) {
|
2021-04-28 22:41:04 +00:00
|
|
|
agent.action_state.timer = 0.0;
|
2022-01-30 21:09:39 +00:00
|
|
|
let mut aggro_on = false;
|
2021-02-07 07:22:06 +00:00
|
|
|
|
2022-03-30 00:04:20 +00:00
|
|
|
let get_pos = |entity| read_data.positions.get(entity);
|
|
|
|
let get_enemy = |entity: EcsEntity| {
|
2022-04-26 18:22:55 +00:00
|
|
|
if self.is_enemy(entity, read_data) {
|
2022-03-30 00:04:20 +00:00
|
|
|
Some(entity)
|
2022-04-17 18:50:50 +00:00
|
|
|
} else if self.should_defend(entity, read_data) {
|
2022-04-26 18:22:55 +00:00
|
|
|
if let Some(attacker) = get_attacker(entity, read_data) {
|
2022-04-26 18:38:08 +00:00
|
|
|
if !self.passive_towards(attacker, read_data) {
|
2022-03-30 00:04:20 +00:00
|
|
|
// aggro_on: attack immediately, do not warn/menace.
|
|
|
|
aggro_on = true;
|
|
|
|
Some(attacker)
|
2021-10-24 05:31:49 +00:00
|
|
|
} else {
|
2022-03-30 00:04:20 +00:00
|
|
|
None
|
|
|
|
}
|
2022-05-01 15:06:43 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
2022-03-30 00:04:20 +00:00
|
|
|
} else {
|
|
|
|
None
|
|
|
|
}
|
|
|
|
};
|
2022-04-26 18:22:55 +00:00
|
|
|
let is_valid_target = |entity| {
|
2022-03-30 00:04:20 +00:00
|
|
|
read_data.healths.get(entity).map_or(false, |health| {
|
|
|
|
!health.is_dead && !is_invulnerable(entity, read_data)
|
|
|
|
})
|
|
|
|
};
|
2021-07-12 15:40:29 +00:00
|
|
|
|
2022-05-05 02:22:19 +00:00
|
|
|
let can_sense_directly_near =
|
|
|
|
{ |e_pos: &Pos| e_pos.0.distance_squared(self.pos.0) < 5_f32.powi(2) };
|
2022-04-28 22:23:48 +00:00
|
|
|
|
|
|
|
let is_detected = |entity: EcsEntity, e_pos: &Pos| {
|
|
|
|
let chance = thread_rng().gen_bool(0.3);
|
|
|
|
|
2022-05-05 02:22:19 +00:00
|
|
|
(can_sense_directly_near(e_pos) && chance)
|
2022-04-29 21:00:14 +00:00
|
|
|
|| self.can_see_entity(agent, controller, entity, e_pos, read_data)
|
2022-04-28 22:23:48 +00:00
|
|
|
};
|
|
|
|
|
2022-03-30 00:04:20 +00:00
|
|
|
// Search the area.
|
|
|
|
// TODO: choose target by more than just distance
|
2021-07-12 15:40:29 +00:00
|
|
|
let common::CachedSpatialGrid(grid) = self.cached_spatial_grid;
|
2022-03-30 00:04:20 +00:00
|
|
|
|
2021-07-12 15:40:29 +00:00
|
|
|
let target = grid
|
2022-03-30 00:04:20 +00:00
|
|
|
.in_circle_aabr(self.pos.0.xy(), agent.psyche.search_dist())
|
2022-04-28 00:29:10 +00:00
|
|
|
.filter(|entity| is_valid_target(*entity))
|
2022-03-30 00:04:20 +00:00
|
|
|
.filter_map(get_enemy)
|
2022-04-28 00:29:10 +00:00
|
|
|
.filter_map(|entity| get_pos(entity).map(|pos| (entity, pos)))
|
2022-04-28 22:23:48 +00:00
|
|
|
.filter(|(entity, e_pos)| is_detected(*entity, e_pos))
|
2022-04-28 00:29:10 +00:00
|
|
|
.min_by_key(|(_, e_pos)| (e_pos.0.distance_squared(self.pos.0) * 100.0) as i32)
|
|
|
|
.map(|(entity, _)| entity);
|
2022-03-30 00:04:20 +00:00
|
|
|
|
2022-04-24 20:15:30 +00:00
|
|
|
if agent.target.is_none() && target.is_some() {
|
2022-01-30 21:09:39 +00:00
|
|
|
if aggro_on {
|
|
|
|
controller.push_utterance(UtteranceKind::Angry);
|
|
|
|
} else {
|
|
|
|
controller.push_utterance(UtteranceKind::Surprised);
|
|
|
|
}
|
2021-06-15 16:15:58 +00:00
|
|
|
}
|
2022-03-30 00:04:20 +00:00
|
|
|
// Change target to new target.
|
2021-04-21 17:10:13 +00:00
|
|
|
agent.target = target.map(|target| Target {
|
|
|
|
target,
|
|
|
|
hostile: true,
|
|
|
|
selected_at: read_data.time.0,
|
2022-01-30 21:09:39 +00:00
|
|
|
aggro_on,
|
2021-04-21 17:10:13 +00:00
|
|
|
});
|
2021-02-07 07:22:06 +00:00
|
|
|
}
|
2021-02-22 00:57:25 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
fn attack(
|
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
2021-05-06 21:17:05 +00:00
|
|
|
tgt_data: &TargetData,
|
2021-03-21 18:22:14 +00:00
|
|
|
read_data: &ReadData,
|
2022-01-18 03:02:43 +00:00
|
|
|
rng: &mut impl Rng,
|
2021-02-07 07:22:06 +00:00
|
|
|
) {
|
2021-04-30 19:25:08 +00:00
|
|
|
let tool_tactic = |tool_kind| match tool_kind {
|
|
|
|
ToolKind::Bow => Tactic::Bow,
|
|
|
|
ToolKind::Staff => Tactic::Staff,
|
2021-07-06 08:29:11 +00:00
|
|
|
ToolKind::Sceptre => Tactic::Sceptre,
|
2021-04-30 19:25:08 +00:00
|
|
|
ToolKind::Hammer => Tactic::Hammer,
|
2022-02-17 05:58:25 +00:00
|
|
|
ToolKind::Sword | ToolKind::Blowgun => Tactic::Sword,
|
2021-04-30 19:25:08 +00:00
|
|
|
ToolKind::Axe => Tactic::Axe,
|
2022-01-21 23:28:15 +00:00
|
|
|
_ => Tactic::SimpleMelee,
|
2021-04-30 19:25:08 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
let tactic = self
|
2021-02-07 07:22:06 +00:00
|
|
|
.inventory
|
2021-05-09 21:18:36 +00:00
|
|
|
.equipped(EquipSlot::ActiveMainhand)
|
2021-02-07 07:22:06 +00:00
|
|
|
.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() {
|
2022-01-20 01:15:50 +00:00
|
|
|
"Oni" | "Sword Simple" => Tactic::Sword,
|
2021-04-30 19:25:08 +00:00
|
|
|
"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 {
|
2021-06-23 20:15:05 +00:00
|
|
|
radius: 6,
|
2021-04-30 19:25:08 +00:00
|
|
|
circle_time: 1,
|
|
|
|
},
|
|
|
|
"Quad Med Basic" => Tactic::QuadMedBasic,
|
2021-06-15 05:43:49 +00:00
|
|
|
"Asp" | "Maneater" => Tactic::QuadLowRanged,
|
|
|
|
"Quad Low Breathe" | "Quad Low Beam" | "Basilisk" => {
|
|
|
|
Tactic::QuadLowBeam
|
|
|
|
},
|
2021-06-23 20:15:05 +00:00
|
|
|
"Quad Low Tail" | "Husk Brute" => Tactic::TailSlap,
|
2021-04-30 19:25:08 +00:00
|
|
|
"Quad Low Quick" => Tactic::QuadLowQuick,
|
|
|
|
"Quad Low Basic" => Tactic::QuadLowBasic,
|
|
|
|
"Theropod Basic" | "Theropod Bird" => Tactic::Theropod,
|
2022-04-23 14:54:01 +00:00
|
|
|
// Arthropods
|
|
|
|
"Antlion" => Tactic::ArthropodMelee,
|
|
|
|
"Tarantula" | "Horn Beetle" => Tactic::ArthropodAmbush,
|
|
|
|
"Weevil" | "Black Widow" => Tactic::ArthropodRanged,
|
2021-04-30 19:25:08 +00:00
|
|
|
"Theropod Charge" => Tactic::CircleCharge {
|
|
|
|
radius: 6,
|
|
|
|
circle_time: 1,
|
|
|
|
},
|
|
|
|
"Turret" => Tactic::Turret,
|
2021-05-06 19:41:21 +00:00
|
|
|
"Haniwa Sentry" => Tactic::RotatingTurret,
|
2021-04-30 19:25:08 +00:00
|
|
|
"Bird Large Breathe" => Tactic::BirdLargeBreathe,
|
|
|
|
"Bird Large Fire" => Tactic::BirdLargeFire,
|
2021-05-26 00:37:31 +00:00
|
|
|
"Bird Large Basic" => Tactic::BirdLargeBasic,
|
2021-04-30 19:25:08 +00:00
|
|
|
"Mindflayer" => Tactic::Mindflayer,
|
2021-04-28 02:33:24 +00:00
|
|
|
"Minotaur" => Tactic::Minotaur,
|
2021-05-06 16:18:10 +00:00
|
|
|
"Clay Golem" => Tactic::ClayGolem,
|
2021-05-26 02:20:27 +00:00
|
|
|
"Tidal Warrior" => Tactic::TidalWarrior,
|
2022-02-09 01:23:23 +00:00
|
|
|
"Tidal Totem"
|
|
|
|
| "Tornado"
|
|
|
|
| "Gnarling Totem Red"
|
|
|
|
| "Gnarling Totem Green"
|
|
|
|
| "Gnarling Totem White" => Tactic::RadialTurret,
|
2021-06-05 18:25:47 +00:00
|
|
|
"Yeti" => Tactic::Yeti,
|
2021-06-20 17:04:06 +00:00
|
|
|
"Harvester" => Tactic::Harvester,
|
2022-01-21 23:28:15 +00:00
|
|
|
"Gnarling Dagger" => Tactic::SimpleBackstab,
|
|
|
|
"Gnarling Blowgun" => Tactic::ElevatedRanged,
|
2022-01-30 23:04:09 +00:00
|
|
|
"Deadwood" => Tactic::Deadwood,
|
2022-02-02 05:17:06 +00:00
|
|
|
"Mandragora" => Tactic::Mandragora,
|
2022-02-03 01:45:43 +00:00
|
|
|
"Wood Golem" => Tactic::WoodGolem,
|
2022-02-09 01:23:23 +00:00
|
|
|
"Gnarling Chieftain" => Tactic::GnarlingChieftain,
|
2022-01-21 23:28:15 +00:00
|
|
|
_ => Tactic::SimpleMelee,
|
2021-04-30 19:25:08 +00:00
|
|
|
},
|
|
|
|
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 {
|
2022-01-21 23:28:15 +00:00
|
|
|
Tactic::SimpleMelee
|
2020-01-26 00:06:03 +00:00
|
|
|
}
|
2021-04-30 19:25:08 +00:00
|
|
|
})
|
2022-01-21 23:28:15 +00:00
|
|
|
.unwrap_or(Tactic::SimpleMelee);
|
2020-01-25 18:49:47 +00:00
|
|
|
|
2021-02-07 07:22:06 +00:00
|
|
|
// Wield the weapon as running towards the target
|
2022-01-26 18:52:19 +00:00
|
|
|
controller.push_action(ControlAction::Wield);
|
2020-07-30 19:26:49 +00:00
|
|
|
|
2021-09-16 10:42:07 +00:00
|
|
|
let min_attack_dist = (self.body.map_or(0.5, |b| b.max_radius()) + DEFAULT_ATTACK_RANGE)
|
2021-05-06 21:17:05 +00:00
|
|
|
* self.scale
|
2021-09-16 10:42:07 +00:00
|
|
|
+ tgt_data.body.map_or(0.5, |b| b.max_radius()) * tgt_data.scale.map_or(1.0, |s| s.0);
|
2021-05-06 21:17:05 +00:00
|
|
|
let dist_sqrd = self.pos.0.distance_squared(tgt_data.pos.0);
|
|
|
|
let angle = self
|
|
|
|
.ori
|
|
|
|
.look_vec()
|
|
|
|
.angle_between(tgt_data.pos.0 - self.pos.0)
|
|
|
|
.to_degrees();
|
2022-01-21 23:28:15 +00:00
|
|
|
let angle_xy = self
|
|
|
|
.ori
|
|
|
|
.look_vec()
|
|
|
|
.xy()
|
|
|
|
.angle_between((tgt_data.pos.0 - self.pos.0).xy())
|
|
|
|
.to_degrees();
|
2021-05-06 21:17:05 +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-10-27 18:01:21 +00:00
|
|
|
let tgt_eye_height = tgt_data.body.map_or(0.0, |b| b.eye_height());
|
|
|
|
let tgt_eye_offset = tgt_eye_height +
|
2021-02-07 07:22:06 +00:00
|
|
|
// 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-08-04 23:13:31 +00:00
|
|
|
// FIXME:
|
|
|
|
// 1) Retrieve actual projectile speed!
|
2021-03-23 09:51:53 +00:00
|
|
|
// 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
|
2021-08-04 23:13:31 +00:00
|
|
|
//
|
|
|
|
// 2) We use eye_offset-s which isn't actually ideal.
|
|
|
|
// Some attacks (beam for example) may use different offsets,
|
|
|
|
// we should probably use offsets from corresponding states.
|
|
|
|
//
|
|
|
|
// 3) Should we even have this big switch?
|
|
|
|
// Not all attacks may want their direction overwritten.
|
|
|
|
// And this is quite hard to debug when you don't see it in actual
|
|
|
|
// attack handler.
|
2021-09-05 22:07:09 +00:00
|
|
|
if let Some(dir) = match self.char_state {
|
2021-09-05 23:03:54 +00:00
|
|
|
CharacterState::ChargedRanged(c) if dist_sqrd > 0.0 => {
|
|
|
|
let charge_factor =
|
|
|
|
c.timer.as_secs_f32() / c.static_data.charge_duration.as_secs_f32();
|
|
|
|
let projectile_speed = c.static_data.initial_projectile_speed
|
|
|
|
+ charge_factor * c.static_data.scaled_projectile_speed;
|
|
|
|
aim_projectile(
|
|
|
|
projectile_speed,
|
2021-09-18 14:16:20 +00:00
|
|
|
self.pos.0
|
|
|
|
+ self.body.map_or(Vec3::zero(), |body| {
|
2021-09-21 23:06:59 +00:00
|
|
|
body.projectile_offsets(self.ori.look_vec())
|
2021-09-18 14:16:20 +00:00
|
|
|
}),
|
2021-09-05 23:03:54 +00:00
|
|
|
Vec3::new(
|
|
|
|
tgt_data.pos.0.x,
|
|
|
|
tgt_data.pos.0.y,
|
|
|
|
tgt_data.pos.0.z + tgt_eye_offset,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
},
|
2021-09-05 22:07:09 +00:00
|
|
|
CharacterState::BasicRanged(c) => {
|
2021-10-27 18:01:21 +00:00
|
|
|
let offset_z = match c.static_data.projectile {
|
|
|
|
// Aim fireballs at feet instead of eyes for splash damage
|
|
|
|
ProjectileConstructor::Fireball {
|
|
|
|
damage: _,
|
|
|
|
radius: _,
|
|
|
|
energy_regen: _,
|
2021-10-29 21:12:57 +00:00
|
|
|
min_falloff: _,
|
2021-10-27 18:01:21 +00:00
|
|
|
} => 0.0,
|
|
|
|
_ => tgt_eye_offset,
|
|
|
|
};
|
2021-09-05 22:07:09 +00:00
|
|
|
let projectile_speed = c.static_data.projectile_speed;
|
2021-06-20 17:04:06 +00:00
|
|
|
aim_projectile(
|
2021-09-05 22:07:09 +00:00
|
|
|
projectile_speed,
|
2021-09-18 14:16:20 +00:00
|
|
|
self.pos.0
|
|
|
|
+ self.body.map_or(Vec3::zero(), |body| {
|
2021-09-21 23:06:59 +00:00
|
|
|
body.projectile_offsets(self.ori.look_vec())
|
2021-09-18 14:16:20 +00:00
|
|
|
}),
|
2021-06-20 17:04:06 +00:00
|
|
|
Vec3::new(
|
|
|
|
tgt_data.pos.0.x,
|
|
|
|
tgt_data.pos.0.y,
|
2021-10-27 18:01:21 +00:00
|
|
|
tgt_data.pos.0.z + offset_z,
|
2021-06-20 17:04:06 +00:00
|
|
|
),
|
|
|
|
)
|
|
|
|
},
|
2021-09-05 23:03:54 +00:00
|
|
|
CharacterState::RepeaterRanged(c) => {
|
|
|
|
let projectile_speed = c.static_data.projectile_speed;
|
|
|
|
aim_projectile(
|
|
|
|
projectile_speed,
|
2021-09-18 14:16:20 +00:00
|
|
|
self.pos.0
|
|
|
|
+ self.body.map_or(Vec3::zero(), |body| {
|
2021-09-21 23:06:59 +00:00
|
|
|
body.projectile_offsets(self.ori.look_vec())
|
2021-09-18 14:16:20 +00:00
|
|
|
}),
|
2021-09-05 23:03:54 +00:00
|
|
|
Vec3::new(
|
|
|
|
tgt_data.pos.0.x,
|
|
|
|
tgt_data.pos.0.y,
|
|
|
|
tgt_data.pos.0.z + tgt_eye_offset,
|
|
|
|
),
|
|
|
|
)
|
|
|
|
},
|
|
|
|
CharacterState::LeapMelee(_) if matches!(tactic, Tactic::Hammer | Tactic::Axe) => {
|
2021-09-05 22:07:09 +00:00
|
|
|
let direction_weight = match tactic {
|
|
|
|
Tactic::Hammer => 0.1,
|
|
|
|
Tactic::Axe => 0.3,
|
2021-09-05 23:13:20 +00:00
|
|
|
_ => unreachable!("Direction weight called on incorrect tactic."),
|
2021-09-05 22:07:09 +00:00
|
|
|
};
|
2021-07-14 01:40:56 +00:00
|
|
|
|
|
|
|
let tgt_pos = tgt_data.pos.0;
|
|
|
|
let self_pos = self.pos.0;
|
|
|
|
|
|
|
|
let delta_x = (tgt_pos.x - self_pos.x) * direction_weight;
|
|
|
|
let delta_y = (tgt_pos.y - self_pos.y) * direction_weight;
|
|
|
|
|
|
|
|
Dir::from_unnormalized(Vec3::new(delta_x, delta_y, -1.0))
|
|
|
|
},
|
2021-09-05 22:07:09 +00:00
|
|
|
CharacterState::BasicBeam(_) => {
|
|
|
|
let aim_from = self.body.map_or(self.pos.0, |body| {
|
|
|
|
self.pos.0
|
|
|
|
+ basic_beam::beam_offsets(
|
|
|
|
body,
|
|
|
|
controller.inputs.look_dir,
|
|
|
|
self.ori.look_vec(),
|
2021-09-15 23:25:00 +00:00
|
|
|
// Try to match animation by getting some context
|
|
|
|
self.vel.0 - self.physics_state.ground_vel,
|
|
|
|
self.physics_state.on_ground,
|
2021-09-05 22:07:09 +00:00
|
|
|
)
|
|
|
|
});
|
2021-08-07 21:18:49 +00:00
|
|
|
let aim_to = Vec3::new(
|
2021-05-06 21:17:05 +00:00
|
|
|
tgt_data.pos.0.x,
|
|
|
|
tgt_data.pos.0.y,
|
|
|
|
tgt_data.pos.0.z + tgt_eye_offset,
|
2021-08-07 21:18:49 +00:00
|
|
|
);
|
|
|
|
Dir::from_unnormalized(aim_to - aim_from)
|
|
|
|
},
|
2021-09-05 22:07:09 +00:00
|
|
|
_ => {
|
|
|
|
let aim_from = Vec3::new(self.pos.0.x, self.pos.0.y, self.pos.0.z + eye_offset);
|
|
|
|
let aim_to = Vec3::new(
|
|
|
|
tgt_data.pos.0.x,
|
|
|
|
tgt_data.pos.0.y,
|
|
|
|
tgt_data.pos.0.z + tgt_eye_offset,
|
|
|
|
);
|
|
|
|
Dir::from_unnormalized(aim_to - aim_from)
|
2021-09-05 23:03:54 +00:00
|
|
|
},
|
2021-03-23 09:51:53 +00:00
|
|
|
} {
|
2021-02-07 07:22:06 +00:00
|
|
|
controller.inputs.look_dir = dir;
|
|
|
|
}
|
|
|
|
|
2021-05-06 21:17:05 +00:00
|
|
|
let attack_data = AttackData {
|
|
|
|
min_attack_dist,
|
|
|
|
dist_sqrd,
|
|
|
|
angle,
|
2022-01-21 23:28:15 +00:00
|
|
|
angle_xy,
|
2021-05-06 21:17:05 +00:00
|
|
|
};
|
|
|
|
|
2022-03-12 22:50:55 +00:00
|
|
|
// Match on tactic. Each tactic has different controls depending on the distance
|
|
|
|
// from the agent to the target.
|
2021-02-07 07:22:06 +00:00
|
|
|
match tactic {
|
2022-01-21 23:28:15 +00:00
|
|
|
Tactic::SimpleMelee => {
|
|
|
|
self.handle_simple_melee(agent, controller, &attack_data, tgt_data, read_data, rng)
|
2021-02-07 07:22:06 +00:00
|
|
|
},
|
|
|
|
Tactic::Axe => {
|
2022-01-18 03:02:43 +00:00
|
|
|
self.handle_axe_attack(agent, controller, &attack_data, tgt_data, read_data, rng)
|
2021-02-07 07:22:06 +00:00
|
|
|
},
|
|
|
|
Tactic::Hammer => {
|
2022-01-18 03:02:43 +00:00
|
|
|
self.handle_hammer_attack(agent, controller, &attack_data, tgt_data, read_data, rng)
|
2021-02-07 07:22:06 +00:00
|
|
|
},
|
|
|
|
Tactic::Sword => {
|
2022-01-18 03:02:43 +00:00
|
|
|
self.handle_sword_attack(agent, controller, &attack_data, tgt_data, read_data, rng)
|
2021-05-06 21:17:05 +00:00
|
|
|
},
|
|
|
|
Tactic::Bow => {
|
2022-01-18 03:02:43 +00:00
|
|
|
self.handle_bow_attack(agent, controller, &attack_data, tgt_data, read_data, rng)
|
2021-05-06 21:17:05 +00:00
|
|
|
},
|
|
|
|
Tactic::Staff => {
|
2022-01-18 03:02:43 +00:00
|
|
|
self.handle_staff_attack(agent, controller, &attack_data, tgt_data, read_data, rng)
|
2021-07-06 08:29:11 +00:00
|
|
|
},
|
2022-01-18 03:02:43 +00:00
|
|
|
Tactic::Sceptre => self.handle_sceptre_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
|
|
|
tgt_data,
|
|
|
|
read_data,
|
|
|
|
rng,
|
|
|
|
),
|
2021-07-12 07:09:57 +00:00
|
|
|
Tactic::StoneGolem => {
|
|
|
|
self.handle_stone_golem_attack(agent, controller, &attack_data, tgt_data, read_data)
|
|
|
|
},
|
2021-05-06 21:17:05 +00:00
|
|
|
Tactic::CircleCharge {
|
|
|
|
radius,
|
|
|
|
circle_time,
|
|
|
|
} => self.handle_circle_charge_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
2021-07-11 18:41:52 +00:00
|
|
|
tgt_data,
|
|
|
|
read_data,
|
2021-05-06 21:17:05 +00:00
|
|
|
radius,
|
|
|
|
circle_time,
|
2022-01-18 03:02:43 +00:00
|
|
|
rng,
|
2021-05-06 21:17:05 +00:00
|
|
|
),
|
|
|
|
Tactic::QuadLowRanged => self.handle_quadlow_ranged_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
2021-07-11 18:41:52 +00:00
|
|
|
tgt_data,
|
|
|
|
read_data,
|
2021-05-06 21:17:05 +00:00
|
|
|
),
|
|
|
|
Tactic::TailSlap => {
|
2021-07-11 18:41:52 +00:00
|
|
|
self.handle_tail_slap_attack(agent, controller, &attack_data, tgt_data, read_data)
|
2021-05-06 21:17:05 +00:00
|
|
|
},
|
|
|
|
Tactic::QuadLowQuick => self.handle_quadlow_quick_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
2021-07-11 18:41:52 +00:00
|
|
|
tgt_data,
|
|
|
|
read_data,
|
2021-05-06 21:17:05 +00:00
|
|
|
),
|
|
|
|
Tactic::QuadLowBasic => self.handle_quadlow_basic_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
2021-07-11 18:41:52 +00:00
|
|
|
tgt_data,
|
|
|
|
read_data,
|
2021-05-06 21:17:05 +00:00
|
|
|
),
|
|
|
|
Tactic::QuadMedJump => self.handle_quadmed_jump_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
2021-07-11 18:41:52 +00:00
|
|
|
tgt_data,
|
|
|
|
read_data,
|
2021-05-06 21:17:05 +00:00
|
|
|
),
|
|
|
|
Tactic::QuadMedBasic => self.handle_quadmed_basic_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
2021-07-11 18:41:52 +00:00
|
|
|
tgt_data,
|
|
|
|
read_data,
|
2021-05-06 21:17:05 +00:00
|
|
|
),
|
|
|
|
Tactic::QuadLowBeam => self.handle_quadlow_beam_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
2021-07-11 18:41:52 +00:00
|
|
|
tgt_data,
|
|
|
|
read_data,
|
2021-05-06 21:17:05 +00:00
|
|
|
),
|
|
|
|
Tactic::Theropod => {
|
2021-07-11 18:41:52 +00:00
|
|
|
self.handle_theropod_attack(agent, controller, &attack_data, tgt_data, read_data)
|
2021-05-06 21:17:05 +00:00
|
|
|
},
|
2022-04-23 14:54:01 +00:00
|
|
|
Tactic::ArthropodMelee => self.handle_arthropod_melee_attack(
|
2021-09-06 23:43:10 +00:00
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
|
|
|
tgt_data,
|
|
|
|
read_data,
|
|
|
|
),
|
2022-04-23 14:54:01 +00:00
|
|
|
Tactic::ArthropodAmbush => self.handle_arthropod_ambush_attack(
|
2021-12-23 14:13:57 +00:00
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
|
|
|
tgt_data,
|
|
|
|
read_data,
|
|
|
|
rng,
|
|
|
|
),
|
|
|
|
Tactic::ArthropodRanged => self.handle_arthropod_ranged_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
|
|
|
tgt_data,
|
|
|
|
read_data,
|
|
|
|
),
|
2022-04-26 23:34:29 +00:00
|
|
|
Tactic::Turret => {
|
|
|
|
self.handle_turret_attack(agent, controller, &attack_data, tgt_data, read_data)
|
2021-05-06 21:17:05 +00:00
|
|
|
},
|
2022-04-26 23:34:29 +00:00
|
|
|
Tactic::FixedTurret => self.handle_fixed_turret_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
|
|
|
tgt_data,
|
|
|
|
read_data,
|
|
|
|
),
|
2022-03-30 00:04:20 +00:00
|
|
|
Tactic::RotatingTurret => {
|
2022-04-26 23:34:29 +00:00
|
|
|
self.handle_rotating_turret_attack(agent, controller, tgt_data, read_data)
|
2022-03-30 00:04:20 +00:00
|
|
|
},
|
2022-01-18 03:02:43 +00:00
|
|
|
Tactic::Mindflayer => self.handle_mindflayer_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
|
|
|
tgt_data,
|
|
|
|
read_data,
|
|
|
|
rng,
|
|
|
|
),
|
2021-05-06 21:17:05 +00:00
|
|
|
Tactic::BirdLargeFire => self.handle_birdlarge_fire_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
2021-07-11 18:41:52 +00:00
|
|
|
tgt_data,
|
|
|
|
read_data,
|
2022-01-18 03:02:43 +00:00
|
|
|
rng,
|
2021-05-06 21:17:05 +00:00
|
|
|
),
|
|
|
|
// Mostly identical to BirdLargeFire but tweaked for flamethrower instead of shockwave
|
|
|
|
Tactic::BirdLargeBreathe => self.handle_birdlarge_breathe_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
2021-07-11 18:41:52 +00:00
|
|
|
tgt_data,
|
|
|
|
read_data,
|
2022-01-18 03:02:43 +00:00
|
|
|
rng,
|
2021-05-06 21:17:05 +00:00
|
|
|
),
|
2021-05-26 00:37:31 +00:00
|
|
|
Tactic::BirdLargeBasic => self.handle_birdlarge_basic_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
2021-07-11 18:41:52 +00:00
|
|
|
tgt_data,
|
|
|
|
read_data,
|
2021-05-26 00:37:31 +00:00
|
|
|
),
|
2021-05-06 21:17:05 +00:00
|
|
|
Tactic::Minotaur => {
|
2021-07-11 18:41:52 +00:00
|
|
|
self.handle_minotaur_attack(agent, controller, &attack_data, tgt_data, read_data)
|
2021-05-06 21:17:05 +00:00
|
|
|
},
|
2021-07-12 07:09:57 +00:00
|
|
|
Tactic::ClayGolem => {
|
|
|
|
self.handle_clay_golem_attack(agent, controller, &attack_data, tgt_data, read_data)
|
|
|
|
},
|
2021-05-26 02:20:27 +00:00
|
|
|
Tactic::TidalWarrior => self.handle_tidal_warrior_attack(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
2021-07-11 18:41:52 +00:00
|
|
|
tgt_data,
|
|
|
|
read_data,
|
2021-05-26 02:20:27 +00:00
|
|
|
),
|
2022-04-22 01:32:56 +00:00
|
|
|
Tactic::RadialTurret => self.handle_radial_turret_attack(controller),
|
2021-06-05 18:25:47 +00:00
|
|
|
Tactic::Yeti => {
|
2021-07-11 18:41:52 +00:00
|
|
|
self.handle_yeti_attack(agent, controller, &attack_data, tgt_data, read_data)
|
2021-06-05 18:25:47 +00:00
|
|
|
},
|
2021-06-20 17:04:06 +00:00
|
|
|
Tactic::Harvester => {
|
2021-07-11 18:41:52 +00:00
|
|
|
self.handle_harvester_attack(agent, controller, &attack_data, tgt_data, read_data)
|
2021-06-20 17:04:06 +00:00
|
|
|
},
|
2022-01-21 23:28:15 +00:00
|
|
|
Tactic::SimpleBackstab => {
|
|
|
|
self.handle_simple_backstab(agent, controller, &attack_data, tgt_data, read_data)
|
|
|
|
},
|
|
|
|
Tactic::ElevatedRanged => {
|
|
|
|
self.handle_elevated_ranged(agent, controller, &attack_data, tgt_data, read_data)
|
|
|
|
},
|
2022-01-30 23:04:09 +00:00
|
|
|
Tactic::Deadwood => {
|
|
|
|
self.handle_deadwood(agent, controller, &attack_data, tgt_data, read_data)
|
|
|
|
},
|
2022-02-02 05:17:06 +00:00
|
|
|
Tactic::Mandragora => {
|
|
|
|
self.handle_mandragora(agent, controller, &attack_data, tgt_data, read_data)
|
|
|
|
},
|
2022-02-03 01:45:43 +00:00
|
|
|
Tactic::WoodGolem => {
|
|
|
|
self.handle_wood_golem(agent, controller, &attack_data, tgt_data, read_data)
|
|
|
|
},
|
2022-02-09 01:23:23 +00:00
|
|
|
Tactic::GnarlingChieftain => self.handle_gnarling_chieftain(
|
|
|
|
agent,
|
|
|
|
controller,
|
|
|
|
&attack_data,
|
|
|
|
tgt_data,
|
|
|
|
read_data,
|
|
|
|
rng,
|
|
|
|
),
|
2021-05-06 21:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-09 17:31:35 +00:00
|
|
|
fn handle_sounds_heard(
|
2021-05-06 21:17:05 +00:00
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
|
|
|
read_data: &ReadData,
|
2022-01-18 03:02:43 +00:00
|
|
|
rng: &mut impl Rng,
|
2021-05-06 21:17:05 +00:00
|
|
|
) {
|
2022-03-09 17:31:35 +00:00
|
|
|
agent.forget_old_sounds(read_data.time.0);
|
2021-05-06 21:17:05 +00:00
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
if is_invulnerable(*self.entity, read_data) {
|
|
|
|
self.idle(agent, controller, read_data, rng);
|
|
|
|
return;
|
2021-05-06 21:17:05 +00:00
|
|
|
}
|
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
if let Some(sound) = agent.sounds_heard.last() {
|
2022-03-09 17:31:35 +00:00
|
|
|
let sound_pos = Pos(sound.pos);
|
|
|
|
let dist_sqrd = self.pos.0.distance_squared(sound_pos.0);
|
2022-03-13 00:09:22 +00:00
|
|
|
// NOTE: There is an implicit distance requirement given that sound volume
|
|
|
|
// disipates as it travels, but we will not want to flee if a sound is super
|
|
|
|
// loud but heard from a great distance, regardless of how loud it was.
|
|
|
|
// `is_close` is this limiter.
|
|
|
|
let is_close = dist_sqrd < 35.0_f32.powi(2);
|
2022-03-09 17:31:35 +00:00
|
|
|
|
|
|
|
let sound_was_loud = sound.vol >= 10.0;
|
|
|
|
let sound_was_threatening = sound_was_loud
|
|
|
|
|| matches!(sound.kind, SoundKind::Utterance(UtteranceKind::Scream, _));
|
|
|
|
|
2022-04-26 18:38:08 +00:00
|
|
|
let has_enemy_alignment = matches!(self.alignment, Some(Alignment::Enemy));
|
2022-03-09 17:31:35 +00:00
|
|
|
// FIXME: We need to be able to change the name of a guard without breaking this
|
|
|
|
// logic. The `Mark` enum from common::agent could be used to match with
|
|
|
|
// `agent::Mark::Guard`
|
|
|
|
let is_village_guard = read_data
|
|
|
|
.stats
|
|
|
|
.get(*self.entity)
|
|
|
|
.map_or(false, |stats| stats.name == *"Guard".to_string());
|
2022-04-26 18:38:08 +00:00
|
|
|
let follows_threatening_sounds = has_enemy_alignment || is_village_guard;
|
2022-03-09 17:31:35 +00:00
|
|
|
|
|
|
|
// TODO: Awareness currently doesn't influence anything.
|
2022-03-19 17:02:29 +00:00
|
|
|
//agent.awareness += 0.5 * sound.vol;
|
2022-03-09 17:31:35 +00:00
|
|
|
|
2022-03-13 00:09:22 +00:00
|
|
|
if sound_was_threatening && is_close {
|
|
|
|
if !self.below_flee_health(agent) && follows_threatening_sounds {
|
2022-01-18 03:02:43 +00:00
|
|
|
self.follow(agent, controller, &read_data.terrain, &sound_pos);
|
2022-03-13 00:09:22 +00:00
|
|
|
} else if self.below_flee_health(agent) || !follows_threatening_sounds {
|
2022-04-29 20:23:07 +00:00
|
|
|
self.flee(agent, controller, &sound_pos, &read_data.terrain);
|
2022-01-18 03:02:43 +00:00
|
|
|
} else {
|
|
|
|
self.idle(agent, controller, read_data, rng);
|
|
|
|
}
|
2022-03-09 17:31:35 +00:00
|
|
|
} else {
|
|
|
|
self.idle(agent, controller, read_data, rng);
|
2021-05-06 21:17:05 +00:00
|
|
|
}
|
2022-04-05 03:40:26 +00:00
|
|
|
} else {
|
|
|
|
self.idle(agent, controller, read_data, rng);
|
2021-05-06 21:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
fn attack_target_attacker(
|
2021-05-06 21:17:05 +00:00
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
read_data: &ReadData,
|
2022-01-18 03:02:43 +00:00
|
|
|
controller: &mut Controller,
|
|
|
|
rng: &mut impl Rng,
|
2021-05-06 21:17:05 +00:00
|
|
|
) {
|
2022-01-18 03:02:43 +00:00
|
|
|
if let Some(Target { target, .. }) = agent.target {
|
|
|
|
if let Some(tgt_health) = read_data.healths.get(target) {
|
|
|
|
if let Some(by) = tgt_health.last_change.damage_by() {
|
|
|
|
if let Some(attacker) = get_entity_by_id(by.uid().0, read_data) {
|
|
|
|
if agent.target.is_none() {
|
2022-01-26 20:12:19 +00:00
|
|
|
controller.push_utterance(UtteranceKind::Angry);
|
2022-01-18 03:02:43 +00:00
|
|
|
}
|
2021-07-14 01:40:56 +00:00
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
agent.target = Some(Target::new(attacker, true, read_data.time.0, true));
|
2021-07-14 01:40:56 +00:00
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
if let Some(tgt_pos) = read_data.positions.get(attacker) {
|
|
|
|
if is_dead_or_invulnerable(attacker, read_data) {
|
2022-05-01 15:06:43 +00:00
|
|
|
// FIXME?: Shouldn't target be set to `None`?
|
|
|
|
// If is dead, then probably. If invulnerable, maybe not.
|
2022-01-18 03:02:43 +00:00
|
|
|
agent.target =
|
|
|
|
Some(Target::new(target, false, read_data.time.0, false));
|
2021-07-14 01:40:56 +00:00
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
self.idle(agent, controller, read_data, rng);
|
|
|
|
} else {
|
|
|
|
let target_data = TargetData::new(
|
|
|
|
tgt_pos,
|
|
|
|
read_data.bodies.get(target),
|
|
|
|
read_data.scales.get(target),
|
|
|
|
);
|
2022-05-01 15:06:43 +00:00
|
|
|
if let Some(tgt_name) =
|
|
|
|
read_data.stats.get(target).map(|stats| stats.name.clone())
|
|
|
|
{
|
|
|
|
agent.add_fight_to_memory(&tgt_name, read_data.time.0)
|
|
|
|
}
|
2022-01-18 03:02:43 +00:00
|
|
|
self.attack(agent, controller, &target_data, read_data, rng);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-05-06 21:17:05 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-18 03:02:43 +00:00
|
|
|
/// Directs the entity to path and move toward the target
|
2022-02-25 20:37:01 +00:00
|
|
|
/// If path is not Full, the entity will path to a location 50 units along
|
2022-01-18 03:02:43 +00:00
|
|
|
/// the vector between the entity and the target. The speed multiplier
|
|
|
|
/// multiplies the movement speed by a value less than 1.0.
|
|
|
|
/// A `None` value implies a multiplier of 1.0.
|
|
|
|
/// Returns `false` if the pathfinding algorithm fails to return a path
|
|
|
|
fn path_toward_target(
|
2021-05-06 21:17:05 +00:00
|
|
|
&self,
|
|
|
|
agent: &mut Agent,
|
|
|
|
controller: &mut Controller,
|
2022-02-27 06:56:36 +00:00
|
|
|
tgt_pos: Vec3<f32>,
|
2021-05-06 21:17:05 +00:00
|
|
|
read_data: &ReadData,
|
2022-02-25 20:35:35 +00:00
|
|
|
path: Path,
|
2022-01-18 03:02:43 +00:00
|
|
|
speed_multiplier: Option<f32>,
|
|
|
|
) -> bool {
|
2022-03-01 21:47:01 +00:00
|
|
|
let partial_path_tgt_pos = |pos_difference: Vec3<f32>| {
|
2022-03-05 08:54:01 +00:00
|
|
|
self.pos.0
|
|
|
|
+ PARTIAL_PATH_DIST * pos_difference.try_normalized().unwrap_or_else(Vec3::zero)
|
2022-02-25 20:44:43 +00:00
|
|
|
};
|
2022-03-05 08:54:01 +00:00
|
|
|
let pos_difference = tgt_pos - self.pos.0;
|
2022-02-25 20:35:35 +00:00
|
|
|
let pathing_pos = match path {
|
2022-03-01 21:40:43 +00:00
|
|
|
Path::Separate => {
|
2022-02-25 20:35:35 +00:00
|
|
|
let mut sep_vec: Vec3<f32> = Vec3::<f32>::zero();
|
|
|
|
|
|
|
|
for entity in read_data
|
|
|
|
.cached_spatial_grid
|
|
|
|
.0
|
2022-03-05 08:54:01 +00:00
|
|
|
.in_circle_aabr(self.pos.0.xy(), SEPARATION_DIST)
|
2021-06-15 13:52:31 +00:00
|
|
|
{
|
2022-02-25 20:35:35 +00:00
|
|
|
if let (Some(alignment), Some(other_alignment)) =
|
|
|
|
(self.alignment, read_data.alignments.get(entity))
|
|
|
|
{
|
|
|
|
if Alignment::passive_towards(*alignment, *other_alignment) {
|
|
|
|
if let (Some(pos), Some(body), Some(other_body)) = (
|
|
|
|
read_data.positions.get(entity),
|
|
|
|
self.body,
|
|
|
|
read_data.bodies.get(entity),
|
|
|
|
) {
|
2022-03-01 21:42:03 +00:00
|
|
|
let dist_xy = self.pos.0.xy().distance(pos.0.xy());
|
2022-02-25 20:48:29 +00:00
|
|
|
let spacing = body.spacing_radius() + other_body.spacing_radius();
|
2022-03-01 21:42:03 +00:00
|
|
|
if dist_xy < spacing {
|
2022-03-01 21:43:33 +00:00
|
|
|
let pos_diff = self.pos.0.xy() - pos.0.xy();
|
|
|
|
sep_vec += pos_diff.try_normalized().unwrap_or_else(Vec2::zero)
|
|
|
|
* ((spacing - dist_xy) / spacing);
|
2022-02-25 20:35:35 +00:00
|
|
|
}
|
2021-06-16 10:57:52 +00:00
|
|
|
}
|
2021-06-15 13:52:31 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2022-03-01 21:33:25 +00:00
|
|
|
partial_path_tgt_pos(
|
2022-03-01 21:38:35 +00:00
|
|
|
sep_vec * SEPARATION_BIAS + pos_difference * (1.0 - SEPARATION_BIAS),
|
2022-02-25 20:44:43 +00:00
|
|
|
)
|
2022-02-25 20:35:35 +00:00
|
|
|
},
|
2022-03-01 21:40:43 +00:00
|
|
|
Path::Full => tgt_pos,
|
2022-03-01 21:38:35 +00:00
|
|
|
Path::Partial => partial_path_tgt_pos(pos_difference),
|
2021-05-21 03:14:45 +00:00
|
|
|
};
|
|
|
|
let speed_multiplier = speed_multiplier.unwrap_or(1.0).min(1.0);
|
|
|
|
if let Some((bearing, speed)) = agent.chaser.chase(
|
|
|
|
&*read_data.terrain,
|
|
|
|
self.pos.0,
|
|
|
|
self.vel.0,
|
|
|
|
pathing_pos,
|
|
|
|
TraversalConfig {
|
|
|
|
min_tgt_dist: 1.25,
|
|
|
|
..self.traversal_config
|
|
|
|
},
|
|
|
|
) {
|
|
|
|
controller.inputs.move_dir =
|
|
|
|
bearing.xy().try_normalized().unwrap_or_else(Vec2::zero) * speed * speed_multiplier;
|
2022-03-30 21:54:03 +00:00
|
|
|
self.jump_if(bearing.z > 1.5, controller);
|
2021-05-21 03:14:45 +00:00
|
|
|
controller.inputs.move_z = bearing.z;
|
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-22 22:11:09 +00:00
|
|
|
fn chat_npc_if_allowed_to_speak(
|
2021-07-14 07:40:43 +00:00
|
|
|
&self,
|
2021-07-31 19:33:28 +00:00
|
|
|
msg: impl ToString,
|
2021-10-22 22:11:09 +00:00
|
|
|
agent: &Agent,
|
2021-07-14 07:40:43 +00:00
|
|
|
event_emitter: &mut Emitter<'_, ServerEvent>,
|
|
|
|
) -> bool {
|
2022-01-18 03:02:43 +00:00
|
|
|
if agent.allowed_to_speak() {
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc(msg, event_emitter);
|
2021-07-14 07:40:43 +00:00
|
|
|
true
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-03-30 21:54:03 +00:00
|
|
|
fn jump_if(&self, condition: bool, controller: &mut Controller) {
|
2021-05-21 03:14:45 +00:00
|
|
|
if condition {
|
2022-01-26 19:09:59 +00:00
|
|
|
controller.push_basic_input(InputKind::Jump);
|
2021-05-21 03:14:45 +00:00
|
|
|
} else {
|
2022-01-26 19:15:40 +00:00
|
|
|
controller.push_cancel_input(InputKind::Jump)
|
2021-05-21 03:14:45 +00:00
|
|
|
}
|
|
|
|
}
|
2021-07-14 07:40:43 +00:00
|
|
|
|
2021-10-22 22:11:09 +00:00
|
|
|
fn chat_npc(&self, msg: impl ToString, event_emitter: &mut Emitter<'_, ServerEvent>) {
|
2021-07-31 19:33:28 +00:00
|
|
|
event_emitter.emit(ServerEvent::Chat(UnresolvedChatMsg::npc(
|
|
|
|
*self.uid,
|
|
|
|
msg.to_string(),
|
|
|
|
)));
|
2021-07-14 07:40:43 +00:00
|
|
|
}
|
|
|
|
|
2021-10-16 16:11:57 +00:00
|
|
|
fn emit_scream(&self, time: f64, event_emitter: &mut Emitter<'_, ServerEvent>) {
|
2021-10-15 19:49:25 +00:00
|
|
|
if let Some(body) = self.body {
|
|
|
|
event_emitter.emit(ServerEvent::Sound {
|
2021-10-15 20:23:45 +00:00
|
|
|
sound: Sound::new(
|
|
|
|
SoundKind::Utterance(UtteranceKind::Scream, *body),
|
|
|
|
self.pos.0,
|
2022-03-08 00:58:44 +00:00
|
|
|
13.0,
|
2021-10-15 20:23:45 +00:00
|
|
|
time,
|
|
|
|
),
|
2021-10-15 19:49:25 +00:00
|
|
|
});
|
|
|
|
}
|
2021-07-14 07:40:43 +00:00
|
|
|
}
|
2021-10-22 22:11:09 +00:00
|
|
|
|
2022-05-01 15:06:43 +00:00
|
|
|
fn cry_out(
|
|
|
|
&self,
|
|
|
|
agent: &Agent,
|
|
|
|
event_emitter: &mut Emitter<'_, ServerEvent>,
|
|
|
|
read_data: &ReadData,
|
|
|
|
) {
|
2022-04-26 18:38:08 +00:00
|
|
|
let has_enemy_alignment = matches!(self.alignment, Some(Alignment::Enemy));
|
2021-10-22 22:11:09 +00:00
|
|
|
|
2022-04-26 18:38:08 +00:00
|
|
|
if has_enemy_alignment {
|
|
|
|
// FIXME: If going to use "cultist + low health + fleeing" string, make sure
|
|
|
|
// they are each true.
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc_if_allowed_to_speak(
|
|
|
|
"npc.speech.cultist_low_health_fleeing",
|
|
|
|
agent,
|
|
|
|
event_emitter,
|
|
|
|
);
|
2022-05-01 15:06:43 +00:00
|
|
|
} else if is_villager(self.alignment) {
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc_if_allowed_to_speak(
|
|
|
|
"npc.speech.villager_under_attack",
|
|
|
|
agent,
|
|
|
|
event_emitter,
|
|
|
|
);
|
2022-05-01 15:06:43 +00:00
|
|
|
self.emit_scream(read_data.time.0, event_emitter);
|
2021-10-22 22:11:09 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
fn exclaim_relief_about_enemy_dead(
|
|
|
|
&self,
|
|
|
|
agent: &Agent,
|
|
|
|
event_emitter: &mut Emitter<'_, ServerEvent>,
|
|
|
|
) {
|
2022-05-01 15:06:43 +00:00
|
|
|
if is_villager(self.alignment) {
|
2021-10-22 22:11:09 +00:00
|
|
|
self.chat_npc_if_allowed_to_speak(
|
|
|
|
"npc.speech.villager_enemy_killed",
|
|
|
|
agent,
|
|
|
|
event_emitter,
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|
2022-03-12 22:50:55 +00:00
|
|
|
|
|
|
|
fn below_flee_health(&self, agent: &Agent) -> bool {
|
|
|
|
self.damage.min(1.0) < agent.psyche.flee_health
|
|
|
|
}
|
2022-04-05 02:07:23 +00:00
|
|
|
|
2022-04-26 18:22:55 +00:00
|
|
|
fn is_more_dangerous_than_target(
|
2022-04-05 02:07:23 +00:00
|
|
|
&self,
|
|
|
|
entity: EcsEntity,
|
|
|
|
target: Target,
|
|
|
|
read_data: &ReadData,
|
|
|
|
) -> bool {
|
|
|
|
let entity_pos = read_data.positions.get(entity);
|
|
|
|
let target_pos = read_data.positions.get(target.target);
|
|
|
|
|
|
|
|
entity_pos.map_or(false, |entity_pos| {
|
|
|
|
target_pos.map_or(true, |target_pos| {
|
|
|
|
// Fuzzy factor that makes it harder for players to cheese enemies by making
|
|
|
|
// them quickly flip aggro between two players.
|
|
|
|
// It does this by only switching aggro if the entity is closer to the enemy by
|
|
|
|
// a specific proportional threshold.
|
|
|
|
const FUZZY_DIST_COMPARISON: f32 = 0.8;
|
|
|
|
|
|
|
|
let is_target_further = target_pos.0.distance(entity_pos.0)
|
|
|
|
< target_pos.0.distance(entity_pos.0) * FUZZY_DIST_COMPARISON;
|
|
|
|
let is_entity_hostile = read_data
|
|
|
|
.alignments
|
|
|
|
.get(entity)
|
|
|
|
.zip(self.alignment)
|
|
|
|
.map_or(false, |(entity, me)| me.hostile_towards(*entity));
|
|
|
|
|
|
|
|
// Consider entity more dangerous than target if entity is closer or if target
|
|
|
|
// had not triggered aggro.
|
|
|
|
!target.aggro_on || (is_target_further && is_entity_hostile)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2022-05-01 15:06:43 +00:00
|
|
|
|
|
|
|
fn remembers_fight_with(&self, other: EcsEntity, read_data: &ReadData) -> bool {
|
|
|
|
let name = || read_data.stats.get(other).map(|stats| stats.name.clone());
|
|
|
|
|
|
|
|
self.rtsim_entity.map_or(false, |rtsim_entity| {
|
|
|
|
name().map_or(false, |name| {
|
|
|
|
rtsim_entity.brain.remembers_fight_with_character(&name)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
}
|
2022-03-30 00:04:20 +00:00
|
|
|
|
2022-04-26 18:22:55 +00:00
|
|
|
fn is_enemy(&self, entity: EcsEntity, read_data: &ReadData) -> bool {
|
2022-04-26 18:38:08 +00:00
|
|
|
let other_alignment = read_data.alignments.get(entity);
|
2022-03-30 00:04:20 +00:00
|
|
|
|
|
|
|
(entity != *self.entity)
|
2022-04-26 18:38:08 +00:00
|
|
|
&& !self.passive_towards(entity, read_data)
|
|
|
|
&& (are_our_owners_hostile(self.alignment, other_alignment, read_data)
|
2022-03-30 00:04:20 +00:00
|
|
|
|| self.remembers_fight_with(entity, read_data)
|
2022-04-24 20:15:30 +00:00
|
|
|
|| (is_villager(self.alignment) && is_dressed_as_cultist(entity, read_data)))
|
2022-03-30 00:04:20 +00:00
|
|
|
}
|
|
|
|
|
2022-04-17 18:50:50 +00:00
|
|
|
fn should_defend(&self, entity: EcsEntity, read_data: &ReadData) -> bool {
|
2022-03-30 00:04:20 +00:00
|
|
|
let entity_alignment = read_data.alignments.get(entity);
|
|
|
|
|
|
|
|
let we_are_friendly = entity_alignment.map_or(false, |entity_alignment| {
|
|
|
|
self.alignment.map_or(false, |alignment| {
|
|
|
|
!alignment.hostile_towards(*entity_alignment)
|
|
|
|
})
|
|
|
|
});
|
|
|
|
let we_share_species = read_data.bodies.get(entity).map_or(false, |entity_body| {
|
|
|
|
self.body.map_or(false, |body| {
|
|
|
|
entity_body.is_same_species_as(body)
|
|
|
|
|| (entity_body.is_humanoid() && body.is_humanoid())
|
|
|
|
})
|
|
|
|
});
|
|
|
|
let self_owns_entity =
|
|
|
|
matches!(entity_alignment, Some(Alignment::Owned(ouid)) if *self.uid == *ouid);
|
|
|
|
|
|
|
|
(we_are_friendly && we_share_species)
|
2022-04-17 18:50:50 +00:00
|
|
|
|| (is_village_guard(*self.entity, read_data) && is_villager(entity_alignment))
|
2022-03-30 00:04:20 +00:00
|
|
|
|| self_owns_entity
|
|
|
|
}
|
2022-04-26 18:38:08 +00:00
|
|
|
|
|
|
|
fn passive_towards(&self, entity: EcsEntity, read_data: &ReadData) -> bool {
|
|
|
|
if let (Some(self_alignment), Some(other_alignment)) =
|
|
|
|
(self.alignment, read_data.alignments.get(entity))
|
|
|
|
{
|
|
|
|
self_alignment.passive_towards(*other_alignment)
|
|
|
|
} else {
|
|
|
|
false
|
|
|
|
}
|
|
|
|
}
|
2022-04-28 00:29:10 +00:00
|
|
|
|
|
|
|
fn can_see_entity(
|
|
|
|
&self,
|
|
|
|
agent: &Agent,
|
|
|
|
controller: &Controller,
|
2022-04-29 21:00:14 +00:00
|
|
|
other: EcsEntity,
|
|
|
|
other_pos: &Pos,
|
2022-04-28 00:29:10 +00:00
|
|
|
read_data: &ReadData,
|
|
|
|
) -> bool {
|
|
|
|
let other_stealth_coefficient = {
|
|
|
|
let is_other_stealthy = read_data
|
|
|
|
.char_states
|
|
|
|
.get(other)
|
|
|
|
.map_or(false, CharacterState::is_stealthy);
|
|
|
|
|
|
|
|
if is_other_stealthy {
|
|
|
|
// TODO: We shouldn't have to check CharacterState. This should be factored in
|
|
|
|
// by the function (such as the one we're calling below) that supposedly
|
|
|
|
// computes a coefficient given stealthy-ness.
|
|
|
|
compute_stealth_coefficient(read_data.inventories.get(other))
|
|
|
|
} else {
|
|
|
|
1.0
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
let dist_sqrd = other_pos.0.distance_squared(self.pos.0);
|
|
|
|
|
|
|
|
let within_sight_dist = {
|
|
|
|
let sight_dist = agent.psyche.sight_dist / other_stealth_coefficient;
|
|
|
|
dist_sqrd < sight_dist.powi(2)
|
|
|
|
};
|
|
|
|
|
|
|
|
let within_fov = (other_pos.0 - self.pos.0)
|
|
|
|
.try_normalized()
|
|
|
|
.map_or(false, |v| v.dot(*controller.inputs.look_dir) > 0.15);
|
|
|
|
|
|
|
|
let other_body = read_data.bodies.get(other);
|
|
|
|
|
|
|
|
within_sight_dist
|
|
|
|
&& within_fov
|
|
|
|
&& entities_have_line_of_sight(self.pos, self.body, other_pos, other_body, read_data)
|
|
|
|
}
|
2021-07-12 15:40:29 +00:00
|
|
|
}
|