4b825dc642cb6eb9a060e54bf8d69288fbee4904ebd360ec63ec976c05699f3180e866b3f69e5472
 
 
1
#include <assert.h>
 
 
2
#include <SDL/SDL.h>
 
 
3
#include <GL/gl.h>
 
 
4
#include "menus.h"
 
 
5
#include <time.h>
 
 
6
#include "system.h"
 
 
7
#include "prototyp.h"
 
 
8
#include "stratdef.h"
 
 
9
#include "net.h"
 
 
10
#include "hud.h"
 
 
11
#include "userprofile.h"
 
 
12
#include "avp_mp_config.h"
 
 
13
#include "savegame.h"
 
 
14
#include "psnd.h"
 
 
15
#include "bh_types.h"
 
 
16
 
 
 
17
extern const struct Map alien_episodes[];
 
 
18
extern const struct Map marine_episodes[];
 
 
19
extern const struct Map predator_episodes[];
 
 
20
 
 
 
21
extern void MakeMarineKeyConfigMenu();
 
 
22
extern void MakePredatorKeyConfigMenu();
 
 
23
extern void MakeAlienKeyConfigMenu();
 
 
24
extern void DrawSliderBar(int x, int y, int alpha);
 
 
25
extern void DrawSlider(int x, int y, int alpha);
 
 
26
extern void DrawRectangle(int x, int y, int w, int h, int alpha);
 
 
27
extern void Rectangle(int x0, int y0, int x1, int y1, int r, int g, int b, int a);
 
 
28
extern void DrawColourBar(int yTop, int yBottom, int rScale, int gScale, int bScale);
 
 
29
extern void GetNextAllowedSpecies(int* species,int search_forwards);
 
 
30
 
 
 
31
extern const char* marine_briefing_text[];
 
 
32
extern const char* alien_briefing_text[];
 
 
33
extern const char* predator_briefing_text[];
 
 
34
extern const char* cheat_modes[];
 
 
35
static const char* BriefingTextString[5];
 
 
36
 
 
 
37
extern int MP_Species;
 
 
38
extern uint8_t* Keyboard;
 
 
39
extern int number_of_available_keys;
 
 
40
 
 
 
41
extern struct AVP_USER_PROFILE UserProfile;
 
 
42
SAVE_SLOT_HEADER SaveGameSlot[NUMBER_OF_SAVE_SLOTS];
 
 
43
 
 
 
44
extern char AAFontWidths[256];
 
 
45
extern int RealFrameTime;
 
 
46
extern SCREENDESCRIPTORBLOCK ScreenDescriptorBlock;
 
 
47
 
 
 
48
extern char IPAddressString[]; 
 
 
49
extern char MP_Config_Description[];
 
 
50
extern char MP_Config_Name[];
 
 
51
static AVP_MENUS Menus;
 
 
52
extern MENU MenusData[];
 
 
53
 
 
 
54
extern int episode_to_play;
 
 
55
extern int CloakingPhase;
 
 
56
 
 
 
57
static int InputIsDebounced = 0;
 
 
58
static int KeyDepressedCounter = 0;
 
 
59
static int EpisodeSelectScrollOffset;
 
 
60
static int MaximumSelectableLevel;
 
 
61
static int KeyConfigSelectionColumn;
 
 
62
 
 
 
63
static int Brightness[16];
 
 
64
 
 
 
65
static uint8_t MultipleAssignments[2][32];
 
 
66
 
 
 
67
static PLAYER_INPUT_CONFIGURATION PlayerInputPrimaryConfig;
 
 
68
static PLAYER_INPUT_CONFIGURATION PlayerInputSecondaryConfig;
 
 
69
 
 
 
70
CONTROL_METHODS PlayerControlMethods;
 
 
71
 
 
 
72
static int MultiplayerConfigurationIndex; //just used for the configuration deletion stuff
 
 
73
static const char* MultiplayerConfigurationName = NULL; //ditto
 
 
74
 
 
 
75
static int HeightOfMenuElement(MENU_ELEMENT *elementPtr)
 
 
76
{
 
 
77
    int h = MENU_ELEMENT_SPACING;
 
 
78
 
 
 
79
    switch(elementPtr->ElementID)
 
 
80
    {
 
 
81
        default:
 
 
82
        {
 
 
83
            if (Menus.FontToUse == MENU_FONT_BIG)
 
 
84
                h += MENU_FONT_HEIGHT;
 
 
85
            else
 
 
86
                h = HUD_FONT_HEIGHT+4;
 
 
87
        }
 
 
88
        break;
 
 
89
        case MENU_ELEMENT_LOADGAME:
 
 
90
        case MENU_ELEMENT_SAVEGAME:
 
 
91
            h = HUD_FONT_HEIGHT*2+4;
 
 
92
        break;
 
 
93
        case MENU_ELEMENT_TEXTFIELD_SMALLWRAPPED :
 
 
94
            h += HUD_FONT_HEIGHT*4;
 
 
95
    }
 
 
96
 
 
 
97
return h;
 
 
98
}
 
 
99
 
 
 
100
static void SetBriefingTextToBlank()
 
 
101
{    
 
 
102
    BriefingTextString[0] = "";
 
 
103
    BriefingTextString[1] = "";
 
 
104
    BriefingTextString[2] = "";
 
 
105
    BriefingTextString[3] = "";
 
 
106
    BriefingTextString[4] = "";
 
 
107
}
 
 
108
 
 
 
109
static void SetBriefingTextForEpisode(int episode)
 
 
110
{
 
 
111
    int i=0;
 
 
112
    const char ** temp_ptr;
 
 
113
 
 
 
114
    switch(AvP.PlayerType)
 
 
115
    {
 
 
116
        default:
 
 
117
            SetBriefingTextToBlank();
 
 
118
        return;
 
 
119
        case I_Marine:
 
 
120
            temp_ptr = marine_briefing_text;
 
 
121
        break;
 
 
122
        case I_Predator:
 
 
123
            temp_ptr = predator_briefing_text;
 
 
124
        break;
 
 
125
        case I_Alien:
 
 
126
            temp_ptr = alien_briefing_text;
 
 
127
    }
 
 
128
 
 
 
129
    for(; i < 5; i++)
 
 
130
        BriefingTextString[i] =  temp_ptr[episode * 5 + i];
 
 
131
}
 
 
132
 
 
 
133
static int NumberOfAvailableLevels()
 
 
134
{
 
 
135
    int i;
 
 
136
    int maximumLevel;
 
 
137
    int numberOfBasicLevels;
 
 
138
    enum gamedifficulty maxDifficulty = I_Hard;
 
 
139
 
 
 
140
    episode_to_play = EpisodeSelectScrollOffset = 0;
 
 
141
 
 
 
142
    switch(AvP.PlayerType)
 
 
143
    {
 
 
144
        case I_Marine:
 
 
145
            maximumLevel = MAX_NO_OF_MARINE_EPISODES-1;
 
 
146
            numberOfBasicLevels = MAX_NO_OF_BASIC_MARINE_EPISODES;
 
 
147
        break;
 
 
148
        case I_Predator:
 
 
149
            maximumLevel = MAX_NO_OF_PREDATOR_EPISODES-1;
 
 
150
            numberOfBasicLevels = MAX_NO_OF_BASIC_PREDATOR_EPISODES;
 
 
151
        break;
 
 
152
        case I_Alien:
 
 
153
            maximumLevel = MAX_NO_OF_ALIEN_EPISODES-1;
 
 
154
            numberOfBasicLevels = MAX_NO_OF_BASIC_ALIEN_EPISODES;
 
 
155
    }
 
 
156
 
 
 
157
    for (i=0; i < numberOfBasicLevels; i++)
 
 
158
    {
 
 
159
        if (Not_Completed == UserProfile.LevelCompleted[AvP.PlayerType].Difficulty[i])
 
 
160
            return (MaximumSelectableLevel = i);
 
 
161
        else if (UserProfile.LevelCompleted[AvP.PlayerType].Difficulty[i] < maxDifficulty)
 
 
162
            maxDifficulty = UserProfile.LevelCompleted[AvP.PlayerType].Difficulty[i];
 
 
163
    }
 
 
164
 
 
 
165
    MaximumSelectableLevel = maximumLevel;
 
 
166
 
 
 
167
    switch(maxDifficulty)
 
 
168
    {
 
 
169
        default:
 
 
170
        case I_Easy:
 
 
171
            MaximumSelectableLevel -= 3;
 
 
172
        break;
 
 
173
        case I_Medium:
 
 
174
            MaximumSelectableLevel -= 1;
 
 
175
        case I_Hard:
 
 
176
        break;
 
 
177
    }
 
 
178
 
 
 
179
return maximumLevel;
 
 
180
}
 
 
181
 
 
 
182
static int LevelMostLikelyToPlay(int number_of_episodes)
 
 
183
{
 
 
184
    int i;
 
 
185
 
 
 
186
    for(i=0; i < number_of_episodes; i++)
 
 
187
    {
 
 
188
        if(I_Hard == UserProfile.LevelCompleted[AvP.PlayerType].Difficulty[i])
 
 
189
            continue;
 
 
190
        else
 
 
191
            break;
 
 
192
    }
 
 
193
 
 
 
194
    if(number_of_episodes == i)
 
 
195
        return 0; // All done
 
 
196
 
 
 
197
    if(!i)
 
 
198
    {
 
 
199
        for(; i < number_of_episodes; i++)
 
 
200
        {
 
 
201
            if(I_Medium == UserProfile.LevelCompleted[AvP.PlayerType].Difficulty[i])
 
 
202
                continue;
 
 
203
            else if(I_Hard == UserProfile.LevelCompleted[AvP.PlayerType].Difficulty[i]) // bonus levels is set to I_Hard by default
 
 
204
                continue;
 
 
205
            else
 
 
206
                break;
 
 
207
        }
 
 
208
 
 
 
209
        if(number_of_episodes == i)
 
 
210
            return 0; // begin with new difficulty?
 
 
211
    }
 
 
212
 
 
 
213
    if(!i)
 
 
214
    {
 
 
215
        for(; i < number_of_episodes; i++)
 
 
216
        {
 
 
217
            if((I_Easy == UserProfile.LevelCompleted[AvP.PlayerType].Difficulty[i])
 
 
218
            ||
 
 
219
            (I_Hard == UserProfile.LevelCompleted[AvP.PlayerType].Difficulty[i])) // bonus levels is set to I_Hard by default
 
 
220
                continue;
 
 
221
            else
 
 
222
                break;
 
 
223
        }
 
 
224
 
 
 
225
        if(number_of_episodes == i)
 
 
226
            return 0; // begin with new difficulty?
 
 
227
    }
 
 
228
 
 
 
229
return i;
 
 
230
}
 
 
231
 
 
 
232
static void SetupNewMenu(enum MENU_ID menuID)
 
 
233
{
 
 
234
    Menus.CurrentMenu = menuID;
 
 
235
 
 
 
236
    /* set pointer to the start of the menu's element data */
 
 
237
    Menus.MenuElements = MenusData[menuID].MenuElements; // could use default
 
 
238
 
 
 
239
    Menus.FontToUse = MenusData[menuID].FontToUse;
 
 
240
    Menus.CurrentlySelectedElement = 0;
 
 
241
    Menus.UserEnteringText = 0;
 
 
242
    Menus.UserChangingKeyConfig = 0;
 
 
243
    Menus.PositionInTextField = 0;
 
 
244
    Menus.WidthLeftForText = 0;
 
 
245
 
 
 
246
    switch(menuID)
 
 
247
    {
 
 
248
        case MENU_MAIN:
 
 
249
        {
 
 
250
            AvP.PlayMode = SinglePlayer;
 
 
251
            static int do_once = 0;
 
 
252
 
 
 
253
            if (!do_once && AnyCheatModesAllowed())
 
 
254
            {
 
 
255
                do_once = 1;
 
 
256
                MenusData->MenuElements[5] = MenusData->MenuElements[6];
 
 
257
                MenusData->MenuElements[5].ElementID = MENU_ELEMENT_GOTOMENU;
 
 
258
                MenusData->MenuElements[6].ElementID = MENU_ELEMENT_QUITGAME;
 
 
259
            }
 
 
260
        }
 
 
261
        break;
 
 
262
        case MENU_MULTIPLAYER_MAINSTART:
 
 
263
            LoadMultiplayerConfiguration("previous_game");
 
 
264
        break;
 
 
265
        case MENU_SKIRMISH:
 
 
266
            AvP.PlayMode = Skirmish;
 
 
267
            LoadMultiplayerConfiguration("previous_game");
 
 
268
            netGameData.gameType = NGT_Coop; //force 'cooperative' game if using skirmish mode
 
 
269
        // no break;
 
 
270
        case MENU_MULTIPLAYER_HOSTSETUP:
 
 
271
        {
 
 
272
            MENU_ELEMENT *elementPtr;
 
 
273
 
 
 
274
            AvP.PlayMode = (MENU_SKIRMISH == menuID) ? Skirmish : NetworkHost;
 
 
275
 
 
 
276
            if(NGT_Coop == netGameData.gameType)
 
 
277
            {
 
 
278
                extern const char** CoopLevelNames;
 
 
279
                extern int NumCoopLevels;
 
 
280
 
 
 
281
                elementPtr = MenusData[MENU_SKIRMISH].MenuElements;
 
 
282
                elementPtr += 2;
 
 
283
                elementPtr->b.MaxSliderValue = NumCoopLevels - 1;
 
 
284
                elementPtr->d.TextSliderStringPointer = CoopLevelNames;
 
 
285
 
 
 
286
                elementPtr = MenusData[MENU_MULTIPLAYER_HOSTSETUP].MenuElements;
 
 
287
                elementPtr += 2;
 
 
288
                elementPtr->b.MaxSliderValue = NumCoopLevels - 1;
 
 
289
                elementPtr->d.TextSliderStringPointer = CoopLevelNames;
 
 
290
            }
 
 
291
            else
 
 
292
            {
 
 
293
                extern const char** MultiplayerLevelNames;
 
 
294
                extern int NumMultiplayerLevels;
 
 
295
 
 
 
296
                elementPtr = MenusData[MENU_MULTIPLAYER_HOSTSETUP].MenuElements;
 
 
297
                elementPtr += 2;
 
 
298
                elementPtr->b.MaxSliderValue = NumMultiplayerLevels - 1;
 
 
299
                elementPtr->d.TextSliderStringPointer = MultiplayerLevelNames;
 
 
300
            }
 
 
301
        }
 
 
302
        break;
 
 
303
        /*
 
 
304
        case MENU_MULTIPLAYER_SAVECONFIG:
 
 
305
            Menus.UserEnteringText = 1;
 
 
306
            Menus.WidthLeftForText = 0; //will be calculated properly when menus are drawn
 
 
307
        break;
 
 
308
        */
 
 
309
        case MENU_SELECT_EPISODE:
 
 
310
        {
 
 
311
            switch(AvP.PlayerType)
 
 
312
            {
 
 
313
                default:
 
 
314
                case I_Alien:
 
 
315
                    Menus.MenuElements->b.MaxSliderValue = NumberOfAvailableLevels();
 
 
316
                    *Menus.MenuElements->c.SliderValuePtr = LevelMostLikelyToPlay(MAX_NO_OF_ALIEN_EPISODES);
 
 
317
                break;
 
 
318
                case I_Marine:
 
 
319
                    Menus.MenuElements->b.MaxSliderValue = NumberOfAvailableLevels();
 
 
320
                    *Menus.MenuElements->c.SliderValuePtr = LevelMostLikelyToPlay(MAX_NO_OF_MARINE_EPISODES);
 
 
321
                break;
 
 
322
                case I_Predator:
 
 
323
                    Menus.MenuElements->b.MaxSliderValue = NumberOfAvailableLevels();
 
 
324
                    *Menus.MenuElements->c.SliderValuePtr = LevelMostLikelyToPlay(MAX_NO_OF_PREDATOR_EPISODES);
 
 
325
            }
 
 
326
        }
 
 
327
        break;
 
 
328
        case MENU_ALIENKEYCONFIG:
 
 
329
        {
 
 
330
            MakeAlienKeyConfigMenu();
 
 
331
            PlayerInputPrimaryConfig = UserProfile.AlienInputPrimaryConfig;
 
 
332
            PlayerInputSecondaryConfig = UserProfile.AlienInputSecondaryConfig;
 
 
333
            EpisodeSelectScrollOffset = 0;
 
 
334
            KeyConfigSelectionColumn = 0;
 
 
335
        }
 
 
336
        break;
 
 
337
        case MENU_MARINEKEYCONFIG:
 
 
338
        {
 
 
339
            MakeMarineKeyConfigMenu();
 
 
340
            PlayerInputPrimaryConfig = UserProfile.MarineInputPrimaryConfig;
 
 
341
            PlayerInputSecondaryConfig = UserProfile.MarineInputSecondaryConfig;
 
 
342
            EpisodeSelectScrollOffset = 0;
 
 
343
            KeyConfigSelectionColumn = 0;
 
 
344
        }
 
 
345
        break;
 
 
346
        case MENU_PREDATORKEYCONFIG:
 
 
347
        {
 
 
348
            MakePredatorKeyConfigMenu();
 
 
349
            PlayerInputPrimaryConfig = UserProfile.PredatorInputPrimaryConfig;
 
 
350
            PlayerInputSecondaryConfig = UserProfile.PredatorInputSecondaryConfig;
 
 
351
            EpisodeSelectScrollOffset = 0;
 
 
352
            KeyConfigSelectionColumn = 0;
 
 
353
        }
 
 
354
        break;
 
 
355
        case MENU_MOUSEOPTIONS:
 
 
356
            PlayerControlMethods = UserProfile.ControlMethods;
 
 
357
        break;
 
 
358
        case MENU_SAVEGAME:
 
 
359
        case MENU_LOADGAME:
 
 
360
            ScanSaveSlots();
 
 
361
        break;
 
 
362
        case MENU_SINGLEPLAYER:
 
 
363
            AvP.PlayMode = SinglePlayer;
 
 
364
        default:
 
 
365
        break;
 
 
366
    }
 
 
367
 
 
 
368
    /* count the number of elements in the menu */
 
 
369
    {
 
 
370
        MENU_ELEMENT *elementPtr = Menus.MenuElements;
 
 
371
        Menus.NumberOfElementsInMenu = 0;
 
 
372
        Menus.MenuHeight = 0;
 
 
373
 
 
 
374
        do
 
 
375
        {
 
 
376
            elementPtr->Brightness = BRIGHTNESS_OF_DARKENED_ELEMENT;
 
 
377
 
 
 
378
            Menus.MenuHeight += HeightOfMenuElement(elementPtr);
 
 
379
            Menus.NumberOfElementsInMenu++;
 
 
380
            elementPtr++;
 
 
381
 
 
 
382
        } while(elementPtr->ElementID != MENU_ELEMENT_ENDOFMENU);
 
 
383
    }       
 
 
384
 
 
 
385
    switch(menuID)
 
 
386
    {
 
 
387
        case MENU_BONUSOPTIONS:
 
 
388
            //UserProfile.active_bonus = 0;
 
 
389
        break;
 
 
390
        case MENU_MARINEKEYCONFIG:
 
 
391
        case MENU_ALIENKEYCONFIG:
 
 
392
        case MENU_PREDATORKEYCONFIG:
 
 
393
            Menus.MenuHeight += 50;
 
 
394
        break;
 
 
395
        case MENU_LEVELBRIEFING_BASIC:
 
 
396
        {
 
 
397
            /* find available difficulty levels */
 
 
398
            if(!episode_to_play)
 
 
399
            {
 
 
400
                Menus.NumberOfElementsInMenu = 3;
 
 
401
                // highlight a suitable level of difficulty
 
 
402
                // default to medium difficulty for first level
 
 
403
                Menus.CurrentlySelectedElement = 1;
 
 
404
            }
 
 
405
            else
 
 
406
            {
 
 
407
                switch(UserProfile.LevelCompleted[AvP.PlayerType].Difficulty[episode_to_play-1])
 
 
408
                {
 
 
409
                    default:
 
 
410
                    case I_Easy:
 
 
411
                        Menus.NumberOfElementsInMenu = 1;
 
 
412
                        Menus.CurrentlySelectedElement = 0;
 
 
413
                    break;
 
 
414
                    case I_Medium:
 
 
415
                        Menus.NumberOfElementsInMenu = 2;
 
 
416
                        Menus.CurrentlySelectedElement = 1;
 
 
417
                    break;
 
 
418
                    case I_Hard:
 
 
419
                        Menus.NumberOfElementsInMenu = 3;
 
 
420
                        Menus.CurrentlySelectedElement = 2;
 
 
421
                }
 
 
422
            }
 
 
423
        }
 
 
424
        case MENU_LEVELBRIEFING_BONUS:
 
 
425
            SetBriefingTextForEpisode(episode_to_play);
 
 
426
        break;
 
 
427
        default:
 
 
428
            SetBriefingTextToBlank();
 
 
429
    }
 
 
430
}
 
 
431
 
 
 
