Home » MODDING HQ 1.13 » v1.13 General Development Talk » Question about JA2 data structures
Question about JA2 data structures[message #350440] Wed, 02 August 2017 09:06 Go to next message
SharkD

 
Messages:362
Registered:July 2003
I have a question regarding JA2 internals. How does the game keep track of people? Is the top level data structure the sector? Or is it squads? Thanks.
Re: Question about JA2 data structures[message #350442 is a reply to message #350440] Wed, 02 August 2017 13:23 Go to previous messageGo to next message
Flugente

 
Messages:3137
Registered:April 2009
Location: Germany
The profile data from MercProfiles.xml is stored in the savegame and used throughout the game in an array called gMercProfiles (or similar, not at code atm to get the exact name). For this reason altering that xml does not affect savegames.

But you likely mean the SOLDIERTYPE class, which stores everything else about persons in the game. This is stored in the array MercPtrs[TOTAL_SOLDIERS] (or slightly different name). Interestingly (and somehwat confusing at first): The first 38 entries contain the data of your team and always exist, whatever sector is loaded (even if none is loaded). The other parts of that array contain the data of all other persons in the currently loaded sector, every team gets a different part of that array.
Apart from auto-resolve (and stuff happening when we fight 2 tactical battles in 2 different sectors at the same time, which is very, VERY bad), these are the only SOLDIERTYPEs in use.

Apart from that, no data is tracked. For soldiers and militia, we just store their number in the patrol groups or sector data. Civilians or creatures aren`t even that, they are created upon loading a map.

Was that useful, or did I misunderstand your question?

[Updated on: Wed, 02 August 2017 13:31]




Saren threw his head back and screamed in impotent fury, before falling to his throne, head in his claws, trembling in horrified disbelief.

Then he heard a faint chime as Sovereign subscribed to her ECHO channel.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: Question about JA2 data structures[message #350449 is a reply to message #350442] Thu, 03 August 2017 07:41 Go to previous messageGo to next message
SharkD

 
Messages:362
Registered:July 2003
I don't really follow you. Could you provide a bit of pseudo code? That I might understand better.

[Updated on: Thu, 03 August 2017 07:41]

Re: Question about JA2 data structures[message #350465 is a reply to message #350449] Thu, 03 August 2017 22:24 Go to previous messageGo to next message
Flugente

 
Messages:3137
Registered:April 2009
Location: Germany
Hmm. I'm not sure what exactly you expect, to be honestly. Here's a trivial example: We check whether any of our mercs currently staff the Alma HQ.
BOOLEAN MercStaffsMilitaryHQ()
{
	SOLDIERTYPE *pSoldier = NULL;
	UINT32 uiCnt = 0;
	UINT32 firstid = gTacticalStatus.Team[ OUR_TEAM ].bFirstID;
	UINT32 lastid  = gTacticalStatus.Team[ OUR_TEAM ].bLastID;
	for ( uiCnt = firstid, pSoldier = MercPtrs[ uiCnt ]; uiCnt <= lastid; ++uiCnt, ++pSoldier)
	{
		if( pSoldier && pSoldier->bAssignment == FACILITY_STRATEGIC_MILITIA_MOVEMENT && pSoldier->flags.fMercAsleep == FALSE )
		{
			return TRUE;
		}
	}

	return FALSE;
}


As said, the pointers on all soldiers are stored in MercPtrs[] and are sorted by team. So we simply loop over our potentially existing teammates and see whether conditions are met.



Saren threw his head back and screamed in impotent fury, before falling to his throne, head in his claws, trembling in horrified disbelief.

Then he heard a faint chime as Sovereign subscribed to her ECHO channel.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: Question about JA2 data structures[message #350482 is a reply to message #350465] Sat, 05 August 2017 13:21 Go to previous messageGo to next message
SharkD

 
Messages:362
Registered:July 2003
How are they sorted? For example are MercPtrs units 1-5 in one team, and MercPtrs units 6-10 in another team? Or is MercPtrs a table made of many smaller tables?

[Updated on: Sat, 05 August 2017 13:21]

Re: Question about JA2 data structures[message #350483 is a reply to message #350482] Sat, 05 August 2017 14:41 Go to previous messageGo to next message
The_Bob

 
Messages:353
Registered:May 2009
Location: Behind you.
It's a flat array holding pointers to mercs and occasionally other stuff, AFAIK in no particular order apart from holding player characters first.

The basic soldier info is defined in Soldier Control.h, the actual data is initialized in Overhead.cpp.

As Flugente said, apart from player characters the data in that array isn't persisted after a map is unloaded. When not on the currently loaded map, militia and enemy troops are just numbers in strategic movement groups, I don't know if they track anything other than the type (admin/regular/elite) of the soldiers there.

The maps contain a bit of information about the characters that are supposed to spawn there, there's a section in the map file listing "placements" described by the "Soldier Create" structure, which is defined in Soldier Create.h. There's two variants, BASIC_SOLDIERCREATE_STRUCT and SOLDIERCREATE_STRUCT, the first one used for placing generic, auto-generated NPCs (with rough control over their gear, attitude, and an optional patrol route) while the second one is very detailed, allowing for bespoke characters to be embedded in the map, typically used for spawning rooftop snipers or other soldiers with specific gear, also the second placement type is used for placing NPCs with profiles on the map, like the Kulbas or the bartenders.

If you'd like to explore how this stuff works in more detail, have a look through the code. Reading 1.13 source can be quite an experience! Consider using a code browser like Sourcetrail to find your way around.

[Updated on: Sat, 05 August 2017 14:44]


Re: Question about JA2 data structures[message #350505 is a reply to message #350483] Tue, 08 August 2017 12:09 Go to previous messageGo to next message
SharkD

 
Messages:362
Registered:July 2003
I'm trying to emulate JA2's strategic map for a Homeworld Remastered mod. Right now I have a table for each map sector, and another table for a single roaming player-controlled squad. I want to expand this to multiple roaming player and enemy squads, but am not sure what the best structure would be.

One difference is that in my mod all aspects of the ships will be persistent. So everything can be dumped into one large table if that makes things simpler.

[Updated on: Tue, 08 August 2017 13:30]

Re: Question about JA2 data structures[message #350523 is a reply to message #350505] Thu, 10 August 2017 08:41 Go to previous messageGo to next message
SharkD

 
Messages:362
Registered:July 2003
Is there a limit to the number of squads you can create? Or does the number simply keep iterating? Thanks.



Homepage: http://isometricland.net
Re: Question about JA2 data structures[message #350527 is a reply to message #350523] Thu, 10 August 2017 13:20 Go to previous messageGo to next message
Flugente

 
Messages:3137
Registered:April 2009
Location: Germany
Keep in mind that the squad number is mostly there for the player, in itself it is pretty meaningless. Every soldier has a member variable that stores their current assignemnt - doctor , repair, various training stuff, or being a member of a squad. There was originally room for 18 squads, nowadays we have 40 due to the increased team size. But this is simply a number.

Much more important to you are travelling groups, each squad happpens to also 'represent' a group. Basically, a group is stucture that stores a groups team (player, enemy, nowadays also militia), sector of origin, current sector, sector they are moving to, arrival time, for enemy/militia: number of each enemy/militia type and for players who belongs to it (I'm not at the code atm, so I'm not sure whether this stores our mercs' IDs, profiles or their squad number). This is coded in such a way that only mercs that are members of a squad may belong to a group.

For enemies/militia, this has the nasty sideeffect that there are 2 ways in which they can be in a sector: static enemies that don't move are stored in the sector's data structure, travelling enemies are stored in the group structure. Our merc's, on the other hand, have their internal sector updated every time they arrive in a sector, we can find them all by simply looping over the MercPtrs-array.

As Sirtech apparently hated vectors, this is simply an array of fixed size that cannot hold more than 256 entries, which means that once we exceed that ingame, nasty stuff will happen (but it hasn't happened so far, so we let that slide). In your case, having a vector of groups that you add or remove elements from seems easier and simpler.

Oh, and a triviall tip: make sure that variables that store numbers of things are sufficiently big. At the moment, the total amount of soldiers in a sector, the number of profiles, the number of sectors and quite a bit of other stuff are always in UINT8, which can only have values from 0-255. As you can imagine, changing that requires changing huge parts of the code, gets nasty when altering saved data (due to padding etc.) and is a general pain in the ass that could have easily been avoided at the creation of the game, all gained through this is a tiny bit of lowered memory usage that is practically meaningless nowadays.

[Updated on: Thu, 10 August 2017 13:39]




Saren threw his head back and screamed in impotent fury, before falling to his throne, head in his claws, trembling in horrified disbelief.

Then he heard a faint chime as Sovereign subscribed to her ECHO channel.

If you want, you can donate to me. This will not affect how and what I code, and I will not code specific features in return. I will be thankful though.


Re: Question about JA2 data structures[message #350550 is a reply to message #350527] Fri, 11 August 2017 19:13 Go to previous message
SharkD

 
Messages:362
Registered:July 2003
Yeah, I figured it was a circa 1999 memory issue.

Homeworld Remastered has memory issues too (it's a 32-bit game) but not this bad I think.

Also, the game uses Lua for everything, so you couldn't choose the size of a variable even if you wanted to.

[Updated on: Fri, 11 August 2017 19:15]




Homepage: http://isometricland.net
Previous Topic: Battles happening simultaneously
Next Topic: ja2MapTool
Goto Forum:
  


Current Time: Thu Sep 21 02:38:57 EEST 2017

Total time taken to generate the page: 0.00769 seconds