- 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 */
show_active_spells(r);
{
if (fval(r, RF_TRAVELUNIT)) {
boolean seeunits = false, seeships = false;
const attrib * ru;
/* show units pulled through region */

View File

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

View File

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

View File

@ -498,6 +498,8 @@ travelthru(const unit * u, region * r)
{
attrib *ru = a_add(&r->attribs, a_new(&at_travelunit));
fset(r, RF_TRAVELUNIT);
ru->data.v = (void*)u;
/* 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)
/* flags that speed up attribute access: */
#define RF_TRAVELUNIT (1<<19)
#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)

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 += att_modification(u, sk);
if(noitem == false) {
if (noitem == false) {
skill = item_modification(u, sk, skill);
}
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_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: */
#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
# 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
#define UNIT_MAXSIZE 50000

View File

@ -1012,6 +1012,25 @@ nothing(void)
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
fix_chaosgates(void)
{
@ -1051,6 +1070,7 @@ korrektur(void)
}
do_once("chgt", fix_chaosgates());
do_once("attr", fix_attribflags());
fix_astralplane();
fix_firewalls();
fix_gates();
@ -1092,13 +1112,3 @@ korrektur(void)
enable_fuzzy = true;
#endif
}
void
korrektur_end(void)
{
}
void
init_conversion(void)
{
}

View File

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

View File

@ -2,6 +2,7 @@
#include <eressea.h>
#include "script.h"
#include "../korrektur.h"
#include <attributes/key.h>
#include <modules/autoseed.h>
@ -52,7 +53,10 @@ get_turn(void)
static int
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

View File

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

View File

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