public override Job JobOnThing(Pawn pawn, Thing t)
        {
            Building_LaserFencePylon pylon = t as Building_LaserFencePylon;
            Job job = new Job(DefDatabase <JobDef> .GetNamed("JobDef_SwitchLaserFence"), pylon);

            return(job);
        }
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Thing thingToIgnore = null)
        {
            string reason          = "";
            bool   canBePlacedHere = Building_LaserFencePylon.CanPlaceNewPylonHere(this.Map, loc, out reason);

            if (canBePlacedHere == false)
            {
                return(new AcceptanceReport(reason));
            }

            // Display potential placing positions.
            foreach (Thing pylon in this.Map.listerThings.ThingsOfDef(ThingDef.Named("LaserFencePylon").blueprintDef))
            {
                if (pylon.Position.InHorDistOf(loc, 6f))
                {
                    Building_LaserFencePylon.DrawPotentialPlacePositions(this.Map, pylon.Position);
                }
            }
            foreach (Thing pylon in this.Map.listerThings.ThingsOfDef(ThingDef.Named("LaserFencePylon").frameDef))
            {
                if (pylon.Position.InHorDistOf(loc, 6f))
                {
                    Building_LaserFencePylon.DrawPotentialPlacePositions(this.Map, pylon.Position);
                }
            }
            foreach (Thing pylon in this.Map.listerThings.ThingsOfDef(ThingDef.Named("LaserFencePylon")))
            {
                if (pylon.Position.InHorDistOf(loc, 6f))
                {
                    Building_LaserFencePylon.DrawPotentialPlacePositions(this.Map, pylon.Position);
                }
            }

            return(true);
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t)
        {
            if ((t is Building_LaserFencePylon) == false)
            {
                return(false);
            }
            if (pawn.CanReserveAndReach(t, PathEndMode.Touch, Danger.Deadly) == false)
            {
                return(false);
            }

            Building_LaserFencePylon pylon = t as Building_LaserFencePylon;

            if (pawn.Dead ||
                pawn.Downed ||
                pawn.IsBurning())
            {
                return(false);
            }
            if (pylon.manualSwitchIsPending)
            {
                return(true);
            }
            return(false);
        }
示例#4
0
        private void TryToConnectToPylon(Building_LaserFencePylon linkedPylon, Rot4 direction, int fenceLength, bool forceConnection)
        {
            Rot4 linkedPylonDirection = direction;

            linkedPylonDirection.Rotate(RotationDirection.Clockwise); // Rotate 2 times to get the opposite direction.
            linkedPylonDirection.Rotate(RotationDirection.Clockwise);
            // Check connection is allowed.
            if (forceConnection)
            {
                linkedPylon.connectionIsAllowedByUser[linkedPylonDirection.AsInt]       = true;
                linkedPylon.cachedConnectionIsAllowedByUser[linkedPylonDirection.AsInt] = true;
            }
            if (linkedPylon.connectionIsAllowedByUser[linkedPylonDirection.AsInt] == false)
            {
                this.connectionIsAllowedByUser[direction.AsInt]       = false;
                this.cachedConnectionIsAllowedByUser[direction.AsInt] = false;
                return;
            }
            // Check linkedPylon is powered.
            CompPowerTrader linkedPowerComp = linkedPylon.TryGetComp <CompPowerTrader>();

            if ((linkedPowerComp != null) &&
                linkedPowerComp.PowerOn)
            {
                if (linkedPylon.linkedPylons[linkedPylonDirection.AsInt] != null)
                {
                    // If linkedPylon is already connected to a third pylon, first disconnect from it.
                    linkedPylon.DisconnectFromPylon(linkedPylonDirection);
                }
                this.linkedPylons[direction.AsInt] = linkedPylon;
                this.ActivateFence(direction, fenceLength);
                linkedPylon.linkedPylons[linkedPylonDirection.AsInt] = this;
                linkedPylon.ActivateFence(linkedPylonDirection, fenceLength);
            }
        }
示例#5
0
 public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null)
 {
     // Display potential build cells.
     foreach (Thing pylon in map.listerThings.ThingsOfDef(Util_LaserFence.LaserFencePylonDef.blueprintDef))
     {
         if (pylon.Position.InHorDistOf(loc, 6f))
         {
             Building_LaserFencePylon.DrawPotentialBuildCells(map, pylon.Position);
         }
     }
     foreach (Thing pylon in map.listerThings.ThingsOfDef(Util_LaserFence.LaserFencePylonDef.frameDef))
     {
         if (pylon.Position.InHorDistOf(loc, 6f))
         {
             Building_LaserFencePylon.DrawPotentialBuildCells(map, pylon.Position);
         }
     }
     foreach (Thing pylon in map.listerThings.ThingsOfDef(Util_LaserFence.LaserFencePylonDef))
     {
         if (pylon.Position.InHorDistOf(loc, 6f))
         {
             Building_LaserFencePylon.DrawPotentialBuildCells(map, pylon.Position);
         }
     }
     return(true);
 }
