Ejemplo n.º 1
0
        public void TryMakePack()
        {
            //TryMakePackUsingJoinPack();

            if (pawnsInPack < maxPawnsInPack)
            {
                List <Pawn> freeHumanlikesOfFaction = pawn.Map.mapPawns.FreeHumanlikesOfFaction(pawn.Faction).ToList();
                //Log.Message("FreeColonists count = " + freeHumanlikesOfFaction.Count());
                for (int i = 0; i < freeHumanlikesOfFaction.Count; i++)
                {
                    Pawn pawn2 = freeHumanlikesOfFaction[i];

                    if (pawn2 == pawn || !pawn2.Awake() || pawn2.IsSlave() || pawn.HavePackRelation(pawn2))
                    {
                        continue;
                    }

                    if (AvaliUtility.BothPawnsReproductiveOrNotReproductive(pawn, pawn2))                     // kits form packs with kits and adults form packs with adults
                    {
                        if (pawnPosInQueue == 0 || (pawn.relations.OpinionOf(pawn2) >= pawnOpinionNeeded && pawn2.relations.OpinionOf(pawn) >= pawnOpinionNeeded))
                        {
                            if (TotalPawnsInPack(pawn2) < maxPawnsInPack)                             // check if pawn2 has atleast 1 vacant slot in pack
                            {
                                if (debug)
                                {
                                    Log.Message(pawn + " try make pack relation with " + pawn2);
                                }
                                pawn.TryAddDirectRelation(pawn2, PawnRelationDefOf.Packmate);
                                if (pawn2.def == ThingDefOf.Avali)
                                {
                                    pawn2.TryAddDirectRelation(pawn, PawnRelationDefOf.Packmate);
                                }

                                pawnsInPack++;

                                if (debug)
                                {
                                    Log.Message(pawn + " packSize = " + pawnsInPack);
                                }
                                if (pawnsInPack >= maxPawnsInPack)
                                {
                                    return;
                                }
                            }

                            /*
                             * if (TotalPawnsInPack(pawn2) < maxPawnsInPack) // check if pawn2 has atleast 1 valant slot in pack
                             * {
                             *      if (debug) Log.Message(pawn + " try make pack relation with " + pawn2);
                             *      GetPawnSkillCount(pawn2); // compare pawn and pawn2 total skill count
                             * }
                             */
                        }
                    }
                }
            }
        }
        protected override ThoughtState CurrentStateInternal(Pawn p)
        {
            if (p.def == ThingDefOf.Avali)
            {
                return(ThoughtState.Inactive);
            }
            List <Hediff> hediffs = p.health.hediffSet.hediffs;

            for (int i = 0; i < hediffs.Count; i++)
            {
                Hediff hediff = hediffs[i];
                if (hediff != null && hediff.Part != null && hediff.Part.Label == "nose")
                {
                    if (hediff.def == RimWorld.HediffDefOf.MissingBodyPart)
                    {
                        return(ThoughtState.Inactive);
                    }
                }
            }

            List <Thing> avaliPawns = new List <Thing>();
            Room         room       = p.GetRoom(RegionType.Set_Passable);

            if (room.PsychologicallyOutdoors)
            {
                return(ThoughtState.Inactive);
            }
            List <Pawn> freeColonistsAndPrisoners = p.GetRoom(RegionType.Set_Passable).Map.mapPawns.FreeColonistsAndPrisoners.ToList();

            for (int i = 0; i < freeColonistsAndPrisoners.Count; i++)
            {
                Thing freeColonistOrPrisoner = freeColonistsAndPrisoners[i] as Thing;
                if (freeColonistOrPrisoner != null)
                {
                    avaliPawns.Add(freeColonistOrPrisoner);
                }
            }

            if (avaliPawns.Count == 0)
            {
                return(ThoughtState.Inactive);
            }

            int avaliPawnsInRange = AvaliUtility.FindAllThingsOnMapAtRange(p, ThingDefOf.Avali, null, avaliPawns, rangeInCells, maxAvaliPawns, false, false).Count;

            if (avaliPawnsInRange > 0)
            {
                avaliPawnsInRange--;
                if (avaliPawnsInRange > 5)
                {
                    avaliPawnsInRange = 5;
                }
                return(ThoughtState.ActiveAtStage(avaliPawnsInRange));
            }

            return(ThoughtState.Inactive);
        }
