This repository has been archived by the owner on Oct 3, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDSPBeltReverseDirection.cs
519 lines (476 loc) · 31.1 KB
/
DSPBeltReverseDirection.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
//
// Copyright (c) 2021, Aaron Shumate
// All rights reserved.
//
// This source code is licensed under the BSD-style license found in the
// LICENSE.txt file in the root directory of this source tree.
//
// Dyson Sphere Program is developed by Youthcat Studio and published by Gamera Game.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using BepInEx;
using HarmonyLib;
using UnityEngine;
using UnityEngine.UI;
using System.IO;
using BepInEx.Logging;
using System.Security;
using System.Security.Permissions;
[module: UnverifiableCode]
#pragma warning disable CS0618 // Type or member is obsolete
[assembly: SecurityPermission(SecurityAction.RequestMinimum, SkipVerification = true)]
#pragma warning restore CS0618 // Type or member is obsolete
namespace DSPBeltReverseDirection
{
[BepInPlugin(pluginGuid, pluginName, pluginVersion)]
[BepInProcess("DSPGAME.exe")]
[BepInProcess("Dyson Sphere Program.exe")]
public class DSPBeltReverseDirection : BaseUnityPlugin
{
public const string pluginGuid = "greyhak.dysonsphereprogram.beltreversedirection";
public const string pluginName = "DSP Belt Reverse Direction";
public const string pluginVersion = "1.1.7";
new internal static ManualLogSource Logger;
new internal static BepInEx.Configuration.ConfigFile Config;
Harmony harmony;
public void Awake()
{
Logger = base.Logger; // "C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\LogOutput.log"
Config = base.Config; // "C:\Program Files (x86)\Steam\steamapps\common\Dyson Sphere Program\BepInEx\config\greyhak.dysonsphereprogram.beltreversedirection.cfg"
harmony = new Harmony(pluginGuid);
harmony.PatchAll(typeof(DSPBeltReverseDirection));
Logger.LogInfo("Initialization complete.");
}
public static RectTransform reverseButton;
public static Sprite reverseSprite;
// The first call happens for some reason after every game load.
// This causes the tip to be displayed without a mouse-over when the BeltWindow opens for the first time.
static bool ignoreFirstReverseButtonOnPointerEnter = true;
[HarmonyPrefix, HarmonyPatch(typeof(UIButton), "OnPointerEnter")]
public static bool UIButton_OnPointerEnter_Prefix(UIButton __instance)
{
if (reverseButton != null && __instance == reverseButton.GetComponent<UIButton>() && ignoreFirstReverseButtonOnPointerEnter)
{
ignoreFirstReverseButtonOnPointerEnter = false;
return false;
}
return true;
}
[HarmonyPrefix, HarmonyPatch(typeof(GameMain), "Begin")]
public static void GameMain_Begin_Prefix()
{
ignoreFirstReverseButtonOnPointerEnter = true;
if (GameMain.instance != null && GameObject.Find("Game Menu/button-1-bg"))
{
if (!GameObject.Find("greyhak-reverse-button"))
{
RectTransform prefab = GameObject.Find("Game Menu/button-1-bg").GetComponent<RectTransform>();
Vector3 referencePosition = prefab.localPosition;
reverseButton = GameObject.Instantiate<RectTransform>(prefab);
reverseButton.gameObject.name = "greyhak-reverse-button";
UIButton uiButton = reverseButton.GetComponent<UIButton>();
uiButton.tips.tipTitle = "Reverse Belt Direction";
uiButton.tips.tipText = "Click to reverse the direction of the conveyor belt.";
uiButton.tips.delay = 0f;
reverseButton.transform.Find("button-1/icon").GetComponent<Image>().sprite = GetSprite();
reverseButton.SetParent(UIRoot.instance.uiGame.beltWindow.windowTrans);
reverseButton.localScale = new Vector3(0.5f, 0.5f, 0.5f);
reverseButton.localPosition = new Vector3(5, 42, 0);
uiButton.OnPointerDown(null);
uiButton.OnPointerEnter(null);
uiButton.button.onClick.AddListener(() =>
{
ReverseBelt();
});
uiButton.onRightClick += PrintDebugInformationAboutPath;
}
}
}
public static Sprite GetSprite()
{
Texture2D tex = new Texture2D(48, 48, TextureFormat.RGBA32, false);
Color color = new Color(1, 1, 1, 1);
// Draw a plane like the one re[resending drones in the Mecha Panel...
for (int x = 0; x < 48; x++)
{
for (int y = 0; y < 48; y++)
{
if (((x >= 7) && (x <= 39) && (y >= 10) && (y <= 16)) || // top
((x == 33) && (y >= 1) && (y <= 25)) ||
((x == 34) && (y >= 2) && (y <= 24)) ||
((x == 35) && (y >= 3) && (y <= 23)) ||
((x == 36) && (y >= 4) && (y <= 22)) ||
((x == 37) && (y >= 5) && (y <= 21)) ||
((x == 38) && (y >= 6) && (y <= 20)) ||
((x == 39) && (y >= 7) && (y <= 19)) ||
((x == 40) && (y >= 8) && (y <= 18)) ||
((x == 41) && (y >= 9) && (y <= 17)) ||
((x == 42) && (y >= 10) && (y <= 16)) ||
((x == 43) && (y >= 11) && (y <= 15)) ||
((x == 44) && (y >= 12) && (y <= 14)) ||
((x == 45) && (y == 13)) ||
((x >= 8) && (x <= 40) && (y >= 31) && (y <= 37)) || // bottom
((x == 2) && (y == 34)) ||
((x == 3) && (y >= 33) && (y <= 35)) ||
((x == 4) && (y >= 32) && (y <= 36)) ||
((x == 5) && (y >= 31) && (y <= 37)) ||
((x == 6) && (y >= 30) && (y <= 38)) ||
((x == 7) && (y >= 29) && (y <= 39)) ||
((x == 8) && (y >= 28) && (y <= 40)) ||
((x == 9) && (y >= 27) && (y <= 41)) ||
((x == 10) && (y >= 26) && (y <= 42)) ||
((x == 11) && (y >= 25) && (y <= 43)) ||
((x == 12) && (y >= 24) && (y <= 44)) ||
((x == 13) && (y >= 23) && (y <= 45)) ||
((x == 14) && (y >= 22) && (y <= 46)))
{
tex.SetPixel(x, y, color);
}
else
{
tex.SetPixel(x, y, new Color(0, 0, 0, 0));
}
}
}
tex.name = "greyhak-reverse-icon";
tex.Apply();
return Sprite.Create(tex, new Rect(0f, 0f, 48f, 48f), new Vector2(0f, 0f), 1000);
}
public const int BELT_INPUT_SLOT = 1;
public const int BELT_OUTPUT_SLOT = 0;
// See this debug data in BepInEx console by setting Logging.Console.Enabled = true.
// See this debug data in LogOutput.log by adding Debug to Logging.Disk.LogLevels.
public static void PrintDebugInformationAboutPath(int data)
{
int selectedBeltId = UIRoot.instance.uiGame.beltWindow.beltId;
PlanetFactory factory = GameMain.mainPlayer.factory;
CargoTraffic cargoTraffic = factory.cargoTraffic;
BeltComponent selectedBeltComponent = cargoTraffic.beltPool[selectedBeltId];
CargoPath cargoPath = cargoTraffic.pathPool[selectedBeltComponent.segPathId];
List<int> cargoPathBelts = cargoPath.belts;
Logger.LogDebug("===============================================================================");
Logger.LogDebug("selectedBeltId=" + selectedBeltId.ToString() + ", selectedBeltComponent.segPathId=" + selectedBeltComponent.segPathId.ToString());
Logger.LogDebug("cargoPathBelts.Count=" + cargoPathBelts.Count.ToString() + ", cargoPath.pathLength=" + cargoPath.pathLength.ToString());
for (int beltIdx = 0; beltIdx < cargoPathBelts.Count; ++beltIdx)
{
BeltComponent beltComponent = cargoTraffic.beltPool[cargoPathBelts[beltIdx]];
Logger.LogDebug(" Belt[" + beltIdx.ToString() +
"]: id=" + beltComponent.id.ToString() +
", entityId=" + beltComponent.entityId.ToString() +
", outputId=" + beltComponent.outputId.ToString() +
", mainInputId=" + beltComponent.mainInputId.ToString() +
", backInputId=" + beltComponent.backInputId.ToString() +
", leftInputId=" + beltComponent.leftInputId.ToString() +
", rightInputId=" + beltComponent.rightInputId.ToString());
factory.ReadObjectConn(beltComponent.entityId, BELT_INPUT_SLOT, out bool inputsOutputFlag, out int inputEntityId, out int inputEntitySlot);
factory.ReadObjectConn(beltComponent.entityId, BELT_OUTPUT_SLOT, out bool outputsOutputFlag, out int outputEntityId, out int outputEntitySlot);
Logger.LogDebug(" Input slot: inputsOutputFlag=" + inputsOutputFlag.ToString() + ", inputEntityId=" + inputEntityId.ToString() + ", inputEntitySlot=" + inputEntitySlot.ToString());
PrintDebugInformationAboutEntity(inputEntityId);
Logger.LogDebug(" Output slot: outputsOutputFlag=" + outputsOutputFlag.ToString() + ", outputEntityId=" + outputEntityId.ToString() + ", outputEntitySlot=" + outputEntitySlot.ToString());
PrintDebugInformationAboutEntity(outputEntityId);
}
Logger.LogDebug("===============================================================================");
}
public static void PrintDebugInformationAboutEntity(int entityId)
{
if (entityId != 0)
{
PlanetFactory factory = GameMain.mainPlayer.factory;
CargoTraffic cargoTraffic = factory.cargoTraffic;
EntityData entity = factory.entityPool[entityId];
if (entity.splitterId != 0)
{
SplitterComponent splitterComponent = cargoTraffic.splitterPool[entity.splitterId];
Logger.LogDebug(" Is splitterId=" + entity.splitterId.ToString() +
", beltA=" + splitterComponent.beltA.ToString() +
", beltB=" + splitterComponent.beltB.ToString() +
", beltC=" + splitterComponent.beltC.ToString() +
", beltD=" + splitterComponent.beltD.ToString());
}
if (entity.minerId != 0)
{
MinerComponent minerComponent = factory.factorySystem.minerPool[entity.minerId];
Logger.LogDebug(" Is minerId=" + entity.minerId.ToString());
}
if (entity.tankId != 0)
{
TankComponent tankComponent = factory.factoryStorage.tankPool[entity.tankId];
Logger.LogDebug(" Is tankId=" + entity.tankId.ToString() +
", belt0=" + tankComponent.belt0.ToString() + (tankComponent.isOutput0 ? "(output)" : "(input)") +
", belt1=" + tankComponent.belt1.ToString() + (tankComponent.isOutput1 ? "(output)" : "(input)") +
", belt2=" + tankComponent.belt2.ToString() + (tankComponent.isOutput2 ? "(output)" : "(input)") +
", belt3=" + tankComponent.belt3.ToString() + (tankComponent.isOutput3 ? "(output)" : "(input)"));
}
if (entity.fractionatorId != 0)
{
FractionatorComponent fractionateComponent = factory.factorySystem.fractionatorPool[entity.fractionatorId];
Logger.LogDebug(" Is fractionatorId=" + entity.fractionatorId.ToString() +
", belt0=" + fractionateComponent.belt0.ToString() + (fractionateComponent.isOutput0 ? "(output)" : "(input)") +
", belt1=" + fractionateComponent.belt1.ToString() + (fractionateComponent.isOutput1 ? "(output)" : "(input)") +
", belt2=" + fractionateComponent.belt2.ToString() + (fractionateComponent.isOutput2 ? "(output)" : "(input)"));
}
if (entity.powerExcId != 0)
{
PowerExchangerComponent powerExchangerComponent = factory.powerSystem.excPool[entity.powerExcId];
Logger.LogDebug(" Is powerExcId=" + entity.powerExcId.ToString() +
", belt0=" + powerExchangerComponent.belt0.ToString() + (powerExchangerComponent.isOutput0 ? "(output)" : "(input)") +
", belt1=" + powerExchangerComponent.belt1.ToString() + (powerExchangerComponent.isOutput1 ? "(output)" : "(input)") +
", belt2=" + powerExchangerComponent.belt2.ToString() + (powerExchangerComponent.isOutput2 ? "(output)" : "(input)") +
", belt3=" + powerExchangerComponent.belt3.ToString() + (powerExchangerComponent.isOutput3 ? "(output)" : "(input)"));
}
if (entity.stationId != 0)
{
StationComponent stationComponent = factory.transport.stationPool[entity.stationId];
Logger.LogDebug(" Is stationId=" + entity.stationId.ToString() + " name=" + stationComponent.name);
}
for (int slotIdx = 0; slotIdx < 6; ++slotIdx)
{
factory.ReadObjectConn(entityId, slotIdx, out bool outputFlag, out int otherEntityId, out int otherEntitySlot);
if (otherEntityId != 0)
{
Logger.LogDebug(" Slot " + slotIdx.ToString() + (outputFlag ? " outputting to " : " inputting from ") + "entity " + otherEntityId.ToString() + " slot " + otherEntitySlot.ToString());
}
}
}
}
struct ReverseConnection
{
public int targetId;
public int outputId;
public int inputId0;
public int inputId1;
public int inputId2;
}
static void ReverseBelt()
{
int selectedBeltId = UIRoot.instance.uiGame.beltWindow.beltId;
PlanetFactory factory = GameMain.mainPlayer.factory;
CargoTraffic cargoTraffic = factory.cargoTraffic;
BeltComponent selectedBeltComponent = cargoTraffic.beltPool[selectedBeltId];
CargoPath cargoPath = cargoTraffic.pathPool[selectedBeltComponent.segPathId];
if (cargoPath.belts.Count > 1)
{
Logger.LogMessage("Reverse!");
bool grabbedItemsFlag = true;
List<int> cargoIds = new List<int>();
for (int index = 0; index + 9 < cargoPath.bufferLength;)
{
if (cargoPath.buffer[index] == 0)
{
cargoIds.Add(0);
++index;
}
else if (
(cargoPath.buffer[index + 0] == 246) ||
(cargoPath.buffer[index + 1] == 247) ||
(cargoPath.buffer[index + 2] == 248) ||
(cargoPath.buffer[index + 3] == 249) ||
(cargoPath.buffer[index + 4] == 250) ||
(cargoPath.buffer[index + 9] == byte.MaxValue) )
{
int extractedCargoId = (int)
(cargoPath.buffer[index + 5] - 1 +
(cargoPath.buffer[index + 6] - 1) * 100) +
(int)(cargoPath.buffer[index + 7] - 1) * 10000 +
(int)(cargoPath.buffer[index + 8] - 1) * 1000000;
cargoIds.Add(extractedCargoId);
index += 10;
}
else
{
Logger.LogWarning("Unable to identify items on the belt.");
grabbedItemsFlag = false;
break;
}
}
if (grabbedItemsFlag)
{
Array.Clear(cargoPath.buffer, 0, cargoPath.bufferLength);
}
int firstBeltId = cargoPath.belts[0];
int lastBeltId = cargoPath.belts[cargoPath.belts.Count - 1];
BeltComponent firstBelt = cargoTraffic.beltPool[firstBeltId];
BeltComponent lastBelt = cargoTraffic.beltPool[lastBeltId];
// For machine connections we reference PlanetFactory.CreateEntityLogicComponents
// These include splitter, miner, tank, fractionate, powerExchanger (and station)
factory.ReadObjectConn(firstBelt.entityId, BELT_INPUT_SLOT, out bool unusedFlag, out int entityIdOfMachineOutputting, out int slotOfMachineOutputting);
factory.ReadObjectConn(lastBelt.entityId, BELT_OUTPUT_SLOT, out unusedFlag, out int entityIdOfMachineGettingInput, out int slotOfMachineGettingInput);
// Note: "Machine" at this point is likely to just be another conveyer.
List<ReverseConnection> reverseConnections = new List<ReverseConnection>();
for (int beltIdx = cargoPath.belts.Count - 1; beltIdx >= 0; --beltIdx)
{
BeltComponent thisBelt = cargoTraffic.beltPool[cargoPath.belts[beltIdx]];
Logger.LogDebug((beltIdx > 0 ? cargoTraffic.beltPool[cargoPath.belts[beltIdx - 1]].id.ToString() : "start") + " -> " + thisBelt.id.ToString() + " -> " + (beltIdx + 1 < cargoPath.belts.Count ? cargoTraffic.beltPool[cargoPath.belts[beltIdx + 1]].id.ToString() : "end"));
Logger.LogDebug(" outputId=" + thisBelt.outputId.ToString() + ", backInputId=" + thisBelt.backInputId.ToString() + ", leftInputId=" + thisBelt.leftInputId.ToString() + ", rightInputId=" + thisBelt.rightInputId.ToString());
if (beltIdx == cargoPath.belts.Count - 1 && thisBelt.outputId != 0 && cargoTraffic.beltPool[thisBelt.outputId].segPathId != thisBelt.segPathId)
{
// About to break a primary segment, so consider this belt as having no output
thisBelt.outputId = 0;
}
ReverseConnection reverseConnection = new ReverseConnection
{
targetId = thisBelt.id,
outputId = thisBelt.mainInputId
};
Logger.LogDebug(" targetId=" + reverseConnection.targetId.ToString() + ", outputId=" + reverseConnection.outputId.ToString());
List<int> inputs = new List<int>();
if (thisBelt.outputId != 0) inputs.Add(thisBelt.outputId);
if (thisBelt.backInputId != 0 && thisBelt.backInputId != reverseConnection.outputId) inputs.Add(thisBelt.backInputId);
if (thisBelt.leftInputId != 0 && thisBelt.leftInputId != reverseConnection.outputId) inputs.Add(thisBelt.leftInputId);
if (thisBelt.rightInputId != 0 && thisBelt.rightInputId != reverseConnection.outputId) inputs.Add(thisBelt.rightInputId);
if (inputs.Count > 0) reverseConnection.inputId0 = inputs[0];
if (inputs.Count > 1) reverseConnection.inputId1 = inputs[1];
if (inputs.Count > 2) reverseConnection.inputId2 = inputs[2];
Logger.LogDebug(" inputId0=" + reverseConnection.inputId0.ToString() + ", inputId1=" + reverseConnection.inputId1.ToString() + ", inputId2=" + reverseConnection.inputId2.ToString());
reverseConnections.Add(reverseConnection);
}
// The order of this loop can be swaped, and still performs the same change.
foreach (ReverseConnection reverseConnection in reverseConnections)
{
cargoTraffic.AlterBeltConnections(reverseConnection.targetId, reverseConnection.outputId, reverseConnection.inputId0, reverseConnection.inputId1, reverseConnection.inputId2);
int entityIdOfThisBelt = cargoTraffic.beltPool[reverseConnection.targetId].entityId;
int entityIdOfOutputBelt = reverseConnection.outputId == 0 ? 0 : cargoTraffic.beltPool[reverseConnection.outputId].entityId;
int entityIdOfMainInputBelt = reverseConnection.inputId0 == 0 ? 0 : cargoTraffic.beltPool[reverseConnection.inputId0].entityId;
// This loop will disconnect all inserters. It's based on PlanetFactory.RemoveEntityWithComponents() and PlanetFactory.ApplyEntityDisconnection()
for (int slotIdx = 0; slotIdx < 16; slotIdx++)
{
factory.ReadObjectConn(entityIdOfThisBelt, slotIdx, out bool flag, out int otherEntityId, out int otherSlotId);
if (otherEntityId > 0)
{
int inserterId = factory.entityPool[otherEntityId].inserterId;
if (inserterId > 0) // Is otherEntityId an inserter entity?
{
if (factory.factorySystem.inserterPool[inserterId].insertTarget == entityIdOfThisBelt)
{
Logger.LogDebug($"Disconnecting inserter insert target {inserterId} from {entityIdOfThisBelt}");
factory.factorySystem.SetInserterInsertTarget(inserterId, 0, 0);
}
if (factory.factorySystem.inserterPool[inserterId].pickTarget == entityIdOfThisBelt)
{
Logger.LogDebug($"Disconnecting inserter pick target {inserterId} from {entityIdOfThisBelt}");
factory.factorySystem.SetInserterPickTarget(inserterId, 0, 0);
}
}
}
}
factory.ClearObjectConn(entityIdOfThisBelt);
factory.WriteObjectConnDirect(entityIdOfThisBelt, BELT_OUTPUT_SLOT, true, entityIdOfOutputBelt, BELT_INPUT_SLOT);
factory.WriteObjectConnDirect(entityIdOfThisBelt, BELT_INPUT_SLOT, false, entityIdOfMainInputBelt, BELT_OUTPUT_SLOT);
factory.OnBeltBuilt(entityIdOfThisBelt); // This reconnects the inserters
}
if (entityIdOfMachineOutputting > 0)
{
EntityData entityOfMachineOutputting = factory.entityPool[entityIdOfMachineOutputting];
if (entityOfMachineOutputting.splitterId != 0)
{
Logger.LogDebug(" Belt receiving input from splitter " + entityOfMachineOutputting.splitterId.ToString());
cargoTraffic.ConnectToSplitter(entityOfMachineOutputting.splitterId, firstBeltId, slotOfMachineOutputting, true);
}
else if (entityOfMachineOutputting.minerId != 0)
{
Logger.LogDebug(" Belt receiving input from miner " + entityOfMachineOutputting.minerId.ToString());
factory.factorySystem.SetMinerInsertTarget(entityOfMachineOutputting.minerId, 0);
}
else if (entityOfMachineOutputting.tankId != 0)
{
Logger.LogDebug(" Belt receiving input from tank " + entityOfMachineOutputting.tankId.ToString());
factory.factoryStorage.SetTankBelt(entityOfMachineOutputting.tankId, firstBeltId, slotOfMachineOutputting, false);
}
else if (entityOfMachineOutputting.fractionatorId != 0)
{
Logger.LogDebug(" Belt receiving input from fractionator " + entityOfMachineOutputting.fractionatorId.ToString());
factory.factorySystem.SetFractionatorBelt(entityOfMachineOutputting.fractionatorId, firstBeltId, slotOfMachineOutputting, false);
}
else if (entityOfMachineOutputting.powerExcId != 0)
{
Logger.LogDebug(" Belt receiving input from power exchanger " + entityOfMachineOutputting.powerExcId.ToString());
factory.powerSystem.SetExchangerBelt(entityOfMachineOutputting.powerExcId, firstBeltId, slotOfMachineOutputting, false);
}
else if (entityOfMachineOutputting.stationId != 0)
{
Logger.LogDebug(" Belt receiving input from station " + entityOfMachineOutputting.stationId.ToString());
factory.ApplyEntityInput(entityIdOfMachineOutputting, firstBelt.entityId, slotOfMachineOutputting, slotOfMachineOutputting, 0);
Logger.LogDebug(" Station now set to " + factory.transport.stationPool[entityOfMachineOutputting.stationId].slots[slotOfMachineOutputting].dir.ToString());
}
factory.WriteObjectConnDirect(firstBelt.entityId, BELT_OUTPUT_SLOT, true, entityIdOfMachineOutputting, slotOfMachineOutputting);
factory.WriteObjectConnDirect(entityIdOfMachineOutputting, slotOfMachineOutputting, false, firstBelt.entityId, BELT_OUTPUT_SLOT);
}
if (entityIdOfMachineGettingInput > 0)
{
EntityData entityOfMachineGettingInput = factory.entityPool[entityIdOfMachineGettingInput];
if (entityOfMachineGettingInput.splitterId != 0)
{
Logger.LogDebug(" Belt outputting to splitter " + entityOfMachineGettingInput.splitterId.ToString());
cargoTraffic.ConnectToSplitter(entityOfMachineGettingInput.splitterId, lastBeltId, slotOfMachineGettingInput, false);
}
else if (entityOfMachineGettingInput.minerId != 0)
{
Logger.LogWarning(" ERROR: Belt outputting to miner " + entityOfMachineGettingInput.minerId.ToString());
}
else if (entityOfMachineGettingInput.tankId != 0)
{
Logger.LogDebug(" Belt outputting to tank " + entityOfMachineGettingInput.tankId.ToString());
factory.factoryStorage.SetTankBelt(entityOfMachineGettingInput.tankId, lastBeltId, slotOfMachineGettingInput, true);
}
else if (entityOfMachineGettingInput.fractionatorId != 0)
{
Logger.LogDebug(" Belt outputting to fractionator " + entityOfMachineGettingInput.fractionatorId.ToString());
factory.factorySystem.SetFractionatorBelt(entityOfMachineGettingInput.fractionatorId, lastBeltId, slotOfMachineGettingInput, true);
}
else if (entityOfMachineGettingInput.powerExcId != 0)
{
Logger.LogDebug(" Belt outputting to power exchanger " + entityOfMachineGettingInput.powerExcId.ToString());
factory.powerSystem.SetExchangerBelt(entityOfMachineGettingInput.powerExcId, lastBeltId, slotOfMachineGettingInput, true);
}
else if (entityOfMachineGettingInput.stationId != 0)
{
Logger.LogDebug(" Belt outputting to station " + entityOfMachineGettingInput.stationId.ToString());
factory.ApplyEntityOutput(entityIdOfMachineGettingInput, lastBelt.entityId, slotOfMachineGettingInput, slotOfMachineGettingInput, 0);
Logger.LogDebug(" Station now set to " + factory.transport.stationPool[entityOfMachineGettingInput.stationId].slots[slotOfMachineGettingInput].dir.ToString());
}
factory.WriteObjectConnDirect(lastBelt.entityId, BELT_INPUT_SLOT, false, entityIdOfMachineGettingInput, slotOfMachineGettingInput);
factory.WriteObjectConnDirect(entityIdOfMachineGettingInput, slotOfMachineGettingInput, true, lastBelt.entityId, BELT_INPUT_SLOT);
}
if (grabbedItemsFlag)
{
CargoPath newCargoPath = cargoTraffic.pathPool[cargoTraffic.beltPool[UIRoot.instance.uiGame.beltWindow.beltId].segPathId];
int index = 4;
for (int cargoIdIdx = cargoIds.Count - 1; cargoIdIdx >= 0; --cargoIdIdx)
{
int insertCargoId = cargoIds[cargoIdIdx];
if (insertCargoId == 0)
{
index++;
}
else
{
if (index + 10 > newCargoPath.bufferLength)
{
Logger.LogInfo("New cargo path is not large enough to fit all the items from the original path. Sending item to Icarus' inventory.");
CargoContainer cargoContainer = cargoPath.cargoContainer;
Cargo cargo = cargoContainer.cargoPool[insertCargoId];
int cargoItem = cargo.item;
cargoContainer.RemoveCargo(insertCargoId);
if (GameMain.mainPlayer.package.AddItemStacked(cargoItem, 1, 1, out int remainInc) == 1)
{
UIItemup.Up(cargoItem, 1);
}
}
else
{
newCargoPath.InsertCargoDirect(index, insertCargoId);
index += 10;
}
}
}
}
cargoTraffic.RemoveCargoPath(cargoPath.id);
// Audio comes from LDB.audios. Good built-in choices are "warp-end" or "ui-click-2" (the upgrade sound).
VFAudio.Create("ui-click-2", null, GameMain.mainPlayer.factory.entityPool[selectedBeltComponent.entityId].pos, true);
}
}
}
}