public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_Beehouse building_beehouse = t as Building_Beehouse;
            bool result;

            if (building_beehouse == null || !building_beehouse.BeehouseIsFull)
            {
                result = false;
            }
            else if (t.IsBurning())
            {
                result = false;
            }
            else
            {
                if (!t.IsForbidden(pawn))
                {
                    LocalTargetInfo target = t;
                    if (pawn.CanReserve(target, 1, -1, null, forced))
                    {
                        result = true;
                        return(result);
                    }
                }
                result = false;
            }
            return(result);
        }
        public override Job JobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_Beehouse building_beehouse = (Building_Beehouse)t;
            Thing             t2 = this.FindDrone(pawn, building_beehouse.theDroneIAmGoingToInsert, building_beehouse);

            return(new Job(DefDatabase <JobDef> .GetNamed("RB_InsertingBees", true), t, t2));
        }
Ejemplo n.º 3
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //Log.Message("I am inside the job now, with "+pawn.ToString(), false);


            Toil reserveBees = Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null);

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch).FailOnDespawnedNullOrForbidden(TargetIndex.B).FailOnSomeonePhysicallyInteracting(TargetIndex.B));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B, false, true, false).FailOnDestroyedNullOrForbidden(TargetIndex.B));

            yield return(Toils_Haul.CheckForGetOpportunityDuplicate(reserveBees, TargetIndex.B, TargetIndex.None, true, null));

            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(240).FailOnDestroyedNullOrForbidden(TargetIndex.B).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Building_Beehouse buildingbeehouse = (Building_Beehouse)this.job.GetTarget(TargetIndex.A).Thing;
                    //buildingbeehouse.queenThing = this.job.targetB.Thing;
                    buildingbeehouse.TryAcceptAnyQueen(this.job.targetB.Thing, true);
                    buildingbeehouse.BeehouseIsExpectingBees = false;

                    //this.job.targetB.Thing.Destroy();
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });
        }
        public override bool HasJobOnThing(Pawn pawn, Thing t, bool forced = false)
        {
            Building_Beehouse building_beehouse = t as Building_Beehouse;

            if (building_beehouse == null || !building_beehouse.BeehouseIsExpectingBees)
            {
                return(false);
            }

            if (!t.IsForbidden(pawn))
            {
                LocalTargetInfo target = t;
                if (pawn.CanReserve(target, 1, 1, null, forced))
                {
                    if (pawn.Map.designationManager.DesignationOn(t, DesignationDefOf.Deconstruct) != null)
                    {
                        return(false);
                    }
                    if (this.FindDrone(pawn, building_beehouse.theDroneIAmGoingToInsert, building_beehouse) == null)
                    {
                        JobFailReason.Is(WorkGiver_InsertDroneInBeehouse.NoDronesFound, null);
                        return(false);
                    }
                    return(!t.IsBurning());
                }
            }
            return(false);
        }
Ejemplo n.º 5
0
        public ThingDef DecideRandomBee()
        {
            Building_BroodChamber buildingbroodchamber = (Building_BroodChamber)this.job.GetTarget(TargetIndex.A).Thing;
            Building_Beehouse     buildingbeehouse     = buildingbroodchamber.GetAdjacentBeehouse();
            Thing    beeDrone = buildingbeehouse.innerContainerDrones.FirstOrFallback();
            Thing    beeQueen = buildingbeehouse.innerContainerQueens.FirstOrFallback();
            ThingDef resultingBee;

            int randomNumber = rand.Next(1, 14);

            if (randomNumber >= 1 && randomNumber <= 5)
            {
                resultingBee = DefDatabase <ThingDef> .GetNamed(beeDrone.def.defName, true);
            }
            else if (randomNumber == 6)
            {
                resultingBee = DefDatabase <ThingDef> .GetNamed(getQueenFromDrone(beeDrone), true);
            }
            else if (randomNumber == 7)
            {
                resultingBee = DefDatabase <ThingDef> .GetNamed(beeQueen.def.defName, true);
            }
            else
            {
                resultingBee = DefDatabase <ThingDef> .GetNamed(getDroneFromQueen(beeQueen), true);
            }

            return(resultingBee);
        }
