Esempio n. 1
0
        void Aggregator4Destroyed()
        {
            MySmallShipBot marcus = (MySmallShipBot)MyScriptWrapper.GetEntity("Marcus");

            MyScriptWrapper.Move(marcus, MyScriptWrapper.GetEntity((uint)EntityID.DummyNearPrefabAutodestruct4).GetPosition());
            MyScriptWrapper.ActivateSpawnPoint((uint)EntityID.SpawnAutodestruct);
        }
        internal override void Init(MySmallShipBot bot)
        {
            base.Init(bot);

            leaderVisible = true;
            visibilityCheckTimer = 0;
        }
        internal override void Update(MySmallShipBot bot)
        {
            base.Update(bot);

            MyEntity enemy = bot.GetEnemy();
            MyDrillBase drill = bot.Weapons.GetMountedDrill();

            if (enemy != null && drill != null)
            {
                Vector3 botToEnemy = enemy.GetPosition() - bot.GetPosition();
                float distance = botToEnemy.Length();
                if (distance <= (bot.DrillDistance + bot.WorldVolume.Radius + enemy.WorldVolume.Radius))
                {
                    if (drill.CurrentState == MyDrillStateEnum.InsideShip)
                    {
                        drill.Eject();
                    }
                    else
                    {
                        drill.Shot(null);
                    }
                }
                else
                {
                    // pull drill back
                    if (drill.CurrentState == MyDrillStateEnum.Activated)
                    {
                        drill.Eject();
                    }
                }

                bot.Move(enemy.GetPosition(), enemy.GetPosition(), enemy.WorldMatrix.Up, distance < 100);
            }
        }
Esempio n. 4
0
        void O10FindBombDealerLoaded(MyMissionBase sender)
        {
            m_manjeet.LookTarget = null;
            MyScriptWrapper.ApplyTransition(MyMusicTransitionEnum.Special, 1, "MM01");
            MyScriptWrapper.SetSleepDistance(m_marcus, 5000);
            MyScriptWrapper.StopFollow(m_marcus);
            m_marcus.SetWaypointPath("MarcusOut");
            m_marcus.SpeedModifier = 2.0f;
            MyScriptWrapper.AddNotification(MyScriptWrapper.CreateNotification(MyTextsWrapperEnum.MarcusIsLeavingForTarja, MyGuiManager.GetFontMinerWarsGreen(), 5000));
            m_marcus.PatrolMode = MyPatrolMode.ONE_WAY;
            m_marcus.Patrol();

            m_valentin = (MySmallShipBot)MyScriptWrapper.GetEntity("RavenGuy");
            m_valentin.LeaderLostEnabled = true;
            MyScriptWrapper.MarkEntity(m_valentin, MyTextsWrapper.Get(MyActorConstants.GetActorDisplayName(MyActorEnum.VALENTIN)).ToString(), HUD.MyHudIndicatorFlagsEnum.SHOW_DISTANCE | HUD.MyHudIndicatorFlagsEnum.SHOW_ONLY_IF_DETECTED_BY_RADAR | HUD.MyHudIndicatorFlagsEnum.SHOW_TEXT | HUD.MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS, HUD.MyGuitargetMode.Friend);
            MyScriptWrapper.StopFollow(m_valentin);
            MyEntity valentinPosition = MyScriptWrapper.GetEntity((uint)EntityID.ValentinBRPosition);

            m_valentin.SetWorldMatrix(valentinPosition.WorldMatrix);

            m_tarja.LeaderLostEnabled = true;
            MyScriptWrapper.StopFollow(m_tarja);
            MyScriptWrapper.MarkEntity(m_tarja, MyTextsWrapper.Get(MyActorConstants.GetActorDisplayName(MyActorEnum.TARJA)).ToString(), HUD.MyHudIndicatorFlagsEnum.SHOW_DISTANCE | HUD.MyHudIndicatorFlagsEnum.SHOW_ONLY_IF_DETECTED_BY_RADAR | HUD.MyHudIndicatorFlagsEnum.SHOW_TEXT | HUD.MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS, HUD.MyGuitargetMode.Friend);
            MyEntity tarjaPosition = MyScriptWrapper.GetEntity((uint)EntityID.TarjaBRPosition);

            m_tarja.SetWorldMatrix(tarjaPosition.WorldMatrix);
            MyScriptWrapper.SetEntityDisplayName(m_tarja, MyTextsWrapper.Get(MyTextsWrapperEnum.Actor_Tarja).ToString());

            MyScriptWrapper.UnhideEntity(MyScriptWrapper.GetEntity((uint)EntityID.BombDealer));
        }
Esempio n. 5
0
        public void Unregister(MySmallShipBot entity)
        {
            System.Diagnostics.Debug.Assert(entity == null || !entity.Closed);

            entity.OnPositionChanged -= OnPositionChangedHandler;
            m_dangerZoneStructure.RemoveProxy(entity.GetDangerZoneID());
        }
