예제 #1
0
        /*Delete Cosntruction Site once it's been confirmed, or no confirmation was necessary */
        private static void DeleteConstructionSiteConfirmed(RoadConstructionSite ConstructionSite)
        {
            if (ConstructionSite.helpFromFaction != null)
            {
                FactionsHelp.HelpFinished(ConstructionSite.helpFromFaction);
            }

            RoadConstructionSite.DeleteSite(ConstructionSite);
        }
예제 #2
0
        public static DiaOption HelpRoadConstruction(Faction faction, Pawn negotiator)
        {
            var dialog = new DiaOption("RoadsOfTheRim_commsAskHelp".Translate());

            // Find all construction sites on the world map
            IEnumerable <WorldObject> constructionSites = Find.WorldObjects.AllWorldObjects
                                                          .Where(site => site.def == DefDatabase <WorldObjectDef> .GetNamed("RoadConstructionSite")).ToArray();

            // If none : option should be disabled
            if (!constructionSites.Any())
            {
                dialog.Disable("RoadsOfTheRim_commsNoSites".Translate());
            }

            var diaNode = new DiaNode("RoadsOfTheRim_commsSitesList".Translate());

            foreach (var o in constructionSites)
            {
                var site      = (RoadConstructionSite)o;
                var diaOption = new DiaOption(site.FullName())
                {
                    action = delegate { FactionsHelp.StartHelping(faction, site, negotiator); }
                };
                // Disable sites that do not have a settlement of this faction close enough (as defined by ConstructionSite.maxTicksToNeighbour)
                if (site.ClosestSettlementOfFaction(faction) == null)
                {
                    diaOption = new DiaOption("Invalid site");
                    diaOption.Disable("RoadsOfTheRim_commsNotClose".Translate(faction.Name));
                }

                if (site.helpFromFaction != null)
                {
                    diaOption = new DiaOption("Invalid site");
                    diaOption.Disable("RoadsOfTheRim_commsAnotherFactionIsHelping".Translate(site.helpFromFaction));
                }

                if (!FactionsHelp.IsDeveloppedEnough(faction,
                                                     site.roadDef.GetModExtension <DefModExtension_RotR_RoadDef>()))
                {
                    diaOption = new DiaOption("Invalid site");
                    diaOption.Disable(
                        "RoadsOfTheRim_commsNotDevelopedEnough".Translate(faction.Name, site.roadDef.label));
                }

                diaNode.options.Add(diaOption);
                diaOption.resolveTree = true;
            }

            // If the faction is already helping, it must be disabled
            if (FactionsHelp.GetCurrentlyHelping(faction))
            {
                dialog = new DiaOption("Can't help build roads");
                dialog.Disable("RoadsOfTheRim_commsAlreadyHelping".Translate());
            }

            // If the faction is in construction cooldown, it must be disabled
            if (FactionsHelp.InCooldown(faction))
            {
                dialog = new DiaOption("Can't help build roads");
                dialog.Disable("RoadsOfTheRim_commsHasHelpedRecently".Translate(
                                   $"{FactionsHelp.DaysBeforeFactionCanHelp(faction):0.0}"));
            }

            // Cancel option (needed when all sites are disabled for one of the above reason)
            var cancelOption = new DiaOption("(" + "RoadsOfTheRim_commsCancel".Translate() + ")");

            diaNode.options.Add(cancelOption);
            cancelOption.resolveTree = true;

            dialog.link = diaNode;
            return(dialog);
        }