432
static void RenderBriefingText(int centreY, int brightness)
 
 
433
{
 
 
434
    int lengthOfLongestLine = -1;
 
 
435
    int x,y,i;
 
 
436
 
 
 
437
    for(i=0; i < 5; i++)
 
 
438
    {
 
 
439
        int length = 0;
 
 
440
 
 
 
441
        const char *ptr = BriefingTextString[i];
 
 
442
 
 
 
443
        if (ptr)
 
 
444
        while(*ptr)
 
 
445
            length += AAFontWidths[(uint8_t)(*ptr++)];
 
 
446
 
 
 
447
        if (lengthOfLongestLine < length)
 
 
448
            lengthOfLongestLine = length;
 
 
449
    }
 
 
450
 
 
 
451
    x = (ScreenDescriptorBlock.SDB_Width - lengthOfLongestLine)/2;
 
 
452
    y = centreY - 3*HUD_FONT_HEIGHT;
 
 
453
 
 
 
454
    for(i=0; i < 5; i++)
 
 
455
    {
 
 
456
        RenderSmallMenuText(BriefingTextString[i], x, y, brightness, MENUFORMAT_LEFTJUSTIFIED/*,MENU_CENTREY-60-100,MENU_CENTREY-60+180*/);
 
 
457
 
 
 
458
        y += i ? HUD_FONT_HEIGHT : HUD_FONT_HEIGHT*2; 
 
 
459
    }
 
 
460
}
 
 
461
 
 
 
462
static void RenderBriefingScreenInfo()
 
 
463
{
 
 
464
    const char * episode_ptr;
 
 
465
 
 
 
466
    switch (AvP.PlayerType)
 
 
467
    {
 
 
468
        case I_Marine:
 
 
469
            episode_ptr =  marine_episodes[episode_to_play].pretty_name;
 
 
470
        break;
 
 
471
        case I_Predator:
 
 
472
            episode_ptr =  predator_episodes[episode_to_play].pretty_name;
 
 
473
        break;
 
 
474
        case I_Alien:
 
 
475
            episode_ptr =  alien_episodes[episode_to_play].pretty_name;
 
 
476
        break;
 
 
477
        default:
 
 
478
            episode_ptr = "";
 
 
479
    }
 
 
480
 
 
 
481
    RenderSmallMenuText(episode_ptr, MENU_LEFTXEDGE, 120, ONE_FIXED, MENUFORMAT_LEFTJUSTIFIED);
 
 
482
 
 
 
483
    RenderBriefingText(ScreenDescriptorBlock.SDB_CentreY, ONE_FIXED);
 
 
484
}
 
 
485
 
 
 
486
int LengthOfSmallMenuText(const char *textPtr)
 
 
487
{
 
 
488
    int width = 0;
 
 
489
 
 
 
490
    while (textPtr && *textPtr) 
 
 
491
    {
 
 
492
        width += AAFontWidths[(unsigned int) *textPtr];
 
 
493
 
 
 
494
        textPtr++;
 
 
495
    }
 
 
496
 
 
 
497
return width;
 
 
498
}
 
 
499
 
 
 
500
static int IsFlamerInLevel(int level)
 
 
501
{
 
 
502
    return strcmp(AvP.LevelName, "Subway");
 
 
503
}
 
 
504
 
 
 
505
static int IsMinigunInLevel(int level)
 
 
506
{
 
 
507
    return strcmp(AvP.LevelName, "Sewer");
 
 
508
}
 
 
509
 
 
 
510
static int IsSadarInLevel(int level)
 
 
511
{
 
 
512
    if(!strcmp(AvP.LevelName, "Massacre")
 
 
513
    ||
 
 
514
    !strcmp(AvP.LevelName, "Meat Factory")
 
 
515
    ||
 
 
516
    !strcmp(AvP.LevelName, "Hadley's Hope")
 
 
517
    ||
 
 
518
    !strcmp(AvP.LevelName, "Hive")
 
 
519
    ||
 
 
520
    !strcmp(AvP.LevelName, "Stranded")
 
 
521
    ||
 
 
522
    !strcmp(AvP.LevelName, "Leadworks"))
 
 
523
        return 0;
 
 
524
    else
 
 
525
        return 1;
 
 
526
}
 
 
527
 
 
 
528
static int IsSkeeterInLevel(int level)
 
 
529
{
 
 
530
    return strcmp(AvP.LevelName, "Leadworks");
 
 
531
}
 
 
532
 
 
 
533
static int IsSmartgunInLevel(int level)
 
 
534
{
 
 
535
    return strcmp(AvP.LevelName, "Nostromo");
 
 
536
}
 
 
537
 
 
 
538
static char MultiplayerBriefing[3][100];
 
 
539
 
 
 
540
static void AddMultiplayerBriefingString(const char* text)
 
 
541
{
 
 
542
    int shortest = 0;
 
 
543
    int shortest_length =1000;
 
 
544
    int i=0;
 
 
545
 
 
 
546
    for(; i < 3; i++)
 
 
547
    {
 
 
548
        int length = strlen(MultiplayerBriefing[i]);
 
 
549
 
 
 
550
        if(length < shortest_length)
 
 
551
        {
 
 
552
            shortest = i;
 
 
553
            shortest_length = length;
 
 
554
        }
 
 
555
    }
 
 
556
 
 
 
557
    if(shortest_length + 3 + strlen(text) >= 100)
 
 
558
        return;
 
 
559
 
 
 
560
    if(shortest_length > 0)
 
 
561
        strcat(MultiplayerBriefing[shortest], " , ");
 
 
562
 
 
 
563
    strcat(MultiplayerBriefing[shortest], text);
 
 
564
}
 
 
565
 
 
 
566
static int SetBriefingTextForMultiplayer()
 
 
567
{
 
 
568
    int level = NumberForCurrentLevel();
 
 
569
    int num_not_available = 0;
 
 
570
 
 
 
571
    SetBriefingTextToBlank();
 
 
572
 
 
 
573
    if (-1 == level)
 
 
574
        return 0;
 
 
575
 
 
 
576
    MultiplayerBriefing[0][0] = '\0';
 
 
577
    MultiplayerBriefing[1][0] = '\0';
 
 
578
    MultiplayerBriefing[2][0] = '\0';
 
 
579
 
 
 
580
    if(!netGameData.allowSmartgun || !IsSmartgunInLevel(level))
 
 
581
    {
 
 
582
        AddMultiplayerBriefingString("Smartgun");
 
 
583
        num_not_available++;
 
 
584
    }
 
 
585
 
 
 
586
    if(!netGameData.allowFlamer || !IsFlamerInLevel(level))
 
 
587
    {
 
 
588
        AddMultiplayerBriefingString("Flamethrower");
 
 
589
        num_not_available++;
 
 
590
    }
 
 
591
 
 
 
592
    if(!netGameData.allowSadar || !IsSadarInLevel(level))
 
 
593
    {
 
 
594
        AddMultiplayerBriefingString("SADAR");
 
 
595
        num_not_available++;
 
 
596
    }
 
 
597
 
 
 
598
    if(!netGameData.allowGrenadeLauncher)
 
 
599
    {
 
 
600
        AddMultiplayerBriefingString("Grenade Launcher");
 
 
601
        num_not_available++;
 
 
602
    }
 
 
603
 
 
 
604
    if(!netGameData.allowMinigun || !IsMinigunInLevel(level))
 
 
605
    {
 
 
606
        AddMultiplayerBriefingString("Minigun");
 
 
607
        num_not_available++;
 
 
608
    }
 
 
609
 
 
 
610
    if(!netGameData.allowSmartDisc || !IsSkeeterInLevel(level))
 
 
611
    {
 
 
612
        AddMultiplayerBriefingString("Skeeter Launcher");
 
 
613
        num_not_available++;
 
 
614
    }
 
 
615
 
 
 
616
    if(!netGameData.allowPistols)
 
 
617
    {
 
 
618
        AddMultiplayerBriefingString("Pistol");
 
 
619
        num_not_available++;
 
 
620
    }
 
 
621
 
 
 
622
    if(!netGameData.allowDisc)
 
 
623
    {
 
 
624
        AddMultiplayerBriefingString("Disc");
 
 
625
        num_not_available++;
 
 
626
    }
 
 
627
 
 
 
628
    if(!netGameData.allowPistol)
 
 
629
    {
 
 
630
        AddMultiplayerBriefingString("Predator Pistol");
 
 
631
        num_not_available++;
 
 
632
    }
 
 
633
 
 
 
634
    if(!netGameData.allowPlasmaCaster)
 
 
635
    {
 
 
636
        AddMultiplayerBriefingString("Shoulder Cannon");
 
 
637
        num_not_available++;
 
 
638
    }
 
 
639
 
 
 
640
    if(!netGameData.allowSpeargun)
 
 
641
    {
 
 
642
        AddMultiplayerBriefingString("Speargun");
 
 
643
        num_not_available++;
 
 
644
    }
 
 
645
 
 
 
646
    if(!netGameData.allowMedicomp)
 
 
647
    {
 
 
648
        AddMultiplayerBriefingString("Medicomp");
 
 
649
        num_not_available++;
 
 
650
    }
 
 
651
 
 
 
652
    if(num_not_available)
 
 
653
    {
 
 
654
        BriefingTextString[1] = "Unavailable weapons:";
 
 
655
        BriefingTextString[2] = MultiplayerBriefing[0];
 
 
656
        BriefingTextString[3] = MultiplayerBriefing[1];
 
 
657
        BriefingTextString[4] = MultiplayerBriefing[2];
 
 
658
    }
 
 
659
 
 
 
660
return num_not_available;
 
 
661
}
 
 
662
 
 
 
663
static void RenderBriefingText2(int centreY, int brightness)
 
 
664
{
 
 
665
    int i;
 
 
666
    int x = ScreenDescriptorBlock.SDB_CentreX;
 
 
667
    int y = centreY - 4 * HUD_FONT_HEIGHT;
 
 
668
 
 
 
669
    for(i=1; i < 5; i++)
 
 
670
    {
 
 
671
        RenderSmallMenuText(BriefingTextString[i], x, y, brightness, MENUFORMAT_CENTREJUSTIFIED);
 
 
672
        y += HUD_FONT_HEIGHT;
 
 
673
    }
 
 
674
}
 
 
675
 
 
 
