From 3fa4c18e879de1647aabc6cb4d2619f423d2374d Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 00:26:23 +0100 Subject: [PATCH 01/13] added files for new module "flyingship" --- src/CMakeLists.txt | 2 ++ src/flyingship.c | 5 +++++ src/flyingship.h | 18 ++++++++++++++++++ src/flyingship.test.c | 6 ++++++ 4 files changed, 31 insertions(+) create mode 100644 src/flyingship.c create mode 100644 src/flyingship.h create mode 100644 src/flyingship.test.c diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index c2551cc45..1817f9cb1 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -117,6 +117,7 @@ set (ERESSEA_SRC travelthru.c monsters.c wormhole.c + flyingship.c ${SPELLS_SRC} ${RACES_SRC} ${ITEMS_SRC} @@ -208,6 +209,7 @@ set(TESTS_SRC spy.test.c study.test.c upkeep.test.c + flyingship.test.c spells/magicresistance.test.c ${ATTRIBUTES_TESTS} ${UTIL_TESTS} diff --git a/src/flyingship.c b/src/flyingship.c new file mode 100644 index 000000000..1f2f59045 --- /dev/null +++ b/src/flyingship.c @@ -0,0 +1,5 @@ +#include +#include +#include "flyingship.h" + + diff --git a/src/flyingship.h b/src/flyingship.h new file mode 100644 index 000000000..9676f0191 --- /dev/null +++ b/src/flyingship.h @@ -0,0 +1,18 @@ +#pragma once + +#ifndef FLYINGSHIP_H +#define FLYINGSHIP_H + + + +#ifdef __cplusplus +extern "C" { +#endif + + + +#ifdef __cplusplus +} +#endif + +#endif \ No newline at end of file diff --git a/src/flyingship.test.c b/src/flyingship.test.c new file mode 100644 index 000000000..00c618cd9 --- /dev/null +++ b/src/flyingship.test.c @@ -0,0 +1,6 @@ +#include +#include "flyingship.h" + +#include +#include +#include From 6e7510b7e9848ea3cf81184aa69494d55789bf51 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 00:32:56 +0100 Subject: [PATCH 02/13] 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 } From d93305b180cdcd27e99c7b39da2b211742976a15 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 00:35:32 +0100 Subject: [PATCH 03/13] moved flying ship functionality from move.c to flyingship.c --- src/flyingship.c | 27 ++++++++++++++++++--------- src/flyingship.h | 7 +++++-- src/move.c | 10 +--------- 3 files changed, 24 insertions(+), 20 deletions(-) diff --git a/src/flyingship.c b/src/flyingship.c index 88d37a6d1..b640b8940 100644 --- a/src/flyingship.c +++ b/src/flyingship.c @@ -14,15 +14,6 @@ /* 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 @@ -89,3 +80,21 @@ int sp_flying_ship(castorder * co) msg_release(m); return cast_level; } + +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; +} + +bool flying_ship(const ship * sh) +{ + if (sh->type->flags & SFL_FLY) + return true; + if (sh->flags & SF_FLYING) + return true; + return false; +} diff --git a/src/flyingship.h b/src/flyingship.h index 33bc3a86f..cbf981f0c 100644 --- a/src/flyingship.h +++ b/src/flyingship.h @@ -5,14 +5,17 @@ #include "magic.h" +#include + #ifdef __cplusplus extern "C" { #endif + int sp_flying_ship(castorder * co); + int levitate_ship(struct ship *sh, struct unit *mage, double power, int duration); - - int sp_flying_ship(castorder * co); + bool flying_ship(const ship * sh); #ifdef __cplusplus } diff --git a/src/move.c b/src/move.c index 8eaf052ca..87b1e44f7 100644 --- a/src/move.c +++ b/src/move.c @@ -28,6 +28,7 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "monster.h" #include "lighthouse.h" #include "piracy.h" +#include "flyingship.h" #include #include @@ -674,15 +675,6 @@ int check_ship_allowed(struct ship *sh, const region * r) return SA_NO_COAST; } -static bool flying_ship(const ship * sh) -{ - if (sh->type->flags & SFL_FLY) - return true; - if (sh->flags & SF_FLYING) - return true; - return false; -} - static void set_coast(ship * sh, region * r, region * rnext) { if (sh->type->flags & SFL_NOCOAST) { From fe0d038bf3b4aeeee64774de0ab0c5e3f1896e93 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 13:39:06 +0100 Subject: [PATCH 04/13] moved more related functionality from shipcurse.c to flyingship.c --- src/flyingship.c | 69 ++++++++++++++++++++++++++++++++++++++++++ src/flyingship.h | 4 +++ src/spells.c | 2 ++ src/spells/shipcurse.c | 60 ------------------------------------ src/spells/shipcurse.h | 7 +---- 5 files changed, 76 insertions(+), 66 deletions(-) diff --git a/src/flyingship.c b/src/flyingship.c index b640b8940..090c3a445 100644 --- a/src/flyingship.c +++ b/src/flyingship.c @@ -1,5 +1,6 @@ #include #include +#include #include "flyingship.h" #include @@ -11,9 +12,51 @@ #include +#include + /* libc includes */ #include +static int flyingship_read(storage * store, curse * c, void *target) +{ + ship *sh = (ship *)target; + c->data.v = sh; + if (global.data_version < FOSS_VERSION) { + sh->flags |= SF_FLYING; + return 0; + } + assert(sh->flags & SF_FLYING); + return 0; +} + +static int flyingship_write(storage * store, const curse * c, + const void *target) +{ + const ship *sh = (const ship *)target; + assert(sh->flags & SF_FLYING); + return 0; +} + +static int flyingship_age(curse * c) +{ + ship *sh = (ship *)c->data.v; + if (sh && c->duration == 1) { + freset(sh, SF_FLYING); + return 1; + } + return 0; +} + +static struct curse_type ct_flyingship = { "flyingship", +CURSETYP_NORM, 0, NO_MERGE, cinfo_ship, NULL, flyingship_read, +flyingship_write, NULL, flyingship_age +}; + +void register_flyingship(void) +{ + ct_register(&ct_flyingship); +} + /* ------------------------------------------------------------- */ /* Name: Luftschiff * Stufe: 6 @@ -98,3 +141,29 @@ bool flying_ship(const ship * sh) return true; return false; } + +curse *shipcurse_flyingship(ship * sh, unit * mage, double power, int duration) +{ + static const curse_type *ct_flyingship = NULL; + if (!ct_flyingship) { + ct_flyingship = ct_find("flyingship"); + assert(ct_flyingship); + } + if (curse_active(get_curse(sh->attribs, ct_flyingship))) { + return NULL; + } + else if (is_cursed(sh->attribs, C_SHIP_SPEEDUP, 0)) { + return NULL; + } + else { + /* mit C_SHIP_NODRIFT haben wir kein Problem */ + curse *c = + create_curse(mage, &sh->attribs, ct_flyingship, power, duration, 0.0, 0); + c->data.v = sh; + if (c && c->duration > 0) { + sh->flags |= SF_FLYING; + } + return c; + } +} + diff --git a/src/flyingship.h b/src/flyingship.h index cbf981f0c..db7c9c716 100644 --- a/src/flyingship.h +++ b/src/flyingship.h @@ -11,8 +11,12 @@ extern "C" { #endif + void register_flyingship(void); + int sp_flying_ship(castorder * co); + 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); bool flying_ship(const ship * sh); diff --git a/src/spells.c b/src/spells.c index 916867a0a..82548ae71 100644 --- a/src/spells.c +++ b/src/spells.c @@ -6730,4 +6730,6 @@ void register_spells(void) register_shipcurse(); register_buildingcurse(); register_magicresistance(); + + register_flyingship(); } diff --git a/src/spells/shipcurse.c b/src/spells/shipcurse.c index 5faab25fe..5a1669b79 100644 --- a/src/spells/shipcurse.c +++ b/src/spells/shipcurse.c @@ -78,41 +78,6 @@ static struct curse_type ct_stormwind = { "stormwind", CURSETYP_NORM, 0, NO_MERGE, cinfo_ship }; -static int flyingship_read(storage * store, curse * c, void *target) -{ - ship *sh = (ship *)target; - c->data.v = sh; - if (global.data_version < FOSS_VERSION) { - sh->flags |= SF_FLYING; - return 0; - } - assert(sh->flags & SF_FLYING); - return 0; -} - -static int flyingship_write(storage * store, const curse * c, - const void *target) -{ - const ship *sh = (const ship *)target; - assert(sh->flags & SF_FLYING); - return 0; -} - -static int flyingship_age(curse * c) -{ - ship *sh = (ship *)c->data.v; - if (sh && c->duration == 1) { - freset(sh, SF_FLYING); - return 1; - } - return 0; -} - -static struct curse_type ct_flyingship = { "flyingship", -CURSETYP_NORM, 0, NO_MERGE, cinfo_ship, NULL, flyingship_read, -flyingship_write, NULL, flyingship_age -}; - static struct curse_type ct_nodrift = { "nodrift", CURSETYP_NORM, 0, (M_DURATION | M_VIGOUR), cinfo_shipnodrift }; @@ -121,35 +86,10 @@ static struct curse_type ct_shipspeedup = { "shipspeedup", CURSETYP_NORM, 0, 0, cinfo_ship }; -curse *shipcurse_flyingship(ship * sh, unit * mage, double power, int duration) -{ - static const curse_type *ct_flyingship = NULL; - if (!ct_flyingship) { - ct_flyingship = ct_find("flyingship"); - assert(ct_flyingship); - } - if (curse_active(get_curse(sh->attribs, ct_flyingship))) { - return NULL; - } - else if (is_cursed(sh->attribs, C_SHIP_SPEEDUP, 0)) { - return NULL; - } - else { - /* mit C_SHIP_NODRIFT haben wir kein Problem */ - curse *c = - create_curse(mage, &sh->attribs, ct_flyingship, power, duration, 0.0, 0); - c->data.v = sh; - if (c && c->duration > 0) { - sh->flags |= SF_FLYING; - } - return c; - } -} void register_shipcurse(void) { ct_register(&ct_stormwind); - ct_register(&ct_flyingship); ct_register(&ct_nodrift); ct_register(&ct_shipspeedup); } diff --git a/src/spells/shipcurse.h b/src/spells/shipcurse.h index edb9b70c4..4c7ce7931 100644 --- a/src/spells/shipcurse.h +++ b/src/spells/shipcurse.h @@ -13,23 +13,18 @@ #ifndef _SCURSE_H #define _SCURSE_H -#include +//#include #ifdef __cplusplus extern "C" { #endif - struct locale; struct message; - struct ship; - struct unit; struct curse; struct message *cinfo_ship(const void *obj, objtype_t typ, const struct curse *c, int self); void register_shipcurse(void); - struct curse *shipcurse_flyingship(struct ship *sh, struct unit *mage, - double power, int duration); #ifdef __cplusplus } From abd6be475f00e31a20aaeaa92876b8dd8b5a6022 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 13:55:28 +0100 Subject: [PATCH 05/13] that just slipped in the commit by accident... --- src/spells/shipcurse.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/spells/shipcurse.h b/src/spells/shipcurse.h index 4c7ce7931..9ac57b142 100644 --- a/src/spells/shipcurse.h +++ b/src/spells/shipcurse.h @@ -13,7 +13,7 @@ #ifndef _SCURSE_H #define _SCURSE_H -//#include +#include #ifdef __cplusplus extern "C" { From 098abcc144eb319137b79547fa177c8d1f917ded Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 14:01:38 +0100 Subject: [PATCH 06/13] internal restructuring in flyingship --- src/flyingship.c | 89 ++++++++++++++++++++++++------------------------ src/flyingship.h | 7 ++-- 2 files changed, 47 insertions(+), 49 deletions(-) diff --git a/src/flyingship.c b/src/flyingship.c index 090c3a445..af026c242 100644 --- a/src/flyingship.c +++ b/src/flyingship.c @@ -17,45 +17,6 @@ /* libc includes */ #include -static int flyingship_read(storage * store, curse * c, void *target) -{ - ship *sh = (ship *)target; - c->data.v = sh; - if (global.data_version < FOSS_VERSION) { - sh->flags |= SF_FLYING; - return 0; - } - assert(sh->flags & SF_FLYING); - return 0; -} - -static int flyingship_write(storage * store, const curse * c, - const void *target) -{ - const ship *sh = (const ship *)target; - assert(sh->flags & SF_FLYING); - return 0; -} - -static int flyingship_age(curse * c) -{ - ship *sh = (ship *)c->data.v; - if (sh && c->duration == 1) { - freset(sh, SF_FLYING); - return 1; - } - return 0; -} - -static struct curse_type ct_flyingship = { "flyingship", -CURSETYP_NORM, 0, NO_MERGE, cinfo_ship, NULL, flyingship_read, -flyingship_write, NULL, flyingship_age -}; - -void register_flyingship(void) -{ - ct_register(&ct_flyingship); -} /* ------------------------------------------------------------- */ /* Name: Luftschiff @@ -124,15 +85,46 @@ int sp_flying_ship(castorder * co) return cast_level; } -int levitate_ship(ship * sh, unit * mage, double power, int duration) +static int flyingship_read(storage * store, curse * c, void *target) { - curse *c = shipcurse_flyingship(sh, mage, power, duration); - if (c) { - return c->no; + ship *sh = (ship *)target; + c->data.v = sh; + if (global.data_version < FOSS_VERSION) { + sh->flags |= SF_FLYING; + return 0; + } + assert(sh->flags & SF_FLYING); + return 0; +} + +static int flyingship_write(storage * store, const curse * c, + const void *target) +{ + const ship *sh = (const ship *)target; + assert(sh->flags & SF_FLYING); + return 0; +} + +static int flyingship_age(curse * c) +{ + ship *sh = (ship *)c->data.v; + if (sh && c->duration == 1) { + freset(sh, SF_FLYING); + return 1; } return 0; } +static struct curse_type ct_flyingship = { "flyingship", +CURSETYP_NORM, 0, NO_MERGE, cinfo_ship, NULL, flyingship_read, +flyingship_write, NULL, flyingship_age +}; + +void register_flyingship(void) +{ + ct_register(&ct_flyingship); +} + bool flying_ship(const ship * sh) { if (sh->type->flags & SFL_FLY) @@ -142,7 +134,7 @@ bool flying_ship(const ship * sh) return false; } -curse *shipcurse_flyingship(ship * sh, unit * mage, double power, int duration) +static curse *shipcurse_flyingship(ship * sh, unit * mage, double power, int duration) { static const curse_type *ct_flyingship = NULL; if (!ct_flyingship) { @@ -167,3 +159,12 @@ 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; +} + diff --git a/src/flyingship.h b/src/flyingship.h index db7c9c716..92e81ad27 100644 --- a/src/flyingship.h +++ b/src/flyingship.h @@ -11,15 +11,12 @@ extern "C" { #endif - void register_flyingship(void); - int sp_flying_ship(castorder * co); - struct curse *shipcurse_flyingship(struct ship *sh, struct unit *mage, - double power, int duration); + void register_flyingship(void); + bool flying_ship(const ship * sh); int levitate_ship(struct ship *sh, struct unit *mage, double power, int duration); - bool flying_ship(const ship * sh); #ifdef __cplusplus } From 8200fdb6c24d85310833b53cda500490675ba8f3 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 15:40:26 +0100 Subject: [PATCH 07/13] moved files for flyingship to subdir "spells" --- src/CMakeLists.txt | 3 +-- src/bind_monsters.c | 3 ++- src/move.c | 3 ++- src/spells.c | 2 +- src/spells/CMakeLists.txt | 1 + src/{ => spells}/flyingship.c | 0 src/{ => spells}/flyingship.h | 0 src/{ => spells}/flyingship.test.c | 0 8 files changed, 7 insertions(+), 5 deletions(-) rename src/{ => spells}/flyingship.c (100%) rename src/{ => spells}/flyingship.h (100%) rename src/{ => spells}/flyingship.test.c (100%) diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 1817f9cb1..037898ed9 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -117,7 +117,6 @@ set (ERESSEA_SRC travelthru.c monsters.c wormhole.c - flyingship.c ${SPELLS_SRC} ${RACES_SRC} ${ITEMS_SRC} @@ -209,7 +208,7 @@ set(TESTS_SRC spy.test.c study.test.c upkeep.test.c - flyingship.test.c + spells/flyingship.test.c spells/magicresistance.test.c ${ATTRIBUTES_TESTS} ${UTIL_TESTS} diff --git a/src/bind_monsters.c b/src/bind_monsters.c index 67ca8ef64..6589e002a 100644 --- a/src/bind_monsters.c +++ b/src/bind_monsters.c @@ -1,7 +1,6 @@ #include #include "spells/shipcurse.h" #include "monster.h" -#include "flyingship.h" #include #include @@ -10,6 +9,8 @@ #include #include +#include + #include #include diff --git a/src/move.c b/src/move.c index 87b1e44f7..8986f2bcf 100644 --- a/src/move.c +++ b/src/move.c @@ -28,7 +28,6 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include "monster.h" #include "lighthouse.h" #include "piracy.h" -#include "flyingship.h" #include #include @@ -49,6 +48,8 @@ OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include +#include + #include "direction.h" #include "calendar.h" #include "skill.h" diff --git a/src/spells.c b/src/spells.c index 82548ae71..32d02570b 100644 --- a/src/spells.c +++ b/src/spells.c @@ -22,7 +22,6 @@ #include "direction.h" #include "randenc.h" #include "monster.h" -#include "flyingship.h" #include #include @@ -31,6 +30,7 @@ #include #include #include +#include /* kernel includes */ #include diff --git a/src/spells/CMakeLists.txt b/src/spells/CMakeLists.txt index 335189c21..6219708d4 100644 --- a/src/spells/CMakeLists.txt +++ b/src/spells/CMakeLists.txt @@ -8,6 +8,7 @@ regioncurse.c shipcurse.c unitcurse.c magicresistance.c +flyingship.c ) FOREACH(_FILE ${_FILES}) LIST(APPEND _SOURCES ${PROJECT_NAME}/${_FILE}) diff --git a/src/flyingship.c b/src/spells/flyingship.c similarity index 100% rename from src/flyingship.c rename to src/spells/flyingship.c diff --git a/src/flyingship.h b/src/spells/flyingship.h similarity index 100% rename from src/flyingship.h rename to src/spells/flyingship.h diff --git a/src/flyingship.test.c b/src/spells/flyingship.test.c similarity index 100% rename from src/flyingship.test.c rename to src/spells/flyingship.test.c From f550431118c7b5c2940d6d7780c8e3c46f2f9c36 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 15:59:29 +0100 Subject: [PATCH 08/13] small documentation correction --- src/spells/flyingship.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/spells/flyingship.c b/src/spells/flyingship.c index af026c242..914ca4deb 100644 --- a/src/spells/flyingship.c +++ b/src/spells/flyingship.c @@ -23,8 +23,8 @@ * Stufe: 6 * * Wirkung: -* Laeßt ein Schiff eine Runde lang fliegen. Wirkt nur auf Boote und -* Langboote. +* Laeßt ein Schiff eine Runde lang fliegen. Wirkt nur auf Boote +* bis Kapazität 50. * Kombinierbar mit "Guenstige Winde", aber nicht mit "Sturmwind". * * Flag: From 0e8365c802ab199d5345c7efa9b732999716e61d Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 16:12:56 +0100 Subject: [PATCH 09/13] moved convenience function for convenience the formerly static function test_create_castorder is now available for general usage via tests.h/.c --- src/spells.test.c | 10 ---------- src/tests.c | 9 +++++++++ src/tests.h | 1 + 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/src/spells.test.c b/src/spells.test.c index 471a043de..44ac20782 100644 --- a/src/spells.test.c +++ b/src/spells.test.c @@ -19,16 +19,6 @@ #include #include - -static void test_create_castorder(castorder *co, unit *u, int level, float force, int range) { - struct locale * lang; - order *ord; - - lang = get_or_create_locale("en"); - create_castorder(co, u, NULL, NULL, u->region, level, force, range, ord = create_order(K_CAST, lang, ""), NULL); - free_order(ord); -} - static void test_good_dreams(CuTest *tc) { struct region *r; struct faction *f1, *f2; diff --git a/src/tests.c b/src/tests.c index 347418ce5..972631827 100644 --- a/src/tests.c +++ b/src/tests.c @@ -179,6 +179,15 @@ item_type * test_create_itemtype(const char * name) { return itype; } +void test_create_castorder(castorder *co, unit *u, int level, float force, int range) { + struct locale * lang; + order *ord; + + lang = get_or_create_locale("en"); + create_castorder(co, u, NULL, NULL, u->region, level, force, range, ord = create_order(K_CAST, lang, ""), NULL); + free_order(ord); +} + void test_translate_param(const struct locale *lang, param_t param, const char *text) { struct critbit_tree **cb; diff --git a/src/tests.h b/src/tests.h index a458e4eab..e9de2aede 100644 --- a/src/tests.h +++ b/src/tests.h @@ -37,6 +37,7 @@ extern "C" { struct item_type * test_create_itemtype(const char * name); struct ship_type *test_create_shiptype(const char * name); struct building_type *test_create_buildingtype(const char *name); + void test_create_castorder(struct castorder *co, struct unit *u, int level, float force, int range); int RunAllTests(void); void test_translate_param(const struct locale *lang, param_t param, const char *text); From 29173887b6d233bfe61fb3017b90a096c7f5f9c2 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 17:09:16 +0100 Subject: [PATCH 10/13] test_create_castorder can take spelllparameters now too --- src/spells.test.c | 6 +++--- src/tests.c | 4 ++-- src/tests.h | 4 +++- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/src/spells.test.c b/src/spells.test.c index 44ac20782..58886d991 100644 --- a/src/spells.test.c +++ b/src/spells.test.c @@ -34,7 +34,7 @@ static void test_good_dreams(CuTest *tc) { u1 = test_create_unit(f1, r); u2 = test_create_unit(f2, r); - test_create_castorder(&co, u1, 10, 10., 0); + test_create_castorder(&co, u1, 10, 10., 0, NULL); level = sp_gooddreams(&co); CuAssertIntEquals(tc, 10, level); @@ -63,7 +63,7 @@ static void test_dreams(CuTest *tc) { u1 = test_create_unit(f1, r); u2 = test_create_unit(f2, r); - test_create_castorder(&co, u1, 10, 10., 0); + test_create_castorder(&co, u1, 10, 10., 0, NULL); sp_gooddreams(&co); sp_baddreams(&co); @@ -90,7 +90,7 @@ static void test_bad_dreams(CuTest *tc) { u1 = test_create_unit(f1, r); u2 = test_create_unit(f2, r); - test_create_castorder(&co, u1, 10, 10., 0); + test_create_castorder(&co, u1, 10, 10., 0, NULL); level = sp_baddreams(&co); CuAssertIntEquals(tc, 10, level); diff --git a/src/tests.c b/src/tests.c index 972631827..4e0206189 100644 --- a/src/tests.c +++ b/src/tests.c @@ -179,12 +179,12 @@ item_type * test_create_itemtype(const char * name) { return itype; } -void test_create_castorder(castorder *co, unit *u, int level, float force, int range) { +void test_create_castorder(castorder *co, unit *u, int level, float force, int range, spellparameter *par) { struct locale * lang; order *ord; lang = get_or_create_locale("en"); - create_castorder(co, u, NULL, NULL, u->region, level, force, range, ord = create_order(K_CAST, lang, ""), NULL); + create_castorder(co, u, NULL, NULL, u->region, level, force, range, ord = create_order(K_CAST, lang, ""), par); free_order(ord); } diff --git a/src/tests.h b/src/tests.h index e9de2aede..ba33dd5a7 100644 --- a/src/tests.h +++ b/src/tests.h @@ -20,6 +20,8 @@ extern "C" { struct building_type; struct ship_type; struct terrain_type; + struct castorder; + struct spellparameter; struct CuTest; @@ -37,7 +39,7 @@ extern "C" { struct item_type * test_create_itemtype(const char * name); struct ship_type *test_create_shiptype(const char * name); struct building_type *test_create_buildingtype(const char *name); - void test_create_castorder(struct castorder *co, struct unit *u, int level, float force, int range); + void test_create_castorder(struct castorder *co, struct unit *u, int level, float force, int range, struct spellparameter *par); int RunAllTests(void); void test_translate_param(const struct locale *lang, param_t param, const char *text); From 96ccb046ab318a2d20932e6465ed435301118cf0 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 17:54:23 +0100 Subject: [PATCH 11/13] added test-suite for flyingship.c some general testing of the spells functionality for future maintenance purposes --- src/spells/flyingship.test.c | 60 ++++++++++++++++++++++++++++++++++++ src/test_eressea.c | 1 + 2 files changed, 61 insertions(+) diff --git a/src/spells/flyingship.test.c b/src/spells/flyingship.test.c index 00c618cd9..9657aea46 100644 --- a/src/spells/flyingship.test.c +++ b/src/spells/flyingship.test.c @@ -1,6 +1,66 @@ #include #include "flyingship.h" +#include +#include +#include +#include +#include + #include #include #include + +static void test_flyingship(CuTest * tc) +{ + castorder co; + spellparameter par; + spllprm par_data; + spllprm *par_data_ptr = &par_data; + par.param = &par_data_ptr; + par_data.typ = SPP_SHIP; + + region *r; + faction *f; + unit *u; + ship_type *shipType1, *shipType2; + ship *sh1, *sh2; + + test_cleanup(); + test_create_world(); + + r = findregion(0, 0); + f = test_create_faction(test_create_race("human")); + u = test_create_unit(f, r); + + shipType1 = test_create_shiptype("boot"); + shipType1->construction->maxsize = 50; + + shipType2 = test_create_shiptype("schiff"); + shipType2->construction->maxsize = 51; + + sh1 = test_create_ship(r, shipType1); + par_data.data.sh = sh1; + test_create_castorder(&co, u, 10, 10.0, 0, &par); + + CuAssertTrue(tc, !flying_ship(sh1)); + CuAssertIntEquals(tc, 10, sp_flying_ship(&co)); + CuAssertTrue(tc, flying_ship(sh1)); + + sh2 = test_create_ship(r, shipType2); + par_data.data.sh = sh2; + test_create_castorder(&co, u, 10, 10.0, 0, &par); + + CuAssertTrue(tc, !flying_ship(sh2)); + CuAssertIntEquals(tc, 0, sp_flying_ship(&co)); + CuAssertTrue(tc, !flying_ship(sh2)); +} + +CuSuite *get_flyingship_suite(void) +{ + CuSuite *suite = CuSuiteNew(); + + SUITE_ADD_TEST(suite, test_flyingship); + + return suite; +} diff --git a/src/test_eressea.c b/src/test_eressea.c index aad65c539..2a0bf04eb 100644 --- a/src/test_eressea.c +++ b/src/test_eressea.c @@ -114,6 +114,7 @@ int RunAllTests(int argc, char *argv[]) ADD_SUITE(donations); ADD_SUITE(travelthru); ADD_SUITE(economy); + ADD_SUITE(flyingship); ADD_SUITE(give); ADD_SUITE(laws); ADD_SUITE(market); From 30dce186977c0bc54f55e1df3ae42a351f4b470e Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 17:58:14 +0100 Subject: [PATCH 12/13] small formal corrections --- src/spells/flyingship.c | 3 +++ src/spells/flyingship.h | 8 ++------ src/spells/flyingship.test.c | 7 +++++-- 3 files changed, 10 insertions(+), 8 deletions(-) diff --git a/src/spells/flyingship.c b/src/spells/flyingship.c index 914ca4deb..7751451ed 100644 --- a/src/spells/flyingship.c +++ b/src/spells/flyingship.c @@ -9,6 +9,9 @@ #include #include #include +#include + +#include #include diff --git a/src/spells/flyingship.h b/src/spells/flyingship.h index 92e81ad27..35c847e03 100644 --- a/src/spells/flyingship.h +++ b/src/spells/flyingship.h @@ -3,18 +3,14 @@ #ifndef FLYINGSHIP_H #define FLYINGSHIP_H -#include "magic.h" - -#include - #ifdef __cplusplus extern "C" { #endif - int sp_flying_ship(castorder * co); + int sp_flying_ship(struct castorder * co); void register_flyingship(void); - bool flying_ship(const ship * sh); + bool flying_ship(const struct ship * sh); int levitate_ship(struct ship *sh, struct unit *mage, double power, int duration); diff --git a/src/spells/flyingship.test.c b/src/spells/flyingship.test.c index 9657aea46..00199e971 100644 --- a/src/spells/flyingship.test.c +++ b/src/spells/flyingship.test.c @@ -7,6 +7,8 @@ #include #include +#include + #include #include #include @@ -17,8 +19,6 @@ static void test_flyingship(CuTest * tc) spellparameter par; spllprm par_data; spllprm *par_data_ptr = &par_data; - par.param = &par_data_ptr; - par_data.typ = SPP_SHIP; region *r; faction *f; @@ -26,6 +26,9 @@ static void test_flyingship(CuTest * tc) ship_type *shipType1, *shipType2; ship *sh1, *sh2; + par.param = &par_data_ptr; + par_data.typ = SPP_SHIP; + test_cleanup(); test_create_world(); From c2a8c32be0d0fafd84371fe35cfb8759179173b4 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 18:08:35 +0100 Subject: [PATCH 13/13] forgot fwd-declaration of structs... --- src/spells/flyingship.h | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/spells/flyingship.h b/src/spells/flyingship.h index 35c847e03..087357b9e 100644 --- a/src/spells/flyingship.h +++ b/src/spells/flyingship.h @@ -7,6 +7,10 @@ extern "C" { #endif + struct castorder; + struct ship; + struct unit; + int sp_flying_ship(struct castorder * co); void register_flyingship(void);