示例#6
0
        public override void DrawGhost(ThingDef def, IntVec3 center, Rot4 rot, Color ghostCol)
        {
            Map currentMap = Find.CurrentMap;

            // Display potential build cells.
            foreach (Thing pylon in currentMap.listerThings.ThingsOfDef(Util_LaserFence.LaserFencePylonDef.blueprintDef))
            {
                if (pylon.Position.InHorDistOf(center, Settings.laserFenceMaxRange + 2f))
                {
                    Building_LaserFencePylon.DrawPotentialBuildCells(currentMap, pylon.Position);
                }
            }
            foreach (Thing pylon in currentMap.listerThings.ThingsOfDef(Util_LaserFence.LaserFencePylonDef.frameDef))
            {
                if (pylon.Position.InHorDistOf(center, Settings.laserFenceMaxRange + 2f))
                {
                    Building_LaserFencePylon.DrawPotentialBuildCells(currentMap, pylon.Position);
                }
            }
            foreach (Thing pylon in currentMap.listerThings.ThingsOfDef(Util_LaserFence.LaserFencePylonDef))
            {
                if (pylon.Position.InHorDistOf(center, Settings.laserFenceMaxRange + 2f))
                {
                    Building_LaserFencePylon.DrawPotentialBuildCells(currentMap, pylon.Position);
                }
            }
        }
 /// <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);
             }
         }
     }
 }
示例#8
0
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_LaserFencePylon pylon = t as Building_LaserFencePylon;

            if (pylon == null)
            {
                return(false);
            }
            if (pawn.CanReserveAndReach(pylon, PathEndMode.InteractionCell, Danger.Deadly) == false)
            {
                return(false);
            }

            if (pawn.Dead ||
                pawn.Downed ||
                pawn.IsBurning())
            {
                return(false);
            }
            if (pylon.manualSwitchIsPending)
            {
                return(true);
            }
            return(false);
        }
        /// <summary>
        /// Connect to a given pylon if allowed or forced.
        /// </summary>
        public void TryConnectToPylon(Building_LaserFencePylon linkedPylon, Rot4 direction, int fenceLength, bool forceConnection, bool pawnIsPresent)
        {
            // Check connection is allowed.
            if (forceConnection)
            {
                linkedPylon.connectionIsAllowed[direction.Opposite.AsInt]       = true;
                linkedPylon.cachedConnectionIsAllowed[direction.Opposite.AsInt] = true;
                TryNotifyConsoleConfigurationChanged();
            }
            if (pawnIsPresent)
            {
                // Avoid connecting when a neutral pawn is in the path but set new configuration so connection will actually happen when pawn will move.
                return;
            }
            if (linkedPylon.connectionIsAllowed[direction.Opposite.AsInt] == false)
            {
                this.connectionIsAllowed[direction.AsInt]       = false;
                this.cachedConnectionIsAllowed[direction.AsInt] = false;
                TryNotifyConsoleConfigurationChanged();
                return;
            }
            // Check linkedPylon is powered.
            CompPowerTrader linkedPowerComp = linkedPylon.TryGetComp <CompPowerTrader>();

            if ((linkedPowerComp != null) &&
                linkedPowerComp.PowerOn)
            {
                this.ActivateFence(direction, fenceLength);
                linkedPylon.ActivateFence(direction.Opposite, fenceLength);
            }
        }
 /// <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);
     }
 }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_LaserFencePylon pylon = t as Building_LaserFencePylon;

            if (pylon == null)
            {
                return(false);
            }
            if (pylon.IsForbidden(pawn) ||
                pylon.IsBurning() ||
                (pylon.manualSwitchIsPending == false) ||
                (pawn.CanReserveAndReach(pylon, this.PathEndMode, pawn.NormalMaxDanger()) == false) ||
                (pylon.Map.designationManager.DesignationOn(pylon, DesignationDefOf.Uninstall) != null))
            {
                return(false);
            }
            return(true);
        }
        public override AcceptanceReport  AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot)
        {
            string reason          = "";
            bool   canBePlacedHere = Building_LaserFencePylon.CanPlaceNewPylonHere(loc, out reason);

            if (canBePlacedHere == false)
            {
                return(new AcceptanceReport(reason));
            }

            // Removed as it is consuming too much CPU when there are many pylons.

            /*// Display potential placing positions.
             * foreach (Building_LaserFencePylon pylon in Find.ListerBuildings.AllBuildingsColonistOfClass<Building_LaserFencePylon>())
             * {
             *  pylon.DrawPotentialPlacePositions();
             * }*/

            return(true);
        }
