From 8cd99bf88cd62254516285102e9a725f7203ecd4 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Fri, 18 May 2012 09:19:46 -0700 Subject: [PATCH] fallback for generating building/ship names in tests, when no translations are available --- src/gamecode/market_test.c | 8 ++++---- src/kernel/building.c | 25 +++++++++++++++++-------- src/kernel/ship.c | 14 ++++++++++++-- 3 files changed, 33 insertions(+), 14 deletions(-) diff --git a/src/gamecode/market_test.c b/src/gamecode/market_test.c index c60876995..1e7eefb8e 100644 --- a/src/gamecode/market_test.c +++ b/src/gamecode/market_test.c @@ -1,5 +1,3 @@ -#include - #include "platform.h" #include "market.h" #include "tests.h" @@ -15,6 +13,9 @@ #include +#include +#include + #include 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; diff --git a/src/kernel/building.c b/src/kernel/building.c index 1295d47b1..525bcff63 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -35,6 +35,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include +#include #include #include #include @@ -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; } diff --git a/src/kernel/ship.c b/src/kernel/ship.c index 2d15bb52c..708665e91 100644 --- a/src/kernel/ship.c +++ b/src/kernel/ship.c @@ -31,6 +31,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. /* util includes */ #include #include +#include #include #include #include @@ -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);