public MyMwcObjectBuilder_FoundationFactory(MyMwcObjectBuilder_PrefabContainer prefabContainer, bool isBuilding, int buildingTimeFromStart, 
     MyMwcObjectBuilder_ObjectToBuild buildingObject, List<MyMwcObjectBuilder_ObjectToBuild> buildingQueue)
 {
     PrefabContainer = prefabContainer;
     IsBuilding = isBuilding;
     BuildingTimeFromStart = buildingTimeFromStart;
     BuildingObject = buildingObject;
     BuildingQueue = buildingQueue;            
 }
Exemplo n.º 2
0
 public MyMwcObjectBuilder_FoundationFactory(MyMwcObjectBuilder_PrefabContainer prefabContainer, bool isBuilding, int buildingTimeFromStart,
                                             MyMwcObjectBuilder_ObjectToBuild buildingObject, List <MyMwcObjectBuilder_ObjectToBuild> buildingQueue)
 {
     PrefabContainer       = prefabContainer;
     IsBuilding            = isBuilding;
     BuildingTimeFromStart = buildingTimeFromStart;
     BuildingObject        = buildingObject;
     BuildingQueue         = buildingQueue;
 }
        protected override void OnOkClick(MyGuiControlButton sender)
        {
            CloseScreen();
            var focused = m_groupList.GetFocusedItem();

            if (focused != null)
            {
                var group = focused.Tag as MyMwcObjectBuilder_ObjectGroup;

                IEnumerable<MyMwcObjectBuilder_PrefabBase> prefabs = group.GetPrefabBuilders(m_entities);
                IEnumerable<MyMwcObjectBuilder_Base> rootObjects = group.GetRootBuilders(m_entities);
                var objects3d = rootObjects.OfType<MyMwcObjectBuilder_Object3dBase>();

                if (objects3d.Any())
                {
                    MyEditorGizmo.ClearSelection();

                    var basePos = MyCamera.Position + Matrix.Invert(MyCamera.ViewMatrix).Forward * 100;
                    var firstPos = objects3d.First().PositionAndOrientation.Position;
                    var offset = basePos - firstPos;

                    foreach (var b in objects3d)
                    {
                        b.PositionAndOrientation.Position += offset;
                        b.ClearEntityId();
                        MyEntity entity = MyEntities.CreateFromObjectBuilderAndAdd(null, b, b.PositionAndOrientation.GetMatrix());
                        MyEditorGizmo.AddEntityToSelection(entity);
                    }
                }

                // Prefabs
                var editedContainer = MyEditor.Static.GetEditedPrefabContainer();
                if (editedContainer == null)
                {
                    MyMwcObjectBuilder_PrefabContainer prefabContainerBuilder = new MyMwcObjectBuilder_PrefabContainer(
                        null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, new List<MyMwcObjectBuilder_PrefabBase>(), MyClientServer.LoggedPlayer.GetUserId(),
                        MyMwcObjectBuilder_FactionEnum.Euroamerican, new MyMwcObjectBuilder_Inventory(new List<MyMwcObjectBuilder_InventoryItem>(), MyInventory.DEFAULT_MAX_ITEMS));

                    editedContainer = MyEntities.CreateFromObjectBuilderAndAdd(
                        null, prefabContainerBuilder,
                        Matrix.CreateTranslation(MyCamera.Position + Matrix.Invert(MyCamera.ViewMatrix).Forward * 100)) as MyPrefabContainer;

                    MyEditor.Static.EditPrefabContainer(editedContainer);
                }

                if (editedContainer != null)
                {
                    MyEditorGizmo.ClearSelection();
                    List<MyEntity> addedEntities = new List<MyEntity>();

                    foreach (var prefabBuilder in prefabs)
                    {
                        prefabBuilder.EntityId = null;
                        var entity = editedContainer.CreateAndAddPrefab(null, prefabBuilder);
                        addedEntities.Add(entity);
                    }

                    // Select newly added objects
                    foreach (var entity in addedEntities)
                    {
                        MyEditorGizmo.AddEntityToSelection(entity);
                    }
                }
            }
        }
        private void AddPrefab(PrefabTag tag, Vector2? screenPosition = null)
        {
            if (tag == null)
            {
                return;
            }

            MyMwcObjectBuilder_PrefabBase prefabBuilder = null;
            MyPrefabContainer container = MyEditor.Static.GetEditedPrefabContainer();

            if (MyFakes.ENABLE_OBJECT_COUNTS_LIMITS)
			{
            //here test if we can even add entity
        	    if (MyEntities.GetObjectsCount() >= MyEditorConstants.MAX_EDITOR_ENTITIES_LIMIT)
    	        {
	                MyAudio.AddCue2D(MySoundCuesEnum.GuiEditorObjectMoveInvalid);
                    MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.MaxLargeShipsCountReached, MyTextsWrapperEnum.MessageBoxCaptionError, MyTextsWrapperEnum.Ok, null));
            	    return;
          		}
            }
            prefabBuilder = MyPrefabFactory.GetInstance().CreatePrefabObjectBuilder(tag.PrefabModule, tag.PrefabId, tag.FactionAppearance);            

            if(container != null && prefabBuilder is MyMwcObjectBuilder_PrefabFoundationFactory && container.ContainsPrefab(PrefabTypesFlagEnum.FoundationFactory))
            {
                // prefab container can contains only one foundation factory
                MyGuiManager.AddScreen(new MyGuiScreenMessageBox(MyMessageBoxType.ERROR, MyTextsWrapperEnum.PrefabContainerAlreadyContainsFoundationFactory,
                        MyTextsWrapperEnum.YouCantAddFoundationFactory, MyTextsWrapperEnum.Ok, null));
                    return;                
            }

            if (container == null)
            {
                List<MyMwcObjectBuilder_PrefabBase> prefabBuilders = new List<MyMwcObjectBuilder_PrefabBase>();
                prefabBuilders.Add(prefabBuilder);
                MyMwcObjectBuilder_PrefabContainer prefabContainerBuilder = new MyMwcObjectBuilder_PrefabContainer(
                    null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, prefabBuilders, MyClientServer.LoggedPlayer.GetUserId(),
                    MyMwcObjectBuilder_FactionEnum.Euroamerican, new MyMwcObjectBuilder_Inventory(new List<MyMwcObjectBuilder_InventoryItem>(), 1000));
                MyEditor.Static.CreateFromObjectBuilder(prefabContainerBuilder, Matrix.Identity, screenPosition);
            }
            else
            {
                MyEditor.Static.CreateFromObjectBuilder(prefabBuilder, Matrix.Identity, screenPosition);
            }
        }
