private void SpawnConvoy(IMyShipController baseToSpawnAt) { var factionId = baseToSpawnAt.OwnerId; var spawnerPosition = baseToSpawnAt.GetPosition(); var gravity = baseToSpawnAt.GetNaturalGravity(); var unitType = baseToSpawnAt.CustomName.Contains("GROUND") ? UnitType.Ground : UnitType.Air; var cargoSize = heatSystem.GenerateCargoShipSize(); //TODO: Should let base define the convoy spawn points //TODO: gravity is not normalized and is being used to scale the spawn point... It should be normalized and then meters used to modify. // NOTE: The .Forward IS normalized, so the scalar is in meters. if (unitType == UnitType.Air) { var positionToSpawn = spawnerPosition + gravity * -5f + baseToSpawnAt.WorldMatrix.Forward * 30; var transportPrefab = PrefabGrid.GetAirTransport(cargoSize); DuckUtils.SpawnInGravity(positionToSpawn, gravity, factionId, transportPrefab.PrefabName, transportPrefab.InitialBeaconName, Vector3D.Normalize(baseToSpawnAt.WorldMatrix.Forward)); } else { var positionToSpawn = spawnerPosition + gravity * -1f + baseToSpawnAt.WorldMatrix.Forward * 35; var transportPrefab = PrefabGrid.GetGroundTransport(cargoSize); DuckUtils.SpawnInGravity(positionToSpawn, gravity, factionId, transportPrefab.PrefabName, transportPrefab.InitialBeaconName, Vector3D.Normalize(baseToSpawnAt.WorldMatrix.Forward)); } }
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); }
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 } } }
private void SpawnUndergroundDefense(IMyPlayer player) { var playerPos = player.GetPosition(); var playerNaturalGravity = marsPlanet.GetGravityAtPoint(playerPos); var vng = playerNaturalGravity; vng.Normalize(); var surface = marsPlanet.GetClosestSurfacePointGlobal(player.GetPosition()); var belowsurface = Vector3D.Distance(playerPos, surface); // ModLog.Info("Below Surface=" + belowsurface.ToString("0.00")); var up = 50 + belowsurface; // 150m above the surface // var up = 150 + belowsurface; // 150m above the surface var locationToSpawn = playerPos + vng * -up; var naturalGravityAtSpawn = marsPlanet.GetGravityAtPoint(locationToSpawn); // DuckUtils.AddGpsToAllPlayers("Location to Spawn", "Above player", locationToSpawn); var spawnLocation = MyAPIGateway.Entities.FindFreePlace(locationToSpawn, 10, 20, 5, 10); if (spawnLocation.HasValue) { PrefabGrid bomb = PrefabGrid.GetBomb(); DuckUtils.SpawnInGravity(spawnLocation.Value, naturalGravityAtSpawn, RemoteControl.OwnerId, bomb.PrefabName, bomb.InitialBeaconName); //DEBUG // DuckUtils.AddGpsToAllPlayers("Bomb Spawn", "bomb for player", spawnLocation.Value); // ModLog.Info("Spawning Bomb!"); } else { ModLog.DebugError("Couldn't spawn bomb!", locationToSpawn); } }
private void SpawnHelperPatrol(IMyPlayer player) { var playerPos = player.GetPosition(); var playerNaturalGravity = marsPlanet.GetGravityAtPoint(playerPos); var perpendicularDistance = MyUtils.GetRandomPerpendicularVector(ref playerNaturalGravity) * 400; //4km away NOTE: since mars NG is not 1.0, it's NOT 4km var locationToSpawnPatrol = playerPos + perpendicularDistance + playerNaturalGravity * -200f; // 2km up var naturalGravityAtSpawn = marsPlanet.GetGravityAtPoint(locationToSpawnPatrol); var spawnLocation = MyAPIGateway.Entities.FindFreePlace(locationToSpawnPatrol, 10, 20, 5, 10); // ModLog.Info("Spawning helper patrol. perpD=" + perpendicularDistance.ToString("N2")); if (spawnLocation.HasValue) { PrefabGrid backup = PrefabGrid.GetBackup(heatSystem.GenerateBackupShipSize()); DuckUtils.SpawnInGravity(spawnLocation.Value, naturalGravityAtSpawn, RemoteControl.OwnerId, backup.PrefabName, backup.InitialBeaconName); } else { ModLog.DebugError("Couldn't spawn backup!", locationToSpawnPatrol); } }
private void GiveOrdersToUnassignedShips() { bool bFoundBackup = false; while (unitialisedNewGrids.Count > 0) { var grid = unitialisedNewGrids.Dequeue(); if (!grid.IsControlledByFaction("GCORP")) { continue; } var roleAndUnitType = PrefabGrid.GetRoleAndUnitType(grid); if (roleAndUnitType == null) { // V26 debug ModLog.Info("Discarding grid because no role found"); continue; } var unitType = roleAndUnitType.Value.UnitType; switch (roleAndUnitType.Value.UnitRole) { case UnitRole.Delivery: var cargoType = CargoType.GenerateRandomCargo(random); LoadCargo(grid, cargoType); if (cargoType.subtypeName == "SteelPlate") { audioSystem.PlayAudioRandomChance(0.1, AudioClip.SteelPlateConvoyDispatched, AudioClip.ConvoyDispatched1); } else if (cargoType.subtypeName == "MetalGrid") { audioSystem.PlayAudioRandomChance(1, AudioClip.MetalGridConvoyDispatched); } else if (cargoType.subtypeName == "Construction") { audioSystem.PlayAudioRandomChance(0.1, AudioClip.ConstructionConvoyDispatched); } else if (cargoType.subtypeName == "InteriorPlate") { audioSystem.PlayAudioRandomChance(0.1, AudioClip.InteriorPlateConvoyDispatched); } else if (cargoType.subtypeName == "Girder") { audioSystem.PlayAudioRandomChance(0.1, AudioClip.GirderConvoyDispatched); } else if (cargoType.subtypeName == "SmallTube") { audioSystem.PlayAudioRandomChance(0.1, AudioClip.SmallTubeConvoyDispatched); } else if (cargoType.subtypeName == "LargeTube") { audioSystem.PlayAudioRandomChance(0.2, AudioClip.LargeTubeConvoyDispatched); } else if (cargoType.subtypeName == "Motor") { audioSystem.PlayAudioRandomChance(0.75, AudioClip.MotorConvoyDispatched); } else if (cargoType.subtypeName == "Display") { audioSystem.PlayAudioRandomChance(0.2, AudioClip.DisplayConvoyDispatched); } else if (cargoType.subtypeName == "BulletproofGlass") { audioSystem.PlayAudioRandomChance(0.3, AudioClip.BulletproofGlassConvoyDispatched); } else if (cargoType.subtypeName == "Computer") { audioSystem.PlayAudioRandomChance(0.2, AudioClip.ComputerConvoyDispatched); } else if (cargoType.subtypeName == "Reactor") { audioSystem.PlayAudioRandomChance(0.75, AudioClip.ReactorConvoyDispatched); } else if (cargoType.subtypeName == "Medical") { audioSystem.PlayAudioRandomChance(0.7, AudioClip.MedicalConvoyDispatched); } else if (cargoType.subtypeName == "RadioCommunication") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.RadioCommunicationConvoyDispatched); } else if (cargoType.subtypeName == "Explosives") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.ExplosivesConvoyDispatched); } else if (cargoType.subtypeName == "SolarCell") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.SolarCellConvoyDispatched); } else if (cargoType.subtypeName == "PowerCell") { audioSystem.PlayAudioRandomChance(0.75, AudioClip.PowerCellConvoyDispatched); } else if (cargoType.subtypeName == "NATO_5p56x45mm") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.NATO_5p56x45mmConvoyDispatched); } else if (cargoType.subtypeName == "NATO_25x184mm") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.NATO25x184mmConvoyDispatched); } else if (cargoType.subtypeName == "Missile200mm") { audioSystem.PlayAudioRandomChance(0.5, AudioClip.Missile200mmConvoyDispatched); } else if (cargoType.subtypeName == "Uranium") { audioSystem.PlayAudioRandomChance(1, AudioClip.UraniumConvoyDispatched); } else // we don't know what it is.. { audioSystem.PlayAudioRandomChance(0.1, AudioClip.ConvoyDispatched1, AudioClip.ConvoyDispatched2, AudioClip.ConvoyDispatched3); } string sPrefix = "T"; if (unitType == UnitType.Air) { sPrefix += "A"; } else { sPrefix += "G"; } grid.SetAllBeaconNames(sPrefix + random.Next(10000, 99999) + " - " + cargoType.GetDisplayName() + " Shipment", 200f); // V31 set short until initialize check timeout var destination = unitType == UnitType.Air ? airConvoyDestinationPosition : groundConvoyDestinationPosition; // ModLog.Info("Air Destination=" + airConvoyDestinationPosition.ToString()); // ModLog.Info("GND Destination=" + groundConvoyDestinationPosition.ToString()); // ModLog.Info("Chosen Dest=" + destination.ToString()); SetDestination(grid, destination); RegisterConvoy(grid, NpcGroupState.Travelling, unitType, destination, MyAPIGateway.Session.GameDateTime); var planet = DuckUtils.FindPlanetInGravity(grid.GetPosition()); if (planet != null) { convoySpawner.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) + " - " + EscortName, 2500f); // V31 shorten escort beacon range to decrease hud spam var nearestPlanet = DuckUtils.FindPlanetInGravity(grid.GetPosition()); if (nearestPlanet != null) { group.JoinAsEscort(grid, unitType, nearestPlanet); } } break; case UnitRole.Backup: var gCorpBase = baseManager.FindBaseWantingBackup(); // V26 bFoundBackup = true; if (gCorpBase == null) { gCorpBase = baseManager.FindBaseNear(grid.GetPosition()); } 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); // backup debug string sBeacon = "M" + random.Next(10000, 99999) + " Investigating Backup Call"; // ModLog.Info("Backup Found:" + sBeacon); // ModLog.Info(" Destination=" + backupPosition.ToString()); grid.SetAllBeaconNames(sBeacon, 20000f); var backupGroup = new BackupGroup(NpcGroupState.Travelling, backupPosition, grid, heatSystem, audioSystem, MyAPIGateway.Session.GameDateTime); //damageSensor.RegisterDamageObserver(grid.EntityId, backupGroup); npcGroups.Add(backupGroup); break; case UnitRole.Bomb: bool hasSensors = false; var slimBlocks = new List <IMySlimBlock>(); grid.GetBlocks(slimBlocks, b => b.FatBlock is IMySensorBlock); if (slimBlocks.Count > 0) { hasSensors = true; } grid.GetBlocks(slimBlocks, b => b.FatBlock is IMyWarhead); foreach (var slim in slimBlocks) { var wh = slim.FatBlock as IMyWarhead; wh.IsArmed = true; if (!hasSensors) // if no sensors, start the countdown { ModLog.Info("BOMB: no sensors: Starting timer"); wh.StartCountdown(); } } break; default: continue; } } if (bFoundBackup) { baseManager.ClearBaseBackupRequests(); } }