fallback for generating building/ship names in tests, when no translations are available

This commit is contained in:
Enno Rehling 2012-05-18 09:19:46 -07:00
parent ad05ec8c53
commit 8cd99bf88c
3 changed files with 33 additions and 14 deletions

View file

@ -1,5 +1,3 @@
#include <cutest/CuTest.h>
#include "platform.h"
#include "market.h"
#include "tests.h"
@ -15,6 +13,9 @@
#include <util/language.h>
#include <cutest/CuTest.h>
#include <tests.h>
#include <stdlib.h>
static void market_curse(CuTest * tc)
@ -33,7 +34,6 @@ static void market_curse(CuTest * tc)
luxury_type *lux = new_luxurytype(ltype, 0);
building_type *btype;
race *rc = rc_add(rc_new("human"));
struct locale *lang = make_locale("en");
free_gamedata();
@ -55,7 +55,7 @@ static void market_curse(CuTest * tc)
}
}
r = findregion(1, 1);
b = new_building(btype, r, lang);
b = test_create_building(r, btype);
b->flags |= BLD_WORKING;
b->size = b->type->maxsize;

View file

@ -35,6 +35,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/bsdstring.h>
#include <util/event.h>
#include <util/functions.h>
#include <util/language.h>
@ -452,6 +453,8 @@ building *new_building(const struct building_type * btype, region * r,
building *b = (building *) calloc(1, sizeof(building));
static boolean init_lighthouse = false;
static const struct building_type *bt_lighthouse = 0;
const char *bname = 0;
char buffer[32];
if (!init_lighthouse) {
bt_lighthouse = bt_find("lighthouse");
@ -471,15 +474,21 @@ building *new_building(const struct building_type * btype, region * r,
if (b->type == bt_lighthouse) {
r->flags |= RF_LIGHTHOUSE;
}
{
const char *bname;
if (b->type->name == NULL) {
bname = LOC(lang, btype->_name);
} else {
bname = LOC(lang, buildingtype(btype, b, 0));
}
b->name = strdup(bname);
if (b->type->name) {
bname = LOC(lang, buildingtype(btype, b, 0));
}
if (!bname) {
bname = LOC(lang, btype->_name);
}
if (!bname) {
bname = LOC(lang, parameters[P_GEBAEUDE]);
}
if (!bname) {
bname = parameters[P_GEBAEUDE];
}
assert(bname);
slprintf(buffer, sizeof(buffer), "%s %s", bname, buildingid(b));
b->name = strdup(bname);
return b;
}

View file

@ -31,6 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* util includes */
#include <util/attrib.h>
#include <util/base36.h>
#include <util/bsdstring.h>
#include <util/event.h>
#include <util/language.h>
#include <util/lists.h>
@ -165,8 +166,9 @@ static ship *deleted_ships;
ship *new_ship(const ship_type * stype, region * r, const struct locale *lang)
{
static char buffer[7 + IDSIZE + 1];
static char buffer[32];
ship *sh = (ship *) calloc(1, sizeof(ship));
const char *sname = 0;
assert(stype);
assert(r);
@ -175,7 +177,15 @@ ship *new_ship(const ship_type * stype, region * r, const struct locale *lang)
sh->type = stype;
sh->region = r;
sprintf(buffer, "%s %s", LOC(lang, stype->name[0]), shipid(sh));
sname = LOC(lang, stype->name[0]);
if (!sname) {
sname = LOC(lang, parameters[P_SHIP]);
if (!sname) {
sname = parameters[P_SHIP];
}
}
assert(sname);
slprintf(buffer, sizeof(buffer), "%s %s", sname, shipid(sh));
sh->name = strdup(buffer);
shash(sh);
addlist(&r->ships, sh);