forked from github/server
- Mapper kompilierte nicht wegen Henne-Ei-Problem destroyfaction().
destroyfaction() nach faction.c gelegt.
This commit is contained in:
parent
0fcf6f7c4f
commit
0dbdac747c
|
@ -101,143 +101,6 @@ extern int * age;
|
|||
boolean nobattle = false;
|
||||
/* ------------------------------------------------------------- */
|
||||
|
||||
void
|
||||
destroyfaction(faction * f)
|
||||
{
|
||||
region *rc;
|
||||
unit *u;
|
||||
faction *ff;
|
||||
|
||||
if( !f->alive ) return;
|
||||
|
||||
for (u=f->units;u;u=u->nextF) {
|
||||
region * r = u->region;
|
||||
unit * au;
|
||||
int number = 0;
|
||||
struct friend {
|
||||
struct friend * next;
|
||||
int number;
|
||||
faction * faction;
|
||||
unit * unit;
|
||||
} * friends = NULL;
|
||||
for (au=r->units;au;au=au->next) if (au->faction!=f) {
|
||||
if (alliedunit(u, au->faction, HELP_ALL)) {
|
||||
struct friend * nf, ** fr = &friends;
|
||||
|
||||
while (*fr && (*fr)->faction->no<au->faction->no) fr = &(*fr)->next;
|
||||
nf = *fr;
|
||||
if (nf==NULL || nf->faction!=au->faction) {
|
||||
nf = calloc(sizeof(struct friend), 1);
|
||||
nf->next = *fr;
|
||||
nf->faction = au->faction;
|
||||
nf->unit = au;
|
||||
*fr = nf;
|
||||
}
|
||||
nf->number += au->number;
|
||||
number += au->number;
|
||||
}
|
||||
}
|
||||
if (friends && number) {
|
||||
struct friend * nf = friends;
|
||||
while (nf) {
|
||||
unit * u2 = nf->unit;
|
||||
#ifdef NEW_ITEMS
|
||||
item * itm = u->items;
|
||||
while(itm){
|
||||
const item_type * itype = itm->type;
|
||||
item * itn = itm->next;
|
||||
int n = itm->number;
|
||||
n = n * nf->number / number;
|
||||
if (n>0) {
|
||||
i_change(&u->items, itype, -n);
|
||||
i_change(&u2->items, itype, n);
|
||||
}
|
||||
itm = itn;
|
||||
}
|
||||
#else
|
||||
resource_t res;
|
||||
for (res = 0; res <= R_SILVER; ++res) {
|
||||
int n = get_resource(u, res);
|
||||
if (n<=0) continue;
|
||||
n = n * nf->number / number;
|
||||
if (n<=0) continue;
|
||||
change_resource(u, res, -n);
|
||||
change_resource(u2, res, n);
|
||||
}
|
||||
#endif
|
||||
number -= nf->number;
|
||||
nf = nf->next;
|
||||
free(friends);
|
||||
friends = nf;
|
||||
}
|
||||
friends = NULL;
|
||||
}
|
||||
if (rterrain(r) != T_OCEAN && !!playerrace(u->race)) {
|
||||
const race * rc = u->race;
|
||||
int p = rpeasants(u->region);
|
||||
int m = rmoney(u->region);
|
||||
int h = rhorses(u->region);
|
||||
|
||||
/* Personen gehen nur an die Bauern, wenn sie auch von dort
|
||||
* stammen */
|
||||
if ((rc->ec_flags & ECF_REC_UNLIMITED)==0) {
|
||||
if (rc->ec_flags & ECF_REC_HORSES) { /* Zentauren an die Pferde */
|
||||
h += u->number;
|
||||
} else if (rc == new_race[RC_URUK]){ /* Orks zählen nur zur Hälfte */
|
||||
p += u->number/2;
|
||||
} else {
|
||||
p += u->number;
|
||||
}
|
||||
}
|
||||
m += get_money(u);
|
||||
h += get_item(u, I_HORSE);
|
||||
rsetpeasants(r, p);
|
||||
rsethorses(r, h);
|
||||
rsetmoney(r, m);
|
||||
|
||||
}
|
||||
set_number(u, 0);
|
||||
}
|
||||
f->alive = 0;
|
||||
/* no way! f->units = NULL; */
|
||||
handle_event(&f->attribs, "destroy", f);
|
||||
for (ff = factions; ff; ff = ff->next) {
|
||||
group *g;
|
||||
ally *sf, *sfn;
|
||||
|
||||
/* Alle HELFE für die Partei löschen */
|
||||
for (sf = ff->allies; sf; sf = sf->next) {
|
||||
if (sf->faction == f) {
|
||||
removelist(&ff->allies, sf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(g=ff->groups; g; g=g->next) {
|
||||
for (sf = g->allies; sf;) {
|
||||
sfn = sf->next;
|
||||
if (sf->faction == f) {
|
||||
removelist(&g->allies, sf);
|
||||
break;
|
||||
}
|
||||
sf = sfn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* units of other factions that were disguised as this faction
|
||||
* have their disguise replaced by ordinary faction hiding. */
|
||||
for(rc=regions; rc; rc=rc->next) {
|
||||
for(u=rc->units; u; u=u->next) {
|
||||
attrib *a = a_find(u->attribs, &at_otherfaction);
|
||||
if(!a) continue;
|
||||
if (get_otherfaction(a) == f) {
|
||||
a_removeall(&u->attribs, &at_otherfaction);
|
||||
fset(u, FL_PARTEITARNUNG);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
restart(unit *u, const race * rc)
|
||||
{
|
||||
|
|
|
@ -46,6 +46,4 @@ extern int count_migrants (const struct faction * f);
|
|||
extern attrib_type at_germs;
|
||||
#endif
|
||||
|
||||
extern void destroyfaction(struct faction * f);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
#include <region.h>
|
||||
#include <unit.h>
|
||||
|
||||
/* gamecode includes */
|
||||
#include <gamecode/laws.h> /* for destroyfaction */
|
||||
|
||||
/* util includes */
|
||||
#include <umlaut.h>
|
||||
#include <base36.h>
|
||||
|
|
|
@ -19,9 +19,14 @@
|
|||
#include "race.h"
|
||||
#include "region.h"
|
||||
#include "plane.h"
|
||||
#include "item.h"
|
||||
#include "group.h"
|
||||
|
||||
/* util includes */
|
||||
#include <base36.h>
|
||||
#include <event.h>
|
||||
|
||||
#include <attributes/otherfaction.h>
|
||||
|
||||
/* libc includes */
|
||||
#include <stdio.h>
|
||||
|
@ -145,3 +150,141 @@ checkpasswd(const faction * f, const char * passwd)
|
|||
if (strcasecmp(f->override, passwd)==0) return true;
|
||||
return false;
|
||||
}
|
||||
|
||||
void
|
||||
destroyfaction(faction * f)
|
||||
{
|
||||
region *rc;
|
||||
unit *u;
|
||||
faction *ff;
|
||||
|
||||
if( !f->alive ) return;
|
||||
|
||||
for (u=f->units;u;u=u->nextF) {
|
||||
region * r = u->region;
|
||||
unit * au;
|
||||
int number = 0;
|
||||
struct friend {
|
||||
struct friend * next;
|
||||
int number;
|
||||
faction * faction;
|
||||
unit * unit;
|
||||
} * friends = NULL;
|
||||
for (au=r->units;au;au=au->next) if (au->faction!=f) {
|
||||
if (alliedunit(u, au->faction, HELP_ALL)) {
|
||||
struct friend * nf, ** fr = &friends;
|
||||
|
||||
while (*fr && (*fr)->faction->no<au->faction->no) fr = &(*fr)->next;
|
||||
nf = *fr;
|
||||
if (nf==NULL || nf->faction!=au->faction) {
|
||||
nf = calloc(sizeof(struct friend), 1);
|
||||
nf->next = *fr;
|
||||
nf->faction = au->faction;
|
||||
nf->unit = au;
|
||||
*fr = nf;
|
||||
}
|
||||
nf->number += au->number;
|
||||
number += au->number;
|
||||
}
|
||||
}
|
||||
if (friends && number) {
|
||||
struct friend * nf = friends;
|
||||
while (nf) {
|
||||
unit * u2 = nf->unit;
|
||||
#ifdef NEW_ITEMS
|
||||
item * itm = u->items;
|
||||
while(itm){
|
||||
const item_type * itype = itm->type;
|
||||
item * itn = itm->next;
|
||||
int n = itm->number;
|
||||
n = n * nf->number / number;
|
||||
if (n>0) {
|
||||
i_change(&u->items, itype, -n);
|
||||
i_change(&u2->items, itype, n);
|
||||
}
|
||||
itm = itn;
|
||||
}
|
||||
#else
|
||||
resource_t res;
|
||||
for (res = 0; res <= R_SILVER; ++res) {
|
||||
int n = get_resource(u, res);
|
||||
if (n<=0) continue;
|
||||
n = n * nf->number / number;
|
||||
if (n<=0) continue;
|
||||
change_resource(u, res, -n);
|
||||
change_resource(u2, res, n);
|
||||
}
|
||||
#endif
|
||||
number -= nf->number;
|
||||
nf = nf->next;
|
||||
free(friends);
|
||||
friends = nf;
|
||||
}
|
||||
friends = NULL;
|
||||
}
|
||||
if (rterrain(r) != T_OCEAN && !!playerrace(u->race)) {
|
||||
const race * rc = u->race;
|
||||
int p = rpeasants(u->region);
|
||||
int m = rmoney(u->region);
|
||||
int h = rhorses(u->region);
|
||||
|
||||
/* Personen gehen nur an die Bauern, wenn sie auch von dort
|
||||
* stammen */
|
||||
if ((rc->ec_flags & ECF_REC_UNLIMITED)==0) {
|
||||
if (rc->ec_flags & ECF_REC_HORSES) { /* Zentauren an die Pferde */
|
||||
h += u->number;
|
||||
} else if (rc == new_race[RC_URUK]){ /* Orks zählen nur zur Hälfte */
|
||||
p += u->number/2;
|
||||
} else {
|
||||
p += u->number;
|
||||
}
|
||||
}
|
||||
m += get_money(u);
|
||||
h += get_item(u, I_HORSE);
|
||||
rsetpeasants(r, p);
|
||||
rsethorses(r, h);
|
||||
rsetmoney(r, m);
|
||||
|
||||
}
|
||||
set_number(u, 0);
|
||||
}
|
||||
f->alive = 0;
|
||||
/* no way! f->units = NULL; */
|
||||
handle_event(&f->attribs, "destroy", f);
|
||||
for (ff = factions; ff; ff = ff->next) {
|
||||
group *g;
|
||||
ally *sf, *sfn;
|
||||
|
||||
/* Alle HELFE für die Partei löschen */
|
||||
for (sf = ff->allies; sf; sf = sf->next) {
|
||||
if (sf->faction == f) {
|
||||
removelist(&ff->allies, sf);
|
||||
break;
|
||||
}
|
||||
}
|
||||
for(g=ff->groups; g; g=g->next) {
|
||||
for (sf = g->allies; sf;) {
|
||||
sfn = sf->next;
|
||||
if (sf->faction == f) {
|
||||
removelist(&g->allies, sf);
|
||||
break;
|
||||
}
|
||||
sf = sfn;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* units of other factions that were disguised as this faction
|
||||
* have their disguise replaced by ordinary faction hiding. */
|
||||
for(rc=regions; rc; rc=rc->next) {
|
||||
for(u=rc->units; u; u=u->next) {
|
||||
attrib *a = a_find(u->attribs, &at_otherfaction);
|
||||
if(!a) continue;
|
||||
if (get_otherfaction(a) == f) {
|
||||
a_removeall(&u->attribs, &at_otherfaction);
|
||||
fset(u, FL_PARTEITARNUNG);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -85,5 +85,6 @@ extern const char * factionname(const struct faction * f);
|
|||
extern void * resolve_faction(void * data);
|
||||
extern struct unit * addplayer(struct region *r, const char *email, const char* password, const struct race * frace, const struct locale *loc);
|
||||
extern boolean checkpasswd(const faction * f, const char * passwd);
|
||||
extern void destroyfaction(faction * f);
|
||||
|
||||
#endif
|
||||
|
|
|
@ -23,9 +23,6 @@
|
|||
#include <region.h>
|
||||
#include <unit.h>
|
||||
|
||||
/* gamecode includes */
|
||||
#include <gamecode/laws.h> /* for destroyfaction */
|
||||
|
||||
/* util includes */
|
||||
#include <umlaut.h>
|
||||
#include <base36.h>
|
||||
|
|
|
@ -4,12 +4,12 @@ ifndef ERESSEA
|
|||
endif
|
||||
|
||||
# Hier definieren, damit nicht '@gcc'
|
||||
CC = gcc-3.0 -D_GNU_SOURCE -ansi -pedantic
|
||||
DEPEND = @gcc-3.0 -MM -MG -r
|
||||
CC = gcc-3.2 -D_GNU_SOURCE -ansi -pedantic
|
||||
DEPEND = @gcc-3.2 -MM -MG -r
|
||||
# CC = gcc -D_GNU_SOURCE
|
||||
AR = ar
|
||||
CTAGS = ctags-exuberant
|
||||
LD = gcc-3.0
|
||||
LD = gcc-3.2
|
||||
INSTALL = cp
|
||||
CFLAGS += -march=athlon -minline-all-stringops
|
||||
|
||||
|
|
|
@ -19,14 +19,13 @@ INCLUDES += \
|
|||
|
||||
LIBNAMES += \
|
||||
e-triggers \
|
||||
e-modules \
|
||||
e-kernel \
|
||||
e-items \
|
||||
e-spells \
|
||||
e-races \
|
||||
e-attributes \
|
||||
e-util \
|
||||
e-modules
|
||||
e-modules \
|
||||
e-util
|
||||
|
||||
LIBS += \
|
||||
-L$(PUBLISH_DIR) \
|
||||
|
|
Loading…
Reference in New Issue