00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <config.h>
00035
00036 #include "commands.h"
00037 #include "item.h"
00038 #include "map.h"
00039 #include "optlist.h"
00040 #include "path.h"
00041
00042 int
00043 rout(void)
00044 {
00045 struct ichrstr *ip;
00046 struct nstr_sect ns;
00047 struct natstr *natp;
00048 struct sctstr sect;
00049 struct nscstr cond[NS_NCOND];
00050 int ncond;
00051 struct range relrange;
00052 int row;
00053 int y;
00054 int ry;
00055 i_type i_del;
00056 int dir;
00057 char *p;
00058
00059
00060 static char *mapbuf = NULL;
00061 static char **map = NULL;
00062 static char *buf = NULL;
00063 int i;
00064
00065 if ((ip = whatitem(player->argp[1], "What item? ")) == 0)
00066 return RET_SYN;
00067 i_del = ip->i_uid;;
00068 if (!snxtsct(&ns, player->argp[2]))
00069 return RET_FAIL;
00070 if (!mapbuf)
00071 mapbuf = malloc(WORLD_Y * MAPWIDTH(3));
00072 if (!map) {
00073 map = malloc(WORLD_Y * sizeof(char *));
00074 if (map && mapbuf) {
00075 for (i = 0; i < WORLD_Y; i++)
00076 map[i] = &mapbuf[MAPWIDTH(3) * i];
00077 } else if (map) {
00078 free(map);
00079 map = NULL;
00080 }
00081 }
00082 if (!buf)
00083 buf = malloc(MAPWIDTH(3) + 12);
00084 if (!mapbuf || !map || !buf) {
00085 pr("Memory error, tell the deity.\n");
00086 logerror("malloc failed in rout\n");
00087 return RET_FAIL;
00088 }
00089 ncond = ns.ncond;
00090 memcpy(cond, ns.cond, sizeof(struct nscstr) * ncond);
00091 ns.ncond = 0;
00092
00093 natp = getnatp(player->cnum);
00094 xyrelrange(natp, &ns.range, &relrange);
00095 memset(mapbuf, 0, ((WORLD_Y * MAPWIDTH(3))));
00096 blankfill(mapbuf, &ns.range, 3);
00097 border(&relrange, " ", " ");
00098
00099 while (nxtsct(&ns, §)) {
00100 if (!player->owner)
00101 continue;
00102 p = &map[ns.dy][ns.dx * 2];
00103 if ((dir = sect.sct_del[i_del] & 0x7) &&
00104 nstr_exec(cond, ncond, §))
00105 memcpy(p, routech[dir][0], 3);
00106 p[1] = dchr[sect.sct_type].d_mnem;
00107 }
00108 for (row = 0, y = ns.range.ly; row < ns.range.height; y++, row++) {
00109 ry = yrel(natp, y);
00110 memset(buf, 0, (MAPWIDTH(3) + 10));
00111 sprintf(buf, "%4d ", ry);
00112 memcpy(buf + 5, map[row], ns.range.width * 2 + 1);
00113 sprintf(buf + 5 + ns.range.width * 2 + 1, " %-4d\n", ry);
00114 pr("%s", buf);
00115 if (y >= WORLD_Y)
00116 y -= WORLD_Y;
00117 }
00118 border(&relrange, " ", " ");
00119 return RET_OK;
00120 }