Skip to content

Commit

Permalink
Constrict Height and Width via a Size Ratio & Fix Humanoids Not Havin…
Browse files Browse the repository at this point in the history
…g A Fixture (DeltaV-Station#1049)

# Description

Title
Intended to stop players from making slender men type characters with
height maxed and width at the minimum, and vice versa
The ratio can be modified via the species' prototype

Also fixes the issue of players being able to noclip because they're
fixture has no radius by setting the Height and Width to the species
default if none is provided. (technically this also fixes Urists always
being as small as possible)

Solves DeltaV-Station#865 DeltaV-Station#497
Partially resolves DeltaV-Station#995

---

<details><summary><h1>Media</h1></summary>
<p>


https://github.com/user-attachments/assets/1b3b32f1-5976-41f8-935b-7d53106e5452

</p>
</details>

---

# Changelog

:cl:
- tweak: Height and width are now constrained by each other.
- fix: Humanoids can no longer phase through walls.

---------

Signed-off-by: Aiden <[email protected]>
Co-authored-by: VMSolidus <[email protected]>
Co-authored-by: DEATHB4DEFEAT <[email protected]>
  • Loading branch information
3 people authored Oct 16, 2024
1 parent 7c1ff61 commit 0865e47
Show file tree
Hide file tree
Showing 3 changed files with 73 additions and 77 deletions.
135 changes: 59 additions & 76 deletions Content.Client/Lobby/UI/HumanoidProfileEditor.xaml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ public HumanoidProfileEditor(
UpdateHairPickers();
OnSkinColorOnValueChanged();
UpdateCustomSpecieNameEdit();
UpdateHeightWidthSliders();
};

#endregion Species
Expand All @@ -195,76 +196,24 @@ public HumanoidProfileEditor(

var prototype = _species.Find(x => x.ID == Profile?.Species) ?? _species.First();

HeightSlider.MinValue = prototype.MinHeight;
HeightSlider.MaxValue = prototype.MaxHeight;
HeightSlider.Value = Profile?.Height ?? prototype.DefaultHeight;
var height = MathF.Round(prototype.AverageHeight * HeightSlider.Value);
HeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", (int) height));

HeightSlider.OnValueChanged += args =>
{
if (Profile is null)
return;

prototype = _species.Find(x => x.ID == Profile.Species) ?? _species.First(); // Just in case
UpdateHeightWidthSliders();
UpdateDimensions(SliderUpdate.Both);

var value = Math.Clamp(args.Value, prototype.MinHeight, prototype.MaxHeight);
var height = MathF.Round(prototype.AverageHeight * value);
HeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", (int) height));
SetProfileHeight(value);
UpdateWeight();
};
HeightSlider.OnValueChanged += _ => UpdateDimensions(SliderUpdate.Height);
WidthSlider.OnValueChanged += _ => UpdateDimensions(SliderUpdate.Width);

HeightReset.OnPressed += _ =>
{
HeightSlider.Value = prototype.DefaultHeight;
SetProfileHeight(prototype.DefaultHeight);
UpdateWeight();
};


WidthSlider.MinValue = prototype.MinWidth;
WidthSlider.MaxValue = prototype.MaxWidth;
WidthSlider.Value = Profile?.Width ?? prototype.DefaultWidth;
var width = MathF.Round(prototype.AverageWidth * WidthSlider.Value);
WidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", width));

WidthSlider.OnValueChanged += args =>
{
if (Profile is null)
return;

prototype = _species.Find(x => x.ID == Profile.Species) ?? _species.First(); // Just in case

var value = Math.Clamp(args.Value, prototype.MinWidth, prototype.MaxWidth);
var width = MathF.Round(prototype.AverageWidth * value);
WidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", width));
SetProfileWidth(value);
UpdateWeight();
UpdateDimensions(SliderUpdate.Height);
};

WidthReset.OnPressed += _ =>
{
WidthSlider.Value = prototype.DefaultWidth;
SetProfileWidth(prototype.DefaultWidth);
UpdateWeight();
UpdateDimensions(SliderUpdate.Width);
};

prototypeManager.Index(prototype.Prototype).TryGetComponent<FixturesComponent>(out var fixture);
if (fixture != null)
{
var radius = fixture.Fixtures["fix1"].Shape.Radius;
var density = fixture.Fixtures["fix1"].Density;
var avg = (WidthSlider.Value + HeightSlider.Value) / 2;
var weight = MathF.Round(MathF.PI * MathF.Pow(radius * avg, 2) * density);
WeightLabel.Text = Loc.GetString("humanoid-profile-editor-weight-label", ("weight", (int) weight));
}
else
{
// Whelp, the fixture doesn't exist, guesstimate it instead
WeightLabel.Text = Loc.GetString("humanoid-profile-editor-weight-label", ("weight", (int) 71));
}

#endregion Height

#region Skin
Expand Down Expand Up @@ -697,8 +646,7 @@ public void SetProfile(HumanoidCharacterProfile? profile, int? slot)
UpdateHairPickers();
UpdateCMarkingsHair();
UpdateCMarkingsFacialHair();
UpdateHeightControls();
UpdateWidthControls();
UpdateHeightWidthSliders();
UpdateWeight();
UpdateCharacterRequired();

Expand Down Expand Up @@ -1193,8 +1141,7 @@ private void SetSpecies(string newSpecies)
UpdateSexControls(); // Update sex for new species
UpdateCharacterRequired();
// Changing species provides inaccurate sliders without these
UpdateHeightControls();
UpdateWidthControls();
UpdateHeightWidthSliders();
UpdateWeight();
UpdateSpeciesGuidebookIcon();
IsDirty = true;
Expand Down Expand Up @@ -1411,34 +1358,68 @@ private void UpdateSpawnPriorityControls()
SpawnPriorityButton.SelectId((int) Profile.SpawnPriority);
}

private void UpdateHeightControls()
private void UpdateHeightWidthSliders()
{
if (Profile == null)
return;

var species = _species.Find(x => x.ID == Profile.Species) ?? _species.First();
var species = _species.Find(x => x.ID == Profile?.Species) ?? _species.First();

HeightSlider.MinValue = species.MinHeight;
HeightSlider.Value = Profile.Height;
HeightSlider.MaxValue = species.MaxHeight;
HeightSlider.Value = Profile?.Height ?? species.DefaultHeight;

WidthSlider.MinValue = species.MinWidth;
WidthSlider.MaxValue = species.MaxWidth;
WidthSlider.Value = Profile?.Width ?? species.DefaultWidth;

var height = MathF.Round(species.AverageHeight * HeightSlider.Value);
HeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", (int) height));

var width = MathF.Round(species.AverageWidth * WidthSlider.Value);
WidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", (int) width));
}

private void UpdateWidthControls()
private enum SliderUpdate
{
if (Profile == null)
return;
Height,
Width,
Both
}

var species = _species.Find(x => x.ID == Profile.Species) ?? _species.First();
private void UpdateDimensions(SliderUpdate updateType)
{
var species = _species.Find(x => x.ID == Profile?.Species) ?? _species.First();

WidthSlider.MinValue = species.MinWidth;
WidthSlider.Value = Profile.Width;
WidthSlider.MaxValue = species.MaxWidth;
if (Profile == null) return;

var heightValue = Math.Clamp(HeightSlider.Value, species.MinHeight, species.MaxHeight);
var widthValue = Math.Clamp(WidthSlider.Value, species.MinWidth, species.MaxWidth);
var sizeRatio = species.SizeRatio;
var ratio = heightValue / widthValue;

if (updateType == SliderUpdate.Height || updateType == SliderUpdate.Both)
if (ratio < 1 / sizeRatio || ratio > sizeRatio)
widthValue = heightValue / (ratio < 1 / sizeRatio ? (1 / sizeRatio) : sizeRatio);

if (updateType == SliderUpdate.Width || updateType == SliderUpdate.Both)
if (ratio < 1 / sizeRatio || ratio > sizeRatio)
heightValue = widthValue * (ratio < 1 / sizeRatio ? (1 / sizeRatio) : sizeRatio);


heightValue = Math.Clamp(heightValue, species.MinHeight, species.MaxHeight);
widthValue = Math.Clamp(widthValue, species.MinWidth, species.MaxWidth);

HeightSlider.Value = heightValue;
WidthSlider.Value = widthValue;

SetProfileHeight(heightValue);
SetProfileWidth(widthValue);

var height = MathF.Round(species.AverageHeight * HeightSlider.Value);
HeightLabel.Text = Loc.GetString("humanoid-profile-editor-height-label", ("height", (int) height));

var width = MathF.Round(species.AverageWidth * WidthSlider.Value);
WidthLabel.Text = Loc.GetString("humanoid-profile-editor-width-label", ("width", (int) width));

UpdateWeight();
}

private void UpdateWeight()
Expand All @@ -1456,7 +1437,9 @@ private void UpdateWeight()
var avg = (Profile.Width + Profile.Height) / 2;
var weight = MathF.Round(MathF.PI * MathF.Pow(radius * avg, 2) * density);
WeightLabel.Text = Loc.GetString("humanoid-profile-editor-weight-label", ("weight", (int) weight));
}
}
else // Whelp, the fixture doesn't exist, guesstimate it instead
WeightLabel.Text = Loc.GetString("humanoid-profile-editor-weight-label", ("weight", (int) 71));

