diff --git a/src/common/gamecode/creport.c b/src/common/gamecode/creport.c index ea9c4e64b..ff86115bb 100644 --- a/src/common/gamecode/creport.c +++ b/src/common/gamecode/creport.c @@ -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) @@ -89,9 +89,9 @@ boolean opt_cr_absolute_coords = false; static const char * crtag(const char * key) { - static const struct locale * lang = NULL; - if (!lang) lang = find_locale(TAG_LOCALE); - return locale_string(lang, key); + static const struct locale * lang = NULL; + if (!lang) lang = find_locale(TAG_LOCALE); + return locale_string(lang, key); } #else #define crtag(x) (x) @@ -100,9 +100,9 @@ crtag(const char * key) * translation table */ typedef struct translation { - struct translation * next; - char * key; - const char * value; + struct translation * next; + char * key; + const char * value; } translation; #define TRANSMAXHASH 257 @@ -112,51 +112,51 @@ static translation * junkyard; static const char * add_translation(const char * key, const char * value) { - int kk = ((key[0] << 5) + key[0]) % TRANSMAXHASH; - translation * t = translation_table[kk]; - while (t && strcmp(t->key, key)!=0) t=t->next; - if (!t) { - if (junkyard) { - t = junkyard; - junkyard = junkyard->next; - } else t = malloc(sizeof(translation)); - t->key = strdup(key); - t->value = value; - t->next = translation_table[kk]; - translation_table[kk] = t; - } - return crtag(key); + int kk = ((key[0] << 5) + key[0]) % TRANSMAXHASH; + translation * t = translation_table[kk]; + while (t && strcmp(t->key, key)!=0) t=t->next; + if (!t) { + if (junkyard) { + t = junkyard; + junkyard = junkyard->next; + } else t = malloc(sizeof(translation)); + t->key = strdup(key); + t->value = value; + t->next = translation_table[kk]; + translation_table[kk] = t; + } + return crtag(key); } static void write_translations(FILE * F) { - int i; - fputs("TRANSLATION\n", F); - for (i=0;i!=TRANSMAXHASH;++i) { - translation * t = translation_table[i]; - while (t) { - fprintf(F, "\"%s\";%s\n", t->value, crtag(t->key)); - t = t->next; - } - } + int i; + fputs("TRANSLATION\n", F); + for (i=0;i!=TRANSMAXHASH;++i) { + translation * t = translation_table[i]; + while (t) { + fprintf(F, "\"%s\";%s\n", t->value, crtag(t->key)); + t = t->next; + } + } } static void reset_translations(void) { - int i; - for (i=0;i!=TRANSMAXHASH;++i) { - translation * t = translation_table[i]; - while (t) { - translation * c = t->next; - free(t->key); - t->next = junkyard; - junkyard = t; - t = c; - } - translation_table[i] = 0; - } + int i; + for (i=0;i!=TRANSMAXHASH;++i) { + translation * t = translation_table[i]; + while (t) { + translation * c = t->next; + free(t->key); + t->next = junkyard; + junkyard = t; + t = c; + } + translation_table[i] = 0; + } } #include "objtypes.h" @@ -177,78 +177,78 @@ print_items(FILE * F, item * items, const struct locale * lang) static void print_curses(FILE * F, const faction * viewer, const void * obj, typ_t typ) { - boolean header = false; - attrib *a = NULL; - int self = 0; - region *r; + boolean header = false; + attrib *a = NULL; + int self = 0; + region *r; - /* Die Sichtbarkeit eines Zaubers und die Zaubermeldung sind bei - * Gebäuden und Schiffen je nach, ob man Besitzer ist, verschieden. - * Bei Einheiten sieht man Wirkungen auf eigene Einheiten immer. - * Spezialfälle (besonderes Talent, verursachender Magier usw. werde - * bei jedem curse gesondert behandelt. */ - if (typ == TYP_SHIP){ - ship * sh = (ship*)obj; - unit * owner = shipowner(sh); - a = sh->attribs; - r = sh->region; - if(owner != NULL) { - if (owner->faction == viewer){ - self = 2; - } else { /* steht eine person der Partei auf dem Schiff? */ - unit *u = NULL; - for (u = r->units; u; u = u->next) { - if (u->ship == sh) { - self = 1; - break; - } - } - } - } - } else if (typ == TYP_BUILDING) { - building * b = (building*)obj; - unit * owner; - a = b->attribs; - r = b->region; - if((owner = buildingowner(r,b)) != NULL){ - if (owner->faction == viewer){ - self = 2; - } else { /* steht eine Person der Partei in der Burg? */ - unit *u = NULL; - for (u = r->units; u; u = u->next) { - if (u->building == b) { - self = 1; - break; - } - } - } - } - } else if (typ == TYP_UNIT) { - unit *u = (unit *)obj; - a = u->attribs; - r = u->region; - if (u->faction == viewer){ - self = 2; - } - } else if (typ == TYP_REGION) { - r = (region *)obj; - a = r->attribs; - } else { - /* fehler */ - } + /* Die Sichtbarkeit eines Zaubers und die Zaubermeldung sind bei + * Gebäuden und Schiffen je nach, ob man Besitzer ist, verschieden. + * Bei Einheiten sieht man Wirkungen auf eigene Einheiten immer. + * Spezialfälle (besonderes Talent, verursachender Magier usw. werde + * bei jedem curse gesondert behandelt. */ + if (typ == TYP_SHIP){ + ship * sh = (ship*)obj; + unit * owner = shipowner(sh); + a = sh->attribs; + r = sh->region; + if(owner != NULL) { + if (owner->faction == viewer){ + self = 2; + } else { /* steht eine person der Partei auf dem Schiff? */ + unit *u = NULL; + for (u = r->units; u; u = u->next) { + if (u->ship == sh) { + self = 1; + break; + } + } + } + } + } else if (typ == TYP_BUILDING) { + building * b = (building*)obj; + unit * owner; + a = b->attribs; + r = b->region; + if((owner = buildingowner(r,b)) != NULL){ + if (owner->faction == viewer){ + self = 2; + } else { /* steht eine Person der Partei in der Burg? */ + unit *u = NULL; + for (u = r->units; u; u = u->next) { + if (u->building == b) { + self = 1; + break; + } + } + } + } + } else if (typ == TYP_UNIT) { + unit *u = (unit *)obj; + a = u->attribs; + r = u->region; + if (u->faction == viewer){ + self = 2; + } + } else if (typ == TYP_REGION) { + r = (region *)obj; + a = r->attribs; + } else { + /* fehler */ + } - while (a) { - int dh = 0; - curse *c; + while (a) { + int dh = 0; + curse *c; - if (fval(a->type, ATF_CURSE)) { + if (fval(a->type, ATF_CURSE)) { - c = (curse *)a->data.v; - if (c->type->curseinfo) { - if (c->type->cansee) { - self = c->type->cansee(viewer, obj, typ, c, self); - } - dh = c->type->curseinfo(viewer->locale, obj, typ, c, self); + c = (curse *)a->data.v; + if (c->type->curseinfo) { + if (c->type->cansee) { + self = c->type->cansee(viewer, obj, typ, c, self); + } + dh = c->type->curseinfo(viewer->locale, obj, typ, c, self); } if (dh==0) { if (c->type->info_str!=NULL) { @@ -257,115 +257,115 @@ print_curses(FILE * F, const faction * viewer, const void * obj, typ_t typ) sprintf(buf, "an unknown curse lies on the region. (%s)", itoa36(c->no)); } } - if (dh==1) { - if (!header) { - header = 1; - fputs("EFFECTS\n", F); - } - fprintf(F, "\"%s\"\n", buf); - } - } else if (a->type==&at_effect && self) { - effect_data * data = (effect_data *)a->data.v; - const char * key = resourcename(data->type->itype->rtype, 0); - if (!header) { - header = 1; - fputs("EFFECTS\n", F); - } - fprintf(F, "\"%d %s\"\n", data->value, add_translation(key, locale_string(default_locale, key))); - } - a = a->next; - } + if (dh==1) { + if (!header) { + header = 1; + fputs("EFFECTS\n", F); + } + fprintf(F, "\"%s\"\n", buf); + } + } else if (a->type==&at_effect && self) { + effect_data * data = (effect_data *)a->data.v; + const char * key = resourcename(data->type->itype->rtype, 0); + if (!header) { + header = 1; + fputs("EFFECTS\n", F); + } + fprintf(F, "\"%d %s\"\n", data->value, add_translation(key, locale_string(default_locale, key))); + } + a = a->next; + } } static int cr_unit(variant var, char * buffer, const void * userdata) { - const faction * report = (const faction*)userdata; - unit * u = (unit *)var.v; - sprintf(buffer, "%d", u?u->no:-1); - unused(report); - return 0; + const faction * report = (const faction*)userdata; + unit * u = (unit *)var.v; + sprintf(buffer, "%d", u?u->no:-1); + unused(report); + return 0; } static int cr_ship(variant var, char * buffer, const void * userdata) { - const faction * report = (const faction*)userdata; - ship * u = (ship *)var.v; - sprintf(buffer, "%d", u?u->no:-1); - unused(report); - return 0; + const faction * report = (const faction*)userdata; + ship * u = (ship *)var.v; + sprintf(buffer, "%d", u?u->no:-1); + unused(report); + return 0; } static int cr_building(variant var, char * buffer, const void * userdata) { - const faction * report = (const faction*)userdata; - building * u = (building *)var.v; - sprintf(buffer, "%d", u?u->no:-1); - unused(report); - return 0; + const faction * report = (const faction*)userdata; + building * u = (building *)var.v; + sprintf(buffer, "%d", u?u->no:-1); + unused(report); + return 0; } static int cr_faction(variant var, char * buffer, const void * userdata) { - const faction * report = (const faction*)userdata; - faction * f = (faction *)var.v; - sprintf(buffer, "%d", f?f->no:-1); - unused(report); - return 0; + const faction * report = (const faction*)userdata; + faction * f = (faction *)var.v; + sprintf(buffer, "%d", f?f->no:-1); + unused(report); + return 0; } static int cr_region(variant var, char * buffer, const void * userdata) { - const faction * report = (const faction*)userdata; - region * r = (region *)var.v; - if (r) { - plane * p = rplane(r); - if (!p || !(p->flags & PFL_NOCOORDS)) { - sprintf(buffer, "%d %d %d", region_x(r, report), region_y(r, report), p?p->id:0); - return 0; - } - } - return -1; + const faction * report = (const faction*)userdata; + region * r = (region *)var.v; + if (r) { + plane * p = rplane(r); + if (!p || !(p->flags & PFL_NOCOORDS)) { + sprintf(buffer, "%d %d %d", region_x(r, report), region_y(r, report), p?p->id:0); + return 0; + } + } + return -1; } static int cr_resource(variant var, char * buffer, const void * userdata) { - const faction * report = (const faction*)userdata; - const resource_type * r = (const resource_type *)var.v; - if (r) { - const char * key = resourcename(r, 0); - sprintf(buffer, "\"%s\"", - add_translation(key, locale_string(report->locale, key))); - return 0; - } - return -1; + const faction * report = (const faction*)userdata; + const resource_type * r = (const resource_type *)var.v; + if (r) { + const char * key = resourcename(r, 0); + sprintf(buffer, "\"%s\"", + add_translation(key, locale_string(report->locale, key))); + return 0; + } + return -1; } static int cr_race(variant var, char * buffer, const void * userdata) { - const faction * report = (const faction*)userdata; - const struct race * rc = (const race *)var.v; - const char * key = rc_name(rc, 0); - sprintf(buffer, "\"%s\"", - add_translation(key, locale_string(report->locale, key))); - return 0; + const faction * report = (const faction*)userdata; + const struct race * rc = (const race *)var.v; + const char * key = rc_name(rc, 0); + sprintf(buffer, "\"%s\"", + add_translation(key, locale_string(report->locale, key))); + return 0; } static int cr_alliance(variant var, char * buffer, const void * userdata) { - const alliance * al = (const alliance *)var.v; - if (al!=NULL) { - sprintf(buffer, "%d", al->id); - } - unused(userdata); - return 0; + const alliance * al = (const alliance *)var.v; + if (al!=NULL) { + sprintf(buffer, "%d", al->id); + } + unused(userdata); + return 0; } static int @@ -413,12 +413,12 @@ cr_resources(variant var, char * buffer, const void * userdata) resource * rlist = (resource*)var.v; char * wp = buffer; if (rlist!=NULL) { - wp += sprintf(wp, "\"%d %s", rlist->number, + wp += sprintf(wp, "\"%d %s", rlist->number, resourcename(rlist->type, rlist->number!=1)); for (;;) { rlist = rlist->next; if (rlist==NULL) break; - wp += sprintf(wp, ", %d %s", rlist->number, + wp += sprintf(wp, ", %d %s", rlist->number, resourcename(rlist->type, rlist->number!=1)); } strcat(wp, "\""); @@ -448,74 +448,74 @@ static struct known_mtype { static void report_crtypes(FILE * F, const struct locale* lang) { - int i; - for (i=0;i!=MTMAXHASH;++i) { - struct known_mtype * kmt; - for (kmt=mtypehash[i];kmt;kmt=kmt->nexthash) { - const struct nrmessage_type * nrt = nrt_find(lang, kmt->mtype); - if (nrt) { - unsigned int hash = kmt->mtype->key; + int i; + for (i=0;i!=MTMAXHASH;++i) { + struct known_mtype * kmt; + for (kmt=mtypehash[i];kmt;kmt=kmt->nexthash) { + const struct nrmessage_type * nrt = nrt_find(lang, kmt->mtype); + if (nrt) { + unsigned int hash = kmt->mtype->key; fprintf(F, "MESSAGETYPE %d\n", hash); fputc('\"', F); - fputs(escape_string(nrt_string(nrt), NULL, 0), F); - fputs("\";text\n", F); - fprintf(F, "\"%s\";section\n", nrt_section(nrt)); - } - } - while (mtypehash[i]) { - kmt = mtypehash[i]; - mtypehash[i] = mtypehash[i]->nexthash; - free(kmt); - } - } + fputs(escape_string(nrt_string(nrt), NULL, 0), F); + fputs("\";text\n", F); + fprintf(F, "\"%s\";section\n", nrt_section(nrt)); + } + } + while (mtypehash[i]) { + kmt = mtypehash[i]; + mtypehash[i] = mtypehash[i]->nexthash; + free(kmt); + } + } } static void render_messages(FILE * F, faction * f, message_list *msgs) { - struct mlist* m = msgs->begin; - while (m) { - char crbuffer[1024*32]; /* gross, wegen spionage-messages :-( */ - boolean printed = false; - const struct message_type * mtype = m->msg->type; - unsigned int hash = mtype->key; + struct mlist* m = msgs->begin; + while (m) { + char crbuffer[1024*32]; /* gross, wegen spionage-messages :-( */ + boolean printed = false; + const struct message_type * mtype = m->msg->type; + unsigned int hash = mtype->key; #ifdef RENDER_CRMESSAGES - char nrbuffer[1024*32]; - nrbuffer[0] = '\0'; - if (nr_render(m->msg, f->locale, nrbuffer, sizeof(nrbuffer), f)>0 && nrbuffer[0]) { - fprintf(F, "MESSAGE %u\n", (unsigned int)m->msg);/*++msgno); */ - fprintf(F, "%d;type\n", hash); + char nrbuffer[1024*32]; + nrbuffer[0] = '\0'; + if (nr_render(m->msg, f->locale, nrbuffer, sizeof(nrbuffer), f)>0 && nrbuffer[0]) { + fprintf(F, "MESSAGE %u\n", (unsigned int)m->msg);/*++msgno); */ + fprintf(F, "%d;type\n", hash); fwritestr(F, nrbuffer); - fputs(";rendered\n", F); - printed = true; - } + fputs(";rendered\n", F); + printed = true; + } #endif - crbuffer[0] = '\0'; - if (cr_render(m->msg, crbuffer, (const void*)f)==0) { - if (!printed) fprintf(F, "MESSAGE %u\n", (unsigned int)m->msg);/*++msgno); */ - if (crbuffer[0]) fputs(crbuffer, F); - } else { - log_error(("could not render cr-message %p: %s\n", m->msg, m->msg->type->name)); - } - if (printed) { - unsigned int ihash = hash % MTMAXHASH; - struct known_mtype * kmt = mtypehash[ihash]; - while (kmt && kmt->mtype != mtype) kmt = kmt->nexthash; - if (kmt==NULL) { - kmt = (struct known_mtype*)malloc(sizeof(struct known_mtype)); - kmt->nexthash = mtypehash[ihash]; - kmt->mtype = mtype; - mtypehash[ihash] = kmt; - } - } - m = m->next; - } + crbuffer[0] = '\0'; + if (cr_render(m->msg, crbuffer, (const void*)f)==0) { + if (!printed) fprintf(F, "MESSAGE %u\n", (unsigned int)m->msg);/*++msgno); */ + if (crbuffer[0]) fputs(crbuffer, F); + } else { + log_error(("could not render cr-message %p: %s\n", m->msg, m->msg->type->name)); + } + if (printed) { + unsigned int ihash = hash % MTMAXHASH; + struct known_mtype * kmt = mtypehash[ihash]; + while (kmt && kmt->mtype != mtype) kmt = kmt->nexthash; + if (kmt==NULL) { + kmt = (struct known_mtype*)malloc(sizeof(struct known_mtype)); + kmt->nexthash = mtypehash[ihash]; + kmt->mtype = mtype; + mtypehash[ihash] = kmt; + } + } + m = m->next; + } } static void cr_output_messages(FILE * F, message_list *msgs, faction * f) { - if (msgs) render_messages(F, f, msgs); + if (msgs) render_messages(F, f, msgs); } /* prints a building */ @@ -528,7 +528,7 @@ cr_output_buildings(FILE * F, building * b, const unit * owner, int fno, faction if (!bt_illusion) bt_illusion = bt_find("illusion"); - fprintf(F, "BURG %d\n", b->no); + fprintf(F, "BURG %d\n", b->no); if (b->type==bt_illusion) { const attrib * a = a_findc(b->attribs, &at_icastle); @@ -543,17 +543,17 @@ cr_output_buildings(FILE * F, building * b, const unit * owner, int fno, faction bname = buildingtype(type, b, b->size); fprintf(F, "\"%s\";Typ\n", add_translation(bname, LOC(f->locale, bname))); fprintf(F, "\"%s\";Name\n", b->name); - if (b->display && strlen(b->display)) - fprintf(F, "\"%s\";Beschr\n", b->display); - if (b->size) - fprintf(F, "%d;Groesse\n", b->size); - if (owner) - fprintf(F, "%d;Besitzer\n", owner ? owner->no : -1); - if (fno >= 0) - fprintf(F, "%d;Partei\n", fno); - if (b->besieged) - fprintf(F, "%d;Belagerer\n", b->besieged); - print_curses(F, f, b, TYP_BUILDING); + if (b->display && strlen(b->display)) + fprintf(F, "\"%s\";Beschr\n", b->display); + if (b->size) + fprintf(F, "%d;Groesse\n", b->size); + if (owner) + fprintf(F, "%d;Besitzer\n", owner ? owner->no : -1); + if (fno >= 0) + fprintf(F, "%d;Partei\n", fno); + if (b->besieged) + fprintf(F, "%d;Belagerer\n", b->besieged); + print_curses(F, f, b, TYP_BUILDING); } /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ @@ -561,25 +561,25 @@ cr_output_buildings(FILE * F, building * b, const unit * owner, int fno, faction static void cr_output_ship(FILE * F, const ship * sh, const unit * u, int fcaptain, const faction * f, const region * r) { - int w = 0; - assert(sh); - fprintf(F, "SCHIFF %d\n", sh->no); - fprintf(F, "\"%s\";Name\n", sh->name); - if (sh->display && strlen(sh->display)) - fprintf(F, "\"%s\";Beschr\n", sh->display); - fprintf(F, "\"%s\";Typ\n", add_translation(sh->type->name[0], locale_string(f->locale, sh->type->name[0]))); - fprintf(F, "%d;Groesse\n", sh->size); - if (sh->damage) { - int percent = sh->damage*100/(sh->size*DAMAGE_SCALE); - fprintf(F, "%d;Schaden\n", percent); - } - if (u) - fprintf(F, "%d;Kapitaen\n", u ? u->no : -1); - if (fcaptain >= 0) - fprintf(F, "%d;Partei\n", fcaptain); + int w = 0; + assert(sh); + fprintf(F, "SCHIFF %d\n", sh->no); + fprintf(F, "\"%s\";Name\n", sh->name); + if (sh->display && strlen(sh->display)) + fprintf(F, "\"%s\";Beschr\n", sh->display); + fprintf(F, "\"%s\";Typ\n", add_translation(sh->type->name[0], locale_string(f->locale, sh->type->name[0]))); + fprintf(F, "%d;Groesse\n", sh->size); + if (sh->damage) { + int percent = sh->damage*100/(sh->size*DAMAGE_SCALE); + fprintf(F, "%d;Schaden\n", percent); + } + if (u) + fprintf(F, "%d;Kapitaen\n", u ? u->no : -1); + if (fcaptain >= 0) + fprintf(F, "%d;Partei\n", fcaptain); - /* calculate cargo */ - if (u && (u->faction == f || omniscient(f))) { + /* calculate cargo */ + if (u && (u->faction == f || omniscient(f))) { int n = 0, p = 0, c = shipcapacity(sh); getshipweight(sh, &n, &p); @@ -587,34 +587,34 @@ cr_output_ship(FILE * F, const ship * sh, const unit * u, int fcaptain, const fa fprintf(F, "%d;capacity\n", c); n = (n+99) / 100; /* 1 Silber = 1 GE */ - fprintf(F, "%d;Ladung\n", n); - fprintf(F, "%d;MaxLadung\n", c / 100); - } - /* shore */ - w = NODIRECTION; - if (!fval(r->terrain, SEA_REGION)) w = sh->coast; - if (w != NODIRECTION) - fprintf(F, "%d;Kueste\n", w); + fprintf(F, "%d;Ladung\n", n); + fprintf(F, "%d;MaxLadung\n", c / 100); + } + /* shore */ + w = NODIRECTION; + if (!fval(r->terrain, SEA_REGION)) w = sh->coast; + if (w != NODIRECTION) + fprintf(F, "%d;Kueste\n", w); - print_curses(F, f, sh, TYP_SHIP); + print_curses(F, f, sh, TYP_SHIP); } /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ /* prints all that belongs to a unit */ static void cr_output_unit(FILE * F, const region * r, - const faction * f, /* observers faction */ - const unit * u, int mode) + const faction * f, /* observers faction */ + const unit * u, int mode) { - /* Race attributes are always plural and item attributes always - * singular */ - const item_type * lasttype; - int pr; - item *itm, *show; - building * b; - const char * pzTmp; - skill * sv; - const attrib *a_fshidden = NULL; + /* Race attributes are always plural and item attributes always + * singular */ + const item_type * lasttype; + int pr; + item *itm, *show; + building * b; + const char * pzTmp; + skill * sv; + const attrib *a_fshidden = NULL; boolean itemcloak = false; static const curse_type * itemcloak_ct = 0; static boolean init = false; @@ -627,103 +627,109 @@ cr_output_unit(FILE * F, const region * r, itemcloak = curse_active(get_curse(u->attribs, itemcloak_ct)); } - assert(u); + assert(u); #ifdef KARMA_MODULE - if (fspecial(u->faction, FS_HIDDEN)) - a_fshidden = a_find(u->attribs, &at_fshidden); + if (fspecial(u->faction, FS_HIDDEN)) + a_fshidden = a_find(u->attribs, &at_fshidden); #endif /* KARMA_MODULE */ - fprintf(F, "EINHEIT %d\n", u->no); - fprintf(F, "\"%s\";Name\n", u->name); - if (u->display && strlen(u->display)) - fprintf(F, "\"%s\";Beschr\n", u->display); + fprintf(F, "EINHEIT %d\n", u->no); + fprintf(F, "\"%s\";Name\n", u->name); + if (u->display && strlen(u->display)) + fprintf(F, "\"%s\";Beschr\n", u->display); + + { + /* print faction information */ + const faction * sf = visible_faction(f, u); + const char * prefix = raceprefix(u); + if (u->faction == f || omniscient(f)) { + const attrib * a_otherfaction = a_find(u->attribs, &at_otherfaction); + const faction * otherfaction = a_otherfaction?get_otherfaction(a_otherfaction):NULL; + /* my own faction, full info */ + const attrib *a = NULL; + unit * mage; - { - /* print faction information */ - const faction * sf = visible_faction(f, u); - const char * prefix = raceprefix(u); - if (u->faction == f || omniscient(f)) { - const attrib * a_otherfaction = a_find(u->attribs, &at_otherfaction); - const faction * otherfaction = a_otherfaction?get_otherfaction(a_otherfaction):NULL; - /* my own faction, full info */ - const attrib *a = NULL; if (fval(u, UFL_GROUP)) a = a_find(u->attribs, &at_group); - if (a!=NULL) { - const group * g = (const group*)a->data.v; - fprintf(F, "%d;gruppe\n", g->gid); - } - fprintf(F, "%d;Partei\n", u->faction->no); - if (sf!=u->faction) fprintf(F, "%d;Verkleidung\n", sf->no); - if (fval(u, UFL_PARTEITARNUNG)) - fprintf(F, "%d;Parteitarnung\n", i2b(fval(u, UFL_PARTEITARNUNG))); + if (a!=NULL) { + const group * g = (const group*)a->data.v; + fprintf(F, "%d;gruppe\n", g->gid); + } + fprintf(F, "%d;Partei\n", u->faction->no); + if (sf!=u->faction) fprintf(F, "%d;Verkleidung\n", sf->no); + if (fval(u, UFL_PARTEITARNUNG)) + fprintf(F, "%d;Parteitarnung\n", i2b(fval(u, UFL_PARTEITARNUNG))); if (otherfaction) { if (otherfaction!=u->faction) { fprintf(F, "%d;Anderepartei\n", otherfaction->no); } } + mage = get_familiar_mage(u); + if (mage) { + fprintf(F, "%u;familiarmage\n", mage->no); + } } else { - if (fval(u, UFL_PARTEITARNUNG)) { - /* faction info is hidden */ - fprintf(F, "%d;Parteitarnung\n", i2b(fval(u, UFL_PARTEITARNUNG))); - } else { - const attrib * a_otherfaction = a_find(u->attribs, &at_otherfaction); - const faction * otherfaction = a_otherfaction?get_otherfaction(a_otherfaction):NULL; - /* other unit. show visible faction, not u->faction */ - fprintf(F, "%d;Partei\n", sf->no); - if (sf == f) { - fprintf(F, "1;Verraeter\n"); - } + if (fval(u, UFL_PARTEITARNUNG)) { + /* faction info is hidden */ + fprintf(F, "%d;Parteitarnung\n", i2b(fval(u, UFL_PARTEITARNUNG))); + } else { + const attrib * a_otherfaction = a_find(u->attribs, &at_otherfaction); + const faction * otherfaction = a_otherfaction?get_otherfaction(a_otherfaction):NULL; + /* other unit. show visible faction, not u->faction */ + fprintf(F, "%d;Partei\n", sf->no); + if (sf == f) { + fprintf(F, "1;Verraeter\n"); + } if (a_otherfaction) { if (otherfaction!=u->faction) { if (alliedunit(u, f, HELP_FSTEALTH)) { fprintf(F, "%d;Anderepartei\n", otherfaction->no); } } - } - } - } - if (prefix) { + } + } + } + if (prefix) { prefix = mkname("prefix", prefix); - fprintf(F, "\"%s\";typprefix\n", add_translation(prefix, LOC(f->locale, prefix))); - } - } - if (u->faction != f && a_fshidden - && a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) { - fprintf(F, "-1;Anzahl\n"); - } else { - fprintf(F, "%d;Anzahl\n", u->number); - } + fprintf(F, "\"%s\";typprefix\n", add_translation(prefix, LOC(f->locale, prefix))); + } + } + if (u->faction != f && a_fshidden + && a_fshidden->data.ca[0] == 1 && effskill(u, SK_STEALTH) >= 6) { + fprintf(F, "-1;Anzahl\n"); + } else { + fprintf(F, "%d;Anzahl\n", u->number); + } pzTmp = get_racename(u->attribs); if (pzTmp) { fprintf(F, "\"%s\";Typ\n", pzTmp); if (u->faction==f && fval(u->race, RCF_SHAPESHIFTANY)) { const char * zRace = rc_name(u->race, 1); - fprintf(F, "\"%s\";wahrerTyp\n", + fprintf(F, "\"%s\";wahrerTyp\n", add_translation(zRace, locale_string(f->locale, zRace))); } } else { const char * zRace = rc_name(u->irace, 1); - fprintf(F, "\"%s\";Typ\n", + fprintf(F, "\"%s\";Typ\n", add_translation(zRace, locale_string(f->locale, zRace))); if (u->faction==f && u->irace!=u->race) { zRace = rc_name(u->race, 1); - fprintf(F, "\"%s\";wahrerTyp\n", + fprintf(F, "\"%s\";wahrerTyp\n", add_translation(zRace, locale_string(f->locale, zRace))); } } if (u->building) - fprintf(F, "%d;Burg\n", u->building->no); - if (u->ship) - fprintf(F, "%d;Schiff\n", u->ship->no); - if (getguard(u)) - fprintf(F, "%d;bewacht\n", getguard(u)?1:0); - if ((b=usiege(u))!=NULL) - fprintf(F, "%d;belagert\n", b->no); + fprintf(F, "%d;Burg\n", u->building->no); + if (u->ship) + fprintf(F, "%d;Schiff\n", u->ship->no); + if (getguard(u)) + fprintf(F, "%d;bewacht\n", getguard(u)?1:0); + if ((b=usiege(u))!=NULL) + fprintf(F, "%d;belagert\n", b->no); - /* additional information for own units */ + /* additional information for own units */ if (u->faction == f || omniscient(f)) { order * ord; const char *c; @@ -835,57 +841,57 @@ cr_output_unit(FILE * F, const region * r, } } } - /* items */ - pr = 0; - if (f == u->faction || omniscient(u->faction)) { - show = u->items; - } else if (itemcloak==false && mode>=see_unit && !(a_fshidden - && a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH) >= 3)) { - show = NULL; - for (itm=u->items;itm;itm=itm->next) { - item * ishow; - const char * ic; - int in; - report_item(u, itm, f, NULL, &ic, &in, true); - if (in>0 && ic && *ic) { - for (ishow = show; ishow; ishow=ishow->next) { - const char * sc; - int sn; - if (ishow->type==itm->type) sc=ic; - else report_item(u, ishow, f, NULL, &sc, &sn, true); - if (sc==ic || strcmp(sc, ic)==0) { - ishow->number+=itm->number; - break; - } - } - if (ishow==NULL) { - ishow = i_add(&show, i_new(itm->type, itm->number)); - } - } - } - } else { - show = NULL; - } - lasttype = NULL; - for (itm=show; itm; itm=itm->next) { - const char * ic; - int in; - assert(itm->type!=lasttype || !"error: list contains two objects of the same item"); - report_item(u, itm, f, NULL, &ic, &in, true); - if (in==0) continue; - if (!pr) { - pr = 1; - fputs("GEGENSTAENDE\n", F); - } - fprintf(F, "%d;%s\n", in, add_translation(ic, locale_string(f->locale, ic))); - } + /* items */ + pr = 0; + if (f == u->faction || omniscient(u->faction)) { + show = u->items; + } else if (itemcloak==false && mode>=see_unit && !(a_fshidden + && a_fshidden->data.ca[1] == 1 && effskill(u, SK_STEALTH) >= 3)) { + show = NULL; + for (itm=u->items;itm;itm=itm->next) { + item * ishow; + const char * ic; + int in; + report_item(u, itm, f, NULL, &ic, &in, true); + if (in>0 && ic && *ic) { + for (ishow = show; ishow; ishow=ishow->next) { + const char * sc; + int sn; + if (ishow->type==itm->type) sc=ic; + else report_item(u, ishow, f, NULL, &sc, &sn, true); + if (sc==ic || strcmp(sc, ic)==0) { + ishow->number+=itm->number; + break; + } + } + if (ishow==NULL) { + ishow = i_add(&show, i_new(itm->type, itm->number)); + } + } + } + } else { + show = NULL; + } + lasttype = NULL; + for (itm=show; itm; itm=itm->next) { + const char * ic; + int in; + assert(itm->type!=lasttype || !"error: list contains two objects of the same item"); + report_item(u, itm, f, NULL, &ic, &in, true); + if (in==0) continue; + if (!pr) { + pr = 1; + fputs("GEGENSTAENDE\n", F); + } + fprintf(F, "%d;%s\n", in, add_translation(ic, locale_string(f->locale, ic))); + } if (show!=u->items) { /* free the temporary items */ while (show) { i_free(i_remove(&show, show)); } } - + print_curses(F, f, u, TYP_UNIT); } /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ @@ -894,14 +900,14 @@ cr_output_unit(FILE * F, const region * r, static void show_allies(FILE * F, const faction * f, const ally * sf) { - for (; sf; sf = sf->next) if (sf->faction) { - int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL); - if (mode!=0 && sf->status>0) { - fprintf(F, "ALLIANZ %d\n", sf->faction->no); - fprintf(F, "\"%s\";Parteiname\n", sf->faction->name); - fprintf(F, "%d;Status\n", sf->status & HELP_ALL); - } - } + for (; sf; sf = sf->next) if (sf->faction) { + int mode = alliedgroup(NULL, f, sf->faction, sf, HELP_ALL); + if (mode!=0 && sf->status>0) { + fprintf(F, "ALLIANZ %d\n", sf->faction->no); + fprintf(F, "\"%s\";Parteiname\n", sf->faction->name); + fprintf(F, "%d;Status\n", sf->status & HELP_ALL); + } + } } #ifdef ENEMIES @@ -921,12 +927,12 @@ show_enemies(FILE * F, const faction_list* flist) static void show_active_spells(const region * r) { - char fogwall[MAXDIRECTIONS]; + char fogwall[MAXDIRECTIONS]; #ifdef TODO /* alte Regionszauberanzeigen umstellen */ - unit *u; - int env = 0; + unit *u; + int env = 0; #endif - memset(fogwall, 0, sizeof(char) * MAXDIRECTIONS); + memset(fogwall, 0, sizeof(char) * MAXDIRECTIONS); } /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ @@ -935,18 +941,18 @@ show_active_spells(const region * r) static void cr_find_address(FILE * F, const faction * uf, const faction_list * addresses) { - const faction_list * flist = addresses; - while (flist!=NULL) { - const faction * f = flist->data; - if (uf!=f && f->no != MONSTER_FACTION) { - fprintf(F, "PARTEI %d\n", f->no); - fprintf(F, "\"%s\";Parteiname\n", f->name); - fprintf(F, "\"%s\";email\n", f->email); - fprintf(F, "\"%s\";banner\n", f->banner); - if (f->alliance!=NULL && f->alliance==uf->alliance) { - fprintf(F, "%d;alliance\n", f->alliance->id); - fprintf(F, "\"%s\";alliancename\n", f->alliance->name); - } + const faction_list * flist = addresses; + while (flist!=NULL) { + const faction * f = flist->data; + if (uf!=f && f->no != MONSTER_FACTION) { + fprintf(F, "PARTEI %d\n", f->no); + fprintf(F, "\"%s\";Parteiname\n", f->name); + fprintf(F, "\"%s\";email\n", f->email); + fprintf(F, "\"%s\";banner\n", f->banner); + if (f->alliance!=NULL && f->alliance==uf->alliance) { + fprintf(F, "%d;alliance\n", f->alliance->id); + fprintf(F, "\"%s\";alliancename\n", f->alliance->name); + } #ifdef SHORTPWDS if (f->shortpwds) { shortpwd * spwd = f->shortpwds; @@ -960,120 +966,120 @@ cr_find_address(FILE * F, const faction * uf, const faction_list * addresses) } } #endif - } - flist = flist->next; - } + } + flist = flist->next; + } } /* = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = = */ static void -cr_reportspell(FILE * F, spell *sp, const struct locale * lang) +cr_reportspell(FILE * F, spell *sp, const struct locale * lang) { - int k; - const char * name = add_translation(mkname("spell", sp->sname), spell_name(sp, lang)); + int k; + const char * name = add_translation(mkname("spell", sp->sname), spell_name(sp, lang)); - fprintf(F, "ZAUBER %d\n", hashstring(spell_name(sp, default_locale))); - fprintf(F, "\"%s\";name\n", name); - fprintf(F, "%d;level\n", sp->level); - fprintf(F, "%d;rank\n", sp->rank); - fprintf(F, "\"%s\";info\n", spell_info(sp, lang)); + fprintf(F, "ZAUBER %d\n", hashstring(spell_name(sp, default_locale))); + fprintf(F, "\"%s\";name\n", name); + fprintf(F, "%d;level\n", sp->level); + fprintf(F, "%d;rank\n", sp->rank); + fprintf(F, "\"%s\";info\n", spell_info(sp, lang)); - if (sp->sptyp & PRECOMBATSPELL) fputs("\"precombat\";class\n", F); - else if (sp->sptyp & COMBATSPELL) fputs("\"combat\";class\n", F); - else if (sp->sptyp & POSTCOMBATSPELL) fputs("\"postcombat\";class\n", F); - else fputs("\"normal\";class\n", F); + if (sp->sptyp & PRECOMBATSPELL) fputs("\"precombat\";class\n", F); + else if (sp->sptyp & COMBATSPELL) fputs("\"combat\";class\n", F); + else if (sp->sptyp & POSTCOMBATSPELL) fputs("\"postcombat\";class\n", F); + else fputs("\"normal\";class\n", F); - if (sp->sptyp & FARCASTING) fputs("1;far\n", F); - if (sp->sptyp & OCEANCASTABLE) fputs("1;ocean\n", F); - if (sp->sptyp & ONSHIPCAST) fputs("1;ship\n", F); - if (!(sp->sptyp & NOTFAMILIARCAST)) fputs("1;familiar\n", F); - fputs("KOMPONENTEN\n", F); + if (sp->sptyp & FARCASTING) fputs("1;far\n", F); + if (sp->sptyp & OCEANCASTABLE) fputs("1;ocean\n", F); + if (sp->sptyp & ONSHIPCAST) fputs("1;ship\n", F); + if (!(sp->sptyp & NOTFAMILIARCAST)) fputs("1;familiar\n", F); + fputs("KOMPONENTEN\n", F); - for (k = 0; sp->components[k].type; ++k) { - const resource_type * rtype = sp->components[k].type; - int itemanz = sp->components[k].amount; - int costtyp = sp->components[k].cost; - if (itemanz > 0) { - const char * name = resourcename(rtype, 0); - fprintf(F, "%d %d;%s\n", itemanz, costtyp == SPC_LEVEL || costtyp == SPC_LINEAR, - add_translation(name, LOC(lang, name))); - } - } + for (k = 0; sp->components[k].type; ++k) { + const resource_type * rtype = sp->components[k].type; + int itemanz = sp->components[k].amount; + int costtyp = sp->components[k].cost; + if (itemanz > 0) { + const char * name = resourcename(rtype, 0); + fprintf(F, "%d %d;%s\n", itemanz, costtyp == SPC_LEVEL || costtyp == SPC_LINEAR, + add_translation(name, LOC(lang, name))); + } + } } static unsigned int encode_region(const faction * f, const region * r) { - unsigned int id; - char *cp, c; - /* obfuscation */ - assert(sizeof(int)==sizeof(char)*4); - id = (((((r->x ^ f->no) % 1024) << 20) | ((r->y ^ f->no) % 1024))); - cp = (char*)&id; - c = cp[0]; - cp[0] = cp[2]; - cp[2] = cp[1]; - cp[1] = cp[3]; - cp[3] = c; - return id; + unsigned int id; + char *cp, c; + /* obfuscation */ + assert(sizeof(int)==sizeof(char)*4); + id = (((((r->x ^ f->no) % 1024) << 20) | ((r->y ^ f->no) % 1024))); + cp = (char*)&id; + c = cp[0]; + cp[0] = cp[2]; + cp[2] = cp[1]; + cp[1] = cp[3]; + cp[3] = c; + return id; } static char * report_resource(char * buf, const char * name, const struct locale * loc, int amount, int level) { - buf += sprintf(buf, "RESOURCE %u\n", hashstring(name)); - buf += sprintf(buf, "\"%s\";type\n", add_translation(name, LOC(loc, name))); - if (amount>=0) { - if (level>=0) buf += sprintf(buf, "%d;skill\n", level); - buf += sprintf(buf, "%d;number\n", amount); - } - return buf; + buf += sprintf(buf, "RESOURCE %u\n", hashstring(name)); + buf += sprintf(buf, "\"%s\";type\n", add_translation(name, LOC(loc, name))); + if (amount>=0) { + if (level>=0) buf += sprintf(buf, "%d;skill\n", level); + buf += sprintf(buf, "%d;number\n", amount); + } + return buf; } static void cr_borders(seen_region ** seen, const region * r, const faction * f, int seemode, FILE * F) { - direction_t d; - int g = 0; - for (d = 0; d != MAXDIRECTIONS; d++) - { /* Nachbarregionen, die gesehen werden, ermitteln */ - const region * r2 = rconnect(r, d); - const border * b; - if (!r2) continue; - if (seemode==see_neighbour) { - seen_region * sr = find_seen(seen, r2); - if (sr==NULL || sr->mode<=see_neighbour) continue; - } - b = get_borders(r, r2); - while (b) { - boolean cs = b->type->fvisible(b, f, r); + direction_t d; + int g = 0; + for (d = 0; d != MAXDIRECTIONS; d++) + { /* Nachbarregionen, die gesehen werden, ermitteln */ + const region * r2 = rconnect(r, d); + const border * b; + if (!r2) continue; + if (seemode==see_neighbour) { + seen_region * sr = find_seen(seen, r2); + if (sr==NULL || sr->mode<=see_neighbour) continue; + } + b = get_borders(r, r2); + while (b) { + boolean cs = b->type->fvisible(b, f, r); - if (!cs) { - cs = b->type->rvisible(b, r); - if (!cs) { - unit * us = r->units; - while (us && !cs) { - if (us->faction==f) { - cs = b->type->uvisible(b, us); - if (cs) break; - } - us=us->next; - } - } - } - if (cs) { - fprintf(F, "GRENZE %d\n", ++g); - fprintf(F, "\"%s\";typ\n", b->type->name(b, r, f, GF_NONE)); - fprintf(F, "%d;richtung\n", d); - if (!b->type->transparent(b, f)) fputs("1;opaque\n", F); - /* pfusch: */ - if (b->type==&bt_road) { - int p = rroad(r, d)*100/r->terrain->max_road; - fprintf(F, "%d;prozent\n", p); - } - } - b = b->next; - } - } + if (!cs) { + cs = b->type->rvisible(b, r); + if (!cs) { + unit * us = r->units; + while (us && !cs) { + if (us->faction==f) { + cs = b->type->uvisible(b, us); + if (cs) break; + } + us=us->next; + } + } + } + if (cs) { + fprintf(F, "GRENZE %d\n", ++g); + fprintf(F, "\"%s\";typ\n", b->type->name(b, r, f, GF_NONE)); + fprintf(F, "%d;richtung\n", d); + if (!b->type->transparent(b, f)) fputs("1;opaque\n", F); + /* pfusch: */ + if (b->type==&bt_road) { + int p = rroad(r, d)*100/r->terrain->max_road; + fprintf(F, "%d;prozent\n", p); + } + } + b = b->next; + } + } } /* main function of the creport. creates the header and traverses all regions */ @@ -1105,24 +1111,24 @@ report_computer(const char * filename, report_context * ctx) fprintf(F, "VERSION %d\n", C_REPORT_VERSION); fprintf(F, "\"%s\";locale\n", locale_name(f->locale)); - fprintf(F, "%d;noskillpoints\n", 1); - fprintf(F, "%ld;date\n", ctx->report_time); - fprintf(F, "\"%s\";Spiel\n", global.gamename); - fprintf(F, "\"%s\";Konfiguration\n", "Standard"); - fprintf(F, "\"%s\";Koordinaten\n", "Hex"); - fprintf(F, "%d;Basis\n", 36); - fprintf(F, "%d;Runde\n", turn); - fputs("2;Zeitalter\n", F); - if (mailto!=NULL) { - fprintf(F, "\"%s\";mailto\n", mailto); - fprintf(F, "\"%s\";mailcmd\n", locale_string(f->locale, "mailcmd")); - } - fprintf(F, "PARTEI %d\n", f->no); - fprintf(F, "\"%s\";locale\n", locale_name(f->locale)); + fprintf(F, "%d;noskillpoints\n", 1); + fprintf(F, "%ld;date\n", ctx->report_time); + fprintf(F, "\"%s\";Spiel\n", global.gamename); + fprintf(F, "\"%s\";Konfiguration\n", "Standard"); + fprintf(F, "\"%s\";Koordinaten\n", "Hex"); + fprintf(F, "%d;Basis\n", 36); + fprintf(F, "%d;Runde\n", turn); + fputs("2;Zeitalter\n", F); + if (mailto!=NULL) { + fprintf(F, "\"%s\";mailto\n", mailto); + fprintf(F, "\"%s\";mailcmd\n", locale_string(f->locale, "mailcmd")); + } + fprintf(F, "PARTEI %d\n", f->no); + fprintf(F, "\"%s\";locale\n", locale_name(f->locale)); fprintf(F, "%d;age\n", f->age); - fprintf(F, "%d;Optionen\n", f->options); + fprintf(F, "%d;Optionen\n", f->options); #ifdef SCORE_MODULE - if (f->options & want(O_SCORE) && f->age>DISPLAYSCORE) { + if (f->options & want(O_SCORE) && f->age>DISPLAYSCORE) { score = f->score; avgscore = average_score_of_age(f->age, f->age / 24 + 1); } @@ -1130,23 +1136,23 @@ report_computer(const char * filename, report_context * ctx) fprintf(F, "%d;Punktedurchschnitt\n", avgscore); #endif { - const char * zRace = rc_name(f->race, 1); - fprintf(F, "\"%s\";Typ\n", add_translation(zRace, LOC(f->locale, zRace))); - } + const char * zRace = rc_name(f->race, 1); + fprintf(F, "\"%s\";Typ\n", add_translation(zRace, LOC(f->locale, zRace))); + } prefix = get_prefix(f->attribs); - if (prefix!=NULL) { + if (prefix!=NULL) { prefix = mkname("prefix", prefix); - fprintf(F, "\"%s\";typprefix\n", + fprintf(F, "\"%s\";typprefix\n", add_translation(prefix, LOC(f->locale, prefix))); - } - fprintf(F, "%d;Rekrutierungskosten\n", f->race->recruitcost); - fprintf(F, "%d;Anzahl Personen\n", count_all(f)); - fprintf(F, "\"%s\";Magiegebiet\n", magietypen[f->magiegebiet]); + } + fprintf(F, "%d;Rekrutierungskosten\n", f->race->recruitcost); + fprintf(F, "%d;Anzahl Personen\n", count_all(f)); + fprintf(F, "\"%s\";Magiegebiet\n", magietypen[f->magiegebiet]); - if (f->race == new_race[RC_HUMAN]) { - fprintf(F, "%d;Anzahl Immigranten\n", count_migrants(f)); - fprintf(F, "%d;Max. Immigranten\n", count_maxmigrants(f)); - } + if (f->race == new_race[RC_HUMAN]) { + fprintf(F, "%d;Anzahl Immigranten\n", count_migrants(f)); + fprintf(F, "%d;Max. Immigranten\n", count_maxmigrants(f)); + } #ifdef HEROES i = countheroes(f); @@ -1160,80 +1166,80 @@ report_computer(const char * filename, report_context * ctx) } fprintf(F, "\"%s\";Parteiname\n", f->name); - fprintf(F, "\"%s\";email\n", f->email); - fprintf(F, "\"%s\";banner\n", f->banner); + fprintf(F, "\"%s\";email\n", f->email); + fprintf(F, "\"%s\";banner\n", f->banner); print_items(F, f->items, f->locale); - fputs("OPTIONEN\n", F); - for (i=0;i!=MAXOPTIONS;++i) { - fprintf(F, "%d;%s\n", (f->options&want(i))?1:0, options[i]); - } + fputs("OPTIONEN\n", F); + for (i=0;i!=MAXOPTIONS;++i) { + fprintf(F, "%d;%s\n", (f->options&want(i))?1:0, options[i]); + } #ifdef ENEMIES show_enemies(F, f->enemies); #endif - show_allies(F, f, f->allies); - { - group * g; - for (g=f->groups;g;g=g->next) { + show_allies(F, f, f->allies); + { + group * g; + for (g=f->groups;g;g=g->next) { - fprintf(F, "GRUPPE %d\n", g->gid); - fprintf(F, "\"%s\";name\n", g->name); + fprintf(F, "GRUPPE %d\n", g->gid); + fprintf(F, "\"%s\";name\n", g->name); prefix = get_prefix(g->attribs); - if (prefix!=NULL) { + if (prefix!=NULL) { prefix = mkname("prefix", prefix); - fprintf(F, "\"%s\";typprefix\n", + fprintf(F, "\"%s\";typprefix\n", add_translation(prefix, LOC(f->locale, prefix))); - } - show_allies(F, f, g->allies); - } - } + } + show_allies(F, f, g->allies); + } + } - cr_output_messages(F, f->msgs, f); - { - struct bmsg * bm; - for (bm=f->battles;bm;bm=bm->next) { - if (!rplane(bm->r)) fprintf(F, "BATTLE %d %d\n", region_x(bm->r, f), region_y(bm->r, f)); - else { - if (rplane(bm->r)->flags & PFL_NOCOORDS) fprintf(F, "BATTLESPEC %d %d\n", encode_region(f, bm->r), rplane(bm->r)->id); - else fprintf(F, "BATTLE %d %d %d\n", region_x(bm->r, f), region_y(bm->r, f), rplane(bm->r)->id); - } - cr_output_messages(F, bm->msgs, f); - } - } + cr_output_messages(F, f->msgs, f); + { + struct bmsg * bm; + for (bm=f->battles;bm;bm=bm->next) { + if (!rplane(bm->r)) fprintf(F, "BATTLE %d %d\n", region_x(bm->r, f), region_y(bm->r, f)); + else { + if (rplane(bm->r)->flags & PFL_NOCOORDS) fprintf(F, "BATTLESPEC %d %d\n", encode_region(f, bm->r), rplane(bm->r)->id); + else fprintf(F, "BATTLE %d %d %d\n", region_x(bm->r, f), region_y(bm->r, f), rplane(bm->r)->id); + } + cr_output_messages(F, bm->msgs, f); + } + } - cr_find_address(F, f, ctx->addresses); - a = a_find(f->attribs, &at_reportspell); - while (a && a->type==&at_reportspell) { + cr_find_address(F, f, ctx->addresses); + a = a_find(f->attribs, &at_reportspell); + while (a && a->type==&at_reportspell) { spell *sp = (spell *)a->data.v; - cr_reportspell(F, sp, f->locale); - a = a->next; - } - for (a=a_find(f->attribs, &at_showitem);a && a->type==&at_showitem;a=a->next) { - const potion_type * ptype = resource2potion(((const item_type*)a->data.v)->rtype); - requirement * m; - const char * ch, * description = NULL; + cr_reportspell(F, sp, f->locale); + a = a->next; + } + for (a=a_find(f->attribs, &at_showitem);a && a->type==&at_showitem;a=a->next) { + const potion_type * ptype = resource2potion(((const item_type*)a->data.v)->rtype); + requirement * m; + const char * ch, * description = NULL; if (ptype==NULL) continue; - m = ptype->itype->construction->materials; - ch = resourcename(ptype->itype->rtype, 0); - fprintf(F, "TRANK %d\n", hashstring(ch)); - fprintf(F, "\"%s\";Name\n", add_translation(ch, locale_string(f->locale, ch))); - fprintf(F, "%d;Stufe\n", ptype->level); + m = ptype->itype->construction->materials; + ch = resourcename(ptype->itype->rtype, 0); + fprintf(F, "TRANK %d\n", hashstring(ch)); + fprintf(F, "\"%s\";Name\n", add_translation(ch, locale_string(f->locale, ch))); + fprintf(F, "%d;Stufe\n", ptype->level); if (description==NULL) { const char * pname = resourcename(ptype->itype->rtype, 0); const char * potiontext = mkname("potion", pname); description = LOC(f->locale, potiontext); } - - fprintf(F, "\"%s\";Beschr\n", description); - fprintf(F, "ZUTATEN\n"); - while (m->number) { - ch = resourcename(m->rtype, 0); - fprintf(F, "\"%s\"\n", add_translation(ch, locale_string(f->locale, ch))); - m++; - } - } + fprintf(F, "\"%s\";Beschr\n", description); + fprintf(F, "ZUTATEN\n"); + + while (m->number) { + ch = resourcename(m->rtype, 0); + fprintf(F, "\"%s\"\n", add_translation(ch, locale_string(f->locale, ch))); + m++; + } + } /* traverse all regions */ for (r=ctx->first;sr==NULL && r!=ctx->last;r=r->next) { @@ -1243,7 +1249,7 @@ report_computer(const char * filename, report_context * ctx) region * r = sr->r; int modifier = 0; const char * tname; - + if (!rplane(r)) { if (opt_cr_absolute_coords) { fprintf(F, "REGION %d %d\n", r->x, r->x); @@ -1264,10 +1270,10 @@ report_computer(const char * filename, report_context * ctx) else { tname = terrain_name(r); } - + fprintf(F, "\"%s\";Terrain\n", add_translation(tname, locale_string(f->locale, tname))); if (sr->mode!=see_unit) fprintf(F, "\"%s\";visibility\n", visibility[sr->mode]); - + { faction * owner = region_owner(r); if (owner) { @@ -1304,13 +1310,13 @@ report_computer(const char * filename, report_context * ctx) fprintf(F, "1;Verorkt\n"); } fprintf(F, "%d;Pferde\n", rhorses(r)); - + if (sr->mode>=see_unit) { struct demand * dmd = r->land->demands; struct rawmaterial * res = r->resources; fprintf(F, "%d;Silber\n", rmoney(r)); fprintf(F, "%d;Unterh\n", entertainmoney(r)); - + if (is_cursed(r->attribs, C_RIOT, 0)){ fprintf(F, "0;Rekruten\n"); } else { @@ -1319,7 +1325,7 @@ report_computer(const char * filename, report_context * ctx) if (production(r)) { fprintf(F, "%d;Lohn\n", wage(r, f, f->race)); } - + while (res) { int maxskill = 0; int level = -1; @@ -1376,7 +1382,7 @@ report_computer(const char * filename, report_context * ctx) { /* Sonderbehandlung Teleport-Ebene */ region_list *rl = astralregions(r, inhabitable); - + if (rl) { region_list *rl2 = rl; while(rl2) { @@ -1389,7 +1395,7 @@ report_computer(const char * filename, report_context * ctx) free_regionlist(rl); } } - + /* describe both passed and inhabited regions */ show_active_spells(r); if (fval(r, RF_TRAVELUNIT)) { @@ -1430,7 +1436,7 @@ report_computer(const char * filename, report_context * ctx) } cr_output_buildings(F, b, u, fno, f); } - + /* ships */ for (sh = r->ships; sh; sh = sh->next) { int fno = -1; @@ -1439,10 +1445,10 @@ report_computer(const char * filename, report_context * ctx) const faction * sf = visible_faction(f,u); fno = sf->no; } - + cr_output_ship(F, sh, u, fno, f, r); } - + /* visible units */ for (u = r->units; u; u = u->next) { boolean visible = true; @@ -1487,7 +1493,7 @@ crwritemap(const char * filename) fprintf(F, "\"%s\";Name\n\"%s\";Terrain\n", rname(r, default_locale), LOC(default_locale, terrain_name(r))); } fclose(F); - return 0; + return 0; } void diff --git a/src/eressea/gmtool.c b/src/eressea/gmtool.c index cd7e24c87..9ffa9bb86 100644 --- a/src/eressea/gmtool.c +++ b/src/eressea/gmtool.c @@ -61,6 +61,17 @@ #include #include +typedef struct window { + boolean (*handlekey)(struct window * win, struct state * st, int key); + void (*paint)(struct window * win, const struct state * st); + + WINDOW * handle; + struct window * next; + struct window * prev; + boolean initialized; + int update; +} window; + extern char * g_reportdir; extern char * g_datadir; extern char * g_basedir; @@ -70,6 +81,8 @@ static int g_quit; static const char * g_logfile = "gmtool.log"; static int force_color = 0; +state * current_state = NULL; + #define IFL_SHIPS (1<<0) #define IFL_UNITS (1<<1) #define IFL_FACTIONS (1<<2) @@ -259,7 +272,7 @@ init_curses(void) refresh(); } -static map_region * +map_region * mr_get(const view * vi, int xofs, int yofs) { return vi->regions + xofs + yofs * vi->extent.width; @@ -416,7 +429,7 @@ paint_map(window * wnd, const state * st) } } -static map_region * +map_region * cursor_region(const view * v, const coordinate * c) { coordinate relpos; @@ -1175,6 +1188,7 @@ run_mapper(void) coor2point(&st.display.topleft, &tl); hstatus = st.wnd_status->handle; /* the lua console needs this */ + current_state = &st; while (!g_quit) { int c; @@ -1232,6 +1246,7 @@ run_mapper(void) } curs_set(1); endwin(); + current_state = NULL; } #define MAXINPUT 512 diff --git a/src/eressea/gmtool.h b/src/eressea/gmtool.h index 9699213e1..93259b3ea 100644 --- a/src/eressea/gmtool.h +++ b/src/eressea/gmtool.h @@ -17,7 +17,6 @@ extern "C" { struct lua_State; extern int gmmain(int argc, char *argv[]); extern int curses_readline(struct lua_State * L, const char * prompt); - #ifdef __cplusplus } #endif diff --git a/src/eressea/gmtool.vcproj b/src/eressea/gmtool.vcproj index 6000af092..4650e518f 100644 --- a/src/eressea/gmtool.vcproj +++ b/src/eressea/gmtool.vcproj @@ -239,6 +239,9 @@ + + diff --git a/src/eressea/gmtool_structs.h b/src/eressea/gmtool_structs.h index 09cd391f2..0f3b90c92 100644 --- a/src/eressea/gmtool_structs.h +++ b/src/eressea/gmtool_structs.h @@ -11,6 +11,10 @@ #ifndef H_GMTOOL_STRUCTS #define H_GMTOOL_STRUCTS +#ifdef __cplusplus +extern "C" { +#endif + /* types imported from eressea: */ struct region; @@ -65,18 +69,14 @@ typedef struct state { struct window * wnd_status; } state; -typedef struct window { - boolean (*handlekey)(struct window * win, struct state * st, int key); - void (*paint)(struct window * win, const struct state * st); - - WINDOW * handle; - struct window * next; - struct window * prev; - boolean initialized; - int update; -} window; +extern map_region * cursor_region(const view * v, const coordinate * c); +extern state * current_state; #define TWIDTH 2 /* width of tile */ #define THEIGHT 1 /* height of tile */ +#ifdef __cplusplus +} +#endif + #endif diff --git a/src/eressea/lua/bindings.h b/src/eressea/lua/bindings.h index 18102b057..6c461af64 100644 --- a/src/eressea/lua/bindings.h +++ b/src/eressea/lua/bindings.h @@ -1,6 +1,8 @@ #ifndef LUA_BINDINGS_H #define LUA_BINDINGS_H +extern bool is_function(struct lua_State * L, const char * fname); + extern void bind_region(struct lua_State * L); extern void bind_unit(struct lua_State * L); extern void bind_ship(struct lua_State * L); @@ -13,9 +15,12 @@ extern void bind_item(struct lua_State * L); extern void bind_event(struct lua_State * L); extern void bind_message(struct lua_State * L); extern void bind_objects(struct lua_State * L); + +/* server only */ extern void bind_script(struct lua_State * L); extern void bind_gamecode(struct lua_State * L); -extern bool is_function(struct lua_State * L, const char * fname); +/* gmtool only */ +extern void bind_gmtool(lua_State * L); #endif diff --git a/src/eressea/lua/gm.cpp b/src/eressea/lua/gm.cpp new file mode 100644 index 000000000..10a7c776d --- /dev/null +++ b/src/eressea/lua/gm.cpp @@ -0,0 +1,70 @@ +#include +#include + +#include "bindings.h" +#include "list.h" +#include "../gmtool_structs.h" + +#include + +// lua includes +#include +#include +#include + +using namespace luabind; + +region * +current_region(void) +{ + map_region * mr = cursor_region(¤t_state->display, ¤t_state->cursor); + return mr->r; +} + +static tag * +next_tag(int hash, const state * st) +{ + while (hash!=MAXTHASH) { + tag * t = st->selected->tags[hash]; + if (t!=NULL) return t; + ++hash; + } + return NULL; +} + +class selectedregion { +public: + static tag * next(tag * node) { + if (node->nexthash) { + return node->nexthash; + } + coordinate * c = &node->coord; + unsigned int key = ((c->x << 12) ^ c->y); + unsigned int hash = key & (MAXTHASH-1); + + return next_tag(++hash, current_state); + } + + static region * value(tag * node) { + return findregion((short)node->coord.x, (short)node->coord.y); + } +}; + + +static eressea::list +selected_regions(void) +{ + return eressea::list(next_tag(0, current_state)); +} + +void +bind_gmtool(lua_State * L) +{ + module(L)[ + def("selected_regions", &selected_regions, return_stl_iterator), + def("current_region", ¤t_region) + ]; +#ifdef LUABIND_NO_EXCEPTIONS + luabind::set_error_callback(error_callback); +#endif +}