forked from github/server
rewrite and unit tests
This commit is contained in:
parent
35c60eb0de
commit
cc3c5580d4
|
@ -392,6 +392,7 @@
|
|||
</message>
|
||||
<message name="curseinfo::magicresistance" section="events">
|
||||
<type>
|
||||
<arg name="building" type="building"/>
|
||||
<arg name="unit" type="unit"/>
|
||||
<arg name="id" type="int"/>
|
||||
</type>
|
||||
|
|
|
@ -17,6 +17,9 @@ function test_dont_move_after_destroy()
|
|||
u:add_order("NACH O")
|
||||
u:add_order("ZERSTOERE " .. itoa36(u.building.id))
|
||||
process_orders()
|
||||
if not u.region then
|
||||
print("shit happened ", u.number)
|
||||
end
|
||||
assert_equal(r1, u.region)
|
||||
assert_equal(nil, u.building)
|
||||
end
|
||||
|
|
|
@ -193,6 +193,7 @@ set(TESTS_SRC
|
|||
spells.test.c
|
||||
spy.test.c
|
||||
upkeep.test.c
|
||||
spells/magicresistance.test.c
|
||||
${ATTRIBUTES_TESTS}
|
||||
${UTIL_TESTS}
|
||||
${KERNEL_TESTS}
|
||||
|
|
|
@ -6767,6 +6767,8 @@ static int sp_readmind(castorder * co)
|
|||
return cast_level;
|
||||
}
|
||||
|
||||
void register_magicresistance(void);
|
||||
|
||||
void register_spells(void)
|
||||
{
|
||||
register_borders();
|
||||
|
@ -6793,4 +6795,5 @@ void register_spells(void)
|
|||
register_regioncurse();
|
||||
register_shipcurse();
|
||||
register_buildingcurse();
|
||||
register_magicresistance();
|
||||
}
|
||||
|
|
|
@ -7,6 +7,7 @@ combatspells.c
|
|||
regioncurse.c
|
||||
shipcurse.c
|
||||
unitcurse.c
|
||||
magicresistance.c
|
||||
)
|
||||
FOREACH(_FILE ${_FILES})
|
||||
LIST(APPEND _SOURCES ${PROJECT_NAME}/${_FILE})
|
||||
|
|
|
@ -33,14 +33,15 @@
|
|||
#include <stdlib.h>
|
||||
#include <assert.h>
|
||||
|
||||
static message *cinfo_building(const void *obj, objtype_t typ, const curse * c,
|
||||
message *cinfo_building(const void *obj, objtype_t typ, const curse * c,
|
||||
int self)
|
||||
{
|
||||
unused_arg(typ);
|
||||
assert(typ == TYP_BUILDING);
|
||||
|
||||
if (self != 0) { /* owner or inside */
|
||||
return msg_message(mkname("curseinfo", c->type->cname), "id", c->no);
|
||||
building *b = (building *)obj;
|
||||
return msg_message(mkname("curseinfo", c->type->cname), "id building", c->no, b);
|
||||
}
|
||||
return msg_message(mkname("curseinfo", "buildingunknown"), "id", c->no);
|
||||
}
|
||||
|
|
|
@ -13,14 +13,17 @@
|
|||
|
||||
#ifndef _BCURSE_H
|
||||
#define _BCURSE_H
|
||||
#include <kernel/objtypes.h>
|
||||
#ifdef __cplusplus
|
||||
extern "C" {
|
||||
#endif
|
||||
|
||||
struct locale;
|
||||
struct curse;
|
||||
struct message;
|
||||
|
||||
extern void register_buildingcurse(void);
|
||||
struct message *cinfo_building(const void *obj, objtype_t typ, const struct curse * c, int self);
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
|
@ -0,0 +1,25 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include "unitcurse.h"
|
||||
#include "buildingcurse.h"
|
||||
#include <kernel/curse.h>
|
||||
|
||||
static struct message *cinfo_magicresistance(const void *obj, objtype_t typ, const struct curse * c, int self)
|
||||
{
|
||||
if (typ == TYP_UNIT) {
|
||||
return cinfo_unit(obj, typ, c, self);
|
||||
}
|
||||
if (typ == TYP_BUILDING) {
|
||||
return cinfo_building(obj, typ, c, self);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static struct curse_type ct_magicresistance = {
|
||||
"magicresistance", CURSETYP_UNIT, CURSE_SPREADMODULO, M_MEN, cinfo_magicresistance
|
||||
};
|
||||
|
||||
void register_magicresistance(void)
|
||||
{
|
||||
ct_register(&ct_magicresistance);
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
#include <platform.h>
|
||||
#include <kernel/config.h>
|
||||
#include <kernel/curse.h>
|
||||
#include <kernel/faction.h>
|
||||
#include <kernel/order.h>
|
||||
#include <kernel/region.h>
|
||||
#include <kernel/spell.h>
|
||||
#include <kernel/unit.h>
|
||||
#include <util/language.h>
|
||||
#include <util/attrib.h>
|
||||
#include <spells/regioncurse.h>
|
||||
#include "spells.h"
|
||||
|
||||
#include <CuTest.h>
|
||||
#include <tests.h>
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <assert.h>
|
||||
|
||||
|
||||
static struct castorder *test_create_castorder(castorder *order, unit *u, const char *name, int level, float force, int range) {
|
||||
struct locale * lang;
|
||||
spell *sp;
|
||||
|
||||
lang = get_or_create_locale("en");
|
||||
sp = create_spell(name, 0);
|
||||
return order = create_castorder(order, u, NULL, sp, u->region, level, force, range, create_order(K_CAST, lang, ""), NULL);
|
||||
}
|
||||
|
||||
static void test_magicresistance(CuTest *tc) {
|
||||
struct region *r;
|
||||
struct faction *f1, *f2;
|
||||
unit *u1, *u2;
|
||||
int level;
|
||||
curse *c;
|
||||
|
||||
test_cleanup();
|
||||
test_create_world();
|
||||
r=findregion(0, 0);
|
||||
f1 = test_create_faction(test_create_race("human"));
|
||||
u1 = test_create_unit(f1, r);
|
||||
|
||||
f2 = test_create_faction(test_create_race("human"));
|
||||
u2 = test_create_unit(f2, r);
|
||||
|
||||
test_cleanup();
|
||||
}
|
||||
|
||||
CuSuite *get_magicresistance_suite(void)
|
||||
{
|
||||
CuSuite *suite = CuSuiteNew();
|
||||
SUITE_ADD_TEST(suite, test_magicresistance);
|
||||
return suite;
|
||||
}
|
|
@ -301,10 +301,6 @@ static struct curse_type ct_oldrace = {
|
|||
"oldrace", CURSETYP_NORM, CURSE_SPREADALWAYS, NO_MERGE, NULL
|
||||
};
|
||||
|
||||
static struct curse_type ct_magicresistance = {
|
||||
"magicresistance", CURSETYP_UNIT, CURSE_SPREADMODULO, M_MEN, cinfo_unit
|
||||
};
|
||||
|
||||
/* ------------------------------------------------------------- */
|
||||
/*
|
||||
* C_SKILL
|
||||
|
@ -365,5 +361,4 @@ void register_unitcurse(void)
|
|||
ct_register(&ct_itemcloak);
|
||||
ct_register(&ct_fumble);
|
||||
ct_register(&ct_oldrace);
|
||||
ct_register(&ct_magicresistance);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue