示例#1
0
        public override AcceptanceReport AllowsPlacing(BuildableDef def, IntVec3 center, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null)
        {
            IntVec3 c  = center + IntVec3.South.RotatedBy(rot);
            IntVec3 c2 = center + IntVec3.North.RotatedBy(rot);

            if (c.Impassable(map) || c2.Impassable(map))
            {
                return("MustPlaceCoolerWithFreeSpaces".Translate());
            }
            Frame firstThing  = c.GetFirstThing <Frame>(map);
            Frame firstThing2 = c2.GetFirstThing <Frame>(map);

            if ((firstThing != null && firstThing.def.entityDefToBuild != null && firstThing.def.entityDefToBuild.passability == Traversability.Impassable) || (firstThing2 != null && firstThing2.def.entityDefToBuild != null && firstThing2.def.entityDefToBuild.passability == Traversability.Impassable))
            {
                return("MustPlaceCoolerWithFreeSpaces".Translate());
            }
            Blueprint firstThing3 = c.GetFirstThing <Blueprint>(map);
            Blueprint firstThing4 = c2.GetFirstThing <Blueprint>(map);

            if ((firstThing3 != null && firstThing3.def.entityDefToBuild != null && firstThing3.def.entityDefToBuild.passability == Traversability.Impassable) || (firstThing4 != null && firstThing4.def.entityDefToBuild != null && firstThing4.def.entityDefToBuild.passability == Traversability.Impassable))
            {
                return("MustPlaceCoolerWithFreeSpaces".Translate());
            }
            return(true);
        }
示例#2
0
        private void AffectCell(IntVec3 c)
        {
            if (!c.InBounds(base.Map))
            {
                return;
            }
            var flag      = ShouldCellBeAffectedOnlyByDamage(c);
            var spawnMote = c.GetFirstThing(Map, damType.explosionCellMote) == null;

            if (!flag && Rand.Chance(preExplosionSpawnChance) && c.Walkable(Map))
            {
                TrySpawnExplosionThing(preExplosionSpawnThingDef, c, preExplosionSpawnThingCount);
            }
            damType.Worker.ExplosionAffectCell(this, c, damagedThings, null, spawnMote && !flag);
            if (!flag && Rand.Chance(postExplosionSpawnChance) && c.Walkable(Map))
            {
                TrySpawnExplosionThing(postExplosionSpawnThingDef, c, postExplosionSpawnThingCount);
            }
            var num = chanceToStartFire;

            if (damageFalloff)
            {
                num *= Mathf.Lerp(1f, (float)DamageAtEdge / damAmount, c.DistanceTo(Position) / radius);
            }
            if (Rand.Chance(num))
            {
                FireUtility.TryStartFireIn(c, Map, Rand.Range(0.1f, 0.925f));
            }
            //ExplosionCE (this) can be Destroyed after ExplosionAffectCell
        }
 /// <summary>
 /// Called when a pawn go to a pylon to take into account the player's cached configuration.
 /// </summary>
 public void Notify_PawnSwitchedLaserFence()
 {
     for (int directionAsInt = 0; directionAsInt < 4; directionAsInt++)
     {
         Rot4 direction = new Rot4(directionAsInt);
         this.connectionIsAllowedByUser[directionAsInt] = this.cachedConnectionIsAllowedByUser[directionAsInt];
         if (this.connectionIsAllowedByUser[directionAsInt])
         {
             // Connection is allowed. Look for a pylon to connect to.
             if (this.fenceLength[direction.AsInt] == 0)
             {
                 this.LookForPylon(direction, true);
             }
         }
         else
         {
             // Connection is forbidden. Disconnect from linked pylon if necessary.
             if (this.fenceLength[directionAsInt] > 0)
             {
                 IntVec3 linkedPylonPosition          = this.Position + new IntVec3(0, 0, this.fenceLength[direction.AsInt] + 1).RotatedBy(direction);
                 Building_LaserFencePylon linkedPylon = linkedPylonPosition.GetFirstThing(this.Map, Util_LaserFence.LaserFencePylonDef) as Building_LaserFencePylon;
                 if (linkedPylon != null)
                 {
                     linkedPylon.connectionIsAllowedByUser[direction.Opposite.AsInt]       = false;
                     linkedPylon.cachedConnectionIsAllowedByUser[direction.Opposite.AsInt] = false;
                 }
                 this.DeactivateFence(direction);
             }
         }
     }
 }
示例#4
0
        /// <summary>
        /// Try to spawn another plant in this cluster.
        /// </summary>
        public static ClusterPlant TryGrowCluster(Cluster cluster)
        {
            IntVec3 spawnCell = IntVec3.Invalid;

            TryGetRandomSpawnCellNearCluster(cluster, out spawnCell);
            if (spawnCell.IsValid)
            {
                ClusterPlant newPlant = ThingMaker.MakeThing(cluster.plantDef) as ClusterPlant;
                GenSpawn.Spawn(newPlant, spawnCell, cluster.Map);
                newPlant.cluster = cluster;
                cluster.NotifyPlantAdded();
                if (cluster.plantDef.isSymbiosisPlant)
                {
                    // Destroy source symbiosis plant.
                    Thing sourceSymbiosisPlant = spawnCell.GetFirstThing(cluster.Map, cluster.plantDef.symbiosisPlantDefSource);
                    if (sourceSymbiosisPlant != null)
                    {
                        sourceSymbiosisPlant.Destroy();
                    }
                }
                return(newPlant);
            }
            else
            {
                return(null);
            }
        }
