- region flag that speeds up access to at_travelunit

- unit flag that speeds up access to at_guard
- test for at_npcfaction only when AllianceRestricted.
This commit is contained in:
Enno Rehling 2005-06-11 23:02:52 +00:00
parent 01fd653508
commit c5846b0990
14 changed files with 135 additions and 109 deletions

View File

@ -1443,7 +1443,7 @@ report_computer(FILE * F, faction * f, struct seen_region ** seen, const faction
/* describe both passed and inhabited regions */ /* describe both passed and inhabited regions */
show_active_spells(r); show_active_spells(r);
{ if (fval(r, RF_TRAVELUNIT)) {
boolean seeunits = false, seeships = false; boolean seeunits = false, seeships = false;
const attrib * ru; const attrib * ru;
/* show units pulled through region */ /* show units pulled through region */

View File

@ -1434,24 +1434,26 @@ static void
durchreisende(FILE * F, const region * r, const faction * f) durchreisende(FILE * F, const region * r, const faction * f)
{ {
attrib *ru; attrib *ru;
int wieviele; int maxtravel;
int counter; int counter;
wieviele = counter = 0; maxtravel = counter = 0;
/* Wieviele sind aufzulisten? Für die Grammatik. */ /* Wieviele sind aufzulisten? Für die Grammatik. */
for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) { if (fval(r, RF_TRAVELUNIT)) {
unit * u = (unit*)ru->data.v; for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) {
if (cansee_durchgezogen(f, r, u, 0) > 0 && r!=u->region) { unit * u = (unit*)ru->data.v;
if (u->ship && !fval(u, UFL_OWNER)) if (cansee_durchgezogen(f, r, u, 0) > 0 && r!=u->region) {
continue; if (u->ship && !fval(u, UFL_OWNER))
wieviele++; continue;
} maxtravel++;
} }
}
if (!wieviele) if (!maxtravel)
return; return;
} else return;
/* Auflisten. */ /* Auflisten. */
@ -1474,15 +1476,15 @@ durchreisende(FILE * F, const region * r, const faction * f)
} else { } else {
scat(unitname(u)); scat(unitname(u));
} }
if (counter + 1 < wieviele) { if (counter + 1 < maxtravel) {
scat(", "); scat(", ");
} else if (counter + 1 == wieviele) { } else if (counter + 1 == maxtravel) {
scat(" und "); scat(" und ");
} }
} }
} }
if (wieviele == 1) { if (maxtravel == 1) {
scat(" hat die Region durchquert."); scat(" hat die Region durchquert.");
rparagraph(F, buf, 0, 0); rparagraph(F, buf, 0, 0);
} else { } else {
@ -2636,11 +2638,13 @@ prepare_report(faction * f)
free_regionlist(rlist); free_regionlist(rlist);
} }
if (mode<see_travel) for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) { if (mode<see_travel && fval(r, RF_TRAVELUNIT)) {
unit * u = (unit*)ru->data.v; for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) {
if (u->faction == f) { unit * u = (unit*)ru->data.v;
mode = see_travel; if (u->faction == f) {
break; mode = see_travel;
break;
}
} }
} }

View File

