//The same as TileFinder.TryFindNewSiteTile EXCEPT
        // this one finds locations with caves
        public static bool TryFindNewSiteTile(out int tile, int minDist = 8, int maxDist                = 30,
                                              bool allowCaravans        = false, bool preferCloserTiles = true, int nearThisTile = -1)
        {
            Func <int, int> findTile = delegate(int root)
            {
                int             minDist2  = minDist;
                int             maxDist2  = maxDist;
                Predicate <int> validator = (int x) =>
                                            !Find.WorldObjects.AnyWorldObjectAt(x) &&
                                            Find.World.HasCaves(x) && TileFinder.IsValidTileForNewSettlement(x, null);
                bool preferCloserTiles2 = preferCloserTiles;
                int  result;
                if (TileFinder.TryFindPassableTileWithTraversalDistance(root, minDist2, maxDist2, out result, validator,
                                                                        false, preferCloserTiles2))
                {
                    return(result);
                }
                return(-1);
            };
            int arg;

            if (nearThisTile != -1)
            {
                arg = nearThisTile;
            }
            else if (!TileFinder.TryFindRandomPlayerTile(out arg, allowCaravans, (int x) => findTile(x) != -1))
            {
                tile = -1;
                return(false);
            }
            tile = findTile(arg);
            return(tile != -1);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            int num = this.worldObject.Tile;

            if (num == -1)
            {
                if (!TileFinder.TryFindNewSiteTile(out num, 7, 27, false, true, -1))
                {
                    num = -1;
                }
            }
            else if (Find.WorldObjects.AnyWorldObjectAt(num))
            {
                if (!TileFinder.TryFindPassableTileWithTraversalDistance(num, 1, 50, out num, (int x) => !Find.WorldObjects.AnyWorldObjectAt(x), false, true, false))
                {
                    num = -1;
                }
            }
            if (num != -1)
            {
                this.worldObject.Tile = num;
                Find.WorldObjects.Add(this.worldObject);
                this.spawned = true;
            }
            return(this.spawned);
        }
Example #3
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = parms.target as Map;

            if (!TileFinder.TryFindPassableTileWithTraversalDistance(map.Tile, 3, 5, out int tile))
            {
                return(false);
            }

            if (!TryResolveFactions(out Pair <Faction, Faction> factionPair))
            {
                return(false);
            }

            PlaceBattle placeBattle = (PlaceBattle)WorldObjectMaker.MakeWorldObject(WorldObjectsDefOfLocal.PlaceBattle);

            placeBattle.Tile = tile;
            placeBattle.SetFaction(factionPair.First);
            placeBattle.SecondFaction = factionPair.Second;

            Find.WorldObjects.Add(placeBattle);

            SendStandardLetter(parms, placeBattle);

            return(true);
        }
Example #4
0
        public override void Notify_QuestSignalReceived(Signal signal)
        {
            base.Notify_QuestSignalReceived(signal);
            if (!(signal.tag == inSignal) || spawned)
            {
                return;
            }
            int tile = worldObject.Tile;

            if (tile == -1)
            {
                if (!TileFinder.TryFindNewSiteTile(out tile))
                {
                    tile = -1;
                }
            }
            else if (Find.WorldObjects.AnyWorldObjectAt(tile) && !TileFinder.TryFindPassableTileWithTraversalDistance(tile, 1, 50, out tile, (int x) => !Find.WorldObjects.AnyWorldObjectAt(x), ignoreFirstTilePassability: false, preferCloserTiles: true))
            {
                tile = -1;
            }
            if (tile != -1)
            {
                worldObject.Tile = tile;
                Find.WorldObjects.Add(worldObject);
                spawned = true;
            }
        }
