forked from github/server
Rassenpräfix-Code etwas aufgeräumt.
This commit is contained in:
parent
50b6823e28
commit
7bf7b22446
|
@ -16,7 +16,32 @@
|
||||||
#include <eressea.h>
|
#include <eressea.h>
|
||||||
#include "raceprefix.h"
|
#include "raceprefix.h"
|
||||||
|
|
||||||
|
#include <util/attrib.h>
|
||||||
|
|
||||||
|
#include <assert.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
attrib_type at_raceprefix = {
|
attrib_type at_raceprefix = {
|
||||||
"raceprefix", NULL, a_finalizestring, NULL, a_writestring, a_readstring, ATF_UNIQUE
|
"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;
|
||||||
|
}
|
||||||
|
|
|
@ -20,7 +20,8 @@ extern "C" {
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
extern struct attrib_type at_raceprefix;
|
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
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
|
|
|
@ -639,11 +639,9 @@ cr_output_unit(FILE * F, const region * r,
|
||||||
const attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
|
const attrib *a_otherfaction = a_find(u->attribs, &at_otherfaction);
|
||||||
const faction * otherfaction = a_otherfaction?get_otherfaction(a_otherfaction):NULL;
|
const faction * otherfaction = a_otherfaction?get_otherfaction(a_otherfaction):NULL;
|
||||||
/* my own faction, full info */
|
/* my own faction, full info */
|
||||||
const attrib * ap = 0;
|
|
||||||
const attrib *a = a_find(u->attribs, &at_group);
|
const attrib *a = a_find(u->attribs, &at_group);
|
||||||
if (a!=NULL) {
|
if (a!=NULL) {
|
||||||
const group * g = (const group*)a->data.v;
|
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;gruppe\n", g->gid);
|
||||||
}
|
}
|
||||||
fprintf(F, "%d;Partei\n", u->faction->no);
|
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)
|
const time_t report_time)
|
||||||
{
|
{
|
||||||
int i;
|
int i;
|
||||||
|
const char * prefix;
|
||||||
region * r;
|
region * r;
|
||||||
building *b;
|
building *b;
|
||||||
ship *sh;
|
ship *sh;
|
||||||
|
@ -1116,10 +1115,9 @@ report_computer(FILE * F, faction * f, const faction_list * addresses,
|
||||||
const char * zRace = rc_name(f->race, 1);
|
const char * zRace = rc_name(f->race, 1);
|
||||||
fprintf(F, "\"%s\";Typ\n", add_translation(zRace, LOC(f->locale, zRace)));
|
fprintf(F, "\"%s\";Typ\n", add_translation(zRace, LOC(f->locale, zRace)));
|
||||||
}
|
}
|
||||||
a = a_find(f->attribs, &at_raceprefix);
|
prefix = get_prefix(f->attribs);
|
||||||
if (a) {
|
if (prefix!=NULL) {
|
||||||
const char * name = (const char*)a->data.v;
|
fprintf(F, "\"%s\";typprefix\n", add_translation(prefix, LOC(f->locale, prefix)));
|
||||||
fprintf(F, "\"%s\";typprefix\n", add_translation(name, LOC(f->locale, name)));
|
|
||||||
}
|
}
|
||||||
fprintf(F, "%d;Rekrutierungskosten\n", f->race->recruitcost);
|
fprintf(F, "%d;Rekrutierungskosten\n", f->race->recruitcost);
|
||||||
fprintf(F, "%d;Anzahl Personen\n", count_all(f));
|
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;
|
group * g;
|
||||||
for (g=f->groups;g;g=g->next) {
|
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, "GRUPPE %d\n", g->gid);
|
||||||
fprintf(F, "\"%s\";name\n", g->name);
|
fprintf(F, "\"%s\";name\n", g->name);
|
||||||
if(a) {
|
prefix = get_prefix(g->attribs);
|
||||||
const char * name = (const char*)a->data.v;
|
if (prefix!=NULL) {
|
||||||
fprintf(F, "\"%s\";typprefix\n", add_translation(name, LOC(f->locale, name)));
|
fprintf(F, "\"%s\";typprefix\n", add_translation(prefix, LOC(f->locale, prefix)));
|
||||||
}
|
}
|
||||||
show_allies(F, f, g->allies);
|
show_allies(F, f, g->allies);
|
||||||
}
|
}
|
||||||
|
|
|
@ -1466,7 +1466,7 @@ static int
|
||||||
prefix_cmd(unit * u, struct order * ord)
|
prefix_cmd(unit * u, struct order * ord)
|
||||||
{
|
{
|
||||||
attrib **ap;
|
attrib **ap;
|
||||||
attrib *a, *a2;
|
attrib *a;
|
||||||
int i;
|
int i;
|
||||||
const char *s;
|
const char *s;
|
||||||
|
|
||||||
|
@ -1474,7 +1474,7 @@ prefix_cmd(unit * u, struct order * ord)
|
||||||
skip_token();
|
skip_token();
|
||||||
s = getstrtoken();
|
s = getstrtoken();
|
||||||
|
|
||||||
if(!*s) {
|
if (!*s) {
|
||||||
a = a_find(u->attribs, &at_group);
|
a = a_find(u->attribs, &at_group);
|
||||||
if (a) {
|
if (a) {
|
||||||
a_removeall(&((group*)a->data.v)->attribs, &at_raceprefix);
|
a_removeall(&((group*)a->data.v)->attribs, &at_raceprefix);
|
||||||
|
@ -1498,12 +1498,7 @@ prefix_cmd(unit * u, struct order * ord)
|
||||||
ap = &u->faction->attribs;
|
ap = &u->faction->attribs;
|
||||||
a = a_find(u->attribs, &at_group);
|
a = a_find(u->attribs, &at_group);
|
||||||
if (a) ap = &((group*)a->data.v)->attribs;
|
if (a) ap = &((group*)a->data.v)->attribs;
|
||||||
|
set_prefix(ap, race_prefixes[i]);
|
||||||
a2 = a_find(*ap, &at_raceprefix);
|
|
||||||
if(!a2)
|
|
||||||
a2 = a_add(ap, a_new(&at_raceprefix));
|
|
||||||
|
|
||||||
a2->data.v = strdup(race_prefixes[i]);
|
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
|
@ -345,13 +345,9 @@ raceprefix(const unit *u)
|
||||||
{
|
{
|
||||||
const attrib * agroup = a_findc(u->attribs, &at_group);
|
const attrib * agroup = a_findc(u->attribs, &at_group);
|
||||||
const attrib * asource = u->faction->attribs;
|
const attrib * asource = u->faction->attribs;
|
||||||
const attrib * a2 = NULL;
|
|
||||||
|
|
||||||
if (agroup!=NULL) asource = ((const group *)(agroup->data.v))->attribs;
|
if (agroup!=NULL) asource = ((const group *)(agroup->data.v))->attribs;
|
||||||
a2 = a_findc(asource, &at_raceprefix);
|
return get_prefix(asource);
|
||||||
|
|
||||||
if (a2!=NULL) return (const char *)a2->data.v;
|
|
||||||
return NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const char *
|
const char *
|
||||||
|
|
Loading…
Reference in New Issue