public static void CheckDefeated(Settlement factionBase)
        {
            if (factionBase.Faction == Faction.OfPlayer)
            {
                return;
            }
            Map map = factionBase.Map;

            if (map == null || !IsDefeated(map, factionBase.Faction))
            {
                return;
            }
            DestroyedSettlement destroyedSettlement = (DestroyedSettlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.DestroyedSettlement);

            destroyedSettlement.Tile = factionBase.Tile;
            destroyedSettlement.SetFaction(factionBase.Faction);
            Find.WorldObjects.Add(destroyedSettlement);
            TimedDetectionRaids component = destroyedSettlement.GetComponent <TimedDetectionRaids>();

            component.CopyFrom(factionBase.GetComponent <TimedDetectionRaids>());
            component.SetNotifiedSilently();
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("LetterFactionBaseDefeated".Translate(factionBase.Label, component.DetectionCountdownTimeLeftString));
            if (!HasAnyOtherBase(factionBase))
            {
                factionBase.Faction.defeated = true;
                stringBuilder.AppendLine();
                stringBuilder.AppendLine();
                stringBuilder.Append("LetterFactionBaseDefeated_FactionDestroyed".Translate(factionBase.Faction.Name));
            }
            foreach (Faction allFaction in Find.FactionManager.AllFactions)
            {
                if (!allFaction.Hidden && !allFaction.IsPlayer && allFaction != factionBase.Faction && allFaction.HostileTo(factionBase.Faction))
                {
                    FactionRelationKind playerRelationKind = allFaction.PlayerRelationKind;
                    if (allFaction.TryAffectGoodwillWith(Faction.OfPlayer, 20, canSendMessage: false, canSendHostilityLetter: false))
                    {
                        stringBuilder.AppendLine();
                        stringBuilder.AppendLine();
                        stringBuilder.Append("RelationsWith".Translate(allFaction.Name) + ": " + 20.ToStringWithSign());
                        allFaction.TryAppendRelationKindChangedInfo(stringBuilder, playerRelationKind, allFaction.PlayerRelationKind);
                    }
                }
            }
            Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseDefeated".Translate(), stringBuilder.ToString(), LetterDefOf.PositiveEvent, new GlobalTargetInfo(factionBase.Tile), factionBase.Faction);
            map.info.parent = destroyedSettlement;
            factionBase.Destroy();
            TaleRecorder.RecordTale(TaleDefOf.CaravanAssaultSuccessful, map.mapPawns.FreeColonists.RandomElement());
        }
Example #2
0
        public static void CheckDefeated(Settlement factionBase)
        {
            if (factionBase.Faction == Faction.OfPlayer)
            {
                return;
            }
            Map map = factionBase.Map;

            if (map == null || !SettlementDefeatUtility.IsDefeated(map, factionBase.Faction))
            {
                return;
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("LetterFactionBaseDefeated".Translate(factionBase.Label, TimedForcedExit.GetForceExitAndRemoveMapCountdownTimeLeftString(60000)));
            if (!SettlementDefeatUtility.HasAnyOtherBase(factionBase))
            {
                factionBase.Faction.defeated = true;
                stringBuilder.AppendLine();
                stringBuilder.AppendLine();
                stringBuilder.Append("LetterFactionBaseDefeated_FactionDestroyed".Translate(factionBase.Faction.Name));
            }
            foreach (Faction current in Find.FactionManager.AllFactions)
            {
                if (!current.def.hidden && !current.IsPlayer && current != factionBase.Faction && current.HostileTo(factionBase.Faction))
                {
                    FactionRelationKind playerRelationKind = current.PlayerRelationKind;
                    if (current.TryAffectGoodwillWith(Faction.OfPlayer, 20, false, false, null, null))
                    {
                        stringBuilder.AppendLine();
                        stringBuilder.AppendLine();
                        stringBuilder.Append("RelationsWith".Translate(current.Name) + ": " + 20.ToStringWithSign());
                        current.TryAppendRelationKindChangedInfo(stringBuilder, playerRelationKind, current.PlayerRelationKind, null);
                    }
                }
            }
            Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseDefeated".Translate(), stringBuilder.ToString(), LetterDefOf.PositiveEvent, new GlobalTargetInfo(factionBase.Tile), factionBase.Faction, null);
            DestroyedSettlement destroyedSettlement = (DestroyedSettlement)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.DestroyedSettlement);

            destroyedSettlement.Tile = factionBase.Tile;
            Find.WorldObjects.Add(destroyedSettlement);
            map.info.parent = destroyedSettlement;
            Find.WorldObjects.Remove(factionBase);
            destroyedSettlement.GetComponent <TimedForcedExit>().StartForceExitAndRemoveMapCountdown();
            TaleRecorder.RecordTale(TaleDefOf.CaravanAssaultSuccessful, new object[]
            {
                map.mapPawns.FreeColonists.RandomElement <Pawn>()
            });
        }
