Array of Integers

LPlate2

Warlord
Joined
Dec 27, 2018
Messages
299
Hi,

I'm trying to create an array of integers from xml. At this stage it compiles for me but I'm still getting 0 for every entry in the array. What have I done wrong here?
Spoiler :
Code:
m_paiImageDims(NULL),
Code:
    SAFE_DELETE_ARRAY(m_paiImageDims);
Code:
int CvUnitInfo::getImageDims(int i) const
{
   FAssertMsg(i < getNumImages(), "Index out of bounds");
   FAssertMsg(i > -1, "Index out of bounds");
   return (m_paiImageDims) ? m_paiImageDims[i] : -1;
}
Code:
    SAFE_DELETE_ARRAY(m_paiImageDims);
   m_paiImageDims = new int[m_iNumImages];
   stream->Read(m_iNumImages, m_paiImageDims);
Code:
    stream->Write(m_iNumImages, m_paiImageDims);
Code:
    if (gDLL->getXMLIFace()->SetToChildByTagName(pXML->GetXML(),"ImageDims"))
   {
       pXML->InitList(&m_paiImageDims, getNumImages());//fix this line?
       gDLL->getXMLIFace()->SetToParent(pXML->GetXML());
   }
 
Thanks,

Bit of progress - I'm getting some values transferred but not the values I expected.
In the xml, in the part I'm testing, I have;
Code:
           <ImageDims>
               <iImageDim>419512</iImageDim>
               <iImageDim>380512</iImageDim>
               <iImageDim>312512</iImageDim>
               <iImageDim>380512</iImageDim>
               <iImageDim>345512</iImageDim>
               <iImageDim>380512</iImageDim>
           </ImageDims>
However, the numbers that seem to get returned by gc.getUnitInfo(iUnit).getImageDims(i) are; -1414812832, -1414812757, -17891669, -17891602, 0, 0.

Any more suggestions?
 
That XML structure is somewhat rare in the game. Typically, key-value mappings, represented as lists of pairs, are used, e.g.
Code:
           <BonusProductionModifiers>
               <BonusProductionModifier>
                   <BonusType>BONUS_STONE</BonusType>
                   <iProductonModifier>100</iProductonModifier>
               </BonusProductionModifier>
           </BonusProductionModifiers>
That's what SetVariableListTagPair expects. If that structure doesn't work for you, then I think you'll have to call CvXMLLoadUtility::getXMLVal in a loop like the one in CvWorldPickerInfo::read. That uses a vector instead of an array; but you could also use an array, allocated through initList or simply through the new operator.
 
Hi,

I've restructured it now to use
Code:
           <ImageDims>
               <ImageDim>
                   <iCount>0</iCount>
                   <iImageDim>419512</iImageDim>
               </ImageDim>

How should I set up the equivalent of the,
Code:
pXML->SetVariableListTagPair(&m_piTerrainCulture, "TerrainCultures", sizeof(GC.getTerrainInfo((TerrainTypes)0)), GC.getNumTerrainInfos(), false);
line? Using this one as the example, rather than,
Code:
    pXML->SetVariableListTagPair(&m_pbFreePromotions, "FreePromotions", sizeof(GC.getPromotionInfo((PromotionTypes)0)), GC.getNumPromotionInfos());
, as it includes an example of a fifth default value.

I've added MAX_NUM_GP in GlobalDefinesAlt.xml and think that GC.getDefineINT("MAX_NUM_GP") is the equivalent that I should use for GC.getNumTerrainInfos().
How do I determine the entry that should go in the equivalent position to sizeof(GC.getTerrainInfo((TerrainTypes)0))?

Code:
    pXML->SetVariableListTagPair(&m_piImageDim, "ImageDims", ????????, GC.getDefineINT("MAX_NUM_GP"), 0);
 
Well, here's the implementation: SetVariableListTagPair
So the first element of each tag pair is expected to be a string corresponding to an enumerator and ultimately to a CvInfo instance, e.g. TERRAIN_GRASSLAND. And iInfoBaseSize is supposed to be the size of that class. However, iInfoBaseSize is actually unused, so this isn't a problem; one can simply pass 0. That said, SetVariableListTagPair will call
iIndexVal = FindInInfoClass(szTextVal);
with szTextVal being the enum string (e.g. "TERRAIN_GRASSLAND"). With your iCount element, szTextVal will be "0", and since there is no such CvInfo instance, the iImageDim won't be read.

If these ImageDims correspond to Great People ("MAX_NUM_GP"?), then perhaps UNIT_GREAT... (CvUnitInfos) or SPECIALIST_GREAT... (CvSpecialistInfos) could be used for the first elements (instead of integers). For the non-great specialists, SetVariableListTagPair would then set the default ImageDim (0). Depends on what info will be available when you eventually call your getImageDims function – a UnitTypes value, a SpecialistTypes value, something else ...
 
Top Bottom