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
Mission Class Reference

#include <mission.h>

Classes

struct  Objective
 
struct  Runtime
 

Public Types

enum  MISSION_AUTO { AUTO_OFF =-1, AUTO_NORMAL =0, AUTO_ON =1 }
 

Public Member Functions

void SetUnpickleData (std::string dat)
 
void terminateMission ()
 
Unitcall_unit_launch (class CreateFlightgroup *fg, int type, const std::string &destinations)
 
 Mission (const char *configfile, bool loadscripts=true)
 
 Mission (const char *filename, const std::string &pythonscript, bool loadscripts=true)
 
std::string Pickle ()
 
void UnPickle (std::string pickled)
 
void AddFlightgroup (Flightgroup *fg)
 
void initMission (bool loadscripts=true)
 
int getPlayerMissionNumber ()
 
 ~Mission ()
 alex Please help me make this function...this is called between mission loops More...
 
FlightgroupfindFlightgroup (const string &fg_name, const string &faction)
 
string getVariable (string name, string defaultval)
 
void GetOrigin (QVector &pos, string &planetname)
 
void DirectorLoop ()
 
void DirectorStart (missionNode *node)
 
void DirectorStartStarSystem (StarSystem *ss)
 
void DirectorInitgame ()
 
void DirectorEnd ()
 
void DirectorBenchmark ()
 
void DirectorShipDestroyed (Unit *unit)
 
void BriefingStart ()
 
class TextPlaneBriefingRender ()
 
void BriefingLoop ()
 
void BriefingUpdate ()
 
void BriefingEnd ()
 
bool BriefingInProgress ()
 
double getGametime ()
 
void loadMissionModules ()
 
void loadModule (string modulename)
 
void addModule (string modulename)
 
bool runScript (string modulename, const string &scriptname, unsigned int classid=0)
 
bool runScript (missionNode *, const string &scriptname, unsigned int classid=0)
 
void RunDirectorScript (const string &)
 
unsigned int createClassInstance (string modulename)
 
void setCurrentAIUnit (Unit *unit)
 
void setCurrentAIOrder (Order *order)
 
varInstlookupClassVariable (string modulename, string varname, unsigned int classid)
 
void destroyClassInstance (string modulename, unsigned int classid)
 
void call_vector_into_olist (varInst *vec_vi, QVector vec3)
 
void deleteVarInst (varInst *vi, bool del_local=false)
 

Static Public Member Functions

static MissiongetNthPlayerMission (int cp, int num)
 
static void wipeDeletedMissions ()
 

Public Attributes

unsigned int player_num
 
MISSION_AUTO player_autopilot
 
MISSION_AUTO global_autopilot
 
vector< Objectiveobjectives
 
class Briefingbriefing
 
string mission_name
 
struct Mission::Runtime runtime
 

Static Public Attributes

static double gametime = 0.0
 
static int number_of_flightgroups = 0
 
static int number_of_ships = 0
 
static vector< Flightgroup * > flightgroups
 
static MessageCentermsgcenter = NULL
 

Friends

void UnpickleMission (std::string pickled)
 

Detailed Description

Definition at line 434 of file mission.h.

Member Enumeration Documentation

Enumerator
AUTO_OFF 
AUTO_NORMAL 
AUTO_ON 

Definition at line 437 of file mission.h.

437 {AUTO_OFF=-1, AUTO_NORMAL=0, AUTO_ON=1};

Constructor & Destructor Documentation

Mission::Mission ( const char *  configfile,
bool  loadscripts = true 
)

Definition at line 69 of file mission.cpp.

70 {
71  ConstructMission( filename, string( "" ), loadscripts );
72 }
Mission::Mission ( const char *  filename,
const std::string &  pythonscript,
bool  loadscripts = true 
)

Definition at line 65 of file mission.cpp.

66 {
67  ConstructMission( filename, script, loadscripts );
68 }
Mission::~Mission ( )

alex Please help me make this function...this is called between mission loops

Definition at line 54 of file mission.cpp.

References VSFileSystem::vs_fprintf().

55 {
56  VSFileSystem::vs_fprintf( stderr, "Mission Cleanup Not Yet Implemented" );
57  //do not delete msgcenter...could be vital
58 }

Member Function Documentation

void Mission::AddFlightgroup ( Flightgroup fg)

Definition at line 364 of file mission.cpp.

References Flightgroup::flightgroup_nr, flightgroups, and number_of_flightgroups.

Referenced by Flightgroup::Init().

365 {
366  fg->flightgroup_nr = flightgroups.size();
367  flightgroups.push_back( fg );
369 }
void Mission::addModule ( string  modulename)

Definition at line 429 of file director_generic.cpp.

Referenced by Unit::LoadAIScript().

430 {
431  import_stack.push_back( modulename );
432 }
void Mission::BriefingEnd ( )

Definition at line 199 of file director.cpp.

References briefing, PythonMissionBaseClass::callFunction(), Mission::Runtime::pymissions, and runtime.

Referenced by BriefingStart(), and BriefingUtil::terminate().

200 {
201  if (briefing) {
202  if (runtime.pymissions)
203  runtime.pymissions->callFunction( "endbriefing" );
204  delete briefing;
205  briefing = NULL;
206  }
207 }
bool Mission::BriefingInProgress ( )

