Example #1
0
        public static void Notify_ThingChanged(Thing thing)
        {
            if (debugDrawLord == null)
            {
                return;
            }
            CheckInitDebugDrawGrid();
            if (thing.def.category != ThingCategory.Building && thing.def.category != ThingCategory.Item && thing.def.passability != Traversability.Impassable)
            {
                return;
            }
            if (thing.def.passability == Traversability.Impassable)
            {
                debugDrawLord = null;
                return;
            }
            int   num  = GenRadial.NumCellsInRadius(8f);
            float num2 = StealAIUtility.StartStealingMarketValueThreshold(debugDrawLord);

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec = thing.Position + GenRadial.RadialPattern[i];
                if (intVec.InBounds(thing.Map))
                {
                    debugDrawGrid[intVec] = TotalMarketValueAround(intVec, Find.CurrentMap, debugDrawLord.ownedPawns.Count) > num2;
                }
            }
        }
        protected override Job TryGiveJob(Pawn pawn)
        {
            IntVec3 c;
            Job     result;
            Thing   thing;

            if (!RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
            {
                result = null;
            }
            else if (StealAIUtility.TryFindBestItemToSteal(pawn.Position, pawn.Map, 12f, out thing, pawn, null) && !GenAI.InDangerousCombat(pawn))
            {
                result = new Job(JobDefOf.Steal)
                {
                    targetA = thing,
                    targetB = c,
                    count   = Mathf.Min(thing.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity, true) / thing.def.VolumePerUnit))
                };
            }
            else
            {
                result = null;
            }
            return(result);
        }
        public static bool TryFindBestItemToSteal(IntVec3 root, Map map, float maxDist, out Thing item, Pawn thief, List <Thing> disallowed = null)
        {
            if (thief != null && !thief.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                item = null;
                return(false);
            }
            if ((thief != null && !map.reachability.CanReachMapEdge(thief.Position, TraverseParms.For(thief, Danger.Some, TraverseMode.ByPawn, false))) || (thief == null && !map.reachability.CanReachMapEdge(root, TraverseParms.For(TraverseMode.PassDoors, Danger.Some, false))))
            {
                item = null;
                return(false);
            }
            Predicate <Thing> predicate      = (Thing t) => (thief == null || thief.CanReserve(t, 1, -1, null, false)) && (disallowed == null || !disallowed.Contains(t)) && t.def.stealable && !t.IsBurning();
            ThingRequest      thingReq       = ThingRequest.ForGroup(ThingRequestGroup.HaulableEverOrMinifiable);
            PathEndMode       peMode         = PathEndMode.ClosestTouch;
            TraverseParms     traverseParams = TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Some, false);
            Predicate <Thing> validator      = predicate;

            if (StealAIUtility.< > f__mg$cache0 == null)
            {
                StealAIUtility.< > f__mg$cache0 = new Func <Thing, float>(StealAIUtility.GetValue);
            }
            item = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(root, map, thingReq, peMode, traverseParams, maxDist, validator, StealAIUtility.< > f__mg$cache0, 15, 15);
            if (item != null && StealAIUtility.GetValue(item) < 320f)
            {
                item = null;
            }
            return(item != null);
        }
