From: <spo...@us...> - 2007-06-17 13:51:31
|
Revision: 564 http://svn.sourceforge.net/opengate/?rev=564&view=rev Author: spom_spom Date: 2007-06-17 06:51:31 -0700 (Sun, 17 Jun 2007) Log Message: ----------- litte code renovation Modified Paths: -------------- branches/ogsector/data/gui/schemes/opengate/BlueHighway-10.font branches/ogsector/data/gui/schemes/opengate/BlueHighway-12.font branches/ogsector/data/gui/schemes/opengate/BlueHighway-14.font branches/ogsector/data/gui/schemes/opengate/BlueHighway-16.font branches/ogsector/data/gui/schemes/opengate/BlueHighway-18.font branches/ogsector/data/gui/schemes/opengate/BlueHighway-8.font branches/ogsector/data/gui/schemes/opengate/opengate.imageset branches/ogsector/data/gui/schemes/opengate/opengate.png branches/ogsector/src/DeviceManager.cpp branches/ogsector/src/DeviceManager.h branches/ogsector/src/Entity.cpp branches/ogsector/src/Entity.h branches/ogsector/src/EntityManager.cpp branches/ogsector/src/GameStateManager.cpp branches/ogsector/src/MarketDialog.cpp branches/ogsector/src/OpcodeWrapper.h branches/ogsector/src/Sector.cpp branches/ogsector/src/Sector.h branches/ogsector/src/SectorObjects.cpp branches/ogsector/src/SectorObjects.h branches/ogsector/src/ShipConfigDialog.cpp branches/ogsector/src/ShipConfigDialog.h branches/ogsector/src/UnDockedState.cpp branches/ogsector/src/Vessel.cpp branches/ogsector/src/Vessel.h branches/ogsector/src/VesselManager.cpp branches/ogsector/src/common.h branches/ogsector/src/networkProtocol.h branches/ogsector/src/networkServer.cpp branches/ogsector/src/networkServerUser.h Removed Paths: ------------- branches/ogsector/data/ships/squadrok/squid/ Modified: branches/ogsector/data/gui/schemes/opengate/BlueHighway-10.font =================================================================== --- branches/ogsector/data/gui/schemes/opengate/BlueHighway-10.font 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/data/gui/schemes/opengate/BlueHighway-10.font 2007-06-17 13:51:31 UTC (rev 564) @@ -1,2 +1,2 @@ <?xml version="1.0" ?> -<Font Name="BlueHighway-10" Filename="BlueHighway.ttf" Type="FreeType" Size="10" NativeHorzRes="800" NativeVertRes="600" AutoScaled="false" /> +<Font Name="BlueHighway-10" Filename="BlueHighway.ttf" Type="FreeType" Size="10" NativeHorzRes="1024" NativeVertRes="768" AutoScaled="true" /> Modified: branches/ogsector/data/gui/schemes/opengate/BlueHighway-12.font =================================================================== --- branches/ogsector/data/gui/schemes/opengate/BlueHighway-12.font 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/data/gui/schemes/opengate/BlueHighway-12.font 2007-06-17 13:51:31 UTC (rev 564) @@ -1,2 +1,2 @@ <?xml version="1.0" ?> -<Font Name="BlueHighway-12" Filename="BlueHighway.ttf" Type="FreeType" Size="12" NativeHorzRes="800" NativeVertRes="600" AutoScaled="false" /> +<Font Name="BlueHighway-12" Filename="BlueHighway.ttf" Type="FreeType" Size="12" NativeHorzRes="1024" NativeVertRes="768" AutoScaled="true" /> Modified: branches/ogsector/data/gui/schemes/opengate/BlueHighway-14.font =================================================================== --- branches/ogsector/data/gui/schemes/opengate/BlueHighway-14.font 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/data/gui/schemes/opengate/BlueHighway-14.font 2007-06-17 13:51:31 UTC (rev 564) @@ -1,2 +1,2 @@ <?xml version="1.0" ?> -<Font Name="BlueHighway-14" Filename="BlueHighway.ttf" Type="FreeType" Size="14" NativeHorzRes="800" NativeVertRes="600" AutoScaled="false" /> +<Font Name="BlueHighway-14" Filename="BlueHighway.ttf" Type="FreeType" Size="14" NativeHorzRes="1024" NativeVertRes="768" AutoScaled="true" /> Modified: branches/ogsector/data/gui/schemes/opengate/BlueHighway-16.font =================================================================== --- branches/ogsector/data/gui/schemes/opengate/BlueHighway-16.font 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/data/gui/schemes/opengate/BlueHighway-16.font 2007-06-17 13:51:31 UTC (rev 564) @@ -1,2 +1,2 @@ <?xml version="1.0" ?> -<Font Name="BlueHighway-16" Filename="BlueHighway.ttf" Type="FreeType" Size="16" NativeHorzRes="800" NativeVertRes="600" AutoScaled="false" /> +<Font Name="BlueHighway-16" Filename="BlueHighway.ttf" Type="FreeType" Size="16" NativeHorzRes="1024" NativeVertRes="768" AutoScaled="true" /> Modified: branches/ogsector/data/gui/schemes/opengate/BlueHighway-18.font =================================================================== --- branches/ogsector/data/gui/schemes/opengate/BlueHighway-18.font 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/data/gui/schemes/opengate/BlueHighway-18.font 2007-06-17 13:51:31 UTC (rev 564) @@ -1,2 +1,2 @@ <?xml version="1.0" ?> -<Font Name="BlueHighway-18" Filename="BlueHighway.ttf" Type="FreeType" Size="18" NativeHorzRes="800" NativeVertRes="600" AutoScaled="false" /> +<Font Name="BlueHighway-18" Filename="BlueHighway.ttf" Type="FreeType" Size="18" NativeHorzRes="1024" NativeVertRes="768" AutoScaled="true" /> Modified: branches/ogsector/data/gui/schemes/opengate/BlueHighway-8.font =================================================================== --- branches/ogsector/data/gui/schemes/opengate/BlueHighway-8.font 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/data/gui/schemes/opengate/BlueHighway-8.font 2007-06-17 13:51:31 UTC (rev 564) @@ -1,2 +1,2 @@ <?xml version="1.0" ?> -<Font Name="BlueHighway-8" Filename="BlueHighway.ttf" Type="FreeType" Size="8" NativeHorzRes="800" NativeVertRes="600" AutoScaled="false" /> +<Font Name="BlueHighway-8" Filename="BlueHighway.ttf" Type="FreeType" Size="8" NativeHorzRes="1024" NativeVertRes="768" AutoScaled="true" /> Modified: branches/ogsector/data/gui/schemes/opengate/opengate.imageset =================================================================== --- branches/ogsector/data/gui/schemes/opengate/opengate.imageset 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/data/gui/schemes/opengate/opengate.imageset 2007-06-17 13:51:31 UTC (rev 564) @@ -68,75 +68,65 @@ <Image Name="IconCommodityNormal" XPos="142" YPos="256" Width="15" Height="15" /> <Image Name="IconCommodityHover" XPos="142" YPos="272" Width="15" Height="15" /> <Image Name="IconCommodity0" XPos="142" YPos="288" Width="15" Height="15" /> - <Image Name="IconCommodity1" XPos="142" YPos="288" Width="15" Height="15" /> - <Image Name="IconCommodity2" XPos="142" YPos="304" Width="15" Height="15" /> - <Image Name="IconCommodity3" XPos="142" YPos="320" Width="15" Height="15" /> - <Image Name="IconCommodity4" XPos="142" YPos="336" Width="15" Height="15" /> + <Image Name="IconCommodity1" XPos="142" YPos="304" Width="15" Height="15" /> + <Image Name="IconCommodity2" XPos="142" YPos="320" Width="15" Height="15" /> + <Image Name="IconCommodity3" XPos="142" YPos="336" Width="15" Height="15" /> <Image Name="IconPowerplantNormal" XPos="158" YPos="256" Width="15" Height="15" /> <Image Name="IconPowerplantHover" XPos="158" YPos="272" Width="15" Height="15" /> <Image Name="IconPowerplant0" XPos="158" YPos="288" Width="15" Height="15" /> - <Image Name="IconPowerplant1" XPos="158" YPos="288" Width="15" Height="15" /> - <Image Name="IconPowerplant2" XPos="158" YPos="304" Width="15" Height="15" /> - <Image Name="IconPowerplant3" XPos="158" YPos="320" Width="15" Height="15" /> - <Image Name="IconPowerplant4" XPos="158" YPos="336" Width="15" Height="15" /> + <Image Name="IconPowerplant1" XPos="158" YPos="304" Width="15" Height="15" /> + <Image Name="IconPowerplant2" XPos="158" YPos="320" Width="15" Height="15" /> + <Image Name="IconPowerplant3" XPos="158" YPos="336" Width="15" Height="15" /> <Image Name="IconEngineNormal" XPos="174" YPos="256" Width="16" Height="15" /> <Image Name="IconEngineHover" XPos="174" YPos="272" Width="16" Height="15" /> <Image Name="IconEngine0" XPos="174" YPos="288" Width="15" Height="15" /> - <Image Name="IconEngine1" XPos="174" YPos="288" Width="15" Height="15" /> - <Image Name="IconEngine2" XPos="174" YPos="304" Width="15" Height="15" /> - <Image Name="IconEngine3" XPos="174" YPos="320" Width="15" Height="15" /> - <Image Name="IconEngine4" XPos="174" YPos="336" Width="15" Height="15" /> + <Image Name="IconEngine1" XPos="174" YPos="304" Width="15" Height="15" /> + <Image Name="IconEngine2" XPos="174" YPos="320" Width="15" Height="15" /> + <Image Name="IconEngine3" XPos="174" YPos="336" Width="15" Height="15" /> <Image Name="IconRadarNormal" XPos="190" YPos="256" Width="15" Height="15" /> <Image Name="IconRadarHover" XPos="190" YPos="272" Width="15" Height="15" /> <Image Name="IconRadar0" XPos="190" YPos="288" Width="15" Height="15" /> - <Image Name="IconRadar1" XPos="190" YPos="288" Width="15" Height="15" /> - <Image Name="IconRadar2" XPos="190" YPos="304" Width="15" Height="15" /> - <Image Name="IconRadar3" XPos="190" YPos="320" Width="15" Height="15" /> - <Image Name="IconRadar4" XPos="190" YPos="336" Width="15" Height="15" /> + <Image Name="IconRadar1" XPos="190" YPos="304" Width="15" Height="15" /> + <Image Name="IconRadar2" XPos="190" YPos="320" Width="15" Height="15" /> + <Image Name="IconRadar3" XPos="190" YPos="336" Width="15" Height="15" /> <Image Name="IconECMNormal" XPos="206" YPos="256" Width="15" Height="15" /> <Image Name="IconECMHover" XPos="206" YPos="272" Width="15" Height="15" /> <Image Name="IconECM0" XPos="206" YPos="288" Width="15" Height="15" /> - <Image Name="IconECM1" XPos="206" YPos="288" Width="15" Height="15" /> - <Image Name="IconECM2" XPos="206" YPos="304" Width="15" Height="15" /> - <Image Name="IconECM3" XPos="206" YPos="320" Width="15" Height="15" /> - <Image Name="IconECM4" XPos="206" YPos="336" Width="15" Height="15" /> + <Image Name="IconECM1" XPos="206" YPos="304" Width="15" Height="15" /> + <Image Name="IconECM2" XPos="206" YPos="320" Width="15" Height="15" /> + <Image Name="IconECM3" XPos="206" YPos="336" Width="15" Height="15" /> <Image Name="IconCapacitorNormal" XPos="222" YPos="256" Width="15" Height="15" /> <Image Name="IconCapacitorHover" XPos="222" YPos="272" Width="15" Height="15" /> <Image Name="IconCapacitor0" XPos="222" YPos="288" Width="15" Height="15" /> - <Image Name="IconCapacitor1" XPos="222" YPos="288" Width="15" Height="15" /> - <Image Name="IconCapacitor2" XPos="222" YPos="304" Width="15" Height="15" /> - <Image Name="IconCapacitor3" XPos="222" YPos="320" Width="15" Height="15" /> - <Image Name="IconCapacitor4" XPos="222" YPos="336" Width="15" Height="15" /> + <Image Name="IconCapacitor1" XPos="222" YPos="304" Width="15" Height="15" /> + <Image Name="IconCapacitor2" XPos="222" YPos="320" Width="15" Height="15" /> + <Image Name="IconCapacitor3" XPos="222" YPos="336" Width="15" Height="15" /> <Image Name="IconShieldNormal" XPos="238" YPos="256" Width="15" Height="15" /> <Image Name="IconShieldHover" XPos="238" YPos="272" Width="15" Height="15" /> <Image Name="IconShield0" XPos="238" YPos="288" Width="15" Height="15" /> - <Image Name="IconShield1" XPos="238" YPos="288" Width="15" Height="15" /> - <Image Name="IconShield2" XPos="238" YPos="304" Width="15" Height="15" /> - <Image Name="IconShield3" XPos="228" YPos="320" Width="15" Height="15" /> - <Image Name="IconShield4" XPos="238" YPos="336" Width="15" Height="15" /> + <Image Name="IconShield1" XPos="238" YPos="304" Width="15" Height="15" /> + <Image Name="IconShield2" XPos="238" YPos="320" Width="15" Height="15" /> + <Image Name="IconShield3" XPos="238" YPos="336" Width="15" Height="15" /> <Image Name="IconGunNormal" XPos="254" YPos="256" Width="15" Height="15" /> <Image Name="IconGunHover" XPos="254" YPos="272" Width="15" Height="15" /> <Image Name="IconGun0" XPos="254" YPos="288" Width="15" Height="15" /> - <Image Name="IconGun1" XPos="254" YPos="288" Width="15" Height="15" /> - <Image Name="IconGun2" XPos="254" YPos="304" Width="15" Height="15" /> - <Image Name="IconGun3" XPos="254" YPos="320" Width="15" Height="15" /> - <Image Name="IconGun4" XPos="254" YPos="336" Width="15" Height="15" /> + <Image Name="IconGun1" XPos="254" YPos="304" Width="15" Height="15" /> + <Image Name="IconGun2" XPos="254" YPos="320" Width="15" Height="15" /> + <Image Name="IconGun3" XPos="254" YPos="336" Width="15" Height="15" /> <Image Name="IconMissileNormal" XPos="270" YPos="256" Width="15" Height="15" /> <Image Name="IconMissileHover" XPos="270" YPos="272" Width="15" Height="15" /> <Image Name="IconMissile0" XPos="270" YPos="288" Width="15" Height="15" /> - <Image Name="IconMissile1" XPos="270" YPos="288" Width="15" Height="15" /> - <Image Name="IconMissile2" XPos="270" YPos="304" Width="15" Height="15" /> - <Image Name="IconMissile3" XPos="270" YPos="320" Width="15" Height="15" /> - <Image Name="IconMissile4" XPos="270" YPos="336" Width="15" Height="15" /> + <Image Name="IconMissile1" XPos="270" YPos="304" Width="15" Height="15" /> + <Image Name="IconMissile2" XPos="270" YPos="320" Width="15" Height="15" /> + <Image Name="IconMissile3" XPos="270" YPos="336" Width="15" Height="15" /> <Image Name="IconMODxNormal" XPos="286" YPos="256" Width="15" Height="15" /> <Image Name="IconMODxHover" XPos="286" YPos="272" Width="15" Height="15" /> <Image Name="IconMODx0" XPos="286" YPos="288" Width="15" Height="15" /> - <Image Name="IconMODx1" XPos="286" YPos="288" Width="15" Height="15" /> - <Image Name="IconMODx2" XPos="286" YPos="304" Width="15" Height="15" /> - <Image Name="IconMODx3" XPos="286" YPos="320" Width="15" Height="15" /> - <Image Name="IconMODx4" XPos="286" YPos="336" Width="15" Height="15" /> - <Image Name="IconStorageNormal" XPos="410" YPos="256" Width="15" Height="15" /> - <Image Name="IconStorageHover" XPos="426" YPos="256" Width="15" Height="15" /> + <Image Name="IconMODx1" XPos="286" YPos="304" Width="15" Height="15" /> + <Image Name="IconMODx2" XPos="286" YPos="320" Width="15" Height="15" /> + <Image Name="IconMODx3" XPos="286" YPos="336" Width="15" Height="15" /> + <Image Name="IconStorageNormal" XPos="410" YPos="256" Width="15" Height="15" /> + <Image Name="IconStorageHover" XPos="426" YPos="256" Width="15" Height="15" /> <Image Name="IconSize1" XPos="473" YPos="223" Width="12" Height="26" /> <Image Name="IconSize2" XPos="460" YPos="223" Width="12" Height="26" /> Modified: branches/ogsector/data/gui/schemes/opengate/opengate.png =================================================================== (Binary files differ) Modified: branches/ogsector/src/DeviceManager.cpp =================================================================== --- branches/ogsector/src/DeviceManager.cpp 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/DeviceManager.cpp 2007-06-17 13:51:31 UTC (rev 564) @@ -18,13 +18,19 @@ * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * ***************************************************************************/ +#include "tinyxml/tinyxml.h" #include "DeviceManager.h" +#include "LogManager.h" +#include <OgreArchiveManager.h> +#include <OgreFileSystem.h> namespace OpenGate{ template<> DeviceManager * Ogre::Singleton< DeviceManager >::ms_Singleton = 0; DeviceManager::DeviceManager( ) : modifier_( KEY_NONE ){ + log_ = LogManager::getSingletonPtr(); + ogreRoot = NULL; renderWindow = NULL; inputManager = NULL; @@ -40,6 +46,64 @@ DeviceManager::~DeviceManager( ) { } +std::string DeviceManager::factionName( int id ) { + if ( factionIDs_.count( id ) ){ + return factionIDs_[ id ]; + } + return "unknown"; +} + +void DeviceManager::loadGlobalIDs(const std::set < std::string > & resourcePaths, const std::string & fileName ){ + + Ogre::FileSystemArchive * pArch = new Ogre::FileSystemArchive( (*resourcePaths.begin()), "FileSystem" ); + Ogre::StringVectorPtr file = pArch->find( fileName, true, false); + + std::string fileFullName( fileName ); + if ( (*file).size() > 0 ){ + fileFullName = (*resourcePaths.begin() ) + "/" + (*file)[ 0 ] ; + } + + for ( unsigned int i = 0; i < (*file).size(); i ++ ){ + log_->info( std::string( "Found ressource: " ) + (*resourcePaths.begin() ) + "/" + (*file)[ i ] ); + } + delete pArch; + + TiXmlDocument doc( fileFullName ); + bool loadOkay = doc.LoadFile(); + + if ( !loadOkay ) { + log_->fatal( std::string( "Failed to load id file: " + fileName ) ); + return; + } + + TiXmlHandle docHandle( &doc ); + TiXmlElement *pElem, *pElemId, *pElemName; + TiXmlHandle hRoot( 0 ); + + pElem = docHandle.FirstChildElement().Element(); + hRoot = TiXmlHandle( pElem ); + + if ( !pElem ) { + log_->fatal( fileName + " cannot read first node." ); + return; + } + + if ( strcmp( "container", pElem->Value() ) != 0 ) { + log_->fatal( fileName + " is no container description" ); + return; + } + + for ( pElem = hRoot.FirstChild( "faction" ).Element(); pElem != 0; pElem = pElem->NextSiblingElement() ) { + pElemId = pElem->FirstChildElement( "faction_id" ); + pElemName = pElem->FirstChildElement( "name_en" ); + if ( pElemId && pElemName ) { + factionIDs_[ toInt( pElemId->FirstChild()->Value() ) ] = pElemName->FirstChild()->Value(); + } + } +} + + + DeviceManager & DeviceManager::getSingleton( ){ assert( ms_Singleton ); return ( *ms_Singleton ); Modified: branches/ogsector/src/DeviceManager.h =================================================================== --- branches/ogsector/src/DeviceManager.h 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/DeviceManager.h 2007-06-17 13:51:31 UTC (rev 564) @@ -66,18 +66,11 @@ std::string languageSuffix() const { return languageSuffix_; } std::string className( int id ) const { return "unknown"; } - std::string factionName( int id ) const { - switch( id ){ - case 0: return "neutral"; - case 1: return "tauseti"; - case 2: return "quantar"; - case 3: return "octavius"; - case 4: return "squadrok"; - case 5: return "amanath"; - case 6: return "hyperial"; - } - return "unknown"; - } + + void loadGlobalIDs(const std::set < std::string > & resourcePaths, const std::string & fileName ); + + std::string factionName( int id ); + std::string categoryName( EntityType rtti ) const { switch( rtti ){ case COMMODITY: return "Commodity"; @@ -106,8 +99,12 @@ Avatar * avatar; protected: + LogManager * log_; + GlobalKeyModifier modifier_; std::string languageSuffix_; + + std::map< int, std::string > factionIDs_; }; } //namespace OpenGate Modified: branches/ogsector/src/Entity.cpp =================================================================== --- branches/ogsector/src/Entity.cpp 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/Entity.cpp 2007-06-17 13:51:31 UTC (rev 564) @@ -51,6 +51,9 @@ void Entity::loadImages_( ) { imageInitialised_ = true; bool haveSmall = true; + + if ( imageFileName_ == "unknown" ) imageFileName_ = name_; + haveSmall = initialiseImage( imageFileName_ + "_76x76.png", imageFileName_ + "Small" ); if ( haveSmall ){ ceguiSmallImageName_ = ceguiImageName_; @@ -68,31 +71,30 @@ bool Entity::initialiseImage( const std::string & imageName, const std::string & targetName, bool verbose ){ bool fail = false; - CEGUI::Texture * texture; + CEGUI::Texture * texture = NULL; - if ( imageName != "unknown" ){ - - try { - texture = dynamic_cast< CEGUI::OgreCEGUIRenderer * >( DeviceManager::getSingleton().guiRenderer )->createTexture( imageName, "General"); - } catch( CEGUI::Exception & e ){ - if ( verbose ) LogManager::getSingleton().warn( e.getMessage().c_str() ); - fail = true; - } - } else { + try { + texture = dynamic_cast< CEGUI::OgreCEGUIRenderer * >( DeviceManager::getSingleton().guiRenderer )->createTexture( imageName, "General"); + } catch( CEGUI::Exception & e ){ + if ( verbose ) LogManager::getSingleton().warn( e.getMessage().c_str() ); fail = true; + } catch( Ogre::Exception & e ){ + if ( verbose ) LogManager::getSingleton().warn( e.what() ); + fail = true; + } catch( ... ){ + if ( verbose ) LogManager::getSingleton().warn( "Unknown exception" ); } - if ( !fail ){ + if ( !fail && texture ){ CEGUI::Imageset * imageSet = CEGUI::ImagesetManager::getSingleton().createImageset( targetName, texture ); imageSet->defineImage( targetName, CEGUI::Point(0.0f, 0.0f), CEGUI::Size( texture->getWidth(), texture->getHeight() ), CEGUI::Point(0.0f,0.0f)); - + ceguiImageName_ = "set:" + targetName + " image:" + targetName; } else { - //** fallback image - // ceguiImageName_ = "set:" + name_ + " image:full_image"; + //** fallback image; + ceguiImageName_ = "set:" + targetName + " image:" + targetName; } - // image_ = new CEGUI::Texture(); return !fail; } Modified: branches/ogsector/src/Entity.h =================================================================== --- branches/ogsector/src/Entity.h 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/Entity.h 2007-06-17 13:51:31 UTC (rev 564) @@ -69,7 +69,7 @@ inline int techLevel( ) const { return techLevel_; } inline void setMass( long mass ){ mass_ = mass; } - inline long mass( ) const { return mass_; } + inline Uint32 mass( ) const { return mass_; } inline void setSize( int size ){ size_ = size; } inline int size( ) const { return size_; } @@ -120,7 +120,7 @@ /*! The required tech level to interact with this object */ int techLevel_; /*! The mass of this entity. */ - long mass_; + Uint32 mass_; /*! The amount of slots necessary to plug in such a device. */ int size_; @@ -149,14 +149,18 @@ inline void setEfficiency( double efficiency ) { efficiency_ = efficiency; } inline double efficiency( ) const { return efficiency_; } - inline void setPowerConsumption( double powerConsumption ) { powerConsumption_ = powerConsumption; } - virtual inline double powerConsumption( ) { return powerConsumption_; } + inline void setPowerConsumption( Uint32 powerConsumption ) { + powerConsumption_ = powerConsumption; + //** if input power is < 1000, then input is scaled in kW + if ( powerConsumption_ < 1e3 ) powerConsumption_ *= 1000; + } + virtual inline Uint32 powerConsumption( ) { return powerConsumption_; } protected: Equipment() : Entity(), manufacturer_( "unkown" ) { size_ = 0; efficiency_ = 1.0; - powerConsumption_ = 0.0; + powerConsumption_ = 0; } virtual ~Equipment() { } @@ -168,7 +172,7 @@ double efficiency_; /*! Stores the power consumption of this equipment */ - double powerConsumption_; + Uint32 powerConsumption_; }; /*! @@ -183,13 +187,17 @@ public: PowerPlant() : Equipment(){ rtti_ = POWERPLANT; - powerOutput_ = 0.0; + powerOutput_ = 0; } - void setPowerOutput( double power ) { powerOutput_ = power; } - double powerOutput( ) const { return powerOutput_; } + inline void setPowerOutput( Uint32 power ) { + powerOutput_ = power; + //** if input power is < 100kW, then input is scaled in kW + if ( powerOutput_ < 1e5 ) powerOutput_ *= 1000; + } + inline Uint32 powerOutput( ) const { return powerOutput_; } protected: - double powerOutput_; + Uint32 powerOutput_; }; /*! @@ -205,17 +213,21 @@ Engine() : Equipment() { rtti_ = ENGINE; - maxThrust_ = 0.0; + maxThrust_ = 0; } - inline void setMaxThrust( double maxThrust ) { maxThrust_ = maxThrust; } - inline double maxThrust( ) { return maxThrust_; } + inline void setMaxThrust( Uint32 maxThrust ) { + maxThrust_ = maxThrust; + //** if input thrust is < 100kN, then input is scaled in kN + if ( maxThrust_ < 1e5 ) maxThrust_ *= 1000; + } + inline Uint32 maxThrust( ) { return maxThrust_; } - double powerConsumption( ) const { return ( maxThrust_ / 1000 ) / efficiency_; } + virtual Uint32 powerConsumption( ) const { return (Uint32)rint(( (float)maxThrust_ / efficiency_ )); } private: /*! Stores the maximum thrust of this engine */ - double maxThrust_; + Uint32 maxThrust_; }; /*! @@ -231,11 +243,11 @@ Radar() : Equipment(){ rtti_ = RADAR; } - void setMaxRange( double range ){ range_ = range; } - double maxRange() const{ return range_; } + inline void setMaxRange( Uint32 range ){ range_ = range; } + inline Uint32 maxRange() const{ return range_; } protected: - double range_; + Uint32 range_; }; /*! @@ -276,18 +288,25 @@ rtti_ = SHIELD; } - void setMaxDeflection( double deflection ){ setMaximumDeflection_ = deflection; } - double maxDeflection( ) const { return setMaximumDeflection_; } + inline void setMaxDeflection( Uint32 deflection ){ + setMaximumDeflection_ = deflection; + //** if input deflection is < 100kJ, then input is scaled in kJ + if ( setMaximumDeflection_ < 1e5 ) setMaximumDeflection_ *= 1000; + } + inline Uint32 maxDeflection( ) const { return setMaximumDeflection_; } - void setRegenerationRate( double regenRate ){ regenerationRate_ = regenRate; } - double regenerationRate( ) const { return regenerationRate_; } + inline void setRegenerationRate( Uint32 regenRate ){ + regenerationRate_ = regenRate; + //** if input regeneration rate is < 10kJ, then input is scaled in kJ + if ( regenerationRate_ < 1e4 ) regenerationRate_ *= 1000; + } + inline Uint32 regenerationRate( ) const { return regenerationRate_; } - double powerConsumption( ) const { return regenerationRate_ / efficiency_; } + inline Uint32 powerConsumption( ) const { return (Uint32) rint( regenerationRate_ / efficiency_ ); } protected: - double regenerationRate_; - double setMaximumDeflection_; - + Uint32 regenerationRate_; + Uint32 setMaximumDeflection_; }; /*! @@ -306,12 +325,16 @@ capacity_ = 0; } - inline void setCapacity( long capacity ) { capacity_ = capacity; } - inline long capacity( ) { return capacity_; } + inline void setCapacity( Uint32 capacity ) { + capacity_ = capacity; + //** if input capacity is < 100kJ, then input is scaled in kJ + if ( capacity_ < 1e5 ) capacity_ *= 1000; + } + inline Uint32 capacity( ) { return capacity_; } private: /*! Stores the capacity of a capacitor */ - long capacity_; + Uint32 capacity_; }; Modified: branches/ogsector/src/EntityManager.cpp =================================================================== --- branches/ogsector/src/EntityManager.cpp 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/EntityManager.cpp 2007-06-17 13:51:31 UTC (rev 564) @@ -46,39 +46,6 @@ } delete pArch; -// for ( std::set < std::string >::iterator it = resourcePaths.begin(); it != resourcePaths.end(); it ++ ){ -// std::string resourceFile( (*it) + "/" + resourceName ); - -// TiXmlDocument doc( resourceFile ); -// bool loadOkay = doc.LoadFile(); - -// std::map < int, std::string > entities; - -// if ( loadOkay ) { -// log_->info( std::string( "open resource file: ") + resourceFile ); -// TiXmlHandle docHandle( &doc ); -// TiXmlElement* pElem; -// TiXmlHandle hRoot( 0 ); - -// pElem = docHandle.FirstChildElement().Element(); -// hRoot = TiXmlHandle( pElem ); - -// if ( pElem ) { -// for ( pElem = hRoot.FirstChild( "Resource" ).Element(); pElem != 0; pElem = pElem->NextSiblingElement() ) { -// log_->info( std::string( "Found ressource: " ) + pElem->Attribute("location") ); -// entities[ toInt( pElem->Attribute("id") ) ] = pElem->Attribute("location"); -// } -// } else { -// log_->fatal( resourceFile + " cannot read first node." ); -// } -// } else { -// // log_->info( resourceFile + " cannot open resourceFile." ); -// } - -// for ( std::map < int, std::string >::iterator it = entities.begin(); it != entities.end(); it ++ ){ -// loadAndCreate( it->first, it->second ); -// } -// } } template<> EquipmentManager * Ogre::Singleton< EquipmentManager >::ms_Singleton = 0; @@ -286,9 +253,9 @@ if ( efficiency > 1 ) efficiency /= 100; } - double powerConsumption = 0.0; + Uint32 powerConsumption = 0; pElem = hRoot.ChildElement( "power_input", 0 ).Element(); - if ( pElem ) powerConsumption = toDouble( pElem->FirstChild()->Value() ); + if ( pElem ) powerConsumption = toInt( pElem->FirstChild()->Value() ); pElem = hRoot.ChildElement( "description_" + DeviceManager::getSingleton().languageSuffix(), 0 ).Element(); if ( !pElem ){ //** fallback to english @@ -306,12 +273,12 @@ switch ( entity->entityType() ){ case POWERPLANT: pElem = hRoot.ChildElement( "power_output", 0 ).Element(); - if ( pElem ) dynamic_cast< PowerPlant * >( entity )->setPowerOutput( toDouble( pElem->FirstChild()->Value() ) ); + if ( pElem ) dynamic_cast< PowerPlant * >( entity )->setPowerOutput( toInt( pElem->FirstChild()->Value() ) ); break; case ENGINE: dynamic_cast< Engine * >( entity )->setEfficiency( efficiency ); pElem = hRoot.ChildElement( "maximum_thrust", 0 ).Element(); - if ( pElem ) dynamic_cast< Engine * >( entity )->setMaxThrust( toDouble( pElem->FirstChild()->Value() ) ); + if ( pElem ) dynamic_cast< Engine * >( entity )->setMaxThrust( toInt( pElem->FirstChild()->Value() ) ); break; case RADAR: @@ -319,7 +286,7 @@ dynamic_cast< Radar * >( entity )->setPowerConsumption( powerConsumption ); pElem = hRoot.ChildElement( "maximum_range", 0 ).Element(); - if ( pElem ) dynamic_cast< Radar * >( entity )->setMaxRange( toDouble( pElem->FirstChild()->Value() ) ); + if ( pElem ) dynamic_cast< Radar * >( entity )->setMaxRange( toInt( pElem->FirstChild()->Value() ) ); break; case ECM: Modified: branches/ogsector/src/GameStateManager.cpp =================================================================== --- branches/ogsector/src/GameStateManager.cpp 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/GameStateManager.cpp 2007-06-17 13:51:31 UTC (rev 564) @@ -315,6 +315,8 @@ devices_.console->addCommand( "/time", &GameStateManager::CMD_printTime, "Show current system time" ); devices_.console->addCommand( "/ai", &GameStateManager::CMD_spawnAi, "[name] Spawn ai subject. /ai help show all available ships." ); + devices_.loadGlobalIDs( resourcePaths_, "ids.xml" ); + vesselManager_ = new VesselManager( ); vesselManager_->load( resourcePaths_, "ships" ); @@ -419,7 +421,7 @@ } void GameStateManager::CMD_spawnAi( const std::vector < std::string > & argv ){ - std::string aiName = "squid"; + std::string aiName = "Squid"; if ( argv.size() > 1 ){ aiName = argv[ 1 ]; } Modified: branches/ogsector/src/MarketDialog.cpp =================================================================== --- branches/ogsector/src/MarketDialog.cpp 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/MarketDialog.cpp 2007-06-17 13:51:31 UTC (rev 564) @@ -554,7 +554,7 @@ switch( item->entityType() ){ case POWERPLANT: - str1a = "Wattage:"; str1b = toStr( dynamic_cast< PowerPlant *>(item)->powerOutput() ) + "K"; + str1a = "Wattage:"; str1b = toStr( dynamic_cast< PowerPlant *>(item)->powerOutput()/1000 ) + "K"; break; case ENGINE: str1a = "Efficiency:" ; str1b = toStr( dynamic_cast< Engine *>(item)->efficiency() ); @@ -562,19 +562,19 @@ break; case RADAR: str1a = "Max. range:" ; str1b = toStr( dynamic_cast< Radar *>(item)->maxRange() ); - str2a = "Power:" ; str2b = toStr( dynamic_cast< Radar *>(item)->powerConsumption() ) + "K"; + str2a = "Power:" ; str2b = toStr( dynamic_cast< Radar *>(item)->powerConsumption()/1000 ) + "K"; break; case ECM: - str1a = "Power:" ; str1b = toStr( dynamic_cast< Engine *>(item)->powerConsumption() ) + "K"; + str1a = "Power:" ; str1b = toStr( dynamic_cast< Engine *>(item)->powerConsumption()/1000 ) + "K"; break; case SHIELD: str1a = "Efficiency:" ; str1b = toStr( dynamic_cast< Shield *>(item)->efficiency() ); - str2a = "Max. Damage:" ; str2b = toStr( dynamic_cast< Shield *>(item)->maxDeflection() ) + "K"; + str2a = "Max. Damage:" ; str2b = toStr( dynamic_cast< Shield *>(item)->maxDeflection()/1000 ) + "K"; str3a = "Recharge:" ; str3b = toStr( dynamic_cast< Shield *>(item)->regenerationRate() / 1000) + "K"; break; case CAPACITOR: str1a = "Efficiency:" ; str1b = toStr( dynamic_cast< Capacitor *>( item )->efficiency() ); - str2a = "Max. Power:" ; str2b = toStr( dynamic_cast< Capacitor *>( item )->capacity() ) + "K"; + str2a = "Max. Power:" ; str2b = toStr( dynamic_cast< Capacitor *>( item )->capacity()/1000 ) + "K"; break; default: break; Modified: branches/ogsector/src/OpcodeWrapper.h =================================================================== --- branches/ogsector/src/OpcodeWrapper.h 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/OpcodeWrapper.h 2007-06-17 13:51:31 UTC (rev 564) @@ -36,7 +36,6 @@ class SectorObject; class Projectile; - class OpcodeCollisionDetection : public Ogre::Singleton< OpcodeCollisionDetection >{ public: OpcodeCollisionDetection( Ogre::SceneManager * sceneMgr ); Modified: branches/ogsector/src/Sector.cpp =================================================================== --- branches/ogsector/src/Sector.cpp 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/Sector.cpp 2007-06-17 13:51:31 UTC (rev 564) @@ -351,10 +351,9 @@ radarMap->removeChild( obj->dotB()->getName() ); } - for ( std::map< long, SectorObjectMoveableAi * >::iterator it = localAiObjects_.begin(); - it != localAiObjects_.end(); it ++ ){ + for ( std::map< long, SectorObjectMoveableAi * >::iterator it = localAiObjects_.begin(); it != localAiObjects_.end(); it ++ ){ if ( it->second->target() == obj ){ - log_->warn( std::string( "ai object target: " ) + it->second->name() + " loose target." ); + log_->warn( std::string( "ai object target: " ) + it->second->name() + " loose target." ); it->second->setTarget( NULL ); } } @@ -421,7 +420,7 @@ obj->mainNode()->setPosition( Ogre::Math::RangeRandom( xmin, xmax ), Ogre::Math::RangeRandom( ymin, ymax ), Ogre::Math::RangeRandom( zmin, zmax ) ); - obj->setThrustPercent( 100 ); + obj->setThrust( obj->maxThrust() ); // obj->mainNode()->setPosition( 0.0f, 0.0f, 200.0f); @@ -572,27 +571,27 @@ } } -void Sector::sendVesselMovement( SectorObjectMoveable * obj ){ +void Sector::sendVesselMovement( SectorObjectMoveableLocal * obj ){ if ( obj ){ MessageBodyShipMovement msg( obj->childID(), obj->mainNode()->getPosition(), - obj->velDirection(), + obj->velocity(), obj->mainNode()->getOrientation(), - obj->thrustPercent(), + obj->thrust(), obj->scaledYaw(), obj->scaledPitch(), obj->scaledRoll(), - obj->incNetSequence() ); + 0 ); network_->send( msg ); } } -void Sector::sendVesselRegister( SectorObjectMoveable * obj ){ +void Sector::sendVesselRegister( SectorObjectMoveableLocal * obj ){ if ( obj ) { log_->info( std::string( "Send register " ) + obj->name() + " id:" + toStr( obj->vessel()->id() ) ); MessageBodyShipRegister msg( obj->userID(), obj->childID(), obj->name(), obj->mainNode()->getPosition(), - obj->vessel()->id() ); + obj->vessel()->id(), obj->mass(), obj->maxShield(), obj->maxThrust() ); network_->send( msg ); } @@ -606,6 +605,9 @@ SectorObjectMoveable * obj = createMoveableObject( msg.name(), msg.senderID(), msg.childID(), *VesselManager::getSingleton().vessel( msg.vesselID() ) ); obj->mainNode()->setPosition( msg.position() ); + obj->setMass( msg.mass() ); + obj->setMaxShield( msg.maxShield() ); + } else { log_->info( "Create ai object " + msg.name()+ " " + toStr( msg.senderID() ) + " " + toStr( (int)msg.childID() ) + " " + toStr( msg.vesselID() ) ); @@ -684,14 +686,9 @@ } -void Sector::sendVesselStatus( SectorObjectMoveable * obj ){ +void Sector::sendVesselStatus( SectorObjectMoveableLocal * obj ){ if ( obj ){ - MessageBodyShipStatus msg( obj->childID(), - obj->shieldPercent(), - obj->armorPercent(), - obj->firePressed(), - obj->afterburnerPressed(), - obj->breakPressed() ); + MessageBodyShipStatus msg( obj->childID(), obj->shield(), obj->armor(), 0, 0, 0 ); network_->send( msg ); } } @@ -744,7 +741,6 @@ for ( std::map< long, SectorObjectMoveable * >::iterator i = movableObjects_.begin(); i != movableObjects_.end(); i++){ std::cerr << "\t" << i->first << " " << i->second->name() << " " << std::endl; } - } } } Modified: branches/ogsector/src/Sector.h =================================================================== --- branches/ogsector/src/Sector.h 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/Sector.h 2007-06-17 13:51:31 UTC (rev 564) @@ -44,12 +44,8 @@ UnDockedState * listener( ){ return listener_; } - void setNetwork( NetworkClient * network ){ network_ = network; } - void update( Ogre::Real elapsedTime ); - LogManager * log() { return log_; } - void createStaticObject( const Ogre::String & meshname, const Ogre::String & objectname, const Ogre::Vector3 & pos, Ogre::Real targetSize, Ogre::Degree yaw ); @@ -72,6 +68,7 @@ void createCircle( ); void selectNextTarget( SectorObject * obj = NULL ); + void selectPrevTarget( SectorObject * obj = NULL ); inline SectorObject * firstTarget( ){ return *itTarget_; } @@ -83,16 +80,16 @@ void sendAllVesselInfos( ); void sendAllVesselMovements( ); - void sendVesselRegister( SectorObjectMoveable * obj ); + void sendVesselRegister( SectorObjectMoveableLocal * obj ); void receiveVesselRegister( const MessageBodyShipRegister & msg ); void sendVesselDeRegister( SectorObjectMoveable * obj ); void receiveVesselDeRegister( const MessageBodyShipDeRegister & msg ); - void sendVesselMovement( SectorObjectMoveable * obj ); + void sendVesselMovement( SectorObjectMoveableLocal * obj ); void receiveVesselMovement( const std::vector < MessageBodyShipMovement * > & movements ); - void sendVesselStatus( SectorObjectMoveable * obj ); + void sendVesselStatus( SectorObjectMoveableLocal * obj ); void receiveVesselStatus( const MessageBodyShipStatus & msg ); void sendVesselAmmoHit( const Projectile & projectile, BaseObject * victim ); Modified: branches/ogsector/src/SectorObjects.cpp =================================================================== --- branches/ogsector/src/SectorObjects.cpp 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/SectorObjects.cpp 2007-06-17 13:51:31 UTC (rev 564) @@ -119,9 +119,8 @@ lifeTime_ = 0.0; oldTime_ = 0.0; - // damage_ = 250.0; - damage_ = (9000.0 + 5700.0) / 4.01; - vel_ = speed * -direction.zAxis().normalisedCopy() + parent->velDirection(); + damage_ = 5000 * 1000; + vel_ = speed * -direction.zAxis().normalisedCopy() + parent->velocity(); } Projectile::~Projectile() { @@ -180,7 +179,6 @@ // return true; // } // } - } return true; } @@ -247,7 +245,7 @@ baseYaw( Ogre::Degree( vessel_->baseYaw() ) ); setBaseSize( vessel_->baseSize() ); - if ( vessel_->factionName() == "squadrok" ){ + if ( vessel_->factionID() == 4 ){ thrusterParticles_ = NULL; thrusterBbs_ = sceneMgr_->createBillboardSet( name_ + "thrust_BBS" ); @@ -269,7 +267,7 @@ } explosion_ = NULL; - setThrustPercent( 0.0 ); + setThrust( 0 ); updateThruster(); } @@ -294,12 +292,68 @@ // Projectile globalisieren. } +bool SectorObjectMoveable::update( Ogre::Real elapsedTime ){ + if ( elapsedTime < 0.001 ) return true; + + lifeTime_ += elapsedTime; + lastFrameCount_ ++; + + Ogre::Real rotFric = rotFriction(); + if ( !isChild() ){ + mainNode_->yaw( Ogre::Degree( yaw_ * ( vessel_->yaw() * rotFric ) * elapsedTime ) ); + mainNode_->pitch( Ogre::Degree( pitch_ * ( vessel_->pitch() * rotFric ) * elapsedTime ) ); + mainNode_->roll( Ogre::Degree( roll_ * ( vessel_->roll() * rotFric ) * elapsedTime ) ); + } else { + mainNode_->yaw( Ogre::Degree( yaw_ * ( vessel_->yaw() * rotFric ) * elapsedTime ), Ogre::Node::TS_PARENT ); + mainNode_->pitch( Ogre::Degree( pitch_ * ( vessel_->pitch() * rotFric ) * elapsedTime ), Ogre::Node::TS_PARENT ); + mainNode_->roll( Ogre::Degree( roll_ * ( vessel_->roll() * rotFric ) * elapsedTime ), Ogre::Node::TS_PARENT ); + } + + // mainNode_->rotate( interpolateRot_, Ogre::Node::TS_PARENT ); + + //** friction = drag * v^2; + Ogre::Real friction = ethernalDensity_ * vessel_->dragFactor() * speed() * speed(); + + Ogre::Vector3 trustDir( mainNode_->getOrientation().zAxis() ); + Ogre::Vector3 flightDir( vel_ ); flightDir.normalise(); + + //** thrust = mass * acc; + if ( mass_ > 0 ){ + acc_ = ( - trustDir * thrust() - flightDir * friction ) / mass_; + } else { + std::cerr << "mass: " << mass_ << std::endl; + } + + if ( breakPressed_ == true ) { + if ( speed() > 0 ) { + acc_ -= flightDir * 4.0; + } + } + + //** v = a * t; + vel_ += acc_ * elapsedTime; + mainNode_->translate( ( vel_ + interpolateVel_ ) * elapsedTime ); + + for ( std::set < Projectile * >::iterator it = projectiles_.begin(); it != projectiles_.end();){ + if ( !(*it)->update( elapsedTime ) ) { + delete *it; + projectiles_.erase( it++ ); + } else ++it; + } + + //** snap quaternion + Ogre::Quaternion rnd( mainNode_->getOrientation() ); + mainNode_->setOrientation( round( rnd.w, 5 ), round( rnd.x, 5 ), round( rnd.y, 5 ), round( rnd.z, 5 ) ); + + return true; +} + void SectorObjectMoveable::setFlightProperties( const MessageBodyShipMovement & msg ){ if ( forceMovement_ ){ mainNode_->setPosition( msg.position() ); mainNode_->setOrientation( msg.orientation() ); vel_ = msg.velocity(); - setThrustPercent( msg.thrust() ); + setThrust( msg.thrust() ); setScaledYaw( msg.yaw() ); setScaledPitch( msg.pitch() ); setScaledRoll( msg.roll() ); @@ -327,7 +381,7 @@ setScaledPitch( msg.pitch() ); vel_ = msg.velocity(); - setThrustPercent( msg.thrust() ); + setThrust( msg.thrust() ); Ogre::Vector3 srcP = mainNode_->getPosition( ); Ogre::Quaternion srcQ = mainNode_->getOrientation( ); @@ -389,12 +443,12 @@ } void SectorObjectMoveable::setStatus( const MessageBodyShipStatus & msg ){ - setFirePressed( msg.firePressed() ); - setAfterburnerPressed( msg.afterburnerPressed() ); - setBreakPressed( msg.breakPressed() ); +// setFirePressed( msg.firePressed() ); +// setAfterburnerPressed( msg.afterburnerPressed() ); +// setBreakPressed( msg.breakPressed() ); - setShieldPercent( msg.shield() ); - setArmorPercent( msg.armor() ); + setShield( msg.shield() ); + setArmor( msg.armor() ); statusChanged_ = false; } @@ -425,130 +479,15 @@ } } -void SectorObjectMoveable::hitByAmmo( float damage ){ - shield_ -= damage; - - if ( shield_ < 0 ){ - armor_ += shield_; - shield_ = 0.0; - armor_ = max( 0.0f, armor_ ); - } - statusChanged_ = true; -} - -bool SectorObjectMoveable::update( Ogre::Real elapsedTime ){ - if ( elapsedTime < 0.001 ) return true; - - lifeTime_ += elapsedTime; - lastFrameCount_ ++; - - Ogre::Real rotFric = rotFriction(); - if ( !isChild() ){ - mainNode_->yaw( Ogre::Degree( yaw_ * ( vessel_->yaw() * rotFric ) * elapsedTime ) ); - mainNode_->pitch( Ogre::Degree( pitch_ * ( vessel_->pitch() * rotFric ) * elapsedTime ) ); - mainNode_->roll( Ogre::Degree( roll_ * ( vessel_->roll() * rotFric ) * elapsedTime ) ); - } else { - mainNode_->yaw( Ogre::Degree( yaw_ * ( vessel_->yaw() * rotFric ) * elapsedTime ), Ogre::Node::TS_PARENT ) ; - mainNode_->pitch( Ogre::Degree( pitch_ * ( vessel_->pitch() * rotFric ) * elapsedTime ), Ogre::Node::TS_PARENT ); - mainNode_->roll( Ogre::Degree( roll_ * ( vessel_->roll() * rotFric ) * elapsedTime ), Ogre::Node::TS_PARENT ); - } - - // mainNode_->rotate( interpolateRot_, Ogre::Node::TS_PARENT ); - - //** friction = drag * v^2; - Ogre::Real friction = ethernalDensity_ * vessel_->dragFactor() * velocity() * velocity(); - - Ogre::Vector3 trustDir( mainNode_->getOrientation().zAxis() ); - Ogre::Vector3 flightDir( vel_ ); flightDir.normalise(); - - updatePowerGrid( elapsedTime ); - - //** thrust = mass * acc; - if ( mass_ > 0 ){ - acc_ = ( - trustDir * thrust() - flightDir * friction ) / mass_; - } else { - std::cerr << "mass: " << mass_ << std::endl; - } - - if ( breakPressed_ == true ) { - if ( velocity() > 0 ) { - acc_ -= flightDir * 4.0; - } - } - - //** v = a * t; - vel_ += acc_ * elapsedTime; - mainNode_->translate( ( vel_ + interpolateVel_ )* elapsedTime ); - - for ( std::set < Projectile * >::iterator it = projectiles_.begin(); it != projectiles_.end();){ - if ( !(*it)->update( elapsedTime ) ) { - delete *it; - projectiles_.erase( it++ ); - } else ++it; - } - - //** object died - if ( armor_ <= 0 || deathSequence_ ) { - return deathSequence( elapsedTime ); - } - - fire( elapsedTime ); - - //** snap quaternion - Ogre::Quaternion rnd( mainNode_->getOrientation() ); - mainNode_->setOrientation( round( rnd.w, 5 ), round( rnd.x, 5 ), round( rnd.y, 5 ), round( rnd.z, 5 ) ); - - return true; -} - -bool SectorObjectMoveable::updatePowerGrid( Ogre::Real elapsedTime ){ - double powerLine = 0.0; - if ( vessel_->powerPlant() ) powerLine = vessel_->powerPlant()->powerOutput(); - - double engineIn = 0.0; - if ( vessel_->engine() ) { - engineIn = vessel_->engine()->powerConsumption() * percentageThrust_ / 100; - engineIn = min( engineIn, powerLine ); - thrust_ = engineIn * 1000 * vessel_->engine()->efficiency(); - } else { - thrust_ = 0.0; - } - powerLine -= engineIn; - powerLine = max( 0.0, powerLine ); - - double shieldIn = 0; - if ( vessel_->shield() ){ - shieldIn = min( vessel_->shield()->powerConsumption(), powerLine ); - shield_ += shieldIn * vessel_->shield()->efficiency() * elapsedTime; - shield_ = min( shield_, maxShield() ); - } - - powerLine -= shieldIn; - powerLine = max( 0.0, powerLine ); - - if ( vessel_->capacitor() ){ - capacity_ += powerLine * vessel_->capacitor()->efficiency() * elapsedTime; - capacity_ = min( (long)capacity_, vessel_->capacitor()->capacity() ); - } - return true; -} - void SectorObjectMoveable::inititializeVesselStats_(){ - mass_ = vessel_->totalMass(); - shield_ = maxShield(); - capacity_ = maxCapacity(); armor_ = maxArmor(); - yaw_ = 0; roll_ = 0; pitch_ = 0; - ammoSpeed_ = 1000; - velocity_ = 0.0; acceleration_ = 0.0; - percentageThrust_ = 0.0; shotsFired_ = 0; //** increase this value to add some fog-friction; ethernalDensity_ = 1.0; @@ -556,7 +495,7 @@ afterburnerPressed_ = false; flashfire_ = false; firePressed_ = false; - fireDelay_ = 0; + vel_ = Ogre::Vector3( 0.0, 0.0, 0.0 ); interpolateRot_ = Ogre::Quaternion( 1.0, 0.0, 0.0, 0.0 ); @@ -577,14 +516,15 @@ void SectorObjectMoveable::updateThruster(){ if ( thrusterParticles_ ){ int nEmits = thrusterParticles_->getNumEmitters( ); - Ogre::Real thrust = thrustPercent(); + Ogre::Real thrustRate = 0; + if ( maxThrust() > 0 ) thrustRate = thrust() / maxThrust(); for ( int i = 0; i < nEmits; i ++ ){ Ogre::ParticleEmitter * pEmit; pEmit = thrusterParticles_->getEmitter( i ); - pEmit->setTimeToLive( thrust / 3000.0 ); - pEmit->setEmissionRate( thrust * 10.0 ); - pEmit->setParticleVelocity( thrust * 5.0 ); + pEmit->setTimeToLive( thrustRate / 3000.0 ); + pEmit->setEmissionRate( thrustRate * 10.0 ); + pEmit->setParticleVelocity( thrustRate * 5.0 ); if ( afterburnerPressed_ ) { pEmit->setColour( Ogre::ColourValue::Blue, Ogre::ColourValue::Red); @@ -595,15 +535,79 @@ } } -void SectorObjectMoveable::fire( Ogre::Real elapsedTime ){ +bool SectorObjectMoveable::deathSequence( Ogre::Real elapsedTime ){ + if ( !deathSequence_ ){ + setVisible( false ); + setSelectable( false ); + sector_->selectNextTarget( this ); + LogManager::getSingleton().info( name_ + " destroyed." ); + if ( !explosion_ ){ + explosion_ = sceneMgr_->createParticleSystem( name_ + "ExplosionSystem", "OpenGate/ExplosionStart" ); + mainNode_->attachObject( explosion_ ); + } + explosion_->getEmitter( 0 )->setEnabled( true ); + explodeSequenceTime_ = explosion_->getEmitter( 0 )->getDuration() + explosion_->getEmitter( 0 )->getMaxTimeToLive(); + + if ( thrusterBbs_ ) thrusterBbs_->setVisible( false ); + thrust_ = 0; + updateThruster(); + deathSequence_ = true; + } + + explodeSequenceTime_ -= elapsedTime; + + if ( explodeSequenceTime_ > 0 || projectiles_.size() > 0 ) { + return true; + } else { + if ( explosion_ ) explosion_->getEmitter( 0 )->setEnabled( false ); + return false; + } +} + +SectorObjectMoveableLocal::SectorObjectMoveableLocal( const Ogre::String & name, Sector * sector, long userID, int childID, + Vessel * vessel ) + : SectorObjectMoveable( name, sector, userID, childID, vessel ){ + + setMass( vessel_->totalMass() ); + + maxThrust_ = 0; + if ( vessel_->engine() ){ + maxThrust_ = vessel_->engine()->maxThrust(); + } + + maxShield_ = 0; + if ( vessel_->shield() ) maxShield_ = vessel_->shield()->maxDeflection(); + shield_ = maxShield_; +} + +bool SectorObjectMoveableLocal::update( Ogre::Real elapsedTime ){ + SectorObjectMoveable::update( elapsedTime ); + + //** object died + if ( armor_ <= 0 || deathSequence_ ) { + return deathSequence( elapsedTime ); + } + + if ( statusChanged_ ){ + sector_->sendVesselStatus( this ); + statusChanged_ = false; + lastShieldSend_ = shield_; + }; + + fire( elapsedTime ); + return true; +} + +void SectorObjectMoveableLocal::fire( Ogre::Real elapsedTime ){ + Ogre::Real delayTime = 0.2; fireDelay_ -= elapsedTime; if ( fireDelay_ <= 0 ){ - Ogre::Real damage = 500.0; + Uint32 damage = 500000; if ( firePressed_ ){ if ( capacity_ > damage ){ projectiles_.insert( new Projectile( this, shotsFired_, ammoSpeed_ ) ); @@ -626,41 +630,56 @@ } } -bool SectorObjectMoveable::deathSequence( Ogre::Real elapsedTime ){ - if ( !deathSequence_ ){ - setVisible( false ); - setSelectable( false ); - sector_->selectNextTarget( this ); - LogManager::getSingleton().info( name_ + " destroyed." ); +void SectorObjectMoveableLocal::hitByAmmo( Uint32 damage ){ - if ( !explosion_ ){ - explosion_ = sceneMgr_->createParticleSystem( name_ + "ExplosionSystem", "OpenGate/ExplosionStart" ); - mainNode_->attachObject( explosion_ ); - } - explosion_->getEmitter( 0 )->setEnabled( true ); - explodeSequenceTime_ = explosion_->getEmitter( 0 )->getDuration() + explosion_->getEmitter( 0 )->getMaxTimeToLive(); + shield_ -= damage; - - if ( thrusterBbs_ ) thrusterBbs_->setVisible( false ); - percentageThrust_ = 0; - updateThruster(); - deathSequence_ = true; + if ( shield_ < 0 ){ + armor_ += shield_; + shield_ = 0; + armor_ = max( 0, armor_); } + statusChanged_ = true; +} - explodeSequenceTime_ -= elapsedTime; +bool SectorObjectMoveableLocal::updatePowerGrid( Ogre::Real elapsedTime ){ + Uint32 powerLine = 0; + if ( vessel_->powerPlant() ) powerLine = vessel_->powerPlant()->powerOutput(); - if ( explodeSequenceTime_ > 0 || projectiles_.size() > 0 ) { - return true; + Uint32 engineIn = 0; + if ( vessel_->engine() ) { + engineIn = (Uint32)rint( vessel_->engine()->powerConsumption() * thrustRate_ ); + engineIn = min( engineIn, powerLine ); + thrust_ = (Uint32)rint( engineIn * vessel_->engine()->efficiency() ); } else { - if ( explosion_ ) explosion_->getEmitter( 0 )->setEnabled( false ); - return false; + thrust_ = 0; } + powerLine -= engineIn; + powerLine = max( 0, powerLine ); + + Uint32 shieldIn = 0; + if ( vessel_->shield() ){ + shieldIn = min( vessel_->shield()->powerConsumption(), powerLine ); + shield_ += (Uint32)rint( shieldIn * vessel_->shield()->efficiency() * elapsedTime ); + shield_ = min( shield_, maxShield() ); + + if ( (float)( shield_ - lastShieldSend_ ) / (float)maxShield() > 0.01 ) statusChanged_ = true; + } + + powerLine -= shieldIn; + powerLine = max( 0, powerLine ); + + if ( vessel_->capacitor() ){ + capacity_ += (Uint32)rint( (Ogre::Real)powerLine * vessel_->capacitor()->efficiency() * elapsedTime ); + capacity_ = min( capacity_, vessel_->capacitor()->capacity() ); + } + return true; } SectorObjectMoveableAi::SectorObjectMoveableAi( const Ogre::String & name, Sector * sector, long userID, int childID, Vessel * vessel ) - : SectorObjectMoveable( name, sector, userID, childID, vessel ){ + : SectorObjectMoveableLocal( name, sector, userID, childID, vessel ){ } bool SectorObjectMoveableAi::update( Ogre::Real elapsedTime ){ @@ -709,18 +728,22 @@ // searchTarget; } - if ( statusChanged_ ){ - sector_->sendVesselStatus( this ); - statusChanged_ = false; - }; - - return SectorObjectMoveable::update( elapsedTime ); + return SectorObjectMoveableLocal::update( elapsedTime ); } -SectorObjectAvatar::SectorObjectAvatar( const Ogre::String & name, Sector * sector, long userID, - Vessel * vessel ) - : SectorObjectMoveable( name, sector, userID, 0, vessel ) { +SectorObjectAvatar::SectorObjectAvatar( const Ogre::String & name, Sector * sector, long userID, Vessel * vessel ) + : SectorObjectMoveableLocal( name, sector, userID, 0, vessel ) { + ammoSpeed_ = 1000; + + thrustRate_ = 0; + + maxCapacity_ = 0; + if ( vessel_->capacitor() ) maxCapacity_ = vessel_->capacitor()->capacity(); + capacity_ = maxCapacity_; + + fireDelay_ = 0; + targetArrow_ = NULL; flightArrow_ = NULL; forceMovement_ = false; @@ -779,19 +802,17 @@ } bool SectorObjectAvatar::update( Ogre::Real elapsedTime ){ - if ( statusChanged_ ){ - sector_->sendVesselStatus( this ); - statusChanged_ = false; - }; - return SectorObjectMoveable::update( elapsedTime ); + updatePowerGrid( elapsedTime ); + + return SectorObjectMoveableLocal::update( elapsedTime ); } void SectorObjectAvatar::reset( ){ deathSequence_ = false; mainNode_->showBoundingBox( false ); - setShieldPercent( 100 ); - setArmorPercent( 100 ); - setThrustPercent( 0.0 ); + setShield( maxShield() ); + setArmor( maxArmor() ); + setThrust( 0 ); } bool SectorObjectAvatar::deathSequence( Ogre::Real elapsedTime ){ Modified: branches/ogsector/src/SectorObjects.h =================================================================== --- branches/ogsector/src/SectorObjects.h 2007-06-17 13:48:07 UTC (rev 563) +++ branches/ogsector/src/SectorObjects.h 2007-06-17 13:51:31 UTC (rev 564) @@ -66,11 +66,11 @@ virtual bool update( Ogre::Real elapsedTime ) = 0; - virtual void hitByAmmo( float damage ){} + virtual void hitByAmmo( Uint32 damage ){} Sector * sector( ) { return sector_; } - virtual Ogre::Vector3 velDirection() const = 0; + virtual Ogre::Vector3 velocity() const = 0; bool selectable() const { return selectable_ ;} @@ -100,7 +100,7 @@ virtual void collide( BaseObject * object ); - inline Ogre::Real damage( ) const { return damage_; } + inline Uint32 damage( ) const { return damage_; } virtual bool update( Ogre::Real elapsedTime ); @@ -108,7 +108,7 @@ BaseObject & parent( ) const { return *parent_; } - Ogre::Vector3 velDirection() const { return vel_; } + Ogre::Vector3 velocity() const { return vel_; } protected: BaseObject * parent_; @@ -119,7 +119,7 @@ Ogre::Real maxLiveTime_; Ogre::Real oldTime_; - Ogre::Real damage_; + Uint32 damage_; }; class SectorObject : public BaseObject { @@ -151,7 +151,7 @@ bool isOnRadar() const { return isOnRadar_; } void onRadar( bool onradar ) { isOnRadar_ = onradar; } - virtual Ogre::Vector3 velDirection() const { return Ogre::Vector3(0.0, 0.0, 0.0 ); } + virtual Ogre::Vector3 velocity() const { return Ogre::Vector3(0.0, 0.0, 0.0 ); } Ogre::OverlayElement * dotA() { return dotA_; } Ogre::OverlayElement * dotB() { return dotB_; } @@ -168,152 +168,133 @@ double baseSize_; }; +/*! Base class for movable objects, instances are only used for foreign player objects. */ + class SectorObjectMoveable : public SectorObject { public: SectorObjectMoveable( const Ogre::String & name, Sector * sector, int userID, int childID, Vessel * vessel ); virtual ~SectorObjectMoveable(); + /*! Returns a handle to the actual vessel */ Vessel * vessel(){ return vessel_; } inline virtual long getTypeID() const { return SECTOROBJECTMOVABLE_RTTI; } + virtual bool update( Ogre::Real elapsedTime ); + + /*! Change visibility - Useful for 1st person view and death sequence */ + inline void setVisible( bool visible ) { mainNodeEntity_->setVisible( visible ); } + + /*! Apply movement from net.*/ void setFlightProperties( const MessageBodyShipMovement & msg ); + /*! Apply status from net.*/ void setStatus( const MessageBodyShipStatus & msg ); + /*! Decide what happen if this object collide with another. */ virtual void collide( BaseObject * object ); - virtual bool update( Ogre::Real elapsedTime ); - virtual bool updatePowerGrid( Ogre::Real elapsedTime ); - - virtual void hitByAmmo( float damage ); - + /*! Set relative yaw, between 0 and 1. */ + inline void setScaledYaw( float rot ){ yaw_ = rot; } inline Ogre::Real scaledYaw() const { return yaw_; } - inline void setScaledYaw( float rot ){ yaw_ = rot; } + /*! Set relative pitch, between 0 and 1. */ + inline void setScaledPitch( float rot ){ pitch_ = rot; } inline Ogre::Real scaledPitch() const { return pitch_; } - inline void setScaledPitch( float rot ){ pitch_ = rot; } + /*! Set relative roll, between 0 and 1. */ + inline void setScaledRoll( float rot ){ roll_ = rot; } inline Ogre::Real scaledRoll() const { return roll_; } - inline void setScaledRoll( float rot ){ roll_ = rot; } - Ogre::Real rotFriction(){ return 0.4 + ( 0.6 * ( 100.0 - percentageThrust_ )/ 100.0 ); } + /*! Calculate friction factor for yaw, pitch, roll, friction increase by thrust */ + inline Ogre::Real rotFriction(){ return 0.4 + ( 0.6 * ( 1.0 - thrustRate() ) ); } - // Change visibility - Useful for 1st person view - inline void setVisible( bool visible ) { mainNodeEntity_->setVisible( visible ); } + /*! Update visual feedback for thrusters */ + void updateThruster(); + /*! Set the current thrust */ + inline void setThrust( Uint32 thrust ) { thrust_ = thrust; updateThruster(); } - inline void setThrustPercent( Ogre::Real thrust ) { - percentageThrust_ = min( thrust, Ogre::Real( 100.0 ) ); - percentageThrust_ = max( Ogre::Real( 0.0 ), thrust ); - updateThruster(); - } + /*! Return the current thrust */ + virtual inline Uint32 thrust() const { return thrust_; } - inline Ogre::Real maxThrust() const { return vessel_->maxThrust(); } - inline Ogre::Real thrustRate() const { - if ( maxThrust() > 1e-4 ) return ( thrust() / maxThrust() ); else return 0.0; ... [truncated message content] |