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

Exobiology improvements #70

Draft
wants to merge 63 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
63 commits
Select commit Hold shift + click to select a range
36bbec3
🏷️ Add `is_landable` to `TargetPlanet`
Somfic May 26, 2024
1fdfb53
🐛 Add check for landable planet
Somfic May 26, 2024
a6a690d
♻️ Remove unneeded reference
Somfic May 26, 2024
24535f2
🐛 Add check for landable planet
Somfic May 26, 2024
34eb7b7
✅ Fix exo tests not comparing against spawned species
Somfic May 27, 2024
582b5db
Discard changes to src/modules/exobiology/models/spawn_source.rs
Somfic May 27, 2024
e081b20
♻️ Add meters to `LocalDistance`
Somfic May 27, 2024
1aa51a0
♻️ Use `LocalDistance` for `semi_major_axis`
Somfic May 27, 2024
5f5f834
♻️ Use `LocalDistance` for `semi_major_axis`
Somfic May 27, 2024
8106699
💡 Add FIXME for unimplemented `geological_signals_present`
Somfic May 27, 2024
6ae017b
🏷️ Derive `Eq` and `PartialEq` for `WillSpawn`
Somfic May 27, 2024
024f8c3
✅ Remove tests for lightyears in `LocalDistance`
Somfic May 27, 2024
5f26367
🐛 Fix `MinDistanceFromParentSun` condition
Somfic May 27, 2024
b6f4f19
✅ Update spawnable species tests
Somfic May 27, 2024
442482a
♻️ Add back `is_landable` check
Somfic May 27, 2024
215c39d
✅ Add rare edge-cases to ignore list
Somfic May 27, 2024
8b3aad5
🐛 Do not filter on `WillSpawn`
Somfic May 27, 2024
06753fc
🎨 Reformatted `planet_state`
Somfic May 27, 2024
2b234ca
✅ Add blacklisted species
Somfic May 27, 2024
601bbb4
✨ Track `pressure` on `TargetPlanet`
Somfic May 27, 2024
ea517df
✨ Implement `MinPressure` condition
Somfic May 27, 2024
89de5fe
🩹 Fix trailing whitespace after species `Display` implementation
Somfic May 27, 2024
400847a
✨ Implement `MaxPressure` condition
Somfic May 27, 2024
01e6d8d
♻️ Add `all` and `any` macros to spawn conditions
Somfic May 27, 2024
1d8df71
🩹 Improve Aleoida conditions
Somfic May 27, 2024
f59ee7e
✨ Add `MainStarClass` condition
Somfic May 27, 2024
3ac7be4
✨ Add `from_pos` to `Region` enum
Somfic May 27, 2024
8f69176
🩹 Improve Anemone conditions
Somfic May 27, 2024
4d276b4
✅ Print table as test output
Somfic May 27, 2024
3162e94
🩹 Make code compile
Somfic May 27, 2024
0eea1bc
🚧 "work"
rster2002 Jun 17, 2024
d7e2faf
🚧 Continue seeing if test would yield usable results
rster2002 Jun 19, 2024
ba08a3d
✨ Add functions for expected species
rster2002 Jun 19, 2024
e5d1eca
👔 Add some of the missing species values
rster2002 Jun 20, 2024
9eb13d8
👔 Some changes to spawn conditions based on EDSM data
rster2002 Jun 20, 2024
60917a8
🔀 Merge branch 'exobiology-improvements' of https://github.com/rster2…
rster2002 Jun 20, 2024
369d55f
👔 More specific spawn conditions
rster2002 Jun 20, 2024
f397754
🍱 Add more journal files
rster2002 Jun 20, 2024
750bfe0
🔀 Merge branch 'master' into exobiology-improvements
rster2002 Jun 21, 2024
a1632c2
✅ Fix test issues
rster2002 Jun 22, 2024
ad932cf
🧪 Start working on adding specific test scenarios
rster2002 Jun 22, 2024
3e6a1ec
🧪 Add failing test for species predictions
rster2002 Jun 23, 2024
b1426d0
🚧 Continue working on exobiology tests
rster2002 Jun 25, 2024
2d000ff
🚧 Continue working on species spawn conditions
rster2002 Jun 26, 2024
2f2a188
🚧 Continue working on species spawn conditions
rster2002 Jun 27, 2024
22a0509
♻️ Don't ask
rster2002 Jun 27, 2024
02fc8fe
🚧 Continue working on spawn conditions
rster2002 Jun 27, 2024
6db9fce
🚧 Continue working
rster2002 Jun 29, 2024
84eef2a
🚧 Continue working on spawn conditions
rster2002 Jun 30, 2024
a424ed4
🚧 Continue refining spawn conditions
rster2002 Jul 3, 2024
99572f5
🚧 Further refine some spawn conditions
rster2002 Jul 3, 2024
987aafa
🚧 Continue refining spawn conditions
rster2002 Jul 4, 2024
330f917
🚧 Continue refining spawn conditions
rster2002 Jul 6, 2024
2cd7c4f
🧪 Add failing spawn condition tests
rster2002 Jul 27, 2024
5514d9a
🚧 Start working through failing tests
rster2002 Jul 29, 2024
99d3027
🚧 Start tweaking Bacterium Tela spawn conditions
rster2002 Aug 2, 2024
0a77863
🚧 Finish tweaking Bacterium Tela spawn conditions
rster2002 Aug 2, 2024
1992d92
🚧 Tweak Bacterium Verrata spawn conditions
rster2002 Aug 3, 2024
1a7f7eb
🚧 Continue working through test cases
rster2002 Aug 3, 2024
6b93ae6
Merge branch 'refs/heads/master' into exobiology-improvements
rster2002 Aug 15, 2024
d8e6a43
🐛 Compilation fixes after merge
rster2002 Aug 15, 2024
8bd9794
♻️ Run clippy --fix and manual fixes
rster2002 Aug 15, 2024
18e15db
🎨 Run cargo fmt
rster2002 Aug 15, 2024
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
22 changes: 22 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ directories = "5.0.1"