示例#5
0
 public static void GetWanderRoot(Pawn pawn, ref IntVec3 __result)
 {
     if (!__result.GetFirstThing(pawn.Map, XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon).DestroyedOrNull())
     {
         __result = pawn.Position;
     }
 }
        public void SwitchOnLight()
        {
            IntVec3 newPosition = this.Wearer.DrawPos.ToIntVec3();

            // Switch off previous light if pawn moved.
            if (((this.light.DestroyedOrNull() == false) &&
                 (newPosition != this.light.Position)) ||
                this.refreshIsNecessary)
            {
                SwitchOffLight();
                this.refreshIsNecessary = false;
            }

            // Try to spawn a new light.
            if (this.light.DestroyedOrNull())
            {
                Thing potentialLight = newPosition.GetFirstThing(this.Wearer.Map, Util_MiningHelmet.miningLightDef);
                if (potentialLight == null)
                {
                    this.light = GenSpawn.Spawn(Util_MiningHelmet.miningLightDef, newPosition, this.Wearer.Map);
                }
                // else another light is already here.
            }
            this.lightIsOn = true;
        }
 private bool CanMoveTo(IntVec3 pos)
 {
     return
         (pos.InBounds(Map) &&
          (
              !pos.Filled(Map) ||
              (pos.GetDoor(Map)?.Open ?? false) ||
              (pos.GetFirstThing <Building_Vent>(Map) is Building_Vent vent && vent.TryGetComp <CompFlickable>().SwitchIsOn)
          ));
 }
示例#8
0
 private static void SpawnShrapnel(ThingDef def, int quantity, IntVec3 center, Map map, float angle, float distanceFactor)
 {
     for (int i = 0; i < quantity; i++)
     {
         IntVec3 intVec = SkyfallerShrapnelUtility.GenerateShrapnelLocation(center, angle, distanceFactor);
         if (SkyfallerShrapnelUtility.IsGoodShrapnelCell(intVec, map) && intVec.GetFirstThing(map, def) == null)
         {
             GenSpawn.Spawn(def, intVec, map);
         }
     }
 }
示例#9
0
        public override void DoEffect(Pawn p)
        {
            base.DoEffect(p);
            var key_stamp = parent.GetComp <CompHoloCryptoStamped>();

            if ((key_stamp == null) || (p.MapHeld == null) || (p.apparel == null))
            {
                return;
            }

            Apparel locked_app = null;
            var     any_locked = false;

            {
                foreach (var app in p.apparel.WornApparel)
                {
                    var app_stamp = app.GetComp <CompHoloCryptoStamped>();
                    if (app_stamp != null)
                    {
                        any_locked = true;
                        if (app_stamp.matches(key_stamp))
                        {
                            locked_app = app;
                            break;
                        }
                    }
                }
            }

            if (locked_app != null)
            {
                //locked_app.Notify_Stripped (p); // TODO This was removed. Necessary?

                p.apparel.Remove(locked_app);
                Thing dropped = null;
                GenThing.TryDropAndSetForbidden(locked_app, p.Position, p.MapHeld, ThingPlaceMode.Near, out dropped, false);                 //this will create a new key somehow.
                if (dropped != null)
                {
                    Messages.Message("Unlocked " + locked_app.def.label, p, MessageTypeDefOf.SilentInput);
                    //parent.DeSpawn();
                    IntVec3 keyPostition = parent.Position;
                    parent.Destroy();
                    keyPostition.GetFirstThing(p.MapHeld, xxx.holokey).Destroy();                      // so I need this line to despawn the new generated key.
                }
                else if (PawnUtility.ShouldSendNotificationAbout(p))
                {
                    Messages.Message("Couldn't drop " + locked_app.def.label, p, MessageTypeDefOf.NegativeEvent);
                }
            }
            else if (any_locked)
            {
                Messages.Message("The key doesn't fit!", p, MessageTypeDefOf.NegativeEvent);
            }
        }
示例#10
0
            internal static void Postfix(IntVec3 c, Map map, ref bool __result)
            {
                if (!__result)
                {
                    return;
                }

                if (c.GetFirstThing <Building_TableTop>(map) != null)
                {
                    __result = false;
                }
            }
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 center, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null)
        {
            IntVec3 c   = center + IntVec3.East.RotatedBy(rot);
            var     bob = c.GetFirstThing <Building_PowerSwitch>(map);

            if (bob == null)
            {
                return("Gray area must be over a Power switch");
            }

            return(true);
        }
 /// <summary>
 /// Deactivate a fence in a given direction:
 /// - remove fence elements,
 /// - inform linked pylon, that it is deactivated.
 /// </summary>
 public void DeactivateFence(Rot4 direction)
 {
     if (this.fenceLength[direction.AsInt] > 0)
     {
         IntVec3 linkedPylonPosition          = this.Position + new IntVec3(0, 0, this.fenceLength[direction.AsInt] + 1).RotatedBy(direction);
         Building_LaserFencePylon linkedPylon = linkedPylonPosition.GetFirstThing(this.Map, Util_LaserFence.LaserFencePylonDef) as Building_LaserFencePylon;
         if (linkedPylon != null)
         {
             linkedPylon.RemoveFenceElements(direction.Opposite);
         }
         this.RemoveFenceElements(direction);
     }
 }
示例#13
0
        // Token: 0x06000006 RID: 6 RVA: 0x000021F0 File Offset: 0x000003F0
        public void SwitchOnLight()
        {
            IntVec3 intVec = base.Wearer.DrawPos.ToIntVec3();

            if (!this.light.DestroyedOrNull() && intVec != this.light.Position)
            {
                this.SwitchOffLight();
            }
            if (this.light.DestroyedOrNull() && intVec.GetFirstThing(base.Wearer.Map, Util_ApparelWithLight.ApparelLightDef) == null)
            {
                this.light = GenSpawn.Spawn(Util_ApparelWithLight.ApparelLightDef, intVec, base.Wearer.Map, WipeMode.Vanish);
            }
            this.lightIsOn = true;
        }
