# Updates to the tech system, and bug fixes.

Techs: Made a separate list of technologies for every player, rather
than array fields in CTechnology. This also involved changing the
tech-related JS functions.

Bugs:
- PS_MAX_PLAYERS should be 8 (the way it's used for array sizes, etc
indicates that it's the maximum possible number of players ever, but it
used to be 6 while the game had 8 players).
- When you changed a CJSSharedProperty that was inherited, m_Inherited
was set to false, so it was no longer inherited by subsequent entities
you created. They got initialized to garbage values as a result.

This was SVN commit r4138.
This commit is contained in:
Matei
2006-07-18 04:17:46 +00:00
parent 1828443b02
commit 845b606763
13 changed files with 127 additions and 95 deletions
+18 -19
View File
@@ -3,6 +3,7 @@
#include "TechnologyCollection.h"
#include "ps/CLogger.h"
#include "ps/VFSUtil.h"
#include "ps/Player.h"
#define LOG_CATEGORY "tech"
@@ -10,7 +11,7 @@ void CTechnologyCollection::LoadFile( const char* path )
{
//Make tech file reading
CStrW tag = CStr(path).AfterLast("/").BeforeLast(".xml");
m_templateFilenames[tag] = path;
m_techFilenames[tag] = path;
}
static void LoadTechThunk( const char* path, const DirEnt* UNUSED(ent), void* context )
@@ -27,45 +28,43 @@ int CTechnologyCollection::loadTechnologies()
return 0;
}
CTechnology* CTechnologyCollection::getTechnology( CStrW name )
CTechnology* CTechnologyCollection::getTechnology( CStrW name, CPlayer* player )
{
// Find player ID
debug_assert( player != 0 );
int id = player->GetPlayerID();
// Check whether this template has already been loaded.
//If previously loaded, all slots will be found, so any entry works.
templateMap::iterator it = m_templates.find( name );
if( it != m_templates.end() )
TechMap::iterator it = m_techs[id].find( name );
if( it != m_techs[id].end() )
return( it->second );
// Find the filename corresponding to this template
templateFilenameMap::iterator filename_it = m_templateFilenames.find( name );
if( filename_it == m_templateFilenames.end() )
TechFilenameMap::iterator filename_it = m_techFilenames.find( name );
if( filename_it == m_techFilenames.end() )
return( NULL );
CStr path( filename_it->second );
//Try to load to the tech
CTechnology* newTemplate = new CTechnology();
CTechnology* newTemplate = new CTechnology( player );
if( !newTemplate->loadXML( path ) )
{
LOG(ERROR, LOG_CATEGORY, "CTechnologyCollection::getTechnology(): Couldn't load template \"%s\"", path.c_str());
LOG(ERROR, LOG_CATEGORY, "CTechnologyCollection::getTechnology(): Couldn't load tech \"%s\"", path.c_str());
delete newTemplate;
return( NULL );
}
m_templates[name] = newTemplate;
m_techs[id][name] = newTemplate;
LOG(NORMAL, LOG_CATEGORY, "CTechnologyCollection::getTechnology(): Loaded template \"%s\"", path.c_str());
LOG(NORMAL, LOG_CATEGORY, "CTechnologyCollection::getTechnology(): Loaded tech \"%s\"", path.c_str());
return newTemplate;
}
void CTechnologyCollection::getTechnologyNames( std::vector<CStrW>& names )
{
for( templateFilenameMap::iterator it = m_templateFilenames.begin(); it != m_templateFilenames.end(); ++it )
if( ! (it->first.Length() > 8 && it->first.Left(8) == L"template"))
names.push_back( it->first );
}
CTechnologyCollection::~CTechnologyCollection()
{
for( templateMap::iterator it = m_templates.begin(); it != m_templates.end(); ++it )
delete( it->second );
for( uint id=0; id<PS_MAX_PLAYERS+1; id++ )
for( TechMap::iterator it = m_techs[id].begin(); it != m_techs[id].end(); ++it )
delete( it->second );
}