Skip to content

Commit

Permalink
Main menu: Add rules
Browse files Browse the repository at this point in the history
  • Loading branch information
1oom-fork committed Jun 10, 2024
1 parent 658bc16 commit 212bcde
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 3 deletions.
28 changes: 28 additions & 0 deletions src/game/game.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,19 @@ static void game_save_custom_opts_to_cfg(struct game_new_options_s *go)
}
}

void game_apply_rules(void)
{
if (game_opt_fix_bugs) {
game_num_fix_bugs();
}
if (game_opt_fix_guardian_repair) {
game_num_fix_guardian_repair();
}
if (game_opt_fix_starting_ships) {
game_num_fix_starting_ships();
}
}

/* -------------------------------------------------------------------------- */

static int game_opt_do_new_seed(char **argv, void *var)
Expand Down Expand Up @@ -582,6 +595,21 @@ const struct cfg_items_s game_cfg_items[] = {
CFG_ITEM_INT("custom_game_home_num_colony_ships", &game_opt_custom.homeworlds.num_colony_ships, NULL),
CFG_ITEM_BOOL("custom_game_home_armed_colony_ships", &game_opt_custom.homeworlds.armed_colony_ships),
CFG_ITEM_BOOL("planet_leaving_trans_fix", &game_planet_leaving_trans_fix),
CFG_ITEM_BOOL("rules_ai_transport_range_fix", &game_num_ai_trans_range_fix),
CFG_ITEM_BOOL("rules_bt_no_tohit_acc", &game_num_bt_no_tohit_acc),
CFG_ITEM_BOOL("rules_bt_precap_tohit", &game_num_bt_precap_tohit),
CFG_ITEM_BOOL("rules_bt_wait_no_reload", &game_num_bt_wait_no_reload),
CFG_ITEM_BOOL("rules_monster_rest_attack", &game_num_monster_rest_att),
CFG_ITEM_BOOL("rules_pop_tenths_fix", &game_num_pop_tenths_fix),
CFG_ITEM_BOOL("rules_retreat_redir_fix", &game_num_retreat_redir_fix),
CFG_ITEM_BOOL("rules_ship_scanner_fix", &game_num_ship_scanner_fix),
CFG_ITEM_BOOL("rules_ship_stargate_redir_fix", &game_num_stargate_redir_fix),
CFG_ITEM_BOOL("rules_ship_trans_redir_fix", &game_num_trans_redir_fix),
CFG_ITEM_BOOL("rules_waste_calc_fix", &game_num_waste_calc_fix),
CFG_ITEM_BOOL("rules_ai_fleet_cheating_fix", &game_num_ai_fleet_cheating_fix),
CFG_ITEM_BOOL("rules_fix_bugs", &game_opt_fix_bugs),
CFG_ITEM_BOOL("rules_fix_guardian_repair", &game_opt_fix_guardian_repair),
CFG_ITEM_BOOL("rules_fix_starting_ships", &game_opt_fix_starting_ships),
CFG_ITEM_END
};

Expand Down
51 changes: 51 additions & 0 deletions src/game/game_nump.c
Original file line number Diff line number Diff line change
Expand Up @@ -445,6 +445,57 @@ static const struct numtbl_s *find_match(const char *numid, int i, int num)

/* -------------------------------------------------------------------------- */

bool game_opt_fix_bugs = false;
bool game_opt_fix_guardian_repair = false;
bool game_opt_fix_starting_ships = false;

void game_num_fix_bugs(void)
{
game_num_ng_tech[RACE_SILICOID][TECH_FIELD_PLANETOLOGY][24] = 1;
game_num_ng_tech[RACE_SILICOID][TECH_FIELD_PLANETOLOGY][30] = 1;
game_num_max_factories = 2700;
game_num_accident_chk_factories = true;
game_num_bt_oracle_fix = true;
game_num_news_orion = true;
game_num_weapon_list_max = 64;
game_num_aud_bounty_give = true;
game_num_orbital_weap_any = true;
game_num_orbital_weap_4 = true;
game_num_orbital_torpedo = true;
game_num_orbital_comp_fix = true;
game_num_combat_trans_fix = true;
game_num_first_tech_rp_fix = true;
game_num_waste_adjust_fix = true;
game_num_eco_slider_slack = 0;
game_num_reset_tform_to_max = false;
game_num_soil_rounding_fix = true;
game_num_hidden_child_labor_fix = true;
game_num_colonized_factories_fix = true;
game_num_cond_build_ind_fix = true;
game_num_slider_stop_tform_fix = true;
}

void game_num_fix_guardian_repair(void)
{
tbl_monster[MONSTER_GUARDIAN][3].special[1] = 16;
tbl_monster[MONSTER_GUARDIAN][4].special[1] = 26;
tbl_monster[MONSTER_GUARDIAN][4].repair = 30;
}

void game_num_fix_starting_ships(void)
{
tbl_startship[0].engines = 2;
tbl_startship[1].engines = 27;
tbl_startship[2].engines = 110;
tbl_startship[3].engines = 85;
tbl_startship[4].engines = 100;
tbl_startship[0].cost = 8;
tbl_startship[1].cost = 14;
tbl_startship[2].cost = 74;
tbl_startship[3].cost = 65;
tbl_startship[4].cost = 570;
}

