Exemplo n.º 1
0
        // When the robot is idle, check if it is inside the room of the recharge station. If not, return there.
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            X2_AIRobot robot = pawn as X2_AIRobot;

            if (robot.DestroyedOrNull())
            {
                return(ThinkResult.NoJob);
            }
            if (!robot.Spawned)
            {
                return(ThinkResult.NoJob);
            }

            X2_Building_AIRobotRechargeStation rechargeStation = robot.rechargeStation;

            if (rechargeStation.DestroyedOrNull())
            {
                return(ThinkResult.NoJob);
            }
            if (!rechargeStation.Spawned)
            {
                return(ThinkResult.NoJob);
            }


            Need_Rest needRest = pawn.needs.rest;

            if (needRest == null)
            {
                return(ThinkResult.NoJob);
            }

            float curLevel = needRest.CurLevel;

            Job jobIdle = new Job(DefDatabase <JobDef> .GetNamed("AIRobot_GoAndWait"), rechargeStation);

            jobIdle.locomotionUrgency = LocomotionUrgency.Amble;

            if (curLevel > 0.751f)
            {
                return(new ThinkResult(jobIdle, this, JobTag.Idle, false));
            }

            //double distance = AIRobot_Helper.GetDistance(pawn.Position, (pawn as X2_AIRobot).rechargeStation.Position);
            //
            //if (distance > 5f)
            //    return ThinkResult.NoJob;

            //Boolean isInDistance = AIRobot_Helper.IsInDistance(pawn.Position, (pawn as X2_AIRobot).rechargeStation.Position, 5);
            //if (isInDistance)
            //    return ThinkResult.NoJob;

            Job job = new Job(DefDatabase <JobDef> .GetNamed("AIRobot_GoRecharge"), rechargeStation);

            job.locomotionUrgency = LocomotionUrgency.Amble;

            return(new ThinkResult(job, this, JobTag.SatisfyingNeeds, false));
        }
