~ubuntu-branches/debian/stretch/opentyrian/stretch

« back to all changes in this revision

Viewing changes to src/game_menu.c

  • Committer: Package Import Robot
  • Author(s): Etienne Millon
  • Date: 2015-03-31 08:48:54 UTC
  • Revision ID: package-import@ubuntu.com-20150331084854-f5a4uoz7uv3vopk6
Tags: upstream-2.1.20130907+dfsg
ImportĀ upstreamĀ versionĀ 2.1.20130907+dfsg

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * OpenTyrian: A modern cross-platform port of Tyrian
 
3
 * Copyright (C) 2007-2009  The OpenTyrian Development Team
 
4
 *
 
5
 * This program is free software; you can redistribute it and/or
 
6
 * modify it under the terms of the GNU General Public License
 
7
 * as published by the Free Software Foundation; either version 2
 
8
 * of the License, or (at your option) any later version.
 
9
 *
 
10
 * This program is distributed in the hope that it will be useful,
 
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
13
 * GNU General Public License for more details.
 
14
 *
 
15
 * You should have received a copy of the GNU General Public License
 
16
 * along with this program; if not, write to the Free Software
 
17
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 
18
 */
 
19
#include "backgrnd.h"
 
20
#include "config.h"
 
21
#include "file.h"
 
22
#include "fonthand.h"
 
23
#include "game_menu.h"
 
24
#include "joystick.h"
 
25
#include "keyboard.h"
 
26
#include "loudness.h"
 
27
#include "mainint.h"
 
28
#include "mouse.h"
 
29
#include "musmast.h"
 
30
#include "network.h"
 
31
#include "nortsong.h"
 
32
#include "nortvars.h"
 
33
#include "params.h"
 
34
#include "pcxmast.h"
 
35
#include "picload.h"
 
36
#include "player.h"
 
37
#include "shots.h"
 
38
#include "sprite.h"
 
39
#include "tyrian2.h"
 
40
#include "varz.h"
 
41
#include "vga256d.h"
 
42
#include "video.h"
 
43
 
 
44
#include <assert.h>
 
45
 
 
46
/*** Structs ***/
 
47
struct cube_struct
 
48
{
 
49
        char title[81];
 
50
        char header[13];
 
51
        int face_sprite;
 
52
        char text[90][36];
 
53
        int last_line;
 
54
};
 
55
 
 
56
/*** Globals ***/
 
57
static int joystick_config = 0; // which joystick is being configured in menu
 
58
 
 
59
static JE_word yLoc;
 
60
static JE_shortint yChg;
 
61
static int newPal, curPal, oldPal;
 
62
static JE_boolean quikSave;
 
63
static JE_byte oldMenu;
 
64
static JE_boolean backFromHelp;
 
65
static JE_integer lastDirection;
 
66
static JE_boolean firstMenu9, paletteChanged;
 
67
static JE_MenuChoiceType menuChoices;
 
68
static JE_integer col, colC;
 
69
static JE_byte lastCurSel;
 
70
static JE_integer curMenu;
 
71
static JE_byte curSel[MENU_MAX]; /* [1..maxmenu] */
 
72
static JE_byte curItemType, curItem, cursor;
 
73
static JE_boolean leftPower, rightPower, rightPowerAfford;
 
74
static JE_byte currentCube;
 
75
static JE_boolean keyboardUsed;
 
76
 
 
77
static JE_byte planetAni, planetAniWait;
 
78
static JE_byte currentDotNum, currentDotWait;
 
79
static JE_real navX, navY, newNavX, newNavY;
 
80
static JE_integer tempNavX, tempNavY;
 
81
static JE_byte planetDots[5]; /* [1..5] */
 
82
static JE_integer planetDotX[5][10], planetDotY[5][10]; /* [1..5, 1..10] */
 
83
static PlayerItems old_items[2];  // TODO: should not be global if possible
 
84
 
 
85
static struct cube_struct cube[4];
 
86
 
 
87
static const JE_MenuChoiceType menuChoicesDefault = { 7, 9, 8, 0, 0, 11, (SAVE_FILES_NUM / 2) + 2, 0, 0, 6, 4, 6, 7, 5 };
 
88
static const JE_byte menuEsc[MENU_MAX] = { 0, 1, 1, 1, 2, 3, 3, 1, 8, 0, 0, 11, 3, 0 };
 
89
static const JE_byte itemAvailMap[7] = { 1, 2, 3, 9, 4, 6, 7 };
 
90
static const JE_word planetX[21] = { 200, 150, 240, 300, 270, 280, 320, 260, 220, 150, 160, 210, 80, 240, 220, 180, 310, 330, 150, 240, 200 };
 
91
static const JE_word planetY[21] = {  40,  90,  90,  80, 170,  30,  50, 130, 120, 150, 220, 200, 80,  50, 160,  10,  55,  55,  90,  90,  40 };
 
92
static const uint cube_line_chars = sizeof(*cube->text) - 1;
 
93
static const uint cube_line_width = 150;
 
94
 
 
95
 
 
96
/*** Functions ***/
 
97
static uint *playeritem_map( PlayerItems *items, uint i )
 
98
{
 
99
        uint * const map[] = { &items->ship, &items->weapon[FRONT_WEAPON].id, &items->weapon[REAR_WEAPON].id, &items->shield, &items->generator, &items->sidekick[LEFT_SIDEKICK], &items->sidekick[RIGHT_SIDEKICK] };
 
100
        assert(i < COUNTOF(map));
 
101
        return map[i];
 
102
}
 
103
 
 
104
 
 
105
JE_longint JE_cashLeft( void )
 
106
{
 
107
        JE_longint tempL = player[0].cash;
 
108
        JE_word itemNum = *playeritem_map(&player[0].items, curSel[1] - 2);
 
109
 
 
110
        tempL -= JE_getCost(curSel[1], itemNum);
 
111
 
 
112
        tempW = 0;
 
113
 
 
114
        switch (curSel[1])
 
115
        {
 
116
        case 3:
 
117
        case 4:
 
118
                for (uint i = 1; i < player[0].items.weapon[curSel[1]-3].power; ++i)
 
119
                {
 
120
                        tempW += weaponPort[itemNum].cost * i;
 
121
                        tempL -= tempW;
 
122
                }
 
123
                break;
 
124
        }
 
125
 
 
126
        return tempL;
 
127
}
 
128
 
 
129
void JE_itemScreen( void )
 
