Skip to content

Commit

Permalink
Merge pull request #706 from starfi5h/pr-LCP1
Browse files Browse the repository at this point in the history
Sync control panel (I) - UIControlPanelWindow
  • Loading branch information
starfi5h authored Sep 9, 2024
2 parents 8586219 + 96d3044 commit f0ad997
Show file tree
Hide file tree
Showing 21 changed files with 1,730 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
using UnityEngine;

namespace NebulaModel.Packets.Logistics.ControlPanel;

public class LCPAdvancedMinerEntryUpdate
{
public LCPAdvancedMinerEntryUpdate() { }

public void Set(int index, StationComponent station, PlanetFactory factory)
{
Index = index;

if (!station.isCollector)
{
var powerSystem = factory.powerSystem;
var powerConsumerComponent = powerSystem.consumerPool[station.pcId];
var networkId = powerConsumerComponent.networkId;
var powerNetwork = powerSystem.netPool[networkId];
ConsumerRatio = (float)powerNetwork.consumerRatio;
RequirePower = (long)((powerConsumerComponent.requiredEnergy * 60L) * ConsumerRatio);
WorkEnergyPerTick = powerSystem.consumerPool[station.pcId].workEnergyPerTick;
PowerRound = station.energy / (float)station.energyMax;
}

var minerComponent = factory.factorySystem.minerPool[station.minerId];
if (minerComponent.id == station.minerId)
{
var veinPool = factory.veinPool;
var lowVeinCount = 0;
var emptyVeinCount = 0;
if (minerComponent.veinCount > 0)
{
for (var i = 0; i < minerComponent.veinCount; i++)
{
var id = minerComponent.veins[i];
if (id > 0 && veinPool[id].id == id)
{
var amount = veinPool[id].amount;
if (amount < 1000)
{
if (amount > 0)
{
lowVeinCount++;
}
else
{
emptyVeinCount++;
}
}
}
}
}
VeinCount = (short)minerComponent.veinCount;
LowVeinCount = (short)lowVeinCount;
EmptyVeinCount = (short)emptyVeinCount;

var veinId = ((minerComponent.veinCount == 0) ? 0 : minerComponent.veins[minerComponent.currentVeinIndex]);
VeinProtoId = (int)veinPool[veinId].type;
var veinProto = LDB.veins.Select((int)veinPool[veinId].type);
if (veinProto != null)
{
minerComponent.GetTotalVeinAmount(veinPool);
TotalVeinAmount = minerComponent.totalVeinAmount;
}
}

ItemId = 0;
if (station.storage == null || station.storage.Length == 0) return;
ref var store = ref station.storage[0];
ItemId = store.itemId;
ItemCount = store.count;
LocalOrder = (short)Mathf.Clamp(store.localOrder, -20000, 20000);
RemoteOrder = (short)Mathf.Clamp(store.remoteOrder, -20000, 20000);
StoreMax = store.max;
LocalLogic = (byte)store.localLogic;
RemoteLogic = (byte)store.remoteLogic;
}

public static readonly LCPAdvancedMinerEntryUpdate Instance = new();

public int Index { get; set; }
public float ConsumerRatio { get; set; }
public long RequirePower { get; set; }
public long WorkEnergyPerTick { get; set; }
public float PowerRound { get; set; }

public int VeinProtoId { get; set; }
public long TotalVeinAmount { get; set; }
public short VeinCount { get; set; }
public short LowVeinCount { get; set; }
public short EmptyVeinCount { get; set; }

public int ItemId { get; set; }
public int ItemCount { get; set; }
public short LocalOrder { get; set; }
public short RemoteOrder { get; set; }
public int StoreMax { get; set; }
public byte LocalLogic { get; set; }
public byte RemoteLogic { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
namespace NebulaModel.Packets.Logistics.ControlPanel;

public class LCPDispenserEntryUpdate
{
public LCPDispenserEntryUpdate() { }

public void Set(int index, DispenserComponent dispenser, PlanetFactory factory)
{
Index = index;

var powerSystem = factory.powerSystem;
var powerConsumerComponent = powerSystem.consumerPool[dispenser.pcId];
var networkId = powerConsumerComponent.networkId;
var powerNetwork = powerSystem.netPool[networkId];
ConsumerRatio = (float)powerNetwork.consumerRatio;
RequirePower = (long)((powerConsumerComponent.requiredEnergy * 60L) * ConsumerRatio);
WorkEnergyPerTick = powerSystem.consumerPool[dispenser.pcId].workEnergyPerTick;
PowerRound = dispenser.energy / (float)dispenser.energyMax;

Filter = dispenser.filter;
PlayerMode = (short)dispenser.playerMode;
StorageMode = (short)dispenser.storageMode;
IdleCourierCount = dispenser.idleCourierCount;
WorkCourierCount = dispenser.workCourierCount;

var status = 0;
if (dispenser.playerMode == EPlayerDeliveryMode.None && dispenser.storageMode == EStorageDeliveryMode.None)
{
status = 1;
}
else if (dispenser.filter == 0)
{
status = 2;
}
else if (dispenser.idleCourierCount + dispenser.workCourierCount == 0)
{
status = 3;
}
else if (dispenser.holdupItemCount > 0)
{
status = 5;
}
else if (ConsumerRatio < 0.0001f && dispenser.energy < 100000L)
{
status = 4;
}
WarningFlag = status > 0;

var count = 0;
var inc = 0;
var loop = 0;
if (dispenser.storage != null && dispenser.filter > 0)
{
var storageComponent = dispenser.storage;
do
{
count += storageComponent.GetItemCount(dispenser.filter, out var num);
inc += num;
storageComponent = storageComponent.previousStorage;
if (loop++ > 20) break;
}
while (storageComponent != null);
}
ItemCount = count;
}

public static readonly LCPDispenserEntryUpdate Instance = new();

public int Index { get; set; }
public float ConsumerRatio { get; set; }
public long RequirePower { get; set; }
public long WorkEnergyPerTick { get; set; }
public float PowerRound { get; set; }

public int Filter { get; set; }
public short PlayerMode { get; set; }
public short StorageMode { get; set; }
public int IdleCourierCount { get; set; }
public int WorkCourierCount { get; set; }
public bool WarningFlag { get; set; }
public int ItemCount { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
using System;
using NebulaAPI.DataStructures;

namespace NebulaModel.Packets.Logistics.ControlPanel;

public class LCPFilterResultsRequest
{
public LCPFilterResultsRequest() { }

public LCPFilterResultsRequest(in ControlPanelFilter controlPanelFilter)
{
TypeFilter = (int)controlPanelFilter.typeFilter;
AstorFilter = controlPanelFilter.astroFilter;
if (controlPanelFilter.itemsFilter != null)
{
ItemsFilter = new int[controlPanelFilter.itemsFilter.Length];
Array.Copy(controlPanelFilter.itemsFilter, ItemsFilter, ItemsFilter.Length);
}
else
{
ItemsFilter = new int[0];
}
StateFilter = controlPanelFilter.stateFilter;
SearchFilter = controlPanelFilter.searchFilter;
SortMethod = (short)controlPanelFilter.sortMethod;

LocalPlanetAstroId = GameMain.data.localPlanet?.astroId ?? 0;
LocalStarAstroId = GameMain.data.localStar?.astroId ?? 0;
PlayerUposition = new Float3(GameMain.mainPlayer.uPosition);
}

public int TypeFilter { get; set; }
public int AstorFilter { get; set; }
public int[] ItemsFilter { get; set; }
public int StateFilter { get; set; }
public string SearchFilter { get; set; }
public short SortMethod { get; set; }
public int LocalPlanetAstroId { get; set; }
public int LocalStarAstroId { get; set; }
public Float3 PlayerUposition { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
using System.Collections.Generic;

namespace NebulaModel.Packets.Logistics.ControlPanel;

public class LCPFilterResultsResponse
{
public LCPFilterResultsResponse() { }

public LCPFilterResultsResponse(List<ControlPanelAstroData> sortedAstros, List<ControlPanelTarget> targets)
{
SortedAstroIds = new int[sortedAstros.Count];
for (var i = 0; i < sortedAstros.Count; i++)
{
SortedAstroIds[i] = sortedAstros[i].astroId;
}

var resultTargetCount = targets.Count;
ObjTypes = new short[resultTargetCount];
ObjIds = new int[resultTargetCount];
AstroIds = new int[resultTargetCount];
EntryTypes = new short[resultTargetCount];
for (var i = 0; i < resultTargetCount; i++)
{
var target = targets[i];
ObjTypes[i] = (short)target.objType;
ObjIds[i] = target.objId;
AstroIds[i] = target.astroId;
EntryTypes[i] = (short)target.entryType;
}
}

public int[] SortedAstroIds { get; set; }
public short[] ObjTypes { get; set; }
public int[] ObjIds { get; set; }
public int[] AstroIds { get; set; }
public short[] EntryTypes { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
namespace NebulaModel.Packets.Logistics.ControlPanel;

public class LCPObjectEntryEntityInfo
{
public LCPObjectEntryEntityInfo() { }

public void Set(int index, int protoId, int id, string name)
{
Index = index;
ProtoId = protoId;
Id = id;
Name = name;
}

public static readonly LCPObjectEntryEntityInfo Instance = new();

public int Index { get; set; }
public int ProtoId { get; set; }
public int Id { get; set; }
public string Name { get; set; }
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
namespace NebulaModel.Packets.Logistics.ControlPanel;

public class LCPObjectEntryRequest
{
public LCPObjectEntryRequest() { }

public void Set(UIControlPanelObjectEntry controlPanelFilter, bool isInit = false)
{
// isInit: Request for entityData.protoId, name
Index = controlPanelFilter.index;
EntryType = (short)controlPanelFilter.entryType;
AstroId = controlPanelFilter.target.astroId;
// Use sign of ObjId to note the state of request
ObjId = isInit ? -controlPanelFilter.target.objId : controlPanelFilter.target.objId;
}

public static readonly LCPObjectEntryRequest Instance = new();

public int Index { get; set; }
public short EntryType { get; set; }
public int AstroId { get; set; }
public int ObjId { get; set; }
}
Loading

0 comments on commit f0ad997

Please sign in to comment.