示例#14
0
        // Token: 0x06000006 RID: 6 RVA: 0x000021F0 File Offset: 0x000003F0
        public void SwitchOnTurret()
        {
            IntVec3 intVec = GetWearer.DrawPos.ToIntVec3();

            if (!this.turret.DestroyedOrNull() && intVec != this.turret.Position)
            {
                this.MoveTurret(intVec);
            }
            if ((this.turret.DestroyedOrNull() || !this.turret.Spawned) && intVec.GetFirstThing(GetWearer.Map, Util_CompEquippableTurret.EquippableTurretDef) == null)
            {
                this.turret = GenSpawn.Spawn(Util_CompEquippableTurret.EquippableTurretDef, intVec, GetWearer.Map, WipeMode.Vanish);
                this.turret.SetFactionDirect(this.GetWearer.Faction);
                ((Building_Turret_Shoulder)this.turret).Parental = GetWearer;
            }
        }
        private static void AddGas_Cell(IntVec3 cell,
                                        Map map,
                                        ThingDef gasDef,
                                        ref float amount,
                                        bool allowOverSaturation = false)
        {
            var spreadingGas = cell.GetFirstThing(map, gasDef) as Gas_Spreading;

            if (spreadingGas == null)
            {
                spreadingGas = ThingMaker.MakeThing(gasDef) as Gas_Spreading;
                GenSpawn.Spawn(spreadingGas, cell, map);
            }

            spreadingGas.AddGas(ref amount, allowOverSaturation);
        }
示例#16
0
        private static void SpawnCaveWellOpening(Map map, IntVec3 position)
        {
            Thing potentialCaveWell = position.GetFirstThing(map, Util_CaveBiome.CaveWellDef);

            if (potentialCaveWell == null)
            {
                GenSpawn.Spawn(Util_CaveBiome.CaveWellDef, position, map);
            }
            foreach (IntVec3 checkedCell in GenAdjFast.AdjacentCells8Way(position))
            {
                potentialCaveWell = checkedCell.GetFirstThing(map, Util_CaveBiome.CaveWellDef);
                if (potentialCaveWell == null)
                {
                    GenSpawn.Spawn(Util_CaveBiome.CaveWellDef, checkedCell, map);
                }
            }
        }
示例#17
0
        // Token: 0x06002689 RID: 9865 RVA: 0x00124A44 File Offset: 0x00122E44
        public static bool AnyHiveLikePreventsClaiming(Thing thing)
        {
            if (!thing.Spawned)
            {
                return(false);
            }
            int num = GenRadial.NumCellsInRadius(2f);

            for (int i = 0; i < num; i++)
            {
                IntVec3 c = thing.Position + GenRadial.RadialPattern[i];
                if (c.InBounds(thing.Map) && c.GetFirstThing(thing.Map, null) != null)
                {
                    return(true);
                }
            }
            return(false);
        }
        internal static void Postfix(IntVec3 c, Map map, float fireSize, bool __result)
        {
            if (!__result)
            {
                return;
            }

            var pawn = c.GetFirstThing <Pawn>(map);

            if (pawn == null)
            {
                return;
            }

            if (Rand.Chance(CatchFireChance * pawn.GetStatValue(StatDefOf.Flammability)))
            {
                pawn.TryAttachFire(fireSize);
            }
        }
        public static float AddGas(IntVec3 pos,
                                   Map map,
                                   ThingDef gasDef,
                                   float amount             = -1,
                                   bool spread              = true,
                                   bool allowOverSaturation = false)
        {
            // check if there is already a gas here, create if needed.
            var startingAmount = amount;
            var gas            = pos.GetFirstThing(map, gasDef);

            if (gas == null)
            {
                gas = ThingMaker.MakeThing(gasDef) as Gas;
                GenSpawn.Spawn(gas, pos, map);
            }

            // add specific amount if relevant
            if (gas is Gas_Spreading spreadingGas)
            {
                if (amount < 0)
                {
                    Log.Error(
                        $"Cannot add {amount} to {spreadingGas} at {spreadingGas.Position}. AddGas on a spreading gas should have a positive amount of gas.");
                    spreadingGas.Destroy();
                    return(amount);
                }

                if (spread)
                {
                    AddGas_FloodFill(pos, map, gasDef, ref amount);
                }
                else
                {
                    AddGas_Cell(pos, map, gasDef, ref amount, allowOverSaturation);
                }
            }

            return(startingAmount - amount);
        }
