internal restructuring in flyingship

This commit is contained in:
Philipp Dreher 2015-11-02 14:01:38 +01:00
parent abd6be475f
commit 098abcc144
2 changed files with 47 additions and 49 deletions

View file

@ -17,45 +17,6 @@
/* libc includes */ /* libc includes */
#include <assert.h> #include <assert.h>
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 /* Name: Luftschiff
@ -124,15 +85,46 @@ int sp_flying_ship(castorder * co)
return cast_level; 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); ship *sh = (ship *)target;
if (c) { c->data.v = sh;
return c->no; 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; 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) bool flying_ship(const ship * sh)
{ {
if (sh->type->flags & SFL_FLY) if (sh->type->flags & SFL_FLY)
@ -142,7 +134,7 @@ bool flying_ship(const ship * sh)
return false; 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; static const curse_type *ct_flyingship = NULL;
if (!ct_flyingship) { 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;
}

View file

@ -11,15 +11,12 @@
extern "C" { extern "C" {
#endif #endif
void register_flyingship(void);
int sp_flying_ship(castorder * co); int sp_flying_ship(castorder * co);
struct curse *shipcurse_flyingship(struct ship *sh, struct unit *mage, void register_flyingship(void);
double power, int duration); bool flying_ship(const ship * sh);
int levitate_ship(struct ship *sh, struct unit *mage, double power, int levitate_ship(struct ship *sh, struct unit *mage, double power,
int duration); int duration);
bool flying_ship(const ship * sh);
#ifdef __cplusplus #ifdef __cplusplus
} }