Beispiel #1
0
        public override void CompTick()
        {
            if (!MercenaryBattle_Active)
            {
                return;
            }
            if (Utilities.FactionsWar().GetWars().Where(w => w.AttackerFaction() == war.AttackerFaction() && w.DefenderFaction() == war.DefenderFaction()).Count() == 0)
            {
                Find.WorldObjects.Remove(parent);
                MercenaryBattle_Active = false;
                return;
            }
            if (!ParentHasMap)
            {
                if (parent.GetComponent <TimeoutComp>().Passed)
                {
                    askingFaction.TryAffectGoodwillWith(Faction.OfPlayer, -50);
                    Utilities.FactionsWar().GetByFaction(askingFaction).resources -= Utilities.FactionsWar().GetByFaction(askingFaction).resources *(3 / 4);
                }
                return;
            }

            for (int i = 0; i < 2; i++)
            {
                Faction f = i == 1 ? war.AttackerFaction() : war.DefenderFaction();
                if (((MapParent)parent).Map.mapPawns.SpawnedPawnsInFaction(f).Count(p => GenHostility.IsActiveThreatTo(p, f == war.AttackerFaction() ? war.DefenderFaction() : war.AttackerFaction())) == 0)
                {
                    BattleEnd(f, war.AttackerFaction() == f ? war.DefenderFaction() : war.AttackerFaction());
                    break;
                }
            }
        }
        public override void DoWindowContents(Rect inRect)
        {
            if (war == null)
            {
                Close(false);
            }
            // Title
            Text.Font   = GameFont.Medium;
            Text.Anchor = TextAnchor.UpperCenter;
            Rect rect2 = inRect.AtZero();

            rect2.height = 36f;
            rect2.xMin  += 9f;
            rect2.yMin  += 5f;
            var header = new Listing_Standard();

            header.Begin(rect2);
            header.Label("WindowWarOverview".Translate(war.AttackerFaction(), war.DefenderFaction()), 50);
            header.GapLine();
            header.End();

            DevModeSliders(inRect);

            // Defender resource box
            float faction1Resources = Utilities.FactionsWar().GetByFaction(war.DefenderFaction()).resources / Utilities.FactionsWar().MaxResourcesForFaction(war.DefenderFaction());

            GUI.color = Color.blue;
            Rect faction1Box = new Rect(inRect.x + factionBoxX, inRect.y + factionBoxY, inRect.xMax - factionBoxXMax, inRect.yMax - factionBoxYMax);

            Widgets.DrawBox(faction1Box, 5);
            Rect faction1 = new Rect(inRect.x + factionBoxX, inRect.y + factionBoxY + 109f * (1 - faction1Resources), inRect.xMax - factionBoxXMax, inRect.yMax - factionBoxYMax - 109f * (1 - faction1Resources));

            Widgets.DrawBoxSolid(faction1, new Color(0.19607843137f, 0.2627450980f, 1f, 1));
            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Small;
            GUI.color   = Color.white;
            Widgets.Label(faction1Box, war.DefenderFaction().Name + "'s Resources: " + Math.Round(faction1Resources * 100) + "%");
            Text.Font = GameFont.Small;

            //defender info

            Rect faction1Info = new Rect(inRect.x + factionBoxX, inRect.y + 220, inRect.xMax - factionBoxXMax, inRect.yMax - factionBoxYMax - 50);

            Text.Anchor = TextAnchor.UpperLeft;
            Faction faction = war.DefenderFaction();

            Widgets.Label(faction1Info, faction.GetInfoText());

            if (faction != null)
            {
                FactionRelationKind playerRelationKind = faction.PlayerRelationKind;
                GUI.color = playerRelationKind.GetColor();
                Widgets.Label(new Rect(faction1Info.x, faction1Info.y + Text.CalcHeight(faction.GetInfoText(), faction1Info.width) + Text.SpaceBetweenLines, faction1Info.width, 30f), playerRelationKind.GetLabel());
            }

            // attacker resource boxes
            float faction2Resources = Utilities.FactionsWar().GetByFaction(war.AttackerFaction()).resources / Utilities.FactionsWar().MaxResourcesForFaction(war.AttackerFaction());
            Rect  faction2Box       = new Rect(inRect.xMax - 230, inRect.y + factionBoxY, 210, inRect.yMax - factionBoxYMax);

            GUI.color = Color.red;
            Widgets.DrawBox(faction2Box, 5);
            Rect faction2 = new Rect(inRect.xMax - 230, inRect.y + factionBoxY + 109f * (1 - faction2Resources), 210, inRect.yMax - factionBoxYMax - 109f * (1 - faction2Resources));

            Widgets.DrawBoxSolid(faction2, new Color(0.8117647058f, 0f, 0.0588235f, 1));
            Text.Anchor = TextAnchor.MiddleCenter;
            Text.Font   = GameFont.Small;
            GUI.color   = Color.white;
            Widgets.Label(faction2Box, war.AttackerFaction().Name + "'s Resources: " + Math.Round(faction2Resources * 100) + "%");


            //attacker info
            Rect faction1Info2 = new Rect(inRect.xMax - 230, inRect.y + 220, 210, inRect.yMax - factionBoxYMax - 50);

            Text.Anchor = TextAnchor.UpperRight;
            Faction faction3 = war.AttackerFaction();

            Widgets.Label(faction1Info2, faction3.GetInfoText());

            if (faction3 != null)
            {
                FactionRelationKind playerRelationKind = faction3.PlayerRelationKind;
                GUI.color = playerRelationKind.GetColor();
                Widgets.Label(new Rect(faction1Info2.x, faction1Info2.y + Text.CalcHeight(faction.GetInfoText(), faction1Info2.width) + Text.SpaceBetweenLines, faction1Info2.width, 30f), playerRelationKind.GetLabel());
            }

            /*Text box*/
            Text.Font = GameFont.Small;
            Rect textRect = new Rect(inRect);

            Text.Anchor    = TextAnchor.MiddleCenter;
            GUI.color      = Color.white;
            textRect.xMin += 5;
            textRect.xMax -= 5;
            textRect.yMin += 300;
            textRect.yMax -= 50;
            Widgets.TextAreaScrollable(textRect, war.warHistory, ref scrollPosition, true);
            Text.Anchor = TextAnchor.UpperLeft;
            GUI.color   = Color.white;
        }
