struct obj * mkobj(char oclass, boolean artif) { int tprob, i, prob = rnd(1000); if(oclass == RANDOM_CLASS) { const struct icp *iprobs = #ifdef REINCARNATION (Is_rogue_level(&u.uz)) ? (const struct icp *)rogueprobs : #endif Inhell ? (const struct icp *)hellprobs : (const struct icp *)mkobjprobs; for(tprob = rnd(100); (tprob -= iprobs->iprob) > 0; iprobs++); oclass = iprobs->iclass; } i = bases[(int)oclass]; while((prob -= objects[i].oc_prob) > 0) i++; if(objects[i].oc_class != oclass || !OBJ_NAME(objects[i])) panic("probtype error, oclass=%d i=%d", (int) oclass, i); return(mksobj(i, TRUE, artif)); }
struct obj *mkobj(struct level *lev, char oclass, boolean artif) { int tprob, i, prob = rnd(1000); if (oclass == RANDOM_CLASS) { const struct icp *iprobs = (Is_rogue_level(&lev->z)) ? (const struct icp *)rogueprobs : In_hell(&lev->z) ? (const struct icp *)hellprobs : (const struct icp *)mkobjprobs; for (tprob = rnd(100); (tprob -= iprobs->iprob) > 0; iprobs++); oclass = iprobs->iclass; } i = bases[(int)oclass]; while ((prob -= objects[i].oc_prob) > 0) i++; if (objects[i].oc_class != oclass || !OBJ_NAME(objects[i])) panic("probtype error, oclass=%d i=%d", (int) oclass, i); return mksobj(lev, i, TRUE, artif); }
/* Set map display mode */ void mswin_select_map_mode(int mode) { HMENU hmenuMap; PNHMainWindow data; winid map_id; map_id = WIN_MAP; data = (PNHMainWindow) GetWindowLong(GetNHApp()->hMainWnd, GWL_USERDATA); #if defined(WIN_CE_SMARTPHONE) /* Smartphone manu has only 2 items */ hmenuMap = _get_main_menu(ID_VIEW); #else hmenuMap = _get_main_menu(ID_MAP); #endif /* override for Rogue level */ if (Is_rogue_level(&u.uz) && !IS_MAP_ASCII(mode)) return; /* set map mode menu mark */ if (IS_MAP_ASCII(mode)) { CheckMenuRadioItem(hmenuMap, IDM_MAP_TILES, IDM_MAP_FIT_TO_SCREEN, mapmode2menuid(IS_MAP_FIT_TO_SCREEN(mode) ? data->mapAcsiiModeSave : mode), MF_BYCOMMAND); } else { CheckMenuRadioItem(hmenuMap, IDM_MAP_TILES, IDM_MAP_FIT_TO_SCREEN, mapmode2menuid(MAP_MODE_TILES), MF_BYCOMMAND); } #if defined(WIN_CE_SMARTPHONE) /* update "Fit To Screen" item text */ { TCHAR wbuf[BUFSZ]; TBBUTTONINFO tbbi; ZeroMemory(wbuf, sizeof(wbuf)); if (!LoadString(GetNHApp()->hApp, (IS_MAP_FIT_TO_SCREEN(mode) ? IDS_CAP_NORMALMAP : IDS_CAP_ENTIREMAP), wbuf, BUFSZ)) { panic("cannot load main menu strings"); } ZeroMemory(&tbbi, sizeof(tbbi)); tbbi.cbSize = sizeof(tbbi); tbbi.dwMask = TBIF_TEXT; tbbi.pszText = wbuf; if (!SendMessage(GetNHApp()->hMenuBar, TB_SETBUTTONINFO, IDM_MAP_FIT_TO_SCREEN, (LPARAM) &tbbi)) { error("Cannot update IDM_MAP_FIT_TO_SCREEN menu item."); } } #else /* set fit-to-screen mode mark */ CheckMenuItem(hmenuMap, IDM_MAP_FIT_TO_SCREEN, MF_BYCOMMAND | (IS_MAP_FIT_TO_SCREEN(mode) ? MF_CHECKED : MF_UNCHECKED)); #endif if (IS_MAP_ASCII(iflags.wc_map_mode) && !IS_MAP_FIT_TO_SCREEN(iflags.wc_map_mode)) { data->mapAcsiiModeSave = iflags.wc_map_mode; } iflags.wc_map_mode = mode; /* ** first, check if WIN_MAP has been inialized. ** If not - attempt to retrieve it by type, then check it again */ if (WIN_MAP != WIN_ERR) mswin_map_mode(mswin_hwnd_from_winid(WIN_MAP), mode); }
/* on WM_PAINT */ void onPaint(HWND hWnd) { PNHMapWindow data; PAINTSTRUCT ps; HDC hDC; HDC tileDC; HGDIOBJ saveBmp; RECT paint_rt; int i, j; /* get window data */ data = (PNHMapWindow) GetWindowLong(hWnd, GWL_USERDATA); hDC = BeginPaint(hWnd, &ps); /* calculate paint rectangle */ if (!IsRectEmpty(&ps.rcPaint)) { /* calculate paint rectangle */ paint_rt.left = max(data->xPos + (ps.rcPaint.left - data->map_orig.x) / data->xScrTile, 0); paint_rt.top = max( data->yPos + (ps.rcPaint.top - data->map_orig.y) / data->yScrTile, 0); paint_rt.right = min( data->xPos + (ps.rcPaint.right - data->map_orig.x) / data->xScrTile + 1, COLNO); paint_rt.bottom = min( data->yPos + (ps.rcPaint.bottom - data->map_orig.y) / data->yScrTile + 1, ROWNO); if (data->bAsciiMode || Is_rogue_level(&u.uz)) { /* You enter a VERY primitive world! */ HGDIOBJ oldFont; oldFont = SelectObject(hDC, data->hMapFont); SetBkMode(hDC, TRANSPARENT); /* draw the map */ for (i = paint_rt.left; i < paint_rt.right; i++) for (j = paint_rt.top; j < paint_rt.bottom; j++) if (data->map[i][j] >= 0) { char ch; TCHAR wch; RECT glyph_rect; int color; unsigned special; int mgch; HBRUSH back_brush; COLORREF OldFg; nhcoord2display(data, i, j, &glyph_rect); #if (VERSION_MAJOR < 4) && (VERSION_MINOR < 4) && (PATCHLEVEL < 2) nhglyph2charcolor(data->map[i][j], &ch, &color); OldFg = SetTextColor(hDC, nhcolor_to_RGB(color)); #else /* rely on NetHack core helper routine */ (void) mapglyph(data->map[i][j], &mgch, &color, &special, i, j); ch = (char) mgch; if (((special & MG_PET) && iflags.hilite_pet) || ((special & MG_DETECT) && iflags.use_inverse)) { back_brush = CreateSolidBrush(nhcolor_to_RGB(CLR_GRAY)); FillRect(hDC, &glyph_rect, back_brush); DeleteObject(back_brush); switch (color) { case CLR_GRAY: case CLR_WHITE: OldFg = SetTextColor( hDC, nhcolor_to_RGB(CLR_BLACK)); break; default: OldFg = SetTextColor(hDC, nhcolor_to_RGB(color)); } } else { OldFg = SetTextColor(hDC, nhcolor_to_RGB(color)); } #endif DrawText(hDC, NH_A2W(&ch, &wch, 1), 1, &glyph_rect, DT_CENTER | DT_VCENTER | DT_NOPREFIX); SetTextColor(hDC, OldFg); } SelectObject(hDC, oldFont); } else { /* prepare tiles DC for mapping */ tileDC = CreateCompatibleDC(hDC); saveBmp = SelectObject(tileDC, GetNHApp()->bmpMapTiles); /* draw the map */ for (i = paint_rt.left; i < paint_rt.right; i++) for (j = paint_rt.top; j < paint_rt.bottom; j++) if (data->map[i][j] >= 0) { short ntile; int t_x, t_y; RECT glyph_rect; ntile = glyph2tile[data->map[i][j]]; t_x = (ntile % GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_X; t_y = (ntile / GetNHApp()->mapTilesPerLine) * GetNHApp()->mapTile_Y; nhcoord2display(data, i, j, &glyph_rect); StretchBlt(hDC, glyph_rect.left, glyph_rect.top, data->xScrTile, data->yScrTile, tileDC, t_x, t_y, GetNHApp()->mapTile_X, GetNHApp()->mapTile_Y, SRCCOPY); if (glyph_is_pet(data->map[i][j]) && iflags.wc_hilite_pet) { /* apply pet mark transparently over pet image */ HDC hdcPetMark; HBITMAP bmPetMarkOld; /* this is DC for petmark bitmap */ hdcPetMark = CreateCompatibleDC(hDC); bmPetMarkOld = SelectObject( hdcPetMark, GetNHApp()->bmpPetMark); nhapply_image_transparent( hDC, glyph_rect.left, glyph_rect.top, data->xScrTile, data->yScrTile, hdcPetMark, 0, 0, TILE_X, TILE_Y, TILE_BK_COLOR); SelectObject(hdcPetMark, bmPetMarkOld); DeleteDC(hdcPetMark); } } SelectObject(tileDC, saveBmp); DeleteDC(tileDC); } /* draw focus rect */ nhcoord2display(data, data->xCur, data->yCur, &paint_rt); if (data->bAsciiMode) { PatBlt(hDC, paint_rt.left, paint_rt.top, paint_rt.right - paint_rt.left, paint_rt.bottom - paint_rt.top, DSTINVERT); } else { DrawFocusRect(hDC, &paint_rt); } } EndPaint(hWnd, &ps); }
int curses_convert_glyph(int ch, int glyph) { int symbol; #ifdef REINCARNATION if (Is_rogue_level(&u.uz)) { return ch; } #endif /* Save some processing time by returning if the glyph represents an object that we don't have custom characters for */ if (!glyph_is_cmap(glyph)) { return ch; } symbol = glyph_to_cmap(glyph); /* If user selected a custom character for this object, don't override this. */ if (((glyph_is_cmap(glyph)) && (ch != showsyms[symbol]))) { return ch; } switch (symbol) { case S_vwall: return ACS_VLINE; case S_hwall: return ACS_HLINE; case S_tlcorn: return ACS_ULCORNER; case S_trcorn: return ACS_URCORNER; case S_blcorn: return ACS_LLCORNER; case S_brcorn: return ACS_LRCORNER; case S_crwall: return ACS_PLUS; case S_tuwall: return ACS_BTEE; case S_tdwall: return ACS_TTEE; case S_tlwall: return ACS_RTEE; case S_trwall: return ACS_LTEE; case S_tree: return ACS_PLMINUS; case S_corr: return ACS_CKBOARD; case S_litcorr: return ACS_CKBOARD; } return ch; }
/* returns true if something happened */ boolean doorlock(struct obj * otmp, int x, int y) { struct rm *door = &level->locations[x][y]; boolean res = TRUE; int loudness = 0; int wandlevel = 0; if (otmp->oclass == WAND_CLASS) wandlevel = getwandlevel(&youmonst, otmp); /* Not completely right, but works since monsters wont use knock/wizlock */ const char *msg = NULL; const char *dustcloud = "A cloud of dust"; const char *quickly_dissipates = "quickly dissipates"; if (door->typ == SDOOR) { switch (otmp->otyp) { case WAN_OPENING: case SPE_KNOCK: case WAN_STRIKING: case SPE_FORCE_BOLT: door->typ = DOOR; door->doormask = D_CLOSED | (door->doormask & D_TRAPPED); newsym(x, y); if (cansee(x, y)) pline(msgc_youdiscover, "A door appears in the wall!"); if (otmp->otyp == WAN_OPENING || otmp->otyp == SPE_KNOCK) return TRUE; break; /* striking: continue door handling below */ case WAN_LOCKING: case SPE_WIZARD_LOCK: default: return FALSE; } } switch (otmp->otyp) { case WAN_LOCKING: case SPE_WIZARD_LOCK: if (Is_rogue_level(&u.uz)) { boolean vis = cansee(x, y); /* Can't have real locking in Rogue, so just hide doorway */ if (vis) pline(msgc_actionok, "%s springs up in the older, more primitive doorway.", dustcloud); else You_hear(msgc_actionok, "a swoosh."); if (obstructed(x, y, msgc_yafm)) { if (vis) pline(msgc_yafm, "The cloud %s.", quickly_dissipates); return FALSE; } block_point(x, y); door->typ = SDOOR; if (vis) pline(msgc_actionok, "The doorway vanishes!"); newsym(x, y); return TRUE; } if (obstructed(x, y, msgc_yafm)) return FALSE; /* Don't allow doors to close over traps. This is for pits */ /* & trap doors, but is it ever OK for anything else? */ if (t_at(level, x, y)) { /* maketrap() clears doormask, so it should be NODOOR */ pline(msgc_yafm, "%s springs up in the doorway, but %s.", dustcloud, quickly_dissipates); return FALSE; } if (wandlevel == P_MASTER) { pline(msgc_yafm, "%s springs up in the doorway and conceals it!", dustcloud); door->typ = SDOOR; newsym(x, y); return TRUE; } switch (door->doormask & ~D_TRAPPED) { case D_CLOSED: msg = "The door locks!"; break; case D_ISOPEN: msg = "The door swings shut, and locks!"; break; case D_BROKEN: msg = "The broken door reassembles and locks!"; break; case D_NODOOR: msg = "A cloud of dust springs up and assembles itself into a door!"; break; default: res = FALSE; break; } block_point(x, y); door->doormask = D_LOCKED | (door->doormask & D_TRAPPED); newsym(x, y); break; case WAN_OPENING: case SPE_KNOCK: if (door->doormask & D_LOCKED) { msg = "The door unlocks!"; door->doormask = D_CLOSED | (door->doormask & D_TRAPPED); } else res = FALSE; break; case WAN_STRIKING: case SPE_FORCE_BOLT: if (door->doormask & (D_LOCKED | D_CLOSED)) { if (door->doormask & D_TRAPPED) { if (MON_AT(level, x, y)) mb_trapped(m_at(level, x, y)); else { if (cansee(x, y)) pline(msgc_substitute, "KABOOM!! You see a door explode."); else You_hear(msgc_levelsound, "a distant explosion."); } door->doormask = D_NODOOR; unblock_point(x, y); newsym(x, y); loudness = 40; break; } door->doormask = D_BROKEN; if (cansee(x, y)) pline(msgc_actionok, "The door crashes open!"); else You_hear(msgc_levelsound, "a crashing sound."); unblock_point(x, y); newsym(x, y); /* force vision recalc before printing more messages */ if (turnstate.vision_full_recalc) vision_recalc(0); loudness = 20; } else res = FALSE; break; default: impossible("magic (%d) attempted on door.", otmp->otyp); break; } if (msg && cansee(x, y)) { pline(msgc_actionok, "%s", msg); /* we know whether it's locked now */ level->locations[x][y].mem_door_l = 1; map_background(x, y, TRUE); } if (loudness > 0) { /* door was destroyed */ wake_nearto(x, y, loudness); if (*in_rooms(level, x, y, SHOPBASE)) add_damage(x, y, 0L); } return res; }