public override void SpawnSetup(Map map, bool respawningAfterLoad) { base.SpawnSetup(map, respawningAfterLoad); if (respawningAfterLoad) { return; } ticksToImpact = (ticksToImpactMax = def.skyfaller.ticksToImpactRange.RandomInRange); if (def.skyfaller.MakesShrapnel) { float num = GenMath.PositiveMod(shrapnelDirection, 360f); if (num < 270f && num >= 90f) { angle = Rand.Range(0f, 33f); } else { angle = Rand.Range(-33f, 0f); } } else if (def.skyfaller.angleCurve != null) { angle = def.skyfaller.angleCurve.Evaluate(0f); } else { angle = -33.7f; } if (def.rotatable && innerContainer.Any) { base.Rotation = innerContainer[0].Rotation; } }
public static int HourInteger(long absTicks, float longitude) { long x = absTicks + GenDate.LocalTicksOffsetFromLongitude(longitude); int num = (int)GenMath.PositiveMod(x, 60000L); return(num / 2500); }
protected virtual void OnClick() { IEnumerable <GlobalTargetInfo> allCulprits = GetReport().AllCulprits; if (allCulprits == null) { return; } tmpTargets.Clear(); foreach (GlobalTargetInfo item in allCulprits) { if (item.IsValid) { tmpTargets.Add(item); } } if (tmpTargets.Any()) { if (Event.current.button == 1) { jumpToTargetCycleIndex--; } else { jumpToTargetCycleIndex++; } CameraJumper.TryJumpAndSelect(tmpTargets[GenMath.PositiveMod(jumpToTargetCycleIndex, tmpTargets.Count)]); tmpTargets.Clear(); } }
public override void SpawnSetup(Map map, bool respawningAfterLoad) { base.SpawnSetup(map, respawningAfterLoad); if (!respawningAfterLoad) { vehicle.CompVehicleLauncher.launchProtocol.SetPositionArriving(new Vector3(DrawPos.x, DrawPos.y + 1, DrawPos.z), Rotation, map); vehicle.CompVehicleLauncher.launchProtocol.OrderProtocol(true); delayLandingTicks = vehicle.CompVehicleLauncher.launchProtocol.landingProperties?.delayByTicks ?? 0; ticksToImpact = def.skyfaller.ticksToImpactRange.RandomInRange; if (def.skyfaller.MakesShrapnel) { float num = GenMath.PositiveMod(shrapnelDirection, 360f); if (num < 270f && num >= 90f) { angle = Rand.Range(0f, 33f); } else { angle = Rand.Range(-33f, 0f); } } else if (def.skyfaller.angleCurve != null) { angle = def.skyfaller.angleCurve.Evaluate(0f); } else { angle = DefaultAngle; } Rotation = rotCrashing; } }
//public TM_Skyfaller() //{ // this.innerContainer = new ThingOwner<Thing>(this); //} //public override void ExposeData() //{ // base.ExposeData(); // Scribe_Deep.Look<ThingOwner>(ref this.innerContainer, "innerContainer", new object[] // { // this // }); // Scribe_Values.Look<int>(ref this.ticksToImpact, "ticksToImpact", 0, false); // Scribe_Values.Look<float>(ref this.angle, "angle", 0f, false); // Scribe_Values.Look<float>(ref this.shrapnelDirection, "shrapnelDirection", 0f, false); //} //public override void PostMake() //{ // base.PostMake(); // if (this.def.skyfaller.MakesShrapnel) // { // this.shrapnelDirection = Rand.Range(0f, 360f); // } //} public override void SpawnSetup(Map map, bool respawningAfterLoad) { base.SpawnSetup(map, respawningAfterLoad); if (!respawningAfterLoad) { this.ticksToImpact = this.def.skyfaller.ticksToImpactRange.RandomInRange; if (this.def.skyfaller.MakesShrapnel) { float num = GenMath.PositiveMod(this.shrapnelDirection, 360f); if (num < 270f && num >= 90f) { this.angle = Rand.Range(0f, 33f); } else { this.angle = Rand.Range(-33f, 0f); } } else { this.angle = -80f; } if (this.def.rotatable && this.innerContainer.Any) { base.Rotation = Rot4.FromAngleFlat(this.angle - 90f);//this.innerContainer[0].Rotation; } } }
void TransformUVs(LayerSubMesh mesh) { // Fix texture flip if (GraphicPrintPatch.matData.TryGetValue(mesh.material, out var matData)) { var fullRot = GenMath.PositiveMod(matData.Item2.AsInt - Rot4.FromAngleFlat(target).AsInt, 4); var graphic = matData.Item1; var flipped = fullRot == 1 && graphic.EastFlipped || fullRot == 3 && graphic.WestFlipped ? 1 : 0; var origUvs = Printer_Plane.defaultUvs; var uvsc = mesh.uvs.Count; Util.ResizeIfNeeded(ref tempUVs, uvsc); for (int i = 0; i < uvsc; i += 4) { tempUVs[i + (3 * flipped & 3)] = origUvs[0]; tempUVs[i + (1 + flipped & 3)] = origUvs[1]; tempUVs[i + (2 + 3 * flipped & 3)] = origUvs[2]; tempUVs[i + (3 + flipped & 3)] = origUvs[3]; } mesh.mesh.SetUVs(tempUVs, uvsc); } }
public static float YearPercent(long absTicks, float longitude) { long x = absTicks + GenDate.LocalTicksOffsetFromLongitude(longitude); int num = (int)GenMath.PositiveMod(x, 3600000L); return((float)num / 3600000f); }
public static void SelectPreviousColonist() { tmpColonists.Clear(); tmpColonists.AddRange(Find.ColonistBar.GetColonistsInOrder().Where(SelectableByHotkey)); if (tmpColonists.Count != 0) { bool worldRenderedNow = WorldRendererUtility.WorldRenderedNow; int num = -1; for (int i = 0; i < tmpColonists.Count; i++) { if ((!worldRenderedNow && Find.Selector.IsSelected(tmpColonists[i])) || (worldRenderedNow && tmpColonists[i].IsCaravanMember() && Find.WorldSelector.IsSelected(tmpColonists[i].GetCaravan()))) { num = i; break; } } if (num == -1) { CameraJumper.TryJumpAndSelect(tmpColonists[tmpColonists.Count - 1]); } else { CameraJumper.TryJumpAndSelect(tmpColonists[GenMath.PositiveMod(num - 1, tmpColonists.Count)]); } tmpColonists.Clear(); } }
public static void SelectPreviousColonist() { ThingSelectionUtility.tmpColonists.Clear(); ThingSelectionUtility.tmpColonists.AddRange(Find.ColonistBar.GetColonistsInOrder().Where(new Func <Pawn, bool>(ThingSelectionUtility.SelectableByHotkey))); if (ThingSelectionUtility.tmpColonists.Count == 0) { return; } bool worldRenderedNow = WorldRendererUtility.WorldRenderedNow; int num = -1; for (int i = 0; i < ThingSelectionUtility.tmpColonists.Count; i++) { if ((!worldRenderedNow && Find.Selector.IsSelected(ThingSelectionUtility.tmpColonists[i])) || (worldRenderedNow && ThingSelectionUtility.tmpColonists[i].IsCaravanMember() && Find.WorldSelector.IsSelected(ThingSelectionUtility.tmpColonists[i].GetCaravan()))) { num = i; break; } } if (num == -1) { CameraJumper.TryJumpAndSelect(ThingSelectionUtility.tmpColonists[ThingSelectionUtility.tmpColonists.Count - 1]); } else { CameraJumper.TryJumpAndSelect(ThingSelectionUtility.tmpColonists[GenMath.PositiveMod(num - 1, ThingSelectionUtility.tmpColonists.Count)]); } ThingSelectionUtility.tmpColonists.Clear(); }
public static void SelectPreviousColonist() { ThingSelectionUtility.tmpColonists.Clear(); List <Pawn> list = ThingSelectionUtility.tmpColonists; IEnumerable <Pawn> colonistsInOrder = Find.ColonistBar.GetColonistsInOrder(); if (ThingSelectionUtility.< > f__mg$cache1 == null) { ThingSelectionUtility.< > f__mg$cache1 = new Func <Pawn, bool>(ThingSelectionUtility.SelectableByHotkey); } list.AddRange(colonistsInOrder.Where(ThingSelectionUtility.< > f__mg$cache1)); if (ThingSelectionUtility.tmpColonists.Count != 0) { bool worldRenderedNow = WorldRendererUtility.WorldRenderedNow; int num = -1; for (int i = 0; i < ThingSelectionUtility.tmpColonists.Count; i++) { if ((!worldRenderedNow && Find.Selector.IsSelected(ThingSelectionUtility.tmpColonists[i])) || (worldRenderedNow && ThingSelectionUtility.tmpColonists[i].IsCaravanMember() && Find.WorldSelector.IsSelected(ThingSelectionUtility.tmpColonists[i].GetCaravan()))) { num = i; break; } } if (num == -1) { CameraJumper.TryJumpAndSelect(ThingSelectionUtility.tmpColonists[ThingSelectionUtility.tmpColonists.Count - 1]); } else { CameraJumper.TryJumpAndSelect(ThingSelectionUtility.tmpColonists[GenMath.PositiveMod(num - 1, ThingSelectionUtility.tmpColonists.Count)]); } ThingSelectionUtility.tmpColonists.Clear(); } }
private void SelectPreviousInGroup() { List <CompTransporter> list = TransportersInGroup(Map); int num = list.IndexOf(this); CameraJumper.TryJumpAndSelect(list[GenMath.PositiveMod(num - 1, list.Count)].parent); }
public virtual Rect DrawAt(float topY, bool minimized) { Text.Font = GameFont.Small; string label = GetLabel(); float height = Text.CalcHeight(label, 148f); Rect rect = new Rect((float)UI.screenWidth - 154f, topY, 154f, height); if (alertBounce != null) { rect.x -= alertBounce.CalculateHorizontalOffset(); } GUI.color = BGColor; GUI.DrawTexture(rect, AlertBGTex); GUI.color = Color.white; GUI.BeginGroup(rect); Text.Anchor = TextAnchor.MiddleRight; Widgets.Label(new Rect(0f, 0f, 148f, height), label); GUI.EndGroup(); if (Mouse.IsOver(rect)) { GUI.DrawTexture(rect, AlertBGTexHighlight); } if (Widgets.ButtonInvisible(rect)) { AlertReport report = GetReport(); IEnumerable <GlobalTargetInfo> culprits = report.culprits; if (culprits != null) { tmpTargets.Clear(); foreach (GlobalTargetInfo item in culprits) { if (item.IsValid) { tmpTargets.Add(item); } } if (tmpTargets.Any()) { if (Event.current.button == 1) { jumpToTargetCycleIndex--; } else { jumpToTargetCycleIndex++; } GlobalTargetInfo target = tmpTargets[GenMath.PositiveMod(jumpToTargetCycleIndex, tmpTargets.Count)]; CameraJumper.TryJumpAndSelect(target); tmpTargets.Clear(); } } } Text.Anchor = TextAnchor.UpperLeft; return(rect); }
public static float DayPercent(long absTicks, float longitude) { long x = absTicks + GenDate.LocalTicksOffsetFromLongitude(longitude); int num = (int)GenMath.PositiveMod(x, 60000L); if (num == 0) { num = 1; } return((float)num / 60000f); }
public static void TimeControlButton(Rect button, ITickable tickable, float alpha) { Widgets.DrawRectFast(button, new Color(0.5f, 0.5f, 0.5f, 0.4f * alpha)); int speed = (int)tickable.TimeSpeed; if (Widgets.ButtonImage(button, TexButton.SpeedButtonTextures[speed])) { int dir = Event.current.button == 0 ? 1 : -1; SendTimeChange(tickable, (TimeSpeed)GenMath.PositiveMod(speed + dir, (int)TimeSpeed.Ultrafast)); Event.current.Use(); } }
void TransformAtlas(LayerSubMesh mesh, TextureAtlasGroup group) { var offset = Rot4.FromAngleFlat(target); var offseti = offset.AsInt; var vertsc = mesh.verts.Count / 5 * 4; var uvsc = mesh.uvs.Count; var vertsArr = NoAllocHelpers.ExtractArrayFromListT(mesh.verts); var uvsArr = NoAllocHelpers.ExtractArrayFromListT(mesh.uvs); Util.ResizeIfNeeded(ref tempVerts, vertsc); Util.ResizeIfNeeded(ref tempUVs, uvsc); for (int i = 0; i < vertsc; i += 4) { var data = vertsArr[vertsc + i / 4]; if (data.x == PrintPlanePatch.SPECIAL_X) { ExchangeVerts(tempVerts, vertsArr, i, offseti); var rotData = ((int)data.z & 0b1100) >> 2; var flipData = (int)data.z & 0b0011; var relRot = GenMath.PositiveMod(rotData - Rot4.FromAngleFlat(target).AsInt, 4); var flipped = relRot == 1 && ((flipData & 1) == 1) || relRot == 3 && ((flipData & 2) == 2) ? 1 : 0; var rotatedMat = GraphicPrintPatch_SetData.intToGraphic[(int)data.y].mats[(rotData + Rot4.FromAngleFlat(-target).AsInt) % 4]; Graphic.TryGetTextureAtlasReplacementInfo(rotatedMat, group, false, false, out _, out var uvs, out _); FixUVs( tempUVs, uvs, i, flipped ); } else if (data.x != PrintPlanePatch.EMPTY_X) { RotateVerts(tempVerts, vertsArr, i, data, offset); Array.Copy(uvsArr, i, tempUVs, i, 4); } else { Array.Copy(vertsArr, i, tempVerts, i, 4); Array.Copy(uvsArr, i, tempUVs, i, 4); } } mesh.mesh.SetVertices(tempVerts, vertsc); mesh.mesh.SetUVs(tempUVs, uvsc); }
public void RotateBy(float by) { current = target; start = current; progress = 0; sectionsDone = 0; workerIndex = 0; cameraPos = Find.CameraDriver.MapPosition; target += by; target = GenMath.PositiveMod(target, 360f); //Log.Message($"{Time.frameCount} {target} {current}"); }
public void Update() { var dist = Mathf.DeltaAngle(start, target); current = GenMath.PositiveMod(start + progress * progress * dist / (AnimTime * AnimTime), 360f); if (current != target) { AnimationStep(); } if (Find.CurrentMap == map) { Find.Camera.transform.rotation = Quaternion.Euler(90, current, 0); } }
public static void TimeControlButton(Rect button, Color bgColor, ITickable tickable) { int speed = (int)tickable.TimeSpeed; if (tickable.ActualRateMultiplier(TimeSpeed.Normal) == 0f) { speed = 0; } Widgets.DrawRectFast(button, bgColor); if (Widgets.ButtonImage(button, TexButton.SpeedButtonTextures[speed])) { int dir = Event.current.button == 0 ? 1 : -1; SendTimeChange(tickable, (TimeSpeed)GenMath.PositiveMod(speed + dir, (int)TimeSpeed.Ultrafast)); Event.current.Use(); } }
public static void SelectPreviousTameAnimal() { var animals = AllTameAnimalsInOrder; var index = 1; LogDebug(animals, true); for (int i = 0; i < animals.Count; i++) // count up because there may be multiple pawns in a caravan, and we cannot select them individually // if we were to loop down, and there was more than one pawn in a caravan, we'd select the same caravan forever. { if (IsSelected(animals[i])) { index = i; break; } } index = GenMath.PositiveMod(index - 1, animals.Count); CameraJumper.TryJumpAndSelect(animals[index]); }
void TransformUVs(LayerSubMesh mesh) { // Fix texture flip if (GraphicPrintPatch_TransformMats.exchangeMats.TryGetValue(mesh.material, out var matData)) { var uvsc = mesh.uvs.Count; var graphic = matData.Item1; var relRot = GenMath.PositiveMod(matData.Item2.AsInt - Rot4.FromAngleFlat(target).AsInt, 4); var flipped = relRot == 1 && graphic.EastFlipped || relRot == 3 && graphic.WestFlipped ? 1 : 0; Util.ResizeIfNeeded(ref tempUVs, uvsc); for (int i = 0; i < uvsc; i += 4) { FixUVs(tempUVs, Printer_Plane.defaultUvs, i, flipped); } mesh.mesh.SetUVs(tempUVs, uvsc); } }
static bool Prefix(ref Skyfaller __instance, Map map, bool respawningAfterLoad, ref int ___ticksToImpactMax) { BaseSpawnSetup(__instance, map, respawningAfterLoad); if (respawningAfterLoad) { return(false); } __instance.ticksToImpact = ___ticksToImpactMax = new IntRange(120, 200).RandomInRange / RefcellRespeedConfig.currentTimeMultiplier; if (__instance.def.skyfaller.MakesShrapnel) { float num = GenMath.PositiveMod(__instance.shrapnelDirection, 360f); __instance.angle = (double)num >= 270.0 || (double)num < 90.0 ? Rand.Range(-33f, 0.0f) : Rand.Range(0.0f, 33f); } else { __instance.angle = __instance.def.skyfaller.angleCurve == null ? -33.7f : __instance.def.skyfaller.angleCurve.Evaluate(0.0f); } if (!__instance.def.rotatable || !__instance.innerContainer.Any) { return(false); } __instance.Rotation = __instance.innerContainer[0].Rotation; return(false); }
//Exact copy (1.1) private static void CalculateNeededLOSToCells(IntVec3 position, Map map, float direction, out IntVec3?needLOSToCell1, out IntVec3?needLOSToCell2) { needLOSToCell1 = null; needLOSToCell2 = null; if (position.CanBeSeenOverFast(map)) { return; } direction = GenMath.PositiveMod(direction, 360f); IntVec3 intVec = position; intVec.z++; IntVec3 intVec2 = position; intVec2.z--; IntVec3 intVec3 = position; intVec3.x--; IntVec3 intVec4 = position; intVec4.x++; if (direction < 90f) { if (intVec3.InBounds(map) && intVec3.CanBeSeenOverFast(map)) { needLOSToCell1 = new IntVec3?(intVec3); } if (intVec.InBounds(map) && intVec.CanBeSeenOverFast(map)) { needLOSToCell2 = new IntVec3?(intVec); return; } } else if (direction < 180f) { if (intVec.InBounds(map) && intVec.CanBeSeenOverFast(map)) { needLOSToCell1 = new IntVec3?(intVec); } if (intVec4.InBounds(map) && intVec4.CanBeSeenOverFast(map)) { needLOSToCell2 = new IntVec3?(intVec4); return; } } else if (direction < 270f) { if (intVec4.InBounds(map) && intVec4.CanBeSeenOverFast(map)) { needLOSToCell1 = new IntVec3?(intVec4); } if (intVec2.InBounds(map) && intVec2.CanBeSeenOverFast(map)) { needLOSToCell2 = new IntVec3?(intVec2); return; } } else { if (intVec2.InBounds(map) && intVec2.CanBeSeenOverFast(map)) { needLOSToCell1 = new IntVec3?(intVec2); } if (intVec3.InBounds(map) && intVec3.CanBeSeenOverFast(map)) { needLOSToCell2 = new IntVec3?(intVec3); } } }
public static float YearPercent(long absTicks, float longitude) { return((float)(int)GenMath.PositiveMod(absTicks + LocalTicksOffsetFromLongitude(longitude), 3600000L) / 3600000f); }
public static int DayTick(long absTicks, float longitude) { return((int)GenMath.PositiveMod(absTicks + LocalTicksOffsetFromLongitude(longitude), 60000L)); }
public static int DayTick(long absTicks, float longitude) { long x = absTicks + GenDate.LocalTicksOffsetFromLongitude(longitude); return((int)GenMath.PositiveMod(x, 60000L)); }