41 #define activeSys _Universe->activeStarSystem()
42 using namespace VSFileSystem;
44 namespace UniverseUtil
46 Unit* PythonUnitIter::current()
49 while ( (ret = **
this) ) {
57 void PythonUnitIter::advanceSignificant()
64 void PythonUnitIter::advanceInsignificant()
71 void PythonUnitIter::advancePlanet()
74 while ( notDone() && !(**this)->isPlanet() )
78 void PythonUnitIter::advanceJumppoint()
81 while ( notDone() && !(**this)->isJumppoint() )
85 void PythonUnitIter::advanceN(
int n )
87 while (notDone() && n > 0) {
93 void PythonUnitIter::advanceNSignificant(
int n )
97 while ( notDone() && (n > 0) ) {
103 void PythonUnitIter::advanceNInsignificant(
int n )
106 advanceInsignificant();
107 while ( notDone() && (n > 0) ) {
108 advanceInsignificant();
113 void PythonUnitIter::advanceNPlanet(
int n )
115 if ( notDone() && !(**this)->isPlanet() )
117 while (notDone() && n > 0) {
123 void PythonUnitIter::advanceNJumppoint(
int n )
125 if ( notDone() && !(**this)->isJumppoint() )
127 while (notDone() && n > 0) {
140 if ( (*it)->GetSerial() == serial )
143 cout<<
"ERROR --> no unit for serial "<<serial<<endl;
146 std::string
vsConfig( std::string category, std::string option, std::string def )
152 string faction_string,
154 string unittype_string,
160 string destinations )
164 if (unittype_string ==
"planet")
166 else if (unittype_string ==
"asteroid")
168 else if (unittype_string ==
"nebula")
182 cf.
waves = nr_of_waves;
185 cf.
rot[0] = cf.
rot[1] = cf.
rot[2] = 0.0f;
196 if ( !category.empty() ) {
200 unsigned int i = Begin+( rand()%(End-Begin) );
204 for (
unsigned int i = 0;
i < 500; ++
i) {
206 if (ret->
GetContent().find(
"mission" ) == string::npos)
211 Cargo tempret = *ret;
294 if ( (NULL == en) || (rand()%3 == 0) )
333 for (
unsigned int i = 0;
i < nass; ++
i)
339 float GetRelation( std::string myfaction, std::string theirfaction )
346 if (myfac == theirfac)
350 else if (theirfac == un->
faction)
355 void AdjustRelation( std::string myfaction, std::string theirfaction,
float factor,
float rank )
359 float realfactor = factor*rank;
363 if (myfac == theirfac)
367 else if (theirfac == un->
faction)
377 if (val > 1) val = 1;
386 fg =
"FG_Relation_"+fg;
393 if (delta > 1) delta = 1;
397 float val =
getSaveData( which_cp, saveVar, 0 )+delta;
398 if (val > 1) val = 1;
407 fg =
"FG_Relation_"+fg;
425 return activeSys->getUnitList().createIterator();
431 for (
int i = -1; (un = *iter) &&
i < index; ++iter) {
445 return reinterpret_cast< Unit*
> (ptr);
453 while ( it.
notDone() && ( (
void*) (*it) != ptr ) )
455 return ( (
void*) (*it) == ptr ) ? reinterpret_cast< Unit* > (ptr) : 0;
462 return iter.
notDone() ? (*iter) : NULL;
466 #ifdef USE_STL_COLLECTION
501 #define DEFAULT_FACTION_SAVENAME "FactionTookOver_"
506 vector< std::string > *ans =
514 vector< std::string > *ans =
519 ans->push_back( std::string( fac ) );
543 std::string::size_type where = objective.find(
".blank" );
544 if (where != string::npos)
545 objective = objective.substr( 0, where )+objective.substr( where+strlen(
".blank" ) );
546 else return objective;
557 return mission->objectives.size()-1;
597 which, NULL,
mission, NULL, NULL );
607 -1, NULL,
mission, NULL, NULL );
631 void IOmessage(
int delay,
string from,
string to,
string message )
660 if (global_auto == 1)
662 else if (global_auto == -1)
666 if (player_auto == 1)
668 else if (player_auto == -1)
677 for (
unsigned int k = 0;
k < 10; ++
k) {
679 bool collision =
false;
688 double mag = delta.Magnitude();
692 delta.Set( 0, 0, 1 );
693 delta = delta.Scale( dist+un->
rSize()+radial_size );
699 pos += ( radial_size+un->
rSize() )*r;
704 if (collision ==
false)
716 string faction_string,
741 return tmp[statname];
766 std::replace( message.begin(), message.end(),
'\'',
'\"' );
767 std::replace( message.begin(), message.end(),
'\\',
'/' );
768 std::replace( message.begin(), message.end(),
'\n',
' ' );
769 std::replace( message.begin(), message.end(),
'\r',
' ' );
779 string pythonCode = game_options.
custompython+
"("+(trusted ?
"True" :
"False")
780 +
", r\'"+cmd+
"\', r\'"+args+
"\', r\'"+
id+
"\')\n";
781 COUT<<
"Executing python command: "<<endl;
782 cout<<
" "<<pythonCode;
783 const char *cpycode = pythonCode.c_str();
784 ::Python::reseterrors();
785 PyRun_SimpleString( const_cast< char* > (cpycode) );
786 ::Python::reseterrors();
804 std::string
getVariable( std::string section, std::string name, std::string def )
808 std::string
getSubVariable( std::string section, std::string subsection, std::string name, std::string def )
859 using namespace VSFileSystem;
864 cout<<
"\t\tcomputing serials for "<<systempath<<
"...";
865 std::string system =
f.ReadFull();
868 std::vector< std::string >search_patterns;
870 bool newserials =
true;
871 if (system.find(
"serial=", 0 ) != std::string::npos) {
873 cout<<
"Found serial in system file : replacing serials..."<<endl;
875 cout<<
"Found no serial in system file : generating..."<<endl;
877 search_patterns.push_back(
"<planet " );
878 search_patterns.push_back(
"<Planet " );
879 search_patterns.push_back(
"<PLANET " );
880 search_patterns.push_back(
"<unit " );
881 search_patterns.push_back(
"<Unit " );
882 search_patterns.push_back(
"<UNIT " );
883 search_patterns.push_back(
"<nebula " );
884 search_patterns.push_back(
"<Nebula " );
885 search_patterns.push_back(
"<NEBULA " );
886 search_patterns.push_back(
"<jump " );
887 search_patterns.push_back(
"<Jump " );
888 search_patterns.push_back(
"<JUMP " );
889 for (std::vector< std::string >::iterator ti = search_patterns.begin(); ti != search_patterns.end(); ++ti) {
890 std::string search( (*ti) );
891 std::string::size_type search_length = (*ti).length();
892 std::string::size_type curpos = 0;
894 while ( ( curpos = system.find( search, curpos ) ) != std::string::npos ) {
900 system.replace( curpos, search_length, serial_str );
902 system.replace( curpos, search_length+15, serial_str );
904 curpos += search_length;
906 cerr<<
"\t\tFound "<<nboc<<
" occurences of "<<search<<endl;
915 cerr<<
"!!! ERROR : opening "<<systempath<<
" for writing"<<endl;
918 if (
f.Write( system ) != system.length() ) {
919 cerr<<
"!!! ERROR : writing system file"<<endl;
926 cerr<<
"ERROR cannot open system file : "<<systempath<<endl;
933 cout<<
"Going through "<<stak.size()<<
" sectors"<<endl;
934 cout<<
"Generating random serial numbers :"<<endl;
935 for (; !stak.empty();) {
936 string sys( stak.back()+
".system" );
940 cout<<
"Computing done."<<endl;
950 std::string::size_type where = system.find_first_of(
'/' );
951 std::string::size_type basewhere = system.find_first_of(
'@', where );
952 return std::string(
"Sec:" )+system.substr( 0, where )
953 +
" Sys:"+( where == string::npos ? std::string(
"") : system.substr( where+1, (basewhere!=string::npos) ? basewhere-where-1 : string::npos ) )
954 +( basewhere == string::npos ? std::string(
"") : std::string(
" ")+system.substr( basewhere+1 ) );
958 if (ship.length() > 0)
959 ship[0] = toupper( ship[0] );
960 std::string::size_type where = ship.find(
"." );
961 if (where != string::npos) {
962 ship = ship.substr( 0, where );
963 ship =
"Refurbished "+ship;
968 string getSaveInfo(
const std::string &filename,
bool formatForTextbox )
971 static set< string >campaign_score_vars;
972 static bool campaign_score_vars_init =
false;
973 if (!campaign_score_vars_init) {
974 string campaign_score =
vs_config->
getVariable(
"physics",
"campaigns",
"privateer_campaign vegastrike_campaign" );
976 string::size_type where = 0, when = game_options.
campaigns.find(
' ' );
977 while (where != string::npos) {
978 campaign_score_vars.insert( game_options.
campaigns.substr( where, ( (when == string::npos) ? when : when-where ) ) );
979 where = (when == string::npos) ? when : when+1;
980 when = game_options.
campaigns.find(
' ', where );
982 campaign_score_vars_init =
true;
985 std::string lf = (formatForTextbox ?
"#n#" :
"\n");
987 bool updatepos =
false;
989 vector< std::string >Ships;
992 savegame.
ParseSaveGame( filename, system,
"", pos, updatepos, creds, Ships,
994 campaign_score_vars );
998 text =
"Savegame: "+text+lf+
"_________________"+lf;
1002 text +=
"Saved on: ";
1003 text += ctime( &attrib.st_mtime )+lf;
1007 ( (
unsigned int) (creds*100) )%100 )+lf;
1009 if ( Ships.size() ) {
1011 if (Ships.size() > 2) {
1012 text +=
"Fleet:"+lf;
1013 for (
unsigned int i = 2;
i < Ships.size();
i += 2)
1019 for (set< string >::const_iterator it = campaign_score_vars.begin(); it != campaign_score_vars.end(); ++it) {
1024 if (var.length() > 0)
1025 var[0] = toupper( var[0] );
1026 text += var.substr( 0, var.find(
"_" ) )+
" Campaign Score: "+
XMLSupport::tostring( curscore )+lf;
1030 text +=
"Campaign Score: 0"+lf;
1047 static string ngsn(
"New_Game" );
1053 vector< string > path;