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 "map.h"
00038 #include "optlist.h"
00039
00040 int
00041 sct(void)
00042 {
00043 struct nstr_sect ns;
00044 struct sctstr sect;
00045 struct nscstr cond[NS_NCOND];
00046 struct range range;
00047 struct natstr *np;
00048 int ncond;
00049 int nsect;
00050 char *ptr;
00051 coord y, yval;
00052 int i;
00053
00054
00055 static char *mapbuf = NULL;
00056 static char **map = NULL;
00057
00058 nsect = 0;
00059 if (!snxtsct(&ns, player->argp[1]))
00060 return RET_SYN;
00061 if (!mapbuf)
00062 mapbuf = malloc(WORLD_Y * MAPWIDTH(1));
00063 if (!map) {
00064 map = malloc(WORLD_Y * sizeof(char *));
00065 if (map && mapbuf) {
00066 for (i = 0; i < WORLD_Y; i++)
00067 map[i] = &mapbuf[MAPWIDTH(1) * i];
00068 } else if (map) {
00069 free(map);
00070 map = NULL;
00071 }
00072 }
00073 if (!mapbuf || !map) {
00074 pr("Memory error, tell the deity.\n");
00075 logerror("malloc failed in sect\n");
00076 return RET_FAIL;
00077 }
00078 np = getnatp(player->cnum);
00079 ncond = ns.ncond;
00080 memcpy(cond, ns.cond, sizeof(*cond) * ncond);
00081 ns.ncond = 0;
00082 xyrelrange(getnatp(player->cnum), &ns.range, &range);
00083 border(&range, " ", "");
00084 blankfill(mapbuf, &ns.range, 1);
00085 while (nxtsct(&ns, §)) {
00086 if (!player->owner)
00087 continue;
00088 ptr = &map[ns.dy][ns.dx];
00089 *ptr = dchr[sect.sct_type].d_mnem;
00090 if (nstr_exec(cond, ncond, §)) {
00091 ++nsect;
00092 *ptr |= 0x80;
00093 }
00094 }
00095 for (i = 0, y = ns.range.ly; i < ns.range.height; y++, i++) {
00096 yval = yrel(np, y);
00097 pr("%3d %s %-3d\n", yval, map[i], yval);
00098 if (y >= WORLD_Y)
00099 y -= WORLD_Y;
00100 }
00101 border(&range, " ", "");
00102 if (nsect == 0) {
00103 if (player->argp[1])
00104 pr("%s: No sector(s)\n", player->argp[1]);
00105 else
00106 pr("%s: No sector(s)\n", "");
00107 return RET_FAIL;
00108 } else
00109 pr("%d sector%s\n", nsect, splur(nsect));
00110 return RET_OK;
00111 }