The incomplete fspecial functions cause quite a bit of attribute-lookups, so I'm putting them in a #define until they get implemented (if ever).

#define KARMA_MODULE is you want to use fspecial in the future.
This commit is contained in:
Enno Rehling 2006-02-17 22:59:03 +00:00
parent da213e5f16
commit dceb83c6a7
25 changed files with 244 additions and 190 deletions

View File

@ -629,8 +629,10 @@ cr_output_unit(FILE * F, const region * r,
assert(u); assert(u);
#ifdef KARMA_MODULE
if (fspecial(u->faction, FS_HIDDEN)) if (fspecial(u->faction, FS_HIDDEN))
a_fshidden = a_find(u->attribs, &at_fshidden); a_fshidden = a_find(u->attribs, &at_fshidden);
#endif /* KARMA_MODULE */
fprintf(F, "EINHEIT %d\n", u->no); fprintf(F, "EINHEIT %d\n", u->no);
fprintf(F, "\"%s\";Name\n", u->name); fprintf(F, "\"%s\";Name\n", u->name);

View File

@ -226,7 +226,9 @@ add_recruits(unit * u, int number, int wanted)
assert(number<=wanted); assert(number<=wanted);
if (number > 0) { if (number > 0) {
unit * unew; unit * unew;
#ifdef KARMA_MODULE
int i = fspecial(u->faction, FS_MILITIA); int i = fspecial(u->faction, FS_MILITIA);
#endif /* KARMA_MODULE */
if (u->number==0) { if (u->number==0) {
set_number(u, number); set_number(u, number);
@ -244,6 +246,7 @@ add_recruits(unit * u, int number, int wanted)
change_level(unew, SK_RIDING, 1); change_level(unew, SK_RIDING, 1);
} }
#ifdef KARMA_MODULE
if (i > 0) { if (i > 0) {
if (unew->race->bonus[SK_SPEAR] >= 0) if (unew->race->bonus[SK_SPEAR] >= 0)
change_level(unew, SK_SPEAR, i); change_level(unew, SK_SPEAR, i);
@ -258,6 +261,7 @@ add_recruits(unit * u, int number, int wanted)
if (unew->race->bonus[SK_AUSDAUER] >= 0) if (unew->race->bonus[SK_AUSDAUER] >= 0)
change_level(unew, SK_AUSDAUER, i); change_level(unew, SK_AUSDAUER, i);
} }
#endif /* KARMA_MODULE */
if (unew!=u) { if (unew!=u) {
transfermen(unew, u, unew->number); transfermen(unew, u, unew->number);
destroy_unit(unew); destroy_unit(unew);

View File

@ -2705,9 +2705,11 @@ instant_orders(void)
case K_SETSTEALTH: case K_SETSTEALTH:
setstealth_cmd(u, ord); setstealth_cmd(u, ord);
break; break;
#ifdef KARMA_MODULE
case K_WEREWOLF: case K_WEREWOLF:
setwere_cmd(u, ord); setwere_cmd(u, ord);
break; break;
#endif /* KARMA_MODULE */
case K_STATUS: case K_STATUS:
/* KAEMPFE [ NICHT | AGGRESSIV | DEFENSIV | HINTEN | FLIEHE ] */ /* KAEMPFE [ NICHT | AGGRESSIV | DEFENSIV | HINTEN | FLIEHE ] */
status_cmd(u, ord); status_cmd(u, ord);
@ -2875,7 +2877,6 @@ renumber_factions(void)
funhash(f); funhash(f);
f->no = rp->want; f->no = rp->want;
fhash(f); fhash(f);
register_faction_id(rp->want);
fset(f, FF_NEWID); fset(f, FF_NEWID);
} }
while (renum) { while (renum) {
@ -3351,18 +3352,23 @@ static int
maxunits(const faction *f) maxunits(const faction *f)
{ {
if (global.unitsperalliance == true) { if (global.unitsperalliance == true) {
faction *f2;
float mult = 1.0; float mult = 1.0;
#ifdef KARMA_MODULE
faction *f2;
for (f2 = factions; f2; f2 = f2->next) { for (f2 = factions; f2; f2 = f2->next) {
if (f2->alliance == f->alliance) { if (f2->alliance == f->alliance) {
mult += 0.4f * fspecial(f2, FS_ADMINISTRATOR); mult += 0.4f * fspecial(f2, FS_ADMINISTRATOR);
} }
} }
#endif /* KARMA_MODULE */
return (int) (global.maxunits * mult); return (int) (global.maxunits * mult);
} }
#ifdef KARMA_MODULE
return (int) (global.maxunits * (1 + 0.4 * fspecial(f, FS_ADMINISTRATOR))); return (int) (global.maxunits * (1 + 0.4 * fspecial(f, FS_ADMINISTRATOR)));
#else
return global.maxunits;
#endif /* KARMA_MODULE */
} }
static boolean static boolean
@ -3654,16 +3660,19 @@ monthly_healing(void)
if (u->race->flags & RCF_NOHEAL) continue; if (u->race->flags & RCF_NOHEAL) continue;
if (fval(u, UFL_HUNGER)) continue; if (fval(u, UFL_HUNGER)) continue;
if (fspecial(u->faction, FS_UNDEAD)) continue;
if (fval(r->terrain, SEA_REGION) && u->ship==NULL && !(canswim(u) || canfly(u))) { if (fval(r->terrain, SEA_REGION) && u->ship==NULL && !(canswim(u) || canfly(u))) {
continue; continue;
} }
#ifdef KARMA_MODULE
if (fspecial(u->faction, FS_UNDEAD)) continue;
if(fspecial(u->faction, FS_REGENERATION)) { if(fspecial(u->faction, FS_REGENERATION)) {
u->hp = umhp; u->hp = umhp;
continue; continue;
} }
#endif /* KARMA_MODULE */
p *= heal_factor(u->race); p *= heal_factor(u->race);
if (u->hp < umhp) { if (u->hp < umhp) {

View File

@ -53,6 +53,8 @@
#include <math.h> #include <math.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef KARMA_MODULE
#define STANDARD_LUCK 0 #define STANDARD_LUCK 0
static void static void
@ -182,4 +184,4 @@ check_luck(void)
lucky_event(f); lucky_event(f);
} }
} }
#endif /* KARMA_MODULE */

View File

@ -676,8 +676,11 @@ drown(region *r)
unit ** up = up=&r->units; unit ** up = up=&r->units;
while (*up) { while (*up) {
unit *u = *up; unit *u = *up;
#ifdef KARMA_MODULE
int amphibian_level = fspecial(u->faction, FS_AMPHIBIAN); int amphibian_level = fspecial(u->faction, FS_AMPHIBIAN);
#else
int amphibian_level = 0;
#endif
if (u->ship || u->race == new_race[RC_SPELL]) { if (u->ship || u->race == new_race[RC_SPELL]) {
up=&u->next; up=&u->next;
continue; continue;
@ -1180,7 +1183,9 @@ icebergs(void)
void void
randomevents(void) randomevents(void)
{ {
#ifdef KARMA_MODULE
faction *f; faction *f;
#endif /* KARMA_MODULE */
region *r; region *r;
building *b, *b2; building *b, *b2;
unit *u; unit *u;
@ -1274,6 +1279,7 @@ randomevents(void)
} }
} }
#ifdef KARMA_MODULE
/* lycanthropen werden werwölfe */ /* lycanthropen werden werwölfe */
for (f = factions; f; f=f->next) { for (f = factions; f; f=f->next) {
int level = fspecial(f, FS_LYCANTROPE); int level = fspecial(f, FS_LYCANTROPE);
@ -1287,6 +1293,7 @@ randomevents(void)
} }
} }
} }
#endif
/* Chaos */ /* Chaos */
for (r = regions; r; r = r->next) { for (r = regions; r; r = r->next) {
@ -1324,8 +1331,9 @@ randomevents(void)
} }
#endif #endif
dissolve_units(); dissolve_units();
check_split(); check_split();
#ifdef KARMA_MODULE
check_luck(); check_luck();
#endif /* KARMA_MODULE */
} }