@ -689,39 +689,39 @@ weapon_effskill(troop t, troop enemy, const weapon * w, boolean attacking, boole
int skill; int skill;
const weapon_type * wtype = w?w->type:NULL; const weapon_type * wtype = w?w->type:NULL;
if (wtype==NULL) { if (wtype==NULL) {
/* Ohne Waffe: Waffenlose Angriffe */ /* Ohne Waffe: Waffenlose Angriffe */
skill = weapon_skill(NULL, tu, attacking); skill = weapon_skill(NULL, tu, attacking);
} else { } else {
if (attacking) { if (attacking) {
skill = w->attackskill; skill = w->attackskill;
} else { } else {
skill = w->defenseskill; skill = w->defenseskill;
} }
if (wtype->modifiers!=NULL) { if (wtype->modifiers!=NULL) {
/* Pferdebonus, Lanzenbonus, usw. */ /* Pferdebonus, Lanzenbonus, usw. */
int m; int m;
unsigned int flags = WMF_SKILL|(attacking?WMF_OFFENSIVE:WMF_DEFENSIVE); unsigned int flags = WMF_SKILL|(attacking?WMF_OFFENSIVE:WMF_DEFENSIVE);
if (riding(t)) flags |= WMF_RIDING; if (riding(t)) flags |= WMF_RIDING;
else flags |= WMF_WALKING; else flags |= WMF_WALKING;
if (riding(enemy)) flags |= WMF_AGAINST_RIDING; if (riding(enemy)) flags |= WMF_AGAINST_RIDING;
else flags |= WMF_AGAINST_WALKING; else flags |= WMF_AGAINST_WALKING;
for (m=0;wtype->modifiers[m].value;++m) { for (m=0;wtype->modifiers[m].value;++m) {
if ((wtype->modifiers[m].flags & flags) == flags) { if ((wtype->modifiers[m].flags & flags) == flags) {
race_list * rlist = wtype->modifiers[m].races; race_list * rlist = wtype->modifiers[m].races;
if (rlist!=NULL) { if (rlist!=NULL) {
while (rlist) { while (rlist) {
if (rlist->data == tu->race) break; if (rlist->data == tu->race) break;
rlist = rlist->next; rlist = rlist->next;
} }
if (rlist==NULL) continue; if (rlist==NULL) continue;
} }
skill += wtype->modifiers[m].value; skill += wtype->modifiers[m].value;
} }
} }
} }
} }
/* Burgenbonus, Pferdebonus */ /* Burgenbonus, Pferdebonus */

View File

@ -978,20 +978,21 @@ int
alliedgroup(const struct plane * pl, const struct faction * f, alliedgroup(const struct plane * pl, const struct faction * f,
const struct faction * f2, const struct ally * sf, int mode) const struct faction * f2, const struct ally * sf, int mode)
{ {
attrib *a;
while (sf && sf->faction!=f2) sf=sf->next; while (sf && sf->faction!=f2) sf=sf->next;
if (sf==NULL) { if (sf==NULL) {
mode = mode & autoalliance(pl, f, f2); mode = mode & autoalliance(pl, f, f2);
} }
mode = ally_mode(sf, mode) | (mode & autoalliance(pl, f, f2)); mode = ally_mode(sf, mode) | (mode & autoalliance(pl, f, f2));
if((a = a_find(f->attribs, &at_npcfaction)) != NULL) { if (AllianceRestricted()) {
return mode; if (a_findc(f->attribs, &at_npcfaction)) {
} return mode;
if((a = a_find(f2->attribs, &at_npcfaction)) != NULL) { }
return mode; if (a_findc(f2->attribs, &at_npcfaction)) {
} return mode;
if (AllianceRestricted() && f->alliance!=f2->alliance) { }
mode &= ~AllianceRestricted(); if (f->alliance!=f2->alliance) {
mode &= ~AllianceRestricted();
}
} }
return mode; return mode;
} }
@ -2152,14 +2153,16 @@ lastregion (faction * f)
if (f->last == r) continue; if (f->last == r) continue;
#endif #endif
/* search the region for travelthru-attributes: */ /* search the region for travelthru-attributes: */
for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) { if (fval(r, RF_TRAVELUNIT)) {
u = (unit*)ru->data.v; for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) {
if (u->faction == f) { u = (unit*)ru->data.v;
f->last = r; if (u->faction == f) {
break; f->last = r;
} break;
} }
if (f->last == r) continue; }
}
if (f->last == r) continue;
if (check_leuchtturm(r, f)) if (check_leuchtturm(r, f))
f->last = r; f->last = r;
if (p && is_watcher(p, f)) { if (p && is_watcher(p, f)) {
@ -2193,11 +2196,13 @@ firstregion (faction * f)
} }
if (f->first == r->next) if (f->first == r->next)
continue; continue;
for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) { if (fval(r, RF_TRAVELUNIT)) {
u = (unit*)ru->data.v; for (ru = a_find(r->attribs, &at_travelunit); ru; ru = ru->nexttype) {
if (u->faction == f) { u = (unit*)ru->data.v;
return f->first = r; if (u->faction == f) {
} return f->first = r;
}
}
} }
if (check_leuchtturm(r, f)) { if (check_leuchtturm(r, f)) {
return f->first = r; return f->first = r;
@ -2452,7 +2457,7 @@ attrib_type at_germs = {
/*********************/ /*********************/
/* at_guard */ /* at_guard */
/*********************/ /*********************/
static attrib_type at_guard = { attrib_type at_guard = {
"guard", "guard",
DEFAULT_INIT, DEFAULT_INIT,
DEFAULT_FINALIZE, DEFAULT_FINALIZE,
@ -2466,11 +2471,16 @@ void
setguard(unit * u, unsigned int flags) setguard(unit * u, unsigned int flags)
{ {
/* setzt die guard-flags der Einheit */ /* setzt die guard-flags der Einheit */
attrib * a = a_find(u->attribs, &at_guard); attrib * a = NULL;
if(flags == GUARD_NONE) { if (fval(u, UFL_GUARD)) {
if(a) a_remove(&u->attribs, a); a = a_find(u->attribs, &at_guard);
}
if (flags == GUARD_NONE) {
freset(u, UFL_GUARD);
if (a) a_remove(&u->attribs, a);
return; return;
} }
fset(u, UFL_GUARD);
if (!a) a = a_add(&u->attribs, a_new(&at_guard)); if (!a) a = a_add(&u->attribs, a_new(&at_guard));
a->data.i = (int)flags; a->data.i = (int)flags;
} }
@ -2478,11 +2488,12 @@ setguard(unit * u, unsigned int flags)
unsigned int unsigned int
getguard(const unit * u) getguard(const unit * u)
{ {
attrib *a;
if(u->region->terrain == T_OCEAN) return GUARD_NONE; if (u->region->terrain == T_OCEAN) return GUARD_NONE;
a = a_find(u->attribs, &at_guard); if (fval(u, UFL_GUARD)) {
if (a) return (unsigned int)a->data.i; attrib * a = a_find(u->attribs, &at_guard);
if (a) return (unsigned int)a->data.i;
}
return GUARD_NONE; return GUARD_NONE;
} }

View File

@ -1187,6 +1187,7 @@ extern int entertainmoney(const struct region * r);
extern int freadstr(FILE * F, char * str, size_t size); extern int freadstr(FILE * F, char * str, size_t size);
extern int fwritestr(FILE * F, const char * str); extern int fwritestr(FILE * F, const char * str);
extern attrib_type at_guard;
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -498,6 +498,8 @@ travelthru(const unit * u, region * r)
{ {
attrib *ru = a_add(&r->attribs, a_new(&at_travelunit)); attrib *ru = a_add(&r->attribs, a_new(&at_travelunit));
fset(r, RF_TRAVELUNIT);
ru->data.v = (void*)u; ru->data.v = (void*)u;
/* the first and last region of the faction gets reset, because travelthrough /* the first and last region of the faction gets reset, because travelthrough

View File

@ -50,6 +50,9 @@ extern "C" {
#define RF_DH (1<<18) #define RF_DH (1<<18)
/* flags that speed up attribute access: */
#define RF_TRAVELUNIT (1<<19)
#define RF_ALL 0xFFFFFF #define RF_ALL 0xFFFFFF
#define RF_SAVEMASK (RF_CHAOTIC|RF_MALLORN|RF_BLOCKED|RF_BLOCK_NORTHWEST|RF_BLOCK_NORTHEAST|RF_BLOCK_EAST|RF_BLOCK_SOUTHEAST|RF_BLOCK_SOUTHWEST|RF_BLOCK_WEST|RF_ENCOUNTER|RF_ORCIFIED) #define RF_SAVEMASK (RF_CHAOTIC|RF_MALLORN|RF_BLOCKED|RF_BLOCK_NORTHWEST|RF_BLOCK_NORTHEAST|RF_BLOCK_EAST|RF_BLOCK_SOUTHEAST|RF_BLOCK_SOUTHWEST|RF_BLOCK_WEST|RF_ENCOUNTER|RF_ORCIFIED)

View File

@ -1038,7 +1038,7 @@ get_modifier(const unit *u, skill_t sk, int level, const region *r, boolean noit
skill += rc_skillmod(u->race, r, sk); skill += rc_skillmod(u->race, r, sk);
skill += att_modification(u, sk); skill += att_modification(u, sk);
if(noitem == false) { if (noitem == false) {
skill = item_modification(u, sk, skill); skill = item_modification(u, sk, skill);
} }
skill = skillmod(u->attribs, u, r, sk, skill, SMF_ALWAYS); skill = skillmod(u->attribs, u, r, sk, skill, SMF_ALWAYS);

View File

@ -57,11 +57,14 @@ struct skill;
#define UFL_ORDERS (1<<24) /* Einheit hat Befehle erhalten */ #define UFL_ORDERS (1<<24) /* Einheit hat Befehle erhalten */
#define UFL_TAKEALL (1<<25) /* Einheit nimmt alle Gegenstände an */ #define UFL_TAKEALL (1<<25) /* Einheit nimmt alle Gegenstände an */
/* flags that speed up attribute access: */
#define UFL_GUARD (1<<27)
/* Flags, die gespeichert werden sollen: */ /* Flags, die gespeichert werden sollen: */
#ifndef HEROES #ifndef HEROES
# define UFL_SAVEMASK (UFL_MOVED | UFL_NOAID | UFL_OWNER | UFL_PARTEITARNUNG | UFL_LOCKED | UFL_HUNGER | UFL_TAKEALL) # define UFL_SAVEMASK (UFL_MOVED | UFL_NOAID | UFL_OWNER | UFL_PARTEITARNUNG | UFL_LOCKED | UFL_HUNGER | UFL_TAKEALL | UFL_GUARD)
#else #else
# define UFL_SAVEMASK (UFL_MOVED | UFL_NOAID | UFL_OWNER | UFL_PARTEITARNUNG | UFL_LOCKED | UFL_HUNGER | UFL_TAKEALL | UFL_HERO) # define UFL_SAVEMASK (UFL_MOVED | UFL_NOAID | UFL_OWNER | UFL_PARTEITARNUNG | UFL_LOCKED | UFL_HUNGER | UFL_TAKEALL | UFL_GUARD | UFL_HERO)
#endif #endif
#define UNIT_MAXSIZE 50000 #define UNIT_MAXSIZE 50000

View File

@ -1012,6 +1012,25 @@ nothing(void)
return 0; return 0;
} }
static int
fix_attribflags(void)
{
region * r;
for (r = regions; r; r=r->next) {
unit * u = r->units;
for (u=r->units;u!=NULL;u=u->next) {
const attrib *a = r->attribs;
while (a) {
if (a->type!=&at_guard) {
fset(u, UFL_GUARD);
}
a = a->next;
return a;
}
}
}
}
static int static int
fix_chaosgates(void) fix_chaosgates(void)
{ {
@ -1051,6 +1070,7 @@ korrektur(void)
} }
do_once("chgt", fix_chaosgates()); do_once("chgt", fix_chaosgates());
do_once("attr", fix_attribflags());
fix_astralplane(); fix_astralplane();
fix_firewalls(); fix_firewalls();
fix_gates(); fix_gates();
@ -1092,13 +1112,3 @@ korrektur(void)
enable_fuzzy = true; enable_fuzzy = true;
#endif #endif
} }
void
korrektur_end(void)
{
}
void
init_conversion(void)
{
}

View File

@ -14,8 +14,7 @@ extern "C" {
#endif #endif
extern void korrektur(void); extern void korrektur(void);
extern void korrektur_end(void);
extern void init_conversion(void);
#ifdef __cplusplus #ifdef __cplusplus
} }
#endif #endif

View File

@ -2,6 +2,7 @@
#include <eressea.h> #include <eressea.h>
#include "script.h" #include "script.h"
#include "../korrektur.h"
#include <attributes/key.h> #include <attributes/key.h>
#include <modules/autoseed.h> #include <modules/autoseed.h>
@ -52,7 +53,10 @@ get_turn(void)
static int static int
read_game(const char * filename) read_game(const char * filename)
{ {
return readgame(filename, false); int rv = readgame(filename, false);
printf(" - Korrekturen Runde %d\n", turn);
korrektur();
return rv;
} }
static int static int

View File

@ -27,8 +27,6 @@
#include <config.h> #include <config.h>
#include "eressea.h" #include "eressea.h"
#include "korrektur.h"
/* initialization - TODO: init in separate module */ /* initialization - TODO: init in separate module */
#include <attributes/attributes.h> #include <attributes/attributes.h>
#include <spells/spells.h> #include <spells/spells.h>
@ -198,7 +196,6 @@ game_init(void)
#ifdef INFOCMD_MODULE #ifdef INFOCMD_MODULE
init_info(); init_info();
#endif #endif
init_conversion();
#ifdef MUSEUM_MODULE #ifdef MUSEUM_MODULE
register_museum(); register_museum();
@ -267,8 +264,6 @@ processturn(char *filename)
readshortpwds("passwords"); readshortpwds("passwords");
#endif #endif
begin = make_summary(); begin = make_summary();
printf(" - Korrekturen Runde %d\n", turn);
korrektur();
turn++; turn++;
if ((i=readorders(filename))!=0) return i; if ((i=readorders(filename))!=0) return i;
if (!nomonsters) { if (!nomonsters) {
@ -288,7 +283,6 @@ processturn(char *filename)
} }
score(); score();
remove_unequipped_guarded(); remove_unequipped_guarded();
korrektur_end();
if (!noreports) reports(); if (!noreports) reports();
free_units(); free_units();
puts(" - Beseitige leere Parteien"); puts(" - Beseitige leere Parteien");

View File

@ -28,7 +28,6 @@
#include <config.h> #include <config.h>
#include <eressea.h> #include <eressea.h>
#include "korrektur.h"
#include "console.h" #include "console.h"
/* initialization - TODO: init in separate module */ /* initialization - TODO: init in separate module */
@ -243,7 +242,6 @@ game_init(void)
#ifdef INFOCMD_MODULE #ifdef INFOCMD_MODULE
init_info(); init_info();
#endif #endif
init_conversion();
#ifdef REMOVE_THIS #ifdef REMOVE_THIS
render_init(); render_init();
@ -361,13 +359,10 @@ process_orders()
#ifdef SHORTPWDS #ifdef SHORTPWDS
readshortpwds("passwords"); readshortpwds("passwords");
#endif #endif
printf(" - Korrekturen Runde %d\n", turn);
korrektur();
turn++; turn++;
processorders(); processorders();
score(); score();
remove_unequipped_guarded(); remove_unequipped_guarded();
korrektur_end();
update_subscriptions(); update_subscriptions();
return 0; return 0;