Merge pull request #609 from ennorehling/develop

BUG: broken ship names
This commit is contained in:
Enno Rehling 2016-11-20 15:23:55 +01:00 committed by GitHub
commit f5da163d18
15 changed files with 60 additions and 52 deletions

View file

@ -181,7 +181,7 @@ static int potion_power(unit *u, int amount) {
if (u->number % 10 > 0) ++use; if (u->number % 10 > 0) ++use;
amount = use; amount = use;
} }
/* Verfünffacht die HP von max. 10 Personen in der Einheit */ /* Verf<EFBFBD>nffacht die HP von max. 10 Personen in der Einheit */
u->hp += _min(u->number, 10 * amount) * unit_max_hp(u) * 4; u->hp += _min(u->number, 10 * amount) * unit_max_hp(u) * 4;
return amount; return amount;
} }
@ -241,8 +241,7 @@ static void init_potiondelay(attrib * a)
a->data.v = malloc(sizeof(potiondelay)); a->data.v = malloc(sizeof(potiondelay));
} }
static void free_potiondelay(attrib * a) static void free_potiondelay(attrib * a) {
{
free(a->data.v); free(a->data.v);
} }

View file

@ -1022,16 +1022,15 @@ static int armor_bonus(const race *rc) {
int natural_armor(unit * du) int natural_armor(unit * du)
{ {
const race *rc = u_race(du); const race *rc = u_race(du);
int bonus, an = rc->armor; int an;
assert(rc); assert(rc);
bonus = armor_bonus(rc); an = armor_bonus(rc);
if (bonus > 0) { if (an > 0) {
int sk = effskill(du, SK_STAMINA, 0); int sk = effskill(du, SK_STAMINA, 0);
sk /= bonus; return rc->armor + sk / an;
an += sk;
} }
return an; return rc->armor;
} }
static int rc_specialdamage(const unit *au, const unit *du, const struct weapon_type *wtype) static int rc_specialdamage(const unit *au, const unit *du, const struct weapon_type *wtype)
@ -2042,19 +2041,12 @@ int hits(troop at, troop dt, weapon * awp)
void dazzle(battle * b, troop * td) void dazzle(battle * b, troop * td)
{ {
/* Nicht kumulativ ! */ /* Nicht kumulativ ! */
if (td->fighter->person[td->index].flags & FL_DAZZLED)
return;
#ifdef TODO_RUNESWORD #ifdef TODO_RUNESWORD
if (td->fighter->weapon[WP_RUNESWORD].count > td->index) { if (td->fighter->weapon[WP_RUNESWORD].count > td->index) {
return; return;
} }
#endif #endif
if (td->fighter->person[td->index].flags & FL_COURAGE) { if (td->fighter->person[td->index].flags & (FL_COURAGE|FL_DAZZLED)) {
return;
}
if (td->fighter->person[td->index].flags & FL_DAZZLED) {
return; return;
} }
@ -2497,7 +2489,7 @@ static int loot_quota(const unit * src, const unit * dst,
{ {
if (dst && src && src->faction != dst->faction) { if (dst && src && src->faction != dst->faction) {
double divisor = config_get_flt("rules.items.loot_divisor", 1); double divisor = config_get_flt("rules.items.loot_divisor", 1);
assert(divisor == 0 || divisor >= 1); assert(divisor <= 0 || divisor >= 1);
if (divisor >= 1) { if (divisor >= 1) {
double r = n / divisor; double r = n / divisor;
int x = (int)r; int x = (int)r;

View file

@ -211,7 +211,7 @@ border_type *find_bordertype(const char *name)
{ {
border_type *bt = bordertypes; border_type *bt = bordertypes;
while (bt && strcmp(bt->__name, name)) while (bt && strcmp(bt->__name, name)!=0)
bt = bt->next; bt = bt->next;
return bt; return bt;
} }
@ -620,7 +620,6 @@ int read_borders(gamedata *data)
assert(type || !"connection type not registered"); assert(type || !"connection type not registered");
} }
READ_INT(store, &bid); READ_INT(store, &bid);
if (data->version < UIDHASH_VERSION) { if (data->version < UIDHASH_VERSION) {
int fx, fy, tx, ty; int fx, fy, tx, ty;
@ -638,10 +637,8 @@ int read_borders(gamedata *data)
from = findregionbyid(fid); from = findregionbyid(fid);
to = findregionbyid(tid); to = findregionbyid(tid);
} }
if (!to || !from) {
if (!to || !from) { if (!to || !from) {
log_error("%s connection %d has missing regions", zText, bid); log_error("%s connection %d has missing regions", zText, bid);
}
if (type->read) { if (type->read) {
// skip ahead // skip ahead
connection dummy; connection dummy;
@ -650,7 +647,7 @@ int read_borders(gamedata *data)
continue; continue;
} }
if (to == from && type && from) { if (to == from && from) {
direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS); direction_t dir = (direction_t)(rng_int() % MAXDIRECTIONS);
region *r = rconnect(from, dir); region *r = rconnect(from, dir);
log_error("[read_borders] invalid %s in %s\n", type->__name, regionname(from, NULL)); log_error("[read_borders] invalid %s in %s\n", type->__name, regionname(from, NULL));
@ -659,7 +656,7 @@ int read_borders(gamedata *data)
} }
if (type->read) { if (type->read) {
connection *b = new_border(type, from, to); connection *b = new_border(type, from, to);
nextborder--; /* new_border erhöht den Wert */ nextborder--; /* new_border erh<EFBFBD>ht den Wert */
b->id = bid; b->id = bid;
assert(bid <= nextborder); assert(bid <= nextborder);
type->read(b, data); type->read(b, data);

View file

@ -796,7 +796,7 @@ static void json_settings(cJSON *json) {
else { else {
char value[32]; char value[32];
if (child->type == cJSON_Number && child->valuedouble && child->valueint<child->valuedouble) { if (child->type == cJSON_Number && child->valuedouble && child->valueint<child->valuedouble) {
_snprintf(value, sizeof(value), "%lf", child->valuedouble); _snprintf(value, sizeof(value), "%f", child->valuedouble);
} }
else { else {
_snprintf(value, sizeof(value), "%d", child->valueint); _snprintf(value, sizeof(value), "%d", child->valueint);

View file

@ -297,10 +297,9 @@ int crew_skill(const ship *sh) {
int shipspeed(const ship * sh, const unit * u) int shipspeed(const ship * sh, const unit * u)
{ {
int k = sh->type->range;
attrib *a; attrib *a;
struct curse *c; struct curse *c;
int bonus; int k, bonus;
assert(sh); assert(sh);
if (!u) u = ship_owner(sh); if (!u) u = ship_owner(sh);
@ -310,6 +309,7 @@ int shipspeed(const ship * sh, const unit * u)
assert(sh->type->construction); assert(sh->type->construction);
assert(sh->type->construction->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */ assert(sh->type->construction->improvement == NULL); /* sonst ist construction::size nicht ship_type::maxsize */
k = sh->type->range;
if (sh->size != sh->type->construction->maxsize) if (sh->size != sh->type->construction->maxsize)
return 0; return 0;
@ -417,7 +417,7 @@ static unit * ship_owner_ex(const ship * sh, const struct faction * last_owner)
{ {
unit *u, *heir = 0; unit *u, *heir = 0;
/* Eigentümer tot oder kein Eigentümer vorhanden. Erste lebende Einheit /* Eigent<EFBFBD>mer tot oder kein Eigent<6E>mer vorhanden. Erste lebende Einheit
* nehmen. */ * nehmen. */
for (u = sh->region->units; u; u = u->next) { for (u = sh->region->units; u; u = u->next) {
if (u->ship == sh) { if (u->ship == sh) {

View file

@ -16,7 +16,7 @@
const attrib_type at_lighthouse = { const attrib_type at_lighthouse = {
"lighthouse" "lighthouse"
/* Rest ist NULL; temporäres, nicht alterndes Attribut */ /* Rest ist NULL; tempor<EFBFBD>res, nicht alterndes Attribut */
}; };
/* update_lighthouse: call this function whenever the size of a lighthouse changes /* update_lighthouse: call this function whenever the size of a lighthouse changes
@ -127,7 +127,7 @@ bool check_leuchtturm(region * r, faction * f)
c += u->number; c += u->number;
if (c > buildingcapacity(b)) if (c > buildingcapacity(b))
break; break;
if (f == NULL || u->faction == f) { if (u->faction == f) {
if (!d) if (!d)
d = distance(r, r2); d = distance(r, r2);
if (maxd < d) if (maxd < d)

View file

@ -1240,9 +1240,9 @@ static bool roadto(const region * r, direction_t dir)
if (!r || dir >= MAXDIRECTIONS || dir < 0) if (!r || dir >= MAXDIRECTIONS || dir < 0)
return false; return false;
r2 = rconnect(r, dir); r2 = rconnect(r, dir);
if (r == NULL || r2 == NULL) if (!r2) {
return false; return false;
}
if (r->attribs || r2->attribs) { if (r->attribs || r2->attribs) {
const curse_type *roads_ct = ct_find("magicstreet"); const curse_type *roads_ct = ct_find("magicstreet");
if (roads_ct != NULL) { if (roads_ct != NULL) {

View file

@ -273,10 +273,10 @@ void setup_drift (struct drift_fixture *fix) {
fix->st_boat->cabins = 20000; fix->st_boat->cabins = 20000;
fix->u = test_create_unit(fix->f = test_create_faction(0), fix->r=findregion(-1,0)); fix->u = test_create_unit(fix->f = test_create_faction(0), fix->r=findregion(-1,0));
assert(fix->r); assert(fix->r && fix->u && fix->f);
set_level(fix->u, SK_SAILING, fix->st_boat->sumskill); set_level(fix->u, SK_SAILING, fix->st_boat->sumskill);
u_set_ship(fix->u, fix->sh = test_create_ship(fix->u->region, fix->st_boat)); u_set_ship(fix->u, fix->sh = test_create_ship(fix->u->region, fix->st_boat));
assert(fix->f && fix->u && fix->sh); assert(fix->sh);
} }
static void test_ship_no_overload(CuTest *tc) { static void test_ship_no_overload(CuTest *tc) {

View file

@ -83,12 +83,12 @@ static void test_piracy_cmd(CuTest * tc) {
t_ocean = get_or_create_terrain("ocean"); t_ocean = get_or_create_terrain("ocean");
st_boat = st_get_or_create("boat"); st_boat = st_get_or_create("boat");
u2 = test_create_unit(test_create_faction(0), test_create_region(1, 0, t_ocean)); u2 = test_create_unit(test_create_faction(0), test_create_region(1, 0, t_ocean));
u_set_ship(u2, test_create_ship(u2->region, st_boat));
assert(u2); assert(u2);
u_set_ship(u2, test_create_ship(u2->region, st_boat));
u = test_create_unit(f = test_create_faction(0), r = test_create_region(0, 0, t_ocean)); u = test_create_unit(f = test_create_faction(0), r = test_create_region(0, 0, t_ocean));
assert(f && u);
set_level(u, SK_SAILING, st_boat->sumskill); set_level(u, SK_SAILING, st_boat->sumskill);
u_set_ship(u, test_create_ship(u->region, st_boat)); u_set_ship(u, test_create_ship(u->region, st_boat));
assert(f && u);
f->locale = get_or_create_locale("de"); f->locale = get_or_create_locale("de");
u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(u2->faction->no)); u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(u2->faction->no));

View file

@ -489,13 +489,14 @@ size_t size)
building *b; building *b;
bool isbattle = (bool)(mode == seen_battle); bool isbattle = (bool)(mode == seen_battle);
item *itm, *show = NULL; item *itm, *show = NULL;
faction *fv = visible_faction(f, u); faction *fv;
char *bufp = buf; char *bufp = buf;
int result = 0; int result = 0;
item results[MAX_INVENTORY]; item results[MAX_INVENTORY];
assert(f);
bufp = STRLCPY(bufp, unitname(u), size); bufp = STRLCPY(bufp, unitname(u), size);
fv = visible_faction(f, u);
if (!isbattle) { if (!isbattle) {
attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction); attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
if (u->faction == f) { if (u->faction == f) {
@ -770,7 +771,7 @@ size_t size)
} }
dh = 0; dh = 0;
if (!getarnt && f) { if (!getarnt) {
if (alliedfaction(rplane(u->region), f, fv, HELP_ALL)) { if (alliedfaction(rplane(u->region), f, fv, HELP_ALL)) {
dh = 1; dh = 1;
} }

View file

@ -3237,8 +3237,7 @@ static int sp_magicboost(castorder * co)
} }
effect = 6; effect = 6;
c = create_curse(mage, &mage->attribs, ct_magicboost, power, 10, effect, 1); create_curse(mage, &mage->attribs, ct_magicboost, power, 10, effect, 1);
/* one aura boost with 200% aura now: */ /* one aura boost with 200% aura now: */
effect = 200; effect = 200;
c = create_curse(mage, &mage->attribs, ct_auraboost, power, 4, effect, 1); c = create_curse(mage, &mage->attribs, ct_auraboost, power, 4, effect, 1);
@ -4031,7 +4030,7 @@ static int sp_recruit(castorder * co)
* ein mehrfaches von Stufe 1, denn in beiden Faellen gibt es nur 1 * ein mehrfaches von Stufe 1, denn in beiden Faellen gibt es nur 1
* Bauer, nur die Kosten steigen. */ * Bauer, nur die Kosten steigen. */
n = (pow(force, 1.6) * 100) / f->race->recruitcost; n = (pow(force, 1.6) * 100) / f->race->recruitcost;
if (rc->recruit_multi != 0) { if (rc->recruit_multi > 0) {
double multp = (double)maxp / rc->recruit_multi; double multp = (double)maxp / rc->recruit_multi;
n = _min(multp, n); n = _min(multp, n);
n = _max(n, 1); n = _max(n, 1);

View file

@ -185,9 +185,7 @@ plane *get_astralplane(void)
if (!rule_astralplane) { if (!rule_astralplane) {
return NULL; return NULL;
} }
if (!astralspace) {
astralspace = getplanebyname("Astralraum"); astralspace = getplanebyname("Astralraum");
}
if (!astralspace) { if (!astralspace) {
astralspace = create_new_plane(1, "Astralraum", astralspace = create_new_plane(1, "Astralraum",
TE_CENTER_X - 500, TE_CENTER_X + 500, TE_CENTER_X - 500, TE_CENTER_X + 500,

View file

@ -81,10 +81,11 @@ void test_upkeep_from_pool(CuTest * tc)
i_silver = it_find("money"); i_silver = it_find("money");
assert(i_silver); assert(i_silver);
r = findregion(0, 0); r = findregion(0, 0);
assert(r);
u1 = test_create_unit(test_create_faction(test_create_race("human")), r); u1 = test_create_unit(test_create_faction(test_create_race("human")), r);
assert(u1); assert(u1);
u2 = test_create_unit(u1->faction, r); u2 = test_create_unit(u1->faction, r);
assert(r && u1 && u2); assert(u2);
config_set("rules.food.flags", "0"); config_set("rules.food.flags", "0");
i_change(&u1->items, i_silver, 30); i_change(&u1->items, i_silver, 30);

View file

@ -40,13 +40,20 @@ int unicode_utf8_trim(utf8_t *buf)
size_t size = 1; size_t size = 1;
wint_t wc = *ip; wint_t wc = *ip;
if (wc & 0x80) { if (wc & 0x80) {
ucs4_t ucs; ucs4_t ucs = 0;
if (ip[1]) {
int ret = unicode_utf8_to_ucs4(&ucs, ip, &size); int ret = unicode_utf8_to_ucs4(&ucs, ip, &size);
if (ret != 0) { if (ret != 0) {
return ret; return ret;
} }
wc = (wint_t)ucs; wc = (wint_t)ucs;
} }
else {
wc = *op = '?';
size = 1;
++result;
}
}
if (op == buf && iswspace(wc)) { if (op == buf && iswspace(wc)) {
++result; ++result;
} }

View file

@ -28,6 +28,10 @@ static void test_unicode_trim(CuTest * tc)
strcpy(buffer, " \t Hello Word"); strcpy(buffer, " \t Hello Word");
CuAssertIntEquals(tc, 3, unicode_utf8_trim(buffer)); CuAssertIntEquals(tc, 3, unicode_utf8_trim(buffer));
CuAssertStrEquals(tc, "Hello Word", buffer); CuAssertStrEquals(tc, "Hello Word", buffer);
buffer[9] = (char)0xc3;
CuAssertIntEquals(tc, 1, unicode_utf8_trim(buffer));
CuAssertStrEquals(tc, "Hello Wor?", buffer);
} }
static void test_unicode_tolower(CuTest * tc) static void test_unicode_tolower(CuTest * tc)
@ -87,11 +91,21 @@ static void test_unicode_utf8_to_other(CuTest *tc)
CuAssertIntEquals(tc, 'l', ch); CuAssertIntEquals(tc, 'l', ch);
} }
static void test_unicode_utf8_to_ucs(CuTest *tc) {
ucs4_t ucs;
size_t sz;
CuAssertIntEquals(tc, 0, unicode_utf8_to_ucs4(&ucs, "a", &sz));
CuAssertIntEquals(tc, 'a', ucs);
CuAssertIntEquals(tc, 1, sz);
}
CuSuite *get_unicode_suite(void) CuSuite *get_unicode_suite(void)
{ {
CuSuite *suite = CuSuiteNew(); CuSuite *suite = CuSuiteNew();
SUITE_ADD_TEST(suite, test_unicode_tolower); SUITE_ADD_TEST(suite, test_unicode_tolower);
SUITE_ADD_TEST(suite, test_unicode_trim); SUITE_ADD_TEST(suite, test_unicode_trim);
SUITE_ADD_TEST(suite, test_unicode_utf8_to_other); SUITE_ADD_TEST(suite, test_unicode_utf8_to_other);
SUITE_ADD_TEST(suite, test_unicode_utf8_to_ucs);
return suite; return suite;
} }