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/externs.h | 3 --- src/init1.cc | 56 ++++++++++-------------------------------------- src/init2.cc | 13 +---------- src/skills.cc | 35 ++++++++++++++++++------------ src/squelch/condition.cc | 4 ++-- src/types.h | 7 +++--- src/variable.cc | 3 --- 7 files changed, 39 insertions(+), 82 deletions(-) (limited to 'src') diff --git a/src/externs.h b/src/externs.h index a9230759..86e3db0f 100644 --- a/src/externs.h +++ b/src/externs.h @@ -311,10 +311,7 @@ extern header *al_head; extern char *al_name; extern artifact_select_flag *a_select_flags; -extern header *ab_head; extern ability_type *ab_info; -extern char *ab_name; -extern char *ab_text; extern header *s_head; extern skill_type *s_info; 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); } diff --git a/src/init2.cc b/src/init2.cc index 009a88d7..17576e8a 100644 --- a/src/init2.cc +++ b/src/init2.cc @@ -610,19 +610,8 @@ static errr init_ab_info(void) /* General buffer */ char buf[1024]; - - /*** Make the "header" ***/ - ab_head = make_header(max_ab_idx); - - - /*** Make the fake arrays ***/ - /* Allocate the "ab_info" array */ - ab_info = make_array(ab_head->info_num); - - /* Hack -- make "fake" arrays */ - ab_name = make_array(FAKE_NAME_SIZE); - ab_text = make_array(FAKE_TEXT_SIZE); + ab_info = make_array(max_ab_idx); /*** Load the ascii template file ***/ diff --git a/src/skills.cc b/src/skills.cc index 0d3c39a3..3ed64d17 100644 --- a/src/skills.cc +++ b/src/skills.cc @@ -827,7 +827,7 @@ static int do_cmd_activate_skill_aux() } if (next) continue; - p.push_back(std::make_tuple(ab_text + ab_info[i].action_desc, + p.push_back(std::make_tuple(ab_info[i].action_desc, ab_info[i].action_mkey)); } } @@ -1438,9 +1438,9 @@ s16b find_ability(cptr name) /* Scan ability list */ for (i = 0; i < max_ab_idx; i++) { - /* The name matches */ - if (ab_info[i].name > 0) { - if (streq(ab_info[i].name + ab_name, name)) return (i); + if (ab_info[i].name && streq(ab_info[i].name, name)) + { + return (i); } } @@ -1532,8 +1532,7 @@ static void gain_ability(int ab) static bool compare_abilities(const int ab_idx1, const int ab_idx2) { - return strcmp(ab_name + ab_info[ab_idx1].name, - ab_name + ab_info[ab_idx2].name) < 0; + return strcmp(ab_info[ab_idx1].name, ab_info[ab_idx2].name) < 0; } /* @@ -1565,7 +1564,7 @@ void dump_abilities(FILE *fff) for (int i : table) { - fprintf(fff, "\n * %s", ab_info[i].name + ab_name); + fprintf(fff, "\n * %s", ab_info[i].name); } fprintf(fff, "\n"); @@ -1590,7 +1589,7 @@ static void print_abilities(const std::vector &table, int sel, int start) c_prt((p_ptr->skill_points) ? TERM_L_BLUE : TERM_L_RED, format("Skill points left: %d", p_ptr->skill_points), 2, 0); - print_desc_aux(ab_info[table[sel]].desc + ab_text, 3, 0); + print_desc_aux(ab_info[table[sel]].desc, 3, 0); for (j = start; j < start + (hgt - 7); j++) { @@ -1620,7 +1619,7 @@ static void print_abilities(const std::vector &table, int sel, int start) end = ']'; } - c_prt(color, format("%c.%c%s", deb, end, ab_info[i].name + ab_name), + c_prt(color, format("%c.%c%s", deb, end, ab_info[i].name), j + 7 - start, 0); if (!ab_info[i].acquired) @@ -1723,7 +1722,7 @@ void do_cmd_ability() /* Contextual help */ if (c == '?') { - help_ability(ab_info[table[sel]].name + ab_name); + help_ability(ab_info[table[sel]].name); } /* Handle boundaries and scrolling */ @@ -1769,25 +1768,33 @@ void apply_level_abilities(int level) if (cp_ptr->abilities[i].level == level) { if ((level > 1) && (!ab_info[cp_ptr->abilities[i].ability].acquired)) - cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[cp_ptr->abilities[i].ability].name); + { + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_info[cp_ptr->abilities[i].ability].name); + } ab_info[cp_ptr->abilities[i].ability].acquired = TRUE; } if (spp_ptr->abilities[i].level == level) { if ((level > 1) && (!ab_info[spp_ptr->abilities[i].ability].acquired)) - cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[spp_ptr->abilities[i].ability].name); + { + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_info[spp_ptr->abilities[i].ability].name); + } ab_info[spp_ptr->abilities[i].ability].acquired = TRUE; } if (rp_ptr->abilities[i].level == level) { if ((level > 1) && (!ab_info[rp_ptr->abilities[i].ability].acquired)) - cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[rp_ptr->abilities[i].ability].name); + { + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_info[rp_ptr->abilities[i].ability].name); + } ab_info[rp_ptr->abilities[i].ability].acquired = TRUE; } if (rmp_ptr->abilities[i].level == level) { if ((level > 1) && (!ab_info[rmp_ptr->abilities[i].ability].acquired)) - cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_name + ab_info[rmp_ptr->abilities[i].ability].name); + { + cmsg_format(TERM_L_GREEN, "You have learned the ability '%s'.", ab_info[rmp_ptr->abilities[i].ability].name); + } ab_info[rmp_ptr->abilities[i].ability].acquired = TRUE; } } diff --git a/src/squelch/condition.cc b/src/squelch/condition.cc index a19391b0..97f9fac6 100644 --- a/src/squelch/condition.cc +++ b/src/squelch/condition.cc @@ -905,7 +905,7 @@ std::shared_ptr AbilityCondition::from_json(json_t *j) void AbilityCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_t bcol) const { - cptr ability_s = ab_info[m_ability_idx].name + ab_name; + cptr ability_s = ab_info[m_ability_idx].name; p->write(ecol, "You have the "); p->write(bcol, ability_s); @@ -915,7 +915,7 @@ void AbilityCondition::write_tree(TreePrinter *p, Cursor *, uint8_t ecol, uint8_ void AbilityCondition::to_json(json_t *j) const { - cptr ability_s = ab_info[m_ability_idx].name + ab_name; + cptr ability_s = ab_info[m_ability_idx].name; json_object_set_new(j, "ability", json_string(ability_s)); } diff --git a/src/types.h b/src/types.h index d475d879..e51690f3 100644 --- a/src/types.h +++ b/src/types.h @@ -2522,9 +2522,10 @@ struct timer_type typedef struct ability_type ability_type; struct ability_type { - u32b name; /* Name */ - u32b desc; /* Description */ - u32b action_desc; /* Action Description */ + const char *name; /* Name */ + char *desc; /* Description */ + + const char *action_desc; /* Action Description */ s16b action_mkey; /* Action do to */ diff --git a/src/variable.cc b/src/variable.cc index 0da55623..4b8a848b 100644 --- a/src/variable.cc +++ b/src/variable.cc @@ -662,10 +662,7 @@ dungeon_info_type *d_info; /* * Player abilities arrays */ -header *ab_head; ability_type *ab_info; -char *ab_name; -char *ab_text; /* * Player skills arrays -- cgit v1.2.3