-
Notifications
You must be signed in to change notification settings - Fork 39
InfoArray (xml)
An InfoArray is an array of numbers intended to be used in the info classes (hence the name). Think of it as a spreadsheet. It has 1-4 columns and each row has data in each column. While the columns are specified in C++, the number of rows isn't.
This is likely best explained by using examples.
InfoArray<YieldTypes> em;
This will create a list of yields. It is best viewed as a bool array of all yields. Yields mentioned in xml are true while those who aren't are false.
<MyInfoArrayTag>
<yield>YIELD_FOOD</yield>
<yield>YIELD_LUMBER</yield>
</MyInfoArrayTag>
This is a much more readable list than the vanilla code requires. The parent tag (in this case MyInfoArrayTag) should be the one used in C++ to load the InfoArray. The DLL code doesn't care about names for child tags. Since the C++ declaration states it's of type YieldTypes, the DLL will throw an error if any string is used, which isn't listed as a Type in CvYieldInfos.
As usual it's highly recommended to turn asserts on when modding either xml or C++ as it increases the level of error detection.
InfoArray<UnitClassTypes, YieldTypes> em;
Now it requires a pair for each row.
<MyInfoArrayTag>
<index>
<class>UNITCLASS_FARMER</class>
<yield>YIELD_FOOD</yield>
</index>
<index>
<class>UNITCLASS_FARMER</class>
<yield>YIELD_LUMBER</yield>
</index>
</MyInfoArrayTag>
This results in
Unit Class | Yield |
---|---|
UNITCLASS_FARMER | YIELD_FOOD |
UNITCLASS_FARMER | YIELD_LUMBER |
However InfoArray can exploit nested lists and precisely the same data can be written:
<MyInfoArrayTag>
<index>
<class>UNITCLASS_FARMER</class>
<yields>
<yield>YIELD_FOOD</yield>
<yield>YIELD_LUMBER</yield>
<yields>
</index>
</MyInfoArrayTag>
Because class is in the parent of yields, looping through yields will give each case a "prefix" of what is set in parent. In this case it's UNICLASS_FARMER for each.
InfoArray<UnitClassTypes, YieldTypes, int> em;
Now there should be an int value for each pair.
<MyInfoArrayTag>
<index>
<class>UNITCLASS_FARMER</class>
<sub>
<group>
<yield>YIELD_FOOD</yield>
<value>5</value>
</group>
<group>
<yield>YIELD_LUMBER</yield>
<value>5</value>
</group>
</sub>
</index>
</MyInfoArrayTag>
Resulting data:
Unit Class | Yield | value |
---|---|---|
UNITCLASS_FARMER | YIELD_FOOD | 5 |
UNITCLASS_FARMER | YIELD_LUMBER | 5 |
Or if nested looping isn't interesting, the same can be written this way:
<MyInfoArrayTag>
<index>
<class>UNITCLASS_FARMER</class>
<yield>YIELD_FOOD</yield>
<value>5</value>
</index>
<index>
<class>UNITCLASS_FARMER</class>
<yield>YIELD_LUMBER</yield>
<value>5</value>
</index>
</MyInfoArrayTag>