From b94f10c44bdea0e6e09e6b39abeed46037a4b233 Mon Sep 17 00:00:00 2001 From: Christian Schlittchen Date: Sat, 28 Apr 2001 12:03:12 +0000 Subject: [PATCH] =?UTF-8?q?-=20Erste=20Version=20der=20Verb=C3=A4nde.=20Un?= =?UTF-8?q?getestet=20und=20noch=20ohne=20Reportanzeige.=20=20=20Committed?= =?UTF-8?q?,=20um=20ekelige=20Konflikte=20in=20messages.xml=20zu=20vermeid?= =?UTF-8?q?en.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/common/attributes/ugroup.c | 26 +++++ src/common/attributes/ugroup.h | 20 ++++ src/common/kernel/ugroup.c | 182 +++++++++++++++++++++++++++++++++ src/common/kernel/ugroup.h | 29 ++++++ 4 files changed, 257 insertions(+) create mode 100644 src/common/attributes/ugroup.c create mode 100644 src/common/attributes/ugroup.h create mode 100644 src/common/kernel/ugroup.c create mode 100644 src/common/kernel/ugroup.h diff --git a/src/common/attributes/ugroup.c b/src/common/attributes/ugroup.c new file mode 100644 index 000000000..d471b03e7 --- /dev/null +++ b/src/common/attributes/ugroup.c @@ -0,0 +1,26 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. + $Id: ugroup.c,v 1.1 2001/04/28 12:03:12 corwin Exp $ + */ + +#include +#include "ugroup.h" +#include + +attrib_type at_ugroup = { + "ugroup", NULL, NULL, NULL, NULL, NULL, ATF_UNIQUE +}; + +void +init_ugroup(void) +{ + at_register(&at_ugroup); +} diff --git a/src/common/attributes/ugroup.h b/src/common/attributes/ugroup.h new file mode 100644 index 000000000..466e79021 --- /dev/null +++ b/src/common/attributes/ugroup.h @@ -0,0 +1,20 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. + $Id: ugroup.h,v 1.1 2001/04/28 12:03:12 corwin Exp $ + */ + +#ifndef AUGROUP_H +#define AUGROUP_H + +extern struct attrib_type at_ugroup; +void init_ugroup(void); +#endif + diff --git a/src/common/kernel/ugroup.c b/src/common/kernel/ugroup.c new file mode 100644 index 000000000..2589021f0 --- /dev/null +++ b/src/common/kernel/ugroup.c @@ -0,0 +1,182 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. + $Id: ugroup.c,v 1.1 2001/04/28 12:03:12 corwin Exp $ + */ + +#include +#include "eressea.h" +#include "unit.h" +#include "region.h" +#include "faction.h" +#include +#include + +#include + +/* Nur die erste Einheit in der Liste + (ugroup->unit_array[0] == u) kann NACH ausführen. */ + +ugroup * +findugroupid(faction *f, int id) +{ + ugroup *ug; + + for(ug=f->ugroups;ug; ug=ug->next) { + if(ug->id == id) return ug; + } + return NULL; +} + +ugroup * +findugroup(unit *u) +{ + attrib *a = a_find(u->attribs, &at_ugroup); + if(!a) return NULL; + return findugroupid(u->faction, a->data.i); +} + +static int +ugroupfreeid(ugroup *ug) +{ + ugroup *ug2; + int id = 0; + + ug2 = ug; + + while(ug2) { + if(ug2->id == id) { + id++; + ug2 = ug; + } else { + ug2 = ug2->next; + } + } + return id; +} + +ugroup * +createugroup(unit *uleader, unit *umember) +{ + ugroup *ug = calloc(1,sizeof(ugroup)); + + ug->id = ugroupfreeid(uleader->faction->ugroups); + ug->members = 2; + ug->unit_array = malloc(2 * sizeof(unit *)); + ug->unit_array[0] = uleader; + a_add(&uleader->attribs, a_new(&at_ugroup))->data.i = ug->id; + ug->unit_array[1] = umember; + a_add(&umember->attribs, a_new(&at_ugroup))->data.i = ug->id; + ug->next = uleader->faction->ugroups; + uleader->faction->ugroups = ug; + + return ug; +} + +void +join_ugroup(unit *u, strlist *order) +{ + unit *u2; + ugroup *ug; + + u2 = getunit(u->region, u->faction); + if(!u2 || cansee(u->faction, u->region, u2, 0) == false) { + cmistake(u, order->s, 63, MSG_EVENT); + return; + } + if(u2 == u) { + cmistake(u, order->s, 292, MSG_EVENT); + return; + } + if(u2->faction != u->faction) { + cmistake(u, order->s, 293, MSG_EVENT); + return; + } + if(u2->building != u->building || u2->ship != u->ship) { + cmistake(u, order->s, 294, MSG_EVENT); + return; + } + if(a_find(u->attribs, &at_ugroup)) { + cmistake(u, order->s, 290, MSG_EVENT); + return; + } + + ug = findugroup(u2); + + if(ug) { + ug->members++; + ug->unit_array = realloc(ug->unit_array, + ug->members * sizeof(unit *)); + ug->unit_array[ug->members-1] = u; + a_add(&u->attribs, a_new(&at_ugroup))->data.i = ug->id; + } else { + createugroup(u2, u); + } +} + +void +leave_ugroup(unit *u, strlist *order) +{ + attrib *a = a_find(u->attribs, &at_ugroup); + ugroup *ug; + boolean found = false; + int i; + + if(!a) { + cmistake(u, order->s, 286, MSG_EVENT); + return; + } + + ug = findugroupid(u->faction, a->data.i); + for(i=0; imembers; i++) { + if(found == true) { + ug->unit_array[i-1] = ug->unit_array[i]; + } else if(ug->unit_array[i] == u) { + found = true; + } + } + ug->members--; + a_remove(&u->attribs, a); + + if(ug->members == 1) { + a_remove(&ug->unit_array[0]->attribs, a); + free(ug->unit_array); + removelist(&u->faction->ugroups, ug); + } else { + ug->unit_array = realloc(ug->unit_array, + ug->members * sizeof(unit *)); + } +} + +void +ugroups(void) +{ + region *r; + unit *u; + strlist *o; + + for(r=regions; r; r=r->next) { + for(u=r->units; u; u=u->next) { + for(o = u->orders; o; o=o->next) { + if(igetkeyword(o->s, u->faction->locale) == K_LEAVEUGROUP) { + leave_ugroup(u, o); + } + } + } + for(u=r->units; u; u=u->next) { + for(o = u->orders; o; o=o->next) { + if(igetkeyword(o->s, u->faction->locale) == K_JOINUGROUP) { + join_ugroup(u, o); + } + } + } + } +} + diff --git a/src/common/kernel/ugroup.h b/src/common/kernel/ugroup.h new file mode 100644 index 000000000..20593d190 --- /dev/null +++ b/src/common/kernel/ugroup.h @@ -0,0 +1,29 @@ +/* vi: set ts=2: + +-------------------+ Christian Schlittchen + | | Enno Rehling + | Eressea PBEM host | Katja Zedel + | (c) 1998 - 2001 | Henning Peters + | | Ingo Wilken + +-------------------+ Stefan Reich + + This program may not be used, modified or distributed + without prior permission by the authors of Eressea. + $Id: ugroup.h,v 1.1 2001/04/28 12:03:12 corwin Exp $ + */ + +#ifndef UGROUP_H +#define UGROUP_H + +/* Globale Liste ugroups. + Bei jeder unit u->ugroup zeigt auf aktuelle Gruppe. + Gruppen mit members <= 1 werden vor den Reports + aufgelöst. */ + +typedef struct ugroup { + struct ugroup *next; + int id; + int members; + unit **unit_array; +} ugroup; + +#endif