From 84f6229dd9affda7ae69d3da4e85880cdc8fb869 Mon Sep 17 00:00:00 2001 From: Karl F Date: Thu, 1 Feb 2024 16:40:31 +0100 Subject: [PATCH] Add galaxy init file, exposing galaxy parameters Expose parameters for explored space: 'min', 'max' range and 'mix' (drop off) parameters. Note: any change to this file will break saves. But we want it for modders. --- src/galaxy/GalaxyConfig.cpp | 18 ++++++++++++++++++ src/galaxy/GalaxyConfig.h | 16 ++++++++++++++++ src/galaxy/SectorGenerator.cpp | 5 +++-- src/galaxy/SectorGenerator.h | 26 +++++++++++++++++++++++++- 4 files changed, 62 insertions(+), 3 deletions(-) create mode 100644 src/galaxy/GalaxyConfig.cpp create mode 100644 src/galaxy/GalaxyConfig.h diff --git a/src/galaxy/GalaxyConfig.cpp b/src/galaxy/GalaxyConfig.cpp new file mode 100644 index 00000000000..283fe3e8f68 --- /dev/null +++ b/src/galaxy/GalaxyConfig.cpp @@ -0,0 +1,18 @@ +// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details +// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt + +#include "GalaxyConfig.h" +#include "FileSystem.h" + +GalaxyConfig::GalaxyConfig() +{ + // set defaults + std::map &map = m_map[""]; + map["GalaxyExploredMax"] = "90"; + map["GalaxyExploredMin"] = "65"; + map["GalaxyExploredMix"] = "40"; + + Read(FileSystem::userFiles, "galaxy.ini"); + + Save(); +} diff --git a/src/galaxy/GalaxyConfig.h b/src/galaxy/GalaxyConfig.h new file mode 100644 index 00000000000..346400f3d07 --- /dev/null +++ b/src/galaxy/GalaxyConfig.h @@ -0,0 +1,16 @@ +// Copyright © 2008-2024 Pioneer Developers. See AUTHORS.txt for details +// Licensed under the terms of the GPL v3. See licenses/GPL-3.txt + +#ifndef _GALAXYCONFIG_H +#define _GALAXYCONFIG_H + +#include "core/IniConfig.h" + +class GalaxyConfig : public IniConfig { +public: + typedef std::map map_string; + // GalaxyConfig(const map_string &override_ = map_string()); + GalaxyConfig(); +}; + +#endif diff --git a/src/galaxy/SectorGenerator.cpp b/src/galaxy/SectorGenerator.cpp index a255e77be71..26928a359e5 100644 --- a/src/galaxy/SectorGenerator.cpp +++ b/src/galaxy/SectorGenerator.cpp @@ -44,12 +44,13 @@ bool SectorCustomSystemsGenerator::Apply(Random &rng, RefCountedPtr gala s.m_seed = cs->seed; if (cs->want_rand_explored) { + /* * 0 - ~500ly from sol: explored * ~500ly - ~700ly (65-90 sectors): gradual * ~700ly+: unexplored */ - if (((dist <= Square(90)) && (dist <= Square(65) || rng.Int32(dist) <= Square(40))) || galaxy->GetFactions()->IsHomeSystem(SystemPath(sx, sy, sz, sysIdx))) + if (((dist <= Square(m_GalaxyExploredMax)) && (dist <= Square(m_GalaxyExploredMin) || rng.Int32(dist) <= Square(m_GalaxyExploredMix))) || galaxy->GetFactions()->IsHomeSystem(SystemPath(sx, sy, sz, sysIdx))) s.m_explored = StarSystem::eEXPLORED_AT_START; else s.m_explored = StarSystem::eUNEXPLORED; @@ -171,7 +172,7 @@ bool SectorRandomSystemsGenerator::Apply(Random &rng, RefCountedPtr gala * ~500ly - ~700ly (65-90 sectors): gradual * ~700ly+: unexplored */ - if (((dist <= Square(90)) && (dist <= Square(65) || rng.Int32(dist) <= Square(40))) || galaxy->GetFactions()->IsHomeSystem(SystemPath(sx, sy, sz, customCount + i))) + if (((dist <= Square(m_GalaxyExploredMax)) && (dist <= Square(m_GalaxyExploredMin) || rng.Int32(dist) <= Square(m_GalaxyExploredMix))) || galaxy->GetFactions()->IsHomeSystem(SystemPath(sx, sy, sz, customCount + i))) s.m_explored = StarSystem::eEXPLORED_AT_START; else s.m_explored = StarSystem::eUNEXPLORED; diff --git a/src/galaxy/SectorGenerator.h b/src/galaxy/SectorGenerator.h index 6ebef3ad97f..2f130870679 100644 --- a/src/galaxy/SectorGenerator.h +++ b/src/galaxy/SectorGenerator.h @@ -4,6 +4,7 @@ #ifndef SECTORGENERATOR_H #define SECTORGENERATOR_H +#include "GalaxyConfig.h" #include "GalaxyGenerator.h" #include "Random.h" #include "RefCounted.h" @@ -13,19 +14,42 @@ class SectorCustomSystemsGenerator : public SectorGeneratorStage { public: SectorCustomSystemsGenerator(int customOnlyRadius) : - m_customOnlyRadius(customOnlyRadius) {} + m_customOnlyRadius(customOnlyRadius) { + m_galaxyConfig = GalaxyConfig(); + + m_GalaxyExploredMax = m_galaxyConfig.Int("GalaxyExploredMax"); + m_GalaxyExploredMin = m_galaxyConfig.Int("GalaxyExploredMin"); + m_GalaxyExploredMix = m_galaxyConfig.Int("GalaxyExploredMix"); + } virtual bool Apply(Random &rng, RefCountedPtr galaxy, RefCountedPtr sector, GalaxyGenerator::SectorConfig *config); private: + int m_GalaxyExploredMax; + int m_GalaxyExploredMin; + int m_GalaxyExploredMix; + int m_customOnlyRadius; + GalaxyConfig m_galaxyConfig; }; class SectorRandomSystemsGenerator : public SectorGeneratorStage { public: + SectorRandomSystemsGenerator(){ + m_galaxyConfig = GalaxyConfig(); + + m_GalaxyExploredMax = m_galaxyConfig.Int("GalaxyExploredMax"); + m_GalaxyExploredMin = m_galaxyConfig.Int("GalaxyExploredMin"); + m_GalaxyExploredMix = m_galaxyConfig.Int("GalaxyExploredMix"); + } virtual bool Apply(Random &rng, RefCountedPtr galaxy, RefCountedPtr sector, GalaxyGenerator::SectorConfig *config); private: + int m_GalaxyExploredMax; + int m_GalaxyExploredMin; + int m_GalaxyExploredMix; + const std::string GenName(RefCountedPtr galaxy, const Sector &sec, Sector::System &sys, int si, Random &rand); + GalaxyConfig m_galaxyConfig; }; class SectorPersistenceGenerator : public SectorGeneratorStage {