void CVehicle::SetModel ( unsigned short usModel ) { if ( usModel != m_usModel ) { m_usModel = usModel; RandomizeColor (); GetInitialDoorStates ( m_ucDoorStates ); } }
void CVehicle::SetModel ( unsigned short usModel ) { if ( usModel != m_usModel ) { m_usModel = usModel; m_eVehicleType = CVehicleManager::GetVehicleType ( m_usModel ); RandomizeColor (); GetInitialDoorStates ( m_ucDoorStates ); // Generate new handling data to fit the vehicle GenerateHandlingData (); } }
void CVehicle::SetModel ( unsigned short usModel ) { if ( usModel != m_usModel ) { m_usModel = usModel; m_eVehicleType = CVehicleManager::GetVehicleType ( m_usModel ); RandomizeColor (); ResetDoors (); CVehicleManager::GetRandomVariation ( m_usModel, m_ucVariant, m_ucVariant2 ); // Generate new handling data to fit the vehicle GenerateHandlingData (); } }
CVehicle::CVehicle ( CVehicleManager* pVehicleManager, CElement* pParent, CXMLNode* pNode, unsigned short usModel ) : CElement ( pParent, pNode ) { // Init m_pVehicleManager = pVehicleManager; m_usModel = usModel; m_pUpgrades = new CVehicleUpgrades ( this ); m_iType = CElement::VEHICLE; SetTypeName ( "vehicle" ); m_eVehicleType = CVehicleManager::GetVehicleType ( m_usModel ); m_fHealth = DEFAULT_VEHICLE_HEALTH; m_ulHealthChangeTime = 0; m_ulBlowTime = 0; m_ulIdleTime = GetTickCount (); m_fTurretPositionX = 0; m_fTurretPositionY = 0; m_bSirenActive = false; m_bLandingGearDown = true; m_usAdjustableProperty = 0; m_bIsFrozen = false; m_bUnoccupiedSyncable = true; m_pSyncer = NULL; GetInitialDoorStates ( m_ucDoorStates ); memset ( m_ucWheelStates, 0, sizeof ( m_ucWheelStates ) ); memset ( m_ucPanelStates, 0, sizeof ( m_ucPanelStates ) ); memset ( m_ucLightStates, 0, sizeof ( m_ucLightStates ) ); m_ucOverrideLights = 0; m_pTowedVehicle = NULL; m_pTowedByVehicle = NULL; m_ucPaintjob = 3; m_ucMaxPassengersOverride = VEHICLE_PASSENGERS_UNDEFINED; m_bRespawnInfoChanged = false; m_fRespawnHealth = DEFAULT_VEHICLE_HEALTH; m_bRespawnEnabled = false; m_ulRespawnTime = 10000; m_ulIdleRespawnTime = 60000; m_bEngineOn = false; m_bLocked = false; m_bDoorsUndamageable = false; m_bDamageProof = false; m_bGunsEnabled = false; m_bFuelTankExplodable = false; m_bOnGround = true; m_bSmokeTrail = false; m_ucAlpha = 255; m_pJackingPlayer = NULL; m_bInWater = false; m_bDerailed = false; m_bIsDerailable = true; m_bTaxiLightState = false; m_bTrainDirection = true; m_HeadLightColor = SColorRGBA ( 255, 255, 255, 255 ); m_bHeliSearchLightVisible = false; // Initialize the occupied Players for ( int i = 0; i < MAX_VEHICLE_SEATS; i++ ) { m_pOccupants [i] = NULL; } // Add us to the vehicle manager pVehicleManager->AddToList ( this ); // Randomize our color RandomizeColor (); // Generate a random reg plate GenerateRegPlate (); }
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; }
CVehicle::CVehicle ( CVehicleManager* pVehicleManager, CElement* pParent, CXMLNode* pNode, unsigned short usModel, unsigned char ucVariant, unsigned char ucVariant2 ) : CElement ( pParent, pNode ) { CElementRefManager::AddElementRefs ( ELEMENT_REF_DEBUG ( this, "CVehicle" ), &m_pTowedVehicle, &m_pTowedByVehicle, &m_pSyncer, &m_pJackingPlayer, NULL ); // Init m_pVehicleManager = pVehicleManager; m_usModel = usModel; m_pUpgrades = new CVehicleUpgrades ( this ); m_iType = CElement::VEHICLE; SetTypeName ( "vehicle" ); m_eVehicleType = CVehicleManager::GetVehicleType ( m_usModel ); m_fHealth = DEFAULT_VEHICLE_HEALTH; m_fLastSyncedHealthHealth = DEFAULT_VEHICLE_HEALTH; m_ulHealthChangeTime = 0; m_llIdleTime = CTickCount::Now (); m_fTurretPositionX = 0; m_fTurretPositionY = 0; m_bSirenActive = false; m_bLandingGearDown = true; m_usAdjustableProperty = 0; m_bIsFrozen = false; m_bUnoccupiedSyncable = true; m_pSyncer = NULL; GetInitialDoorStates ( m_ucDoorStates ); memset ( &m_ucWheelStates[0], 0, sizeof ( m_ucWheelStates ) ); memset ( &m_ucPanelStates[0], 0, sizeof ( m_ucPanelStates ) ); memset ( &m_ucLightStates[0], 0, sizeof ( m_ucLightStates ) ); m_ucOverrideLights = 0; m_pTowedVehicle = NULL; m_pTowedByVehicle = NULL; m_ucPaintjob = 3; m_ucMaxPassengersOverride = VEHICLE_PASSENGERS_UNDEFINED; m_pHandlingEntry = NULL; m_fRespawnHealth = DEFAULT_VEHICLE_HEALTH; m_bRespawnEnabled = false; m_ulBlowRespawnInterval = 10000; m_ulIdleRespawnInterval = 60000; m_bEngineOn = false; for ( unsigned int i = 0; i < 6; ++i ) m_fDoorOpenRatio [ i ] = 0.0f; m_bLocked = false; m_bDoorsUndamageable = false; m_bDamageProof = false; m_bGunsEnabled = false; m_bFuelTankExplodable = false; m_bOnGround = true; m_bSmokeTrail = false; m_ucAlpha = 255; m_pJackingPlayer = NULL; m_bInWater = false; m_bDerailed = false; m_bIsDerailable = true; m_fTrainSpeed = 0.0f; m_fTrainPosition = 0.0f; m_ucTrackID = 0; m_bTaxiLightState = false; m_bTrainDirection = false; m_HeadLightColor = SColorRGBA ( 255, 255, 255, 255 ); m_bHeliSearchLightVisible = false; m_bCollisionsEnabled = true; m_bHandlingChanged = false; m_ucVariant = ucVariant; m_ucVariant2 = ucVariant2; // Initialize the occupied Players for ( int i = 0; i < MAX_VEHICLE_SEATS; i++ ) { m_pOccupants [i] = NULL; } // Add us to the vehicle manager pVehicleManager->AddToList ( this ); // Randomize our color RandomizeColor (); // Generate a random reg plate GenerateRegPlate (); // Generate the handling data GenerateHandlingData (); // Prepare the sirens RemoveVehicleSirens(); m_tSirenBeaconInfo.m_bOverrideSirens = false; }