private void OnTriggerEnter(Collider other) { float distance = Vector3.Distance(LocalPlayer.Transform.position, this.transform.position); if (distance < 100) { soundEmitter.PlayExplosionSound(); LocalPlayer.HitReactions.enableFootShake(1, Math.Min(30 / distance, 0.5f)); } if (other.CompareTag("suitCase") || other.CompareTag("metalProp") || other.CompareTag("animalCollide") || other.CompareTag("Fish") || other.CompareTag("Tree") || other.CompareTag("MidTree") || other.CompareTag("suitCase") || other.CompareTag("SmallTree")) { other.SendMessage("Hit", Damage, SendMessageOptions.DontRequireReceiver); other.SendMessage("Explosion", 0.1f, SendMessageOptions.DontRequireReceiver); } else if (other.transform.root == LocalPlayer.Transform.root) { LocalPlayer.Stats.Hit(Damage, false, PlayerStats.DamageType.Fire); ModdedPlayer.instance.Stun(3f); BuffDB.AddBuff(21, 69, Damage / 3, 60); other.SendMessage("Burn", SendMessageOptions.DontRequireReceiver); } else if (other.CompareTag("BreakableWood") || other.CompareTag("BreakableRock") || other.CompareTag("BreakableRock") || other.CompareTag("structure")) { other.SendMessage("Hit", Damage, SendMessageOptions.DontRequireReceiver); other.SendMessage("LocalizedHit", new LocalizedHitData(transform.position, Damage), SendMessageOptions.DontRequireReceiver); } }
public static void SetSettings(MyGlobalLoddingSettings globalLodding, MyPassLoddingSetting gbufferLodding, MyPassLoddingSetting[] cascadeDepthLoddings, MyPassLoddingSetting singleDepthLodding) { m_objectDistanceAdd = globalLodding.ObjectDistanceAdd; m_objectDistanceMult = globalLodding.ObjectDistanceMult; for (int i = 0; i < MyPassIdResolver.MaxGBufferPassesCount; i++) { m_loddingSetting[MyPassIdResolver.DefaultGBufferPassId] = gbufferLodding; } int cascadeDepthPassesCount = Math.Min(cascadeDepthLoddings.Length, MyPassIdResolver.MaxCascadeDepthPassesCount); for (int i = 0; i < cascadeDepthPassesCount; i++) { m_loddingSetting[MyPassIdResolver.GetCascadeDepthPassId(i)] = cascadeDepthLoddings[i]; } for (int i = cascadeDepthPassesCount; i < MyPassIdResolver.MaxCascadeDepthPassesCount; i++) { m_loddingSetting[MyPassIdResolver.GetCascadeDepthPassId(i)] = MyPassLoddingSetting.Default; } for (int i = 0; i < MyPassIdResolver.MaxCascadeDepthPassesCount; i++) { m_loddingSetting[MyPassIdResolver.GetSingleDepthPassId(i)] = singleDepthLodding; } }
public static void SetHeight(float[,] heightMap, Vector2 pos, float height) { int x = Math.Max(Math.Min((int)pos.X, heightMap.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, heightMap.GetLength(1) - 1), 0); heightMap[x, y] = height; }
public Interval Range(Interval other) { int start = Math.Min(Start, other.Start); int endInclusive = Math.Max(EndInclusive, other.EndInclusive); return(FromBounds(start, endInclusive)); }
/// <summary> /// Gets the torsional stiffness. /// </summary> /// <returns>System.Double.</returns> protected override double GetTorsionalStiffness() { double a1 = 0.5 * NMath.Max(b, d); double a2 = 0.5 * NMath.Min(b, d); return(a1 * a2.Cubed() * ((16d / 3) - 3.36 * (a2 / a1) * (1 - (a2 / a1).Pow(4) / 12))); }
public int Closest(Vector3D p) { // Needs to be non-euclidean calc, // Moving the hex to the center will make that be the case. Mobius m = MobiusToCenter; Polygon poly = Hexagon.Clone(); poly.Transform(m); p = m.Apply(p); double d1 = poly.Segments[1].Midpoint.Dist(p); double d2 = poly.Segments[3].Midpoint.Dist(p); double d3 = poly.Segments[5].Midpoint.Dist(p); double min = Math.Min(d1, Math.Min(d2, d3)); if (min == d1) { return(4); } if (min == d2) { return(0); } if (min == d3) { return(2); } return(-1); }
/// <summary> /// Updates the extents to include the specified coordinate. /// </summary> /// <param name="coordinate">The coordinate.</param> public void Add(Point3D coordinate) { if (coordinate.Y > MaxY) { MaxY = NMath.Min(coordinate.Y, _minY); } if (coordinate.Y < MinY) { MinY = NMath.Max(coordinate.Y, _maxY); } if (coordinate.X > MaxX) { MaxX = NMath.Min(coordinate.X, _minX); } if (coordinate.X < MinX) { MinX = NMath.Max(coordinate.X, _maxX); } if (coordinate.Z > MaxZ) { MaxZ = NMath.Min(coordinate.Z, _minZ); } if (coordinate.Z < MinZ) { MinZ = NMath.Max(coordinate.Z, _maxZ); } }
protected override void OnMeasure(int widthMeasureSpec, int heightMeasureSpec) { base.OnMeasure(widthMeasureSpec, heightMeasureSpec); width = MeasureSpec.GetSize(widthMeasureSpec); height = MeasureSpec.GetSize(heightMeasureSpec); //Fit to screen. float scale; float scaleX = width / bmWidth; float scaleY = height / bmHeight; scale = Math.Min(scaleX, scaleY); matrix.SetScale(scale, scale); ImageMatrix = matrix; saveScale = 1f; // Center the image redundantYSpace = height - (scale * bmHeight); redundantXSpace = width - (scale * bmWidth); redundantYSpace /= 2; redundantXSpace /= 2; matrix.PostTranslate(redundantXSpace, redundantYSpace); origWidth = width - 2 * redundantXSpace; origHeight = height - 2 * redundantYSpace; right = width * saveScale - width - (2 * redundantXSpace * saveScale); bottom = height * saveScale - height - (2 * redundantYSpace * saveScale); ImageMatrix = matrix; }
public static float GetHeight(float[,] heightMap, Vector2 pos) { int x = Math.Max(Math.Min((int)pos.X, heightMap.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, heightMap.GetLength(1) - 1), 0); return(heightMap[x, y]); }
/** * Create a color integer value with specified alpha. * This may be useful to change alpha value of background color. * * @param alpha alpha value from 0.0f to 1.0f. * @param baseColor base color. alpha value will be ignored. * @return a color with alpha made from base color */ public static int GetColorWithAlpha(float alpha, int baseColor) { int a = Math.Min(255, Math.Max(0, (int)(alpha * 255))) << 24; int rgb = 0x00ffffff & baseColor; return(a + rgb); }
public static void AddValue(MapData[,] map, Vector2 pos, ScalarFieldType value, float amount) { int x = Math.Max(Math.Min((int)pos.X, map.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, map.GetLength(1) - 1), 0); map[x, y].SetValue(value, map[x, y].GetValue(value) + amount); }
public static float GetValue(MapData[,] map, Vector2 pos, ScalarFieldType value) { int x = Math.Max(Math.Min((int)pos.X, map.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, map.GetLength(1) - 1), 0); return(map[x, y].GetValue(value)); }
/** * Generate a frequency set as the union of two input sets, with the * values clipped to a specified maximum value. If an element is * contained in both sets, the value for the output, prior to clipping, * will be the sum of the two input values. * * @param a The first set. * @param b The second set. * @param clip The maximum value to allow for any output. * @return The sum of the two sets, with the individual elements clipped * to the maximum value given by {@code clip}. */ protected static FrequencySet <string> CombineAndClip(FrequencySet <string> a, FrequencySet <string> b, int clip) { FrequencySet <string> result = new FrequencySet <string>(); foreach (KeyValuePair <string, StrongBox <int> > entry in a) { for (int i = 0; i < entry.Value.Value; i++) { result.Add(entry.Key); } } foreach (KeyValuePair <string, StrongBox <int> > entry in b) { for (int i = 0; i < entry.Value.Value; i++) { result.Add(entry.Key); } } foreach (KeyValuePair <string, StrongBox <int> > entry in result) { entry.Value.Value = Math.Min(entry.Value.Value, clip); } return(result); }
public static WaterType GetWater(MapData[,] map, Vector2 pos) { int x = Math.Max(Math.Min((int)pos.X, map.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, map.GetLength(1) - 1), 0); return(map[x, y].Water); }
/// <summary> /// Updates the extents to include the specified coordinate. /// </summary> /// <param name="coordinate">The coordinate.</param> public override void Add(CartesianCoordinate3D coordinate) { if (coordinate.Y > MaxY) { MaxY = NMath.Min(coordinate.Y, _minY); } if (coordinate.Y < MinY) { MinY = NMath.Max(coordinate.Y, _maxY); } if (coordinate.X > MaxX) { MaxX = NMath.Min(coordinate.X, _minX); } if (coordinate.X < MinX) { MinX = NMath.Max(coordinate.X, _maxX); } if (coordinate.Z > MaxZ) { MaxZ = NMath.Min(coordinate.Z, _minZ); } if (coordinate.Z < MinZ) { MinZ = NMath.Max(coordinate.Z, _maxZ); } }
/// <summary> /// {@inheritDoc} </summary> protected internal override double DoIntegrate() { // Compute first estimate with a single step. double oldt = this.Stage(1); int n = 2; while (true) { // Improve integral with a larger number of steps. double t = this.Stage(n); // Estimate the error. double delta = FastMath.Abs(t - oldt); double limit = FastMath.Max(this.AbsoluteAccuracy, this.RelativeAccuracy * (FastMath.Abs(oldt) + FastMath.Abs(t)) * 0.5); // check convergence if (this.iterations.Count + 1 >= this.MinimalIterationCount && delta <= limit) { return(t); } // Prepare next iteration. double ratio = FastMath.Min(4, FastMath.Pow(delta / limit, 0.5 / this.numberOfPoints)); n = FastMath.Max((int)(ratio * n), n + 1); oldt = t; this.iterations.IncrementCount(); } }
public override sealed string toHex() { try { long oldPos = getPos(); int size = (int)getSize(); byte[] temp = this.temp(); char[] hexChars = Buf.hexChars; StringBuilder s = new StringBuilder(size * 2); setPos(0); int total = 0; while (total < size) { int n = m_stream.Read(temp, 0, Math.Min(temp.Length, size - total)); for (int i = 0; i < n; ++i) { int b = temp[i] & 0xFF; s.Append(hexChars[b >> 4]).Append(hexChars[b & 0xf]); } total += n; } setPos(oldPos); return(s.ToString()); } catch (IOException e) { throw IOErr.make(e).val; } }
//---------------------------------------------------------------------------------------- private void Apply() { m_settings.Target.transform.position = Time.deltaTime > 0 ? Vector3.Lerp(m_settings.Target.transform.position, m_settings.Panning, m_settings.PanSmoothing * Time.deltaTime) : m_settings.Panning; Vector3 currentPos = m_settings.Target.transform.position; currentPos.x += m_settings.XDistance; currentPos.y += m_settings.YDistance; currentPos.z += m_settings.ZDistance; float target = m_settings.TiltStart; if (m_settings.AllowZoomTilting) { float zoomChange = m_settings.TiltMaxChange / (m_settings.TiltStart - Mathf.Abs(m_settings.MinZoom)); float change = Math.Min((m_settings.TiltStart - m_settings.Zoom) * zoomChange, 0); target = m_settings.TiltAngle + change; } m_smoothTitlt = Time.deltaTime > 0 ? Mathf.SmoothDamp(m_smoothTitlt, target, ref m_smoothVelocity, Time.deltaTime * m_settings.TiltSmoothing) : target; Quaternion rotation = Quaternion.Euler(m_smoothTitlt, m_settings.Rotation, 0); Vector3 position = rotation * new Vector3(0, 0, -currentPos.y) + m_settings.Target.transform.position; position.y = Math.Max(position.y, m_settings.MinHeightOffset); transform.position = Time.deltaTime > 0 ? Vector3.Lerp(transform.position, position, m_settings.PanSmoothing * Time.deltaTime) : position; transform.rotation = rotation; }
public static void SetWater(MapData[,] heightMap, Vector2 pos, WaterType waterType) { int x = Math.Max(Math.Min((int)pos.X, heightMap.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, heightMap.GetLength(1) - 1), 0); heightMap[x, y].Water = waterType; }
private static int GetMaxCacheSize(int maxCacheSize) { if (maxCacheSize <= 0) { return(GetCacheSizeInPercent(0.2f)); // 20% } return(Math.Min(GetCacheSizeInPercent(0.2f), maxCacheSize)); }
public static void MultValue(MapData[,] heightMap, Vector2 pos, ScalarFieldType value, float height) { int x = Math.Max(Math.Min((int)pos.X, heightMap.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, heightMap.GetLength(1) - 1), 0); float c = heightMap[x, y].GetValue(value); heightMap[x, y].SetValue(value, c * height); }
/** <summary>Sets the size of a set.</summary> * <param name="nwords">how many words the new set should be</param> */ private void SetSize(int nwords) { ulong[] newbits = new ulong[nwords]; int n = Math.Min(nwords, _bits.Length); Array.Copy(_bits, newbits, n); _bits = newbits; }
public static void AddValue(OverworldCell[,] map, Vector2 pos, OverworldField value, float amount) { DebugHelper.AssertNotNull(map); int x = Math.Max(Math.Min((int)pos.X, map.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, map.GetLength(1) - 1), 0); map[x, y].SetValue(value, map[x, y].GetValue(value) + amount); }
private static int GetMaxCacheSize() { if (ImageService.Config.MaxCacheSize <= 0) { return(GetCacheSizeInPercent(0.2f)); // 20% } return(Math.Min(GetCacheSizeInPercent(0.2f), ImageService.Config.MaxCacheSize)); }
public static float GetValue(OverworldCell[,] map, Vector2 pos, OverworldField value) { DebugHelper.AssertNotNull(map); int x = Math.Max(Math.Min((int)pos.X, map.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, map.GetLength(1) - 1), 0); return(map[x, y].GetValue(value)); }
public override int Write(byte[] src, int timeoutMillis) { var endpoint = mDevice.GetInterface(0).GetEndpoint(1); var offset = 0; while (offset < src.Length) { int writeLength; int amtWritten; lock (mWriteBufferLock) { byte[] writeBuffer; writeLength = Math.Min(src.Length - offset, mWriteBuffer.Length); if (offset == 0) { writeBuffer = src; } else { // bulkTransfer does not support offsets, make a copy. Buffer.BlockCopy(src, offset, mWriteBuffer, 0, writeLength); writeBuffer = mWriteBuffer; } amtWritten = mConnection.BulkTransfer(endpoint, writeBuffer, writeLength, timeoutMillis); } if (amtWritten <= 0) { throw new IOException( "Error writing " + writeLength + " bytes at offset " + offset + " length=" + src.Length); } Log.Debug(TAG, "Wrote amtWritten=" + amtWritten + " attempted=" + writeLength); offset += amtWritten; } return(offset); }
//---------------------------------------------------------------------------------------- private void Clamp() { Vector3 pos = m_settings.Panning; pos.x = Math.Min(Math.Max(pos.x, m_settings.PanningMinZ), m_settings.PanningMaxZ); pos.z = Math.Min(Math.Max(pos.z, m_settings.PanningMinX), m_settings.PanningMaxX); pos.y = 0; m_settings.Panning = pos; }
public void Generate(Pawn mother = null, Pawn father = null) { if (!(parent is Pawn pawn)) { return; } if (!Genes.EffectsThing(parent)) { return; } _geneRecords = new Dictionary <StatDef, GeneRecord>(); if (mother == null) { mother = pawn.GetMother(); } if (father == null) { father = pawn.GetFather(); } var motherStats = mother?.AnimalGenetics().GeneRecords; var fatherStats = father?.AnimalGenetics().GeneRecords; var affectedStats = Constants.affectedStats; foreach (var stat in affectedStats) { float motherValue = motherStats != null ? motherStats[stat].Value : Mathf.Max(Verse.Rand.Gaussian(Settings.Core.mean, Settings.Core.stdDev), 0.1f); float fatherValue = fatherStats != null ? fatherStats[stat].Value : Mathf.Max(Verse.Rand.Gaussian(Settings.Core.mean, Settings.Core.stdDev), 0.1f); float highValue = Math.Max(motherValue, fatherValue); float lowValue = Math.Min(motherValue, fatherValue); float?ToNullableFloat(bool nullify, float value) => nullify ? null : (float?)value; var record = new GeneRecord(ToNullableFloat(mother == null, motherValue), ToNullableFloat(father == null, fatherValue)); record.ParentValue = Verse.Rand.Chance(Settings.Core.bestGeneChance) ? highValue : lowValue; if (record.ParentValue == motherValue) { record.Parent = motherStats != null ? GeneRecord.Source.Mother : GeneRecord.Source.None; } else { record.Parent = fatherStats != null ? GeneRecord.Source.Father : GeneRecord.Source.None; } record.Value = record.ParentValue + Verse.Rand.Gaussian(Settings.Core.mutationMean, Settings.Core.mutationStdDev); record.Value = Mathf.Max(record.Value, 0.1f); _geneRecords[stat] = record; } }
public static void MinBlend(OverworldCell[,] heightMap, Vector2 pos, float height, OverworldField type) { int x = Math.Max(Math.Min((int)pos.X, heightMap.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, heightMap.GetLength(1) - 1), 0); float orig = heightMap[x, y].GetValue(type); heightMap[x, y].SetValue(type, Math.Min(orig, height)); }
public static void MultValue(OverworldCell[,] heightMap, Vector2 pos, OverworldField value, float height) { DebugHelper.AssertNotNull(heightMap); int x = Math.Max(Math.Min((int)pos.X, heightMap.GetLength(0) - 1), 0); int y = Math.Max(Math.Min((int)pos.Y, heightMap.GetLength(1) - 1), 0); float c = heightMap[x, y].GetValue(value); heightMap[x, y].SetValue(value, c * height); }