Example #1
0
        public void InsertRequiredActors()
        {
            MyMwcLog.WriteLine("InsertRequiredActors - START");

            foreach (MyActorEnum actor in RequiredActors)
            {
                switch (actor)
                {
                //Insert Madelyn
                case MyActorEnum.MADELYN:
                {
                    if (!MyEntities.EntityExists("Madelyn"))
                    {
                        MyMwcLog.WriteLine("Insert Madelyne - START");

                        // Holds ids for remap
                        IMyEntityIdRemapContext remapContext = new MyEntityIdRemapContext();

                        //MyMwcObjectBuilder_SectorObjectGroups groups = MySectorGenerator.LoadSectorGroups(MyTemplateGroups.GetGroupSector(MyTemplateGroupEnum.Madelyn));
                        MyMwcObjectBuilder_SectorObjectGroups groups = MySession.Static.LoadSectorGroups(MyTemplateGroups.GetGroupSector(MyTemplateGroupEnum.Madelyn));
                        System.Diagnostics.Debug.Assert(groups.Groups.Count > 0);

                        MyMwcObjectBuilder_ObjectGroup madelynGroup = groups.Groups[0];
                        groups.RemapEntityIds(remapContext);
                        IEnumerable <MyMwcObjectBuilder_Base> rootObjects = madelynGroup.GetRootBuilders(groups.Entities);

                        List <MyMwcObjectBuilder_Base> clonedList = new List <MyMwcObjectBuilder_Base>();
                        foreach (MyMwcObjectBuilder_Base o in rootObjects)
                        {
                            // Clone
                            var clone = o.Clone() as MyMwcObjectBuilder_Base;
                            // we want Madelyn's prefab container as first builder
                            if (clone is MyMwcObjectBuilder_PrefabContainer)
                            {
                                clonedList.Insert(0, clone);
                            }
                            else
                            {
                                clonedList.Add(clone);
                            }
                        }

                        System.Diagnostics.Debug.Assert(clonedList.Count > 0 && clonedList[0] is MyMwcObjectBuilder_PrefabContainer);

                        // create Madelyn's prefab container
                        MyEntity madelynMothership = MyEntities.CreateFromObjectBuilder(MyTextsWrapper.Get(MyTextsWrapperEnum.Actor_Madelyn).ToString(), clonedList[0], ((MyMwcObjectBuilder_Object3dBase)clonedList[0]).PositionAndOrientation.GetMatrix());
                        madelynMothership.FindChild(MyMissionLocation.MADELYN_HANGAR).DisplayName = MyTextsWrapper.Get(MyTextsWrapperEnum.Sapho).ToString();
                        madelynMothership.SetName(MyActorConstants.GetActorName(MyActorEnum.MADELYN));
                        Matrix madelynMothershipWorldInv = Matrix.Invert(madelynMothership.WorldMatrix);

                        List <MinerWars.AppCode.Game.Entities.WayPoints.MyWayPoint> waypoints = new List <Entities.WayPoints.MyWayPoint>();

                        // create other entities as children of Madelyn's prefab container
                        for (int i = 1; i < clonedList.Count; i++)
                        {
                            System.Diagnostics.Debug.Assert(clonedList[i] is MyMwcObjectBuilder_Object3dBase);
                            MyEntity childEntity = MyEntities.CreateFromObjectBuilder(null, clonedList[i], ((MyMwcObjectBuilder_Object3dBase)clonedList[i]).PositionAndOrientation.GetMatrix());
                            childEntity.SetLocalMatrix(childEntity.WorldMatrix * madelynMothershipWorldInv);
                            madelynMothership.Children.Add(childEntity);
                            if (childEntity is MinerWars.AppCode.Game.Entities.WayPoints.MyWayPoint)
                            {
                                waypoints.Add(childEntity as MinerWars.AppCode.Game.Entities.WayPoints.MyWayPoint);
                            }
                        }

                        // connect waypoints of Madelyn's prefab container
                        foreach (var waypoint in waypoints)
                        {
                            waypoint.ResolveLinks();
                        }

                        // set correct Madelyn's position and add to scene
                        madelynMothership.SetWorldMatrix(MyPlayer.FindMothershipPosition());
                        madelynMothership.Link();
                        MyEntities.Add(madelynMothership);

                        MyMwcLog.WriteLine("Insert Madelyne - END");
                    }
                    else
                    {
                        MyMwcLog.WriteLine("Insert Madelyne - Madelyne already loaded");
                    }

                    MyWayPointGraph.RecreateWaypointsAroundMadelyn();
                }
                break;

                //Insert Marcus
                case MyActorEnum.MARCUS:
                    InsertFriend(MyActorEnum.MARCUS);
                    break;

                //Insert RavenGirl
                case MyActorEnum.TARJA:
                    InsertFriend(MyActorEnum.TARJA);
                    break;

                //Insert RavenGuy
                case MyActorEnum.VALENTIN:
                    InsertFriend(MyActorEnum.VALENTIN, MyMwcObjectBuilder_SmallShip_TypesEnum.HAMMER);
                    break;

                default:
                    System.Diagnostics.Debug.Assert(false, "Uknown actor to insert!");
                    break;
                }
            }

            MyMwcLog.WriteLine("InsertRequiredActors - END");
        }