Ejemplo n.º 1
0
 override public void SetBasement(SurfaceBlock b, PixelPosByte pos)
 {
     if (b == null)
     {
         return;
     }
     b.ClearSurface(!(innerPosition == SurfaceRect.full));
     SetBuildingData(b, pos);
     b.ReplaceMaterial(ResourceType.FERTILE_SOIL_ID);
     if (!subscribedToUpdate)
     {
         GameMaster.realMaster.labourUpdateEvent += LabourUpdate;
         subscribedToUpdate = true;
     }
 }
Ejemplo n.º 2
0
    void LabourResult()
    {
        float totalResources = 0;

        actionLabel         = "";
        bool?[,] pillarsMap = new bool?[8, 8];
        for (int a = 0; a < 8; a++)
        {
            for (int b = 0; b < 8; b++)
            {
                pillarsMap[a, b] = null;
            }
        }
        int placesToWork = 64;
        List <ScalableHarvestableResource> unfinishedPillars = new List <ScalableHarvestableResource>();

        if (workObject.cellsStatus != 0)
        {
            int i = 0;
            while (i < workObject.surfaceObjects.Count)
            {
                ScalableHarvestableResource shr = workObject.surfaceObjects[i] as ScalableHarvestableResource;
                if (shr == null)
                {
                    workObject.surfaceObjects[i].Annihilate(false);
                }
                else
                {
                    if (shr.resourceCount == ScalableHarvestableResource.MAX_VOLUME)
                    {
                        placesToWork--;
                        pillarsMap[shr.innerPosition.x / 2, shr.innerPosition.z / 2] = true;
                        totalResources += ScalableHarvestableResource.MAX_VOLUME;
                    }
                    else
                    {
                        pillarsMap[shr.innerPosition.x / 2, shr.innerPosition.z / 2] = false;
                        totalResources += shr.resourceCount;
                        unfinishedPillars.Add(shr);
                    }
                }
                i++;
            }
        }

        if (placesToWork == 0)
        {
            actionLabel = Localization.GetActionLabel(LocalizationActionLabels.BlockCompleted);
            workObject.ClearSurface(false); // false так как все равно его удаляем
            workObject.myChunk.ReplaceBlock(workObject.pos, BlockType.Cube, rtype.ID, rtype.ID, false);
            StopWork();
        }
        else
        {
            int pos = (int)(placesToWork * Random.value);
            int n   = 0;
            for (int a = 0; a < 8; a++)
            {
                for (int b = 0; b < 8; b++)
                {
                    if (pillarsMap[a, b] == true)
                    {
                        continue;
                    }
                    else
                    {
                        if (n == pos)
                        {
                            ScalableHarvestableResource shr = null;
                            float count = BUILDING_SPEED * workflow;
                            if (pillarsMap[a, b] == false)
                            {
                                foreach (ScalableHarvestableResource fo in unfinishedPillars)
                                {
                                    if (fo.innerPosition.x / 2 == a & fo.innerPosition.z / 2 == b)
                                    {
                                        shr = fo;
                                        break;
                                    }
                                }
                                if (count > ScalableHarvestableResource.MAX_VOLUME - shr.resourceCount)
                                {
                                    count = ScalableHarvestableResource.MAX_VOLUME - shr.resourceCount;
                                }
                            }
                            else
                            {
                                shr = Structure.GetStructureByID(Structure.RESOURCE_STICK_ID) as ScalableHarvestableResource;
                                shr.SetBasement(workObject, new PixelPosByte(a * 2, b * 2));
                            }
                            count = GameMaster.colonyController.storage.GetResources(rtype, count);
                            if (count == 0)
                            {
                                // if (showOnGUI) actionLabel = Localization.GetAnnouncementString(GameAnnouncements.NotEnoughResources);
                            }
                            else
                            {
                                totalResources += count;
                                shr.AddResource(rtype, count);
                            }
                            actionLabel += string.Format("{0:0.##}", totalResources / (float)CubeBlock.MAX_VOLUME * 100f) + '%';
                            return;
                        }
                        else
                        {
                            n++;
                        }
                    }
                }
            }
        }
    }