also fix dummy targetnames in -mergebsp -fixnames, may legitimately exist as outcome of misc_model->group_entity connection

This commit is contained in:
Garux 2021-11-04 19:45:57 +03:00
parent d1610b49ff
commit 0aa61b7dfa

View File

@ -782,17 +782,20 @@ int MergeBSPMain( Args& args ){
} }
} }
/* make target/targetname names unique */ /* make target/targetname names unique */
if( fixnames ){ ///! assumes there are no dummy targetnames to fix in incoming bsp if( fixnames ){
const auto has_name = []( const std::vector<entity_t>& entities, const char *name ){ const auto is_name = []( const epair_t& ep ){ return striEqual( ep.key.c_str(), "target" ) || striEqual( ep.key.c_str(), "targetname" ); };
const auto has_name = [is_name]( const std::vector<entity_t>& entities, const char *name ){
for( auto&& e : entities ) for( auto&& e : entities )
if( striEqual( name, e.valueForKey( "target" ) ) for( auto&& ep : e.epairs )
|| striEqual( name, e.valueForKey( "targetname" ) ) ) if( is_name( ep ) && striEqual( name, ep.value.c_str() ) )
return true; return true;
return false; return false;
}; };
for( auto&& e : bsp.entities ) for( auto&& e : bsp.entities )
{ {
if( const char *name; e.read_keyvalue( name, "target" ) ){ for( const char *key : { "target", "targetname" } )
{
if( const char *name; e.read_keyvalue( name, key ) ){
if( has_name( entities, name ) ){ if( has_name( entities, name ) ){
StringOutputStream newName; StringOutputStream newName;
int id = 0; int id = 0;
@ -804,14 +807,14 @@ int MergeBSPMain( Args& args ){
const CopiedString oldName = name; // backup it, original will change const CopiedString oldName = name; // backup it, original will change
for( auto&& e : bsp.entities ) for( auto&& e : bsp.entities )
for( auto&& ep : e.epairs ) for( auto&& ep : e.epairs )
if( ( striEqual( ep.key.c_str(), "target" ) || striEqual( ep.key.c_str(), "targetname" ) ) if( is_name( ep ) && striEqual( ep.value.c_str(), oldName.c_str() ) )
&& striEqual( ep.value.c_str(), oldName.c_str() ) )
ep.value = newName; ep.value = newName;
} }
} }
} }
} }
} }
}
{ {
entities.insert( entities.cend(), bsp.entities.cbegin() + 1, bsp.entities.cend() ); // minus world entities.insert( entities.cend(), bsp.entities.cbegin() + 1, bsp.entities.cend() ); // minus world