From b1ab3a0a91ccda260f8a12e9b501137f6c0e8bb8 Mon Sep 17 00:00:00 2001 From: Katja Zedel Date: Sun, 29 Sep 2002 18:11:08 +0000 Subject: [PATCH] =?UTF-8?q?neues=20attribut=20at=5Fmovement=20=C3=A4ndert?= =?UTF-8?q?=20movement=20verhalten=20einer=20einzelnen=20einheit=20setzen?= =?UTF-8?q?=20mit=20set=5Fmovement=20auswerten=20mit=20boolean=20get=5Fmov?= =?UTF-8?q?ement=20(&atlist,=20type)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/attributes/at_movement.c | 59 +++++++++++++++++++++++++++++ src/common/attributes/at_movement.h | 20 ++++++++++ src/common/kernel/movement.c | 23 +++++++++-- src/common/kernel/movement.h | 8 ++++ 4 files changed, 107 insertions(+), 3 deletions(-) create mode 100644 src/common/attributes/at_movement.c create mode 100644 src/common/attributes/at_movement.h diff --git a/src/common/attributes/at_movement.c b/src/common/attributes/at_movement.c new file mode 100644 index 000000000..e193ef76b --- /dev/null +++ b/src/common/attributes/at_movement.c @@ -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 +#include +#include +#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); +} diff --git a/src/common/attributes/at_movement.h b/src/common/attributes/at_movement.h new file mode 100644 index 000000000..4188f3074 --- /dev/null +++ b/src/common/attributes/at_movement.h @@ -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; + diff --git a/src/common/kernel/movement.c b/src/common/kernel/movement.c index f9569c8f2..8c67cc6eb 100644 --- a/src/common/kernel/movement.c +++ b/src/common/kernel/movement.c @@ -56,6 +56,7 @@ /* attributes includes */ #include #include +#include /* 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); diff --git a/src/common/kernel/movement.h b/src/common/kernel/movement.h index ee142f4d6..ea388f1b3 100644 --- a/src/common/kernel/movement.h +++ b/src/common/kernel/movement.h @@ -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