Definition at line 157 of file director.cpp.

References briefing.

158 {
159  return briefing != NULL;
160 }
void Mission::BriefingLoop ( )

Definition at line 175 of file director.cpp.

References briefing, PythonMissionBaseClass::callFunction(), Mission::Runtime::pymissions, and runtime.

Referenced by DirectorLoop().

176 {
177  if (briefing)
178  if (runtime.pymissions)
179  runtime.pymissions->callFunction( "loopbriefing" );
180 }
class TextPlane * Mission::BriefingRender ( )

Definition at line 181 of file director.cpp.

References briefing, MessageCenter::last(), gameMessage::message, msgcenter, Briefing::Render(), TextPlane::SetText(), and Briefing::tp.

182 {
183  if (briefing) {
184  vector< std::string >who;
185  who.push_back( "briefing" );
186  string str1;
187  gameMessage g1, g2;
188  if ( msgcenter->last( 0, g1, who ) )
189  str1 = g1.message;
190  if ( msgcenter->last( 1, g2, who ) )
191  str1 = str1+string( "\n" )+g2.message;
192  briefing->tp.SetText( str1 );
193  briefing->Render();
194  return &briefing->tp;
195  }
196  return NULL;
197 }
void Mission::BriefingStart ( )

Definition at line 161 of file director.cpp.

References briefing, BriefingEnd(), PythonMissionBaseClass::callFunction(), Mission::Runtime::pymissions, and runtime.

162 {
163  if (briefing)
164  BriefingEnd();
165  briefing = new Briefing();
166  if (runtime.pymissions)
167  runtime.pymissions->callFunction( "initbriefing" );
168 }
void Mission::BriefingUpdate ( )

Definition at line 169 of file director.cpp.

References briefing, and Briefing::Update().

170 {
171  if (briefing)
172  briefing->Update();
173 }
Unit * Mission::call_unit_launch ( class CreateFlightgroup fg,
int  type,
const std::string &  destinations 
)

Definition at line 940 of file script_call_unit_generic.cpp.

References _Universe, Universe::AccessCockpit(), Unit::activeStarSystem, StarSystem::AddUnit(), Flightgroup::ainame, ASTEROIDPTR, CollideArray::begin(), StarSystem::collidemap, UnitFactory::createAsteroid(), UnitFactory::createNebula(), UnitFactory::createPlanet(), UnitFactory::createUnit(), d, Flightgroup::faction, CreateFlightgroup::fg, FactionUtil::GetFactionIndex(), Cockpit::GetParent(), getUniqueSerial(), UnitContainer::GetUnit(), GFXGetMaterial(), is_null(), Universe::isPlayerStarship(), Flightgroup::leader, Unit::LoadAIScript(), Unit::location, NEBULAPTR, Flightgroup::nr_ships, CreateFlightgroup::nr_ships, ONE, parse_alpha(), ParseDestinations(), PLANETPTR, Flightgroup::pos, Unit::PrimeOrders(), QVector, Unit::rSize(), Universe::scriptStarSystem(), Unit::SetPosAndCumPos(), Unit::SetTurretAI(), UnitContainer::SetUnit(), Unit::Target(), Flightgroup::type, Unit::UNIT_BOLT, Unit::UNIT_ONLY, Unit::UpdateCollideQueue(), Vector, and ZERO.

Referenced by DirectorShipDestroyed(), and UniverseUtil::launchJumppoint().

