コード例 #1
0
        public bool TryFindShootLineFromTo(IntVec3 root, LocalTargetInfo targ, out ShootLine resultingLine)
        {
            if (targ.HasThing && targ.Thing.Map != caster.Map)
            {
                resultingLine = default(ShootLine);
                return(false);
            }
            if (verbProps.IsMeleeAttack || verbProps.range <= 1.42f)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(ReachabilityImmediate.CanReachImmediate(root, targ, caster.Map, PathEndMode.Touch, null));
            }
            CellRect cellRect = (!targ.HasThing) ? CellRect.SingleCell(targ.Cell) : targ.Thing.OccupiedRect();
            float    num      = verbProps.EffectiveMinRange(targ, caster);
            float    num2     = cellRect.ClosestDistSquaredTo(root);

            if (num2 > verbProps.range * verbProps.range || num2 < num * num)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(false);
            }
            if (!verbProps.requireLineOfSight)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                return(true);
            }
            IntVec3 goodDest;

            if (CasterIsPawn)
            {
                if (CanHitFromCellIgnoringRange(root, targ, out goodDest))
                {
                    resultingLine = new ShootLine(root, goodDest);
                    return(true);
                }
                ShootLeanUtility.LeanShootingSourcesFromTo(root, cellRect.ClosestCellTo(root), caster.Map, tempLeanShootSources);
                for (int i = 0; i < tempLeanShootSources.Count; i++)
                {
                    IntVec3 intVec = tempLeanShootSources[i];
                    if (CanHitFromCellIgnoringRange(intVec, targ, out goodDest))
                    {
                        resultingLine = new ShootLine(intVec, goodDest);
                        return(true);
                    }
                }
            }
            else
            {
                CellRect.CellRectIterator iterator = caster.OccupiedRect().GetIterator();
                while (!iterator.Done())
                {
                    IntVec3 current = iterator.Current;
                    if (CanHitFromCellIgnoringRange(current, targ, out goodDest))
                    {
                        resultingLine = new ShootLine(current, goodDest);
                        return(true);
                    }
                    iterator.MoveNext();
                }
            }
            resultingLine = new ShootLine(root, targ.Cell);
            return(false);
        }
コード例 #2
0
        public override void DeSpawn()
        {
            Map map = base.Map;

            base.DeSpawn();
            if (base.def.IsEdifice())
            {
                map.edificeGrid.DeRegister(this);
            }
            if (base.def.MakeFog)
            {
                map.fogGrid.Notify_FogBlockerRemoved(base.Position);
            }
            if (base.def.holdsRoof)
            {
                RoofCollapseCellsFinder.Notify_RoofHolderDespawned(this, map);
            }
            if (this.sustainerAmbient != null)
            {
                this.sustainerAmbient.End();
            }
            CellRect cellRect = this.OccupiedRect();

            for (int i = cellRect.minZ; i <= cellRect.maxZ; i++)
            {
                for (int j = cellRect.minX; j <= cellRect.maxX; j++)
                {
                    IntVec3     loc         = new IntVec3(j, 0, i);
                    MapMeshFlag mapMeshFlag = MapMeshFlag.Buildings;
                    if (base.def.coversFloor)
                    {
                        mapMeshFlag |= MapMeshFlag.Terrain;
                    }
                    if (base.def.Fillage == FillCategory.Full)
                    {
                        mapMeshFlag |= MapMeshFlag.Roofs;
                        mapMeshFlag |= MapMeshFlag.Snow;
                    }
                    map.mapDrawer.MapMeshDirty(loc, mapMeshFlag);
                    map.glowGrid.MarkGlowGridDirty(loc);
                }
            }
            map.listerBuildings.Remove(this);
            map.listerBuildingsRepairable.Notify_BuildingDeSpawned(this);
            if (base.def.leaveTerrain != null && Current.ProgramState == ProgramState.Playing)
            {
                CellRect.CellRectIterator iterator = this.OccupiedRect().GetIterator();
                while (!iterator.Done())
                {
                    map.terrainGrid.SetTerrain(iterator.Current, base.def.leaveTerrain);
                    iterator.MoveNext();
                }
            }
            map.designationManager.Notify_BuildingDespawned(this);
            if (!this.CanBeSeenOver())
            {
                map.exitMapGrid.Notify_LOSBlockerDespawned();
            }
            if (base.def.building.hasFuelingPort)
            {
                IntVec3        fuelingPortCell = FuelingPortUtility.GetFuelingPortCell(base.Position, base.Rotation);
                CompLaunchable compLaunchable  = FuelingPortUtility.LaunchableAt(fuelingPortCell, map);
                if (compLaunchable != null)
                {
                    compLaunchable.Notify_FuelingPortSourceDeSpawned();
                }
            }
            if (base.def.building.ai_combatDangerous)
            {
                AvoidGridMaker.Notify_CombatDangerousBuildingDespawned(this, map);
            }
        }