130
{
 
131
        bool quit = false;
 
132
 
 
133
        /* SYN: Okay, here's the menu numbers. All are reindexed by -1 from the original code.
 
134
                0: full game menu
 
135
                1: upgrade ship main
 
136
                2: full game options
 
137
                3: play next level
 
138
                4: upgrade ship submenus
 
139
                5: keyboard settings
 
140
                6: load/save menu
 
141
                7: data cube menu
 
142
                8: read data cube
 
143
                9: 2 player arcade game menu
 
144
                10: 1 player arcade game menu
 
145
                11: network game options
 
146
                12: joystick settings
 
147
                13: super tyrian
 
148
        */
 
149
 
 
150
        free_sprite2s(&shapes6);
 
151
        JE_loadCompShapes(&shapes6, '1');  // item sprites
 
152
 
 
153
        load_cubes();
 
154
 
 
155
        VGAScreen = VGAScreenSeg;
 
156
 
 
157
        memcpy(menuChoices, menuChoicesDefault, sizeof(menuChoices));
 
158
 
 
159
        play_song(songBuy);
 
160
 
 
161
        JE_loadPic(VGAScreen, 1, false);
 
162
 
 
163
        curPal = 1;
 
164
        newPal = 0;
 
165
 
 
166
        JE_showVGA();
 
167
 
 
168
        set_palette(colors, 0, 255);
 
169
 
 
170
        col = 1;
 
171
        gameLoaded = false;
 
172
        curItemType = 1;
 
173
        cursor = 1;
 
174
        curItem = 0;
 
175
 
 
176
        for (unsigned int i = 0; i < COUNTOF(curSel); ++i)
 
177
                curSel[i] = 2;
 
178
 
 
179
        curMenu = 0;
 
180
 
 
181
        int temp_weapon_power[7]; // assumes there'll never be more than 6 weapons to choose from, 7th is "Done"
 
182
 
 
183
        /* JE: (* Check for where Pitems and Select match up - if no match then add to the itemavail list *) */
 
184
        for (int i = 0; i < 7; i++)
 
185
        {
 
186
                int item = *playeritem_map(&player[0].last_items, i);
 
187
 
 
188
                int slot = 0;
 
189
 
 
190
                for ( ; slot < itemAvailMax[itemAvailMap[i]-1]; ++slot)
 
191
                {
 
192
                        if (itemAvail[itemAvailMap[i]-1][slot] == item)
 
193
                                break;
 
194
                }
 
195
 
 
196
                if (slot == itemAvailMax[itemAvailMap[i]-1])
 
197
                {
 
198
                        itemAvail[itemAvailMap[i]-1][slot] = item;
 
199
                        itemAvailMax[itemAvailMap[i]-1]++;
 
200
                }
 
201
        }
 
202
 
 
203
        memcpy(VGAScreen2->pixels, VGAScreen->pixels, VGAScreen2->pitch * VGAScreen2->h);
 
204
 
 
205
        keyboardUsed = false;
 
206
        firstMenu9 = false;
 
207
        backFromHelp = false;
 
208
 
 
209
        /* JE: Sort items in merchant inventory */
 
210
        for (int x = 0; x < 9; x++)
 
211
        {
 
212
                if (itemAvailMax[x] > 1)
 
213
                {
 
214
                        for (temp = 0; temp < itemAvailMax[x] - 1; temp++)
 
215
                        {
 
216
                                for (temp2 = temp; temp2 < itemAvailMax[x]; temp2++)
 
217
                                {
 
218
                                        if (itemAvail[x][temp] == 0 || (itemAvail[x][temp] > itemAvail[x][temp2] && itemAvail[x][temp2] != 0))
 
219
                                        {
 
220
                                                temp3 = itemAvail[x][temp];
 
221
                                                itemAvail[x][temp] = itemAvail[x][temp2];
 
222
                                                itemAvail[x][temp2] = temp3;
 
223
                                        }
 
224
                                }
 
225
                        }
 
226
                }
 
227
        }
 
228
 
 
229
        do
 
230
        {
 
231
                quit = false;
 
232
 
 
233
                JE_getShipInfo();
 
234
 
 
235
                /* JE: If curMenu==1 and twoPlayerMode is on, then force move to menu 10 */
 
236
                if (curMenu == 0)
 
237
                {
 
238
                        if (twoPlayerMode)
 
239
                                curMenu = 9;
 
240
 
 
241
                        if (isNetworkGame || onePlayerAction)
 
242
                                curMenu = 10;
 
243
 
 
244
                        if (superTyrian)
 
245
                                curMenu = 13;
 
246
                }
 
247
 
 
248
                paletteChanged = false;
 
249
 
 
250
                leftPower = false;
 
251
                rightPower = false;
 
252
 
 
253
                /* SYN: note reindexing... "firstMenu9" refers to Menu 8 here :( */
 
254
                if (curMenu != 8 || firstMenu9)
 
255
                {
 
256
                        memcpy(VGAScreen->pixels, VGAScreen2->pixels, VGAScreen->pitch * VGAScreen->h);
 
257
                }
 
258
 
 
259
                defaultBrightness = -3;
 
260
 
 
261
                if (curMenu == 1 && (curSel[curMenu] == 3 || curSel[curMenu] == 4))
 
262
                {
 
263
                        // reset temp_weapon_power[] every time we select upgrading front or back
 
264
                        const uint item       = player[0].items.weapon[curSel[1] - 3].id,
 
265
                                   item_power = player[0].items.weapon[curSel[1] - 3].power,
 
266
                                   i = curSel[1] - 2;  // 1 or 2 (front or rear)
 
267
 
 
268
                        // set power level of owned weapon
 
269
                        for (int slot = 0; slot < itemAvailMax[itemAvailMap[i]-1]; ++slot)
 
270
                        {
 
271
                                if (itemAvail[itemAvailMap[i]-1][slot] == item)
 
272
                                        temp_weapon_power[slot] = item_power;
 
273
                                else
 
274
                                        temp_weapon_power[slot] = 1;
 
275
                        }
 
276
 
 
277
                        // set power level for "Done"
 
278
                        temp_weapon_power[itemAvailMax[itemAvailMap[i]-1]] = item_power;
 
279
                }
 
280
 
 
281
                /* play next level menu */
 
282
                if (curMenu == 3)
 
283
                {
 
284
                        planetAni = 0;
 
285
                        keyboardUsed = false;
 
286
                        currentDotNum = 0;
 
287
                        currentDotWait = 8;
 
288
                        planetAniWait = 3;
 
289
                        JE_updateNavScreen();
 
290
                }
 
291
 
 
292
                /* Draw menu title for everything but upgrade ship submenus */
 
293
                if (curMenu != 4)
 
294
                {
 
295
                        JE_drawMenuHeader();
 
296
                }
 
297
 
 
298
                /* Draw menu choices for simple menus */
 
299
                if ((curMenu >= 0 && curMenu <= 3) || (curMenu >= 9 && curMenu <= 11) || curMenu == 13)
 
300
                {
 
301
                        JE_drawMenuChoices();
 
302
                }
 
303
 
 
304
                /* Data cube icons */
 
305
                if (curMenu == 0)
 
306
                {
 
307
                        for (int i = 1; i <= cubeMax; i++)
 
308
                        {
 
309
                                blit_sprite_dark(VGAScreen, 190 + i * 18 + 2, 37 + 1, OPTION_SHAPES, 34, false);
 
310
                                blit_sprite(VGAScreen, 190 + i * 18, 37, OPTION_SHAPES, 34);  // data cube
 
311
                        }
 
312
                }
 
313
 
 
314
                /* load/save menu */
 
315
                if (curMenu == 6)
 
316
                {
 
317
                        int min, max;
 
318
 
 
319
                        if (twoPlayerMode)
 
320
                        {
 
321
                                min = 13;
 
322
                                max = 24;
 
323
                        }
 
324
                        else
 
325
                        {
 
326
                                min = 2;
 
327
                                max = 13;
 
328
                        }
 
329
 
 
330
                        for (int x = min; x <= max; x++)
 
331
                        {
 
332
                                /* Highlight if current selection */
 
333
                                temp2 = (x - min + 2 == curSel[curMenu]) ? 15 : 28;
 
334
 
 
335
                                /* Write save game slot */
 
336
                                if (x == max)
 
337
                                        strcpy(tempStr, miscText[6-1]);
 
338
                                else if (saveFiles[x-2].level == 0)
 
339
                                        strcpy(tempStr, miscText[3-1]);
 
340
                                else
 
341
                                        strcpy(tempStr, saveFiles[x-2].name);
 
342
 
 
343
                                int tempY = 38 + (x - min)*11;
 
344
 
 
345
                                JE_textShade(VGAScreen, 163, tempY, tempStr, temp2 / 16, temp2 % 16 - 8, DARKEN);
 
346
 
 
347
                                /* If selected with keyboard, move mouse pointer to match? Or something. */
 
348
                                if (x - min + 2 == curSel[curMenu])
 
349
                                {
 
350
                                        if (keyboardUsed)
 
351
                                                set_mouse_position(305, 38 + (x - min) * 11);
 
352
                                }
 
353
 
 
354
                                if (x < max) /* x == max isn't a save slot */
 
355
                                {
 
356
                                        /* Highlight if current selection */
 
357
                                        temp2 = (x - min + 2 == curSel[curMenu]) ? 252 : 250;
 
358
 
 
359
                                        if (saveFiles[x-2].level == 0)
 
360
                                        {
 
361
                                                strcpy(tempStr, "-----"); /* Empty save slot */
 
362
                                        }
 
363
                                        else
 
364
                                        {
 
365
                                                char buf[20];
 
366
 
 
367
                                                strcpy(tempStr, saveFiles[x-2].levelName);
 
368
 
 
369
                                                snprintf(buf, sizeof buf, "%s%d", miscTextB[1-1], saveFiles[x-2].episode);
 
370
                                                JE_textShade(VGAScreen, 297, tempY, buf, temp2 / 16, temp2 % 16 - 8, DARKEN);
 
371
                                        }
 
372
 
 
373
                                        JE_textShade(VGAScreen, 245, tempY, tempStr, temp2 / 16, temp2 % 16 - 8, DARKEN);
 
374
                                }
 
375
 
 
376
                                JE_drawMenuHeader();
 
377
                        }
 
378
                }
 
379
 
 
380
                /* keyboard settings menu */
 
381
                if (curMenu == 5)
 
382
                {
 
383
                        for (int x = 2; x <= 11; x++)
 
384
                        {
 
385
                                if (x == curSel[curMenu])
 
386
                                {
 
387
                                        temp2 = 15;
 
388
                                        if (keyboardUsed)
 
389
                                                set_mouse_position(305, 38 + (x - 2) * 12);
 
390
                                }
 
391
                                else
 
392
                                {
 
393
                                        temp2 = 28;
 
394
                                }
 
395
 
 
396
                                JE_textShade(VGAScreen, 166, 38 + (x - 2)*12, menuInt[curMenu + 1][x-1], temp2 / 16, temp2 % 16 - 8, DARKEN);
 
397
 
 
398
                                if (x < 10) /* 10 = reset to defaults, 11 = done */
 
399
                                {
 
400
                                        temp2 = (x == curSel[curMenu]) ? 252 : 250;
 
401
                                        JE_textShade(VGAScreen, 236, 38 + (x - 2)*12, SDL_GetKeyName(keySettings[x-2]), temp2 / 16, temp2 % 16 - 8, DARKEN);
 
402
                                }
 
403
                        }
 
404
 
 
405
                        menuChoices[5] = 11;
 
406
                }
 
407
 
 
408
                /* Joystick settings menu */
 
409
                if (curMenu == 12)
 
410
                {
 
411
                        const char *menu_item[] =
 
412
                        {
 
413
                                "JOYSTICK",
 
414
                                "ANALOG AXES",
 
415
                                " SENSITIVITY",
 
416
                                " THRESHOLD",
 
417
                                menuInt[6][1],
 
418
                                menuInt[6][4],
 
419
                                menuInt[6][2],
 
420
                                menuInt[6][3],
 
421
                                menuInt[6][5],
 
422
                                menuInt[6][6],
 
423
                                menuInt[6][7],
 
424
                                menuInt[6][8],
 
425
                                "MENU",
 
426
                                "PAUSE",
 
427
                                menuInt[6][9],
 
428
                                menuInt[6][10]
 
429
                        };
 
430
 
 
431
                        for (uint i = 0; i < COUNTOF(menu_item); i++)
 
432
                        {
 
433
                                int temp = (i == curSel[curMenu] - 2u) ? 15 : 28;
 
434
 
 
435
                                JE_textShade(VGAScreen, 166, 38 + i * 8, menu_item[i], temp / 16, temp % 16 - 8, DARKEN);
 
436
 
 
437
                                temp = (i == curSel[curMenu] - 2u) ? 252 : 250;
 
438
 
 
439
                                char value[30] = "";
 
440
                                if (joysticks == 0 && i < 14) // no joysticks, everything disabled
 
441
                                {
 
442
                                        sprintf(value, "-");
 
443
                                }
 
444
                                else if (i == 0) // joystick number
 
445
                                {
 
446
                                        sprintf(value, "%d", joystick_config + 1);
 
447
                                }
 
448
                                else if (i == 1) // joystick is analog
 
449
                                {
 
450
                                        sprintf(value, "%s", joystick[joystick_config].analog ? "TRUE" : "FALSE");
 
451
                                }
 
452
                                else if (i < 4)  // joystick analog settings
 
453
                                {
 
454
                                        if (!joystick[joystick_config].analog)
 
455
                                                temp -= 3;
 
456
                                        sprintf(value, "%d", i == 2 ? joystick[joystick_config].sensitivity : joystick[joystick_config].threshold);
 
457
                                }
 
458
                                else if (i < 14) // assignments
 
459
                                {
 
460
                                        joystick_assignments_to_string(value, sizeof(value), joystick[joystick_config].assignment[i - 4]);
 
461
                                }
 
462
 
 
463
                                JE_textShade(VGAScreen, 236, 38 + i * 8, value, temp / 16, temp % 16 - 8, DARKEN);
 
464
                        }
 
465
 
 
466
                        menuChoices[curMenu] = COUNTOF(menu_item) + 1;
 
467
                }
 
468
 
 
469
                /* Upgrade weapon submenus, with weapon sim */
 
470
                if (curMenu == 4)
 
471
                {
 
472
                        /* Move cursor until we hit either "Done" or a weapon the player can afford */
 
473
                        while (curSel[4] < menuChoices[4] && JE_getCost(curSel[1], itemAvail[itemAvailMap[curSel[1]-2]-1][curSel[4]-2]) > player[0].cash)
 
474
                        {
 
475
                                curSel[4] += lastDirection;
 
476
                                if (curSel[4] < 2)
 
477
                                        curSel[4] = menuChoices[4];
 
478
                                else if (curSel[4] > menuChoices[4])
 
479
                                        curSel[4] = 2;
 
480
                        }
 
481
 
 
482
                        if (curSel[4] == menuChoices[4])
 
483
                        {
 
484
                                /* If cursor on "Done", use previous weapon */
 
485
                                *playeritem_map(&player[0].items, curSel[1] - 2) = *playeritem_map(&old_items[0], curSel[1] - 2);
 
486
                        }
 
487
                        else
 
488
                        {
 
489
                                /* Otherwise display the selected weapon */
 
490
                                *playeritem_map(&player[0].items, curSel[1] - 2) = itemAvail[itemAvailMap[curSel[1]-2]-1][curSel[4]-2];
 
491
                        }
 
492
 
 
493
                        /* Get power level info for front and rear weapons */
 
494
                        if ((curSel[1] == 3 && curSel[4] < menuChoices[4]) || (curSel[1] == 4 && curSel[4] < menuChoices[4]-1))
 
495
                        {
 
496
                                const uint port = curSel[1] - 3,  // 0 or 1 (front or back)
 
497
                                           item_level = player[0].items.weapon[port].power;
 
498
 
 
499
                                // calculate upgradeCost
 
500
                                JE_getCost(curSel[1], itemAvail[itemAvailMap[curSel[1]-2]-1][curSel[5]-2]);
 
501
 
 
502
                                leftPower  = item_level > 1;  // can downgrade
 
503
                                rightPower = item_level < 11; // can upgrade
 
504
 
 
505
                                if (rightPower)
 
506
                                        rightPowerAfford = JE_cashLeft() >= upgradeCost; // can afford upgrade
 
507
                        }
 
508
                        else
 
509
                        {
 
510
                                /* Nothing else can be upgraded / downgraded */
 
511
                                leftPower = false;
 
512
                                rightPower = false;
 
513
                        }
 
514
 
 
515
                        /* submenu title  e.g., "Left Sidekick" */
 
516
                        JE_dString(VGAScreen, 74 + JE_fontCenter(menuInt[2][curSel[1]-1], FONT_SHAPES), 10, menuInt[2][curSel[1]-1], FONT_SHAPES);
 
517
 
 
518
                        /* Iterate through all submenu options */
 
519
                        for (tempW = 1; tempW < menuChoices[curMenu]; tempW++)
 
520
                        {
 
521
                                int tempY = 40 + (tempW-1) * 26; /* Calculate y position */
 
522
                                uint temp_cost;
 
523
 
 
524
                                /* Is this a item or None/DONE? */
 
525
                                if (tempW < menuChoices[4] - 1)
 
526
                                {
 
527
                                        /* Get base cost for choice */
 
528
                                        temp_cost = JE_getCost(curSel[1], itemAvail[itemAvailMap[curSel[1]-2]-1][tempW-1]);
 
529
                                }
 
530
                                else
 
531
                                {
 
532
                                        /* "None" is free :) */
 
533
                                        temp_cost = 0;
 
534
                                }
 
535
 
 
536
                                int afford_shade = (temp_cost > player[0].cash) ? 4 : 0;  // can player afford current weapon at all
 
537
 
 
538
                                temp = itemAvail[itemAvailMap[curSel[1]-2]-1][tempW-1]; /* Item ID */
 
539
                                switch (curSel[1]-1)
 
540
                                {
 
541
                                        case 1: /* ship */
 
542
                                                if (temp > 90)
 
543
                                                {
 
544
                                                        snprintf(tempStr, sizeof(tempStr), "Custom Ship %d", temp - 90);
 
545
                                                } else {
 
546
                                                        strcpy(tempStr, ships[temp].name);
 
547
                                                }
 
548
                                                break;
 
549
                                        case 2: /* front and rear weapon */
 
550
                                        case 3:
 
551
                                                strcpy(tempStr, weaponPort[temp].name);
 
552
                                                break;
 
553
                                        case 4: /* shields */
 
554
                                                strcpy(tempStr, shields[temp].name);
 
555
                                                break;
 
556
                                        case 5: /* generator */
 
557
                                                strcpy(tempStr, powerSys[temp].name);
 
558
                                                break;
 
559
                                        case 6: /* sidekicks */
 
560
                                        case 7:
 
561
                                                strcpy(tempStr, options[temp].name);
 
562
                                                break;
 
563
                                }
 
564
                                if (tempW == curSel[curMenu]-1)
 
565
                                {
 
566
                                        if (keyboardUsed)
 
567
                                        {
 
568
                                                set_mouse_position(305, tempY + 10);
 
569
                                        }
 
570
                                        temp2 = 15;
 
571
                                } else {
 
572
                                        temp2 = 28;
 
573
                                }
 
574
 
 
575
                                JE_getShipInfo();
 
576
 
 
577
                                /* item-owned marker */
 
578
                                if (temp == *playeritem_map(&old_items[0], curSel[1] - 2) && temp != 0 && tempW != menuChoices[curMenu]-1)
 
579
                                {
 
580
                                        fill_rectangle_xy(VGAScreen, 160, tempY+7, 300, tempY+11, 227);
 
581
                                        blit_sprite2(VGAScreen, 298, tempY+2, shapes6, 247);
 
582
                                }
 
583
 
 
584
                                /* Draw DONE */
 
585
                                if (tempW == menuChoices[curMenu]-1)
 
586
                                {
 
587
                                        strcpy(tempStr, miscText[13]);
 
588
                                }
 
589
                                JE_textShade(VGAScreen, 185, tempY, tempStr, temp2 / 16, temp2 % 16 - 8 - afford_shade, DARKEN);
 
590
 
 
591
                                /* Draw icon if not DONE. NOTE: None is a normal item with a blank icon. */
 
592
                                if (tempW < menuChoices[curMenu]-1)
 
593
                                {
 
594
                                        JE_drawItem(curSel[1]-1, temp, 160, tempY-4);
 
595
                                }
 
596
 
 
597
                                /* Make selected text brigther */
 
598
                                temp2 = (tempW == curSel[curMenu]-1) ? 15 : 28;
 
599
 
 
600
                                /* Draw Cost: if it's not the DONE option */
 
601
                                if (tempW != menuChoices[curMenu]-1)
 
602
                                {
 
603
                                        char buf[20];
 
604
 
 
605
                                        snprintf(buf, sizeof buf, "Cost: %d", temp_cost);
 
606
                                        JE_textShade(VGAScreen, 187, tempY+10, buf, temp2 / 16, temp2 % 16 - 8 - afford_shade, DARKEN);
 
607
                                }
 
608
                        }
 
609
                } /* /weapon upgrade */
 
610
 
 
611
                /* Draw current money and shield/armor bars, when appropriate */
 
612
                /* YKS: Ouch */
 
613
                if (((curMenu <= 2 || curMenu == 5 || curMenu == 6 || curMenu >= 10) && !twoPlayerMode) || (curMenu == 4 && (curSel[1] >= 1 && curSel[1] <= 6)))
 
614
                {
 
615
                        if (curMenu != 4)
 
616
                        {
 
617
                                char buf[20];
 
618
 
 
619
                                snprintf(buf, sizeof buf, "%lu", player[0].cash);
 
620
                                JE_textShade(VGAScreen, 65, 173, buf, 1, 6, DARKEN);
 
621
                        }
 
622
                        JE_barDrawShadow(VGAScreen, 42, 152, 3, 14, player[0].armor, 2, 13);
 
623
                        JE_barDrawShadow(VGAScreen, 104, 152, 2, 14, shields[player[0].items.shield].mpwr * 2, 2, 13);
 
624
                }
 
625
 
 
626
                /* Draw crap on the left side of the screen, i.e. two player scores, ship graphic, etc. */
 
627
                if (((curMenu >= 0 && curMenu <= 2) || curMenu == 5 || curMenu == 6 || curMenu >= 9) || (curMenu == 4 && (curSel[1] == 2 || curSel[1] == 5)))
 
628
                {
 
629
                        if (twoPlayerMode)
 
630
                        {
 
631
                                char buf[50];
 
632
 
 
633
                                for (uint i = 0; i < 2; ++i)
 
634
                                {
 
635
                                        snprintf(buf, sizeof(buf), "%s %lu", miscText[40 + i], player[i].cash);
 
636
                                        JE_textShade(VGAScreen, 25, 50 + 10 * i, buf, 15, 0, FULL_SHADE);
 
637
                                }
 
638
                        }
 
639
                        else if (superArcadeMode != SA_NONE || superTyrian)
 
640
                        {
 
641
                                helpBoxColor = 15;
 
642
                                helpBoxBrightness = 4;
 
643
                                if (!superTyrian)
 
644
                                        JE_helpBox(VGAScreen, 35, 25, superShips[superArcadeMode], 18);
 
645
                                else
 
646
                                        JE_helpBox(VGAScreen, 35, 25, superShips[SA+3], 18);
 
647
                                helpBoxBrightness = 1;
 
648
 
 
649
                                JE_textShade(VGAScreen, 25, 50, superShips[SA+1], 15, 0, FULL_SHADE);
 
650
                                JE_helpBox(VGAScreen,   25, 60, weaponPort[player[0].items.weapon[FRONT_WEAPON].id].name, 22);
 
651
                                JE_textShade(VGAScreen, 25, 120, superShips[SA+2], 15, 0, FULL_SHADE);
 
652
                                JE_helpBox(VGAScreen,   25, 130, special[player[0].items.special].name, 22);
 
653
                        }
 
654
                        else
 
655
                        {
 
656
                                draw_ship_illustration();
 
657
                        }
 
658
                }
 
659
 
 
660
                /* Changing the volume? */
 
661
                if ((curMenu == 2) || (curMenu == 11))
 
662
                {
 
663
                        JE_barDrawShadow(VGAScreen, 225, 70, 1, music_disabled ? 12 : 16, tyrMusicVolume / 12, 3, 13);
 
664
                        JE_barDrawShadow(VGAScreen, 225, 86, 1, samples_disabled ? 12 : 16, fxVolume / 12, 3, 13);
 
665
                }
 
666
 
 
667
                /* 7 is data cubes menu, 8 is reading a data cube, "firstmenu9" refers to menu 8 because of reindexing */
 
668
                if (curMenu == 7 || ( curMenu == 8 && (firstMenu9 || backFromHelp) ) )
 
669
                {
 
670
                        firstMenu9 = false;
 
671
                        menuChoices[7] = cubeMax + 2;
 
672
                        fill_rectangle_xy(VGAScreen, 1, 1, 145, 170, 0);
 
673
 
 
674
                        blit_sprite(VGAScreenSeg, 1, 1, OPTION_SHAPES, 20); /* Portrait area background */
 
675
 
 
676
                        if (curMenu == 7)
 
677
                        {
 
678
                                if (cubeMax == 0)
 
679
                                {
 
680
                                        JE_helpBox(VGAScreen, 166, 80, miscText[16 - 1], 30);
 
681
                                        tempW = 160;
 
682
                                        temp2 = 252;
 
683
                                }
 
684
                                else
 
685
                                {
 
686
                                        for (int x = 1; x <= cubeMax; x++)
 
687
                                        {
 
688
                                                JE_drawCube(VGAScreenSeg, 166, 38 + (x - 1) * 28, 13, 0);
 
689
                                                if (x + 1 == curSel[curMenu])
 
690
                                                {
 
691
                                                        if (keyboardUsed)
 
692
                                                                set_mouse_position(305, 38 + (x - 1) * 28 + 6);
 
693
                                                        temp2 = 252;
 
694
                                                }
 
695
                                                else
 
696
                                                {
 
697
                                                        temp2 = 250;
 
698
                                                }
 
699
 
 
700
                                                helpBoxColor = temp2 / 16;
 
701
                                                helpBoxBrightness = (temp2 % 16) - 8;
 
702
                                                helpBoxShadeType = DARKEN;
 
703
                                                JE_helpBox(VGAScreen, 192, 44 + (x - 1) * 28, cube[x - 1].title, 24);
 
704
                                        }
 
705
                                        int x = cubeMax + 1;
 
706
                                        if (x + 1 == curSel[curMenu])
 
707
                                        {
 
708
                                                if (keyboardUsed)
 
709
                                                        set_mouse_position(305, 38 + (x - 1) * 28 + 6);
 
710
                                                temp2 = 252;
 
711
                                        }
 
712
                                        else
 
713
                                        {
 
714
                                                temp2 = 250;
 
715
                                        }
 
716
                                        tempW = 44 + (x - 1) * 28;
 
717
                                }
 
718
 
 
719
                                JE_textShade(VGAScreen, 172, tempW, miscText[6 - 1], temp2 / 16, (temp2 % 16) - 8, DARKEN);
 
720
                        }
 
721
 
 
722
                        if (curSel[7] < menuChoices[7])
 
723
                        {
 
724
                                const int face_sprite = cube[curSel[7] - 2].face_sprite;
 
725
 
 
726
                                if (face_sprite != -1)
 
727
                                {
 
728
                                        const int face_x = 77 - (sprite(FACE_SHAPES, face_sprite)->width / 2),
 
729
                                                  face_y = 92 - (sprite(FACE_SHAPES, face_sprite)->height / 2);
 
730
 
 
731
                                        blit_sprite(VGAScreenSeg, face_x, face_y, FACE_SHAPES, face_sprite);  // datacube face
 
732
 
 
733
                                        // modify pallete for face
 
734
                                        paletteChanged = true;
 
735
                                        temp2 = facepal[face_sprite];
 
736
                                        newPal = 0;
 
737
 
 
738
                                        for (temp = 1; temp <= 255 - (3 * 16); temp++)
 
739
                                                colors[temp] = palettes[temp2][temp];
 
740
                                }
 
741
                        }
 
742
                }
 
743
 
 
744
                /* 2 player input devices */
 
745
                if (curMenu == 9)
 
746
                {
 
747
                        for (uint i = 0; i < COUNTOF(inputDevice); i++)
 
748
                        {
 
749
                                if (inputDevice[i] > 2 + joysticks)
 
750
                                        inputDevice[i] = inputDevice[i == 0 ? 1 : 0] == 1 ? 2 : 1;
 
751
 
 
752
                                char temp[64];
 
753
                                if (joysticks > 1 && inputDevice[i] > 2)
 
754
                                        sprintf(temp, "%s %d", inputDevices[2], inputDevice[i] - 2);
 
755
                                else
 
756
                                        sprintf(temp, "%s", inputDevices[inputDevice[i] - 1]);
 
757
                                JE_dString(VGAScreen, 186, 38 + 2 * (i + 1) * 16, temp, SMALL_FONT_SHAPES);
 
758
                        }
 
759
                }
 
760
 
 
761
                /* JE: { - Step VI - Help text for current cursor location } */
 
762
 
 
763
                flash = false;
 
764
 
 
765
                /* JE: {Reset player weapons} */
 
766
                memset(shotMultiPos, 0, sizeof(shotMultiPos));
 
767
 
 
768
                JE_drawScore();
 
769
 
 
770
                JE_drawMainMenuHelpText();
 
771
 
 
772
                if (newPal > 0) /* can't reindex this :( */
 
773
                {
 
774
                        curPal = newPal;
 
775
                        memcpy(colors, palettes[newPal - 1], sizeof(colors));
 
776
                        set_palette(palettes[newPal - 1], 0, 255);
 
777
                        newPal = 0;
 
778
                }
 
779
 
 
780
                /* datacube title under face */
 
781
                if ( ( (curMenu == 7) || (curMenu == 8) ) && (curSel[7] < menuChoices[7]) )
 
782
                        JE_textShade (VGAScreen, 75 - JE_textWidth(cube[curSel[7] - 2].header, TINY_FONT) / 2, 173, cube[curSel[7] - 2].header, 14, 3, DARKEN);
 
783
 
 
784
                /* SYN: Everything above was just drawing the screen. In the rest of it, we process
 
785
                   any user input (and do a few other things) */
 
786
 
 
787
                /* SYN: Let's start by getting fresh events from SDL */
 
788
                service_SDL_events(true);
 
789
 
 
790
                if (constantPlay)
 
791
                {
 
792
                        mainLevel = mapSection[mapPNum-1];
 
793
                        jumpSection = true;
 
794
                }
 
795
                else
 
796
                {
 
797
                        do
 
798
                        {
 
799
                        /* Inner loop -- this handles animations on menus that need them and handles
 
800
                           some keyboard events. Events it can't handle end the loop and fall through
 
801
                           to the main keyboard handler below.
 
802
 
 
803
                           Also, I think all timing is handled in here. Somehow. */
 
804
 
 
805
                                NETWORK_KEEP_ALIVE();
 
806
 
 
807
                                mouseCursor = 0;
 
808
 
 
809
                                col += colC;
 
810
                                if (col < -2 || col > 6)
 
811
                                {
 
812
                                        colC = (-1 * colC);
 
813
                                }
 
814
 
 
815
                                // data cube reading
 
816
                                if (curMenu == 8)
 
817
                                {
 
818
                                        if (mouseX > 164 && mouseX < 299 && mouseY > 47 && mouseY < 153)
 
819
                                        {
 
820
                                                if (mouseY > 100)
 
821
                                                        mouseCursor = 2;
 
822
                                                else
 
823
                                                        mouseCursor = 1;
 
824
                                        }
 
825
 
 
826
                                        fill_rectangle_xy(VGAScreen, 160, 49, 310, 158, 228);
 
827
                                        if (yLoc + yChg < 0)
 
828
                                        {
 
829
                                                yChg = 0;
 
830
                                                yLoc = 0;
 
831
                                        }
 
832
 
 
833
                                        yLoc += yChg;
 
834
                                        temp = yLoc / 12;
 
835
                                        temp2 = yLoc % 12;
 
836
                                        tempW = 38 + 12 - temp2;
 
837
                                        temp3 = cube[curSel[7] - 2].last_line;
 
838
 
 
839
                                        for (int x = temp + 1; x <= temp + 10; x++)
 
840
                                        {
 
841
                                                if (x <= temp3)
 
842
                                                {
 
843
                                                        JE_outTextAndDarken(VGAScreen, 161, tempW, cube[curSel[7] - 2].text[x-1], 14, 3, TINY_FONT);
 
844
                                                        tempW += 12;
 
845
                                                }
 
846
                                        }
 
847
 
 
848
                                        fill_rectangle_xy(VGAScreen, 160, 39, 310, 48, 228);
 
849
                                        fill_rectangle_xy(VGAScreen, 160, 157, 310, 166, 228);
 
850
 
 
851
                                        int percent_read = (cube[currentCube].last_line <= 9)
 
852
                                                           ? 100
 
853
                                                           : (yLoc * 100) / ((cube[currentCube].last_line - 9) * 12);
 
854
 
 
855
                                        char buf[20];
 
856
                                        snprintf(buf, sizeof(buf), "%s %d%%", miscText[11], percent_read);
 
857
                                        JE_outTextAndDarken(VGAScreen, 176, 160, buf, 14, 1, TINY_FONT);
 
858
 
 
859
                                        JE_dString(VGAScreen, 260, 160, miscText[12], SMALL_FONT_SHAPES);
 
860
 
 
861
                                        if (temp2 == 0)
 
862
                                                yChg = 0;
 
863
 
 
864
                                        JE_mouseStart();
 
865
 
 
866
                                        JE_showVGA();
 
867
 
 
868
                                        if (backFromHelp)
 
869
                                        {
 
870
                                                fade_palette(colors, 10, 0, 255);
 
871
                                                backFromHelp = false;
 
872
                                        }
 
873
                                        JE_mouseReplace();
 
874
 
 
875
                                        setjasondelay(1);
 
876
                                }
 
877
                                else
 
878
                                {
 
879
                                        /* current menu is not 8 (read data cube) */
 
880
 
 
881
                                        if (curMenu == 3)
 
882
                                        {
 
883
                                                JE_updateNavScreen();
 
884
                                                JE_drawMainMenuHelpText();
 
885
                                                JE_drawMenuHeader();
 
886
                                                JE_drawMenuChoices();
 
887
                                                if (extraGame)
 
888
                                                        JE_dString(VGAScreen, 170, 140, miscText[68 - 1], FONT_SHAPES);
 
889
                                        }
 
890
 
 
891
                                        if (curMenu == 7 && curSel[7] < menuChoices[7])
 
892
                                        {
 
893
                                                /* Draw flashy cube */
 
894
                                                blit_sprite_hv_blend(VGAScreenSeg, 166, 38 + (curSel[7] - 2) * 28, OPTION_SHAPES, 25, 13, col);
 
895
                                        }
 
896
 
 
897
                                        /* IF (curmenu = 5) AND (cursel [2] IN [3, 4, 6, 7, 8]) */
 
898
                                        if (curMenu == 4 && ( curSel[1] == 3 || curSel[1] == 4 || ( curSel[1] >= 6 && curSel[1] <= 8) ) )
 
899
                                        {
 
900
                                                setjasondelay(3);
 
901
                                                JE_weaponSimUpdate();
 
902
                                                JE_drawScore();
 
903
                                                service_SDL_events(false);
 
904
 
 
905
                                                if (newPal > 0)
 
906
                                                {
 
907
                                                        curPal = newPal;
 
908
                                                        set_palette(palettes[newPal - 1], 0, 255);
 
909
                                                        newPal = 0;
 
910
                                                }
 
911
 
 
912
                                                JE_mouseStart();
 
913
 
 
914
                                                if (paletteChanged)
 
915
                                                {
 
916
                                                        set_palette(colors, 0, 255);
 
917
                                                        paletteChanged = false;
 
918
                                                }
 
919
 
 
920
                                                JE_showVGA(); /* SYN: This is where it updates the screen for the weapon sim */
 
921
 
 
922
                                                if (backFromHelp)
 
923
                                                {
 
924
                                                        fade_palette(colors, 10, 0, 255);
 
925
                                                        backFromHelp = false;
 
926
                                                }
 
927
 
 
928
                                                JE_mouseReplace();
 
929
 
 
930
                                        } else { /* current menu is anything but weapon sim or datacube */
 
931
 
 
932
                                                setjasondelay(2);
 
933
 
 
934
                                                JE_drawScore();
 
935
                                                //JE_waitRetrace();  didn't do anything anyway?
 
936
 
 
937
                                                if (newPal > 0)
 
938
                                                {
 
939
                                                        curPal = newPal;
 
940
                                                        set_palette(palettes[newPal - 1], 0, 255);
 
941
                                                        newPal = 0;
 
942
                                                }
 
943
 
 
944
                                                JE_mouseStart();
 
945
 
 
946
                                                if (paletteChanged)
 
947
                                                {
 
948
                                                        set_palette(colors, 0, 255);
 
949
                                                        paletteChanged = false;
 
950
                                                }
 
951
 
 
952
                                                JE_showVGA(); /* SYN: This is the where the screen updates for most menus */
 
953
 
 
954
                                                JE_mouseReplace();
 
955
 
 
956
                                                if (backFromHelp)
 
957
                                                {
 
958
                                                        fade_palette(colors, 10, 0, 255);
 
959
                                                        backFromHelp = false;
 
960
                                                }
 
961
 
 
962
                                        }
 
963
                                }
 
964
 
 
965
                                wait_delay();
 
966
 
 
967
                                push_joysticks_as_keyboard();
 
968
                                service_SDL_events(false);
 
969
                                mouseButton = JE_mousePosition(&mouseX, &mouseY);
 
970
                                inputDetected = newkey || mouseButton > 0;
 
971
 
 
972
                                if (curMenu != 6)
 
973
                                {
 
974
                                        if (keysactive[SDLK_s] && (keysactive[SDLK_LALT] || keysactive[SDLK_RALT]) )
 
975
                                        {
 
976
                                                if (curMenu == 8 || curMenu == 7)
 
977
                                                {
 
978
                                                        curMenu = 0;
 
979
                                                }
 
980
                                                quikSave = true;
 
981
                                                oldMenu = curMenu;
 
982
                                                curMenu = 6;
 
983
                                                performSave = true;
 
984
                                                newPal = 1;
 
985
                                                oldPal = curPal;
 
986
                                        }
 
987
                                        if (keysactive[SDLK_l] && (keysactive[SDLK_LALT] || keysactive[SDLK_RALT]) )
 
988
                                        {
 
989
                                                if (curMenu == 8 || curMenu == 7)
 
990
                                                {
 
991
                                                        curMenu = 0;
 
992
                                                }
 
993
                                                quikSave = true;
 
994
                                                oldMenu = curMenu;
 
995
                                                curMenu = 6;
 
996
                                                performSave = false;
 
997
                                                newPal = 1;
 
998
                                                oldPal = curPal;
 
999
                                        }
 
1000
                                }
 
1001
 
 
1002
                                if (curMenu == 8)
 
1003
                                {
 
1004
                                        if (mouseButton > 0 && mouseCursor >= 1)
 
1005
                                        {
 
1006
                                                inputDetected = false;
 
1007
                                                if (mouseCursor == 1)
 
1008
                                                {
 
1009
                                                        yChg = -1;
 
1010
                                                } else {
 
1011
                                                        yChg = 1;
 
1012
                                                }
 
1013
                                        }
 
1014
 
 
1015
                                        if (keysactive[SDLK_PAGEUP])
 
1016
                                        {
 
1017
                                                yChg = -2;
 
1018
                                                inputDetected = false;
 
1019
                                        }
 
1020
                                        if (keysactive[SDLK_PAGEDOWN])
 
1021
                                        {
 
1022
                                                yChg = 2;
 
1023
                                                inputDetected = false;
 
1024
                                        }
 
1025
 
 
1026
                                        bool joystick_up = false, joystick_down = false;
 
1027
                                        for (int j = 0; j < joysticks; j++)
 
1028
                                        {
 
1029
                                                joystick_up |= joystick[j].direction[0];
 
1030
                                                joystick_down |= joystick[j].direction[2];
 
1031
                                        }
 
1032
 
 
1033
                                        if (keysactive[SDLK_UP] || joystick_up)
 
1034
                                        {
 
1035
                                                yChg = -1;
 
1036
                                                inputDetected = false;
 
1037
                                        }
 
1038
 
 
1039
                                        if (keysactive[SDLK_DOWN] || joystick_down)
 
1040
                                        {
 
1041
                                                yChg = 1;
 
1042
                                                inputDetected = false;
 
1043
                                        }
 
1044
 
 
1045
                                        if (yChg < 0 && yLoc == 0)
 
1046
                                        {
 
1047
                                                yChg = 0;
 
1048
                                        }
 
1049
                                        if (yChg  > 0 && (yLoc / 12) > cube[currentCube].last_line - 10)
 
1050
                                        {
 
1051
                                                yChg = 0;
 
1052
                                        }
 
1053
                                }
 
1054
 
 
1055
                        } while (!inputDetected);
 
1056
                }
 
1057
 
 
1058
                keyboardUsed = false;
 
1059
 
 
1060
                /* The rest of this just grabs input events, handles them, then proceeds on. */
 
1061
 
 
1062
                if (mouseButton > 0)
 
1063
                {
 
1064
                        lastDirection = 1;
 
1065
 
 
1066
                        mouseButton = JE_mousePosition(&mouseX, &mouseY);
 
1067
 
 
1068
                        if (curMenu == 7 && cubeMax == 0)
 
1069
                        {
 
1070
                                curMenu = 0;
 
1071
                                JE_playSampleNum(S_SPRING);
 
1072
                                newPal = 1;
 
1073
                                JE_wipeKey();
 
1074
                        }
 
1075
 
 
1076
                        if (curMenu == 8)
 
1077
                        {
 
1078
                                if ((mouseX > 258) && (mouseX < 290) && (mouseY > 159) && (mouseY < 171))
 
1079
                                {
 
1080
                                        curMenu = 7;
 
1081
                                        JE_playSampleNum(S_SPRING);
 
1082
                                }
 
1083
                        }
 
1084
 
 
1085
                        if (curMenu == 2 || curMenu == 11)
 
1086
                        {
 
1087
                                if ((mouseX >= (225 - 4)) && (mouseY >= 70) && (mouseY <= 82))
 
1088
                                {
 
1089
                                        if (music_disabled)
 
1090
                                        {
 
1091
                                                music_disabled = false;
 
1092
                                                restart_song();
 
1093
                                        }
 
1094
 
 
1095
                                        curSel[2] = 4;
 
1096
 
 
1097
                                        tyrMusicVolume = (mouseX - (225 - 4)) / 4 * 12;
 
1098
                                        if (tyrMusicVolume > 255)
 
1099
                                                tyrMusicVolume = 255;
 
1100
                                }
 
1101
 
 
1102
                                if ((mouseX >= (225 - 4)) && (mouseY >= 86) && (mouseY <= 98))
 
1103
                                {
 
1104
                                        samples_disabled = false;
 
1105
 
 
1106
                                        curSel[2] = 5;
 
1107
 
 
1108
                                        fxVolume = (mouseX - (225 - 4)) / 4 * 12;
 
1109
                                        if (fxVolume > 255)
 
1110
                                                fxVolume = 255;
 
1111
                                }
 
1112
 
 
1113
                                JE_calcFXVol();
 
1114
 
 
1115
                                set_volume(tyrMusicVolume, fxVolume);
 
1116
 
 
1117
                                JE_playSampleNum(S_CURSOR);
 
1118
                        }
 
1119
 
 
1120
                        if ((mouseY > 20) && (mouseX > 170) && (mouseX < 308) && (curMenu != 8))
 
1121
                        {
 
1122
                                const JE_byte mouseSelectionY[MENU_MAX] = { 16, 16, 16, 16, 26, 12, 11, 28, 0, 16, 16, 16, 8, 16 };
 
1123
 
 
1124
                                int selection = (mouseY - 38) / mouseSelectionY[curMenu]+2;
 
1125
 
 
1126
                                if (curMenu == 9)
 
1127
                                {
 
1128
                                        if (selection > 5)
 
1129
                                                selection--;
 
1130
                                        if (selection > 3)
 
1131
                                                selection--;
 
1132
                                }
 
1133
 
 
1134
                                if (curMenu == 0)
 
1135
                                {
 
1136
                                        if (selection > 7)
 
1137
                                                selection = 7;
 
1138
                                }
 
1139
 
 
1140
                                // is play next level screen?
 
1141
                                if (curMenu == 3)
 
1142
                                {
 
1143
                                        if (selection == menuChoices[curMenu] + 1)
 
1144
                                                selection = menuChoices[curMenu];
 
1145
                                }
 
1146
 
 
1147
                                if (selection <= menuChoices[curMenu])
 
1148
                                {
 
1149
                                        if ((curMenu == 4) && (selection == menuChoices[4]))
 
1150
                                        {
 
1151
                                                player[0].cash = JE_cashLeft();
 
1152
                                                curMenu = 1;
 
1153
                                                JE_playSampleNum(S_ITEM);
 
1154
                                        }
 
1155
                                        else
 
1156
                                        {
 
1157
                                                JE_playSampleNum(S_CLICK);
 
1158
                                                if (curSel[curMenu] == selection)
 
1159
                                                {
 
1160
                                                        JE_menuFunction(curSel[curMenu]);
 
1161
                                                }
 
1162
                                                else
 
1163
                                                {
 
1164
                                                        if ((curMenu == 4) && (JE_getCost(curSel[1], itemAvail[itemAvailMap[curSel[2]-1]][selection-2]) > player[0].cash))
 
1165
                                                        {
 
1166
                                                                JE_playSampleNum(S_CLINK);
 
1167
                                                        }
 
1168
                                                        else
 
1169
                                                        {
 
1170
                                                                if (curSel[1] == 4)
 
1171
                                                                        player[0].weapon_mode = 1;
 
1172
 
 
1173
                                                                curSel[curMenu] = selection;
 
1174
                                                        }
 
1175
 
 
1176
                                                        // in front or rear weapon upgrade screen?
 
1177
                                                        if ((curMenu == 4) && ((curSel[1] == 3) || (curSel[1] == 4)))
 
1178
                                                                player[0].items.weapon[curSel[1]-3].power = temp_weapon_power[curSel[4]-2];
 
1179
                                                }
 
1180
                                        }
 
1181
                                }
 
1182
 
 
1183
                                wait_noinput(false, true, false);
 
1184
                        }
 
1185
 
 
1186
                        if ((curMenu == 4) && ((curSel[1] == 3) || (curSel[1] == 4)))
 
1187
                        {
 
1188
                                if ((mouseX >= 23) && (mouseX <= 36) && (mouseY >= 149) && (mouseY <= 168))
 
1189
                                {
 
1190
                                        JE_playSampleNum(S_CURSOR);
 
1191
                                        switch (curSel[1])
 
1192
                                        {
 
1193
                                        case 3:
 
1194
                                        case 4:
 
1195
                                                if (leftPower)
 
1196
                                                        player[0].items.weapon[curSel[1]-3].power = --temp_weapon_power[curSel[4]-2];
 
1197
                                                else
 
1198
                                                        JE_playSampleNum(S_CLINK);
 
1199
 
 
1200
                                                break;
 
1201
                                        }
 
1202
                                        wait_noinput(false, true, false);
 
1203
                                }
 
1204
 
 
1205
                                if ((mouseX >= 119) && (mouseX <= 131) && (mouseY >= 149) && (mouseY <= 168))
 
1206
                                {
 
1207
                                        JE_playSampleNum(S_CURSOR);
 
1208
                                        switch (curSel[1])
 
1209
                                        {
 
1210
                                        case 3:
 
1211
                                        case 4:
 
1212
                                                if (rightPower && rightPowerAfford)
 
1213
                                                        player[0].items.weapon[curSel[1]-3].power = ++temp_weapon_power[curSel[4]-2];
 
1214
                                                else
 
1215
                                                        JE_playSampleNum(S_CLINK);
 
1216
 
 
1217
                                                break;
 
1218
                                        }
 
1219
                                        wait_noinput(false, true, false);
 
1220
                                }
 
1221
                        }
 
1222
                }
 
1223
                else if (newkey)
 
1224
                {
 
1225
                        switch (lastkey_sym)
 
1226
                        {
 
1227
                        case SDLK_SLASH:
 
1228
                                // if in rear weapon upgrade screen
 
1229
                                if ( (curMenu == 4) && (curSel[1] == 4))
 
1230
                                {
 
1231
                                        // cycle weapon modes
 
1232
                                        if (++player[0].weapon_mode > weaponPort[player[0].items.weapon[REAR_WEAPON].id].opnum)
 
1233
                                                player[0].weapon_mode = 1;
 
1234
                                }
 
1235
                                break;
 
1236
 
 
1237
                        case SDLK_SPACE:
 
1238
                        case SDLK_RETURN:
 
1239
                                keyboardUsed = true;
 
1240
 
 
1241
                                // if front or rear weapon, update "Done" power level
 
1242
                                if (curMenu == 4 && (curSel[1] == 3 || curSel[1] == 4))
 
1243
                                        temp_weapon_power[itemAvailMax[itemAvailMap[curSel[1]-2]-1]] = player[0].items.weapon[curSel[1]-3].power;
 
1244
 
 
1245
                                JE_menuFunction(curSel[curMenu]);
 
1246
                                break;
 
1247
 
 
1248
                        case SDLK_ESCAPE:
 
1249
                                keyboardUsed = true;
 
1250
 
 
1251
                                JE_playSampleNum(S_SPRING);
 
1252
                                if ( (curMenu == 6) && quikSave)
 
1253
                                {
 
1254
                                        curMenu = oldMenu;
 
1255
                                        newPal = oldPal;
 
1256
                                }
 
1257
                                else if (menuEsc[curMenu] == 0)
 
1258
                                {
 
1259
                                        if (JE_quitRequest())
 
1260
                                        {
 
1261
                                                gameLoaded = true;
 
1262
                                                mainLevel = 0;
 
1263
                                        }
 
1264
                                }
 
1265
                                else
 
1266
                                {
 
1267
                                        if (curMenu == 4)  // leaving upgrade menu without buying
 
1268
                                        {
 
1269
                                                player[0].items = old_items[0];
 
1270
                                                curSel[4] = lastCurSel;
 
1271
                                                player[0].cash = JE_cashLeft();
 
1272
                                        }
 
1273
 
 
1274
                                        if (curMenu != 8) // not data cube
 
1275
                                                newPal = 1;
 
1276
 
 
1277
                                        curMenu = menuEsc[curMenu] - 1;
 
1278
                                }
 
1279
                                break;
 
1280
 
 
1281
                        case SDLK_F1:
 
1282
                                if (!isNetworkGame)
 
1283
                                {
 
1284
                                        JE_helpSystem(2);
 
1285
                                        fade_black(10);
 
1286
 
 
1287
                                        play_song(songBuy);
 
1288
 
 
1289
                                        JE_loadPic(VGAScreen, 1, false);
 
1290
                                        newPal = 1;
 
1291
 
 
1292
                                        switch (curMenu)
 
1293
                                        {
 
1294
                                        case 3:
 
1295
                                                newPal = 18;
 
1296
                                                break;
 
1297
                                        case 7:
 
1298
                                        case 8:
 
1299
                                                break;
 
1300
                                        }
 
1301
 
 
1302
                                        memcpy(VGAScreen2->pixels, VGAScreen->pixels, VGAScreen2->pitch * VGAScreen2->h);
 
1303
 
 
1304
                                        curPal = newPal;
 
1305
                                        memcpy(colors, palettes[newPal-1], sizeof(colors));
 
1306
                                        JE_showVGA();
 
1307
                                        newPal = 0;
 
1308
                                        backFromHelp = true;
 
1309
                                }
 
1310
                                break;
 
1311
 
 
1312
                        case SDLK_UP:
 
1313
                                keyboardUsed = true;
 
1314
                                lastDirection = -1;
 
1315
 
 
1316
                                if (curMenu != 8) // not data cube
 
1317
                                        JE_playSampleNum(S_CURSOR);
 
1318
 
 
1319
                                curSel[curMenu]--;
 
1320
                                if (curSel[curMenu] < 2)
 
1321
                                        curSel[curMenu] = menuChoices[curMenu];
 
1322
 
 
1323
                                // if in front or rear weapon upgrade screen
 
1324
                                if (curMenu == 4 && (curSel[1] == 3 || curSel[1] == 4))
 
1325
                                {
 
1326
                                        player[0].items.weapon[curSel[1]-3].power = temp_weapon_power[curSel[4]-2];
 
1327
                                        if (curSel[curMenu] == 4)
 
1328
                                                player[0].weapon_mode = 1;
 
1329
                                }
 
1330
 
 
1331
                                // if joystick config, skip disabled items when digital
 
1332
                                if (curMenu == 12 && joysticks > 0 && !joystick[joystick_config].analog && curSel[curMenu] == 5)
 
1333
                                        curSel[curMenu] = 3;
 
1334
 
 
1335
                                break;
 
1336
 
 
1337
                        case SDLK_DOWN:
 
1338
                                keyboardUsed = true;
 
1339
                                lastDirection = 1;
 
1340
 
 
1341
                                if (curMenu != 8) // not data cube
 
1342
                                        JE_playSampleNum(S_CURSOR);
 
1343
 
 
1344
                                curSel[curMenu]++;
 
1345
                                if (curSel[curMenu] > menuChoices[curMenu])
 
1346
                                        curSel[curMenu] = 2;
 
1347
 
 
1348
                                // if in front or rear weapon upgrade screen
 
1349
                                if (curMenu == 4 && (curSel[1] == 3 || curSel[1] == 4))
 
1350
                                {
 
1351
                                        player[0].items.weapon[curSel[1]-3].power = temp_weapon_power[curSel[4]-2];
 
1352
                                        if (curSel[curMenu] == 4)
 
1353
                                                player[0].weapon_mode = 1;
 
1354
                                }
 
1355
 
 
1356
                                // if in joystick config, skip disabled items when digital
 
1357
                                if (curMenu == 12 && joysticks > 0 && !joystick[joystick_config].analog && curSel[curMenu] == 4)
 
1358
                                        curSel[curMenu] = 6;
 
1359
 
 
1360
                                break;
 
1361
 
 
1362
                        case SDLK_HOME:
 
1363
                                if (curMenu == 8) // data cube
 
1364
                                        yLoc = 0;
 
1365
                                break;
 
1366
 
 
1367
                        case SDLK_END:
 
1368
                                if (curMenu == 8) // data cube
 
1369
                                        yLoc = (cube[currentCube].last_line - 9) * 12;
 
1370
                                break;
 
1371
 
 
1372
                        case SDLK_LEFT:
 
1373
                                if (curMenu == 12) // joystick settings menu
 
1374
                                {
 
1375
                                        if (joysticks > 0)
 
1376
                                        {
 
1377
                                                switch (curSel[curMenu])
 
1378
                                                {
 
1379
                                                        case 2:
 
1380
                                                                if (joystick_config == 0)
 
1381
                                                                        joystick_config = joysticks;
 
1382
                                                                joystick_config--;
 
1383
                                                                break;
 
1384
                                                        case 3:
 
1385
                                                                joystick[joystick_config].analog = !joystick[joystick_config].analog;
 
1386
                                                                break;
 
1387
                                                        case 4:
 
1388
                                                                if (joystick[joystick_config].sensitivity == 0)
 
1389
                                                                        joystick[joystick_config].sensitivity = 10;
 
1390
                                                                else
 
1391
                                                                        joystick[joystick_config].sensitivity--;
 
1392
                                                                break;
 
1393
                                                        case 5:
 
1394
                                                                if (joystick[joystick_config].threshold == 0)
 
1395
                                                                        joystick[joystick_config].threshold = 10;
 
1396
                                                                else
 
1397
                                                                        joystick[joystick_config].threshold--;
 
1398
                                                                break;
 
1399
                                                        default:
 
1400
                                                                break;
 
1401
                                                }
 
1402
                                        }
 
1403
                                }
 
1404
 
 
1405
                                if (curMenu == 9)
 
1406
                                {
 
1407
                                        switch (curSel[curMenu])
 
1408
                                        {
 
1409
                                        case 3:
 
1410
                                        case 4:
 
1411
                                                JE_playSampleNum(S_CURSOR);
 
1412
 
 
1413
                                                int temp = curSel[curMenu] - 3;
 
1414
                                                do {
 
1415
                                                        if (joysticks == 0)
 
1416
                                                        {
 
1417
                                                                inputDevice[temp == 0 ? 1 : 0] = inputDevice[temp]; // swap controllers
 
1418
                                                        }
 
1419
                                                        if (inputDevice[temp] <= 1)
 
1420
                                                        {
 
1421
                                                                inputDevice[temp] = 2 + joysticks;
 
1422
                                                        } else {
 
1423
                                                                inputDevice[temp]--;
 
1424
                                                        }
 
1425
                                                } while (inputDevice[temp] == inputDevice[temp == 0 ? 1 : 0]);
 
1426
                                                break;
 
1427
                                        }
 
1428
                                }
 
1429
 
 
1430
                                if (curMenu == 2 || curMenu == 4  || curMenu == 11)
 
1431
                                {
 
1432
                                        JE_playSampleNum(S_CURSOR);
 
1433
                                }
 
1434
 
 
1435
                                switch (curMenu)
 
1436
                                {
 
1437
                                case 2:
 
1438
                                case 11:
 
1439
                                        switch (curSel[curMenu])
 
1440
                                        {
 
1441
                                        case 4:
 
1442
                                                JE_changeVolume(&tyrMusicVolume, -12, &fxVolume, 0);
 
1443
                                                if (music_disabled)
 
1444
                                                {
 
1445
                                                        music_disabled = false;
 
1446
                                                        restart_song();
 
1447
                                                }
 
1448
                                                break;
 
1449
                                        case 5:
 
1450
                                                JE_changeVolume(&tyrMusicVolume, 0, &fxVolume, -12);
 
1451
                                                samples_disabled = false;
 
1452
                                                break;
 
1453
                                        }
 
1454
                                        break;
 
1455
                                case 4:
 
1456
                                        switch (curSel[1])
 
1457
                                        {
 
1458
                                        case 3:
 
1459
                                        case 4:
 
1460
                                                if (leftPower)
 
1461
                                                        player[0].items.weapon[curSel[1]-3].power = --temp_weapon_power[curSel[4]-2];
 
1462
                                                else
 
1463
                                                        JE_playSampleNum(S_CLINK);
 
1464
 
 
1465
                                                break;
 
1466
                                        }
 
1467
                                        break;
 
1468
                                }
 
1469
                                break;
 
1470
 
 
1471
                        case SDLK_RIGHT:
 
1472
                                if (curMenu == 12) // joystick settings menu
 
1473
                                {
 
1474
                                        if (joysticks > 0)
 
1475
                                        {
 
1476
                                                switch (curSel[curMenu])
 
1477
                                                {
 
1478
                                                        case 2:
 
1479
                                                                joystick_config++;
 
1480
                                                                joystick_config %= joysticks;
 
1481
                                                                break;
 
1482
                                                        case 3:
 
1483
                                                                joystick[joystick_config].analog = !joystick[joystick_config].analog;
 
1484
                                                                break;
 
1485
                                                        case 4:
 
1486
                                                                joystick[joystick_config].sensitivity++;
 
1487
                                                                joystick[joystick_config].sensitivity %= 11;
 
1488
                                                                break;
 
1489
                                                        case 5:
 
1490
                                                                joystick[joystick_config].threshold++;
 
1491
                                                                joystick[joystick_config].threshold %= 11;
 
1492
                                                                break;
 
1493
                                                        default:
 
1494
                                                                break;
 
1495
                                                }
 
1496
                                        }
 
1497
                                }
 
1498
 
 
1499
                                if (curMenu == 9)
 
1500
                                {
 
1501
                                        switch (curSel[curMenu])
 
1502
                                        {
 
1503
                                        case 3:
 
1504
                                        case 4:
 
1505
                                                JE_playSampleNum(S_CURSOR);
 
1506
 
 
1507
                                                int temp = curSel[curMenu] - 3;
 
1508
                                                do {
 
1509
                                                        if (joysticks == 0)
 
1510
                                                        {
 
1511
                                                                inputDevice[temp == 0 ? 1 : 0] = inputDevice[temp]; // swap controllers
 
1512
                                                        }
 
1513
                                                        if (inputDevice[temp] >= 2 + joysticks)
 
1514
                                                        {
 
1515
                                                                inputDevice[temp] = 1;
 
1516
                                                        } else {
 
1517
                                                                inputDevice[temp]++;
 
1518
                                                        }
 
1519
                                                } while (inputDevice[temp] == inputDevice[temp == 0 ? 1 : 0]);
 
1520
                                                break;
 
1521
                                        }
 
1522
                                }
 
1523
 
 
1524
                                if (curMenu == 2 || curMenu == 4  || curMenu == 11)
 
1525
                                {
 
1526
                                        JE_playSampleNum(S_CURSOR);
 
1527
                                }
 
1528
 
 
1529
                                switch (curMenu)
 
1530
                                {
 
1531
                                case 2:
 
1532
                                case 11:
 
1533
                                        switch (curSel[curMenu])
 
1534
                                        {
 
1535
                                        case 4:
 
1536
                                                JE_changeVolume(&tyrMusicVolume, 12, &fxVolume, 0);
 
1537
                                                if (music_disabled)
 
1538
                                                {
 
1539
                                                        music_disabled = false;
 
1540
                                                        restart_song();
 
1541
                                                }
 
1542
                                                break;
 
1543
                                        case 5:
 
1544
                                                JE_changeVolume(&tyrMusicVolume, 0, &fxVolume, 12);
 
1545
                                                samples_disabled = false;
 
1546
                                                break;
 
1547
                                        }
 
1548
                                        break;
 
1549
                                case 4:
 
1550
                                        switch (curSel[1])
 
1551
                                        {
 
1552
                                        case 3:
 
1553
                                        case 4:
 
1554
                                                if (rightPower && rightPowerAfford)
 
1555
                                                        player[0].items.weapon[curSel[1]-3].power = ++temp_weapon_power[curSel[4]-2];
 
1556
                                                else
 
1557
                                                        JE_playSampleNum(S_CLINK);
 
1558
 
 
1559
                                                break;
 
1560
                                        }
 
1561
                                        break;
 
1562
                                }
 
1563
                                break;
 
1564
 
 
1565
                        default:
 
1566
                                break;
 
1567
                        }
 
1568
                }
 
1569
 
 
1570
        } while (!(quit || gameLoaded || jumpSection));
 
1571
 
 
1572
#ifdef WITH_NETWORK
 
1573
        if (!quit && isNetworkGame)
 
1574
        {
 
1575
                JE_barShade(VGAScreen, 3, 3, 316, 196);
 
1576
                JE_barShade(VGAScreen, 1, 1, 318, 198);
 
1577
                JE_dString(VGAScreen, 10, 160, "Waiting for other player.", SMALL_FONT_SHAPES);
 
1578
 
 
1579
                network_prepare(PACKET_WAITING);
 
1580
                network_send(4);  // PACKET_WAITING
 
1581
 
 
1582
                while (true)
 
1583
                {
 
1584
                        service_SDL_events(false);
 
1585
                        JE_showVGA();
 
1586
 
 
1587
                        if (packet_in[0] && SDLNet_Read16(&packet_in[0]->data[0]) == PACKET_WAITING)
 
1588
                        {
 
1589
                                network_update();
 
1590
                                break;
 
1591
                        }
 
1592
 
 
1593
                        network_update();
 
1594
                        network_check();
 
1595
 
 
1596
                        SDL_Delay(16);
 
1597
                }
 
1598
 
 
1599
                network_state_reset();
 
1600
        }
 
1601
 
 
1602
        if (isNetworkGame)
 
1603
        {
 
1604
                while (!network_is_sync())
 
1605
                {
 
1606
                        service_SDL_events(false);
 
1607
                        JE_showVGA();
 
1608
 
 
1609
                        network_check();
 
1610
                        SDL_Delay(16);
 
1611
                }
 
1612
        }
 
1613
#endif
 
1614
 
 
1615
        if (gameLoaded)
 
1616
                fade_black(10);
 
1617
}
 
