Skip to content

Commit

Permalink
More Storage Rebalancing (space-wizards#21373)
Browse files Browse the repository at this point in the history
* the changes...

* eek
  • Loading branch information
EmoGarbage404 authored Nov 1, 2023
1 parent 9e7cac2 commit 85f09ca
Show file tree
Hide file tree
Showing 66 changed files with 188 additions and 201 deletions.
3 changes: 2 additions & 1 deletion Content.Client/Storage/UI/StorageWindow.cs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,8 @@ public StorageWindow(IEntityManager entityManager)
VerticalAlignment = VAlignment.Center
};
_information.SetMessage(Loc.GetString("comp-storage-window-weight",
("percent", 0),
("weight", 0),
("maxWeight", 0),
("size", SharedItemSystem.GetItemSizeLocale(ItemSize.Normal))));

vBox.AddChild(_information);
Expand Down
6 changes: 3 additions & 3 deletions Content.Shared/Item/ItemComponent.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,15 +89,15 @@ public enum ItemSize
/// <summary>
/// Items that are too large to fit inside of standard bags, but can worn in exterior slots or placed in custom containers.
/// </summary>
Large = 16,
Large = 8,

/// <summary>
/// Items that are too large to place inside of any kind of container.
/// </summary>
Huge = 24,
Huge = 16,

