demon stealth: cloak as other race.

added a Lua test.
get_race oob fix (potential crash).
This commit is contained in:
Enno Rehling 2017-04-22 18:33:47 +02:00
parent e938350acd
commit e530543022
3 changed files with 27 additions and 9 deletions

View File

@ -404,3 +404,22 @@ function test_birthdaycake()
u:add_order("ZEIGE Geburtstagstorte")
process_orders()
end
function test_demonstealth()
local desc, r, f, u
r = region.create(0, 0, "plain")
f = faction.create("demon@eressea.de", "demon", "de")
u = unit.create(f, r, 1)
u:clear_orders()
u:add_order("TARNE Zwerg")
process_orders()
desc = u:show()
assert_not_nil(string.find(desc, "Zwerg"))
u:clear_orders()
u:add_order("TARNE Drache")
process_orders()
desc = u:show()
assert_equal(nil, string.find(desc, "Drache"))
end

View File

@ -166,7 +166,7 @@ const struct race *findrace(const char *s, const struct locale *lang)
const struct race *get_race(race_t rt) {
const char * name;
assert(rt < MAXRACES);
assert(rt>=0 && rt < MAXRACES);
name = racenames[rt];
if (!name) {
return NULL;

View File

@ -254,19 +254,18 @@ int setstealth_cmd(unit * u, struct order *ord)
NORACE
};
int i;
for (i = 0; allowed[i] != NORACE; ++i)
if (get_race(allowed[i]) == trace)
break;
for (i = 0; allowed[i] != NORACE; ++i) {
if (get_race(allowed[i]) == trace) {
u->irace = trace;
if (u_race(u)->flags & RCF_SHAPESHIFTANY && get_racename(u->attribs))
set_racename(&u->attribs, NULL);
break;
}
}
return 0;
}
/* Singdrachen koennen sich nur als Drachen tarnen */
if (u_race(u) == get_race(RC_SONGDRAGON)
else if (u_race(u) == get_race(RC_SONGDRAGON)
|| u_race(u) == get_race(RC_BIRTHDAYDRAGON)) {
if (trace == get_race(RC_SONGDRAGON) || trace == get_race(RC_FIREDRAGON)
|| trace == get_race(RC_DRAGON) || trace == get_race(RC_WYRM)) {