forked from github/server
remove static variables optimizations, they create global state that is bad for testing
This commit is contained in:
parent
59b0f0f582
commit
3625ba6a95
11 changed files with 208 additions and 242 deletions
|
@ -1972,14 +1972,16 @@ static void buy(unit * u, request ** buyorders, struct order *ord)
|
|||
}
|
||||
} else {
|
||||
/* ...oder in der Region muß es eine Burg geben. */
|
||||
building *b;
|
||||
static const struct building_type *bt_castle;
|
||||
if (!bt_castle)
|
||||
bt_castle = bt_find("castle");
|
||||
building *b = 0;
|
||||
if (r->buildings) {
|
||||
const struct building_type *bt_castle = bt_find("castle");
|
||||
|
||||
for (b = r->buildings; b; b = b->next) {
|
||||
if (b->type == bt_castle && b->size >= 2)
|
||||
if (b->type == bt_castle && b->size >= 2) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (b == NULL) {
|
||||
cmistake(u, ord, 119, MSG_COMMERCE);
|
||||
return;
|
||||
|
@ -2276,15 +2278,14 @@ static bool sell(unit * u, request ** sellorders, struct order *ord)
|
|||
}
|
||||
} else {
|
||||
/* ...oder in der Region muß es eine Burg geben. */
|
||||
building *b;
|
||||
static const struct building_type *bt_castle;
|
||||
if (!bt_castle)
|
||||
bt_castle = bt_find("castle");
|
||||
building *b = 0;
|
||||
if (r->buildings) {
|
||||
const struct building_type *bt_castle = bt_find("castle");
|
||||
for (b = r->buildings; b; b = b->next) {
|
||||
if (b->type == bt_castle && b->size >= 2)
|
||||
break;
|
||||
if (b->type == bt_castle && b->size >= 2) break;
|
||||
}
|
||||
if (b == NULL) {
|
||||
}
|
||||
if (!b) {
|
||||
cmistake(u, ord, 119, MSG_COMMERCE);
|
||||
return false;
|
||||
}
|
||||
|
|
|
@ -278,31 +278,22 @@ void build_road(region * r, unit * u, int size, direction_t d)
|
|||
|
||||
if (r->terrain == newterrain(T_SWAMP)) {
|
||||
/* wenn kein Damm existiert */
|
||||
static const struct building_type *bt_dam;
|
||||
if (!bt_dam)
|
||||
bt_dam = bt_find("dam");
|
||||
assert(bt_dam);
|
||||
if (!buildingtype_exists(r, bt_dam, true)) {
|
||||
const struct building_type *bt_dam = bt_find("dam");
|
||||
if (!bt_dam || !buildingtype_exists(r, bt_dam, true)) {
|
||||
cmistake(u, u->thisorder, 132, MSG_PRODUCE);
|
||||
return;
|
||||
}
|
||||
} else if (r->terrain == newterrain(T_DESERT)) {
|
||||
static const struct building_type *bt_caravan;
|
||||
if (!bt_caravan)
|
||||
bt_caravan = bt_find("caravan");
|
||||
assert(bt_caravan);
|
||||
const struct building_type *bt_caravan = bt_find("caravan");
|
||||
/* wenn keine Karawanserei existiert */
|
||||
if (!buildingtype_exists(r, bt_caravan, true)) {
|
||||
if (!bt_caravan || !buildingtype_exists(r, bt_caravan, true)) {
|
||||
cmistake(u, u->thisorder, 133, MSG_PRODUCE);
|
||||
return;
|
||||
}
|
||||
} else if (r->terrain == newterrain(T_GLACIER)) {
|
||||
static const struct building_type *bt_tunnel;
|
||||
if (!bt_tunnel)
|
||||
bt_tunnel = bt_find("tunnel");
|
||||
assert(bt_tunnel);
|
||||
const struct building_type *bt_tunnel = bt_find("tunnel");
|
||||
/* wenn kein Tunnel existiert */
|
||||
if (!buildingtype_exists(r, bt_tunnel, true)) {
|
||||
if (!bt_tunnel || !buildingtype_exists(r, bt_tunnel, true)) {
|
||||
cmistake(u, u->thisorder, 131, MSG_PRODUCE);
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -203,28 +203,25 @@ attrib_type at_building_generic_type = {
|
|||
/* Returns the (internal) name for a building of given size and type. Especially, returns the correct
|
||||
* name if it depends on the size (as for Eressea castles).
|
||||
*/
|
||||
const char *buildingtype(const building_type * btype, const building * b,
|
||||
int bsize)
|
||||
const char *buildingtype(const building_type * btype, const building * b, int bsize)
|
||||
{
|
||||
const char *s = NULL;
|
||||
static bool init_generic = false;
|
||||
static const struct building_type *bt_generic;
|
||||
const char *s;
|
||||
assert(btype);
|
||||
|
||||
if (!init_generic) {
|
||||
init_generic = true;
|
||||
bt_generic = bt_find("generic");
|
||||
s = btype->_name;
|
||||
if (btype->name) {
|
||||
s = btype->name(btype, b, bsize);
|
||||
}
|
||||
if (b && b->attribs) {
|
||||
const struct building_type *bt_generic = bt_find("generic");
|
||||
|
||||
if (btype == bt_generic) {
|
||||
const attrib *a = a_find(b->attribs, &at_building_generic_type);
|
||||
if (a)
|
||||
if (a) {
|
||||
s = (const char *)a->data.v;
|
||||
}
|
||||
|
||||
if (btype->name)
|
||||
s = btype->name(btype, b, bsize);
|
||||
if (s == NULL)
|
||||
s = btype->_name;
|
||||
}
|
||||
}
|
||||
return s;
|
||||
}
|
||||
|
||||
|
@ -527,22 +524,17 @@ static building *deleted_buildings;
|
|||
void remove_building(building ** blist, building * b)
|
||||
{
|
||||
unit *u;
|
||||
static const struct building_type *bt_caravan, *bt_dam, *bt_tunnel;
|
||||
static bool init = false;
|
||||
|
||||
if (!init) {
|
||||
init = true;
|
||||
bt_caravan = bt_find("caravan");
|
||||
bt_dam = bt_find("dam");
|
||||
bt_tunnel = bt_find("tunnel");
|
||||
}
|
||||
const struct building_type *bt_caravan, *bt_dam, *bt_tunnel;
|
||||
|
||||
assert(bfindhash(b->no));
|
||||
|
||||
bt_caravan = bt_find("caravan");
|
||||
bt_dam = bt_find("dam");
|
||||
bt_tunnel = bt_find("tunnel");
|
||||
|
||||
handle_event(b->attribs, "destroy", b);
|
||||
for (u = b->region->units; u; u = u->next) {
|
||||
if (u->building == b)
|
||||
leave(u, true);
|
||||
if (u->building == b) leave(u, true);
|
||||
}
|
||||
|
||||
b->size = 0;
|
||||
|
|
|
@ -1075,17 +1075,8 @@ static attrib_type at_lighthouse = {
|
|||
*/
|
||||
void update_lighthouse(building * lh)
|
||||
{
|
||||
static bool init_lighthouse = false;
|
||||
static const struct building_type *bt_lighthouse = 0;
|
||||
|
||||
if (!init_lighthouse) {
|
||||
bt_lighthouse = bt_find("lighthouse");
|
||||
if (bt_lighthouse == NULL)
|
||||
return;
|
||||
init_lighthouse = true;
|
||||
}
|
||||
|
||||
if (lh->type == bt_lighthouse) {
|
||||
const struct building_type *bt_lighthouse = bt_find("lighthouse");
|
||||
if (bt_lighthouse && lh->type == bt_lighthouse) {
|
||||
region *r = lh->region;
|
||||
int d = (int)log10(lh->size) + 1;
|
||||
int x;
|
||||
|
@ -1102,9 +1093,7 @@ void update_lighthouse(building * lh)
|
|||
int px = r->x + x, py = r->y + y;
|
||||
pnormalize(&px, &py, rplane(r));
|
||||
r2 = findregion(px, py);
|
||||
if (r2 == NULL)
|
||||
continue;
|
||||
if (!fval(r2->terrain, SEA_REGION))
|
||||
if (!r2 || !fval(r2->terrain, SEA_REGION))
|
||||
continue;
|
||||
if (distance(r, r2) > d)
|
||||
continue;
|
||||
|
@ -2418,9 +2407,7 @@ static const int wagetable[7][4] = {
|
|||
|
||||
int cmp_wage(const struct building *b, const building * a)
|
||||
{
|
||||
static const struct building_type *bt_castle;
|
||||
if (!bt_castle)
|
||||
bt_castle = bt_find("castle");
|
||||
const struct building_type *bt_castle = bt_find("castle");
|
||||
if (b->type == bt_castle) {
|
||||
if (!a)
|
||||
return 1;
|
||||
|
|
|
@ -629,9 +629,7 @@ static bool is_freezing(const unit * u)
|
|||
int check_ship_allowed(struct ship *sh, const region * r)
|
||||
{
|
||||
int c = 0;
|
||||
static const building_type *bt_harbour = NULL;
|
||||
|
||||
if (bt_harbour == NULL)
|
||||
const building_type *bt_harbour = NULL;
|
||||
bt_harbour = bt_find("harbour");
|
||||
|
||||
if (sh->region && r_insectstalled(r)) {
|
||||
|
@ -639,14 +637,15 @@ int check_ship_allowed(struct ship *sh, const region * r)
|
|||
unit *u;
|
||||
|
||||
for (u = sh->region->units; u != NULL; u = u->next) {
|
||||
if (u->ship != sh)
|
||||
if (u->ship != sh) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (is_freezing(u)) {
|
||||
unit *captain = ship_owner(sh);
|
||||
if (captain) {
|
||||
ADDMSG(&captain->faction->msgs, msg_message("detectforbidden",
|
||||
"unit region", u, r));
|
||||
ADDMSG(&captain->faction->msgs,
|
||||
msg_message("detectforbidden", "unit region", u, r));
|
||||
}
|
||||
|
||||
return SA_NO_INSECT;
|
||||
|
|
|
@ -341,8 +341,7 @@ void
|
|||
report_building(const struct building *b, const char **name,
|
||||
const char **illusion)
|
||||
{
|
||||
static int init;
|
||||
static const struct building_type *bt_illusion;
|
||||
const struct building_type *bt_illusion;
|
||||
|
||||
if (name) {
|
||||
*name = buildingtype(b->type, b, b->size);
|
||||
|
@ -350,10 +349,7 @@ report_building(const struct building *b, const char **name,
|
|||
if (illusion) {
|
||||
*illusion = NULL;
|
||||
|
||||
if (!init) {
|
||||
bt_illusion = bt_find("illusioncastle");
|
||||
init = 1;
|
||||
}
|
||||
if (bt_illusion && b->type == bt_illusion) {
|
||||
const attrib *a = a_findc(b->attribs, &at_icastle);
|
||||
if (a != NULL) {
|
||||
|
@ -463,16 +459,12 @@ bufunit(const faction * f, const unit * u, int indent, int mode, char *buf,
|
|||
faction *fv = visible_faction(f, u);
|
||||
char *bufp = buf;
|
||||
bool itemcloak = false;
|
||||
static const curse_type *itemcloak_ct = 0;
|
||||
static bool init = false;
|
||||
const curse_type *itemcloak_ct = 0;
|
||||
int bytes;
|
||||
item result[MAX_INVENTORY];
|
||||
|
||||
if (!init) {
|
||||
init = true;
|
||||
itemcloak_ct = ct_find("itemcloak");
|
||||
}
|
||||
if (itemcloak_ct != NULL) {
|
||||
if (itemcloak_ct) {
|
||||
itemcloak = curse_active(get_curse(u->attribs, itemcloak_ct));
|
||||
}
|
||||
|
||||
|
@ -1504,13 +1496,10 @@ static void prepare_reports(void)
|
|||
{
|
||||
region *r;
|
||||
faction *f;
|
||||
static const struct building_type *bt_lighthouse = NULL;
|
||||
if (bt_lighthouse == NULL) {
|
||||
bt_lighthouse = bt_find("lighthouse");
|
||||
}
|
||||
const struct building_type *bt_lighthouse = bt_find("lighthouse");
|
||||
|
||||
for (f = factions; f; f = f->next) {
|
||||
if (f->seen)
|
||||
seen_done(f->seen);
|
||||
if (f->seen) seen_done(f->seen);
|
||||
f->seen = seen_init();
|
||||
}
|
||||
|
||||
|
|
|
@ -3256,14 +3256,11 @@ int renumber_cmd(unit * u, order * ord)
|
|||
|
||||
static building *age_building(building * b)
|
||||
{
|
||||
static bool init = false;
|
||||
static const building_type *bt_blessed;
|
||||
static const curse_type *ct_astralblock;
|
||||
if (!init) {
|
||||
init = true;
|
||||
const struct building_type *bt_blessed;
|
||||
const struct curse_type *ct_astralblock;
|
||||
|
||||
bt_blessed = bt_find("blessedstonecircle");
|
||||
ct_astralblock = ct_find("astralblock");
|
||||
}
|
||||
|
||||
/* blesses stone circles create an astral protection in the astral region
|
||||
* above the shield, which prevents chaos suction and other spells.
|
||||
|
|
|
@ -32,9 +32,7 @@ static unsigned int get_markets(region * r, unit ** results, size_t size)
|
|||
{
|
||||
unsigned int n = 0;
|
||||
building *b;
|
||||
static const building_type *btype;
|
||||
if (!btype)
|
||||
btype = bt_find("market");
|
||||
const building_type *btype = bt_find("market");
|
||||
if (!btype)
|
||||
return 0;
|
||||
for (b = r->buildings; n < size && b; b = b->next) {
|
||||
|
|
|
@ -4402,11 +4402,9 @@ int sp_icastle(castorder * co)
|
|||
icastle_data *data;
|
||||
const char *bname;
|
||||
message *msg;
|
||||
static const building_type *bt_illusion;
|
||||
const building_type *bt_illusion = bt_find("illusioncastle");
|
||||
|
||||
if (bt_illusion == NULL)
|
||||
bt_illusion = bt_find("illusioncastle");
|
||||
if (bt_illusion == NULL) {
|
||||
if (!bt_illusion) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
-- new tests 2014-06-11
|
||||
|
||||
--require "tests.settings"
|
||||
--require "tests.config"
|
||||
--require "tests.locale"
|
||||
--require "tests.regions"
|
||||
require "tests.settings"
|
||||
require "tests.config"
|
||||
require "tests.locale"
|
||||
require "tests.regions"
|
||||
require "tests.ships"
|
||||
|
||||
|
|
|
@ -85,4 +85,18 @@ function test_sail_to_forbidden_shore()
|
|||
assert_equal(ocean, u.region)
|
||||
end
|
||||
|
||||
function test_sail_into_harbour()
|
||||
local ocean = region.create(1, 0, "ocean")
|
||||
local shore = region.create(0, 0, "glacier")
|
||||
local f = faction.create("noreply@eressea.de", "human", "de")
|
||||
local u = unit.create(f, ocean, 1)
|
||||
u.name = "Sailor"
|
||||
u.ship = ship.create(ocean, "boat")
|
||||
u:set_skill("sailing", 10)
|
||||
u:add_order("NACH W")
|
||||
local b = building.create(shore, "harbour")
|
||||
assert_not_nil(b)
|
||||
process_orders()
|
||||
|
||||
assert_equal(shore, u.region)
|
||||
end
|
||||
|
|
Loading…
Reference in a new issue