Smol animals

This commit is contained in:
Joshua Barretto 2022-08-11 18:57:13 +01:00
parent f140a94dc6
commit 8ff438bb5b
4 changed files with 10 additions and 7 deletions

View File

@ -654,6 +654,7 @@ impl ServerChatCommand {
Enum("entity", ENTITIES.clone(), Required),
Integer("amount", 1, Optional),
Boolean("ai", "true".to_string(), Optional),
Float("ai", 1.0, Optional),
],
"Spawn a test entity",
Some(Admin),

View File

@ -1,5 +1,5 @@
use common::{
comp::{Body, Controller, InputKind, Ori, Pos, Vel},
comp::{Body, Controller, InputKind, Ori, Pos, Vel, Scale},
link::Is,
mounting::Mount,
uid::UidAllocator,
@ -24,6 +24,7 @@ impl<'a> System<'a> for Sys {
WriteStorage<'a, Vel>,
WriteStorage<'a, Ori>,
ReadStorage<'a, Body>,
ReadStorage<'a, Scale>,
);
const NAME: &'static str = "mount";
@ -41,6 +42,7 @@ impl<'a> System<'a> for Sys {
mut velocities,
mut orientations,
bodies,
scales,
): Self::SystemData,
) {
// For each mount...
@ -67,8 +69,8 @@ impl<'a> System<'a> for Sys {
let vel = velocities.get(entity).copied();
if let (Some(pos), Some(ori), Some(vel)) = (pos, ori, vel) {
let mounter_body = bodies.get(rider);
let mounting_offset = body.map_or(Vec3::unit_z(), Body::mount_offset)
+ mounter_body.map_or(Vec3::zero(), Body::rider_offset);
let mounting_offset = body.map_or(Vec3::unit_z(), Body::mount_offset) * scales.get(entity).map_or(1.0, |s| s.0)
+ mounter_body.map_or(Vec3::zero(), Body::rider_offset) * scales.get(rider).map_or(1.0, |s| s.0);
let _ = positions.insert(rider, Pos(pos.0 + ori.to_quat() * mounting_offset));
let _ = orientations.insert(rider, ori);
let _ = velocities.insert(rider, vel);

View File

@ -1189,8 +1189,8 @@ fn handle_spawn(
args: Vec<String>,
action: &ServerChatCommand,
) -> CmdResult<()> {
match parse_cmd_args!(args, String, npc::NpcBody, u32, bool) {
(Some(opt_align), Some(npc::NpcBody(id, mut body)), opt_amount, opt_ai) => {
match parse_cmd_args!(args, String, npc::NpcBody, u32, bool, f32) {
(Some(opt_align), Some(npc::NpcBody(id, mut body)), opt_amount, opt_ai, opt_scale) => {
let uid = uid(server, target, "target")?;
let alignment = parse_alignment(uid, &opt_align)?;
let amount = opt_amount.filter(|x| *x > 0).unwrap_or(1).min(50);
@ -1227,7 +1227,7 @@ fn handle_spawn(
body,
)
.with(comp::Vel(vel))
.with(body.scale())
.with(opt_scale.map(comp::Scale).unwrap_or(body.scale()))
.with(alignment);
if ai {

View File

@ -809,7 +809,7 @@ impl FigureMgr {
const MIN_PERFECT_RATE_DIST: f32 = 100.0;
if (i as u64 + tick)
% (((pos.0.distance_squared(focus_pos).powf(0.25) - MIN_PERFECT_RATE_DIST.sqrt())
% ((((pos.0.distance_squared(focus_pos) / scale.map_or(1.0, |s| s.0)).powf(0.25) - MIN_PERFECT_RATE_DIST.sqrt())
.max(0.0)
/ 3.0) as u64)
.saturating_add(1)