示例#1
0
        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);
                    }
                }
            }
        }
示例#2
0
        internal override void Update()
        {
            if (!leader.IsControlledByNpcFaction())
            {
                leader     = null;
                GroupState = NpcGroupState.Disbanded;
                return;
            }

            if (GroupState == NpcGroupState.Travelling && Vector3D.Distance(Destination, leader.GetPosition()) < 40.0)
            {
                GroupState = NpcGroupState.Disbanding;
            }

            if (GroupState == NpcGroupState.Disbanding)
            {
                var isArmed = leader.HasUsableGun();
                if (AttemptDespawn(leader))
                {
                    leader     = null;
                    GroupState = NpcGroupState.Disbanded;
                    if (isArmed)
                    {
                        ArrivalObserver.GroupArrivedIntact();
                    }
                }
                return;
            }

            if (DuckUtils.IsAnyPlayerNearPosition(leader.GetPosition(), 1000) &&
                (GroupState == NpcGroupState.Travelling || GroupState == NpcGroupState.Disbanding))
            {
                GroupState = NpcGroupState.InCombat;
                leader.SetLightingColors(Color.Red);
                leader.RemoveFromFirstBeaconName(ReturningToBase);
                leader.AppendToFirstBeaconName(InterceptingBeaconSuffix);
                audioSystem.PlayAudio(CalAudioClip.TargetFoundDronesAttack, CalAudioClip.TargetIdentifiedUnitsConverge);
            }

            if (GroupState == NpcGroupState.InCombat)
            {
                if (!leader.HasUsableGun())
                {
                    GroupState = NpcGroupState.Disbanding;
                    leader.SendToPosition(Destination);
                    audioSystem.PlayAudio(CalAudioClip.DroneDisarmed);
                }
                else
                {
                    var player = DuckUtils.GetNearestPlayerToPosition(leader.GetPosition(), 1250);
                    if (player == null)
                    {
                        GroupState = NpcGroupState.Disbanding;                         // Return to normal, cowardly players have run off or died
                        // TODO: get lighting per-faction
                        leader.SetLightingColors(GcorpBlue);
                        leader.RemoveFromFirstBeaconName(InterceptingBeaconSuffix);
                        leader.AppendToFirstBeaconName(ReturningToBase);
                        leader.SendToPosition(Destination);
                        audioSystem.PlayAudio(CalAudioClip.HostileDisappeared, CalAudioClip.TargetFleeingPursuit);
                    }
                    else
                    {
                        leader.SendToPosition(player.GetPosition(), 2);
                    }
                }
            }
        }
示例#3
0
        internal override void Update()
        {
            CheckEscortsAlive();

            if (!leader.IsControlledByNpcFaction())
            {
                GroupState = NpcGroupState.Disbanding;
                InitiateDisbandProtocols();
            }
            else if ((GroupState == NpcGroupState.Travelling || GroupState == NpcGroupState.InCombat) &&
                     Vector3D.DistanceSquared(Destination, leader.GetPosition()) < 200.0 * 200)    // increase to 200 to allow for variations in height.
            //                     && Vector3D.Distance(Destination, leader.GetPosition()) < 100.0)
            {
                ArrivalObserver.GroupArrivedIntact();
                audioSystem.PlayAudioRandomChance(0.1, CalAudioClip.ConvoyArrivedSafely);
                GroupState = NpcGroupState.Disbanding;
                InitiateDisbandProtocols();
                ResetBeaconNames();
            }

            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(CalAudioClip.DisengagingFromHostile, CalAudioClip.TargetLost);
                    }
                    else
                    {
                        audioSystem.PlayAudio(CalAudioClip.PursuitEvaded, CalAudioClip.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);
                }
            }
        }
示例#4
0
        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);
                }
            }
        }