1618
 
 
1619
void draw_ship_illustration( void )
 
1620
{
 
1621
        // full of evil hardcoding
 
1622
 
 
1623
        // ship
 
1624
        {
 
1625
                assert(player[0].items.ship > 0);
 
1626
 
 
1627
                const int sprite_id = (player[0].items.ship < COUNTOF(ships))  // shipedit ships get a default
 
1628
                                      ? ships[player[0].items.ship].bigshipgraphic - 1
 
1629
                                      : 31;
 
1630
 
 
1631
                const int ship_x[6] = { 31, 0, 0, 0, 35, 31 },
 
1632
                          ship_y[6] = { 36, 0, 0, 0, 33, 35 };
 
1633
 
 
1634
                const int x = ship_x[sprite_id - 27],
 
1635
                          y = ship_y[sprite_id - 27];
 
1636
 
 
1637
                blit_sprite(VGAScreenSeg, x, y, OPTION_SHAPES, sprite_id);
 
1638
        }
 
1639
 
 
1640
        // generator
 
1641
        {
 
1642
                assert(player[0].items.generator > 0 && player[0].items.generator < 7);
 
1643
 
 
1644
                const int sprite_id = (player[0].items.generator == 1)  // generator 1 and generator 2 have the same sprite
 
1645
                                      ? player[0].items.generator + 15
 
1646
                                      : player[0].items.generator + 14;
 
1647
 
 
1648
                const int generator_x[5] = { 62, 64, 67, 66, 63 },
 
1649
                          generator_y[5] = { 84, 85, 86, 84, 97 };
 
1650
                const int x = generator_x[sprite_id - 16],
 
1651
                          y = generator_y[sprite_id - 16];
 
1652
 
 
1653
                blit_sprite(VGAScreenSeg, x, y, WEAPON_SHAPES, sprite_id);
 
1654
        }
 
1655
 
 
1656
        const int weapon_sprites[43] =
 
1657
        {
 
1658
                -1,  0,  1,  2,  3,  4,  5,  6,  7,  8,
 
1659
                 9, 10, 11, 21,  5, 13, -1, 14, 15,  0,
 
1660
                14,  9,  8,  2, 15,  0, 13,  0,  8,  8,
 
1661
                11,  1,  0,  0,  0,  0,  0,  0,  0,  0,
 
1662
                 0,  2,  1
 
1663
        };
 
1664
 
 
1665
        // front weapon
 
1666
        if (player[0].items.weapon[FRONT_WEAPON].id > 0)
 
1667
        {
 
1668
                const int front_weapon_xy_list[43] =
 
1669
                {
 
1670
                         -1,  4,  9,  3,  8,  2,  5, 10,  1, -1,
 
1671
                         -1, -1, -1,  7,  8, -1, -1,  0, -1,  4,
 
1672
                          0, -1, -1,  3, -1,  4, -1,  4, -1, -1,
 
1673
                         -1,  9,  0,  0,  0,  0,  0,  0,  0,  0,
 
1674
                          0,  3,  9
 
1675
                };
 
1676
 
 
1677
                const int front_weapon_x[12] = { 59, 66, 66, 54, 61, 51, 58, 51, 61, 52, 53, 58 };
 
1678
                const int front_weapon_y[12] = { 38, 53, 41, 36, 48, 35, 41, 35, 53, 41, 39, 31 };
 
1679
                const int x = front_weapon_x[front_weapon_xy_list[player[0].items.weapon[FRONT_WEAPON].id]],
 
1680
                          y = front_weapon_y[front_weapon_xy_list[player[0].items.weapon[FRONT_WEAPON].id]];
 
1681
 
 
1682
                blit_sprite(VGAScreenSeg, x, y, WEAPON_SHAPES, weapon_sprites[player[0].items.weapon[FRONT_WEAPON].id]);  // ship illustration: front weapon
 
1683
        }
 
1684
 
 
1685
        // rear weapon
 
1686
        if (player[0].items.weapon[REAR_WEAPON].id > 0)
 
1687
        {
 
1688
                const int rear_weapon_xy_list[43] =
 
1689
                {
 
1690
                        -1, -1, -1, -1, -1, -1, -1, -1, -1,  0,
 
1691
                         1,  2,  3, -1,  4,  5, -1, -1,  6, -1,
 
1692
                        -1,  1,  0, -1,  6, -1,  5, -1,  0,  0,
 
1693
                         3,  0,  0,  0,  0,  0,  0,  0,  0,  0,
 
1694
                         0, -1, -1
 
1695
                };
 
1696
 
 
1697
                const int rear_weapon_x[7] = { 41, 27,  49,  43, 51, 39, 41 };
 
1698
                const int rear_weapon_y[7] = { 92, 92, 113, 102, 97, 96, 76 };
 
1699
                const int x = rear_weapon_x[rear_weapon_xy_list[player[0].items.weapon[REAR_WEAPON].id]],
 
1700
                          y = rear_weapon_y[rear_weapon_xy_list[player[0].items.weapon[REAR_WEAPON].id]];
 
1701
 
 
1702
                blit_sprite(VGAScreenSeg, x, y, WEAPON_SHAPES, weapon_sprites[player[0].items.weapon[REAR_WEAPON].id]);
 
1703
        }
 
1704
 
 
1705
        // sidekicks
 
1706
        JE_drawItem(6, player[0].items.sidekick[LEFT_SIDEKICK], 3, 84);
 
1707
        JE_drawItem(7, player[0].items.sidekick[RIGHT_SIDEKICK], 129, 84);
 
1708
 
 
1709
        // shield
 
1710
        blit_sprite_hv(VGAScreenSeg, 28, 23, OPTION_SHAPES, 26, 15, shields[player[0].items.shield].mpwr - 10);
 
1711
}
 