示例#13
0
        public static void DrawPotentialPlacePositions(Map map, IntVec3 pylonPosition)
        {
            List <IntVec3> potentialPlacingPositionsList = new List <IntVec3>();

            for (int directionAsInt = 0; directionAsInt < 4; directionAsInt++)
            {
                for (int offset = 1; offset <= 5; offset++)
                {
                    string  unusedReason   = "";
                    IntVec3 testedPosition = pylonPosition + new IntVec3(offset, 0, 0).RotatedBy(new Rot4(directionAsInt));
                    if (Building_LaserFencePylon.CanPlaceNewPylonHere(map, testedPosition, out unusedReason))
                    {
                        potentialPlacingPositionsList.Add(testedPosition);
                    }
                }
                if (potentialPlacingPositionsList.NullOrEmpty() == false)
                {
                    GenDraw.DrawFieldEdges(potentialPlacingPositionsList);
                }
            }
        }
        /// <summary>
        /// Connect to a given pylon if allowed or forced.
        /// </summary>
        public void TryConnectToPylon(Building_LaserFencePylon linkedPylon, Rot4 direction, int fenceLength, bool forceConnection)
        {
            // Check connection is allowed.
            if (forceConnection)
            {
                linkedPylon.connectionIsAllowedByUser[direction.Opposite.AsInt]       = true;
                linkedPylon.cachedConnectionIsAllowedByUser[direction.Opposite.AsInt] = true;
            }
            if (linkedPylon.connectionIsAllowedByUser[direction.Opposite.AsInt] == false)
            {
                this.connectionIsAllowedByUser[direction.AsInt]       = false;
                this.cachedConnectionIsAllowedByUser[direction.AsInt] = false;
                return;
            }
            // Check linkedPylon is powered.
            CompPowerTrader linkedPowerComp = linkedPylon.TryGetComp <CompPowerTrader>();

            if ((linkedPowerComp != null) &&
                linkedPowerComp.PowerOn)
            {
                this.ActivateFence(direction, fenceLength);
                linkedPylon.ActivateFence(direction.Opposite, fenceLength);
            }
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_LaserFencePylon pylon = t as Building_LaserFencePylon;

            return(new Job(Util_LaserFence.SwitchLaserFenceDef, pylon));
        }
 private void TryToConnectToPylon(Building_LaserFencePylon linkedPylon, Rot4 direction, int fenceLength, bool forceConnection)
 {
     Rot4 linkedPylonDirection = direction;
     linkedPylonDirection.Rotate(RotationDirection.Clockwise); // Rotate 2 times to get the opposite direction.
     linkedPylonDirection.Rotate(RotationDirection.Clockwise);
     // Check connection is allowed.
     if (forceConnection)
     {
         linkedPylon.connectionIsAllowedByUser[linkedPylonDirection.AsInt] = true;
         linkedPylon.cachedConnectionIsAllowedByUser[linkedPylonDirection.AsInt] = true;
     }
     if (linkedPylon.connectionIsAllowedByUser[linkedPylonDirection.AsInt] == false)
     {
         this.connectionIsAllowedByUser[direction.AsInt] = false;
         this.cachedConnectionIsAllowedByUser[direction.AsInt] = false;
         return;
     }
     // Check linkedPylon is powered.
     CompPowerTrader linkedPowerComp = linkedPylon.TryGetComp<CompPowerTrader>();
     if ((linkedPowerComp != null)
         && linkedPowerComp.PowerOn)
     {
         if (linkedPylon.linkedPylons[linkedPylonDirection.AsInt] != null)
         {
             // If linkedPylon is already connected to a third pylon, first disconnect from it.
             linkedPylon.DisconnectFromPylon(linkedPylonDirection);
         }
         this.linkedPylons[direction.AsInt] = linkedPylon;
         this.ActivateFence(direction, fenceLength);
         linkedPylon.linkedPylons[linkedPylonDirection.AsInt] = this;
         linkedPylon.ActivateFence(linkedPylonDirection, fenceLength);
     }
 }