public static bool CanReserve(AttackTargetReservationManager __instance, ref bool __result, Pawn claimant, IAttackTarget target)
        {
            if (__instance.IsReservedBy(claimant, target))
            {
                __result = true;
                return(false);
            }

            int reservationsCount             = GetReservationsCount2(__instance, target, claimant.Faction);
            int maxPreferredReservationsCount = GetMaxPreferredReservationsCount2(__instance, target);

            __result = reservationsCount < maxPreferredReservationsCount;
            return(false);
        }
        private static int GetMaxPreferredReservationsCount2(AttackTargetReservationManager __instance, IAttackTarget target)
        {
            int      num      = 0;
            CellRect cellRect = target.Thing.OccupiedRect();

            foreach (IntVec3 item in cellRect.ExpandedBy(1))
            {
                if (!cellRect.Contains(item) && item.InBounds(map(__instance)) && item.Standable(map(__instance)))
                {
                    num++;
                }
            }

            return(num);
        }
 public static bool ReleaseAllClaimedBy(AttackTargetReservationManager __instance, Pawn claimant)
 {
     lock (reservations(__instance))
     {
         for (int num = reservations(__instance).Count - 1; num >= 0; num--)
         {
             AttackTargetReservation reservation = reservations(__instance)[num];
             if (reservation != null && reservation.claimant == claimant)
             {
                 reservations(__instance).RemoveAt(num);
             }
         }
     }
     return(false);
 }
예제 #4
0
        public static bool FirstReservationFor(AttackTargetReservationManager __instance, ref IAttackTarget __result, Pawn claimant)
        {
            List <AttackTargetReservation> snapshotReservations = reservations(__instance);

            for (int i = snapshotReservations.Count - 1; i >= 0; i--)
            {
                AttackTargetReservation reservation = snapshotReservations[i];
                if (reservation.claimant == claimant)
                {
                    __result = reservation.target;
                    return(false);
                }
            }
            __result = null;
            return(false);
        }
        public static bool GetReservationsCount(AttackTargetReservationManager __instance, ref int __result, IAttackTarget target, Faction faction)
        {
            int num = 0;
            List <AttackTargetReservation> snapshotReservations = __instance.reservations;

            for (int i = 0; i < snapshotReservations.Count; i++)
            {
                AttackTargetReservation attackTargetReservation = snapshotReservations[i];
                if (attackTargetReservation.target == target && attackTargetReservation.claimant.Faction == faction)
                {
                    num++;
                }
            }

            __result = num;
            return(false);
        }
예제 #6
0
        public static bool IsReservedBy(AttackTargetReservationManager __instance, ref bool __result, Pawn claimant, IAttackTarget target)
        {
            List <AttackTargetReservation> snapshotReservations = reservations(__instance);

            for (int i = 0; i < snapshotReservations.Count; i++)
            {
                AttackTargetReservation attackTargetReservation = snapshotReservations[i];
                if (attackTargetReservation.target == target && attackTargetReservation.claimant == claimant)
                {
                    __result = true;
                    return(false);
                }
            }

            __result = false;
            return(false);
        }
 public static bool ReleaseAllClaimedBy(AttackTargetReservationManager __instance, Pawn claimant)
 {
     lock (RimThreaded.map_AttackTargetReservationManager_reservations_Lock)
     {
         List <AttackTargetReservation> snapshotReservations        = __instance.reservations;
         List <AttackTargetReservation> newAttackTargetReservations = new List <AttackTargetReservation>(snapshotReservations.Count);
         for (int i = 0; i < snapshotReservations.Count - 1; i++)
         {
             AttackTargetReservation attackTargetReservation = snapshotReservations[i];
             if (attackTargetReservation.claimant != claimant)
             {
                 newAttackTargetReservations.Add(attackTargetReservation);
             }
         }
         __instance.reservations = newAttackTargetReservations;
     }
     return(false);
 }
        private static int GetReservationsCount2(AttackTargetReservationManager __instance, IAttackTarget target, Faction faction)
        {
            int num = 0;

            for (int i = 0; i < reservations(__instance).Count; i++)
            {
                AttackTargetReservation attackTargetReservation = reservations(__instance)[i];
                if (attackTargetReservation != null)
                {
                    if (attackTargetReservation.target == target && attackTargetReservation.claimant != null && attackTargetReservation.claimant.Faction == faction)
                    {
                        num++;
                    }
                }
            }

            return(num);
        }
        public static bool ReleaseAllForTarget(AttackTargetReservationManager __instance, IAttackTarget target)
        {
            List <AttackTargetReservation> attackTargetReservations = reservations(__instance);

            lock (attackTargetReservations)
            {
                for (int i = attackTargetReservations.Count - 1; i >= 0; i--)
                {
                    AttackTargetReservation attackTargetReservation = attackTargetReservations[i];
                    if (attackTargetReservation != null && attackTargetReservation.target == target)
                    {
                        attackTargetReservations.RemoveAt(i);
                    }
                }
            }

            return(false);
        }
 public static bool FirstReservationFor(AttackTargetReservationManager __instance, ref IAttackTarget __result, Pawn claimant)
 {
     lock (reservations(__instance))
     {
         for (int i = reservations(__instance).Count - 1; i >= 0; i--)
         {
             if (null != reservations(__instance)[i])
             {
                 if (reservations(__instance)[i].claimant == claimant)
                 {
                     __result = reservations(__instance)[i].target;
                     return(false);
                 }
             }
         }
     }
     __result = null;
     return(false);
 }
