Example #1
0
bool SectorCustomSystemsGenerator::Apply(Random& rng, RefCountedPtr<Galaxy> galaxy, RefCountedPtr<Sector> sector, GalaxyGenerator::SectorConfig* config)
{
	PROFILE_SCOPED()

	const int sx = sector->sx;
	const int sy = sector->sy;
	const int sz = sector->sz;

	if ((sx >= -m_customOnlyRadius) && (sx <= m_customOnlyRadius-1) &&
		(sy >= -m_customOnlyRadius) && (sy <= m_customOnlyRadius-1) &&
		(sz >= -m_customOnlyRadius) && (sz <= m_customOnlyRadius-1))
		config->isCustomOnly = true;

	const std::vector<const CustomSystem*> &systems = galaxy->GetCustomSystems()->GetCustomSystemsForSector(sx, sy, sz);
	if (systems.size() == 0) return true;

	Uint32 sysIdx = 0;
	for (std::vector<const CustomSystem*>::const_iterator it = systems.begin(); it != systems.end(); ++it, ++sysIdx) {
		const CustomSystem *cs = *it;
		Sector::System s(sector.Get(), sx, sy, sz, sysIdx);
		s.m_pos = Sector::SIZE*cs->pos;
		s.m_name = cs->name;
		for (s.m_numStars=0; s.m_numStars<cs->numStars; s.m_numStars++) {
			if (cs->primaryType[s.m_numStars] == 0) break;
			s.m_starType[s.m_numStars] = cs->primaryType[s.m_numStars];
		}
		s.m_customSys = cs;
		s.m_seed = cs->seed;
		if (cs->want_rand_explored) {
			/*
			 * 0 - ~500ly from sol: explored
			 * ~500ly - ~700ly (65-90 sectors): gradual
			 * ~700ly+: unexplored
			 */
			int dist = isqrt(1 + sx*sx + sy*sy + sz*sz);
			if (((dist <= 90) && ( dist <= 65 || rng.Int32(dist) <= 40)) || galaxy->GetFactions()->IsHomeSystem(SystemPath(sx, sy, sz, sysIdx)))
				s.m_explored = StarSystem::eEXPLORED_AT_START;
			else
				s.m_explored = StarSystem::eUNEXPLORED;
		} else {
			if (cs->explored)
				s.m_explored = StarSystem::eEXPLORED_AT_START;
			else
				s.m_explored = StarSystem::eUNEXPLORED;
		}
		sector->m_systems.push_back(s);
	}
	return true;
}