Ejemplo n.º 1
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);
        }
Ejemplo n.º 2
0
        private void SpawnHelperPatrol(IMyPlayer player)
        {
            var playerPos            = player.GetPosition();
            var playerNaturalGravity = marsPlanet.GetGravityAtPoint(playerPos);
            //TODO does perpendicularDistance maybe need to be normalised?
            // TODO: use faction info from faction definition.
            var perpendicularDistance = MyUtils.GetRandomPerpendicularVector(ref playerNaturalGravity) * 400; //4km away
            var locationToSpawnPatrol = playerPos + perpendicularDistance + playerNaturalGravity * -200f;     // 2km up
            var naturalGravityAtSpawn = marsPlanet.GetGravityAtPoint(locationToSpawnPatrol);

            var spawnLocation = MyAPIGateway.Entities.FindFreePlace(locationToSpawnPatrol, 10, 20, 5, 10);

            if (spawnLocation.HasValue)
            {
                PrefabGrid backup = faction.Ships.GetBackupShip();
                DuckUtils.SpawnInGravity(spawnLocation.Value, naturalGravityAtSpawn, RemoteControl.OwnerId,
                                         // TODO: use faction info from faction definition.
                                         backup.PrefabName, backup.InitialBeaconName);
            }
            else
            {
                ModLog.DebugError("Couldn't spawn backup!", locationToSpawnPatrol);
            }
        }
Ejemplo n.º 3
0
        private void GiveOrdersToUnassignedShips()
        {
            while (unitialisedNewGrids.Count > 0)
            {
                var grid = unitialisedNewGrids.Dequeue();
                if (!grid.IsControlledByNpcFaction())
                {
                    continue;
                }

                var roleAndUnitType = PrefabGrid.GetRoleAndUnitType(grid);
                if (roleAndUnitType == null)
                {
                    continue;
                }

                var unitType = roleAndUnitType.Value.UnitType;

                switch (roleAndUnitType.Value.UnitRole)
                {
                case UnitRole.Delivery:
                    var cargoType = CargoType.GenerateRandomCargo(random);
                    LoadCargo(grid, cargoType);
                    grid.SetAllBeaconNames("T" + random.Next(10000, 99999) + " - " + cargoType.GetDisplayName() + " Shipment",
                                           20000f);
                    var destination = unitType == UnitType.Air ? airConvoyDestinationPosition : groundConvoyDestinationPosition;
                    SetDestination(grid, destination);
                    RegisterConvoy(grid, NpcGroupState.Travelling, unitType, destination, MyAPIGateway.Session.GameDateTime);

                    var planet = DuckUtils.FindPlanetInGravity(grid.GetPosition());
                    if (planet != null)
                    {
                        CalFactions.Gcorp.Ships.SpawnConvoyEscorts(grid, unitType, planet);
                    }
                    break;

                case UnitRole.Escort:
                    var group = FindNearestJoinableNpcGroup(grid.GetPosition(), unitType);
                    if (group == null)
                    {
                        ModLog.Error("Escort ship spawned but can't find a group to join!");
                        grid.CloseAll();
                    }
                    else
                    {
                        grid.SetAllBeaconNames("E" + random.Next(10000, 99999) + " - Convoy Escort", 20000f);
                        var nearestPlanet = DuckUtils.FindPlanetInGravity(grid.GetPosition());
                        if (nearestPlanet != null)
                        {
                            group.JoinAsEscort(grid, unitType, nearestPlanet);
                        }
                    }
                    break;

                case UnitRole.Backup:
                    var gCorpBase = baseManager.FindBaseWantingBackup();
                    if (gCorpBase == null)
                    {
                        ModLog.Error("Backup ship spawned but can't find the base that asked for it!");
                        grid.CloseAll();
                        break;
                    }
                    var backupPosition = gCorpBase.GetBackupPosition();
                    grid.SendToPosition(backupPosition);
                    grid.SetAllBeaconNames("M" + random.Next(10000, 99999) + " Investigating Backup Call", 20000f);
                    var backupGroup = new BackupGroup(NpcGroupState.Travelling, backupPosition, grid,
                                                      heatSystem, audioSystem, MyAPIGateway.Session.GameDateTime);
                    //damageSensor.RegisterDamageObserver(grid.EntityId, backupGroup);
                    npcGroups.Add(backupGroup);
                    break;

                default:
                    continue;
                }
            }
        }
Ejemplo n.º 4
0
 public PathGridItem CreateInstance(PrefabGrid <PathGridItem> grid, GridLocation location)
 {
     return(Object.Instantiate(grid.Prefab, GridSpaceGlobalSpaceConverter.FromLocation(location, 0.45f),
                               Quaternion.identity));
 }