Esempio n. 6
0
        void O03FlyToStartLoaded(MyMissionBase sender)
        {
            MyScriptWrapper.OnBotReachedWaypoint += Script_BotReachedWaypoint;

            m_detector_ReachStart.OnEntityEnter += StartPositionEntered;
            m_detector_ReachStart.OnEntityLeave += StartPositionLeaved;
            m_detector_ReachStart.On();

            MyScriptWrapper.ActivateSpawnPoint((uint)EntityID.Racer2);
            MyScriptWrapper.ActivateSpawnPoint((uint)EntityID.Racer3);
            MyScriptWrapper.MarkEntity(MyScriptWrapper.GetEntity((uint)EntityID.DetectorStartRacePosition), MyTexts.FlyToStartingPoint, HUD.MyHudIndicatorFlagsEnum.SHOW_TEXT | HUD.MyHudIndicatorFlagsEnum.SHOW_DISTANCE | HUD.MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS);

            m_manjeet.LookTarget = null;
            m_manjeet.SetWaypointPath("SmugglerOut");
            m_manjeet.PatrolMode = CommonLIB.AppCode.ObjectBuilders.Object3D.MyPatrolMode.ONE_WAY;
            m_manjeet.Patrol();
            MyScriptWrapper.SetSleepDistance(m_manjeet, 3000);

            MySmallShipBot challenger = (MySmallShipBot)MyScriptWrapper.GetEntity("Challenger");

            challenger.SetWaypointPath("Gotostart");
            challenger.PatrolMode = CommonLIB.AppCode.ObjectBuilders.Object3D.MyPatrolMode.ONE_WAY;
            challenger.Patrol();

            MyScriptWrapper.SetSleepDistance(challenger, 20000);

            MyScriptWrapper.SetEntitiesEnabled(m_influenceSpheresFansBeforeStart, true);
        }
        internal override void Init(MySmallShipBot bot)
        {
            base.Init(bot);

            baseMatrix = bot.WorldMatrix;
            lookTarget = bot.GetPosition() + baseMatrix.Forward * 100;
        }
        internal override void Update(MySmallShipBot bot)
        {
            base.Update(bot);

            MyEntity    enemy = bot.GetEnemy();
            MyDrillBase drill = bot.Weapons.GetMountedDrill();

            if (enemy != null && drill != null)
            {
                Vector3 botToEnemy = enemy.GetPosition() - bot.GetPosition();
                float   distance   = botToEnemy.Length();
                if (distance <= (bot.DrillDistance + bot.WorldVolume.Radius + enemy.WorldVolume.Radius))
                {
                    if (drill.CurrentState == MyDrillStateEnum.InsideShip)
                    {
                        drill.Eject();
                    }
                    else
                    {
                        drill.Shot(null);
                    }
                }
                else
                {
                    // pull drill back
                    if (drill.CurrentState == MyDrillStateEnum.Activated)
                    {
                        drill.Eject();
                    }
                }

                bot.Move(enemy.GetPosition(), enemy.GetPosition(), enemy.WorldMatrix.Up, distance < 100);
            }
        }
Esempio n. 9
0
        void O12BRFightLoaded(MyMissionBase sender)
        {
            m_valentin = (MySmallShipBot)MyScriptWrapper.GetEntity("RavenGuy");
            MyScriptWrapper.ApplyTransition(MyMusicTransitionEnum.HeavyFight, 3, "KA03");
            MyScriptWrapper.Follow(MySession.PlayerShip, m_marcus);
            MyScriptWrapper.Follow(MySession.PlayerShip, m_tarja);
            MyScriptWrapper.Follow(MySession.PlayerShip, m_valentin);
            m_marcus.SpeedModifier = 1.0f;

            MyScriptWrapper.ChangeFaction((uint)EntityID.BR_SP_Boss, MyMwcObjectBuilder_FactionEnum.Slavers);
            foreach (var bot in MyScriptWrapper.GetSpawnPointBots((uint)EntityID.BR_SP_Boss))
            {
                if (bot.Ship != null)
                {
                    MyScriptWrapper.SetEntityDestructible(bot.Ship, true);
                    MyScriptWrapper.ChangeFaction(bot.Ship, MyMwcObjectBuilder_FactionEnum.Slavers);
                }
            }

            foreach (var spawn in m_spawns)
            {
                MyScriptWrapper.ChangeFaction(spawn, MyMwcObjectBuilder_FactionEnum.Slavers);
                foreach (var bot in MyScriptWrapper.GetSpawnPointBots(spawn))
                {
                    if (bot.Ship != null)
                    {
                        MyScriptWrapper.SetEntityDestructible(bot.Ship, true);
                        MyScriptWrapper.ChangeFaction(bot.Ship, MyMwcObjectBuilder_FactionEnum.Slavers);
                    }
                }
            }
        }
Esempio n. 10
0
 void UpdateGoals(MySmallShipBot bot)
 {
     moveTarget = bot.GetPosition() + MyMwcUtils.GetRandomVector3Normalized() * 1000;
     lookTarget = bot.GetPosition() + MyMwcUtils.GetRandomVector3Normalized() * 1000;
     up = MyMwcUtils.GetRandomVector3Normalized() * 1000;
     shoot = MyMwcUtils.GetRandomBool(2);
 }
Esempio n. 11
0
        public void Unregister(MySmallShipBot entity)
        {
            System.Diagnostics.Debug.Assert(entity == null || !entity.Closed);

            entity.OnPositionChanged -= OnPositionChangedHandler;
            m_dangerZoneStructure.RemoveProxy(entity.GetDangerZoneID());
        }
        private void FollowToRoutePosition(MySmallShipBot bot)
        {
            // Fly to visible position, if too close look for new visible position
            if (Vector3.DistanceSquared(m_followPosition.Value, bot.GetPosition()) < 5 * 5)
            {
                m_followPosition = null;
            }
            else
            {
                bot.Move(m_followPosition.Value, m_followPosition.Value, bot.WorldMatrix.Up, false, 1, 2);

                if (m_stuckTimer > STUCK_TIME)
                {
                    if (Vector3.DistanceSquared(bot.GetPosition(), m_stuckPosition) > STUCK_DISTANCE)
                    {
                        m_followPosition = null;
                    }
                    else
                    {
                        m_followPosition = m_stuckPosition + MyMwcUtils.GetRandomVector3Normalized() * 1000;
                    }
                }
                else if (Vector3.DistanceSquared(bot.GetPosition(), m_stuckPosition) > STUCK_DISTANCE)
                {
                    ResetStuck(bot);
                }
                else
                {
                    m_stuckTimer += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                }
            }
        }
        public override void Load()
        {
            base.Load();

            MyScriptWrapper.AlarmLaunched += MyScriptWrapper_AlarmLaunched;

            // Turn off sunwind, meteorwind and icestorm
            MyScriptWrapper.EnableGlobalEvent(World.Global.MyGlobalEventEnum.SunWind, false);
            MyScriptWrapper.EnableGlobalEvent(World.Global.MyGlobalEventEnum.MeteorWind, false);
            MyScriptWrapper.EnableGlobalEvent(World.Global.MyGlobalEventEnum.IceStorm, false);

            // Add Fourth Reich FalseId to inventory if player already haven't got one
            MyScriptWrapper.AddFalseIdToPlayersInventory(MyMwcObjectBuilder_FactionEnum.FourthReich);

            // Add Radar Jammer to player inventory
            MyScriptWrapper.AddInventoryItem(MyScriptWrapper.GetPlayerInventory(), MyMwcObjectBuilderTypeEnum.SmallShip_Tool, (int)MyMwcObjectBuilder_SmallShip_Tool_TypesEnum.RADAR_JAMMER, 1f);

            // Add Hacking Tool to player inventory
            MyScriptWrapper.AddInventoryItem(MyScriptWrapper.GetCentralInventory(), MyMwcObjectBuilderTypeEnum.SmallShip_HackingTool, (int)MyMwcObjectBuilder_SmallShip_HackingTool_TypesEnum.Level_2, 1f, true);
            MyScriptWrapper.AddInventoryItem(MyScriptWrapper.GetCentralInventory(), MyMwcObjectBuilderTypeEnum.SmallShip_HackingTool, (int)MyMwcObjectBuilder_SmallShip_HackingTool_TypesEnum.Level_3, 1f, true);

            // Set musicmood right from script start
            MyAudio.ApplyTransition(MyMusicTransitionEnum.TensionBeforeAnAction);

            m_Slave = (MySmallShipBot)MyScriptWrapper.TryGetEntity(328);
            MySession.PlayerFriends.Add(m_Slave);
            m_Slave.Follow(MySession.PlayerShip);
            m_Slave.SetName("Slave");
        }