コード例 #3
0
        public static IntVec3 FindNoWipeSpawnLocNear(IntVec3 near, Map map, ThingDef thingToSpawn, Rot4 rot, int maxDist = 2, Predicate <IntVec3> extraValidator = null)
        {
            int     num    = GenRadial.NumCellsInRadius((float)maxDist);
            IntVec3 intVec = IntVec3.Invalid;
            float   num2   = 0f;

            for (int i = 0; i < num; i++)
            {
                IntVec3 intVec2 = near + GenRadial.RadialPattern[i];
                if (intVec2.InBounds(map))
                {
                    CellRect cellRect = GenAdj.OccupiedRect(intVec2, rot, thingToSpawn.size);
                    if (cellRect.InBounds(map))
                    {
                        if (GenSight.LineOfSight(near, intVec2, map, true, null, 0, 0))
                        {
                            if (extraValidator == null || extraValidator(intVec2))
                            {
                                if (thingToSpawn.category != ThingCategory.Building || GenConstruct.CanBuildOnTerrain(thingToSpawn, intVec2, map, rot, null))
                                {
                                    bool flag  = false;
                                    bool flag2 = false;
                                    CellFinder.tmpUniqueWipedThings.Clear();
                                    CellRect.CellRectIterator iterator = cellRect.GetIterator();
                                    while (!iterator.Done())
                                    {
                                        if (iterator.Current.Impassable(map))
                                        {
                                            flag2 = true;
                                        }
                                        List <Thing> thingList = iterator.Current.GetThingList(map);
                                        for (int j = 0; j < thingList.Count; j++)
                                        {
                                            if (thingList[j] is Pawn)
                                            {
                                                flag = true;
                                            }
                                            else if (GenSpawn.SpawningWipes(thingToSpawn, thingList[j].def) && !CellFinder.tmpUniqueWipedThings.Contains(thingList[j]))
                                            {
                                                CellFinder.tmpUniqueWipedThings.Add(thingList[j]);
                                            }
                                        }
                                        iterator.MoveNext();
                                    }
                                    if (flag && thingToSpawn.passability == Traversability.Impassable)
                                    {
                                        CellFinder.tmpUniqueWipedThings.Clear();
                                    }
                                    else if (flag2 && thingToSpawn.category == ThingCategory.Item)
                                    {
                                        CellFinder.tmpUniqueWipedThings.Clear();
                                    }
                                    else
                                    {
                                        float num3 = 0f;
                                        for (int k = 0; k < CellFinder.tmpUniqueWipedThings.Count; k++)
                                        {
                                            if (CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Building && !CellFinder.tmpUniqueWipedThings[k].def.costList.NullOrEmpty <ThingDefCountClass>() && CellFinder.tmpUniqueWipedThings[k].def.costStuffCount == 0)
                                            {
                                                List <ThingDefCountClass> list = CellFinder.tmpUniqueWipedThings[k].CostListAdjusted();
                                                for (int l = 0; l < list.Count; l++)
                                                {
                                                    num3 += list[l].thingDef.GetStatValueAbstract(StatDefOf.MarketValue, null) * (float)list[l].count * (float)CellFinder.tmpUniqueWipedThings[k].stackCount;
                                                }
                                            }
                                            else
                                            {
                                                num3 += CellFinder.tmpUniqueWipedThings[k].MarketValue * (float)CellFinder.tmpUniqueWipedThings[k].stackCount;
                                            }
                                            if (CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Building || CellFinder.tmpUniqueWipedThings[k].def.category == ThingCategory.Item)
                                            {
                                                num3 = Mathf.Max(num3, 0.001f);
                                            }
                                        }
                                        CellFinder.tmpUniqueWipedThings.Clear();
                                        if (!intVec.IsValid || num3 < num2)
                                        {
                                            if (num3 == 0f)
                                            {
                                                return(intVec2);
                                            }
                                            intVec = intVec2;
                                            num2   = num3;
                                        }
                                    }
                                }
                            }
                        }
                    }
                }
            }
            return((!intVec.IsValid) ? near : intVec);
        }