Beispiel #3
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!TryFindCaravanProximity(out Caravan caravan, out Settlement set) || !EndGame_Settings.FactionWar)
            {
                return(false);
            }
            List <Pawn> pawnsF1 = new List <Pawn>();
            List <Pawn> pawnsF2 = new List <Pawn>();
            War         war     = Utilities.FactionsWar().GetWars().FirstOrDefault(x => x.TryFindFactioninvolved(set.Faction) && (x.AttackerFaction().HostileTo(Faction.OfPlayer) || x.DefenderFaction().HostileTo(Faction.OfPlayer)));

            for (int i = 0; i < 2; i++)
            {
                List <PawnKindDef> kindDefs = new List <PawnKindDef>()
                {
                    DefDatabase <PawnKindDef> .GetNamed("Mercenary_Elite"),
                    DefDatabase <PawnKindDef> .GetNamed("Town_Guard"),
                    DefDatabase <PawnKindDef> .GetNamed("Grenadier_Destructive")
                };
                if (i == 0)
                {
                    pawnsF1 = Utilities.GenerateFighter(Math.Max(def.minThreatPoints, Utilities.FactionsWar().GetByFaction(war.DefenderFaction()).resources * 0.1f), null, kindDefs, null, war.DefenderFaction(), new IntVec3(), true);
                }
                else
                {
                    pawnsF2 = Utilities.GenerateFighter(Math.Max(def.minThreatPoints, Utilities.FactionsWar().GetByFaction(war.AttackerFaction()).resources * 0.1f), null, kindDefs, null, war.AttackerFaction(), new IntVec3(), true);
                }
            }
            if (pawnsF1.NullOrEmpty() || pawnsF2.NullOrEmpty())
            {
                return(false);
            }
            LongEventHandler.QueueLongEvent(() => DoExecute(parms, pawnsF1, pawnsF2), "GeneratingMapForNewEncounter", false, null);
            return(true);
        }
 private bool TryFindSuitableBattleLocation(out int tile, War war)
 {
     foreach (Settlement set in Find.WorldObjects.Settlements.Where(s => s.Faction == war.AttackerFaction() || s.Faction == war.DefenderFaction()))
     {
         if (Utilities.Reachable(Find.AnyPlayerHomeMap.Tile, set.Tile, 75))
         {
             return(!TileFinder.TryFindPassableTileWithTraversalDistance(set.Tile, 3, 20, out tile, x => !Find.WorldObjects.AnyWorldObjectAt(x)) ? false : true);
         }
     }
     tile = -1;
     return(false);
 }
        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;
            }
        }