示例#20
0
        public static bool ExplosionAffectCell(DamageWorker __instance, Explosion explosion, IntVec3 c, List <Thing> damagedThings, List <Thing> ignoredThings, bool canThrowMotes)
        {
            if (__instance.def.explosionCellMote != null && canThrowMotes)
            {
                Mote mote = c.GetFirstThing(explosion.Map, __instance.def.explosionCellMote) as Mote;
                if (mote != null)
                {
                    mote.spawnTick = Find.TickManager.TicksGame;
                }
                else
                {
                    float t     = Mathf.Clamp01((explosion.Position - c).LengthHorizontal / explosion.radius);
                    Color color = Color.Lerp(__instance.def.explosionColorCenter, __instance.def.explosionColorEdge, t);
                    MoteMaker.ThrowExplosionCell(c, explosion.Map, __instance.def.explosionCellMote, color);
                }
            }

            //thingsToAffect.Clear();
            List <Thing> thingsToAffect = new List <Thing>();
            float        num            = float.MinValue;
            bool         flag           = false;
            List <Thing> list           = explosion.Map.thingGrid.ThingsListAt(c);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (thing.def.category != ThingCategory.Mote && thing.def.category != ThingCategory.Ethereal)
                {
                    thingsToAffect.Add(thing);
                    if (thing.def.Fillage == FillCategory.Full && thing.def.Altitude > num)
                    {
                        flag = true;
                        num  = thing.def.Altitude;
                    }
                }
            }

            for (int j = 0; j < thingsToAffect.Count; j++)
            {
                if (thingsToAffect[j].def.Altitude >= num) //Null Reference Exception
                {
                    ExplosionDamageThing(__instance, explosion, thingsToAffect[j], damagedThings, ignoredThings, c);
                }
            }

            if (!flag)
            {
                ExplosionDamageTerrain(__instance, explosion, c);
            }

            if (__instance.def.explosionSnowMeltAmount > 0.0001f)
            {
                float lengthHorizontal = (c - explosion.Position).LengthHorizontal;
                float num2             = 1f - lengthHorizontal / explosion.radius;
                if (num2 > 0f)
                {
                    explosion.Map.snowGrid.AddDepth(c, (0f - num2) * __instance.def.explosionSnowMeltAmount);
                }
            }

            if (__instance.def != DamageDefOf.Bomb && __instance.def != DamageDefOf.Flame)
            {
                return(false);
            }

            List <Thing> list2 = explosion.Map.listerThings.ThingsOfDef(ThingDefOf.RectTrigger);

            for (int k = 0; k < list2.Count; k++)
            {
                RectTrigger rectTrigger = (RectTrigger)list2[k];
                if (rectTrigger.activateOnExplosion && rectTrigger.Rect.Contains(c))
                {
                    rectTrigger.ActivatedBy(null);
                }
            }
            return(false);
        }
        private static bool CanSpawnHiveAt(IntVec3 c, Map map, IntVec3 parentPos, ThingDef parentDef, float minDist, bool ignoreRoofedRequirement)
        {
            bool result;

            if ((!ignoreRoofedRequirement && !c.Roofed(map)) || (!c.Walkable(map) || (minDist != 0f && (float)c.DistanceToSquared(parentPos) < minDist * minDist)) || c.GetFirstThing(map, ThingDefOf.InsectJelly) != null || c.GetFirstThing(map, ThingDefOf.GlowPod) != null)
            {
                result = false;
            }
            else
            {
                for (int i = 0; i < 9; i++)
                {
                    IntVec3 c2 = c + GenAdj.AdjacentCellsAndInside[i];
                    if (c2.InBounds(map))
                    {
                        List <Thing> thingList = c2.GetThingList(map);
                        for (int j = 0; j < thingList.Count; j++)
                        {
                            if (thingList[j] is Hive || thingList[j] is TunnelHiveSpawner)
                            {
                                return(false);
                            }
                        }
                    }
                }
                List <Thing> thingList2 = c.GetThingList(map);
                for (int k = 0; k < thingList2.Count; k++)
                {
                    Thing thing = thingList2[k];
                    bool  flag  = thing.def.category == ThingCategory.Building && thing.def.passability == Traversability.Impassable;
                    if (flag && GenSpawn.SpawningWipes(parentDef, thing.def))
                    {
                        return(true);
                    }
                }
                result = true;
            }
            return(result);
        }
 private static void SpawnCaveWellOpening(IntVec3 position)
 {
     Thing potentialCaveWell = position.GetFirstThing(Util_CaveBiome.CaveWellDef);
     if (potentialCaveWell == null)
     {
         GenSpawn.Spawn(Util_CaveBiome.CaveWellDef, position);
     }
     foreach (IntVec3 checkedCell in GenAdjFast.AdjacentCells8Way(position))
     {
         potentialCaveWell = checkedCell.GetFirstThing(Util_CaveBiome.CaveWellDef);
         if (potentialCaveWell == null)
         {
             GenSpawn.Spawn(Util_CaveBiome.CaveWellDef, checkedCell);
         }
     }
 }
