DisableStockVehiclesForSpecialVehicleFeature export for plugins assuming full control over those

This commit is contained in:
Silent 2018-05-07 23:56:12 +02:00
parent cb8eb2f3b0
commit 7e50ef41a0
No known key found for this signature in database
GPG key ID: AE53149BB0C45AF1

View file

@ -21,6 +21,7 @@ float CAutomobile::ms_engineCompSpeed;
namespace SVF { namespace SVF {
enum class Feature enum class Feature
{ {
NO_FEATURE,
PHOENIX_FLUTTER, PHOENIX_FLUTTER,
SWEEPER_BRUSHES, SWEEPER_BRUSHES,
NEWSVAN_DISH, NEWSVAN_DISH,
@ -33,18 +34,43 @@ namespace SVF {
NO_ROTOR_FADE, NO_ROTOR_FADE,
}; };
int32_t nextFeatureCookie = 0; Feature GetFeatureFromName( const char* featureName )
{
const std::pair< const char*, Feature > features[] = {
{ "PHOENIX_FLUTTER", Feature::PHOENIX_FLUTTER },
{ "SWEEPER_BRUSHES", Feature::SWEEPER_BRUSHES },
{ "NEWSVAN_DISH", Feature::NEWSVAN_DISH },
{ "BOAT_MOVING_PROP", Feature::BOAT_MOVING_PROP },
{ "EXTRA_AILERONS1", Feature::EXTRA_AILERONS1 },
{ "EXTRA_AILERONS2", Feature::EXTRA_AILERONS2 },
};
auto it = std::find_if( std::begin(features), std::end(features), [featureName]( const auto& e ) {
return _stricmp( e.first, featureName ) == 0;
});
if ( it == std::end(features) ) return Feature::NO_FEATURE;
return it->second;
}
static int32_t nextFeatureCookie = 0;
int32_t _getCookie() int32_t _getCookie()
{ {
return nextFeatureCookie++; return nextFeatureCookie++;
} }
auto _registerFeatureInternal( int32_t modelID, Feature feature ) static int32_t highestStockCookie = 0;
int32_t _getCookieStockID()
{ {
return std::make_pair( modelID, std::make_tuple( feature, _getCookie() ) ); return highestStockCookie = _getCookie();
} }
std::multimap<int32_t, std::tuple<Feature, int32_t> > specialVehFeatures = { auto _registerFeatureInternal( int32_t modelID, Feature feature )
{
return std::make_pair( modelID, std::make_tuple( feature, _getCookieStockID() ) );
}
static std::multimap<int32_t, std::tuple<Feature, int32_t> > specialVehFeatures = {
_registerFeatureInternal( 430, Feature::BOAT_MOVING_PROP ), _registerFeatureInternal( 430, Feature::BOAT_MOVING_PROP ),
_registerFeatureInternal( 453, Feature::BOAT_MOVING_PROP ), _registerFeatureInternal( 453, Feature::BOAT_MOVING_PROP ),
_registerFeatureInternal( 454, Feature::BOAT_MOVING_PROP ), _registerFeatureInternal( 454, Feature::BOAT_MOVING_PROP ),
@ -57,6 +83,8 @@ namespace SVF {
int32_t RegisterFeature( int32_t modelID, Feature feature ) int32_t RegisterFeature( int32_t modelID, Feature feature )
{ {
if ( feature == Feature::NO_FEATURE ) return -1;
const int32_t cookie = _getCookie(); const int32_t cookie = _getCookie();
specialVehFeatures.emplace( modelID, std::make_tuple(feature, cookie) ); specialVehFeatures.emplace( modelID, std::make_tuple(feature, cookie) );
return cookie; return cookie;
@ -74,6 +102,22 @@ namespace SVF {
} }
} }
void DisableStockVehiclesForFeature( Feature feature )
{
if ( feature == Feature::NO_FEATURE ) return;
for ( auto it = specialVehFeatures.begin(); it != specialVehFeatures.end(); )
{
if ( std::get<int32_t>(it->second) <= highestStockCookie )
{
it = specialVehFeatures.erase( it );
}
else
{
++it;
}
}
}
bool ModelHasFeature( int32_t modelID, Feature feature ) bool ModelHasFeature( int32_t modelID, Feature feature )
{ {
auto results = specialVehFeatures.equal_range( modelID ); auto results = specialVehFeatures.equal_range( modelID );
@ -81,25 +125,6 @@ namespace SVF {
return std::get<Feature>(e.second) == feature; return std::get<Feature>(e.second) == feature;
} ) != results.second; } ) != results.second;
} }
int32_t _registerFeature( int32_t modelID, const char* featureName )
{
const std::pair< const char*, Feature > features[] = {
{ "PHOENIX_FLUTTER", Feature::PHOENIX_FLUTTER },
{ "SWEEPER_BRUSHES", Feature::SWEEPER_BRUSHES },
{ "NEWSVAN_DISH", Feature::NEWSVAN_DISH },
{ "BOAT_MOVING_PROP", Feature::BOAT_MOVING_PROP },
{ "EXTRA_AILERONS1", Feature::EXTRA_AILERONS1 },
{ "EXTRA_AILERONS2", Feature::EXTRA_AILERONS2 },
};
auto it = std::find_if( std::begin(features), std::end(features), [featureName]( const auto& e ) {
return _stricmp( e.first, featureName ) == 0;
});
if ( it == std::end(features) ) return -1;
return RegisterFeature( modelID, it->second );
}
} }
@ -570,7 +595,7 @@ extern "C" {
__declspec(dllexport) int32_t RegisterSpecialVehicleFeature( int32_t modelID, const char* featureName ) __declspec(dllexport) int32_t RegisterSpecialVehicleFeature( int32_t modelID, const char* featureName )
{ {
if ( featureName == nullptr ) return -1; if ( featureName == nullptr ) return -1;
return SVF::_registerFeature( modelID, featureName ); return SVF::RegisterFeature( modelID, SVF::GetFeatureFromName(featureName) );
} }
__declspec(dllexport) void DeleteSpecialVehicleFeature( int32_t cookie ) __declspec(dllexport) void DeleteSpecialVehicleFeature( int32_t cookie )
@ -579,4 +604,10 @@ __declspec(dllexport) void DeleteSpecialVehicleFeature( int32_t cookie )
SVF::DeleteFeature( cookie ); SVF::DeleteFeature( cookie );
} }
} __declspec(dllexport) void DisableStockVehiclesForSpecialVehicleFeature( const char* featureName )
{
if ( featureName == nullptr ) return;
SVF::DisableStockVehiclesForFeature( SVF::GetFeatureFromName(featureName) );
}
}