Skip to content

ModAPI SDK v2.5.205

Choose a tag to compare

@emd4600 emd4600 released this 02 Oct 22:37
· 355 commits to master since this release

This update contains many improvements to planets and stars:

  • Added many fields to cPlanetRecord and cStarRecord.
  • Improved StarID and PlanetID
  • Added class SpaceNames used to generate random names.
  • Added class ResourceKeyGenerator used to generate unique keys for creations/planets.
  • Now it is possible to create instances of cPlanetRecord with all the fields necessary.
  • Added some methods related with galaxy generation. One of them is cStarManager::GenerateSolSystem(), which is called when generating the galaxy to create the Sol system (which contains the Earth, etc). This method can be detoured to add special stars or planets during galaxy creation. For example, this simple method adds the Jupiter moon "Io":
member_detour(GenerateSolSystem__detour, Simulator::cStarManager, void())
{
	void detoured()
	{
		using namespace Simulator;

		original_function(this);

		auto solStar = GetSol();

		// 0 is the Earth, 1 is the Moon, 2 is Mercury, 3 is Venus, 4 is Mars, 5 is asteroid belt,
		// 6 is Jupiter,...
		auto jupiter = solStar->GetPlanetRecord(6);

		cPlanetRecordPtr planet;
		cPlanetRecord::Create(PlanetID(solStar->GetID(), solStar->mPlanetCount), planet);

		planet->mName = u"Io";
		planet->mType = PlanetType::T0;
		planet->mTechLevel = TechLevel::None;
		StarManager.GenerateEllipticalOrbit(solStar, planet->mOrbit, 21.0, 23.0, jupiter);

		planet->SetGeneratedTerrainKey(planet->GenerateTerrainKey());
		// I just used a random terrain script here
		TerrainResourceManager.SaveTerrain(planet->GetGeneratedTerrainKey(), id("crystal_hex"), 0x4184A200);

		StarManager.CalculatePlanetScores(planet.get());

		solStar->mPlanetCount++;
	}
};

void AttachDetours()
{
	attach_detour(GenerateSolSystem__detour, Simulator::cStarManager, GenerateSolSystem);
}