/// <summary>
/// Picture furry gf
/// </summary>
Ginormous = 48
Ginormous = 32
}
3 changes: 3 additions & 0 deletions Content.Shared/Stacks/SharedStackSystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -329,6 +329,9 @@ public bool TryAdd(EntityUid insertEnt, EntityUid targetEnt, int count, StackCom
if (!Resolve(insertEnt, ref insertStack) || !Resolve(targetEnt, ref targetStack))
return false;

if (insertStack.StackTypeId != targetStack.StackTypeId)
return false;

var available = GetAvailableSpace(targetStack);

if (available <= 0)
Expand Down
79 changes: 55 additions & 24 deletions Content.Shared/Storage/EntitySystems/SharedStorageSystem.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@
using System.Diagnostics.CodeAnalysis;
using System.Linq;
using Content.Shared.ActionBlocker;
using Content.Shared.CombatMode;
Expand Down Expand Up @@ -473,32 +472,35 @@ public bool CanInsert(EntityUid uid, EntityUid insertEnt, out string? reason, St
return false;
}

if (item.Size > GetMaxItemSize((uid, storageComp)))
if (!_stackQuery.TryGetComponent(insertEnt, out var stack) || !HasSpaceInStacks(uid, stack.StackTypeId))
{
reason = "comp-storage-too-big";
return false;
}
if (item.Size > GetMaxItemSize((uid, storageComp)))
{
reason = "comp-storage-too-big";
return false;
}

if (TryComp<StorageComponent>(insertEnt, out var insertStorage)
&& GetMaxItemSize((insertEnt, insertStorage)) >= GetMaxItemSize((uid, storageComp)))
{
reason = "comp-storage-too-big";
return false;
}
if (TryComp<StorageComponent>(insertEnt, out var insertStorage)
&& GetMaxItemSize((insertEnt, insertStorage)) >= GetMaxItemSize((uid, storageComp)))
{
reason = "comp-storage-too-big";
return false;
}

if (storageComp.MaxSlots != null)
{
if (storageComp.Container.ContainedEntities.Count >= storageComp.MaxSlots)
if (storageComp.MaxSlots != null)
{
if (storageComp.Container.ContainedEntities.Count >= storageComp.MaxSlots)
{
reason = "comp-storage-insufficient-capacity";
return false;
}
}
else if (SharedItemSystem.GetItemSizeWeight(item.Size) + GetCumulativeItemSizes(uid, storageComp) > storageComp.MaxTotalWeight)
{
reason = "comp-storage-insufficient-capacity";
return false;
}
}
else if (SharedItemSystem.GetItemSizeWeight(item.Size) + GetCumulativeItemSizes(uid, storageComp) > storageComp.MaxTotalWeight)
{
reason = "comp-storage-insufficient-capacity";
return false;
}

reason = null;
return true;
Expand Down Expand Up @@ -554,7 +556,7 @@ public bool Insert(

foreach (var ent in storageComp.Container.ContainedEntities)
{
if (!_stackQuery.TryGetComponent(ent, out var containedStack) || !insertStack.StackTypeId.Equals(containedStack.StackTypeId))
if (!_stackQuery.TryGetComponent(ent, out var containedStack))
continue;

if (!_stack.TryAdd(insertEnt, ent, insertStack, containedStack))
Expand All @@ -571,18 +573,24 @@ public bool Insert(
}

// Still stackable remaining
if (insertStack.Count > 0)
if (toInsertCount > 0)
{
// Try to insert it as a new stack.
if (!CanInsert(uid, insertEnt, out _, storageComp) ||
!storageComp.Container.Insert(insertEnt))
{
UpdateUI(uid, storageComp);

// If we also didn't do any stack fills above then just end
// otherwise play sound and update UI anyway.
if (toInsertCount == insertStack.Count)
return false;
}
}
else
{
UpdateUI(uid, storageComp);
}
}
// Non-stackable but no insertion for reasons.
else if (!storageComp.Container.Insert(insertEnt))
Expand Down Expand Up @@ -657,11 +665,32 @@ public bool HasSpace(Entity<StorageComponent?> uid)
//todo maybe this shouldn't be authoritative over weight? idk.
if (uid.Comp.MaxSlots != null)
{
return uid.Comp.Container.ContainedEntities.Count < uid.Comp.MaxSlots;
return uid.Comp.Container.ContainedEntities.Count < uid.Comp.MaxSlots || HasSpaceInStacks(uid);
}

return GetCumulativeItemSizes(uid, uid.Comp) < uid.Comp.MaxTotalWeight || HasSpaceInStacks(uid);
}

private bool HasSpaceInStacks(Entity<StorageComponent?> uid, string? stackType = null)
{
if (!Resolve(uid, ref uid.Comp))
return false;

foreach (var contained in uid.Comp.Container.ContainedEntities)
{
if (!_stackQuery.TryGetComponent(contained, out var stack))
continue;

if (stackType != null && !stack.StackTypeId.Equals(stackType))
continue;

if (_stack.GetAvailableSpace(stack) == 0)
continue;

return true;
}

return GetCumulativeItemSizes(uid, uid.Comp) < uid.Comp.MaxTotalWeight;
return false;
}

/// <summary>
Expand Down Expand Up @@ -697,7 +726,9 @@ public ItemSize GetMaxItemSize(Entity<StorageComponent?> uid)

// if there is no max item size specified, the value used
// is one below the item size of the storage entity, clamped at ItemSize.Tiny
return (ItemSize) Math.Max((int) item.Size - 1, 1);
var sizes = Enum.GetValues<ItemSize>().ToList();
var currentSizeIndex = sizes.IndexOf(item.Size);
return sizes[Math.Max(currentSizeIndex - 1, 0)];
}

