forked from github/server
Merge pull request #813 from ennorehling/develop
Monster AI changes, HELFE Refacoring
This commit is contained in:
commit
485dacc25a
78 changed files with 596 additions and 530 deletions
clibs
scripts
src
alchemy.calchemy.test.cautomate.cbattle.cbattle.hbattle.test.cbind_faction.ceconomy.test.cgive.test.cgmtool.cguard.test.cjson.test.c
kernel
alliance.test.cally.cally.test.cattrib.test.cbuild.cbuild.test.cbuilding.ccommand.test.c
laws.claws.test.clistbox.cmagic.cmagic.test.cmain.cdb
faction.cfaction.hfaction.test.cgroup.test.citem.citem.test.cmessages.test.corder.test.cplane.cplane.test.cregion.cregion.test.csave.csave.test.cship.test.cspell.test.cspellbook.test.ctypes.hunit.test.cmodules
monsters.cmonsters.test.cmove.test.corderdb.cpiracy.test.cprefix.test.creport.creports.test.cspells.cspells
spy.test.cteleport.ctest_eressea.ctests.ctests.test.cutil
tests
vs2015-build.bat
2
clibs
2
clibs
|
@ -1 +1 @@
|
|||
Subproject commit d86c8525489d7f11b7ba13e101bb59ecf160b871
|
||||
Subproject commit ed5c4fee3afbc3d8be79d64857f30702aed522f8
|
|
@ -1,3 +1,4 @@
|
|||
-- Weltentor portal module
|
||||
local tunnels = {}
|
||||
|
||||
local buildings = {}
|
||||
|
@ -24,25 +25,15 @@ local function get_target(param)
|
|||
end
|
||||
|
||||
local function tunnel_action(b, param)
|
||||
local r = nil
|
||||
if tonumber(param)~=nil then
|
||||
r = get_region_by_id(tonumber(param))
|
||||
end
|
||||
local units = tunnel_travelers(b)
|
||||
if units~=nil then
|
||||
local rto = get_target(param)
|
||||
if rto and units then
|
||||
eressea.log.debug("Tunnel from " .. tostring(b) .. " [" .. param .. "]")
|
||||
for key, u in pairs(units) do
|
||||
local rto = r
|
||||
if r==nil then
|
||||
rto = get_target(param)
|
||||
end
|
||||
if rto~=nil then
|
||||
u.region = rto
|
||||
eressea.log.debug("teleported " .. tostring(u) .. " to " .. tostring(rto))
|
||||
end
|
||||
end
|
||||
end
|
||||
return 1 -- return 0 to destroy
|
||||
end
|
||||
|
||||
function tunnels.init()
|
||||
|
|
|
@ -34,22 +34,18 @@ function test_build_watch()
|
|||
local u = unit.create(f, r, 1)
|
||||
|
||||
u.number = 20
|
||||
u:add_item("log", 20)
|
||||
u:add_item("log", 30)
|
||||
u.id = 42
|
||||
|
||||
u:set_skill("building", 1)
|
||||
u:add_order("MACHE Wache")
|
||||
process_orders()
|
||||
assert_not_nil(u.building)
|
||||
if 5 ~= u.building.size then
|
||||
-- debug logging to find intermittent errors
|
||||
for k,v in ipairs(f.messages) do
|
||||
print(v)
|
||||
end
|
||||
end
|
||||
-- stage two needs skill 2, this unit can only build a first stage:
|
||||
assert_equal(5, u.building.size)
|
||||
|
||||
u:set_skill("building", 2)
|
||||
u:clear_orders()
|
||||
u:add_order("MACHE Wache " .. itoa36(u.building.id))
|
||||
process_orders()
|
||||
assert_not_nil(u.building)
|
||||
|
|
|
@ -1,52 +0,0 @@
|
|||
-- create a fixed path to a specific region
|
||||
local function create_path(from, to)
|
||||
local param = tostring(to.uid)
|
||||
local b = building.create(from, "portal")
|
||||
b.name = "Weltentor"
|
||||
b.size = 1
|
||||
b:add_action("tunnel_action", param)
|
||||
end
|
||||
|
||||
-- create a wonky tunnel wth more than one exit
|
||||
local function create_tunnel(from, param)
|
||||
local b = building.create(from, "portal")
|
||||
b.name = "Weltentor"
|
||||
b.size = 1
|
||||
b:add_action("tunnel_action", param)
|
||||
end
|
||||
|
||||
-- make a tunnel from the cursor to the first selected region
|
||||
function mktunnel()
|
||||
local from = gmtool.get_cursor()
|
||||
local to = gmtool.get_selection()()
|
||||
if to~=nil then
|
||||
region.create(from.x, from.y, "glacier")
|
||||
create_tunnel(from, to)
|
||||
gmtool.select(to, 0)
|
||||
gmtool.highlight(to, 1)
|
||||
end
|
||||
end
|
||||
|
||||
-- turn all selected regions into targets for a wonky tunnel ("tnnL")
|
||||
function mkanchors()
|
||||
for r in gmtool.get_selection() do
|
||||
if not r:get_key("tnnL") then
|
||||
r:set_key("tnnL", true)
|
||||
if r:get_flag(0) then
|
||||
-- RF_CHAOTIC gets removed
|
||||
r:set_flag(0, false)
|
||||
end
|
||||
r:set_resource("peasant", r:get_resource("peasant") + 1)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
-- region.create and prepare all hell-regions to become wonky gates
|
||||
function mkgates()
|
||||
for r in regions() do
|
||||
if r.plane_id==0 and r.terrain=="hell" then
|
||||
create_tunnel(r, "tnnL")
|
||||
region.create(r.x, r.y, "glacier")
|
||||
end
|
||||
end
|
||||
end
|
|
@ -66,7 +66,7 @@ void new_potiontype(item_type * itype, int level)
|
|||
{
|
||||
potion_type *ptype;
|
||||
|
||||
ptype = (potion_type *)calloc(sizeof(potion_type), 1);
|
||||
ptype = (potion_type *)calloc(1, sizeof(potion_type));
|
||||
itype->flags |= ITF_POTION;
|
||||
ptype->itype = itype;
|
||||
ptype->level = level;
|
||||
|
@ -181,7 +181,7 @@ int use_potion(unit * u, const item_type * itype, int amount, struct order *ord)
|
|||
|
||||
static void a_initeffect(variant *var)
|
||||
{
|
||||
var->v = calloc(sizeof(effect_data), 1);
|
||||
var->v = calloc(1, sizeof(effect_data));
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
|
@ -45,16 +45,16 @@ static void test_herbsearch(CuTest * tc)
|
|||
CuAssertPtrEquals(tc, u2, is_guarded(r, u));
|
||||
herbsearch(u, INT_MAX);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error70"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error59"));
|
||||
test_clear_messages(f);
|
||||
|
||||
setguard(u2, false);
|
||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u));
|
||||
CuAssertPtrEquals(tc, 0, (void *)rherbtype(r));
|
||||
CuAssertPtrEquals(tc, NULL, is_guarded(r, u));
|
||||
CuAssertPtrEquals(tc, NULL, (void *)rherbtype(r));
|
||||
herbsearch(u, INT_MAX);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error108"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error70"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error59"));
|
||||
test_clear_messages(f);
|
||||
|
||||
rsetherbtype(r, itype);
|
||||
|
@ -62,9 +62,9 @@ static void test_herbsearch(CuTest * tc)
|
|||
CuAssertIntEquals(tc, 0, rherbs(r));
|
||||
herbsearch(u, INT_MAX);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "researchherb_none"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error108"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error108"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error70"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error59"));
|
||||
test_clear_messages(f);
|
||||
|
||||
rsetherbs(r, 100);
|
||||
|
@ -73,10 +73,10 @@ static void test_herbsearch(CuTest * tc)
|
|||
CuAssertIntEquals(tc, 99, rherbs(r));
|
||||
CuAssertIntEquals(tc, 1, i_get(u->items, itype));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "herbfound"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "researchherb_none"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error108"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error70"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error59"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "researchherb_none"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error108"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error70"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error59"));
|
||||
test_clear_messages(f);
|
||||
|
||||
test_teardown();
|
||||
|
|
|
@ -36,20 +36,22 @@ int autostudy_init(scholar scholars[], int max_scholars, region *r)
|
|||
for (u = r->units; u; u = u->next) {
|
||||
keyword_t kwd = getkeyword(u->thisorder);
|
||||
if (kwd == K_AUTOSTUDY) {
|
||||
if (long_order_allowed(u) && unit_can_study(u)) {
|
||||
scholar * st = scholars + nscholars;
|
||||
init_order(u->thisorder, u->faction->locale);
|
||||
st->sk = getskill(u->faction->locale);
|
||||
st->level = effskill_study(u, st->sk);
|
||||
st->learn = 0;
|
||||
st->u = u;
|
||||
if (++nscholars == max_scholars) {
|
||||
log_fatal("you must increase MAXSCHOLARS");
|
||||
if (long_order_allowed(u)) {
|
||||
if (unit_can_study(u)) {
|
||||
scholar * st = scholars + nscholars;
|
||||
init_order(u->thisorder, u->faction->locale);
|
||||
st->sk = getskill(u->faction->locale);
|
||||
st->level = effskill_study(u, st->sk);
|
||||
st->learn = 0;
|
||||
st->u = u;
|
||||
if (++nscholars == max_scholars) {
|
||||
log_fatal("you must increase MAXSCHOLARS");
|
||||
}
|
||||
}
|
||||
else {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_race_nolearn", "race",
|
||||
u_race(u)));
|
||||
}
|
||||
}
|
||||
else {
|
||||
ADDMSG(&u->faction->msgs, msg_feedback(u, u->thisorder, "error_race_nolearn", "race",
|
||||
u_race(u)));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
18
src/battle.c
18
src/battle.c
|
@ -1138,7 +1138,7 @@ static void demon_dazzle(fighter *af, troop dt) {
|
|||
if (u_race(af->unit) == get_race(RC_DAEMON)) {
|
||||
if (!(df->person[dt.index].flags & (FL_COURAGE | FL_DAZZLED))) {
|
||||
df->person[dt.index].flags |= FL_DAZZLED;
|
||||
df->person[dt.index].defence--;
|
||||
df->person[dt.index].defense--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1191,7 +1191,7 @@ static void destroy_items(troop dt) {
|
|||
|
||||
}
|
||||
|
||||
static void calculate_defence_type(troop dt, troop at, int type, bool missile,
|
||||
static void calculate_defense_type(troop dt, troop at, int type, bool missile,
|
||||
const weapon_type **dwtype, int *defskill) {
|
||||
const weapon *weapon;
|
||||
weapon = select_weapon(dt, false, true); /* missile=true to get the unmodified best weapon she has */
|
||||
|
@ -1320,7 +1320,7 @@ terminate(troop dt, troop at, int type, const char *damage_formula, bool missile
|
|||
++at.fighter->hits;
|
||||
|
||||
calculate_attack_type(at, dt, type, missile, &awtype, &attskill, &magic);
|
||||
calculate_defence_type(at, dt, type, missile, &awtype, &attskill);
|
||||
calculate_defense_type(at, dt, type, missile, &awtype, &attskill);
|
||||
|
||||
if (is_riding(at) && (awtype == NULL || (fval(awtype, WTF_HORSEBONUS)
|
||||
&& !fval(awtype, WTF_MISSILE)))) {
|
||||
|
@ -1946,7 +1946,7 @@ int skilldiff(troop at, troop dt, int dist)
|
|||
rc_goblin = get_race(RC_GOBLIN);
|
||||
}
|
||||
skdiff += af->person[at.index].attack;
|
||||
skdiff -= df->person[dt.index].defence;
|
||||
skdiff -= df->person[dt.index].defense;
|
||||
|
||||
if (df->person[dt.index].flags & FL_SLEEPING)
|
||||
skdiff += 2;
|
||||
|
@ -2075,7 +2075,7 @@ void dazzle(battle * b, troop * td)
|
|||
}
|
||||
|
||||
td->fighter->person[td->index].flags |= FL_DAZZLED;
|
||||
td->fighter->person[td->index].defence--;
|
||||
td->fighter->person[td->index].defense--;
|
||||
}
|
||||
|
||||
void damage_building(battle * b, building * bldg, int damage_abs)
|
||||
|
@ -2241,7 +2241,7 @@ static void attack(battle * b, troop ta, const att * a, int numattack)
|
|||
td.fighter->person[td.index].attack -= 1;
|
||||
}
|
||||
else {
|
||||
td.fighter->person[td.index].defence -= 1;
|
||||
td.fighter->person[td.index].defense -= 1;
|
||||
}
|
||||
c--;
|
||||
}
|
||||
|
@ -3184,7 +3184,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
|||
strongmen = trollbelts(u);
|
||||
if (strongmen > fig->unit->number) strongmen = fig->unit->number;
|
||||
|
||||
/* Hitpoints, Attack- und Defence-Boni f<>r alle Personen */
|
||||
/* Hitpoints, Attack- und Defense-Boni fuer alle Personen */
|
||||
for (i = 0; i < fig->alive; i++) {
|
||||
assert(i < fig->unit->number);
|
||||
fig->person[i].hp = h;
|
||||
|
@ -3226,7 +3226,7 @@ fighter *make_fighter(battle * b, unit * u, side * s1, bool attack)
|
|||
assert(w != WMAX);
|
||||
}
|
||||
assert(w >= 0);
|
||||
fig->weapons = (weapon *)calloc(sizeof(weapon), (size_t)(w + 1));
|
||||
fig->weapons = (weapon *)calloc((size_t)(w + 1), sizeof(weapon));
|
||||
memcpy(fig->weapons, weapons, (size_t)w * sizeof(weapon));
|
||||
|
||||
for (i = 0; i != w; ++i) {
|
||||
|
@ -3452,7 +3452,7 @@ battle *make_battle(region * r)
|
|||
break;
|
||||
}
|
||||
if (!bf) {
|
||||
bf = (bfaction *)calloc(sizeof(bfaction), 1);
|
||||
bf = (bfaction *)calloc(1, sizeof(bfaction));
|
||||
++b->nfactions;
|
||||
bf->faction = u->faction;
|
||||
bf->next = b->factions;
|
||||
|
|
|
@ -173,7 +173,7 @@ extern "C" {
|
|||
struct person {
|
||||
int hp; /* Trefferpunkte der Personen */
|
||||
int attack;
|
||||
int defence;
|
||||
int defense;
|
||||
int damage;
|
||||
int flags;
|
||||
int speed;
|
||||
|
|
|
@ -78,7 +78,7 @@ static void test_make_fighter(CuTest * tc)
|
|||
af = make_fighter(b, au, as, false);
|
||||
|
||||
CuAssertIntEquals(tc, 1, b->nfighters);
|
||||
CuAssertPtrEquals(tc, 0, af->building);
|
||||
CuAssertPtrEquals(tc, NULL, af->building);
|
||||
CuAssertPtrEquals(tc, as, af->side);
|
||||
CuAssertIntEquals(tc, 0, af->run.hp);
|
||||
CuAssertIntEquals(tc, ST_BEHIND, af->status);
|
||||
|
@ -216,7 +216,7 @@ static void test_defenders_get_building_bonus(CuTest * tc)
|
|||
af = make_fighter(b, au, as, true);
|
||||
|
||||
CuAssertPtrEquals(tc, bld, df->building);
|
||||
CuAssertPtrEquals(tc, 0, af->building);
|
||||
CuAssertPtrEquals(tc, NULL, af->building);
|
||||
|
||||
dt.fighter = df;
|
||||
dt.index = 0;
|
||||
|
@ -261,7 +261,7 @@ static void test_attackers_get_no_building_bonus(CuTest * tc)
|
|||
as = make_side(b, au->faction, 0, 0, 0);
|
||||
af = make_fighter(b, au, as, true);
|
||||
|
||||
CuAssertPtrEquals(tc, 0, af->building);
|
||||
CuAssertPtrEquals(tc, NULL, af->building);
|
||||
free_battle(b);
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -298,12 +298,12 @@ static void test_building_bonus_respects_size(CuTest * tc)
|
|||
df = make_fighter(b, du, as, false);
|
||||
|
||||
CuAssertPtrEquals(tc, bld, af->building);
|
||||
CuAssertPtrEquals(tc, 0, df->building);
|
||||
CuAssertPtrEquals(tc, NULL, df->building);
|
||||
free_battle(b);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
static void test_building_defence_bonus(CuTest * tc)
|
||||
static void test_building_defense_bonus(CuTest * tc)
|
||||
{
|
||||
building_type * btype;
|
||||
|
||||
|
@ -570,7 +570,7 @@ static void test_battle_skilldiff(CuTest *tc)
|
|||
CuAssertIntEquals(tc, 0, skilldiff(ta, td, 0));
|
||||
|
||||
ta.fighter->person[0].attack = 2;
|
||||
td.fighter->person[0].defence = 1;
|
||||
td.fighter->person[0].defense = 1;
|
||||
CuAssertIntEquals(tc, 1, skilldiff(ta, td, 0));
|
||||
|
||||
td.fighter->person[0].flags |= FL_SLEEPING;
|
||||
|
@ -888,7 +888,7 @@ CuSuite *get_battle_suite(void)
|
|||
SUITE_ADD_TEST(suite, test_defenders_get_building_bonus);
|
||||
SUITE_ADD_TEST(suite, test_attackers_get_no_building_bonus);
|
||||
SUITE_ADD_TEST(suite, test_building_bonus_respects_size);
|
||||
SUITE_ADD_TEST(suite, test_building_defence_bonus);
|
||||
SUITE_ADD_TEST(suite, test_building_defense_bonus);
|
||||
SUITE_ADD_TEST(suite, test_calculate_armor);
|
||||
SUITE_ADD_TEST(suite, test_natural_armor);
|
||||
SUITE_ADD_TEST(suite, test_magic_resistance);
|
||||
|
|
|
@ -382,20 +382,8 @@ static int tolua_faction_set_origin(lua_State * L)
|
|||
static int tolua_faction_get_origin(lua_State * L)
|
||||
{
|
||||
faction *self = (faction *)tolua_tousertype(L, 1, 0);
|
||||
|
||||
ursprung *origin = self->ursprung;
|
||||
int x, y;
|
||||
while (origin != NULL && origin->id != 0) {
|
||||
origin = origin->next;
|
||||
}
|
||||
if (origin) {
|
||||
x = origin->x;
|
||||
y = origin->y;
|
||||
}
|
||||
else {
|
||||
x = 0;
|
||||
y = 0;
|
||||
}
|
||||
int x = 0, y = 0;
|
||||
faction_getorigin(self, 0, &x, &y);
|
||||
|
||||
lua_pushinteger(L, x);
|
||||
lua_pushinteger(L, y);
|
||||
|
|
|
@ -357,7 +357,7 @@ static void test_tax_cmd(CuTest *tc) {
|
|||
|
||||
set_level(u, SK_TAXING, 1);
|
||||
tax_cmd(u, ord, &taxorders);
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(u->faction->msgs, "error_no_tax_skill"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->faction->msgs, "error_no_tax_skill"));
|
||||
CuAssertPtrNotNull(tc, taxorders);
|
||||
|
||||
rsetmoney(r, 11);
|
||||
|
@ -415,8 +415,8 @@ static void test_maintain_buildings(CuTest *tc) {
|
|||
b->flags = 0;
|
||||
maintain_buildings(r);
|
||||
CuAssertIntEquals(tc, BLD_MAINTAINED, fval(b, BLD_MAINTAINED));
|
||||
CuAssertPtrEquals(tc, 0, f->msgs);
|
||||
CuAssertPtrEquals(tc, 0, r->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, f->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, r->msgs);
|
||||
|
||||
req = calloc(2, sizeof(maintenance));
|
||||
req[0].number = 100;
|
||||
|
@ -438,8 +438,8 @@ static void test_maintain_buildings(CuTest *tc) {
|
|||
maintain_buildings(r);
|
||||
CuAssertIntEquals(tc, BLD_MAINTAINED, fval(b, BLD_MAINTAINED));
|
||||
CuAssertIntEquals(tc, 0, i_get(u->items, itype));
|
||||
CuAssertPtrEquals(tc, 0, r->msgs);
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "maintenance_nowork"));
|
||||
CuAssertPtrEquals(tc, NULL, r->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "maintenance_nowork"));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "maintenance"));
|
||||
test_clear_messagelist(&f->msgs);
|
||||
|
||||
|
@ -448,7 +448,7 @@ static void test_maintain_buildings(CuTest *tc) {
|
|||
b->flags = 0;
|
||||
maintain_buildings(r);
|
||||
CuAssertIntEquals(tc, 0, fval(b, BLD_MAINTAINED));
|
||||
CuAssertPtrEquals(tc, 0, f->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, f->msgs);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(r->msgs, "maintenance_noowner"));
|
||||
test_clear_messagelist(&r->msgs);
|
||||
|
||||
|
|
|
@ -92,7 +92,7 @@ static void test_give_unit(CuTest * tc) {
|
|||
give_unit(env.src, env.dst, NULL);
|
||||
CuAssertPtrEquals(tc, env.f2, env.src->faction);
|
||||
CuAssertIntEquals(tc, 1, env.f2->newbies);
|
||||
CuAssertPtrEquals(tc, 0, env.f1->units);
|
||||
CuAssertPtrEquals(tc, NULL, env.f1->units);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "give_person"));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(env.f2->msgs, "receive_person"));
|
||||
test_teardown();
|
||||
|
@ -304,7 +304,7 @@ static void test_give_men_requires_contact(CuTest * tc) {
|
|||
ord = create_order(K_GIVE, env.f1->locale, "%s ALLES PERSONEN", itoa36(env.dst->no));
|
||||
test_clear_messages(env.f1);
|
||||
give_cmd(env.src, ord);
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(env.f1->msgs, "give_person"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(env.f1->msgs, "give_person"));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(env.f1->msgs, "feedback_no_contact"));
|
||||
|
||||
msg_release(msg);
|
||||
|
@ -408,7 +408,7 @@ static void test_give_okay(CuTest * tc) {
|
|||
setup_give(&env);
|
||||
|
||||
config_set("rules.give.flags", "0");
|
||||
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, NULL));
|
||||
CuAssertPtrEquals(tc, NULL, check_give(env.src, env.dst, NULL));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -451,7 +451,7 @@ static void test_give_new_unit(CuTest * tc) {
|
|||
setup_give(&env);
|
||||
env.dst->number = 0;
|
||||
fset(env.dst, UFL_ISNEW);
|
||||
CuAssertPtrEquals(tc, 0, check_give(env.src, env.dst, NULL));
|
||||
CuAssertPtrEquals(tc, NULL, check_give(env.src, env.dst, NULL));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
|
|
@ -1361,7 +1361,7 @@ static void update_view(view * vi)
|
|||
|
||||
state *state_open(void)
|
||||
{
|
||||
state *st = calloc(sizeof(state), 1);
|
||||
state *st = (state *)calloc(1, sizeof(state));
|
||||
st->display.pl = get_homeplane();
|
||||
st->cursor.pl = get_homeplane();
|
||||
st->cursor.x = 0;
|
||||
|
|
|
@ -29,7 +29,7 @@ static void test_is_guarded(CuTest *tc) {
|
|||
r = test_create_region(0, 0, NULL);
|
||||
u1 = test_create_unit(test_create_faction(NULL), r);
|
||||
u2 = test_create_unit(test_create_faction(rc), r);
|
||||
CuAssertPtrEquals(tc, 0, is_guarded(r, u1));
|
||||
CuAssertPtrEquals(tc, NULL, is_guarded(r, u1));
|
||||
setguard(u2, true);
|
||||
CuAssertPtrEquals(tc, u2, is_guarded(r, u1));
|
||||
test_teardown();
|
||||
|
|
|
@ -71,8 +71,8 @@ static cJSON *export_a_region(CuTest * tc, const struct terrain_type *terrain, r
|
|||
json = cJSON_Parse(buf);
|
||||
CuAssertPtrNotNull(tc, json);
|
||||
CuAssertIntEquals(tc, cJSON_Object, json->type);
|
||||
CuAssertPtrEquals(tc, 0, cJSON_GetObjectItem(json, "factions"));
|
||||
CuAssertPtrEquals(tc, 0, cJSON_GetObjectItem(json, "units"));
|
||||
CuAssertPtrEquals(tc, NULL, cJSON_GetObjectItem(json, "factions"));
|
||||
CuAssertPtrEquals(tc, NULL, cJSON_GetObjectItem(json, "units"));
|
||||
CuAssertPtrNotNull(tc, regs = cJSON_GetObjectItem(json, "regions"));
|
||||
CuAssertIntEquals(tc, cJSON_Object, regs->type);
|
||||
result = regs->child;
|
||||
|
@ -111,7 +111,7 @@ static void test_export_ocean_region(CuTest * tc) {
|
|||
test_setup();
|
||||
terrain = test_create_terrain("ocean", SEA_REGION);
|
||||
json = export_a_region(tc, terrain, 0);
|
||||
CuAssertPtrEquals(tc, 0, cJSON_GetObjectItem(json, "name"));
|
||||
CuAssertPtrEquals(tc, NULL, cJSON_GetObjectItem(json, "name"));
|
||||
cJSON_Delete(json);
|
||||
test_teardown();
|
||||
}
|
||||
|
|
|
@ -34,14 +34,14 @@ static void test_alliance_make(CuTest *tc) {
|
|||
CuAssertStrEquals(tc, "Hodor", al->name);
|
||||
CuAssertIntEquals(tc, 1, al->id);
|
||||
CuAssertIntEquals(tc, 0, al->flags);
|
||||
CuAssertPtrEquals(tc, 0, al->members);
|
||||
CuAssertPtrEquals(tc, 0, al->_leader);
|
||||
CuAssertPtrEquals(tc, 0, al->allies);
|
||||
CuAssertPtrEquals(tc, NULL, al->members);
|
||||
CuAssertPtrEquals(tc, NULL, al->_leader);
|
||||
CuAssertPtrEquals(tc, NULL, al->allies);
|
||||
CuAssertPtrEquals(tc, al, findalliance(1));
|
||||
CuAssertPtrEquals(tc, al, alliances);
|
||||
free_alliances();
|
||||
CuAssertPtrEquals(tc, 0, findalliance(1));
|
||||
CuAssertPtrEquals(tc, 0, alliances);
|
||||
CuAssertPtrEquals(tc, NULL, findalliance(1));
|
||||
CuAssertPtrEquals(tc, NULL, alliances);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -50,8 +50,8 @@ static void test_alliance_join(CuTest *tc) {
|
|||
alliance * al;
|
||||
|
||||
setup_alliance(&fix);
|
||||
CuAssertPtrEquals(tc, 0, fix.f1->alliance);
|
||||
CuAssertPtrEquals(tc, 0, fix.f2->alliance);
|
||||
CuAssertPtrEquals(tc, NULL, fix.f1->alliance);
|
||||
CuAssertPtrEquals(tc, NULL, fix.f2->alliance);
|
||||
al = makealliance(1, "Hodor");
|
||||
setalliance(fix.f1, al);
|
||||
CuAssertPtrEquals(tc, fix.f1, alliance_get_leader(al));
|
||||
|
@ -99,7 +99,7 @@ static void test_alliance_cmd(CuTest *tc) {
|
|||
unit_addorder(u2, create_order(K_ALLIANCE, u1->faction->locale, "%s %s", alliance_kwd[ALLIANCE_JOIN], itoa36(42)));
|
||||
CuAssertTrue(tc, is_allied(u1->faction, u1->faction));
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u1->faction));
|
||||
CuAssertPtrEquals(tc, NULL, f_get_alliance(u1->faction));
|
||||
alliance_cmd();
|
||||
al = f_get_alliance(u1->faction);
|
||||
CuAssertPtrNotNull(tc, al);
|
||||
|
@ -126,10 +126,10 @@ static void test_alliance_limits(CuTest *tc) {
|
|||
unit_addorder(u1, create_order(K_ALLIANCE, u1->faction->locale, "%s %s", alliance_kwd[ALLIANCE_INVITE], itoa36(u2->faction->no)));
|
||||
unit_addorder(u2, create_order(K_ALLIANCE, u1->faction->locale, "%s %s", alliance_kwd[ALLIANCE_JOIN], itoa36(42)));
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u1->faction));
|
||||
CuAssertPtrEquals(tc, NULL, f_get_alliance(u1->faction));
|
||||
alliance_cmd();
|
||||
CuAssertPtrNotNull(tc, f_get_alliance(u1->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u2->faction));
|
||||
CuAssertPtrEquals(tc, NULL, f_get_alliance(u2->faction));
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(u2->faction->msgs, "too_many_units_in_alliance"));
|
||||
test_teardown();
|
||||
|
@ -152,7 +152,7 @@ static void test_alliance_cmd_kick(CuTest *tc) {
|
|||
CuAssertTrue(tc, is_allied(u1->faction, u2->faction));
|
||||
alliance_cmd();
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u2->faction));
|
||||
CuAssertPtrEquals(tc, NULL, f_get_alliance(u2->faction));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -168,10 +168,10 @@ static void test_alliance_cmd_no_invite(CuTest *tc) {
|
|||
unit_addorder(u2, create_order(K_ALLIANCE, u1->faction->locale, "%s %s", alliance_kwd[ALLIANCE_JOIN], itoa36(42)));
|
||||
CuAssertTrue(tc, is_allied(u1->faction, u1->faction));
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u1->faction));
|
||||
CuAssertPtrEquals(tc, NULL, f_get_alliance(u1->faction));
|
||||
alliance_cmd();
|
||||
CuAssertPtrNotNull(tc, f_get_alliance(u1->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u2->faction));
|
||||
CuAssertPtrEquals(tc, NULL, f_get_alliance(u2->faction));
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -193,7 +193,7 @@ static void test_alliance_cmd_leave(CuTest *tc) {
|
|||
CuAssertTrue(tc, is_allied(u1->faction, u2->faction));
|
||||
alliance_cmd();
|
||||
CuAssertTrue(tc, !is_allied(u1->faction, u2->faction));
|
||||
CuAssertPtrEquals(tc, 0, f_get_alliance(u1->faction));
|
||||
CuAssertPtrEquals(tc, NULL, f_get_alliance(u1->faction));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
|
|
@ -56,10 +56,8 @@ ally * ally_add(ally **al_p, struct faction *f) {
|
|||
if (f && al->faction == f) return al;
|
||||
al_p = &al->next;
|
||||
}
|
||||
al = (ally *)malloc(sizeof(ally));
|
||||
al = (ally *)calloc(1, sizeof(ally));
|
||||
al->faction = f;
|
||||
al->status = 0;
|
||||
al->next = 0;
|
||||
*al_p = al;
|
||||
return al;
|
||||
}
|
||||
|
|
|
@ -15,8 +15,8 @@ static void test_ally(CuTest * tc)
|
|||
CuAssertPtrEquals(tc, f1, ally_find(al, f1)->faction);
|
||||
|
||||
ally_remove(&al, f1);
|
||||
CuAssertPtrEquals(tc, 0, al);
|
||||
CuAssertPtrEquals(tc, 0, ally_find(al, f1));
|
||||
CuAssertPtrEquals(tc, NULL, al);
|
||||
CuAssertPtrEquals(tc, NULL, ally_find(al, f1));
|
||||
}
|
||||
|
||||
static void test_ally_null(CuTest * tc)
|
||||
|
@ -28,7 +28,7 @@ static void test_ally_null(CuTest * tc)
|
|||
CuAssertPtrNotNull(tc, a1);
|
||||
CuAssertPtrNotNull(tc, a2);
|
||||
CuAssertPtrEquals(tc, a2, a1->next);
|
||||
CuAssertPtrEquals(tc, 0, a2->next);
|
||||
CuAssertPtrEquals(tc, NULL, a2->next);
|
||||
free(a1);
|
||||
free(a2);
|
||||
}
|
||||
|
|
|
@ -15,11 +15,11 @@ static void test_attrib_new(CuTest * tc)
|
|||
attrib_type at_test = { "test" };
|
||||
attrib * a;
|
||||
CuAssertPtrNotNull(tc, (a = a_new(&at_test)));
|
||||
CuAssertPtrEquals(tc, 0, a->next);
|
||||
CuAssertPtrEquals(tc, 0, a->nexttype);
|
||||
CuAssertPtrEquals(tc, NULL, a->next);
|
||||
CuAssertPtrEquals(tc, NULL, a->nexttype);
|
||||
CuAssertPtrEquals(tc, (void *)a->type, (void *)&at_test);
|
||||
a_remove(&a, a);
|
||||
CuAssertPtrEquals(tc, 0, a);
|
||||
CuAssertPtrEquals(tc, NULL, a);
|
||||
}
|
||||
|
||||
static void test_attrib_add(CuTest * tc)
|
||||
|
@ -51,7 +51,7 @@ static void test_attrib_remove_self(CuTest * tc) {
|
|||
CuAssertPtrNotNull(tc, a_add(&alist, a_new(&at_foo)));
|
||||
CuAssertPtrNotNull(tc, a = a_add(&alist, a_new(&at_foo)));
|
||||
CuAssertPtrEquals(tc, a, alist->next);
|
||||
CuAssertPtrEquals(tc, 0, alist->nexttype);
|
||||
CuAssertPtrEquals(tc, NULL, alist->nexttype);
|
||||
CuAssertIntEquals(tc, 1, a_remove(&alist, alist));
|
||||
CuAssertPtrEquals(tc, a, alist);
|
||||
a_removeall(&alist, NULL);
|
||||
|
@ -66,11 +66,11 @@ static void test_attrib_removeall(CuTest * tc) {
|
|||
a_add(&alist, a_new(&at_foo));
|
||||
a_removeall(&alist, &at_foo);
|
||||
CuAssertPtrEquals(tc, a, alist);
|
||||
CuAssertPtrEquals(tc, 0, alist->next);
|
||||
CuAssertPtrEquals(tc, NULL, alist->next);
|
||||
a_add(&alist, a_new(&at_bar));
|
||||
a_add(&alist, a_new(&at_foo));
|
||||
a_removeall(&alist, NULL);
|
||||
CuAssertPtrEquals(tc, 0, alist);
|
||||
CuAssertPtrEquals(tc, NULL, alist);
|
||||
}
|
||||
|
||||
static void test_attrib_remove(CuTest * tc)
|
||||
|
@ -83,7 +83,7 @@ static void test_attrib_remove(CuTest * tc)
|
|||
CuAssertIntEquals(tc, 1, a_remove(&alist, a));
|
||||
CuAssertPtrNotNull(tc, alist);
|
||||
CuAssertIntEquals(tc, 1, a_remove(&alist, alist));
|
||||
CuAssertPtrEquals(tc, 0, alist);
|
||||
CuAssertPtrEquals(tc, NULL, alist);
|
||||
}
|
||||
|
||||
static void test_attrib_nexttype(CuTest * tc)
|
||||
|
@ -92,16 +92,16 @@ static void test_attrib_nexttype(CuTest * tc)
|
|||
attrib_type at_bar = { "bar" };
|
||||
attrib *a, *alist = 0;
|
||||
CuAssertPtrNotNull(tc, (a = a_new(&at_foo)));
|
||||
CuAssertPtrEquals(tc, 0, a->nexttype);
|
||||
CuAssertPtrEquals(tc, NULL, a->nexttype);
|
||||
CuAssertPtrEquals(tc, a, a_add(&alist, a));
|
||||
CuAssertPtrEquals(tc, 0, alist->nexttype);
|
||||
CuAssertPtrEquals(tc, NULL, alist->nexttype);
|
||||
|
||||
CuAssertPtrNotNull(tc, a_add(&alist, a_new(&at_foo)));
|
||||
CuAssertPtrEquals(tc, 0, alist->nexttype);
|
||||
CuAssertPtrEquals(tc, NULL, alist->nexttype);
|
||||
|
||||
CuAssertPtrNotNull(tc, (a = a_add(&alist, a_new(&at_bar))));
|
||||
CuAssertPtrEquals(tc, a, alist->nexttype);
|
||||
CuAssertPtrEquals(tc, 0, a->nexttype);
|
||||
CuAssertPtrEquals(tc, NULL, a->nexttype);
|
||||
|
||||
a_remove(&alist, alist);
|
||||
CuAssertPtrEquals(tc, a, alist->nexttype);
|
||||
|
|
|
@ -54,16 +54,17 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include <kernel/unit.h>
|
||||
|
||||
/* from libutil */
|
||||
#include <util/base36.h>
|
||||
#include <util/goodies.h>
|
||||
#include <util/language.h>
|
||||
#include <util/log.h>
|
||||
#include <util/param.h>
|
||||
#include <util/parser.h>
|
||||
#include <util/resolve.h>
|
||||
#include <util/strings.h>
|
||||
|
||||
/* from libc */
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
#include <math.h>
|
||||
#include <stdio.h>
|
||||
|
@ -180,7 +181,9 @@ int destroy_cmd(unit * u, struct order *ord)
|
|||
s = gettoken(token, sizeof(token));
|
||||
|
||||
if (s && *s) {
|
||||
n = atoi((const char *)s);
|
||||
ERRNO_CHECK();
|
||||
n = atoi(s);
|
||||
errno = 0;
|
||||
if (n <= 0) {
|
||||
n = INT_MAX;
|
||||
}
|
||||
|
|
|
@ -202,8 +202,8 @@ static void test_build_building_no_materials(CuTest *tc) {
|
|||
set_level(u, SK_BUILDING, 1);
|
||||
u->orders = create_order(K_MAKE, u->faction->locale, 0);
|
||||
CuAssertIntEquals(tc, ENOMATERIALS, build_building(u, btype, 0, 4, u->orders));
|
||||
CuAssertPtrEquals(tc, 0, u->region->buildings);
|
||||
CuAssertPtrEquals(tc, 0, u->building);
|
||||
CuAssertPtrEquals(tc, NULL, u->region->buildings);
|
||||
CuAssertPtrEquals(tc, NULL, u->building);
|
||||
teardown_build(&bf);
|
||||
}
|
||||
|
||||
|
@ -267,7 +267,7 @@ static void test_build_destroy_road(CuTest *tc)
|
|||
|
||||
CuAssertIntEquals(tc, 0, destroy_cmd(u, ord));
|
||||
CuAssertIntEquals(tc, 100, rroad(r, D_EAST));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "destroy_road"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "destroy_road"));
|
||||
|
||||
set_level(u, SK_ROAD_BUILDING, 1);
|
||||
CuAssertIntEquals(tc, 0, destroy_cmd(u, ord));
|
||||
|
@ -324,7 +324,7 @@ static void test_build_destroy_road_guard(CuTest *tc)
|
|||
CuAssertIntEquals(tc, 0, destroy_cmd(u, ord));
|
||||
CuAssertIntEquals(tc, 100, rroad(r, D_EAST));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error70"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "destroy_road"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "destroy_road"));
|
||||
|
||||
test_clear_messages(f);
|
||||
setguard(ug, false);
|
||||
|
|
|
@ -135,7 +135,7 @@ building_type *bt_get_or_create(const char *name)
|
|||
if (name != NULL) {
|
||||
building_type *btype = bt_find_i(name);
|
||||
if (btype == NULL) {
|
||||
btype = calloc(sizeof(building_type), 1);
|
||||
btype = (building_type *)calloc(1, sizeof(building_type));
|
||||
btype->_name = str_strdup(name);
|
||||
btype->flags = BTF_DEFAULT;
|
||||
btype->auraregen = 1.0;
|
||||
|
|
|
@ -37,8 +37,8 @@ static void test_command(CuTest * tc) {
|
|||
st = stree_create();
|
||||
CuAssertPtrNotNull(tc, st);
|
||||
CuAssertPtrEquals(tc, loc, (struct locale *)st->lang);
|
||||
CuAssertPtrEquals(tc, 0, st->root);
|
||||
CuAssertPtrEquals(tc, 0, st->next);
|
||||
CuAssertPtrEquals(tc, NULL, st->root);
|
||||
CuAssertPtrEquals(tc, NULL, st->next);
|
||||
stree_add(st, "two", parser_two);
|
||||
stree_add(st, "six", parser_six);
|
||||
CuAssertPtrNotNull(tc, st->root);
|
||||
|
|
|
@ -11,6 +11,7 @@
|
|||
#include <assert.h>
|
||||
#include <limits.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
#include <string.h>
|
||||
|
||||
static sqlite3 *g_game_db;
|
||||
|
@ -179,11 +180,14 @@ static int db_open_swap(const char *dbname) {
|
|||
return 0;
|
||||
}
|
||||
|
||||
static const char *g_swapname;
|
||||
|
||||
int db_driver_open(database_t db, const char *dbname)
|
||||
{
|
||||
ERRNO_CHECK();
|
||||
|
||||
if (db == DB_SWAP) {
|
||||
g_swapname = dbname;
|
||||
return db_open_swap(dbname);
|
||||
}
|
||||
else if (db == DB_GAME) {
|
||||
|
@ -205,6 +209,13 @@ void db_driver_close(database_t db)
|
|||
assert(err == SQLITE_OK);
|
||||
err = sqlite3_close(g_temp_db);
|
||||
assert(err == SQLITE_OK);
|
||||
if (g_swapname) {
|
||||
FILE * F = fopen(g_swapname, "r");
|
||||
if (F) {
|
||||
fclose(F);
|
||||
remove(g_swapname);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (db == DB_GAME) {
|
||||
assert(g_game_db);
|
||||
|
|
|
@ -119,7 +119,7 @@ static void free_faction(faction * f)
|
|||
|
||||
i_freeall(&f->items);
|
||||
|
||||
freelist(f->ursprung);
|
||||
freelist(f->origin);
|
||||
}
|
||||
|
||||
#define FMAXHASH 2039
|
||||
|
@ -727,10 +727,10 @@ bool faction_alive(const faction *f) {
|
|||
|
||||
void faction_getorigin(const faction * f, int id, int *x, int *y)
|
||||
{
|
||||
ursprung *ur;
|
||||
origin *ur;
|
||||
|
||||
assert(f && x && y);
|
||||
for (ur = f->ursprung; ur; ur = ur->next) {
|
||||
for (ur = f->origin; ur; ur = ur->next) {
|
||||
if (ur->id == id) {
|
||||
*x = ur->x;
|
||||
*y = ur->y;
|
||||
|
@ -739,24 +739,27 @@ void faction_getorigin(const faction * f, int id, int *x, int *y)
|
|||
}
|
||||
}
|
||||
|
||||
void faction_setorigin(faction * f, int id, int x, int y)
|
||||
{
|
||||
ursprung *ur;
|
||||
assert(f != NULL);
|
||||
for (ur = f->ursprung; ur; ur = ur->next) {
|
||||
if (ur->id == id) {
|
||||
ur->x = ur->x + x;
|
||||
ur->y = ur->y + y;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
ur = calloc(1, sizeof(ursprung));
|
||||
static origin *new_origin(int id, int x, int y) {
|
||||
origin *ur = (origin *)calloc(1, sizeof(origin));
|
||||
ur->id = id;
|
||||
ur->x = x;
|
||||
ur->y = y;
|
||||
return ur;
|
||||
}
|
||||
|
||||
addlist(&f->ursprung, ur);
|
||||
void faction_setorigin(faction * f, int id, int x, int y)
|
||||
{
|
||||
origin **urp;
|
||||
assert(f != NULL);
|
||||
for (urp = &f->origin; *urp; urp = &(*urp)->next) {
|
||||
origin *ur = *urp;
|
||||
if (ur->id == id) {
|
||||
ur->x += x;
|
||||
ur->y += y;
|
||||
return;
|
||||
}
|
||||
}
|
||||
*urp = new_origin(id, x, y);
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -37,7 +37,7 @@ extern "C" {
|
|||
struct attrib_type;
|
||||
struct gamedata;
|
||||
struct selist;
|
||||
|
||||
|
||||
/* faction flags */
|
||||
#define FFL_NOAID (1<<0) /* Hilfsflag Kampf */
|
||||
#define FFL_ISNEW (1<<1)
|
||||
|
@ -54,6 +54,12 @@ extern "C" {
|
|||
#define FFL_NPC (1<<25) /* eine Partei mit Monstern */
|
||||
#define FFL_SAVEMASK (FFL_DEFENDER|FFL_NPC|FFL_NOIDLEOUT|FFL_CURSED)
|
||||
|
||||
typedef struct origin {
|
||||
struct origin *next;
|
||||
int id;
|
||||
int x, y;
|
||||
} origin;
|
||||
|
||||
typedef struct faction {
|
||||
struct faction *next;
|
||||
struct faction *nexthash;
|
||||
|
@ -72,7 +78,7 @@ extern "C" {
|
|||
const struct locale *locale;
|
||||
int lastorders;
|
||||
int age;
|
||||
struct ursprung *ursprung;
|
||||
struct origin *origin;
|
||||
const struct race *race;
|
||||
magic_t magiegebiet;
|
||||
int newbies;
|
||||
|
|
|
@ -57,7 +57,7 @@ static void test_remove_empty_factions_alliance(CuTest *tc) {
|
|||
CuAssertPtrEquals(tc, f, alliance_get_leader(al));
|
||||
CuAssertIntEquals(tc, 1, selist_length(al->members));
|
||||
remove_empty_factions();
|
||||
CuAssertPtrEquals(tc, 0, al->_leader);
|
||||
CuAssertPtrEquals(tc, NULL, al->_leader);
|
||||
CuAssertIntEquals(tc, 0, selist_length(al->members));
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -75,7 +75,7 @@ static void test_remove_empty_factions(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, false, f->_alive);
|
||||
CuAssertPtrEquals(tc, fm, factions);
|
||||
CuAssertPtrEquals(tc, NULL, fm->next);
|
||||
CuAssertPtrEquals(tc, 0, findfaction(fno));
|
||||
CuAssertPtrEquals(tc, NULL, findfaction(fno));
|
||||
CuAssertPtrEquals(tc, fm, get_monsters());
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ static void test_remove_dead_factions(CuTest *tc) {
|
|||
f->_alive = false;
|
||||
fno = f->no;
|
||||
remove_empty_factions();
|
||||
CuAssertPtrEquals(tc, 0, findfaction(fno));
|
||||
CuAssertPtrEquals(tc, NULL, findfaction(fno));
|
||||
CuAssertPtrEquals(tc, fm, get_monsters());
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -119,7 +119,7 @@ static void test_addfaction(CuTest *tc) {
|
|||
CuAssertPtrEquals(tc, NULL, (void *)f->next);
|
||||
CuAssertPtrEquals(tc, NULL, (void *)f->banner);
|
||||
CuAssertPtrEquals(tc, NULL, (void *)f->spellbook);
|
||||
CuAssertPtrEquals(tc, NULL, (void *)f->ursprung);
|
||||
CuAssertPtrEquals(tc, NULL, (void *)f->origin);
|
||||
CuAssertPtrEquals(tc, (void *)factions, (void *)f);
|
||||
CuAssertStrEquals(tc, "test@eressea.de", f->email);
|
||||
CuAssertTrue(tc, checkpasswd(f, "hurrdurr"));
|
||||
|
@ -162,11 +162,11 @@ static void test_set_origin(CuTest *tc) {
|
|||
test_setup();
|
||||
pl = create_new_plane(0, "", 0, 19, 0, 19, 0);
|
||||
f = test_create_faction(NULL);
|
||||
CuAssertPtrEquals(tc, 0, f->ursprung);
|
||||
CuAssertPtrEquals(tc, NULL, f->origin);
|
||||
faction_setorigin(f, 0, 1, 1);
|
||||
CuAssertIntEquals(tc, 0, f->ursprung->id);
|
||||
CuAssertIntEquals(tc, 1, f->ursprung->x);
|
||||
CuAssertIntEquals(tc, 1, f->ursprung->y);
|
||||
CuAssertIntEquals(tc, 0, f->origin->id);
|
||||
CuAssertIntEquals(tc, 1, f->origin->x);
|
||||
CuAssertIntEquals(tc, 1, f->origin->y);
|
||||
faction_getorigin(f, 0, &x, &y);
|
||||
CuAssertIntEquals(tc, 1, x);
|
||||
CuAssertIntEquals(tc, 1, y);
|
||||
|
@ -190,7 +190,7 @@ static void test_set_origin_bug(CuTest *tc) {
|
|||
faction_setorigin(f, 0, -10, 3);
|
||||
faction_setorigin(f, 0, -13, -4);
|
||||
adjust_coordinates(f, &x, &y, pl);
|
||||
CuAssertIntEquals(tc, 0, f->ursprung->id);
|
||||
CuAssertIntEquals(tc, 0, f->origin->id);
|
||||
CuAssertIntEquals(tc, -9, x);
|
||||
CuAssertIntEquals(tc, 2, y);
|
||||
test_teardown();
|
||||
|
@ -250,7 +250,7 @@ static void test_set_email(CuTest *tc) {
|
|||
faction_setemail(f, "bugs@eressea.de");
|
||||
CuAssertStrEquals(tc, "bugs@eressea.de", f->email);
|
||||
faction_setemail(f, NULL);
|
||||
CuAssertPtrEquals(tc, 0, f->email);
|
||||
CuAssertPtrEquals(tc, NULL, f->email);
|
||||
CuAssertStrEquals(tc, "", faction_getemail(f));
|
||||
test_teardown();
|
||||
}
|
||||
|
|
|
@ -35,7 +35,7 @@ static void test_group_readwrite_dead_faction(CuTest *tc) {
|
|||
f = test_create_faction(NULL);
|
||||
fno = f->no;
|
||||
CuAssertPtrEquals(tc, f, factions);
|
||||
CuAssertPtrEquals(tc, 0, f->next);
|
||||
CuAssertPtrEquals(tc, NULL, f->next);
|
||||
f2 = test_create_faction(NULL);
|
||||
CuAssertPtrEquals(tc, f2, factions->next);
|
||||
u = test_create_unit(f2, test_create_region(0, 0, NULL));
|
||||
|
@ -58,14 +58,14 @@ static void test_group_readwrite_dead_faction(CuTest *tc) {
|
|||
read_game(&data);
|
||||
mstream_done(&data.strm);
|
||||
gamedata_done(&data);
|
||||
CuAssertPtrEquals(tc, 0, findfaction(fno));
|
||||
CuAssertPtrEquals(tc, NULL, findfaction(fno));
|
||||
f2 = factions;
|
||||
CuAssertPtrNotNull(tc, f2);
|
||||
u = f2->units;
|
||||
CuAssertPtrNotNull(tc, u);
|
||||
g = get_group(u);
|
||||
CuAssertPtrNotNull(tc, g);
|
||||
CuAssertPtrEquals(tc, 0, g->allies);
|
||||
CuAssertPtrEquals(tc, NULL, g->allies);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -106,11 +106,11 @@ static void test_group_readwrite(CuTest * tc)
|
|||
CuAssertPtrNotNull(tc, f->groups->next);
|
||||
CuAssertIntEquals(tc, 43, f->groups->next->gid);
|
||||
CuAssertStrEquals(tc, "Egoisten", f->groups->next->name);
|
||||
CuAssertPtrEquals(tc, 0, f->groups->allies);
|
||||
CuAssertPtrEquals(tc, NULL, f->groups->allies);
|
||||
g = f->groups->next;
|
||||
CuAssertIntEquals(tc, 44, key_get(g->attribs, 44));
|
||||
CuAssertPtrNotNull(tc, g->allies);
|
||||
CuAssertPtrEquals(tc, 0, g->allies->next);
|
||||
CuAssertPtrEquals(tc, NULL, g->allies->next);
|
||||
CuAssertPtrEquals(tc, f, g->allies->faction);
|
||||
CuAssertIntEquals(tc, HELP_GIVE, g->allies->status);
|
||||
test_teardown();
|
||||
|
@ -135,7 +135,7 @@ static void test_group(CuTest * tc)
|
|||
CuAssertIntEquals(tc, 1, g->members);
|
||||
set_group(u, 0);
|
||||
CuAssertIntEquals(tc, 0, g->members);
|
||||
CuAssertPtrEquals(tc, 0, get_group(u));
|
||||
CuAssertPtrEquals(tc, NULL, get_group(u));
|
||||
set_group(u, g);
|
||||
CuAssertIntEquals(tc, 1, g->members);
|
||||
CuAssertPtrEquals(tc, g, get_group(u));
|
||||
|
|
|
@ -723,7 +723,7 @@ int change_money(unit * u, int v)
|
|||
return 0;
|
||||
}
|
||||
|
||||
static int add_resourcename_cb(const void * match, const void * key,
|
||||
static int add_resourcename_cb(void * match, const void * key,
|
||||
size_t keylen, void *data)
|
||||
{
|
||||
struct locale * lang = (struct locale *)data;
|
||||
|
@ -773,7 +773,7 @@ attrib_type at_showitem = {
|
|||
"showitem"
|
||||
};
|
||||
|
||||
static int add_itemname_cb(const void * match, const void * key,
|
||||
static int add_itemname_cb(void * match, const void * key,
|
||||
size_t keylen, void *data)
|
||||
{
|
||||
struct locale * lang = (struct locale *)data;
|
||||
|
@ -919,7 +919,7 @@ void free_rtype(resource_type *rtype) {
|
|||
free(rtype);
|
||||
}
|
||||
|
||||
static int free_rtype_cb(const void * match, const void * key,
|
||||
static int free_rtype_cb(void * match, const void * key,
|
||||
size_t keylen, void *cbdata)
|
||||
{
|
||||
resource_type *rtype = ((rt_entry *)match)->value;;
|
||||
|
|
|
@ -61,7 +61,7 @@ static void test_uchange(CuTest * tc, unit * u, const resource_type * rtype) {
|
|||
CuAssertIntEquals(tc, 0, rtype->uchange(u, rtype, -n));
|
||||
CuAssertPtrNotNull(tc, sl);
|
||||
CuAssertStrEquals(tc, "serious accounting error. number of items is %d.", sl->s);
|
||||
CuAssertPtrEquals(tc, 0, sl->next);
|
||||
CuAssertPtrEquals(tc, NULL, sl->next);
|
||||
test_log_stop(log, sl);
|
||||
}
|
||||
|
||||
|
@ -86,7 +86,7 @@ void test_resource_type(CuTest * tc)
|
|||
|
||||
test_setup();
|
||||
|
||||
CuAssertPtrEquals(tc, 0, rt_find("herpderp"));
|
||||
CuAssertPtrEquals(tc, NULL, rt_find("herpderp"));
|
||||
|
||||
test_create_itemtype("herpderp");
|
||||
test_create_itemtype("herpes");
|
||||
|
@ -122,7 +122,7 @@ void test_findresourcetype(CuTest * tc)
|
|||
locale_setstring(lang, "peasant", "Bauer");
|
||||
init_resources();
|
||||
CuAssertPtrNotNull(tc, rt_find("peasant"));
|
||||
CuAssertPtrEquals(tc, 0, rt_find("log"));
|
||||
CuAssertPtrEquals(tc, NULL, rt_find("log"));
|
||||
itype = test_create_itemtype("log");
|
||||
|
||||
CuAssertPtrEquals(tc, (void*)itype->rtype, (void*)findresourcetype("Holz", lang));
|
||||
|
@ -164,13 +164,13 @@ static void test_core_resources(CuTest *tc) {
|
|||
CuAssertPtrNotNull(tc, rtype->itype);
|
||||
CuAssertPtrNotNull(tc, rtype->uchange);
|
||||
CuAssertPtrNotNull(tc, rtype = rt_find("peasant"));
|
||||
CuAssertPtrEquals(tc, 0, rtype->itype);
|
||||
CuAssertPtrEquals(tc, NULL, rtype->itype);
|
||||
CuAssertPtrNotNull(tc, rtype = rt_find("permaura"));
|
||||
CuAssertPtrEquals(tc, 0, rtype->itype);
|
||||
CuAssertPtrEquals(tc, NULL, rtype->itype);
|
||||
CuAssertPtrNotNull(tc, rtype = rt_find("hp"));
|
||||
CuAssertPtrEquals(tc, 0, rtype->itype);
|
||||
CuAssertPtrEquals(tc, NULL, rtype->itype);
|
||||
CuAssertPtrNotNull(tc, rtype = rt_find("aura"));
|
||||
CuAssertPtrEquals(tc, 0, rtype->itype);
|
||||
CuAssertPtrEquals(tc, NULL, rtype->itype);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
|
|
@ -59,7 +59,7 @@ static void test_merge_split(CuTest *tc) {
|
|||
add_message(&append, msg = msg_message(mtype->name, ""));
|
||||
msg_release(msg);
|
||||
|
||||
CuAssertPtrEquals(tc, 0, mlist->begin->next);
|
||||
CuAssertPtrEquals(tc, NULL, mlist->begin->next);
|
||||
CuAssertPtrEquals(tc, &mlist->begin->next, mlist->end);
|
||||
split = merge_messages(mlist, append);
|
||||
CuAssertPtrNotNull(tc, split);
|
||||
|
@ -68,7 +68,7 @@ static void test_merge_split(CuTest *tc) {
|
|||
CuAssertPtrNotNull(tc, mlist->begin->next);
|
||||
CuAssertPtrEquals(tc, append->begin, mlist->begin->next);
|
||||
split_messages(mlist, split);
|
||||
CuAssertPtrEquals(tc, 0, mlist->begin->next);
|
||||
CuAssertPtrEquals(tc, NULL, mlist->begin->next);
|
||||
free_messagelist(*split);
|
||||
free_messagelist(mlist->begin);
|
||||
free(mlist);
|
||||
|
|
|
@ -239,11 +239,11 @@ static void test_replace_order(CuTest *tc) {
|
|||
orig = create_order(K_MAKE, lang, NULL);
|
||||
repl = create_order(K_ALLY, lang, NULL);
|
||||
replace_order(&orders, orig, repl);
|
||||
CuAssertPtrEquals(tc, 0, orders);
|
||||
CuAssertPtrEquals(tc, NULL, orders);
|
||||
orders = orig;
|
||||
replace_order(&orders, orig, repl);
|
||||
CuAssertPtrNotNull(tc, orders);
|
||||
CuAssertPtrEquals(tc, 0, orders->next);
|
||||
CuAssertPtrEquals(tc, NULL, orders->next);
|
||||
CuAssertIntEquals(tc, getkeyword(repl), getkeyword(orders));
|
||||
free_order(orders);
|
||||
free_order(repl);
|
||||
|
|
|
@ -122,7 +122,7 @@ int getplaneid(const region * r)
|
|||
static int
|
||||
ursprung_x(const faction * f, const plane * pl, const region * rdefault)
|
||||
{
|
||||
ursprung *ur;
|
||||
origin *ur;
|
||||
int id = 0;
|
||||
|
||||
if (!f)
|
||||
|
@ -131,7 +131,7 @@ ursprung_x(const faction * f, const plane * pl, const region * rdefault)
|
|||
if (pl)
|
||||
id = pl->id;
|
||||
|
||||
for (ur = f->ursprung; ur; ur = ur->next) {
|
||||
for (ur = f->origin; ur; ur = ur->next) {
|
||||
if (ur->id == id)
|
||||
return ur->x;
|
||||
}
|
||||
|
@ -145,7 +145,7 @@ ursprung_x(const faction * f, const plane * pl, const region * rdefault)
|
|||
static int
|
||||
ursprung_y(const faction * f, const plane * pl, const region * rdefault)
|
||||
{
|
||||
ursprung *ur;
|
||||
origin *ur;
|
||||
int id = 0;
|
||||
|
||||
if (!f)
|
||||
|
@ -154,7 +154,7 @@ ursprung_y(const faction * f, const plane * pl, const region * rdefault)
|
|||
if (pl)
|
||||
id = pl->id;
|
||||
|
||||
for (ur = f->ursprung; ur; ur = ur->next) {
|
||||
for (ur = f->origin; ur; ur = ur->next) {
|
||||
if (ur->id == id)
|
||||
return ur->y;
|
||||
}
|
||||
|
|
|
@ -11,15 +11,15 @@ static void test_plane(CuTest *tc) {
|
|||
|
||||
test_setup();
|
||||
r = test_create_region(0, 0, NULL);
|
||||
CuAssertPtrEquals(tc, 0, findplane(0, 0));
|
||||
CuAssertPtrEquals(tc, 0, getplane(r));
|
||||
CuAssertPtrEquals(tc, NULL, findplane(0, 0));
|
||||
CuAssertPtrEquals(tc, NULL, getplane(r));
|
||||
CuAssertIntEquals(tc, 0, getplaneid(r));
|
||||
CuAssertPtrEquals(tc, 0, getplanebyid(0));
|
||||
CuAssertPtrEquals(tc, NULL, getplanebyid(0));
|
||||
CuAssertIntEquals(tc, 0, plane_center_x(0));
|
||||
CuAssertIntEquals(tc, 0, plane_center_y(0));
|
||||
CuAssertIntEquals(tc, 0, plane_width(0));
|
||||
CuAssertIntEquals(tc, 0, plane_height(0));
|
||||
CuAssertPtrEquals(tc, 0, get_homeplane());
|
||||
CuAssertPtrEquals(tc, NULL, get_homeplane());
|
||||
|
||||
pl = create_new_plane(1, "Hell", 4, 8, 40, 80, 15);
|
||||
r = test_create_region(4, 40, 0);
|
||||
|
@ -28,7 +28,7 @@ static void test_plane(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, 8, pl->maxx);
|
||||
CuAssertIntEquals(tc, 40, pl->miny);
|
||||
CuAssertIntEquals(tc, 80, pl->maxy);
|
||||
CuAssertPtrEquals(tc, 0, pl->attribs);
|
||||
CuAssertPtrEquals(tc, NULL, pl->attribs);
|
||||
CuAssertStrEquals(tc, "Hell", pl->name);
|
||||
CuAssertPtrEquals(tc, pl, findplane(4, 40));
|
||||
CuAssertPtrEquals(tc, pl, getplane(r));
|
||||
|
|
|
@ -774,7 +774,7 @@ region *new_region(int x, int y, struct plane *pl, int uid)
|
|||
log_error("duplicate region contains units\n");
|
||||
return r;
|
||||
}
|
||||
r = calloc(1, sizeof(region));
|
||||
r = (region *)calloc(sizeof(region), 1);
|
||||
assert_alloc(r);
|
||||
r->x = x;
|
||||
r->y = y;
|
||||
|
|
|
@ -23,14 +23,14 @@ void test_terraform(CuTest *tc) {
|
|||
t_plain = test_create_terrain("plain", LAND_REGION);
|
||||
t_ocean = test_create_terrain("ocean", SEA_REGION);
|
||||
r = test_create_region(0, 0, t_ocean);
|
||||
CuAssertPtrEquals(tc, 0, r->land);
|
||||
CuAssertPtrEquals(tc, NULL, r->land);
|
||||
terraform_region(r, t_plain);
|
||||
CuAssertPtrNotNull(tc, r->land);
|
||||
CuAssertPtrNotNull(tc, r->land->demands);
|
||||
CuAssertPtrEquals(tc, itype, (void *)r->land->demands->type->itype);
|
||||
CuAssertIntEquals(tc, 0, r->land->demands->type->price);
|
||||
terraform_region(r, t_ocean);
|
||||
CuAssertPtrEquals(tc, 0, r->land);
|
||||
CuAssertPtrEquals(tc, NULL, r->land);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
|
|
@ -357,14 +357,14 @@ static void read_skills(gamedata *data, unit *u)
|
|||
size_t sz = u->skill_size * sizeof(skill);
|
||||
|
||||
qsort(skills, u->skill_size, sizeof(skill), skill_cmp);
|
||||
u->skills = malloc(sz);
|
||||
u->skills = (skill *)malloc(sz);
|
||||
memcpy(u->skills, skills, sz);
|
||||
}
|
||||
}
|
||||
else {
|
||||
int i;
|
||||
READ_INT(data->store, &u->skill_size);
|
||||
u->skills = malloc(sizeof(skill)*u->skill_size);
|
||||
u->skills = (skill *)malloc(sizeof(skill)*u->skill_size);
|
||||
for (i = 0; i != u->skill_size; ++i) {
|
||||
skill *sv = u->skills + i;
|
||||
read_skill(data, sv);
|
||||
|
@ -420,7 +420,7 @@ unit *read_unit(gamedata *data)
|
|||
u_setfaction(u, NULL);
|
||||
}
|
||||
else {
|
||||
u = calloc(sizeof(unit), 1);
|
||||
u = (unit *)calloc(1, sizeof(unit));
|
||||
assert_alloc(u);
|
||||
u->no = n;
|
||||
uhash(u);
|
||||
|
@ -1095,7 +1095,7 @@ faction *read_faction(gamedata * data)
|
|||
void write_faction(gamedata *data, const faction * f)
|
||||
{
|
||||
ally *sf;
|
||||
ursprung *ur;
|
||||
origin *ur;
|
||||
|
||||
assert(f->_alive);
|
||||
assert(f->no > 0 && f->no <= MAX_UNIT_NR);
|
||||
|
@ -1134,8 +1134,8 @@ void write_faction(gamedata *data, const faction * f)
|
|||
WRITE_SECTION(data->store);
|
||||
WRITE_TOK(data->store, "end");
|
||||
WRITE_SECTION(data->store);
|
||||
WRITE_INT(data->store, listlen(f->ursprung));
|
||||
for (ur = f->ursprung; ur; ur = ur->next) {
|
||||
WRITE_INT(data->store, listlen(f->origin));
|
||||
for (ur = f->origin; ur; ur = ur->next) {
|
||||
WRITE_INT(data->store, ur->id);
|
||||
WRITE_INT(data->store, ur->x);
|
||||
WRITE_INT(data->store, ur->y);
|
||||
|
|
|
@ -86,7 +86,7 @@ static void test_readwrite_unit(CuTest * tc)
|
|||
CuAssertPtrEquals(tc, f, u->faction);
|
||||
CuAssertStrEquals(tc, "Hodor", u->_name);
|
||||
CuAssertTrue(tc, irace == u_irace(u));
|
||||
CuAssertPtrEquals(tc, 0, u->region);
|
||||
CuAssertPtrEquals(tc, NULL, u->region);
|
||||
|
||||
mstream_done(&data.strm);
|
||||
gamedata_done(&data);
|
||||
|
@ -115,7 +115,7 @@ static void test_readwrite_faction(CuTest * tc)
|
|||
f = read_faction(&data);
|
||||
CuAssertPtrNotNull(tc, f);
|
||||
CuAssertStrEquals(tc, "Hodor", f->name);
|
||||
CuAssertPtrEquals(tc, 0, f->units);
|
||||
CuAssertPtrEquals(tc, NULL, f->units);
|
||||
factions = f;
|
||||
|
||||
mstream_done(&data.strm);
|
||||
|
@ -179,7 +179,7 @@ static void test_readwrite_building(CuTest * tc)
|
|||
b = read_building(&data);
|
||||
CuAssertPtrNotNull(tc, b);
|
||||
CuAssertStrEquals(tc, "Hodor", b->name);
|
||||
CuAssertPtrEquals(tc, 0, b->region);
|
||||
CuAssertPtrEquals(tc, NULL, b->region);
|
||||
b->region = r;
|
||||
r->buildings = b;
|
||||
|
||||
|
@ -212,7 +212,7 @@ static void test_readwrite_ship(CuTest * tc)
|
|||
sh = read_ship(&data);
|
||||
CuAssertPtrNotNull(tc, sh);
|
||||
CuAssertStrEquals(tc, "Hodor", sh->name);
|
||||
CuAssertPtrEquals(tc, 0, sh->region);
|
||||
CuAssertPtrEquals(tc, NULL, sh->region);
|
||||
sh->region = r;
|
||||
r->ships = sh;
|
||||
|
||||
|
@ -233,7 +233,7 @@ static void test_readwrite_attrib(CuTest *tc) {
|
|||
gamedata_init(&data, &store, RELEASE_VERSION);
|
||||
write_attribs(data.store, a, NULL);
|
||||
a_removeall(&a, NULL);
|
||||
CuAssertPtrEquals(tc, 0, a);
|
||||
CuAssertPtrEquals(tc, NULL, a);
|
||||
|
||||
data.strm.api->rewind(data.strm.handle);
|
||||
read_attribs(&data, &a, NULL);
|
||||
|
@ -262,7 +262,7 @@ static void test_readwrite_dead_faction_group(CuTest *tc) {
|
|||
f = test_create_faction(NULL);
|
||||
fno = f->no;
|
||||
CuAssertPtrEquals(tc, f, factions);
|
||||
CuAssertPtrEquals(tc, 0, f->next);
|
||||
CuAssertPtrEquals(tc, NULL, f->next);
|
||||
f2 = test_create_faction(NULL);
|
||||
CuAssertPtrEquals(tc, f2, factions->next);
|
||||
u = test_create_unit(f2, test_create_region(0, 0, NULL));
|
||||
|
@ -281,14 +281,14 @@ static void test_readwrite_dead_faction_group(CuTest *tc) {
|
|||
f = f2 = NULL;
|
||||
data.strm.api->rewind(data.strm.handle);
|
||||
read_game(&data);
|
||||
CuAssertPtrEquals(tc, 0, findfaction(fno));
|
||||
CuAssertPtrEquals(tc, NULL, findfaction(fno));
|
||||
f2 = factions;
|
||||
CuAssertPtrNotNull(tc, f2);
|
||||
u = f2->units;
|
||||
CuAssertPtrNotNull(tc, u);
|
||||
g = get_group(u);
|
||||
CuAssertPtrNotNull(tc, g);
|
||||
CuAssertPtrEquals(tc, 0, g->allies);
|
||||
CuAssertPtrEquals(tc, NULL, g->allies);
|
||||
mstream_done(&data.strm);
|
||||
gamedata_done(&data);
|
||||
test_teardown();
|
||||
|
@ -319,10 +319,10 @@ static void test_readwrite_dead_faction_regionowner(CuTest *tc) {
|
|||
mstream_done(&data.strm);
|
||||
gamedata_done(&data);
|
||||
f = factions;
|
||||
CuAssertPtrEquals(tc, 0, f);
|
||||
CuAssertPtrEquals(tc, NULL, f);
|
||||
r = regions;
|
||||
CuAssertPtrNotNull(tc, r);
|
||||
CuAssertPtrEquals(tc, 0, region_get_owner(r));
|
||||
CuAssertPtrEquals(tc, NULL, region_get_owner(r));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -359,7 +359,7 @@ static void test_readwrite_dead_faction_changefaction(CuTest *tc) {
|
|||
CuAssertPtrNotNull(tc, r);
|
||||
u = r->units;
|
||||
CuAssertPtrNotNull(tc, u);
|
||||
CuAssertPtrEquals(tc, 0, a_find(u->attribs, &at_eventhandler));
|
||||
CuAssertPtrEquals(tc, NULL, a_find(u->attribs, &at_eventhandler));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -396,7 +396,7 @@ static void test_readwrite_dead_faction_createunit(CuTest *tc) {
|
|||
CuAssertPtrNotNull(tc, r);
|
||||
u = r->units;
|
||||
CuAssertPtrNotNull(tc, u);
|
||||
CuAssertPtrEquals(tc, 0, a_find(u->attribs, &at_eventhandler));
|
||||
CuAssertPtrEquals(tc, NULL, a_find(u->attribs, &at_eventhandler));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
|
|
@ -278,7 +278,7 @@ static void test_shipowner_goes_to_same_faction_after_leave(CuTest * tc)
|
|||
leave_ship(u3);
|
||||
CuAssertPtrEquals(tc, u2, ship_owner(sh));
|
||||
leave_ship(u2);
|
||||
CuAssertPtrEquals(tc, 0, ship_owner(sh));
|
||||
CuAssertPtrEquals(tc, NULL, ship_owner(sh));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -311,7 +311,7 @@ static void test_shipowner_resets_when_empty(CuTest * tc)
|
|||
u_set_ship(u, sh);
|
||||
CuAssertPtrEquals(tc, u, ship_owner(sh));
|
||||
u->number = 0;
|
||||
CuAssertPtrEquals(tc, 0, ship_owner(sh));
|
||||
CuAssertPtrEquals(tc, NULL, ship_owner(sh));
|
||||
u->number = 1;
|
||||
CuAssertPtrEquals(tc, u, ship_owner(sh));
|
||||
test_teardown();
|
||||
|
@ -353,7 +353,7 @@ void test_shipowner_goes_to_empty_unit_after_leave(CuTest * tc)
|
|||
leave_ship(u1);
|
||||
CuAssertPtrEquals(tc, u3, ship_owner(sh));
|
||||
leave_ship(u3);
|
||||
CuAssertPtrEquals(tc, 0, ship_owner(sh));
|
||||
CuAssertPtrEquals(tc, NULL, ship_owner(sh));
|
||||
u2->number = 1;
|
||||
CuAssertPtrEquals(tc, u2, ship_owner(sh));
|
||||
test_teardown();
|
||||
|
@ -365,8 +365,8 @@ static void test_stype_defaults(CuTest *tc) {
|
|||
stype = st_get_or_create("hodor");
|
||||
CuAssertPtrNotNull(tc, stype);
|
||||
CuAssertStrEquals(tc, "hodor", stype->_name);
|
||||
CuAssertPtrEquals(tc, 0, stype->construction);
|
||||
CuAssertPtrEquals(tc, 0, stype->coasts);
|
||||
CuAssertPtrEquals(tc, NULL, stype->construction);
|
||||
CuAssertPtrEquals(tc, NULL, stype->coasts);
|
||||
CuAssertDblEquals(tc, 0.0, stype->damage, 0.0);
|
||||
CuAssertDblEquals(tc, 1.0, stype->storm, 0.0);
|
||||
CuAssertDblEquals(tc, 1.0, stype->tac_bonus, 0.01);
|
||||
|
|
|
@ -17,8 +17,8 @@ static void test_create_a_spell(CuTest * tc)
|
|||
spell * sp;
|
||||
|
||||
test_setup();
|
||||
CuAssertPtrEquals(tc, 0, spells);
|
||||
CuAssertPtrEquals(tc, 0, find_spell("testspell"));
|
||||
CuAssertPtrEquals(tc, NULL, spells);
|
||||
CuAssertPtrEquals(tc, NULL, find_spell("testspell"));
|
||||
|
||||
sp = create_spell("testspell");
|
||||
CuAssertPtrEquals(tc, sp, find_spell("testspell"));
|
||||
|
@ -37,13 +37,13 @@ static void test_create_duplicate_spell(CuTest * tc)
|
|||
test_log_stderr(0); /* suppress the "duplicate spell" error message */
|
||||
log = test_log_start(LOG_CPERROR, &sl);
|
||||
|
||||
CuAssertPtrEquals(tc, 0, find_spell("testspell"));
|
||||
CuAssertPtrEquals(tc, NULL, find_spell("testspell"));
|
||||
|
||||
sp = create_spell("testspell");
|
||||
CuAssertPtrEquals(tc, 0, create_spell("testspell"));
|
||||
CuAssertPtrEquals(tc, NULL, create_spell("testspell"));
|
||||
CuAssertPtrNotNull(tc, sl);
|
||||
CuAssertStrEquals(tc, "create_spell: duplicate name '%s'", sl->s);
|
||||
CuAssertPtrEquals(tc, 0, sl->next);
|
||||
CuAssertPtrEquals(tc, NULL, sl->next);
|
||||
CuAssertPtrEquals(tc, sp, find_spell("testspell"));
|
||||
test_log_stop(log, sl);
|
||||
test_log_stderr(1); /* or teardown complains that stderr logging is off */
|
||||
|
|
|
@ -25,7 +25,7 @@ void test_named_spellbooks(CuTest * tc)
|
|||
|
||||
sb = create_spellbook(0);
|
||||
CuAssertPtrNotNull(tc, sb);
|
||||
CuAssertPtrEquals(tc, 0, sb->name);
|
||||
CuAssertPtrEquals(tc, NULL, sb->name);
|
||||
spellbook_clear(sb);
|
||||
free(sb);
|
||||
|
||||
|
|
|
@ -55,12 +55,6 @@ struct terrain_type;
|
|||
struct unit;
|
||||
struct weapon_type;
|
||||
|
||||
typedef struct ursprung {
|
||||
struct ursprung *next;
|
||||
int id;
|
||||
int x, y;
|
||||
} ursprung;
|
||||
|
||||
/* seen_mode: visibility in the report */
|
||||
typedef enum {
|
||||
seen_none,
|
||||
|
|
|
@ -42,7 +42,7 @@ static void test_remove_empty_units(CuTest *tc) {
|
|||
CuAssertPtrNotNull(tc, findunit(uid));
|
||||
u->number = 0;
|
||||
remove_empty_units();
|
||||
CuAssertPtrEquals(tc, 0, findunit(uid));
|
||||
CuAssertPtrEquals(tc, NULL, findunit(uid));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -61,9 +61,9 @@ static void test_remove_empty_units_in_region(CuTest *tc) {
|
|||
CuAssertPtrNotNull(tc, findunit(uid));
|
||||
u->number = 0;
|
||||
remove_empty_units_in_region(u->region);
|
||||
CuAssertPtrEquals(tc, 0, findunit(uid));
|
||||
CuAssertPtrEquals(tc, 0, u->nextF);
|
||||
CuAssertPtrEquals(tc, 0, u->region);
|
||||
CuAssertPtrEquals(tc, NULL, findunit(uid));
|
||||
CuAssertPtrEquals(tc, NULL, u->nextF);
|
||||
CuAssertPtrEquals(tc, NULL, u->region);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -78,7 +78,7 @@ static void test_remove_units_without_faction(CuTest *tc) {
|
|||
uid = u->no;
|
||||
u_setfaction(u, 0);
|
||||
remove_empty_units_in_region(u->region);
|
||||
CuAssertPtrEquals(tc, 0, findunit(uid));
|
||||
CuAssertPtrEquals(tc, NULL, findunit(uid));
|
||||
CuAssertIntEquals(tc, 0, u->number);
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -94,7 +94,7 @@ static void test_remove_units_with_dead_faction(CuTest *tc) {
|
|||
uid = u->no;
|
||||
u->faction->_alive = false;
|
||||
remove_empty_units_in_region(u->region);
|
||||
CuAssertPtrEquals(tc, 0, findunit(uid));
|
||||
CuAssertPtrEquals(tc, NULL, findunit(uid));
|
||||
CuAssertIntEquals(tc, 0, u->number);
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -308,16 +308,16 @@ static void test_inside_building(CuTest *tc) {
|
|||
|
||||
b->size = 1;
|
||||
scale_number(u, 1);
|
||||
CuAssertPtrEquals(tc, 0, inside_building(u));
|
||||
CuAssertPtrEquals(tc, NULL, inside_building(u));
|
||||
u->building = b;
|
||||
CuAssertPtrEquals(tc, b, inside_building(u));
|
||||
scale_number(u, 2);
|
||||
CuAssertPtrEquals(tc, 0, inside_building(u));
|
||||
CuAssertPtrEquals(tc, NULL, inside_building(u));
|
||||
b->size = 2;
|
||||
CuAssertPtrEquals(tc, b, inside_building(u));
|
||||
u = test_create_unit(u->faction, u->region);
|
||||
u->building = b;
|
||||
CuAssertPtrEquals(tc, 0, inside_building(u));
|
||||
CuAssertPtrEquals(tc, NULL, inside_building(u));
|
||||
b->size = 3;
|
||||
CuAssertPtrEquals(tc, b, inside_building(u));
|
||||
test_teardown();
|
||||
|
@ -397,7 +397,7 @@ static void test_unit_description(CuTest *tc) {
|
|||
rc = test_create_race("hodor");
|
||||
u = test_create_unit(test_create_faction(rc), test_create_region(0, 0, NULL));
|
||||
|
||||
CuAssertPtrEquals(tc, 0, u->display);
|
||||
CuAssertPtrEquals(tc, NULL, u->display);
|
||||
CuAssertStrEquals(tc, 0, u_description(u, lang));
|
||||
u->display = str_strdup("Hodor");
|
||||
CuAssertStrEquals(tc, "Hodor", u_description(u, NULL));
|
||||
|
@ -428,37 +428,37 @@ static void test_remove_unit(CuTest *tc) {
|
|||
CuAssertPtrEquals(tc, u1, f->units);
|
||||
CuAssertPtrEquals(tc, u2, u1->nextF);
|
||||
CuAssertPtrEquals(tc, u1, u2->prevF);
|
||||
CuAssertPtrEquals(tc, 0, u2->nextF);
|
||||
CuAssertPtrEquals(tc, NULL, u2->nextF);
|
||||
uno = u1->no;
|
||||
region_setresource(r, rtype, 0);
|
||||
i_change(&u1->items, rtype->itype, 100);
|
||||
remove_unit(&r->units, u1);
|
||||
CuAssertIntEquals(tc, 0, u1->number);
|
||||
CuAssertPtrEquals(tc, 0, u1->region);
|
||||
CuAssertPtrEquals(tc, NULL, u1->region);
|
||||
/* money is given to a survivor: */
|
||||
CuAssertPtrEquals(tc, 0, u1->items);
|
||||
CuAssertPtrEquals(tc, NULL, u1->items);
|
||||
CuAssertIntEquals(tc, 0, region_getresource(r, rtype));
|
||||
CuAssertIntEquals(tc, 100, i_get(u2->items, rtype->itype));
|
||||
|
||||
/* unit is removed from f->units: */
|
||||
CuAssertPtrEquals(tc, 0, u1->nextF);
|
||||
CuAssertPtrEquals(tc, NULL, u1->nextF);
|
||||
CuAssertPtrEquals(tc, u2, f->units);
|
||||
CuAssertPtrEquals(tc, 0, u2->nextF);
|
||||
CuAssertPtrEquals(tc, 0, u2->prevF);
|
||||
CuAssertPtrEquals(tc, NULL, u2->nextF);
|
||||
CuAssertPtrEquals(tc, NULL, u2->prevF);
|
||||
/* unit is no longer in r->units: */
|
||||
CuAssertPtrEquals(tc, u2, r->units);
|
||||
CuAssertPtrEquals(tc, 0, u2->next);
|
||||
CuAssertPtrEquals(tc, NULL, u2->next);
|
||||
|
||||
/* unit is in deleted_units: */
|
||||
CuAssertPtrEquals(tc, 0, findunit(uno));
|
||||
CuAssertPtrEquals(tc, NULL, findunit(uno));
|
||||
CuAssertPtrEquals(tc, f, dfindhash(uno));
|
||||
|
||||
remove_unit(&r->units, u2);
|
||||
/* no survivor, give money to peasants: */
|
||||
CuAssertIntEquals(tc, 100, region_getresource(r, rtype));
|
||||
/* there are now no more units: */
|
||||
CuAssertPtrEquals(tc, 0, r->units);
|
||||
CuAssertPtrEquals(tc, 0, f->units);
|
||||
CuAssertPtrEquals(tc, NULL, r->units);
|
||||
CuAssertPtrEquals(tc, NULL, f->units);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
|
|
@ -2911,7 +2911,7 @@ void maketemp_cmd(unit *u, order **olist)
|
|||
order *deford = default_order(u2->faction->locale);
|
||||
if (deford) {
|
||||
set_order(&u2->thisorder, NULL);
|
||||
addlist(&u2->orders, deford);
|
||||
unit_addorder(u2, deford);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -123,8 +123,8 @@ static void test_enter_building(CuTest * tc)
|
|||
rc->flags = RCF_SWIM;
|
||||
u->building = 0;
|
||||
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, false));
|
||||
CuAssertPtrEquals(tc, 0, u->building);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->building);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
|
||||
CuAssertIntEquals(tc, 0, enter_building(u, NULL, b->no, true));
|
||||
CuAssertPtrNotNull(tc, u->faction->msgs);
|
||||
|
@ -164,8 +164,8 @@ static void test_enter_ship(CuTest * tc)
|
|||
rc->flags = RCF_SWIM;
|
||||
u->ship = 0;
|
||||
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, false));
|
||||
CuAssertPtrEquals(tc, 0, u->ship);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->ship);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
|
||||
CuAssertIntEquals(tc, 0, enter_ship(u, NULL, sh->no, true));
|
||||
CuAssertPtrNotNull(tc, u->faction->msgs);
|
||||
|
@ -1040,8 +1040,8 @@ static void test_long_order_normal(CuTest *tc) {
|
|||
CuAssertIntEquals(tc, 0, fval(u, UFL_MOVED));
|
||||
CuAssertIntEquals(tc, 0, fval(u, UFL_LONGACTION));
|
||||
CuAssertPtrNotNull(tc, u->orders);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, 0, u->old_orders);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->old_orders);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -1051,9 +1051,9 @@ static void test_long_order_none(CuTest *tc) {
|
|||
test_setup();
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
update_long_order(u);
|
||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
||||
CuAssertPtrEquals(tc, 0, u->orders);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||
CuAssertPtrEquals(tc, NULL, u->orders);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -1065,9 +1065,9 @@ static void test_long_order_cast(CuTest *tc) {
|
|||
unit_addorder(u, create_order(K_CAST, u->faction->locale, NULL));
|
||||
unit_addorder(u, create_order(K_CAST, u->faction->locale, NULL));
|
||||
update_long_order(u);
|
||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
||||
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||
CuAssertPtrNotNull(tc, u->orders);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -1080,9 +1080,9 @@ static void test_long_order_buy_sell(CuTest *tc) {
|
|||
unit_addorder(u, create_order(K_SELL, u->faction->locale, NULL));
|
||||
unit_addorder(u, create_order(K_SELL, u->faction->locale, NULL));
|
||||
update_long_order(u);
|
||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
||||
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||
CuAssertPtrNotNull(tc, u->orders);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -1108,7 +1108,7 @@ static void test_long_order_multi_buy(CuTest *tc) {
|
|||
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
||||
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
||||
update_long_order(u);
|
||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
||||
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||
CuAssertPtrNotNull(tc, u->orders);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52"));
|
||||
test_teardown();
|
||||
|
@ -1123,9 +1123,9 @@ static void test_long_order_multi_sell(CuTest *tc) {
|
|||
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
||||
unit_addorder(u, create_order(K_SELL, u->faction->locale, 0));
|
||||
update_long_order(u);
|
||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
||||
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||
CuAssertPtrNotNull(tc, u->orders);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -1137,7 +1137,7 @@ static void test_long_order_buy_cast(CuTest *tc) {
|
|||
unit_addorder(u, create_order(K_BUY, u->faction->locale, 0));
|
||||
unit_addorder(u, create_order(K_CAST, u->faction->locale, 0));
|
||||
update_long_order(u);
|
||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
||||
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||
CuAssertPtrNotNull(tc, u->orders);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(u->faction->msgs, "error52"));
|
||||
test_teardown();
|
||||
|
@ -1155,7 +1155,7 @@ static void test_long_order_hungry(CuTest *tc) {
|
|||
update_long_order(u);
|
||||
CuAssertIntEquals(tc, K_WORK, getkeyword(u->thisorder));
|
||||
CuAssertPtrNotNull(tc, u->orders);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -1167,7 +1167,7 @@ static void test_ally_cmd_errors(CuTest *tc) {
|
|||
test_setup();
|
||||
u = test_create_unit(test_create_faction(NULL), test_create_region(0, 0, NULL));
|
||||
fid = u->faction->no + 1;
|
||||
CuAssertPtrEquals(tc, 0, findfaction(fid));
|
||||
CuAssertPtrEquals(tc, NULL, findfaction(fid));
|
||||
|
||||
ord = create_order(K_ALLY, u->faction->locale, itoa36(fid));
|
||||
ally_cmd(u, ord);
|
||||
|
@ -1264,25 +1264,25 @@ static void test_ally_cmd(CuTest *tc) {
|
|||
|
||||
ord = create_order(K_ALLY, f->locale, "%s", itoa36(f->no));
|
||||
ally_cmd(u, ord);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
CuAssertIntEquals(tc, HELP_ALL, alliedfaction(0, u->faction, f, HELP_ALL));
|
||||
free_order(ord);
|
||||
|
||||
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_NOT]));
|
||||
ally_cmd(u, ord);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
|
||||
free_order(ord);
|
||||
|
||||
ord = create_order(K_ALLY, f->locale, "%s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]));
|
||||
ally_cmd(u, ord);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
CuAssertIntEquals(tc, HELP_GUARD, alliedfaction(0, u->faction, f, HELP_ALL));
|
||||
free_order(ord);
|
||||
|
||||
ord = create_order(K_ALLY, f->locale, "%s %s %s", itoa36(f->no), LOC(f->locale, parameters[P_GUARD]), LOC(f->locale, parameters[P_NOT]));
|
||||
ally_cmd(u, ord);
|
||||
CuAssertPtrEquals(tc, 0, u->faction->msgs);
|
||||
CuAssertPtrEquals(tc, NULL, u->faction->msgs);
|
||||
CuAssertIntEquals(tc, 0, alliedfaction(0, u->faction, f, HELP_ALL));
|
||||
free_order(ord);
|
||||
|
||||
|
@ -1374,7 +1374,7 @@ static void test_mail_unit_no_msg(CuTest *tc) {
|
|||
f = u->faction;
|
||||
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_UNIT]), itoa36(u->no));
|
||||
mail_cmd(u, ord);
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "unitmessage"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "unitmessage"));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
||||
free_order(ord);
|
||||
test_teardown();
|
||||
|
@ -1389,7 +1389,7 @@ static void test_mail_faction_no_msg(CuTest *tc) {
|
|||
f = u->faction;
|
||||
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no));
|
||||
mail_cmd(u, ord);
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "regionmessage"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "regionmessage"));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
||||
free_order(ord);
|
||||
test_teardown();
|
||||
|
@ -1404,7 +1404,7 @@ static void test_mail_faction_no_target(CuTest *tc) {
|
|||
f = u->faction;
|
||||
ord = create_order(K_MAIL, f->locale, "%s %s", LOC(f->locale, parameters[P_FACTION]), itoa36(f->no+1));
|
||||
mail_cmd(u, ord);
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "regionmessage"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "regionmessage"));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error66"));
|
||||
free_order(ord);
|
||||
test_teardown();
|
||||
|
@ -1419,7 +1419,7 @@ static void test_mail_region_no_msg(CuTest *tc) {
|
|||
f = u->faction;
|
||||
ord = create_order(K_MAIL, f->locale, LOC(f->locale, parameters[P_REGION]));
|
||||
mail_cmd(u, ord);
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(u->region->msgs, "mail_result"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(u->region->msgs, "mail_result"));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error30"));
|
||||
free_order(ord);
|
||||
test_teardown();
|
||||
|
@ -1457,14 +1457,14 @@ static void test_show_without_item(CuTest *tc)
|
|||
locale_setstring(loc, "iteminfo::testitem", "testdescription");
|
||||
|
||||
reshow_cmd(u, ord);
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error21"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error21"));
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(f->msgs, "error36"));
|
||||
test_clear_messages(f);
|
||||
|
||||
i_add(&(u->items), i_new(itype, 1));
|
||||
reshow_cmd(u, ord);
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error21"));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "error36"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error21"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "error36"));
|
||||
test_clear_messages(f);
|
||||
|
||||
free_order(ord);
|
||||
|
@ -1609,7 +1609,7 @@ static void test_demon_hunger(CuTest * tc)
|
|||
get_food(r);
|
||||
|
||||
CuAssertIntEquals(tc, 20, i_get(u->items, rtype->itype));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "malnourish"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "malnourish"));
|
||||
|
||||
config_set("hunger.demon.peasant_tolerance", "0");
|
||||
|
||||
|
|
|
@ -28,7 +28,7 @@ void
|
|||
insert_selection(list_selection ** p_sel, list_selection * prev,
|
||||
const char *str, void *payload)
|
||||
{
|
||||
list_selection *sel = calloc(sizeof(list_selection), 1);
|
||||
list_selection *sel = (list_selection *)calloc(1, sizeof(list_selection));
|
||||
sel->str = str_strdup(str);
|
||||
sel->data = payload;
|
||||
if (*p_sel) {
|
||||
|
@ -56,7 +56,7 @@ const char *str, void *payload)
|
|||
list_selection **push_selection(list_selection ** p_sel, char *str,
|
||||
void *payload)
|
||||
{
|
||||
list_selection *sel = calloc(sizeof(list_selection), 1);
|
||||
list_selection *sel = (list_selection *)calloc(1, sizeof(list_selection));
|
||||
list_selection *prev = NULL;
|
||||
sel->str = str;
|
||||
sel->data = payload;
|
||||
|
|
|
@ -2950,7 +2950,7 @@ void free_spellbook(spellbook *sb) {
|
|||
free(sb);
|
||||
}
|
||||
|
||||
static int free_spellbook_cb(const void *match, const void *key, size_t keylen, void *data) {
|
||||
static int free_spellbook_cb(void *match, const void *key, size_t keylen, void *data) {
|
||||
const sb_entry *ent = (const sb_entry *)match;
|
||||
UNUSED_ARG(data);
|
||||
UNUSED_ARG(keylen);
|
||||
|
|
|
@ -45,7 +45,7 @@ void test_updatespells(CuTest * tc)
|
|||
CuAssertPtrNotNull(tc, book);
|
||||
spellbook_add(book, sp, 1);
|
||||
|
||||
CuAssertPtrEquals(tc, 0, f->spellbook);
|
||||
CuAssertPtrEquals(tc, NULL, f->spellbook);
|
||||
pick_random_spells(f, 1, book, 1);
|
||||
CuAssertPtrNotNull(tc, f->spellbook);
|
||||
CuAssertIntEquals(tc, 1, selist_length(f->spellbook->spells));
|
||||
|
@ -191,7 +191,7 @@ void test_getspell_unit(CuTest * tc)
|
|||
sp = create_spell("testspell");
|
||||
locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp");
|
||||
|
||||
CuAssertPtrEquals(tc, 0, unit_getspell(u, "Herp-a-derp", lang));
|
||||
CuAssertPtrEquals(tc, NULL, unit_getspell(u, "Herp-a-derp", lang));
|
||||
|
||||
unit_add_spell(u, 0, sp, 1);
|
||||
CuAssertPtrNotNull(tc, unit_getspell(u, "Herp-a-derp", lang));
|
||||
|
@ -220,7 +220,7 @@ void test_getspell_faction(CuTest * tc)
|
|||
sp = create_spell("testspell");
|
||||
locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp");
|
||||
|
||||
CuAssertPtrEquals(tc, 0, unit_getspell(u, "Herp-a-derp", lang));
|
||||
CuAssertPtrEquals(tc, NULL, unit_getspell(u, "Herp-a-derp", lang));
|
||||
|
||||
f->spellbook = create_spellbook(0);
|
||||
spellbook_add(f->spellbook, sp, 1);
|
||||
|
@ -250,7 +250,7 @@ void test_getspell_school(CuTest * tc)
|
|||
sp = create_spell("testspell");
|
||||
locale_setstring(lang, mkname("spell", sp->sname), "Herp-a-derp");
|
||||
|
||||
CuAssertPtrEquals(tc, 0, unit_getspell(u, "Herp-a-derp", lang));
|
||||
CuAssertPtrEquals(tc, NULL, unit_getspell(u, "Herp-a-derp", lang));
|
||||
|
||||
book = faction_get_spellbook(f);
|
||||
CuAssertPtrNotNull(tc, book);
|
||||
|
@ -287,7 +287,7 @@ void test_set_pre_combatspell(CuTest * tc)
|
|||
CuAssertIntEquals(tc, 1, get_combatspelllevel(u, index));
|
||||
unset_combatspell(u, sp);
|
||||
CuAssertIntEquals(tc, 0, get_combatspelllevel(u, index));
|
||||
CuAssertPtrEquals(tc, 0, (spell *)get_combatspell(u, index));
|
||||
CuAssertPtrEquals(tc, NULL, (spell *)get_combatspell(u, index));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -319,7 +319,7 @@ void test_set_main_combatspell(CuTest * tc)
|
|||
CuAssertIntEquals(tc, 1, get_combatspelllevel(u, index));
|
||||
unset_combatspell(u, sp);
|
||||
CuAssertIntEquals(tc, 0, get_combatspelllevel(u, index));
|
||||
CuAssertPtrEquals(tc, 0, (spell *)get_combatspell(u, index));
|
||||
CuAssertPtrEquals(tc, NULL, (spell *)get_combatspell(u, index));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -351,7 +351,7 @@ void test_set_post_combatspell(CuTest * tc)
|
|||
CuAssertIntEquals(tc, 1, get_combatspelllevel(u, index));
|
||||
unset_combatspell(u, sp);
|
||||
CuAssertIntEquals(tc, 0, get_combatspelllevel(u, index));
|
||||
CuAssertPtrEquals(tc, 0, (spell *)get_combatspell(u, index));
|
||||
CuAssertPtrEquals(tc, NULL, (spell *)get_combatspell(u, index));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
|
|
@ -335,6 +335,8 @@ int main(int argc, char **argv)
|
|||
game_done();
|
||||
lua_done(L);
|
||||
log_close();
|
||||
stats_write(stdout, "");
|
||||
stats_close();
|
||||
if (d) {
|
||||
iniparser_freedict(d);
|
||||
}
|
||||
|
|
|
@ -133,7 +133,7 @@ newfaction *read_newfactions(const char *filename)
|
|||
if (nf) {
|
||||
continue;
|
||||
}
|
||||
nf = calloc(sizeof(newfaction), 1);
|
||||
nf = (newfaction *)calloc(1, sizeof(newfaction));
|
||||
if (check_email(email) == 0) {
|
||||
nf->email = str_strdup(email);
|
||||
} else {
|
||||
|
|
|
@ -56,7 +56,6 @@
|
|||
#include <util/base36.h>
|
||||
#include "util/keyword.h"
|
||||
#include "util/language.h"
|
||||
#include <util/lists.h>
|
||||
#include <util/log.h>
|
||||
#include <util/rand.h>
|
||||
#include <util/rng.h>
|
||||
|
@ -203,6 +202,7 @@ void monsters_desert(struct faction *monsters)
|
|||
int monster_attacks(unit * monster, bool rich_only)
|
||||
{
|
||||
const race *rc_serpent = get_race(RC_SEASERPENT);
|
||||
int result = -1;
|
||||
if (monster->status < ST_AVOID) {
|
||||
region *r = monster->region;
|
||||
unit *u2;
|
||||
|
@ -220,15 +220,16 @@ int monster_attacks(unit * monster, bool rich_only)
|
|||
if (!rich_only || m > 0) {
|
||||
order *ord = monster_attack(monster, u2);
|
||||
if (ord) {
|
||||
addlist(&monster->orders, ord);
|
||||
result = 0;
|
||||
unit_addorder(monster, ord);
|
||||
money += m;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
return money;
|
||||
return money > 0 ? money : result;
|
||||
}
|
||||
return 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
static order *get_money_for_dragon(region * r, unit * udragon, int wanted)
|
||||
|
@ -249,7 +250,8 @@ static order *get_money_for_dragon(region * r, unit * udragon, int wanted)
|
|||
* und holt sich Silber von Einheiten, vorausgesetzt er bewacht bereits */
|
||||
money = 0;
|
||||
if (attacks && is_guard(udragon)) {
|
||||
money += monster_attacks(udragon, true);
|
||||
int m = monster_attacks(udragon, true);
|
||||
if (m > 0) money += m;
|
||||
}
|
||||
|
||||
/* falls die einnahmen erreicht werden, bleibt das monster noch eine */
|
||||
|
@ -606,6 +608,7 @@ static void recruit_dracoids(unit * dragon, int size)
|
|||
region *r = dragon->region;
|
||||
const struct item *weapon = NULL;
|
||||
unit *un = create_unit(r, f, size, get_race(RC_DRACOID), 0, NULL, NULL);
|
||||
stats_count("monsters.create.dracoid", 1);
|
||||
|
||||
fset(un, UFL_ISNEW | UFL_MOVED);
|
||||
|
||||
|
@ -737,19 +740,12 @@ void plan_monsters(faction * f)
|
|||
|
||||
for (r = regions; r; r = r->next) {
|
||||
unit *u;
|
||||
bool attacking = false;
|
||||
/* Tiny optimization: Monsters on land only attack randomly when
|
||||
* they are guarding. If nobody is guarding this region (RF_GUARDED),
|
||||
* there can't be any random attacks.
|
||||
*/
|
||||
if (!r->land || r->flags & RF_GUARDED) {
|
||||
attacking = chance(attack_chance);
|
||||
}
|
||||
|
||||
for (u = r->units; u; u = u->next) {
|
||||
const race *rc = u_race(u);
|
||||
attrib *ta;
|
||||
order *long_order = NULL;
|
||||
bool can_move = true;
|
||||
|
||||
/* Ab hier nur noch Befehle f<>r NPC-Einheiten. */
|
||||
if (u->faction!=f)
|
||||
|
@ -760,16 +756,19 @@ void plan_monsters(faction * f)
|
|||
u->flags &= ~UFL_ANON_FACTION;
|
||||
}
|
||||
|
||||
/* Befehle m<>ssen jede Runde neu gegeben werden: */
|
||||
free_orders(&u->orders);
|
||||
if (skill_enabled(SK_PERCEPTION)) {
|
||||
/* Monster bekommen jede Runde ein paar Tage Wahrnehmung dazu */
|
||||
produceexp(u, SK_PERCEPTION, u->number);
|
||||
}
|
||||
|
||||
if (attacking && (!r->land || is_guard(u))) {
|
||||
monster_attacks(u, false);
|
||||
/* Befehle m<>ssen jede Runde neu gegeben werden: */
|
||||
free_orders(&u->orders);
|
||||
|
||||
/* All monsters guard the region: */
|
||||
if (u->status < ST_FLEE && !monster_is_waiting(u) && r->land) {
|
||||
unit_addorder(u, create_order(K_GUARD, u->faction->locale, NULL));
|
||||
}
|
||||
|
||||
/* units with a plan to kill get ATTACK orders (even if they don't guard): */
|
||||
ta = a_find(u->attribs, &at_hate);
|
||||
if (ta && !monster_is_waiting(u)) {
|
||||
|
@ -777,7 +776,8 @@ void plan_monsters(faction * f)
|
|||
if (tu && tu->region == r) {
|
||||
order * ord = monster_attack(u, tu);
|
||||
if (ord) {
|
||||
addlist(&u->orders, ord);
|
||||
unit_addorder(u, ord);
|
||||
can_move = false;
|
||||
}
|
||||
}
|
||||
else if (tu) {
|
||||
|
@ -786,17 +786,22 @@ void plan_monsters(faction * f)
|
|||
allowed = allowed_fly;
|
||||
}
|
||||
long_order = plan_move_to_target(u, tu->region, 2, allowed);
|
||||
can_move = false;
|
||||
}
|
||||
else
|
||||
a_remove(&u->attribs, ta);
|
||||
}
|
||||
/* All monsters guard the region: */
|
||||
if (u->status < ST_FLEE && !monster_is_waiting(u) && r->land) {
|
||||
addlist(&u->orders, create_order(K_GUARD, u->faction->locale, NULL));
|
||||
else if (!r->land || is_guard(u)) {
|
||||
if (chance(attack_chance)) {
|
||||
int m = monster_attacks(u, false);
|
||||
if (m >= 0) {
|
||||
can_move = false;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Einheiten mit Bewegungsplan kriegen ein NACH: */
|
||||
if (long_order == NULL) {
|
||||
if (can_move && long_order == NULL) {
|
||||
ta = a_find(u->attribs, &at_targetregion);
|
||||
if (ta) {
|
||||
if (u->region == (region *)ta->data.v) {
|
||||
|
@ -817,7 +822,7 @@ void plan_monsters(faction * f)
|
|||
long_order = plan_dragon(u);
|
||||
}
|
||||
else {
|
||||
if (rc == get_race(RC_SEASERPENT)) {
|
||||
if (can_move && rc == get_race(RC_SEASERPENT)) {
|
||||
long_order = create_order(K_PIRACY, f->locale, NULL);
|
||||
}
|
||||
else {
|
||||
|
@ -827,6 +832,7 @@ void plan_monsters(faction * f)
|
|||
}
|
||||
}
|
||||
}
|
||||
|
||||
if (long_order == NULL && unit_can_study(u)) {
|
||||
/* Einheiten, die Waffenlosen Kampf lernen k<>nnten, lernen es um
|
||||
* zu bewachen: */
|
||||
|
@ -840,7 +846,7 @@ void plan_monsters(faction * f)
|
|||
}
|
||||
|
||||
if (long_order) {
|
||||
addlist(&u->orders, long_order);
|
||||
unit_addorder(u, long_order);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -863,6 +869,7 @@ static int nrand(int handle_start, int sub)
|
|||
|
||||
unit *spawn_seaserpent(region *r, faction *f) {
|
||||
unit *u = create_unit(r, f, 1, get_race(RC_SEASERPENT), 0, NULL, NULL);
|
||||
stats_count("monsters.create.seaserpent", 1);
|
||||
fset(u, UFL_ISNEW | UFL_MOVED);
|
||||
equip_unit(u, "seed_seaserpent");
|
||||
return u;
|
||||
|
@ -903,6 +910,7 @@ void spawn_dragons(void)
|
|||
else {
|
||||
u = create_unit(r, monsters, nrand(30, 20) + 1, get_race(RC_DRAGON), 0, NULL, NULL);
|
||||
}
|
||||
stats_count("monsters.create.dragon", 1);
|
||||
fset(u, UFL_ISNEW | UFL_MOVED);
|
||||
equip_unit(u, "seed_dragon");
|
||||
|
||||
|
@ -935,7 +943,7 @@ void spawn_undead(void)
|
|||
}
|
||||
|
||||
if (r->land && unburied > rpeasants(r) / 20
|
||||
&& rng_int() % 10000 < 200) {
|
||||
&& rng_int() % 10000 < 100) {
|
||||
message *msg;
|
||||
unit *u;
|
||||
/* es ist sinnfrei, wenn irgendwo im Wald 3er-Einheiten Untote entstehen.
|
||||
|
@ -963,6 +971,7 @@ void spawn_undead(void)
|
|||
}
|
||||
|
||||
u = create_unit(r, monsters, undead, rc, 0, NULL, NULL);
|
||||
stats_count("monsters.create.undead", 1);
|
||||
fset(u, UFL_ISNEW | UFL_MOVED);
|
||||
if ((rc == get_race(RC_SKELETON) || rc == get_race(RC_ZOMBIE))
|
||||
&& rng_int() % 10 < 4) {
|
||||
|
|
|
@ -123,7 +123,7 @@ static void test_monsters_waiting(CuTest * tc)
|
|||
setguard(m, true);
|
||||
fset(m, UFL_ISNEW);
|
||||
monster_attacks(m, false);
|
||||
CuAssertPtrEquals(tc, 0, find_order("attack 1", m));
|
||||
CuAssertPtrEquals(tc, NULL, find_order("attack 1", m));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -173,7 +173,7 @@ static void test_monsters_attack_not(CuTest * tc)
|
|||
|
||||
plan_monsters(m->faction);
|
||||
|
||||
CuAssertPtrEquals(tc, 0, find_order("attack 1", m));
|
||||
CuAssertPtrEquals(tc, NULL, find_order("attack 1", m));
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
|
|
@ -225,16 +225,16 @@ static void test_ship_trails(CuTest *tc) {
|
|||
move_ship(sh, r1, r3, NULL);
|
||||
CuAssertPtrEquals(tc, r3, sh->region);
|
||||
CuAssertPtrEquals(tc, sh, r3->ships);
|
||||
CuAssertPtrEquals(tc, 0, r1->ships);
|
||||
CuAssertPtrEquals(tc, 0, a_find(r1->attribs, &at_shiptrail));
|
||||
CuAssertPtrEquals(tc, 0, a_find(r3->attribs, &at_shiptrail));
|
||||
CuAssertPtrEquals(tc, NULL, r1->ships);
|
||||
CuAssertPtrEquals(tc, NULL, a_find(r1->attribs, &at_shiptrail));
|
||||
CuAssertPtrEquals(tc, NULL, a_find(r3->attribs, &at_shiptrail));
|
||||
add_regionlist(&route, r3);
|
||||
add_regionlist(&route, r2);
|
||||
move_ship(sh, r3, r1, route);
|
||||
CuAssertPtrEquals(tc, r1, sh->region);
|
||||
CuAssertPtrEquals(tc, sh, r1->ships);
|
||||
CuAssertPtrEquals(tc, 0, r3->ships);
|
||||
CuAssertPtrEquals(tc, 0, a_find(r1->attribs, &at_shiptrail));
|
||||
CuAssertPtrEquals(tc, NULL, r3->ships);
|
||||
CuAssertPtrEquals(tc, NULL, a_find(r1->attribs, &at_shiptrail));
|
||||
CuAssertPtrNotNull(tc, a_find(r2->attribs, &at_shiptrail));
|
||||
CuAssertPtrNotNull(tc, a_find(r3->attribs, &at_shiptrail));
|
||||
free_regionlist(route);
|
||||
|
@ -258,7 +258,7 @@ static void test_age_trails(CuTest *tc) {
|
|||
a_age(&r1->attribs, r1);
|
||||
CuAssertPtrNotNull(tc, r1->attribs);
|
||||
a_age(&r1->attribs, r1);
|
||||
CuAssertPtrEquals(tc, 0, r1->attribs);
|
||||
CuAssertPtrEquals(tc, NULL, r1->attribs);
|
||||
free_regionlist(route);
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -323,7 +323,7 @@ static void test_ship_empty(CuTest *tc) {
|
|||
movement();
|
||||
CuAssertPtrEquals(tc, fix.sh->region, findregion(0, 0));
|
||||
CuAssertIntEquals(tc, 2, ship_damage_percent(fix.sh));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(fix.f->msgs, "ship_drift"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(fix.f->msgs, "ship_drift"));
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ static void test_no_drift_damage(CuTest *tc) {
|
|||
movement();
|
||||
CuAssertPtrEquals(tc, fix.sh->region, findregion(0, 0));
|
||||
CuAssertIntEquals(tc, 0, ship_damage_percent(fix.sh));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(fix.f->msgs, "ship_drift"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(fix.f->msgs, "ship_drift"));
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -386,7 +386,7 @@ static void test_ship_no_real_overload(CuTest *tc) {
|
|||
movement();
|
||||
CuAssertPtrEquals(tc, fix.u->region, findregion(0, 0));
|
||||
CuAssertIntEquals(tc, 82, ship_damage_percent(fix.sh));
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(fix.f->msgs, "massive_overload"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(fix.f->msgs, "massive_overload"));
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -431,7 +431,7 @@ static void test_ship_ridiculous_overload_bad(CuTest *tc) {
|
|||
movement();
|
||||
CuAssertTrue(tc, ship_damage_percent(fix.sh) > 99);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "massive_overload"));
|
||||
CuAssertPtrEquals(tc, 0, fix.sh->region);
|
||||
CuAssertPtrEquals(tc, NULL, fix.sh->region);
|
||||
CuAssertPtrNotNull(tc, test_find_messagetype(fix.f->msgs, "shipsink"));
|
||||
test_teardown();
|
||||
}
|
||||
|
|
|
@ -16,7 +16,6 @@
|
|||
void orderdb_open(void)
|
||||
{
|
||||
const char *dbname;
|
||||
|
||||
dbname = config_get("game.dbswap");
|
||||
db_driver_open(DB_SWAP, dbname);
|
||||
}
|
||||
|
|
|
@ -106,7 +106,7 @@ static void test_piracy_cmd(CuTest * tc) {
|
|||
u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(u2->faction->no));
|
||||
|
||||
piracy_cmd(u);
|
||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
||||
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||
CuAssertTrue(tc, u->region != r);
|
||||
CuAssertPtrEquals(tc, u2->region, u->region);
|
||||
CuAssertPtrEquals(tc, u2->region, u->ship->region);
|
||||
|
@ -211,7 +211,7 @@ static void test_piracy_cmd_land_to_land(CuTest * tc) {
|
|||
u->thisorder = create_order(K_PIRACY, f->locale, "%s", itoa36(target));
|
||||
|
||||
piracy_cmd(u);
|
||||
CuAssertPtrEquals(tc, 0, u->thisorder);
|
||||
CuAssertPtrEquals(tc, NULL, u->thisorder);
|
||||
CuAssertPtrEquals(tc, r, u->region);
|
||||
|
||||
test_teardown();
|
||||
|
@ -226,7 +226,7 @@ static void test_piracy_cmd_swimmer(CuTest * tc) {
|
|||
r = pirate->region;
|
||||
|
||||
piracy_cmd(pirate);
|
||||
CuAssertPtrEquals(tc, 0, pirate->thisorder);
|
||||
CuAssertPtrEquals(tc, NULL, pirate->thisorder);
|
||||
CuAssertTrue(tc, pirate->region != r);
|
||||
CuAssertPtrEquals(tc, victim->region, pirate->region);
|
||||
CuAssertPtrNotNullMsg(tc, "successful PIRACY message", test_find_messagetype(pirate->faction->msgs, "piratesawvictim"));
|
||||
|
|
|
@ -11,17 +11,17 @@
|
|||
|
||||
static void test_add_prefix(CuTest *tc) {
|
||||
test_setup();
|
||||
CuAssertPtrEquals(tc, 0, race_prefixes);
|
||||
CuAssertPtrEquals(tc, NULL, race_prefixes);
|
||||
CuAssertIntEquals(tc, 0, add_raceprefix("sea"));
|
||||
CuAssertPtrNotNull(tc, race_prefixes);
|
||||
CuAssertStrEquals(tc, "sea", race_prefixes[0]);
|
||||
CuAssertPtrEquals(tc, 0, race_prefixes[1]);
|
||||
CuAssertPtrEquals(tc, NULL, race_prefixes[1]);
|
||||
CuAssertIntEquals(tc, 0, add_raceprefix("moon"));
|
||||
CuAssertStrEquals(tc, "sea", race_prefixes[0]);
|
||||
CuAssertStrEquals(tc, "moon", race_prefixes[1]);
|
||||
CuAssertPtrEquals(tc, 0, race_prefixes[2]);
|
||||
CuAssertPtrEquals(tc, NULL, race_prefixes[2]);
|
||||
free_prefixes();
|
||||
CuAssertPtrEquals(tc, 0, race_prefixes);
|
||||
CuAssertPtrEquals(tc, NULL, race_prefixes);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
|
197
src/report.c
197
src/report.c
|
@ -873,6 +873,8 @@ bool see_border(const connection * b, const faction * f, const region * r)
|
|||
return cs;
|
||||
}
|
||||
|
||||
#define MAX_EDGES 16
|
||||
|
||||
void report_region(struct stream *out, const region * r, faction * f)
|
||||
{
|
||||
int n;
|
||||
|
@ -883,13 +885,13 @@ void report_region(struct stream *out, const region * r, faction * f)
|
|||
attrib *a;
|
||||
const char *tname;
|
||||
struct edge {
|
||||
struct edge *next;
|
||||
char *name;
|
||||
bool transparent;
|
||||
bool block;
|
||||
bool exist[MAXDIRECTIONS];
|
||||
direction_t lastd;
|
||||
} *edges = NULL, *e;
|
||||
} edges[MAX_EDGES];
|
||||
int ne = 0;
|
||||
bool see[MAXDIRECTIONS];
|
||||
char buf[8192];
|
||||
char *bufp = buf;
|
||||
|
@ -908,7 +910,8 @@ void report_region(struct stream *out, const region * r, faction * f)
|
|||
if (!r2)
|
||||
continue;
|
||||
for (b = get_borders(r, r2); b;) {
|
||||
struct edge *edg = edges;
|
||||
int e;
|
||||
struct edge *match = NULL;
|
||||
bool transparent = b->type->transparent(b, f);
|
||||
const char *name = border_name(b, r, f, GF_DETAILED | GF_ARTICLE);
|
||||
|
||||
|
@ -919,18 +922,22 @@ void report_region(struct stream *out, const region * r, faction * f)
|
|||
b = b->next;
|
||||
continue;
|
||||
}
|
||||
while (edg && (edg->transparent != transparent || strcmp(name, edg->name)!=0)) {
|
||||
edg = edg->next;
|
||||
for (e = 0; e!=ne; ++e) {
|
||||
struct edge *edg = edges + e;
|
||||
if (edg->transparent == transparent && 0 == strcmp(name, edg->name)) {
|
||||
match = edg;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (!edg) {
|
||||
edg = calloc(sizeof(struct edge), 1);
|
||||
edg->name = str_strdup(name);
|
||||
edg->transparent = transparent;
|
||||
edg->next = edges;
|
||||
edges = edg;
|
||||
if (match == NULL) {
|
||||
match = edges + ne;
|
||||
match->name = str_strdup(name);
|
||||
match->transparent = transparent;
|
||||
++ne;
|
||||
assert(ne < MAX_EDGES);
|
||||
}
|
||||
edg->lastd = d;
|
||||
edg->exist[d] = true;
|
||||
match->lastd = d;
|
||||
match->exist[d] = true;
|
||||
b = b->next;
|
||||
}
|
||||
}
|
||||
|
@ -1227,27 +1234,22 @@ void report_region(struct stream *out, const region * r, faction * f)
|
|||
nr_curses(out, 0, f, TYP_REGION, r);
|
||||
n = 0;
|
||||
|
||||
if (edges)
|
||||
if (ne > 0) {
|
||||
int e;
|
||||
newline(out);
|
||||
for (e = edges; e; e = e->next) {
|
||||
message *msg;
|
||||
for (e = 0; e != ne; ++e) {
|
||||
message *msg;
|
||||
|
||||
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
||||
if (e->exist[d]) {
|
||||
msg = msg_message(e->transparent ? "nr_border_transparent" : "nr_border_opaque",
|
||||
"object dir", e->name, d);
|
||||
nr_render(msg, f->locale, buf, sizeof(buf), f);
|
||||
msg_release(msg);
|
||||
paragraph(out, buf, 0, 0, 0);
|
||||
for (d = 0; d != MAXDIRECTIONS; ++d) {
|
||||
if (edges[e].exist[d]) {
|
||||
msg = msg_message(edges[e].transparent ? "nr_border_transparent" : "nr_border_opaque",
|
||||
"object dir", edges[e].name, d);
|
||||
nr_render(msg, f->locale, buf, sizeof(buf), f);
|
||||
msg_release(msg);
|
||||
paragraph(out, buf, 0, 0, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if (edges) {
|
||||
while (edges) {
|
||||
e = edges->next;
|
||||
free(edges->name);
|
||||
free(edges);
|
||||
edges = e;
|
||||
free(edges[e].name);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1512,93 +1514,78 @@ static void
|
|||
show_allies(const faction * f, const ally * allies, char *buf, size_t size)
|
||||
{
|
||||
int allierte = 0;
|
||||
int i = 0, h, hh = 0;
|
||||
int bytes, dh = 0;
|
||||
int i = 0, h, hh = 0, dh = 0;
|
||||
const ally *sf;
|
||||
char *bufp = buf; /* buf already contains data */
|
||||
|
||||
--size; /* leave room for a null-terminator */
|
||||
|
||||
|
||||
for (sf = allies; sf; sf = sf->next) {
|
||||
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
|
||||
if (mode > 0)
|
||||
if (mode > 0) {
|
||||
++allierte;
|
||||
}
|
||||
}
|
||||
|
||||
for (sf = allies; sf; sf = sf->next) {
|
||||
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
|
||||
if (mode <= 0)
|
||||
continue;
|
||||
i++;
|
||||
if (dh) {
|
||||
if (i == allierte) {
|
||||
bytes = (int)str_strlcpy(bufp, LOC(f->locale, "list_and"), size);
|
||||
if (allierte > 0) {
|
||||
sbstring sbs;
|
||||
sbs_init(&sbs, buf, size);
|
||||
|
||||
for (sf = allies; sf; sf = sf->next) {
|
||||
int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL);
|
||||
if (mode <= 0)
|
||||
continue;
|
||||
i++;
|
||||
if (dh) {
|
||||
if (i == allierte) {
|
||||
sbs_strcat(&sbs, LOC(f->locale, "list_and"));
|
||||
}
|
||||
else {
|
||||
sbs_strcat(&sbs, ", ");
|
||||
}
|
||||
}
|
||||
dh = 1;
|
||||
hh = 0;
|
||||
sbs_strcat(&sbs, factionname(sf->faction));
|
||||
sbs_strcat(&sbs, " (");
|
||||
if ((mode & HELP_ALL) == HELP_ALL) {
|
||||
sbs_strcat(&sbs, LOC(f->locale, parameters[P_ANY]));
|
||||
}
|
||||
else {
|
||||
bytes = (int)str_strlcpy(bufp, ", ", size);
|
||||
}
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
}
|
||||
dh = 1;
|
||||
hh = 0;
|
||||
bytes = (int)str_strlcpy(bufp, factionname(sf->faction), size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
bytes = (int)str_strlcpy(bufp, " (", size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
if ((mode & HELP_ALL) == HELP_ALL) {
|
||||
bytes = (int)str_strlcpy(bufp, LOC(f->locale, parameters[P_ANY]), size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
}
|
||||
else {
|
||||
for (h = 1; h <= HELP_TRAVEL; h *= 2) {
|
||||
int p = MAXPARAMS;
|
||||
if ((mode & h) == h) {
|
||||
switch (h) {
|
||||
case HELP_TRAVEL:
|
||||
p = P_TRAVEL;
|
||||
break;
|
||||
case HELP_MONEY:
|
||||
p = P_MONEY;
|
||||
break;
|
||||
case HELP_FIGHT:
|
||||
p = P_FIGHT;
|
||||
break;
|
||||
case HELP_GIVE:
|
||||
p = P_GIVE;
|
||||
break;
|
||||
case HELP_GUARD:
|
||||
p = P_GUARD;
|
||||
break;
|
||||
case HELP_FSTEALTH:
|
||||
p = P_FACTIONSTEALTH;
|
||||
break;
|
||||
for (h = 1; h <= HELP_TRAVEL; h *= 2) {
|
||||
int p = MAXPARAMS;
|
||||
if ((mode & h) == h) {
|
||||
switch (h) {
|
||||
case HELP_TRAVEL:
|
||||
p = P_TRAVEL;
|
||||
break;
|
||||
case HELP_MONEY:
|
||||
p = P_MONEY;
|
||||
break;
|
||||
case HELP_FIGHT:
|
||||
p = P_FIGHT;
|
||||
break;
|
||||
case HELP_GIVE:
|
||||
p = P_GIVE;
|
||||
break;
|
||||
case HELP_GUARD:
|
||||
p = P_GUARD;
|
||||
break;
|
||||
case HELP_FSTEALTH:
|
||||
p = P_FACTIONSTEALTH;
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (p != MAXPARAMS) {
|
||||
if (hh) {
|
||||
sbs_strcat(&sbs, ", ");
|
||||
}
|
||||
sbs_strcat(&sbs, LOC(f->locale, parameters[p]));
|
||||
hh = 1;
|
||||
}
|
||||
}
|
||||
if (p != MAXPARAMS) {
|
||||
if (hh) {
|
||||
bytes = (int)str_strlcpy(bufp, ", ", size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
}
|
||||
bytes = (int)str_strlcpy(bufp, LOC(f->locale, parameters[p]), size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
hh = 1;
|
||||
}
|
||||
}
|
||||
sbs_strcat(&sbs, ")");
|
||||
}
|
||||
bytes = (int)str_strlcpy(bufp, ")", size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
sbs_strcat(&sbs, ".");
|
||||
}
|
||||
bytes = (int)str_strlcpy(bufp, ".", size);
|
||||
if (wrptr(&bufp, &size, bytes) != 0)
|
||||
WARN_STATIC_BUFFER();
|
||||
*bufp = 0;
|
||||
}
|
||||
|
||||
static void allies(struct stream *out, const faction * f)
|
||||
|
|
|
@ -76,7 +76,7 @@ static void test_reorder_units(CuTest * tc)
|
|||
CuAssertPtrEquals(tc, u2, u3->next);
|
||||
CuAssertPtrEquals(tc, u1, u2->next);
|
||||
CuAssertPtrEquals(tc, u0, u1->next);
|
||||
CuAssertPtrEquals(tc, 0, u0->next);
|
||||
CuAssertPtrEquals(tc, NULL, u0->next);
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
|
@ -130,19 +130,19 @@ static void test_sparagraph(CuTest *tc) {
|
|||
split_paragraph(&sp, "Hello World", 0, 16, 0);
|
||||
CuAssertPtrNotNull(tc, sp);
|
||||
CuAssertStrEquals(tc, "Hello World", sp->s);
|
||||
CuAssertPtrEquals(tc, 0, sp->next);
|
||||
CuAssertPtrEquals(tc, NULL, sp->next);
|
||||
freestrlist(sp);
|
||||
|
||||
split_paragraph(&sp, "Hello World", 4, 16, 0);
|
||||
CuAssertPtrNotNull(tc, sp);
|
||||
CuAssertStrEquals(tc, " Hello World", sp->s);
|
||||
CuAssertPtrEquals(tc, 0, sp->next);
|
||||
CuAssertPtrEquals(tc, NULL, sp->next);
|
||||
freestrlist(sp);
|
||||
|
||||
split_paragraph(&sp, "Hello World", 4, 16, '*');
|
||||
CuAssertPtrNotNull(tc, sp);
|
||||
CuAssertStrEquals(tc, " * Hello World", sp->s);
|
||||
CuAssertPtrEquals(tc, 0, sp->next);
|
||||
CuAssertPtrEquals(tc, NULL, sp->next);
|
||||
freestrlist(sp);
|
||||
|
||||
split_paragraph(&sp, "12345678 90 12345678", 0, 8, '*');
|
||||
|
@ -152,7 +152,7 @@ static void test_sparagraph(CuTest *tc) {
|
|||
CuAssertStrEquals(tc, "90", sp->next->s);
|
||||
CuAssertPtrNotNull(tc, sp->next->next);
|
||||
CuAssertStrEquals(tc, "12345678", sp->next->next->s);
|
||||
CuAssertPtrEquals(tc, 0, sp->next->next->next);
|
||||
CuAssertPtrEquals(tc, NULL, sp->next->next->next);
|
||||
freestrlist(sp);
|
||||
}
|
||||
|
||||
|
@ -326,7 +326,7 @@ static void test_arg_resources(CuTest *tc) {
|
|||
CuAssertPtrNotNull(tc, res = res->next);
|
||||
CuAssertPtrEquals(tc, itype->rtype, (void *)res->type);
|
||||
CuAssertIntEquals(tc, 5, res->number);
|
||||
CuAssertPtrEquals(tc, 0, res->next);
|
||||
CuAssertPtrEquals(tc, NULL, res->next);
|
||||
atype->release(v2);
|
||||
test_teardown();
|
||||
}
|
||||
|
@ -340,7 +340,7 @@ static void test_newbie_password_message(CuTest *tc) {
|
|||
f->flags = 0;
|
||||
prepare_report(&ctx, f);
|
||||
CuAssertIntEquals(tc, 0, f->flags&FFL_PWMSG);
|
||||
CuAssertPtrEquals(tc, 0, test_find_messagetype(f->msgs, "changepasswd"));
|
||||
CuAssertPtrEquals(tc, NULL, test_find_messagetype(f->msgs, "changepasswd"));
|
||||
f->age=2;
|
||||
prepare_report(&ctx, f);
|
||||
CuAssertIntEquals(tc, FFL_PWMSG, f->flags&FFL_PWMSG);
|
||||
|
@ -511,7 +511,7 @@ void test_prepare_lighthouse_capacity(CuTest *tc) {
|
|||
|
||||
prepare_report(&ctx, u2->faction);
|
||||
CuAssertPtrEquals(tc, r1, ctx.first);
|
||||
CuAssertPtrEquals(tc, 0, ctx.last);
|
||||
CuAssertPtrEquals(tc, NULL, ctx.last);
|
||||
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
||||
CuAssertIntEquals(tc, seen_neighbour, r2->seen.mode);
|
||||
finish_reports(&ctx);
|
||||
|
@ -520,7 +520,7 @@ void test_prepare_lighthouse_capacity(CuTest *tc) {
|
|||
config_set_int("rules.lighthouse.unit_capacity", 1);
|
||||
prepare_report(&ctx, u2->faction);
|
||||
CuAssertPtrEquals(tc, r1, ctx.first);
|
||||
CuAssertPtrEquals(tc, 0, ctx.last);
|
||||
CuAssertPtrEquals(tc, NULL, ctx.last);
|
||||
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
||||
CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode);
|
||||
finish_reports(&ctx);
|
||||
|
@ -619,15 +619,15 @@ static void test_prepare_report(CuTest *tc) {
|
|||
r = test_create_region(0, 0, NULL);
|
||||
|
||||
prepare_report(&ctx, f);
|
||||
CuAssertPtrEquals(tc, 0, ctx.first);
|
||||
CuAssertPtrEquals(tc, 0, ctx.last);
|
||||
CuAssertPtrEquals(tc, NULL, ctx.first);
|
||||
CuAssertPtrEquals(tc, NULL, ctx.last);
|
||||
CuAssertIntEquals(tc, seen_none, r->seen.mode);
|
||||
finish_reports(&ctx);
|
||||
|
||||
test_create_unit(f, r);
|
||||
prepare_report(&ctx, f);
|
||||
CuAssertPtrEquals(tc, r, ctx.first);
|
||||
CuAssertPtrEquals(tc, 0, ctx.last);
|
||||
CuAssertPtrEquals(tc, NULL, ctx.last);
|
||||
CuAssertIntEquals(tc, seen_unit, r->seen.mode);
|
||||
finish_reports(&ctx);
|
||||
CuAssertIntEquals(tc, seen_none, r->seen.mode);
|
||||
|
@ -655,7 +655,7 @@ static void test_seen_neighbours(CuTest *tc) {
|
|||
test_create_unit(f, r1);
|
||||
prepare_report(&ctx, f);
|
||||
CuAssertPtrEquals(tc, r1, ctx.first);
|
||||
CuAssertPtrEquals(tc, 0, ctx.last);
|
||||
CuAssertPtrEquals(tc, NULL, ctx.last);
|
||||
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
||||
CuAssertIntEquals(tc, seen_neighbour, r2->seen.mode);
|
||||
finish_reports(&ctx);
|
||||
|
@ -682,7 +682,7 @@ static void test_seen_travelthru(CuTest *tc) {
|
|||
CuAssertPtrEquals(tc, r3, f->last);
|
||||
prepare_report(&ctx, f);
|
||||
CuAssertPtrEquals(tc, r1, ctx.first);
|
||||
CuAssertPtrEquals(tc, 0, ctx.last);
|
||||
CuAssertPtrEquals(tc, NULL, ctx.last);
|
||||
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
||||
CuAssertIntEquals(tc, seen_travel, r2->seen.mode);
|
||||
CuAssertIntEquals(tc, seen_neighbour, r3->seen.mode);
|
||||
|
@ -760,7 +760,7 @@ static void test_report_far_vision(CuTest *tc) {
|
|||
report_context ctx;
|
||||
prepare_report(&ctx, f);
|
||||
CuAssertPtrEquals(tc, r1, ctx.first);
|
||||
CuAssertPtrEquals(tc, 0, ctx.last);
|
||||
CuAssertPtrEquals(tc, NULL, ctx.last);
|
||||
CuAssertIntEquals(tc, seen_unit, r1->seen.mode);
|
||||
CuAssertIntEquals(tc, seen_spell, r2->seen.mode);
|
||||
finish_reports(&ctx);
|
||||
|
|
|
@ -2348,7 +2348,7 @@ void patzer_peasantmob(const castorder * co)
|
|||
create_unit(r, f, n, get_race(RC_PEASANT), 0, LOC(f->locale, "angry_mob"),
|
||||
NULL);
|
||||
fset(u, UFL_ISNEW);
|
||||
addlist(&u->orders, create_order(K_GUARD, lang, NULL));
|
||||
unit_addorder(u, create_order(K_GUARD, lang, NULL));
|
||||
set_order(&u->thisorder, default_order(lang));
|
||||
a = a_new(&at_unitdissolve);
|
||||
a->data.ca[0] = 1; /* An rpeasants(r). */
|
||||
|
|
|
@ -79,7 +79,7 @@ const curse_type ct_firewall = {
|
|||
|
||||
static void wall_init(connection * b)
|
||||
{
|
||||
wall_data *fd = (wall_data *)calloc(sizeof(wall_data), 1);
|
||||
wall_data *fd = (wall_data *)calloc(1, sizeof(wall_data));
|
||||
fd->countdown = -1; /* infinite */
|
||||
b->data.v = fd;
|
||||
}
|
||||
|
|
|
@ -956,7 +956,7 @@ int sp_hero(struct castorder * co)
|
|||
|
||||
if (df) {
|
||||
if (!(df->person[dt.index].flags & FL_COURAGE)) {
|
||||
df->person[dt.index].defence += df_bonus;
|
||||
df->person[dt.index].defense += df_bonus;
|
||||
df->person[dt.index].flags = df->person[dt.index].flags | FL_COURAGE;
|
||||
targets++;
|
||||
--force;
|
||||
|
@ -1005,7 +1005,7 @@ int sp_berserk(struct castorder * co)
|
|||
if (df) {
|
||||
if (!(df->person[dt.index].flags & FL_COURAGE)) {
|
||||
df->person[dt.index].attack += at_bonus;
|
||||
df->person[dt.index].defence -= df_malus;
|
||||
df->person[dt.index].defense -= df_malus;
|
||||
df->person[dt.index].flags = df->person[dt.index].flags | FL_COURAGE;
|
||||
targets++;
|
||||
--force;
|
||||
|
@ -1064,7 +1064,7 @@ int sp_frighten(struct castorder * co)
|
|||
}
|
||||
if (!is_magic_resistant(mage, df->unit, 0)) {
|
||||
df->person[dt.index].attack -= at_malus;
|
||||
df->person[dt.index].defence -= df_malus;
|
||||
df->person[dt.index].defense -= df_malus;
|
||||
targets++;
|
||||
}
|
||||
--force;
|
||||
|
@ -1109,7 +1109,7 @@ int sp_tiredsoldiers(struct castorder * co)
|
|||
if (!(df->person[t.index].flags & FL_TIRED)) {
|
||||
if (!is_magic_resistant(mage, df->unit, 0)) {
|
||||
df->person[t.index].flags = df->person[t.index].flags | FL_TIRED;
|
||||
df->person[t.index].defence -= 2;
|
||||
df->person[t.index].defense -= 2;
|
||||
++n;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -272,7 +272,7 @@ static void test_sabotage_other_success(CuTest *tc) {
|
|||
assert(ord);
|
||||
set_level(u2, SK_SPY, 1);
|
||||
CuAssertIntEquals(tc, 0, sabotage_cmd(u2, ord));
|
||||
CuAssertPtrEquals(tc, 0, r->ships);
|
||||
CuAssertPtrEquals(tc, NULL, r->ships);
|
||||
free_order(ord);
|
||||
test_teardown();
|
||||
}
|
||||
|
|
|
@ -182,6 +182,7 @@ void spawn_braineaters(float chance)
|
|||
u = create_unit(r, f, 1 + rng_int() % 10 + rng_int() % 10,
|
||||
rc_brain, 0, NULL, NULL);
|
||||
equip_unit(u, "seed_braineater");
|
||||
stats_count("monsters.create.braineater", 1);
|
||||
|
||||
next = rng_int() % (int)(chance * 100);
|
||||
}
|
||||
|
|
|
@ -175,6 +175,8 @@ int RunAllTests(int argc, char *argv[])
|
|||
fail_count = summary->failCount;
|
||||
CuSuiteDelete(summary);
|
||||
game_done();
|
||||
log_close();
|
||||
stats_close();
|
||||
return fail_count;
|
||||
}
|
||||
return 0;
|
||||
|
|
|
@ -234,6 +234,8 @@ static void test_reset(void) {
|
|||
default_locale = 0;
|
||||
calendar_cleanup();
|
||||
close_orders();
|
||||
log_close();
|
||||
stats_close();
|
||||
free_special_directions();
|
||||
free_locales();
|
||||
free_spells();
|
||||
|
|
|
@ -23,13 +23,13 @@ static void test_resources(CuTest *tc) {
|
|||
CuAssertPtrNotNull(tc, rt_find("permaura"));
|
||||
CuAssertPtrEquals(tc, rt_find("permaura"), (void *)get_resourcetype(R_PERMAURA));
|
||||
|
||||
CuAssertPtrEquals(tc, 0, rt_find("stone"));
|
||||
CuAssertPtrEquals(tc, NULL, rt_find("stone"));
|
||||
rtype = rt_get_or_create("stone");
|
||||
CuAssertPtrEquals(tc, (void *)rtype, (void *)rt_find("stone"));
|
||||
CuAssertPtrEquals(tc, (void *)rtype, (void *)get_resourcetype(R_STONE));
|
||||
free_resources();
|
||||
CuAssertPtrEquals(tc, 0, rt_find("stone"));
|
||||
CuAssertPtrEquals(tc, 0, rt_find("peasant"));
|
||||
CuAssertPtrEquals(tc, NULL, rt_find("stone"));
|
||||
CuAssertPtrEquals(tc, NULL, rt_find("peasant"));
|
||||
rtype = rt_get_or_create("stone");
|
||||
CuAssertPtrEquals(tc, (void *)rtype, (void *)get_resourcetype(R_STONE));
|
||||
test_teardown();
|
||||
|
|
|
@ -31,6 +31,7 @@ extern "C" {
|
|||
const char *itoa36(int i);
|
||||
const char *itoa10(int i);
|
||||
extern int atoi36(const char *s);
|
||||
extern int atoi10(const char *s);
|
||||
int i10toi36(int i);
|
||||
|
||||
#ifdef __cplusplus
|
||||
|
|
|
@ -53,10 +53,7 @@
|
|||
/* Just to make sure the prototypes match the actual definitions */
|
||||
#include "crypt_blowfish.h"
|
||||
|
||||
#ifdef __i386__
|
||||
#define BF_ASM 1
|
||||
#define BF_SCALE 1
|
||||
#elif defined(__x86_64__) || defined(__alpha__) || defined(__hppa__)
|
||||
#if defined(__x86_64__) || defined(__alpha__) || defined(__hppa__)
|
||||
#define BF_ASM 0
|
||||
#define BF_SCALE 1
|
||||
#else
|
||||
|
|
|
@ -16,6 +16,8 @@ without prior permission by the authors of Eressea.
|
|||
#include "strings.h"
|
||||
#include "unicode.h"
|
||||
|
||||
#include <critbit.h>
|
||||
|
||||
#include <assert.h>
|
||||
#include <errno.h>
|
||||
#include <limits.h>
|
||||
|
@ -318,3 +320,77 @@ int log_level(log_t * log, int flags)
|
|||
log->flags = flags;
|
||||
return old;
|
||||
}
|
||||
|
||||
static critbit_tree stats = CRITBIT_TREE();
|
||||
|
||||
int stats_count(const char *stat, int delta) {
|
||||
size_t len;
|
||||
char data[128];
|
||||
void * match;
|
||||
if (cb_find_prefix_str(&stats, stat, &match, 1, 0) == 0) {
|
||||
len = cb_new_kv(stat, strlen(stat), &delta, sizeof(delta), data);
|
||||
cb_insert(&stats, data, len);
|
||||
return delta;
|
||||
}
|
||||
else {
|
||||
int *num;
|
||||
cb_get_kv_ex(match, (void **)&num);
|
||||
return *num += delta;
|
||||
}
|
||||
}
|
||||
|
||||
#if 0
|
||||
#define STATS_BATCH 8
|
||||
void stats_walk(const char *prefix, void(*callback)(const char *, int, void *), void *udata) {
|
||||
void *match[STATS_BATCH];
|
||||
int n, off = 0;
|
||||
do {
|
||||
int i;
|
||||
n = cb_find_prefix_str(&stats, prefix, match, STATS_BATCH, off);
|
||||
if (n == 0) {
|
||||
break;
|
||||
}
|
||||
off += n;
|
||||
for (i = 0; i != n; ++i) {
|
||||
const void *kv = match[i];
|
||||
int *num;
|
||||
cb_get_kv_ex(kv, &(void *)num);
|
||||
callback(kv, *num, udata);
|
||||
}
|
||||
} while (n == STATS_BATCH);
|
||||
}
|
||||
#else
|
||||
|
||||
struct walk_data {
|
||||
int (*callback)(const char *, int, void *);
|
||||
void *udata;
|
||||
};
|
||||
|
||||
static int walk_cb(void * match, const void * key, size_t keylen, void *udata) {
|
||||
struct walk_data *data = (struct walk_data *)udata;
|
||||
int *num;
|
||||
cb_get_kv_ex(match, (void **)&num);
|
||||
return data->callback((const char*)match, *num, data->udata);
|
||||
}
|
||||
|
||||
int stats_walk(const char *prefix, int (*callback)(const char *, int, void *), void *udata) {
|
||||
struct walk_data data;
|
||||
data.callback = callback;
|
||||
data.udata = udata;
|
||||
return cb_foreach(&stats, prefix, strlen(prefix), walk_cb, &data);
|
||||
}
|
||||
#endif
|
||||
|
||||
static int write_cb(const char *key, int val, void *udata) {
|
||||
FILE * F = (FILE *)udata;
|
||||
fprintf(F, "%s: %d\n", (const char *)key, val);
|
||||
return 0;
|
||||
}
|
||||
|
||||
void stats_write(FILE *F, const char *prefix) {
|
||||
stats_walk(prefix, write_cb, F);
|
||||
}
|
||||
|
||||
void stats_close(void) {
|
||||
cb_clear(&stats);
|
||||
}
|
||||
|
|
|
@ -36,6 +36,12 @@ extern "C" {
|
|||
void log_printf(FILE * ios, const char *format, ...);
|
||||
|
||||
void errno_check(const char *file, int line);
|
||||
|
||||
int stats_count(const char *stat, int delta);
|
||||
void stats_write(FILE *F, const char *prefix);
|
||||
int stats_walk(const char *prefix, int (*callback)(const char *key, int val, void * udata), void *udata);
|
||||
void stats_close(void);
|
||||
|
||||
#define ERRNO_CHECK() errno_check(__FILE__, __LINE__)
|
||||
|
||||
|
||||
|
|
|
@ -1,11 +1,13 @@
|
|||
#ifdef _MSC_VER
|
||||
#include <platform.h>
|
||||
#endif
|
||||
#include <CuTest.h>
|
||||
|
||||
#include "log.h"
|
||||
#include "macros.h"
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
#include <stdarg.h>
|
||||
#include <string.h>
|
||||
|
||||
|
@ -32,9 +34,47 @@ static void test_logging(CuTest * tc)
|
|||
CuAssertStrEquals(tc, "World", str2);
|
||||
}
|
||||
|
||||
static int stats_cb(const char *stat, int num, void *udata) {
|
||||
int *counter = (int *)udata;
|
||||
if (counter) {
|
||||
*counter += num;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void test_stats(CuTest * tc)
|
||||
{
|
||||
int n = 0;
|
||||
test_setup();
|
||||
CuAssertIntEquals(tc, 1, stats_count("foobar", 1));
|
||||
CuAssertIntEquals(tc, 2, stats_count("test.one", 2));
|
||||
CuAssertIntEquals(tc, 1, stats_count("test.two", 1));
|
||||
CuAssertIntEquals(tc, 4, stats_count("test.one", 2));
|
||||
CuAssertIntEquals(tc, 1, stats_count("test.two", 0));
|
||||
|
||||
n = 0;
|
||||
CuAssertIntEquals(tc, 0, stats_walk("", stats_cb, &n));
|
||||
CuAssertIntEquals(tc, 6, n);
|
||||
|
||||
n = 0;
|
||||
CuAssertIntEquals(tc, 0, stats_walk("test", stats_cb, &n));
|
||||
CuAssertIntEquals(tc, 5, n);
|
||||
|
||||
n = 0;
|
||||
CuAssertIntEquals(tc, 0, stats_walk("test.one", stats_cb, &n));
|
||||
CuAssertIntEquals(tc, 4, n);
|
||||
|
||||
n = 0;
|
||||
CuAssertIntEquals(tc, 0, stats_walk("foobar", stats_cb, &n));
|
||||
CuAssertIntEquals(tc, 1, n);
|
||||
|
||||
test_teardown();
|
||||
}
|
||||
|
||||
CuSuite *get_log_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_logging);
|
||||
SUITE_ADD_TEST(suite, test_stats);
|
||||
return suite;
|
||||
}
|
||||
|
|
|
@ -77,7 +77,7 @@ int pofile_read(const char *filename, int (*callback)(const char *msgid, const c
|
|||
int err = sscanf(line, "%8s", token);
|
||||
if (err == 1) {
|
||||
char *text = NULL;
|
||||
size_t size, len = strlen(token);
|
||||
size_t size = 0, len = strlen(token);
|
||||
|
||||
line = line + len + 1;
|
||||
if (len == 7 && memcmp(token, "msgctxt", 7) == 0) {
|
||||
|
@ -99,7 +99,7 @@ int pofile_read(const char *filename, int (*callback)(const char *msgid, const c
|
|||
msgid[0] = 0;
|
||||
}
|
||||
}
|
||||
if (text) {
|
||||
if (size > 0) {
|
||||
line = read_multiline(F, line, text, size);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -22,10 +22,10 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#include "strings.h"
|
||||
|
||||
/* libc includes */
|
||||
#include <assert.h>
|
||||
#include <ctype.h>
|
||||
#include <stdarg.h>
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdlib.h>
|
||||
|
||||
#ifdef HAVE_LIBBSD
|
||||
|
|
|
@ -20,6 +20,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
|
|||
#define STRINGS_H
|
||||
|
||||
#include <stddef.h>
|
||||
#include <string.h>
|
||||
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
|
|
|
@ -117,7 +117,7 @@ char * transliterate(char * out, size_t size, const char * in)
|
|||
}
|
||||
|
||||
tnode * mknode(void) {
|
||||
tnode * node = calloc(1, sizeof(tnode));
|
||||
tnode * node = (tnode *)calloc(1, sizeof(tnode));
|
||||
node->refcount = 1;
|
||||
return node;
|
||||
}
|
||||
|
|
|
@ -3,7 +3,8 @@ IF EXIST ..\build-vs10 SET BUILD=..\build-vs10\eressea\Debug
|
|||
IF EXIST ..\build-vs11 SET BUILD=..\build-vs11\eressea\Debug
|
||||
IF EXIST ..\build-vs12 SET BUILD=..\build-vs12\eressea\Debug
|
||||
IF EXIST ..\build-vs14 SET BUILD=..\build-vs14\eressea\Debug
|
||||
REM IF EXIST ..\build-vs15 SET BUILD=..\build-vs15\eressea\Debug
|
||||
IF EXIST ..\build-vs15 SET BUILD=..\build-vs15\eressea\Debug
|
||||
|
||||
SET SERVER=%BUILD%\eressea.exe
|
||||
%BUILD%\test_eressea.exe
|
||||
%SERVER% ..\scripts\run-tests.lua
|
||||
|
|
|
@ -1,5 +1,7 @@
|
|||
@ECHO OFF
|
||||
SET VSVERSION=14
|
||||
SET VSVERSION=15
|
||||
IF NOT "%1" == "" SET VSVERSION=%1%
|
||||
|
||||
SET SRCDIR=%CD%
|
||||
CD ..
|
||||
SET ERESSEA=%CD%
|
||||
|
|
Loading…
Add table
Reference in a new issue