Example #5
0
        //// Added for testing purposes...
        //private Site CreateSite(int tile, SitePartDef sitePart, int days, Faction siteFaction, List<Thing> items)
        //{
        //    WorldObjectDef woDef;
        //    float chance = Rand.Value;
        //    //if (chance < 0.5f)
        //    //    woDef = WorldObjectDefOf.AbandonedFactionBase;
        //    //else
        //        woDef = WorldObjectDefOf.Site;

        //    Site site = (Site)WorldObjectMaker.MakeWorldObject(woDef);
        //    //site.Tile = tile;
        //    site.core = DefDatabase<SiteCoreDef>.GetNamed("Anomaly_ItemStash");

        //    if (sitePart != null)
        //        site.parts.Add(sitePart);

        //    if (siteFaction != null)
        //        site.SetFaction(siteFaction);

        //    if (days > 0)
        //        site.GetComponent<TimeoutComp>().StartTimeout(days * 60000);

        //    if (items != null && items.Count > 0)
        //        site.GetComponent<ItemStashContentsComp>().contents.TryAddRangeOrTransfer(items);

        //    //Find.WorldObjects.Add(site);
        //    return site;
        //}


        // From RimWorld.Planet.TileFinder.TryFindNewSiteTile(..)
        private bool TryFindNewAnomalyTile(out int tile, int minDist = 7, int maxDist = 27, bool allowCaravans = false, bool preferCloserTiles = true, int nearThisTile = -1)
        {
            Func <int, int> findTile = delegate(int root)
            {
                int             minDist2           = minDist;
                int             maxDist2           = maxDist;
                Predicate <int> validator          = (int x) => !Find.WorldObjects.AnyWorldObjectAt(x) && TileFinder.IsValidTileForNewSettlement(x, null);
                TileFinderMode  preferCloserTiles2 = TileFinderMode.Random;
                if (preferCloserTiles)
                {
                    preferCloserTiles2 = TileFinderMode.Near;
                }
                int result = default(int);
                if (TileFinder.TryFindPassableTileWithTraversalDistance(root, minDist2, maxDist2, out result, validator, false, preferCloserTiles2))
                {
                    return(result);
                }
                return(-1);
            };
            int arg = default(int);

            if (nearThisTile != -1)
            {
                arg = nearThisTile;
            }
            else if (!TileFinder.TryFindRandomPlayerTile(out arg, allowCaravans, (Predicate <int>)((int x) => findTile(x) != -1)))
            {
                tile = -1;
                return(false);
            }
            tile = findTile(arg);
            return(tile != -1);
        }