676
static void RenderMenuElement(MENU_ELEMENT *elementPtr, int e, int y)
 
 
677
{
 
 
678
    switch(elementPtr->ElementID)
 
 
679
    {
 
 
680
        case MENU_ELEMENT_STARTSKIRMISH:
 
 
681
        {
 
 
682
            RenderSmallMenuText(elementPtr->menu_name, ScreenDescriptorBlock.SDB_CentreX, y, elementPtr->Brightness, MENUFORMAT_CENTREJUSTIFIED);
 
 
683
 
 
 
684
            if(SetBriefingTextForMultiplayer())
 
 
685
                RenderBriefingText2(y, ONE_FIXED);
 
 
686
        }
 
 
687
        break;
 
 
688
        case MENU_ELEMENT_STARTMPGAME: //fall thru
 
 
689
        case MENU_ELEMENT_JOINMPGAME: // fall thru
 
 
690
        {
 
 
691
            //RenderBriefingText(ScreenDescriptorBlock.SDB_CentreY, ONE_FIXED);
 
 
692
            if(SetBriefingTextForMultiplayer())
 
 
693
                RenderBriefingText2(y, ONE_FIXED);
 
 
694
 
 
 
695
        } // no break for you
 
 
696
        case MENU_ELEMENT_GOTOMENU:
 
 
697
        case MENU_ELEMENT_RESUMEGAME:
 
 
698
        case MENU_ELEMENT_RESTARTGAME:
 
 
699
        case MENU_ELEMENT_DIFFICULTYLEVEL:
 
 
700
        case MENU_ELEMENT_KEYCONFIGOK:
 
 
701
        case MENU_ELEMENT_RESETKEYCONFIG:
 
 
702
        case MENU_ELEMENT_SAVEMPCONFIG:
 
 
703
        case MENU_ELEMENT_RESETMPCONFIG:
 
 
704
        case MENU_ELEMENT_DELETEMPCONFIG:
 
 
705
        case MENU_ELEMENT_QUITGAME:
 
 
706
        case MENU_ELEMENT_STARTLEVELWITHCHEAT:
 
 
707
        case MENU_ELEMENT_SELECT_SPECIES:
 
 
708
            RenderSmallMenuText(elementPtr->menu_name, ScreenDescriptorBlock.SDB_CentreX, y, elementPtr->Brightness, MENUFORMAT_CENTREJUSTIFIED);
 
 
709
        break;
 
 
710
        case MENU_ELEMENT_LEVELNAME:
 
 
711
        {
 
 
712
            RenderSmallMenuText("Environment", ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
713
 
 
 
714
            if(elementPtr->d.TextSliderStringPointer)
 
 
715
            {
 
 
716
                int index = *elementPtr->c.SliderValuePtr;
 
 
717
                const char *level_name = elementPtr->d.TextSliderStringPointer[index];
 
 
718
                strncpy(AvP.LevelName, level_name, 39);
 
 
719
 
 
 
720
                if(index >= ((NGT_Coop == netGameData.gameType) ? MAX_NO_OF_COOPERATIVE_EPISODES : MAX_NO_OF_MULTIPLAYER_EPISODES))
 
 
721
                {
 
 
722
                    char *p = strstr(AvP.LevelName, "(c)");
 
 
723
 
 
 
724
                    if(NULL != p)
 
 
725
                    {
 
 
726
                        *p = '\0';
 
 
727
                    }
 
 
728
                    else
 
 
729
                    {
 
 
730
                        p = strstr(AvP.LevelName, ".rif");
 
 
731
 
 
 
732
                        if(NULL != p)
 
 
733
                            *p = '\0';
 
 
734
                    }
 
 
735
                    strcat(AvP.LevelName, " (custom)");
 
 
736
                    RenderSmallMenuText(AvP.LevelName, ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_LEFTJUSTIFIED);
 
 
737
                    snprintf(AvP.LevelName, 40, "custom/%s", elementPtr->d.TextSliderStringPointer[index]);
 
 
738
                    break;
 
 
739
                }
 
 
740
            }
 
 
741
            else
 
 
742
            {
 
 
743
                strcpy(AvP.LevelName, "FIX THIS");
 
 
744
            }
 
 
745
 
 
 
746
            RenderSmallMenuText(AvP.LevelName, ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y, elementPtr->Brightness, MENUFORMAT_LEFTJUSTIFIED);
 
 
747
        }
 
 
748
        break;
 
 
749
        case MENU_ELEMENT_LOADSOUNDS:
 
 
750
        case MENU_ELEMENT_TOGGLE_MOUSE_GRAB:
 
 
751
        case MENU_ELEMENT_TOGGLE_FULLSCREEN:
 
 
752
            RenderSmallMenuText(*elementPtr->c.NumberPtr ? "On" : "Off", ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y,
elementPtr->Brightness, MENUFORMAT_LEFTJUSTIFIED);
 
 
753
            RenderSmallMenuText(elementPtr->menu_name, ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
754
        break;
 
 
755
        case MENU_ELEMENT_TEXTSLIDER:
 
 
756
        {
 
 
757
            const char *textPtr = elementPtr->d.TextSliderStringPointer[*elementPtr->c.SliderValuePtr];
 
 
758
 
 
 
759
            int length = LengthOfSmallMenuText(textPtr);
 
 
760
 
 
 
761
            if (length > (ScreenDescriptorBlock.SDB_Width - ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING*2))
 
 
762
            {
 
 
763
    RenderSmallMenuText(textPtr, ScreenDescriptorBlock.SDB_Width-MENU_ELEMENT_SPACING, y, elementPtr->Brightness, MENUFORMAT_RIGHTJUSTIFIED);
 
 
764
    RenderSmallMenuText(elementPtr->menu_name, ScreenDescriptorBlock.SDB_Width-MENU_ELEMENT_SPACING*2-length, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
765
            }
 
 
766
            else
 
 
767
            {
 
 
768
                RenderSmallMenuText(textPtr, ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y, elementPtr->Brightness, MENUFORMAT_LEFTJUSTIFIED);
 
 
769
                RenderSmallMenuText(elementPtr->menu_name, ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
770
            }
 
 
771
        }
 
 
772
        break;
 
 
773
        case MENU_ELEMENT_SPECIES_TEXTSLIDER:
 
 
774
        {
 
 
775
            RenderSmallMenuText(elementPtr->menu_name, ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
776
            const char * textPtr = elementPtr->d.TextSliderStringPointer[*elementPtr->c.SliderValuePtr];
 
 
777
            RenderSmallMenuText(textPtr, ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y, elementPtr->Brightness, MENUFORMAT_LEFTJUSTIFIED);
 
 
778
        }
 
 
779
        break;
 
 
780
        case MENU_ELEMENT_CHEATMODE_TEXTSLIDER:
 
 
781
            RenderSmallMenuText("Cheat Mode", ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
782
            RenderSmallMenuText(cheat_modes[*elementPtr->c.SliderValuePtr], ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y,
elementPtr->Brightness, MENUFORMAT_LEFTJUSTIFIED);
 
 
783
        break;
 
 
784
        case MENU_ELEMENT_CHEATMODE_SPECIES_TEXTSLIDER:
 
 
785
        {
 
 
786
            const char *textPtr = elementPtr->d.TextSliderStringPointer[*elementPtr->c.SliderValuePtr];
 
 
787
            RenderSmallMenuText (elementPtr->menu_name, ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
788
            RenderSmallMenuText (textPtr, ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y, elementPtr->Brightness, MENUFORMAT_LEFTJUSTIFIED);
 
 
789
        }
 
 
790
        break;
 
 
791
        case MENU_ELEMENT_CHEATMODE_ENVIRONMENT_TEXTSLIDER:
 
 
792
        {
 
 
793
            const char *textPtr;
 
 
794
 
 
 
795
            if (*elementPtr->c.SliderValuePtr < MAX_NO_OF_MARINE_EPISODES)
 
 
796
            {
 
 
797
                textPtr =  marine_episodes[*elementPtr->c.SliderValuePtr].pretty_name;
 
 
798
            }
 
 
799
            else if ( *elementPtr->c.SliderValuePtr < MAX_NO_OF_PREDATOR_EPISODES + MAX_NO_OF_MARINE_EPISODES)
 
 
800
            {
 
 
801
                textPtr =  predator_episodes[*elementPtr->c.SliderValuePtr - MAX_NO_OF_MARINE_EPISODES].pretty_name;
 
 
802
            }
 
 
803
            else
 
 
804
            {
 
 
805
                textPtr =  alien_episodes[*elementPtr->c.SliderValuePtr - MAX_NO_OF_MARINE_EPISODES - MAX_NO_OF_PREDATOR_EPISODES].pretty_name;
 
 
806
            }
 
 
807
 
 
 
808
            RenderSmallMenuText ("Environment", ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
809
            RenderSmallMenuText (textPtr, ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y, elementPtr->Brightness, MENUFORMAT_LEFTJUSTIFIED);
 
 
810
        }
 
 
811
        break;
 
 
812
        case MENU_ELEMENT_TEXTFIELD:
 
 
813
        {
 
 
814
            if (NULL == elementPtr->menu_name)
 
 
815
            {
 
 
816
                if (Menus.UserEnteringText && (e == Menus.CurrentlySelectedElement))
 
 
817
                {
 
 
818
                    int b = GetSin(CloakingPhase & 4095);
 
 
819
                    int x = RenderSmallMenuText(elementPtr->c.TextPtr, ScreenDescriptorBlock.SDB_CentreX, y, elementPtr->Brightness/2,
MENUFORMAT_CENTREJUSTIFIED);
 
 
820
                    x = RenderSmallMenuText("I", x, y, MUL_FIXED(b, b), MENUFORMAT_CENTREJUSTIFIED);
 
 
821
 
 
 
822
                    //work out how much space was left over
 
 
823
                    if(Menus.PositionInTextField)
 
 
824
                        Menus.WidthLeftForText = MENU_RIGHTXEDGE -x;
 
 
825
                    else
 
 
826
                        Menus.WidthLeftForText = MENU_RIGHTXEDGE - ScreenDescriptorBlock.SDB_CentreX;
 
 
827
                }
 
 
828
                else
 
 
829
                {
 
 
830
                    RenderSmallMenuText(elementPtr->c.TextPtr, ScreenDescriptorBlock.SDB_CentreX, y, elementPtr->Brightness, MENUFORMAT_CENTREJUSTIFIED);
 
 
831
                }
 
 
832
            }
 
 
833
            else
 
 
834
            {
 
 
835
                RenderSmallMenuText(elementPtr->menu_name , ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
836
 
 
 
837
                if (Menus.UserEnteringText && e == Menus.CurrentlySelectedElement)
 
 
838
                {
 
 
839
                    int b = GetSin(CloakingPhase & 4095);
 
 
840
                    int x =
RenderSmallMenuText(elementPtr->c.TextPtr,ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING,y,elementPtr->Brightness/2,MENUFORMAT_LEFTJUSTIFIED);
 
 
841
                    x = RenderSmallMenuText("I", x + LengthOfSmallMenuText(elementPtr->c.TextPtr), y, MUL_FIXED(b, b), MENUFORMAT_LEFTJUSTIFIED);
 
 
842
 
 
 
843
                    //work out how much space was left over
 
 
844
                    if(Menus.PositionInTextField)
 
 
845
                        Menus.WidthLeftForText = MENU_RIGHTXEDGE -x;
 
 
846
                    else
 
 
847
                        Menus.WidthLeftForText = MENU_RIGHTXEDGE -(ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING);
 
 
848
                }
 
 
849
                else
 
 
850
                {
 
 
851
                    RenderSmallMenuText(elementPtr->c.TextPtr, ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_LEFTJUSTIFIED);
 
 
852
                }
 
 
853
            }
 
 
854
        }
 
 
855
        break;
 
 
856
        case MENU_ELEMENT_TEXTFIELD_SMALLWRAPPED:
 
 
857
        {
 
 
858
            if (!elementPtr->menu_name)
 
 
859
            {
 
 
860
                int left = MENU_LEFTXEDGE;
 
 
861
                int right = MENU_RIGHTXEDGE;
 
 
862
                int bottom = y + 4 * HUD_FONT_HEIGHT;
 
 
863
 
 
 
864
                if (Menus.UserEnteringText && e == Menus.CurrentlySelectedElement)
 
 
865
                {
 
 
866
                    int output_x,output_y;
 
 
867
                    int b = GetSin(CloakingPhase & 4095);
 
 
868
                    output_x = RenderSmallMenuText("I", output_x, output_y, MUL_FIXED(b,b), MENUFORMAT_LEFTJUSTIFIED);
 
 
869
 
 
 
870
                    //work out how much space was left over
 
 
871
                    if(bottom - output_y < HUD_FONT_HEIGHT)
 
 
872
                    {
 
 
873
                        //no space left
 
 
874
                        Menus.WidthLeftForText= 0;
 
 
875
                    }
 
 
876
                    else if(bottom - output_y >= 2 * HUD_FONT_HEIGHT)
 
 
877
                    {
 
 
878
                        //at least a whole line left
 
 
879
                        Menus.WidthLeftForText = right - left;
 
 
880
                    }
 
 
881
                    else
 
 
882
                    {
 
 
883
                        //on the last line
 
 
884
                        Menus.WidthLeftForText = right - output_x;
 
 
885
                    }
 
 
886
                }
 
 
887
            }
 
 
888
            else
 
 
889
            {
 
 
890
                int left = ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING;
 
 
891
                int right = MENU_RIGHTXEDGE;
 
 
892
                int bottom = y + 4 * HUD_FONT_HEIGHT;
 
 
893
 
 
 
894
RenderSmallMenuText(elementPtr->menu_name,
ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING,y+HUD_FONT_HEIGHT,elementPtr->Brightness,MENUFORMAT_RIGHTJUSTIFIED);
 
 
895
 
 
 
896
                if (Menus.UserEnteringText && e == Menus.CurrentlySelectedElement)
 
 
897
                {
 
 
898
                    int output_x,output_y;
 
 
899
                    int b = GetSin(CloakingPhase&4095);
 
 
900
                    output_x = RenderSmallMenuText("I",output_x,output_y,MUL_FIXED(b,b),MENUFORMAT_LEFTJUSTIFIED);
 
 
901
 
 
 
902
                    //work out how much space was left over
 
 
903
                    if(bottom - output_y < HUD_FONT_HEIGHT)
 
 
904
                    {
 
 
905
                        //no space left
 
 
906
                        Menus.WidthLeftForText = 0;
 
 
907
                    }
 
 
908
                    else if(bottom - output_y >= 2*HUD_FONT_HEIGHT)
 
 
909
                    {
 
 
910
                        //at least a whole line left
 
 
911
                        Menus.WidthLeftForText = right - left;
 
 
912
                    }
 
 
913
                    else
 
 
914
                    {
 
 
915
                        //on the last line
 
 
916
                        Menus.WidthLeftForText = right - output_x;
 
 
917
                    }
 
 
918
                }
 
 
919
            }
 
 
920
        }
 
 
921
        break;
 
 
922
        case MENU_ELEMENT_NUMBERFIELD:
 
 
923
        {
 
 
924
            RenderSmallMenuText(elementPtr->menu_name, ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
925
 
 
 
926
            if(*elementPtr->c.NumberPtr != 0 || elementPtr->print_zero == 0)
 
 
927
            {
 
 
928
                char NumberString[50]={'\0'};
 
 
929
 
 
 
930
                sprintf(NumberString, "%d ", *elementPtr->c.NumberPtr);
 
 
931
 
 
 
932
                if (elementPtr->d.TextSliderStringPointer != 0)
 
 
933
                    strncat(NumberString, elementPtr->d.TextSliderStringPointer, 50 - strlen(NumberString));
 
 
934
 
 
 
935
                RenderSmallMenuText(NumberString, ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_LEFTJUSTIFIED);
 
 
936
            }
 
 
937
            else
 
 
938
            {
 
 
939
                RenderSmallMenuText(elementPtr->print_zero, ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_LEFTJUSTIFIED);
 
 
940
            }
 
 
941
        }
 
 
942
        break;
 
 
943
        case MENU_ELEMENT_LOADMPCONFIG:
 
 
944
        case MENU_ELEMENT_LOADIPADDRESS:
 
 
945
            RenderSmallMenuText(elementPtr->c.TextPtr, ScreenDescriptorBlock.SDB_CentreX, y, elementPtr->Brightness, MENUFORMAT_CENTREJUSTIFIED);
 
 
946
        break;
 
 
947
        case MENU_ELEMENT_SLIDER:
 
 
948
        {
 
 
949
            int x = ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING+3;
 
 
950
            x += (201*(*elementPtr->c.SliderValuePtr))/elementPtr->b.MaxSliderValue;
 
 
951
 
 
 
952
            RenderSmallMenuText(elementPtr->menu_name, ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
953
 
 
 
954
            DrawSliderBar(ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING,y+1,elementPtr->Brightness);
 
 
955
            DrawSlider(x,y+4,elementPtr->Brightness);
 
 
956
        }
 
 
957
        break;
 
 
958
        case MENU_ELEMENT_SELECT_WINDOWSIZE:
 
 
959
        {
 
 
960
            char buf[64];
 
 
961
            snprintf(buf, 64, "%dx%d", UserProfile.screen.width , UserProfile.screen.height);
 
 
962
 
 
 
963
            int length = LengthOfSmallMenuText(buf);
 
 
964
 
 
 
965
            if (length > (ScreenDescriptorBlock.SDB_Width - ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING*2))
 
 
966
            {
 
 
967
                RenderSmallMenuText(buf, ScreenDescriptorBlock.SDB_Width-MENU_ELEMENT_SPACING, y, elementPtr->Brightness, MENUFORMAT_RIGHTJUSTIFIED);
 
 
968
                RenderSmallMenuText(elementPtr->menu_name, ScreenDescriptorBlock.SDB_Width-MENU_ELEMENT_SPACING*2-length, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
969
            }
 
 
970
            else
 
 
971
            {
 
 
972
                RenderSmallMenuText(buf, ScreenDescriptorBlock.SDB_CentreX+MENU_ELEMENT_SPACING, y, elementPtr->Brightness, MENUFORMAT_LEFTJUSTIFIED);
 
 
973
                RenderSmallMenuText(elementPtr->menu_name, ScreenDescriptorBlock.SDB_CentreX-MENU_ELEMENT_SPACING, y, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
974
            }
 
 
975
        }
 
 
976
        break;
 
 
977
        case MENU_ELEMENT_KEYCONFIG:
 
 
978
        {
 
 
979
            SDLKey *primaryKey = ((SDLKey *)&PlayerInputPrimaryConfig) + e - 2;
 
 
980
            SDLKey *secondaryKey = ((SDLKey *)&PlayerInputSecondaryConfig) + e - 2;
 
 
981
            const char * char_ptr_primary;
 
 
982
            const char * char_ptr_secondary;
 
 
983
 
 
 
984
            {
 
 
985
 
 
 
986
            char *tmp;
 
 
987
            int i=0;
 
 
988
            int tmp_key = *primaryKey;
 
 
989
 
 
 
990
                for (; i < 2; tmp_key = *secondaryKey )
 
 
991
                {
 
 
992
                    switch(tmp_key)
 
 
993
                    {
 
 
994
                    case SDLK_CLEAR:
 
 
995
                        tmp = "";
 
 
996
                    break;
 
 
997
                    case SDL_BUTTON_LEFT:
 
 
998
                        tmp = "left Mouse";
 
 
999
                    break;
 
 
1000
                    case SDL_BUTTON_RIGHT:
 
 
1001
                        tmp = "right Mouse";
 
 
1002
                    break;
 
 
1003
                    case SDL_BUTTON_MIDDLE:
 
 
1004
                        tmp = "middle Mouse";
 
 
1005
                    break;
 
 
1006
                    case SDL_BUTTON_WHEELUP:
 
 
1007
                        tmp = "mouse wheel up";
 
 
1008
                    break;
 
 
1009
                    case SDL_BUTTON_WHEELDOWN:
 
 
1010
                        tmp = "mouse wheel down";
 
 
1011
                    break;
 
 
1012
                    default:
 
 
1013
                        tmp = SDL_GetKeyName(tmp_key);
 
 
1014
                    }
 
 
1015
 
 
 
1016
                    if (i++)    
 
 
1017
                        char_ptr_secondary = tmp;
 
 
1018
                    else
 
 
1019
                        char_ptr_primary = tmp;
 
 
1020
                }
 
 
1021
            }
 
 
1022
 
 
 
1023
            if (e == Menus.CurrentlySelectedElement)
 
 
1024
            {
 
 
1025
                int x,g;
 
 
1026
 
 
 
1027
                if (KeyConfigSelectionColumn)
 
 
1028
                    x = MENU_RIGHTXEDGE;
 
 
1029
                else
 
 
1030
                    x = ScreenDescriptorBlock.SDB_CentreX;
 
 
1031
 
 
 
1032
                if (Menus.UserChangingKeyConfig)
 
 
1033
                    g = 255;
 
 
1034
                else
 
 
1035
                    g = 128;
 
 
1036
 
 
 
1037
                    Rectangle(x-100, y-4, x+4, y+19, 0, g, 0, 255);
 
 
1038
            }
 
 
1039
 
 
 
1040
            if (Menus.UserChangingKeyConfig && e == Menus.CurrentlySelectedElement)
 
 
1041
            {
 
 
1042
                int b = GetSin(CloakingPhase & 4095);
 
 
1043
 
 
 
1044
                if (Menus.ChangingPrimaryConfig)
 
 
1045
                {
 
 
1046
                    RenderSmallMenuText("_", ScreenDescriptorBlock.SDB_CentreX, y , MUL_FIXED(b,b), MENUFORMAT_RIGHTJUSTIFIED);
 
 
1047
                    RenderSmallMenuText(char_ptr_secondary , MENU_RIGHTXEDGE, y, elementPtr->Brightness, MENUFORMAT_RIGHTJUSTIFIED );
 
 
1048
                }
 
 
1049
                else
 
 
1050
                {
 
 
1051
                    RenderSmallMenuText(char_ptr_primary, ScreenDescriptorBlock.SDB_CentreX, y, elementPtr->Brightness, MENUFORMAT_RIGHTJUSTIFIED );
 
 
1052
                    RenderSmallMenuText("_",MENU_RIGHTXEDGE,y,MUL_FIXED(b,b),MENUFORMAT_RIGHTJUSTIFIED);
 
 
1053
                }
 
 
1054
            }
 
 
1055
            else
 
 
1056
            {
 
 
1057
 
 
 
1058
                if (MultipleAssignments[0][e-2])
 
 
1059
    RenderSmallMenuText_Coloured(char_ptr_primary, ScreenDescriptorBlock.SDB_CentreX, y, ONE_FIXED, MENUFORMAT_RIGHTJUSTIFIED, ONE_FIXED, ONE_FIXED, 0 );
 
 
1060
                else
 
 
1061
    RenderSmallMenuText(char_ptr_primary, ScreenDescriptorBlock.SDB_CentreX, y, elementPtr->Brightness, MENUFORMAT_RIGHTJUSTIFIED );
 
 
1062
 
 
 
1063
                if (MultipleAssignments[1][e-2])
 
 
1064
    RenderSmallMenuText_Coloured(char_ptr_secondary, MENU_RIGHTXEDGE, y, ONE_FIXED, MENUFORMAT_RIGHTJUSTIFIED, ONE_FIXED, ONE_FIXED, 0 );
 
 
1065
                else
 
 
1066
    RenderSmallMenuText(char_ptr_secondary, MENU_RIGHTXEDGE, y, elementPtr->Brightness, MENUFORMAT_RIGHTJUSTIFIED );
 
 
1067
 
 
 
1068
            }
 
 
1069
 
 
 
1070
            RenderSmallMenuText(elementPtr->c.TextPtr, MENU_LEFTXEDGE, y, elementPtr->Brightness, MENUFORMAT_LEFTJUSTIFIED );
 
 
1071
        }
 
 
1072
        default:
 
 
1073
        break;
 
 
1074
    }
 
 
1075
}
 
 
1076
 
 
 
1077
static void RenderMenu()
 
 
1078
{
 
 
1079
    MENU_ELEMENT *elementPtr = Menus.MenuElements;
 
 
1080
    int e;
 
 
1081
    int y;
 
 
1082
 
 
 
1083
    if (Menus.MenusState == MENUSSTATE_MAINMENUS)
 
 
1084
    {
 
 
1085
        RenderSmallMenuText("Aliens Versus Predator", ScreenDescriptorBlock.SDB_CentreX, 70, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
1086
 
 
 
1087
        if ((Menus.CurrentMenu == MENU_LEVELBRIEFING_BASIC) || (Menus.CurrentMenu == MENU_LEVELBRIEFING_BONUS))
 
 
1088
        {
 
 
1089
            y = ScreenDescriptorBlock.SDB_CentreY + HUD_FONT_HEIGHT*5;
 
 
1090
            RenderBriefingScreenInfo();
 
 
1091
        }
 
 
1092
        else
 
 
1093
        {
 
 
1094
            y = MENU_CENTREY - (Menus.MenuHeight)/2;
 
 
1095
        }
 
 
1096
    }
 
 
1097
    else
 
 
1098
    {
 
 
1099
        y = (ScreenDescriptorBlock.SDB_Height - Menus.MenuHeight)/2;
 
 
1100
    }
 
 
1101
 
 
 
1102
    for (e = 0; e < Menus.NumberOfElementsInMenu; e++, elementPtr++)
 
 
1103
    {
 
 
1104
        int targetBrightness =
 
 
1105
            (e == Menus.CurrentlySelectedElement)
 
 
1106
                ? BRIGHTNESS_OF_HIGHLIGHTED_ELEMENT : BRIGHTNESS_OF_DARKENED_ELEMENT;
 
 
1107
 
 
 
1108
        if (targetBrightness > elementPtr->Brightness)
 
 
1109
        {
 
 
1110
            elementPtr->Brightness += BRIGHTNESS_CHANGE_SPEED;
 
 
1111
 
 
 
1112
            if(elementPtr->Brightness > targetBrightness)
 
 
1113
                elementPtr->Brightness = targetBrightness;
 
 
1114
        }
 
 
1115
        else
 
 
1116
        {
 
 
1117
            elementPtr->Brightness -= BRIGHTNESS_CHANGE_SPEED;
 
 
1118
 
 
 
1119
            if(elementPtr->Brightness < targetBrightness)
 
 
1120
                elementPtr->Brightness = targetBrightness;
 
 
1121
        }
 
 
1122
 
 
 
1123
        RenderMenuElement(elementPtr, e, y);
 
 
1124
        y += HeightOfMenuElement(elementPtr);
 
 
1125
    }
 
 
1126
}
 
 
1127
 
 
 
1128
static void RenderEpisodeSelectMenu(int numberOfBasicLevels, const struct Map *map)
 
 
1129
{
 
 
1130
    MENU_ELEMENT *elementPtr = &Menus.MenuElements[Menus.CurrentlySelectedElement];
 
 
1131
    int currentEpisode = *(elementPtr->c.SliderValuePtr);
 
 
1132
    int centrePosition = currentEpisode * 65536 + EpisodeSelectScrollOffset;
 
 
1133
    char *TextPtr;
 
 
1134
    int i;
 
 
1135
 
 
 
1136
    RenderSmallMenuText("Select Episode", ScreenDescriptorBlock.SDB_CentreX, 70, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
1137
 
 
 
1138
    for (i=0; i <= elementPtr->b.MaxSliderValue; i++)
 
 
1139
    {
 
 
1140
        int y = MUL_FIXED(i*65536-centrePosition, 100);
 
 
1141
 
 
 
1142
        if (y >= -150 && y <= 150)
 
 
1143
        {
 
 
1144
            int targetBrightness = (i == currentEpisode) ? BRIGHTNESS_OF_HIGHLIGHTED_ELEMENT : BRIGHTNESS_OF_DARKENED_ELEMENT;
 
 
1145
 
 
 
1146
            if (targetBrightness > Brightness[i])
 
 
1147
            {
 
 
1148
                Brightness[i] += BRIGHTNESS_CHANGE_SPEED;
 
 
1149
 
 
 
1150
                if(Brightness[i] > targetBrightness)
 
 
1151
                    Brightness[i] = targetBrightness;
 
 
1152
            }
 
 
1153
            else
 
 
1154
            {
 
 
1155
                Brightness[i] -= BRIGHTNESS_CHANGE_SPEED;
 
 
1156
 
 
 
1157
                if(Brightness[i] < targetBrightness)
 
 
1158
                    Brightness[i] = targetBrightness;
 
 
1159
            }
 
 
1160
 
 
 
1161
            int b = Brightness[i];
 
 
1162
            int yCoord = MENU_CENTREY+y-60;
 
 
1163
 
 
 
1164
            RenderSmallMenuText(map[i].pretty_name, MENU_LEFTXEDGE+150, yCoord, b, MENUFORMAT_LEFTJUSTIFIED);
 
 
1165
 
 
 
1166
            if (MaximumSelectableLevel >= i)
 
 
1167
            {
 
 
1168
                if (i < numberOfBasicLevels)
 
 
1169
                {
 
 
1170
                    switch(UserProfile.LevelCompleted[AvP.PlayerType].Difficulty[i])
 
 
1171
                    {
 
 
1172
                        case I_Easy:
 
 
1173
                            TextPtr = "Completed on Easy";
 
 
1174
                        break;    
 
 
1175
                        case I_Medium:
 
 
1176
                            TextPtr = "Completed on Medium";
 
 
1177
                        break;
 
 
1178
                        case I_Hard:
 
 
1179
                            TextPtr = "Completed on Hard";
 
 
1180
                        break;
 
 
1181
                        case Not_Completed:
 
 
1182
                        default: 
 
 
1183
                            TextPtr = "Not yet completed";
 
 
1184
                    }
 
 
1185
                }
 
 
1186
                else
 
 
1187
                {
 
 
1188
                    TextPtr = (Not_Completed == UserProfile.LevelCompleted[AvP.PlayerType].Difficulty[i]) ? "Not yet completed" :
"Completed";
 
 
1189
                }
 
 
1190
            }
 
 
1191
            else
 
 
1192
            {
 
 
1193
                TextPtr = (i == elementPtr->b.MaxSliderValue) ? "Not yet available - to acess complete game on Hard" : "Not yet available - to
acess complete game on Medium";
 
 
1194
            }
 
 
1195
 
 
 
1196
            RenderSmallMenuText(TextPtr, MENU_LEFTXEDGE+150, yCoord+30, b, MENUFORMAT_LEFTJUSTIFIED );
 
 
1197
        }
 
 
1198
    }
 
 
1199
 
 
 
1200
    if (EpisodeSelectScrollOffset > 0)
 
 
1201
    {
 
 
1202
        EpisodeSelectScrollOffset -= MUL_FIXED(EpisodeSelectScrollOffset*2+8192, RealFrameTime<<1);
 
 
1203
 
 
 
1204
        if (EpisodeSelectScrollOffset < 0)
 
 
1205
            EpisodeSelectScrollOffset = 0;
 
 
1206
    }
 
 
1207
    else if (EpisodeSelectScrollOffset < 0)
 
 
1208
    {
 
 
1209
        EpisodeSelectScrollOffset += MUL_FIXED(-EpisodeSelectScrollOffset*2+8192, RealFrameTime<<1);
 
 
1210
 
 
 
1211
        if (EpisodeSelectScrollOffset > 0)
 
 
1212
            EpisodeSelectScrollOffset = 0;
 
 
1213
    }
 
 
1214
}
 
 
1215
 
 
 
1216
static void RenderKeyConfigurationMenu()
 
 
1217
{
 
 
1218
    MENU_ELEMENT *elementPtr = Menus.MenuElements;
 
 
1219
    int centrePosition;
 
 
1220
    int i, y;
 
 
1221
    int centreY = ScreenDescriptorBlock.SDB_CentreY +25;
 
 
1222
 
 
 
1223
    {
 
 
1224
        int b = ONE_FIXED;
 
 
1225
        if (!(Menus.CurrentlySelectedElement >= 2))
 
 
1226
            b /= 4;
 
 
1227
 
 
 
1228
        //RenderSmallMenuText(MenusData[Menus.CurrentMenu].MenuTitle, ScreenDescriptorBlock.SDB_CentreX, 70, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
1229
        DrawRectangle(10, (ScreenDescriptorBlock.SDB_CentreY + 25 - 115), (ScreenDescriptorBlock.SDB_Width-20), 250, b);
 
 
1230
    }
 
 
1231
 
 
 
1232
    y = centreY-160;
 
 
1233
 
 
 
1234
    for (i = 0; i < 2; i++, elementPtr++)
 
 
1235
    {
 
 
1236
        int targetBrightness = (i == Menus.CurrentlySelectedElement) ? BRIGHTNESS_OF_HIGHLIGHTED_ELEMENT : BRIGHTNESS_OF_DARKENED_ELEMENT;
 
 
1237
 
 
 
1238
        if (targetBrightness > elementPtr->Brightness)
 
 
1239
        {
 
 
1240
            elementPtr->Brightness += BRIGHTNESS_CHANGE_SPEED;
 
 
1241
 
 
 
1242
            if(elementPtr->Brightness > targetBrightness)
 
 
1243
                elementPtr->Brightness = targetBrightness;
 
 
1244
        }
 
 
1245
        else
 
 
1246
        {
 
 
1247
            elementPtr->Brightness -= BRIGHTNESS_CHANGE_SPEED;
 
 
1248
 
 
 
1249
            if(elementPtr->Brightness < targetBrightness)
 
 
1250
                elementPtr->Brightness = targetBrightness;
 
 
1251
        }
 
 
1252
 
 
 
1253
        RenderMenuElement(elementPtr, i, y);
 
 
1254
        y += HeightOfMenuElement(elementPtr);
 
 
1255
    }
 
 
1256
 
 
 
1257
    centrePosition = Menus.CurrentlySelectedElement * ONE_FIXED;
 
 
1258
 
 
 
1259
    if (centrePosition < 2 * ONE_FIXED)
 
 
1260
        centrePosition = 2* ONE_FIXED;
 
 
1261
 
 
 
1262
    for (i=2; i < Menus.NumberOfElementsInMenu; i++, elementPtr++)
 
 
1263
    {
 
 
1264
        y = MUL_FIXED(i*65536-centrePosition,20);
 
 
1265
 
 
 
1266
        if (y >= -100 && y <= 100)
 
 
1267
        {
 
 
1268
            int targetBrightness;
 
 
1269
 
 
 
1270
            if (i == Menus.CurrentlySelectedElement)
 
 
1271
                targetBrightness = BRIGHTNESS_OF_HIGHLIGHTED_ELEMENT;
 
 
1272
            else
 
 
1273
                targetBrightness = BRIGHTNESS_OF_DARKENED_ELEMENT;
 
 
1274
 
 
 
1275
            elementPtr->Brightness = targetBrightness;
 
 
1276
            RenderMenuElement(elementPtr, i, centreY+y);
 
 
1277
        }
 
 
1278
    }
 
 
1279
 
 
 
1280
    if (EpisodeSelectScrollOffset > 0)
 
 
1281
    {
 
 
1282
        EpisodeSelectScrollOffset -= MUL_FIXED(EpisodeSelectScrollOffset*2+8192, RealFrameTime<<1);
 
 
1283
 
 
 
1284
        if (EpisodeSelectScrollOffset < 0)
 
 
1285
            EpisodeSelectScrollOffset=0;
 
 
1286
    }
 
 
1287
    else if (EpisodeSelectScrollOffset < 0)
 
 
1288
    {
 
 
1289
        EpisodeSelectScrollOffset += MUL_FIXED(-EpisodeSelectScrollOffset*2+8192, RealFrameTime<<1);
 
 
1290
 
 
 
1291
        if (EpisodeSelectScrollOffset > 0)
 
 
1292
            EpisodeSelectScrollOffset=0;
 
 
1293
    }
 
 
1294
}
 
 
1295
 
 
 
1296
static void RenderLoadSaveGameMenu(int save_menu)
 
 
1297
{
 
 
1298
    MENU_ELEMENT *elementPtr = Menus.MenuElements;
 
 
1299
    int e;
 
 
1300
    int y;
 
 
1301
 
 
 
1302
    if (Menus.MenusState == MENUSSTATE_MAINMENUS)
 
 
1303
        y = MENU_CENTREY - (Menus.MenuHeight)/2;
 
 
1304
    else
 
 
1305
        y = (ScreenDescriptorBlock.SDB_Height - Menus.MenuHeight)/2;
 
 
1306
 
 
 
1307
    for (e = 0; e < Menus.NumberOfElementsInMenu; e++, elementPtr++)
 
 
1308
    {
 
 
1309
        char buffer[100];
 
 
1310
        SAVE_SLOT_HEADER *slotPtr = &SaveGameSlot[e];
 
 
1311
        int targetBrightness;
 
 
1312
 
 
 
1313
        if (e == Menus.CurrentlySelectedElement)
 
 
1314
        {
 
 
1315
            Rectangle(MENU_LEFTXEDGE, y-2, MENU_RIGHTXEDGE, y+4+HUD_FONT_HEIGHT*2, 0, 128, 0, 255);
 
 
1316
 
 
 
1317
            targetBrightness = BRIGHTNESS_OF_HIGHLIGHTED_ELEMENT;
 
 
1318
        }
 
 
1319
        else
 
 
1320
        { 
 
 
1321
            targetBrightness = BRIGHTNESS_OF_DARKENED_ELEMENT;
 
 
1322
        }
 
 
1323
 
 
 
1324
        if (targetBrightness > elementPtr->Brightness)
 
 
1325
        {
 
 
1326
            elementPtr->Brightness+=BRIGHTNESS_CHANGE_SPEED;
 
 
1327
 
 
 
1328
            if(elementPtr->Brightness > targetBrightness)
 
 
1329
                elementPtr->Brightness = targetBrightness;
 
 
1330
        }
 
 
1331
        else
 
 
1332
        {
 
 
1333
            elementPtr->Brightness-=BRIGHTNESS_CHANGE_SPEED;
 
 
1334
 
 
 
1335
            if(elementPtr->Brightness < targetBrightness)
 
 
1336
                elementPtr->Brightness = targetBrightness;
 
 
1337
        }
 
 
1338
 
 
 
1339
        sprintf(buffer, "%d.", e+1);
 
 
1340
        RenderSmallMenuText(buffer, MENU_LEFTXEDGE+20, y, elementPtr->Brightness, MENUFORMAT_RIGHTJUSTIFIED);
 
 
1341
 
 
 
1342
        if (slotPtr->SlotUsed)
 
 
1343
        {
 
 
1344
            int numberOfBasicEpisodes;
 
 
1345
 
 
 
1346
            const char * episode_ptr;
 
 
1347
            const char * species;
 
 
1348
 
 
 
1349
            switch(slotPtr->player_type)
 
 
1350
            {
 
 
1351
                case I_Marine:
 
 
1352
                {
 
 
1353
                    episode_ptr =  marine_episodes[slotPtr->Episode].pretty_name;
 
 
1354
                    species = "Marine";
 
 
1355
                    numberOfBasicEpisodes = MAX_NO_OF_BASIC_MARINE_EPISODES;
 
 
1356
                }
 
 
1357
                break;
 
 
1358
                case I_Predator:
 
 
1359
                {
 
 
1360
                    episode_ptr =  predator_episodes[slotPtr->Episode].pretty_name;
 
 
1361
                    species = "Predator";
 
 
1362
                    numberOfBasicEpisodes = MAX_NO_OF_BASIC_PREDATOR_EPISODES;
 
 
1363
                }
 
 
1364
                break;
 
 
1365
                case I_Alien:
 
 
1366
                {
 
 
1367
                    episode_ptr =  alien_episodes[slotPtr->Episode].pretty_name;
 
 
1368
                    species = "Alien";
 
 
1369
                    numberOfBasicEpisodes = MAX_NO_OF_BASIC_ALIEN_EPISODES;
 
 
1370
                }
 
 
1371
            }
 
 
1372
 
 
 
1373
            RenderSmallMenuText(species, MENU_LEFTXEDGE+30, y, elementPtr->Brightness, MENUFORMAT_LEFTJUSTIFIED);
 
 
1374
            RenderSmallMenuText(episode_ptr, ScreenDescriptorBlock.SDB_CentreX, y, elementPtr->Brightness, MENUFORMAT_CENTREJUSTIFIED);
 
 
1375
 
 
 
1376
            if (numberOfBasicEpisodes > slotPtr->Episode)
 
 
1377
            {
 
 
1378
                const char *ptr;
 
 
1379
 
 
 
1380
                switch (slotPtr->Difficulty)
 
 
1381
                {
 
 
1382
                    case 0:
 
 
1383
                        ptr = "Training";
 
 
1384
                    break;
 
 
1385
                    case 1:
 
 
1386
                        ptr = "Realistic";
 
 
1387
                    break;
 
 
1388
                    case 2:
 
 
1389
                        ptr = "Director's Cut";
 
 
1390
                    break;
 
 
1391
                    default: // should not happen
 
 
1392
                    ptr = "fix this2";
 
 
1393
                }
 
 
1394
 
 
 
1395
                RenderSmallMenuText(ptr, MENU_RIGHTXEDGE-30, y, elementPtr->Brightness, MENUFORMAT_RIGHTJUSTIFIED);
 
 
1396
            }
 
 
1397
 
 
 
1398
            sprintf(buffer, "%s %02d:%02d:%02d", "Time Elapsed: ", slotPtr->ElapsedTime_Hours, slotPtr->ElapsedTime_Minutes,
slotPtr->ElapsedTime_Seconds);
 
 
1399
            RenderSmallMenuText(buffer, MENU_LEFTXEDGE+30, y+HUD_FONT_HEIGHT+1, elementPtr->Brightness, MENUFORMAT_LEFTJUSTIFIED);
 
 
1400
 
 
 
1401
            sprintf(buffer, "%s: %d", "Saves left: ", slotPtr->SavesLeft);
 
 
1402
            RenderSmallMenuText(buffer, ScreenDescriptorBlock.SDB_CentreX, y+HUD_FONT_HEIGHT+1, elementPtr->Brightness, MENUFORMAT_CENTREJUSTIFIED);
 
 
1403
            RenderSmallMenuText(ctime(&slotPtr->TimeStamp), MENU_RIGHTXEDGE-30, y+HUD_FONT_HEIGHT+1, elementPtr->Brightness,
MENUFORMAT_RIGHTJUSTIFIED);
 
 
1404
        }
 
 
1405
        else
 
 
1406
        {
 
 
1407
            RenderSmallMenuText("Emtpy Save Slot", ScreenDescriptorBlock.SDB_CentreX, y, elementPtr->Brightness, MENUFORMAT_CENTREJUSTIFIED);
 
 
1408
        }
 
 
1409
 
 
 
1410
        y += HeightOfMenuElement(elementPtr);
 
 
1411
    }
 
 
1412
 
 
 
1413
    if (Menus.MenusState == MENUSSTATE_MAINMENUS)
 
 
1414
    {
 
 
1415
        RenderSmallMenuText("Load Game", ScreenDescriptorBlock.SDB_CentreX, 70, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
1416
    }
 
 
1417
    else
 
 
1418
    {
 
 
1419
        y = (ScreenDescriptorBlock.SDB_Height - Menus.MenuHeight)/2 - 30;
 
 
1420
 
 
 
1421
        if(save_menu)
 
 
1422
        {
 
 
1423
            static char text [22]= "Number of saves left  ";
 
 
1424
 
 
 
1425
            switch(PlayerStatus.saves_left)
 
 
1426
            {
 
 
1427
            case 0:
 
 
1428
                text[21] = '0';
 
 
1429
            break;
 
 
1430
            case 1:
 
 
1431
                text[21] = '1';
 
 
1432
            break;
 
 
1433
            case 2:
 
 
1434
                text[21] = '2';
 
 
1435
            break;
 
 
1436
            case 3:
 
 
1437
                text[21] = '3';
 
 
1438
            break;
 
 
1439
            case 4:
 
 
1440
                text[21] = '4';
 
 
1441
            break;
 
 
1442
            default:
 
 
1443
                text[21] = '?';
 
 
1444
            }
 
 
1445
 
 
 
1446
            RenderSmallMenuText(text, ScreenDescriptorBlock.SDB_CentreX, y, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
1447
        }
 
 
1448
        else
 
 
1449
        {
 
 
1450
            RenderSmallMenuText("Load Game", ScreenDescriptorBlock.SDB_CentreX, y, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
1451
        }
 
 
1452
    }
 
 
1453
}
 
 
1454
 
 
 
1455
static int get_new_env(int slot, int force_load)
 
 
1456
{
 
 
1457
    AvP.Difficulty = SaveGameSlot[slot].Difficulty;
 
 
1458
    SetBriefingTextForEpisode(SaveGameSlot[slot].Episode);
 
 
1459
 
 
 
1460
        //see if we will need to change level
 
 
1461
    if(force_load || (SaveGameSlot[slot].player_type != AvP.PlayerType) || (SaveGameSlot[slot].Episode != episode_to_play))
 
 
1462
    {
 
 
1463
        AvP.PlayerType = SaveGameSlot[slot].player_type;
 
 
1464
        episode_to_play = SaveGameSlot[slot].Episode;
 
 
1465
        SetLevelToLoadForSinglePlayer(episode_to_play);
 
 
1466
        return 1;
 
 
1467
    }
 
 
1468
 
 
 
1469
return 0;
 
 
1470
}
 
 
1471
 
 
 
1472
static void InteractWithMenuElement(enum MENU_ELEMENT_INTERACTION_ID interactionID)
 
 
1473
{
 
 
1474
    MENU_ELEMENT *elementPtr = &Menus.MenuElements[Menus.CurrentlySelectedElement];
 
 
1475
 
 
 
1476
    if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1477
        Sound_Play(SID_MENUS_SELECT_ITEM, "r");
 
 
1478
    else
 
 
1479
        Sound_Play(SID_MENUS_CHANGE_ITEM, "r");
 
 
1480
 
 
 
1481
    switch(elementPtr->ElementID)
 
 
1482
    {
 
 
1483
        case MENU_ELEMENT_SELECT_SPECIES:
 
 
1484
        {
 
 
1485
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1486
            {
 
 
1487
                AvP.PlayerType = Menus.CurrentlySelectedElement;
 
 
1488
                SetupNewMenu(elementPtr->b.MenuToGoTo);
 
 
1489
            }
 
 
1490
        }
 
 
1491
        break;
 
 
1492
        case MENU_ELEMENT_GOTOMENU:
 
 
1493
        {
 
 
1494
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1495
                SetupNewMenu(elementPtr->b.MenuToGoTo);
 
 
1496
        }
 
 
1497
        break;
 
 
1498
        case MENU_ELEMENT_SAVEMPCONFIG:
 
 
1499
        {
 
 
1500
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1501
            {
 
 
1502
                if(MP_Config_Name[0])
 
 
1503
                    SaveMultiplayerConfiguration(MP_Config_Name);
 
 
1504
 
 
 
1505
                SetupNewMenu(elementPtr->b.MenuToGoTo);
 
 
1506
            }
 
 
1507
        }
 
 
1508
        break;
 
 
1509
        case MENU_ELEMENT_TEXTFIELD:
 
 
1510
        {
 
 
1511
            Menus.UserEnteringText = 1;
 
 
1512
            Menus.PositionInTextField = strlen(elementPtr->c.TextPtr);
 
 
1513
            Menus.WidthLeftForText = 0; //will be calculated properly when menus are drawn
 
 
1514
            elementPtr->c.TextPtr[Menus.PositionInTextField] = 0;
 
 
1515
        }
 
 
1516
        break;
 
 
1517
        case MENU_ELEMENT_TEXTFIELD_SMALLWRAPPED:
 
 
1518
        {
 
 
1519
            Menus.UserEnteringText = 1;
 
 
1520
            Menus.PositionInTextField = strlen(elementPtr->c.TextPtr);
 
 
1521
            Menus.WidthLeftForText = 0; //will be calculated properly when menus are drawn
 
 
1522
        }
 
 
1523
        break;
 
 
1524
        case MENU_ELEMENT_NUMBERFIELD:
 
 
1525
        {
 
 
1526
            if(interactionID == MENU_ELEMENT_INTERACTION_DECREASE)
 
 
1527
            {
 
 
1528
                (*elementPtr->c.NumberPtr)--;
 
 
1529
 
 
 
1530
                if(*elementPtr->c.NumberPtr < 0)
 
 
1531
                    *elementPtr->c.NumberPtr = 0;
 
 
1532
            }
 
 
1533
            else if(interactionID == MENU_ELEMENT_INTERACTION_INCREASE)
 
 
1534
            {
 
 
1535
                (*elementPtr->c.NumberPtr)++;
 
 
1536
 
 
 
1537
                if(*elementPtr->c.NumberPtr > elementPtr->b.MaxValue)
 
 
1538
                    *elementPtr->c.NumberPtr = elementPtr->b.MaxValue;
 
 
1539
            }
 
 
1540
            else
 
 
1541
            {
 
 
1542
                *elementPtr->c.NumberPtr = 0;
 
 
1543
            }
 
 
1544
        }
 
 
1545
        break;
 
 
1546
        case MENU_ELEMENT_DUMMYTEXTSLIDER:
 
 
1547
        case MENU_ELEMENT_DUMMYTEXTSLIDER_POINTER:
 
 
1548
        break;
 
 
1549
        case MENU_ELEMENT_SLIDER:
 
 
1550
        {
 
 
1551
            if ((interactionID == MENU_ELEMENT_INTERACTION_SELECT) || (interactionID == MENU_ELEMENT_INTERACTION_INCREASE))
 
 
1552
            {
 
 
1553
                if (*elementPtr->c.SliderValuePtr < elementPtr->b.MaxSliderValue)
 
 
1554
                    *elementPtr->c.SliderValuePtr += 1;
 
 
1555
            }
 
 
1556
            else
 
 
1557
            {
 
 
1558
                if (*elementPtr->c.SliderValuePtr > 0)
 
 
1559
                    *elementPtr->c.SliderValuePtr -= 1;
 
 
1560
            }
 
 
1561
        }
 
 
1562
        break;
 
 
1563
        case MENU_ELEMENT_TOGGLE_MOUSE_GRAB:
 
 
1564
        {
 
 
1565
            extern void toggle_mouse_grab();
 
 
1566
            UserProfile.grabmouse ^= 1;
 
 
1567
            toggle_mouse_grab();
 
 
1568
        }
 
 
1569
        break;
 
 
1570
        case MENU_ELEMENT_TOGGLE_FULLSCREEN:
 
 
1571
        {
 
 
1572
            extern int SetVideoMode();
 
 
1573
            UserProfile.fullscreen ^= 1;
 
 
1574
            SetVideoMode();
 
 
1575
        }
 
 
1576
        break;
 
 
1577
        case MENU_ELEMENT_LOADSOUNDS:
 
 
1578
        case MENU_ELEMENT_LEVELNAME:
 
 
1579
        case MENU_ELEMENT_TEXTSLIDER:
 
 
1580
        {
 
 
1581
            if ((interactionID == MENU_ELEMENT_INTERACTION_SELECT) || (interactionID == MENU_ELEMENT_INTERACTION_INCREASE))
 
 
1582
            {
 
 
1583
                *elementPtr->c.SliderValuePtr += 1;
 
 
1584
 
 
 
1585
                if (*elementPtr->c.SliderValuePtr > elementPtr->b.MaxSliderValue)
 
 
1586
                    *elementPtr->c.SliderValuePtr = 0;
 
 
1587
            }
 
 
1588
            else
 
 
1589
            {
 
 
1590
                *elementPtr->c.SliderValuePtr -= 1;
 
 
1591
 
 
 
1592
                if (*elementPtr->c.SliderValuePtr < 0)
 
 
1593
                    *elementPtr->c.SliderValuePtr = elementPtr->b.MaxSliderValue;
 
 
1594
            }
 
 
1595
        }
 
 
1596
        break;
 
 
1597
        case MENU_ELEMENT_SPECIES_TEXTSLIDER:
 
 
1598
        {
 
 
1599
            if ((interactionID == MENU_ELEMENT_INTERACTION_SELECT) || (interactionID == MENU_ELEMENT_INTERACTION_INCREASE))
 
 
1600
            {
 
 
1601
                *elementPtr->c.SliderValuePtr += 1;
 
 
1602
 
 
 
1603
                if (*elementPtr->c.SliderValuePtr > elementPtr->b.MaxSliderValue)
 
 
1604
                    *elementPtr->c.SliderValuePtr = 0;
 
 
1605
 
 
 
1606
                GetNextAllowedSpecies(elementPtr->c.SliderValuePtr, 1);
 
 
1607
            }
 
 
1608
            else
 
 
1609
            {
 
 
1610
                *elementPtr->c.SliderValuePtr -= 1;
 
 
1611
 
 
 
1612
                if (*elementPtr->c.SliderValuePtr < 0)
 
 
1613
                    *elementPtr->c.SliderValuePtr = elementPtr->b.MaxSliderValue;
 
 
1614
 
 
 
1615
                GetNextAllowedSpecies(elementPtr->c.SliderValuePtr, 0);
 
 
1616
            }
 
 
1617
        }
 
 
1618
        break;
 
 
1619
        case MENU_ELEMENT_CHEATMODE_SPECIES_TEXTSLIDER:
 
 
1620
        {
 
 
1621
            if ((interactionID == MENU_ELEMENT_INTERACTION_SELECT) || (interactionID == MENU_ELEMENT_INTERACTION_INCREASE))
 
 
1622
            {
 
 
1623
                *elementPtr->c.SliderValuePtr += 1;
 
 
1624
 
 
 
1625
                if (*elementPtr->c.SliderValuePtr > elementPtr->b.MaxSliderValue)
 
 
1626
                    *elementPtr->c.SliderValuePtr = 0;
 
 
1627
 
 
 
1628
                CheatMode_GetNextAllowedSpecies(elementPtr->c.SliderValuePtr, 1);
 
 
1629
            }
 
 
1630
            else
 
 
1631
            {
 
 
1632
                *elementPtr->c.SliderValuePtr -= 1;
 
 
1633
 
 
 
1634
                if (*elementPtr->c.SliderValuePtr < 0)
 
 
1635
                    *elementPtr->c.SliderValuePtr = elementPtr->b.MaxSliderValue;
 
 
1636
 
 
 
1637
                CheatMode_GetNextAllowedSpecies(elementPtr->c.SliderValuePtr, 0);
 
 
1638
            }
 
 
1639
        }
 
 
1640
        break;
 
 
1641
        case MENU_ELEMENT_CHEATMODE_TEXTSLIDER:
 
 
1642
        {
 
 
1643
            if ((interactionID == MENU_ELEMENT_INTERACTION_SELECT) || (interactionID == MENU_ELEMENT_INTERACTION_INCREASE))
 
 
1644
            {
 
 
1645
                *elementPtr->c.SliderValuePtr += 1;
 
 
1646
 
 
 
1647
                if (*elementPtr->c.SliderValuePtr > elementPtr->b.MaxSliderValue)
 
 
1648
                    *elementPtr->c.SliderValuePtr = 0;
 
 
1649
 
 
 
1650
                CheatMode_GetNextAllowedMode(elementPtr->c.SliderValuePtr, 1);
 
 
1651
            }
 
 
1652
            else
 
 
1653
            {
 
 
1654
                *elementPtr->c.SliderValuePtr -= 1;
 
 
1655
 
 
 
1656
                if (*elementPtr->c.SliderValuePtr < 0)
 
 
1657
                    *elementPtr->c.SliderValuePtr = elementPtr->b.MaxSliderValue;
 
 
1658
 
 
 
1659
                CheatMode_GetNextAllowedMode(elementPtr->c.SliderValuePtr, 0);
 
 
1660
            }
 
 
1661
        }
 
 
1662
        break;
 
 
1663
        case MENU_ELEMENT_CHEATMODE_ENVIRONMENT_TEXTSLIDER:
 
 
1664
        {
 
 
1665
            if ((interactionID == MENU_ELEMENT_INTERACTION_SELECT) || (interactionID == MENU_ELEMENT_INTERACTION_INCREASE))
 
 
1666
            {
 
 
1667
                *elementPtr->c.SliderValuePtr += 1;
 
 
1668
 
 
 
1669
                if (*elementPtr->c.SliderValuePtr > elementPtr->b.MaxSliderValue)
 
 
1670
                    *elementPtr->c.SliderValuePtr = 0;
 
 
1671
 
 
 
1672
                CheatMode_GetNextAllowedEnvironment(elementPtr->c.SliderValuePtr, 1);
 
 
1673
            }
 
 
1674
            else
 
 
1675
            {
 
 
1676
                *elementPtr->c.SliderValuePtr -= 1;
 
 
1677
 
 
 
1678
                if (*elementPtr->c.SliderValuePtr < 0)
 
 
1679
                    *elementPtr->c.SliderValuePtr = elementPtr->b.MaxSliderValue;
 
 
1680
 
 
 
1681
                CheatMode_GetNextAllowedEnvironment(elementPtr->c.SliderValuePtr, 0);
 
 
1682
            }
 
 
1683
        }
 
 
1684
        break;
 
 
1685
        case MENU_ELEMENT_QUITGAME:
 
 
1686
        {
 
 
1687
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1688
            {
 
 
1689
                AvP.MainLoopRunning = 0;
 
 
1690
                Menus.MenusState = MENUSSTATE_OUTSIDEMENUS;
 
 
1691
            }
 
 
1692
        }
 
 
1693
        break;
 
 
1694
        case MENU_ELEMENT_DELETEMPCONFIG:
 
 
1695
        {
 
 
1696
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1697
            {
 
 
1698
                //DeleteMultiplayerConfigurationByIndex(MultiplayerConfigurationIndex);
 
 
1699
                //go back to the load config menu
 
 
1700
                //SetupNewMenu(MENU_MULTIPLAYER_LOADCONFIG);
 
 
1701
            }
 
 
1702
        }
 
 
1703
        break;  
 
 
1704
        case MENU_ELEMENT_DIFFICULTYLEVEL:
 
 
1705
        {
 
 
1706
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1707
            {
 
 
1708
                AvP.Difficulty = (Menus.CurrentMenu == MENU_LEVELBRIEFING_BASIC) ? Menus.CurrentlySelectedElement : I_Hard;
 
 
1709
                Menus.MenusState = MENUSSTATE_STARTGAME;
 
 
1710
                SetLevelToLoadForSinglePlayer(episode_to_play);
 
 
1711
            }
 
 
1712
        }
 
 
1713
        break;
 
 
1714
        case MENU_ELEMENT_SELECTEPISODE:
 
 
1715
        {
 
 
1716
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT && MaximumSelectableLevel >= *elementPtr->c.SliderValuePtr)
 
 
1717
            {
 
 
1718
                int number_of_bacis_levels;
 
 
1719
 
 
 
1720
                switch(AvP.PlayerType)
 
 
1721
                {
 
 
1722
                    case I_Alien:
 
 
1723
                        number_of_bacis_levels = MAX_NO_OF_BASIC_ALIEN_EPISODES;
 
 
1724
                    break;
 
 
1725
                    case I_Marine:
 
 
1726
                        number_of_bacis_levels = MAX_NO_OF_BASIC_MARINE_EPISODES;
 
 
1727
                    break;
 
 
1728
                    case I_Predator:
 
 
1729
                        number_of_bacis_levels = MAX_NO_OF_BASIC_PREDATOR_EPISODES;
 
 
1730
                }
 
 
1731
 
 
 
1732
                SetupNewMenu((episode_to_play < number_of_bacis_levels) ? MENU_LEVELBRIEFING_BASIC : MENU_LEVELBRIEFING_BONUS);
 
 
1733
            }
 
 
1734
            else
 
 
1735
            {
 
 
1736
                /* This code is reached when an EPISODE element has been
 
 
1737
                activated but not "selected" i.e. the user wants to change
 
 
1738
                the current episode, not start playing the current episode */
 
 
1739
                if (interactionID == MENU_ELEMENT_INTERACTION_INCREASE)
 
 
1740
                {
 
 
1741
                    if (*elementPtr->c.SliderValuePtr < elementPtr->b.MaxSliderValue)
 
 
1742
                    {
 
 
1743
                        *elementPtr->c.SliderValuePtr +=1;
 
 
1744
                        EpisodeSelectScrollOffset -= ONE_FIXED;
 
 
1745
                    }
 
 
1746
                }
 
 
1747
                else if (*elementPtr->c.SliderValuePtr > 0)
 
 
1748
                {
 
 
1749
                    *elementPtr->c.SliderValuePtr -= 1;
 
 
1750
                    EpisodeSelectScrollOffset += ONE_FIXED;
 
 
1751
                }
 
 
1752
            }
 
 
1753
        }
 
 
1754
        break;
 
 
1755
        case MENU_ELEMENT_STARTLEVELWITHCHEAT:
 
 
1756
        {
 
 
1757
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1758
            {
 
 
1759
                Menus.MenusState = MENUSSTATE_STARTGAME;
 
 
1760
                AvP.PlayerType = CheatMode_Species;
 
 
1761
                AvP.Difficulty = I_Hard;
 
 
1762
                SetLevelToLoadForCheatMode(CheatMode_Environment);
 
 
1763
            }
 
 
1764
        }
 
 
1765
        break;
 
 
1766
        case MENU_ELEMENT_STARTSKIRMISH:
 
 
1767
        case MENU_ELEMENT_STARTMPGAME:
 
 
1768
        {
 
 
1769
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1770
            {
 
 
1771
                if (InitAVPNetGameForHost(UserProfile.PlayerName, MP_Species, netGameData.gameType, netGameData.levelNumber))
 
 
1772
                {
 
 
1773
                    Menus.MenusState = MENUSSTATE_STARTGAME;
 
 
1774
 
 
 
1775
                    if(netGameData.gameType == NGT_Coop)
 
 
1776
                    {
 
 
1777
                        if(netGameData.levelNumber < MAX_NO_OF_COOPERATIVE_EPISODES)
 
 
1778
                            SetLevelToLoadForCooperative(netGameData.levelNumber);
 
 
1779
                    }
 
 
1780
                    else if(netGameData.levelNumber < MAX_NO_OF_MULTIPLAYER_EPISODES)
 
 
1781
                    {
 
 
1782
                        SetLevelToLoadForMultiplayer(netGameData.levelNumber);
 
 
1783
                    }
 
 
1784
                }
 
 
1785
 
 
 
1786
                strcpy(MP_Config_Description, "previous_game");
 
 
1787
                SaveMultiplayerConfiguration("previous_game");
 
 
1788
            }
 
 
1789
        }
 
 
1790
        break;
 
 
1791
        case MENU_ELEMENT_JOINMPGAME:
 
 
1792
        {
 
 
1793
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1794
            {
 
 
1795
                Menus.MenusState = MENUSSTATE_STARTGAME;
 
 
1796
                netGameData.myStartFlag = 1;        
 
 
1797
            }
 
 
1798
        }
 
 
1799
        break;
 
 
1800
        case MENU_ELEMENT_LOADMPCONFIG:
 
 
1801
        {
 
 
1802
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1803
            {
 
 
1804
                //LoadMultiplayerConfigurationByIndex(Menus.CurrentlySelectedElement);
 
 
1805
                SetupNewMenu(elementPtr->b.MenuToGoTo);
 
 
1806
            }
 
 
1807
        }
 
 
1808
        break;
 
 
1809
        case MENU_ELEMENT_LOADIPADDRESS:
 
 
1810
        {
 
 
1811
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1812
            {
 
 
1813
                LoadIPAddress(elementPtr->c.TextPtr);
 
 
1814
                SetupNewMenu(elementPtr->b.MenuToGoTo);
 
 
1815
            }
 
 
1816
        }
 
 
1817
        break;
 
 
1818
        case MENU_ELEMENT_SELECT_WINDOWSIZE:
 
 
1819
        {
 
 
1820
            extern void change_video_mode(int);
 
 
1821
            change_video_mode(((interactionID == MENU_ELEMENT_INTERACTION_SELECT) || (interactionID == MENU_ELEMENT_INTERACTION_INCREASE)));
 
 
1822
        }
 
 
1823
        break;
 
 
1824
        case MENU_ELEMENT_RESUMEGAME:
 
 
1825
        {
 
 
1826
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1827
                Menus.MenusState = MENUSSTATE_OUTSIDEMENUS;
 
 
1828
        }
 
 
1829
        break;
 
 
1830
        case MENU_ELEMENT_RESTARTGAME:
 
 
1831
        {
 
 
1832
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1833
            {
 
 
1834
                Menus.MenusState = MENUSSTATE_OUTSIDEMENUS;
 
 
1835
                AvP.RestartLevel = 1;
 
 
1836
                AvP.MainLoopRunning = 0;
 
 
1837
            }
 
 
1838
        }
 
 
1839
        break;
 
 
1840
        case MENU_ELEMENT_KEYCONFIG:
 
 
1841
        {
 
 
1842
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1843
            {
 
 
1844
                Menus.UserChangingKeyConfig = 1;
 
 
1845
                Menus.ChangingPrimaryConfig = !KeyConfigSelectionColumn;
 
 
1846
            }
 
 
1847
            else
 
 
1848
            {
 
 
1849
                KeyConfigSelectionColumn = !KeyConfigSelectionColumn;     
 
 
1850
            }
 
 
1851
        }
 
 
1852
        break;
 
 
1853
        case MENU_ELEMENT_KEYCONFIGOK:
 
 
1854
        {
 
 
1855
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1856
            {
 
 
1857
                switch (Menus.CurrentMenu)
 
 
1858
                {
 
 
1859
                    case MENU_MARINEKEYCONFIG:
 
 
1860
                    {
 
 
1861
                        UserProfile.MarineInputPrimaryConfig = PlayerInputPrimaryConfig;
 
 
1862
                        UserProfile.MarineInputSecondaryConfig = PlayerInputSecondaryConfig;
 
 
1863
                    }
 
 
1864
                    break;
 
 
1865
                    case MENU_PREDATORKEYCONFIG:
 
 
1866
                    {
 
 
1867
                        UserProfile.PredatorInputPrimaryConfig = PlayerInputPrimaryConfig;
 
 
1868
                        UserProfile.PredatorInputSecondaryConfig = PlayerInputSecondaryConfig;
 
 
1869
                    }
 
 
1870
                    break;
 
 
1871
                    case MENU_ALIENKEYCONFIG:
 
 
1872
                    {
 
 
1873
                        UserProfile.AlienInputPrimaryConfig = PlayerInputPrimaryConfig;
 
 
1874
                        UserProfile.AlienInputSecondaryConfig = PlayerInputSecondaryConfig;
 
 
1875
                    }
 
 
1876
                    break;
 
 
1877
                    case MENU_MOUSEOPTIONS:
 
 
1878
                        UserProfile.ControlMethods = PlayerControlMethods;
 
 
1879
                    default:
 
 
1880
                    break;
 
 
1881
                }
 
 
1882
 
 
 
1883
                SaveUserProfile();
 
 
1884
            }
 
 
1885
        }
 
 
1886
        break;
 
 
1887
        case MENU_ELEMENT_RESETKEYCONFIG:
 
 
1888
        {
 
 
1889
            if (interactionID == MENU_ELEMENT_INTERACTION_SELECT)
 
 
1890
            {
 
 
1891
                switch (Menus.CurrentMenu)
 
 
1892
                {
 
 
1893
                    case MENU_MARINEKEYCONFIG:
 
 
1894
                    {
 
 
1895
                        UserProfile.MarineInputPrimaryConfig = DefaultMarineInputPrimaryConfig;
 
 
1896
                        UserProfile.MarineInputSecondaryConfig = DefaultMarineInputSecondaryConfig;
 
 
1897
                    }
 
 
1898
                    break;
 
 
1899
                    case MENU_PREDATORKEYCONFIG:
 
 
1900
                    {
 
 
1901
                        UserProfile.PredatorInputPrimaryConfig = DefaultPredatorInputPrimaryConfig;
 
 
1902
                        UserProfile.PredatorInputSecondaryConfig = DefaultPredatorInputSecondaryConfig;
 
 
1903
                    }
 
 
1904
                    break;
 
 
1905
                    case MENU_ALIENKEYCONFIG:
 
 
1906
                    {
 
 
1907
                        UserProfile.AlienInputPrimaryConfig = DefaultAlienInputPrimaryConfig;
 
 
1908
                        UserProfile.AlienInputPrimaryConfig = DefaultAlienInputSecondaryConfig;
 
 
1909
                    }
 
 
1910
                    default:
 
 
1911
                        break;
 
 
1912
                }
 
 
1913
            }
 
 
1914
        }
 
 
1915
        break;
 
 
1916
        case MENU_ELEMENT_RESETMPCONFIG:
 
 
1917
        {
 
 
1918
            //reset the multiplayer configuration
 
 
1919
            extern void SetDefaultMultiplayerConfig();
 
 
1920
            SetDefaultMultiplayerConfig();
 
 
1921
        }
 
 
1922
        break;
 
 
1923
        case MENU_ELEMENT_LOADGAME:
 
 
1924
        {
 
 
1925
            int slot = Menus.CurrentlySelectedElement;
 
 
1926
 
 
 
1927
            if(slot >= 0 && slot < NUMBER_OF_SAVE_SLOTS)
 
 
1928
            {
 
 
1929
                if(SaveGameSlot[slot].SlotUsed)
 
 
1930
                {
 
 
1931
                    LoadGameRequest = slot;
 
 
1932
 
 
 
1933
                    if(Menus.MenusState == MENUSSTATE_INGAMEMENUS)
 
 
1934
                    {
 
 
1935
                        if (!get_new_env(slot, 0))
 
 
1936
                            AvP.RestartLevel = 1;
 
 
1937
 
 
 
1938
                            AvP.MainLoopRunning = 0;
 
 
1939
                    }
 
 
1940
                    else
 
 
1941
                    {
 
 
1942
                        get_new_env(slot, 1);
 
 
1943
                    }
 
 
1944
 
 
 
1945
                    Menus.MenusState = MENUSSTATE_STARTGAME;    
 
 
1946
                }
 
 
1947
            }
 
 
1948
        }
 
 
1949
        break;
 
 
1950
        case MENU_ELEMENT_SAVEGAME:
 
 
1951
        {
 
 
1952
            int slot = Menus.CurrentlySelectedElement;
 
 
1953
 
 
 
1954
            if(slot >= 0 && slot < NUMBER_OF_SAVE_SLOTS)
 
 
1955
            {
 
 
1956
                Menus.MenusState = MENUSSTATE_STARTGAME;
 
 
1957
 
 
 
1958
                if(!PlayerStatus.Alive || (CHEATMODE_NONACTIVE != UserProfile.active_bonus) || (PlayerStatus.saves_left < 1))
 
 
1959
                {
 
 
1960
                    //empty
 
 
1961
                }
 
 
1962
                else
 
 
1963
                {
 
 
1964
                    SaveGame(slot);
 
 
1965
                }
 
 
1966
            }
 
 
1967
        }
 
 
1968
        break;
 
 
1969
        default:
 
 
1970
        assert("UNKNOWN MENU ELEMENT"==0);
 
 
1971
    }
 
 
1972
}
 
 
1973
 
 
 
1974
static void ActUponUsersInput()
 
 
1975
{
 
 
1976
    if (Menus.UserEnteringText)
 
 
1977
    {
 
 
1978
        MENU_ELEMENT *elementPtr = &Menus.MenuElements[Menus.CurrentlySelectedElement];
 
 
1979
 
 
 
1980
        if (Keyboard[SDLK_ESCAPE] || Keyboard[SDLK_RETURN])
 
 
1981
        {
 
 
1982
            elementPtr->c.TextPtr[Menus.PositionInTextField] = 0;
 
 
1983
            Menus.UserEnteringText = 0;
 
 
1984
 
 
 
1985
            // KJL 10:09:35 09/02/00 - when the user has entered their name,
 
 
1986
            // move down to the next option. If the user enters a null
 
 
1987
            // string, replace it with a placeholder name        
 
 
1988
            if((Menus.CurrentMenu == MENU_SKIRMISH) || (Menus.CurrentMenu == MENU_MULTIPLAYER_MAINSTART))
 
 
1989
            {
 
 
1990
                if(!Menus.PositionInTextField)
 
 
1991
                    strcpy(elementPtr->c.TextPtr, "DeadMeat");
 
 
1992
 
 
 
1993
                Menus.CurrentlySelectedElement++;
 
 
1994
            }
 
 
1995
        }
 
 
1996
        else if (Keyboard[SDLK_BACKSPACE] || Keyboard[SDLK_DELETE])
 
 
1997
        {
 
 
1998
            if (Menus.PositionInTextField > 0)
 
 
1999
                elementPtr->c.TextPtr[--Menus.PositionInTextField] = 0;
 
 
2000
        }
 
 
2001
        else if(Keyboard[SDLK_LEFT])
 
 
2002
        {
 
 
2003
            if (Menus.PositionInTextField > 0)
 
 
2004
                --Menus.PositionInTextField;
 
 
2005
        }
 
 
2006
        else
 
 
2007
        {
 
 
2008
            if (Menus.PositionInTextField < elementPtr->b.MaxTextLength)
 
 
2009
            {
 
 
2010
                signed int key = SDLK_FIRST;
 
 
2011
 
 
 
2012
                for (; key < number_of_available_keys; key++)
 
 
2013
                {
 
 
2014
                    if (key != SDLK_ESCAPE && key != SDLK_RETURN)
 
 
2015
                    {
 
 
2016
                        if (Keyboard[key])
 
 
2017
                        {
 
 
2018
                            if (Menus.PositionInTextField < elementPtr->b.MaxTextLength)
 
 
2019
                            {
 
 
2020
                                //see if there is room for this character
 
 
2021
                                if(Menus.FontToUse == MENU_FONT_BIG && elementPtr->ElementID != MENU_ELEMENT_TEXTFIELD_SMALLWRAPPED)
 
 
2022
                                {
 
 
2023
                                    //using large font
 
 
2024
                                    //allocate 32 pixels for each new character for the moment
 
 
2025
                                    //the true amount used will be worked out when the font is drawn
 
 
2026
                                    //Might cause a slight glitch for fast typists , but I forgot about 
 
 
2027
                                    //the damned kerned fonts until after I'd written most of this
 
 
2028
                                        if(Menus.WidthLeftForText < 32)
 
 
2029
                                            break;
 
 
2030
 
 
 
2031
                                    Menus.WidthLeftForText -= 32;
 
 
2032
                                }
 
 
2033
                                else
 
 
2034
                                {
 
 
2035
                                    //using small font
 
 
2036
                                    if(Menus.WidthLeftForText < AAFontWidths[(uint8_t)key])
 
 
2037
                                            break;
 
 
2038
 
 
 
2039
                                    Menus.WidthLeftForText -= AAFontWidths[(uint8_t)key];
 
 
2040
                                }
 
 
2041
 
 
 
2042
                                elementPtr->c.TextPtr[Menus.PositionInTextField++] = key;
 
 
2043
                                elementPtr->c.TextPtr[Menus.PositionInTextField] = 0;
 
 
2044
                            }
 
 
2045
 
 
 
2046
                        break;
 
 
2047
                        }
 
 
2048
                    }
 
 
2049
                }
 
 
2050
 
 
 
2051
            }
 
 
2052
        }
 
 
2053
 
 
 
2054
        memset(&Keyboard[0], 0, number_of_available_keys); //SDL_EnableKeyRepeat(0, SDL_DEFAULT_REPEAT_INTERVAL); does not work
 
 
2055
    }
 
 
2056
    else if (Menus.UserChangingKeyConfig)
 
 
2057
    {
 
 
2058
        if (Keyboard[SDLK_ESCAPE])
 
 
2059
        {
 
 
2060
            Menus.UserChangingKeyConfig = 0;
 
 
2061
        }
 
 
2062
        else
 
 
2063
        {
 
 
2064
            int key = SDLK_FIRST;
 
 
2065
 
 
 
2066
            for (; key < number_of_available_keys; key++)
 
 
2067
            {
 
 
2068
                if (!(key == SDLK_ESCAPE) && !(key >= SDLK_0 && key <= SDLK_9) && !( key == SDLK_RETURN))
 
 
2069
                {
 
 
2070
                    if (Keyboard[key])
 
 
2071
                    {
 
 
2072
                        if (Menus.ChangingPrimaryConfig)
 
 
2073
                        {
 
 
2074
                            *(((SDLKey*)&PlayerInputPrimaryConfig)+Menus.CurrentlySelectedElement-2) = key;
 
 
2075
                            Menus.UserChangingKeyConfig=0;
 
 
2076
                        }
 
 
2077
                        else // changing Secondary
 
 
2078
                        {
 
 
2079
                            *(((SDLKey*)&PlayerInputSecondaryConfig)+Menus.CurrentlySelectedElement-2) = key;
 
 
2080
                            Menus.UserChangingKeyConfig=0;
 
 
2081
                        }
 
 
2082
                    break;
 
 
2083
                    }
 
 
2084
                }
 
 
2085
            }
 
 
2086
        }
 
 
2087
    }
 
 
2088
    else
 
 
2089
    {
 
 
2090
        if ((Keyboard[SDLK_ESCAPE] || Keyboard[SDL_BUTTON_RIGHT]) && (Menus.CurrentMenu != MENU_MAIN))
 
 
2091
        {
 
 
2092
            switch(Menus.CurrentMenu)
 
 
2093
            {
 
 
2094
            /*
 
 
2095
                case MENU_MULTIPLAYER_CONFIG_JOIN:
 
 
2096
                    AddNetMsg_PlayerLeaving();
 
 
2097
                    NetSendMessages();
 
 
2098
                break;
 
 
2099
            */
 
 
2100
                case MENU_GAMEOPTIONS:
 
 
2101
                    SetDetailLevelsFromMenu();
 
 
2102
                break;
 
 
2103
                case MENU_BONUSOPTIONS:
 
 
2104
                    //UserProfile.active_bonus = CHEATMODE_NONACTIVE;
 
 
2105
                break;    
 
 
2106
                case MENU_SKIRMISH:
 
 
2107
                case MENU_MULTIPLAYER_HOSTSETUP:
 
 
2108
                case MENU_MULTIPLAYER_MAINSTART:
 
 
2109
                default:
 
 
2110
                break;
 
 
2111
            }
 
 
2112
 
 
 
2113
            if(InputIsDebounced)
 
 
2114
            {
 
 
2115
                if (Menus.CurrentMenu == MENU_INGAME)
 
 
2116
                    Menus.MenusState = MENUSSTATE_STARTGAME;
 
 
2117
                else
 
 
2118
                    SetupNewMenu(MenusData[Menus.CurrentMenu].ParentMenu);
 
 
2119
 
 
 
2120
                InputIsDebounced = 0;
 
 
2121
            }
 
 
2122
        }
 
 
2123
        else if (Keyboard[SDLK_RETURN] || Keyboard[SDLK_SPACE] || Keyboard[SDL_BUTTON_LEFT])
 
 
2124
        {
 
 
2125
            if (InputIsDebounced)
 
 
2126
            {
 
 
2127
                InteractWithMenuElement(MENU_ELEMENT_INTERACTION_SELECT);
 
 
2128
                InputIsDebounced = 0;
 
 
2129
            }
 
 
2130
        }
 
 
2131
        else if (Keyboard[SDLK_UP] || Keyboard[SDL_BUTTON_WHEELUP])
 
 
2132
        {
 
 
2133
            if (InputIsDebounced)
 
 
2134
            {
 
 
2135
                switch (Menus.CurrentMenu)
 
 
2136
                {
 
 
2137
                    case MENU_SELECT_EPISODE:
 
 
2138
                        InteractWithMenuElement(MENU_ELEMENT_INTERACTION_DECREASE);
 
 
2139
                    break;
 
 
2140
                    case MENU_MARINEKEYCONFIG:
 
 
2141
                    case MENU_PREDATORKEYCONFIG:
 
 
2142
                    case MENU_ALIENKEYCONFIG:
 
 
2143
                    {
 
 
2144
                        if (Menus.CurrentlySelectedElement > 0)
 
 
2145
                        {
 
 
2146
                            Menus.CurrentlySelectedElement--;
 
 
2147
                            //Sound_Play(SID_MENUS_CHANGE_ITEM, "r");
 
 
2148
                        }
 
 
2149
                    }
 
 
2150
                    break;
 
 
2151
                    default:
 
 
2152
                    {
 
 
2153
                        Menus.CurrentlySelectedElement--;
 
 
2154
 
 
 
2155
                        if (Menus.CurrentlySelectedElement < 0)
 
 
2156
                            Menus.CurrentlySelectedElement = Menus.NumberOfElementsInMenu-1;
 
 
2157
 
 
 
2158
                        Sound_Play(SID_MENUS_CHANGE_ITEM, "r");
 
 
2159
                    }
 
 
2160
                }
 
 
2161
                InputIsDebounced = 0;
 
 
2162
            }
 
 
2163
            else
 
 
2164
            {
 
 
2165
                KeyDepressedCounter += RealFrameTime;
 
 
2166
            }
 
 
2167
        }
 
 
2168
        else if (Keyboard[SDLK_DOWN] || Keyboard[SDL_BUTTON_WHEELDOWN])
 
 
2169
        {
 
 
2170
            if (InputIsDebounced)
 
 
2171
            {
 
 
2172
                switch (Menus.CurrentMenu)
 
 
2173
                {
 
 
2174
                    case MENU_SELECT_EPISODE:
 
 
2175
                        InteractWithMenuElement(MENU_ELEMENT_INTERACTION_INCREASE);
 
 
2176
                    break;
 
 
2177
                    case MENU_MARINEKEYCONFIG:
 
 
2178
                    case MENU_PREDATORKEYCONFIG:
 
 
2179
                    case MENU_ALIENKEYCONFIG:
 
 
2180
                    {
 
 
2181
                        if (Menus.CurrentlySelectedElement < Menus.NumberOfElementsInMenu-1)
 
 
2182
                        {
 
 
2183
                            Menus.CurrentlySelectedElement++;
 
 
2184
                            Sound_Play(SID_MENUS_CHANGE_ITEM, "r");
 
 
2185
                        }
 
 
2186
                        break;
 
 
2187
                    }
 
 
2188
                    default:
 
 
2189
                    {
 
 
2190
                        Menus.CurrentlySelectedElement++;
 
 
2191
 
 
 
2192
                        if (Menus.CurrentlySelectedElement >= Menus.NumberOfElementsInMenu)
 
 
2193
                            Menus.CurrentlySelectedElement= 0;
 
 
2194
 
 
 
2195
                        Sound_Play(SID_MENUS_CHANGE_ITEM, "r");
 
 
2196
                        break;
 
 
2197
                    }
 
 
2198
                }
 
 
2199
 
 
 
2200
                InputIsDebounced = 0;
 
 
2201
            }
 
 
2202
            else
 
 
2203
            {
 
 
2204
                KeyDepressedCounter += RealFrameTime;
 
 
2205
            }
 
 
2206
        }
 
 
2207
        else if (Keyboard[SDLK_LEFT])
 
 
2208
        {
 
 
2209
            if (InputIsDebounced)
 
 
2210
            {
 
 
2211
                InteractWithMenuElement(MENU_ELEMENT_INTERACTION_DECREASE);
 
 
2212
                InputIsDebounced = 0;
 
 
2213
            }
 
 
2214
            else
 
 
2215
            {
 
 
2216
                KeyDepressedCounter += RealFrameTime;
 
 
2217
            }
 
 
2218
        }
 
 
2219
        else if (Keyboard[SDLK_RIGHT])
 
 
2220
        {
 
 
2221
            if (InputIsDebounced)
 
 
2222
            {
 
 
2223
                InteractWithMenuElement(MENU_ELEMENT_INTERACTION_INCREASE);
 
 
2224
                InputIsDebounced = 0;
 
 
2225
            }
 
 
2226
            else
 
 
2227
            {
 
 
2228
                KeyDepressedCounter += RealFrameTime;
 
 
2229
            }
 
 
2230
        }
 
 
2231
        else if (Keyboard[SDLK_BACKSPACE]) 
 
 
2232
        {
 
 
2233
            switch (Menus.MenuElements[Menus.CurrentlySelectedElement].ElementID)
 
 
2234
            {
 
 
2235
                case MENU_ELEMENT_KEYCONFIG:
 
 
2236
                {
 
 
2237
                    if (!KeyConfigSelectionColumn)
 
 
2238
                    {
 
 
2239
                        *( ((uint8_t*)&PlayerInputPrimaryConfig) + Menus.CurrentlySelectedElement-2) = "fix";
 
 
2240
                    }
 
 
2241
                    else // changing Secondary
 
 
2242
                    {
 
 
2243
                        *( ((uint8_t*)&PlayerInputSecondaryConfig) + Menus.CurrentlySelectedElement-2) = "fix";
 
 
2244
                    }
 
 
2245
                    break;
 
 
2246
                }
 
 
2247
                case MENU_ELEMENT_LOADMPCONFIG :
 
 
2248
                {
 
 
2249
                    //take note of the current configuration
 
 
2250
                    MultiplayerConfigurationIndex = Menus.CurrentlySelectedElement;
 
 
2251
                    MultiplayerConfigurationName = Menus.MenuElements[Menus.CurrentlySelectedElement].c.TextPtr;
 
 
2252
                    //setup the delete configuration menu
 
 
2253
                }
 
 
2254
                default:
 
 
2255
                break;
 
 
2256
            }
 
 
2257
        }
 
 
2258
        else  
 
 
2259
        {
 
 
2260
            InputIsDebounced = 1;
 
 
2261
            KeyDepressedCounter = 0;
 
 
2262
        }
 
 
2263
 
 
 
2264
        if (KeyDepressedCounter > ONE_FIXED)
 
 
2265
            InputIsDebounced = 1;
 
 
2266
    }
 
 
2267
}
 
 
2268
 
 
 
2269
static void CheckForKeysWithMultipleAssignments()
 
 
2270
{
 
 
2271
    SDLKey *configPtr[2];
 
 
2272
    int column,row;
 
 
2273
 
 
 
2274
    configPtr[0] = (SDLKey*)&PlayerInputPrimaryConfig;
 
 
2275
    configPtr[1] = (SDLKey*)&PlayerInputSecondaryConfig;
 
 
2276
 
 
 
2277
    for (column=0; column <= 1; column++)
 
 
2278
    {
 
 
2279
        for (row=0; row < 32; row++)
 
 
2280
        {
 
 
2281
            int innerColumn,innerRow;
 
 
2282
 
 
 
2283
            MultipleAssignments[column][row] = 0;
 
 
2284
 
 
 
2285
            for (innerColumn=0; innerColumn<=1; innerColumn++)
 
 
2286
            for (innerRow=0; innerRow<32; innerRow++)
 
 
2287
            {
 
 
2288
                if (innerRow==row) continue;
 
 
2289
                // && innerColumn==column) continue;
 
 
2290
                if ( (configPtr[column])[row]==(configPtr[innerColumn])[innerRow] )
 
 
2291
                {
 
 
2292
                    MultipleAssignments[column][row] = 1;
 
 
2293
                }
 
 
2294
            }
 
 
2295
        }
 
 
2296
    }
 
 
2297
}
 
 
2298
 
 
 
2299
static void TestValidityOfCheatMenu()
 
 
2300
{
 
 
2301
    CheatMode_GetNextAllowedMode(Menus.MenuElements[0].c.SliderValuePtr, 1);
 
 
2302
    CheatMode_GetNextAllowedSpecies(Menus.MenuElements[1].c.SliderValuePtr, 1);
 
 
2303
    CheatMode_GetNextAllowedEnvironment(Menus.MenuElements[2].c.SliderValuePtr, 1);
 
 
2304
}
 
 
2305
 
 
 
2306
static void RenderScrollyMenu()
 
 
2307
{
 
 
2308
    MENU_ELEMENT *elementPtr = Menus.MenuElements;
 
 
2309
    int i;
 
 
2310
    int y;
 
 
2311
    int first = Menus.CurrentlySelectedElement;
 
 
2312
    int last = Menus.CurrentlySelectedElement;
 
 
2313
    int available_above = (MENU_HEIGHT-HeightOfMenuElement(&elementPtr[Menus.CurrentlySelectedElement]))/2;
 
 
2314
    int available_below = available_above;
 
 
2315
    int done = 0;
 
 
2316
 
 
 
2317
    //work out the first and last element to be drawn
 
 
2318
    do
 
 
2319
    {
 
 
2320
        done = 1;
 
 
2321
 
 
 
2322
        if(first-1 >= 0)
 
 
2323
        {
 
 
2324
            int h = HeightOfMenuElement(&elementPtr[first-1]);
 
 
2325
 
 
 
2326
            if(h <= available_above)
 
 
2327
            {
 
 
2328
                available_above -= h;
 
 
2329
                first--;
 
 
2330
                done = 0;
 
 
2331
            }
 
 
2332
            else
 
 
2333
            {
 
 
2334
                available_below += available_above;
 
 
2335
                available_above = 0;
 
 
2336
            }
 
 
2337
        }
 
 
2338
 
 
 
2339
        if(!first)
 
 
2340
        {
 
 
2341
            //no more elements above selected element
 
 
2342
            available_below += available_above;
 
 
2343
            available_above = 0;
 
 
2344
        }
 
 
2345
 
 
 
2346
        if(last+1 < Menus.NumberOfElementsInMenu)
 
 
2347
        {
 
 
2348
            int h = HeightOfMenuElement(&elementPtr[last+1]);
 
 
2349
 
 
 
2350
            if(h <= available_below)
 
 
2351
            {
 
 
2352
                available_below -= h;
 
 
2353
                last++;
 
 
2354
                done = 0;
 
 
2355
            }
 
 
2356
        }
 
 
2357
 
 
 
2358
        if(last == (Menus.NumberOfElementsInMenu-1))
 
 
2359
        {
 
 
2360
            //no more elements below selected element
 
 
2361
            available_above += available_below;
 
 
2362
            available_below = 0;
 
 
2363
        }
 
 
2364
 
 
 
2365
    } while(!done);
 
 
2366
 
 
 
2367
    //draw the appropriate elements
 
 
2368
    elementPtr = &elementPtr[first];
 
 
2369
    y = MENU_TOPY;
 
 
2370
 
 
 
2371
    for(i=first; i <= last; i++, elementPtr++)
 
 
2372
    {
 
 
2373
        elementPtr->Brightness = (i == Menus.CurrentlySelectedElement) ? BRIGHTNESS_OF_HIGHLIGHTED_ELEMENT : BRIGHTNESS_OF_DARKENED_ELEMENT;
 
 
2374
        RenderMenuElement(elementPtr, i, y);
 
 
2375
        y += HeightOfMenuElement(elementPtr);
 
 
2376
    }
 
 
2377
}
 
 
2378
 
 
 
2379
static int ActualGammaSetting = -1;
 
 
2380
unsigned char GammaValues[256];
 
 
2381
 
 
 
2382
static void UpdateGammaSettings()
 
 
2383
{
 
 
2384
    if (UserProfile.GammaSetting != ActualGammaSetting) 
 
 
2385
    {
 
 
2386
        int i;
 
 
2387
 
 
 
2388
        for (i=0; i <= 255; i++)
 
 
2389
        {
 
 
2390
            int u = ((i*65536)/255);
 
 
2391
            int m = MUL_FIXED(u,u);
 
 
2392
            int l = MUL_FIXED(2*u,ONE_FIXED-u);
 
 
2393
 
 
 
2394
            int a = m + MUL_FIXED(UserProfile.GammaSetting*256,l);
 
 
2395
 
 
 
2396
            m = MUL_FIXED(a,a);
 
 
2397
            l = MUL_FIXED(2*a, ONE_FIXED-a);
 
 
2398
 
 
 
2399
            a = m/256 + MUL_FIXED(UserProfile.GammaSetting,l);
 
 
2400
 
 
 
2401
            GammaValues[i]= (a < 0) ? 0 : (a > 255) ? 255 : a;
 
 
2402
        }
 
 
2403
 
 
 
2404
        ActualGammaSetting = UserProfile.GammaSetting;
 
 
2405
    }
 
 
2406
}
 
 
2407
 
 
 
2408
static void UpdateMenus()
 
 
2409
{
 
 
2410
    switch (Menus.CurrentMenu)
 
 
2411
    {
 
 
2412
        case MENU_LOADGAME:
 
 
2413
            RenderLoadSaveGameMenu(0);
 
 
2414
        break;
 
 
2415
        case MENU_SAVEGAME:
 
 
2416
            if(!PlayerStatus.Alive)
 
 
2417
            {
 
 
2418
                RenderSmallMenuText("No save in when dead.", ScreenDescriptorBlock.SDB_CentreX, 70, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
2419
            }
 
 
2420
            else if(CHEATMODE_NONACTIVE != UserProfile.active_bonus)
 
 
2421
            {
 
 
2422
                RenderSmallMenuText("No save in cheat/debug mode.", ScreenDescriptorBlock.SDB_CentreX, 70, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
2423
            }
 
 
2424
            else if(PlayerStatus.saves_left < 1)
 
 
2425
            {
 
 
2426
                RenderSmallMenuText("No saves left.", ScreenDescriptorBlock.SDB_CentreX, 70, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
2427
            }
 
 
2428
            else if(!safetosave())
 
 
2429
            {
 
 
2430
                RenderSmallMenuText("Not safe to save.", ScreenDescriptorBlock.SDB_CentreX, 70, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
2431
            }
 
 
2432
            else
 
 
2433
            {
 
 
2434
                RenderLoadSaveGameMenu(1);
 
 
2435
            }
 
 
2436
        break;
 
 
2437
        case MENU_SELECT_EPISODE:
 
 
2438
            switch(AvP.PlayerType)
 
 
2439
            {
 
 
2440
                default:
 
 
2441
                case I_Alien:
 
 
2442
                    RenderEpisodeSelectMenu(MAX_NO_OF_BASIC_ALIEN_EPISODES, alien_episodes);
 
 
2443
                break;
 
 
2444
                case I_Marine:
 
 
2445
                    RenderEpisodeSelectMenu(MAX_NO_OF_BASIC_MARINE_EPISODES, marine_episodes);
 
 
2446
                break;
 
 
2447
                case I_Predator:
 
 
2448
                    RenderEpisodeSelectMenu(MAX_NO_OF_BASIC_PREDATOR_EPISODES, predator_episodes);
 
 
2449
            }
 
 
2450
        break;
 
 
2451
        case MENU_ALIENKEYCONFIG:
 
 
2452
        case MENU_MARINEKEYCONFIG:
 
 
2453
        case MENU_PREDATORKEYCONFIG:
 
 
2454
            CheckForKeysWithMultipleAssignments();
 
 
2455
            RenderKeyConfigurationMenu();
 
 
2456
        break;
 
 
2457
        case MENU_SKIRMISH:
 
 
2458
            RenderSmallMenuText("Skirmish", ScreenDescriptorBlock.SDB_CentreX, 70, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
2459
            RenderScrollyMenu();
 
 
2460
        break;
 
 
2461
        case MENU_MULTIPLAYER_HOSTSETUP:
 
 
2462
            RenderSmallMenuText("Multiplayer Configuration", ScreenDescriptorBlock.SDB_CentreX, 70, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
2463
            RenderScrollyMenu();
 
 
2464
        break;
 
 
2465
        //case MENU_MULTIPLAYER_CONFIG_JOIN: RenderScrollyMenu(); break;
 
 
2466
        //case MENU_MULTIPLAYER_LOADCONFIG:
 
 
2467
            //RenderSmallMenuText("Load Configuration", ScreenDescriptorBlock.SDB_CentreX, 70, ONE_FIXED, MENUFORMAT_CENTREJUSTIFIED);
 
 
2468
            //RenderScrollyMenu();
 
 
2469
        break;
 
 
2470
        case MENU_AUDIOVIDEOOPTIONS:
 
 
2471
        {
 
 
2472
            if(3 == Menus.CurrentlySelectedElement)
 
 
2473
                SoundSys_ChangeVolume(MUL_FIXED(UserProfile.EffectsSoundVolume, MasterVolumeFadeLevel));
 
 
2474
            else if(5 == Menus.CurrentlySelectedElement)
 
 
2475
                UpdateGammaSettings();
 
 
2476
 
 
 
2477
            int scale = DIV_FIXED(ScreenDescriptorBlock.SDB_Height, ScreenDescriptorBlock.SDB_Width);
 
 
2478
            int h = scale/2048;
 
 
2479
            int offset = scale/4096;
 
 
2480
            DrawColourBar(offset, offset+h,  ONE_FIXED, 0, 0);
 
 
2481
            DrawColourBar(offset*2+h, offset*2+h*2,  0, ONE_FIXED, 0);
 
 
2482
            DrawColourBar(ScreenDescriptorBlock.SDB_Height - offset*2-h*2, ScreenDescriptorBlock.SDB_Height - offset*2-h,  0, 0, ONE_FIXED);
 
 
2483
            DrawColourBar(ScreenDescriptorBlock.SDB_Height - offset-h, ScreenDescriptorBlock.SDB_Height - offset, ONE_FIXED, ONE_FIXED, ONE_FIXED);
 
 
2484
            RenderMenu();
 
 
2485
        }
 
 
2486
        break;
 
 
2487
        case MENU_BONUSOPTIONS:
 
 
2488
            TestValidityOfCheatMenu();
 
 
2489
            RenderMenu();