From 39b355073b178ddca269016bb13974f0f9669273 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 31 Aug 2016 09:26:48 +0200 Subject: [PATCH 1/6] fix mac build with clang 7.3 --- src/kernel/race.c | 2 +- src/kernel/race.test.c | 9 +++++++++ src/spells.c | 2 +- tolua | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/kernel/race.c b/src/kernel/race.c index be9f2ab68..2c22f6c09 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -155,7 +155,7 @@ static race *rc_find_i(const char *name) const char *rname = name; race *rc = races; - while (rc && !strcmp(rname, rc->_name) == 0) { + while (rc && strcmp(rname, rc->_name) != 0) { rc = rc->next; } if (!rc && strcmp(name, "uruk") == 0) { diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index aa37093d4..e8bbfcf29 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -41,11 +41,20 @@ static void test_rc_defaults(CuTest *tc) { test_cleanup(); } +static void test_rc_find(CuTest *tc) { + race *rc; + test_cleanup(); + rc = test_create_race("hungryhippos"); + CuAssertPtrEquals(tc, rc, (void *)rc_find("hungryhippos")); + test_cleanup(); +} + CuSuite *get_race_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_rc_name); SUITE_ADD_TEST(suite, test_rc_defaults); + SUITE_ADD_TEST(suite, test_rc_find); return suite; } diff --git a/src/spells.c b/src/spells.c index 1da440df2..e455f7395 100644 --- a/src/spells.c +++ b/src/spells.c @@ -5354,7 +5354,7 @@ int sp_leaveastral(castorder * co) u = pa->param[n]->data.u; if (!ucontact(u, mage)) { - if (power > 10 && !pa->param[n]->flag == TARGET_RESISTS + if (power > 10 && !(pa->param[n]->flag == TARGET_RESISTS) && can_survive(u, rt)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "feedback_no_contact_no_resist", "target", u)); diff --git a/tolua b/tolua index e53fe09e5..32cc6a3e7 160000 --- a/tolua +++ b/tolua @@ -1 +1 @@ -Subproject commit e53fe09e5789083698d2efb1fd36250efa700c34 +Subproject commit 32cc6a3e78238278bc5b1fb8566526558e5afdda From cd46bac13210b32cf7782ce622c3dce67f87912b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 31 Aug 2016 09:26:48 +0200 Subject: [PATCH 2/6] fix mac build with clang 7.3 --- src/kernel/race.c | 2 +- src/kernel/race.test.c | 9 +++++++++ src/spells.c | 2 +- tolua | 2 +- 4 files changed, 12 insertions(+), 3 deletions(-) diff --git a/src/kernel/race.c b/src/kernel/race.c index be9f2ab68..2c22f6c09 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -155,7 +155,7 @@ static race *rc_find_i(const char *name) const char *rname = name; race *rc = races; - while (rc && !strcmp(rname, rc->_name) == 0) { + while (rc && strcmp(rname, rc->_name) != 0) { rc = rc->next; } if (!rc && strcmp(name, "uruk") == 0) { diff --git a/src/kernel/race.test.c b/src/kernel/race.test.c index aa37093d4..e8bbfcf29 100644 --- a/src/kernel/race.test.c +++ b/src/kernel/race.test.c @@ -41,11 +41,20 @@ static void test_rc_defaults(CuTest *tc) { test_cleanup(); } +static void test_rc_find(CuTest *tc) { + race *rc; + test_cleanup(); + rc = test_create_race("hungryhippos"); + CuAssertPtrEquals(tc, rc, (void *)rc_find("hungryhippos")); + test_cleanup(); +} + CuSuite *get_race_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_rc_name); SUITE_ADD_TEST(suite, test_rc_defaults); + SUITE_ADD_TEST(suite, test_rc_find); return suite; } diff --git a/src/spells.c b/src/spells.c index 1da440df2..e455f7395 100644 --- a/src/spells.c +++ b/src/spells.c @@ -5354,7 +5354,7 @@ int sp_leaveastral(castorder * co) u = pa->param[n]->data.u; if (!ucontact(u, mage)) { - if (power > 10 && !pa->param[n]->flag == TARGET_RESISTS + if (power > 10 && !(pa->param[n]->flag == TARGET_RESISTS) && can_survive(u, rt)) { ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, "feedback_no_contact_no_resist", "target", u)); diff --git a/tolua b/tolua index e53fe09e5..32cc6a3e7 160000 --- a/tolua +++ b/tolua @@ -1 +1 @@ -Subproject commit e53fe09e5789083698d2efb1fd36250efa700c34 +Subproject commit 32cc6a3e78238278bc5b1fb8566526558e5afdda From 61a1cfa141be9eb881d330c1e4df3cfb19bbdc4b Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 31 Aug 2016 09:50:28 +0200 Subject: [PATCH 3/6] fix build script jobs determination on mac --- s/build | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/s/build b/s/build index ea0f5f3d0..1d580a349 100755 --- a/s/build +++ b/s/build @@ -5,8 +5,13 @@ while [ ! -d $ROOT/.git ]; do done [ -z "$BUILD" ] && BUILD=Debug - -[ -z "$JOBS" ] && [ "" != "which nproc" ] && JOBS=`nproc` +if [ -z "$JOBS" ] ; then + if [ -e /usr/sbin/sysctl ]; then + JOBS=`sysctl -n hw.ncpu` + else + JOBS=`nproc` + fi +fi DISTCC=`which distcc` if [ ! -z "$DISTCC" ] ; then JOBS=`distcc -j` From 9a72157cf3d5cd2dd1f3b1a1a844d89e81f4c7ec Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 31 Aug 2016 11:35:07 +0200 Subject: [PATCH 4/6] split out seaserpent creation for testing --- src/bind_monsters.c | 2 +- src/monsters.c | 24 +++++++++++++++++------- src/monsters.h | 8 ++++++++ 3 files changed, 26 insertions(+), 8 deletions(-) create mode 100644 src/monsters.h diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 6589e002a..271045491 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -1,6 +1,7 @@ #include #include "spells/shipcurse.h" #include "monster.h" +#include "monsters.h" #include #include @@ -28,7 +29,6 @@ static int tolua_levitate_ship(lua_State * L) } extern void spawn_undead(void); -extern void spawn_dragons(void); extern void plan_monsters(struct faction *f); static int tolua_planmonsters(lua_State * L) diff --git a/src/monsters.c b/src/monsters.c index 2fc2fcde3..67bf9370d 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -20,6 +20,8 @@ #include #include +#include "monsters.h" + #include "economy.h" #include "chaos.h" #include "give.h" @@ -883,7 +885,16 @@ static int nrand(int start, int sub) return res; } -/** Drachen und Seeschlangen können entstehen */ +unit *spawn_seaserpent(region *r, faction *f) { + unit *u = create_unit(r, f, 1, get_race(RC_SEASERPENT), 0, NULL, NULL); + fset(u, UFL_ISNEW | UFL_MOVED); + equip_unit(u, get_equipment("monster_seaserpent")); + return u; +} + +/** + * Drachen und Seeschlangen können entstehen + */ void spawn_dragons(void) { region *r; @@ -892,13 +903,12 @@ void spawn_dragons(void) for (r = regions; r; r = r->next) { unit *u; - if (fval(r->terrain, SEA_REGION) && rng_int() % 10000 < 1) { - u = create_unit(r, monsters, 1, get_race(RC_SEASERPENT), 0, NULL, NULL); - fset(u, UFL_ISNEW | UFL_MOVED); - equip_unit(u, get_equipment("monster_seaserpent")); + if (fval(r->terrain, SEA_REGION)) { + if (rng_int() % 10000 < 1) { + u = spawn_seaserpent(r, monsters); + } } - - if ((r->terrain == newterrain(T_GLACIER) + else if ((r->terrain == newterrain(T_GLACIER) || r->terrain == newterrain(T_SWAMP) || r->terrain == newterrain(T_DESERT)) && rng_int() % 10000 < (5 + 100 * chaosfactor(r))) { diff --git a/src/monsters.h b/src/monsters.h new file mode 100644 index 000000000..02e41c0a4 --- /dev/null +++ b/src/monsters.h @@ -0,0 +1,8 @@ +#pragma once + +struct unit; +struct region; +struct faction; + +struct unit *spawn_seaserpent(struct region *r, struct faction *f); +void spawn_dragons(void); From 8a157de36cd121317a9454e73038a9ca163035b3 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 31 Aug 2016 16:43:02 +0200 Subject: [PATCH 5/6] only name monsters that have a naming function. test is bad, failing. --- src/kernel/unit.c | 8 ++++---- src/monsters.test.c | 15 +++++++++++++++ 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/kernel/unit.c b/src/kernel/unit.c index 47e4a63b4..a95dbe4cb 100644 --- a/src/kernel/unit.c +++ b/src/kernel/unit.c @@ -1470,12 +1470,12 @@ unit *create_unit(region * r, faction * f, int number, const struct race *urace, /* u->region auch */ u->hp = unit_max_hp(u) * number; - if (!dname) { - name_unit(u); - } - else { + if (dname) { u->_name = _strdup(dname); } + else if (urace->generate_name || playerrace(urace)) { + name_unit(u); + } if (creator) { attrib *a; diff --git a/src/monsters.test.c b/src/monsters.test.c index dd69e6bdb..5e4f7138a 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -11,6 +11,7 @@ #include #include "monster.h" +#include "monsters.h" #include "guard.h" #include "reports.h" #include "skill.h" @@ -244,10 +245,24 @@ static void test_monsters_learn_exp(CuTest * tc) test_cleanup(); } +static void test_spawn_seaserpent(CuTest *tc) { + region *r; + unit *u; + faction *f; + test_cleanup(); + r = test_create_region(0, 0, 0); + f = test_create_faction(0); + u = spawn_seaserpent(r, f); + CuAssertPtrNotNull(tc, u); + CuAssertPtrEquals(tc, 0, u->_name); + test_cleanup(); +} + CuSuite *get_monsters_suite(void) { CuSuite *suite = CuSuiteNew(); SUITE_ADD_TEST(suite, test_monsters_attack); + SUITE_ADD_TEST(suite, test_spawn_seaserpent); SUITE_ADD_TEST(suite, test_monsters_attack_ocean); SUITE_ADD_TEST(suite, test_seaserpent_piracy); SUITE_ADD_TEST(suite, test_monsters_waiting); From 1eb0fd758a6b31a444ea0707727485206cbea369 Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Wed, 31 Aug 2016 16:47:36 +0200 Subject: [PATCH 6/6] fix broken seaserpent test --- src/monsters.test.c | 3 +++ 1 file changed, 3 insertions(+) diff --git a/src/monsters.test.c b/src/monsters.test.c index 5e4f7138a..a44a354d9 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -249,7 +249,10 @@ static void test_spawn_seaserpent(CuTest *tc) { region *r; unit *u; faction *f; + race *rc; test_cleanup(); + rc = test_create_race("seaserpent"); + rc->flags |= RCF_NPC; r = test_create_region(0, 0, 0); f = test_create_faction(0); u = spawn_seaserpent(r, f);