Esempio n. 14
0
        void Aggregator3Destroyed()
        {
            MySmallShipBot marcus   = (MySmallShipBot)MyScriptWrapper.GetEntity("Marcus");
            MyEntity       destroy4 = MyScriptWrapper.GetEntity((uint)EntityID.PrefabAutodestruct4);

            marcus.Attack(destroy4);
        }
 public void Init(MySmallShipBot bot)
 {
     m_stuckPosition  = bot.GetPosition();
     m_stuckTimer     = 0;
     m_followPosition = null;
     m_followPath     = null;
     PathNotFound     = false;
 }
Esempio n. 16
0
 public static void DebugDraw()
 {
     foreach (var pair in CurrentBotsAttackingPlayer)
     {
         MySmallShipBot bot = pair.Value;
         MyDebugDraw.DrawSphereWireframe(bot.GetPosition(), bot.WorldVolume.Radius, new Vector3(1, 0, 0), 1);
     }
 }
 public void Init(MySmallShipBot bot)
 {
     m_stuckPosition = bot.GetPosition();
     m_stuckTimer = 0;
     m_followPosition = null;
     m_followPath = null;
     PathNotFound = false;
 }
        void BotSpawned(MyEntity spawnpoint, MyEntity bot)
        {
            //List<uint> {
            //    (uint)EntityID.SpawnLastR,
            //    (uint)EntityID.SpawnLastL,
            //    (uint)EntityID.SpawnLastAsteroid,
            //    (uint)EntityID.SpawnCenterL,
            //    (uint)EntityID.SpawnCenterR }

            var attackerList = new List <uint>
            {
                (uint)EntityID.SpawnInR,
                (uint)EntityID.SpawnInL,
                (uint)EntityID.SpawnIn3,
                (uint)EntityID.SpawnIn4,
                (uint)EntityID.SpawnFrontL,
                (uint)EntityID.SpawnFrontR,
                (uint)EntityID.SpawnCenterL,
                (uint)EntityID.SpawnCenterR,
                (uint)EntityID.SpawnLastL,
                (uint)EntityID.SpawnLastR,
                (uint)EntityID.SpawnLastAsteroid,
                (uint)EntityID.SpawnLast1,
                (uint)EntityID.SpawnLast1_2,
                (uint)EntityID.SpawnLast2,
                (uint)EntityID.SpawnLast2_2,
                (uint)EntityID.SpawnLast3,
                (uint)EntityID.SpawnLast3_2,
                (uint)EntityID.SpawnLast4,
            };

            foreach (var item in attackerList)
            {
                if (spawnpoint == MyScriptWrapper.GetEntity(item) && bot != null)
                {
                    MyScriptWrapper.SetSleepDistance(bot as MySmallShipBot, 10000);
                    var botShip = bot as MySmallShipBot;
                    m_attackerBots.Add(botShip);
                    //botShip.Attack(MyScriptWrapper.GetEntity((uint)m_transporterAttackPoints[MyMwcUtils.GetRandomInt(m_transporterAttackPoints.Count)]));
                }
            }

            foreach (var item in m_spawnCompanions)
            {
                if (spawnpoint == MyScriptWrapper.GetEntity(item))
                {
                    MySmallShipBot botship = bot as MySmallShipBot;
                    //botship.SlowDown = 0.583f;
                    botship.SpeedModifier = 0.583f * (MOTHERSHIP_SLOWSPEED / MOTHERSHIP_FULLSPEED);

                    botship.IsDestructible = m_reassignBotTargets;
                    if (m_reassignBotTargets)
                    {
                        bot.Kill(m_towers[MyMwcUtils.GetRandomInt(m_towers.Length)]);
                    }
                }
            }
        }
        internal Vector3 GetUpPlane(MySmallShipBot bot)
        {
            if (MySession.PlayerShip != null)
            {
                return(MySession.PlayerShip.WorldMatrix.Up);
            }

            return(bot.WorldMatrix.Up);
        }
        private void GuardsCatchedPlayer()
        {
            MySmallShipBot vesselGuardL = (MySmallShipBot)MyScriptWrapper.GetEntity("GuardL");
            MySmallShipBot vesselGuardR = (MySmallShipBot)MyScriptWrapper.GetEntity("GuardR");

            MyScriptWrapper.ChangeFaction(vesselGuardL, MyMwcObjectBuilder_FactionEnum.Slavers);
            MyScriptWrapper.ChangeFaction(vesselGuardR, MyMwcObjectBuilder_FactionEnum.Slavers);
            Fail(MyTextsWrapperEnum.Fail_CaughtByGuards);
        }
        private void MissedWindow()
        {
            MySmallShipBot vesselGuardL = (MySmallShipBot)MyScriptWrapper.GetEntity("GuardL");
            MySmallShipBot vesselGuardR = (MySmallShipBot)MyScriptWrapper.GetEntity("GuardR");

            MyScriptWrapper.ChangeFaction(vesselGuardL, MyMwcObjectBuilder_FactionEnum.Slavers);
            MyScriptWrapper.ChangeFaction(vesselGuardR, MyMwcObjectBuilder_FactionEnum.Slavers);
            Fail(MyTextsWrapperEnum.Fail_MissedTimeWindow);
        }
