Home » SIRTECH CLASSICS » Jagged Alliance: Unfinished Business » Vanilla Modding » JA2 Source Code Digging: Adding new teams?
JA2 Source Code Digging: Adding new teams?[message #186328] Mon, 26 May 2008 03:07 Go to next message
Shanga

 
Messages:3507
Registered:January 2000
Location: Danubia
Here's a bit of code I stumbled upon. Looks like a good start to investigate how new groups can be added to JA2.

NOTE: I've used Jones html version from SVN to peek in, hope its not too altered:


https://81.169.133.124/source/ja2/branches/Jones/html/Overhead_01Types_8h-source.html#l00337
Quote:


00320 //NOTE: The editor uses these enumerations, so please update the text as well if you modify or
00321 // add new groups. Try to abbreviate the team name as much as possible. The text is in
00322 // EditorMercs.c
00323 #ifdef JA2EDITOR
00324 extern UINT16 gszCivGroupNames[ NUM_CIV_GROUPS ][ 20 ];
00325 #endif
00326 //
00327 //-----------------------------------------------
00328
00329 // PALETTE SUBSITUTION TYPES
00330 typedef struct
00331 {
00332 UINT8 ubStart;
00333 UINT8 ubEnd;
00334
00335 } PaletteSubRangeType;
00336
00337 typedef CHAR8 PaletteRepID[ 30 ];
00338
00339 typedef struct
00340 {
00341 UINT8 ubType;
00342 PaletteRepID ID;
00343 UINT8 ubPaletteSize;
00344 UINT8 *r;
00345 UINT8 *g;
00346 UINT8 *b;
00347
00348 } PaletteReplacementType;
00349
00350 // MACROS
00351 // This will set an animation ID
00352 #define SET_PALETTEREP_ID( a, b ) ( strcpy( a, b ) )
00353 // strcmp returns 0 if true!
00354 #define COMPARE_PALETTEREP_ID( a, b ) ( strcmp( a, b ) ? FALSE : TRUE )
00355
00356 #endif


Re: JA2 Source Code Digging: Adding new teams?[message #186329] Mon, 26 May 2008 03:08 Go to previous messageGo to next message
Shanga

 
Messages:3507
Registered:January 2000
Location: Danubia
And another function that looks like the one responsible for "coloring" the various bodytypes (I might be wrong, but I am no coder so all i can do is scout):

https://81.169.133.124/source/ja2/branches/Jones/html/Soldier_01Control_8cpp-source.html#l06223


Quote:

06120 ///////////////////////////////////////////////////////
06121 //PALETTE REPLACEMENT FUNCTIONS
06122 ///////////////////////////////////////////////////////
06123 BOOLEAN LoadPaletteData( )
06124 {
06125 HWFILE hFile;
06126 UINT32 cnt, cnt2;
06127
06128 hFile = FileOpen( PALETTEFILENAME, FILE_ACCESS_READ, FALSE );
06129
06130 // Read # of types
06131 if ( !FileRead( hFile, &guiNumPaletteSubRanges, sizeof( guiNumPaletteSubRanges ), (UINT32 *)NULL ) )
06132 {
06133 return( FALSE );
06134 }
06135
06136 // Malloc!
06137 gpPaletteSubRanges = (PaletteSubRangeType *) MemAlloc( sizeof( PaletteSubRangeType ) * guiNumPaletteSubRanges );
06138 gubpNumReplacementsPerRange = (UINT8 *) MemAlloc( sizeof( UINT8 ) * guiNumPaletteSubRanges );
06139
06140 // Read # of types for each!
06141 for ( cnt = 0; cnt < guiNumPaletteSubRanges; cnt++ )
06142 {
06143 if ( !FileRead( hFile, &gubpNumReplacementsPerRange[ cnt ], sizeof( UINT8 ), (UINT32 *)NULL ) )
06144 {
06145 return( FALSE );
06146 }
06147 }
06148
06149 // Loop for each one, read in data
06150 for ( cnt = 0; cnt < guiNumPaletteSubRanges; cnt++ )
06151 {
06152 if ( !FileRead( hFile, &gpPaletteSubRanges[ cnt ].ubStart, sizeof( UINT8 ), (UINT32 *)NULL ) )
06153 {
06154 return( FALSE );
06155 }
06156 if ( !FileRead( hFile, &gpPaletteSubRanges[ cnt ].ubEnd, sizeof( UINT8 ), (UINT32 *)NULL ) )
06157 {
06158 return( FALSE );
06159 }
06160 }
06161
06162
06163 // Read # of palettes
06164 if ( !FileRead( hFile, &guiNumReplacements, sizeof( guiNumReplacements ), (UINT32 *)NULL ) )
06165 {
06166 return( FALSE );
06167 }
06168
06169 // Malloc!
06170 gpPalRep = (PaletteReplacementType *) MemAlloc( sizeof( PaletteReplacementType ) * guiNumReplacements );
06171
06172 // Read!
06173 for ( cnt = 0; cnt < guiNumReplacements; cnt++ )
06174 {
06175 // type
06176 if ( !FileRead( hFile, &gpPalRep[ cnt ].ubType, sizeof( gpPalRep[ cnt ].ubType ), (UINT32 *)NULL ) )
06177 {
06178 return( FALSE );
06179 }
06180
06181 if ( !FileRead( hFile, &gpPalRep[ cnt ].ID, sizeof( gpPalRep[ cnt ].ID ), (UINT32 *)NULL ) )
06182 {
06183 return( FALSE );
06184 }
06185
06186 // # entries
06187 if ( !FileRead( hFile, &gpPalRep[ cnt ].ubPaletteSize, sizeof( gpPalRep[ cnt ].ubPaletteSize ), (UINT32 *)NULL ) )
06188 {
06189 return( FALSE );
06190 }
06191
06192 // Malloc
06193 gpPalRep[ cnt ].r = (UINT8 *) MemAlloc( gpPalRep[ cnt ].ubPaletteSize );
06194 CHECKF( gpPalRep[ cnt ].r != NULL );
06195 gpPalRep[ cnt ].g = (UINT8 *) MemAlloc( gpPalRep[ cnt ].ubPaletteSize );
06196 CHECKF( gpPalRep[ cnt ].g != NULL );
06197 gpPalRep[ cnt ].b = (UINT8 *) MemAlloc( gpPalRep[ cnt ].ubPaletteSize );
06198 CHECKF( gpPalRep[ cnt ].b != NULL );
06199
06200 for( cnt2 = 0; cnt2 < gpPalRep[ cnt ].ubPaletteSize; cnt2++ )
06201 {
06202 if ( !FileRead( hFile, &gpPalRep[ cnt ].r[ cnt2 ], sizeof( UINT8 ), (UINT32 *)NULL ) )
06203 {
06204 return( FALSE );
06205 }
06206 if ( !FileRead( hFile, &gpPalRep[ cnt ].g[ cnt2 ], sizeof( UINT8 ), (UINT32 *)NULL ) )
06207 {
06208 return( FALSE );
06209 }
06210 if ( !FileRead( hFile, &gpPalRep[ cnt ].b[ cnt2 ], sizeof( UINT8 ), (UINT32 *)NULL ) )
06211 {
06212 return( FALSE );
06213 }
06214 }
06215
06216 }
06217
06218 FileClose( hFile );
06219
06220 return( TRUE );
06221 }
06222
06223 BOOLEAN SetPaletteReplacement( SGPPaletteEntry *p8BPPPalette, PaletteRepID aPalRep )
06224 {
06225 UINT32 cnt2;
06226 UINT8 ubType;
06227 UINT8 ubPalIndex;
06228
06229 CHECKF( GetPaletteRepIndexFromID( aPalRep, &ubPalIndex ) );
06230
06231 // Get range type
06232 ubType = gpPalRep[ ubPalIndex ].ubType;
06233
06234 for ( cnt2 = gpPaletteSubRanges[ ubType ].ubStart; cnt2 <= gpPaletteSubRanges[ ubType ].ubEnd; cnt2++ )
06235 {
06236 p8BPPPalette[ cnt2 ].peRed = gpPalRep[ ubPalIndex ].r[ cnt2 - gpPaletteSubRanges[ ubType ].ubStart ];
06237 p8BPPPalette[ cnt2 ].peGreen = gpPalRep[ ubPalIndex ].g[ cnt2 - gpPaletteSubRanges[ ubType ].ubStart ];
06238 p8BPPPalette[ cnt2 ].peBlue = gpPalRep[ ubPalIndex ].b[ cnt2 - gpPaletteSubRanges[ ubType ].ubStart ];
06239 }
06240
06241 return( TRUE );
06242 }
06243
06244
06245 BOOLEAN DeletePaletteData( )
06246 {
06247 UINT32 cnt;
06248
06249 // Free!
06250 if ( gpPaletteSubRanges != NULL )
06251 {
06252 MemFree( gpPaletteSubRanges );
06253 gpPaletteSubRanges = NULL;
06254 }
06255
06256 if ( gubpNumReplacementsPerRange != NULL )
06257 {
06258 MemFree( gubpNumReplacementsPerRange );
06259 gubpNumReplacementsPerRange = NULL;
06260 }
06261
06262
06263 for ( cnt = 0; cnt < guiNumReplacements; cnt++ )
06264 {
06265 // Free
06266 if ( gpPalRep[ cnt ].r != NULL )
06267 {
06268 MemFree( gpPalRep[ cnt ].r );
06269 gpPalRep[ cnt ].r = NULL;
06270 }
06271 if ( gpPalRep[ cnt ].g != NULL )
06272 {
06273 MemFree( gpPalRep[ cnt ].g );
06274 gpPalRep[ cnt ].g = NULL;
06275 }
06276 if ( gpPalRep[ cnt ].b != NULL )
06277 {
06278 MemFree( gpPalRep[ cnt ].b );
06279 gpPalRep[ cnt ].b = NULL;
06280 }
06281 }
06282
06283 // Free
06284 if ( gpPalRep != NULL )
06285 {
06286 MemFree( gpPalRep );
06287 gpPalRep = NULL;
06288 }
06289
06290 return( TRUE );
06291 }
06292
06293
06294 BOOLEAN GetPaletteRepIndexFromID( PaletteRepID aPalRep, UINT8 *pubPalIndex )
06295 {
06296 UINT32 cnt;
06297
06298 // Check if type exists
06299 for ( cnt = 0; cnt < guiNumReplacements; cnt++ )
06300 {
06301 if ( COMPARE_PALETTEREP_ID( aPalRep, gpPalRep[ cnt ].ID ) )
06302 {
06303 *pubPalIndex = ( UINT8 )cnt;
06304 return( TRUE );
06305 }
06306 }
06307
06308 DebugMsg( TOPIC_JA2, DBG_LEVEL_3, "Invalid Palette Replacement ID given");
06309 return( FALSE );
06310 }


Re: JA2 Source Code Digging: Adding new teams?[message #186333] Mon, 26 May 2008 03:20 Go to previous messageGo to next message
Shanga

 
Messages:3507
Registered:January 2000
Location: Danubia

Now, can a programmer translate that to English? Smile


Re: JA2 Source Code Digging: Adding new teams?[message #186356] Mon, 26 May 2008 10:55 Go to previous messageGo to next message
Tron

 
Messages:227
Registered:August 2007
Location: Germany
The source code consists of roughly half a million lines of code*. What you copied here is just a bunch of type and macro declarations for palettes and later some code to load palettes - two very small and pretty unimportant pieces of code. Sorry, nobody is going to "translate [all of it] to English". If you want to tinker with the source code, you won't be able to avoid learning C.

[*] Which is unnecessarily bloated. One part of the effort to improve maintainability in JA2-Stracciatella is to simplify the source code, which resulted in about 150.000 lines (short: 150 kLOC) less code.
Re: JA2 Source Code Digging: Adding new teams?[message #186374] Mon, 26 May 2008 14:25 Go to previous message
Shanga

 
Messages:3507
Registered:January 2000
Location: Danubia
Quote:

just a bunch of type and macro declarations for palettes and later some code to load palettes - two very small and pretty unimportant pieces of code


ROLF you just "translated" them for me. Cheers!


Previous Topic: what is the system bpp?
Next Topic: General modding query regarding extending aim Link length
Goto Forum:
  


Current Time: Mon Apr 24 02:31:56 EEST 2017

Total time taken to generate the page: 0.00830 seconds