[dev-dependencies]
tokio-test = "0.4.4"
csv = "1.3.0"

[features]
default = ["asynchronous", "strict"]
Expand Down
2 changes: 0 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -70,14 +70,12 @@ mod tests {
let mut entry_count = 0;

for journal in &logs {
let mut found_file_header = false;
let reader = journal.create_blocking_reader().unwrap();

for entry in reader {
entry_count += 1;

if let LogEventContent::FileHeader(_) = entry.unwrap().content {
found_file_header = true;
file_header_count += 1;
}
}
Expand Down
7 changes: 7 additions & 0 deletions src/modules/exobiology/models/spawn_condition.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use crate::galaxy::Region;
use crate::materials::Material;
use crate::modules::galaxy::{
AtmosphereType, PlanetClass, StarClass, StarLuminosity, VolcanismType,
Expand All @@ -15,6 +16,7 @@ pub enum SpawnCondition {
/// The maximum gravity the planet must have, in G
MaxGravity(f32),
PlanetClass(PlanetClass),
MainStarClass(StarClass),
ParentStarClass(StarClass),
ParentStarLuminosity(StarLuminosity),
MinOrEqualParentStarLuminosity(StarLuminosity),
Expand All @@ -24,6 +26,9 @@ pub enum SpawnCondition {
MinDistanceFromParentSun(f32),
AnyVolcanism,

MinPressure(f32),
MaxPressure(f32),

/// The maximum distance the planet needs to be from the center of a nebula in Ly
WithinNebulaRange(f32),

Expand All @@ -36,6 +41,8 @@ pub enum SpawnCondition {
IcyComposition,
MetalComposition,

Region(Region),

Special,

Any(Vec<SpawnCondition>),
Expand Down
66 changes: 39 additions & 27 deletions src/modules/exobiology/models/spawn_source.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ use crate::exobiology::models::spawn_source::spawn_source_star::SpawnSourceStar;
use crate::exobiology::models::spawn_source::target_planet::TargetPlanet;
use crate::exobiology::models::spawn_source::target_system::TargetSystem;
use crate::exobiology::{SpawnCondition, Species};
use crate::galaxy::{AtmosphereDensity, AtmosphereType, Nebula, VolcanismType};
use crate::galaxy::{AtmosphereDensity, AtmosphereType, Nebula, Region, VolcanismType};
use crate::logs::scan_event::ScanEventParent;

#[derive(Debug)]
Expand All @@ -27,14 +27,19 @@ impl<'a> SpawnSource<'a> {

/// Checks if the given species can spawn on this spawn source.
pub fn can_spawn_species(&self, species: &Species) -> bool {
species
.spawn_conditions()
.iter()
.all(|condition| self.satisfies_spawn_condition(condition))
if !self.target_planet.is_landable {
return false;
}

self.satisfies_spawn_condition(species.spawn_conditions())
}

/// Checks if the spawn source satisfies the given condition.
pub fn satisfies_spawn_condition(&self, condition: &SpawnCondition) -> bool {
if !self.target_planet.is_landable {
return false;
}

match condition {
SpawnCondition::MinMeanTemperature(min_temp) => {
&self.target_planet.surface_temperature >= min_temp
Expand All @@ -59,6 +64,9 @@ impl<'a> SpawnSource<'a> {
&self.target_planet.gravity.as_g() <= max_gravity
}
SpawnCondition::PlanetClass(planet_class) => &self.target_planet.class == planet_class,
SpawnCondition::MainStarClass(star_class) => {
&self.target_system.stars_in_system[&0].class == star_class
}
SpawnCondition::ParentStarClass(star_class) => {
self.parent_stars().any(|star| &star.class == star_class)
}
Expand All @@ -77,7 +85,7 @@ impl<'a> SpawnSource<'a> {
}
SpawnCondition::MinDistanceFromParentSun(min_distance) => {
// TODO not sure, but Eccentricity might need to be taken into account as well
&(self.target_planet.semi_major_axis / 149597870700.0) >= min_distance
&(self.target_planet.semi_major_axis.as_au()) >= min_distance
}
SpawnCondition::AnyVolcanism => {
self.target_planet.volcanism.kind != VolcanismType::None
Expand All @@ -94,28 +102,32 @@ impl<'a> SpawnSource<'a> {
SpawnCondition::MaterialPresence(material) => {
self.target_planet.materials.contains(material)
}
SpawnCondition::RockyComposition => {
let Some(composition) = &self.target_planet.composition else {
return false;
};

composition.rock > 0.0
SpawnCondition::RockyComposition => self
.target_planet
.composition
.as_ref()
.is_some_and(|composition| composition.rock > 0.0),
SpawnCondition::IcyComposition => self
.target_planet
.composition
.as_ref()
.is_some_and(|composition| composition.ice > 0.0),
SpawnCondition::MetalComposition => self
.target_planet
.composition
.as_ref()
.is_some_and(|composition| composition.metal > 0.0),
SpawnCondition::MinPressure(min_pressure) => {
&self.target_planet.pressure >= min_pressure
}
SpawnCondition::MaxPressure(max_pressure) => {
&self.target_planet.pressure <= max_pressure
}
SpawnCondition::Region(region) => {
Region::from_pos(self.target_system.star_system_position).is_some_and(
|actual_region| &actual_region == region || actual_region == Region::Unknown,
)
}
SpawnCondition::IcyComposition => {
let Some(composition) = &self.target_planet.composition else {
return false;
};

composition.ice > 0.0
}
SpawnCondition::MetalComposition => {
let Some(composition) = &self.target_planet.composition else {
return false;
};

composition.metal > 0.0
}

SpawnCondition::Special => false,

SpawnCondition::Any(conditions) => conditions
Expand Down
8 changes: 6 additions & 2 deletions src/modules/exobiology/models/spawn_source/target_planet.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
use crate::galaxy::{Atmosphere, Gravity, PlanetClass, PlanetComposition, Volcanism};
use crate::galaxy::{
Atmosphere, Gravity, LocalDistance, PlanetClass, PlanetComposition, Volcanism,
};
use crate::logs::scan_event::ScanEventParent;
use crate::materials::Material;
use serde::Serialize;
use std::collections::HashSet;

#[derive(Debug, Serialize)]
pub struct TargetPlanet {
pub is_landable: bool,
pub atmosphere: Atmosphere,
pub gravity: Gravity,
pub class: PlanetClass,
Expand All @@ -14,6 +17,7 @@ pub struct TargetPlanet {
pub materials: HashSet<Material>,
pub composition: Option<PlanetComposition>,
pub parents: Vec<ScanEventParent>,
pub semi_major_axis: f32,
pub semi_major_axis: LocalDistance,
pub geological_signals_present: bool,
pub pressure: f32,
}
89 changes: 40 additions & 49 deletions src/modules/exobiology/models/species.rs
Original file line number Diff line number Diff line change
Expand Up @@ -32,35 +32,27 @@ pub enum Species {
AmphoraPlant,

// Anemones
// TODO needs to be verified
#[serde(rename = "$Codex_Ent_Sphere_Name;")]
AnemoneLuteolum,

// TODO needs to be verified
#[serde(rename = "$Codex_Ent_SphereABCD_01_Name;")]
AnemoneCroceum,

// TODO needs to be verified
#[serde(rename = "$Codex_Ent_SphereABCD_02_Name;")]
AnemonePuniceum,

// TODO needs to be verified
#[serde(rename = "$Codex_Ent_SphereABCD_03_Name;")]
AnemoneRoseum,

// TODO needs to be verified
#[serde(rename = "$Codex_Ent_SphereEFGH_Name;")]
AnemoneBlatteumBioluminescent,

// TODO needs to be verified
#[serde(rename = "$Codex_Ent_SphereEFGH_01_Name;")]
AnemoneRubeumBioluminescent,

// TODO needs to be verified
#[serde(rename = "$Codex_Ent_SphereEFGH_02_Name;")]
AnemonePrasinumBioluminescent,

// TODO needs to be verified
#[serde(rename = "$Codex_Ent_SphereEFGH_03_Name;")]
AnemoneRoseumBioluminescent,

Expand Down Expand Up @@ -475,14 +467,14 @@ impl Display for Species {
Species::BacteriumVesicula => "Bacterium Vesicula",
Species::BacteriumVolu => "Bacterium Volu",

Species::BrainTreeAureum => "Aureum Brain Tree ",
Species::BrainTreeGypseeum => "Gypseeum Brain Tree ",
Species::BrainTreeLindigoticum => "Lindigoticum Brain Tree ",
Species::BrainTreeAureum => "Aureum Brain Tree",
Species::BrainTreeGypseeum => "Gypseeum Brain Tree",
Species::BrainTreeLindigoticum => "Lindigoticum Brain Tree",
Species::BrainTreeLividum => "Lividum Brain Tree ",
Species::BrainTreeOstrinum => "Ostrinum Brain Tree ",
Species::BrainTreePuniceum => "Puniceum Brain Tree ",
Species::BrainTreeRoseum => "Roseum Brain Tree ",
Species::BrainTreeViride => "Viride Brain Tree ",
Species::BrainTreeOstrinum => "Ostrinum Brain Tree",
Species::BrainTreePuniceum => "Puniceum Brain Tree",
Species::BrainTreeRoseum => "Roseum Brain Tree",
Species::BrainTreeViride => "Viride Brain Tree",

Species::CactoidaCortexum => "Cactoida Cortexum",
Species::CactoidaLapis => "Cactoida Lapis",
Expand Down Expand Up @@ -591,7 +583,7 @@ impl Display for Species {
}

impl Species {
pub fn spawn_conditions(&self) -> &Vec<SpawnCondition> {
pub fn spawn_conditions(&self) -> &SpawnCondition {
&SPECIES_SPAWN_CONDITIONS
.iter()
.find(|(species, _)| species == self)
Expand All @@ -611,21 +603,18 @@ impl Species {
Species::AleoidaLaminiae => 3_385_200,
Species::AleoidaGravis => 12_934_900,

// TODO this needs a value
Species::AmphoraPlant => 0,
Species::AmphoraPlant => 1_628_800,

// TODO these need values
Species::AnemoneLuteolum => 0,
Species::AnemoneCroceum => 0,
Species::AnemonePuniceum => 0,
Species::AnemoneRoseum => 0,
Species::AnemoneBlatteumBioluminescent => 0,
Species::AnemoneRubeumBioluminescent => 0,
Species::AnemonePrasinumBioluminescent => 0,
Species::AnemoneRoseumBioluminescent => 0,

// TODO this needs a value
Species::BarkMound => 0,
Species::AnemoneLuteolum => 1_499_900,
Species::AnemoneCroceum => 1_499_900,
Species::AnemonePuniceum => 1_499_900,
Species::AnemoneRoseum => 1_499_900,
Species::AnemoneBlatteumBioluminescent => 1_499_900,
Species::AnemoneRubeumBioluminescent => 1_499_900,
Species::AnemonePrasinumBioluminescent => 1_499_900,
Species::AnemoneRoseumBioluminescent => 1_499_900,

Species::BarkMound => 1_471_900,

Species::BacteriumAurasus => 1_000_000,
Species::BacteriumNebulus => 5_289_900,
Expand All @@ -642,14 +631,14 @@ impl Species {
Species::BacteriumVerrata => 3_897_000,

// TODO these need values
Species::BrainTreeRoseum => 0,
Species::BrainTreeGypseeum => 0,
Species::BrainTreeOstrinum => 0,
Species::BrainTreeViride => 0,
Species::BrainTreeLividum => 0,
Species::BrainTreeAureum => 0,
Species::BrainTreePuniceum => 0,
Species::BrainTreeLindigoticum => 0,
Species::BrainTreeRoseum => 1_593_700,
Species::BrainTreeGypseeum => 1_593_700,
Species::BrainTreeOstrinum => 1_593_700,
Species::BrainTreeViride => 1_593_700,
Species::BrainTreeLividum => 1_593_700,
Species::BrainTreeAureum => 1_593_700,
Species::BrainTreePuniceum => 1_593_700,
Species::BrainTreeLindigoticum => 1_593_700,

Species::CactoidaCortexum => 3_667_600,
Species::CactoidaLapis => 2_483_600,
Expand Down Expand Up @@ -745,15 +734,14 @@ impl Species {
Species::ThargoidBarnacleMatrixSubmerged => 0,
Species::ThargoidBarnacleMatrix => 2_313_500,

// TODO these need values
Species::SinuousTubersRoseum => 0,
Species::SinuousTubersPrasinum => 0,
Species::SinuousTubersAlbidum => 0,
Species::SinuousTubersCaeruleum => 0,
Species::SinuousTubersBlatteum => 0,
Species::SinuousTubersLindigoticum => 0,
Species::SinuousTubersViolaceum => 0,
Species::SinuousTubersViride => 0,
Species::SinuousTubersRoseum => 1_514_500,
Species::SinuousTubersPrasinum => 1_514_500,
Species::SinuousTubersAlbidum => 1_514_500,
Species::SinuousTubersCaeruleum => 1_514_500,
Species::SinuousTubersBlatteum => 1_514_500,
Species::SinuousTubersLindigoticum => 1_514_500,
Species::SinuousTubersViolaceum => 1_514_500,
Species::SinuousTubersViride => 1_514_500,
}
}
}
Expand All @@ -762,12 +750,15 @@ impl Species {
mod tests {
use strum::IntoEnumIterator;

use crate::modules::exobiology::Species;
use crate::{
exobiology::r#static::species_spawn_conditions::SPECIES_SPAWN_CONDITIONS,
modules::exobiology::Species,
};

#[test]
fn all_species_have_matching_spawn_conditions() {
for species in Species::iter() {
assert!(!species.spawn_conditions().is_empty());
assert!(SPECIES_SPAWN_CONDITIONS.iter().any(|(s, _)| *s == species));
}
}
}
Loading
Loading