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);
     }
 }
Beispiel #2
0
        public static void PlaceBridgeIfNeeded(BuildableDef sourceDef, IntVec3 pos, Map map, Rot4 rotation, Faction faction, ThingDef stuff)
        {
            TerrainDef bridgeDef = PlaceBridges.GetNeededBridge(sourceDef, pos, map, stuff);

            if (bridgeDef == null)
            {
                return;
            }

            if (pos.GetThingList(map).Any(t => t.def.entityDefToBuild == bridgeDef))
            {
                return;                //Already building!
            }
            Log.Message($"Replace Stuff placing {bridgeDef} for {sourceDef}({sourceDef.GetTerrainAffordanceNeed(stuff)}) on {map.terrainGrid.TerrainAt(pos)}");
            GenConstruct.PlaceBlueprintForBuild_NewTemp(bridgeDef, pos, map, rotation, faction, null);            //Are there bridge precepts/styles?...
        }
Beispiel #3
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;
        }
        //protected override void DrawPlaceMouseAttachments(float curX, ref float curY)
        public static void Postfix(Designator_Build __instance, float curX, ref float curY)
        {
            List <TerrainDef> neededBridges = new List <TerrainDef>();

            ThingDef              stuff   = __instance.StuffDef;
            DesignationDragger    dragger = Find.DesignatorManager.Dragger;
            IEnumerable <IntVec3> cells   = dragger.Dragging ? dragger.DragCells :
                                            GenAdj.OccupiedRect(UI.MouseCell(), __instance.PlacingRot(), __instance.PlacingDef.Size).Cells;

            foreach (IntVec3 dragPos in cells)
            {
                if (PlaceBridges.GetNeededBridge(__instance.PlacingDef, dragPos, __instance.Map, stuff) is TerrainDef tdef)
                {
                    neededBridges.Add(tdef);
                }
            }

            if (neededBridges.Count == 0)
            {
                return;
            }

            Dictionary <ThingDef, int> bridgeTotalCost = new Dictionary <ThingDef, int>();
            float work = 0;

            foreach (TerrainDef bridgeDef in neededBridges)
            {
                work += bridgeDef.GetStatValueAbstract(StatDefOf.WorkToBuild);
                if (bridgeDef.costList != null)
                {
                    foreach (ThingDefCountClass bridgeCost in bridgeDef.costList)
                    {
                        bridgeTotalCost.TryGetValue(bridgeCost.thingDef, out int costCount);
                        bridgeTotalCost[bridgeCost.thingDef] = costCount + bridgeCost.count;
                    }
                }
            }

            if (bridgeTotalCost.Count == 0)
            {
                string label = $"{StatDefOf.WorkToBuild.LabelCap}: {work.ToStringWorkAmount()} ({TerrainDefOf.Bridge.LabelCap})";                 //Not bridgeCostDef.LabelCap

                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleLeft;
                Widgets.Label(new Rect(curX + 29f, curY, 999f, 29f), label);                 //private const float DragPriceDrawNumberX
                curY       += 29f;
                Text.Anchor = TextAnchor.UpperLeft;
            }

            foreach (var(bridgeCostDef, bridgeCostCount) in bridgeTotalCost.Select(x => (x.Key, x.Value)))
            {
                Widgets.ThingIcon(new Rect(curX, curY, 27f, 27f), bridgeCostDef);

                string label = $"{bridgeCostCount} ({TerrainDefOf.Bridge.LabelCap})";                 //Not bridgeCostDef.LabelCap
                //This doesn't account for normal building cost + under bridge cost, but what can you do
                if (__instance.Map.resourceCounter.GetCount(bridgeCostDef) < bridgeCostCount)
                {
                    GUI.color = Color.red;
                    label     = label + " (" + "NotEnoughStoredLower".Translate() + ")";
                }
                Text.Font   = GameFont.Small;
                Text.Anchor = TextAnchor.MiddleLeft;
                Widgets.Label(new Rect(curX + 29f, curY, 999f, 29f), label);                 //private const float DragPriceDrawNumberX
                curY       += 29f;
                Text.Anchor = TextAnchor.UpperLeft;
            }
            GUI.color = Color.white;
        }