Example #6
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Caravan caravan = parms.target as Caravan;
            bool    result;

            if (caravan == null)
            {
                result = false;
            }
            else
            {
                int  tile;
                Site site = (Site)WorldObjectMaker.MakeWorldObject(SiteDefOfReconAndDiscovery.RD_Adventure);
                TileFinder.TryFindPassableTileWithTraversalDistance(caravan.Tile, 1, 2, out tile, (int t) => !Find.WorldObjects.AnyMapParentAt(t), false);
                site.Tile = tile;
                Faction faction = Find.FactionManager.RandomEnemyFaction(true, false, true, TechLevel.Spacer);
                site.SetFaction(faction);

                site.AddPart(new SitePart(site, SiteDefOfReconAndDiscovery.RD_AbandonedColony, SiteDefOfReconAndDiscovery.RD_AbandonedColony.Worker.GenerateDefaultParams(StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction)));

                SitePart holoDisk = new SitePart(site, SiteDefOfReconAndDiscovery.RD_HoloDisk, SiteDefOfReconAndDiscovery.RD_HoloDisk.Worker.GenerateDefaultParams(StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction));
                holoDisk.hidden = true;
                site.parts.Add(holoDisk);
                if (Rand.Value < 0.3f)
                {
                    SitePart scatteredManhunters = new SitePart(site, SiteDefOfReconAndDiscovery.RD_ScatteredManhunters, SiteDefOfReconAndDiscovery.RD_ScatteredManhunters.Worker.GenerateDefaultParams
                                                                    (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction));
                    scatteredManhunters.hidden = true;
                    site.parts.Add(scatteredManhunters);
                }
                if (Rand.Value < 0.1f)
                {
                    SitePart mechanoidForces = new SitePart(site, SiteDefOfReconAndDiscovery.RD_MechanoidForces, SiteDefOfReconAndDiscovery.RD_MechanoidForces.Worker.GenerateDefaultParams
                                                                (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction));
                    mechanoidForces.hidden = true;
                    site.parts.Add(mechanoidForces);
                }
                if (Rand.Value < 0.05f)
                {
                    SitePart stargate = new SitePart(site, SiteDefOfReconAndDiscovery.RD_Stargate, SiteDefOfReconAndDiscovery.RD_Stargate.Worker.GenerateDefaultParams
                                                         (StorytellerUtility.DefaultSiteThreatPointsNow(), tile, faction));

                    stargate.hidden = true;

                    site.parts.Add(stargate);
                }
                Find.WorldObjects.Add(site);
                if (site == null)
                {
                    result = false;
                }
                else
                {
                    base.SendStandardLetter(parms, caravan);
                    result = true;
                }
            }
            return(result);
        }
        private int GetPlace(Map map)
        {
            int playerTile = map.Tile;

            TileFinder.TryFindPassableTileWithTraversalDistance(playerTile, 3, 6, out int result, (int x) => !Find.WorldObjects.AnyWorldObjectAt(x));

            return(result);
        }
        private int GetPlace(Map map)
        {
            int playerTile = map.Tile;

            TileFinder.TryFindPassableTileWithTraversalDistance(playerTile, 9, 20, out int result);

            return(result);
        }
        protected override bool CanFireNowSub(IncidentParms parms)
        {
            if (!TileFinder.TryFindPassableTileWithTraversalDistance(Find.AnyPlayerHomeMap.Tile, 7, 15, out int newTile, (int i) => !Find.WorldObjects.AnyWorldObjectAt(i)))
            {
                return(false);
            }

            return(true);
        }
Example #10
0
            static int FindTile(int root)
            {
                if (TileFinder.TryFindPassableTileWithTraversalDistance(root, 7, 66, out var num))
                {
                    return(num);
                }

                return(-1);
            }
Example #11
0
        // From RimWorld.Planet.TileFinder.TryFindNewSiteTile(..)
        private bool TryFindNewAnomalyTile(out int tile)
        {
            int rootTile;

            if (!TileFinder.TryFindRandomPlayerTile(out rootTile, true))
            {
                tile = -1;
                return(false);
            }
            return(TileFinder.TryFindPassableTileWithTraversalDistance(rootTile, AnomalyDistanceMin, (int)Props.radius, out tile, (int x) => !Find.WorldObjects.AnyWorldObjectAt(x), false));
        }
Example #12
0
        public override bool TryGiveQuestTo(Pawn questPawn, QuestDef questDef)
        {
            if (questPawn == null)
            {
                return(false);
            }

            EventSettings settings = Settings.EventsSettings["Quest_KillOrder"];

            if (!settings.Active)
            {
                return(false);
            }

            if (!TryResolveTwoFaction(out Faction faction1, out Faction faction2))
            {
                return(false);
            }

            if (!TileFinder.TryFindPassableTileWithTraversalDistance(Find.AnyPlayerHomeMap.Tile, 8, 24, out int result))
            {
                return(false);
            }

            Pawn pawn = PawnGenerator.GeneratePawn(PawnKindDefOf.AncientSoldier, faction2);

            Find.WorldPawns.PassToWorld(pawn);

            if (pawn == null)
            {
                return(false);
            }

            TargetPawn = pawn;

            Faction     = faction1;
            TicksToPass = Rand.Range(6, 12) * 60000;
            id          = QuestsManager.Communications.UniqueIdManager.GetNextQuestID();

            GenerateRewards();

            ShowInConsole = false;

            QuestsManager.Communications.AddQuestPawn(questPawn, this);
            QuestsManager.Communications.AddQuest(this);

            if (TargetPawn == null)
            {
                return(false);
            }

            return(true);
        }
        public override void PostMapRemove(Map map)
        {
            base.PostMapRemove(map);

            if (TileFinder.TryFindPassableTileWithTraversalDistance(Site.Tile, 3, 5, out int tile))
            {
                Site.Tile = tile;
                Visited   = true;

                ResetIcon();
            }
        }
 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);
 }
