From cc21a19831e6eb1b5a19dea527d1a7a6cb84918f Mon Sep 17 00:00:00 2001 From: Enno Rehling Date: Sun, 30 May 2004 12:09:45 +0000 Subject: [PATCH] setting RF_COMBATDEBUG (bit 14) in a region triggers a summary of the weapons/skills in the battle --- src/common/kernel/battle.c | 58 +++++++++++++++++++ src/common/kernel/battle.h | 2 +- src/common/kernel/region.h | 111 +++++++++++++++++++------------------ src/eressea/lua/region.cpp | 16 ++++++ 4 files changed, 132 insertions(+), 55 deletions(-) diff --git a/src/common/kernel/battle.c b/src/common/kernel/battle.c index f5a5bada3..8d0d450e1 100644 --- a/src/common/kernel/battle.c +++ b/src/common/kernel/battle.c @@ -3581,6 +3581,62 @@ init_battle(region * r, battle **bp) return fighting; } +static void +battle_stats(FILE * F, battle * b) +{ + typedef struct stat_info { + struct stat_info * next; + weapon * wp; + int level; + int number; + } stat_info; + side * s; + cv_foreach(s, b->sides) { + fighter * df; + stat_info * stats = NULL, * stat; + cv_foreach(df, s->fighters) { + unit *du = df->unit; + troop dt; + stat_info * slast = NULL; + + dt.fighter = df; + for (dt.index=0;dt.index!=du->number;++dt.index) { + weapon * wp = preferred_weapon(dt, true); + int level = wp->attackskill; + stat_info ** slist = &stats; + + if (slast && slast->wp==wp && slast->level==level) { + ++slast->number; + continue; + } + while (*slist && (*slist)->wp!=wp) { + slist = &(*slist)->next; + } + while (*slist && (*slist)->wp==wp && (*slist)->level>level) { + slist = &(*slist)->next; + } + stat = *slist; + if (stat->wp!=wp || stat->level!=level) { + stat = calloc(1, sizeof(stat_info)); + stat->wp = wp; + stat->level = level; + stat->next = *slist; + *slist = stat; + } + slast = stat; + ++slast->number; + } + } cv_next(df); + + fprintf(F, "##STATS## Heer %u - %s:\n", s->index, factionname(s->bf->faction)); + for (stat=stats;stat!=NULL;stat=stat->next) { + const weapon_type * wtype = stat->wp->type; + fprintf(F, "%s %u : %u\n", wtype->itype->rtype->_name[0], stat->level, stat->number); + } + freelist(stats); + } cv_next(s); +} + void do_battle(void) { @@ -3631,6 +3687,8 @@ do_battle(void) b->has_tactics_turn = false; } + if (b->region->flags & RF_COMBATDEBUG) battle_stats(bdebug, b); + /* PRECOMBATSPELLS */ do_combatmagic(b, DO_PRECOMBATSPELL); diff --git a/src/common/kernel/battle.h b/src/common/kernel/battle.h index 9b425031a..553633e30 100644 --- a/src/common/kernel/battle.h +++ b/src/common/kernel/battle.h @@ -78,7 +78,7 @@ extern "C" { # define E_ENEMY 1 # define E_ATTACKING 2 int enemy[128]; - struct side * enemies[128]; + struct side * enemies[128]; cvector fighters; /* vector der Einheiten dieser Fraktion */ int index; /* Eintrag der Fraktion in b->matrix/b->enemies */ int size[NUMROWS]; /* Anzahl Personen in Reihe X. 0 = Summe */ diff --git a/src/common/kernel/region.h b/src/common/kernel/region.h index 8b5ada99b..73003c1a0 100644 --- a/src/common/kernel/region.h +++ b/src/common/kernel/region.h @@ -1,7 +1,7 @@ /* vi: set ts=2: * - * - * Eressea PB(E)M host Copyright (C) 1998-2003 + * + * Eressea PB(E)M host Copyright (C) 1998-2003 * Christian Schlittchen (corwin@amber.kn-bremen.de) * Katja Zedel (katze@felidae.kn-bremen.de) * Henning Peters (faroul@beyond.kn-bremen.de) @@ -23,22 +23,25 @@ extern "C" { #define FAST_CONNECT -#define RF_CHAOTIC (1<<0) -#define RF_MALLORN (1<<1) -#define RF_BLOCKED (1<<2) +#define RF_CHAOTIC (1<<0) +#define RF_MALLORN (1<<1) +#define RF_BLOCKED (1<<2) -#define RF_BLOCK_NORTHWEST (1<<3) -#define RF_BLOCK_NORTHEAST (1<<4) -#define RF_BLOCK_EAST (1<<5) -#define RF_BLOCK_SOUTHEAST (1<<6) -#define RF_BLOCK_SOUTHWEST (1<<7) -#define RF_BLOCK_WEST (1<<8) +#define RF_BLOCK_NORTHWEST (1<<3) +#define RF_BLOCK_NORTHEAST (1<<4) +#define RF_BLOCK_EAST (1<<5) +#define RF_BLOCK_SOUTHEAST (1<<6) +#define RF_BLOCK_SOUTHWEST (1<<7) +#define RF_BLOCK_WEST (1<<8) -#define RF_ENCOUNTER (1<<9) -#define RF_MIGRATION (1<<10) -#define RF_UNUSED_1 (1<<11) -#define RF_ORCIFIED (1<<12) -#define RF_DH (1<<18) +#define RF_ENCOUNTER (1<<9) +#define RF_MIGRATION (1<<10) +#define RF_UNUSED_1 (1<<11) +#define RF_ORCIFIED (1<<12) + +#define RF_COMBATDEBUG (1<<14) + +#define RF_DH (1<<18) #define RF_ALL 0xFFFFFF @@ -48,54 +51,54 @@ struct message_list; struct rawmaterial; typedef struct land_region { - char *name; - /* TODO: demand kann nach Konvertierung entfernt werden. */ - struct demand { - struct demand * next; - const struct luxury_type * type; - int value; - } * demands; - const struct herb_type * herbtype; - short herbs; + char *name; + /* TODO: demand kann nach Konvertierung entfernt werden. */ + struct demand { + struct demand * next; + const struct luxury_type * type; + int value; + } * demands; + const struct herb_type * herbtype; + short herbs; #if GROWING_TREES - int trees[3]; /* 0 -> Samen, 1 -> Sprößlinge, 2 -> Bäume */ + int trees[3]; /* 0 -> Samen, 1 -> Sprößlinge, 2 -> Bäume */ #else - int trees; + int trees; #endif - int horses; - int peasants; - int newpeasants; - int money; + int horses; + int peasants; + int newpeasants; + int money; #if NEW_RESOURCEGROWTH == 0 - int iron; + int iron; #endif } land_region; typedef struct region { - struct region *next; - struct land_region *land; - struct unit *units; - struct ship *ships; - struct building *buildings; - int x, y; - struct plane *planep; - char *display; - unsigned int flags; - unsigned short age; - struct message_list *msgs; - struct individual_message { - struct individual_message * next; - const struct faction * viewer; - struct message_list *msgs; - } * individual_messages; - struct attrib *attribs; - struct region *nexthash; - terrain_t terrain; + struct region *next; + struct land_region *land; + struct unit *units; + struct ship *ships; + struct building *buildings; + int x, y; + struct plane *planep; + char *display; + unsigned int flags; + unsigned short age; + struct message_list *msgs; + struct individual_message { + struct individual_message * next; + const struct faction * viewer; + struct message_list *msgs; + } * individual_messages; + struct attrib *attribs; + struct region *nexthash; + terrain_t terrain; #ifdef WEATHER - weather_t weathertype; + weather_t weathertype; #endif #if NEW_RESOURCEGROWTH - struct rawmaterial * resources; + struct rawmaterial * resources; #endif #ifdef FAST_CONNECT struct region * connect[MAXDIRECTIONS]; @@ -120,7 +123,7 @@ typedef struct spec_direction { } spec_direction; typedef struct { - direction_t dir; + direction_t dir; } moveblock; #define region_hashkey(r) (abs((r)->x + 0x100 * (r)->y)) diff --git a/src/eressea/lua/region.cpp b/src/eressea/lua/region.cpp index 12065ef4d..17e25aba2 100644 --- a/src/eressea/lua/region.cpp +++ b/src/eressea/lua/region.cpp @@ -89,6 +89,20 @@ operator==(const region& a, const region&b) return a.x==b.x && a.y==b.y; } +static bool +region_getflag(const region& r, int bit) +{ + if (r.flags & (1<