diff --git a/scripts/tests/common.lua b/scripts/tests/common.lua index e612a17d7..936d2a79b 100644 --- a/scripts/tests/common.lua +++ b/scripts/tests/common.lua @@ -1066,3 +1066,48 @@ function test_give_silver() assert_equal(21, r:get_resource("money")) assert_equal(10, u:get_item("money")) end + +function test_give_horses() + local r = region.create(0, 0, "plain") + local f = create_faction('human') + local u = unit.create(f, r, 1) + + r:set_resource("horse", 0) + u:add_item("horse", 21) + u:add_item("dolphin", 10) + u:add_order("GIB 0 7 PFERD") + u:add_order("GIB 0 5 DELPHIN") + process_orders() + assert_equal(7, r:get_resource("horse")) + assert_equal(5, u:get_item("dolphin")) + assert_equal(14, u:get_item("horse")) +end + +function test_give_silver() + local r = region.create(0, 0, "plain") + local f = create_faction('human') + local u = unit.create(f, r, 1) + + r:set_resource("peasant", 0) + r:set_resource("money", 11) + u:clear_orders() + u:add_item("money", 20) + u:add_order("GIB 0 10 SILBER") + process_orders() + assert_equal(21, r:get_resource("money")) + assert_equal(10, u:get_item("money")) +end + +function test_build_castle() + local r = region.create(0, 0, "plain") + local f = create_faction('human') + local u = unit.create(f, r, 1) + + u:add_item('stone', 1) + u:set_skill('building', 1) + u:add_order("MACHE BURG") + process_orders() + assert_not_nil(u.building) + assert_equal(1, u.building.size) + assert_equal(u.building.name, "Burg") +end diff --git a/src/kernel/building.c b/src/kernel/building.c index 31c4b3e27..431d44e9e 100644 --- a/src/kernel/building.c +++ b/src/kernel/building.c @@ -362,9 +362,6 @@ building *new_building(const struct building_type * btype, region * r, *bptr = b; update_lighthouse(b); - if (b->type->name) { - bname = LOC(lang, buildingtype(btype, b, 0)); - } if (!bname) { bname = LOC(lang, btype->_name); } diff --git a/src/kernel/building.h b/src/kernel/building.h index a2019e4a2..476424a92 100644 --- a/src/kernel/building.h +++ b/src/kernel/building.h @@ -76,6 +76,7 @@ extern "C" { extern struct selist *buildingtypes; extern struct attrib_type at_building_action; + extern struct attrib_type at_building_generic_type; int cmp_castle_size(const struct building *b, const struct building *a); int building_protection(const struct building_type *btype, int stage); @@ -114,13 +115,13 @@ extern "C" { int flags; } building; - extern struct attrib_type at_building_generic_type; - extern const char *buildingtype(const building_type * btype, + + const char *buildingtype(const building_type * btype, const struct building *b, int bsize); - extern const char *write_buildingname(const building * b, char *ibuf, + const char *write_buildingname(const building * b, char *ibuf, size_t size); - extern int buildingcapacity(const struct building *b); - extern struct building *new_building(const struct building_type *typ, + int buildingcapacity(const struct building *b); + struct building *new_building(const struct building_type *typ, struct region *r, const struct locale *lang); int build_building(struct unit *u, const struct building_type *typ, int id, int size, struct order *ord); @@ -145,9 +146,9 @@ extern "C" { void bunhash(struct building *b); int buildingcapacity(const struct building *b); - extern void remove_building(struct building **blist, struct building *b); - extern void free_building(struct building *b); - extern void free_buildings(void); + void remove_building(struct building **blist, struct building *b); + void free_building(struct building *b); + void free_buildings(void); const struct building_type *findbuildingtype(const char *name, const struct locale *lang); @@ -155,16 +156,16 @@ extern "C" { #include "build.h" #define NOBUILDING NULL - extern int resolve_building(variant data, void *address); - extern void write_building_reference(const struct building *b, + int resolve_building(variant data, void *address); + void write_building_reference(const struct building *b, struct storage *store); - extern variant read_building_reference(struct gamedata *data); + variant read_building_reference(struct gamedata *data); - extern struct building *findbuilding(int n); + struct building *findbuilding(int n); - extern struct unit *building_owner(const struct building *b); - extern void building_set_owner(struct unit * u); - extern void building_update_owner(struct building * bld); + struct unit *building_owner(const struct building *b); + void building_set_owner(struct unit * u); + void building_update_owner(struct building * bld); bool buildingtype_exists(const struct region *r, const struct building_type *bt, bool working); @@ -172,10 +173,10 @@ extern "C" { bool is_building_type(const struct building_type *btype, const char *name); struct building *active_building(const struct unit *u, const struct building_type *btype); - extern const char *buildingname(const struct building *b); + const char *buildingname(const struct building *b); - extern const char *building_getname(const struct building *b); - extern void building_setname(struct building *self, const char *name); + const char *building_getname(const struct building *b); + void building_setname(struct building *self, const char *name); struct region *building_getregion(const struct building *b); void building_setregion(struct building *bld, struct region *r);