Exemple #1
0
        public override void SpawnSetup(Map map, bool respawningAfterLoad)
        {
            base.SpawnSetup(map, respawningAfterLoad);
            this.mapManager = map.GetComponent <MapTickManager>();
            if (buildingPawn == null)
            {
                DoPawn();
            }

            this.buildingPawn?.skills.skills.ForEach(s =>
            {
                s.Level = extension_Skills.GetExtendedSkillLevel(s.def, typeof(Building_ProgrammableAssembler));
                ReflectionUtility.cachedTotallyDisabled.SetValue(s, BoolUnknown.Unknown);
            });

            this.compPowerTrader = GetComp <CompPowerTrader>();
            this.compRefuelable  = GetComp <CompRefuelable>();
            this.compFlick       = GetComp <CompFlickable>();

            //Assign Pawn's mapIndexOrState to building's mapIndexOrState
            ReflectionUtility.mapIndexOrState.SetValue(buildingPawn, ReflectionUtility.mapIndexOrState.GetValue(this));
            //Assign Pawn's position without nasty errors
            buildingPawn.SetPositionDirect(Position);

            //Need this type of call to set the Powerconsumption on load
            //A normal call will not work
            var rangePowerSupplyMachine = this.RangePowerSupplyMachine;

            if (rangePowerSupplyMachine != null)
            {
                this.MapManager.NextAction(rangePowerSupplyMachine.RefreshPowerStatus);
                this.MapManager.AfterAction(5, rangePowerSupplyMachine.RefreshPowerStatus);
            }
            PRFGameComponent.RegisterAssemblerQueue(this);
        }
        private void generalRelease()
        {
            if (PRFGameComponent.PRF_StaticPawn == null)
            {
                PRFGameComponent.GenStaticPawn();
            }
            if (PRFGameComponent.PRF_StaticJob == null)
            {
                PRFGameComponent.PRF_StaticJob = new Job(PRFDefOf.PRFStaticJob);
            }

            Building tb = researchBench ?? drilltypeBuilding;

            /*
             * Log.Message("----------------------------------");
             * List<ReservationManager.Reservation> reservations;
             * reservations = (List<ReservationManager.Reservation>)ReflectionUtility.sal_reservations.GetValue(Map.reservationManager);
             * reservations = reservations.Where(r => r.Faction != null && r.Faction.IsPlayer).ToList();
             * foreach (ReservationManager.Reservation res in reservations)
             * {
             *  Log.Message("Reservation for " + res.Claimant + " at " + res.Target);
             *
             * }
             */

            Map.reservationManager.Release(tb, PRFGameComponent.PRF_StaticPawn, PRFGameComponent.PRF_StaticJob);
            //Log.Message("generalRelease for " + (Position + Rotation.FacingCell) );
        }
        static void Postfix(ResourceCounter __instance, Dictionary <ThingDef, int> ___countedAmounts, Map ___map)
        {
            int i = 0;
            PRFGameComponent gamecomp = Current.Game.GetComponent <PRFGameComponent>();

            for (i = 0; i < gamecomp.AssemblerQueue.Count; i++)
            {
                //Don't count Recorces of other maps
                if (gamecomp.AssemblerQueue[i].Map != ___map)
                {
                    continue;
                }

                foreach (Thing heldThing in gamecomp.AssemblerQueue[i].GetThingQueue())
                {
                    Thing innerIfMinified = heldThing.GetInnerIfMinified();
                    //Added Should Count Checks
                    //EverStorable is form HeldThings
                    //Fresh Check is from ShouldCount (maybe we can hit that via harmony/reflection somhow)
                    if (innerIfMinified.def.EverStorable(false) && !innerIfMinified.IsNotFresh())
                    {
                        //Causes an error otherwise #345 (seems to be clothing that causes it)
                        if (___countedAmounts.ContainsKey(innerIfMinified.def))
                        {
                            ___countedAmounts[innerIfMinified.def] += innerIfMinified.stackCount;
                        }
                    }
                }
            }
        }
        static void Postfix(RecipeWorkerCounter __instance, ref int __result, Bill_Production bill)
        {
            if (bill.includeFromZone == null)
            {
                int              i         = 0;
                ThingDef         targetDef = __instance.recipe.products[0].thingDef;
                PRFGameComponent gamecomp  = Current.Game.GetComponent <PRFGameComponent>();

                for (i = 0; i < gamecomp.AssemblerQueue.Count; i++)
                {
                    //Don't count Recorces of other maps
                    if (bill.Map != gamecomp.AssemblerQueue[i].Map)
                    {
                        continue;
                    }
                    foreach (Thing heldThing in gamecomp.AssemblerQueue[i].GetThingQueue())
                    {
                        Thing innerIfMinified = heldThing.GetInnerIfMinified();
                        if (innerIfMinified.def == targetDef)
                        {
                            __result += innerIfMinified.stackCount;
                        }
                    }
                }
            }
        }
        private void generalReserve()
        {
            if (PRFGameComponent.PRF_StaticPawn == null)
            {
                PRFGameComponent.GenStaticPawn();
            }
            if (PRFGameComponent.PRF_StaticJob == null)
            {
                PRFGameComponent.PRF_StaticJob = new Job(PRFDefOf.PRFStaticJob);
            }

            Building tb = researchBench ?? drilltypeBuilding;

            List <ReservationManager.Reservation> reservations;

            reservations = (List <ReservationManager.Reservation>)ReflectionUtility.sal_reservations.GetValue(Map.reservationManager);
            var res = new ReservationManager.Reservation(PRFGameComponent.PRF_StaticPawn, PRFGameComponent.PRF_StaticJob, 1, -1, tb /*(Position + Rotation.FacingCell)*/, null);

            if (!reservations.Where(r => r.Claimant == PRFGameComponent.PRF_StaticPawn && r.Job == PRFGameComponent.PRF_StaticJob && r.Target == tb).Any())
            {
                reservations.Add(res);
            }
            ReflectionUtility.sal_reservations.SetValue(Map.reservationManager, reservations);

            //Spammy Debug

            /*
             * reservations = (List<ReservationManager.Reservation>)ReflectionUtility.sal_reservations.GetValue(Map.reservationManager);
             * reservations = reservations.Where(r => r.Faction != null && r.Faction.IsPlayer).ToList();
             * foreach (ReservationManager.Reservation res in reservations)
             * {
             *  Log.Message("Reservation for " + res.Claimant + " at " + res.Target);
             *
             * }
             */
        }