Example #3
0
        public static Site MakeSite(SiteCoreDef core, IEnumerable <SitePartDef> siteParts, int tile, Faction faction, bool ifHostileThenMustRemainHostile = true, float?threatPoints = null)
        {
            Site site = (Site)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Site);

            site.Tile = tile;
            site.SetFaction(faction);
            if (ifHostileThenMustRemainHostile && faction != null && faction.HostileTo(Faction.OfPlayer))
            {
                site.factionMustRemainHostile = true;
            }
            float num = (!threatPoints.HasValue) ? StorytellerUtility.DefaultSiteThreatPointsNow() : threatPoints.Value;

            site.desiredThreatPoints = num;
            int num2 = 0;

            if (core.wantsThreatPoints)
            {
                num2++;
            }
            if (siteParts != null)
            {
                foreach (SitePartDef current in siteParts)
                {
                    if (current.wantsThreatPoints)
                    {
                        num2++;
                    }
                }
            }
            float num3           = (num2 == 0) ? 0f : (num / (float)num2);
            float myThreatPoints = (!core.wantsThreatPoints) ? 0f : num3;

            site.core = new SiteCore(core, core.Worker.GenerateDefaultParams(site, myThreatPoints));
            if (siteParts != null)
            {
                foreach (SitePartDef current2 in siteParts)
                {
                    float myThreatPoints2 = (!current2.wantsThreatPoints) ? 0f : num3;
                    site.parts.Add(new SitePart(current2, current2.Worker.GenerateDefaultParams(site, myThreatPoints2)));
                }
            }
            return(site);
        }
        public static Site MakeSite(SiteCoreDef core, IEnumerable <SitePartDef> siteParts, Faction faction, bool ifHostileThenMustRemainHostile = true)
        {
            Site site = (Site)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Site);

            site.core = new SiteCore(core, core.Worker.GenerateDefaultParams());
            site.SetFaction(faction);
            if (siteParts != null)
            {
                foreach (SitePartDef sitePartDef in siteParts)
                {
                    site.parts.Add(new SitePart(sitePartDef, sitePartDef.Worker.GenerateDefaultParams()));
                }
            }
            if (ifHostileThenMustRemainHostile && faction != null && faction.HostileTo(Faction.OfPlayer))
            {
                site.factionMustRemainHostile = true;
            }
            return(site);
        }
Example #5
0
        public static void CheckDefeated(FactionBase factionBase)
        {
            if (factionBase.Faction == Faction.OfPlayer)
            {
                return;
            }
            Map map = factionBase.Map;

            if (map == null || !FactionBaseDefeatUtility.IsDefeated(map, factionBase.Faction))
            {
                return;
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.Append("LetterFactionBaseDefeated".Translate(new object[]
            {
                factionBase.Label,
                TimedForcedExit.GetForceExitAndRemoveMapCountdownTimeLeftString(60000)
            }));
            if (!FactionBaseDefeatUtility.HasAnyOtherBase(factionBase))
            {
                factionBase.Faction.defeated = true;
                stringBuilder.AppendLine();
                stringBuilder.AppendLine();
                stringBuilder.Append("LetterFactionBaseDefeated_FactionDestroyed".Translate(new object[]
                {
                    factionBase.Faction.Name
                }));
            }
            Find.LetterStack.ReceiveLetter("LetterLabelFactionBaseDefeated".Translate(), stringBuilder.ToString(), LetterDefOf.PositiveEvent, new GlobalTargetInfo(factionBase.Tile), null);
            DestroyedFactionBase destroyedFactionBase = (DestroyedFactionBase)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.DestroyedFactionBase);

            destroyedFactionBase.Tile = factionBase.Tile;
            Find.WorldObjects.Add(destroyedFactionBase);
            map.info.parent = destroyedFactionBase;
            Find.WorldObjects.Remove(factionBase);
            destroyedFactionBase.GetComponent <TimedForcedExit>().StartForceExitAndRemoveMapCountdown();
            TaleRecorder.RecordTale(TaleDefOf.CaravanAssaultSuccessful, new object[]
            {
                map.mapPawns.FreeColonists.RandomElement <Pawn>()
            });
        }