Example #15
0
 private bool TryFindDestinationTileActual(int rootTile, int minDist, out int tile)
 {
     for (int i = 0; i < 2; i++)
     {
         bool canTraverseImpassable = i == 1;
         if (TileFinder.TryFindPassableTileWithTraversalDistance(rootTile, minDist, 800, out tile, (int x) => !Find.WorldObjects.AnyWorldObjectAt(x) && Find.WorldGrid[x].biome.canBuildBase && Find.WorldGrid[x].biome.canAutoChoose, true, true, canTraverseImpassable))
         {
             return(true);
         }
     }
     tile = -1;
     return(false);
 }
Example #16
0
 internal bool TryFindHackingSourceTile()
 {
     if (this.alliedBase == null)
     {
         return(TileFinder.TryFindPassableTileWithTraversalDistance(this.rootMap.Tile, MinHackingWorldDistance, MaxHackingWorldDistance,
                                                                    out this.hackingSourceTile, preferCloserTiles: false));
     }
     else             //Find tile close to Allied base as well ...
     {
         return(TileFinder.TryFindPassableTileWithTraversalDistance(this.rootMap.Tile, MinHackingWorldDistance, MaxHackingWorldDistance,
                                                                    out this.hackingSourceTile, (x) => Find.WorldGrid.TraversalDistanceBetween(x, this.alliedBase.Tile) <= MaxHackingWorldDistance,
                                                                    preferCloserTiles: false));
     }
 }
Example #17
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            if (!TileFinder.TryFindPassableTileWithTraversalDistance(map.Tile, 10, 15, out int newTile))
            {
                return(false);
            }

            if (!Find.FactionManager.AllFactionsVisible.Any(x => {
                if (x == Faction.OfPlayer)
                {
                    return(false);
                }

                var relation = x.RelationKindWith(Faction.OfPlayer);

                if (relation == FactionRelationKind.Ally || relation == FactionRelationKind.Neutral)
                {
                    return(true);
                }

                return(false);
            }))
            {
                return(false);
            }

            var dialog = QuestsManager.Communications.MakeDialogFromIncident(def);

            FairPlace fairPlace = (FairPlace)WorldObjectMaker.MakeWorldObject(WorldObjectsDefOfLocal.FairPlace);

            fairPlace.Tile = newTile;
            fairPlace.SetFaction(Faction.OfPlayer);
            fairPlace.SetTimer(10);
            fairPlace.CommunicationDialog = dialog;
            DefDatabase <MapGeneratorBlueprints.MapGenerator.MapGeneratorDef> .AllDefsListForReading.Where(gen => gen.targetTags != null && gen.targetTags.Contains(fairPlace.MapGeneratorTag)).TryRandomElementByWeight(w => w.Commonality, out fairPlace.MapGenerator);

            QuestsManager.Communications.AddCommunication(dialog);

            Find.WorldObjects.Add(fairPlace);

            SendStandardLetter(parms, fairPlace);

            return(true);
        }