Ejemplo n.º 3
0
 public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null)
 {
     if (loc.GetRoof(map) != null)
     {
         if (AvaliUtility.BuildingInPosition(map, loc, checkingDef) != null)
         {
             return(new AcceptanceReport("SpaceAlreadyOccupied".Translate()));
         }
         else
         {
             return(true);
         }
     }
     return(new AcceptanceReport("MustPlaceUnderRoof".Translate()));
 }
Ejemplo n.º 4
0
        protected override IEnumerable <Toil> MakeNewToils()
        {
            //this.FailOnDespawnedOrNull(BedInd);
            this.FailOnDespawnedOrNull(PartnerInd);
            this.FailOn(() => !partner.health.capacities.CanBeAwake);

            Building partnerCellBuilding = partner.Position.GetFirstBuilding(Map);

            if (partnerCellBuilding == null || partnerCellBuilding.GetStatValue(StatDefOf.Comfort) < 0.5f)
            {
                Room room = pawn.GetRoom(RegionType.Set_Passable);
                if (room == null)
                {
                    yield break;
                }
                AvaliUtility.FindAllThingsOnMapAtRange(pawn, null, typeof(Pawn), room.ContainedAndAdjacentThings, 20, 9999, true, true);

                /*
                 * Predicate<Thing> validator = delegate(Thing t)
                 * {
                 *      Thing building2 = t as Building;
                 *
                 *      return (building2.def.thingClass == typeof(Building_Bed) || building2.def.building.isSittable) && pawn.CanReserve(building2, 1, -1, null, false);
                 * };
                 */
                //Thing thing = (Thing)GenClosest.ClosestThingReachable(pawn.Position, pawn.Map, ThingRequest.ForDef(thingDef), PathEndMode.Touch, TraverseParms.For(pawn, Danger.Deadly, TraverseMode.ByPawn, false), maxSearchDistance, validator, null, 0, -1, false, RegionType.Set_Passable, false);



                //List<Thing> buildingsInRoom = AvaliUtility.FindAllThingsOnMapAtRange(pawn, null, typeof(Building), room.ContainedAndAdjacentThings, 20, 9999, true, true);



                /*if (room.PsychologicallyOutdoors)
                 * {
                 *
                 * }*/
            }

            yield break;
        }
        public override AcceptanceReport AllowsPlacing(BuildableDef def, IntVec3 center, Rot4 rot, Map map, Thing thingToIgnore = null)
        {
            if (rot == Rot4.West || rot == Rot4.East)
            {
                c1 = center + new IntVec3(1, 0, 0);
                c2 = center - new IntVec3(1, 0, 0);
            }
            else
            {
                c1 = center + new IntVec3(0, 0, 1);
                c2 = center - new IntVec3(0, 0, 1);
            }

            if (AvaliUtility.BuildingInPosition(map, c1, def) != null)
            {
                if (AvaliUtility.BuildingInPosition(map, c2, def) != null)
                {
                    return(true);
                }
            }

            return(true);
        }
