/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2006, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2007, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
struct natstr *np;
struct range range;
struct nstr_item ni;
- struct shpstr ship;
- struct lndstr land;
- struct plnstr plane;
- struct nukstr nuke;
+ union empobj_storage unit;
coord x, y;
int i;
/* Note this is not re-entrant anyway, so we keep the buffers
static unsigned char *bitmap = NULL;
static char *wmapbuf = NULL;
static char **wmap = NULL;
+ static int ef_mappable[] = { EF_PLANE, EF_SHIP, EF_LAND, EF_NUKE, EF_BAD };
+ static int ef_unit_map[] = { MAP_PLANE, MAP_SHIP, MAP_LAND, MAP_NUKE };
+ char *name;
if (!wmapbuf)
wmapbuf = malloc(WORLD_Y * MAPWIDTH(1));
}
if (player->aborted)
return RET_OK;
- if (map_flags & MAP_PLANE) {
- snxtitem_all(&ni, EF_PLANE);
- while (nxtitem(&ni, &plane)) {
- if (plane.pln_own == 0)
- continue;
- if (plane.pln_own != player->cnum && !player->god)
- continue;
- if (!xyinrange(plane.pln_x, plane.pln_y, &nsp->range))
- continue;
- x = xnorm(plane.pln_x - nsp->range.lx);
- y = ynorm(plane.pln_y - nsp->range.ly);
- wmap[y][x] = (*plchr[(int)plane.pln_type].pl_name) & ~0x20;
- }
- }
- if (map_flags & MAP_SHIP) {
- snxtitem_all(&ni, EF_SHIP);
- while (nxtitem(&ni, &ship)) {
- if (ship.shp_own == 0)
- continue;
- if (ship.shp_own != player->cnum && !player->god)
- continue;
- if (!xyinrange(ship.shp_x, ship.shp_y, &nsp->range))
- continue;
+ i = 0;
+ while (ef_mappable[i] != EF_BAD) {
+ if (map_flags & ef_unit_map[i]) {
+ snxtitem_all(&ni, ef_mappable[i]);
+ while (nxtitem(&ni, &unit)) {
+ if (unit.gen.own == 0)
+ continue;
+ if (unit.gen.own != player->cnum && !player->god)
+ continue;
+ if (!xyinrange(unit.gen.x, unit.gen.y, &nsp->range))
+ continue;
- x = xnorm(ship.shp_x - nsp->range.lx);
- y = ynorm(ship.shp_y - nsp->range.ly);
- wmap[y][x] = (*mchr[(int)ship.shp_type].m_name) & ~0x20;
- }
- }
- if (map_flags & MAP_LAND) {
- snxtitem_all(&ni, EF_LAND);
- while (nxtitem(&ni, &land)) {
- if (land.lnd_own == 0)
- continue;
- if (land.lnd_own != player->cnum && !player->god)
- continue;
- if (!xyinrange(land.lnd_x, land.lnd_y, &nsp->range))
- continue;
+ x = xnorm(unit.gen.x - nsp->range.lx);
+ y = ynorm(unit.gen.y - nsp->range.ly);
- x = xnorm(land.lnd_x - nsp->range.lx);
- y = ynorm(land.lnd_y - nsp->range.ly);
- wmap[y][x] = (*lchr[(int)land.lnd_type].l_name) & ~0x20;
- }
- }
- if (map_flags & MAP_NUKE) {
- snxtitem_all(&ni, EF_NUKE);
- while (nxtitem(&ni, &nuke)) {
- if (nuke.nuk_own == 0)
- continue;
- if (nuke.nuk_own != player->cnum && !player->god)
- continue;
- if (!xyinrange(nuke.nuk_x, nuke.nuk_y, &nsp->range))
- continue;
-
- x = xnorm(nuke.nuk_x - nsp->range.lx);
- y = ynorm(nuke.nuk_y - nsp->range.ly);
- wmap[y][x] = 'N';
+ if (ef_mappable[i] == EF_NUKE)
+ wmap[y][x] = 'N';
+ else {
+ if ((name = emp_obj_chr_name(&unit.gen)) == NULL)
+ return RET_FAIL;
+ wmap[y][x] = *name & ~0x20;
+ }
+ }
}
+ i++;
}
if (map_flags & MAP_HIGH) {
- char *ptr;
struct sctstr sect;
snxtsct_rewind(nsp);
while (nxtsct(nsp, §) && !player->aborted) {
if (!player->god && !emp_getbit(nsp->x, nsp->y, bitmap))
continue;
- ptr = &wmap[nsp->dy][nsp->dx];
if (sect.sct_own == player->cnum)
- *ptr |= 0x80;
+ wmap[nsp->dy][nsp->dx] |= 0x80;
}
}
if (origin)
int
unit_map(int unit_type, int uid, struct nstr_sect *nsp, char *originp)
{
- struct shpstr origs;
- struct lndstr origl;
- struct plnstr origp;
- struct nukstr orign;
struct empobj *gp;
struct range range;
+ char *name;
- if (unit_type == EF_LAND) {
- if (!getland(uid, &origl) || !player->owner || origl.lnd_own == 0)
- return RET_FAIL;
- gp = (struct empobj *)&origl;
- *originp = *lchr[(int)origl.lnd_type].l_name;
- } else if (unit_type == EF_PLANE) {
- if (!getplane(uid, &origp) || !player->owner || origp.pln_own == 0)
- return RET_FAIL;
- gp = (struct empobj *)&origp;
- *originp = *plchr[(int)origp.pln_type].pl_name;
- } else if (unit_type == EF_NUKE) {
- if (!getnuke(uid, &orign) || !player->owner || orign.nuk_own == 0)
- return RET_FAIL;
- gp = (struct empobj *)&orign;
+ gp = get_empobjp(unit_type, uid);
+ if (!gp || (gp->own != player->cnum && !player->god) || gp->own == 0)
+ return RET_FAIL;
+
+ if (unit_type == EF_NUKE)
*originp = 'n';
- } else {
- if (!getship(uid, &origs) || !player->owner || origs.shp_own == 0)
+ else {
+ if ((name = emp_obj_chr_name(gp)) == NULL)
return RET_FAIL;
- gp = (struct empobj *)&origs;
- *originp = *mchr[(int)origs.shp_type].m_name;
+ *originp = *name;
}
range.lx = xnorm(gp->x - 10);