From 6e7510b7e9848ea3cf81184aa69494d55789bf51 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 00:32:56 +0100 Subject: [PATCH] moved flying ship functionality from spells.c and shipcurse.c to flyingship.c --- src/bind_monsters.c | 1 + src/flyingship.c | 86 ++++++++++++++++++++++++++++++++++++++++++ src/flyingship.h | 5 ++- src/spells.c | 67 +------------------------------- src/spells/shipcurse.c | 9 ----- src/spells/shipcurse.h | 2 - 6 files changed, 92 insertions(+), 78 deletions(-) diff --git a/src/bind_monsters.c b/src/bind_monsters.c index a106ec638..67ca8ef64 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -1,6 +1,7 @@ #include #include "spells/shipcurse.h" #include "monster.h" +#include "flyingship.h" #include #include diff --git a/src/flyingship.c b/src/flyingship.c index 1f2f59045..88d37a6d1 100644 --- a/src/flyingship.c +++ b/src/flyingship.c @@ -2,4 +2,90 @@ #include #include "flyingship.h" +#include +#include +#include +#include +#include +#include +#include + +/* libc includes */ +#include + +int levitate_ship(ship * sh, unit * mage, double power, int duration) +{ + curse *c = shipcurse_flyingship(sh, mage, power, duration); + if (c) { + return c->no; + } + return 0; +} + +/* ------------------------------------------------------------- */ +/* Name: Luftschiff +* Stufe: 6 +* +* Wirkung: +* Laeßt ein Schiff eine Runde lang fliegen. Wirkt nur auf Boote und +* Langboote. +* Kombinierbar mit "Guenstige Winde", aber nicht mit "Sturmwind". +* +* Flag: +* (ONSHIPCAST | SHIPSPELL | TESTRESISTANCE) +*/ +int sp_flying_ship(castorder * co) +{ + ship *sh; + unit *u; + region *r = co_get_region(co); + unit *mage = co->magician.u; + int cast_level = co->level; + double power = co->force; + spellparameter *pa = co->par; + message *m = NULL; + int cno; + + /* wenn kein Ziel gefunden, Zauber abbrechen */ + if (pa->param[0]->flag == TARGET_NOTFOUND) + return 0; + sh = pa->param[0]->data.sh; + if (sh->type->construction->maxsize > 50) { + ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, + "error_flying_ship_too_big", "ship", sh)); + return 0; + } + + /* Duration = 1, nur diese Runde */ + + cno = levitate_ship(sh, mage, power, 1); + if (cno == 0) { + if (is_cursed(sh->attribs, C_SHIP_FLYING, 0)) { + /* Auf dem Schiff befindet liegt bereits so ein Zauber. */ + cmistake(mage, co->order, 211, MSG_MAGIC); + } + else if (is_cursed(sh->attribs, C_SHIP_SPEEDUP, 0)) { + /* Es ist zu gefaehrlich, ein sturmgepeitschtes Schiff fliegen zu lassen. */ + cmistake(mage, co->order, 210, MSG_MAGIC); + } + return 0; + } + sh->coast = NODIRECTION; + + /* melden, 1x pro Partei */ + for (u = r->units; u; u = u->next) + freset(u->faction, FFL_SELECT); + for (u = r->units; u; u = u->next) { + /* das sehen natuerlich auch die Leute an Land */ + if (!fval(u->faction, FFL_SELECT)) { + fset(u->faction, FFL_SELECT); + if (!m) + m = msg_message("flying_ship_result", "mage ship", mage, sh); + add_message(&u->faction->msgs, m); + } + } + if (m) + msg_release(m); + return cast_level; +} diff --git a/src/flyingship.h b/src/flyingship.h index 9676f0191..33bc3a86f 100644 --- a/src/flyingship.h +++ b/src/flyingship.h @@ -3,13 +3,16 @@ #ifndef FLYINGSHIP_H #define FLYINGSHIP_H - +#include "magic.h" #ifdef __cplusplus extern "C" { #endif + int levitate_ship(struct ship *sh, struct unit *mage, double power, + int duration); + int sp_flying_ship(castorder * co); #ifdef __cplusplus } diff --git a/src/spells.c b/src/spells.c index d9f7f4b10..916867a0a 100644 --- a/src/spells.c +++ b/src/spells.c @@ -22,6 +22,7 @@ #include "direction.h" #include "randenc.h" #include "monster.h" +#include "flyingship.h" #include #include @@ -5993,72 +5994,6 @@ int sp_movecastle(castorder * co) return cast_level; } -/* ------------------------------------------------------------- */ -/* Name: Luftschiff - * Stufe: 6 - * - * Wirkung: - * Laeßt ein Schiff eine Runde lang fliegen. Wirkt nur auf Boote und - * Langboote. - * Kombinierbar mit "Guenstige Winde", aber nicht mit "Sturmwind". - * - * Flag: - * (ONSHIPCAST | SHIPSPELL | TESTRESISTANCE) - */ -int sp_flying_ship(castorder * co) -{ - ship *sh; - unit *u; - region *r = co_get_region(co); - unit *mage = co->magician.u; - int cast_level = co->level; - double power = co->force; - spellparameter *pa = co->par; - message *m = NULL; - int cno; - - /* wenn kein Ziel gefunden, Zauber abbrechen */ - if (pa->param[0]->flag == TARGET_NOTFOUND) - return 0; - sh = pa->param[0]->data.sh; - if (sh->type->construction->maxsize > 50) { - ADDMSG(&mage->faction->msgs, msg_feedback(mage, co->order, - "error_flying_ship_too_big", "ship", sh)); - return 0; - } - - /* Duration = 1, nur diese Runde */ - - cno = levitate_ship(sh, mage, power, 1); - if (cno == 0) { - if (is_cursed(sh->attribs, C_SHIP_FLYING, 0)) { - /* Auf dem Schiff befindet liegt bereits so ein Zauber. */ - cmistake(mage, co->order, 211, MSG_MAGIC); - } - else if (is_cursed(sh->attribs, C_SHIP_SPEEDUP, 0)) { - /* Es ist zu gefaehrlich, ein sturmgepeitschtes Schiff fliegen zu lassen. */ - cmistake(mage, co->order, 210, MSG_MAGIC); - } - return 0; - } - sh->coast = NODIRECTION; - - /* melden, 1x pro Partei */ - for (u = r->units; u; u = u->next) - freset(u->faction, FFL_SELECT); - for (u = r->units; u; u = u->next) { - /* das sehen natuerlich auch die Leute an Land */ - if (!fval(u->faction, FFL_SELECT)) { - fset(u->faction, FFL_SELECT); - if (!m) - m = msg_message("flying_ship_result", "mage ship", mage, sh); - add_message(&u->faction->msgs, m); - } - } - if (m) - msg_release(m); - return cast_level; -} /* ------------------------------------------------------------- */ /* Name: Stehle Aura diff --git a/src/spells/shipcurse.c b/src/spells/shipcurse.c index 29e4ad8f8..5faab25fe 100644 --- a/src/spells/shipcurse.c +++ b/src/spells/shipcurse.c @@ -146,15 +146,6 @@ curse *shipcurse_flyingship(ship * sh, unit * mage, double power, int duration) } } -int levitate_ship(ship * sh, unit * mage, double power, int duration) -{ - curse *c = shipcurse_flyingship(sh, mage, power, duration); - if (c) { - return c->no; - } - return 0; -} - void register_shipcurse(void) { ct_register(&ct_stormwind); diff --git a/src/spells/shipcurse.h b/src/spells/shipcurse.h index 676cd7344..edb9b70c4 100644 --- a/src/spells/shipcurse.h +++ b/src/spells/shipcurse.h @@ -30,8 +30,6 @@ extern "C" { void register_shipcurse(void); struct curse *shipcurse_flyingship(struct ship *sh, struct unit *mage, double power, int duration); - int levitate_ship(struct ship *sh, struct unit *mage, double power, - int duration); #ifdef __cplusplus }