Esempio n. 22
0
        public override void Load()
        {
            if (!IsMainSector)
            {
                return;
            }

            m_detector_ReachStart = MyScriptWrapper.GetDetector(MyScriptWrapper.GetEntity((uint)EntityID.DetectorStartRacePosition));
            m_detector_Explosion1 = MyScriptWrapper.GetDetector(MyScriptWrapper.GetEntity((uint)EntityID.DetectorExplosion1));

            m_detector_Explosion2      = MyScriptWrapper.GetDetector(MyScriptWrapper.GetEntity((uint)EntityID.DetectorExplosion2));
            m_detector_Explosion3      = MyScriptWrapper.GetDetector(MyScriptWrapper.GetEntity((uint)EntityID.DetectorExplosion3));
            m_detector_TunnelExplosion = MyScriptWrapper.GetDetector(MyScriptWrapper.GetEntity((uint)EntityID.DetectorTunnelExplosion));

            m_marcus   = MyScriptWrapper.GetEntity(MyActorConstants.GetActorName(MyActorEnum.MARCUS));
            m_tarja    = MyScriptWrapper.GetEntity(MyActorConstants.GetActorName(MyActorEnum.TARJA));
            m_vitolino = MyScriptWrapper.GetEntity(MyActorConstants.GetActorName(MyActorEnum.VALENTIN));
            m_manjeet  = (MySmallShipBot)MyScriptWrapper.GetEntity((uint)EntityID.Manjeet);

            MyScriptWrapper.OnDialogueFinished     += Script_DialogueFinished;
            MyScriptWrapper.OnSpawnpointBotSpawned += Script_BotSpawned;

            ShutDownAllLights();

            foreach (var minesDummy in m_minesDummies)
            {
                MyScriptWrapper.GenerateMinesField <MyMineSmart>(MyScriptWrapper.GetEntity(minesDummy),
                                                                 MyMwcObjectBuilder_FactionEnum.Russian, 4,
                                                                 MyTextsWrapper.Get(MyTextsWrapperEnum.MineBasicHud).ToString(),
                                                                 MyHudIndicatorFlagsEnum.SHOW_BORDER_INDICATORS |
                                                                 MyHudIndicatorFlagsEnum.ALPHA_CORRECTION_BY_DISTANCE |
                                                                 MyHudIndicatorFlagsEnum.SHOW_TEXT |
                                                                 MyHudIndicatorFlagsEnum.SHOW_DISTANCE |
                                                                 MyHudIndicatorFlagsEnum.SHOW_FACTION_RELATION_MARKER |
                                                                 MyHudIndicatorFlagsEnum.SHOW_ONLY_IF_DETECTED_BY_RADAR);
            }

            m_playerIsOnStart      = false;
            m_challengerIsOnStart  = false;
            m_unfollowedCompanions = false;

            foreach (var item in m_raceTowers)
            {
                if (item != null)
                {
                    foreach (var item2 in item)
                    {
                        MyScriptWrapper.UnhideEntity(MyScriptWrapper.GetEntity(item2));
                    }
                }
            }

            MyScriptWrapper.UnhideEntity(MyScriptWrapper.GetEntity((uint)EntityID.Transporter));

            base.Load();
        }
        internal override void Close(MySmallShipBot bot)
        {
            base.Close(bot);

            var drill = bot.Weapons.GetMountedDrill();
            if (drill != null && drill.CurrentState != MyDrillStateEnum.InsideShip)
            {
                drill.Eject();
            }
        }
Esempio n. 24
0
 public static void StartGameoverTimer()
 {
     if (m_gameOverTimer == null)
     {
         MyAudio.AddCue2D(MySoundCuesEnum.SfxClaxonAlert);
         MySmallShipBot.PlayFriendlyFireCue();
         MyDialogues.Stop();
         m_gameOverTimer = 10.0f; // 10s
     }
 }
Esempio n. 25
0
        void OnEntityPositionChanged(object sender, EventArgs e)
        {
            MySmallShipBot smallShip = sender as MySmallShipBot;

            if (smallShip != null)
            {
                BoundingBox bbox = new BoundingBox(smallShip.WorldAABB.Min - new Vector3(DANGER_ZONE_SIZE), smallShip.WorldAABB.Max + new Vector3(DANGER_ZONE_SIZE));
                m_dangerZoneStructure.MoveProxy(smallShip.GetDangerZoneID(), ref bbox, Vector3.Zero);
            }
        }
Esempio n. 26
0
        private MySmallShipBot CreateShip(MyMwcObjectBuilder_SmallShip_Bot bldr, Vector3 position)
        {
            MySmallShipBot bot = CreateBotFromBuilder(bldr, position);

            MyEntities.Add(bot);

            SetBotPath(bot);

            return(bot);
        }
        void Return_OnMissionLoaded(MyMissionBase sender)
        {
            MySmallShipBot transport1 = (MySmallShipBot)MyScriptWrapper.GetEntity((uint)EntityID.ShipTransport1);

            transport1.SetWaypointPath("transport");
            transport1.Patrol();
            MySmallShipBot transport2 = (MySmallShipBot)MyScriptWrapper.GetEntity((uint)EntityID.ShipTransport2);

            transport2.SetWaypointPath("transport");
            transport2.Patrol();
        }
