public static void PlaceBridgeIfNeeded(BuildableDef sourceDef, IntVec3 pos, Map map, Rot4 rotation, Faction faction, ThingDef stuff)
 {
     if (pos.GetThingList(map).Any(t => t.def.entityDefToBuild == TerrainDefOf.Bridge))
     {
         return;                //Already building!
     }
     if (PlaceBridges.NeedsBridge(sourceDef, pos, map, stuff))
     {
         GenConstruct.PlaceBlueprintForBuild(TerrainDefOf.Bridge, pos, map, rotation, faction, null);
     }
 }
Exemplo n.º 2
0
        //public static Blueprint_Build PlaceBlueprintForBuild(BuildableDef sourceDef, IntVec3 center, Map map, Rot4 rotation, Faction faction, ThingDef stuff)
        public static void Prefix(BuildableDef sourceDef, IntVec3 center, Map map, Rot4 rotation, Faction faction)
        {
            if (faction != Faction.OfPlayer || sourceDef == TerrainDefOf.Bridge)
            {
                return;
            }

            TerrainAffordanceDef affNeeded = sourceDef.terrainAffordanceNeeded;

            foreach (IntVec3 pos in GenAdj.CellsOccupiedBy(center, rotation, sourceDef.Size))
            {
                if (PlaceBridges.NeedsBridge(sourceDef, pos, map))
                {
                    GenConstruct.PlaceBlueprintForBuild(TerrainDefOf.Bridge, pos, map, rotation, faction, null);
                }
            }
        }
        public static void DrawBridgeCost(Designator_Build designator, Vector2 drawPos, float curY, ThingDef stuff)
        {
            DesignationDragger dragger  = Find.DesignatorManager.Dragger;
            int bridgeCount             = 0;
            IEnumerable <IntVec3> cells = dragger.Dragging ? dragger.DragCells :
                                          GenAdj.OccupiedRect(UI.MouseCell(), designator.PlacingRot(), designator.PlacingDef.Size).Cells;

            foreach (IntVec3 dragPos in cells)
            {
                if (PlaceBridges.NeedsBridge(designator.PlacingDef, dragPos, designator.Map, stuff))
                {
                    bridgeCount++;
                }
            }

            if (bridgeCount == 0)
            {
                return;
            }

            //could just say wood here, this is still assuming it costs only one thing.
            ThingDefCountClass bridgeCost = TerrainDefOf.Bridge.costList.First();

            Widgets.ThingIcon(new Rect(drawPos.x, drawPos.y + curY, 27f, 27f), bridgeCost.thingDef);

            int totalCost = bridgeCost.count * bridgeCount;

            string label = $"{totalCost} ({TerrainDefOf.Bridge.LabelCap})";

            //This doesn't account for normal building cost + under bridge cost, but what can you do
            if (designator.Map.resourceCounter.GetCount(bridgeCost.thingDef) < totalCost)
            {
                GUI.color = Color.red;
                label     = label + " (" + "NotEnoughStoredLower".Translate() + ")";
            }
            Text.Font   = GameFont.Small;
            Text.Anchor = TextAnchor.MiddleLeft;
            Widgets.Label(new Rect(drawPos.x + 29f, drawPos.y + curY, 999f, 29f), label);
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = Color.white;
        }