bool CElement::LoadFromCustomData ( CLuaMain* pLuaMain, CEvents* pEvents ) { assert ( pLuaMain ); assert ( pEvents ); // Mark this as an MAP created element m_bMapCreated = true; // Read out all the attributes into our custom data records ReadCustomData ( pLuaMain, pEvents ); // Grab the "id" custom data into our m_strName member char szBuf[MAX_ELEMENT_NAME_LENGTH + 1] = {0}; GetCustomDataString ( "id", szBuf, MAX_ELEMENT_NAME_LENGTH, false ); m_strName = szBuf; // Grab the attaching custom data GetCustomDataString ( "attachTo", m_szAttachToID, MAX_ELEMENT_NAME_LENGTH, true ); GetCustomDataFloat ( "attachX", m_vecAttachedPosition.fX, true ); GetCustomDataFloat ( "attachY", m_vecAttachedPosition.fY, true ); GetCustomDataFloat ( "attachZ", m_vecAttachedPosition.fZ, true ); // Load the special attributes from our custom data return ReadSpecialData (); }
bool CTeam::ReadSpecialData(void) { // Grab the "name" char szTemp[MAX_TEAM_NAME]; if (GetCustomDataString("name", szTemp, MAX_TEAM_NAME, true)) { SetTeamName(szTemp); } else { CLogger::ErrorPrintf("Bad/missing name' attribute in <team> (line %u)\n", m_uiLine); return false; } // Grab the "color" data int iTemp; if (GetCustomDataString("color", szTemp, MAX_TEAM_NAME, true)) { // Convert it to RGBA unsigned char ucAlpha; if (!XMLColorToInt(szTemp, m_ucRed, m_ucGreen, m_ucBlue, ucAlpha)) { CLogger::ErrorPrintf("Bad 'color' value specified in <team> (line %u)\n", m_uiLine); return false; } } else { if (GetCustomDataInt("colorR", iTemp, true)) m_ucRed = static_cast<unsigned char>(iTemp); else m_ucRed = 255; if (GetCustomDataInt("colorG", iTemp, true)) m_ucGreen = static_cast<unsigned char>(iTemp); else m_ucGreen = 255; if (GetCustomDataInt("colorB", iTemp, true)) m_ucBlue = static_cast<unsigned char>(iTemp); else m_ucBlue = 255; } if (!GetCustomDataBool("friendlyfire", m_bFriendlyFire, true)) { m_bFriendlyFire = true; } if (GetCustomDataInt("dimension", iTemp, true)) m_usDimension = static_cast<unsigned short>(iTemp); return true; }
bool CRadarArea::ReadSpecialData ( void ) { // Grab the "posX" data if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <radararea> (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 <radararea> (line %u)\n", m_uiLine ); return false; } // Grab the "sizeX" data if ( !GetCustomDataFloat ( "sizeX", m_vecSize.fX, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'sizeX' attribute in <radararea> (line %u)\n", m_uiLine ); return false; } // Grab the "sizeY" data if ( !GetCustomDataFloat ( "sizeY", m_vecSize.fY, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'sizeY' attribute in <radararea> (line %u)\n", m_uiLine ); return false; } // Grab the "color" data char szColor [64]; if ( GetCustomDataString ( "color", szColor, 64, true ) ) { // Convert it to RGBA if ( !XMLColorToInt ( szColor, m_Color.R, m_Color.G, m_Color.B, m_Color.A ) ) { CLogger::ErrorPrintf ( "Bad 'color' value specified in <radararea> (line %u)\n", m_uiLine ); return false; } } else { m_Color = SColorRGBA ( 255, 0, 0, 255 ); } int iTemp; if ( GetCustomDataInt ( "dimension", iTemp, true ) ) m_usDimension = static_cast < unsigned short > ( iTemp ); return true; }
bool CElement::LoadFromCustomData ( CEvents* pEvents ) { assert ( pEvents ); // Read out all the attributes into our custom data records ReadCustomData ( pEvents ); // Grab the "id" custom data into our m_strName member char szBuf[MAX_ELEMENT_NAME_LENGTH + 1] = {0}; GetCustomDataString ( "id", szBuf, MAX_ELEMENT_NAME_LENGTH, false ); m_strName = szBuf; // Grab the attaching custom data szBuf[0] = 0; GetCustomDataString ( "attachTo", szBuf, MAX_ELEMENT_NAME_LENGTH, true ); m_strAttachToID = szBuf; GetCustomDataFloat ( "attachX", m_vecAttachedPosition.fX, true ); GetCustomDataFloat ( "attachY", m_vecAttachedPosition.fY, true ); GetCustomDataFloat ( "attachZ", m_vecAttachedPosition.fZ, true ); // Load the special attributes from our custom data return ReadSpecialData (); }
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; }
bool CMarker::ReadSpecialData ( void ) { // Grab the "posX" data if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <marker> (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 <marker> (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 <marker> (line %u)\n", m_uiLine ); return false; } // Set the position in the col object if ( m_pCollision ) m_pCollision->SetPosition ( m_vecPosition ); // Grab the "type" data char szBuffer [128]; unsigned char ucType; if ( GetCustomDataString ( "type", szBuffer, 128, true ) ) { // Convert it to a type ucType = static_cast < unsigned char > ( CMarkerManager::StringToType ( szBuffer ) ); if ( ucType == CMarker::TYPE_INVALID ) { CLogger::LogPrintf ( "WARNING: Unknown 'type' value specified in <marker>; defaulting to \"default\" (line %u)\n", m_uiLine ); ucType = CMarker::TYPE_CHECKPOINT; } } else { ucType = CMarker::TYPE_CHECKPOINT; } SetMarkerType(ucType); // Grab the "color" data if ( GetCustomDataString ( "color", szBuffer, 128, true ) ) { // Convert the HTML-style color to RGB if ( !XMLColorToInt ( szBuffer, m_Color.R, m_Color.G, m_Color.B, m_Color.A ) ) { CLogger::ErrorPrintf ( "Bad 'color' specified in <marker> (line %u)\n", m_uiLine ); return false; } } else { SetColor ( SColorRGBA( 255, 0, 0, 255 ) ); } float fSize; if ( GetCustomDataFloat ( "size", fSize, true ) ) m_fSize = fSize; int iTemp; if ( GetCustomDataInt ( "dimension", iTemp, true ) ) m_usDimension = static_cast < unsigned short > ( iTemp ); if ( GetCustomDataInt ( "interior", iTemp, true ) ) m_ucInterior = static_cast < unsigned char > ( iTemp ); // Success return true; }
bool CPickup::ReadSpecialData ( void ) { unsigned short usBuffer = 0; // Grab the "posX" data if ( !GetCustomDataFloat ( "posX", m_vecPosition.fX, true ) ) { CLogger::ErrorPrintf ( "Bad/missing 'posX' attribute in <pickup> (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 <pickup> (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 <pickup> (line %u)\n", m_uiLine ); return false; } // Put the collision object at the given xyz if ( m_pCollision ) m_pCollision->SetPosition ( m_vecPosition ); // Grab the "type" data char szBuffer [128]; if ( GetCustomDataString ( "type", szBuffer, 128, true ) ) { // Check what type it is m_bIsTypeRandom = false; if ( stricmp ( szBuffer, "health" ) == 0 ) { m_ucType = HEALTH; m_usModel = CPickupManager::GetHealthModel (); } else if ( stricmp ( szBuffer, "armor" ) == 0 ) { m_ucType = ARMOR; m_usModel = CPickupManager::GetArmorModel (); } else if ( IsNumericString ( szBuffer ) ) { // could be a weapon usBuffer = atoi ( szBuffer ); if ( CPickupManager::IsValidWeaponID ( usBuffer ) ) { // its a weapon m_ucType = WEAPON; m_usModel = CPickupManager::GetWeaponModel ( m_ucWeaponType ); } } else if ( stricmp ( szBuffer, "custom" ) == 0 ) { m_ucType = CUSTOM; m_usModel = 1700; } else if ( stricmp ( szBuffer, "random" ) == 0 ) { m_ucType = HEALTH; m_usModel = CPickupManager::GetHealthModel (); m_bIsTypeRandom = true; } else { CLogger::LogPrintf ( "WARNING: Unknown 'type' value in <pickup>; defaulting to \"random\" (line %u)\n", m_uiLine ); m_ucType = HEALTH; m_usModel = CPickupManager::GetHealthModel (); m_bIsTypeRandom = true; } } else { CLogger::ErrorPrintf ( "Bad/missing 'type' attribute in <pickup> (line %u)\n", m_uiLine ); return false; } // Is this a weapon pickup? if ( m_ucType == CPickup::WEAPON || m_bIsTypeRandom ) { // Remember the weapon type m_ucWeaponType = static_cast < unsigned char > ( usBuffer ); m_usModel = CPickupManager::GetWeaponModel ( m_ucWeaponType ); m_bIsWeaponTypeRandom = false; } // Is this a health pickup? if ( m_ucType == CPickup::HEALTH || m_ucType == CPickup::ARMOR || m_bIsTypeRandom ) { // Grab the "health" data if ( GetCustomDataString ( "amount", szBuffer, 128, true ) ) { // Is it random? if ( strcmp ( szBuffer, "random" ) == 0 ) { m_fAmount = 100.0f; m_bIsHealthRandom = true; } else { // Convert the health to an integer and limit it to 100 m_fAmount = static_cast < float > ( atoi ( szBuffer ) ); if ( m_fAmount > 100.0f ) m_fAmount = 100.0f; } } else { m_fAmount = 100.0f; m_bIsHealthRandom = false; } } // Is this a weapon pickup? int iTemp; if ( m_ucType == CPickup::WEAPON || m_bIsTypeRandom ) { // Grab the "ammo" data if ( GetCustomDataInt ( "amount", iTemp, true ) ) { // Limit it to 0-9999 if it was above if ( iTemp > 9999 ) iTemp = 9999; else if ( iTemp < 0 ) iTemp = 0; // Remember it m_usAmmo = static_cast < unsigned short > ( iTemp ); } else { m_usAmmo = 100; } } // Grab the "respawn" data if ( GetCustomDataInt ( "respawn", iTemp, true ) ) { // Make sure it's above 3 seconds if ( iTemp < 3000 ) iTemp = 3000; // Remember it m_ulRespawnIntervals = static_cast < unsigned long > ( iTemp ); } else { m_ulRespawnIntervals = 10000; } // Is this a custom pickup? if ( m_ucType == CPickup::CUSTOM ) { // Grab the "model" data if ( GetCustomDataInt ( "model", iTemp, true ) ) { // Valid id? if ( CObjectManager::IsValidModel ( iTemp ) || iTemp == 370 ) // 370 = jetpack - sort of a hack { // Set the object id m_usModel = static_cast < unsigned short > ( iTemp ); } else { CLogger::ErrorPrintf ( "Bad 'model' id specified in <pickup> (line %u)\n", m_uiLine ); return false; } } else { // Error out if custom is specified but no model id is CLogger::ErrorPrintf ( "Pickup type set to 'custom' but no 'model' id specified (line %u)\n", m_uiLine ); return false; } } if ( GetCustomDataInt ( "dimension", iTemp, true ) ) m_usDimension = static_cast < unsigned short > ( iTemp ); // Success return true; }