alliance code. #define ALLIANCES to use.

requires that alliancejoin and alliancekick are called at some point in the code.
This commit is contained in:
Enno Rehling 2002-08-26 14:16:16 +00:00
parent f0040493d1
commit 86c0a65184
11 changed files with 493 additions and 26 deletions

View File

@ -323,17 +323,17 @@ expandrecruit(region * r, request * recruitorders)
}
i = fspecial(unew->faction, FS_MILITIA);
if (i > 0) {
if (unew->race->bonus[SK_SPEAR] >= 0)
if (unew->race->bonus[SK_SPEAR] >= 0)
change_level(unew, SK_SPEAR, i);
if (unew->race->bonus[SK_SWORD] >= 0)
if (unew->race->bonus[SK_SWORD] >= 0)
change_level(unew, SK_SWORD, i);
if (unew->race->bonus[SK_LONGBOW] >= 0)
if (unew->race->bonus[SK_LONGBOW] >= 0)
change_level(unew, SK_LONGBOW, i);
if (unew->race->bonus[SK_CROSSBOW] >= 0)
if (unew->race->bonus[SK_CROSSBOW] >= 0)
change_level(unew, SK_CROSSBOW, i);
if (unew->race->bonus[SK_RIDING] >= 0)
if (unew->race->bonus[SK_RIDING] >= 0)
change_level(unew, SK_RIDING, i);
if (unew->race->bonus[SK_AUSDAUER] >= 0)
if (unew->race->bonus[SK_AUSDAUER] >= 0)
change_level(unew, SK_AUSDAUER, i);
}
if (unew!=u) {
@ -341,7 +341,7 @@ expandrecruit(region * r, request * recruitorders)
destroy_unit(unew);
}
if (u->n < u->wants) {
ADDMSG(&u->faction->msgs, msg_message("recruit",
ADDMSG(&u->faction->msgs, msg_message("recruit",
"unit region amount want", u, r, u->n, u->wants));
}
}
@ -526,7 +526,7 @@ give_item(int want, const item_type * itype, unit * src, unit * dest, const char
n = min(want, n);
#define GIVERESTRICTION 3
if (dest && src->faction != dest->faction && src->faction->age < GIVERESTRICTION) {
ADDMSG(&src->faction->msgs, msg_error(src, cmd, "giverestriction",
ADDMSG(&src->faction->msgs, msg_error(src, cmd, "giverestriction",
"turns", GIVERESTRICTION));
return -1;
} else if (n == 0) {
@ -573,7 +573,7 @@ givemen(int n, unit * u, unit * u2, const char * cmd)
int error = 0;
if (u2 && u->faction != u2->faction && u->faction->age < GIVERESTRICTION) {
ADDMSG(&u->faction->msgs, msg_error(u, cmd, "giverestriction",
ADDMSG(&u->faction->msgs, msg_error(u, cmd, "giverestriction",
"turns", GIVERESTRICTION));
return;
} else if (u == u2) {
@ -971,7 +971,7 @@ dogive(region * r, unit * u, strlist * S, boolean liefere, int mode)
if (u->items) {
item **itmp=&u->items;
while (*itmp) {
if ((*itmp)->number > 0
if ((*itmp)->number > 0
&& (*itmp)->number - new_get_resvalue(u, (*itmp)->type->rtype) > 0) {
n = (*itmp)->number - new_get_resvalue(u, (*itmp)->type->rtype);
if (give_item(n, (*itmp)->type, u, u2, S->s)==0) continue;
@ -1284,7 +1284,7 @@ maintain_buildings(boolean crash)
}
}
void
void
economics(void)
{
region *r;
@ -1353,7 +1353,7 @@ economics(void)
/* ------------------------------------------------------------- */
static void
static void
manufacture(unit * u, const item_type * itype, int want)
{
int n;
@ -2582,7 +2582,7 @@ planttrees(region *r, unit *u, int raw)
}
if (fval(r, RF_MALLORN) && skill < 7 ) {
add_message(&u->faction->msgs,
msg_error(u, findorder(u, u->thisorder), "plant_skills",
msg_error(u, findorder(u, u->thisorder), "plant_skills",
"skill minskill product", SK_HERBALISM, 7, itype->rtype, 1));
return;
}
@ -2610,7 +2610,7 @@ planttrees(region *r, unit *u, int raw)
produceexp(u, SK_HERBALISM, u->number);
new_use_pooled(u, itype->rtype, GET_DEFAULT, n);
ADDMSG(&u->faction->msgs, msg_message("plant",
ADDMSG(&u->faction->msgs, msg_message("plant",
"unit region amount herb", u, r, planted, itype->rtype));
}
@ -3279,7 +3279,7 @@ produce(void)
if (fval(u, FL_TRADER)) {
attrib * a = a_find(u->attribs, &at_trades);
if (a && a->data.i) {
produceexp(u, SK_TRADE, u->number);
produceexp(u, SK_TRADE, u->number);
}
u->thisorder[0]=0;
continue;

View File

@ -0,0 +1,160 @@
/* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea-pbem.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2001 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.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 "alliance.h"
#include "command.h"
/* kernel includes */
#include <faction.h>
#include <message.h>
#include <region.h>
#include <unit.h>
/* util includes */
#include <umlaut.h>
/* libc includes */
#include <stdlib.h>
#include <string.h>
alliance * alliances = NULL;
alliance *
makealliance(int id, const char * name)
{
alliance * al = calloc(1, sizeof(alliance));
al->id=id;
al->name=strdup(name);
al->next=alliances;
return alliances=al;
}
alliance *
findalliance(int id)
{
alliance * al;
for (al=alliances;al;al=al->next) {
if (al->id==id) return al;
}
return NULL;
}
void destroy_kick(struct attrib * a)
{
faction_list * flist = (faction_list*)a->data.v;
freelist(flist);
}
const attrib_type at_kick = { "kick",
DEFAULT_INIT, destroy_kick
};
static attrib *
make_kick(void)
{
return a_new(&at_kick);
}
void
add_kick(attrib * a, const faction * f)
{
faction_list * flist = (faction_list*)a->data.v;
while (flist && flist->data!=f) flist = flist->next;
if (flist) return;
flist = calloc(1, sizeof(faction_list));
flist->data = (void*)f;
flist->next = (faction_list*)a->data.v;
a->data.v = flist;
}
static void
alliance_kick(const char * str, void * data, const char * cmd)
{
unit * u = (unit*)data;
faction * f = findfaction(atoi36(igetstrtoken(str)));
attrib * a;
if (f==NULL || f->alliance!=u->faction->alliance) {
/* does not belong to our alliance */
return;
}
a = a_find(f->attribs, &at_kick);
if (a==NULL) a = a_add(&f->attribs, make_kick());
add_kick(a, f);
}
static void
alliance_join(const char * str, void * data, const char * cmd)
{
unit * u = (unit*)data;
alliance * al = findalliance(atoi36(igetstrtoken(str)));
if (u->faction->alliance!=NULL || al==NULL) {
/* not found */
return;
}
u->faction->alliance = al;
/* inform the rest? */
}
static tnode * g_keys;
static void
alliance_command(const char * str, void * data, const char * cmd)
{
do_command(g_keys, data, str);
}
static void
execute(tnode * root)
{
region ** rp = &regions;
while (*rp) {
region * r = *rp;
unit **up = &r->units;
while (*up) {
unit * u = *up;
strlist * order;
for (order = u->orders; order; order = order->next) {
if (igetkeyword(order->s, u->faction->locale) == K_ALLIANCE) {
do_command(root, u, order->s);
}
}
if (u==*up) up = &u->next;
}
if (*rp==r) rp = &r->next;
}
}
void
alliancejoin(void)
{
tnode root;
add_command(&root, "alliance", &alliance_command);
g_keys = calloc(1, sizeof(tnode));
add_command(g_keys, "join", &alliance_join);
execute(&root);
free(g_keys);
}
void
alliancekick(void)
{
tnode root;
add_command(&root, "alliance", &alliance_command);
g_keys = calloc(1, sizeof(tnode));
add_command(g_keys, "kick", &alliance_kick);
execute(&root);
free(g_keys);
}

View File

@ -0,0 +1,34 @@
/* 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.
*/
struct plane;
struct attrib;
struct unit;
struct faction;
struct region;
typedef struct alliance {
struct alliance * next;
int id;
char * name;
} alliance;
extern alliance * alliances;
extern alliance * findalliance(int id);
extern alliance * makealliance(int id, const char * name);
extern void alliancejoin(void);
extern void alliancekick(void);
/* execute commands */

View File

@ -336,16 +336,13 @@ set_enemy(side * as, side * ds, boolean attacking)
if (attacking) as->enemy[ds->index] |= E_ATTACKING;
}
extern int alliance(const ally * sf, const faction * f, int mode);
#ifdef ALLIANCES
static int
allysf(side * s, faction * f)
allysfm(side * s, faction * f, int mode)
{
if (s->bf->faction==f) return true;
if (s->group) return alliance(s->group->allies, f, HELP_FIGHT);
return alliance(s->bf->faction->allies, f, HELP_FIGHT);
return isallied(s->battle->plane, s->faction, f, mode);
}
#else
static int
allysfm(side * s, faction * f, int mode)
{
@ -353,6 +350,14 @@ allysfm(side * s, faction * f, int mode)
if (s->group) return alliance(s->group->allies, f, mode);
return alliance(s->bf->faction->allies, f, mode);
}
#endif
static int
allysf(side * s, faction * f)
{
return allysfm(s, f, HELP_FIGHT);
}
troop
select_corpse(battle * b, fighter * af)

View File

@ -725,6 +725,24 @@ unit_has_cursed_item(unit *u)
return false;
}
#ifdef ALLIANCES
int
allied(const unit * u, const faction * f2, int mode)
{
if (u->faction->alliance==f2->alliance) return mode;
return 0;
}
int
isallied(const plane * pl, const faction * f, const faction * f2, int mode)
{
unused(pl);
if (f->alliance==f2->alliance) return mode;
return 0;
}
#else
/* f hat zu f2 HELFE mode gesetzt */
int
isallied(const plane * pl, const faction * f, const faction * f2, int mode)
@ -751,7 +769,7 @@ isallied(const plane * pl, const faction * f, const faction * f2, int mode)
return 0;
}
int
static int
alliance(const ally * sf, const faction * f, int mode)
{
while (sf) {
@ -792,6 +810,7 @@ allied(const unit * u, const faction * f2, int mode)
if (a) sf = ((group*)a->data.v)->allies;
return alliance(sf, f2, mode);
}
#endif
boolean
seefaction(const faction * f, const region * r, const unit * u, int modifier)

View File

@ -154,9 +154,10 @@ struct xml_stack;
#define WATCHERS_VERSION 310
#define OVERRIDE_VERSION 311
#define CURSETYPE_VERSION 312
#define ALLIANCES_VERSION 313
#define UGROUPS_VERSION 400 /* nicht aktivieren, nicht fertig */
#define RELEASE_VERSION CURSETYPE_VERSION
#define RELEASE_VERSION ALLIANCES_VERSION
/*
#if RELEASE_VERSION >= UGROUPS_VERSION
@ -440,6 +441,7 @@ enum {
K_PFLANZE,
K_WEREWOLF,
K_XE,
K_ALLIANCE,
MAXKEYWORDS,
NOKEYWORD = (keyword_t) - 1
};

View File

@ -14,6 +14,7 @@
#define FACTION_H
struct player;
struct alliance;
typedef struct faction {
struct faction *next;
@ -55,6 +56,9 @@ typedef struct faction {
int number; /* enno: unterschied zu num_people ? */
int money;
int score;
#ifdef ALLIANCES
struct alliance * alliance;
#endif
#ifdef VICTORY_DELAY
unsigned char victory_delay;
#endif

View File

@ -50,6 +50,11 @@
#include <attributes/ugroup.h>
#endif
/* modules include */
#ifdef ALLIANCES
# include <modules/alliance.h>
#endif
/* attributes includes */
#include <attributes/key.h>
@ -717,6 +722,20 @@ read_ugroups(FILE *file)
}
#endif
#ifdef ALLIANCES
void
read_alliances(FILE * F)
{
char pbuf[32];
rns(F, pbuf, sizeof(pbuf));
while (strcmp(pbuf, "end")!=0) {
rs(F, buf);
makealliance(atoi36(pbuf), buf);
rns(F, pbuf, sizeof(pbuf));
}
}
#endif
int
readgame(boolean backup)
{
@ -807,7 +826,11 @@ readgame(boolean backup)
}
/* Read factions */
#ifdef ALLIANCES
if (global.data_version>ALLIANCES_VERSION) {
read_alliances(F);
}
#endif
n = ri(F);
printf(" - Einzulesende Parteien: %d\n", n);
fp = &factions;
@ -1114,6 +1137,22 @@ void wi36(FILE * F, int n)
fprintf(F, "%s ", itoa36(n));
}
#ifdef ALLIANCES
void
write_alliances(FILE * F)
{
alliance * al = alliances;
while (al) {
ws(F, itoa36(al->id));
ws(F, al->name);
al = al->next;
wnl(F);
}
ws(F, "end");
wnl(F);
}
#endif
void
write_items(FILE *F, item *ilist)
{
@ -1263,7 +1302,9 @@ writegame(char *path, char quiet)
/* Write factions */
#if defined(ALLIANCES) && RELEASE_VERSION>=ALLIANCES_VERSION
write_alliances(F);
#endif
n=listlen(factions);
wi(F, n);
wnl(F);

View File

@ -0,0 +1,160 @@
/* vi: set ts=2:
+-------------------+ Christian Schlittchen <corwin@amber.kn-bremen.de>
| | Enno Rehling <enno@eressea-pbem.de>
| Eressea PBEM host | Katja Zedel <katze@felidae.kn-bremen.de>
| (c) 1998 - 2001 | Henning Peters <faroul@beyond.kn-bremen.de>
| | Ingo Wilken <Ingo.Wilken@informatik.uni-oldenburg.de>
+-------------------+ Stefan Reich <reich@halbling.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 "alliance.h"
#include "command.h"
/* kernel includes */
#include <faction.h>
#include <message.h>
#include <region.h>
#include <unit.h>
/* util includes */
#include <umlaut.h>
/* libc includes */
#include <stdlib.h>
#include <string.h>
alliance * alliances = NULL;
alliance *
makealliance(int id, const char * name)
{
alliance * al = calloc(1, sizeof(alliance));
al->id=id;
al->name=strdup(name);
al->next=alliances;
return alliances=al;
}
alliance *
findalliance(int id)
{
alliance * al;
for (al=alliances;al;al=al->next) {
if (al->id==id) return al;
}
return NULL;
}
void destroy_kick(struct attrib * a)
{
faction_list * flist = (faction_list*)a->data.v;
freelist(flist);
}
const attrib_type at_kick = { "kick",
DEFAULT_INIT, destroy_kick
};
static attrib *
make_kick(void)
{
return a_new(&at_kick);
}
void
add_kick(attrib * a, const faction * f)
{
faction_list * flist = (faction_list*)a->data.v;
while (flist && flist->data!=f) flist = flist->next;
if (flist) return;
flist = calloc(1, sizeof(faction_list));
flist->data = (void*)f;
flist->next = (faction_list*)a->data.v;
a->data.v = flist;
}
static void
alliance_kick(const char * str, void * data, const char * cmd)
{
unit * u = (unit*)data;
faction * f = findfaction(atoi36(igetstrtoken(str)));
attrib * a;
if (f==NULL || f->alliance!=u->faction->alliance) {
/* does not belong to our alliance */
return;
}
a = a_find(f->attribs, &at_kick);
if (a==NULL) a = a_add(&f->attribs, make_kick());
add_kick(a, f);
}
static void
alliance_join(const char * str, void * data, const char * cmd)
{
unit * u = (unit*)data;
alliance * al = findalliance(atoi36(igetstrtoken(str)));
if (u->faction->alliance!=NULL || al==NULL) {
/* not found */
return;
}
u->faction->alliance = al;
/* inform the rest? */
}
static tnode * g_keys;
static void
alliance_command(const char * str, void * data, const char * cmd)
{
do_command(g_keys, data, str);
}
static void
execute(tnode * root)
{
region ** rp = &regions;
while (*rp) {
region * r = *rp;
unit **up = &r->units;
while (*up) {
unit * u = *up;
strlist * order;
for (order = u->orders; order; order = order->next) {
if (igetkeyword(order->s, u->faction->locale) == K_ALLIANCE) {
do_command(root, u, order->s);
}
}
if (u==*up) up = &u->next;
}
if (*rp==r) rp = &r->next;
}
}
void
alliancejoin(void)
{
tnode root;
add_command(&root, "alliance", &alliance_command);
g_keys = calloc(1, sizeof(tnode));
add_command(g_keys, "join", &alliance_join);
execute(&root);
free(g_keys);
}
void
alliancekick(void)
{
tnode root;
add_command(&root, "alliance", &alliance_command);
g_keys = calloc(1, sizeof(tnode));
add_command(g_keys, "kick", &alliance_kick);
execute(&root);
free(g_keys);
}

View File

@ -0,0 +1,34 @@
/* 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.
*/
struct plane;
struct attrib;
struct unit;
struct faction;
struct region;
typedef struct alliance {
struct alliance * next;
int id;
char * name;
} alliance;
extern alliance * alliances;
extern alliance * findalliance(int id);
extern alliance * makealliance(int id, const char * name);
extern void alliancejoin(void);
extern void alliancekick(void);
/* execute commands */

View File

@ -86,6 +86,10 @@ LIB32=link.exe -lib
# PROP Default_Filter "*.h"
# Begin Source File
SOURCE=.\alliance.h
# End Source File
# Begin Source File
SOURCE=.\arena.h
# End Source File
# Begin Source File
@ -135,6 +139,10 @@ SOURCE=.\xmas2001.h
# End Group
# Begin Source File
SOURCE=.\alliance.c
# End Source File
# Begin Source File
SOURCE=.\arena.c
# End Source File
# Begin Source File