1712
 
 
1713
void load_cubes( void )
 
1714
{
 
1715
        for (int cube_slot = 0; cube_slot < cubeMax; ++cube_slot)
 
1716
        {
 
1717
                memset(cube[cube_slot].text, 0, sizeof(cube->text));
 
1718
 
 
1719
                load_cube(cube_slot, cubeList[cube_slot]);
 
1720
        }
 
1721
}
 
1722
 
 
1723
bool load_cube( int cube_slot, int cube_index )
 
1724
{
 
1725
        FILE *f = dir_fopen_die(data_dir(), cube_file, "rb");
 
1726
 
 
1727
        char buf[256];
 
1728
 
 
1729
        // seek to the cube
 
1730
        while (cube_index > 0)
 
1731
        {
 
1732
                read_encrypted_pascal_string(buf, sizeof(buf), f);
 
1733
                if (buf[0] == '*')
 
1734
                        --cube_index;
 
1735
 
 
1736
                if (feof(f))
 
1737
                {
 
1738
                        fclose(f);
 
1739
 
 
1740
                        return false;
 
1741
                }
 
1742
        }
 
1743
 
 
1744
        str_pop_int(&buf[4], &cube[cube_slot].face_sprite);
 
1745
        --cube[cube_slot].face_sprite;
 
1746
 
 
1747
        read_encrypted_pascal_string(cube[cube_slot].title, sizeof(cube[cube_slot].title), f);
 
1748
        read_encrypted_pascal_string(cube[cube_slot].header, sizeof(cube[cube_slot].header), f);
 
1749
 
 
1750
        uint line = 0, line_chars = 0, line_width = 0;
 
1751
 
 
1752
        // for each line of decrypted text, split the line into words
 
1753
        // and add them individually to the lines of wrapped text
 
1754
        for (; ; )
 
1755
        {
 
1756
                read_encrypted_pascal_string(buf, sizeof(buf), f);
 
1757
 
 
1758
                // end of data
 
1759
                if (feof(f) || buf[0] == '*')
 
1760
                        break;
 
1761
 
 
1762
                // new paragraph
 
1763
                if (strlen(buf) == 0)
 
1764
                {
 
1765
                        if (line_chars == 0)
 
1766
                                line += 4;  // subsequent new paragaphs indicate 4-line break
 
1767
                        else
 
1768
                                ++line;
 
1769
                        line_chars = 0;
 
1770
                        line_width = 0;
 
1771
 
 
1772
                        continue;
 
1773
                }
 
1774
 
 
1775
                uint word_start = 0;
 
1776
                for (uint i = 0; ; ++i)
 
1777
                {
 
1778
                        bool end_of_line = (buf[i] == '\0'),
 
1779
                             end_of_word = end_of_line || (buf[i] == ' ');
 
1780
 
 
1781
                        if (end_of_word)
 
1782
                        {
 
1783
                                buf[i] = '\0';
 
1784
 
 
1785
                                char *word = &buf[word_start];
 
1786
                                word_start = i + 1;
 
1787
 
 
1788
                                uint word_chars = strlen(word),
 
1789
                                     word_width = JE_textWidth(word, TINY_FONT);
 
1790
 
 
1791
                                // word won't fit; no can do
 
1792
                                if (word_chars > cube_line_chars || word_width > cube_line_width)
 
1793
                                        break;
 
1794
 
 
1795
                                bool prepend_space = true;
 
1796
 
 
1797
                                line_chars += word_chars + (prepend_space ? 1 : 0);
 
1798
                                line_width += word_width + (prepend_space ? 6 : 0);
 
1799
 
 
1800
                                // word won't fit on current line; use next
 
1801
                                if (line_chars > cube_line_chars || line_width > cube_line_width)
 
1802
                                {
 
1803
                                        ++line;
 
1804
                                        line_chars = word_chars;
 
1805
                                        line_width = word_width;
 
1806
 
 
1807
                                        prepend_space = false;
 
1808
                                }
 
1809
 
 
1810
                                // append word
 
1811
                                if (line < COUNTOF(cube->text))
 
1812
                                {
 
1813
                                        if (prepend_space)
 
1814
                                                strcat(cube[cube_slot].text[line], " ");
 
1815
                                        strcat(cube[cube_slot].text[line], word);
 
1816
 
 
1817
                                        // track last line with text
 
1818
                                        cube[cube_slot].last_line = line + 1;
 
1819
                                }
 
1820
                        }
 
1821
 
 
1822
                        if (end_of_line)
 
1823
                                break;
 
1824
                }
 
1825
        }
 
1826
 
 
1827
        fclose(f);
 
1828
 
 
1829
        return true;
 
1830
}
 
