// end build request
 public void CreateSelectedBuilding(byte x, byte z, bool checkForIntersections)
 {
     if (observingSurface == null || observingSurface.destroyed)
     {
         SelfShutOff();
         return;
     }
     ResourceContainer[] cost;
     if (selectedStructureID != Structure.SETTLEMENT_CENTER_ID)
     {
         cost = ResourcesCost.GetCost(selectedStructureID);
     }
     else
     {
         cost = ResourcesCost.GetSettlementUpgradeCost(constructingLevel);
     }
     if (colony.storage.CheckSpendPossibility(cost))
     {
         byte strSize = Structure.GetStructureSize(selectedStructureID), res = PlaneExtension.INNER_RESOLUTION;
         if (x + strSize > res)
         {
             x = (byte)(res - strSize);
         }
         if (z + strSize > res)
         {
             z = (byte)(res - strSize);
         }
         if (checkForIntersections && observingSurface.IsAnyBuildingInArea(new SurfaceRect(x, z, strSize)))
         {
             constructingPlaneTouchPos = new Vector2Int(x, z);
             buildIntersectionSubmit.SetActive(true);
             return;
         }
         else
         {
             colony.storage.GetResources(cost);
             Structure s  = Structure.GetStructureByID(selectedStructureID);
             byte      rt = 0;
             if (s.rotate90only)
             {
                 rt  = (byte)(Random.value * 3);
                 rt *= 2;
             }
             else
             {
                 rt = (byte)(Random.value * 7);
             }
             if (s.ID == Structure.SETTLEMENT_CENTER_ID)
             {
                 (s as Settlement).SetLevel(constructingLevel);
             }
             s.SetBasement(observingSurface, new PixelPosByte(x, z));
             //if (!(s is Dock) & !(s is Hangar)) s.SetModelRotation(rt);
             PoolMaster.current.BuildSplash(s.transform.position);
             GameMaster.realMaster.eventTracker?.BuildingConstructed(s);
             if (observingSurface.fulfillStatus != FullfillStatus.Empty)
             {
                 if (constructionPlane.activeSelf)
                 {
                     PrepareConstructionPlane();
                 }
                 if (strSize == res | Structure.PlaceInCenter(selectedStructureID))
                 {
                     if (s is IPlanable)
                     {
                         var   ip = s as IPlanable;
                         Plane p;
                         if (ip.TryGetPlane(observingSurface.faceIndex, out p) && !p.isTerminate)
                         {
                             var sbb = selectedBuildingButton;
                             UIController.current.Select(p);
                         }
                     }
                 }
                 ReturnButton();
             }
             else
             {
                 ReturnButton();
             }
         }
     }
     else
     {
         GameLogUI.NotEnoughResourcesAnnounce();
     }
 }
    public void SelectBuildingForConstruction(int i_structureID, int buttonIndex)
    {
        selectedStructureID = i_structureID;
        buildingButtonsContainer.GetChild(buttonIndex).GetComponent <Image>().overrideSprite = PoolMaster.gui_overridingSprite;
        if (selectedBuildingButton >= 0)
        {
            buildingButtonsContainer.GetChild(selectedBuildingButton).GetComponent <Image>().overrideSprite = null;
        }
        selectedBuildingButton = buttonIndex;

        infoPanel.SetActive(true);
        nameField.text = Localization.GetStructureName(selectedStructureID);
        var sts = Structure.GetStructureSize(selectedStructureID).ToString();

        gridTextField.text = sts + " x " + sts;

        var stype = Structure.GetTypeByID(selectedStructureID);
        var btype = typeof(Building);

        if (stype == btype || stype.IsSubclassOf(btype))
        {
            var energySurplus = Building.GetEnergySurplus(selectedStructureID);
            if (energySurplus != 0)
            {
                energyIcon.SetActive(true);
                energyTextField.gameObject.SetActive(true);
                energyTextField.text = energySurplus > 0 ? '+' + energySurplus.ToString() :  energySurplus.ToString();
            }
            else
            {
                energyIcon.SetActive(false);
                energyTextField.gameObject.SetActive(false);
            }
            var htype = typeof(House);
            if (stype == htype || stype.IsSubclassOf(htype))
            {
                housingIcon.SetActive(true);
                housingTextField.gameObject.SetActive(true);
                housingTextField.text = House.GetHousingValue(selectedStructureID).ToString();
            }
            else
            {
                housingIcon.SetActive(false);
                housingTextField.gameObject.SetActive(false);
            }
        }
        else
        {
            energyIcon.SetActive(false);
            energyTextField.gameObject.SetActive(false);
            housingIcon.SetActive(false);
            housingTextField.gameObject.SetActive(false);
        }
        description.text = Localization.GetStructureDescription(selectedStructureID);
        (description.transform.parent as RectTransform).SetInsetAndSizeFromParentEdge(RectTransform.Edge.Top, 0, description.rectTransform.rect.height);

        resourcesCostImage[0].transform.parent.gameObject.SetActive(true);
        Text t = resourcesCostImage[0].transform.GetChild(0).GetComponent <Text>();

        string reason     = "UNACCEPTABLE!";
        bool   acceptable = Structure.CheckSpecialBuildingConditions(selectedStructureID, observingSurface, ref reason);

        if (!acceptable)
        {
            t.text  = reason;
            t.color = Color.yellow;
            resourcesCostImage[0].uvRect = ResourceType.GetResourceIconRect(0);
            resourcesCostImage[0].gameObject.SetActive(true);
            for (int i = 1; i < resourcesCostImage.Length; i++)
            {
                resourcesCostImage[i].gameObject.SetActive(false);
            }
            buildingCreateMode = BuildingCreateInfoMode.Unacceptable_Material;
            innerBuildButton.gameObject.SetActive(false);
        }
        else
        {
            // all conditions met
            ResourceContainer[] cost;
            if (selectedStructureID != Structure.SETTLEMENT_CENTER_ID)
            {
                cost = ResourcesCost.GetCost(selectedStructureID);
            }
            else
            {
                cost = ResourcesCost.GetSettlementUpgradeCost(constructingLevel);
            }
            //resource cost drawing
            float[] storageResources = colony.storage.standartResources;
            for (int i = 0; i < resourcesCostImage.Length; i++)
            {
                if (i < cost.Length)
                {
                    resourcesCostImage[i].uvRect = ResourceType.GetResourceIconRect(cost[i].type.ID);
                    t      = resourcesCostImage[i].transform.GetChild(0).GetComponent <Text>();
                    t.text = Localization.GetResourceName(cost[i].type.ID) + " : " + string.Format("{0:0.##}", cost[i].volume);
                    showingResourcesCount[i] = new Vector2(cost[i].type.ID, cost[i].volume);
                    if (storageResources[cost[i].type.ID] < cost[i].volume)
                    {
                        t.color = Color.red;
                    }
                    else
                    {
                        t.color = Color.white;
                    }
                    resourcesCostImage[i].gameObject.SetActive(true);
                }
                else
                {
                    resourcesCostImage[i].gameObject.SetActive(false);
                }
            }
            lastStorageStatus  = colony.storage.operationsDone;
            buildingCreateMode = BuildingCreateInfoMode.Acceptable;
            innerBuildButton.gameObject.SetActive(true);
        }
    }