Beispiel #1
0
        public static FactionRelationship GetRelationBetweenGridAndCharacter(IMyCubeGrid npcGrid, IMyCharacter character)
        {
            long       npcGridOwner = npcGrid.BigOwners.FirstOrDefault();
            IMyFaction npcFaction   = MyAPIGateway.Session.Factions.TryGetPlayerFaction(npcGridOwner);

            return(MyAPIGateway.Session.Factions.GetReputationBetweenPlayerAndFaction(character.EntityId, npcFaction.FactionId) >= -500 ? FactionRelationship.Friends : FactionRelationship.Enemies);
        }
Beispiel #2
0
        public static ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group> FindGridGroup(string gridName)
        {
            int i = 0;

            ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group> groups = new ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group>();

            Parallel.ForEach(MyCubeGridGroups.Static.Physical.Groups, group => {
                foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in group.Nodes)
                {
                    IMyCubeGrid grid = groupNodes.NodeData;

                    if (grid.Physics == null)
                    {
                        continue;
                    }

                    /* Gridname is wrong ignore */
                    if (!grid.CustomName.Equals(gridName))
                    {
                        i++;
                        continue;
                    }

                    groups.Add(group);
                }
            });
            if (i >= 1)
            {
            }
            return(groups);
        }
Beispiel #3
0
        public override void UpdateAfterSimulation10()
        {
            try {
                if (projector == null || !projector.Enabled || !projector.IsWorking || !projector.IsFunctional)
                {
                    return;
                }
                var projectorgrid = projector.GetTopMostParent();
                VRage.Game.ModAPI.IMyCubeGrid grid = (projectorgrid as VRage.Game.ModAPI.IMyCubeGrid);
                if (projectorgrid.Physics.LinearVelocity.Length() > 1)
                {
                    List <VRage.Game.ModAPI.IMySlimBlock> blocks = new List <VRage.Game.ModAPI.IMySlimBlock> ();
                    grid.GetBlocks(blocks, b => b != null && b.FatBlock != null && (b.FatBlock as IMyProjector) != null && b.FatBlock.IsWorking && b.FatBlock.IsFunctional &&
                                   b.FatBlock.BlockDefinition.ToString().Contains("MyObjectBuilder_Projector"));

                    foreach (VRage.Game.ModAPI.IMySlimBlock b in blocks)
                    {
                        if ((b.FatBlock as IMyProjector).Enabled)
                        {
                            (b.FatBlock as IMyProjector).RequestEnable(false);
                        }
                        var damage = grid.GridSizeEnum.Equals(MyCubeSize.Large) ? 15.5 f : 0.05 f;
                        b.DecreaseMountLevel(damage, null, true);
                        b.ApplyAccumulatedDamage();
                        MyAPIGateway.Utilities.ShowMessage(grid.CustomName, "projector failed because of high velocity!");
                    }
                }
            } catch (Exception e) {
            }
        }
Beispiel #4
0
        public static ConcurrentBag <MyGroups <MyCubeGrid, MyGridMechanicalGroupData> .Group> FindGridGroupMechanical(string gridName)
        {
            try {
                ConcurrentBag <MyGroups <MyCubeGrid, MyGridMechanicalGroupData> .Group> groups = new ConcurrentBag <MyGroups <MyCubeGrid, MyGridMechanicalGroupData> .Group>();
                Parallel.ForEach(MyCubeGridGroups.Static.Mechanical.Groups, group => {
                    foreach (MyGroups <MyCubeGrid, MyGridMechanicalGroupData> .Node groupNodes in group.Nodes)
                    {
                        IMyCubeGrid grid = groupNodes.NodeData;

                        if (grid.Physics == null)
                        {
                            continue;
                        }

                        /* Gridname is wrong ignore */
                        if (!grid.CustomName.Equals(gridName))
                        {
                            continue;
                        }

                        groups.Add(group);
                    }
                });

                return(groups);
            } catch (Exception e) {
                Log.Fatal("Error at GridFinder: " + e.ToString());
                return(null);
            }
        }
Beispiel #5
0
        private void SpawnEscortGrid(PrefabGrid prefabGrid, Vector3D naturalGravity, EscortPosition escortPosition,
                                     UnitType convoyUnitType, IMyCubeGrid convoyLeaderGrid)
        {
            var positionToSpawn = Convoy.GetEscortPositionVector(convoyLeaderGrid, naturalGravity, escortPosition,
                                                                 GetAdditionalHeightModifier(convoyUnitType));
            var factionId = convoyLeaderGrid.GetGridControllerFaction();
            var forwards  = convoyLeaderGrid.WorldMatrix.Forward;

            DuckUtils.SpawnInGravity(positionToSpawn, naturalGravity, factionId, prefabGrid.PrefabName,
                                     prefabGrid.InitialBeaconName, forwards);
        }
Beispiel #6
0
        public static FactionRelationship GetRelationBetweenGrids(IMyCubeGrid npcGrid, IMyCubeGrid otherGrid)
        {
            long npcGridOwner   = npcGrid.BigOwners.FirstOrDefault();
            long otherGridOwner = otherGrid.BigOwners.FirstOrDefault();

            if (npcGridOwner == 0 || otherGridOwner == 0)
            {
                return(FactionRelationship.Enemies);
            }
            IMyFaction npcFaction = MyAPIGateway.Session.Factions.TryGetPlayerFaction(npcGridOwner);

            return(MyAPIGateway.Session.Factions.GetReputationBetweenPlayerAndFaction(otherGridOwner, npcFaction.FactionId) >= -500 ? FactionRelationship.Friends : FactionRelationship.Enemies);
        }
