diff options
author | Manoj Srivastava <srivasta@debian.org> | 2020-05-23 00:33:19 -0700 |
---|---|---|
committer | Manoj Srivastava <srivasta@debian.org> | 2020-05-23 00:33:19 -0700 |
commit | d6b913d3ca2e84b75f3675fd6e9f5246c100cf27 (patch) | |
tree | 5fc28b7efc737bf2c79dc7d799e0a6013957fe11 /src | |
parent | c42f029316c0c004a795ca170bdb50644a800534 (diff) | |
parent | 73a0259be1d44fdb2ab34266ae0ff63f0d8f0b60 (diff) |
Merge branch 'master' into dgit/siddebian/2.4.0-ah-1archive/debian/2.4.0-ah-1
Diffstat (limited to 'src')
341 files changed, 20751 insertions, 39667 deletions
diff --git a/src/.gitignore b/src/.gitignore index 098f3b10..485f14c6 100644 --- a/src/.gitignore +++ b/src/.gitignore @@ -1,3 +1,7 @@ /harness -/tome +/tome-gcu +/tome-gtk2 +/tome-sdl +/tome-x11 +/tome-win *.plist diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index f4b2d2db..30ceb76c 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -1,6 +1,9 @@ INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/include) INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/bandit) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/fmt) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/pcg-cpp/include) +INCLUDE_DIRECTORIES(${CMAKE_CURRENT_SOURCE_DIR}/../vendor/jsoncons) # Add subdirectories ADD_SUBDIRECTORY (squelch) @@ -22,6 +25,7 @@ SET(SRCS_COMMON dice.cc dungeon.cc files.cc + game.cc gen_evol.cc gen_maze.cc generate.cc @@ -32,14 +36,17 @@ SET(SRCS_COMMON init1.cc init2.cc joke.cc + level_marker.cc levels.cc loadsave.cc lua_bind.cc melee1.cc melee2.cc + message.cc messages.cc mimic.cc modules.cc + monster_spell.cc monster_type.cc monster1.cc monster2.cc @@ -48,7 +55,9 @@ SET(SRCS_COMMON object1.cc object2.cc object_filter.cc + object_flag_meta.cc options.cc + player_type.cc powers.cc q_betwen.cc q_bounty.cc @@ -78,11 +87,9 @@ SET(SRCS_COMMON q_ultrag.cc q_wight.cc q_wolves.cc - quark.cc quest.cc randart.cc range.cc - script.cc skills.cc spell_type.cc spells1.cc @@ -92,15 +99,13 @@ SET(SRCS_COMMON spells5.cc spells6.cc squeltch.cc - status.cc store.cc tables.cc - traps.cc util.cc variable.cc wild.cc - wizard1.cc wizard2.cc + seed.cc xtra1.cc xtra2.cc z-form.c @@ -109,31 +114,27 @@ SET(SRCS_COMMON z-util.c ) -# Sources (PROGRAM) -SET(SRCS_PROGRAM - main-gcu.c - main-gtk2.c - main-sdl.c - main-x11.c - main.c -) - # Sources (TEST) SET(SRCS_TESTS ../tests/get_level_device.cc ../tests/harness.cc ../tests/lua_get_level.cc + ../tests/flag_set.cc + ../tests/grid.cc ) ADD_LIBRARY(game - ${SRCS_COMMON} + ${SRCS_COMMON} ${SRCS_VENDOR} ) +ADD_LIBRARY(game_main + main.cc) + # Need a few additional source files for Windows. -if(WIN32) +IF(WIN32) SET(SRCS ${SRCS} main-win.c) # Resource files require a little workaround. - if(MINGW) + IF(MINGW) # Workaround for resource compilation for mingw on CMake. # See http://www.cmake.org/Bug/view.php?id=4068 ADD_CUSTOM_COMMAND(OUTPUT ${CMAKE_CURRENT_BINARY_DIR}/angband_rc.o @@ -141,20 +142,44 @@ if(WIN32) -i${CMAKE_CURRENT_SOURCE_DIR}/angband.rc -o ${CMAKE_CURRENT_BINARY_DIR}/angband_rc.o) SET(SRCS ${SRCS} ${CMAKE_CURRENT_BINARY_DIR}/angband_rc.o) - else(MINGW) + ELSE(MINGW) SET(SRCS ${SRCS} angband.rc) - endif(MINGW) -endif(WIN32) + ENDIF(MINGW) + # Executable for Win32 + ADD_EXECUTABLE(tome-win WIN32 main-win.c) + TARGET_LINK_LIBRARIES(tome-win game squelch ${LIBS} winmm wsock32) + INSTALL(TARGETS tome-win RUNTIME DESTINATION bin) +ENDIF(WIN32) + +# tome executables +IF(X11_FOUND) + INCLUDE_DIRECTORIES(${X11_INCLUDE_DIR}) + ADD_EXECUTABLE(tome-x11 main-x11.c) + TARGET_LINK_LIBRARIES(tome-x11 game_main game squelch ${LIBS} ${X11_LIBRARIES}) + INSTALL(TARGETS tome-x11 RUNTIME DESTINATION bin) +ENDIF() -# tome executable -ADD_EXECUTABLE(tome ${EXECUTABLE_OPTIONS} ${SRCS_PROGRAM}) -TARGET_LINK_LIBRARIES(tome game squelch ${LIBS}) +IF(SDL_FOUND AND SDLIMAGE_FOUND AND SDLTTF_FOUND) + INCLUDE_DIRECTORIES(${SDL_INCLUDE_DIR} ${SDLIMAGE_INCLUDE_DIR} ${SDLTTF_INCLUDE_DIR}) + ADD_EXECUTABLE(tome-sdl main-sdl.c) + TARGET_LINK_LIBRARIES(tome-sdl game_main game squelch ${LIBS} ${SDLIMAGE_LIBRARY} ${SDLTTF_LIBRARY} ${SDL_LIBRARY} m) + INSTALL(TARGETS tome-sdl RUNTIME DESTINATION bin) +ENDIF() + +IF(CURSES_FOUND) + INCLUDE_DIRECTORIES(${CURSES_INCLUDE_DIR}) + ADD_EXECUTABLE(tome-gcu main-gcu.c) + TARGET_LINK_LIBRARIES(tome-gcu game_main game squelch ${LIBS} ${CURSES_LIBRARIES}) + INSTALL(TARGETS tome-gcu RUNTIME DESTINATION bin) +ENDIF() + +IF(GTK2_FOUND) + INCLUDE_DIRECTORIES(${GTK2_INCLUDE_DIRS}) + ADD_EXECUTABLE(tome-gtk2 main-gtk2.c) + TARGET_LINK_LIBRARIES(tome-gtk2 game_main game squelch ${LIBS} ${GTK2_LIBRARIES}) + INSTALL(TARGETS tome-gtk2 RUNTIME DESTINATION bin) +ENDIF() # test harness executable -ADD_EXECUTABLE(harness ${EXECUTABLE_OPTIONS} ${SRCS_TESTS}) +ADD_EXECUTABLE(harness ${SRCS_TESTS}) TARGET_LINK_LIBRARIES(harness game squelch ${LIBS}) - -# Installation -INSTALL(TARGETS tome - RUNTIME DESTINATION games -) diff --git a/src/ability_type.hpp b/src/ability_type.hpp index ea8a921d..0ec596ba 100644 --- a/src/ability_type.hpp +++ b/src/ability_type.hpp @@ -1,5 +1,8 @@ #pragma once +#include <string> +#include <vector> + #include "h-basic.h" /** @@ -7,21 +10,38 @@ */ struct ability_type { - const char *name; /* Name */ - char *desc; /* Description */ +public: + struct skill_requirement { + s16b skill_idx = 0; + s16b level = 0; + }; + +public: + std::string name; /* Name */ + std::string desc; /* Description */ + + std::string action_desc; /* Action Description */ + + s16b action_mkey = 0; /* Action do to */ + + s16b cost = 0; /* Skill points cost */ - const char *action_desc; /* Action Description */ + std::vector<skill_requirement> need_skills; /* List of prereq skills */ - s16b action_mkey; /* Action do to */ + s16b stat[6] { }; /* List of prereq stats */ - s16b cost; /* Skill points cost */ + std::vector<s16b> need_abilities; /* List of prereq abilities */ - bool_ acquired; /* Do the player actualylg ot it ? */ + /** + * Default constructor + */ + ability_type() + { + for (auto &stat_ref: stat) + { + // Requirement is always met unless otherwise specified. + stat_ref = -1; + } + } - /* Prereqs */ - s16b skills[10]; /* List of prereq skills(10 max) */ - s16b skill_levels[10]; /* List of prereq skills(10 max) */ - s16b stat[6]; /* List of prereq stats */ - s16b need_abilities[10]; /* List of prereq abilities(10 max) */ - s16b forbid_abilities[10]; /* List of forbidden abilities(10 max) */ }; diff --git a/src/ability_type_fwd.hpp b/src/ability_type_fwd.hpp deleted file mode 100644 index bade8638..00000000 --- a/src/ability_type_fwd.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -struct ability_type; diff --git a/src/alloc.hpp b/src/alloc.hpp new file mode 100644 index 00000000..1d4ce815 --- /dev/null +++ b/src/alloc.hpp @@ -0,0 +1,29 @@ +#pragma once + +#include "h-basic.h" +#include "alloc_entry.hpp" + +#include <vector> + +/** + * Allocations of object kinds and monster races. + */ +struct Alloc { + + /* + * The entries in the "kind allocator table" + */ + std::vector<alloc_entry> kind_table; + + /* + * The flag to tell if kind_table contains valid entries + * for normal (i.e. kind_is_legal) object allocation + */ + bool kind_table_valid = false; + + /* + * The entries in the "race allocator table" + */ + std::vector<alloc_entry> race_table; + +}; diff --git a/src/alloc_entry.hpp b/src/alloc_entry.hpp index 41ec3b66..5e0e547f 100644 --- a/src/alloc_entry.hpp +++ b/src/alloc_entry.hpp @@ -11,10 +11,10 @@ */ struct alloc_entry { - s16b index; /* The actual index */ + s16b index = -1; /* The actual index */ - byte level; /* Base dungeon level */ - byte prob1; /* Probability, pass 1 */ - byte prob2; /* Probability, pass 2 */ - byte prob3; /* Probability, pass 3 */ + byte level = 0; /* Base dungeon level */ + byte prob1 = 0; /* Probability, pass 1 */ + byte prob2 = 0; /* Probability, pass 2 */ + byte prob3 = 0; /* Probability, pass 3 */ }; diff --git a/src/artifact_type.hpp b/src/artifact_type.hpp index 7a4340aa..9f866aa7 100644 --- a/src/artifact_type.hpp +++ b/src/artifact_type.hpp @@ -1,6 +1,7 @@ #pragma once #include "h-basic.h" +#include "object_flag_set.hpp" /** * Artifact descriptor. @@ -11,50 +12,39 @@ */ struct artifact_type { - char const *name; /* Artifact name */ - char *text; /* Artifact description */ + char const *name = nullptr; /* Artifact name */ + char *text = nullptr; /* Artifact description */ - byte tval; /* Artifact type */ - byte sval; /* Artifact sub type */ + byte tval = 0; /* Artifact type */ + byte sval = 0; /* Artifact sub type */ - s16b pval; /* Artifact extra info */ + s16b pval = 0; /* Artifact extra info */ - s16b to_h; /* Bonus to hit */ - s16b to_d; /* Bonus to damage */ - s16b to_a; /* Bonus to armor */ + s16b to_h = 0; /* Bonus to hit */ + s16b to_d = 0; /* Bonus to damage */ + s16b to_a = 0; /* Bonus to armor */ - s16b activate; /* Activation Number */ + s16b activate = 0; /* Activation Number */ - s16b ac; /* Base armor */ + s16b ac = 0; /* Base armor */ - byte dd, ds; /* Damage when hits */ + byte dd = 0; /* Damage dice */ + byte ds = 0; /* Damage sides */ - s16b weight; /* Weight */ + s16b weight = 0; /* Weight */ - s32b cost; /* Artifact "cost" */ + s32b cost = 0; /* Artifact "cost" */ - u32b flags1; /* Artifact Flags, set 1 */ - u32b flags2; /* Artifact Flags, set 2 */ - u32b flags3; /* Artifact Flags, set 3 */ - u32b flags4; /* Artifact Flags, set 4 */ - u32b flags5; /* Artifact Flags, set 5 */ + object_flag_set flags; /* Artifact Flags */ + object_flag_set oflags; /* Obvious Flags */ - u32b oflags1; /* Obvious Flags, set 1 */ - u32b oflags2; /* Obvious Flags, set 2 */ - u32b oflags3; /* Obvious Flags, set 3 */ - u32b oflags4; /* Obvious Flags, set 4 */ - u32b oflags5; /* Obvious Flags, set 5 */ + byte level = 0; /* Artifact level */ + byte rarity = 0; /* Artifact rarity */ - byte level; /* Artifact level */ - byte rarity; /* Artifact rarity */ + byte cur_num = 0; /* Number created (0 or 1) */ - byte cur_num; /* Number created (0 or 1) */ - byte max_num; /* Unused (should be "1") */ + s16b power = 0; /* Power granted, if any */ - u32b esp; /* ESP flags */ - u32b oesp; /* ESP flags */ + s16b set = 0; /* Which set does it belong it, if any? */ - s16b power; /* Power granted(if any) */ - - s16b set; /* Does it belongs to a set ?*/ }; diff --git a/src/artifact_type_fwd.hpp b/src/artifact_type_fwd.hpp deleted file mode 100644 index f3862d5a..00000000 --- a/src/artifact_type_fwd.hpp +++ /dev/null @@ -1,3 +0,0 @@ -#pragma once - -struct artifact_type; diff --git a/src/birth.cc b/src/birth.cc index f3897496..f677e6e1 100644 --- a/src/birth.cc +++ b/src/birth.cc @@ -6,27 +6,27 @@ * included in all such copies. */ #include "birth.hpp" -#include "birth.h" #include "ability_type.hpp" #include "artifact_type.hpp" #include "corrupt.hpp" #include "cmd4.hpp" #include "cmd5.hpp" +#include "dungeon_flag.hpp" #include "dungeon_info_type.hpp" #include "files.h" #include "files.hpp" +#include "game.hpp" #include "gods.hpp" #include "help.hpp" -#include "hist_type.hpp" #include "hooks.hpp" #include "init2.hpp" #include "mimic.hpp" #include "messages.hpp" -#include "meta_class_type.hpp" #include "modules.hpp" #include "monster2.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" #include "notes.hpp" #include "object1.hpp" #include "object2.hpp" @@ -34,6 +34,7 @@ #include "options.hpp" #include "player_class.hpp" #include "player_race.hpp" +#include "player_race_flag.hpp" #include "player_race_mod.hpp" #include "player_type.hpp" #include "q_rand.hpp" @@ -46,7 +47,6 @@ #include "store.hpp" #include "tables.hpp" #include "town_type.hpp" -#include "trap_type.hpp" #include "util.hpp" #include "util.h" #include "variable.h" @@ -56,6 +56,10 @@ #include "xtra2.hpp" #include "z-rand.hpp" +#include <algorithm> +#include <boost/filesystem.hpp> +#include <fmt/format.h> +#include <numeric> #include <string> /* @@ -100,73 +104,48 @@ static s32b auto_round; */ static s32b last_round; -/* Human */ -static const char *human_syllable1[] = -{ - "Ab", "Ac", "Ad", "Af", "Agr", "Ast", "As", "Al", "Adw", "Adr", "Ar", - "B", "Br", "C", "Cr", "Ch", "Cad", "D", "Dr", "Dw", "Ed", "Eth", "Et", - "Er", "El", "Eow", "F", "Fr", "G", "Gr", "Gw", "Gal", "Gl", "H", "Ha", - "Ib", "Jer", "K", "Ka", "Ked", "L", "Loth", "Lar", "Leg", "M", "Mir", - "N", "Nyd", "Ol", "Oc", "On", "P", "Pr", "R", "Rh", "S", "Sev", "T", - "Tr", "Th", "V", "Y", "Z", "W", "Wic", -}; - -static const char *human_syllable2[] = -{ - "a", "ae", "au", "ao", "are", "ale", "ali", "ay", "ardo", "e", "ei", - "ea", "eri", "era", "ela", "eli", "enda", "erra", "i", "ia", "ie", - "ire", "ira", "ila", "ili", "ira", "igo", "o", "oa", "oi", "oe", - "ore", "u", "y", -}; - -static const char *human_syllable3[] = -{ - "a", "and", "b", "bwyn", "baen", "bard", "c", "ctred", "cred", "ch", - "can", "d", "dan", "don", "der", "dric", "dfrid", "dus", "f", "g", - "gord", "gan", "l", "li", "lgrin", "lin", "lith", "lath", "loth", - "ld", "ldric", "ldan", "m", "mas", "mos", "mar", "mond", "n", - "nydd", "nidd", "nnon", "nwan", "nyth", "nad", "nn", "nnor", "nd", - "p", "r", "ron", "rd", "s", "sh", "seth", "sean", "t", "th", "tha", - "tlan", "trem", "tram", "v", "vudd", "w", "wan", "win", "wyn", "wyr", - "wyr", "wyth", -}; - /* * Random Name Generator * based on a Javascript by Michael Hensley * "http://geocities.com/timessquare/castle/6274/" */ -static void create_random_name(int race, char *name) +static std::string create_random_name() { - const char *syl1, *syl2, *syl3; - - int idx; - - - /* Paranoia */ - if (!name) return; - - /* Select the monster type */ - switch (race) - { - /* Create the monster name */ - - /* Use human ones */ - default: - { - idx = rand_int(sizeof(human_syllable1) / sizeof(char *)); - syl1 = human_syllable1[idx]; - idx = rand_int(sizeof(human_syllable2) / sizeof(char *)); - syl2 = human_syllable2[idx]; - idx = rand_int(sizeof(human_syllable3) / sizeof(char *)); - syl3 = human_syllable3[idx]; - - break; - } - } - - /* Concatenate selected syllables */ - strnfmt(name, 32, "%s%s%s", syl1, syl2, syl3); + static const std::vector<std::string> human_syllable1 + { + "Ab", "Ac", "Ad", "Af", "Agr", "Ast", "As", "Al", "Adw", "Adr", "Ar", + "B", "Br", "C", "Cr", "Ch", "Cad", "D", "Dr", "Dw", "Ed", "Eth", "Et", + "Er", "El", "Eow", "F", "Fr", "G", "Gr", "Gw", "Gal", "Gl", "H", "Ha", + "Ib", "Jer", "K", "Ka", "Ked", "L", "Loth", "Lar", "Leg", "M", "Mir", + "N", "Nyd", "Ol", "Oc", "On", "P", "Pr", "R", "Rh", "S", "Sev", "T", + "Tr", "Th", "V", "Y", "Z", "W", "Wic", + }; + + static const std::vector<std::string> human_syllable2 + { + "a", "ae", "au", "ao", "are", "ale", "ali", "ay", "ardo", "e", "ei", + "ea", "eri", "era", "ela", "eli", "enda", "erra", "i", "ia", "ie", + "ire", "ira", "ila", "ili", "ira", "igo", "o", "oa", "oi", "oe", + "ore", "u", "y", + }; + + static const std::vector<std::string> human_syllable3 + { + "a", "and", "b", "bwyn", "baen", "bard", "c", "ctred", "cred", "ch", + "can", "d", "dan", "don", "der", "dric", "dfrid", "dus", "f", "g", + "gord", "gan", "l", "li", "lgrin", "lin", "lith", "lath", "loth", + "ld", "ldric", "ldan", "m", "mas", "mos", "mar", "mond", "n", + "nydd", "nidd", "nnon", "nwan", "nyth", "nad", "nn", "nnor", "nd", + "p", "r", "ron", "rd", "s", "sh", "seth", "sean", "t", "th", "tha", + "tlan", "trem", "tram", "v", "vudd", "w", "wan", "win", "wyn", "wyr", + "wyr", "wyth", + }; + + auto const &syl1 = *uniform_element(human_syllable1); + auto const &syl2 = *uniform_element(human_syllable2); + auto const &syl3 = *uniform_element(human_syllable3); + + return syl1 + syl2 + syl3; } @@ -197,15 +176,13 @@ void print_desc(cptr txt) /* * Save the current data for later */ -static void save_prev_data(void) +static void save_prev_data() { - int i; - + auto &previous_char = game->previous_char; /*** Save the current data ***/ /* Save the data */ - previous_char.sex = p_ptr->psex; previous_char.race = p_ptr->prace; previous_char.rmod = p_ptr->pracem; previous_char.pclass = p_ptr->pclass; @@ -216,24 +193,14 @@ static void save_prev_data(void) previous_char.god = p_ptr->pgod; previous_char.grace = p_ptr->grace; - previous_char.age = p_ptr->age; - previous_char.wt = p_ptr->wt; - previous_char.ht = p_ptr->ht; - previous_char.sc = p_ptr->sc; previous_char.au = p_ptr->au; /* Save the stats */ - for (i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) { previous_char.stat[i] = p_ptr->stat_max[i]; } previous_char.luck = p_ptr->luck_base; - - /* Save the history */ - for (i = 0; i < 4; i++) - { - strcpy(previous_char.history[i], history[i]); - } } @@ -242,45 +209,29 @@ static void save_prev_data(void) */ static void load_prev_data(bool_ save) { - int i; - + auto &previous_char = game->previous_char; birther temp; /*** Save the current data ***/ /* Save the data */ - temp.age = p_ptr->age; - temp.wt = p_ptr->wt; - temp.ht = p_ptr->ht; - temp.sc = p_ptr->sc; temp.au = p_ptr->au; /* Save the stats */ - for (i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) { temp.stat[i] = p_ptr->stat_max[i]; } temp.luck = p_ptr->luck_base; - /* Save the history */ - for (i = 0; i < 4; i++) - { - strcpy(temp.history[i], history[i]); - } - - /*** Load the previous data ***/ /* Load the data */ - p_ptr->age = previous_char.age; - p_ptr->wt = previous_char.wt; - p_ptr->ht = previous_char.ht; - p_ptr->sc = previous_char.sc; p_ptr->au = previous_char.au; /* Load the stats */ - for (i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) { p_ptr->stat_max[i] = previous_char.stat[i]; p_ptr->stat_cur[i] = previous_char.stat[i]; @@ -288,35 +239,19 @@ static void load_prev_data(bool_ save) p_ptr->luck_base = previous_char.luck; p_ptr->luck_max = previous_char.luck; - /* Load the history */ - for (i = 0; i < 4; i++) - { - strcpy(history[i], previous_char.history[i]); - } - /*** Save the current data ***/ if (!save) return; /* Save the data */ - previous_char.age = temp.age; - previous_char.wt = temp.wt; - previous_char.ht = temp.ht; - previous_char.sc = temp.sc; previous_char.au = temp.au; /* Save the stats */ - for (i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) { previous_char.stat[i] = temp.stat[i]; } previous_char.luck = temp.luck; - - /* Save the history */ - for (i = 0; i < 4; i++) - { - strcpy(previous_char.history[i], temp.history[i]); - } } @@ -385,7 +320,7 @@ static int adjust_stat(int value, int amount, int auto_roll) * * For efficiency, we include a chunk of "calc_bonuses()". */ -static void get_stats(void) +static void get_stats() { int i, j; @@ -436,7 +371,7 @@ static void get_stats(void) p_ptr->stat_max[i] = j; /* Obtain a "bonus" for "race" and "class" */ - bonus = rp_ptr->r_adj[i] + rmp_ptr->r_adj[i] + cp_ptr->c_adj[i]; + bonus = rp_ptr->ps.adj[i] + rmp_ptr->ps.adj[i] + cp_ptr->ps.adj[i]; /* Start fully healed */ p_ptr->stat_cur[i] = p_ptr->stat_max[i]; @@ -456,289 +391,121 @@ static void get_stats(void) /* - * Roll for some info that the auto-roller ignores + * Roll for player HP */ -static void get_extra(void) +void roll_player_hp() { - int i, j, min_value, max_value; + auto &player_hp = game->player_hp; + // Minimum hitpoints at highest level + int const min_value = + (PY_MAX_LEVEL * (p_ptr->hitdie - 1) * 3) / 8 + PY_MAX_LEVEL; - /* Level one */ - p_ptr->max_plv = p_ptr->lev = 1; - - /* Experience factor */ - p_ptr->expfact = rp_ptr->r_exp + rmp_ptr->r_exp + cp_ptr->c_exp; + // Maximum hitpoints at highest level + int const max_value = + (PY_MAX_LEVEL * (p_ptr->hitdie - 1) * 5) / 8 + PY_MAX_LEVEL; - /* Initialize quest */ - p_ptr->inside_quest = 0; - - /* Hitdice */ - p_ptr->hitdie = rp_ptr->r_mhp + rmp_ptr->r_mhp + cp_ptr->c_mhp; - - /* Initial hitpoints */ - p_ptr->mhp = p_ptr->hitdie; - - /* Minimum hitpoints at highest level */ - min_value = (PY_MAX_LEVEL * (p_ptr->hitdie - 1) * 3) / 8; - min_value += PY_MAX_LEVEL; - - /* Maximum hitpoints at highest level */ - max_value = (PY_MAX_LEVEL * (p_ptr->hitdie - 1) * 5) / 8; - max_value += PY_MAX_LEVEL; - - /* Pre-calculate level 1 hitdice */ + // Pre-calculate level 1 hitdice; first roll is always maximal player_hp[0] = p_ptr->hitdie; - /* Roll out the hitpoints */ - while (TRUE) + // Roll out the hitpoints + while (true) { - /* Roll the hitpoint values */ - for (i = 1; i < PY_MAX_LEVEL; i++) - { - j = randint(p_ptr->hitdie); - player_hp[i] = player_hp[i - 1] + j; - } + // Roll the hitpoint values + std::generate( + player_hp.begin() + 1, + player_hp.end(), + []() { return randint(p_ptr->hitdie); }); - /* XXX Could also require acceptable "mid-level" hitpoints */ + // Sum along + std::partial_sum( + player_hp.begin(), + player_hp.end(), + player_hp.begin()); - /* Require "valid" hitpoints at highest level */ - if (player_hp[PY_MAX_LEVEL - 1] < min_value) continue; - if (player_hp[PY_MAX_LEVEL - 1] > max_value) continue; + // Require "valid" hitpoints at highest level + if (player_hp.back() < min_value) continue; + if (player_hp.back() > max_value) continue; - /* Acceptable */ + // Acceptable break; } - - p_ptr->tactic = 4; - p_ptr->movement = 4; } /* - * Get the racial history, and social class, using the "history charts". + * Roll for some info that the auto-roller ignores */ -static void get_history(void) +static void get_extra() { - int i, n, chart, roll, social_class; - - char *s, *t; - - char buf[240]; - - - /* Clear the previous history strings */ - for (i = 0; i < 4; i++) history[i][0] = '\0'; - - /* Clear the history text */ - buf[0] = '\0'; - - /* Initial social class */ - social_class = randint(4); - - /* Starting place */ - chart = rp_ptr->chart; - - /* Process the history */ - while (chart) - { - /* Start over */ - i = 0; - - /* Roll for nobility */ - roll = randint(100); - - - /* Access the proper entry in the table */ - while ((chart != bg[i].chart) || (roll > bg[i].roll)) i++; - - /* Acquire the textual history */ - (void)strcat(buf, bg[i].info); - - /* Add in the social class */ - social_class += (int)(bg[i].bonus) - 50; - - /* Enter the next chart */ - chart = bg[i].next; - } - - - - /* Verify social class */ - if (social_class > 100) social_class = 100; - else if (social_class < 1) social_class = 1; - - /* Save the social class */ - p_ptr->sc = social_class; - - - /* Skip leading spaces */ - for (s = buf; *s == ' '; s++) /* loop */; - - /* Get apparent length */ - n = strlen(s); - - /* Kill trailing spaces */ - while ((n > 0) && (s[n - 1] == ' ')) s[--n] = '\0'; - - - /* Start at first line */ - i = 0; - - /* Collect the history */ - while (TRUE) - { - /* Extract remaining length */ - n = strlen(s); - - /* All done */ - if (n < 60) - { - /* Save one line of history */ - strcpy(history[i++], s); + /* Level one */ + p_ptr->max_plv = p_ptr->lev = 1; - /* All done */ - break; - } + /* Experience factor */ + p_ptr->expfact = rp_ptr->ps.exp + rmp_ptr->ps.exp + cp_ptr->ps.exp; - /* Find a reasonable break-point */ - for (n = 60; ((n > 0) && (s[n - 1] != ' ')); n--) /* loop */; + /* Initialize quest */ + p_ptr->inside_quest = 0; - /* Save next location */ - t = s + n; + /* Hitdice */ + p_ptr->hitdie = rp_ptr->ps.mhp + rmp_ptr->ps.mhp + cp_ptr->ps.mhp; - /* Wipe trailing spaces */ - while ((n > 0) && (s[n - 1] == ' ')) s[--n] = '\0'; + /* Initial hitpoints */ + p_ptr->mhp = p_ptr->hitdie; - /* Save one line of history */ - strcpy(history[i++], s); + /* Roll for HP */ + roll_player_hp(); - /* Start next line */ - for (s = t; *s == ' '; s++) /* loop */; - } + /* Set tactics and movement */ + p_ptr->tactic = 4; + p_ptr->movement = 4; } /* * Fill the random_artifacts array with relevant info. */ -static errr init_randart(void) +static errr init_randart() { - int i; - - long cost; - - random_artifact* ra_ptr; - char buf[80]; - - for (i = 0; i < MAX_RANDARTS; i++) + for (int i = 0; i < MAX_RANDARTS; i++) { - ra_ptr = &random_artifacts[i]; - - strcpy(ra_ptr->name_short, - get_line("rart_s.txt", ANGBAND_DIR_FILE, buf, i)); - strcpy(ra_ptr->name_full, - get_line("rart_f.txt", ANGBAND_DIR_FILE, buf, i)); - - ra_ptr->attr = randint(15); - ra_ptr->activation = rand_int(MAX_T_ACT); - ra_ptr->generated = FALSE; - - cost = randnor(0, 250); + // Generate a 'cost' + auto cost = randnor(0, 250); + if (cost < 0) + { + cost = 0; + } - if (cost < 0) cost = 0; + // Generate the random artifact + random_artifact ra; + ra.name_short = get_line("rart_s.txt", ANGBAND_DIR_FILE, buf, i); + ra.name_full = get_line("rart_f.txt", ANGBAND_DIR_FILE, buf, i); + ra.attr = randint(15); + ra.activation = rand_int(MAX_T_ACT); + ra.generated = FALSE; + ra.cost = cost; - ra_ptr->cost = cost; + // Push + game->random_artifacts.push_back(ra); } return 0; } -/* - * A helper function for get_ahw(), also called by polymorph code - */ -void get_height_weight(void) -{ - int h_mean, h_stddev; - - int w_mean, w_stddev; - - - /* Extract mean and standard deviation -- Male */ - if (p_ptr->psex == SEX_MALE) - { - h_mean = rp_ptr->m_b_ht + rmp_ptr->m_b_ht; - h_stddev = rp_ptr->m_m_ht + rmp_ptr->m_m_ht; - - w_mean = rp_ptr->m_b_wt + rmp_ptr->m_b_wt; - w_stddev = rp_ptr->m_m_wt + rmp_ptr->m_m_wt; - } - - /* Female */ - else if (p_ptr->psex == SEX_FEMALE) - { - h_mean = rp_ptr->f_b_ht + rmp_ptr->f_b_ht; - h_stddev = rp_ptr->f_m_ht + rmp_ptr->f_m_ht; - - w_mean = rp_ptr->f_b_wt + rmp_ptr->f_b_wt; - w_stddev = rp_ptr->f_m_wt + rmp_ptr->f_m_wt; - } - - /* Neuter XXX */ - else - { - h_mean = (rp_ptr->m_b_ht + rmp_ptr->m_b_ht + - rp_ptr->f_b_ht + rmp_ptr->f_b_ht) / 2, - h_stddev = (rp_ptr->m_m_ht + rmp_ptr->m_m_ht + - rp_ptr->f_m_ht + rmp_ptr->f_m_ht) / 2; - - w_mean = (rp_ptr->m_b_wt + rmp_ptr->m_b_wt + - rp_ptr->f_b_wt + rmp_ptr->f_b_wt) / 2, - w_stddev = (rp_ptr->m_m_wt + rmp_ptr->m_m_wt + - rp_ptr->f_m_wt + rmp_ptr->f_m_wt) / 2; - } - - /* Calculate height/weight */ - p_ptr->ht = randnor(h_mean, h_stddev); - p_ptr->wt = randnor(w_mean, w_stddev); - - /* Weight/height shouldn't be negative */ - if (p_ptr->ht < 1) p_ptr->ht = 1; - if (p_ptr->wt < 1) p_ptr->wt = 1; -} - - -/* - * Computes character's age, height, and weight - */ -static void get_ahw(void) -{ - /* Calculate the age */ - p_ptr->age = rp_ptr->b_age + rmp_ptr->b_age + - randint(rp_ptr->m_age + rmp_ptr->m_age); - - /* Calculate the height/weight */ - get_height_weight(); -} - - - /* * Get the player's starting money */ -static void get_money(void) +static void get_money() { - int i, gold; - - - /* Social Class determines starting gold */ - gold = (p_ptr->sc * 6) + randint(100) + 300; + /* Starting gold */ + int gold = randint(100) + 300; /* Process the stats */ - for (i = 0; i < 6; i++) + for (int i = 0; i < 6; i++) { /* Mega-Hack -- reduce gold for high stats */ if (stat_use[i] >= 18 + 50) gold -= 300; @@ -761,7 +528,7 @@ static void get_money(void) * * See 'display_player()' for basic method. */ -static void birth_put_stats(void) +static void birth_put_stats() { int i, p; @@ -798,17 +565,19 @@ static void birth_put_stats(void) /* * Clear all the global "character" data */ -static void player_wipe(void) +static void player_wipe() { - int i, j; - + auto const &d_info = game->edit_data.d_info; + auto &r_info = game->edit_data.r_info; + auto &k_info = game->edit_data.k_info; + auto &a_info = game->edit_data.a_info; + auto &level_markers = game->level_markers; /* Wipe special levels */ wipe_saved(); /* Hack -- zero the struct */ - static_assert(std::is_pod<player_type>::value, "Cannot memset non-POD type"); - memset(p_ptr, 0, sizeof(player_type)); + *p_ptr = player_type(); /* Level 1 is the first level */ p_ptr->lev = 1; @@ -816,33 +585,23 @@ static void player_wipe(void) /* Not dead yet */ p_ptr->lives = 0; - /* Wipe the history */ - for (i = 0; i < 4; i++) - { - for (j = 0; j < 60; j++) - { - if (j < 59) history[i][j] = ' '; - else history[i][j] = '\0'; - } - } - /* Wipe the towns */ - for (i = 0; i < max_d_idx; i++) + for (auto &&i: level_markers) { - for (j = 0; j < MAX_DUNGEON_DEPTH; j++) + for (auto &&j: i) { - special_lvl[j][i] = 0; + j = level_marker::NORMAL; } } /* Wipe the towns */ - for (i = max_real_towns + 1; i < max_towns; i++) + for (std::size_t i = max_real_towns + 1; i < max_towns; i++) { town_info[i].flags = 0; } /* Wipe the quests */ - for (i = 0; i < MAX_Q_IDX; i++) + for (std::size_t i = 0; i < MAX_Q_IDX; i++) { quest[i].status = QUEST_STATUS_UNTAKEN; for (auto &quest_data : quest[i].data) @@ -851,22 +610,12 @@ static void player_wipe(void) } } - /* Wipe the rune spells */ - rune_num = 0; - for (i = 0; i < MAX_RUNES; i++) - { - strcpy(rune_spells[i].name, ""); - rune_spells[i].type = 0; - rune_spells[i].rune2 = 0; - rune_spells[i].mana = 0; - } - /* No items */ inven_cnt = 0; equip_cnt = 0; /* Clear the inventory */ - for (i = 0; i < INVEN_TOTAL; i++) + for (std::size_t i = 0; i < INVEN_TOTAL; i++) { object_wipe(&p_ptr->inventory[i]); } @@ -875,32 +624,29 @@ static void player_wipe(void) init_randart(); /* Start with no artifacts made yet */ - for (i = 0; i < max_a_idx; i++) + for (auto &a_ref: a_info) { - artifact_type *a_ptr = &a_info[i]; - a_ptr->cur_num = 0; + a_ref.cur_num = 0; } /* Reset the "objects" */ - for (i = 1; i < max_k_idx; i++) + for (auto &k_ref: k_info) { - object_kind *k_ptr = &k_info[i]; - /* Reset "tried" */ - k_ptr->tried = FALSE; + k_ref.tried = FALSE; /* Reset "aware" */ - k_ptr->aware = FALSE; + k_ref.aware = FALSE; /* Reset "artifact" */ - k_ptr->artifact = 0; + k_ref.artifact = 0; } /* Reset the "monsters" */ - for (i = 1; i < max_r_idx; i++) + for (auto &r_ref: r_info) { - monster_race *r_ptr = &r_info[i]; + auto r_ptr = &r_ref; /* Hack -- Reset the counter */ r_ptr->cur_num = 0; @@ -909,8 +655,7 @@ static void player_wipe(void) r_ptr->max_num = 100; /* Hack -- Reset the max counter */ - if (r_ptr->flags1 & RF1_UNIQUE) r_ptr->max_num = 1; - if (r_ptr->flags3 & RF3_UNIQUE_4) r_ptr->max_num = 4; + if (r_ptr->flags & RF_UNIQUE) r_ptr->max_num = 1; /* Clear player kills */ r_ptr->r_pkills = 0; @@ -924,12 +669,7 @@ static void player_wipe(void) p_ptr->food = PY_FOOD_FULL - 1; /* Clear "cheat" options */ - cheat_peek = FALSE; - cheat_hear = FALSE; - cheat_room = FALSE; - cheat_xtra = FALSE; - cheat_know = FALSE; - cheat_live = FALSE; + options->reset_cheat_options(); /* Assume no winning game */ total_winner = 0; @@ -939,11 +679,8 @@ static void player_wipe(void) noscore = 0; wizard = 0; - /* Assume no innate spells */ - spell_num = 0; - /* Clear the fate */ - for (i = 0; i < MAX_FATES; i++) + for (std::size_t i = 0; i < MAX_FATES; i++) { fates[i].fate = 0; } @@ -971,22 +708,15 @@ static void player_wipe(void) doppleganger = 0; /* Wipe the recall depths */ - for (i = 0; i < max_d_idx; i++) + for (std::size_t i = 0; i < d_info.size(); i++) { max_dlv[i] = 0; } /* Wipe the known inscription list */ - for (i = 0; i < MAX_INSCRIPTIONS; i++) - { - inscription_info[i].know = FALSE; - } - - /* Wipe the known traps list */ - for (i = 0; i < max_t_idx; i++) + for (auto &inscription_known: p_ptr->inscriptions) { - t_info[i].known = 0; - t_info[i].ident = FALSE; + inscription_known = false; } /* Reset wild_mode to FALSE */ @@ -997,7 +727,7 @@ static void player_wipe(void) p_ptr->allow_one_death = 0; /* Wipe the power list */ - for (i = 0; i < POWER_MAX; i++) + for (std::size_t i = 0; i < POWER_MAX; i++) { p_ptr->powers_mod[i] = 0; } @@ -1014,29 +744,39 @@ static void player_wipe(void) /* Create an object */ -void outfit_obj(int tv, int sv, int pval, int dd, int ds) +static void outfit_obj(object_proto const *proto) { object_type forge; - object_type *q_ptr; /* Get local object */ - q_ptr = &forge; + auto q_ptr = &forge; q_ptr->pval = 0; q_ptr->pval2 = 0; /* Hack -- Give the player an object */ - object_prep(q_ptr, lookup_kind(tv, sv)); + object_prep(q_ptr, lookup_kind(proto->tval, proto->sval)); - if (pval) - q_ptr->pval = pval; + if (proto->pval) + { + q_ptr->pval = proto->pval; + } /* These objects are "storebought" */ q_ptr->ident |= IDENT_MENTAL; - q_ptr->number = damroll(dd, ds); + q_ptr->number = damroll(proto->dd, proto->ds); object_aware(q_ptr); object_known(q_ptr); - (void)inven_carry(q_ptr, FALSE); + inven_carry(q_ptr, FALSE); +} + + +static void outfit_objs(std::vector<object_proto> const &protos) +{ + for (auto const &proto: protos) + { + outfit_obj(&proto); + } } @@ -1051,7 +791,7 @@ static void player_outfit_object(int qty, int tval, int sval) q_ptr->number = qty; object_aware(q_ptr); object_known(q_ptr); - (void)inven_carry(q_ptr, FALSE); + inven_carry(q_ptr, FALSE); } @@ -1074,11 +814,11 @@ static void player_outfit_spellbook(cptr spell_name) * * Having an item makes the player "aware" of its purpose. */ -static void player_outfit(void) +static void player_outfit() { - int i; + // Shorthand names for convenience cptr class_name = spp_ptr->title; - cptr subrace_name = rmp_ptr->title; + auto const &subrace_name = rmp_ptr->title; /* * Get an adventurer guide describing a bit of the @@ -1144,37 +884,37 @@ static void player_outfit(void) } /* Dragons */ - if (streq(subrace_name, "Red")) + if (subrace_name == "Red") { player_outfit_spellbook("Globe of Light"); } - if (streq(subrace_name, "Black")) + if (subrace_name == "Black") { player_outfit_spellbook("Geyser"); } - if (streq(subrace_name, "Green")) + if (subrace_name == "Green") { player_outfit_spellbook("Noxious Cloud"); } - if (streq(subrace_name, "Blue")) + if (subrace_name == "Blue") { player_outfit_spellbook("Stone Skin"); } - if (streq(subrace_name, "White")) + if (subrace_name == "White") { player_outfit_spellbook("Sense Monsters"); } - if (streq(subrace_name, "Ethereal")) + if (subrace_name == "Ethereal") { player_outfit_spellbook("Recharge"); } /* Demons */ - if (streq(subrace_name, "(Aewrog)")) + if (subrace_name == "(Aewrog)") { player_outfit_spellbook("Charm"); } - if (streq(subrace_name, "(Narrog)")) + if (subrace_name == "(Narrog)") { player_outfit_spellbook("Phase Door"); } @@ -1212,7 +952,7 @@ static void player_outfit(void) identify_pack_fully(); } - if (streq(rmp_ptr->title, "Vampire")) + if (rmp_ptr->title == "Vampire") { player_gain_corruption(CORRUPT_VAMPIRE_TEETH); player_gain_corruption(CORRUPT_VAMPIRE_STRENGTH); @@ -1237,55 +977,29 @@ static void player_outfit(void) q_ptr->timeout = rand_range(3, 7) * 500; object_aware(q_ptr); object_known(q_ptr); - (void)inven_carry(q_ptr, FALSE); - } - - /* Rogues have a better knowledge of traps */ - if (has_ability(AB_TRAPPING)) - { - t_info[TRAP_OF_DAGGER_I].known = randint(50) + 50; - t_info[TRAP_OF_POISON_NEEDLE].known = randint(50) + 50; - t_info[TRAP_OF_FIRE_BOLT].known = randint(50) + 50; - t_info[TRAP_OF_DAGGER_I].ident = TRUE; - t_info[TRAP_OF_POISON_NEEDLE].ident = TRUE; - t_info[TRAP_OF_FIRE_BOLT].ident = TRUE; - - /* Hack -- Give the player a some ammo for the traps */ - object_type forge; - object_type *q_ptr = &forge; - object_prep(q_ptr, lookup_kind(TV_SHOT, SV_AMMO_NORMAL)); - q_ptr->number = (byte)rand_range(5, 15); - object_aware(q_ptr); - object_known(q_ptr); - - /* These objects are "storebought" */ - q_ptr->ident |= IDENT_MENTAL; - - (void)inven_carry(q_ptr, FALSE); + inven_carry(q_ptr, FALSE); } - /* Hack -- Give the player some useful objects */ - for (i = 0; i < rp_ptr->obj_num; i++) - outfit_obj(rp_ptr->obj_tval[i], rp_ptr->obj_sval[i], rp_ptr->obj_pval[i], rp_ptr->obj_dd[i], rp_ptr->obj_ds[i]); - for (i = 0; i < rmp_ptr->obj_num; i++) - outfit_obj(rmp_ptr->obj_tval[i], rmp_ptr->obj_sval[i], rmp_ptr->obj_pval[i], rmp_ptr->obj_dd[i], rmp_ptr->obj_ds[i]); - for (i = 0; i < cp_ptr->obj_num; i++) - outfit_obj(cp_ptr->obj_tval[i], cp_ptr->obj_sval[i], cp_ptr->obj_pval[i], cp_ptr->obj_dd[i], cp_ptr->obj_ds[i]); - for (i = 0; i < cp_ptr->spec[p_ptr->pspec].obj_num; i++) - outfit_obj(cp_ptr->spec[p_ptr->pspec].obj_tval[i], cp_ptr->spec[p_ptr->pspec].obj_sval[i], cp_ptr->spec[p_ptr->pspec].obj_pval[i], cp_ptr->spec[p_ptr->pspec].obj_dd[i], cp_ptr->spec[p_ptr->pspec].obj_ds[i]); + /* Outfit the player with starting items */ + outfit_objs(rp_ptr->object_protos); + outfit_objs(rmp_ptr->object_protos); + outfit_objs(cp_ptr->object_protos); + outfit_objs(cp_ptr->spec[p_ptr->pspec].object_protos); } -int dump_classes(s16b *classes, int sel, u32b *restrictions) +static void dump_classes(std::vector<u16b> const &classes, int sel, u32b *restrictions) { - int n = 0; + auto const &class_info = game->edit_data.class_info; char buf[80]; /* Clean up */ clear_from(12); - while (classes[n] != -1) + int n_max = static_cast<int>(classes.size()); // Warning avoidance + + for (int n = 0; n < n_max; n++) { cptr mod = ""; char p2 = ')', p1 = ' '; @@ -1302,7 +1016,7 @@ int dump_classes(s16b *classes, int sel, u32b *restrictions) /* Display */ strnfmt(buf, 80, "%c%c%c %s%s", p1, - (n <= 25) ? I2A(n) : I2D(n - 26), p2, cp_ptr->title, mod); + (n <= 25) ? I2A(n) : I2D(n - 26), p2, cp_ptr->title.c_str(), mod); /* Print some more info */ if (sel == n) @@ -1310,7 +1024,7 @@ int dump_classes(s16b *classes, int sel, u32b *restrictions) std::string desc; desc += cp_ptr->desc; - if (cp_ptr->flags1 & PR1_EXPERIMENTAL) + if (cp_ptr->flags & PR_EXPERIMENTAL) { desc += "\nEXPERIMENTAL"; } @@ -1318,7 +1032,7 @@ int dump_classes(s16b *classes, int sel, u32b *restrictions) print_desc(desc.c_str()); if (!(restrictions[classes[n] / 32] & BIT(classes[n])) || - cp_ptr->flags1 & PR1_EXPERIMENTAL) + (cp_ptr->flags & PR_EXPERIMENTAL)) c_put_str(TERM_BLUE, buf, 18 + (n / 4), 1 + 20 * (n % 4)); else c_put_str(TERM_L_BLUE, buf, 18 + (n / 4), 1 + 20 * (n % 4)); @@ -1326,36 +1040,34 @@ int dump_classes(s16b *classes, int sel, u32b *restrictions) else { if (!(restrictions[classes[n] / 32] & BIT(classes[n])) || - cp_ptr->flags1 & PR1_EXPERIMENTAL) + (cp_ptr->flags & PR_EXPERIMENTAL)) c_put_str(TERM_SLATE, buf, 18 + (n / 4), 1 + 20 * (n % 4)); else put_str(buf, 18 + (n / 4), 1 + 20 * (n % 4)); } - n++; - } - return (n); + } } -int dump_specs(int sel) +static void dump_specs(int sel_) { - int n = 0; + auto const &class_info = game->edit_data.class_info; - char buf[80]; + assert(sel_ >= 0); + std::size_t sel = sel_; - /* Clean up */ clear_from(12); - for (n = 0; n < MAX_SPEC; n++) - { - char p2 = ')', p1 = ' '; + auto specs = &class_info[p_ptr->pclass].spec; - /* Found the last one ? */ - if (!class_info[p_ptr->pclass].spec[n].title) break; + for (std::size_t n = 0; n < specs->size(); n++) + { + char p2 = ')'; + char p1 = ' '; /* Analyze */ p_ptr->pspec = n; - spp_ptr = &class_info[p_ptr->pclass].spec[p_ptr->pspec]; + spp_ptr = &(*specs)[p_ptr->pspec]; if (sel == n) { @@ -1364,6 +1076,7 @@ int dump_specs(int sel) } /* Display */ + char buf[80]; strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, spp_ptr->title); /* Print some more info */ @@ -1372,32 +1085,40 @@ int dump_specs(int sel) std::string desc; desc += spp_ptr->desc; - if (spp_ptr->flags1 & PR1_EXPERIMENTAL) + if (spp_ptr->flags & PR_EXPERIMENTAL) { desc += "\nEXPERIMENTAL"; } print_desc(desc.c_str()); - if (spp_ptr->flags1 & PR1_EXPERIMENTAL) + if (spp_ptr->flags & PR_EXPERIMENTAL) + { c_put_str(TERM_BLUE, buf, 18 + (n / 4), 1 + 20 * (n % 4)); + } else + { c_put_str(TERM_L_BLUE, buf, 18 + (n / 4), 1 + 20 * (n % 4)); + } } else { - if (spp_ptr->flags1 & PR1_EXPERIMENTAL) + if (spp_ptr->flags & PR_EXPERIMENTAL) + { c_put_str(TERM_SLATE, buf, 18 + (n / 4), 1 + 20 * (n % 4)); + } else + { put_str(buf, 18 + (n / 4), 1 + 20 * (n % 4)); + } } } - - return (n); } -int dump_races(int sel) +static int dump_races(int sel) { + auto const &race_info = game->edit_data.race_info; + int n = 0; char buf[80]; @@ -1405,7 +1126,7 @@ int dump_races(int sel) /* Clean up */ clear_from(12); - for (n = 0; n < max_rp_idx; n++) + for (n = 0; n < static_cast<int>(race_info.size()); n++) { char p2 = ')', p1 = ' '; @@ -1420,7 +1141,7 @@ int dump_races(int sel) } /* Display */ - strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, rp_ptr->title); + strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, rp_ptr->title.c_str()); /* Print some more info */ if (sel == n) @@ -1428,21 +1149,21 @@ int dump_races(int sel) std::string desc; desc += rp_ptr->desc; - if (rp_ptr->flags1 & PR1_EXPERIMENTAL) + if (rp_ptr->flags & PR_EXPERIMENTAL) { desc += "\nEXPERIMENTAL"; } print_desc(desc.c_str()); - if (rp_ptr->flags1 & PR1_EXPERIMENTAL) + if (rp_ptr->flags & PR_EXPERIMENTAL) c_put_str(TERM_BLUE, buf, 18 + (n / 5), 1 + 15 * (n % 5)); else c_put_str(TERM_L_BLUE, buf, 18 + (n / 5), 1 + 15 * (n % 5)); } else { - if (rp_ptr->flags1 & PR1_EXPERIMENTAL) + if (rp_ptr->flags & PR_EXPERIMENTAL) c_put_str(TERM_SLATE, buf, 18 + (n / 5), 1 + 15 * (n % 5)); else put_str(buf, 18 + (n / 5), 1 + 15 * (n % 5)); @@ -1453,8 +1174,10 @@ int dump_races(int sel) } -int dump_rmods(int sel, int *racem, int max) +static int dump_rmods(int sel, int *racem, int max) { + auto const &race_mod_info = game->edit_data.race_mod_info; + int n = 0; char buf[80]; @@ -1479,7 +1202,7 @@ int dump_rmods(int sel, int *racem, int max) /* Display */ if (racem[n]) - strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, rmp_ptr->title); + strnfmt(buf, 80, "%c%c%c %s", p1, I2A(n), p2, rmp_ptr->title.c_str()); else strnfmt(buf, 80, "%c%c%c Classical", p1, I2A(n), p2); @@ -1488,22 +1211,22 @@ int dump_rmods(int sel, int *racem, int max) { std::string desc; - desc += rmp_ptr->desc; - if (rmp_ptr->flags1 & PR1_EXPERIMENTAL) + desc += rmp_ptr->description; + if (rmp_ptr->flags & PR_EXPERIMENTAL) { desc += "\nEXPERIMENTAL"; } print_desc(desc.c_str()); - if (rmp_ptr->flags1 & PR1_EXPERIMENTAL) + if (rmp_ptr->flags & PR_EXPERIMENTAL) c_put_str(TERM_BLUE, buf, 18 + (n / 5), 1 + 15 * (n % 5)); else c_put_str(TERM_L_BLUE, buf, 18 + (n / 5), 1 + 15 * (n % 5)); } else { - if (rmp_ptr->flags1 & PR1_EXPERIMENTAL) + if (rmp_ptr->flags & PR_EXPERIMENTAL) c_put_str(TERM_SLATE, buf, 18 + (n / 5), 1 + 15 * (n % 5)); else put_str(buf, 18 + (n / 5), 1 + 15 * (n % 5)); @@ -1513,7 +1236,7 @@ int dump_rmods(int sel, int *racem, int max) return (n); } -int dump_gods(int sel, int *choice, int max) +static int dump_gods(int sel, int *choice, int max) { int i, j; char buf[80]; @@ -1576,7 +1299,12 @@ static bool_ do_quick_start = FALSE; static bool_ player_birth_aux_ask() { - int i, k, n, v, sel; + auto &class_info = game->edit_data.class_info; + auto const &race_info = game->edit_data.race_info; + auto const &race_mod_info = game->edit_data.race_mod_info; + auto const &d_info = game->edit_data.d_info; + + int k, n, v, sel; int racem[100], max_racem = 0; @@ -1584,12 +1312,12 @@ static bool_ player_birth_aux_ask() char c; - char p2 = ')'; - char buf[200]; char inp[200]; - s16b *class_types; + int const NAME_ROW = 2; + int const RACE_ROW = 3; + int const CLASS_ROW = 4; /*** Intro ***/ @@ -1597,14 +1325,12 @@ static bool_ player_birth_aux_ask() Term_clear(); /* Title everything */ - put_str("Name :", 2, 1); - put_str("Sex :", 3, 1); - put_str("Race :", 4, 1); - put_str("Class :", 5, 1); + put_str("Name :", NAME_ROW, 1); + c_put_str(TERM_L_BLUE, game->player_name.c_str(), NAME_ROW, 9); - /* Dump the default name */ - c_put_str(TERM_L_BLUE, player_name, 2, 9); + put_str("Race :", RACE_ROW, 1); + put_str("Class :", CLASS_ROW, 1); /*** Instructions ***/ @@ -1621,16 +1347,12 @@ static bool_ player_birth_aux_ask() /*** Quick Start ***/ - if (previous_char.quick_ok) + if (game->previous_char.quick_ok) { - /* Extra info */ - Term_putstr(1, 15, -1, TERM_WHITE, - "Do you want to use the quick start function(same character as your last one)."); - /* Choose */ while (1) { - put_str("Use quick start (y/n)?", 20, 2); + put_str("Use same character as last time (y/n)? ", 20, 2); c = inkey(); if (c == 'Q') quit(NULL); else if (c == 'S') return (FALSE); @@ -1650,78 +1372,22 @@ static bool_ player_birth_aux_ask() /* Clean up */ clear_from(15); - /*** Player sex ***/ - - if (do_quick_start) - { - k = previous_char.sex; - } - else - { - /* Extra info */ - Term_putstr(5, 15, -1, TERM_WHITE, - "Your 'sex' does not have any significant gameplay effects."); - - /* Prompt for "Sex" */ - for (n = 0; n < MAX_SEXES; n++) - { - /* Analyze */ - p_ptr->psex = n; - sp_ptr = &sex_info[p_ptr->psex]; - - /* Display */ - strnfmt(buf, 200, "%c%c %s", I2A(n), p2, sp_ptr->title); - put_str(buf, 21 + (n / 5), 2 + 15 * (n % 5)); - } - - /* Choose */ - while (1) - { - strnfmt(buf, 200, "Choose a sex (%c-%c), * for random, = for options: ", I2A(0), I2A(n - 1)); - put_str(buf, 20, 2); - c = inkey(); - if (c == 'Q') quit(NULL); - if (c == 'S') return (FALSE); - if (c == '*') - { - k = rand_int(MAX_SEXES); - break; - } - k = (islower(c) ? A2I(c) : -1); - if ((k >= 0) && (k < n)) break; - if (c == '?') do_cmd_help(); - else if (c == '=') - { - screen_save(); - do_cmd_options_aux(6, "Startup Options", FALSE); - screen_load(); - } - else bell(); - } - } - - /* Set sex */ - p_ptr->psex = k; - sp_ptr = &sex_info[p_ptr->psex]; - - /* Display */ - c_put_str(TERM_L_BLUE, sp_ptr->title, 3, 9); - /* Clean up */ clear_from(15); /*** Player race ***/ - if (do_quick_start) { - k = previous_char.race; + k = game->previous_char.race; } else { /* Only one choice = instant choice */ - if (max_rp_idx == 1) + if (race_info.size() == 1) + { k = 0; + } else { /* Extra info */ @@ -1736,7 +1402,7 @@ static bool_ player_birth_aux_ask() while (1) { strnfmt(buf, 200, "Choose a race (%c-%c), * for a random choice, = for options, 8/2/4/6 for movement: ", - I2A(0), I2A(max_rp_idx - 1)); + I2A(0), I2A(race_info.size() - 1)); put_str(buf, 17, 2); c = inkey(); @@ -1744,7 +1410,7 @@ static bool_ player_birth_aux_ask() if (c == 'S') return (FALSE); if (c == '*') { - k = rand_int(max_rp_idx); + k = rand_int(race_info.size()); break; } k = (islower(c) ? A2I(c) : -1); @@ -1799,13 +1465,16 @@ static bool_ player_birth_aux_ask() rp_ptr = &race_info[p_ptr->prace]; /* Display */ - c_put_str(TERM_L_BLUE, rp_ptr->title, 4, 9); + c_put_str(TERM_L_BLUE, rp_ptr->title.c_str(), RACE_ROW, 9); /* Get a random name */ - if (!do_quick_start) create_random_name(p_ptr->prace, player_name); + if (!do_quick_start) + { + game->player_name = create_random_name(); + } /* Display */ - c_put_str(TERM_L_BLUE, player_name, 2, 9); + c_put_str(TERM_L_BLUE, game->player_name.c_str(), NAME_ROW, 9); /* Clean up */ clear_from(12); @@ -1814,21 +1483,23 @@ static bool_ player_birth_aux_ask() /*** Player race mod ***/ if (do_quick_start) { - k = previous_char.rmod; + k = game->previous_char.rmod; p_ptr->pracem = k; rmp_ptr = &race_mod_info[p_ptr->pracem]; } else { /* Only one choice = instant choice */ - if (max_rmp_idx == 1) + if (race_mod_info.size() == 1) + { k = 0; + } else { for (n = 0; n < 100; n++) racem[n] = 0; max_racem = 0; - for (n = 0; n < max_rmp_idx; n++) + for (n = 0; n < static_cast<int>(race_mod_info.size()); n++) { /* Analyze */ p_ptr->pracem = n; @@ -1867,16 +1538,24 @@ static bool_ player_birth_aux_ask() if (c == 'S') return (FALSE); if (c == '*') { - do - { - k = rand_int(max_racem); + // Which choices are legal? + std::vector<int> valid_choices(max_racem); + for (int i = 0; i < max_racem; i++) { + if ((BIT(racem[i]) & rmp_ptr->choice[racem[i] / 32])) + { + valid_choices.push_back(i); + } } - while (!(BIT(racem[k]) & rmp_ptr->choice[racem[k] / 32])); + + // Choose + assert(!valid_choices.empty()); + k = *uniform_element(valid_choices); + break; } else if (c == '?') { - help_subrace(race_mod_info[racem[sel]].title); + help_subrace(race_mod_info[racem[sel]].title.c_str()); } k = (islower(c) ? A2I(c) : -1); @@ -1927,7 +1606,8 @@ static bool_ player_birth_aux_ask() rmp_ptr = &race_mod_info[p_ptr->pracem]; /* Display */ - c_put_str(TERM_L_BLUE, get_player_race_name(p_ptr->prace, p_ptr->pracem), 4, 9); + auto const race_name = get_player_race_name(p_ptr->prace, p_ptr->pracem); + c_put_str(TERM_L_BLUE, race_name.c_str(), RACE_ROW, 9); } } @@ -1938,72 +1618,49 @@ static bool_ player_birth_aux_ask() /*** Player class ***/ if (do_quick_start) { - k = previous_char.pclass; + k = game->previous_char.pclass; p_ptr->pclass = k; cp_ptr = &class_info[p_ptr->pclass]; - k = previous_char.spec; + k = game->previous_char.spec; p_ptr->pspec = k; spp_ptr = &class_info[p_ptr->pclass].spec[p_ptr->pspec]; } else { - int z; - - for (z = 0; z < 2; z++) + for (int z = 0; z < 2; z++) + { restrictions[z] = (rp_ptr->choice[z] | rmp_ptr->pclass[z]) & (~rmp_ptr->mclass[z]); + } - if (max_mc_idx > 1) + // Get list of all the classes. + std::vector<u16b> class_types; + for (std::size_t i = 0; i < class_info.size(); i++) { - /* Extra info */ - Term_putstr(5, 13, -1, TERM_WHITE, - "Your 'class' determines various intrinsic abilities and bonuses."); + class_types.push_back(i); + } - /* Get a class type */ - for (i = 0; i < max_mc_idx; i++) - c_put_str(meta_class_info[i].color, format("%c) %s", I2A(i), meta_class_info[i].name), 16 + i, 2); - while (1) - { - strnfmt(buf, 200, "Choose a class type (a-%c), * for random, = for options: ", I2A(max_mc_idx - 1)); - put_str(buf, 15, 2); - c = inkey(); - if (c == 'Q') quit(NULL); - if (c == 'S') return (FALSE); - if (c == '*') - { - k = rand_int(max_mc_idx); - break; - } - k = (islower(c) ? A2I(c) : (D2I(c) + 26)); - if ((k >= 0) && (k < max_mc_idx)) break; - if (c == '?') do_cmd_help(); - else if (c == '=') - { - screen_save(); - do_cmd_options_aux(6, "Startup Options", FALSE); - screen_load(); - } - else bell(); + // Sort into display order + std::stable_sort( + class_types.begin(), + class_types.end(), + [&class_info](auto i, auto j) { + return class_info[i].display_order_idx < class_info[j].display_order_idx; } - } - else - { - k = 0; - } - class_types = meta_class_info[k].classes; - clear_from(15); + ); /* Count classes */ - n = 0; - while (class_types[n] != -1) n++; + n = class_types.size(); /* Only one choice = instant choice */ if (n == 1) + { k = 0; + } else { /* Dump classes */ sel = 0; - n = dump_classes(class_types, sel, restrictions); + dump_classes(class_types, sel, restrictions); /* Get a class */ while (1) @@ -2072,11 +1729,7 @@ static bool_ player_birth_aux_ask() clear_from(15); /* Count choices */ - for (n = 0; n < MAX_SPEC; n++) - { - /* Found the last one ? */ - if (!class_info[p_ptr->pclass].spec[n].title) break; - } + n = class_info[p_ptr->pclass].spec.size(); /* Only one choice = auto choice */ if (n == 1) @@ -2085,7 +1738,7 @@ static bool_ player_birth_aux_ask() { /* Dump classes spec */ sel = 0; - n = dump_specs(sel); + dump_specs(sel); /* Get a class */ while (1) @@ -2152,7 +1805,7 @@ static bool_ player_birth_aux_ask() spp_ptr = &class_info[p_ptr->pclass].spec[p_ptr->pspec]; /* Display */ - c_put_str(TERM_L_BLUE, spp_ptr->title, 5, 9); + c_put_str(TERM_L_BLUE, spp_ptr->title, CLASS_ROW, 9); /* Clean up */ clear_from(15); @@ -2160,11 +1813,11 @@ static bool_ player_birth_aux_ask() /*** Player god ***/ if (do_quick_start) { - k = previous_char.god; + k = game->previous_char.god; p_ptr->pgod = k; - set_grace(previous_char.grace); + set_grace(game->previous_char.grace); } - else if (race_flags1_p(PR1_NO_GOD)) + else if (race_flags_p(PR_NO_GOD)) { p_ptr->pgod = GOD_NONE; } @@ -2271,7 +1924,7 @@ static bool_ player_birth_aux_ask() } /* A god that like us ? more grace ! */ - if (race_flags1_p(PR1_GOD_FRIEND)) + if (race_flags_p(PR_GOD_FRIEND)) { set_grace(200); } @@ -2298,10 +1951,8 @@ static bool_ player_birth_aux_ask() } } - /* Set birth options: maximize, preserve, sepcial levels and astral */ - p_ptr->preserve = preserve; - p_ptr->special = special_lvls; - p_ptr->astral = (race_flags2_p(PR2_ASTRAL)) ? TRUE : FALSE; + /* Is the player an "astral" being? */ + p_ptr->astral = (race_flags_p(PR_ASTRAL)) ? TRUE : FALSE; /* * A note by pelpel. (remove this please) @@ -2335,11 +1986,11 @@ static bool_ player_birth_aux_ask() /*** User enters number of quests ***/ /* Heino Vander Sanden and Jimmy De Laet */ - if (!ironman_rooms) + if (!options->ironman_rooms) { if (do_quick_start) { - v = previous_char.quests; + v = game->previous_char.quests; } else { @@ -2421,7 +2072,7 @@ static bool_ player_birth_aux_ask() plots[PLOT_OTHER] = QUEST_NULL; } - quest_random_init_hook(QUEST_RANDOM); + quest_random_init_hook(); /* Ok */ return (TRUE); @@ -2453,7 +2104,7 @@ static const int birth_stat_costs[(18-10) + 1] = * * Taken from V 2.9.0 */ -static bool_ player_birth_aux_point(void) +static bool_ player_birth_aux_point() { int i; @@ -2471,8 +2122,6 @@ static bool_ player_birth_aux_point(void) char buf[80]; - int mode = 0; - /* Initialize stats */ for (i = 0; i < 6; i++) @@ -2485,12 +2134,6 @@ static bool_ player_birth_aux_point(void) /* Roll for base hitpoints */ get_extra(); - /* Roll for age/height/weight */ - get_ahw(); - - /* Roll for social class */ - get_history(); - /* Get luck */ p_ptr->luck_base = rp_ptr->luck + rmp_ptr->luck + rand_range( -5, 5); p_ptr->luck_max = p_ptr->luck_base; @@ -2543,7 +2186,7 @@ static bool_ player_birth_aux_point(void) p_ptr->csp = p_ptr->msp; /* Display the player */ - display_player(mode); + display_player(0); /* Display the costs header */ put_str("Cost", row - 2, col + 32); @@ -2613,8 +2256,6 @@ static bool_ player_birth_aux_auto() { int i, j, m, v; - int mode = 0; - bool_ flag = FALSE; bool_ prev = FALSE; @@ -2631,7 +2272,7 @@ static bool_ player_birth_aux_auto() /* Initialize */ - if (autoroll) + if (options->autoroll) { int mval[6]; @@ -2655,7 +2296,7 @@ static bool_ player_birth_aux_auto() stat_match[i] = 0; /* Race/Class bonus */ - j = rp_ptr->r_adj[i] + rmp_ptr->r_adj[i] + cp_ptr->c_adj[i]; + j = rp_ptr->ps.adj[i] + rmp_ptr->ps.adj[i] + cp_ptr->ps.adj[i]; /* Obtain the "maximal" stat */ m = adjust_stat(17, j, TRUE); @@ -2694,7 +2335,7 @@ static bool_ player_birth_aux_auto() if (!askfor_aux(inp, 8)) inp[0] = '\0'; /* Weirdos stat display .. erm .. I mean, original stat display */ - if (!linear_stats) + if (!options->linear_stats) { /* Hack -- add a fake slash */ strcat(inp, "/"); @@ -2734,20 +2375,19 @@ static bool_ player_birth_aux_auto() while (TRUE) { /* Feedback */ - if (autoroll) + if (options->autoroll) { Term_clear(); put_str("Name :", 2, 1); - put_str("Sex :", 3, 1); - put_str("Race :", 4, 1); - put_str("Class:", 5, 1); + c_put_str(TERM_L_BLUE, game->player_name.c_str(), 2, 9); + + put_str("Race :", 3, 1); + auto const player_race_name = get_player_race_name(p_ptr->prace, p_ptr->pracem); + c_put_str(TERM_L_BLUE, player_race_name.c_str(), 3, 9); - c_put_str(TERM_L_BLUE, player_name, 2, 9); - c_put_str(TERM_L_BLUE, sp_ptr->title, 3, 9); - strnfmt(buf, 80, "%s", get_player_race_name(p_ptr->prace, p_ptr->pracem)); - c_put_str(TERM_L_BLUE, buf, 4, 9); - c_put_str(TERM_L_BLUE, spp_ptr->title, 5, 9); + put_str("Class:", 4, 1); + c_put_str(TERM_L_BLUE, spp_ptr->title, 4, 9); /* Label stats */ put_str("STR:", 2 + A_STR, 61); @@ -2775,7 +2415,7 @@ static bool_ player_birth_aux_auto() } /* Auto-roll */ - while (autoroll) + while (options->autoroll) { bool_ accept = TRUE; @@ -2833,18 +2473,9 @@ static bool_ player_birth_aux_auto() /*** Display ***/ - /* Mode */ - mode = 0; - /* Roll for base hitpoints */ get_extra(); - /* Roll for age/height/weight */ - get_ahw(); - - /* Roll for social class */ - get_history(); - /* Roll for gold */ get_money(); @@ -2864,15 +2495,13 @@ static bool_ player_birth_aux_auto() p_ptr->csp = p_ptr->msp; /* Display the player */ - display_player(mode); + display_player(0); /* Prepare a prompt (must squeeze everything in) */ Term_gotoxy(2, 23); Term_addch(TERM_WHITE, b1); Term_addstr( -1, TERM_WHITE, "'r' to reroll"); if (prev) Term_addstr( -1, TERM_WHITE, ", 'p' for prev"); - if (mode) Term_addstr( -1, TERM_WHITE, ", 'h' for Misc."); - else Term_addstr( -1, TERM_WHITE, ", 'h' for History"); Term_addstr( -1, TERM_WHITE, ", or ESC to accept"); Term_addch(TERM_WHITE, b2); @@ -2898,13 +2527,6 @@ static bool_ player_birth_aux_auto() continue; } - /* Toggle the display */ - if ((c == 'H') || (c == 'h')) - { - mode = ((mode != 0) ? 0 : 1); - continue; - } - /* Help */ if (c == '?') { @@ -2942,20 +2564,20 @@ static bool_ player_birth_aux_auto() */ static bool_ player_birth_aux() { - char c; - - int i, j; - - int y = 0, x = 0; + auto const &s_descriptors = game->edit_data.s_descriptors; + auto &s_info = game->s_info; - char old_history[4][60]; + char c; /* Ask */ if (!player_birth_aux_ask()) return (FALSE); - for (i = 1; i < max_s_idx; i++) - s_info[i].dev = FALSE; - for (i = 1; i < max_s_idx; i++) + for (std::size_t i = 1; i < s_descriptors.size(); i++) + { + s_info[i].dev = false; + } + + for (std::size_t i = 1; i < s_descriptors.size(); i++) { s32b value = 0, mod = 0; @@ -2966,14 +2588,18 @@ static bool_ player_birth_aux() /* Develop only revelant branches */ if (s_info[i].value || s_info[i].mod) { - int z = s_info[i].father; + int z = s_descriptors[i].father; while (z != -1) { - s_info[z].dev = TRUE; - z = s_info[z].father; + // Mark as developed + s_info[z].dev = true; + // Next node up the tree + z = s_descriptors[z].father; if (z == 0) + { break; + } } } } @@ -3000,7 +2626,7 @@ static bool_ player_birth_aux() else { /* Point based */ - if (point_based) + if (options->point_based) { if (!player_birth_aux_point()) return FALSE; } @@ -3010,83 +2636,9 @@ static bool_ player_birth_aux() if (!player_birth_aux_auto()) return FALSE; } - /* Edit character background */ - for (i = 0; i < 4; i++) - { - strnfmt(old_history[i], 60, "%s", history[i]); - } - /* Turn 0 to space */ - for (i = 0; i < 4; i++) - { - for (j = 0; history[i][j]; j++) /* loop */; - - for (; j < 59; j++) history[i][j] = ' '; - } - display_player(1); - c_put_str(TERM_L_GREEN, "(Character Background - Edit Mode)", 15, 20); - while (TRUE) - { - for (i = 0; i < 4; i++) - { - put_str(history[i], i + 16, 10); - } - c_put_str(TERM_L_BLUE, format("%c", history[y][x]), y + 16, x + 10); - - /* Place cursor just after cost of current stat */ - Term_gotoxy(x + 10, y + 16); - - c = inkey(); - - if (c == '8') - { - y--; - if (y < 0) y = 3; - } - else if (c == '2') - { - y++; - if (y > 3) y = 0; - } - else if (c == '6') - { - x++; - if (x > 59) x = 0; - } - else if (c == '4') - { - x--; - if (x < 0) x = 59; - } - else if (c == '\r') - { - break; - } - else if (c == ESCAPE) - { - for (i = 0; i < 4; i++) - { - strnfmt(history[i], 60, "%s", old_history[i]); - put_str(history[i], i + 16, 10); - } - break; - } - else - { - history[y][x++] = c; - if (x > 58) - { - x = 0; - y++; - if (y > 3) y = 0; - } - } - } - - /*** Finish up ***/ /* Get a name, recolor it, prepare savefile */ - get_name(); @@ -3104,7 +2656,7 @@ static bool_ player_birth_aux() } /* Save this for the next character */ - previous_char.quick_ok = TRUE; + game->previous_char.quick_ok = TRUE; save_prev_data(); /* Accept */ @@ -3113,105 +2665,9 @@ static bool_ player_birth_aux() /* - * Helper function for validate_bg(). - */ -static void validate_bg_aux(int chart, bool_ chart_checked[], char *buf) -{ - char *s; - - int i; - - - /* Assume the chart does not exist */ - bool_ chart_exists = FALSE; - - /* Assume the chart is not complete */ - bool_ chart_complete = FALSE; - - int bg_max = max_bg_idx; - - /* No chart */ - if (!chart) return; - - /* Already saw this chart */ - if (chart_checked[chart]) return; - - /* Build a debug message */ - s = buf + strlen(buf); - - /* XXX XXX XXX */ - (void) strnfmt(s, -1, "%d --> ", chart); - - /* Check each chart */ - for (i = 0; i < bg_max; i++) - { - /* Require same chart */ - if (bg[i].chart != chart) continue; - - /* The chart exists */ - chart_exists = TRUE; - - /* Validate the "next" chart recursively */ - validate_bg_aux(bg[i].next, chart_checked, buf); - - /* Require a terminator */ - if (bg[i].roll != 100) continue; - - /* The chart is complete */ - chart_complete = TRUE; - } - - /* Failed: The chart does not exist */ - if (!chart_exists) - { - quit_fmt("birth.c: bg[] chart %d does not exist\n%s", chart, buf); - } - - /* Failed: The chart is not complete */ - if (!chart_complete) - { - quit_fmt("birth.c: bg[] chart %d is not complete", chart); - } - - /* Remember we saw this chart */ - chart_checked[chart] = TRUE; - - /* Build a debug message */ - *s = 0; -} - - -/* - * Verify that the bg[] table is valid. - */ -static void validate_bg(void) -{ - int i, race; - - bool_ chart_checked[512]; - - char buf[1024]; - - - for (i = 0; i < 512; i++) chart_checked[i] = FALSE; - - /* Check each race */ - for (race = 0; race < max_rp_idx; race++) - { - /* Get the first chart for this race */ - int chart = race_info[race].chart; - - (void) strcpy(buf, ""); - - /* Validate the chart recursively */ - validate_bg_aux(chart, chart_checked, buf); - } -} - -/* * Initialize a random town */ -void init_town(int t_idx, int level) +static void init_town(int t_idx) { town_type *t_ptr = &town_info[t_idx]; @@ -3222,10 +2678,7 @@ void init_town(int t_idx, int level) t_ptr->flags &= ~(TOWN_KNOWN); /* Generation seed for the town */ - t_ptr->seed = randint(0x10000000); - - /* Total hack and not even used */ - t_ptr->numstores = 8; + t_ptr->seed = seed_t::system(); } /* @@ -3234,12 +2687,14 @@ void init_town(int t_idx, int level) * Note that we may be called with "junk" leftover in the various * fields, so we must be sure to clear them first. */ -void player_birth(void) +void player_birth() { - int i, j, rtown = TOWN_RANDOM; + auto const &st_info = game->edit_data.st_info; + auto &d_info = game->edit_data.d_info; + auto &messages = game->messages; - /* Validate the bg[] table */ - validate_bg(); + /* Starting index for generated towns */ + std::size_t rtown = TOWN_RANDOM; /* Create a new character */ while (1) @@ -3258,14 +2713,15 @@ void player_birth(void) recalc_skills(FALSE); /* grab level 1 abilities */ - for (i = 0; i < max_ab_idx; i++) - ab_info[i].acquired = FALSE; + p_ptr->abilities.clear(); apply_level_abilities(1); /* Complete the god */ - i = p_ptr->pgod; - p_ptr->pgod = 0; - follow_god(i, TRUE); + { + byte i = p_ptr->pgod; + p_ptr->pgod = 0; + follow_god(i, TRUE); + } /* Select the default melee type */ select_default_melee(); @@ -3274,19 +2730,19 @@ void player_birth(void) add_note_type(NOTE_BIRTH); /* Note player birth in the message recall */ - message_add(" ", TERM_L_BLUE); - message_add(" ", TERM_L_BLUE); - message_add("====================", TERM_L_BLUE); - message_add(" ", TERM_L_BLUE); - message_add(" ", TERM_L_BLUE); + messages.add(" ", TERM_L_BLUE); + messages.add(" ", TERM_L_BLUE); + messages.add("====================", TERM_L_BLUE); + messages.add(" ", TERM_L_BLUE); + messages.add(" ", TERM_L_BLUE); /* Hack -- outfit the player */ player_outfit(); /* Initialize random towns in the dungeons */ - for (i = 0; i < max_d_idx; i++) + for (std::size_t i = 0; i < d_info.size(); i++) { - dungeon_info_type *d_ptr = &d_info[i]; + auto d_ptr = &d_info[i]; int num = 0, z; d_ptr->t_num = 0; @@ -3295,7 +2751,7 @@ void player_birth(void) d_ptr->t_idx[z] = 0; d_ptr->t_level[z] = 0; } - if (!(d_ptr->flags1 & DF1_RANDOM_TOWNS)) continue; + if (!(d_ptr->flags & DF_RANDOM_TOWNS)) continue; /* Can we add a town ? */ while (magik(TOWN_CHANCE - (num * 10))) @@ -3307,15 +2763,17 @@ void player_birth(void) while (TRUE) { - int j; bool_ ok = TRUE; lev = rand_range(d_ptr->mindepth, d_ptr->maxdepth - 1); /* Be sure it wasnt already used */ - for (j = 0; j < num; j++) + for (int j = 0; j < num; j++) { - if (d_ptr->t_level[j] == lev) ok = FALSE; + if (d_ptr->t_level[j] == lev) + { + ok = FALSE; + } } /* Ok found one */ @@ -3325,11 +2783,11 @@ void player_birth(void) if (wizard) { - message_add(format("Random dungeon town: d_idx:%d, lev:%d", i, lev), TERM_WHITE); + messages.add(format("Random dungeon town: d_idx:%d, lev:%d", i, lev), TERM_WHITE); } /* Create the town */ - init_town(d_ptr->t_idx[num], d_ptr->t_level[num]); + init_town(d_ptr->t_idx[num]); num++; @@ -3341,7 +2799,7 @@ void player_birth(void) } /* Init the towns */ - for (i = 1; i < max_towns; i++) + for (std::size_t i = 1; i < max_towns; i++) { /* Not destroyed ! yet .. ;) */ town_info[i].destroyed = FALSE; @@ -3352,7 +2810,7 @@ void player_birth(void) create_stores_stock(i); /* Init the stores */ - for (j = 0; j < max_st_idx; j++) + for (std::size_t j = 0; j < st_info.size(); j++) { /* Initialize */ store_init(i, j); @@ -3360,13 +2818,15 @@ void player_birth(void) } /* Init wilderness seeds */ - for (i = 0; i < max_wild_x; i++) + auto &wilderness = game->wilderness; + for (std::size_t y = 0; y < wilderness.height(); y++) { - for (j = 0; j < max_wild_y; j++) + for (std::size_t x = 0; x < wilderness.width(); x++) { - wild_map[j][i].seed = rand_int(0x10000000); - wild_map[j][i].entrance = 0; - wild_map[j][i].known = FALSE; + auto &w = wilderness(x, y); + w.seed = seed_t::system(); + w.entrance = 0; + w.known = FALSE; } } } @@ -3374,11 +2834,11 @@ void player_birth(void) -char savefile_module[46][80]; -char savefile_names[46][30]; -char savefile_desc[46][80]; -bool_ savefile_alive[46]; -int savefile_idx[46]; +static char savefile_module[46][80]; +static char savefile_names[46][30]; +static char savefile_desc[46][80]; +static bool_ savefile_alive[46]; +static int savefile_idx[46]; /* * Grab all the names from an index @@ -3388,7 +2848,7 @@ int load_savefile_names() FILE *fff; char buf[1024]; char tmp[50]; - char player_base_save[32]; + std::string player_base_save; int max = 0, fd; @@ -3404,7 +2864,7 @@ int load_savefile_names() /* Save the current 'player_base' */ - strncpy(player_base_save, player_base, 32); + player_base_save = game->player_base; /* @@ -3463,7 +2923,7 @@ int load_savefile_names() strcpy(savefile_desc[max], buf + i); /* Build platform-dependent savefile name */ - strncpy(player_base, savefile_names[max], 32); + game->player_base = savefile_names[max]; process_player_name(TRUE); /* Try to open the savefile */ @@ -3480,7 +2940,7 @@ int load_savefile_names() my_fclose(fff); /* Restore the values of 'player_base' and 'savefile' */ - strncpy(player_base, player_base_save, 32); + game->player_base = player_base_save; process_player_name(TRUE); return (max); @@ -3512,15 +2972,16 @@ void save_savefile_names() * Save, use '@' intead of ':' as a separator because it cannot exists * in savefiles */ + auto const player_race_name = get_player_race_name(p_ptr->prace, p_ptr->pracem); fprintf(fff, "%s@%c%s@%s, the %s %s is %s\n", game_module, - (death) ? '0' : '1', player_base, player_name, - get_player_race_name(p_ptr->prace, p_ptr->pracem), + (death) ? '0' : '1', game->player_base.c_str(), game->player_name.c_str(), + player_race_name.c_str(), spp_ptr->title, (!death) ? "alive" : "dead"); for (i = 0; i < max; i++) { - if (!strcmp(savefile_names[i], player_base)) continue; + if (!strcmp(savefile_names[i], game->player_base.c_str())) continue; fprintf(fff, "%s@%c%s@%s\n", savefile_module[i], (savefile_alive[i]) ? '1' : '0', savefile_names[i], savefile_desc[i]); } @@ -3651,22 +3112,20 @@ savefile_try_again: } else if (((k == 0x7F) || (k == '\010')) && (sel >= 2)) { - char player_base_save[32]; - if (!get_check(format("Really delete '%s'?", savefile_names[savefile_idx[sel - 2]]))) continue; /* Save current 'player_base' */ - strncpy(player_base_save, player_base, 32); + std::string player_base_save = game->player_base; /* Build platform-dependent save file name */ - strncpy(player_base, savefile_names[savefile_idx[sel - 2]], 32); + game->player_base = savefile_names[savefile_idx[sel - 2]]; process_player_name(TRUE); /* Remove the savefile */ fd_kill(savefile); /* Restore 'player_base' and 'savefile' */ - strncpy(player_base, player_base_save, 32); + game->player_base = player_base_save; process_player_name(TRUE); /* Reload, gods I hate using goto .. */ @@ -3675,18 +3134,49 @@ savefile_try_again: continue; } + // + // React + // + if (k == 'a') { /* Display prompt */ prt("Enter the name of the savefile that will hold this character: ", 23, 0); /* Ask the user for a string */ - if (!askfor_aux(player_base, 15)) continue; + if (!askfor_aux(&game->player_base, 15)) continue; /* Process the player name */ process_player_name(TRUE); - return (TRUE); + // If the savefile already exists, we do *NOT* want to + // create a new game, so we'll need to return FALSE for + // that. + if (boost::filesystem::exists(savefile)) + { + // Show a message so user doesn't get confused. + msg_print(NULL); + + // Prompt for it + prt(fmt::format( + "Character '{}' already exists! Press any key to load.", + game->player_base), + 0, 0); + + // Wait + inkey(); + + // Erase the prompt + prt("", 0, 0); + + // Load character + return FALSE; + } + else + { + // Start new game + return TRUE; + } } if (k == 'b') { @@ -3694,7 +3184,7 @@ savefile_try_again: prt("Enter the name of a savefile: ", 23, 0); /* Ask the user for a string */ - if (!askfor_aux(player_base, 15)) continue; + if (!askfor_aux(&game->player_base, 15)) continue; /* Process the player name */ process_player_name(TRUE); @@ -3710,7 +3200,7 @@ savefile_try_again: if ((x < 2) || (x >= max)) continue; - strnfmt(player_base, 32, "%s", savefile_names[savefile_idx[x - 2]]); + game->player_base = savefile_names[savefile_idx[x - 2]]; /* Process the player name */ process_player_name(TRUE); diff --git a/src/birth.h b/src/birth.h deleted file mode 100644 index 41620bfa..00000000 --- a/src/birth.h +++ /dev/null @@ -1,14 +0,0 @@ -#pragma once - -#include "h-basic.h" - -// C linkage required for these functions since main-* code uses them. -#ifdef __cplusplus -extern "C" { -#endif - -extern bool_ no_begin_screen; - -#ifdef __cplusplus -} // extern "C" -#endif diff --git a/src/birth.hpp b/src/birth.hpp index fb036ecc..82bdfcf6 100644 --- a/src/birth.hpp +++ b/src/birth.hpp @@ -2,8 +2,10 @@ #include "h-basic.h" -extern void print_desc_aux(cptr txt, int y, int x); -extern void save_savefile_names(void); -extern bool_ begin_screen(void); -extern void get_height_weight(void); -extern void player_birth(void); +void print_desc_aux(cptr txt, int y, int x); +void save_savefile_names(); +bool_ begin_screen(); +void player_birth(); +void roll_player_hp(); + +extern bool_ no_begin_screen; diff --git a/src/birther.hpp b/src/birther.hpp index f517fb9d..0c28b513 100644 --- a/src/birther.hpp +++ b/src/birther.hpp @@ -2,12 +2,14 @@ #include "h-basic.h" +#include <string> +#include <vector> + /** * Player information during the birth process. */ struct birther { - s16b sex; s16b race; s16b rmod; s16b pclass; @@ -17,19 +19,11 @@ struct birther byte god; s32b grace; - s32b god_favor; - - s16b age; - s16b wt; - s16b ht; - s16b sc; s32b au; s16b stat[6]; s16b luck; - char history[4][60]; - bool_ quick_ok; }; diff --git a/src/bldg.cc b/src/bldg.cc index 7095e8c3..9b3750a6 100644 --- a/src/bldg.cc +++ b/src/bldg.cc @@ -16,6 +16,7 @@ #include "cave_type.hpp" #include "cmd3.hpp" #include "files.hpp" +#include "game.hpp" #include "hooks.hpp" #include "hook_quest_finish_in.hpp" #include "hook_quest_fail_in.hpp" @@ -23,7 +24,9 @@ #include "mimic.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_flag.hpp" #include "owner_type.hpp" +#include "player_race_flag.hpp" #include "player_type.hpp" #include "q_library.hpp" #include "q_fireprof.hpp" @@ -49,10 +52,11 @@ static int building_loc = 0; /* * A helper function for is_state */ -static bool_ is_state_aux(store_type *s_ptr, int state) +static bool_ is_state_aux(store_type const *s_ptr, int state) { - owner_type *ow_ptr = &ow_info[s_ptr->owner]; + auto const &ow_info = game->edit_data.ow_info; + auto ow_ptr = &ow_info[s_ptr->owner]; /* Check race */ if (ow_ptr->races[state][p_ptr->prace / 32] & (1 << p_ptr->prace)) @@ -74,7 +78,7 @@ static bool_ is_state_aux(store_type *s_ptr, int state) /* * Test if the state accords with the player */ -bool_ is_state(store_type *s_ptr, int state) +bool_ is_state(store_type const *s_ptr, int state) { if (state == STORE_NORMAL) { @@ -108,99 +112,95 @@ static void clear_bldg(int min_row, int max_row) /* * Display a building. */ -void show_building(store_type *s_ptr) +void show_building(store_type const *s_ptr) { - char buff[20]; + auto const &ba_info = game->edit_data.ba_info; + auto const &st_info = game->edit_data.st_info; - int i; - - byte action_color; - - char tmp_str[80]; - - store_info_type *st_ptr = &st_info[s_ptr->st_idx]; + auto st_ptr = &st_info[s_ptr->st_idx]; - - for (i = 0; i < 6; i++) + for (std::size_t i = 0; i < st_ptr->actions.size(); i++) { - store_action_type *ba_ptr = &ba_info[st_ptr->actions[i]]; + auto ba_ptr = &ba_info[st_ptr->actions[i]]; + + byte action_color; + char buff[20]; - if (ba_ptr->letter != '.') + if (ba_ptr->action_restr == 0) { - if (ba_ptr->action_restr == 0) + if ((is_state(s_ptr, STORE_LIKED) && (ba_ptr->costs[STORE_LIKED] == 0)) || + (is_state(s_ptr, STORE_HATED) && (ba_ptr->costs[STORE_HATED] == 0)) || + (is_state(s_ptr, STORE_NORMAL) && (ba_ptr->costs[STORE_NORMAL] == 0))) { - if ((is_state(s_ptr, STORE_LIKED) && (ba_ptr->costs[STORE_LIKED] == 0)) || - (is_state(s_ptr, STORE_HATED) && (ba_ptr->costs[STORE_HATED] == 0)) || - (is_state(s_ptr, STORE_NORMAL) && (ba_ptr->costs[STORE_NORMAL] == 0))) - { - action_color = TERM_WHITE; - buff[0] = '\0'; - } - else if (is_state(s_ptr, STORE_LIKED)) - { - action_color = TERM_L_GREEN; - strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_LIKED]); - } - else if (is_state(s_ptr, STORE_HATED)) - { - action_color = TERM_RED; - strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_HATED]); - } - else - { - action_color = TERM_YELLOW; - strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_NORMAL]); - } + action_color = TERM_WHITE; + buff[0] = '\0'; } - else if (ba_ptr->action_restr == 1) + else if (is_state(s_ptr, STORE_LIKED)) { - if ((is_state(s_ptr, STORE_LIKED) && (ba_ptr->costs[STORE_LIKED] == 0)) || - (is_state(s_ptr, STORE_NORMAL) && (ba_ptr->costs[STORE_NORMAL] == 0))) - { - action_color = TERM_WHITE; - buff[0] = '\0'; - } - else if (is_state(s_ptr, STORE_LIKED)) - { - action_color = TERM_L_GREEN; - strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_LIKED]); - } - else if (is_state(s_ptr, STORE_HATED)) - { - action_color = TERM_L_DARK; - strnfmt(buff, 20, "(closed)"); - } - else - { - action_color = TERM_YELLOW; - strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_NORMAL]); - } + action_color = TERM_L_GREEN; + strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_LIKED]); + } + else if (is_state(s_ptr, STORE_HATED)) + { + action_color = TERM_RED; + strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_HATED]); } else { - if (is_state(s_ptr, STORE_LIKED) && (ba_ptr->costs[STORE_LIKED] == 0)) - { - action_color = TERM_WHITE; - buff[0] = '\0'; - } - else if (is_state(s_ptr, STORE_LIKED)) - { - action_color = TERM_L_GREEN; - strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_LIKED]); - } - else - { - action_color = TERM_L_DARK; - strnfmt(buff, 20, "(closed)"); - } + action_color = TERM_YELLOW; + strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_NORMAL]); } + } + else if (ba_ptr->action_restr == 1) + { + if ((is_state(s_ptr, STORE_LIKED) && (ba_ptr->costs[STORE_LIKED] == 0)) || + (is_state(s_ptr, STORE_NORMAL) && (ba_ptr->costs[STORE_NORMAL] == 0))) + { + action_color = TERM_WHITE; + buff[0] = '\0'; + } + else if (is_state(s_ptr, STORE_LIKED)) + { + action_color = TERM_L_GREEN; + strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_LIKED]); + } + else if (is_state(s_ptr, STORE_HATED)) + { + action_color = TERM_L_DARK; + strnfmt(buff, 20, "(closed)"); + } + else + { + action_color = TERM_YELLOW; + strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_NORMAL]); + } + } + else + { + if (is_state(s_ptr, STORE_LIKED) && (ba_ptr->costs[STORE_LIKED] == 0)) + { + action_color = TERM_WHITE; + buff[0] = '\0'; + } + else if (is_state(s_ptr, STORE_LIKED)) + { + action_color = TERM_L_GREEN; + strnfmt(buff, 20, "(%dgp)", ba_ptr->costs[STORE_LIKED]); + } + else + { + action_color = TERM_L_DARK; + strnfmt(buff, 20, "(closed)"); + } + } - strnfmt(tmp_str, 80, " %c", ba_ptr->letter); - c_put_str(TERM_YELLOW, tmp_str, 21 + (i / 2), 17 + (30 * (i % 2))); + char tmp_str[80]; - strnfmt(tmp_str, 80, ") %s %s", ba_ptr->name, buff); - c_put_str(action_color, tmp_str, 21 + (i / 2), 2 + 17 + (30 * (i % 2))); - } + strnfmt(tmp_str, 80, " %c", ba_ptr->letter); + c_put_str(TERM_YELLOW, tmp_str, 21 + (i / 2), 17 + (30 * (i % 2))); + + strnfmt(tmp_str, 80, ") %s %s", ba_ptr->name.c_str(), buff); + c_put_str(action_color, tmp_str, 21 + (i / 2), 2 + 17 + (30 * (i % 2))); } } @@ -332,7 +332,7 @@ static bool_ gamble_comm(int cmd) if (cmd == BACT_GAMBLE_RULES) { /* Peruse the gambling help file */ - (void)show_file("gambling.txt", NULL, 0, 0); + show_file("gambling.txt", NULL); } else { @@ -541,7 +541,7 @@ static bool_ inn_comm(int cmd) /* Extract race info */ - vampire = ((race_flags1_p(PR1_VAMPIRE)) || (p_ptr->mimic_form == resolve_mimic_name("Vampire"))); + vampire = ((race_flags_p(PR_VAMPIRE)) || (p_ptr->mimic_form == resolve_mimic_name("Vampire"))); switch (cmd) { @@ -551,7 +551,7 @@ static bool_ inn_comm(int cmd) { msg_print("The barkeep gives you some gruel and a beer."); msg_print(NULL); - (void) set_food(PY_FOOD_MAX - 1); + set_food(PY_FOOD_MAX - 1); } else msg_print("You're a vampire and I don't have any food for you!"); @@ -743,7 +743,7 @@ static bool_ castle_quest(int y, int x) get_questinfo(plots[plot]); /* Add the hooks */ - quest[plots[plot]].init(plots[plot]); + quest[plots[plot]].init(); return (TRUE); } @@ -754,13 +754,13 @@ static bool_ castle_quest(int y, int x) /* * Displaying town history -KMW- */ -static void town_history(void) +static void town_history() { /* Save screen */ screen_save(); /* Peruse the building help file */ - (void)show_file("bldg.txt", NULL, 0, 0); + show_file("bldg.txt", NULL); /* Load screen */ screen_load(); @@ -770,7 +770,7 @@ static void town_history(void) /* * compare_weapon_aux2 -KMW- */ -static void compare_weapon_aux2(object_type *o_ptr, int numblows, int r, int c, int mult, const char *attr, u32b f1, u32b f2, u32b f3, byte color) +static void compare_weapon_aux2(object_type *o_ptr, int numblows, int r, int c, int mult, const char *attr, byte color) { char tmp_str[80]; @@ -788,80 +788,77 @@ static void compare_weapon_aux2(object_type *o_ptr, int numblows, int r, int c, */ static void compare_weapon_aux1(object_type *o_ptr, int col, int r) { - u32b f1, f2, f3, f4, f5, esp; - - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const f = object_flags(o_ptr); - - if (f1 & (TR1_SLAY_ANIMAL)) + if (f & TR_SLAY_ANIMAL) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 2, "Animals:", - f1, f2, f3, TERM_YELLOW); + TERM_YELLOW); } - if (f1 & (TR1_SLAY_EVIL)) + if (f & TR_SLAY_EVIL) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 2, "Evil:", - f1, f2, f3, TERM_YELLOW); + TERM_YELLOW); } - if (f1 & (TR1_SLAY_UNDEAD)) + if (f & TR_SLAY_UNDEAD) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 3, "Undead:", - f1, f2, f3, TERM_YELLOW); + TERM_YELLOW); } - if (f1 & (TR1_SLAY_DEMON)) + if (f & TR_SLAY_DEMON) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 3, "Demons:", - f1, f2, f3, TERM_YELLOW); + TERM_YELLOW); } - if (f1 & (TR1_SLAY_ORC)) + if (f & TR_SLAY_ORC) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 3, "Orcs:", - f1, f2, f3, TERM_YELLOW); + TERM_YELLOW); } - if (f1 & (TR1_SLAY_TROLL)) + if (f & TR_SLAY_TROLL) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 3, "Trolls:", - f1, f2, f3, TERM_YELLOW); + TERM_YELLOW); } - if (f1 & (TR1_SLAY_GIANT)) + if (f & TR_SLAY_GIANT) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 3, "Giants:", - f1, f2, f3, TERM_YELLOW); + TERM_YELLOW); } - if (f1 & (TR1_SLAY_DRAGON)) + if (f & TR_SLAY_DRAGON) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 3, "Dragons:", - f1, f2, f3, TERM_YELLOW); + TERM_YELLOW); } - if (f1 & (TR1_KILL_DRAGON)) + if (f & TR_KILL_DRAGON) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 5, "Dragons:", - f1, f2, f3, TERM_YELLOW); + TERM_YELLOW); } - if (f1 & (TR1_BRAND_ACID)) + if (f & TR_BRAND_ACID) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 3, "Acid:", - f1, f2, f3, TERM_RED); + TERM_RED); } - if (f1 & (TR1_BRAND_ELEC)) + if (f & TR_BRAND_ELEC) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 3, "Elec:", - f1, f2, f3, TERM_RED); + TERM_RED); } - if (f1 & (TR1_BRAND_FIRE)) + if (f & TR_BRAND_FIRE) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 3, "Fire:", - f1, f2, f3, TERM_RED); + TERM_RED); } - if (f1 & (TR1_BRAND_COLD)) + if (f & TR_BRAND_COLD) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 3, "Cold:", - f1, f2, f3, TERM_RED); + TERM_RED); } - if (f1 & (TR1_BRAND_POIS)) + if (f & TR_BRAND_POIS) { compare_weapon_aux2(o_ptr, p_ptr->num_blow, r++, col, 3, "Poison:", - f1, f2, f3, TERM_RED); + TERM_RED); } } @@ -905,7 +902,7 @@ static bool item_tester_hook_melee_weapon(object_type const *o_ptr) /* * compare_weapons -KMW- */ -static bool_ compare_weapons(void) +static bool_ compare_weapons() { int item, i; @@ -989,8 +986,7 @@ static bool_ compare_weapons(void) * sharpen arrows, repair armor, repair weapon * -KMW- */ -static bool_ fix_item(int istart, int iend, int ispecific, bool_ iac, - int ireward, bool_ set_reward) +static bool_ fix_item(int istart, int iend, int ispecific, bool_ iac) { int i; @@ -1084,7 +1080,7 @@ static bool_ fix_item(int istart, int iend, int ispecific, bool_ iac, /* * Research Item */ -static bool_ research_item(void) +static bool_ research_item() { clear_bldg(5, 18); return (identify_fully()); @@ -1095,18 +1091,14 @@ static bool_ research_item(void) /* * Execute a building command */ -bool_ bldg_process_command(store_type *s_ptr, int i) +bool_ bldg_process_command(const store_type *s_ptr, store_action_type const *ba_ptr) { - store_action_type *ba_ptr = &ba_info[st_info[s_ptr->st_idx].actions[i]]; - int bact = ba_ptr->action; int bcost; bool_ paid = FALSE; - bool_ set_reward = FALSE; - bool_ recreate = FALSE; @@ -1140,8 +1132,6 @@ bool_ bldg_process_command(store_type *s_ptr, int i) return FALSE; } - if (!bcost) set_reward = TRUE; - switch (bact) { case BACT_RESEARCH_ITEM: @@ -1218,12 +1208,6 @@ bool_ bldg_process_command(store_type *s_ptr, int i) break; } - case BACT_RESEARCH_MONSTER: - { - paid = !research_mon(); - break; - } - case BACT_COMPARE_WEAPONS: { paid = compare_weapons(); @@ -1232,15 +1216,13 @@ bool_ bldg_process_command(store_type *s_ptr, int i) case BACT_ENCHANT_WEAPON: { - paid = fix_item(INVEN_WIELD, INVEN_WIELD, 0, FALSE, - BACT_ENCHANT_WEAPON, set_reward); + paid = fix_item(INVEN_WIELD, INVEN_WIELD, 0, FALSE); break; } case BACT_ENCHANT_ARMOR: { - paid = fix_item(INVEN_BODY, INVEN_FEET, 0, TRUE, - BACT_ENCHANT_ARMOR, set_reward); + paid = fix_item(INVEN_BODY, INVEN_FEET, 0, TRUE); break; } @@ -1306,15 +1288,13 @@ bool_ bldg_process_command(store_type *s_ptr, int i) case BACT_ENCHANT_ARROWS: { - paid = fix_item(0, INVEN_WIELD, TV_ARROW, FALSE, - BACT_ENCHANT_ARROWS, set_reward); + paid = fix_item(0, INVEN_WIELD, TV_ARROW, FALSE); break; } case BACT_ENCHANT_BOW: { - paid = fix_item(INVEN_BOW, INVEN_BOW, TV_BOW, FALSE, - BACT_ENCHANT_BOW, set_reward); + paid = fix_item(INVEN_BOW, INVEN_BOW, TV_BOW, FALSE); break; } @@ -1445,7 +1425,7 @@ bool_ bldg_process_command(store_type *s_ptr, int i) /* * Enter quest level */ -void enter_quest(void) +void enter_quest() { if (!(cave[p_ptr->py][p_ptr->px].feat == FEAT_QUEST_ENTER)) { diff --git a/src/bldg.hpp b/src/bldg.hpp index 0daebbee..3b3412fa 100644 --- a/src/bldg.hpp +++ b/src/bldg.hpp @@ -1,9 +1,10 @@ #pragma once #include "h-basic.h" +#include "store_action_type_fwd.hpp" #include "store_type_fwd.hpp" -extern bool_ bldg_process_command(store_type *s_ptr, int i); -extern void show_building(store_type *s_ptr); -extern bool_ is_state(store_type *s_ptr, int state); -extern void enter_quest(void); +bool_ bldg_process_command(store_type const *s_ptr, store_action_type const *action); +void show_building(store_type const *s_ptr); +bool_ is_state(store_type const *s_ptr, int state); +void enter_quest(); diff --git a/src/cave.cc b/src/cave.cc index 5ff31019..cad1506e 100644 --- a/src/cave.cc +++ b/src/cave.cc @@ -1,12 +1,18 @@ #include "cave.hpp" #include "cave_type.hpp" +#include "dungeon_flag.hpp" +#include "feature_flag.hpp" #include "feature_type.hpp" +#include "game.hpp" #include "hook_enter_dungeon_in.hpp" #include "monster2.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" +#include "monster_spell_flag.hpp" #include "monster_type.hpp" #include "object1.hpp" +#include "object_flag.hpp" #include "object_kind.hpp" #include "options.hpp" #include "player_type.hpp" @@ -14,7 +20,6 @@ #include "spells1.hpp" #include "store_info_type.hpp" #include "tables.hpp" -#include "trap_type.hpp" #include "util.hpp" #include "util.h" #include "variable.h" @@ -64,15 +69,15 @@ int distance(int y1, int x1, int y2, int x2) */ static bool_ is_wall(cave_type *c_ptr) { - byte feat; - + auto const &f_info = game->edit_data.f_info; /* Handle feature mimics */ - if (c_ptr->mimic) feat = c_ptr->mimic; - else feat = c_ptr->feat; + byte const feat = c_ptr->mimic + ? c_ptr->mimic + : c_ptr->feat; /* Paranoia */ - if (feat >= max_f_idx) return FALSE; + if (feat >= f_info.size()) return FALSE; /* Vanilla floors and doors aren't considered to be walls */ if (feat < FEAT_SECRET) return FALSE; @@ -87,7 +92,7 @@ static bool_ is_wall(cave_type *c_ptr) if (feat == FEAT_SMALL_TREES) return TRUE; /* Normal cases: use the WALL flag in f_info.txt */ - return (f_info[feat].flags1 & FF1_WALL) ? TRUE : FALSE; + return (f_info[feat].flags & FF_WALL) ? TRUE : FALSE; } @@ -353,7 +358,7 @@ bool_ los(int y1, int x1, int y2, int x2) /* * Returns true if the player's grid is dark */ -bool_ no_lite(void) +bool_ no_lite() { return (!player_can_see_bold(p_ptr->py, p_ptr->px)); } @@ -379,7 +384,10 @@ bool_ cave_valid_bold(int y, int x) object_type *o_ptr = &o_list[o_idx]; /* Forbid artifact grids */ - if ((o_ptr->art_name) || artifact_p(o_ptr)) return (FALSE); + if (artifact_p(o_ptr)) + { + return (FALSE); + } } /* Accept */ @@ -393,6 +401,8 @@ bool_ cave_valid_bold(int y, int x) */ static void image_monster(byte *ap, char *cp) { + auto const &r_info = game->edit_data.r_info; + // Cached state which keeps a list of all the "live" monster race entries. static std::vector<size_t> *instance = nullptr; @@ -402,7 +412,7 @@ static void image_monster(byte *ap, char *cp) // Create the list of "live" indexes instance = new std::vector<size_t>(); // Start at 1 to avoid 'player' - for (size_t i = 1; i < max_r_idx; i++) + for (size_t i = 1; i < r_info.size(); i++) { if (r_info[i].name) { @@ -426,6 +436,8 @@ static void image_monster(byte *ap, char *cp) */ static void image_object(byte *ap, char *cp) { + auto const &k_info = game->edit_data.k_info; + // Cached state which keeps a list of the "live" object_kind entries. static std::vector<size_t> *instance = nullptr; @@ -435,7 +447,7 @@ static void image_object(byte *ap, char *cp) // Create the list of "live" indexes instance = new std::vector<size_t>(); // Filter all the "live" entries - for (size_t i = 0; i < max_k_idx; i++) + for (size_t i = 0; i < k_info.size(); i++) { if (k_info[i].name) { @@ -499,50 +511,60 @@ static char get_shimmer_color() /* - * Table of breath colors. Must match listings in a single set of - * monster spell flags. - * - * The value "255" is special. Monsters with that kind of breath - * may be any color. + * Breath color */ -static byte breath_to_attr[32][2] = -{ - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { 0, 0 }, - { TERM_SLATE, TERM_L_DARK }, /* RF4_BRTH_ACID */ - { TERM_BLUE, TERM_L_BLUE }, /* RF4_BRTH_ELEC */ - { TERM_RED, TERM_L_RED }, /* RF4_BRTH_FIRE */ - { TERM_WHITE, TERM_L_WHITE }, /* RF4_BRTH_COLD */ - { TERM_GREEN, TERM_L_GREEN }, /* RF4_BRTH_POIS */ - { TERM_L_GREEN, TERM_GREEN }, /* RF4_BRTH_NETHR */ - { TERM_YELLOW, TERM_ORANGE }, /* RF4_BRTH_LITE */ - { TERM_L_DARK, TERM_SLATE }, /* RF4_BRTH_DARK */ - { TERM_L_UMBER, TERM_UMBER }, /* RF4_BRTH_CONFU */ - { TERM_YELLOW, TERM_L_UMBER }, /* RF4_BRTH_SOUND */ - { 255, 255 }, /* (any color) */ /* RF4_BRTH_CHAOS */ - { TERM_VIOLET, TERM_VIOLET }, /* RF4_BRTH_DISEN */ - { TERM_L_RED, TERM_VIOLET }, /* RF4_BRTH_NEXUS */ - { TERM_L_BLUE, TERM_L_BLUE }, /* RF4_BRTH_TIME */ - { TERM_L_WHITE, TERM_SLATE }, /* RF4_BRTH_INER */ - { TERM_L_WHITE, TERM_SLATE }, /* RF4_BRTH_GRAV */ - { TERM_UMBER, TERM_L_UMBER }, /* RF4_BRTH_SHARD */ - { TERM_ORANGE, TERM_RED }, /* RF4_BRTH_PLAS */ - { TERM_UMBER, TERM_L_UMBER }, /* RF4_BRTH_FORCE */ - { TERM_L_BLUE, TERM_WHITE }, /* RF4_BRTH_MANA */ - { 0, 0 }, /* */ - { TERM_GREEN, TERM_L_GREEN }, /* RF4_BRTH_NUKE */ - { 0, 0 }, /* */ - { TERM_WHITE, TERM_L_RED }, /* RF4_BRTH_DISINT */ +struct breath_color { + std::size_t breath_idx; + byte first_color; + byte second_color; }; /* + * Breath colors. The value "255" is special. Monsters with + * that kind of breath may be any color. + */ +static breath_color const *lookup_breath_color(std::size_t i) +{ + static breath_color breath_to_attr[] = + { + { SF_BR_ACID_IDX, TERM_SLATE, TERM_L_DARK }, + { SF_BR_ELEC_IDX, TERM_BLUE, TERM_L_BLUE }, + { SF_BR_FIRE_IDX, TERM_RED, TERM_L_RED }, + { SF_BR_COLD_IDX, TERM_WHITE, TERM_L_WHITE }, + { SF_BR_POIS_IDX, TERM_GREEN, TERM_L_GREEN }, + { SF_BR_NETH_IDX, TERM_L_GREEN, TERM_GREEN }, + { SF_BR_LITE_IDX, TERM_YELLOW, TERM_ORANGE }, + { SF_BR_DARK_IDX, TERM_L_DARK, TERM_SLATE }, + { SF_BR_CONF_IDX, TERM_L_UMBER, TERM_UMBER }, + { SF_BR_SOUN_IDX, TERM_YELLOW, TERM_L_UMBER }, + { SF_BR_CHAO_IDX, 255, 255 }, + { SF_BR_DISE_IDX, TERM_VIOLET, TERM_VIOLET }, + { SF_BR_NEXU_IDX, TERM_L_RED, TERM_VIOLET }, + { SF_BR_TIME_IDX, TERM_L_BLUE, TERM_L_BLUE }, + { SF_BR_INER_IDX, TERM_L_WHITE, TERM_SLATE }, + { SF_BR_GRAV_IDX, TERM_L_WHITE, TERM_SLATE }, + { SF_BR_SHAR_IDX, TERM_UMBER, TERM_L_UMBER }, + { SF_BR_PLAS_IDX, TERM_ORANGE, TERM_RED }, + { SF_BR_WALL_IDX, TERM_UMBER, TERM_L_UMBER }, + { SF_BR_MANA_IDX, TERM_L_BLUE, TERM_WHITE }, + { SF_BR_NUKE_IDX, TERM_GREEN, TERM_L_GREEN }, + { SF_BR_DISI_IDX, TERM_WHITE, TERM_L_RED }, + }; + + for (auto const &breath_color: breath_to_attr) + { + if (breath_color.breath_idx == i) + { + return &breath_color; + } + } + + return nullptr; +} + + +/* * Multi-hued monsters shimmer acording to their breaths. * * If a monster has only one kind of breath, it uses both colors @@ -555,9 +577,7 @@ static byte multi_hued_attr(std::shared_ptr<monster_race> r_ptr) { byte allowed_attrs[15]; - int i, j; - - int stored_colors = 0; + std::size_t stored_colors = 0; int breaths = 0; @@ -570,18 +590,22 @@ static byte multi_hued_attr(std::shared_ptr<monster_race> r_ptr) if (!r_ptr->freq_inate) return (get_shimmer_color()); /* Check breaths */ - for (i = 0; i < 32; i++) + for (std::size_t i = 0; i < monster_spell_flag_set::nbits; i++) { bool_ stored = FALSE; /* Don't have that breath */ - if (!(r_ptr->flags4 & (1L << i))) continue; + if (!(r_ptr->spells.bit(i))) continue; - /* Get the first color of this breath */ - first_color = breath_to_attr[i][0]; + /* Find the breath in our list */ + auto breath_color = lookup_breath_color(i); + if (!breath_color) + { + continue; + } - /* Breath has no color associated with it */ - if (first_color == 0) continue; + /* Get the first color of this breath */ + first_color = breath_color->first_color; /* Monster can be of any color */ if (first_color == 255) return (randint(15)); @@ -595,7 +619,7 @@ static byte multi_hued_attr(std::shared_ptr<monster_race> r_ptr) /* Always store the first color */ - for (j = 0; j < stored_colors; j++) + for (std::size_t j = 0; j < stored_colors; j++) { /* Already stored */ if (allowed_attrs[j] == first_color) stored = TRUE; @@ -612,7 +636,7 @@ static byte multi_hued_attr(std::shared_ptr<monster_race> r_ptr) */ if (breaths == 1) { - second_color = breath_to_attr[i][1]; + second_color = breath_color->second_color; } } @@ -825,6 +849,11 @@ static byte darker_attrs[16] = static void map_info(int y, int x, byte *ap, char *cp) { + auto const &st_info = game->edit_data.st_info; + auto const &r_info = game->edit_data.r_info; + auto const &f_info = game->edit_data.f_info; + auto const &k_info = game->edit_data.k_info; + byte a; byte c; @@ -841,20 +870,13 @@ static void map_info(int y, int x, byte *ap, char *cp) auto info = c_ptr->info; /* Feature code */ - auto feat = c_ptr->feat; - - /* Apply "mimic" field */ - if (c_ptr->mimic) - { - feat = c_ptr->mimic; - } - else - { - feat = f_info[feat].mimic; - } + auto const feat = c_ptr->mimic + ? c_ptr->mimic + : f_info[c_ptr->feat].mimic + ; /* Access floor */ - feature_type *f_ptr = &f_info[feat]; + auto f_ptr = &f_info[feat]; /**** Layer 1 -- Terrain feature ****/ @@ -887,43 +909,8 @@ static void map_info(int y, int x, byte *ap, char *cp) a = TERM_VIOLET; } - /* Mega-Hack 3 -- Traps don't have f_info entries either */ - if ((info & (CAVE_TRDT)) && (feat != FEAT_ILLUS_WALL)) - { - /* Trap index */ - auto t_idx = c_ptr->t_idx; - - /* - * If trap is set on a floor grid that is not - * one of "interesting" features, use a special - * symbol to display it. Check for doors is no longer - * necessary because they have REMEMBER flag now. - * - * Cave macros cannot be used safely here, because of - * c_ptr->mimic XXX XXX - */ - if ((f_ptr->flags1 & (FF1_FLOOR | FF1_REMEMBER)) == FF1_FLOOR) - { - c = f_info[FEAT_TRAP].x_char; - } - - /* Add attr XXX XXX XXX */ - a = t_info[t_idx].color; - - /* Get a new color with a strange formula :) XXX XXX XXX */ - if (t_info[t_idx].flags & FTRAP_CHANGE) - { - s32b tmp; - - tmp = dun_level + dungeon_type + feat; - - a = tmp % 16; - } - } - - /**** Step 2 -- Apply special random effects ****/ - if (!avoid_other && !avoid_shimmer) + if (!options->avoid_other && !options->avoid_shimmer) { /* Special terrain effect */ if (c_ptr->effect) @@ -932,7 +919,7 @@ static void map_info(int y, int x, byte *ap, char *cp) } /* Multi-hued attr */ - else if (f_ptr->flags1 & FF1_ATTR_MULTI) + else if (f_ptr->flags & FF_ATTR_MULTI) { a = f_ptr->shimmer[rand_int(7)]; } @@ -945,7 +932,6 @@ static void map_info(int y, int x, byte *ap, char *cp) * Special lighting effects, if specified and applicable * This will never happen for * - any grids in the overhead map - * - traps * - (graphics modes) terrain features without corresponding * "darker" tiles. * @@ -954,16 +940,16 @@ static void map_info(int y, int x, byte *ap, char *cp) */ /* view_special_lite: lighting effects for boring features */ - if (view_special_lite && - ((f_ptr->flags1 & (FF1_FLOOR | FF1_REMEMBER)) == FF1_FLOOR)) + if (options->view_special_lite && + ((f_ptr->flags & (FF_FLOOR | FF_REMEMBER)) == FF_FLOOR)) { - if (!p_ptr->wild_mode && !(info & (CAVE_TRDT))) + if (!p_ptr->wild_mode) { /* Handle "seen" grids */ if (info & (CAVE_SEEN)) { /* Only lit by "torch" light */ - if (view_yellow_lite && !(info & (CAVE_GLOW))) + if (options->view_yellow_lite && !(info & (CAVE_GLOW))) { /* Use "yellow" */ a = TERM_YELLOW; @@ -985,7 +971,7 @@ static void map_info(int y, int x, byte *ap, char *cp) } /* "Out-of-sight" glowing grids -- handle "view_bright_lite" */ - else if (view_bright_lite) + else if (options->view_bright_lite) { /* Use darker colour */ a = dark_attrs[a & 0xF]; @@ -994,10 +980,10 @@ static void map_info(int y, int x, byte *ap, char *cp) } /* view_granite_lite: lighting effects for walls and doors */ - else if (view_granite_lite && - (f_ptr->flags1 & (FF1_NO_VISION | FF1_DOOR))) + else if (options->view_granite_lite && + (f_ptr->flags & (FF_NO_VISION | FF_DOOR))) { - if (!p_ptr->wild_mode && !(info & (CAVE_TRDT))) + if (!p_ptr->wild_mode) { /* Handle "seen" grids */ if (info & (CAVE_SEEN)) @@ -1013,7 +999,7 @@ static void map_info(int y, int x, byte *ap, char *cp) } /* Handle "view_bright_lite" */ - else if (view_bright_lite) + else if (options->view_bright_lite) { /* Use darker colour */ a = dark_attrs[a & 0xF]; @@ -1058,34 +1044,31 @@ static void map_info(int y, int x, byte *ap, char *cp) /**** Layer 2 -- Objects ****/ - if (feat != FEAT_MON_TRAP) + for (auto const o_idx: c_ptr->o_idxs) { - for (auto const o_idx: c_ptr->o_idxs) - { - /* Acquire object */ - object_type *o_ptr = &o_list[o_idx]; + /* Acquire object */ + object_type *o_ptr = &o_list[o_idx]; - /* Memorized objects */ - if (o_ptr->marked) - { - /* Normal char */ - *cp = object_char(o_ptr); + /* Memorized objects */ + if (o_ptr->marked) + { + /* Normal char */ + *cp = object_char(o_ptr); - /* Normal attr */ - *ap = object_attr(o_ptr); + /* Normal attr */ + *ap = object_attr(o_ptr); - /* Multi-hued attr */ - if (!avoid_other && (k_info[o_ptr->k_idx].flags5 & TR5_ATTR_MULTI)) - { - *ap = get_shimmer_color(); - } + /* Multi-hued attr */ + if (!options->avoid_other && (k_info[o_ptr->k_idx].flags & TR_ATTR_MULTI)) + { + *ap = get_shimmer_color(); + } - /* Hack -- hallucination */ - if (p_ptr->image) image_object(ap, cp); + /* Hack -- hallucination */ + if (p_ptr->image) image_object(ap, cp); - /* Done */ - break; - } + /* Done */ + break; } } @@ -1097,7 +1080,7 @@ static void map_info(int y, int x, byte *ap, char *cp) monster_type *m_ptr = &m_list[c_ptr->m_idx]; auto const r_ptr = m_ptr->race(); - if (r_ptr->flags9 & RF9_MIMIC) + if (r_ptr->flags & RF_MIMIC) { /* Acquire object being mimicked */ object_type *o_ptr = &o_list[m_ptr->mimic_o_idx()]; @@ -1112,7 +1095,7 @@ static void map_info(int y, int x, byte *ap, char *cp) *ap = object_attr(o_ptr); /* Multi-hued attr */ - if (!avoid_other && (k_info[o_ptr->k_idx].flags5 & TR5_ATTR_MULTI)) + if (!options->avoid_other && (k_info[o_ptr->k_idx].flags & TR_ATTR_MULTI)) { *ap = get_shimmer_color(); } @@ -1131,7 +1114,7 @@ static void map_info(int y, int x, byte *ap, char *cp) a = r_ptr->x_attr; /* Ignore weird codes */ - if (avoid_other) + if (options->avoid_other) { /* Use char */ *cp = c; @@ -1141,10 +1124,10 @@ static void map_info(int y, int x, byte *ap, char *cp) } /* Multi-hued monster */ - else if (r_ptr->flags1 & (RF1_ATTR_MULTI)) + else if (r_ptr->flags & RF_ATTR_MULTI) { /* Is it a shapechanger? */ - if (r_ptr->flags2 & (RF2_SHAPECHANGER)) + if (r_ptr->flags & RF_SHAPECHANGER) { image_random(ap, cp); } @@ -1152,7 +1135,7 @@ static void map_info(int y, int x, byte *ap, char *cp) *cp = c; /* Multi-hued attr */ - if (r_ptr->flags2 & (RF2_ATTR_ANY)) + if (r_ptr->flags & RF_ATTR_ANY) { *ap = randint(15); } @@ -1163,7 +1146,7 @@ static void map_info(int y, int x, byte *ap, char *cp) } /* Normal monster (not "clear" in any way) */ - else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR | RF1_CHAR_CLEAR))) + else if (!(r_ptr->flags & (RF_ATTR_CLEAR | RF_CHAR_CLEAR))) { /* Use char */ *cp = c; @@ -1189,14 +1172,14 @@ static void map_info(int y, int x, byte *ap, char *cp) else { /* Normal (non-clear char) monster */ - if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR))) + if (!(r_ptr->flags & RF_CHAR_CLEAR)) { /* Normal char */ *cp = c; } /* Normal (non-clear attr) monster */ - else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR))) + else if (!(r_ptr->flags & RF_ATTR_CLEAR)) { /* Normal attr */ *ap = a; @@ -1217,10 +1200,10 @@ static void map_info(int y, int x, byte *ap, char *cp) if ((y == p_ptr->py) && (x == p_ptr->px) && (!p_ptr->invis || p_ptr->see_inv)) { - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; /* Get the "player" attr */ - if (!avoid_other && (r_ptr->flags1 & RF1_ATTR_MULTI)) + if (!options->avoid_other && (r_ptr->flags & RF_ATTR_MULTI)) { a = get_shimmer_color(); } @@ -1233,7 +1216,7 @@ static void map_info(int y, int x, byte *ap, char *cp) c = r_ptr->x_char; /* Show player health char instead? */ - if (player_char_health) + if (options->player_char_health) { int percent = p_ptr->chp * 10 / p_ptr->mhp; @@ -1258,14 +1241,22 @@ static void map_info(int y, int x, byte *ap, char *cp) */ void map_info_default(int y, int x, byte *ap, char *cp) { + auto const &st_info = game->edit_data.st_info; + auto const &r_info = game->edit_data.r_info; + auto const &f_info = game->edit_data.f_info; + auto const &k_info = game->edit_data.k_info; + byte a; byte c; + /* Shorthand */ + auto const avoid_other = options->avoid_other; + /**** Preparation ****/ /* Access the grid */ - cave_type *c_ptr = &cave[y][x]; + auto const c_ptr = &cave[y][x]; /* Cache some frequently used values */ @@ -1274,20 +1265,12 @@ void map_info_default(int y, int x, byte *ap, char *cp) auto info = c_ptr->info; /* Feature code */ - auto feat = c_ptr->feat; - - /* Apply "mimic" field */ - if (c_ptr->mimic) - { - feat = c_ptr->mimic; - } - else - { - feat = f_info[feat].mimic; - } + auto const feat = c_ptr->mimic + ? c_ptr->mimic + : f_info[c_ptr->feat].mimic; /* Access floor */ - feature_type *f_ptr = &f_info[feat]; + feature_type const *f_ptr = &f_info[feat]; /**** Layer 1 -- Terrain feature ****/ @@ -1321,41 +1304,6 @@ void map_info_default(int y, int x, byte *ap, char *cp) a = TERM_VIOLET; } - /* Mega-Hack 3 -- Traps don't have f_info entries either */ - if ((info & (CAVE_TRDT)) && (feat != FEAT_ILLUS_WALL)) - { - /* Trap index */ - auto t_idx = c_ptr->t_idx; - - /* - * If trap is set on a floor grid that is not - * one of "interesting" features, use a special - * symbol to display it. Check for doors is no longer - * necessary because they have REMEMBER flag now. - * - * Cave macros cannot be used safely here, because of - * c_ptr->mimic XXX XXX - */ - if ((f_ptr->flags1 & (FF1_FLOOR | FF1_REMEMBER)) == FF1_FLOOR) - { - c = f_info[FEAT_TRAP].d_char; - } - - /* Add attr */ - a = t_info[t_idx].color; - - /* Get a new color with a strange formula :) */ - if (t_info[t_idx].flags & FTRAP_CHANGE) - { - s32b tmp; - - tmp = dun_level + dungeon_type + feat; - - a = tmp % 16; - } - } - - /**** Step 2 -- Apply special random effects ****/ if (!avoid_other) { @@ -1366,7 +1314,7 @@ void map_info_default(int y, int x, byte *ap, char *cp) } /* Multi-hued attr */ - else if (f_ptr->flags1 & FF1_ATTR_MULTI) + else if (f_ptr->flags & FF_ATTR_MULTI) { a = f_ptr->shimmer[rand_int(7)]; } @@ -1379,7 +1327,6 @@ void map_info_default(int y, int x, byte *ap, char *cp) * Special lighting effects, if specified and applicable * This will never happen for * - any grids in the overhead map - * - traps * - (graphics modes) terrain features without corresponding * "darker" tiles. * @@ -1388,16 +1335,16 @@ void map_info_default(int y, int x, byte *ap, char *cp) */ /* view_special_lite: lighting effects for boring features */ - if (view_special_lite && - ((f_ptr->flags1 & (FF1_FLOOR | FF1_REMEMBER)) == FF1_FLOOR)) + if (options->view_special_lite && + ((f_ptr->flags & (FF_FLOOR | FF_REMEMBER)) == FF_FLOOR)) { - if (!p_ptr->wild_mode && !(info & (CAVE_TRDT))) + if (!p_ptr->wild_mode) { /* Handle "seen" grids */ if (info & (CAVE_SEEN)) { /* Only lit by "torch" light */ - if (view_yellow_lite && !(info & (CAVE_GLOW))) + if (options->view_yellow_lite && !(info & (CAVE_GLOW))) { /* Use "yellow" */ a = TERM_YELLOW; @@ -1419,7 +1366,7 @@ void map_info_default(int y, int x, byte *ap, char *cp) } /* "Out-of-sight" glowing grids -- handle "view_bright_lite" */ - else if (view_bright_lite) + else if (options->view_bright_lite) { /* Use darker colour */ a = dark_attrs[a & 0xF]; @@ -1428,10 +1375,10 @@ void map_info_default(int y, int x, byte *ap, char *cp) } /* view_granite_lite: lighting effects for walls and doors */ - else if (view_granite_lite && - (f_ptr->flags1 & (FF1_NO_VISION | FF1_DOOR))) + else if (options->view_granite_lite && + (f_ptr->flags & (FF_NO_VISION | FF_DOOR))) { - if (!p_ptr->wild_mode && !(info & (CAVE_TRDT))) + if (!p_ptr->wild_mode) { /* Handle "seen" grids */ if (info & (CAVE_SEEN)) @@ -1447,7 +1394,7 @@ void map_info_default(int y, int x, byte *ap, char *cp) } /* Handle "view_bright_lite" */ - else if (view_bright_lite) + else if (options->view_bright_lite) { /* Use darker colour */ a = dark_attrs[a & 0xF]; @@ -1487,35 +1434,31 @@ void map_info_default(int y, int x, byte *ap, char *cp) /**** Layer 2 -- Objects ****/ - if (feat != FEAT_MON_TRAP) + for (auto const this_o_idx: c_ptr->o_idxs) { - for (auto const this_o_idx: c_ptr->o_idxs) + /* Acquire object */ + object_type *o_ptr = &o_list[this_o_idx]; + + /* Memorized objects */ + if (o_ptr->marked) { - /* Acquire object */ - object_type *o_ptr = &o_list[this_o_idx]; + /* Normal char */ + *cp = object_char_default(o_ptr); - /* Memorized objects */ - if (o_ptr->marked) - { - /* Normal char */ - *cp = object_char_default(o_ptr); + /* Normal attr */ + *ap = object_attr_default(o_ptr); - /* Normal attr */ - *ap = object_attr_default(o_ptr); + /* Multi-hued attr */ + if (!avoid_other && (k_info[o_ptr->k_idx].flags & TR_ATTR_MULTI)) + { + *ap = get_shimmer_color(); + } - /* Multi-hued attr */ - if (!avoid_other && - (k_info[o_ptr->k_idx].flags5 & TR5_ATTR_MULTI)) - { - *ap = get_shimmer_color(); - } + /* Hack -- hallucination */ + if (p_ptr->image) image_object(ap, cp); - /* Hack -- hallucination */ - if (p_ptr->image) image_object(ap, cp); - - /* Done */ - break; - } + /* Done */ + break; } } @@ -1527,7 +1470,7 @@ void map_info_default(int y, int x, byte *ap, char *cp) monster_type *m_ptr = &m_list[c_ptr->m_idx]; auto const r_ptr = m_ptr->race(); - if (r_ptr->flags9 & RF9_MIMIC) + if (r_ptr->flags & RF_MIMIC) { /* Acquire object being mimicked */ object_type *o_ptr = &o_list[m_ptr->mimic_o_idx()]; @@ -1542,7 +1485,7 @@ void map_info_default(int y, int x, byte *ap, char *cp) *ap = object_attr_default(o_ptr); /* Multi-hued attr */ - if (!avoid_other && (k_info[o_ptr->k_idx].flags5 & TR5_ATTR_MULTI)) + if (!avoid_other && (k_info[o_ptr->k_idx].flags & TR_ATTR_MULTI)) { *ap = get_shimmer_color(); } @@ -1571,10 +1514,10 @@ void map_info_default(int y, int x, byte *ap, char *cp) } /* Multi-hued monster */ - else if (r_ptr->flags1 & (RF1_ATTR_MULTI)) + else if (r_ptr->flags & RF_ATTR_MULTI) { /* Is it a shapechanger? */ - if (r_ptr->flags2 & (RF2_SHAPECHANGER)) + if (r_ptr->flags & RF_SHAPECHANGER) { image_random(ap, cp); } @@ -1582,7 +1525,7 @@ void map_info_default(int y, int x, byte *ap, char *cp) *cp = c; /* Multi-hued attr */ - if (r_ptr->flags2 & (RF2_ATTR_ANY)) + if (r_ptr->flags & RF_ATTR_ANY) { *ap = randint(15); } @@ -1593,7 +1536,7 @@ void map_info_default(int y, int x, byte *ap, char *cp) } /* Normal monster (not "clear" in any way) */ - else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR | RF1_CHAR_CLEAR))) + else if (!(r_ptr->flags & (RF_ATTR_CLEAR | RF_CHAR_CLEAR))) { /* Use char */ *cp = c; @@ -1616,14 +1559,14 @@ void map_info_default(int y, int x, byte *ap, char *cp) else { /* Normal (non-clear char) monster */ - if (!(r_ptr->flags1 & (RF1_CHAR_CLEAR))) + if (!(r_ptr->flags & RF_CHAR_CLEAR)) { /* Normal char */ *cp = c; } /* Normal (non-clear attr) monster */ - else if (!(r_ptr->flags1 & (RF1_ATTR_CLEAR))) + else if (!(r_ptr->flags & RF_ATTR_CLEAR)) { /* Normal attr */ *ap = a; @@ -1646,10 +1589,10 @@ void map_info_default(int y, int x, byte *ap, char *cp) (!p_ptr->invis || (p_ptr->invis && p_ptr->see_inv))) { - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; /* Get the "player" attr */ - if (!avoid_other && (r_ptr->flags1 & RF1_ATTR_MULTI)) + if (!avoid_other && (r_ptr->flags & RF_ATTR_MULTI)) { a = get_shimmer_color(); } @@ -1774,7 +1717,7 @@ void note_spot(int y, int x) monster_type *m_ptr = &m_list[c_ptr->m_idx]; auto r_ptr = m_ptr->race(); - if (r_ptr->flags9 & RF9_MIMIC) + if (r_ptr->flags & RF_MIMIC) { object_type *o_ptr = &o_list[m_ptr->mimic_o_idx()]; o_ptr->marked = TRUE; @@ -1783,18 +1726,17 @@ void note_spot(int y, int x) /* Hack -- memorize grids */ - if (!(info & (CAVE_MARK))) + if (!(info & CAVE_MARK)) { /* Memorise some "boring" grids */ if (cave_plain_floor_grid(c_ptr)) { /* Option -- memorise certain floors */ - if ((info & (CAVE_TRDT)) || - ((info & (CAVE_GLOW)) && view_perma_grids ) || - view_torch_grids) + if (((info & CAVE_GLOW) && options->view_perma_grids) || + options->view_torch_grids) { /* Memorize */ - c_ptr->info |= (CAVE_MARK); + c_ptr->info |= CAVE_MARK; } } @@ -1802,7 +1744,7 @@ void note_spot(int y, int x) else { /* Memorize */ - c_ptr->info |= (CAVE_MARK); + c_ptr->info |= CAVE_MARK; } } } @@ -1839,17 +1781,17 @@ void lite_spot(int y, int x) * of both "lite_spot()" and "print_rel()", and that we use the * "lite_spot()" function to display the player grid, if needed. */ -void prt_map(void) +void prt_map() { int x, y; int v; /* Access the cursor state */ - (void)Term_get_cursor(&v); + Term_get_cursor(&v); /* Hide the cursor */ - (void)Term_set_cursor(0); + Term_set_cursor(0); /* Dump the map */ for (y = panel_row_min; y <= panel_row_max; y++) @@ -1872,7 +1814,7 @@ void prt_map(void) lite_spot(p_ptr->py, p_ptr->px); /* Restore the cursor */ - (void)Term_set_cursor(v); + Term_set_cursor(v); } @@ -1970,9 +1912,9 @@ static byte priority_table[][2] = */ static byte priority(byte a, char c) { - int i, p0, p1; + auto const &f_info = game->edit_data.f_info; - feature_type *f_ptr; + int i, p0, p1; /* Scan the table */ for (i = 0; TRUE; i++) @@ -1987,7 +1929,7 @@ static byte priority(byte a, char c) p0 = priority_table[i][0]; /* Access the feature */ - f_ptr = &f_info[p0]; + auto f_ptr = &f_info[p0]; /* Check character and attribute, accept matches */ if ((f_ptr->x_char == c) && (f_ptr->x_attr == a)) return (p1); @@ -2020,9 +1962,6 @@ void display_map(int *cy, int *cx) byte tp; - bool_ old_view_special_lite; - bool_ old_view_granite_lite; - int hgt, wid, yrat, xrat, yfactor, xfactor; @@ -2047,12 +1986,12 @@ void display_map(int *cy, int *cx) /* Save lighting effects */ - old_view_special_lite = view_special_lite; - old_view_granite_lite = view_granite_lite; + auto const old_view_special_lite = options->view_special_lite; + auto const old_view_granite_lite = options->view_granite_lite; /* Disable lighting effects */ - view_special_lite = FALSE; - view_granite_lite = FALSE; + options->view_special_lite = FALSE; + options->view_granite_lite = FALSE; /* Set up initial maps */ @@ -2149,8 +2088,8 @@ void display_map(int *cy, int *cx) *cx = p_ptr->px * xfactor / xrat + COL_MAP; /* Restore lighting effects */ - view_special_lite = old_view_special_lite; - view_granite_lite = old_view_granite_lite; + options->view_special_lite = old_view_special_lite; + options->view_granite_lite = old_view_granite_lite; } @@ -2159,7 +2098,7 @@ void display_map(int *cy, int *cx) * * Currently, the "player" is displayed on the map. XXX XXX XXX */ -void do_cmd_view_map(void) +void do_cmd_view_map() { int cy, cx; int wid, hgt; @@ -2822,7 +2761,7 @@ static void vinfo_init_aux(vinfo_hack *hack, int y, int x, long m) * a number which is too high, running this function, and using the * error messages to obtain the correct values. */ -errr vinfo_init(void) +errr vinfo_init() { int i, y, x; @@ -3044,7 +2983,7 @@ errr vinfo_init(void) /* * Forget the "CAVE_VIEW" grids, redrawing as needed */ -void forget_view(void) +void forget_view() { int i; @@ -3152,7 +3091,7 @@ void forget_view(void) * special grids. Because the actual number of required grids is bizarre, * we simply allocate twice as many as we would normally need. XXX XXX XXX */ -void update_view(void) +void update_view() { int i, o; int y, x; @@ -3471,7 +3410,7 @@ void update_view(void) /* * Clear monster light */ -void forget_mon_lite(void) +void forget_mon_lite() { int i, y, x; @@ -3519,7 +3458,7 @@ void forget_mon_lite(void) * This function works within the current player's field of view * calculated by update_view(), so it should normally be called * whenever FoV is updated (== PU_VIEW | PU_MON_LITE). The other - * case is when RF9_HAS_LITE monsters have moved or dead. Monster + * case is when RF_HAS_LITE monsters have moved or dead. Monster * creation occurs out of LoS, so I chose not to take this into * consideration. * @@ -3536,8 +3475,10 @@ void forget_mon_lite(void) * or brighter light, and it doesn't work well with PernAngband's already * colourful terrain features in aesthetically pleasing ways... -- pelpel */ -void update_mon_lite(void) +void update_mon_lite() { + auto const &f_info = game->edit_data.f_info; + int i, y, x, d; int fy, fx; @@ -3625,7 +3566,7 @@ void update_mon_lite(void) auto r_ptr = m_ptr->race(); /* Skip monsters not carrying light source */ - if (!(r_ptr->flags9 & RF9_HAS_LITE)) continue; + if (!(r_ptr->flags & RF_HAS_LITE)) continue; /* Access the location */ fy = m_ptr->fy; @@ -3676,7 +3617,7 @@ void update_mon_lite(void) * * We don't have four sides for a wall grid, so... */ - if (invis && (f_info[c_ptr->feat].flags1 & FF1_NO_VISION)) continue; + if (invis && (f_info[c_ptr->feat].flags & FF_NO_VISION)) continue; /* Give monster light to the location */ c_ptr->info |= (CAVE_MLIT | CAVE_SEEN); @@ -3850,12 +3791,12 @@ static void update_flow_aux(int y, int x, int n) * We do not need a priority queue because the cost from grid * to grid is always "one" and we process them in order. */ -void update_flow(void) +void update_flow() { int x, y, d; /* Hack -- disabled */ - if (!flow_by_sound) return; + if (!options->flow_by_sound) return; /* Paranoia -- make sure the array is empty */ if (temp_n) return; @@ -3918,31 +3859,14 @@ void update_flow(void) /* * Hack -- map the current panel (plus some) ala "magic mapping" */ -void map_area(void) +void map_area() { - int i, x, y, y1, y2, x1, x2; - - cave_type *c_ptr; - - - /* Pick an area to map */ - y1 = panel_row_min - randint(10); - y2 = panel_row_max + randint(10); - x1 = panel_col_min - randint(20); - x2 = panel_col_max + randint(20); - - /* Speed -- shrink to fit legal bounds */ - if (y1 < 1) y1 = 1; - if (y2 > cur_hgt - 2) y2 = cur_hgt - 2; - if (x1 < 1) x1 = 1; - if (x2 > cur_wid - 2) x2 = cur_wid - 2; - - /* Scan that area */ - for (y = y1; y <= y2; y++) + /* Scan the whole map */ + for (int y = 1; y < cur_hgt - 1; y++) { - for (x = x1; x <= x2; x++) + for (int x = 1; x < cur_wid - 1; x++) { - c_ptr = &cave[y][x]; + auto c_ptr = &cave[y][x]; /* All non-walls are "checked" */ if (!is_wall(c_ptr)) @@ -3955,7 +3879,7 @@ void map_area(void) } /* Memorize known walls */ - for (i = 0; i < 8; i++) + for (int i = 0; i < 8; i++) { c_ptr = &cave[y + ddy_ddd[i]][x + ddx_ddd[i]]; @@ -3995,7 +3919,7 @@ void map_area(void) * since this would prevent the use of "view_torch_grids" as a method to * keep track of what grids have been observed directly. */ -void wiz_lite(void) +void wiz_lite() { int i, y, x; @@ -4028,7 +3952,7 @@ void wiz_lite(void) monster_type *m_ptr = &m_list[c_ptr->m_idx]; auto const r_ptr = m_ptr->race(); - if (r_ptr->flags9 & RF9_MIMIC) + if (r_ptr->flags & RF_MIMIC) { object_type *o_ptr = &o_list[m_ptr->mimic_o_idx()]; o_ptr->marked = TRUE; @@ -4058,7 +3982,7 @@ void wiz_lite(void) } /* Normally, memorize floors (see above) */ - if (view_perma_grids && !view_torch_grids) + if (options->view_perma_grids && !options->view_torch_grids) { /* Memorize the grid */ c_ptr->info |= (CAVE_MARK); @@ -4078,7 +4002,7 @@ void wiz_lite(void) p_ptr->window |= (PW_OVERHEAD); } -void wiz_lite_extra(void) +void wiz_lite_extra() { int y, x; for (y = 0; y < cur_hgt; y++) @@ -4094,7 +4018,7 @@ void wiz_lite_extra(void) /* * Forget the dungeon map (ala "Thinking of Maud..."). */ -void wiz_dark(void) +void wiz_dark() { int i, y, x; @@ -4406,7 +4330,7 @@ void object_track(object_type *o_ptr) * * All disturbance cancels repeated commands, resting, and running. */ -void disturb(int stop_search) +void disturb() { /* Cancel auto-commands */ /* command_new = 0; */ @@ -4441,21 +4365,37 @@ void disturb(int stop_search) p_ptr->update |= (PU_TORCH); } - /* Cancel searching if requested */ - if (stop_search && p_ptr->searching) + /* Flush the input if requested */ + if (options->flush_disturb) { - /* Cancel */ - p_ptr->searching = FALSE; + flush(); + } +} - /* Recalculate bonuses */ - p_ptr->update |= (PU_BONUS); - /* Redraw the state */ - p_ptr->redraw |= (PR_FRAME); + +/* + * Disturb if option 'disturb_state' is set. + */ +void disturb_on_state() +{ + if (options->disturb_state) + { + disturb(); } +} - /* Flush the input if requested */ - if (flush_disturb) flush(); + + +/* + * Disturb if option 'disturb_other' is set. + */ +void disturb_on_other() +{ + if (options->disturb_other) + { + disturb(); + } } @@ -4467,7 +4407,7 @@ void disturb(int stop_search) static int random_quest_number() { if ((dun_level >= 1) && (dun_level < MAX_RANDOM_QUEST) && - (dungeon_flags1 & DF1_PRINCIPAL) && + (dungeon_flags & DF_PRINCIPAL) && (random_quests[dun_level].type) && (!random_quests[dun_level].done) && (!is_randhero(dun_level))) @@ -4550,7 +4490,9 @@ bool cave_floor_bold(int y, int x) */ bool cave_floor_grid(cave_type const *c) { - return (f_info[c->feat].flags1 & FF1_FLOOR) && (c->feat != FEAT_MON_TRAP); + auto const &f_info = game->edit_data.f_info; + + return bool(f_info[c->feat].flags & FF_FLOOR); } @@ -4569,9 +4511,11 @@ bool cave_plain_floor_bold(int y, int x) */ bool cave_plain_floor_grid(cave_type const *c) { + auto const &f_info = game->edit_data.f_info; + return - (f_info[c->feat].flags1 & FF1_FLOOR) && - !(f_info[c->feat].flags1 & FF1_REMEMBER); + (f_info[c->feat].flags & FF_FLOOR) && + !(f_info[c->feat].flags & FF_REMEMBER); } @@ -4595,7 +4539,9 @@ bool cave_sight_bold(int y, int x) bool cave_sight_grid(cave_type const *c) { - return !(f_info[c->feat].flags1 & FF1_NO_VISION); + auto const &f_info = game->edit_data.f_info; + + return !(f_info[c->feat].flags & FF_NO_VISION); } @@ -4609,11 +4555,12 @@ bool cave_sight_grid(cave_type const *c) */ bool cave_clean_bold(int y, int x) { + auto const &f_info = game->edit_data.f_info; + return - (f_info[cave[y][x].feat].flags1 & FF1_FLOOR) && - (cave[y][x].feat != FEAT_MON_TRAP) && + (f_info[cave[y][x].feat].flags & FF_FLOOR) && (cave[y][x].o_idxs.empty()) && - !(f_info[cave[y][x].feat].flags1 & FF1_PERMANENT); + !(f_info[cave[y][x].feat].flags & FF_PERMANENT); } /* @@ -4641,19 +4588,21 @@ bool cave_empty_bold(int y, int x) */ bool cave_naked_bold(int y, int x) { + auto const &f_info = game->edit_data.f_info; + return - (f_info[cave[y][x].feat].flags1 & FF1_FLOOR) && - (cave[y][x].feat != FEAT_MON_TRAP) && - !(f_info[cave[y][x].feat].flags1 & FF1_PERMANENT) && + (f_info[cave[y][x].feat].flags & FF_FLOOR) && + !(f_info[cave[y][x].feat].flags & FF_PERMANENT) && (cave[y][x].o_idxs.empty()) && (cave[y][x].m_idx == 0); } bool cave_naked_bold2(int y, int x) { + auto const &f_info = game->edit_data.f_info; + return - (f_info[cave[y][x].feat].flags1 & FF1_FLOOR) && - (cave[y][x].feat != FEAT_MON_TRAP) && + (f_info[cave[y][x].feat].flags & FF_FLOOR) && (cave[y][x].o_idxs.empty()) && (cave[y][x].m_idx == 0); } @@ -4669,7 +4618,9 @@ bool cave_perma_bold(int y, int x) bool cave_perma_grid(cave_type const *c) { - return f_info[c->feat].flags1 & FF1_PERMANENT; + auto const &f_info = game->edit_data.f_info; + + return bool(f_info[c->feat].flags & FF_PERMANENT); } /* diff --git a/src/cave.hpp b/src/cave.hpp index 64f67dba..ce1631a1 100644 --- a/src/cave.hpp +++ b/src/cave.hpp @@ -4,52 +4,54 @@ #include "cave_type_fwd.hpp" #include "object_type_fwd.hpp" -extern int distance(int y1, int x1, int y2, int x2); -extern bool_ los(int y1, int x1, int y2, int x2); -extern bool_ cave_valid_bold(int y, int x); -extern bool_ no_lite(void); -extern void map_info_default(int y, int x, byte *ap, char *cp); -extern void move_cursor_relative(int row, int col); -extern void print_rel(char c, byte a, int y, int x); -extern void note_spot(int y, int x); -extern void lite_spot(int y, int x); -extern void prt_map(void); -extern void display_map(int *cy, int *cx); -extern void do_cmd_view_map(void); -extern errr vinfo_init(void); -extern void forget_view(void); -extern void update_view(void); -extern void forget_mon_lite(void); -extern void update_mon_lite(void); -extern void update_flow(void); -extern void map_area(void); -extern void wiz_lite(void); -extern void wiz_lite_extra(void); -extern void wiz_dark(void); -extern void cave_set_feat(int y, int x, int feat); -extern void place_floor(int y, int x); -extern void place_floor_convert_glass(int y, int x); -extern void place_filler(int y, int x); -extern void mmove2(int *y, int *x, int y1, int x1, int y2, int x2); -extern bool_ projectable(int y1, int x1, int y2, int x2); -extern void scatter(int *yp, int *xp, int y, int x, int d); -extern void health_track(int m_idx); -extern void monster_race_track(int r_idx, int ego); -extern void object_track(object_type *o_ptr); -extern void disturb(int stop_search); -extern int is_quest(int level); -extern int new_effect(int type, int dam, int time, int cy, int cx, int rad, s32b flags); -extern bool cave_floor_bold(int y, int x); -extern bool cave_floor_grid(cave_type const *c); -extern bool cave_plain_floor_bold(int y, int x); -extern bool cave_plain_floor_grid(cave_type const *c); -extern bool cave_sight_bold(int y, int x); -extern bool cave_sight_grid(cave_type const *c); -extern bool cave_clean_bold(int y, int x); -extern bool cave_empty_bold(int y, int x); -extern bool cave_naked_bold(int y, int x); -extern bool cave_naked_bold2(int y, int x); -extern bool cave_perma_bold(int y, int x); -extern bool cave_perma_grid(cave_type const *c); -extern bool player_has_los_bold(int y, int x); -extern bool player_can_see_bold(int y, int x); +int distance(int y1, int x1, int y2, int x2); +bool_ los(int y1, int x1, int y2, int x2); +bool_ cave_valid_bold(int y, int x); +bool_ no_lite(); +void map_info_default(int y, int x, byte *ap, char *cp); +void move_cursor_relative(int row, int col); +void print_rel(char c, byte a, int y, int x); +void note_spot(int y, int x); +void lite_spot(int y, int x); +void prt_map(); +void display_map(int *cy, int *cx); +void do_cmd_view_map(); +errr vinfo_init(); +void forget_view(); +void update_view(); +void forget_mon_lite(); +void update_mon_lite(); +void update_flow(); +void map_area(); +void wiz_lite(); +void wiz_lite_extra(); +void wiz_dark(); +void cave_set_feat(int y, int x, int feat); +void place_floor(int y, int x); +void place_floor_convert_glass(int y, int x); +void place_filler(int y, int x); +void mmove2(int *y, int *x, int y1, int x1, int y2, int x2); +bool_ projectable(int y1, int x1, int y2, int x2); +void scatter(int *yp, int *xp, int y, int x, int d); +void health_track(int m_idx); +void monster_race_track(int r_idx, int ego); +void object_track(object_type *o_ptr); +void disturb(); +void disturb_on_state(); +void disturb_on_other(); +int is_quest(int level); +int new_effect(int type, int dam, int time, int cy, int cx, int rad, s32b flags); +bool cave_floor_bold(int y, int x); +bool cave_floor_grid(cave_type const *c); +bool cave_plain_floor_bold(int y, int x); +bool cave_plain_floor_grid(cave_type const *c); +bool cave_sight_bold(int y, int x); +bool cave_sight_grid(cave_type const *c); +bool cave_clean_bold(int y, int x); +bool cave_empty_bold(int y, int x); +bool cave_naked_bold(int y, int x); +bool cave_naked_bold2(int y, int x); +bool cave_perma_bold(int y, int x); +bool cave_perma_grid(cave_type const *c); +bool player_has_los_bold(int y, int x); +bool player_can_see_bold(int y, int x); diff --git a/src/cave_type.hpp b/src/cave_type.hpp index 958ace1d..08e6002f 100644 --- a/src/cave_type.hpp +++ b/src/cave_type.hpp @@ -38,8 +38,6 @@ struct cave_type s16b m_idx = 0; /* Monster in this grid */ - s16b t_idx = 0; /* trap index (in t_list) or zero */ - s16b special = 0; /* Special cave info */ s16b special2 = 0; /* Special cave info */ diff --git a/src/cmd1.cc b/src/cmd1.cc index f4066915..13edf0ff 100644 --- a/src/cmd1.cc +++ b/src/cmd1.cc @@ -13,8 +13,10 @@ #include "cmd4.hpp" #include "cmd5.hpp" #include "dungeon_info_type.hpp" +#include "feature_flag.hpp" #include "feature_type.hpp" #include "files.hpp" +#include "game.hpp" #include "gods.hpp" #include "hooks.hpp" #include "hook_move_in.hpp" @@ -25,19 +27,20 @@ #include "monster2.hpp" #include "monster3.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" +#include "monster_spell_flag.hpp" #include "monster_type.hpp" +#include "object_flag.hpp" #include "object1.hpp" #include "object2.hpp" #include "options.hpp" +#include "player_race_flag.hpp" #include "player_type.hpp" -#include "quark.hpp" #include "skills.hpp" #include "spells1.hpp" #include "spells2.hpp" #include "spells3.hpp" #include "tables.hpp" -#include "traps.hpp" -#include "trap_type.hpp" #include "util.hpp" #include "util.h" #include "variable.h" @@ -239,11 +242,8 @@ s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr, auto const r_ptr = m_ptr->race(); - u32b f1, f2, f3, f4, f5, esp; - - /* Extract the flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const f = object_flags(o_ptr); /* Some "weapons" and "ammo" do extra damage */ switch (o_ptr->tval) @@ -259,150 +259,84 @@ s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr, case TV_DIGGING: { /* Slay Animal */ - if ((f1 & (TR1_SLAY_ANIMAL)) && (r_ptr->flags3 & (RF3_ANIMAL))) + if ((f & TR_SLAY_ANIMAL) && (r_ptr->flags & RF_ANIMAL)) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_ANIMAL); - } - if (mult < 2) mult = 2; } /* Slay Evil */ - if ((f1 & (TR1_SLAY_EVIL)) && (r_ptr->flags3 & (RF3_EVIL))) + if ((f & TR_SLAY_EVIL) && (r_ptr->flags & RF_EVIL)) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_EVIL); - } - if (mult < 2) mult = 2; } /* Slay Undead */ - if ((f1 & (TR1_SLAY_UNDEAD)) && (r_ptr->flags3 & (RF3_UNDEAD))) + if ((f & TR_SLAY_UNDEAD) && (r_ptr->flags & RF_UNDEAD)) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_UNDEAD); - } - if (mult < 3) mult = 3; } /* Slay Demon */ - if ((f1 & (TR1_SLAY_DEMON)) && (r_ptr->flags3 & (RF3_DEMON))) + if ((f & TR_SLAY_DEMON) && (r_ptr->flags & RF_DEMON)) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_DEMON); - } - if (mult < 3) mult = 3; } /* Slay Orc */ - if ((f1 & (TR1_SLAY_ORC)) && (r_ptr->flags3 & (RF3_ORC))) + if ((f & TR_SLAY_ORC) && (r_ptr->flags & RF_ORC)) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_ORC); - } - if (mult < 3) mult = 3; } /* Slay Troll */ - if ((f1 & (TR1_SLAY_TROLL)) && (r_ptr->flags3 & (RF3_TROLL))) + if ((f & TR_SLAY_TROLL) && (r_ptr->flags & RF_TROLL)) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_TROLL); - } - if (mult < 3) mult = 3; } /* Slay Giant */ - if ((f1 & (TR1_SLAY_GIANT)) && (r_ptr->flags3 & (RF3_GIANT))) + if ((f & TR_SLAY_GIANT) && (r_ptr->flags & RF_GIANT)) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_GIANT); - } - if (mult < 3) mult = 3; } /* Slay Dragon */ - if ((f1 & (TR1_SLAY_DRAGON)) && (r_ptr->flags3 & (RF3_DRAGON))) + if ((f & TR_SLAY_DRAGON) && (r_ptr->flags & RF_DRAGON)) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_DRAGON); - } - if (mult < 3) mult = 3; } /* Execute Dragon */ - if ((f1 & (TR1_KILL_DRAGON)) && (r_ptr->flags3 & (RF3_DRAGON))) + if ((f & TR_KILL_DRAGON) && (r_ptr->flags & RF_DRAGON)) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_DRAGON); - } - if (mult < 5) mult = 5; } /* Execute Undead */ - if ((f5 & (TR5_KILL_UNDEAD)) && (r_ptr->flags3 & (RF3_UNDEAD))) + if ((f & TR_KILL_UNDEAD) && (r_ptr->flags & RF_UNDEAD)) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_UNDEAD); - } if (mult < 5) mult = 5; } /* Execute Demon */ - if ((f5 & (TR5_KILL_DEMON)) && (r_ptr->flags3 & (RF3_DEMON))) + if ((f & TR_KILL_DEMON) && (r_ptr->flags & RF_DEMON)) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_DEMON); - } - if (mult < 5) mult = 5; } /* Brand (Acid) */ - if (f1 & (TR1_BRAND_ACID)) + if (f & TR_BRAND_ACID) { - /* Notice immunity */ - if (r_ptr->flags3 & (RF3_IM_ACID)) + if (r_ptr->flags & RF_IM_ACID) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_IM_ACID); - } + // No additional multiplier } - - /* Notice susceptibility */ - else if (r_ptr->flags9 & (RF9_SUSCEP_ACID)) + else if (r_ptr->flags & RF_SUSCEP_ACID) { - if (m_ptr->ml) - { - r_ptr->r_flags9 |= (RF9_SUSCEP_ACID); - } if (mult < 6) mult = 6; } - - /* Otherwise, take the damage */ else { if (mult < 3) mult = 3; @@ -410,28 +344,16 @@ s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr, } /* Brand (Elec) */ - if (f1 & (TR1_BRAND_ELEC)) + if (f & TR_BRAND_ELEC) { - /* Notice immunity */ - if (r_ptr->flags3 & (RF3_IM_ELEC)) + if (r_ptr->flags & RF_IM_ELEC) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_IM_ELEC); - } + // No additional multiplier } - - /* Notice susceptibility */ - else if (r_ptr->flags9 & (RF9_SUSCEP_ELEC)) + else if (r_ptr->flags & RF_SUSCEP_ELEC) { - if (m_ptr->ml) - { - r_ptr->r_flags9 |= (RF9_SUSCEP_ELEC); - } if (mult < 6) mult = 6; } - - /* Otherwise, take the damage */ else { if (mult < 3) mult = 3; @@ -439,28 +361,16 @@ s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr, } /* Brand (Fire) */ - if (f1 & (TR1_BRAND_FIRE)) + if (f & TR_BRAND_FIRE) { - /* Notice immunity */ - if (r_ptr->flags3 & (RF3_IM_FIRE)) + if (r_ptr->flags & RF_IM_FIRE) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_IM_FIRE); - } + // No additional multiplier } - - /* Notice susceptibility */ - else if (r_ptr->flags3 & (RF3_SUSCEP_FIRE)) + else if (r_ptr->flags & RF_SUSCEP_FIRE) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_SUSCEP_FIRE); - } if (mult < 6) mult = 6; } - - /* Otherwise, take the damage */ else { if (mult < 3) mult = 3; @@ -468,28 +378,16 @@ s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr, } /* Brand (Cold) */ - if (f1 & (TR1_BRAND_COLD)) + if (f & TR_BRAND_COLD) { - /* Notice immunity */ - if (r_ptr->flags3 & (RF3_IM_COLD)) + if (r_ptr->flags & RF_IM_COLD) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_IM_COLD); - } + // No additional multiplier } - - /* Notice susceptibility */ - else if (r_ptr->flags3 & (RF3_SUSCEP_COLD)) + else if (r_ptr->flags & RF_SUSCEP_COLD) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_SUSCEP_COLD); - } if (mult < 6) mult = 6; } - - /* Otherwise, take the damage */ else { if (mult < 3) mult = 3; @@ -497,29 +395,17 @@ s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr, } /* Brand (Poison) */ - if (f1 & (TR1_BRAND_POIS) || (p_ptr->tim_poison)) + if ((f & TR_BRAND_POIS) || (p_ptr->tim_poison)) { - /* Notice immunity */ - if (r_ptr->flags3 & (RF3_IM_POIS)) + if (r_ptr->flags & RF_IM_POIS) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_IM_POIS); - } + // No additional damage } - - /* Notice susceptibility */ - else if (r_ptr->flags9 & (RF9_SUSCEP_POIS)) + else if (r_ptr->flags & RF_SUSCEP_POIS) { - if (m_ptr->ml) - { - r_ptr->r_flags9 |= (RF9_SUSCEP_POIS); - } if (mult < 6) mult = 6; if (magik(95)) *special |= SPEC_POIS; } - - /* Otherwise, take the damage */ else { if (mult < 3) mult = 3; @@ -528,18 +414,12 @@ s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr, } /* Wounding */ - if (f5 & (TR5_WOUNDING)) + if (f & TR_WOUNDING) { - /* Notice immunity */ - if (r_ptr->flags8 & (RF8_NO_CUT)) + if (r_ptr->flags & RF_NO_CUT) { - if (m_ptr->ml) - { - r_info[m_ptr->r_idx].r_flags8 |= (RF8_NO_CUT); - } + // No additional damage } - - /* Otherwise, take the damage */ else { if (magik(50)) *special |= SPEC_CUT; @@ -556,89 +436,6 @@ s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr, /* - * Search for hidden things - */ -void search(void) -{ - /* Start with base search ability */ - int chance = p_ptr->skill_srh; - - /* Penalize various conditions */ - if (p_ptr->blind || no_lite()) chance = chance / 10; - if (p_ptr->confused || p_ptr->image) chance = chance / 10; - - /* Search the nearby grids, which are always in bounds */ - for (int y = (p_ptr->py - 1); y <= (p_ptr->py + 1); y++) - { - for (int x = (p_ptr->px - 1); x <= (p_ptr->px + 1); x++) - { - /* Sometimes, notice things */ - if (rand_int(100) < chance) - { - /* Access the grid */ - cave_type *c_ptr = &cave[y][x]; - - /* Invisible trap */ - if ((c_ptr->t_idx != 0) && !(c_ptr->info & CAVE_TRDT)) - { - /* Pick a trap */ - pick_trap(y, x); - - /* Message */ - msg_print("You have found a trap."); - - /* Disturb */ - disturb(0); - } - - /* Secret door */ - if (c_ptr->feat == FEAT_SECRET) - { - /* Message */ - msg_print("You have found a secret door."); - - /* Pick a door XXX XXX XXX */ - cave_set_feat(y, x, FEAT_DOOR_HEAD + 0x00); - cave[y][x].mimic = 0; - lite_spot(y, x); - - /* Disturb */ - disturb(0); - } - - /* Scan all objects in the grid */ - for (auto const o_idx: c_ptr->o_idxs) - { - object_type * o_ptr = &o_list[o_idx]; - - /* Skip non-chests */ - if (o_ptr->tval != TV_CHEST) continue; - - /* Skip non-trapped chests */ - if (!o_ptr->pval) continue; - - /* Identify once */ - if (!object_known_p(o_ptr)) - { - /* Message */ - msg_print("You have discovered a trap on the chest!"); - - /* Know the trap */ - object_known(o_ptr); - - /* Notice it */ - disturb(0); - } - } - } - } - } -} - - - - -/* * Player "wants" to pick up an object or gold. * Note that we ONLY handle things that can be picked up. * See "move_player()" for handling of other things. @@ -652,39 +449,11 @@ void carry(int pickup) } -/* - * Handle player hitting a real trap - */ -static void hit_trap(void) -{ - bool_ ident = FALSE; - - cave_type *c_ptr; - - - /* Disturb the player */ - disturb(0); - - /* Get the cave grid */ - c_ptr = &cave[p_ptr->py][p_ptr->px]; - if (c_ptr->t_idx != 0) - { - ident = player_activate_trap_type(p_ptr->py, p_ptr->px, NULL, -1); - if (ident) - { - t_info[c_ptr->t_idx].ident = TRUE; - msg_format("You identified the trap as %s.", - t_info[c_ptr->t_idx].name); - } - } -} - - -void touch_zap_player(monster_type *m_ptr) +static void touch_zap_player(monster_type *m_ptr) { auto r_ptr = m_ptr->race(); - if (r_ptr->flags2 & (RF2_AURA_FIRE)) + if (r_ptr->flags & RF_AURA_FIRE) { if (!(p_ptr->immune_fire)) { @@ -703,13 +472,12 @@ void touch_zap_player(monster_type *m_ptr) if (p_ptr->sensible_fire) aura_damage = (aura_damage + 2) * 2; take_hit(aura_damage, aura_dam); - r_ptr->r_flags2 |= RF2_AURA_FIRE; handle_stuff(); } } - if (r_ptr->flags2 & (RF2_AURA_ELEC)) + if (r_ptr->flags & RF_AURA_ELEC) { if (!(p_ptr->immune_elec)) { @@ -726,7 +494,6 @@ void touch_zap_player(monster_type *m_ptr) msg_print("You get zapped!"); take_hit(aura_damage, aura_dam); - r_ptr->r_flags2 |= RF2_AURA_ELEC; handle_stuff(); } } @@ -740,9 +507,9 @@ void touch_zap_player(monster_type *m_ptr) static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, int x, int y) { - monster_type *t_ptr = &m_list[m_idx]; + auto const &r_info = game->edit_data.r_info; - monster_race *r_ptr; + monster_type *t_ptr = &m_list[m_idx]; int ap_cnt; @@ -750,8 +517,6 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, char t_name[80]; - cptr sym_name = symbiote_name(TRUE); - char temp[80]; bool_ blinked = FALSE, touched = FALSE; @@ -760,17 +525,15 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, byte x_saver = t_ptr->fx; - object_type *o_ptr; - - /* Get the carried monster */ - o_ptr = &p_ptr->inventory[INVEN_CARRY]; + auto o_ptr = &p_ptr->inventory[INVEN_CARRY]; if (!o_ptr->k_idx) return; - r_ptr = &r_info[o_ptr->pval]; + /* Get monster race of the symbiote */ + auto r_ptr = &r_info[o_ptr->pval]; /* Not allowed to attack */ - if (r_ptr->flags1 & RF1_NEVER_BLOW) return; + if (r_ptr->flags & RF_NEVER_BLOW) return; /* Total armor */ ac = t_ptr->ac; @@ -792,9 +555,6 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, /* Scan through all four blows */ for (ap_cnt = 0; ap_cnt < 4; ap_cnt++) { - bool_ visible = FALSE; - bool_ obvious = FALSE; - int power = 0; int damage = 0; @@ -818,9 +578,6 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, /* break; */ } - /* Extract visibility (before blink) */ - visible = TRUE; - /* Extract the attack "power" */ power = get_attack_power(effect); @@ -828,7 +585,7 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, if (!effect || check_hit2(power, rlev, ac)) { /* Always disturbing */ - disturb(1); + disturb(); /* Describe the attack method */ switch (method) @@ -1003,13 +760,12 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, { strnfmt(temp, sizeof(temp), act, t_name); if (t_ptr->ml) - msg_format("%s %s", sym_name, temp); + { + msg_format("%s %s", symbiote_name(true).c_str(), temp); + } } - /* Hack -- assume all attacks are obvious */ - obvious = TRUE; - /* Roll out the damage */ damage = damroll(d_dice, d_side); @@ -1166,15 +922,13 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, { auto tr_ptr = t_ptr->race(); /* Aura fire */ - if ((tr_ptr->flags2 & RF2_AURA_FIRE) && - !(r_ptr->flags3 & RF3_IM_FIRE)) + if ((tr_ptr->flags & RF_AURA_FIRE) && + !(r_ptr->flags & RF_IM_FIRE)) { if (t_ptr->ml) { blinked = FALSE; msg_format("You are suddenly very hot!"); - if (t_ptr->ml) - tr_ptr->r_flags2 |= RF2_AURA_FIRE; } project(m_idx, 0, p_ptr->py, p_ptr->px, damroll(1 + ((t_ptr->level) / 26), @@ -1183,15 +937,13 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, } /* Aura elec */ - if ((tr_ptr->flags2 & (RF2_AURA_ELEC)) && - !(r_ptr->flags3 & (RF3_IM_ELEC))) + if ((tr_ptr->flags & RF_AURA_ELEC) && + !(r_ptr->flags & RF_IM_ELEC)) { if (t_ptr->ml) { blinked = FALSE; msg_format("You get zapped!"); - if (t_ptr->ml) - tr_ptr->r_flags2 |= RF2_AURA_ELEC; } project(m_idx, 0, p_ptr->py, p_ptr->px, damroll(1 + ((t_ptr->level) / 26), @@ -1222,35 +974,20 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, case RBM_CHARGE: { /* Disturb */ - disturb(1); + disturb(); /* Message */ - msg_format("%s misses %s.", sym_name, t_name); + msg_format("%s misses %s.", symbiote_name(true).c_str(), t_name); break; } } } - - - /* Analyze "visible" monsters only */ - if (visible) - { - /* Count "obvious" attacks (and ones that cause damage) */ - if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10)) - { - /* Count attacks of this type */ - if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR) - { - r_ptr->r_blows[ap_cnt]++; - } - } - } } /* Blink away */ if (blinked) { - msg_format("You and %s flee laughing!", symbiote_name(FALSE)); + msg_format("You and %s flee laughing!", symbiote_name(false).c_str()); teleport_player(MAX_SIGHT * 2 + 5); } @@ -1263,6 +1000,8 @@ static void carried_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, int x, int y) { + auto const &r_info = game->edit_data.r_info; + monster_type *t_ptr = &m_list[m_idx]; auto tr_ptr = t_ptr->race(); @@ -1287,7 +1026,7 @@ static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, auto r_ptr = &r_info[p_ptr->body_monster]; /* Not allowed to attack */ - if (r_ptr->flags1 & RF1_NEVER_BLOW) return; + if (r_ptr->flags & RF_NEVER_BLOW) return; /* Total armor */ ac = t_ptr->ac; @@ -1310,9 +1049,6 @@ static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, for (ap_cnt = 0; ap_cnt < (p_ptr->num_blow > 4) ? 4 : p_ptr->num_blow; ap_cnt++) { - bool_ visible = FALSE; - bool_ obvious = FALSE; - int power = 0; int damage = 0; @@ -1336,9 +1072,6 @@ static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, /* break; */ } - /* Extract visibility (before blink) */ - visible = TRUE; - /* Extract the attack "power" */ power = get_attack_power(effect); @@ -1346,7 +1079,7 @@ static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, if (!effect || check_hit2(power, rlev, ac)) { /* Always disturbing */ - disturb(1); + disturb(); /* Describe the attack method */ switch (method) @@ -1525,9 +1258,6 @@ static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, } - /* Hack -- assume all attacks are obvious */ - obvious = TRUE; - /* Roll out the damage */ damage = damroll(d_dice, d_side) + p_ptr->to_d; @@ -1682,15 +1412,13 @@ static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, if (touched) { /* Aura fire */ - if ((tr_ptr->flags2 & RF2_AURA_FIRE) && - !(r_ptr->flags3 & RF3_IM_FIRE)) + if ((tr_ptr->flags & RF_AURA_FIRE) && + !(r_ptr->flags & RF_IM_FIRE)) { if (t_ptr->ml) { blinked = FALSE; msg_format("You are suddenly very hot!"); - if (t_ptr->ml) - tr_ptr->r_flags2 |= RF2_AURA_FIRE; } project(m_idx, 0, p_ptr->py, p_ptr->px, damroll(1 + ((t_ptr->level) / 26), @@ -1699,15 +1427,13 @@ static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, } /* Aura elec */ - if ((tr_ptr->flags2 & (RF2_AURA_ELEC)) && - !(r_ptr->flags3 & (RF3_IM_ELEC))) + if ((tr_ptr->flags & RF_AURA_ELEC) && + !(r_ptr->flags & RF_IM_ELEC)) { if (t_ptr->ml) { blinked = FALSE; msg_format("You get zapped!"); - if (t_ptr->ml) - tr_ptr->r_flags2 |= RF2_AURA_ELEC; } project(m_idx, 0, p_ptr->py, p_ptr->px, damroll(1 + ((t_ptr->level) / 26), @@ -1739,7 +1465,7 @@ static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, case RBM_CHARGE: { /* Disturb */ - disturb(1); + disturb(); /* Message */ msg_format("You miss %s.", t_name); @@ -1748,21 +1474,6 @@ static void incarnate_monster_attack(s16b m_idx, bool_ *fear, bool_ *mdeath, } } } - - - /* Analyze "visible" monsters only */ - if (visible) - { - /* Count "obvious" attacks (and ones that cause damage) */ - if (obvious || damage || (r_ptr->r_blows[ap_cnt] > 10)) - { - /* Count attacks of this type */ - if (r_ptr->r_blows[ap_cnt] < MAX_UCHAR) - { - r_ptr->r_blows[ap_cnt]++; - } - } - } } /* Blink away */ @@ -1838,22 +1549,20 @@ void attack_special(monster_type *m_ptr, s32b special, int dam) /* Special - Cut monster */ if (special & SPEC_CUT) { - /* Cut the monster */ - if (r_ptr->flags8 & (RF8_NO_CUT)) + if (r_ptr->flags & RF_NO_CUT) { - if (m_ptr->ml) - { - r_info[m_ptr->r_idx].r_flags8 |= (RF8_NO_CUT); - } + // No damage } else if (rand_int(100) >= r_ptr->level) { - /* Already partially poisoned */ - if (m_ptr->bleeding) msg_format("%^s is bleeding more strongly.", - m_name); - /* Was not poisoned */ + if (m_ptr->bleeding) + { + msg_format("%^s is bleeding more strongly.", m_name); + } else + { msg_format("%^s is bleeding.", m_name); + } m_ptr->bleeding += dam * 2; } @@ -1862,36 +1571,33 @@ void attack_special(monster_type *m_ptr, s32b special, int dam) /* Special - Poison monster */ if (special & SPEC_POIS) { - /* Poison the monster */ - if (r_ptr->flags3 & (RF3_IM_POIS)) + if (r_ptr->flags & RF_IM_POIS) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_IM_POIS); - } + // No damage } - /* Notice susceptibility */ - else if (r_ptr->flags9 & (RF9_SUSCEP_POIS)) + else if (r_ptr->flags & RF_SUSCEP_POIS) { - if (m_ptr->ml) + if (m_ptr->poisoned) { - r_ptr->r_flags9 |= (RF9_SUSCEP_POIS); + msg_format("%^s is more poisoned.", m_name); } - /* Already partially poisoned */ - if (m_ptr->poisoned) msg_format("%^s is more poisoned.", m_name); - /* Was not poisoned */ else + { msg_format("%^s is poisoned.", m_name); + } m_ptr->poisoned += dam * 2; } else if (rand_int(100) >= r_ptr->level) { - /* Already partially poisoned */ - if (m_ptr->poisoned) msg_format("%^s is more poisoned.", m_name); - /* Was not poisoned */ + if (m_ptr->poisoned) + { + msg_format("%^s is more poisoned.", m_name); + } else + { msg_format("%^s is poisoned.", m_name); + } m_ptr->poisoned += dam; } @@ -1929,11 +1635,11 @@ static void py_attack_hand(int *k, monster_type *m_ptr, s32b *special) /* Extract monster name (or "it") */ auto const r_ptr = m_ptr->race(); - if (r_ptr->flags1 & RF1_UNIQUE) resist_stun += 88; - if (r_ptr->flags3 & RF3_NO_CONF) resist_stun += 44; - if (r_ptr->flags3 & RF3_NO_SLEEP) resist_stun += 44; - if ((r_ptr->flags3 & RF3_UNDEAD) || - (r_ptr->flags3 & RF3_NONLIVING)) resist_stun += 88; + if (r_ptr->flags & RF_UNIQUE) resist_stun += 88; + if (r_ptr->flags & RF_NO_CONF) resist_stun += 44; + if (r_ptr->flags & RF_NO_SLEEP) resist_stun += 44; + if ((r_ptr->flags & RF_UNDEAD) || + (r_ptr->flags & RF_NONLIVING)) resist_stun += 88; if (plev) { @@ -1951,7 +1657,7 @@ static void py_attack_hand(int *k, monster_type *m_ptr, s32b *special) { old_ptr = ma_ptr; - if (wizard && cheat_xtra) + if (wizard && options->cheat_xtra) { msg_print("Attack re-selected."); } @@ -1972,11 +1678,10 @@ static void py_attack_hand(int *k, monster_type *m_ptr, s32b *special) /* Describe attack */ if (ma_ptr->effect & MA_KNEE) { - if (r_ptr->flags1 & RF1_MALE) + if (r_ptr->flags & RF_MALE) { if (!desc) msg_format("You hit %s in the groin with your knee!", m_name); - sound(SOUND_PAIN); special_effect = MA_KNEE; } else if (!desc) msg_format(ma_ptr->desc, m_name); @@ -1993,7 +1698,7 @@ static void py_attack_hand(int *k, monster_type *m_ptr, s32b *special) if (ma_ptr->effect & MA_SLOW) { if (! - ((r_ptr->flags1 & RF1_NEVER_MOVE) || + ((r_ptr->flags & RF_NEVER_MOVE) || strchr("UjmeEv$,DdsbBFIJQSXclnw!=?", r_ptr->d_char))) { if (!desc) msg_format("You kick %s in the ankle.", m_name); @@ -2035,10 +1740,10 @@ static void py_attack_hand(int *k, monster_type *m_ptr, s32b *special) if (((special_effect & MA_FULL_SLOW) || (special_effect & MA_SLOW)) && ((*k + p_ptr->to_d) < m_ptr->hp)) { - if (!(r_ptr->flags1 & RF1_UNIQUE) && + if (!(r_ptr->flags & RF_UNIQUE) && (randint(plev) > m_ptr->level) && m_ptr->mspeed > 60) { - msg_format("%^s starts limping slower.", m_name); + msg_format("%^s starts limping.", m_name); m_ptr->mspeed -= 10; } } @@ -2064,24 +1769,25 @@ static void py_attack_hand(int *k, monster_type *m_ptr, s32b *special) static void do_nazgul(int *k, int *num, int num_blow, int weap, std::shared_ptr<monster_race> r_ptr, object_type *o_ptr) { - u32b f1, f2, f3, f4, f5, esp; - - bool_ mundane; bool_ allow_shatter = TRUE; /* Extract mundane-ness of the current weapon */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const f = object_flags(o_ptr); /* It should be Slay Evil, Slay Undead, or *Slay Undead* */ - mundane = !(f1 & TR1_SLAY_EVIL) && !(f1 & TR1_SLAY_UNDEAD) && - !(f5 & TR5_KILL_UNDEAD); + bool_ const mundane = + !(f & TR_SLAY_EVIL) && + !(f & TR_SLAY_UNDEAD) && + !(f & TR_KILL_UNDEAD); /* Some blades can resist shattering */ - if (f5 & TR5_RES_MORGUL) + if (f & TR_RES_MORGUL) + { allow_shatter = FALSE; + } /* Mega Hack -- Hitting Nazgul is REALY dangerous (ideas from Akhronath) */ - if (r_ptr->flags7 & RF7_NAZGUL) + if (r_ptr->flags & RF_NAZGUL) { if ((!o_ptr->name2) && (!artifact_p(o_ptr)) && allow_shatter) { @@ -2158,6 +1864,8 @@ static void do_nazgul(int *k, int *num, int num_blow, int weap, std::shared_ptr< */ void py_attack(int y, int x, int max_blow) { + auto const &r_info = game->edit_data.r_info; + int num = 0, k, bonus, chance; s32b special = 0; @@ -2188,15 +1896,12 @@ void py_attack(int y, int x, int max_blow) int drain_left = MAX_VAMPIRIC_DRAIN; - /* A massive hack -- life-draining weapons */ - u32b f1, f2, f3, f4, f5, esp; - int weap; /* Disturb the player */ - disturb(0); + disturb(); - if (r_info[p_ptr->body_monster].flags1 & RF1_NEVER_BLOW) + if (r_info[p_ptr->body_monster].flags & RF_NEVER_BLOW) { msg_print("You cannot attack in this form!"); return; @@ -2234,21 +1939,16 @@ void py_attack(int y, int x, int max_blow) !(p_ptr->stun || p_ptr->confused || p_ptr->image || !(m_ptr->ml))) { - if (!(p_ptr->inventory[INVEN_WIELD].art_name)) + // Only 'Stormbringer' can hit friendlies unless player forces attack. + if (p_ptr->inventory[INVEN_WIELD].artifact_name == "'Stormbringer'") { - msg_format("You stop to avoid hitting %s.", m_name); - return; + msg_format("Your black blade greedily attacks %s!", m_name); } - - if (! - (streq - (quark_str(p_ptr->inventory[INVEN_WIELD].art_name), "'Stormbringer'"))) + else { msg_format("You stop to avoid hitting %s.", m_name); return; } - - msg_format("Your black blade greedily attacks %s!", m_name); } /* Break goi/manashield */ @@ -2309,9 +2009,9 @@ void py_attack(int y, int x, int max_blow) bonus = p_ptr->to_h + p_ptr->to_h_melee + o_ptr->to_h; chance = p_ptr->skill_thn + (bonus * BTH_PLUS_ADJ); - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); - if (!(f4 & TR4_NEVER_BLOW)) + if (!(flags & TR_NEVER_BLOW)) { int num_blow = p_ptr->num_blow; @@ -2325,14 +2025,11 @@ void py_attack(int y, int x, int max_blow) /* Test for hit */ if (test_hit_norm(chance, m_ptr->ac, m_ptr->ml)) { - /* Sound */ - sound(SOUND_HIT); - /* Hack -- bare hands do one damage */ k = 1; /* Select a chaotic effect (50% chance) */ - if ((f1 & TR1_CHAOTIC) && (rand_int(2) == 0)) + if ((flags & TR_CHAOTIC) && (rand_int(2) == 0)) { if (randint(5) < 3) { @@ -2362,17 +2059,17 @@ void py_attack(int y, int x, int max_blow) } /* Vampiric drain */ - if ((f1 & TR1_VAMPIRIC) || (chaos_effect == 1)) + if ((flags & TR_VAMPIRIC) || (chaos_effect == 1)) { if (! - ((r_ptr->flags3 & RF3_UNDEAD) || - (r_ptr->flags3 & RF3_NONLIVING))) + ((r_ptr->flags & RF_UNDEAD) || + (r_ptr->flags & RF_NONLIVING))) drain_result = m_ptr->hp; else drain_result = 0; } - if (f1 & TR1_VORPAL && (randint(6) == 1)) + if ((flags & TR_VORPAL) && (randint(6) == 1)) vorpal_cut = TRUE; else vorpal_cut = FALSE; @@ -2411,7 +2108,7 @@ void py_attack(int y, int x, int max_blow) /* Stunning blow */ if (magik(get_skill(SKILL_STUN)) && (o_ptr->tval == TV_HAFTED) && (o_ptr->weight > 50) && done_crit) { - if (!(r_ptr->flags4 & (RF4_BR_SOUN)) && !(r_ptr->flags4 & (RF4_BR_WALL)) && k) + if (!(r_ptr->spells & SF_BR_SOUN) && !(r_ptr->spells & SF_BR_WALL) && k) { int tmp; @@ -2474,7 +2171,7 @@ void py_attack(int y, int x, int max_blow) /* Melkor can cast curse for you*/ if (praying_to(GOD_MELKOR)) { - int lv = get_level(MELKOR_CURSE, 100, 1); + int lv = get_level_s(MELKOR_CURSE, 100); if (lv >= 10) { @@ -2489,7 +2186,7 @@ void py_attack(int y, int x, int max_blow) } /* May it clone the monster ? */ - if ((f4 & TR4_CLONE) && magik(30)) + if ((flags & TR_CLONE) && magik(30)) { msg_format("Oh no! Your weapon clones %^s!", m_name); @@ -2556,7 +2253,7 @@ void py_attack(int y, int x, int max_blow) /* Hack -- High-level warriors can spread their attacks out * among weaker foes. */ - if ((has_ability(AB_SPREAD_BLOWS)) && (num < num_blow) && + if ((p_ptr->has_ability(AB_SPREAD_BLOWS)) && (num < num_blow) && (energy_use)) { energy_use = energy_use * num / num_blow; @@ -2590,7 +2287,7 @@ void py_attack(int y, int x, int max_blow) { drain_heal = damroll(4, (drain_result / 6)); - if (cheat_xtra) + if (options->cheat_xtra) { msg_format("Draining left: %d", drain_left); } @@ -2632,13 +2329,8 @@ void py_attack(int y, int x, int max_blow) } /* Confuse the monster */ - if (r_ptr->flags3 & (RF3_NO_CONF)) + if (r_ptr->flags & RF_NO_CONF) { - if (m_ptr->ml) - { - r_ptr->r_flags3 |= (RF3_NO_CONF); - } - msg_format("%^s is unaffected.", m_name); } else if (rand_int(100) < m_ptr->level) @@ -2663,8 +2355,8 @@ void py_attack(int y, int x, int max_blow) else if ((chaos_effect == 5) && cave_floor_bold(y, x) && (randint(90) > m_ptr->level)) { - if (!((r_ptr->flags1 & RF1_UNIQUE) || - (r_ptr->flags4 & RF4_BR_CHAO) || + if (!((r_ptr->flags & RF_UNIQUE) || + (r_ptr->spells & SF_BR_CHAO) || (m_ptr->mflag & MFLAG_QUEST))) { /* Handle polymorph */ @@ -2699,9 +2391,6 @@ void py_attack(int y, int x, int max_blow) /* Player misses */ else { - /* Sound */ - sound(SOUND_MISS); - backstab = FALSE; /* Clumsy! */ /* Message */ @@ -2723,9 +2412,6 @@ void py_attack(int y, int x, int max_blow) /* Hack -- delay fear messages */ if (fear && m_ptr->ml) { - /* Sound */ - sound(SOUND_FLEE); - /* Message */ msg_format("%^s flees in terror!", m_name); } @@ -2743,13 +2429,16 @@ void py_attack(int y, int x, int max_blow) bool_ player_can_enter(byte feature) { + auto const &r_info = game->edit_data.r_info; + auto const &f_info = game->edit_data.f_info; + bool_ pass_wall; bool_ only_wall = FALSE; /* Player can not walk through "walls" unless in Shadow Form */ - if (p_ptr->wraith_form || (race_flags1_p(PR1_SEMI_WRAITH))) + if (p_ptr->wraith_form || (race_flags_p(PR_SEMI_WRAITH))) pass_wall = TRUE; else pass_wall = FALSE; @@ -2785,30 +2474,30 @@ bool_ player_can_enter(byte feature) { if (p_ptr->fly || pass_wall || - (has_ability(AB_TREE_WALK)) || + p_ptr->has_ability(AB_TREE_WALK) || (p_ptr->mimic_form == resolve_mimic_name("Ent")) || ((p_ptr->grace >= 9000) && praying_to(GOD_YAVANNA))) return (TRUE); } - if ((p_ptr->climb) && (f_info[feature].flags1 & FF1_CAN_CLIMB)) + if ((p_ptr->climb) && (f_info[feature].flags & FF_CAN_CLIMB)) return (TRUE); if ((p_ptr->fly) && - ((f_info[feature].flags1 & FF1_CAN_FLY) || - (f_info[feature].flags1 & FF1_CAN_LEVITATE))) + ((f_info[feature].flags & FF_CAN_FLY) || + (f_info[feature].flags & FF_CAN_LEVITATE))) return (TRUE); - else if (only_wall && (f_info[feature].flags1 & FF1_FLOOR)) + else if (only_wall && (f_info[feature].flags & FF_FLOOR)) return (FALSE); else if ((p_ptr->ffall) && - (f_info[feature].flags1 & FF1_CAN_LEVITATE)) + (f_info[feature].flags & FF_CAN_LEVITATE)) return (TRUE); else if ((pass_wall || only_wall) && - (f_info[feature].flags1 & FF1_CAN_PASS)) + (f_info[feature].flags & FF_CAN_PASS)) return (TRUE); - else if (f_info[feature].flags1 & FF1_NO_WALK) + else if (f_info[feature].flags & FF_NO_WALK) return (FALSE); - else if ((f_info[feature].flags1 & FF1_WEB) && - ((!(r_info[p_ptr->body_monster].flags7 & RF7_SPIDER)) && (p_ptr->mimic_form != resolve_mimic_name("Spider")))) + else if ((f_info[feature].flags & FF_WEB) && + ((!(r_info[p_ptr->body_monster].flags & RF_SPIDER)) && (p_ptr->mimic_form != resolve_mimic_name("Spider")))) return (FALSE); return (TRUE); @@ -2827,14 +2516,16 @@ bool_ player_can_enter(byte feature) static bool_ easy_open_door(int y, int x) { + auto const &r_info = game->edit_data.r_info; + int i, j; cave_type *c_ptr = &cave[y][x]; - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; - if ((p_ptr->body_monster != 0) && !(r_ptr->flags2 & RF2_OPEN_DOOR)) + if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_OPEN_DOOR)) { msg_print("You cannot open doors."); @@ -2859,7 +2550,7 @@ static bool_ easy_open_door(int y, int x) else if (c_ptr->feat >= FEAT_DOOR_HEAD + 0x01) { /* Disarm factor */ - i = p_ptr->skill_dis; + i = 100; /* Penalize some conditions */ if (p_ptr->blind || no_lite()) i = i / 10; @@ -2880,18 +2571,12 @@ static bool_ easy_open_door(int y, int x) /* Message */ msg_print("You have picked the lock."); - /* Set off trap */ - if (c_ptr->t_idx != 0) player_activate_door_trap(y, x); - /* Open the door */ cave_set_feat(y, x, FEAT_OPEN); /* Update some things */ p_ptr->update |= (PU_VIEW | PU_MONSTERS | PU_MON_LITE); - /* Sound */ - sound(SOUND_OPENDOOR); - /* Experience */ gain_exp(1); } @@ -2900,7 +2585,7 @@ static bool_ easy_open_door(int y, int x) else { /* Failure */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_print("You failed to pick the lock."); @@ -2910,17 +2595,11 @@ static bool_ easy_open_door(int y, int x) /* Closed door */ else { - /* Set off trap */ - if (c_ptr->t_idx != 0) player_activate_door_trap(y, x); - /* Open the door */ cave_set_feat(y, x, FEAT_OPEN); /* Update some things */ p_ptr->update |= (PU_VIEW | PU_MONSTERS | PU_MON_LITE); - - /* Sound */ - sound(SOUND_OPENDOOR); } /* Result */ @@ -2936,43 +2615,43 @@ static bool_ easy_open_door(int y, int x) * any monster which might be in the destination grid. Previously, * moving into walls was "free" and did NOT hit invisible monsters. */ -void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) +void move_player_aux(int dir, int do_pickup, int run) { + auto const &d_info = game->edit_data.d_info; + auto const &r_info = game->edit_data.r_info; + auto const &f_info = game->edit_data.f_info; + int y, x, tmp; cave_type *c_ptr = &cave[p_ptr->py][p_ptr->px]; monster_type *m_ptr; - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; char m_name[80]; - bool_ stormbringer = FALSE; - - bool_ old_dtrap, new_dtrap; - bool_ oktomove = TRUE; /* Hack - random movement */ if (p_ptr->disembodied) tmp = dir; - else if ((r_ptr->flags1 & RF1_RAND_25) && (r_ptr->flags1 & RF1_RAND_50)) + else if ((r_ptr->flags & RF_RAND_25) && (r_ptr->flags & RF_RAND_50)) { if (randint(100) < 75) tmp = randint(9); else tmp = dir; } - else if (r_ptr->flags1 & RF1_RAND_50) + else if (r_ptr->flags & RF_RAND_50) { if (randint(100) < 50) tmp = randint(9); else tmp = dir; } - else if (r_ptr->flags1 & RF1_RAND_25) + else if (r_ptr->flags & RF_RAND_25) { if (randint(100) < 25) tmp = randint(9); @@ -3118,12 +2797,6 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) m_ptr = &m_list[c_ptr->m_idx]; auto const mr_ptr = m_ptr->race(); - if (p_ptr->inventory[INVEN_WIELD].art_name) - { - if (streq(quark_str(p_ptr->inventory[INVEN_WIELD].art_name), "'Stormbringer'")) - stormbringer = TRUE; - } - /* Hack -- attack monsters */ if (c_ptr->m_idx && (m_ptr->ml || player_can_enter(c_ptr->feat))) { @@ -3144,13 +2817,16 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) /* Track a new monster */ if (m_ptr->ml) health_track(c_ptr->m_idx); + /* Is it Stormbringer? */ + bool stormbringer = p_ptr->inventory[INVEN_WIELD].artifact_name == "'Stormbringer'"; + /* displace? */ if (stormbringer && (randint(1000) > 666)) { py_attack(y, x, -1); } else if (cave_floor_bold(p_ptr->py, p_ptr->px) || - (mr_ptr->flags2 & RF2_PASS_WALL)) + (mr_ptr->flags & RF_PASS_WALL)) { msg_format("You push past %s.", m_name); m_ptr->fy = p_ptr->py; @@ -3182,21 +2858,13 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) oktomove = FALSE; } - /* Don't step on known traps. */ - else if (disarm && (c_ptr->info & (CAVE_TRDT)) && !(p_ptr->confused || p_ptr->stun || p_ptr->image)) - { - msg_print("You stop to avoid triggering the trap."); - energy_use = 0; - oktomove = FALSE; - } - /* Player can't enter ? soo bad for him/her ... */ else if (!player_can_enter(c_ptr->feat)) { oktomove = FALSE; /* Disturb the player */ - disturb(0); + disturb(); if (p_ptr->prob_travel) { @@ -3225,11 +2893,10 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) /* Wall (or secret door) */ else { - int feat; - - if (c_ptr->mimic) feat = c_ptr->mimic; - else - feat = f_info[c_ptr->feat].mimic; + int const feat = c_ptr->mimic + ? c_ptr->mimic + : f_info[c_ptr->feat].mimic + ; msg_format("You feel %s.", f_info[feat].block); c_ptr->info |= (CAVE_MARK); @@ -3274,40 +2941,6 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) energy_use = 0; } } - - /* Sound */ - sound(SOUND_HITWALL); - } - - /* - * Check trap detection status -- retrieve them here - * because they are used by the movement code as well - */ - old_dtrap = ((cave[p_ptr->py][p_ptr->px].info & CAVE_DETECT) != 0); - new_dtrap = ((cave[y][x].info & CAVE_DETECT) != 0); - - /* Normal movement */ - if (oktomove && running && disturb_detect) - { - /* - * Disturb the player when about to leave the trap detected - * area - */ - if (old_dtrap && !new_dtrap) - { - /* Disturb player */ - disturb(0); - - /* but don't take a turn */ - energy_use = 0; - - /* Tell player why */ - cmsg_print(TERM_VIOLET, "You are about to leave a trap detected zone."); - /* Flush */ - /* msg_print(NULL); */ - - oktomove = FALSE; - } } /* Normal movement */ @@ -3343,20 +2976,6 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) /* Check for new panel (redraw map) */ verify_panel(); - /* Check detection status */ - if (old_dtrap && !new_dtrap) - { - cmsg_print(TERM_VIOLET, "You leave a trap detected zone."); - if (running) msg_print(NULL); - p_ptr->redraw |= (PR_FRAME); - } - else if (!old_dtrap && new_dtrap) - { - cmsg_print(TERM_L_BLUE, "You enter a trap detected zone."); - if (running) msg_print(NULL); - p_ptr->redraw |= (PR_FRAME); - } - /* Update stuff */ p_ptr->update |= (PU_VIEW | PU_FLOW | PU_MON_LITE); @@ -3372,7 +2991,7 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) /* Mega-hack for dungeon branches */ if ((feat == FEAT_MORE) && c_ptr->special) { - msg_format("There is %s", d_info[c_ptr->special].text); + msg_format("There is %s", d_info[c_ptr->special].text.c_str()); } else { @@ -3383,18 +3002,6 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) if (running) msg_print(NULL); } - /* Spontaneous Searching */ - if ((p_ptr->skill_fos >= 50) || (0 == rand_int(50 - p_ptr->skill_fos))) - { - search(); - } - - /* Continuous Searching */ - if (p_ptr->searching) - { - search(); - } - /* Handle "objects" */ carry(do_pickup); @@ -3402,7 +3009,7 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) if (c_ptr->feat == FEAT_SHOP) { /* Disturb */ - disturb(0); + disturb(); /* Hack -- Enter store */ command_new = '_'; @@ -3420,31 +3027,11 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) if (running) msg_print(NULL); } - /* Discover invisible traps */ - else if ((c_ptr->t_idx != 0) && - !(f_info[cave[y][x].feat].flags1 & FF1_DOOR)) - { - /* Disturb */ - disturb(0); - - if (!(c_ptr->info & (CAVE_TRDT))) - { - /* Message */ - msg_print("You found a trap!"); - - /* Pick a trap */ - pick_trap(p_ptr->py, p_ptr->px); - } - - /* Hit the trap */ - hit_trap(); - } - /* Execute the inscription */ else if (c_ptr->inscription) { /* Disturb */ - disturb(0); + disturb(); msg_format("There is an inscription here: %s", inscription_info[c_ptr->inscription].text); @@ -3468,9 +3055,9 @@ void move_player_aux(int dir, int do_pickup, int run, bool_ disarm) } } -void move_player(int dir, int do_pickup, bool_ disarm) +void move_player(int dir, int do_pickup) { - move_player_aux(dir, do_pickup, 0, disarm); + move_player_aux(dir, do_pickup, 0); } @@ -3479,13 +3066,7 @@ void move_player(int dir, int do_pickup, bool_ disarm) */ static int see_obstacle_grid(cave_type *c_ptr) { - /* - * Hack -- Avoid hitting detected traps, because we cannot rely on - * the CAVE_MARK check below, and traps can be set to nearly - * everything the player can move on to XXX XXX XXX - */ - if (c_ptr->info & (CAVE_TRDT)) return (TRUE); - + auto const &f_info = game->edit_data.f_info; /* Hack -- Handle special cases XXX XXX */ switch (c_ptr->feat) @@ -3508,7 +3089,7 @@ static int see_obstacle_grid(cave_type *c_ptr) /* "Safe" floor grids aren't obstacles */ - if (f_info[c_ptr->feat].flags1 & FF1_CAN_RUN) return (FALSE); + if (f_info[c_ptr->feat].flags & FF_CAN_RUN) return (FALSE); /* Must be known to the player */ if (!(c_ptr->info & (CAVE_MARK))) return (FALSE); @@ -3836,8 +3417,10 @@ static void run_init(int dir) * * Return TRUE if the running should be stopped */ -static bool_ run_test(void) +static bool_ run_test() { + auto const &f_info = game->edit_data.f_info; + int prev_dir, new_dir, check_dir = 0; int row, col; @@ -3927,7 +3510,7 @@ static bool_ run_test(void) case FEAT_BROKEN: { /* Option -- ignore */ - if (find_ignore_doors) notice = FALSE; + if (options->find_ignore_doors) notice = FALSE; /* Done */ break; @@ -3953,7 +3536,7 @@ static bool_ run_test(void) case FEAT_BETWEEN2: { /* Option -- ignore */ - if (find_ignore_stairs) notice = FALSE; + if (options->find_ignore_stairs) notice = FALSE; /* Done */ break; @@ -3961,14 +3544,11 @@ static bool_ run_test(void) } /* Check the "don't notice running" flag */ - if (f_info[c_ptr->feat].flags1 & FF1_DONT_NOTICE_RUNNING) + if (f_info[c_ptr->feat].flags & FF_DONT_NOTICE_RUNNING) { notice = FALSE; } - /* A detected trap is interesting */ - if (c_ptr->info & (CAVE_TRDT)) notice = TRUE; - /* Interesting feature */ if (notice) return (TRUE); @@ -3976,9 +3556,6 @@ static bool_ run_test(void) inv = FALSE; } - /* Mega-Hack -- Maze code removes CAVE_MARK XXX XXX XXX */ - if (c_ptr->info & (CAVE_TRDT)) return (TRUE); - /* Analyze unknown grids and floors */ if (inv || cave_floor_bold(row, col)) { @@ -4132,7 +3709,7 @@ static bool_ run_test(void) } /* Two options, examining corners */ - else if (find_examine && !find_cut) + else if (options->find_examine && !options->find_cut) { /* Primary option */ find_current = option; @@ -4154,7 +3731,7 @@ static bool_ run_test(void) { /* Can not see anything ahead and in the direction we */ /* are turning, assume that it is a potential corner. */ - if (find_examine && + if (options->find_examine && see_nothing(option, row, col) && see_nothing(option2, row, col)) { @@ -4170,7 +3747,7 @@ static bool_ run_test(void) } /* This corner is seen to be enclosed; we cut the corner. */ - else if (find_cut) + else if (options->find_cut) { find_current = option2; find_prevdir = option2; @@ -4216,7 +3793,7 @@ void run_step(int dir) msg_print("You cannot run in that direction."); /* Disturb */ - disturb(0); + disturb(); /* Done */ return; @@ -4236,7 +3813,7 @@ void run_step(int dir) if (run_test()) { /* Disturb */ - disturb(0); + disturb(); /* Done */ return; @@ -4251,15 +3828,17 @@ void run_step(int dir) /* Move the player, using the "pickup" flag */ - move_player_aux(find_current, always_pickup, 1, TRUE); + move_player_aux(find_current, options->always_pickup, 1); } /* * Issue a pet command */ -void do_cmd_pet(void) +void do_cmd_pet() { + auto const &r_info = game->edit_data.r_info; + int i = 0; int num = 0; @@ -4520,13 +4099,11 @@ void do_cmd_pet(void) /* Process the monsters (backwards) */ for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--) { - monster_race *r_ptr; - /* Access the monster */ m_ptr = &m_list[pet_ctr]; - r_ptr = &r_info[m_ptr->r_idx]; + auto r_ptr = &r_info[m_ptr->r_idx]; - if ((!(r_ptr->flags7 & RF7_NO_DEATH)) && ((m_ptr->status == MSTATUS_PET) || (m_ptr->status == MSTATUS_FRIEND))) /* Get rid of it! */ + if ((!(r_ptr->flags & RF_NO_DEATH)) && ((m_ptr->status == MSTATUS_PET) || (m_ptr->status == MSTATUS_FRIEND))) /* Get rid of it! */ { bool_ checked = FALSE; char command; @@ -4589,13 +4166,11 @@ void do_cmd_pet(void) /* Process the monsters (backwards) */ for (pet_ctr = m_max - 1; pet_ctr >= 1; pet_ctr--) { - monster_race *r_ptr; - /* Access the monster */ m_ptr = &m_list[pet_ctr]; - r_ptr = &r_info[m_ptr->r_idx]; + auto r_ptr = &r_info[m_ptr->r_idx]; - if ((!(r_ptr->flags7 & RF7_NO_DEATH)) && ((m_ptr->status == MSTATUS_COMPANION))) /* Get rid of it! */ + if ((!(r_ptr->flags & RF_NO_DEATH)) && ((m_ptr->status == MSTATUS_COMPANION))) /* Get rid of it! */ { bool_ delete_this = FALSE; @@ -4720,9 +4295,11 @@ void do_cmd_integrate_body() */ bool_ do_cmd_leave_body(bool_ drop_body) { + auto const &r_info = game->edit_data.r_info; + object_type *o_ptr, forge; - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; int i; @@ -4759,7 +4336,7 @@ bool_ do_cmd_leave_body(bool_ drop_body) o_ptr->ident |= IDENT_STOREB; /* Unique corpses are unique */ - if (r_ptr->flags1 & RF1_UNIQUE) + if (r_ptr->flags & RF_UNIQUE) { o_ptr->name1 = 201; } @@ -4855,13 +4432,13 @@ bool_ execute_inscription(byte i, byte y, byte x) monster_type *m_ptr = &m_list[c_ptr->m_idx]; auto const r_ptr = m_ptr->race(); - if (r_ptr->flags7 & RF7_CAN_FLY) + if (r_ptr->flags & RF_CAN_FLY) { msg_print("The monster simply flies over the chasm."); } else { - if (!(r_ptr->flags1 & RF1_UNIQUE)) + if (!(r_ptr->flags & RF_UNIQUE)) { msg_print("The monster falls in the chasm!"); delete_monster_idx(c_ptr->m_idx); @@ -4953,13 +4530,14 @@ void do_cmd_engrave() { if (!strcmp(inscription_info[i].text, buf)) { - if (inscription_info[i].know) + if (p_ptr->inscriptions[i]) { - /* Save the inscription */ cave[p_ptr->py][p_ptr->px].inscription = i; } else + { msg_print("You can't use this inscription for now."); + } } } diff --git a/src/cmd1.hpp b/src/cmd1.hpp index 3ae44ed2..19b40ebf 100644 --- a/src/cmd1.hpp +++ b/src/cmd1.hpp @@ -4,22 +4,22 @@ #include "monster_type_fwd.hpp" #include "object_type_fwd.hpp" -extern void attack_special(monster_type *m_ptr, s32b special, int dam); -extern bool_ test_hit_fire(int chance, int ac, int vis); -extern bool_ test_hit_norm(int chance, int ac, int vis); -extern s16b critical_shot(int weight, int plus, int dam, int skill); -extern s16b critical_norm(int weight, int plus, int dam, int weapon_tval, bool_ *done_crit); -extern s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr, s32b *special); -extern void search(void); -extern void carry(int pickup); -extern void py_attack(int y, int x, int max_blow); -extern bool_ player_can_enter(byte feature); -extern void move_player(int dir, int do_pickup, bool_ disarm); -extern void move_player_aux(int dir, int do_pickup, int run, bool_ disarm); -extern void run_step(int dir); -extern void do_cmd_pet(void); -extern void do_cmd_integrate_body(); -extern bool_ do_cmd_leave_body(bool_ drop_body); -extern bool_ execute_inscription(byte i, byte y, byte x); -extern void do_cmd_engrave(void); -extern void do_spin(void); +void attack_special(monster_type *m_ptr, s32b special, int dam); +bool_ test_hit_fire(int chance, int ac, int vis); +bool_ test_hit_norm(int chance, int ac, int vis); +s16b critical_shot(int weight, int plus, int dam, int skill); +s16b critical_norm(int weight, int plus, int dam, int weapon_tval, bool_ *done_crit); +s16b tot_dam_aux(object_type *o_ptr, int tdam, monster_type *m_ptr, s32b *special); +void search(); +void carry(int pickup); +void py_attack(int y, int x, int max_blow); +bool_ player_can_enter(byte feature); +void move_player(int dir, int do_pickup); +void move_player_aux(int dir, int do_pickup, int run); +void run_step(int dir); +void do_cmd_pet(); +void do_cmd_integrate_body(); +bool_ do_cmd_leave_body(bool_ drop_body); +bool_ execute_inscription(byte i, byte y, byte x); +void do_cmd_engrave(); +void do_spin(); diff --git a/src/cmd2.cc b/src/cmd2.cc index cfdeab44..a348c221 100644 --- a/src/cmd2.cc +++ b/src/cmd2.cc @@ -13,8 +13,11 @@ #include "cave_type.hpp" #include "cmd1.hpp" #include "dungeon_info_type.hpp" +#include "dungeon_flag.hpp" +#include "feature_flag.hpp" #include "feature_type.hpp" #include "files.hpp" +#include "game.hpp" #include "gods.hpp" #include "hook_chat_in.hpp" #include "hook_enter_dungeon_in.hpp" @@ -26,11 +29,14 @@ #include "monster2.hpp" #include "monster3.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" #include "monster_type.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_flag.hpp" #include "object_kind.hpp" #include "options.hpp" +#include "player_race_flag.hpp" #include "player_type.hpp" #include "skills.hpp" #include "spells1.hpp" @@ -38,8 +44,6 @@ #include "spells3.hpp" #include "stats.hpp" #include "tables.hpp" -#include "trap_type.hpp" -#include "traps.hpp" #include "util.hpp" #include "util.h" #include "variable.h" @@ -56,7 +60,7 @@ using std::this_thread::sleep_for; using std::chrono::milliseconds; -void do_cmd_immovable_special(void); +void do_cmd_immovable_special(); /* * Try to bash an altar @@ -73,14 +77,16 @@ static bool_ do_cmd_bash_altar(int y, int x) */ static bool_ do_cmd_bash_fountain(int y, int x) { + auto const &r_info = game->edit_data.r_info; + int bash, temp; bool_ more = TRUE; - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; - if ((p_ptr->body_monster != 0) && !(r_ptr->flags2 & RF2_BASH_DOOR)) + if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_BASH_DOOR)) { msg_print("You cannot do that."); @@ -129,19 +135,44 @@ static bool_ stair_hooks(stairs_direction direction) return (!out.allow); } +/* + * Ask for confirmation before leaving level; based + * on whether the 'confirm_stairs' option is set. + */ +static bool ask_leave() +{ + if (options->confirm_stairs) + { + if (get_check("Really leave the level? ")) + { + return true; // Leave + } + else + { + return false; // Don't leave + } + } + else + { + return true; // Leave + } +} + /* * Go up one level */ -void do_cmd_go_up(void) +void do_cmd_go_up() { + auto const &d_info = game->edit_data.d_info; + bool_ go_up = FALSE, go_up_many = FALSE, prob_traveling = FALSE; cave_type *c_ptr; int oldl = dun_level; - dungeon_info_type *d_ptr = &d_info[dungeon_type]; + auto d_ptr = &d_info[dungeon_type]; /* Player grid */ @@ -160,15 +191,11 @@ void do_cmd_go_up(void) { go_up = TRUE; } - else if ((dungeon_flags2 & DF2_ASK_LEAVE)) + else if (dungeon_flags & DF_ASK_LEAVE) { go_up = get_check("Leave this unique level forever? "); } - else if (confirm_stairs) - { - go_up = get_check("Really leave the level? "); - } - else + else if (ask_leave()) { go_up = TRUE; } @@ -181,15 +208,11 @@ void do_cmd_go_up(void) { go_up = TRUE; } - else if ((dungeon_flags2 & DF2_ASK_LEAVE)) + else if (dungeon_flags & DF_ASK_LEAVE) { go_up = get_check("Leave this unique level forever? "); } - else if (confirm_stairs) - { - go_up_many = get_check("Really leave the level? "); - } - else + else if (ask_leave()) { go_up_many = TRUE; } @@ -200,7 +223,7 @@ void do_cmd_go_up(void) { leaving_quest = p_ptr->inside_quest; - if ((dungeon_flags2 & DF2_ASK_LEAVE) && + if ((dungeon_flags & DF_ASK_LEAVE) && !get_check("Leave this unique level forever? ")) return; @@ -214,12 +237,12 @@ void do_cmd_go_up(void) } /* Exits to previous area in flat terrains */ - else if (!(dungeon_flags1 & DF1_FLAT) && + else if (!(dungeon_flags & DF_FLAT) && p_ptr->prob_travel && !p_ptr->inside_quest) { if (d_ptr->mindepth == dun_level) return; - if (dungeon_flags2 & DF2_NO_EASY_MOVE) + if (dungeon_flags & DF_NO_EASY_MOVE) { msg_print("Some powerful force prevents your from teleporting."); return; @@ -227,12 +250,7 @@ void do_cmd_go_up(void) prob_traveling = TRUE; - if (confirm_stairs) - { - if (get_check("Really leave the level? ")) - go_up = TRUE; - } - else + if (ask_leave()) { go_up = TRUE; } @@ -296,7 +314,7 @@ void do_cmd_go_up(void) /* * Returns TRUE if we are in the Between... */ -static bool_ between_effect(void) +static bool_ between_effect() { byte bx, by; @@ -340,19 +358,19 @@ static bool_ between_effect(void) /* * Go down one level */ -void do_cmd_go_down(void) +void do_cmd_go_down() { + auto const &d_info = game->edit_data.d_info; + cave_type *c_ptr; bool_ go_down = FALSE, go_down_many = FALSE, prob_traveling = FALSE; - bool_ fall_trap = FALSE; - char i; int old_dun = dun_level; - dungeon_info_type *d_ptr = &d_info[dungeon_type]; + auto d_ptr = &d_info[dungeon_type]; /* MUST be actived now */ @@ -363,10 +381,8 @@ void do_cmd_go_down(void) if (p_ptr->astral && (dun_level == 98)) return; - if (c_ptr->t_idx == TRAP_OF_SINKING) fall_trap = TRUE; - /* test if on special level */ - if ((dungeon_flags2 & DF2_ASK_LEAVE)) + if (dungeon_flags & DF_ASK_LEAVE) { prt("Leave this unique level forever (y/n) ? ", 0, 0); flush(); @@ -394,12 +410,7 @@ void do_cmd_go_down(void) } else { - if (confirm_stairs) - { - if (get_check("Really leave the level? ")) - go_down_many = TRUE; - } - else + if (ask_leave()) { go_down_many = TRUE; } @@ -423,12 +434,7 @@ void do_cmd_go_down(void) } else { - if (confirm_stairs) - { - if (get_check("Really leave the level? ")) - go_down = TRUE; - } - else + if (ask_leave()) { go_down = TRUE; } @@ -444,31 +450,26 @@ void do_cmd_go_down(void) return; } - else if (!(dungeon_flags1 & DF1_FLAT) && + else if (!(dungeon_flags & DF_FLAT) && p_ptr->prob_travel && !p_ptr->inside_quest) { if (d_ptr->maxdepth == dun_level) return; - if (dungeon_flags2 & DF2_NO_EASY_MOVE) + if (dungeon_flags & DF_NO_EASY_MOVE) { - msg_print("Some powerfull force prevents your from teleporting."); + msg_print("Some powerful force prevents your from teleporting."); return; } prob_traveling = TRUE; - if (confirm_stairs) - { - if (get_check("Really leave the level? ")) - go_down = TRUE; - } - else + if (ask_leave()) { go_down = TRUE; } } - else if (!(fall_trap)) + else { msg_print("I see no down staircase here."); return; @@ -478,15 +479,10 @@ void do_cmd_go_down(void) { energy_use = 0; - if (fall_trap) - msg_print("You deliberately jump through the trap door."); + if (c_ptr->feat == FEAT_WAY_MORE) + msg_print("You enter the next area."); else - { - if (c_ptr->feat == FEAT_WAY_MORE) - msg_print("You enter the next area."); - else - msg_print("You enter a maze of down staircases."); - } + msg_print("You enter a maze of down staircases."); autosave_checkpoint(); @@ -512,7 +508,7 @@ void do_cmd_go_down(void) { if (d_info[c_ptr->special].min_plev <= p_ptr->lev) { - dungeon_info_type *d_ptr = &d_info[c_ptr->special]; + auto d_ptr = &d_info[c_ptr->special]; /* Do the lua scripts refuse ? ;) */ { @@ -543,7 +539,7 @@ void do_cmd_go_down(void) dun_level = d_ptr->mindepth; } - msg_format("You go into %s", d_info[dungeon_type].text); + msg_format("You go into %s", d_info[dungeon_type].text.c_str()); } else { @@ -556,58 +552,9 @@ void do_cmd_go_down(void) /* Leaving */ p_ptr->leaving = TRUE; - - if (!fall_trap) - { - /* Create a way back */ - if (go_down_many) - create_up_shaft = TRUE; - else - create_up_stair = TRUE; - } } } - - -/* - * Simple command to "search" for one turn - */ -void do_cmd_search(void) -{ - /* Allow repeated command */ - if (command_arg) - { - /* Set repeat count */ - command_rep = command_arg - 1; - - /* Redraw the state */ - p_ptr->redraw |= (PR_FRAME); - - /* Cancel the arg */ - command_arg = 0; - } - - /* Take a turn */ - energy_use = 100; - - /* Search */ - search(); -} - - -/* - * Hack -- toggle search mode - */ -void do_cmd_toggle_search(void) -{ - p_ptr->update |= (PU_BONUS); - p_ptr->redraw |= (PR_FRAME); - p_ptr->searching = !p_ptr->searching; -} - - - /* * Determine if a grid contains a chest */ @@ -648,6 +595,8 @@ static s16b chest_check(int y, int x) */ static void chest_death(int y, int x, s16b o_idx) { + auto const &d_info = game->edit_data.d_info; + int number; bool_ small; @@ -717,41 +666,6 @@ static void chest_death(int y, int x, s16b o_idx) /* - * Chests have traps too. - * - * Exploding chest destroys contents (and traps). - * Note that the chest itself is never destroyed. - */ -static void chest_trap(int y, int x, s16b o_idx) -{ - int trap; - - object_type *o_ptr = &o_list[o_idx]; - - bool_ ident = FALSE; - - - /* Ignore disarmed chests */ - if (o_ptr->pval <= 0) return; - - /* Obtain the trap */ - trap = o_ptr->pval; - - /* Message */ - msg_print("You found a trap!"); - - /* Set off trap */ - ident = player_activate_trap_type(y, x, o_ptr, o_idx); - if (ident) - { - t_info[o_ptr->pval].ident = TRUE; - msg_format("You identified the trap as %s.", - t_info[trap].name); - } -} - - -/* * Attempt to open the given chest at the given location * * Assume there is no monster blocking the destination @@ -760,6 +674,8 @@ static void chest_trap(int y, int x, s16b o_idx) */ static bool_ do_cmd_open_chest(int y, int x, s16b o_idx) { + auto const &r_info = game->edit_data.r_info; + int i, j; bool_ flag = TRUE; @@ -768,10 +684,10 @@ static bool_ do_cmd_open_chest(int y, int x, s16b o_idx) object_type *o_ptr = &o_list[o_idx]; - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; - if ((p_ptr->body_monster != 0) && !(r_ptr->flags2 & RF2_OPEN_DOOR)) + if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_OPEN_DOOR)) { msg_print("You cannot open chests."); @@ -788,7 +704,7 @@ static bool_ do_cmd_open_chest(int y, int x, s16b o_idx) flag = FALSE; /* Get the "disarm" factor */ - i = p_ptr->skill_dis; + i = 100; /* Penalize some conditions */ if (p_ptr->blind || no_lite()) i = i / 10; @@ -814,7 +730,7 @@ static bool_ do_cmd_open_chest(int y, int x, s16b o_idx) /* We may continue repeating */ more = TRUE; - if (flush_failure) flush(); + flush_on_failure(); msg_print("You failed to pick the lock."); } @@ -823,9 +739,6 @@ static bool_ do_cmd_open_chest(int y, int x, s16b o_idx) /* Allowed to open */ if (flag) { - /* Apply chest traps, if any */ - chest_trap(y, x, o_idx); - /* Let the Chest drop items */ chest_death(y, x, o_idx); } @@ -862,16 +775,6 @@ static bool_ is_closed(cave_type *c_ptr) return ((feat >= FEAT_DOOR_HEAD) && (feat <= FEAT_DOOR_TAIL)); } - -/* - * Return TRUE if the given grid has a trap - */ -static bool_ is_trap(cave_type *c_ptr) -{ - return ((c_ptr->info & (CAVE_TRDT)) != 0); -} - - /* * Return the number of doors/traps around (or under) * the character using the filter function 'test' @@ -953,9 +856,6 @@ static int count_chests(int *y, int *x, bool_ trapped) /* Already open */ if (o_ptr->pval == 0) continue; - /* No (known) traps here */ - if (trapped && (!object_known_p(o_ptr) || !o_ptr->pval)) continue; - /* OK */ ++count; @@ -1004,16 +904,18 @@ static int coords_to_dir(int y, int x) */ static bool_ do_cmd_open_aux(int y, int x, int dir) { + auto const &r_info = game->edit_data.r_info; + int i, j; cave_type *c_ptr; bool_ more = FALSE; - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; - if ((p_ptr->body_monster != 0) && !(r_ptr->flags2 & RF2_OPEN_DOOR)) + if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_OPEN_DOOR)) { msg_print("You cannot open doors."); @@ -1037,7 +939,7 @@ static bool_ do_cmd_open_aux(int y, int x, int dir) else if (c_ptr->feat >= FEAT_DOOR_HEAD + 0x01) { /* Disarm factor */ - i = p_ptr->skill_dis; + i = 100; /* Penalize some conditions */ if (p_ptr->blind || no_lite()) i = i / 10; @@ -1058,18 +960,12 @@ static bool_ do_cmd_open_aux(int y, int x, int dir) /* Message */ msg_print("You have picked the lock."); - /* Set off trap */ - if (c_ptr->t_idx != 0) player_activate_door_trap(y, x); - /* Open the door */ cave_set_feat(y, x, FEAT_OPEN); /* Update some things */ p_ptr->update |= (PU_VIEW | PU_MONSTERS | PU_MON_LITE); - /* Sound */ - sound(SOUND_OPENDOOR); - /* Experience */ gain_exp(1); } @@ -1078,7 +974,7 @@ static bool_ do_cmd_open_aux(int y, int x, int dir) else { /* Failure */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_print("You failed to pick the lock."); @@ -1091,17 +987,11 @@ static bool_ do_cmd_open_aux(int y, int x, int dir) /* Closed door */ else { - /* Set off trap */ - if (c_ptr->t_idx != 0) player_activate_door_trap(y, x); - /* Open the door */ cave_set_feat(y, x, FEAT_OPEN); /* Update some things */ p_ptr->update |= (PU_VIEW | PU_MONSTERS | PU_MON_LITE); - - /* Sound */ - sound(SOUND_OPENDOOR); } /* Result */ @@ -1115,8 +1005,10 @@ static bool_ do_cmd_open_aux(int y, int x, int dir) * * Unlocking a locked door/chest is worth one experience point. */ -void do_cmd_open(void) +void do_cmd_open() { + auto const &r_info = game->edit_data.r_info; + int y, x, dir; s16b o_idx; @@ -1125,10 +1017,10 @@ void do_cmd_open(void) bool_ more = FALSE; - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; - if ((p_ptr->body_monster != 0) && !(r_ptr->flags2 & RF2_OPEN_DOOR)) + if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_OPEN_DOOR)) { msg_print("You cannot open doors."); @@ -1225,7 +1117,7 @@ void do_cmd_open(void) } /* Cancel repeat unless we may continue */ - if (!more) disturb(0); + if (!more) disturb(); } @@ -1241,14 +1133,16 @@ void do_cmd_open(void) */ static bool_ do_cmd_close_aux(int y, int x, int dir) { + auto const &r_info = game->edit_data.r_info; + cave_type *c_ptr; bool_ more = FALSE; - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; - if ((p_ptr->body_monster != 0) && !(r_ptr->flags2 & RF2_OPEN_DOOR)) + if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_OPEN_DOOR)) { msg_print("You cannot close doors."); @@ -1261,9 +1155,6 @@ static bool_ do_cmd_close_aux(int y, int x, int dir) /* Get grid and contents */ c_ptr = &cave[y][x]; - /* Set off trap */ - if (c_ptr->t_idx != 0) player_activate_door_trap(y, x); - /* Broken door */ if (c_ptr->feat == FEAT_BROKEN) { @@ -1279,9 +1170,6 @@ static bool_ do_cmd_close_aux(int y, int x, int dir) /* Update some things */ p_ptr->update |= (PU_VIEW | PU_MONSTERS | PU_MON_LITE); - - /* Sound */ - sound(SOUND_SHUTDOOR); } /* Result */ @@ -1292,7 +1180,7 @@ static bool_ do_cmd_close_aux(int y, int x, int dir) /* * Close an open door. */ -void do_cmd_close(void) +void do_cmd_close() { int y, x, dir; @@ -1377,7 +1265,7 @@ void do_cmd_close(void) } /* Cancel repeat unless we may continue */ - if (!more) disturb(0); + if (!more) disturb(); } @@ -1386,6 +1274,8 @@ void do_cmd_close(void) */ static bool_ do_cmd_tunnel_test(int y, int x) { + auto const &f_info = game->edit_data.f_info; + /* Must have knowledge(execpt on "forget" levels) */ if (!(cave[y][x].info & (CAVE_MARK))) { @@ -1407,7 +1297,7 @@ static bool_ do_cmd_tunnel_test(int y, int x) } /* Must be tunnelable */ - if (!(f_info[cave[y][x].feat].flags1 & FF1_TUNNELABLE)) + if (!(f_info[cave[y][x].feat].flags & FF_TUNNELABLE)) { /* Message */ msg_print(f_info[cave[y][x].feat].tunnel); @@ -1466,10 +1356,13 @@ static bool_ twall(int y, int x, byte feat) */ static bool_ do_cmd_tunnel_aux(int y, int x, int dir) { + auto const &d_info = game->edit_data.d_info; + auto const &f_info = game->edit_data.f_info; + int skill_req = 0, skill_req_1pct = 0; cave_type *c_ptr = &cave[y][x]; - feature_type *f_ptr = &f_info[c_ptr->feat]; + auto f_ptr = &f_info[c_ptr->feat]; bool_ more = FALSE; @@ -1495,11 +1388,8 @@ static bool_ do_cmd_tunnel_aux(int y, int x, int dir) /* Get grid */ c_ptr = &cave[y][x]; - /* Sound */ - sound(SOUND_DIG); - /* Titanium */ - if (f_ptr->flags1 & FF1_PERMANENT) + if (f_ptr->flags & FF_PERMANENT) { msg_print(f_ptr->tunnel); } @@ -1520,9 +1410,6 @@ static bool_ do_cmd_tunnel_aux(int y, int x, int dir) /* We may continue chopping */ msg_print(f_ptr->tunnel); more = TRUE; - - /* Occasional Search XXX XXX */ - if (rand_int(100) < 25) search(); } } @@ -1673,9 +1560,6 @@ static bool_ do_cmd_tunnel_aux(int y, int x, int dir) msg_print("You have finished the tunnel."); c_ptr->mimic = 0; lite_spot(y, x); - - /* Set off trap */ - if (c_ptr->t_idx != 0) player_activate_door_trap(y, x); } /* Keep trying */ @@ -1690,9 +1574,6 @@ static bool_ do_cmd_tunnel_aux(int y, int x, int dir) /* We may continue tunelling */ msg_print(f_info[feat].tunnel); more = TRUE; - - /* Occasional Search XXX XXX */ - if (rand_int(100) < 25) search(); } } @@ -1750,7 +1631,7 @@ static bool_ do_cmd_tunnel_aux(int y, int x, int dir) * Digging is very difficult without a "digger" weapon, but can be * accomplished by strong players using heavy weapons. */ -void do_cmd_tunnel(void) +void do_cmd_tunnel() { int y, x, dir; @@ -1784,16 +1665,8 @@ void do_cmd_tunnel(void) /* Get grid */ c_ptr = &cave[y][x]; - /* No tunnelling through doors */ - if (((c_ptr->feat >= FEAT_DOOR_HEAD) && - (c_ptr->feat <= FEAT_DOOR_TAIL)) || (c_ptr->feat == FEAT_SHOP)) - { - /* Message */ - msg_print("You cannot tunnel through doors."); - } - /* No tunnelling through air */ - else if (cave_floor_grid(c_ptr)) + if (cave_floor_grid(c_ptr)) { /* Message */ msg_print("You cannot tunnel through air."); @@ -1821,309 +1694,9 @@ void do_cmd_tunnel(void) } /* Cancel repetition unless we can continue */ - if (!more) disturb(0); -} - - -/* - * Perform the basic "disarm" command - * - * Assume destination is a visible trap - * - * Assume there is no monster blocking the destination - * - * Returns TRUE if repeated commands may continue - */ -static bool_ do_cmd_disarm_chest(int y, int x, s16b o_idx) -{ - int i, j; - - bool_ more = FALSE; - - object_type *o_ptr = &o_list[o_idx]; - - trap_type *t_ptr = &t_info[o_ptr->pval]; - - - /* Take a turn */ - energy_use = 100; - - /* Get the "disarm" factor */ - i = p_ptr->skill_dis; - - /* Penalize some conditions */ - if (p_ptr->blind || no_lite()) i = i / 10; - if (p_ptr->confused || p_ptr->image) i = i / 10; - - /* Extract the difficulty */ - j = i - t_ptr->difficulty * 3; - - /* Always have a small chance of success */ - if (j < 2) j = 2; - - /* Must find the trap first. */ - if (!object_known_p(o_ptr)) - { - msg_print("I don't see any traps."); - } - - /* Already disarmed/unlocked */ - else if (o_ptr->pval <= 0) - { - msg_print("The chest is not trapped."); - } - - /* Success (get a lot of experience) */ - else if (rand_int(100) < j) - { - msg_print("You have disarmed the chest."); - gain_exp(t_ptr->difficulty * 3); - o_ptr->pval = (0 - o_ptr->pval); - } - - /* Failure -- Keep trying */ - else if ((i > 5) && (randint(i) > 5)) - { - /* We may keep trying */ - more = TRUE; - if (flush_failure) flush(); - msg_print("You failed to disarm the chest."); - } - - /* Failure -- Set off the trap */ - else - { - msg_print("You set off a trap!"); - sound(SOUND_FAIL); - chest_trap(y, x, o_idx); - } - - /* Result */ - return (more); + if (!more) disturb(); } - -/* - * Perform the basic "disarm" command - * - * Assume destination is a visible trap - * - * Assume there is no monster blocking the destination - * - * Returns TRUE if repeated commands may continue - */ -static bool_ do_cmd_disarm_aux(int y, int x, int dir, int do_pickup) -{ - int i, j, power; - - cave_type *c_ptr; - - cptr name; - - bool_ more = FALSE; - - - /* Take a turn */ - energy_use = 100; - - /* Get grid and contents */ - c_ptr = &cave[y][x]; - - /* Access trap name */ - if (t_info[c_ptr->t_idx].ident) - { - name = t_info[c_ptr->t_idx].name; - } - else - { - name = "unknown trap"; - } - - /* Get the "disarm" factor */ - i = p_ptr->skill_dis; - - /* Penalize some conditions */ - if (p_ptr->blind || no_lite()) i = i / 10; - if (p_ptr->confused || p_ptr->image) i = i / 10; - - /* XXX XXX XXX Variable power? */ - - /* Extract trap "power" */ - power = t_info[c_ptr->t_idx].difficulty; - - /* Extract the difficulty */ - j = i - power; - - /* Always have a small chance of success */ - if (j < 2) j = 2; - - /* Success */ - if (rand_int(100) < j) - { - /* Message */ - msg_format("You have disarmed the %s.", name); - - /* Reward */ - gain_exp(power); - - /* Forget the trap */ - c_ptr->info &= ~(CAVE_MARK | CAVE_TRDT); - - /* Remove the trap */ - c_ptr->t_idx = 0; - - /* Move the player onto the trap */ - if (!(f_info[c_ptr->feat].flags1 & FF1_DOOR)) - move_player_aux(dir, do_pickup, 0, TRUE); - - /* Remove trap attr from grid */ - note_spot(y, x); - lite_spot(y, x); - } - - /* Failure -- Keep trying */ - else if ((i > 5) && (randint(i) > 5)) - { - /* Failure */ - if (flush_failure) flush(); - - /* Message */ - msg_format("You failed to disarm the %s.", name); - - /* We may keep trying */ - more = TRUE; - } - - /* Failure -- Set off the trap */ - else - { - /* Message */ - msg_format("You set off the %s!", name); - - /* Move the player onto the trap */ - if (!(f_info[c_ptr->feat].flags1 & FF1_DOOR)) - move_player_aux(dir, do_pickup, 0, FALSE); - } - - /* Result */ - return (more); -} - - -/* - * Disamrs the monster traps(no failure) - */ -void do_cmd_disarm_mon_trap(int y, int x) -{ - msg_print("You disarm the monster trap."); - - place_floor_convert_glass(y, x); - cave[p_ptr->py][p_ptr->px].special = cave[p_ptr->py][p_ptr->px].special2 = 0; -} - - -/* - * Disarms a trap, or chest - */ -void do_cmd_disarm(void) -{ - int y, x, dir; - - s16b o_idx; - - cave_type *c_ptr; - - bool_ more = FALSE; - - - /* Pick a direction if there's an obvious choice */ - { - int num_traps, num_chests; - - /* Count visible traps */ - num_traps = count_feats(&y, &x, is_trap, TRUE); - - /* Count chests (trapped) */ - num_chests = count_chests(&y, &x, TRUE); - - /* See if only one target */ - if (num_traps || num_chests) - { - if (num_traps + num_chests <= 1) - command_dir = coords_to_dir(y, x); - } - } - - /* Allow repeated command */ - if (command_arg) - { - /* Set repeat count */ - command_rep = command_arg - 1; - - /* Redraw the state */ - p_ptr->redraw |= (PR_FRAME); - - /* Cancel the arg */ - command_arg = 0; - } - - /* Get a direction (or abort) */ - if (get_rep_dir(&dir)) - { - /* Get location */ - y = p_ptr->py + ddy[dir]; - x = p_ptr->px + ddx[dir]; - - /* Get grid and contents */ - c_ptr = &cave[y][x]; - - /* Check for chests */ - o_idx = chest_check(y, x); - - /* Disarm a trap */ - if (((c_ptr->t_idx == 0) || (!(c_ptr->info & CAVE_TRDT))) && - !o_idx && (c_ptr->feat != FEAT_MON_TRAP)) - { - /* Message */ - msg_print("You see nothing there to disarm."); - } - - /* Monster in the way */ - else if (c_ptr->m_idx) - { - /* Message */ - msg_print("There is a monster in the way!"); - - /* Attack */ - py_attack(y, x, -1); - } - - /* Disarm chest */ - else if (o_idx) - { - /* Disarm the chest */ - more = do_cmd_disarm_chest(y, x, o_idx); - } - - /* Disarm trap */ - else - { - /* Disarm the trap */ - if (c_ptr->feat == FEAT_MON_TRAP) - { - do_cmd_disarm_mon_trap(y, x); - more = FALSE; - } - else - more = do_cmd_disarm_aux(y, x, dir, always_pickup); - } - } - - /* Cancel repeat unless told not to */ - if (!more) disturb(0); -} - - /* * Perform the basic "bash" command * @@ -2135,16 +1708,18 @@ void do_cmd_disarm(void) */ static bool_ do_cmd_bash_aux(int y, int x, int dir) { + auto const &r_info = game->edit_data.r_info; + int bash, temp; cave_type *c_ptr; bool_ more = FALSE; - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; - if ((p_ptr->body_monster != 0) && !(r_ptr->flags2 & RF2_BASH_DOOR)) + if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_BASH_DOOR)) { msg_print("You cannot do that."); @@ -2182,26 +1757,17 @@ static bool_ do_cmd_bash_aux(int y, int x, int dir) /* Break down the door */ if (rand_int(100) < 50) { - /* Set off trap */ - if (c_ptr->t_idx != 0) player_activate_door_trap(y, x); - cave_set_feat(y, x, FEAT_BROKEN); } /* Open the door */ else { - /* Set off trap */ - if (c_ptr->t_idx != 0) player_activate_door_trap(y, x); - cave_set_feat(y, x, FEAT_OPEN); } - /* Sound */ - sound(SOUND_OPENDOOR); - /* Hack -- Fall through the door. Can't disarm while falling. */ - move_player_aux(dir, always_pickup, 0, FALSE); + move_player_aux(dir, options->always_pickup, 0); /* Update some things */ p_ptr->update |= (PU_VIEW | PU_MON_LITE); @@ -2225,7 +1791,7 @@ static bool_ do_cmd_bash_aux(int y, int x, int dir) msg_print("You are off-balance."); /* Hack -- Lose balance ala paralysis */ - (void)set_paralyzed(2 + rand_int(2)); + set_paralyzed(2 + rand_int(2)); } /* Result */ @@ -2247,18 +1813,20 @@ static bool_ do_cmd_bash_aux(int y, int x, int dir) * * Creatures can also open or bash doors, see elsewhere. */ -void do_cmd_bash(void) +void do_cmd_bash() { + auto const &r_info = game->edit_data.r_info; + int y, x, dir; cave_type *c_ptr; bool_ more = FALSE; - monster_race *r_ptr = &r_info[p_ptr->body_monster]; + auto r_ptr = &r_info[p_ptr->body_monster]; - if ((p_ptr->body_monster != 0) && !(r_ptr->flags2 & RF2_BASH_DOOR)) + if ((p_ptr->body_monster != 0) && !(r_ptr->flags & RF_BASH_DOOR)) { msg_print("You cannot do that."); @@ -2329,7 +1897,7 @@ void do_cmd_bash(void) } /* Unless valid action taken, cancel bash */ - if (!more) disturb(0); + if (!more) disturb(); } @@ -2344,8 +1912,10 @@ void do_cmd_bash(void) * This command must always take a turn, to prevent free detection * of invisible monsters. */ -void do_cmd_alter(void) +void do_cmd_alter() { + auto const &f_info = game->edit_data.f_info; + int y, x, dir; cave_type *c_ptr; @@ -2395,19 +1965,12 @@ void do_cmd_alter(void) } /* Tunnel through walls */ - else if (f_info[c_ptr->feat].flags1 & FF1_TUNNELABLE) + else if (f_info[c_ptr->feat].flags & FF_TUNNELABLE) { /* Tunnel */ more = do_cmd_tunnel_aux(y, x, dir); } - /* Disarm traps */ - else if (c_ptr->t_idx != 0) - { - /* Tunnel */ - more = do_cmd_disarm_aux(y, x, dir, always_pickup); - } - /* Oops */ else { @@ -2417,7 +1980,7 @@ void do_cmd_alter(void) } /* Cancel repetition unless we can continue */ - if (!more) disturb(0); + if (!more) disturb(); } @@ -2461,7 +2024,7 @@ static bool_ get_spike(int *ip) * * This command may NOT be repeated */ -void do_cmd_spike(void) +void do_cmd_spike() { int y, x, dir, item; @@ -2528,8 +2091,10 @@ void do_cmd_spike(void) } -static void do_cmd_walk_jump(int pickup, bool_ disarm) +static void do_cmd_walk_jump(int pickup) { + auto const &wf_info = game->edit_data.wf_info; + int dir; bool_ more = FALSE; @@ -2555,7 +2120,7 @@ static void do_cmd_walk_jump(int pickup, bool_ disarm) energy_use = 100; /* Actually move the character */ - move_player(dir, pickup, disarm); + move_player(dir, pickup); /* Allow more walking */ more = TRUE; @@ -2565,8 +2130,9 @@ static void do_cmd_walk_jump(int pickup, bool_ disarm) energy_use *= (p_ptr->wild_mode) ? ((MAX_HGT + MAX_WID) / 2) : 1; /* Hack again -- Is there a special encounter ??? */ + auto const &wilderness = game->wilderness; if (p_ptr->wild_mode && - magik(wf_info[wild_map[p_ptr->py][p_ptr->px].feat].level - (p_ptr->lev * 2))) + magik(wf_info[wilderness(p_ptr->px, p_ptr->py).feat].level - (p_ptr->lev * 2))) { /* Go into large wilderness view */ p_ptr->wilderness_x = p_ptr->px; @@ -2584,7 +2150,7 @@ static void do_cmd_walk_jump(int pickup, bool_ disarm) } /* Cancel repeat unless we may continue */ - if (!more) disturb(0); + if (!more) disturb(); } @@ -2729,7 +2295,7 @@ static void do_cmd_unwalk() else if (((feat >= FEAT_QUEST_ENTER) && (feat <= FEAT_QUEST_UP)) || ((feat >= FEAT_LESS) && (feat <= FEAT_MORE))) { - move_player(dir, always_pickup, TRUE); + move_player(dir, options->always_pickup); more = FALSE; } @@ -2746,7 +2312,7 @@ static void do_cmd_unwalk() while (dir == 5); } - move_player(dir, always_pickup, TRUE); + move_player(dir, options->always_pickup); } /* Walking semantics */ @@ -2756,14 +2322,14 @@ static void do_cmd_unwalk() } /* Cancel repetition unless we can continue */ - if (!more) disturb(0); + if (!more) disturb(); } /* * Support code for the "Walk" and "Jump" commands */ -void do_cmd_walk(int pickup, bool_ disarm) +void do_cmd_walk(int pickup) { /* Move (usually pickup) */ @@ -2773,7 +2339,7 @@ void do_cmd_walk(int pickup, bool_ disarm) } else { - do_cmd_walk_jump(pickup, disarm); + do_cmd_walk_jump(pickup); } } @@ -2806,7 +2372,7 @@ void do_cmd_run_run() /* * Start running. */ -void do_cmd_run(void) +void do_cmd_run() { if (p_ptr->immovable) { @@ -2846,20 +2412,6 @@ void do_cmd_stay(int pickup) /* Take a turn */ energy_use = 100; - - /* Spontaneous Searching */ - if ((p_ptr->skill_fos >= 50) || (0 == rand_int(50 - p_ptr->skill_fos))) - { - search(); - } - - /* Continuous Searching */ - if (p_ptr->searching) - { - search(); - } - - /* Handle "objects" */ carry(pickup); @@ -2868,7 +2420,7 @@ void do_cmd_stay(int pickup) if (c_ptr->feat == FEAT_SHOP) { /* Disturb */ - disturb(0); + disturb(); /* Hack -- enter store */ command_new = '_'; @@ -2878,13 +2430,15 @@ void do_cmd_stay(int pickup) /* * Resting allows a player to safely restore his hp -RAK- */ -void do_cmd_rest(void) +void do_cmd_rest() { + auto const &f_info = game->edit_data.f_info; + /* Can't rest on a Void Jumpgate -- too dangerous */ if (cave[p_ptr->py][p_ptr->px].feat == FEAT_BETWEEN) { /* 'R&\n' is one of our favourite macros, so we have to do this */ - if (flush_failure) flush(); + flush_on_failure(); /* Tell the player why */ msg_print(format("Resting on a %s is too dangerous!", @@ -2898,7 +2452,7 @@ void do_cmd_rest(void) if (p_ptr->necro_extra & CLASS_UNDEAD) { /* 'R&\n' is one of our favourite macros, so we have to do this */ - if (flush_failure) flush(); + flush_on_failure(); /* Tell the player why */ msg_print("Resting is impossible while undead!"); @@ -2951,9 +2505,6 @@ void do_cmd_rest(void) /* Save the rest code */ resting = command_arg; - /* Cancel searching */ - p_ptr->searching = FALSE; - /* Recalculate bonuses */ p_ptr->update |= (PU_BONUS); @@ -3108,7 +2659,7 @@ int get_shooter_mult(object_type *o_ptr) * * Note that Bows of "Extra Shots" give an extra shot. */ -void do_cmd_fire(void) +void do_cmd_fire() { int dir, item; @@ -3140,7 +2691,7 @@ void do_cmd_fire(void) char o_name[80]; - int msec = delay_factor * delay_factor * delay_factor; + auto const msec = options->delay_factor_ms(); /* Get the "bow" (if any) */ @@ -3210,10 +2761,6 @@ void do_cmd_fire(void) } - /* Sound */ - sound(SOUND_SHOOT); - - /* Describe the object */ object_desc(o_name, q_ptr, FALSE, 3); @@ -3354,9 +2901,9 @@ void do_cmd_fire(void) cptr note_dies = " dies."; /* Some monsters get "destroyed" */ - if ((r_ptr->flags3 & (RF3_DEMON)) || - (r_ptr->flags3 & (RF3_UNDEAD)) || - (r_ptr->flags2 & (RF2_STUPID)) || + if ((r_ptr->flags & RF_DEMON) || + (r_ptr->flags & RF_UNDEAD) || + (r_ptr->flags & RF_STUPID) || (strchr("Evg", r_ptr->d_char))) { /* Special note at death */ @@ -3444,9 +2991,6 @@ void do_cmd_fire(void) { char m_name[80]; - /* Sound */ - sound(SOUND_FLEE); - /* Get the monster name (or "it") */ monster_desc(m_name, m_ptr, 0); @@ -3546,8 +3090,10 @@ void do_cmd_fire(void) * to hit bonus of the weapon to have an effect? Should it ever cause * the item to be destroyed? Should it do any damage at all? */ -void do_cmd_throw(void) +void do_cmd_throw() { + auto const &k_info = game->edit_data.k_info; + int dir; s32b special = 0; @@ -3577,7 +3123,7 @@ void do_cmd_throw(void) char o_name[80]; - int msec = delay_factor * delay_factor * delay_factor; + auto const msec = options->delay_factor_ms(); /* Get an item */ int item; @@ -3592,11 +3138,10 @@ void do_cmd_throw(void) /* Access the item */ object_type *o_ptr = get_object(item); - u32b f1, f2, f3, f4, f5, esp; - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Hack - Cannot throw away 'no drop' cursed items */ - if (cursed_p(o_ptr) && (f4 & TR4_CURSE_NO_DROP)) + if (cursed_p(o_ptr) && (flags & TR_CURSE_NO_DROP)) { /* Oops */ msg_print("Hmmm, you seem to be unable to throw it."); @@ -3768,9 +3313,9 @@ void do_cmd_throw(void) cptr note_dies = " dies."; /* Some monsters get "destroyed" */ - if ((r_ptr->flags3 & (RF3_DEMON)) || - (r_ptr->flags3 & (RF3_UNDEAD)) || - (r_ptr->flags2 & (RF2_STUPID)) || + if ((r_ptr->flags & RF_DEMON) || + (r_ptr->flags & RF_UNDEAD) || + (r_ptr->flags & RF_STUPID) || (strchr("Evg", r_ptr->d_char))) { /* Special note at death */ @@ -3854,9 +3399,6 @@ void do_cmd_throw(void) { char m_name[80]; - /* Sound */ - sound(SOUND_FLEE); - /* Get the monster name (or "it") */ monster_desc(m_name, m_ptr, 0); @@ -3924,8 +3466,10 @@ void do_cmd_throw(void) * to hit bonus of the weapon to have an effect? Should it ever cause * the item to be destroyed? Should it do any damage at all? */ -void do_cmd_boomerang(void) +void do_cmd_boomerang() { + auto const &k_info = game->edit_data.k_info; + int dir; int j, y, x, ny, nx, ty, tx; @@ -3952,7 +3496,7 @@ void do_cmd_boomerang(void) s32b special = 0; - int msec = delay_factor * delay_factor * delay_factor; + auto const msec = options->delay_factor_ms(); /* Get the "bow" (if any) */ @@ -4095,9 +3639,9 @@ void do_cmd_boomerang(void) cptr note_dies = " dies."; /* Some monsters get "destroyed" */ - if ((r_ptr->flags3 & (RF3_DEMON)) || - (r_ptr->flags3 & (RF3_UNDEAD)) || - (r_ptr->flags2 & (RF2_STUPID)) || + if ((r_ptr->flags & RF_DEMON) || + (r_ptr->flags & RF_UNDEAD) || + (r_ptr->flags & RF_STUPID) || (strchr("Evg", r_ptr->d_char))) { /* Special note at death */ @@ -4181,9 +3725,6 @@ void do_cmd_boomerang(void) { char m_name[80]; - /* Sound */ - sound(SOUND_FLEE); - /* Get the monster name (or "it") */ monster_desc(m_name, m_ptr, 0); @@ -4196,8 +3737,7 @@ void do_cmd_boomerang(void) j = (hit_body ? breakage_chance(o_ptr) : 0); /* Break the boomerang */ - if (!(o_ptr->art_name || artifact_p(o_ptr)) && - (rand_int(100) < j)) + if ((!artifact_p(o_ptr)) && (rand_int(100) < j)) { msg_print(format("Your %s is destroyed.", o_name)); inc_stack_size_ex(INVEN_BOW, -1, OPTIMIZE, NO_DESCRIBE); @@ -4252,6 +3792,8 @@ void do_cmd_boomerang(void) static bool_ tport_vertically(bool_ how) { + auto const &d_info = game->edit_data.d_info; + /* quest? */ if (p_ptr->inside_quest) { @@ -4259,7 +3801,7 @@ static bool_ tport_vertically(bool_ how) return (FALSE); } - if (dungeon_flags2 & DF2_NO_EASY_MOVE) + if (dungeon_flags & DF_NO_EASY_MOVE) { msg_print("Some powerful force prevents you from teleporting."); return FALSE; @@ -4299,7 +3841,7 @@ static bool_ tport_vertically(bool_ how) * Do a special ``movement'' action. Meant to be used for ``immovable'' * characters. */ -void do_cmd_immovable_special(void) +void do_cmd_immovable_special() { int i, ii, ij, dir; @@ -4360,8 +3902,8 @@ void do_cmd_immovable_special(void) /* Give some choices */ prt("(a) Teleport to a specific place.", 4, 5); prt("(b) Fetch an item.", 5, 5); - prt("(c) Go up 50'", 6, 5); - prt("(d) Go down 50'", 7, 5); + prt("(c) Go up one level", 6, 5); + prt("(d) Go down one level", 7, 5); /* Prompt */ prt("Command: ", 9, 0); @@ -4397,7 +3939,7 @@ void do_cmd_immovable_special(void) if (!get_aim_dir(&dir)) return; fetch(dir, p_ptr->lev * 15, FALSE); - py_pickup_floor(always_pickup); + py_pickup_floor(options->always_pickup); did_act = TRUE; break; @@ -4529,8 +4071,10 @@ static void do_cmd_sacrifice_aule() * Handle sacrifices. * Grace is increased by value of sacrifice. */ -void do_cmd_sacrifice(void) +void do_cmd_sacrifice() { + auto const &r_info = game->edit_data.r_info; + byte on_what = cave[p_ptr->py][p_ptr->px].feat; /* Check valididty */ @@ -4753,6 +4297,8 @@ std::vector<s16b> show_monster_inven(int m_idx) */ void do_cmd_steal() { + auto const &r_info = game->edit_data.r_info; + int dir = 0, item = -1, k = -1; bool_ done = FALSE; @@ -4780,7 +4326,7 @@ void do_cmd_steal() } /* The monster is immune */ - if (r_info[m_ptr->r_idx].flags7 & (RF7_NO_THEFT)) + if (r_info[m_ptr->r_idx].flags & RF_NO_THEFT) { msg_print("The monster is guarding the treasures."); return; @@ -4883,7 +4429,7 @@ void do_cmd_steal() m_ptr->hold_o_idxs.erase(m_ptr->hold_o_idxs.begin() + k); /* Rogues gain some xp */ - if (race_flags1_p(PR1_EASE_STEAL)) + if (race_flags_p(PR_EASE_STEAL)) { s32b max_point; diff --git a/src/cmd2.hpp b/src/cmd2.hpp index 142238ab..9641dc72 100644 --- a/src/cmd2.hpp +++ b/src/cmd2.hpp @@ -4,30 +4,29 @@ #include "object_type_fwd.hpp" #include <vector> -extern std::vector<s16b> show_monster_inven(int m_idx); -extern int breakage_chance(object_type *o_ptr); -extern void do_cmd_go_up(void); -extern void do_cmd_go_down(void); -extern void do_cmd_search(void); -extern void do_cmd_toggle_search(void); -extern void do_cmd_open(void); -extern void do_cmd_close(void); -extern void do_cmd_chat(void); -extern void do_cmd_give(void); -extern void do_cmd_tunnel(void); -extern void do_cmd_disarm(void); -extern void do_cmd_bash(void); -extern void do_cmd_alter(void); -extern void do_cmd_spike(void); -extern void do_cmd_walk(int pickup, bool_ disarm); -extern void do_cmd_stay(int pickup); -extern void do_cmd_run(void); -extern void do_cmd_rest(void); -extern int get_shooter_mult(object_type *o_ptr); -extern void do_cmd_fire(void); -extern void do_cmd_throw(void); -extern void do_cmd_boomerang(void); -extern void do_cmd_immovable_special(void); -extern void fetch(int dir, int wgt, bool_ require_los); -extern void do_cmd_sacrifice(void); -extern void do_cmd_steal(void); +std::vector<s16b> show_monster_inven(int m_idx); +int breakage_chance(object_type *o_ptr); +void do_cmd_go_up(); +void do_cmd_go_down(); +void do_cmd_search(); +void do_cmd_toggle_search(); +void do_cmd_open(); +void do_cmd_close(); +void do_cmd_chat(); +void do_cmd_give(); +void do_cmd_tunnel(); +void do_cmd_bash(); +void do_cmd_alter(); +void do_cmd_spike(); +void do_cmd_walk(int pickup); +void do_cmd_stay(int pickup); +void do_cmd_run(); +void do_cmd_rest(); +int get_shooter_mult(object_type *o_ptr); +void do_cmd_fire(); +void do_cmd_throw(); +void do_cmd_boomerang(); +void do_cmd_immovable_special(); +void fetch(int dir, int wgt, bool_ require_los); +void do_cmd_sacrifice(); +void do_cmd_steal(); diff --git a/src/cmd3.cc b/src/cmd3.cc index 59e61719..cbf58820 100644 --- a/src/cmd3.cc +++ b/src/cmd3.cc @@ -12,19 +12,21 @@ #include "cave_type.hpp" #include "cli_comm.hpp" #include "files.hpp" +#include "game.hpp" #include "gods.hpp" #include "hook_drop_in.hpp" #include "hook_wield_in.hpp" #include "hooks.hpp" #include "monster1.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_flag.hpp" #include "object_kind.hpp" #include "object_type.hpp" #include "options.hpp" #include "player_type.hpp" -#include "quark.hpp" #include "squeltch.hpp" #include "store.hpp" #include "store_type.hpp" @@ -40,13 +42,14 @@ #include <cassert> #include <algorithm> +#include <fmt/format.h> #include <memory> #include <utility> /* * Display p_ptr->inventory */ -void do_cmd_inven(void) +void do_cmd_inven() { char out_val[160]; @@ -101,7 +104,7 @@ void do_cmd_inven(void) /* * Display equipment */ -void do_cmd_equip(void) +void do_cmd_equip() { char out_val[160]; @@ -159,28 +162,18 @@ void do_cmd_equip(void) */ static bool item_tester_hook_wear(object_type const *o_ptr) { - u32b f1, f2, f3, f4, f5, esp; int slot = wield_slot(o_ptr); - - /* Extract the flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); - /* Only one ultimate at a time */ - if (f4 & TR4_ULTIMATE) + if (object_flags(o_ptr) & TR_ULTIMATE) { - int i; - - for (i = INVEN_WIELD; i < INVEN_TOTAL; i++) + for (int i = INVEN_WIELD; i < INVEN_TOTAL; i++) { object_type *q_ptr = &p_ptr->inventory[i]; - /* Extract the flags */ - object_flags(q_ptr, &f1, &f2, &f3, &f4, &f5, &esp); - if (!q_ptr->k_idx) continue; - if (f4 & TR4_ULTIMATE) return (FALSE); + if (object_flags(q_ptr) & TR_ULTIMATE) return (FALSE); } } @@ -211,8 +204,10 @@ bool_ is_slot_ok(int slot) /* * Wield or wear a single item from the pack or floor */ -void do_cmd_wield(void) +void do_cmd_wield() { + auto const &a_info = game->edit_data.a_info; + int item, slot, num = 1; object_type forge; @@ -225,9 +220,6 @@ void do_cmd_wield(void) char o_name[80]; - u32b f1, f2, f3, f4, f5, esp; - - /* Get an item */ if (!get_item(&item, "Wear/Wield which item? ", @@ -258,7 +250,7 @@ void do_cmd_wield(void) return; } - if ((cursed_p(o_ptr)) && (wear_confirm) + if ((cursed_p(o_ptr)) && (options->wear_confirm) && (object_known_p(o_ptr) || (o_ptr->ident & (IDENT_SENSE)))) { char dummy[512]; @@ -281,11 +273,11 @@ void do_cmd_wield(void) } /* Extract the flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Two handed weapons can't be wielded with a shield */ if ((is_slot_ok(slot - INVEN_WIELD + INVEN_ARM)) && - (f4 & TR4_MUST2H) && + (flags & TR_MUST2H) && (p_ptr->inventory[slot - INVEN_WIELD + INVEN_ARM].k_idx != 0)) { object_desc(o_name, o_ptr, FALSE, 0); @@ -298,10 +290,10 @@ void do_cmd_wield(void) i_ptr = &p_ptr->inventory[slot - INVEN_ARM + INVEN_WIELD]; /* Extract the flags */ - object_flags(i_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const i_flags = object_flags(i_ptr); /* Prevent shield from being put on if wielding 2H */ - if ((f4 & TR4_MUST2H) && (i_ptr->k_idx) && + if ((i_flags & TR_MUST2H) && (i_ptr->k_idx) && (p_ptr->body_parts[slot - INVEN_WIELD] == INVEN_ARM)) { object_desc(o_name, o_ptr, FALSE, 0); @@ -310,7 +302,7 @@ void do_cmd_wield(void) } if ((p_ptr->body_parts[slot - INVEN_WIELD] == INVEN_ARM) && - (f4 & TR4_COULD2H)) + (i_flags & TR_COULD2H)) { if (!get_check("Are you sure you want to restrict your fighting? ")) { @@ -319,13 +311,9 @@ void do_cmd_wield(void) } } - - /* Extract the flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); - if ((is_slot_ok(slot - INVEN_WIELD + INVEN_ARM)) && (p_ptr->inventory[slot - INVEN_WIELD + INVEN_ARM].k_idx != 0) && - (f4 & TR4_COULD2H)) + (flags & TR_COULD2H)) { if (!get_check("Are you sure you want to use this weapon with a shield?")) { @@ -359,7 +347,7 @@ void do_cmd_wield(void) if (o_ptr->k_idx) { /* Take off existing item */ - (void)inven_takeoff(slot, 255, FALSE); + inven_takeoff(slot, 255, FALSE); } } else @@ -369,7 +357,7 @@ void do_cmd_wield(void) if (!object_similar(o_ptr, q_ptr)) { /* Take off existing item */ - (void)inven_takeoff(slot, 255, FALSE); + inven_takeoff(slot, 255, FALSE); } else { @@ -461,7 +449,7 @@ void do_cmd_wield(void) /* * Take off an item */ -void do_cmd_takeoff(void) +void do_cmd_takeoff() { /* Get an item */ int item; @@ -491,7 +479,7 @@ void do_cmd_takeoff(void) energy_use = 50; /* Take off the item */ - (void)inven_takeoff(item, 255, FALSE); + inven_takeoff(item, 255, FALSE); /* Recalculate hitpoint */ p_ptr->update |= (PU_HP); @@ -503,7 +491,7 @@ void do_cmd_takeoff(void) /* * Drop an item */ -void do_cmd_drop(void) +void do_cmd_drop() { /* Get an item */ int item; @@ -517,8 +505,7 @@ void do_cmd_drop(void) /* Get the item */ object_type *o_ptr = get_object(item); - u32b f1, f2, f3, f4, f5, esp; - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Can we drop */ struct hook_drop_in in = { item }; @@ -537,7 +524,7 @@ void do_cmd_drop(void) } else { - if (f4 & TR4_CURSE_NO_DROP) + if (flags & TR_CURSE_NO_DROP) { /* Oops */ msg_print("Hmmm, you seem to be unable to drop it."); @@ -570,8 +557,10 @@ void do_cmd_drop(void) /* * Destroy an item */ -void do_cmd_destroy(void) +void do_cmd_destroy() { + auto const &k_info = game->edit_data.k_info; + int old_number; bool_ force = FALSE; @@ -626,10 +615,8 @@ void do_cmd_destroy(void) /* Take no time, just like the automatizer */ energy_use = 0; - u32b f1, f2, f3, f4, f5, esp; - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); - - if ((f4 & TR4_CURSE_NO_DROP) && cursed_p(o_ptr)) + auto const flags = object_flags(o_ptr); + if ((flags & TR_CURSE_NO_DROP) && cursed_p(o_ptr)) { /* Oops */ msg_print("Hmmm, you seem to be unable to destroy it."); @@ -640,7 +627,7 @@ void do_cmd_destroy(void) /* Artifacts cannot be destroyed */ - if (artifact_p(o_ptr) || o_ptr->art_name) + if (artifact_p(o_ptr)) { byte feel = SENSE_SPECIAL; @@ -670,7 +657,6 @@ void do_cmd_destroy(void) /* Message */ msg_format("You destroy %s.", o_name); - sound(SOUND_DESTITEM); /* Create an automatizer rule */ if (automatizer_create) @@ -689,8 +675,10 @@ void do_cmd_destroy(void) } /* Eru wont be happy */ - if (f3 & TR3_BLESSED) + if (flags & TR_BLESSED) + { inc_piety(GOD_ERU, -10 * k_info[o_ptr->k_idx].level); + } /* Eliminate the item */ inc_stack_size(item, -amt); @@ -700,7 +688,7 @@ void do_cmd_destroy(void) /* * Observe an item which has been *identify*-ed */ -void do_cmd_observe(void) +void do_cmd_observe() { /* Get an item */ int item; @@ -732,7 +720,7 @@ void do_cmd_observe(void) * Remove the inscription from an object * XXX Mention item (when done)? */ -void do_cmd_uninscribe(void) +void do_cmd_uninscribe() { /* Get an item */ int item; @@ -748,7 +736,7 @@ void do_cmd_uninscribe(void) object_type *o_ptr = get_object(item); /* Nothing to remove */ - if (!o_ptr->note) + if (o_ptr->inscription.empty()) { msg_print("That item had no inscription to remove."); return; @@ -758,7 +746,7 @@ void do_cmd_uninscribe(void) msg_print("Inscription removed."); /* Remove the incription */ - o_ptr->note = 0; + o_ptr->inscription.clear(); /* Combine the pack */ p_ptr->notice |= (PN_COMBINE); @@ -771,7 +759,7 @@ void do_cmd_uninscribe(void) /* * Inscribe an object with a comment */ -void do_cmd_inscribe(void) +void do_cmd_inscribe() { /* Get an item */ int item; @@ -794,22 +782,15 @@ void do_cmd_inscribe(void) msg_format("Inscribing %s.", o_name); msg_print(NULL); - /* Start with nothing */ + /* Start with old inscription */ char out_val[80]; - strcpy(out_val, ""); - - /* Use old inscription */ - if (o_ptr->note) - { - /* Start with the old inscription */ - strcpy(out_val, quark_str(o_ptr->note)); - } + strcpy(out_val, o_ptr->inscription.c_str()); /* Get a new inscription (possibly empty) */ if (get_string("Inscription: ", out_val, sizeof(out_val))) { /* Save the inscription */ - o_ptr->note = quark_add(out_val); + o_ptr->inscription = out_val; /* Combine the pack */ p_ptr->notice |= (PN_COMBINE); @@ -839,7 +820,7 @@ static object_filter_t const &item_tester_refill_lantern() /* * Refill the players lamp (from the pack or floor) */ -static void do_cmd_refill_lamp(void) +static void do_cmd_refill_lamp() { /* Get an item */ int item; @@ -902,7 +883,7 @@ static object_filter_t const &item_tester_refill_torch() /* * Refuel the players torch (from the pack or floor) */ -static void do_cmd_refill_torch(void) +static void do_cmd_refill_torch() { /* Get an item */ int item; @@ -954,15 +935,10 @@ static void do_cmd_refill_torch(void) /* * Refill the players lamp, or restock his torches */ -void do_cmd_refill(void) +void do_cmd_refill() { - object_type *o_ptr; - - u32b f1, f2, f3, f4, f5, esp; - - /* Get the light */ - o_ptr = &p_ptr->inventory[INVEN_LITE]; + auto o_ptr = &p_ptr->inventory[INVEN_LITE]; /* It is nothing */ if (o_ptr->tval != TV_LITE) @@ -971,9 +947,9 @@ void do_cmd_refill(void) return; } - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); - if (f4 & TR4_FUEL_LITE) + if (flags & TR_FUEL_LITE) { /* It's a torch */ if (o_ptr->sval == SV_LITE_TORCH || @@ -1002,7 +978,7 @@ void do_cmd_refill(void) /* * Target command */ -void do_cmd_target(void) +void do_cmd_target() { /* Target set */ if (target_set(TARGET_KILL)) @@ -1022,7 +998,7 @@ void do_cmd_target(void) /* * Look command */ -void do_cmd_look(void) +void do_cmd_look() { /* Look around */ if (target_set(TARGET_LOOK)) @@ -1036,7 +1012,7 @@ void do_cmd_look(void) /* * Allow the player to examine other sectors on the map */ -void do_cmd_locate(void) +void do_cmd_locate() { int dir, y1, x1, y2, x2; int panel_hgt, panel_wid; @@ -1249,6 +1225,8 @@ static cptr ident_info[] = */ static bool compare_monster_experience(int w1, int w2) { + auto const &r_info = game->edit_data.r_info; + /* Extract experience */ s32b z1 = r_info[w1].mexp; s32b z2 = r_info[w2].mexp; @@ -1266,6 +1244,8 @@ static bool compare_monster_experience(int w1, int w2) */ static bool compare_monster_level(int w1, int w2) { + auto const &r_info = game->edit_data.r_info; + /* Extract levels */ byte z1 = r_info[w1].level; byte z2 = r_info[w2].level; @@ -1278,28 +1258,13 @@ static bool compare_monster_level(int w1, int w2) return compare_monster_experience(w1, w2); } -/** - * Sort by total number of kills - */ -static bool compare_total_kills(int w1, int w2) -{ - /* Extract total kills */ - s16b z1 = r_info[w1].r_tkills; - s16b z2 = r_info[w2].r_tkills; - - /* Compare total kills */ - if (z1 < z2) return true; - if (z1 > z2) return false; - - /* Punt to monster level. */ - return compare_monster_level(w1, w2); -} - /* * Sort by player kills */ static bool compare_player_kills(int w1, int w2) { + auto const &r_info = game->edit_data.r_info; + /* Extract player kills */ s16b z1 = r_info[w1].r_pkills; s16b z2 = r_info[w2].r_pkills; @@ -1308,8 +1273,8 @@ static bool compare_player_kills(int w1, int w2) if (z1 < z2) return true; if (z1 > z2) return false; - /* Punt to total number of kills. */ - return compare_total_kills(w1, w2); + /* Punt to monster level. */ + return compare_monster_level(w1, w2); } @@ -1318,7 +1283,9 @@ static bool compare_player_kills(int w1, int w2) */ static void roff_top(int r_idx) { - monster_race *r_ptr = &r_info[r_idx]; + auto const &r_info = game->edit_data.r_info; + + auto r_ptr = &r_info[r_idx]; byte a1, a2; @@ -1341,7 +1308,7 @@ static void roff_top(int r_idx) Term_gotoxy(0, 0); /* A title (use "The" for non-uniques) */ - if (!(r_ptr->flags1 & (RF1_UNIQUE))) + if (!(r_ptr->flags & RF_UNIQUE)) { Term_addstr( -1, TERM_WHITE, "The "); } @@ -1374,9 +1341,9 @@ static void roff_top(int r_idx) * * Note that the player ghosts are ignored. XXX XXX XXX */ -void do_cmd_query_symbol(void) +void do_cmd_query_symbol() { - int i, r_idx; + auto const &r_info = game->edit_data.r_info; char sym, query; @@ -1404,6 +1371,7 @@ void do_cmd_query_symbol(void) "or (Ctrl-A, Ctrl-U, Ctrl-N, Ctrl-M):", &sym)) return; /* Find that character info, and describe it */ + std::size_t i; for (i = 0; ident_info[i]; ++i) { if (sym == ident_info[i][0]) break; @@ -1445,19 +1413,16 @@ void do_cmd_query_symbol(void) prt(buf, 0, 0); /* Collect matching monsters */ - std::vector<u16b> who; - for (i = 1; i < max_r_idx; i++) + std::vector<std::size_t> who; + for (std::size_t i = 1; i < r_info.size(); i++) { - monster_race *r_ptr = &r_info[i]; - - /* Nothing to recall */ - if (!cheat_know && !r_ptr->r_sights) continue; + auto r_ptr = &r_info[i]; /* Require non-unique monsters if needed */ - if (norm && (r_ptr->flags1 & (RF1_UNIQUE))) continue; + if (norm && (r_ptr->flags & RF_UNIQUE)) continue; /* Require unique monsters if needed */ - if (uniq && !(r_ptr->flags1 & (RF1_UNIQUE))) continue; + if (uniq && !(r_ptr->flags & RF_UNIQUE)) continue; /* Require monsters with the name requested if needed */ if (name) @@ -1529,7 +1494,7 @@ void do_cmd_query_symbol(void) while (1) { /* Extract a race */ - r_idx = who[i]; + auto r_idx = who[i]; /* Hack -- Auto-recall */ monster_race_track(r_idx, 0); @@ -1554,7 +1519,7 @@ void do_cmd_query_symbol(void) Term_save(); /* Recall on screen */ - screen_roff(who[i], 0, 0); + screen_roff(who[i], 0); /* Hack -- Complete the prompt (again) */ Term_addstr( -1, TERM_WHITE, " [(r)ecall, ESC]"); @@ -1608,206 +1573,6 @@ void do_cmd_query_symbol(void) /* - * research_mon - * -KMW- - */ -bool_ research_mon() -{ - int i, r_idx; - - char sym, query; - - char buf[128]; - - - s16b oldkills; - - byte oldwake; - - bool_ oldcheat; - - - bool_ all = FALSE; - - bool_ uniq = FALSE; - - bool_ norm = FALSE; - - bool_ notpicked; - - - bool_ recall = FALSE; - - monster_race *r2_ptr; - - /* Hack -- Remember "cheat_know" flag */ - oldcheat = cheat_know; - - - /* Get a character, or abort */ - if (!get_com("Enter character of monster: ", &sym)) return (TRUE); - - /* Find that character info, and describe it */ - for (i = 0; ident_info[i]; ++i) - { - if (sym == ident_info[i][0]) break; - } - - if (ident_info[i]) - { - strnfmt(buf, 128, "%c - %s.", sym, ident_info[i] + 2); - } - else - { - strnfmt(buf, 128, "%c - %s.", sym, "Unknown Symbol"); - } - - /* Display the result */ - prt(buf, 16, 10); - - - /* Collect matching monsters */ - std::vector<u16b> who; - for (i = 1; i < max_r_idx; i++) - { - monster_race *r_ptr = &r_info[i]; - - /* Hack -- Force "cheat_know" */ - cheat_know = TRUE; - - /* Nothing to recall */ - if (!cheat_know && !r_ptr->r_sights) continue; - - /* Require non-unique monsters if needed */ - if (norm && (r_ptr->flags1 & (RF1_UNIQUE))) continue; - - /* Require unique monsters if needed */ - if (uniq && !(r_ptr->flags1 & (RF1_UNIQUE))) continue; - - /* Collect "appropriate" monsters */ - if (all || (r_ptr->d_char == sym)) { - who.push_back(i); - } - } - - /* Nothing to recall */ - if (who.empty()) - { - /* Restore the "cheat_know" flag */ - cheat_know = oldcheat; - - return (TRUE); - } - - - query = 'y'; - - /* Sort by level */ - std::sort(std::begin(who), std::end(who), compare_monster_level); - - - /* Start at the end */ - i = who.size() - 1; - - notpicked = TRUE; - - /* Scan the monster memory */ - while (notpicked) - { - /* Extract a race */ - r_idx = who[i]; - - /* Hack -- Auto-recall */ - monster_race_track(r_idx, 0); - - /* Hack -- Handle stuff */ - handle_stuff(); - - /* Hack -- Begin the prompt */ - roff_top(r_idx); - - /* Hack -- Complete the prompt */ - Term_addstr( -1, TERM_WHITE, " [(r)ecall, ESC, space to continue]"); - - /* Interact */ - while (1) - { - /* Recall */ - if (recall) - { - /* Save the screen */ - character_icky = TRUE; - Term_save(); - - /* Recall on screen */ - r2_ptr = &r_info[r_idx]; - - oldkills = r2_ptr->r_tkills; - oldwake = r2_ptr->r_wake; - screen_roff(who[i], 0, 1); - r2_ptr->r_tkills = oldkills; - r2_ptr->r_wake = oldwake; - r2_ptr->r_sights = 1; - cheat_know = oldcheat; - notpicked = FALSE; - break; - - } - - /* Command */ - query = inkey(); - - /* Unrecall */ - if (recall) - { - /* Restore */ - Term_load(); - character_icky = FALSE; - } - - /* Normal commands */ - if (query != 'r') break; - - /* Toggle recall */ - recall = !recall; - } - - /* Stop scanning */ - if (query == ESCAPE) break; - - /* Move to "prev" monster */ - if (query == '-') - { - i++; - assert(i >= 0); - if (static_cast<size_t>(i) == who.size()) - { - i = 0; - } - } - - /* Move to "next" monster */ - else - { - if (i-- == 0) - { - i = who.size() - 1; - } - } - } - - - /* Re-display the identity */ - /* prt(buf, 5, 5);*/ - - /* Restore the "cheat_know" flag */ - cheat_know = oldcheat; - - return (notpicked); -} - - -/* * Try to "sense" the grid's mana */ bool_ do_cmd_sense_grid_mana() @@ -1836,9 +1601,8 @@ bool_ do_cmd_sense_grid_mana() /* Roll for usage */ if ((chance < USE_DEVICE) || (randint(chance) < USE_DEVICE)) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("You failed to sense the grid's mana."); - sound(SOUND_FAIL); return FALSE; } @@ -1976,7 +1740,7 @@ static bool_ get_string_cli(cptr prompt, char *buf, int len) * * See defines.h for a list of the codes used. */ -void do_cmd_cli(void) +void do_cmd_cli() { char buff[80]; @@ -2009,33 +1773,23 @@ void do_cmd_cli(void) */ void do_cmd_cli_help() { - int i, j; - - FILE *fff; - - char file_name[1024]; - - - /* Temporary file */ - if (path_temp(file_name, 1024)) return; + fmt::MemoryWriter w; + for (int i = 0, j = -1; i < cli_total; i++) + { + if (j < i - 1) + { + w << "/"; + } - /* Open a new file */ - fff = my_fopen(file_name, "w"); + w.write("[[[[[G{}]", cli_info[i].comm); - for (i = 0, j = -1; i < cli_total; i++) - { - if (j < i - 1) fprintf(fff, "/"); - fprintf(fff, "[[[[[G%s]", cli_info[i].comm); if (cli_info[i].descrip != cli_info[i + 1].descrip) { - fprintf(fff, " %s\n", cli_info[i].descrip); + w.write(" {}\n", cli_info[i].descrip); j = i; } } - /* Close the file */ - my_fclose(fff); - /* Enter "icky" mode */ character_icky = TRUE; @@ -2043,16 +1797,13 @@ void do_cmd_cli_help() Term_save(); /* Display the file contents */ - show_file(file_name, "Command line help", 0, 0); + show_string(w.c_str(), "Command line help"); /* Restore the screen */ Term_load(); /* Leave "icky" mode */ character_icky = FALSE; - - /* Remove the file */ - fd_kill(file_name); } diff --git a/src/cmd3.hpp b/src/cmd3.hpp index 48677b77..97d3e22f 100644 --- a/src/cmd3.hpp +++ b/src/cmd3.hpp @@ -2,23 +2,22 @@ #include "h-basic.h" -extern void do_cmd_html_dump(void); -extern void cli_add(cptr active, cptr trigger, cptr descr); -extern void do_cmd_cli(void); -extern void do_cmd_cli_help(void); -extern void do_cmd_inven(void); -extern void do_cmd_equip(void); -extern void do_cmd_wield(void); -extern void do_cmd_takeoff(void); -extern void do_cmd_drop(void); -extern void do_cmd_destroy(void); -extern void do_cmd_observe(void); -extern void do_cmd_uninscribe(void); -extern void do_cmd_inscribe(void); -extern void do_cmd_refill(void); -extern void do_cmd_target(void); -extern void do_cmd_look(void); -extern void do_cmd_locate(void); -extern void do_cmd_query_symbol(void); -extern bool_ do_cmd_sense_grid_mana(void); -extern bool_ research_mon(void); +void do_cmd_html_dump(); +void cli_add(cptr active, cptr trigger, cptr descr); +void do_cmd_cli(); +void do_cmd_cli_help(); +void do_cmd_inven(); +void do_cmd_equip(); +void do_cmd_wield(); +void do_cmd_takeoff(); +void do_cmd_drop(); +void do_cmd_destroy(); +void do_cmd_observe(); +void do_cmd_uninscribe(); +void do_cmd_inscribe(); +void do_cmd_refill(); +void do_cmd_target(); +void do_cmd_look(); +void do_cmd_locate(); +void do_cmd_query_symbol(); +bool_ do_cmd_sense_grid_mana(); diff --git a/src/cmd4.cc b/src/cmd4.cc index 4b6c040c..a820da41 100644 --- a/src/cmd4.cc +++ b/src/cmd4.cc @@ -10,26 +10,30 @@ #include "artifact_type.hpp" #include "cave_type.hpp" #include "corrupt.hpp" +#include "dungeon_flag.hpp" #include "dungeon_info_type.hpp" #include "feature_type.hpp" #include "files.hpp" +#include "game.hpp" #include "hooks.hpp" #include "init1.hpp" #include "levels.hpp" #include "messages.hpp" #include "monster2.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" #include "monster_type.hpp" #include "notes.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_flag.hpp" #include "object_kind.hpp" +#include "options.hpp" #include "player_type.hpp" #include "skills.hpp" #include "squeltch.hpp" #include "tables.hpp" #include "town_type.hpp" -#include "trap_type.hpp" #include "util.hpp" #include "util.h" #include "variable.h" @@ -37,11 +41,13 @@ #include "xtra1.hpp" #include "z-rand.hpp" +#include <algorithm> #include <cassert> +#include <fmt/format.h> #include <memory> +#include <numeric> #include <string> #include <vector> -#include <algorithm> /* * Hack -- redraw the screen @@ -54,7 +60,7 @@ * selecting various things, such as graphics mode, so it must call * the "TERM_XTRA_REACT" hook before redrawing the windows. */ -void do_cmd_redraw(void) +void do_cmd_redraw() { int j; @@ -125,7 +131,7 @@ void do_cmd_redraw(void) /* * Hack -- change name */ -void do_cmd_change_name(void) +void do_cmd_change_name() { char c; @@ -143,8 +149,8 @@ void do_cmd_change_name(void) /* Forever */ while (1) { - /* keep mode below 7 */ - mode = (mode + 6) % 6; + /* keep mode below 5 */ + mode = (mode + 5) % 5; /* Display the player */ display_player(mode); @@ -174,7 +180,7 @@ void do_cmd_change_name(void) /* File dump */ else if (c == 'f') { - strnfmt(tmp, 160, "%s.txt", player_name); + strnfmt(tmp, 160, "%s.txt", game->player_name.c_str()); if (get_string("Filename(you can post it to http://angband.oook.cz/): ", tmp, 80)) { if (tmp[0] && (tmp[0] != ' ')) @@ -199,11 +205,11 @@ void do_cmd_change_name(void) /* Change tactic */ if (c == 't') { - (void)do_cmd_change_tactic( -1); + do_cmd_change_tactic( -1); } else if (c == 'T') { - (void)do_cmd_change_tactic(1); + do_cmd_change_tactic(1); } /* Change movement */ @@ -247,12 +253,16 @@ void do_cmd_change_name(void) /* * Recall the most recent message */ -void do_cmd_message_one(void) +void do_cmd_message_one() { - cptr msg = format("> %s", message_str(0)); + auto const &messages = game->messages; + + auto message = messages.at(0); + + cptr msg = format("> %s", message.text_with_count().c_str()); /* Recall one message XXX XXX XXX */ - display_message(0, 0, strlen(msg), message_color(0), msg); + display_message(0, 0, strlen(msg), message.color, msg); } @@ -274,30 +284,21 @@ void do_cmd_message_one(void) * * Now taking advantages of big-screen. -pav- */ -void do_cmd_messages(void) +void do_cmd_messages() { - int i, j, k, n; - u32b q; - int wid, hgt; - - char shower[80]; - char finder[80]; - - /* Wipe finder */ - strcpy(finder, ""); - - /* Wipe shower */ - strcpy(shower, ""); + auto const &messages = game->messages; + /* String to highlight */ + std::string shower; /* Total messages */ - n = message_num(); + const int n = messages.size(); /* Start on first message */ - i = 0; + int i = 0; /* Start at leftmost edge */ - q = 0; + u32b q = 0; /* Enter "icky" mode */ character_icky = TRUE; @@ -312,35 +313,38 @@ void do_cmd_messages(void) Term_clear(); /* Retrieve current screen size */ + int wid; + int hgt; Term_get_size(&wid, &hgt); /* Dump up to 20 (or more in bigscreen) lines of messages */ + int j; for (j = 0; (j < (hgt - 4)) && (i + j < n); j++) { - cptr msg = message_str(i + j); - byte color = message_color(i + j); + auto message = messages.at(i + j); + auto text = message.text_with_count(); + auto color = message.color; /* Apply horizontal scroll */ - msg = (strlen(msg) >= q) ? (msg + q) : ""; + text = (text.size() >= q) ? text.substr(q) : ""; /* Dump the messages, bottom to top */ - display_message(0, (hgt - 3) - j, strlen(msg), color, msg); + display_message(0, (hgt - 3) - j, text.size(), color, text.c_str()); /* Hilite "shower" */ if (shower[0]) { - cptr str = msg; - + std::size_t pos = 0; /* Display matches */ - while ((str = strstr(str, shower)) != NULL) + while ((pos = text.find(shower, pos)) != std::string::npos) { - int len = strlen(shower); + std::size_t len = shower.size(); /* Display the match */ - Term_putstr(str - msg, (hgt - 3) - j, len, TERM_YELLOW, shower); + Term_putstr(pos, (hgt - 3) - j, len, TERM_YELLOW, shower.c_str()); /* Advance */ - str += len; + pos += len; } } } @@ -353,7 +357,7 @@ void do_cmd_messages(void) prt("[Press 'p' for older, 'n' for newer, ..., or ESCAPE]", hgt - 1, 0); /* Get a command */ - k = inkey(); + const auto k = inkey(); /* Exit on Escape */ if (k == ESCAPE) break; @@ -388,7 +392,10 @@ void do_cmd_messages(void) prt("Show: ", hgt - 1, 0); /* Get a "shower" string, or continue */ - if (!askfor_aux(shower, 80)) continue; + if (!askfor_aux(&shower, 80)) + { + continue; + } /* Okay */ continue; @@ -403,18 +410,22 @@ void do_cmd_messages(void) prt("Find: ", hgt - 1, 0); /* Get a "finder" string, or continue */ - if (!askfor_aux(finder, 80)) continue; + auto finder = shower; + if (!askfor_aux(&finder, 80)) + { + continue; + } /* Show it */ - strcpy(shower, finder); + shower = finder; /* Scan messages */ for (z = i + 1; z < n; z++) { - cptr msg = message_str(z); + auto message = messages.at(z); /* Search for it */ - if (strstr(msg, finder)) + if (message.text_with_count().find(finder) != std::string::npos) { /* New location */ i = z; @@ -494,7 +505,7 @@ namespace { /** * Interact with given vector of options. */ -static void interact_with_options(std::vector<option_type *> const &options, char const *info, interaction_mode_t interaction_mode) +static void interact_with_options(std::vector<option_type> const &options, char const *info, interaction_mode_t interaction_mode) { size_t n = options.size(); @@ -522,9 +533,9 @@ static void interact_with_options(std::vector<option_type *> const &options, cha /* Display the option text */ strnfmt(buf, 80, "%-48s: %s (%s)", - options[i]->o_desc, - (*options[i]->o_var ? "yes" : "no "), - options[i]->o_text); + options[i].o_desc, + (*options[i].o_var) ? "yes" : "no ", + options[i].o_text); c_prt(a, buf, i + 2, 0); } @@ -580,7 +591,7 @@ static void interact_with_options(std::vector<option_type *> const &options, cha { break; } - *(options[k]->o_var) = TRUE; + *(options[k].o_var) = TRUE; k = (k + 1) % n; break; } @@ -594,7 +605,7 @@ static void interact_with_options(std::vector<option_type *> const &options, cha break; } - *(options[k]->o_var) = FALSE; + *(options[k].o_var) = FALSE; k = (k + 1) % n; break; } @@ -614,56 +625,26 @@ static void interact_with_options(std::vector<option_type *> const &options, cha /* - * Cheating options - */ -static option_type cheat_info[6] = -{ - { &cheat_peek, FALSE, 0, 0, "cheat_peek", "Peek into object creation" }, - { &cheat_hear, FALSE, 0, 1, "cheat_hear", "Peek into monster creation" }, - { &cheat_room, FALSE, 0, 2, "cheat_room", "Peek into dungeon creation" }, - { &cheat_xtra, FALSE, 0, 3, "cheat_xtra", "Peek into something else" }, - { &cheat_know, FALSE, 0, 4, "cheat_know", "Know complete monster info" }, - { &cheat_live, FALSE, 0, 5, "cheat_live", "Allow player to avoid death" } -}; - -/* * Interact with some options for cheating */ static void do_cmd_options_cheat(cptr info) { - // Calculate number of cheat options - size_t n = std::distance(std::begin(cheat_info), std::end(cheat_info)); - - // Build the vector of options we're going to interact with - std::vector<option_type *> options; - options.reserve(n); - for (auto &option : cheat_info) - { - options.push_back(&option); - } - // Interact - interact_with_options(options, info, interaction_mode_t::READ_WRITE); + interact_with_options(options->cheat_options, info, interaction_mode_t::READ_WRITE); // If user toggled any of the options to TRUE, then we add those cheats // to the player's "noscore" flags. Note that it doesn't matter what the // previous value was -- we don't "unset" noscore flags anyway. - for (auto &option: options) + for (auto const &option: options->cheat_options) { - if (*option->o_var) + if (*option.o_var) { - noscore |= (option->o_page * 256 + option->o_bit); + noscore |= (option.o_page * 256 + option.o_bit); } } } -static option_type autosave_info[2] = -{ - { &autosave_l, FALSE, 0, 6, "autosave_l", "Autosave when entering new levels" }, - { &autosave_t, FALSE, 0, 7, "autosave_t", "Timed autosave" }, -}; - s16b toggle_frequency(s16b current) { if (current == 0) return (50); @@ -687,7 +668,9 @@ static void do_cmd_options_autosave(cptr info) { char ch; - int i, k = 0, n = 2; + int i, k = 0; + + int n = options->autosave_options.size(); int dir; @@ -714,15 +697,18 @@ static void do_cmd_options_autosave(cptr info) /* Color current option */ if (i == k) a = TERM_L_BLUE; + /* Get the option */ + auto const option = &options->autosave_options[i]; + /* Display the option text */ strnfmt(buf, 80, "%-48s: %s (%s)", - autosave_info[i].o_desc, - (*autosave_info[i].o_var ? "yes" : "no "), - autosave_info[i].o_text); + option->o_desc, + (*option->o_var) ? "yes" : "no ", + option->o_text); c_prt(a, buf, i + 2, 0); } - prt(format("Timed autosave frequency: every %d turns", autosave_freq), 5, 0); + prt(format("Timed autosave frequency: every %d turns", options->autosave_freq), 5, 0); /* Hilite current option */ @@ -768,8 +754,7 @@ static void do_cmd_options_autosave(cptr info) case 'Y': case '6': { - - (*autosave_info[k].o_var) = TRUE; + (*options->autosave_options[k].o_var) = TRUE; k = (k + 1) % n; break; @@ -779,7 +764,7 @@ static void do_cmd_options_autosave(cptr info) case 'N': case '4': { - (*autosave_info[k].o_var) = FALSE; + (*options->autosave_options[k].o_var) = FALSE; k = (k + 1) % n; break; @@ -788,9 +773,9 @@ static void do_cmd_options_autosave(cptr info) case 'f': case 'F': { - autosave_freq = toggle_frequency(autosave_freq); - prt(format("Timed autosave frequency: every %d turns", - autosave_freq), 5, 0); + options->autosave_freq = toggle_frequency(options->autosave_freq); + prt(fmt::format("Timed autosave frequency: every {} turns", + options->autosave_freq), 5, 0); break; } @@ -811,28 +796,29 @@ static void do_cmd_options_autosave(cptr info) void do_cmd_options_aux(int page, cptr info, bool_ read_only) { // Scrape together all the options from the relevant page. - std::vector<option_type *> options; - options.reserve(64); // Seems a reasonable number; anything more would be unusable anyway - for (size_t i = 0; option_info[i].o_desc; i++) - { - if (option_info[i].o_page == page) - { - options.push_back(&option_info[i]); - } - } + std::vector<option_type> page_options; + page_options.reserve(options->standard_options.size()); + std::copy_if( + std::begin(options->standard_options), + std::end(options->standard_options), + std::back_inserter(page_options), + [=](option_type const &option) -> bool { + return (option.o_page == page); + } + ); // Interact with the options interaction_mode_t interaction_mode = read_only ? interaction_mode_t::READ_ONLY : interaction_mode_t::READ_WRITE; - interact_with_options(options, info, interaction_mode); + interact_with_options(page_options, info, interaction_mode); } /* * Modify the "window" options */ -static void do_cmd_options_win(void) +static void do_cmd_options_win() { int i, j, d; @@ -848,7 +834,7 @@ static void do_cmd_options_win(void) /* Memorize old flags */ - for (j = 0; j < 8; j++) + for (j = 0; j < ANGBAND_TERM_MAX; j++) { /* Acquire current flags */ old_flag[j] = window_flag[j]; @@ -865,7 +851,7 @@ static void do_cmd_options_win(void) prt("Window Flags (<dir>, t, y, n, ESC) ", 0, 0); /* Display the windows */ - for (j = 0; j < 8; j++) + for (j = 0; j < ANGBAND_TERM_MAX; j++) { byte a = TERM_WHITE; @@ -895,7 +881,7 @@ static void do_cmd_options_win(void) Term_putstr(0, i + 5, -1, a, str); /* Display the windows */ - for (j = 0; j < 8; j++) + for (j = 0; j < ANGBAND_TERM_MAX; j++) { byte a = TERM_WHITE; @@ -932,7 +918,7 @@ static void do_cmd_options_win(void) case 't': { /* Clear windows */ - for (j = 0; j < 8; j++) + for (j = 0; j < ANGBAND_TERM_MAX; j++) { window_flag[j] &= ~(1L << y); } @@ -982,7 +968,7 @@ static void do_cmd_options_win(void) } /* Notice changes */ - for (j = 0; j < 8; j++) + for (j = 0; j < ANGBAND_TERM_MAX; j++) { term *old = Term; @@ -1037,25 +1023,25 @@ static errr option_dump(cptr fname) fprintf(fff, "# Automatic option dump\n\n"); /* Dump options (skip cheat, adult, score) */ - for (i = 0; option_info[i].o_var != NULL; i++) + for (auto const &option: options->standard_options) { /* Require a real option */ - if (!option_info[i].o_text) continue; + if (!option.o_text) continue; /* No birth options */ - if (option_info[i].o_page == 6) continue; + if (option.o_page == 6) continue; /* Comment */ - fprintf(fff, "# Option '%s'\n", option_info[i].o_desc); + fprintf(fff, "# Option '%s'\n", option.o_desc); /* Dump the option */ - if ((*option_info[i].o_var)) + if (*option.o_var) { - fprintf(fff, "Y:%s\n", option_info[i].o_text); + fprintf(fff, "Y:%s\n", option.o_text); } else { - fprintf(fff, "X:%s\n", option_info[i].o_text); + fprintf(fff, "X:%s\n", option.o_text); } /* Skip a line */ @@ -1111,9 +1097,6 @@ static errr option_dump(cptr fname) */ static void do_cmd_pref_file_hack(int row) { - char ftmp[80]; - - /* Prompt */ prt("Command: Load a user pref file", row, 0); @@ -1121,21 +1104,24 @@ static void do_cmd_pref_file_hack(int row) prt("File: ", row + 2, 0); /* Default filename */ - strnfmt(ftmp, 80, "%s.prf", player_base); + std::string ftmp = fmt::format("{}.prf", game->player_base); /* Ask for a file (or cancel) */ - if (!askfor_aux(ftmp, 80)) return; + if (!askfor_aux(&ftmp, 80)) + { + return; + } /* Process the given filename */ - if (process_pref_file(ftmp)) + if (process_pref_file(ftmp.c_str())) { /* Mention failure */ - msg_format("Failed to load '%s'!", ftmp); + msg_format("Failed to load '%s'!", ftmp.c_str()); } else { /* Mention success */ - msg_format("Loaded '%s'.", ftmp); + msg_format("Loaded '%s'.", ftmp.c_str()); } } @@ -1146,7 +1132,7 @@ static void do_cmd_pref_file_hack(int row) * The user must use the "Ctrl-R" command to "adapt" to changes * in any options which control "visual" aspects of the game. */ -void do_cmd_options(void) +void do_cmd_options() { int k; @@ -1216,8 +1202,6 @@ void do_cmd_options(void) case 'u': case 'U': { - char ftmp[80]; - /* Prompt */ prt("Command: Append options to a file", 21, 0); @@ -1225,13 +1209,13 @@ void do_cmd_options(void) prt("File: ", 21, 0); /* Default filename */ - strnfmt(ftmp, 80, "%s.prf", player_base); + auto ftmp = fmt::format("{}.prf", game->player_base); /* Ask for a file */ - if (!askfor_aux(ftmp, 80)) continue; + if (!askfor_aux(&ftmp, 80)) continue; /* Dump the options */ - if (option_dump(ftmp)) + if (option_dump(ftmp.c_str())) { /* Failure */ msg_print("Failed!"); @@ -1340,14 +1324,26 @@ void do_cmd_options(void) /* Get a new value */ while (1) { - int msec = delay_factor * delay_factor * delay_factor; - prt(format("Current base delay factor: %d (%d msec)", - delay_factor, msec), 22, 0); + auto const msec = options->delay_factor_ms(); + + prt(fmt::format("Current base delay factor: {:d} ({:d} msec)", + options->delay_factor, msec), 22, 0); prt("Delay Factor (0-9 or ESC to accept): ", 23, 0); + k = inkey(); - if (k == ESCAPE) break; - if (isdigit(k)) delay_factor = D2I(k); - else bell(); + if (k == ESCAPE) + { + break; + } + + if (isdigit(k)) + { + options->delay_factor = D2I(k); + } + else + { + bell(); + } } break; @@ -1363,13 +1359,24 @@ void do_cmd_options(void) /* Get a new value */ while (1) { - prt(format("Current hitpoint warning: %d0%%", - hitpoint_warn), 22, 0); + prt(fmt::format("Current hitpoint warning: {:d}0%", + options->hitpoint_warn), 22, 0); prt("Hitpoint Warning (0-9 or ESC to accept): ", 20, 0); + k = inkey(); - if (k == ESCAPE) break; - if (isdigit(k)) hitpoint_warn = D2I(k); - else bell(); + if (k == ESCAPE) + { + break; + } + + if (isdigit(k)) + { + options->hitpoint_warn = D2I(k); + } + else + { + bell(); + } } break; @@ -1401,7 +1408,7 @@ void do_cmd_options(void) * * XXX XXX XXX Allow absolute file names? */ -void do_cmd_pref(void) +void do_cmd_pref() { char buf[80]; @@ -1413,7 +1420,7 @@ void do_cmd_pref(void) if (!get_string("Pref: ", buf, 80)) return; /* Process that pref command */ - (void)process_pref_file_aux(buf); + process_pref_file_aux(buf); } @@ -1642,19 +1649,10 @@ static errr keymap_dump(cptr fname) * * Could use some helpful instructions on this page. XXX XXX XXX */ -void do_cmd_macros(void) +void do_cmd_macros() { - int i; - - char tmp[1024]; - - char buf[1024]; - - int mode; - - /* Keymap mode */ - mode = get_keymap_mode(); + int mode = get_keymap_mode(); /* Enter "icky" mode */ @@ -1667,6 +1665,8 @@ void do_cmd_macros(void) /* Process requests until done */ while (1) { + char buf[1024]; + /* Clear screen */ Term_clear(); @@ -1700,7 +1700,7 @@ void do_cmd_macros(void) prt("Command: ", 16, 0); /* Get a command */ - i = inkey(); + int i = inkey(); /* Leave */ if (i == ESCAPE) break; @@ -1715,13 +1715,16 @@ void do_cmd_macros(void) prt("File: ", 18, 0); /* Default filename */ - strnfmt(tmp, 1024, "%s.prf", player_name); + auto tmp = fmt::format("{}.prf", game->player_name); /* Ask for a file */ - if (!askfor_aux(tmp, 80)) continue; + if (!askfor_aux(&tmp, 80)) + { + continue; + } /* Process the given filename */ - if (0 != process_pref_file(tmp)) + if (0 != process_pref_file(tmp.c_str())) { /* Prompt */ msg_print("Could not load file!"); @@ -1738,13 +1741,16 @@ void do_cmd_macros(void) prt("File: ", 18, 0); /* Default filename */ - strnfmt(tmp, 1024, "%s.prf", player_name); + auto tmp = fmt::format("{}.prf", game->player_name); /* Ask for a file */ - if (!askfor_aux(tmp, 80)) continue; + if (!askfor_aux(&tmp, 80)) + { + continue; + } /* Dump the macros */ - (void)macro_dump(tmp); + macro_dump(tmp.c_str()); /* Prompt */ msg_print("Appended macros."); @@ -1794,6 +1800,8 @@ void do_cmd_macros(void) /* Create a macro */ else if (i == '4') { + char tmp[1024]; + /* Prompt */ prt("Command: Create a macro", 16, 0); @@ -1855,13 +1863,16 @@ void do_cmd_macros(void) prt("File: ", 18, 0); /* Default filename */ - strnfmt(tmp, 1024, "%s.prf", player_name); + auto tmp = fmt::format("{}.prf", game->player_name); /* Ask for a file */ - if (!askfor_aux(tmp, 80)) continue; + if (!askfor_aux(&tmp, 80)) + { + continue; + } /* Dump the macros */ - (void)keymap_dump(tmp); + keymap_dump(tmp.c_str()); /* Prompt */ msg_print("Appended keymaps."); @@ -1911,6 +1922,8 @@ void do_cmd_macros(void) /* Create a keymap */ else if (i == '8') { + char tmp[1024]; + /* Prompt */ prt("Command: Create a keymap", 16, 0); @@ -1967,6 +1980,8 @@ void do_cmd_macros(void) /* Enter a new action */ else if (i == '0') { + char tmp[1024]; + /* Prompt */ prt("Command: Enter a new action", 16, 0); @@ -2005,8 +2020,12 @@ void do_cmd_macros(void) /* * Interact with "visuals" */ -void do_cmd_visuals(void) +void do_cmd_visuals() { + auto &r_info = game->edit_data.r_info; + auto &f_info = game->edit_data.f_info; + auto &k_info = game->edit_data.k_info; + int i; FILE *fff; @@ -2069,7 +2088,7 @@ void do_cmd_visuals(void) if (!askfor_aux(tmp, 70)) continue; /* Process the given filename */ - (void)process_pref_file(tmp); + process_pref_file(tmp); } /* Dump monster attr/chars */ @@ -2101,9 +2120,9 @@ void do_cmd_visuals(void) fprintf(fff, "# Monster attr/char definitions\n\n"); /* Dump monsters */ - for (i = 0; i < max_r_idx; i++) + for (std::size_t i = 0; i < r_info.size(); i++) { - monster_race *r_ptr = &r_info[i]; + auto r_ptr = &r_info[i]; /* Skip non-entries */ if (!r_ptr->name) continue; @@ -2112,7 +2131,7 @@ void do_cmd_visuals(void) fprintf(fff, "# %s\n", r_ptr->name); /* Dump the monster attr/char info */ - fprintf(fff, "R:%d:0x%02X:0x%02X\n\n", i, + fprintf(fff, "R:%zu:0x%02X:0x%02X\n\n", i, static_cast<unsigned int>(r_ptr->x_attr), static_cast<unsigned int>(r_ptr->x_char)); } @@ -2156,9 +2175,9 @@ void do_cmd_visuals(void) fprintf(fff, "# Object attr/char definitions\n\n"); /* Dump objects */ - for (i = 0; i < max_k_idx; i++) + for (std::size_t k = 0; k < k_info.size(); k++) { - object_kind *k_ptr = &k_info[i]; + object_kind *k_ptr = &k_info[k]; /* Skip non-entries */ if (!k_ptr->name) continue; @@ -2167,7 +2186,7 @@ void do_cmd_visuals(void) fprintf(fff, "# %s\n", k_ptr->name); /* Dump the object attr/char info */ - fprintf(fff, "K:%d:0x%02X:0x%02X\n\n", i, + fprintf(fff, "K:%zu:0x%02X:0x%02X\n\n", k, (byte)(k_ptr->x_attr), (byte)(k_ptr->x_char)); } @@ -2210,9 +2229,9 @@ void do_cmd_visuals(void) fprintf(fff, "# Feature attr/char definitions\n\n"); /* Dump features */ - for (i = 0; i < max_f_idx; i++) + for (std::size_t f_idx = 0; f_idx < f_info.size(); f_idx++) { - feature_type *f_ptr = &f_info[i]; + auto f_ptr = &f_info[f_idx]; /* Skip non-entries */ if (!f_ptr->name) continue; @@ -2221,7 +2240,7 @@ void do_cmd_visuals(void) fprintf(fff, "# %s\n", f_ptr->name); /* Dump the feature attr/char info */ - fprintf(fff, "F:%d:0x%02X:0x%02X\n\n", i, + fprintf(fff, "F:%zu:0x%02X:0x%02X\n\n", f_idx, (byte)(f_ptr->x_attr), (byte)(f_ptr->x_char)); } @@ -2246,7 +2265,7 @@ void do_cmd_visuals(void) /* Hack -- query until done */ while (1) { - monster_race *r_ptr = &r_info[r]; + auto r_ptr = &r_info[r]; byte da = (r_ptr->d_attr); char dc = (r_ptr->d_char); @@ -2281,8 +2300,8 @@ void do_cmd_visuals(void) if (i == ESCAPE) break; /* Analyze */ - if (i == 'n') r = (r + max_r_idx + 1) % max_r_idx; - if (i == 'N') r = (r + max_r_idx - 1) % max_r_idx; + if (i == 'n') r = (r + r_info.size() + 1) % r_info.size(); + if (i == 'N') r = (r + r_info.size() - 1) % r_info.size(); if (i == 'a') r_ptr->x_attr = (ca + 1); if (i == 'A') r_ptr->x_attr = (ca - 1); if (i == 'c') r_ptr->x_char = (cc + 1); @@ -2336,8 +2355,8 @@ void do_cmd_visuals(void) if (i == ESCAPE) break; /* Analyze */ - if (i == 'n') k = (k + max_k_idx + 1) % max_k_idx; - if (i == 'N') k = (k + max_k_idx - 1) % max_k_idx; + if (i == 'n') k = (k + k_info.size() + 1) % k_info.size(); + if (i == 'N') k = (k + k_info.size() - 1) % k_info.size(); if (i == 'a') k_info[k].x_attr = (ca + 1); if (i == 'A') k_info[k].x_attr = (ca - 1); if (i == 'c') k_info[k].x_char = (cc + 1); @@ -2356,7 +2375,7 @@ void do_cmd_visuals(void) /* Hack -- query until done */ while (1) { - feature_type *f_ptr = &f_info[f]; + auto f_ptr = &f_info[f]; byte da = f_ptr->d_attr; char dc = f_ptr->d_char; @@ -2391,8 +2410,8 @@ void do_cmd_visuals(void) if (i == ESCAPE) break; /* Analyze */ - if (i == 'n') f = (f + max_f_idx + 1) % max_f_idx; - if (i == 'N') f = (f + max_f_idx - 1) % max_f_idx; + if (i == 'n') f = (f + f_info.size() + 1) % f_info.size(); + if (i == 'N') f = (f + f_info.size() - 1) % f_info.size(); if (i == 'a') f_info[f].x_attr = (ca + 1); if (i == 'A') f_info[f].x_attr = (ca - 1); if (i == 'c') f_info[f].x_char = (cc + 1); @@ -2437,7 +2456,7 @@ void do_cmd_visuals(void) /* * Interact with "colors" */ -void do_cmd_colors(void) +void do_cmd_colors() { int i; @@ -2494,7 +2513,7 @@ void do_cmd_colors(void) if (!askfor_aux(tmp, 70)) continue; /* Process the given filename */ - (void)process_pref_file(tmp); + process_pref_file(tmp); /* Mega-Hack -- react to changes */ Term_xtra(TERM_XTRA_REACT, 0); @@ -2659,7 +2678,7 @@ void do_cmd_colors(void) * Take notes. There are two ways this can happen, either in the message * recall or a file. */ -void do_cmd_note(void) +void do_cmd_note() { char buf[80]; @@ -2680,7 +2699,7 @@ void do_cmd_note(void) /* * Mention the current version */ -void do_cmd_version(void) +void do_cmd_version() { /* Silly message */ msg_format("You are playing %s made by %s (%s).", @@ -2714,14 +2733,16 @@ static cptr do_cmd_feeling_text[11] = * Note that "feeling" is set to zero unless some time has passed. * Note that this is done when the level is GENERATED, not entered. */ -void do_cmd_feeling(void) +void do_cmd_feeling() { + auto const &d_info = game->edit_data.d_info; + /* Verify the feeling */ if (feeling < 0) feeling = 0; if (feeling > 10) feeling = 10; /* Feeling of the fate */ - if (fate_flag && !(dungeon_flags2 & DF2_SPECIAL) && !p_ptr->inside_quest) + if (fate_flag && !(dungeon_flags & DF_SPECIAL) && !p_ptr->inside_quest) { msg_print("You feel that you will meet your fate here."); } @@ -2733,11 +2754,11 @@ void do_cmd_feeling(void) } /* No useful feeling in special levels */ - if (dungeon_flags2 & DF2_DESC) + if (dungeon_flags & DF_DESC) { char buf[1024]; - if ((get_dungeon_save(buf)) || (generate_special_feeling) || (dungeon_flags2 & DF2_DESC_ALWAYS)) + if (get_dungeon_save(buf) || game->generate_special_feeling || (dungeon_flags & DF_DESC_ALWAYS)) { if (!get_level_desc(buf)) msg_print("Someone forgot to describe this level!"); else msg_print(buf); @@ -2757,7 +2778,7 @@ void do_cmd_feeling(void) { /* This could be simplified with a correct p_ptr->town_num */ int i, town_level = 0; - dungeon_info_type *d_ptr = &d_info[dungeon_type]; + auto d_ptr = &d_info[dungeon_type]; /* Is it a town level ? */ for (i = 0; i < TOWN_DUNGEON; i++) @@ -2784,7 +2805,7 @@ static char hack[17] = "dwsorgbuDWvyRGBU"; /* * Hack -- load a screen dump from a file */ -void do_cmd_load_screen(void) +void do_cmd_load_screen() { int i, y, x; @@ -2872,7 +2893,7 @@ void do_cmd_load_screen(void) for (x = 0; x < len; x++) { /* Get the attr/char */ - (void)(Term_what(x, y, &a, &c)); + (Term_what(x, y, &a, &c)); /* Look up the attr */ for (i = 0; i < 16; i++) @@ -2908,7 +2929,7 @@ void do_cmd_load_screen(void) /* * Hack -- save a screen dump to a file */ -void do_cmd_save_screen(void) +void do_cmd_save_screen() { int y, x; int wid, hgt; @@ -2948,7 +2969,7 @@ void do_cmd_save_screen(void) for (x = 0; x < wid; x++) { /* Get the attr/char */ - (void)(Term_what(x, y, &a, &c)); + (Term_what(x, y, &a, &c)); /* Dump it */ buf[x] = c; @@ -2972,7 +2993,7 @@ void do_cmd_save_screen(void) for (x = 0; x < wid; x++) { /* Get the attr/char */ - (void)(Term_what(x, y, &a, &c)); + (Term_what(x, y, &a, &c)); /* Dump it */ buf[x] = hack[a & 0x0F]; @@ -3009,30 +3030,20 @@ void do_cmd_save_screen(void) /* * Check the status of "artifacts" */ -void do_cmd_knowledge_artifacts(void) +void do_cmd_knowledge_artifacts() { - int i, k, z, x, y; + auto const &k_info = game->edit_data.k_info; + auto const &a_info = game->edit_data.a_info; - FILE *fff; - - char file_name[1024]; + int i, z, x, y; char base_name[80]; - /* Temporary file */ - if (path_temp(file_name, 1024)) return; - - /* Open a new file */ - fff = my_fopen(file_name, "w"); - /* Scan the artifacts */ - std::unique_ptr<bool_[]> okay(new bool_[max_a_idx]); - for (k = 0; k < max_a_idx; k++) + std::vector<bool_> okay(a_info.size(), FALSE); + for (std::size_t k = 0; k < a_info.size(); k++) { - artifact_type *a_ptr = &a_info[k]; - - /* Default */ - okay[k] = FALSE; + auto a_ptr = &a_info[k]; /* Skip "empty" artifacts */ if (!a_ptr->name) continue; @@ -3044,16 +3055,13 @@ void do_cmd_knowledge_artifacts(void) okay[k] = TRUE; } - std::unique_ptr<bool_[]> okayk(new bool_[max_k_idx]); - for (k = 0; k < max_k_idx; k++) + std::vector<bool_> okayk(k_info.size(), FALSE); + for (std::size_t k = 0; k < k_info.size(); k++) { - object_kind *k_ptr = &k_info[k]; - - /* Default */ - okayk[k] = FALSE; + auto k_ptr = &k_info[k]; /* Skip "empty" artifacts */ - if (!(k_ptr->flags3 & TR3_NORM_ART)) continue; + if (!(k_ptr->flags & TR_NORM_ART)) continue; /* Skip "uncreated" artifacts */ if (!k_ptr->artifact) continue; @@ -3085,7 +3093,7 @@ void do_cmd_knowledge_artifacts(void) if (object_known_p(o_ptr)) continue; /* Note the artifact */ - if (k_info[o_ptr->k_idx].flags3 & TR3_NORM_ART) + if (k_info[o_ptr->k_idx].flags & TR_NORM_ART) { okayk[o_ptr->k_idx] = FALSE; } @@ -3118,7 +3126,7 @@ void do_cmd_knowledge_artifacts(void) if (object_known_p(o_ptr)) continue; /* Note the artifact */ - if (k_info[o_ptr->k_idx].flags3 & TR3_NORM_ART) + if (k_info[o_ptr->k_idx].flags & TR_NORM_ART) { okayk[o_ptr->k_idx] = FALSE; } @@ -3147,7 +3155,7 @@ void do_cmd_knowledge_artifacts(void) if (object_known_p(o_ptr)) continue; /* Note the artifact */ - if (k_info[o_ptr->k_idx].flags3 & TR3_NORM_ART) + if (k_info[o_ptr->k_idx].flags & TR_NORM_ART) { okayk[o_ptr->k_idx] = FALSE; } @@ -3157,10 +3165,13 @@ void do_cmd_knowledge_artifacts(void) } } + /* Output buffer */ + fmt::MemoryWriter w; + /* Scan the artifacts */ - for (k = 0; k < max_a_idx; k++) + for (std::size_t k = 0; k < a_info.size(); k++) { - artifact_type *a_ptr = &a_info[k]; + auto a_ptr = &a_info[k]; /* List "dead" ones */ if (!okay[k]) continue; @@ -3176,7 +3187,6 @@ void do_cmd_knowledge_artifacts(void) { object_type forge; object_type *q_ptr; - u32b f1, f2, f3, f4, f5, esp; /* Get local object */ q_ptr = &forge; @@ -3188,19 +3198,21 @@ void do_cmd_knowledge_artifacts(void) q_ptr->name1 = k; /* Spell in it ? no ! */ - object_flags(q_ptr, &f1, &f2, &f3, &f4, &f5, &esp); - if (f5 & TR5_SPELL_CONTAIN) + auto const flags = object_flags(q_ptr); + if (flags & TR_SPELL_CONTAIN) + { q_ptr->pval2 = -1; + } /* Describe the artifact */ object_desc_store(base_name, q_ptr, FALSE, 0); } /* Hack -- Build the artifact name */ - fprintf(fff, " The %s\n", base_name); + w.write(" The {}\n", base_name); } - for (k = 0; k < max_k_idx; k++) + for (std::size_t k = 0; k < k_info.size(); k++) { /* List "dead" ones */ if (!okayk[k]) continue; @@ -3225,68 +3237,18 @@ void do_cmd_knowledge_artifacts(void) } /* Hack -- Build the artifact name */ - fprintf(fff, " The %s\n", base_name); + w.write(" The {}\n", base_name); } - /* Close the file */ - my_fclose(fff); - - /* Display the file contents */ - show_file(file_name, "Artifacts Seen", 0, 0); - - /* Remove the file */ - fd_kill(file_name); + /* Display */ + show_string(w.c_str(), "Artifacts Seen"); } -/* - * Check the status of traps - */ -void do_cmd_knowledge_traps(void) +static int monster_get_race_level(int r_idx) { - int k; - - FILE *fff; - - trap_type *t_ptr; - - char file_name[1024]; - + auto const &r_info = game->edit_data.r_info; - /* Temporary file */ - if (path_temp(file_name, 1024)) return; - - /* Open a new file */ - fff = my_fopen(file_name, "w"); - - /* Scan the traps */ - for (k = 0; k < max_t_idx; k++) - { - /* Get the trap */ - t_ptr = &t_info[k]; - - /* Skip "empty" traps */ - if (!t_ptr->name) continue; - - /* Skip unidentified traps */ - if (!t_ptr->ident) continue; - - /* Hack -- Build the trap name */ - fprintf(fff, " %s\n", t_ptr->name); - } - - /* Close the file */ - my_fclose(fff); - - /* Display the file contents */ - show_file(file_name, "Traps known", 0, 0); - - /* Remove the file */ - fd_kill(file_name); -} - - -static int monster_get_race_level(int r_idx) { /* Hack -- Morgoth is always last */ if (r_idx == 862) { return 20000; @@ -3295,40 +3257,23 @@ static int monster_get_race_level(int r_idx) { return r_info[r_idx].level; } -static bool compare_monster_level(int r_idx1, int r_idx2) { - return monster_get_race_level(r_idx1) < monster_get_race_level(r_idx2); -} - /* * Display known uniques - * - * Note that the player ghosts are ignored. XXX XXX XXX */ -static void do_cmd_knowledge_uniques(void) +static void do_cmd_knowledge_uniques() { - int k; - - FILE *fff; - - char file_name[1024]; - - - /* Temporary file */ - if (path_temp(file_name, 1024)) return; - - /* Open a new file */ - fff = my_fopen(file_name, "w"); + auto const &r_info = game->edit_data.r_info; // Extract the unique race indexes. - std::vector<int> unique_r_idxs; - for (k = 1; k < max_r_idx; k++) + std::vector<std::size_t> unique_r_idxs; + for (std::size_t k = 1; k < r_info.size(); k++) { - monster_race *r_ptr = &r_info[k]; + auto r_ptr = &r_info[k]; /* Only print Uniques */ - if (r_ptr->flags1 & (RF1_UNIQUE) && - !(r_ptr->flags7 & RF7_PET) && - !(r_ptr->flags7 & RF7_NEUTRAL)) + if ((r_ptr->flags & RF_UNIQUE) && + !(r_ptr->flags & RF_PET) && + !(r_ptr->flags & RF_NEUTRAL)) { unique_r_idxs.push_back(k); } @@ -3337,48 +3282,41 @@ static void do_cmd_knowledge_uniques(void) // Sort races by level. std::sort(std::begin(unique_r_idxs), std::end(unique_r_idxs), - compare_monster_level); + [](auto r_idx1, auto r_idx2) -> bool { + return monster_get_race_level(r_idx1) < monster_get_race_level(r_idx2); + }); - /* Scan the monster races */ - for (int r_idx : unique_r_idxs) + // Scan the monster races + fmt::MemoryWriter w; + for (std::size_t r_idx : unique_r_idxs) { - monster_race *r_ptr = &r_info[r_idx]; + auto r_ptr = &r_info[r_idx]; /* Only print Uniques */ - if (r_ptr->flags1 & (RF1_UNIQUE)) + if (r_ptr->flags & RF_UNIQUE) { bool_ dead = (r_ptr->max_num == 0); - /* Only display "known" uniques */ - if (dead || cheat_know || r_ptr->r_sights) + /* Print a message */ + if (dead) { - /* Print a message */ - if (dead) - { - fprintf(fff, "[[[[[%c%c] [[[[[R%-68s is dead]\n", - conv_color[r_ptr->d_attr], - r_ptr->d_char, - r_ptr->name); - } - else - { - fprintf(fff, "[[[[[%c%c] [[[[[w%-68s is alive]\n", - conv_color[r_ptr->d_attr], - r_ptr->d_char, - r_ptr->name); - } + w.write("[[[[[{}{}] [[[[[R{:<68} is dead]\n", + static_cast<char>(conv_color[r_ptr->d_attr]), + static_cast<char>(r_ptr->d_char), + r_ptr->name); + } + else + { + w.write("[[[[[{}{}] [[[[[w{:<68} is alive]\n", + static_cast<char>(conv_color[r_ptr->d_attr]), + static_cast<char>(r_ptr->d_char), + r_ptr->name); } } } - /* Close the file */ - my_fclose(fff); - - /* Display the file contents */ - show_file(file_name, "Known Uniques", 0, 0); - - /* Remove the file */ - fd_kill(file_name); + // Display + show_string(w.c_str(), "Known Uniques"); } @@ -3438,29 +3376,29 @@ static void plural_aux(char *name) } /* Broken plurals are, well, broken */ - else if (name[name_len - 1] == 'y') + else if (name_len >= 1 && name[name_len - 1] == 'y') { strcpy(&name[name_len - 1], "ies"); } - else if (streq(&name[name_len - 4], "ouse")) + else if (name_len >= 4 && streq(&name[name_len - 4], "ouse")) { strcpy(&name[name_len - 4], "ice"); } - else if (streq(&name[name_len - 6], "kelman")) + else if (name_len >= 6 && streq(&name[name_len - 6], "kelman")) { strcpy(&name[name_len - 6], "kelmen"); } - else if (streq(&name[name_len - 2], "ex")) + else if (name_len >= 2 && streq(&name[name_len - 2], "ex")) { strcpy(&name[name_len - 2], "ices"); } - else if (streq(&name[name_len - 3], "olf")) + else if (name_len >= 3 && streq(&name[name_len - 3], "olf")) { strcpy(&name[name_len - 3], "olves"); } /* Now begins sane cases */ - else if ((streq(&name[name_len - 2], "ch")) || (name[name_len - 1] == 's')) + else if ((name_len >= 2 && streq(&name[name_len - 2], "ch")) || (name_len >= 1 && name[name_len - 1] == 's')) { strcpy(&name[name_len], "es"); } @@ -3474,38 +3412,19 @@ static void plural_aux(char *name) /* * Display current pets */ -static void do_cmd_knowledge_pets(void) +static void do_cmd_knowledge_pets() { - int i; - - FILE *fff; - - monster_type *m_ptr; - int t_friends = 0; - int t_levels = 0; - int show_upkeep = 0; - - int upkeep_divider = 20; - - char file_name[1024]; - - - /* Temporary file */ - if (path_temp(file_name, 1024)) return; - - /* Open a new file */ - fff = my_fopen(file_name, "w"); - - if (has_ability(AB_PERFECT_CASTING)) upkeep_divider = 15; + // Buffer + fmt::MemoryWriter w; /* Process the monsters (backwards) */ - for (i = m_max - 1; i >= 1; i--) + for (int i = m_max - 1; i >= 1; i--) { /* Access the monster */ - m_ptr = &m_list[i]; + monster_type *m_ptr = &m_list[i]; /* Ignore "dead" monsters */ if (!m_ptr->r_idx) continue; @@ -3521,13 +3440,17 @@ static void do_cmd_knowledge_pets(void) char pet_name[80]; monster_desc(pet_name, m_ptr, 0x88); - fprintf(fff, "%s%s (%s)\n", - (r_ptr->flags1 & RF1_UNIQUE) ? "#####G" : "", - pet_name, - (m_ptr->status < MSTATUS_COMPANION) ? "pet" : "companion"); + w.write("{}{} ({})\n", + (r_ptr->flags & RF_UNIQUE) ? "#####G" : "", + pet_name, + (m_ptr->status < MSTATUS_COMPANION) ? "pet" : "companion"); } } + // Calculate upkeep + int show_upkeep = 0; + int upkeep_divider = p_ptr->has_ability(AB_PERFECT_CASTING) ? 15 : 20; + if (t_friends > 1 + (p_ptr->lev / (upkeep_divider))) { show_upkeep = (t_levels); @@ -3536,104 +3459,78 @@ static void do_cmd_knowledge_pets(void) else if (show_upkeep < 10) show_upkeep = 10; } + // Summary + w.write("----------------------------------------------\n"); + w.write(" Total: {} pet{}.\n", t_friends, (t_friends == 1 ? "" : "s")); + w.write(" Upkeep: {}% mana.\n", show_upkeep); - fprintf(fff, "----------------------------------------------\n"); - fprintf(fff, " Total: %d pet%s.\n", t_friends, (t_friends == 1 ? "" : "s")); - fprintf(fff, " Upkeep: %d%% mana.\n", show_upkeep); - - - /* Close the file */ - my_fclose(fff); - - /* Display the file contents */ - show_file(file_name, "Current Pets", 0, 0); - - /* Remove the file */ - fd_kill(file_name); + // Display + show_string(w.c_str(), "Current Pets"); } /* * Total kill count - * - * Note that the player ghosts are ignored. XXX XXX XXX */ -static void do_cmd_knowledge_kill_count(void) +static void do_cmd_knowledge_kill_count() { - int k; - - FILE *fff; - - char file_name[1024]; + auto const &r_info = game->edit_data.r_info; s32b Total = 0; + // Buffer + fmt::MemoryWriter w; - /* Temporary file */ - if (path_temp(file_name, 1024)) return; - - /* Open a new file */ - fff = my_fopen(file_name, "w"); - + // Summary of monsters slain { - /* Monsters slain */ - int kk; - /* For all monsters */ - for (kk = 1; kk < max_r_idx; kk++) + for (auto const &r_ref: r_info) { - monster_race *r_ptr = &r_info[kk]; + auto r_ptr = &r_ref; - if (r_ptr->flags1 & (RF1_UNIQUE)) + if (r_ptr->flags & RF_UNIQUE) { - bool_ dead = (r_ptr->max_num == 0); - - if (dead) + if (r_ptr->max_num == 0) { Total++; } } else { - s16b This = r_ptr->r_pkills; - - if (This > 0) - { - Total += This; - } + Total += std::max<s16b>(r_ptr->r_pkills, 0); } } if (Total < 1) { - fprintf(fff, "You have defeated no enemies yet.\n\n"); + w.write("You have defeated no enemies yet.\n\n"); } else if (Total == 1) { - fprintf(fff, "You have defeated one enemy.\n\n"); + w.write("You have defeated one enemy.\n\n"); } else { - fprintf(fff, "You have defeated " FMTs32b " enemies.\n\n", Total); + w.write("You have defeated {} enemies.\n\n", Total); } } Total = 0; /* Scan the monster races */ - for (k = 0; k < max_r_idx; k++) + for (auto const &r_ref: r_info) { - monster_race *r_ptr = &r_info[k]; + auto r_ptr = &r_ref; - if (r_ptr->flags1 & (RF1_UNIQUE)) + if (r_ptr->flags & RF_UNIQUE) { bool_ dead = (r_ptr->max_num == 0); if (dead) { /* Print a message */ - fprintf(fff, " %s\n", r_ptr->name); + w.write(" {}\n", r_ptr->name); Total++; } } @@ -3647,11 +3544,11 @@ static void do_cmd_knowledge_kill_count(void) { if (strstr(r_ptr->name, "coins")) { - fprintf(fff, " 1 pile of %s\n", r_ptr->name); + w.write(" 1 pile of {}\n", r_ptr->name); } else { - fprintf(fff, " 1 %s\n", r_ptr->name); + w.write(" 1 {}\n", r_ptr->name); } } else @@ -3659,7 +3556,7 @@ static void do_cmd_knowledge_kill_count(void) char to_plural[80]; strcpy(to_plural, r_ptr->name); plural_aux(to_plural); - fprintf(fff, " %d %s\n", This, to_plural); + w.write(" {} {}\n", This, to_plural); } Total += This; @@ -3667,147 +3564,100 @@ static void do_cmd_knowledge_kill_count(void) } } - fprintf(fff, "----------------------------------------------\n"); - fprintf(fff, " Total: " FMTs32b " creature%s killed.\n", Total, (Total == 1 ? "" : "s")); - - /* Close the file */ - my_fclose(fff); + w.write("----------------------------------------------\n"); + w.write(" Total: {} creature{} killed.\n", Total, (Total == 1 ? "" : "s")); /* Display the file contents */ - show_file(file_name, "Kill Count", 0, 0); - - /* Remove the file */ - fd_kill(file_name); + show_string(w.c_str(), "Kill Count"); } /* * Display known objects */ -static void do_cmd_knowledge_objects(void) +static void do_cmd_knowledge_objects() { - int k; - - FILE *fff; - - char o_name[80]; + auto const &k_info = game->edit_data.k_info; - char file_name[1024]; - - - /* Temporary file */ - if (path_temp(file_name, 1024)) return; - - /* Open a new file */ - fff = my_fopen(file_name, "w"); + fmt::MemoryWriter w; /* Scan the object kinds */ - for (k = 1; k < max_k_idx; k++) + for (std::size_t k = 1; k < k_info.size(); k++) { - object_kind *k_ptr = &k_info[k]; + auto k_ptr = &k_info[k]; /* Hack -- skip artifacts */ - if (k_ptr->flags3 & (TR3_INSTA_ART)) continue; + if (k_ptr->flags & (TR_INSTA_ART)) continue; /* List known flavored objects */ if (k_ptr->flavor && k_ptr->aware) { - object_type *i_ptr; object_type object_type_body; /* Get local object */ - i_ptr = &object_type_body; + object_type *i_ptr = &object_type_body; /* Create fake object */ object_prep(i_ptr, k); /* Describe the object */ + char o_name[80]; object_desc_store(o_name, i_ptr, FALSE, 0); /* Print a message */ - fprintf(fff, " %s\n", o_name); + w.write(" {}\n", o_name); } } - /* Close the file */ - my_fclose(fff); - - /* Display the file contents */ - show_file(file_name, "Known Objects", 0, 0); - - /* Remove the file */ - fd_kill(file_name); + // Display + show_string(w.c_str(), "Known Objects"); } /* * List recall depths */ -static void do_cmd_knowledge_dungeons(void) +static void do_cmd_knowledge_dungeons() { - int y; - char file_name[1024]; - FILE *fff; + auto const &d_info = game->edit_data.d_info; - /* Temporary file */ - if (path_temp(file_name, 1024)) return; - - /* Open a new file */ - fff = my_fopen(file_name, "w"); - - /* Oops */ - if (fff == NULL) return; + fmt::MemoryWriter w; /* Scan all dungeons */ - for (y = 1; y < max_d_idx; y++) + for (std::size_t y = 1; y < d_info.size(); y++) { /* The dungeon has a valid recall depth set */ if (max_dlv[y]) { /* Describe the recall depth */ - fprintf(fff, " %c%s: Level %d (%d')\n", - (p_ptr->recall_dungeon == y) ? '*' : ' ', + w.write(" {}{}: Level {}\n", + (p_ptr->recall_dungeon == y) ? '*' : ' ', d_info[y].name, - max_dlv[y], 50 * (max_dlv[y])); + max_dlv[y]); } } - /* Close the file */ - my_fclose(fff); - - /* Display the file contents */ - show_file(file_name, "Recall Depths", 0, 0); - - /* Remove the file */ - fd_kill(file_name); + // Display + show_string(w.c_str(), "Recall Depths"); } /* * List known towns */ -void do_cmd_knowledge_towns(void) +void do_cmd_knowledge_towns() { - int i, j; - char file_name[1024]; - FILE *fff; - - /* Temporary file */ - if (path_temp(file_name, 1024)) return; + auto const &d_info = game->edit_data.d_info; - /* Open a new file */ - fff = my_fopen(file_name, "w"); - - /* Oops */ - if (fff == NULL) return; + fmt::MemoryWriter w; /* Scan all dungeons */ - for (i = 0; i < max_d_idx; i++) + for (auto const &d_ref: d_info) { - dungeon_info_type *d_ptr = &d_info[i]; + auto d_ptr = &d_ref; /* Scan all dungeon town slots */ - for (j = 0; j < TOWN_DUNGEON; j++) + for (int j = 0; j < TOWN_DUNGEON; j++) { int town_idx = d_ptr->t_idx[j]; @@ -3818,127 +3668,51 @@ void do_cmd_knowledge_towns(void) if (!(town_info[town_idx].flags & (TOWN_KNOWN))) continue; /* Describe the dungeon town */ - fprintf(fff, " %s: Level %d (%d')\n", + w.write(" {}: Level {}\n", d_ptr->name, - d_ptr->t_level[j], - 50 * d_ptr->t_level[j]); + d_ptr->t_level[j]); } } - /* Close the file */ - my_fclose(fff); - /* Display the file contents */ - show_file(file_name, "Dungeon Towns", 0, 0); - - /* Remove the file */ - fd_kill(file_name); + show_string(w.c_str(), "Dungeon Towns"); } /* * List corruptions */ -static void do_cmd_knowledge_corruptions(void) +static void do_cmd_knowledge_corruptions() { - FILE *fff; - - char file_name[1024]; - - - /* Temporary file */ - if (path_temp(file_name, 1024)) return; - - /* Open a new file */ - fff = my_fopen(file_name, "w"); - - /* Dump the corruptions to file */ - if (fff) - { - dump_corruptions(fff, TRUE, FALSE); - } - - /* Close the file */ - my_fclose(fff); - - /* Display the file contents */ - show_file(file_name, "Corruptions", 0, 0); - - /* Remove the file */ - fd_kill(file_name); -} - - -/* - * Helper function for do_cmd_knowledge_quests - */ -static void insert_sort_quest(int *order, int *num, int q_idx) -{ - int i, j; - - quest_type *q_ptr = &quest[q_idx]; - - int level = q_ptr->level; - - - /* Find the place */ - for (i = 0; i < *num; i++) - { - quest_type *q2_ptr = &quest[order[i]]; - int level2 = q2_ptr->level; - - if (level < level2) break; - } - - /* Move the remaining items */ - for (j = *num - 1; j >= i; j--) - { - order[j + 1] = order[j]; - } - - /* Insert it */ - order[i] = q_idx; - (*num)++; + show_string(dump_corruptions(true, false).c_str(), "Corruptions"); } /* * Print quest status of all active quests */ -static void do_cmd_knowledge_quests(void) +static void do_cmd_knowledge_quests() { - FILE *fff; - - char file_name[1024]; - - int order[MAX_Q_IDX] = { }; - - int num = 0; - - int i, j, z; - - - /* Temporary file */ - if (path_temp(file_name, 1024)) return; - - /* Open a new file */ - fff = my_fopen(file_name, "w"); - - for (i = 0; i < MAX_Q_IDX; i++) - { - insert_sort_quest(order, &num, i); - } - - for (z = 0; z < MAX_Q_IDX; z++) + /* Figure out display order of quests */ + int order[MAX_Q_IDX]; + std::iota(order, order + MAX_Q_IDX, 0); // Start with order of definition + std::sort(order, order + MAX_Q_IDX, [](int qi, int qj) -> bool { + return (quest[qi].level < quest[qj].level); + }); + + /* Write */ + fmt::MemoryWriter w; + for (int z = 0; z < MAX_Q_IDX; z++) { - i = order[z]; + int const i = order[z]; /* Dynamic descriptions */ if (quest[i].gen_desc != NULL) { - if (!quest[i].gen_desc(fff)) + auto s = quest[i].gen_desc(); + if (!s.empty()) { - continue; + w.write("{}\n\n", s); } } @@ -3948,68 +3722,42 @@ static void do_cmd_knowledge_quests(void) if (quest[i].status == QUEST_STATUS_TAKEN) { /* Print the quest info */ - fprintf(fff, "#####y%s (Danger level: %d)\n", + w.write("#####y{} (Danger level: {})\n", quest[i].name, quest[i].level); - j = 0; + int j = 0; while ((j < 10) && (quest[i].desc[j][0] != '\0')) { - fprintf(fff, "%s\n", quest[i].desc[j++]); + w.write("{}\n", quest[i].desc[j++]); } - fprintf(fff, "\n"); + w.write("\n"); } else if (quest[i].status == QUEST_STATUS_COMPLETED) { - fprintf(fff , "#####G%s Completed - Unrewarded\n", quest[i].name); - fprintf(fff, "\n"); + w.write("#####G{} Completed - Unrewarded\n", quest[i].name); + w.write("\n"); } } } - /* Close the file */ - my_fclose(fff); - - /* Display the file contents */ - show_file(file_name, "Quest status", 0, 0); - - /* Remove the file */ - fd_kill(file_name); + /* Display */ + show_string(w.c_str(), "Quest status"); } /* * Print fate status */ -static void do_cmd_knowledge_fates(void) +static void do_cmd_knowledge_fates() { - FILE *fff; - - char file_name[1024]; - - - /* Temporary file */ - if (path_temp(file_name, 1024)) return; - - /* Open a new file */ - fff = my_fopen(file_name, "w"); - - dump_fates(fff); - - /* Close the file */ - my_fclose(fff); - - /* Display the file contents */ - show_file(file_name, "Fate status", 0, 0); - - /* Remove the file */ - fd_kill(file_name); + show_string(dump_fates().c_str(), "Fate status"); } /* * Print the note file */ -void do_cmd_knowledge_notes(void) +void do_cmd_knowledge_notes() { /* Spawn */ show_notes_file(); @@ -4022,7 +3770,7 @@ void do_cmd_knowledge_notes(void) /* * Interact with "knowledge" */ -void do_cmd_knowledge(void) +void do_cmd_knowledge() { int i; @@ -4052,12 +3800,11 @@ void do_cmd_knowledge(void) prt("(7) Display current pets", 10, 5); prt("(8) Display current quests", 11, 5); prt("(9) Display current fates", 12, 5); - prt("(0) Display known traps", 13, 5); - prt("(A) Display known dungeon towns", 14, 5); - prt("(B) Display notes", 15, 5); + prt("(0) Display known dungeon towns", 13, 5); + prt("(A) Display notes", 14, 5); /* Prompt */ - prt("Command: ", 17, 0); + prt("Command: ", 16, 0); /* Prompt */ i = inkey(); @@ -4139,17 +3886,8 @@ void do_cmd_knowledge(void) break; } - /* Traps */ - case '0': - { - do_cmd_knowledge_traps(); - - break; - } - /* Dungeon towns */ - case 'A': - case 'a': + case '0': { do_cmd_knowledge_towns(); @@ -4157,8 +3895,8 @@ void do_cmd_knowledge(void) } /* Notes */ - case 'B': - case 'b': + case 'A': + case 'a': { do_cmd_knowledge_notes(); @@ -4190,7 +3928,7 @@ void do_cmd_knowledge(void) * Check on the status of an active quest -KMW- * TODO: Spill out status when not a simple kill # monster. */ -void do_cmd_checkquest(void) +void do_cmd_checkquest() { /* Enter "icky" mode */ character_icky = TRUE; @@ -4267,9 +4005,10 @@ void do_cmd_time() strcpy(desc, "It is a strange time."); /* Display day */ - u32b days = bst(DAY, turn) + 1; + auto days = bst(DAY, turn) + 1; + auto days_str = get_day(days); msg_format("This is the %s day of your adventure.", - get_day(days)); + days_str.c_str()); /* Message */ msg_format("The time is %d:%02d %s.", diff --git a/src/cmd4.hpp b/src/cmd4.hpp index 4470c94f..39f1c16c 100644 --- a/src/cmd4.hpp +++ b/src/cmd4.hpp @@ -2,27 +2,27 @@ #include "h-basic.h" -extern void macro_recorder_start(void); -extern void macro_recorder_add(char c); -extern void macro_recorder_stop(void); -extern void do_cmd_macro_recorder(void); -extern void do_cmd_redraw(void); -extern void do_cmd_change_name(void); -extern void do_cmd_message_one(void); -extern void do_cmd_messages(void); -extern void do_cmd_options(void); -extern void do_cmd_pref(void); -extern void do_cmd_macros(void); -extern void do_cmd_visuals(void); -extern void do_cmd_colors(void); -extern void do_cmd_note(void); -extern void do_cmd_version(void); -extern void do_cmd_feeling(void); -extern void do_cmd_load_screen(void); -extern void do_cmd_save_screen(void); -extern void do_cmd_knowledge(void); -extern void do_cmd_checkquest(void); -extern void do_cmd_change_tactic(int i); -extern void do_cmd_change_movement(int i); -extern void do_cmd_time(void); -extern void do_cmd_options_aux(int page, cptr info, bool_ read_only); +void macro_recorder_start(); +void macro_recorder_add(char c); +void macro_recorder_stop(); +void do_cmd_macro_recorder(); +void do_cmd_redraw(); +void do_cmd_change_name(); +void do_cmd_message_one(); +void do_cmd_messages(); +void do_cmd_options(); +void do_cmd_pref(); +void do_cmd_macros(); +void do_cmd_visuals(); +void do_cmd_colors(); +void do_cmd_note(); +void do_cmd_version(); +void do_cmd_feeling(); +void do_cmd_load_screen(); +void do_cmd_save_screen(); +void do_cmd_knowledge(); +void do_cmd_checkquest(); +void do_cmd_change_tactic(int i); +void do_cmd_change_movement(int i); +void do_cmd_time(); +void do_cmd_options_aux(int page, cptr info, bool_ read_only); diff --git a/src/cmd5.cc b/src/cmd5.cc index a1dd5cbf..a93759b0 100644 --- a/src/cmd5.cc +++ b/src/cmd5.cc @@ -12,11 +12,16 @@ #include "cave.hpp" #include "cave_type.hpp" #include "corrupt.hpp" +#include "dungeon_flag.hpp" +#include "game.hpp" #include "lua_bind.hpp" #include "monster2.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" +#include "monster_spell_flag.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_flag.hpp" #include "object_type.hpp" #include "player_class.hpp" #include "player_race.hpp" @@ -35,7 +40,6 @@ #include "util.h" #include "variable.h" #include "variable.hpp" -#include "quark.hpp" #include "wizard2.hpp" #include "xtra1.hpp" #include "xtra2.hpp" @@ -69,7 +73,7 @@ static object_filter_t const &hook_school_spellable() static auto instance = Or( is_school_book(), And( - HasFlag5(TR5_SPELL_CONTAIN), + HasFlags(TR_SPELL_CONTAIN), has_pval2)); return instance; } @@ -221,22 +225,21 @@ static void browse_school_spell(int book, int spell_idx, object_type *o_ptr) * and in the dark, primarily to allow browsing in stores. */ -extern void do_cmd_browse_aux(object_type *o_ptr) +void do_cmd_browse_aux(object_type *o_ptr) { - u32b f1, f2, f3, f4, f5, esp; - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); if (is_school_book()(o_ptr)) { browse_school_spell(o_ptr->sval, o_ptr->pval, o_ptr); } - else if (f5 & TR5_SPELL_CONTAIN && o_ptr->pval2 != -1) + else if ((flags & TR_SPELL_CONTAIN) && (o_ptr->pval2 != -1)) { browse_school_spell(255, o_ptr->pval2, o_ptr); } } -void do_cmd_browse(void) +void do_cmd_browse() { /* Get an item */ int item; @@ -283,8 +286,10 @@ static void do_poly_wounds() } } -void do_poly_self(void) +void do_poly_self() { + auto const &race_info = game->edit_data.race_info; + int power = p_ptr->lev; int poly_power; @@ -298,25 +303,6 @@ void do_poly_self(void) /* Some form of racial polymorph... */ power -= 10; - if ((power > rand_int(5)) && (rand_int(4) == 0)) - { - /* sex change */ - power -= 2; - - if (p_ptr->psex == SEX_MALE) - { - p_ptr->psex = SEX_FEMALE; - sp_ptr = &sex_info[p_ptr->psex]; - strcpy(effect_msg, "female"); - } - else - { - p_ptr->psex = SEX_MALE; - sp_ptr = &sex_info[p_ptr->psex]; - strcpy(effect_msg, "male"); - } - } - if ((power > rand_int(30)) && (rand_int(5) == 0)) { int tmp = 0; @@ -328,14 +314,14 @@ void do_poly_self(void) { if ( rand_int(2) == 0) { - (void)dec_stat(tmp, randint(6) + 6, (rand_int(3) == 0)); + dec_stat(tmp, randint(6) + 6, (rand_int(3) == 0)); power -= 1; } tmp++; } /* Deformities are discriminated against! */ - (void)dec_stat(A_CHR, randint(6), TRUE); + dec_stat(A_CHR, randint(6), TRUE); if (effect_msg[0]) { @@ -374,34 +360,34 @@ void do_poly_self(void) /* Roll until an appropriate selection is made */ while (1) { - new_race = rand_int(max_rp_idx); - expfact = race_info[new_race].r_exp; + new_race = rand_int(race_info.size()); + expfact = race_info[new_race].ps.exp; - if ((new_race != p_ptr->prace) && (expfact <= goalexpfact)) break; + if ((new_race != p_ptr->prace) && (expfact <= goalexpfact)) + { + break; + } } if (effect_msg[0]) { msg_format("You turn into a%s %s!", - ((is_a_vowel(*race_info[new_race].title)) ? "n" : ""), - race_info[new_race].title); + (is_a_vowel(race_info[new_race].title[0]) ? "n" : ""), + race_info[new_race].title.c_str()); } else { msg_format("You turn into a %s %s!", effect_msg, - race_info[new_race].title); + race_info[new_race].title.c_str()); } p_ptr->prace = new_race; rp_ptr = &race_info[p_ptr->prace]; /* Experience factor */ - p_ptr->expfact = rp_ptr->r_exp + rmp_ptr->r_exp + cp_ptr->c_exp; - - /* Calculate the height/weight */ - get_height_weight(); - + p_ptr->expfact = rp_ptr->ps.exp + rmp_ptr->ps.exp + cp_ptr->ps.exp; + /* Level up if necessary */ check_experience(); p_ptr->max_plv = p_ptr->lev; @@ -423,7 +409,7 @@ void do_poly_self(void) msg_print("Your internal organs are rearranged!"); while (tmp < 6) { - (void)dec_stat(tmp, randint(6) + 6, (rand_int(3) == 0)); + dec_stat(tmp, randint(6) + 6, (rand_int(3) == 0)); tmp++; } if (rand_int(6) == 0) @@ -552,179 +538,141 @@ void fetch(int dir, int wgt, bool_ require_los) /* - * Handle random effects of player shrieking - */ -void shriek_effect() -{ - switch (randint(9)) - { - case 1: - case 5: - case 8: - case 9: - { - msg_print("You make a high-pitched shriek!"); - aggravate_monsters(1); - - break; - } - case 2: - case 6: - { - msg_print("Oops! You call a monster."); - summon_specific(p_ptr->py, p_ptr->px, max_dlv[dungeon_type], 0); - - break; - } - case 3: - case 7: - { - msg_print("The dungeon collapses!"); - earthquake(p_ptr->py, p_ptr->px, 5); - - break; - } - case 4: - { - msg_print("Your shriek is so horrible that you damage your health!"); - take_hit(damroll(p_ptr->lev / 5, 8), "inner hemorrhaging"); - - break; - } - } -} - -/* * Return the symbiote's name or description. */ -cptr symbiote_name(bool_ capitalize) +std::string symbiote_name(bool capitalize) { + auto const &r_info = game->edit_data.r_info; + object_type *o_ptr = &p_ptr->inventory[INVEN_CARRY]; - static char buf[80]; - /* Make sure there actually is a symbiote there... */ + std::string buf; + buf.reserve(32); + + // Fallback; shouldn't ever be necessary if (!o_ptr->k_idx) { - strcpy(buf, "A non-existent symbiote"); + buf += "A non-existent symbiote"; } else { - monster_race *r_ptr = &r_info[o_ptr->pval]; - cptr s = NULL; + auto r_ptr = &r_info[o_ptr->pval]; + std::size_t i = 0; - if (r_ptr->flags1 & RF1_UNIQUE) + if (r_ptr->flags & RF_UNIQUE) { - /* Unique monster; no preceding "your", and ignore our name. */ - strncpy(buf, r_ptr->name, sizeof(buf)); + // Unique monster; no preceding "your" and ignore name + buf += r_ptr->name; } - else if (o_ptr->note && - (s = strstr(quark_str(o_ptr->note), "#named ")) != NULL) + else if ((i = o_ptr->inscription.find("#named ")) != std::string::npos) { - /* We've named it. */ - strncpy(buf, s + 7, sizeof(buf)); + // We've named it; extract the name */ + buf += o_ptr->inscription.substr(i); } else { - /* No special cases, just return "Your <monster type>". */ - strcpy(buf, "your "); - strncpy(buf + 5, r_ptr->name, sizeof(buf) - 5); + // No special cases; just return "Your <monster type>". + buf += "your "; + buf += r_ptr->name; } } - /* Just in case... */ - buf[sizeof(buf) - 1] = '\0'; - if (capitalize) buf[0] = toupper(buf[0]); + // Capitalize? + if (capitalize) + { + buf[0] = toupper(buf[0]); + } + + // Done return buf; } + /* - * Use a power of the monster in symbiosis + * Find monster power */ -int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost) +monster_power const *lookup_monster_power(std::size_t idx) { - int power = -1; - - int num = 0, dir = 0 , i; - - int powers[96]; - - bool_ flag; - - int ask, plev = p_ptr->lev; - - char choice; - - char out_val[160]; - - monster_race *r_ptr = &r_info[r_idx]; - - int rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1); - - int x = p_ptr->px, y = p_ptr->py, k; - - int rad; - - int label; - - - /* List the monster powers -- RF4_* */ - for (i = 0; i < 32; i++) + for (auto const &p: monster_powers) { - if (r_ptr->flags4 & BIT(i)) + if (p.monster_spell_index == idx) { - if (monster_powers[i].great && (!great)) continue; - if (!monster_powers[i].power) continue; - powers[num++] = i; + return &p; } } + return nullptr; +} - /* List the monster powers -- RF5_* */ - for (i = 0; i < 32; i++) - { - if (r_ptr->flags5 & BIT(i)) - { - if (monster_powers[i + 32].great && (!great)) continue; - if (!monster_powers[i + 32].power) continue; - powers[num++] = i + 32; - } - } - /* List the monster powers -- RF6_* */ - for (i = 0; i < 32; i++) +/* + * Extract powers + */ +std::vector<monster_power const *> extract_monster_powers(monster_race const *r_ptr, bool great) +{ + std::vector<monster_power const *> powers; + powers.reserve(MONSTER_POWERS_MAX); + + for (std::size_t i = 0; i < monster_spell_flag_set::nbits; i++) { - if (r_ptr->flags6 & BIT(i)) + if (r_ptr->spells.bit(i)) { - if (monster_powers[i + 64].great && (!great)) continue; - if (!monster_powers[i + 64].power) continue; - powers[num++] = i + 64; + if (auto power = lookup_monster_power(i)) + { + if (power->great && (!great)) + { + continue; + } + powers.push_back(power); + } } } + return powers; +} + +/** + * Calculate mana required for a given monster power. + */ +static int calc_monster_spell_mana(monster_power const *mp_ptr) +{ + int mana = mp_ptr->mana / 10; + if (mana > p_ptr->msp) mana = p_ptr->msp; + if (!mana) mana = 1; + return mana; +} + +/** + * Choose a monster power + */ +static std::tuple<int, int> choose_monster_power(monster_race const *r_ptr, bool great, bool symbiosis) +{ + /* Extract available monster powers */ + auto powers = extract_monster_powers(r_ptr, great); + int const num = powers.size(); // Avoid signed/unsigned warnings + if (!num) { msg_print("You have no powers you can use."); - return (0); + return std::make_tuple(0, num); } - if (only_number) return (num); - - /* Nothing chosen yet */ - flag = FALSE; - /* Get the last label */ - label = (num <= 26) ? I2A(num - 1) : I2D(num - 1 - 26); + int label = (num <= 26) ? I2A(num - 1) : I2D(num - 1 - 26); /* Build a prompt (accept all spells) */ /* Mega Hack -- if no_cost is false, we're actually a Possessor -dsb */ + char out_val[160]; strnfmt(out_val, 78, "(Powers a-%c, ESC=exit) Use which power of your %s? ", - label, (no_cost ? "symbiote" : "body")); + label, (symbiosis ? "symbiote" : "body")); /* Save the screen */ character_icky = TRUE; Term_save(); /* Get a spell from the user */ + monster_power const *power = nullptr; + bool_ flag = FALSE; // Nothing chosen yet while (!flag) { /* Show the list */ @@ -732,26 +680,26 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost byte y = 1, x = 0; int ctr = 0; char dummy[80]; - strcpy(dummy, ""); prt ("", y++, x); while (ctr < num) { - monster_power *mp_ptr = &monster_powers[powers[ctr]]; - int mana = mp_ptr->mana / 10; - - if (mana > p_ptr->msp) mana = p_ptr->msp; - - if (!mana) mana = 1; + monster_power const *mp_ptr = powers[ctr]; label = (ctr < 26) ? I2A(ctr) : I2D(ctr - 26); - if (!no_cost) + byte color = TERM_L_GREEN; + if (!symbiosis) { + int mana = calc_monster_spell_mana(mp_ptr); strnfmt(dummy, 80, " %c) %2d %s", label, mana, mp_ptr->name); + // Gray out if player doesn't have enough mana to cast. + if (mana > p_ptr->csp) { + color = TERM_L_DARK; + } } else { @@ -761,11 +709,11 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost if (ctr < 17) { - prt(dummy, y + ctr, x); + c_prt(color, dummy, y + ctr, x); } else { - prt(dummy, y + ctr - 17, x + 40); + c_prt(color, dummy, y + ctr - 17, x + 40); } ctr++; @@ -781,6 +729,7 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost } } + char choice; if (!get_com(out_val, &choice)) { flag = FALSE; @@ -792,6 +741,8 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost choice = 'a'; } + int i; + int ask; if (isalpha(choice)) { /* Note verify */ @@ -818,16 +769,26 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost continue; } - /* Save the spell index */ + /* Save the spell */ power = powers[i]; + /* Make sure it's actually possible for the player to cast */ + if (!symbiosis) + { + if (p_ptr->csp < calc_monster_spell_mana(power)) + { + bell(); + continue; + } + } + /* Verify it */ if (ask) { char tmp_val[160]; /* Prompt */ - strnfmt(tmp_val, 78, "Use %s? ", monster_powers[power].name); + strnfmt(tmp_val, 78, "Use %s? ", power->name); /* Belay that order */ if (!get_check(tmp_val)) continue; @@ -842,55 +803,60 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost character_icky = FALSE; /* Abort if needed */ - if (!flag) + if (!flag || (power == nullptr)) { - energy_use = 0; - return -1; + return std::make_tuple(-1, num); } - /* 'Powerful' monsters have wider radii */ - if (r_ptr->flags2 & RF2_POWERFUL) - { - rad = 1 + (p_ptr->lev / 15); - } - else - { - rad = 1 + (p_ptr->lev / 20); - } + return std::make_tuple(power->monster_spell_index, num); +} + +/* + * Apply the effect of a monster power + */ +static void apply_monster_power(monster_race const *r_ptr, std::size_t monster_spell_idx) +{ + assert(monster_spell_idx < monster_spell_flag_set::nbits); + + /* Shorthand */ + int const x = p_ptr->px; + int const y = p_ptr->py; + int const plev = p_ptr->lev; + int const rlev = ((r_ptr->level >= 1) ? r_ptr->level : 1); + + /* 'Powerful' monsters have wider radii */ + int rad = (r_ptr->flags & RF_POWERFUL) + ? 1 + (p_ptr->lev / 15) + : 1 + (p_ptr->lev / 20); /* Analyse power */ - switch (power) + switch (monster_spell_idx) { - /**** RF4 (bit position) ****/ - - /* SHRIEK */ - case 0: + case SF_SHRIEK_IDX: { aggravate_monsters( -1); break; } - /* MULTIPLY */ - case 1: + case SF_MULTIPLY_IDX: { do_cmd_wiz_named_friendly(p_ptr->body_monster, FALSE); break; } - /* S_ANIMAL */ - case 2: + case SF_S_ANIMAL_IDX: { summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE); break; } - /* ROCKET */ - case 3: + case SF_ROCKET_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_ROCKET, dir, p_ptr->lev * 12, 1 + (p_ptr->lev / 20)); @@ -898,9 +864,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* ARROW_1 */ - case 4: + case SF_ARROW_1_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_ARROW, dir, damroll(1, 6)); @@ -908,9 +874,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* ARROW_2 */ - case 5: + case SF_ARROW_2_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_ARROW, dir, damroll(3, 6)); @@ -918,9 +884,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* ARROW_3 */ - case 6: + case SF_ARROW_3_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_ARROW, dir, damroll(5, 6)); @@ -928,9 +894,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* ARROW_4 */ - case 7: + case SF_ARROW_4_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_ARROW, dir, damroll(7, 6)); @@ -938,9 +904,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_ACID */ - case 8: + case SF_BR_ACID_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_ACID, dir, p_ptr->lev * 5, rad); @@ -948,9 +914,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_ELEC */ - case 9: + case SF_BR_ELEC_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_ELEC, dir, p_ptr->lev * 5, rad); @@ -958,9 +924,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_FIRE */ - case 10: + case SF_BR_FIRE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_FIRE, dir, p_ptr->lev * 5, rad); @@ -968,9 +934,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_COLD */ - case 11: + case SF_BR_COLD_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_COLD, dir, p_ptr->lev * 5, rad); @@ -978,9 +944,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_POIS */ - case 12: + case SF_BR_POIS_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_POIS, dir, p_ptr->lev * 5, rad); @@ -988,9 +954,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_NETH */ - case 13: + case SF_BR_NETH_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_NETHER, dir, p_ptr->lev * 5, rad); @@ -998,9 +964,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_LITE */ - case 14: + case SF_BR_LITE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_LITE, dir, p_ptr->lev * 8, rad); @@ -1008,9 +974,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_DARK */ - case 15: + case SF_BR_DARK_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_DARK, dir, p_ptr->lev * 8, rad); @@ -1018,9 +984,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_CONF */ - case 16: + case SF_BR_CONF_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_CONFUSION, dir, p_ptr->lev * 8, rad); @@ -1028,9 +994,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_SOUN */ - case 17: + case SF_BR_SOUN_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_SOUND, dir, p_ptr->lev * 8, rad); @@ -1038,9 +1004,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_CHAO */ - case 18: + case SF_BR_CHAO_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_CHAOS, dir, p_ptr->lev * 7, rad); @@ -1048,9 +1014,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_DISE */ - case 19: + case SF_BR_DISE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_DISENCHANT, dir, p_ptr->lev * 7, rad); @@ -1058,9 +1024,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_NEXU */ - case 20: + case SF_BR_NEXU_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_NEXUS, dir, p_ptr->lev * 5, rad); @@ -1068,9 +1034,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_TIME */ - case 21: + case SF_BR_TIME_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_TIME, dir, p_ptr->lev * 3, rad); @@ -1078,9 +1044,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_INER */ - case 22: + case SF_BR_INER_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_INERTIA, dir, p_ptr->lev * 4, rad); @@ -1088,9 +1054,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_GRAV */ - case 23: + case SF_BR_GRAV_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_GRAVITY, dir, p_ptr->lev * 4, rad); @@ -1098,9 +1064,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_SHAR */ - case 24: + case SF_BR_SHAR_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_SHARDS, dir, p_ptr->lev * 8, rad); @@ -1108,9 +1074,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_PLAS */ - case 25: + case SF_BR_PLAS_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_PLASMA, dir, p_ptr->lev * 3, rad); @@ -1118,9 +1084,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_WALL */ - case 26: + case SF_BR_WALL_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_FORCE, dir, p_ptr->lev * 4, rad); @@ -1128,9 +1094,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_MANA */ - case 27: + case SF_BR_MANA_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_MANA, dir, p_ptr->lev * 5, rad); @@ -1138,9 +1104,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BA_NUKE */ - case 28: + case SF_BA_NUKE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_NUKE, dir, p_ptr->lev * 8, 1 + (p_ptr->lev / 20)); @@ -1148,9 +1114,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_NUKE */ - case 29: + case SF_BR_NUKE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_NUKE, dir, p_ptr->lev * 8, 1 + (p_ptr->lev / 20)); @@ -1158,9 +1124,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BA_CHAO */ - case 30: + case SF_BA_CHAO_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_CHAOS, dir, p_ptr->lev * 4, 2); @@ -1168,9 +1134,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BR_DISI */ - case 31: + case SF_BR_DISI_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_DISINTEGRATE, dir, p_ptr->lev * 5, 1 + (p_ptr->lev / 20)); @@ -1178,12 +1144,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - - /**** RF5 (bit position + 32) ****/ - - /* BA_ACID */ - case 32: + case SF_BA_ACID_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_ACID, dir, randint(p_ptr->lev * 6) + 20, 2); @@ -1191,9 +1154,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BA_ELEC */ - case 33: + case SF_BA_ELEC_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_ELEC, dir, randint(p_ptr->lev * 3) + 20, 2); @@ -1201,9 +1164,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BA_FIRE */ - case 34: + case SF_BA_FIRE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_FIRE, dir, randint(p_ptr->lev * 7) + 20, 2); @@ -1211,9 +1174,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BA_COLD */ - case 35: + case SF_BA_COLD_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_COLD, dir, randint(p_ptr->lev * 3) + 20, 2); @@ -1221,9 +1184,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BA_POIS */ - case 36: + case SF_BA_POIS_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_POIS, dir, damroll(12, 2), 2); @@ -1231,9 +1194,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BA_NETH */ - case 37: + case SF_BA_NETH_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_NETHER, dir, randint(p_ptr->lev * 4) + 20, 2); @@ -1241,9 +1204,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BA_WATE */ - case 38: + case SF_BA_WATE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_WATER, dir, randint(p_ptr->lev * 4) + 20, 2); @@ -1251,9 +1214,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BA_MANA */ - case 39: + case SF_BA_MANA_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_MANA, dir, randint(p_ptr->lev * 3) + 20, 2); @@ -1261,9 +1224,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BA_DARK */ - case 40: + case SF_BA_DARK_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_ball(GF_DARK, dir, randint(p_ptr->lev * 3) + 20, 2); @@ -1271,15 +1234,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* 41 DRAIN_MANA -- Not available */ - - /* 42 MIND_BLAST -- Not available */ - - /* 43 BRAIN_SMASH -- Not available */ - - /* CAUSE_1 */ - case 44: + case SF_CAUSE_1_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_MANA, dir, damroll(3, 8)); @@ -1287,9 +1244,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* CAUSE_2 */ - case 45: + case SF_CAUSE_2_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_MANA, dir, damroll(8, 8)); @@ -1297,9 +1254,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* CAUSE_3 */ - case 46: + case SF_CAUSE_3_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_MANA, dir, damroll(10, 15)); @@ -1307,9 +1264,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* CAUSE_4 */ - case 47: + case SF_CAUSE_4_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_MANA, dir, damroll(15, 15)); @@ -1317,9 +1274,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BO_ACID */ - case 48: + case SF_BO_ACID_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_ACID, dir, damroll(7, 8) + (p_ptr->lev / 3)); @@ -1327,9 +1284,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BO_ELEC */ - case 49: + case SF_BO_ELEC_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_ELEC, dir, damroll(4, 8) + (p_ptr->lev / 3)); @@ -1337,9 +1294,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BO_FIRE */ - case 50: + case SF_BO_FIRE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_FIRE, dir, damroll(9, 8) + (p_ptr->lev / 3)); @@ -1347,9 +1304,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BO_COLD */ - case 51: + case SF_BO_COLD_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_COLD, dir, damroll(6, 8) + (p_ptr->lev / 3)); @@ -1357,9 +1314,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BO_POIS */ - case 52: + case SF_BO_POIS_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_POIS, dir, damroll(7, 8) + (p_ptr->lev / 3)); @@ -1367,9 +1324,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BO_NETH */ - case 53: + case SF_BO_NETH_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_NETHER, dir, damroll(5, 5) + (p_ptr->lev / 3)); @@ -1377,9 +1334,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BO_WATE */ - case 54: + case SF_BO_WATE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_WATER, dir, damroll(10, 10) + (p_ptr->lev / 3)); @@ -1387,9 +1344,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BO_MANA */ - case 55: + case SF_BO_MANA_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_MANA, dir, damroll(3, 8) + (p_ptr->lev / 3)); @@ -1397,9 +1354,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BO_PLAS */ - case 56: + case SF_BO_PLAS_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_PLASMA, dir, damroll(8, 8) + (p_ptr->lev / 3)); @@ -1407,9 +1364,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BO_ICEE */ - case 57: + case SF_BO_ICEE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_ICE, dir, damroll(6, 6) + (p_ptr->lev / 3)); @@ -1417,9 +1374,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* MISSILE */ - case 58: + case SF_MISSILE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_MISSILE, dir, damroll(2, 6) + (p_ptr->lev / 3)); @@ -1427,9 +1384,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* SCARE */ - case 59: + case SF_SCARE_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fear_monster(dir, plev); @@ -1437,9 +1394,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BLIND */ - case 60: + case SF_BLIND_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_CONFUSION, dir, damroll(1, 8) + (p_ptr->lev / 3)); @@ -1447,9 +1404,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* CONF */ - case 61: + case SF_CONF_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_CONFUSION, dir, damroll(7, 8) + (p_ptr->lev / 3)); @@ -1457,9 +1414,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* SLOW */ - case 62: + case SF_SLOW_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_OLD_SLOW, dir, damroll(6, 8) + (p_ptr->lev / 3)); @@ -1467,9 +1424,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* HOLD */ - case 63: + case SF_HOLD_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_OLD_SLEEP, dir, damroll(5, 8) + (p_ptr->lev / 3)); @@ -1477,27 +1434,23 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - - /**** RF6 (bit position + 64) ****/ - - /* HASTE */ - case 64: + case SF_HASTE_IDX: { if (!p_ptr->fast) { - (void)set_fast(randint(20 + (plev) ) + plev, 10); + set_fast(randint(20 + (plev) ) + plev, 10); } else { - (void)set_fast(p_ptr->fast + randint(5), 10); + set_fast(p_ptr->fast + randint(5), 10); } break; } - /* HAND_DOOM */ - case 65: + case SF_HAND_DOOM_IDX: { + int dir; if (!get_aim_dir(&dir)) break; fire_bolt(GF_MANA, dir, damroll(10, 8) + (p_ptr->lev)); @@ -1505,18 +1458,16 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* HEAL */ - case 66: + case SF_HEAL_IDX: { hp_player(damroll(8, 5)); break; } - /* S_ANIMALS */ - case 67: + case SF_S_ANIMALS_IDX: { - for (k = 0; k < 4; k++) + for (int k = 0; k < 4; k++) { summon_specific_friendly(y, x, rlev, SUMMON_ANIMAL, TRUE); } @@ -1524,10 +1475,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* BLINK */ - case 68: + case SF_BLINK_IDX: { - if (dungeon_flags2 & DF2_NO_TELEPORT) + if (dungeon_flags & DF_NO_TELEPORT) { msg_print("No teleport on special levels..."); break; @@ -1538,10 +1488,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* TPORT */ - case 69: + case SF_TPORT_IDX: { - if (dungeon_flags2 & DF2_NO_TELEPORT) + if (dungeon_flags & DF_NO_TELEPORT) { msg_print("No teleport on special levels..."); break; @@ -1552,12 +1501,11 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* TELE_TO */ - case 70: + case SF_TELE_TO_IDX: { int ii, ij; - if (dungeon_flags2 & DF2_NO_TELEPORT) + if (dungeon_flags & DF_NO_TELEPORT) { msg_print("No teleport on special levels..."); break; @@ -1570,8 +1518,8 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost p_ptr->energy -= 60 - plev; if (!cave_empty_bold(ij, ii) || - (cave[ij][ii].info & CAVE_ICKY) || - (distance(ij, ii, p_ptr->py, p_ptr->px) > plev * 20 + 2)) + (cave[ij][ii].info & CAVE_ICKY) || + (distance(ij, ii, p_ptr->py, p_ptr->px) > plev * 20 + 2)) { msg_print("You fail to show the destination correctly!"); p_ptr->energy -= 100; @@ -1582,26 +1530,25 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* TELE_AWAY */ - case 71: + case SF_TELE_AWAY_IDX: { - if (dungeon_flags2 & DF2_NO_TELEPORT) + if (dungeon_flags & DF_NO_TELEPORT) { msg_print("No teleport on special levels..."); break; } + int dir; if (!get_aim_dir(&dir)) break; - (void)fire_beam(GF_AWAY_ALL, dir, plev); + fire_beam(GF_AWAY_ALL, dir, plev); break; } - /* TELE_LEVEL */ - case 72: + case SF_TELE_LEVEL_IDX: { - if (dungeon_flags2 & DF2_NO_TELEPORT) + if (dungeon_flags & DF_NO_TELEPORT) { msg_print("No teleport on special levels..."); break; @@ -1612,11 +1559,10 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* DARKNESS */ - case 73: + case SF_DARKNESS_IDX: { - (void)project( -1, 3, p_ptr->py, p_ptr->px, 0, GF_DARK_WEAK, - PROJECT_GRID | PROJECT_KILL); + project( -1, 3, p_ptr->py, p_ptr->px, 0, GF_DARK_WEAK, + PROJECT_GRID | PROJECT_KILL); /* Unlite the room */ unlite_room(p_ptr->py, p_ptr->px); @@ -1624,34 +1570,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* TRAPS */ - case 74: + case SF_S_THUNDERLORD_IDX: { - trap_creation(); - - break; - } - - /* 75 FORGET -- Not available */ - - /* ANIM_DEAD -- Use the same code as the nether spell */ - case 76: - { - if (!get_aim_dir(&dir)) break; - - fire_ball(GF_RAISE, dir, 1, 0); - - break; - } - - /* 77 S_BUG -- Not available, well we do that anyway ;) */ - - /* 78 S_RNG -- Not available, who dares? */ - - /* S_THUNDERLORD */ - case 79: - { - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { summon_specific_friendly(y, x, rlev, SUMMON_THUNDERLORD, TRUE); } @@ -1659,13 +1580,12 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_KIN -- Summon Kin, because we code bugs :) */ - case 80: + case SF_S_KIN_IDX: { /* Big hack */ summon_kin_type = r_ptr->d_char; - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { summon_specific_friendly(y, x, rlev, SUMMON_KIN, TRUE); } @@ -1673,10 +1593,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_HI_DEMON */ - case 81: + case SF_S_HI_DEMON_IDX: { - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { summon_specific_friendly(y, x, rlev, SUMMON_HI_DEMON, TRUE); } @@ -1684,10 +1603,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_MONSTER */ - case 82: + case SF_S_MONSTER_IDX: { - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { summon_specific_friendly(y, x, rlev, 0, TRUE); } @@ -1695,10 +1613,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_MONSTERS */ - case 83: + case SF_S_MONSTERS_IDX: { - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { summon_specific_friendly(y, x, rlev, 0, TRUE); } @@ -1706,10 +1623,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_ANT */ - case 84: + case SF_S_ANT_IDX: { - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { summon_specific_friendly(y, x, rlev, SUMMON_ANT, TRUE); } @@ -1717,10 +1633,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_SPIDER */ - case 85: + case SF_S_SPIDER_IDX: { - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { summon_specific_friendly(y, x, rlev, SUMMON_SPIDER, TRUE); } @@ -1728,10 +1643,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_HOUND */ - case 86: + case SF_S_HOUND_IDX: { - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { summon_specific_friendly(y, x, rlev, SUMMON_HOUND, TRUE); } @@ -1739,10 +1653,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_HYDRA */ - case 87: + case SF_S_HYDRA_IDX: { - for (k = 0; k < 6; k++) + for (int k = 0; k < 6; k++) { summon_specific_friendly(y, x, rlev, SUMMON_HYDRA, TRUE); } @@ -1750,10 +1663,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_ANGEL */ - case 88: + case SF_S_ANGEL_IDX: { - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { summon_specific_friendly(y, x, rlev, SUMMON_ANGEL, TRUE); } @@ -1761,10 +1673,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_DEMON */ - case 89: + case SF_S_DEMON_IDX: { - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { summon_specific_friendly(y, x, rlev, SUMMON_DEMON, TRUE); } @@ -1772,10 +1683,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_UNDEAD */ - case 90: + case SF_S_UNDEAD_IDX: { - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { summon_specific_friendly(y, x, rlev, SUMMON_UNDEAD, TRUE); } @@ -1783,10 +1693,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_DRAGON */ - case 91: + case SF_S_DRAGON_IDX: { - for (k = 0; k < 1; k++) + for (int k = 0; k < 1; k++) { summon_specific_friendly(y, x, rlev, SUMMON_DRAGON, TRUE); } @@ -1794,10 +1703,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_HI_UNDEAD */ - case 92: + case SF_S_HI_UNDEAD_IDX: { - for (k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { summon_specific_friendly(y, x, rlev, SUMMON_HI_UNDEAD_NO_UNIQUES, TRUE); } @@ -1805,10 +1713,9 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_HI_DRAGON */ - case 93: + case SF_S_HI_DRAGON_IDX: { - for (k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { summon_specific_friendly(y, x, rlev, SUMMON_HI_DRAGON_NO_UNIQUES, TRUE); } @@ -1816,38 +1723,43 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost break; } - /* S_WRAITH */ - case 94: + case SF_S_WRAITH_IDX: { - for (k = 0; k < 8; k++) + for (int k = 0; k < 8; k++) { summon_specific_friendly(y, x, rlev, SUMMON_WRAITH, TRUE); } break; } - - /* 95 S_UNIQUE -- Not available */ } +} - /* Take some SP */ - if (!no_cost) - { - int chance, pchance; - - chance = (monster_powers[power].mana + r_ptr->level); - pchance = adj_str_wgt[p_ptr->stat_ind[A_WIS]] / 2 + get_skill(SKILL_POSSESSION); - if (rand_int(chance) >= pchance) - { - int m = monster_powers[power].mana / 10; +/* + * Use a monster power and call the given callback. + */ +static int use_monster_power_aux(monster_race const *r_ptr, bool great, bool symbiosis, std::function<void(monster_power const *power)> f) +{ + int power; + int num; + std::tie(power, num) = choose_monster_power(r_ptr, great, symbiosis); + + // Early exit? + if (power == 0) { + // No powers available + return 0; + } else if (power < 0) { + // Canceled by user + energy_use = 0; + return -1; + } - if (m > p_ptr->msp) m = p_ptr->msp; - if (!m) m = 1; + // Apply the effect + apply_monster_power(r_ptr, power); - p_ptr->csp -= m; - } - } + // Post-processing + f(&monster_powers[power]); /* Redraw mana */ p_ptr->redraw |= (PR_FRAME); @@ -1858,6 +1770,38 @@ int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost return (num); } +/** + * Use a power of the monster in symbiosis + */ +int use_symbiotic_power(int r_idx, bool great) +{ + auto const &r_info = game->edit_data.r_info; + + monster_race const *r_ptr = &r_info[r_idx]; + return use_monster_power_aux(r_ptr, great, true, [](monster_power const *) { + // Don't need to do anything post-cast. + }); +} + +/** + * Use a power of a possessed body. + */ +void use_monster_power(int r_idx, bool great) +{ + auto const &r_info = game->edit_data.r_info; + + monster_race const *r_ptr = &r_info[r_idx]; + use_monster_power_aux(r_ptr, great, false, [r_ptr](monster_power const *power) { + // Sometimes give a free cast. + int chance = (power->mana + r_ptr->level); + int pchance = adj_str_wgt[p_ptr->stat_ind[A_WIS]] / 2 + get_skill(SKILL_POSSESSION); + if (rand_int(chance) >= pchance) + { + p_ptr->csp -= calc_monster_spell_mana(power); + } + }); +} + /* * Schooled magic */ @@ -1888,11 +1832,10 @@ boost::optional<int> get_item_hook_find_spell(object_filter_t const &) object_type *o_ptr = &p_ptr->inventory[i]; /* Extract object flags */ - u32b f1, f2, f3, f4, f5, esp; - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Must we wield it to cast from it? */ - if ((wield_slot(o_ptr) != -1) && (i < INVEN_WIELD) && (f5 & TR5_WIELD_CAST)) + if ((wield_slot(o_ptr) != -1) && (i < INVEN_WIELD) && (flags & TR_WIELD_CAST)) { continue; } @@ -1901,7 +1844,7 @@ boost::optional<int> get_item_hook_find_spell(object_filter_t const &) if (!is_school_book()(o_ptr)) { /* Does it contain the appropriate spell? */ - if ((f5 & TR5_SPELL_CONTAIN) && (o_ptr->pval2 == spell)) + if ((flags & TR_SPELL_CONTAIN) && (o_ptr->pval2 == spell)) { hack_force_spell = spell; hack_force_spell_pval = o_ptr->pval; @@ -1961,7 +1904,6 @@ s32b get_school_spell(cptr do_what, s16b force_book) object_type *o_ptr, forge; int tmp; int sval, pval; - u32b f1, f2, f3, f4, f5, esp; hack_force_spell = -1; hack_force_spell_pval = -1; @@ -1987,10 +1929,10 @@ s32b get_school_spell(cptr do_what, s16b force_book) /* Get the item */ o_ptr = get_object(item); - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const f = object_flags(o_ptr); /* If it can be wielded, it must */ - if ((wield_slot(o_ptr) != -1) && (item < INVEN_WIELD) && (f5 & TR5_WIELD_CAST)) + if ((wield_slot(o_ptr) != -1) && (item < INVEN_WIELD) && (f & TR_WIELD_CAST)) { msg_format("You cannot %s from that object; it must be wielded first.", do_what); return -1; @@ -2178,10 +2120,9 @@ void cast_school_spell() /* Can it contains a schooled spell ? */ static bool hook_school_can_spellable(object_type const *o_ptr) { - u32b f1, f2, f3, f4, f5, esp; - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const f = object_flags(o_ptr); - return ((f5 & TR5_SPELL_CONTAIN) && (o_ptr->pval2 == -1)); + return ((f & TR_SPELL_CONTAIN) && (o_ptr->pval2 == -1)); } /* diff --git a/src/cmd5.hpp b/src/cmd5.hpp index 1b3b062a..d25efb73 100644 --- a/src/cmd5.hpp +++ b/src/cmd5.hpp @@ -2,15 +2,22 @@ #include "h-basic.h" #include "object_type_fwd.hpp" +#include "monster_race_fwd.hpp" +#include "monster_power_fwd.hpp" -extern bool_ is_magestaff(void); -extern void do_cmd_browse_aux(object_type *o_ptr); -extern void do_cmd_browse(void); -extern void fetch(int dir, int wgt, bool_ require_los); -extern void do_poly_self(void); -extern cptr symbiote_name(bool_ capitalize); -extern int use_symbiotic_power(int r_idx, bool_ great, bool_ only_number, bool_ no_cost); -extern bool_ is_ok_spell(s32b spell_idx, s32b pval); -extern s32b get_school_spell(cptr do_what, s16b force_book); -extern void do_cmd_copy_spell(void); -extern void cast_school_spell(void); +#include <string> +#include <vector> + +bool_ is_magestaff(); +void do_cmd_browse_aux(object_type *o_ptr); +void do_cmd_browse(); +void fetch(int dir, int wgt, bool_ require_los); +void do_poly_self(); +std::string symbiote_name(bool capitalize); +int use_symbiotic_power(int r_idx, bool great); +void use_monster_power(int r_idx, bool great); +bool_ is_ok_spell(s32b spell_idx, s32b pval); +s32b get_school_spell(cptr do_what, s16b force_book); +void do_cmd_copy_spell(); +void cast_school_spell(); +std::vector<monster_power const *> extract_monster_powers(monster_race const *r_ptr, bool great); diff --git a/src/cmd6.cc b/src/cmd6.cc index 0a5595fa..e36f0cb6 100644 --- a/src/cmd6.cc +++ b/src/cmd6.cc @@ -14,9 +14,11 @@ #include "cmd1.hpp" #include "cmd7.hpp" #include "corrupt.hpp" +#include "dungeon_flag.hpp" #include "dungeon_info_type.hpp" #include "ego_item_type.hpp" #include "files.hpp" +#include "game.hpp" #include "hook_eat_in.hpp" #include "hook_eat_out.hpp" #include "hooks.hpp" @@ -24,12 +26,16 @@ #include "mimic.hpp" #include "monster2.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" +#include "monster_spell_flag.hpp" #include "monster_type.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_flag.hpp" #include "object_kind.hpp" #include "object_type.hpp" #include "options.hpp" +#include "player_race_flag.hpp" #include "player_type.hpp" #include "randart.hpp" #include "skills.hpp" @@ -55,12 +61,6 @@ using boost::algorithm::iequals; /* - * Forward declare - */ -static bool_ activate_spell(object_type * o_ptr, byte choice); - - -/* * General function to find an item by its name */ static select_by_name_t select_object_by_name(std::string const &prompt) @@ -148,7 +148,9 @@ static select_by_name_t select_object_by_name(std::string const &prompt) */ static void corpse_effect(object_type *o_ptr, bool_ cutting) { - monster_race *r_ptr = &r_info[o_ptr->pval2]; + auto const &r_info = game->edit_data.r_info; + + auto r_ptr = &r_info[o_ptr->pval2]; /* Assume no bad effects */ bool_ harmful = FALSE; @@ -538,7 +540,7 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) */ /* Acid */ - if (r_ptr->flags4 & RF4_BR_ACID && brpow > 0) + if ((r_ptr->spells & SF_BR_ACID) && brpow > 0) { brdam = ((brpow / 3) > 1600 ? 1600 : (brpow / 3)); @@ -553,13 +555,13 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) } o_ptr->pval = 1; } - else if (r_ptr->flags4 & RF4_BR_ACID) + else if (r_ptr->spells & SF_BR_ACID) { set_oppose_acid(p_ptr->oppose_acid + rand_int(10) + 10); } /* Electricity */ - if (r_ptr->flags4 & RF4_BR_ELEC && brpow > 0) + if ((r_ptr->spells & SF_BR_ELEC) && brpow > 0) { brdam = ((brpow / 3) > 1600 ? 1600 : (brpow / 3)); @@ -575,13 +577,13 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) o_ptr->weight = o_ptr->weight - brpow; o_ptr->pval = o_ptr->weight; } - else if (r_ptr->flags4 & RF4_BR_ELEC) + else if (r_ptr->spells & SF_BR_ELEC) { set_oppose_elec(p_ptr->oppose_elec + rand_int(10) + 10); } /* Fire */ - if (r_ptr->flags4 & RF4_BR_FIRE && brpow > 0) + if ((r_ptr->spells & SF_BR_FIRE) && brpow > 0) { brdam = ((brpow / 3) > 1600 ? 1600 : (brpow / 3)); @@ -596,13 +598,13 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) } o_ptr->pval = 1; } - else if (r_ptr->flags4 & RF4_BR_FIRE) + else if (r_ptr->spells & SF_BR_FIRE) { set_oppose_fire(p_ptr->oppose_fire + rand_int(10) + 10); } /* Cold */ - if (r_ptr->flags4 & RF4_BR_COLD && brpow > 0) + if ((r_ptr->spells & SF_BR_COLD) && brpow > 0) { brdam = ((brpow / 3) > 1600 ? 1600 : (brpow / 3)); @@ -618,13 +620,13 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) o_ptr->weight = o_ptr->weight - brpow; o_ptr->pval = o_ptr->weight; } - else if (r_ptr->flags4 & RF4_BR_COLD) + else if (r_ptr->spells & SF_BR_COLD) { set_oppose_cold(p_ptr->oppose_cold + rand_int(10) + 10); } /* Poison */ - if (r_ptr->flags4 & RF4_BR_POIS && brpow > 0) + if ((r_ptr->spells & SF_BR_POIS) && brpow > 0) { brdam = ((brpow / 3) > 800 ? 800 : (brpow / 3)); @@ -636,7 +638,7 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) if (!(p_ptr->resist_pois || p_ptr->oppose_pois)) { - (void)set_poisoned(p_ptr->poisoned + rand_int(brdam) + 10); + set_poisoned(p_ptr->poisoned + rand_int(brdam) + 10); } /* Take damage */ @@ -647,7 +649,7 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) } /* Nether */ - if (r_ptr->flags4 & RF4_BR_NETH && brpow > 0) + if ((r_ptr->spells & SF_BR_NETH) && brpow > 0) { brdam = ((brpow / 6) > 550 ? 550 : (brpow / 6)); @@ -684,7 +686,7 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) } /* Confusion */ - if (r_ptr->flags4 & RF4_BR_CONF && brpow > 0) + if ((r_ptr->spells & SF_BR_CONF) && brpow > 0) { msg_print("A strange liquid splashes on you!"); @@ -697,7 +699,7 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) } /* Chaos */ - if (r_ptr->flags4 & RF4_BR_CHAO && brpow > 0) + if ((r_ptr->spells & SF_BR_CHAO) && brpow > 0) { brdam = ((brpow / 6) > 600 ? 600 : (brpow / 6)); @@ -711,12 +713,12 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) if (!p_ptr->resist_conf) { - (void)set_confused(p_ptr->confused + rand_int(20) + 10); + set_confused(p_ptr->confused + rand_int(20) + 10); } if (!p_ptr->resist_chaos) { - (void)set_image(p_ptr->image + randint(10)); + set_image(p_ptr->image + randint(10)); } if (!p_ptr->resist_neth && !p_ptr->resist_chaos) @@ -743,7 +745,7 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) } /* Disenchantment */ - if (r_ptr->flags4 & RF4_BR_DISE && brpow > 0) + if ((r_ptr->spells & SF_BR_DISE) && brpow > 0) { brdam = ((brpow / 6) > 500 ? 500 : (brpow / 6)); @@ -756,7 +758,7 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) } else { - (void)apply_disenchant(0); + apply_disenchant(0); } /* Take damage */ @@ -765,7 +767,7 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) } /* Plasma */ - if (r_ptr->flags4 & RF4_BR_PLAS && brpow > 0) + if ((r_ptr->spells & SF_BR_PLAS) && brpow > 0) { brdam = ((brpow / 6) > 150 ? 150 : (brpow / 6)); @@ -777,7 +779,7 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) if (!p_ptr->resist_sound) { int k = (randint((brdam > 40) ? 35 : (brdam * 3 / 4 + 5))); - (void)set_stun(p_ptr->stun + k); + set_stun(p_ptr->stun + k); } /* Take damage */ @@ -787,7 +789,7 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) } /* Hack -- Jellies are immune to acid only if they are already acidic */ - if (strchr("j", r_ptr->d_char) && (r_ptr->flags3 & RF3_IM_ACID)) + if (strchr("j", r_ptr->d_char) && (r_ptr->flags & RF_IM_ACID)) { dam = damroll(8, 8); @@ -809,7 +811,7 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) * are immune to poison because their body already contains * poisonous chemicals. */ - if (strchr("ijkmS,", r_ptr->d_char) && (r_ptr->flags3 & RF3_IM_POIS)) + if (strchr("ijkmS,", r_ptr->d_char) && (r_ptr->flags & RF_IM_POIS)) { if (!(p_ptr->resist_pois || p_ptr->oppose_pois)) { @@ -824,82 +826,82 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) */ if (!harmful && !cutting && (o_ptr->sval != SV_CORPSE_MEAT)) { - if (r_ptr->flags3 & RF3_IM_ACID) + if (r_ptr->flags & RF_IM_ACID) { set_oppose_acid(p_ptr->oppose_acid + rand_int(10) + 10); } - if (r_ptr->flags3 & RF3_IM_ELEC) + if (r_ptr->flags & RF_IM_ELEC) { set_oppose_elec(p_ptr->oppose_elec + rand_int(10) + 10); } - if (r_ptr->flags3 & RF3_IM_FIRE) + if (r_ptr->flags & RF_IM_FIRE) { set_oppose_fire(p_ptr->oppose_fire + rand_int(10) + 10); } - if (r_ptr->flags3 & RF3_IM_COLD) + if (r_ptr->flags & RF_IM_COLD) { set_oppose_cold(p_ptr->oppose_cold + rand_int(10) + 10); } - if (r_ptr->flags3 & RF3_IM_POIS) + if (r_ptr->flags & RF_IM_POIS) { set_oppose_pois(p_ptr->oppose_pois + rand_int(10) + 10); } - if (r_ptr->flags3 & RF3_RES_NETH) + if (r_ptr->flags & RF_RES_NETH) { set_protevil(p_ptr->protevil + rand_int(25) + 3 * r_ptr->level); } - if (r_ptr->flags3 & RF3_RES_PLAS) + if (r_ptr->flags & RF_RES_PLAS) { set_oppose_fire(p_ptr->oppose_fire + rand_int(20) + 20); } - if (r_ptr->flags2 & RF2_SHAPECHANGER) + if (r_ptr->flags & RF_SHAPECHANGER) { - /* DGDGDG (void)set_mimic(20 , rand_int(MIMIC_VALAR)); */ + /* DGDGDG set_mimic(20 , rand_int(MIMIC_VALAR)); */ } - if (r_ptr->flags3 & RF3_DEMON) + if (r_ptr->flags & RF_DEMON) { - /* DGDGDG (void)set_mimic(30 , MIMIC_DEMON); */ + /* DGDGDG set_mimic(30 , MIMIC_DEMON); */ } - if (r_ptr->flags3 & RF3_UNDEAD) + if (r_ptr->flags & RF_UNDEAD) { - /* DGDGDG (void)set_mimic(30 , MIMIC_VAMPIRE); */ + /* DGDGDG set_mimic(30 , MIMIC_VAMPIRE); */ } - if (r_ptr->flags3 & RF3_NO_FEAR) + if (r_ptr->flags & RF_NO_FEAR) { - (void)set_afraid(0); + set_afraid(0); } - if (r_ptr->flags3 & RF3_NO_STUN) + if (r_ptr->flags & RF_NO_STUN) { - (void)set_stun(0); + set_stun(0); } - if (r_ptr->flags3 & RF3_NO_CONF) + if (r_ptr->flags & RF_NO_CONF) { - (void)set_confused(0); + set_confused(0); } - if (r_ptr->flags6 & RF6_S_THUNDERLORD) + if (r_ptr->spells & SF_S_THUNDERLORD) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_THUNDERLORD, FALSE); } - if (r_ptr->flags6 & RF6_S_DEMON) + if (r_ptr->spells & SF_S_DEMON) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_DEMON, FALSE); } - if (r_ptr->flags6 & RF6_S_KIN) + if (r_ptr->spells & SF_S_KIN) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_KIN, FALSE); } - if (r_ptr->flags6 & RF6_S_HI_DEMON) + if (r_ptr->spells & SF_S_HI_DEMON) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_HI_DEMON, FALSE); } - if (r_ptr->flags6 & RF6_S_MONSTER) + if (r_ptr->spells & SF_S_MONSTER) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, 0, FALSE); } - if (r_ptr->flags6 & RF6_S_MONSTERS) + if (r_ptr->spells & SF_S_MONSTERS) { int k; for (k = 0; k < 8; k++) @@ -907,47 +909,47 @@ static void corpse_effect(object_type *o_ptr, bool_ cutting) summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, 0, FALSE); } } - if (r_ptr->flags6 & RF6_S_UNDEAD) + if (r_ptr->spells & SF_S_UNDEAD) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_UNDEAD, FALSE); } - if (r_ptr->flags6 & RF6_S_DRAGON) + if (r_ptr->spells & SF_S_DRAGON) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_DRAGON, FALSE); } - if (r_ptr->flags6 & RF6_S_ANT) + if (r_ptr->spells & SF_S_ANT) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_ANT, FALSE); } - if (r_ptr->flags6 & RF6_S_SPIDER) + if (r_ptr->spells & SF_S_SPIDER) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_SPIDER, FALSE); } - if (r_ptr->flags6 & RF6_S_HOUND) + if (r_ptr->spells & SF_S_HOUND) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_HOUND, FALSE); } - if (r_ptr->flags6 & RF6_S_HYDRA) + if (r_ptr->spells & SF_S_HYDRA) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_HYDRA, FALSE); } - if (r_ptr->flags6 & RF6_S_ANGEL) + if (r_ptr->spells & SF_S_ANGEL) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_ANGEL, FALSE); } - if (r_ptr->flags6 & RF6_S_HI_DRAGON) + if (r_ptr->spells & SF_S_HI_DRAGON) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_HI_DRAGON, FALSE); } - if (r_ptr->flags6 & RF6_S_HI_UNDEAD) + if (r_ptr->spells & SF_S_HI_UNDEAD) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_HI_UNDEAD, FALSE); } - if (r_ptr->flags6 & RF6_S_WRAITH) + if (r_ptr->spells & SF_S_WRAITH) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_WRAITH, FALSE); } - if (r_ptr->flags6 & RF6_S_UNIQUE) + if (r_ptr->spells & SF_S_UNIQUE) { summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_UNIQUE, FALSE); } @@ -972,14 +974,15 @@ static object_filter_t const &item_tester_hook_eatable() /* * Eat some food (from the pack or floor) */ -void do_cmd_eat_food(void) +void do_cmd_eat_food() { + auto const &r_info = game->edit_data.r_info; + auto const &k_info = game->edit_data.k_info; + int ident, lev, fval = 0; object_type *q_ptr, forge; - monster_race *r_ptr; - bool_ destroy = TRUE; /* Get an item */ @@ -997,10 +1000,6 @@ void do_cmd_eat_food(void) /* Get the item */ object_type *o_ptr = get_object(item); - /* Sound */ - sound(SOUND_EAT); - - /* Take a turn */ energy_use = 100; @@ -1114,7 +1113,7 @@ void do_cmd_eat_food(void) case SV_FOOD_WEAKNESS: { take_hit(damroll(6, 6), "poisonous food"); - (void)do_dec_stat(A_STR, STAT_DEC_NORMAL); + do_dec_stat(A_STR, STAT_DEC_NORMAL); ident = TRUE; @@ -1124,7 +1123,7 @@ void do_cmd_eat_food(void) case SV_FOOD_SICKNESS: { take_hit(damroll(6, 6), "poisonous food"); - (void)do_dec_stat(A_CON, STAT_DEC_NORMAL); + do_dec_stat(A_CON, STAT_DEC_NORMAL); ident = TRUE; @@ -1134,7 +1133,7 @@ void do_cmd_eat_food(void) case SV_FOOD_STUPIDITY: { take_hit(damroll(8, 8), "poisonous food"); - (void)do_dec_stat(A_INT, STAT_DEC_NORMAL); + do_dec_stat(A_INT, STAT_DEC_NORMAL); ident = TRUE; @@ -1144,7 +1143,7 @@ void do_cmd_eat_food(void) case SV_FOOD_NAIVETY: { take_hit(damroll(8, 8), "poisonous food"); - (void)do_dec_stat(A_WIS, STAT_DEC_NORMAL); + do_dec_stat(A_WIS, STAT_DEC_NORMAL); ident = TRUE; @@ -1154,7 +1153,7 @@ void do_cmd_eat_food(void) case SV_FOOD_UNHEALTH: { take_hit(damroll(10, 10), "poisonous food"); - (void)do_dec_stat(A_CON, STAT_DEC_NORMAL); + do_dec_stat(A_CON, STAT_DEC_NORMAL); ident = TRUE; @@ -1164,7 +1163,7 @@ void do_cmd_eat_food(void) case SV_FOOD_DISEASE: { take_hit(damroll(10, 10), "poisonous food"); - (void)do_dec_stat(A_STR, STAT_DEC_NORMAL); + do_dec_stat(A_STR, STAT_DEC_NORMAL); ident = TRUE; @@ -1308,8 +1307,8 @@ void do_cmd_eat_food(void) case SV_FOOD_WAYBREAD: { msg_print("That tastes very good."); - (void)set_poisoned(0); - (void)hp_player(damroll(4, 8)); + set_poisoned(0); + hp_player(damroll(4, 8)); set_food(PY_FOOD_MAX - 1); ident = TRUE; @@ -1330,7 +1329,7 @@ void do_cmd_eat_food(void) object_aware(q_ptr); object_known(q_ptr); q_ptr->ident |= IDENT_STOREB; - (void)inven_carry(q_ptr, FALSE); + inven_carry(q_ptr, FALSE); break; } @@ -1339,9 +1338,9 @@ void do_cmd_eat_food(void) { msg_print("A fresh, clean essence rises, driving away wounds and poison."); - (void)set_poisoned(0); - (void)set_stun(0); - (void)set_cut(0); + set_poisoned(0); + set_stun(0); + set_cut(0); if (p_ptr->black_breath) { msg_print("The hold of the Black Breath on you is broken!"); @@ -1358,7 +1357,7 @@ void do_cmd_eat_food(void) /* Corpses... */ else { - r_ptr = &r_info[o_ptr->pval2]; + auto r_ptr = &r_info[o_ptr->pval2]; /* Analyse the corpse */ switch (o_ptr->sval) @@ -1370,7 +1369,7 @@ void do_cmd_eat_food(void) /* Not all is edible. Apologies if messy. */ /* Check weight -- they have to have some meat left */ - if (r_ptr->flags9 & RF9_DROP_SKELETON) + if (r_ptr->flags & RF_DROP_SKELETON) { if (o_ptr->weight <= (r_ptr->weight * 3) / 5) { @@ -1491,10 +1490,10 @@ void do_cmd_eat_food(void) /* Food can feed the player, in a different ways */ /* Vampires */ - if ((race_flags1_p(PR1_VAMPIRE)) || (p_ptr->mimic_form == resolve_mimic_name("Vampire"))) + if ((race_flags_p(PR_VAMPIRE)) || (p_ptr->mimic_form == resolve_mimic_name("Vampire"))) { /* Reduced nutritional benefit */ - /* (void)set_food(p_ptr->food + (fval / 10)); -- No more */ + /* set_food(p_ptr->food + (fval / 10)); -- No more */ msg_print("Mere victuals hold scant sustenance for a being such as yourself."); /* Hungry */ @@ -1504,9 +1503,9 @@ void do_cmd_eat_food(void) } } - else if (race_flags1_p(PR1_NO_FOOD)) + else if (race_flags_p(PR_NO_FOOD)) { - if (race_flags1_p(PR1_UNDEAD)) + if (race_flags_p(PR_UNDEAD)) { msg_print("The food of mortals is poor sustenance for you."); } @@ -1520,7 +1519,7 @@ void do_cmd_eat_food(void) /* Those living in fresh */ else { - (void)set_food(p_ptr->food + fval); + set_food(p_ptr->food + fval); } @@ -1535,8 +1534,10 @@ void do_cmd_eat_food(void) /* * Cut a corpse up for convenient storage */ -void do_cmd_cut_corpse(void) +void do_cmd_cut_corpse() { + auto const &r_info = game->edit_data.r_info; + int item, meat = 0, not_meat = 0; /* Get an item */ @@ -1552,7 +1553,7 @@ void do_cmd_cut_corpse(void) /* Get the item */ object_type *o_ptr = get_object(item); - monster_race *r_ptr = &r_info[o_ptr->pval2]; + auto r_ptr = &r_info[o_ptr->pval2]; if ((o_ptr->sval != SV_CORPSE_CORPSE) && (o_ptr->sval != SV_CORPSE_HEAD)) { @@ -1564,7 +1565,7 @@ void do_cmd_cut_corpse(void) { case SV_CORPSE_CORPSE: { - if (r_ptr->flags9 & RF9_DROP_SKELETON) + if (r_ptr->flags & RF_DROP_SKELETON) { not_meat = (r_ptr->weight * 3) / 5; } @@ -1634,7 +1635,7 @@ void do_cmd_cut_corpse(void) * * Salt water works well. */ -void do_cmd_cure_meat(void) +void do_cmd_cure_meat() { int item, num, cure; @@ -1813,9 +1814,9 @@ static bool_ quaff_potion(int tval, int sval, int pval, int pval2) case SV_POTION_SALT_WATER: { msg_print("The potion makes you vomit!"); - (void)set_food(PY_FOOD_STARVE - 1); - (void)set_poisoned(0); - (void)set_paralyzed(4); + set_food(PY_FOOD_STARVE - 1); + set_poisoned(0); + set_paralyzed(4); ident = TRUE; break; @@ -1907,12 +1908,12 @@ static bool_ quaff_potion(int tval, int sval, int pval, int pval2) { msg_print("Your nerves and muscles feel weak and lifeless!"); take_hit(damroll(10, 10), "a potion of Ruination"); - (void)dec_stat(A_DEX, 25, TRUE); - (void)dec_stat(A_WIS, 25, TRUE); - (void)dec_stat(A_CON, 25, TRUE); - (void)dec_stat(A_STR, 25, TRUE); - (void)dec_stat(A_CHR, 25, TRUE); - (void)dec_stat(A_INT, 25, TRUE); + dec_stat(A_DEX, 25, TRUE); + dec_stat(A_WIS, 25, TRUE); + dec_stat(A_CON, 25, TRUE); + dec_stat(A_STR, 25, TRUE); + dec_stat(A_CHR, 25, TRUE); + dec_stat(A_INT, 25, TRUE); ident = TRUE; break; @@ -1964,8 +1965,8 @@ static bool_ quaff_potion(int tval, int sval, int pval, int pval2) { msg_print("Massive explosions rupture your body!"); take_hit(damroll(50, 20), "a potion of Detonation"); - (void)set_stun(p_ptr->stun + 75); - (void)set_cut(p_ptr->cut + 5000); + set_stun(p_ptr->stun + 75); + set_cut(p_ptr->cut + 5000); ident = TRUE; break; @@ -2029,7 +2030,7 @@ static bool_ quaff_potion(int tval, int sval, int pval, int pval2) } else { - (void)set_fast(p_ptr->fast + 5, 10); + set_fast(p_ptr->fast + 5, 10); } break; @@ -2133,18 +2134,18 @@ static bool_ quaff_potion(int tval, int sval, int pval, int pval2) msg_print("You feel life flow through your body!"); restore_level(); hp_player(5000); - (void)set_poisoned(0); - (void)set_blind(0); - (void)set_confused(0); - (void)set_image(0); - (void)set_stun(0); - (void)set_cut(0); - (void)do_res_stat(A_STR, TRUE); - (void)do_res_stat(A_CON, TRUE); - (void)do_res_stat(A_DEX, TRUE); - (void)do_res_stat(A_WIS, TRUE); - (void)do_res_stat(A_INT, TRUE); - (void)do_res_stat(A_CHR, TRUE); + set_poisoned(0); + set_blind(0); + set_confused(0); + set_image(0); + set_stun(0); + set_cut(0); + do_res_stat(A_STR, TRUE); + do_res_stat(A_CON, TRUE); + do_res_stat(A_DEX, TRUE); + do_res_stat(A_WIS, TRUE); + do_res_stat(A_INT, TRUE); + do_res_stat(A_CHR, TRUE); if (p_ptr->black_breath) { msg_print("The hold of the Black Breath on you is broken!"); @@ -2287,26 +2288,14 @@ static bool_ quaff_potion(int tval, int sval, int pval, int pval2) msg_print("You begin to feel more enlightened..."); msg_print(NULL); wiz_lite_extra(); - (void)do_inc_stat(A_INT); - (void)do_inc_stat(A_WIS); - (void)detect_traps(DEFAULT_RADIUS); - (void)detect_doors(DEFAULT_RADIUS); - (void)detect_stairs(DEFAULT_RADIUS); - (void)detect_treasure(DEFAULT_RADIUS); - (void)detect_objects_gold(DEFAULT_RADIUS); - (void)detect_objects_normal(DEFAULT_RADIUS); + do_inc_stat(A_INT); + do_inc_stat(A_WIS); + detect_doors(DEFAULT_RADIUS); + detect_stairs(DEFAULT_RADIUS); + detect_treasure(DEFAULT_RADIUS); + detect_objects_gold(DEFAULT_RADIUS); + detect_objects_normal(DEFAULT_RADIUS); identify_pack(); - self_knowledge(NULL); - ident = TRUE; - - break; - } - - case SV_POTION_SELF_KNOWLEDGE: - { - msg_print("You begin to know yourself a little better..."); - msg_print(NULL); - self_knowledge(NULL); ident = TRUE; break; @@ -2326,11 +2315,11 @@ static bool_ quaff_potion(int tval, int sval, int pval, int pval2) case SV_POTION_RESISTANCE: { - (void)set_oppose_acid(p_ptr->oppose_acid + randint(20) + 20); - (void)set_oppose_elec(p_ptr->oppose_elec + randint(20) + 20); - (void)set_oppose_fire(p_ptr->oppose_fire + randint(20) + 20); - (void)set_oppose_cold(p_ptr->oppose_cold + randint(20) + 20); - (void)set_oppose_pois(p_ptr->oppose_pois + randint(20) + 20); + set_oppose_acid(p_ptr->oppose_acid + randint(20) + 20); + set_oppose_elec(p_ptr->oppose_elec + randint(20) + 20); + set_oppose_fire(p_ptr->oppose_fire + randint(20) + 20); + set_oppose_cold(p_ptr->oppose_cold + randint(20) + 20); + set_oppose_pois(p_ptr->oppose_pois + randint(20) + 20); ident = TRUE; break; @@ -2352,7 +2341,7 @@ static bool_ quaff_potion(int tval, int sval, int pval, int pval2) case SV_POTION_INVULNERABILITY: { - (void)set_invuln(p_ptr->invuln + randint(7) + 7); + set_invuln(p_ptr->invuln + randint(7) + 7); ident = TRUE; break; @@ -2489,8 +2478,10 @@ static bool_ quaff_potion(int tval, int sval, int pval, int pval2) /* * Quaff a potion (from the pack or the floor) */ -void do_cmd_quaff_potion(void) +void do_cmd_quaff_potion() { + auto const &k_info = game->edit_data.k_info; + int ident, lev; /* Get an item */ @@ -2509,10 +2500,6 @@ void do_cmd_quaff_potion(void) object_type *o_ptr = get_object(item); - /* Sound */ - sound(SOUND_QUAFF); - - /* Take a turn */ energy_use = 100; @@ -2552,7 +2539,7 @@ void do_cmd_quaff_potion(void) /* Potions can feed the player */ - (void)set_food(p_ptr->food + o_ptr->pval); + set_food(p_ptr->food + o_ptr->pval); /* Destroy potion */ @@ -2563,7 +2550,7 @@ void do_cmd_quaff_potion(void) /* * Fill an empty bottle */ -static void do_cmd_fill_bottle(void) +static void do_cmd_fill_bottle() { cave_type *c_ptr = &cave[p_ptr->py][p_ptr->px]; @@ -2649,16 +2636,16 @@ static void do_cmd_fill_bottle(void) /* * Drink from a fountain */ -void do_cmd_drink_fountain(void) +void do_cmd_drink_fountain() { + auto const &k_info = game->edit_data.k_info; + cave_type *c_ptr = &cave[p_ptr->py][p_ptr->px]; bool_ ident; int tval, sval, pval = 0; - int i; - char ch; @@ -2695,9 +2682,9 @@ void do_cmd_drink_fountain(void) sval = c_ptr->special - SV_POTION_LAST; } - for (i = 0; i < max_k_idx; i++) + for (auto const &k_ref: k_info) { - object_kind *k_ptr = &k_info[i]; + auto k_ptr = &k_ref; if (k_ptr->tval != tval) continue; if (k_ptr->sval != sval) continue; @@ -2724,7 +2711,7 @@ void do_cmd_drink_fountain(void) /* * Curse the players armor */ -bool_ curse_armor(void) +bool_ curse_armor() { object_type *o_ptr; @@ -2742,7 +2729,7 @@ bool_ curse_armor(void) object_desc(o_name, o_ptr, FALSE, 3); /* Attempt a saving throw for artifacts */ - if (((o_ptr->art_name) || artifact_p(o_ptr)) && (rand_int(100) < 50)) + if (artifact_p(o_ptr) && (rand_int(100) < 50)) { /* Cool */ msg_format("A terrible black aura tries to surround your armour, " @@ -2764,10 +2751,7 @@ bool_ curse_armor(void) o_ptr->ac = 0; o_ptr->dd = 0; o_ptr->ds = 0; - o_ptr->art_flags1 = 0; - o_ptr->art_flags2 = 0; - o_ptr->art_flags3 = 0; - o_ptr->art_flags4 = 0; + o_ptr->art_flags = object_flag_set(); /* Curse it */ o_ptr->ident |= (IDENT_CURSED); @@ -2789,7 +2773,7 @@ bool_ curse_armor(void) /* * Curse the players weapon */ -bool_ curse_weapon(void) +bool_ curse_weapon() { object_type *o_ptr; @@ -2807,7 +2791,7 @@ bool_ curse_weapon(void) object_desc(o_name, o_ptr, FALSE, 3); /* Attempt a saving throw */ - if ((artifact_p(o_ptr) || o_ptr->art_name) && (rand_int(100) < 50)) + if (artifact_p(o_ptr) && (rand_int(100) < 50)) { /* Cool */ msg_format("A terrible black aura tries to surround your weapon, " @@ -2829,10 +2813,7 @@ bool_ curse_weapon(void) o_ptr->ac = 0; o_ptr->dd = 0; o_ptr->ds = 0; - o_ptr->art_flags1 = 0; - o_ptr->art_flags2 = 0; - o_ptr->art_flags3 = 0; - o_ptr->art_flags4 = 0; + o_ptr->art_flags = object_flag_set(); /* Curse it */ @@ -2874,8 +2855,12 @@ static object_filter_t const &item_tester_hook_readable() * include scrolls with no effects but recharge or identify, which are * cancelled before use. XXX Reading them still takes a turn, though. */ -void do_cmd_read_scroll(void) +void do_cmd_read_scroll() { + auto const &d_info = game->edit_data.d_info; + auto const &k_info = game->edit_data.k_info; + auto &r_info = game->edit_data.r_info; + /* Check some conditions */ if (p_ptr->blind) { @@ -2942,12 +2927,12 @@ void do_cmd_read_scroll(void) msg_print("You feel the souls of the dead coming back " "from the Halls of Mandos."); - for (int k = 0; k < max_r_idx; k++) + for (auto &r_ref: r_info) { - monster_race *r_ptr = &r_info[k]; + auto r_ptr = &r_ref; - if (r_ptr->flags1 & RF1_UNIQUE && - !(r_ptr->flags9 & RF9_SPECIAL_GENE)) + if (r_ptr->flags & RF_UNIQUE && + !(r_ptr->flags & RF_SPECIAL_GENE)) { r_ptr->max_num = 1; } @@ -2983,7 +2968,7 @@ void do_cmd_read_scroll(void) } msg_format("Recall reset to %s at level %d.", - d_info[p_ptr->recall_dungeon].name, + d_info[p_ptr->recall_dungeon].name.c_str(), max_dlv[p_ptr->recall_dungeon]); ident = TRUE; @@ -2995,7 +2980,6 @@ void do_cmd_read_scroll(void) case SV_SCROLL_DIVINATION: { int i, count = 0; - char buf[120]; while (count < 1000) { @@ -3007,8 +2991,7 @@ void do_cmd_read_scroll(void) msg_print("A message appears on the scroll. It says:"); msg_print(NULL); - fate_desc(buf, i); - msg_format("%s", buf); + msg_format("%s", fate_desc(i).c_str()); msg_print(NULL); msg_print("The scroll disappears in a puff of smoke!"); @@ -3026,7 +3009,7 @@ void do_cmd_read_scroll(void) { if (!(p_ptr->resist_blind) && !(p_ptr->resist_dark)) { - (void)set_blind(p_ptr->blind + 3 + randint(5)); + set_blind(p_ptr->blind + 3 + randint(5)); } if (unlite_area(10, 3)) ident = TRUE; @@ -3093,13 +3076,6 @@ void do_cmd_read_scroll(void) break; } - case SV_SCROLL_TRAP_CREATION: - { - if (trap_creation()) ident = TRUE; - - break; - } - case SV_SCROLL_PHASE_DOOR: { teleport_player(10); @@ -3120,7 +3096,7 @@ void do_cmd_read_scroll(void) case SV_SCROLL_TELEPORT_LEVEL: { - (void)teleport_player_level(); + teleport_player_level(); ident = TRUE; @@ -3129,7 +3105,7 @@ void do_cmd_read_scroll(void) case SV_SCROLL_WORD_OF_RECALL: { - if ((dungeon_flags2 & DF2_ASK_LEAVE) && !get_check("Leave this unique level forever? ")) + if ((dungeon_flags & DF_ASK_LEAVE) && !get_check("Leave this unique level forever? ")) { used_up = FALSE; } @@ -3174,9 +3150,11 @@ void do_cmd_read_scroll(void) case SV_SCROLL_STAR_REMOVE_CURSE: { - remove_all_curse(); - - ident = TRUE; + if (remove_all_curse()) + { + msg_print("You feel as if someone is watching over you."); + ident = TRUE; + } break; } @@ -3275,13 +3253,6 @@ void do_cmd_read_scroll(void) break; } - case SV_SCROLL_DETECT_TRAP: - { - if (detect_traps(DEFAULT_RADIUS)) ident = TRUE; - - break; - } - case SV_SCROLL_DETECT_DOOR: { if (detect_doors(DEFAULT_RADIUS)) ident = TRUE; @@ -3357,13 +3328,6 @@ void do_cmd_read_scroll(void) break; } - case SV_SCROLL_TRAP_DOOR_DESTRUCTION: - { - if (destroy_doors_touch()) ident = TRUE; - - break; - } - case SV_SCROLL_STAR_DESTRUCTION: { /* Prevent destruction of quest levels and town */ @@ -3390,7 +3354,7 @@ void do_cmd_read_scroll(void) case SV_SCROLL_GENOCIDE: { - (void)genocide(TRUE); + genocide(TRUE); ident = TRUE; @@ -3399,7 +3363,7 @@ void do_cmd_read_scroll(void) case SV_SCROLL_MASS_GENOCIDE: { - (void)mass_genocide(TRUE); + mass_genocide(TRUE); ident = TRUE; @@ -3586,14 +3550,15 @@ void do_cmd_read_scroll(void) cptr q = format("book-%d.txt", o_ptr->sval); /* Peruse the help file */ - (void)show_file(q, NULL, 0, 0); + show_file(q, NULL); /* Load screen */ screen_load(); + /* Inscriptions become known upon reading */ if (o_ptr->sval >= 100) { - inscription_info[o_ptr->sval - 100].know = TRUE; + p_ptr->inscriptions[o_ptr->sval - 100] = TRUE; } used_up = FALSE; @@ -3621,8 +3586,6 @@ void do_cmd_read_scroll(void) /* Hack -- allow certain scrolls to be "preserved" */ if (!used_up) return; - sound(SOUND_SCROLL); - /* Destroy scroll */ inc_stack_size(item, -1); } @@ -3694,12 +3657,10 @@ static void activate_stick(object_type *o_ptr, bool_ *obvious, bool_ *use_charge * * Hack -- staffs of identify can be "cancelled". */ -void do_cmd_use_staff(void) +void do_cmd_use_staff() { bool_ obvious, use_charge; - u32b f1, f2, f3, f4, f5, esp; - /* No magic */ if (p_ptr->antimagic) { @@ -3746,10 +3707,10 @@ void do_cmd_use_staff(void) unset_stick_mode(); /* Extract object flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Is it simple to use ? */ - if (f4 & TR4_EASY_USE) + if (flags & TR_EASY_USE) { chance /= 3; } @@ -3763,25 +3724,21 @@ void do_cmd_use_staff(void) /* Roll for usage */ if (magik(chance)) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("You failed to use the staff properly."); - sound(SOUND_FAIL); return; } /* Notice empty staffs */ if (o_ptr->pval <= 0) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("The staff has no charges left."); o_ptr->ident |= (IDENT_EMPTY); return; } - /* Sound */ - sound(SOUND_ZAP); - /* Analyze the staff */ activate_stick(o_ptr, &obvious, &use_charge); @@ -3871,13 +3828,10 @@ void do_cmd_use_staff(void) * basic "bolt" rods, but the basic "ball" wands do the same damage * as the basic "ball" rods. */ -void do_cmd_aim_wand(void) +void do_cmd_aim_wand() { bool_ obvious, use_charge; - u32b f1, f2, f3, f4, f5, esp; - - /* No magic */ if (p_ptr->antimagic) { @@ -3924,10 +3878,10 @@ void do_cmd_aim_wand(void) unset_stick_mode(); /* Extract object flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Is it simple to use ? */ - if (f4 & TR4_EASY_USE) + if (flags & TR_EASY_USE) { chance /= 3; } @@ -3935,24 +3889,20 @@ void do_cmd_aim_wand(void) /* Roll for usage */ if (magik(chance)) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("You failed to use the wand properly."); - sound(SOUND_FAIL); return; } /* The wand is already empty! */ if (o_ptr->pval <= 0) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("The wand has no charges left."); o_ptr->ident |= (IDENT_EMPTY); return; } - /* Sound */ - sound(SOUND_ZAP); - /* Analyze the wand */ activate_stick(o_ptr, &obvious, &use_charge); @@ -4038,12 +3988,6 @@ static bool item_tester_hook_attachable(object_type const *o_ptr) */ void zap_combine_rod_tip(object_type *q_ptr, int tip_item) { - int item; - - u32b f1, f2, f3, f4, f5, esp; - s32b cost; - - /* No magic */ if (p_ptr->antimagic) { @@ -4052,6 +3996,7 @@ void zap_combine_rod_tip(object_type *q_ptr, int tip_item) } /* Get an item */ + int item; if (!get_item(&item, "Attach the rod tip with which rod? ", "You have no rod to attach to.", @@ -4065,12 +4010,11 @@ void zap_combine_rod_tip(object_type *q_ptr, int tip_item) object_type *o_ptr = get_object(item); /* Examine the rod */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Calculate rod tip's mana cost */ - cost = q_ptr->pval; - - if (f4 & TR4_CHEAPNESS) + s32b cost = q_ptr->pval; + if (flags & TR_CHEAPNESS) { cost /= 2; } @@ -4096,18 +4040,16 @@ void zap_combine_rod_tip(object_type *q_ptr, int tip_item) /* * Zap a rod, or attack a rod tip to a rod */ -void do_cmd_zap_rod(void) +void do_cmd_zap_rod() { + auto const &k_info = game->edit_data.k_info; + int item, ident, chance, dir, lev; int cost; bool_ require_dir; - object_kind *tip_ptr; - - u32b f1, f2, f3, f4, f5, esp; - /* Hack -- let perception get aborted */ bool_ use_charge = TRUE; @@ -4161,7 +4103,6 @@ void do_cmd_zap_rod(void) { switch (o_ptr->pval) { - case SV_ROD_DETECT_TRAP: case SV_ROD_HAVOC: case SV_ROD_HOME: { @@ -4188,15 +4129,18 @@ void do_cmd_zap_rod(void) energy_use = 100; /* Examine the rod */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); - if (f4 & TR4_FAST_CAST) energy_use /= 2; + if (flags & TR_FAST_CAST) + { + energy_use /= 2; + } /* Not identified yet */ ident = FALSE; /* Extract the item level */ - tip_ptr = &k_info[lookup_kind(TV_ROD, o_ptr->pval)]; + auto tip_ptr = &k_info[lookup_kind(TV_ROD, o_ptr->pval)]; lev = k_info[lookup_kind(TV_ROD, o_ptr->pval)].level; /* Base chance of success */ @@ -4214,7 +4158,7 @@ void do_cmd_zap_rod(void) } /* Is it simple to use ? */ - if (f4 & TR4_EASY_USE) + if (flags & TR_EASY_USE) { chance *= 10; } @@ -4229,13 +4173,11 @@ void do_cmd_zap_rod(void) if ((chance < USE_DEVICE) || (randint(chance) < USE_DEVICE)) { /* Flush input if necessary */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_print("You failed to use the rod properly."); - sound(SOUND_FAIL); - return; } @@ -4243,13 +4185,13 @@ void do_cmd_zap_rod(void) cost = tip_ptr->pval; /* "Cheapness" ego halven the cost */ - if (f4 & TR4_CHEAPNESS) cost = cost / 2; + if (flags & TR_CHEAPNESS) cost = cost / 2; /* A single rod is still charging */ if (o_ptr->timeout < cost) { /* Flush input if necessary */ - if (flush_failure) flush(); + flush_on_failure(); /* Message */ msg_print("The rod does not have enough mana yet."); @@ -4260,9 +4202,6 @@ void do_cmd_zap_rod(void) /* Increase the timeout by the rod kind's pval. */ o_ptr->timeout -= cost; - /* Sound */ - sound(SOUND_ZAP); - /* Analyze the rod */ switch (o_ptr->pval) { @@ -4275,13 +4214,6 @@ void do_cmd_zap_rod(void) break; } - case SV_ROD_DETECT_TRAP: - { - if (detect_traps(DEFAULT_RADIUS)) ident = TRUE; - - break; - } - case SV_ROD_DETECT_DOOR: { if (detect_doors(DEFAULT_RADIUS)) ident = TRUE; @@ -4301,7 +4233,7 @@ void do_cmd_zap_rod(void) case SV_ROD_RECALL: { - if ((dungeon_flags2 & DF2_ASK_LEAVE) && !get_check("Leave this unique level forever? ")) + if ((dungeon_flags & DF_ASK_LEAVE) && !get_check("Leave this unique level forever? ")) { use_charge = FALSE; } @@ -4340,15 +4272,6 @@ void do_cmd_zap_rod(void) break; } - case SV_ROD_PROBING: - { - probing(); - - ident = TRUE; - - break; - } - case SV_ROD_CURING: { if (set_blind(0)) ident = TRUE; @@ -4391,7 +4314,7 @@ void do_cmd_zap_rod(void) } else { - (void)set_fast(p_ptr->fast + 5, 10); + set_fast(p_ptr->fast + 5, 10); } break; @@ -4404,13 +4327,6 @@ void do_cmd_zap_rod(void) break; } - case SV_ROD_DISARMING: - { - if (disarm_trap(dir)) ident = TRUE; - - break; - } - case SV_ROD_LITE: { msg_print("A line of blue shimmering light appears."); @@ -4571,7 +4487,7 @@ static object_filter_t const &item_tester_hook_activate() using namespace object_filter; static auto instance = And( IsKnown(), - HasFlag3(TR3_ACTIVATE)); + HasFlags(TR_ACTIVATE)); return instance; } @@ -4672,7 +4588,7 @@ int ring_of_power() /* * Enchant some bolts */ -bool_ brand_bolts(void) +bool_ brand_bolts() { int i; @@ -4686,7 +4602,7 @@ bool_ brand_bolts(void) if (o_ptr->tval != TV_BOLT) continue; /* Skip artifacts and ego-items */ - if (o_ptr->art_name || artifact_p(o_ptr) || ego_item_p(o_ptr)) continue; + if (artifact_p(o_ptr) || ego_item_p(o_ptr)) continue; /* Skip cursed/broken items */ if (cursed_p(o_ptr)) continue; @@ -4711,7 +4627,7 @@ bool_ brand_bolts(void) } /* Flush */ - if (flush_failure) flush(); + flush_on_failure(); /* Fail */ msg_print("The fiery enchantment failed."); @@ -4878,13 +4794,12 @@ static void activate_valaroma() * Note that it always takes a turn to activate an object, even if * the user hits "escape" at the "direction" prompt. */ -void do_cmd_activate(void) +void do_cmd_activate() { - int item, lev, chance; - - char ch, spell_choice; + auto const &k_info = game->edit_data.k_info; + auto const &a_info = game->edit_data.a_info; - u32b f1, f2, f3, f4, f5, esp; + int item, lev, chance; /* Get an item */ command_wrk = USE_EQUIP; @@ -4901,10 +4816,10 @@ void do_cmd_activate(void) object_type *o_ptr = get_object(item); /* Extract object flags */ - object_flags(o_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + auto const flags = object_flags(o_ptr); /* Wearable items have to be worn */ - if (!(f5 & TR5_ACTIVATE_NO_WIELD)) + if (!(flags & TR_ACTIVATE_NO_WIELD)) { if (item < INVEN_WIELD) { @@ -4924,7 +4839,7 @@ void do_cmd_activate(void) { if (o_ptr->tval == TV_RANDART) { - lev = random_artifacts[o_ptr->sval].level; + lev = game->random_artifacts[o_ptr->sval].level; } else { @@ -4947,7 +4862,7 @@ void do_cmd_activate(void) } /* Is it simple to use ? */ - if (f4 & TR4_EASY_USE) + if (flags & TR_EASY_USE) { chance *= 10; } @@ -4961,24 +4876,16 @@ void do_cmd_activate(void) /* Roll for usage */ if ((chance < USE_DEVICE) || (randint(chance) < USE_DEVICE)) { - if (flush_failure) flush(); + flush_on_failure(); msg_print("You failed to activate it properly."); - sound(SOUND_FAIL); return; } /* Check the recharge */ if (o_ptr->timeout) { - /* Mage Staff of Spells -- Have another timeout in xtra2 */ - if (is_ego_p(o_ptr, EGO_MSTAFF_SPELL) && o_ptr->xtra2) - { - msg_print("It whines, glows and fades..."); - return; - } - /* Monster eggs */ - else if (o_ptr->tval == TV_EGG) + if (o_ptr->tval == TV_EGG) { msg_print("You resume the development of the egg."); o_ptr->timeout = 0; @@ -5002,9 +4909,6 @@ void do_cmd_activate(void) /* Activate the item */ msg_print("You activate it..."); - /* Sound */ - sound(SOUND_ZAP); - /* New mostly unified activation code This has to be early to allow artifacts to override normal items -- neil */ @@ -5017,61 +4921,6 @@ void do_cmd_activate(void) return; } - /* Mage Staff of Spells */ - if (is_ego_p(o_ptr, EGO_MSTAFF_SPELL)) - { - while (TRUE) - { - if (!get_com("Use Spell [1] or [2]?", &ch)) - { - return; - } - - if (ch == '1') - { - spell_choice = 1; - break; - } - - if (ch == '2') - { - spell_choice = 2; - break; - } - } - - if (spell_choice == 1) - { - /* Still need to check timeouts because there is another counter */ - if (o_ptr->timeout) - { - msg_print("The first spell is still charging!"); - return; - } - - /* Cast spell 1 */ - activate_spell(o_ptr, spell_choice); - } - else if (spell_choice == 2) - { - /* Still need to check timeouts because there is another counter */ - if (o_ptr->xtra2) - { - msg_print("The second spell is still charging!"); - return; - } - - /* Cast spell 2 */ - activate_spell(o_ptr, spell_choice); - } - - /* Window stuff */ - p_ptr->window |= (PW_INVEN | PW_EQUIP); - - /* Success */ - return; - } - /* Monster eggs */ if (o_ptr->tval == TV_EGG) { @@ -5108,6 +4957,10 @@ void do_cmd_activate(void) const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { + auto const &k_info = game->edit_data.k_info; + auto const &a_info = game->edit_data.a_info; + auto const &e_info = game->edit_data.e_info; + int plev = get_skill(SKILL_DEVICE); int i = 0, ii = 0, ij = 0, k, dir, dummy = 0; @@ -5125,7 +4978,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) spell = a_info[o_ptr->name1].activate; /* Random Artifacts */ - if (!spell && o_ptr->art_name) + if (!spell && (!o_ptr->artifact_name.empty())) spell = o_ptr->xtra2; /* Ego Items */ @@ -5227,67 +5080,6 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) break; } - case ACT_NUMENOR: - { - /* Give full knowledge */ - /* Hack -- Maximal info */ - monster_race *r_ptr; - cave_type *c_ptr; - int x, y, m; - - if (!doit) return "analyze monster every 500+d200 turns"; - - if (!tgt_pt(&x, &y)) break; - - c_ptr = &cave[y][x]; - if (!c_ptr->m_idx) break; - - r_ptr = &r_info[c_ptr->m_idx]; - - /* Observe "maximal" attacks */ - for (m = 0; m < 4; m++) - { - /* Examine "actual" blows */ - if (r_ptr->blow[m].effect || r_ptr->blow[m].method) - { - /* Hack -- maximal observations */ - r_ptr->r_blows[m] = MAX_UCHAR; - } - } - - /* Hack -- maximal drops */ - r_ptr->r_drop_gold = r_ptr->r_drop_item = - (((r_ptr->flags1 & (RF1_DROP_4D2)) ? 8 : 0) + - ((r_ptr->flags1 & (RF1_DROP_3D2)) ? 6 : 0) + - ((r_ptr->flags1 & (RF1_DROP_2D2)) ? 4 : 0) + - ((r_ptr->flags1 & (RF1_DROP_1D2)) ? 2 : 0) + - ((r_ptr->flags1 & (RF1_DROP_90)) ? 1 : 0) + - ((r_ptr->flags1 & (RF1_DROP_60)) ? 1 : 0)); - - /* Hack -- but only "valid" drops */ - if (r_ptr->flags1 & (RF1_ONLY_GOLD)) r_ptr->r_drop_item = 0; - if (r_ptr->flags1 & (RF1_ONLY_ITEM)) r_ptr->r_drop_gold = 0; - - /* Hack -- observe many spells */ - r_ptr->r_cast_inate = MAX_UCHAR; - r_ptr->r_cast_spell = MAX_UCHAR; - - /* Hack -- know all the flags */ - r_ptr->r_flags1 = r_ptr->flags1; - r_ptr->r_flags2 = r_ptr->flags2; - r_ptr->r_flags3 = r_ptr->flags3; - r_ptr->r_flags4 = r_ptr->flags4; - r_ptr->r_flags5 = r_ptr->flags5; - r_ptr->r_flags6 = r_ptr->flags6; - r_ptr->r_flags7 = r_ptr->flags7; - r_ptr->r_flags8 = r_ptr->flags8; - r_ptr->r_flags9 = r_ptr->flags9; - - o_ptr->timeout = rand_int(200) + 500; - - break; - } - case ACT_KNOWLEDGE: { if (!doit) return "whispers from beyond(sanity drain) every 100+d200 turns"; @@ -5305,12 +5097,12 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) msg_print("The phial wells with dark light..."); unlite_area(damroll(2, 15), 3); take_hit(damroll(10, 10), "activating The Phial of Undeath"); - (void)dec_stat(A_DEX, 25, STAT_DEC_PERMANENT); - (void)dec_stat(A_WIS, 25, STAT_DEC_PERMANENT); - (void)dec_stat(A_CON, 25, STAT_DEC_PERMANENT); - (void)dec_stat(A_STR, 25, STAT_DEC_PERMANENT); - (void)dec_stat(A_CHR, 25, STAT_DEC_PERMANENT); - (void)dec_stat(A_INT, 25, STAT_DEC_PERMANENT); + dec_stat(A_DEX, 25, STAT_DEC_PERMANENT); + dec_stat(A_WIS, 25, STAT_DEC_PERMANENT); + dec_stat(A_CON, 25, STAT_DEC_PERMANENT); + dec_stat(A_STR, 25, STAT_DEC_PERMANENT); + dec_stat(A_CHR, 25, STAT_DEC_PERMANENT); + dec_stat(A_INT, 25, STAT_DEC_PERMANENT); o_ptr->timeout = rand_int(10) + 10; @@ -5332,7 +5124,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "dispel small life every 55+d55 turns"; msg_print("You exterminate small life."); - (void)dispel_monsters(4); + dispel_monsters(4); o_ptr->timeout = rand_int(55) + 55; @@ -5345,11 +5137,11 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) msg_print("The ring glows brightly..."); if (!p_ptr->fast) { - (void)set_fast(randint(75) + 75, 10); + set_fast(randint(75) + 75, 10); } else { - (void)set_fast(p_ptr->fast + 5, 10); + set_fast(p_ptr->fast + 5, 10); } o_ptr->timeout = rand_int(150) + 150; @@ -5428,7 +5220,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) msg_print("The stone reveals hidden mysteries..."); if (!ident_spell()) break; - if (has_ability(AB_PERFECT_CASTING)) + if (p_ptr->has_ability(AB_PERFECT_CASTING)) { /* Sufficient mana */ if (20 <= p_ptr->csp) @@ -5450,10 +5242,10 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) msg_print("You are too weak to control the stone!"); /* Hack -- Bypass free action */ - (void)set_paralyzed(randint(5 * oops + 1)); + set_paralyzed(randint(5 * oops + 1)); /* Confusing. */ - (void)set_confused(p_ptr->confused + + set_confused(p_ptr->confused + randint(5 * oops + 1)); } @@ -5466,7 +5258,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) /* Confusing. */ if (rand_int(5) == 0) { - (void)set_confused(p_ptr->confused + randint(10)); + set_confused(p_ptr->confused + randint(10)); } /* Exercise a little care... */ @@ -5508,15 +5300,15 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) msg_print("You breathe the elements."); fire_ball(GF_MISSILE, dir, 300, 4); msg_print("Your armor glows many colours..."); - (void)set_afraid(0); - (void)set_shero(p_ptr->shero + randint(50) + 50); - (void)hp_player(30); - (void)set_blessed(p_ptr->blessed + randint(50) + 50); - (void)set_oppose_acid(p_ptr->oppose_acid + randint(50) + 50); - (void)set_oppose_elec(p_ptr->oppose_elec + randint(50) + 50); - (void)set_oppose_fire(p_ptr->oppose_fire + randint(50) + 50); - (void)set_oppose_cold(p_ptr->oppose_cold + randint(50) + 50); - (void)set_oppose_pois(p_ptr->oppose_pois + randint(50) + 50); + set_afraid(0); + set_shero(p_ptr->shero + randint(50) + 50); + hp_player(30); + set_blessed(p_ptr->blessed + randint(50) + 50); + set_oppose_acid(p_ptr->oppose_acid + randint(50) + 50); + set_oppose_elec(p_ptr->oppose_elec + randint(50) + 50); + set_oppose_fire(p_ptr->oppose_fire + randint(50) + 50); + set_oppose_cold(p_ptr->oppose_cold + randint(50) + 50); + set_oppose_pois(p_ptr->oppose_pois + randint(50) + 50); o_ptr->timeout = 400; @@ -5527,13 +5319,13 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return ("heal (777), curing and heroism every 300 turns"); msg_print("A heavenly choir sings..."); - (void)set_poisoned(0); - (void)set_cut(0); - (void)set_stun(0); - (void)set_confused(0); - (void)set_blind(0); - (void)set_hero(p_ptr->hero + randint(25) + 25); - (void)hp_player(777); + set_poisoned(0); + set_cut(0); + set_stun(0); + set_confused(0); + set_blind(0); + set_hero(p_ptr->hero + randint(25) + 25); + hp_player(777); o_ptr->timeout = 300; @@ -5554,11 +5346,11 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "resistance (20+d20 turns) every 111 turns"; msg_print("Your cloak glows many colours..."); - (void)set_oppose_acid(p_ptr->oppose_acid + randint(20) + 20); - (void)set_oppose_elec(p_ptr->oppose_elec + randint(20) + 20); - (void)set_oppose_fire(p_ptr->oppose_fire + randint(20) + 20); - (void)set_oppose_cold(p_ptr->oppose_cold + randint(20) + 20); - (void)set_oppose_pois(p_ptr->oppose_pois + randint(20) + 20); + set_oppose_acid(p_ptr->oppose_acid + randint(20) + 20); + set_oppose_elec(p_ptr->oppose_elec + randint(20) + 20); + set_oppose_fire(p_ptr->oppose_fire + randint(20) + 20); + set_oppose_cold(p_ptr->oppose_cold + randint(20) + 20); + set_oppose_pois(p_ptr->oppose_pois + randint(20) + 20); o_ptr->timeout = 111; @@ -5608,7 +5400,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case 11: case 12: { - (void)stair_creation(); + stair_creation(); break; } @@ -5654,7 +5446,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "summon the Legion of the Dawn every 500+d500 turns"; msg_print("You summon the Legion of the Dawn."); - (void)summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_DAWN, TRUE); + summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_DAWN, TRUE); o_ptr->timeout = 500 + randint(500); @@ -5689,7 +5481,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "fire branding of bolts every 999 turns"; msg_print("Your crossbow glows deep red..."); - (void)brand_bolts(); + brand_bolts(); o_ptr->timeout = 999; @@ -5760,9 +5552,8 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) if (!doit) return "clairvoyance every 100+d100 turns"; msg_print("The stone glows a deep green..."); wiz_lite_extra(); - (void)detect_traps(DEFAULT_RADIUS); - (void)detect_doors(DEFAULT_RADIUS); - (void)detect_stairs(DEFAULT_RADIUS); + detect_doors(DEFAULT_RADIUS); + detect_stairs(DEFAULT_RADIUS); o_ptr->timeout = rand_int(100) + 100; @@ -5847,11 +5638,11 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) if (!doit) return "berserker and +10 to speed (50) every 100+d200 turns"; if (!p_ptr->fast) { - (void)set_fast(randint(50) + 50, 10); + set_fast(randint(50) + 50, 10); } else { - (void)set_fast(p_ptr->fast + 5, 10); + set_fast(p_ptr->fast + 5, 10); } hp_player(30); set_afraid(0); @@ -5927,7 +5718,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "detect orcs every 10 turns"; msg_print("Your weapon glows brightly..."); - (void)detect_monsters_xxx(RF3_ORC, DEFAULT_RADIUS); + detect_monsters_orcs(DEFAULT_RADIUS); o_ptr->timeout = 10; @@ -6306,7 +6097,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "teleport away every 200 turns"; if (!get_aim_dir(&dir)) break; - (void)fire_beam(GF_AWAY_ALL, dir, plev); + fire_beam(GF_AWAY_ALL, dir, plev); o_ptr->timeout = 200; @@ -6330,7 +6121,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "genocide every 500 turns"; msg_print("It glows deep blue..."); - (void)genocide(TRUE); + genocide(TRUE); o_ptr->timeout = 500; @@ -6341,7 +6132,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "mass genocide every 1000 turns"; msg_print("It lets out a long, shrill note..."); - (void)mass_genocide(TRUE); + mass_genocide(TRUE); o_ptr->timeout = 1000; @@ -6354,7 +6145,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "charm animal every 300 turns"; if (!get_aim_dir(&dir)) break; - (void) charm_animal(dir, plev); + charm_animal(dir, plev); o_ptr->timeout = 300; @@ -6365,7 +6156,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "enslave undead every 333 turns"; if (!get_aim_dir(&dir)) break; - (void)control_one_undead(dir, plev); + control_one_undead(dir, plev); o_ptr->timeout = 333; @@ -6376,7 +6167,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "charm monster every 400 turns"; if (!get_aim_dir(&dir)) break; - (void) charm_monster(dir, plev); + charm_monster(dir, plev); o_ptr->timeout = 400; @@ -6386,7 +6177,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_CHARM_ANIMALS: { if (!doit) return "animal friendship every 500 turns"; - (void) charm_animals(plev * 2); + charm_animals(plev * 2); o_ptr->timeout = 500; @@ -6406,7 +6197,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_SUMMON_ANIMAL: { if (!doit) return "summon animal every 200+d300 turns"; - (void)summon_specific_friendly(p_ptr->py, p_ptr->px, plev, SUMMON_ANIMAL_RANGER, TRUE); + summon_specific_friendly(p_ptr->py, p_ptr->px, plev, SUMMON_ANIMAL_RANGER, TRUE); o_ptr->timeout = 200 + randint(300); @@ -6417,7 +6208,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "summon phantasmal servant every 200+d200 turns"; msg_print("You summon a phantasmal servant."); - (void)summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_PHANTOM, TRUE); + summon_specific_friendly(p_ptr->py, p_ptr->px, dun_level, SUMMON_PHANTOM, TRUE); o_ptr->timeout = 200 + randint(200); @@ -6509,8 +6300,8 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_CURE_LW: { if (!doit) return format("cure light wounds every %d turns", (is_junkart ? 50 : 10)); - (void)set_afraid(0); - (void)hp_player(30); + set_afraid(0); + hp_player(30); o_ptr->timeout = 10; @@ -6522,7 +6313,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) if (!doit) return format("cure serious wounds every %s turns", (is_junkart? "75" : "3+d3")); msg_print("It radiates deep purple..."); hp_player(damroll(4, 8)); - (void)set_cut((p_ptr->cut / 2) - 50); + set_cut((p_ptr->cut / 2) - 50); o_ptr->timeout = rand_int(3) + 3; @@ -6533,8 +6324,8 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "remove fear and cure poison every 5 turns"; msg_print("It glows deep blue..."); - (void)set_afraid(0); - (void)set_poisoned(0); + set_afraid(0); + set_poisoned(0); o_ptr->timeout = 5; @@ -6556,13 +6347,13 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return format("restore stats and life levels every %d turns", (is_junkart ? 200 : 750)); msg_print("It glows a deep green..."); - (void)do_res_stat(A_STR, TRUE); - (void)do_res_stat(A_INT, TRUE); - (void)do_res_stat(A_WIS, TRUE); - (void)do_res_stat(A_DEX, TRUE); - (void)do_res_stat(A_CON, TRUE); - (void)do_res_stat(A_CHR, TRUE); - (void)restore_level(); + do_res_stat(A_STR, TRUE); + do_res_stat(A_INT, TRUE); + do_res_stat(A_WIS, TRUE); + do_res_stat(A_DEX, TRUE); + do_res_stat(A_CON, TRUE); + do_res_stat(A_CHR, TRUE); + restore_level(); o_ptr->timeout = 750; @@ -6574,8 +6365,8 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) if (!doit) return format("heal 700 hit points every %d turns", (is_junkart ? 100 : 250)); msg_print("It glows deep blue..."); msg_print("You feel a warm tingling inside..."); - (void)hp_player(700); - (void)set_cut(0); + hp_player(700); + set_cut(0); o_ptr->timeout = 250; @@ -6587,8 +6378,8 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) if (!doit) return "heal 1000 hit points every 888 turns"; msg_print("It glows a bright white..."); msg_print("You feel much better..."); - (void)hp_player(1000); - (void)set_cut(0); + hp_player(1000); + set_cut(0); o_ptr->timeout = 888; @@ -6598,7 +6389,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_ESP: { if (!doit) return "temporary ESP (dur 25+d30) every 200 turns"; - (void)set_tim_esp(p_ptr->tim_esp + randint(30) + 25); + set_tim_esp(p_ptr->tim_esp + randint(30) + 25); o_ptr->timeout = 200; @@ -6608,8 +6399,8 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_BERSERK: { if (!doit) return "heroism and berserk (dur 50+d50) every 100+d100 turns"; - (void)set_shero(p_ptr->shero + randint(50) + 50); - (void)set_blessed(p_ptr->blessed + randint(50) + 50); + set_shero(p_ptr->shero + randint(50) + 50); + set_blessed(p_ptr->blessed + randint(50) + 50); o_ptr->timeout = 100 + randint(100); @@ -6621,7 +6412,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) if (!doit) return "protection from evil (dur level*3 + d25) every 225+d225 turns"; msg_print("It lets out a shrill wail..."); k = 3 * p_ptr->lev; - (void)set_protevil(p_ptr->protevil + randint(25) + k); + set_protevil(p_ptr->protevil + randint(25) + k); o_ptr->timeout = rand_int(225) + 225; @@ -6632,11 +6423,11 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "resist elements (dur 40+d40) every 200 turns"; msg_print("It glows many colours..."); - (void)set_oppose_acid(p_ptr->oppose_acid + randint(40) + 40); - (void)set_oppose_elec(p_ptr->oppose_elec + randint(40) + 40); - (void)set_oppose_fire(p_ptr->oppose_fire + randint(40) + 40); - (void)set_oppose_cold(p_ptr->oppose_cold + randint(40) + 40); - (void)set_oppose_pois(p_ptr->oppose_pois + randint(40) + 40); + set_oppose_acid(p_ptr->oppose_acid + randint(40) + 40); + set_oppose_elec(p_ptr->oppose_elec + randint(40) + 40); + set_oppose_fire(p_ptr->oppose_fire + randint(40) + 40); + set_oppose_cold(p_ptr->oppose_cold + randint(40) + 40); + set_oppose_pois(p_ptr->oppose_pois + randint(40) + 40); o_ptr->timeout = 200; @@ -6649,11 +6440,11 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) msg_print("It glows bright green..."); if (!p_ptr->fast) { - (void)set_fast(randint(20) + 20, 10); + set_fast(randint(20) + 20, 10); } else { - (void)set_fast(p_ptr->fast + 5, 10); + set_fast(p_ptr->fast + 5, 10); } o_ptr->timeout = 250; @@ -6667,11 +6458,11 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) msg_print("It glows brightly..."); if (!p_ptr->fast) { - (void)set_fast(randint(75) + 75, 10); + set_fast(randint(75) + 75, 10); } else { - (void)set_fast(p_ptr->fast + 5, 10); + set_fast(p_ptr->fast + 5, 10); } o_ptr->timeout = rand_int(200) + 200; @@ -6692,7 +6483,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_INVULN: { if (!doit) return "invulnerability (dur 8+d8) every 1000 turns"; - (void)set_invuln(p_ptr->invuln + randint(8) + 8); + set_invuln(p_ptr->invuln + randint(8) + 8); o_ptr->timeout = 1000; @@ -6738,10 +6529,9 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_DETECT_XTRA: { - if (!doit) return "detection, probing and identify true every 1000 turns"; + if (!doit) return "detection and identify true every 1000 turns"; msg_print("It glows brightly..."); detect_all(DEFAULT_RADIUS); - probing(); identify_fully(); o_ptr->timeout = 1000; @@ -6795,7 +6585,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_SATIATE: { if (!doit) return "satisfy hunger every 200 turns"; - (void)set_food(PY_FOOD_MAX - 1); + set_food(PY_FOOD_MAX - 1); o_ptr->timeout = 200; @@ -6839,7 +6629,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) { if (!doit) return "alchemy every 500 turns"; msg_print("It glows bright yellow..."); - (void) alchemy(); + alchemy(); o_ptr->timeout = 500; @@ -6849,7 +6639,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_DIM_DOOR: { if (!doit) return "dimension door every 100 turns"; - if (dungeon_flags2 & DF2_NO_TELEPORT) + if (dungeon_flags & DF_NO_TELEPORT) { msg_print("Not on special levels!"); break; @@ -6892,7 +6682,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_RECALL: { - if (!(dungeon_flags2 & DF2_ASK_LEAVE) || ((dungeon_flags2 & DF2_ASK_LEAVE) && !get_check("Leave this unique level forever? "))) + if (!(dungeon_flags & DF_ASK_LEAVE) || ((dungeon_flags & DF_ASK_LEAVE) && !get_check("Leave this unique level forever? "))) { if (!doit) return "word of recall every 200 turns"; msg_print("It glows soft white..."); @@ -6920,12 +6710,12 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) msg_print("Your nerves and muscles feel weak and lifeless!"); take_hit(damroll(10, 10), "activating Ruination"); - (void)dec_stat(A_DEX, 25, TRUE); - (void)dec_stat(A_WIS, 25, TRUE); - (void)dec_stat(A_CON, 25, TRUE); - (void)dec_stat(A_STR, 25, TRUE); - (void)dec_stat(A_CHR, 25, TRUE); - (void)dec_stat(A_INT, 25, TRUE); + dec_stat(A_DEX, 25, TRUE); + dec_stat(A_WIS, 25, TRUE); + dec_stat(A_CON, 25, TRUE); + dec_stat(A_STR, 25, TRUE); + dec_stat(A_CHR, 25, TRUE); + dec_stat(A_INT, 25, TRUE); /* Timeout is set before return */ @@ -6945,7 +6735,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_UNINT: { if (!doit) return "decreasing Intelligence"; - (void)dec_stat(A_INT, 25, FALSE); + dec_stat(A_INT, 25, FALSE); /* Timeout is set before return */ @@ -6955,7 +6745,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_UNSTR: { if (!doit) return "decreasing Strength"; - (void)dec_stat(A_STR, 25, FALSE); + dec_stat(A_STR, 25, FALSE); /* Timeout is set before return */ @@ -6965,7 +6755,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_UNCON: { if (!doit) return "decreasing Constitution"; - (void)dec_stat(A_CON, 25, FALSE); + dec_stat(A_CON, 25, FALSE); /* Timeout is set before return */ @@ -6975,7 +6765,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_UNCHR: { if (!doit) return "decreasing Charisma"; - (void)dec_stat(A_CHR, 25, FALSE); + dec_stat(A_CHR, 25, FALSE); /* Timeout is set before return */ @@ -6985,7 +6775,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_UNDEX: { if (!doit) return "decreasing Dexterity"; - (void)dec_stat(A_DEX, 25, FALSE); + dec_stat(A_DEX, 25, FALSE); /* Timeout is set before return */ @@ -6995,7 +6785,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_UNWIS: { if (!doit) return "decreasing Wisdom"; - (void)dec_stat(A_WIS, 25, FALSE); + dec_stat(A_WIS, 25, FALSE); /* Timeout is set before return */ @@ -7005,12 +6795,12 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_STATLOSS: { if (!doit) return "stat loss"; - (void)dec_stat(A_STR, 15, FALSE); - (void)dec_stat(A_INT, 15, FALSE); - (void)dec_stat(A_WIS, 15, FALSE); - (void)dec_stat(A_DEX, 15, FALSE); - (void)dec_stat(A_CON, 15, FALSE); - (void)dec_stat(A_CHR, 15, FALSE); + dec_stat(A_STR, 15, FALSE); + dec_stat(A_INT, 15, FALSE); + dec_stat(A_WIS, 15, FALSE); + dec_stat(A_DEX, 15, FALSE); + dec_stat(A_CON, 15, FALSE); + dec_stat(A_CHR, 15, FALSE); /* Timeout is set before return */ @@ -7020,12 +6810,12 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_HISTATLOSS: { if (!doit) return "high stat loss"; - (void)dec_stat(A_STR, 25, FALSE); - (void)dec_stat(A_INT, 25, FALSE); - (void)dec_stat(A_WIS, 25, FALSE); - (void)dec_stat(A_DEX, 25, FALSE); - (void)dec_stat(A_CON, 25, FALSE); - (void)dec_stat(A_CHR, 25, FALSE); + dec_stat(A_STR, 25, FALSE); + dec_stat(A_INT, 25, FALSE); + dec_stat(A_WIS, 25, FALSE); + dec_stat(A_DEX, 25, FALSE); + dec_stat(A_CON, 25, FALSE); + dec_stat(A_CHR, 25, FALSE); /* Timeout is set before return */ @@ -7095,7 +6885,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_HUNGER: { if (!doit) return "create hunger"; - (void)set_food(PY_FOOD_WEAK); + set_food(PY_FOOD_WEAK); /* Timeout is set before return */ @@ -7196,7 +6986,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) case ACT_CURE_HUNGER: { if (!doit) return "satisfy hunger every 100 turns"; - (void)set_food(PY_FOOD_MAX - 1); + set_food(PY_FOOD_MAX - 1); /* Timeout is set before return */ @@ -7373,8 +7163,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) c_ptr->info &= ~(CAVE_GLOW); /* Hack -- Forget "boring" grids */ - if (cave_plain_floor_grid(c_ptr) && - !(c_ptr->info & (CAVE_TRDT))) + if (cave_plain_floor_grid(c_ptr)) { /* Forget the grid */ c_ptr->info &= ~(CAVE_MARK); @@ -7561,7 +7350,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) if (!get_aim_dir(&dir)) break; fire_ball(GF_COLD, dir, 50, 2); - (void)set_oppose_cold(p_ptr->oppose_cold + randint(20) + 20); + set_oppose_cold(p_ptr->oppose_cold + randint(20) + 20); o_ptr->timeout = rand_int(50) + 50; @@ -7575,7 +7364,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) if (!get_aim_dir(&dir)) break; fire_ball(GF_FIRE, dir, 50, 2); - (void)set_oppose_fire(p_ptr->oppose_fire + randint(20) + 20); + set_oppose_fire(p_ptr->oppose_fire + randint(20) + 20); o_ptr->timeout = rand_int(50) + 50; @@ -7588,7 +7377,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) if (!get_aim_dir(&dir)) break; fire_ball(GF_ACID, dir, 50, 2); - (void)set_oppose_acid(p_ptr->oppose_acid + randint(20) + 20); + set_oppose_acid(p_ptr->oppose_acid + randint(20) + 20); o_ptr->timeout = rand_int(50) + 50; @@ -7602,7 +7391,7 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) if (!get_aim_dir(&dir)) break; fire_ball(GF_ELEC, dir, 50, 2); - (void)set_oppose_elec(p_ptr->oppose_elec + randint(20) + 20); + set_oppose_elec(p_ptr->oppose_elec + randint(20) + 20); o_ptr->timeout = rand_int(50) + 50; @@ -7892,37 +7681,3 @@ const char *activation_aux(object_type * o_ptr, bool_ doit, int item) return NULL; } - - -static bool_ activate_spell(object_type * o_ptr, byte choice) -{ - int mana = 0, gf = 0, mod = 0; - - rune_spell s_ptr; - - - if (choice == 1) - { - gf = o_ptr->pval & 0xFFFF; - mod = o_ptr->pval3 & 0xFFFF; - mana = o_ptr->pval2 & 0xFF; - } - else if (choice == 2) - { - gf = o_ptr->pval >> 16; - mod = o_ptr->pval3 >> 16; - mana = o_ptr->pval2 >> 8; - } - - s_ptr.type = gf; - s_ptr.rune2 = 1 << mod; - s_ptr.mana = mana; - - /* Execute */ - rune_exec(&s_ptr, 0); - - if (choice == 1) o_ptr->timeout = mana * 5; - if (choice == 2) o_ptr->xtra2 = mana * 5; - - return (TRUE); -} diff --git a/src/cmd6.hpp b/src/cmd6.hpp index ad6619f6..076a9abb 100644 --- a/src/cmd6.hpp +++ b/src/cmd6.hpp @@ -3,16 +3,16 @@ #include "h-basic.h" #include "object_type_fwd.hpp" -extern void set_stick_mode(object_type *o_ptr); -extern void unset_stick_mode(void); -extern void do_cmd_eat_food(void); -extern void do_cmd_quaff_potion(void); -extern void do_cmd_read_scroll(void); -extern void do_cmd_aim_wand(void); -extern void do_cmd_use_staff(void); -extern void do_cmd_zap_rod(void); -extern const char *activation_aux(object_type *o_ptr, bool_ desc, int item); -extern void do_cmd_activate(void); -extern void do_cmd_cut_corpse(void); -extern void do_cmd_cure_meat(void); -extern void do_cmd_drink_fountain(void); +void set_stick_mode(object_type *o_ptr); +void unset_stick_mode(); +void do_cmd_eat_food(); +void do_cmd_quaff_potion(); +void do_cmd_read_scroll(); +void do_cmd_aim_wand(); +void do_cmd_use_staff(); +void do_cmd_zap_rod(); +const char *activation_aux(object_type *o_ptr, bool_ desc, int item); +void do_cmd_activate(); +void do_cmd_cut_corpse(); +void do_cmd_cure_meat(); +void do_cmd_drink_fountain(); diff --git a/src/cmd7.cc b/src/cmd7.cc index 2317f8b9..ec13c908 100644 --- a/src/cmd7.cc +++ b/src/cmd7.cc @@ -13,19 +13,22 @@ #include "cmd1.hpp" #include "cmd5.hpp" #include "cmd6.hpp" +#include "dungeon_flag.hpp" #include "ego_item_type.hpp" #include "files.hpp" +#include "game.hpp" #include "hooks.hpp" #include "mimic.hpp" #include "monster2.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" #include "monster_type.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_flag.hpp" #include "object_kind.hpp" #include "options.hpp" #include "player_type.hpp" -#include "quark.hpp" #include "skills.hpp" #include "spells1.hpp" #include "spells2.hpp" @@ -39,6 +42,8 @@ #include "xtra2.hpp" #include "z-rand.hpp" +#include <fmt/format.h> + /* * Describe class powers of Mindcrafters * @@ -107,6 +112,8 @@ void mindcraft_info(char *p, int power) */ void mimic_info(char *p, int power) { + auto const &k_info = game->edit_data.k_info; + int plev = get_skill(SKILL_MIMICRY); object_type *o_ptr = &p_ptr->inventory[INVEN_OUTER]; @@ -340,7 +347,7 @@ static bool_ get_magic_power(int *sn, magic_power *powers, int max_powers, * do_cmd_cast calls this function if the player's class * is 'mindcrafter'. */ -void do_cmd_mindcraft(void) +void do_cmd_mindcraft() { int n = 0, b = 0; @@ -417,12 +424,10 @@ void do_cmd_mindcraft(void) /* Failed spell */ if (rand_int(100) < chance) { - if (flush_failure) flush(); + flush_on_failure(); msg_format("You failed to concentrate hard enough!"); - sound(SOUND_FAIL); - if (randint(100) < (chance / 2)) { /* Backfire */ @@ -460,8 +465,6 @@ void do_cmd_mindcraft(void) /* Successful spells */ else { - sound(SOUND_ZAP); - /* spell code */ switch (n) { @@ -483,7 +486,6 @@ void do_cmd_mindcraft(void) { b = detect_monsters_normal(DEFAULT_RADIUS); if (plev > 14) b |= detect_monsters_invis(DEFAULT_RADIUS); - if (plev > 4) b |= detect_traps(DEFAULT_RADIUS); } else { @@ -531,7 +533,7 @@ void do_cmd_mindcraft(void) { int ii, ij; - if (dungeon_flags2 & DF2_NO_TELEPORT) + if (dungeon_flags & DF_NO_TELEPORT) { msg_print("Not on special levels!"); break; @@ -627,7 +629,7 @@ void do_cmd_mindcraft(void) } else { - (void)mindblast_monsters(plev * ((plev - 5) / 10 + 1)); + mindblast_monsters(plev * ((plev - 5) / 10 + 1)); } break; @@ -654,11 +656,11 @@ void do_cmd_mindcraft(void) if (!p_ptr->fast) { /* Haste */ - (void)set_fast(b, plev / 5); + set_fast(b, plev / 5); } else { - (void)set_fast(p_ptr->fast + b, plev / 5); + set_fast(p_ptr->fast + b, plev / 5); } break; @@ -722,7 +724,7 @@ void do_cmd_mindcraft(void) msg_print("You faint from the effort!"); /* Hack -- Bypass free action */ - (void)set_paralyzed(randint(5 * oops + 1)); + set_paralyzed(randint(5 * oops + 1)); /* Damage WIS (possibly permanently) */ if (rand_int(100) < 50) @@ -733,7 +735,7 @@ void do_cmd_mindcraft(void) msg_print("You have damaged your mind!"); /* Reduce constitution */ - (void)dec_stat(A_WIS, 15 + randint(10), perm); + dec_stat(A_WIS, 15 + randint(10), perm); } } @@ -762,6 +764,8 @@ static int get_mimic_chance(int mimic) void do_cmd_mimic_lore() { + auto const &k_info = game->edit_data.k_info; + int fail; object_type *o_ptr; @@ -840,7 +844,7 @@ void do_cmd_mimic_lore() p_ptr->update |= (PU_BONUS); } -static bool_ mimic_forbid_travel(void *, void *, void *) +static bool mimic_forbid_travel(void *, void *, void *) { u32b value = p_ptr->mimic_extra >> 16; u32b att = p_ptr->mimic_extra & 0xFFFF; @@ -848,17 +852,17 @@ static bool_ mimic_forbid_travel(void *, void *, void *) if(value > 0 && (att & CLASS_ARMS || att & CLASS_LEGS)) { msg_print("You had best not travel with your extra limbs."); - return TRUE; + return true; } - return FALSE; + return false; } /* * do_cmd_cast calls this function if the player's class * is 'mimic'. */ -void do_cmd_mimic(void) +void do_cmd_mimic() { int n = 0, b = 0; @@ -946,12 +950,10 @@ void do_cmd_mimic(void) /* Failed spell */ if (rand_int(100) < fail) { - if (flush_failure) flush(); + flush_on_failure(); msg_format("You failed to concentrate hard enough!"); - sound(SOUND_FAIL); - if (randint(100) < (fail / 2)) { /* Backfire */ @@ -982,8 +984,6 @@ void do_cmd_mimic(void) /* Successful spells */ else { - sound(SOUND_ZAP); - /* spell code */ switch (n) { @@ -1131,7 +1131,7 @@ void do_cmd_mimic(void) msg_print("You faint from the effort!"); /* Hack -- Bypass free action */ - (void)set_paralyzed(randint(5 * oops + 1)); + set_paralyzed(randint(5 * oops + 1)); /* Damage WIS (possibly permanently) */ if (rand_int(100) < 50) @@ -1142,7 +1142,7 @@ void do_cmd_mimic(void) msg_print("You have damaged your mind!"); /* Reduce constitution */ - (void)dec_stat(A_DEX, 15 + randint(10), perm); + dec_stat(A_DEX, 15 + randint(10), perm); } } @@ -1158,7 +1158,7 @@ void do_cmd_mimic(void) * do_cmd_cast calls this function if the player's class * is 'beastmaster'. */ -void do_cmd_beastmaster(void) +void do_cmd_beastmaster() { int plev = p_ptr->lev, i, num; @@ -1200,7 +1200,7 @@ void do_cmd_beastmaster(void) /* * Command to ask favors from your god. */ -void do_cmd_pray(void) +void do_cmd_pray() { if (p_ptr->pgod == GOD_NONE) { @@ -1228,7 +1228,7 @@ void do_cmd_pray(void) /* * Return percentage chance of spell failure. */ -int spell_chance_random(random_spell* rspell) +int spell_chance_random(random_spell const *rspell) { int chance, minfail; @@ -1263,29 +1263,28 @@ int spell_chance_random(random_spell* rspell) */ static void print_spell_batch(int batch, int max) { - char buff[80]; - - random_spell* rspell; - - int i; - + auto const &random_spells = p_ptr->random_spells; prt(format(" %-30s Lev Fail Mana Damage ", "Name"), 1, 20); + int i; for (i = 0; i < max; i++) { - rspell = &random_spells[batch * 10 + i]; + auto rspell = &random_spells[batch * 10 + i]; + + std::string buff; + std::string name = name_spell(rspell); if (rspell->untried) { - strnfmt(buff, 80, " %c) %-30s (Spell untried) ", - I2A(i), rspell->name); + buff = fmt::format(" {:c}) {:<30} (Spell untried) ", + (char) I2A(i), name); } else { - strnfmt(buff, 80, " %c) %-30s %3d %4d%% %3d %3dd%d ", - I2A(i), rspell->name, + buff = fmt::format(" {:c}) {:<30} {:>3d} {:>4d}% {:>3d} {:>3d}d{:d} ", + (char) I2A(i), name, rspell->level, spell_chance_random(rspell), rspell->mana, rspell->dam_dice, rspell->dam_sides); } @@ -1301,18 +1300,13 @@ static void print_spell_batch(int batch, int max) /* * List ten random spells and ask to pick one. */ -static random_spell* select_spell_from_batch(int batch) +static random_spell* select_spell_from_batch(std::size_t batch) { - char tmp[160]; - - char out_val[30]; + auto &random_spells = p_ptr->random_spells; + char tmp[160]; char which; - - int mut_max = 10; - - random_spell* ret; - + random_spell* ret = nullptr; /* Enter "icky" mode */ character_icky = TRUE; @@ -1320,13 +1314,12 @@ static random_spell* select_spell_from_batch(int batch) /* Save the screen */ Term_save(); - if (spell_num < (batch + 1) * 10) - { - mut_max = spell_num - batch * 10; - } + int const mut_max = (random_spells.size() < (batch + 1) * 10) + ? random_spells.size() - batch * 10 + : 10; - strnfmt(tmp, 160, "(a-%c, A-%c to browse, / to rename, - to comment) Select a power: ", - I2A(mut_max - 1), I2A(mut_max - 1) - 'a' + 'A'); + strnfmt(tmp, 160, "(a-%c) Select a power: ", + I2A(mut_max - 1)); prt(tmp, 0, 0); @@ -1365,65 +1358,7 @@ static random_spell* select_spell_from_batch(int batch) continue; } - /* Rename */ - if (which == '/') - { - prt("Rename which power: ", 0, 0); - which = tolower(inkey()); - - if (isalpha(which) && (A2I(which) <= mut_max)) - { - strcpy(out_val, random_spells[batch*10 + A2I(which)].name); - if (get_string("Name this power: ", out_val, 29)) - { - strcpy(random_spells[batch*10 + A2I(which)].name, out_val); - } - prt(tmp, 0, 0); - } - else - { - bell(); - prt(tmp, 0, 0); - } - - /* Wait for next command */ - continue; - } - - /* Comment */ - if (which == '-') - { - prt("Comment which power: ", 0, 0); - which = tolower(inkey()); - - if (isalpha(which) && (A2I(which) <= mut_max)) - { - strcpy(out_val, random_spells[batch*10 + A2I(which)].desc); - if (get_string("Comment this power: ", out_val, 29)) - { - strcpy(random_spells[batch*10 + A2I(which)].desc, out_val); - } - prt(tmp, 0, 0); - } - else - { - bell(); - prt(tmp, 0, 0); - } - - /* Wait for next command */ - continue; - } - - if (isalpha(which) && isupper(which)) - { - which = tolower(which); - c_prt(TERM_L_BLUE, format("%s : %s", random_spells[batch*10 + A2I(which)].name, random_spells[batch*10 + A2I(which)].desc), 0, 0); - inkey(); - prt(tmp, 0, 0); - continue; - } - else if (isalpha(which) && (A2I(which) < mut_max)) + if (isalpha(which) && (A2I(which) < mut_max)) { /* Pick the power */ ret = &random_spells[batch * 10 + A2I(which)]; @@ -1453,12 +1388,11 @@ static random_spell* select_spell_from_batch(int batch) */ static random_spell* select_spell() { - char tmp[160]; + auto const &random_spells = p_ptr->random_spells; + char tmp[160]; char which; - int batch_max = (spell_num - 1) / 10; - random_spell *ret; @@ -1470,12 +1404,15 @@ static random_spell* select_spell() } /* No spells available */ - if (spell_num == 0) + if (random_spells.empty()) { msg_print("There are no spells you can cast."); return NULL; } + /* How many spells in the last batch? */ + int batch_max = (random_spells.size() - 1) / 10; + /* Enter "icky" mode */ character_icky = TRUE; @@ -1535,7 +1472,7 @@ static random_spell* select_spell() } -void do_cmd_powermage(void) +void do_cmd_powermage() { random_spell *s_ptr; @@ -1581,7 +1518,7 @@ void do_cmd_powermage(void) char sfail[80]; /* Flush input if told so */ - if (flush_failure) flush(); + flush_on_failure(); /* Insane players can see something strange */ if (rand_int(100) < insanity) @@ -1596,8 +1533,6 @@ void do_cmd_powermage(void) msg_print("You failed to get the spell off!"); } - sound(SOUND_FAIL); - /* Let time pass */ if (is_magestaff()) energy_use = 80; else energy_use = 100; @@ -1615,7 +1550,7 @@ void do_cmd_powermage(void) p_ptr->csp -= s_ptr->mana; - s_ptr->untried = FALSE; + s_ptr->untried = false; proj_flags = s_ptr->proj_flags; /* Hack -- Spell needs a target */ @@ -1761,7 +1696,7 @@ void brand_ammo(int brand_type, int bolts_only) } else { - if (flush_failure) flush(); + flush_on_failure(); msg_print("The enchantment failed."); } } @@ -1792,6 +1727,8 @@ void summon_monster(int sumtype) */ void do_cmd_possessor() { + auto const &r_info = game->edit_data.r_info; + char ch, ext; @@ -1831,8 +1768,6 @@ void do_cmd_possessor() if (ext == 1) { - bool_ use_great = FALSE; - if (p_ptr->disembodied) { msg_print("You don't currently own a body to use."); @@ -1840,26 +1775,11 @@ void do_cmd_possessor() } /* Do we have access to all the powers ? */ - if (get_skill_scale(SKILL_POSSESSION, 100) >= r_info[p_ptr->body_monster].level) - use_great = TRUE; + bool use_great = (get_skill_scale(SKILL_POSSESSION, 100) >= r_info[p_ptr->body_monster].level); - use_symbiotic_power(p_ptr->body_monster, use_great, FALSE, FALSE); - - if (p_ptr->csp < 0) - { - msg_print("You lose control of your body!"); - if (!do_cmd_leave_body(FALSE)) - { - cmsg_print(TERM_VIOLET, - "You are forced back into your body by your cursed items, " - "you suffer a system shock!"); - - p_ptr->chp = 1; - - /* Display the hitpoints */ - p_ptr->redraw |= (PR_FRAME); - } - } + /* Select power */ + use_monster_power(p_ptr->body_monster, use_great); + assert(p_ptr->csp >= 0); // Sanity check } else if (ext == 2) { @@ -1900,7 +1820,7 @@ static object_filter_t const &item_tester_hook_convertible() * do_cmd_cast calls this function if the player's class * is 'archer'. */ -void do_cmd_archer(void) +void do_cmd_archer() { int ext = 0; char ch; @@ -1992,11 +1912,11 @@ void do_cmd_archer(void) q_ptr->discount = 90; q_ptr->found = OBJ_FOUND_SELFMADE; - (void)inven_carry(q_ptr, FALSE); + inven_carry(q_ptr, FALSE); msg_print("You make some ammo."); - (void)wall_to_mud(dir); + wall_to_mud(dir); p_ptr->update |= (PU_VIEW | PU_FLOW | PU_MON_LITE); p_ptr->window |= (PW_OVERHEAD); } @@ -2035,7 +1955,7 @@ void do_cmd_archer(void) inc_stack_size(item, -1); - (void)inven_carry(q_ptr, FALSE); + inven_carry(q_ptr, FALSE); } /**********Create bolts*********/ @@ -2071,14 +1991,14 @@ void do_cmd_archer(void) inc_stack_size(item, -1); - (void)inven_carry(q_ptr, FALSE); + inven_carry(q_ptr, FALSE); } } /* * Control whether shots are allowed to pierce */ -void do_cmd_set_piercing(void) +void do_cmd_set_piercing() { char ch; char com[80]; @@ -2148,7 +2068,7 @@ void necro_info(char *p, int power) /* * Cast a Necromancy spell */ -void do_cmd_necromancer(void) +void do_cmd_necromancer() { int n = 0, b = 0; int chance; @@ -2223,9 +2143,8 @@ void do_cmd_necromancer(void) /* Failed spell */ if (rand_int(100) < chance) { - if (flush_failure) flush(); + flush_on_failure(); msg_format("You failed to concentrate hard enough!"); - sound(SOUND_FAIL); if (randint(100) < (chance / 2)) { @@ -2269,8 +2188,6 @@ void do_cmd_necromancer(void) } else { - sound(SOUND_ZAP); - /* spell code */ switch (n) { @@ -2326,7 +2243,7 @@ void do_cmd_necromancer(void) object_prep(o_ptr, k_idx); apply_magic(o_ptr, plev * 2, TRUE, TRUE, TRUE); - o_ptr->art_flags5 |= TR5_TEMPORARY; + o_ptr->art_flags |= TR_TEMPORARY; o_ptr->timeout = dur; /* These objects are "storebought" */ @@ -2335,7 +2252,7 @@ void do_cmd_necromancer(void) object_aware(o_ptr); object_known(o_ptr); - (void)inven_carry(o_ptr, FALSE); + inven_carry(o_ptr, FALSE); k_allow_special[k_idx] = FALSE; @@ -2425,7 +2342,7 @@ void do_cmd_necromancer(void) msg_print("You faint from the effort!"); /* Hack -- Bypass free action */ - (void)set_paralyzed(randint(5 * oops + 1)); + set_paralyzed(randint(5 * oops + 1)); /* Damage CON (possibly permanently) */ if (rand_int(100) < 50) @@ -2436,7 +2353,7 @@ void do_cmd_necromancer(void) msg_print("You have damaged your body!"); /* Reduce constitution */ - (void)dec_stat(A_CON, 15 + randint(10), perm); + dec_stat(A_CON, 15 + randint(10), perm); } } @@ -2448,23 +2365,6 @@ void do_cmd_necromancer(void) } /* - * Hook to determine if an object is "runestone" - */ -static bool item_tester_hook_runestone(object_type const *o_ptr) -{ - return ((o_ptr->tval == TV_RUNE2) && - (o_ptr->sval == RUNE_STONE) && - (o_ptr->pval == 0)); -} - -static bool item_tester_hook_runestone_full(object_type const *o_ptr) -{ - return ((o_ptr->tval == TV_RUNE2) && - (o_ptr->sval == RUNE_STONE) && - (o_ptr->pval != 0)); -} - -/* * math.h(sqrt) is banned of angband so ... :) */ s32b sroot(s32b n) @@ -2486,1054 +2386,6 @@ s32b sroot(s32b n) } -/* - * Damage formula, for runes - */ -void rune_calc_power(s32b *power, s32b *powerdiv) -{ - /* Not too weak power(paranoia) */ - *power = (*power < 1) ? 1 : *power; - *power += 3; - - *power = 37 * sroot(*power) / 10; - - /* To reduce the high level power, while increasing the low levels */ - *powerdiv = *power / 3; - if (*powerdiv < 1) *powerdiv = 1; - - /* Use the spell multiplicator */ - *power *= (p_ptr->to_s / 2) ? (p_ptr->to_s / 2) : 1; -} - - -/* - * Return percentage chance of runespell failure. - */ -int spell_chance_rune(rune_spell* spell) -{ - int chance, minfail; - - s32b power = spell->mana, power_rune = 0, powerdiv = 0; - - - if (spell->rune2 & RUNE_POWER_SURGE) - { - power_rune += 4; - } - if (spell->rune2 & RUNE_ARMAGEDDON) - { - power_rune += 3; - } - if (spell->rune2 & RUNE_SPHERE) - { - power_rune += 2; - } - if (spell->rune2 & RUNE_RAY) - { - power_rune += 1; - } - - rune_calc_power(&power, &powerdiv); - - chance = (5 * power_rune) + (power); - - /* Reduce failure rate by INT/WIS adjustment */ - chance -= 3 * (adj_mag_stat[p_ptr->stat_ind[A_DEX]] - 1); - - /* Extract the minimum failure rate */ - minfail = adj_mag_fail[p_ptr->stat_ind[A_DEX]]; - - /* Return the chance */ - return clamp_failure_chance(chance, minfail); -} - - -/* - * Combine the Runes - */ -int rune_exec(rune_spell *spell, int cost) -{ - int dir, power_rune = 0, mana_used, plev = get_skill(SKILL_RUNECRAFT); - - int chance; - - s32b power, powerdiv; - - int rad = 0, ty = -1, tx = -1, dam = 0, flg = 0; - - - if (spell->rune2 & RUNE_POWER_SURGE) - { - power_rune += 4; - } - if (spell->rune2 & RUNE_ARMAGEDDON) - { - power_rune += 3; - } - if (spell->rune2 & RUNE_SPHERE) - { - power_rune += 2; - } - if (spell->rune2 & RUNE_RAY) - { - power_rune += 1; - } - - - power = spell->mana; - - if (cost && ((power * cost / 100) > p_ptr->csp - (power_rune * (plev / 5)))) - { - power = p_ptr->csp - (power_rune * (plev / 5)); - mana_used = power + (power_rune * (plev / 5)); - } - else - { - mana_used = (power * cost / 100) + (power_rune * (plev / 5)); - } - - rune_calc_power(&power, &powerdiv); - - dam = damroll(powerdiv, power); - - if (wizard) msg_format("Rune %dd%d = dam %d", powerdiv, power, dam); - - /* Extract the base spell failure rate */ - chance = spell_chance_rune(spell); - - /* Failure ? */ - if (rand_int(100) < chance) - { - int insanity = (p_ptr->msane - p_ptr->csane) * 100 / p_ptr->msane; - char sfail[80]; - - /* Flush input if told so */ - if (flush_failure) flush(); - - /* Insane players can see something strange */ - if (rand_int(100) < insanity) - { - get_rnd_line("sfail.txt", sfail); - msg_format("A cloud of %s appears above you.", sfail); - } - - /* Normal failure messages */ - else - { - msg_print("You failed to get the spell off!"); - } - - sound(SOUND_FAIL); - - if (is_magestaff()) energy_use = 80; - else energy_use = 100; - - /* Window stuff */ - p_ptr->window |= (PW_PLAYER); - p_ptr->redraw |= (PR_FRAME); - return (mana_used); - } - - if (spell->rune2 & RUNE_POWER_SURGE) - { - flg |= (PROJECT_VIEWABLE); - ty = p_ptr->py; - tx = p_ptr->px; - } - - if (spell->rune2 & RUNE_ARMAGEDDON) - { - flg |= (PROJECT_THRU); - flg |= (PROJECT_KILL); - flg |= (PROJECT_ITEM); - flg |= (PROJECT_GRID); - flg |= (PROJECT_METEOR_SHOWER); - rad = (power / 8 == 0) ? 1 : power / 8; - rad = (rad > 10) ? 10 : rad; - ty = p_ptr->py; - tx = p_ptr->px; - } - - if (spell->rune2 & RUNE_SPHERE) - { - flg |= (PROJECT_THRU); - flg |= (PROJECT_KILL); - flg |= (PROJECT_ITEM); - flg |= (PROJECT_GRID); - rad = (power / 8 == 0) ? 1 : power / 8; - rad = (rad > 10) ? 10 : rad; - ty = p_ptr->py; - tx = p_ptr->px; - } - - if (spell->rune2 & RUNE_RAY) - { - flg |= (PROJECT_THRU); - flg |= (PROJECT_KILL); - flg |= (PROJECT_BEAM); - ty = -1; - tx = -1; - } - if (spell->rune2 & RUNE_ARROW) - { - flg |= (PROJECT_THRU); - flg |= (PROJECT_STOP); - flg |= (PROJECT_KILL); - ty = -1; - tx = -1; - } - if (spell->rune2 & RUNE_SELF) - { - flg |= (PROJECT_THRU); - flg |= (PROJECT_STOP); - flg |= (PROJECT_KILL); - ty = p_ptr->py; - tx = p_ptr->px; - unsafe = TRUE; - } - - if ((ty == -1) && (tx == -1)) - { - if (!get_aim_dir(&dir)) return (mana_used); - - /* Use the given direction */ - tx = p_ptr->px + ddx[dir]; - ty = p_ptr->py + ddy[dir]; - - /* Hack -- Use an actual "target" */ - if ((dir == 5) && target_okay()) - { - tx = target_col; - ty = target_row; - } - } - - if (flg & PROJECT_VIEWABLE) - { - project_hack(spell->type, dam); - } - else if (flg & PROJECT_METEOR_SHOWER) - { - project_meteor(rad, spell->type, dam, flg); - } - else project(0, rad, ty, tx, dam, spell->type, flg); - - if (unsafe) unsafe = FALSE; - - /* Window stuff */ - p_ptr->window |= (PW_PLAYER); - p_ptr->redraw |= (PR_FRAME); - - return (mana_used); -} - - -/* - * Test if all runes needed at in the player p_ptr->inventory - */ -bool_ test_runespell(rune_spell *spell) -{ - int i; - - object_type *o_ptr; - - bool_ typeok = FALSE; - - int rune2 = 0; - - - for (i = 0; i < INVEN_WIELD; i++) - { - o_ptr = &p_ptr->inventory[i]; - - if (!o_ptr->k_idx) continue; - - /* Does the rune1(type) match ? */ - if ((o_ptr->tval == TV_RUNE1) && (o_ptr->sval == spell->type)) - { - typeok = TRUE; - } - - if ((o_ptr->tval == TV_RUNE2) && (o_ptr->sval != RUNE_STONE)) - { - /* Add it to the list */ - rune2 |= 1 << o_ptr->sval; - } - } - - /* Need all runes to be present */ - return (typeok && ((rune2 & spell->rune2) == spell->rune2)); -} - - -/* - * Ask for rune, rune2 and mana - */ -bool_ get_runespell(rune_spell *spell) -{ - s32b rune_combine = 0; - - /* Lambda to use for selecting the secondary rune(s) */ - auto rune2_filter = [&](object_type const *o_ptr) -> bool { - return ((o_ptr->tval == TV_RUNE2) && - (o_ptr->sval != RUNE_STONE) && - (!(rune_combine & BIT(o_ptr->sval)))); - }; - - /* Prompt */ - const char *const q = "Use which rune? "; - const char *const s = "You have no rune to use."; - - /* Extract first rune for the base effect */ - int type = 0; - { - int item; - if (!get_item(&item, q, s, (USE_INVEN | USE_FLOOR), object_filter::TVal(TV_RUNE1))) - { - return FALSE; - } - - object_type *o_ptr = get_object(item); - type = o_ptr->sval; - } - - /* Choose secondary rune(s) */ - int rune2 = 0; - while (1) - { - int item; - if (!get_item(&item, q, nullptr, (USE_INVEN | USE_FLOOR), rune2_filter)) - { - break; - } - - object_type *o_ptr = get_object(item); - - rune_combine |= 1 << o_ptr->sval; - rune2 |= 1 << o_ptr->sval; - } - - if (!rune2) - { - msg_print("You have not selected a second rune!"); - return (FALSE); - } - - int power_rune = 0; - int plev = get_skill(SKILL_RUNECRAFT); - s32b power = get_quantity("Which amount of Mana? ", - p_ptr->csp - (power_rune * (plev / 5))); - if (power < 1) - { - power = 1; - } - - spell->mana = power; - spell->type = type; - spell->rune2 = rune2; - - return (TRUE); -} - - -void do_cmd_rune(void) -{ - rune_spell spell; - - - /* Require some mana */ - if (p_ptr->csp <= 0) - { - msg_print("You have no mana!"); - return; - } - - /* Require lite */ - if (p_ptr->blind || no_lite()) - { - msg_print("You cannot see!"); - return; - } - - /* Not when confused */ - if (p_ptr->confused) - { - msg_print("You are too confused!"); - return; - } - - if (!get_runespell(&spell)) return; - - /* Execute at normal mana cost */ - p_ptr->csp -= rune_exec(&spell, 100); - - /* Safety :) */ - if (p_ptr->csp < 0) p_ptr->csp = 0; - - /* Take a turn */ - if (is_magestaff()) energy_use = 80; - else energy_use = 100; - - /* Window stuff */ - p_ptr->window |= (PW_PLAYER); - p_ptr->redraw |= (PR_FRAME); -} - - -/* - * Print a batch of runespells. - */ -static void print_runespell_batch(int batch, int max) -{ - char buff[80]; - - rune_spell* spell; - - int i; - - s32b power, powerdiv; - - int p, dp; - - - prt(format(" %-30s Fail Mana Power", "Name"), 1, 20); - - for (i = 0; i < max; i++) - { - spell = &rune_spells[batch * 10 + i]; - - power = spell->mana; - rune_calc_power(&power, &powerdiv); - p = power; - dp = powerdiv; - - strnfmt(buff, 80, " %c) %-30s %4d%% %4d %dd%d ", I2A(i), spell->name, - spell_chance_rune(spell), spell->mana, dp, p); - - prt(buff, 2 + i, 20); - } - prt("", 2 + i, 20); -} - - - -/* - * List ten random spells and ask to pick one. - */ - -static rune_spell* select_runespell_from_batch(int batch, int *s_idx) -{ - char tmp[160]; - - char out_val[30]; - - char which; - - int mut_max = 10; - - rune_spell* ret; - - - character_icky = TRUE; - - if (rune_num < (batch + 1) * 10) - { - mut_max = rune_num - batch * 10; - } - - strnfmt(tmp, 160, "(a-%c, * to list, / to rename, - to comment) Select a power: ", - I2A(mut_max - 1)); - - prt(tmp, 0, 0); - - while (1) - { - Term_save(); - - print_runespell_batch(batch, mut_max); - - which = inkey(); - - Term_load(); - - if (which == ESCAPE) - { - *s_idx = -1; - ret = NULL; - break; - } - else if ((which == '*') || (which == '?') || (which == ' ')) - { - print_runespell_batch(batch, mut_max); - } - else if ((which == '\r') && (mut_max == 1)) - { - *s_idx = batch * 10; - ret = &rune_spells[batch * 10]; - break; - } - else if (which == '/') - { - prt("Rename which power: ", 0, 0); - which = tolower(inkey()); - - if (isalpha(which) && (A2I(which) <= mut_max)) - { - strcpy(out_val, rune_spells[batch*10 + A2I(which)].name); - if (get_string("Name this power: ", out_val, 29)) - { - strcpy(rune_spells[batch*10 + A2I(which)].name, out_val); - } - prt(tmp, 0, 0); - } - else - { - bell(); - prt(tmp, 0, 0); - } - } - else - { - which = tolower(which); - if (isalpha(which) && (A2I(which) < mut_max)) - { - *s_idx = batch * 10 + A2I(which); - ret = &rune_spells[batch * 10 + A2I(which)]; - break; - } - else - { - bell(); - } - } - } - - character_icky = FALSE; - - return (ret); -} - - -/* - * Pick a random spell from a menu - */ - -rune_spell* select_runespell(int *s_idx) -{ - char tmp[160]; - - char which; - - int batch_max = (rune_num - 1) / 10; - - if (rune_num == 0) - { - msg_print("There are no runespells you can cast."); - return (NULL); - } - - character_icky = TRUE; - Term_save(); - - strnfmt(tmp, 160, "(a-%c) Select batch of powers: ", I2A(batch_max)); - - prt(tmp, 0, 0); - - while (1) - { - which = inkey(); - - if (which == ESCAPE) - { - Term_load(); - character_icky = FALSE; - return (NULL); - } - else if ((which == '\r') && (batch_max == 0)) - { - Term_load(); - character_icky = FALSE; - return (select_runespell_from_batch(0, s_idx)); - - } - else - { - which = tolower(which); - if (isalpha(which) && (A2I(which) <= batch_max)) - { - Term_load(); - character_icky = FALSE; - return (select_runespell_from_batch(A2I(which), s_idx)); - } - else - { - bell(); - } - } - } -} - - -/* - * Cast a memorized runespell - * Note that the only limits are antimagic & conf, NOT blind - */ -void do_cmd_rune_cast() -{ - rune_spell *s_ptr; - - int s_idx; - - - /* Require some mana */ - if (p_ptr->csp <= 0) - { - msg_print("You have no mana!"); - return; - } - - /* No magic */ - if (p_ptr->antimagic) - { - msg_print("Your anti-magic field disrupts any magic attempts."); - return; - } - - /* No magic */ - if (p_ptr->anti_magic) - { - msg_print("Your anti-magic shell disrupts any magic attempts."); - return; - } - - /* Not when confused */ - if (p_ptr->confused) - { - msg_print("You are too confused!"); - return; - } - - s_ptr = select_runespell(&s_idx); - - if (s_ptr == NULL) return; - - /* Need the runes */ - if (!test_runespell(s_ptr)) - { - msg_print("You lack some essential rune(s) for this runespell!"); - return; - } - - /* Execute at normal mana cost */ - p_ptr->csp -= rune_exec(s_ptr, 100); - - /* Safety :) */ - if (p_ptr->csp < 0) p_ptr->csp = 0; - - /* Take a turn */ - if (is_magestaff()) energy_use = 80; - else energy_use = 100; - - /* Window stuff */ - p_ptr->window |= (PW_PLAYER); - p_ptr->redraw |= (PR_FRAME); -} - - -/* - * Cast a runespell from a carved runestone - */ -void do_cmd_runestone() -{ - rune_spell s_ptr; - - int item; - - - /* Require some mana */ - if (p_ptr->csp <= 0) - { - msg_print("You have no mana!"); - return; - } - - /* Require lite */ - if (p_ptr->blind || no_lite()) - { - msg_print("You cannot see!"); - return; - } - - /* Not when confused */ - if (p_ptr->confused) - { - msg_print("You are too confused!"); - return; - } - - /* No magic */ - if (p_ptr->antimagic) - { - msg_print("Your anti-magic field disrupts any magic attempts."); - return; - } - - /* No magic */ - if (p_ptr->anti_magic) - { - msg_print("Your anti-magic shell disrupts any magic attempts."); - return; - } - - /* Get an item */ - if (!get_item(&item, - "Cast from which runestone? ", - "You have no runestone to cast from.", - (USE_INVEN | USE_FLOOR), - item_tester_hook_runestone_full)) - { - return; - } - - /* Get the item */ - object_type *o_ptr = get_object(item); - - s_ptr.type = o_ptr->pval; - s_ptr.rune2 = o_ptr->pval2; - s_ptr.mana = o_ptr->pval3; - - /* Execute less mana */ - p_ptr->csp -= rune_exec(&s_ptr, 75); - - /* Safety :) */ - if (p_ptr->csp < 0) p_ptr->csp = 0; - - /* Take a turn */ - energy_use = 100; - - /* Window stuff */ - p_ptr->window |= (PW_PLAYER); - p_ptr->redraw |= (PR_FRAME); -} - - -/* - * Add a runespell to the list - */ -void do_cmd_rune_add_mem() -{ - rune_spell s_ptr; - - rune_spell *ds_ptr = &rune_spells[rune_num]; - - - /* Not when confused */ - if (p_ptr->confused) - { - msg_print("You are too confused!"); - return; - } - - - if (rune_num >= MAX_RUNES) - { - msg_print("You have already learned the maximum number of runespells!"); - return; - } - - if (!get_runespell(&s_ptr)) return; - - ds_ptr->type = s_ptr.type; - ds_ptr->rune2 = s_ptr.rune2; - ds_ptr->mana = s_ptr.mana; - strcpy(ds_ptr->name, "Unnamed Runespell"); - - get_string("Name this runespell: ", ds_ptr->name, 29); - - rune_num++; - - /* Take a turn */ - energy_use = 100; - - /* Window stuff */ - p_ptr->window |= (PW_PLAYER); - p_ptr->redraw |= (PR_FRAME); -} - - -/* - * Carve a runespell onto a Runestone - */ -void do_cmd_rune_carve() -{ - rune_spell s_ptr; - - int item, i; - - char out_val[80]; - - - /* Not when confused */ - if (p_ptr->confused) - { - msg_print("You are too confused!"); - return; - } - - /* Require lite */ - if (p_ptr->blind || no_lite()) - { - msg_print("You cannot see!"); - return; - } - - if (!get_check("Beware, this will destroy the involved runes, continue?")) - { - return; - } - - if (!get_runespell(&s_ptr)) return; - - /* Get an item */ - if (!get_item(&item, - "Use which runestone? ", - "You have no runestone to use.", - (USE_INVEN | USE_FLOOR), - item_tester_hook_runestone)) - { - return; - } - - /* Get the item */ - object_type *o_ptr = get_object(item); - - o_ptr->pval = s_ptr.type; - o_ptr->pval2 = s_ptr.rune2; - o_ptr->pval3 = s_ptr.mana; - - /* Start with nothing */ - strcpy(out_val, ""); - - /* Use old inscription */ - if (o_ptr->note) - { - /* Start with the old inscription */ - strcpy(out_val, quark_str(o_ptr->note)); - } - - /* Get a new inscription (possibly empty) */ - if (get_string("Name this runestone: ", out_val, 80)) - { - /* Save the inscription */ - o_ptr->note = quark_add(out_val); - - /* Combine the pack */ - p_ptr->notice |= (PN_COMBINE); - - /* Window stuff */ - p_ptr->window |= (PW_INVEN | PW_EQUIP); - } - - /* Delete the runes */ - for (i = 0; i < INVEN_WIELD; i++) - { - o_ptr = &p_ptr->inventory[i]; - - if (o_ptr->k_idx) - { - bool_ do_del = FALSE; - - if ((o_ptr->tval == TV_RUNE1) && (o_ptr->sval == s_ptr.type)) do_del = TRUE; - if ((o_ptr->tval == TV_RUNE2) && (BIT(o_ptr->sval) & s_ptr.rune2)) do_del = TRUE; - - if (do_del) - { - inc_stack_size_ex(i, -1, OPTIMIZE, NO_DESCRIBE); - } - } - } - - /* Take a turn -- Carving takes a LONG time */ - energy_use = 400; - - /* Window stuff */ - p_ptr->window |= (PW_PLAYER); - p_ptr->redraw |= (PR_FRAME); -} - - -/* - * Remove a runespell - */ -void do_cmd_rune_del() -{ - rune_spell *s_ptr; - - int s_idx; - - int i; - - - /* Not when confused */ - if (p_ptr->confused) - { - msg_print("You are too confused!"); - return; - } - - s_ptr = select_runespell(&s_idx); - - if (s_ptr == NULL) return; - - /* Delete and move */ - for (i = s_idx + 1; i < rune_num; i++) - { - rune_spells[i - 1].type = rune_spells[i].type; - rune_spells[i - 1].rune2 = rune_spells[i].rune2; - rune_spells[i - 1].mana = rune_spells[i].mana; - strcpy(rune_spells[i - 1].name, rune_spells[i].name); - } - rune_num--; - - /* Take a turn */ - energy_use = 100; - - /* Window stuff */ - p_ptr->window |= (PW_PLAYER); - p_ptr->redraw |= (PR_FRAME); -} - - -void do_cmd_rune_add() -{ - int ext = 0; - - char ch; - - - /* Select what to do */ - while (TRUE) - { - if (!get_com("Add to [M]emory(need runes to cast) or " - "Carve a [R]unestone(less mana to cast)", &ch)) - { - ext = 0; - break; - } - if ((ch == 'M') || (ch == 'm')) - { - ext = 1; - break; - } - if ((ch == 'R') || (ch == 'r')) - { - ext = 2; - break; - } - } - - switch (ext) - { - /* Create a Spell in memory */ - case 1: - { - do_cmd_rune_add_mem(); - break; - } - - /* Carve a Runestone */ - case 2: - { - do_cmd_rune_carve(); - break; - } - } -} - - -void do_cmd_runecrafter() -{ - int ext = 0; - - char ch; - - - /* Select what to do */ - while (TRUE) - { - if (!get_com("Rune Spell:[C]reate, [D]elete, C[a]st, D[i]rectly Cast " - "or Use [R]unestone", &ch)) - { - ext = 0; - break; - } - if ((ch == 'C') || (ch == 'c')) - { - ext = 1; - break; - } - if ((ch == 'D') || (ch == 'd')) - { - ext = 2; - break; - } - if ((ch == 'A') || (ch == 'a')) - { - ext = 3; - break; - } - if ((ch == 'I') || (ch == 'i')) - { - ext = 4; - break; - } - if ((ch == 'R') || (ch == 'r')) - { - ext = 5; - break; - } - } - - switch (ext) - { - /* Create a Spell */ - case 1: - { - do_cmd_rune_add(); - break; - } - - /* Delete a Spell */ - case 2: - { - do_cmd_rune_del(); - break; - } - - /* Cast a Spell */ - case 3: - { - do_cmd_rune_cast(); - break; - } - - /* Directly Cast a Spell */ - case 4: - { - do_cmd_rune(); - break; - } - - /* Cast a Runestone */ - case 5: - { - do_cmd_runestone(); - break; - } - } -} - - void do_cmd_unbeliever_antimagic() { if (get_skill(SKILL_ANTIMAGIC) < 20) @@ -3572,7 +2424,7 @@ void do_cmd_unbeliever() /* Select what to do */ while (TRUE) { - if (!get_com("Disrupt [C]ontinuum or [D]etect Traps", &ch)) + if (!get_com("Disrupt [C]ontinuum or [D]estroy Doors", &ch)) { ext = 0; break; @@ -3598,20 +2450,18 @@ void do_cmd_unbeliever() break; } - /* Detect Traps */ + /* Destroy Doors */ case 2: { s16b skill = get_skill(SKILL_ANTIMAGIC); if (skill < 25) { - msg_print("You cannot use your detection abilities yet."); + msg_print("You cannot use your door destruction abilities yet."); break; } - detect_traps(DEFAULT_RADIUS); - - if (skill >= 35) destroy_doors_touch(); + destroy_doors_touch(); break; } @@ -3638,6 +2488,8 @@ static object_filter_t const &item_tester_hook_totemable() */ void do_cmd_summoner_extract() { + auto const &r_info = game->edit_data.r_info; + object_type forge, *q_ptr; /* Not when confused */ @@ -3669,7 +2521,7 @@ void do_cmd_summoner_extract() object_type *o_ptr = get_object(item); bool_ partial; - if (r_info[o_ptr->pval2].flags1 & RF1_UNIQUE) + if (r_info[o_ptr->pval2].flags & RF_UNIQUE) { partial = FALSE; } @@ -3701,7 +2553,7 @@ void do_cmd_summoner_extract() object_aware(q_ptr); object_known(q_ptr); q_ptr->ident |= IDENT_MENTAL; - (void)inven_carry(q_ptr, FALSE); + inven_carry(q_ptr, FALSE); msg_print("You extract a totem from the dead corpse."); energy_use += 100; @@ -3710,15 +2562,17 @@ void do_cmd_summoner_extract() void summon_true(int r_idx, int item) { + auto const &r_info = game->edit_data.r_info; + int i, status, x = 1, y = 1, rx, ry = 0, chance; bool_ used; - monster_race *r_ptr = &r_info[r_idx]; + auto r_ptr = &r_info[r_idx]; /* Uniques are less likely to be nice */ - if (r_ptr->flags1 & (RF1_UNIQUE)) + if (r_ptr->flags & RF_UNIQUE) { /* Because it's unique, it will always be destroyed */ used = TRUE; @@ -3877,7 +2731,7 @@ void do_cmd_summoner_summon() } -void do_cmd_summoner(void) +void do_cmd_summoner() { int ext = 0; @@ -3951,7 +2805,7 @@ void do_cmd_summoner(void) /* * Dodge Chance Feedback. */ -void use_ability_blade(void) +void use_ability_blade() { int chance = p_ptr->dodge_chance - ((dun_level * 5) / 6); @@ -4017,7 +2871,7 @@ void symbiotic_info(char *p, int power) /* * Cast a symbiotic spell */ -void do_cmd_symbiotic(void) +void do_cmd_symbiotic() { int n = 0; int chance; @@ -4089,14 +2943,11 @@ void do_cmd_symbiotic(void) /* Failed spell */ if (rand_int(100) < chance) { - if (flush_failure) flush(); + flush_on_failure(); msg_format("You failed to concentrate hard enough!"); - sound(SOUND_FAIL); } else { - sound(SOUND_ZAP); - /* spell code */ switch (n) { @@ -4118,7 +2969,7 @@ void do_cmd_symbiotic(void) m_ptr = &m_list[c_ptr->m_idx]; auto const r_ptr = m_ptr->race(); - if (!(r_ptr->flags1 & RF1_NEVER_MOVE)) + if (!(r_ptr->flags & RF_NEVER_MOVE)) { msg_print("You can only hypnotise monsters that cannot move."); } @@ -4126,7 +2977,7 @@ void do_cmd_symbiotic(void) { msg_print("You can only hypnotise pets and companions."); } - else if (r_ptr->flags9 & RF9_SPECIAL_GENE) + else if (r_ptr->flags & RF_SPECIAL_GENE) { msg_print("You cannot hypnotise this monster."); } @@ -4270,7 +3121,7 @@ void do_cmd_symbiotic(void) break; } - if (0 > use_symbiotic_power(o_ptr->pval, FALSE, FALSE, TRUE)) + if (0 > use_symbiotic_power(o_ptr->pval, false)) return; break; @@ -4291,7 +3142,7 @@ void do_cmd_symbiotic(void) o_ptr->pval2 += hp; if (o_ptr->pval2 > o_ptr->pval3) o_ptr->pval2 = o_ptr->pval3; - msg_format("%s is healed.", symbiote_name(TRUE)); + msg_format("%s is healed.", symbiote_name(true).c_str()); /* Display the monster hitpoints */ p_ptr->redraw |= (PR_FRAME); @@ -4309,7 +3160,7 @@ void do_cmd_symbiotic(void) break; } - if(0 > use_symbiotic_power(o_ptr->pval, TRUE, FALSE, TRUE)) + if(0 > use_symbiotic_power(o_ptr->pval, true)) return; break; @@ -4327,17 +3178,14 @@ void do_cmd_symbiotic(void) case 8: { int y, x; - cave_type *c_ptr; - monster_type *m_ptr; - if (!tgt_pt(&x, &y)) return; - c_ptr = &cave[y][x]; + cave_type *c_ptr = &cave[y][x]; if (!c_ptr->m_idx) break; - m_ptr = &m_list[c_ptr->m_idx]; - use_symbiotic_power(m_ptr->r_idx, TRUE, FALSE, TRUE); + monster_type *m_ptr = &m_list[c_ptr->m_idx]; + use_symbiotic_power(m_ptr->r_idx, true); break; } @@ -4375,7 +3223,7 @@ void do_cmd_symbiotic(void) msg_print("You faint from the effort!"); /* Hack -- Bypass free action */ - (void)set_paralyzed(randint(5 * oops + 1)); + set_paralyzed(randint(5 * oops + 1)); /* Damage CON (possibly permanently) */ if (rand_int(100) < 50) @@ -4386,7 +3234,7 @@ void do_cmd_symbiotic(void) msg_print("You have damaged your body!"); /* Reduce constitution */ - (void)dec_stat(A_CHR, 15 + randint(10), perm); + dec_stat(A_CHR, 15 + randint(10), perm); } } @@ -4419,7 +3267,7 @@ void do_cmd_create_boulder() object_type forge; object_type *q_ptr; - (void)wall_to_mud(dir); + wall_to_mud(dir); /* Get local object */ q_ptr = &forge; @@ -4433,7 +3281,7 @@ void do_cmd_create_boulder() q_ptr->discount = 90; q_ptr->found = OBJ_FOUND_SELFMADE; - (void)inven_carry(q_ptr, FALSE); + inven_carry(q_ptr, FALSE); msg_print("You make some boulders."); @@ -4448,7 +3296,7 @@ void do_cmd_create_boulder() /* * Clamp failure chance */ -extern int clamp_failure_chance(int chance, int minfail) +int clamp_failure_chance(int chance, int minfail) { if (minfail < 0) minfail = 0; diff --git a/src/cmd7.hpp b/src/cmd7.hpp index 162e5461..b9d518b2 100644 --- a/src/cmd7.hpp +++ b/src/cmd7.hpp @@ -1,28 +1,25 @@ #pragma once #include "h-basic.h" -#include "rune_spell_fwd.hpp" #include "object_type_fwd.hpp" -extern void do_cmd_pray(void); -extern void do_cmd_create_boulder(void); -extern int rune_exec(rune_spell *spell, int cost); -extern void necro_info(char *p, int power); -extern void mindcraft_info(char *p, int power); -extern void symbiotic_info(char *p, int power); -extern void mimic_info(char *p, int power); -extern void do_cmd_summoner(void); -extern void do_cmd_mindcraft(void); -extern void do_cmd_mimic(void); -extern void use_ability_blade(void); -extern void do_cmd_beastmaster(void); -extern void do_cmd_powermage(void); -extern void do_cmd_possessor(void); -extern void do_cmd_archer(void); -extern void do_cmd_set_piercing(void); -extern void do_cmd_necromancer(void); -extern void do_cmd_unbeliever(void); -extern void do_cmd_runecrafter(void); -extern void do_cmd_symbiotic(void); -extern s32b sroot(s32b n); -extern int clamp_failure_chance(int chance, int minfail); +void do_cmd_pray(); +void do_cmd_create_boulder(); +void necro_info(char *p, int power); +void mindcraft_info(char *p, int power); +void symbiotic_info(char *p, int power); +void mimic_info(char *p, int power); +void do_cmd_summoner(); +void do_cmd_mindcraft(); +void do_cmd_mimic(); +void use_ability_blade(); +void do_cmd_beastmaster(); +void do_cmd_powermage(); +void do_cmd_possessor(); +void do_cmd_archer(); +void do_cmd_set_piercing(); +void do_cmd_necromancer(); +void do_cmd_unbeliever(); +void do_cmd_symbiotic(); +s32b sroot(s32b n); +int clamp_failure_chance(int chance, int minfail); diff --git a/src/corrupt.cc b/src/corrupt.cc index f182a9e2..bd3ae5f0 100644 --- a/src/corrupt.cc +++ b/src/corrupt.cc @@ -1,7 +1,10 @@ #include "corrupt.hpp" +#include "game.hpp" #include "init1.hpp" +#include "object_flag.hpp" #include "player_race.hpp" +#include "player_race_flag.hpp" #include "player_race_mod.hpp" #include "player_type.hpp" #include "stats.hpp" @@ -12,6 +15,7 @@ #include "z-rand.hpp" #include <cassert> +#include <fmt/format.h> /** * Corruptions @@ -38,45 +42,40 @@ struct corruption_type static void subrace_add_power(player_race_mod *rmp_ptr, int power) { - int i; - - for (i=0; i<4; i++) - { - if (rmp_ptr->powers[i] == -1) - { - rmp_ptr->powers[i] = power; - return; - } - } + rmp_ptr->ps.powers.push_back(power); } static void player_gain_vampire_teeth() { + auto &race_mod_info = game->edit_data.race_mod_info; + player_race_mod *rmp_ptr = NULL; switch_subrace(SUBRACE_SAVE, TRUE); rmp_ptr = &race_mod_info[SUBRACE_SAVE]; subrace_add_power(rmp_ptr, PWR_VAMPIRISM); - rmp_ptr->flags1 = rmp_ptr->flags1 - | PR1_VAMPIRE - | PR1_UNDEAD - | PR1_NO_SUBRACE_CHANGE; + rmp_ptr->flags = rmp_ptr->flags + | PR_VAMPIRE + | PR_UNDEAD + | PR_NO_SUBRACE_CHANGE; } static void player_gain_vampire_strength() { + auto &race_mod_info = game->edit_data.race_mod_info; + player_race_mod *rmp_ptr = &race_mod_info[SUBRACE_SAVE]; - /* Apply the bonuses/penalities */ - rmp_ptr->r_mhp = rmp_ptr->r_mhp + 1; - rmp_ptr->r_exp = rmp_ptr->r_exp + 100; - rmp_ptr->r_adj[A_STR] = rmp_ptr->r_adj[A_STR] + 3; - rmp_ptr->r_adj[A_INT] = rmp_ptr->r_adj[A_INT] + 2; - rmp_ptr->r_adj[A_WIS] = rmp_ptr->r_adj[A_WIS] - 3; - rmp_ptr->r_adj[A_DEX] = rmp_ptr->r_adj[A_DEX] - 2; - rmp_ptr->r_adj[A_CON] = rmp_ptr->r_adj[A_CON] + 1; - rmp_ptr->r_adj[A_CHR] = rmp_ptr->r_adj[A_CHR] - 4; + rmp_ptr->ps.mhp += +1; + rmp_ptr->ps.exp += +100; + + rmp_ptr->ps.adj[A_STR] += +3; + rmp_ptr->ps.adj[A_INT] += +2; + rmp_ptr->ps.adj[A_WIS] += -3; + rmp_ptr->ps.adj[A_DEX] += -2; + rmp_ptr->ps.adj[A_CON] += +1; + rmp_ptr->ps.adj[A_CHR] += -4; /* be reborn! */ do_rebirth(); @@ -85,33 +84,29 @@ static void player_gain_vampire_strength() static void player_gain_vampire() { + auto &race_mod_info = game->edit_data.race_mod_info; + player_race_mod *rmp_ptr = &race_mod_info[SUBRACE_SAVE]; - /* Be a Vampire and be proud of it */ - cptr title = rmp_ptr->title; - if (streq(title, "Vampire")) + if (rmp_ptr->title == "Vampire") { - title = "Vampire"; rmp_ptr->place = FALSE; - set_subrace_title(rmp_ptr, title); } else { - char buf[512]; - sprintf(buf, "Vampire %s", title); - set_subrace_title(rmp_ptr, buf); + rmp_ptr->title = fmt::format("Vampire {}", rmp_ptr->title); } /* Bonus/and .. not bonus :) */ - rmp_ptr->flags1 = rmp_ptr->flags1 | PR1_HURT_LITE; - rmp_ptr->oflags2[2] = rmp_ptr->oflags2[2] - | TR2_RES_POIS - | TR2_RES_NETHER - | TR2_RES_COLD - | TR2_RES_DARK - | TR2_HOLD_LIFE; - rmp_ptr->oflags3[2] = rmp_ptr->oflags3[2] - | TR3_LITE1; + rmp_ptr->flags |= PR_HURT_LITE; + rmp_ptr->lflags[1].oflags |= + ( TR_RES_POIS + | TR_RES_NETHER + | TR_RES_COLD + | TR_RES_DARK + | TR_HOLD_LIFE + | TR_LITE1 + ); } /** @@ -706,7 +701,7 @@ static bool_ player_can_gain_corruption(int corruption_idx) if (corruption_idx == CORRUPT_TROLL_BLOOD) { /* Ok trolls should not get this one. never. */ - if (streq(rp_ptr->title, "Troll")) + if (rp_ptr->title == "Troll") { allowed = FALSE; } @@ -716,7 +711,7 @@ static bool_ player_can_gain_corruption(int corruption_idx) if (game_module_idx == MODULE_THEME) { - if (streq(rp_ptr->title, "Maia")) + if (rp_ptr->title == "Maia") { /* We use a whitelist of corruptions for Maiar */ bool_ allow = FALSE; @@ -764,7 +759,7 @@ static bool_ player_allow_corruption(int corruption_idx) /* Vampire teeth is special */ if (corruption_idx == CORRUPT_VAMPIRE_TEETH) { - if (race_flags1_p(PR1_NO_SUBRACE_CHANGE)) + if (race_flags_p(PR_NO_SUBRACE_CHANGE)) { return TRUE; } @@ -944,20 +939,18 @@ void lose_corruption() /* * Dump the corruption list */ -void dump_corruptions(FILE *fff, bool_ color, bool_ header) +std::string dump_corruptions(bool color, bool header) { - int i; + fmt::MemoryWriter w; - assert(fff != NULL); - - for (i = 0; i < CORRUPTIONS_MAX; i++) + for (int i = 0; i < CORRUPTIONS_MAX; i++) { - corruption_type *c_ptr = &corruptions[i]; + corruption_type const *c_ptr = &corruptions[i]; if (header) { - fprintf(fff, "\n Corruption list:\n"); - header = FALSE; + w.write("\nCorruption list:\n\n"); + header = false; } if (p_ptr->corruptions[i]) @@ -966,16 +959,18 @@ void dump_corruptions(FILE *fff, bool_ color, bool_ header) if (color) { - fprintf(fff, "#####%c%s:\n", conv_color[c], c_ptr->name); + w.write("#####{}{}:\n", static_cast<char>(conv_color[c]), c_ptr->name); } else { - fprintf(fff, "%s:\n", c_ptr->name); + w.write("{}:\n", c_ptr->name); } - fprintf(fff, "%s\n", c_ptr->desc); + w.write("{}\n\n", c_ptr->desc); } } + + return w.str(); } /* diff --git a/src/corrupt.hpp b/src/corrupt.hpp index c200762e..77a7496e 100644 --- a/src/corrupt.hpp +++ b/src/corrupt.hpp @@ -1,11 +1,13 @@ #include "h-basic.h" -extern void gain_random_corruption(); -extern void dump_corruptions(FILE *OutFile, bool_ color, bool_ header); -extern void lose_corruption(); -extern bool_ player_has_corruption(int corruption_idx); -extern void player_gain_corruption(int corruption_idx); -extern s16b get_corruption_power(int corruption_idx); +#include <string> + +void gain_random_corruption(); +std::string dump_corruptions(bool color, bool header); +void lose_corruption(); +bool_ player_has_corruption(int corruption_idx); +void player_gain_corruption(int corruption_idx); +s16b get_corruption_power(int corruption_idx); /* * Corruptions diff --git a/src/defines.h b/src/defines.h index fc1f61f5..4a2ad0e0 100644 --- a/src/defines.h +++ b/src/defines.h @@ -37,8 +37,8 @@ */ #ifndef IS_CVS -/* #define IS_CVS " (ah)" */ -#define IS_CVS " (ah, git)" +#define IS_CVS " (ah)" +/* #define IS_CVS " (ah, git)" */ #endif #define USER_PATH_VERSION "/2.4" @@ -114,26 +114,19 @@ */ #define DEFAULT_RADIUS 25 - -#define CHANCE_TRAP_JAMMED_DOOR 2500 -#define CHANCE_TRAP_SECRET_DOOR 1500 -#define CHANCE_TRAP_LOCKED_DOOR 1000 -#define CHANCE_TRAP_DOOR 500 /* in 10000 */ -#define CHANCE_TRAP_FLOOR 4 /* in 10000 chance of placing a trap */ - #define MAX_SPELLS 100 #define MAX_RUNES 100 /* - * Total number of stores (see "store.c", etc) + * Total number of monster powers */ -#define STORE_GENERAL 0 -#define STORE_HOME 7 +#define MONSTER_POWERS_MAX 96 /* - * Maximum number of player "sex" types (see "table.c", etc) + * Total number of stores (see "store.c", etc) */ -#define MAX_SEXES 3 +#define STORE_GENERAL 0 +#define STORE_HOME 7 /* Number of Random Artifacts */ #define MAX_RANDARTS 84 @@ -383,63 +376,14 @@ #define MAX_STACK_SIZE 100 -/* - * Player sex constants (hard-coded by save-files, arrays, etc) - */ -#define SEX_FEMALE 0 -#define SEX_MALE 1 -#define SEX_NEUTER 2 - - -/* Race flags */ -#define PR1_EXPERIMENTAL 0x00000001L /* Is still under developemnt */ -/* XXX */ -#define PR1_RESIST_BLACK_BREATH 0x00000004L /* Resist black breath */ -#define PR1_NO_STUN 0x00000008L /* Never stunned */ -#define PR1_XTRA_MIGHT_BOW 0x00000010L /* Xtra might with bows */ -#define PR1_XTRA_MIGHT_XBOW 0x00000020L /* Xtra might with xbows */ -#define PR1_XTRA_MIGHT_SLING 0x00000040L /* Xtra might with slings */ -#define PR1_AC_LEVEL 0x00000080L /* More AC with levels */ -#define PR1_HURT_LITE 0x00000100L /* Hurt by light */ -#define PR1_VAMPIRE 0x00000200L /* Vampire */ -#define PR1_UNDEAD 0x00000400L /* Undead */ -#define PR1_NO_CUT 0x00000800L /* no cuts */ -#define PR1_CORRUPT 0x00001000L /* hack-- corrupted */ -#define PR1_NO_FOOD 0x00002000L /* little gain from food */ -#define PR1_NO_GOD 0x00004000L /* cannot worship */ -/* XXX */ -#define PR1_ELF 0x00010000L /* Is an elf */ -#define PR1_SEMI_WRAITH 0x00020000L /* Takes damage when going in walls */ -#define PR1_NO_SUBRACE_CHANGE 0x00040000L /* Impossible to change subrace */ -/* XXX */ -#define PR1_ANTIMAGIC 0x00100000L /* antimagic ... hack */ -#define PR1_MOLD_FRIEND 0x00200000L /* Not attacked by molds wielded */ -#define PR1_GOD_FRIEND 0x00400000L /* Better grace */ -/* XXX */ -#define PR1_INNATE_SPELLS 0x01000000L /* KNown all spells, only need books */ -/* XXX */ -/* XXX */ -#define PR1_EASE_STEAL 0x08000000L /* Gain xp by stealing */ -/* XXX */ -/* XXX */ -/* XXX */ -/* XXX */ - -/* XXX */ -#define PR2_ASTRAL 0x00000002L /* Is it an astral being coming from th halls of mandos ? */ -/* XXX */ - -/* XXX */ #define MKEY_MINDCRAFT 2 #define MKEY_ANTIMAGIC 3 #define MKEY_MIMIC 6 #define MKEY_NECRO 7 #define MKEY_POWER_MAGE 8 -#define MKEY_RUNE 9 #define MKEY_FORGING 10 #define MKEY_INCARNATION 11 #define MKEY_SUMMON 13 -#define MKEY_TRAP 14 #define MKEY_STEAL 15 #define MKEY_DODGE 16 #define MKEY_SCHOOL 17 @@ -535,9 +479,6 @@ /* Feature 0x10 -- web */ -/* Traps */ -#define FEAT_TRAP 0x11 - /* Features 0x12 - 0x1F -- unused */ /* Doors */ @@ -621,7 +562,6 @@ #define FEAT_MARKER 0xAC /* 172 */ /* Feature 0xAD -- Underground Tunnel */ #define FEAT_TAINTED_WATER 0xAE /* 174 */ -#define FEAT_MON_TRAP 0xAF /* 175 */ #define FEAT_BETWEEN2 0xB0 /* 176 */ #define FEAT_LAVA_WALL 0xB1 /* 177 */ #define FEAT_GREAT_FIRE 0xB2 /* 178 */ @@ -686,208 +626,13 @@ /*** Artifact indexes (see "lib/edit/a_info.txt") ***/ - -/* Lites */ -#define ART_GALADRIEL 1 -#define ART_ELENDIL 2 -#define ART_THRAIN 3 -#define ART_PALANTIR 202 -#define ART_UNDEATH 200 -#define ART_STONE_LORE 15 -#define ART_PALANTIR_ITHIL 208 - -/* Amulets */ -#define ART_CARLAMMAS 4 -#define ART_INGWE 5 -#define ART_DWARVES 6 #define ART_ANCHOR 14 -#define ART_ELESSAR 206 -#define ART_EVENSTAR 207 - -/* Rings */ -#define ART_FLAR 7 -#define ART_BARAHIR 8 -#define ART_TULKAS 9 -#define ART_NARYA 10 -#define ART_NENYA 11 -#define ART_VILYA 12 #define ART_POWER 13 -/* 14 used by the anchor of space-time */ -/* 15 used by the stone of lore */ - -/* Dragon Scale */ -#define ART_RAZORBACK 16 -#define ART_BLADETURNER 17 -#define ART_MEDIATOR 166 - -/* Hard Armour */ -#define ART_HIMRING 167 -#define ART_SOULKEEPER 19 -#define ART_ISILDUR 20 -#define ART_ROHIRRIM 21 -#define ART_BELEGENNON 22 -#define ART_CELEBORN 23 -#define ART_ARVEDUI 24 -#define ART_CASPANION 25 - -/* Thunderlord flying suit */ -#define ART_MARDA 26 -#define ART_TRON 27 - -/* Soft Armour */ -#define ART_THALKETTOTH 28 - -/* Shields */ -#define ART_THORIN 30 -#define ART_CELEGORM 31 -#define ART_ANARION 32 -#define ART_GILGALAD 169 -#define ART_HARADRIM 176 - -/* Helms and Crowns */ #define ART_MORGOTH 34 -#define ART_BERUTHIEL 35 -#define ART_THRANDUIL 36 -#define ART_THENGEL 37 -#define ART_HAMMERHAND 38 -#define ART_DOR 39 -#define ART_HOLHENNETH 40 -#define ART_GORLIM 41 -#define ART_GONDOR 42 -#define ART_KNOWLEDGE 160 -#define ART_NUMENOR 43 -#define ART_CELEBRIMBOR 170 - -/* Cloaks */ -#define ART_COLLUIN 44 -#define ART_HOLCOLLETH 45 -#define ART_THINGOL 46 -#define ART_THORONGIL 47 -#define ART_COLANNON 48 -#define ART_LUTHIEN 49 -#define ART_TUOR 50 - -/* Gloves */ -#define ART_CAMBELEG 52 -#define ART_CAMMITHRIM 53 -#define ART_PAURHACH 54 -#define ART_PAURNIMMEN 55 -#define ART_PAURAEGEN 56 -#define ART_PAURNEN 57 -#define ART_CAMLOST 58 -#define ART_FINGOLFIN 59 -#define ART_EOL 178 - -/* Boots */ -#define ART_FEANOR 60 -#define ART_DAL 61 -#define ART_THROR 62 - |