forked from github/server
make report_resource return an rtype, not a name.
This commit is contained in:
parent
d6ce1d9cfe
commit
0379a17350
|
@ -1094,12 +1094,12 @@ static void cr_reportspell(FILE * F, spell * sp, int level, const struct locale
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static char *cr_output_resource(char *buf, const char *name,
|
static char *cr_output_resource(char *buf, const resource_type *rtype,
|
||||||
const struct locale *loc, int amount, int level)
|
const struct locale *loc, int amount, int level)
|
||||||
{
|
{
|
||||||
assert(name);
|
assert(rtype);
|
||||||
buf += sprintf(buf, "RESOURCE %u\n", hashstring(name));
|
buf += sprintf(buf, "RESOURCE %u\n", hashstring(rtype->_name));
|
||||||
buf += sprintf(buf, "\"%s\";type\n", translate(name, LOC(loc, name)));
|
buf += sprintf(buf, "\"%s\";type\n", translate(rtype->_name, LOC(loc, rtype->_name)));
|
||||||
if (amount >= 0) {
|
if (amount >= 0) {
|
||||||
if (level >= 0)
|
if (level >= 0)
|
||||||
buf += sprintf(buf, "%d;skill\n", level);
|
buf += sprintf(buf, "%d;skill\n", level);
|
||||||
|
@ -1180,7 +1180,7 @@ void cr_output_resources(stream *out, const faction * f, const region *r, bool s
|
||||||
}
|
}
|
||||||
for (n = 0; n < size; ++n) {
|
for (n = 0; n < size; ++n) {
|
||||||
if (result[n].level >= 0 && result[n].number >= 0) {
|
if (result[n].level >= 0 && result[n].number >= 0) {
|
||||||
stream_printf(out, "%d;%s\n", result[n].number, crtag(result[n].name));
|
/* stream_printf(out, "%d;%s\n", result[n].number, crtag(result[n].name)); */
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
@ -1188,7 +1188,7 @@ void cr_output_resources(stream *out, const faction * f, const region *r, bool s
|
||||||
for (n = 0; n < size; ++n) {
|
for (n = 0; n < size; ++n) {
|
||||||
if (result[n].number >= 0) {
|
if (result[n].number >= 0) {
|
||||||
pos =
|
pos =
|
||||||
cr_output_resource(pos, result[n].name, f->locale, result[n].number,
|
cr_output_resource(pos, result[n].rtype, f->locale, result[n].number,
|
||||||
result[n].level);
|
result[n].level);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -58,6 +58,7 @@ static void test_cr_resources(CuTest *tc) {
|
||||||
struct locale *lang;
|
struct locale *lang;
|
||||||
|
|
||||||
test_setup();
|
test_setup();
|
||||||
|
init_resources();
|
||||||
lang = get_or_create_locale("de"); /* CR tags are translated from this */
|
lang = get_or_create_locale("de"); /* CR tags are translated from this */
|
||||||
locale_setstring(lang, "money", "Silber");
|
locale_setstring(lang, "money", "Silber");
|
||||||
locale_setstring(lang, "money_p", "Silber");
|
locale_setstring(lang, "money_p", "Silber");
|
||||||
|
|
|
@ -988,6 +988,11 @@ void init_resources(void)
|
||||||
rtype->itype = it_get_or_create(rtype);
|
rtype->itype = it_get_or_create(rtype);
|
||||||
rtype->itype->flags |= ITF_ANIMAL | ITF_BIG;
|
rtype->itype->flags |= ITF_ANIMAL | ITF_BIG;
|
||||||
|
|
||||||
|
rtype = rt_get_or_create(resourcenames[R_SAPLING]);
|
||||||
|
rtype = rt_get_or_create(resourcenames[R_TREE]);
|
||||||
|
rtype = rt_get_or_create(resourcenames[R_MALLORN_SAPLING]);
|
||||||
|
rtype = rt_get_or_create(resourcenames[R_MALLORN_TREE]);
|
||||||
|
|
||||||
/* "special" spell components */
|
/* "special" spell components */
|
||||||
rtype = rt_get_or_create(resourcenames[R_AURA]);
|
rtype = rt_get_or_create(resourcenames[R_AURA]);
|
||||||
rtype->uchange = res_changeaura;
|
rtype->uchange = res_changeaura;
|
||||||
|
|
|
@ -1005,7 +1005,7 @@ void report_region(struct stream *out, const region * r, faction * f)
|
||||||
for (n = 0; n < numresults; ++n) {
|
for (n = 0; n < numresults; ++n) {
|
||||||
if (result[n].number >= 0 && result[n].level >= 0) {
|
if (result[n].number >= 0 && result[n].level >= 0) {
|
||||||
bytes = snprintf(bufp, size, ", %d %s/%d", result[n].number,
|
bytes = snprintf(bufp, size, ", %d %s/%d", result[n].number,
|
||||||
LOC(f->locale, result[n].name), result[n].level);
|
LOC(f->locale, result[n].rtype->_name), result[n].level);
|
||||||
if (wrptr(&bufp, &size, bytes) != 0)
|
if (wrptr(&bufp, &size, bytes) != 0)
|
||||||
WARN_STATIC_BUFFER();
|
WARN_STATIC_BUFFER();
|
||||||
}
|
}
|
||||||
|
|
|
@ -346,11 +346,11 @@ report_items(const unit *u, item * result, int size, const unit * owner,
|
||||||
return n;
|
return n;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void report_resource(resource_report * result, const resource_type *rtype,
|
||||||
report_resource(resource_report * result, const char *name, int number,
|
int number, int level)
|
||||||
int level)
|
|
||||||
{
|
{
|
||||||
result->name = name;
|
assert(rtype);
|
||||||
|
result->rtype = rtype;
|
||||||
result->number = number;
|
result->number = number;
|
||||||
result->level = level;
|
result->level = level;
|
||||||
}
|
}
|
||||||
|
@ -408,37 +408,38 @@ const faction * viewer, bool see_unit)
|
||||||
int trees = rtrees(r, 2);
|
int trees = rtrees(r, 2);
|
||||||
int saplings = rtrees(r, 1);
|
int saplings = rtrees(r, 1);
|
||||||
bool mallorn = fval(r, RF_MALLORN) != 0;
|
bool mallorn = fval(r, RF_MALLORN) != 0;
|
||||||
|
const resource_type *rtype;
|
||||||
|
|
||||||
if (money) {
|
if (money) {
|
||||||
if (n >= size)
|
if (n >= size)
|
||||||
return -1;
|
return -1;
|
||||||
report_resource(result + n, "money", money, -1);
|
report_resource(result + n, get_resourcetype(R_SILVER), money, -1);
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
if (peasants) {
|
if (peasants) {
|
||||||
if (n >= size)
|
if (n >= size)
|
||||||
return -1;
|
return -1;
|
||||||
report_resource(result + n, "peasant", peasants, -1);
|
report_resource(result + n, get_resourcetype(R_PEASANT), peasants, -1);
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
if (horses) {
|
if (horses) {
|
||||||
if (n >= size)
|
if (n >= size)
|
||||||
return -1;
|
return -1;
|
||||||
report_resource(result + n, "horse", horses, -1);
|
report_resource(result + n, get_resourcetype(R_HORSE), horses, -1);
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
if (saplings) {
|
if (saplings) {
|
||||||
if (n >= size)
|
if (n >= size)
|
||||||
return -1;
|
return -1;
|
||||||
report_resource(result + n, mallorn ? "mallornsapling" : "sapling",
|
rtype = get_resourcetype(mallorn ? R_MALLORN_SAPLING : R_SAPLING);
|
||||||
saplings, -1);
|
report_resource(result + n, rtype, saplings, -1);
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
if (trees) {
|
if (trees) {
|
||||||
if (n >= size)
|
if (n >= size)
|
||||||
return -1;
|
return -1;
|
||||||
report_resource(result + n, mallorn ? "mallorn" : "tree", trees,
|
rtype = get_resourcetype(mallorn ? R_MALLORN_TREE : R_TREE);
|
||||||
-1);
|
report_resource(result + n, rtype, trees, -1);
|
||||||
++n;
|
++n;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -471,7 +472,7 @@ const faction * viewer, bool see_unit)
|
||||||
if (level >= 0 && visible >= 0) {
|
if (level >= 0 && visible >= 0) {
|
||||||
if (n >= size)
|
if (n >= size)
|
||||||
return -1;
|
return -1;
|
||||||
report_resource(result + n, res->type->rtype->_name, visible, level);
|
report_resource(result + n, res->type->rtype, visible, level);
|
||||||
n++;
|
n++;
|
||||||
}
|
}
|
||||||
res = res->next;
|
res = res->next;
|
||||||
|
|
|
@ -107,7 +107,7 @@ extern "C" {
|
||||||
} arg_regions;
|
} arg_regions;
|
||||||
|
|
||||||
typedef struct resource_report {
|
typedef struct resource_report {
|
||||||
const char *name;
|
const struct resource_type *rtype;
|
||||||
int number;
|
int number;
|
||||||
int level;
|
int level;
|
||||||
} resource_report;
|
} resource_report;
|
||||||
|
|
Loading…
Reference in New Issue