2 #include "cmd/script/mission.h"
23 using namespace XMLSupport;
24 using namespace GalaxyXML;
29 int sl = strlen( input );
32 char *tmp = strdup( input );
36 if ( 0 == strcmp( ptr,
".system" ) ) {
41 ptr = ( tmp+(ptr-ttmp) );
58 char del[] = {
'/',
'\0'};
64 string d3fault = galaxy->
getVariable( section, subsection, variable,
65 galaxy->
getVariable( section, variable, defaultst ) );
66 if (d3fault.length() == 0)
67 d3fault = galaxy->
getVariable( section, variable, defaultst );
68 if (d3fault.length() == 0)
73 void ClampIt(
float &prop,
float min,
float max )
81 void ClampIt(
int &prop,
int min,
int max )
136 return (
float( rand() ) )/( ( ( (float) RAND_MAX )+1 ) );
139 static float sqav01()
145 static float fsqav(
float in1,
float in2 )
147 return sqav01()*(in2-in1)+in1;
150 static int rnd(
int in1,
int in2 )
152 return (
int) ( in1+(in2-in1)*(
float( rand() ) )/( ( (
float) RAND_MAX )+1 ) );
155 static int iav(
int in1,
int in2 )
157 return rnd( in1, in2+1 );
160 static int isqav(
int in1,
int in2 )
162 return (
int) ( in1+(in2+1-in1)*sqav01() );
180 static vector< string >rv;
182 string::size_type pos = 0, sep;
183 while ( ( sep = value.find(
' ', pos ) ) != string::npos ) {
184 rv.push_back( value.substr( pos, sep-pos ) );
187 if ( pos < value.length() )
188 rv.push_back( value.substr( pos ) );
226 bool canret = origin.length() == 0;
227 for (
unsigned int i = 0; i < si.
jumps.size(); i++)
228 if (si.
jumps[i] == origin) {
233 si.
jumps.push_back( origin );
238 clampSystem( si, minlimit, maxlimit );
247 return galaxy->getVariable( sector, name, prop,
248 galaxy->getVariable( sector, prop, galaxy->getVariable(
"unknown_sector",
"min", prop,
"" ) ) );
255 return galaxy->getVariable( sector, name, prop, def );
267 map< string, unsigned int > visited;
268 vector< const string* > origin;
269 deque< const string* > open;
273 origin.push_back(NULL);
274 open.push_back(&from);
277 while (!open.empty()) {
278 const string *system = open.front();
281 const vector< std::string > &adjacent = getAdjacentStarSystems(*system);
282 for (vector< std::string >::const_iterator i = adjacent.begin(); i != adjacent.end(); ++i) {
283 map< string, unsigned int >::const_iterator velem = visited.find(*i);
284 if (velem == visited.end()) {
285 visited[*i] = origin.size();
286 origin.push_back(system);
287 velem = visited.find(*i);
294 open.push_back(&velem->first);
302 map< string, unsigned int >::const_iterator velem = visited.find(to);
303 while (velem != visited.end()) {
304 path.push_back(velem->first);
305 if (origin[velem->second] == NULL)
306 velem = visited.end();
308 velem = visited.find(*origin[velem->second]);
312 reverse(path.begin(), path.end());