1831
 
 
1832
void JE_drawItem( JE_byte itemType, JE_word itemNum, JE_word x, JE_word y )
 
1833
{
 
1834
        JE_word tempW = 0;
 
1835
 
 
1836
        if (itemNum > 0)
 
1837
        {
 
1838
                switch (itemType)
 
1839
                {
 
1840
                        case 2:
 
1841
                        case 3:
 
1842
                                tempW = weaponPort[itemNum].itemgraphic;
 
1843
                                break;
 
1844
                        case 5:
 
1845
                                tempW = powerSys[itemNum].itemgraphic;
 
1846
                                break;
 
1847
                        case 6:
 
1848
                        case 7:
 
1849
                                tempW = options[itemNum].itemgraphic;
 
1850
                                break;
 
1851
                        case 4:
 
1852
                                tempW = shields[itemNum].itemgraphic;
 
1853
                                break;
 
1854
                }
 
1855
 
 
1856
                if (itemType == 1)
 
1857
                {
 
1858
                        if (itemNum > 90)
 
1859
                        {
 
1860
                                shipGrPtr = &shapes9;
 
1861
                                shipGr = JE_SGr(itemNum - 90, &shipGrPtr);
 
1862
                                blit_sprite2x2(VGAScreen, x, y, *shipGrPtr, shipGr);
 
1863
                        }
 
1864
                        else
 
1865
                        {
 
1866
                                blit_sprite2x2(VGAScreen, x, y, shapes9, ships[itemNum].shipgraphic);
 
1867
                        }
 
1868
                }
 
1869
                else if (tempW > 0)
 
1870
                {
 
1871
                        blit_sprite2x2(VGAScreen, x, y, shapes6, tempW);
 
1872
                }
 
1873
        }
 
1874
}
 
1875
 
 
1876
void JE_drawMenuHeader( void )
 
1877
{
 
1878
        switch (curMenu)
 
1879
        {
 
1880
                case 8:
 
1881
                        strcpy(tempStr, cube[curSel[7]-2].header);
 
1882
                        break;
 
1883
                case 7:
 
1884
                        strcpy(tempStr, menuInt[1][1]);
 
1885
                        break;
 
1886
                case 6:
 
1887
                        strcpy(tempStr, menuInt[3][performSave + 1]);
 
1888
                        break;
 
1889
                default:
 
1890
                        strcpy(tempStr, menuInt[curMenu + 1][0]);
 
1891
                        break;
 
1892
        }
 
1893
        JE_dString(VGAScreen, 74 + JE_fontCenter(tempStr, FONT_SHAPES), 10, tempStr, FONT_SHAPES);
 
1894
}
 
1895
 
 
1896
void JE_drawMenuChoices( void )
 
1897
{
 
1898
        JE_byte x;
 
1899
        char *str;
 
1900
 
 
1901
        for (x = 2; x <= menuChoices[curMenu]; x++)
 
1902
        {
 
1903
                int tempY = 38 + (x-1) * 16;
 
1904
 
 
1905
                if (curMenu == 0)
 
1906
                {
 
1907
                        if (x == 7)
 
1908
                        {
 
1909
                                tempY += 16;
 
1910
                        }
 
1911
                }
 
1912
 
 
1913
                if (curMenu == 9)
 
1914
                {
 
1915
                        if (x > 3)
 
1916
                        {
 
1917
                                tempY += 16;
 
1918
                        }
 
1919
                        if (x > 4)
 
1920
                        {
 
1921
                                tempY += 16;
 
1922
                        }
 
1923
                }
 
1924
 
 
1925
                if (!(curMenu == 3 && x == menuChoices[curMenu]))
 
1926
                {
 
1927
                        tempY -= 16;
 
1928
                }
 
1929
 
 
1930
                str = malloc(strlen(menuInt[curMenu + 1][x-1])+2);
 
1931
                if (curSel[curMenu] == x)
 
1932
                {
 
1933
                        str[0] = '~';
 
1934
                        strcpy(str+1, menuInt[curMenu + 1][x-1]);
 
1935
                } else {
 
1936
                        strcpy(str, menuInt[curMenu + 1][x-1]);
 
1937
                }
 
1938
                JE_dString(VGAScreen, 166, tempY, str, SMALL_FONT_SHAPES);
 
1939
                free(str);
 
1940
 
 
1941
                if (keyboardUsed && curSel[curMenu] == x)
 
1942
                {
 
1943
                        set_mouse_position(305, tempY + 6);
 
1944
                }
 
1945
        }
 
1946
}
 
1947
 
 
1948
void JE_updateNavScreen( void )
 
1949
{
 
1950
        JE_byte x;
 
1951
 
 
1952
        /* minor issues: */
 
1953
        /* TODO: The scroll to the new planet is too fast, I think */
 
1954
        /* TODO: The starting coordinates for the scrolling effect may be wrong, the
 
1955
           yellowish planet below Tyrian isn't visible for as many frames as in the
 
1956
           original. */
 
1957
 
 
1958
        tempNavX = roundf(navX);
 
1959
        tempNavY = roundf(navY);
 
1960
        fill_rectangle_xy(VGAScreen, 19, 16, 135, 169, 2);
 
1961
        JE_drawNavLines(true);
 
1962
        JE_drawNavLines(false);
 
1963
        JE_drawDots();
 
1964
 
 
1965
        for (x = 0; x < 11; x++)
 
1966
                JE_drawPlanet(x);
 
1967
 
 
1968
        for (x = 0; x < menuChoices[3]-1; x++)
 
1969
        {
 
1970
                if (mapPlanet[x] > 11)
 
1971
                        JE_drawPlanet(mapPlanet[x] - 1);
 
1972
        }
 
1973
 
 
1974
        if (mapOrigin > 11)
 
1975
                JE_drawPlanet(mapOrigin - 1);
 
1976
 
 
1977
        blit_sprite(VGAScreenSeg, 0, 0, OPTION_SHAPES, 28);  // navigation screen interface
 
1978
 
 
1979
        if (curSel[3] < menuChoices[3])
 
1980
        {
 
1981
                const unsigned int origin_x_offset = sprite(PLANET_SHAPES, PGR[mapOrigin-1]-1)->width / 2,
 
1982
                                   origin_y_offset = sprite(PLANET_SHAPES, PGR[mapOrigin-1]-1)->height / 2,
 
1983
                                   dest_x_offset = sprite(PLANET_SHAPES, PGR[mapPlanet[curSel[3]-2] - 1]-1)->width / 2,
 
1984
                                   dest_y_offset = sprite(PLANET_SHAPES, PGR[mapPlanet[curSel[3]-2] - 1]-1)->height / 2;
 
1985
 
 
1986
                newNavX = (planetX[mapOrigin-1] - origin_x_offset
 
1987
                          + planetX[mapPlanet[curSel[3]-2] - 1] - dest_x_offset) / 2.0f;
 
1988
                newNavY = (planetY[mapOrigin-1] - origin_y_offset
 
1989
                          + planetY[mapPlanet[curSel[3]-2] - 1] - dest_y_offset) / 2.0f;
 
1990
        }
 
1991
 
 
1992
        navX = navX + (newNavX - navX) / 2.0f;
 
1993
        navY = navY + (newNavY - navY) / 2.0f;
 
1994
 
 
1995
        if (abs(newNavX - navX) < 1)
 
1996
                navX = newNavX;
 
1997
        if (abs(newNavY - navY) < 1)
 
1998
                navY = newNavY;
 
1999
 
 
2000
        fill_rectangle_xy(VGAScreen, 314, 0, 319, 199, 230);
 
2001
 
 
2002
        if (planetAniWait > 0)
 
2003
        {
 
2004
                planetAniWait--;
 
2005
        }
 
2006
        else
 
2007
        {
 
2008
                planetAni++;
 
2009
                if (planetAni > 14)
 
2010
                        planetAni = 0;
 
2011
                planetAniWait = 3;
 
2012
        }
 
2013
 
 
2014
        if (currentDotWait > 0)
 
2015
        {
 
2016
                currentDotWait--;
 
2017
        }
 
2018
        else
 
2019
        {
 
2020
                if (currentDotNum < planetDots[curSel[3]-2])
 
2021
                        currentDotNum++;
 
2022
                currentDotWait = 5;
 
2023
        }
 
2024
}
 
