From cbef37bd5bfb938a2303ee3887520c08be85d8e8 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 26 Mar 2013 17:10:10 +0100 Subject: Switch almost everything over to C++ --- src/init1.cc | 11816 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 11816 insertions(+) create mode 100644 src/init1.cc (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc new file mode 100644 index 00000000..076ca70e --- /dev/null +++ b/src/init1.cc @@ -0,0 +1,11816 @@ +/* File: init1.c */ + +/* Purpose: Initialization (part 1) -BEN- */ + +#include "angband.h" + + +/* + * This file is used to initialize various variables and arrays for the + * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass + * the common limitation of "read()" and "write()" to only 32767 bytes + * at a time. + * + * Several of the arrays for Angband are built from "template" files in + * the "lib/file" directory, from which quick-load binary "image" files + * are constructed whenever they are not present in the "lib/data" + * directory, or if those files become obsolete, if we are allowed. + * + * Warning -- the "ascii" file parsers use a minor hack to collect the + * name and text information in a single pass. Thus, the game will not + * be able to load any template file with more than 20K of names or 60K + * of text, even though technically, up to 64K should be legal. + */ + + +/*** Helper arrays for parsing ascii template files ***/ + +/* + * Monster Blow Methods + */ +static cptr r_info_blow_method[] = +{ + "*", + "HIT", + "TOUCH", + "PUNCH", + "KICK", + "CLAW", + "BITE", + "STING", + "XXX1", + "BUTT", + "CRUSH", + "ENGULF", + "CHARGE", + "CRAWL", + "DROOL", + "SPIT", + "EXPLODE", + "GAZE", + "WAIL", + "SPORE", + "XXX4", + "BEG", + "INSULT", + "MOAN", + "SHOW", + NULL +}; + + +/* + * Monster Blow Effects + */ +static cptr r_info_blow_effect[] = +{ + "*", + "HURT", + "POISON", + "UN_BONUS", + "UN_POWER", + "EAT_GOLD", + "EAT_ITEM", + "EAT_FOOD", + "EAT_LITE", + "ACID", + "ELEC", + "FIRE", + "COLD", + "BLIND", + "CONFUSE", + "TERRIFY", + "PARALYZE", + "LOSE_STR", + "LOSE_INT", + "LOSE_WIS", + "LOSE_DEX", + "LOSE_CON", + "LOSE_CHR", + "LOSE_ALL", + "SHATTER", + "EXP_10", + "EXP_20", + "EXP_40", + "EXP_80", + "DISEASE", + "TIME", + "INSANITY", + "HALLU", + "PARASITE", + "ABOMINATION", + NULL +}; + + +/* + * Monster race flags + */ +static cptr r_info_flags1[] = +{ + "UNIQUE", + "QUESTOR", + "MALE", + "FEMALE", + "CHAR_CLEAR", + "CHAR_MULTI", + "ATTR_CLEAR", + "ATTR_MULTI", + "FORCE_DEPTH", + "FORCE_MAXHP", + "FORCE_SLEEP", + "FORCE_EXTRA", + "FRIEND", + "FRIENDS", + "ESCORT", + "ESCORTS", + "NEVER_BLOW", + "NEVER_MOVE", + "RAND_25", + "RAND_50", + "ONLY_GOLD", + "ONLY_ITEM", + "DROP_60", + "DROP_90", + "DROP_1D2", + "DROP_2D2", + "DROP_3D2", + "DROP_4D2", + "DROP_GOOD", + "DROP_GREAT", + "DROP_USEFUL", + "DROP_CHOSEN" +}; + +/* + * Monster race flags + */ +static cptr r_info_flags2[] = +{ + "STUPID", + "SMART", + "CAN_SPEAK", + "REFLECTING", + "INVISIBLE", + "COLD_BLOOD", + "EMPTY_MIND", + "WEIRD_MIND", + "DEATH_ORB", + "REGENERATE", + "SHAPECHANGER", + "ATTR_ANY", + "POWERFUL", + "ELDRITCH_HORROR", + "AURA_FIRE", + "AURA_ELEC", + "OPEN_DOOR", + "BASH_DOOR", + "PASS_WALL", + "KILL_WALL", + "MOVE_BODY", + "KILL_BODY", + "TAKE_ITEM", + "KILL_ITEM", + "BRAIN_1", + "BRAIN_2", + "BRAIN_3", + "BRAIN_4", + "BRAIN_5", + "BRAIN_6", + "BRAIN_7", + "BRAIN_8" +}; + +/* + * Monster race flags + */ +static cptr r_info_flags3[] = +{ + "ORC", + "TROLL", + "GIANT", + "DRAGON", + "DEMON", + "UNDEAD", + "EVIL", + "ANIMAL", + "THUNDERLORD", + "GOOD", + "AURA_COLD", /* TODO: Implement aura_cold */ + "NONLIVING", + "HURT_LITE", + "HURT_ROCK", + "SUSCEP_FIRE", + "SUSCEP_COLD", + "IM_ACID", + "IM_ELEC", + "IM_FIRE", + "IM_COLD", + "IM_POIS", + "RES_TELE", + "RES_NETH", + "RES_WATE", + "RES_PLAS", + "RES_NEXU", + "RES_DISE", + "UNIQUE_4", + "NO_FEAR", + "NO_STUN", + "NO_CONF", + "NO_SLEEP" +}; + +/* + * Monster race flags + */ +static cptr r_info_flags4[] = +{ + "SHRIEK", + "MULTIPLY", + "S_ANIMAL", + "ROCKET", + "ARROW_1", + "ARROW_2", + "ARROW_3", + "ARROW_4", + "BR_ACID", + "BR_ELEC", + "BR_FIRE", + "BR_COLD", + "BR_POIS", + "BR_NETH", + "BR_LITE", + "BR_DARK", + "BR_CONF", + "BR_SOUN", + "BR_CHAO", + "BR_DISE", + "BR_NEXU", + "BR_TIME", + "BR_INER", + "BR_GRAV", + "BR_SHAR", + "BR_PLAS", + "BR_WALL", + "BR_MANA", + "BA_NUKE", + "BR_NUKE", + "BA_CHAO", + "BR_DISI", +}; + +/* + * Monster race flags + */ +static cptr r_info_flags5[] = +{ + "BA_ACID", + "BA_ELEC", + "BA_FIRE", + "BA_COLD", + "BA_POIS", + "BA_NETH", + "BA_WATE", + "BA_MANA", + "BA_DARK", + "DRAIN_MANA", + "MIND_BLAST", + "BRAIN_SMASH", + "CAUSE_1", + "CAUSE_2", + "CAUSE_3", + "CAUSE_4", + "BO_ACID", + "BO_ELEC", + "BO_FIRE", + "BO_COLD", + "BO_POIS", + "BO_NETH", + "BO_WATE", + "BO_MANA", + "BO_PLAS", + "BO_ICEE", + "MISSILE", + "SCARE", + "BLIND", + "CONF", + "SLOW", + "HOLD" +}; + +/* + * Monster race flags + */ +static cptr r_info_flags6[] = +{ + "HASTE", + "HAND_DOOM", + "HEAL", + "S_ANIMALS", + "BLINK", + "TPORT", + "TELE_TO", + "TELE_AWAY", + "TELE_LEVEL", + "DARKNESS", + "TRAPS", + "FORGET", + "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */ + "S_BUG", + "S_RNG", + "S_THUNDERLORD", /* DG : Summon Thunderlord */ + "S_KIN", + "S_HI_DEMON", + "S_MONSTER", + "S_MONSTERS", + "S_ANT", + "S_SPIDER", + "S_HOUND", + "S_HYDRA", + "S_ANGEL", + "S_DEMON", + "S_UNDEAD", + "S_DRAGON", + "S_HI_UNDEAD", + "S_HI_DRAGON", + "S_WRAITH", + "S_UNIQUE" +}; + + +/* + * Monster race flags + */ +static cptr r_info_flags7[] = +{ + "AQUATIC", + "CAN_SWIM", + "CAN_FLY", + "FRIENDLY", + "PET", + "MORTAL", + "SPIDER", + "NAZGUL", + "DG_CURSE", + "POSSESSOR", + "NO_DEATH", + "NO_TARGET", + "AI_ANNOY", + "AI_SPECIAL", + "NEUTRAL", + "DROP_ART", + "DROP_RANDART", + "AI_PLAYER", + "NO_THEFT", + "SPIRIT", + "IM_MELEE", + "XXX7X21", + "XXX7X22", + "XXX7X23", + "XXX7X24", + "XXX7X25", + "XXX7X26", + "XXX7X27", + "XXX7X28", + "XXX7X29", + "XXX7X30", + "XXX7X31", +}; + +/* + * Monster race flags + */ +static cptr r_info_flags8[] = +{ + "WILD_ONLY", + "WILD_TOWN", + "XXX8X02", + "WILD_SHORE", + "WILD_OCEAN", + "WILD_WASTE", + "WILD_WOOD", + "WILD_VOLCANO", + "XXX8X08", + "WILD_MOUNTAIN", + "WILD_GRASS", + "NO_CUT", + "CTHANGBAND", + "XXX8X13", + "ZANGBAND", + "JOKEANGBAND", + "BASEANGBAND", + "XXX8X17", + "XXX8X18", + "XXX8X19", + "XXX8X20", + "XXX8X21", + "XXX8X22", + "XXX8X23", + "XXX8X24", + "XXX8X25", + "XXX8X26", + "XXX8X27", + "XXX8X28", + "XXX8X29", + "WILD_SWAMP", /* ToDo: Implement Swamp */ + "WILD_TOO", +}; + + +/* + * Monster race flags - Drops + */ +static cptr r_info_flags9[] = +{ + "DROP_CORPSE", + "DROP_SKELETON", + "HAS_LITE", + "MIMIC", + "HAS_EGG", + "IMPRESED", + "SUSCEP_ACID", + "SUSCEP_ELEC", + "SUSCEP_POIS", + "KILL_TREES", + "WYRM_PROTECT", + "DOPPLEGANGER", + "ONLY_DEPTH", + "SPECIAL_GENE", + "NEVER_GENE", + "XXX9X15", + "XXX9X16", + "XXX9X17", + "XXX9X18", + "XXX9X19", + "XXX9X20", + "XXX9X21", + "XXX9X22", + "XXX9X23", + "XXX9X24", + "XXX9X25", + "XXX9X26", + "XXX9X27", + "XXX9X28", + "XXX9X29", + "XXX9X30", + "XXX9X31", +}; + + +/* + * Object flags + */ +cptr k_info_flags1[] = +{ + "STR", + "INT", + "WIS", + "DEX", + "CON", + "CHR", + "MANA", + "SPELL", + "STEALTH", + "SEARCH", + "INFRA", + "TUNNEL", + "SPEED", + "BLOWS", + "CHAOTIC", + "VAMPIRIC", + "SLAY_ANIMAL", + "SLAY_EVIL", + "SLAY_UNDEAD", + "SLAY_DEMON", + "SLAY_ORC", + "SLAY_TROLL", + "SLAY_GIANT", + "SLAY_DRAGON", + "KILL_DRAGON", + "VORPAL", + "IMPACT", + "BRAND_POIS", + "BRAND_ACID", + "BRAND_ELEC", + "BRAND_FIRE", + "BRAND_COLD" +}; + +/* + * Object flags + */ +cptr k_info_flags2[] = +{ + "SUST_STR", + "SUST_INT", + "SUST_WIS", + "SUST_DEX", + "SUST_CON", + "SUST_CHR", + "INVIS", + "LIFE", + "IM_ACID", + "IM_ELEC", + "IM_FIRE", + "IM_COLD", + "SENS_FIRE", + "REFLECT", + "FREE_ACT", + "HOLD_LIFE", + "RES_ACID", + "RES_ELEC", + "RES_FIRE", + "RES_COLD", + "RES_POIS", + "RES_FEAR", + "RES_LITE", + "RES_DARK", + "RES_BLIND", + "RES_CONF", + "RES_SOUND", + "RES_SHARDS", + "RES_NETHER", + "RES_NEXUS", + "RES_CHAOS", + "RES_DISEN" +}; + +/* + * Trap flags + */ +cptr k_info_flags2_trap[] = +{ + "AUTOMATIC_5", + "AUTOMATIC_99", + "KILL_GHOST", + "TELEPORT_TO", + "ONLY_DRAGON", + "ONLY_DEMON", + "XXX3", + "XXX3", + "ONLY_ANIMAL", + "ONLY_UNDEAD", + "ONLY_EVIL", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", + "XXX3", +}; + + +/* + * Object flags + */ +cptr k_info_flags3[] = +{ + "SH_FIRE", + "SH_ELEC", + "AUTO_CURSE", + "DECAY", + "NO_TELE", + "NO_MAGIC", + "WRAITH", + "TY_CURSE", + "EASY_KNOW", + "HIDE_TYPE", + "SHOW_MODS", + "INSTA_ART", + "FEATHER", + "LITE1", + "SEE_INVIS", + "NORM_ART", + "SLOW_DIGEST", + "REGEN", + "XTRA_MIGHT", + "XTRA_SHOTS", + "IGNORE_ACID", + "IGNORE_ELEC", + "IGNORE_FIRE", + "IGNORE_COLD", + "ACTIVATE", + "DRAIN_EXP", + "TELEPORT", + "AGGRAVATE", + "BLESSED", + "CURSED", + "HEAVY_CURSE", + "PERMA_CURSE" +}; + +/* + * Object flags + */ +cptr k_info_flags4[] = +{ + "NEVER_BLOW", + "PRECOGNITION", + "BLACK_BREATH", + "RECHARGE", + "FLY", + "DG_CURSE", + "COULD2H", + "MUST2H", + "LEVELS", + "CLONE", + "SPECIAL_GENE", + "CLIMB", + "FAST_CAST", + "CAPACITY", + "CHARGING", + "CHEAPNESS", + "FOUNTAIN", + "ANTIMAGIC_50", + "ANTIMAGIC_30", + "ANTIMAGIC_20", + "ANTIMAGIC_10", + "EASY_USE", + "IM_NETHER", + "RECHARGED", + "ULTIMATE", + "AUTO_ID", + "LITE2", + "LITE3", + "FUEL_LITE", + "ART_EXP", + "CURSE_NO_DROP", + "NO_RECHARGE" +}; + +/* + * Object flags + */ +cptr k_info_flags5[] = +{ + "TEMPORARY", + "DRAIN_MANA", + "DRAIN_HP", + "KILL_DEMON", + "KILL_UNDEAD", + "CRIT", + "ATTR_MULTI", + "WOUNDING", + "FULL_NAME", + "LUCK", + "IMMOVABLE", + "SPELL_CONTAIN", + "RES_MORGUL", + "ACTIVATE_NO_WIELD", + "MAGIC_BREATH", + "WATER_BREATH", + "WIELD_CAST", + "XXX8X17", + "XXX8X18", + "XXX8X19", + "XXX8X20", + "XXX8X21", + "XXX8X22", + "XXX8X23", + "XXX8X24", + "XXX8X25", + "XXX8X26", + "XXX8X27", + "XXX8X28", + "XXX8X29", + "XXX8X02", + "XXX8X22", +}; + +/* + * ESP flags + */ +cptr esp_flags[] = +{ + "ESP_ORC", + "ESP_TROLL", + "ESP_DRAGON", + "ESP_GIANT", + "ESP_DEMON", + "ESP_UNDEAD", + "ESP_EVIL", + "ESP_ANIMAL", + "ESP_THUNDERLORD", + "ESP_GOOD", + "ESP_NONLIVING", + "ESP_UNIQUE", + "ESP_SPIDER", + "XXX8X02", + "XXX8X02", + "XXX8X02", + "XXX8X02", + "XXX8X17", + "XXX8X18", + "XXX8X19", + "XXX8X20", + "XXX8X21", + "XXX8X22", + "XXX8X23", + "XXX8X24", + "XXX8X25", + "XXX8X26", + "XXX8X27", + "XXX8X28", + "XXX8X29", + "XXX8X02", + "ESP_ALL", +}; + +/* Specially handled properties for ego-items */ + +static cptr ego_flags[] = +{ + "SUSTAIN", + "OLD_RESIST", + "ABILITY", + "R_ELEM", + "R_LOW", + "R_HIGH", + "R_ANY", + "R_DRAGON", + "SLAY_WEAP", + "DAM_DIE", + "DAM_SIZE", + "PVAL_M1", + "PVAL_M2", + "PVAL_M3", + "PVAL_M5", + "AC_M1", + "AC_M2", + "AC_M3", + "AC_M5", + "TH_M1", + "TH_M2", + "TH_M3", + "TH_M5", + "TD_M1", + "TD_M2", + "TD_M3", + "TD_M5", + "R_P_ABILITY", + "R_STAT", + "R_STAT_SUST", + "R_IMMUNITY", + "LIMIT_BLOWS" +}; + +/* + * Feature flags + */ +static cptr f_info_flags1[] = +{ + "NO_WALK", + "NO_VISION", + "CAN_LEVITATE", + "CAN_PASS", + "FLOOR", + "WALL", + "PERMANENT", + "CAN_FLY", + "REMEMBER", + "NOTICE", + "DONT_NOTICE_RUNNING", + "CAN_RUN", + "DOOR", + "SUPPORT_LIGHT", + "CAN_CLIMB", + "TUNNELABLE", + "WEB", + "ATTR_MULTI", + "SUPPORT_GROWTH", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1" +}; + +/* + * Dungeon flags + */ +static cptr d_info_flags1[] = +{ + "PRINCIPAL", + "MAZE", + "SMALLEST", + "SMALL", + "BIG", + "NO_DOORS", + "WATER_RIVER", + "LAVA_RIVER", + "WATER_RIVERS", + "LAVA_RIVERS", + "CAVE", + "CAVERN", + "NO_UP", + "HOT", + "COLD", + "FORCE_DOWN", + "FORGET", + "NO_DESTROY", + "SAND_VEIN", + "CIRCULAR_ROOMS", + "EMPTY", + "DAMAGE_FEAT", + "FLAT", + "TOWER", + "RANDOM_TOWNS", + "DOUBLE", + "LIFE_LEVEL", + "EVOLVE", + "ADJUST_LEVEL_1", + "ADJUST_LEVEL_2", + "NO_RECALL", + "NO_STREAMERS" +}; + +static cptr d_info_flags2[] = +{ + "ADJUST_LEVEL_1_2", + "NO_SHAFT", + "ADJUST_LEVEL_PLAYER", + "NO_TELEPORT", + "ASK_LEAVE", + "NO_STAIR", + "SPECIAL", + "NO_NEW_MONSTER", + "DESC", + "NO_GENO", + "NO_BREATH", + "WATER_BREATH", + "ELVEN", + "DWARVEN", + "NO_EASY_MOVE", + "NO_RECALL_OUT", + "DESC_ALWAYS", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1" +}; + +/* + * Trap flags + */ +static cptr t_info_flags[] = +{ + "CHEST", + "DOOR", + "FLOOR", + "XXX4", + "XXX5", + "XXX6", + "XXX7", + "XXX8", + "XXX9", + "XXX10", + "XXX11", + "XXX12", + "XXX13", + "XXX14", + "XXX15", + "XXX16", + "LEVEL1", + "LEVEL2", + "LEVEL3", + "LEVEL4", + "XXX21", + "XXX22", + "XXX23", + "XXX24", + "XXX25", + "XXX26", + "XXX27", + "XXX28", + "XXX29", + "XXX30", + "XXX31", + "XXX32" +}; + +/* + * Wilderness feature flags + */ +static cptr wf_info_flags1[] = +{ + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1" +}; + +/* + * Stores flags + */ +static cptr st_info_flags1[] = +{ + "DEPEND_LEVEL", + "SHALLOW_LEVEL", + "MEDIUM_LEVEL", + "DEEP_LEVEL", + "RARE", + "VERY_RARE", + "COMMON", + "ALL_ITEM", + "RANDOM", + "FORCE_LEVEL", + "MUSEUM", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1" +}; + +/* + * Race flags + */ +cptr rp_info_flags1[] = +{ + "EXPERIMENTAL", + "XXX", + "RESIST_BLACK_BREATH", + "NO_STUN", + "XTRA_MIGHT_BOW", + "XTRA_MIGHT_XBOW", + "XTRA_MIGHT_SLING", + "AC_LEVEL", + "HURT_LITE", + "VAMPIRE", + "UNDEAD", + "NO_CUT", + "CORRUPT", + "NO_FOOD", + "NO_GOD", + "XXX", + "ELF", + "SEMI_WRAITH", + "NO_SUBRACE_CHANGE", + "XXX", + "XXX", + "MOLD_FRIEND", + "GOD_FRIEND", + "XXX", + "INNATE_SPELLS", + "XXX", + "XXX", + "EASE_STEAL", + "XXX", + "XXX", + "XXX", + "XXX" +}; + +/* + * Race flags + */ +cptr rp_info_flags2[] = +{ + "XXX", + "ASTRAL", + "XXX", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1" +}; + +/* Skill flags */ +static cptr s_info_flags1[] = +{ + "HIDDEN", + "AUTO_HIDE", + "RANDOM_GAIN", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1", + "XXX1" +}; + +/* + * Dungeon effect types (used in E:damage:frequency:type entry in d_info.txt) + */ +static struct +{ +cptr name; +int feat; +} +d_info_dtypes[] = +{ + {"ELEC", GF_ELEC}, + {"POISON", GF_POIS}, + {"ACID", GF_ACID}, + {"COLD", GF_COLD}, + {"FIRE", GF_FIRE}, + {"MISSILE", GF_MISSILE}, + {"ARROW", GF_ARROW}, + {"PLASMA", GF_PLASMA}, + {"WATER", GF_WATER}, + {"LITE", GF_LITE}, + {"DARK", GF_DARK}, + {"LITE_WEAK", GF_LITE_WEAK}, + {"LITE_DARK", GF_DARK_WEAK}, + {"SHARDS", GF_SHARDS}, + {"SOUND", GF_SOUND}, + {"CONFUSION", GF_CONFUSION}, + {"FORCE", GF_FORCE}, + {"INERTIA", GF_INERTIA}, + {"MANA", GF_MANA}, + {"METEOR", GF_METEOR}, + {"ICE", GF_ICE}, + {"CHAOS", GF_CHAOS}, + {"NETHER", GF_NETHER}, + {"DISENCHANT", GF_DISENCHANT}, + {"NEXUS", GF_NEXUS}, + {"TIME", GF_TIME}, + {"GRAVITY", GF_GRAVITY}, + {"ROCKET", GF_ROCKET}, + {"NUKE", GF_NUKE}, + {"HOLY_FIRE", GF_HOLY_FIRE}, + {"HELL_FIRE", GF_HELL_FIRE}, + {"DISINTEGRATE", GF_DISINTEGRATE}, + {"DESTRUCTION", GF_DESTRUCTION}, + {"RAISE", GF_RAISE}, + {NULL, 0} +}; + +/* Essence names for al_info.txt */ +static const char *essence_names[] = +{ + "No name here", /* can't be matched, sscanf stops at spaces */ + "POISON", + "EXPLOSION", + "TELEPORT", + "COLD", + "FIRE", + "ACID", + "LIFE", + "CONFUSION", + "LITE", + "CHAOS", + "TIME", + "MAGIC", + "EXTRALIFE", + "DARKNESS", + "KNOWLEDGE", + "FORCE", + "LIGHTNING", + "MANA", + "" +}; +static const char *activation_names[] = +{ + "NO_ACTIVATION", /* 0*/ + "SUNLIGHT", /* 1*/ + "BO_MISS_1", /* 2*/ + "BA_POIS_1", /* 3*/ + "BO_ELEC_1", /* 4*/ + "BO_ACID_1", /* 5*/ + "BO_COLD_1", /* 6*/ + "BO_FIRE_1", /* 7*/ + "BA_COLD_1", /* 8*/ + "BA_FIRE_1", /* 9*/ + "DRAIN_1", /* 10*/ + "BA_COLD_2", /* 11*/ + "BA_ELEC_2", /* 12*/ + "DRAIN_2", /* 13*/ + "VAMPIRE_1", /* 14*/ + "BO_MISS_2", /* 15*/ + "BA_FIRE_2", /* 16*/ + "BA_COLD_3", /* 17*/ + "BA_ELEC_3", /* 18*/ + "WHIRLWIND", /* 19*/ + "VAMPIRE_2", /* 20*/ + "CALL_CHAOS", /* 21*/ + "ROCKET", /* 22*/ + "DISP_EVIL", /* 23*/ + "BA_MISS_3", /* 24*/ + "DISP_GOOD", /* 25*/ + "GILGALAD", /* 26*/ + "CELEBRIMBOR", /* 27*/ + "SKULLCLEAVER", /* 28*/ + "HARADRIM", /* 29*/ + "FUNDIN", /* 30*/ + "EOL", /* 31*/ + "UMBAR", /* 32*/ + "NUMENOR", /* 33*/ + "KNOWLEDGE", /* 34*/ + "UNDEATH", /* 35*/ + "THRAIN", /* 36*/ + "BARAHIR", /* 37*/ + "TULKAS", /* 38*/ + "NARYA", /* 39*/ + "NENYA", /* 40*/ + "VILYA", /* 41*/ + "POWER", /* 42*/ + "STONE_LORE", /* 43*/ + "RAZORBACK", /* 44*/ + "BLADETURNER", /* 45*/ + "MEDIATOR", /* 46*/ + "BELEGENNON", /* 47*/ + "GORLIM", /* 48*/ + "COLLUIN", /* 49*/ + "BELANGIL", /* 50*/ + "CONFUSE", /* 51*/ + "SLEEP", /* 52*/ + "QUAKE", /* 53*/ + "TERROR", /* 54*/ + "TELE_AWAY", /* 55*/ + "BANISH_EVIL", /* 56*/ + "GENOCIDE", /* 57*/ + "MASS_GENO", /* 58*/ + "ANGUIREL", /* 59*/ + "ERU", /* 60*/ + "DAWN", /* 61*/ + "FIRESTAR", /* 62*/ + "TURMIL", /* 63*/ + "CUBRAGOL", /* 64*/ + "CHARM_ANIMAL", /* 65*/ + "CHARM_UNDEAD", /* 66*/ + "CHARM_OTHER", /* 67*/ + "CHARM_ANIMALS", /* 68*/ + "CHARM_OTHERS", /* 69*/ + "SUMMON_ANIMAL", /* 70*/ + "SUMMON_PHANTOM", /* 71*/ + "SUMMON_ELEMENTAL", /* 72*/ + "SUMMON_DEMON", /* 73*/ + "SUMMON_UNDEAD", /* 74*/ + "ELESSAR", /* 75*/ + "GANDALF", /* 76*/ + "MARDA", /* 77*/ + "PALANTIR", /* 78*/ + "XXX79", + "XXX80", + "CURE_LW", /* 81*/ + "CURE_MW", /* 82*/ + "CURE_POISON", /* 83*/ + "REST_LIFE", /* 84*/ + "REST_ALL", /* 85*/ + "CURE_700", /* 86*/ + "CURE_1000", /* 87*/ + "XXX88", + "EREBOR", /* 89*/ + "DRUEDAIN", /* 90*/ + "ESP", /* 91*/ + "BERSERK", /* 92*/ + "PROT_EVIL", /* 93*/ + "RESIST_ALL", /* 94*/ + "SPEED", /* 95*/ + "XTRA_SPEED", /* 96*/ + "WRAITH", /* 97*/ + "INVULN", /* 98*/ + "ROHAN", /* 99*/ + "HELM", /* 100*/ + "BOROMIR", /* 101*/ + "HURIN", /* 102*/ + "AXE_GOTHMOG", /* 103*/ + "MELKOR", /* 104*/ + "GROND", /* 105*/ + "NATUREBANE", /* 106*/ + "NIGHT", /* 107*/ + "ORCHAST", /* 108*/ + "XXX109", + "XXX110", + "LIGHT", /* 111*/ + "MAP_LIGHT", /* 112*/ + "DETECT_ALL", /* 113*/ + "DETECT_XTRA", /* 114*/ + "ID_FULL", /* 115*/ + "ID_PLAIN", /* 116*/ + "RUNE_EXPLO", /* 117*/ + "RUNE_PROT", /* 118*/ + "SATIATE", /* 119*/ + "DEST_DOOR", /* 120*/ + "STONE_MUD", /* 121*/ + "RECHARGE", /* 122*/ + "ALCHEMY", /* 123*/ + "DIM_DOOR", /* 124*/ + "TELEPORT", /* 125*/ + "RECALL", /* 126*/ + "DEATH", /* 127*/ + "RUINATION", /* 128*/ + "DESTRUC", /* 129*/ + "UNINT", /* 130*/ + "UNSTR", /* 131*/ + "UNCON", /* 132*/ + "UNCHR", /* 133*/ + "UNDEX", /* 134*/ + "UNWIS", /* 135*/ + "STATLOSS", /* 136*/ + "HISTATLOSS", /* 137*/ + "EXPLOSS", /* 138*/ + "HIEXPLOSS", /* 139*/ + "SUMMON_MONST", /* 140*/ + "PARALYZE", /* 141*/ + "HALLU", /* 142*/ + "POISON", /* 143*/ + "HUNGER", /* 144*/ + "STUN", /* 145*/ + "CUTS", /* 146*/ + "PARANO", /* 147*/ + "CONFUSION", /* 148*/ + "BLIND", /* 149*/ + "PET_SUMMON", /* 150*/ + "CURE_PARA", /* 151*/ + "CURE_HALLU", /* 152*/ + "CURE_POIS", /* 153*/ + "CURE_HUNGER", /* 154*/ + "CURE_STUN", /* 155*/ + "CURE_CUTS", /* 156*/ + "CURE_FEAR", /* 157*/ + "CURE_CONF", /* 158*/ + "CURE_BLIND", /* 159*/ + "CURING", /* 160*/ + "DARKNESS", /* 161*/ + "LEV_TELE", /* 162*/ + "ACQUIREMENT", /* 163*/ + "WEIRD", /* 164*/ + "AGGRAVATE", /* 165*/ + "MUT", /* 166*/ + "CURE_INSANITY", /* 167*/ + "CURE_MUT", /* 168*/ + "LIGHT_ABSORBTION", /* 169*/ + "BA_FIRE_H", /* 170*/ + "BA_COLD_H", /* 171*/ + "BA_ELEC_H", /* 172*/ + "BA_ACID_H", /* 173*/ + "SPIN", /* 174*/ + "NOLDOR", /* 175*/ + "SPECTRAL", /* 176*/ + "JUMP", /* 177*/ + "DEST_TELE", /* 178*/ + "BA_POIS_4", /* 179*/ + "BA_COLD_4", /* 180*/ + "BA_FIRE_4", /* 181*/ + "BA_ACID_4", /* 182*/ + "BA_ELEC_4", /* 183*/ + "BR_ELEC", /* 184*/ + "BR_COLD", /* 185*/ + "BR_FIRE", /* 186*/ + "BR_ACID", /* 187*/ + "BR_POIS", /* 188*/ + "BR_MANY", /* 189*/ + "BR_CONF", /* 190*/ + "BR_SOUND", /* 191*/ + "BR_CHAOS", /* 192*/ + "BR_SHARD", /* 193*/ + "BR_BALANCE", /* 194*/ + "BR_LIGHT", /* 195*/ + "BR_POWER", /* 196*/ + "GROW_MOLD", /* 197*/ + "XXX198", + "XXX199", + "MUSIC", /* 200*/ + "" +}; + +/* + * Convert a "color letter" into an "actual" color + * The colors are: dwsorgbuDWvyRGBU, as shown below + */ +int color_char_to_attr(char c) +{ + switch (c) + { + case 'd': + return (TERM_DARK); + case 'w': + return (TERM_WHITE); + case 's': + return (TERM_SLATE); + case 'o': + return (TERM_ORANGE); + case 'r': + return (TERM_RED); + case 'g': + return (TERM_GREEN); + case 'b': + return (TERM_BLUE); + case 'u': + return (TERM_UMBER); + + case 'D': + return (TERM_L_DARK); + case 'W': + return (TERM_L_WHITE); + case 'v': + return (TERM_VIOLET); + case 'y': + return (TERM_YELLOW); + case 'R': + return (TERM_L_RED); + case 'G': + return (TERM_L_GREEN); + case 'B': + return (TERM_L_BLUE); + case 'U': + return (TERM_L_UMBER); + } + + return ( -1); +} + +/* + * Attr value-to-char convertion table + */ +byte conv_color[16] = +{ + 'd', + 'w', + 's', + 'o', + 'r', + 'g', + 'b', + 'u', + 'D', + 'W', + 'v', + 'y', + 'R', + 'G', + 'B', + 'U', +}; + + +/* Values in re_info can be fixed, added, substracted or percented */ +static byte monster_ego_modify(char c) +{ + switch (c) + { + case '+': + return MEGO_ADD; + case '-': + return MEGO_SUB; + case '=': + return MEGO_FIX; + case '%': + return MEGO_PRC; + default: + { + msg_format("Unknown mego value modifier %c.", c); + return MEGO_ADD; + } + } +} + +/* + * Implements fp stacks, for included files + */ +static FILE *fp_stack[10]; +static int fp_stack_idx = 0; + +/* + * Must be caleld before the main loop + */ +static void fp_stack_init(FILE *fp) +{ + fp_stack[0] = fp; + fp_stack_idx = 0; +} + +static void fp_stack_push(cptr name) +{ + if (fp_stack_idx < 9) + { + char buf[1024]; + FILE *fp; + + /* Build the filename */ + path_build(buf, 1024, ANGBAND_DIR_EDIT, name); + + /* Open the file */ + fp = my_fopen(buf, "r"); + + /* Parse it */ + if (!fp) quit(format("Cannot open '%s' file.", name)); + + printf("ibncluding %s\n", name); + + fp_stack[++fp_stack_idx] = fp; + } +} + +static bool_ fp_stack_pop() +{ + if (fp_stack_idx > 0) + { + FILE *fp = fp_stack[fp_stack_idx--]; + my_fclose(fp); + return TRUE; + } + else + return FALSE; +} + +/* + * Must be used instead of my_fgets for teh main loop + */ +static int my_fgets_dostack(char *buf, int len) +{ + // End of a file + if (0 != my_fgets(fp_stack[fp_stack_idx], buf, len)) + { + // If any left, use them + if (fp_stack_pop()) + return my_fgets_dostack(buf, len); + // If not, this is the end + else + return 1; + } + else + { + return 0; + } +} + + +/*** Initialize from ascii template files ***/ + +/* + * Grab one race flag from a textual string + */ +static bool_ unknown_shut_up = FALSE; +static errr grab_one_class_flag(u32b *choice, cptr what) +{ + int i; + cptr s; + + /* Scan classes flags */ + for (i = 0; i < max_c_idx && (s = class_info[i].title + c_name); i++) + { + if (streq(what, s)) + { + (choice[i / 32]) |= (1L << i); + return (0); + } + } + + /* Oops */ + if (!unknown_shut_up) msg_format("Unknown class flag '%s'.", what); + + /* Failure */ + return (1); +} +static errr grab_one_race_allow_flag(u32b *choice, cptr what) +{ + int i; + cptr s; + + /* Scan classes flags */ + for (i = 0; i < max_rp_idx && (s = race_info[i].title + rp_name); i++) + { + if (streq(what, s)) + { + (choice[i / 32]) |= (1L << i); + return (0); + } + } + + /* Oops */ + if (!unknown_shut_up) msg_format("(1)Unknown race flag '%s'.", what); + + /* Failure */ + return (1); +} + +/* + * Grab one flag from a textual string + */ +static errr grab_one_skill_flag(u32b *f1, cptr what) +{ + int i; + + /* Check flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, s_info_flags1[i])) + { + (*f1) |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("(2)Unknown skill flag '%s'.", what); + + /* Error */ + return (1); +} +/* + * Grab one flag from a textual string + */ +static errr grab_one_player_race_flag(u32b *f1, u32b *f2, cptr what) +{ + int i; + + /* Check flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, rp_info_flags1[i])) + { + (*f1) |= (1L << i); + return (0); + } + } + + /* Check flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, rp_info_flags2[i])) + { + (*f2) |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("(2)Unknown race flag '%s'.", what); + + /* Error */ + return (1); +} + +/* Get an activation number (good for artifacts, recipes, egos, and object kinds) */ +int get_activation(char *activation) +{ + int i; + for ( i = 0 ; activation_names[i][0] ; i++) + if (!strncmp(activation_names[i], activation, 19)) + { + return i; + } + return -1; +} + +/* + * Grab one flag in an object_kind from a textual string + */ +static errr grab_one_race_kind_flag(u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp, cptr what) +{ + int i; + + /* Check flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags1[i])) + { + (*f1) |= (1L << i); + return (0); + } + } + + /* Check flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2[i])) + { + (*f2) |= (1L << i); + return (0); + } + } + + /* Check flags2 -- traps*/ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2_trap[i])) + { + (*f3) |= (1L << i); + return (0); + } + } + + /* Check flags3 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags3[i])) + { + (*f3) |= (1L << i); + return (0); + } + } + + /* Check flags4 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags4[i])) + { + (*f4) |= (1L << i); + return (0); + } + } + + /* Check flags5 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags5[i])) + { + (*f5) |= (1L << i); + return (0); + } + } + + /* Check esp_flags */ + for (i = 0; i < 32; i++) + { + if (streq(what, esp_flags[i])) + { + (*esp) |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown object flag '%s'.", what); + + /* Error */ + return (1); +} + +/* + * Initialize the "player" arrays, by parsing an ascii "template" file + */ +errr init_player_info_txt(FILE *fp, char *buf) +{ + int i = 0, z; + int powers = 0; + int lev = 1; + int tit_idx = 0; + int spec_idx = 0; + int cur_ab = -1; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + player_race *rp_ptr = NULL; + player_race_mod *rmp_ptr = NULL; + player_class *c_ptr = NULL; + player_spec *s_ptr = NULL; + meta_class_type *mc_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Start the "fake" stuff */ + rp_head->name_size = 0; + rp_head->text_size = 0; + rmp_head->name_size = 0; + rmp_head->text_size = 0; + c_head->name_size = 0; + c_head->text_size = 0; + + /* Init general skills */ + for (z = 0; z < MAX_SKILLS; z++) + { + gen_skill_basem[z] = 0; + gen_skill_base[z] = 0; + gen_skill_modm[z] = 0; + gen_skill_mod[z] = 0; + } + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Reinit error_idx */ + if (buf[0] == 'I') + { + error_idx = -1; + continue; + } + + /* Process 'H' for "History" */ + if (buf[0] == 'H') + { + int idx; + char *zz[6]; + + /* Scan for the values */ + if (tokenize(buf + 2, 6, zz, ':', ':') != 6) return (1); + + idx = atoi(zz[0]); + bg[idx].roll = atoi(zz[1]); + bg[idx].chart = atoi(zz[2]); + bg[idx].next = atoi(zz[3]); + bg[idx].bonus = atoi(zz[4]); + + bg[idx].info = ++rp_head->text_size; + + /* Append chars to the name */ + strcpy(rp_text + rp_head->text_size, zz[5]); + + /* Advance the index */ + rp_head->text_size += strlen(zz[5]); + + /* Next... */ + continue; + } + + /* Process 'G:k' for "General skills" */ + if ((buf[0] == 'G') && (buf[2] == 'k')) + { + long val, mod, i; + char name[200], v, m; + + /* Scan for the values */ + if (5 != sscanf(buf + 4, "%c%ld:%c%ld:%s", + &v, &val, &m, &mod, name)) return (1); + + if ((i = find_skill(name)) == -1) return (1); + gen_skill_basem[i] = monster_ego_modify(v); + gen_skill_base[i] = val; + gen_skill_modm[i] = monster_ego_modify(m); + gen_skill_mod[i] = mod; + + /* Next... */ + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if ((buf[0] == 'R') && (buf[2] == 'N')) + { + /* Find the colon before the name */ + s = strchr(buf + 4, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 4); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= rp_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + rp_ptr = &race_info[i]; + + /* Hack -- Verify space */ + if (rp_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!rp_ptr->title) rp_ptr->title = ++rp_head->name_size; + + /* Append chars to the name */ + strcpy(rp_name + rp_head->name_size, s); + + /* Advance the index */ + rp_head->name_size += strlen(s); + + rp_ptr->powers[0] = rp_ptr->powers[1] = rp_ptr->powers[2] = rp_ptr->powers[3] = -1; + powers = 0; + lev = 1; + cur_ab = 0; + for (z = 0; z < 10; z++) + rp_ptr->abilities[z].level = -1; + + /* Next... */ + continue; + } + + /* Process 'D' for "Description" */ + if ((buf[0] == 'R') && (buf[2] == 'D')) + { + /* Acquire the text */ + s = buf + 4; + + /* Hack -- Verify space */ + if (rp_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!rp_ptr->desc) + { + rp_ptr->desc = ++rp_head->text_size; + + /* Append chars to the name */ + strcpy(rp_text + rp_head->text_size, s); + + /* Advance the index */ + rp_head->text_size += strlen(s); + } + else + { + /* Append chars to the name */ + strcpy(rp_text + rp_head->text_size, format("\n%s", s)); + + /* Advance the index */ + rp_head->text_size += strlen(s) + 1; + } + + /* Next... */ + continue; + } + + /* Process 'E' for "body parts" */ + if ((buf[0] == 'R') && (buf[2] == 'E')) + { + int s[BODY_MAX], z; + + /* Scan for the values */ + if (BODY_MAX != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5])) return (1); + + for (z = 0; z < BODY_MAX; z++) + rp_ptr->body_parts[z] = s[z]; + + /* Next... */ + continue; + } + + /* Process 'R' for "flag level" */ + if ((buf[0] == 'R') && (buf[2] == 'R')) + { + int s[2]; + + /* Scan for the values */ + if (2 != sscanf(buf + 4, "%d:%d", + &s[0], &s[1])) return (1); + + lev = s[0]; + rp_ptr->opval[lev] = s[1]; + + /* Next... */ + continue; + } + + /* Process 'S' for "Stats" */ + if ((buf[0] == 'R') && (buf[2] == 'S')) + { + int s[7], z; + + /* Scan for the values */ + if (7 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6])) return (1); + + rp_ptr->luck = s[6]; + for (z = 0; z < 6; z++) + rp_ptr->r_adj[z] = s[z]; + + /* Next... */ + continue; + } + + /* Process 'Z' for "powers" */ + if ((buf[0] == 'R') && (buf[2] == 'Z')) + { + int i; + + /* Acquire the text */ + s = buf + 4; + + /* Find it in the list */ + for (i = 0; i < POWER_MAX; i++) + { + if (!stricmp(s, powers_type[i].name)) break; + } + + if (i == POWER_MAX) return (6); + + rp_ptr->powers[powers++] = i; + + /* Next... */ + continue; + } + + /* Process 'K' for "sKills" */ + if ((buf[0] == 'R') && (buf[2] == 'K')) + { + int s[8]; + + /* Scan for the values */ + if (8 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7])) return (1); + + rp_ptr->r_dis = s[0]; + rp_ptr->r_dev = s[1]; + rp_ptr->r_sav = s[2]; + rp_ptr->r_stl = s[3]; + rp_ptr->r_srh = s[4]; + rp_ptr->r_fos = s[5]; + rp_ptr->r_thn = s[6]; + rp_ptr->r_thb = s[7]; + + /* Next... */ + continue; + } + + /* Process 'k' for "skills" */ + if ((buf[0] == 'R') && (buf[2] == 'k')) + { + long val, mod, i; + char name[200], v, m; + + /* Scan for the values */ + if (5 != sscanf(buf + 4, "%c%ld:%c%ld:%s", + &v, &val, &m, &mod, name)) return (1); + + if ((i = find_skill(name)) == -1) return (1); + rp_ptr->skill_basem[i] = monster_ego_modify(v); + rp_ptr->skill_base[i] = val; + rp_ptr->skill_modm[i] = monster_ego_modify(m); + rp_ptr->skill_mod[i] = mod; + + /* Next... */ + continue; + } + + /* Process 'b' for "abilities" */ + if ((buf[0] == 'R') && (buf[2] == 'b')) + { + char *sec; + + /* Scan for the values */ + if (NULL == (sec = strchr(buf + 4, ':'))) + { + return (1); + } + *sec = '\0'; + sec++; + if (!*sec) return (1); + + if ((i = find_ability(sec)) == -1) return (1); + + rp_ptr->abilities[cur_ab].ability = i; + rp_ptr->abilities[cur_ab].level = atoi(buf + 4); + cur_ab++; + + /* Next... */ + continue; + } + + /* Process 'M' for "Mods" */ + if ((buf[0] == 'R') && (buf[2] == 'M')) + { + int s[10]; + + /* Scan for the values */ + if (10 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8], &s[9])) return (1); + + rp_ptr->b_age = s[0]; + rp_ptr->m_age = s[1]; + rp_ptr->m_b_ht = s[2]; + rp_ptr->m_m_ht = s[3]; + rp_ptr->m_b_wt = s[4]; + rp_ptr->m_m_wt = s[5]; + rp_ptr->f_b_ht = s[6]; + rp_ptr->f_m_ht = s[7]; + rp_ptr->f_b_wt = s[8]; + rp_ptr->f_m_wt = s[9]; + + /* Next... */ + continue; + } + + /* Process 'P' for "xtra" */ + if ((buf[0] == 'R') && (buf[2] == 'P')) + { + int s[4]; + + /* Scan for the values */ + if (4 != sscanf(buf + 4, "%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3])) return (1); + + rp_ptr->r_mhp = s[0]; + rp_ptr->r_exp = s[1]; + rp_ptr->infra = s[2]; + rp_ptr->chart = s[3]; + + /* Next... */ + continue; + } + + /* Process 'G' for "Player flags" (multiple lines) */ + if ((buf[0] == 'R') && (buf[2] == 'G')) + { + /* Parse every entry */ + for (s = buf + 4; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_player_race_flag(&rp_ptr->flags1, &rp_ptr->flags2, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'F' for "level Flags" (multiple lines) */ + if ((buf[0] == 'R') && (buf[2] == 'F')) + { + /* Parse every entry */ + for (s = buf + 4; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_race_kind_flag(&rp_ptr->oflags1[lev], &rp_ptr->oflags2[lev], &rp_ptr->oflags3[lev], &rp_ptr->oflags4[lev], &rp_ptr->oflags5[lev], &rp_ptr->oesp[lev], s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'O' for "Object birth" */ + if ((buf[0] == 'R') && (buf[2] == 'O')) + { + int s[5]; + + /* Scan for the values */ + if (5 != sscanf(buf + 4, "%d:%d:%d:%dd%d", + &s[0], &s[1], &s[4], &s[2], &s[3])) + { + s[4] = 0; + + if (4 != sscanf(buf + 4, "%d:%d:%dd%d", + &s[0], &s[1], &s[2], &s[3])) + { + return (1); + } + } + + rp_ptr->obj_pval[rp_ptr->obj_num] = s[4]; + rp_ptr->obj_tval[rp_ptr->obj_num] = s[0]; + rp_ptr->obj_sval[rp_ptr->obj_num] = s[1]; + rp_ptr->obj_dd[rp_ptr->obj_num] = s[2]; + rp_ptr->obj_ds[rp_ptr->obj_num++] = s[3]; + + /* Next... */ + continue; + } + + /* Process 'C' for "Class choice flags" (multiple lines) */ + if ((buf[0] == 'R') && (buf[2] == 'C')) + { + /* Parse every entry */ + for (s = buf + 4; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_class_flag(rp_ptr->choice, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if ((buf[0] == 'S') && (buf[2] == 'N')) + { + /* Find the colon before the name */ + s = strchr(buf + 4, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 4); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= rmp_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + rmp_ptr = &race_mod_info[i]; + + /* Hack -- Verify space */ + if (rmp_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!rmp_ptr->title) rmp_ptr->title = ++rmp_head->name_size; + + /* Append chars to the name */ + strcpy(rmp_name + rmp_head->name_size, s); + + /* Advance the index */ + rmp_head->name_size += strlen(s); + + rmp_ptr->powers[0] = rmp_ptr->powers[1] = rmp_ptr->powers[2] = rmp_ptr->powers[3] = -1; + powers = 0; + lev = 1; + cur_ab = 0; + for (z = 0; z < 10; z++) + rmp_ptr->abilities[z].level = -1; + + /* Next... */ + continue; + } + + /* Process 'D' for "Description" */ + if ((buf[0] == 'S') && (buf[2] == 'D')) + { + /* Acquire the text */ + s = buf + 6; + + if (buf[4] == 'A') rmp_ptr->place = TRUE; + else rmp_ptr->place = FALSE; + + /* Hack -- Verify space */ + if (rmp_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!rmp_ptr->desc) + { + rmp_ptr->desc = ++rmp_head->text_size; + + /* Append chars to the name */ + strcpy(rmp_text + rmp_head->text_size, s); + + /* Advance the index */ + rmp_head->text_size += strlen(s); + } + else + { + /* Append chars to the name */ + strcpy(rmp_text + rmp_head->text_size, format("\n%s", s)); + + /* Advance the index */ + rmp_head->text_size += strlen(s) + 1; + } + + /* Next... */ + continue; + } + + /* Process 'E' for "body parts" */ + if ((buf[0] == 'S') && (buf[2] == 'E')) + { + int s[BODY_MAX], z; + + /* Scan for the values */ + if (BODY_MAX != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5])) return (1); + + for (z = 0; z < BODY_MAX; z++) + rmp_ptr->body_parts[z] = s[z]; + + /* Next... */ + continue; + } + + /* Process 'R' for "flag level" */ + if ((buf[0] == 'S') && (buf[2] == 'R')) + { + int s[2]; + + /* Scan for the values */ + if (2 != sscanf(buf + 4, "%d:%d", + &s[0], &s[1])) return (1); + + lev = s[0]; + rmp_ptr->opval[lev] = s[1]; + + /* Next... */ + continue; + } + + /* Process 'S' for "Stats" */ + if ((buf[0] == 'S') && (buf[2] == 'S')) + { + int s[8], z; + + /* Scan for the values */ + if (8 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7])) return (1); + + rmp_ptr->mana = s[7]; + rmp_ptr->luck = s[6]; + for (z = 0; z < 6; z++) + rmp_ptr->r_adj[z] = s[z]; + + /* Next... */ + continue; + } + + /* Process 'Z' for "powers" */ + if ((buf[0] == 'S') && (buf[2] == 'Z')) + { + int i; + + /* Acquire the text */ + s = buf + 4; + + /* Find it in the list */ + for (i = 0; i < POWER_MAX; i++) + { + if (!stricmp(s, powers_type[i].name)) break; + } + + if (i == POWER_MAX) return (6); + + rmp_ptr->powers[powers++] = i; + + /* Next... */ + continue; + } + + /* Process 'k' for "skills" */ + if ((buf[0] == 'S') && (buf[2] == 'k')) + { + long val, mod, i; + char name[200], v, m; + + /* Scan for the values */ + if (5 != sscanf(buf + 4, "%c%ld:%c%ld:%s", + &v, &val, &m, &mod, name)) return (1); + + if ((i = find_skill(name)) == -1) return (1); + rmp_ptr->skill_basem[i] = monster_ego_modify(v); + rmp_ptr->skill_base[i] = val; + rmp_ptr->skill_modm[i] = monster_ego_modify(m); + rmp_ptr->skill_mod[i] = mod; + + /* Next... */ + continue; + } + + /* Process 'b' for "abilities" */ + if ((buf[0] == 'S') && (buf[2] == 'b')) + { + char *sec; + + /* Scan for the values */ + if (NULL == (sec = strchr(buf + 4, ':'))) + { + return (1); + } + *sec = '\0'; + sec++; + if (!*sec) return (1); + + if ((i = find_ability(sec)) == -1) return (1); + + rmp_ptr->abilities[cur_ab].ability = i; + rmp_ptr->abilities[cur_ab].level = atoi(buf + 4); + cur_ab++; + + /* Next... */ + continue; + } + + /* Process 'K' for "sKills" */ + if ((buf[0] == 'S') && (buf[2] == 'K')) + { + int s[8]; + + /* Scan for the values */ + if (8 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7])) return (1); + + rmp_ptr->r_dis = s[0]; + rmp_ptr->r_dev = s[1]; + rmp_ptr->r_sav = s[2]; + rmp_ptr->r_stl = s[3]; + rmp_ptr->r_srh = s[4]; + rmp_ptr->r_fos = s[5]; + rmp_ptr->r_thn = s[6]; + rmp_ptr->r_thb = s[7]; + + /* Next... */ + continue; + } + + /* Process 'M' for "Mods" */ + if ((buf[0] == 'S') && (buf[2] == 'M')) + { + int s[10]; + + /* Scan for the values */ + if (10 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8], &s[9])) return (1); + + rmp_ptr->b_age = s[0]; + rmp_ptr->m_age = s[1]; + rmp_ptr->m_b_ht = s[2]; + rmp_ptr->m_m_ht = s[3]; + rmp_ptr->m_b_wt = s[4]; + rmp_ptr->m_m_wt = s[5]; + rmp_ptr->f_b_ht = s[6]; + rmp_ptr->f_m_ht = s[7]; + rmp_ptr->f_b_wt = s[8]; + rmp_ptr->f_m_wt = s[9]; + + /* Next... */ + continue; + } + + /* Process 'P' for "xtra" */ + if ((buf[0] == 'S') && (buf[2] == 'P')) + { + int s[3]; + + /* Scan for the values */ + if (3 != sscanf(buf + 4, "%d:%d:%d", + &s[0], &s[1], &s[2])) return (1); + + rmp_ptr->r_mhp = s[0]; + rmp_ptr->r_exp = s[1]; + rmp_ptr->infra = s[2]; + + /* Next... */ + continue; + } + + /* Process 'G' for "Player flags" (multiple lines) */ + if ((buf[0] == 'S') && (buf[2] == 'G')) + { + /* Parse every entry */ + for (s = buf + 4; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_player_race_flag(&rmp_ptr->flags1, &rmp_ptr->flags2, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'F' for "level Flags" (multiple lines) */ + if ((buf[0] == 'S') && (buf[2] == 'F')) + { + /* Parse every entry */ + for (s = buf + 4; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_race_kind_flag(&rmp_ptr->oflags1[lev], &rmp_ptr->oflags2[lev], &rmp_ptr->oflags3[lev], &rmp_ptr->oflags4[lev], &rmp_ptr->oflags5[lev], &rmp_ptr->oesp[lev], s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'O' for "Object birth" */ + if ((buf[0] == 'S') && (buf[2] == 'O')) + { + int s[5]; + + /* Scan for the values */ + if (5 != sscanf(buf + 4, "%d:%d:%d:%dd%d", + &s[0], &s[1], &s[4], &s[2], &s[3])) + { + s[4] = 0; + + if (4 != sscanf(buf + 4, "%d:%d:%dd%d", + &s[0], &s[1], &s[2], &s[3])) + { + return (1); + } + } + + rmp_ptr->obj_pval[rmp_ptr->obj_num] = s[4]; + rmp_ptr->obj_tval[rmp_ptr->obj_num] = s[0]; + rmp_ptr->obj_sval[rmp_ptr->obj_num] = s[1]; + rmp_ptr->obj_dd[rmp_ptr->obj_num] = s[2]; + rmp_ptr->obj_ds[rmp_ptr->obj_num++] = s[3]; + + /* Next... */ + continue; + } + + /* Process 'A' for "Allowed races" (multiple lines) */ + if ((buf[0] == 'S') && (buf[2] == 'A')) + { + /* Parse every entry */ + for (s = buf + 4; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_race_allow_flag(rmp_ptr->choice, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'C' for "Class choice flags" (multiple lines) */ + if ((buf[0] == 'S') && (buf[2] == 'C')) + { + u32b choice[2] = {0, 0}, z; + + /* Parse every entry */ + for (s = buf + 6; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_class_flag(choice, s)) return (5); + + /* Start the next entry */ + s = t; + } + + for (z = 0; z < 2; z++) + { + if (buf[4] == 'A') rmp_ptr->pclass[z] |= choice[z]; + else rmp_ptr->mclass[z] |= choice[z]; + } + + /* Next... */ + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if ((buf[0] == 'C') && (buf[2] == 'N')) + { + int z; + + /* Find the colon before the name */ + s = strchr(buf + 4, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 4); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= c_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + c_ptr = &class_info[i]; + + /* Hack -- Verify space */ + if (c_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!c_ptr->title) c_ptr->title = ++c_head->name_size; + + /* Append chars to the name */ + strcpy(c_name + c_head->name_size, s); + + /* Advance the index */ + c_head->name_size += strlen(s); + + c_ptr->powers[0] = c_ptr->powers[1] = c_ptr->powers[2] = c_ptr->powers[3] = -1; + powers = 0; + lev = 1; + for (z = 0; z < 10; z++) + c_ptr->abilities[z].level = -1; + cur_ab = 0; + c_ptr->obj_num = 0; + tit_idx = 0; + spec_idx = -1; + for (z = 0; z < MAX_SPEC; z++) + c_ptr->spec[z].title = 0; + + /* Next... */ + continue; + } + + /* Process 'D' for "Description" */ + if ((buf[0] == 'C') && (buf[2] == 'D')) + { + /* Acquire the text */ + s = buf + 6; + + /* Hack -- Verify space */ + if (c_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + switch (buf[4]) + { + case '0': + /* Advance and Save the text index */ + if (!c_ptr->desc) + { + c_ptr->desc = ++c_head->text_size; + + /* Append chars to the name */ + strcpy(c_text + c_head->text_size, s); + + /* Advance the index */ + c_head->text_size += strlen(s); + } + else + { + /* Append chars to the name */ + strcpy(c_text + c_head->text_size, format("\n%s", s)); + + /* Advance the index */ + c_head->text_size += strlen(s) + 1; + } + break; + case '1': + /* Advance and Save the text index */ + c_ptr->titles[tit_idx++] = ++c_head->text_size; + + /* Append chars to the name */ + strcpy(c_text + c_head->text_size, s); + + /* Advance the index */ + c_head->text_size += strlen(s); + break; + default: + return (6); + break; + } + + /* Next... */ + continue; + } + + /* Process 'O' for "Object birth" */ + if ((buf[0] == 'C') && (buf[2] == 'O')) + { + int s[5]; + + /* Scan for the values */ + if (5 != sscanf(buf + 4, "%d:%d:%d:%dd%d", + &s[0], &s[1], &s[4], &s[2], &s[3])) + { + s[4] = 0; + + if (4 != sscanf(buf + 4, "%d:%d:%dd%d", + &s[0], &s[1], &s[2], &s[3])) + { + return (1); + } + } + + c_ptr->obj_pval[c_ptr->obj_num] = s[4]; + c_ptr->obj_tval[c_ptr->obj_num] = s[0]; + c_ptr->obj_sval[c_ptr->obj_num] = s[1]; + c_ptr->obj_dd[c_ptr->obj_num] = s[2]; + c_ptr->obj_ds[c_ptr->obj_num++] = s[3]; + + /* Next... */ + continue; + } + + /* Process 'E' for "body parts" */ + if ((buf[0] == 'C') && (buf[2] == 'E')) + { + int s[BODY_MAX], z; + + /* Scan for the values */ + if (BODY_MAX != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5])) return (1); + + for (z = 0; z < BODY_MAX; z++) + c_ptr->body_parts[z] = s[z]; + + /* Next... */ + continue; + } + + /* Process 'R' for "flag level" */ + if ((buf[0] == 'C') && (buf[2] == 'R')) + { + int s[2]; + + /* Scan for the values */ + if (2 != sscanf(buf + 4, "%d:%d", + &s[0], &s[1])) return (1); + + lev = s[0]; + c_ptr->opval[lev] = s[1]; + + /* Next... */ + continue; + } + + /* Process 'C' for "Stats" */ + if ((buf[0] == 'C') && (buf[2] == 'S')) + { + int s[8], z; + + /* Scan for the values */ + if (8 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7])) return (1); + + c_ptr->mana = s[6]; + c_ptr->extra_blows = s[7]; + for (z = 0; z < 6; z++) + c_ptr->c_adj[z] = s[z]; + + /* Next... */ + continue; + } + + /* Process 'k' for "skills" */ + if ((buf[0] == 'C') && (buf[2] == 'k')) + { + long val, mod, i; + char name[200], v, m; + + /* Scan for the values */ + if (5 != sscanf(buf + 4, "%c%ld:%c%ld:%s", + &v, &val, &m, &mod, name)) return (1); + + if ((i = find_skill(name)) == -1) return (1); + c_ptr->skill_basem[i] = monster_ego_modify(v); + c_ptr->skill_base[i] = val; + c_ptr->skill_modm[i] = monster_ego_modify(m); + c_ptr->skill_mod[i] = mod; + + /* Next... */ + continue; + } + + /* Process 'b' for "abilities" */ + if ((buf[0] == 'C') && (buf[2] == 'b')) + { + char *sec; + + /* Scan for the values */ + if (NULL == (sec = strchr(buf + 4, ':'))) + { + return (1); + } + *sec = '\0'; + sec++; + if (!*sec) return (1); + + if ((i = find_ability(sec)) == -1) return (1); + + c_ptr->abilities[cur_ab].ability = i; + c_ptr->abilities[cur_ab].level = atoi(buf + 4); + cur_ab++; + + /* Next... */ + continue; + } + + /* Process 'g' for "gods" */ + if ((buf[0] == 'C') && (buf[2] == 'g')) + { + int i; + + if (streq(buf + 4, "All Gods")) + c_ptr->gods = 0xFFFFFFFF; + else + { + if ((i = find_god(buf + 4)) == -1) return (1); + c_ptr->gods |= BIT(i); + } + + /* Next... */ + continue; + } + + /* Process 'Z' for "powers" */ + if ((buf[0] == 'C') && (buf[2] == 'Z')) + { + int i; + + /* Acquire the text */ + s = buf + 4; + + /* Find it in the list */ + for (i = 0; i < POWER_MAX; i++) + { + if (!stricmp(s, powers_type[i].name)) break; + } + + if (i == POWER_MAX) return (6); + + c_ptr->powers[powers++] = i; + + /* Next... */ + continue; + } + + /* Process 'K' for "sKills" */ + if ((buf[0] == 'C') && (buf[2] == 'K')) + { + int s[8]; + + /* Scan for the values */ + if (8 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7])) return (1); + + c_ptr->c_dis = s[0]; + c_ptr->c_dev = s[1]; + c_ptr->c_sav = s[2]; + c_ptr->c_stl = s[3]; + c_ptr->c_srh = s[4]; + c_ptr->c_fos = s[5]; + c_ptr->c_thn = s[6]; + c_ptr->c_thb = s[7]; + + /* Next... */ + continue; + } + + /* Process 'x' for "Xtra skills" */ + if ((buf[0] == 'C') && (buf[2] == 'X')) + { + int s[8]; + + /* Scan for the values */ + if (8 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d", + &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7])) return (1); + + c_ptr->x_dis = s[0]; + c_ptr->x_dev = s[1]; + c_ptr->x_sav = s[2]; + c_ptr->x_stl = s[3]; + c_ptr->x_srh = s[4]; + c_ptr->x_fos = s[5]; + c_ptr->x_thn = s[6]; + c_ptr->x_thb = s[7]; + + /* Next... */ + continue; + } + + /* Process 'P' for "xtra" */ + if ((buf[0] == 'C') && (buf[2] == 'P')) + { + int s[2]; + + /* Scan for the values */ + if (2 != sscanf(buf + 4, "%d:%d", + &s[0], &s[1])) return (1); + + c_ptr->c_mhp = s[0]; + c_ptr->c_exp = s[1]; + + /* Next... */ + continue; + } + + /* Process 'C' for "sensing" */ + if ((buf[0] == 'C') && (buf[2] == 'C')) + { + long int s[3]; + char h, m; + + /* Scan for the values */ + if (5 != sscanf(buf + 4, "%c:%c:%ld:%ld:%ld", + &h, &m, &s[0], &s[1], &s[2])) return (1); + + c_ptr->sense_heavy = (h == 'H') ? TRUE : FALSE; + c_ptr->sense_heavy_magic = (m == 'H') ? TRUE : FALSE; + c_ptr->sense_base = s[0]; + c_ptr->sense_pl = s[1]; + c_ptr->sense_plus = s[2]; + + /* Next... */ + continue; + } + + /* Process 'B' for "blows" */ + if ((buf[0] == 'C') && (buf[2] == 'B')) + { + int s[3]; + + /* Scan for the values */ + if (3 != sscanf(buf + 4, "%d:%d:%d", + &s[0], &s[1], &s[2])) return (1); + + c_ptr->blow_num = s[0]; + c_ptr->blow_wgt = s[1]; + c_ptr->blow_mul = s[2]; + + /* Next... */ + continue; + } + + /* Process 'G' for "Player flags" (multiple lines) */ + if ((buf[0] == 'C') && (buf[2] == 'G')) + { + /* Parse every entry */ + for (s = buf + 4; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_player_race_flag(&c_ptr->flags1, &c_ptr->flags2, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'F' for "level Flags" (multiple lines) */ + if ((buf[0] == 'C') && (buf[2] == 'F')) + { + /* Parse every entry */ + for (s = buf + 4; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_race_kind_flag(&c_ptr->oflags1[lev], &c_ptr->oflags2[lev], &c_ptr->oflags3[lev], &c_ptr->oflags4[lev], &c_ptr->oflags5[lev], &c_ptr->oesp[lev], s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Specialities */ + if ((buf[0] == 'C') && (buf[2] == 'a')) + { + /* Process 'N' for "New/Number/Name" */ + if (buf[4] == 'N') + { + /* Find the colon before the name */ + s = buf + 6; + + /* Paranoia -- require a name */ + if (!*s) return (1); + /* Get the index */ + spec_idx++; + + /* Verify information */ + if (spec_idx >= MAX_SPEC) return (2); + + /* Point at the "info" */ + s_ptr = &c_ptr->spec[spec_idx]; + + /* Hack -- Verify space */ + if (c_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!s_ptr->title) s_ptr->title = ++c_head->name_size; + + /* Append chars to the name */ + strcpy(c_name + c_head->name_size, s); + + /* Advance the index */ + c_head->name_size += strlen(s); + + s_ptr->obj_num = 0; + cur_ab = 0; + for (z = 0; z < 10; z++) + s_ptr->abilities[z].level = -1; + + /* Next... */ + continue; + } + + /* Process 'D' for "Description" */ + if (buf[4] == 'D') + { + /* Acquire the text */ + s = buf + 6; + + /* Hack -- Verify space */ + if (c_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!s_ptr->desc) + { + s_ptr->desc = ++c_head->text_size; + + /* Append chars to the name */ + strcpy(c_text + c_head->text_size, s); + + /* Advance the index */ + c_head->text_size += strlen(s); + } + else + { + /* Append chars to the name */ + strcpy(c_text + c_head->text_size, format("\n%s", s)); + + /* Advance the index */ + c_head->text_size += strlen(s) + 1; + } + + /* Next... */ + continue; + } + + /* Process 'O' for "Object birth" */ + if (buf[4] == 'O') + { + int s[5]; + + /* Scan for the values */ + if (5 != sscanf(buf + 6, "%d:%d:%d:%dd%d", + &s[0], &s[1], &s[4], &s[2], &s[3])) + { + s[4] = 0; + + if (4 != sscanf(buf + 6, "%d:%d:%dd%d", + &s[0], &s[1], &s[2], &s[3])) + { + return (1); + } + } + + s_ptr->obj_pval[s_ptr->obj_num] = s[4]; + s_ptr->obj_tval[s_ptr->obj_num] = s[0]; + s_ptr->obj_sval[s_ptr->obj_num] = s[1]; + s_ptr->obj_dd[s_ptr->obj_num] = s[2]; + s_ptr->obj_ds[s_ptr->obj_num++] = s[3]; + + /* Next... */ + continue; + } + + /* Process 'g' for "gods" */ + if (buf[4] == 'g') + { + int i; + + if (streq(buf + 6, "All Gods")) + s_ptr->gods = 0xFFFFFFFF; + else + { + if ((i = find_god(buf + 6)) == -1) return (1); + s_ptr->gods |= BIT(i); + } + + /* Next... */ + continue; + } + + /* Process 'k' for "skills" */ + if (buf[4] == 'k') + { + long val, mod, i; + char name[200], v, m; + + /* Scan for the values */ + if (5 != sscanf(buf + 6, "%c%ld:%c%ld:%s", + &v, &val, &m, &mod, name)) return (1); + + if ((i = find_skill(name)) == -1) return (1); + s_ptr->skill_basem[i] = monster_ego_modify(v); + s_ptr->skill_base[i] = val; + s_ptr->skill_modm[i] = monster_ego_modify(m); + s_ptr->skill_mod[i] = mod; + + /* Next... */ + continue; + } + + /* Process 'b' for "abilities" */ + if (buf[4] == 'b') + { + char *sec; + + /* Scan for the values */ + if (NULL == (sec = strchr(buf + 6, ':'))) + { + return (1); + } + *sec = '\0'; + sec++; + if (!*sec) return (1); + + if ((i = find_ability(sec)) == -1) return (1); + + s_ptr->abilities[cur_ab].ability = i; + s_ptr->abilities[cur_ab].level = atoi(buf + 6); + cur_ab++; + + /* Next... */ + continue; + } + + /* Process 'G' for "Player flags" (multiple lines) */ + if (buf[4] == 'G') + { + /* Parse every entry */ + for (s = buf + 6; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_player_race_flag(&s_ptr->flags1, &s_ptr->flags2, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + + /* Process 'K' for "desired skills" */ + if (buf[4] == 'K') + { + long val; + char name[200]; + + /* Scan for the values */ + if (2 != sscanf(buf + 6, "%ld:%s", + &val, name)) return (1); + + if ((i = find_skill(name)) == -1) return (1); + s_ptr->skill_ideal[i] = val; + + /* Next... */ + continue; + } + } + + /* Process 'N' for "New/Number/Name" */ + if ((buf[0] == 'M') && (buf[2] == 'N')) + { + /* Find the colon before the name */ + s = strchr(buf + 4, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 4); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= max_mc_idx) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + mc_ptr = &meta_class_info[i]; + + /* Append chars to the name */ + strcpy(mc_ptr->name, s + 2); + mc_ptr->color = color_char_to_attr(s[0]); + for (powers = 0; powers < max_c_idx; powers++) + mc_ptr->classes[powers] = -1; + powers = 0; + + /* Next... */ + continue; + } + + /* Process 'C' for "Classes" */ + if ((buf[0] == 'M') && (buf[2] == 'C')) + { + int i; + + /* Acquire the text */ + s = buf + 4; + + /* Find it in the list */ + for (i = 0; i < max_c_idx; i++) + { + if (!stricmp(s, class_info[i].title + c_name)) break; + } + + if (i == max_c_idx) return (6); + + mc_ptr->classes[powers++] = i; + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + /* Complete the "name" and "text" sizes */ + ++rp_head->name_size; + ++rp_head->text_size; + ++rmp_head->name_size; + ++rmp_head->text_size; + ++c_head->name_size; + ++c_head->text_size; + /* No version yet */ + if (!okay) return (2); + + /* Success */ + return (0); +} + + +/* + * Initialize the "v_info" array, by parsing an ascii "template" file + */ +errr init_v_info_txt(FILE *fp, char *buf, bool_ start) +{ + int i; + char *s; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + vault_type *v_ptr = NULL; + + if (start) + { + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + /* Prepare the "fake" stuff */ + v_head->name_size = 0; + v_head->text_size = 0; + } + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + if ((buf[0] == 'Q') || (buf[0] == 'T')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf, "V:%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i <= error_idx) return (4); + + /* Verify information */ + if (i >= v_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + v_ptr = &v_info[i]; + + /* Hack -- Verify space */ + if (v_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!v_ptr->name) v_ptr->name = ++v_head->name_size; + + /* Append chars to the name */ + strcpy(v_name + v_head->name_size, s); + + /* Advance the index */ + v_head->name_size += strlen(s); + + /* Next... */ + continue; + } + + /* There better be a current v_ptr */ + if (!v_ptr) return (3); + + /* Process 'D' for "Description" */ + if (buf[0] == 'D') + { + /* Acquire the text */ + s = buf + 2; + + /* Hack -- Verify space */ + if (v_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!v_ptr->text) v_ptr->text = ++v_head->text_size; + + /* Append chars to the name */ + strcpy(v_text + v_head->text_size, s); + + /* Advance the index */ + v_head->text_size += strlen(s); + + /* Next... */ + continue; + } + + + /* Process 'X' for "Extra info" (one line only) */ + if (buf[0] == 'X') + { + int typ, rat, hgt, wid; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%d:%d", + &typ, &rat, &hgt, &wid)) return (1); + + /* Save the values */ + v_ptr->typ = typ; + v_ptr->rat = rat; + v_ptr->hgt = hgt; + v_ptr->wid = wid; + + /* Next... */ + continue; + } + + /* There better be a current v_ptr */ + if (!v_ptr) return (3); + + /* Process monster, item and level info for special levels */ + if (buf[0] == 'Y') + { + + int mon1, mon2, mon3, mon4, mon5, mon6, mon7, mon8, mon9; + int mon10, item1, item2, item3, lvl, dun_type; + + /* Scan for the values */ + if (15 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", + &mon1, &mon2, &mon3, &mon4, &mon5, &mon6, &mon7, &mon8, &mon9, &mon10, &item1, &item2, &item3, &lvl, &dun_type)) return (1); + + /* Save the values */ + v_ptr->mon[0] = mon1; + v_ptr->mon[1] = mon2; + v_ptr->mon[2] = mon3; + v_ptr->mon[3] = mon4; + v_ptr->mon[4] = mon5; + v_ptr->mon[5] = mon6; + v_ptr->mon[6] = mon7; + v_ptr->mon[7] = mon8; + v_ptr->mon[8] = mon9; + v_ptr->mon[9] = mon10; + v_ptr->item[0] = item1; + v_ptr->item[1] = item2; + v_ptr->item[2] = item3; + v_ptr->lvl = lvl; + v_ptr->dun_type = dun_type; + + /* Next... */ + continue; + } + + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + if (!start) + { + ++v_head->name_size; + ++v_head->text_size; + } + + + /* No version yet */ + if (!okay) return (2); + + + /* Success */ + return (0); +} + + +/* + * Grab one flag in an feature_type from a textual string + */ +static errr grab_one_feature_flag(feature_type *f_ptr, cptr what) +{ + int i; + + /* Check flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, f_info_flags1[i])) + { + f_ptr->flags1 |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown object flag '%s'.", what); + + /* Error */ + return (1); +} + + +/* + * Initialize the "f_info" array, by parsing an ascii "template" file + */ +errr init_f_info_txt(FILE *fp, char *buf) +{ + int i; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + u32b default_desc = 0, default_tunnel = 0, default_block = 0; + + /* Current entry */ + feature_type *f_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Prepare the "fake" stuff */ + f_head->name_size = 0; + f_head->text_size = 0; + + /* Add some fake descs */ + default_desc = ++f_head->text_size; + strcpy(f_text + f_head->text_size, "a wall blocking your way"); + f_head->text_size += strlen("a wall blocking your way"); + + default_tunnel = ++f_head->text_size; + strcpy(f_text + f_head->text_size, "You cannot tunnel through that."); + f_head->text_size += strlen("You cannot tunnel through that."); + + default_block = ++f_head->text_size; + strcpy(f_text + f_head->text_size, "a wall blocking your way"); + f_head->text_size += strlen("a wall blocking your way"); + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i <= error_idx) return (4); + + /* Verify information */ + if (i >= f_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + f_ptr = &f_info[i]; + + /* Hack -- Verify space */ + if (f_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!f_ptr->name) f_ptr->name = ++f_head->name_size; + + /* Append chars to the name */ + strcpy(f_name + f_head->name_size, s); + + /* Advance the index */ + f_head->name_size += strlen(s); + + /* Default "mimic" */ + f_ptr->mimic = i; + f_ptr->text = default_desc; + f_ptr->block = default_desc; + f_ptr->tunnel = default_tunnel; + f_ptr->block = default_block; + + /* Next... */ + continue; + } + + /* There better be a current f_ptr */ + if (!f_ptr) return (3); + + + /* Process 'D' for "Descriptions" */ + if (buf[0] == 'D') + { + /* Acquire the text */ + s = buf + 4; + + /* Hack -- Verify space */ + if (f_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + switch (buf[2]) + { + case '0': + /* Advance and Save the text index */ + f_ptr->text = ++f_head->text_size; + break; + case '1': + /* Advance and Save the text index */ + f_ptr->tunnel = ++f_head->text_size; + break; + case '2': + /* Advance and Save the text index */ + f_ptr->block = ++f_head->text_size; + break; + default: + return (6); + break; + } + + /* Append chars to the name */ + strcpy(f_text + f_head->text_size, s); + + /* Advance the index */ + f_head->text_size += strlen(s); + + /* Next... */ + continue; + } + + + /* Process 'M' for "Mimic" (one line only) */ + if (buf[0] == 'M') + { + int mimic; + + /* Scan for the values */ + if (1 != sscanf(buf + 2, "%d", + &mimic)) return (1); + + /* Save the values */ + f_ptr->mimic = mimic; + + /* Next... */ + continue; + } + + /* Process 'S' for "Shimmer" (one line only) */ + if (buf[0] == 'S') + { + char s0, s1, s2, s3, s4, s5, s6; + + /* Scan for the values */ + if (7 != sscanf(buf + 2, "%c:%c:%c:%c:%c:%c:%c", + &s0, &s1, &s2, &s3, &s4, &s5, &s6)) return (1); + + /* Save the values */ + f_ptr->shimmer[0] = color_char_to_attr(s0); + f_ptr->shimmer[1] = color_char_to_attr(s1); + f_ptr->shimmer[2] = color_char_to_attr(s2); + f_ptr->shimmer[3] = color_char_to_attr(s3); + f_ptr->shimmer[4] = color_char_to_attr(s4); + f_ptr->shimmer[5] = color_char_to_attr(s5); + f_ptr->shimmer[6] = color_char_to_attr(s6); + + /* Next... */ + continue; + } + + + /* Process 'G' for "Graphics" (one line only) */ + if (buf[0] == 'G') + { + int tmp; + + /* Paranoia */ + if (!buf[2]) return (1); + if (!buf[3]) return (1); + if (!buf[4]) return (1); + + /* Extract the color */ + tmp = color_char_to_attr(buf[4]); + + /* Paranoia */ + if (tmp < 0) return (1); + + /* Save the values */ + f_ptr->d_attr = tmp; + f_ptr->d_char = buf[2]; + + /* Next... */ + continue; + } + + /* Process 'E' for "Effects" (up to four lines) -SC- */ + if (buf[0] == 'E') + { + int side, dice, freq, type; + cptr tmp; + + /* Find the next empty blow slot (if any) */ + for (i = 0; i < 4; i++) if ((!f_ptr->d_side[i]) && + (!f_ptr->d_dice[i])) break; + + /* Oops, no more slots */ + if (i == 4) return (1); + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%dd%d:%d:%d", + &dice, &side, &freq, &type)) + { + int j; + + if (3 != sscanf(buf + 2, "%dd%d:%d", + &dice, &side, &freq)) return (1); + + tmp = buf + 2; + for (j = 0; j < 2; j++) + { + tmp = strchr(tmp, ':'); + if (tmp == NULL) return (1); + tmp++; + } + + j = 0; + + while (d_info_dtypes[j].name != NULL) + if (strcmp(d_info_dtypes[j].name, tmp) == 0) + { + f_ptr->d_type[i] = d_info_dtypes[j].feat; + break; + } + else j++; + + if (d_info_dtypes[j].name == NULL) return (1); + } + else + f_ptr->d_type[i] = type; + + freq *= 10; + /* Save the values */ + f_ptr->d_side[i] = side; + f_ptr->d_dice[i] = dice; + f_ptr->d_frequency[i] = freq; + + /* Next... */ + continue; + } + + /* Hack -- Process 'F' for flags */ + if (buf[0] == 'F') + { + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_feature_flag(f_ptr, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++f_head->name_size; + ++f_head->text_size; + + + /* No version yet */ + if (!okay) return (2); + + + /* Success */ + return (0); +} + + +/* + * Grab one flag in an object_kind from a textual string + */ +static errr grab_one_kind_flag(object_kind *k_ptr, cptr what, bool_ obvious) +{ + int i; + + /* Check flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags1[i])) + { + if (obvious) + k_ptr->oflags1 |= (1L << i); + else + k_ptr->flags1 |= (1L << i); + return (0); + } + } + + /* Check flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2[i])) + { + if (obvious) + k_ptr->oflags2 |= (1L << i); + else + k_ptr->flags2 |= (1L << i); + return (0); + } + } + + /* Check flags2 -- traps*/ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2_trap[i])) + { + if (obvious) + k_ptr->oflags2 |= (1L << i); + else + k_ptr->flags2 |= (1L << i); + return (0); + } + } + + /* Check flags3 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags3[i])) + { + if (obvious) + k_ptr->oflags3 |= (1L << i); + else + k_ptr->flags3 |= (1L << i); + return (0); + } + } + + /* Check flags4 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags4[i])) + { + if (obvious) + k_ptr->oflags4 |= (1L << i); + else + k_ptr->flags4 |= (1L << i); + return (0); + } + } + + /* Check flags5 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags5[i])) + { + if (obvious) + k_ptr->oflags5 |= (1L << i); + else + k_ptr->flags5 |= (1L << i); + return (0); + } + } + + /* Check esp_flags */ + for (i = 0; i < 32; i++) + { + if (streq(what, esp_flags[i])) + { + if (obvious) + k_ptr->oesp |= (1L << i); + else + k_ptr->esp |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown object flag '%s'.", what); + + /* Error */ + return (1); +} + +/* + * Initialize the "k_info" array, by parsing an ascii "template" file + */ +errr init_k_info_txt(FILE *fp, char *buf) +{ + int i; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + object_kind *k_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Prepare the "fake" stuff */ + k_head->name_size = 0; + k_head->text_size = 0; + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i <= error_idx) return (4); + + /* Verify information */ + if (i >= k_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + k_ptr = &k_info[i]; + + /* Hack -- Verify space */ + if (k_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!k_ptr->name) k_ptr->name = ++k_head->name_size; + + /* Append chars to the name */ + strcpy(k_name + k_head->name_size, s); + + /* Advance the index */ + k_head->name_size += strlen(s); + + /* Needed hack */ + k_ptr->esp = 0; + k_ptr->power = -1; + + /* Next... */ + continue; + } + + /* There better be a current k_ptr */ + if (!k_ptr) return (3); + + /* Process 'D' for "Description" */ + if (buf[0] == 'D') + { + /* Acquire the text */ + s = buf + 2; + + /* Hack -- Verify space */ + if (k_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!k_ptr->text) k_ptr->text = ++k_head->text_size; + + /* Append a space if needed */ + else if (k_text[k_head->text_size - 1] != ' ') + { + /* Append chars to the name */ + strcpy(k_text + k_head->text_size, " "); + + /* Advance the index */ + k_head->text_size += 1; + } + + /* Append chars to the name */ + strcpy(k_text + k_head->text_size, s); + + /* Advance the index */ + k_head->text_size += strlen(s); + + /* Next... */ + continue; + } + + /* Process 'G' for "Graphics" (one line only) */ + if (buf[0] == 'G') + { + char sym; + int tmp; + + /* Paranoia */ + if (!buf[2]) return (1); + if (!buf[3]) return (1); + if (!buf[4]) return (1); + + /* Extract the char */ + sym = buf[2]; + + /* Extract the attr */ + tmp = color_char_to_attr(buf[4]); + + /* Paranoia */ + if (tmp < 0) return (1); + + /* Save the values */ + k_ptr->d_attr = tmp; + k_ptr->d_char = sym; + + /* Next... */ + continue; + } + + /* Process 'I' for "Info" (one line only) */ + if (buf[0] == 'I') + { + int tval, sval, pval, pval2 = 0; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%d:%d", + &tval, &sval, &pval, &pval2)) + { + char spl[70]; + + if (4 != sscanf(buf + 2, "%d:%d:%d:SPELL=%s", + &tval, &sval, &pval, spl)) + { + if (3 != sscanf(buf + 2, "%d:%d:%d", + &tval, &sval, &pval)) + return (1); + } + else + { + char *spl = strchr(buf + 2, '=') + 1; + + pval2 = find_spell(spl); + } + } + + /* Save the values */ + k_ptr->tval = tval; + k_ptr->sval = sval; + k_ptr->pval = pval; + k_ptr->pval2 = pval2; + + /* Next... */ + continue; + } + + /* Process 'W' for "More Info" (one line only) */ + if (buf[0] == 'W') + { + int level, extra, wgt; + long cost; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%d:%ld", + &level, &extra, &wgt, &cost)) return (1); + + /* Save the values */ + k_ptr->level = level; + k_ptr->extra = extra; + k_ptr->weight = wgt; + k_ptr->cost = cost; + + /* Next... */ + continue; + } + + /* Process 'T' for "arTifact Info" (one line only) */ + if (buf[0] == 'T') + { + int btval, bsval; + + /* Scan for the values */ + if (2 != sscanf(buf + 2, "%d:%d", + &btval, &bsval)) return (1); + + /* Save the values */ + k_ptr->btval = btval; + k_ptr->bsval = bsval; + + /* Next... */ + continue; + } + + /* Process 'Z' for "Granted power" */ + if (buf[0] == 'Z') + { + int i; + + /* Acquire the text */ + s = buf + 2; + + /* Find it in the list */ + for (i = 0; i < POWER_MAX; i++) + { + if (!stricmp(s, powers_type[i].name)) break; + } + + if (i == POWER_MAX) return (6); + + k_ptr->power = i; + + /* Next... */ + continue; + } + + /* Process 'a' for Activation */ + if ( buf[0] == 'a') + { + if (prefix(buf + 2, "HARDCORE=")) + { + k_ptr->activate = get_activation(buf + 11); + if (k_ptr->activate == -1) + return 1; + } + else if (prefix(buf + 2, "SPELL=")) + { + k_ptr->activate = -find_spell(buf + 8); + if (k_ptr->activate == -( -1)) + return 1; + } + + /* Next... */ + continue; + } + + /* Process 'A' for "Allocation" (one line only) */ + if (buf[0] == 'A') + { + int i; + + /* XXX XXX XXX Simply read each number following a colon */ + for (i = 0, s = buf + 1; s && (s[0] == ':') && s[1]; ++i) + { + /* Default chance */ + k_ptr->chance[i] = 1; + + /* Store the level */ + k_ptr->locale[i] = atoi(s + 1); + + /* Find the slash */ + t = strchr(s + 1, '/'); + + /* Find the next colon */ + s = strchr(s + 1, ':'); + + /* If the slash is "nearby", use it */ + if (t && (!s || t < s)) + { + int chance = atoi(t + 1); + if (chance > 0) k_ptr->chance[i] = chance; + } + } + + /* Next... */ + continue; + } + + /* Hack -- Process 'P' for "power" and such */ + if (buf[0] == 'P') + { + int ac, hd1, hd2, th, td, ta; + + /* Scan for the values */ + if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d", + &ac, &hd1, &hd2, &th, &td, &ta)) return (1); + + k_ptr->ac = ac; + k_ptr->dd = hd1; + k_ptr->ds = hd2; + k_ptr->to_h = th; + k_ptr->to_d = td; + k_ptr->to_a = ta; + + /* Next... */ + continue; + } + + /* Hack -- Process 'F' for flags */ + if (buf[0] == 'F') + { + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_kind_flag(k_ptr, s, FALSE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Hack -- Process 'f' for obvious flags */ + if (buf[0] == 'f') + { + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_kind_flag(k_ptr, s, TRUE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++k_head->name_size; + ++k_head->text_size; + + + /* No version yet */ + if (!okay) return (2); + + + /* Success */ + return (0); +} + +/*Get a kind flag, return flag*32+bit number or -1 for unknown*/ + +int get_k_flag(char *what) +{ + int i; + + /* Check flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags1[i])) + return i; + if (streq(what, k_info_flags2[i])) + return 1*32 + i; + if (streq(what, k_info_flags2_trap[i])) + return 1*32 + i; + if (streq(what, k_info_flags3[i])) + return 2*32 + i; + if (streq(what, k_info_flags4[i])) + return 3*32 + i; + if (streq(what, k_info_flags5[i])) + return 4*32 + i; + if (streq(what, esp_flags[i])) + return 5*32 + i; + } + + /* Oops */ + msg_format("Unknown object flag '%s'.", what); + + /* Error */ + return ( -1); + +} + +int get_r_flag(char *what) +{ + int i; + + /* Check flags */ + /* this processes all r_info_flag arrays in parallel. + Seemed like a good idea at the time.. + */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags1[i])) + return i; + if (streq(what, r_info_flags2[i])) + return 1*32 + i; + if (streq(what, r_info_flags3[i])) + return 2*32 + i; + if (streq(what, r_info_flags4[i])) + return 3*32 + i; + if (streq(what, r_info_flags5[i])) + return 4*32 + i; + if (streq(what, r_info_flags6[i])) + return 5*32 + i; + if (streq(what, r_info_flags7[i])) + return 6*32 + i; + if (streq(what, r_info_flags8[i])) + return 7*32 + i; + if (streq(what, r_info_flags9[i])) + return 8*32 + i; + } + + /* Oops */ + msg_format("Unknown race flag '%s'.", what); + + /* Error */ + return ( -1); +} +int init_al_info_essence(char *essence) +{ + int i; + for ( i = 0 ; essence_names[i][0] ; i++) + if (!strncmp(essence_names[i], essence, 9)) + { + return i; + } + return -1; +} +/* + * Initialize the "al_info" array, by parsing an ascii "template" file + */ +errr init_al_info_txt(FILE *fp, char *buf) +{ + int al_idx = 0, a_idx = 0; + char *s, *t; + struct artifact_select_flag *a_ptr = NULL; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + /* Fun! */ + al_head->name_size = 0; + *al_name = 0; + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'I' for "Info" (one line only) */ + if (buf[0] == 'I') + { + int tval, sval, qty; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d:%d:%d", + &tval, &sval, &qty)) + { + return (1); + } + + /* ignore everything after the first space. */ + s = strchr(buf, ' '); + if (s != NULL) + *s = 0; + + /* Save the values */ + alchemist_recipes[al_idx].tval = tval; + alchemist_recipes[al_idx].sval = sval; + alchemist_recipes[al_idx].qty = qty; + alchemist_recipes[al_idx].sval_essence = init_al_info_essence(strrchr(buf, ':') + 1); + if (alchemist_recipes[al_idx].sval_essence < 0) + return 5; + + al_idx++; + if (al_idx >= max_al_idx) + return 7; + /* Next... */ + continue; + } + if (buf[0] == 'a') + { + int qty; + if ( 1 != sscanf(buf + 2, "%d", &qty)) + { + return (1); + } + s = strrchr(buf, ':'); + *(s++) = 0; + t = strchr(s, ' '); + *(t++) = 0; + alchemist_recipes[al_idx].tval = 0; + alchemist_recipes[al_idx].sval = get_k_flag(s); + alchemist_recipes[al_idx].qty = qty; + alchemist_recipes[al_idx].sval_essence = init_al_info_essence(t); + if (alchemist_recipes[al_idx].sval_essence < 0) + return 1; + + al_idx++; + if (al_idx >= max_al_idx) + return 7; /* 7 is an 'out of memory' error */ + + continue; + } + if (buf[0] == 'A') + { + int group, level, pval, rtval, rsval, rpval; + long xp; + /*Verify that complete description information is + Recorded for previous Artifact flag + */ + if (a_ptr + && (!a_ptr->group || !a_ptr->desc || !a_ptr->item_desc != !a_ptr->rtval) + ) + return (1); + + a_ptr = &a_select_flags[a_idx++]; + + if ( 7 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%ld", + &group, &rtval, &rsval, &rpval, &pval, &level, &xp)) + return (1); + a_ptr->group = group; + a_ptr->rtval = rtval; + a_ptr->rsval = rsval; + a_ptr->rpval = rpval; + a_ptr->pval = pval; + a_ptr->level = level; + a_ptr->xp = xp; + continue; + } + + /*Anything else here MUST be a artifact flag line*/ + if ( !a_ptr) + return (3); + + if (buf[0] == 'F') + { + /* Get the Item flag associated with this */ + a_ptr->flag = get_k_flag(buf + 2); + if (a_ptr->flag == -1) + return (1); + continue; + } + if (buf[0] == 'x') + { + /* Get the activation name associated with this */ + a_ptr->flag = -get_activation(buf + 2); + if (a_ptr->flag == 1) + return (1); + a_ptr->group = 88; + a_ptr->pval = 0; + continue; + } + /* Get the race flags associated with this */ + if (buf[0] == 'f') + { + char *s, *t; + int idx = 0; + + if ( a_ptr->rflag[0] ) + { + msg_print("duplicate f: entries for one corpse"); + return (5); + } + + if ( a_ptr->rtval != TV_CORPSE ) + { + msg_print("f: section for corpse flags only"); + return (5); + } + if ( a_ptr->rpval ) + { + msg_print("Can't specify r_info.txt index with f: section"); + return (5); + } + + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + if ( idx > 5 ) + { + msg_print("Limit on race flags is currently 6"); + return (5); + } + + /* Parse this entry */ + a_ptr->rflag[idx] = get_r_flag(s); + if (a_ptr->rflag[idx++] == -1) + return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'p' for "Plural Description" */ + /* Only valid for flag which depend on pval */ + if (buf[0] == 'p') + { + /* Reject if doesn't depend on pval */ + + if (!a_ptr->pval) + return (1); + + /* Acquire the description */ + s = buf + 2; + + /* Hack -- Verify space */ + if (al_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + a_ptr->item_descp = ++al_head->name_size; + + /* Append chars to the name */ + strcpy(al_name + al_head->name_size, s); + + /* Advance the index */ + al_head->name_size += strlen(s); + + /* Next... */ + continue; + } + + /* Process 'D' for "Description" */ + if (buf[0] == 'D') + { + /* Acquire the description */ + s = buf + 2; + + /* Hack -- Verify space */ + if (al_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + a_ptr->desc = ++al_head->name_size; + + /* Append chars to the name */ + strcpy(al_name + al_head->name_size, s); + + /* Advance the index */ + al_head->name_size += strlen(s); + + /* Next... */ + continue; + } + + /* Process 'd' for "Item Description" */ + if (buf[0] == 'd') + { + /* Acquire the name */ + s = buf + 2; + + /* Hack -- Verify space */ + if (al_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + if (a_ptr->item_desc) + return (7); + + /* Advance and Save the name index */ + a_ptr->item_desc = ++al_head->name_size; + + /* Append chars to the name */ + strcpy(al_name + al_head->name_size, s); + + /* Advance the index */ + al_head->name_size += strlen(s); + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + /* No version yet */ + if (!okay) return (2); + + /* Hack - set the al_head->text_size to byte size of array */ + al_head->text_size = (a_idx + 1) * sizeof(artifact_select_flag); + + /* Success */ + return (0); +} + +/* + * Grab one flag in an artifact_type from a textual string + */ +static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what, bool_ obvious) +{ + int i; + + /* Check flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags1[i])) + { + if (obvious) + a_ptr->oflags1 |= (1L << i); + else + a_ptr->flags1 |= (1L << i); + return (0); + } + } + + /* Check flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2[i])) + { + if (obvious) + a_ptr->oflags2 |= (1L << i); + else + a_ptr->flags2 |= (1L << i); + return (0); + } + } + + /* Check flags2 -- traps*/ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2_trap[i])) + { + if (obvious) + a_ptr->oflags2 |= (1L << i); + else + a_ptr->flags2 |= (1L << i); + return (0); + } + } + + /* Check flags3 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags3[i])) + { + if (obvious) + a_ptr->oflags3 |= (1L << i); + else + a_ptr->flags3 |= (1L << i); + return (0); + } + } + + /* Check flags4 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags4[i])) + { + if (obvious) + a_ptr->oflags4 |= (1L << i); + else + a_ptr->flags4 |= (1L << i); + return (0); + } + } + + /* Check flags5 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags5[i])) + { + if (obvious) + a_ptr->oflags5 |= (1L << i); + else + a_ptr->flags5 |= (1L << i); + return (0); + } + } + + /* Check esp_flags */ + for (i = 0; i < 32; i++) + { + if (streq(what, esp_flags[i])) + { + if (obvious) + a_ptr->oesp |= (1L << i); + else + a_ptr->esp |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown artifact flag '%s'.", what); + + /* Error */ + return (1); +} + + + + +/* + * Initialize the "a_info" array, by parsing an ascii "template" file + */ +errr init_a_info_txt(FILE *fp, char *buf) +{ + int i; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + artifact_type *a_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= a_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + a_ptr = &a_info[i]; + + /* Hack -- Verify space */ + if (a_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!a_ptr->name) a_ptr->name = ++a_head->name_size; + + /* Append chars to the name */ + strcpy(a_name + a_head->name_size, s); + + /* Advance the index */ + a_head->name_size += strlen(s); + + /* Ignore everything */ + a_ptr->flags3 |= (TR3_IGNORE_ACID); + a_ptr->flags3 |= (TR3_IGNORE_ELEC); + a_ptr->flags3 |= (TR3_IGNORE_FIRE); + a_ptr->flags3 |= (TR3_IGNORE_COLD); + + /* Needed hack */ + a_ptr->esp = 0; + a_ptr->power = -1; + + /*Require activating artifacts to have a activation type */ + if (a_ptr && a_ptr->flags3 & TR3_ACTIVATE && !a_ptr->activate) + { + msg_print("Activate flag without activate type"); + return 1; + } + + /* Next... */ + continue; + } + + /* There better be a current a_ptr */ + if (!a_ptr) return (3); + + /* Process 'D' for "Description" */ + if (buf[0] == 'D') + { + /* Acquire the text */ + s = buf + 2; + + /* Hack -- Verify space */ + if (a_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!a_ptr->text) a_ptr->text = ++a_head->text_size; + + /* Append a space at the end of the line, if needed */ + else if (a_text[a_head->text_size - 1] != ' ') + { + /* Append the space */ + strcpy(a_text + a_head->text_size, " "); + + /* Advance the index */ + a_head->text_size += 1; + } + + /* Append chars to the name */ + strcpy(a_text + a_head->text_size, s); + + /* Advance the index */ + a_head->text_size += strlen(s); + + /* Next... */ + continue; + } + + /* Process 'I' for "Info" (one line only) */ + if (buf[0] == 'I') + { + int tval, sval, pval; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d:%d:%d", + &tval, &sval, &pval)) + { + return (1); + } + + /* Save the values */ + a_ptr->tval = tval; + a_ptr->sval = sval; + a_ptr->pval = pval; + + /* Verify */ + if (!lookup_kind(tval, sval)) return (6); + + /* Next... */ + continue; + } + + /* Process 'W' for "More Info" (one line only) */ + if (buf[0] == 'W') + { + int level, rarity, wgt; + long cost; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%d:%ld", + &level, &rarity, &wgt, &cost)) return (1); + + /* Save the values */ + a_ptr->level = level; + a_ptr->rarity = rarity; + a_ptr->weight = wgt; + a_ptr->cost = cost; + + /* Next... */ + continue; + } + + /* Hack -- Process 'P' for "power" and such */ + if (buf[0] == 'P') + { + int ac, hd1, hd2, th, td, ta; + + /* Scan for the values */ + if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d", + &ac, &hd1, &hd2, &th, &td, &ta)) return (1); + + a_ptr->ac = ac; + a_ptr->dd = hd1; + a_ptr->ds = hd2; + a_ptr->to_h = th; + a_ptr->to_d = td; + a_ptr->to_a = ta; + + /* Next... */ + continue; + } + + /* Process 'Z' for "Granted power" */ + if (buf[0] == 'Z') + { + int i; + + /* Acquire the text */ + s = buf + 2; + + /* Find it in the list */ + for (i = 0; i < POWER_MAX; i++) + { + if (!stricmp(s, powers_type[i].name)) break; + } + + if (i == POWER_MAX) return (6); + + a_ptr->power = i; + + /* Next... */ + continue; + } + + /* Hack -- Process 'F' for flags */ + if (buf[0] == 'F') + { + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* Parse this entry */ + if (0 != grab_one_artifact_flag(a_ptr, s, FALSE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Hack -- Process 'f' for obvious flags */ + if (buf[0] == 'f') + { + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_artifact_flag(a_ptr, s, TRUE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Read activation type. */ + if (buf[0] == 'a') + { + if (prefix(buf + 2, "HARDCORE=")) + { + a_ptr->activate = get_activation(buf + 11); + if (a_ptr->activate == -1) + return 1; + } + else if (prefix(buf + 2, "SPELL=")) + { + a_ptr->activate = -find_spell(buf + 8); + if (a_ptr->activate == -( -1)) + return 1; + } + + /* Next... */ + continue; + } + + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++a_head->name_size; + ++a_head->text_size; + + + /* No version yet */ + if (!okay) return (2); + + + /* Success */ + return (0); +} + +/* +* Initialize the "set_info" array, by parsing an ascii "template" file +*/ +errr init_set_info_txt(FILE *fp, char *buf) +{ + int i; + int cur_art = 0, cur_num = 0; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + set_type *set_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + int z, y; + + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= set_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + set_ptr = &set_info[i]; + + /* Hack -- Verify space */ + if (set_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!set_ptr->name) set_ptr->name = ++set_head->name_size; + + /* Append chars to the name */ + strcpy(set_name + set_head->name_size, s); + + /* Advance the index */ + set_head->name_size += strlen(s); + + /* Needed hack */ + set_ptr->num = 0; + set_ptr->num_use = 0; + for (z = 0; z < 6; z++) + { + set_ptr->arts[z].a_idx = 0; + set_ptr->arts[z].present = FALSE; + for (y = 0; y < 6; y++) + { + set_ptr->arts[z].flags1[y] = 0; + set_ptr->arts[z].flags2[y] = 0; + set_ptr->arts[z].flags3[y] = 0; + set_ptr->arts[z].flags4[y] = 0; + set_ptr->arts[z].flags5[y] = 0; + set_ptr->arts[z].esp[y] = 0; + set_ptr->arts[z].pval[y] = 0; + } + } + + /* Next... */ + continue; + } + + /* There better be a current set_ptr */ + if (!set_ptr) return (3); + + /* Process 'D' for "Description" */ + if (buf[0] == 'D') + { + /* Acquire the text */ + s = buf + 2; + + /* Hack -- Verify space */ + if (set_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!set_ptr->desc) set_ptr->desc = ++set_head->text_size; + + /* Append chars to the name */ + strcpy(set_text + set_head->text_size, s); + + /* Advance the index */ + set_head->text_size += strlen(s); + + /* Next... */ + continue; + } + + /* Process 'P' for "Power" (up to 6) */ + if (buf[0] == 'P') + { + int a_idx, num, pval; + int z; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d:%d:%d", + &a_idx, &num, &pval)) + { + return (1); + } + + for (z = 0; z < set_ptr->num; z++) + if (set_ptr->arts[z].a_idx == a_idx) break; + if (z == set_ptr->num) + { + set_ptr->num++; + set_ptr->arts[z].a_idx = a_idx; + } + + /* Save the values */ + set_ptr->arts[z].pval[num - 1] = pval; + cur_art = z; + cur_num = num - 1; + + /* Next... */ + continue; + } + + /* Process 'F' for flags */ + if (buf[0] == 'F') + { + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* Parse this entry */ + if (0 != grab_one_race_kind_flag(&set_ptr->arts[cur_art].flags1[cur_num], + &set_ptr->arts[cur_art].flags2[cur_num], + &set_ptr->arts[cur_art].flags3[cur_num], + &set_ptr->arts[cur_art].flags4[cur_num], + &set_ptr->arts[cur_art].flags5[cur_num], + &set_ptr->arts[cur_art].esp[cur_num], + s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++set_head->name_size; + ++set_head->text_size; + + + /* No version yet */ + if (!okay) return (2); + + + /* Success */ + return (0); +} + + +/* + * Initialize the "s_info" array, by parsing an ascii "template" file + */ +errr init_s_info_txt(FILE *fp, char *buf) +{ + int i, z, order = 1; + + char *s; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + skill_type *s_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'T' for "skill Tree" */ + if (buf[0] == 'T') + { + char *sec; + s16b s1, s2; + + /* Scan for the values */ + if (NULL == (sec = strchr(buf + 2, ':'))) + { + return (1); + } + *sec = '\0'; + sec++; + if (!*sec) return (1); + + s1 = find_skill(buf + 2); + s2 = find_skill(sec); + if (s2 == -1) return (1); + + s_info[s2].father = s1; + s_info[s2].order = order++; + + /* Next... */ + continue; + } + + /* Process 'E' for "Exclusive" */ + if (buf[0] == 'E') + { + char *sec; + s16b s1, s2; + + /* Scan for the values */ + if (NULL == (sec = strchr(buf + 2, ':'))) + { + return (1); + } + *sec = '\0'; + sec++; + if (!*sec) return (1); + + s1 = find_skill(buf + 2); + s2 = find_skill(sec); + if ((s1 == -1) || (s2 == -1)) return (1); + + s_info[s1].action[s2] = SKILL_EXCLUSIVE; + s_info[s2].action[s1] = SKILL_EXCLUSIVE; + + /* Next... */ + continue; + } + + + /* Process 'O' for "Opposite" */ + if (buf[0] == 'O') + { + char *sec, *cval; + s16b s1, s2; + + /* Scan for the values */ + if (NULL == (sec = strchr(buf + 2, ':'))) + { + return (1); + } + *sec = '\0'; + sec++; + if (!*sec) return (1); + if (NULL == (cval = strchr(sec, '%'))) + { + return (1); + } + *cval = '\0'; + cval++; + if (!*cval) return (1); + + s1 = find_skill(buf + 2); + s2 = find_skill(sec); + if ((s1 == -1) || (s2 == -1)) return (1); + + s_info[s1].action[s2] = -atoi(cval); + + /* Next... */ + continue; + } + + /* Process 'A' for "Amical/friendly" */ + if (buf[0] == 'f') + { + char *sec, *cval; + s16b s1, s2; + + /* Scan for the values */ + if (NULL == (sec = strchr(buf + 2, ':'))) + { + return (1); + } + *sec = '\0'; + sec++; + if (!*sec) return (1); + if (NULL == (cval = strchr(sec, '%'))) + { + return (1); + } + *cval = '\0'; + cval++; + if (!*cval) return (1); + + s1 = find_skill(buf + 2); + s2 = find_skill(sec); + if ((s1 == -1) || (s2 == -1)) return (1); + + s_info[s1].action[s2] = atoi(cval); + + /* Next... */ + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i >= s_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + s_ptr = &s_info[i]; + + /* Hack -- Verify space */ + if (s_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!s_ptr->name) s_ptr->name = ++s_head->name_size; + + /* Append chars to the name */ + strcpy(s_name + s_head->name_size, s); + + /* Advance the index */ + s_head->name_size += strlen(s); + + /* Init */ + s_ptr->action_mkey = 0; + s_ptr->dev = FALSE; + s_ptr->random_gain_chance = 100; + for (z = 0; z < max_s_idx; z++) + { + s_ptr->action[z] = 0; + } + + /* Next... */ + continue; + } + + /* There better be a current s_ptr */ + if (!s_ptr) return (3); + + /* Process 'D' for "Description" */ + if (buf[0] == 'D') + { + /* Acquire the text */ + s = buf + 2; + + /* Hack -- Verify space */ + if (s_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!s_ptr->desc) + { + s_ptr->desc = ++s_head->text_size; + + /* Append chars to the name */ + strcpy(s_text + s_head->text_size, s); + + /* Advance the index */ + s_head->text_size += strlen(s); + } + else + { + /* Append chars to the name */ + strcpy(s_text + s_head->text_size, format("\n%s", s)); + + /* Advance the index */ + s_head->text_size += strlen(s) + 1; + } + + /* Next... */ + continue; + } + + /* Process 'A' for "Activation Description" */ + if (buf[0] == 'A') + { + char *txt; + + /* Acquire the text */ + s = buf + 2; + + if (NULL == (txt = strchr(s, ':'))) return (1); + *txt = '\0'; + txt++; + + /* Hack -- Verify space */ + if (s_head->text_size + strlen(txt) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!s_ptr->action_desc) s_ptr->action_desc = ++s_head->text_size; + + /* Append chars to the name */ + strcpy(s_text + s_head->text_size, txt); + s_ptr->action_mkey = atoi(s); + + /* Advance the index */ + s_head->text_size += strlen(txt); + + /* Next... */ + continue; + } + + /* Process 'I' for "Info" (one line only) */ + if (buf[0] == 'I') + { + int rate; + + /* Scan for the values */ + if (1 != sscanf(buf + 2, "%d", &rate)) + { + return (1); + } + + /* Save the values */ + s_ptr->rate = rate; + + /* Next... */ + continue; + } + + /* Process 'G' for "random Gain" (one line only) */ + if (buf[0] == 'G') + { + int chance; + + /* Scan for the values */ + if (1 != sscanf(buf + 2, "%d", &chance)) + { + return (1); + } + + /* Save the values */ + s_ptr->random_gain_chance = chance; + + /* Next... */ + continue; + } + + /* Process 'F' for flags */ + if (buf[0] == 'F') + { + char *t; + + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* Parse this entry */ + if (0 != grab_one_skill_flag(&(s_ptr->flags1), s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++s_head->name_size; + ++s_head->text_size; + + + /* No version yet */ + if (!okay) return (2); + + + /* Success */ + return (0); +} + +/* + * Initialize the "ab_info" array, by parsing an ascii "template" file + */ +errr init_ab_info_txt(FILE *fp, char *buf) +{ + int i, z; + + char *s; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + ability_type *ab_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i >= ab_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + ab_ptr = &ab_info[i]; + + /* Hack -- Verify space */ + if (ab_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!ab_ptr->name) ab_ptr->name = ++ab_head->name_size; + + /* Append chars to the name */ + strcpy(ab_name + ab_head->name_size, s); + + /* Advance the index */ + ab_head->name_size += strlen(s); + + /* Init */ + ab_ptr->action_mkey = 0; + ab_ptr->acquired = FALSE; + for (z = 0; z < 10; z++) + { + ab_ptr->skills[z] = -1; + ab_ptr->need_abilities[z] = -1; + ab_ptr->forbid_abilities[z] = -1; + } + for (z = 0; z < 6; z++) + { + ab_ptr->stat[z] = -1; + } + + /* Next... */ + continue; + } + + /* There better be a current ab_ptr */ + if (!ab_ptr) return (3); + + /* Process 'D' for "Description" */ + if (buf[0] == 'D') + { + /* Acquire the text */ + s = buf + 2; + + /* Hack -- Verify space */ + if (ab_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!ab_ptr->desc) + { + ab_ptr->desc = ++ab_head->text_size; + + /* Append chars to the name */ + strcpy(ab_text + ab_head->text_size, s); + + /* Advance the index */ + ab_head->text_size += strlen(s); + } + else + { + /* Append chars to the name */ + strcpy(ab_text + ab_head->text_size, format("\n%s", s)); + + /* Advance the index */ + ab_head->text_size += strlen(s) + 1; + } + + /* Next... */ + continue; + } + + /* Process 'A' for "Activation Description" */ + if (buf[0] == 'A') + { + char *txt; + + /* Acquire the text */ + s = buf + 2; + + if (NULL == (txt = strchr(s, ':'))) return (1); + *txt = '\0'; + txt++; + + /* Hack -- Verify space */ + if (ab_head->text_size + strlen(txt) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!ab_ptr->action_desc) ab_ptr->action_desc = ++ab_head->text_size; + + /* Append chars to the name */ + strcpy(ab_text + ab_head->text_size, txt); + ab_ptr->action_mkey = atoi(s); + + /* Advance the index */ + ab_head->text_size += strlen(txt); + + /* Next... */ + continue; + } + + /* Process 'I' for "Info" (one line only) */ + if (buf[0] == 'I') + { + int cost; + + /* Scan for the values */ + if (1 != sscanf(buf + 2, "%d", &cost)) + { + return (1); + } + + /* Save the values */ + ab_ptr->cost = cost; + + /* Next... */ + continue; + } + + /* Process 'k' for "Skill" */ + if (buf[0] == 'k') + { + char *sec; + s16b level, skill; + + /* Scan for the values */ + if (NULL == (sec = strchr(buf + 2, ':'))) + { + return (1); + } + *sec = '\0'; + sec++; + if (!*sec) return (1); + + level = atoi(buf + 2); + skill = find_skill(sec); + + if (skill == -1) return (1); + + for (z = 0; z < 10; z++) + if (ab_ptr->skills[z] == -1) break; + + if (z < 10) + { + ab_ptr->skills[z] = skill; + ab_ptr->skill_levels[z] = level; + } + + /* Next... */ + continue; + } + + /* Process 'a' for "needed ability" */ + if (buf[0] == 'a') + { + s16b ab; + + ab = find_ability(buf + 2); + + if (ab == -1) return (1); + + for (z = 0; z < 10; z++) + if (ab_ptr->need_abilities[z] == -1) break; + + if (z < 10) + { + ab_ptr->need_abilities[z] = ab; + } + + /* Next... */ + continue; + } + + /* Process 'S' for "Stat" */ + if (buf[0] == 'S') + { + char *sec; + s16b stat; + + /* Scan for the values */ + if (NULL == (sec = strchr(buf + 2, ':'))) + { + return (1); + } + *sec = '\0'; + sec++; + if (!*sec) return (1); + + for (stat = 0; stat < 6; stat++) + { + if (!strcmp(stat_names[stat], sec)) + break; + } + + if (stat == 6) return (1); + + ab_ptr->stat[stat] = atoi(buf + 2); + + /* Next... */ + continue; + } + + /* Process 'E' for "Excluding ability" */ + if (buf[0] == 'E') + { + char *sec; + s16b ab1, ab2; + + /* Scan for the values */ + if (NULL == (sec = strchr(buf + 2, ':'))) + { + return (1); + } + *sec = '\0'; + sec++; + if (!*sec) return (1); + + ab1 = find_ability(buf + 2); + ab2 = find_ability(sec); + + if ((ab1 == -1) || (ab2 == -1)) return (1); + + for (z = 0; z < 10; z++) + if (ab_info[ab1].forbid_abilities[z] == -1) break; + if (z < 10) + { + ab_info[ab1].forbid_abilities[z] = ab2; + } + + for (z = 0; z < 10; z++) + if (ab_info[ab2].forbid_abilities[z] == -1) break; + if (z < 10) + { + ab_info[ab2].forbid_abilities[z] = ab1; + } + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++ab_head->name_size; + ++ab_head->text_size; + + + /* No version yet */ + if (!okay) return (2); + + + /* Success */ + return (0); +} + + +/* + * Grab one flag in a ego-item_type from a textual string + */ +static bool_ grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what, int n, bool_ obvious) +{ + int i; + + /* Check flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags1[i])) + { + if (obvious) + e_ptr->oflags1[n] |= (1L << i); + else + e_ptr->flags1[n] |= (1L << i); + return (0); + } + } + + /* Check flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2[i])) + { + if (obvious) + e_ptr->oflags2[n] |= (1L << i); + else + e_ptr->flags2[n] |= (1L << i); + return (0); + } + } + + /* Check flags2 -- traps */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2_trap[i])) + { + if (obvious) + e_ptr->oflags2[n] |= (1L << i); + else + e_ptr->flags2[n] |= (1L << i); + return (0); + } + } + + /* Check flags3 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags3[i])) + { + if (obvious) + e_ptr->oflags3[n] |= (1L << i); + else + e_ptr->flags3[n] |= (1L << i); + return (0); + } + } + + /* Check flags4 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags4[i])) + { + if (obvious) + e_ptr->oflags4[n] |= (1L << i); + else + e_ptr->flags4[n] |= (1L << i); + return (0); + } + } + + /* Check flags5 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags5[i])) + { + if (obvious) + e_ptr->oflags5[n] |= (1L << i); + else + e_ptr->flags5[n] |= (1L << i); + return (0); + } + } + + /* Check esp_flags */ + for (i = 0; i < 32; i++) + { + if (streq(what, esp_flags[i])) + { + if (obvious) + e_ptr->oesp[n] |= (1L << i); + else + e_ptr->esp[n] |= (1L << i); + return (0); + } + } + + /* Check ego_flags */ + for (i = 0; i < 32; i++) + { + if (streq(what, ego_flags[i])) + { + e_ptr->fego[n] |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown ego-item flag '%s'.", what); + + /* Error */ + return (1); +} + +static bool_ grab_one_ego_item_flag_restrict(ego_item_type *e_ptr, cptr what, bool_ need) +{ + int i; + + /* Check flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags1[i])) + { + if (need) + e_ptr->need_flags1 |= (1L << i); + else + e_ptr->forbid_flags1 |= (1L << i); + return (0); + } + } + + /* Check flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2[i])) + { + if (need) + e_ptr->need_flags2 |= (1L << i); + else + e_ptr->forbid_flags2 |= (1L << i); + return (0); + } + } + + /* Check flags2 -- traps */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2_trap[i])) + { + if (need) + e_ptr->need_flags2 |= (1L << i); + else + e_ptr->forbid_flags2 |= (1L << i); + return (0); + } + } + + /* Check flags3 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags3[i])) + { + if (need) + e_ptr->need_flags3 |= (1L << i); + else + e_ptr->forbid_flags3 |= (1L << i); + return (0); + } + } + + /* Check flags4 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags4[i])) + { + if (need) + e_ptr->need_flags4 |= (1L << i); + else + e_ptr->forbid_flags4 |= (1L << i); + return (0); + } + } + + /* Check flags5 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags5[i])) + { + if (need) + e_ptr->need_flags5 |= (1L << i); + else + e_ptr->forbid_flags5 |= (1L << i); + return (0); + } + } + + /* Check esp_flags */ + for (i = 0; i < 32; i++) + { + if (streq(what, esp_flags[i])) + { + if (need) + e_ptr->need_esp |= (1L << i); + else + e_ptr->forbid_esp |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown ego-item restrict flag '%s'.", what); + + /* Error */ + return (1); +} + + + + +/* + * Initialize the "e_info" array, by parsing an ascii "template" file + */ +errr init_e_info_txt(FILE *fp, char *buf) +{ + int i, cur_r = -1, cur_t = 0, j; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + ego_item_type *e_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= e_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + e_ptr = &e_info[i]; + + /* Hack -- Verify space */ + if (e_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!e_ptr->name) e_ptr->name = ++e_head->name_size; + + /* Append chars to the name */ + strcpy(e_name + e_head->name_size, s); + + /* Advance the index */ + e_head->name_size += strlen(s); + + /* Needed hack */ + e_ptr->power = -1; + cur_r = -1; + cur_t = 0; + + for (j = 0; j < 10; j++) + { + e_ptr->tval[j] = 255; + } + for (j = 0; j < 5; j++) + { + e_ptr->rar[j] = 0; + e_ptr->flags1[j] = 0; + e_ptr->flags2[j] = 0; + e_ptr->flags3[j] = 0; + e_ptr->flags4[j] = 0; + e_ptr->flags5[j] = 0; + e_ptr->esp[j] = 0; + } + + /* Next... */ + continue; + } + + /* There better be a current e_ptr */ + if (!e_ptr) return (3); + + + /* Process 'T' for "Tval/Sval" (up to 5 lines) */ + if (buf[0] == 'T') + { + int tv, minsv, maxsv; + + if (cur_t == 10) return 1; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d:%d:%d", + &tv, &minsv, &maxsv)) return (1); + + /* Save the values */ + e_ptr->tval[cur_t] = tv; + e_ptr->min_sval[cur_t] = minsv; + e_ptr->max_sval[cur_t] = maxsv; + + cur_t++; + + /* Next... */ + continue; + } + + /* Process 'R' for "flags rarity" (up to 5 lines) */ + if (buf[0] == 'R') + { + int rar; + + if (cur_r == 5) return 1; + + /* Scan for the values */ + if (1 != sscanf(buf + 2, "%d", + &rar)) return (1); + + cur_r++; + + /* Save the values */ + e_ptr->rar[cur_r] = rar; + + /* Next... */ + continue; + } + + /* Process 'X' for "Xtra" (one line only) */ + if (buf[0] == 'X') + { + int slot, rating; + char pos; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%c:%d:%d", + &pos, &slot, &rating)) return (1); + + /* Save the values */ + /* e_ptr->slot = slot; */ + e_ptr->rating = rating; + e_ptr->before = (pos == 'B') ? TRUE : FALSE; + + /* Next... */ + continue; + } + + /* Process 'W' for "More Info" (one line only) */ + if (buf[0] == 'W') + { + int level, rarity, rarity2; + long cost; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%d:%ld", + &level, &rarity, &rarity2, &cost)) return (1); + + /* Save the values */ + e_ptr->level = level; + e_ptr->rarity = rarity; + e_ptr->mrarity = rarity2; + e_ptr->cost = cost; + + /* Next... */ + continue; + } + + /* Hack -- Process 'C' for "creation" */ + if (buf[0] == 'C') + { + int th, td, ta, pv; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%d:%d", + &th, &td, &ta, &pv)) return (1); + + e_ptr->max_to_h = th; + e_ptr->max_to_d = td; + e_ptr->max_to_a = ta; + e_ptr->max_pval = pv; + + /* Next... */ + continue; + } + + /* Process 'Z' for "Granted power" */ + if (buf[0] == 'Z') + { + int i; + + /* Acquire the text */ + s = buf + 2; + + /* Find it in the list */ + for (i = 0; i < POWER_MAX; i++) + { + if (!stricmp(s, powers_type[i].name)) break; + } + + if (i == POWER_MAX) return (6); + + e_ptr->power = i; + + /* Next... */ + continue; + } + + if (buf[0] == 'a') + { + if (prefix(buf + 2, "HARDCORE=")) + { + e_ptr->activate = get_activation(buf + 11); + if (e_ptr->activate == -1) + return 1; + } + else if (prefix(buf + 2, "SPELL=")) + { + e_ptr->activate = -find_spell(buf + 8); + if (e_ptr->activate == -( -1)) + return 1; + } + + /* Next... */ + continue; + } + + /* Hack -- Process 'r:N' for needed flags */ + if ((buf[0] == 'r') && (buf[2] == 'N')) + { + /* Parse every entry textually */ + for (s = buf + 4; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* Parse this entry */ + if (0 != grab_one_ego_item_flag_restrict(e_ptr, s, TRUE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Hack -- Process 'r:F' for forbidden flags */ + if ((buf[0] == 'r') && (buf[2] == 'F')) + { + /* Parse every entry textually */ + for (s = buf + 4; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* Parse this entry */ + if (0 != grab_one_ego_item_flag_restrict(e_ptr, s, FALSE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Hack -- Process 'F' for flags */ + if (buf[0] == 'F') + { + if (cur_r == -1) return (6); + + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* Parse this entry */ + if (0 != grab_one_ego_item_flag(e_ptr, s, cur_r, FALSE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Hack -- Process 'f' for obvious flags */ + if (buf[0] == 'f') + { + if (cur_r == -1) return (6); + + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* Parse this entry */ + if (0 != grab_one_ego_item_flag(e_ptr, s, cur_r, TRUE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++e_head->name_size; + ++e_head->text_size; + + + /* No version yet */ + if (!okay) return (2); + + + /* Success */ + return (0); +} + +/* + * Grab one flag in a randart_part_type from a textual string + */ +static bool_ grab_one_randart_item_flag(randart_part_type *ra_ptr, cptr what, char c) +{ + int i; + u32b *f1, *f2, *f3, *f4, *f5, *esp; + + if (c == 'F') + { + f1 = &ra_ptr->flags1; + f2 = &ra_ptr->flags2; + f3 = &ra_ptr->flags3; + f4 = &ra_ptr->flags4; + f5 = &ra_ptr->flags5; + esp = &ra_ptr->esp; + } + else + { + f1 = &ra_ptr->aflags1; + f2 = &ra_ptr->aflags2; + f3 = &ra_ptr->aflags3; + f4 = &ra_ptr->aflags4; + f5 = &ra_ptr->aflags5; + esp = &ra_ptr->aesp; + } + + /* Check flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags1[i])) + { + *f1 |= (1L << i); + return (0); + } + } + + /* Check flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2[i])) + { + *f2 |= (1L << i); + return (0); + } + } + + /* Check flags2 -- traps */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags2_trap[i])) + { + *f2 |= (1L << i); + return (0); + } + } + + /* Check flags3 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags3[i])) + { + *f3 |= (1L << i); + return (0); + } + } + + /* Check flags4 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags4[i])) + { + *f4 |= (1L << i); + return (0); + } + } + + /* Check flags5 */ + for (i = 0; i < 32; i++) + { + if (streq(what, k_info_flags5[i])) + { + *f5 |= (1L << i); + return (0); + } + } + + /* Check esp_flags */ + for (i = 0; i < 32; i++) + { + if (streq(what, esp_flags[i])) + { + *esp |= (1L << i); + return (0); + } + } + + /* Check ego_flags */ + if (c == 'F') + { + for (i = 0; i < 32; i++) + { + if (streq(what, ego_flags[i])) + { + ra_ptr->fego |= (1L << i); + return (0); + } + } + } + + /* Oops */ + msg_format("Unknown ego-item flag '%s'.", what); + + /* Error */ + return (1); +} + + + + +/* + * Initialize the "ra_info" array, by parsing an ascii "template" file + */ +errr init_ra_info_txt(FILE *fp, char *buf) +{ + int i, cur_t = 0, j, cur_g = 0; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + randart_part_type *ra_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'G' for "General" (up to 30 lines) */ + if (buf[0] == 'G') + { + int chance, dd, ds, plus; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%dd%d:%d", + &chance, &dd, &ds, &plus)) return (1); + + /* Save the values */ + ra_gen[cur_g].chance = chance; + ra_gen[cur_g].dd = dd; + ra_gen[cur_g].ds = ds; + ra_gen[cur_g].plus = plus; + cur_g++; + + /* Next... */ + continue; + } + + /* Process 'N' for "New/Number" */ + if (buf[0] == 'N') + { + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= ra_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + ra_ptr = &ra_info[i]; + + /* Needed hack */ + ra_ptr->power = -1; + cur_t = 0; + + for (j = 0; j < 20; j++) + { + ra_ptr->tval[j] = 255; + } + ra_ptr->flags1 = 0; + ra_ptr->flags2 = 0; + ra_ptr->flags3 = 0; + ra_ptr->flags4 = 0; + ra_ptr->flags5 = 0; + ra_ptr->esp = 0; + ra_ptr->fego = 0; + + /* Next... */ + continue; + } + + /* There better be a current ra_ptr */ + if (!ra_ptr) return (3); + + /* Process 'T' for "Tval/Sval" (up to 5 lines) */ + if (buf[0] == 'T') + { + int tv, minsv, maxsv; + + if (cur_t == 20) return 1; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d:%d:%d", + &tv, &minsv, &maxsv)) return (1); + + /* Save the values */ + ra_ptr->tval[cur_t] = tv; + ra_ptr->min_sval[cur_t] = minsv; + ra_ptr->max_sval[cur_t] = maxsv; + + cur_t++; + + /* Next... */ + continue; + } + + /* Process 'X' for "Xtra" (one line only) */ + if (buf[0] == 'X') + { + int power, max; + + /* Scan for the values */ + if (2 != sscanf(buf + 2, "%d:%d", + &power, &max)) return (1); + + /* Save the values */ + ra_ptr->value = power; + ra_ptr->max = max; + + /* Next... */ + continue; + } + + /* Process 'W' for "More Info" (one line only) */ + if (buf[0] == 'W') + { + int level, rarity, rarity2; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d:%d:%d", + &level, &rarity, &rarity2)) return (1); + + /* Save the values */ + ra_ptr->level = level; + ra_ptr->rarity = rarity; + ra_ptr->mrarity = rarity2; + + /* Next... */ + continue; + } + + /* Hack -- Process 'C' for "creation" */ + if (buf[0] == 'C') + { + int th, td, ta, pv; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%d:%d", + &th, &td, &ta, &pv)) return (1); + + ra_ptr->max_to_h = th; + ra_ptr->max_to_d = td; + ra_ptr->max_to_a = ta; + ra_ptr->max_pval = pv; + + /* Next... */ + continue; + } + + /* Process 'Z' for "Granted power" */ + if (buf[0] == 'Z') + { + int i; + + /* Acquire the text */ + s = buf + 2; + + /* Find it in the list */ + for (i = 0; i < POWER_MAX; i++) + { + if (!stricmp(s, powers_type[i].name)) break; + } + + if (i == POWER_MAX) return (6); + + ra_ptr->power = i; + + /* Next... */ + continue; + } + + /* Hack -- Process 'F' for flags */ + if (buf[0] == 'F') + { + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* Parse this entry */ + if (0 != grab_one_randart_item_flag(ra_ptr, s, 'F')) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Hack -- Process 'A' for antagonic flags */ + if (buf[0] == 'A') + { + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* Parse this entry */ + if (0 != grab_one_randart_item_flag(ra_ptr, s, 'A')) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + + /* No version yet */ + if (!okay) return (2); + + + /* Success */ + return (0); +} + +/* + * Grab one (basic) flag in a monster_race from a textual string + */ +static errr grab_one_basic_flag(monster_race *r_ptr, cptr what) +{ + int i; + + /* Scan flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags1[i])) + { + r_ptr->flags1 |= (1L << i); + return (0); + } + } + + /* Scan flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags2[i])) + { + r_ptr->flags2 |= (1L << i); + return (0); + } + } + + /* Scan flags3 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags3[i])) + { + r_ptr->flags3 |= (1L << i); + return (0); + } + } + + /* Scan flags7 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags7[i])) + { + r_ptr->flags7 |= (1L << i); + return (0); + } + } + + /* Scan flags8 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags8[i])) + { + r_ptr->flags8 |= (1L << i); + return (0); + } + } + + /* Scan flags9 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags9[i])) + { + r_ptr->flags9 |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown monster flag '%s'.", what); + + /* Failure */ + return (1); +} + + +/* + * Grab one (spell) flag in a monster_race from a textual string + */ +static errr grab_one_spell_flag(monster_race *r_ptr, cptr what) +{ + int i; + + /* Scan flags4 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags4[i])) + { + r_ptr->flags4 |= (1L << i); + return (0); + } + } + + /* Scan flags5 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags5[i])) + { + r_ptr->flags5 |= (1L << i); + return (0); + } + } + + /* Scan flags6 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags6[i])) + { + r_ptr->flags6 |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown monster flag '%s'.", what); + + /* Failure */ + return (1); +} + + +/* + * Initialize the "r_info" array, by parsing an ascii "template" file + */ +errr init_r_info_txt(FILE *fp, char *buf) +{ + int i; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + monster_race *r_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Start the "fake" stuff */ + r_head->name_size = 0; + r_head->text_size = 0; + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= r_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + r_ptr = &r_info[i]; + + /* Hack -- Verify space */ + if (r_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!r_ptr->name) r_ptr->name = ++r_head->name_size; + + /* Append chars to the name */ + strcpy(r_name + r_head->name_size, s); + + /* Advance the index */ + r_head->name_size += strlen(s); + + /* HACK -- Those ones HAVE to have a set default value */ + r_ptr->drops.treasure = OBJ_GENE_TREASURE; + r_ptr->drops.combat = OBJ_GENE_COMBAT; + r_ptr->drops.magic = OBJ_GENE_MAGIC; + r_ptr->drops.tools = OBJ_GENE_TOOL; + r_ptr->freq_inate = r_ptr->freq_spell = 0; + + /* Next... */ + continue; + } + + /* There better be a current r_ptr */ + if (!r_ptr) return (3); + + + /* Process 'D' for "Description" */ + if (buf[0] == 'D') + { + /* Acquire the text */ + s = buf + 2; + + /* Hack -- Verify space */ + if (r_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!r_ptr->text) r_ptr->text = ++r_head->text_size; + + /* Append chars to the name */ + strcpy(r_text + r_head->text_size, s); + + /* Advance the index */ + r_head->text_size += strlen(s); + + /* Next... */ + continue; + } + + /* Process 'G' for "Graphics" (one line only) */ + if (buf[0] == 'G') + { + char sym; + int tmp; + + /* Paranoia */ + if (!buf[2]) return (1); + if (!buf[3]) return (1); + if (!buf[4]) return (1); + + /* Extract the char */ + sym = buf[2]; + + /* Extract the attr */ + tmp = color_char_to_attr(buf[4]); + + /* Paranoia */ + if (tmp < 0) return (1); + + /* Save the values */ + r_ptr->d_char = sym; + r_ptr->d_attr = tmp; + + /* Next... */ + continue; + } + + /* Process 'I' for "Info" (one line only) */ + if (buf[0] == 'I') + { + int spd, hp1, hp2, aaf, ac, slp; + + /* Scan for the other values */ + if (6 != sscanf(buf + 2, "%d:%dd%d:%d:%d:%d", + &spd, &hp1, &hp2, &aaf, &ac, &slp)) return (1); + + /* Save the values */ + r_ptr->speed = spd; + r_ptr->hdice = hp1; + r_ptr->hside = hp2; + r_ptr->aaf = aaf; + r_ptr->ac = ac; + r_ptr->sleep = slp; + + /* Next... */ + continue; + } + + /* Process 'E' for "Body Parts" (one line only) */ + if (buf[0] == 'E') + { + int weap, tors, fing, head, arms, legs; + + /* Scan for the other values */ + if (BODY_MAX != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d", + &weap, &tors, &arms, &fing, &head, &legs)) return (1); + + /* Save the values */ + r_ptr->body_parts[BODY_WEAPON] = weap; + r_ptr->body_parts[BODY_TORSO] = tors; + r_ptr->body_parts[BODY_ARMS] = arms; + r_ptr->body_parts[BODY_FINGER] = fing; + r_ptr->body_parts[BODY_HEAD] = head; + r_ptr->body_parts[BODY_LEGS] = legs; + + /* Mega debugging hack */ + if (weap > arms) quit(format("monster %d, %d weapon(s), %d arm(s) !", error_idx, weap, arms)); + + /* Next... */ + continue; + } + + /* Process 'O' for "Object type" (one line only) */ + if (buf[0] == 'O') + { + int treasure, combat, magic, tools; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%d:%d", + &treasure, &combat, &magic, &tools)) return (1); + + /* Save the values */ + r_ptr->drops.treasure = treasure; + r_ptr->drops.combat = combat; + r_ptr->drops.magic = magic; + r_ptr->drops.tools = tools; + + /* Next... */ + continue; + } + + /* Process 'W' for "More Info" (one line only) */ + if (buf[0] == 'W') + { + int lev, rar, wt; + long exp; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%d:%ld", + &lev, &rar, &wt, &exp)) return (1); + + /* Save the values */ + r_ptr->level = lev; + r_ptr->rarity = rar; + /* MEGA HACK */ + if (!wt) wt = 100; + r_ptr->weight = wt; + r_ptr->mexp = exp; + + /* Next... */ + continue; + } + + /* Process 'B' for "Blows" (up to four lines) */ + if (buf[0] == 'B') + { + int n1, n2; + + /* Find the next empty blow slot (if any) */ + for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break; + + /* Oops, no more slots */ + if (i == 4) return (1); + + /* Analyze the first field */ + for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */; + + /* Terminate the field (if necessary) */ + if (*t == ':') *t++ = '\0'; + + /* Analyze the method */ + for (n1 = 0; r_info_blow_method[n1]; n1++) + { + if (streq(s, r_info_blow_method[n1])) break; + } + + /* Invalid method */ + if (!r_info_blow_method[n1]) return (1); + + /* Analyze the second field */ + for (s = t; *t && (*t != ':'); t++) /* loop */; + + /* Terminate the field (if necessary) */ + if (*t == ':') *t++ = '\0'; + + /* Analyze effect */ + for (n2 = 0; r_info_blow_effect[n2]; n2++) + { + if (streq(s, r_info_blow_effect[n2])) break; + } + + /* Invalid effect */ + if (!r_info_blow_effect[n2]) return (1); + + /* Analyze the third field */ + for (s = t; *t && (*t != 'd'); t++) /* loop */; + + /* Terminate the field (if necessary) */ + if (*t == 'd') *t++ = '\0'; + + /* Save the method */ + r_ptr->blow[i].method = n1; + + /* Save the effect */ + r_ptr->blow[i].effect = n2; + + /* Extract the damage dice and sides */ + r_ptr->blow[i].d_dice = atoi(s); + r_ptr->blow[i].d_side = atoi(t); + + /* Next... */ + continue; + } + + /* Process 'F' for "Basic Flags" (multiple lines) */ + if (buf[0] == 'F') + { + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_basic_flag(r_ptr, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'S' for "Spell Flags" (multiple lines) */ + if (buf[0] == 'S') + { + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* XXX XXX XXX Hack -- Read spell frequency */ + if (1 == sscanf(s, "1_IN_%d", &i)) + { + /* Extract a "frequency" */ + r_ptr->freq_spell = r_ptr->freq_inate = 100 / i; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Parse this entry */ + if (0 != grab_one_spell_flag(r_ptr, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++r_head->name_size; + ++r_head->text_size; + + for (i = 1; i < max_r_idx; i++) + { + /* Invert flag WILD_ONLY <-> RF8_DUNGEON */ + r_info[i].flags8 ^= 1L; + + /* WILD_TOO without any other wilderness flags enables all flags */ + if ((r_info[i].flags8 & RF8_WILD_TOO) && !(r_info[i].flags8 & 0x7FFFFFFE)) + r_info[i].flags8 = 0x0463; + } + + /* No version yet */ + if (!okay) return (2); + + /* Success */ + return (0); +} + + +/* + * Grab one (basic) flag in a monster_race from a textual string + */ +static errr grab_one_basic_ego_flag(monster_ego *re_ptr, cptr what, bool_ add) +{ + int i; + + /* Scan flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags1[i])) + { + if (add) + re_ptr->mflags1 |= (1L << i); + else + re_ptr->nflags1 |= (1L << i); + return (0); + } + } + + /* Scan flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags2[i])) + { + if (add) + re_ptr->mflags2 |= (1L << i); + else + re_ptr->nflags2 |= (1L << i); + return (0); + } + } + + /* Scan flags3 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags3[i])) + { + if (add) + re_ptr->mflags3 |= (1L << i); + else + re_ptr->nflags3 |= (1L << i); + return (0); + } + } + + /* Scan flags7 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags7[i])) + { + if (add) + re_ptr->mflags7 |= (1L << i); + else + re_ptr->nflags7 |= (1L << i); + return (0); + } + } + + /* Scan flags8 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags8[i])) + { + if (add) + re_ptr->mflags8 |= (1L << i); + else + re_ptr->nflags8 |= (1L << i); + return (0); + } + } + + /* Scan flags9 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags9[i])) + { + if (add) + re_ptr->mflags9 |= (1L << i); + else + re_ptr->nflags9 |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown monster flag '%s'.", what); + + /* Failure */ + return (1); +} + + +/* + * Grab one (spell) flag in a monster_race from a textual string + */ +static errr grab_one_spell_ego_flag(monster_ego *re_ptr, cptr what, bool_ add) +{ + int i; + + /* Scan flags4 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags4[i])) + { + if (add) + re_ptr->mflags4 |= (1L << i); + else + re_ptr->nflags4 |= (1L << i); + return (0); + } + } + + /* Scan flags5 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags5[i])) + { + if (add) + re_ptr->mflags5 |= (1L << i); + else + re_ptr->nflags5 |= (1L << i); + return (0); + } + } + + /* Scan flags6 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags6[i])) + { + if (add) + re_ptr->mflags6 |= (1L << i); + else + re_ptr->nflags6 |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown monster flag '%s'.", what); + + /* Failure */ + return (1); +} + +/* + * Grab one (basic) flag in a monster_race from a textual string + */ +static errr grab_one_ego_flag(monster_ego *re_ptr, cptr what, bool_ must) +{ + int i; + + /* Scan flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags1[i])) + { + if (must) re_ptr->flags1 |= (1L << i); + else re_ptr->hflags1 |= (1L << i); + return (0); + } + } + + /* Scan flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags2[i])) + { + if (must) re_ptr->flags2 |= (1L << i); + else re_ptr->hflags2 |= (1L << i); + return (0); + } + } + + /* Scan flags3 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags3[i])) + { + if (must) re_ptr->flags3 |= (1L << i); + else re_ptr->hflags3 |= (1L << i); + return (0); + } + } + + /* Scan flags7 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags7[i])) + { + if (must) re_ptr->flags7 |= (1L << i); + else re_ptr->hflags7 |= (1L << i); + return (0); + } + } + + /* Scan flags8 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags8[i])) + { + if (must) re_ptr->flags8 |= (1L << i); + else re_ptr->hflags8 |= (1L << i); + return (0); + } + } + + /* Scan flags9 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags9[i])) + { + if (must) re_ptr->flags9 |= (1L << i); + else re_ptr->hflags9 |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown monster flag '%s'.", what); + + /* Failure */ + return (1); +} + +/* + * Initialize the "re_info" array, by parsing an ascii "template" file + */ +errr init_re_info_txt(FILE *fp, char *buf) +{ + int i, j; + + byte blow_num = 0; + int r_char_number = 0, nr_char_number = 0; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + monster_ego *re_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Start the "fake" stuff */ + re_head->name_size = 0; + re_head->text_size = 0; + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= re_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + re_ptr = &re_info[i]; + + /* Hack -- Verify space */ + if (re_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!re_ptr->name) re_ptr->name = ++re_head->name_size; + + /* Append chars to the name */ + strcpy(re_name + re_head->name_size, s); + + /* Advance the index */ + re_head->name_size += strlen(s); + + /* Some inits */ + blow_num = 0; + r_char_number = 0; + nr_char_number = 0; + for (j = 0; j < 5; j++) re_ptr->r_char[j] = 0; + for (j = 0; j < 5; j++) re_ptr->nr_char[j] = 0; + for (j = 0; j < 4; j++) + { + re_ptr->blow[j].method = 0; + re_ptr->blow[j].effect = 0; + re_ptr->blow[j].d_dice = 0; + re_ptr->blow[j].d_side = 0; + re_ptr->blowm[j][0] = MEGO_ADD; + re_ptr->blowm[j][1] = MEGO_ADD; + } + + /* Next... */ + continue; + } + + /* There better be a current re_ptr */ + if (!re_ptr) return (3); + + /* Process 'G' for "Graphics" (one line only) */ + if (buf[0] == 'G') + { + char sym; + int tmp; + + /* Paranoia */ + if (!buf[2]) return (1); + if (!buf[3]) return (1); + if (!buf[4]) return (1); + + /* Extract the char */ + if (buf[2] != '*') sym = buf[2]; + else sym = MEGO_CHAR_ANY; + + /* Extract the attr */ + if (buf[4] != '*') tmp = color_char_to_attr(buf[4]); + else tmp = MEGO_CHAR_ANY; + + /* Paranoia */ + if (tmp < 0) return (1); + + /* Save the values */ + re_ptr->d_char = sym; + re_ptr->d_attr = tmp; + + /* Next... */ + continue; + } + + /* Process 'I' for "Info" (one line only) */ + if (buf[0] == 'I') + { + int spd, hp1, hp2, aaf, ac, slp; + char mspd, mhp1, mhp2, maaf, mac, mslp; + + /* Scan for the other values */ + if (12 != sscanf(buf + 2, "%c%d:%c%dd%c%d:%c%d:%c%d:%c%d", + &mspd, &spd, &mhp1, &hp1, &mhp2, &hp2, &maaf, &aaf, &mac, &ac, &mslp, &slp)) return (1); + + /* Save the values */ + re_ptr->speed = (spd << 2) + monster_ego_modify(mspd); + re_ptr->hdice = (hp1 << 2) + monster_ego_modify(mhp1); + re_ptr->hside = (hp2 << 2) + monster_ego_modify(mhp2); + re_ptr->aaf = (aaf << 2) + monster_ego_modify(maaf); + re_ptr->ac = (ac << 2) + monster_ego_modify(mac); + re_ptr->sleep = (slp << 2) + monster_ego_modify(mslp); + + /* Next... */ + continue; + } + + /* Process 'W' for "More Info" (one line only) */ + if (buf[0] == 'W') + { + int lev, rar, wt; + char mlev, mwt, mexp, pos; + long exp; + + /* Scan for the values */ + if (8 != sscanf(buf + 2, "%c%d:%d:%c%d:%c%ld:%c", + &mlev, &lev, &rar, &mwt, &wt, &mexp, &exp, &pos)) return (1); + + /* Save the values */ + re_ptr->level = (lev << 2) + monster_ego_modify(mlev); + re_ptr->rarity = rar; + re_ptr->weight = (wt << 2) + monster_ego_modify(mwt); + re_ptr->mexp = (exp << 2) + monster_ego_modify(mexp); + re_ptr->before = (pos == 'B') ? TRUE : FALSE; + + /* Next... */ + continue; + } + + /* Process 'B' for "Blows" (up to four lines) */ + if (buf[0] == 'B') + { + int n1, n2, dice, side; + char mdice, mside; + + /* Oops, no more slots */ + if (blow_num == 4) return (1); + + /* Analyze the first field */ + for (s = t = buf + 2; *t && (*t != ':'); t++) /* loop */; + + /* Terminate the field (if necessary) */ + if (*t == ':') *t++ = '\0'; + + /* Analyze the method */ + for (n1 = 0; r_info_blow_method[n1]; n1++) + { + if (streq(s, r_info_blow_method[n1])) break; + } + + /* Invalid method */ + if (!r_info_blow_method[n1]) return (1); + + /* Analyze the second field */ + for (s = t; *t && (*t != ':'); t++) /* loop */; + + /* Terminate the field (if necessary) */ + if (*t == ':') *t++ = '\0'; + + /* Analyze effect */ + for (n2 = 0; r_info_blow_effect[n2]; n2++) + { + if (streq(s, r_info_blow_effect[n2])) break; + } + + /* Invalid effect */ + if (!r_info_blow_effect[n2]) return (1); + + /* Save the method */ + re_ptr->blow[blow_num].method = n1; + + /* Save the effect */ + re_ptr->blow[blow_num].effect = n2; + + /* Extract the damage dice and sides */ + if (4 != sscanf(t, "%c%dd%c%d", + &mdice, &dice, &mside, &side)) return (1); + + re_ptr->blow[blow_num].d_dice = dice; + re_ptr->blow[blow_num].d_side = side; + re_ptr->blowm[blow_num][0] = monster_ego_modify(mdice); + re_ptr->blowm[blow_num][1] = monster_ego_modify(mside); + blow_num++; + + /* Next... */ + continue; + } + + /* Process 'F' for "Flags monster must have" (multiple lines) */ + if (buf[0] == 'F') + { + char r_char; + + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* XXX XXX XXX Hack -- Read monster symbols */ + if (1 == sscanf(s, "R_CHAR_%c", &r_char)) + { + /* Limited to 5 races */ + if (r_char_number >= 5) continue; + + /* Extract a "frequency" */ + re_ptr->r_char[r_char_number++] = r_char; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Parse this entry */ + if (0 != grab_one_ego_flag(re_ptr, s, TRUE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'H' for "Flags monster must not have" (multiple lines) */ + if (buf[0] == 'H') + { + char r_char; + + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* XXX XXX XXX Hack -- Read monster symbols */ + if (1 == sscanf(s, "R_CHAR_%c", &r_char)) + { + /* Limited to 5 races */ + if (nr_char_number >= 5) continue; + + /* Extract a "frequency" */ + re_ptr->nr_char[nr_char_number++] = r_char; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Parse this entry */ + if (0 != grab_one_ego_flag(re_ptr, s, FALSE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'M' for "Basic Monster Flags" (multiple lines) */ + if (buf[0] == 'M') + { + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_basic_ego_flag(re_ptr, s, TRUE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'O' for "Basic Monster -Flags" (multiple lines) */ + if (buf[0] == 'O') + { + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* XXX XXX XXX Hack -- Read no flags */ + if (!strcmp(s, "MF_ALL")) + { + /* No flags */ + re_ptr->nflags1 = re_ptr->nflags2 = re_ptr->nflags3 = re_ptr->nflags7 = re_ptr->nflags8 = re_ptr->nflags9 = 0xFFFFFFFF; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Parse this entry */ + if (0 != grab_one_basic_ego_flag(re_ptr, s, FALSE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'S' for "Spell Flags" (multiple lines) */ + if (buf[0] == 'S') + { + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* XXX XXX XXX Hack -- Read spell frequency */ + if (1 == sscanf(s, "1_IN_%d", &i)) + { + /* Extract a "frequency" */ + re_ptr->freq_spell = re_ptr->freq_inate = 100 / i; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Parse this entry */ + if (0 != grab_one_spell_ego_flag(re_ptr, s, TRUE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'T' for "Spell -Flags" (multiple lines) */ + if (buf[0] == 'T') + { + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* XXX XXX XXX Hack -- Read no flags */ + if (!strcmp(s, "MF_ALL")) + { + /* No flags */ + re_ptr->nflags4 = re_ptr->nflags5 = re_ptr->nflags6 = 0xFFFFFFFF; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Parse this entry */ + if (0 != grab_one_spell_ego_flag(re_ptr, s, FALSE)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++re_head->name_size; + + /* No version yet */ + if (!okay) return (2); + + /* Success */ + return (0); +} + + +/* + * Grab one flag in an trap_type from a textual string + */ +static errr grab_one_trap_type_flag(trap_type *t_ptr, cptr what) +{ + s16b i; + + /* Check flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, t_info_flags[i])) + { + t_ptr->flags |= (1L << i); + return (0); + } + } + /* Oops */ + msg_format("Unknown trap_type flag '%s'.", what); + + /* Error */ + return (1); +} + + +/* + * Initialize the "tr_info" array, by parsing an ascii "template" file + */ +errr init_t_info_txt(FILE *fp, char *buf) +{ + int i; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + trap_type *t_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Prepare the "fake" stuff */ + t_head->name_size = 0; + t_head->text_size = 0; + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i <= error_idx) return (4); + + /* Verify information */ + if (i >= t_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + t_ptr = &t_info[i]; + + /* Hack -- Verify space */ + if (t_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!t_ptr->name) t_ptr->name = ++t_head->name_size; + + /* Append chars to the name */ + strcpy(t_name + t_head->name_size, s); + + /* Advance the index */ + t_head->name_size += strlen(s); + + /* Next... */ + continue; + } + + /* There better be a current t_ptr */ + if (!t_ptr) return (3); + + + /* Process 'I' for "Information" */ + if (buf[0] == 'I') + { + int probability, another, p1valinc, difficulty; + int minlevel; + int dd, ds; + char color; + + /* Scan for the values */ + if (8 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%dd%d:%c", + &difficulty, &probability, &another, + &p1valinc, &minlevel, &dd, &ds, + &color)) return (1); + + t_ptr->difficulty = (byte)difficulty; + t_ptr->probability = (s16b)probability; + t_ptr->another = (s16b)another; + t_ptr->p1valinc = (s16b)p1valinc; + t_ptr->minlevel = (byte)minlevel; + t_ptr->dd = (s16b)dd; + t_ptr->ds = (s16b)ds; + t_ptr->color = color_char_to_attr(color); + + /* Next... */ + continue; + } + + + /* Process 'D' for "Description" */ + if (buf[0] == 'D') + { + /* Acquire the text */ + s = buf + 2; + + /* Hack -- Verify space */ + if (t_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!t_ptr->text) t_ptr->text = ++t_head->text_size; + + /* Append chars to the name */ + strcpy(t_text + t_head->text_size, s); + + /* Advance the index */ + t_head->text_size += strlen(s); + + /* Next... */ + continue; + } + + + /* Hack -- Process 'F' for flags */ + if (buf[0] == 'F') + { + + t_ptr->flags = 0; + + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_trap_type_flag(t_ptr, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++t_head->name_size; + ++t_head->text_size; + + + /* No version yet */ + if (!okay) return (2); + + + /* Success */ + return (0); +} + +/* + * Grab one flag for a dungeon type from a textual string + */ +errr grab_one_dungeon_flag(u32b *flags1, u32b *flags2, cptr what) +{ + int i; + + /* Scan flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, d_info_flags1[i])) + { + *flags1 |= (1L << i); + return (0); + } + } + + /* Scan flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, d_info_flags2[i])) + { + *flags2 |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown dungeon type flag '%s'.", what); + + /* Failure */ + return (1); +} + +/* + * Grab one (basic) flag in a monster_race from a textual string + */ +static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what, byte rule) +{ + int i; + + /* Scan flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags1[i])) + { + d_ptr->rules[rule].mflags1 |= (1L << i); + return (0); + } + } + + /* Scan flags2 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags2[i])) + { + d_ptr->rules[rule].mflags2 |= (1L << i); + return (0); + } + } + + /* Scan flags3 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags3[i])) + { + d_ptr->rules[rule].mflags3 |= (1L << i); + return (0); + } + } + + /* Scan flags7 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags7[i])) + { + d_ptr->rules[rule].mflags7 |= (1L << i); + return (0); + } + } + + /* Scan flags8 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags8[i])) + { + d_ptr->rules[rule].mflags8 |= (1L << i); + return (0); + } + } + + /* Scan flags9 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags9[i])) + { + d_ptr->rules[rule].mflags9 |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown monster flag '%s'.", what); + + /* Failure */ + return (1); +} + + +/* + * Grab one (spell) flag in a monster_race from a textual string + */ +static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what, byte rule) +{ + int i; + + /* Scan flags4 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags4[i])) + { + d_ptr->rules[rule].mflags4 |= (1L << i); + return (0); + } + } + + /* Scan flags5 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags5[i])) + { + d_ptr->rules[rule].mflags5 |= (1L << i); + return (0); + } + } + + /* Scan flags6 */ + for (i = 0; i < 32; i++) + { + if (streq(what, r_info_flags6[i])) + { + d_ptr->rules[rule].mflags6 |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown monster flag '%s'.", what); + + /* Failure */ + return (1); +} + +/* + * Initialize the "d_info" array, by parsing an ascii "template" file + */ +errr init_d_info_txt(FILE *fp, char *buf) +{ + int i, j; + + s16b rule_num = 0; + + byte r_char_number = 0; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + dungeon_info_type *d_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Start the "fake" stuff */ + d_head->name_size = 0; + d_head->text_size = 0; + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= d_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + d_ptr = &d_info[i]; + + /* Hack -- Verify space */ + if (d_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!d_ptr->name) d_ptr->name = ++d_head->name_size; + + /* Append chars to the name */ + strcpy(d_name + d_head->name_size, s); + + /* Advance the index */ + d_head->name_size += strlen(s); + + /* HACK -- Those ones HAVE to have a set default value */ + d_ptr->size_x = -1; + d_ptr->size_y = -1; + d_ptr->ix = -1; + d_ptr->iy = -1; + d_ptr->ox = -1; + d_ptr->oy = -1; + d_ptr->fill_method = 1; + rule_num = -1; + r_char_number = 0; + for (j = 0; j < 5; j++) + { + int k; + + d_ptr->rules[j].mode = DUNGEON_MODE_NONE; + d_ptr->rules[j].percent = 0; + + for (k = 0; k < 5; k++) d_ptr->rules[j].r_char[k] = 0; + } + + /* HACK -- Those ones HAVE to have a set default value */ + d_ptr->objs.treasure = OBJ_GENE_TREASURE; + d_ptr->objs.combat = OBJ_GENE_COMBAT; + d_ptr->objs.magic = OBJ_GENE_MAGIC; + d_ptr->objs.tools = OBJ_GENE_TOOL; + + /* The default generator */ + strcpy(d_ptr->generator, "dungeon"); + + /* Next... */ + continue; + } + + /* There better be a current d_ptr */ + if (!d_ptr) return (3); + + /* Process 'D' for "Description */ + if (buf[0] == 'D') + { + /* Acquire short name */ + d_ptr->short_name[0] = buf[2]; + d_ptr->short_name[1] = buf[3]; + d_ptr->short_name[2] = buf[4]; + + /* Acquire the text */ + s = buf + 6; + + /* Hack -- Verify space */ + if (d_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!d_ptr->text) d_ptr->text = ++d_head->text_size; + + /* Append chars to the name */ + strcpy(d_text + d_head->text_size, s); + + /* Advance the index */ + d_head->text_size += strlen(s); + + /* Next... */ + continue; + } + + /* Process 'W' for "More Info" (one line only) */ + if (buf[0] == 'W') + { + int min_lev, max_lev; + int min_plev, next; + int min_alloc, max_chance; + + /* Scan for the values */ + if (6 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d", + &min_lev, &max_lev, &min_plev, &next, &min_alloc, &max_chance)) return (1); + + /* Save the values */ + d_ptr->mindepth = min_lev; + d_ptr->maxdepth = max_lev; + d_ptr->min_plev = min_plev; + d_ptr->next = next; + d_ptr->min_m_alloc_level = min_alloc; + d_ptr->max_m_alloc_chance = max_chance; + + /* Next... */ + continue; + } + + /* Process 'L' for "fLoor type" (one line only) */ + if (buf[0] == 'L') + { + int f1, f2, f3; + int p1, p2, p3; + int i; + + /* Scan for the values */ + if (6 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d", + &f1, &p1, &f2, &p2, &f3, &p3)) + { + /* Scan for the values - part ii*/ + if (3 != sscanf(buf + 2, "%d:%d:%d", &p1, &p2, + &p3)) return (1); + + /* Save the values */ + d_ptr->floor_percent1[1] = p1; + d_ptr->floor_percent2[1] = p2; + d_ptr->floor_percent3[1] = p3; + + continue; + } + + /* Save the values */ + d_ptr->floor1 = f1; + d_ptr->floor2 = f2; + d_ptr->floor3 = f3; + + for (i = 0; i < 2; i++) + { + d_ptr->floor_percent1[i] = p1; + d_ptr->floor_percent2[i] = p2; + d_ptr->floor_percent3[i] = p3; + } + + /* Next... */ + continue; + } + + /* Process 'O' for "Object type" (one line only) */ + if (buf[0] == 'O') + { + int treasure, combat, magic, tools; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%d:%d", + &treasure, &combat, &magic, &tools)) return (1); + + /* Save the values */ + d_ptr->objs.treasure = treasure; + d_ptr->objs.combat = combat; + d_ptr->objs.magic = magic; + d_ptr->objs.tools = tools; + + /* Next... */ + continue; + } + + /* Process 'G' for "Generator" (one line only) */ + if (buf[0] == 'G') + { + strnfmt(d_ptr->generator, 30, "%s", buf + 2); + + /* Next... */ + continue; + } + + /* Process 'A' for "wAll type" (one line only) */ + if (buf[0] == 'A') + { + int w1, w2, w3, outer, inner; + int p1, p2, p3; + int i; + + /* Scan for the values */ + if (8 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d", + &w1, &p1, &w2, &p2, &w3, &p3, &outer, &inner)) + { + /* Scan for the values - part ii*/ + if (3 != sscanf(buf + 2, "%d:%d:%d", &p1, &p2, + &p3)) return (1); + + /* Save the values */ + d_ptr->fill_percent1[1] = p1; + d_ptr->fill_percent2[1] = p2; + d_ptr->fill_percent3[1] = p3; + continue; + } + + /* Save the values */ + d_ptr->fill_type1 = w1; + d_ptr->fill_type2 = w2; + d_ptr->fill_type3 = w3; + + for (i = 0; i < 2; i++) + { + d_ptr->fill_percent1[i] = p1; + d_ptr->fill_percent2[i] = p2; + d_ptr->fill_percent3[i] = p3; + } + + d_ptr->outer_wall = outer; + d_ptr->inner_wall = inner; + + /* Next... */ + continue; + } + + /* Process 'E' for "Effects" (up to four lines) -SC- */ + if (buf[0] == 'E') + { + int side, dice, freq, type; + cptr tmp; + + /* Find the next empty blow slot (if any) */ + for (i = 0; i < 4; i++) if ((!d_ptr->d_side[i]) && + (!d_ptr->d_dice[i])) break; + + /* Oops, no more slots */ + if (i == 4) return (1); + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%dd%d:%d:%d", + &dice, &side, &freq, &type)) + { + int j; + + if (3 != sscanf(buf + 2, "%dd%d:%d", + &dice, &side, &freq)) return (1); + + tmp = buf + 2; + for (j = 0; j < 2; j++) + { + tmp = strchr(tmp, ':'); + if (tmp == NULL) return (1); + tmp++; + } + + j = 0; + + while (d_info_dtypes[j].name != NULL) + if (strcmp(d_info_dtypes[j].name, tmp) == 0) + { + d_ptr->d_type[i] = d_info_dtypes[j].feat; + break; + } + else j++; + + if (d_info_dtypes[j].name == NULL) return (1); + } + else + d_ptr->d_type[i] = type; + + freq *= 10; + /* Save the values */ + d_ptr->d_side[i] = side; + d_ptr->d_dice[i] = dice; + d_ptr->d_frequency[i] = freq; + + /* Next... */ + continue; + } + + /* Process 'F' for "Dungeon Flags" (multiple lines) */ + if (buf[0] == 'F') + { + int artif = 0, monst = 0, obj = 0; + int ix = -1, iy = -1, ox = -1, oy = -1; + int fill_method; + + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Read dungeon in/out coords */ + if (4 == sscanf(s, "WILD_%d_%d__%d_%d", &ix, &iy, &ox, &oy)) + { + d_ptr->ix = ix; + d_ptr->iy = iy; + d_ptr->ox = ox; + d_ptr->oy = oy; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Read dungeon size */ + if (2 == sscanf(s, "SIZE_%d_%d", &ix, &iy)) + { + d_ptr->size_x = ix; + d_ptr->size_y = iy; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Read dungeon fill method */ + if (1 == sscanf(s, "FILL_METHOD_%d", &fill_method)) + { + d_ptr->fill_method = fill_method; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Read Final Object */ + if (1 == sscanf(s, "FINAL_OBJECT_%d", &obj)) + { + /* Extract a "Final Artifact" */ + d_ptr->final_object = obj; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Read Final Artifact */ + if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif )) + { + /* Extract a "Final Artifact" */ + d_ptr->final_artifact = artif ; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Read Artifact Guardian */ + if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst)) + { + /* Extract a "Artifact Guardian" */ + d_ptr->final_guardian = monst; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Parse this entry */ + if (0 != grab_one_dungeon_flag(&(d_ptr->flags1), &(d_ptr->flags2), s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'R' for "monster generation Rule" (up to 5 lines) */ + if (buf[0] == 'R') + { + int percent, mode; + int z, y, lims[5]; + + /* Scan for the values */ + if (2 != sscanf(buf + 2, "%d:%d", + &percent, &mode)) return (1); + + /* Save the values */ + r_char_number = 0; + rule_num++; + + d_ptr->rules[rule_num].percent = percent; + d_ptr->rules[rule_num].mode = mode; + + /* Lets remap the flat percents */ + lims[0] = d_ptr->rules[0].percent; + for (y = 1; y <= rule_num; y++) + { + lims[y] = lims[y - 1] + d_ptr->rules[y].percent; + } + for (z = 0; z < 100; z++) + { + for (y = rule_num; y >= 0; y--) + { + if (z < lims[y]) d_ptr->rule_percents[z] = y; + } + } + + /* Next... */ + continue; + } + + /* Process 'M' for "Basic Flags" (multiple lines) */ + if (buf[0] == 'M') + { + byte r_char; + + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Read monster symbols */ + if (1 == sscanf(s, "R_CHAR_%c", &r_char)) + { + /* Limited to 5 races */ + if (r_char_number >= 5) continue; + + /* Extract a "frequency" */ + d_ptr->rules[rule_num].r_char[r_char_number++] = r_char; + + /* Start at next entry */ + s = t; + + /* Continue */ + continue; + } + + /* Parse this entry */ + if (0 != grab_one_basic_monster_flag(d_ptr, s, rule_num)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'S' for "Spell Flags" (multiple lines) */ + if (buf[0] == 'S') + { + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while ((*t == ' ') || (*t == '|')) t++; + } + + /* Parse this entry */ + if (0 != grab_one_spell_monster_flag(d_ptr, s, rule_num)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++d_head->name_size; + ++d_head->text_size; + + /* No version yet */ + if (!okay) return (2); + + /* Success */ + return (0); +} + +/* + * Grab one race flag from a textual string + */ +static errr grab_one_race_flag(owner_type *ow_ptr, int state, cptr what) +{ + /* int i; + cptr s; */ + + /* Scan race flags */ + unknown_shut_up = TRUE; + if (!grab_one_race_allow_flag(ow_ptr->races[state], what)) + { + unknown_shut_up = FALSE; + return (0); + } + + /* Scan classes flags */ + if (!grab_one_class_flag(ow_ptr->classes[state], what)) + { + unknown_shut_up = FALSE; + return (0); + } + + /* Oops */ + unknown_shut_up = FALSE; + msg_format("Unknown race/class flag '%s'.", what); + + /* Failure */ + return (1); +} + +/* + * Grab one store flag from a textual string + */ +static errr grab_one_store_flag(store_info_type *st_ptr, cptr what) +{ + int i; + + /* Scan store flags */ + for (i = 0; i < 32; i++) + { + if (streq(what, st_info_flags1[i])) + { + st_ptr->flags1 |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown store flag '%s'.", what); + + /* Failure */ + return (1); +} + +/* + * Initialize the "st_info" array, by parsing an ascii "template" file + */ +errr init_st_info_txt(FILE *fp, char *buf) +{ + int i = 0, item_idx = 0; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + store_info_type *st_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Start the "fake" stuff */ + st_head->name_size = 0; + st_head->text_size = 0; + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= st_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + st_ptr = &st_info[i]; + + /* Hack -- Verify space */ + if (st_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!st_ptr->name) st_ptr->name = ++st_head->name_size; + + /* Append chars to the name */ + strcpy(st_name + st_head->name_size, s); + + /* Advance the index */ + st_head->name_size += strlen(s); + + /* We are ready for a new set of objects */ + item_idx = 0; + + /* Next... */ + continue; + } + + /* There better be a current st_ptr */ + if (!st_ptr) return (3); + + /* Process 'I' for "Items" (multiple lines) */ + if (buf[0] == 'I') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + st_ptr->table[item_idx][1] = atoi(buf + 2); + + /* Append chars to the name */ + st_ptr->table[item_idx++][0] = test_item_name(s); + + st_ptr->table_num = item_idx; + + /* Next... */ + continue; + } + + /* Process 'T' for "Tval/sval" */ + if (buf[0] == 'T') + { + int tv1, sv1, rar1; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d:%d:%d", + &rar1, &tv1, &sv1)) return (1); + + /* Get the index */ + st_ptr->table[item_idx][1] = rar1; + /* Hack -- 256 as a sval means all possible items */ + st_ptr->table[item_idx++][0] = (sv1 < 256) ? lookup_kind(tv1, sv1) : tv1 + 10000; + + st_ptr->table_num = item_idx; + + /* Next... */ + continue; + } + + /* Process 'G' for "Graphics" one line only) */ + if (buf[0] == 'G') + { + char c, a; + int attr; + + /* Scan for the values */ + if (2 != sscanf(buf + 2, "%c:%c", + &c, &a)) return (1); + + /* Extract the color */ + attr = color_char_to_attr(a); + + /* Paranoia */ + if (attr < 0) return (1); + + /* Save the values */ + st_ptr->d_char = c; + st_ptr->d_attr = attr; + + /* Next... */ + continue; + } + + /* Process 'A' for "Actions" (one line only) */ + if (buf[0] == 'A') + { + int a1, a2, a3, a4, a5, a6; + + /* Scan for the values */ + if (6 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d", + &a1, &a2, &a3, &a4, &a5, &a6)) return (1); + + /* Save the values */ + st_ptr->actions[0] = a1; + st_ptr->actions[1] = a2; + st_ptr->actions[2] = a3; + st_ptr->actions[3] = a4; + st_ptr->actions[4] = a5; + st_ptr->actions[5] = a6; + + /* Next... */ + continue; + } + + /* Process 'F' for "store Flags" (multiple lines) */ + if (buf[0] == 'F') + { + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_store_flag(st_ptr, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Process 'O' for "Owners" (one line only) */ + if (buf[0] == 'O') + { + int a1, a2, a3, a4; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%d:%d", + &a1, &a2, &a3, &a4)) return (1); + + /* Save the values */ + st_ptr->owners[0] = a1; + st_ptr->owners[1] = a2; + st_ptr->owners[2] = a3; + st_ptr->owners[3] = a4; + + /* Next... */ + continue; + } + + /* Process 'W' for "Extra info" (one line only) */ + if (buf[0] == 'W') + { + int max_obj; + + /* Scan for the values */ + if (1 != sscanf(buf + 2, "%d", + &max_obj)) return (1); + + /* Save the values */ + if (max_obj > STORE_INVEN_MAX) max_obj = STORE_INVEN_MAX; + st_ptr->max_obj = max_obj; + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++st_head->name_size; + ++st_head->text_size; + + /* No version yet */ + if (!okay) return (2); + + /* Success */ + return (0); +} + +/* + * Initialize the "ba_info" array, by parsing an ascii "template" file + */ +errr init_ba_info_txt(FILE *fp, char *buf) +{ + int i = 0; + + char *s; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + store_action_type *ba_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Start the "fake" stuff */ + ba_head->name_size = 0; + ba_head->text_size = 0; + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= ba_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + ba_ptr = &ba_info[i]; + + /* Hack -- Verify space */ + if (ba_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!ba_ptr->name) ba_ptr->name = ++ba_head->name_size; + + /* Append chars to the name */ + strcpy(ba_name + ba_head->name_size, s); + + /* Advance the index */ + ba_head->name_size += strlen(s); + + /* Next... */ + continue; + } + + /* There better be a current ba_ptr */ + if (!ba_ptr) return (3); + + /* Process 'C' for "Costs" (one line only) */ + if (buf[0] == 'C') + { + int ch, cn, cl; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d:%d:%d", + &ch, &cn, &cl)) return (1); + + /* Save the values */ + ba_ptr->costs[STORE_HATED] = ch; + ba_ptr->costs[STORE_NORMAL] = cn; + ba_ptr->costs[STORE_LIKED] = cl; + + /* Next... */ + continue; + } + + /* Process 'I' for "Infos" (one line only) */ + if (buf[0] == 'I') + { + int act, act_res; + char letter, letter_aux = 0; + + /* Scan for the values */ + if (4 != sscanf(buf + 2, "%d:%d:%c:%c", &act, &act_res, &letter, &letter_aux)) + if (3 != sscanf(buf + 2, "%d:%d:%c", &act, &act_res, &letter)) + return (1); + + /* Save the values */ + ba_ptr->action = act; + ba_ptr->action_restr = act_res; + ba_ptr->letter = letter; + ba_ptr->letter_aux = letter_aux; + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++ba_head->name_size; + ++ba_head->text_size; + + /* No version yet */ + if (!okay) return (2); + + /* Success */ + return (0); +} + +/* + * Initialize the "ow_info" array, by parsing an ascii "template" file + */ +errr init_ow_info_txt(FILE *fp, char *buf) +{ + int i; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + owner_type *ow_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Start the "fake" stuff */ + ow_head->name_size = 0; + ow_head->text_size = 0; + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= ow_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + ow_ptr = &ow_info[i]; + + /* Hack -- Verify space */ + if (ow_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!ow_ptr->name) ow_ptr->name = ++ow_head->name_size; + + /* Append chars to the name */ + strcpy(ow_name + ow_head->name_size, s); + + /* Advance the index */ + ow_head->name_size += strlen(s); + + /* Next... */ + continue; + } + + /* There better be a current ow_ptr */ + if (!ow_ptr) return (3); + + + /* Process 'C' for "Costs" (one line only) */ + if (buf[0] == 'C') + { + int ch, cn, cl; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d:%d:%d", + &ch, &cn, &cl)) return (1); + + /* Save the values */ + ow_ptr->costs[STORE_HATED] = ch; + ow_ptr->costs[STORE_NORMAL] = cn; + ow_ptr->costs[STORE_LIKED] = cl; + + /* Next... */ + continue; + } + + /* Process 'I' for "Info" (multiple lines line only) */ + if (buf[0] == 'I') + { + int cost, inf; + + /* Scan for the values */ + if (2 != sscanf(buf + 2, "%d:%d", + &cost, &inf)) return (1); + + /* Save the values */ + ow_ptr->max_cost = cost; + ow_ptr->inflation = inf; + + /* Next... */ + continue; + } + + /* Process 'L' for "Liked races/classes" (multiple lines) */ + if (buf[0] == 'L') + { + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_race_flag(ow_ptr, STORE_LIKED, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + /* Process 'H' for "Hated races/classes" (multiple lines) */ + if (buf[0] == 'H') + { + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_race_flag(ow_ptr, STORE_HATED, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++ow_head->name_size; + ++ow_head->text_size; + + /* No version yet */ + if (!okay) return (2); + + /* Success */ + return (0); +} + +/* + * Grab one flag for a dungeon type from a textual string + */ +static errr grab_one_wf_info_flag(wilderness_type_info *wf_ptr, cptr what) +{ + int i; + + /* Scan flags1 */ + for (i = 0; i < 32; i++) + { + if (streq(what, wf_info_flags1[i])) + { + wf_ptr->flags1 |= (1L << i); + return (0); + } + } + + /* Oops */ + msg_format("Unknown monster flag '%s'.", what); + + /* Failure */ + return (1); +} + +/* + * Initialize the "wf_info" array, by parsing an ascii "template" file + */ +errr init_wf_info_txt(FILE *fp, char *buf) +{ + int i; + + char *s, *t; + + /* Not ready yet */ + bool_ okay = FALSE; + + /* Current entry */ + wilderness_type_info *wf_ptr = NULL; + + + /* Just before the first record */ + error_idx = -1; + + /* Just before the first line */ + error_line = -1; + + + /* Start the "fake" stuff */ + wf_head->name_size = 0; + wf_head->text_size = 0; + + /* Parse */ + fp_stack_init(fp); + while (0 == my_fgets_dostack(buf, 1024)) + { + /* Advance the line number */ + error_line++; + + /* Skip comments and blank lines */ + if (!buf[0] || (buf[0] == '#')) continue; + + /* Verify correct "colon" format */ + if (buf[1] != ':') return (1); + + + /* Hack -- Process 'V' for "Version" */ + if (buf[0] == 'V') + { + int v1, v2, v3; + + /* Scan for the values */ + if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); + + /* Okay to proceed */ + okay = TRUE; + + /* Continue */ + continue; + } + + /* No version yet */ + if (!okay) return (2); + + /* Included file */ + if (buf[0] == '<') + { + fp_stack_push(buf + 2); + continue; + } + + /* Process 'N' for "New/Number/Name" */ + if (buf[0] == 'N') + { + /* Find the colon before the name */ + s = strchr(buf + 2, ':'); + + /* Verify that colon */ + if (!s) return (1); + + /* Nuke the colon, advance to the name */ + *s++ = '\0'; + + /* Paranoia -- require a name */ + if (!*s) return (1); + + /* Get the index */ + i = atoi(buf + 2); + + /* Verify information */ + if (i < error_idx) return (4); + + /* Verify information */ + if (i >= wf_head->info_num) return (2); + + /* Save the index */ + error_idx = i; + + /* Point at the "info" */ + wf_ptr = &wf_info[i]; + + /* Hack -- Verify space */ + if (wf_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); + + /* Advance and Save the name index */ + if (!wf_ptr->name) wf_ptr->name = ++wf_head->name_size; + + /* Append chars to the name */ + strcpy(wf_name + wf_head->name_size, s); + + /* Advance the index */ + wf_head->name_size += strlen(s); + + /* Next... */ + continue; + } + + /* There better be a current wf_ptr */ + if (!wf_ptr) return (3); + + /* Process 'D' for "Description */ + if (buf[0] == 'D') + { + /* Acquire the text */ + s = buf + 2; + + /* Hack -- Verify space */ + if (wf_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + + /* Advance and Save the text index */ + if (!wf_ptr->text) wf_ptr->text = ++wf_head->text_size; + + /* Append chars to the name */ + strcpy(wf_text + wf_head->text_size, s); + + /* Advance the index */ + wf_head->text_size += strlen(s); + + /* Next... */ + continue; + } + + /* Process 'W' for "More Info" (one line only) */ + if (buf[0] == 'W') + { + int entrance, level; + int road, feat, ter_idx; + char car; + + /* Scan for the values */ + if (6 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%c", + &level, &entrance, &road, &feat, &ter_idx, &car)) return (1); + + /* Save the values */ + wf_ptr->level = level; + wf_ptr->entrance = entrance; + wf_ptr->road = road; + wf_ptr->feat = feat; + wf_ptr->terrain_idx = ter_idx; + + /* To acces it easily from the map structure */ + wildc2i[(int)car] = error_idx; + + /* Next... */ + continue; + } + + /* Process 'X' for "More Info" (one line only) */ + if (buf[0] == 'X') + { + int terrain[MAX_WILD_TERRAIN], i; + + /* Scan for the values */ + if (MAX_WILD_TERRAIN != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", + &terrain[0], &terrain[1], &terrain[2], + &terrain[3], &terrain[4], &terrain[5], + &terrain[6], &terrain[7], &terrain[8], + &terrain[9], &terrain[10], &terrain[11], + &terrain[12], &terrain[13], &terrain[14], + &terrain[15], &terrain[16], &terrain[17])) return (1); + + /* Save the values */ + for (i = 0; i < MAX_WILD_TERRAIN; i++) + { + wf_ptr->terrain[i] = terrain[i]; + } + + /* Next... */ + continue; + } + + /* Process 'F' for "Wilderness feature Flags" (multiple lines) */ + if (buf[0] == 'F') + { + /* Parse every entry */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_wf_info_flag(wf_ptr, s)) return (5); + + /* Start the next entry */ + s = t; + } + + /* Next... */ + continue; + } + + /* Oops */ + return (6); + } + + + /* Complete the "name" and "text" sizes */ + ++wf_head->name_size; + ++wf_head->text_size; + + /* No version yet */ + if (!okay) return (2); + + /* Success */ + return (0); +} + + +/* Random dungeon grid effects */ +#define RANDOM_NONE 0x00 +#define RANDOM_FEATURE 0x01 +#define RANDOM_MONSTER 0x02 +#define RANDOM_OBJECT 0x04 +#define RANDOM_EGO 0x08 +#define RANDOM_ARTIFACT 0x10 +#define RANDOM_TRAP 0x20 + + +typedef struct dungeon_grid dungeon_grid; + +struct dungeon_grid +{ + int feature; /* Terrain feature */ + int monster; /* Monster */ + int object; /* Object */ + int ego; /* Ego-Item */ + int artifact; /* Artifact */ + int trap; /* Trap */ + int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */ + int special; /* Reserved for special terrain info */ + int random; /* Number of the random effect */ + int bx, by; /* For between gates */ + int mimic; /* Mimiced features */ + s32b mflag; /* monster's mflag */ + bool_ ok; + bool_ defined; +}; +static bool_ meta_sleep = TRUE; + +static dungeon_grid letter[255]; + +/* + * Parse a sub-file of the "extra info" + */ +static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalstart, int ymax, int xmax, bool_ full) +{ + int i; + + char *zz[33]; + + + /* Skip "empty" lines */ + if (!buf[0]) return (0); + + /* Skip "blank" lines */ + if (isspace(buf[0])) return (0); + + /* Skip comments */ + if (buf[0] == '#') return (0); + + /* Require "?:*" format */ + if (buf[1] != ':') return (1); + + + /* Process "%:" */ + if (buf[0] == '%') + { + /* Attempt to Process the given file */ + return (process_dungeon_file(buf + 2, yval, xval, ymax, xmax, FALSE, full)); + } + + /* Process "N:" */ + if (buf[0] == 'N') + { + int num; + + if ((num = tokenize(buf + 2, 1, zz, ':', '/')) > 0) + { + meta_sleep = atoi(zz[0]); + } + + return (0); + } + + /* Process "F:::::::::::" -- info for dungeon grid */ + if (buf[0] == 'F') + { + int num; + + if ((num = tokenize(buf + 2, 11, zz, ':', '/')) > 1) + { + int index = zz[0][0]; + + /* Reset the feature */ + letter[index].feature = 0; + letter[index].monster = 0; + letter[index].object = 0; + letter[index].ego = 0; + letter[index].artifact = 0; + letter[index].trap = 0; + letter[index].cave_info = 0; + letter[index].special = 0; + letter[index].random = 0; + letter[index].mimic = 0; + letter[index].mflag = 0; + letter[index].ok = TRUE; + letter[index].defined = TRUE; + + if (num > 1) + { + if (zz[1][0] == '*') + { + letter[index].random |= RANDOM_FEATURE; + if (zz[1][1]) + { + zz[1]++; + letter[index].feature = atoi(zz[1]); + } + } + else + { + letter[index].feature = atoi(zz[1]); + } + } + + if (num > 2) + letter[index].cave_info = atoi(zz[2]); + + /* Monster */ + if (num > 3) + { + if (zz[3][0] == '*') + { + letter[index].random |= RANDOM_MONSTER; + if (zz[3][1]) + { + zz[3]++; + letter[index].monster = atoi(zz[3]); + } + } + else + { + letter[index].monster = atoi(zz[3]); + } + } + + /* Object */ + if (num > 4) + { + if (zz[4][0] == '*') + { + letter[index].random |= RANDOM_OBJECT; + + if (zz[4][1]) + { + zz[4]++; + letter[index].object = atoi(zz[4]); + } + } + else + { + letter[index].object = atoi(zz[4]); + } + } + + /* Ego-Item */ + if (num > 5) + { + if (zz[5][0] == '*') + { + letter[index].random |= RANDOM_EGO; + + if (zz[5][1]) + { + zz[5]++; + letter[index].ego = atoi(zz[5]); + } + } + else + { + letter[index].ego = atoi(zz[5]); + } + } + + /* Artifact */ + if (num > 6) + { + if (zz[6][0] == '*') + { + letter[index].random |= RANDOM_ARTIFACT; + + if (zz[6][1]) + { + zz[6]++; + letter[index].artifact = atoi(zz[6]); + } + } + else + { + letter[index].artifact = atoi(zz[6]); + } + } + + if (num > 7) + { + if (zz[7][0] == '*') + { + letter[index].random |= RANDOM_TRAP; + + if (zz[7][1]) + { + zz[7]++; + letter[index].trap = atoi(zz[7]); + } + } + else + letter[index].trap = atoi(zz[7]); + } + + if (num > 8) + { + /* Quests can be defined by name only */ + if (zz[8][0] == '"') + { + int i; + + /* Hunt & shoot the ending " */ + i = strlen(zz[8]) - 1; + if (zz[8][i] == '"') zz[8][i] = '\0'; + letter[index].special = 0; + for (i = 0; i < MAX_Q_IDX; i++) + { + if (!strcmp(&zz[8][1], quest[i].name)) + { + letter[index].special = i; + break; + } + } + } + else + letter[index].special = atoi(zz[8]); + } + + if (num > 9) + { + letter[index].mimic = atoi(zz[9]); + } + + if (num > 10) + { + letter[index].mflag = atoi(zz[10]); + } + + return (0); + } + } + + /* Process "f:flags" -- level flags */ + else if (buf[0] == 'f') + { + char *s, *t; + + /* Parse every entry textually */ + for (s = buf + 2; *s; ) + { + /* Find the end of this entry */ + for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + + /* Nuke and skip any dividers */ + if (*t) + { + *t++ = '\0'; + while (*t == ' ' || *t == '|') t++; + } + + /* Parse this entry */ + if (0 != grab_one_dungeon_flag(&dungeon_flags1, &dungeon_flags2, s)) return 1; + + /* Start the next entry */ + s = t; + } + + return 0; + } + + /* Process "D:" -- info for the cave grids */ + else if (buf[0] == 'D') + { + int x, m_idx = 0; + + object_type object_type_body; + + /* Acquire the text */ + char *s = buf + 2; + + /* Length of the text */ + int len = strlen(s); + + int y = *yval; + *xval = xvalstart; + for (x = *xval, i = 0; ((x < xmax) && (i < len)); x++, s++, i++) + { + /* Access the grid */ + cave_type *c_ptr = &cave[y][x]; + + int idx = s[0]; + + int object_index = letter[idx].object; + int monster_index = letter[idx].monster; + int random = letter[idx].random; + int artifact_index = letter[idx].artifact; + + if (!letter[idx].ok) msg_format("Warning '%c' not defined but used.", idx); + + if (init_flags & INIT_GET_SIZE) continue; + + /* use the plasma generator wilderness */ + if (((!dun_level) || (!letter[idx].defined)) && (idx == ' ')) continue; + + /* Clear some info */ + c_ptr->info = 0; + + /* Lay down a floor */ + c_ptr->mimic = letter[idx].mimic; + cave_set_feat(y, x, letter[idx].feature); + + /* Cave info */ + c_ptr->info |= letter[idx].cave_info; + + /* Create a monster */ + if (random & RANDOM_MONSTER) + { + int level = monster_level; + + monster_level = quest[p_ptr->inside_quest].level + monster_index; + + m_idx = place_monster(y, x, meta_sleep, FALSE); + + monster_level = level; + } + else if (monster_index) + { + /* Place it */ + m_allow_special[monster_index] = TRUE; + m_idx = place_monster_aux(y, x, monster_index, meta_sleep, FALSE, MSTATUS_ENEMY); + m_allow_special[monster_index] = FALSE; + } + + /* Set the mflag of the monster */ + if (m_idx) m_list[m_idx].mflag |= letter[idx].mflag; + + /* Object (and possible trap) */ + if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP)) + { + int level = object_level; + + object_level = quest[p_ptr->inside_quest].level; + + /* + * Random trap and random treasure defined + * 25% chance for trap and 75% chance for object + */ + if (rand_int(100) < 75) + { + place_object(y, x, FALSE, FALSE, OBJ_FOUND_SPECIAL); + } + else + { + place_trap(y, x); + } + + object_level = level; + } + else if (random & RANDOM_OBJECT) + { + /* Create an out of deep object */ + if (object_index) + { + int level = object_level; + + object_level = quest[p_ptr->inside_quest].level + object_index; + if (rand_int(100) < 75) + place_object(y, x, FALSE, FALSE, OBJ_FOUND_SPECIAL); + else if (rand_int(100) < 80) + place_object(y, x, TRUE, FALSE, OBJ_FOUND_SPECIAL); + else + place_object(y, x, TRUE, TRUE, OBJ_FOUND_SPECIAL); + + object_level = level; + } + else if (rand_int(100) < 75) + { + place_object(y, x, FALSE, FALSE, OBJ_FOUND_SPECIAL); + } + else if (rand_int(100) < 80) + { + place_object(y, x, TRUE, FALSE, OBJ_FOUND_SPECIAL); + } + else + { + place_object(y, x, TRUE, TRUE, OBJ_FOUND_SPECIAL); + } + } + /* Random trap */ + else if (random & RANDOM_TRAP) + { + place_trap(y, x); + } + else if (object_index) + { + /* Get local object */ + object_type *o_ptr = &object_type_body; + + k_allow_special[object_index] = TRUE; + + /* Create the item */ + object_prep(o_ptr, object_index); + + /* Apply magic (no messages, no artifacts) */ + apply_magic(o_ptr, dun_level, FALSE, TRUE, FALSE); + + o_ptr->found = OBJ_FOUND_SPECIAL; + + k_allow_special[object_index] = FALSE; + + drop_near(o_ptr, -1, y, x); + } + + /* Artifact */ + if (artifact_index) + { + int I_kind = 0; + + artifact_type *a_ptr = &a_info[artifact_index]; + + object_type forge; + + /* Get local object */ + object_type *q_ptr = &forge; + + a_allow_special[artifact_index] = TRUE; + + /* Wipe the object */ + object_wipe(q_ptr); + + /* Acquire the "kind" index */ + I_kind = lookup_kind(a_ptr->tval, a_ptr->sval); + + /* Create the artifact */ + object_prep(q_ptr, I_kind); + + /* Save the name */ + q_ptr->name1 = artifact_index; + + /* Extract the fields */ + q_ptr->pval = a_ptr->pval; + q_ptr->ac = a_ptr->ac; + q_ptr->dd = a_ptr->dd; + q_ptr->ds = a_ptr->ds; + q_ptr->to_a = a_ptr->to_a; + q_ptr->to_h = a_ptr->to_h; + q_ptr->to_d = a_ptr->to_d; + q_ptr->weight = a_ptr->weight; + q_ptr->found = OBJ_FOUND_SPECIAL; + + random_artifact_resistance(q_ptr); + + a_info[artifact_index].cur_num = 1; + + a_allow_special[artifact_index] = FALSE; + + /* It's amazing that this "creating objects anywhere" + junk ever worked. + Let's just HACK around one observed bug: Shadow Cloak + of Luthien [Globe of Light] */ + { + u32b f1, f2, f3, f4, f5, esp; + object_flags(q_ptr, &f1, &f2, &f3, &f4, &f5, &esp); + if (f5 & TR5_SPELL_CONTAIN) + q_ptr->pval2 = -1; + } + + /* Drop the artifact */ + drop_near(q_ptr, -1, y, x); + + } + + /* Terrain special */ + if (letter[idx].special == -1) + { + if (!letter[idx].bx) + { + letter[idx].bx = x; + letter[idx].by = y; + } + else + { + c_ptr->special = (letter[idx].by << 8) + letter[idx].bx; + cave[letter[idx].by][letter[idx].bx].special = (y << 8) + x; + } + } + else + { + c_ptr->special = letter[idx].special; + } + } + if (full && (*xval < x)) *xval = x; + (*yval)++; + + return (0); + } + + /* Process "W:: ..." -- info for the wilderness */ + else if (buf[0] == 'W') + { + /* Process "W:D: */ + /* Layout of the wilderness */ + if (buf[2] == 'D') + { + int x; + char i; + + /* Acquire the text */ + char *s = buf + 4; + + int y = *yval; + + for (x = 0; x < max_wild_x; x++) + { + if (1 != sscanf(s + x, "%c", &i)) return (1); + wild_map[y][x].feat = wildc2i[(int)i]; + + /* + * If this is a town/dungeon entrance, note + * its coordinates. (Have to check for + * duplicate Morias...) + */ + if (wf_info[wildc2i[(int)i]].entrance && + wf_info[wildc2i[(int)i]].wild_x == 0) + { + wf_info[wildc2i[(int)i]].wild_x = x; + wf_info[wildc2i[(int)i]].wild_y = y; + } + } + + (*yval)++; + + return (0); + } + /* Process "M::" -- move line lines */ + else if (buf[2] == 'M') + { + if (tokenize(buf + 4, 2, zz, ':', '/') == 2) + { + if (atoi(zz[0])) + { + (*yval) += atoi(zz[1]); + } + else + { + (*yval) -= atoi(zz[1]); + } + } + else + { + return (1); + } + return (0); + } + /* Process "W:P:: - starting position in the wilderness */ + else if (buf[2] == 'P') + { + if ((p_ptr->wilderness_x == 0) && + (p_ptr->wilderness_y == 0)) + { + if (tokenize(buf + 4, 2, zz, ':', '/') == 2) + { + p_ptr->wilderness_x = atoi(zz[0]); + p_ptr->wilderness_y = atoi(zz[1]); + } + else + { + return (1); + } + } + + return (0); + } + /* Process "W:E::: - entrance to the dungeon */ + else if (buf[2] == 'E') + { + if (tokenize(buf + 4, 3, zz, ':', '/') == 3) + { + wild_map[atoi(zz[1])][atoi(zz[2])].entrance = 1000 + atoi(zz[0]); + } + else + { + return (1); + } + + return (0); + } + } + + /* Process "P::" -- player position */ + else if (buf[0] == 'P') + { + if (init_flags & INIT_CREATE_DUNGEON) + { + if (tokenize(buf + 2, 2, zz, ':', '/') == 2) + { + /* Place player in a quest level */ + if (p_ptr->inside_quest || (init_flags & INIT_POSITION)) + { + p_ptr->py = atoi(zz[0]); + p_ptr->px = atoi(zz[1]); + } + /* Place player in the town */ + else if ((p_ptr->oldpx == 0) && (p_ptr->oldpy == 0)) + { + p_ptr->oldpy = atoi(zz[0]); + p_ptr->oldpx = atoi(zz[1]); + } + } + } + + return (0); + } + + /* Process "M::" -- set maximum values */ + else if (buf[0] == 'M') + { + if (tokenize(buf + 2, 3, zz, ':', '/') >= 2) + { + /* Maximum towns */ + if (zz[0][0] == 'T') + { + max_towns = atoi(zz[1]); + } + + /* Maximum real towns */ + if (zz[0][0] == 't') + { + max_real_towns = atoi(zz[1]); + } + + /* Maximum r_idx */ + else if (zz[0][0] == 'R') + { + max_r_idx = atoi(zz[1]); + } + + /* Maximum re_idx */ + else if (zz[0][0] == 'r') + { + max_re_idx = atoi(zz[1]); + } + + /* Maximum s_idx */ + else if (zz[0][0] == 'k') + { + max_s_idx = atoi(zz[1]); + if (max_s_idx > MAX_SKILLS) return (1); + } + + /* Maximum ab_idx */ + else if (zz[0][0] == 'b') + { + max_ab_idx = atoi(zz[1]); + } + + /* Maximum k_idx */ + else if (zz[0][0] == 'K') + { + max_k_idx = atoi(zz[1]); + } + + /* Maximum v_idx */ + else if (zz[0][0] == 'V') + { + max_v_idx = atoi(zz[1]); + } + + /* Maximum f_idx */ + else if (zz[0][0] == 'F') + { + max_f_idx = atoi(zz[1]); + } + + /* Maximum a_idx */ + else if (zz[0][0] == 'A') + { + max_a_idx = atoi(zz[1]); + } + + /* Maximum al_idx */ + else if (zz[0][0] == 'a') + { + max_al_idx = atoi(zz[1]); + } + + /* Maximum e_idx */ + else if (zz[0][0] == 'E') + { + max_e_idx = atoi(zz[1]); + } + + /* Maximum ra_idx */ + else if (zz[0][0] == 'Z') + { + max_ra_idx = atoi(zz[1]); + } + + /* Maximum o_idx */ + else if (zz[0][0] == 'O') + { + max_o_idx = atoi(zz[1]); + } + + /* Maximum player types */ + else if (zz[0][0] == 'P') + { + if (zz[1][0] == 'R') + { + max_rp_idx = atoi(zz[2]); + } + else if (zz[1][0] == 'S') + { + max_rmp_idx = atoi(zz[2]); + } + else if (zz[1][0] == 'C') + { + max_c_idx = atoi(zz[2]); + } + else if (zz[1][0] == 'M') + { + max_mc_idx = atoi(zz[2]); + } + else if (zz[1][0] == 'H') + { + max_bg_idx = atoi(zz[2]); + } + } + + /* Maximum m_idx */ + else if (zz[0][0] == 'M') + { + max_m_idx = atoi(zz[1]); + } + + /* Maximum tr_idx */ + else if (zz[0][0] == 'U') + { + max_t_idx = atoi(zz[1]); + } + + /* Maximum wf_idx */ + else if (zz[0][0] == 'W') + { + max_wf_idx = atoi(zz[1]); + } + + /* Maximum ba_idx */ + else if (zz[0][0] == 'B') + { + max_ba_idx = atoi(zz[1]); + } + + /* Maximum st_idx */ + else if (zz[0][0] == 'S') + { + max_st_idx = atoi(zz[1]); + } + + /* Maximum set_idx */ + else if (zz[0][0] == 's') + { + max_set_idx = atoi(zz[1]); + } + + /* Maximum ow_idx */ + else if (zz[0][0] == 'N') + { + max_ow_idx = atoi(zz[1]); + } + + /* Maximum wilderness x size */ + else if (zz[0][0] == 'X') + { + max_wild_x = atoi(zz[1]); + } + + /* Maximum wilderness y size */ + else if (zz[0][0] == 'Y') + { + max_wild_y = atoi(zz[1]); + } + + /* Maximum d_idx */ + else if (zz[0][0] == 'D') + { + max_d_idx = atoi(zz[1]); + } + + return (0); + } + } + + /* Failure */ + return (1); +} + + + + +/* + * Helper function for "process_dungeon_file()" + */ +static cptr process_dungeon_file_expr(char **sp, char *fp) +{ + cptr v; + + char *b; + char *s; + + char b1 = '['; + char b2 = ']'; + + char f = ' '; + + /* Initial */ + s = (*sp); + + /* Skip spaces */ + while (isspace(*s)) s++; + + /* Save start */ + b = s; + + /* Default */ + v = "?o?o?"; + + /* Analyze */ + if (*s == b1) + { + const char *p; + const char *t; + + /* Skip b1 */ + s++; + + /* First */ + t = process_dungeon_file_expr(&s, &f); + + /* Oops */ + if (!*t) + { + /* Nothing */ + } + + /* Function: IOR */ + else if (streq(t, "IOR")) + { + v = "0"; + while (*s && (f != b2)) + { + t = process_dungeon_file_expr(&s, &f); + if (*t && !streq(t, "0")) v = "1"; + } + } + + /* Function: AND */ + else if (streq(t, "AND")) + { + v = "1"; + while (*s && (f != b2)) + { + t = process_dungeon_file_expr(&s, &f); + if (*t && streq(t, "0")) v = "0"; + } + } + + /* Function: NOT */ + else if (streq(t, "NOT")) + { + v = "1"; + while (*s && (f != b2)) + { + t = process_dungeon_file_expr(&s, &f); + if (*t && streq(t, "1")) v = "0"; + } + } + + /* Function: EQU */ + else if (streq(t, "EQU")) + { + v = "1"; + if (*s && (f != b2)) + { + t = process_dungeon_file_expr(&s, &f); + } + while (*s && (f != b2)) + { + p = t; + t = process_dungeon_file_expr(&s, &f); + if (*t && !streq(p, t)) v = "0"; + } + } + + /* Function: LEQ */ + else if (streq(t, "LEQ")) + { + v = "1"; + if (*s && (f != b2)) + { + t = process_dungeon_file_expr(&s, &f); + } + while (*s && (f != b2)) + { + p = t; + t = process_dungeon_file_expr(&s, &f); + if (*t && (strcmp(p, t) > 0)) v = "0"; + } + } + + /* Function: GEQ */ + else if (streq(t, "GEQ")) + { + v = "1"; + if (*s && (f != b2)) + { + t = process_dungeon_file_expr(&s, &f); + } + while (*s && (f != b2)) + { + p = t; + t = process_dungeon_file_expr(&s, &f); + if (*t && (strcmp(p, t) < 0)) v = "0"; + } + } + + /* Oops */ + else + { + while (*s && (f != b2)) + { + t = process_dungeon_file_expr(&s, &f); + } + } + + /* Verify ending */ + if (f != b2) v = "?x?x?"; + + /* Extract final and Terminate */ + if ((f = *s) != '\0') * s++ = '\0'; + } + + /* Other */ + else + { + bool_ text_mode = FALSE; + + /* Accept all printables except spaces and brackets */ + while (isprint(*s)) + { + if (*s == '"') text_mode = !text_mode; + if (!text_mode) + { + if (strchr(" []", *s)) + break; + } + else + { + if (strchr("[]", *s)) + break; + } + + ++s; + } + + /* Extract final and Terminate */ + if ((f = *s) != '\0') * s++ = '\0'; + + /* Variable */ + if (*b == '$') + { + /* System */ + if (streq(b + 1, "SYS")) + { + v = ANGBAND_SYS; + } + + /* Graphics */ + else if (streq(b + 1, "GRAF")) + { + v = ANGBAND_GRAF; + } + + /* Race */ + else if (streq(b + 1, "RACE")) + { + v = rp_ptr->title + rp_name; + } + + /* Race Mod */ + else if (streq(b + 1, "RACEMOD")) + { + v = rmp_ptr->title + rmp_name; + } + + /* Class */ + else if (streq(b + 1, "CLASS")) + { + v = cp_ptr->title + c_name; + } + + /* Player */ + else if (streq(b + 1, "PLAYER")) + { + v = player_base; + } + + /* Town */ + else if (streq(b + 1, "TOWN")) + { + strnfmt(pref_tmp_value, 8, "%d", p_ptr->town_num); + v = pref_tmp_value; + } + + /* Town destroyed */ + else if (prefix(b + 1, "TOWN_DESTROY")) + { + strnfmt(pref_tmp_value, 8, "%d", town_info[atoi(b + 13)].destroyed); + v = pref_tmp_value; + } + + /* Current quest number */ + else if (streq(b + 1, "QUEST_NUMBER")) + { + strnfmt(pref_tmp_value, 8, "%d", p_ptr->inside_quest); + v = pref_tmp_value; + } + + /* Number of last quest */ + else if (streq(b + 1, "LEAVING_QUEST")) + { + strnfmt(pref_tmp_value, 8, "%d", leaving_quest); + v = pref_tmp_value; + } + + /* DAYTIME status */ + else if (prefix(b + 1, "DAYTIME")) + { + if ((bst(HOUR, turn) >= 6) && (bst(HOUR, turn) < 18)) + v = "1"; + else + v = "0"; + } + + /* Quest status */ + else if (prefix(b + 1, "QUEST")) + { + /* "QUEST" uses a special parameter to determine the number of the quest */ + if (*(b + 6) != '"') + strnfmt(pref_tmp_value, 8, "%d", quest[atoi(b + 6)].status); + else + { + char c[80]; + int i; + + /* Copy it to temp array, so that we can modify it safely */ + strcpy(c, b + 7); + + /* Hunt & shoot the ending " */ + for (i = 0; (c[i] != '"') && (c[i] != '\0'); i++); + if (c[i] == '"') c[i] = '\0'; + strcpy(pref_tmp_value, "-1"); + for (i = 0; i < MAX_Q_IDX; i++) + { + if (streq(c, quest[i].name)) + { + strnfmt(pref_tmp_value, 8, "%d", quest[i].status); + break; + } + } + } + v = pref_tmp_value; + } + + /* Variant name */ + else if (streq(b + 1, "VARIANT")) + { + v = "ToME"; + } + + /* Wilderness */ + else if (streq(b + 1, "WILDERNESS")) + { + v = "NORMAL"; + } + } + + /* Constant */ + else + { + v = b; + } + } + + /* Save */ + (*fp) = f; + + /* Save */ + (*sp) = s; + + /* Result */ + return (v); +} + + +errr process_dungeon_file(cptr name, int *yval, int *xval, int ymax, int xmax, bool_ init, bool_ full) +{ + FILE *fp = 0; + + char buf[1024]; + + int num = -1, i; + + errr err = 0; + + bool_ bypass = FALSE; + + /* Save the start since it ought to be modified */ + int xmin = *xval; + + if (init) + { + meta_sleep = TRUE; + for (i = 0; i < 255; i++) + { + letter[i].defined = FALSE; + if (i == ' ') letter[i].ok = TRUE; + else letter[i].ok = FALSE; + letter[i].bx = 0; + letter[i].by = 0; + } + } + + /* Build the filename */ + path_build(buf, 1024, ANGBAND_DIR_EDIT, name); + + /* Open the file */ + fp = my_fopen(buf, "r"); + + /* No such file */ + if (!fp) + { + msg_format("Cannot find file %s at %s", name, buf); + return ( -1); + } + + /* Process the file */ + while (0 == my_fgets(fp, buf, 1024)) + { + /* Count lines */ + num++; + + + /* Skip "empty" lines */ + if (!buf[0]) continue; + + /* Skip "blank" lines */ + if (isspace(buf[0])) continue; + + /* Skip comments */ + if (buf[0] == '#') continue; + + + /* Process "?:" */ + if ((buf[0] == '?') && (buf[1] == ':')) + { + char f; + cptr v; + char *s; + + /* Start */ + s = buf + 2; + + /* Parse the expr */ + v = process_dungeon_file_expr(&s, &f); + + /* Set flag */ + bypass = (streq(v, "0") ? TRUE : FALSE); + + /* Continue */ + continue; + } + + /* Apply conditionals */ + if (bypass) continue; + + + /* Process "%:" */ + if (buf[0] == '%') + { + /* Process that file if allowed */ + (void)process_dungeon_file(buf + 2, yval, xval, ymax, xmax, FALSE, full); + + /* Continue */ + continue; + } + + + /* Process the line */ + err = process_dungeon_file_aux(buf, yval, xval, xmin, ymax, xmax, full); + + /* Oops */ + if (err) break; + } + + + /* Error */ + if (err) + { + /* Useful error message */ + msg_format("Error %d in line %d of file '%s'.", err, num, name); + msg_format("Parsing '%s'", buf); + } + + /* Close the file */ + my_fclose(fp); + + /* Result */ + return (err); +} -- cgit v1.2.3 From 88767d9fd11638b90e16da05426b19da9ef2b9b9 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 8 Sep 2013 11:49:32 +0200 Subject: Fix an overflow with allocation values --- src/init1.cc | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 076ca70e..646e8083 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4393,6 +4393,11 @@ errr init_k_info_txt(FILE *fp, char *buf) /* XXX XXX XXX Simply read each number following a colon */ for (i = 0, s = buf + 1; s && (s[0] == ':') && s[1]; ++i) { + if (i >= ALLOCATION_MAX) { + msg_print("Too many allocation entries."); + return 1; + } + /* Default chance */ k_ptr->chance[i] = 1; @@ -4409,7 +4414,9 @@ errr init_k_info_txt(FILE *fp, char *buf) if (t && (!s || t < s)) { int chance = atoi(t + 1); - if (chance > 0) k_ptr->chance[i] = chance; + if (chance > 0) { + k_ptr->chance[i] = chance; + } } } -- cgit v1.2.3 From 5a60ce1f8ab8a6a34cf55b637dd601b5d4422197 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 8 Sep 2013 12:36:06 +0200 Subject: Fix undefined behavior when too many "flag rarity groups" were used --- src/init1.cc | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 646e8083..7730467a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6316,6 +6316,7 @@ errr init_ab_info_txt(FILE *fp, char *buf) static bool_ grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what, int n, bool_ obvious) { int i; + assert(n < FLAG_RARITY_MAX); /* Check flags1 */ for (i = 0; i < 32; i++) @@ -6643,7 +6644,7 @@ errr init_e_info_txt(FILE *fp, char *buf) { e_ptr->tval[j] = 255; } - for (j = 0; j < 5; j++) + for (j = 0; j < FLAG_RARITY_MAX; j++) { e_ptr->rar[j] = 0; e_ptr->flags1[j] = 0; @@ -6652,6 +6653,13 @@ errr init_e_info_txt(FILE *fp, char *buf) e_ptr->flags4[j] = 0; e_ptr->flags5[j] = 0; e_ptr->esp[j] = 0; + e_ptr->oflags1[j] = 0; + e_ptr->oflags2[j] = 0; + e_ptr->oflags3[j] = 0; + e_ptr->oflags4[j] = 0; + e_ptr->oflags5[j] = 0; + e_ptr->oesp[j] = 0; + e_ptr->fego[j] = 0; } /* Next... */ @@ -6689,14 +6697,16 @@ errr init_e_info_txt(FILE *fp, char *buf) { int rar; - if (cur_r == 5) return 1; + cur_r++; + + if (cur_r >= FLAG_RARITY_MAX) { + return 1; + } /* Scan for the values */ if (1 != sscanf(buf + 2, "%d", &rar)) return (1); - cur_r++; - /* Save the values */ e_ptr->rar[cur_r] = rar; -- cgit v1.2.3 From ff252acf7f2f38e33017e82881c95825b54c7cee Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 16 Dec 2014 18:28:59 +0100 Subject: Replace uses of stricmp with boost::algorithm::iequals --- src/init1.cc | 20 ++++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 7730467a..8dd0fa62 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4,6 +4,10 @@ #include "angband.h" +#include + +using boost::algorithm::iequals; + /* * This file is used to initialize various variables and arrays for the @@ -2049,7 +2053,7 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Find it in the list */ for (i = 0; i < POWER_MAX; i++) { - if (!stricmp(s, powers_type[i].name)) break; + if (iequals(s, powers_type[i].name)) break; } if (i == POWER_MAX) return (6); @@ -2427,7 +2431,7 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Find it in the list */ for (i = 0; i < POWER_MAX; i++) { - if (!stricmp(s, powers_type[i].name)) break; + if (iequals(s, powers_type[i].name)) break; } if (i == POWER_MAX) return (6); @@ -2950,7 +2954,7 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Find it in the list */ for (i = 0; i < POWER_MAX; i++) { - if (!stricmp(s, powers_type[i].name)) break; + if (iequals(s, powers_type[i].name)) break; } if (i == POWER_MAX) return (6); @@ -3373,7 +3377,7 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Find it in the list */ for (i = 0; i < max_c_idx; i++) { - if (!stricmp(s, class_info[i].title + c_name)) break; + if (iequals(s, class_info[i].title + c_name)) break; } if (i == max_c_idx) return (6); @@ -4354,7 +4358,7 @@ errr init_k_info_txt(FILE *fp, char *buf) /* Find it in the list */ for (i = 0; i < POWER_MAX; i++) { - if (!stricmp(s, powers_type[i].name)) break; + if (iequals(s, powers_type[i].name)) break; } if (i == POWER_MAX) return (6); @@ -5247,7 +5251,7 @@ errr init_a_info_txt(FILE *fp, char *buf) /* Find it in the list */ for (i = 0; i < POWER_MAX; i++) { - if (!stricmp(s, powers_type[i].name)) break; + if (iequals(s, powers_type[i].name)) break; } if (i == POWER_MAX) return (6); @@ -6782,7 +6786,7 @@ errr init_e_info_txt(FILE *fp, char *buf) /* Find it in the list */ for (i = 0; i < POWER_MAX; i++) { - if (!stricmp(s, powers_type[i].name)) break; + if (iequals(s, powers_type[i].name)) break; } if (i == POWER_MAX) return (6); @@ -7271,7 +7275,7 @@ errr init_ra_info_txt(FILE *fp, char *buf) /* Find it in the list */ for (i = 0; i < POWER_MAX; i++) { - if (!stricmp(s, powers_type[i].name)) break; + if (iequals(s, powers_type[i].name)) break; } if (i == POWER_MAX) return (6); -- cgit v1.2.3 From c5de7e5167233f6c0e9f499a9323fa4b084f775c Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 22 Dec 2014 22:33:58 +0100 Subject: Make "pref_tmp_value" local --- src/init1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 8dd0fa62..52405944 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -11420,6 +11420,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst */ static cptr process_dungeon_file_expr(char **sp, char *fp) { + static char pref_tmp_value[8]; cptr v; char *b; -- cgit v1.2.3 From d63789e481ea6cc451934ca868f7de1aec6abc38 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:56 +0100 Subject: Change "activation spells" to use the old style This fits in better with the rest of the code and lets us clean up the spell handling a bit. Activation failure rate for the moved items may have changed slightly, but it doesn't seem like this would be much of an issue. --- src/init1.cc | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 52405944..7e278d0e 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1398,6 +1398,12 @@ static const char *activation_names[] = "XXX198", "XXX199", "MUSIC", /* 200*/ + "ETERNAL_FLAME", /* 201 */ + "MAGGOT", /* 202 */ + "LEBOHAUM", /* 203 */ + "DURANDIL", /* 204 */ + "RADAGAST", /* 205, Theme */ + "VALAROMA", /* 206, Theme */ "" }; @@ -1670,14 +1676,18 @@ static errr grab_one_player_race_flag(u32b *f1, u32b *f2, cptr what) } /* Get an activation number (good for artifacts, recipes, egos, and object kinds) */ -int get_activation(char *activation) +static int get_activation(char *activation) { int i; for ( i = 0 ; activation_names[i][0] ; i++) + { if (!strncmp(activation_names[i], activation, 19)) { return i; } + } + + msg_format("Unknown activation '%s'.", activation); return -1; } -- cgit v1.2.3 From 46a9d6e37cf61e03ab9c0fd03ebf04aca6a965d2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:56 +0100 Subject: Remove "HARDCORE=" and "SPELL=" handling for txt files We no longer need the distinction between HARDCORE= and SPELL= any longer, so just get rid of the prefix. --- src/init1.cc | 37 ++++++++----------------------------- 1 file changed, 8 insertions(+), 29 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 7e278d0e..8696e18a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4382,17 +4382,10 @@ errr init_k_info_txt(FILE *fp, char *buf) /* Process 'a' for Activation */ if ( buf[0] == 'a') { - if (prefix(buf + 2, "HARDCORE=")) + k_ptr->activate = get_activation(buf + 2); + if (k_ptr->activate == -1) { - k_ptr->activate = get_activation(buf + 11); - if (k_ptr->activate == -1) - return 1; - } - else if (prefix(buf + 2, "SPELL=")) - { - k_ptr->activate = -find_spell(buf + 8); - if (k_ptr->activate == -( -1)) - return 1; + return 1; } /* Next... */ @@ -5329,17 +5322,10 @@ errr init_a_info_txt(FILE *fp, char *buf) /* Read activation type. */ if (buf[0] == 'a') { - if (prefix(buf + 2, "HARDCORE=")) + a_ptr->activate = get_activation(buf + 2); + if (a_ptr->activate == -1) { - a_ptr->activate = get_activation(buf + 11); - if (a_ptr->activate == -1) - return 1; - } - else if (prefix(buf + 2, "SPELL=")) - { - a_ptr->activate = -find_spell(buf + 8); - if (a_ptr->activate == -( -1)) - return 1; + return 1; } /* Next... */ @@ -6809,16 +6795,9 @@ errr init_e_info_txt(FILE *fp, char *buf) if (buf[0] == 'a') { - if (prefix(buf + 2, "HARDCORE=")) - { - e_ptr->activate = get_activation(buf + 11); - if (e_ptr->activate == -1) - return 1; - } - else if (prefix(buf + 2, "SPELL=")) + e_ptr->activate = get_activation(buf + 2); + if (e_ptr->activate == -1) { - e_ptr->activate = -find_spell(buf + 8); - if (e_ptr->activate == -( -1)) return 1; } -- cgit v1.2.3 From c4746c0f6d328baa429c96e54d86d2d7f97ccbcc Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: Remove r_name, r_text, r_head in favor of simple strings --- src/init1.cc | 66 +++++++++++++++++++++++++++++++----------------------------- 1 file changed, 34 insertions(+), 32 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 8696e18a..4fc3513d 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1498,6 +1498,33 @@ static byte monster_ego_modify(char c) } } +/** + * Append one string to the end of another, reallocating if + * necessary. + */ +static void strappend(char **s, char *t) +{ + // Do we need to initialize the destination string? + if (*s == nullptr) + { + // Costs an extra allocation which could be avoided + // but this leads to simpler code. + *s = strdup(""); + } + // We should really be preserving the original pointer and + // do something else in case of failure to realloc(), but + // instead we just do the lazy thing and call abort() if + // reallocation fails. In practice it won't. + *s = static_cast(realloc(*s, strlen(*s) + strlen(t) + 1)); + if (*s == nullptr) + { + abort(); // Cannot handle failure to reallocate + } + + /* Append 't' to the destination string */ + strcat(*s, t); +} + /* * Implements fp stacks, for included files */ @@ -7485,10 +7512,6 @@ errr init_r_info_txt(FILE *fp, char *buf) error_line = -1; - /* Start the "fake" stuff */ - r_head->name_size = 0; - r_head->text_size = 0; - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -7550,7 +7573,7 @@ errr init_r_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= r_head->info_num) return (2); + if (i >= max_r_idx) return (2); /* Save the index */ error_idx = i; @@ -7558,17 +7581,9 @@ errr init_r_info_txt(FILE *fp, char *buf) /* Point at the "info" */ r_ptr = &r_info[i]; - /* Hack -- Verify space */ - if (r_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!r_ptr->name) r_ptr->name = ++r_head->name_size; - - /* Append chars to the name */ - strcpy(r_name + r_head->name_size, s); - - /* Advance the index */ - r_head->name_size += strlen(s); + /* Allocate name string. */ + assert(!r_ptr->name); // Sanity check that we aren't overwriting anything + r_ptr->name = strdup(s); /* HACK -- Those ones HAVE to have a set default value */ r_ptr->drops.treasure = OBJ_GENE_TREASURE; @@ -7591,17 +7606,8 @@ errr init_r_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 2; - /* Hack -- Verify space */ - if (r_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ - if (!r_ptr->text) r_ptr->text = ++r_head->text_size; - - /* Append chars to the name */ - strcpy(r_text + r_head->text_size, s); - - /* Advance the index */ - r_head->text_size += strlen(s); + /* Append to description */ + strappend(&r_ptr->text, s); /* Next... */ continue; @@ -7853,11 +7859,7 @@ errr init_r_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++r_head->name_size; - ++r_head->text_size; - + /* Postprocessing */ for (i = 1; i < max_r_idx; i++) { /* Invert flag WILD_ONLY <-> RF8_DUNGEON */ -- cgit v1.2.3 From 4b6f8d810f5ad513bea8fada09be01dde0fd643c Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: Remove k_name, k_text, k_head in favor of simple strings --- src/init1.cc | 46 +++++----------------------------------------- 1 file changed, 5 insertions(+), 41 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 4fc3513d..f00e5a54 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4155,10 +4155,6 @@ errr init_k_info_txt(FILE *fp, char *buf) error_line = -1; - /* Prepare the "fake" stuff */ - k_head->name_size = 0; - k_head->text_size = 0; - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -4220,7 +4216,7 @@ errr init_k_info_txt(FILE *fp, char *buf) if (i <= error_idx) return (4); /* Verify information */ - if (i >= k_head->info_num) return (2); + if (i >= max_k_idx) return (2); /* Save the index */ error_idx = i; @@ -4228,17 +4224,9 @@ errr init_k_info_txt(FILE *fp, char *buf) /* Point at the "info" */ k_ptr = &k_info[i]; - /* Hack -- Verify space */ - if (k_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - /* Advance and Save the name index */ - if (!k_ptr->name) k_ptr->name = ++k_head->name_size; - - /* Append chars to the name */ - strcpy(k_name + k_head->name_size, s); - - /* Advance the index */ - k_head->name_size += strlen(s); + assert(!k_ptr->name); + k_ptr->name = strdup(s); /* Needed hack */ k_ptr->esp = 0; @@ -4257,27 +4245,8 @@ errr init_k_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 2; - /* Hack -- Verify space */ - if (k_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ - if (!k_ptr->text) k_ptr->text = ++k_head->text_size; - - /* Append a space if needed */ - else if (k_text[k_head->text_size - 1] != ' ') - { - /* Append chars to the name */ - strcpy(k_text + k_head->text_size, " "); - - /* Advance the index */ - k_head->text_size += 1; - } - - /* Append chars to the name */ - strcpy(k_text + k_head->text_size, s); - - /* Advance the index */ - k_head->text_size += strlen(s); + /* Append description */ + strappend(&k_ptr->text, s); /* Next... */ continue; @@ -4538,11 +4507,6 @@ errr init_k_info_txt(FILE *fp, char *buf) } - /* Complete the "name" and "text" sizes */ - ++k_head->name_size; - ++k_head->text_size; - - /* No version yet */ if (!okay) return (2); -- cgit v1.2.3 From cf3bec7340563628689e92d3be018a25fa550dbd Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: init1.c: Use safer variant of strdup() --- src/init1.cc | 21 ++++++++++++++++++--- 1 file changed, 18 insertions(+), 3 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index f00e5a54..4a646b51 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1498,6 +1498,21 @@ static byte monster_ego_modify(char c) } } +/** + * Version of strdup() which just aborts if an allocation + * error occurs. + */ +static char *my_strdup(const char *s) +{ + char *p = strdup(s); + if (!p) + { + abort(); + } + return p; +} + + /** * Append one string to the end of another, reallocating if * necessary. @@ -1509,7 +1524,7 @@ static void strappend(char **s, char *t) { // Costs an extra allocation which could be avoided // but this leads to simpler code. - *s = strdup(""); + *s = my_strdup(""); } // We should really be preserving the original pointer and // do something else in case of failure to realloc(), but @@ -4226,7 +4241,7 @@ errr init_k_info_txt(FILE *fp, char *buf) /* Advance and Save the name index */ assert(!k_ptr->name); - k_ptr->name = strdup(s); + k_ptr->name = my_strdup(s); /* Needed hack */ k_ptr->esp = 0; @@ -7547,7 +7562,7 @@ errr init_r_info_txt(FILE *fp, char *buf) /* Allocate name string. */ assert(!r_ptr->name); // Sanity check that we aren't overwriting anything - r_ptr->name = strdup(s); + r_ptr->name = my_strdup(s); /* HACK -- Those ones HAVE to have a set default value */ r_ptr->drops.treasure = OBJ_GENE_TREASURE; -- cgit v1.2.3 From dfcb08c2e7c2e6713691b3003e51295f05e75f5a Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: init1.c: strappend() takes a const second parameter --- src/init1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 4a646b51..b01072a2 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1517,7 +1517,7 @@ static char *my_strdup(const char *s) * Append one string to the end of another, reallocating if * necessary. */ -static void strappend(char **s, char *t) +static void strappend(char **s, const char *t) { // Do we need to initialize the destination string? if (*s == nullptr) -- cgit v1.2.3 From 7357dd5d299d7937ce62b486dda375b3b0eadb49 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: Make sure {k_ptr,r_ptr}*->text is initialized to empty string This is simpler to make robust, so we'll opt for just doing this at initialization time. --- src/init1.cc | 6 ++++++ 1 file changed, 6 insertions(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index b01072a2..402618ea 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4243,6 +4243,9 @@ errr init_k_info_txt(FILE *fp, char *buf) assert(!k_ptr->name); k_ptr->name = my_strdup(s); + /* Ensure empty description */ + k_ptr->text = my_strdup(""); + /* Needed hack */ k_ptr->esp = 0; k_ptr->power = -1; @@ -7564,6 +7567,9 @@ errr init_r_info_txt(FILE *fp, char *buf) assert(!r_ptr->name); // Sanity check that we aren't overwriting anything r_ptr->name = my_strdup(s); + /* Ensure empty description */ + r_ptr->text = my_strdup(""); + /* HACK -- Those ones HAVE to have a set default value */ r_ptr->drops.treasure = OBJ_GENE_TREASURE; r_ptr->drops.combat = OBJ_GENE_COMBAT; -- cgit v1.2.3 From cbc6fe196f7205f3e5de8c14cba957dbd2e72890 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: Replace a_head, a_name, a_text with simple char * --- src/init1.cc | 48 +++++++++++------------------------------------- 1 file changed, 11 insertions(+), 37 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 402618ea..a65863b5 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -7,6 +7,7 @@ #include using boost::algorithm::iequals; +using boost::algorithm::ends_with; /* @@ -5111,26 +5112,18 @@ errr init_a_info_txt(FILE *fp, char *buf) /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= a_head->info_num) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ a_ptr = &a_info[i]; - /* Hack -- Verify space */ - if (a_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!a_ptr->name) a_ptr->name = ++a_head->name_size; - - /* Append chars to the name */ - strcpy(a_name + a_head->name_size, s); + /* Copy name */ + assert(!a_ptr->name); + a_ptr->name = my_strdup(s); - /* Advance the index */ - a_head->name_size += strlen(s); + /* Ensure empty description */ + a_ptr->text = my_strdup(""); /* Ignore everything */ a_ptr->flags3 |= (TR3_IGNORE_ACID); @@ -5162,27 +5155,13 @@ errr init_a_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 2; - /* Hack -- Verify space */ - if (a_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ - if (!a_ptr->text) a_ptr->text = ++a_head->text_size; - - /* Append a space at the end of the line, if needed */ - else if (a_text[a_head->text_size - 1] != ' ') - { - /* Append the space */ - strcpy(a_text + a_head->text_size, " "); - - /* Advance the index */ - a_head->text_size += 1; + /* Add separator if necessary */ + if (*a_ptr->text != '\0' && !ends_with(a_ptr->text, " ")) { + strappend(&a_ptr->text, " "); } - /* Append chars to the name */ - strcpy(a_text + a_head->text_size, s); - - /* Advance the index */ - a_head->text_size += strlen(s); + /* Append to description */ + strappend(&a_ptr->text, s); /* Next... */ continue; @@ -5347,11 +5326,6 @@ errr init_a_info_txt(FILE *fp, char *buf) } - /* Complete the "name" and "text" sizes */ - ++a_head->name_size; - ++a_head->text_size; - - /* No version yet */ if (!okay) return (2); -- cgit v1.2.3 From d56f3fcfdb6e166118d869290723320891c5c878 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:57 +0100 Subject: init1.c: Add missing range check for a_info[] load --- src/init1.cc | 3 +++ 1 file changed, 3 insertions(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index a65863b5..770ae4d0 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5112,6 +5112,9 @@ errr init_a_info_txt(FILE *fp, char *buf) /* Verify information */ if (i < error_idx) return (4); + /* Verify information */ + if (i >= max_a_idx) return (2); + /* Save the index */ error_idx = i; -- cgit v1.2.3 From e2b5157f29e66cb0ccb151bfd46ee43c8c745fe7 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove v_name, v_text, v_head --- src/init1.cc | 54 +++++++++++------------------------------------------- 1 file changed, 11 insertions(+), 43 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 770ae4d0..2c89736b 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3463,7 +3463,7 @@ errr init_player_info_txt(FILE *fp, char *buf) /* * Initialize the "v_info" array, by parsing an ascii "template" file */ -errr init_v_info_txt(FILE *fp, char *buf, bool_ start) +errr init_v_info_txt(FILE *fp, char *buf) { int i; char *s; @@ -3474,18 +3474,11 @@ errr init_v_info_txt(FILE *fp, char *buf, bool_ start) /* Current entry */ vault_type *v_ptr = NULL; - if (start) - { - /* Just before the first record */ - error_idx = -1; - - /* Just before the first line */ - error_line = -1; + /* Just before the first record */ + error_idx = -1; - /* Prepare the "fake" stuff */ - v_head->name_size = 0; - v_head->text_size = 0; - } + /* Just before the first line */ + error_line = -1; /* Parse */ fp_stack_init(fp); @@ -3549,7 +3542,7 @@ errr init_v_info_txt(FILE *fp, char *buf, bool_ start) if (i <= error_idx) return (4); /* Verify information */ - if (i >= v_head->info_num) return (2); + if (i >= max_v_idx) return (2); /* Save the index */ error_idx = i; @@ -3557,17 +3550,9 @@ errr init_v_info_txt(FILE *fp, char *buf, bool_ start) /* Point at the "info" */ v_ptr = &v_info[i]; - /* Hack -- Verify space */ - if (v_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!v_ptr->name) v_ptr->name = ++v_head->name_size; - - /* Append chars to the name */ - strcpy(v_name + v_head->name_size, s); - - /* Advance the index */ - v_head->name_size += strlen(s); + /* Initialize data -- we ignore the name, it's not + * used for anything */ + v_ptr->data = my_strdup(""); /* Next... */ continue; @@ -3582,17 +3567,8 @@ errr init_v_info_txt(FILE *fp, char *buf, bool_ start) /* Acquire the text */ s = buf + 2; - /* Hack -- Verify space */ - if (v_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ - if (!v_ptr->text) v_ptr->text = ++v_head->text_size; - - /* Append chars to the name */ - strcpy(v_text + v_head->text_size, s); - - /* Advance the index */ - v_head->text_size += strlen(s); + /* Append data */ + strappend(&v_ptr->data, s); /* Next... */ continue; @@ -3659,14 +3635,6 @@ errr init_v_info_txt(FILE *fp, char *buf, bool_ start) } - /* Complete the "name" and "text" sizes */ - if (!start) - { - ++v_head->name_size; - ++v_head->text_size; - } - - /* No version yet */ if (!okay) return (2); -- cgit v1.2.3 From e6d0a04ee4231400fe9cd4037bf89e2985a18bf3 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove e_name, e_text, e_head --- src/init1.cc | 21 ++++----------------- 1 file changed, 4 insertions(+), 17 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 2c89736b..66ea59ab 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6569,7 +6569,7 @@ errr init_e_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= e_head->info_num) return (2); + if (i >= max_e_idx) return (2); /* Save the index */ error_idx = i; @@ -6577,17 +6577,9 @@ errr init_e_info_txt(FILE *fp, char *buf) /* Point at the "info" */ e_ptr = &e_info[i]; - /* Hack -- Verify space */ - if (e_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!e_ptr->name) e_ptr->name = ++e_head->name_size; - - /* Append chars to the name */ - strcpy(e_name + e_head->name_size, s); - - /* Advance the index */ - e_head->name_size += strlen(s); + /* Copy name */ + assert(!e_ptr->name); + e_ptr->name = my_strdup(s); /* Needed hack */ e_ptr->power = -1; @@ -6876,11 +6868,6 @@ errr init_e_info_txt(FILE *fp, char *buf) } - /* Complete the "name" and "text" sizes */ - ++e_head->name_size; - ++e_head->text_size; - - /* No version yet */ if (!okay) return (2); -- cgit v1.2.3 From 8e89f38f28fd5c7dff91732807a591eaefbc36c0 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove re_head, re_name --- src/init1.cc | 25 ++++--------------------- 1 file changed, 4 insertions(+), 21 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 66ea59ab..ad1cda4c 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -8046,11 +8046,6 @@ errr init_re_info_txt(FILE *fp, char *buf) /* Just before the first line */ error_line = -1; - - /* Start the "fake" stuff */ - re_head->name_size = 0; - re_head->text_size = 0; - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -8112,7 +8107,7 @@ errr init_re_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= re_head->info_num) return (2); + if (i >= max_re_idx) return (2); /* Save the index */ error_idx = i; @@ -8120,17 +8115,9 @@ errr init_re_info_txt(FILE *fp, char *buf) /* Point at the "info" */ re_ptr = &re_info[i]; - /* Hack -- Verify space */ - if (re_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!re_ptr->name) re_ptr->name = ++re_head->name_size; - - /* Append chars to the name */ - strcpy(re_name + re_head->name_size, s); - - /* Advance the index */ - re_head->name_size += strlen(s); + /* Copy name */ + assert(!re_ptr->name); + re_ptr->name = my_strdup(s); /* Some inits */ blow_num = 0; @@ -8529,10 +8516,6 @@ errr init_re_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++re_head->name_size; - /* No version yet */ if (!okay) return (2); -- cgit v1.2.3 From de5ee3b24f035efe3da8260687200109302f350a Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove d_head, d_name, d_text --- src/init1.cc | 39 ++++++++------------------------------- 1 file changed, 8 insertions(+), 31 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index ad1cda4c..5dc7358a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -8943,11 +8943,6 @@ errr init_d_info_txt(FILE *fp, char *buf) /* Just before the first line */ error_line = -1; - - /* Start the "fake" stuff */ - d_head->name_size = 0; - d_head->text_size = 0; - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -9009,7 +9004,7 @@ errr init_d_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= d_head->info_num) return (2); + if (i >= max_d_idx) return (2); /* Save the index */ error_idx = i; @@ -9017,17 +9012,12 @@ errr init_d_info_txt(FILE *fp, char *buf) /* Point at the "info" */ d_ptr = &d_info[i]; - /* Hack -- Verify space */ - if (d_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!d_ptr->name) d_ptr->name = ++d_head->name_size; - - /* Append chars to the name */ - strcpy(d_name + d_head->name_size, s); + /* Copy name */ + assert(!d_ptr->name); + d_ptr->name = my_strdup(s); - /* Advance the index */ - d_head->name_size += strlen(s); + /* Initialize description */ + d_ptr->text = my_strdup(""); /* HACK -- Those ones HAVE to have a set default value */ d_ptr->size_x = -1; @@ -9076,17 +9066,8 @@ errr init_d_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 6; - /* Hack -- Verify space */ - if (d_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ - if (!d_ptr->text) d_ptr->text = ++d_head->text_size; - - /* Append chars to the name */ - strcpy(d_text + d_head->text_size, s); - - /* Advance the index */ - d_head->text_size += strlen(s); + /* Append to description */ + strappend(&d_ptr->text, s); /* Next... */ continue; @@ -9500,10 +9481,6 @@ errr init_d_info_txt(FILE *fp, char *buf) } - /* Complete the "name" and "text" sizes */ - ++d_head->name_size; - ++d_head->text_size; - /* No version yet */ if (!okay) return (2); -- cgit v1.2.3 From 3f59d3d407cd743f4e4b27791c4fe13785f8669d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove ab_head, ab_name, ab_text --- src/init1.cc | 56 +++++++++++--------------------------------------------- 1 file changed, 11 insertions(+), 45 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 5dc7358a..8cf7c3f1 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6003,7 +6003,7 @@ errr init_ab_info_txt(FILE *fp, char *buf) i = atoi(buf + 2); /* Verify information */ - if (i >= ab_head->info_num) return (2); + if (i >= max_ab_idx) return (2); /* Save the index */ error_idx = i; @@ -6011,17 +6011,9 @@ errr init_ab_info_txt(FILE *fp, char *buf) /* Point at the "info" */ ab_ptr = &ab_info[i]; - /* Hack -- Verify space */ - if (ab_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!ab_ptr->name) ab_ptr->name = ++ab_head->name_size; - - /* Append chars to the name */ - strcpy(ab_name + ab_head->name_size, s); - - /* Advance the index */ - ab_head->name_size += strlen(s); + /* Copy name */ + assert(!ab_ptr->name); + ab_ptr->name = my_strdup(s); /* Init */ ab_ptr->action_mkey = 0; @@ -6050,27 +6042,14 @@ errr init_ab_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 2; - /* Hack -- Verify space */ - if (ab_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ + /* Append description */ if (!ab_ptr->desc) { - ab_ptr->desc = ++ab_head->text_size; - - /* Append chars to the name */ - strcpy(ab_text + ab_head->text_size, s); - - /* Advance the index */ - ab_head->text_size += strlen(s); + ab_ptr->desc = my_strdup(s); } else { - /* Append chars to the name */ - strcpy(ab_text + ab_head->text_size, format("\n%s", s)); - - /* Advance the index */ - ab_head->text_size += strlen(s) + 1; + strappend(&ab_ptr->desc, format("\n%s", s)); } /* Next... */ @@ -6089,19 +6068,13 @@ errr init_ab_info_txt(FILE *fp, char *buf) *txt = '\0'; txt++; - /* Hack -- Verify space */ - if (ab_head->text_size + strlen(txt) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ - if (!ab_ptr->action_desc) ab_ptr->action_desc = ++ab_head->text_size; + /* Copy name */ + assert(!ab_ptr->action_desc); + ab_ptr->action_desc = my_strdup(txt); - /* Append chars to the name */ - strcpy(ab_text + ab_head->text_size, txt); + /* Set mkey */ ab_ptr->action_mkey = atoi(s); - /* Advance the index */ - ab_head->text_size += strlen(txt); - /* Next... */ continue; } @@ -6249,16 +6222,9 @@ errr init_ab_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++ab_head->name_size; - ++ab_head->text_size; - - /* No version yet */ if (!okay) return (2); - /* Success */ return (0); } -- cgit v1.2.3 From 3bfa6a0e2cba6b4fc8f53dac1e987c95fe7ed93c Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove c_head, c_name, c_text --- src/init1.cc | 100 ++++++++++++++++++----------------------------------------- 1 file changed, 30 insertions(+), 70 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 8cf7c3f1..aac41a8b 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1624,7 +1624,7 @@ static errr grab_one_class_flag(u32b *choice, cptr what) cptr s; /* Scan classes flags */ - for (i = 0; i < max_c_idx && (s = class_info[i].title + c_name); i++) + for (i = 0; i < max_c_idx && (s = class_info[i].title); i++) { if (streq(what, s)) { @@ -1855,8 +1855,6 @@ errr init_player_info_txt(FILE *fp, char *buf) rp_head->text_size = 0; rmp_head->name_size = 0; rmp_head->text_size = 0; - c_head->name_size = 0; - c_head->text_size = 0; /* Init general skills */ for (z = 0; z < MAX_SKILLS; z++) @@ -2770,7 +2768,7 @@ errr init_player_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= c_head->info_num) return (2); + if (i >= max_c_idx) return (2); /* Save the index */ error_idx = i; @@ -2778,18 +2776,11 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Point at the "info" */ c_ptr = &class_info[i]; - /* Hack -- Verify space */ - if (c_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!c_ptr->title) c_ptr->title = ++c_head->name_size; - - /* Append chars to the name */ - strcpy(c_name + c_head->name_size, s); - - /* Advance the index */ - c_head->name_size += strlen(s); + /* Copy name */ + assert(!c_ptr->title); + c_ptr->title = my_strdup(s); + /* Initialize */ c_ptr->powers[0] = c_ptr->powers[1] = c_ptr->powers[2] = c_ptr->powers[3] = -1; powers = 0; lev = 1; @@ -2812,43 +2803,31 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 6; - /* Hack -- Verify space */ - if (c_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - switch (buf[4]) { - case '0': - /* Advance and Save the text index */ + case '0': /* Class description */ if (!c_ptr->desc) { - c_ptr->desc = ++c_head->text_size; - /* Append chars to the name */ - strcpy(c_text + c_head->text_size, s); - - /* Advance the index */ - c_head->text_size += strlen(s); + c_ptr->desc = my_strdup(s); } else { - /* Append chars to the name */ - strcpy(c_text + c_head->text_size, format("\n%s", s)); - - /* Advance the index */ - c_head->text_size += strlen(s) + 1; + strappend(&c_ptr->desc, format("\n%s", s)); } break; - case '1': - /* Advance and Save the text index */ - c_ptr->titles[tit_idx++] = ++c_head->text_size; - /* Append chars to the name */ - strcpy(c_text + c_head->text_size, s); + case '1': /* Class title */ + /* Copy */ + assert(!c_ptr->titles[tit_idx]); + c_ptr->titles[tit_idx] = my_strdup(s); + + /* Go to next title in array */ + tit_idx++; - /* Advance the index */ - c_head->text_size += strlen(s); break; - default: + + default: /* Unknown */ return (6); break; } @@ -3189,18 +3168,11 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Point at the "info" */ s_ptr = &c_ptr->spec[spec_idx]; - /* Hack -- Verify space */ - if (c_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!s_ptr->title) s_ptr->title = ++c_head->name_size; - - /* Append chars to the name */ - strcpy(c_name + c_head->name_size, s); - - /* Advance the index */ - c_head->name_size += strlen(s); + /* Copy title */ + assert(!s_ptr->title); + s_ptr->title = my_strdup(s); + /* Initialize */ s_ptr->obj_num = 0; cur_ab = 0; for (z = 0; z < 10; z++) @@ -3216,27 +3188,13 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 6; - /* Hack -- Verify space */ - if (c_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ if (!s_ptr->desc) { - s_ptr->desc = ++c_head->text_size; - - /* Append chars to the name */ - strcpy(c_text + c_head->text_size, s); - - /* Advance the index */ - c_head->text_size += strlen(s); + s_ptr->desc = my_strdup(s); } else { - /* Append chars to the name */ - strcpy(c_text + c_head->text_size, format("\n%s", s)); - - /* Advance the index */ - c_head->text_size += strlen(s) + 1; + strappend(&s_ptr->desc, format("\n%s", s)); } /* Next... */ @@ -3430,7 +3388,10 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Find it in the list */ for (i = 0; i < max_c_idx; i++) { - if (iequals(s, class_info[i].title + c_name)) break; + if (class_info[i].title && iequals(s, class_info[i].title)) + { + break; + } } if (i == max_c_idx) return (6); @@ -3450,8 +3411,7 @@ errr init_player_info_txt(FILE *fp, char *buf) ++rp_head->text_size; ++rmp_head->name_size; ++rmp_head->text_size; - ++c_head->name_size; - ++c_head->text_size; + /* No version yet */ if (!okay) return (2); @@ -11448,7 +11408,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp) /* Class */ else if (streq(b + 1, "CLASS")) { - v = cp_ptr->title + c_name; + v = cp_ptr->title; } /* Player */ -- cgit v1.2.3 From caa23251d8b279529330641032c62f8640ee13ff Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove rp_head, rp_name, rp_text, rmp_head, rmp_name, rmp_text --- src/init1.cc | 110 ++++++++++++++++------------------------------------------- 1 file changed, 30 insertions(+), 80 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index aac41a8b..28f8ba10 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1645,7 +1645,7 @@ static errr grab_one_race_allow_flag(u32b *choice, cptr what) cptr s; /* Scan classes flags */ - for (i = 0; i < max_rp_idx && (s = race_info[i].title + rp_name); i++) + for (i = 0; i < max_rp_idx && (s = race_info[i].title); i++) { if (streq(what, s)) { @@ -1849,13 +1849,6 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Just before the first line */ error_line = -1; - - /* Start the "fake" stuff */ - rp_head->name_size = 0; - rp_head->text_size = 0; - rmp_head->name_size = 0; - rmp_head->text_size = 0; - /* Init general skills */ for (z = 0; z < MAX_SKILLS; z++) { @@ -1926,13 +1919,9 @@ errr init_player_info_txt(FILE *fp, char *buf) bg[idx].next = atoi(zz[3]); bg[idx].bonus = atoi(zz[4]); - bg[idx].info = ++rp_head->text_size; - - /* Append chars to the name */ - strcpy(rp_text + rp_head->text_size, zz[5]); - - /* Advance the index */ - rp_head->text_size += strlen(zz[5]); + /* Copy text */ + assert(!bg[idx].info); + bg[idx].info = my_strdup(zz[5]); /* Next... */ continue; @@ -1980,7 +1969,7 @@ errr init_player_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= rp_head->info_num) return (2); + if (i >= max_rp_idx) return (2); /* Save the index */ error_idx = i; @@ -1988,18 +1977,11 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Point at the "info" */ rp_ptr = &race_info[i]; - /* Hack -- Verify space */ - if (rp_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!rp_ptr->title) rp_ptr->title = ++rp_head->name_size; - - /* Append chars to the name */ - strcpy(rp_name + rp_head->name_size, s); - - /* Advance the index */ - rp_head->name_size += strlen(s); + /* Copy title */ + assert(!rp_ptr->title); + rp_ptr->title = my_strdup(s); + /* Initialize */ rp_ptr->powers[0] = rp_ptr->powers[1] = rp_ptr->powers[2] = rp_ptr->powers[3] = -1; powers = 0; lev = 1; @@ -2017,27 +1999,13 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 4; - /* Hack -- Verify space */ - if (rp_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ if (!rp_ptr->desc) { - rp_ptr->desc = ++rp_head->text_size; - - /* Append chars to the name */ - strcpy(rp_text + rp_head->text_size, s); - - /* Advance the index */ - rp_head->text_size += strlen(s); + rp_ptr->desc = my_strdup(s); } else { - /* Append chars to the name */ - strcpy(rp_text + rp_head->text_size, format("\n%s", s)); - - /* Advance the index */ - rp_head->text_size += strlen(s) + 1; + strappend(&rp_ptr->desc, format("\n%s", s)); } /* Next... */ @@ -2354,7 +2322,7 @@ errr init_player_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= rmp_head->info_num) return (2); + if (i >= max_rmp_idx) return (2); /* Save the index */ error_idx = i; @@ -2362,18 +2330,11 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Point at the "info" */ rmp_ptr = &race_mod_info[i]; - /* Hack -- Verify space */ - if (rmp_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!rmp_ptr->title) rmp_ptr->title = ++rmp_head->name_size; - - /* Append chars to the name */ - strcpy(rmp_name + rmp_head->name_size, s); - - /* Advance the index */ - rmp_head->name_size += strlen(s); + /* Copy title */ + assert(!rmp_ptr->title); + rmp_ptr->title = my_strdup(s); + /* Initialize */ rmp_ptr->powers[0] = rmp_ptr->powers[1] = rmp_ptr->powers[2] = rmp_ptr->powers[3] = -1; powers = 0; lev = 1; @@ -2391,30 +2352,25 @@ errr init_player_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 6; - if (buf[4] == 'A') rmp_ptr->place = TRUE; - else rmp_ptr->place = FALSE; - - /* Hack -- Verify space */ - if (rmp_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); + /* Place */ + if (buf[4] == 'A') + { + rmp_ptr->place = TRUE; + } + else + { + rmp_ptr->place = FALSE; + } - /* Advance and Save the text index */ + /* Description */ if (!rmp_ptr->desc) { - rmp_ptr->desc = ++rmp_head->text_size; - - /* Append chars to the name */ - strcpy(rmp_text + rmp_head->text_size, s); - - /* Advance the index */ - rmp_head->text_size += strlen(s); + rmp_ptr->desc = my_strdup(s); } else { /* Append chars to the name */ - strcpy(rmp_text + rmp_head->text_size, format("\n%s", s)); - - /* Advance the index */ - rmp_head->text_size += strlen(s) + 1; + strappend(&rmp_ptr->desc, format("\n%s", s)); } /* Next... */ @@ -3406,12 +3362,6 @@ errr init_player_info_txt(FILE *fp, char *buf) return (6); } - /* Complete the "name" and "text" sizes */ - ++rp_head->name_size; - ++rp_head->text_size; - ++rmp_head->name_size; - ++rmp_head->text_size; - /* No version yet */ if (!okay) return (2); @@ -11396,13 +11346,13 @@ static cptr process_dungeon_file_expr(char **sp, char *fp) /* Race */ else if (streq(b + 1, "RACE")) { - v = rp_ptr->title + rp_name; + v = rp_ptr->title; } /* Race Mod */ else if (streq(b + 1, "RACEMOD")) { - v = rmp_ptr->title + rmp_name; + v = rmp_ptr->title; } /* Class */ -- cgit v1.2.3 From 560ebe18ecf165dcfffa2d57870f01f1099be44c Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove set_head, set_name, set_text --- src/init1.cc | 38 +++++++------------------------------- 1 file changed, 7 insertions(+), 31 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 28f8ba10..d8217499 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5302,7 +5302,7 @@ errr init_set_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= set_head->info_num) return (2); + if (i >= max_set_idx) return (2); /* Save the index */ error_idx = i; @@ -5310,19 +5310,11 @@ errr init_set_info_txt(FILE *fp, char *buf) /* Point at the "info" */ set_ptr = &set_info[i]; - /* Hack -- Verify space */ - if (set_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!set_ptr->name) set_ptr->name = ++set_head->name_size; - - /* Append chars to the name */ - strcpy(set_name + set_head->name_size, s); - - /* Advance the index */ - set_head->name_size += strlen(s); + /* Copy name */ + assert(!set_ptr->name); + set_ptr->name = my_strdup(s); - /* Needed hack */ + /* Initialize */ set_ptr->num = 0; set_ptr->num_use = 0; for (z = 0; z < 6; z++) @@ -5354,17 +5346,8 @@ errr init_set_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 2; - /* Hack -- Verify space */ - if (set_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ - if (!set_ptr->desc) set_ptr->desc = ++set_head->text_size; - - /* Append chars to the name */ - strcpy(set_text + set_head->text_size, s); - - /* Advance the index */ - set_head->text_size += strlen(s); + /* Append chars to the description */ + strappend(&set_ptr->desc, s); /* Next... */ continue; @@ -5438,16 +5421,9 @@ errr init_set_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++set_head->name_size; - ++set_head->text_size; - - /* No version yet */ if (!okay) return (2); - /* Success */ return (0); } -- cgit v1.2.3 From 7fce5e3c4d9c6700786828a6b82577fa95499217 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove ra_head --- src/init1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index d8217499..1d8d30d7 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6940,7 +6940,7 @@ errr init_ra_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= ra_head->info_num) return (2); + if (i >= max_ra_idx) return (2); /* Save the index */ error_idx = i; -- cgit v1.2.3 From e3405ca03eebafa60e773812c4f12fed7f4805db Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove t_head, t_name, t_text --- src/init1.cc | 40 ++++++---------------------------------- 1 file changed, 6 insertions(+), 34 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 1d8d30d7..76c33e9a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -8415,18 +8415,12 @@ errr init_t_info_txt(FILE *fp, char *buf) /* Current entry */ trap_type *t_ptr = NULL; - /* Just before the first record */ error_idx = -1; /* Just before the first line */ error_line = -1; - - /* Prepare the "fake" stuff */ - t_head->name_size = 0; - t_head->text_size = 0; - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -8488,7 +8482,7 @@ errr init_t_info_txt(FILE *fp, char *buf) if (i <= error_idx) return (4); /* Verify information */ - if (i >= t_head->info_num) return (2); + if (i >= max_t_idx) return (2); /* Save the index */ error_idx = i; @@ -8496,17 +8490,11 @@ errr init_t_info_txt(FILE *fp, char *buf) /* Point at the "info" */ t_ptr = &t_info[i]; - /* Hack -- Verify space */ - if (t_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!t_ptr->name) t_ptr->name = ++t_head->name_size; - - /* Append chars to the name */ - strcpy(t_name + t_head->name_size, s); + /* Copy name */ + t_ptr->name = my_strdup(s); - /* Advance the index */ - t_head->name_size += strlen(s); + /* Initialize */ + t_ptr->text = my_strdup(""); /* Next... */ continue; @@ -8550,17 +8538,8 @@ errr init_t_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 2; - /* Hack -- Verify space */ - if (t_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ - if (!t_ptr->text) t_ptr->text = ++t_head->text_size; - /* Append chars to the name */ - strcpy(t_text + t_head->text_size, s); - - /* Advance the index */ - t_head->text_size += strlen(s); + strappend(&t_ptr->text, s); /* Next... */ continue; @@ -8602,16 +8581,9 @@ errr init_t_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++t_head->name_size; - ++t_head->text_size; - - /* No version yet */ if (!okay) return (2); - /* Success */ return (0); } -- cgit v1.2.3 From 58e8024f17446bf3b1a36985d746f6de330874c0 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove s_head, s_name, s_text --- src/init1.cc | 58 ++++++++++++---------------------------------------------- 1 file changed, 12 insertions(+), 46 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 76c33e9a..109ec2be 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5627,7 +5627,7 @@ errr init_s_info_txt(FILE *fp, char *buf) i = atoi(buf + 2); /* Verify information */ - if (i >= s_head->info_num) return (2); + if (i >= max_s_idx) return (2); /* Save the index */ error_idx = i; @@ -5635,17 +5635,9 @@ errr init_s_info_txt(FILE *fp, char *buf) /* Point at the "info" */ s_ptr = &s_info[i]; - /* Hack -- Verify space */ - if (s_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!s_ptr->name) s_ptr->name = ++s_head->name_size; - - /* Append chars to the name */ - strcpy(s_name + s_head->name_size, s); - - /* Advance the index */ - s_head->name_size += strlen(s); + /* Copy name */ + assert(!s_ptr->name); + s_ptr->name = my_strdup(s); /* Init */ s_ptr->action_mkey = 0; @@ -5669,34 +5661,21 @@ errr init_s_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 2; - /* Hack -- Verify space */ - if (s_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ + /* Description */ if (!s_ptr->desc) { - s_ptr->desc = ++s_head->text_size; - - /* Append chars to the name */ - strcpy(s_text + s_head->text_size, s); - - /* Advance the index */ - s_head->text_size += strlen(s); + s_ptr->desc = my_strdup(s); } else { - /* Append chars to the name */ - strcpy(s_text + s_head->text_size, format("\n%s", s)); - - /* Advance the index */ - s_head->text_size += strlen(s) + 1; + strappend(&s_ptr->desc, format("\n%s", s)); } /* Next... */ continue; } - /* Process 'A' for "Activation Description" */ + /* Process 'A' for "Activation Description" (one line only) */ if (buf[0] == 'A') { char *txt; @@ -5708,19 +5687,13 @@ errr init_s_info_txt(FILE *fp, char *buf) *txt = '\0'; txt++; - /* Hack -- Verify space */ - if (s_head->text_size + strlen(txt) + 8 > FAKE_TEXT_SIZE) return (7); + /* Copy action description */ + assert(!s_ptr->action_desc); + s_ptr->action_desc = my_strdup(txt); - /* Advance and Save the text index */ - if (!s_ptr->action_desc) s_ptr->action_desc = ++s_head->text_size; - - /* Append chars to the name */ - strcpy(s_text + s_head->text_size, txt); + /* Copy mkey index */ s_ptr->action_mkey = atoi(s); - /* Advance the index */ - s_head->text_size += strlen(txt); - /* Next... */ continue; } @@ -5794,16 +5767,9 @@ errr init_s_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++s_head->name_size; - ++s_head->text_size; - - /* No version yet */ if (!okay) return (2); - /* Success */ return (0); } -- cgit v1.2.3 From e20d50a1b347d52d9b6e2c2570fe97f196c2c069 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove al_head, al_name --- src/init1.cc | 55 ++++++++++++------------------------------------------- 1 file changed, 12 insertions(+), 43 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 109ec2be..b4180a88 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4509,10 +4509,6 @@ errr init_al_info_txt(FILE *fp, char *buf) /* Just before the first line */ error_line = -1; - /* Fun! */ - al_head->name_size = 0; - *al_name = 0; - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -4715,71 +4711,47 @@ errr init_al_info_txt(FILE *fp, char *buf) if (buf[0] == 'p') { /* Reject if doesn't depend on pval */ - if (!a_ptr->pval) return (1); /* Acquire the description */ s = buf + 2; - /* Hack -- Verify space */ - if (al_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - a_ptr->item_descp = ++al_head->name_size; - - /* Append chars to the name */ - strcpy(al_name + al_head->name_size, s); - - /* Advance the index */ - al_head->name_size += strlen(s); + /* Copy plural description */ + assert(!a_ptr->item_descp); + a_ptr->item_descp = my_strdup(s); /* Next... */ continue; } - /* Process 'D' for "Description" */ + /* Process 'D' for "Description" (one line only) */ if (buf[0] == 'D') { /* Acquire the description */ s = buf + 2; - /* Hack -- Verify space */ - if (al_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - a_ptr->desc = ++al_head->name_size; - - /* Append chars to the name */ - strcpy(al_name + al_head->name_size, s); - - /* Advance the index */ - al_head->name_size += strlen(s); + /* Copy description */ + assert(!a_ptr->desc); + a_ptr->desc = my_strdup(s); /* Next... */ continue; } - /* Process 'd' for "Item Description" */ + /* Process 'd' for "Item Description" (one line only) */ if (buf[0] == 'd') { /* Acquire the name */ s = buf + 2; - /* Hack -- Verify space */ - if (al_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - + /* Reject if we already have a description */ if (a_ptr->item_desc) return (7); - /* Advance and Save the name index */ - a_ptr->item_desc = ++al_head->name_size; - - /* Append chars to the name */ - strcpy(al_name + al_head->name_size, s); - - /* Advance the index */ - al_head->name_size += strlen(s); + /* Copy description */ + assert(!a_ptr->item_desc); + a_ptr->item_desc = my_strdup(s); /* Next... */ continue; @@ -4792,9 +4764,6 @@ errr init_al_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Hack - set the al_head->text_size to byte size of array */ - al_head->text_size = (a_idx + 1) * sizeof(artifact_select_flag); - /* Success */ return (0); } -- cgit v1.2.3 From 1ba4f05af61fbc1b65cf12d140bb4bce6c91e71d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove wf_head, wf_name, wf_text --- src/init1.cc | 43 ++++++++----------------------------------- 1 file changed, 8 insertions(+), 35 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index b4180a88..40fa8605 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -10020,18 +10020,12 @@ errr init_wf_info_txt(FILE *fp, char *buf) /* Current entry */ wilderness_type_info *wf_ptr = NULL; - /* Just before the first record */ error_idx = -1; /* Just before the first line */ error_line = -1; - - /* Start the "fake" stuff */ - wf_head->name_size = 0; - wf_head->text_size = 0; - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -10093,7 +10087,7 @@ errr init_wf_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= wf_head->info_num) return (2); + if (i >= max_wf_idx) return (2); /* Save the index */ error_idx = i; @@ -10101,17 +10095,9 @@ errr init_wf_info_txt(FILE *fp, char *buf) /* Point at the "info" */ wf_ptr = &wf_info[i]; - /* Hack -- Verify space */ - if (wf_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!wf_ptr->name) wf_ptr->name = ++wf_head->name_size; - - /* Append chars to the name */ - strcpy(wf_name + wf_head->name_size, s); - - /* Advance the index */ - wf_head->name_size += strlen(s); + /* Copy the name */ + assert(!wf_ptr->name); + wf_ptr->name = my_strdup(s); /* Next... */ continue; @@ -10120,23 +10106,15 @@ errr init_wf_info_txt(FILE *fp, char *buf) /* There better be a current wf_ptr */ if (!wf_ptr) return (3); - /* Process 'D' for "Description */ + /* Process 'D' for "Description (one line only) */ if (buf[0] == 'D') { /* Acquire the text */ s = buf + 2; - /* Hack -- Verify space */ - if (wf_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - - /* Advance and Save the text index */ - if (!wf_ptr->text) wf_ptr->text = ++wf_head->text_size; - - /* Append chars to the name */ - strcpy(wf_text + wf_head->text_size, s); - - /* Advance the index */ - wf_head->text_size += strlen(s); + /* Copy description */ + assert(!wf_ptr->text); + wf_ptr->text = my_strdup(s); /* Next... */ continue; @@ -10222,11 +10200,6 @@ errr init_wf_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++wf_head->name_size; - ++wf_head->text_size; - /* No version yet */ if (!okay) return (2); -- cgit v1.2.3 From c54c7ab7a45e1729bcd3a238cd296850ba91c55f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove st_head, st_name --- src/init1.cc | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 40fa8605..31d56fed 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -9324,11 +9324,6 @@ errr init_st_info_txt(FILE *fp, char *buf) /* Just before the first line */ error_line = -1; - - /* Start the "fake" stuff */ - st_head->name_size = 0; - st_head->text_size = 0; - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -9390,7 +9385,7 @@ errr init_st_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= st_head->info_num) return (2); + if (i >= max_st_idx) return (2); /* Save the index */ error_idx = i; @@ -9398,17 +9393,9 @@ errr init_st_info_txt(FILE *fp, char *buf) /* Point at the "info" */ st_ptr = &st_info[i]; - /* Hack -- Verify space */ - if (st_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!st_ptr->name) st_ptr->name = ++st_head->name_size; - - /* Append chars to the name */ - strcpy(st_name + st_head->name_size, s); - - /* Advance the index */ - st_head->name_size += strlen(s); + /* Copy name */ + assert(!st_ptr->name); + st_ptr->name = my_strdup(s); /* We are ready for a new set of objects */ item_idx = 0; @@ -9579,11 +9566,6 @@ errr init_st_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++st_head->name_size; - ++st_head->text_size; - /* No version yet */ if (!okay) return (2); -- cgit v1.2.3 From daede88ba01cc86d982ff2f2f40fdf517cb90ab0 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove ba_head, ba_name --- src/init1.cc | 26 ++++---------------------- 1 file changed, 4 insertions(+), 22 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 31d56fed..8ce1524a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -9595,11 +9595,6 @@ errr init_ba_info_txt(FILE *fp, char *buf) /* Just before the first line */ error_line = -1; - - /* Start the "fake" stuff */ - ba_head->name_size = 0; - ba_head->text_size = 0; - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -9661,7 +9656,7 @@ errr init_ba_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= ba_head->info_num) return (2); + if (i >= max_ba_idx) return (2); /* Save the index */ error_idx = i; @@ -9669,17 +9664,9 @@ errr init_ba_info_txt(FILE *fp, char *buf) /* Point at the "info" */ ba_ptr = &ba_info[i]; - /* Hack -- Verify space */ - if (ba_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!ba_ptr->name) ba_ptr->name = ++ba_head->name_size; - - /* Append chars to the name */ - strcpy(ba_name + ba_head->name_size, s); - - /* Advance the index */ - ba_head->name_size += strlen(s); + /* Copy name */ + assert(!ba_ptr->name); + ba_ptr->name = my_strdup(s); /* Next... */ continue; @@ -9731,11 +9718,6 @@ errr init_ba_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++ba_head->name_size; - ++ba_head->text_size; - /* No version yet */ if (!okay) return (2); -- cgit v1.2.3 From 11056413f0457bca511ad6f875219e031a2c3503 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove ow_head, ow_name --- src/init1.cc | 27 ++++----------------------- 1 file changed, 4 insertions(+), 23 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 8ce1524a..79ae95f8 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -9740,18 +9740,12 @@ errr init_ow_info_txt(FILE *fp, char *buf) /* Current entry */ owner_type *ow_ptr = NULL; - /* Just before the first record */ error_idx = -1; /* Just before the first line */ error_line = -1; - - /* Start the "fake" stuff */ - ow_head->name_size = 0; - ow_head->text_size = 0; - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -9813,7 +9807,7 @@ errr init_ow_info_txt(FILE *fp, char *buf) if (i < error_idx) return (4); /* Verify information */ - if (i >= ow_head->info_num) return (2); + if (i >= max_ow_idx) return (2); /* Save the index */ error_idx = i; @@ -9821,17 +9815,9 @@ errr init_ow_info_txt(FILE *fp, char *buf) /* Point at the "info" */ ow_ptr = &ow_info[i]; - /* Hack -- Verify space */ - if (ow_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!ow_ptr->name) ow_ptr->name = ++ow_head->name_size; - - /* Append chars to the name */ - strcpy(ow_name + ow_head->name_size, s); - - /* Advance the index */ - ow_head->name_size += strlen(s); + /* Copy name */ + assert(!ow_ptr->name); + ow_ptr->name = my_strdup(s); /* Next... */ continue; @@ -9933,11 +9919,6 @@ errr init_ow_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++ow_head->name_size; - ++ow_head->text_size; - /* No version yet */ if (!okay) return (2); -- cgit v1.2.3 From 2714df02ad4a4b47745caa149561e3a8c821df45 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:58 +0100 Subject: Remove f_head, f_name, f_text --- src/init1.cc | 74 ++++++++++++------------------------------------------------ 1 file changed, 14 insertions(+), 60 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 79ae95f8..be294cce 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3590,36 +3590,16 @@ errr init_f_info_txt(FILE *fp, char *buf) /* Not ready yet */ bool_ okay = FALSE; - u32b default_desc = 0, default_tunnel = 0, default_block = 0; /* Current entry */ feature_type *f_ptr = NULL; - /* Just before the first record */ error_idx = -1; /* Just before the first line */ error_line = -1; - - /* Prepare the "fake" stuff */ - f_head->name_size = 0; - f_head->text_size = 0; - - /* Add some fake descs */ - default_desc = ++f_head->text_size; - strcpy(f_text + f_head->text_size, "a wall blocking your way"); - f_head->text_size += strlen("a wall blocking your way"); - - default_tunnel = ++f_head->text_size; - strcpy(f_text + f_head->text_size, "You cannot tunnel through that."); - f_head->text_size += strlen("You cannot tunnel through that."); - - default_block = ++f_head->text_size; - strcpy(f_text + f_head->text_size, "a wall blocking your way"); - f_head->text_size += strlen("a wall blocking your way"); - /* Parse */ fp_stack_init(fp); while (0 == my_fgets_dostack(buf, 1024)) @@ -3681,7 +3661,7 @@ errr init_f_info_txt(FILE *fp, char *buf) if (i <= error_idx) return (4); /* Verify information */ - if (i >= f_head->info_num) return (2); + if (i >= max_f_idx) return (2); /* Save the index */ error_idx = i; @@ -3689,24 +3669,15 @@ errr init_f_info_txt(FILE *fp, char *buf) /* Point at the "info" */ f_ptr = &f_info[i]; - /* Hack -- Verify space */ - if (f_head->name_size + strlen(s) + 8 > FAKE_NAME_SIZE) return (7); - - /* Advance and Save the name index */ - if (!f_ptr->name) f_ptr->name = ++f_head->name_size; - - /* Append chars to the name */ - strcpy(f_name + f_head->name_size, s); - - /* Advance the index */ - f_head->name_size += strlen(s); + /* Copy name */ + assert(!f_ptr->name); + f_ptr->name = my_strdup(s); - /* Default "mimic" */ + /* Initialize */ f_ptr->mimic = i; - f_ptr->text = default_desc; - f_ptr->block = default_desc; - f_ptr->tunnel = default_tunnel; - f_ptr->block = default_block; + f_ptr->text = DEFAULT_FEAT_TEXT; + f_ptr->tunnel = DEFAULT_FEAT_TUNNEL; + f_ptr->block = DEFAULT_FEAT_BLOCK; /* Next... */ continue; @@ -3722,34 +3693,24 @@ errr init_f_info_txt(FILE *fp, char *buf) /* Acquire the text */ s = buf + 4; - /* Hack -- Verify space */ - if (f_head->text_size + strlen(s) + 8 > FAKE_TEXT_SIZE) return (7); - switch (buf[2]) { case '0': - /* Advance and Save the text index */ - f_ptr->text = ++f_head->text_size; + assert(f_ptr->text == DEFAULT_FEAT_TEXT); + f_ptr->text = my_strdup(s); break; case '1': - /* Advance and Save the text index */ - f_ptr->tunnel = ++f_head->text_size; + assert(f_ptr->tunnel == DEFAULT_FEAT_TUNNEL); + f_ptr->tunnel = my_strdup(s); break; case '2': - /* Advance and Save the text index */ - f_ptr->block = ++f_head->text_size; + assert(f_ptr->block == DEFAULT_FEAT_BLOCK); + f_ptr->block = my_strdup(s); break; default: return (6); - break; } - /* Append chars to the name */ - strcpy(f_text + f_head->text_size, s); - - /* Advance the index */ - f_head->text_size += strlen(s); - /* Next... */ continue; } @@ -3906,16 +3867,9 @@ errr init_f_info_txt(FILE *fp, char *buf) return (6); } - - /* Complete the "name" and "text" sizes */ - ++f_head->name_size; - ++f_head->text_size; - - /* No version yet */ if (!okay) return (2); - /* Success */ return (0); } -- cgit v1.2.3 From ee2595abc99b86f081acbf5479577f9548baff3b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:59 +0100 Subject: Move gods.cc function declarations to separate header --- src/init1.cc | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index be294cce..d975bd24 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1,8 +1,5 @@ -/* File: init1.c */ - -/* Purpose: Initialization (part 1) -BEN- */ - #include "angband.h" +#include "gods.hpp" #include -- cgit v1.2.3 From dc4b789acb2e6737dd6ed5721b3efbde1a2be14f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:11:59 +0100 Subject: Move skills.cc function declarations to skills.hpp --- src/init1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index d975bd24..08287688 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1,5 +1,6 @@ #include "angband.h" #include "gods.hpp" +#include "skills.hpp" #include -- cgit v1.2.3 From fe6ebd4af16244a02e16eb095181c0d8d5c56858 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move cave.cc function declarations to separate header --- src/init1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 08287688..25e933e7 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1,4 +1,5 @@ #include "angband.h" +#include "cave.hpp" #include "gods.hpp" #include "skills.hpp" -- cgit v1.2.3 From 6cffbd70646ee66c3b2a2a2fd7fd35c23d88b93e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:00 +0100 Subject: Move cmd5.cc function declarations to separate header file Make a few of functions static, remove dead code and fix a few stray declarations while we're at it. --- src/init1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 25e933e7..abe50587 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -2,6 +2,7 @@ #include "cave.hpp" #include "gods.hpp" #include "skills.hpp" +#include "spells5.hpp" #include -- cgit v1.2.3 From f19edf28cf16a0776f54753d953901b91f54e278 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:01 +0100 Subject: Split traps.cc function declarations to separate file --- src/init1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index abe50587..9af6d44c 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3,6 +3,7 @@ #include "gods.hpp" #include "skills.hpp" #include "spells5.hpp" +#include "traps.hpp" #include -- cgit v1.2.3 From 37ac44add61e4547507770017dcb85b53c20acb5 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 23 Feb 2015 09:12:01 +0100 Subject: Split util.cc function declarations into separate header files We need one .h file and one .hpp since some of the functions are being called from plain C code. --- src/init1.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 9af6d44c..f689e940 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4,6 +4,8 @@ #include "skills.hpp" #include "spells5.hpp" #include "traps.hpp" +#include "util.hpp" +#include "util.h" #include -- cgit v1.2.3 From d379c47aaec011921c1d09140ee1098a7053b5b6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:40 +0100 Subject: Split monster2.cc declarations into separate header --- src/init1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index f689e940..b59c4e18 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1,6 +1,7 @@ #include "angband.h" #include "cave.hpp" #include "gods.hpp" +#include "monster2.hpp" #include "skills.hpp" #include "spells5.hpp" #include "traps.hpp" -- cgit v1.2.3 From 7bdfa1a20c8921e53baecdd12b48870417f8b426 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:40 +0100 Subject: Split files.cc declarations into separate header files --- src/init1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index b59c4e18..42b0fb4d 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1,5 +1,6 @@ #include "angband.h" #include "cave.hpp" +#include "files.hpp" #include "gods.hpp" #include "monster2.hpp" #include "skills.hpp" -- cgit v1.2.3 From cfc0a04155eda35a4fe80ef72fd2b0f9eb10856b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:41 +0100 Subject: Split object*.cc declarations into separate header files --- src/init1.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 42b0fb4d..23431fe4 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3,6 +3,8 @@ #include "files.hpp" #include "gods.hpp" #include "monster2.hpp" +#include "object1.hpp" +#include "object2.hpp" #include "skills.hpp" #include "spells5.hpp" #include "traps.hpp" -- cgit v1.2.3 From 5fbaba97d2613e30671a447a10093c4fd9df2e96 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:41 +0100 Subject: Split init1.cc declarations into separate header file --- src/init1.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 23431fe4..b3b1f22d 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1,3 +1,5 @@ +#include "init1.hpp" + #include "angband.h" #include "cave.hpp" #include "files.hpp" -- cgit v1.2.3 From 3d13f588b3927f2a2732959a7702b577a4642d34 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:41 +0100 Subject: Split init2.cc declarations to separate header files --- src/init1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index b3b1f22d..cc6c265e 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4,6 +4,7 @@ #include "cave.hpp" #include "files.hpp" #include "gods.hpp" +#include "init2.hpp" #include "monster2.hpp" #include "object1.hpp" #include "object2.hpp" -- cgit v1.2.3 From f93c700dc8320da438ad46b59b2541e29d9b6d68 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:42 +0100 Subject: Split tables.cc declarations into separate header files --- src/init1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index cc6c265e..fe6abb87 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -10,6 +10,7 @@ #include "object2.hpp" #include "skills.hpp" #include "spells5.hpp" +#include "tables.hpp" #include "traps.hpp" #include "util.hpp" #include "util.h" -- cgit v1.2.3 From 6f612c6e6cf9b20c00fd2f515d3694d2b7f7f444 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 7 Mar 2015 16:55:42 +0100 Subject: Split variables.cc declarations to separate header files - Can now remove externs.h. Yay! - Put a stray option variable into its rightful place in options.hpp --- src/init1.cc | 2 ++ 1 file changed, 2 insertions(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index fe6abb87..93e7d2c0 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -14,6 +14,8 @@ #include "traps.hpp" #include "util.hpp" #include "util.h" +#include "variable.h" +#include "variable.hpp" #include -- cgit v1.2.3 From 7d5abc9c35e080555d1841234497ad1b06528f3a Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 22 Mar 2015 19:32:29 +0100 Subject: Split struct ability_type into separate header file --- src/init1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 93e7d2c0..eb8dc876 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1,6 +1,7 @@ #include "init1.hpp" #include "angband.h" +#include "ability_type.hpp" #include "cave.hpp" #include "files.hpp" #include "gods.hpp" -- cgit v1.2.3 From 237e105406f97bbec0ee42d37d02cec639e5db70 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 7 Jun 2015 17:49:09 +0200 Subject: Remove unused "include" handling for data files --- src/init1.cc | 261 +++++------------------------------------------------------ 1 file changed, 19 insertions(+), 242 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index eb8dc876..276012dd 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1555,77 +1555,6 @@ static void strappend(char **s, const char *t) strcat(*s, t); } -/* - * Implements fp stacks, for included files - */ -static FILE *fp_stack[10]; -static int fp_stack_idx = 0; - -/* - * Must be caleld before the main loop - */ -static void fp_stack_init(FILE *fp) -{ - fp_stack[0] = fp; - fp_stack_idx = 0; -} - -static void fp_stack_push(cptr name) -{ - if (fp_stack_idx < 9) - { - char buf[1024]; - FILE *fp; - - /* Build the filename */ - path_build(buf, 1024, ANGBAND_DIR_EDIT, name); - - /* Open the file */ - fp = my_fopen(buf, "r"); - - /* Parse it */ - if (!fp) quit(format("Cannot open '%s' file.", name)); - - printf("ibncluding %s\n", name); - - fp_stack[++fp_stack_idx] = fp; - } -} - -static bool_ fp_stack_pop() -{ - if (fp_stack_idx > 0) - { - FILE *fp = fp_stack[fp_stack_idx--]; - my_fclose(fp); - return TRUE; - } - else - return FALSE; -} - -/* - * Must be used instead of my_fgets for teh main loop - */ -static int my_fgets_dostack(char *buf, int len) -{ - // End of a file - if (0 != my_fgets(fp_stack[fp_stack_idx], buf, len)) - { - // If any left, use them - if (fp_stack_pop()) - return my_fgets_dostack(buf, len); - // If not, this is the end - else - return 1; - } - else - { - return 0; - } -} - - /*** Initialize from ascii template files ***/ /* @@ -1873,8 +1802,7 @@ errr init_player_info_txt(FILE *fp, char *buf) } /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -1904,13 +1832,6 @@ errr init_player_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Reinit error_idx */ if (buf[0] == 'I') { @@ -3405,8 +3326,7 @@ errr init_v_info_txt(FILE *fp, char *buf) error_line = -1; /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -3437,13 +3357,6 @@ errr init_v_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -3615,8 +3528,7 @@ errr init_f_info_txt(FILE *fp, char *buf) error_line = -1; /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -3646,13 +3558,6 @@ errr init_f_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -4018,8 +3923,7 @@ errr init_k_info_txt(FILE *fp, char *buf) /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -4049,13 +3953,6 @@ errr init_k_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -4478,8 +4375,7 @@ errr init_al_info_txt(FILE *fp, char *buf) error_line = -1; /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -4508,13 +4404,6 @@ errr init_al_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'I' for "Info" (one line only) */ if (buf[0] == 'I') { @@ -4868,8 +4757,7 @@ errr init_a_info_txt(FILE *fp, char *buf) /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -4899,13 +4787,6 @@ errr init_a_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -5177,8 +5058,7 @@ errr init_set_info_txt(FILE *fp, char *buf) /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -5208,13 +5088,6 @@ errr init_set_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -5390,8 +5263,7 @@ errr init_s_info_txt(FILE *fp, char *buf) /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -5421,13 +5293,6 @@ errr init_s_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'T' for "skill Tree" */ if (buf[0] == 'T') { @@ -5735,8 +5600,7 @@ errr init_ab_info_txt(FILE *fp, char *buf) /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -5766,13 +5630,6 @@ errr init_ab_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -6264,8 +6121,7 @@ errr init_e_info_txt(FILE *fp, char *buf) /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -6295,13 +6151,6 @@ errr init_e_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -6775,8 +6624,7 @@ errr init_ra_info_txt(FILE *fp, char *buf) /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -6806,13 +6654,6 @@ errr init_ra_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'G' for "General" (up to 30 lines) */ if (buf[0] == 'G') { @@ -7182,8 +7023,7 @@ errr init_r_info_txt(FILE *fp, char *buf) /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -7213,13 +7053,6 @@ errr init_r_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -7802,8 +7635,7 @@ errr init_re_info_txt(FILE *fp, char *buf) error_line = -1; /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -7833,13 +7665,6 @@ errr init_re_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -8325,8 +8150,7 @@ errr init_t_info_txt(FILE *fp, char *buf) error_line = -1; /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -8356,13 +8180,6 @@ errr init_t_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -8671,8 +8488,7 @@ errr init_d_info_txt(FILE *fp, char *buf) error_line = -1; /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -8702,13 +8518,6 @@ errr init_d_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -9293,8 +9102,7 @@ errr init_st_info_txt(FILE *fp, char *buf) error_line = -1; /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -9324,13 +9132,6 @@ errr init_st_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -9564,8 +9365,7 @@ errr init_ba_info_txt(FILE *fp, char *buf) error_line = -1; /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -9595,13 +9395,6 @@ errr init_ba_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -9715,8 +9508,7 @@ errr init_ow_info_txt(FILE *fp, char *buf) error_line = -1; /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -9746,13 +9538,6 @@ errr init_ow_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -9940,8 +9725,7 @@ errr init_wf_info_txt(FILE *fp, char *buf) error_line = -1; /* Parse */ - fp_stack_init(fp); - while (0 == my_fgets_dostack(buf, 1024)) + while (0 == my_fgets(fp, buf, 1024)) { /* Advance the line number */ error_line++; @@ -9971,13 +9755,6 @@ errr init_wf_info_txt(FILE *fp, char *buf) /* No version yet */ if (!okay) return (2); - /* Included file */ - if (buf[0] == '<') - { - fp_stack_push(buf + 2); - continue; - } - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { -- cgit v1.2.3 From 9dea3ca3085db413860d5923b5405841a4e1f784 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 7 Jun 2015 17:49:09 +0200 Subject: Reduce scope of buffer for data parsing functions --- src/init1.cc | 72 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 38 insertions(+), 34 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 276012dd..30eed949 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1764,7 +1764,7 @@ static errr grab_one_race_kind_flag(u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b /* * Initialize the "player" arrays, by parsing an ascii "template" file */ -errr init_player_info_txt(FILE *fp, char *buf) +errr init_player_info_txt(FILE *fp) { int i = 0, z; int powers = 0; @@ -1772,7 +1772,7 @@ errr init_player_info_txt(FILE *fp, char *buf) int tit_idx = 0; int spec_idx = 0; int cur_ab = -1; - + char buf[1024]; char *s, *t; /* Not ready yet */ @@ -3308,9 +3308,10 @@ errr init_player_info_txt(FILE *fp, char *buf) /* * Initialize the "v_info" array, by parsing an ascii "template" file */ -errr init_v_info_txt(FILE *fp, char *buf) +errr init_v_info_txt(FILE *fp) { int i; + char buf[1024]; char *s; /* Not ready yet */ @@ -3509,10 +3510,10 @@ static errr grab_one_feature_flag(feature_type *f_ptr, cptr what) /* * Initialize the "f_info" array, by parsing an ascii "template" file */ -errr init_f_info_txt(FILE *fp, char *buf) +errr init_f_info_txt(FILE *fp) { int i; - + char buf[1024]; char *s, *t; /* Not ready yet */ @@ -3902,10 +3903,10 @@ static errr grab_one_kind_flag(object_kind *k_ptr, cptr what, bool_ obvious) /* * Initialize the "k_info" array, by parsing an ascii "template" file */ -errr init_k_info_txt(FILE *fp, char *buf) +errr init_k_info_txt(FILE *fp) { int i; - + char buf[1024]; char *s, *t; /* Not ready yet */ @@ -4359,11 +4360,12 @@ int init_al_info_essence(char *essence) /* * Initialize the "al_info" array, by parsing an ascii "template" file */ -errr init_al_info_txt(FILE *fp, char *buf) +errr init_al_info_txt(FILE *fp) { int al_idx = 0, a_idx = 0; char *s, *t; struct artifact_select_flag *a_ptr = NULL; + char buf[1024]; /* Not ready yet */ bool_ okay = FALSE; @@ -4736,10 +4738,10 @@ static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what, bool_ obviou /* * Initialize the "a_info" array, by parsing an ascii "template" file */ -errr init_a_info_txt(FILE *fp, char *buf) +errr init_a_info_txt(FILE *fp) { int i; - + char buf[1024]; char *s, *t; /* Not ready yet */ @@ -5036,10 +5038,11 @@ errr init_a_info_txt(FILE *fp, char *buf) /* * Initialize the "set_info" array, by parsing an ascii "template" file */ -errr init_set_info_txt(FILE *fp, char *buf) +errr init_set_info_txt(FILE *fp) { int i; int cur_art = 0, cur_num = 0; + char buf[1024]; char *s, *t; @@ -5242,10 +5245,10 @@ errr init_set_info_txt(FILE *fp, char *buf) /* * Initialize the "s_info" array, by parsing an ascii "template" file */ -errr init_s_info_txt(FILE *fp, char *buf) +errr init_s_info_txt(FILE *fp) { int i, z, order = 1; - + char buf[1024]; char *s; /* Not ready yet */ @@ -5579,10 +5582,10 @@ errr init_s_info_txt(FILE *fp, char *buf) /* * Initialize the "ab_info" array, by parsing an ascii "template" file */ -errr init_ab_info_txt(FILE *fp, char *buf) +errr init_ab_info_txt(FILE *fp) { int i, z; - + char buf[1024]; char *s; /* Not ready yet */ @@ -6100,10 +6103,10 @@ static bool_ grab_one_ego_item_flag_restrict(ego_item_type *e_ptr, cptr what, bo /* * Initialize the "e_info" array, by parsing an ascii "template" file */ -errr init_e_info_txt(FILE *fp, char *buf) +errr init_e_info_txt(FILE *fp) { int i, cur_r = -1, cur_t = 0, j; - + char buf[1024]; char *s, *t; /* Not ready yet */ @@ -6603,10 +6606,10 @@ static bool_ grab_one_randart_item_flag(randart_part_type *ra_ptr, cptr what, ch /* * Initialize the "ra_info" array, by parsing an ascii "template" file */ -errr init_ra_info_txt(FILE *fp, char *buf) +errr init_ra_info_txt(FILE *fp) { int i, cur_t = 0, j, cur_g = 0; - + char buf[1024]; char *s, *t; /* Not ready yet */ @@ -7002,10 +7005,10 @@ static errr grab_one_spell_flag(monster_race *r_ptr, cptr what) /* * Initialize the "r_info" array, by parsing an ascii "template" file */ -errr init_r_info_txt(FILE *fp, char *buf) +errr init_r_info_txt(FILE *fp) { int i; - + char buf[1024]; char *s, *t; /* Not ready yet */ @@ -7612,10 +7615,10 @@ static errr grab_one_ego_flag(monster_ego *re_ptr, cptr what, bool_ must) /* * Initialize the "re_info" array, by parsing an ascii "template" file */ -errr init_re_info_txt(FILE *fp, char *buf) +errr init_re_info_txt(FILE *fp) { int i, j; - + char buf[1024]; byte blow_num = 0; int r_char_number = 0, nr_char_number = 0; @@ -8131,10 +8134,10 @@ static errr grab_one_trap_type_flag(trap_type *t_ptr, cptr what) /* * Initialize the "tr_info" array, by parsing an ascii "template" file */ -errr init_t_info_txt(FILE *fp, char *buf) +errr init_t_info_txt(FILE *fp) { int i; - + char buf[1024]; char *s, *t; /* Not ready yet */ @@ -8464,9 +8467,10 @@ static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what, byt /* * Initialize the "d_info" array, by parsing an ascii "template" file */ -errr init_d_info_txt(FILE *fp, char *buf) +errr init_d_info_txt(FILE *fp) { int i, j; + char buf[1024]; s16b rule_num = 0; @@ -9082,10 +9086,10 @@ static errr grab_one_store_flag(store_info_type *st_ptr, cptr what) /* * Initialize the "st_info" array, by parsing an ascii "template" file */ -errr init_st_info_txt(FILE *fp, char *buf) +errr init_st_info_txt(FILE *fp) { int i = 0, item_idx = 0; - + char buf[1024]; char *s, *t; /* Not ready yet */ @@ -9345,10 +9349,10 @@ errr init_st_info_txt(FILE *fp, char *buf) /* * Initialize the "ba_info" array, by parsing an ascii "template" file */ -errr init_ba_info_txt(FILE *fp, char *buf) +errr init_ba_info_txt(FILE *fp) { int i = 0; - + char buf[1024]; char *s; /* Not ready yet */ @@ -9489,10 +9493,10 @@ errr init_ba_info_txt(FILE *fp, char *buf) /* * Initialize the "ow_info" array, by parsing an ascii "template" file */ -errr init_ow_info_txt(FILE *fp, char *buf) +errr init_ow_info_txt(FILE *fp) { int i; - + char buf[1024]; char *s, *t; /* Not ready yet */ @@ -9706,10 +9710,10 @@ static errr grab_one_wf_info_flag(wilderness_type_info *wf_ptr, cptr what) /* * Initialize the "wf_info" array, by parsing an ascii "template" file */ -errr init_wf_info_txt(FILE *fp, char *buf) +errr init_wf_info_txt(FILE *fp) { int i; - + char buf[1024]; char *s, *t; /* Not ready yet */ -- cgit v1.2.3 From c8a270e51dc22f39ed048ab1cc609e6e456df58f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 7 Jun 2015 17:49:09 +0200 Subject: Split types.h into separate header for each type --- src/init1.cc | 32 +++++++++++++++++++++++++++++++- 1 file changed, 31 insertions(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 30eed949..a1d2b7a7 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1,22 +1,51 @@ #include "init1.hpp" -#include "angband.h" #include "ability_type.hpp" +#include "alchemist_recipe.hpp" +#include "artifact_type.hpp" +#include "artifact_select_flag.hpp" #include "cave.hpp" +#include "cave_type.hpp" +#include "dungeon_info_type.hpp" +#include "ego_item_type.hpp" +#include "feature_type.hpp" #include "files.hpp" #include "gods.hpp" +#include "hist_type.hpp" #include "init2.hpp" +#include "meta_class_type.hpp" #include "monster2.hpp" +#include "monster_ego.hpp" +#include "monster_race.hpp" +#include "monster_type.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_kind.hpp" +#include "owner_type.hpp" +#include "player_class.hpp" +#include "player_race.hpp" +#include "player_race_mod.hpp" +#include "player_type.hpp" +#include "randart_gen_type.hpp" +#include "randart_part_type.hpp" +#include "set_type.hpp" +#include "skill_type.hpp" #include "skills.hpp" #include "spells5.hpp" +#include "store_action_type.hpp" +#include "store_info_type.hpp" +#include "store_type.hpp" #include "tables.hpp" +#include "town_type.hpp" +#include "trap_type.hpp" #include "traps.hpp" #include "util.hpp" #include "util.h" #include "variable.h" #include "variable.hpp" +#include "vault_type.hpp" +#include "wilderness_map.hpp" +#include "wilderness_type_info.hpp" #include @@ -9202,6 +9231,7 @@ errr init_st_info_txt(FILE *fp) st_ptr->table[item_idx++][0] = test_item_name(s); st_ptr->table_num = item_idx; + assert(st_ptr->table_num <= STORE_CHOICES); /* Next... */ continue; -- cgit v1.2.3 From baa22bb096d08b6304b0dada144fec128ac69974 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 21 Aug 2015 21:06:13 +0200 Subject: Remove unused IM_MELEE flag --- src/init1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index a1d2b7a7..fdf87da2 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -411,7 +411,7 @@ static cptr r_info_flags7[] = "AI_PLAYER", "NO_THEFT", "SPIRIT", - "IM_MELEE", + "XXX7X20", "XXX7X21", "XXX7X22", "XXX7X23", -- cgit v1.2.3 From 47fb7807d77c92fa6e72017501d9355d780adf40 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 14 Sep 2015 06:03:01 +0200 Subject: Remove TR4_ANTIMAGIC_{30,20,10} flags They're only used for the Antimagic realm of leveling items and we might as well use ANTIMAGIC_50 there, given the rarity of the flag. --- src/init1.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index fdf87da2..1f2023f0 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -685,9 +685,9 @@ cptr k_info_flags4[] = "CHEAPNESS", "FOUNTAIN", "ANTIMAGIC_50", - "ANTIMAGIC_30", - "ANTIMAGIC_20", - "ANTIMAGIC_10", + "XXX5", + "XXX5", + "XXX5", "EASY_USE", "IM_NETHER", "RECHARGED", -- cgit v1.2.3 From 33e7dc3baa6b375efb6d8989ffe3c50511291228 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Remove Alchemist class and associated skills/code Alchemy has always been ridiculously broken and there's been a huge amount of horrible code to support it. Sorry to any fans of Alchemy, but it's got to go. --- src/init1.cc | 383 +---------------------------------------------------------- 1 file changed, 1 insertion(+), 382 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 1f2023f0..d9ad1ccf 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1,9 +1,7 @@ #include "init1.hpp" #include "ability_type.hpp" -#include "alchemist_recipe.hpp" #include "artifact_type.hpp" -#include "artifact_select_flag.hpp" #include "cave.hpp" #include "cave_type.hpp" #include "dungeon_info_type.hpp" @@ -696,7 +694,7 @@ cptr k_info_flags4[] = "LITE2", "LITE3", "FUEL_LITE", - "ART_EXP", + "XXX5", "CURSE_NO_DROP", "NO_RECHARGE" }; @@ -1215,30 +1213,6 @@ d_info_dtypes[] = {NULL, 0} }; -/* Essence names for al_info.txt */ -static const char *essence_names[] = -{ - "No name here", /* can't be matched, sscanf stops at spaces */ - "POISON", - "EXPLOSION", - "TELEPORT", - "COLD", - "FIRE", - "ACID", - "LIFE", - "CONFUSION", - "LITE", - "CHAOS", - "TIME", - "MAGIC", - "EXTRALIFE", - "DARKNESS", - "KNOWLEDGE", - "FORCE", - "LIGHTNING", - "MANA", - "" -}; static const char *activation_names[] = { "NO_ACTIVATION", /* 0*/ @@ -4307,355 +4281,6 @@ errr init_k_info_txt(FILE *fp) return (0); } -/*Get a kind flag, return flag*32+bit number or -1 for unknown*/ - -int get_k_flag(char *what) -{ - int i; - - /* Check flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags1[i])) - return i; - if (streq(what, k_info_flags2[i])) - return 1*32 + i; - if (streq(what, k_info_flags2_trap[i])) - return 1*32 + i; - if (streq(what, k_info_flags3[i])) - return 2*32 + i; - if (streq(what, k_info_flags4[i])) - return 3*32 + i; - if (streq(what, k_info_flags5[i])) - return 4*32 + i; - if (streq(what, esp_flags[i])) - return 5*32 + i; - } - - /* Oops */ - msg_format("Unknown object flag '%s'.", what); - - /* Error */ - return ( -1); - -} - -int get_r_flag(char *what) -{ - int i; - - /* Check flags */ - /* this processes all r_info_flag arrays in parallel. - Seemed like a good idea at the time.. - */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags1[i])) - return i; - if (streq(what, r_info_flags2[i])) - return 1*32 + i; - if (streq(what, r_info_flags3[i])) - return 2*32 + i; - if (streq(what, r_info_flags4[i])) - return 3*32 + i; - if (streq(what, r_info_flags5[i])) - return 4*32 + i; - if (streq(what, r_info_flags6[i])) - return 5*32 + i; - if (streq(what, r_info_flags7[i])) - return 6*32 + i; - if (streq(what, r_info_flags8[i])) - return 7*32 + i; - if (streq(what, r_info_flags9[i])) - return 8*32 + i; - } - - /* Oops */ - msg_format("Unknown race flag '%s'.", what); - - /* Error */ - return ( -1); -} -int init_al_info_essence(char *essence) -{ - int i; - for ( i = 0 ; essence_names[i][0] ; i++) - if (!strncmp(essence_names[i], essence, 9)) - { - return i; - } - return -1; -} -/* - * Initialize the "al_info" array, by parsing an ascii "template" file - */ -errr init_al_info_txt(FILE *fp) -{ - int al_idx = 0, a_idx = 0; - char *s, *t; - struct artifact_select_flag *a_ptr = NULL; - char buf[1024]; - - /* Not ready yet */ - bool_ okay = FALSE; - - /* Just before the first record */ - error_idx = -1; - - /* Just before the first line */ - error_line = -1; - - /* Parse */ - while (0 == my_fgets(fp, buf, 1024)) - { - /* Advance the line number */ - error_line++; - - /* Skip comments and blank lines */ - if (!buf[0] || (buf[0] == '#')) continue; - - /* Verify correct "colon" format */ - if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - - /* Process 'I' for "Info" (one line only) */ - if (buf[0] == 'I') - { - int tval, sval, qty; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d:%d:%d", - &tval, &sval, &qty)) - { - return (1); - } - - /* ignore everything after the first space. */ - s = strchr(buf, ' '); - if (s != NULL) - *s = 0; - - /* Save the values */ - alchemist_recipes[al_idx].tval = tval; - alchemist_recipes[al_idx].sval = sval; - alchemist_recipes[al_idx].qty = qty; - alchemist_recipes[al_idx].sval_essence = init_al_info_essence(strrchr(buf, ':') + 1); - if (alchemist_recipes[al_idx].sval_essence < 0) - return 5; - - al_idx++; - if (al_idx >= max_al_idx) - return 7; - /* Next... */ - continue; - } - if (buf[0] == 'a') - { - int qty; - if ( 1 != sscanf(buf + 2, "%d", &qty)) - { - return (1); - } - s = strrchr(buf, ':'); - *(s++) = 0; - t = strchr(s, ' '); - *(t++) = 0; - alchemist_recipes[al_idx].tval = 0; - alchemist_recipes[al_idx].sval = get_k_flag(s); - alchemist_recipes[al_idx].qty = qty; - alchemist_recipes[al_idx].sval_essence = init_al_info_essence(t); - if (alchemist_recipes[al_idx].sval_essence < 0) - return 1; - - al_idx++; - if (al_idx >= max_al_idx) - return 7; /* 7 is an 'out of memory' error */ - - continue; - } - if (buf[0] == 'A') - { - int group, level, pval, rtval, rsval, rpval; - long xp; - /*Verify that complete description information is - Recorded for previous Artifact flag - */ - if (a_ptr - && (!a_ptr->group || !a_ptr->desc || !a_ptr->item_desc != !a_ptr->rtval) - ) - return (1); - - a_ptr = &a_select_flags[a_idx++]; - - if ( 7 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d:%ld", - &group, &rtval, &rsval, &rpval, &pval, &level, &xp)) - return (1); - a_ptr->group = group; - a_ptr->rtval = rtval; - a_ptr->rsval = rsval; - a_ptr->rpval = rpval; - a_ptr->pval = pval; - a_ptr->level = level; - a_ptr->xp = xp; - continue; - } - - /*Anything else here MUST be a artifact flag line*/ - if ( !a_ptr) - return (3); - - if (buf[0] == 'F') - { - /* Get the Item flag associated with this */ - a_ptr->flag = get_k_flag(buf + 2); - if (a_ptr->flag == -1) - return (1); - continue; - } - if (buf[0] == 'x') - { - /* Get the activation name associated with this */ - a_ptr->flag = -get_activation(buf + 2); - if (a_ptr->flag == 1) - return (1); - a_ptr->group = 88; - a_ptr->pval = 0; - continue; - } - /* Get the race flags associated with this */ - if (buf[0] == 'f') - { - char *s, *t; - int idx = 0; - - if ( a_ptr->rflag[0] ) - { - msg_print("duplicate f: entries for one corpse"); - return (5); - } - - if ( a_ptr->rtval != TV_CORPSE ) - { - msg_print("f: section for corpse flags only"); - return (5); - } - if ( a_ptr->rpval ) - { - msg_print("Can't specify r_info.txt index with f: section"); - return (5); - } - - /* Parse every entry textually */ - for (s = buf + 2; *s; ) - { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while ((*t == ' ') || (*t == '|')) t++; - } - - if ( idx > 5 ) - { - msg_print("Limit on race flags is currently 6"); - return (5); - } - - /* Parse this entry */ - a_ptr->rflag[idx] = get_r_flag(s); - if (a_ptr->rflag[idx++] == -1) - return (5); - - /* Start the next entry */ - s = t; - } - - /* Next... */ - continue; - } - - /* Process 'p' for "Plural Description" */ - /* Only valid for flag which depend on pval */ - if (buf[0] == 'p') - { - /* Reject if doesn't depend on pval */ - if (!a_ptr->pval) - return (1); - - /* Acquire the description */ - s = buf + 2; - - /* Copy plural description */ - assert(!a_ptr->item_descp); - a_ptr->item_descp = my_strdup(s); - - /* Next... */ - continue; - } - - /* Process 'D' for "Description" (one line only) */ - if (buf[0] == 'D') - { - /* Acquire the description */ - s = buf + 2; - - /* Copy description */ - assert(!a_ptr->desc); - a_ptr->desc = my_strdup(s); - - /* Next... */ - continue; - } - - /* Process 'd' for "Item Description" (one line only) */ - if (buf[0] == 'd') - { - /* Acquire the name */ - s = buf + 2; - - /* Reject if we already have a description */ - if (a_ptr->item_desc) - return (7); - - /* Copy description */ - assert(!a_ptr->item_desc); - a_ptr->item_desc = my_strdup(s); - - /* Next... */ - continue; - } - - /* Oops */ - return (6); - } - - /* No version yet */ - if (!okay) return (2); - - /* Success */ - return (0); -} - /* * Grab one flag in an artifact_type from a textual string */ @@ -10619,12 +10244,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_a_idx = atoi(zz[1]); } - /* Maximum al_idx */ - else if (zz[0][0] == 'a') - { - max_al_idx = atoi(zz[1]); - } - /* Maximum e_idx */ else if (zz[0][0] == 'E') { -- cgit v1.2.3 From 158518061b09bb478140ede11c21bd1536814e0e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Remove ANGBAND_GRAF --- src/init1.cc | 6 ------ 1 file changed, 6 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index d9ad1ccf..216b655b 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -10536,12 +10536,6 @@ static cptr process_dungeon_file_expr(char **sp, char *fp) v = ANGBAND_SYS; } - /* Graphics */ - else if (streq(b + 1, "GRAF")) - { - v = ANGBAND_GRAF; - } - /* Race */ else if (streq(b + 1, "RACE")) { -- cgit v1.2.3 From 97bcf1bc612d9920390c885b8dcea0b0cda6f246 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Migrate z-rand.c to C++ - Include explicitly instead of via angband.h - Change to regular functions instead of macros. --- src/init1.cc | 1 + 1 file changed, 1 insertion(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 216b655b..66624ec3 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -44,6 +44,7 @@ #include "vault_type.hpp" #include "wilderness_map.hpp" #include "wilderness_type_info.hpp" +#include "z-rand.hpp" #include -- cgit v1.2.3 From bb7e2c66a403a9e0af291a539bfb4e7bc9ebca92 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Remove useless V: lines from data files --- src/init1.cc | 459 ----------------------------------------------------------- 1 file changed, 459 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 66624ec3..ec3b768c 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1779,9 +1779,6 @@ errr init_player_info_txt(FILE *fp) char buf[1024]; char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ player_race *rp_ptr = NULL; player_race_mod *rmp_ptr = NULL; @@ -1817,25 +1814,6 @@ errr init_player_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Reinit error_idx */ if (buf[0] == 'I') { @@ -3301,9 +3279,6 @@ errr init_player_info_txt(FILE *fp) return (6); } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -3318,9 +3293,6 @@ errr init_v_info_txt(FILE *fp) char buf[1024]; char *s; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ vault_type *v_ptr = NULL; @@ -3343,25 +3315,6 @@ errr init_v_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf, "V:%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -3477,10 +3430,6 @@ errr init_v_info_txt(FILE *fp) } - /* No version yet */ - if (!okay) return (2); - - /* Success */ return (0); } @@ -3520,9 +3469,6 @@ errr init_f_info_txt(FILE *fp) char buf[1024]; char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ feature_type *f_ptr = NULL; @@ -3544,25 +3490,6 @@ errr init_f_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -3791,9 +3718,6 @@ errr init_f_info_txt(FILE *fp) return (6); } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -3913,9 +3837,6 @@ errr init_k_info_txt(FILE *fp) char buf[1024]; char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ object_kind *k_ptr = NULL; @@ -3940,24 +3861,6 @@ errr init_k_info_txt(FILE *fp) if (buf[1] != ':') return (1); - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -4273,11 +4176,6 @@ errr init_k_info_txt(FILE *fp) return (6); } - - /* No version yet */ - if (!okay) return (2); - - /* Success */ return (0); } @@ -4399,9 +4297,6 @@ errr init_a_info_txt(FILE *fp) char buf[1024]; char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ artifact_type *a_ptr = NULL; @@ -4425,25 +4320,6 @@ errr init_a_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -4681,11 +4557,6 @@ errr init_a_info_txt(FILE *fp) return (6); } - - /* No version yet */ - if (!okay) return (2); - - /* Success */ return (0); } @@ -4701,9 +4572,6 @@ errr init_set_info_txt(FILE *fp) char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ set_type *set_ptr = NULL; @@ -4727,25 +4595,6 @@ errr init_set_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -4889,9 +4738,6 @@ errr init_set_info_txt(FILE *fp) return (6); } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -4906,9 +4752,6 @@ errr init_s_info_txt(FILE *fp) char buf[1024]; char *s; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ skill_type *s_ptr = NULL; @@ -4932,25 +4775,6 @@ errr init_s_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'T' for "skill Tree" */ if (buf[0] == 'T') { @@ -5227,9 +5051,6 @@ errr init_s_info_txt(FILE *fp) return (6); } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -5243,9 +5064,6 @@ errr init_ab_info_txt(FILE *fp) char buf[1024]; char *s; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ ability_type *ab_ptr = NULL; @@ -5269,25 +5087,6 @@ errr init_ab_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -5526,9 +5325,6 @@ errr init_ab_info_txt(FILE *fp) return (6); } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -5764,9 +5560,6 @@ errr init_e_info_txt(FILE *fp) char buf[1024]; char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ ego_item_type *e_ptr = NULL; @@ -5790,25 +5583,6 @@ errr init_e_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -6129,11 +5903,6 @@ errr init_e_info_txt(FILE *fp) return (6); } - - /* No version yet */ - if (!okay) return (2); - - /* Success */ return (0); } @@ -6267,9 +6036,6 @@ errr init_ra_info_txt(FILE *fp) char buf[1024]; char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ randart_part_type *ra_ptr = NULL; @@ -6293,25 +6059,6 @@ errr init_ra_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'G' for "General" (up to 30 lines) */ if (buf[0] == 'G') { @@ -6528,11 +6275,6 @@ errr init_ra_info_txt(FILE *fp) return (6); } - - /* No version yet */ - if (!okay) return (2); - - /* Success */ return (0); } @@ -6666,9 +6408,6 @@ errr init_r_info_txt(FILE *fp) char buf[1024]; char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ monster_race *r_ptr = NULL; @@ -6692,25 +6431,6 @@ errr init_r_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -7033,9 +6753,6 @@ errr init_r_info_txt(FILE *fp) r_info[i].flags8 = 0x0463; } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -7279,9 +6996,6 @@ errr init_re_info_txt(FILE *fp) char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ monster_ego *re_ptr = NULL; @@ -7304,25 +7018,6 @@ errr init_re_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -7754,9 +7449,6 @@ errr init_re_info_txt(FILE *fp) return (6); } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -7795,9 +7487,6 @@ errr init_t_info_txt(FILE *fp) char buf[1024]; char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ trap_type *t_ptr = NULL; @@ -7819,25 +7508,6 @@ errr init_t_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -7959,9 +7629,6 @@ errr init_t_info_txt(FILE *fp) return (6); } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -8133,9 +7800,6 @@ errr init_d_info_txt(FILE *fp) char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ dungeon_info_type *d_ptr = NULL; @@ -8158,25 +7822,6 @@ errr init_d_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -8675,10 +8320,6 @@ errr init_d_info_txt(FILE *fp) return (6); } - - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -8747,9 +8388,6 @@ errr init_st_info_txt(FILE *fp) char buf[1024]; char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ store_info_type *st_ptr = NULL; @@ -8772,25 +8410,6 @@ errr init_st_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -8995,9 +8614,6 @@ errr init_st_info_txt(FILE *fp) return (6); } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -9011,9 +8627,6 @@ errr init_ba_info_txt(FILE *fp) char buf[1024]; char *s; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ store_action_type *ba_ptr = NULL; @@ -9036,25 +8649,6 @@ errr init_ba_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -9139,9 +8733,6 @@ errr init_ba_info_txt(FILE *fp) return (6); } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -9155,9 +8746,6 @@ errr init_ow_info_txt(FILE *fp) char buf[1024]; char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ owner_type *ow_ptr = NULL; @@ -9179,25 +8767,6 @@ errr init_ow_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -9332,9 +8901,6 @@ errr init_ow_info_txt(FILE *fp) return (6); } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } @@ -9372,9 +8938,6 @@ errr init_wf_info_txt(FILE *fp) char buf[1024]; char *s, *t; - /* Not ready yet */ - bool_ okay = FALSE; - /* Current entry */ wilderness_type_info *wf_ptr = NULL; @@ -9396,25 +8959,6 @@ errr init_wf_info_txt(FILE *fp) /* Verify correct "colon" format */ if (buf[1] != ':') return (1); - - /* Hack -- Process 'V' for "Version" */ - if (buf[0] == 'V') - { - int v1, v2, v3; - - /* Scan for the values */ - if (3 != sscanf(buf + 2, "%d.%d.%d", &v1, &v2, &v3)) return (2); - - /* Okay to proceed */ - okay = TRUE; - - /* Continue */ - continue; - } - - /* No version yet */ - if (!okay) return (2); - /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { @@ -9550,9 +9094,6 @@ errr init_wf_info_txt(FILE *fp) return (6); } - /* No version yet */ - if (!okay) return (2); - /* Success */ return (0); } -- cgit v1.2.3 From cb7d0c75f4bc7dc4810fc0d1db4723c0079d4d72 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Remove unused object_kind field "extra" --- src/init1.cc | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index ec3b768c..d9474e63 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3989,16 +3989,15 @@ errr init_k_info_txt(FILE *fp) /* Process 'W' for "More Info" (one line only) */ if (buf[0] == 'W') { - int level, extra, wgt; + int level, unused, wgt; long cost; /* Scan for the values */ if (4 != sscanf(buf + 2, "%d:%d:%d:%ld", - &level, &extra, &wgt, &cost)) return (1); + &level, &unused, &wgt, &cost)) return (1); /* Save the values */ k_ptr->level = level; - k_ptr->extra = extra; k_ptr->weight = wgt; k_ptr->cost = cost; -- cgit v1.2.3 From e119442d5ddbaa081b583e7ff6346b4f3933704e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 11 Dec 2015 08:09:30 +0100 Subject: Remove unused wf_info flag handling code --- src/init1.cc | 93 +----------------------------------------------------------- 1 file changed, 1 insertion(+), 92 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index d9474e63..7083a5f3 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -970,46 +970,6 @@ static cptr t_info_flags[] = "XXX32" }; -/* - * Wilderness feature flags - */ -static cptr wf_info_flags1[] = -{ - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1" -}; - /* * Stores flags */ @@ -8904,30 +8864,6 @@ errr init_ow_info_txt(FILE *fp) return (0); } -/* - * Grab one flag for a dungeon type from a textual string - */ -static errr grab_one_wf_info_flag(wilderness_type_info *wf_ptr, cptr what) -{ - int i; - - /* Scan flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, wf_info_flags1[i])) - { - wf_ptr->flags1 |= (1L << i); - return (0); - } - } - - /* Oops */ - msg_format("Unknown monster flag '%s'.", what); - - /* Failure */ - return (1); -} - /* * Initialize the "wf_info" array, by parsing an ascii "template" file */ @@ -8935,7 +8871,7 @@ errr init_wf_info_txt(FILE *fp) { int i; char buf[1024]; - char *s, *t; + char *s; /* Current entry */ wilderness_type_info *wf_ptr = NULL; @@ -9062,33 +8998,6 @@ errr init_wf_info_txt(FILE *fp) continue; } - /* Process 'F' for "Wilderness feature Flags" (multiple lines) */ - if (buf[0] == 'F') - { - /* Parse every entry */ - for (s = buf + 2; *s; ) - { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_wf_info_flag(wf_ptr, s)) return (5); - - /* Start the next entry */ - s = t; - } - - /* Next... */ - continue; - } - /* Oops */ return (6); } -- cgit v1.2.3 From 959f8c09f32e6b431bc4f7af8d1a5c296cefdafe Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Fri, 5 Feb 2016 19:22:46 +0100 Subject: Remove unused dungeon_info_type::next --- src/init1.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 7083a5f3..9d221c01 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -7876,18 +7876,17 @@ errr init_d_info_txt(FILE *fp) if (buf[0] == 'W') { int min_lev, max_lev; - int min_plev, next; + int min_plev; int min_alloc, max_chance; /* Scan for the values */ - if (6 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%d", - &min_lev, &max_lev, &min_plev, &next, &min_alloc, &max_chance)) return (1); + if (5 != sscanf(buf + 2, "%d:%d:%d:%d:%d", + &min_lev, &max_lev, &min_plev, &min_alloc, &max_chance)) return (1); /* Save the values */ d_ptr->mindepth = min_lev; d_ptr->maxdepth = max_lev; d_ptr->min_plev = min_plev; - d_ptr->next = next; d_ptr->min_m_alloc_level = min_alloc; d_ptr->max_m_alloc_chance = max_chance; -- cgit v1.2.3 From a343ccf6b05df1d889cb4302a3e9e21c4816c048 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 10 Mar 2016 18:41:54 +0100 Subject: Remove player gender, age, height, etc. --- src/init1.cc | 48 ------------------------------------------------ 1 file changed, 48 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 9d221c01..31e8c55a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -2026,30 +2026,6 @@ errr init_player_info_txt(FILE *fp) continue; } - /* Process 'M' for "Mods" */ - if ((buf[0] == 'R') && (buf[2] == 'M')) - { - int s[10]; - - /* Scan for the values */ - if (10 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", - &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8], &s[9])) return (1); - - rp_ptr->b_age = s[0]; - rp_ptr->m_age = s[1]; - rp_ptr->m_b_ht = s[2]; - rp_ptr->m_m_ht = s[3]; - rp_ptr->m_b_wt = s[4]; - rp_ptr->m_m_wt = s[5]; - rp_ptr->f_b_ht = s[6]; - rp_ptr->f_m_ht = s[7]; - rp_ptr->f_b_wt = s[8]; - rp_ptr->f_m_wt = s[9]; - - /* Next... */ - continue; - } - /* Process 'P' for "xtra" */ if ((buf[0] == 'R') && (buf[2] == 'P')) { @@ -2392,30 +2368,6 @@ errr init_player_info_txt(FILE *fp) continue; } - /* Process 'M' for "Mods" */ - if ((buf[0] == 'S') && (buf[2] == 'M')) - { - int s[10]; - - /* Scan for the values */ - if (10 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d:%d:%d", - &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7], &s[8], &s[9])) return (1); - - rmp_ptr->b_age = s[0]; - rmp_ptr->m_age = s[1]; - rmp_ptr->m_b_ht = s[2]; - rmp_ptr->m_m_ht = s[3]; - rmp_ptr->m_b_wt = s[4]; - rmp_ptr->m_m_wt = s[5]; - rmp_ptr->f_b_ht = s[6]; - rmp_ptr->f_m_ht = s[7]; - rmp_ptr->f_b_wt = s[8]; - rmp_ptr->f_m_wt = s[9]; - - /* Next... */ - continue; - } - /* Process 'P' for "xtra" */ if ((buf[0] == 'S') && (buf[2] == 'P')) { -- cgit v1.2.3 From 4632374161221b21423b2cf5c88f3bc4e7d7afe6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 10 Mar 2016 18:41:54 +0100 Subject: Use std::vector for vault data --- src/init1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 31e8c55a..323a0c7f 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3275,7 +3275,7 @@ errr init_v_info_txt(FILE *fp) s = buf + 2; /* Append data */ - strappend(&v_ptr->data, s); + v_ptr->data += s; /* Next... */ continue; -- cgit v1.2.3 From 8a7e17e88e60c841f4086be30f8a090aa651a722 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 10 Mar 2016 18:41:54 +0100 Subject: Remove unused code --- src/init1.cc | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 323a0c7f..e908a470 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1668,16 +1668,6 @@ static errr grab_one_race_kind_flag(u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b } } - /* Check flags2 -- traps*/ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2_trap[i])) - { - (*f3) |= (1L << i); - return (0); - } - } - /* Check flags3 */ for (i = 0; i < 32; i++) { -- cgit v1.2.3 From 6c007b95bdb3658da6dc0fef74a4c798a8d558f2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Thu, 10 Mar 2016 18:41:54 +0100 Subject: Remove massive amounts of boilerplate in init1.cc --- src/init1.cc | 1233 +++++++++++++--------------------------------------------- 1 file changed, 270 insertions(+), 963 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index e908a470..2a8c8c3c 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -927,7 +927,6 @@ static cptr d_info_flags2[] = "XXX1", "XXX1", "XXX1", - "XXX1", "XXX1" }; @@ -1006,7 +1005,6 @@ static cptr st_info_flags1[] = "XXX1", "XXX1", "XXX1", - "XXX1", "XXX1" }; @@ -1085,7 +1083,6 @@ cptr rp_info_flags2[] = "XXX1", "XXX1", "XXX1", - "XXX1", "XXX1" }; @@ -1123,10 +1120,83 @@ static cptr s_info_flags1[] = "XXX1", "XXX1", "XXX1", - "XXX1", "XXX1" }; + +/* + * Helpers for looking up flags in the above arrays + * and extracting "bitmasks" from them. + */ + +namespace { // anonymous + +namespace detail { + +/** + * A "tie" (see e.g. std::tuple) between a "flags" value pointer and its + * corresponding array of text strings. Implementation detail. + */ +template struct flag_tie_impl { +private: + u32b *m_mask; + cptr (&m_flags)[N]; +public: + flag_tie_impl(u32b *mask, cptr (&flags)[N]): m_mask(mask), m_flags(flags) { + // Empty + } + + bool match(cptr flag) { + for (unsigned int i = 0; i < N; i++) + { + if (streq(flag, m_flags[i])) + { + *m_mask |= (1L << i); + return true; + } + } + return false; + } +}; + +} // namespace detail + +/** + * Tie a flags value pointer and its corresponding array + * of text strings. + */ +template detail::flag_tie_impl flag_tie(u32b *mask, cptr (&flags)[N]) { + static_assert(N <= 32, "Array too large to represent result"); + return detail::flag_tie_impl(mask, flags); +} + +/** + * Look up flag in array of flags. + */ +template bool lookup_flags(cptr) +{ + // Base case: No match + return false; +} + +/** + * Look up flag in array of flags. + */ +template bool lookup_flags(cptr flag, detail::flag_tie_impl tie, Pairs&&...rest) { + // Inductive case: Check against current "tie" + if (tie.match(flag)) { + // Match + return true; + } else { + // No match; check against rest of the array of flags + return lookup_flags(flag, rest...); + } +} + +} // namespace anonymous + + + /* * Dungeon effect types (used in E:damage:frequency:type entry in d_info.txt) */ @@ -1573,16 +1643,9 @@ static errr grab_one_race_allow_flag(u32b *choice, cptr what) */ static errr grab_one_skill_flag(u32b *f1, cptr what) { - int i; - - /* Check flags1 */ - for (i = 0; i < 32; i++) + if (lookup_flags(what, flag_tie(f1, s_info_flags1))) { - if (streq(what, s_info_flags1[i])) - { - (*f1) |= (1L << i); - return (0); - } + return 0; } /* Oops */ @@ -1596,26 +1659,11 @@ static errr grab_one_skill_flag(u32b *f1, cptr what) */ static errr grab_one_player_race_flag(u32b *f1, u32b *f2, cptr what) { - int i; - - /* Check flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, rp_info_flags1[i])) - { - (*f1) |= (1L << i); - return (0); - } - } - - /* Check flags2 */ - for (i = 0; i < 32; i++) + if (lookup_flags(what, + flag_tie(f1, rp_info_flags1), + flag_tie(f2, rp_info_flags2))) { - if (streq(what, rp_info_flags2[i])) - { - (*f2) |= (1L << i); - return (0); - } + return 0; } /* Oops */ @@ -1646,66 +1694,15 @@ static int get_activation(char *activation) */ static errr grab_one_race_kind_flag(u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp, cptr what) { - int i; - - /* Check flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags1[i])) - { - (*f1) |= (1L << i); - return (0); - } - } - - /* Check flags2 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2[i])) - { - (*f2) |= (1L << i); - return (0); - } - } - - /* Check flags3 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags3[i])) - { - (*f3) |= (1L << i); - return (0); - } - } - - /* Check flags4 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags4[i])) - { - (*f4) |= (1L << i); - return (0); - } - } - - /* Check flags5 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags5[i])) - { - (*f5) |= (1L << i); - return (0); - } - } - - /* Check esp_flags */ - for (i = 0; i < 32; i++) + if (lookup_flags(what, + flag_tie(f1, k_info_flags1), + flag_tie(f2, k_info_flags2), + flag_tie(f3, k_info_flags3), + flag_tie(f4, k_info_flags4), + flag_tie(f5, k_info_flags5), + flag_tie(esp, esp_flags))) { - if (streq(what, esp_flags[i])) - { - (*esp) |= (1L << i); - return (0); - } + return 0; } /* Oops */ @@ -3340,22 +3337,15 @@ errr init_v_info_txt(FILE *fp) /* * Grab one flag in an feature_type from a textual string */ -static errr grab_one_feature_flag(feature_type *f_ptr, cptr what) +static errr grab_one_feature_flag(u32b *f1, cptr what) { - int i; - - /* Check flags1 */ - for (i = 0; i < 32; i++) + if (lookup_flags(what, flag_tie(f1, f_info_flags1))) { - if (streq(what, f_info_flags1[i])) - { - f_ptr->flags1 |= (1L << i); - return (0); - } + return (0); } /* Oops */ - msg_format("Unknown object flag '%s'.", what); + msg_format("Unknown feature flag '%s'.", what); /* Error */ return (1); @@ -3604,7 +3594,7 @@ errr init_f_info_txt(FILE *fp) } /* Parse this entry */ - if (0 != grab_one_feature_flag(f_ptr, s)) return (5); + if (0 != grab_one_feature_flag(&f_ptr->flags1, s)) return (5); /* Start the next entry */ s = t; @@ -3630,97 +3620,25 @@ errr init_f_info_txt(FILE *fp) */ static errr grab_one_kind_flag(object_kind *k_ptr, cptr what, bool_ obvious) { - int i; - - /* Check flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags1[i])) - { - if (obvious) - k_ptr->oflags1 |= (1L << i); - else - k_ptr->flags1 |= (1L << i); - return (0); - } - } - - /* Check flags2 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2[i])) - { - if (obvious) - k_ptr->oflags2 |= (1L << i); - else - k_ptr->flags2 |= (1L << i); - return (0); - } - } - - /* Check flags2 -- traps*/ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2_trap[i])) - { - if (obvious) - k_ptr->oflags2 |= (1L << i); - else - k_ptr->flags2 |= (1L << i); - return (0); - } - } - - /* Check flags3 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags3[i])) - { - if (obvious) - k_ptr->oflags3 |= (1L << i); - else - k_ptr->flags3 |= (1L << i); - return (0); - } - } - - /* Check flags4 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags4[i])) - { - if (obvious) - k_ptr->oflags4 |= (1L << i); - else - k_ptr->flags4 |= (1L << i); - return (0); - } - } - - /* Check flags5 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags5[i])) - { - if (obvious) - k_ptr->oflags5 |= (1L << i); - else - k_ptr->flags5 |= (1L << i); - return (0); - } - } - - /* Check esp_flags */ - for (i = 0; i < 32; i++) + /* Dispatch to correct set of flags */ + u32b *f1 = obvious ? &k_ptr->oflags1 : &k_ptr->flags1; + u32b *f2 = obvious ? &k_ptr->oflags2 : &k_ptr->flags2; + u32b *f3 = obvious ? &k_ptr->oflags3 : &k_ptr->flags3; + u32b *f4 = obvious ? &k_ptr->oflags4 : &k_ptr->flags4; + u32b *f5 = obvious ? &k_ptr->oflags5 : &k_ptr->flags5; + u32b *esp = obvious ? &k_ptr->oesp : &k_ptr->esp; + + /* Lookup */ + if (lookup_flags(what, + flag_tie(f1, k_info_flags1), + flag_tie(f2, k_info_flags2), + flag_tie(f2, k_info_flags2_trap), + flag_tie(f3, k_info_flags3), + flag_tie(f4, k_info_flags4), + flag_tie(f5, k_info_flags5), + flag_tie(esp, esp_flags))) { - if (streq(what, esp_flags[i])) - { - if (obvious) - k_ptr->oesp |= (1L << i); - else - k_ptr->esp |= (1L << i); - return (0); - } + return 0; } /* Oops */ @@ -4086,97 +4004,25 @@ errr init_k_info_txt(FILE *fp) */ static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what, bool_ obvious) { - int i; - - /* Check flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags1[i])) - { - if (obvious) - a_ptr->oflags1 |= (1L << i); - else - a_ptr->flags1 |= (1L << i); - return (0); - } - } - - /* Check flags2 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2[i])) - { - if (obvious) - a_ptr->oflags2 |= (1L << i); - else - a_ptr->flags2 |= (1L << i); - return (0); - } - } - - /* Check flags2 -- traps*/ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2_trap[i])) - { - if (obvious) - a_ptr->oflags2 |= (1L << i); - else - a_ptr->flags2 |= (1L << i); - return (0); - } - } - - /* Check flags3 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags3[i])) - { - if (obvious) - a_ptr->oflags3 |= (1L << i); - else - a_ptr->flags3 |= (1L << i); - return (0); - } - } - - /* Check flags4 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags4[i])) - { - if (obvious) - a_ptr->oflags4 |= (1L << i); - else - a_ptr->flags4 |= (1L << i); - return (0); - } - } - - /* Check flags5 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags5[i])) - { - if (obvious) - a_ptr->oflags5 |= (1L << i); - else - a_ptr->flags5 |= (1L << i); - return (0); - } - } - - /* Check esp_flags */ - for (i = 0; i < 32; i++) + /* Dispatch to correct set of flags */ + u32b *f1 = obvious ? &a_ptr->oflags1 : &a_ptr->flags1; + u32b *f2 = obvious ? &a_ptr->oflags2 : &a_ptr->flags2; + u32b *f3 = obvious ? &a_ptr->oflags3 : &a_ptr->flags3; + u32b *f4 = obvious ? &a_ptr->oflags4 : &a_ptr->flags4; + u32b *f5 = obvious ? &a_ptr->oflags5 : &a_ptr->flags5; + u32b *esp = obvious ? &a_ptr->oesp : &a_ptr->esp; + + /* Lookup */ + if (lookup_flags(what, + flag_tie(f1, k_info_flags1), + flag_tie(f2, k_info_flags2), + flag_tie(f2, k_info_flags2_trap), + flag_tie(f3, k_info_flags3), + flag_tie(f4, k_info_flags4), + flag_tie(f5, k_info_flags5), + flag_tie(esp, esp_flags))) { - if (streq(what, esp_flags[i])) - { - if (obvious) - a_ptr->oesp |= (1L << i); - else - a_ptr->esp |= (1L << i); - return (0); - } + return 0; } /* Oops */ @@ -5236,108 +5082,29 @@ errr init_ab_info_txt(FILE *fp) */ static bool_ grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what, int n, bool_ obvious) { - int i; assert(n < FLAG_RARITY_MAX); - /* Check flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags1[i])) - { - if (obvious) - e_ptr->oflags1[n] |= (1L << i); - else - e_ptr->flags1[n] |= (1L << i); - return (0); - } - } - - /* Check flags2 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2[i])) - { - if (obvious) - e_ptr->oflags2[n] |= (1L << i); - else - e_ptr->flags2[n] |= (1L << i); - return (0); - } - } - - /* Check flags2 -- traps */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2_trap[i])) - { - if (obvious) - e_ptr->oflags2[n] |= (1L << i); - else - e_ptr->flags2[n] |= (1L << i); - return (0); - } - } - - /* Check flags3 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags3[i])) - { - if (obvious) - e_ptr->oflags3[n] |= (1L << i); - else - e_ptr->flags3[n] |= (1L << i); - return (0); - } - } - - /* Check flags4 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags4[i])) - { - if (obvious) - e_ptr->oflags4[n] |= (1L << i); - else - e_ptr->flags4[n] |= (1L << i); - return (0); - } - } - - /* Check flags5 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags5[i])) - { - if (obvious) - e_ptr->oflags5[n] |= (1L << i); - else - e_ptr->flags5[n] |= (1L << i); - return (0); - } - } - - /* Check esp_flags */ - for (i = 0; i < 32; i++) - { - if (streq(what, esp_flags[i])) - { - if (obvious) - e_ptr->oesp[n] |= (1L << i); - else - e_ptr->esp[n] |= (1L << i); - return (0); - } - } - - /* Check ego_flags */ - for (i = 0; i < 32; i++) + /* Dispatch to correct set of flags */ + u32b *f1 = obvious ? &e_ptr->oflags1[n] : &e_ptr->flags1[n]; + u32b *f2 = obvious ? &e_ptr->oflags2[n] : &e_ptr->flags2[n]; + u32b *f3 = obvious ? &e_ptr->oflags3[n] : &e_ptr->flags3[n]; + u32b *f4 = obvious ? &e_ptr->oflags4[n] : &e_ptr->flags4[n]; + u32b *f5 = obvious ? &e_ptr->oflags5[n] : &e_ptr->flags5[n]; + u32b *esp = obvious ? &e_ptr->oesp[n] : &e_ptr->esp[n]; + u32b *ego = obvious ? &e_ptr->fego[n] : &e_ptr->fego[n]; + + /* Lookup */ + if (lookup_flags(what, + flag_tie(f1, k_info_flags1), + flag_tie(f2, k_info_flags2), + flag_tie(f2, k_info_flags2_trap), + flag_tie(f3, k_info_flags3), + flag_tie(f4, k_info_flags4), + flag_tie(f5, k_info_flags5), + flag_tie(esp, esp_flags), + flag_tie(ego, ego_flags))) { - if (streq(what, ego_flags[i])) - { - e_ptr->fego[n] |= (1L << i); - return (0); - } + return (0); } /* Oops */ @@ -5349,97 +5116,25 @@ static bool_ grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what, int n, bool static bool_ grab_one_ego_item_flag_restrict(ego_item_type *e_ptr, cptr what, bool_ need) { - int i; - - /* Check flags1 */ - for (i = 0; i < 32; i++) + /* Dispatch to correct set of flags */ + u32b *f1 = need ? &e_ptr->need_flags1 : &e_ptr->forbid_flags1; + u32b *f2 = need ? &e_ptr->need_flags2 : &e_ptr->forbid_flags2; + u32b *f3 = need ? &e_ptr->need_flags3 : &e_ptr->forbid_flags3; + u32b *f4 = need ? &e_ptr->need_flags4 : &e_ptr->forbid_flags4; + u32b *f5 = need ? &e_ptr->need_flags5 : &e_ptr->forbid_flags5; + u32b *esp = need ? &e_ptr->need_esp : &e_ptr->forbid_esp; + + /* Lookup */ + if (lookup_flags(what, + flag_tie(f1, k_info_flags1), + flag_tie(f2, k_info_flags2), + flag_tie(f2, k_info_flags2_trap), + flag_tie(f3, k_info_flags3), + flag_tie(f4, k_info_flags4), + flag_tie(f5, k_info_flags5), + flag_tie(esp, esp_flags))) { - if (streq(what, k_info_flags1[i])) - { - if (need) - e_ptr->need_flags1 |= (1L << i); - else - e_ptr->forbid_flags1 |= (1L << i); - return (0); - } - } - - /* Check flags2 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2[i])) - { - if (need) - e_ptr->need_flags2 |= (1L << i); - else - e_ptr->forbid_flags2 |= (1L << i); - return (0); - } - } - - /* Check flags2 -- traps */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2_trap[i])) - { - if (need) - e_ptr->need_flags2 |= (1L << i); - else - e_ptr->forbid_flags2 |= (1L << i); - return (0); - } - } - - /* Check flags3 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags3[i])) - { - if (need) - e_ptr->need_flags3 |= (1L << i); - else - e_ptr->forbid_flags3 |= (1L << i); - return (0); - } - } - - /* Check flags4 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags4[i])) - { - if (need) - e_ptr->need_flags4 |= (1L << i); - else - e_ptr->forbid_flags4 |= (1L << i); - return (0); - } - } - - /* Check flags5 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags5[i])) - { - if (need) - e_ptr->need_flags5 |= (1L << i); - else - e_ptr->forbid_flags5 |= (1L << i); - return (0); - } - } - - /* Check esp_flags */ - for (i = 0; i < 32; i++) - { - if (streq(what, esp_flags[i])) - { - if (need) - e_ptr->need_esp |= (1L << i); - else - e_ptr->forbid_esp |= (1L << i); - return (0); - } + return 0; } /* Oops */ @@ -5813,108 +5508,35 @@ errr init_e_info_txt(FILE *fp) */ static bool_ grab_one_randart_item_flag(randart_part_type *ra_ptr, cptr what, char c) { - int i; - u32b *f1, *f2, *f3, *f4, *f5, *esp; - - if (c == 'F') - { - f1 = &ra_ptr->flags1; - f2 = &ra_ptr->flags2; - f3 = &ra_ptr->flags3; - f4 = &ra_ptr->flags4; - f5 = &ra_ptr->flags5; - esp = &ra_ptr->esp; - } - else - { - f1 = &ra_ptr->aflags1; - f2 = &ra_ptr->aflags2; - f3 = &ra_ptr->aflags3; - f4 = &ra_ptr->aflags4; - f5 = &ra_ptr->aflags5; - esp = &ra_ptr->aesp; - } - - /* Check flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags1[i])) - { - *f1 |= (1L << i); - return (0); - } - } - - /* Check flags2 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2[i])) - { - *f2 |= (1L << i); - return (0); - } - } - - /* Check flags2 -- traps */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags2_trap[i])) - { - *f2 |= (1L << i); - return (0); - } - } - - /* Check flags3 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags3[i])) - { - *f3 |= (1L << i); - return (0); - } - } - - /* Check flags4 */ - for (i = 0; i < 32; i++) - { - if (streq(what, k_info_flags4[i])) - { - *f4 |= (1L << i); - return (0); - } - } - - /* Check flags5 */ - for (i = 0; i < 32; i++) + bool regular = (c == 'F'); + + /* Dispatch to correct set of flags */ + u32b *f1 = regular ? &ra_ptr->flags1 : &ra_ptr->aflags1; + u32b *f2 = regular ? &ra_ptr->flags2 : &ra_ptr->aflags2; + u32b *f3 = regular ? &ra_ptr->flags3 : &ra_ptr->aflags3; + u32b *f4 = regular ? &ra_ptr->flags4 : &ra_ptr->aflags4; + u32b *f5 = regular ? &ra_ptr->flags5 : &ra_ptr->aflags5; + u32b *esp = regular ? &ra_ptr->esp : &ra_ptr->aesp; + + /* Check flags */ + if (lookup_flags(what, + flag_tie(f1, k_info_flags1), + flag_tie(f2, k_info_flags2), + flag_tie(f2, k_info_flags2_trap), + flag_tie(f3, k_info_flags3), + flag_tie(f4, k_info_flags4), + flag_tie(f5, k_info_flags5), + flag_tie(esp, esp_flags))) { - if (streq(what, k_info_flags5[i])) - { - *f5 |= (1L << i); - return (0); - } - } - - /* Check esp_flags */ - for (i = 0; i < 32; i++) - { - if (streq(what, esp_flags[i])) - { - *esp |= (1L << i); - return (0); - } + return 0; } /* Check ego_flags */ - if (c == 'F') + if (regular) { - for (i = 0; i < 32; i++) + if (lookup_flags(what, flag_tie(&ra_ptr->fego, ego_flags))) { - if (streq(what, ego_flags[i])) - { - ra_ptr->fego |= (1L << i); - return (0); - } + return 0; } } @@ -6185,66 +5807,15 @@ errr init_ra_info_txt(FILE *fp) */ static errr grab_one_basic_flag(monster_race *r_ptr, cptr what) { - int i; - - /* Scan flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags1[i])) - { - r_ptr->flags1 |= (1L << i); - return (0); - } - } - - /* Scan flags2 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags2[i])) - { - r_ptr->flags2 |= (1L << i); - return (0); - } - } - - /* Scan flags3 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags3[i])) - { - r_ptr->flags3 |= (1L << i); - return (0); - } - } - - /* Scan flags7 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags7[i])) - { - r_ptr->flags7 |= (1L << i); - return (0); - } - } - - /* Scan flags8 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags8[i])) - { - r_ptr->flags8 |= (1L << i); - return (0); - } - } - - /* Scan flags9 */ - for (i = 0; i < 32; i++) + if (lookup_flags(what, + flag_tie(&r_ptr->flags1, r_info_flags1), + flag_tie(&r_ptr->flags2, r_info_flags2), + flag_tie(&r_ptr->flags3, r_info_flags3), + flag_tie(&r_ptr->flags7, r_info_flags7), + flag_tie(&r_ptr->flags8, r_info_flags8), + flag_tie(&r_ptr->flags9, r_info_flags9))) { - if (streq(what, r_info_flags9[i])) - { - r_ptr->flags9 |= (1L << i); - return (0); - } + return 0; } /* Oops */ @@ -6260,36 +5831,12 @@ static errr grab_one_basic_flag(monster_race *r_ptr, cptr what) */ static errr grab_one_spell_flag(monster_race *r_ptr, cptr what) { - int i; - - /* Scan flags4 */ - for (i = 0; i < 32; i++) + if (lookup_flags(what, + flag_tie(&r_ptr->flags4, r_info_flags4), + flag_tie(&r_ptr->flags5, r_info_flags5), + flag_tie(&r_ptr->flags6, r_info_flags6))) { - if (streq(what, r_info_flags4[i])) - { - r_ptr->flags4 |= (1L << i); - return (0); - } - } - - /* Scan flags5 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags5[i])) - { - r_ptr->flags5 |= (1L << i); - return (0); - } - } - - /* Scan flags6 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags6[i])) - { - r_ptr->flags6 |= (1L << i); - return (0); - } + return (0); } /* Oops */ @@ -6664,84 +6211,24 @@ errr init_r_info_txt(FILE *fp) */ static errr grab_one_basic_ego_flag(monster_ego *re_ptr, cptr what, bool_ add) { - int i; - - /* Scan flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags1[i])) - { - if (add) - re_ptr->mflags1 |= (1L << i); - else - re_ptr->nflags1 |= (1L << i); - return (0); - } - } - - /* Scan flags2 */ - for (i = 0; i < 32; i++) + /* Dispatch to correct set of flags */ + u32b *f1 = add ? &re_ptr->mflags1 : &re_ptr->nflags1; + u32b *f2 = add ? &re_ptr->mflags2 : &re_ptr->nflags2; + u32b *f3 = add ? &re_ptr->mflags3 : &re_ptr->nflags3; + u32b *f7 = add ? &re_ptr->mflags7 : &re_ptr->nflags7; + u32b *f8 = add ? &re_ptr->mflags8 : &re_ptr->nflags8; + u32b *f9 = add ? &re_ptr->mflags9 : &re_ptr->nflags9; + + /* Lookup */ + if (lookup_flags(what, + flag_tie(f1, r_info_flags1), + flag_tie(f2, r_info_flags2), + flag_tie(f3, r_info_flags3), + flag_tie(f7, r_info_flags7), + flag_tie(f8, r_info_flags8), + flag_tie(f9, r_info_flags9))) { - if (streq(what, r_info_flags2[i])) - { - if (add) - re_ptr->mflags2 |= (1L << i); - else - re_ptr->nflags2 |= (1L << i); - return (0); - } - } - - /* Scan flags3 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags3[i])) - { - if (add) - re_ptr->mflags3 |= (1L << i); - else - re_ptr->nflags3 |= (1L << i); - return (0); - } - } - - /* Scan flags7 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags7[i])) - { - if (add) - re_ptr->mflags7 |= (1L << i); - else - re_ptr->nflags7 |= (1L << i); - return (0); - } - } - - /* Scan flags8 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags8[i])) - { - if (add) - re_ptr->mflags8 |= (1L << i); - else - re_ptr->nflags8 |= (1L << i); - return (0); - } - } - - /* Scan flags9 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags9[i])) - { - if (add) - re_ptr->mflags9 |= (1L << i); - else - re_ptr->nflags9 |= (1L << i); - return (0); - } + return 0; } /* Oops */ @@ -6757,45 +6244,18 @@ static errr grab_one_basic_ego_flag(monster_ego *re_ptr, cptr what, bool_ add) */ static errr grab_one_spell_ego_flag(monster_ego *re_ptr, cptr what, bool_ add) { - int i; - - /* Scan flags4 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags4[i])) - { - if (add) - re_ptr->mflags4 |= (1L << i); - else - re_ptr->nflags4 |= (1L << i); - return (0); - } - } - - /* Scan flags5 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags5[i])) - { - if (add) - re_ptr->mflags5 |= (1L << i); - else - re_ptr->nflags5 |= (1L << i); - return (0); - } - } + /* Dispatch to correct set of flags */ + u32b *f4 = add ? &re_ptr->mflags4 : &re_ptr->nflags4; + u32b *f5 = add ? &re_ptr->mflags5 : &re_ptr->nflags5; + u32b *f6 = add ? &re_ptr->mflags6 : &re_ptr->nflags6; - /* Scan flags6 */ - for (i = 0; i < 32; i++) + /* Lookup */ + if (lookup_flags(what, + flag_tie(f4, r_info_flags4), + flag_tie(f5, r_info_flags5), + flag_tie(f6, r_info_flags6))) { - if (streq(what, r_info_flags6[i])) - { - if (add) - re_ptr->mflags6 |= (1L << i); - else - re_ptr->nflags6 |= (1L << i); - return (0); - } + return (0); } /* Oops */ @@ -6810,72 +6270,24 @@ static errr grab_one_spell_ego_flag(monster_ego *re_ptr, cptr what, bool_ add) */ static errr grab_one_ego_flag(monster_ego *re_ptr, cptr what, bool_ must) { - int i; - - /* Scan flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags1[i])) - { - if (must) re_ptr->flags1 |= (1L << i); - else re_ptr->hflags1 |= (1L << i); - return (0); - } - } - - /* Scan flags2 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags2[i])) - { - if (must) re_ptr->flags2 |= (1L << i); - else re_ptr->hflags2 |= (1L << i); - return (0); - } - } - - /* Scan flags3 */ - for (i = 0; i < 32; i++) + /* Dispatch to correct set of flags */ + u32b *f1 = must ? &re_ptr->flags1 : &re_ptr->hflags1; + u32b *f2 = must ? &re_ptr->flags2 : &re_ptr->hflags2; + u32b *f3 = must ? &re_ptr->flags3 : &re_ptr->hflags3; + u32b *f7 = must ? &re_ptr->flags7 : &re_ptr->hflags7; + u32b *f8 = must ? &re_ptr->flags8 : &re_ptr->hflags8; + u32b *f9 = must ? &re_ptr->flags9 : &re_ptr->hflags9; + + /* Lookup */ + if (lookup_flags(what, + flag_tie(f1, r_info_flags1), + flag_tie(f2, r_info_flags2), + flag_tie(f3, r_info_flags3), + flag_tie(f7, r_info_flags7), + flag_tie(f8, r_info_flags8), + flag_tie(f9, r_info_flags9))) { - if (streq(what, r_info_flags3[i])) - { - if (must) re_ptr->flags3 |= (1L << i); - else re_ptr->hflags3 |= (1L << i); - return (0); - } - } - - /* Scan flags7 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags7[i])) - { - if (must) re_ptr->flags7 |= (1L << i); - else re_ptr->hflags7 |= (1L << i); - return (0); - } - } - - /* Scan flags8 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags8[i])) - { - if (must) re_ptr->flags8 |= (1L << i); - else re_ptr->hflags8 |= (1L << i); - return (0); - } - } - - /* Scan flags9 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags9[i])) - { - if (must) re_ptr->flags9 |= (1L << i); - else re_ptr->hflags9 |= (1L << i); - return (0); - } + return (0); } /* Oops */ @@ -7360,17 +6772,11 @@ errr init_re_info_txt(FILE *fp) */ static errr grab_one_trap_type_flag(trap_type *t_ptr, cptr what) { - s16b i; - - /* Check flags1 */ - for (i = 0; i < 32; i++) + if (lookup_flags(what, flag_tie(&t_ptr->flags, t_info_flags))) { - if (streq(what, t_info_flags[i])) - { - t_ptr->flags |= (1L << i); - return (0); - } + return (0); } + /* Oops */ msg_format("Unknown trap_type flag '%s'.", what); @@ -7537,28 +6943,13 @@ errr init_t_info_txt(FILE *fp) /* * Grab one flag for a dungeon type from a textual string */ -errr grab_one_dungeon_flag(u32b *flags1, u32b *flags2, cptr what) +errr grab_one_dungeon_flag(u32b *f1, u32b *f2, cptr what) { - int i; - - /* Scan flags1 */ - for (i = 0; i < 32; i++) + if (lookup_flags(what, + flag_tie(f1, d_info_flags1), + flag_tie(f2, d_info_flags2))) { - if (streq(what, d_info_flags1[i])) - { - *flags1 |= (1L << i); - return (0); - } - } - - /* Scan flags2 */ - for (i = 0; i < 32; i++) - { - if (streq(what, d_info_flags2[i])) - { - *flags2 |= (1L << i); - return (0); - } + return (0); } /* Oops */ @@ -7573,66 +6964,15 @@ errr grab_one_dungeon_flag(u32b *flags1, u32b *flags2, cptr what) */ static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what, byte rule) { - int i; - - /* Scan flags1 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags1[i])) - { - d_ptr->rules[rule].mflags1 |= (1L << i); - return (0); - } - } - - /* Scan flags2 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags2[i])) - { - d_ptr->rules[rule].mflags2 |= (1L << i); - return (0); - } - } - - /* Scan flags3 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags3[i])) - { - d_ptr->rules[rule].mflags3 |= (1L << i); - return (0); - } - } - - /* Scan flags7 */ - for (i = 0; i < 32; i++) + if (lookup_flags(what, + flag_tie(&d_ptr->rules[rule].mflags1, r_info_flags1), + flag_tie(&d_ptr->rules[rule].mflags2, r_info_flags2), + flag_tie(&d_ptr->rules[rule].mflags3, r_info_flags3), + flag_tie(&d_ptr->rules[rule].mflags7, r_info_flags7), + flag_tie(&d_ptr->rules[rule].mflags8, r_info_flags8), + flag_tie(&d_ptr->rules[rule].mflags9, r_info_flags9))) { - if (streq(what, r_info_flags7[i])) - { - d_ptr->rules[rule].mflags7 |= (1L << i); - return (0); - } - } - - /* Scan flags8 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags8[i])) - { - d_ptr->rules[rule].mflags8 |= (1L << i); - return (0); - } - } - - /* Scan flags9 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags9[i])) - { - d_ptr->rules[rule].mflags9 |= (1L << i); - return (0); - } + return 0; } /* Oops */ @@ -7648,36 +6988,12 @@ static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what, byt */ static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what, byte rule) { - int i; - - /* Scan flags4 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags4[i])) - { - d_ptr->rules[rule].mflags4 |= (1L << i); - return (0); - } - } - - /* Scan flags5 */ - for (i = 0; i < 32; i++) - { - if (streq(what, r_info_flags5[i])) - { - d_ptr->rules[rule].mflags5 |= (1L << i); - return (0); - } - } - - /* Scan flags6 */ - for (i = 0; i < 32; i++) + if (lookup_flags(what, + flag_tie(&d_ptr->rules[rule].mflags4, r_info_flags4), + flag_tie(&d_ptr->rules[rule].mflags5, r_info_flags5), + flag_tie(&d_ptr->rules[rule].mflags6, r_info_flags6))) { - if (streq(what, r_info_flags6[i])) - { - d_ptr->rules[rule].mflags6 |= (1L << i); - return (0); - } + return 0; } /* Oops */ @@ -8229,9 +7545,6 @@ errr init_d_info_txt(FILE *fp) */ static errr grab_one_race_flag(owner_type *ow_ptr, int state, cptr what) { - /* int i; - cptr s; */ - /* Scan race flags */ unknown_shut_up = TRUE; if (!grab_one_race_allow_flag(ow_ptr->races[state], what)) @@ -8260,16 +7573,10 @@ static errr grab_one_race_flag(owner_type *ow_ptr, int state, cptr what) */ static errr grab_one_store_flag(store_info_type *st_ptr, cptr what) { - int i; - /* Scan store flags */ - for (i = 0; i < 32; i++) + if (lookup_flags(what, flag_tie(&st_ptr->flags1, st_info_flags1))) { - if (streq(what, st_info_flags1[i])) - { - st_ptr->flags1 |= (1L << i); - return (0); - } + return 0; } /* Oops */ -- cgit v1.2.3 From f271b4a96b231b6a399d93d2d36bf397c18a42e2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 27 Mar 2016 15:46:59 +0200 Subject: Fix missing newlines in k_info description texts --- src/init1.cc | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 2a8c8c3c..5decdfaa 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3735,8 +3735,14 @@ errr init_k_info_txt(FILE *fp) /* Acquire the text */ s = buf + 2; - /* Append description */ - strappend(&k_ptr->text, s); + if (!k_ptr->text) + { + k_ptr->text = my_strdup(s); + } + else + { + strappend(&k_ptr->text, format("\n%s", s)); + } /* Next... */ continue; -- cgit v1.2.3 From 17b80947b08764700c4162e443fc6956b758486d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 27 Mar 2016 15:46:59 +0200 Subject: Reformat flags in *.txt files to be more tool-friendly This means we have a *lot* of added lines, but on the upside it's much simpler to use simple text-based tools and we get rid of a lot of purely boilerplate code --- src/init1.cc | 878 +++++++++++++---------------------------------------------- 1 file changed, 187 insertions(+), 691 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 5decdfaa..56b1a3ac 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -2034,24 +2034,9 @@ errr init_player_info_txt(FILE *fp) /* Process 'G' for "Player flags" (multiple lines) */ if ((buf[0] == 'R') && (buf[2] == 'G')) { - /* Parse every entry */ - for (s = buf + 4; *s; ) + if (0 != grab_one_player_race_flag(&rp_ptr->flags1, &rp_ptr->flags2, buf + 4)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_player_race_flag(&rp_ptr->flags1, &rp_ptr->flags2, s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -2061,24 +2046,9 @@ errr init_player_info_txt(FILE *fp) /* Process 'F' for "level Flags" (multiple lines) */ if ((buf[0] == 'R') && (buf[2] == 'F')) { - /* Parse every entry */ - for (s = buf + 4; *s; ) + if (0 != grab_one_race_kind_flag(&rp_ptr->oflags1[lev], &rp_ptr->oflags2[lev], &rp_ptr->oflags3[lev], &rp_ptr->oflags4[lev], &rp_ptr->oflags5[lev], &rp_ptr->oesp[lev], buf + 4)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_race_kind_flag(&rp_ptr->oflags1[lev], &rp_ptr->oflags2[lev], &rp_ptr->oflags3[lev], &rp_ptr->oflags4[lev], &rp_ptr->oflags5[lev], &rp_ptr->oesp[lev], s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -2116,24 +2086,9 @@ errr init_player_info_txt(FILE *fp) /* Process 'C' for "Class choice flags" (multiple lines) */ if ((buf[0] == 'R') && (buf[2] == 'C')) { - /* Parse every entry */ - for (s = buf + 4; *s; ) + if (0 != grab_one_class_flag(rp_ptr->choice, buf + 4)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_class_flag(rp_ptr->choice, s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -2375,24 +2330,9 @@ errr init_player_info_txt(FILE *fp) /* Process 'G' for "Player flags" (multiple lines) */ if ((buf[0] == 'S') && (buf[2] == 'G')) { - /* Parse every entry */ - for (s = buf + 4; *s; ) + if (0 != grab_one_player_race_flag(&rmp_ptr->flags1, &rmp_ptr->flags2, buf + 4)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_player_race_flag(&rmp_ptr->flags1, &rmp_ptr->flags2, s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -2402,24 +2342,9 @@ errr init_player_info_txt(FILE *fp) /* Process 'F' for "level Flags" (multiple lines) */ if ((buf[0] == 'S') && (buf[2] == 'F')) { - /* Parse every entry */ - for (s = buf + 4; *s; ) + if (0 != grab_one_race_kind_flag(&rmp_ptr->oflags1[lev], &rmp_ptr->oflags2[lev], &rmp_ptr->oflags3[lev], &rmp_ptr->oflags4[lev], &rmp_ptr->oflags5[lev], &rmp_ptr->oesp[lev], buf + 4)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_race_kind_flag(&rmp_ptr->oflags1[lev], &rmp_ptr->oflags2[lev], &rmp_ptr->oflags3[lev], &rmp_ptr->oflags4[lev], &rmp_ptr->oflags5[lev], &rmp_ptr->oesp[lev], s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -2457,24 +2382,9 @@ errr init_player_info_txt(FILE *fp) /* Process 'A' for "Allowed races" (multiple lines) */ if ((buf[0] == 'S') && (buf[2] == 'A')) { - /* Parse every entry */ - for (s = buf + 4; *s; ) + if (0 != grab_one_race_allow_flag(rmp_ptr->choice, buf + 4)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_race_allow_flag(rmp_ptr->choice, s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -2484,32 +2394,23 @@ errr init_player_info_txt(FILE *fp) /* Process 'C' for "Class choice flags" (multiple lines) */ if ((buf[0] == 'S') && (buf[2] == 'C')) { - u32b choice[2] = {0, 0}, z; - - /* Parse every entry */ - for (s = buf + 6; *s; ) + u32b choice[2] = {0, 0}; + if (0 != grab_one_class_flag(choice, buf + 6)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_class_flag(choice, s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } - for (z = 0; z < 2; z++) + /* Combine into the class flags */ + for (int z = 0; z < 2; z++) { - if (buf[4] == 'A') rmp_ptr->pclass[z] |= choice[z]; - else rmp_ptr->mclass[z] |= choice[z]; + if (buf[4] == 'A') + { + rmp_ptr->pclass[z] |= choice[z]; + } + else + { + rmp_ptr->mclass[z] |= choice[z]; + } } /* Next... */ @@ -2869,24 +2770,9 @@ errr init_player_info_txt(FILE *fp) /* Process 'G' for "Player flags" (multiple lines) */ if ((buf[0] == 'C') && (buf[2] == 'G')) { - /* Parse every entry */ - for (s = buf + 4; *s; ) + if (0 != grab_one_player_race_flag(&c_ptr->flags1, &c_ptr->flags2, buf + 4)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_player_race_flag(&c_ptr->flags1, &c_ptr->flags2, s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -3359,7 +3245,7 @@ errr init_f_info_txt(FILE *fp) { int i; char buf[1024]; - char *s, *t; + char *s; /* Current entry */ feature_type *f_ptr = NULL; @@ -3580,32 +3466,15 @@ errr init_f_info_txt(FILE *fp) /* Hack -- Process 'F' for flags */ if (buf[0] == 'F') { - /* Parse every entry textually */ - for (s = buf + 2; *s; ) + if (0 != grab_one_feature_flag(&f_ptr->flags1, buf + 2)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_feature_flag(&f_ptr->flags1, s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ continue; } - - /* Oops */ return (6); } @@ -3945,24 +3814,9 @@ errr init_k_info_txt(FILE *fp) /* Hack -- Process 'F' for flags */ if (buf[0] == 'F') { - /* Parse every entry textually */ - for (s = buf + 2; *s; ) + if (0 != grab_one_kind_flag(k_ptr, buf + 2, FALSE)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_kind_flag(k_ptr, s, FALSE)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -3972,24 +3826,9 @@ errr init_k_info_txt(FILE *fp) /* Hack -- Process 'f' for obvious flags */ if (buf[0] == 'f') { - /* Parse every entry textually */ - for (s = buf + 2; *s; ) + if (0 != grab_one_kind_flag(k_ptr, buf + 2, TRUE)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_kind_flag(k_ptr, s, TRUE)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -4048,7 +3887,7 @@ errr init_a_info_txt(FILE *fp) { int i; char buf[1024]; - char *s, *t; + char *s; /* Current entry */ artifact_type *a_ptr = NULL; @@ -4241,25 +4080,7 @@ errr init_a_info_txt(FILE *fp) /* Hack -- Process 'F' for flags */ if (buf[0] == 'F') { - /* Parse every entry textually */ - for (s = buf + 2; *s; ) - { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while ((*t == ' ') || (*t == '|')) t++; - } - - /* Parse this entry */ - if (0 != grab_one_artifact_flag(a_ptr, s, FALSE)) return (5); - - /* Start the next entry */ - s = t; - } + if (0 != grab_one_artifact_flag(a_ptr, buf+2, FALSE)) return (5); /* Next... */ continue; @@ -4268,25 +4089,7 @@ errr init_a_info_txt(FILE *fp) /* Hack -- Process 'f' for obvious flags */ if (buf[0] == 'f') { - /* Parse every entry textually */ - for (s = buf + 2; *s; ) - { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_artifact_flag(a_ptr, s, TRUE)) return (5); - - /* Start the next entry */ - s = t; - } + if (0 != grab_one_artifact_flag(a_ptr, buf+2, TRUE)) return (5); /* Next... */ continue; @@ -4323,7 +4126,7 @@ errr init_set_info_txt(FILE *fp) int cur_art = 0, cur_num = 0; char buf[1024]; - char *s, *t; + char *s; /* Current entry */ set_type *set_ptr = NULL; @@ -4456,30 +4259,16 @@ errr init_set_info_txt(FILE *fp) /* Process 'F' for flags */ if (buf[0] == 'F') { - /* Parse every entry textually */ - for (s = buf + 2; *s; ) + /* Parse this entry */ + if (0 != grab_one_race_kind_flag(&set_ptr->arts[cur_art].flags1[cur_num], + &set_ptr->arts[cur_art].flags2[cur_num], + &set_ptr->arts[cur_art].flags3[cur_num], + &set_ptr->arts[cur_art].flags4[cur_num], + &set_ptr->arts[cur_art].flags5[cur_num], + &set_ptr->arts[cur_art].esp[cur_num], + buf + 2)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while ((*t == ' ') || (*t == '|')) t++; - } - - /* Parse this entry */ - if (0 != grab_one_race_kind_flag(&set_ptr->arts[cur_art].flags1[cur_num], - &set_ptr->arts[cur_art].flags2[cur_num], - &set_ptr->arts[cur_art].flags3[cur_num], - &set_ptr->arts[cur_art].flags4[cur_num], - &set_ptr->arts[cur_art].flags5[cur_num], - &set_ptr->arts[cur_art].esp[cur_num], - s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -4774,27 +4563,10 @@ errr init_s_info_txt(FILE *fp) /* Process 'F' for flags */ if (buf[0] == 'F') { - char *t; - - /* Parse every entry textually */ - for (s = buf + 2; *s; ) + if (0 != grab_one_skill_flag(&s_ptr->flags1, buf + 2)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while ((*t == ' ') || (*t == '|')) t++; - } - - /* Parse this entry */ - if (0 != grab_one_skill_flag(&(s_ptr->flags1), s)) return (5); - - /* Start the next entry */ - s = t; - } + return (5); + } /* Next... */ continue; @@ -5419,24 +5191,9 @@ errr init_e_info_txt(FILE *fp) /* Hack -- Process 'r:F' for forbidden flags */ if ((buf[0] == 'r') && (buf[2] == 'F')) { - /* Parse every entry textually */ - for (s = buf + 4; *s; ) + if (0 != grab_one_ego_item_flag_restrict(e_ptr, buf + 4, FALSE)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while ((*t == ' ') || (*t == '|')) t++; - } - - /* Parse this entry */ - if (0 != grab_one_ego_item_flag_restrict(e_ptr, s, FALSE)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -5563,7 +5320,7 @@ errr init_ra_info_txt(FILE *fp) { int i, cur_t = 0, j, cur_g = 0; char buf[1024]; - char *s, *t; + char *s; /* Current entry */ randart_part_type *ra_ptr = NULL; @@ -5749,24 +5506,9 @@ errr init_ra_info_txt(FILE *fp) /* Hack -- Process 'F' for flags */ if (buf[0] == 'F') { - /* Parse every entry textually */ - for (s = buf + 2; *s; ) + if (0 != grab_one_randart_item_flag(ra_ptr, buf + 2, 'F')) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while ((*t == ' ') || (*t == '|')) t++; - } - - /* Parse this entry */ - if (0 != grab_one_randart_item_flag(ra_ptr, s, 'F')) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -5776,24 +5518,9 @@ errr init_ra_info_txt(FILE *fp) /* Hack -- Process 'A' for antagonic flags */ if (buf[0] == 'A') { - /* Parse every entry textually */ - for (s = buf + 2; *s; ) + if (0 != grab_one_randart_item_flag(ra_ptr, buf + 2, 'A')) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while ((*t == ' ') || (*t == '|')) t++; - } - - /* Parse this entry */ - if (0 != grab_one_randart_item_flag(ra_ptr, s, 'A')) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -6128,24 +5855,9 @@ errr init_r_info_txt(FILE *fp) /* Process 'F' for "Basic Flags" (multiple lines) */ if (buf[0] == 'F') { - /* Parse every entry */ - for (s = buf + 2; *s; ) + if (0 != grab_one_basic_flag(r_ptr, buf + 2)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_basic_flag(r_ptr, s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -6155,37 +5867,22 @@ errr init_r_info_txt(FILE *fp) /* Process 'S' for "Spell Flags" (multiple lines) */ if (buf[0] == 'S') { - /* Parse every entry */ - for (s = buf + 2; *s; ) - { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + s = buf + 2; - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while ((*t == ' ') || (*t == '|')) t++; - } + /* XXX XXX XXX Hack -- Read spell frequency */ + if (1 == sscanf(s, "1_IN_%d", &i)) + { + /* Extract a "frequency" */ + r_ptr->freq_spell = r_ptr->freq_inate = 100 / i; + } - /* XXX XXX XXX Hack -- Read spell frequency */ - if (1 == sscanf(s, "1_IN_%d", &i)) + /* Parse this entry */ + else + { + if (0 != grab_one_spell_flag(r_ptr, s)) { - /* Extract a "frequency" */ - r_ptr->freq_spell = r_ptr->freq_inate = 100 / i; - - /* Start at next entry */ - s = t; - - /* Continue */ - continue; + return (5); } - - /* Parse this entry */ - if (0 != grab_one_spell_flag(r_ptr, s)) return (5); - - /* Start the next entry */ - s = t; } /* Next... */ @@ -6533,39 +6230,24 @@ errr init_re_info_txt(FILE *fp) char r_char; /* Parse every entry */ - for (s = buf + 2; *s; ) + s = buf + 2; + + /* XXX XXX XXX Hack -- Read monster symbols */ + if (1 == sscanf(s, "R_CHAR_%c", &r_char)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + /* Limited to 5 races */ + if (r_char_number >= 5) continue; - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } + /* Extract a "frequency" */ + re_ptr->r_char[r_char_number++] = r_char; + } - /* XXX XXX XXX Hack -- Read monster symbols */ - if (1 == sscanf(s, "R_CHAR_%c", &r_char)) + /* Parse this entry */ + else { + if (0 != grab_one_ego_flag(re_ptr, s, TRUE)) { - /* Limited to 5 races */ - if (r_char_number >= 5) continue; - - /* Extract a "frequency" */ - re_ptr->r_char[r_char_number++] = r_char; - - /* Start at next entry */ - s = t; - - /* Continue */ - continue; + return (5); } - - /* Parse this entry */ - if (0 != grab_one_ego_flag(re_ptr, s, TRUE)) return (5); - - /* Start the next entry */ - s = t; } /* Next... */ @@ -6578,39 +6260,24 @@ errr init_re_info_txt(FILE *fp) char r_char; /* Parse every entry */ - for (s = buf + 2; *s; ) + s = buf + 2; + + /* XXX XXX XXX Hack -- Read monster symbols */ + if (1 == sscanf(s, "R_CHAR_%c", &r_char)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + /* Limited to 5 races */ + if (nr_char_number >= 5) continue; - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } + /* Extract a "frequency" */ + re_ptr->nr_char[nr_char_number++] = r_char; + } - /* XXX XXX XXX Hack -- Read monster symbols */ - if (1 == sscanf(s, "R_CHAR_%c", &r_char)) + /* Parse this entry */ + else { + if (0 != grab_one_ego_flag(re_ptr, s, FALSE)) { - /* Limited to 5 races */ - if (nr_char_number >= 5) continue; - - /* Extract a "frequency" */ - re_ptr->nr_char[nr_char_number++] = r_char; - - /* Start at next entry */ - s = t; - - /* Continue */ - continue; + return (5); } - - /* Parse this entry */ - if (0 != grab_one_ego_flag(re_ptr, s, FALSE)) return (5); - - /* Start the next entry */ - s = t; } /* Next... */ @@ -6620,24 +6287,9 @@ errr init_re_info_txt(FILE *fp) /* Process 'M' for "Basic Monster Flags" (multiple lines) */ if (buf[0] == 'M') { - /* Parse every entry */ - for (s = buf + 2; *s; ) + if (0 != grab_one_basic_ego_flag(re_ptr, buf + 2, TRUE)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_basic_ego_flag(re_ptr, s, TRUE)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -6647,37 +6299,21 @@ errr init_re_info_txt(FILE *fp) /* Process 'O' for "Basic Monster -Flags" (multiple lines) */ if (buf[0] == 'O') { - /* Parse every entry */ - for (s = buf + 2; *s; ) - { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + s = buf + 2; - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } + /* XXX XXX XXX Hack -- Read no flags */ + if (!strcmp(s, "MF_ALL")) + { + /* No flags */ + re_ptr->nflags1 = re_ptr->nflags2 = re_ptr->nflags3 = re_ptr->nflags7 = re_ptr->nflags8 = re_ptr->nflags9 = 0xFFFFFFFF; + } - /* XXX XXX XXX Hack -- Read no flags */ - if (!strcmp(s, "MF_ALL")) + /* Parse this entry */ + else { + if (0 != grab_one_basic_ego_flag(re_ptr, s, FALSE)) { - /* No flags */ - re_ptr->nflags1 = re_ptr->nflags2 = re_ptr->nflags3 = re_ptr->nflags7 = re_ptr->nflags8 = re_ptr->nflags9 = 0xFFFFFFFF; - - /* Start at next entry */ - s = t; - - /* Continue */ - continue; + return (5); } - - /* Parse this entry */ - if (0 != grab_one_basic_ego_flag(re_ptr, s, FALSE)) return (5); - - /* Start the next entry */ - s = t; } /* Next... */ @@ -6687,37 +6323,21 @@ errr init_re_info_txt(FILE *fp) /* Process 'S' for "Spell Flags" (multiple lines) */ if (buf[0] == 'S') { - /* Parse every entry */ - for (s = buf + 2; *s; ) - { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + s = buf + 2; - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while ((*t == ' ') || (*t == '|')) t++; - } + /* XXX XXX XXX Hack -- Read spell frequency */ + if (1 == sscanf(s, "1_IN_%d", &i)) + { + /* Extract a "frequency" */ + re_ptr->freq_spell = re_ptr->freq_inate = 100 / i; + } - /* XXX XXX XXX Hack -- Read spell frequency */ - if (1 == sscanf(s, "1_IN_%d", &i)) + /* Parse this entry */ + else { + if (0 != grab_one_spell_ego_flag(re_ptr, s, TRUE)) { - /* Extract a "frequency" */ - re_ptr->freq_spell = re_ptr->freq_inate = 100 / i; - - /* Start at next entry */ - s = t; - - /* Continue */ - continue; + return (5); } - - /* Parse this entry */ - if (0 != grab_one_spell_ego_flag(re_ptr, s, TRUE)) return (5); - - /* Start the next entry */ - s = t; } /* Next... */ @@ -7021,7 +6641,7 @@ errr init_d_info_txt(FILE *fp) byte r_char_number = 0; - char *s, *t; + char *s; /* Current entry */ dungeon_info_type *d_ptr = NULL; @@ -7327,104 +6947,57 @@ errr init_d_info_txt(FILE *fp) int artif = 0, monst = 0, obj = 0; int ix = -1, iy = -1, ox = -1, oy = -1; int fill_method; + s = buf + 2; - /* Parse every entry */ - for (s = buf + 2; *s; ) + /* Read dungeon in/out coords */ + if (4 == sscanf(s, "WILD_%d_%d__%d_%d", &ix, &iy, &ox, &oy)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Read dungeon in/out coords */ - if (4 == sscanf(s, "WILD_%d_%d__%d_%d", &ix, &iy, &ox, &oy)) - { - d_ptr->ix = ix; - d_ptr->iy = iy; - d_ptr->ox = ox; - d_ptr->oy = oy; - - /* Start at next entry */ - s = t; - - /* Continue */ - continue; - } - - /* Read dungeon size */ - if (2 == sscanf(s, "SIZE_%d_%d", &ix, &iy)) - { - d_ptr->size_x = ix; - d_ptr->size_y = iy; - - /* Start at next entry */ - s = t; - - /* Continue */ - continue; - } - - /* Read dungeon fill method */ - if (1 == sscanf(s, "FILL_METHOD_%d", &fill_method)) - { - d_ptr->fill_method = fill_method; - - /* Start at next entry */ - s = t; - - /* Continue */ - continue; - } - - /* Read Final Object */ - if (1 == sscanf(s, "FINAL_OBJECT_%d", &obj)) - { - /* Extract a "Final Artifact" */ - d_ptr->final_object = obj; + d_ptr->ix = ix; + d_ptr->iy = iy; + d_ptr->ox = ox; + d_ptr->oy = oy; + } - /* Start at next entry */ - s = t; + /* Read dungeon size */ + else if (2 == sscanf(s, "SIZE_%d_%d", &ix, &iy)) + { + d_ptr->size_x = ix; + d_ptr->size_y = iy; + } - /* Continue */ - continue; - } + /* Read dungeon fill method */ + else if (1 == sscanf(s, "FILL_METHOD_%d", &fill_method)) + { + d_ptr->fill_method = fill_method; + } - /* Read Final Artifact */ - if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif )) - { - /* Extract a "Final Artifact" */ - d_ptr->final_artifact = artif ; + /* Read Final Object */ + else if (1 == sscanf(s, "FINAL_OBJECT_%d", &obj)) + { + /* Extract a "Final Artifact" */ + d_ptr->final_object = obj; + } - /* Start at next entry */ - s = t; + /* Read Final Artifact */ + else if (1 == sscanf(s, "FINAL_ARTIFACT_%d", &artif )) + { + /* Extract a "Final Artifact" */ + d_ptr->final_artifact = artif ; + } - /* Continue */ - continue; - } + /* Read Artifact Guardian */ + else if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst)) + { + /* Extract a "Artifact Guardian" */ + d_ptr->final_guardian = monst; + } - /* Read Artifact Guardian */ - if (1 == sscanf(s, "FINAL_GUARDIAN_%d", &monst)) + /* Parse this entry */ + else { + if (0 != grab_one_dungeon_flag(&(d_ptr->flags1), &(d_ptr->flags2), s)) { - /* Extract a "Artifact Guardian" */ - d_ptr->final_guardian = monst; - - /* Start at next entry */ - s = t; - - /* Continue */ - continue; + return (5); } - - /* Parse this entry */ - if (0 != grab_one_dungeon_flag(&(d_ptr->flags1), &(d_ptr->flags2), s)) return (5); - - /* Start the next entry */ - s = t; } /* Next... */ @@ -7470,41 +7043,24 @@ errr init_d_info_txt(FILE *fp) if (buf[0] == 'M') { byte r_char; + s = buf + 2; - /* Parse every entry */ - for (s = buf + 2; *s; ) + /* Read monster symbols */ + if (1 == sscanf(s, "R_CHAR_%c", &r_char)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; + /* Limited to 5 races */ + if (r_char_number >= 5) continue; - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } + /* Extract a "frequency" */ + d_ptr->rules[rule_num].r_char[r_char_number++] = r_char; + } - /* Read monster symbols */ - if (1 == sscanf(s, "R_CHAR_%c", &r_char)) + /* Parse this entry */ + else { + if (0 != grab_one_basic_monster_flag(d_ptr, s, rule_num)) { - /* Limited to 5 races */ - if (r_char_number >= 5) continue; - - /* Extract a "frequency" */ - d_ptr->rules[rule_num].r_char[r_char_number++] = r_char; - - /* Start at next entry */ - s = t; - - /* Continue */ - continue; + return (5); } - - /* Parse this entry */ - if (0 != grab_one_basic_monster_flag(d_ptr, s, rule_num)) return (5); - - /* Start the next entry */ - s = t; } /* Next... */ @@ -7514,24 +7070,12 @@ errr init_d_info_txt(FILE *fp) /* Process 'S' for "Spell Flags" (multiple lines) */ if (buf[0] == 'S') { - /* Parse every entry */ - for (s = buf + 2; *s; ) - { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while ((*t == ' ') || (*t == '|')) t++; - } - - /* Parse this entry */ - if (0 != grab_one_spell_monster_flag(d_ptr, s, rule_num)) return (5); + s = buf + 2; - /* Start the next entry */ - s = t; + /* Parse this entry */ + if (0 != grab_one_spell_monster_flag(d_ptr, s, rule_num)) + { + return (5); } /* Next... */ @@ -7599,7 +7143,7 @@ errr init_st_info_txt(FILE *fp) { int i = 0, item_idx = 0; char buf[1024]; - char *s, *t; + char *s; /* Current entry */ store_info_type *st_ptr = NULL; @@ -7763,25 +7307,7 @@ errr init_st_info_txt(FILE *fp) /* Process 'F' for "store Flags" (multiple lines) */ if (buf[0] == 'F') { - /* Parse every entry */ - for (s = buf + 2; *s; ) - { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_store_flag(st_ptr, s)) return (5); - - /* Start the next entry */ - s = t; - } + if (0 != grab_one_store_flag(st_ptr, buf + 2)) return (5); /* Next... */ continue; @@ -7957,7 +7483,7 @@ errr init_ow_info_txt(FILE *fp) { int i; char buf[1024]; - char *s, *t; + char *s; /* Current entry */ owner_type *ow_ptr = NULL; @@ -8060,24 +7586,9 @@ errr init_ow_info_txt(FILE *fp) /* Process 'L' for "Liked races/classes" (multiple lines) */ if (buf[0] == 'L') { - /* Parse every entry */ - for (s = buf + 2; *s; ) + if (0 != grab_one_race_flag(ow_ptr, STORE_LIKED, buf + 2)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_race_flag(ow_ptr, STORE_LIKED, s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ @@ -8086,24 +7597,9 @@ errr init_ow_info_txt(FILE *fp) /* Process 'H' for "Hated races/classes" (multiple lines) */ if (buf[0] == 'H') { - /* Parse every entry */ - for (s = buf + 2; *s; ) + if (0 != grab_one_race_flag(ow_ptr, STORE_HATED, buf + 2)) { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_race_flag(ow_ptr, STORE_HATED, s)) return (5); - - /* Start the next entry */ - s = t; + return (5); } /* Next... */ -- cgit v1.2.3 From 4fbb684dead05e8579046b997888abc6bb76af25 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 27 Mar 2016 15:46:59 +0200 Subject: Avoid hardcoding most artifact numbers --- src/init1.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 56b1a3ac..75a75d3a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -722,9 +722,9 @@ cptr k_info_flags5[] = "MAGIC_BREATH", "WATER_BREATH", "WIELD_CAST", - "XXX8X17", - "XXX8X18", - "XXX8X19", + "RANDOM_RESIST", + "RANDOM_POWER", + "RANDOM_RES_OR_POWER", "XXX8X20", "XXX8X21", "XXX8X22", -- cgit v1.2.3 From d1f01115fe9df36800191f1aa55d3ee45eb8cd02 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sun, 27 Mar 2016 15:46:59 +0200 Subject: Move "drops artifact N at %chance" to edit r_info --- src/init1.cc | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 75a75d3a..10698d2d 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5769,6 +5769,25 @@ errr init_r_info_txt(FILE *fp) continue; } + /* Process 'A' for standard artifact drop (one line only) */ + if (buf[0] == 'A') + { + int artifact_idx; + int artifact_chance; + + /* Scan for values */ + if (2 != sscanf(buf + 2, "%d:%d", + &artifact_idx, + &artifact_chance)) return (1); + + /* Save the values */ + r_ptr->artifact_idx = artifact_idx; + r_ptr->artifact_chance = artifact_chance; + + /* Next... */ + continue; + } + /* Process 'W' for "More Info" (one line only) */ if (buf[0] == 'W') { -- cgit v1.2.3 From 168767170d481b9cc5fad6abe84af36e022fbf83 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 29 Mar 2016 20:32:55 +0200 Subject: Add missing "static" qualifiers in init1.cc --- src/init1.cc | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 10698d2d..03966464 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -507,7 +507,7 @@ static cptr r_info_flags9[] = /* * Object flags */ -cptr k_info_flags1[] = +static cptr k_info_flags1[] = { "STR", "INT", @@ -546,7 +546,7 @@ cptr k_info_flags1[] = /* * Object flags */ -cptr k_info_flags2[] = +static cptr k_info_flags2[] = { "SUST_STR", "SUST_INT", @@ -585,7 +585,7 @@ cptr k_info_flags2[] = /* * Trap flags */ -cptr k_info_flags2_trap[] = +static cptr k_info_flags2_trap[] = { "AUTOMATIC_5", "AUTOMATIC_99", @@ -625,7 +625,7 @@ cptr k_info_flags2_trap[] = /* * Object flags */ -cptr k_info_flags3[] = +static cptr k_info_flags3[] = { "SH_FIRE", "SH_ELEC", @@ -664,7 +664,7 @@ cptr k_info_flags3[] = /* * Object flags */ -cptr k_info_flags4[] = +static cptr k_info_flags4[] = { "NEVER_BLOW", "PRECOGNITION", @@ -703,7 +703,7 @@ cptr k_info_flags4[] = /* * Object flags */ -cptr k_info_flags5[] = +static cptr k_info_flags5[] = { "TEMPORARY", "DRAIN_MANA", @@ -742,7 +742,7 @@ cptr k_info_flags5[] = /* * ESP flags */ -cptr esp_flags[] = +static cptr esp_flags[] = { "ESP_ORC", "ESP_TROLL", @@ -1011,7 +1011,7 @@ static cptr st_info_flags1[] = /* * Race flags */ -cptr rp_info_flags1[] = +static cptr rp_info_flags1[] = { "EXPERIMENTAL", "XXX", @@ -1050,7 +1050,7 @@ cptr rp_info_flags1[] = /* * Race flags */ -cptr rp_info_flags2[] = +static cptr rp_info_flags2[] = { "XXX", "ASTRAL", -- cgit v1.2.3 From 899041ce6b7cbc33e8cb3124aaa54b518c4a4b72 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 29 Mar 2016 20:32:55 +0200 Subject: Convert dungeon_info_type to use new flag_set --- src/init1.cc | 97 ++++++------------------------------------------------------ 1 file changed, 9 insertions(+), 88 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 03966464..7ff179fb 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5,6 +5,7 @@ #include "cave.hpp" #include "cave_type.hpp" #include "dungeon_info_type.hpp" +#include "dungeon_flag.hpp" #include "ego_item_type.hpp" #include "feature_type.hpp" #include "files.hpp" @@ -855,81 +856,6 @@ static cptr f_info_flags1[] = "XXX1" }; -/* - * Dungeon flags - */ -static cptr d_info_flags1[] = -{ - "PRINCIPAL", - "MAZE", - "SMALLEST", - "SMALL", - "BIG", - "NO_DOORS", - "WATER_RIVER", - "LAVA_RIVER", - "WATER_RIVERS", - "LAVA_RIVERS", - "CAVE", - "CAVERN", - "NO_UP", - "HOT", - "COLD", - "FORCE_DOWN", - "FORGET", - "NO_DESTROY", - "SAND_VEIN", - "CIRCULAR_ROOMS", - "EMPTY", - "DAMAGE_FEAT", - "FLAT", - "TOWER", - "RANDOM_TOWNS", - "DOUBLE", - "LIFE_LEVEL", - "EVOLVE", - "ADJUST_LEVEL_1", - "ADJUST_LEVEL_2", - "NO_RECALL", - "NO_STREAMERS" -}; - -static cptr d_info_flags2[] = -{ - "ADJUST_LEVEL_1_2", - "NO_SHAFT", - "ADJUST_LEVEL_PLAYER", - "NO_TELEPORT", - "ASK_LEAVE", - "NO_STAIR", - "SPECIAL", - "NO_NEW_MONSTER", - "DESC", - "NO_GENO", - "NO_BREATH", - "WATER_BREATH", - "ELVEN", - "DWARVEN", - "NO_EASY_MOVE", - "NO_RECALL_OUT", - "DESC_ALWAYS", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1" -}; - /* * Trap flags */ @@ -6585,20 +6511,15 @@ errr init_t_info_txt(FILE *fp) return (0); } -/* - * Grab one flag for a dungeon type from a textual string - */ -errr grab_one_dungeon_flag(u32b *f1, u32b *f2, cptr what) +errr grab_one_dungeon_flag(dungeon_flag_set *flags, const char *str) { - if (lookup_flags(what, - flag_tie(f1, d_info_flags1), - flag_tie(f2, d_info_flags2))) - { - return (0); - } +#define DF(tier, index, name) \ + if (streq(str, #name)) { *flags |= DF_##name; return 0; } +#include "dungeon_flag_list.hpp" +#undef DF /* Oops */ - msg_format("Unknown dungeon type flag '%s'.", what); + msg_format("Unknown dungeon type flag '%s'.", str); /* Failure */ return (1); @@ -7013,7 +6934,7 @@ errr init_d_info_txt(FILE *fp) /* Parse this entry */ else { - if (0 != grab_one_dungeon_flag(&(d_ptr->flags1), &(d_ptr->flags2), s)) + if (0 != grab_one_dungeon_flag(&d_ptr->flags, s)) { return (5); } @@ -8044,7 +7965,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst } /* Parse this entry */ - if (0 != grab_one_dungeon_flag(&dungeon_flags1, &dungeon_flags2, s)) return 1; + if (0 != grab_one_dungeon_flag(&dungeon_flags, s)) return 1; /* Start the next entry */ s = t; -- cgit v1.2.3 From e17e742edb3809d45ce1edc716d71b3bb93056d6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Make obj_theme a non-POD struct --- src/init1.cc | 18 +++++++----------- 1 file changed, 7 insertions(+), 11 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 7ff179fb..cfd767f8 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5575,12 +5575,11 @@ errr init_r_info_txt(FILE *fp) /* Ensure empty description */ r_ptr->text = my_strdup(""); - /* HACK -- Those ones HAVE to have a set default value */ - r_ptr->drops.treasure = OBJ_GENE_TREASURE; - r_ptr->drops.combat = OBJ_GENE_COMBAT; - r_ptr->drops.magic = OBJ_GENE_MAGIC; - r_ptr->drops.tools = OBJ_GENE_TOOL; - r_ptr->freq_inate = r_ptr->freq_spell = 0; + /* Set default drop theme */ + r_ptr->drops = obj_theme::defaults(); + + r_ptr->freq_inate = 0; + r_ptr->freq_spell = 0; /* Next... */ continue; @@ -6662,11 +6661,8 @@ errr init_d_info_txt(FILE *fp) for (k = 0; k < 5; k++) d_ptr->rules[j].r_char[k] = 0; } - /* HACK -- Those ones HAVE to have a set default value */ - d_ptr->objs.treasure = OBJ_GENE_TREASURE; - d_ptr->objs.combat = OBJ_GENE_COMBAT; - d_ptr->objs.magic = OBJ_GENE_MAGIC; - d_ptr->objs.tools = OBJ_GENE_TOOL; + /* Set default drop theme */ + d_ptr->objs = obj_theme::defaults(); /* The default generator */ strcpy(d_ptr->generator, "dungeon"); -- cgit v1.2.3 From 59b5314b6b7880cfda73f34aed03a700fd523017 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Rework RF{4,5,6}_* monster spell flags to flag_set<> --- src/init1.cc | 188 +++++------------------------------------------------------ 1 file changed, 13 insertions(+), 175 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index cfd767f8..3b94adb5 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -16,6 +16,7 @@ #include "monster2.hpp" #include "monster_ego.hpp" #include "monster_race.hpp" +#include "monster_spell.hpp" #include "monster_type.hpp" #include "object1.hpp" #include "object2.hpp" @@ -268,124 +269,6 @@ static cptr r_info_flags3[] = "NO_SLEEP" }; -/* - * Monster race flags - */ -static cptr r_info_flags4[] = -{ - "SHRIEK", - "MULTIPLY", - "S_ANIMAL", - "ROCKET", - "ARROW_1", - "ARROW_2", - "ARROW_3", - "ARROW_4", - "BR_ACID", - "BR_ELEC", - "BR_FIRE", - "BR_COLD", - "BR_POIS", - "BR_NETH", - "BR_LITE", - "BR_DARK", - "BR_CONF", - "BR_SOUN", - "BR_CHAO", - "BR_DISE", - "BR_NEXU", - "BR_TIME", - "BR_INER", - "BR_GRAV", - "BR_SHAR", - "BR_PLAS", - "BR_WALL", - "BR_MANA", - "BA_NUKE", - "BR_NUKE", - "BA_CHAO", - "BR_DISI", -}; - -/* - * Monster race flags - */ -static cptr r_info_flags5[] = -{ - "BA_ACID", - "BA_ELEC", - "BA_FIRE", - "BA_COLD", - "BA_POIS", - "BA_NETH", - "BA_WATE", - "BA_MANA", - "BA_DARK", - "DRAIN_MANA", - "MIND_BLAST", - "BRAIN_SMASH", - "CAUSE_1", - "CAUSE_2", - "CAUSE_3", - "CAUSE_4", - "BO_ACID", - "BO_ELEC", - "BO_FIRE", - "BO_COLD", - "BO_POIS", - "BO_NETH", - "BO_WATE", - "BO_MANA", - "BO_PLAS", - "BO_ICEE", - "MISSILE", - "SCARE", - "BLIND", - "CONF", - "SLOW", - "HOLD" -}; - -/* - * Monster race flags - */ -static cptr r_info_flags6[] = -{ - "HASTE", - "HAND_DOOM", - "HEAL", - "S_ANIMALS", - "BLINK", - "TPORT", - "TELE_TO", - "TELE_AWAY", - "TELE_LEVEL", - "DARKNESS", - "TRAPS", - "FORGET", - "ANIM_DEAD", /* ToDo: Implement ANIM_DEAD */ - "S_BUG", - "S_RNG", - "S_THUNDERLORD", /* DG : Summon Thunderlord */ - "S_KIN", - "S_HI_DEMON", - "S_MONSTER", - "S_MONSTERS", - "S_ANT", - "S_SPIDER", - "S_HOUND", - "S_HYDRA", - "S_ANGEL", - "S_DEMON", - "S_UNDEAD", - "S_DRAGON", - "S_HI_UNDEAD", - "S_HI_DRAGON", - "S_WRAITH", - "S_UNIQUE" -}; - - /* * Monster race flags */ @@ -5488,14 +5371,15 @@ static errr grab_one_basic_flag(monster_race *r_ptr, cptr what) /* * Grab one (spell) flag in a monster_race from a textual string */ -static errr grab_one_spell_flag(monster_race *r_ptr, cptr what) +static errr grab_one_monster_spell_flag(monster_spell_flag_set *flags, cptr what) { - if (lookup_flags(what, - flag_tie(&r_ptr->flags4, r_info_flags4), - flag_tie(&r_ptr->flags5, r_info_flags5), - flag_tie(&r_ptr->flags6, r_info_flags6))) + for (auto const &monster_spell: monster_spells()) { - return (0); + if (streq(what, monster_spell->name)) + { + *flags |= monster_spell->flag_set; + return 0; + } } /* Oops */ @@ -5823,7 +5707,7 @@ errr init_r_info_txt(FILE *fp) /* Parse this entry */ else { - if (0 != grab_one_spell_flag(r_ptr, s)) + if (0 != grab_one_monster_spell_flag(&r_ptr->spells, s)) { return (5); } @@ -5886,32 +5770,6 @@ static errr grab_one_basic_ego_flag(monster_ego *re_ptr, cptr what, bool_ add) } -/* - * Grab one (spell) flag in a monster_race from a textual string - */ -static errr grab_one_spell_ego_flag(monster_ego *re_ptr, cptr what, bool_ add) -{ - /* Dispatch to correct set of flags */ - u32b *f4 = add ? &re_ptr->mflags4 : &re_ptr->nflags4; - u32b *f5 = add ? &re_ptr->mflags5 : &re_ptr->nflags5; - u32b *f6 = add ? &re_ptr->mflags6 : &re_ptr->nflags6; - - /* Lookup */ - if (lookup_flags(what, - flag_tie(f4, r_info_flags4), - flag_tie(f5, r_info_flags5), - flag_tie(f6, r_info_flags6))) - { - return (0); - } - - /* Oops */ - msg_format("Unknown monster flag '%s'.", what); - - /* Failure */ - return (1); -} - /* * Grab one (basic) flag in a monster_race from a textual string */ @@ -6278,7 +6136,7 @@ errr init_re_info_txt(FILE *fp) /* Parse this entry */ else { - if (0 != grab_one_spell_ego_flag(re_ptr, s, TRUE)) + if (0 != grab_one_monster_spell_flag(&re_ptr->mspells, s)) { return (5); } @@ -6308,7 +6166,7 @@ errr init_re_info_txt(FILE *fp) if (!strcmp(s, "MF_ALL")) { /* No flags */ - re_ptr->nflags4 = re_ptr->nflags5 = re_ptr->nflags6 = 0xFFFFFFFF; + re_ptr->nspells = ~monster_spell_flag_set(); /* Start at next entry */ s = t; @@ -6318,7 +6176,7 @@ errr init_re_info_txt(FILE *fp) } /* Parse this entry */ - if (0 != grab_one_spell_ego_flag(re_ptr, s, FALSE)) return (5); + if (0 != grab_one_monster_spell_flag(&re_ptr->nspells, s)) return (5); /* Start the next entry */ s = t; @@ -6548,26 +6406,6 @@ static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what, byt } -/* - * Grab one (spell) flag in a monster_race from a textual string - */ -static errr grab_one_spell_monster_flag(dungeon_info_type *d_ptr, cptr what, byte rule) -{ - if (lookup_flags(what, - flag_tie(&d_ptr->rules[rule].mflags4, r_info_flags4), - flag_tie(&d_ptr->rules[rule].mflags5, r_info_flags5), - flag_tie(&d_ptr->rules[rule].mflags6, r_info_flags6))) - { - return 0; - } - - /* Oops */ - msg_format("Unknown monster flag '%s'.", what); - - /* Failure */ - return (1); -} - /* * Initialize the "d_info" array, by parsing an ascii "template" file */ @@ -7009,7 +6847,7 @@ errr init_d_info_txt(FILE *fp) s = buf + 2; /* Parse this entry */ - if (0 != grab_one_spell_monster_flag(d_ptr, s, rule_num)) + if (0 != grab_one_monster_spell_flag(&d_ptr->rules[rule_num].mspells, s)) { return (5); } -- cgit v1.2.3 From bc5fd67c4fa703d06c5c08435e65d439d513465d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Remove WILD_SWAMP which was never implemented --- src/init1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 3b94adb5..290091dc 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -343,7 +343,7 @@ static cptr r_info_flags8[] = "XXX8X27", "XXX8X28", "XXX8X29", - "WILD_SWAMP", /* ToDo: Implement Swamp */ + "XXX8X30", "WILD_TOO", }; -- cgit v1.2.3 From fc41a7d28d8896da79963d23ed1afba408e27470 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Remove unused special-casing of RF8_WILD_TOO in init1.cc --- src/init1.cc | 4 ---- 1 file changed, 4 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 290091dc..9b76b8f8 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5726,10 +5726,6 @@ errr init_r_info_txt(FILE *fp) { /* Invert flag WILD_ONLY <-> RF8_DUNGEON */ r_info[i].flags8 ^= 1L; - - /* WILD_TOO without any other wilderness flags enables all flags */ - if ((r_info[i].flags8 & RF8_WILD_TOO) && !(r_info[i].flags8 & 0x7FFFFFFE)) - r_info[i].flags8 = 0x0463; } /* Success */ -- cgit v1.2.3 From 68e2a10b2d76cb3a2f5aa6818b4b184b6a02ef14 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Rework RF{1,2,3,7,8,9}_* monster flags to use flag_set<> --- src/init1.cc | 371 +++-------------------------------------------------------- 1 file changed, 18 insertions(+), 353 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 9b76b8f8..327faca6 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -16,6 +16,7 @@ #include "monster2.hpp" #include "monster_ego.hpp" #include "monster_race.hpp" +#include "monster_race_flag.hpp" #include "monster_spell.hpp" #include "monster_type.hpp" #include "object1.hpp" @@ -152,242 +153,6 @@ static cptr r_info_blow_effect[] = }; -/* - * Monster race flags - */ -static cptr r_info_flags1[] = -{ - "UNIQUE", - "QUESTOR", - "MALE", - "FEMALE", - "CHAR_CLEAR", - "CHAR_MULTI", - "ATTR_CLEAR", - "ATTR_MULTI", - "FORCE_DEPTH", - "FORCE_MAXHP", - "FORCE_SLEEP", - "FORCE_EXTRA", - "FRIEND", - "FRIENDS", - "ESCORT", - "ESCORTS", - "NEVER_BLOW", - "NEVER_MOVE", - "RAND_25", - "RAND_50", - "ONLY_GOLD", - "ONLY_ITEM", - "DROP_60", - "DROP_90", - "DROP_1D2", - "DROP_2D2", - "DROP_3D2", - "DROP_4D2", - "DROP_GOOD", - "DROP_GREAT", - "DROP_USEFUL", - "DROP_CHOSEN" -}; - -/* - * Monster race flags - */ -static cptr r_info_flags2[] = -{ - "STUPID", - "SMART", - "CAN_SPEAK", - "REFLECTING", - "INVISIBLE", - "COLD_BLOOD", - "EMPTY_MIND", - "WEIRD_MIND", - "DEATH_ORB", - "REGENERATE", - "SHAPECHANGER", - "ATTR_ANY", - "POWERFUL", - "ELDRITCH_HORROR", - "AURA_FIRE", - "AURA_ELEC", - "OPEN_DOOR", - "BASH_DOOR", - "PASS_WALL", - "KILL_WALL", - "MOVE_BODY", - "KILL_BODY", - "TAKE_ITEM", - "KILL_ITEM", - "BRAIN_1", - "BRAIN_2", - "BRAIN_3", - "BRAIN_4", - "BRAIN_5", - "BRAIN_6", - "BRAIN_7", - "BRAIN_8" -}; - -/* - * Monster race flags - */ -static cptr r_info_flags3[] = -{ - "ORC", - "TROLL", - "GIANT", - "DRAGON", - "DEMON", - "UNDEAD", - "EVIL", - "ANIMAL", - "THUNDERLORD", - "GOOD", - "AURA_COLD", /* TODO: Implement aura_cold */ - "NONLIVING", - "HURT_LITE", - "HURT_ROCK", - "SUSCEP_FIRE", - "SUSCEP_COLD", - "IM_ACID", - "IM_ELEC", - "IM_FIRE", - "IM_COLD", - "IM_POIS", - "RES_TELE", - "RES_NETH", - "RES_WATE", - "RES_PLAS", - "RES_NEXU", - "RES_DISE", - "UNIQUE_4", - "NO_FEAR", - "NO_STUN", - "NO_CONF", - "NO_SLEEP" -}; - -/* - * Monster race flags - */ -static cptr r_info_flags7[] = -{ - "AQUATIC", - "CAN_SWIM", - "CAN_FLY", - "FRIENDLY", - "PET", - "MORTAL", - "SPIDER", - "NAZGUL", - "DG_CURSE", - "POSSESSOR", - "NO_DEATH", - "NO_TARGET", - "AI_ANNOY", - "AI_SPECIAL", - "NEUTRAL", - "DROP_ART", - "DROP_RANDART", - "AI_PLAYER", - "NO_THEFT", - "SPIRIT", - "XXX7X20", - "XXX7X21", - "XXX7X22", - "XXX7X23", - "XXX7X24", - "XXX7X25", - "XXX7X26", - "XXX7X27", - "XXX7X28", - "XXX7X29", - "XXX7X30", - "XXX7X31", -}; - -/* - * Monster race flags - */ -static cptr r_info_flags8[] = -{ - "WILD_ONLY", - "WILD_TOWN", - "XXX8X02", - "WILD_SHORE", - "WILD_OCEAN", - "WILD_WASTE", - "WILD_WOOD", - "WILD_VOLCANO", - "XXX8X08", - "WILD_MOUNTAIN", - "WILD_GRASS", - "NO_CUT", - "CTHANGBAND", - "XXX8X13", - "ZANGBAND", - "JOKEANGBAND", - "BASEANGBAND", - "XXX8X17", - "XXX8X18", - "XXX8X19", - "XXX8X20", - "XXX8X21", - "XXX8X22", - "XXX8X23", - "XXX8X24", - "XXX8X25", - "XXX8X26", - "XXX8X27", - "XXX8X28", - "XXX8X29", - "XXX8X30", - "WILD_TOO", -}; - - -/* - * Monster race flags - Drops - */ -static cptr r_info_flags9[] = -{ - "DROP_CORPSE", - "DROP_SKELETON", - "HAS_LITE", - "MIMIC", - "HAS_EGG", - "IMPRESED", - "SUSCEP_ACID", - "SUSCEP_ELEC", - "SUSCEP_POIS", - "KILL_TREES", - "WYRM_PROTECT", - "DOPPLEGANGER", - "ONLY_DEPTH", - "SPECIAL_GENE", - "NEVER_GENE", - "XXX9X15", - "XXX9X16", - "XXX9X17", - "XXX9X18", - "XXX9X19", - "XXX9X20", - "XXX9X21", - "XXX9X22", - "XXX9X23", - "XXX9X24", - "XXX9X25", - "XXX9X26", - "XXX9X27", - "XXX9X28", - "XXX9X29", - "XXX9X30", - "XXX9X31", -}; - - /* * Object flags */ @@ -5344,21 +5109,17 @@ errr init_ra_info_txt(FILE *fp) return (0); } -/* - * Grab one (basic) flag in a monster_race from a textual string - */ -static errr grab_one_basic_flag(monster_race *r_ptr, cptr what) + +static errr grab_monster_race_flag(monster_race_flag_set *flags, cptr what) { - if (lookup_flags(what, - flag_tie(&r_ptr->flags1, r_info_flags1), - flag_tie(&r_ptr->flags2, r_info_flags2), - flag_tie(&r_ptr->flags3, r_info_flags3), - flag_tie(&r_ptr->flags7, r_info_flags7), - flag_tie(&r_ptr->flags8, r_info_flags8), - flag_tie(&r_ptr->flags9, r_info_flags9))) - { - return 0; - } +#define RF(tier, index, name) \ + if (streq(what, #name)) \ + { \ + *flags |= BOOST_PP_CAT(RF_,name); \ + return 0; \ + }; +#include "monster_race_flag_list.hpp" +#undef RF /* Oops */ msg_format("Unknown monster flag '%s'.", what); @@ -5683,7 +5444,7 @@ errr init_r_info_txt(FILE *fp) /* Process 'F' for "Basic Flags" (multiple lines) */ if (buf[0] == 'F') { - if (0 != grab_one_basic_flag(r_ptr, buf + 2)) + if (0 != grab_monster_race_flag(&r_ptr->flags, buf + 2)) { return (5); } @@ -5721,83 +5482,11 @@ errr init_r_info_txt(FILE *fp) return (6); } - /* Postprocessing */ - for (i = 1; i < max_r_idx; i++) - { - /* Invert flag WILD_ONLY <-> RF8_DUNGEON */ - r_info[i].flags8 ^= 1L; - } - /* Success */ return (0); } -/* - * Grab one (basic) flag in a monster_race from a textual string - */ -static errr grab_one_basic_ego_flag(monster_ego *re_ptr, cptr what, bool_ add) -{ - /* Dispatch to correct set of flags */ - u32b *f1 = add ? &re_ptr->mflags1 : &re_ptr->nflags1; - u32b *f2 = add ? &re_ptr->mflags2 : &re_ptr->nflags2; - u32b *f3 = add ? &re_ptr->mflags3 : &re_ptr->nflags3; - u32b *f7 = add ? &re_ptr->mflags7 : &re_ptr->nflags7; - u32b *f8 = add ? &re_ptr->mflags8 : &re_ptr->nflags8; - u32b *f9 = add ? &re_ptr->mflags9 : &re_ptr->nflags9; - - /* Lookup */ - if (lookup_flags(what, - flag_tie(f1, r_info_flags1), - flag_tie(f2, r_info_flags2), - flag_tie(f3, r_info_flags3), - flag_tie(f7, r_info_flags7), - flag_tie(f8, r_info_flags8), - flag_tie(f9, r_info_flags9))) - { - return 0; - } - - /* Oops */ - msg_format("Unknown monster flag '%s'.", what); - - /* Failure */ - return (1); -} - - -/* - * Grab one (basic) flag in a monster_race from a textual string - */ -static errr grab_one_ego_flag(monster_ego *re_ptr, cptr what, bool_ must) -{ - /* Dispatch to correct set of flags */ - u32b *f1 = must ? &re_ptr->flags1 : &re_ptr->hflags1; - u32b *f2 = must ? &re_ptr->flags2 : &re_ptr->hflags2; - u32b *f3 = must ? &re_ptr->flags3 : &re_ptr->hflags3; - u32b *f7 = must ? &re_ptr->flags7 : &re_ptr->hflags7; - u32b *f8 = must ? &re_ptr->flags8 : &re_ptr->hflags8; - u32b *f9 = must ? &re_ptr->flags9 : &re_ptr->hflags9; - - /* Lookup */ - if (lookup_flags(what, - flag_tie(f1, r_info_flags1), - flag_tie(f2, r_info_flags2), - flag_tie(f3, r_info_flags3), - flag_tie(f7, r_info_flags7), - flag_tie(f8, r_info_flags8), - flag_tie(f9, r_info_flags9))) - { - return (0); - } - - /* Oops */ - msg_format("Unknown monster flag '%s'.", what); - - /* Failure */ - return (1); -} - /* * Initialize the "re_info" array, by parsing an ascii "template" file */ @@ -6042,7 +5731,7 @@ errr init_re_info_txt(FILE *fp) /* Parse this entry */ else { - if (0 != grab_one_ego_flag(re_ptr, s, TRUE)) + if (0 != grab_monster_race_flag(&re_ptr->flags, s)) { return (5); } @@ -6072,7 +5761,7 @@ errr init_re_info_txt(FILE *fp) /* Parse this entry */ else { - if (0 != grab_one_ego_flag(re_ptr, s, FALSE)) + if (0 != grab_monster_race_flag(&re_ptr->hflags, s)) { return (5); } @@ -6085,7 +5774,7 @@ errr init_re_info_txt(FILE *fp) /* Process 'M' for "Basic Monster Flags" (multiple lines) */ if (buf[0] == 'M') { - if (0 != grab_one_basic_ego_flag(re_ptr, buf + 2, TRUE)) + if (0 != grab_monster_race_flag(&re_ptr->mflags, buf + 2)) { return (5); } @@ -6102,13 +5791,12 @@ errr init_re_info_txt(FILE *fp) /* XXX XXX XXX Hack -- Read no flags */ if (!strcmp(s, "MF_ALL")) { - /* No flags */ - re_ptr->nflags1 = re_ptr->nflags2 = re_ptr->nflags3 = re_ptr->nflags7 = re_ptr->nflags8 = re_ptr->nflags9 = 0xFFFFFFFF; + re_ptr->nflags = ~monster_race_flag_set(); } /* Parse this entry */ else { - if (0 != grab_one_basic_ego_flag(re_ptr, s, FALSE)) + if (0 != grab_monster_race_flag(&re_ptr->nflags, s)) { return (5); } @@ -6378,29 +6066,6 @@ errr grab_one_dungeon_flag(dungeon_flag_set *flags, const char *str) return (1); } -/* - * Grab one (basic) flag in a monster_race from a textual string - */ -static errr grab_one_basic_monster_flag(dungeon_info_type *d_ptr, cptr what, byte rule) -{ - if (lookup_flags(what, - flag_tie(&d_ptr->rules[rule].mflags1, r_info_flags1), - flag_tie(&d_ptr->rules[rule].mflags2, r_info_flags2), - flag_tie(&d_ptr->rules[rule].mflags3, r_info_flags3), - flag_tie(&d_ptr->rules[rule].mflags7, r_info_flags7), - flag_tie(&d_ptr->rules[rule].mflags8, r_info_flags8), - flag_tie(&d_ptr->rules[rule].mflags9, r_info_flags9))) - { - return 0; - } - - /* Oops */ - msg_format("Unknown monster flag '%s'.", what); - - /* Failure */ - return (1); -} - /* * Initialize the "d_info" array, by parsing an ascii "template" file @@ -6827,7 +6492,7 @@ errr init_d_info_txt(FILE *fp) /* Parse this entry */ else { - if (0 != grab_one_basic_monster_flag(d_ptr, s, rule_num)) + if (0 != grab_monster_race_flag(&d_ptr->rules[rule_num].mflags, s)) { return (5); } -- cgit v1.2.3 From fc06bedef3f5521a97989ebb6c7160744c640a19 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Mon, 20 Jun 2016 22:49:05 +0200 Subject: Change set_type to non-POD type --- src/init1.cc | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 327faca6..38736f0e 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3728,8 +3728,6 @@ errr init_set_info_txt(FILE *fp) /* Process 'N' for "New/Number/Name" */ if (buf[0] == 'N') { - int z, y; - /* Find the colon before the name */ s = strchr(buf + 2, ':'); @@ -3764,11 +3762,12 @@ errr init_set_info_txt(FILE *fp) /* Initialize */ set_ptr->num = 0; set_ptr->num_use = 0; - for (z = 0; z < 6; z++) + + for (std::size_t z = 0; z < SET_MAX_SIZE; z++) { set_ptr->arts[z].a_idx = 0; set_ptr->arts[z].present = FALSE; - for (y = 0; y < 6; y++) + for (std::size_t y = 0; y < SET_MAX_SIZE; y++) { set_ptr->arts[z].flags1[y] = 0; set_ptr->arts[z].flags2[y] = 0; -- cgit v1.2.3 From 073ad3584fbf781ce10bef61ad4ff38850282f47 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 21 Jun 2016 13:37:02 +0200 Subject: Rework TR{1,2,3,4,5}_* flags to flag_set<> --- src/init1.cc | 634 ++++++++++------------------------------------------------- 1 file changed, 100 insertions(+), 534 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 38736f0e..0a6ecff0 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -21,6 +21,8 @@ #include "monster_type.hpp" #include "object1.hpp" #include "object2.hpp" +#include "object_flag.hpp" +#include "object_flag_meta.hpp" #include "object_kind.hpp" #include "owner_type.hpp" #include "player_class.hpp" @@ -153,280 +155,6 @@ static cptr r_info_blow_effect[] = }; -/* - * Object flags - */ -static cptr k_info_flags1[] = -{ - "STR", - "INT", - "WIS", - "DEX", - "CON", - "CHR", - "MANA", - "SPELL", - "STEALTH", - "SEARCH", - "INFRA", - "TUNNEL", - "SPEED", - "BLOWS", - "CHAOTIC", - "VAMPIRIC", - "SLAY_ANIMAL", - "SLAY_EVIL", - "SLAY_UNDEAD", - "SLAY_DEMON", - "SLAY_ORC", - "SLAY_TROLL", - "SLAY_GIANT", - "SLAY_DRAGON", - "KILL_DRAGON", - "VORPAL", - "IMPACT", - "BRAND_POIS", - "BRAND_ACID", - "BRAND_ELEC", - "BRAND_FIRE", - "BRAND_COLD" -}; - -/* - * Object flags - */ -static cptr k_info_flags2[] = -{ - "SUST_STR", - "SUST_INT", - "SUST_WIS", - "SUST_DEX", - "SUST_CON", - "SUST_CHR", - "INVIS", - "LIFE", - "IM_ACID", - "IM_ELEC", - "IM_FIRE", - "IM_COLD", - "SENS_FIRE", - "REFLECT", - "FREE_ACT", - "HOLD_LIFE", - "RES_ACID", - "RES_ELEC", - "RES_FIRE", - "RES_COLD", - "RES_POIS", - "RES_FEAR", - "RES_LITE", - "RES_DARK", - "RES_BLIND", - "RES_CONF", - "RES_SOUND", - "RES_SHARDS", - "RES_NETHER", - "RES_NEXUS", - "RES_CHAOS", - "RES_DISEN" -}; - -/* - * Trap flags - */ -static cptr k_info_flags2_trap[] = -{ - "AUTOMATIC_5", - "AUTOMATIC_99", - "KILL_GHOST", - "TELEPORT_TO", - "ONLY_DRAGON", - "ONLY_DEMON", - "XXX3", - "XXX3", - "ONLY_ANIMAL", - "ONLY_UNDEAD", - "ONLY_EVIL", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", - "XXX3", -}; - - -/* - * Object flags - */ -static cptr k_info_flags3[] = -{ - "SH_FIRE", - "SH_ELEC", - "AUTO_CURSE", - "DECAY", - "NO_TELE", - "NO_MAGIC", - "WRAITH", - "TY_CURSE", - "EASY_KNOW", - "HIDE_TYPE", - "SHOW_MODS", - "INSTA_ART", - "FEATHER", - "LITE1", - "SEE_INVIS", - "NORM_ART", - "SLOW_DIGEST", - "REGEN", - "XTRA_MIGHT", - "XTRA_SHOTS", - "IGNORE_ACID", - "IGNORE_ELEC", - "IGNORE_FIRE", - "IGNORE_COLD", - "ACTIVATE", - "DRAIN_EXP", - "TELEPORT", - "AGGRAVATE", - "BLESSED", - "CURSED", - "HEAVY_CURSE", - "PERMA_CURSE" -}; - -/* - * Object flags - */ -static cptr k_info_flags4[] = -{ - "NEVER_BLOW", - "PRECOGNITION", - "BLACK_BREATH", - "RECHARGE", - "FLY", - "DG_CURSE", - "COULD2H", - "MUST2H", - "LEVELS", - "CLONE", - "SPECIAL_GENE", - "CLIMB", - "FAST_CAST", - "CAPACITY", - "CHARGING", - "CHEAPNESS", - "FOUNTAIN", - "ANTIMAGIC_50", - "XXX5", - "XXX5", - "XXX5", - "EASY_USE", - "IM_NETHER", - "RECHARGED", - "ULTIMATE", - "AUTO_ID", - "LITE2", - "LITE3", - "FUEL_LITE", - "XXX5", - "CURSE_NO_DROP", - "NO_RECHARGE" -}; - -/* - * Object flags - */ -static cptr k_info_flags5[] = -{ - "TEMPORARY", - "DRAIN_MANA", - "DRAIN_HP", - "KILL_DEMON", - "KILL_UNDEAD", - "CRIT", - "ATTR_MULTI", - "WOUNDING", - "FULL_NAME", - "LUCK", - "IMMOVABLE", - "SPELL_CONTAIN", - "RES_MORGUL", - "ACTIVATE_NO_WIELD", - "MAGIC_BREATH", - "WATER_BREATH", - "WIELD_CAST", - "RANDOM_RESIST", - "RANDOM_POWER", - "RANDOM_RES_OR_POWER", - "XXX8X20", - "XXX8X21", - "XXX8X22", - "XXX8X23", - "XXX8X24", - "XXX8X25", - "XXX8X26", - "XXX8X27", - "XXX8X28", - "XXX8X29", - "XXX8X02", - "XXX8X22", -}; - -/* - * ESP flags - */ -static cptr esp_flags[] = -{ - "ESP_ORC", - "ESP_TROLL", - "ESP_DRAGON", - "ESP_GIANT", - "ESP_DEMON", - "ESP_UNDEAD", - "ESP_EVIL", - "ESP_ANIMAL", - "ESP_THUNDERLORD", - "ESP_GOOD", - "ESP_NONLIVING", - "ESP_UNIQUE", - "ESP_SPIDER", - "XXX8X02", - "XXX8X02", - "XXX8X02", - "XXX8X02", - "XXX8X17", - "XXX8X18", - "XXX8X19", - "XXX8X20", - "XXX8X21", - "XXX8X22", - "XXX8X23", - "XXX8X24", - "XXX8X25", - "XXX8X26", - "XXX8X27", - "XXX8X28", - "XXX8X29", - "XXX8X02", - "ESP_ALL", -}; - /* Specially handled properties for ego-items */ static cptr ego_flags[] = @@ -1190,6 +918,7 @@ static errr grab_one_class_flag(u32b *choice, cptr what) /* Failure */ return (1); } + static errr grab_one_race_allow_flag(u32b *choice, cptr what) { int i; @@ -1263,19 +992,30 @@ static int get_activation(char *activation) return -1; } +/* + * Convert string to object_flag_set value + */ +static object_flag_set object_flag_set_from_string(cptr what) +{ + for (auto const flag_meta: object_flags_meta()) + { + if (streq(what, flag_meta->e_name)) + { + return flag_meta->flag_set; + }; + } + + return object_flag_set(); +} + /* * Grab one flag in an object_kind from a textual string */ -static errr grab_one_race_kind_flag(u32b *f1, u32b *f2, u32b *f3, u32b *f4, u32b *f5, u32b *esp, cptr what) +static errr grab_object_flag(object_flag_set *flags, cptr what) { - if (lookup_flags(what, - flag_tie(f1, k_info_flags1), - flag_tie(f2, k_info_flags2), - flag_tie(f3, k_info_flags3), - flag_tie(f4, k_info_flags4), - flag_tie(f5, k_info_flags5), - flag_tie(esp, esp_flags))) + if (object_flag_set f = object_flag_set_from_string(what)) { + *flags |= f; return 0; } @@ -1620,7 +1360,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'F' for "level Flags" (multiple lines) */ if ((buf[0] == 'R') && (buf[2] == 'F')) { - if (0 != grab_one_race_kind_flag(&rp_ptr->oflags1[lev], &rp_ptr->oflags2[lev], &rp_ptr->oflags3[lev], &rp_ptr->oflags4[lev], &rp_ptr->oflags5[lev], &rp_ptr->oesp[lev], buf + 4)) + if (grab_object_flag(&rp_ptr->oflags[lev], buf + 4)) { return (5); } @@ -1916,7 +1656,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'F' for "level Flags" (multiple lines) */ if ((buf[0] == 'S') && (buf[2] == 'F')) { - if (0 != grab_one_race_kind_flag(&rmp_ptr->oflags1[lev], &rmp_ptr->oflags2[lev], &rmp_ptr->oflags3[lev], &rmp_ptr->oflags4[lev], &rmp_ptr->oflags5[lev], &rmp_ptr->oesp[lev], buf + 4)) + if (0 != grab_object_flag(&rmp_ptr->oflags[lev], buf + 4)) { return (5); } @@ -2370,7 +2110,10 @@ errr init_player_info_txt(FILE *fp) } /* Parse this entry */ - if (0 != grab_one_race_kind_flag(&c_ptr->oflags1[lev], &c_ptr->oflags2[lev], &c_ptr->oflags3[lev], &c_ptr->oflags4[lev], &c_ptr->oflags5[lev], &c_ptr->oesp[lev], s)) return (5); + if (0 != grab_object_flag(&c_ptr->oflags[lev], s)) + { + return (5); + } /* Start the next entry */ s = t; @@ -3058,39 +2801,6 @@ errr init_f_info_txt(FILE *fp) } -/* - * Grab one flag in an object_kind from a textual string - */ -static errr grab_one_kind_flag(object_kind *k_ptr, cptr what, bool_ obvious) -{ - /* Dispatch to correct set of flags */ - u32b *f1 = obvious ? &k_ptr->oflags1 : &k_ptr->flags1; - u32b *f2 = obvious ? &k_ptr->oflags2 : &k_ptr->flags2; - u32b *f3 = obvious ? &k_ptr->oflags3 : &k_ptr->flags3; - u32b *f4 = obvious ? &k_ptr->oflags4 : &k_ptr->flags4; - u32b *f5 = obvious ? &k_ptr->oflags5 : &k_ptr->flags5; - u32b *esp = obvious ? &k_ptr->oesp : &k_ptr->esp; - - /* Lookup */ - if (lookup_flags(what, - flag_tie(f1, k_info_flags1), - flag_tie(f2, k_info_flags2), - flag_tie(f2, k_info_flags2_trap), - flag_tie(f3, k_info_flags3), - flag_tie(f4, k_info_flags4), - flag_tie(f5, k_info_flags5), - flag_tie(esp, esp_flags))) - { - return 0; - } - - /* Oops */ - msg_format("Unknown object flag '%s'.", what); - - /* Error */ - return (1); -} - /* * Initialize the "k_info" array, by parsing an ascii "template" file */ @@ -3162,7 +2872,6 @@ errr init_k_info_txt(FILE *fp) k_ptr->text = my_strdup(""); /* Needed hack */ - k_ptr->esp = 0; k_ptr->power = -1; /* Next... */ @@ -3388,7 +3097,7 @@ errr init_k_info_txt(FILE *fp) /* Hack -- Process 'F' for flags */ if (buf[0] == 'F') { - if (0 != grab_one_kind_flag(k_ptr, buf + 2, FALSE)) + if (0 != grab_object_flag(&k_ptr->flags, buf + 2)) { return (5); } @@ -3400,7 +3109,7 @@ errr init_k_info_txt(FILE *fp) /* Hack -- Process 'f' for obvious flags */ if (buf[0] == 'f') { - if (0 != grab_one_kind_flag(k_ptr, buf + 2, TRUE)) + if (0 != grab_object_flag(&k_ptr->oflags, buf + 2)) { return (5); } @@ -3418,40 +3127,6 @@ errr init_k_info_txt(FILE *fp) return (0); } -/* - * Grab one flag in an artifact_type from a textual string - */ -static errr grab_one_artifact_flag(artifact_type *a_ptr, cptr what, bool_ obvious) -{ - /* Dispatch to correct set of flags */ - u32b *f1 = obvious ? &a_ptr->oflags1 : &a_ptr->flags1; - u32b *f2 = obvious ? &a_ptr->oflags2 : &a_ptr->flags2; - u32b *f3 = obvious ? &a_ptr->oflags3 : &a_ptr->flags3; - u32b *f4 = obvious ? &a_ptr->oflags4 : &a_ptr->flags4; - u32b *f5 = obvious ? &a_ptr->oflags5 : &a_ptr->flags5; - u32b *esp = obvious ? &a_ptr->oesp : &a_ptr->esp; - - /* Lookup */ - if (lookup_flags(what, - flag_tie(f1, k_info_flags1), - flag_tie(f2, k_info_flags2), - flag_tie(f2, k_info_flags2_trap), - flag_tie(f3, k_info_flags3), - flag_tie(f4, k_info_flags4), - flag_tie(f5, k_info_flags5), - flag_tie(esp, esp_flags))) - { - return 0; - } - - /* Oops */ - msg_format("Unknown artifact flag '%s'.", what); - - /* Error */ - return (1); -} - - /* @@ -3524,17 +3199,16 @@ errr init_a_info_txt(FILE *fp) a_ptr->text = my_strdup(""); /* Ignore everything */ - a_ptr->flags3 |= (TR3_IGNORE_ACID); - a_ptr->flags3 |= (TR3_IGNORE_ELEC); - a_ptr->flags3 |= (TR3_IGNORE_FIRE); - a_ptr->flags3 |= (TR3_IGNORE_COLD); + a_ptr->flags |= TR_IGNORE_ACID | + TR_IGNORE_ELEC | + TR_IGNORE_FIRE | + TR_IGNORE_COLD; /* Needed hack */ - a_ptr->esp = 0; a_ptr->power = -1; /*Require activating artifacts to have a activation type */ - if (a_ptr && a_ptr->flags3 & TR3_ACTIVATE && !a_ptr->activate) + if (a_ptr && (a_ptr->flags & TR_ACTIVATE) && !a_ptr->activate) { msg_print("Activate flag without activate type"); return 1; @@ -3654,7 +3328,10 @@ errr init_a_info_txt(FILE *fp) /* Hack -- Process 'F' for flags */ if (buf[0] == 'F') { - if (0 != grab_one_artifact_flag(a_ptr, buf+2, FALSE)) return (5); + if (grab_object_flag(&a_ptr->flags, buf+2)) + { + return (5); + } /* Next... */ continue; @@ -3663,7 +3340,10 @@ errr init_a_info_txt(FILE *fp) /* Hack -- Process 'f' for obvious flags */ if (buf[0] == 'f') { - if (0 != grab_one_artifact_flag(a_ptr, buf+2, TRUE)) return (5); + if (grab_object_flag(&a_ptr->oflags, buf+2)) + { + return (5); + } /* Next... */ continue; @@ -3759,26 +3439,6 @@ errr init_set_info_txt(FILE *fp) assert(!set_ptr->name); set_ptr->name = my_strdup(s); - /* Initialize */ - set_ptr->num = 0; - set_ptr->num_use = 0; - - for (std::size_t z = 0; z < SET_MAX_SIZE; z++) - { - set_ptr->arts[z].a_idx = 0; - set_ptr->arts[z].present = FALSE; - for (std::size_t y = 0; y < SET_MAX_SIZE; y++) - { - set_ptr->arts[z].flags1[y] = 0; - set_ptr->arts[z].flags2[y] = 0; - set_ptr->arts[z].flags3[y] = 0; - set_ptr->arts[z].flags4[y] = 0; - set_ptr->arts[z].flags5[y] = 0; - set_ptr->arts[z].esp[y] = 0; - set_ptr->arts[z].pval[y] = 0; - } - } - /* Next... */ continue; } @@ -3832,14 +3492,7 @@ errr init_set_info_txt(FILE *fp) /* Process 'F' for flags */ if (buf[0] == 'F') { - /* Parse this entry */ - if (0 != grab_one_race_kind_flag(&set_ptr->arts[cur_art].flags1[cur_num], - &set_ptr->arts[cur_art].flags2[cur_num], - &set_ptr->arts[cur_art].flags3[cur_num], - &set_ptr->arts[cur_art].flags4[cur_num], - &set_ptr->arts[cur_art].flags5[cur_num], - &set_ptr->arts[cur_art].esp[cur_num], - buf + 2)) + if (grab_object_flag(&set_ptr->arts[cur_art].flags[cur_num], buf + 2)) { return (5); } @@ -4429,67 +4082,30 @@ errr init_ab_info_txt(FILE *fp) /* - * Grab one flag in a ego-item_type from a textual string + * Grab one flag in a ego-item_type from a textual string. + * + * We explicitly allow nullptr for the "ego" parameter. */ -static bool_ grab_one_ego_item_flag(ego_item_type *e_ptr, cptr what, int n, bool_ obvious) +static bool_ grab_one_ego_item_flag(object_flag_set *flags, u32b *ego, cptr what) { - assert(n < FLAG_RARITY_MAX); - - /* Dispatch to correct set of flags */ - u32b *f1 = obvious ? &e_ptr->oflags1[n] : &e_ptr->flags1[n]; - u32b *f2 = obvious ? &e_ptr->oflags2[n] : &e_ptr->flags2[n]; - u32b *f3 = obvious ? &e_ptr->oflags3[n] : &e_ptr->flags3[n]; - u32b *f4 = obvious ? &e_ptr->oflags4[n] : &e_ptr->flags4[n]; - u32b *f5 = obvious ? &e_ptr->oflags5[n] : &e_ptr->flags5[n]; - u32b *esp = obvious ? &e_ptr->oesp[n] : &e_ptr->esp[n]; - u32b *ego = obvious ? &e_ptr->fego[n] : &e_ptr->fego[n]; - - /* Lookup */ - if (lookup_flags(what, - flag_tie(f1, k_info_flags1), - flag_tie(f2, k_info_flags2), - flag_tie(f2, k_info_flags2_trap), - flag_tie(f3, k_info_flags3), - flag_tie(f4, k_info_flags4), - flag_tie(f5, k_info_flags5), - flag_tie(esp, esp_flags), - flag_tie(ego, ego_flags))) + /* Lookup as an object_flag */ + if (auto f = object_flag_set_from_string(what)) { - return (0); + *flags |= f; + return 0; } - /* Oops */ - msg_format("Unknown ego-item flag '%s'.", what); - - /* Error */ - return (1); -} - -static bool_ grab_one_ego_item_flag_restrict(ego_item_type *e_ptr, cptr what, bool_ need) -{ - /* Dispatch to correct set of flags */ - u32b *f1 = need ? &e_ptr->need_flags1 : &e_ptr->forbid_flags1; - u32b *f2 = need ? &e_ptr->need_flags2 : &e_ptr->forbid_flags2; - u32b *f3 = need ? &e_ptr->need_flags3 : &e_ptr->forbid_flags3; - u32b *f4 = need ? &e_ptr->need_flags4 : &e_ptr->forbid_flags4; - u32b *f5 = need ? &e_ptr->need_flags5 : &e_ptr->forbid_flags5; - u32b *esp = need ? &e_ptr->need_esp : &e_ptr->forbid_esp; - - /* Lookup */ - if (lookup_flags(what, - flag_tie(f1, k_info_flags1), - flag_tie(f2, k_info_flags2), - flag_tie(f2, k_info_flags2_trap), - flag_tie(f3, k_info_flags3), - flag_tie(f4, k_info_flags4), - flag_tie(f5, k_info_flags5), - flag_tie(esp, esp_flags))) + /* Lookup as ego flag */ + if (ego) { - return 0; + if (lookup_flags(what, flag_tie(ego, ego_flags))) + { + return (0); + } } /* Oops */ - msg_format("Unknown ego-item restrict flag '%s'.", what); + msg_format("Unknown ego-item flag '%s'.", what); /* Error */ return (1); @@ -4497,13 +4113,12 @@ static bool_ grab_one_ego_item_flag_restrict(ego_item_type *e_ptr, cptr what, bo - /* * Initialize the "e_info" array, by parsing an ascii "template" file */ errr init_e_info_txt(FILE *fp) { - int i, cur_r = -1, cur_t = 0, j; + int i, cur_r = -1, cur_t = 0; char buf[1024]; char *s, *t; @@ -4557,6 +4172,10 @@ errr init_e_info_txt(FILE *fp) /* Save the index */ error_idx = i; + /* Reset cur_* variables */ + cur_r = -1; + cur_t = 0; + /* Point at the "info" */ e_ptr = &e_info[i]; @@ -4564,33 +4183,6 @@ errr init_e_info_txt(FILE *fp) assert(!e_ptr->name); e_ptr->name = my_strdup(s); - /* Needed hack */ - e_ptr->power = -1; - cur_r = -1; - cur_t = 0; - - for (j = 0; j < 10; j++) - { - e_ptr->tval[j] = 255; - } - for (j = 0; j < FLAG_RARITY_MAX; j++) - { - e_ptr->rar[j] = 0; - e_ptr->flags1[j] = 0; - e_ptr->flags2[j] = 0; - e_ptr->flags3[j] = 0; - e_ptr->flags4[j] = 0; - e_ptr->flags5[j] = 0; - e_ptr->esp[j] = 0; - e_ptr->oflags1[j] = 0; - e_ptr->oflags2[j] = 0; - e_ptr->oflags3[j] = 0; - e_ptr->oflags4[j] = 0; - e_ptr->oflags5[j] = 0; - e_ptr->oesp[j] = 0; - e_ptr->fego[j] = 0; - } - /* Next... */ continue; } @@ -4751,7 +4343,10 @@ errr init_e_info_txt(FILE *fp) } /* Parse this entry */ - if (0 != grab_one_ego_item_flag_restrict(e_ptr, s, TRUE)) return (5); + if (grab_object_flag(&e_ptr->need_flags, s)) + { + return (5); + } /* Start the next entry */ s = t; @@ -4764,7 +4359,7 @@ errr init_e_info_txt(FILE *fp) /* Hack -- Process 'r:F' for forbidden flags */ if ((buf[0] == 'r') && (buf[2] == 'F')) { - if (0 != grab_one_ego_item_flag_restrict(e_ptr, buf + 4, FALSE)) + if (grab_object_flag(&e_ptr->forbid_flags, buf + 4)) { return (5); } @@ -4792,7 +4387,14 @@ errr init_e_info_txt(FILE *fp) } /* Parse this entry */ - if (0 != grab_one_ego_item_flag(e_ptr, s, cur_r, FALSE)) return (5); + assert(cur_r < FLAG_RARITY_MAX); + if (0 != grab_one_ego_item_flag( + &e_ptr->flags[cur_r], + &e_ptr->fego[cur_r], + s)) + { + return (5); + } /* Start the next entry */ s = t; @@ -4821,7 +4423,14 @@ errr init_e_info_txt(FILE *fp) } /* Parse this entry */ - if (0 != grab_one_ego_item_flag(e_ptr, s, cur_r, TRUE)) return (5); + assert(cur_r < FLAG_RARITY_MAX); + if (0 != grab_one_ego_item_flag( + &e_ptr->oflags[cur_r], + nullptr, + s)) + { + return (5); + } /* Start the next entry */ s = t; @@ -4839,51 +4448,6 @@ errr init_e_info_txt(FILE *fp) return (0); } -/* - * Grab one flag in a randart_part_type from a textual string - */ -static bool_ grab_one_randart_item_flag(randart_part_type *ra_ptr, cptr what, char c) -{ - bool regular = (c == 'F'); - - /* Dispatch to correct set of flags */ - u32b *f1 = regular ? &ra_ptr->flags1 : &ra_ptr->aflags1; - u32b *f2 = regular ? &ra_ptr->flags2 : &ra_ptr->aflags2; - u32b *f3 = regular ? &ra_ptr->flags3 : &ra_ptr->aflags3; - u32b *f4 = regular ? &ra_ptr->flags4 : &ra_ptr->aflags4; - u32b *f5 = regular ? &ra_ptr->flags5 : &ra_ptr->aflags5; - u32b *esp = regular ? &ra_ptr->esp : &ra_ptr->aesp; - - /* Check flags */ - if (lookup_flags(what, - flag_tie(f1, k_info_flags1), - flag_tie(f2, k_info_flags2), - flag_tie(f2, k_info_flags2_trap), - flag_tie(f3, k_info_flags3), - flag_tie(f4, k_info_flags4), - flag_tie(f5, k_info_flags5), - flag_tie(esp, esp_flags))) - { - return 0; - } - - /* Check ego_flags */ - if (regular) - { - if (lookup_flags(what, flag_tie(&ra_ptr->fego, ego_flags))) - { - return 0; - } - } - - /* Oops */ - msg_format("Unknown ego-item flag '%s'.", what); - - /* Error */ - return (1); -} - - /* @@ -4964,12 +4528,7 @@ errr init_ra_info_txt(FILE *fp) { ra_ptr->tval[j] = 255; } - ra_ptr->flags1 = 0; - ra_ptr->flags2 = 0; - ra_ptr->flags3 = 0; - ra_ptr->flags4 = 0; - ra_ptr->flags5 = 0; - ra_ptr->esp = 0; + ra_ptr->flags = object_flag_set(); ra_ptr->fego = 0; /* Next... */ @@ -5076,10 +4635,13 @@ errr init_ra_info_txt(FILE *fp) continue; } - /* Hack -- Process 'F' for flags */ + /* Process 'F' for flags */ if (buf[0] == 'F') { - if (0 != grab_one_randart_item_flag(ra_ptr, buf + 2, 'F')) + if (0 != grab_one_ego_item_flag( + &ra_ptr->flags, + &ra_ptr->fego, + buf + 2)) { return (5); } @@ -5088,10 +4650,13 @@ errr init_ra_info_txt(FILE *fp) continue; } - /* Hack -- Process 'A' for antagonic flags */ + /* Process 'A' for antagonic flags */ if (buf[0] == 'A') { - if (0 != grab_one_randart_item_flag(ra_ptr, buf + 2, 'A')) + if (0 != grab_one_ego_item_flag( + &ra_ptr->aflags, + nullptr, + buf + 2)) { return (5); } @@ -7659,10 +7224,11 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst Let's just HACK around one observed bug: Shadow Cloak of Luthien [Globe of Light] */ { - u32b f1, f2, f3, f4, f5, esp; - 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; + } } /* Drop the artifact */ -- cgit v1.2.3 From 3966bfb2f6836d13c1a93bfab1e9fa61ec4fff35 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 21 Jun 2016 21:17:20 +0200 Subject: Rework FF1_* flags to flags_set<> --- src/init1.cc | 56 +++++++++++--------------------------------------------- 1 file changed, 11 insertions(+), 45 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 0a6ecff0..ec12ad34 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -7,6 +7,7 @@ #include "dungeon_info_type.hpp" #include "dungeon_flag.hpp" #include "ego_item_type.hpp" +#include "feature_flag.hpp" #include "feature_type.hpp" #include "files.hpp" #include "gods.hpp" @@ -193,45 +194,6 @@ static cptr ego_flags[] = "LIMIT_BLOWS" }; -/* - * Feature flags - */ -static cptr f_info_flags1[] = -{ - "NO_WALK", - "NO_VISION", - "CAN_LEVITATE", - "CAN_PASS", - "FLOOR", - "WALL", - "PERMANENT", - "CAN_FLY", - "REMEMBER", - "NOTICE", - "DONT_NOTICE_RUNNING", - "CAN_RUN", - "DOOR", - "SUPPORT_LIGHT", - "CAN_CLIMB", - "TUNNELABLE", - "WEB", - "ATTR_MULTI", - "SUPPORT_GROWTH", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1" -}; - /* * Trap flags */ @@ -2540,12 +2502,16 @@ errr init_v_info_txt(FILE *fp) /* * Grab one flag in an feature_type from a textual string */ -static errr grab_one_feature_flag(u32b *f1, cptr what) +static int grab_one_feature_flag(cptr what, feature_flag_set *flags) { - if (lookup_flags(what, flag_tie(f1, f_info_flags1))) - { - return (0); - } +#define FF(tier, index, name) \ + if (streq(what, #name)) \ + { \ + *flags |= BOOST_PP_CAT(FF_,name); \ + return 0; \ + }; +#include "feature_flag_list.hpp" +#undef FF /* Oops */ msg_format("Unknown feature flag '%s'.", what); @@ -2783,7 +2749,7 @@ errr init_f_info_txt(FILE *fp) /* Hack -- Process 'F' for flags */ if (buf[0] == 'F') { - if (0 != grab_one_feature_flag(&f_ptr->flags1, buf + 2)) + if (0 != grab_one_feature_flag(buf + 2, &f_ptr->flags)) { return (5); } -- cgit v1.2.3 From 3941b7834f0a038ed544e6ee96b9920d43db4c32 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 22 Jun 2016 07:42:43 +0200 Subject: Rework PR{1,2}_* flags to flag_set<> Since there's no need for two tiers we also reduce the flag set to 1 tier. (Breaks savefile compatbility.) --- src/init1.cc | 106 ++++++++++------------------------------------------------- 1 file changed, 17 insertions(+), 89 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index ec12ad34..53e9d851 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -28,6 +28,7 @@ #include "owner_type.hpp" #include "player_class.hpp" #include "player_race.hpp" +#include "player_race_flag.hpp" #include "player_race_mod.hpp" #include "player_type.hpp" #include "randart_gen_type.hpp" @@ -272,84 +273,6 @@ static cptr st_info_flags1[] = "XXX1" }; -/* - * Race flags - */ -static cptr rp_info_flags1[] = -{ - "EXPERIMENTAL", - "XXX", - "RESIST_BLACK_BREATH", - "NO_STUN", - "XTRA_MIGHT_BOW", - "XTRA_MIGHT_XBOW", - "XTRA_MIGHT_SLING", - "AC_LEVEL", - "HURT_LITE", - "VAMPIRE", - "UNDEAD", - "NO_CUT", - "CORRUPT", - "NO_FOOD", - "NO_GOD", - "XXX", - "ELF", - "SEMI_WRAITH", - "NO_SUBRACE_CHANGE", - "XXX", - "XXX", - "MOLD_FRIEND", - "GOD_FRIEND", - "XXX", - "INNATE_SPELLS", - "XXX", - "XXX", - "EASE_STEAL", - "XXX", - "XXX", - "XXX", - "XXX" -}; - -/* - * Race flags - */ -static cptr rp_info_flags2[] = -{ - "XXX", - "ASTRAL", - "XXX", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1" -}; - /* Skill flags */ static cptr s_info_flags1[] = { @@ -922,14 +845,16 @@ static errr grab_one_skill_flag(u32b *f1, cptr what) /* * Grab one flag from a textual string */ -static errr grab_one_player_race_flag(u32b *f1, u32b *f2, cptr what) +static errr grab_one_player_race_flag(player_race_flag_set *flags, cptr what) { - if (lookup_flags(what, - flag_tie(f1, rp_info_flags1), - flag_tie(f2, rp_info_flags2))) - { - return 0; - } +#define PR(tier, index, name) \ + if (streq(what, #name)) \ + { \ + *flags |= BOOST_PP_CAT(PR_,name); \ + return 0; \ + }; +#include "player_race_flag_list.hpp" +#undef PR /* Oops */ msg_format("(2)Unknown race flag '%s'.", what); @@ -1310,7 +1235,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'G' for "Player flags" (multiple lines) */ if ((buf[0] == 'R') && (buf[2] == 'G')) { - if (0 != grab_one_player_race_flag(&rp_ptr->flags1, &rp_ptr->flags2, buf + 4)) + if (0 != grab_one_player_race_flag(&rp_ptr->flags, buf + 4)) { return (5); } @@ -1606,7 +1531,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'G' for "Player flags" (multiple lines) */ if ((buf[0] == 'S') && (buf[2] == 'G')) { - if (0 != grab_one_player_race_flag(&rmp_ptr->flags1, &rmp_ptr->flags2, buf + 4)) + if (0 != grab_one_player_race_flag(&rmp_ptr->flags, buf + 4)) { return (5); } @@ -2046,7 +1971,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'G' for "Player flags" (multiple lines) */ if ((buf[0] == 'C') && (buf[2] == 'G')) { - if (0 != grab_one_player_race_flag(&c_ptr->flags1, &c_ptr->flags2, buf + 4)) + if (0 != grab_one_player_race_flag(&c_ptr->flags, buf + 4)) { return (5); } @@ -2244,7 +2169,10 @@ errr init_player_info_txt(FILE *fp) } /* Parse this entry */ - if (0 != grab_one_player_race_flag(&s_ptr->flags1, &s_ptr->flags2, s)) return (5); + if (0 != grab_one_player_race_flag(&s_ptr->flags, s)) + { + return (5); + } /* Start the next entry */ s = t; -- cgit v1.2.3 From 6f02ef2e62739efc23d10ae2c7cea69a908b657b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 21 Jun 2016 11:02:48 +0200 Subject: Rework ETR4_* flags to flag_set<> --- src/init1.cc | 62 ++++++++++++++++++++---------------------------------------- 1 file changed, 21 insertions(+), 41 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 53e9d851..7b15440a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6,6 +6,7 @@ #include "cave_type.hpp" #include "dungeon_info_type.hpp" #include "dungeon_flag.hpp" +#include "ego_flag.hpp" #include "ego_item_type.hpp" #include "feature_flag.hpp" #include "feature_type.hpp" @@ -157,44 +158,6 @@ static cptr r_info_blow_effect[] = }; -/* Specially handled properties for ego-items */ - -static cptr ego_flags[] = -{ - "SUSTAIN", - "OLD_RESIST", - "ABILITY", - "R_ELEM", - "R_LOW", - "R_HIGH", - "R_ANY", - "R_DRAGON", - "SLAY_WEAP", - "DAM_DIE", - "DAM_SIZE", - "PVAL_M1", - "PVAL_M2", - "PVAL_M3", - "PVAL_M5", - "AC_M1", - "AC_M2", - "AC_M3", - "AC_M5", - "TH_M1", - "TH_M2", - "TH_M3", - "TH_M5", - "TD_M1", - "TD_M2", - "TD_M3", - "TD_M5", - "R_P_ABILITY", - "R_STAT", - "R_STAT_SUST", - "R_IMMUNITY", - "LIMIT_BLOWS" -}; - /* * Trap flags */ @@ -3975,12 +3938,28 @@ errr init_ab_info_txt(FILE *fp) } +/* + * Look up ego flag + */ +static ego_flag_set lookup_ego_flag(const char *what) +{ +#define ETR(tier, index, name) \ + if (streq(what, #name)) \ + { \ + return BOOST_PP_CAT(ETR_,name); \ + }; +#include "ego_flag_list.hpp" +#undef ETR + return ego_flag_set(); +} + + /* * Grab one flag in a ego-item_type from a textual string. * * We explicitly allow nullptr for the "ego" parameter. */ -static bool_ grab_one_ego_item_flag(object_flag_set *flags, u32b *ego, cptr what) +static bool_ grab_one_ego_item_flag(object_flag_set *flags, ego_flag_set *ego, cptr what) { /* Lookup as an object_flag */ if (auto f = object_flag_set_from_string(what)) @@ -3992,8 +3971,9 @@ static bool_ grab_one_ego_item_flag(object_flag_set *flags, u32b *ego, cptr what /* Lookup as ego flag */ if (ego) { - if (lookup_flags(what, flag_tie(ego, ego_flags))) + if (auto f = lookup_ego_flag(what)) { + *ego |= f; return (0); } } @@ -4423,7 +4403,7 @@ errr init_ra_info_txt(FILE *fp) ra_ptr->tval[j] = 255; } ra_ptr->flags = object_flag_set(); - ra_ptr->fego = 0; + ra_ptr->fego = ego_flag_set(); /* Next... */ continue; -- cgit v1.2.3 From 9e04bdd234e09e3e2e50c65ec21688a496ae1c4f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 22 Jun 2016 09:36:59 +0200 Subject: Split store_info_type::table into a "kind" and "chance" component --- src/init1.cc | 17 ++++++++++------- 1 file changed, 10 insertions(+), 7 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 7b15440a..e4c2bc98 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6100,13 +6100,14 @@ errr init_st_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - st_ptr->table[item_idx][1] = atoi(buf + 2); + st_ptr->item_chance[item_idx] = atoi(buf + 2); /* Append chars to the name */ - st_ptr->table[item_idx++][0] = test_item_name(s); + st_ptr->item_kind[item_idx] = test_item_name(s); - st_ptr->table_num = item_idx; - assert(st_ptr->table_num <= STORE_CHOICES); + item_idx++; + st_ptr->item_num = item_idx; + assert(st_ptr->item_num <= STORE_CHOICES); /* Next... */ continue; @@ -6122,11 +6123,13 @@ errr init_st_info_txt(FILE *fp) &rar1, &tv1, &sv1)) return (1); /* Get the index */ - st_ptr->table[item_idx][1] = rar1; + st_ptr->item_chance[item_idx] = rar1; /* Hack -- 256 as a sval means all possible items */ - st_ptr->table[item_idx++][0] = (sv1 < 256) ? lookup_kind(tv1, sv1) : tv1 + 10000; + st_ptr->item_kind[item_idx] = (sv1 < 256) ? lookup_kind(tv1, sv1) : tv1 + 10000; - st_ptr->table_num = item_idx; + item_idx++; + st_ptr->item_num = item_idx; + assert(st_ptr->item_num <= STORE_CHOICES); /* Next... */ continue; -- cgit v1.2.3 From e3cd14d9d6d0e90bae7864025e5b2865c045ef96 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 22 Jun 2016 10:13:59 +0200 Subject: Rework SF1_* flags to flag_set<> --- src/init1.cc | 59 +++++++++++++---------------------------------------------- 1 file changed, 13 insertions(+), 46 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index e4c2bc98..37cc9de3 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -39,6 +39,7 @@ #include "skills.hpp" #include "spells5.hpp" #include "store_action_type.hpp" +#include "store_flag.hpp" #include "store_info_type.hpp" #include "store_type.hpp" #include "tables.hpp" @@ -197,45 +198,6 @@ static cptr t_info_flags[] = "XXX32" }; -/* - * Stores flags - */ -static cptr st_info_flags1[] = -{ - "DEPEND_LEVEL", - "SHALLOW_LEVEL", - "MEDIUM_LEVEL", - "DEEP_LEVEL", - "RARE", - "VERY_RARE", - "COMMON", - "ALL_ITEM", - "RANDOM", - "FORCE_LEVEL", - "MUSEUM", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1" -}; - /* Skill flags */ static cptr s_info_flags1[] = { @@ -5994,13 +5956,15 @@ static errr grab_one_race_flag(owner_type *ow_ptr, int state, cptr what) /* * Grab one store flag from a textual string */ -static errr grab_one_store_flag(store_info_type *st_ptr, cptr what) +static errr grab_one_store_flag(store_flag_set *flags, cptr what) { - /* Scan store flags */ - if (lookup_flags(what, flag_tie(&st_ptr->flags1, st_info_flags1))) - { - return 0; - } +#define STF(tier, index, name) \ + if (streq(what, #name)) { \ + *flags |= BOOST_PP_CAT(STF_,name); \ + return 0; \ + } +#include "store_flag_list.hpp" +#undef STF /* Oops */ msg_format("Unknown store flag '%s'.", what); @@ -6183,7 +6147,10 @@ errr init_st_info_txt(FILE *fp) /* Process 'F' for "store Flags" (multiple lines) */ if (buf[0] == 'F') { - if (0 != grab_one_store_flag(st_ptr, buf + 2)) return (5); + if (0 != grab_one_store_flag(&st_ptr->flags, buf + 2)) + { + return (5); + } /* Next... */ continue; -- cgit v1.2.3 From c7544e07ecec46084970e708176a12d94ecf7bd0 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 22 Jun 2016 10:42:25 +0200 Subject: Remove unused "rate" field from store_type --- src/init1.cc | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 37cc9de3..ba13cfae 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3569,24 +3569,6 @@ errr init_s_info_txt(FILE *fp) continue; } - /* Process 'I' for "Info" (one line only) */ - if (buf[0] == 'I') - { - int rate; - - /* Scan for the values */ - if (1 != sscanf(buf + 2, "%d", &rate)) - { - return (1); - } - - /* Save the values */ - s_ptr->rate = rate; - - /* Next... */ - continue; - } - /* Process 'G' for "random Gain" (one line only) */ if (buf[0] == 'G') { -- cgit v1.2.3 From 85143506abfb231a6ffc717a0ebc1a8339cd8a50 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 22 Jun 2016 11:26:23 +0200 Subject: Rework SKF1_* flags to flag_set<> --- src/init1.cc | 54 +++++++++++------------------------------------------- 1 file changed, 11 insertions(+), 43 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index ba13cfae..13a376d3 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -35,6 +35,7 @@ #include "randart_gen_type.hpp" #include "randart_part_type.hpp" #include "set_type.hpp" +#include "skill_flag.hpp" #include "skill_type.hpp" #include "skills.hpp" #include "spells5.hpp" @@ -198,43 +199,6 @@ static cptr t_info_flags[] = "XXX32" }; -/* Skill flags */ -static cptr s_info_flags1[] = -{ - "HIDDEN", - "AUTO_HIDE", - "RANDOM_GAIN", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1", - "XXX1" -}; - /* * Helpers for looking up flags in the above arrays @@ -754,12 +718,16 @@ static errr grab_one_race_allow_flag(u32b *choice, cptr what) /* * Grab one flag from a textual string */ -static errr grab_one_skill_flag(u32b *f1, cptr what) +static errr grab_one_skill_flag(skill_flag_set *flags, cptr what) { - if (lookup_flags(what, flag_tie(f1, s_info_flags1))) - { - return 0; - } +#define SKF(tier, index, name) \ + if (streq(what, #name)) \ + { \ + *flags |= BOOST_PP_CAT(SKF_,name); \ + return 0; \ + }; +#include "skill_flag_list.hpp" +#undef SKF /* Oops */ msg_format("(2)Unknown skill flag '%s'.", what); @@ -3590,7 +3558,7 @@ errr init_s_info_txt(FILE *fp) /* Process 'F' for flags */ if (buf[0] == 'F') { - if (0 != grab_one_skill_flag(&s_ptr->flags1, buf + 2)) + if (0 != grab_one_skill_flag(&s_ptr->flags, buf + 2)) { return (5); } -- cgit v1.2.3 From 68d77669646e9a51bb622bdced5be948c58791e2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Remove unused fields in player_{class,race,race_mod} structs --- src/init1.cc | 88 ------------------------------------------------------------ 1 file changed, 88 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 13a376d3..ed173481 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1041,28 +1041,6 @@ errr init_player_info_txt(FILE *fp) continue; } - /* Process 'K' for "sKills" */ - if ((buf[0] == 'R') && (buf[2] == 'K')) - { - int s[8]; - - /* Scan for the values */ - if (8 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d", - &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7])) return (1); - - rp_ptr->r_dis = s[0]; - rp_ptr->r_dev = s[1]; - rp_ptr->r_sav = s[2]; - rp_ptr->r_stl = s[3]; - rp_ptr->r_srh = s[4]; - rp_ptr->r_fos = s[5]; - rp_ptr->r_thn = s[6]; - rp_ptr->r_thb = s[7]; - - /* Next... */ - continue; - } - /* Process 'k' for "skills" */ if ((buf[0] == 'R') && (buf[2] == 'k')) { @@ -1382,28 +1360,6 @@ errr init_player_info_txt(FILE *fp) continue; } - /* Process 'K' for "sKills" */ - if ((buf[0] == 'S') && (buf[2] == 'K')) - { - int s[8]; - - /* Scan for the values */ - if (8 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d", - &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7])) return (1); - - rmp_ptr->r_dis = s[0]; - rmp_ptr->r_dev = s[1]; - rmp_ptr->r_sav = s[2]; - rmp_ptr->r_stl = s[3]; - rmp_ptr->r_srh = s[4]; - rmp_ptr->r_fos = s[5]; - rmp_ptr->r_thn = s[6]; - rmp_ptr->r_thb = s[7]; - - /* Next... */ - continue; - } - /* Process 'P' for "xtra" */ if ((buf[0] == 'S') && (buf[2] == 'P')) { @@ -1764,50 +1720,6 @@ errr init_player_info_txt(FILE *fp) continue; } - /* Process 'K' for "sKills" */ - if ((buf[0] == 'C') && (buf[2] == 'K')) - { - int s[8]; - - /* Scan for the values */ - if (8 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d", - &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7])) return (1); - - c_ptr->c_dis = s[0]; - c_ptr->c_dev = s[1]; - c_ptr->c_sav = s[2]; - c_ptr->c_stl = s[3]; - c_ptr->c_srh = s[4]; - c_ptr->c_fos = s[5]; - c_ptr->c_thn = s[6]; - c_ptr->c_thb = s[7]; - - /* Next... */ - continue; - } - - /* Process 'x' for "Xtra skills" */ - if ((buf[0] == 'C') && (buf[2] == 'X')) - { - int s[8]; - - /* Scan for the values */ - if (8 != sscanf(buf + 4, "%d:%d:%d:%d:%d:%d:%d:%d", - &s[0], &s[1], &s[2], &s[3], &s[4], &s[5], &s[6], &s[7])) return (1); - - c_ptr->x_dis = s[0]; - c_ptr->x_dev = s[1]; - c_ptr->x_sav = s[2]; - c_ptr->x_stl = s[3]; - c_ptr->x_srh = s[4]; - c_ptr->x_fos = s[5]; - c_ptr->x_thn = s[6]; - c_ptr->x_thb = s[7]; - - /* Next... */ - continue; - } - /* Process 'P' for "xtra" */ if ((buf[0] == 'C') && (buf[2] == 'P')) { -- cgit v1.2.3 From f1898380237c975d07cf98bb25a882085f1e3b95 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Change meta_class_type::classes to std::vector --- src/init1.cc | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index ed173481..05a4f857 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -2039,8 +2039,6 @@ errr init_player_info_txt(FILE *fp) /* Append chars to the name */ strcpy(mc_ptr->name, s + 2); mc_ptr->color = color_char_to_attr(s[0]); - for (powers = 0; powers < max_c_idx; powers++) - mc_ptr->classes[powers] = -1; powers = 0; /* Next... */ @@ -2066,7 +2064,7 @@ errr init_player_info_txt(FILE *fp) if (i == max_c_idx) return (6); - mc_ptr->classes[powers++] = i; + mc_ptr->classes.push_back(i); /* Next... */ continue; -- cgit v1.2.3 From 2fa1a5e82a4e13f16ea6001c11d2452bac036d20 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Unify skill_* fields into skill_modifier{,s} --- src/init1.cc | 120 +++++++++++++++++++++++++---------------------------------- 1 file changed, 51 insertions(+), 69 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 05a4f857..d86fbd4e 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -806,6 +806,37 @@ static errr grab_object_flag(object_flag_set *flags, cptr what) return (1); } +/* + * Read skill values + */ +static int read_skill_modifiers(skill_modifiers *skill_modifiers, cptr buf) +{ + long val, mod; + char v, m; + char name[200]; + + if (5 != sscanf(buf, "%c%ld:%c%ld:%s", &v, &val, &m, &mod, name)) + { + return 1; + } + + long i; + if ((i = find_skill(name)) == -1) + { + return 1; + } + + auto s = &skill_modifiers->modifiers[i]; + + s->basem = monster_ego_modify(v); + s->base = val; + s->modm = monster_ego_modify(m); + s->mod = mod; + + return 0; +} + + /* * Initialize the "player" arrays, by parsing an ascii "template" file */ @@ -834,15 +865,6 @@ errr init_player_info_txt(FILE *fp) /* Just before the first line */ error_line = -1; - /* Init general skills */ - for (z = 0; z < MAX_SKILLS; z++) - { - gen_skill_basem[z] = 0; - gen_skill_base[z] = 0; - gen_skill_modm[z] = 0; - gen_skill_mod[z] = 0; - } - /* Parse */ while (0 == my_fgets(fp, buf, 1024)) { @@ -888,18 +910,10 @@ errr init_player_info_txt(FILE *fp) /* Process 'G:k' for "General skills" */ if ((buf[0] == 'G') && (buf[2] == 'k')) { - long val, mod, i; - char name[200], v, m; - - /* Scan for the values */ - if (5 != sscanf(buf + 4, "%c%ld:%c%ld:%s", - &v, &val, &m, &mod, name)) return (1); - - if ((i = find_skill(name)) == -1) return (1); - gen_skill_basem[i] = monster_ego_modify(v); - gen_skill_base[i] = val; - gen_skill_modm[i] = monster_ego_modify(m); - gen_skill_mod[i] = mod; + if (read_skill_modifiers(gen_skill, buf + 4)) + { + return 1; + } /* Next... */ continue; @@ -1044,18 +1058,10 @@ errr init_player_info_txt(FILE *fp) /* Process 'k' for "skills" */ if ((buf[0] == 'R') && (buf[2] == 'k')) { - long val, mod, i; - char name[200], v, m; - - /* Scan for the values */ - if (5 != sscanf(buf + 4, "%c%ld:%c%ld:%s", - &v, &val, &m, &mod, name)) return (1); - - if ((i = find_skill(name)) == -1) return (1); - rp_ptr->skill_basem[i] = monster_ego_modify(v); - rp_ptr->skill_base[i] = val; - rp_ptr->skill_modm[i] = monster_ego_modify(m); - rp_ptr->skill_mod[i] = mod; + if (read_skill_modifiers(&rp_ptr->skill_modifiers, buf + 4)) + { + return 1; + } /* Next... */ continue; @@ -1319,18 +1325,10 @@ errr init_player_info_txt(FILE *fp) /* Process 'k' for "skills" */ if ((buf[0] == 'S') && (buf[2] == 'k')) { - long val, mod, i; - char name[200], v, m; - - /* Scan for the values */ - if (5 != sscanf(buf + 4, "%c%ld:%c%ld:%s", - &v, &val, &m, &mod, name)) return (1); - - if ((i = find_skill(name)) == -1) return (1); - rmp_ptr->skill_basem[i] = monster_ego_modify(v); - rmp_ptr->skill_base[i] = val; - rmp_ptr->skill_modm[i] = monster_ego_modify(m); - rmp_ptr->skill_mod[i] = mod; + if (read_skill_modifiers(&rmp_ptr->skill_modifiers, buf + 4)) + { + return 1; + } /* Next... */ continue; @@ -1640,18 +1638,10 @@ errr init_player_info_txt(FILE *fp) /* Process 'k' for "skills" */ if ((buf[0] == 'C') && (buf[2] == 'k')) { - long val, mod, i; - char name[200], v, m; - - /* Scan for the values */ - if (5 != sscanf(buf + 4, "%c%ld:%c%ld:%s", - &v, &val, &m, &mod, name)) return (1); - - if ((i = find_skill(name)) == -1) return (1); - c_ptr->skill_basem[i] = monster_ego_modify(v); - c_ptr->skill_base[i] = val; - c_ptr->skill_modm[i] = monster_ego_modify(m); - c_ptr->skill_mod[i] = mod; + if (read_skill_modifiers(&c_ptr->skill_modifiers, buf + 4)) + { + return 1; + } /* Next... */ continue; @@ -1916,18 +1906,10 @@ errr init_player_info_txt(FILE *fp) /* Process 'k' for "skills" */ if (buf[4] == 'k') { - long val, mod, i; - char name[200], v, m; - - /* Scan for the values */ - if (5 != sscanf(buf + 6, "%c%ld:%c%ld:%s", - &v, &val, &m, &mod, name)) return (1); - - if ((i = find_skill(name)) == -1) return (1); - s_ptr->skill_basem[i] = monster_ego_modify(v); - s_ptr->skill_base[i] = val; - s_ptr->skill_modm[i] = monster_ego_modify(m); - s_ptr->skill_mod[i] = mod; + if (read_skill_modifiers(&s_ptr->skill_modifiers, buf + 6)) + { + return 1; + } /* Next... */ continue; -- cgit v1.2.3 From 804ff8c184e8ce892ed7629ba6feec9bef5aa7ff Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Remove unused player_spec::skill_ideal field --- src/init1.cc | 18 ------------------ 1 file changed, 18 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index d86fbd4e..e504f5ed 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1968,24 +1968,6 @@ errr init_player_info_txt(FILE *fp) /* Next... */ continue; } - - - /* Process 'K' for "desired skills" */ - if (buf[4] == 'K') - { - long val; - char name[200]; - - /* Scan for the values */ - if (2 != sscanf(buf + 6, "%ld:%s", - &val, name)) return (1); - - if ((i = find_skill(name)) == -1) return (1); - s_ptr->skill_ideal[i] = val; - - /* Next... */ - continue; - } } /* Process 'N' for "New/Number/Name" */ -- cgit v1.2.3 From 4d07dca15f547f6233b714c8c82b43bcd5beaebc Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Unify obj_* fields into object_proto struct --- src/init1.cc | 109 ++++++++++++++++++++--------------------------------------- 1 file changed, 37 insertions(+), 72 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index e504f5ed..5b1e5709 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -837,6 +837,35 @@ static int read_skill_modifiers(skill_modifiers *skill_modifiers, cptr buf) } +/* + * Read prototype objects + */ +static int read_proto_object(object_proto *proto, s16b *num, cptr buf) +{ + int s0, s1, s2, s3, s4; + + if (5 != sscanf(buf, "%d:%d:%d:%dd%d", &s0, &s1, &s4, &s2, &s3)) + { + s4 = 0; + + if (4 != sscanf(buf, "%d:%d:%dd%d", &s0, &s1, &s2, &s3)) + { + return 1; + } + } + + proto->pval = s4; + proto->tval = s0; + proto->sval = s1; + proto->dd = s2; + proto->ds = s3; + + (*num)++; + + return 0; +} + + /* * Initialize the "player" arrays, by parsing an ascii "template" file */ @@ -1136,27 +1165,11 @@ errr init_player_info_txt(FILE *fp) /* Process 'O' for "Object birth" */ if ((buf[0] == 'R') && (buf[2] == 'O')) { - int s[5]; - - /* Scan for the values */ - if (5 != sscanf(buf + 4, "%d:%d:%d:%dd%d", - &s[0], &s[1], &s[4], &s[2], &s[3])) + if (read_proto_object(&rp_ptr->obj[rp_ptr->obj_num], &rp_ptr->obj_num, buf + 4)) { - s[4] = 0; - - if (4 != sscanf(buf + 4, "%d:%d:%dd%d", - &s[0], &s[1], &s[2], &s[3])) - { - return (1); - } + return 1; } - rp_ptr->obj_pval[rp_ptr->obj_num] = s[4]; - rp_ptr->obj_tval[rp_ptr->obj_num] = s[0]; - rp_ptr->obj_sval[rp_ptr->obj_num] = s[1]; - rp_ptr->obj_dd[rp_ptr->obj_num] = s[2]; - rp_ptr->obj_ds[rp_ptr->obj_num++] = s[3]; - /* Next... */ continue; } @@ -1402,27 +1415,11 @@ errr init_player_info_txt(FILE *fp) /* Process 'O' for "Object birth" */ if ((buf[0] == 'S') && (buf[2] == 'O')) { - int s[5]; - - /* Scan for the values */ - if (5 != sscanf(buf + 4, "%d:%d:%d:%dd%d", - &s[0], &s[1], &s[4], &s[2], &s[3])) + if (read_proto_object(&rmp_ptr->obj[rmp_ptr->obj_num], &rmp_ptr->obj_num, buf + 4)) { - s[4] = 0; - - if (4 != sscanf(buf + 4, "%d:%d:%dd%d", - &s[0], &s[1], &s[2], &s[3])) - { - return (1); - } + return 1; } - rmp_ptr->obj_pval[rmp_ptr->obj_num] = s[4]; - rmp_ptr->obj_tval[rmp_ptr->obj_num] = s[0]; - rmp_ptr->obj_sval[rmp_ptr->obj_num] = s[1]; - rmp_ptr->obj_dd[rmp_ptr->obj_num] = s[2]; - rmp_ptr->obj_ds[rmp_ptr->obj_num++] = s[3]; - /* Next... */ continue; } @@ -1560,27 +1557,11 @@ errr init_player_info_txt(FILE *fp) /* Process 'O' for "Object birth" */ if ((buf[0] == 'C') && (buf[2] == 'O')) { - int s[5]; - - /* Scan for the values */ - if (5 != sscanf(buf + 4, "%d:%d:%d:%dd%d", - &s[0], &s[1], &s[4], &s[2], &s[3])) + if (read_proto_object(&c_ptr->obj[c_ptr->obj_num], &c_ptr->obj_num, buf + 4)) { - s[4] = 0; - - if (4 != sscanf(buf + 4, "%d:%d:%dd%d", - &s[0], &s[1], &s[2], &s[3])) - { - return (1); - } + return 1; } - c_ptr->obj_pval[c_ptr->obj_num] = s[4]; - c_ptr->obj_tval[c_ptr->obj_num] = s[0]; - c_ptr->obj_sval[c_ptr->obj_num] = s[1]; - c_ptr->obj_dd[c_ptr->obj_num] = s[2]; - c_ptr->obj_ds[c_ptr->obj_num++] = s[3]; - /* Next... */ continue; } @@ -1861,27 +1842,11 @@ errr init_player_info_txt(FILE *fp) /* Process 'O' for "Object birth" */ if (buf[4] == 'O') { - int s[5]; - - /* Scan for the values */ - if (5 != sscanf(buf + 6, "%d:%d:%d:%dd%d", - &s[0], &s[1], &s[4], &s[2], &s[3])) + if (read_proto_object(&s_ptr->obj[s_ptr->obj_num], &s_ptr->obj_num, buf + 6)) { - s[4] = 0; - - if (4 != sscanf(buf + 6, "%d:%d:%dd%d", - &s[0], &s[1], &s[2], &s[3])) - { - return (1); - } + return 1; } - s_ptr->obj_pval[s_ptr->obj_num] = s[4]; - s_ptr->obj_tval[s_ptr->obj_num] = s[0]; - s_ptr->obj_sval[s_ptr->obj_num] = s[1]; - s_ptr->obj_dd[s_ptr->obj_num] = s[2]; - s_ptr->obj_ds[s_ptr->obj_num++] = s[3]; - /* Next... */ continue; } -- cgit v1.2.3 From b7ca0a34a2a01ab496dbb829011d40b01106017d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Use std::vector<> for object_proto members --- src/init1.cc | 25 ++++++++++++------------- 1 file changed, 12 insertions(+), 13 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 5b1e5709..14175b2c 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -840,7 +840,7 @@ static int read_skill_modifiers(skill_modifiers *skill_modifiers, cptr buf) /* * Read prototype objects */ -static int read_proto_object(object_proto *proto, s16b *num, cptr buf) +static int read_proto_object(std::vector *protos, cptr buf) { int s0, s1, s2, s3, s4; @@ -854,13 +854,14 @@ static int read_proto_object(object_proto *proto, s16b *num, cptr buf) } } - proto->pval = s4; - proto->tval = s0; - proto->sval = s1; - proto->dd = s2; - proto->ds = s3; + object_proto proto; + proto.pval = s4; + proto.tval = s0; + proto.sval = s1; + proto.dd = s2; + proto.ds = s3; - (*num)++; + protos->emplace_back(proto); return 0; } @@ -1165,7 +1166,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'O' for "Object birth" */ if ((buf[0] == 'R') && (buf[2] == 'O')) { - if (read_proto_object(&rp_ptr->obj[rp_ptr->obj_num], &rp_ptr->obj_num, buf + 4)) + if (read_proto_object(&rp_ptr->object_protos, buf + 4)) { return 1; } @@ -1415,7 +1416,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'O' for "Object birth" */ if ((buf[0] == 'S') && (buf[2] == 'O')) { - if (read_proto_object(&rmp_ptr->obj[rmp_ptr->obj_num], &rmp_ptr->obj_num, buf + 4)) + if (read_proto_object(&rmp_ptr->object_protos, buf + 4)) { return 1; } @@ -1505,7 +1506,6 @@ errr init_player_info_txt(FILE *fp) for (z = 0; z < 10; z++) c_ptr->abilities[z].level = -1; cur_ab = 0; - c_ptr->obj_num = 0; tit_idx = 0; spec_idx = -1; for (z = 0; z < MAX_SPEC; z++) @@ -1557,7 +1557,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'O' for "Object birth" */ if ((buf[0] == 'C') && (buf[2] == 'O')) { - if (read_proto_object(&c_ptr->obj[c_ptr->obj_num], &c_ptr->obj_num, buf + 4)) + if (read_proto_object(&c_ptr->object_protos, buf + 4)) { return 1; } @@ -1811,7 +1811,6 @@ errr init_player_info_txt(FILE *fp) s_ptr->title = my_strdup(s); /* Initialize */ - s_ptr->obj_num = 0; cur_ab = 0; for (z = 0; z < 10; z++) s_ptr->abilities[z].level = -1; @@ -1842,7 +1841,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'O' for "Object birth" */ if (buf[4] == 'O') { - if (read_proto_object(&s_ptr->obj[s_ptr->obj_num], &s_ptr->obj_num, buf + 6)) + if (read_proto_object(&s_ptr->object_protos, buf + 6)) { return 1; } -- cgit v1.2.3 From f507d6fb86fe7cfaf4dec69afa36875a1a4aaae4 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Remove unused player_class::sense_* members --- src/init1.cc | 20 -------------------- 1 file changed, 20 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 14175b2c..de19105d 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1707,26 +1707,6 @@ errr init_player_info_txt(FILE *fp) continue; } - /* Process 'C' for "sensing" */ - if ((buf[0] == 'C') && (buf[2] == 'C')) - { - long int s[3]; - char h, m; - - /* Scan for the values */ - if (5 != sscanf(buf + 4, "%c:%c:%ld:%ld:%ld", - &h, &m, &s[0], &s[1], &s[2])) return (1); - - c_ptr->sense_heavy = (h == 'H') ? TRUE : FALSE; - c_ptr->sense_heavy_magic = (m == 'H') ? TRUE : FALSE; - c_ptr->sense_base = s[0]; - c_ptr->sense_pl = s[1]; - c_ptr->sense_plus = s[2]; - - /* Next... */ - continue; - } - /* Process 'B' for "blows" */ if ((buf[0] == 'C') && (buf[2] == 'B')) { -- cgit v1.2.3 From 0a16384475488d682e33c8d55691e5d9417412ac Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Unify opval/oflags in player_* structs into player_level_flag --- src/init1.cc | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index de19105d..412dde11 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1040,7 +1040,7 @@ errr init_player_info_txt(FILE *fp) &s[0], &s[1])) return (1); lev = s[0]; - rp_ptr->opval[lev] = s[1]; + rp_ptr->lflags[lev].pval = s[1]; /* Next... */ continue; @@ -1154,7 +1154,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'F' for "level Flags" (multiple lines) */ if ((buf[0] == 'R') && (buf[2] == 'F')) { - if (grab_object_flag(&rp_ptr->oflags[lev], buf + 4)) + if (grab_object_flag(&rp_ptr->lflags[lev].oflags, buf + 4)) { return (5); } @@ -1290,7 +1290,7 @@ errr init_player_info_txt(FILE *fp) &s[0], &s[1])) return (1); lev = s[0]; - rmp_ptr->opval[lev] = s[1]; + rmp_ptr->lflags[lev].pval = s[1]; /* Next... */ continue; @@ -1404,7 +1404,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'F' for "level Flags" (multiple lines) */ if ((buf[0] == 'S') && (buf[2] == 'F')) { - if (0 != grab_object_flag(&rmp_ptr->oflags[lev], buf + 4)) + if (0 != grab_object_flag(&rmp_ptr->lflags[lev].oflags, buf + 4)) { return (5); } @@ -1592,7 +1592,7 @@ errr init_player_info_txt(FILE *fp) &s[0], &s[1])) return (1); lev = s[0]; - c_ptr->opval[lev] = s[1]; + c_ptr->lflags[lev].pval = s[1]; /* Next... */ continue; @@ -1753,7 +1753,7 @@ errr init_player_info_txt(FILE *fp) } /* Parse this entry */ - if (0 != grab_object_flag(&c_ptr->oflags[lev], s)) + if (0 != grab_object_flag(&c_ptr->lflags[lev].oflags, s)) { return (5); } -- cgit v1.2.3 From 10c45c9975c076476cf1bcb6a1260c1ee055a6a1 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Change 'abilities' member of player_* to a std::vector<> --- src/init1.cc | 119 ++++++++++++++++++++++++----------------------------------- 1 file changed, 48 insertions(+), 71 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 412dde11..def2cdb1 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -867,17 +867,56 @@ static int read_proto_object(std::vector *protos, cptr buf) } +/* + * Read an ability assignment + */ +static int read_ability(std::vector *abilities, char *buf) +{ + int level = 0; + char *name = nullptr; + + // Find the ':' separator + if (!(name = strchr(buf, ':'))) + { + return 1; + } + + // Split the buffer there and advance to point at the ability name + name++; + + // Extract the level + if (1 != sscanf(buf, "%d:", &level)) + { + return 1; + } + + // Try to find the ability by name + int idx = find_ability(name); + if (idx < 0) + { + return 1; + } + + // Insert + player_race_ability_type ability; + ability.ability = idx; + ability.level = level; + abilities->emplace_back(ability); + + return 0; +} + + /* * Initialize the "player" arrays, by parsing an ascii "template" file */ errr init_player_info_txt(FILE *fp) { - int i = 0, z; + int i = 0; int powers = 0; int lev = 1; int tit_idx = 0; int spec_idx = 0; - int cur_ab = -1; char buf[1024]; char *s, *t; @@ -987,9 +1026,6 @@ errr init_player_info_txt(FILE *fp) rp_ptr->powers[0] = rp_ptr->powers[1] = rp_ptr->powers[2] = rp_ptr->powers[3] = -1; powers = 0; lev = 1; - cur_ab = 0; - for (z = 0; z < 10; z++) - rp_ptr->abilities[z].level = -1; /* Next... */ continue; @@ -1100,22 +1136,10 @@ errr init_player_info_txt(FILE *fp) /* Process 'b' for "abilities" */ if ((buf[0] == 'R') && (buf[2] == 'b')) { - char *sec; - - /* Scan for the values */ - if (NULL == (sec = strchr(buf + 4, ':'))) + if (read_ability(&rp_ptr->abilities, buf + 4)) { - return (1); + return 1; } - *sec = '\0'; - sec++; - if (!*sec) return (1); - - if ((i = find_ability(sec)) == -1) return (1); - - rp_ptr->abilities[cur_ab].ability = i; - rp_ptr->abilities[cur_ab].level = atoi(buf + 4); - cur_ab++; /* Next... */ continue; @@ -1225,9 +1249,6 @@ errr init_player_info_txt(FILE *fp) rmp_ptr->powers[0] = rmp_ptr->powers[1] = rmp_ptr->powers[2] = rmp_ptr->powers[3] = -1; powers = 0; lev = 1; - cur_ab = 0; - for (z = 0; z < 10; z++) - rmp_ptr->abilities[z].level = -1; /* Next... */ continue; @@ -1351,22 +1372,10 @@ errr init_player_info_txt(FILE *fp) /* Process 'b' for "abilities" */ if ((buf[0] == 'S') && (buf[2] == 'b')) { - char *sec; - - /* Scan for the values */ - if (NULL == (sec = strchr(buf + 4, ':'))) + if (read_ability(&rmp_ptr->abilities, buf + 4)) { return (1); } - *sec = '\0'; - sec++; - if (!*sec) return (1); - - if ((i = find_ability(sec)) == -1) return (1); - - rmp_ptr->abilities[cur_ab].ability = i; - rmp_ptr->abilities[cur_ab].level = atoi(buf + 4); - cur_ab++; /* Next... */ continue; @@ -1503,9 +1512,6 @@ errr init_player_info_txt(FILE *fp) c_ptr->powers[0] = c_ptr->powers[1] = c_ptr->powers[2] = c_ptr->powers[3] = -1; powers = 0; lev = 1; - for (z = 0; z < 10; z++) - c_ptr->abilities[z].level = -1; - cur_ab = 0; tit_idx = 0; spec_idx = -1; for (z = 0; z < MAX_SPEC; z++) @@ -1631,22 +1637,10 @@ errr init_player_info_txt(FILE *fp) /* Process 'b' for "abilities" */ if ((buf[0] == 'C') && (buf[2] == 'b')) { - char *sec; - - /* Scan for the values */ - if (NULL == (sec = strchr(buf + 4, ':'))) + if (read_ability(&c_ptr->abilities, buf + 4)) { - return (1); + return 1; } - *sec = '\0'; - sec++; - if (!*sec) return (1); - - if ((i = find_ability(sec)) == -1) return (1); - - c_ptr->abilities[cur_ab].ability = i; - c_ptr->abilities[cur_ab].level = atoi(buf + 4); - cur_ab++; /* Next... */ continue; @@ -1790,11 +1784,6 @@ errr init_player_info_txt(FILE *fp) assert(!s_ptr->title); s_ptr->title = my_strdup(s); - /* Initialize */ - cur_ab = 0; - for (z = 0; z < 10; z++) - s_ptr->abilities[z].level = -1; - /* Next... */ continue; } @@ -1862,22 +1851,10 @@ errr init_player_info_txt(FILE *fp) /* Process 'b' for "abilities" */ if (buf[4] == 'b') { - char *sec; - - /* Scan for the values */ - if (NULL == (sec = strchr(buf + 6, ':'))) + if (read_ability(&s_ptr->abilities, buf + 6)) { - return (1); + return 1; } - *sec = '\0'; - sec++; - if (!*sec) return (1); - - if ((i = find_ability(sec)) == -1) return (1); - - s_ptr->abilities[cur_ab].ability = i; - s_ptr->abilities[cur_ab].level = atoi(buf + 6); - cur_ab++; /* Next... */ continue; -- cgit v1.2.3 From 347afc50368137901a989ac4a4fc9298056c7377 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Unify store_info_type::item_* info std::vector --- src/init1.cc | 34 +++++++++++++--------------------- 1 file changed, 13 insertions(+), 21 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index def2cdb1..6fef9561 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5723,7 +5723,7 @@ static errr grab_one_store_flag(store_flag_set *flags, cptr what) */ errr init_st_info_txt(FILE *fp) { - int i = 0, item_idx = 0; + int i = 0; char buf[1024]; char *s; @@ -5783,9 +5783,6 @@ errr init_st_info_txt(FILE *fp) assert(!st_ptr->name); st_ptr->name = my_strdup(s); - /* We are ready for a new set of objects */ - item_idx = 0; - /* Next... */ continue; } @@ -5808,15 +5805,11 @@ errr init_st_info_txt(FILE *fp) /* Paranoia -- require a name */ if (!*s) return (1); - /* Get the index */ - st_ptr->item_chance[item_idx] = atoi(buf + 2); - - /* Append chars to the name */ - st_ptr->item_kind[item_idx] = test_item_name(s); - - item_idx++; - st_ptr->item_num = item_idx; - assert(st_ptr->item_num <= STORE_CHOICES); + /* Add to items array */ + store_item item; + item.chance = atoi(buf + 2); + item.kind = test_item_name(s); + st_ptr->items.emplace_back(item); /* Next... */ continue; @@ -5831,14 +5824,13 @@ errr init_st_info_txt(FILE *fp) if (3 != sscanf(buf + 2, "%d:%d:%d", &rar1, &tv1, &sv1)) return (1); - /* Get the index */ - st_ptr->item_chance[item_idx] = rar1; - /* Hack -- 256 as a sval means all possible items */ - st_ptr->item_kind[item_idx] = (sv1 < 256) ? lookup_kind(tv1, sv1) : tv1 + 10000; - - item_idx++; - st_ptr->item_num = item_idx; - assert(st_ptr->item_num <= STORE_CHOICES); + /* Add to the items array */ + store_item item; + item.chance = rar1; + item.kind = (sv1 < 256) + ? lookup_kind(tv1, sv1) + : tv1 + 10000; /* An SVAL of 256 means all possible items. */ + st_ptr->items.emplace_back(item); /* Next... */ continue; -- cgit v1.2.3 From cb9fde0cde82d4122c8bd9836309720294dee77f Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Rework store_info_type::owners to std::vector<> --- src/init1.cc | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 6fef9561..3dec9b6e 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5900,13 +5900,23 @@ errr init_st_info_txt(FILE *fp) /* Scan for the values */ if (4 != sscanf(buf + 2, "%d:%d:%d:%d", - &a1, &a2, &a3, &a4)) return (1); + &a1, &a2, &a3, &a4)) + { + return 1; + } + + /* Get a reference to the owners */ + auto owners = &st_ptr->owners; /* Save the values */ - st_ptr->owners[0] = a1; - st_ptr->owners[1] = a2; - st_ptr->owners[2] = a3; - st_ptr->owners[3] = a4; + owners->push_back(a1); + owners->push_back(a2); + owners->push_back(a3); + owners->push_back(a4); + + /* Sort and remove duplicates */ + std::sort(owners->begin(), owners->end()); + owners->erase(std::unique(owners->begin(), owners->end()), owners->end()); /* Next... */ continue; -- cgit v1.2.3 From 1f861bb683f70856787b100219fd40ff31be12b8 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Rework store_info_type::actions into a std::vector<> --- src/init1.cc | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 3dec9b6e..1d04509b 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5870,12 +5870,18 @@ errr init_st_info_txt(FILE *fp) &a1, &a2, &a3, &a4, &a5, &a6)) return (1); /* Save the values */ - st_ptr->actions[0] = a1; - st_ptr->actions[1] = a2; - st_ptr->actions[2] = a3; - st_ptr->actions[3] = a4; - st_ptr->actions[4] = a5; - st_ptr->actions[5] = a6; + st_ptr->actions.push_back(a1); + st_ptr->actions.push_back(a2); + st_ptr->actions.push_back(a3); + st_ptr->actions.push_back(a4); + st_ptr->actions.push_back(a5); + st_ptr->actions.push_back(a6); + + /* Remove zero entries since they have no effect */ + st_ptr->actions.erase( + std::remove(st_ptr->actions.begin(), st_ptr->actions.end(), 0), + st_ptr->actions.end() + ); /* Next... */ continue; -- cgit v1.2.3 From 50c916646b647030755673a9a1dc82e192e492d4 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:13 +0200 Subject: Change player_class::spec to a std::vector<> --- src/init1.cc | 19 ++++--------------- 1 file changed, 4 insertions(+), 15 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 1d04509b..0654155e 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -916,7 +916,6 @@ errr init_player_info_txt(FILE *fp) int powers = 0; int lev = 1; int tit_idx = 0; - int spec_idx = 0; char buf[1024]; char *s, *t; @@ -1475,8 +1474,6 @@ errr init_player_info_txt(FILE *fp) /* Process 'N' for "New/Number/Name" */ if ((buf[0] == 'C') && (buf[2] == 'N')) { - int z; - /* Find the colon before the name */ s = strchr(buf + 4, ':'); @@ -1513,9 +1510,6 @@ errr init_player_info_txt(FILE *fp) powers = 0; lev = 1; tit_idx = 0; - spec_idx = -1; - for (z = 0; z < MAX_SPEC; z++) - c_ptr->spec[z].title = 0; /* Next... */ continue; @@ -1771,17 +1765,12 @@ errr init_player_info_txt(FILE *fp) /* Paranoia -- require a name */ if (!*s) return (1); - /* Get the index */ - spec_idx++; - - /* Verify information */ - if (spec_idx >= MAX_SPEC) return (2); - /* Point at the "info" */ - s_ptr = &c_ptr->spec[spec_idx]; + /* Create the spec entry */ + c_ptr->spec.emplace_back(player_spec()); - /* Copy title */ - assert(!s_ptr->title); + /* Fill in initial values */ + s_ptr = &c_ptr->spec.back(); s_ptr->title = my_strdup(s); /* Next... */ -- cgit v1.2.3 From 76b3632d13bbf57c6354bc10f67ea849f1d47279 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Rework player_race_mod::{title,desc} to std::string --- src/init1.cc | 15 +++++---------- 1 file changed, 5 insertions(+), 10 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 0654155e..de92ae90 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1241,8 +1241,7 @@ errr init_player_info_txt(FILE *fp) rmp_ptr = &race_mod_info[i]; /* Copy title */ - assert(!rmp_ptr->title); - rmp_ptr->title = my_strdup(s); + rmp_ptr->title = s; /* Initialize */ rmp_ptr->powers[0] = rmp_ptr->powers[1] = rmp_ptr->powers[2] = rmp_ptr->powers[3] = -1; @@ -1270,15 +1269,11 @@ errr init_player_info_txt(FILE *fp) } /* Description */ - if (!rmp_ptr->desc) + if (!rmp_ptr->description.empty()) { - rmp_ptr->desc = my_strdup(s); - } - else - { - /* Append chars to the name */ - strappend(&rmp_ptr->desc, format("\n%s", s)); + rmp_ptr->description += '\n'; } + rmp_ptr->description += s; /* Next... */ continue; @@ -7331,7 +7326,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp) /* Race Mod */ else if (streq(b + 1, "RACEMOD")) { - v = rmp_ptr->title; + v = rmp_ptr->title.c_str(); // The string SHOULD be stable enough for this } /* Class */ -- cgit v1.2.3 From cc857c940cfe1bfe8d78674dbce53e5b71acaf41 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Move ability_type::acquired to p_ptr struct This is justified by the fact that the 'acquired' flag is actually a player-centered bit of information and must be loaded/saved. Everything else in ability_type is defined by the *.txt files. --- src/init1.cc | 1 - 1 file changed, 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index de92ae90..3f803fbe 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3419,7 +3419,6 @@ errr init_ab_info_txt(FILE *fp) /* Init */ ab_ptr->action_mkey = 0; - ab_ptr->acquired = FALSE; for (z = 0; z < 10; z++) { ab_ptr->skills[z] = -1; -- cgit v1.2.3 From daf23851092099647a3830aa1c0cf12962f55b8e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Move 'player_*' shared fields to new 'player_shared' struct --- src/init1.cc | 33 ++++++++++++++++++--------------- 1 file changed, 18 insertions(+), 15 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 3f803fbe..028e6b14 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -1022,7 +1022,6 @@ errr init_player_info_txt(FILE *fp) rp_ptr->title = my_strdup(s); /* Initialize */ - rp_ptr->powers[0] = rp_ptr->powers[1] = rp_ptr->powers[2] = rp_ptr->powers[3] = -1; powers = 0; lev = 1; @@ -1092,7 +1091,9 @@ errr init_player_info_txt(FILE *fp) rp_ptr->luck = s[6]; for (z = 0; z < 6; z++) - rp_ptr->r_adj[z] = s[z]; + { + rp_ptr->ps.adj[z] = s[z]; + } /* Next... */ continue; @@ -1114,7 +1115,7 @@ errr init_player_info_txt(FILE *fp) if (i == POWER_MAX) return (6); - rp_ptr->powers[powers++] = i; + rp_ptr->ps.powers.push_back(i); /* Next... */ continue; @@ -1153,8 +1154,8 @@ errr init_player_info_txt(FILE *fp) if (4 != sscanf(buf + 4, "%d:%d:%d:%d", &s[0], &s[1], &s[2], &s[3])) return (1); - rp_ptr->r_mhp = s[0]; - rp_ptr->r_exp = s[1]; + rp_ptr->ps.mhp = s[0]; + rp_ptr->ps.exp = s[1]; rp_ptr->infra = s[2]; rp_ptr->chart = s[3]; @@ -1244,7 +1245,6 @@ errr init_player_info_txt(FILE *fp) rmp_ptr->title = s; /* Initialize */ - rmp_ptr->powers[0] = rmp_ptr->powers[1] = rmp_ptr->powers[2] = rmp_ptr->powers[3] = -1; powers = 0; lev = 1; @@ -1323,7 +1323,9 @@ errr init_player_info_txt(FILE *fp) rmp_ptr->mana = s[7]; rmp_ptr->luck = s[6]; for (z = 0; z < 6; z++) - rmp_ptr->r_adj[z] = s[z]; + { + rmp_ptr->ps.adj[z] = s[z]; + } /* Next... */ continue; @@ -1345,7 +1347,7 @@ errr init_player_info_txt(FILE *fp) if (i == POWER_MAX) return (6); - rmp_ptr->powers[powers++] = i; + rmp_ptr->ps.powers.push_back(i); /* Next... */ continue; @@ -1384,8 +1386,8 @@ errr init_player_info_txt(FILE *fp) if (3 != sscanf(buf + 4, "%d:%d:%d", &s[0], &s[1], &s[2])) return (1); - rmp_ptr->r_mhp = s[0]; - rmp_ptr->r_exp = s[1]; + rmp_ptr->ps.mhp = s[0]; + rmp_ptr->ps.exp = s[1]; rmp_ptr->infra = s[2]; /* Next... */ @@ -1501,7 +1503,6 @@ errr init_player_info_txt(FILE *fp) c_ptr->title = my_strdup(s); /* Initialize */ - c_ptr->powers[0] = c_ptr->powers[1] = c_ptr->powers[2] = c_ptr->powers[3] = -1; powers = 0; lev = 1; tit_idx = 0; @@ -1605,7 +1606,9 @@ errr init_player_info_txt(FILE *fp) c_ptr->mana = s[6]; c_ptr->extra_blows = s[7]; for (z = 0; z < 6; z++) - c_ptr->c_adj[z] = s[z]; + { + c_ptr->ps.adj[z] = s[z]; + } /* Next... */ continue; @@ -1668,7 +1671,7 @@ errr init_player_info_txt(FILE *fp) if (i == POWER_MAX) return (6); - c_ptr->powers[powers++] = i; + c_ptr->ps.powers.push_back(i); /* Next... */ continue; @@ -1683,8 +1686,8 @@ errr init_player_info_txt(FILE *fp) if (2 != sscanf(buf + 4, "%d:%d", &s[0], &s[1])) return (1); - c_ptr->c_mhp = s[0]; - c_ptr->c_exp = s[1]; + c_ptr->ps.mhp = s[0]; + c_ptr->ps.exp = s[1]; /* Next... */ continue; -- cgit v1.2.3 From 1e045ed09258e6c7fff63ef829759c6c8f06f441 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Separate skill values from skill descriptions --- src/init1.cc | 27 +++++++++------------------ 1 file changed, 9 insertions(+), 18 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 028e6b14..5395ed70 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3085,12 +3085,12 @@ errr init_set_info_txt(FILE *fp) */ errr init_s_info_txt(FILE *fp) { - int i, z, order = 1; + int i, order = 1; char buf[1024]; char *s; /* Current entry */ - skill_type *s_ptr = NULL; + skill_descriptor *s_ptr = NULL; /* Just before the first record */ @@ -3131,8 +3131,8 @@ errr init_s_info_txt(FILE *fp) s2 = find_skill(sec); if (s2 == -1) return (1); - s_info[s2].father = s1; - s_info[s2].order = order++; + s_descriptors[s2].father = s1; + s_descriptors[s2].order = order++; /* Next... */ continue; @@ -3157,8 +3157,8 @@ errr init_s_info_txt(FILE *fp) s2 = find_skill(sec); if ((s1 == -1) || (s2 == -1)) return (1); - s_info[s1].action[s2] = SKILL_EXCLUSIVE; - s_info[s2].action[s1] = SKILL_EXCLUSIVE; + s_descriptors[s1].action[s2] = SKILL_EXCLUSIVE; + s_descriptors[s2].action[s1] = SKILL_EXCLUSIVE; /* Next... */ continue; @@ -3191,7 +3191,7 @@ errr init_s_info_txt(FILE *fp) s2 = find_skill(sec); if ((s1 == -1) || (s2 == -1)) return (1); - s_info[s1].action[s2] = -atoi(cval); + s_descriptors[s1].action[s2] = -atoi(cval); /* Next... */ continue; @@ -3223,7 +3223,7 @@ errr init_s_info_txt(FILE *fp) s2 = find_skill(sec); if ((s1 == -1) || (s2 == -1)) return (1); - s_info[s1].action[s2] = atoi(cval); + s_descriptors[s1].action[s2] = atoi(cval); /* Next... */ continue; @@ -3254,21 +3254,12 @@ errr init_s_info_txt(FILE *fp) error_idx = i; /* Point at the "info" */ - s_ptr = &s_info[i]; + s_ptr = &s_descriptors[i]; /* Copy name */ assert(!s_ptr->name); s_ptr->name = my_strdup(s); - /* Init */ - s_ptr->action_mkey = 0; - s_ptr->dev = FALSE; - s_ptr->random_gain_chance = 100; - for (z = 0; z < max_s_idx; z++) - { - s_ptr->action[z] = 0; - } - /* Next... */ continue; } -- cgit v1.2.3 From 4fb8fb773d93efe1cdc812d1046c530c20098455 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:14 +0200 Subject: Remove dead code Fixes a few compiler warnings. --- src/init1.cc | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 5395ed70..9fac93c9 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -913,7 +913,6 @@ static int read_ability(std::vector *abilities, char * errr init_player_info_txt(FILE *fp) { int i = 0; - int powers = 0; int lev = 1; int tit_idx = 0; char buf[1024]; @@ -1022,7 +1021,6 @@ errr init_player_info_txt(FILE *fp) rp_ptr->title = my_strdup(s); /* Initialize */ - powers = 0; lev = 1; /* Next... */ @@ -1245,7 +1243,6 @@ errr init_player_info_txt(FILE *fp) rmp_ptr->title = s; /* Initialize */ - powers = 0; lev = 1; /* Next... */ @@ -1503,7 +1500,6 @@ errr init_player_info_txt(FILE *fp) c_ptr->title = my_strdup(s); /* Initialize */ - powers = 0; lev = 1; tit_idx = 0; @@ -1911,7 +1907,6 @@ errr init_player_info_txt(FILE *fp) /* Append chars to the name */ strcpy(mc_ptr->name, s + 2); mc_ptr->color = color_char_to_attr(s[0]); - powers = 0; /* Next... */ continue; -- cgit v1.2.3 From be49084ba59b89c14f8b9f9e1274b013428d7205 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:15 +0200 Subject: Clean up process_dungeon_file_aux() a little bit --- src/init1.cc | 23 +++++++++++++---------- 1 file changed, 13 insertions(+), 10 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 9fac93c9..c0835da0 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6837,29 +6837,32 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst /* Layout of the wilderness */ if (buf[2] == 'D') { - int x; - char i; - /* Acquire the text */ char *s = buf + 4; int y = *yval; - for (x = 0; x < max_wild_x; x++) + for (int x = 0; x < max_wild_x; x++) { - if (1 != sscanf(s + x, "%c", &i)) return (1); - wild_map[y][x].feat = wildc2i[(int)i]; + char i; + if (1 != sscanf(s + x, "%c", &i)) + { + return (1); + } + + auto const wi = wildc2i[(int)i]; + + wild_map[y][x].feat = wi; /* * If this is a town/dungeon entrance, note * its coordinates. (Have to check for * duplicate Morias...) */ - if (wf_info[wildc2i[(int)i]].entrance && - wf_info[wildc2i[(int)i]].wild_x == 0) + if (wf_info[wi].entrance && wf_info[wi].wild_x == 0) { - wf_info[wildc2i[(int)i]].wild_x = x; - wf_info[wildc2i[(int)i]].wild_y = y; + wf_info[wi].wild_x = x; + wf_info[wi].wild_y = y; } } -- cgit v1.2.3 From dc261d2c9732554d9f510e11711ac84d028e5ac1 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:15 +0200 Subject: Use grid<> for wilderness grid --- src/init1.cc | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index c0835da0..3fb33179 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6363,6 +6363,8 @@ static dungeon_grid letter[255]; */ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalstart, int ymax, int xmax, bool_ full) { + auto &wilderness = *wilderness_ptr; + int i; char *zz[33]; @@ -6842,7 +6844,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst int y = *yval; - for (int x = 0; x < max_wild_x; x++) + for (std::size_t x = 0; x < wilderness.width(); x++) { char i; if (1 != sscanf(s + x, "%c", &i)) @@ -6852,7 +6854,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst auto const wi = wildc2i[(int)i]; - wild_map[y][x].feat = wi; + wilderness(x, y).feat = wi; /* * If this is a town/dungeon entrance, note @@ -6914,7 +6916,9 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst { if (tokenize(buf + 4, 3, zz, ':', '/') == 3) { - wild_map[atoi(zz[1])][atoi(zz[2])].entrance = 1000 + atoi(zz[0]); + int y = atoi(zz[1]); + int x = atoi(zz[2]); + wilderness(x, y).entrance = 1000 + atoi(zz[0]); } else { @@ -7104,13 +7108,13 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst /* Maximum wilderness x size */ else if (zz[0][0] == 'X') { - max_wild_x = atoi(zz[1]); + wilderness.width(atoi(zz[1])); } /* Maximum wilderness y size */ else if (zz[0][0] == 'Y') { - max_wild_y = atoi(zz[1]); + wilderness.height(atoi(zz[1])); } /* Maximum d_idx */ -- cgit v1.2.3 From 05cdb1a997cba7748f0089cffa0a5885ca0b2c43 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 17 Sep 2016 09:58:15 +0200 Subject: Move wilderness structure into Game --- src/init1.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 3fb33179..fa99031f 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -11,6 +11,7 @@ #include "feature_flag.hpp" #include "feature_type.hpp" #include "files.hpp" +#include "game.hpp" #include "gods.hpp" #include "hist_type.hpp" #include "init2.hpp" @@ -6363,7 +6364,7 @@ static dungeon_grid letter[255]; */ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalstart, int ymax, int xmax, bool_ full) { - auto &wilderness = *wilderness_ptr; + auto &wilderness = game->wilderness; int i; -- cgit v1.2.3 From d8de8c129fb9fc8d2110f39108949d7025456151 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Remove dead code --- src/init1.cc | 2 -- 1 file changed, 2 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index fa99031f..012537ce 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -43,7 +43,6 @@ #include "store_action_type.hpp" #include "store_flag.hpp" #include "store_info_type.hpp" -#include "store_type.hpp" #include "tables.hpp" #include "town_type.hpp" #include "trap_type.hpp" @@ -53,7 +52,6 @@ #include "variable.h" #include "variable.hpp" #include "vault_type.hpp" -#include "wilderness_map.hpp" #include "wilderness_type_info.hpp" #include "z-rand.hpp" -- cgit v1.2.3 From 1173c144b06d5d2d3c9e6351af5e6f06cb843d4b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move v_info into GameEditData --- src/init1.cc | 42 +++++++++++++++++++++--------------------- 1 file changed, 21 insertions(+), 21 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 012537ce..08cc80a0 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -51,7 +51,6 @@ #include "util.h" #include "variable.h" #include "variable.hpp" -#include "vault_type.hpp" #include "wilderness_type_info.hpp" #include "z-rand.hpp" @@ -61,6 +60,20 @@ using boost::algorithm::iequals; using boost::algorithm::ends_with; +/** + * Expand vector such that it has room for an item at index i. + * If the vector is already large enough, nothing happens. + */ +template typename std::vector::reference expand_to_fit_index(std::vector &v, std::size_t i) +{ + if (v.size() < i + 1) + { + v.resize(i + 1); + } + return v[i]; +} + + /* * This file is used to initialize various variables and arrays for the * Angband game. Note the use of "fd_read()" and "fd_write()" to bypass @@ -1950,12 +1963,12 @@ errr init_player_info_txt(FILE *fp) */ errr init_v_info_txt(FILE *fp) { - int i; char buf[1024]; - char *s; + + auto &v_info = game->edit_data.v_info; /* Current entry */ - vault_type *v_ptr = NULL; + vault_type *v_ptr = nullptr; /* Just before the first record */ error_idx = -1; @@ -1980,7 +1993,7 @@ errr init_v_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -1992,23 +2005,16 @@ errr init_v_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i <= error_idx) return (4); - /* Verify information */ - if (i >= max_v_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - v_ptr = &v_info[i]; - - /* Initialize data -- we ignore the name, it's not - * used for anything */ - v_ptr->data = my_strdup(""); + v_ptr = &expand_to_fit_index(v_info, i); /* Next... */ continue; @@ -2021,7 +2027,7 @@ errr init_v_info_txt(FILE *fp) if (buf[0] == 'D') { /* Acquire the text */ - s = buf + 2; + cptr s = buf + 2; /* Append data */ v_ptr->data += s; @@ -7001,12 +7007,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_k_idx = atoi(zz[1]); } - /* Maximum v_idx */ - else if (zz[0][0] == 'V') - { - max_v_idx = atoi(zz[1]); - } - /* Maximum f_idx */ else if (zz[0][0] == 'F') { -- cgit v1.2.3 From fd6449ac75f553e32d2efa84c3cdfba88bb32d6e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move ra_gen and ra_info into GameEditData --- src/init1.cc | 71 +++++++++++++++++++++++++----------------------------------- 1 file changed, 29 insertions(+), 42 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 08cc80a0..4f563005 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -55,6 +55,7 @@ #include "z-rand.hpp" #include +#include using boost::algorithm::iequals; using boost::algorithm::ends_with; @@ -4013,9 +4014,10 @@ errr init_e_info_txt(FILE *fp) */ errr init_ra_info_txt(FILE *fp) { - int i, cur_t = 0, j, cur_g = 0; + auto &ra_gen = game->edit_data.ra_gen; + auto &ra_info = game->edit_data.ra_info; + char buf[1024]; - char *s; /* Current entry */ randart_part_type *ra_ptr = NULL; @@ -4050,11 +4052,14 @@ errr init_ra_info_txt(FILE *fp) &chance, &dd, &ds, &plus)) return (1); /* Save the values */ - ra_gen[cur_g].chance = chance; - ra_gen[cur_g].dd = dd; - ra_gen[cur_g].ds = ds; - ra_gen[cur_g].plus = plus; - cur_g++; + randart_gen_type gen; + gen.chance = chance; + gen.dd = dd; + gen.ds = ds; + gen.plus = plus; + + /* Add to data */ + ra_gen.emplace_back(gen); /* Next... */ continue; @@ -4064,30 +4069,16 @@ errr init_ra_info_txt(FILE *fp) if (buf[0] == 'N') { /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_ra_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - ra_ptr = &ra_info[i]; - - /* Needed hack */ - ra_ptr->power = -1; - cur_t = 0; - - for (j = 0; j < 20; j++) - { - ra_ptr->tval[j] = 255; - } - ra_ptr->flags = object_flag_set(); - ra_ptr->fego = ego_flag_set(); + ra_ptr = &expand_to_fit_index(ra_info, i); /* Next... */ continue; @@ -4099,20 +4090,19 @@ errr init_ra_info_txt(FILE *fp) /* Process 'T' for "Tval/Sval" (up to 5 lines) */ if (buf[0] == 'T') { - int tv, minsv, maxsv; - - if (cur_t == 20) return 1; - /* Scan for the values */ + int tv, minsv, maxsv; if (3 != sscanf(buf + 2, "%d:%d:%d", &tv, &minsv, &maxsv)) return (1); - /* Save the values */ - ra_ptr->tval[cur_t] = tv; - ra_ptr->min_sval[cur_t] = minsv; - ra_ptr->max_sval[cur_t] = maxsv; + /* Set up filter */ + randart_part_type::kind_filter_t filter; + filter.tval = tv; + filter.min_sval = minsv; + filter.max_sval = maxsv; - cur_t++; + /* Add filter */ + ra_ptr->kind_filter.emplace_back(filter); /* Next... */ continue; @@ -4174,18 +4164,21 @@ errr init_ra_info_txt(FILE *fp) /* Process 'Z' for "Granted power" */ if (buf[0] == 'Z') { - int i; - /* Acquire the text */ - s = buf + 2; + char const *s = buf + 2; /* Find it in the list */ + std::size_t i; for (i = 0; i < POWER_MAX; i++) { if (iequals(s, powers_type[i].name)) break; } - if (i == POWER_MAX) return (6); + /* Not present? Fail */ + if (i == POWER_MAX) + { + return (6); + } ra_ptr->power = i; @@ -7025,12 +7018,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_e_idx = atoi(zz[1]); } - /* Maximum ra_idx */ - else if (zz[0][0] == 'Z') - { - max_ra_idx = atoi(zz[1]); - } - /* Maximum o_idx */ else if (zz[0][0] == 'O') { -- cgit v1.2.3 From b329b2fd77e32112a08fc41e1be58b32648225cf Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move ow_info and ba_info into GameEditData --- src/init1.cc | 44 ++++++++++++-------------------------------- 1 file changed, 12 insertions(+), 32 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 4f563005..086314a2 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5928,9 +5928,9 @@ errr init_st_info_txt(FILE *fp) */ errr init_ba_info_txt(FILE *fp) { - int i = 0; + auto &ba_info = game->edit_data.ba_info; + char buf[1024]; - char *s; /* Current entry */ store_action_type *ba_ptr = NULL; @@ -5958,7 +5958,7 @@ errr init_ba_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -5970,23 +5970,19 @@ errr init_ba_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_ba_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - ba_ptr = &ba_info[i]; + ba_ptr = &expand_to_fit_index(ba_info, i); /* Copy name */ - assert(!ba_ptr->name); - ba_ptr->name = my_strdup(s); + ba_ptr->name = s; /* Next... */ continue; @@ -6047,9 +6043,9 @@ errr init_ba_info_txt(FILE *fp) */ errr init_ow_info_txt(FILE *fp) { - int i; + auto &ow_info = game->edit_data.ow_info; + char buf[1024]; - char *s; /* Current entry */ owner_type *ow_ptr = NULL; @@ -6076,7 +6072,7 @@ errr init_ow_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -6088,23 +6084,19 @@ errr init_ow_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_ow_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - ow_ptr = &ow_info[i]; + ow_ptr = &expand_to_fit_index(ow_info, i); /* Copy name */ - assert(!ow_ptr->name); - ow_ptr->name = my_strdup(s); + ow_ptr->name = s; /* Next... */ continue; @@ -7067,12 +7059,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_wf_idx = atoi(zz[1]); } - /* Maximum ba_idx */ - else if (zz[0][0] == 'B') - { - max_ba_idx = atoi(zz[1]); - } - /* Maximum st_idx */ else if (zz[0][0] == 'S') { @@ -7085,12 +7071,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_set_idx = atoi(zz[1]); } - /* Maximum ow_idx */ - else if (zz[0][0] == 'N') - { - max_ow_idx = atoi(zz[1]); - } - /* Maximum wilderness x size */ else if (zz[0][0] == 'X') { -- cgit v1.2.3 From 460513b54733dbc3b10274622d960b3c47f60e85 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Remove meta_class_info We replace it with a single number on the C:N: line which determines the display order of the classes. (That's all that meta_class_info effectively did.) --- src/init1.cc | 140 ++++++++++++++++------------------------------------------- 1 file changed, 37 insertions(+), 103 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 086314a2..5867ef5a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -15,7 +15,6 @@ #include "gods.hpp" #include "hist_type.hpp" #include "init2.hpp" -#include "meta_class_type.hpp" #include "monster2.hpp" #include "monster_ego.hpp" #include "monster_race.hpp" @@ -55,6 +54,8 @@ #include "z-rand.hpp" #include +#include +#include #include using boost::algorithm::iequals; @@ -925,18 +926,15 @@ static int read_ability(std::vector *abilities, char * */ errr init_player_info_txt(FILE *fp) { - int i = 0; int lev = 1; int tit_idx = 0; char buf[1024]; - char *s, *t; /* Current entry */ player_race *rp_ptr = NULL; player_race_mod *rmp_ptr = NULL; player_class *c_ptr = NULL; player_spec *s_ptr = NULL; - meta_class_type *mc_ptr = NULL; /* Just before the first record */ @@ -1003,7 +1001,7 @@ errr init_player_info_txt(FILE *fp) if ((buf[0] == 'R') && (buf[2] == 'N')) { /* Find the colon before the name */ - s = strchr(buf + 4, ':'); + char *s = strchr(buf + 4, ':'); /* Verify that colon */ if (!s) return (1); @@ -1015,7 +1013,7 @@ errr init_player_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 4); + int i = atoi(buf + 4); /* Verify information */ if (i < error_idx) return (4); @@ -1044,7 +1042,7 @@ errr init_player_info_txt(FILE *fp) if ((buf[0] == 'R') && (buf[2] == 'D')) { /* Acquire the text */ - s = buf + 4; + char const *s = buf + 4; if (!rp_ptr->desc) { @@ -1113,12 +1111,11 @@ errr init_player_info_txt(FILE *fp) /* Process 'Z' for "powers" */ if ((buf[0] == 'R') && (buf[2] == 'Z')) { - int i; - /* Acquire the text */ - s = buf + 4; + char const *s = buf + 4; /* Find it in the list */ + int i; for (i = 0; i < POWER_MAX; i++) { if (iequals(s, powers_type[i].name)) break; @@ -1226,7 +1223,7 @@ errr init_player_info_txt(FILE *fp) if ((buf[0] == 'S') && (buf[2] == 'N')) { /* Find the colon before the name */ - s = strchr(buf + 4, ':'); + char *s = strchr(buf + 4, ':'); /* Verify that colon */ if (!s) return (1); @@ -1238,7 +1235,7 @@ errr init_player_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 4); + int i = atoi(buf + 4); /* Verify information */ if (i < error_idx) return (4); @@ -1266,7 +1263,7 @@ errr init_player_info_txt(FILE *fp) if ((buf[0] == 'S') && (buf[2] == 'D')) { /* Acquire the text */ - s = buf + 6; + char const *s = buf + 6; /* Place */ if (buf[4] == 'A') @@ -1344,12 +1341,11 @@ errr init_player_info_txt(FILE *fp) /* Process 'Z' for "powers" */ if ((buf[0] == 'S') && (buf[2] == 'Z')) { - int i; - /* Acquire the text */ - s = buf + 4; + char const *s = buf + 4; /* Find it in the list */ + int i; for (i = 0; i < POWER_MAX; i++) { if (iequals(s, powers_type[i].name)) break; @@ -1481,25 +1477,26 @@ errr init_player_info_txt(FILE *fp) /* Process 'N' for "New/Number/Name" */ if ((buf[0] == 'C') && (buf[2] == 'N')) { - /* Find the colon before the name */ - s = strchr(buf + 4, ':'); + /* Advance beyond prefix */ + char *s = strchr(buf + 4, ':'); /* Verify that colon */ if (!s) return (1); - /* Nuke the colon, advance to the name */ - *s++ = '\0'; + /* Extract the suffix */ + std::string suffix(s + 1); + if (suffix.empty()) return (1); - /* Paranoia -- require a name */ - if (!*s) return (1); + /* Split suffix into fields */ + std::vector fields; + boost::algorithm::split(fields, suffix, boost::is_any_of(":")); - /* Get the index */ - i = atoi(buf + 4); + /* Make sure we have two fields */ + if (fields.size() < 2) return (1); - /* Verify information */ + /* Get the entry index */ + int i = atoi(buf + 4); if (i < error_idx) return (4); - - /* Verify information */ if (i >= max_c_idx) return (2); /* Save the index */ @@ -1510,7 +1507,8 @@ errr init_player_info_txt(FILE *fp) /* Copy name */ assert(!c_ptr->title); - c_ptr->title = my_strdup(s); + c_ptr->display_order_idx = std::stoi(fields[0]); + c_ptr->title = my_strdup(fields[1].c_str()); /* Initialize */ lev = 1; @@ -1524,7 +1522,7 @@ errr init_player_info_txt(FILE *fp) if ((buf[0] == 'C') && (buf[2] == 'D')) { /* Acquire the text */ - s = buf + 6; + char const *s = buf + 6; switch (buf[4]) { @@ -1667,12 +1665,11 @@ errr init_player_info_txt(FILE *fp) /* Process 'Z' for "powers" */ if ((buf[0] == 'C') && (buf[2] == 'Z')) { - int i; - /* Acquire the text */ - s = buf + 4; + char const *s = buf + 4; /* Find it in the list */ + int i; for (i = 0; i < POWER_MAX; i++) { if (iequals(s, powers_type[i].name)) break; @@ -1735,8 +1732,10 @@ errr init_player_info_txt(FILE *fp) if ((buf[0] == 'C') && (buf[2] == 'F')) { /* Parse every entry */ - for (s = buf + 4; *s; ) + for (char *s = buf + 4; *s; ) { + char *t; + /* Find the end of this entry */ for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; @@ -1768,7 +1767,7 @@ errr init_player_info_txt(FILE *fp) if (buf[4] == 'N') { /* Find the colon before the name */ - s = buf + 6; + char const *s = buf + 6; /* Paranoia -- require a name */ if (!*s) return (1); @@ -1788,7 +1787,7 @@ errr init_player_info_txt(FILE *fp) if (buf[4] == 'D') { /* Acquire the text */ - s = buf + 6; + char const *s = buf + 6; if (!s_ptr->desc) { @@ -1860,8 +1859,10 @@ errr init_player_info_txt(FILE *fp) if (buf[4] == 'G') { /* Parse every entry */ - for (s = buf + 6; *s; ) + for (char *s = buf + 6; *s; ) { + char *t; + /* Find the end of this entry */ for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; @@ -1887,69 +1888,6 @@ errr init_player_info_txt(FILE *fp) } } - /* Process 'N' for "New/Number/Name" */ - if ((buf[0] == 'M') && (buf[2] == 'N')) - { - /* Find the colon before the name */ - s = strchr(buf + 4, ':'); - - /* Verify that colon */ - if (!s) return (1); - - /* Nuke the colon, advance to the name */ - *s++ = '\0'; - - /* Paranoia -- require a name */ - if (!*s) return (1); - - /* Get the index */ - i = atoi(buf + 4); - - /* Verify information */ - if (i < error_idx) return (4); - - /* Verify information */ - if (i >= max_mc_idx) return (2); - - /* Save the index */ - error_idx = i; - - /* Point at the "info" */ - mc_ptr = &meta_class_info[i]; - - /* Append chars to the name */ - strcpy(mc_ptr->name, s + 2); - mc_ptr->color = color_char_to_attr(s[0]); - - /* Next... */ - continue; - } - - /* Process 'C' for "Classes" */ - if ((buf[0] == 'M') && (buf[2] == 'C')) - { - int i; - - /* Acquire the text */ - s = buf + 4; - - /* Find it in the list */ - for (i = 0; i < max_c_idx; i++) - { - if (class_info[i].title && iequals(s, class_info[i].title)) - { - break; - } - } - - if (i == max_c_idx) return (6); - - mc_ptr->classes.push_back(i); - - /* Next... */ - continue; - } - /* Oops */ return (6); } @@ -7031,10 +6969,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst { max_c_idx = atoi(zz[2]); } - else if (zz[1][0] == 'M') - { - max_mc_idx = atoi(zz[2]); - } else if (zz[1][0] == 'H') { max_bg_idx = atoi(zz[2]); -- cgit v1.2.3 From 80f38daed5c89df95dcf3aee3e9d3a4ecafe5d03 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Remove unused includes --- src/init1.cc | 5 ----- 1 file changed, 5 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 5867ef5a..ac1d6bc7 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -26,20 +26,16 @@ #include "object_flag.hpp" #include "object_flag_meta.hpp" #include "object_kind.hpp" -#include "owner_type.hpp" #include "player_class.hpp" #include "player_race.hpp" #include "player_race_flag.hpp" #include "player_race_mod.hpp" #include "player_type.hpp" -#include "randart_gen_type.hpp" -#include "randart_part_type.hpp" #include "set_type.hpp" #include "skill_flag.hpp" #include "skill_type.hpp" #include "skills.hpp" #include "spells5.hpp" -#include "store_action_type.hpp" #include "store_flag.hpp" #include "store_info_type.hpp" #include "tables.hpp" @@ -56,7 +52,6 @@ #include #include #include -#include using boost::algorithm::iequals; using boost::algorithm::ends_with; -- cgit v1.2.3 From 3cdeb22086fc177165acb2d7b6530ccc230ec8e6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move class_info to GameEditData --- src/init1.cc | 36 +++++++++++++++--------------------- 1 file changed, 15 insertions(+), 21 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index ac1d6bc7..b4c0a5ac 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -682,13 +682,12 @@ static void strappend(char **s, const char *t) static bool_ unknown_shut_up = FALSE; static errr grab_one_class_flag(u32b *choice, cptr what) { - int i; - cptr s; + auto const &class_info = game->edit_data.class_info; /* Scan classes flags */ - for (i = 0; i < max_c_idx && (s = class_info[i].title); i++) + for (std::size_t i = 0; i < class_info.size(); i++) { - if (streq(what, s)) + if (class_info[i].title == what) { (choice[i / 32]) |= (1L << i); return (0); @@ -921,6 +920,8 @@ static int read_ability(std::vector *abilities, char * */ errr init_player_info_txt(FILE *fp) { + auto &class_info = game->edit_data.class_info; + int lev = 1; int tit_idx = 0; char buf[1024]; @@ -1492,18 +1493,17 @@ errr init_player_info_txt(FILE *fp) /* Get the entry index */ int i = atoi(buf + 4); if (i < error_idx) return (4); - if (i >= max_c_idx) return (2); /* Save the index */ error_idx = i; /* Point at the "info" */ - c_ptr = &class_info[i]; + c_ptr = &expand_to_fit_index(class_info, i); + assert(c_ptr->title.empty()); - /* Copy name */ - assert(!c_ptr->title); + /* Initialize */ c_ptr->display_order_idx = std::stoi(fields[0]); - c_ptr->title = my_strdup(fields[1].c_str()); + c_ptr->title = fields[1]; /* Initialize */ lev = 1; @@ -1522,15 +1522,13 @@ errr init_player_info_txt(FILE *fp) switch (buf[4]) { case '0': /* Class description */ - if (!c_ptr->desc) + // Need newline? + if (!c_ptr->desc.empty()) { - - c_ptr->desc = my_strdup(s); - } - else - { - strappend(&c_ptr->desc, format("\n%s", s)); + c_ptr->desc += '\n'; } + // Append + c_ptr->desc += s; break; case '1': /* Class title */ @@ -6960,10 +6958,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst { max_rmp_idx = atoi(zz[2]); } - else if (zz[1][0] == 'C') - { - max_c_idx = atoi(zz[2]); - } else if (zz[1][0] == 'H') { max_bg_idx = atoi(zz[2]); @@ -7222,7 +7216,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp) /* Class */ else if (streq(b + 1, "CLASS")) { - v = cp_ptr->title; + v = cp_ptr->title.c_str(); // The string SHOULD be stable enough for this } /* Player */ -- cgit v1.2.3 From d33961f89a0c80f2fae4020184e72467b5c192cf Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move race_info and race_mod_info to GameEditData --- src/init1.cc | 51 ++++++++++++++++++--------------------------------- 1 file changed, 18 insertions(+), 33 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index b4c0a5ac..3b0bb701 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -703,13 +703,12 @@ static errr grab_one_class_flag(u32b *choice, cptr what) static errr grab_one_race_allow_flag(u32b *choice, cptr what) { - int i; - cptr s; + auto const &race_info = game->edit_data.race_info; /* Scan classes flags */ - for (i = 0; i < max_rp_idx && (s = race_info[i].title); i++) + for (std::size_t i = 0; i < race_info.size(); i++) { - if (streq(what, s)) + if (race_info[i].title == what) { (choice[i / 32]) |= (1L << i); return (0); @@ -921,6 +920,8 @@ static int read_ability(std::vector *abilities, char * errr init_player_info_txt(FILE *fp) { auto &class_info = game->edit_data.class_info; + auto &race_info = game->edit_data.race_info; + auto &race_mod_info = game->edit_data.race_mod_info; int lev = 1; int tit_idx = 0; @@ -1014,18 +1015,15 @@ errr init_player_info_txt(FILE *fp) /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_rp_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - rp_ptr = &race_info[i]; + rp_ptr = &expand_to_fit_index(race_info, i); + assert(rp_ptr->title.empty()); /* Copy title */ - assert(!rp_ptr->title); - rp_ptr->title = my_strdup(s); + rp_ptr->title = s; /* Initialize */ lev = 1; @@ -1037,18 +1035,15 @@ errr init_player_info_txt(FILE *fp) /* Process 'D' for "Description" */ if ((buf[0] == 'R') && (buf[2] == 'D')) { - /* Acquire the text */ - char const *s = buf + 4; - - if (!rp_ptr->desc) - { - rp_ptr->desc = my_strdup(s); - } - else + // Need newline? + if (!rp_ptr->desc.empty()) { - strappend(&rp_ptr->desc, format("\n%s", s)); + rp_ptr->desc += '\n'; } + // Append + rp_ptr->desc += (buf + 4); + /* Next... */ continue; } @@ -1236,14 +1231,12 @@ errr init_player_info_txt(FILE *fp) /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_rmp_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - rmp_ptr = &race_mod_info[i]; + rmp_ptr = &expand_to_fit_index(race_mod_info, i); + assert(rmp_ptr->title.empty()); /* Copy title */ rmp_ptr->title = s; @@ -6950,15 +6943,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst /* Maximum player types */ else if (zz[0][0] == 'P') { - if (zz[1][0] == 'R') - { - max_rp_idx = atoi(zz[2]); - } - else if (zz[1][0] == 'S') - { - max_rmp_idx = atoi(zz[2]); - } - else if (zz[1][0] == 'H') + if (zz[1][0] == 'H') { max_bg_idx = atoi(zz[2]); } @@ -7204,7 +7189,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp) /* Race */ else if (streq(b + 1, "RACE")) { - v = rp_ptr->title; + v = rp_ptr->title.c_str(); // The string SHOULD be stable enough for this } /* Race Mod */ -- cgit v1.2.3 From 42847682e6b753a819d23c3df77467f6d39c486b Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move bg into GameEditData --- src/init1.cc | 32 ++++++++++++-------------------- 1 file changed, 12 insertions(+), 20 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 3b0bb701..f6d798a9 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -922,6 +922,7 @@ errr init_player_info_txt(FILE *fp) auto &class_info = game->edit_data.class_info; auto &race_info = game->edit_data.race_info; auto &race_mod_info = game->edit_data.race_mod_info; + auto &bg = game->edit_data.bg; int lev = 1; int tit_idx = 0; @@ -962,21 +963,21 @@ errr init_player_info_txt(FILE *fp) /* Process 'H' for "History" */ if (buf[0] == 'H') { - int idx; - char *zz[6]; + char *zz[5]; /* Scan for the values */ - if (tokenize(buf + 2, 6, zz, ':', ':') != 6) return (1); + if (tokenize(buf + 2, 5, zz, ':', ':') != 5) return (1); - idx = atoi(zz[0]); - bg[idx].roll = atoi(zz[1]); - bg[idx].chart = atoi(zz[2]); - bg[idx].next = atoi(zz[3]); - bg[idx].bonus = atoi(zz[4]); + /* Create new entry */ + hist_type hist; + hist.roll = atoi(zz[0]); + hist.chart = atoi(zz[1]); + hist.next = atoi(zz[2]); + hist.bonus = atoi(zz[3]); + hist.info = my_strdup(zz[4]); - /* Copy text */ - assert(!bg[idx].info); - bg[idx].info = my_strdup(zz[5]); + /* Append */ + bg.emplace_back(hist); /* Next... */ continue; @@ -6940,15 +6941,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_o_idx = atoi(zz[1]); } - /* Maximum player types */ - else if (zz[0][0] == 'P') - { - if (zz[1][0] == 'H') - { - max_bg_idx = atoi(zz[2]); - } - } - /* Maximum m_idx */ else if (zz[0][0] == 'M') { -- cgit v1.2.3 From 4b179786d73cde338e97503d036baea9015f655d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move gen_skill to GameEditData --- src/init1.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index f6d798a9..afd256a4 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -923,6 +923,7 @@ errr init_player_info_txt(FILE *fp) auto &race_info = game->edit_data.race_info; auto &race_mod_info = game->edit_data.race_mod_info; auto &bg = game->edit_data.bg; + auto &gen_skill = game->edit_data.gen_skill; int lev = 1; int tit_idx = 0; @@ -986,7 +987,7 @@ errr init_player_info_txt(FILE *fp) /* Process 'G:k' for "General skills" */ if ((buf[0] == 'G') && (buf[2] == 'k')) { - if (read_skill_modifiers(gen_skill, buf + 4)) + if (read_skill_modifiers(&gen_skill, buf + 4)) { return 1; } -- cgit v1.2.3 From 667acd0e312301ad613b6a71f843c51d2062aee6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move d_info into GameEditData --- src/init1.cc | 49 ++++++++++++++++++++++++------------------------- 1 file changed, 24 insertions(+), 25 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index afd256a4..5fd257b0 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5113,15 +5113,14 @@ errr grab_one_dungeon_flag(dungeon_flag_set *flags, const char *str) */ errr init_d_info_txt(FILE *fp) { - int i, j; + auto &d_info = game->edit_data.d_info; + char buf[1024]; s16b rule_num = 0; byte r_char_number = 0; - char *s; - /* Current entry */ dungeon_info_type *d_ptr = NULL; @@ -5148,7 +5147,7 @@ errr init_d_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -5160,19 +5159,16 @@ errr init_d_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_d_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - d_ptr = &d_info[i]; + d_ptr = &expand_to_fit_index(d_info, i); /* Copy name */ assert(!d_ptr->name); @@ -5191,14 +5187,15 @@ errr init_d_info_txt(FILE *fp) d_ptr->fill_method = 1; rule_num = -1; r_char_number = 0; - for (j = 0; j < 5; j++) + for (std::size_t j = 0; j < 5; j++) { - int k; - d_ptr->rules[j].mode = DUNGEON_MODE_NONE; d_ptr->rules[j].percent = 0; - for (k = 0; k < 5; k++) d_ptr->rules[j].r_char[k] = 0; + for (std::size_t k = 0; k < 5; k++) + { + d_ptr->rules[j].r_char[k] = 0; + } } /* Set default drop theme */ @@ -5223,7 +5220,7 @@ errr init_d_info_txt(FILE *fp) d_ptr->short_name[2] = buf[4]; /* Acquire the text */ - s = buf + 6; + char *s = buf + 6; /* Append to description */ strappend(&d_ptr->text, s); @@ -5369,8 +5366,15 @@ errr init_d_info_txt(FILE *fp) cptr tmp; /* Find the next empty blow slot (if any) */ - for (i = 0; i < 4; i++) if ((!d_ptr->d_side[i]) && - (!d_ptr->d_dice[i])) break; + std::size_t i; + for (i = 0; i < 4; i++) + { + if ((!d_ptr->d_side[i]) && + (!d_ptr->d_dice[i])) + { + break; + } + } /* Oops, no more slots */ if (i == 4) return (1); @@ -5423,7 +5427,8 @@ errr init_d_info_txt(FILE *fp) int artif = 0, monst = 0, obj = 0; int ix = -1, iy = -1, ox = -1, oy = -1; int fill_method; - s = buf + 2; + + char const *s = buf + 2; /* Read dungeon in/out coords */ if (4 == sscanf(s, "WILD_%d_%d__%d_%d", &ix, &iy, &ox, &oy)) @@ -5519,7 +5524,7 @@ errr init_d_info_txt(FILE *fp) if (buf[0] == 'M') { byte r_char; - s = buf + 2; + char const *s = buf + 2; /* Read monster symbols */ if (1 == sscanf(s, "R_CHAR_%c", &r_char)) @@ -5546,7 +5551,7 @@ errr init_d_info_txt(FILE *fp) /* Process 'S' for "Spell Flags" (multiple lines) */ if (buf[0] == 'S') { - s = buf + 2; + char const *s = buf + 2; /* Parse this entry */ if (0 != grab_one_monster_spell_flag(&d_ptr->rules[rule_num].mspells, s)) @@ -6984,12 +6989,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst wilderness.height(atoi(zz[1])); } - /* Maximum d_idx */ - else if (zz[0][0] == 'D') - { - max_d_idx = atoi(zz[1]); - } - return (0); } } -- cgit v1.2.3 From 7ccb0c1a48d571abd6dc3aca725275e2d264aa2d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Change strings in dungeon_info_type to std::string --- src/init1.cc | 22 ++++++++-------------- 1 file changed, 8 insertions(+), 14 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 5fd257b0..4233b032 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5169,13 +5169,10 @@ errr init_d_info_txt(FILE *fp) /* Point at the "info" */ d_ptr = &expand_to_fit_index(d_info, i); + assert(d_ptr->name.empty()); /* Copy name */ - assert(!d_ptr->name); - d_ptr->name = my_strdup(s); - - /* Initialize description */ - d_ptr->text = my_strdup(""); + d_ptr->name = s; /* HACK -- Those ones HAVE to have a set default value */ d_ptr->size_x = -1; @@ -5202,7 +5199,7 @@ errr init_d_info_txt(FILE *fp) d_ptr->objs = obj_theme::defaults(); /* The default generator */ - strcpy(d_ptr->generator, "dungeon"); + d_ptr->generator = "dungeon"; /* Next... */ continue; @@ -5215,15 +5212,12 @@ errr init_d_info_txt(FILE *fp) if (buf[0] == 'D') { /* Acquire short name */ - d_ptr->short_name[0] = buf[2]; - d_ptr->short_name[1] = buf[3]; - d_ptr->short_name[2] = buf[4]; - - /* Acquire the text */ - char *s = buf + 6; + d_ptr->short_name += buf[2]; + d_ptr->short_name += buf[3]; + d_ptr->short_name += buf[4]; /* Append to description */ - strappend(&d_ptr->text, s); + d_ptr->text += (buf + 6); /* Next... */ continue; @@ -5312,7 +5306,7 @@ errr init_d_info_txt(FILE *fp) /* Process 'G' for "Generator" (one line only) */ if (buf[0] == 'G') { - strnfmt(d_ptr->generator, 30, "%s", buf + 2); + d_ptr->generator = (buf + 2); /* Next... */ continue; -- cgit v1.2.3 From 1726fc7a8ab66c15385bdda8f0533cddeb867b58 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move set_info into GameEditData --- src/init1.cc | 22 ++++++---------------- 1 file changed, 6 insertions(+), 16 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 4233b032..7d8afaa9 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -2872,12 +2872,11 @@ errr init_a_info_txt(FILE *fp) */ errr init_set_info_txt(FILE *fp) { - int i; + auto &set_info = game->edit_data.set_info; + int cur_art = 0, cur_num = 0; char buf[1024]; - char *s; - /* Current entry */ set_type *set_ptr = NULL; @@ -2905,7 +2904,7 @@ errr init_set_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -2917,19 +2916,16 @@ errr init_set_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_set_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - set_ptr = &set_info[i]; + set_ptr = &expand_to_fit_index(set_info, i); /* Copy name */ assert(!set_ptr->name); @@ -2946,7 +2942,7 @@ errr init_set_info_txt(FILE *fp) if (buf[0] == 'D') { /* Acquire the text */ - s = buf + 2; + char const *s = buf + 2; /* Append chars to the description */ strappend(&set_ptr->desc, s); @@ -6965,12 +6961,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_st_idx = atoi(zz[1]); } - /* Maximum set_idx */ - else if (zz[0][0] == 's') - { - max_set_idx = atoi(zz[1]); - } - /* Maximum wilderness x size */ else if (zz[0][0] == 'X') { -- cgit v1.2.3 From 0cea35759ed072d3a42b54926d6fee7d12346418 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Change set_type name/desc to std::string --- src/init1.cc | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 7d8afaa9..b68309b7 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -2926,10 +2926,10 @@ errr init_set_info_txt(FILE *fp) /* Point at the "info" */ set_ptr = &expand_to_fit_index(set_info, i); + assert(set_ptr->name.empty()); /* Copy name */ - assert(!set_ptr->name); - set_ptr->name = my_strdup(s); + set_ptr->name = s; /* Next... */ continue; @@ -2941,11 +2941,14 @@ errr init_set_info_txt(FILE *fp) /* Process 'D' for "Description" */ if (buf[0] == 'D') { - /* Acquire the text */ - char const *s = buf + 2; + /* Need newline? */ + if (!set_ptr->desc.empty()) + { + set_ptr->desc += '\n'; + } - /* Append chars to the description */ - strappend(&set_ptr->desc, s); + /* Append */ + set_ptr->desc += (buf + 2); /* Next... */ continue; -- cgit v1.2.3 From aebc48dffa75698be4d2c1bb2b1a0927b10be1cc Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move st_info into GameEditData --- src/init1.cc | 23 +++++++---------------- 1 file changed, 7 insertions(+), 16 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index b68309b7..fb44c99b 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5617,9 +5617,9 @@ static errr grab_one_store_flag(store_flag_set *flags, cptr what) */ errr init_st_info_txt(FILE *fp) { - int i = 0; + auto &st_info = game->edit_data.st_info; + char buf[1024]; - char *s; /* Current entry */ store_info_type *st_ptr = NULL; @@ -5647,7 +5647,7 @@ errr init_st_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -5659,22 +5659,19 @@ errr init_st_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_st_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - st_ptr = &st_info[i]; + st_ptr = &expand_to_fit_index(st_info, i); + assert(!st_ptr->name); /* Copy name */ - assert(!st_ptr->name); st_ptr->name = my_strdup(s); /* Next... */ @@ -5688,7 +5685,7 @@ errr init_st_info_txt(FILE *fp) if (buf[0] == 'I') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -6958,12 +6955,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_wf_idx = atoi(zz[1]); } - /* Maximum st_idx */ - else if (zz[0][0] == 'S') - { - max_st_idx = atoi(zz[1]); - } - /* Maximum wilderness x size */ else if (zz[0][0] == 'X') { -- cgit v1.2.3 From e02a2dfd184a996a02ecc6004a0a03bcfbd19131 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Change store_info_type::name to std::string --- src/init1.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index fb44c99b..658cf8e2 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5669,10 +5669,10 @@ errr init_st_info_txt(FILE *fp) /* Point at the "info" */ st_ptr = &expand_to_fit_index(st_info, i); - assert(!st_ptr->name); + assert(st_ptr->name.empty()); /* Copy name */ - st_ptr->name = my_strdup(s); + st_ptr->name = s; /* Next... */ continue; -- cgit v1.2.3 From dd76070a7d8676a5f13dcc91fc7ed2eb2639d9df Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move ab_info into GameEditData --- src/init1.cc | 69 ++++++++++++++++++++++++++++++++---------------------------- 1 file changed, 37 insertions(+), 32 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 658cf8e2..977bad9a 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3279,9 +3279,9 @@ errr init_s_info_txt(FILE *fp) */ errr init_ab_info_txt(FILE *fp) { - int i, z; + auto &ab_info = game->edit_data.ab_info; + char buf[1024]; - char *s; /* Current entry */ ability_type *ab_ptr = NULL; @@ -3310,7 +3310,7 @@ errr init_ab_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -3322,16 +3322,13 @@ errr init_ab_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); - - /* Verify information */ - if (i >= max_ab_idx) return (2); + int i = atoi(buf + 2); /* Save the index */ error_idx = i; /* Point at the "info" */ - ab_ptr = &ab_info[i]; + ab_ptr = &expand_to_fit_index(ab_info, i); /* Copy name */ assert(!ab_ptr->name); @@ -3339,13 +3336,13 @@ errr init_ab_info_txt(FILE *fp) /* Init */ ab_ptr->action_mkey = 0; - for (z = 0; z < 10; z++) + for (std::size_t z = 0; z < 10; z++) { ab_ptr->skills[z] = -1; ab_ptr->need_abilities[z] = -1; ab_ptr->forbid_abilities[z] = -1; } - for (z = 0; z < 6; z++) + for (std::size_t z = 0; z < 6; z++) { ab_ptr->stat[z] = -1; } @@ -3361,7 +3358,7 @@ errr init_ab_info_txt(FILE *fp) if (buf[0] == 'D') { /* Acquire the text */ - s = buf + 2; + char const *s = buf + 2; /* Append description */ if (!ab_ptr->desc) @@ -3383,7 +3380,7 @@ errr init_ab_info_txt(FILE *fp) char *txt; /* Acquire the text */ - s = buf + 2; + char *s = buf + 2; if (NULL == (txt = strchr(s, ':'))) return (1); *txt = '\0'; @@ -3438,8 +3435,14 @@ errr init_ab_info_txt(FILE *fp) if (skill == -1) return (1); + std::size_t z; for (z = 0; z < 10; z++) - if (ab_ptr->skills[z] == -1) break; + { + if (ab_ptr->skills[z] == -1) + { + break; + } + } if (z < 10) { @@ -3454,20 +3457,14 @@ errr init_ab_info_txt(FILE *fp) /* Process 'a' for "needed ability" */ if (buf[0] == 'a') { - s16b ab; - - ab = find_ability(buf + 2); - - if (ab == -1) return (1); - - for (z = 0; z < 10; z++) - if (ab_ptr->need_abilities[z] == -1) break; - - if (z < 10) + s16b ab = find_ability(buf + 2); + if (ab == -1) { - ab_ptr->need_abilities[z] = ab; + return (1); } + ab_ptr->need_abilities.push_back(ab); + /* Next... */ continue; } @@ -3521,15 +3518,29 @@ errr init_ab_info_txt(FILE *fp) if ((ab1 == -1) || (ab2 == -1)) return (1); + std::size_t z; + for (z = 0; z < 10; z++) - if (ab_info[ab1].forbid_abilities[z] == -1) break; + { + if (ab_info[ab1].forbid_abilities[z] == -1) + { + break; + } + } + if (z < 10) { ab_info[ab1].forbid_abilities[z] = ab2; } for (z = 0; z < 10; z++) - if (ab_info[ab2].forbid_abilities[z] == -1) break; + { + if (ab_info[ab2].forbid_abilities[z] == -1) + { + break; + } + } + if (z < 10) { ab_info[ab2].forbid_abilities[z] = ab1; @@ -6901,12 +6912,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst if (max_s_idx > MAX_SKILLS) return (1); } - /* Maximum ab_idx */ - else if (zz[0][0] == 'b') - { - max_ab_idx = atoi(zz[1]); - } - /* Maximum k_idx */ else if (zz[0][0] == 'K') { -- cgit v1.2.3 From c84490dd6fb5d1e85482c2271e00cb768bae410e Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Change ability_type::{name, desc, action_desc} to std::string --- src/init1.cc | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 977bad9a..f9df3c1b 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3329,10 +3329,10 @@ errr init_ab_info_txt(FILE *fp) /* Point at the "info" */ ab_ptr = &expand_to_fit_index(ab_info, i); + assert(ab_ptr->name.empty()); /* Copy name */ - assert(!ab_ptr->name); - ab_ptr->name = my_strdup(s); + ab_ptr->name = s; /* Init */ ab_ptr->action_mkey = 0; @@ -3357,19 +3357,15 @@ errr init_ab_info_txt(FILE *fp) /* Process 'D' for "Description" */ if (buf[0] == 'D') { - /* Acquire the text */ - char const *s = buf + 2; - - /* Append description */ - if (!ab_ptr->desc) - { - ab_ptr->desc = my_strdup(s); - } - else + /* Need newline? */ + if (!ab_ptr->desc.empty()) { - strappend(&ab_ptr->desc, format("\n%s", s)); + ab_ptr->desc += '\n'; } + /* Append */ + ab_ptr->desc += (buf + 2); + /* Next... */ continue; } @@ -3387,8 +3383,8 @@ errr init_ab_info_txt(FILE *fp) txt++; /* Copy name */ - assert(!ab_ptr->action_desc); - ab_ptr->action_desc = my_strdup(txt); + assert(ab_ptr->action_desc.empty()); + ab_ptr->action_desc = txt; /* Set mkey */ ab_ptr->action_mkey = atoi(s); -- cgit v1.2.3 From 5f3ce3824f5174608a955703a14595c14d0a577d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Clean up ability_type --- src/init1.cc | 88 +++++------------------------------------------------------- 1 file changed, 6 insertions(+), 82 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index f9df3c1b..a6376090 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3334,19 +3334,6 @@ errr init_ab_info_txt(FILE *fp) /* Copy name */ ab_ptr->name = s; - /* Init */ - ab_ptr->action_mkey = 0; - for (std::size_t z = 0; z < 10; z++) - { - ab_ptr->skills[z] = -1; - ab_ptr->need_abilities[z] = -1; - ab_ptr->forbid_abilities[z] = -1; - } - for (std::size_t z = 0; z < 6; z++) - { - ab_ptr->stat[z] = -1; - } - /* Next... */ continue; } @@ -3415,7 +3402,6 @@ errr init_ab_info_txt(FILE *fp) if (buf[0] == 'k') { char *sec; - s16b level, skill; /* Scan for the values */ if (NULL == (sec = strchr(buf + 2, ':'))) @@ -3426,25 +3412,15 @@ errr init_ab_info_txt(FILE *fp) sec++; if (!*sec) return (1); - level = atoi(buf + 2); - skill = find_skill(sec); - + s16b level = atoi(buf + 2); + s16b skill = find_skill(sec); if (skill == -1) return (1); - std::size_t z; - for (z = 0; z < 10; z++) - { - if (ab_ptr->skills[z] == -1) - { - break; - } - } + ability_type::skill_requirement req; + req.skill_idx = skill; + req.level = level; - if (z < 10) - { - ab_ptr->skills[z] = skill; - ab_ptr->skill_levels[z] = level; - } + ab_ptr->need_skills.emplace_back(req); /* Next... */ continue; @@ -3494,58 +3470,6 @@ errr init_ab_info_txt(FILE *fp) continue; } - /* Process 'E' for "Excluding ability" */ - if (buf[0] == 'E') - { - char *sec; - s16b ab1, ab2; - - /* Scan for the values */ - if (NULL == (sec = strchr(buf + 2, ':'))) - { - return (1); - } - *sec = '\0'; - sec++; - if (!*sec) return (1); - - ab1 = find_ability(buf + 2); - ab2 = find_ability(sec); - - if ((ab1 == -1) || (ab2 == -1)) return (1); - - std::size_t z; - - for (z = 0; z < 10; z++) - { - if (ab_info[ab1].forbid_abilities[z] == -1) - { - break; - } - } - - if (z < 10) - { - ab_info[ab1].forbid_abilities[z] = ab2; - } - - for (z = 0; z < 10; z++) - { - if (ab_info[ab2].forbid_abilities[z] == -1) - { - break; - } - } - - if (z < 10) - { - ab_info[ab2].forbid_abilities[z] = ab1; - } - - /* Next... */ - continue; - } - /* Oops */ return (6); } -- cgit v1.2.3 From 5869c5622e4345ffd50e0713d188f2d283b61caa Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Remove support for "O:" lines in s_info.txt If was actually not being used. --- src/init1.cc | 32 -------------------------------- 1 file changed, 32 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index a6376090..29f63ac7 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3091,38 +3091,6 @@ errr init_s_info_txt(FILE *fp) } - /* Process 'O' for "Opposite" */ - if (buf[0] == 'O') - { - char *sec, *cval; - s16b s1, s2; - - /* Scan for the values */ - if (NULL == (sec = strchr(buf + 2, ':'))) - { - return (1); - } - *sec = '\0'; - sec++; - if (!*sec) return (1); - if (NULL == (cval = strchr(sec, '%'))) - { - return (1); - } - *cval = '\0'; - cval++; - if (!*cval) return (1); - - s1 = find_skill(buf + 2); - s2 = find_skill(sec); - if ((s1 == -1) || (s2 == -1)) return (1); - - s_descriptors[s1].action[s2] = -atoi(cval); - - /* Next... */ - continue; - } - /* Process 'A' for "Amical/friendly" */ if (buf[0] == 'f') { -- cgit v1.2.3 From 765e1a3dc7abce3a849b8d1f124ada7a6984154a Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move s_{info,descriptors} to Game/GameEdtiData --- src/init1.cc | 61 ++++++++++++++++++++++++++++-------------------------------- 1 file changed, 28 insertions(+), 33 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 29f63ac7..9431ec46 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -833,7 +833,7 @@ static int read_skill_modifiers(skill_modifiers *skill_modifiers, cptr buf) return 1; } - auto s = &skill_modifiers->modifiers[i]; + auto s = &expand_to_fit_index(skill_modifiers->modifiers, i); s->basem = monster_ego_modify(v); s->base = val; @@ -3011,9 +3011,11 @@ errr init_set_info_txt(FILE *fp) */ errr init_s_info_txt(FILE *fp) { - int i, order = 1; + auto &s_descriptors = game->edit_data.s_descriptors; + auto &s_info = game->s_info; + + int order = 1; char buf[1024]; - char *s; /* Current entry */ skill_descriptor *s_ptr = NULL; @@ -3083,8 +3085,11 @@ errr init_s_info_txt(FILE *fp) s2 = find_skill(sec); if ((s1 == -1) || (s2 == -1)) return (1); - s_descriptors[s1].action[s2] = SKILL_EXCLUSIVE; - s_descriptors[s2].action[s1] = SKILL_EXCLUSIVE; + // The "exclusive" relation is symmetric, so + // add summetrically so we don't have to specify + // twice in data files. + s_descriptors[s1].excludes.push_back(s2); + s_descriptors[s2].excludes.push_back(s1); /* Next... */ continue; @@ -3117,7 +3122,8 @@ errr init_s_info_txt(FILE *fp) s2 = find_skill(sec); if ((s1 == -1) || (s2 == -1)) return (1); - s_descriptors[s1].action[s2] = atoi(cval); + s_descriptors[s1].increases.emplace_back( + std::make_tuple(s2, atoi(cval))); /* Next... */ continue; @@ -3127,7 +3133,7 @@ errr init_s_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -3139,19 +3145,19 @@ errr init_s_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); - - /* Verify information */ - if (i >= max_s_idx) return (2); + int i = atoi(buf + 2); /* Save the index */ error_idx = i; /* Point at the "info" */ - s_ptr = &s_descriptors[i]; + s_ptr = &expand_to_fit_index(s_descriptors, i); + assert(s_ptr->name.empty()); + + /* Make sure s_info also expands appropriately */ + expand_to_fit_index(s_info, i); /* Copy name */ - assert(!s_ptr->name); s_ptr->name = my_strdup(s); /* Next... */ @@ -3164,19 +3170,15 @@ errr init_s_info_txt(FILE *fp) /* Process 'D' for "Description" */ if (buf[0] == 'D') { - /* Acquire the text */ - s = buf + 2; - - /* Description */ - if (!s_ptr->desc) - { - s_ptr->desc = my_strdup(s); - } - else + /* Need newline? */ + if (!s_ptr->desc.empty()) { - strappend(&s_ptr->desc, format("\n%s", s)); + s_ptr->desc += '\n'; } + /* Append */ + s_ptr->desc += (buf + 2); + /* Next... */ continue; } @@ -3187,15 +3189,15 @@ errr init_s_info_txt(FILE *fp) char *txt; /* Acquire the text */ - s = buf + 2; + char const *s = buf + 2; if (NULL == (txt = strchr(s, ':'))) return (1); *txt = '\0'; txt++; /* Copy action description */ - assert(!s_ptr->action_desc); - s_ptr->action_desc = my_strdup(txt); + assert(s_ptr->action_desc.empty()); + s_ptr->action_desc = txt; /* Copy mkey index */ s_ptr->action_mkey = atoi(s); @@ -6793,13 +6795,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_re_idx = atoi(zz[1]); } - /* Maximum s_idx */ - else if (zz[0][0] == 'k') - { - max_s_idx = atoi(zz[1]); - if (max_s_idx > MAX_SKILLS) return (1); - } - /* Maximum k_idx */ else if (zz[0][0] == 'K') { -- cgit v1.2.3 From e1230547a936c7180b3a69012659fc511027f035 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move re_info into GameEditData --- src/init1.cc | 43 +++++++++++++++++++------------------------ 1 file changed, 19 insertions(+), 24 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 9431ec46..62211893 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4433,12 +4433,12 @@ errr init_r_info_txt(FILE *fp) */ errr init_re_info_txt(FILE *fp) { - int i, j; + auto &re_info = game->edit_data.re_info; + char buf[1024]; byte blow_num = 0; - int r_char_number = 0, nr_char_number = 0; - - char *s, *t; + int r_char_number = 0; + int nr_char_number = 0; /* Current entry */ monster_ego *re_ptr = NULL; @@ -4466,7 +4466,7 @@ errr init_re_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -4478,19 +4478,16 @@ errr init_re_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_re_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - re_ptr = &re_info[i]; + re_ptr = &expand_to_fit_index(re_info, i); /* Copy name */ assert(!re_ptr->name); @@ -4500,9 +4497,8 @@ errr init_re_info_txt(FILE *fp) blow_num = 0; r_char_number = 0; nr_char_number = 0; - for (j = 0; j < 5; j++) re_ptr->r_char[j] = 0; - for (j = 0; j < 5; j++) re_ptr->nr_char[j] = 0; - for (j = 0; j < 4; j++) + + for (std::size_t j = 0; j < 4; j++) { re_ptr->blow[j].method = 0; re_ptr->blow[j].effect = 0; @@ -4598,6 +4594,8 @@ errr init_re_info_txt(FILE *fp) { int n1, n2, dice, side; char mdice, mside; + char *s; + char *t; /* Oops, no more slots */ if (blow_num == 4) return (1); @@ -4658,7 +4656,7 @@ errr init_re_info_txt(FILE *fp) char r_char; /* Parse every entry */ - s = buf + 2; + char const *s = buf + 2; /* XXX XXX XXX Hack -- Read monster symbols */ if (1 == sscanf(s, "R_CHAR_%c", &r_char)) @@ -4688,7 +4686,7 @@ errr init_re_info_txt(FILE *fp) char r_char; /* Parse every entry */ - s = buf + 2; + char const *s = buf + 2; /* XXX XXX XXX Hack -- Read monster symbols */ if (1 == sscanf(s, "R_CHAR_%c", &r_char)) @@ -4727,7 +4725,7 @@ errr init_re_info_txt(FILE *fp) /* Process 'O' for "Basic Monster -Flags" (multiple lines) */ if (buf[0] == 'O') { - s = buf + 2; + char const *s = buf + 2; /* XXX XXX XXX Hack -- Read no flags */ if (!strcmp(s, "MF_ALL")) @@ -4750,7 +4748,8 @@ errr init_re_info_txt(FILE *fp) /* Process 'S' for "Spell Flags" (multiple lines) */ if (buf[0] == 'S') { - s = buf + 2; + char const *s = buf + 2; + int i; /* XXX XXX XXX Hack -- Read spell frequency */ if (1 == sscanf(s, "1_IN_%d", &i)) @@ -4775,8 +4774,10 @@ errr init_re_info_txt(FILE *fp) if (buf[0] == 'T') { /* Parse every entry */ - for (s = buf + 2; *s; ) + for (char *s = buf + 2; *s; ) { + char *t; + /* Find the end of this entry */ for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; @@ -6789,12 +6790,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_r_idx = atoi(zz[1]); } - /* Maximum re_idx */ - else if (zz[0][0] == 'r') - { - max_re_idx = atoi(zz[1]); - } - /* Maximum k_idx */ else if (zz[0][0] == 'K') { -- cgit v1.2.3 From 5ddcbbf1cdce68e565376819efedd519892512ad Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move wf_info into GameEditData --- src/init1.cc | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 62211893..17024337 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6000,9 +6000,9 @@ errr init_ow_info_txt(FILE *fp) */ errr init_wf_info_txt(FILE *fp) { - int i; + auto &wf_info = game->edit_data.wf_info; + char buf[1024]; - char *s; /* Current entry */ wilderness_type_info *wf_ptr = NULL; @@ -6029,7 +6029,7 @@ errr init_wf_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -6041,19 +6041,16 @@ errr init_wf_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_wf_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - wf_ptr = &wf_info[i]; + wf_ptr = &expand_to_fit_index(wf_info, i); /* Copy the name */ assert(!wf_ptr->name); @@ -6070,7 +6067,7 @@ errr init_wf_info_txt(FILE *fp) if (buf[0] == 'D') { /* Acquire the text */ - s = buf + 2; + char *s = buf + 2; /* Copy description */ assert(!wf_ptr->text); @@ -6177,6 +6174,7 @@ static dungeon_grid letter[255]; static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalstart, int ymax, int xmax, bool_ full) { auto &wilderness = game->wilderness; + auto &wf_info = game->edit_data.wf_info; int i; @@ -6832,12 +6830,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_t_idx = atoi(zz[1]); } - /* Maximum wf_idx */ - else if (zz[0][0] == 'W') - { - max_wf_idx = atoi(zz[1]); - } - /* Maximum wilderness x size */ else if (zz[0][0] == 'X') { -- cgit v1.2.3 From 0c2f30b56c221a826ba64f0ec864c29d0f717644 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move r_info into GameEditData --- src/init1.cc | 31 +++++++++++-------------------- 1 file changed, 11 insertions(+), 20 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 17024337..3dcee907 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4097,9 +4097,9 @@ static errr grab_one_monster_spell_flag(monster_spell_flag_set *flags, cptr what */ errr init_r_info_txt(FILE *fp) { - int i; + auto &r_info = game->edit_data.r_info; + char buf[1024]; - char *s, *t; /* Current entry */ monster_race *r_ptr = NULL; @@ -4128,7 +4128,7 @@ errr init_r_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -4140,19 +4140,16 @@ errr init_r_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_r_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - r_ptr = &r_info[i]; + r_ptr = &expand_to_fit_index(r_info, i); /* Allocate name string. */ assert(!r_ptr->name); // Sanity check that we aren't overwriting anything @@ -4178,11 +4175,8 @@ errr init_r_info_txt(FILE *fp) /* Process 'D' for "Description" */ if (buf[0] == 'D') { - /* Acquire the text */ - s = buf + 2; - /* Append to description */ - strappend(&r_ptr->text, s); + strappend(&r_ptr->text, buf + 2); /* Next... */ continue; @@ -4324,7 +4318,9 @@ errr init_r_info_txt(FILE *fp) /* Process 'B' for "Blows" (up to four lines) */ if (buf[0] == 'B') { - int n1, n2; + int i, n1, n2; + char *s; + char *t; /* Find the next empty blow slot (if any) */ for (i = 0; i < 4; i++) if (!r_ptr->blow[i].method) break; @@ -4397,7 +4393,8 @@ errr init_r_info_txt(FILE *fp) /* Process 'S' for "Spell Flags" (multiple lines) */ if (buf[0] == 'S') { - s = buf + 2; + char const *s = buf + 2; + int i; /* XXX XXX XXX Hack -- Read spell frequency */ if (1 == sscanf(s, "1_IN_%d", &i)) @@ -6782,12 +6779,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_real_towns = atoi(zz[1]); } - /* Maximum r_idx */ - else if (zz[0][0] == 'R') - { - max_r_idx = atoi(zz[1]); - } - /* Maximum k_idx */ else if (zz[0][0] == 'K') { -- cgit v1.2.3 From b9fca0267b1d6a32d57e1fb4387f52c19d1c3fa6 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move f_info into GameEditData --- src/init1.cc | 22 +++++++--------------- 1 file changed, 7 insertions(+), 15 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 3dcee907..d2fef6a9 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -2056,9 +2056,9 @@ static int grab_one_feature_flag(cptr what, feature_flag_set *flags) */ errr init_f_info_txt(FILE *fp) { - int i; + auto &f_info = game->edit_data.f_info; + char buf[1024]; - char *s; /* Current entry */ feature_type *f_ptr = NULL; @@ -2085,7 +2085,7 @@ errr init_f_info_txt(FILE *fp) if (buf[0] == 'N') { /* Find the colon before the name */ - s = strchr(buf + 2, ':'); + char *s = strchr(buf + 2, ':'); /* Verify that colon */ if (!s) return (1); @@ -2097,19 +2097,16 @@ errr init_f_info_txt(FILE *fp) if (!*s) return (1); /* Get the index */ - i = atoi(buf + 2); + int i = atoi(buf + 2); /* Verify information */ if (i <= error_idx) return (4); - /* Verify information */ - if (i >= max_f_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - f_ptr = &f_info[i]; + f_ptr = &expand_to_fit_index(f_info, i); /* Copy name */ assert(!f_ptr->name); @@ -2133,7 +2130,7 @@ errr init_f_info_txt(FILE *fp) if (buf[0] == 'D') { /* Acquire the text */ - s = buf + 4; + const char *s = buf + 4; switch (buf[2]) { @@ -2226,6 +2223,7 @@ errr init_f_info_txt(FILE *fp) { int side, dice, freq, type; cptr tmp; + int i; /* Find the next empty blow slot (if any) */ for (i = 0; i < 4; i++) if ((!f_ptr->d_side[i]) && @@ -6785,12 +6783,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_k_idx = atoi(zz[1]); } - /* Maximum f_idx */ - else if (zz[0][0] == 'F') - { - max_f_idx = atoi(zz[1]); - } - /* Maximum a_idx */ else if (zz[0][0] == 'A') { -- cgit v1.2.3 From 1bbed63b66c0f69809e698576a51501150f06bba Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move k_info into GameEditData --- src/init1.cc | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index d2fef6a9..89149c8f 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -2300,6 +2300,8 @@ errr init_f_info_txt(FILE *fp) */ errr init_k_info_txt(FILE *fp) { + auto &k_info = game->edit_data.k_info; + int i; char buf[1024]; char *s, *t; @@ -2349,14 +2351,11 @@ errr init_k_info_txt(FILE *fp) /* Verify information */ if (i <= error_idx) return (4); - /* Verify information */ - if (i >= max_k_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - k_ptr = &k_info[i]; + k_ptr = &expand_to_fit_index(k_info, i); /* Advance and Save the name index */ assert(!k_ptr->name); @@ -6777,12 +6776,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_real_towns = atoi(zz[1]); } - /* Maximum k_idx */ - else if (zz[0][0] == 'K') - { - max_k_idx = atoi(zz[1]); - } - /* Maximum a_idx */ else if (zz[0][0] == 'A') { -- cgit v1.2.3 From 57bb453a15034c67d04496360b306a5f3bfd0bf2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move a_info into GameEditData --- src/init1.cc | 19 ++++++------------- 1 file changed, 6 insertions(+), 13 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 89149c8f..3912db12 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -2627,6 +2627,8 @@ errr init_k_info_txt(FILE *fp) */ errr init_a_info_txt(FILE *fp) { + auto &a_info = game->edit_data.a_info; + int i; char buf[1024]; char *s; @@ -2675,14 +2677,11 @@ errr init_a_info_txt(FILE *fp) /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_a_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - a_ptr = &a_info[i]; + a_ptr = &expand_to_fit_index(a_info, i); /* Copy name */ assert(!a_ptr->name); @@ -6169,6 +6168,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst { auto &wilderness = game->wilderness; auto &wf_info = game->edit_data.wf_info; + auto &a_info = game->edit_data.a_info; int i; @@ -6557,11 +6557,10 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst { int I_kind = 0; - artifact_type *a_ptr = &a_info[artifact_index]; - - object_type forge; + auto a_ptr = &a_info[artifact_index]; /* Get local object */ + object_type forge; object_type *q_ptr = &forge; a_allow_special[artifact_index] = TRUE; @@ -6776,12 +6775,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_real_towns = atoi(zz[1]); } - /* Maximum a_idx */ - else if (zz[0][0] == 'A') - { - max_a_idx = atoi(zz[1]); - } - /* Maximum e_idx */ else if (zz[0][0] == 'E') { -- cgit v1.2.3 From 89e75b855662b1dcc86a6dc3789fa496aafbb0a2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move e_info into GameEditData --- src/init1.cc | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 3912db12..185548ea 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3499,6 +3499,8 @@ static bool_ grab_one_ego_item_flag(object_flag_set *flags, ego_flag_set *ego, c */ errr init_e_info_txt(FILE *fp) { + auto &e_info = game->edit_data.e_info; + int i, cur_r = -1, cur_t = 0; char buf[1024]; char *s, *t; @@ -3547,9 +3549,6 @@ errr init_e_info_txt(FILE *fp) /* Verify information */ if (i < error_idx) return (4); - /* Verify information */ - if (i >= max_e_idx) return (2); - /* Save the index */ error_idx = i; @@ -3558,7 +3557,7 @@ errr init_e_info_txt(FILE *fp) cur_t = 0; /* Point at the "info" */ - e_ptr = &e_info[i]; + e_ptr = &expand_to_fit_index(e_info, i); /* Copy name */ assert(!e_ptr->name); @@ -6775,12 +6774,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_real_towns = atoi(zz[1]); } - /* Maximum e_idx */ - else if (zz[0][0] == 'E') - { - max_e_idx = atoi(zz[1]); - } - /* Maximum o_idx */ else if (zz[0][0] == 'O') { -- cgit v1.2.3 From c25b265c056a4512b0fb0e1789927e6c4b7b32cf Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:08 +0200 Subject: Move t_info into GameEditData --- src/init1.cc | 13 +++---------- 1 file changed, 3 insertions(+), 10 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 185548ea..105aadda 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -4836,6 +4836,8 @@ static errr grab_one_trap_type_flag(trap_type *t_ptr, cptr what) */ errr init_t_info_txt(FILE *fp) { + auto &t_info = game->edit_data.t_info; + int i; char buf[1024]; char *s, *t; @@ -4882,14 +4884,11 @@ errr init_t_info_txt(FILE *fp) /* Verify information */ if (i <= error_idx) return (4); - /* Verify information */ - if (i >= max_t_idx) return (2); - /* Save the index */ error_idx = i; /* Point at the "info" */ - t_ptr = &t_info[i]; + t_ptr = &expand_to_fit_index(t_info, i); /* Copy name */ t_ptr->name = my_strdup(s); @@ -6786,12 +6785,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst max_m_idx = atoi(zz[1]); } - /* Maximum tr_idx */ - else if (zz[0][0] == 'U') - { - max_t_idx = atoi(zz[1]); - } - /* Maximum wilderness x size */ else if (zz[0][0] == 'X') { -- cgit v1.2.3 From cbafbc638c2e1d5bb40ee6bc419007062e9615e4 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Wed, 5 Oct 2016 18:45:09 +0200 Subject: Remove traps Credit goes mostly to "miramor" who did most of the actual work. I just did a few minor tweaks and fixes + rebased onto master. --- src/init1.cc | 219 +---------------------------------------------------------- 1 file changed, 3 insertions(+), 216 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 105aadda..6fd08ed2 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -40,8 +40,6 @@ #include "store_info_type.hpp" #include "tables.hpp" #include "town_type.hpp" -#include "trap_type.hpp" -#include "traps.hpp" #include "util.hpp" #include "util.h" #include "variable.h" @@ -169,46 +167,6 @@ static cptr r_info_blow_effect[] = }; -/* - * Trap flags - */ -static cptr t_info_flags[] = -{ - "CHEST", - "DOOR", - "FLOOR", - "XXX4", - "XXX5", - "XXX6", - "XXX7", - "XXX8", - "XXX9", - "XXX10", - "XXX11", - "XXX12", - "XXX13", - "XXX14", - "XXX15", - "XXX16", - "LEVEL1", - "LEVEL2", - "LEVEL3", - "LEVEL4", - "XXX21", - "XXX22", - "XXX23", - "XXX24", - "XXX25", - "XXX26", - "XXX27", - "XXX28", - "XXX29", - "XXX30", - "XXX31", - "XXX32" -}; - - /* * Helpers for looking up flags in the above arrays * and extracting "bitmasks" from them. @@ -1370,7 +1328,6 @@ errr init_player_info_txt(FILE *fp) return (1); } - /* Next... */ continue; } @@ -4814,177 +4771,8 @@ errr init_re_info_txt(FILE *fp) /* - * Grab one flag in an trap_type from a textual string - */ -static errr grab_one_trap_type_flag(trap_type *t_ptr, cptr what) -{ - if (lookup_flags(what, flag_tie(&t_ptr->flags, t_info_flags))) - { - return (0); - } - - /* Oops */ - msg_format("Unknown trap_type flag '%s'.", what); - - /* Error */ - return (1); -} - - -/* - * Initialize the "tr_info" array, by parsing an ascii "template" file + * Grab one flag for a dungeon type from a textual string */ -errr init_t_info_txt(FILE *fp) -{ - auto &t_info = game->edit_data.t_info; - - int i; - char buf[1024]; - char *s, *t; - - /* Current entry */ - trap_type *t_ptr = NULL; - - /* Just before the first record */ - error_idx = -1; - - /* Just before the first line */ - error_line = -1; - - /* Parse */ - while (0 == my_fgets(fp, buf, 1024)) - { - /* Advance the line number */ - error_line++; - - /* Skip comments and blank lines */ - if (!buf[0] || (buf[0] == '#')) continue; - - /* Verify correct "colon" format */ - if (buf[1] != ':') return (1); - - /* Process 'N' for "New/Number/Name" */ - if (buf[0] == 'N') - { - /* Find the colon before the name */ - s = strchr(buf + 2, ':'); - - /* Verify that colon */ - if (!s) return (1); - - /* Nuke the colon, advance to the name */ - *s++ = '\0'; - - /* Paranoia -- require a name */ - if (!*s) return (1); - - /* Get the index */ - i = atoi(buf + 2); - - /* Verify information */ - if (i <= error_idx) return (4); - - /* Save the index */ - error_idx = i; - - /* Point at the "info" */ - t_ptr = &expand_to_fit_index(t_info, i); - - /* Copy name */ - t_ptr->name = my_strdup(s); - - /* Initialize */ - t_ptr->text = my_strdup(""); - - /* Next... */ - continue; - } - - /* There better be a current t_ptr */ - if (!t_ptr) return (3); - - - /* Process 'I' for "Information" */ - if (buf[0] == 'I') - { - int probability, another, p1valinc, difficulty; - int minlevel; - int dd, ds; - char color; - - /* Scan for the values */ - if (8 != sscanf(buf + 2, "%d:%d:%d:%d:%d:%dd%d:%c", - &difficulty, &probability, &another, - &p1valinc, &minlevel, &dd, &ds, - &color)) return (1); - - t_ptr->difficulty = (byte)difficulty; - t_ptr->probability = (s16b)probability; - t_ptr->another = (s16b)another; - t_ptr->p1valinc = (s16b)p1valinc; - t_ptr->minlevel = (byte)minlevel; - t_ptr->dd = (s16b)dd; - t_ptr->ds = (s16b)ds; - t_ptr->color = color_char_to_attr(color); - - /* Next... */ - continue; - } - - - /* Process 'D' for "Description" */ - if (buf[0] == 'D') - { - /* Acquire the text */ - s = buf + 2; - - /* Append chars to the name */ - strappend(&t_ptr->text, s); - - /* Next... */ - continue; - } - - - /* Hack -- Process 'F' for flags */ - if (buf[0] == 'F') - { - - t_ptr->flags = 0; - - /* Parse every entry textually */ - for (s = buf + 2; *s; ) - { - /* Find the end of this entry */ - for (t = s; *t && (*t != ' ') && (*t != '|'); ++t) /* loop */; - - /* Nuke and skip any dividers */ - if (*t) - { - *t++ = '\0'; - while (*t == ' ' || *t == '|') t++; - } - - /* Parse this entry */ - if (0 != grab_one_trap_type_flag(t_ptr, s)) return (5); - - /* Start the next entry */ - s = t; - } - - /* Next... */ - continue; - } - - - /* Oops */ - return (6); - } - - /* Success */ - return (0); -} - errr grab_one_dungeon_flag(dungeon_flag_set *flags, const char *str) { #define DF(tier, index, name) \ @@ -6490,7 +6278,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst } else { - place_trap(y, x); + /* No traps - do nothing */ } object_level = level; @@ -6525,10 +6313,9 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst place_object(y, x, TRUE, TRUE, OBJ_FOUND_SPECIAL); } } - /* Random trap */ else if (random & RANDOM_TRAP) { - place_trap(y, x); + /* Do nothing */ } else if (object_index) { -- cgit v1.2.3 From e2f33131dfed23435a7915daa57b1ddf05c5f898 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 8 Oct 2016 11:38:29 +0200 Subject: Remove traps from maps and levels --- src/init1.cc | 71 +++++++++++------------------------------------------------- 1 file changed, 13 insertions(+), 58 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 6fd08ed2..c77f28eb 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -5921,7 +5921,6 @@ errr init_wf_info_txt(FILE *fp) #define RANDOM_OBJECT 0x04 #define RANDOM_EGO 0x08 #define RANDOM_ARTIFACT 0x10 -#define RANDOM_TRAP 0x20 typedef struct dungeon_grid dungeon_grid; @@ -5933,7 +5932,6 @@ struct dungeon_grid int object; /* Object */ int ego; /* Ego-Item */ int artifact; /* Artifact */ - int trap; /* Trap */ int cave_info; /* Flags for CAVE_MARK, CAVE_GLOW, CAVE_ICKY, CAVE_ROOM */ int special; /* Reserved for special terrain info */ int random; /* Number of the random effect */ @@ -5994,12 +5992,12 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst return (0); } - /* Process "F:::::::::::" -- info for dungeon grid */ + /* Process "F::::::::::" -- info for dungeon grid */ if (buf[0] == 'F') { int num; - if ((num = tokenize(buf + 2, 11, zz, ':', '/')) > 1) + if ((num = tokenize(buf + 2, 10, zz, ':', '/')) > 1) { int index = zz[0][0]; @@ -6009,7 +6007,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst letter[index].object = 0; letter[index].ego = 0; letter[index].artifact = 0; - letter[index].trap = 0; letter[index].cave_info = 0; letter[index].special = 0; letter[index].random = 0; @@ -6115,34 +6112,17 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst if (num > 7) { - if (zz[7][0] == '*') - { - letter[index].random |= RANDOM_TRAP; - - if (zz[7][1]) - { - zz[7]++; - letter[index].trap = atoi(zz[7]); - } - } - else - letter[index].trap = atoi(zz[7]); - } - - if (num > 8) - { + char *field = zz[7]; /* Quests can be defined by name only */ - if (zz[8][0] == '"') + if (field[0] == '"') { - int i; - /* Hunt & shoot the ending " */ - i = strlen(zz[8]) - 1; - if (zz[8][i] == '"') zz[8][i] = '\0'; + int i = strlen(field) - 1; + if (field[i] == '"') field[i] = '\0'; letter[index].special = 0; for (i = 0; i < MAX_Q_IDX; i++) { - if (!strcmp(&zz[8][1], quest[i].name)) + if (!strcmp(&field[1], quest[i].name)) { letter[index].special = i; break; @@ -6150,17 +6130,17 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst } } else - letter[index].special = atoi(zz[8]); + letter[index].special = atoi(field); } - if (num > 9) + if (num > 8) { - letter[index].mimic = atoi(zz[9]); + letter[index].mimic = atoi(zz[8]); } - if (num > 10) + if (num > 9) { - letter[index].mflag = atoi(zz[10]); + letter[index].mflag = atoi(zz[9]); } return (0); @@ -6262,28 +6242,7 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst if (m_idx) m_list[m_idx].mflag |= letter[idx].mflag; /* Object (and possible trap) */ - if ((random & RANDOM_OBJECT) && (random & RANDOM_TRAP)) - { - int level = object_level; - - object_level = quest[p_ptr->inside_quest].level; - - /* - * Random trap and random treasure defined - * 25% chance for trap and 75% chance for object - */ - if (rand_int(100) < 75) - { - place_object(y, x, FALSE, FALSE, OBJ_FOUND_SPECIAL); - } - else - { - /* No traps - do nothing */ - } - - object_level = level; - } - else if (random & RANDOM_OBJECT) + if (random & RANDOM_OBJECT) { /* Create an out of deep object */ if (object_index) @@ -6313,10 +6272,6 @@ static errr process_dungeon_file_aux(char *buf, int *yval, int *xval, int xvalst place_object(y, x, TRUE, TRUE, OBJ_FOUND_SPECIAL); } } - else if (random & RANDOM_TRAP) - { - /* Do nothing */ - } else if (object_index) { /* Get local object */ -- cgit v1.2.3 From f40b4894a8410c1277aaabbf5ac47536810b65aa Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Sat, 8 Oct 2016 14:57:33 +0200 Subject: Work around bad strchr() declaration Fixes #11 --- src/init1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index c77f28eb..427e2d86 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -3142,7 +3142,7 @@ errr init_s_info_txt(FILE *fp) char *txt; /* Acquire the text */ - char const *s = buf + 2; + char *s = buf + 2; if (NULL == (txt = strchr(s, ':'))) return (1); *txt = '\0'; -- cgit v1.2.3 From a40a0d1aeddb4742e486f601cbcc7e9ddcc06e2d Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 2 May 2017 19:20:57 +0200 Subject: Move player_{name,base} to Game --- src/init1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 427e2d86..96c1b067 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6749,7 +6749,7 @@ static cptr process_dungeon_file_expr(char **sp, char *fp) /* Player */ else if (streq(b + 1, "PLAYER")) { - v = player_base; + v = game->player_base.c_str(); // The string SHOULD be stable enough for this } /* Town */ -- cgit v1.2.3 From ca47ccdc66d252e0b5791112cac4042e86cefc89 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 2 May 2017 19:20:57 +0200 Subject: Remove character background --- src/init1.cc | 32 +++----------------------------- 1 file changed, 3 insertions(+), 29 deletions(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 96c1b067..056b5b51 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -13,7 +13,6 @@ #include "files.hpp" #include "game.hpp" #include "gods.hpp" -#include "hist_type.hpp" #include "init2.hpp" #include "monster2.hpp" #include "monster_ego.hpp" @@ -880,7 +879,6 @@ errr init_player_info_txt(FILE *fp) auto &class_info = game->edit_data.class_info; auto &race_info = game->edit_data.race_info; auto &race_mod_info = game->edit_data.race_mod_info; - auto &bg = game->edit_data.bg; auto &gen_skill = game->edit_data.gen_skill; int lev = 1; @@ -919,29 +917,6 @@ errr init_player_info_txt(FILE *fp) continue; } - /* Process 'H' for "History" */ - if (buf[0] == 'H') - { - char *zz[5]; - - /* Scan for the values */ - if (tokenize(buf + 2, 5, zz, ':', ':') != 5) return (1); - - /* Create new entry */ - hist_type hist; - hist.roll = atoi(zz[0]); - hist.chart = atoi(zz[1]); - hist.next = atoi(zz[2]); - hist.bonus = atoi(zz[3]); - hist.info = my_strdup(zz[4]); - - /* Append */ - bg.emplace_back(hist); - - /* Next... */ - continue; - } - /* Process 'G:k' for "General skills" */ if ((buf[0] == 'G') && (buf[2] == 'k')) { @@ -1107,16 +1082,15 @@ errr init_player_info_txt(FILE *fp) /* Process 'P' for "xtra" */ if ((buf[0] == 'R') && (buf[2] == 'P')) { - int s[4]; + int s[3]; /* Scan for the values */ - if (4 != sscanf(buf + 4, "%d:%d:%d:%d", - &s[0], &s[1], &s[2], &s[3])) return (1); + if (3 != sscanf(buf + 4, "%d:%d:%d", + &s[0], &s[1], &s[2])) return (1); rp_ptr->ps.mhp = s[0]; rp_ptr->ps.exp = s[1]; rp_ptr->infra = s[2]; - rp_ptr->chart = s[3]; /* Next... */ continue; -- cgit v1.2.3 From 6a35e3de332df186eab39c3b67506882409a3ca2 Mon Sep 17 00:00:00 2001 From: Bardur Arantsson Date: Tue, 2 May 2017 19:20:57 +0200 Subject: Remove redundant (void) parameters and return value casts --- src/init1.cc | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'src/init1.cc') diff --git a/src/init1.cc b/src/init1.cc index 056b5b51..e367f603 100644 --- a/src/init1.cc +++ b/src/init1.cc @@ -6910,7 +6910,7 @@ errr process_dungeon_file(cptr name, int *yval, int *xval, int ymax, int xmax, b if (buf[0] == '%') { /* Process that file if allowed */ - (void)process_dungeon_file(buf + 2, yval, xval, ymax, xmax, FALSE, full); + process_dungeon_file(buf + 2, yval, xval, ymax, xmax, FALSE, full); /* Continue */ continue; -- cgit v1.2.3