Esempio n. 1
0
        public static string GenerateHistory(Faction subject, ref int disposition)
        {
            List <WeightedString> HistoryOptions = new List <WeightedString>();
            List <string>         history        = new List <string>();
            string text = "";

            int year = Find.TickManager.StartingYear - startingYear.RandomInRange;

            while (year < Find.TickManager.StartingYear)
            {
                HistoryOptions.Clear();
                HistoryOptions.Add(new WeightedString(FE_GrammarUtility.History(null, null, null, PawnGenerator.GeneratePawn(subject.RandomPawnKind(), subject)), 12));
                HistoryOptions.Add(new WeightedString(FE_GrammarUtility.History(subject), 4));
                HistoryOptions.Add(new WeightedString(FE_GrammarUtility.History(subject, Find.FactionManager.AllFactionsVisible.Where(fac => !fac.IsPlayer && fac != subject && !fac.def.hidden).RandomElement()), 3));
                HistoryOptions.Add(new WeightedString(FE_GrammarUtility.History(null, null, Find.WorldObjects.Settlements.FindAll(x => x.Faction == subject).RandomElement(), null), 16));
                HistoryOptions.Add(new WeightedString(FE_GrammarUtility.History(null, null, null, null, SettlementNameGenerator.GenerateSettlementName(null, subject.def.settlementNameMaker)), 10));
                HistoryOptions.Add(new WeightedString(FE_GrammarUtility.History(), 9));

                if (!HistoryOptions.TryRandomElementByWeight(x => x.weight, out WeightedString option))
                {
                    return("");
                }
                if (!CompareAlmostEqual(option.option, history))
                {
                    history.Add("HistoryDate".Translate(year));
                    history.Add(option.option + "\n\n");
                    year += leapInYears.RandomInRange;
                }
            }
            for (int i = 0; i < history.Count - 1; i += 2)
            {
                text += TrimKeys(history[i] + history[i + 1], subject, ref disposition);
            }
            return(text);
        }
        private void WarUpdate(War war)
        {
            Faction f1 = war.AttackerFaction();
            Faction f2 = war.DefenderFaction();

            if (f1 == null || f2 == null || f1.defeated || f2.defeated)
            {
                Wars.Remove(war);
                return;
            }
            // Settlement conqured
            int chance = WarEventChance.RandomInRange;

            // Event Chance - 0.000675% every 600 ticks

            // Settlement Conqoured 0.00005%
            if (chance < 5)
            {
                Settlement settlement;
                // if f1
                if (Rand.Chance(0.5f + GetByFaction(f2).resources == GetByFaction(f1).resources ? GetByFaction(f2).resources / GetByFaction(f1).resources < 1 ? (0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f)) : -(0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f)) : 0))
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f1).RandomElement();
                    GetByFaction(f1).history += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarSettlementConqueredWinner".Translate(settlement, f2);
                    GetByFaction(f2).history += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarSettlementConqueredLoser".Translate(settlement, f1);
                }
                // if f2
                else
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f2).RandomElement();
                }

                Settlement set = (Settlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Settlement);
                set.SetFaction(settlement.Faction == f1 ? f2 : f1);

                set.Tile = settlement.Tile;
                set.Name = settlement.Name;
                Find.WorldObjects.Remove(settlement);
                Find.WorldObjects.Add(set);

                GetByFaction(set.Faction).resources        += SETTLEMENT_RESOURCE_VALUE;
                GetByFaction(settlement.Faction).resources -= SETTLEMENT_RESOURCE_VALUE * 5;
                Messages.Message("MessageFactionWarSettlementConquered".Translate(set.Faction, settlement, settlement.Faction), MessageTypeDefOf.NeutralEvent);
                war.warHistory += "HistoryDate".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks)) + "MessageFactionWarSettlementConquered".Translate(set.Faction, settlement, settlement.Faction) + "\n\n";
                return;
            }
            // Settlement raided 0.00005%
            if (chance < 10)
            {
                Settlement settlement;
                // if f1
                if (Rand.Chance(0.5f + (GetByFaction(f2).resources / GetByFaction(f1).resources) < 1 ? (0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f)) : -(0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f))))
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f1).RandomElement();
                }
                // if f2
                else
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f2).RandomElement();
                }
                Find.WorldObjects.Remove(settlement);

                GetByFaction(settlement.Faction == f1 ? f2 : f1).resources += SETTLEMENT_RESOURCE_VALUE / 2;
                GetByFaction(settlement.Faction).resources -= SETTLEMENT_RESOURCE_VALUE * 5;
                Messages.Message(FE_GrammarUtility.WarEvent(settlement.Faction == f1 ? f2 : f1, settlement.Faction, settlement), MessageTypeDefOf.NeutralEvent);
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + FE_GrammarUtility.WarEvent(settlement.Faction == f1 ? f2 : f1, settlement.Faction, settlement) + "\n\n";
                return;
            }
            // Artifact cache - Background 0.0007%
            if (chance < 80)
            {
                if (Rand.Chance(0.5f))
                {
                    GetByFaction(f1).resources += LARGE_EVENT_Cache_RESOURCE_VALUE;
                    war.warHistory             += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + FE_GrammarUtility.WarEvent(f1) + "\n\n";
                }
                else
                {
                    GetByFaction(f2).resources += LARGE_EVENT_Cache_RESOURCE_VALUE;
                    war.warHistory             += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + FE_GrammarUtility.WarEvent(f2) + "\n\n";
                }
                return;
            }
            // Farms burned - Background 0.001%
            if (chance < 180)
            {
                if (Rand.Chance(0.5f))
                {
                    GetByFaction(f2).resources -= MEDIUM_EVENT_RESOURCE_VALUE;
                    war.warHistory             += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarFarms".Translate(f1, f2) + "\n\n";
                }
                else
                {
                    GetByFaction(f1).resources -= MEDIUM_EVENT_RESOURCE_VALUE;
                    war.warHistory             += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarFarms".Translate(f2, f1) + "\n\n";
                }
                return;
            }
            // Supply Depot 0.00025%
            if (chance < 205)
            {
                if (!Find.WorldObjects.Settlements.Where(x => (x.Faction == f1 && GetByFaction(f1).resources >= MEDIUM_EVENT_RESOURCE_VALUE * 2) || (x.Faction == f2 && GetByFaction(f1).resources >= MEDIUM_EVENT_RESOURCE_VALUE * 2)).TryRandomElement(out Settlement settlement))
                {
                    return;
                }
                if (!GetByFaction(settlement.Faction).SupplyDepots.Any(x => x > 10 * Global.DayInTicks) || !Find.WorldObjects.AllWorldObjects.Any(x => x.GetComponent <WorldObjectComp_SupplyDepot>() != null && x.GetComponent <WorldObjectComp_SupplyDepot>().IsActive&& x.GetComponent <TimeoutComp>().TicksLeft > 10 * Global.DayInTicks))
                {
                    return;
                }
                if (settlement.Faction.HostileTo(Faction.OfPlayer) && TileFinder.TryFindPassableTileWithTraversalDistance(settlement.Tile, 5, 25, out int tile))
                {
                    Site worldObject = SiteMaker.MakeSite(SiteCoreDefOf.Nothing, SitePartDefOf.Outpost, tile, settlement.Faction);
                    worldObject.GetComponent <TimeoutComp>().StartTimeout(Global.DayInTicks * 14);
                    WorldObjectComp_SupplyDepot.Type type = Rand.Chance(0.5f) ? WorldObjectComp_SupplyDepot.Type.Food : WorldObjectComp_SupplyDepot.Type.Weapons;
                    worldObject.GetComponent <WorldObjectComp_SupplyDepot>().StartComp(type);
                    worldObject.customLabel = "Supply Depot: " + type;
                    Find.WorldObjects.Add(worldObject);
                    Messages.Message("MessageFactionWarSupply".Translate(settlement.Faction), worldObject, MessageTypeDefOf.NeutralEvent, false);
                }
                else
                {
                    GetByFaction(settlement.Faction).SupplyDepots.Add(Global.DayInTicks * 14);
                    Messages.Message("MessageFactionWarSupply".Translate(settlement.Faction), null, MessageTypeDefOf.NeutralEvent, false);
                }
                GetByFaction(settlement.Faction).resources -= MEDIUM_EVENT_RESOURCE_VALUE;
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarSupply".Translate(settlement.Faction) + "\n\n";
                return;
            }
            // Caravan ambushed - Background 0.00125%
            if (chance < 355)
            {
                Faction ambusher = Rand.Chance(0.5f) ? f2 : f1;

                GetByFaction(ambusher == f1 ? f2 : f1).resources -= MINOR_EVENT_RESOURCE_VALUE;
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarCaravanAmbush".Translate(ambusher, ambusher == f1 ? f2 : f1) + "\n\n";
                return;
            }
            // Minor Outpost raided - Background 0.001%
            if (chance < 455)
            {
                Faction raider = Rand.Chance(0.5f) ? f2 : f1;

                GetByFaction(raider == f1 ? f2 : f1).resources -= MEDIUM_EVENT_RESOURCE_VALUE;
                GetByFaction(raider).resources += MEDIUM_EVENT_RESOURCE_VALUE / 2;
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarMinorOutpostRaid".Translate(raider, raider == f1 ? f2 : f1) + "\n\n";
                return;
            }
            // Failed Settlement raid - Background 0.001%
            if (chance < 555)
            {
                Settlement settlement;
                // if f1
                if (Rand.Chance(0.5f + (GetByFaction(f2).resources / GetByFaction(f1).resources) < 1 ? (0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f)) : -(0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f))))
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f1).RandomElement();
                }
                // if f2
                else
                {
                    settlement = Find.WorldObjects.Settlements.Where(x => x.Faction == f2).RandomElement();
                }
                Find.WorldObjects.Remove(settlement);

                GetByFaction(settlement.Faction == f1 ? f2 : f1).resources -= LARGE_EVENT_Cache_RESOURCE_VALUE;

                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + FE_GrammarUtility.WarEvent(settlement.Faction == f1 ? f2 : f1, settlement.Faction, settlement, true) + "\n\n";
                return;
            }

            // settlement Nuked - toxic fallout 0.00005%
            if (chance < 560 && Find.TickManager.TicksGame > Global.DayInTicks * 20 && Find.Storyteller.difficulty.difficulty >= 2 && !Find.AnyPlayerHomeMap.GameConditionManager.ConditionIsActive(GameConditionDefOf.ToxicFallout))
            {
                if (!(Rand.Chance(0.5f + GetByFaction(f2).resources == GetByFaction(f1).resources ? GetByFaction(f2).resources / GetByFaction(f1).resources < 1 ? (0.5f - (GetByFaction(f2).resources / GetByFaction(f1).resources / 2f)) : -(0.5f - ((GetByFaction(f2).resources / GetByFaction(f1).resources) / 2f)) : 0) && (f1.def.techLevel == TechLevel.Industrial || f1.def.techLevel == TechLevel.Spacer) &&
                      Find.WorldObjects.Settlements.Where(x => x.Faction == f2 && Utilities.Reachable(Find.AnyPlayerHomeMap.Tile, x.Tile, 30)).TryRandomElement(out Settlement ruin)))
                {
                    if (!((f2.def.techLevel == TechLevel.Industrial || f1.def.techLevel == TechLevel.Spacer) && Find.WorldObjects.Settlements.Where(x => x.Faction == f1 && Utilities.Reachable(Find.AnyPlayerHomeMap.Tile, x.Tile, 30)).TryRandomElement(out ruin)))
                    {
                        return;
                    }
                }
                Find.WorldObjects.Remove(ruin);

                GetByFaction(ruin.Faction).resources -= SETTLEMENT_RESOURCE_VALUE * 7;
                IncidentParms parms = new IncidentParms()
                {
                    forced = true,
                    target = Find.AnyPlayerHomeMap
                };
                IncidentDefOf.ToxicFallout.Worker.TryExecute(parms);
                Messages.Message("MessageFactionWarSettlementNuked".Translate(ruin, ruin.Faction == f1 ? f2 : f1), MessageTypeDefOf.ThreatSmall);

                GetByFaction(ruin.Faction == f1 ? f2 : f1).history += "HistoryDate".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks)) + "MessageFactionWarSettlementWinner".Translate(ruin, ruin.Faction, ruin.Faction == f1 ? f2 : f1) + "\n\n";
                GetByFaction(ruin.Faction).history += "HistoryDate".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks)) + "MessageFactionWarSettlementNukedLoser".Translate(ruin, ruin.Faction == f1 ? f2 : f1) + "\n\n";
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + "MessageFactionWarSettlementNukedHistory".Translate(ruin.Faction == f1 ? f2 : f1, ruin, ruin.Faction) + "\n\n";
                return;
            }
            // Factories sabotaged - background - 0.001%
            if (chance < 660)
            {
                Faction spy = Rand.Chance(0.5f) ? f2 : f1;

                GetByFaction(spy).resources -= MINOR_EVENT_RESOURCE_VALUE;
                war.warHistory += "HistoryDateRecent".Translate(5500 + (Find.TickManager.TicksGame / Global.YearInTicks), GenLocalDate.DayOfYear(Find.AnyPlayerHomeMap)) + FE_GrammarUtility.WarEvent(spy, spy == f1 ? f2 : f1) + "\n\n";
                return;
            }
        }