From fe0d038bf3b4aeeee64774de0ab0c5e3f1896e93 Mon Sep 17 00:00:00 2001 From: Philipp Dreher Date: Mon, 2 Nov 2015 13:39:06 +0100 Subject: [PATCH] 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 }