Esempio n. 28
0
        internal bool TrySwitchExploreSearch(MySmallShipBot bot)
        {
            Vector3 flyTo = bot.GetPosition() + MyMwcUtils.GetRandomVector3Normalized() * MyMwcUtils.GetRandomFloat(0, 100);

            if (bot.TryTestPosition(flyTo, bot.GetPosition()))
            {
                m_state = CuriousState.EXPLORE_SEARCHING;
                return(true);
            }
            return(false);
        }
        void ShootShotgun(MySmallShipBot bot, bool targetVisible, float distance, float angleToTarget)
        {
            switch (m_fireState)
            {
            case FireStateEnum.WAIT:
                m_fireTimer = 0;
                if (angleToTarget < SHOOT_CONE && targetVisible && distance <= FIRING_RANGE_MAX)
                {
                    m_fireState = FireStateEnum.FIRE;
                }
                break;

            case FireStateEnum.FIRE:
                if (targetVisible && distance <= FIRING_RANGE_MAX && angleToTarget < SHOOT_CONE)
                {
                    m_fireTimer += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                    bot.Shoot(m_currentWeapon);
                    if (m_fireTimer > 0.5f)
                    {
                        m_fireTimer = 0;
                        m_fireState = FireStateEnum.COOLDOWN;
                    }
                    else if (angleToTarget < HIT_CONE)
                    {
                        m_fireTimer = 0;
                        m_fireState = FireStateEnum.HIT;
                    }
                }
                else
                {
                    m_fireState = FireStateEnum.WAIT;
                }
                break;

            case FireStateEnum.HIT:
                m_fireTimer += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                bot.Shoot(m_currentWeapon);
                if (m_fireTimer > 0.5f)
                {
                    m_fireState = FireStateEnum.COOLDOWN;
                    m_fireTimer = 0;
                }
                break;

            case FireStateEnum.COOLDOWN:
                m_fireTimer += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                if (m_fireTimer > 0.5f)
                {
                    m_fireTimer = 0;
                    m_fireState = FireStateEnum.FIRE;
                }
                break;
            }
        }
        internal override void Close(MySmallShipBot bot)
        {
            base.Close(bot);

            if (m_state == StateEnum.CLOSING_IN_FORMATION)
            {
                MyAttackFormations.Instance.RemoveEntity(bot);
            }

            MyBotCoordinator.RemoveAttacker(bot);
        }
        public void Init(MySmallShipBot bot, Vector3 location)
        {
            locationVisibleCheckTimer = 0;
            stuckPosition             = bot.GetPosition();
            stuckTimer          = 0;
            PathNotFound        = false;
            this.location       = location;
            currentPathPosition = 0;

            UpdateTargetVisibility(bot);
        }
        internal override void Close(MySmallShipBot bot)
        {
            base.Close(bot);

            var drill = bot.Weapons.GetMountedDrill();

            if (drill != null && drill.CurrentState != MyDrillStateEnum.InsideShip)
            {
                drill.Eject();
            }
        }
Esempio n. 33
0
 public void Start(MySmallShipBot bot)
 {
     m_bot = bot;
     m_botFaction = bot.Faction;
     m_seeDistance = bot.SeeDistance;
     m_botWorldMatrix = bot.WorldMatrix;
     m_position = bot.GetPosition();
     m_closestEnemy_OnClose = closestEnemy_OnClose;
     m_closestVisual_OnClose = closestVisual_OnClose;
     m_bot.OnClose += m_bot_OnClose;
 }
 public void Start(MySmallShipBot bot)
 {
     m_bot                   = bot;
     m_botFaction            = bot.Faction;
     m_seeDistance           = bot.SeeDistance;
     m_botWorldMatrix        = bot.WorldMatrix;
     m_position              = bot.GetPosition();
     m_closestEnemy_OnClose  = closestEnemy_OnClose;
     m_closestVisual_OnClose = closestVisual_OnClose;
     m_bot.OnClose          += m_bot_OnClose;
 }
        private void Follow1Reached()
        {
            MyScriptWrapper.ActivateSpawnPoint((uint)EntityID.SpawnpointFactory);
            MySmallShipBot mitchel = (MySmallShipBot)MyScriptWrapper.GetEntity("Mitchel");

            mitchel.SetWaypointPath("Follow2");
            mitchel.PatrolMode = MyPatrolMode.ONE_WAY;
            mitchel.Patrol();

            MyScriptWrapper.SetEntityEnabled((uint)EntityID.FactoryFound, true);
        }
        public void Init(MySmallShipBot bot, Vector3 location)
        {
            locationVisibleCheckTimer = 0;
            stuckPosition = bot.GetPosition();
            stuckTimer = 0;
            PathNotFound = false;
            this.location = location;
            currentPathPosition = 0;

            UpdateTargetVisibility(bot);
        }
Esempio n. 37
0
 public static void RemoveAttacker(MySmallShipBot attacker)
 {
     for (int i = 0; i < CurrentBotsAttackingPlayer.Count; i++)
     {
         var pair = CurrentBotsAttackingPlayer[i];
         if (pair.Value == attacker)
         {
             CurrentBotsAttackingPlayer.RemoveAt(i);
             break;
         }
     }
 }
Esempio n. 38
0
        internal override void Init(MySmallShipBot bot)
        {
            base.Init(bot);

            findSmallship = new MyFindSmallshipHelper();
            //processedWaypoints = 0;
            if (bot.WaypointPath != null && bot.WaypointPath.WayPoints.Count > 0)
            {
                bot.CurrentWaypoint = bot.WaypointPath.WayPoints[0];
                m_lastWayPointPath = bot.WaypointPath;
            }
        }
Esempio n. 39
0
        public override void PreloadForDraw()
        {
            base.PreloadForDraw();

            foreach (Bot bot in m_botShips)
            {
                MySmallShipBot ship = CreateBotFromBuilder(bot.Builder, Vector3.Zero);
                ship.PreloadForDraw();
                ship.Physics.Enabled = false;
                ship.MarkForClose();
            }
        }
        public override void Unload()
        {
            base.Unload();
            MyScriptWrapper.OnSpawnpointBotSpawned -= MyScriptWrapperOnOnSpawnpointBotSpawned;
            MyScriptWrapper.OnBotReachedWaypoint   -= MyScriptWrapperOnBotReachedWaypoint;

            m_ravenguyBot  = null;
            m_ravengirlBot = null;
            m_marcus       = null;
            m_reef         = null;
            m_barkeeper    = null;
        }
 private void WaitForPath(MySmallShipBot bot)
 {
     if (bot.TryGetPath(out followPath))
     {
         if (followPath == null)
         {
             PathNotFound = true;
         }
         lookingForPath = false;
         currentPathPosition = 0;
         ResetStuck(bot);
     }
 }
