2020-07-08 01:41:20 +02:00
|
|
|
|
#nullable enable
|
|
|
|
|
|
using System;
|
Bodysystem and damagesystem rework (#1544)
* Things and stuff with grids, unfinished w/ code debug changes.
* Updated submodule and also lost some progress cause I fucked it up xd
* First unfinished draft of the BodySystem. Doesn't compile.
* More changes to make it compile, but still just a framework. Doesn't do anything at the moment.
* Many cleanup changes.
* Revert "Merge branch 'master' of https://github.com/GlassEclipse/space-station-14 into body_system"
This reverts commit ddd4aebbc76cf2a0b7b102f72b93d55a0816c88c, reversing
changes made to 12d0dd752706bdda8879393bd8191a1199a0c978.
* Commit human.yml
* Updated a lot of things to be more classy, more progress overall, etc. etc.
* Latest update with many changes
* Minor changes
* Fixed Travis build bug
* Adds first draft of Body Scanner console, apparently I also forgot to tie Mechanisms into body parts so now a heart just sits in the Torso like a good boy :)
* Commit rest of stuff
* Latest changes
* Latest changes again
* 14 naked cowboys
* Yay!
* Latest changes (probably doesnt compile)
* Surgery!!!!!!!!!~1116y
* Cleaned some stuff up
* More cleanup
* Refactoring of code. Basic surgery path now done.
* Removed readme, has been added to HackMD
* Fixes typo (and thus test errors)
* WIP changes, committing so I can pull latest master changes
* Still working on that god awful merge
* Latest changes
* Latest changes!!
* Beginning of refactor to BoundUserInterface
* Surgery!
* Latest changes - fixes pr change requests and random fixes
* oops
* Fixes bodypart recursion
* Beginning of work on revamping the damage system.
* More latest changes
* Latest changes
* Finished merge
* Commit before removing old healthcode
* Almost done with removing speciescomponent...
* It compiles!!!
* yahoo more work
* Fixes to make it work
* Merge conflict fixes
* Deleting species visualizer was a mistake
* IDE warnings are VERBOTEN
* makes the server not kill itself on startup, some cleanup (#1)
* Namespaces, comments and exception fixes
* Fix conveyor and conveyor switch serialization
SS14 in reactive when
* Move damage, acts and body to shared
Damage cleanup
Comment cleanup
* Rename SpeciesComponent to RotationComponent and cleanup
Damage cleanup
Comment cleanup
* Fix nullable warnings
* Address old reviews
Fix off welder suicide damage type, deathmatch and suspicion
* Fix new test fail with units being able to accept items when unpowered
* Remove RotationComponent, change references to IBodyManagerComponent
* Add a bloodstream to humans
* More cleanups
* Add body conduits, connections, connectors substances and valves
* Revert "Add body conduits, connections, connectors substances and valves"
This reverts commit 9ab0b50e6b15fe98852d7b0836c0cdbf4bd76d20.
* Implement the heart mechanism behavior with the circulatory network
* Added network property to mechanism behaviors
* Changed human organ sprites and added missing ones
* Fix tests
* Add individual body part sprite rendering
* Fix error where dropped mechanisms are not initialized
* Implement client/server body damage
* Make DamageContainer take care of raising events
* Reimplement medical scanner with the new body system
* Improve the medical scanner ui
* Merge conflict fixes
* Fix crash when colliding with something
* Fix microwave suicides and eyes sprite rendering
* Fix nullable reference error
* Fix up surgery client side
* Fix missing using from merge conflict
* Add breathing
*inhale
* Merge conflict fixes
* Fix accumulatedframetime being reset to 0 instead of decreased by the threshold
https://github.com/space-wizards/space-station-14/pull/1617
* Use and add to the new AtmosHelpers
* Fix feet
* Add proper coloring to dropped body parts
* Fix Urist's lungs being too strong
* Merge conflict fixes
* Merge conflict fixes
* Merge conflict fixes
Co-authored-by: GlassEclipse <tsymall5@gmail.com>
Co-authored-by: Pieter-Jan Briers <pieterjan.briers+git@gmail.com>
Co-authored-by: AJCM-git <60196617+AJCM-git@users.noreply.github.com>
2020-08-17 01:42:42 +02:00
|
|
|
|
using Content.Shared.GameObjects.Components.Body;
|
2021-02-11 01:13:03 -08:00
|
|
|
|
using Robust.Shared.Configuration;
|
2020-06-24 02:21:20 +02:00
|
|
|
|
using Robust.Shared.GameObjects;
|
|
|
|
|
|
using Robust.Shared.IoC;
|
|
|
|
|
|
using Robust.Shared.Log;
|
|
|
|
|
|
using Robust.Shared.Map;
|
|
|
|
|
|
using Robust.Shared.Maths;
|
|
|
|
|
|
using Robust.Shared.Physics;
|
2021-02-18 09:09:07 +01:00
|
|
|
|
using Robust.Shared.Players;
|
2020-06-24 02:21:20 +02:00
|
|
|
|
using Robust.Shared.Serialization;
|
|
|
|
|
|
using Robust.Shared.Timing;
|
|
|
|
|
|
using Robust.Shared.ViewVariables;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Content.Shared.GameObjects.Components.Movement
|
|
|
|
|
|
{
|
2020-06-24 11:58:13 +02:00
|
|
|
|
public abstract class SharedPlayerInputMoverComponent : Component, IMoverComponent, ICollideSpecial
|
2020-06-24 02:21:20 +02:00
|
|
|
|
{
|
|
|
|
|
|
// This class has to be able to handle server TPS being lower than client FPS.
|
|
|
|
|
|
// While still having perfectly responsive movement client side.
|
|
|
|
|
|
// We do this by keeping track of the exact sub-tick values that inputs are pressed on the client,
|
|
|
|
|
|
// and then building a total movement vector based on those sub-tick steps.
|
|
|
|
|
|
//
|
|
|
|
|
|
// We keep track of the last sub-tick a movement input came in,
|
|
|
|
|
|
// Then when a new input comes in, we calculate the fraction of the tick the LAST input was active for
|
|
|
|
|
|
// (new sub-tick - last sub-tick)
|
|
|
|
|
|
// and then add to the total-this-tick movement vector
|
|
|
|
|
|
// by multiplying that fraction by the movement direction for the last input.
|
|
|
|
|
|
// This allows us to incrementally build the movement vector for the current tick,
|
|
|
|
|
|
// without having to keep track of some kind of list of inputs and calculating it later.
|
|
|
|
|
|
//
|
|
|
|
|
|
// We have to keep track of a separate movement vector for walking and sprinting,
|
|
|
|
|
|
// since we don't actually know our current movement speed while processing inputs.
|
|
|
|
|
|
// We change which vector we write into based on whether we were sprinting after the previous input.
|
|
|
|
|
|
// (well maybe we do but the code is designed such that MoverSystem applies movement speed)
|
|
|
|
|
|
// (and I'm not changing that)
|
|
|
|
|
|
|
|
|
|
|
|
[Dependency] private readonly IConfigurationManager _configurationManager = default!;
|
|
|
|
|
|
[Dependency] private readonly IGameTiming _gameTiming = default!;
|
|
|
|
|
|
|
|
|
|
|
|
public sealed override string Name => "PlayerInputMover";
|
|
|
|
|
|
public sealed override uint? NetID => ContentNetIDs.PLAYER_INPUT_MOVER;
|
|
|
|
|
|
|
|
|
|
|
|
private GameTick _lastInputTick;
|
|
|
|
|
|
private ushort _lastInputSubTick;
|
|
|
|
|
|
private Vector2 _curTickWalkMovement;
|
|
|
|
|
|
private Vector2 _curTickSprintMovement;
|
|
|
|
|
|
|
|
|
|
|
|
private MoveButtons _heldMoveButtons = MoveButtons.None;
|
|
|
|
|
|
|
|
|
|
|
|
public float CurrentWalkSpeed
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2020-08-20 16:48:00 +02:00
|
|
|
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component))
|
2020-06-24 02:21:20 +02:00
|
|
|
|
{
|
|
|
|
|
|
return component.CurrentWalkSpeed;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return MovementSpeedModifierComponent.DefaultBaseWalkSpeed;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public float CurrentSprintSpeed
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
2020-08-20 16:48:00 +02:00
|
|
|
|
if (Owner.TryGetComponent(out MovementSpeedModifierComponent? component))
|
2020-06-24 02:21:20 +02:00
|
|
|
|
{
|
|
|
|
|
|
return component.CurrentSprintSpeed;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return MovementSpeedModifierComponent.DefaultBaseSprintSpeed;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-08 13:30:22 +02:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2020-06-24 02:21:20 +02:00
|
|
|
|
public float CurrentPushSpeed => 5;
|
2020-09-08 13:30:22 +02:00
|
|
|
|
[ViewVariables(VVAccess.ReadWrite)]
|
2020-06-24 02:21:20 +02:00
|
|
|
|
public float GrabRange => 0.2f;
|
2020-06-29 22:51:47 -07:00
|
|
|
|
public bool Sprinting => !HasFlag(_heldMoveButtons, MoveButtons.Walk);
|
2020-06-24 02:21:20 +02:00
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Calculated linear velocity direction of the entity.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ViewVariables]
|
|
|
|
|
|
public (Vector2 walking, Vector2 sprinting) VelocityDir
|
|
|
|
|
|
{
|
|
|
|
|
|
get
|
|
|
|
|
|
{
|
|
|
|
|
|
if (!_gameTiming.InSimulation)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Outside of simulation we'll be running client predicted movement per-frame.
|
|
|
|
|
|
// So return a full-length vector as if it's a full tick.
|
|
|
|
|
|
// Physics system will have the correct time step anyways.
|
|
|
|
|
|
var immediateDir = DirVecForButtons(_heldMoveButtons);
|
|
|
|
|
|
return Sprinting ? (Vector2.Zero, immediateDir) : (immediateDir, Vector2.Zero);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Vector2 walk;
|
|
|
|
|
|
Vector2 sprint;
|
|
|
|
|
|
float remainingFraction;
|
|
|
|
|
|
|
|
|
|
|
|
if (_gameTiming.CurTick > _lastInputTick)
|
|
|
|
|
|
{
|
|
|
|
|
|
walk = Vector2.Zero;
|
|
|
|
|
|
sprint = Vector2.Zero;
|
|
|
|
|
|
remainingFraction = 1;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
walk = _curTickWalkMovement;
|
|
|
|
|
|
sprint = _curTickSprintMovement;
|
|
|
|
|
|
remainingFraction = (ushort.MaxValue - _lastInputSubTick) / (float) ushort.MaxValue;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var curDir = DirVecForButtons(_heldMoveButtons) * remainingFraction;
|
|
|
|
|
|
|
|
|
|
|
|
if (Sprinting)
|
|
|
|
|
|
{
|
|
|
|
|
|
sprint += curDir;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
walk += curDir;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Logger.Info($"{curDir}{walk}{sprint}");
|
|
|
|
|
|
return (walk, sprint);
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-09-06 16:11:53 +02:00
|
|
|
|
public abstract EntityCoordinates LastPosition { get; set; }
|
2020-06-24 02:21:20 +02:00
|
|
|
|
public abstract float StepSoundDistance { get; set; }
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Whether or not the player can move diagonally.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
[ViewVariables]
|
2020-11-07 01:15:56 +01:00
|
|
|
|
public bool DiagonalMovementEnabled => _configurationManager.GetCVar<bool>(CCVars.GameDiagonalMovement);
|
2020-06-24 02:21:20 +02:00
|
|
|
|
|
|
|
|
|
|
/// <inheritdoc />
|
|
|
|
|
|
public override void OnAdd()
|
|
|
|
|
|
{
|
2020-10-11 16:36:58 +02:00
|
|
|
|
// This component requires that the entity has a IPhysicsComponent.
|
|
|
|
|
|
if (!Owner.HasComponent<IPhysicsComponent>())
|
2020-06-24 02:21:20 +02:00
|
|
|
|
Logger.Error(
|
|
|
|
|
|
$"[ECS] {Owner.Prototype?.Name} - {nameof(SharedPlayerInputMoverComponent)} requires" +
|
2020-10-11 16:36:58 +02:00
|
|
|
|
$" {nameof(IPhysicsComponent)}. ");
|
2020-06-24 02:21:20 +02:00
|
|
|
|
|
|
|
|
|
|
base.OnAdd();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Toggles one of the four cardinal directions. Each of the four directions are
|
|
|
|
|
|
/// composed into a single direction vector, <see cref="VelocityDir"/>. Enabling
|
|
|
|
|
|
/// opposite directions will cancel each other out, resulting in no direction.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
/// <param name="direction">Direction to toggle.</param>
|
|
|
|
|
|
/// <param name="subTick"></param>
|
|
|
|
|
|
/// <param name="enabled">If the direction is active.</param>
|
|
|
|
|
|
public void SetVelocityDirection(Direction direction, ushort subTick, bool enabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Logger.Info($"[{_gameTiming.CurTick}/{subTick}] {direction}: {enabled}");
|
|
|
|
|
|
|
|
|
|
|
|
var bit = direction switch
|
|
|
|
|
|
{
|
|
|
|
|
|
Direction.East => MoveButtons.Right,
|
|
|
|
|
|
Direction.North => MoveButtons.Up,
|
|
|
|
|
|
Direction.West => MoveButtons.Left,
|
|
|
|
|
|
Direction.South => MoveButtons.Down,
|
|
|
|
|
|
_ => throw new ArgumentException(nameof(direction))
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
SetMoveInput(subTick, enabled, bit);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private void SetMoveInput(ushort subTick, bool enabled, MoveButtons bit)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Modifies held state of a movement button at a certain sub tick and updates current tick movement vectors.
|
|
|
|
|
|
|
|
|
|
|
|
if (_gameTiming.CurTick > _lastInputTick)
|
|
|
|
|
|
{
|
|
|
|
|
|
_curTickWalkMovement = Vector2.Zero;
|
|
|
|
|
|
_curTickSprintMovement = Vector2.Zero;
|
|
|
|
|
|
_lastInputTick = _gameTiming.CurTick;
|
|
|
|
|
|
_lastInputSubTick = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-07-08 02:59:07 +02:00
|
|
|
|
if (subTick >= _lastInputSubTick)
|
2020-07-08 01:28:49 +02:00
|
|
|
|
{
|
|
|
|
|
|
var fraction = (subTick - _lastInputSubTick) / (float) ushort.MaxValue;
|
|
|
|
|
|
|
|
|
|
|
|
ref var lastMoveAmount = ref Sprinting ? ref _curTickSprintMovement : ref _curTickWalkMovement;
|
2020-06-24 02:21:20 +02:00
|
|
|
|
|
2020-07-08 01:28:49 +02:00
|
|
|
|
lastMoveAmount += DirVecForButtons(_heldMoveButtons) * fraction;
|
2020-06-24 02:21:20 +02:00
|
|
|
|
|
2020-07-08 01:28:49 +02:00
|
|
|
|
_lastInputSubTick = subTick;
|
|
|
|
|
|
}
|
2020-06-24 02:21:20 +02:00
|
|
|
|
|
|
|
|
|
|
if (enabled)
|
|
|
|
|
|
{
|
|
|
|
|
|
_heldMoveButtons |= bit;
|
|
|
|
|
|
}
|
|
|
|
|
|
else
|
|
|
|
|
|
{
|
|
|
|
|
|
_heldMoveButtons &= ~bit;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
Dirty();
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-24 04:04:43 +02:00
|
|
|
|
public void SetSprinting(ushort subTick, bool walking)
|
2020-06-24 02:21:20 +02:00
|
|
|
|
{
|
|
|
|
|
|
// Logger.Info($"[{_gameTiming.CurTick}/{subTick}] Sprint: {enabled}");
|
|
|
|
|
|
|
2020-06-24 04:04:43 +02:00
|
|
|
|
SetMoveInput(subTick, walking, MoveButtons.Walk);
|
2020-06-24 02:21:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
public override void HandleComponentState(ComponentState? curState, ComponentState? nextState)
|
|
|
|
|
|
{
|
|
|
|
|
|
if (curState is MoverComponentState state)
|
|
|
|
|
|
{
|
|
|
|
|
|
_heldMoveButtons = state.Buttons;
|
|
|
|
|
|
_lastInputTick = GameTick.Zero;
|
|
|
|
|
|
_lastInputSubTick = 0;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2021-02-18 09:09:07 +01:00
|
|
|
|
public override ComponentState GetComponentState(ICommonSession player)
|
2020-06-24 02:21:20 +02:00
|
|
|
|
{
|
|
|
|
|
|
return new MoverComponentState(_heldMoveButtons);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
|
/// Retrieves the normalized direction vector for a specified combination of movement keys.
|
|
|
|
|
|
/// </summary>
|
|
|
|
|
|
private Vector2 DirVecForButtons(MoveButtons buttons)
|
|
|
|
|
|
{
|
|
|
|
|
|
// key directions are in screen coordinates
|
|
|
|
|
|
// _moveDir is in world coordinates
|
|
|
|
|
|
// if the camera is moved, this needs to be changed
|
|
|
|
|
|
|
|
|
|
|
|
var x = 0;
|
2020-06-29 22:51:47 -07:00
|
|
|
|
x -= HasFlag(buttons, MoveButtons.Left) ? 1 : 0;
|
|
|
|
|
|
x += HasFlag(buttons, MoveButtons.Right) ? 1 : 0;
|
2020-06-24 02:21:20 +02:00
|
|
|
|
|
|
|
|
|
|
var y = 0;
|
|
|
|
|
|
if (DiagonalMovementEnabled || x == 0)
|
|
|
|
|
|
{
|
2020-06-29 22:51:47 -07:00
|
|
|
|
y -= HasFlag(buttons, MoveButtons.Down) ? 1 : 0;
|
|
|
|
|
|
y += HasFlag(buttons, MoveButtons.Up) ? 1 : 0;
|
2020-06-24 02:21:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var vec = new Vector2(x, y);
|
|
|
|
|
|
|
|
|
|
|
|
// can't normalize zero length vector
|
|
|
|
|
|
if (vec.LengthSquared > 1.0e-6)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Normalize so that diagonals aren't faster or something.
|
|
|
|
|
|
vec = vec.Normalized;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return vec;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-24 11:58:13 +02:00
|
|
|
|
bool ICollideSpecial.PreventCollide(IPhysBody collidedWith)
|
|
|
|
|
|
{
|
|
|
|
|
|
// Don't collide with other mobs
|
2020-10-10 15:25:13 +02:00
|
|
|
|
return collidedWith.Entity.HasComponent<IBody>();
|
2020-06-24 11:58:13 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
2020-06-24 02:21:20 +02:00
|
|
|
|
[Serializable, NetSerializable]
|
|
|
|
|
|
private sealed class MoverComponentState : ComponentState
|
|
|
|
|
|
{
|
|
|
|
|
|
public MoveButtons Buttons { get; }
|
|
|
|
|
|
|
|
|
|
|
|
public MoverComponentState(MoveButtons buttons) : base(ContentNetIDs
|
|
|
|
|
|
.PLAYER_INPUT_MOVER)
|
|
|
|
|
|
{
|
|
|
|
|
|
Buttons = buttons;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
[Flags]
|
|
|
|
|
|
private enum MoveButtons : byte
|
|
|
|
|
|
{
|
|
|
|
|
|
None = 0,
|
|
|
|
|
|
Up = 1,
|
|
|
|
|
|
Down = 2,
|
|
|
|
|
|
Left = 4,
|
|
|
|
|
|
Right = 8,
|
2020-06-24 04:04:43 +02:00
|
|
|
|
Walk = 16,
|
2020-06-24 02:21:20 +02:00
|
|
|
|
}
|
2020-06-29 22:51:47 -07:00
|
|
|
|
|
|
|
|
|
|
private static bool HasFlag(MoveButtons buttons, MoveButtons flag)
|
|
|
|
|
|
{
|
|
|
|
|
|
return (buttons & flag) == flag;
|
|
|
|
|
|
}
|
2020-06-24 02:21:20 +02:00
|
|
|
|
}
|
|
|
|
|
|
}
|