Vegastrike 0.5.1 rc1  1.0
Original sources for Vegastrike Evolved
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
galaxy_gen.h File Reference
#include <vector>
#include <string>

Go to the source code of this file.

Classes

struct  SystemInfo
 All the properties from the galaxy in a system. More...
 

Functions

std::string getStarSystemFileName (const std::string &input)
 appends .system More...
 
std::string getStarSystemName (const std::string &in)
 finds the name after all / characters and capitalizes the first letter More...
 
std::string getStarSystemSector (const std::string &in)
 finds the name before the first / this is the sector name More...
 
string getUniversePath ()
 
void readnames (vector< string > &entity, const char *filename)
 
void generateStarSystem (SystemInfo &si)
 

Function Documentation

void generateStarSystem ( SystemInfo si)

Definition at line 1344 of file galaxy_gen.cpp.

References SystemInfo::asteroids, SystemInfo::asteroidslist, StarSystemGent::background, SystemInfo::backgrounds, SystemInfo::compactness, StarSystemGent::compactness, VSFileSystem::CreateDirectoryHome(), StarSystemGent::CreateStarSystem(), f, SystemInfo::faction, StarSystemGent::faction, SystemInfo::filename, VegaConfig::getVariable(), StarSystemGent::gradtex, i, int, StarSystemGent::jumpcompactness, SystemInfo::jumps, StarSystemGent::jumps, SystemInfo::name, SystemInfo::names, StarSystemGent::names, StarSystemGent::naturalphenomena, SystemInfo::nebulae, SystemInfo::nebulaelist, StarSystemGent::numnaturalphenomena, StarSystemGent::numstarbases, StarSystemGent::numstarentities, SystemInfo::numstars, SystemInfo::numun1, SystemInfo::numun2, VSFileSystem::Ok, XMLSupport::parse_float(), XMLSupport::parse_int(), SystemInfo::planetlist, pushTowardsMean(), StarSystemGent::readColorGrads(), StarSystemGent::readentity(), readnames(), readplanetentity(), StarSystemGent::ResetGlobalVariables(), SystemInfo::ringlist, StarSystemGent::rings, SystemInfo::sector, SystemInfo::seed, seedrand(), VSFileSystem::sharedsectors, SystemInfo::smallun, StarSystemGent::starbases, StarSystemGent::starradius, SystemInfo::stars, StarSystemGent::stars, stringhash(), SystemInfo::sunradius, VSFileSystem::SystemFile, StarSystemGent::systemname, VSFileSystem::universe_name, vs_config, and VSFileSystem::vs_fprintf().

Referenced by MakeStarSystem().

1345 {
1347  static float radiusscale = XMLSupport::parse_float( vs_config->getVariable( "galaxy", "StarRadiusScale", "1000" ) );
1348  si.sunradius *= radiusscale;
1349  systemname = si.name;
1350  static float compactness_scale = XMLSupport::parse_float( vs_config->getVariable( "galaxy", "CompactnessScale", "1.5" ) );
1351  static float jump_compactness_scale =
1352  XMLSupport::parse_float( vs_config->getVariable( "galaxy", "JumpCompactnessScale", "1.5" ) );
1353  static int meannaturalphenomena = XMLSupport::parse_int( vs_config->getVariable( "galaxy", "MeanNaturalPhenomena", "1" ) );
1354  static int meanbases = XMLSupport::parse_int( vs_config->getVariable( "galaxy", "MeanStarBases", "2" ) );
1355  compactness = si.compactness*compactness_scale;
1356  jumpcompactness = si.compactness*jump_compactness_scale;
1357  if (si.seed)
1358  seedrand( si.seed );
1359  else
1360  seedrand( stringhash( si.sector+'/'+si.name ) );
1361  VSFileSystem::vs_fprintf( stderr, "star %d, natural %d, bases %d", si.numstars, si.numun1, si.numun2 );
1362  int nat = pushTowardsMean( meannaturalphenomena, si.numun1 );
1363  numnaturalphenomena = nat > si.numun1 ? si.numun1 : nat;
1364  numstarbases = pushTowardsMean( meanbases, si.numun2 );
1365  static float smallUnitsMultiplier = XMLSupport::parse_float( vs_config->getVariable( "galaxy", "SmallUnitsMultiplier", "0" ) );
1366  numstarbases = (int) (si.numun2*smallUnitsMultiplier);
1368  VSFileSystem::vs_fprintf( stderr, "star %d, natural %d, bases %d", numstarentities, numnaturalphenomena, numstarbases );
1369  starradius.push_back( si.sunradius );
1370  readColorGrads( gradtex, (si.stars).c_str() );
1371 
1372  readentity( starbases, (si.smallun).c_str() );
1373  readentity( background, (si.backgrounds).c_str() );
1374  if ( background.empty() )
1375  background.push_back( si.backgrounds );
1376  if (si.nebulae)
1377  readentity( naturalphenomena, (si.nebulaelist).c_str() );
1378  if (si.asteroids)
1379  readentity( naturalphenomena, (si.asteroidslist).c_str() );
1380  for (unsigned int i = 0; i < si.jumps.size(); i++)
1381  jumps.push_back( si.jumps[i] );
1382  faction = si.faction;
1383 
1385 
1386  readentity( rings, (si.ringlist).c_str() );
1387  readnames( names, (si.names).c_str() );
1388 
1390 
1391  VSError err = f.OpenCreateWrite( si.filename, SystemFile );
1392  if (err <= Ok) {
1393  CreateStarSystem();
1394  f.Close();
1395  }
1396  ResetGlobalVariables(); //deallocate any unused memory in vectors.
1397 }
std::string getStarSystemFileName ( const std::string &  input)

appends .system

std::string getStarSystemName ( const std::string &  in)

finds the name after all / characters and capitalizes the first letter

std::string getStarSystemSector ( const std::string &  in)

finds the name before the first / this is the sector name

string getUniversePath ( )

Definition at line 56 of file galaxy.cpp.

References vs_options::universe_path.

57 {
58  char del[] = {'/', '\0'};
59  return game_options.universe_path+string( del );
60 }
void readnames ( vector< string > &  entity,
const char *  filename 
)

warning... obvious vulnerability

Definition at line 1182 of file galaxy_gen.cpp.

References VSFileSystem::VSFile::Close(), VSFileSystem::VSFile::Eof(), f, i, input_buffer, VSFileSystem::Ok, VSFileSystem::VSFile::OpenReadOnly(), VSFileSystem::VSFile::ReadLine(), and VSFileSystem::UniverseFile.

Referenced by generateStarSystem().

1183 {
1184  VSFile f;
1185  VSError err = f.OpenReadOnly( filename, UniverseFile );
1186  if (err > Ok)
1187  return;
1189  char input_buffer[1000];
1190  while ( !f.Eof() ) {
1191  f.ReadLine( input_buffer, 999 );
1192  if (input_buffer[0] == '\0' || input_buffer[0] == '\n' || input_buffer[0] == '\r')
1193  continue;
1194  for (unsigned int i = 0; input_buffer[i] != '\0' && i < 999; i++) {
1195  if (input_buffer[i] == '\r')
1196  input_buffer[i] = '\0';
1197  if (input_buffer[i] == '\n') {
1198  input_buffer[i] = '\0';
1199  break;
1200  }
1201  }
1202  entity.push_back( input_buffer );
1203  }
1204  f.Close();
1205 }