diff --git a/.travis.yml b/.travis.yml index 003fb67ad..78aaf3648 100644 --- a/.travis.yml +++ b/.travis.yml @@ -7,7 +7,8 @@ script: s/travis-build addons: apt: packages: - - liblua5.2-dev + - liblua5.1-dev + - libtolua-dev - libncurses5-dev - libsqlite3-dev - libxml2-dev diff --git a/res/eressea/equipment.xml b/res/eressea/equipment.xml index f35505bc0..bf7e38376 100644 --- a/res/eressea/equipment.xml +++ b/res/eressea/equipment.xml @@ -269,11 +269,6 @@ - - - - - diff --git a/res/races/zombie.xml b/res/races/zombie.xml index faecf021d..8c23aea83 100644 --- a/res/races/zombie.xml +++ b/res/races/zombie.xml @@ -3,7 +3,7 @@ recruitcost="-1" maintenance="0" weight="1000" capacity="440" speed="1.000000" hp="20" damage="1d5" unarmedattack="-2" unarmeddefense="-2" playerrace="no" walk="yes" shapeshift="no" giveperson="no" giveunit="no" - getitem="no" recruitethereal="no" equipment="yes" scarepeasants="yes" + getitem="no" equipment="yes" scarepeasants="yes" cansteal="no" unarmedguard="yes" absorbpeasants="yes" noheal="yes" undead="yes" resistpierce="yes"> diff --git a/src/economy.c b/src/economy.c index 8f6a1afa1..6ec5d9191 100644 --- a/src/economy.c +++ b/src/economy.c @@ -180,15 +180,6 @@ static void expandorders(region * r, request * requests) /* ------------------------------------------------------------- */ -static void change_level(unit * u, skill_t sk, int bylevel) -{ - skill *sv = unit_skill(u, sk); - assert(bylevel > 0); - if (sv == 0) - sv = add_skill(u, sk); - sk_set(sv, sv->level + bylevel); -} - typedef struct recruitment { struct recruitment *next; faction *f; @@ -258,10 +249,6 @@ void add_recruits(unit * u, int number, int wanted) strlcat(equipment, "_unit", sizeof(equipment)); equip_unit(unew, get_equipment(equipment)); - if (u_race(unew)->ec_flags & ECF_REC_HORSES) { - change_level(unew, SK_RIDING, 1); - } - if (unew != u) { transfermen(unew, u, unew->number); remove_unit(&r->units, unew); @@ -278,24 +265,6 @@ static int any_recruiters(const struct race *rc, int qty) return (int)(qty * 2 * rc->recruit_multi); } -/*static int peasant_recruiters(const struct race *rc, int qty) -{ -if (rc->ec_flags & ECF_REC_ETHEREAL) -return -1; -if (rc->ec_flags & ECF_REC_HORSES) -return -1; -return (int)(qty * 2 * rc->recruit_multi); -}*/ - -static int horse_recruiters(const struct race *rc, int qty) -{ - if (rc->ec_flags & ECF_REC_ETHEREAL) - return -1; - if (rc->ec_flags & ECF_REC_HORSES) - return (int)(qty * 2.0 * rc->recruit_multi); - return -1; -} - static int do_recruiting(recruitment * recruits, int available) { recruitment *rec; @@ -407,17 +376,6 @@ static void expandrecruit(region * r, request * recruitorders) int orc_total = 0; - /* centaurs: */ - recruits = select_recruitment(&recruitorders, horse_recruiters, &orc_total); - if (recruits) { - int recruited, horses = rhorses(r) * 2; - if (orc_total < horses) - horses = orc_total; - recruited = do_recruiting(recruits, horses); - rsethorses(r, (horses - recruited) / 2); - free_recruitments(recruits); - } - /* peasant limited: */ recruits = select_recruitment(&recruitorders, any_recruiters, &orc_total); if (recruits) { @@ -539,7 +497,7 @@ static void recruit(unit * u, struct order *ord, request ** recruitorders) return; } - if (!(rc->ec_flags & ECF_REC_HORSES) && fval(r, RF_ORCIFIED)) { + if (fval(r, RF_ORCIFIED)) { if (rc != get_race(RC_ORC)) { cmistake(u, ord, 238, MSG_EVENT); return; diff --git a/src/kernel/config.c b/src/kernel/config.c index ebfe13833..7c58d7766 100644 --- a/src/kernel/config.c +++ b/src/kernel/config.c @@ -70,7 +70,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include diff --git a/src/kernel/curse.c b/src/kernel/curse.c index ac2e917a7..3ecf48899 100644 --- a/src/kernel/curse.c +++ b/src/kernel/curse.c @@ -522,6 +522,24 @@ static void set_cursedmen(curse * c, int cursedmen) } } +static int newcurseid(void) { + int random_no; + int start_random_no; + random_no = 1 + (rng_int() % MAX_UNIT_NR); + start_random_no = random_no; + + while (findcurse(random_no)) { + random_no++; + if (random_no == MAX_UNIT_NR + 1) { + random_no = 1; + } + if (random_no == start_random_no) { + random_no = (int)MAX_UNIT_NR + 1; + } + } + return random_no; +} + /* ------------------------------------------------------------- */ /* Legt eine neue Verzauberung an. Sollte es schon einen Zauber * dieses Typs geben, gibt es den bestehenden zurück. @@ -543,7 +561,7 @@ static curse *make_curse(unit * mage, attrib ** ap, const curse_type * ct, c->effect = effect; c->magician = mage; - c->no = newunitid(); + c->no = newcurseid(); chash(c); switch (c->type->typ) { diff --git a/src/kernel/curse.h b/src/kernel/curse.h index a1518bbdd..0de1211c7 100644 --- a/src/kernel/curse.h +++ b/src/kernel/curse.h @@ -280,7 +280,6 @@ extern "C" { * */ struct curse *get_curse(struct attrib *ap, const curse_type * ctype); - int find_cursebyname(const char *c); const curse_type *ct_find(const char *c); bool ct_changed(int *cache); void ct_register(const curse_type *); diff --git a/src/kernel/faction.c b/src/kernel/faction.c index 0ccf62f52..774a6aec8 100755 --- a/src/kernel/faction.c +++ b/src/kernel/faction.c @@ -49,7 +49,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include @@ -387,19 +386,14 @@ void destroyfaction(faction ** fp) const race *rc = u_race(u); int m = rmoney(r); + /* Personen gehen nur an die Bauern, wenn sie auch von dort + * stammen */ if ((rc->ec_flags & ECF_REC_ETHEREAL) == 0) { int p = rpeasants(u->region); int h = rhorses(u->region); item *itm; - /* Personen gehen nur an die Bauern, wenn sie auch von dort - * stammen */ - if (rc->ec_flags & ECF_REC_HORSES) { /* Zentauren an die Pferde */ - h += u->number; - } - else { /* Orks zählen nur zur Hälfte */ - p += (int)(u->number * rc->recruit_multi); - } + p += (int)(u->number * rc->recruit_multi); for (itm = u->items; itm; itm = itm->next) { if (itm->type->flags & ITF_ANIMAL) { h += itm->number; diff --git a/src/kernel/race.h b/src/kernel/race.h index 214f2738d..dc3becabb 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -217,7 +217,6 @@ extern "C" { #define GIVEPERSON (1<<2) /* übergibt Personen */ #define GIVEUNIT (1<<3) /* Einheiten an andere Partei übergeben */ #define GETITEM (1<<4) /* nimmt Gegenstände an */ -#define ECF_REC_HORSES (1<<6) /* Rekrutiert aus Pferden */ #define ECF_REC_ETHEREAL (1<<7) /* Rekrutiert aus dem Nichts */ #define ECF_REC_UNLIMITED (1<<8) /* Rekrutiert ohne Limit */ diff --git a/src/kernel/save.c b/src/kernel/save.c index 34a408113..2373d60a0 100644 --- a/src/kernel/save.c +++ b/src/kernel/save.c @@ -69,7 +69,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include #include #include diff --git a/src/kernel/unit.c b/src/kernel/unit.c index ab3bd294c..201153663 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1084,15 +1084,9 @@ void transfermen(unit * u, unit * dst, int n) else if (r->land) { if ((u_race(u)->ec_flags & ECF_REC_ETHEREAL) == 0) { const race *rc = u_race(u); - if (rc->ec_flags & ECF_REC_HORSES) { /* Zentauren an die Pferde */ - int h = rhorses(r) + n; - rsethorses(r, h); - } - else { - int p = rpeasants(r); - p += (int)(n * rc->recruit_multi); - rsetpeasants(r, p); - } + int p = rpeasants(r); + p += (int)(n * rc->recruit_multi); + rsetpeasants(r, p); } } } @@ -1437,6 +1431,26 @@ void free_unit(unit * u) } } +static int newunitid(void) +{ + int random_unit_no; + int start_random_no; + random_unit_no = 1 + (rng_int() % MAX_UNIT_NR); + start_random_no = random_unit_no; + + while (ufindhash(random_unit_no) || dfindhash(random_unit_no) + || forbiddenid(random_unit_no)) { + random_unit_no++; + if (random_unit_no == MAX_UNIT_NR + 1) { + random_unit_no = 1; + } + if (random_unit_no == start_random_no) { + random_unit_no = (int)MAX_UNIT_NR + 1; + } + } + return random_unit_no; +} + static void createunitid(unit * u, int id) { if (id <= 0 || id > MAX_UNIT_NR || ufindhash(id) || dfindhash(id) @@ -1699,6 +1713,7 @@ int unit_getcapacity(const unit * u) } void renumber_unit(unit *u, int no) { + if (no == 0) no = newunitid(); uunhash(u); if (!ualias(u)) { attrib *a = a_add(&u->attribs, a_new(&at_alias)); @@ -1929,27 +1944,6 @@ bool unit_can_study(const unit *u) { return !((u_race(u)->flags & RCF_NOLEARN) || fval(u, UFL_WERE)); } -/* ID's für Einheiten und Zauber */ -int newunitid(void) -{ - int random_unit_no; - int start_random_no; - random_unit_no = 1 + (rng_int() % MAX_UNIT_NR); - start_random_no = random_unit_no; - - while (ufindhash(random_unit_no) || dfindhash(random_unit_no) - || forbiddenid(random_unit_no)) { - random_unit_no++; - if (random_unit_no == MAX_UNIT_NR + 1) { - random_unit_no = 1; - } - if (random_unit_no == start_random_no) { - random_unit_no = (int)MAX_UNIT_NR + 1; - } - } - return random_unit_no; -} - static int read_newunitid(const faction * f, const region * r) { int n; diff --git a/src/kernel/unit.h b/src/kernel/unit.h index 32e48a950..a360321a2 100644 --- a/src/kernel/unit.h +++ b/src/kernel/unit.h @@ -258,7 +258,6 @@ extern "C" { #define GET_PEASANTS 2 int getunit(const struct region * r, const struct faction * f, struct unit **uresult); - int newunitid(void); int read_unitid(const struct faction *f, const struct region *r); void setstatus(struct unit *u, int status); diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 894647f89..e022effaf 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1730,8 +1730,6 @@ static int parse_races(xmlDocPtr doc) rc->ec_flags |= GIVEUNIT; if (xml_bvalue(node, "getitem", false)) rc->ec_flags |= GETITEM; - if (xml_bvalue(node, "recruithorses", false)) - rc->ec_flags |= ECF_REC_HORSES; if (xml_bvalue(node, "recruitethereal", false)) rc->ec_flags |= ECF_REC_ETHEREAL; if (xml_bvalue(node, "recruitunlimited", false)) diff --git a/src/laws.c b/src/laws.c index e243378dd..623a163d6 100755 --- a/src/laws.c +++ b/src/laws.c @@ -2916,7 +2916,7 @@ int renumber_cmd(unit * u, order * ord) { char token[128]; const char *s; - int i; + int i = 0; faction *f = u->faction; init_order(ord); @@ -2936,10 +2936,7 @@ int renumber_cmd(unit * u, order * ord) case P_UNIT: s = gettoken(token, sizeof(token)); - if (s == NULL || *s == 0) { - i = newunitid(); - } - else { + if (s && *s) { i = atoi36((const char *)s); if (i <= 0 || i > MAX_UNIT_NR) { cmistake(u, ord, 114, MSG_EVENT); diff --git a/src/lighthouse.c b/src/lighthouse.c index 96b42b333..dd1183558 100644 --- a/src/lighthouse.c +++ b/src/lighthouse.c @@ -73,13 +73,11 @@ int lighthouse_range(const building * b, const faction * f) region *r = b->region; int c = 0; int cap = buildingcapacity(b); - unit *u; + unit *u, *uown = building_owner(b); for (u = r->units; u; u = u->next) { - if (u->building == b || u == building_owner(b)) { - if (u->building == b) { - c += u->number; - } + if (u->building == b || u == uown) { + c += u->number; if (c > cap) { break; } diff --git a/src/reports.c b/src/reports.c index dc0edf1b3..5a7f29a10 100644 --- a/src/reports.c +++ b/src/reports.c @@ -1170,11 +1170,9 @@ static void add_seen_nb(faction *f, region *r, seen_mode mode) { /** mark all regions seen by the lighthouse. */ -static void prepare_lighthouse(building * b, report_context *ctx) +static void prepare_lighthouse(faction *f, region *r, int range) { - faction *f = ctx->f; - int range = lighthouse_range(b, f); - quicklist *ql, *rlist = get_regions_distance(b->region, range); + quicklist *ql, *rlist = get_regions_distance(r, range); int qi; for (ql = rlist, qi = 0; ql; ql_advance(&ql, &qi, 1)) { @@ -1316,7 +1314,6 @@ static void cb_add_seen(region *r, unit *u, void *cbdata) { void prepare_report(report_context *ctx, faction *f) { region *r; - building *b; static int config; static bool rule_region_owners; const struct building_type *bt_lighthouse = bt_find("lighthouse"); @@ -1334,34 +1331,36 @@ void prepare_report(report_context *ctx, faction *f) ctx->last = lastregion(f); for (r = ctx->first; r!=ctx->last; r = r->next) { + int range = 0; unit *u; + if (fval(r, RF_LIGHTHOUSE) && bt_lighthouse) { + if (rule_region_owners && f == region_get_owner(r)) { + /* region owners get the report from lighthouses */ + building *b; - if (fval(r, RF_LIGHTHOUSE)) { - /* region owners get the report from lighthouses */ - if (rule_region_owners && bt_lighthouse) { - for (b = rbuildings(r); b; b = b->next) { - if (b && b->type == bt_lighthouse) { - u = building_owner(b); - if (u && u->faction==f) { - prepare_lighthouse(b, ctx); - add_seen_nb(f, r, seen_unit); - } + for (b = r->buildings; b; b = b->next) { + if (b->type == bt_lighthouse) { + int br = lighthouse_range(b, NULL); + if (br > range) range = br; } } } - } for (u = r->units; u; u = u->next) { - if (u->faction==f) { + if (u->faction == f) { add_seen_nb(f, r, seen_unit); - if (fval(r, RF_LIGHTHOUSE)) { + if (fval(r, RF_LIGHTHOUSE) && bt_lighthouse) { if (u->building && u->building->type == bt_lighthouse && inside_building(u)) { - /* we are in a lighthouse. add the regions we can see from here! */ - prepare_lighthouse(u->building, ctx); + int br = lighthouse_range(u->building, f); + if (br > range) range = br; } } } } + if (range > 0) { + /* we are in at least one lighthouse. add the regions we can see from here! */ + prepare_lighthouse(f, r, range); + } if (fval(r, RF_TRAVELUNIT) && r->seen.mode #include #include #include @@ -344,6 +345,43 @@ static void test_prepare_lighthouse(CuTest *tc) { test_cleanup(); } +static void test_prepare_lighthouse_owners(CuTest *tc) { + report_context ctx; + faction *f; + region *r1, *r2, *r3; + unit *u; + building *b; + building_type *btype; + const struct terrain_type *t_ocean, *t_plain; + + test_setup(); + config_set("rules.region_owner_pay_building", "lighthouse"); + config_set("rules.region_owners", "1"); + t_ocean = test_create_terrain("ocean", SEA_REGION); + t_plain = test_create_terrain("plain", LAND_REGION); + f = test_create_faction(0); + r1 = test_create_region(0, 0, t_plain); + r2 = test_create_region(1, 0, t_ocean); + r3 = test_create_region(2, 0, t_ocean); + btype = test_create_buildingtype("lighthouse"); + b = test_create_building(r1, btype); + b->flags |= BLD_MAINTAINED; + b->size = 10; + update_lighthouse(b); + u = test_create_unit(f, r1); + u = test_create_unit(test_create_faction(0), r1); + u->building = b; + set_level(u, SK_PERCEPTION, 3); + region_set_owner(b->region, f, 0); + prepare_report(&ctx, f); + CuAssertPtrEquals(tc, r1, ctx.first); + CuAssertPtrEquals(tc, NULL, ctx.last); + CuAssertIntEquals(tc, seen_unit, r1->seen.mode); + CuAssertIntEquals(tc, seen_lighthouse, r2->seen.mode); + CuAssertIntEquals(tc, seen_neighbour, r3->seen.mode); + test_cleanup(); +} + static void test_prepare_report(CuTest *tc) { report_context ctx; faction *f; @@ -432,6 +470,7 @@ CuSuite *get_reports_suite(void) SUITE_ADD_TEST(suite, test_seen_neighbours); SUITE_ADD_TEST(suite, test_seen_travelthru); SUITE_ADD_TEST(suite, test_prepare_lighthouse); + SUITE_ADD_TEST(suite, test_prepare_lighthouse_owners); SUITE_ADD_TEST(suite, test_prepare_lighthouse_capacity); SUITE_ADD_TEST(suite, test_prepare_travelthru); SUITE_ADD_TEST(suite, test_reorder_units); diff --git a/src/sqlite.c b/src/sqlite.c index 37535c9d1..42bfdb3b5 100644 --- a/src/sqlite.c +++ b/src/sqlite.c @@ -3,7 +3,6 @@ #include #include #include -#include #include #include #include diff --git a/src/xmlreport.c b/src/xmlreport.c index 43d7cc55b..fd2b5e464 100644 --- a/src/xmlreport.c +++ b/src/xmlreport.c @@ -61,7 +61,6 @@ without prior permission by the authors of Eressea. #include #include #include -#include #include #ifdef USE_LIBXML2