941 {
942  int faction_nr = FactionUtil::GetFactionIndex( fg->fg->faction );
943  Unit **units = new Unit*[fg->nr_ships];
944  int u;
945  Unit *par = _Universe->AccessCockpit()->GetParent();
946  CollideMap::iterator metahint[2] = {
949  };
950  CollideMap::iterator *hint = metahint;
951  if ( par && !is_null( par->location[Unit::UNIT_ONLY] ) && !is_null( par->location[Unit::UNIT_BOLT] )
953  hint = par->location;
954  for (u = 0; u < fg->nr_ships; u++) {
955  Unit *my_unit;
956  if (type == PLANETPTR) {
957  float radius = 1;
958  char *tex = strdup( fg->fg->type.c_str() );
959  char *nam = strdup( fg->fg->type.c_str() );
960  char *bsrc = strdup( fg->fg->type.c_str() );
961  char *bdst = strdup( fg->fg->type.c_str() );
962  char *citylights = strdup( fg->fg->type.c_str() );
963  tex[0] = '\0';
964  bsrc[0] = '\0'; //have at least 1 char
965  bdst[0] = '\0';
966  citylights[0] = '\0';
967  GFXMaterial mat;
968  GFXGetMaterial( 0, mat );
969  BLENDFUNC s = ONE;
970  BLENDFUNC d = ZERO;
971  if (bdst[0] != '\0')
972  d = parse_alpha( bdst );
973  if (bsrc[0] != '\0')
974  s = parse_alpha( bsrc );
975  my_unit = UnitFactory::createPlanet( QVector( 0, 0, 0 ), QVector( 0, 0, 0 ), 0, Vector( 0, 0, 0 ),
976  0, 0, radius, tex, "", "", s,
977  d, ParseDestinations( destinations ),
978  QVector( 0, 0, 0 ), NULL, mat,
979  vector< GFXLightLocal > (), faction_nr, nam, getUniqueSerial() );
980  free( bsrc );
981  free( bdst );
982  free( tex );
983  free( nam );
984  free( citylights );
985  } else if (type == NEBULAPTR) {
986  my_unit = UnitFactory::createNebula(
987  fg->fg->type.c_str(), false, faction_nr, fg->fg, u+fg->fg->nr_ships-fg->nr_ships, getUniqueSerial() );
988  } else if (type == ASTEROIDPTR) {
989  my_unit = UnitFactory::createAsteroid(
990  fg->fg->type.c_str(), faction_nr, fg->fg, u+fg->fg->nr_ships-fg->nr_ships, .01, getUniqueSerial() );
991  } else {
992  my_unit = UnitFactory::createUnit( fg->fg->type.c_str(), false, faction_nr, string(
993  "" ), fg->fg, u+fg->fg->nr_ships-fg->nr_ships, NULL, getUniqueSerial() );
994  }
995  units[u] = my_unit;
996  }
997  float fg_radius = units[0]->rSize();
998  Unit *my_unit;
999  for (u = 0; u < fg->nr_ships; u++) {
1000  my_unit = units[u];
1001  QVector pox;
1002  pox.i = fg->fg->pos.i+u*fg_radius*3;
1003  pox.j = fg->fg->pos.j+u*fg_radius*3;
1004  pox.k = fg->fg->pos.k+u*fg_radius*3;
1005  my_unit->SetPosAndCumPos( pox );
1006  if (type == ASTEROIDPTR || type == NEBULAPTR) {
1007  my_unit->PrimeOrders();
1008  } else {
1009  my_unit->LoadAIScript( fg->fg->ainame );
1010  my_unit->SetTurretAI();
1011  }
1012  _Universe->scriptStarSystem()->AddUnit( my_unit );
1013  my_unit->UpdateCollideQueue( _Universe->scriptStarSystem(), hint );
1014  if ( !is_null( my_unit->location[Unit::UNIT_ONLY] ) && !is_null( my_unit->location[Unit::UNIT_BOLT] ) )
1015  hint = my_unit->location;
1016  my_unit->Target( NULL );
1017  }
1018  my_unit = units[0];
1019  if ( !_Universe->isPlayerStarship( fg->fg->leader.GetUnit() ) )
1020  fg->fg->leader.SetUnit( my_unit );
1021  delete[] units;
1022  return my_unit;
1023 }
void Mission::call_vector_into_olist ( varInst vec_vi,
QVector  vec3 
)

Definition at line 234 of file script_call_olist.cpp.

References varInst::float_val, varInst::object, varInst::objectname, varInst::type, VAR_FLOAT, VAR_OBJECT, and VI_IN_OBJECT.

Referenced by AIFlyToWaypoint::AIFlyToWaypoint(), AIFlyToWaypointDefend::AIFlyToWaypointDefend(), AIPatrol::AIPatrol(), and AIPatrolDefend::AIPatrolDefend().

235 {
236  olist_t *my_object = new olist_t;
237  olist_counter++;
238 
239  vec_vi->type = VAR_OBJECT;
240  vec_vi->objectname = "olist";
241  vec_vi->object = (void*) my_object;
242 
243  varInst *push_vi;
244 
245  push_vi = newVarInst( VI_IN_OBJECT );
246  push_vi->type = VAR_FLOAT;
247  push_vi->float_val = vec3.i;
248  my_object->push_back( push_vi );
249 
250  push_vi = newVarInst( VI_IN_OBJECT );
251  push_vi->type = VAR_FLOAT;
252  push_vi->float_val = vec3.j;
253  my_object->push_back( push_vi );
254 
255  push_vi = newVarInst( VI_IN_OBJECT );
256  push_vi->type = VAR_FLOAT;
257  push_vi->float_val = vec3.k;
258  my_object->push_back( push_vi );
259 }
unsigned int Mission::createClassInstance ( string  modulename)

Definition at line 565 of file mission_script.cpp.

References missionNode::script_t::classinst_counter, missionNode::script_t::classvars, Mission::Runtime::modules, runtime, missionNode::script, SCRIPT_RUN, varInst::type, and VI_CLASSVAR.

Referenced by AImissionScript::AImissionScript().

566 {
567  missionNode *module_node = runtime.modules[modulename];
568  if (module_node == NULL) {
569  fatalError( NULL, SCRIPT_RUN, "module "+modulename+" not found" );
570  assert( 0 );
571  }
572  module_node->script.classinst_counter++;
573 
574  char buf[200];
575  sprintf( buf, "class counter for module %s : %d\n", modulename.c_str(), module_node->script.classinst_counter );
576  debug( 1, NULL, 0, buf );
577 
578  varInstMap *cvmap = new varInstMap();
579 
580  module_node->script.classvars.push_back( cvmap );
581 
582  varInstMap *cvmap0 = module_node->script.classvars[0];
583 
584  vsUMap< string, varInst* >::const_iterator iter;
585  for (iter = cvmap0->begin(); iter != cvmap0->end(); iter++) {
586  varInst *vi0 = (*iter).second;
587  string vi0_name = (*iter).first;
588 
589  varInst *vi = newVarInst( VI_CLASSVAR );
590  vi->type = vi0->type;
591  assignVariable( vi, vi0 );
592 
593  (*cvmap)[vi0_name] = vi;
594  }
595  return module_node->script.classinst_counter;
596 }
void Mission::deleteVarInst ( varInst vi,
bool  del_local = false 
)

Definition at line 533 of file mission_script.cpp.

References varInst::scopetype, VI_CLASSVAR, VI_CONST, VI_ERROR, VI_GLOBAL, VI_IN_OBJECT, VI_LOCAL, and VI_MODULE.

Referenced by AImissionScript::Execute(), and runScript().

534 {
535  if (vi == NULL)
536  return;
537  if (vi->scopetype == VI_GLOBAL || vi->scopetype == VI_MODULE || vi->scopetype == VI_CLASSVAR) {
538  debug( 12, NULL, 0, "reqested to delete global/module vi\n" );
539  } else if (vi->scopetype == VI_ERROR) {
540  debug( 2, NULL, 0, "reqested to delete vi_error\n" );
541  } else if (del_local == false && vi->scopetype == VI_IN_OBJECT) {
542  //debug(2,NULL,0,"reqested to delete vi in object\n");
543  } else if (vi->scopetype == VI_CONST) {
544  debug( 12, NULL, 0, "reqested to delete const vi\n" );
545  } else if (del_local == false && vi->scopetype == VI_LOCAL) {
546  debug( 12, NULL, 0, "reqested to delete local vi\n" );
547  } else {
548  delete vi;
549  vi_counter--;
550  }
551 }
void Mission::destroyClassInstance ( string  modulename,
unsigned int  classid 
)

Definition at line 598 of file mission_script.cpp.

References missionNode::script_t::classvars, Mission::Runtime::modules, runtime, missionNode::script, and SCRIPT_RUN.

Referenced by AImissionScript::~AImissionScript().

599 {
600  missionNode *module = runtime.modules[modulename];
601  if (module == NULL) {
602  fatalError( NULL, SCRIPT_RUN, "module "+modulename+" not found" );
603  assert( 0 );
604  }
605  if ( classid >= module->script.classvars.size() ) {
606  fatalError( module, SCRIPT_RUN, "illegal classvar nr." );
607  assert( 0 );
608  }
609  printf( "destroying class instance %s:%d\n", modulename.c_str(), classid );
610  varInstMap *cvmap = module->script.classvars[classid];
611 
612  deleteVarMap( cvmap );
613 
614  module->script.classvars[classid] = NULL;
615 }
void Mission::DirectorBenchmark ( )

Definition at line 209 of file director.cpp.

References benchmark, gametime, and winsys_exit().

210 {
211  total_nr_frames++;
212  if (benchmark > 0.0 && benchmark < gametime) {
213  std::cout<<"Game was running for "<<gametime<<" secs, av. framerate "<<( (double) total_nr_frames )/gametime
214  <<std::endl;
215  winsys_exit( 0 );
216  }
217 }
void Mission::DirectorEnd ( )

Definition at line 96 of file director.cpp.

References RunDirectorScript().

97 {
98  if (director == NULL)
99  return;
100  RunDirectorScript( "endgame" );
101 }
void Mission::DirectorInitgame ( )

Definition at line 506 of file director_generic.cpp.

References _Universe, Universe::CurrentCockpit(), pythonMission::FactoryString(), player_num, Mission::Runtime::pymissions, RunDirectorScript(), runtime, and PythonMissionBaseClass::UnPickle().

Referenced by createObjects().

507 {
509  if (nextpythonmission) {
510  //CAUSES AN UNRESOLVED EXTERNAL SYMBOL FOR PythonClass::last_instance ?!?!
511 #ifndef _WIN32
512  char *tmp = nextpythonmission;
513  while (*tmp) {
514  if (tmp[0] == '\r') tmp[0] = '\n';
515  tmp++;
516  }
517 #endif
518  runtime.pymissions = ( pythonMission::FactoryString( nextpythonmission ) );
519  delete[] nextpythonmission; //delete the allocated memory
520  nextpythonmission = NULL;
521  if ( !this->unpickleData.empty() ) {
522  if (runtime.pymissions) {
523  runtime.pymissions->UnPickle( unpickleData );
524  unpickleData = "";
525  }
526  }
527  }
528  if (director == NULL)
529  return;
530  RunDirectorScript( "initgame" );
531 }
void Mission::DirectorLoop ( )

Definition at line 75 of file director.cpp.

References BriefingLoop(), PythonMissionBaseClass::Execute(), gametime, getTimeCompression(), Mission::Runtime::pymissions, runtime, and SIMULATION_ATOM.

76 {
77  double oldgametime = gametime;
78  gametime += SIMULATION_ATOM; //elapsed;
79  if (getTimeCompression() >= .1)
80  if (gametime <= oldgametime)
82  try {
83  BriefingLoop();
84  if (runtime.pymissions)
86  }
87  catch (...) {
88  if ( PyErr_Occurred() ) {
89  PyErr_Print();
90  PyErr_Clear();
91  fflush( stderr );
92  fflush( stdout );
93  } throw;
94  }
95 }
void Mission::DirectorShipDestroyed ( Unit unit)

Definition at line 103 of file director.cpp.

References MessageCenter::add(), call_unit_launch(), Flightgroup::faction, CreateFlightgroup::fg, Order::findOrderList(), Unit::getAIState(), Unit::getFgSubnumber(), Unit::getFlightgroup(), Order::getOrderList(), mission, msgcenter, Flightgroup::name, Flightgroup::nr_ships, CreateFlightgroup::nr_ships, Flightgroup::nr_ships_left, Flightgroup::nr_waves_left, Flightgroup::orderlist, Flightgroup::pos, Unit::Position(), Flightgroup::type, CreateFlightgroup::UNIT, UNITPTR, CreateFlightgroup::unittype, VSFileSystem::vs_dprintf(), and CreateFlightgroup::waves.

Referenced by GameUnit< UnitType >::Explode().

104 {
105  Flightgroup *fg = unit->getFlightgroup();
106  if (fg == NULL) {
107  printf( "ship destroyed-no flightgroup\n" );
108  return;
109  }
110  if (fg->nr_ships_left <= 0 && fg->nr_waves_left > 0) {
111  printf( "WARNING: nr_ships_left<=0\n" );
112  return;
113  }
114  fg->nr_ships_left -= 1;
115 
116  char buf[512];
117 
118  if ( (fg->faction.length()+fg->type.length()+fg->name.length()+12+30) < sizeof (buf) )
119  sprintf( buf, "Ship destroyed: %s:%s:%s-%d", fg->faction.c_str(), fg->type.c_str(),
120  fg->name.c_str(), unit->getFgSubnumber() );
121  else
122  sprintf( buf, "Ship destroyed: (ERROR)-%d", unit->getFgSubnumber() );
123 
124  msgcenter->add( "game", "all", buf );
125 
126  if (fg->nr_ships_left == 0) {
127  VSFileSystem::vs_dprintf( 2, "no ships left in fg %s\n", fg->name.c_str() );
128  if (fg->nr_waves_left > 0) {
129  //sprintf( buf, "Relaunching %s wave", fg->name.c_str() ); FIXME
130  //mission->msgcenter->add( "game", "all", buf );
131  VSFileSystem::vs_dprintf( 1, "Relaunching %s wave", fg->name.c_str() );
132 
133  //launch new wave
134  fg->nr_waves_left -= 1;
135  fg->nr_ships_left = fg->nr_ships;
136 
137  Order *order = NULL;
138  order = unit->getAIState() ? unit->getAIState()->findOrderList() : NULL;
139  fg->orderlist = NULL;
140  if (order) {
141  fg->orderlist = order->getOrderList();
142  }
144  cf.fg = fg;
146  cf.fg->pos = unit->Position();
147  cf.waves = fg->nr_waves_left;
148  cf.nr_ships = fg->nr_ships;
149 
150  call_unit_launch( &cf, UNITPTR, string( "" ) );
151  } else {
152  mission->msgcenter->add( "game", "all", "Flightgroup "+fg->name+" destroyed" );
153  }
154  }
155 }
void Mission::DirectorStart ( missionNode node)

Definition at line 452 of file director_generic.cpp.

References easyDomNode::attr_value(), Mission::Runtime::cur_thread, VegaConfig::getVariable(), loadMissionModules(), Mission::Runtime::modules, XMLSupport::parse_bool(), PARSE_DECL, PARSE_FULL, runtime, SCRIPT_PARSE, Mission::Runtime::thread_nr, Mission::Runtime::threads, and vs_config.

453 {
454  cout<<"DIRECTOR START"<<endl;
455 
456  static int st_debuglevel = atoi( vs_config->getVariable( "interpreter", "debuglevel", "0" ).c_str() );
457  static bool st_start_game = XMLSupport::parse_bool( vs_config->getVariable( "interpreter", "startgame", "true" ) );
458  static bool st_do_trace = XMLSupport::parse_bool( vs_config->getVariable( "interpreter", "trace", "false" ) );
459 
460  debuglevel = st_debuglevel;
461  start_game = st_start_game;
462  do_trace = st_do_trace;
463 
464  vi_counter = 0;
465  old_vi_counter = 0;
466 
467  olist_counter = 0;
468  old_olist_counter = 0;
469 
470  string_counter = 0;
471  old_string_counter = 0;
472  missionThread *main_thread = new missionThread;
473  runtime.thread_nr = 0;
474  runtime.threads.push_back( main_thread );
475  runtime.cur_thread = main_thread;
476 
477  director = NULL;
478  std::string doparse = node->attr_value( "do_parse" );
479  if ( !doparse.empty() )
480  if (XMLSupport::parse_bool( doparse ) == false)
481  return;
482  cout<<"parsing declarations for director"<<endl;
483 
484  parsemode = PARSE_DECL;
485 
486  doModule( node, SCRIPT_PARSE );
487 
488  importf = new easyDomFactory< missionNode > ();
489 
491 
492  parsemode = PARSE_FULL;
493 
494  doModule( node, SCRIPT_PARSE );
495 
496  vsUMap< string, missionNode* >::iterator iter;
497  for (iter = runtime.modules.begin(); iter != runtime.modules.end(); iter++) {
498  string mname = (*iter).first;
499  missionNode *mnode = (*iter).second;
500  if (mname != "director") {
501  cout<<" parsing full module "<<mname<<endl;
502  doModule( mnode, SCRIPT_PARSE );
503  }
504  }
505 }
void Mission::DirectorStartStarSystem ( StarSystem ss)

Definition at line 434 of file director_generic.cpp.

References RunDirectorScript().

Referenced by Universe::Generate2().

435 {
436  RunDirectorScript( "initstarsystem" );
437 }
Flightgroup * Mission::findFlightgroup ( const string &  fg_name,
const string &  faction 
)

Definition at line 472 of file mission.cpp.

References flightgroups.

Referenced by Flightgroup::newFlightgroup(), UnitFactory::parseAsteroidBuffer(), UnitFactory::parseNebulaBuffer(), and UnitFactory::parseUnitBuffer().

473 {
474  vector< Flightgroup* >::const_iterator siter;
475  for (siter = flightgroups.begin(); siter != flightgroups.end(); siter++)
476  if ( (*siter)->name == offset_name && (fac.empty() || (*siter)->faction == fac) )
477  return *siter;
478  return NULL;
479 }
Mission * Mission::getNthPlayerMission ( int  cp,
int  num 
)
static

Definition at line 212 of file mission.cpp.

References active_missions.

Referenced by LoadMission(), SaveGame::LoadSavedMissions(), NetClient::logout(), and NetServer::sendKill().

213 {
214  vector< Mission* > *active_missions = ::active_missions.Get();
215  Mission *activeMis = NULL;
216  if (missionnum >= 0) {
217  int num = -1;
218  vector< Mission* >::iterator pl = active_missions->begin();
219  if ( pl == active_missions->end() ) return NULL;
220  for (; pl != active_missions->end(); ++pl) {
221  if ( (*pl)->player_num == (unsigned int) cp )
222  num++;
223  if (num == missionnum) {
224  //Found it!
225  activeMis = (*pl);
226  break;
227  }
228  }
229  }
230  return activeMis;
231 }
void Mission::GetOrigin ( QVector pos,
string &  planetname 
)

Definition at line 303 of file mission.cpp.

References easyDomNode::attr_value().

Referenced by bootstrap_main_loop(), and createObjects().

304 {
305  if (origin_node == NULL) {
306  pos.i = pos.j = pos.k = 0.0;
307  planetname = string();
308  return;
309  }
310  bool ok = doPosition( origin_node, &pos.i, NULL );
311  if (!ok)
312  pos.i = pos.j = pos.k = 0.0;
313  planetname = origin_node->attr_value( "planet" );
314 }
int Mission::getPlayerMissionNumber ( )

Definition at line 191 of file mission.cpp.

References active_missions.

Referenced by BaseComputer::acceptMission(), NetServer::sendSaveData(), and terminateMission().

192 {
193  int num = 0;
194 
195  vector< Mission* > *active_missions = ::active_missions.Get();
196  vector< Mission* >::iterator pl = active_missions->begin();
197 
198  if ( pl == active_missions->end() )
199  return -1;
200 
201  for (; pl != active_missions->end(); ++pl) {
202  if ( (*pl)->player_num == this->player_num ) {
203  if (*pl == this)
204  return (int)num;
205  else
206  num++;
207  }
208  }
209 
210  return -1;
211 }
string Mission::getVariable ( string  name,
string  defaultval 
)

Definition at line 507 of file mission.cpp.

References easyDomNode::subnodes.

Referenced by bootstrap_main_loop(), createObjects(), IncrementStartupVariable(), initMission(), and Cockpit::Update().

508 {
509  vector< easyDomNode* >::const_iterator siter;
510  for (siter = variables->subnodes.begin(); siter != variables->subnodes.end(); siter++) {
511  string scan_name = (*siter)->attr_value( "name" );
512  if (scan_name == name)
513  return (*siter)->attr_value( "value" );
514  }
515  return defaultval;
516 }
void Mission::initMission ( bool  loadscripts = true)

Definition at line 125 of file mission.cpp.

References getVariable(), mission_name, and msgcenter.

Referenced by bootstrap_main_loop(), and NetServer::start().

126 {
127  if (!top)
128  return;
129  if (msgcenter == NULL)
130  msgcenter = new MessageCenter();
131  checkMission( top, loadscripts );
132  mission_name = getVariable( "mission_name", "" );
133 }
void Mission::loadMissionModules ( )

Definition at line 383 of file director_generic.cpp.

References loadModule(), Mission::Runtime::modules, runtime, and SCRIPT_PARSE.

Referenced by DirectorStart().

384 {
385  missionNode *node = director;
386  while (import_stack.size() > 0) {
387  string importname = import_stack.back();
388  import_stack.pop_back();
389 
390  missionNode *module = runtime.modules[importname];
391  if (module == NULL)
392  loadModule( importname );
393  else
394  debug( 3, node, SCRIPT_PARSE, "already have module "+importname );
395  }
396 }
void Mission::loadModule ( string  modulename)

Definition at line 368 of file director_generic.cpp.

References easyDomFactory< domNodeType >::LoadXML(), SCRIPT_PARSE, and tagDomNode::Tag().

Referenced by loadMissionModules().

369 {
370  missionNode *node = director;
371 
372  debug( 3, node, SCRIPT_PARSE, "loading module "+modulename );
373 
374  cout<<" loading module "<<modulename<<endl;
375 
376  string filename = "modules/"+modulename+".module";
377  missionNode *import_top = importf->LoadXML( filename.c_str() );
378  if (import_top == NULL) {}
379  import_top->Tag( &tagmap );
380 
381  doModule( import_top, SCRIPT_PARSE );
382 }
varInst * Mission::lookupClassVariable ( string  modulename,
string  varname,
unsigned int  classid 
)

Definition at line 182 of file script_variables.cpp.

References missionNode::script_t::classvars, Mission::Runtime::modules, missionNode::script_t::name, runtime, missionNode::script, and SCRIPT_RUN.

Referenced by AIFlyToJumppoint::AIFlyToJumppoint(), AIFlyToWaypoint::AIFlyToWaypoint(), AIFlyToWaypointDefend::AIFlyToWaypointDefend(), AIOrderList::AIOrderList(), AIPatrol::AIPatrol(), AIPatrolDefend::AIPatrolDefend(), and AImissionScript::Execute().

183 {
184  missionNode *module = runtime.modules[modulename];
185  string mname = module->script.name;
186  if (classid == 0)
187  //no class instance
188  return NULL;
189  if ( classid >= module->script.classvars.size() ) {
190  fatalError( module, SCRIPT_RUN, "illegal classvar nr." );
191  assert( 0 );
192  }
193  varInstMap *cvmap = module->script.classvars[classid];
194 
195  varInst *var = (*cvmap)[varname];
196  return var;
197 }
std::string Mission::Pickle ( )

Definition at line 439 of file director_generic.cpp.

References PythonMissionBaseClass::Pickle(), Mission::Runtime::pymissions, and runtime.

440 {
441  if (!runtime.pymissions)
442  return "";
443  else
444  return runtime.pymissions->Pickle();
445 }
void Mission::RunDirectorScript ( const string &  script)

Definition at line 398 of file director_generic.cpp.

References runScript().

Referenced by DirectorEnd(), DirectorInitgame(), and DirectorStartStarSystem().

399 {
400  runScript( director, script, 0 );
401 }
bool Mission::runScript ( string  modulename,
const string &  scriptname,
unsigned int  classid = 0 
)

Definition at line 420 of file director_generic.cpp.

References Mission::Runtime::modules, and runtime.

Referenced by AImissionScript::Execute(), RunDirectorScript(), and AImissionScript::~AImissionScript().

421 {
422  return runScript( runtime.modules[modulename], scriptname, classid );
423 }
bool Mission::runScript ( missionNode module_node,
const string &  scriptname,
unsigned int  classid = 0 
)

Definition at line 402 of file director_generic.cpp.

References missionThread::classid_stack, Mission::Runtime::cur_thread, deleteVarInst(), missionThread::module_stack, runtime, missionNode::script, SCRIPT_RUN, and missionNode::script_t::scripts.

403 {
404  if (module_node == NULL)
405  return false;
406  missionNode *script_node = module_node->script.scripts[scriptname];
407  if (script_node == NULL)
408  return false;
409  runtime.cur_thread->module_stack.push_back( module_node );
410  runtime.cur_thread->classid_stack.push_back( classid );
411 
412  varInst *vi = doScript( script_node, SCRIPT_RUN );
413  deleteVarInst( vi );
414 
415  runtime.cur_thread->classid_stack.pop_back();
416  runtime.cur_thread->module_stack.pop_back();
417  return true;
418 }
void Mission::setCurrentAIOrder ( Order order)
inline

Definition at line 525 of file mission.h.

Referenced by AImissionScript::Execute().

526  {
527  current_ai_order = order;
528  }
void Mission::setCurrentAIUnit ( Unit unit)
inline

Definition at line 521 of file mission.h.

Referenced by AImissionScript::Execute().

522  {
523  current_ai_unit = unit;
524  }
void Mission::SetUnpickleData ( std::string  dat)
inline

Definition at line 462 of file mission.h.

463  {
464  unpickleData = dat;
465  }
void Mission::terminateMission ( )

Definition at line 232 of file mission.cpp.

References _Universe, Universe::AccessCockpit(), active_missions, PythonMissionBaseClass::Destroy(), f, g_game, SaveGame::getMissionStringData(), getPlayerMissionNumber(), mission_name, Network, player_num, Mission::Runtime::pymissions, runtime, Cockpit::savegame, NetServer::sendMission(), SERVER, size, Subcmd::TerminateMission, VSFileSystem::vs_dprintf(), game_data_t::vsdebug, and VSServer.

Referenced by BaseComputer::acceptMission(), NetClient::logout(), NetServer::sendKill(), and UniverseUtil::terminateMission().

233 {
234  vector< Mission* > *active_missions = ::active_missions.Get();
235  vector< Mission* >::iterator f;
236 
237  f = std::find( Mission_delqueue.begin(), Mission_delqueue.end(), this );
238  if (f != Mission_delqueue.end())
239  VSFileSystem::vs_dprintf( 1, "Not deleting mission twice: %s\n", this->mission_name.c_str() );
240 
241  f = std::find( active_missions->begin(), active_missions->end(), this );
242 
243  // Debugging aid for persistent missions bug
244  if (g_game.vsdebug >= 1) {
245  int misnum = -1;
246  for (vector< Mission* >::iterator i = active_missions->begin(); i != active_missions->end(); ++i) {
247  if ((*i)->player_num == player_num) {
248  ++misnum;
249  VSFileSystem::vs_dprintf( 1, " Mission #%d: %s\n", misnum, (*i)->mission_name.c_str() );
250  }
251  }
252  }
253 
254  int queuenum = -1;
255  if ( f != active_missions->end() ) {
256  queuenum = getPlayerMissionNumber(); //-1 used as error code, 0 is first player mission
257  if ( (Network != NULL || SERVER) && player_num >= 0 ) {
258  int num = queuenum;
259  if (num >= 0)
260  if (SERVER && num > 0)
262  }
263  active_missions->erase( f );
264  }
265  if (this != (*active_missions)[0]) //Shouldn't this always be true?
266  Mission_delqueue.push_back( this ); //only delete if we arent' the base mission
267  //NETFIXME: This routine does not work properly yet.
268  VSFileSystem::vs_dprintf( 1, "Terminating mission %s #%d\n", this->mission_name.c_str(), queuenum );
269  if (queuenum >= 0) {
270  // queuenum - 1 since mission #0 is the base mission (main_menu) and is persisted
271  // in savegame.cpp:LoadSavedMissions, and it has no correspondin active_scripts/active_missions entry,
272  // meaning the actual active_scripts index is offset by 1.
273  unsigned int num = queuenum - 1;
274 
275  vector< std::string > *scripts = &_Universe->AccessCockpit( player_num )->savegame->getMissionStringData(
276  "active_scripts" );
277  VSFileSystem::vs_dprintf( 1, "Terminating mission #%d - got %d scripts\n", queuenum, scripts->size() );
278  if ( num < scripts->size() )
279  scripts->erase( scripts->begin()+num );
280  vector< std::string > *missions = &_Universe->AccessCockpit( player_num )->savegame->getMissionStringData(
281  "active_missions" );
282  VSFileSystem::vs_dprintf( 1, "Terminating mission #%d - got %d missions\n", queuenum, missions->size() );
283  if ( num < missions->size() )
284  missions->erase( missions->begin()+num );
285  VSFileSystem::vs_dprintf( 1, "Terminating mission #%d - %d scripts remain\n", queuenum, scripts->size() );
286  VSFileSystem::vs_dprintf( 1, "Terminating mission #%d - %d missions remain\n", queuenum, missions->size() );
287  }
288  if (runtime.pymissions)
290  runtime.pymissions = NULL;
291 }
void Mission::UnPickle ( std::string  pickled)

Definition at line 446 of file director_generic.cpp.

References Mission::Runtime::pymissions, runtime, and PythonMissionBaseClass::UnPickle().

447 {
448  if (runtime.pymissions)
449  runtime.pymissions->UnPickle( pickled );
450 }
void Mission::wipeDeletedMissions ( )
static

Definition at line 183 of file mission.cpp.

184 {
185  while ( !Mission_delqueue.empty() ) {
186  delete Mission_delqueue.back();
187  Mission_delqueue.pop_back();
188  }
189 }

Friends And Related Function Documentation

void UnpickleMission ( std::string  pickled)
friend

Definition at line 119 of file load_mission.cpp.

120 {
121  std::string file = PickledDataOnlyMissionName( pickled );
122  pickled = PickledDataSansMissionName( pickled );
123  if ( pickled.length() ) {
124  active_missions.push_back( new Mission( file.c_str() ) );
125  active_missions.back()->initMission();
126  active_missions.back()->SetUnpickleData( pickled );
127  }
128 }

Member Data Documentation

vector< Flightgroup * > Mission::flightgroups
static

Definition at line 489 of file mission.h.

Referenced by AddFlightgroup(), createObjects(), and findFlightgroup().

double Mission::gametime = 0.0
static

Definition at line 467 of file mission.h.

Referenced by DirectorBenchmark(), DirectorLoop(), UniverseUtil::GetGameTime(), and getGametime().

MISSION_AUTO Mission::global_autopilot

Definition at line 440 of file mission.h.

Referenced by UniverseUtil::SetAutoStatus().

string Mission::mission_name

Definition at line 468 of file mission.h.

Referenced by initMission(), and terminateMission().

int Mission::number_of_flightgroups = 0
static

Definition at line 486 of file mission.h.

Referenced by AddFlightgroup().

int Mission::number_of_ships = 0
static

Definition at line 487 of file mission.h.

Referenced by createObjects(), and UniverseUtil::launchJumppoint().

MISSION_AUTO Mission::player_autopilot

Definition at line 439 of file mission.h.

Referenced by UniverseUtil::SetAutoStatus().


The documentation for this class was generated from the following files: