Author Topic: Corrections For Map Numunits And Unit Instancenum  (Read 1496 times)

Offline Arklon

  • Administrator
  • Hero Member
  • *****
  • Posts: 1269
Corrections For Map Numunits And Unit Instancenum
« on: July 31, 2009, 01:14:53 AM »
Quote
(00:09:35) (+Arklon) hmm
(00:09:48) (+Arklon) HFL's GameMapEx::GetNumUnits() really gets the X offset
(00:09:55) (+Arklon) returns 32 for not world maps
(00:09:57) (+Arklon) 0 for world maps
(00:43:26) (+Arklon) another thing I found out
(00:43:32) (+Arklon) unit instanceNum is a char, not a short
(00:44:13) (+Arklon) the next byte seems to be used by trucks with cargo or units with weapons
(01:58:22) (&Hooman) post it to the forums
(01:58:28) (&Hooman) that way a record is kept around
(01:58:36) (&Hooman) searching IRC logs is a pain

Even though I found this out with using HFL (which is known to be broken in various ways), I compared the data structures in question with Hooman's internal data notes and, while there are a few slight differences, the parts affected by these findings are the same between both.

In HFL, the data structure of the map object is defined as:
Quote
struct OP2Map
{
   int unknown;
   unsigned int pixelWidthMask;
   int pixelWidth;
   unsigned int tileXMask;
   int tileWidth;
   unsigned char logTileWidth; // base 2 log
   char filler1[3];
   MAP_RECT clipRect;
   int numTiles;
   int numTileSets;
   unsigned char logTileHeight; // base 2 log
   char filler2[3];
   int unknown2;
   int numUnits;
   int unknown3[4];
};
numUnits is not actually the number of units as was (somehow) previously thought. It seems to be the x offset. For non-world maps, it is set to 32; for world maps, it is 0.

As for instanceNum...
In HFL, the data structure of the unit object is defined as:
Quote
// OP2Unit
// Can't use bit fields on the 'char' types since the compiler will still pad to word-size
struct OP2Unit
{
   void *vtbl;
   int isLive;
   void *prevUnit;
   void *nextUnit;
   int id;
   int pixelX;
   int pixelY;
   char unknown0;
   char ownerCreator; // lower 4 bits: owner ID, upper 4 bits: creator ID
   short damage;
   char boolNewAction;
   char curCmd;
   char curAction;
   char lastAction;
   short weaponCargo; // trucks: lowest 4 bits, cargo type; next 4 bits, cargo amount
   short unknown1;
   int unknown2;
   short instanceNum;
[...]
However, instanceNum is not stored as a short (two bytes), but as a single byte (char). I'm not sure what the other byte is, but it seems to be used by cargo trucks with cargo in them or with units that have turrets (but not ConVecs with kits in cargo).