Skip to content

Commit

Permalink
port DoPassportOption
Browse files Browse the repository at this point in the history
  • Loading branch information
rr- committed Mar 7, 2021
1 parent 50968fc commit 76707fd
Show file tree
Hide file tree
Showing 6 changed files with 218 additions and 20 deletions.
12 changes: 6 additions & 6 deletions docs/progress.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 2 additions & 2 deletions docs/progress.txt
Original file line number Diff line number Diff line change
Expand Up @@ -724,7 +724,7 @@ EarthQuakeControl 0x0042D700 0x0000006F +
# option.cpp
GetScancodeName ---------- ---------- -
DoInventoryOptions 0x0042D770 0x00000180 +
DoPassportOption 0x0042D9C0 0x000004D0 *
DoPassportOption 0x0042D9C0 0x000004D0 +
DoGammaOption ---------- ---------- +
DoDetailOptionHW 0x0042DE90 0x00000435 -
DoDetailOption 0x0042E2D0 0x000002E8 -
Expand All @@ -737,7 +737,7 @@ S_ShowControls 0x0042F230 0x000004B1 +
S_ChangeCtrlText ---------- ---------- -
S_RemoveCtrlText ---------- ---------- -
S_RemoveCtrl ---------- ---------- -
InitRequester ---------- ---------- -
InitRequester ---------- ---------- +
RemoveRequester ---------- ---------- -
DisplayRequester 0x0042F6F0 0x0000056B *

Expand Down
3 changes: 0 additions & 3 deletions src/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -418,9 +418,6 @@ void GetSavedGamesList(REQUEST_INFO* req)
req->y = -100;
req->vis_lines = 12;
break;

default:
break;
}

if (req->requested >= req->vis_lines) {
Expand Down
208 changes: 208 additions & 0 deletions src/game/option.c
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@
#define GAMMA_MODIFIER 8
#define MIN_GAMMA_LEVEL -127
#define MAX_GAMMA_LEVEL 127
#define PASSPORT_2FRONT IN_LEFT
#define PASSPORT_2BACK IN_RIGHT

static TEXTSTRING* PassportText1;
static int32_t PassportMode;

// original name: do_inventory_options
void DoInventoryOptions(INVENTORY_ITEM* inv_item)
Expand Down Expand Up @@ -75,6 +80,208 @@ void DoInventoryOptions(INVENTORY_ITEM* inv_item)
}
}

void DoPassportOption(INVENTORY_ITEM* inv_item)
{
T_RemovePrint(InvItemText[0]);
InvItemText[IT_NAME] = NULL;

int16_t page = (inv_item->goal_frame - inv_item->open_frame) / 5;
if ((inv_item->goal_frame - inv_item->open_frame) % 5) {
page = -1;
}

if (InventoryMode == INV_LOAD_MODE || InventoryMode == INV_SAVE_MODE) {
InputDB &= ~(PASSPORT_2FRONT | PASSPORT_2BACK);
}

switch (page) {
case 0:
if (PassportMode == 1) {
int32_t select = DisplayRequester(&LoadGameRequester);
if (select) {
if (select > 0) {
InventoryExtraData[1] = select - 1;
} else if (
InventoryMode != INV_SAVE_MODE
&& InventoryMode != INV_LOAD_MODE) {
Input = 0;
InputDB = 0;
}
PassportMode = 0;
} else {
Input = 0;
InputDB = 0;
}
} else if (PassportMode == 0) {
if (!SavedGamesCount || InventoryMode == INV_SAVE_MODE) {
InputDB = PASSPORT_2BACK;
} else {
if (!PassportText1) {
PassportText1 = T_Print(0, -16, 0, "Load Game");
T_BottomAlign(PassportText1, 1);
T_CentreH(PassportText1, 1);
}
if (CHK_ANY(InputDB, IN_SELECT)
|| InventoryMode == INV_LOAD_MODE) {
T_RemovePrint(InvRingText);
InvRingText = NULL;
T_RemovePrint(InvItemText[IT_NAME]);
InvItemText[IT_NAME] = NULL;
GetSavedGamesList(&LoadGameRequester);
InitRequester(&LoadGameRequester);
PassportMode = 1;
Input = 0;
InputDB = 0;
}
}
}
break;

case 1:
if (PassportMode == 1) {
int32_t select = DisplayRequester(&LoadGameRequester);
if (select) {
if (select > 0) {
PassportMode = 0;
InventoryExtraData[1] = select - 1;
} else {
if (InventoryMode != INV_SAVE_MODE
&& InventoryMode != INV_LOAD_MODE) {
Input = 0;
InputDB = 0;
}
PassportMode = 0;
}
} else {
Input = 0;
InputDB = 0;
}
} else if (PassportMode == 0) {
if (InventoryMode == INV_DEATH_MODE) {
InputDB = inv_item->anim_direction == -1 ? PASSPORT_2FRONT
: PASSPORT_2BACK;
}
if (!PassportText1) {
if (InventoryMode == INV_TITLE_MODE || !CurrentLevel) {
PassportText1 = T_Print(0, -16, 0, "New Game");
} else {
PassportText1 = T_Print(0, -16, 0, "Save Game");
}
T_BottomAlign(PassportText1, 1);
T_CentreH(PassportText1, 1);
}
if (CHK_ANY(InputDB, IN_SELECT) || InventoryMode == INV_SAVE_MODE) {
if (InventoryMode == INV_TITLE_MODE || !CurrentLevel) {
InventoryExtraData[1] = CurrentLevel;
} else {
T_RemovePrint(InvRingText);
InvRingText = NULL;
T_RemovePrint(InvItemText[IT_NAME]);
InvItemText[IT_NAME] = NULL;
GetSavedGamesList(&LoadGameRequester);
InitRequester(&LoadGameRequester);
PassportMode = 1;
Input = 0;
InputDB = 0;
}
}
}
break;

case 2:
if (!PassportText1) {
if (InventoryMode == INV_TITLE_MODE) {
PassportText1 = T_Print(0, -16, 0, "Exit Game");
} else {
PassportText1 = T_Print(0, -16, 0, "Exit to Title");
}
T_BottomAlign(PassportText1, 1);
T_CentreH(PassportText1, 1);
}
break;
}

if (CHK_ANY(InputDB, PASSPORT_2FRONT)
&& (InventoryMode != INV_DEATH_MODE || SavedGamesCount)) {
inv_item->anim_direction = -1;
inv_item->goal_frame -= 5;

Input = 0;
InputDB = 0;

if (!SavedGamesCount) {
if (inv_item->goal_frame < inv_item->open_frame + 5) {
inv_item->goal_frame = inv_item->open_frame + 5;
} else if (PassportText1) {
T_RemovePrint(PassportText1);
PassportText1 = NULL;
}
} else {
if (inv_item->goal_frame < inv_item->open_frame) {
inv_item->goal_frame = inv_item->open_frame;
} else {
SoundEffect(115, NULL, SFX_ALWAYS);
if (PassportText1) {
T_RemovePrint(PassportText1);
PassportText1 = NULL;
}
}
}
}

if (CHK_ANY(InputDB, PASSPORT_2BACK)) {
inv_item->goal_frame += 5;
inv_item->anim_direction = 1;

Input = 0;
InputDB = 0;

if (inv_item->goal_frame > inv_item->frames_total - 6) {
inv_item->goal_frame = inv_item->frames_total - 6;
} else {
SoundEffect(115, NULL, SFX_ALWAYS);
if (PassportText1) {
T_RemovePrint(PassportText1);
PassportText1 = NULL;
}
}
}

if (CHK_ANY(InputDB, IN_DESELECT)) {
if (InventoryMode == INV_DEATH_MODE) {
Input = 0;
InputDB = 0;
} else {
if (page == 2) {
inv_item->anim_direction = 1;
inv_item->goal_frame = inv_item->frames_total - 1;
} else {
inv_item->goal_frame = 0;
inv_item->anim_direction = -1;
}
if (PassportText1) {
T_RemovePrint(PassportText1);
PassportText1 = 0;
}
}
}

if (CHK_ANY(InputDB, IN_SELECT)) {
InventoryExtraData[0] = page;
if (page == 2) {
inv_item->anim_direction = 1;
inv_item->goal_frame = inv_item->frames_total - 1;
} else {
inv_item->goal_frame = 0;
inv_item->anim_direction = -1;
}
if (PassportText1) {
T_RemovePrint(PassportText1);
PassportText1 = 0;
}
}
}