Exemplo n.º 5
0
        private void GenerateStations(MyMwcVector3Int sector, MySolarSystemMapData solarData, MySolarSystemMapSectorData sectorData, List<MyMwcObjectBuilder_Base> addToList, Random rnd, MyDynamicAABBTree prunningStructure)
        {
            Dictionary<MyMwcVector3Int, MyMwcObjectBuilder_SectorObjectGroups> groupCache = new Dictionary<MyMwcVector3Int, MyMwcObjectBuilder_SectorObjectGroups>();

            //List<MyImportantSolarObject>
            var objects = solarData.ImportantObjects.Where(o => o.NavigationMark.Sector.Equals(sector));

            foreach(var obj in objects)
            {
                var size = MyPrefabContainerConstants.MAX_DISTANCE_FROM_CONTAINER_CENTER / 1000;
                Vector3? pos = FindEntityPosition(prunningStructure, rnd, size);
                if (pos.HasValue)
                {
                    var templateSector = MyTemplateGroups.GetGroupSector(obj.TemplateGroup);
                    MyMwcObjectBuilder_SectorObjectGroups groups;
                    if (!groupCache.TryGetValue(templateSector, out groups))
                    {
                        groups = LoadObjectGroups(templateSector);
                        if (groups == null)
                        {
                            return;
                        }
                        groupCache.Add(templateSector, groups);
                    }

                    sectorData.Entities.Add(new MySolarSystemMapEntity(sector, pos.Value, size, "", MySolarSystemEntityEnum.OutpostIcon));

                    var group = rnd.Item(groups.Groups);
                    IEnumerable<MyMwcObjectBuilder_PrefabBase> prefabs = group.GetPrefabBuilders(groups.Entities);
                    IEnumerable<MyMwcObjectBuilder_Base> rootObjects = group.GetRootBuilders(groups.Entities);
                    var objects3d = rootObjects.OfType<MyMwcObjectBuilder_Object3dBase>();

                    var faction = MyFactions.GetFactionBySector(sector);

                    var objectPos = pos.Value;
                    if (objects3d.Any())
                    {
                        var firstPos = objects3d.First().PositionAndOrientation.Position;
                        var offset = objectPos - firstPos;

                        foreach (var o in objects3d)
                        {
                            // Clone
                            var clone = o.Clone() as MyMwcObjectBuilder_Object3dBase;
                            clone.PositionAndOrientation.Position += offset;
                            clone.ClearEntityId();
                            if (clone is MyMwcObjectBuilder_PrefabContainer)
                            {
                                ((MyMwcObjectBuilder_PrefabContainer)clone).Faction = faction;
                            }
                            if (clone is MyMwcObjectBuilder_SpawnPoint)
                            {
                                ((MyMwcObjectBuilder_SpawnPoint)clone).Faction = faction;
                            }
                            addToList.Add(clone);
                        }
                    }
                    else if(prefabs.Any())
                    {
                        MyMwcObjectBuilder_PrefabContainer container = new MyMwcObjectBuilder_PrefabContainer(null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE,
                            prefabs.ToList(), 0, faction, null);

                        var clone = container.Clone() as MyMwcObjectBuilder_PrefabContainer; // To clone children easily
                        clone.ClearEntityId(); // Clear childs ids
                        clone.PositionAndOrientation = new MyMwcPositionAndOrientation(objectPos, Vector3.Forward, Vector3.Up);
                        addToList.Add(clone);
                    }
                } //end of station generation

                if (pos.HasValue && rnd.Float(0, 1) < 0.5f)
                { //Create mysterious cube at 1% of stations
                    var sizeMyst = size * 1.5f;
                    Vector3? posMyst = FindEntityPosition(prunningStructure, rnd, sizeMyst, 1.0f, 1.0f, pos.Value);
                    if (posMyst.HasValue)
                    {
                        CreateMysteriousCubes(posMyst.Value, addToList, rnd);
                    }

                    //Create some more
                    int count = rnd.Next(5);
                    for (int i = 0; i < count; i++)
                    {
                        var size2 = MyMwcSectorConstants.SECTOR_SIZE / 2;
                        Vector3? pos2 = FindEntityPosition(prunningStructure, rnd, size2);
                        if (pos2.HasValue)
                        {
                            CreateMysteriousCubes(pos2.Value, addToList, rnd);
                        }
                    }
                }
            }
        }