Esempio n. 42
0
        public int Register(MySmallShipBot entity)
        {
            System.Diagnostics.Debug.Assert(entity == null || !entity.Closed);

            entity.OnPositionChanged += OnPositionChangedHandler;

            MyDangerZoneElement element = new MyDangerZoneElement(entity);

            BoundingBox bbox = new BoundingBox(entity.WorldAABB.Min - new Vector3(DANGER_ZONE_SIZE), entity.WorldAABB.Max + new Vector3(DANGER_ZONE_SIZE));

            int proxyId = m_dangerZoneStructure.AddProxy(ref bbox, element, 0);

            return proxyId;
        }
Esempio n. 43
0
        public void Start(MySmallShipBot bot, Vector3 position, Vector3 targetPosition)
        {
            m_bot = bot;
            m_position = position;
            m_targetPosition = targetPosition;
            m_up = bot.WorldMatrix.Up;

            float delta = 1.0f;
            m_points[0] = new Vector3(m_bot.LocalAABB.Max.X * delta, m_bot.LocalAABB.Max.Y * delta, m_bot.LocalAABB.Max.Z);
            m_points[1] = new Vector3(m_bot.LocalAABB.Min.X * delta, m_bot.LocalAABB.Max.Y * delta, m_bot.LocalAABB.Max.Z);
            m_points[2] = new Vector3(m_bot.LocalAABB.Max.X * delta, m_bot.LocalAABB.Min.Y, m_bot.LocalAABB.Max.Z);
            m_points[3] = new Vector3(m_bot.LocalAABB.Min.X * delta, m_bot.LocalAABB.Min.Y, m_bot.LocalAABB.Max.Z);

            Result = null;
            m_bot.OnClose += m_bot_OnClose;
        }
        private void CheckIfRoutePositionComputed(MySmallShipBot bot, MyEntity entityTarget)
        {
            // Wait for result (visible route position)
            if (bot.TryGetRoute(out m_followPosition))
            {
                m_lookingForPosition = false;

                if (!m_followPosition.HasValue)
                {
                    //PathNotFound = true;
                    m_lookingForPath = bot.TryFindPath(entityTarget.WorldAABB.GetCenter());  // can't get unstuck; try to find path using waypoints
                }

                ResetStuck(bot);
            }
        }
        internal override void Update(MySmallShipBot bot)
        {
            base.Update(bot);

            MyEntity enemy = bot.GetClosestEnemy();
            if (enemy != null)
            {
                Vector3 enemyToBot = bot.GetPosition() - enemy.GetPosition();
                float distance = enemyToBot.Length();
                if (distance <= bot.RunAwayDistance)
                {
                    Vector3 enemyToBotDirection = enemyToBot / distance;
                    Vector3 escapeTarget = bot.GetPosition() + enemyToBotDirection * 1000;
                    bot.Move(escapeTarget, escapeTarget, bot.WorldMatrix.Up, false);
                }
            }
        }
        internal override void Init(MySmallShipBot bot)
        {
            base.Init(bot);

            m_location = SourceDesire.GetLocation();
            m_state = CuriousState.GOTO;
            m_explorationTime = 0;

            m_target = SourceDesire.GetEnemy();

            if (m_target != null)
            {
	            Debug.Assert(!m_target.Closed);
                Debug.Assert(m_target != bot);
                //MyDialogues.Play(MyDialogueEnum.EAC_SURVEY_SITE_1800_RUSSIANSCREAM_02);
            }

            m_gotoLocationHelper.Init(bot, m_location);
        }
Esempio n. 47
0
        internal override void Update(MySmallShipBot bot)
        {
            base.Update(bot);

            if (timeToGoalChange <= 0)
            {
                UpdateGoals(bot);
                timeToGoalChange = MyMwcUtils.GetRandomFloat(CHANGE_TIME_MIN, CHANGE_TIME_MAX);
            }
            else
            {
                timeToGoalChange -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
            }

            bot.Move(moveTarget, lookTarget, up, false);
            if (shoot)
            {
                // just some default distance so that bot shoots (legacy shoot method)
                bot.Shoot(MyMwcObjectBuilder_FireKeyEnum.Primary);
            }
        }
            public RouteToBeFound(MySmallShipBot bot, MyPositionMemory positionMemory, RouteFoundHandler routeFoundHandler, object userData)
            {
                PositionMemory = positionMemory;
                PositionMemoryIndex = PositionMemory.GetCount() - 1;

                Bot = bot;
                Up = bot.WorldMatrix.Up;
                Position = bot.WorldMatrix.Translation;

                Points = new Vector3[4];
                float delta = 1.0f;
                float scale = 1.0f / MySmallShipConstants.ALL_SMALL_SHIP_MODEL_SCALE;
                Points[0] = new Vector3(Bot.LocalAABB.Max.X * delta * scale, Bot.LocalAABB.Max.Y * delta * scale, Bot.LocalAABB.Max.Z * scale);
                Points[1] = new Vector3(Bot.LocalAABB.Min.X * delta * scale, Bot.LocalAABB.Max.Y * delta * scale, Bot.LocalAABB.Max.Z * scale);
                Points[2] = new Vector3(Bot.LocalAABB.Max.X * delta * scale, Bot.LocalAABB.Min.Y * scale, Bot.LocalAABB.Max.Z * scale);
                Points[3] = new Vector3(Bot.LocalAABB.Min.X * delta * scale, Bot.LocalAABB.Min.Y * scale, Bot.LocalAABB.Max.Z * scale);

                RouteFoundHandler = routeFoundHandler;
                UserData = userData;

                Bot.OnClose += OnCloseBot;
            }
        private void FollowPath(MySmallShipBot bot)
        {
            if (currentPathPosition >= followPath.Count)
            {
                followPath = null;  // reached the goal or got stuck
            }
            else if (Vector3.DistanceSquared(followPath[currentPathPosition], bot.GetPosition()) < PATH_NEAR_DISTANCE_SQR)
            {
                currentPathPosition++;  // next waypoint reached
            }
            else
            {
                bot.Move(followPath[currentPathPosition], followPath[currentPathPosition], bot.WorldMatrix.Up, false, 1, 2);

                if (stuckTimer > 3)
                {
                    if (Vector3.DistanceSquared(bot.GetPosition(), stuckPosition) > STUCK_DISTANCE)
                    {
                        currentPathPosition++;  // try skipping ahead to the next waypoint instead of getting stuck right away
                        ResetStuck(bot);
                    }
                    else
                    {
                        //followPath[currentPathPosition] += MyMwcUtils.GetRandomVector3Normalized() * 1000;  // jitter the sub-goal
                    }
                }
                else if (Vector3.DistanceSquared(bot.GetPosition(), stuckPosition) > STUCK_DISTANCE)
                {
                    ResetStuck(bot);
                }
                else
                {
                    stuckTimer += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                }
            }
        }
        public void Update(MySmallShipBot bot)
        {
            // Location visible, fly to it
            if (!lookingForPath)
            {
                UpdateTargetVisibility(bot);
                
                if (locationVisible)
                {
                    FlyToLocation(bot);
                    return;
                }
            }

            // Wait for path
            if (lookingForPath)
            {
                WaitForPath(bot);
            }
            // Path found, follow path
            else if (!lookingForPath && followPath != null)
            {
                FollowPath(bot);
            }
            // Start looking for path
            else if (!lookingForPath)
            {
                lookingForPath = bot.TryFindPath(location);
            }
        }