// original name: do_gamma_option
void DoGammaOption(INVENTORY_ITEM* inv_item)
{
Expand Down Expand Up @@ -280,5 +487,6 @@ void InitRequester(REQUEST_INFO* req)
void T1MInjectGameOption()
{
INJECT(0x0042D770, DoInventoryOptions);
INJECT(0x0042D9C0, DoPassportOption);
INJECT(0x0042F230, S_ShowControls);
}
3 changes: 2 additions & 1 deletion src/game/option.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,18 @@
#include "game/types.h"

// clang-format off
#define DoPassportOption ((void (*)(INVENTORY_ITEM* inv_item))0x0042D9C0)
#define DoDetailOption ((void (*)(INVENTORY_ITEM* inv_item))0x0042E2D0)
#define DoSoundOption ((void (*)(INVENTORY_ITEM* inv_item))0x0042E5C0)
#define DoControlOption ((void (*)(INVENTORY_ITEM* inv_item))0x0042EAC0)
#define DisplayRequester ((int32_t (*)(REQUEST_INFO* req))0x0042F6F0)
// clang-format on

void DoInventoryOptions(INVENTORY_ITEM* inv_item);
void DoPassportOption(INVENTORY_ITEM* inv_item);
void DoGammaOption(INVENTORY_ITEM* inv_item);
void DoCompassOption(INVENTORY_ITEM* inv_item);
void S_ShowControls();
void InitRequester(REQUEST_INFO* req);

void T1MInjectGameOption();

Expand Down
8 changes: 0 additions & 8 deletions src/json-parser/json.c
Original file line number Diff line number Diff line change
Expand Up @@ -227,8 +227,6 @@ int json_get_string_size(struct json_parse_state_s* state, size_t is_key)
data_size++;

switch (src[offset]) {
default:
break;
case '\0':
case '\t':
state->error = json_parse_error_invalid_string;
Expand Down Expand Up @@ -1784,8 +1782,6 @@ json_extract_get_value_size(const struct json_value_s* const value)
struct json_extract_result_s result = { 0, 0 };

switch (value->type) {
default:
break;
case json_type_object:
result = json_extract_get_object_size(
(const struct json_object_s*)value->payload);
Expand Down Expand Up @@ -2004,8 +2000,6 @@ int json_write_get_number_size(const struct json_number_s* number, size_t* size)

if (number->number_size >= 2) {
switch (number->number[1]) {
default:
break;
case 'x':
case 'X':
/* the number is a json_parse_flags_allow_hexadecimal_numbers
Expand Down Expand Up @@ -2235,8 +2229,6 @@ char* json_write_number(const struct json_number_s* number, char* data)

if (number->number_size >= 2) {
switch (number->number[1]) {
default:
break;
case 'x':
case 'X':
/* The number is a json_parse_flags_allow_hexadecimal_numbers
Expand Down

0 comments on commit 76707fd

Please sign in to comment.