From b50c1720cf9ff09f2d9390ebb44bf087aaecd8ae Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 16 Aug 2015 16:18:59 +0200 Subject: [PATCH] several monster_attack fixes. 1. do not try to attack other monsters. 2. monsters outside of a building can attack units outside of buildings. 3. dragons can guard without weapons. --- res/eressea/races.xml | 10 +++++----- src/kernel/race.c | 5 +---- src/monsters.c | 11 ++++------- src/move.c | 4 +--- src/spells.c | 4 ++-- 5 files changed, 13 insertions(+), 21 deletions(-) diff --git a/res/eressea/races.xml b/res/eressea/races.xml index 26a63752f..7f6c6d873 100644 --- a/res/eressea/races.xml +++ b/res/eressea/races.xml @@ -430,7 +430,7 @@ - + @@ -733,7 +733,7 @@ - + @@ -745,7 +745,7 @@ - + @@ -758,7 +758,7 @@ - + @@ -1170,7 +1170,7 @@ - + diff --git a/src/kernel/race.c b/src/kernel/race.c index 155a1d326..811b78296 100644 --- a/src/kernel/race.c +++ b/src/kernel/race.c @@ -175,8 +175,6 @@ race *rc_get_or_create(const char *zName) assert(zName); rc = rc_find_i(zName); if (!rc) { - char zBuffer[80]; - rc = (race *)calloc(sizeof(race), 1); rc->hitpoints = 1; rc->weight = PERSON_WEIGHT; @@ -189,8 +187,7 @@ race *rc_get_or_create(const char *zName) log_error("race '%s' has an invalid name. remove spaces\n", zName); assert(strchr(zName, ' ') == NULL); } - strcpy(zBuffer, zName); - rc->_name = _strdup(zBuffer); + rc->_name = _strdup(zName); rc->precombatspell = NULL; rc->attack[0].type = AT_COMBATSPELL; diff --git a/src/monsters.c b/src/monsters.c index d81ba7f81..fdcb3d7e6 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -146,10 +146,8 @@ static void reduce_weight(unit * u) static order *monster_attack(unit * u, const unit * target) { - if (u->region != target->region) - return NULL; - if (u->faction == target->faction) - return NULL; + assert(u->region == target->region); + assert(u->faction != target->faction); if (!cansee(u->faction, u->region, target, 0)) return NULL; if (monster_is_waiting(u)) @@ -167,7 +165,7 @@ static order *get_money_for_dragon(region * r, unit * u, int wanted) if (attack_chance > 0.0 && is_guard(u, GUARD_TAX)) { /* attackiere bewachende Einheiten nur wenn wir selbst schon bewachen */ for (u2 = r->units; u2; u2 = u2->next) { - if (u2 != u && is_guard(u2, GUARD_TAX)) { + if (u2 != u && is_guard(u2, GUARD_TAX) && u->faction!=u2->faction) { /*In E3 + E4 etwas problematisch, da der Regionsbesitzer immer bewacht. Der Drache greift also immer die Burg an!*/ order *ord = monster_attack(u, u2); if (ord) @@ -557,8 +555,7 @@ static void monster_attacks(unit * u) unit *u2; for (u2 = r->units; u2; u2 = u2->next) { - if (cansee(u->faction, r, u2, 0) && u2->faction != u->faction && inside_building(u2) != u->building - && chance(0.75)) { + if (u2->faction != u->faction && cansee(u->faction, r, u2, 0) && !inside_building(u2)) { order *ord = monster_attack(u, u2); if (ord) addlist(&u->orders, ord); diff --git a/src/move.c b/src/move.c index 4fd9e6dab..27449423e 100644 --- a/src/move.c +++ b/src/move.c @@ -970,9 +970,7 @@ static bool is_guardian_r(const unit * guard) if ((guard->flags & UFL_GUARD) == 0) return false; - if (!armedmen(guard, true) && !fval(u_race(guard), RCF_UNARMEDGUARD)) - return false; - return true; + return armedmen(guard, true) > 0 || fval(u_race(guard), RCF_UNARMEDGUARD); } bool is_guard(const struct unit * u, unsigned int mask) diff --git a/src/spells.c b/src/spells.c index 8b504487a..cf38dd74b 100644 --- a/src/spells.c +++ b/src/spells.c @@ -6564,14 +6564,14 @@ static spelldata spell_functions[] = { { "analysedream", sp_analysedream, 0 }, { "disturbingdreams", sp_disturbingdreams, 0 }, { "sleep", sp_sleep, 0 }, - { "wisps", 0, 0 }, /* this spell is gone */ + { "wisps", 0, 0 }, /* TODO: this spell is gone */ { "gooddreams", sp_gooddreams, 0 }, { "illaundestroymagic", sp_destroy_magic, 0 }, { "clone", sp_clonecopy, 0 }, { "bad_dreams", sp_baddreams, 0 }, { "mindblast", sp_mindblast_temp, 0 }, { "orkdream", sp_sweetdreams, 0 }, - { "summon_alp", sp_summon_alp, 0 }, + { "summon_alp", sp_summon_alp, 0 }, // TODO: this spell is disabled everywhere /* M_CERDDOR */ { "appeasement", sp_denyattack, 0 }, { "song_of_healing", sp_healing, 0 },