예제 #11
0
        public static bool ReleaseAllForTarget(AttackTargetReservationManager __instance, IAttackTarget target)
        {
            lock (RimThreaded.map_AttackTargetReservationManager_reservations_Lock)
            {
                List <AttackTargetReservation> snapshotReservations        = reservations(__instance);
                List <AttackTargetReservation> newAttackTargetReservations = new List <AttackTargetReservation>(snapshotReservations.Count);
                for (int i = 0; i < snapshotReservations.Count - 1; i++)
                {
                    AttackTargetReservation attackTargetReservation = snapshotReservations[i];
                    if (attackTargetReservation.target != target)
                    {
                        newAttackTargetReservations.Add(attackTargetReservation);
                    }
                }
                reservations(__instance) = newAttackTargetReservations;
            }

            return(false);
        }
        public static bool IsReservedBy(AttackTargetReservationManager __instance, ref bool __result, Pawn claimant, IAttackTarget target)
        {
            AttackTargetReservation attackTargetReservation;

            for (int i = 0; i < reservations(__instance).Count; i++)
            {
                try
                {
                    attackTargetReservation = reservations(__instance)[i];
                }
                catch (ArgumentOutOfRangeException) { break; }
                if (attackTargetReservation != null && attackTargetReservation.target == target && attackTargetReservation.claimant == claimant)
                {
                    __result = true;
                    return(false);
                }
            }
            __result = false;
            return(false);
        }
        public void Reserve(AttackTargetReservationManager __instance, Pawn claimant, Job job, IAttackTarget target)
        {
            bool isReservedBy = __instance.IsReservedBy(claimant, target);

            if (target == null)
            {
                Log.Warning(claimant + " tried to reserve null attack target.");
            }
            else if (!isReservedBy)
            {
                AttackTargetReservation attackTargetReservation = new AttackTargetReservation();
                attackTargetReservation.target   = target;
                attackTargetReservation.claimant = claimant;
                attackTargetReservation.job      = job;
                lock (reservations(__instance))
                {
                    reservations(__instance).Add(attackTargetReservation);
                }
            }
        }
        public static bool ReleaseClaimedBy(AttackTargetReservationManager __instance, Pawn claimant, Job job)
        {
            lock (reservations(__instance)) {
                for (int i = reservations(__instance).Count - 1; i >= 0; i--)
                {
                    AttackTargetReservation reservation;

                    reservation = reservations(__instance)[i];

                    if (reservation != null)
                    {
                        if (reservation.claimant == claimant && reservation.job == job)
                        {
                            {
                                reservations(__instance).RemoveAt(i);
                            }
                        }
                    }
                }
            }
            return(false);
        }
 public static bool Reserve(AttackTargetReservationManager __instance, Pawn claimant, Job job, IAttackTarget target)
 {
     if (target == null)
     {
         Log.Warning(string.Concat(claimant, " tried to reserve null attack target."));
     }
     else if (!__instance.IsReservedBy(claimant, target))
     {
         AttackTargetReservation attackTargetReservation = new AttackTargetReservation
         {
             target   = target,
             claimant = claimant,
             job      = job
         };
         lock (RimThreaded.map_AttackTargetReservationManager_reservations_Lock)
         {
             __instance.reservations = new List <AttackTargetReservation>(__instance.reservations)
             {
                 attackTargetReservation
             };
         }
     }
     return(false);
 }
