/*
* Empire - A multi-player, client/server Internet based war game.
- * Copyright (C) 1986-2008, Dave Pare, Jeff Bailey, Thomas Ruschak,
+ * Copyright (C) 1986-2010, Dave Pare, Jeff Bailey, Thomas Ruschak,
* Ken Stevens, Steve McClure
*
* This program is free software; you can redistribute it and/or modify
* ---
*
* maps.c: Map routines
- *
+ *
* Known contributors to this file:
* Ken Stevens, 1995
* Steve McClure, 1998
+ * Markus Armbruster, 2004-2008
* Ron Koenderink, 2006
*/
#include "ship.h"
#include "xy.h"
+static int draw_map(int, char, int, struct nstr_sect *);
static int bmnxtsct(struct nstr_sect *);
-static char map_char(int type, natid own, int owner_or_god);
+static char map_char(int, natid, int);
+static int unit_map(int, int, struct nstr_sect *, char *);
int
do_map(int bmap, int unit_type, char *arg, char *map_flags_arg)
return draw_map(bmap, origin, map_flags, &ns);
}
-int
+static int
draw_map(int bmap, char origin, int map_flags, struct nstr_sect *nsp)
{
struct natstr *np;
}
}
if (!bitmap)
- bitmap = malloc((WORLD_X * WORLD_Y) / 8);
+ bitmap = malloc(WORLD_SZ() / 8);
if (!wmapbuf || !wmap || !bitmap) {
pr("Memory error, tell the deity.\n");
logerror("malloc failed in draw_map\n");
/* fall through */
case 'b':
while (bmnxtsct(nsp) && !player->aborted) {
- if (0 != (c = player->bmap[sctoff(nsp->x, nsp->y)]))
+ if (0 != (c = player->bmap[nsp->id]))
wmap[nsp->dy][nsp->dx] = c;
}
break;
case 't':
while (bmnxtsct(nsp) && !player->aborted) {
- if (0 != (c = player->map[sctoff(nsp->x, nsp->y)]))
+ if (0 != (c = player->map[nsp->id]))
wmap[nsp->dy][nsp->dx] = c;
}
break;
case 'r':
while (bmnxtsct(nsp) && !player->aborted) {
- player->bmap[sctoff(nsp->x, nsp->y)] =
- player->map[sctoff(nsp->x, nsp->y)];
- if (0 != (c = player->bmap[sctoff(nsp->x, nsp->y)]))
+ player->bmap[nsp->id] =
+ player->map[nsp->id];
+ if (0 != (c = player->bmap[nsp->id]))
wmap[nsp->dy][nsp->dx] = c;
}
ef_write(EF_BMAP, player->cnum, player->bmap);
struct sctstr sect;
if (!player->god) {
- memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
+ memset(bitmap, 0, WORLD_SZ() / 8);
bitinit2(nsp, bitmap, player->cnum);
}
while (nxtsct(nsp, §) && !player->aborted) {
int changed = 0;
if (!player->god) {
- memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
+ memset(bitmap, 0, WORLD_SZ() / 8);
bitinit2(nsp, bitmap, player->cnum);
}
while (nxtsct(nsp, §) && !player->aborted) {
i = 0;
while (ef_mappable[i] != EF_BAD) {
if (map_flags & ef_unit_map[i]) {
- snxtitem_all(&ni, ef_mappable[i]);
+ snxtitem_area(&ni, ef_mappable[i], &nsp->range);
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(unit.gen.x - nsp->range.lx);
- y = ynorm(unit.gen.y - nsp->range.ly);
+ x = deltx(&nsp->range, unit.gen.x);
+ y = delty(&nsp->range, unit.gen.y);
if (ef_mappable[i] == EF_NUKE)
wmap[y][x] = 'N';
else {
- if ((name = emp_obj_chr_name(&unit.gen)) == NULL)
- return RET_FAIL;
+ name = empobj_chr_name(&unit.gen);
wmap[y][x] = *name & ~0x20;
}
}
struct sctstr sect;
snxtsct_rewind(nsp);
- if (!player->god) {
- memset(bitmap, 0, (WORLD_X * WORLD_Y) / 8);
- bitinit2(nsp, bitmap, player->cnum);
- }
while (nxtsct(nsp, §) && !player->aborted) {
- if (!player->god && !emp_getbit(nsp->x, nsp->y, bitmap))
- continue;
if (sect.sct_own == player->cnum)
wmap[nsp->dy][nsp->dx] |= 0x80;
}
return '?';
}
-int
+static int
unit_map(int unit_type, int uid, struct nstr_sect *nsp, char *originp)
{
- struct empobj *gp;
+ union empobj_storage unit;
struct range range;
char *name;
- gp = get_empobjp(unit_type, uid);
- if (!gp || (gp->own != player->cnum && !player->god) || gp->own == 0)
+ if (CANT_HAPPEN((ef_flags(unit_type) & (EFF_OWNER | EFF_XY))
+ != (EFF_OWNER | EFF_XY)))
+ return RET_FAIL;
+
+ if (!get_empobj(unit_type, uid, &unit))
+ return RET_FAIL;
+ if (!player->owner || unit.gen.own == 0)
return RET_FAIL;
if (unit_type == EF_NUKE)
*originp = 'n';
else {
- if ((name = emp_obj_chr_name(gp)) == NULL)
- return RET_FAIL;
+ name = empobj_chr_name(&unit.gen);
*originp = *name;
}
- range.lx = xnorm(gp->x - 10);
- range.hx = xnorm(gp->x + 11);
- range.ly = ynorm(gp->y - 5);
- range.hy = ynorm(gp->y + 6);
+ range.lx = xnorm(unit.gen.x - 10);
+ range.hx = xnorm(unit.gen.x + 10);
+ range.ly = ynorm(unit.gen.y - 5);
+ range.hy = ynorm(unit.gen.y + 5);
xysize_range(&range);
snxtsct_area(nsp, &range);
return RET_OK;
np = getnatp(player->cnum);
sprintf(coordinates, "%d:%d,%d:%d",
- xrel(np, curx - 10), xrel(np, curx + 11),
- yrel(np, cury - 5), yrel(np, cury + 6));
+ xrel(np, curx - 10), xrel(np, curx + 10),
+ yrel(np, cury - 5), yrel(np, cury + 5));
arg = coordinates;
map_flag_arg = NULL;
} else {
from_des &= ~0x20;
while (nxtsct(ns, §)) {
- if (!(fromdes = from_bmap[sctoff(ns->x, ns->y)]))
+ if (!(fromdes = from_bmap[sect.sct_uid]))
continue;
- todes = to_bmap[sctoff(ns->x, ns->y)];
+ todes = to_bmap[sect.sct_uid];
if (todes &&
todes != '?' &&
todes != '.' && todes != ' ' && todes != from_des)