Exemplo n.º 2
0
        public override void ExposeData()
        {
            try
            {
                try
                {
                    base.ExposeData();
                }
                catch (Exception ex)
                {
                    Log.Warning("Warning: X2_Building_AIRobot_RechargeStation -- Unknown error while loading base->ExposeData:\n" + ex.Message + "\n" + ex.StackTrace);
                }

                Scribe_Values.Look <bool>(ref this.robotSpawnedOnce, "robotSpawned", false);
                Scribe_Values.Look <bool>(ref this.robotIsDestroyed, "robotDestroyed", false);
                Scribe_Values.Look <bool>(ref this.SpawnRobotAfterRecharge, "autospawn", true);
                Scribe_Values.Look <bool>(ref this.isRechargeActive, "isRechargeActive", false);
                Scribe_Values.Look <bool>(ref this.isRepairRequestActive, "isRepairRequestActive", false);

                try
                {
                    if (Scribe.mode == LoadSaveMode.Saving && robot != null && robot.DestroyedOrNull())
                    {
                        robot = null;
                    }
                    Scribe_References.Look <X2_AIRobot>(ref robot, "robot", false); // must be before Scribe_Collections -> Else errors!
                }
                catch (Exception ex)
                {
                    Log.Warning("Warning: X2_Building_AIRobot_RechargeStation -- Error while loading 'robot':\n" + ex.Message + "\n" + ex.StackTrace);
                }

                try
                {
                    Scribe_Collections.Look <X2_AIRobot>(ref this.container, "container", LookMode.Deep, null); // new object[0]); -> Throws errors!
                }
                catch (Exception ex)
                {
                    Log.Warning("Warning: X2_Building_AIRobot_RechargeStation -- Error while loading 'container':\n" + ex.Message + "\n" + ex.StackTrace);
                }
            }
            catch (Exception ex)
            {
                Log.Error("X2_Building_AIRobot_RechargeStation -- Unknown error while loading:\n" + ex.Message + "\n" + ex.StackTrace);
            }

            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                updateGraphicForceNeeded = true;

                if (container == null)
                {
                    ClearContainer();
                }
            }
        }
        // When the robot is idle, check if it is inside the room of the recharge station. If not, return there.
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            X2_AIRobot robot = pawn as X2_AIRobot;

            if (robot.DestroyedOrNull())
            {
                return(ThinkResult.NoJob);
            }
            if (!robot.Spawned)
            {
                return(ThinkResult.NoJob);
            }

            X2_Building_AIRobotRechargeStation rechargeStation = robot.rechargeStation;

            if (rechargeStation.DestroyedOrNull())
            {
                return(ThinkResult.NoJob);
            }
            if (!rechargeStation.Spawned)
            {
                return(ThinkResult.NoJob);
            }

            Room roomRecharge = rechargeStation.Position.GetRoom(rechargeStation.Map);
            Room roomRobot    = robot.Position.GetRoom(robot.Map);

            if (roomRecharge == roomRobot)
            {
                return(ThinkResult.NoJob);
            }

            // Find target pos, but max 10 cells away!
            Map     mapRecharge = rechargeStation.Map;
            IntVec3 posRecharge = rechargeStation.Position;
            IntVec3 cell        = roomRecharge.Cells.Where(c =>
                                                           c.Standable(mapRecharge) && !c.IsForbidden(pawn) &&
                                                           AIRobot_Helper.IsInDistance(c, posRecharge, 10) &&
                                                           pawn.CanReach(c, PathEndMode.OnCell, Danger.Some, false, TraverseMode.ByPawn)
                                                           )
                                  .FirstOrDefault();

            if (cell == null || cell == IntVec3.Invalid)
            {
                return(ThinkResult.NoJob);
            }

            Job jobGoto = new Job(JobDefOf.Goto, cell);

            jobGoto.locomotionUrgency = LocomotionUrgency.Amble;

            return(new ThinkResult(jobGoto, this, JobTag.Misc, false));
        }
        private void TryUpdateAllowedArea(X2_AIRobot robot)
        {
            if (robot.DestroyedOrNull() || !robot.Spawned)
            {
                return;
            }
            if (ForbidUtility.InAllowedArea(this.Position, robot))
            {
                return;
            }

            Messages.Message("AIRobot_MessageRechargeStationOutsideAreaRestriction".Translate(), robot, MessageTypeDefOf.RejectInput);

            //Remove area from robot
            robot.playerSettings.Notify_AreaRemoved(robot.playerSettings.AreaRestriction);
        }
        public override void ExposeData()
        {
            try
            {
                try
                {
                    base.ExposeData();
                }
                catch (Exception ex)
                {
                    Log.Warning("Warning: X2_Building_AIRobot_RechargeStation -- Unknown error while loading base->ExposeData:\n" + ex.Message + "\n" + ex.StackTrace);
                }

                Scribe_Values.Look <bool>(ref this.robotSpawnedOnce, "robotSpawned", false);
                Scribe_Values.Look <bool>(ref this.robotIsDestroyed, "robotDestroyed", false);
                Scribe_Values.Look <bool>(ref this.SpawnRobotAfterRecharge, "autospawn", true);
                Scribe_Values.Look <bool>(ref this.isRechargeActive, "isRechargeActive", false);
                Scribe_Values.Look <bool>(ref this.isRepairRequestActive, "isRepairRequestActive", false);
                Scribe_Collections.Look <ThingDef, int>(ref this.isRepairRequestCosts, "isRepairRequestCosts", LookMode.Def, LookMode.Value);

                try
                {
                    if (Scribe.mode == LoadSaveMode.Saving && robot != null && robot.DestroyedOrNull())
                    {
                        robot = null;
                    }
                    Scribe_References.Look <X2_AIRobot>(ref robot, "robot", false); // must be before Scribe_Collections -> Else errors!
                }
                catch (Exception ex)
                {
                    Log.Warning("Warning: X2_Building_AIRobot_RechargeStation -- Error while loading 'robot':\n" + ex.Message + "\n" + ex.StackTrace);
                }

                try
                {
                    Scribe_Collections.Look <X2_AIRobot>(ref this.container, "container", LookMode.Deep, null); // new object[0]); -> Throws errors!
                }
                catch (Exception ex)
                {
                    Log.Warning("Warning: X2_Building_AIRobot_RechargeStation -- Error while loading 'container':\n" + ex.Message + "\n" + ex.StackTrace);
                }
            }
            catch (Exception ex)
            {
                Log.Error("X2_Building_AIRobot_RechargeStation -- Unknown error while loading:\n" + ex.Message + "\n" + ex.StackTrace);
            }

            if (Scribe.mode == LoadSaveMode.PostLoadInit)
            {
                updateGraphicForceNeeded = true;

                if (container == null)
                {
                    ClearContainer();
                }

                //// Check/update faction - Disabled, this is causing problems..
                //if (robot != null)
                //{
                //    if (this.Faction != null && (robot.Faction == null || robot.Faction != this.Faction))
                //        robot.SetFactionDirect(this.Faction);
                //    if (robot.Faction == null && Faction.OfPlayerSilentFail != null)
                //        robot.SetFactionDirect(Faction.OfPlayerSilentFail);
                //}
            }
        }