Example #18
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = Find.AnyPlayerHomeMap;

            if (!TileFinder.TryFindPassableTileWithTraversalDistance(map.Tile, 5, 7, out int newTile))
            {
                return(false);
            }

            SkillDef compSkill = DefDatabase <SkillDef> .GetRandom();

            int level = Rand.Range(8, 20);

            WorldObject_Competitions place = (WorldObject_Competitions)WorldObjectMaker.MakeWorldObject(WorldObjectsDefOfLocal.CompetitionsPlace);

            place.Tile = newTile;
            place.SetFaction(Faction.OfPlayer);
            place.CompetitionSkill = compSkill;
            place.CompetitionSkillLevelRequired = level;
            place.RewardCount = level * 140;
            place.TicksToEnd  = 5 * 60000;

            Find.WorldObjects.Add(place);

            string label       = def.label;
            string description = string.Format(def.letterText, compSkill.LabelCap, place.RewardCount, level);

            Find.LetterStack.ReceiveLetter(label, description, def.letterDef, new LookTargets(place));

            var dialog = QuestsManager.Communications.MakeDialogFromIncident(def, new List <CommOption>
            {
                new CommOption_CompetitionsPaid()
                {
                    WorldObject_Competitions = place
                }
            });

            dialog.Description = description;

            QuestsManager.Communications.AddCommunication(dialog);

            place.Dialog = dialog;

            return(true);
        }
Example #19
0
        public override void TakeQuestByQuester(QuestPawn quester, bool notify = true)
        {
            TileFinder.TryFindPassableTileWithTraversalDistance(Find.AnyPlayerHomeMap.Tile, 6, 24, out int result);

            QuestSite questPlace = (QuestSite)WorldObjectMaker.MakeWorldObject(QuestRim.WorldObjectDefOfLocal.QuestPlace);

            questPlace.Tile = result;
            questPlace.SetFaction(Faction);
            questPlace.Init(this);
            questPlace.RemoveAfterLeave = false;

            Target = questPlace;
            Site   = questPlace;

            Find.WorldObjects.Add(questPlace);

            base.TakeQuestByQuester(quester, notify);
        }