Beispiel #7
0
        internal void SpawnConvoyEscorts(IMyCubeGrid convoyLeaderGrid, UnitType unitType, MyPlanet marsPlanet)
        {
            var gravity = marsPlanet.GetGravityAtPoint(convoyLeaderGrid.GetPosition());
            var escortsNeededToSpawn = heatSystem.GenerateEscortSpecs();

            if (unitType == UnitType.Air)
            {
                SpawnAirEscorts(escortsNeededToSpawn, gravity, convoyLeaderGrid);
            }
            else
            {
                SpawnLandEscorts(escortsNeededToSpawn, gravity, convoyLeaderGrid);
                SpawnAirEscorts(escortsNeededToSpawn, gravity, convoyLeaderGrid);
            }
        }
Beispiel #8
0
        public override void GridInitialising(IMyCubeGrid grid)
        {
            if (!grid.IsStatic)
            {
                return;
            }

            foreach (var remoteControl in grid.GetTerminalBlocksOfType <IMyRemoteControl>())
            {
                if (remoteControl.IsControlledByFaction("GCORP") &&
                    remoteControl.CustomName.Contains(DeliverySpawnerPrefix))                 // Finds both ground and air spawners
                {
                    spawningBases.Add(remoteControl);
                }
            }
        }
        public override void GridInitialising(IMyCubeGrid grid)
        {
            if (!grid.IsStatic)
            {
                return;
            }

            foreach (var remoteControl in grid.GetTerminalBlocksOfType <IMyRemoteControl>())
            {
                // TODO: need another method to determine ownership (or just ignore it)
                if (                                                          /*remoteControl.IsControlledByFaction("GCORP") && */
                    remoteControl.CustomName.Contains(DeliverySpawnerPrefix)) // Finds both ground and air spawners
                {
                    spawningBases.Add(remoteControl);
                }
            }
        }
Beispiel #10
0
        private void SpawnEscorts(ICollection <ShipSize> escortsNeededToSpawn, Vector3D gravity,
                                  IList <EscortPosition> allowedPositions, UnitType unitType, IMyCubeGrid convoyLeaderGrid)
        {
            var positionIndex = 0;

            foreach (var escort in escortsNeededToSpawn.Reverse())
            {
                SpawnEscortGrid(PrefabGrid.GetEscort(unitType, escort), gravity,
                                allowedPositions[positionIndex], unitType, convoyLeaderGrid);
                positionIndex++;
                escortsNeededToSpawn.Remove(escort);
                if (positionIndex == allowedPositions.Count)
                {
                    break;                     // Can't spawn any more of this type, all positions full
                }
            }
        }
Beispiel #11
0
 private void SpawnAirEscorts(ICollection <ShipSize> escortsNeededToSpawn, Vector3D gravity,
                              IMyCubeGrid convoyLeaderGrid)
 {
     SpawnEscorts(escortsNeededToSpawn, gravity, Convoy.AirEscortPositions, UnitType.Air, convoyLeaderGrid);
 }
Beispiel #12
0
        public static ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group> FindLookAtGridGroup(IMyCharacter controlledEntity)
        {
            const float range = 5000;
            Matrix      worldMatrix;
            Vector3D    startPosition;
            Vector3D    endPosition;

            worldMatrix   = controlledEntity.GetHeadMatrix(true, true, false); // dead center of player cross hairs, or the direction the player is looking with ALT.
            startPosition = worldMatrix.Translation + worldMatrix.Forward * 0.5f;
            endPosition   = worldMatrix.Translation + worldMatrix.Forward * (range + 0.5f);

            var list = new Dictionary <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group, double>();
            var ray  = new RayD(startPosition, worldMatrix.Forward);

            foreach (var group in MyCubeGridGroups.Static.Physical.Groups)
            {
                foreach (MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Node groupNodes in group.Nodes)
                {
                    IMyCubeGrid cubeGrid = groupNodes.NodeData;

                    if (cubeGrid != null)
                    {
                        if (cubeGrid.Physics == null)
                        {
                            continue;
                        }

                        // check if the ray comes anywhere near the Grid before continuing.
                        if (ray.Intersects(cubeGrid.WorldAABB).HasValue)
                        {
                            Vector3I?hit = cubeGrid.RayCastBlocks(startPosition, endPosition);

                            if (hit.HasValue)
                            {
                                double distance = (startPosition - cubeGrid.GridIntegerToWorld(hit.Value)).Length();


                                if (list.TryGetValue(group, out double oldDistance))
                                {
                                    if (distance < oldDistance)
                                    {
                                        list.Remove(group);
                                        list.Add(group, distance);
                                    }
                                }
                                else
                                {
                                    list.Add(group, distance);
                                }
                            }
                        }
                    }
                }
            }

            ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group> bag = new ConcurrentBag <MyGroups <MyCubeGrid, MyGridPhysicalGroupData> .Group>();

            if (list.Count == 0)
            {
                return(bag);
            }

            // find the closest Entity.
            var item = list.OrderBy(f => f.Value).First();

            bag.Add(item.Key);

            return(bag);
        }