From 71d05584032d850d640cf06ed23d51a395cee09e Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 19 Apr 2015 09:49:52 +0200 Subject: [PATCH 1/4] Bug 2089: remove the giveitem restriction from all races. https://bugs.eressea.de/view.php?id=2089 --- res/e3a/races.xml | 62 +++++++++++++++---------------- res/eressea/races.xml | 84 +++++++++++++++++++++--------------------- res/races/aquarian.xml | 2 +- res/races/cat.xml | 2 +- res/races/demon.xml | 2 +- res/races/dragon.xml | 2 +- res/races/dwarf.xml | 2 +- res/races/elf.xml | 2 +- res/races/goblin-2.xml | 2 +- res/races/goblin-3.xml | 2 +- res/races/goblin.xml | 2 +- res/races/halfling.xml | 2 +- res/races/human.xml | 2 +- res/races/insect.xml | 2 +- res/races/orc.xml | 2 +- res/races/troll.xml | 2 +- res/races/zombie.xml | 2 +- src/kernel/xmlreader.c | 2 +- 18 files changed, 89 insertions(+), 89 deletions(-) diff --git a/res/e3a/races.xml b/res/e3a/races.xml index d5139298b..94bf9a742 100644 --- a/res/e3a/races.xml +++ b/res/e3a/races.xml @@ -8,7 +8,7 @@ - + @@ -32,7 +32,7 @@ - + @@ -47,7 +47,7 @@ - + @@ -76,7 +76,7 @@ - + @@ -104,7 +104,7 @@ - + @@ -124,7 +124,7 @@ - + @@ -144,7 +144,7 @@ - + @@ -167,7 +167,7 @@ - + @@ -192,7 +192,7 @@ - + @@ -219,7 +219,7 @@ - + @@ -241,7 +241,7 @@ - + @@ -263,7 +263,7 @@ - + @@ -287,7 +287,7 @@ - + @@ -311,7 +311,7 @@ - + @@ -334,7 +334,7 @@ - + @@ -361,7 +361,7 @@ - + @@ -384,7 +384,7 @@ - + @@ -409,7 +409,7 @@ - + @@ -435,7 +435,7 @@ - + @@ -460,7 +460,7 @@ - + @@ -484,7 +484,7 @@ - + @@ -507,7 +507,7 @@ - + @@ -535,7 +535,7 @@ - + @@ -559,7 +559,7 @@ - + @@ -582,7 +582,7 @@ - + @@ -624,7 +624,7 @@ - + @@ -677,7 +677,7 @@ - + @@ -695,13 +695,13 @@ - + - + @@ -717,7 +717,7 @@ - + @@ -747,7 +747,7 @@ - + diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 02d530da3..e672d7e4d 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -5,12 +5,12 @@ regaura="0.000000" weight="500" capacity="200" equipment="no" speed="1.000000" hp="1000" ac="4" damage="2d4" unarmedattack="10" unarmeddefense="10" attackmodifier="8" defensemodifier="8" - fly="no" walk="no" canteach="no" getitem="yes" giveitem="yes"> + fly="no" walk="no" canteach="no" getitem="yes"> - + @@ -26,7 +26,7 @@ - + @@ -60,7 +60,7 @@ - + @@ -89,7 +89,7 @@ - + @@ -117,7 +117,7 @@ - + @@ -147,7 +147,7 @@ - + @@ -177,7 +177,7 @@ - + @@ -208,7 +208,7 @@ - + @@ -243,7 +243,7 @@ - + @@ -274,7 +274,7 @@ - + @@ -307,7 +307,7 @@ - + @@ -338,7 +338,7 @@ - + @@ -369,7 +369,7 @@ - + @@ -400,7 +400,7 @@ - + @@ -430,7 +430,7 @@ - + @@ -462,7 +462,7 @@ - + @@ -494,7 +494,7 @@ - + @@ -524,7 +524,7 @@ - + @@ -557,7 +557,7 @@ - + @@ -605,7 +605,7 @@ - + @@ -674,7 +674,7 @@ - + @@ -692,13 +692,13 @@ - + - + @@ -713,14 +713,14 @@ - + - + @@ -745,7 +745,7 @@ - + @@ -785,7 +785,7 @@ - + @@ -804,7 +804,7 @@ - + @@ -830,7 +830,7 @@ - + @@ -863,7 +863,7 @@ - + @@ -892,7 +892,7 @@ - + @@ -924,7 +924,7 @@ - + @@ -955,7 +955,7 @@ - + @@ -981,7 +981,7 @@ - + @@ -1014,7 +1014,7 @@ - + @@ -1137,7 +1137,7 @@ - + @@ -1181,7 +1181,7 @@ - + @@ -1212,7 +1212,7 @@ - - + @@ -1269,7 +1269,7 @@ - + @@ -1301,7 +1301,7 @@ - + diff --git a/res/races/aquarian.xml b/res/races/aquarian.xml index 0bd11c8c3..f9c174339 100644 --- a/res/races/aquarian.xml +++ b/res/races/aquarian.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/cat.xml b/res/races/cat.xml index d71d41b92..818b24b36 100644 --- a/res/races/cat.xml +++ b/res/races/cat.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/demon.xml b/res/races/demon.xml index ba187acfd..9a0cc6d48 100644 --- a/res/races/demon.xml +++ b/res/races/demon.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/dragon.xml b/res/races/dragon.xml index ecb7e04da..7a6dee3a7 100644 --- a/res/races/dragon.xml +++ b/res/races/dragon.xml @@ -1,5 +1,5 @@ +"6" damage="2d30" unarmedattack="0" unarmeddefense="0" attackmodifier="7" defensemodifier="7" scarepeasants="yes" fly="yes" walk="yes" teach="no" getitem="yes" resistbash="yes"> diff --git a/res/races/dwarf.xml b/res/races/dwarf.xml index a718581a7..8a31e4543 100644 --- a/res/races/dwarf.xml +++ b/res/races/dwarf.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/elf.xml b/res/races/elf.xml index 678422652..a88953ddb 100644 --- a/res/races/elf.xml +++ b/res/races/elf.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/goblin-2.xml b/res/races/goblin-2.xml index 7e23e28cf..6097e1b25 100644 --- a/res/races/goblin-2.xml +++ b/res/races/goblin-2.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/goblin-3.xml b/res/races/goblin-3.xml index 845b69c20..094c78bf0 100644 --- a/res/races/goblin-3.xml +++ b/res/races/goblin-3.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/goblin.xml b/res/races/goblin.xml index da2ee2907..b43792e0e 100644 --- a/res/races/goblin.xml +++ b/res/races/goblin.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/halfling.xml b/res/races/halfling.xml index 0e61aa55d..85bb6eb2e 100644 --- a/res/races/halfling.xml +++ b/res/races/halfling.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/human.xml b/res/races/human.xml index 0d689b4ac..26cb15c3b 100644 --- a/res/races/human.xml +++ b/res/races/human.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/insect.xml b/res/races/insect.xml index d727e1ee4..849da9a40 100644 --- a/res/races/insect.xml +++ b/res/races/insect.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/orc.xml b/res/races/orc.xml index 2caaaf8e5..64804a1c0 100644 --- a/res/races/orc.xml +++ b/res/races/orc.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/troll.xml b/res/races/troll.xml index 3761e17ec..c3e4db475 100644 --- a/res/races/troll.xml +++ b/res/races/troll.xml @@ -1,5 +1,5 @@ - + diff --git a/res/races/zombie.xml b/res/races/zombie.xml index 5d76a8557..a0798aaa4 100644 --- a/res/races/zombie.xml +++ b/res/races/zombie.xml @@ -2,7 +2,7 @@ diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 14f9f8f56..00f10b8ac 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1693,7 +1693,7 @@ static int parse_races(xmlDocPtr doc) if (xml_bvalue(node, "irongolem", false)) rc->flags |= RCF_IRONGOLEM; - if (xml_bvalue(node, "giveitem", false)) + if (xml_bvalue(node, "giveitem", true)) rc->ec_flags |= GIVEITEM; if (xml_bvalue(node, "giveperson", false)) rc->ec_flags |= GIVEPERSON; From f06e3371a060335f0b2231adb64921221230df12 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 19 Apr 2015 12:49:39 +0200 Subject: [PATCH 2/4] Bug 2089 again. rename giveitem flag to keepitem, because races should default to not holding on to their stuff. --- src/give.c | 8 ++++---- src/kernel/jsonconf.c | 3 ++- src/kernel/jsonconf.test.c | 2 +- src/kernel/pool.c | 4 ++-- src/kernel/race.h | 2 +- src/kernel/unit.c | 8 ++++---- src/kernel/xmlreader.c | 4 ++-- src/laws.c | 2 +- src/tests.c | 2 +- src/upkeep.c | 4 +--- 10 files changed, 19 insertions(+), 20 deletions(-) diff --git a/src/give.c b/src/give.c index d875dc34a..93cba504e 100644 --- a/src/give.c +++ b/src/give.c @@ -595,7 +595,7 @@ void give_cmd(unit * u, order * ord) else if (p == P_HERBS) { bool given = false; - if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); return; @@ -660,7 +660,7 @@ void give_cmd(unit * u, order * ord) if (!s || *s == 0) { /* GIVE ALL items that you have */ /* do these checks once, not for each item we have: */ - if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); return; @@ -704,7 +704,7 @@ void give_cmd(unit * u, order * ord) } } } - else if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + else if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); } @@ -763,7 +763,7 @@ void give_cmd(unit * u, order * ord) } if (u2 != NULL) { - if (!(u_race(u)->ec_flags & GIVEITEM) && u2 != NULL) { + if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) && u2 != NULL) { ADDMSG(&u->faction->msgs, msg_feedback(u, ord, "race_nogive", "race", u_race(u))); return; diff --git a/src/kernel/jsonconf.c b/src/kernel/jsonconf.c index 1b6995778..8db61376c 100644 --- a/src/kernel/jsonconf.c +++ b/src/kernel/jsonconf.c @@ -62,6 +62,7 @@ static int json_flags(cJSON *json, const char *flags[]) { for (i = 0; flags[i]; ++i) { if (strcmp(flags[i], entry->valuestring) == 0) { result |= (1 << i); + break; } } } @@ -344,7 +345,7 @@ static void json_race(cJSON *json, race *rc) { "coastal", "", "cansail", 0 }; const char *ecflags[] = { - "", "giveitem", "giveperson", + "", "keepitem", "giveperson", "giveunit", "getitem", 0 }; if (json->type != cJSON_Object) { diff --git a/src/kernel/jsonconf.test.c b/src/kernel/jsonconf.test.c index db861fcfc..bbe222fb6 100644 --- a/src/kernel/jsonconf.test.c +++ b/src/kernel/jsonconf.test.c @@ -51,7 +51,7 @@ static void test_flags(CuTest *tc) { check_flag(tc, "dragon", RCF_DRAGON); check_flag(tc, "fly", RCF_FLY); check_ec_flag(tc, "getitem", GETITEM); - check_ec_flag(tc, "giveitem", GIVEITEM); + check_ec_flag(tc, "keepitem", ECF_KEEP_ITEM); check_ec_flag(tc, "giveperson", GIVEPERSON); check_ec_flag(tc, "giveunit", GIVEUNIT); test_cleanup(); diff --git a/src/kernel/pool.c b/src/kernel/pool.c index e487abf23..12e314fd3 100644 --- a/src/kernel/pool.c +++ b/src/kernel/pool.c @@ -179,7 +179,7 @@ int count) if (u != v && (v->items || rtype->uget)) { int mask; - if ((urace(v)->ec_flags & GIVEITEM) == 0) + if ((urace(v)->ec_flags & ECF_KEEP_ITEM)) continue; if (v->faction == f) { @@ -232,7 +232,7 @@ use_pooled(unit * u, const resource_type * rtype, unsigned int mode, int count) for (v = r->units; use > 0 && v != NULL; v = v->next) { if (u != v) { int mask; - if ((urace(v)->ec_flags & GIVEITEM) == 0) + if ((urace(v)->ec_flags & ECF_KEEP_ITEM)) continue; if (v->items == NULL && rtype->uget == NULL) continue; diff --git a/src/kernel/race.h b/src/kernel/race.h index cccc88167..d8246a382 100644 --- a/src/kernel/race.h +++ b/src/kernel/race.h @@ -215,7 +215,7 @@ extern "C" { #define RCF_IRONGOLEM (1<<28) /* race gets irongolem properties */ /* Economic flags */ -#define GIVEITEM (1<<1) /* gibt Gegenstände weg */ +#define ECF_KEEP_ITEM (1<<1) /* gibt Gegenstände weg */ #define GIVEPERSON (1<<2) /* übergibt Personen */ #define GIVEUNIT (1<<3) /* Einheiten an andere Partei übergeben */ #define GETITEM (1<<4) /* nimmt Gegenstände an */ diff --git a/src/kernel/unit.c b/src/kernel/unit.c index d65c7b3c2..a946caae0 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -257,9 +257,9 @@ static buddy *get_friends(const unit * u, int *numfriends) *fr = nf; } else if (nf->faction == u2->faction - && (u_race(u2)->ec_flags & GIVEITEM)) { + && !(u_race(u2)->ec_flags & ECF_KEEP_ITEM)) { /* we don't like to gift it to units that won't give it back */ - if ((u_race(nf->unit)->ec_flags & GIVEITEM) == 0) { + if ((u_race(nf->unit)->ec_flags & ECF_KEEP_ITEM)) { nf->unit = u2; } } @@ -300,7 +300,7 @@ int gift_items(unit * u, int flags) if (u->items == NULL || fval(u_race(u), RCF_ILLUSIONARY)) return 0; - if ((u_race(u)->ec_flags & GIVEITEM) == 0) + if ((u_race(u)->ec_flags & ECF_KEEP_ITEM)) return 0; /* at first, I should try giving my crap to my own units in this region */ @@ -311,7 +311,7 @@ int gift_items(unit * u, int flags) /* some units won't take stuff: */ if (u_race(u2)->ec_flags & GETITEM) { /* we don't like to gift it to units that won't give it back */ - if (u_race(u2)->ec_flags & GIVEITEM) { + if (!(u_race(u2)->ec_flags & ECF_KEEP_ITEM)) { i_merge(&u2->items, &u->items); u->items = NULL; break; diff --git a/src/kernel/xmlreader.c b/src/kernel/xmlreader.c index 00f10b8ac..ae9cf9c43 100644 --- a/src/kernel/xmlreader.c +++ b/src/kernel/xmlreader.c @@ -1693,8 +1693,8 @@ static int parse_races(xmlDocPtr doc) if (xml_bvalue(node, "irongolem", false)) rc->flags |= RCF_IRONGOLEM; - if (xml_bvalue(node, "giveitem", true)) - rc->ec_flags |= GIVEITEM; + if (!xml_bvalue(node, "keepitem", false)) + rc->ec_flags |= ECF_KEEP_ITEM; if (xml_bvalue(node, "giveperson", false)) rc->ec_flags |= GIVEPERSON; if (xml_bvalue(node, "giveunit", false)) diff --git a/src/laws.c b/src/laws.c index 8caf8eb60..9a1358733 100755 --- a/src/laws.c +++ b/src/laws.c @@ -3092,7 +3092,7 @@ static building *age_building(building * b) * find out if there's a magician in there. */ for (u = r->units; u; u = u->next) { if (b == u->building && inside_building(u)) { - if (!(u_race(u)->ec_flags & GIVEITEM) == 0) { + if ((u_race(u)->ec_flags & ECF_KEEP_ITEM) == 0) { int n, unicorns = 0; for (n = 0; n != u->number; ++n) { if (chance(0.02)) { diff --git a/src/tests.c b/src/tests.c index ed554915b..9c03e1e18 100644 --- a/src/tests.c +++ b/src/tests.c @@ -31,7 +31,7 @@ struct race *test_create_race(const char *name) { race *rc = rc_get_or_create(name); rc->maintenance = 10; - rc->ec_flags |= GETITEM | GIVEITEM; + rc->ec_flags |= GETITEM; return rc; } diff --git a/src/upkeep.c b/src/upkeep.c index 5eecc1b42..d1c34f476 100644 --- a/src/upkeep.c +++ b/src/upkeep.c @@ -42,9 +42,7 @@ int lifestyle(const unit * u) static bool help_money(const unit * u) { - if (u_race(u)->ec_flags & GIVEITEM) - return true; - return false; + return !(u_race(u)->ec_flags & ECF_KEEP_ITEM); } static void help_feed(unit * donor, unit * u, int *need_p) From d2fbdec8311a85fa8325fd85af79d6e854de44b8 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Apr 2015 15:07:10 +0200 Subject: [PATCH 3/4] re-enable disabled tests for E2, add test for FOLLOW. --- scripts/tests/e2/init.lua | 6 +++--- scripts/tests/e2/movement.lua | 15 +++++++++++++++ src/kernel/order.c | 1 + src/move.c | 5 +++-- 4 files changed, 22 insertions(+), 5 deletions(-) diff --git a/scripts/tests/e2/init.lua b/scripts/tests/e2/init.lua index 427a7884d..bec715853 100644 --- a/scripts/tests/e2/init.lua +++ b/scripts/tests/e2/init.lua @@ -1,4 +1,4 @@ --- require 'tests.e2.shiplanding' --- require 'tests.e2.e2features' --- require 'tests.e2.movement' +require 'tests.e2.shiplanding' +require 'tests.e2.e2features' +require 'tests.e2.movement' require 'tests.e2.guard' diff --git a/scripts/tests/e2/movement.lua b/scripts/tests/e2/movement.lua index c97fccac7..e0c433761 100644 --- a/scripts/tests/e2/movement.lua +++ b/scripts/tests/e2/movement.lua @@ -44,3 +44,18 @@ function test_dolphin_in_ocean() process_orders() assert_equal(r2, u1.region) end + +function test_follow() + local r1 = region.create(0, 0, "plain") + local r2 = region.create(1, 0, "plain") + local f = faction.create("test@example.com", "human", "de") + local u1 = unit.create(f, r1, 1) + local u2 = unit.create(f, r1, 1) + u1:clear_orders() + u2:clear_orders() + u1:add_order("NACH O") + u2:add_order("FOLGE EINHEIT " .. itoa36(u1.id)) + process_orders() + assert_equal(u1.region, r2) + assert_equal(u2.region, r2) +end diff --git a/src/kernel/order.c b/src/kernel/order.c index 70114125d..fc29932fc 100644 --- a/src/kernel/order.c +++ b/src/kernel/order.c @@ -305,6 +305,7 @@ order *create_order(keyword_t kwd, const struct locale * lang, switch (*params) { case 's': s = va_arg(marker, const char *); + assert(s); bytes = (int)strlcpy(bufp, s, size); if (wrptr(&bufp, &size, bytes) != 0) WARN_STATIC_BUFFER(); diff --git a/src/move.c b/src/move.c index 25ee31d9a..54864b89e 100644 --- a/src/move.c +++ b/src/move.c @@ -2313,10 +2313,11 @@ static void travel(unit * u, region_list ** routep) if (uf->region == r) { order *follow_order; const struct locale *lang = u->faction->locale; - + const char *s = LOC(uf->faction->locale, parameters[P_UNIT]); /* construct an order */ + assert(s || !"missing translation for UNIT keyword"); follow_order = create_order(K_FOLLOW, lang, "%s %i", - LOC(uf->faction->locale, parameters[P_UNIT]), ut->no); + s, ut->no); route_end = reroute(uf, route_begin, route_end); travel_i(uf, route_begin, route_end, follow_order, TRAVEL_FOLLOWING, From a5e68e10fec74412c046b78e7132e5ec86e17253 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Mon, 20 Apr 2015 15:19:17 +0200 Subject: [PATCH 4/4] test for FOLLOW SHIP --- scripts/tests/e2/movement.lua | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/scripts/tests/e2/movement.lua b/scripts/tests/e2/movement.lua index e0c433761..ef62873d8 100644 --- a/scripts/tests/e2/movement.lua +++ b/scripts/tests/e2/movement.lua @@ -53,9 +53,34 @@ function test_follow() local u2 = unit.create(f, r1, 1) u1:clear_orders() u2:clear_orders() + u1:add_item("money", 100) + u2:add_item("money", 100) u1:add_order("NACH O") u2:add_order("FOLGE EINHEIT " .. itoa36(u1.id)) process_orders() assert_equal(u1.region, r2) assert_equal(u2.region, r2) end + +function test_follow_ship() + local r1 = region.create(0, 0, "plain") + region.create(1, 0, "ocean") + region.create(2, 0, "ocean") + local f = faction.create("test@example.com", "human", "de") + local u1 = unit.create(f, r1, 1) + local u2 = unit.create(f, r1, 1) + u1:add_item("money", 100) + u2:add_item("money", 100) + u1.ship = ship.create(r1, "boat") + assert(u1.ship) + u1:set_skill("sailing", 2) + u1:clear_orders() + u1:add_order("NACH O O") + u2.ship = ship.create(r1, "boat") + u2:set_skill("sailing", 2) + u2:clear_orders() + u2:add_order("FOLGE SCHIFF " .. itoa36(u1.ship.id)) + process_orders() + assert_equal(2, u1.region.x) + assert_equal(2, u2.region.x) +end