Ejemplo n.º 6
0
        public override AcceptanceReport AllowsPlacing(BuildableDef checkingDef, IntVec3 loc, Rot4 rot, Map map, Thing thingToIgnore = null, Thing thing = null)
        {
            Thing avaliWormholePlatform = AvaliUtility.SpecifiedThingAtCellWithDefName(map.thingGrid.ThingsListAtFast(loc), "AvaliWormholePlatform");

            if (avaliWormholePlatform != null && loc == avaliWormholePlatform.InteractionCell)
            {
                return(true);
            }

            Thing avaliWormholePod = AvaliUtility.SpecifiedThingAtCellWithDefName(map.thingGrid.ThingsListAtFast(new IntVec3(loc.x, loc.y, loc.z + 1)), "AvaliWormholePod");

            if (DirectionCorrect(avaliWormholePod, loc))
            {
                return(true);
            }

            avaliWormholePod = AvaliUtility.SpecifiedThingAtCellWithDefName(map.thingGrid.ThingsListAtFast(new IntVec3(loc.x, loc.y, loc.z - 1)), "AvaliWormholePod");
            if (DirectionCorrect(avaliWormholePod, loc))
            {
                return(true);
            }

            avaliWormholePod = AvaliUtility.SpecifiedThingAtCellWithDefName(map.thingGrid.ThingsListAtFast(new IntVec3(loc.x + 1, loc.y, loc.z)), "AvaliWormholePod");
            if (DirectionCorrect(avaliWormholePod, loc))
            {
                return(true);
            }

            avaliWormholePod = AvaliUtility.SpecifiedThingAtCellWithDefName(map.thingGrid.ThingsListAtFast(new IntVec3(loc.x - 1, loc.y, loc.z)), "AvaliWormholePod");
            if (DirectionCorrect(avaliWormholePod, loc))
            {
                return(true);
            }

            return(new AcceptanceReport("MustPlaceOnWormholePlatformIntCell".Translate()));
        }
Ejemplo n.º 7
0
        public void TryStartUseJob(Pawn selPawn)
        {
            if (debug)
            {
                Log.Message("TryStartUseJob");
            }

            Job job = null;

            if (Props.workTable == null)
            {
                job = new Job(Props.useJob, parent, null, null);

                Thing sittableThing = AvaliUtility.FindAllThingsOnMapAtRange(selPawn, null, typeof(Building), null, 15, 1, true, true).First();
                if (sittableThing != null)
                {
                    job = new Job(Props.useJob, parent, sittableThing, null);
                }

                if (debug)
                {
                    Log.Message(selPawn + " job = " + Props.useJob + ", " + parent + ", " + sittableThing);
                }
            }
            else
            {
                Thing workTable = null;

                if (Props.workTable == ThingDef.Named("SimpleResearchBench"))
                {
                    workTable = AvaliUtility.FindClosestUnoccupiedThing(selPawn, ThingDef.Named("HiTechResearchBench"), 9999, true);
                    if (debug)
                    {
                        Log.Message("Closest unoccupied hi-tech research bench = " + workTable);
                    }
                }

                if (workTable == null)
                {
                    workTable = AvaliUtility.FindClosestUnoccupiedThing(selPawn, Props.workTable, 9999, false);
                    if (debug)
                    {
                        Log.Message("Closest unoccupied work table = " + workTable);
                    }
                }

                if (workTable == null)
                {
                    //if (Props.workTable.defName == "HiTechResearchBench") new AcceptanceReport("NoHiTechResearchBench".Translate());
                    //else if (Props.workTable.defName == "SimpleResearchBench") new AcceptanceReport("NoResearchBench".Translate());
                    //else new AcceptanceReport("NoAppropriateWorkBench".Translate());

                    if (debug)
                    {
                        Log.Message("workTable = null");
                    }
                    return;
                }

                if (!workTable.def.hasInteractionCell)
                {
                    Log.Error(workTable + " not have interaction cell.");
                    return;
                }

                job = new Job(Props.useJob, parent, workTable, workTable.OccupiedRect().ClosestCellTo(workTable.InteractionCell));
            }

            job.count = 1;
            selPawn.jobs.TryTakeOrderedJob(job, JobTag.MiscWork);
        }
Ejemplo n.º 8
0
        public void MakeStartingPack()
        {
            //Log.Message("DaysPassed = " + GenDate.DaysPassedFloat);
            if (pawn.IsColonist && GenDate.DaysPassedFloat > 0.1f)
            {
                makeStartingPack = false;
            }
            if (pawn.IsPrisoner)
            {
                makeStartingPack = false;
            }
            if (pawn.story.traits.HasTrait(RimWorld.TraitDefOf.Psychopath))
            {
                makeStartingPack = false;
            }

            if (makeStartingPack == false)
            {
                return;
            }

            for (int i = 0; i < relatedPawns.Count; i++)
            {
                Pawn pawn2 = relatedPawns[i];
                if (pawn.HavePackRelation(pawn2))
                {
                    makeStartingPack = false;
                    return;
                }
            }

            List <Pawn> freeHumanlikesOfFaction = pawn.Map.mapPawns.FreeHumanlikesOfFaction(pawn.Faction).ToList();

            //Log.Message("FreeColonists count = " + freeHumanlikesOfFaction.Count);

            pawnPosInQueue = 0;
            for (int i = 0; i < freeHumanlikesOfFaction.Count; i++)
            {
                Pawn pawn2 = freeHumanlikesOfFaction[i];

                if (pawn2 == pawn ||
                    pawn2.def != ThingDefOf.Avali ||
                    pawn2.IsSlave() ||
                    pawn2.story.traits.HasTrait(RimWorld.TraitDefOf.Psychopath) ||
                    pawn2.HavePackRelation(pawn))
                {
                    continue;
                }

                if (AvaliUtility.BothPawnsReproductiveOrNotReproductive(pawn, pawn2))
                {
                    if (pawn.thingIDNumber > pawn2.thingIDNumber)
                    {
                        pawnPosInQueue += 1;
                    }
                }
            }

            if (debug)
            {
                Log.Message(pawn + " ID: " + pawn.thingIDNumber + "; pawnPosInQueue = " + pawnPosInQueue);
            }
            makeStartingPack = false;
        }
Ejemplo n.º 9
0
        public override IEnumerable <FloatMenuOption> CompFloatMenuOptions(Pawn selPawn)
        {
            if (selPawn.CanReserveAndReach(parent, PathEndMode.ClosestTouch, Danger.Deadly, 1, -1, null, false))
            {
                if (parent.GetType() != typeof(Apparel))
                {
                    yield break;
                }

                if (!selPawn.IsColonist || !selPawn.Awake())
                {
                    yield break;
                }

                List <Thing> avalablePawns = AvaliUtility.FindAllThingsOnMapAtRange(parent, null, typeof(Pawn), null, float.MaxValue, int.MaxValue, true, true);
                if (avalablePawns.Count == 0)
                {
                    yield break;
                }

                const string putOnLabel = "PutOnLabel";

                for (int i = 0; i < avalablePawns.Count; i++)
                {
                    var p = avalablePawns[i] as Pawn;
                    //Log.Message("p = " + p + "; i = " + i);

                    if (p != null && p != selPawn)
                    {
                        if (!p.IsColonist && !p.IsPrisonerOfColony)
                        {
                            if (!p.Downed)
                            {
                                continue;
                            }
                            if (p.RaceProps.IsMechanoid || !p.RaceProps.ToolUser)
                            {
                                continue;
                            }
                        }
                    }
                    else
                    {
                        continue;
                    }

                    var alienDef = p.def as ThingDef_AlienRace;
                    if (alienDef != null)
                    {
                        List <string> apparelList = alienDef.alienRace.raceRestriction.apparelList;
                        if (apparelList.Count > 0)
                        {
                            apparelList.AddRange(alienDef.alienRace.raceRestriction.whiteApparelList);
                            bool isCompatibleApparel = false;

                            for (int j = 0; j < apparelList.Count; j++)
                            {
                                string apparel = apparelList[j];

                                if (parent.def.defName == apparel)
                                {
                                    isCompatibleApparel = true;
                                    break;
                                }
                            }

                            if (!isCompatibleApparel)
                            {
                                continue;
                            }
                        }
                    }

                    yield return(new FloatMenuOption(putOnLabel.Translate(p.Label), delegate
                    {
                        Job job = new Job(JobDefOf.PutOn, parent, p, selPawn.Position);
                        job.count = 1;
                        selPawn.jobs.TryTakeOrderedJob(job, JobTag.MiscWork);
                    }, MenuOptionPriority.Default, null, null, 0f, null, null));
                }
            }

            yield break;
        }