neues attribut at_movement

ändert movement verhalten einer einzelnen einheit
setzen mit set_movement
auswerten mit boolean get_movement (&atlist, type)
This commit is contained in:
Katja Zedel 2002-09-29 18:11:08 +00:00
parent c74ab30536
commit b1ab3a0a91
4 changed files with 107 additions and 3 deletions

View File

@ -0,0 +1,59 @@
/* vi: set ts=2:
*
*
* Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de)
* Henning Peters (faroul@beyond.kn-bremen.de)
* Enno Rehling (enno@eressea-pbem.de)
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
*
* This program may not be used, modified or distributed without
* prior permission by the authors of Eressea.
*/
#include <config.h>
#include <eressea.h>
#include <attrib.h>
#include "at_movement.h"
static void
write_movement(const attrib * a, FILE * F)
{
fprintf(F, "%d", a->data.i);
}
static int
read_movement(attrib * a, FILE * F)
{
fscanf(F, "%d", &a->data.i);
if (a->data.i !=0 ) return AT_READ_OK;
else return AT_READ_FAIL;
}
attrib_type at_movement = {
"movement", NULL, NULL, NULL, write_movement, read_movement
};
boolean
get_movement(attrib ** alist, int type)
{
attrib * a = a_find(*alist, &at_movement);
if (a==NULL) return false;
if (a->data.i & type) return true;
return false;
}
void
set_movement(attrib ** alist, int type)
{
attrib * a = a_find(*alist, &at_movement);
if (a==NULL) a = a_add(alist, a_new(&at_movement));
a->data.i |= type;
}
void
init_movement(void)
{
at_register(&at_movement);
}

View File

@ -0,0 +1,20 @@
/* vi: set ts=2:
*
*
* Eressea PB(E)M host Copyright (C) 1998-2000
* Christian Schlittchen (corwin@amber.kn-bremen.de)
* Katja Zedel (katze@felidae.kn-bremen.de)
* Henning Peters (faroul@beyond.kn-bremen.de)
* Enno Rehling (enno@eressea-pbem.de)
* Ingo Wilken (Ingo.Wilken@informatik.uni-oldenburg.de)
*
* This program may not be used, modified or distributed without
* prior permission by the authors of Eressea.
*/
extern boolean get_movement(attrib ** alist, int type);
extern void set_movement(struct attrib ** alist, int type);
extern void init_movement(void);
extern struct attrib_type at_movement;

View File

@ -56,6 +56,7 @@
/* attributes includes */
#include <attributes/follow.h>
#include <attributes/targetregion.h>
#include <attributes/at_movement.h>
/* TODO: boder_type::move() must be able to change target (wisps) */
extern border_type bt_wisps;
@ -286,6 +287,8 @@ canwalk(unit * u)
boolean
canfly(unit *u)
{
if (get_movement(&u->attribs, MV_CANNOTMOVE)) return false;
if(get_item(u, I_HORSE)) return false;
if(get_item(u, I_PEGASUS) >= u->number && effskill(u, SK_RIDING) >= 4)
@ -293,12 +296,16 @@ canfly(unit *u)
if (fval(u->race, RCF_FLY)) return true;
if (get_movement(&u->attribs, MV_FLY)) return true;
return false;
}
boolean
canswim(unit *u)
{
if (get_movement(&u->attribs, MV_CANNOTMOVE)) return false;
if (get_item(u, I_HORSE)) return false;
if (get_item(u, I_DOLPHIN) >= u->number && effskill(u, SK_RIDING) >= 4)
@ -310,6 +317,10 @@ canswim(unit *u)
if (u->race->flags & RCF_SWIM) return true;
if (get_movement(&u->attribs, MV_FLY)) return true;
if (get_movement(&u->attribs, MV_SWIM)) return true;
return false;
}
@ -2087,7 +2098,9 @@ movement(void)
cmistake(u, findorder(u, u->thisorder), 52, MSG_MOVE);
set_string(&u->thisorder, "");
up = &u->next;
} else if (u->race->flags & RCF_CANNOTMOVE) {
} else if ((u->race->flags & RCF_CANNOTMOVE)
|| get_movement(&u->attribs, MV_CANNOTMOVE))
{
cmistake(u, findorder(u, u->thisorder), 55, MSG_MOVE);
set_string(&u->thisorder, "");
up = &u->next;
@ -2129,7 +2142,9 @@ movement(void)
if(attacked(u)) {
cmistake(u, o->s, 52, MSG_MOVE);
break;
} else if(u->race->flags & RCF_CANNOTMOVE) {
} else if((u->race->flags & RCF_CANNOTMOVE)
|| get_movement(&u->attribs, MV_CANNOTMOVE))
{
cmistake(u, o->s, 55, MSG_MOVE);
break;
}
@ -2163,7 +2178,9 @@ movement(void)
|| igetkeyword(u->thisorder, u->faction->locale) == K_ROUTE)) {
if (attacked(u)) {
cmistake(u, findorder(u, u->thisorder), 52, MSG_PRODUCE);
} else if (u->race->flags & RCF_CANNOTMOVE) {
} else if ((u->race->flags & RCF_CANNOTMOVE)
|| get_movement(&u->attribs, MV_CANNOTMOVE))
{
cmistake(u, findorder(u, u->thisorder), 55, MSG_PRODUCE);
} else
move(r, u, true);

View File

@ -17,6 +17,14 @@
struct unit;
struct ship;
/* ------------------------------------------------------------- */
/* die Zahlen sind genau äquivalent zu den race Flags */
#define MV_CANNOTMOVE (1<<5)
#define MV_FLY (1<<7) /* kann fliegen */
#define MV_SWIM (1<<8) /* kann schwimmen */
#define MV_WALK (1<<9) /* kann über Land gehen */
/* ------------------------------------------------------------- */
/* Die tragekapaz. ist hardcodiert mit defines, da es bis jetzt sowieso nur 2