Example #20
0
        //The same as TileFinder.TryFindNewSiteTile EXCEPT
        // this one finds locations with caves
        public static bool TryFindNewSiteTile(out int tile, int minDist = 8, int maxDist                = 30,
                                              bool allowCaravans        = false, bool preferCloserTiles = true, int nearThisTile = -1)
        {
            int findTile(int root)
            {
                bool validator(int x)
                {
                    return(!Find.WorldObjects.AnyWorldObjectAt(x) && Find.World.HasCaves(x) &&
                           TileFinder.IsValidTileForNewSettlement(x));
                }

                var tileFinderMode = TileFinderMode.Near;

                if (!preferCloserTiles)
                {
                    tileFinderMode = TileFinderMode.Furthest;
                }

                if (TileFinder.TryFindPassableTileWithTraversalDistance(root, minDist, maxDist, out var result,
                                                                        validator,
                                                                        false, tileFinderMode))
                {
                    return(result);
                }

                return(-1);
            }

            int arg;

            if (nearThisTile != -1)
            {
                arg = nearThisTile;
            }
            else if (!TileFinder.TryFindRandomPlayerTile(out arg, allowCaravans, x => findTile(x) != -1))
            {
                tile = -1;
                return(false);
            }

            tile = findTile(arg);
            return(tile != -1);
        }
        public override void DoAction(EmailMessage message, EmailBox box, Pawn speaker)
        {
            if (!TileFinder.TryFindPassableTileWithTraversalDistance(Find.AnyPlayerHomeMap.Tile, 8, 20, out int result))
            {
                Log.Warning("Cannon find place, try again");
                return;
            }

            Faction traderFaction = Find.FactionManager.FirstFactionOfDef(FactionDefOfLocal.DarkNetTraders);

            Quest_Laboratory quest = new Quest_Laboratory();

            quest.TicksToPass = 10 * 60000;
            quest.Faction     = traderFaction;
            quest.id          = QuestsManager.Communications.UniqueIdManager.GetNextQuestID();
            quest.GenerateRewards(quest.GetQuestThingFilter(), new FloatRange(2000, 3500), new IntRange(5, 10), null, null);
            Thing silver = ThingMaker.MakeThing(ThingDefOf.Silver);

            silver.stackCount = Rand.Range(1000, 2000);
            quest.Rewards.Add(silver);

            QuestSite questPlace = (QuestSite)WorldObjectMaker.MakeWorldObject(QuestRim.WorldObjectDefOfLocal.QuestPlace);

            questPlace.Tile = result;
            questPlace.SetFaction(traderFaction);
            questPlace.Init(quest);
            questPlace.RemoveAfterLeave = false;

            quest.Target = questPlace;
            quest.Site   = questPlace;

            Find.WorldObjects.Add(questPlace);

            QuestsManager.Communications.AddQuest(quest, QuestsManager.Communications.MakeQuestLetter(quest, description: quest.Description, lookTarget: questPlace));

            var component = QuestsManager.Communications.Components.Where(x => x is EmailMessageTimeComp_QuestLaboratory).FirstOrDefault();

            if (component != null)
            {
                QuestsManager.Communications.RemoveComponent(component);
            }
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!TileFinder.TryFindPassableTileWithTraversalDistance(Find.AnyPlayerHomeMap.Tile, 7, 15, out int newTile, (int i) => !Find.WorldObjects.AnyWorldObjectAt(i)))
            {
                return(false);
            }

            if (GssRaids.GssFaction == null)
            {
                return(false);
            }

            DarkNet darkNet = Current.Game.GetComponent <DarkNet>();

            if (darkNet == null || darkNet.Traders == null)
            {
                return(false);
            }

            DarkNetTrader trader = darkNet.Traders.RandomElement();

            Quest_DarkNetKillInformator quest = new Quest_DarkNetKillInformator(trader.def);

            quest.GenerateRewards(quest.GetQuestThingFilter(), new FloatRange(1200, 2500), new IntRange(1, 4), null, null);

            quest.id          = QuestsManager.Communications.UniqueIdManager.GetNextQuestID();
            quest.TicksToPass = 10 * 60000;
            quest.Faction     = GssRaids.GssFaction;

            string title = string.Format(def.letterLabel, trader.def.LabelCap, quest.Faction.Name);
            string desc  = string.Format(def.letterText, trader.def.LabelCap, quest.Faction.Name);

            QuestSite site = QuestsHandler.CreateSiteFor(quest, newTile, quest.Faction);

            Find.WorldObjects.Add(site);

            QuestsManager.Communications.AddQuest(quest);

            Find.LetterStack.ReceiveLetter(title, desc, def.letterDef, new LookTargets(site));

            return(true);
        }