Example #6
0
        public static Site MakeSite(IEnumerable <SitePartDefWithParams> siteParts, int tile, Faction faction, bool ifHostileThenMustRemainHostile = true)
        {
            Site site = (Site)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Site);

            site.Tile = tile;
            site.SetFaction(faction);
            if (ifHostileThenMustRemainHostile && faction != null && faction.HostileTo(Faction.OfPlayer))
            {
                site.factionMustRemainHostile = true;
            }
            if (siteParts != null)
            {
                foreach (SitePartDefWithParams sitePart in siteParts)
                {
                    site.AddPart(new SitePart(site, sitePart.def, sitePart.parms));
                }
            }
            site.desiredThreatPoints = site.ActualThreatPoints;
            return(site);
        }
Example #7
0
        private bool TrySplitCaravan()
        {
            List <Pawn> pawns = TransferableUtility.GetPawnsFromTransferables(this.transferables);

            if (!this.CheckForErrors(pawns))
            {
                return(false);
            }
            for (int i = 0; i < pawns.Count; i++)
            {
                CaravanInventoryUtility.MoveAllInventoryToSomeoneElse(pawns[i], this.caravan.PawnsListForReading, pawns);
            }
            Caravan caravan = (Caravan)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Caravan);

            caravan.Tile = this.caravan.Tile;
            caravan.SetFaction(this.caravan.Faction);
            caravan.Name = CaravanNameGenerator.GenerateCaravanName(caravan);
            Find.WorldObjects.Add(caravan);
            for (int j = 0; j < pawns.Count; j++)
            {
                this.caravan.RemovePawn(pawns[j]);
                caravan.AddPawn(pawns[j], true);
            }
            this.transferables.RemoveAll((TransferableOneWay x) => x.AnyThing is Pawn);
            for (int k = 0; k < this.transferables.Count; k++)
            {
                TransferableUtility.TransferNoSplit(this.transferables[k].things, this.transferables[k].CountToTransfer, delegate(Thing thing, int numToTake)
                {
                    Pawn ownerOf = CaravanInventoryUtility.GetOwnerOf(this.caravan, thing);
                    if (ownerOf == null)
                    {
                        Log.Error("Error while splitting a caravan: Thing " + thing + " has no owner. Where did it come from then?");
                    }
                    else
                    {
                        CaravanInventoryUtility.MoveInventoryToSomeoneElse(ownerOf, thing, pawns, null, numToTake);
                    }
                }, true, true);
            }
            return(true);
        }
Example #8
0
        public static Caravan MakeCaravan(IEnumerable <Pawn> pawns, Faction faction, int startingTile, bool addToWorldPawnsIfNotAlready)
        {
            if (startingTile < 0 && addToWorldPawnsIfNotAlready)
            {
                Log.Warning("Tried to create a caravan but chose not to spawn a caravan but pass pawns to world. This can cause bugs because pawns can be discarded.", false);
            }
            CaravanMaker.tmpPawns.Clear();
            CaravanMaker.tmpPawns.AddRange(pawns);
            Caravan caravan = (Caravan)WorldObjectMaker.MakeWorldObject(WorldObjectDefOf.Caravan);

            if (startingTile >= 0)
            {
                caravan.Tile = startingTile;
            }
            caravan.SetFaction(faction);
            if (startingTile >= 0)
            {
                Find.WorldObjects.Add(caravan);
            }
            for (int i = 0; i < CaravanMaker.tmpPawns.Count; i++)
            {
                Pawn pawn = CaravanMaker.tmpPawns[i];
                if (pawn.Dead)
                {
                    Log.Warning("Tried to form a caravan with a dead pawn " + pawn, false);
                }
                else
                {
                    caravan.AddPawn(pawn, addToWorldPawnsIfNotAlready);
                    if (addToWorldPawnsIfNotAlready && !pawn.IsWorldPawn())
                    {
                        Find.WorldPawns.PassToWorld(pawn, PawnDiscardDecideMode.Decide);
                    }
                }
            }
            caravan.Name = CaravanNameGenerator.GenerateCaravanName(caravan);
            CaravanMaker.tmpPawns.Clear();
            caravan.SetUniqueId(Find.UniqueIDsManager.GetNextCaravanID());
            return(caravan);
        }