diff --git a/src/monsters.c b/src/monsters.c index f5d38a446..78999e015 100644 --- a/src/monsters.c +++ b/src/monsters.c @@ -485,65 +485,6 @@ static order *make_movement_order(unit * u, const region * target, int moves, return parse_order(zOrder, u->faction->locale); } -#ifdef TODO_ALP -static order *monster_seeks_target(region * r, unit * u) -{ - direction_t d; - unit *target = NULL; - int dist, dist2; - direction_t i; - region *nr; - - /* Das Monster sucht ein bestimmtes Opfer. Welches, steht - * in einer Referenz/attribut - * derzeit gibt es nur den alp - */ - - switch (old_race(u_race(u))) { - case RC_ALP: - target = alp_target(u); - break; - default: - assert(!"Seeker-Monster gibt kein Ziel an"); - } - - /* TODO: prüfen, ob target überhaupt noch existiert... */ - if (!target) { - log_error("Monster '%s' hat kein Ziel!\n", unitname(u)); - return NULL; /* this is a bug workaround! remove!! */ - } - - if (r == target->region) { /* Wir haben ihn! */ - if (u_race(u) == get_race(RC_ALP)) { - alp_findet_opfer(u, r); - } else { - assert(!"Seeker-Monster hat keine Aktion fuer Ziel"); - } - return NULL; - } - - /* Simpler Ansatz: Nachbarregion mit gerinster Distanz suchen. - * Sinnvoll momentan nur bei Monstern, die sich nicht um das - * Terrain kümmern. Nebelwände & Co machen derzeit auch nix... - */ - dist2 = distance(r, target->region); - d = NODIRECTION; - for (i = 0; i < MAXDIRECTIONS; i++) { - nr = rconnect(r, i); - assert(nr); - dist = distance(nr, target->region); - if (dist < dist2) { - dist2 = dist; - d = i; - } - } - assert(d != NODIRECTION); - - return create_order(K_MOVE, u->faction->locale, "%s", - LOC(u->faction->locale, directions[d])); -} -#endif - void random_growl(const unit *u, region *target, int rand) { const struct locale *lang = u->faction->locale; @@ -652,6 +593,13 @@ static order *plan_dragon(unit * u) region *tr = NULL; bool move = false; order *long_order = NULL; + static int rc_cache; + static const race *rc_wyrm; + const race * rc = u_race(u); + + if (rc_changed(&rc_cache)) { + rc_wyrm = get_race(RC_WYRM); + } if (ta == NULL) { move |= (rpeasants(r) == 0); /* when no peasants, move */ @@ -659,7 +607,7 @@ static order *plan_dragon(unit * u) } move |= chance(0.04); /* 4% chance to change your mind */ - if (u_race(u) == get_race(RC_WYRM) && !move) { + if (rc == rc_wyrm && !move) { unit *u2; for (u2 = r->units; u2; u2 = u2->next) { /* wyrme sind einzelgänger */ @@ -689,18 +637,21 @@ static order *plan_dragon(unit * u) } if (tr != NULL) { assert(long_order == NULL); - switch (old_race(u_race(u))) { - case RC_FIREDRAGON: - long_order = make_movement_order(u, tr, 4, allowed_dragon); - break; - case RC_DRAGON: - long_order = make_movement_order(u, tr, 3, allowed_dragon); - break; - case RC_WYRM: + // TODO: per-race planning functions? + if (rc == rc_wyrm) { long_order = make_movement_order(u, tr, 1, allowed_dragon); - break; - default: - break; + } + else { + switch (old_race(rc)) { + case RC_FIREDRAGON: + long_order = make_movement_order(u, tr, 4, allowed_dragon); + break; + case RC_DRAGON: + long_order = make_movement_order(u, tr, 3, allowed_dragon); + break; + default: + break; + } } if (long_order) { reduce_weight(u); @@ -752,6 +703,7 @@ void plan_monsters(faction * f) bool attacking = chance(attack_chance); for (u = r->units; u; u = u->next) { + const race *rc = u_race(u); attrib *ta; order *long_order = NULL; @@ -807,7 +759,7 @@ void plan_monsters(faction * f) a_remove(&u->attribs, ta); } } - else if (u_race(u)->flags & RCF_MOVERANDOM) { + else if (rc->flags & RCF_MOVERANDOM) { if (chance(random_move_chance()) || check_overpopulated(u)) { long_order = monster_move(r, u); } @@ -821,31 +773,24 @@ void plan_monsters(faction * f) handle_event(u->attribs, "ai_move", u); } - switch (old_race(u_race(u))) { - case RC_SEASERPENT: - long_order = create_order(K_PIRACY, f->locale, NULL); - break; -#ifdef TODO_ALP - case RC_ALP: - long_order = monster_seeks_target(r, u); - break; -#endif - case RC_FIREDRAGON: - case RC_DRAGON: - case RC_WYRM: + if (fval(rc, RCF_DRAGON)) { long_order = plan_dragon(u); - break; - default: - if (u_race(u)->flags & RCF_LEARN) { - long_order = monster_learn(u); + } + else { + if (rc == get_race(RC_SEASERPENT)) { + long_order = create_order(K_PIRACY, f->locale, NULL); + } + else { + if (rc->flags & RCF_LEARN) { + long_order = monster_learn(u); + } } - break; } } if (long_order == NULL && unit_can_study(u)) { /* Einheiten, die Waffenlosen Kampf lernen könnten, lernen es um * zu bewachen: */ - if (u_race(u)->bonus[SK_WEAPONLESS] != -99) { + if (rc->bonus[SK_WEAPONLESS] != -99) { if (effskill(u, SK_WEAPONLESS, 0) < 1) { long_order = create_order(K_STUDY, f->locale, "'%s'", diff --git a/src/monsters.test.c b/src/monsters.test.c index a44a354d9..6797a9ce0 100644 --- a/src/monsters.test.c +++ b/src/monsters.test.c @@ -54,8 +54,7 @@ static void create_monsters(faction **player, faction **monsters, unit **u, unit *monsters = get_or_create_monsters(); assert(rc_find((*monsters)->race->_name)); rc = rc_get_or_create((*monsters)->race->_name); - fset(rc, RCF_UNARMEDGUARD); - fset(rc, RCF_NPC); + fset(rc, RCF_UNARMEDGUARD|RCF_NPC|RCF_DRAGON); fset(*monsters, FFL_NOIDLEOUT); assert(fval(*monsters, FFL_NPC) && fval((*monsters)->race, RCF_UNARMEDGUARD) && fval((*monsters)->race, RCF_NPC) && fval(*monsters, FFL_NOIDLEOUT)); diff --git a/src/move.c b/src/move.c index a97bc5425..63c79dd6b 100644 --- a/src/move.c +++ b/src/move.c @@ -1473,7 +1473,7 @@ static int movement_speed(unit * u) return BP_DRAGON; } switch (old_race(u_race(u))) { - case RC_BIRTHDAYDRAGON: + case RC_BIRTHDAYDRAGON: // FIXME: catdragon has RCF_DRAGON, so this cannot happen case RC_SONGDRAGON: mp = BP_DRAGON; break;