Skip to content
This repository has been archived by the owner on Nov 1, 2024. It is now read-only.

Commit

Permalink
Merge pull request #25 from new-frontiers-14/master
Browse files Browse the repository at this point in the history
Split cargo request console (new-frontiers-14#1191)
  • Loading branch information
Vonsant authored Apr 12, 2024
2 parents 7391ab5 + 2a5998b commit 0927c3f
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 12 deletions.
21 changes: 12 additions & 9 deletions Content.Server/Cargo/Systems/CargoSystem.Orders.cs
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private void OnAddOrderMessage(EntityUid uid, CargoOrderConsoleComponent compone
if (!component.AllowedGroups.Contains(product.Group))
return;

var data = GetOrderData(args, product, GenerateOrderId(orderDatabase));
var data = GetOrderData(EntityManager.GetNetEntity(uid), args, product, GenerateOrderId(orderDatabase));

if (!TryAddOrder(orderDatabase.Owner, data, orderDatabase))
{
Expand Down Expand Up @@ -283,12 +283,15 @@ private void UpdateOrderState(CargoOrderConsoleComponent component, EntityUid? s

if (station == null || !TryGetOrderDatabase(station.Value, out var _, out var orderDatabase, component)) return;

// Frontier - we only want to see orders made on the same computer, so filter them out
var filteredOrders = orderDatabase.Orders.Where(order => order.Computer == EntityManager.GetNetEntity(component.Owner)).ToList();

var state = new CargoConsoleInterfaceState(
MetaData(player).EntityName,
GetOutstandingOrderCount(orderDatabase),
orderDatabase.Capacity,
balance,
orderDatabase.Orders);
filteredOrders);

_uiSystem.SetUiState(bui, state);
}
Expand All @@ -303,9 +306,9 @@ private void PlayDenySound(EntityUid uid, CargoOrderConsoleComponent component)
_audio.PlayPvs(_audio.GetSound(component.ErrorSound), uid);
}

private static CargoOrderData GetOrderData(CargoConsoleAddOrderMessage args, CargoProductPrototype cargoProduct, int id)
private static CargoOrderData GetOrderData(NetEntity consoleUid, CargoConsoleAddOrderMessage args, CargoProductPrototype cargoProduct, int id)
{
return new CargoOrderData(id, cargoProduct.Product, cargoProduct.Cost, args.Amount, args.Requester, args.Reason);
return new CargoOrderData(id, cargoProduct.Product, cargoProduct.Cost, args.Amount, args.Requester, args.Reason, consoleUid);
}

public static int GetOutstandingOrderCount(StationCargoOrderDatabaseComponent component)
Expand Down Expand Up @@ -366,7 +369,7 @@ StationDataComponent stationData
DebugTools.Assert(_protoMan.HasIndex<EntityPrototype>(spawnId));
// Make an order
var id = GenerateOrderId(component);
var order = new CargoOrderData(id, spawnId, cost, qty, sender, description);
var order = new CargoOrderData(id, spawnId, cost, qty, sender, description, null);

// Approve it now
order.SetApproverData(dest, sender);
Expand Down Expand Up @@ -411,9 +414,9 @@ public void ClearOrders(StationCargoOrderDatabaseComponent component)
component.Orders.Clear();
}

private static bool PopFrontOrder(StationCargoOrderDatabaseComponent orderDB, [NotNullWhen(true)] out CargoOrderData? orderOut)
private static bool PopFrontOrder(List<NetEntity> consoleUidList, StationCargoOrderDatabaseComponent orderDB, [NotNullWhen(true)] out CargoOrderData? orderOut)
{
var orderIdx = orderDB.Orders.FindIndex(order => order.Approved);
var orderIdx = orderDB.Orders.FindIndex(order => order.Approved && consoleUidList.Any(consoleUid => consoleUid == order.Computer));
if (orderIdx == -1)
{
orderOut = null;
Expand All @@ -434,9 +437,9 @@ private static bool PopFrontOrder(StationCargoOrderDatabaseComponent orderDB, [N
/// <summary>
/// Tries to fulfill the next outstanding order.
/// </summary>
private bool FulfillNextOrder(StationCargoOrderDatabaseComponent orderDB, EntityCoordinates spawn, string? paperProto)
private bool FulfillNextOrder(List<NetEntity> consoleUidList, StationCargoOrderDatabaseComponent orderDB, EntityCoordinates spawn, string? paperProto)
{
if (!PopFrontOrder(orderDB, out var order))
if (!PopFrontOrder(consoleUidList, orderDB, out var order))
return false;

return FulfillOrder(order, spawn, paperProto);
Expand Down
2 changes: 1 addition & 1 deletion Content.Server/Cargo/Systems/CargoSystem.Shuttle.cs
Original file line number Diff line number Diff line change
Expand Up @@ -165,7 +165,7 @@ private List<CargoOrderData> GetProjectedOrders(
// We won't be able to fit the whole order on, so make one
// which represents the space we do have left:
var reducedOrder = new CargoOrderData(order.OrderId,
order.ProductId, order.Price, spaceRemaining, order.Requester, order.Reason);
order.ProductId, order.Price, spaceRemaining, order.Requester, order.Reason, null);
orders.Add(reducedOrder);
}
else
Expand Down
6 changes: 5 additions & 1 deletion Content.Server/Cargo/Systems/CargoSystem.Telepad.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
using System.Linq;
using Content.Server.Cargo.Components;
using Content.Server.Construction;
using Content.Server.Paper;
Expand Down Expand Up @@ -67,8 +68,11 @@ private void UpdateTelepad(float frameTime)
continue;
}

// Frontier - This makes sure telepads spawn goods of linked computers only.
List<NetEntity> consoleUidList = sinkComponent.LinkedSources.Select(item => EntityManager.GetNetEntity(item)).ToList();

var xform = Transform(uid);
if (FulfillNextOrder(orderDatabase, xform.Coordinates, comp.PrinterOutput))
if (FulfillNextOrder(consoleUidList, orderDatabase, xform.Coordinates, comp.PrinterOutput))
{
_audio.PlayPvs(_audio.GetSound(comp.TeleportSound), uid, AudioParams.Default.WithVolume(-8f));
UpdateOrders(station.Value, orderDatabase);
Expand Down
5 changes: 4 additions & 1 deletion Content.Shared/Cargo/CargoOrderData.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,17 @@ public sealed class CargoOrderData
public bool Approved => Approver is not null;
public string? Approver;

public CargoOrderData(int orderId, string productId, int price, int amount, string requester, string reason)
public NetEntity? Computer = null;

public CargoOrderData(int orderId, string productId, int price, int amount, string requester, string reason, NetEntity? computer)
{
OrderId = orderId;
ProductId = productId;
Price = price;
OrderQuantity = amount;
Requester = requester;
Reason = reason;
Computer = computer;
}

public void SetApproverData(string? fullName, string? jobTitle)
Expand Down

0 comments on commit 0927c3f

Please sign in to comment.