Ejemplo n.º 6
0
        private void TryInsertQueen()
        {
            Building_Beehouse buildingbeehouse = (Building_Beehouse)this.beehouse;

            buildingbeehouse.BeehouseIsExpectingQueens = true;
            buildingbeehouse.theQueenIAmGoingToInsert  = queen.def.defName;
        }
        private void TryInsertDrone()
        {
            Building_Beehouse buildingbeehouse = (Building_Beehouse)this.beehouse;

            buildingbeehouse.BeehouseIsExpectingBees  = true;
            buildingbeehouse.theDroneIAmGoingToInsert = drone.def.defName;
        }
Ejemplo n.º 8
0
        public override void Notify_PatherFailed()
        {
            Building_Beehouse buildingbeehouse = (Building_Beehouse)this.job.GetTarget(TargetIndex.A).Thing;

            buildingbeehouse.BeehouseIsExpectingBees = false;

            this.EndJobWith(JobCondition.ErroredPather);
        }
        private Thing FindDrone(Pawn pawn, string theDroneIAmGoingToInsert, Building_Beehouse building_beehouse)
        {
            Predicate <Thing> predicate      = (Thing x) => !x.IsForbidden(pawn) && pawn.CanReserve(x, 1, 1, null, false);
            IntVec3           position       = pawn.Position;
            Map               map            = pawn.Map;
            ThingRequest      thingReq       = ThingRequest.ForDef(ThingDef.Named(theDroneIAmGoingToInsert));
            PathEndMode       peMode         = PathEndMode.ClosestTouch;
            TraverseParms     traverseParams = TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false);
            Predicate <Thing> validator      = predicate;

            return(GenClosest.ClosestThingReachable(position, map, thingReq, peMode, traverseParams, 9999f, validator, null, 0, -1, false, RegionType.Set_Passable, false));
        }
Ejemplo n.º 10
0
        public override void PostDraw()
        {
            if (RimBees_Settings.RB_Ben_ShowMissingBees)
            {
                Building_Beehouse beehouse = this.parent as Building_Beehouse;
                var expectingQueens        = beehouse.BeehouseIsExpectingQueens;
                var expectingDrones        = beehouse.BeehouseIsExpectingBees;
                var queenContainer         = beehouse.innerContainerQueens;
                var droneContainer         = beehouse.innerContainerDrones;
                var missingPlant           = !beehouse.flagPlants;

                int offset = 0;
                if ((queenContainer.NullOrEmpty() && !expectingQueens) || (droneContainer.NullOrEmpty() && !expectingDrones))
                {
                    RenderMissingFuelOverlay(DroneMat, ref offset);
                }
                else if (compPower != null && !compPower.PowerOn)
                {
                    var matNoPower = MaterialPool.MatFrom("UI/Overlays/NeedsPower", ShaderDatabase.MetaOverlay);
                    RenderMissingFuelOverlay(matNoPower, ref offset);
                }
                else if (missingPlant)
                {
                    // only one "weird plant" is needed even if both bees require different plants, so if we got here, both are missing.
                    var weirdPlant = BenLubarsRimBeesPatches.GetWeirdPlantDef(queenContainer.FirstOrFallback()) ?? BenLubarsRimBeesPatches.GetWeirdPlantDef(droneContainer.FirstOrFallback());
                    if (weirdPlant != null)
                    {
                        var mat = MaterialPool.MatFrom(new MaterialRequest(weirdPlant.uiIcon, ShaderDatabase.MetaOverlay));
                        RenderMissingFuelOverlay(mat, ref offset);
                    }
                }
            }

            if (RimBees_Settings.RB_Ben_ShowProgress)
            {
                Building_Beehouse beehouse = this.parent as Building_Beehouse;
                var averageDays            = (float)beehouse.CalculateTheTicksAverage();
                if (averageDays > 0f)
                {
                    var progress = beehouse.tickCounter / (beehouse.ticksToDays * averageDays);
                    GenDraw.DrawFillableBar(new GenDraw.FillableBarRequest
                    {
                        center      = parent.DrawPos + ProgressBarOffset,
                        size        = ProgressBarSize,
                        fillPercent = progress,
                        margin      = 0.1f,
                        rotation    = Rot4.North,
                        filledMat   = FilledMat,
                        unfilledMat = UnfilledMat,
                    });
                }
            }
        }
