Fix RestoreState to assign IDs to instance vars

master
melex750 2016-05-24 10:09:44 -04:00
parent cdd719cc47
commit c19f97bc24
1 changed files with 14 additions and 0 deletions

View File

@ -805,6 +805,8 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
CBotToken token(name, std::string()); CBotToken token(name, std::string());
bool isClass = false;
switch (w) switch (w)
{ {
case CBotTypInt: case CBotTypInt:
@ -826,6 +828,7 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
// returns an intrinsic object or element of an array // returns an intrinsic object or element of an array
case CBotTypIntrinsic: case CBotTypIntrinsic:
isClass = true;
case CBotTypArrayBody: case CBotTypArrayBody:
{ {
CBotTypResult r; CBotTypResult r;
@ -843,6 +846,17 @@ bool CBotVar::RestoreState(FILE* pf, CBotVar* &pVar)
if ( !RestoreState(pf, (static_cast<CBotVarClass*>(pNew))->m_pVar)) return false; if ( !RestoreState(pf, (static_cast<CBotVarClass*>(pNew))->m_pVar)) return false;
pNew->SetIdent(id); pNew->SetIdent(id);
if (isClass && p == nullptr) // set id for each item in this instance
{
CBotVar* pVars = pNew->GetItemList();
long itemId = 1;
while (pVars != nullptr)
{
pVars->m_ident = itemId++;
pVars = pVars->GetNext();
}
}
if ( p != nullptr ) if ( p != nullptr )
{ {
delete pNew; delete pNew;