Departmental Economy (#36445)

* Cargo Accounts, Request Consoles, and lock boxes

* Funding Allocation Computer

* final changes

* test fix

* remove dumb code

* ScarKy0 review

* first cour

* second cour

* Update machines.yml

* review

---------

Co-authored-by: ScarKy0 <106310278+ScarKy0@users.noreply.github.com>
Co-authored-by: Milon <milonpl.git@proton.me>
This commit is contained in:
Nemanja
2025-04-13 09:22:36 -04:00
committed by GitHub
parent 5f78b72763
commit 12b75beeab
62 changed files with 2106 additions and 331 deletions

View File

@@ -1,7 +1,54 @@
using System.Linq;
using Content.Shared.Cargo.Components;
using Content.Shared.Cargo.Prototypes;
using Robust.Shared.Prototypes;
using Robust.Shared.Serialization;
namespace Content.Shared.Cargo;
public abstract class SharedCargoSystem : EntitySystem
{
/// <summary>
/// For a given station, retrieves the balance in a specific account.
/// </summary>
public int GetBalanceFromAccount(Entity<StationBankAccountComponent?> station, ProtoId<CargoAccountPrototype> account)
{
if (!Resolve(station, ref station.Comp))
return 0;
return station.Comp.Accounts.GetValueOrDefault(account);
}
/// <summary>
/// For a station, creates a distribution between one "primary" account and the other accounts.
/// The primary account receives the majority cut specified, with the remaining accounts getting cuts
/// distributed through the remaining amount, based on <see cref="StationBankAccountComponent.RevenueDistribution"/>
/// </summary>
public Dictionary<ProtoId<CargoAccountPrototype>, double> CreateAccountDistribution(
ProtoId<CargoAccountPrototype> primary,
StationBankAccountComponent stationBank,
double primaryCut = 1.0)
{
var distribution = new Dictionary<ProtoId<CargoAccountPrototype>, double>
{
{ primary, primaryCut }
};
var remaining = 1.0 - primaryCut;
var allAccountPercentages = new Dictionary<ProtoId<CargoAccountPrototype>, double>(stationBank.RevenueDistribution);
allAccountPercentages.Remove(primary);
var weightsSum = allAccountPercentages.Values.Sum();
foreach (var (account, percentage) in allAccountPercentages)
{
var adjustedPercentage = percentage / weightsSum;
distribution.Add(account, remaining * adjustedPercentage);
}
return distribution;
}
}
[NetSerializable, Serializable]
public enum CargoConsoleUiKey : byte
{
@@ -17,8 +64,6 @@ public enum CargoPalletConsoleUiKey : byte
Sale
}
public abstract class SharedCargoSystem : EntitySystem {}
[Serializable, NetSerializable]
public enum CargoTelepadState : byte
{