Example #23
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!TryResolveTwoFactions(out Faction alliedFaction, out Faction enemyFaction))
            {
                return(false);
            }

            if (enemyFaction.leader == null)
            {
                return(false);
            }

            if (!TileFinder.TryFindPassableTileWithTraversalDistance(Find.AnyPlayerHomeMap.Tile, 7, 16, out int result))
            {
                return(false);
            }

            Quest_KillLeader quest = new Quest_KillLeader(enemyFaction.leader, Rand.Range(11, 17));

            quest.Faction = alliedFaction;
            quest.id      = QuestsManager.Communications.UniqueIdManager.GetNextQuestID();
            quest.GenerateRewards(quest.GetQuestThingFilter(), new FloatRange(600, 800) * (float)enemyFaction.def.techLevel, new IntRange(1, 3), null, null);

            QuestSite questPlace = (QuestSite)WorldObjectMaker.MakeWorldObject(QuestRim.WorldObjectDefOfLocal.QuestPlace);

            questPlace.Tile = result;
            questPlace.SetFaction(alliedFaction);
            questPlace.Init(quest);
            questPlace.RemoveAfterLeave = false;

            quest.Target = questPlace;
            quest.Site   = questPlace;

            Find.WorldObjects.Add(questPlace);

            string description = string.Format(def.letterText, alliedFaction.Name, enemyFaction.leader.Name.ToString(), enemyFaction.Name);

            QuestsManager.Communications.AddQuest(quest, QuestsManager.Communications.MakeQuestLetter(quest, description: description, lookTarget: questPlace));

            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            DarkNet darkNet = Current.Game.GetComponent <DarkNet>();

            if (darkNet == null || darkNet.Traders == null)
            {
                return(false);
            }

            DarkNetTrader trader   = darkNet.Traders.RandomElement();
            Faction       attacker = Find.FactionManager.FirstFactionOfDef(MoreEvents.FactionDefOfLocal.Pirate);

            if (attacker == null || attacker.defeated)
            {
                return(false);
            }

            if (!TileFinder.TryFindPassableTileWithTraversalDistance(Find.AnyPlayerHomeMap.Tile, 5, 12, out int newTile, (int i) => !Find.WorldObjects.AnyWorldObjectAt(i)))
            {
                return(false);
            }

            Quest_DarkNetCaptureMaterials quest = new Quest_DarkNetCaptureMaterials(trader.def);

            quest.id          = QuestsManager.Communications.UniqueIdManager.GetNextQuestID();
            quest.TicksToPass = 7 * 60000;
            quest.Faction     = attacker;

            string title = string.Format(def.letterLabel, trader.def.LabelCap);
            string desc  = string.Format(def.letterText, trader.def.LabelCap);

            QuestSite site = QuestsHandler.CreateSiteFor(quest, newTile, quest.Faction);

            Find.WorldObjects.Add(site);

            QuestsManager.Communications.AddQuest(quest);

            Find.LetterStack.ReceiveLetter(title, desc, def.letterDef, new LookTargets(site));

            return(true);
        }
Example #25
0
        private bool tryFindTile(out int tile)
        {
            int findTile(int root)
            {
                bool validator(int x) => !Find.WorldObjects.AnyWorldObjectAt(x) && TileFinder.IsValidTileForNewSettlement(x, null) && (Find.WorldGrid[x].biome.defName == "CaveOasis" || Find.WorldGrid[x].biome.defName == "TunnelworldCave" || Find.WorldGrid[x].biome.defName == "CaveEntrance" || Find.WorldGrid[x].biome.defName == "InfestedMountains" || Find.WorldGrid[x].biome.defName == "DesertCanyon");

                if (TileFinder.TryFindPassableTileWithTraversalDistance(root, SiteTuning.ItemStashQuestSiteDistanceRange.min, SiteTuning.ItemStashQuestSiteDistanceRange.max, out int result, validator))
                {
                    return(result);
                }
                return(-1);
            }

            if (!TileFinder.TryFindRandomPlayerTile(out int arg, false, (int x) => findTile(x) != -1))
            {
                tile = -1;
                return(false);
            }
            tile = findTile(arg);
            return(tile != -1);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (Find.WorldObjects.Caravans.TryRandomElement(out Caravan caravan))
            {
                if (TileFinder.TryFindPassableTileWithTraversalDistance(caravan.Tile, 2, 5, out int tile))
                {
                    if (Find.FactionManager.AllFactionsVisible.Where(x => x != Faction.OfPlayer).TryRandomElement(out Faction faction))
                    {
                        MassBurialPlace massBurialPlace = (MassBurialPlace)WorldObjectMaker.MakeWorldObject(WorldObjectsDefOfLocal.MassBurialPlace);
                        massBurialPlace.Tile = tile;
                        massBurialPlace.SetFaction(faction);

                        Find.WorldObjects.Add(massBurialPlace);

                        SendStandardLetter(parms, massBurialPlace, faction.Name);
                    }
                }
            }

            return(true);
        }
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            if (!TryResolveTwoFaction(out Faction faction1, out Faction faction2))
            {
                return(false);
            }

            if (!TileFinder.TryFindPassableTileWithTraversalDistance(Find.AnyPlayerHomeMap.Tile, 7, 15, out int result))
            {
                return(false);
            }

            Pawn pawn = PawnGenerator.GeneratePawn(PawnKindDefOf.AncientSoldier, faction2);

            Find.WorldPawns.PassToWorld(pawn);

            Quest_KillOrder quest = new Quest_KillOrder(pawn, Rand.Range(10, 17));

            quest.Faction = faction1;
            quest.id      = QuestsManager.Communications.UniqueIdManager.GetNextQuestID();
            quest.GenerateRewards();

            QuestSite questPlace = (QuestSite)WorldObjectMaker.MakeWorldObject(QuestRim.WorldObjectDefOfLocal.QuestPlace);

            questPlace.Tile = result;
            questPlace.SetFaction(faction1);
            questPlace.Init(quest);
            questPlace.RemoveAfterLeave = false;

            quest.Target = questPlace;
            quest.Site   = questPlace;

            Find.WorldObjects.Add(questPlace);

            string description = string.Format(def.letterText, faction1.Name, pawn.Name.ToString(), faction2.Name);

            QuestsManager.Communications.AddQuest(quest, QuestsManager.Communications.MakeQuestLetter(quest, description: description, lookTarget: questPlace));

            return(true);
        }
