Esempio n. 1
0
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);
}
Esempio n. 2
0
/**\brief Initializes a new Engine with the given parameters.
 * \param _name Name of the Engine
 * \param _thrustsound Pointer to a Sound object that will be played for thrust
 * \param _forceOutput The amount of force the Engine generates
 * \param _msrp Price of the Engine
 * \param foldDrive Fold capable
 * \param _flareAnimation Thrust animation
 */
Engine::Engine( string _name, Sound* _thrustsound, float _forceOutput,
		short int _msrp, bool _foldDrive, string _flareAnimation, Image* _pic) :
	thrustsound(_thrustsound),
	foldDrive(_foldDrive),
	flareAnimation(_flareAnimation)
{
	SetName(_name);
	SetMSRP(_msrp);
	SetPicture(_pic);
	SetForceOutput(_forceOutput);
}
Esempio n. 3
0
/**\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);
}
Esempio n. 4
0
/**\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;
}
Esempio n. 5
0
/**\brief Creates a new Weapon object given parameters.
 * \param _name Name of the weapon
 * \param _image Picture of the weapon as fired
 * \param _pic Picture of the weapon in shop
 * \param _weaponType Type of weapon
 * \param _payload Amount of damage
 * \param _velocity Traveling velocity
 * \param _acceleration Acceleration of the weapon
 * \param _ammoType Type of ammo required
 * \param _ammoConsumption Amount of ammo consumed per shot
 * \param _fireDelay Delay after firing
 * \param _lifetime Life the ammo
 * \param _sound Sound the weapon makes
 * \param _tracking Turning rate
 * \param _msrp Price of the weapon
 */
Weapon::Weapon(
		string _name,
		Image* _image,
		Image* _pic,
		string _description,
		int _weaponType,
		int _payload,
		int _velocity,
		int _acceleration,
		AmmoType _ammoType,
		int _ammoConsumption,
		int _fireDelay,
		int _lifetime,
		Sound* _sound,
		float _tracking,
		int _msrp):
	image(_image),
	sound(_sound),
	weaponType(_weaponType),
	payload(_payload),
	velocity(_velocity),
	acceleration(_acceleration),
	ammoType(_ammoType),
	ammoConsumption(_ammoConsumption),
	fireDelay(_fireDelay),
	lifetime(_lifetime),
	tracking(_tracking)
{
	SetName(_name);
	SetMSRP( _msrp );
	SetPicture( _pic );
	SetDescription( _description );
	
	// Generic Outfit stuff
	//((Component*)this)->SetName(_name);
}
Esempio n. 6
0
/**\brief Parser to parse the XML file
 */
bool Engine::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) {
	xmlNodePtr  attr;
	string value;

	if( (attr = FirstChildNamed(node,"forceOutput")) ){
		value = NodeToString(doc,attr);
		SetForceOutput( 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,"foldDrive")) ){
		value = NodeToString(doc,attr);
		foldDrive = (atoi( value.c_str() ) != 0);
	} else return false;

	if( (attr = FirstChildNamed(node,"flareAnimation")) ){
		flareAnimation = NodeToString(doc,attr);
	} else return false;

	if( (attr = FirstChildNamed(node,"thrustSound")) ){
		thrustsound = Sound::Get( NodeToString(doc,attr) );
	} 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;

	return true;
}
Esempio n. 7
0
/**\brief Parses weapon information
 */
bool Weapon::FromXMLNode( xmlDocPtr doc, xmlNodePtr node ) {
	xmlNodePtr  attr;
	string value;

	if( (attr = FirstChildNamed(node,"weaponType")) ){
		weaponType = (short int)NodeToInt(doc,attr);
	} else {
		LogMsg(ERR,"Could not find child node weaponType while searching component");
		return false;
	}

	if( (attr = FirstChildNamed(node,"imageName")) ){
		image = Image::Get( NodeToString(doc,attr) );
	} else {
		LogMsg(ERR,"Could not find child node imageName while searching component");
		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 Weapon Name
		Image::Store(name, pic);
		SetPicture(pic);
	} else {
		LogMsg(ERR,"Could not find child node picName while searching component");
		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,"payload")) ){
		payload = NodeToInt(doc,attr);
	} else {
		LogMsg(ERR,"Could not find child node payload while searching component");
		return false;
	}

	if( (attr = FirstChildNamed(node,"velocity")) ){
		velocity = NodeToInt(doc,attr);
	} else {
		LogMsg(ERR,"Could not find child node velocity while searching component");
		return false;
	}

	if( (attr = FirstChildNamed(node,"acceleration")) ){
		acceleration = NodeToInt(doc,attr);
	} else {
		LogMsg(ERR,"Could not find child node acceleration while searching component");
		return false;
	}

	if( (attr = FirstChildNamed(node,"ammoType")) ){
		value = NodeToString(doc,attr);
		ammoType = AmmoNameToType(value);
		if(ammoType>=max_ammo) {
			LogMsg(ERR,"ammoType is >= max_ammo in Weapons XML parsing");
			return false;
		}
	} else {
		LogMsg(ERR,"Could not find child node ammoType while searching component");
		return false;
	}

	if( (attr = FirstChildNamed(node,"ammoConsumption")) ){
		ammoConsumption = NodeToInt(doc,attr);
	} else {
		LogMsg(ERR,"Could not find child node ammoConsumption while searching component");
		return false;
	}

	if( (attr = FirstChildNamed(node, "fireDelay")) ) {
		fireDelay = NodeToInt(doc,attr);
	} else {
		LogMsg(ERR, "Could not find child node fireDelay while searching component");
		return false;
	}

	if( (attr = FirstChildNamed(node, "lifetime")) ) {
		lifetime = NodeToInt(doc,attr);
	} else {
		LogMsg(ERR, "Could not find child node lifetime while searching component");
		return false;
	}

	if( (attr = FirstChildNamed(node,"tracking")) ) {
		float _tracking = NodeToFloat(doc,attr);
		if (_tracking > 1.0f ) _tracking = 1.0f;
		if (_tracking < 0.0001f ) _tracking = 0.0f;
		tracking = _tracking;
	} else {
		LogMsg(ERR, "Could not find child node tracking while searching component");
		return false;
	}

	if( (attr = FirstChildNamed(node, "msrp")) ) {
		value = NodeToString(doc,attr);
		SetMSRP( (short int)atoi( value.c_str() ));
	} else {
		LogMsg(ERR, "Could not find child node msrp while searching component");
		return false;
	}

	if( (attr = FirstChildNamed(node, "sound")) ) {
		value = NodeToString(doc,attr);
		this->sound = Sound::Get( value );
		if( this->sound == NULL) {
			// Do not return false here - they may be disabling audio on purpose or audio may not be supported on their system
			LogMsg(WARN, "Could not load sound file while searching component");
		}
	} else {
		LogMsg(ERR, "Could not find child node sound while searching component");
		return false;
	}

	return true;
}
Esempio n. 8
0
/**\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;
}
Esempio n. 9
0
/**\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;
}
Esempio n. 10
0
/**\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;
}