62 int Mission:: total_nr_frames = 0;
67 ConstructMission( filename, script, loadscripts );
71 ConstructMission( filename,
string(
"" ), loadscripts );
73 void Mission::ConstructMission(
const char *configfile,
const std::string &script,
bool loadscripts )
80 nextpythonmission = NULL;
81 if (script.length() > 0) {
82 nextpythonmission =
new char[script.length()+2];
83 nextpythonmission[script.length()+1] = 0;
84 nextpythonmission[script.length()] = 0;
85 strcpy( nextpythonmission, script.c_str() );
89 top = domf->
LoadXML( configfile );
90 static bool dontpanic =
false;
91 if (top == NULL && !dontpanic) {
92 cout<<
"Panic exit - mission file "<<configfile<<
" not found"<<endl;
131 checkMission( top, loadscripts );
137 bool Mission::checkMission(
easyDomNode *node,
bool loadscripts )
139 if (node->
Name() !=
"mission") {
140 cout<<
"this is no Vegastrike mission file"<<endl;
143 vector< easyDomNode* >::const_iterator siter;
144 for (siter = node->
subnodes.begin(); siter != node->
subnodes.end(); siter++) {
145 if ( (*siter)->Name() ==
"variables" ) {
146 doVariables( *siter );
147 }
else if ( ( (*siter)->Name() ==
"flightgroups" ) ) {
148 doFlightgroups( *siter );
149 }
else if ( ( (*siter)->Name() ==
"settings" ) ) {
150 doSettings( *siter );
151 }
else if ( ( (*siter)->Name() ==
"module" ) ) {
154 }
else if ( ( (*siter)->Name() ==
"python" ) && (!this->nextpythonmission) ) {
156 string locals = (*siter)->attr_value(
textAttr );
157 const char *constdumbstr = locals.c_str();
158 int i = strlen( constdumbstr );
159 char *dumbstr =
new char[i+2];
160 strncpy( dumbstr, constdumbstr, i );
163 for (i -= 1; i >= 0; i--) {
165 if (dumbstr[i] ==
'\t' || dumbstr[i] ==
' ' || dumbstr[i] ==
'\r' || dumbstr[i] ==
'\n') {
174 this->nextpythonmission = dumbstr;
176 cout<<
"warning: Unknown tag: "<<(*siter)->Name()<<endl;
185 while ( !Mission_delqueue.empty() ) {
186 delete Mission_delqueue.back();
187 Mission_delqueue.pop_back();
196 vector< Mission* >::iterator pl = active_missions->begin();
198 if ( pl == active_missions->end() )
201 for (; pl != active_missions->end(); ++pl) {
202 if ( (*pl)->player_num == this->player_num ) {
216 if (missionnum >= 0) {
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 )
223 if (num == missionnum) {
235 vector< Mission* >::iterator
f;
237 f = std::find( Mission_delqueue.begin(), Mission_delqueue.end(), this );
238 if (f != Mission_delqueue.end())
241 f = std::find( active_missions->begin(), active_missions->end(), this );
246 for (vector< Mission* >::iterator i = active_missions->begin(); i != active_missions->end(); ++i) {
255 if ( f != active_missions->end() ) {
263 active_missions->erase( f );
265 if (
this != (*active_missions)[0])
266 Mission_delqueue.push_back(
this );
273 unsigned int num = queuenum - 1;
278 if ( num < scripts->
size() )
279 scripts->erase( scripts->begin()+num );
283 if ( num < missions->
size() )
284 missions->erase( missions->begin()+num );
305 if (origin_node == NULL) {
306 pos.i = pos.j = pos.k = 0.0;
307 planetname = string();
310 bool ok = doPosition( origin_node, &pos.i, NULL );
312 pos.i = pos.j = pos.k = 0.0;
313 planetname = origin_node->
attr_value(
"planet" );
321 vector< easyDomNode* >::const_iterator siter;
322 for (siter = node->
subnodes.begin(); siter != node->
subnodes.end(); siter++) {
324 if (mnode->
Name() ==
"origin")
333 if (variables != NULL) {
334 cout<<
"only one variable section allowed"<<endl;
339 vector< easyDomNode* >::const_iterator siter;
340 for (siter = node->
subnodes.begin(); siter != node->
subnodes.end(); siter++)
348 if (node->
Name() !=
"var") {
349 cout<<
"not a variable"<<endl;
360 vector< easyDomNode* >::const_iterator siter;
361 for (siter = node->
subnodes.begin(); siter != node->
subnodes.end(); siter++)
362 checkFlightgroup( *siter );
372 void Mission::checkFlightgroup(
easyDomNode *node )
374 if (node->
Name() !=
"flightgroup") {
375 cout<<
"not a flightgroup"<<endl;
380 string texture_alpha = node->
attr_value(
"logo_alpha" );
386 string nr_ships = node->
attr_value(
"nr_ships" );
387 string terrain_nr = node->
attr_value(
"terrain_nr" );
388 string unittype = node->
attr_value(
"unit_type" );
389 if ( name.empty() || faction.empty() || type.empty() || ainame.empty() || waves.empty() || nr_ships.empty() ) {
390 cout<<
"no valid flightgroup decsription"<<endl;
393 if ( unittype.empty() )
394 unittype =
string(
"unit" );
395 int waves_i = atoi( waves.c_str() );
396 int nr_ships_i = atoi( nr_ships.c_str() );
398 bool have_pos =
false;
399 bool have_rot =
false;
404 rot[0] = rot[1] = rot[2] = 0.0;
407 vector< easyDomNode* >::const_iterator siter;
408 for (siter = node->
subnodes.begin(); siter != node->
subnodes.end(); siter++) {
409 if ( (*siter)->Name() ==
"pos" )
410 have_pos = doPosition( *siter, pos, &cf );
411 else if ( (*siter)->Name() ==
"rot" )
412 have_rot = doRotation( *siter, rot, &cf );
413 else if ( (*siter)->Name() ==
"order" )
414 doOrder( *siter, cf.
fg );
417 cout<<
"don;t have a position in flightgroup "<<name<<endl;
418 if ( terrain_nr.empty() ) {
421 if (terrain_nr ==
"mission")
427 if (unittype ==
"vehicle")
429 if (unittype ==
"building")
434 cf.
fg->
pos.i = pos[0];
435 cf.
fg->
pos.j = pos[1];
436 cf.
fg->
pos.k = pos[2];
437 for (
int i = 0; i < 3; i++)
440 if (ainame[0] ==
'_') {
455 if ( x.empty() || y.empty() || z.empty() ) {
456 cout<<
"no valid position"<<endl;
459 pos[0] = strtod( x.c_str(), NULL );
460 pos[1] = strtod( y.c_str(), NULL );
461 pos[2] = strtod( z.c_str(), NULL );
463 pos[0] += cf->
fg->
pos.i;
464 pos[1] += cf->
fg->
pos.j;
465 pos[2] += cf->
fg->
pos.k;
474 vector< Flightgroup* >::const_iterator siter;
476 if ( (*siter)->name == offset_name && (fac.empty() || (*siter)->faction == fac) )
496 if ( order.empty() || target.empty() ) {
497 cout<<
"you have to give an order and a target"<<endl;
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" );