Ejemplo n.º 1
0
        //
        // Methods
        //
        public void AddRobotToContainer(ArcBaseRobot bot)
        {
            bool flag = AttachmentUtility.HasAttachment(bot, ThingDefOf.Fire);

            if (flag)
            {
                AttachmentUtility.GetAttachment(bot, ThingDefOf.Fire).Destroy(0);
            }
            bot.stances.CancelBusyStanceHard();
            bot.jobs.StopAll(false);
            bot.pather.StopDead();
            bool drafted = bot.Drafted;

            if (drafted)
            {
                bot.drafter.Drafted = false;
            }
            bool flag2 = !this.container.Contains(bot);

            if (flag2)
            {
                this.container.Add(bot);
            }
            List <Map> maps = Find.Maps;

            for (int i = 0; i < maps.Count; i++)
            {
                maps [i].designationManager.RemoveAllDesignationsOn(bot, false);
            }
            this.DespawnRobot(bot, false);
        }
        protected override bool Satisfied(Pawn pawn)
        {
            bool flag = this.workType == null;
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                ArcBaseRobot bot   = pawn as ArcBaseRobot;
                bool         flag2 = bot == null;
                if (flag2)
                {
                    result = false;
                }
                else
                {
                    ThingDef_BaseRobot thingDef_bot = bot.def as ThingDef_BaseRobot;
                    bool flag3 = thingDef_bot == null;
                    result = (!flag3 && bot.CanDoWorkType(this.workType));
                }
            }
            return(result);
        }
Ejemplo n.º 3
0
        //
        // Static Methods
        //
        public static Building_BaseRobotRechargeStation TryFindRechargeStation(ArcBaseRobot bot, Map map)
        {
            if (map == null && bot.rechargeStation != null)
            {
                map = bot.rechargeStation.Map;
            }
            if (map == null)
            {
                map = bot.Map;
            }

            Building_BaseRobotRechargeStation result;

            if (map == null)
            {
                result = null;
            }
            else
            {
                IEnumerable <Building_BaseRobotRechargeStation> enumerable = map.listerBuildings.AllBuildingsColonistOfClass <Building_BaseRobotRechargeStation> ();
                if (enumerable == null)
                {
                    result = null;
                }
                else
                {
                    Building_BaseRobotRechargeStation Building_BaseRobotRechargeStation = (from t in enumerable
                                                                                           where t.robot == bot
                                                                                           select t).FirstOrDefault <Building_BaseRobotRechargeStation> ();
                    result = Building_BaseRobotRechargeStation;
                }
            }
            return(result);
        }
Ejemplo n.º 4
0
        private void Button_SpawnBot()
        {
            bool flag = this.robot != null || this.robotIsDestroyed;

            if (!flag)
            {
                bool flag2 = GenText.NullOrEmpty(this.spawnThingDef);
                if (flag2)
                {
                    Log.Error("Robot Recharge Station: Wanted to spawn robot, but spawnThingDef is null or empty!");
                }
                else
                {
                    bool         flag3 = !this.IsRobotInContainer();
                    ArcBaseRobot bot;
                    if (flag3)
                    {
                        bot = Building_BaseRobotCreator.CreateRobot(this.spawnThingDef, base.Position, base.Map, Faction.OfPlayer);
                    }
                    else
                    {
                        bot = this.container [0];
                        this.container.Remove(bot);
                        bot = (GenSpawn.Spawn(bot, base.Position, base.Map) as ArcBaseRobot);
                    }
                    this.robot = bot;
                    this.robot.rechargeStation   = this;
                    this.robotSpawnedOnce        = true;
                    this.SpawnRobotAfterRecharge = true;
                }
            }
        }
Ejemplo n.º 5
0
        static void Postfix(Pawn_NeedsTracker __instance, NeedDef nd, ref bool __result)
        {
            Pawn pawn = (Pawn)AccessTools.Field(typeof(Pawn_NeedsTracker), "pawn").GetValue(__instance);

            Log.Message("Pawn battery check: " + pawn.Name);
            if (nd.needClass == typeof(Need_Battery))
            {
                if (pawn.def.thingClass == typeof(ArcBaseRobot))
                {
                    ArcBaseRobot robot = (ArcBaseRobot)pawn;
                    if (robot.isRobot())
                    {
                        Log.Message("Pawn need battery : " + pawn.Name);
                        __result = true;
                    }
                    else
                    {
                        __result = false;
                    }
                }
                else
                {
                    __result = false;
                }
            }
            else if (pawn.def.thingClass == typeof(ArcBaseRobot))
            {
                __result = false;
            }
        }
        public static Building_BaseRobotRechargeStation FindRechargeStationFor(ArcBaseRobot sleeper, ArcBaseRobot traveler, bool sleeperWillBePrisoner, bool checkSocialProperness, bool medicalBedNeeded = false)
        {
            Predicate <Thing> predicate = delegate(Thing t) {
                bool flag3 = !ReservationUtility.CanReserveAndReach(traveler, t, PathEndMode.OnCell, Danger.Some, 1, -1, null, false);
                bool result2;
                if (flag3)
                {
                    result2 = false;
                }
                else
                {
                    Building_BaseRobotRechargeStation rechargeStation = t as Building_BaseRobotRechargeStation;
                    bool flag4 = rechargeStation == null;
                    if (flag4)
                    {
                        result2 = false;
                    }
                    else
                    {
                        bool flag5 = rechargeStation.robot != null && rechargeStation.robot != sleeper;
                        if (flag5)
                        {
                            result2 = false;
                        }
                        else
                        {
                            bool flag6 = ForbidUtility.IsForbidden(rechargeStation, traveler);
                            if (flag6)
                            {
                                result2 = false;
                            }
                            else
                            {
                                bool flag7 = FireUtility.IsBurning(rechargeStation);
                                result2 = !flag7;
                            }
                        }
                    }
                }
                return(result2);
            };
            bool flag = sleeper.rechargeStation != null && predicate(sleeper.rechargeStation);
            Building_BaseRobotRechargeStation result;

            if (flag)
            {
                Building_BaseRobotRechargeStation rechargeStation = sleeper.rechargeStation;
                bool flag2 = rechargeStation != null;
                if (flag2)
                {
                    result = rechargeStation;
                    return(result);
                }
            }
            result = null;
            return(result);
        }
Ejemplo n.º 7
0
        public static ArcBaseRobot CreateRobot(string pawnDefName, IntVec3 position, Map map, Faction faction)
        {
            PawnKindDef named = DefDatabase <PawnKindDef> .GetNamed(pawnDefName, true);

            //PawnGenerationRequest pawnGenerationRequest = new PawnGenerationRequest (named, faction, 2, -1, true, true, false, false, false, false, 0, false, false, true, false, false, null, new float? (0), new float? (0), new Gender? (1), new float? (0), null);
            PawnGenerationRequest gen      = new PawnGenerationRequest(named, faction, PawnGenerationContext.NonPlayer, -1, true, true, false, false, false, false, 0, false, false, true, false, false, false, false, null, 0, 0, 0, Gender.None, 0, null);
            ArcBaseRobot          newThing = (ArcBaseRobot)PawnGenerator.GeneratePawn(gen);

            return((ArcBaseRobot)Building_BaseRobotCreator.Spawn(newThing, position, map));
        }
Ejemplo n.º 8
0
        private void Button_ResetDestroyedRobot()
        {
            bool flag = this.robot != null && !this.robot.Destroyed;

            if (flag)
            {
                this.robot.Destroy(0);
            }
            this.robot            = null;
            this.robotIsDestroyed = false;
            this.Button_SpawnBot();
        }
Ejemplo n.º 9
0
        //
        // Methods
        //
        private Toil DespawnIntoContainer()
        {
            Toil toil = new Toil();

            toil.initAction = delegate {
                ArcBaseRobot bot = toil.actor as ArcBaseRobot;
                if (bot != null &&
                    bot.rechargeStation != null)
                {
                    bot.rechargeStation.AddRobotToContainer(bot);
                }
            };
            toil.defaultCompleteMode = ToilCompleteMode.Instant;
            return(toil);
        }
