-
Notifications
You must be signed in to change notification settings - Fork 21
/
EntityEvaluator.cs
996 lines (591 loc) · 19.8 KB
/
EntityEvaluator.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
using ModularEncountersSystems.API;
using ModularEncountersSystems.Helpers;
using ModularEncountersSystems.Logging;
using Sandbox.Definitions;
using Sandbox.Game;
using Sandbox.Game.Entities;
using Sandbox.Game.Weapons;
using Sandbox.ModAPI;
using Sandbox.ModAPI.Weapons;
using System;
using System.Collections.Generic;
using System.Text;
using VRage.Game;
using VRage.Game.ModAPI;
using VRage.ModAPI;
using VRageMath;
namespace ModularEncountersSystems.Entities {
public enum BlockTypeEnum {
None,
All,
Antennas,
Beacons,
Buttons,
Containers,
Controllers,
Gravity,
Guns,
Gyros,
Inhibitors,
JumpDrives,
Mechanical,
Medical,
NanoBots,
Power,
Parachutes,
Production,
Projectors,
RivalAi,
Seats,
Shields,
Stores,
Thrusters,
Tools,
Turrets,
TurretControllers
}
public enum OwnerTypeEnum {
None = 0,
Unowned = 1,
Player = 1 << 1,
NPC = 1 << 2
}
public enum RelationTypeEnum {
None = 0,
Enemy = 1,
Neutral = 1 << 1,
Friends = 1 << 2,
Faction = 1 << 3
}
public static class EntityEvaluator {
public static double AltitudeAtPosition(Vector3D coords) {
foreach (var planet in PlanetManager.Planets) {
if (planet.Closed)
continue;
if (planet.IsPositionInRange(coords))
return planet.AltitudeAtPosition(coords);
}
return -1000000;
}
public static List<GridEntity> GetAttachedGrids(IMyCubeGrid cubeGrid) {
var gridList = new List<GridEntity>();
if (cubeGrid == null)
return gridList;
GetAttachedGrids(cubeGrid, gridList);
return gridList;
}
public static void GetAttachedGrids(IMyCubeGrid cubeGrid, List<GridEntity> gridList) {
lock(gridList)
gridList.Clear();
var gridGroup = MyAPIGateway.GridGroups.GetGroup(cubeGrid, GridLinkTypeEnum.Physical);
foreach (var grid in GridManager.Grids) {
if (grid.IsClosed() || !grid.HasPhysics)
continue;
if (gridGroup.Contains(grid.CubeGrid))
gridList.Add(grid);
}
}
public static void GetAttachedGrids(GridEntity parent) {
//SpawnLogger.Write("Method Start", SpawnerDebugEnum.Dev, true);
if (parent?.CubeGrid == null)
return;
//SpawnLogger.Write("Clear Lists", SpawnerDebugEnum.Dev, true);
lock (parent.PhysicalLinkedGrids)
parent.PhysicalLinkedGrids.Clear();
lock (parent.LinkedGrids)
parent.LinkedGrids.Clear();
//SpawnLogger.Write("Get Group", SpawnerDebugEnum.Dev, true);
MyAPIGateway.GridGroups.GetGroup(parent.CubeGrid, GridLinkTypeEnum.Physical, parent.PhysicalLinkedGrids);
parent.RefreshLinkedGrids = false;
//SpawnLogger.Write("First Loop", SpawnerDebugEnum.Dev, true);
foreach (var grid in GridManager.Grids) {
if (grid == null || grid.IsClosed() || !grid.HasPhysics)
continue;
if (grid.CubeGrid != null && parent.PhysicalLinkedGrids.Contains(grid.CubeGrid))
parent.LinkedGrids.Add(grid);
}
if (parent.LinkedGrids.Count == 0)
parent.LinkedGrids.Add(parent);
//SpawnLogger.Write("Second Loop", SpawnerDebugEnum.Dev, true);
for (int i = parent.LinkedGrids.Count - 1; i >= 0; i--) {
var grid = parent.LinkedGrids[i];
if (grid == null || grid == parent)
continue;
grid.LinkedGrids = parent.LinkedGrids;
grid.RefreshLinkedGrids = false;
}
}
public static GridEntity GetGridProfile(IMyCubeGrid cubeGrid) {
foreach (var grid in GridManager.Grids) {
if (grid.IsClosed() || !grid.HasPhysics)
continue;
if (grid.CubeGrid == cubeGrid)
return grid;
}
return null;
}
public static OwnerTypeEnum GetOwnersFromList(List<long> owners) {
var result = OwnerTypeEnum.Unowned;
if (owners.Count == 0)
return result;
foreach (var owner in owners) {
if (FactionHelper.IsIdentityNPC(owner)) {
result |= OwnerTypeEnum.NPC;
result &= ~OwnerTypeEnum.Unowned;
} else {
result |= OwnerTypeEnum.Player;
result &= ~OwnerTypeEnum.Unowned;
}
}
return result;
}
public static GridOwnershipEnum GetGridOwnerships(List<GridEntity> gridList, bool overrideCheck = false) {
GridOwnershipEnum result = GridOwnershipEnum.None;
for (int i = gridList.Count - 1; i >= 0; i--) {
var grid = GridManager.GetSafeGridFromIndex(i);
if(grid != null)
result |= GetGridOwnerships(grid, overrideCheck);
}
return result;
}
public static GridOwnershipEnum GetGridOwnerships(GridEntity grid, bool overrideCheck = false) {
if (!grid.ActiveEntity())
return GridOwnershipEnum.None;
if (!grid.RecheckOwnershipMajority && !overrideCheck)
return grid.Ownership;
GridOwnershipEnum result = GridOwnershipEnum.None;
foreach (var owner in grid.CubeGrid.BigOwners) {
if (owner == 0)
continue;
if (FactionHelper.IsIdentityPlayer(owner))
result |= GridOwnershipEnum.PlayerMajority;
else
result |= GridOwnershipEnum.NpcMajority;
}
foreach (var owner in grid.CubeGrid.SmallOwners) {
if (owner == 0 || grid.CubeGrid.BigOwners.Contains(owner))
continue;
if (FactionHelper.IsIdentityPlayer(owner))
result |= GridOwnershipEnum.PlayerMinority;
else
result |= GridOwnershipEnum.NpcMinority;
}
grid.RecheckOwnershipMajority = false;
grid.Ownership = result;
return result;
}
public static RelationTypeEnum GetRelationsFromList(long ownerId, List<long> owners) {
var result = RelationTypeEnum.None;
if (owners.Count == 0) {
result = RelationTypeEnum.Enemy;
return result;
}
foreach (var owner in owners) {
var relation = GetRelationBetweenIdentities(ownerId, owner);
if (!result.HasFlag(relation))
result |= relation;
}
return result;
}
public static RelationTypeEnum GetRelationBetweenIdentities(long ownerA, long ownerB) {
var factionA = MyAPIGateway.Session.Factions.TryGetPlayerFaction(ownerA);
var factionB = MyAPIGateway.Session.Factions.TryGetPlayerFaction(ownerB);
if (factionA != null && factionA == factionB)
return RelationTypeEnum.Faction;
if (FactionHelper.IsIdentityNPC(ownerA)) {
if (factionA != null)
return GetRelationFromReputation(MyAPIGateway.Session.Factions.GetReputationBetweenPlayerAndFaction(ownerB, factionA.FactionId));
}
if (FactionHelper.IsIdentityNPC(ownerB)) {
if (factionB != null)
return GetRelationFromReputation(MyAPIGateway.Session.Factions.GetReputationBetweenPlayerAndFaction(ownerA, factionB.FactionId));
}
if (factionA != null && factionB != null) {
return GetRelationFromReputation(MyAPIGateway.Session.Factions.GetReputationBetweenFactions(factionA.FactionId, factionB.FactionId));
}
return RelationTypeEnum.Enemy;
}
public static RelationTypeEnum GetRelationFromReputation(int reputation) {
if (reputation < -500)
return RelationTypeEnum.Enemy;
if (reputation > 500)
return RelationTypeEnum.Friends;
return RelationTypeEnum.Neutral;
}
public static double GravityAtPosition(Vector3D coords) {
foreach (var planet in PlanetManager.Planets) {
if (planet.Closed)
continue;
if (planet.IsPositionInRange(coords))
return GravityAtPosition(coords, planet);
}
return 0;
}
//150m Box of Red Ship
public static ITarget GetTargetFromBlockEntity(IMyCubeBlock entity) {
if (entity == null) {
//Logger.Write(" - IMyCubeBlock Entity Null", BehaviorDebugEnum.TargetAcquisition);
return null;
}
var grid = entity.SlimBlock.CubeGrid;
foreach (var gridEntity in GridManager.Grids) {
if (!gridEntity.ActiveEntity() || grid != gridEntity.CubeGrid)
continue;
foreach (var block in gridEntity.AllTerminalBlocks) {
if (!block.ActiveEntity())
continue;
if (entity.EntityId == block.Block.EntityId)
return block;
}
}
//Logger.Write(" - IMyCubeBlock Entity Not Found In Existing Grids", BehaviorDebugEnum.TargetAcquisition);
return null;
}
public static ITarget GetTargetFromEntity(IMyEntity entity) {
//Try Player
var character = entity as IMyCharacter;
var block = entity as IMyCubeBlock;
if (character != null) {
return GetTargetFromPlayerEntity(character);
} else if(block == null) {
var toolBase = entity as IMyEngineerToolBase;
var gunBase = entity as IMyGunBaseUser;
if (gunBase != null) {
return GetTargetFromPlayerEntity(gunBase.Owner as IMyCharacter);
}
if (toolBase != null) {
IMyEntity charEntity = null;
if (MyAPIGateway.Entities.TryGetEntityById(toolBase.OwnerId, out charEntity))
return GetTargetFromPlayerEntity(charEntity as IMyCharacter);
}
}
//Try Block/Grid
var grid = entity as IMyCubeGrid;
if (grid != null)
return GetTargetFromGridEntity(grid);
if (block != null)
return GetTargetFromBlockEntity(block);
return null;
}
public static ITarget GetTargetFromGridEntity(IMyCubeGrid entity) {
if (entity == null)
return null;
foreach (var gridEntity in GridManager.Grids) {
if (!gridEntity.ActiveEntity() || entity != gridEntity.CubeGrid)
continue;
return gridEntity;
}
return null;
}
public static ITarget GetTargetFromPlayerEntity(IMyCharacter entity) {
if (entity == null)
return null;
foreach (var playerEntity in PlayerManager.Players) {
if (!playerEntity.ActiveEntity() || entity.EntityId != playerEntity.ParentEntity.EntityId)
continue;
return playerEntity;
}
return null;
}
public static double GravityAtPosition(Vector3D coords, PlanetEntity planet) {
return planet.Gravity.GetGravityMultiplier(coords);
}
public static double GridBroadcastRange(List<GridEntity> grids, bool onlyAntenna = false) {
double result = 0;
foreach (var grid in grids) {
var power = GridBroadcastRange(grid);
if (power > result)
result = power;
}
return result;
}
public static double GridBroadcastRange(GridEntity grid, bool onlyAntenna = false, bool allowNpcSignals = false, string matchFaction = null, string matchName = null) {
double result = 0;
foreach (var antenna in grid.Antennas) {
if (antenna.IsClosed() || !antenna.Working || !antenna.Functional)
continue;
var antennaBlock = antenna.Block as IMyRadioAntenna;
if (antennaBlock == null || !antennaBlock.IsBroadcasting)
continue;
if (!allowNpcSignals && matchFaction == null && FactionHelper.IsIdentityNPC(antennaBlock.OwnerId))
continue;
if (matchFaction != null) {
var faction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(antennaBlock.OwnerId);
if (faction?.Tag != matchFaction)
continue;
}
if (matchName != null && matchName != antennaBlock.CustomName)
continue;
if (antennaBlock.Radius > result)
result = antennaBlock.Radius;
}
if (onlyAntenna)
return result;
foreach (var beacon in grid.Beacons) {
if (beacon.IsClosed() || !beacon.Working || !beacon.Functional)
continue;
var beaconBlock = beacon.Block as IMyBeacon;
if (beaconBlock == null)
continue;
if (!allowNpcSignals && matchFaction == null && FactionHelper.IsIdentityNPC(beaconBlock.OwnerId))
continue;
if (matchFaction != null) {
var faction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(beaconBlock.OwnerId);
if (faction?.Tag != matchFaction)
continue;
}
if (matchName != null && matchName != beaconBlock.CustomName)
continue;
if (beaconBlock.Radius > result)
result = beaconBlock.Radius;
}
return result;
}
public static bool GridPowered(List<GridEntity> grids) {
foreach (var grid in grids) {
if (GridPowered(grid))
return true;
}
return false;
}
public static bool GridPowered(GridEntity grid) {
return grid.IsPowered();
}
public static Vector2 GridPowerOutput(List<GridEntity> grids) {
var result = Vector2.Zero;
for (int i = grids.Count - 1; i >= 0; i--) {
var grid = GridManager.GetSafeGridFromIndex(i, grids);
if (grid != null)
result += GridPowerOutput(grid);
}
return result;
}
public static Vector2 GridPowerOutput(GridEntity grid) {
var result = Vector2.Zero;
if (grid.IsClosed())
return result;
foreach (var block in grid.Power) {
if (block.IsClosed() || !block.Working || !block.Functional)
continue;
var powerBlock = block.Block as IMyPowerProducer;
if (powerBlock == null)
continue;
result.X += powerBlock.CurrentOutput;
result.Y += powerBlock.MaxOutput;
}
return result;
}
public static bool GridShielded(List<GridEntity> grids) {
foreach (var grid in grids) {
if (GridShielded(grid))
return true;
}
return false;
}
public static bool GridShielded(GridEntity grid) {
if (grid.IsClosed())
return false;
if (EntityShielded(grid.CubeGrid))
return true;
foreach (var shield in grid.Shields) {
if (shield.IsClosed() || !shield.Working || !shield.Functional)
continue;
return true;
}
return false;
}
public static float GridTargetValue(List<GridEntity> gridList) {
float result = 0;
foreach (var grid in gridList) {
result += GridTargetValue(grid);
}
return result;
}
public static float GridTargetValue(GridEntity grid) {
var timespan = MyAPIGateway.Session.GameDateTime - grid.LastThreatCalculationTime;
if (timespan.TotalMilliseconds < 5000)
return grid.ThreatScore;
float result = 0;
if (grid.IsClosed() || grid.AllBlocks.Count <= 1)
return result;
result += GetTargetValueFromBlockList(grid.Antennas, 4, 2);
result += GetTargetValueFromBlockList(grid.Beacons, 3, 2);
result += GetTargetValueFromBlockList(grid.Containers, 0.5f, 2, true);
result += GetTargetValueFromBlockList(grid.Controllers, 0.5f, 2);
result += GetTargetValueFromBlockList(grid.Gravity, 2, 4, true);
result += GetTargetValueFromBlockList(grid.Guns, 5, 4, true);
result += GetTargetValueFromBlockList(grid.JumpDrives, 10, 2);
result += GetTargetValueFromBlockList(grid.Mechanical, 1, 2);
result += GetTargetValueFromBlockList(grid.Medical, 10, 2);
result += GetTargetValueFromBlockList(grid.NanoBots, 15, 2);
result += GetTargetValueFromBlockList(grid.Production, 2, 2, true);
result += GetTargetValueFromBlockList(grid.Power, 0.5f, 2, true);
result += GetTargetValueFromBlockList(grid.Shields, 15, 2);
result += GetTargetValueFromBlockList(grid.Thrusters, 1, 2);
result += GetTargetValueFromBlockList(grid.Tools, 2, 2, true);
result += GetTargetValueFromBlockList(grid.Turrets, 7.5f, 4, true);
//Factor Power
result += (grid.PowerOutput().Y > 0) ? (grid.PowerOutput().Y / 10) : 0;
//Factor Total Block Count
result += grid.AllBlocks.Count / 100;
//Factor Grid Box Size
result += (float)Vector3D.Distance(grid.CubeGrid.WorldAABB.Min, grid.CubeGrid.WorldAABB.Max) / 4;
//Factor Static/Dynamic
if (grid.CubeGrid.IsStatic)
result *= 0.75f;
//Factor Cube Size
if (grid.CubeGrid.GridSizeEnum == MyCubeSize.Large)
result *= 2.5f;
else
result *= 0.5f;
grid.ThreatScore = result * 0.70f;
grid.LastThreatCalculationTime = MyAPIGateway.Session.GameDateTime;
return grid.ThreatScore;
}
public static int GridPcuValue(List<GridEntity> gridList) {
int result = 0;
foreach (var grid in gridList) {
result += GridPcuValue(grid);
}
return result;
}
public static int GridPcuValue(GridEntity grid) {
var timespan = MyAPIGateway.Session.GameDateTime - grid.LastPcuCalculationTime;
if (timespan.TotalMilliseconds < 5000)
return grid.PcuScore;
int result = 0;
if (grid.IsClosed())
return result;
for (int i = grid.AllBlocks.Count - 1; i >= 0; i--) {
var block = grid.AllBlocks[i];
var def = block?.BlockDefinition as MyCubeBlockDefinition;
if (def == null)
continue;
result += def.PCU;
}
grid.PcuScore = result;
grid.LastPcuCalculationTime = MyAPIGateway.Session.GameDateTime;
return result;
}
public static float GetTargetValueFromBlockList(List<BlockEntity> blockList, float threatValue, float modMultiplier = 2, bool scanInventory = false) {
float result = 0;
foreach (var block in blockList) {
if (block.IsClosed() || !block.Functional)
continue;
var value = threatValue * (block.Modded ? modMultiplier : 1);
if (scanInventory) {
if (block.Block.HasInventory && block.Block.GetInventory().MaxVolume > 0) {
var inventoryModifier = ((float)block.Block.GetInventory().CurrentVolume / (float)block.Block.GetInventory().MaxVolume) + 1;
if (inventoryModifier != float.NaN)
value *= inventoryModifier;
}
}
result += value;
}
return result;
}
public static int GridMovementScore(List<GridEntity> grids) {
int result = 0;
foreach (var grid in grids) {
var score = GridVisibleMovementScore(grid);
if (score > result)
result = score;
}
return result;
}
public static int GridVisibleMovementScore(GridEntity grid) {
var speed = grid.CurrentSpeed();
if (speed < 1)
return 0;
return (int)(grid.BoundingBoxSize() * speed);
}
public static int GridWeaponCount(List<GridEntity> grids) {
int result = 0;
foreach (var grid in grids) {
result += GridWeaponCount(grid);
}
return result;
}
public static int GridWeaponCount(GridEntity grid) {
int result = 0;
foreach (var gun in grid.Guns) {
if (!gun.ActiveEntity())
continue;
result++;
}
foreach (var turret in grid.Turrets) {
if (!turret.ActiveEntity())
continue;
result++;
}
return result;
}
public static bool IsPlayerControlled(GridEntity cubeGrid) {
foreach (var controller in cubeGrid.Controllers) {
if (!controller.ActiveEntity())
continue;
IMyShipController shipController = controller.Block as IMyShipController;
if (shipController == null)
continue;
if (shipController.CanControlShip && shipController.IsUnderControl)
return true;
}
return false;
}
public static bool IsPositionNearEntity(Vector3D coords, double distance) {
foreach (var grid in GridManager.Grids) {
if (!grid.ActiveEntity())
continue;
if (grid.Distance(coords) < distance)
return true;
}
foreach (var player in PlayerManager.Players) {
if (!player.ActiveEntity())
continue;
if (player.Distance(coords) < distance)
return true;
}
return false;
}
public static Vector3D EntityAcceleration(IMyEntity entity) {
if (entity == null || entity.MarkedForClose || entity.Closed)
return Vector3D.Zero;
if (entity.Physics == null)
return Vector3D.Zero;
return entity.Physics.LinearAcceleration;
}
public static bool EntityShielded(IMyEntity entity) {
if (entity == null || entity.MarkedForClose || entity.Closed)
return false;
//Begin Defense Shield API Check
if (APIs.Shields.ProtectedByShield(entity))
return true;
//End Defense Shield API Check
return false;
}
public static double EntityMaxSpeed(IMyEntity entity) {
if (entity == null || entity.MarkedForClose || entity.Closed)
return 0;
if (entity as IMyCubeGrid != null) {
var grid = entity as IMyCubeGrid;
if (grid.GridSizeEnum == MyCubeSize.Large)
return MyDefinitionManager.Static.EnvironmentDefinition.LargeShipMaxSpeed;
}
return MyDefinitionManager.Static.EnvironmentDefinition.SmallShipMaxSpeed;
}
public static double EntitySpeed(IMyEntity entity) {
if (entity == null || entity.MarkedForClose || entity.Closed)
return -1;
if (entity.Physics == null)
return -1;
return entity.Physics.LinearVelocity.Length();
}
public static Vector3D EntityVelocity(IMyEntity entity) {
if (entity == null || entity.MarkedForClose || entity.Closed)
return Vector3D.Zero;
if (entity.Physics == null)
return Vector3D.Zero;
return entity.Physics.LinearVelocity;
}
}
}