Esempio n. 51
0
 void m_bot_OnClose(MyEntity obj)
 {
     m_bot = null;
 }
Esempio n. 52
0
 internal override bool ShouldFallAsleep(MySmallShipBot bot)
 {
     // check whether the followed object is/can be asleep
     if (bot.Leader != null)
     {
         var leaderBot = bot.Leader as MySmallShipBot;
         if (leaderBot == null) return false;  // if I don't follow a bot, I don't fall asleep no matter what
         return leaderBot.IsSleeping;
     }
     return base.ShouldFallAsleep(bot);
 }
Esempio n. 53
0
        internal override void Update(MySmallShipBot bot)
        {
            base.Update(bot);

            if (bot.Leader != null)
            {
                if (ShouldFallAsleep(bot))
                {
                    bot.IsSleeping = true;
                    return;
                }

                Vector3 leaderToBot = bot.GetPosition() - bot.Leader.GetPosition();
                Vector3 formationPositionActual = bot.Leader.GetFormationPosition(bot);
                Vector3 botToFormationPosition = formationPositionActual - bot.GetPosition();

                float leaderDistance = leaderToBot.Length();
                float formationPositionDistance = botToFormationPosition.Length();

                Vector3 flyTo;
                if (formationPositionDistance > MyMwcMathConstants.EPSILON_SQUARED && leaderDistance > MyMwcMathConstants.EPSILON)
                {
                    float leaderFactor = MathHelper.Clamp(leaderDistance - 5, 0, 25) / 20;
                    flyTo = (1.0f - leaderFactor) * leaderToBot / leaderDistance + leaderFactor * botToFormationPosition / formationPositionDistance;
                    flyTo = MyMwcUtils.Normalize(flyTo);
                    flyTo = bot.GetPosition() + flyTo * formationPositionDistance;

                    // Update leader visibility
                    if (visibilityCheckTimer <= 0)
                    {
                        MyLine line = new MyLine(bot.GetPosition(), formationPositionActual, true);
                        leaderVisible = !MyEntities.GetIntersectionWithLine(ref line, bot, bot.Leader, true, ignoreSmallShips: true).HasValue;

                        visibilityCheckTimer = 0.5f;
                    }
                    else
                    {
                        visibilityCheckTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
                    }
                }
                else
                {
                    // Bot is on formation position
                    flyTo = bot.GetPosition() + bot.WorldMatrix.Forward;
                    leaderVisible = true;
                }
                 
                if (leaderVisible)
                {
                    bool afterburner = /*bot.Leader.IsAfterburnerOn() || */formationPositionDistance > AFTERBURNER_DISTANCE;
                    Vector3 lookTarget = formationPositionDistance < LOOK_DISTANCE ? formationPositionActual + bot.Leader.WorldMatrix.Forward * 5000 : formationPositionActual;

                    float factor = MathHelper.Clamp(formationPositionDistance / 200, 0.5f, 1.0f);

                    factor = factor * factor * factor;

                    bot.Move(flyTo, lookTarget, bot.Leader.WorldMatrix.Up, afterburner, 1, 25, factor, slowRotation: true);

                    checkTimer += MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;

                    findSmallship.Init(bot);
                }
                else
                {
                    if (leaderDistance > MIN_LEADER_DISTANCE)
                    {
                        findSmallship.Update(bot, bot.Leader);

                        if (findSmallship.PathNotFound)
                        {
							//We dont want our friends sleeping elsewhere
                          //  bot.IsSleeping = true;
                        }
                    }
                }
            }
        }
 private void FlyToLocation(MySmallShipBot bot)
 {
     bot.Move(location, location, GetUpPlane(bot), false, 1, 2);
 }
 private void ResetStuck(MySmallShipBot bot)
 {
     stuckPosition = bot.GetPosition();
     stuckTimer = 0;
 }
Esempio n. 56
0
        internal override bool ShouldFallAsleep(MySmallShipBot bot)
        {
            // check distance from path
            if (bot.WaypointPath == null)
                return base.ShouldFallAsleep(bot);
            if (MySession.PlayerShip == null)
                return false;  // don't fall asleep if there's no player

            var playerPos = MySession.PlayerShip.GetPosition();
            bool cycle = bot.PatrolMode == MyPatrolMode.CYCLE;

            List<MyWayPoint> path = null;

            using (MyWayPoint.BlockedEdgesLock.AcquireSharedUsing())
            {
                path = bot.WaypointPath.CompletePath(MyWayPoint.BlockedEdgesForBots, bot.CurrentWaypoint, false, cycle);
            }

            for (int i = (cycle ? 0 : 1), j = (cycle ? path.Count - 1 : 0); i < path.Count; j = i++)
                if (MyMath.DistanceSquaredFromLineSegment(path[i].Position, path[j].Position, playerPos) < MyAIConstants.SLEEP_DISTANCE_FROM_PATH_SQUARED)
                    return false;

            return base.ShouldFallAsleep(bot);
        }