示例#23
0
        public bool BuildingDesignatorControl()
        {
            if (Find.CurrentMap == null || Find.DesignatorManager == null)
            {
                return(true);
            }
            var Dem = Find.DesignatorManager.SelectedDesignator;

            if (Dem != null && Dem is Designator_Build)
            {
                if (Event.current.type == EventType.MouseDown && Event.current.button == 2)
                {
                    //Better than UI.mousecell
                    MiddleClickCell = Find.CameraDriver.MapPosition;
                }

                //Middle click to select designator
                if (Event.current.type == EventType.MouseUp && Event.current.button == 2 && MiddleClickCell == Find.CameraDriver.MapPosition)
                {
                    Thing   targetThing = null;
                    IntVec3 UICell      = UI.MouseCell();
                    Map     map         = Find.CurrentMap;
                    if (map == null)
                    {
                        return(false);
                    }
                    if (!UICell.InBounds(map))
                    {
                        return(false);
                    }

                    //Search for blueprints
                    if (targetThing == null)
                    {
                        targetThing = UICell.GetFirstThing <Blueprint>(map);
                    }

                    //Search for frames
                    if (targetThing == null)
                    {
                        targetThing = UICell.GetFirstThing <Frame>(map);
                    }

                    //Search for Buildings
                    if (targetThing == null)
                    {
                        targetThing = UICell.GetFirstBuilding(map);
                    }

                    //Can't find things
                    if (targetThing == null)
                    {
                        //SoundDefOf.ClickReject.PlayOneShotOnCamera();
                        Event.current.Use();
                        return(false);
                    }

                    //Find designator
                    Designator_Build Desig = null;
                    Desig = BuildCopyCommandUtility.FindAllowedDesignator(targetThing.def);

                    if (Desig == null && (targetThing is Blueprint || targetThing is Frame))
                    {
                        Desig = BuildCopyCommandUtility.FindAllowedDesignator(targetThing.def.entityDefToBuild);
                    }

                    if ((targetThing.def.BuildableByPlayer || targetThing.def.entityDefToBuild?.BuildableByPlayer == true) && Desig != null)
                    {
                        //Set stuff

                        if (targetThing.Stuff != null)
                        {
                            Desig.SetStuffDef(targetThing.Stuff);
                        }
                        if ((targetThing as Blueprint_Build)?.stuffToUse != null)
                        {
                            Desig.SetStuffDef((targetThing as Blueprint_Build).stuffToUse);
                        }
                        if ((targetThing as Blueprint_Install)?.Stuff != null)
                        {
                            Desig.SetStuffDef((targetThing as Blueprint_Install).Stuff);
                        }
                        if ((targetThing as Frame)?.Stuff != null)
                        {
                            Desig.SetStuffDef((targetThing as Frame).Stuff);
                        }

                        Find.DesignatorManager.Select(Desig);
                        SoundDefOf.Click.PlayOneShotOnCamera();
                    }
                    else
                    {
                        //SoundDefOf.ClickReject.PlayOneShotOnCamera();
                    }

                    Event.current.Use();
                    return(false);
                }

                //Cancel drag

                //First, absorb Right click event, handle it manually
                if (Event.current.type == EventType.MouseDown && Event.current.button == 1)
                {
                    Event.current.Use();
                }

                if (IsCancelDragging)
                {
                    GenUI.DrawMouseAttachment(CancelIcon, string.Empty, 0);
                }
                if (Input.GetMouseButton(1))
                {
                    if (IsCancelDragging)
                    {
                        //RenderCancelHighlights();
                    }
                    else
                    {
                        //Start cancel dragging

                        IsCancelDragging = true;
                        DragStart        = UI.MouseCell();
                        SoundDefOf.Click.PlayOneShotOnCamera(null);
                    }
                }

                //Right click up
                else if (Event.current.type == EventType.MouseUp && Event.current.button == 1)
                {
                    IsCancelDragging = false;
                    selectedThings.Clear();
                    Event.current.Use();

                    if (selectedThings.Any())
                    {
                        selectedThings.Do(delegate(Thing t) { t.Destroy(DestroyMode.Cancel); });
                        SoundDefOf.Designate_Cancel.PlayOneShotOnCamera();
                    }
                    else
                    {
                        SoundDefOf.CancelMode.PlayOneShotOnCamera(null);
                        Find.DesignatorManager.Deselect();
                        return(false);
                    }
                }

                //While cancel dragging, left click to abort
                if (Event.current.type == EventType.MouseDown && Event.current.button == 0 && IsCancelDragging)
                {
                    selectedThings.Clear();
                    IsCancelDragging = false;
                    SoundDefOf.CancelMode.PlayOneShotOnCamera(null);
                    Find.DesignatorManager.Deselect();
                    Event.current.Use();
                    return(false);
                }

                //Drag to place blueprints

                var BuildDesignator = (Designator_Build)Dem;

                if (BuildDesignator.DraggableDimensions != 0)
                {
                    return(true);
                }

                if (Event.current.type == EventType.MouseDown && Event.current.button == 0)
                {
                    PreviousCell = IntVec3.Invalid;
                    ClickedFlag  = true;
                    Event.current.Use();
                }
                if (Event.current.type == EventType.MouseUp && Event.current.button == 0)
                {
                    PreviousCell = IntVec3.Invalid;
                    ClickedFlag  = false;
                    Event.current.Use();
                }

                if (Input.GetMouseButton(0) && !Mouse.IsInputBlockedNow && PreviousCell != UI.MouseCell() && ClickedFlag)
                {
                    var acceptanceReport = BuildDesignator.CanDesignateCell(UI.MouseCell());

                    if (DebugSettings.godMode && acceptanceReport.Accepted) //Handle god mode
                    {
                        Traverse     t        = Traverse.Create(BuildDesignator);
                        BuildableDef entDef   = t.Field("entDef").GetValue <BuildableDef>();
                        Rot4         rot      = t.Field("placingRot").GetValue <Rot4>();
                        CellRect     cellRect = GenAdj.OccupiedRect(UI.MouseCell(), rot, entDef.Size);
                        foreach (IntVec3 c in cellRect)
                        {
                            var thinglist = c.GetThingList(Find.CurrentMap);
                            for (int i = 0; i < thinglist.Count; i++)
                            {
                                var thing3 = thinglist[i];
                                if (!GenConstruct.CanPlaceBlueprintOver(entDef, thing3.def))
                                {
                                    acceptanceReport = new AcceptanceReport("SpaceAlreadyOccupied_DevFail");
                                }
                            }
                        }
                    }
                    if (acceptanceReport.Accepted)
                    {
                        BuildDesignator.DesignateSingleCell(UI.MouseCell());
                        BuildDesignator.Finalize(true);
                    }
                    else
                    {
                        //If this is first cell clicked
                        if (PreviousCell == IntVec3.Invalid)
                        {
                            Messages.Message(acceptanceReport.Reason, MessageTypeDefOf.SilentInput, false);
                            BuildDesignator.Finalize(false);
                        }
                    }

                    PreviousCell = UI.MouseCell();
                    //Event.current.Use();
                }
                return(false);
            }
            else //This is not Building designator
            {
                IsCancelDragging = false;
                return(true);
            }
        }
        /// <summary>
        /// Check if position is valid to grow a plant. Does not check cluster exclusivity!
        /// </summary>
        public static bool IsValidPositionToGrowPlant(ThingDef_ClusterPlant plantDef, IntVec3 position, bool checkTemperature = true)
        {
            if (position.InBounds() == false)
            {
                return false;
            }
            if (plantDef.isSymbiosisPlant)
            {
                // For symbiosis plant, only check there is a source symbiosis plant.
                if (position.GetFirstThing(plantDef.symbiosisPlantDefSource) != null)
                {
                    return true;
                }
                else
                {
                    return false;
                }
            }
            // Check there is no building or cover.
            if ((position.GetEdifice() != null)
                || (position.GetCover() != null))
            {
                return false;
            }
            // Check terrain condition.
            if (ClusterPlant.CanTerrainSupportPlantAt(plantDef, position) == false)
            {
                return false;
            }
            // Check temperature conditions.
            if (ClusterPlant.IsTemperatureConditionOkAt(plantDef, position) == false)
            {
                return false;
            }
            // Check light conditions.
            if (ClusterPlant.IsLightConditionOkAt(plantDef, position) == false)
            {
                return false;
            }
            // Check there is no other plant.
            if (Find.ThingGrid.ThingAt(position, ThingCategory.Plant) != null)
            {
                return false;
            }
            // Check the cell is not blocked by a plant, an item, a pawn, a rock...
	        List<Thing> thingList = Find.ThingGrid.ThingsListAt(position);
	        for (int thingIndex = 0; thingIndex < thingList.Count; thingIndex++)
	        {
                Thing thing = thingList[thingIndex];
                //Log.Message("checking thing + " + thing.ToString() + " at " + position.ToString());
		        if (thing.def.BlockPlanting)
		        {
			        return false;
		        }
		        if (plantDef.passability == Traversability.Impassable
                    && (thing.def.category == ThingCategory.Pawn
                        || thing.def.category == ThingCategory.Item
                        || thing.def.category == ThingCategory.Building
                        || thing.def.category == ThingCategory.Plant))
		        {
			        return false;
		        }
	        }
            // Check snow level.
            if (GenPlant.SnowAllowsPlanting(position) == false)
            {
                return false;
            }
            return true;
        }