Example #4
0
        public static bool TryFindBestItemToSteal(IntVec3 root, Map map, float maxDist, out Thing item, Pawn thief, List <Thing> disallowed = null)
        {
            bool result;

            if (thief != null && !thief.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                item   = null;
                result = false;
            }
            else if ((thief != null && !map.reachability.CanReachMapEdge(thief.Position, TraverseParms.For(thief, Danger.Some, TraverseMode.ByPawn, false))) || (thief == null && !map.reachability.CanReachMapEdge(root, TraverseParms.For(TraverseMode.PassDoors, Danger.Some, false))))
            {
                item   = null;
                result = false;
            }
            else
            {
                Predicate <Thing> validator = (Thing t) => (thief == null || thief.CanReserve(t, 1, -1, null, false)) && (disallowed == null || !disallowed.Contains(t)) && t.def.stealable && !t.IsBurning();
                item = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(root, map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEverOrMinifiable), PathEndMode.ClosestTouch, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Some, false), maxDist, validator, (Thing x) => StealAIUtility.GetValue(x), 15, 15);
                if (item != null && StealAIUtility.GetValue(item) < 320f)
                {
                    item = null;
                }
                result = (item != null);
            }
            return(result);
        }
        public virtual void MakeLords(IncidentParms parms, List <Pawn> pawns)
        {
            Map map = (Map)parms.target;
            List <List <Pawn> > list = IncidentParmsUtility.SplitIntoGroups(pawns, parms.pawnGroups);
            int @int = Rand.Int;

            for (int i = 0; i < list.Count; i++)
            {
                List <Pawn> list2 = list[i];
                Lord        lord  = LordMaker.MakeNewLord(parms.faction, this.MakeLordJob(parms, map, list2, @int), map, list2);
                if (DebugViewSettings.drawStealDebug && parms.faction.HostileTo(Faction.OfPlayer))
                {
                    Log.Message(string.Concat(new object[]
                    {
                        "Market value threshold to start stealing (raiders=",
                        lord.ownedPawns.Count,
                        "): ",
                        StealAIUtility.StartStealingMarketValueThreshold(lord),
                        " (colony wealth=",
                        map.wealthWatcher.WealthTotal,
                        ")"
                    }), false);
                }
            }
        }
Example #6
0
        private static float TotalMarketValueAround(IntVec3 center, Map map, int pawnsCount)
        {
            if (center.Impassable(map))
            {
                return(0f);
            }
            float num = 0f;

            tmpToSteal.Clear();
            for (int i = 0; i < pawnsCount; i++)
            {
                IntVec3 intVec = center + GenRadial.RadialPattern[i];
                if (!intVec.InBounds(map) || intVec.Impassable(map) || !GenSight.LineOfSight(center, intVec, map))
                {
                    intVec = center;
                }
                if (StealAIUtility.TryFindBestItemToSteal(intVec, map, 7f, out var item, null, tmpToSteal))
                {
                    num += StealAIUtility.GetValue(item);
                    tmpToSteal.Add(item);
                }
            }
            tmpToSteal.Clear();
            return(num);
        }
Example #7
0
        private static float TotalMarketValueAround(IntVec3 center, Map map, int pawnsCount)
        {
            if (center.Impassable(map))
            {
                return(0f);
            }
            float num = 0f;

            StealAIDebugDrawer.tmpToSteal.Clear();
            for (int i = 0; i < pawnsCount; i++)
            {
                IntVec3 intVec = center + GenRadial.RadialPattern[i];
                if (!intVec.InBounds(map) || intVec.Impassable(map) || !GenSight.LineOfSight(center, intVec, map, false, null, 0, 0))
                {
                    intVec = center;
                }
                Thing thing = default(Thing);
                if (StealAIUtility.TryFindBestItemToSteal(intVec, map, 7f, out thing, (Pawn)null, StealAIDebugDrawer.tmpToSteal))
                {
                    num += StealAIUtility.GetValue(thing);
                    StealAIDebugDrawer.tmpToSteal.Add(thing);
                }
            }
            StealAIDebugDrawer.tmpToSteal.Clear();
            return(num);
        }
 protected override bool TryFindGoodOpportunisticTaskTarget(Pawn pawn, out Thing target, List <Thing> alreadyTakenTargets)
 {
     if (pawn.mindState.duty != null && pawn.mindState.duty.def == this.DutyDef && pawn.carryTracker.CarriedThing != null)
     {
         target = pawn.carryTracker.CarriedThing;
         return(true);
     }
     return(StealAIUtility.TryFindBestItemToSteal(pawn.Position, pawn.Map, 7f, out target, pawn, alreadyTakenTargets));
 }
