Exemple #1
0
    void DronesUpdate()
    {
        if (currentSimTick % FactoryDrones.DronesSlowFactor == 0)
        {
            FactoryDrones.UpdateTasks();

            for (int i = 0; i < FactoryMaster.s.GetDrones().Count; i++)
            {
                if (FactoryMaster.s.GetDrones()[i] != null)
                {
                    FactoryDrones.UpdateDrone(FactoryMaster.s.GetDrones()[i]);
                }
            }
        }
    }
    /// <summary>
    /// Sets up the building inventory with slots made for the possible inputs&outputs craftable by the building.
    /// Must be called after the crafting controller is set up
    /// </summary>
    /// <param name="mydat"></param>
    public void SetUp(Position location, BuildingCraftingController myCrafter, BuildingData myData, List <InventoryItemSlot> starterInventory)
    {
        myLocation = location;

        switch (myData.myType)
        {
        case BuildingData.ItemType.Base:
            myType = InventoryType.Base;
            break;

        case BuildingData.ItemType.Miner:
            //myType = InventoryType.Miner;
            myType = InventoryType.NormalBuilding;
            break;

        case BuildingData.ItemType.Storage:
            myType = InventoryType.Storage;
            break;

        default:
            myType = InventoryType.NormalBuilding;
            break;
        }

        inventory.Clear();

        switch (myType)
        {
        case InventoryType.NormalBuilding:

            for (int i = 0; i < myCrafter.myCraftingProcesses.Length; i++)
            {
                var inputs = myCrafter.myCraftingProcesses[i].GetInputItems();
                for (int m = 0; m < inputs.Length; m++)
                {
                    AddSlot(inputs[m].Item1, inputs[m].Item2 * 2, InventoryItemSlot.SlotType.input, false);
                }

                var outputs = myCrafter.myCraftingProcesses[i].GetOutputItems();
                for (int m = 0; m < outputs.Length; m++)
                {
                    AddSlot(outputs[m].Item1, outputs[m].Item2 * 2, InventoryItemSlot.SlotType.output, false);
                }
            }

            break;

        case InventoryType.Miner:

            var ores = DataHolder.s.GetAllOres();

            for (int i = 0; i < ores.Length; i++)
            {
                AddSlot(DataHolder.s.GetItem(ores[i].oreUniqueName), -1, InventoryItemSlot.SlotType.input, false);
                AddSlot(DataHolder.s.GetItem(ores[i].oreUniqueName), -1, InventoryItemSlot.SlotType.output, false);
            }

            break;

        case InventoryType.Storage:

            // only fill in as much as we need. some slots may be leftover from construction.
            for (int i = inventory.Count; i < myData.buildingGrade; i++)
            {
                AddSlot(Item.GetEmpty(), 99, InventoryItemSlot.SlotType.storage, false);
            }

            FactoryDrones.RegisterStorageBuilding(this);

            break;
        }

        if (starterInventory != null)
        {
            foreach (var slot in starterInventory)
            {
                RestoreSlot(slot, false, myData.myType == BuildingData.ItemType.Rocket);
            }
        }

        dwellerSlots.Clear();
        for (int i = 0; i < myData.housingSlots; i++)
        {
            dwellerSlots.Add(AddSlot(Item.GetEmpty(), 1, InventoryItemSlot.SlotType.house, false));
        }

        maxDwellers = myData.housingSlots;

        workerSlots.Clear();
        for (int i = 0; i < myData.workerRequirement; i++)
        {
            workerSlots.Add(AddSlot(Item.GetEmpty(), 1, InventoryItemSlot.SlotType.worker, false));
        }

        maxWorkers = myData.workerRequirement;


        drawInventoryEvent?.Invoke();
        InventoryContentsChanged();
    }
 void OnDestroy()
 {
     FactoryDrones.RemoveStorageBuilding(this);
 }
Exemple #4
0
    public static void StartDeconstruction(Position location)
    {
        var myTile = Grid.s.GetTile(location);

        if (myTile.areThereConstruction)
        {
            var myConstruction = myTile.myConstruction;

            if (myConstruction.isConstruction)
            {
                myConstruction.isConstruction = false;

                if (myConstruction.constructionInventory.GetTotalAmountOfItems() + myConstruction.afterConstructionInventory.GetTotalAmountOfItems() <= 0)
                {
                    CompleteDeconstruction(myConstruction.center);
                }
                else
                {
                    FactoryDrones.UpdateConstructionTaskModeMidTask(myConstruction);
                }
            }
        }
        else
        {
            int                      direction    = 0;
            BuildingData             buildingData = null;
            List <InventoryItemSlot> afterConstructionInventory = null;
            bool                     canBeDestroyed             = true;
            if (myTile.areThereBelt)
            {
                buildingData = FactoryMaster.s.beltBuildingData;
                direction    = myTile.myBelt.direction;
                afterConstructionInventory = RemoveBelt(location);
                for (int i = afterConstructionInventory.Count - 1; i >= 0; i--)
                {
                    if (afterConstructionInventory[i].myItem.isEmpty())
                    {
                        afterConstructionInventory.RemoveAt(i);
                    }
                }
            }
            else if (myTile.areThereConnector)
            {
                buildingData = FactoryMaster.s.connectorBuildingData;
                direction    = myTile.myConnector.direction;
                RemoveConnector(location);
            }
            else if (myTile.areThereBuilding)
            {
                buildingData               = myTile.myBuilding.buildingData;
                canBeDestroyed             = myTile.myBuilding.isDestructable;
                location                   = myTile.myBuilding.center;
                afterConstructionInventory = RemoveBuilding(location);
            }

            if (canBeDestroyed)
            {
                if (buildingData != null)
                {
                    var construction = new Construction(buildingData, direction, location, GetRequirements(buildingData, true), afterConstructionInventory, false);
                    FactoryMaster.s.AddConstruction(construction);

                    foreach (var loc in construction.locations)
                    {
                        Grid.s.GetTile(loc).myConstruction = construction;
                    }
                }
            }
        }

        ObjectsUpdated?.Invoke();
    }