예제 #16
0
 public void ConstructComponents()
 {
     this.spawnedThings      = new ThingOwner <Thing>(this);
     this.cellIndices        = new CellIndices(this);
     this.listerThings       = new ListerThings(ListerThingsUse.Global);
     this.listerBuildings    = new ListerBuildings();
     this.mapPawns           = new MapPawns(this);
     this.dynamicDrawManager = new DynamicDrawManager(this);
     this.mapDrawer          = new MapDrawer(this);
     this.tooltipGiverList   = new TooltipGiverList();
     this.pawnDestinationReservationManager = new PawnDestinationReservationManager();
     this.reservationManager = new ReservationManager(this);
     this.physicalInteractionReservationManager = new PhysicalInteractionReservationManager();
     this.designationManager             = new DesignationManager(this);
     this.lordManager                    = new LordManager(this);
     this.debugDrawer                    = new DebugCellDrawer();
     this.passingShipManager             = new PassingShipManager(this);
     this.haulDestinationManager         = new HaulDestinationManager(this);
     this.gameConditionManager           = new GameConditionManager(this);
     this.weatherManager                 = new WeatherManager(this);
     this.zoneManager                    = new ZoneManager(this);
     this.resourceCounter                = new ResourceCounter(this);
     this.mapTemperature                 = new MapTemperature(this);
     this.temperatureCache               = new TemperatureCache(this);
     this.areaManager                    = new AreaManager(this);
     this.attackTargetsCache             = new AttackTargetsCache(this);
     this.attackTargetReservationManager = new AttackTargetReservationManager(this);
     this.lordsStarter                   = new VoluntarilyJoinableLordsStarter(this);
     this.thingGrid                  = new ThingGrid(this);
     this.coverGrid                  = new CoverGrid(this);
     this.edificeGrid                = new EdificeGrid(this);
     this.blueprintGrid              = new BlueprintGrid(this);
     this.fogGrid                    = new FogGrid(this);
     this.glowGrid                   = new GlowGrid(this);
     this.regionGrid                 = new RegionGrid(this);
     this.terrainGrid                = new TerrainGrid(this);
     this.pathGrid                   = new PathGrid(this);
     this.roofGrid                   = new RoofGrid(this);
     this.fertilityGrid              = new FertilityGrid(this);
     this.snowGrid                   = new SnowGrid(this);
     this.deepResourceGrid           = new DeepResourceGrid(this);
     this.exitMapGrid                = new ExitMapGrid(this);
     this.linkGrid                   = new LinkGrid(this);
     this.glowFlooder                = new GlowFlooder(this);
     this.powerNetManager            = new PowerNetManager(this);
     this.powerNetGrid               = new PowerNetGrid(this);
     this.regionMaker                = new RegionMaker(this);
     this.pathFinder                 = new PathFinder(this);
     this.pawnPathPool               = new PawnPathPool(this);
     this.regionAndRoomUpdater       = new RegionAndRoomUpdater(this);
     this.regionLinkDatabase         = new RegionLinkDatabase();
     this.moteCounter                = new MoteCounter();
     this.gatherSpotLister           = new GatherSpotLister();
     this.windManager                = new WindManager(this);
     this.listerBuildingsRepairable  = new ListerBuildingsRepairable();
     this.listerHaulables            = new ListerHaulables(this);
     this.listerMergeables           = new ListerMergeables(this);
     this.listerFilthInHomeArea      = new ListerFilthInHomeArea(this);
     this.reachability               = new Reachability(this);
     this.itemAvailability           = new ItemAvailability(this);
     this.autoBuildRoofAreaSetter    = new AutoBuildRoofAreaSetter(this);
     this.roofCollapseBufferResolver = new RoofCollapseBufferResolver(this);
     this.roofCollapseBuffer         = new RoofCollapseBuffer();
     this.wildAnimalSpawner          = new WildAnimalSpawner(this);
     this.wildPlantSpawner           = new WildPlantSpawner(this);
     this.steadyEnvironmentEffects   = new SteadyEnvironmentEffects(this);
     this.skyManager                 = new SkyManager(this);
     this.overlayDrawer              = new OverlayDrawer();
     this.floodFiller                = new FloodFiller(this);
     this.weatherDecider             = new WeatherDecider(this);
     this.fireWatcher                = new FireWatcher(this);
     this.dangerWatcher              = new DangerWatcher(this);
     this.damageWatcher              = new DamageWatcher();
     this.strengthWatcher            = new StrengthWatcher(this);
     this.wealthWatcher              = new WealthWatcher(this);
     this.regionDirtyer              = new RegionDirtyer(this);
     this.cellsInRandomOrder         = new MapCellsInRandomOrder(this);
     this.rememberedCameraPos        = new RememberedCameraPos(this);
     this.mineStrikeManager          = new MineStrikeManager();
     this.storyState                 = new StoryState(this);
     this.retainedCaravanData        = new RetainedCaravanData(this);
     this.components.Clear();
     this.FillComponents();
 }