Skip to content

Commit

Permalink
Add galaxy init file, exposing galaxy parameters
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
impaktor authored and sturnclaw committed Dec 6, 2024
1 parent 0ff6b06 commit 61ceb71
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 3 deletions.
18 changes: 18 additions & 0 deletions src/galaxy/GalaxyConfig.cpp
Original file line number Diff line number Diff line change
@@ -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<std::string, std::string> &map = m_map[""];
map["GalaxyExploredMax"] = "90";
map["GalaxyExploredMin"] = "65";
map["GalaxyExploredMix"] = "40";

Read(FileSystem::userFiles, "galaxy.ini");

Save();
}
16 changes: 16 additions & 0 deletions src/galaxy/GalaxyConfig.h
Original file line number Diff line number Diff line change
@@ -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<std::string, std::string> map_string;
// GalaxyConfig(const map_string &override_ = map_string());
GalaxyConfig();
};

#endif
5 changes: 3 additions & 2 deletions src/galaxy/SectorGenerator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,12 +44,13 @@ bool SectorCustomSystemsGenerator::Apply(Random &rng, RefCountedPtr<Galaxy> 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;
Expand Down Expand Up @@ -171,7 +172,7 @@ bool SectorRandomSystemsGenerator::Apply(Random &rng, RefCountedPtr<Galaxy> 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;
Expand Down
26 changes: 25 additions & 1 deletion src/galaxy/SectorGenerator.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#ifndef SECTORGENERATOR_H
#define SECTORGENERATOR_H

#include "GalaxyConfig.h"
#include "GalaxyGenerator.h"
#include "Random.h"
#include "RefCounted.h"
Expand All @@ -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> galaxy, RefCountedPtr<Sector> 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> galaxy, RefCountedPtr<Sector> sector, GalaxyGenerator::SectorConfig *config);

private:
int m_GalaxyExploredMax;
int m_GalaxyExploredMin;
int m_GalaxyExploredMix;

const std::string GenName(RefCountedPtr<Galaxy> galaxy, const Sector &sec, Sector::System &sys, int si, Random &rand);
GalaxyConfig m_galaxyConfig;
};

class SectorPersistenceGenerator : public SectorGeneratorStage {
Expand Down

0 comments on commit 61ceb71

Please sign in to comment.