Esempio n. 57
0
        private void UpdateVisibility(MySmallShipBot bot, Vector3 targetPosition)
        {
            if (m_visibilityCheckTimer <= 0)
            {
                if (bot.GetPosition() == targetPosition)
                {
                    m_targetVisible = true;


                }
                else
                {
                    MyLine line = new MyLine(bot.GetPosition(), targetPosition, true);
                    var result = MyEntities.GetIntersectionWithLine(ref line, bot, null, true, ignoreChilds: true);
                    m_targetVisible = !result.HasValue;
                }

                m_visibilityCheckTimer = 0.5f;
            }
            else
            {
                m_visibilityCheckTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
            }
        }
 private void UpdateTargetVisibility(MySmallShipBot bot)
 {
     if (locationVisibleCheckTimer <= 0)
     {
         MyLine line = new MyLine(bot.GetPosition(), location, true);
         var result = MyEntities.GetIntersectionWithLine(ref line, bot, null, true, ignoreChilds: true);
         locationVisible = !result.HasValue;
         locationVisibleCheckTimer = 0.25f;
     }
     else
     {
         locationVisibleCheckTimer -= MyConstants.PHYSICS_STEP_SIZE_IN_SECONDS;
     }
 }
Esempio n. 59
0
        internal override void Update(MySmallShipBot bot)
        {
            base.Update(bot);

            if (ShouldFallAsleep(bot))
            {
                bot.IsSleeping = true;
                return;
            }

            bool pathChange = m_lastWayPointPath != bot.WaypointPath;
            if (pathChange) 
            {
                m_lastWayPointPath = bot.WaypointPath;
                m_currentWayPointIndex = 0;
            }

            bool cycle = bot.PatrolMode == MyPatrolMode.CYCLE;

            if (bot.WaypointPath != null && !bot.SuspendPatrol && bot.WaypointPath.WayPoints.Count > 0)
            {
                UpdateVisibility(bot, bot.CurrentWaypoint.GetPosition());

                if (!m_targetVisible)
                {
                    findSmallship.Update(bot, bot.CurrentWaypoint);
                    if (findSmallship.PathNotFound)
                    {
                        bot.IsSleeping = true;
                        m_isInvalid = true;
                    }
                }
                else
                {
                    bool blockedEdgesIdDirty = m_lastBlockedEdgesChangeId != MyWayPoint.BlockedEdgesChangeId;
                    m_path.Clear();
                    using (MyWayPoint.BlockedEdgesLock.AcquireSharedUsing())
                    {
                        m_path.AddRange(bot.WaypointPath.CompletePath(MyWayPoint.BlockedEdgesForBots, bot.CurrentWaypoint, false, cycle, !blockedEdgesIdDirty));
                    }
                    m_lastBlockedEdgesChangeId = MyWayPoint.BlockedEdgesChangeId;

                    if (blockedEdgesIdDirty)
                    {
                        if (bot.CurrentWaypoint == null)
                        {
                            m_currentWayPointIndex = 0;
                        }
                        else
                        {
                            m_currentWayPointIndex = m_path.IndexOf(bot.CurrentWaypoint);
                        }
                    }

                    // no path found
                    if (m_currentWayPointIndex == -1)
                    {
                        return;
                    }

                    bot.CurrentWaypoint = m_path[m_currentWayPointIndex];

                    if (Vector3.DistanceSquared(bot.GetPosition(), bot.CurrentWaypoint.GetPosition()) <= WAYPOINT_NEAR_DISTANCE_SQR)
                    {
                        if (bot.CurrentWaypoint.EntityId != null && m_lastWayPoint != bot.CurrentWaypoint)
                        {
                            m_lastWayPoint = bot.CurrentWaypoint;

                            MyScriptWrapper.BotReachedWaypoint(bot, bot.CurrentWaypoint);
                        }
                        //++processedWaypoints;

                        int count = m_path.Count;
                        switch (bot.PatrolMode)
                        {
                            case MyPatrolMode.CYCLE:
                                //bot.CurrentWaypointIndex = processedWaypoints % count;
                                m_currentWayPointIndex++;
                                if (m_currentWayPointIndex >= count)
                                {
                                    m_currentWayPointIndex = 0;
                                }
                                break;
                            case MyPatrolMode.PING_PONG:
                                if (count > 1)
                                {
                                    //bot.CurrentWaypointIndex = processedWaypoints % (count * 2 - 2);
                                    //if (bot.CurrentWaypointIndex >= count)
                                    //{
                                    //    bot.CurrentWaypointIndex = (count * 2 - 2) - bot.CurrentWaypointIndex;
                                    //}
                                    if (m_forward)
                                    {
                                        if (m_currentWayPointIndex < count - 1)
                                        {
                                            m_currentWayPointIndex++;
                                        }
                                        else
                                        {
                                            m_currentWayPointIndex--;
                                            m_forward = false;
                                        }
                                    }
                                    else
                                    {
                                        if (m_currentWayPointIndex > 0)
                                        {
                                            m_currentWayPointIndex--;
                                        }
                                        else
                                        {
                                            m_currentWayPointIndex++;
                                            m_forward = true;
                                        }
                                    }
                                }
                                else
                                {
                                    m_currentWayPointIndex = 0;
                                }
                                break;
                            case MyPatrolMode.ONE_WAY:
                                if (m_currentWayPointIndex < m_path.Count - 1)
                                {
                                    ++m_currentWayPointIndex;
                                }
                                break;
                        }

                        bot.CurrentWaypoint = m_path[m_currentWayPointIndex];
                    }

                    bot.Move(bot.CurrentWaypoint.GetPosition(), bot.CurrentWaypoint.GetPosition(), GetUpPlane(), false);
                    findSmallship.Init(bot);
                }
            }
        }
        internal Vector3 GetUpPlane(MySmallShipBot bot)
        {
            if (MySession.PlayerShip != null)
            {
                return MySession.PlayerShip.WorldMatrix.Up;
            }

            return bot.WorldMatrix.Up;
        }