2025
 
 
2026
void JE_drawLines( SDL_Surface *surface, JE_boolean dark )
 
2027
{
 
2028
        JE_byte x, y;
 
2029
        JE_integer tempX, tempY;
 
2030
        JE_integer tempX2, tempY2;
 
2031
        JE_word tempW, tempW2;
 
2032
 
 
2033
        tempX2 = -10;
 
2034
        tempY2 = 0;
 
2035
 
 
2036
        tempW = 0;
 
2037
        for (x = 0; x < 20; x++)
 
2038
        {
 
2039
                tempW += 15;
 
2040
                tempX = tempW - tempX2;
 
2041
 
 
2042
                if (tempX > 18 && tempX < 135)
 
2043
                {
 
2044
                        if (dark)
 
2045
                        {
 
2046
                                JE_rectangle(surface, tempX + 1, 0, tempX + 1, 199, 32+3);
 
2047
                        } else {
 
2048
                                JE_rectangle(surface, tempX, 0, tempX, 199, 32+5);
 
2049
                        }
 
2050
                }
 
2051
        }
 
2052
 
 
2053
        tempW = 0;
 
2054
        for (y = 0; y < 20; y++)
 
2055
        {
 
2056
                tempW += 15;
 
2057
                tempY = tempW - tempY2;
 
2058
 
 
2059
                if (tempY > 15 && tempY < 169)
 
2060
                {
 
2061
                        if (dark)
 
2062
                        {
 
2063
                                JE_rectangle(surface, 0, tempY + 1, 319, tempY + 1, 32+3);
 
2064
                        } else {
 
2065
                                JE_rectangle(surface, 0, tempY, 319, tempY, 32+5);
 
2066
                        }
 
2067
 
 
2068
                        tempW2 = 0;
 
2069
 
 
2070
                        for (x = 0; x < 20; x++)
 
2071
                        {
 
2072
                                tempW2 += 15;
 
2073
                                tempX = tempW2 - tempX2;
 
2074
                                if (tempX > 18 && tempX < 135)
 
2075
                                {
 
2076
                                        JE_pix3(surface, tempX, tempY, 32+6);
 
2077
                                }
 
2078
                        }
 
2079
                }
 
2080
        }
 
2081
}
 
2082
 
 
2083
/* SYN: This was originally PROC drawlines... yes, there were two different procs called
 
2084
   drawlines in different scopes in the same file. Dammit, Jason, why do you do this to me? */
 
2085
 
 
2086
void JE_drawNavLines( JE_boolean dark )
 
2087
{
 
2088
        JE_byte x, y;
 
2089
        JE_integer tempX, tempY;
 
2090
        JE_integer tempX2, tempY2;
 
2091
        JE_word tempW, tempW2;
 
2092
 
 
2093
        tempX2 = tempNavX >> 1;
 
2094
        tempY2 = tempNavY >> 1;
 
2095
 
 
2096
        tempW = 0;
 
2097
        for (x = 1; x <= 20; x++)
 
2098
        {
 
2099
                tempW += 15;
 
2100
                tempX = tempW - tempX2;
 
2101
 
 
2102
                if (tempX > 18 && tempX < 135)
 
2103
                {
 
2104
                        if (dark)
 
2105
                                JE_rectangle(VGAScreen, tempX + 1, 16, tempX + 1, 169, 1);
 
2106
                        else
 
2107
                                JE_rectangle(VGAScreen, tempX, 16, tempX, 169, 5);
 
2108
                }
 
2109
        }
 
2110
 
 
2111
        tempW = 0;
 
2112
        for (y = 1; y <= 20; y++)
 
2113
        {
 
2114
                tempW += 15;
 
2115
                tempY = tempW - tempY2;
 
2116
 
 
2117
                if (tempY > 15 && tempY < 169)
 
2118
                {
 
2119
                        if (dark)
 
2120
                                JE_rectangle(VGAScreen, 19, tempY + 1, 135, tempY + 1, 1);
 
2121
                        else
 
2122
                                JE_rectangle(VGAScreen, 8, tempY, 160, tempY, 5);
 
2123
 
 
2124
                        tempW2 = 0;
 
2125
 
 
2126
                        for (x = 0; x < 20; x++)
 
2127
                        {
 
2128
                                tempW2 += 15;
 
2129
                                tempX = tempW2 - tempX2;
 
2130
                                if (tempX > 18 && tempX < 135)
 
2131
                                        JE_pix3(VGAScreen, tempX, tempY, 7);
 
2132
                        }
 
2133
                }
 
2134
        }
 
2135
}
 
2136
 
 
2137
void JE_drawDots( void )
 
2138
{
 
2139
        JE_byte x, y;
 
2140
        JE_integer tempX, tempY;
 
2141
 
 
2142
        for (x = 0; x < mapPNum; x++)
 
2143
        {
 
2144
                for (y = 0; y < planetDots[x]; y++)
 
2145
                {
 
2146
                        tempX = planetDotX[x][y] - tempNavX + 66 - 2;
 
2147
                        tempY = planetDotY[x][y] - tempNavY + 85 - 2;
 
2148
                        if (tempX > 0 && tempX < 140 && tempY > 0 && tempY < 168)
 
2149
                                blit_sprite(VGAScreenSeg, tempX, tempY, OPTION_SHAPES, (x == curSel[3]-2 && y < currentDotNum) ? 30 : 29);  // navigation dots
 
2150
                }
 
2151
        }
 
2152
}
 
2153
 
 
2154
void JE_drawPlanet( JE_byte planetNum )
 
2155
{
 
2156
        JE_integer tempZ = PGR[planetNum]-1,
 
2157
                   tempX = planetX[planetNum] + 66 - tempNavX - sprite(PLANET_SHAPES, tempZ)->width / 2,
 
2158
                   tempY = planetY[planetNum] + 85 - tempNavY - sprite(PLANET_SHAPES, tempZ)->height / 2;
 
2159
 
 
2160
        if (tempX > -7 && tempX + sprite(PLANET_SHAPES, tempZ)->width < 170 && tempY > 0 && tempY < 160)
 
2161
        {
 
2162
                if (PAni[planetNum])
 
2163
                        tempZ += planetAni;
 
2164
 
 
2165
                blit_sprite_dark(VGAScreenSeg, tempX + 3, tempY + 3, PLANET_SHAPES, tempZ, false);
 
2166
                blit_sprite(VGAScreenSeg, tempX, tempY, PLANET_SHAPES, tempZ);  // planets
 
2167
        }
 
2168
}
 
2169
 
 
2170
void JE_scaleBitmap( SDL_Surface *dst_bitmap, const SDL_Surface *src_bitmap,  int x1, int y1, int x2, int y2 )
 
2171
{
 
2172
        /* This function scales one screen and writes the result to another.
 
2173
         *  The only code that calls it is the code run when you select 'ship
 
2174
         * specs' from the main menu.
 
2175
         *
 
2176
         * Originally this used fixed point math.  I haven't seen that in ages :).
 
2177
         * But we're well past the point of needing that.*/
 
2178
 
 
2179
        assert(src_bitmap != NULL && dst_bitmap != NULL);
 
2180
        assert(x1 >= 0 && y1 >= 0 && x2 < src_bitmap->pitch && y2 < src_bitmap->h);
 
2181
 
 
2182
        int w = x2 - x1 + 1,
 
2183
            h = y2 - y1 + 1;
 
2184
        float base_skip_w = src_bitmap->pitch / (float)w,
 
2185
              base_skip_h = src_bitmap->h / (float)h;
 
2186
        float cumulative_skip_w, cumulative_skip_h;
 
2187
 
 
2188
 
 
2189
        //Okay, it's time to loop through and add bits of A to a rectangle in B
 
2190
        Uint8 *dst = dst_bitmap->pixels;  /* 8-bit specific */
 
2191
        const Uint8 *src, *src_w;  /* 8-bit specific */
 
2192
 
 
2193
        dst += y1 * dst_bitmap->pitch + x1;
 
2194
        cumulative_skip_h = 0;
 
2195
 
 
2196
        for (int i = 0; i < h; i++)
 
2197
        {
 
2198
                //this sets src to the beginning of our desired line
 
2199
                src = src_w = (Uint8 *)(src_bitmap->pixels) + (src_bitmap->w * ((unsigned int)cumulative_skip_h));
 
2200
                cumulative_skip_h += base_skip_h;
 
2201
                cumulative_skip_w = 0;
 
2202
 
 
2203
                for (int j = 0; j < w; j++)
 
2204
                {
 
2205
                        //copy and move pointers
 
2206
                        *dst = *src;
 
2207
                        dst++;
 
2208
 
 
2209
                        cumulative_skip_w += base_skip_w;
 
2210
                        src = src_w + ((unsigned int)cumulative_skip_w); //value is floored
 
2211
                }
 
2212
 
 
2213
                dst += dst_bitmap->pitch - w;
 
2214
        }
 
2215
}
 
2216
 
 
2217
void JE_initWeaponView( void )
 
2218
{
 
2219
        fill_rectangle_xy(VGAScreen, 8, 8, 144, 177, 0);
 
2220
 
 
2221
        player[0].sidekick[LEFT_SIDEKICK].x = 72 - 15;
 
2222
        player[0].sidekick[LEFT_SIDEKICK].y = 120;
 
2223
        player[0].sidekick[RIGHT_SIDEKICK].x = 72 + 15;
 
2224
        player[0].sidekick[RIGHT_SIDEKICK].y = 120;
 
2225
 
 
2226
        player[0].x = 72;
 
2227
        player[0].y = 110;
 
2228
        player[0].delta_x_shot_move = 0;
 
2229
        player[0].delta_y_shot_move = 0;
 
2230
        player[0].last_x_explosion_follow = 72;
 
2231
        player[0].last_y_explosion_follow = 110;
 
2232
        power = 500;
 
2233
        lastPower = 500;
 
2234
 
 
2235
        memset(shotAvail, 0, sizeof(shotAvail));
 
2236
 
 
2237
        memset(shotRepeat, 1, sizeof(shotRepeat));
 
2238
        memset(shotMultiPos, 0, sizeof(shotMultiPos));
 
2239
 
 
2240
        initialize_starfield();
 
2241
}
 
2242
 
 
2243
void JE_computeDots( void )
 
2244
{
 
2245
        JE_integer tempX, tempY;
 
2246
        JE_longint distX, distY;
 
2247
        JE_byte x, y;
 
2248
 
 
2249
        for (x = 0; x < mapPNum; x++)
 
2250
        {
 
2251
                distX = (int)(planetX[mapPlanet[x]-1]) - (int)(planetX[mapOrigin-1]);
 
2252
                distY = (int)(planetY[mapPlanet[x]-1]) - (int)(planetY[mapOrigin-1]);
 
2253
                tempX = abs(distX) + abs(distY);
 
2254
 
 
2255
                if (tempX != 0)
 
2256
                {
 
2257
                        planetDots[x] = roundf(sqrtf(sqrtf((distX * distX) + (distY * distY)))) - 1;
 
2258
                } else {
 
2259
                        planetDots[x] = 0;
 
2260
                }
 
2261
 
 
2262
                if (planetDots[x] > 10)
 
2263
                {
 
2264
                        planetDots[x] = 10;
 
2265
                }
 
2266
 
 
2267
                for (y = 0; y < planetDots[x]; y++)
 
2268
                {
 
2269
                        tempX = JE_partWay(planetX[mapOrigin-1], planetX[mapPlanet[x]-1], planetDots[x], y);
 
2270
                        tempY = JE_partWay(planetY[mapOrigin-1], planetY[mapPlanet[x]-1], planetDots[x], y);
 
2271
                        /* ??? Why does it use temp? =P */
 
2272
                        planetDotX[x][y] = tempX;
 
2273
                        planetDotY[x][y] = tempY;
 
2274
                }
 
2275
        }
 
2276
}
 
2277
 
 
2278
JE_integer JE_partWay( JE_integer start, JE_integer finish, JE_byte dots, JE_byte dist )
 
2279
{
 
2280
        return (finish - start) / (dots + 2) * (dist + 1) + start;
 
2281
}
 
2282
 
 
2283
void JE_doShipSpecs( void )
 
2284
{
 
2285
        /* This function is called whenever you select 'ship specs' in the
 
2286
         * game menu.  It draws the nice green tech screen and scales it onto
 
2287
         * the main window.  To do this we need two temp buffers, so we're going
 
2288
         * to use VGAScreen and game_screen for the purpose (making things more
 
2289
         * complex than they would be if we just malloc'd, but faster)
 
2290
         *
 
2291
         * Originally the whole system was pretty oddly designed.  So I changed it.
 
2292
         * Currently drawFunkyScreen creates the image, scaleInPicture draws it,
 
2293
         * and doFunkyScreen ties everything together.  Before it was more like
 
2294
         * an oddly designed, unreusable, global sharing hierarchy. */
 
2295
 
 
2296
        //create the image we want
 
2297
        wait_noinput(true, true, true);
 
2298
        JE_drawShipSpecs(game_screen, VGAScreen2);
 
2299
 
 
2300
        //reset VGAScreen2, which we clobbered
 
2301
        JE_loadPic(VGAScreen2, 1, false);
 
2302
 
 
2303
        //draw it
 
2304
        JE_playSampleNum(16);
 
2305
        JE_scaleInPicture(VGAScreen, game_screen);
 
2306
        wait_input(true, true, true);
 
2307
}
 
2308
 
 
2309
void JE_drawMainMenuHelpText( void )
 
2310
{
 
2311
        char tempStr[67];
 
2312
        JE_byte temp;
 
2313
 
 
2314
        temp = curSel[curMenu] - 2;
 
2315
        if (curMenu == 12) // joystick settings menu help
 
2316
        {
 
2317
                int help[16] = { 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 15, 24, 11 };
 
2318
                memcpy(tempStr, mainMenuHelp[help[curSel[curMenu] - 2]], sizeof(tempStr));
 
2319
        }
 
2320
        else if (curMenu < 3 || curMenu == 9 || curMenu > 10)
 
2321
        {
 
2322
                memcpy(tempStr, mainMenuHelp[(menuHelp[curMenu][temp])-1], sizeof(tempStr));
 
2323
        }
 
2324
        else if (curMenu == 5 && curSel[5] == 10)
 
2325
        {
 
2326
                memcpy(tempStr, mainMenuHelp[25-1], sizeof(tempStr));
 
2327
        }
 
2328
        else if (leftPower || rightPower)
 
2329
        {
 
2330
                memcpy(tempStr, mainMenuHelp[24-1], sizeof(tempStr));
 
2331
        }
 
2332
        else if ( (temp == menuChoices[curMenu] - 1) || ( (curMenu == 7) && (cubeMax == 0) ) )
 
2333
        {
 
2334
                memcpy(tempStr, mainMenuHelp[12-1], sizeof(tempStr));
 
2335
        }
 
2336
        else
 
2337
        {
 
2338
                memcpy(tempStr, mainMenuHelp[17 + curMenu - 3], sizeof(tempStr));
 
2339
        }
 
2340
        
 
2341
        JE_textShade(VGAScreen, 10, 187, tempStr, 14, 1, DARKEN);
 
2342
}
 
2343
 
 
2344
JE_boolean JE_quitRequest( void )
 