Exemplo n.º 6
0
        public void GenerateSectorObjectBuildersFromSolarEntities(List<MySolarSystemMapEntity> entities, List<MyMwcObjectBuilder_Base> addToList, Random rnd, MyWeightDictionary<MyMwcVoxelMaterialsEnum> primaryMaterials, MyWeightDictionary<MyMwcVoxelMaterialsEnum> secondaryMaterials, MyStaticAsteroidTypeSetEnum staticAsteroidTypesets, MyMwcVoxelMaterialsEnum? fieldMaterial = null, MySolarSystemArea.AreaEnum? areaType = null)
        {
            List<MyMwcObjectBuilder_StaticAsteroid_TypesEnum> asteroids = new List<MyMwcObjectBuilder_StaticAsteroid_TypesEnum>(5);
            List<MyMwcVoxelFilesEnum> voxelAsteroids = new List<MyMwcVoxelFilesEnum>(10);

            int count = addToList.Count;

            foreach (var e in entities)
            {
                if (e.EntityType == MySolarSystemEntityEnum.VoxelAsteroid)
                {
                    int voxelAsteroidSize = FindAsteroidSize(e.Radius, MyVoxelMap.AsteroidSizes);

                    int rndIndex = rnd.Next(0, voxelAsteroids.Count);

                    MyVoxelMap.GetAsteroidsBySizeInMeters(voxelAsteroidSize, voxelAsteroids, false);

                    MyMwcObjectBuilder_VoxelMap builder = GenerateVoxelMap(voxelAsteroidSize, e.PositionInSector, rnd, voxelAsteroids, primaryMaterials, secondaryMaterials);

                    addToList.Add(builder);
                }
                else if (e.EntityType == MySolarSystemEntityEnum.StaticAsteroid)
                {
                    float radius = 100;
                    if (e.Radius == 10000)
                        radius = rnd.Next(2000, 11000);
                    if (e.Radius == 1000)
                        radius = rnd.Next(100, 1100);
                    if (e.Radius == 100)
                        radius = rnd.Next(10, 100);


                    MyMwcVoxelMaterialsEnum asteroidMaterial = MyMwcVoxelMaterialsEnum.Stone_01;
                    if (primaryMaterials.Count > 0)
                        primaryMaterials.GetRandomItem(rnd);

                    MyStaticAsteroidTypeSetEnum asteroidType = MyStaticAsteroidTypeSetEnum.A;

                    //for (int i = 0; i < 40000000; i++)
                    {
                        asteroidType = (MyStaticAsteroidTypeSetEnum)rnd.Item(Enum.GetValues(typeof(MyStaticAsteroidTypeSetEnum)));
                    }

                    if ((staticAsteroidTypesets & MyStaticAsteroidTypeSetEnum.A) == MyStaticAsteroidTypeSetEnum.A)
                        asteroidType = MyStaticAsteroidTypeSetEnum.A;
                    if ((staticAsteroidTypesets & MyStaticAsteroidTypeSetEnum.B) == MyStaticAsteroidTypeSetEnum.B)
                        asteroidType = MyStaticAsteroidTypeSetEnum.B;
                    if ((staticAsteroidTypesets & MyStaticAsteroidTypeSetEnum.All) == MyStaticAsteroidTypeSetEnum.All)
                        asteroidType = rnd.Float(0, 1) > 0.5f ? MyStaticAsteroidTypeSetEnum.A : MyStaticAsteroidTypeSetEnum.B;

                    var builder = GenerateStaticAsteroid(radius, asteroidType, asteroidMaterial, e.PositionInSector, rnd, asteroids);

  
                    builder.AsteroidMaterial1 = fieldMaterial;
                    if (areaType == MySolarSystemArea.AreaEnum.Sun)
                    {
                        builder.FieldDir = MinerWars.AppCode.Game.GUI.MyGuiScreenGamePlay.Static.GetDirectionToSunNormalized();
                    }

                    builder.Generated = true;
                    addToList.Add(builder);

                 
                    //MyEntity ent = MyEntities.CreateFromObjectBuilderAndAdd(null, new MyMwcObjectBuilder_StaticAsteroid(asteroids[rndIndex], mat),
                    //    Matrix.CreateWorld(e.PositionInSector, rnd.Vector(1), rnd.Vector(1)));
                }
                else if (e.EntityType == MySolarSystemEntityEnum.LargeShip)
                {
                    var shipType = rnd.Enum<MyMwcObjectBuilder_PrefabLargeShip_TypesEnum>();
                    MyMwcObjectBuilder_Prefab_AppearanceEnum appearance = rnd.Enum<MyMwcObjectBuilder_Prefab_AppearanceEnum>();

                    var ship = new MyMwcObjectBuilder_PrefabLargeShip(shipType, appearance, new MyMwcVector3Short(0, 0, 0), rnd.Vector(1), null, rnd.FloatNormal(), "Abandoned large ship", 0, false, 0);                    
                    var gamePlayProperties = MyGameplayConstants.GetGameplayProperties(MyMwcObjectBuilderTypeEnum.PrefabLargeShip, (int)shipType, MyMwcObjectBuilder_FactionEnum.Euroamerican);
                    ship.PrefabHealthRatio = MyGameplayConstants.HEALTH_RATIO_MAX;
                    ship.PrefabMaxHealth = gamePlayProperties.MaxHealth;
                    var prefabs = new List<MyMwcObjectBuilder_PrefabBase>();
                    prefabs.Add(ship);
                    var container = new MyMwcObjectBuilder_PrefabContainer(0, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, prefabs, 0, rnd.Enum<MyMwcObjectBuilder_FactionEnum>(), null);
                    container.PositionAndOrientation = new MyMwcPositionAndOrientation(e.PositionInSector, Vector3.Forward, Vector3.Up);
                    addToList.Add(container);
                }
                else if (e.EntityType == MySolarSystemEntityEnum.DebrisField)
                {
                    MyMwcObjectBuilder_LargeDebrisField objectBuilder = new MyMwcObjectBuilder_LargeDebrisField(MyMwcObjectBuilder_LargeDebrisField_TypesEnum.Debris84);
                    objectBuilder.PositionAndOrientation = new MyMwcPositionAndOrientation(e.PositionInSector, rnd.Vector(1), rnd.Vector(1));
                    addToList.Add(objectBuilder);
                }
            }
        }
        /// <summary>
        /// Creates new foundation factory from player's inventory. When player has no foundation factory in inventory, then returns result false.
        /// </summary>        
        /// <param name="result">Result of foundation factory creation</param>
        /// <returns>Instance of new foundation factory</returns>
        public static MyPrefabFoundationFactory TryCreateFoundationFactory(MyPlayer player, out bool result)
        {
            MyPrefabFoundationFactory foundationFactory = null;            
            MyInventoryItem foundationFactoryItem = player.Ship.Inventory.GetInventoryItem(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT);
            if (foundationFactoryItem == null) 
            {
                foundationFactoryItem = player.Ship.Inventory.GetInventoryItem(MyMwcObjectBuilderTypeEnum.FoundationFactory, null);
            }
            if (foundationFactoryItem == null)
            {
                result = false;                
            }
            else
            {
                MyMwcObjectBuilder_PrefabFoundationFactory foundationFactoryBuilder =
                    MyMwcObjectBuilder_Base.CreateNewObject(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT) as MyMwcObjectBuilder_PrefabFoundationFactory;
                MyMwcObjectBuilder_PrefabContainer prefabContainerBuilder = new MyMwcObjectBuilder_PrefabContainer(
                    null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, new List<MyMwcObjectBuilder_PrefabBase>(), MyClientServer.LoggedPlayer.GetUserId(),
                    player.Faction, new MyMwcObjectBuilder_Inventory(new List<MyMwcObjectBuilder_InventoryItem>(), 1000));

                Matrix ffWorld = Matrix.Identity;
                ffWorld.Translation = player.Ship.WorldMatrix.Translation + player.Ship.WorldMatrix.Forward * 20;

                MyPrefabContainer prefabContainer = new MyPrefabContainer();
                prefabContainer.Init(null, prefabContainerBuilder, ffWorld);
                MyEntities.Add(prefabContainer);

                MyPrefabConfiguration ffConfiguration = MyPrefabConstants.GetPrefabConfiguration(MyMwcObjectBuilderTypeEnum.PrefabFoundationFactory, (int)MyMwcObjectBuilder_PrefabFoundationFactory_TypesEnum.DEFAULT);
                
                foundationFactory = new MyPrefabFoundationFactory(prefabContainer);
                foundationFactory.Init(null, new Vector3(0f, 0f, 0f), Matrix.Identity, foundationFactoryBuilder, ffConfiguration);                
                prefabContainer.AddPrefab(foundationFactory);
                
                player.Ship.Inventory.RemoveInventoryItemAmount(ref foundationFactoryItem, 1f);
                                
                result = true;
            }
            return foundationFactory;
        }                        
        public MyPrefabContainer CreateFakePrefabContainer(string hudLabelText, Vector3 position)
        {

            List<MyMwcObjectBuilder_PrefabBase> prefabBuilders = new List<MyMwcObjectBuilder_PrefabBase>();
            int i = 0;
            int x = 0;
            foreach (MyMwcObjectBuilderTypeEnum prefabType in MyGuiPrefabHelpers.MyMwcPrefabTypesEnumValues)
            {
                foreach (int prefabId in MyMwcObjectBuilder_Base.GetObjectBuilderIDs(prefabType))
                {
                    MyMwcObjectBuilder_PrefabBase prefabBuilder = MyPrefabFactory.GetInstance().CreatePrefabObjectBuilder(prefabType, prefabId, MyMwcObjectBuilder_Prefab_AppearanceEnum.None);

                    prefabBuilders.Add(prefabBuilder);
                    i = i + 1000;
                    x = x + 500;
                }
            }

            MyMwcObjectBuilder_PrefabContainer prefabContainerBuilder = new MyMwcObjectBuilder_PrefabContainer(
                null, MyMwcObjectBuilder_PrefabContainer_TypesEnum.INSTANCE, prefabBuilders, MyClientServer.LoggedPlayer.GetUserId(),
                MyMwcObjectBuilder_FactionEnum.Euroamerican, new MyMwcObjectBuilder_Inventory(new List<MyMwcObjectBuilder_InventoryItem>(), MyInventory.DEFAULT_MAX_ITEMS));
            MyPrefabContainer container = (MyPrefabContainer)MyEntities.CreateFromObjectBuilderAndAdd(hudLabelText, prefabContainerBuilder, Matrix.CreateWorld(position, Vector3.Forward, Vector3.Up));
            MyEntities.TestEntityAfterInsertionForCollision(container);
            return container;
        }