示例#25
0
        public void XenoLordTick()
        {
            if (map != null)
            {
                IntVec3            c             = IntVec3.Invalid;
                Lord               lord          = null;
                List <Lord>        Hivelords     = new List <Lord>();
                Lord               Hivelord      = null;
                LordJob            Hivejob       = null;
                Pawn               Hivequeen     = null;
                IEnumerable <Lord> lords         = pawn.Map.lordManager.lords.Where(x => x.faction == pawn.Faction);
                bool               isDefendPoint = pawn.GetLord() != null?pawn.GetLord().LordJob is LordJob_DefendPoint : false;

                bool isAssaultColony = pawn.GetLord() != null?pawn.GetLord().LordJob is LordJob_AssaultColony : false;

                bool hostsPresent    = map.mapPawns.AllPawnsSpawned.Any(x => x.isPotentialHost() && !x.isCocooned() && IsAcceptablePreyFor(pawn, x, true));
                bool LordReplaceable = (isDefendPoint || (isAssaultColony && !hostsPresent));
                //   Log.Message(string.Format("LordReplaceable: {0}, isDefendPoint: {1}, isAssaultColony: {2}, hostsPresent: {3}", LordReplaceable, isDefendPoint, isAssaultColony, !hostsPresent));
                if (lords.Count() != 0 && ((pawn.GetLord() != null && LordReplaceable) || pawn.GetLord() == null))
                {
                    foreach (var l in lords)
                    {
                        if (l != null)
                        {
                            if (XenomorphUtil.HivelikesPresent(map))
                            {
                                if (l.LordJob is LordJob_DefendAndExpandHiveLike j)
                                {
                                    Hivelord = l;
                                    Hivejob  = j;
                                    if (l.ownedPawns.Any(x => x.kindDef == QueenDef))
                                    {
                                        Hivequeen = l.ownedPawns.Find(x => x.kindDef == QueenDef);
                                    }
                                    if (pawn.kindDef != XenomorphDefOf.RRY_Xenomorph_Queen || (pawn.kindDef == XenomorphDefOf.RRY_Xenomorph_Queen && Hivequeen != null))
                                    {
                                        Hivelords.Add(l);
                                    }
                                }
                            }
                            else if (XenomorphUtil.HiveSlimePresent(map))
                            {
                                if (l.LordJob is LordJob_DefendHiveLoc j)
                                {
                                    Hivelord = l;
                                    Hivejob  = j;
                                    if (l.ownedPawns.Any(x => x.kindDef == QueenDef))
                                    {
                                        Hivequeen = l.ownedPawns.Find(x => x.kindDef == QueenDef);
                                    }
                                    if (pawn.kindDef != XenomorphDefOf.RRY_Xenomorph_Queen || (pawn.kindDef == XenomorphDefOf.RRY_Xenomorph_Queen && Hivequeen != null))
                                    {
                                        Hivelords.Add(l);
                                    }
                                }
                            }
                        }
                        else
                        {
                            /*
                             * lord = l;
                             * lord.AddPawn(pawn);
                             * pawn.mindState.duty = lord.ownedPawns.FindAll(x => x.mindState.duty != null && x != pawn).RandomElement().mindState.duty;
                             * break;
                             */
                        }
                    }
                }
                if (pawn.GetLord() != null && LordReplaceable)
                {
                    lord = pawn.GetLord();
                    if (lord.ownedPawns.Count == 0)
                    {
                        Log.Message(string.Format("got no pawns, wtf?"));
                    }
                    if (lord.ownedPawns.Count == 1)
                    {
                    }
                    if (c == IntVec3.Invalid && XenomorphUtil.HivelikesPresent(map))
                    {
                        c = !XenomorphUtil.ClosestReachableHivelike(pawn).DestroyedOrNull() ? XenomorphUtil.ClosestReachableHivelike(pawn).Position : IntVec3.Invalid;
                    }
                    if (c == IntVec3.Invalid && XenomorphUtil.EggsPresent(map))
                    {
                        c = !XenomorphUtil.ClosestReachableEgg(pawn).DestroyedOrNull() ? XenomorphUtil.ClosestReachableEgg(pawn).Position : IntVec3.Invalid;
                    }
                    if (c == IntVec3.Invalid && XenomorphUtil.CocoonsPresent(map, XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon))
                    {
                        c = !XenomorphUtil.ClosestReachableCocoon(pawn, XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon).DestroyedOrNull() ? XenomorphUtil.ClosestReachableCocoon(pawn, XenomorphDefOf.RRY_Xenomorph_Humanoid_Cocoon).Position : IntVec3.Invalid;
                    }
                    if (c == IntVec3.Invalid && XenomorphUtil.CocoonsPresent(map, XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon))
                    {
                        c = !XenomorphUtil.ClosestReachableCocoon(pawn, XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon).DestroyedOrNull() ? XenomorphUtil.ClosestReachableCocoon(pawn, XenomorphDefOf.RRY_Xenomorph_Animal_Cocoon).Position : IntVec3.Invalid;
                    }
                    if (c == IntVec3.Invalid)
                    {
                        if (InfestationLikeCellFinder.TryFindCell(out c, pawn.Map, false))
                        {
                            if (Prefs.DevMode)
                            {
                                ThingDef td = XenomorphDefOf.RRY_Filth_Slime;
                                GenSpawn.Spawn(td, c, pawn.Map);
                                Find.LetterStack.ReceiveLetter(string.Format("Lord Created"), string.Format("@: {0} ", c), LetterDefOf.NegativeEvent, c.GetFirstThing(pawn.Map, td), null, null);
                            }
                        }
                        if (pawn.CanReach(c, PathEndMode.OnCell, Danger.Deadly, true))
                        {
                            c = RCellFinder.RandomWanderDestFor(pawn, c, 3f, null, Danger.Some);
                        }
                        else
                        {
                            c = RCellFinder.RandomWanderDestFor(pawn, pawn.Position, 3f, null, Danger.Some);
                        }
                    }
                    if (c != IntVec3.Invalid)
                    {
                        LordJob newJob;
                        if (XenomorphUtil.HivelikesPresent(map))
                        {
                            newJob = new LordJob_DefendAndExpandHiveLike(false);
                        }
                        else
                        {
                            newJob = new LordJob_DefendHiveLoc(parent.Faction, c);
                        }
                        if (LordReplaceable)
                        {
                            if (!Hivelords.NullOrEmpty())
                            {
                                Hivelord = Hivelords.RandomElement();
                                SwitchToLord(Hivelord);
                                CreateNewLord(pawn, c, newJob);
                            }
                            else
                            {
                                CreateNewLord(pawn, c, newJob);
                            }
                            if (HiveLoc == IntVec3.Invalid)
                            {
                                HiveLoc = c;
                            }
                        }
                    }
                }
                else if (c == IntVec3.Invalid && (pawn.GetLord() != null && pawn.GetLord().LordJob is LordJob LordJob))
                {
                    lord = pawn.GetLord();
                    c    = LordJob.lord.Graph.StartingToil.FlagLoc;
                    if (c == IntVec3.Invalid)
                    {
                        c = LordJob.lord.CurLordToil.FlagLoc;
                    }
                }
                else if (pawn.GetLord() == null)
                {
                    if (!Hivelords.NullOrEmpty())
                    {
                        Hivelord = Hivelords.RandomElement();
                        SwitchToLord(Hivelord);
                    }
                }
                if (pawn.GetLord() != null)
                {
                    List <Pawn> list = pawn.GetLord().ownedPawns.Where(x => x.mindState.duty != null).ToList();
                    if (pawn.GetLord() != null && pawn.mindState.duty == null && !list.NullOrEmpty())
                    {
                        pawn.mindState.duty = list.RandomElement().mindState.duty;
                    }
                }
            }
        }
