forked from yasumitsu/ja2-1.13-source-mirror
-
Notifications
You must be signed in to change notification settings - Fork 0
/
aniviewscreen.cpp
402 lines (301 loc) · 8.38 KB
/
aniviewscreen.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
#ifdef PRECOMPILEDHEADERS
#include "JA2 All.h"
#else
#include "builddefines.h"
#include <stdio.h>
#include <time.h>
#include "sgp.h"
#include "gameloop.h"
#include "himage.h"
#include "vobject.h"
#include "vobject_blitters.h"
#include "worlddef.h"
#include "renderworld.h"
#include "input.h"
#include "font.h"
#include "screenids.h"
#include "container.h"
#include "overhead.h"
#include "sysutil.h"
#include "Font Control.h"
#include "Animation Control.h"
#include "Animation Data.h"
#include "Event Pump.h"
#include "Render Dirty.h"
#include "Sys Globals.h"
#include "Interface.h"
#include <wchar.h>
#include <tchar.h>
#include "english.h"
#include "Fileman.h"
#include "messageboxscreen.h"
#endif
//forward declarations of common classes to eliminate includes
class OBJECTTYPE;
class SOLDIERTYPE;
void BuildListFile( );
BOOLEAN gfAniEditMode = FALSE;
static UINT16 usStartAnim = 0;
static UINT8 ubStartHeight = 0;
static SOLDIERTYPE *pSoldier;
static BOOLEAN fOKFiles = FALSE;
static UINT8 ubNumStates = 0;
static UINT16 *pusStates = NULL;
static INT8 ubCurLoadedState = 0;
void CycleAnimations( )
{
INT32 cnt;
// FInd the next animation with start height the same...
for ( cnt = usStartAnim + 1; cnt < NUMANIMATIONSTATES; cnt++ )
{
if ( gAnimControl[ cnt ].ubHeight == ubStartHeight )
{
usStartAnim = ( UINT8) cnt;
pSoldier->EVENT_InitNewSoldierAnim( usStartAnim, 0 , TRUE );
return;
}
}
usStartAnim = 0;
pSoldier->EVENT_InitNewSoldierAnim( usStartAnim, 0 , TRUE );
}
UINT32 AniEditScreenInit(void)
{
return TRUE;
}
// The ShutdownGame function will free up/undo all things that were started in InitializeGame()
// It will also be responsible to making sure that all Gaming Engine tasks exit properly
UINT32 AniEditScreenShutdown(void)
{
return TRUE;
}
UINT32 AniEditScreenHandle(void)
{
InputAtom InputEvent;
static BOOLEAN fFirstTime = TRUE;
static UINT16 usOldState;
static BOOLEAN fToggle = FALSE;
static BOOLEAN fToggle2 = FALSE;
// EV_S_SETPOSITION SSetPosition;
// Make backups
if ( fFirstTime )
{
gfAniEditMode = TRUE;
usStartAnim = 0;
ubStartHeight = ANIM_STAND;
fFirstTime = FALSE;
fToggle = FALSE;
fToggle2 = FALSE;
ubCurLoadedState = 0;
pSoldier = MercPtrs[ gusSelectedSoldier ];
gTacticalStatus.uiFlags |= LOADING_SAVED_GAME;
pSoldier->EVENT_InitNewSoldierAnim( usStartAnim, 0 , TRUE );
BuildListFile( );
}
/////////////////////////////////////////////////////
StartFrameBufferRender( );
RenderWorld( );
ExecuteBaseDirtyRectQueue( );
/////////////////////////////////////////////////////
EndFrameBufferRender( );
SetFont( LARGEFONT1 );
mprintf( 0,0,L"SOLDIER ANIMATION VIEWER" );
gprintfdirty( (INT16)0,(INT16)0,L"SOLDIER ANIMATION VIEWER" );
mprintf( 0,20,L"Current Animation: %S %S", gAnimControl[ usStartAnim ].zAnimStr, gAnimSurfaceDatabase[ pSoldier->usAnimSurface ].Filename );
gprintfdirty( (INT16)0,(INT16)20,L"Current Animation: %S %S", gAnimControl[ usStartAnim ].zAnimStr, gAnimSurfaceDatabase[ pSoldier->usAnimSurface ].Filename );
switch( ubStartHeight )
{
case ANIM_STAND:
mprintf( 0,40,L"Current Stance: STAND" );
break;
case ANIM_CROUCH:
mprintf( 0,40,L"Current Stance: CROUCH" );
break;
case ANIM_PRONE:
mprintf( 0,40,L"Current Stance: PRONE" );
break;
}
gprintfdirty( (INT16)0,(INT16)40,L"Current Animation: %S", gAnimControl[ usStartAnim ].zAnimStr );
if ( fToggle )
{
mprintf( 0,60,L"FORCE ON" );
gprintfdirty( (INT16)0,(INT16)60,L"FORCE OFF" );
}
if ( fToggle2 )
{
mprintf( 0,70,L"LOADED ORDER ON" );
gprintfdirty( (INT16)0,(INT16)70,L"LOADED ORDER ON" );
mprintf( 0,90,L"LOADED ORDER : %S", gAnimControl[ pusStates[ ubCurLoadedState ] ].zAnimStr );
gprintfdirty( (INT16)0,(INT16)90,L"LOADED ORDER : %S", gAnimControl[ pusStates[ ubCurLoadedState ] ].zAnimStr );
}
if (DequeueSpecificEvent(&InputEvent, KEY_DOWN|KEY_UP|KEY_REPEAT))
{
if ((InputEvent.usEvent == KEY_DOWN)&&(InputEvent.usParam == ESC))
{
fFirstTime = TRUE;
gfAniEditMode = FALSE;
fFirstTimeInGameScreen = TRUE;
gTacticalStatus.uiFlags &= (~LOADING_SAVED_GAME);
if ( fOKFiles )
{
MemFree( pusStates );
}
fOKFiles = FALSE;
return( GAME_SCREEN );
}
if ((InputEvent.usEvent == KEY_UP) && (InputEvent.usParam == SPACE ))
{
if ( !fToggle && !fToggle2 )
{
CycleAnimations( );
}
}
if ((InputEvent.usEvent == KEY_UP) && (InputEvent.usParam == 's' ))
{
if ( !fToggle )
{
UINT16 usAnim=0;
usOldState = usStartAnim;
switch( ubStartHeight )
{
case ANIM_STAND:
usAnim = STANDING;
break;
case ANIM_CROUCH:
usAnim = CROUCHING;
break;
case ANIM_PRONE:
usAnim = PRONE;
break;
}
pSoldier->EVENT_InitNewSoldierAnim( usAnim, 0 , TRUE );
}
else
{
pSoldier->EVENT_InitNewSoldierAnim( usOldState, 0 , TRUE );
}
fToggle = !fToggle;
}
if ((InputEvent.usEvent == KEY_UP) && (InputEvent.usParam == 'l' ))
{
if ( !fToggle2 )
{
usOldState = usStartAnim;
pSoldier->EVENT_InitNewSoldierAnim( pusStates[ ubCurLoadedState ], 0 , TRUE );
}
else
{
pSoldier->EVENT_InitNewSoldierAnim( usOldState, 0 , TRUE );
}
fToggle2 = !fToggle2;
}
if ((InputEvent.usEvent == KEY_UP) && (InputEvent.usParam == PGUP ))
{
if ( fOKFiles && fToggle2 )
{
ubCurLoadedState++;
if ( ubCurLoadedState == ubNumStates )
{
ubCurLoadedState = 0;
}
pSoldier->EVENT_InitNewSoldierAnim( pusStates[ ubCurLoadedState ], 0 , TRUE );
}
}
if ((InputEvent.usEvent == KEY_UP) && (InputEvent.usParam == PGDN ))
{
if ( fOKFiles && fToggle2 )
{
ubCurLoadedState--;
if ( ubCurLoadedState == 0 )
{
ubCurLoadedState = ubNumStates;
}
pSoldier->EVENT_InitNewSoldierAnim( pusStates[ ubCurLoadedState ], 0 , TRUE );
}
}
if ((InputEvent.usEvent == KEY_UP) && (InputEvent.usParam == 'c' ))
{
// CLEAR!
usStartAnim = 0;
pSoldier->EVENT_InitNewSoldierAnim( usStartAnim, 0 , TRUE );
}
if ((InputEvent.usEvent == KEY_UP) && (InputEvent.usParam == ENTER ))
{
if ( ubStartHeight == ANIM_STAND )
{
ubStartHeight = ANIM_CROUCH;
}
else if ( ubStartHeight == ANIM_CROUCH )
{
ubStartHeight = ANIM_PRONE;
}
else
{
ubStartHeight = ANIM_STAND;
}
}
}
return( ANIEDIT_SCREEN );
}
UINT16 GetAnimStateFromName( STR8 zName )
{
INT32 cnt;
// FInd the next animation with start height the same...
for ( cnt = 0; cnt < NUMANIMATIONSTATES; cnt++ )
{
if ( _stricmp( gAnimControl[ cnt ].zAnimStr, zName ) == 0 )
{
return( (UINT16) cnt );
}
}
return( 5555 );
}
void BuildListFile( )
{
FILE *infoFile;
CHAR8 currFilename[128];
int numEntries = 0;
int cnt;
UINT16 usState;
CHAR16 zError[128];
//Verify the existance of the header text file.
infoFile = fopen( "ANITEST.DAT", "rb");
if(!infoFile)
{
return;
}
//count STIs inside header and verify each one's existance.
while( !feof( infoFile ) )
{
fgets( currFilename, 128, infoFile );
//valid entry in header, continue on...
numEntries++;
}
fseek( infoFile, 0, SEEK_SET ); //reset header file
// Allocate array
pusStates = (UINT16 *) MemAlloc( sizeof( UINT16 ) * numEntries );
fOKFiles = TRUE;
cnt = 0;
while( !feof( infoFile ) && cnt < numEntries )
{
fgets( currFilename, 128, infoFile );
// Remove newline
currFilename[ strlen( currFilename ) -1 ] = '\0';
currFilename[ strlen( currFilename ) -1 ] = '\0';
usState = GetAnimStateFromName( currFilename );
if ( usState != 5555 )
{
// Bob: swapped places, there's numEntries things to be put in pusStates, I'm guessing supposed to start at 0
pusStates[cnt] = usState;
cnt++;
ubNumStates = (UINT8)cnt;
// pusStates[ cnt ] = usState;
}
else
{
swprintf( zError, L"Animation str %S is not known: ", currFilename );
DoMessageBox( MSG_BOX_BASIC_STYLE, zError, ANIEDIT_SCREEN, ( UINT8 )MSG_BOX_FLAG_YESNO, NULL, NULL );
fclose( infoFile );
return;
}
}
}