public float GetPositionUpdateInterval(Client recipient) { if (!Enabled) { return(1000.0f); } if (recipient.Character == null || recipient.Character.IsDead) { return(0.2f); } else { float distance = Vector2.Distance(recipient.Character.WorldPosition, WorldPosition); float priority = 1.0f - MathUtils.InverseLerp( NetConfig.HighPrioCharacterPositionUpdateDistance, NetConfig.LowPrioCharacterPositionUpdateDistance, distance); float interval = MathHelper.Lerp( NetConfig.LowPrioCharacterPositionUpdateInterval, NetConfig.HighPrioCharacterPositionUpdateInterval, priority); if (IsDead) { interval = Math.Max(interval * 2, 0.1f); } return(interval); } }
public Color GetDifficultyColor() { int v = Difficulty ?? MissionPrefab.MinDifficulty; float t = MathUtils.InverseLerp(MissionPrefab.MinDifficulty, MissionPrefab.MaxDifficulty, v); return(ToolBox.GradientLerp(t, GUI.Style.Green, GUI.Style.Orange, GUI.Style.Red)); }
public override float GetPriority() { if (!IsAllowed) { Priority = 0; return(Priority); } if (targetCharacter == null || targetCharacter.CurrentHull == null || targetCharacter.Removed || targetCharacter.IsDead) { Priority = 0; } else { // Vertical distance matters more than horizontal (climbing up/down is harder than moving horizontally) float dist = Math.Abs(character.WorldPosition.X - targetCharacter.WorldPosition.X) + Math.Abs(character.WorldPosition.Y - targetCharacter.WorldPosition.Y) * 2.0f; float distanceFactor = MathHelper.Lerp(1, 0.1f, MathUtils.InverseLerp(0, 5000, dist)); if (targetCharacter.CurrentHull == character.CurrentHull) { distanceFactor = 1; } float vitalityFactor = 1 - AIObjectiveRescueAll.GetVitalityFactor(targetCharacter) / 100; float devotion = CumulatedDevotion / 100; Priority = MathHelper.Lerp(0, 100, MathHelper.Clamp(devotion + (vitalityFactor * distanceFactor * PriorityModifier), 0, 1)); } return(Priority); }
public float GetPositionUpdateInterval(Client recipient) { if (!Enabled) { return(1000.0f); } Vector2 comparePosition = recipient.SpectatePos == null ? recipient.Character.WorldPosition : recipient.SpectatePos.Value; float distance = Vector2.Distance(comparePosition, WorldPosition); float priority = 1.0f - MathUtils.InverseLerp( NetConfig.HighPrioCharacterPositionUpdateDistance, NetConfig.LowPrioCharacterPositionUpdateDistance, distance); float interval = MathHelper.Lerp( NetConfig.LowPrioCharacterPositionUpdateInterval, NetConfig.HighPrioCharacterPositionUpdateInterval, priority); if (IsDead) { interval = Math.Max(interval * 2, 0.1f); } return(interval); }
public override float GetPriority() { if (!IsAllowed) { Priority = 0; Abandon = true; return(Priority); } // TODO: priority list? // Ignore items that are being repaired by someone else. if (Item.Repairables.Any(r => r.CurrentFixer != null && r.CurrentFixer != character)) { Priority = 0; } else { float distanceFactor = 1; if (!isPriority && Item.CurrentHull != character.CurrentHull) { float yDist = Math.Abs(character.WorldPosition.Y - Item.WorldPosition.Y); yDist = yDist > 100 ? yDist * 5 : 0; float dist = Math.Abs(character.WorldPosition.X - Item.WorldPosition.X) + yDist; distanceFactor = MathHelper.Lerp(1, 0.25f, MathUtils.InverseLerp(0, 4000, dist)); } float requiredSuccessFactor = objectiveManager.IsCurrentOrder <AIObjectiveRepairItems>() ? 0 : AIObjectiveRepairItems.RequiredSuccessFactor; float severity = isPriority ? 1 : AIObjectiveRepairItems.GetTargetPriority(Item, character, requiredSuccessFactor) / 100; bool isSelected = IsRepairing(); float selectedBonus = isSelected ? 100 - MaxDevotion : 0; float devotion = (CumulatedDevotion + selectedBonus) / 100; float reduction = isPriority ? 1 : isSelected ? 2 : 3; float max = MathHelper.Min(AIObjectiveManager.OrderPriority - reduction, 90); Priority = MathHelper.Lerp(0, max, MathHelper.Clamp(devotion + (severity * distanceFactor * PriorityModifier), 0, 1)); } return(Priority); }
/// <summary> /// Instantiates level data using the properties of the connection (seed, size, difficulty) /// </summary> public LevelData(LocationConnection locationConnection) { Seed = locationConnection.Locations[0].BaseName + locationConnection.Locations[1].BaseName; Biome = locationConnection.Biome; Type = LevelType.LocationConnection; GenerationParams = LevelGenerationParams.GetRandom(Seed, LevelType.LocationConnection, Biome); Difficulty = locationConnection.Difficulty; float sizeFactor = MathUtils.InverseLerp( MapGenerationParams.Instance.SmallLevelConnectionLength, MapGenerationParams.Instance.LargeLevelConnectionLength, locationConnection.Length); int width = (int)MathHelper.Lerp(GenerationParams.MinWidth, GenerationParams.MaxWidth, sizeFactor); Size = new Point( (int)MathUtils.Round(width, Level.GridCellSize), (int)MathUtils.Round(GenerationParams.Height, Level.GridCellSize)); var rand = new MTRandom(ToolBox.StringToInt(Seed)); InitialDepth = (int)MathHelper.Lerp(GenerationParams.InitialDepthMin, GenerationParams.InitialDepthMax, (float)rand.NextDouble()); HasBeaconStation = rand.NextDouble() < locationConnection.Locations.Select(l => l.Type.BeaconStationChance).Max(); IsBeaconActive = false; }
public override float GetPriority() { // TODO: priority list? // Ignore items that are being repaired by someone else. if (Item.Repairables.Any(r => r.CurrentFixer != null && r.CurrentFixer != character)) { return(0); } float yDist = Math.Abs(character.WorldPosition.Y - Item.WorldPosition.Y); yDist = yDist > 100 ? yDist * 5 : 0; float dist = Math.Abs(character.WorldPosition.X - Item.WorldPosition.X) + yDist; float distanceFactor = MathHelper.Lerp(1, 0.25f, MathUtils.InverseLerp(0, 5000, dist)); if (Item.CurrentHull == character.CurrentHull) { distanceFactor = 1; } float damagePriority = MathHelper.Lerp(1, 0, Item.Condition / Item.MaxCondition); float successFactor = MathHelper.Lerp(0, 1, Item.Repairables.Average(r => r.DegreeOfSuccess(character))); float isSelected = IsRepairing ? 50 : 0; float devotion = (Math.Min(Priority, 10) + isSelected) / 100; float max = MathHelper.Min(AIObjectiveManager.OrderPriority - 1, 90); return(MathHelper.Lerp(0, max, MathHelper.Clamp(devotion + damagePriority * distanceFactor * successFactor * PriorityModifier, 0, 1))); }
public override float GetPriority() { if (!IsAllowed) { Priority = 0; return(Priority); } if (!objectiveManager.IsCurrentOrder <AIObjectiveExtinguishFires>() && Character.CharacterList.Any(c => c.CurrentHull == targetHull && !HumanAIController.IsFriendly(c) && HumanAIController.IsActive(c))) { Priority = 0; } else { float yDist = Math.Abs(character.WorldPosition.Y - targetHull.WorldPosition.Y); yDist = yDist > 100 ? yDist * 3 : 0; float dist = Math.Abs(character.WorldPosition.X - targetHull.WorldPosition.X) + yDist; float distanceFactor = MathHelper.Lerp(1, 0.1f, MathUtils.InverseLerp(0, 5000, dist)); if (targetHull == character.CurrentHull) { distanceFactor = 1; } float severity = AIObjectiveExtinguishFires.GetFireSeverity(targetHull); float severityFactor = MathHelper.Lerp(0, 1, severity / 100); float devotion = CumulatedDevotion / 100; Priority = MathHelper.Lerp(0, 100, MathHelper.Clamp(devotion + (severityFactor * distanceFactor * PriorityModifier), 0, 1)); } return(Priority); }
public override float GetPriority() { if (targetCharacter == null) { return(0); } if (targetCharacter.CurrentHull == null || targetCharacter.Removed || targetCharacter.IsDead) { abandon = true; return(0); } // Don't go into rooms that have enemies if (Character.CharacterList.Any(c => c.CurrentHull == targetCharacter.CurrentHull && !HumanAIController.IsFriendly(c))) { abandon = true; return(0); } // Vertical distance matters more than horizontal (climbing up/down is harder than moving horizontally) float dist = Math.Abs(character.WorldPosition.X - targetCharacter.WorldPosition.X) + Math.Abs(character.WorldPosition.Y - targetCharacter.WorldPosition.Y) * 2.0f; float distanceFactor = MathHelper.Lerp(1, 0.5f, MathUtils.InverseLerp(0, 10000, dist)); float vitalityFactor = AIObjectiveRescueAll.GetVitalityFactor(targetCharacter); float devotion = Math.Min(Priority, 10) / 100; return(MathHelper.Lerp(0, 100, MathHelper.Clamp(devotion + vitalityFactor * distanceFactor, 0, 1))); }
public void ServerWrite(IWriteMessage message, Client c, object[] extraData = null) { message.WriteRangedSingle(MathHelper.Clamp(waterVolume / Volume, 0.0f, 1.5f), 0.0f, 1.5f, 8); message.WriteRangedSingle(MathHelper.Clamp(OxygenPercentage, 0.0f, 100.0f), 0.0f, 100.0f, 8); message.Write(FireSources.Count > 0); if (FireSources.Count > 0) { message.WriteRangedInteger(Math.Min(FireSources.Count, 16), 0, 16); for (int i = 0; i < Math.Min(FireSources.Count, 16); i++) { var fireSource = FireSources[i]; Vector2 normalizedPos = new Vector2( (fireSource.Position.X - rect.X) / rect.Width, (fireSource.Position.Y - (rect.Y - rect.Height)) / rect.Height); message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.X, 0.0f, 1.0f), 0.0f, 1.0f, 8); message.WriteRangedSingle(MathHelper.Clamp(normalizedPos.Y, 0.0f, 1.0f), 0.0f, 1.0f, 8); message.WriteRangedSingle(MathHelper.Clamp(fireSource.Size.X / rect.Width, 0.0f, 1.0f), 0, 1.0f, 8); } } message.Write(extraData != null); if (extraData != null) { message.Write((bool)extraData[0]); // Section update if ((bool)extraData[0]) { int sectorToUpdate = (int)extraData[1]; int start = sectorToUpdate * BackgroundSectionsPerNetworkEvent; int end = Math.Min((sectorToUpdate + 1) * BackgroundSectionsPerNetworkEvent, BackgroundSections.Count - 1); message.WriteRangedInteger(sectorToUpdate, 0, BackgroundSections.Count - 1); for (int i = start; i < end; i++) { message.WriteRangedSingle(BackgroundSections[i].ColorStrength, 0.0f, 1.0f, 8); message.Write(BackgroundSections[i].Color.PackedValue); } } else // Decal update { message.WriteRangedInteger(decals.Count, 0, MaxDecalsPerHull); foreach (Decal decal in decals) { message.Write(decal.Prefab.UIntIdentifier); message.Write((byte)decal.SpriteIndex); float normalizedXPos = MathHelper.Clamp(MathUtils.InverseLerp(0.0f, rect.Width, decal.CenterPosition.X), 0.0f, 1.0f); float normalizedYPos = MathHelper.Clamp(MathUtils.InverseLerp(-rect.Height, 0.0f, decal.CenterPosition.Y), 0.0f, 1.0f); message.WriteRangedSingle(normalizedXPos, 0.0f, 1.0f, 8); message.WriteRangedSingle(normalizedYPos, 0.0f, 1.0f, 8); message.WriteRangedSingle(decal.Scale, 0f, 2f, 12); } } } }
private int CalculateCellCount(int minValue, int maxValue) { if (maxValue == 0) { return(0); } float t = MathUtils.InverseLerp(0, 100, Level.Loaded.Difficulty * Config.AgentSpawnCountDifficultyMultiplier); return((int)Math.Round(MathHelper.Lerp(minValue, maxValue, t))); }
private float GetSpawnTime() { float randomFactor = Config.AgentSpawnDelayRandomFactor; float delay = Config.AgentSpawnDelay; float min = delay; float max = delay * 6; float t = Level.Loaded.Difficulty * Config.AgentSpawnDelayDifficultyMultiplier * Rand.Range(1 - randomFactor, 1 + randomFactor); return(MathHelper.Lerp(max, min, MathUtils.InverseLerp(0, 100, t))); }
public void UpdateDeformations(float deltaTime) { float diff = Math.Abs(UpperLimit - LowerLimit); float strength = MathHelper.Lerp(0, 1, MathUtils.InverseLerp(0, MathHelper.Pi, diff)); float jointAngle = JointAngle * strength; JointBendDeformation limbADeformation = LimbA.Deformations.Find(d => d is JointBendDeformation) as JointBendDeformation; JointBendDeformation limbBDeformation = LimbB.Deformations.Find(d => d is JointBendDeformation) as JointBendDeformation; if (limbADeformation != null && limbBDeformation != null) { UpdateBend(LimbA, limbADeformation, this.LocalAnchorA, -jointAngle); UpdateBend(LimbB, limbBDeformation, this.LocalAnchorB, jointAngle); } void UpdateBend(Limb limb, JointBendDeformation deformation, Vector2 localAnchor, float angle) { deformation.Scale = limb.DeformSprite.Size; Vector2 displayAnchor = ConvertUnits.ToDisplayUnits(localAnchor); displayAnchor.Y = -displayAnchor.Y; Vector2 refPos = displayAnchor + limb.DeformSprite.Origin; refPos.X /= limb.DeformSprite.Size.X; refPos.Y /= limb.DeformSprite.Size.Y; if (Math.Abs(localAnchor.X) > Math.Abs(localAnchor.Y)) { if (localAnchor.X > 0.0f) { deformation.BendRightRefPos = refPos; deformation.BendRight = angle; } else { deformation.BendLeftRefPos = refPos; deformation.BendLeft = angle; } } else { if (localAnchor.Y > 0.0f) { deformation.BendUpRefPos = refPos; deformation.BendUp = angle; } else { deformation.BendDownRefPos = refPos; deformation.BendDown = angle; } } } }
/// <summary> /// Calculates one percent between the range as the increment/decrement. /// This value is rounded so that the bigger it is, the less decimals are used (min 0, max 3). /// Return value is clamped between 0.1f and 1000. /// </summary> private float Round() { if (!maxValueFloat.HasValue || !minValueFloat.HasValue) { return(0); } float onePercent = MathHelper.Lerp(minValueFloat.Value, maxValueFloat.Value, 0.01f); float diff = maxValueFloat.Value - minValueFloat.Value; int decimals = (int)MathHelper.Lerp(3, 0, MathUtils.InverseLerp(10, 1000, diff)); return(MathHelper.Clamp((float)Math.Round(onePercent, decimals), 0.1f, 1000)); }
public override float GetPriority(AIObjectiveManager objectiveManager) { if (gotoObjective != null && !gotoObjective.CanBeCompleted) { return(0); } // Vertical distance matters more than horizontal (climbing up/down is harder than moving horizontally) float dist = Math.Abs(character.WorldPosition.X - targetHull.WorldPosition.X) + Math.Abs(character.WorldPosition.Y - targetHull.WorldPosition.Y) * 2.0f; float distanceFactor = MathHelper.Lerp(1, 0.1f, MathUtils.InverseLerp(0, 10000, dist)); float severityFactor = MathHelper.Lerp(0, 1, MathHelper.Clamp(targetHull.FireSources.Sum(fs => fs.Size.X) / targetHull.Size.X, 0, 1)); return(MathHelper.Clamp(Priority * severityFactor * distanceFactor, 0, 100)); }
/// <summary> /// Scrolls the list to the specific element, currently only works when smooth scrolling and PadBottom are enabled. /// </summary> /// <param name="component"></param> public void ScrollToElement(GUIComponent component) { GUI.PlayUISound(GUISoundType.Click); List <GUIComponent> children = Content.Children.ToList(); int index = children.IndexOf(component); if (index < 0) { return; } targetScroll = MathHelper.Clamp(MathHelper.Lerp(0, 1, MathUtils.InverseLerp(0, (children.Count - 0.9f), index)), ScrollBar.MinValue, ScrollBar.MaxValue); }
protected override float GetPriority() { if (!IsAllowed || Item.IgnoreByAI(character)) { Priority = 0; Abandon = true; if (IsRepairing()) { Item.Repairables.ForEach(r => r.StopRepairing(character)); } return(Priority); } if (HumanAIController.IsItemRepairedByAnother(Item, out _)) { Priority = 0; IsCompleted = true; } else { float distanceFactor = 1; if (!isPriority && Item.CurrentHull != character.CurrentHull) { float yDist = Math.Abs(character.WorldPosition.Y - Item.WorldPosition.Y); yDist = yDist > 100 ? yDist * 5 : 0; float dist = Math.Abs(character.WorldPosition.X - Item.WorldPosition.X) + yDist; distanceFactor = MathHelper.Lerp(1, 0.25f, MathUtils.InverseLerp(0, 4000, dist)); } float requiredSuccessFactor = objectiveManager.HasOrder <AIObjectiveRepairItems>() ? 0 : AIObjectiveRepairItems.RequiredSuccessFactor; float severity = isPriority ? 1 : AIObjectiveRepairItems.GetTargetPriority(Item, character, requiredSuccessFactor) / 100; bool isSelected = IsRepairing(); float selectedBonus = isSelected ? 100 - MaxDevotion : 0; float devotion = (CumulatedDevotion + selectedBonus) / 100; float reduction = isPriority ? 1 : isSelected ? 2 : 3; float max = AIObjectiveManager.LowestOrderPriority - reduction; float highestWeight = -1; foreach (string tag in Item.Prefab.Tags) { if (JobPrefab.ItemRepairPriorities.TryGetValue(tag, out float weight) && weight > highestWeight) { highestWeight = weight; } } if (highestWeight == -1) { // Predefined weight not found. highestWeight = 1; } Priority = MathHelper.Lerp(0, max, MathHelper.Clamp(devotion + (severity * distanceFactor * highestWeight * PriorityModifier), 0, 1)); } return(Priority); }
private void FindTargetHulls() { bool isCurrentHullOK = !HumanAIController.UnsafeHulls.Contains(character.CurrentHull) && !IsForbidden(character.CurrentHull); targetHulls.Clear(); hullWeights.Clear(); foreach (var hull in Hull.hullList) { if (HumanAIController.UnsafeHulls.Contains(hull)) { continue; } if (hull.Submarine == null) { continue; } if (hull.Submarine.TeamID != character.TeamID) { continue; } // If the character is inside, only take connected hulls into account. if (character.Submarine != null && !character.Submarine.IsEntityFoundOnThisSub(hull, true)) { continue; } if (IsForbidden(hull)) { continue; } // Ignore hulls that are too low to stand inside if (character.AnimController is HumanoidAnimController animController) { if (hull.CeilingHeight < ConvertUnits.ToDisplayUnits(animController.HeadPosition.Value)) { continue; } } if (!targetHulls.Contains(hull)) { targetHulls.Add(hull); float weight = hull.Volume; // Prefer rooms that are closer. Avoid rooms that are not in the same level. float dist = Math.Abs(character.WorldPosition.X - hull.WorldPosition.X) + Math.Abs(character.WorldPosition.Y - hull.WorldPosition.Y) * 5.0f; float distanceFactor = MathHelper.Lerp(1, 0.1f, MathUtils.InverseLerp(0, 2500, dist)); weight *= distanceFactor; hullWeights.Add(weight); } } }
private void UpdateMapAnim(MapAnim anim, float deltaTime) { //pause animation while there are messageboxes on screen if (GUIMessageBox.MessageBoxes.Count > 0) { return; } if (!string.IsNullOrEmpty(anim.StartMessage)) { new GUIMessageBox("", anim.StartMessage); anim.StartMessage = null; return; } if (anim.StartZoom == null) { anim.StartZoom = MathUtils.InverseLerp(generationParams.MinZoom, generationParams.MaxZoom, zoom); } if (anim.EndZoom == null) { anim.EndZoom = MathUtils.InverseLerp(generationParams.MinZoom, generationParams.MaxZoom, zoom); } anim.StartPos = (anim.StartLocation == null) ? -DrawOffset : anim.StartLocation.MapPosition; anim.Timer = Math.Min(anim.Timer + deltaTime, anim.Duration); float t = anim.Duration <= 0.0f ? 1.0f : Math.Max(anim.Timer / anim.Duration, 0.0f); DrawOffset = -Vector2.SmoothStep(anim.StartPos.Value, anim.EndLocation.MapPosition, t); DrawOffset += new Vector2( (float)PerlinNoise.CalculatePerlin(Timing.TotalTime * 0.3f % 255, Timing.TotalTime * 0.4f % 255, 0) - 0.5f, (float)PerlinNoise.CalculatePerlin(Timing.TotalTime * 0.4f % 255, Timing.TotalTime * 0.3f % 255, 0.5f) - 0.5f) * 50.0f * (float)Math.Sin(t * MathHelper.Pi); zoom = MathHelper.Lerp(generationParams.MinZoom, generationParams.MaxZoom, MathHelper.SmoothStep(anim.StartZoom.Value, anim.EndZoom.Value, t)); if (anim.Timer >= anim.Duration) { if (!string.IsNullOrEmpty(anim.EndMessage)) { new GUIMessageBox("", anim.EndMessage); anim.EndMessage = null; return; } anim.Finished = true; } }
public override float GetPriority() { if (character.TeamID == CharacterTeamType.FriendlyNPC && Enemy != null) { if (Enemy.Submarine == null || (Enemy.Submarine.TeamID != character.TeamID && Enemy.Submarine != character.Submarine)) { Priority = 0; Abandon = true; return Priority; } } float damageFactor = MathUtils.InverseLerp(0.0f, 5.0f, HumanAIController.GetDamageDoneByAttacker(Enemy) / 100.0f); Priority = TargetEliminated ? 0 : Math.Min((95 + damageFactor) * PriorityModifier, 100); return Priority; }
public override float GetPriority() { if (Leak.Open == 0.0f) { return(0.0f); } // Vertical distance matters more than horizontal (climbing up/down is harder than moving horizontally) float dist = Math.Abs(character.WorldPosition.X - Leak.WorldPosition.X) + Math.Abs(character.WorldPosition.Y - Leak.WorldPosition.Y) * 2.0f; float distanceFactor = MathHelper.Lerp(1, 0.25f, MathUtils.InverseLerp(0, 10000, dist)); float severity = AIObjectiveFixLeaks.GetLeakSeverity(Leak); float max = Math.Min((AIObjectiveManager.OrderPriority - 1), 90); float devotion = Math.Min(Priority, 10) / 100; return(MathHelper.Lerp(0, max, MathHelper.Clamp(devotion + severity * distanceFactor * PriorityModifier, 0, 1))); }
public override float GetPriority() { if (Character.CharacterList.Any(c => c.CurrentHull == targetHull && !HumanAIController.IsFriendly(c))) { return(0); } // Vertical distance matters more than horizontal (climbing up/down is harder than moving horizontally) float dist = Math.Abs(character.WorldPosition.X - targetHull.WorldPosition.X) + Math.Abs(character.WorldPosition.Y - targetHull.WorldPosition.Y) * 2.0f; float distanceFactor = MathHelper.Lerp(1, 0.1f, MathUtils.InverseLerp(0, 10000, dist)); float severity = AIObjectiveExtinguishFires.GetFireSeverity(targetHull); float severityFactor = MathHelper.Lerp(0, 1, severity / 100); float devotion = Math.Min(Priority, 10) / 100; return(MathHelper.Lerp(0, 100, MathHelper.Clamp(devotion + severityFactor * distanceFactor, 0, 1))); }
protected override float GetPriority() { if (!IsAllowed) { Priority = 0; Abandon = true; return(Priority); } bool isOrder = objectiveManager.HasOrder <AIObjectiveExtinguishFires>(); if (!isOrder && Character.CharacterList.Any(c => c.CurrentHull == targetHull && !HumanAIController.IsFriendly(c) && HumanAIController.IsActive(c))) { // Don't go into rooms with any enemies, unless it's an order Priority = 0; Abandon = true; } else { float yDist = Math.Abs(character.WorldPosition.Y - targetHull.WorldPosition.Y); yDist = yDist > 100 ? yDist * 3 : 0; float dist = Math.Abs(character.WorldPosition.X - targetHull.WorldPosition.X) + yDist; float distanceFactor = MathHelper.Lerp(1, 0.1f, MathUtils.InverseLerp(0, 5000, dist)); if (targetHull == character.CurrentHull || HumanAIController.VisibleHulls.Contains(targetHull)) { distanceFactor = 1; } float severity = AIObjectiveExtinguishFires.GetFireSeverity(targetHull); if (severity > 0.75f && !isOrder && targetHull.RoomName != null && !targetHull.RoomName.Contains("reactor", StringComparison.OrdinalIgnoreCase) && !targetHull.RoomName.Contains("engine", StringComparison.OrdinalIgnoreCase) && !targetHull.RoomName.Contains("command", StringComparison.OrdinalIgnoreCase)) { // Ignore severe fires to prevent casualities unless ordered to extinguish. Priority = 0; Abandon = true; } else { float devotion = CumulatedDevotion / 100; Priority = MathHelper.Lerp(0, 100, MathHelper.Clamp(devotion + (severity * distanceFactor * PriorityModifier), 0, 1)); } } return(Priority); }
/// <summary> /// Instantiates level data using the properties of the connection (seed, size, difficulty) /// </summary> public LevelData(LocationConnection locationConnection) { Seed = locationConnection.Locations[0].BaseName + locationConnection.Locations[1].BaseName; Biome = locationConnection.Biome; Type = LevelType.LocationConnection; GenerationParams = LevelGenerationParams.GetRandom(Seed, LevelType.LocationConnection, Biome); Difficulty = locationConnection.Difficulty; float sizeFactor = MathUtils.InverseLerp( MapGenerationParams.Instance.SmallLevelConnectionLength, MapGenerationParams.Instance.LargeLevelConnectionLength, locationConnection.Length); int width = (int)MathHelper.Lerp(GenerationParams.MinWidth, GenerationParams.MaxWidth, sizeFactor); Size = new Point( (int)MathUtils.Round(width, Level.GridCellSize), (int)MathUtils.Round(GenerationParams.Height, Level.GridCellSize)); }
public override float GetPriority() { if (targetCharacter == null || targetCharacter.CurrentHull == null || targetCharacter.Removed || targetCharacter.IsDead) { return(0); } // Vertical distance matters more than horizontal (climbing up/down is harder than moving horizontally) float dist = Math.Abs(character.WorldPosition.X - targetCharacter.WorldPosition.X) + Math.Abs(character.WorldPosition.Y - targetCharacter.WorldPosition.Y) * 2.0f; float distanceFactor = MathHelper.Lerp(1, 0.1f, MathUtils.InverseLerp(0, 5000, dist)); if (targetCharacter.CurrentHull == character.CurrentHull) { distanceFactor = 1; } float vitalityFactor = AIObjectiveRescueAll.GetVitalityFactor(targetCharacter); float devotion = Math.Min(Priority, 10) / 100; return(MathHelper.Lerp(0, 100, MathHelper.Clamp(devotion + vitalityFactor * distanceFactor, 0, 1))); }
public override float GetPriority() { // TODO: priority list? // Ignore items that are being repaired by someone else. if (Item.Repairables.Any(r => r.CurrentFixer != null && r.CurrentFixer != character)) { return(0); } // Vertical distance matters more than horizontal (climbing up/down is harder than moving horizontally) float dist = Math.Abs(character.WorldPosition.X - Item.WorldPosition.X) + Math.Abs(character.WorldPosition.Y - Item.WorldPosition.Y) * 2.0f; float distanceFactor = MathHelper.Lerp(1, 0.5f, MathUtils.InverseLerp(0, 10000, dist)); float damagePriority = MathHelper.Lerp(1, 0, Item.Condition / Item.MaxCondition); float successFactor = MathHelper.Lerp(0, 1, Item.Repairables.Average(r => r.DegreeOfSuccess(character))); float isSelected = character.SelectedConstruction == Item ? 50 : 0; float devotion = (Math.Min(Priority, 10) + isSelected) / 100; float max = MathHelper.Min(AIObjectiveManager.OrderPriority - 1, 90); return(MathHelper.Lerp(0, max, MathHelper.Clamp(devotion + damagePriority * distanceFactor * successFactor * PriorityModifier, 0, 1))); }
public static float GetLeakSeverity(Gap leak) { if (leak == null) { return(0); } float sizeFactor = MathHelper.Lerp(1, 10, MathUtils.InverseLerp(0, 200, (leak.IsHorizontal ? leak.Rect.Width : leak.Rect.Height))); float severity = sizeFactor * leak.Open; if (!leak.IsRoomToRoom) { severity *= 100; // If there is a leak in the outer walls, the severity cannot be lower than 10, no matter how small the leak return(MathHelper.Clamp(severity, 10, 100)); } else { return(MathHelper.Min(severity, 100)); } }
public override float GetPriority() { if (!IsAllowed) { Priority = 0; Abandon = true; return(Priority); } bool isOrder = objectiveManager.HasOrder <AIObjectiveExtinguishFires>(); if (!isOrder && Character.CharacterList.Any(c => c.CurrentHull == targetHull && !HumanAIController.IsFriendly(c) && HumanAIController.IsActive(c))) { // Don't go into rooms with any enemies, unless it's an order Priority = 0; Abandon = true; } else { float yDist = Math.Abs(character.WorldPosition.Y - targetHull.WorldPosition.Y); yDist = yDist > 100 ? yDist * 3 : 0; float dist = Math.Abs(character.WorldPosition.X - targetHull.WorldPosition.X) + yDist; float distanceFactor = MathHelper.Lerp(1, 0.1f, MathUtils.InverseLerp(0, 5000, dist)); if (targetHull == character.CurrentHull || HumanAIController.VisibleHulls.Contains(targetHull)) { distanceFactor = 1; } float severity = AIObjectiveExtinguishFires.GetFireSeverity(targetHull); if (severity > 0.5f && !isOrder) { // Ignore severe fires unless ordered. (Let the fire drain all the oxygen instead). Priority = 0; Abandon = true; } else { float devotion = CumulatedDevotion / 100; Priority = MathHelper.Lerp(0, 100, MathHelper.Clamp(devotion + (severity * distanceFactor * PriorityModifier), 0, 1)); } } return(Priority); }
public float GetOrderPriority(AIObjective objective) { if (objective == ForcedOrder) { return(HighestOrderPriority); } var currentOrder = CurrentOrders.FirstOrDefault(o => o.Objective == objective); if (currentOrder.Objective == null) { return(HighestOrderPriority); } else if (currentOrder.ManualPriority > 0) { return(MathHelper.Lerp(LowestOrderPriority, HighestOrderPriority, MathUtils.InverseLerp(1, CharacterInfo.HighestManualOrderPriority, currentOrder.ManualPriority))); } #if DEBUG DebugConsole.AddWarning("Error in order priority: shouldn't return 0!"); #endif return(0); }
private void UpdateScrollBar(GUIListBox listBox) { var sb = listBox.ScrollBar; sb.BarScroll = MathHelper.Clamp(MathHelper.Lerp(0, 1, MathUtils.InverseLerp(0, listBox.Content.CountChildren - 1, listBox.SelectedIndex)), sb.MinValue, sb.MaxValue); }