View File

@ -1759,6 +1759,7 @@ report_plaintext(const char * filename, report_context * ctx)
centre(F, alliancename(f->alliance), true); centre(F, alliancename(f->alliance), true);
} }
#ifdef KARMA_MODULE
buf[0] = 0; buf[0] = 0;
dh = 0; dh = 0;
for (a=a_find(f->attribs, &at_faction_special); a; a=a->nexttype) { for (a=a_find(f->attribs, &at_faction_special); a; a=a->nexttype) {
@ -1773,13 +1774,14 @@ report_plaintext(const char * filename, report_context * ctx)
strcat(buf, buf2); strcat(buf, buf2);
} }
if(dh > 0) centre(F, buf, true); if(dh > 0) centre(F, buf, true);
dh = 0;
if (f->karma > 0) { if (f->karma > 0) {
sprintf(buf, "Deine Partei hat %d Karma.", f->karma); sprintf(buf, "Deine Partei hat %d Karma.", f->karma);
centre(F, buf, true); centre(F, buf, true);
} }
#endif
dh = 0;
if (f->age <= 2) { if (f->age <= 2) {
if (f->age <= 1) { if (f->age <= 1) {
ADDMSG(&f->msgs, msg_message("changepasswd", ADDMSG(&f->msgs, msg_message("changepasswd",

View File

@ -118,6 +118,7 @@ spy_cmd(unit * u, struct order * ord)
int int
setwere_cmd(unit *u, struct order * ord) setwere_cmd(unit *u, struct order * ord)
{ {
#ifdef KARMA_MODULE
int level = fspecial(u->faction, FS_LYCANTROPE); int level = fspecial(u->faction, FS_LYCANTROPE);
const char *s; const char *s;
@ -148,7 +149,7 @@ setwere_cmd(unit *u, struct order * ord)
} }
} }
#endif /* KARMA_MODULE */
return 0; return 0;
} }
@ -158,7 +159,6 @@ setstealth_cmd(unit * u, struct order * ord)
const char *s; const char *s;
char level; char level;
const race * trace; const race * trace;
attrib *a;
init_tokens(ord); init_tokens(ord);
skip_token(); skip_token();
@ -264,6 +264,7 @@ setstealth_cmd(unit * u, struct order * ord)
/* TARNE ALLES (was nicht so alles geht?) */ /* TARNE ALLES (was nicht so alles geht?) */
u_seteffstealth(u, -1); u_seteffstealth(u, -1);
break; break;
#ifdef KARMA_MODULE
case P_NUMBER: case P_NUMBER:
/* TARNE ANZAHL [NICHT] */ /* TARNE ANZAHL [NICHT] */
if (!fspecial(u->faction, FS_HIDDEN)) { if (!fspecial(u->faction, FS_HIDDEN)) {
@ -272,15 +273,17 @@ setstealth_cmd(unit * u, struct order * ord)
} }
s = getstrtoken(); s = getstrtoken();
if (findparam(s, u->faction->locale) == P_NOT) { if (findparam(s, u->faction->locale) == P_NOT) {
a = a_find(u->attribs, &at_fshidden); attrib * a = a_find(u->attribs, &at_fshidden);
if(a) a->data.ca[0] = 0; if (a==NULL) a->data.ca[0] = 0;
if (a->data.i == 0) a_remove(&u->attribs, a); if (a->data.i == 0) a_remove(&u->attribs, a);
} else { } else {
a = a_find(u->attribs, &at_fshidden); attrib * a = a_find(u->attribs, &at_fshidden);
if(!a) a = a_add(&u->attribs, a_new(&at_fshidden)); if (a!=NULL) a = a_add(&u->attribs, a_new(&at_fshidden));
a->data.ca[0] = 1; a->data.ca[0] = 1;
} }
break; break;
#endif /* KARMA_MODULE */
#ifdef KARMA_MODULE
case P_ITEMS: case P_ITEMS:
/* TARNE GEGENSTÄNDE [NICHT] */ /* TARNE GEGENSTÄNDE [NICHT] */
if(!fspecial(u->faction, FS_HIDDEN)) { if(!fspecial(u->faction, FS_HIDDEN)) {
@ -288,15 +291,16 @@ setstealth_cmd(unit * u, struct order * ord)
return 0; return 0;
} }
if (findparam(s, u->faction->locale) == P_NOT) { if (findparam(s, u->faction->locale) == P_NOT) {
a = a_find(u->attribs, &at_fshidden); attrib * a = a_find(u->attribs, &at_fshidden);
if(a) a->data.ca[1] = 0; if (a!=NULL) a->data.ca[1] = 0;
if (a->data.i == 0) a_remove(&u->attribs, a); if (a->data.i == 0) a_remove(&u->attribs, a);
} else { } else {
a = a_find(u->attribs, &at_fshidden); attrib * a = a_find(u->attribs, &at_fshidden);
if(!a) a = a_add(&u->attribs, a_new(&at_fshidden)); if (a==NULL) a = a_add(&u->attribs, a_new(&at_fshidden));
a->data.ca[1] = 1; a->data.ca[1] = 1;
} }
break; break;
#endif /* KARMA_MODULE */
case P_NOT: case P_NOT:
u_seteffstealth(u, -1); u_seteffstealth(u, -1);
break; break;

View File

@ -447,7 +447,6 @@ learn(void)
int p; int p;
magic_t mtyp; magic_t mtyp;
int l; int l;
int warrior_skill;
int studycost; int studycost;
/* lernen nach lehren */ /* lernen nach lehren */
@ -645,18 +644,20 @@ learn(void)
change_effect(u, oldpotiontype[P_FOOL], -l); change_effect(u, oldpotiontype[P_FOOL], -l);
} }
warrior_skill = fspecial(u->faction, FS_WARRIOR); #ifdef KARMA_MODULE
if(warrior_skill > 0) { l = fspecial(u->faction, FS_WARRIOR);
if (l > 0) {
if (sk == SK_CROSSBOW || sk == SK_LONGBOW if (sk == SK_CROSSBOW || sk == SK_LONGBOW
|| sk == SK_CATAPULT || sk == SK_MELEE || sk == SK_SPEAR || sk == SK_CATAPULT || sk == SK_MELEE || sk == SK_SPEAR
|| sk == SK_AUSDAUER || sk == SK_WEAPONLESS) || sk == SK_AUSDAUER || sk == SK_WEAPONLESS)
{ {
teach->value += u->number * (5+warrior_skill*5); teach->value += u->number * 5 * (l+1);
} else { } else {
teach->value -= u->number * (5+warrior_skill*5); teach->value -= u->number * 5 * (l+1);
teach->value = max(0, teach->value); teach->value = max(0, teach->value);
} }
} }
#endif /* KARMA_MODULE */
if (p != studycost) { if (p != studycost) {
/* ist_in_gebaeude(r, u, BT_UNIVERSITAET) == 1) { */ /* ist_in_gebaeude(r, u, BT_UNIVERSITAET) == 1) { */

View File

@ -905,7 +905,6 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
unit *du = df->unit; unit *du = df->unit;
battle *b = df->side->battle; battle *b = df->side->battle;
int heiltrank = 0; int heiltrank = 0;
int faerie_level;
char debugbuf[512]; char debugbuf[512];
/* Schild */ /* Schild */
@ -929,10 +928,12 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
++at.fighter->hits; ++at.fighter->hits;
#endif #endif
#ifdef KARMA_MODULE
if (fval(au, UFL_WERE)) { if (fval(au, UFL_WERE)) {
int level = fspecial(du->faction, FS_LYCANTROPE); int level = fspecial(du->faction, FS_LYCANTROPE);
da += level; da += level;
} }
#endif /* KARMA_MODULE */
switch (type) { switch (type) {
case AT_STANDARD: case AT_STANDARD:
@ -964,11 +965,14 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
/* magische Rüstung durch Artefakte oder Sprüche */ /* magische Rüstung durch Artefakte oder Sprüche */
/* Momentan nur Trollgürtel und Werwolf-Eigenschaft */ /* Momentan nur Trollgürtel und Werwolf-Eigenschaft */
am = select_magicarmor(dt); am = select_magicarmor(dt);
#ifdef KARMA_MODULE
if(fval(du, UFL_WERE)) { if(fval(du, UFL_WERE)) {
/* this counts as magical armor */ /* this counts as magical armor */
int level = fspecial(du->faction, FS_LYCANTROPE); int level = fspecial(du->faction, FS_LYCANTROPE);
am += level; am += level;
} }
#endif /* KARMA_MODULE */
#if CHANGED_CROSSBOWS == 1 #if CHANGED_CROSSBOWS == 1
if(awtype && fval(awtype,WTF_ARMORPIERCING)) { if(awtype && fval(awtype,WTF_ARMORPIERCING)) {
@ -989,6 +993,22 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
if (type!=AT_COMBATSPELL && type!=AT_SPELL) { if (type!=AT_COMBATSPELL && type!=AT_SPELL) {
/* Kein Zauber, normaler Waffenschaden */ /* Kein Zauber, normaler Waffenschaden */
double kritchance = (sk * 3 - sd) / 200.0; double kritchance = (sk * 3 - sd) / 200.0;
#ifdef KARMA_MODULE
int faerie_level = fspecial(du->faction, FS_FAERIE);
da += jihad(au->faction, du->race);
if (type == AT_STANDARD && faerie_level) {
int c;
for (c=0;weapon->type->itype->construction->materials[c].number; c++) {
if(weapon->type->itype->construction->materials[c].rtype == oldresourcetype[R_IRON]) {
da += faerie_level;
break;
}
}
}
#endif /* KARMA_MODULE */
kritchance = max(kritchance, 0.005); kritchance = max(kritchance, 0.005);
kritchance = min(0.9, kritchance); kritchance = min(0.9, kritchance);
@ -1000,20 +1020,6 @@ terminate(troop dt, troop at, int type, const char *damage, boolean missile)
} }
da += rc_specialdamage(au->race, du->race, awtype); da += rc_specialdamage(au->race, du->race, awtype);
#ifdef KARMA_MODULE
da += jihad(au->faction, du->race);
#endif
faerie_level = fspecial(du->faction, FS_FAERIE);
if (type == AT_STANDARD && faerie_level) {
int c;
for (c=0;weapon->type->itype->construction->materials[c].number; c++) {
if(weapon->type->itype->construction->materials[c].rtype == oldresourcetype[R_IRON]) {
da += faerie_level;
break;
}
}
}
if (awtype!=NULL && fval(awtype, WTF_MISSILE)) { if (awtype!=NULL && fval(awtype, WTF_MISSILE)) {
/* Fernkampfschadenbonus */ /* Fernkampfschadenbonus */
@ -1615,10 +1621,12 @@ skilldiff(troop at, troop dt, int dist)
skdiff += 5; skdiff += 5;
} }
#ifdef KARMA_MODULE
/* Werwolf */ /* Werwolf */
if(fval(au, UFL_WERE)) { if(fval(au, UFL_WERE)) {
skdiff += fspecial(au->faction, FS_LYCANTROPE); skdiff += fspecial(au->faction, FS_LYCANTROPE);
} }
#endif /* KARMA_MODULE */
if (au->race == new_race[RC_GOBLIN] && if (au->race == new_race[RC_GOBLIN] &&
af->side->size[SUM_ROW] >= df->side->size[SUM_ROW] * 10) af->side->size[SUM_ROW] >= df->side->size[SUM_ROW] * 10)
@ -1640,13 +1648,16 @@ skilldiff(troop at, troop dt, int dist)
init=true; init=true;
} }
if (df->building->type->flags & BTF_PROTECTION) { if (df->building->type->flags & BTF_PROTECTION) {
int beff = buildingeffsize(df->building, false)-1;
/* -1 because the tradepost has no protection value */
#ifdef KARMA_MODULE
if (fspecial(au->faction, FS_SAPPER)) { if (fspecial(au->faction, FS_SAPPER)) {
/* Halbe Schutzwirkung, aufgerundet */ /* Halbe Schutzwirkung, aufgerundet */
/* -1 because the tradepost has no protection value */ beff = (beff+1)/2;
skdiff -= (buildingeffsize(df->building, false)-1+1)/2;
} else {
skdiff -= buildingeffsize(df->building, false)-1;
} }
#endif /* KARMA_MODULE */
skdiff -= beff;
is_protected = 2; is_protected = 2;
} }
if (strongwall_ct) { if (strongwall_ct) {
@ -2342,14 +2353,16 @@ aftermath(battle * b)
fighter *df = *fi; fighter *df = *fi;
unit *du = df->unit; unit *du = df->unit;
int dead = du->number - df->alive - df->run.number; int dead = du->number - df->alive - df->run.number;
const attrib *a;
int pr_mercy = 0; int pr_mercy = 0;
#ifdef KARMA_MODULE
const attrib *a;
for (a = a_find(du->attribs, &at_prayer_effect); a; a = a->nexttype) { for (a = a_find(du->attribs, &at_prayer_effect); a; a = a->nexttype) {
if (a->data.sa[0] == PR_MERCY) { if (a->data.sa[0] == PR_MERCY) {
pr_mercy = a->data.sa[1]; pr_mercy = a->data.sa[1];
} }
} }
#endif /* KARMA_MODULE */
#ifdef TROLLSAVE #ifdef TROLLSAVE
/* Trolle können regenerieren */ /* Trolle können regenerieren */
@ -2900,12 +2913,14 @@ make_fighter(battle * b, unit * u, side * s1, boolean attack)
/* Effekte von Artefakten */ /* Effekte von Artefakten */
strongmen = min(fig->unit->number, get_item(u, I_TROLLBELT)); strongmen = min(fig->unit->number, get_item(u, I_TROLLBELT));
#ifdef KARMA_MODULE
for (a = a_find(u->attribs, &at_prayer_effect); a; a = a->nexttype) { for (a = a_find(u->attribs, &at_prayer_effect); a; a = a->nexttype) {
if (a->data.sa[0] == PR_AID) { if (a->data.sa[0] == PR_AID) {
pr_aid = true; pr_aid = true;
break; break;
} }
} }
#endif /* KARMA_MODULE */
/* Hitpoints, Attack- und Defence-Boni für alle Personen */ /* Hitpoints, Attack- und Defence-Boni für alle Personen */
for (i = 0; i < fig->alive; i++) { for (i = 0; i < fig->alive; i++) {
@ -3916,6 +3931,7 @@ do_battle(void)
do_attack(fig); do_attack(fig);
} }
#ifdef KARMA_MODULE
/* Regeneration */ /* Regeneration */
for (fi = b->fighters.begin; fi != b->fighters.end; ++fi) { for (fi = b->fighters.begin; fi != b->fighters.end; ++fi) {
fighter *fig = *fi; fighter *fig = *fi;
@ -3926,6 +3942,7 @@ do_battle(void)
do_regenerate(fig); do_regenerate(fig);
} }
} }
#endif /* KARMA_MODULE */
} }
printf("\n"); printf("\n");

View File

@ -530,7 +530,9 @@ max_skill(faction * f, skill_t sk)
m = MAXMAGICIANS; m = MAXMAGICIANS;
} }
if (f->race == new_race[RC_ELF]) m += 1; if (f->race == new_race[RC_ELF]) m += 1;
#ifdef KARMA_MODULE
m += fspecial(f, FS_MAGOCRACY) * 2; m += fspecial(f, FS_MAGOCRACY) * 2;
#endif /* KARMA_MODULE */
break; break;
case SK_ALCHEMY: case SK_ALCHEMY:
m = MAXALCHEMISTS; m = MAXALCHEMISTS;
@ -1166,20 +1168,22 @@ static attrib_type at_lighthouse = {
void void
update_lighthouse(building * lh) update_lighthouse(building * lh)
{ {
region * r = lh->region;
short d = (short)log10(lh->size) + 1;
short x, y;
static boolean init_lighthouse = false; static boolean init_lighthouse = false;
static const struct building_type * bt_lighthouse = 0; static const struct building_type * bt_lighthouse = 0;
if (!init_lighthouse) { if (!init_lighthouse) {
bt_lighthouse = bt_find("lighthouse"); bt_lighthouse = bt_find("lighthouse");
if (bt_lighthouse==NULL) return;
init_lighthouse = true; init_lighthouse = true;
} }
if (bt_lighthouse==NULL || lh->type!=bt_lighthouse) return; if (lh->type==bt_lighthouse) {
region * r = lh->region;
short d = (short)log10(lh->size) + 1;
short x;
for (x=-d;x<=d;++x) { for (x=-d;x<=d;++x) {
short y;
for (y=-d;y<=d;++y) { for (y=-d;y<=d;++y) {
attrib * a; attrib * a;
region * r2 = findregion(x+r->x, y+r->y); region * r2 = findregion(x+r->x, y+r->y);
@ -1200,6 +1204,8 @@ update_lighthouse(building * lh)
} }
} }
}
int int
count_all(const faction * f) count_all(const faction * f)
{ {
@ -2549,38 +2555,17 @@ remove_empty_units(void)
} }
} }
int *used_faction_ids = NULL;
int no_used_faction_ids = 0;
static int
_cmp_int(const void *i1, const void *i2)
{
if(i2==NULL)
return(*(int*)i1);
return (*(int*)i1 - *(int *)i2);
}
void
register_faction_id(int id)
{
no_used_faction_ids++;
used_faction_ids = realloc(used_faction_ids, no_used_faction_ids*sizeof(int));
used_faction_ids[no_used_faction_ids-1] = id;
if(no_used_faction_ids > 1)
qsort(used_faction_ids, (size_t)no_used_faction_ids, sizeof(int), _cmp_int);
}
boolean boolean
faction_id_is_unused(int id) faction_id_is_unused(int id)
{ {
return findfaction(id)==NULL; return findfaction(id)==NULL && id!=MONSTER_FACTION;
} }
int int
weight(const unit * u) weight(const unit * u)
{ {
int w, n = 0, in_bag = 0; int w, n = 0, in_bag = 0;
int faerie_level; int faerie_level = 0;
item * itm; item * itm;
for (itm=u->items;itm;itm=itm->next) { for (itm=u->items;itm;itm=itm->next) {
@ -2590,7 +2575,10 @@ weight(const unit * u)
in_bag += w; in_bag += w;
} }
#ifdef KARMA_MODULE
faerie_level = fspecial(u->faction, FS_FAERIE); faerie_level = fspecial(u->faction, FS_FAERIE);
#endif /* KARMA_MODULE */
if (faerie_level) { if (faerie_level) {
n += (u->number * u->race->weight)/(1+faerie_level); n += (u->number * u->race->weight)/(1+faerie_level);
} else { } else {
@ -2605,18 +2593,6 @@ weight(const unit * u)
return n; return n;
} }
void
init_used_faction_ids(void)
{
faction *f;
no_used_faction_ids = 0;
for(f = factions; f; f = f->next) {
register_faction_id(f->no);
}
}
void void
make_undead_unit(unit * u) make_undead_unit(unit * u)
{ {
@ -2683,13 +2659,14 @@ lifestyle(const unit * u)
if(u->region->planep && fval(u->region->planep, PFL_NOFEED)) if(u->region->planep && fval(u->region->planep, PFL_NOFEED))
return 0; return 0;
#ifdef KARMA_MODULE
if(fspecial(u->faction, FS_REGENERATION)) if(fspecial(u->faction, FS_REGENERATION))
need += 1; need += 1;
if(fspecial(u->faction, FS_ADMINISTRATOR)) if(fspecial(u->faction, FS_ADMINISTRATOR))
need += 1; need += 1;
if(fspecial(u->faction, FS_WYRM) && u->race == new_race[RC_WYRM]) if(fspecial(u->faction, FS_WYRM) && u->race == new_race[RC_WYRM])
need *= 500; need *= 500;
#endif /* KARMA_MODULE */
return need; return need;
} }
@ -2812,9 +2789,11 @@ default_wage(const region *r, const faction * f, const race * rc)
index = 1; index = 1;
} }
wage = wagetable[esize][index]; wage = wagetable[esize][index];
#ifdef KARMA_MODULE
if (fspecial(f, FS_URBAN)) { if (fspecial(f, FS_URBAN)) {
wage += wagetable[esize][3]; wage += wagetable[esize][3];
} }
#endif /* KARMA_MODULE */
} else { } else {
if (fval(r->terrain, SEA_REGION)) { if (fval(r->terrain, SEA_REGION)) {
wage = 11; wage = 11;
@ -3121,9 +3100,14 @@ attrib_init(void)
at_register(&at_icastle); at_register(&at_icastle);
at_register(&at_guard); at_register(&at_guard);
at_register(&at_group); at_register(&at_group);
#ifdef KARMA_MODULE
at_register(&at_faction_special); at_register(&at_faction_special);
at_register(&at_prayer_timeout); at_register(&at_prayer_timeout);
at_register(&at_wyrm); at_register(&at_wyrm);
at_register(&at_jihad);
#endif /* KARMA_MODULE */
at_register(&at_building_generic_type); at_register(&at_building_generic_type);
at_register(&at_maxmagicians); at_register(&at_maxmagicians);
at_register(&at_npcfaction); at_register(&at_npcfaction);
@ -3136,7 +3120,6 @@ attrib_init(void)
register_bordertype(&bt_road); register_bordertype(&bt_road);
register_bordertype(&bt_questportal); register_bordertype(&bt_questportal);
at_register(&at_jihad);
at_register(&at_germs); at_register(&at_germs);
at_register(&at_laen); /* required for old datafiles */ at_register(&at_laen); /* required for old datafiles */
#ifdef XECMD_MODULE #ifdef XECMD_MODULE

View File

@ -848,9 +848,6 @@ extern int turn;
extern int quiet; extern int quiet;
/* parteinummern */ /* parteinummern */
extern int *used_faction_ids;
extern int no_used_faction_ids;
extern void register_faction_id(int id);
extern boolean faction_id_is_unused(int); extern boolean faction_id_is_unused(int);
/* leuchtturm */ /* leuchtturm */

View File

@ -128,7 +128,6 @@ addfaction(const char *email, const char * password,
f->options = Pow(O_REPORT) | Pow(O_ZUGVORLAGE) | Pow(O_SILBERPOOL) | Pow(O_COMPUTER) | Pow(O_COMPRESS) | Pow(O_ADRESSEN) | Pow(O_STATISTICS); f->options = Pow(O_REPORT) | Pow(O_ZUGVORLAGE) | Pow(O_SILBERPOOL) | Pow(O_COMPUTER) | Pow(O_COMPRESS) | Pow(O_ADRESSEN) | Pow(O_STATISTICS);
f->no = unused_faction_id(); f->no = unused_faction_id();
register_faction_id(f->no);
addlist(&factions, f); addlist(&factions, f);
fhash(f); fhash(f);

View File

@ -76,7 +76,6 @@ typedef struct faction {
int num_total; /* Anzahl Personen mit Monstern */ int num_total; /* Anzahl Personen mit Monstern */
int options; int options;
int no_units; int no_units;
int karma;
struct ally *allies; struct ally *allies;
struct group *groups; struct group *groups;
boolean alive; /* enno: sollte ein flag werden */ boolean alive; /* enno: sollte ein flag werden */
@ -84,6 +83,9 @@ typedef struct faction {
int money; int money;
#ifdef SCORE_MODULE #ifdef SCORE_MODULE
int score; int score;
#endif
#ifdef KARMA_MODULE
int karma;
#endif #endif
struct alliance * alliance; struct alliance * alliance;
#ifdef VICTORY_DELAY #ifdef VICTORY_DELAY

View File

@ -68,6 +68,7 @@ attrib_type at_jihad = {
"jihad", NULL, NULL, NULL, a_writeshorts, a_readshorts "jihad", NULL, NULL, NULL, a_writeshorts, a_readshorts
}; };
#ifdef KARMA_MODULE
struct fspecialdata fspecials[MAXFACTIONSPECIALS] = { struct fspecialdata fspecials[MAXFACTIONSPECIALS] = {
{ {
"Regeneration", "Regeneration",
@ -352,13 +353,11 @@ buy_special(unit *u, struct order * ord, fspecial_t special)
int int
fspecial(const faction *f, fspecial_t special) fspecial(const faction *f, fspecial_t special)
{ {
#ifdef KARMA_MODULE
attrib *a; attrib *a;
for (a=a_find(f->attribs, &at_faction_special); a; a=a->nexttype) { for (a=a_find(f->attribs, &at_faction_special); a; a=a->nexttype) {
if(a->data.sa[0] == special) return a->data.sa[1]; if(a->data.sa[0] == special) return a->data.sa[1];
} }
#endif
return 0; return 0;
} }
@ -604,3 +603,4 @@ karma(void)
parse(K_SETJIHAD, jihad_cmd, false); parse(K_SETJIHAD, jihad_cmd, false);
parse(K_SACRIFICE, sacrifice_cmd, true); parse(K_SACRIFICE, sacrifice_cmd, true);
} }
#endif

View File

@ -16,8 +16,6 @@
extern "C" { extern "C" {
#endif #endif
struct faction;
typedef enum { typedef enum {
FS_REGENERATION, FS_REGENERATION,
FS_URBAN, FS_URBAN,
@ -44,18 +42,18 @@ typedef enum {
MAXFACTIONSPECIALS MAXFACTIONSPECIALS
} fspecial_t; } fspecial_t;
#ifdef KARMA_MODULE
typedef enum { typedef enum {
PR_AID, PR_AID,
PR_MERCY, PR_MERCY,
MAXPRAYEREFFECTS MAXPRAYEREFFECTS
} prayereffect_t; } prayereffect_t;
typedef struct fspecialdata fspecialdata; typedef struct fspecialdata {
struct fspecialdata {
const char *name; const char *name;
const char *description; const char *description;
const short maxlevel; const short maxlevel;
}; } fspecialdata;
extern struct attrib_type at_faction_special; extern struct attrib_type at_faction_special;
extern struct attrib_type at_prayer_timeout; extern struct attrib_type at_prayer_timeout;
@ -67,7 +65,6 @@ extern struct attrib_type at_jihad;
extern struct fspecialdata fspecials[]; extern struct fspecialdata fspecials[];
extern int fspecial(const struct faction *f, fspecial_t special); extern int fspecial(const struct faction *f, fspecial_t special);
#ifdef KARMA_MODULE
extern void karma(void); extern void karma(void);
extern int jihad(struct faction *, const struct race *); extern int jihad(struct faction *, const struct race *);
extern void jihad_attacks(void); extern void jihad_attacks(void);

View File

@ -418,9 +418,12 @@ updatespelllist(unit * u)
/* Nur Wyrm-Magier bekommen den Wyrmtransformationszauber */ /* Nur Wyrm-Magier bekommen den Wyrmtransformationszauber */
sp = find_spellbyid(M_GRAU, SPL_BECOMEWYRM); sp = find_spellbyid(M_GRAU, SPL_BECOMEWYRM);
#ifdef KARMA_MODULE
if (fspecial(u->faction, FS_WYRM) && !has_spell(u, sp) && sp->level<=sk) { if (fspecial(u->faction, FS_WYRM) && !has_spell(u, sp) && sp->level<=sk) {
add_spell(mage, find_spellbyid(M_GRAU, SPL_BECOMEWYRM)); add_spell(mage, find_spellbyid(M_GRAU, SPL_BECOMEWYRM));
} }
#endif /* KARMA_MODULE */
/* Transformierte Wyrm-Magier bekommen Drachenodem */ /* Transformierte Wyrm-Magier bekommen Drachenodem */
if (dragonrace(u->race)) { if (dragonrace(u->race)) {
@ -1159,8 +1162,9 @@ target_resists_magic(unit *magician, void *obj, int objtyp, int t_bonus)
skill * sv; skill * sv;
unit * u = (unit*)obj; unit * u = (unit*)obj;
#ifdef KARMA_MODULE
if (fspecial(u->faction, FS_MAGICIMMUNE)) return true; if (fspecial(u->faction, FS_MAGICIMMUNE)) return true;
#endif /* KARMA_MODULE */
at = effskill(magician, SK_MAGIC); at = effskill(magician, SK_MAGIC);
for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) { for (sv = u->skills; sv != u->skills + u->skill_size; ++sv) {
@ -1396,7 +1400,9 @@ regeneration(unit * u)
double potenz = 1.5; double potenz = 1.5;
double divisor = 2.0; double divisor = 2.0;
#ifdef KARMA_MODULE
if (fspecial(u->faction, FS_MAGICIMMUNE)) return 0; if (fspecial(u->faction, FS_MAGICIMMUNE)) return 0;
#endif /* KARMA_MODULE */
sk = effskill(u, SK_MAGIC); sk = effskill(u, SK_MAGIC);
/* Rassenbonus/-malus */ /* Rassenbonus/-malus */

View File

@ -210,8 +210,10 @@ personcapacity(const unit *u)
{ {
int cap = u->race->weight+u->race->capacity; int cap = u->race->weight+u->race->capacity;
#ifdef KARMA_MODULE
if (fspecial(u->faction, FS_QUICK)) if (fspecial(u->faction, FS_QUICK))
cap -= 200; cap -= 200;
#endif /* KARMA_MODULE */
return cap; return cap;
} }
@ -391,8 +393,9 @@ canswim(unit *u)
if (get_item(u, I_DOLPHIN) >= u->number && effskill(u, SK_RIDING) >= 4) if (get_item(u, I_DOLPHIN) >= u->number && effskill(u, SK_RIDING) >= 4)
return true; return true;
#ifdef KARMA_MODULE
if (fspecial(u->faction, FS_AMPHIBIAN)) return true; if (fspecial(u->faction, FS_AMPHIBIAN)) return true;
#endif /* KARMA_MODULE */
if (u->race->flags & RCF_FLY) return true; if (u->race->flags & RCF_FLY) return true;
if (u->race->flags & RCF_SWIM) return true; if (u->race->flags & RCF_SWIM) return true;
@ -1259,8 +1262,10 @@ movement_speed(unit * u)
default: default:
mp = BP_WALKING; mp = BP_WALKING;
#ifdef KARMA_MODULE
/* faction special */ /* faction special */
if (fspecial(u->faction, FS_QUICK)) mp = BP_RIDING; if (fspecial(u->faction, FS_QUICK)) mp = BP_RIDING;
#endif /* KARMA_MODULE */
/* Siebenmeilentee */ /* Siebenmeilentee */
if (!fval(u->region->terrain, SEA_REGION) && get_effect(u, oldpotiontype[P_FAST]) >= u->number) { if (!fval(u->region->terrain, SEA_REGION) && get_effect(u, oldpotiontype[P_FAST]) >= u->number) {

View File

@ -207,9 +207,11 @@ unit_max_hp(const unit * u)
p = pow(effskill(u, SK_AUSDAUER) / 2.0, 1.5) * 0.2; p = pow(effskill(u, SK_AUSDAUER) / 2.0, 1.5) * 0.2;
h += (int) (h * p + 0.5); h += (int) (h * p + 0.5);
#ifdef KARMA_MODULE
if (fspecial(u->faction, FS_UNDEAD)) { if (fspecial(u->faction, FS_UNDEAD)) {
h *= 2; h *= 2;
} }
#endif /* KARMA_MODULE */
/* der healing curse verändert die maximalen hp */ /* der healing curse verändert die maximalen hp */
if (heal_ct) { if (heal_ct) {

View File

@ -203,7 +203,7 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
const char *pzTmp; const char *pzTmp;
building * b; building * b;
boolean isbattle = (boolean)(mode == see_battle); boolean isbattle = (boolean)(mode == see_battle);
int telepath_see = fspecial(f, FS_TELEPATHY); int telepath_see = 0;
attrib *a_fshidden = NULL; attrib *a_fshidden = NULL;
item * itm; item * itm;
item * show; item * show;
@ -222,8 +222,12 @@ bufunit(const faction * f, const unit * u, int indent, int mode)
itemcloak = curse_active(get_curse(u->attribs, itemcloak_ct)); itemcloak = curse_active(get_curse(u->attribs, itemcloak_ct));
} }
if (fspecial(u->faction, FS_HIDDEN)) #ifdef KARMA_MODULE
if (fspecial(u->faction, FS_HIDDEN)) {
a_fshidden = a_find(u->attribs, &at_fshidden); a_fshidden = a_find(u->attribs, &at_fshidden);
}
telepath_see = fspecial(f, FS_TELEPATHY);
#endif /* KARMA_MODULE */
rsize = strlcpy(bufp, unitname(u), size); rsize = strlcpy(bufp, unitname(u), size);
if (rsize>size) rsize = size-1; if (rsize>size) rsize = size-1;

View File

@ -1528,7 +1528,14 @@ readfaction(FILE * F)
convertunique(f); convertunique(f);
#endif #endif
f->magiegebiet = (magic_t)ri(F); f->magiegebiet = (magic_t)ri(F);
#ifdef KARMA_MODULE
f->karma = ri(F); f->karma = ri(F);
#else
/* ignore karma */
ri(F);
#endif /* KARMA_MODULE */
f->flags = ri(F); f->flags = ri(F);
freset(f, FFL_OVERRIDE); freset(f, FFL_OVERRIDE);
@ -1620,7 +1627,12 @@ writefaction(FILE * F, const faction * f)
ws(F, f->race->_name[0]); ws(F, f->race->_name[0]);
wnl(F); wnl(F);
wi(F, f->magiegebiet); wi(F, f->magiegebiet);
#ifdef KARMA_MODULE
wi(F, f->karma); wi(F, f->karma);
#else
wi(F, 0);
#endif /* KARMA_MODULE */
wi(F, f->flags); wi(F, f->flags);
a_write(F, f->attribs); a_write(F, f->attribs);
wnl(F); wnl(F);
@ -1663,7 +1675,7 @@ readgame(const char * filename, int backup)
faction *f, **fp; faction *f, **fp;
region *r; region *r;
building *b, **bp; building *b, **bp;
ship *sh, **shp; ship **shp;
unit *u; unit *u;
FILE * F; FILE * F;
int rmax = maxregions; int rmax = maxregions;
@ -1752,18 +1764,18 @@ readgame(const char * filename, int backup)
while (--n >= 0) { while (--n >= 0) {
faction * f = readfaction(F); faction * f = readfaction(F);
addlist2(fp, f);
*fp = f;
fp = &f->next;
fhash(f); fhash(f);
} }
*fp = 0; *fp = 0;
/* Benutzte Faction-Ids */ /* Benutzte Faction-Ids */
no_used_faction_ids = ri(F); i = ri(F);
/* used_faction_ids = gc_add(malloc(no_used_faction_ids*sizeof(int))); */ while (i--) {
used_faction_ids = malloc(no_used_faction_ids*sizeof(int)); ri(F); /* used faction ids. ignore. */
for(i=0; i < no_used_faction_ids; i++) {
used_faction_ids[i] = ri(F);
} }
/* Regionen */ /* Regionen */
@ -1795,7 +1807,7 @@ readgame(const char * filename, int backup)
if (dirtyload) break; if (dirtyload) break;
skip = true; skip = true;
} }
if ((n%1024)==0) { /* das spart extrem Zeit */ if ((n & 0x3FF) == 0) { /* das spart extrem Zeit */
printf(" - Einzulesende Regionen: %d/%d ", rmax, n); printf(" - Einzulesende Regionen: %d/%d ", rmax, n);
printf("* %d,%d \r", x, y); printf("* %d,%d \r", x, y);
} }
@ -1818,6 +1830,8 @@ readgame(const char * filename, int backup)
b = (building *) calloc(1, sizeof(building)); b = (building *) calloc(1, sizeof(building));
b->no = rid(F); b->no = rid(F);
*bp = b;
bp = &b->next;
bhash(b); bhash(b);
rds(F, &b->name); rds(F, &b->name);
if (lomem) rds(F, 0); if (lomem) rds(F, 0);
@ -1837,7 +1851,6 @@ readgame(const char * filename, int backup)
} }
b->region = r; b->region = r;
a_read(F, &b->attribs); a_read(F, &b->attribs);
addlist2(bp, b);
} }
/* Schiffe */ /* Schiffe */
@ -1845,10 +1858,11 @@ readgame(const char * filename, int backup)
shp = &r->ships; shp = &r->ships;
while (--p >= 0) { while (--p >= 0) {
sh = (ship *) calloc(1, sizeof(ship)); ship * sh = (ship *) calloc(1, sizeof(ship));
sh->region = r; sh->region = r;
sh->no = rid(F); sh->no = rid(F);
*shp = sh;
shp = &sh->next;
shash(sh); shash(sh);
rds(F, &sh->name); rds(F, &sh->name);
if (lomem) rds(F, 0); if (lomem) rds(F, 0);
@ -1868,8 +1882,6 @@ readgame(const char * filename, int backup)
sh->coast = (direction_t)ri(F); sh->coast = (direction_t)ri(F);
a_read(F, &sh->attribs); a_read(F, &sh->attribs);
addlist2(shp, sh);
} }
*shp = 0; *shp = 0;
@ -1882,9 +1894,12 @@ readgame(const char * filename, int backup)
while (--p >= 0) { while (--p >= 0) {
unit * u = readunit(F); unit * u = readunit(F);
sc_mage * mage; sc_mage * mage;
assert(u->region==NULL); assert(u->region==NULL);
u->region = r; u->region = r;
addlist2(up,u); *up = u;
up = &u->next;
update_interval(u->faction, u->region); update_interval(u->faction, u->region);
mage = get_mage(u); mage = get_mage(u);
if (mage && mage->spellcount<0) { if (mage && mage->spellcount<0) {
@ -1943,7 +1958,7 @@ int
writegame(const char *filename, char quiet) writegame(const char *filename, char quiet)
{ {
char *base; char *base;
int i,n; int n;
faction *f; faction *f;
region *r; region *r;
building *b; building *b;
@ -2035,14 +2050,7 @@ writegame(const char *filename, char quiet)
writefaction(F, f); writefaction(F, f);
} }
wi(F, no_used_faction_ids); wi(F, 0); /* used faction ids. old stuff */
wnl(F);
for(i=0; i<no_used_faction_ids; i++) {
wi(F, used_faction_ids[i]);
wnl(F);
}
wnl(F); wnl(F);
/* Write regions */ /* Write regions */

View File

@ -1124,6 +1124,7 @@ get_modifier(const unit *u, skill_t sk, int level, const region *r, boolean noit
} }
skill = skillmod(u->attribs, u, r, sk, skill, SMF_ALWAYS); skill = skillmod(u->attribs, u, r, sk, skill, SMF_ALWAYS);
#ifdef KARMA_MODULE
if (fspecial(u->faction, FS_TELEPATHY)) { if (fspecial(u->faction, FS_TELEPATHY)) {
switch(sk) { switch(sk) {
case SK_ALCHEMY: case SK_ALCHEMY:
@ -1137,6 +1138,7 @@ get_modifier(const unit *u, skill_t sk, int level, const region *r, boolean noit
skill -= 2; skill -= 2;
} }
} }
#endif
#ifdef HUNGER_REDUCES_SKILL #ifdef HUNGER_REDUCES_SKILL
if (fval(u, UFL_HUNGER)) { if (fval(u, UFL_HUNGER)) {

View File

@ -7046,9 +7046,10 @@ sp_destroy_curse(castorder *co)
int int
sp_becomewyrm(castorder *co) sp_becomewyrm(castorder *co)
{ {
#ifdef KARMA_MODULE
unit *u = co->magician.u; unit *u = co->magician.u;
int wyrms_already_created = 0; int wyrms_already_created = 0;
int wyrms_allowed; int wyrms_allowed = 0;
attrib *a; attrib *a;
wyrms_allowed = fspecial(u->faction, FS_WYRM); wyrms_allowed = fspecial(u->faction, FS_WYRM);
@ -7073,6 +7074,9 @@ sp_becomewyrm(castorder *co)
ADDMSG(&u->faction->msgs, msg_message("becomewyrm", "u", u)); ADDMSG(&u->faction->msgs, msg_message("becomewyrm", "u", u));
return co->level; return co->level;
#else
return 0;
#endif /* KARMA_MODULE */
} }
/* ------------------------------------------------------------- */ /* ------------------------------------------------------------- */

View File

@ -310,7 +310,6 @@ game_done(void)
faction *f, *f2; faction *f, *f2;
ship *s, *s2; ship *s, *s2;
free(used_faction_ids);
for (r = regions; r; r = r2) { for (r = regions; r; r = r2) {
for (u = r->units; u; u = u2) { for (u = r->units; u; u = u2) {
u2 = u->next; u2 = u->next;

View File

@ -356,8 +356,6 @@ game_done(void)
* nicht freigegebenem Speicher sucht, der nicht bis zum Ende benötigt * nicht freigegebenem Speicher sucht, der nicht bis zum Ende benötigt
* wird (temporäre Hilsstrukturen) */ * wird (temporäre Hilsstrukturen) */
free(used_faction_ids);
while (regions) { while (regions) {
region *r = regions; region *r = regions;
regions = r->next; regions = r->next;

View File

@ -1525,7 +1525,6 @@ makemonsters(void)
factions=f; factions=f;
f->options = Pow(O_REPORT); f->options = Pow(O_REPORT);
f->no=MONSTER_FACTION; f->no=MONSTER_FACTION;
register_faction_id(f->no);
f->subscription = 0; f->subscription = 0;
f->name=strdup("Monster"); f->name=strdup("Monster");
f->passw=strdup("abc123"); f->passw=strdup("abc123");