コード例 #4
0
ファイル: Verb.cs プロジェクト: aihhr1832/RimWorld-Decompile
        public bool TryFindShootLineFromTo(IntVec3 root, LocalTargetInfo targ, out ShootLine resultingLine)
        {
            bool result;

            if (targ.HasThing && targ.Thing.Map != this.caster.Map)
            {
                resultingLine = default(ShootLine);
                result        = false;
            }
            else if (this.verbProps.IsMeleeAttack || this.verbProps.range <= 1.42f)
            {
                resultingLine = new ShootLine(root, targ.Cell);
                result        = ReachabilityImmediate.CanReachImmediate(root, targ, this.caster.Map, PathEndMode.Touch, null);
            }
            else
            {
                CellRect cellRect = (!targ.HasThing) ? CellRect.SingleCell(targ.Cell) : targ.Thing.OccupiedRect();
                float    num      = cellRect.ClosestDistSquaredTo(root);
                if (num > this.verbProps.range * this.verbProps.range || num < this.verbProps.minRange * this.verbProps.minRange)
                {
                    resultingLine = new ShootLine(root, targ.Cell);
                    result        = false;
                }
                else if (!this.verbProps.requireLineOfSight)
                {
                    resultingLine = new ShootLine(root, targ.Cell);
                    result        = true;
                }
                else
                {
                    if (this.CasterIsPawn)
                    {
                        IntVec3 dest;
                        if (this.CanHitFromCellIgnoringRange(root, targ, out dest))
                        {
                            resultingLine = new ShootLine(root, dest);
                            return(true);
                        }
                        ShootLeanUtility.LeanShootingSourcesFromTo(root, cellRect.ClosestCellTo(root), this.caster.Map, Verb.tempLeanShootSources);
                        for (int i = 0; i < Verb.tempLeanShootSources.Count; i++)
                        {
                            IntVec3 intVec = Verb.tempLeanShootSources[i];
                            if (this.CanHitFromCellIgnoringRange(intVec, targ, out dest))
                            {
                                resultingLine = new ShootLine(intVec, dest);
                                return(true);
                            }
                        }
                    }
                    else
                    {
                        CellRect.CellRectIterator iterator = this.caster.OccupiedRect().GetIterator();
                        while (!iterator.Done())
                        {
                            IntVec3 intVec2 = iterator.Current;
                            IntVec3 dest;
                            if (this.CanHitFromCellIgnoringRange(intVec2, targ, out dest))
                            {
                                resultingLine = new ShootLine(intVec2, dest);
                                return(true);
                            }
                            iterator.MoveNext();
                        }
                    }
                    resultingLine = new ShootLine(root, targ.Cell);
                    result        = false;
                }
            }
            return(result);
        }
コード例 #5
0
ファイル: Projectile.cs プロジェクト: potsh/RimWorld
        protected bool CanHit(Thing thing)
        {
            if (!thing.Spawned)
            {
                return(false);
            }
            if (thing == launcher)
            {
                return(false);
            }
            bool flag = false;

            CellRect.CellRectIterator iterator = thing.OccupiedRect().GetIterator();
            while (!iterator.Done())
            {
                List <Thing> thingList = iterator.Current.GetThingList(base.Map);
                bool         flag2     = false;
                for (int i = 0; i < thingList.Count; i++)
                {
                    if (thingList[i] != thing && thingList[i].def.Fillage == FillCategory.Full && thingList[i].def.Altitude >= thing.def.Altitude)
                    {
                        flag2 = true;
                        break;
                    }
                }
                if (!flag2)
                {
                    flag = true;
                    break;
                }
                iterator.MoveNext();
            }
            if (!flag)
            {
                return(false);
            }
            ProjectileHitFlags hitFlags = HitFlags;

            if (thing == intendedTarget && (hitFlags & ProjectileHitFlags.IntendedTarget) != 0)
            {
                return(true);
            }
            if (thing != intendedTarget)
            {
                if (thing is Pawn)
                {
                    if ((hitFlags & ProjectileHitFlags.NonTargetPawns) != 0)
                    {
                        return(true);
                    }
                }
                else if ((hitFlags & ProjectileHitFlags.NonTargetWorld) != 0)
                {
                    return(true);
                }
            }
            if (thing == intendedTarget && thing.def.Fillage == FillCategory.Full)
            {
                return(true);
            }
            return(false);
        }