public override void GridInitialising(IMyCubeGrid grid) { BlocksFixup(grid); if (grid.IsStatic && grid.IsControlledByFaction("GCORP")) { var slimBlocks = new List <IMySlimBlock>(); grid.GetBlocks(slimBlocks, b => b.FatBlock is IMyRemoteControl); foreach (var slim in slimBlocks) { var remoteControl = slim.FatBlock as IMyRemoteControl; if (remoteControl.IsControlledByFaction("GCORP") && remoteControl.CustomName.Contains("DELIVERY") // AIR_DELIVERY_SPAWNER // GROUND_DELIVERY_SPAWNER //Remote Control ) { var planet = DuckUtils.FindPlanetInGravity(remoteControl.GetPosition()); if (planet == null) { continue; // Space bases not yet supported. } bases.Add(new GCorpBase(remoteControl, ZeroDate, planet, heatSystem, audioSystem)); return; // Accepted grid, no need to keep looping } } } }
public override void GridInitialising(IMyCubeGrid grid) { if (!grid.IsControlledByFaction("GCORP")) { return; } // if (!bInitialInit) return; if (grid.IsStatic) { OfferPotentialDestination(grid); } else { OfferPotentialNpcShip(grid); } }
protected static bool AttemptDespawn(IMyCubeGrid grid, Int32 minplayerdistance = 1750) { if (!grid.IsControlledByFaction("GCORP")) { return(true); // If we are not GCorp don't try to despawn, we may be wreckage or player hijacked } // if player is 'near' base, then disabled drones near the base won't be despawned // if (!DuckUtils.IsAnyPlayerNearPosition(grid.GetPosition(), 1750)) // V26 if (!DuckUtils.IsAnyPlayerNearPosition(grid.GetPosition(), minplayerdistance)) { grid.CloseAll(); return(true); } return(false); }
private void OfferPotentialNpcShip(IMyCubeGrid grid) { // ModLog.Info("Potentential NPC:" + grid.CustomName); NpcGroupSaveData npcGroupSaveData; if (restoredNpcGroupData.TryGetValue(grid.EntityId, out npcGroupSaveData)) { // ModLog.Info(" Potentential NPC: Found in restored NPC Group data:" + npcGroupSaveData.NpcGroupType.ToString() + " Type="+ npcGroupSaveData.LeaderUnitType.ToString()); if (npcGroupSaveData.NpcGroupType == NpcGroupType.Backup) { npcGroups.Add(new BackupGroup(npcGroupSaveData.State, npcGroupSaveData.GroupDestination, grid, heatSystem, audioSystem, DateTime.FromBinary(npcGroupSaveData.SpawnTime))); } else // Must be convoy { if (modBuildWhenLastSaved > 30 || !bInitialInit) { restoredConvoys.Add(grid.EntityId, RegisterConvoy(grid, npcGroupSaveData.State, npcGroupSaveData.LeaderUnitType, npcGroupSaveData.GroupDestination, DateTime.FromBinary(npcGroupSaveData.SpawnTime))); } else { // else old drones with scripts that don't work on 1.193.100 if (grid.IsControlledByFaction("GCORP")) // see npcgroup.AttemptDespawn() { ModLog.Info("save build#:" + modBuildWhenLastSaved.ToString() + " Initial=" + bInitialInit.ToString()); ModLog.Info("Removing dead drone Grid:" + grid.CustomName); bOldRemovals = true; grid.CloseAll(); } } } } else { // ModLog.Info(" Potentential NPC: NOT in restored NPC Group data:" + grid.CustomName); if (modBuildWhenLastSaved > 30 || !bInitialInit) { possibleEscorts.Add(grid); } else { // Need better discernment to not delete placed G-Corp grids like G-Corp AP Turret and GCorp Experimental Mech if (grid.IsControlledByFaction("GCORP")) // see npcgroup.AttemptDespawn() { var slimBlocks = new List <IMySlimBlock>(); grid.GetBlocks(slimBlocks, b => b.FatBlock is IMyBeacon); foreach (var slim in slimBlocks) { var fb = slim.FatBlock as IMyBeacon; if (fb.CustomName.Contains(EscortName)) { ModLog.Info("Removing dead escort drone Grid:" + grid.CustomName); bOldRemovals = true; grid.CloseAll(); break; } } } } } }
internal override void Update() { if (!leader.IsControlledByFaction("GCORP")) { leader = null; GroupState = NpcGroupState.Disbanded; return; } // ModLog.Info("Backup:" + leader.EntityId.ToString() + " " + GroupState.ToString()); if ((GroupState == NpcGroupState.Travelling || GroupState == NpcGroupState.ReturningForRepairs) && Vector3D.DistanceSquared(Destination, leader.GetPosition()) < 40.0 * 40.0) { // it arrives at destination. and nothing... get rid of it. // ModLog.Info(" Backup arrived at base/target and nothing found. Disbanding"); GroupState = NpcGroupState.Disbanding; } if (GroupState == NpcGroupState.Disbanding) { var isArmed = leader.HasUsableGun(); if (AttemptDespawn(leader, 200)) //V26 { leader = null; GroupState = NpcGroupState.Disbanded; if (isArmed) { ArrivalObserver.GroupArrivedIntact(); } } return; } if (DuckUtils.IsAnyPlayerNearPosition(leader.GetPosition(), 2000) && //V29 1000->2000 Backups were getting disbanded when player between 1000 and max spawn distance. (GroupState == NpcGroupState.Travelling || GroupState == NpcGroupState.Disbanding)) { GroupState = NpcGroupState.InCombat; // ModLog.Info("Backup:" + leader.EntityId.ToString() + " Found Target:" + GroupState.ToString()); leader.SetLightingColors(Color.Red); leader.RemoveFromFirstBeaconName(ReturningToBase); leader.AppendToFirstBeaconName(InterceptingBeaconSuffix); audioSystem.PlayAudio(AudioClip.TargetFoundDronesAttack, AudioClip.TargetIdentifiedUnitsConverge); } // todo: if no player nearby go searching for player vehicles near base/convoy // todo: if can't target player after a delay (or player under cover?), search for player vehicles near current location if (GroupState == NpcGroupState.InCombat) { if (!leader.HasUsableGun()) { // GroupState = NpcGroupState.Disbanding; GroupState = NpcGroupState.ReturningForRepairs; //V29 // ModLog.Info("Backup:" + leader.EntityId.ToString() + " No Gun." + GroupState.ToString()); leader.SetLightingColors(GcorpBlue); leader.RemoveFromFirstBeaconName(" Investigating Backup Call"); // match text in NpcGroupManager leader.RemoveFromFirstBeaconName(InterceptingBeaconSuffix); leader.AppendToFirstBeaconName(ReturningToBase); leader.SendToPosition(Destination); audioSystem.PlayAudio(AudioClip.DroneDisarmed); // disbanding, but for backups we want to extra penalize for killing unit heat.BackupDisabled(); } else { var player = DuckUtils.GetNearestPlayerToPosition(leader.GetPosition(), 2000); //V29 1250->2000 if (player == null) { GroupState = NpcGroupState.Disbanding; // Return to normal, cowardly players have run off or died // ModLog.Info("Backup:" + leader.EntityId.ToString() + " No Players in range after Combat mode." + GroupState.ToString()); leader.SetLightingColors(GcorpBlue); leader.RemoveFromFirstBeaconName(InterceptingBeaconSuffix); leader.AppendToFirstBeaconName(ReturningToBase); leader.SendToPosition(Destination); audioSystem.PlayAudio(AudioClip.HostileDisappeared, AudioClip.TargetFleeingPursuit); } else { float heightModifier = 15; // Change from 2 pre V26 // Added V26 if (DuckUtils.IsPlayerUnderCover(player)) { heightModifier = 300; } leader.SendToPosition(player.GetPosition(), heightModifier); } } } }
internal override void Update() { CheckEscortsAlive(); if (!leader.IsControlledByFaction("GCORP")) { GroupState = NpcGroupState.Disbanding; InitiateDisbandProtocols(); } else if ((GroupState == NpcGroupState.Travelling || GroupState == NpcGroupState.InCombat) && Vector3D.DistanceSquared(Destination, leader.GetPosition()) < 300.0 * 300) // increase to 300 to allow for variations in height. V26 // && Vector3D.DistanceSquared(Destination, leader.GetPosition()) < 200.0*200) // increase to 200 to allow for variations in height. // && Vector3D.Distance(Destination, leader.GetPosition()) < 100.0) { string sBeacons = ""; var slimBlocks2 = new List <IMySlimBlock>(); leader.GetBlocks(slimBlocks2, b => b.FatBlock is IMyBeacon); foreach (var slim2 in slimBlocks2) { var beacon = slim2.FatBlock as IMyBeacon; sBeacons += beacon.CustomName; } ModLog.Info("Group Arrived at destination: " + leader.CustomName + " " + sBeacons); ArrivalObserver.GroupArrivedIntact(); audioSystem.PlayAudioRandomChance(0.1, AudioClip.ConvoyArrivedSafely); GroupState = NpcGroupState.Disbanding; InitiateDisbandProtocols(); ResetBeaconNames(); } // ModLogs are for DEBUG nav script // ModLog.Info("Convoy update:" + leader.CustomName+" ID:"+leader.EntityId.ToString() + " State:"+GroupState.ToString()); if ((GroupState == NpcGroupState.Travelling)) { var currentTime = MyAPIGateway.Session.GameDateTime; if (GroupSpawnTime + convoyInitiateTime < currentTime) { leader.SetAllBeaconNames(null, 20000f); } bool bKeenAutopilotActive = false; var slimBlocks = new List <IMySlimBlock>(); leader.GetBlocks(slimBlocks, b => b.FatBlock is IMyRemoteControl); IMyRemoteControl remoteControl = null; foreach (var slim in slimBlocks) { remoteControl = slim.FatBlock as IMyRemoteControl; bKeenAutopilotActive = remoteControl.IsAutoPilotEnabled; // ModLog.Info("Keen Autopilot:" + bKeenAutopilotActive.ToString()); break; } slimBlocks.Clear(); leader.GetBlocks(slimBlocks, b => b.FatBlock is IMyProgrammableBlock); foreach (var slim in slimBlocks) { var block = slim.FatBlock as IMyProgrammableBlock; if (block == null) { continue; } if (block.CustomName.Contains("NAV")) { if (!bKeenAutopilotActive && GroupSpawnTime + convoyInitiateTime < currentTime // delay check for mode change. ) { if (//!bKeenAutopilotActive && block.DetailedInfo.Contains("mode=0") || block.DetailedInfo.Contains("mode=-1")) { if (remoteControl == null) { // nothing left to do. Remove it (and try again) GroupState = NpcGroupState.Inactive; // this will cause NpcGroupManager to spawn a new convoy to replace this one. return; } // force it to use Keen Autopilot remoteControl.ClearWaypoints(); remoteControl.AddWaypoint(Destination, "Target"); remoteControl.SpeedLimit = 10; remoteControl.SetAutoPilotEnabled(true); /* * // debug output * var slimBlocks2 = new List<IMySlimBlock>(); * leader.GetBlocks(slimBlocks2, b => b.FatBlock is IMyBeacon); * string sBeacons = ""; * foreach(var slim2 in slimBlocks2) * { * var beacon = slim2.FatBlock as IMyBeacon; * sBeacons += beacon.CustomName; * } * * // it didn't get the command! * // GroupState = NpcGroupState.Inactive; // this will cause NpcGroupManager to spawn a new convoy to replace this one. * ModLog.Info("Autopilot recovery because leader NAV not in correct mode: "+ sBeacons); */ } break; } // ModLog.Info("PB:"+block.CustomName+"\n"+"DetailedInfo=:\n" + block.DetailedInfo); } } // Following is just debug info /* * leader.GetBlocks(slimBlocks, b => b.FatBlock is IMyGyro); * foreach (var slim in slimBlocks) * { * var block = slim.FatBlock as IMyGyro; * if (block!=null && block.CustomName.Contains("NAV")) * { * ModLog.Info("G:"+block.CustomName + "\n"); * } * } */ } if (GroupState == NpcGroupState.Disbanding) { AttemptDespawning(); return; } if (DuckUtils.IsAnyPlayerNearPosition(leader.GetPosition(), 1000) && GroupState == NpcGroupState.Travelling) { GroupState = NpcGroupState.InCombat; InitiateAttackProtocols(); } if (GroupState == NpcGroupState.InCombat) { var player = DuckUtils.GetNearestPlayerToPosition(leader.GetPosition(), 4000); if (player == null) { GroupState = NpcGroupState.Travelling; // Return to normal, cowardly players have run off or died ResetBeaconNames(); if (escortDic.Count > 0) //todo maybe check if the escorts are actually alive? Dunno if doing this already { audioSystem.PlayAudio(AudioClip.DisengagingFromHostile, AudioClip.TargetLost); } else { audioSystem.PlayAudio(AudioClip.PursuitEvaded, AudioClip.SensorsLostTrack); } } else { SendArmedEscortsNearPosition(player.GetPosition()); // Use same position as when escorting, to avoid collisions } } if (GroupState == NpcGroupState.Travelling) { foreach (var entry in escortDic) { SendEscortToGrid(entry.Key, entry.Value, leader); } } }