示例#26
0
 internal bool <> m__0(IntVec3 x)
 {
     return(InfestationCellFinder.GetScoreAt(x, this.map) > 0f && x.GetFirstThing(this.map, ThingDefOf.Hive) == null && x.GetFirstThing(this.map, ThingDefOf.TunnelHiveSpawner) == null);
 }
示例#27
0
        /// <summary>
        /// Check if position is valid to grow a plant. Does not check cluster exclusivity!
        /// </summary>
        public static bool IsValidPositionToGrowPlant(ThingDef_ClusterPlant plantDef, Map map, IntVec3 position, bool checkTemperature = true)
        {
            if (position.InBounds(map) == false)
            {
                return(false);
            }
            if (plantDef.isSymbiosisPlant)
            {
                // For symbiosis plant, only check there is a source symbiosis plant.
                if (position.GetFirstThing(map, plantDef.symbiosisPlantDefSource) != null)
                {
                    return(true);
                }
                else
                {
                    return(false);
                }
            }
            // Check there is no building or cover.
            if ((position.GetEdifice(map) != null) ||
                (position.GetCover(map) != null))
            {
                return(false);
            }
            // Check terrain condition.
            if (ClusterPlant.CanTerrainSupportPlantAt(plantDef, map, position) == false)
            {
                return(false);
            }
            // Check temperature conditions.
            if (ClusterPlant.IsTemperatureConditionOkAt(plantDef, map, position) == false)
            {
                return(false);
            }
            // Check light conditions.
            if (ClusterPlant.IsLightConditionOkAt(plantDef, map, position) == false)
            {
                return(false);
            }
            // Check there is no other plant.
            if (map.thingGrid.ThingAt(position, ThingCategory.Plant) != null)
            {
                return(false);
            }
            // Check the cell is not blocked by a plant, an item, a pawn, a rock...
            List <Thing> thingList = map.thingGrid.ThingsListAt(position);

            for (int thingIndex = 0; thingIndex < thingList.Count; thingIndex++)
            {
                Thing thing = thingList[thingIndex];
                if (thing.def.BlockPlanting)
                {
                    return(false);
                }
                if (plantDef.passability == Traversability.Impassable &&
                    (thing.def.category == ThingCategory.Pawn ||
                     thing.def.category == ThingCategory.Item ||
                     thing.def.category == ThingCategory.Building ||
                     thing.def.category == ThingCategory.Plant))
                {
                    return(false);
                }
            }
            // Check snow level.
            if (GenPlant.SnowAllowsPlanting(position, map) == false)
            {
                return(false);
            }
            return(true);
        }
        public override void ExplosionAffectCell(Explosion explosion, IntVec3 c, List <Thing> damagedThings, List <Thing> ignoredThings, bool canThrowMotes)
        {
            if (this.def.explosionCellMote != null && canThrowMotes)
            {
                Mote mote = c.GetFirstThing(explosion.Map, this.def.explosionCellMote) as Mote;
                if (mote != null)
                {
                    mote.spawnTick = Find.TickManager.TicksGame;
                }
                else
                {
                    float t     = Mathf.Clamp01((explosion.Position - c).LengthHorizontal / explosion.radius);
                    Color color = Color.Lerp(this.def.explosionColorCenter, this.def.explosionColorEdge, t);
                    PurpleIvyMoteMaker.ThrowExplosionCell(c, explosion.Map, this.def.explosionCellMote, color);
                }
            }
            DamageWorker_AddInjuryNoCamShaker.thingsToAffect.Clear();
            float        num  = float.MinValue;
            bool         flag = false;
            List <Thing> list = explosion.Map.thingGrid.ThingsListAt(c);

            for (int i = 0; i < list.Count; i++)
            {
                Thing thing = list[i];
                if (thing.def.category != ThingCategory.Mote && thing.def.category != ThingCategory.Ethereal)
                {
                    if (thing.Faction != PurpleIvyData.AlienFaction)
                    {
                        DamageWorker_AddInjuryNoCamShaker.thingsToAffect.Add(thing);
                        if (thing.def.Fillage == FillCategory.Full && thing.def.Altitude > num)
                        {
                            flag = true;
                            num  = thing.def.Altitude;
                        }
                    }
                }
            }
            for (int j = 0; j < DamageWorker_AddInjuryNoCamShaker.thingsToAffect.Count; j++)
            {
                if (DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j].def.Altitude >= num)
                {
                    if (DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j] is Pawn)
                    {
                        Pawn pawn = (Pawn)DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j];
                        if (Rand.Chance(0.3f))
                        {
                            pawn.stances.stunner.StunFor(Rand.RangeInclusive(100, 200), explosion.instigator);
                        }
                    }
                    this.ExplosionDamageThing(explosion, DamageWorker_AddInjuryNoCamShaker.thingsToAffect[j], damagedThings, ignoredThings, c);
                }
            }
            if (!flag)
            {
                this.ExplosionDamageTerrain(explosion, c);
            }
            if (this.def.explosionSnowMeltAmount > 0.0001f)
            {
                float lengthHorizontal = (c - explosion.Position).LengthHorizontal;
                float num2             = 1f - lengthHorizontal / explosion.radius;
                if (num2 > 0f)
                {
                    explosion.Map.snowGrid.AddDepth(c, -num2 * this.def.explosionSnowMeltAmount);
                }
            }
            if (this.def == DamageDefOf.Bomb || this.def == DamageDefOf.Flame)
            {
                List <Thing> list2 = explosion.Map.listerThings.ThingsOfDef(ThingDefOf.RectTrigger);
                for (int k = 0; k < list2.Count; k++)
                {
                    RectTrigger rectTrigger = (RectTrigger)list2[k];
                    if (rectTrigger.activateOnExplosion && rectTrigger.Rect.Contains(c))
                    {
                        rectTrigger.ActivatedBy(null);
                    }
                }
            }
        }