Ejemplo n.º 11
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            this.FailOnDespawnedNullOrForbidden(TargetIndex.A);
            this.FailOnBurningImmobile(TargetIndex.A);
            yield return(Toils_Goto.GotoThing(TargetIndex.A, PathEndMode.Touch));

            yield return(Toils_General.Wait(240).FailOnDestroyedNullOrForbidden(TargetIndex.A).FailOnCannotTouch(TargetIndex.A, PathEndMode.Touch).WithProgressBarToilDelay(TargetIndex.A, false, -0.5f));

            yield return(new Toil
            {
                initAction = delegate
                {
                    Building_Beehouse buildingbeehouse = (Building_Beehouse)this.job.GetTarget(TargetIndex.A).Thing;
                    buildingbeehouse.BeehouseIsFull = false;
                    Thing newComb = ThingMaker.MakeThing(DecideRandomComb());
                    GenSpawn.Spawn(newComb, buildingbeehouse.Position - GenAdj.CardinalDirections[0], buildingbeehouse.Map);

                    StoragePriority currentPriority = StoreUtility.CurrentStoragePriorityOf(newComb);
                    IntVec3 c;
                    if (StoreUtility.TryFindBestBetterStoreCellFor(newComb, this.pawn, this.Map, currentPriority, this.pawn.Faction, out c, true))
                    {
                        this.job.SetTarget(TargetIndex.C, c);
                        this.job.SetTarget(TargetIndex.B, newComb);
                        this.job.count = newComb.stackCount;
                        buildingbeehouse.tickCounter = 0;
                    }
                    else
                    {
                        this.EndJobWith(JobCondition.Incompletable);
                        buildingbeehouse.BeehouseIsFull = false;
                        buildingbeehouse.tickCounter = 0;
                    }
                },
                defaultCompleteMode = ToilCompleteMode.Instant
            });

            yield return(Toils_Reserve.Reserve(TargetIndex.B, 1, -1, null));

            yield return(Toils_Reserve.Reserve(TargetIndex.C, 1, -1, null));

            yield return(Toils_Goto.GotoThing(TargetIndex.B, PathEndMode.ClosestTouch));

            yield return(Toils_Haul.StartCarryThing(TargetIndex.B, false, false, false));

            Toil carryToCell = Toils_Haul.CarryHauledThingToCell(TargetIndex.C);

            yield return(carryToCell);

            yield return(Toils_Haul.PlaceHauledThingInCell(TargetIndex.C, carryToCell, true));
        }
Ejemplo n.º 12
0
        private void TryInsertDrone()
        {
            Pawn pawn = null;

            foreach (Pawn current in map.mapPawns.FreeColonistsSpawned)
            {
                bool flag = !current.Dead;

                if (flag)
                {
                    bool flag2 = current.health.capacities.CapableOf(PawnCapacityDefOf.Manipulation) && current.health.capacities.CapableOf(PawnCapacityDefOf.Moving);

                    if (flag2)
                    {
                        pawn = current;
                        break;
                    }
                }
            }
            //Log.Message(pawn.ToString(), false);

            bool flag4 = (pawn != null);

            if (flag4)
            {
                if (pawn.CanReach(beehouse, PathEndMode.InteractionCell, Danger.Some, false, TraverseMode.ByPawn))
                {
                    // pawn.jobs.StopAll(false);

                    Job job = new Job(DefDatabase <JobDef> .GetNamed("RB_InsertingBees", true), beehouse, drone);
                    job.count = 1;
                    if (TryToReserveThings(pawn, job))
                    {
                        pawn.jobs.TryTakeOrderedJob(job, JobTag.Misc);
                        Building_Beehouse buildingbeehouse = (Building_Beehouse)this.beehouse;
                        buildingbeehouse.BeehouseIsExpectingBees = true;
                    }
                    else
                    {
                        pawn.ClearAllReservations();
                        //Messages.Message("Can't reserve things", MessageTypeDefOf.RejectInput);
                    }
                }
            }
            else
            {
                Messages.Message("No colonists available to take care of the bees", MessageTypeDefOf.RejectInput);
            }
        }
