Fixing bug 1802 again, CR contains no Monster names.

This commit is contained in:
Enno Rehling 2015-02-11 07:55:35 +01:00
parent 2481f46199
commit 83e610ee03
12 changed files with 37 additions and 35 deletions

View File

@ -167,7 +167,7 @@ static int tolua_unit_set_group(lua_State * L)
static int tolua_unit_get_name(lua_State * L)
{
unit *self = (unit *)tolua_tousertype(L, 1, 0);
tolua_pushstring(L, self->name);
tolua_pushstring(L, unit_getname(self));
return 1;
}

View File

@ -758,7 +758,7 @@ static void cr_output_unit(FILE * F, const region * r, const faction * f,
assert(u && u->number);
fprintf(F, "EINHEIT %d\n", u->no);
fprintf(F, "\"%s\";Name\n", u->name);
fprintf(F, "\"%s\";Name\n", unit_getname(u));
str = u_description(u, f->locale);
if (str) {
fprintf(F, "\"%s\";Beschr\n", str);

View File

@ -423,7 +423,7 @@ static void paint_info_region(window * wnd, const state * st)
wattroff(win, A_BOLD | COLOR_PAIR(COLOR_YELLOW));
for (u = r->units; u && line < maxline; u = u->next) {
mvwprintw(win, line, 1, "%.4s ", itoa36(u->no));
mvwaddnstr(win, line++, 6, (char *)u->name, size - 5);
mvwaddnstr(win, line++, 6, unit_getname(u), size - 5);
}
}
}

View File

