コード例 #1
0
        private void Produce(IronProducer ironProducer, GiverComponent ironGiver, DwarfsSlots dwarfsSlots)
        {
            if (!ironProducer || !ironGiver || !dwarfsSlots)
            {
                return;
            }

            if (ironProducer.timeSinceLastProduction >=
                ironProducer.productionEveryXMinutes * FramesPerSecond * secondPerMinute ||
                ironGiver.amount < ironGiver.maxCapacity)
            {
                ironGiver.amount += (ironProducer.productionPerMinute * dwarfsSlots.dwarfsAlreadyIn);
                ironProducer.timeSinceLastProduction = 0;
            }
            else
            {
                ironProducer.timeSinceLastProduction++;
            }
        }
コード例 #2
0
        private void addNewMine(IronProducer ironProducer, GiverComponent ironGiver, DwarfsSlots dwarfsSlots)
        {
            IronProducer[]   tmpIronProducers = new IronProducer[ironProducers.Length + 1];
            GiverComponent[] tmpIronGivers    = new GiverComponent[ironGivers.Length + 1];
            DwarfsSlots[]    tmpDwarfsSlots   = new DwarfsSlots[workingSlots.Length + 1];

            for (int i = 0; i < ironProducers.Length; i++)
            {
                tmpIronProducers[i] = ironProducers[i];
                tmpIronGivers[i]    = ironGivers[i];
                tmpDwarfsSlots[i]   = workingSlots[i];
            }

            tmpIronProducers[tmpIronProducers.Length - 1] = ironProducer;
            tmpIronGivers[tmpIronProducers.Length - 1]    = ironGiver;
            tmpDwarfsSlots[tmpDwarfsSlots.Length - 1]     = dwarfsSlots;

            ironProducers = tmpIronProducers;
            ironGivers    = tmpIronGivers;
            workingSlots  = tmpDwarfsSlots;
        }
コード例 #3
0
        void Update()
        {
            if (dayCycleSystem.state != DayCycleSystem.State.WORK)
            {
                return;
            }

            //Get ressource from giver then go the passiveInventory
            for (int index = 0; index < giverComponents.Length; index++)
            {
                GiverComponent giverComponent = giverComponents[index];
                if (giverComponent.nbDwarfsAttributed >= 1 || giverComponent.amount < 10)
                {
                    continue;
                }

                for (int i = 0; i < pathComponents.Length; i++)
                {
                    PathComponent pathComponent = pathComponents[i];
                    if (pathComponent.nodes.Length != 0)
                    {
                        continue;
                    }

                    Transform   giverBuildingTransformsComponent = giverTransformComponents[index];
                    DwarfsSlots giverDwarfsSlots = giverDwarfsSlotComponents[index];

                    Transform dwarfsTransform = dwarfsTransformComponents[i];

                    //Then go to closet storage
                    int indexPassiveInventory = GetClosestStorageIndexFromBuilding(giverBuildingTransformsComponent.position, giverComponent.resourceType);

                    if (indexPassiveInventory == -1)
                    {
                        continue;
                    }
                    InventoryComponent dwarfsInventoryComponent = dwarfsInventoryComponents[i];

                    if (pathComponent.index != 0 && pathComponent.dwarfsSlots[pathComponent.index - 1] != null)
                    {
                        pathComponent.dwarfsSlots[pathComponent.index - 1].dwarfsAlreadyIn--;
                        pathComponent.dwarfsSlots[pathComponent.index - 1].dwarfsInside
                        .Remove(dwarfsInventoryComponent);
                    }

                    giverComponent.nbDwarfsAttributed++;

                    dwarfsInventoryComponent.resourceType = giverComponent.resourceType;

                    //Go to giver
                    pathComponent.nodes       = aStarSystem.GetPath(dwarfsTransform, giverBuildingTransformsComponent);
                    pathComponent.dwarfsSlots = new DwarfsSlots[pathComponent.nodes.Length];
                    pathComponent.dwarfsSlots[pathComponent.nodes.Length - 1] = giverDwarfsSlots;
                    pathComponent.index = 0;

                    //Then go to closet storage
                    GraphNodeComponent[] path2  = aStarSystem.GetPath(giverBuildingTransformsComponent, passiveInventoryTransformsComponents[indexPassiveInventory]);
                    DwarfsSlots[]        slots2 = new DwarfsSlots[path2.Length];
                    slots2[path2.Length - 1] = passiveInventoryDwarfsSlotsComponents[indexPassiveInventory];

                    pathComponent.nodes       = pathComponent.nodes.Concat(path2).ToArray();
                    pathComponent.dwarfsSlots = pathComponent.dwarfsSlots.Concat(slots2).ToArray();
                    break;
                }
            }

            //Get ressource from storage then go the receiver
            for (int index = 0; index < receiverComponents.Length; index++)
            {
                ReceiverComponent receiverComponent = receiverComponents[index];
                if (receiverComponent.nbDwarfsAttributed >= 1 || receiverComponent.amount >= receiverComponent.maxCapacity)
                {
                    continue;
                }

                for (int i = 0; i < pathComponents.Length; i++)
                {
                    PathComponent pathComponent = pathComponents[i];
                    if (pathComponent.nodes.Length != 0)
                    {
                        continue;
                    }

                    Transform   receiverBuildingTransformsComponent = receiverTransformComponents[index];
                    DwarfsSlots receiverDwarfsSlots = receiverDwarfsSlotComponents[index];

                    Transform dwarfsTransform = dwarfsTransformComponents[i];

                    //Then go to closet storage
                    int indexPassiveInventory =
                        GetClosestStorageIndexFromBuilding(receiverBuildingTransformsComponent.position,
                                                           receiverComponent.resourceType);

                    if (indexPassiveInventory == -1)
                    {
                        continue;
                    }

                    InventoryComponent dwarfsInventoryComponent = dwarfsInventoryComponents[i];

                    if (pathComponent.index != 0 && pathComponent.dwarfsSlots[pathComponent.index - 1] != null)
                    {
                        pathComponent.dwarfsSlots[pathComponent.index - 1].dwarfsAlreadyIn--;
                        pathComponent.dwarfsSlots[pathComponent.index - 1].dwarfsInside
                        .Remove(dwarfsInventoryComponent);
                    }

                    receiverComponent.nbDwarfsAttributed++;

                    dwarfsInventoryComponent.resourceType = receiverComponent.resourceType;

                    //Go to closet storage
                    pathComponent.nodes = aStarSystem.GetPath(dwarfsTransform,
                                                              passiveInventoryTransformsComponents[indexPassiveInventory]);
                    pathComponent.dwarfsSlots = new DwarfsSlots[pathComponent.nodes.Length];
                    pathComponent.dwarfsSlots[pathComponent.nodes.Length - 1] = passiveInventoryDwarfsSlotsComponents[indexPassiveInventory];
                    pathComponent.index = 0;

                    //Then go to giver
                    GraphNodeComponent[] path2  = aStarSystem.GetPath(passiveInventoryTransformsComponents[indexPassiveInventory], receiverBuildingTransformsComponent);
                    DwarfsSlots[]        slots2 = new DwarfsSlots[path2.Length];
                    slots2[path2.Length - 1] = receiverDwarfsSlots;

                    pathComponent.nodes       = pathComponent.nodes.Concat(path2).ToArray();
                    pathComponent.dwarfsSlots = pathComponent.dwarfsSlots.Concat(slots2).ToArray();
                    break;
                }
            }
        }