Fix empdump not to depend on POGO's origin
Treat NATID_BAD as deity with absolute coordinates in nstr_exec_val() and xdinit(). Use that in dump_table().
This commit is contained in:
parent
9c2a05e126
commit
ee863c5d25
3 changed files with 31 additions and 11 deletions
|
@ -61,7 +61,8 @@ nstr_mksymval(struct valstr *val, struct castr *ca, int idx)
|
||||||
/*
|
/*
|
||||||
* Evaluate VAL.
|
* Evaluate VAL.
|
||||||
* If VAL is symbolic, evaluate it into a promoted value type.
|
* If VAL is symbolic, evaluate it into a promoted value type.
|
||||||
* Use country CNUM's coordinate system and access control.
|
* Translate it for country CNUM (coordinate system and contact
|
||||||
|
* status), except when CNUM is NATID_BAD.
|
||||||
* PTR points to a context object of the type that was used to compile
|
* PTR points to a context object of the type that was used to compile
|
||||||
* the value.
|
* the value.
|
||||||
* Unless WANT is NSC_NOTYPE, coerce the value to promoted value type
|
* Unless WANT is NSC_NOTYPE, coerce the value to promoted value type
|
||||||
|
@ -74,6 +75,7 @@ nstr_exec_val(struct valstr *val, natid cnum, void *ptr, enum nsc_type want)
|
||||||
char *memb_ptr;
|
char *memb_ptr;
|
||||||
enum nsc_type valtype;
|
enum nsc_type valtype;
|
||||||
int idx;
|
int idx;
|
||||||
|
coord c;
|
||||||
struct natstr *natp;
|
struct natstr *natp;
|
||||||
|
|
||||||
if (CANT_HAPPEN(want != NSC_NOTYPE && !NSC_IS_PROMOTED(want)))
|
if (CANT_HAPPEN(want != NSC_NOTYPE && !NSC_IS_PROMOTED(want)))
|
||||||
|
@ -119,19 +121,35 @@ nstr_exec_val(struct valstr *val, natid cnum, void *ptr, enum nsc_type want)
|
||||||
val->val_as.lng = ((long *)memb_ptr)[idx];
|
val->val_as.lng = ((long *)memb_ptr)[idx];
|
||||||
break;
|
break;
|
||||||
case NSC_XCOORD:
|
case NSC_XCOORD:
|
||||||
val->val_as.lng = xrel(getnatp(cnum), ((short *)memb_ptr)[idx]);
|
c = ((short *)memb_ptr)[idx];
|
||||||
|
if (cnum == NATID_BAD) {
|
||||||
|
/* FIXME use variant of xrel() that takes orig instead of nation */
|
||||||
|
if (c >= WORLD_X / 2)
|
||||||
|
c -= WORLD_X;
|
||||||
|
} else
|
||||||
|
c = xrel(getnatp(cnum), c);
|
||||||
|
val->val_as.lng = c;
|
||||||
break;
|
break;
|
||||||
case NSC_YCOORD:
|
case NSC_YCOORD:
|
||||||
val->val_as.lng = yrel(getnatp(cnum), ((short *)memb_ptr)[idx]);
|
c = ((short *)memb_ptr)[idx];
|
||||||
|
if (cnum == NATID_BAD) {
|
||||||
|
/* FIXME use variant of yrel() that takes orig instead of nation */
|
||||||
|
if (c >= WORLD_Y / 2)
|
||||||
|
c -= WORLD_Y;
|
||||||
|
} else
|
||||||
|
c = yrel(getnatp(cnum), c);
|
||||||
|
val->val_as.lng = c;
|
||||||
break;
|
break;
|
||||||
case NSC_HIDDEN:
|
case NSC_HIDDEN:
|
||||||
val->val_as.lng = -1;
|
val->val_as.lng = -1;
|
||||||
if (CANT_HAPPEN(((struct natstr *)ptr)->ef_type != EF_NATION))
|
if (CANT_HAPPEN(((struct natstr *)ptr)->ef_type != EF_NATION))
|
||||||
break;
|
break;
|
||||||
|
if (!opt_HIDDEN && cnum != NATID_BAD) {
|
||||||
natp = getnatp(cnum);
|
natp = getnatp(cnum);
|
||||||
if (!opt_HIDDEN
|
if (natp->nat_stat != STAT_GOD
|
||||||
|| natp->nat_stat == STAT_GOD
|
&& !(getcontact(natp, idx) && getcontact(ptr, idx)))
|
||||||
|| (getcontact(natp, idx) && getcontact(ptr, idx)))
|
break;
|
||||||
|
}
|
||||||
val->val_as.lng = ((unsigned char *)memb_ptr)[idx];
|
val->val_as.lng = ((unsigned char *)memb_ptr)[idx];
|
||||||
break;
|
break;
|
||||||
case NSC_FLOAT:
|
case NSC_FLOAT:
|
||||||
|
|
|
@ -82,7 +82,8 @@
|
||||||
#include "xdump.h"
|
#include "xdump.h"
|
||||||
|
|
||||||
/*
|
/*
|
||||||
* Initialize XD to dump for country CNUM.
|
* Initialize XD.
|
||||||
|
* Translate dump for country CNUM, except when CNUM is NATID_BAD.
|
||||||
* If HUMAN, dump in human-readable format.
|
* If HUMAN, dump in human-readable format.
|
||||||
* Dump is to be delivered through callback PR.
|
* Dump is to be delivered through callback PR.
|
||||||
* Return XD.
|
* Return XD.
|
||||||
|
@ -91,7 +92,7 @@ struct xdstr *
|
||||||
xdinit(struct xdstr *xd, natid cnum, int human, void (*pr)(char *fmt, ...))
|
xdinit(struct xdstr *xd, natid cnum, int human, void (*pr)(char *fmt, ...))
|
||||||
{
|
{
|
||||||
xd->cnum = cnum;
|
xd->cnum = cnum;
|
||||||
xd->divine = getnatp(cnum)->nat_stat == STAT_GOD;
|
xd->divine = cnum == NATID_BAD || getnatp(cnum)->nat_stat == STAT_GOD;
|
||||||
xd->human = human;
|
xd->human = human;
|
||||||
xd->pr = pr;
|
xd->pr = pr;
|
||||||
return xd;
|
return xd;
|
||||||
|
|
|
@ -40,6 +40,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
#include "file.h"
|
#include "file.h"
|
||||||
#include "optlist.h"
|
#include "optlist.h"
|
||||||
|
#include "nat.h"
|
||||||
#include "prototypes.h"
|
#include "prototypes.h"
|
||||||
#include "version.h"
|
#include "version.h"
|
||||||
#include "xdump.h"
|
#include "xdump.h"
|
||||||
|
@ -213,7 +214,7 @@ dump_table(int type, int human)
|
||||||
if (!ca)
|
if (!ca)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
xdinit(&xd, 0, human, printf_wrapper);
|
xdinit(&xd, NATID_BAD, human, printf_wrapper);
|
||||||
xdhdr(&xd, ef_nameof(type), 0);
|
xdhdr(&xd, ef_nameof(type), 0);
|
||||||
xdcolhdr(&xd, ca);
|
xdcolhdr(&xd, ca);
|
||||||
for (i = 0; (p = ef_ptr(type, i)); i++) {
|
for (i = 0; (p = ef_ptr(type, i)); i++) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue