Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reduce player species spawn rate and make on stage radius bigger #6001

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions simulation_parameters/Constants.cs
Original file line number Diff line number Diff line change
Expand Up @@ -102,6 +102,30 @@ public static class Constants

public const float MIN_DISTANCE_FROM_PLAYER_FOR_SPAWN = SPAWN_SECTOR_SIZE - 10;

/// <summary>
/// Used to reduce how commonly the player species spawns to make it more likely for the player to encounter
/// other species.
/// </summary>
public const float PLAYER_SPECIES_SPAWN_MULTIPLIER = 0.5f;

/// <summary>
/// Smaller spawn penalty to make binding agents easier to use with better player species spawn rates.
/// </summary>
public const float PLAYER_SPECIES_SPAWN_MULTIPLIER_BINDING_AGENTS = 0.7f;

/// <summary>
/// Cells farther than this are forced to move towards the player to get on screen to give better activity
/// from our limited entity count. Lower values let farther away cells to just chill without having to move.
/// </summary>
public const float ON_STAGE_THRESHOLD_AROUND_PLAYER = 0.71f;

/// <summary>
/// Sets much randomness is added on each axis (X and Z) for a cell's target to move to the player position to
/// get "on stage"
/// Larger values add more randomness to cells moving towards the player.
/// </summary>
public const float ON_STAGE_DESTINATION_RANDOMNESS = 20;

/// <summary>
/// Scale factor for density of compound cloud spawns
/// </summary>
Expand Down
29 changes: 26 additions & 3 deletions src/microbe_stage/PatchManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ public void OnPropertiesLoaded()
}

/// <summary>
/// Applies all patch related settings that are needed to be set. Like different spawners, despawning old
/// Applies all patch-related settings that are needed to be set. Like different spawners, despawning old
/// entities if the patch changed etc.
/// </summary>
/// <param name="currentPatch">The patch to apply settings from</param>
Expand Down Expand Up @@ -98,7 +98,7 @@ public bool ApplyChangedPatchSettingsIfNeeded(Patch currentPatch, IMicrobeSpawnE

GD.Print($"Applying patch ({currentPatch.Name}) settings");

// Update environment for process system
// Update environment for the process system
processSystem.SetBiome(currentPatch.Biome);

// Apply spawn system settings
Expand All @@ -112,7 +112,7 @@ public bool ApplyChangedPatchSettingsIfNeeded(Patch currentPatch, IMicrobeSpawnE
}

/// <summary>
/// Updates spawn system settings for current patch
/// Updates spawn system settings for the current patch
/// </summary>
public void UpdateSpawners(Patch currentPatch, IMicrobeSpawnEnvironment spawnEnvironment)
{
Expand Down Expand Up @@ -253,6 +253,29 @@ private void HandleCellSpawns(Patch patch, IMicrobeSpawnEnvironment spawnEnviron
var density = MathF.Max(MathF.Log(population / Constants.MICROBE_SPAWN_DENSITY_POPULATION_MULTIPLIER) *
Constants.MICROBE_SPAWN_DENSITY_SCALE_FACTOR, 0.0f);

if (entry.Key.PlayerSpecies)
{
// Adjust player species spawn rate as there have been too many complaints about the player just seeing
// their own species

// Except if the player is maybe looking for binding opportunities, then reduce the spawns much less
bool hasBinding = false;

if (entry.Key is MicrobeSpecies microbeSpecies)
{
hasBinding = microbeSpecies.Organelles.Any(o => o.Definition.HasBindingFeature);
}

if (hasBinding)
{
density *= Constants.PLAYER_SPECIES_SPAWN_MULTIPLIER_BINDING_AGENTS;
}
else
{
density *= Constants.PLAYER_SPECIES_SPAWN_MULTIPLIER;
}
}

var name = species.ID.ToString(CultureInfo.InvariantCulture);

HandleSpawnHelper(microbeSpawners, name, density,
Expand Down
17 changes: 14 additions & 3 deletions src/microbe_stage/systems/MicrobeAISystem.cs
Original file line number Diff line number Diff line change
Expand Up @@ -456,11 +456,22 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor
if (potentiallyKnownPlayerPosition != null)
{
// Only move if we aren't sessile
// The threshold is not too high so that not all cells are forced to move
if (position.Position.DistanceSquaredTo(potentiallyKnownPlayerPosition.Value) >
Math.Pow(Constants.SPAWN_SECTOR_SIZE, 2) * 0.75f &&
Math.Pow(Constants.SPAWN_SECTOR_SIZE, 2) * Constants.ON_STAGE_THRESHOLD_AROUND_PLAYER &&
!isSessile)
{
ai.MoveToLocation(potentiallyKnownPlayerPosition.Value, ref control, entity);
// And some randomness is added here so that each cell doesn't literally want to move to the exact
// same position
// TODO: this probably gets re-called for each cell quite often so this randomness may not be
// very efficient as the values will average out over multiple calls
var randomness =
new Vector3(random.NextSingle() * Constants.ON_STAGE_DESTINATION_RANDOMNESS -
Constants.ON_STAGE_DESTINATION_RANDOMNESS * 0.5f, 0,
random.NextSingle() * Constants.ON_STAGE_DESTINATION_RANDOMNESS -
Constants.ON_STAGE_DESTINATION_RANDOMNESS * 0.5f);

ai.MoveToLocation(potentiallyKnownPlayerPosition.Value + randomness, ref control, entity);
return;
}

Expand All @@ -470,7 +481,7 @@ private void ChooseActions(in Entity entity, ref MicrobeAI ai, ref CompoundAbsor

var isIronEater = organelles.IronBreakdownEfficiency > 0;

// Siderophore is experimental feature
// Siderophore is an experimental feature
if (!gameWorld!.WorldSettings.ExperimentalFeatures)
isIronEater = false;

Expand Down