public FixedPoint2 GetStorageFillPercentage(Entity<StorageComponent?> uid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,8 @@
name: death squad backpack
description: Holds the kit of CentComm's most feared agents.
components:
- type: Storage
maxTotalWeight: 56
- type: StorageFill
contents:
- id: BoxSurvivalEngineering
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@
- id: BoxSurvivalSecurity
- id: Flash
- id: MagazinePistol

- type: entity
noSpawn: true
parent: ClothingBackpackDuffelSecurity
Expand All @@ -47,7 +47,6 @@
components:
- type: StorageFill
contents:
- id: BoxSurvivalBrigmedic
- id: Flash

- type: entity
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@
- id: BoxSurvivalSecurity
- id: Flash
- id: MagazinePistol

- type: entity
noSpawn: true
parent: ClothingBackpackSatchelSecurity
Expand All @@ -61,7 +61,6 @@
components:
- type: StorageFill
contents:
- id: BoxSurvivalBrigmedic
- id: Flash

- type: entity
Expand Down
38 changes: 19 additions & 19 deletions Resources/Prototypes/Catalog/Fills/Boxes/ammunition.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
- type: StorageFill
contents:
- id: MagazinePistolCaselessRifle
amount: 6
amount: 4

- type: entity
name: box of .25 caseless (practice) magazines
Expand All @@ -31,7 +31,7 @@
- type: StorageFill
contents:
- id: MagazinePistolCaselessRiflePractice
amount: 6
amount: 4

- type: entity
name: box of .25 caseless (rubber) magazines
Expand All @@ -42,7 +42,7 @@
- type: StorageFill
contents:
- id: MagazineCaselessRifleRubber
amount: 6
amount: 4

# LightRifle
- type: entity
Expand All @@ -54,7 +54,7 @@
- type: StorageFill
contents:
- id: MagazineLightRifle
amount: 6
amount: 4

- type: entity
name: box of .30 rifle (practice) magazines
Expand All @@ -65,7 +65,7 @@
- type: StorageFill
contents:
- id: MagazineLightRiflePractice
amount: 6
amount: 4

- type: entity
name: box of .30 rifle (rubber) magazines
Expand All @@ -76,7 +76,7 @@
- type: StorageFill
contents:
- id: MagazineLightRifleRubber
amount: 6
amount: 4

- type: entity
name: box of Vector magazines
Expand Down Expand Up @@ -132,7 +132,7 @@
- type: StorageFill
contents:
- id: MagazinePistol
amount: 6
amount: 4

- type: entity
name: box of pistol .35 auto (practice) magazines
Expand All @@ -143,7 +143,7 @@
- type: StorageFill
contents:
- id: MagazinePistolPractice
amount: 6
amount: 4

- type: entity
name: box of pistol .35 auto (rubber) magazines
Expand All @@ -154,7 +154,7 @@
- type: StorageFill
contents:
- id: MagazinePistolRubber
amount: 6
amount: 4

- type: entity
name: box of machine pistol .35 auto magazines
Expand All @@ -165,7 +165,7 @@
- type: StorageFill
contents:
- id: MagazinePistolHighCapacity
amount: 6
amount: 4

- type: entity
name: box of machine pistol .35 auto (practice) magazines
Expand All @@ -176,7 +176,7 @@
- type: StorageFill
contents:
- id: MagazinePistolHighCapacityPractice
amount: 6
amount: 4

- type: entity
name: box of machine pistol .35 auto (rubber) magazines
Expand All @@ -187,7 +187,7 @@
- type: StorageFill
contents:
- id: MagazinePistolHighCapacityRubber
amount: 6
amount: 4


- type: entity
Expand Down Expand Up @@ -233,7 +233,7 @@
- type: StorageFill
contents:
- id: MagazineShotgun
amount: 6
amount: 4

- type: entity
name: box of (.50 beanbag) ammo drums
Expand All @@ -244,7 +244,7 @@
- type: StorageFill
contents:
- id: MagazineShotgunBeanbag
amount: 6
amount: 4

- type: entity
name: box of (.50 slug) ammo drums
Expand All @@ -255,7 +255,7 @@
- type: StorageFill
contents:
- id: MagazineShotgunSlug
amount: 6
amount: 4

- type: entity
name: box of (.50 incendiary) ammo drums
Expand All @@ -266,7 +266,7 @@
- type: StorageFill
contents:
- id: MagazineShotgunIncendiary
amount: 6
amount: 4

# base BallisticAmmoProvider dispensers
- type: entity
Expand Down Expand Up @@ -396,7 +396,7 @@
- type: StorageFill
contents:
- id: MagazineRifle
amount: 6
amount: 4

- type: entity
name: box of .20 rifle (practice) magazines
Expand All @@ -407,7 +407,7 @@
- type: StorageFill
contents:
- id: MagazineRiflePractice
amount: 6
amount: 4

- type: entity
name: box of .20 rifle (rubber) magazines
Expand All @@ -418,4 +418,4 @@
- type: StorageFill
contents:
- id: MagazineRifleRubber
amount: 6
amount: 4
Loading

0 comments on commit 85f09ca

Please sign in to comment.