示例#29
0
 protected override bool IsValidTile(Map map, IntVec3 pos)
 {
     return(base.IsValidTile(map, pos) && pos.GetFirstThing <Thing>(map) == null);
 }
 public static bool StackableAtEx(ThingDef def, IntVec3 storeCell, Map map)
 {
     Log.Message($"StackableAtEx {def}@{storeCell}, {storeCell.GetFirstThing<ExtendedStorage.Building_ExtendedStorage>(map) != null}");
     return(storeCell.GetFirstThing <ExtendedStorage.Building_ExtendedStorage>(map) != null);
     // && storage.StoredThingDef == def //StoredThingDef is internal? okay then
 }
 bool IsValidChairTile(Map map, IntVec3 pos)
 {
     return(pos.GetFirstThing <Building>(map) == null);
 }
示例#32
0
 private static void SpawnShrapnel(ThingDef def, int quantity, IntVec3 center, Map map, float angle, float distanceFactor)
 {
     for (int i = 0; i < quantity; i++)
     {
         IntVec3 intVec = GenerateShrapnelLocation(center, angle, distanceFactor);
         if (IsGoodShrapnelCell(intVec, map) && (def.category != ThingCategory.Item || intVec.GetFirstItem(map) == null) && intVec.GetFirstThing(map, def) == null)
         {
             GenSpawn.Spawn(def, intVec, map);
         }
     }
 }