2345
{
 
2346
        bool quit_selected = true, done = false;
 
2347
 
 
2348
        JE_clearKeyboard();
 
2349
        JE_wipeKey();
 
2350
        wait_noinput(true, true, true);
 
2351
 
 
2352
        JE_barShade(VGAScreen, 65, 55, 255, 155);
 
2353
 
 
2354
        while (!done)
 
2355
        {
 
2356
                Uint8 col = 8;
 
2357
                int colC = 1;
 
2358
 
 
2359
                do
 
2360
                {
 
2361
                        service_SDL_events(true);
 
2362
                        setjasondelay(4);
 
2363
 
 
2364
                        blit_sprite(VGAScreen, 50, 50, OPTION_SHAPES, 35);  // message box
 
2365
                        JE_textShade(VGAScreen, 70, 60, miscText[28], 0, 5, FULL_SHADE);
 
2366
                        JE_helpBox(VGAScreen, 70, 90, miscText[30], 30);
 
2367
 
 
2368
                        col += colC;
 
2369
                        if (col > 8 || col < 2)
 
2370
                                colC = -colC;
 
2371
 
 
2372
                        int temp_x, temp_c;
 
2373
 
 
2374
                        temp_x = 54 + 45 - (JE_textWidth(miscText[9], FONT_SHAPES) / 2);
 
2375
                        temp_c = quit_selected ? col - 12 : -5;
 
2376
 
 
2377
                        JE_outTextAdjust(VGAScreen, temp_x, 128, miscText[9], 15, temp_c, FONT_SHAPES, true);
 
2378
 
 
2379
                        temp_x = 149 + 45 - (JE_textWidth(miscText[10], FONT_SHAPES) / 2);
 
2380
                        temp_c = !quit_selected ? col - 12 : -5;
 
2381
 
 
2382
                        JE_outTextAdjust(VGAScreen, temp_x, 128, miscText[10], 15, temp_c, FONT_SHAPES, true);
 
2383
 
 
2384
                        if (has_mouse)
 
2385
                        {
 
2386
                                JE_mouseStart();
 
2387
                                JE_showVGA();
 
2388
                                JE_mouseReplace();
 
2389
                        }
 
2390
                        else
 
2391
                        {
 
2392
                                JE_showVGA();
 
2393
                        }
 
2394
 
 
2395
                        wait_delay();
 
2396
 
 
2397
                        push_joysticks_as_keyboard();
 
2398
                        service_SDL_events(false);
 
2399
 
 
2400
                } while (!newkey && !mousedown);
 
2401
 
 
2402
                if (mousedown)
 
2403
                {
 
2404
                        if (lastmouse_y > 123 && lastmouse_y < 149)
 
2405
                        {
 
2406
                                if (lastmouse_x > 56 && lastmouse_x < 142)
 
2407
                                {
 
2408
                                        quit_selected = true;
 
2409
                                        done = true;
 
2410
                                }
 
2411
                                else if (lastmouse_x > 151 && lastmouse_x < 237)
 
2412
                                {
 
2413
                                        quit_selected = false;
 
2414
                                        done = true;
 
2415
                                }
 
2416
                        }
 
2417
                        mousedown = false;
 
2418
                }
 
2419
                else if (newkey)
 
2420
                {
 
2421
                        switch (lastkey_sym)
 
2422
                        {
 
2423
                                case SDLK_LEFT:
 
2424
                                case SDLK_RIGHT:
 
2425
                                case SDLK_TAB:
 
2426
                                        quit_selected = !quit_selected;
 
2427
                                        JE_playSampleNum(S_CURSOR);
 
2428
                                        break;
 
2429
                                case SDLK_RETURN:
 
2430
                                case SDLK_SPACE:
 
2431
                                        done = true;
 
2432
                                        break;
 
2433
                                case SDLK_ESCAPE:
 
2434
                                        quit_selected = false;
 
2435
                                        done = true;
 
2436
                                        break;
 
2437
                                default:
 
2438
                                        break;
 
2439
                        }
 
2440
                }
 
2441
        }
 
2442
 
 
2443
        JE_playSampleNum(quit_selected ? S_SPRING : S_CLICK);
 
2444
 
 
2445
#ifdef WITH_NETWORK
 
2446
        if (isNetworkGame && quit_selected)
 
2447
        {
 
2448
                network_prepare(PACKET_QUIT);
 
2449
                network_send(4);  // PACKET QUIT
 
2450
 
 
2451
                network_tyrian_halt(0, true);
 
2452
        }
 
2453
#endif
 
2454
 
 
2455
        return quit_selected;
 
2456
}
 
2457
 
 
2458
void JE_genItemMenu( JE_byte itemNum )
 
2459
{
 
2460
        menuChoices[4] = itemAvailMax[itemAvailMap[itemNum - 2] - 1] + 2;
 
2461
 
 
2462
        temp3 = 2;
 
2463
        temp2 = *playeritem_map(&player[0].items, itemNum - 2);
 
2464
 
 
2465
        strcpy(menuInt[5][0], menuInt[2][itemNum - 1]);
 
2466
 
 
2467
        for (tempW = 0; tempW < itemAvailMax[itemAvailMap[itemNum - 2] - 1]; tempW++)
 
2468
        {
 
2469
                temp = itemAvail[itemAvailMap[itemNum - 2] - 1][tempW];
 
2470
                switch (itemNum)
 
2471
                {
 
2472
                case 2:
 
2473
                        strcpy(tempStr, ships[temp].name);
 
2474
                        break;
 
2475
                case 3:
 
2476
                case 4:
 
2477
                        strcpy(tempStr, weaponPort[temp].name);
 
2478
                        break;
 
2479
                case 5:
 
2480
                        strcpy(tempStr, shields[temp].name);
 
2481
                        break;
 
2482
                case 6:
 
2483
                        strcpy(tempStr, powerSys[temp].name);
 
2484
                        break;
 
2485
                case 7:
 
2486
                case 8:
 
2487
                        strcpy(tempStr, options[temp].name);
 
2488
                        break;
 
2489
                }
 
2490
                if (temp == temp2)
 
2491
                {
 
2492
                        temp3 = tempW + 2;
 
2493
                }
 
2494
                strcpy(menuInt[5][tempW], tempStr);
 
2495
        }
 
2496
 
 
2497
        strcpy(menuInt[5][tempW], miscText[13]);
 
2498
 
 
2499
        curSel[4] = temp3;
 
2500
}
 
2501
 
 
2502
void JE_scaleInPicture( SDL_Surface *dst, const SDL_Surface *src )
 
2503
{
 
2504
        for (int i = 2; i <= 160; i += 2)
 
2505
        {
 
2506
                if (JE_anyButton()) { break; }
 
2507
 
 
2508
                JE_scaleBitmap(dst, src, 160 - i, 0, 160 + i - 1, 100 + roundf(i * 0.625f) - 1);
 
2509
                JE_showVGA();
 
2510
 
 
2511
                SDL_Delay(1);
 
2512
        }
 
2513
}
 
2514
 
 
2515
 
 
2516
void JE_drawScore( void )
 
2517
{
 
2518
        char cl[24];
 
2519
        if (curMenu == 4)
 
2520
        {
 
2521
                sprintf(cl, "%d", JE_cashLeft());
 
2522
                JE_textShade(VGAScreen, 65, 173, cl, 1, 6, DARKEN);
 
2523
        }
 
2524
}
 
2525
 
 
2526
void JE_menuFunction( JE_byte select )
 
2527
{
 
2528
        JE_byte x;
 
2529
        JE_word curSelect;
 
2530
 
 
2531
        col = 0;
 
2532
        colC = -1;
 
2533
        JE_playSampleNum(S_CLICK);
 
2534
 
 
2535
        curSelect = curSel[curMenu];
 
2536
 
 
2537
        switch (curMenu)
 
2538
        {
 
2539
        case 0: //root menu
 
2540
                switch (select)
 
2541
                {
 
2542
                case 2: //cubes
 
2543
                        curMenu = 7;
 
2544
                        curSel[7] = 2;
 
2545
                        break;
 
2546
                case 3: //shipspecs
 
2547
                        JE_doShipSpecs();
 
2548
                        break;
 
2549
                case 4://upgradeship
 
2550
                        curMenu = 1;
 
2551
                        break;
 
2552
                case 5: //options
 
2553
                        curMenu = 2;
 
2554
                        break;
 
2555
                case 6: //nextlevel
 
2556
                        curMenu = 3;
 
2557
                        newPal = 18;
 
2558
                        JE_computeDots();
 
2559
                        navX = planetX[mapOrigin - 1];
 
2560
                        navY = planetY[mapOrigin - 1];
 
2561
                        newNavX = navX;
 
2562
                        newNavY = navY;
 
2563
                        menuChoices[3] = mapPNum + 2;
 
2564
                        curSel[3] = 2;
 
2565
                        strcpy(menuInt[4][0], "Next Level");
 
2566
                        for (x = 0; x < mapPNum; x++)
 
2567
                        {
 
2568
                                temp = mapPlanet[x];
 
2569
                                strcpy(menuInt[4][x + 1], pName[temp - 1]);
 
2570
                        }
 
2571
                        strcpy(menuInt[4][x + 1], miscText[5]);
 
2572
                        break;
 
2573
                case 7: //quit
 
2574
                        if (JE_quitRequest())
 
2575
                        {
 
2576
                                gameLoaded = true;
 
2577
                                mainLevel = 0;
 
2578
                        }
 
2579
                        break;
 
2580
                }
 
2581
                break;
 
2582
 
 
2583
        case 1: //upgradeship
 
2584
                if (select == 9) //done
 
2585
                {
 
2586
                        curMenu = 0;
 
2587
                }
 
2588
                else // selected item to upgrade
 
2589
                {
 
2590
                        old_items[0] = player[0].items;
 
2591
 
 
2592
                        lastDirection = 1;
 
2593
                        JE_genItemMenu(select);
 
2594
                        JE_initWeaponView();
 
2595
                        curMenu = 4;
 
2596
                        lastCurSel = curSel[4];
 
2597
                        player[0].cash = player[0].cash * 2 - JE_cashLeft();
 
2598
                }
 
2599
                break;
 
2600
 
 
2601
        case 2: //options
 
2602
                switch (select)
 
2603
                {
 
2604
                case 2:
 
2605
                        curMenu = 6;
 
2606
                        performSave = false;
 
2607
                        quikSave = false;
 
2608
                        break;
 
2609
                case 3:
 
2610
                        curMenu = 6;
 
2611
                        performSave = true;
 
2612
                        quikSave = false;
 
2613
                        break;
 
2614
                case 6:
 
2615
                        curMenu = 12;
 
2616
                        break;
 
2617
                case 7:
 
2618
                        curMenu = 5;
 
2619
                        break;
 
2620
                case 8:
 
2621
                        curMenu = 0;
 
2622
                        break;
 
2623
                }
 
2624
                break;
 
2625
 
 
2626
        case 3: //nextlevel
 
2627
                if (select == menuChoices[3]) //exit
 
2628
                {
 
2629
                        curMenu = 0;
 
2630
                        newPal = 1;
 
2631
                } else {
 
2632
                        mainLevel = mapSection[curSelect - 2];
 
2633
                        jumpSection = true;
 
2634
                }
 
2635
                break;
 
2636
 
 
2637
        case 4: //buying
 
2638
                if (curSel[4] < menuChoices[4])
 
2639
                {
 
2640
                        // select done
 
2641
                        curSel[4] = menuChoices[4];
 
2642
                }
 
2643
                else // if done is selected
 
2644
                {
 
2645
                        JE_playSampleNum(S_ITEM);
 
2646
 
 
2647
                        player[0].cash = JE_cashLeft();
 
2648
                        curMenu = 1;
 
2649
                }
 
2650
                break;
 
2651
 
 
2652
        case 5: /* keyboard settings */
 
2653
                if (curSelect == 10) /* reset to defaults */
 
2654
                {
 
2655
                        memcpy(keySettings, defaultKeySettings, sizeof(keySettings));
 
2656
                }
 
2657
                else if (curSelect == 11) /* done */
 
2658
                {
 
2659
                        if (isNetworkGame || onePlayerAction)
 
2660
                        {
 
2661
                                curMenu = 11;
 
2662
                        } else {
 
2663
                                curMenu = 2;
 
2664
                        }
 
2665
                }
 
2666
                else /* change key */
 
2667
                {
 
2668
                        temp2 = 254;
 
2669
                        int tempY = 38 + (curSelect - 2) * 12;
 
2670
                        JE_textShade(VGAScreen, 236, tempY, SDL_GetKeyName(keySettings[curSelect-2]), (temp2 / 16), (temp2 % 16) - 8, DARKEN);
 
2671
                        JE_showVGA();
 
2672
 
 
2673
                        wait_noinput(true, true, true);
 
2674
 
 
2675
                        col = 248;
 
2676
                        colC = 1;
 
2677
 
 
2678
                        do {
 
2679
                                setjasondelay(1);
 
2680
 
 
2681
                                col += colC;
 
2682
                                if (col < 243 || col > 248)
 
2683
                                {
 
2684
                                        colC *= -1;
 
2685
                                }
 
2686
                                JE_rectangle(VGAScreen, 230, tempY - 2, 300, tempY + 7, col);
 
2687
 
 
2688
                                poll_joysticks();
 
2689
                                service_SDL_events(true);
 
2690
 
 
2691
                                JE_showVGA();
 
2692
 
 
2693
                                wait_delay();
 
2694
                        } while (!newkey && !mousedown && !joydown);
 
2695
                        
 
2696
                        if (newkey)
 
2697
                        {
 
2698
                                // already used? then swap
 
2699
                                for (uint i = 0; i < COUNTOF(keySettings); ++i)
 
2700
                                {
 
2701
                                        if (keySettings[i] == lastkey_sym)
 
2702
                                        {
 
2703
                                                keySettings[i] = keySettings[curSelect-2];
 
2704
                                                break;
 
2705
                                        }
 
2706
                                }
 
2707
                                
 
2708
                                if (lastkey_sym != SDLK_ESCAPE && // reserved for menu
 
2709
                                    lastkey_sym != SDLK_F11 &&    // reserved for gamma
 
2710
                                    lastkey_sym != SDLK_p)        // reserved for pause
 
2711
                                {
 
2712
                                        JE_playSampleNum(S_CLICK);
 
2713
                                        keySettings[curSelect-2] = lastkey_sym;
 
2714
                                        ++curSelect;
 
2715
                                }
 
2716
                                
 
2717
                                JE_wipeKey();
 
2718
                        }
 
2719
                }
 
2720
                break;
 
2721
 
 
2722
        case 6: //save
 
2723
                if (curSelect == 13)
 
2724
                {
 
2725
                        if (quikSave)
 
2726
                        {
 
2727
                                curMenu = oldMenu;
 
2728
                                newPal = oldPal;
 
2729
                        } else {
 
2730
                                curMenu = 2;
 
2731
                        }
 
2732
                } else {
 
2733
                        if (twoPlayerMode)
 
2734
                        {
 
2735
                                temp = 11;
 
2736
                        } else {
 
2737
                                temp = 0;
 
2738
                        }
 
2739
                        JE_operation(curSelect - 1 + temp);
 
2740
                        if (quikSave)
 
2741
                        {
 
2742
                                curMenu = oldMenu;
 
2743
                                newPal = oldPal;
 
2744
                        }
 
2745
                }
 
2746
                break;
 
2747
 
 
2748
        case 7: //cubes
 
2749
                if (curSelect == menuChoices[curMenu])
 
2750
                {
 
2751
                        curMenu = 0;
 
2752
                        newPal = 1;
 
2753
                } else {
 
2754
                        if (cubeMax > 0)
 
2755
                        {
 
2756
                                firstMenu9 = true;
 
2757
                                curMenu = 8;
 
2758
                                yLoc = 0;
 
2759
                                yChg = 0;
 
2760
                                currentCube = curSel[7] - 2;
 
2761
                        } else {
 
2762
                                curMenu = 0;
 
2763
                                newPal = 1;
 
2764
                        }
 
2765
                }
 
2766
                break;
 
2767
 
 
2768
        case 8: //cubes 2
 
2769
                curMenu = 7;
 
2770
                break;
 
2771
 
 
2772
        case 9: //2player
 
2773
                switch (curSel[curMenu])
 
2774
                {
 
2775
                case 2:
 
2776
                        mainLevel = mapSection[mapPNum-1];
 
2777
                        jumpSection = true;
 
2778
                        break;
 
2779
                case 3:
 
2780
                case 4:
 
2781
                        JE_playSampleNum(S_CURSOR);
 
2782
 
 
2783
                        int temp = curSel[curMenu] - 3;
 
2784
                        do {
 
2785
                                if (joysticks == 0)
 
2786
                                {
 
2787
                                        inputDevice[temp == 0 ? 1 : 0] = inputDevice[temp]; // swap controllers
 
2788
                                }
 
2789
                                if (inputDevice[temp] >= 2 + joysticks)
 
2790
                                {
 
2791
                                        inputDevice[temp] = 1;
 
2792
                                } else {
 
2793
                                        inputDevice[temp]++;
 
2794
                                }
 
2795
                        } while (inputDevice[temp] == inputDevice[temp == 0 ? 1 : 0]);
 
2796
                        break;
 
2797
                case 5:
 
2798
                        curMenu = 2;
 
2799
                        break;
 
2800
                case 6:
 
2801
                        if (JE_quitRequest())
 
2802
                        {
 
2803
                                gameLoaded = true;
 
2804
                                mainLevel = 0;
 
2805
                        }
 
2806
                        break;
 
2807
                }
 
2808
                break;
 
2809
 
 
2810
        case 10: //arcade
 
2811
                switch (curSel[curMenu])
 
2812
                {
 
2813
                case 2:
 
2814
                        mainLevel = mapSection[mapPNum-1];
 
2815
                        jumpSection = true;
 
2816
                        break;
 
2817
                case 3:
 
2818
                        curMenu = 2;
 
2819
                        break;
 
2820
                case 4:
 
2821
                        if (JE_quitRequest())
 
2822
                        {
 
2823
                                gameLoaded = true;
 
2824
                                mainLevel = 0;
 
2825
                        }
 
2826
                        break;
 
2827
                }
 
2828
                break;
 
2829
 
 
2830
        case 11: //dunno, possibly online multiplayer
 
2831
                switch (select)
 
2832
                {
 
2833
                case 2:
 
2834
                        curMenu = 12;
 
2835
                        break;
 
2836
                case 3:
 
2837
                        curMenu = 5;
 
2838
                        break;
 
2839
                case 6:
 
2840
                        curMenu = 10;
 
2841
                        break;
 
2842
                }
 
2843
                break;
 
2844
 
 
2845
        case 12: //joy
 
2846
                if (joysticks == 0 && select != 17)
 
2847
                        break;
 
2848
 
 
2849
                switch (select)
 
2850
                {
 
2851
                case 2:
 
2852
                        joystick_config++;
 
2853
                        joystick_config %= joysticks;
 
2854
                        break;
 
2855
                case 3:
 
2856
                        joystick[joystick_config].analog = !joystick[joystick_config].analog;
 
2857
                        break;
 
2858
                case 4:
 
2859
                        if (joystick[joystick_config].analog)
 
2860
                        {
 
2861
                                joystick[joystick_config].sensitivity++;
 
2862
                                joystick[joystick_config].sensitivity %= 11;
 
2863
                        }
 
2864
                        break;
 
2865
                case 5:
 
2866
                        if (joystick[joystick_config].analog)
 
2867
                        {
 
2868
                                joystick[joystick_config].threshold++;
 
2869
                                joystick[joystick_config].threshold %= 11;
 
2870
                        }
 
2871
                        break;
 
2872
                case 16:
 
2873
                        reset_joystick_assignments(joystick_config);
 
2874
                        break;
 
2875
                case 17:
 
2876
                        if (isNetworkGame || onePlayerAction)
 
2877
                        {
 
2878
                                curMenu = 11;
 
2879
                        } else {
 
2880
                                curMenu = 2;
 
2881
                        }
 
2882
                        break;
 
2883
                default:
 
2884
                        if (joysticks == 0)
 
2885
                                break;
 
2886
 
 
2887
                        // int temp = 254;
 
2888
                        // JE_textShade(VGAScreen, 236, 38 + i * 8, value, temp / 16, temp % 16 - 8, DARKEN);
 
2889
 
 
2890
                        JE_rectangle(VGAScreen, 235, 21 + select * 8, 310, 30 + select * 8, 248);
 
2891
 
 
2892
                        Joystick_assignment temp;
 
2893
                        if (detect_joystick_assignment(joystick_config, &temp))
 
2894
                        {
 
2895
                                // if the detected assignment was already set, unset it
 
2896
                                for (uint i = 0; i < COUNTOF(*joystick->assignment); i++)
 
2897
                                {
 
2898
                                        if (joystick_assignment_cmp(&temp, &joystick[joystick_config].assignment[select - 6][i]))
 
2899
                                        {
 
2900
                                                joystick[joystick_config].assignment[select - 6][i].type = NONE;
 
2901
                                                goto joystick_assign_done;
 
2902
                                        }
 
2903
                                }
 
2904
 
 
2905
                                // if there is an empty assignment, set it
 
2906
                                for (uint i = 0; i < COUNTOF(*joystick->assignment); i++)
 
2907
                                {
 
2908
                                        if (joystick[joystick_config].assignment[select - 6][i].type == NONE)
 
2909
                                        {
 
2910
                                                joystick[joystick_config].assignment[select - 6][i] = temp;
 
2911
                                                goto joystick_assign_done;
 
2912
                                        }
 
2913
                                }
 
2914
 
 
2915
                                // if no assignments are empty, shift them all forward and set the last one
 
2916
                                for (uint i = 0; i < COUNTOF(*joystick->assignment); i++)
 
2917
                                {
 
2918
                                        if (i == COUNTOF(*joystick->assignment) - 1)
 
2919
                                                joystick[joystick_config].assignment[select - 6][i] = temp;
 
2920
                                        else
 
2921
                                                joystick[joystick_config].assignment[select - 6][i] = joystick[joystick_config].assignment[select - 6][i + 1];
 
2922
                                }
 
2923
 
 
2924
joystick_assign_done:
 
2925
                                curSelect++;
 
2926
 
 
2927
                                poll_joysticks();
 
2928
                        }
 
2929
                }
 
2930
                break;
 
2931
 
 
2932
        case 13: //engage
 
2933
                switch (curSel[curMenu])
 
2934
                {
 
2935
                case 2:
 
2936
                        mainLevel = mapSection[mapPNum-1];
 
2937
                        jumpSection = true;
 
2938
                        break;
 
2939
                case 3:
 
2940
                        JE_doShipSpecs();
 
2941
                        break;
 
2942
                case 4:
 
2943
                        curMenu = 2;
 
2944
                        break;
 
2945
                case 5:
 
2946
                        if (JE_quitRequest())
 
2947
                        {
 
2948
                                if (isNetworkGame)
 
2949
                                {
 
2950
                                        JE_tyrianHalt(0);
 
2951
                                }
 
2952
                                gameLoaded = true;
 
2953
                                mainLevel = 0;
 
2954
                        }
 
2955
                }
 
2956
                break;
 
2957
        }
 
2958
 
 
2959
        old_items[0] = player[0].items;
 
2960
}
 