Example #28
0
        public override bool TryGiveQuestTo(Pawn questPawn, QuestDef questDef)
        {
            EventSettings settings = Settings.EventsSettings["Quest_KillLeader"];

            if (!settings.Active)
            {
                return(false);
            }

            if (!TryResolveTwoFactions(out Faction alliedFaction, out Faction enemyFaction))
            {
                return(false);
            }

            if (enemyFaction.leader == null)
            {
                return(false);
            }

            if (!TileFinder.TryFindPassableTileWithTraversalDistance(Find.AnyPlayerHomeMap.Tile, 8, 20, out int result))
            {
                return(false);
            }

            Faction     = alliedFaction;
            TicksToPass = Rand.Range(8, 15) * 60000;
            id          = QuestsManager.Communications.UniqueIdManager.GetNextQuestID();

            TargetPawn = enemyFaction.leader;

            GenerateRewards(GetQuestThingFilter(), new FloatRange(600, 800) * (float)enemyFaction.def.techLevel, new IntRange(1, 3), null, null);

            ShowInConsole = false;

            QuestsManager.Communications.AddQuestPawn(questPawn, this);
            QuestsManager.Communications.AddQuest(this);

            return(true);
        }
Example #29
0
        public override void TakeQuestByQuester(QuestPawn quester, bool notify = true)
        {
            TileFinder.TryFindPassableTileWithTraversalDistance(Find.AnyPlayerHomeMap.Tile, 5, 12, out int newTile, (int i) => !Find.WorldObjects.AnyWorldObjectAt(i));

            LookTargets target = new LookTargets(newTile);

            Target = target;

            QuestSite questPlace = QuestsHandler.CreateSiteFor(this, newTile, Faction);

            Site = questPlace;

            Find.WorldObjects.Add(questPlace);

            ShowInConsole = true;

            TicksToPass = DaysRange.RandomInRange * 60000;

            if (notify)
            {
                Find.LetterStack.ReceiveLetter(QuestsManager.Communications.MakeQuestLetter(this, "TakeQuestFromPawnLetter".Translate(CardLabel), "TakeQuestFromPawnLetterDesc".Translate(CardLabel, Description)));
            }
        }
Example #30
0
 private bool TryFindDestinationTileActual(int rootTile, int minDist, out int tile)
 {
     return(TileFinder.TryFindPassableTileWithTraversalDistance(rootTile, minDist, 800, out tile, (int x) => !Find.WorldObjects.AnyWorldObjectAt(x) && Find.WorldGrid[x].biome.canBuildBase && Find.WorldGrid[x].biome.canAutoChoose, true, true));
 }