Ejemplo n.º 10
0
        private void TryThrowBatteryMote(ArcBaseRobot robot)
        {
            bool flag = robot == null;

            if (!flag)
            {
                this.timerMoteThrow--;
                bool flag2 = this.timerMoteThrow > 0;
                if (!flag2)
                {
                    this.timerMoteThrow = 300;
                    //float curLevel = robot.needs.rest.CurLevel;
                    float curLevel = robot.needs.TryGetNeed <Need_Battery>().CurLevel;

                    bool flag3 = curLevel > 0.99;
                    if (!flag3)
                    {
                        bool flag4 = curLevel > 0.9;
                        if (flag4)
                        {
                            MoteThrowHelper.ThrowBatteryGreen(base.Position.ToVector3(), base.Map, 0.8f);
                        }
                        else
                        {
                            bool flag5 = curLevel > 0.7;
                            if (flag5)
                            {
                                MoteThrowHelper.ThrowBatteryYellowYellow(base.Position.ToVector3(), base.Map, 0.8f);
                            }
                            else
                            {
                                bool flag6 = curLevel > 0.35;
                                if (flag6)
                                {
                                    MoteThrowHelper.ThrowBatteryYellow(base.Position.ToVector3(), base.Map, 0.8f);
                                }
                                else
                                {
                                    MoteThrowHelper.ThrowBatteryRed(base.Position.ToVector3(), base.Map, 0.8f);
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 11
0
        public override void Tick()
        {
            base.Tick();

            // Not sure why this is here - robots don't need food

            /*if (this.needs.food != null &&
             *      this.needs.food.CurLevel < 1) {
             *      this.needs.food.CurLevel = 1;
             * }/**/

            // Gain experience if learning is allowed
            if (this.def2 == null ||
                !this.def2.allowLearning)
            {
                foreach (SkillRecord current in this.skills.skills)
                {
                    if (current.xpSinceLastLevel > 1)
                    {
                        current.xpSinceLastLevel = 1;
                        current.xpSinceMidnight  = 1;
                    }
                }
            }
            Need_Battery batt = this.needs.TryGetNeed <Need_Battery> ();

            if (base.Spawned &&
                (base.Dead || base.Downed || batt.CurLevel <= 0.02))
            {
                this.Destroy();
            }
            else
            {
                if (base.Spawned)
                {
                    if (this.rechargeStation == null)
                    {
                        this.rechargeStation = ArcBaseRobot.TryFindRechargeStation(this, base.Map);
                    }
                }
            }
        }
Ejemplo n.º 12
0
        public void DespawnRobot(ArcBaseRobot bot, bool destroying = false)
        {
            bool flag = bot != null && !bot.Destroyed;

            if (flag)
            {
                if (destroying)
                {
                    bot.Destroy(0);
                }
                else
                {
                    bool spawned = bot.Spawned;
                    if (spawned)
                    {
                        bot.DeSpawn();
                    }
                }
            }
            this.robot = null;
        }
Ejemplo n.º 13
0
 public override void SetInitialLevel()
 {
     Log.Message("Pawn battery check1: " + pawn.Name);
     if (pawn.def.thingClass == typeof(ArcBaseRobot))
     {
         ArcBaseRobot robot = (ArcBaseRobot)pawn;
         Log.Message("Pawn battery check1a: " + pawn.Name);
         if (robot.isRobot())
         {
             Log.Message("Pawn battery check1b: " + pawn.Name);
             this.CurLevel = Rand.Range(0.9f, 1);
         }
         else
         {
             //not needed
             Log.Message("no battery needed1");
         }
     }
     else
     {
         //not needed
         Log.Message("no battery needed2");
     }
 }
Ejemplo n.º 14
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            ArcBaseRobot bot = pawn as ArcBaseRobot;
            Building_BaseRobotRechargeStation rechargeStation = BaseRobot_Helper.FindRechargeStationFor(bot);
            Job result;

            if (rechargeStation == null)
            {
                result = null;
            }
            else
            {
                if (bot.rechargeStation != rechargeStation)
                {
                    result = null;
                }
                else
                {
                    Job job = new Job(DefDatabase <JobDef> .GetNamed("AIRobot_GoRecharge", true), rechargeStation);
                    result = job;
                }
            }
            return(result);
        }
Ejemplo n.º 15
0
        public override void Tick()
        {
            base.Tick();
            this.UpdateGraphic();

            if (this.robot == null && this.IsRobotInContainer())
            {
                ArcBaseRobot bot = this.container [0];
                if (bot == null)
                {
                    this.container.Remove(this.container [0]);
                }
                else
                {
                    Need_Battery battery = bot.needs.TryGetNeed <Need_Battery> ();

                    if (this.SpawnRobotAfterRecharge && battery.CurLevel >= 0.99)
                    {
                        this.Button_SpawnBot();
                    }
                    else
                    {
                        if (battery.CurLevel < 1)
                        {
                            //Need_Rest expr_B8 = bot.needs.rest;
                            battery.CurLevel = battery.CurLevel + 4E-05f * this.rechargeEfficiency;
                            if (battery.CurLevel > 1)
                            {
                                battery.CurLevel = 1;
                            }
                            this.TryThrowBatteryMote(bot);
                        }
                    }
                }
            }
            else
            {
                if (!this.robotIsDestroyed)
                {
                    if (!(this.robot == null && (!this.robotSpawnedOnce || !this.IsRobotInContainer())))
                    {
                        if (this.robotSpawnedOnce && !this.IsRobotInContainer() && (this.robot == null || this.robot.Destroyed || this.robot.Dead))
                        {
                            if ((this.robot.Destroyed || this.robot.Dead) && this.robot.Corpse != null)
                            {
                                this.robot.Corpse.Destroy(0);
                            }
                            this.robotIsDestroyed = true;
                        }
                        else
                        {
                            this.checkDistanceAndEnergyTicks--;
                            bool flag10 = this.checkDistanceAndEnergyTicks > 0;
                            if (!flag10)
                            {
                                this.checkDistanceAndEnergyTicks = 192;
                                Need_Battery battery = this.robot.needs.TryGetNeed <Need_Battery> ();
                                if (battery.CurLevel < 0.4 && !this.robot.Drafted && !BaseRobot_Helper.IsInDistance(base.Position, this.robot.Position, 50))
                                {
                                    this.Button_CallBotForShutdown();
                                    this.SpawnRobotAfterRecharge = true;
                                }
                            }
                        }
                    }
                }
            }
        }
Ejemplo n.º 16
0
 private void Button_RepairDestroyedRobot()
 {
     this.robot            = null;
     this.robotIsDestroyed = false;
     this.Button_SpawnBot();
 }
Ejemplo n.º 17
0
        protected override Job TryGiveJob(Pawn pawn)
        {
            ArcBaseRobot bot = pawn as ArcBaseRobot;

            Job result;

            if (bot == null)
            {
                result = null;
            }
            else
            {
                List <WorkGiver> workGivers         = bot.GetWorkGivers(false);
                int               num               = -999;
                TargetInfo        targetInfo        = TargetInfo.Invalid;
                WorkGiver_Scanner workGiver_Scanner = null;
                for (int i = 0; i < workGivers.Count; i++)
                {
                    WorkGiver workGiver = workGivers [i];
                    if (workGiver.def.priorityInType != num &&
                        targetInfo.IsValid)
                    {
                        break;
                    }
                    if (this.PawnCanUseWorkGiver(pawn, workGiver))
                    {
                        try {
                            Job job = workGiver.NonScanJob(pawn);
                            if (job != null)
                            {
                                result = job;
                                return(result);
                            }
                            WorkGiver_Scanner scanner = workGiver as WorkGiver_Scanner;

                            if (scanner != null)
                            {
                                if (workGiver.def.scanThings)
                                {
                                    Predicate <Thing>   predicate  = (Thing t) => !ForbidUtility.IsForbidden(t, pawn) && scanner.HasJobOnThing(pawn, t, false);
                                    IEnumerable <Thing> enumerable = scanner.PotentialWorkThingsGlobal(pawn);

                                    Thing thing;
                                    if (scanner.Prioritized)
                                    {
                                        IEnumerable <Thing> enumerable2 = enumerable;

                                        if (enumerable2 == null)
                                        {
                                            enumerable2 = pawn.Map.listerThings.ThingsMatching(scanner.PotentialWorkThingRequest);
                                        }
                                        Predicate <Thing> predicate2 = predicate;
                                        thing = GenClosest.ClosestThing_Global_Reachable(pawn.Position, pawn.Map, enumerable2, scanner.PathEndMode, TraverseParms.For(pawn, Danger.Deadly, 0, false), 9999, predicate2, (Thing x) => scanner.GetPriority(pawn, x));
                                    }
                                    else
                                    {
                                        Predicate <Thing> predicate3 = predicate;
                                        bool flag7 = enumerable != null;
                                        thing = GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, scanner.PotentialWorkThingRequest, scanner.PathEndMode, TraverseParms.For(pawn, Danger.Deadly, 0, false), 9999, predicate3, enumerable, 0, scanner.MaxRegionsToScanBeforeGlobalSearch, flag7, RegionType.Set_Passable, false);
                                    }
                                    if (thing != null)
                                    {
                                        targetInfo        = thing;
                                        workGiver_Scanner = scanner;
                                    }
                                }

                                if (workGiver.def.scanCells)
                                {
                                    IntVec3 position     = pawn.Position;
                                    float   num2         = 99999;
                                    float   num3         = float.MinValue;
                                    bool    prioritized2 = scanner.Prioritized;
                                    foreach (IntVec3 current in scanner.PotentialWorkCellsGlobal(pawn))
                                    {
                                        bool  flag9 = false;
                                        float num4  = (float)(current - position).LengthHorizontalSquared;
                                        if (prioritized2)
                                        {
                                            if (!ForbidUtility.IsForbidden(current, pawn) &&
                                                scanner.HasJobOnCell(pawn, current))
                                            {
                                                float priority = scanner.GetPriority(pawn, current);
                                                if (priority > num3 ||
                                                    (priority == num3 && num4 < num2))
                                                {
                                                    flag9 = true;
                                                    num3  = priority;
                                                }
                                            }
                                        }
                                        else
                                        {
                                            if (num4 < num2 &&
                                                !ForbidUtility.IsForbidden(current, pawn) &&
                                                scanner.HasJobOnCell(pawn, current))
                                            {
                                                flag9 = true;
                                            }
                                        }
                                        if (flag9)
                                        {
                                            targetInfo        = new TargetInfo(current, pawn.Map, false);
                                            workGiver_Scanner = scanner;
                                            num2 = num4;
                                        }
                                    }
                                }
                            }
                        }
                        catch (Exception ex) {
                            Log.Error(string.Concat(new object[] {
                                pawn,
                                " threw exception in WorkGiver ",
                                workGiver.def.defName,
                                ": ",
                                ex.ToString()
                            }));
                        }

                        if (targetInfo.IsValid)
                        {
                            //pawn.workSettings.lastGivenWorkType = workGiver.def.workType;
                            Job job2 = workGiver_Scanner.JobOnThing(pawn, targetInfo.Thing, false);

                            if (job2 != null)
                            {
                                result = job2;
                                return(result);
                            }
                            Log.ErrorOnce(string.Concat(new object[] {
                                workGiver_Scanner,
                                " provided target ",
                                targetInfo,
                                " but yielded no actual job for pawn ",
                                pawn,
                                ". The CanGiveJob and JobOnX methods may not be synchronized."
                            }), 6112651);
                        }
                        num = workGiver.def.priorityInType;
                    }
                }
                result = null;
            }
            return(result);
        }
Ejemplo n.º 18
0
 public static Building_BaseRobotRechargeStation FindRechargeStationFor(ArcBaseRobot p)
 {
     return(BaseRobot_Helper.FindRechargeStationFor(p, p, false, false, false));
 }