bool game_num_patch(const char *numid, const int32_t *patchnums, int first, int num)
{
const struct numtbl_s *s = find_match(numid, first, num);
Expand Down
9 changes: 9 additions & 0 deletions src/game/game_nump.h
Original file line number Diff line number Diff line change
@@ -1,6 +1,15 @@
#ifndef INC_1OOM_GAME_NUMP_H
#define INC_1OOM_GAME_NUMP_H

#include "types.h"

extern bool game_opt_fix_bugs;
extern bool game_opt_fix_guardian_repair;
extern bool game_opt_fix_starting_ships;

extern void game_num_fix_bugs(void);
extern void game_num_fix_guardian_repair(void);
extern void game_num_fix_starting_ships(void);
extern void game_num_dump(void);

#endif
1 change: 1 addition & 0 deletions src/gameapi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ extern const struct cfg_items_s game_cfg_items[];

extern bool game_num_patch(const char *numid, const int32_t *patchnums, int first, int num);
extern bool game_str_patch(const char *strid, const char *patchstr, int i);
extern void game_apply_rules(void);

#endif
5 changes: 5 additions & 0 deletions src/lbxview.c
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,11 @@ bool game_num_patch(const char *numid, int32_t *patchnums, int first, int num)
return true;
}

void game_apply_rules(void)
{

}

/* -------------------------------------------------------------------------- */

#define UI_SCREEN_W 320
Expand Down
2 changes: 2 additions & 0 deletions src/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include <stdlib.h>

#include "main.h"
#include "gameapi.h"
#include "hw.h"
#include "lbx.h"
#include "log.h"
Expand Down Expand Up @@ -81,6 +82,7 @@ int main_1oom(int argc, char **argv)
"Alternatively copy your\nMOO1 LBX files to your\n1oom directory.");
return 4;
}
game_apply_rules();
if (pbx_apply_queued_files()) {
return 5;
}
Expand Down
7 changes: 7 additions & 0 deletions src/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,15 @@ struct menu_item_data_s {
int action_i;
int value_min;
int value_max;
bool need_restart;
};

static inline struct menu_item_data_s *menu_item_force_restart(struct menu_item_data_s *d)
{
d->need_restart = true;
return d;
}