Ejemplo n.º 13
0
        public Building_Beehouse GetAdjacentBeehouse()
        {
            Building_Beehouse result;


            IntVec3           c       = this.Position + GenAdj.CardinalDirections[3];
            Building_Beehouse edifice = (Building_Beehouse)c.GetEdifice(base.Map);

            if ((edifice != null) && (edifice.TryGetComp <CompBeeHouse>().GetIsBeehouse))
            {
                result = edifice;
                return(result);
            }

            result = null;
            return(result);
        }
Ejemplo n.º 14
0
        public Building_Beehouse GetAdjacentBeehouse()
        {
            Building_Beehouse result;


            IntVec3           c       = this.Position + GenAdj.CardinalDirections[3];
            Building_Beehouse edifice = (Building_Beehouse)c.GetEdifice(base.Map);

            if (edifice != null && ((edifice.def == DefDatabase <ThingDef> .GetNamed("RB_Beehouse", true)) || (edifice.def == DefDatabase <ThingDef> .GetNamed("RB_ClimatizedBeehouse", true)) || (edifice.def == DefDatabase <ThingDef> .GetNamed("RB_AdvancedBeehouse", true))))
            {
                result = edifice;
                return(result);
            }

            result = null;
            return(result);
        }
Ejemplo n.º 15
0
        public static bool RegrowIfBeehouseNearby(ref Plant __instance)
        {
            if (__instance.Blighted)
            {
                return(true);
            }

            if (__instance.def.plant.HarvestDestroys && __instance.def.plant.Sowable && !__instance.def.plant.IsTree)

            {
                int num = GenRadial.NumCellsInRadius(6);
                for (int i = 0; i < num; i++)
                {
                    IntVec3 current = __instance.Position + GenRadial.RadialPattern[i];
                    if (current.InBounds(__instance.Map))
                    {
                        Building getbeehouse = current.GetEdifice(__instance.Map);
                        if ((getbeehouse != null) && ((getbeehouse.def.defName == "RB_Beehouse") || (getbeehouse.def.defName == "RB_AdvancedClimatizedBeehouse") ||
                                                      (getbeehouse.def.defName == "RB_ClimatizedBeehouse") || (getbeehouse.def.defName == "RB_AdvancedBeehouse")))
                        {
                            Building_Beehouse thebeehouse = (Building_Beehouse)getbeehouse;

                            if (thebeehouse.BeehouseIsRunning)
                            {
                                Random random = new Random();
                                if (random.NextDouble() > 0.75)
                                {
                                    Thing thing = ThingMaker.MakeThing(ThingDef.Named(__instance.def.defName), null);
                                    Plant plant = (Plant)thing;
                                    GenSpawn.Spawn(plant, __instance.Position, __instance.Map);
                                    plant.Growth = 0.25f;
                                    __instance.Map.mapDrawer.MapMeshDirty(__instance.Position, MapMeshFlag.Things);
                                    return(true);
                                }
                            }
                        }
                    }
                }
                return(true);
            }
            else
            {
                return(true);
            }
        }
Ejemplo n.º 16
0
        public ThingDef DecideRandomComb()
        {
            Building_Beehouse buildingbeehouse = (Building_Beehouse)this.job.GetTarget(TargetIndex.A).Thing;
            ThingDef          resultingComb;

            int randomNumber = rand.Next(1, 3);

            if (randomNumber == 1)
            {
                resultingComb = DefDatabase <ThingDef> .GetNamed(buildingbeehouse.innerContainerDrones.FirstOrFallback().TryGetComp <CompBees>().GetComb, true);
            }
            else
            {
                resultingComb = DefDatabase <ThingDef> .GetNamed(buildingbeehouse.innerContainerQueens.FirstOrFallback().TryGetComp <CompBees>().GetComb, true);
            }

            return(resultingComb);
        }