#include <sys/types.h> #include <ctype.h> #include <stdio.h> #include <stdlib.h> #include <string.h> #include <time.h> #include "mud.h" bool kk = FALSE; /* Internal use */ bool mb = FALSE; /* Show all mobiles option */ bool noibm = FALSE; /* No Extended IBM char set option */ char outp[80][25]; /* Virtual Screen for character output */ char colrs[80][25]; /* Virtual Screen - numeric color values */ char smlmap[MAP_WIDTH][MAP_HEIGHT]; char smlcolors[MAP_WIDTH][MAP_HEIGHT]; char max_col[25]; bool now = FALSE; char cur_col = 0; char last_col; void clr (CHAR_DATA * ch) { write_to_buffer (ch->desc, "\x1B[37;0m\x1B[2J\x1B[1;1f", 0); return; } void gotoxy (CHAR_DATA * ch, int x, int y) { char tt[50]; sprintf (tt, "\x1B[%d;%df", y, x); write_to_buffer (ch->desc, tt, 0); return; } void do_drawrooms (CHAR_DATA * ch, char *argy) { DEFINE_COMMAND ("codeone", do_drawrooms, POSITION_DEAD, IMM_LEVEL, LOG_NORMAL, "This shows an overhead map of the current area around you.") do_rawclear(ch); if (!ch->desc) return; drawstuff(ch, argy, 23, 78); return; } void drawstuff (CHAR_DATA *ch, char* argy, int maxy, int maxx) { char *y = argy; if (IS_MOB(ch)) return; if (IS_SET(ch->pcdata->act2, PLR_NOIBM)) noibm = TRUE; else noibm = FALSE; mb = FALSE; for (; *y != '\0'; y++) { if (*y == 'N' || *y == 'n') noibm = TRUE; if (*y == 'M' || *y == 'm') mb = TRUE; if (*y == 'K' || *y == 'k') kk = TRUE; } bzero (outp, sizeof(outp)); bzero (colrs, sizeof(colrs)); ch->pcdata->maxx = maxx; ch->pcdata->maxy = maxy; go_display (ch, ch->in_room, (maxx/2), (maxy/2), maxy, maxx); outp[(maxx/2)][(maxy/2)] = '@'; colrs[(maxx/2)][(maxy/2)] = 7; draw_data (ch, maxy); write_to_buffer(ch->desc, "\x1B[0;37m", 0); gotoxy (ch, 1, maxy+1); undisplay(ch->in_room); gotoxy(ch, 1, ch->pcdata->pagelen); mb = FALSE; noibm = FALSE; return; } void undisplay (ROOM_DATA *rid) { int i; if (!IS_SET(rid->room_flags, R_MARK)) return; REMOVE_BIT(rid->room_flags, R_MARK); for (i = 0; i < 6; i++) if (rid->exit[i] && rid->exit[i]->to_room) undisplay(rid->exit[i]->to_room); return; } void go_display (CHAR_DATA * ch, ROOM_DATA * rid, int x, int y, int maxy, int maxx) { int i, newx = x, newy = y; if (x > maxx || x < 0 || y > maxy || y < 0) /* Boundary case stop */ return; if (IS_SET(rid->room_flags, R_MARK)) return; SET_BIT(rid->room_flags, R_MARK); if (mb && rid->people != NULL) { outp[x][y] = (rid->pcs > 0 ? 'P' : 'M'); } else { outp[x][y] = (noibm ? rid->noibm : rid->ibm); } colrs[x][y] = rid->color; if (x > max_col[y]) max_col[y] = x; for (i = 0; i < 4; i ++) { if (rid->exit[i] && rid->exit[i]->to_room) { if ((i % 2) == 0) newy += (i-1); else newx += (2-i); go_display(ch, rid->exit[i]->to_room, newx, newy, maxy, maxx); newy = y; newx = x; } } return; } /* Draw the actual data to the user's output buffer. */ void draw_data (CHAR_DATA * ch, int lines) { int i, j; char buf[100]; gotoxy (ch, 1, 1); /* Home cursor */ last_col = 0; /* Last column used for truncating trailing spaces */ for (i = 1; i <= lines; i++) { for (j = 1; j < ch->pcdata->maxx+1; j++) { if (outp[j][i] == '\0') /* Null -> Space */ { write_to_buffer (ch->desc, " ", 0); } else { sprintf(buf, "%s%c", ((colrs[j][i] == 0 || colrs[j][i] != last_col) ? color_table[colrs[j][i]].code : ""), outp[j][i]); last_col = colrs[j][i]; write_to_buffer(ch->desc, buf, 0); } } gotoxy(ch, 1, i+1); } send_to_char ("\x1B[0;37m", ch); /* Back to gray */ return; } void do_drawtop (CHAR_DATA * ch, char *argy) { char tt[50]; DEFINE_COMMAND ("drawtop", do_drawtop, POSITION_DEAD, IMM_LEVEL, LOG_NORMAL, "This command shows an updated map in the upper half of the screen.") if (!ch->desc) return; /* Vt100 windowing code - set up window */ drawstuff(ch, argy, 10, 78); write_to_buffer (ch->desc, "\x1B[0;37m", 0); send_to_char ("\x1B[10;1f\x1B[1;37m-------------------------------------------------------------------------------\x1B[0;37m", ch); sprintf (tt, "\x1B[%d;1f", ch->pcdata->pagelen); send_to_char (tt, ch); return; } void sml_display (CHAR_DATA * ch, ROOM_DATA * rid, int x, int y) { bool found = FALSE; int i, newx = x, newy = y; /* Stay within map boundaries */ if (x >= MAP_WIDTH || x < 0 || y >= MAP_HEIGHT || y < 0) return; /* Do not look at the same room twice. */ if (IS_SET(rid->room_flags, R_MARK)) return; SET_BIT(rid->room_flags, R_MARK); smlcolors[x][y] = rid->color; if (kk && rid->pcs > 0) { CHAR_DATA *rch; for(rch = rid->people; rch != NULL; rch=rch->next_in_room) { if (IS_PLAYER(rch) && !DIFF_ALIGN(ch, rch)) { found = TRUE; smlmap[x][y] = 'P'; smlcolors[x][y] = 12; break; } } } if (!found && mb) { CHAR_DATA *rch; for (rch = rid->people; rch != NULL; rch = rch->next_in_room) { if (IS_MOB(rch)) { found = TRUE; smlmap[x][y] = rch->pIndexData->symbol; smlcolors[x][y] = rch->pIndexData->color; break; } } } if (!found) smlmap[x][y] = (noibm ? rid->noibm : rid->ibm); for (i = 0; i < 4; i ++) { if (rid->exit[i] && rid->exit[i]->to_room) { if ((i % 2) == 0) newy += (i-1); else newx += (2-i); sml_display(ch, rid->exit[i]->to_room , newx, newy); newy = y; newx = x; } } return; } void small_map (CHAR_DATA *ch) { if (IS_MOB(ch)) return; if (ch->move <4) { send_to_char("You are too exhausted to make a map of the area around you.\n\r", ch); return; } ch->move -=2; if (IS_SET(ch->pcdata->act2, PLR_NOIBM)) noibm = TRUE; if (IS_SET(ch->pcdata->act2, PLR_VIEWMOBS)) mb = TRUE; if (IS_SET(ch->pcdata->act2, PLR_VIEWPLAYERS)) kk = TRUE; bzero (smlmap, sizeof(smlmap)); bzero (smlcolors, sizeof(smlcolors)); ch->pcdata->x = (MAP_WIDTH/2 + 1); ch->pcdata->y = (MAP_HEIGHT/2 + 1); sml_display(ch, ch->in_room, MAP_WIDTH/2, MAP_HEIGHT/2); smlmap[MAP_WIDTH/2][MAP_HEIGHT/2] = '@'; smlcolors[MAP_WIDTH/2][MAP_HEIGHT/2] = 7; draw_small (ch); write_to_buffer(ch->desc, "\x1B[0;37m", 0); undisplay(ch->in_room); gotoxy(ch, 1, ch->pcdata->pagelen); mb = FALSE; noibm = FALSE; kk = FALSE; return; } void draw_small (CHAR_DATA * ch) { int i, j; int currcolor = 0; char buf[100]; sprintf(buf, "\x1b[%d;%dr", MAP_HEIGHT, ch->pcdata->pagelen); send_to_char(buf, ch); gotoxy(ch,1,1); /* Now draw themap row by row... */ for (i = 0; i < MAP_HEIGHT; i++) { for (j = 0; j < MAP_WIDTH; j++) { if (smlmap[j][i] == '\0') { write_to_buffer (ch->desc, " ", 0); } else { sprintf(buf, "%s%c", ((smlcolors[j][i] != currcolor && smlcolors[j][i] != 0) ? color_table[smlcolors[j][i]].code : ""), smlmap[j][i]); write_to_buffer (ch->desc, buf, 0); currcolor = smlcolors[j][i]; } } send_to_char ("\n\r", ch); /* Next line */ } sprintf(buf, "\x1b[0;37m\x1b[%d;1f", ch->pcdata->pagelen); send_to_char(buf, ch); return; }