Beispiel #1
0
        private static int GetRoyalExpectations(Building_GuestBed bed, Pawn guest, Room room, out RoyalTitle title)
        {
            var royalExpectations = 0;

            title = guest.royalty?.HighestTitleWithBedroomRequirements();
            if (title != null)
            {
                if (room == null)
                {
                    royalExpectations -= 75;
                }
                else
                {
                    foreach (Building_Bed roomBeds in room.ContainedBeds)
                    {
                        if (roomBeds != bed && BedClaimedByStranger(roomBeds, guest))
                        {
                            royalExpectations -= 100;
                        }
                    }
                }

                if (RoyalTitleUtility.BedroomSatisfiesRequirements(room, title))
                {
                    royalExpectations += 100;
                }
            }

            return(royalExpectations);
        }
Beispiel #2
0
        private static float BedValue(Building_GuestBed bed, Pawn guest, int money)
        {
            StaticBedValue(bed, out var room, out var quality, out var impressiveness, out var roomType, out var comfort);

            var fee = RoundToInt(money > 0 ? 250 * (bed.rentalFee / money) : 0); // 0 - 250

            // Royalty requires single bed?
            var royalExpectations = GetRoyalExpectations(bed, guest, room, out var title);

            // Shared
            int otherPawnOpinion = OtherPawnOpinion(bed, guest); // -150 - 0

            // Temperature
            var temperature = GetTemperatureScore(guest, room, bed); // -200 - 0

            // Traits
            if (guest.story.traits.HasTrait(TraitDefOf.Greedy))
            {
                fee            *= 3;
                impressiveness -= 50;
            }

            if (guest.story.traits.HasTrait(TraitDefOf.Kind))
            {
                fee /= 2;
            }

            if (guest.story.traits.HasTrait(TraitDefOf.Ascetic))
            {
                impressiveness *= -1;
                roomType        = 75;  // We don't care, so always max
                comfort         = 100; // We don't care, so always max
            }

            if (guest.story.traits.HasTrait(TraitDef.Named("Jealous")))
            {
                fee            /= 4;
                impressiveness -= 50;
                impressiveness *= 4;
            }

            // Tired
            int distance = 0;

            if (guest.IsTired())
            {
                distance = (int)bed.Position.DistanceTo(guest.Position);
                //Log.Message($"{guest.LabelShort} is tired. {bed.LabelCap} is {distance} units far away.");
            }

            var score = impressiveness + quality + comfort + roomType + temperature + otherPawnOpinion + royalExpectations - distance;
            var value = CeilToInt(scoreFactor * score - fee);

            //Log.Message($"For {guest.LabelShort} {bed.Label} at {bed.Position} has a score of {score} and value of {value}:\n"
            //            + $"impressiveness = {impressiveness}, quality = {quality}, fee = {fee}, roomType = {roomType}, opinion = {otherPawnOpinion}, temperature = {temperature}, distance = {distance}");
            return(value);
        }
Beispiel #3
0
        public static int StaticBedValue(Building_GuestBed bed, [CanBeNull] out Room room, out int quality, out int impressiveness, out int roomTypeScore)
        {
            room = bed.Map != null && bed.Map.regionAndRoomUpdater.Enabled ? bed.GetRoom() : null;

            quality        = GetBedQuality(bed);
            impressiveness = room != null?GetRoomImpressiveness(room) : 0;

            roomTypeScore = GetRoomTypeScore(room) * 2;
            return(quality + impressiveness + roomTypeScore);
        }
        public static void DoBedInfos(Rect windowRect, Building_GuestBed bed)
        {
            Rect rect = new Rect(WindowPadding, 18, windowRect.width - 2 * WindowPadding, 100f);

            GUI.color = Color.white;
            Widgets.Label(rect, "BedSatisfiedTitles".Translate());
            rect.y += LineHeight + SpaceBetweenLines;
            var curY = rect.y;

            DrawTitles(rect, ref curY, bed);
            rect.y = curY;
            Widgets.Label(rect, bed.Stats.textNextTitleReq);
        }
Beispiel #5
0
        private static int OtherPawnOpinion(Building_GuestBed bed, Pawn guest)
        {
            if (!BedClaimedByStranger(bed, guest))
            {
                return(0);
            }

            // Take opinion of other into account
            var otherOwner = bed.Owners().FirstOrDefault(owner => owner != guest);
            var opinion    = otherOwner != null ? (guest.relations.OpinionOf(otherOwner) - 15) * 4 : 0;

            return(-150 + opinion);
        }
        private static void DrawTitles(Rect rectTotal, ref float curY, Building_GuestBed bed)
        {
            var stackElements = from titleDef in DefDatabase <RoyalTitleDef> .AllDefsListForReading
                                orderby titleDef.seniority
                                let titleLabel = titleDef.GetLabelCapForBothGenders()
                                                 let possibleFactions = GuestUtility.DistinctFactions.Where(f => f.def.RoyalTitlesAllInSeniorityOrderForReading.Contains(titleDef)).ToArray()
                                                                        let accepted = bed.Stats.metRoyalTitles.Contains(titleDef)
                                                                                       where possibleFactions.Length > 0
                                                                                       select new GenUI.AnonymousStackElement
            {
                drawer = delegate(Rect r) {
                    Color guiColor = GUI.color;
                    Rect  rect     = new Rect(r.x, r.y, r.width, r.height);
                    GUI.color = accepted ? CharacterCardUtility.StackElementBackground : StackElementBackgroundDisabled;
                    GUI.DrawTexture(rect, BaseContent.WhiteTex);
                    GUI.color = guiColor;
                    if (Mouse.IsOver(rect))
                    {
                        Widgets.DrawHighlight(rect);
                    }

                    Rect labelRect    = new Rect(r.x, r.y, r.width + 2f + IconSize * possibleFactions.Length, r.height);
                    Rect positionIcon = new Rect(r.x + 1f, r.y + 1f, IconSize, IconSize);
                    foreach (var faction in possibleFactions)
                    {
                        GUI.color = accepted ? faction.Color : CharacterCardUtility.StackElementBackground;
                        GUI.DrawTexture(positionIcon, faction.def.FactionIcon);
                        positionIcon.x += IconSize;
                    }

                    GUI.color = accepted ? guiColor : Color.gray;
                    Widgets.Label(new Rect(labelRect.x + labelRect.height + 5f, labelRect.y, labelRect.width - 10f, labelRect.height), titleLabel);
                    GUI.color = guiColor;
                },
                width = Text.CalcSize(titleLabel).x + 15f + IconSize * possibleFactions.Length
            };
            var stackList = stackElements.ToList();

            curY += GenUI.DrawElementStack(
                new Rect(15f, curY, rectTotal.width - 5f, 50f),
                22f,
                stackList,
                delegate(Rect r, GenUI.AnonymousStackElement obj) { obj.drawer(r); },
                obj => obj.width, 4, 5, false).height;

            if (stackList.Any())
            {
                curY += 10f;
            }
        }
Beispiel #7
0
        public override ThinkResult TryIssueJobPackage(Pawn pawn, JobIssueParams jobParams)
        {
            if (pawn.CurJob != null)
            {
                //Log.Message(pawn.NameStringShort + " already has a job: " + pawn.CurJob);
                return(new ThinkResult(pawn.CurJob, this));
            }
            if (pawn.needs == null || pawn.needs.rest == null)
            {
                if (pawn.needs == null)
                {
                    Log.ErrorOnce(pawn.NameStringShort + " has no needs", 453636 + pawn.thingIDNumber);
                }
                if (pawn.needs.rest == null)
                {
                    Log.ErrorOnce(pawn.NameStringShort + " has no rest need", 357474 + pawn.thingIDNumber);
                }
                return(ThinkResult.NoJob);
            }
            if (pawn.mindState == null)
            {
                Log.ErrorOnce(pawn.NameStringShort + " has no mindstate", 23892 + pawn.thingIDNumber);
                pawn.mindState = new Pawn_MindState(pawn);
            }

            if (Find.TickManager.TicksGame - pawn.mindState.lastDisturbanceTick < 400)
            {
                Log.Message(pawn.NameStringShort + " can't sleep - got disturbed");
                return(ThinkResult.NoJob);
            }
            Building_GuestBed bed = pawn.FindBedFor();

            if (bed != null)
            {
                return(new ThinkResult(new Job(JobDefOf.LayDown, bed), this));
            }
            IntVec3 vec = CellFinder.RandomClosewalkCellNear(pawn.mindState.duty.focus.Cell, pawn.MapHeld, 4);

            if (!pawn.CanReserve(vec))
            {
                return(ThinkResult.NoJob);
            }

            pawn.Reserve(vec);
            return(new ThinkResult(new Job(JobDefOf.LayDown, vec), this));
        }
Beispiel #8
0
 public Gizmo_GuestBedStats(Building_GuestBed bed)
 {
     this.bed = bed;
     order    = -100f;
 }
Beispiel #9
0
 private static float GetBedComfort(Building_GuestBed bed)
 {
     return(bed.GetStatValue(StatDefOf.Comfort));
 }