public override void Randomize() { stat = (from d in DefDatabase <StatDef> .AllDefs where d.scenarioRandomizable select d).RandomElement(); factor = GenMath.RoundedHundredth(Rand.Range(0.1f, 3f)); }
private bool Allows(Thing t, ThingDef expectedDef, QualityRange qualityRange, FloatRange hpRange, ThingFilter filter) { #if DEBUG || DEBUG_DO_UNTIL_X Log.Warning("StoredApparel.Allows Begin [" + t.Label + "]"); #endif if (t.def != expectedDef) { #if DEBUG || DEBUG_DO_UNTIL_X Log.Warning("StoredApparel.Allows End Def Does Not Match [False]"); #endif return(false); } #if DEBUG || DEBUG_DO_UNTIL_X Log.Message(" def uses HP: " + expectedDef.useHitPoints + " filter: " + hpRange.min + " " + hpRange.max); #endif if (expectedDef.useHitPoints && hpRange != null && hpRange.min != 0f && hpRange.max != 100f) { float num = (float)t.HitPoints / (float)t.MaxHitPoints; num = GenMath.RoundedHundredth(num); if (!hpRange.IncludesEpsilon(Mathf.Clamp01(num))) { #if DEBUG || DEBUG_DO_UNTIL_X Log.Warning("StoredApparel.Allows End Hit Points [False - HP]"); #endif return(false); } } #if DEBUG || DEBUG_DO_UNTIL_X Log.Message(" def follows quality: " + t.def.FollowQualityThingFilter() + " filter quality levels: " + qualityRange.min + " " + qualityRange.max); #endif if (qualityRange != null && qualityRange != QualityRange.All && t.def.FollowQualityThingFilter()) { QualityCategory p; if (!t.TryGetQuality(out p)) { p = QualityCategory.Normal; } if (!qualityRange.Includes(p)) { #if DEBUG || DEBUG_DO_UNTIL_X Log.Warning("StoredApparel.Allows End Quality [False - Quality]"); #endif return(false); } } if (filter != null && !filter.Allows(t.Stuff)) { #if DEBUG || DEBUG_DO_UNTIL_X Log.Warning("StoredApparel.Allows End Quality [False - filters.Allows]"); #endif return(false); } #if DEBUG || DEBUG_DO_UNTIL_X Log.Warning(" StoredApparel.Allows End [True]"); #endif return(true); }
public override void Randomize() { chance = GenMath.RoundedHundredth(Rand.Range(0.05f, 1f)); context = Extensions.GetEnumValues <PawnModifierContext>().RandomElement(); faction = faction = DefDatabase <FactionDef> .AllDefs.Where(f => !f.isPlayer).RandomElement(); gender = Extensions.GetEnumValues <PawnModifierGender>().RandomElement(); }
private bool Allows(Thing t, ThingDef expectedDef, ThingFilter filter) { if (filter == null) { return(true); } #if DEBUG || DEBUG_DO_UNTIL_X Log.Warning("StoredApparel.Allows Begin [" + t.Label + "]"); #endif if (t.def != expectedDef) { #if DEBUG || DEBUG_DO_UNTIL_X Log.Warning(" StoredApparel.Allows End Def Does Not Match [False]"); #endif return(false); } if (expectedDef.useHitPoints && filter.AllowedHitPointsPercents.min != 0f && filter.AllowedHitPointsPercents.max != 100f) { float num = (float)t.HitPoints / (float)t.MaxHitPoints; num = GenMath.RoundedHundredth(num); if (!filter.AllowedHitPointsPercents.IncludesEpsilon(Mathf.Clamp01(num))) { #if DEBUG || DEBUG_DO_UNTIL_X Log.Warning(" StoredApparel.Allows End Hit Points [False]"); #endif return(false); } } if (filter.AllowedQualityLevels != QualityRange.All && t.def.FollowQualityThingFilter()) { QualityCategory p; if (!t.TryGetQuality(out p)) { p = QualityCategory.Normal; } if (!filter.AllowedQualityLevels.Includes(p)) { #if DEBUG || DEBUG_DO_UNTIL_X Log.Warning(" StoredApparel.Allows End Quality [False]"); #endif return(false); } } #if DEBUG || DEBUG_DO_UNTIL_X Log.Warning(" StoredApparel.Allows End [True]"); #endif return(true); }
static void Postfix(ref float __result, HediffSet diffSet, PawnCapacityDef capacity, List <PawnCapacityUtility.CapacityImpactor> impactors, bool forTradePrice) { var pawn = diffSet.pawn; var aspectTracker = pawn.GetAspectTracker(); if (aspectTracker != null && __result > 0) { float offset = 0; float postFix = 1; float setMax = float.PositiveInfinity; foreach (Aspect aspect in aspectTracker.Aspects) { if (!aspect.HasCapMods) { continue; } foreach (PawnCapacityModifier capMod in aspect.CapMods) { if (capMod.capacity != capacity) { continue; } offset += capMod.offset; postFix *= capMod.postFactor; if (capMod.SetMaxDefined && (capMod.setMax < setMax)) { setMax = capMod.setMax; } } impactors?.Add(new AspectCapacityImpactor(aspect)); } offset += GetTotalCapacityOffset(diffSet, capacity); //need to start with the uncapped offset value offset = Mathf.Min(offset * postFix, setMax); GenMath.RoundedHundredth(Mathf.Max(offset, capacity.minValue)); __result = Mathf.Min(__result, offset); //take the min of the aspect modified value and the capped value from Rimworld's calculation } }
internal static bool Allows(StorageSettings storageSettings, QThing qthing) { if (!storageSettings.filter.Allows(qthing.def)) { return(false); } if (qthing.def.useHitPoints) { var hitPointsPercent = GenMath.RoundedHundredth(qthing.hitPoints / (float)qthing.thing.MaxHitPoints); if (!storageSettings.filter.AllowedHitPointsPercents.IncludesEpsilon(Mathf.Clamp01(hitPointsPercent))) { return(false); } } return(true); }
public static float Postfix(float __result, HediffSet diffSet, PawnCapacityDef capacity, ref List <PawnCapacityUtility.CapacityImpactor> impactors) { if (capacity.zeroIfCannotBeAwake && !diffSet.pawn.health.capacities.CanBeAwake) { return(__result); } var max = 999f; var originalMult = 1f; foreach (var hediff in diffSet.hediffs) { var capMod = hediff.CapMods?.Find(mod => mod.capacity == capacity); if (capMod == null) { continue; } originalMult *= capMod.postFactor; if (capMod.setMax < max) { max = capMod.setMax; } } var offset = diffSet.pawn.PsiTracker().GetTotalOffsetOfCapacity(capacity); var mult = diffSet.pawn.PsiTracker().GetTotalFactorOfCapacity(capacity); if (impactors != null) { var abilities = diffSet.pawn.PsiTracker().GetAllAbilitiesImpactingCapacity(capacity); impactors.AddRange(abilities.Select(ab => new CapacityImpactorPsychic { ability = ab })); } var newResult = __result * mult + offset * originalMult * mult; __result = Mathf.Min(newResult, max); return(GenMath.RoundedHundredth(Mathf.Max(__result, capacity.minValue))); }
public override void Randomize() { chance = GenMath.RoundedHundredth(Rand.Range(0.05f, 1f)); context = PawnGenerationContextUtility.GetRandom(); hideOffMap = false; }
public override void Randomize() { blindThreshold = GenMath.RoundedHundredth(Rand.Range(0f, 1f)); }
public override void Randomize() { stat = DefDatabase <StatDef> .AllDefs.Where((StatDef d) => d.scenarioRandomizable).RandomElement(); factor = GenMath.RoundedHundredth(Rand.Range(0.1f, 3f)); }
public override void DoWindowContents(Rect inRect) { Color prevColor = GUI.color; GameFont prevFont = Text.Font; TextAnchor prevAnchor = Text.Anchor; GUI.color = Color.black; Widgets.DrawBoxSolid(imageRect, GUI.color); Widgets.DrawBox(descriptionRect, 4); GUI.color = prevColor; Widgets.DrawWindowBackground(descriptionRect.ContractedBy(4f)); Widgets.DrawLightHighlight(descriptionRect.ContractedBy(4f + commonMargin)); Text.Font = GameFont.Small; Rect contracted = descriptionRect.ContractedBy(4f + commonMargin * 2f); Rect nextButtonRect = contracted.RightPartPixels(100f).TopPartPixels((contracted.height - commonMargin) / 2f); Rect lastButtonRect = nextButtonRect.CopyAndShift(0f, nextButtonRect.height + commonMargin); Widgets.LabelScrollable(contracted.LeftPartPixels(contracted.width - 100f - commonMargin), patchNoteDef.PatchNoteImageDescriptions[displayedImage], ref scrollPos); Text.Font = GameFont.Medium; Text.Anchor = TextAnchor.MiddleCenter; if (displayedImage < patchNoteDef.PatchNoteImages.Count - 1) { Widgets.DrawBoxSolid(nextButtonRect, Color.black); Widgets.Label(nextButtonRect, ">"); if (Widgets.ButtonInvisible(nextButtonRect)) { displayedImage++; SoundDefOf.Click.PlayOneShotOnCamera(); } } if (displayedImage > 0) { Widgets.DrawBoxSolid(lastButtonRect, Color.black); Widgets.Label(lastButtonRect, "<"); if (Widgets.ButtonInvisible(lastButtonRect)) { displayedImage--; SoundDefOf.Click.PlayOneShotOnCamera(); } } //Make images look better if they are 16/9 Texture2D tex = patchNoteDef.PatchNoteImages[displayedImage]; if (GenMath.RoundedHundredth((float)tex.width / tex.height / (16f / 9f)) == 1f) { GUI.DrawTexture(imageRect.ContractedBy(4f), tex); } else { GUI.DrawTexture(imageRect.ContractedBy(4f), tex, ScaleMode.ScaleToFit); } Text.Anchor = prevAnchor; Text.Font = prevFont; if (Widgets.ButtonInvisible(windowRect) && !Mouse.IsOver(imageRect) && !Mouse.IsOver(descriptionRect)) { Close(); } }
public override string GetInspectString() { return("WIN_InspectWindow".Translate(GenMath.RoundedHundredth((skyLight1 > skyLight2) ? skyLight1 : skyLight2) * 100)); }
public override void DoWindowContents(Rect inRect) { // Politics Disabled base.DoWindowContents(inRect); if (!Utility.PoliticsEnabled) { Widgets.Label(inRect, $"You need at least {Settings.MinPopulation} free, adult colonists for politics."); return; } Listing_Standard content = new Listing_Standard(); content.Begin(inRect); // Current Leader content.Label($"{Utility.LeaderTitle.CapitalizeFirst(Utility.RimocracyComp.LeaderTitleDef)}: {Utility.RimocracyComp.Leader?.NameFullColored ?? "none"}"); // Governance target, leader skills and next succession if (Utility.RimocracyComp.Leader != null) { content.Label($"Governance quality: {Utility.RimocracyComp.Governance.ToStringPercent("F1")}. Decays at {Utility.RimocracyComp.GovernanceDecayPerDay.ToStringPercent()} per day."); content.Label($"Governance target: {Utility.RimocracyComp.GovernanceTarget.ToStringPercent()}"); Utility.RimocracyComp.GovernanceTarget = GenMath.RoundedHundredth(content.Slider(Utility.RimocracyComp.GovernanceTarget, 0, 1)); if (Utility.RimocracyComp.FocusSkill != null) { content.Label($"Focus skill: {Utility.RimocracyComp.FocusSkill.LabelCap}."); } if (Utility.RimocracyComp.TermDuration != TermDuration.Indefinite) { content.Label($"Next {Utility.RimocracyComp.SuccessionWorker.def.noun} in {(Utility.RimocracyComp.TermExpiration - Find.TickManager.TicksAbs).ToStringTicksToPeriod(false)}."); } } // Next election else if (Utility.RimocracyComp.ElectionTick > Find.TickManager.TicksAbs) { content.Label($"{Utility.LeaderTitle.CapitalizeFirst(Utility.RimocracyComp.LeaderTitleDef)} will be elected in {(Utility.RimocracyComp.ElectionTick - Find.TickManager.TicksAbs).ToStringTicksToPeriod(false)}."); } else { content.Label($"Choosing a new {Utility.LeaderTitle}..."); } // Election candidates if (!Utility.RimocracyComp.Campaigns.NullOrEmpty()) { content.Gap(); content.Label("Candidates:"); content.Label(Utility.RimocracyComp.Campaigns.Select(ec => $"- {ec}").ToLineList()); } content.Gap(); if (content.ButtonText("View Decisions")) { Find.WindowStack.Add(new Dialog_DecisionList()); } content.End(); }