Model::Model( string _name, Image* _image, string _description, Engine* _defaultEngine, float _mass, short int _thrustOffset, float _rotPerSecond, float _maxSpeed, int _hullStrength, int _shieldStrength, int _msrp, int _cargoSpace, vector<WeaponSlot>& _weaponSlots) : image(_image), defaultEngine(_defaultEngine), thrustOffset(_thrustOffset) { SetName(_name); SetDescription(_description); SetMass(_mass); SetRotationsPerSecond(_rotPerSecond); SetMaxSpeed(_maxSpeed); SetMSRP(_msrp); SetCargoSpace(_cargoSpace); SetHullStrength(_hullStrength); SetShieldStrength(_shieldStrength); ConfigureWeaponSlots(_weaponSlots); //((Component*)this)->SetName(_name); }
/**\brief Creates an empty Model object. */ Model::Model() :image(NULL) ,defaultEngine(NULL) ,thrustOffset(0) { SetName(""); SetMass(1.0f); SetRotationsPerSecond(0.2f); SetHullStrength(100); SetShieldStrength(100); SetCargoSpace(10); }
/**\brief Creates a Model with the given parameters. * \param _name Name of the ship * \param _image Image of the ship * \param _mass Mass of the ship * \param _thrustOffset For animation * \param _rotPerSecond Rotation per second * \param _maxSpeed Maximum speed * \param _hullStrength Maximum damage it can take * \param _msrp Price * \param _cargoSpace Tons of cargo space */ Model::Model( string _name, Image* _image, float _mass, short int _thrustOffset, float _rotPerSecond, float _maxSpeed, int _hullStrength, int _msrp, int _cargoSpace) : image(_image), thrustOffset(_thrustOffset) { SetName(_name); SetMass(_mass); SetRotationsPerSecond(_rotPerSecond); SetMaxSpeed(_maxSpeed); SetMSRP(_msrp); SetCargoSpace(_cargoSpace); SetHullStrength(_hullStrength); //((Component*)this)->SetName(_name); }
/**\brief For parsing XML file into fields. */ bool Model::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) { xmlNodePtr attr; string value; if( (attr = FirstChildNamed(node,"image")) ){ image = Image::Get( NodeToString(doc,attr) ); Image::Store(name, image); SetPicture(image); } else return false; if( (attr = FirstChildNamed(node,"mass")) ){ value = NodeToString(doc,attr); SetMass( static_cast<float> (atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"rotationsPerSecond")) ){ value = NodeToString(doc,attr); SetRotationsPerSecond( static_cast<float>(atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"thrustOffset")) ){ value = NodeToString(doc,attr); thrustOffset = static_cast<short>(atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"maxSpeed")) ){ value = NodeToString(doc,attr); SetMaxSpeed( static_cast<float>(atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"msrp")) ){ value = NodeToString(doc,attr); SetMSRP( (short int)atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"cargoSpace")) ){ value = NodeToString(doc,attr); SetCargoSpace( atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"hullStrength")) ){ value = NodeToString(doc,attr); SetHullStrength( (short)atoi( value.c_str() )); } else return false; return true; }
/**\brief Parses weapon information */ bool Outfit::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) { xmlNodePtr attr; string value; if( (attr = FirstChildNamed(node,"msrp")) ){ value = NodeToString(doc,attr); SetMSRP( atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"picName")) ){ Image* pic = Image::Get( NodeToString(doc,attr) ); // This image can be accessed by either the path or the Engine Name Image::Store(name, pic); SetPicture(pic); } else return false; if( (attr = FirstChildNamed(node,"rotationsPerSecond")) ){ value = NodeToString(doc,attr); SetRotationsPerSecond( static_cast<float>(atof( value.c_str() ))); } if( (attr = FirstChildNamed(node,"maxSpeed")) ){ value = NodeToString(doc,attr); SetMaxSpeed( static_cast<float>(atof( value.c_str() ))); } if( (attr = FirstChildNamed(node,"forceOutput")) ){ value = NodeToString(doc,attr); SetForceOutput( static_cast<float> (atof( value.c_str() ))); } if( (attr = FirstChildNamed(node,"mass")) ){ value = NodeToString(doc,attr); SetMass( static_cast<float> (atof( value.c_str() ))); } if( (attr = FirstChildNamed(node,"cargoSpace")) ){ value = NodeToString(doc,attr); SetCargoSpace( atoi( value.c_str() )); } if( (attr = FirstChildNamed(node,"surfaceArea")) ){ value = NodeToString(doc,attr); SetSurfaceArea( atoi( value.c_str() )); } if( (attr = FirstChildNamed(node,"cargoSpace")) ){ value = NodeToString(doc,attr); SetCargoSpace( atoi( value.c_str() )); } if( (attr = FirstChildNamed(node,"hullStrength")) ){ value = NodeToString(doc,attr); SetHullStrength( atoi( value.c_str() )); } if( (attr = FirstChildNamed(node,"shildStrength")) ){ value = NodeToString(doc,attr); SetShieldStrength( (short)atoi( value.c_str() )); } return true; }
/**\brief For parsing XML file into fields. */ bool Model::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) { xmlNodePtr attr; string value; if( (attr = FirstChildNamed(node,"image")) ){ image = Image::Get( NodeToString(doc,attr) ); Image::Store(name, image); SetPicture(image); } else return false; if( (attr = FirstChildNamed(node,"mass")) ){ value = NodeToString(doc,attr); SetMass( static_cast<float> (atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"rotationsPerSecond")) ){ value = NodeToString(doc,attr); SetRotationsPerSecond( static_cast<float>(atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"thrustOffset")) ){ value = NodeToString(doc,attr); thrustOffset = static_cast<short>(atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"maxSpeed")) ){ value = NodeToString(doc,attr); SetMaxSpeed( static_cast<float>(atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"msrp")) ){ value = NodeToString(doc,attr); SetMSRP( (short int)atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"cargoSpace")) ){ value = NodeToString(doc,attr); SetCargoSpace( atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"hullStrength")) ){ value = NodeToString(doc,attr); SetHullStrength( (short)atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"shieldStrength")) ){ value = NodeToString(doc,attr); SetShieldStrength( (short)atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"weaponSlots")) ){ // pass the weaponSlots XML node into a handler function ConfigureWeaponSlots( doc, attr ); } else { cout << "Model::FromXMLNode(): Did not find weapon slot configuration - assuming defaults." << endl; // with no parameters, it sets default values ConfigureWeaponSlots(); } return true; }
/**\brief For parsing XML file into fields. */ bool Model::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) { xmlNodePtr attr; string value; if( (attr = FirstChildNamed(node,"image")) ){ image = Image::Get( NodeToString(doc,attr) ); Image::Store(name, image); SetPicture(image); } else return false; if( (attr = FirstChildNamed(node,"description")) ){ value = NodeToString(doc,attr); SetDescription( value ); } else { LogMsg( WARN, "%s does not have a description.", GetName().c_str() ); } if( (attr = FirstChildNamed(node,"engine")) ){ defaultEngine = Menu::GetCurrentScenario()->GetEngines()->GetEngine( NodeToString(doc,attr) ); } else return false; if( (attr = FirstChildNamed(node,"mass")) ){ value = NodeToString(doc,attr); SetMass( static_cast<float> (atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"rotationsPerSecond")) ){ value = NodeToString(doc,attr); SetRotationsPerSecond( static_cast<float>(atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"thrustOffset")) ){ value = NodeToString(doc,attr); thrustOffset = static_cast<short>(atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"maxSpeed")) ){ value = NodeToString(doc,attr); SetMaxSpeed( static_cast<float>(atof( value.c_str() ))); } else return false; if( (attr = FirstChildNamed(node,"msrp")) ){ value = NodeToString(doc,attr); SetMSRP( (short int)atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"cargoSpace")) ){ value = NodeToString(doc,attr); SetCargoSpace( atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"hullStrength")) ){ value = NodeToString(doc,attr); SetHullStrength( (short)atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"shieldStrength")) ){ value = NodeToString(doc,attr); SetShieldStrength( (short)atoi( value.c_str() )); } else return false; if( (attr = FirstChildNamed(node,"weaponSlots")) ){ // pass the weaponSlots XML node into a handler function ConfigureWeaponSlots( doc, attr ); } else { //LogMsg( WARN, "Did not find weapon slot configuration - ship cannot have weapons."); } return true; }