Rassenpräfix-Code etwas aufgeräumt.

This commit is contained in:
Enno Rehling 2004-07-09 19:14:10 +00:00
parent 50b6823e28
commit 7bf7b22446
5 changed files with 38 additions and 24 deletions

View File

@ -16,7 +16,32 @@
#include <eressea.h>
#include "raceprefix.h"
#include <util/attrib.h>
#include <assert.h>
#include <string.h>
attrib_type at_raceprefix = {
"raceprefix", NULL, a_finalizestring, NULL, a_writestring, a_readstring, ATF_UNIQUE
};
void
set_prefix(attrib ** ap, const char * str)
{
attrib * a = a_find(*ap, &at_raceprefix);
if (a==NULL) {
a = a_add(ap, a_new(&at_raceprefix));
} else {
free(a->data.v);
}
assert(a->type==&at_raceprefix);
a->data.v = strdup(str);
}
const char *
get_prefix(const attrib * a)
{
a = a_findc(a, &at_raceprefix);
if (a==NULL) return NULL;
return (const char *)a->data.v;
}

View File

@ -20,7 +20,8 @@ extern "C" {
#endif
extern struct attrib_type at_raceprefix;
extern void set_prefix(struct attrib ** ap, const char * str);
extern const char * get_prefix(const struct attrib * a);
#ifdef __cplusplus
}

View File

@ -639,11 +639,9 @@ cr_output_unit(FILE * F, const region * r,
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 * ap = 0;
const attrib *a = a_find(u->attribs, &at_group);
if (a!=NULL) {
const group * g = (const group*)a->data.v;
ap = a_find(g->attribs, &at_raceprefix);
fprintf(F, "%d;gruppe\n", g->gid);
}
fprintf(F, "%d;Partei\n", u->faction->no);
@ -1072,6 +1070,7 @@ report_computer(FILE * F, faction * f, const faction_list * addresses,
const time_t report_time)
{
int i;
const char * prefix;
region * r;
building *b;
ship *sh;
@ -1116,10 +1115,9 @@ report_computer(FILE * F, faction * f, const faction_list * addresses,
const char * zRace = rc_name(f->race, 1);
fprintf(F, "\"%s\";Typ\n", add_translation(zRace, LOC(f->locale, zRace)));
}
a = a_find(f->attribs, &at_raceprefix);
if (a) {
const char * name = (const char*)a->data.v;
fprintf(F, "\"%s\";typprefix\n", add_translation(name, LOC(f->locale, name)));
prefix = get_prefix(f->attribs);
if (prefix!=NULL) {
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));
@ -1143,13 +1141,12 @@ report_computer(FILE * F, faction * f, const faction_list * addresses,
{
group * g;
for (g=f->groups;g;g=g->next) {
const attrib *a = a_find(g->attribs, &at_raceprefix);
fprintf(F, "GRUPPE %d\n", g->gid);
fprintf(F, "\"%s\";name\n", g->name);
if(a) {
const char * name = (const char*)a->data.v;
fprintf(F, "\"%s\";typprefix\n", add_translation(name, LOC(f->locale, name)));
prefix = get_prefix(g->attribs);
if (prefix!=NULL) {
fprintf(F, "\"%s\";typprefix\n", add_translation(prefix, LOC(f->locale, prefix)));
}
show_allies(F, f, g->allies);
}

View File

@ -1466,7 +1466,7 @@ static int
prefix_cmd(unit * u, struct order * ord)
{
attrib **ap;
attrib *a, *a2;
attrib *a;
int i;
const char *s;
@ -1498,12 +1498,7 @@ prefix_cmd(unit * u, struct order * ord)
ap = &u->faction->attribs;
a = a_find(u->attribs, &at_group);
if (a) ap = &((group*)a->data.v)->attribs;
a2 = a_find(*ap, &at_raceprefix);
if(!a2)
a2 = a_add(ap, a_new(&at_raceprefix));
a2->data.v = strdup(race_prefixes[i]);
set_prefix(ap, race_prefixes[i]);
return 0;
}

View File

@ -345,13 +345,9 @@ raceprefix(const unit *u)
{
const attrib * agroup = a_findc(u->attribs, &at_group);
const attrib * asource = u->faction->attribs;
const attrib * a2 = NULL;
if (agroup!=NULL) asource = ((const group *)(agroup->data.v))->attribs;
a2 = a_findc(asource, &at_raceprefix);
if (a2!=NULL) return (const char *)a2->data.v;
return NULL;
return get_prefix(asource);
}
const char *