bool CVehicle::ReadSpecialData ( void ) { // Grab the "posX" data if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "posY" data if ( !GetCustomDataFloat ( "posY", m_vecPosition.fY, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posY' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "posZ" data if ( !GetCustomDataFloat ( "posZ", m_vecPosition.fZ, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posZ' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "rotX", "rotY" and "rotZ" data GetCustomDataFloat ( "rotX", m_vecRotationDegrees.fX, true ); GetCustomDataFloat ( "rotY", m_vecRotationDegrees.fY, true ); GetCustomDataFloat ( "rotZ", m_vecRotationDegrees.fZ, true ); // Wrap them around 360 m_vecRotationDegrees.fX = WrapAround ( m_vecRotationDegrees.fX, 360.0f ); m_vecRotationDegrees.fY = WrapAround ( m_vecRotationDegrees.fY, 360.0f ); m_vecRotationDegrees.fZ = WrapAround ( m_vecRotationDegrees.fZ, 360.0f ); // Set the respawn matrix SetRespawnPosition ( m_vecPosition ); SetRespawnRotationDegrees ( m_vecRotationDegrees ); // Grab the "model" data int iTemp; if ( GetCustomDataInt ( "model", iTemp, true ) ) { // Is it valid? if ( CVehicleManager::IsValidModel ( iTemp ) ) { // Remember it and generate a new random color m_usModel = static_cast < unsigned short > ( iTemp ); m_Color = RandomizeColor (); GetInitialDoorStates ( m_ucDoorStates ); m_usAdjustableProperty = 0; } else { CLogger::ErrorPrintf ( "Bad 'model'(%d) id specified in <vehicle> (line %u)\n", iTemp, m_uiLine ); return false; } } else { CLogger::ErrorPrintf ( "Bad/missing 'model' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "turretX" data if ( GetCustomDataFloat ( "turretX", m_fTurretPositionX, true ) ) { m_fTurretPositionX = ConvertDegreesToRadians ( m_fTurretPositionX ); } // Grab the "turretY" data if ( GetCustomDataFloat ( "turretY", m_fTurretPositionY, true ) ) { m_fTurretPositionY = ConvertDegreesToRadians ( m_fTurretPositionY ); } // Grab the "health" data if ( GetCustomDataFloat ( "health", m_fHealth, true ) ) { if ( m_fHealth < 0.0f ) m_fHealth = 0.0f; } // Grab the "Sirens" data if ( !GetCustomDataBool ( "sirens", m_bSirenActive, true ) ) { m_bSirenActive = false; } // Grab the "landingGearDown" data if ( !GetCustomDataBool ( "landingGearDown", m_bLandingGearDown, true ) ) { m_bLandingGearDown = true; } if ( !GetCustomDataBool ( "locked", m_bLocked, true ) ) { m_bLocked = false; } // Grab the "specialState" data if ( GetCustomDataInt ( "specialState", iTemp, true ) ) { m_usAdjustableProperty = static_cast < unsigned short > ( iTemp ); } else { m_usAdjustableProperty = 0; } // Grab the "color" data char szTemp [ 256 ]; if ( GetCustomDataString ( "color", szTemp, 256, true ) ) { char* sz1 = strtok ( szTemp, "," ); char* sz2 = strtok ( NULL, "," ); char* sz3 = strtok ( NULL, "," ); char* sz4 = strtok ( NULL, "," ); if ( sz1 ) m_Color.SetColor1 ( atoi ( sz1 ) ); if ( sz2 ) m_Color.SetColor2 ( atoi ( sz2 ) ); if ( sz3 ) m_Color.SetColor3 ( atoi ( sz3 ) ); if ( sz4 ) m_Color.SetColor4 ( atoi ( sz4 ) ); } if ( GetCustomDataInt ( "paintjob", iTemp, true ) ) m_ucPaintjob = static_cast < unsigned char > ( iTemp ); if ( GetCustomDataString ( "upgrades", szTemp, 256, true ) ) { if ( m_pUpgrades ) { if ( strcmp ( szTemp, "all" ) == 0 ) { m_pUpgrades->AddAllUpgrades (); } else { bool bTemp = true; while ( char* token = strtok ( ( bTemp ) ? szTemp : NULL, "," ) ) { bTemp = false; unsigned short usUpgrade = static_cast < unsigned short > ( atoi ( token ) ); if ( CVehicleUpgrades::IsValidUpgrade ( usUpgrade ) ) { m_pUpgrades->AddUpgrade ( usUpgrade ); } } } } } if ( GetCustomDataString ( "plate", szTemp, 9, true ) ) { SetRegPlate ( szTemp ); } if ( GetCustomDataInt ( "interior", iTemp, true ) ) m_ucInterior = static_cast < unsigned char > ( iTemp ); if ( GetCustomDataInt ( "dimension", iTemp, true ) ) m_usDimension = static_cast < unsigned short > ( iTemp ); return true; }
bool CVehicle::ReadSpecialData ( void ) { // Grab the "posX" data if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "posY" data if ( !GetCustomDataFloat ( "posY", m_vecPosition.fY, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posY' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "posZ" data if ( !GetCustomDataFloat ( "posZ", m_vecPosition.fZ, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posZ' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the "rotX", "rotY" and "rotZ" data GetCustomDataFloat ( "rotX", m_vecRotationDegrees.fX, true ); GetCustomDataFloat ( "rotY", m_vecRotationDegrees.fY, true ); GetCustomDataFloat ( "rotZ", m_vecRotationDegrees.fZ, true ); // Wrap them around 360 m_vecRotationDegrees.fX = WrapAround ( m_vecRotationDegrees.fX, 360.0f ); m_vecRotationDegrees.fY = WrapAround ( m_vecRotationDegrees.fY, 360.0f ); m_vecRotationDegrees.fZ = WrapAround ( m_vecRotationDegrees.fZ, 360.0f ); // Set the respawn matrix SetRespawnPosition ( m_vecPosition ); SetRespawnRotationDegrees ( m_vecRotationDegrees ); // Grab the "model" data int iTemp; if ( GetCustomDataInt ( "model", iTemp, true ) ) { // Is it valid? if ( CVehicleManager::IsValidModel ( iTemp ) ) { // Remember it and generate a new random color SetModel ( static_cast < unsigned short > ( iTemp ) ); m_usAdjustableProperty = 0; } else { CLogger::ErrorPrintf ( "Bad 'model'(%d) id specified in <vehicle> (line %u)\n", iTemp, m_uiLine ); return false; } } else { CLogger::ErrorPrintf ( "Bad/missing 'model' attribute in <vehicle> (line %u)\n", m_uiLine ); return false; } // Grab the variant data if ( GetCustomDataInt ( "variant1", iTemp, true ) ) { m_ucVariant = static_cast < unsigned char > ( iTemp ); } if ( GetCustomDataInt ( "variant2", iTemp, true ) ) { m_ucVariant2 = static_cast < unsigned char > ( iTemp ); } if ( m_ucVariant == 254 && m_ucVariant2 == 254 ) CVehicleManager::GetRandomVariation ( m_usModel, m_ucVariant, m_ucVariant2 ); // Grab the "turretX" data if ( GetCustomDataFloat ( "turretX", m_fTurretPositionX, true ) ) { m_fTurretPositionX = ConvertDegreesToRadians ( m_fTurretPositionX ); } // Grab the "turretY" data if ( GetCustomDataFloat ( "turretY", m_fTurretPositionY, true ) ) { m_fTurretPositionY = ConvertDegreesToRadians ( m_fTurretPositionY ); } // Grab the "health" data if ( GetCustomDataFloat ( "health", m_fHealth, true ) ) { if ( m_fHealth < 0.0f ) m_fHealth = 0.0f; } // Grab the "Sirens" data if ( !GetCustomDataBool ( "sirens", m_bSirenActive, true ) ) { m_bSirenActive = false; } // Grab the "landingGearDown" data if ( !GetCustomDataBool ( "landingGearDown", m_bLandingGearDown, true ) ) { m_bLandingGearDown = true; } if ( !GetCustomDataBool ( "locked", m_bLocked, true ) ) { m_bLocked = false; } // Grab the "specialState" data if ( GetCustomDataInt ( "specialState", iTemp, true ) ) { m_usAdjustableProperty = static_cast < unsigned short > ( iTemp ); } else { m_usAdjustableProperty = 0; } // Grab the "color" data char szTemp [ 256 ]; if ( GetCustomDataString ( "color", szTemp, 256, true ) ) { uchar ucValues[12] = { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 }; char* sz1 = strtok ( szTemp, ", " ); if ( sz1 ) ucValues[0] = atoi ( sz1 ); int i; for ( i = 1 ; i < 12 ; i++ ) { char* szn = strtok ( NULL, ", " ); if ( !szn ) break; ucValues[i] = atoi ( szn ); } if ( i == 3 || i == 6 || i == 9 || i == 12 ) { m_Color.SetRGBColors ( SColorRGBA ( ucValues[0], ucValues[1], ucValues[2], 0 ), SColorRGBA ( ucValues[3], ucValues[4], ucValues[5], 0 ), SColorRGBA ( ucValues[6], ucValues[7], ucValues[8], 0 ), SColorRGBA ( ucValues[9], ucValues[10], ucValues[11], 0 ) ); } else { m_Color.SetPaletteColors ( ucValues[0], ucValues[1], ucValues[2], ucValues[3] ); } } if ( GetCustomDataInt ( "paintjob", iTemp, true ) ) m_ucPaintjob = static_cast < unsigned char > ( iTemp ); if ( GetCustomDataString ( "upgrades", szTemp, 256, true ) ) { if ( m_pUpgrades ) { if ( strcmp ( szTemp, "all" ) == 0 ) { m_pUpgrades->AddAllUpgrades (); } else { bool bTemp = true; while ( char* token = strtok ( ( bTemp ) ? szTemp : NULL, ", " ) ) { bTemp = false; unsigned short usUpgrade = static_cast < unsigned short > ( atoi ( token ) ); if ( CVehicleUpgrades::IsValidUpgrade ( usUpgrade ) ) { m_pUpgrades->AddUpgrade ( usUpgrade ); } } } } } if ( GetCustomDataString ( "plate", szTemp, 9, true ) ) SetRegPlate ( szTemp ); if ( GetCustomDataInt ( "interior", iTemp, true ) ) m_ucInterior = static_cast < unsigned char > ( iTemp ); if ( GetCustomDataInt ( "dimension", iTemp, true ) ) m_usDimension = static_cast < unsigned short > ( iTemp ); if ( !GetCustomDataBool ( "collisions", m_bCollisionsEnabled, true ) ) m_bCollisionsEnabled = true; if ( GetCustomDataInt ( "alpha", iTemp, true ) ) m_ucAlpha = static_cast < unsigned char > ( iTemp ); bool bFrozen; if ( GetCustomDataBool ( "frozen", bFrozen, true ) ) m_bIsFrozen = bFrozen; return true; }