19 typedef std::pair< std::string, CCScript* >MyPair;
24 tmp.insert( MyPair(
"loop around", &
LoopAround ) );
26 tmp.insert( MyPair(
"barrel roll", &
BarrelRoll ) );
27 tmp.insert( MyPair(
"veer away", &
VeerAway ) );
34 tmp.insert( MyPair(
"fly straight", &
FlyStraight ) );
37 tmp.insert( MyPair(
"do nothing", &
DoNothing ) );
38 tmp.insert( MyPair(
"take off", &
Takeoff ) );
39 tmp.insert( MyPair(
"coast to stop", &
CoastToStop ) );
46 tmp.insert( MyPair(
"kick stop", &
Kickstop ) );
47 tmp.insert( MyPair(
"move to", &
MoveTo ) );
49 tmp.insert( MyPair(
"skilled afterburner slide", &
SkilledABSlide ) );
51 tmp.insert( MyPair(
"stop", &
Stop ) );
52 tmp.insert( MyPair(
"turn away", &
TurnAway ) );
54 tmp.insert( MyPair(
"turn towards", &
TurnTowards ) );
56 tmp.insert( MyPair(
"drop cargo", &
DropCargo ) );
59 tmp.insert( MyPair(
"roll right", &
RollRight ) );
61 tmp.insert( MyPair(
"roll left", &
RollLeft ) );
64 tmp.insert( MyPair(
"evade up down", &
EvadeUpDown ) );
73 if (tmp.find(
"roll perpendicular fast")==tmp.end()){
82 if (s.length() == 0)
return true;
100 float& AIScript::topf()
102 if ( !xml->
floats.size() ) {
108 void AIScript::popf()
110 if (xml->
floats.size() <= 0) {
121 "\nERROR: Vector stack is empty... Will return <%f, %f, %f>\n",
128 void AIScript::popv()
130 if (xml->
vectors.size() <= 0) {
137 void AIScript::beginElement(
void *userData,
const XML_Char *name,
const XML_Char **atts )
142 void AIScript::endElement(
void *userData,
const XML_Char *name )
144 ( (
AIScript*) userData )->endElement( name );
267 void AIScript::beginElement(
const string &name,
const AttributeList &attributes )
269 using namespace AiXml;
279 AttributeList::const_iterator iter;
296 xml->vectors.push(
QVector( 0, 0, 0 ) );
297 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
314 xml->vectors.push( xml->vectors.top() );
318 topv() = ( tmp->Position() );
321 topv() = ( tmp->Position() );
323 topv() = (xml->defaultvec);
328 topv() = ( tmp->Position() );
330 topv() = (xml->defaultvec);
339 topv() = ( tmp->GetVelocity() );
342 topv() = ( tmp->GetVelocity() );
344 topv() = (xml->defaultvec);
349 topv() = ( tmp->GetVelocity() );
351 topv() = (xml->defaultvec);
363 xml->afterburn =
true;
364 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
382 xml->afterburn =
true;
383 xml->terminate =
true;
384 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
407 xml->afterburn =
true;
408 xml->terminate =
true;
409 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
461 xml->floats.push( 0 );
462 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
472 xml->floats.push( xml->floats.top() );
486 xml->afterburn =
false;
487 xml->terminate =
true;
488 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
509 xml->executefor.push_back( 0 );
510 xml->terminate =
true;
511 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
518 xml->executefor.back() =
parse_float( (*iter).value );
525 xml->executefor.push_back( 0 );
526 for (iter = attributes.begin(); iter != attributes.end(); iter++) {
530 xml->executefor.back() =
parse_float( (*iter).value );
542 void AIScript::endElement(
const string &name )
544 using namespace AiXml;
557 xml->vectors.push( tmp->ToWorldCoordinates( topv() ) );
560 xml->vectors.push( tmp->ToWorldCoordinates( topv() ) );
562 xml->vectors.push( xml->defaultvec );
568 xml->vectors.push( tmp->ToLocalCoordinates( topv() ) );
571 xml->vectors.push( tmp->ToLocalCoordinates( topv() ) );
573 xml->vectors.push( xml->defaultvec );
580 xml->vectors.push( tmp->ToWorldCoordinates( topv() ) );
582 xml->vectors.push( xml->defaultvec );
587 xml->vectors.push( tmp->ToLocalCoordinates( topv() ) );
589 xml->vectors.push( xml->defaultvec );
602 if (topv().i || topv().j || topv().k)
614 topv() = CrossProduct( topv(), temp );
618 xml->floats.push( 0 );
642 xml->vectors.push(
QVector( temp.i, temp.j, topf() ) );
647 xml->floats.push( topv().i );
648 xml->floats.push( topv().j );
649 xml->floats.push( topv().k );
662 topv() = topv()-temp;
671 xml->orders.push_back(
new Orders::MoveTo( topv(), xml->afterburn, xml->acc ) );
697 xml->afterburn ), ( (
bool) xml->acc ),
698 xml->afterburn, xml->terminate ) );
714 xml->afterburn, xml->terminate ) );
721 if ( !xml->executefor.empty() ) {
722 if (xml->executefor.back() > 0) {
723 xml->orders[xml->orders.size()-1] =
new Orders::ExecuteFor( xml->orders[xml->orders.size()-1], xml->executefor.back() );
724 xml->executefor.pop_back();
730 if ( !xml->executefor.empty() ) {
731 xml->orders.push_back(
new CloakFor( xml->terminate, xml->executefor.back() ) );
732 xml->executefor.pop_back();
737 xml->defaultvec = topv();
739 xml->defaultf = topf();
748 void AIScript::LoadXML()
751 using namespace AiXml;
752 using namespace VSFileSystem;
753 string full_filename = filename;
756 if (iter==
hard_coded_scripts.end() && full_filename.length() > 5 && full_filename[0] ==
'r' && full_filename[1] ==
'o' && full_filename[2] ==
'l'
757 && full_filename[3] ==
'l' && full_filename[4] ==
' ') {
759 full_filename = full_filename.substr( 5 );
763 CCScript *myscript = (*iter).second;
764 (*myscript)(
this,
parent);
766 unsigned int val = rand();
767 if (val < RAND_MAX/4)
769 else if (val < RAND_MAX/2)
787 float pdmag = PosDifference.Magnitude();
795 value /= game_speed*game_accel;
836 xml->terminate =
true;
837 xml->afterburn =
true;
839 xml->defaultvec =
QVector( 0, 0, 0 );
844 XML_Parser parser = XML_ParserCreate( NULL );
848 XML_SetUserData( parser,
this );
852 XML_SetElementHandler( parser, &AIScript::beginElement, &AIScript::endElement );
856 XML_Parse( parser, (
f.ReadFull() ).c_str(),
f.Size(), 1 );
861 XML_ParserFree( parser );
866 for (
unsigned int i = 0;
i < xml->orders.size();
i++) {
870 xml->orders[
i]->SetParent(
parent );
889 filename =
new char[strlen( scriptname )+1];
890 strcpy( filename, scriptname );