Example #9
0
 protected override Job TryGiveJob(Pawn pawn)
 {
     if (!RCellFinder.TryFindBestExitSpot(pawn, out IntVec3 spot))
     {
         return(null);
     }
     if (StealAIUtility.TryFindBestItemToSteal(pawn.Position, pawn.Map, 12f, out Thing item, pawn) && !GenAI.InDangerousCombat(pawn))
     {
         Job job = new Job(JobDefOf.Steal);
         job.targetA = item;
         job.targetB = spot;
         job.count   = Mathf.Min(item.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity) / item.def.VolumePerUnit));
         return(job);
     }
     return(null);
 }
        public static bool TryFindBestItemToSteal(IntVec3 root, Map map, float maxDist, out Thing item, Pawn thief, List <Thing> disallowed = null)
        {
            if (thief != null && !thief.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation))
            {
                item = null;
                return(false);
            }
            if (thief != null && !map.reachability.CanReachMapEdge(thief.Position, TraverseParms.For(thief, Danger.Some, TraverseMode.ByPawn, false)))
            {
                goto IL_009d;
            }
            if (thief == null && !map.reachability.CanReachMapEdge(root, TraverseParms.For(TraverseMode.PassDoors, Danger.Some, false)))
            {
                goto IL_009d;
            }
            Predicate <Thing> validator = delegate(Thing t)
            {
                if (thief != null && !thief.CanReserve(t, 1, -1, null, false))
                {
                    return(false);
                }
                if (disallowed != null && disallowed.Contains(t))
                {
                    return(false);
                }
                if (!t.def.stealable)
                {
                    return(false);
                }
                if (t.IsBurning())
                {
                    return(false);
                }
                return(true);
            };

            item = GenClosest.ClosestThing_Regionwise_ReachablePrioritized(root, map, ThingRequest.ForGroup(ThingRequestGroup.HaulableEverOrMinifiable), PathEndMode.ClosestTouch, TraverseParms.For(TraverseMode.NoPassClosedDoors, Danger.Some, false), maxDist, validator, StealAIUtility.GetValue, 15, 15);
            if (item != null && StealAIUtility.GetValue(item) < 320.0)
            {
                item = null;
            }
            return(item != null);

IL_009d:
            item = null;
            return(false);
        }
        public static float TotalMarketValueAround(List <Pawn> pawns)
        {
            float num = 0f;

            StealAIUtility.tmpToSteal.Clear();
            for (int i = 0; i < pawns.Count; i++)
            {
                Thing thing = default(Thing);
                if (pawns[i].Spawned && StealAIUtility.TryFindBestItemToSteal(pawns[i].Position, pawns[i].Map, 7f, out thing, pawns[i], StealAIUtility.tmpToSteal))
                {
                    num += StealAIUtility.GetValue(thing);
                    StealAIUtility.tmpToSteal.Add(thing);
                }
            }
            StealAIUtility.tmpToSteal.Clear();
            return(num);
        }
 public override bool ActivateOn(Lord lord, TriggerSignal signal)
 {
     if (signal.type == TriggerSignalType.Tick && Find.TickManager.TicksGame % 120 == 0)
     {
         if (TutorSystem.TutorialMode)
         {
             return(false);
         }
         if (Find.TickManager.TicksGame - lord.lastPawnHarmTick > 300)
         {
             float num  = StealAIUtility.TotalMarketValueAround(lord.ownedPawns);
             float num2 = StealAIUtility.StartStealingMarketValueThreshold(lord);
             return(num > num2);
         }
     }
     return(false);
 }
        public static void DebugDraw()
        {
            if (!DebugViewSettings.drawStealDebug)
            {
                StealAIDebugDrawer.debugDrawLord = null;
                return;
            }
            Lord lord = StealAIDebugDrawer.debugDrawLord;

            StealAIDebugDrawer.debugDrawLord = StealAIDebugDrawer.FindHostileLord();
            if (StealAIDebugDrawer.debugDrawLord == null)
            {
                return;
            }
            StealAIDebugDrawer.CheckInitDebugDrawGrid();
            float num = StealAIUtility.StartStealingMarketValueThreshold(StealAIDebugDrawer.debugDrawLord);

            if (lord != StealAIDebugDrawer.debugDrawLord)
            {
                foreach (IntVec3 intVec in Find.CurrentMap.AllCells)
                {
                    StealAIDebugDrawer.debugDrawGrid[intVec] = (StealAIDebugDrawer.TotalMarketValueAround(intVec, Find.CurrentMap, StealAIDebugDrawer.debugDrawLord.ownedPawns.Count) > num);
                }
            }
            foreach (IntVec3 c in Find.CurrentMap.AllCells)
            {
                if (StealAIDebugDrawer.debugDrawGrid[c])
                {
                    CellRenderer.RenderCell(c, 0.5f);
                }
            }
            StealAIDebugDrawer.tmpToSteal.Clear();
            for (int i = 0; i < StealAIDebugDrawer.debugDrawLord.ownedPawns.Count; i++)
            {
                Pawn  pawn = StealAIDebugDrawer.debugDrawLord.ownedPawns[i];
                Thing thing;
                if (StealAIUtility.TryFindBestItemToSteal(pawn.Position, pawn.Map, 7f, out thing, pawn, StealAIDebugDrawer.tmpToSteal))
                {
                    GenDraw.DrawLineBetween(pawn.TrueCenter(), thing.TrueCenter());
                    StealAIDebugDrawer.tmpToSteal.Add(thing);
                }
            }
            StealAIDebugDrawer.tmpToSteal.Clear();
        }
Example #14
0
        public static void DebugDraw()
        {
            if (!DebugViewSettings.drawStealDebug)
            {
                debugDrawLord = null;
                return;
            }
            Lord lord = debugDrawLord;

            debugDrawLord = FindHostileLord();
            if (debugDrawLord == null)
            {
                return;
            }
            CheckInitDebugDrawGrid();
            float num = StealAIUtility.StartStealingMarketValueThreshold(debugDrawLord);

            if (lord != debugDrawLord)
            {
                foreach (IntVec3 allCell in Find.CurrentMap.AllCells)
                {
                    debugDrawGrid[allCell] = TotalMarketValueAround(allCell, Find.CurrentMap, debugDrawLord.ownedPawns.Count) > num;
                }
            }
            foreach (IntVec3 allCell2 in Find.CurrentMap.AllCells)
            {
                if (debugDrawGrid[allCell2])
                {
                    CellRenderer.RenderCell(allCell2);
                }
            }
            tmpToSteal.Clear();
            for (int i = 0; i < debugDrawLord.ownedPawns.Count; i++)
            {
                Pawn pawn = debugDrawLord.ownedPawns[i];
                if (StealAIUtility.TryFindBestItemToSteal(pawn.Position, pawn.Map, 7f, out var item, pawn, tmpToSteal))
                {
                    GenDraw.DrawLineBetween(pawn.TrueCenter(), item.TrueCenter());
                    tmpToSteal.Add(item);
                }
            }
            tmpToSteal.Clear();
        }
Example #15
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            IntVec3 c = default(IntVec3);

            if (!RCellFinder.TryFindBestExitSpot(pawn, out c, TraverseMode.ByPawn))
            {
                return(null);
            }
            Thing thing = default(Thing);

            if (StealAIUtility.TryFindBestItemToSteal(pawn.Position, pawn.Map, 12f, out thing, pawn, (List <Thing>)null) && !GenAI.InDangerousCombat(pawn))
            {
                Job job = new Job(JobDefOf.Steal);
                job.targetA = thing;
                job.targetB = c;
                job.count   = Mathf.Min(thing.stackCount, (int)(pawn.GetStatValue(StatDefOf.CarryingCapacity, true) / thing.def.VolumePerUnit));
                return(job);
            }
            return(null);
        }
Example #16
0
 private static float <TryFindBestItemToSteal> m__0(Thing x)
 {
     return(StealAIUtility.GetValue(x));
 }
Example #17
0
        protected override bool TryExecuteWorker(IncidentParms parms)
        {
            Map map = (Map)parms.target;

            this.ResolveRaidPoints(parms);
            if (!this.TryResolveRaidFaction(parms))
            {
                return(false);
            }
            this.ResolveRaidStrategy(parms);
            this.ResolveRaidArriveMode(parms);
            if (!this.ResolveRaidSpawnCenter(parms))
            {
                return(false);
            }
            IncidentParmsUtility.AdjustPointsForGroupArrivalParams(parms);
            PawnGroupMakerParms defaultPawnGroupMakerParms = IncidentParmsUtility.GetDefaultPawnGroupMakerParms(parms, false);
            List <Pawn>         list = PawnGroupMakerUtility.GeneratePawns(PawnGroupKindDefOf.Normal, defaultPawnGroupMakerParms, true).ToList();

            if (list.Count == 0)
            {
                Log.Error("Got no pawns spawning raid from parms " + parms);
                return(false);
            }
            TargetInfo target = TargetInfo.Invalid;

            if (parms.raidArrivalMode == PawnsArriveMode.CenterDrop || parms.raidArrivalMode == PawnsArriveMode.EdgeDrop)
            {
                DropPodUtility.DropThingsNear(parms.spawnCenter, map, list.Cast <Thing>(), parms.raidPodOpenDelay, false, true, true, false);
                target = new TargetInfo(parms.spawnCenter, map, false);
            }
            else
            {
                foreach (Pawn item in list)
                {
                    IntVec3 loc = CellFinder.RandomClosewalkCellNear(parms.spawnCenter, map, 8, null);
                    GenSpawn.Spawn(item, loc, map, parms.spawnRotation, false);
                    target = item;
                }
            }
            StringBuilder stringBuilder = new StringBuilder();

            stringBuilder.AppendLine("Points = " + parms.points.ToString("F0"));
            foreach (Pawn item2 in list)
            {
                string str = (item2.equipment == null || item2.equipment.Primary == null) ? "unarmed" : item2.equipment.Primary.LabelCap;
                stringBuilder.AppendLine(item2.KindLabel + " - " + str);
            }
            string letterLabel = this.GetLetterLabel(parms);
            string letterText  = this.GetLetterText(parms, list);

            PawnRelationUtility.Notify_PawnsSeenByPlayer_Letter(list, ref letterLabel, ref letterText, this.GetRelatedPawnsInfoLetterText(parms), true, true);
            Find.LetterStack.ReceiveLetter(letterLabel, letterText, this.GetLetterDef(), target, stringBuilder.ToString());
            if (this.GetLetterDef() == LetterDefOf.ThreatBig)
            {
                TaleRecorder.RecordTale(TaleDefOf.RaidArrived);
            }
            Lord lord = LordMaker.MakeNewLord(parms.faction, parms.raidStrategy.Worker.MakeLordJob(parms, map), map, list);

            AvoidGridMaker.RegenerateAvoidGridsFor(parms.faction, map);
            LessonAutoActivator.TeachOpportunity(ConceptDefOf.EquippingWeapons, OpportunityType.Critical);
            if (!PlayerKnowledgeDatabase.IsComplete(ConceptDefOf.ShieldBelts))
            {
                for (int i = 0; i < list.Count; i++)
                {
                    Pawn pawn = list[i];
                    if (pawn.apparel.WornApparel.Any((Apparel ap) => ap is ShieldBelt))
                    {
                        LessonAutoActivator.TeachOpportunity(ConceptDefOf.ShieldBelts, OpportunityType.Critical);
                        break;
                    }
                }
            }
            if (DebugViewSettings.drawStealDebug && parms.faction.HostileTo(Faction.OfPlayer))
            {
                Log.Message("Market value threshold to start stealing: " + StealAIUtility.StartStealingMarketValueThreshold(lord) + " (colony wealth = " + map.wealthWatcher.WealthTotal + ")");
            }
            return(true);
        }
        public virtual void MakeLords(IncidentParms parms, List <Pawn> pawns)
        {
            Map map = (Map)parms.target;
            List <List <Pawn> > list = IncidentParmsUtility.SplitIntoGroups(pawns, parms.pawnGroups);
            int @int = Rand.Int;

            for (int i = 0; i < list.Count; i++)
            {
                List <Pawn> list2 = list[i];
                Lord        lord  = LordMaker.MakeNewLord(parms.faction, MakeLordJob(parms, map, list2, @int), map, list2);
                lord.inSignalLeave = parms.inSignalEnd;
                QuestUtility.AddQuestTag(lord, parms.questTag);
                if (DebugViewSettings.drawStealDebug && parms.faction.HostileTo(Faction.OfPlayer))
                {
                    Log.Message("Market value threshold to start stealing (raiders=" + lord.ownedPawns.Count + "): " + StealAIUtility.StartStealingMarketValueThreshold(lord) + " (colony wealth=" + map.wealthWatcher.WealthTotal + ")");
                }
            }
        }