2961
 
 
2962
void JE_drawShipSpecs( SDL_Surface * screen, SDL_Surface * temp_screen  )
 
2963
{
 
2964
        /* In this function we create our ship description image.
 
2965
         *
 
2966
         * We use a temp screen for convenience.  Bad design maybe (Jason!),
 
2967
         * but it'll be okay (and the alternative is malloc/a large stack) */
 
2968
 
 
2969
        int temp_x = 0, temp_y = 0, temp_index;
 
2970
        Uint8 *src, *dst;
 
2971
 
 
2972
 
 
2973
        //first, draw the text and other assorted flavoring.
 
2974
        JE_clr256(screen);
 
2975
        JE_drawLines(screen, true);
 
2976
        JE_drawLines(screen, false);
 
2977
        JE_rectangle(screen, 0, 0, 319, 199, 37);
 
2978
        JE_rectangle(screen, 1, 1, 318, 198, 35);
 
2979
 
 
2980
        verticalHeight = 9;
 
2981
        JE_outText(screen, 10, 2, ships[player[0].items.ship].name, 12, 3);
 
2982
        JE_helpBox(screen, 100, 20, shipInfo[player[0].items.ship-1][0], 40);
 
2983
        JE_helpBox(screen, 100, 100, shipInfo[player[0].items.ship-1][1], 40);
 
2984
        verticalHeight = 7;
 
2985
 
 
2986
        JE_outText(screen, JE_fontCenter(miscText[4], TINY_FONT), 190, miscText[4], 12, 2);
 
2987
 
 
2988
 
 
2989
        //now draw the green ship over that.
 
2990
        //This hardcoded stuff is for positioning our little ship graphic
 
2991
        if (player[0].items.ship > 90)
 
2992
        {
 
2993
                temp_index = 32;
 
2994
        }
 
2995
        else if (player[0].items.ship > 0)
 
2996
        {
 
2997
                temp_index = ships[player[0].items.ship].bigshipgraphic;
 
2998
        }
 
2999
        else
 
3000
        {
 
3001
                temp_index = ships[old_items[0].ship].bigshipgraphic;
 
3002
        }
 
3003
 
 
3004
        switch (temp_index)
 
3005
        {
 
3006
                case 32:
 
3007
                        temp_x = 35;
 
3008
                        temp_y = 33;
 
3009
                        break;
 
3010
                case 28:
 
3011
                        temp_x = 31;
 
3012
                        temp_y = 36;
 
3013
                        break;
 
3014
                case 33:
 
3015
                        temp_x = 31;
 
3016
                        temp_y = 35;
 
3017
                        break;
 
3018
                default:
 
3019
                        assert(0);
 
3020
        }
 
3021
        temp_x -= 30;
 
3022
 
 
3023
 
 
3024
        //draw the ship into our temp buffer.
 
3025
        JE_clr256(temp_screen);
 
3026
        blit_sprite(temp_screen, temp_x, temp_y, OPTION_SHAPES, temp_index - 1);  // ship illustration
 
3027
 
 
3028
        /* But wait!  Our ship is fully colored, not green!
 
3029
         * With a little work we could get the sprite dimensions and greenify
 
3030
         * the area it resides in.  For now, let's just greenify the (almost
 
3031
         * entirely) black screen.
 
3032
 
 
3033
         * We can't work in place.  In fact we'll need to overlay the result
 
3034
         * To avoid our temp screen dependence this has been rewritten to
 
3035
         * only write one line at a time.*/
 
3036
        dst = screen->pixels;
 
3037
        src = temp_screen->pixels;
 
3038
        for (int y = 0; y < screen->h; y++)
 
3039
        {
 
3040
                for (int x = 0; x < screen->pitch; x++)
 
3041
                {
 
3042
                        int avg = 0;
 
3043
                        if (y > 0)
 
3044
                                avg += *(src - screen->pitch) & 0x0f;
 
3045
                        if (y < screen->h - 1)
 
3046
                                avg += *(src + screen->pitch) & 0x0f;
 
3047
                        if (x > 0)
 
3048
                                avg += *(src - 1) & 0x0f;
 
3049
                        if (x < screen->pitch - 1)
 
3050
                                avg += *(src + 1) & 0x0f;
 
3051
                        avg /= 4;
 
3052
 
 
3053
                        if ((*src & 0x0f) > avg)
 
3054
                        {
 
3055
                                *dst = (*src & 0x0f) | 0xc0;
 
3056
                        //} else {
 
3057
                        //      *dst = 0;
 
3058
                        }
 
3059
 
 
3060
                        src++;
 
3061
                        dst++;
 
3062
                }
 
3063
        }
 
3064
}
 
3065
 
 
3066
void JE_weaponSimUpdate( void )
 
3067
{
 
3068
        char buf[32];
 
3069
 
 
3070
        JE_weaponViewFrame();
 
3071
 
 
3072
        if ( (curSel[1] == 3 && curSel[4] < menuChoices[4]) || (curSel[1] == 4 && curSel[4] < menuChoices[4] - 1) )
 
3073
        {
 
3074
                if (leftPower)
 
3075
                {
 
3076
                        sprintf(buf, "%d", downgradeCost);
 
3077
                        JE_outText(VGAScreen, 26, 137, buf, 1, 4);
 
3078
                }
 
3079
                else
 
3080
                {
 
3081
                        blit_sprite(VGAScreenSeg, 24, 149, OPTION_SHAPES, 13);  // downgrade disabled
 
3082
                }
 
3083
 
 
3084
                if (rightPower)
 
3085
                {
 
3086
                        if (!rightPowerAfford)
 
3087
                        {
 
3088
                                sprintf(buf, "%d", upgradeCost);
 
3089
                                JE_outText(VGAScreen, 108, 137, buf, 7, 4);
 
3090
                                blit_sprite(VGAScreenSeg, 119, 149, OPTION_SHAPES, 14);  // upgrade disabled
 
3091
                        }
 
3092
                        else
 
3093
                        {
 
3094
                                sprintf(buf, "%d", upgradeCost);
 
3095
                                JE_outText(VGAScreen, 108, 137, buf, 1, 4);
 
3096
                        }
 
3097
                }
 
3098
                else
 
3099
                {
 
3100
                        blit_sprite(VGAScreenSeg, 119, 149, OPTION_SHAPES, 14);  // upgrade disabled
 
3101
                }
 
3102
 
 
3103
                temp = player[0].items.weapon[curSel[1]-3].power;
 
3104
 
 
3105
                for (int x = 1; x <= temp; x++)
 
3106
                {
 
3107
                        fill_rectangle_xy(VGAScreen, 39 + x * 6, 151, 39 + x * 6 + 4, 151, 251);
 
3108
                        JE_pix(VGAScreen, 39 + x * 6, 151, 252);
 
3109
                        fill_rectangle_xy(VGAScreen, 39 + x * 6, 152, 39 + x * 6 + 4, 164, 250);
 
3110
                        fill_rectangle_xy(VGAScreen, 39 + x * 6, 165, 39 + x * 6 + 4, 165, 249);
 
3111
                }
 
3112
 
 
3113
                sprintf(buf, "POWER: %d", temp);
 
3114
                JE_outText(VGAScreen, 58, 137, buf, 15, 4);
 
3115
        }
 
3116
        else
 
3117
        {
 
3118
                leftPower = false;
 
3119
                rightPower = false;
 
3120
                blit_sprite(VGAScreenSeg, 20, 146, OPTION_SHAPES, 17);  // hide power level interface
 
3121
        }
 
3122
 
 
3123
        JE_drawItem(1, player[0].items.ship, player[0].x - 5, player[0].y - 7);
 
3124
}
 
3125
 
 
3126
void JE_weaponViewFrame( void )
 
3127
{
 
3128
        fill_rectangle_xy(VGAScreen, 8, 8, 143, 182, 0);
 
3129
 
 
3130
        /* JE: (* Port Configuration Display *)
 
3131
        (*    drawportconfigbuttons;*/
 
3132
 
 
3133
        update_and_draw_starfield(VGAScreen, 1);
 
3134
 
 
3135
        mouseX = player[0].x;
 
3136
        mouseY = player[0].y;
 
3137
 
 
3138
        // create shots in weapon simulator
 
3139
        for (uint i = 0; i < 2; ++i)
 
3140
        {
 
3141
                if (shotRepeat[i] > 0)
 
3142
                {
 
3143
                        --shotRepeat[i];
 
3144
                }
 
3145
                else
 
3146
                {
 
3147
                        const uint item       = player[0].items.weapon[i].id,
 
3148
                                   item_power = player[0].items.weapon[i].power - 1,
 
3149
                                   item_mode = (i == REAR_WEAPON) ? player[0].weapon_mode - 1 : 0;
 
3150
 
 
3151
                        b = player_shot_create(item, i, player[0].x, player[0].y, mouseX, mouseY, weaponPort[item].op[item_mode][item_power], 1);
 
3152
                }
 
3153
        }
 
3154
 
 
3155
        if (options[player[0].items.sidekick[LEFT_SIDEKICK]].wport > 0)
 
3156
        {
 
3157
                if (shotRepeat[SHOT_LEFT_SIDEKICK] > 0)
 
3158
                {
 
3159
                        --shotRepeat[SHOT_LEFT_SIDEKICK];
 
3160
                }
 
3161
                else
 
3162
                {
 
3163
                        const uint item = player[0].items.sidekick[LEFT_SIDEKICK];
 
3164
                        const int x = player[0].sidekick[LEFT_SIDEKICK].x,
 
3165
                                  y = player[0].sidekick[LEFT_SIDEKICK].y;
 
3166
 
 
3167
                        b = player_shot_create(options[item].wport, SHOT_LEFT_SIDEKICK, x, y, mouseX, mouseY, options[item].wpnum, 1);
 
3168
                }
 
3169
        }
 
3170
 
 
3171
        if (options[player[0].items.sidekick[RIGHT_SIDEKICK]].tr == 2)
 
3172
        {
 
3173
                player[0].sidekick[RIGHT_SIDEKICK].x = player[0].x;
 
3174
                player[0].sidekick[RIGHT_SIDEKICK].y = MAX(10, player[0].y - 20);
 
3175
        }
 
3176
        else
 
3177
        {
 
3178
                player[0].sidekick[RIGHT_SIDEKICK].x = 72 + 15;
 
3179
                player[0].sidekick[RIGHT_SIDEKICK].y = 120;
 
3180
        }
 
3181
 
 
3182
        if (options[player[0].items.sidekick[RIGHT_SIDEKICK]].wport > 0)
 
3183
        {
 
3184
                if (shotRepeat[SHOT_RIGHT_SIDEKICK] > 0)
 
3185
                {
 
3186
                        --shotRepeat[SHOT_RIGHT_SIDEKICK];
 
3187
                }
 
3188
                else
 
3189
                {
 
3190
                        const uint item = player[0].items.sidekick[RIGHT_SIDEKICK];
 
3191
                        const int x = player[0].sidekick[RIGHT_SIDEKICK].x,
 
3192
                                  y = player[0].sidekick[RIGHT_SIDEKICK].y;
 
3193
 
 
3194
                        b = player_shot_create(options[item].wport, SHOT_RIGHT_SIDEKICK, x, y, mouseX, mouseY, options[item].wpnum, 1);
 
3195
                }
 
3196
        }
 
3197
 
 
3198
        simulate_player_shots();
 
3199
 
 
3200
        blit_sprite(VGAScreenSeg, 0, 0, OPTION_SHAPES, 12); // upgrade interface
 
3201
 
 
3202
 
 
3203
        /*========================Power Bar=========================*/
 
3204
 
 
3205
        power += powerAdd;
 
3206
        if (power > 900)
 
3207
                power = 900;
 
3208
 
 
3209
        temp = power / 10;
 
3210
 
 
3211
        for (temp = 147 - temp; temp <= 146; temp++)
 
3212
        {
 
3213
                temp2 = 113 + (146 - temp) / 9 + 2;
 
3214
                temp3 = (temp + 1) % 6;
 
3215
                if (temp3 == 1)
 
3216
                        temp2 += 3;
 
3217
                else if (temp3 != 0)
 
3218
                        temp2 += 2;
 
3219
 
 
3220
                JE_pix(VGAScreen, 141, temp, temp2 - 3);
 
3221
                JE_pix(VGAScreen, 142, temp, temp2 - 3);
 
3222
                JE_pix(VGAScreen, 143, temp, temp2 - 2);
 
3223
                JE_pix(VGAScreen, 144, temp, temp2 - 1);
 
3224
                fill_rectangle_xy(VGAScreen, 145, temp, 149, temp, temp2);
 
3225
 
 
3226
                if (temp2 - 3 < 112)
 
3227
                        temp2++;
 
3228
        }
 
3229
 
 
3230
        temp = 147 - (power / 10);
 
3231
        temp2 = 113 + (146 - temp) / 9 + 4;
 
3232
 
 
3233
        JE_pix(VGAScreen, 141, temp - 1, temp2 - 1);
 
3234
        JE_pix(VGAScreen, 142, temp - 1, temp2 - 1);
 
3235
        JE_pix(VGAScreen, 143, temp - 1, temp2 - 1);
 
3236
        JE_pix(VGAScreen, 144, temp - 1, temp2 - 1);
 
3237
 
 
3238
        fill_rectangle_xy(VGAScreen, 145, temp-1, 149, temp-1, temp2);
 
3239
 
 
3240
        lastPower = temp;
 
3241
 
 
3242
        //JE_waitFrameCount();  TODO: didn't do anything?
 
3243
}
 
3244