SpriteView.InvalidateMeasure();
}
Expand Down
6 changes: 6 additions & 0 deletions Content.Shared/Humanoid/Prototypes/SpeciesPrototype.cs
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,12 @@ public sealed partial class SpeciesPrototype : IPrototype
[DataField]
public int MaxAge = 120;

/// <summary>
/// The minimum height and width ratio for this species
/// </summary>
[DataField]
public float SizeRatio = 1.2f;

/// <summary>
/// The minimum height for this species
/// </summary>
Expand Down
9 changes: 8 additions & 1 deletion Content.Shared/Humanoid/SharedHumanoidAppearanceSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,14 @@ public virtual void LoadProfile(EntityUid uid, HumanoidCharacterProfile profile,

humanoid.CustomSpecieName = profile.Customspeciename;

_heightAdjust.SetScale(uid, new Vector2(profile.Width, profile.Height));
var species = _proto.Index(humanoid.Species);

if (profile.Height <= 0 || profile.Width <= 0)
SetScale(uid, new Vector2(species.DefaultWidth, species.DefaultHeight), true, humanoid);
else
SetScale(uid, new Vector2(profile.Width, profile.Height), true, humanoid);

_heightAdjust.SetScale(uid, new Vector2(humanoid.Width, humanoid.Height));

humanoid.LastProfileLoaded = profile; // DeltaV - let paradox anomaly be cloned

Expand Down

0 comments on commit 0865e47

Please sign in to comment.