static inline void menu_make_page(struct menu_item_data_s *d, const char *text, int page, mookey_t key)
{
d->type = MENU_ITEM_TYPE_PAGE;
Expand Down
53 changes: 50 additions & 3 deletions src/ui/classic/uimainmenu.c
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include "game_misc.h"
#include "game_new.h"
#include "game_num.h"
#include "game_nump.h"
#include "game_save.h"
#include "game_str.h"
#include "hw.h"
Expand All @@ -34,6 +35,13 @@

/* -------------------------------------------------------------------------- */

static bool force_restart = false;

static bool main_menu_game_active(void)
{
return !force_restart;
}

static bool main_menu_have_save_continue(void) {
return game_save_tbl_have_save[GAME_SAVE_I_CONTINUE];
}
Expand Down Expand Up @@ -223,6 +231,10 @@ static void main_menu_draw_cb(void *vptr)
hw_video_copy_back_to_page2();
lbxfont_select(2, 7, 0, 0);
lbxfont_print_str_right(315, 193, PACKAGE_NAME " " VERSION_STR, UI_SCREEN_W, ui_scale);
if (force_restart) {
lbxfont_select(2, 2, 0, 0);
lbxfont_print_str_center(160, 60, "Application restart required", UI_SCREEN_W, ui_scale);
}
for (int i = 0; i < d->item_count; ++i) {
struct main_menu_item_s *it = &d->items[i];
if (it->active) {
Expand Down Expand Up @@ -312,6 +324,20 @@ static void mm_options_small_set_item_dimensions(struct main_menu_data_s *d, int
}
}

static void mm_options_small2_set_item_dimensions(struct main_menu_data_s *d, int i)
{
struct main_menu_item_s *it = &d->items[i];
uint16_t step_y;
it->font_i = 2;
main_menu_set_item_wh(d, it);
step_y = 0x80 / ((d->item_count + 1) / 2);
it->x = i%2 ? 0xe0 : 0x60;
if (i%2 == 0 && i == d->item_count - 1) {
it->x = 0xa0;
}
it->y = 0x47 + step_y * (i/2);
}

static void mm_custom_set_item_dimensions(struct main_menu_data_s *d, int i)
{
struct main_menu_item_s *it = &d->items[i];
Expand All @@ -334,7 +360,7 @@ static void mm_custom_set_item_dimensions(struct main_menu_data_s *d, int i)
static void main_menu_make_main_page(struct main_menu_data_s *d)
{
d->set_item_dimensions = main_menu_set_item_dimensions;
menu_make_page(menu_allocate_item(), "Game", MAIN_MENU_PAGE_GAME, MOO_KEY_g);
menu_make_page_conditional(menu_allocate_item(), "Game", MAIN_MENU_PAGE_GAME, main_menu_game_active, MOO_KEY_g);
menu_make_page(menu_allocate_item(), "Options", MAIN_MENU_PAGE_OPTIONS, MOO_KEY_o);
menu_make_page(menu_allocate_item(), "UI Preset", MAIN_MENU_PAGE_PRESET, MOO_KEY_p);
menu_make_action(menu_allocate_item(), "Quit to OS", MAIN_MENU_ACT_QUIT_GAME, MOO_KEY_q);
Expand Down Expand Up @@ -426,7 +452,7 @@ static void main_menu_make_options_sound_page(struct main_menu_data_s *d)
static void main_menu_make_options_video_page(struct main_menu_data_s *d)
{
d->set_item_dimensions = mm_options_set_item_dimensions;
menu_make_int(menu_allocate_item(), "UI scale", &ui_scale_hint, 1, UI_SCALE_MAX, MOO_KEY_s);
menu_make_int(menu_item_force_restart(menu_allocate_item()), "UI scale", &ui_scale_hint, 1, UI_SCALE_MAX, MOO_KEY_s);
hw_opt_menu_make_page_video();
menu_make_back(menu_allocate_item());
}
Expand Down Expand Up @@ -462,7 +488,22 @@ static void main_menu_make_options_interface_page(struct main_menu_data_s *d)

static void main_menu_make_options_rules_page(struct main_menu_data_s *d)
{
d->set_item_dimensions = mm_options_small_set_item_dimensions;
d->set_item_dimensions = mm_options_small2_set_item_dimensions;
menu_make_bool(menu_allocate_item(), "AI Transport Range Fix", &game_num_ai_trans_range_fix, MOO_KEY_UNKNOWN);
menu_make_bool(menu_allocate_item(), "Battle No Tohit Accumulation", &game_num_bt_no_tohit_acc, MOO_KEY_UNKNOWN);
menu_make_bool(menu_allocate_item(), "Battle Precap Tohit", &game_num_bt_precap_tohit, MOO_KEY_UNKNOWN);
menu_make_bool(menu_allocate_item(), "Battle Wait No Reload", &game_num_bt_wait_no_reload, MOO_KEY_UNKNOWN);
menu_make_bool(menu_allocate_item(), "Monster Rest Attack", &game_num_monster_rest_att, MOO_KEY_UNKNOWN);
menu_make_bool(menu_allocate_item(), "Population Tenths Fix", &game_num_pop_tenths_fix, MOO_KEY_UNKNOWN);
menu_make_bool(menu_allocate_item(), "Retreat Redir Fix", &game_num_retreat_redir_fix, MOO_KEY_UNKNOWN);
menu_make_bool(menu_allocate_item(), "Ship Scanner Fix", &game_num_ship_scanner_fix, MOO_KEY_UNKNOWN);
menu_make_bool(menu_allocate_item(), "Stargate Redirection Fix", &game_num_stargate_redir_fix, MOO_KEY_UNKNOWN);
menu_make_bool(menu_allocate_item(), "Transport Redirection Fix", &game_num_trans_redir_fix, MOO_KEY_UNKNOWN);
menu_make_bool(menu_allocate_item(), "Waste Calc Fix", &game_num_waste_calc_fix, MOO_KEY_UNKNOWN);
menu_make_bool(menu_allocate_item(), "AI Fleet Cheating Fix", &game_num_ai_fleet_cheating_fix, MOO_KEY_UNKNOWN);
menu_make_bool(menu_item_force_restart(menu_allocate_item()), "Apply Fix Bugs", &game_opt_fix_bugs, MOO_KEY_UNKNOWN);
menu_make_bool(menu_item_force_restart(menu_allocate_item()), "Apply Fix Guardian Repair", &game_opt_fix_guardian_repair, MOO_KEY_UNKNOWN);
menu_make_bool(menu_item_force_restart(menu_allocate_item()), "Apply Fix Starting Ships", &game_opt_fix_starting_ships, MOO_KEY_UNKNOWN);
menu_make_back(menu_allocate_item());
}

Expand Down Expand Up @@ -606,6 +647,9 @@ static int main_menu_get_item_wheel(struct main_menu_data_s *d, int16_t oi)
static void main_menu_item_do_plus(struct main_menu_data_s *d, int item_i)
{
const struct main_menu_item_s *it = &d->items[item_i];
if (it->data.need_restart) {
force_restart = true;
}
if (it->data.type == MENU_ITEM_TYPE_RETURN) {
d->ret = it->data.action_i;
d->flag_done = true;
Expand Down Expand Up @@ -650,6 +694,9 @@ static void main_menu_item_do_plus(struct main_menu_data_s *d, int item_i)
static void main_menu_item_do_minus(struct main_menu_data_s *d, int item_i)
{
const struct main_menu_item_s *it = &d->items[item_i];
if (it->data.need_restart) {
force_restart = true;
}
if (it->data.type == MENU_ITEM_TYPE_INT
|| it->data.type == MENU_ITEM_TYPE_ENUM) {
int *v = it->data.value_ptr;
Expand Down

0 comments on commit 212bcde

Please sign in to comment.