@ -618,7 +618,7 @@ unit *read_unit(struct gamedata *data)
}
READ_STR(data->store, obuf, sizeof(obuf));
u->name = _strdup(obuf);
u->_name = _strdup(obuf);
if (lomem) {
READ_STR(data->store, NULL, 0);
}
@ -754,8 +754,8 @@ void write_unit(struct gamedata *data, const unit * u)
write_unit_reference(u, data->store);
write_faction_reference(u->faction, data->store);
WRITE_STR(data->store, (const char *)u->name);
WRITE_STR(data->store, u->display ? (const char *)u->display : "");
WRITE_STR(data->store, u->_name);
WRITE_STR(data->store, u->display ? u->display : "");
WRITE_INT(data->store, u->number);
WRITE_INT(data->store, u->age);
WRITE_TOK(data->store, u_race(u)->_name);
@ -1600,7 +1600,7 @@ int readgame(const char *filename, int backup)
sc_mage *mage;
if (gdata.version < AUTO_RACENAME_VERSION) {
if (u->name && fval(u->faction, FFL_NPC)) {
if (u->_name && fval(u->faction, FFL_NPC)) {
if (unit_name_equals_race(u)) {
unit_setname(u, NULL);
}

View File

@ -1430,7 +1430,7 @@ int invisible(const unit * target, const unit * viewer)
*/
void free_unit(unit * u)
{
free(u->name);
free(u->_name);
free(u->display);
free_order(u->thisorder);
free_orders(&u->orders);
@ -1542,7 +1542,7 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace,
name_unit(u);
}
else {
u->name = _strdup(dname);
u->_name = _strdup(dname);
}
if (creator) {
@ -1633,16 +1633,21 @@ int countheroes(const struct faction *f)
const char *unit_getname(const unit * u)
{
return (const char *)u->name;
if (!u->_name) {
const struct locale * lang = u->faction ? u->faction->locale : default_locale;
const char *rcname = rc_name_s(u->_race, u->number == 1 ? NAME_SINGULAR : NAME_PLURAL);
return LOC(lang, rcname);
}
return u->_name;
}
void unit_setname(unit * u, const char *name)
{
free(u->name);
free(u->_name);
if (name)
u->name = _strdup(name);
u->_name = _strdup(name);
else
u->name = NULL;
u->_name = NULL;
}
const char *unit_getinfo(const unit * u)
@ -1880,14 +1885,8 @@ static int nextbuf = 0;
char *write_unitname(const unit * u, char *buffer, size_t size)
{
if (u->name) {
slprintf(buffer, size, "%s (%s)", u->name, itoa36(u->no));
}
else {
const struct locale * lang = u->faction ? u->faction->locale : default_locale;
const char * name = rc_name_s(u->_race, u->number == 1 ? NAME_SINGULAR : NAME_PLURAL);
slprintf(buffer, size, "%s (%s)", LOC(lang, name), itoa36(u->no));
}
const char * name = unit_getname(u);
slprintf(buffer, size, "%s (%s)", name, itoa36(u->no));
buffer[size - 1] = 0;
return buffer;
}
@ -1899,14 +1898,14 @@ const char *unitname(const unit * u)
}
bool unit_name_equals_race(const unit *u) {
if (u->name) {
if (u->_name) {
char sing[32], plur[32];
const struct locale *lang = u->faction->locale;
rc_name(u->_race, NAME_SINGULAR, sing, sizeof(sing));
rc_name(u->_race, NAME_PLURAL, plur, sizeof(plur));
if (strcmp(u->name, sing) == 0 || strcmp(u->name, plur) == 0 ||
strcmp(u->name, LOC(lang, sing)) == 0 ||
strcmp(u->name, LOC(lang, plur)) == 0) {
if (strcmp(u->_name, sing) == 0 || strcmp(u->_name, plur) == 0 ||
strcmp(u->_name, LOC(lang, sing)) == 0 ||
strcmp(u->_name, LOC(lang, plur)) == 0) {
return true;
}
}

View File

@ -84,7 +84,7 @@ extern "C" {
struct region *region;
int no;
int hp;
char *name;
char *_name;
char *display;
struct faction *faction;
struct building *building;

View File

@ -155,10 +155,12 @@ static void test_unit_name_from_race(CuTest *tc) {
_snprintf(name, sizeof(name), "Mensch (%s)", itoa36(u->no));
CuAssertStrEquals(tc, name, unitname(u));
CuAssertStrEquals(tc, "Mensch", unit_getname(u));
u->number = 2;
_snprintf(name, sizeof(name), "Menschen (%s)", itoa36(u->no));
CuAssertStrEquals(tc, name, unitname(u));
CuAssertStrEquals(tc, "Menschen", unit_getname(u));
test_cleanup();
}

View File

@ -1835,9 +1835,10 @@ int name_cmd(struct unit *u, struct order *ord)
}
else {
const char *udefault = LOC(u2->faction->locale, "unitdefault");
const char *uname = unit_getname(u2);
size_t udlen = strlen(udefault);
size_t unlen = strlen(u2->name);
if (unlen >= udlen && strncmp(u2->name, udefault, udlen) != 0) {
size_t unlen = strlen(uname);
if (unlen >= udlen && strncmp(uname, udefault, udlen) != 0) {
cmistake(u2, ord, 244, MSG_EVENT);
break;
}
@ -1850,10 +1851,10 @@ int name_cmd(struct unit *u, struct order *ord)
ADDMSG(&u2->faction->msgs, msg_message("renamed_notseen",
"renamed region", u2, r));
}
s = &u2->name;
s = &u2->_name;
}
else {
s = &u->name;
s = &u->_name;
}
break;

View File

@ -1589,7 +1589,7 @@ report_template(const char *filename, report_context * ctx, const char *charset)
size = sizeof(buf) - 1;
bytes = _snprintf(bufp, size, "%s %s; %s [%d,%d$",
LOC(u->faction->locale, parameters[P_UNIT]),
unitid(u), u->name, u->number, get_money(u));
unitid(u), unit_getname(u), u->number, get_money(u));
if (wrptr(&bufp, &size, bytes) != 0)
WARN_STATIC_BUFFER();
if (u->building && building_owner(u->building) == u) {

View File

@ -2074,7 +2074,7 @@ static void eval_unitname(struct opstack **stack, const void *userdata)
{ /* unit -> string */
const struct faction *f = (const struct faction *)userdata;
const struct unit *u = (const struct unit *)opop(stack).v;
const char *c = u ? u->name : LOC(f->locale, "an_unknown_unit");
const char *c = u ? unit_getname(u) : LOC(f->locale, "an_unknown_unit");
size_t len = strlen(c);
variant var;
@ -2086,7 +2086,7 @@ static void eval_unitid(struct opstack **stack, const void *userdata)
{ /* unit -> int */
const struct faction *f = (const struct faction *)userdata;
const struct unit *u = (const struct unit *)opop(stack).v;
const char *c = u ? u->name : LOC(f->locale, "an_unknown_unit");
const char *c = u ? unit_getname(u) : LOC(f->locale, "an_unknown_unit");
size_t len = strlen(c);
variant var;

View File

@ -1748,7 +1748,7 @@ int sp_undeadhero(struct castorder * co)
if (j > 0) {
item **ilist;
unit *u =
create_unit(r, mage->faction, 0, get_race(RC_UNDEAD), 0, du->name,
create_unit(r, mage->faction, 0, get_race(RC_UNDEAD), 0, du->_name,
du);
/* new units gets some stats from old unit */

View File

@ -240,7 +240,7 @@ const message_type *register_msg(const char *type, int n_param, ...) {
void assert_messages(struct CuTest * tc, struct mlist *msglist, const message_type **types,
int num_msgs, bool exact_match, ...) {
va_list args;
int found, argc = -1;
int found = 0, argc = -1;
struct message *msg;
bool match = true;