-
Notifications
You must be signed in to change notification settings - Fork 0
/
ConveyorEntity.cs
4111 lines (3437 loc) · 167 KB
/
ConveyorEntity.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
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
using System;
using System.IO;
using UnityEngine;
using System.Collections.Generic;
//To consider; if conveyors carry bars 99% of the time, pre-instantiate those and use UVs, and instantiate a rarer, tertiary object
public class ConveyorEntity : MachineEntity, PowerConsumerInterface, ItemSupplierInterface, ItemConsumerInterface
{
public const float TIER1_SPEED = 1;
public const float TIER2_SPEED = 2;
public const float TIER3_SPEED = 4;
public const float TIER0_SPEED = 0.15f;
public const float FAST_SETTING_SPEED_FACTOR = 2;
public const float VERTICAL_SPEED_FACTOR = 1;//was 0.25f;
public static int PowerPerItem = 10;//theoretical max of 150/face, which is 750/min per face.
public const float CARRY_TIME = 1;
public const float VISUAL_CARRY_TIME = 1;
public const float MYNOCK_DEBOUCE_TIME = 600; // Avoid spawning mynocks on the same conveyor for 10 minutes after one is killed.
public string mText = null;
//private bool stringDirty;
public float mrMaxPower = 1500.0f;
public float mrCurrentPower = 0.0f;
float mrNormalisedPower;
public float mrPowerSpareCapacity;
public float mrLockTimer;//Do not increment visual or carry timer; rewind them to .5;set conveyor speed accordingly; (even consider slowing down the conveyor)
public float mrRobotLockTimer;//Used purely to say 'I have this'; decays to avoid reference count issues
bool mbLinkedToGO;
public bool mbCheckAdjacencyRotation;
public bool mbReadyToConvey;
public float mrCarryTimer;//0-1, updated at 3.3hz (this represents normalised time!)
public float mrVisualCarryTimer;//0-1, updated at 60hz
public float mrCarrySpeed = 1.0f;
public float mrBaseCarrySpeed = 1.0f;//before faffing with cold, etc
public float mrMynockCounter = 0.0f;
public float mrMynockDebounce = 0.0f;
public GameObject mCarriedObjectParent;//this is what we move, and what has the LOD calc on it until Martijn does more useful lodding code
public GameObject mCarriedObjectCube;//A child of above, has it's UVs set
public GameObject mCarriedObjectItem; //A child of the parent
public GameObject mConveyorObject;//optimise things by predicating off of this objects IsVisible
public GameObject mBeltObject;//can be hidden at a distance; containers the UVScroller component
GameObject SpecificDetail;//Used in special cases only
Animation mAnimation;
public ushort mCarriedCube; //Is this now 100% deprecated?
public ushort mCarriedValue; // ALSO CARRY VALUE FFS
public ItemBase mCarriedItem;
public int ExemplarItemID = -1;
public ushort ExemplarBlockID;
public ushort ExemplarBlockValue;
public bool mbInvertExemplar;
public Light mMotorLight;
System.Random mRand;
public Vector3 mItemForwards;//if our item was delivered from another conveyor, then
public bool mbMynockNeeded;//if we load off disk and our mynock timer drops below 5, we know we haven't got a saved mynock on there
public int mnItemsPerMinute;
public int mnItemsThisMinute;
float mrIPMCounter = 60;
bool mbInstancedBase;
int mnInstancedID = -1;
int mnInstancerType;
// Flag to stop grommet exploit.
private bool mInOffloadFromGrommet;
public void ClearConveyor()
{
mCarriedCube = eCubeTypes.NULL;
mCarriedItem = null;
//Reset other things as needed
mbReadyToConvey = true;
mrCarryTimer = 0.0f;
mbStopBelt = true;
mbConveyorBlocked = false;
MarkDirtyDelayed();
}
public uint mConveyedItems;
bool mbUnityCubeNeedsUpdate;
Vector3 mDetailForward = Vector3.forward;
public Vector3 mForwards;
public Vector3 mUp;//What we rotate around, if requested
public Vector3 mLeft;
public Vector3 mRight;
// public bool mbAttachedToConveyor;
// public bool mbAttachedToHopper;
public bool mbConveyorBlocked;
public bool mbStopBelt;//Is this 'stop animating the scroller'
public float mrBlockedTime;
public bool mbConveyorVisuallyBlocked;
public static GameObject IngotObject;
bool mbRotateModel = false;
Quaternion mTargetRotation = Quaternion.identity;
int mnRotationWithoutSuccess;
// public bool ForceRotationAroundY;
//This order MUST match the Value!
public enum eConveyorType
{
eConveyor,
eConveyorFilter,
eTransportPipe,
eTransportPipeFilter,
eConveyorStamper, //converts bars into plates
eConveyorExtruder, //converts bars into piles of wire, somehow
eConveyorCoiler, //converts piles of wire into spools of wire, somehow.
eConveyorBender, //converts tubes into bent tubes
eConveyorPipeExtrusion,//converts bars into tubes
eConveyorPCBAssembler,//converts pipes into bent pipes <-best comment ever
eConveyorTurntable,//automatically rotates after item entry; cannot rotate twice, only once, three and four times
eBasicConveyor,//cheap as chips, but really horribly slow
eAdvancedFilter,//allows exemplar
eConveyorSlopeUp,//Slopes move an item up and along a square. Act like normal conveyors in all other respects. Basically add our up to our drop off position
eConveyorSlopeDown,
eMotorisedConveyor,//This performs the storage hopper look up 3x faster
eBasicCorner_CW,
eBasicCorner_CCW,
eCorner_CW,
eCorner_CCW,
eNumConveyorTypes,
}
//conversion machines should rely almost entirely on unity animation, and simply offer up the necessary item onwards.
bool mbItemHasBeenConverted;
int mnNumRotations;
public bool mbRecommendPlayerUnfreeze;
public bool mbConveyorFrozen;//run at 1% speed, turn blue.
public bool mbConveyorToxic;//run at 0-10% speed, turn green
int mnPenaltyFactor;//0-100
bool mbConveyorNeedsColourChange;
public int mnCurrentPenaltyFactor = 0;
float mrSleepTimer;
public int autoturncheck;
public int adjuvantconveyorcheck;
//This can only be set if we are Value 1/3, which is a Filter
public eHopperRequestType meRequestType = eHopperRequestType.eAny;
// ************************************************************************************************************************************************
public void SwitchRequestType()
{
MarkDirtyDelayed();
meRequestType++;
if (meRequestType == eHopperRequestType.eNum) meRequestType = eHopperRequestType.eAny;
ExemplarItemID = -1;
ExemplarBlockValue = 0;
ExemplarBlockID = 0;
ExemplarString = PersistentSettings.GetString("Conv_NONE");
Debug.LogWarning("Conveyor using generic requests and wiping Exemplar!");
}
// ************************************************************************************************************************************************
public void SwitchRequestTypeRev()
{
MarkDirtyDelayed();
meRequestType--;
if ((int)meRequestType <= 0) meRequestType = (eHopperRequestType.eNum - 1);
ExemplarItemID = -1;
ExemplarBlockValue = 0;
ExemplarBlockID = 0;
ExemplarString = PersistentSettings.GetString("Conv_NONE");
Debug.LogWarning("Conveyor using generic requests and wiping Exemplar!");
}
public string ExemplarString = PersistentSettings.GetString("Conv_NONE");
// ************************************************************************************************************************************************
public void SetExemplar(ItemBase lExemplar)
{
FloatingCombatTextQueue lFQ = FloatingCombatTextManager.instance.QueueText(mnX, mnY + 1, mnZ, 1.0f, ItemManager.GetItemName(lExemplar), Color.green, 1.5f);
if (lFQ != null) lFQ.mrStartRadiusRand = 0.25f;
ExemplarString = ItemManager.GetItemName(lExemplar);
if (lExemplar.mnItemID != -1)
{
ExemplarItemID = lExemplar.mnItemID;
if (ExemplarItemID == 0)
{
Debug.LogError("Error, Exemplar attempted to be set, but no ItemID? " + ItemManager.GetItemName(lExemplar));
meRequestType = eHopperRequestType.eNone; // Illegal request type, prevent anything being extracted.
}
else
{
// Set to Any so that we don't interfere now a valid examplar has been set.
meRequestType = eHopperRequestType.eAny;
}
ExemplarBlockValue = 0;
ExemplarBlockID = 0;
}
else
{
if (lExemplar.mType == ItemType.ItemCubeStack)
{
ExemplarBlockID = (lExemplar as ItemCubeStack).mCubeType;
ExemplarBlockValue = (lExemplar as ItemCubeStack).mCubeValue;
ExemplarItemID = -1;
// Set to Any so that we don't interfere now a valid examplar has been set.
meRequestType = eHopperRequestType.eAny;
}
else
{
//I dont fucking know
Debug.LogWarning("Error, unable to set exemplars for type " + ItemManager.GetItemName(lExemplar));
meRequestType = eHopperRequestType.eNone; // Illegal request type, prevent anything being extracted.
}
}
MarkDirtyDelayed();
Debug.LogWarning("Conveyor set to Exemplar " + ExemplarItemID + "/" + ExemplarBlockID + "/" + ExemplarBlockValue);
//+ ItemManager.GetItemName(lExemplar));
//lnItemID);
}
// ************************************************************************************************************************************************
public ConveyorEntity(Segment segment, long x, long y, long z, ushort cube, byte flags, ushort lValue, bool lbLoadedFromDisk) : base(eSegmentEntity.Conveyor, SpawnableObjectEnum.Conveyor, x, y, z, cube, flags, lValue, Vector3.zero, segment)
{
mRand = new System.Random();
mValue = lValue;
SetObjectType();
mbNeedsLowFrequencyUpdate = true;
mbNeedsUnityUpdate = true;
mCarriedCube = eCubeTypes.NULL;
mrCarryTimer = 0;
mbReadyToConvey = true;
mForwards = SegmentCustomRenderer.GetRotationQuaternion(flags) * Vector3.forward;
mForwards.Normalize();
mDetailForward = mForwards;
mItemForwards = mForwards;//Start with a Valid forwards
mUp = SegmentCustomRenderer.GetRotationQuaternion(flags) * Vector3.up;
mUp.Normalize();
mLeft = SegmentCustomRenderer.GetRotationQuaternion(flags) * Vector3.left;
mLeft.Normalize();
mRight = SegmentCustomRenderer.GetRotationQuaternion(flags) * Vector3.right;
mRight.Normalize();
mrMaxPower = 0;
base.DoThreadedRaycastVis = true;
base.MaxRayCastVis = 80;
base.RayCastOffset = mUp * 0.35f;//new Vector3(0,0.5f,0);//so above the conveyor, not world.up (Reduced so that we won't break 'above' within a single cube)
if (lValue == (ushort)eConveyorType.eConveyorFilter || lValue == (ushort)eConveyorType.eTransportPipeFilter)
{
meRequestType = eHopperRequestType.eNone;//Default to nothing, so player can make the rest of the network
}
if (lValue == (ushort)eConveyorType.eAdvancedFilter)
{
meRequestType = eHopperRequestType.eNone;//Default to nothing, so player can make the rest of the network; BlockId or non-zero Exemplar will allow progress
}
/*
//T1 conveyors cannot stick to walls and ceilings; their Y must be zero!
if (lValue == (ushort)eConveyorType.eConveyor || lValue == (ushort)eConveyorType.eConveyorFilter)
{
if (mForwards.y != 0.0f)
{
WorldScript.instance.Dig(segment,(int)(x % 16),(int)(y % 16),(int)(z % 16));
//and re-drop ourselves!
Vector3 lUnityPos = WorldScript.instance.mPlayerFrustrum.GetCoordsToUnity(x, y, z);
CollectableManager.instance.QueueCollectableSpawn(
lUnityPos,cube,lValue,mForwards,0.1f);//re-drop, but slowly
}
}
*/
//u wot m8
//if (PersistentSettings.settingsIni.GetBoolean("FastConveyors",false))
if (lValue == (ushort)eConveyorType.eMotorisedConveyor)
{
mrMaxPower = 125;//about 25 items
}
mnY = y;//just so I am sure
CalcPenaltyFactor();
//if we are looking at a conveyor, and the conveyor is looking at us, then rotate ourselves to face the same way as that conveyor
// Debug.Log("Conveyor looking along dir " + dir.ToString() + " using flags" + flags);
if (lValue == (ushort)eConveyorType.eBasicConveyor ||
lValue == (ushort)eConveyorType.eConveyor ||
lValue == (ushort)eConveyorType.eConveyorTurntable ||
lValue == (ushort)eConveyorType.eTransportPipe)
{
//Ones from disk seem to break randomly. Not going to invDebug.LogWarning ("Falling at " + mVelocity.y + "/" + (WorldScript.instance.mWorldData.mrMaxFallingSpeed * Time.deltaTime).ToString ());estigate, by the time we loaded from disk, we can assume the player achieved what they wanted
if (WorldScript.mbIsServer)
{
//Update it's own mesh on placement acourding to it's enviroment
AutoTurn();
//Update conveyor mesh in front of this one
CheckAdjacentConveyor();
}
}
else if (lValue == (ushort)eConveyorType.eConveyorSlopeUp && WorldScript.mbIsServer)
{
//Update conveyor mesh in front of this one
CheckAdjacentConveyor();
}
CalcCarrySpeed();
mnInstancedID = -1;//Ensure that we don't have one, and, more importantly, don't try and give one BACK!
if (lValue == (ushort)eConveyorType.eBasicConveyor || lValue == (ushort)eConveyorType.eConveyor)
{
mbInstancedBase = true;
mnInstancerType = (int)InstanceManager.eSimpleInstancerType.eT1ConveyorBase;
}
base.MaxNetworkSendDist = 8;//temp - probably more like 64 - base on rate?
if (lValue == (ushort)eConveyorType.eAdvancedFilter || lValue == (ushort)eConveyorType.eConveyorFilter || lValue == (ushort)eConveyorType.eTransportPipeFilter)
{
base.MaxNetworkSendDist = 128;
}
if (IsCrafter())
{
base.MaxNetworkSendDist = 128;
}
}
void CalcPenaltyFactor()
{
mnPenaltyFactor = 0;
mbRecommendPlayerUnfreeze = false;
if (mValue == (ushort)eConveyorType.eConveyor || mValue == (ushort)eConveyorType.eBasicConveyor ||
mValue == (ushort)eConveyorType.eConveyorSlopeUp || mValue == (ushort)eConveyorType.eConveyorSlopeDown ||
mValue == (ushort)eConveyorType.eCorner_CW || mValue == (ushort)eConveyorType.eBasicCorner_CW ||
mValue == (ushort)eConveyorType.eCorner_CCW || mValue == (ushort)eConveyorType.eBasicCorner_CCW)
{
if (mnY - WorldScript.mDefaultOffset < BiomeLayer.CavernColdCeiling && mnY - WorldScript.mDefaultOffset > BiomeLayer.CavernColdFloor)
{
bool lbDoCold = true;
if (mRoomController != null)
{
if (mRoomController.mrHeatModulation >= 1.0f)
{
//hurray
lbDoCold = false;
}
}
//We are a T1 conveyor in an invalid location, punish the player (and encourage MM and T2s)
mbConveyorFrozen = true;
mbHoloDirty = true;
mnPenaltyFactor = (int)(BiomeLayer.CavernColdCeiling - (mnY - WorldScript.mDefaultOffset));
mnPenaltyFactor *= 100;
if (mnPenaltyFactor > 10000) mnPenaltyFactor = 10000;
mnCurrentPenaltyFactor = 0;
}
if (mnY - WorldScript.mDefaultOffset < BiomeLayer.CavernToxicCeiling && mnY - WorldScript.mDefaultOffset > BiomeLayer.CavernToxicFloor)
{
bool lbDoToxic = true;
if (mRoomController != null)
{
if (mRoomController.mrToxicRating >= 1.0f)
{
//hurray
lbDoToxic = false;
}
}
if (lbDoToxic)
{
//We are a T1 conveyor in an invalid location, punish the player (and encourage MM and T2s)
mbConveyorToxic = true;
mnCurrentPenaltyFactor = mRand.Next(2000, 5000);
//Random.Range(2000,5000);
mnPenaltyFactor = mnCurrentPenaltyFactor - 1;//will force an update during, er, update
//mrCarrySpeed /= (float)Random.Range(2,50);
}
}
}
else
{
mnCurrentPenaltyFactor = 0;
}
}
void CalcCarrySpeed()
{
mrCarrySpeed = TIER1_SPEED;
//T2 moves quickly
if (mValue == (ushort)eConveyorType.eTransportPipe || mValue == (ushort)eConveyorType.eTransportPipeFilter)
{
mrCarrySpeed = TIER2_SPEED;
}
//T0 does not
if (mValue == (ushort)eConveyorType.eBasicConveyor)
{
mrCarrySpeed = TIER0_SPEED;
}
if (mValue == (ushort)eConveyorType.eBasicCorner_CW) mrCarrySpeed = TIER0_SPEED;
if (mValue == (ushort)eConveyorType.eBasicCorner_CCW) mrCarrySpeed = TIER0_SPEED;
if (mValue == (ushort)eConveyorType.eCorner_CW) mrCarrySpeed = TIER1_SPEED;
if (mValue == (ushort)eConveyorType.eCorner_CCW) mrCarrySpeed = TIER1_SPEED;
//Because I can't be bothered to deal with the compaints...
if (mValue == (ushort)eConveyorType.eAdvancedFilter)
{
mrCarrySpeed = TIER2_SPEED;
}
if (mValue == (ushort)eConveyorType.eMotorisedConveyor)
{
mrCarrySpeed = TIER3_SPEED;
}
if (DifficultySettings.mbFastConveyors)//Should this affect assembly line machines?
{
mrCarrySpeed *= FAST_SETTING_SPEED_FACTOR;
}
if (DifficultySettings.mbRushMode)
{
mrCarrySpeed *= 2.0f;//I wonder what this is going to do...
}
//If conevyor is going UP, reduce speed massively
if (mForwards.y > 0.0f)
{
//All tiers, initially, until I tested it.
mrCarrySpeed *= VERTICAL_SPEED_FACTOR;
//Debug.LogWarning(lValue.ToString() + "Conveyor heading at Y of " + mForwards.y + ": reducing Carry speed to " + mrCarrySpeed);
}
//Assembly line machines aren't affected
if (DifficultySettings.mbRoboMania)
{
mrCarrySpeed /= 16.0f;
}
float lrAssemblySpeed = TIER0_SPEED;
if (DifficultySettings.mbCasualResource) lrAssemblySpeed *= 3.0f;
//3.06 - Assembly lines made slower.
if (mValue == (ushort)eConveyorType.eConveyorStamper) mrCarrySpeed = lrAssemblySpeed;
if (mValue == (ushort)eConveyorType.eConveyorPCBAssembler) mrCarrySpeed = lrAssemblySpeed;
if (mValue == (ushort)eConveyorType.eConveyorCoiler) mrCarrySpeed = lrAssemblySpeed;
if (mValue == (ushort)eConveyorType.eConveyorExtruder) mrCarrySpeed = lrAssemblySpeed;
if (mValue == (ushort)eConveyorType.eConveyorPipeExtrusion) mrCarrySpeed = lrAssemblySpeed;
mrBaseCarrySpeed = mrCarrySpeed;
}
void SetObjectType()
{
if (mValue == (ushort)eConveyorType.eConveyor) mObjectType = SpawnableObjectEnum.Conveyor;
if (mValue == (ushort)eConveyorType.eConveyorFilter) mObjectType = SpawnableObjectEnum.Conveyor_Filter_Single;
if (mValue == (ushort)eConveyorType.eTransportPipe) mObjectType = SpawnableObjectEnum.TransportPipe;
if (mValue == (ushort)eConveyorType.eTransportPipeFilter) mObjectType = SpawnableObjectEnum.TransportPipe_Filter_Single;
//FC2 force away from SH
if (mValue == (ushort)eConveyorType.eConveyorStamper) mObjectType = SpawnableObjectEnum.Stamper_T1;
if (mValue == (ushort)eConveyorType.eConveyorBender) mObjectType = SpawnableObjectEnum.AirInductor;//on purpose error
if (mValue == (ushort)eConveyorType.eConveyorCoiler) mObjectType = SpawnableObjectEnum.Coiler_T1;
if (mValue == (ushort)eConveyorType.eConveyorExtruder) mObjectType = SpawnableObjectEnum.Extruder_T1;
if (mValue == (ushort)eConveyorType.eConveyorPipeExtrusion) mObjectType = SpawnableObjectEnum.PipeExtruder_T1;
if (mValue == (ushort)eConveyorType.eConveyorPCBAssembler) mObjectType = SpawnableObjectEnum.PCBAssembler_T1;
if (mValue == (ushort)eConveyorType.eConveyorTurntable) mObjectType = SpawnableObjectEnum.Turntable_T1;
if (mValue == (ushort)eConveyorType.eBasicConveyor) mObjectType = SpawnableObjectEnum.BasicConveyor;
if (mValue == (ushort)eConveyorType.eAdvancedFilter) mObjectType = SpawnableObjectEnum.Conveyor_Filter_Advanced;//FC2 force away from SH
if (mValue == (ushort)eConveyorType.eConveyorSlopeUp) mObjectType = SpawnableObjectEnum.Conveyor_SlopeUp;
if (mValue == (ushort)eConveyorType.eConveyorSlopeDown) mObjectType = SpawnableObjectEnum.Conveyor_SlopeDown;
if (mValue == (ushort)eConveyorType.eMotorisedConveyor) mObjectType = SpawnableObjectEnum.Conveyor_Motorised;//FC2 force away from SH
if (mValue == (ushort)eConveyorType.eBasicCorner_CW) mObjectType = SpawnableObjectEnum.Basic_Conveyor_Corner_CW;
if (mValue == (ushort)eConveyorType.eBasicCorner_CCW) mObjectType = SpawnableObjectEnum.Basic_Conveyor_Corner_CCW;
if (mValue == (ushort)eConveyorType.eCorner_CW) mObjectType = SpawnableObjectEnum.Conveyor_Corner_CW;
if (mValue == (ushort)eConveyorType.eCorner_CCW) mObjectType = SpawnableObjectEnum.Conveyor_Corner_CCW;
}
// ************************************************************************************************************************************************
public override void SpawnGameObject()
{
// object based on value for tiers
SetObjectType();
base.SpawnGameObject();
}
// ************************************************************************************************************************************************
public override void DropGameObject()
{
base.DropGameObject();
mbLinkedToGO = false;
mbCheckedScroller = false;
mPGScroller = null;
mInstancedScroller = null;
if (mnInstancedID != -1)
{
InstanceManager.instance.maSimpleInstancers[mnInstancerType].Remove(mnInstancedID);
mnInstancedID = -1;
}
}
// ************************************************************************************************************************************************
int mnLFUpdates;
float mrReadoutTick;
// ************************************************************************************************************************************************
InventoryExtractionOptions mCachedHopperOptions = new InventoryExtractionOptions();
InventoryExtractionResults mCachedHopperResults = new InventoryExtractionResults();
void LookForHopper()
{
long checkX = this.mnX;
long checkY = this.mnY;
long checkZ = this.mnZ;
int lnXMod = 0;
int lnYMod = 0;
int lnZMod = 0;
if (mnLFUpdates % 6 == 0) lnXMod--;
if (mnLFUpdates % 6 == 1) lnXMod++;
if (mnLFUpdates % 6 == 2) lnYMod--;
if (mnLFUpdates % 6 == 3) lnYMod++;
if (mnLFUpdates % 6 == 4) lnZMod--;
if (mnLFUpdates % 6 == 5) lnZMod++;
//Never attempt to take items FROM the forwards tho (else we will take stuff out of the hopper we're putting things into)
if (lnXMod == (int)mForwards.x &&
lnYMod == (int)mForwards.y &&
lnZMod == (int)mForwards.z)
{
return;
}
if (mValue == (int)eConveyorType.eMotorisedConveyor)
{
lnXMod = -(int)mForwards.x;
lnYMod = -(int)mForwards.y;
lnZMod = -(int)mForwards.z;
}
checkX += lnXMod;
checkY += lnYMod;
checkZ += lnZMod;
Segment checkSegment = AttemptGetSegment(checkX, checkY, checkZ);
if (checkSegment == null)
return;
var hopperEntity = checkSegment.SearchEntity(checkX, checkY, checkZ) as StorageMachineInterface;
if (hopperEntity != null)
{
// Check the permissions on this inventory.
eHopperPermissions permissions = hopperEntity.GetPermissions();
if (permissions == eHopperPermissions.Locked)
return;
// Check logistics are currently allowed
if (false == hopperEntity.InventoryExtractionPermitted)
return;
mCachedHopperOptions.SourceEntity = this;
mCachedHopperOptions.RequestType = meRequestType;
mCachedHopperOptions.ExemplarItemID = ExemplarItemID;
mCachedHopperOptions.ExemplarBlockID = ExemplarBlockID;
mCachedHopperOptions.ExemplarBlockValue = ExemplarBlockValue;
mCachedHopperOptions.InvertExemplar = mbInvertExemplar;
mCachedHopperOptions.MinimumAmount = 1;
mCachedHopperOptions.MaximumAmount = 1;
if (hopperEntity.TryExtract(mCachedHopperOptions, ref mCachedHopperResults))
{
if (mCachedHopperResults.Item != null)
{
AddItem(mCachedHopperResults.Item);
}
else
{
AddCube(mCachedHopperResults.Cube, mCachedHopperResults.Value, 1.0f);
}
mCachedHopperResults.Item = null;
base.ImportantNetworkUpdate = true;//this will override the distance check when the next transmission goes live
RequestImmediateNetworkUpdate(); //we collected something from a storage hopper, sync across network
}
}
}
// ************************************************************************************************************************************************
public bool IsCarryingCargo()
{
#if FC_2
if (mCarriedCube != eCubeTypes.OreCoal)
if (mCarriedCube != eCubeTypes.NULL) Debug.LogError("We *ARE* still using CarriedCubes! " + TerrainData.GetNameForValue(mCarriedCube, mCarriedValue));
#endif
if (mCarriedCube != eCubeTypes.NULL) return true;
if (mCarriedItem != null) return true;
return false;
}
// ************************************************************************************************************************************************
void OffloadCargo(long checkX, long checkY, long checkZ)
{
if (mCarriedCube == eCubeTypes.NULL && mCarriedItem == null)
{
if (WorldScript.mbIsServer)
{
Debug.LogError("Error, attempted to offload cargo, but both cube and carried item were null!?");
FinaliseOffloadingCargo();
}
return;
}
if (WorldScript.mbIsServer == false)
{
if (IsConveyor() == false)
{
return;//assembly line machines DO NOT handoff on the client, only the server. This should avoid the (slightly confusing) copper bar into stamper, tin plate out...
}
}
// If this is an upslope conveyor check forwards and upwards one space.
if (mObjectType == SpawnableObjectEnum.Conveyor_SlopeUp)
{
checkX += (int)mUp.x;
checkY += (int)mUp.y;
checkZ += (int)mUp.z;
}
//if (mObjectType == SpawnableObjectEnum.Conveyor_SlopeDown)
//Do nothing - the output from this is straight
// Debug.Log("CheckX:" + checkX + ".ThisX:" + this.mnX);
// Debug.Log("CheckY:" + checkY + ".ThisY:" + this.mnY);
// Debug.Log("CheckZ:" + checkZ + ".ThisZ:" + this.mnZ);
// Debug.Log(mForwards);
Segment checkSegment = AttemptGetSegment(checkX, checkY, checkZ);
if (checkSegment == null)
return;
ushort lCube = checkSegment.GetCube(checkX, checkY, checkZ);
// special case - Logistics Grommet
if (lCube == eCubeTypes.LogisticsGrommet && !mInOffloadFromGrommet)
{
//If there is another PSB the OTHER side of this, hook that up
long lDiffX = (mnX - checkX) * 2;
long lDiffY = (mnY - checkY) * 2;
long lDiffZ = (mnZ - checkZ) * 2;
//todo, ensure no teleporting down stripes.
mInOffloadFromGrommet = true;
OffloadCargo(mnX - lDiffX, mnY - lDiffY, mnZ - lDiffZ);
mInOffloadFromGrommet = false;
return;
}
// This flag will be set if we've decided to look for a download conveyor which should be in front and down one space.
bool lbOnlyAllowDownSlope = false;
if (lCube == eCubeTypes.Air)//this ensures we don't do the re-check when there's something like a hopper here. It also means no clipping through stuff!
{
//checkY--;
//Assume Downward convyor matches original's orientation for those who like building pretty conveyor systems
checkX -= (int)mUp.x;
checkY -= (int)mUp.y;
checkZ -= (int)mUp.z;
checkSegment = AttemptGetSegment(checkX, checkY, checkZ);
if (checkSegment == null)
return;
lCube = checkSegment.GetCube(checkX, checkY, checkZ);
lbOnlyAllowDownSlope = true;
}
bool successfullyOffloaded = false;
// First consider conveyors separately.
if (lCube == eCubeTypes.Conveyor)
{
// mbAttachedToConveyor = true;
// mbAttachedToHopper = false;
//this is quite a slow call. Given that we are, you know, a conveyor, and only have 1 check location, I wonder if this can be smarted up? Offload Cargo can take 100ms on huge worlds
//We could cache the type and then only call this if it changes. Also need to check if the old one was deleted
ConveyorEntity lConv = checkSegment.FetchEntity(eSegmentEntity.Conveyor, checkX, checkY, checkZ) as ConveyorEntity;
// If this is a conveyor, and either we are happy for any type of conveyor, or it's a downslope
if (lConv != null && (!lbOnlyAllowDownSlope || lConv.mObjectType == SpawnableObjectEnum.Conveyor_SlopeDown))
{
float lrDot = Vector3.Dot(mForwards, lConv.mForwards);
// Debug.Log("Conveyors have a dot of " + lrDot);
bool validConveyor = true;
if (lrDot < -0.9f)//I am not going to risk checking <1.0f
{
//This means we are pointing AT the conveyor - and it's pointing at us!
validConveyor = false;
}
if (lConv.mObjectType == SpawnableObjectEnum.Conveyor_SlopeUp || lConv.mObjectType == SpawnableObjectEnum.Conveyor_SlopeDown)
{
if (lrDot < 0.9f)
{
//Debug.LogWarning("Can't drop off to target slope that's not in the same direction");
validConveyor = false;
}
}
//Conveyor handing to another conveyor
//If these are assembly line machines, they shouldn't skip nor allow sideways stuff, really...
if (validConveyor && lConv.mbReadyToConvey && lConv.mrLockTimer == 0.0f)//should this be collapsed into one ready check?
{
//hurrah
if (mCarriedCube != eCubeTypes.NULL)
{
ARTHERPetSurvival.instance.GotOre(mCarriedCube);
//todo, if this is a conveyor at 90 degrees along the Y, drop in with a 50% offset
float lrOffset = 0.5f;
if (lConv.mForwards == mForwards) lrOffset = 1.0f;
//We should now pass on any 'over' simulation. T2 pipes on Fast update at 0.8/tick, so that means we're quite likely at a carrytimer of <-0.6 !
lrOffset += mrCarryTimer;
lConv.AddCube(mCarriedCube, mCarriedValue, lrOffset);
}
else
{
//attempt to add Item
//Debug.Log("Conveyor has no Item to convey?");
float lrOffset = 0.5f;
if (lConv.mForwards == mForwards) lrOffset = 1.0f;
//We should now pass on any 'over' simulation. T2 pipes on Fast update at 0.8/tick, so that means we're quite likely at a carrytimer of <-0.6 !
lrOffset += mrCarryTimer;
lConv.AddItem(mCarriedItem, lrOffset);
}
lConv.mItemForwards = mItemForwards;
mCarriedCube = eCubeTypes.NULL;
mCarriedValue = 0;
mCarriedItem = null;
mbStopBelt = true;
mbConveyorBlocked = false;
FinaliseOffloadingCargo();
successfullyOffloaded = true;
}
}
}
else
{
// If we haven't offloaded to another conveyor then attempt to offload to another entity type now.
if (!lbOnlyAllowDownSlope)
{
#if UNITY_EDITOR
if (!CubeHelper.IsMachine(lCube))
{
//If we point the conveyor at, say, a rock, this will entirely break, but only in-editor. Else we assume that it is a Mod.
//Debug.LogError("Correct assumption! Do not call this for non-machines");
}
else
{
#endif
// Determine type of entity at this location.
eSegmentEntity entityType = EntityManager.GetEntityTypeFromBlock(lCube);
// Try to get the entity, it must implement the ItemConsumerInterface
ItemConsumerInterface targetEntity = checkSegment.FetchEntity(entityType, checkX, checkY, checkZ) as ItemConsumerInterface;
// We found a consumer entity
if (targetEntity != null)
{
// Try to deliver the item or cube.
if (targetEntity.TryDeliverItem(this, mCarriedItem, mCarriedCube, mCarriedValue, true))
{
// Successfully delivered the item or cube.
// Clear the item or cube
mCarriedItem = null;
mCarriedCube = eCubeTypes.NULL;
mCarriedValue = 0;
// Stop the belt and flag the conveyor is not blocked
mbStopBelt = true;
mbConveyorBlocked = false;
FinaliseOffloadingCargo();
// Request a network update
RequestImmediateNetworkUpdate();
successfullyOffloaded = true;
}
}
#if UNITY_EDITOR
}
#endif
}
}
// If we've still failed to offload the item then do final actions
if (!successfullyOffloaded)
{
// Failed to offload this item.
if (!mbConveyorBlocked)
{
// Stop the belt and mark as blocked.
mbConveyorBlocked = true;
mbStopBelt = true;
base.ImportantNetworkUpdate = true;//Force a single update regardless of distance. To do : make sure this IS a single update!
RequestImmediateNetworkUpdate();//ensure this ripples outwards to the clients
}
// If we are a conveyor turntable turn to face the next direction.
if (mObjectType == SpawnableObjectEnum.Turntable_T1)
{
//Debug.LogWarning ("TT facing Conv, spinning" + lrDot);
DoNextTurnTable();
return;
}
}
else
{
//we have successfully cleared down the cube
meNextAnimState = eAnimState.Out;
//Debug.LogWarning("Setting *OUT* anim!");
mnRotationWithoutSuccess = 0;
}
// if (lCube == eCubeTypes.StorageHopper)
// {
//// mbAttachedToConveyor = true;
//// mbAttachedToHopper = false;
//
// StorageHopper lHop = checkSegment.FetchEntity(eSegmentEntity.StorageHopper,checkX,checkY,checkZ) as StorageHopper;
// if (lHop != null)
// {
// //Cube/Item path
// if (mCarriedCube != eCubeTypes.NULL)
// {
// //Does the hopper have room?
// if (lHop.mnStorageFree > 0)
// {
// //hurray
// lHop.AddCube(mCarriedCube, mCarriedValue);
//
// // Clear the item or cube
// mCarriedCube = eCubeTypes.NULL;
// mCarriedValue = 0;
//
// // Stop the belt
// mbStopBelt = true;
//
// // Conveyor is not blocked if it successfully offloaded
// mbConveyorBlocked = false;
//
// RequestImmediateNetworkUpdate();
// lHop.RequestImmediateNetworkUpdate();
//
// FinaliseOffloadingCargo();
// }
// else
// {
// //Debug.Log("Conveyor's target hopper is full!");
// if (!mbConveyorBlocked)
// {
// mbConveyorBlocked = true;
// mbStopBelt = true;
// }
//
// if (mObjectType == SpawnableObjectEnum.Turntable_T1)
// {
// //Debug.LogWarning ("TT facing Conv, spinning" + lrDot);
// DoNextTurnTable();
// return;
// }
// }
// }
// else
// {
// //Does the hopper have room?
// if (lHop.mnStorageFree > 0)
// {
// //hurray
// lHop.AddItem(mCarriedItem);
//
//
// mCarriedItem = null;
// mbStopBelt = true;
// //Debug.Log("Conveyor offloaded Cube to a hopper");
// mbConveyorBlocked = false;
//
// FinaliseOffloadingCargo();
//
// RequestImmediateNetworkUpdate();
// lHop.RequestImmediateNetworkUpdate();
// }
// else
// {
// //Debug.Log("Conveyor's target hopper is full!");
// if (!mbConveyorBlocked)
// {
// mbConveyorBlocked = true;
// mbStopBelt = true;