Add some more exception handling to InitRead API methods

develop
Petr Mrázek 2010-03-23 00:35:23 +01:00
parent 24d969791b
commit efadfe98b2
1 changed files with 40 additions and 11 deletions

@ -150,12 +150,18 @@ public:
DfVector *p_current_settlement;
};
// FIXME: flesh it out
bool API::Private::InitReadNames()
{
try
{
name_firstname_offset = offset_descriptor->getOffset("name_firstname");
name_nickname_offset = offset_descriptor->getOffset("name_nickname");
name_words_offset = offset_descriptor->getOffset("name_words");
}
catch(Error::MissingMemoryDefinition)
{
return false;
}
return true;
}
@ -810,7 +816,15 @@ bool API::ReadGeology (vector < vector <uint16_t> >& assign)
// returns number of buildings, expects v_buildingtypes that will later map t_building.type to its name
bool API::InitReadBuildings ( uint32_t& numbuildings )
{
int buildings = d->offset_descriptor->getAddress ("buildings");
int buildings = 0;
try
{
buildings = d->offset_descriptor->getAddress ("buildings");
}
catch(Error::MissingMemoryDefinition)
{
return false;
}
d->buildingsInited = true;
d->p_bld = new DfVector (d->p->readVector (buildings, 4));
numbuildings = d->p_bld->getSize();
@ -863,7 +877,15 @@ bool API::InitReadEffects ( uint32_t & numeffects )
{
if(d->effectsInited)
FinishReadEffects();
int effects = d->offset_descriptor->getAddress ("effects_vector");
int effects = 0;
try
{
effects = d->offset_descriptor->getAddress ("effects_vector");
}
catch(Error::MissingMemoryDefinition)
{
return false;
}
d->effectsInited = true;
d->p_effect = new DfVector (d->p->readVector (effects, 4));
numeffects = d->p_effect->getSize();
@ -913,7 +935,15 @@ void API::FinishReadEffects()
// returns number of constructions, prepares a vector, returns total number of constructions
bool API::InitReadConstructions(uint32_t & numconstructions)
{
int constructions = d->offset_descriptor->getAddress ("constructions");
int constructions = 0;
try
{
constructions = d->offset_descriptor->getAddress ("constructions");
}
catch(Error::MissingMemoryDefinition)
{
return false;
}
d->p_cons = new DfVector (d->p->readVector (constructions, 4));
d->constructionsInited = true;
numconstructions = d->p_cons->getSize();
@ -1001,10 +1031,10 @@ void API::FinishReadVegetation()
bool API::InitReadCreatures( uint32_t &numcreatures )
{
if(!d->InitReadNames()) return false;
try
{
memory_info * minfo = d->offset_descriptor;
d->InitReadNames();
int creatures = d->offset_descriptor->getAddress ("creatures");
d->creature_pos_offset = minfo->getOffset ("creature_position");
d->creature_type_offset = minfo->getOffset ("creature_race");
@ -1032,7 +1062,6 @@ bool API::InitReadCreatures( uint32_t &numcreatures )
d->creature_mood_offset = minfo->getOffset("creature_mood");
d->p_cre = new DfVector (d->p->readVector (creatures, 4));
//InitReadNameTables();
d->creaturesInited = true;
numcreatures = d->p_cre->getSize();
return true;