| 2187 | } |
| 2188 | |
| 2189 | BOOL |
| 2190 | initMapTiles(void) |
| 2191 | { |
| 2192 | HBITMAP hBmp; |
| 2193 | BITMAP bm; |
| 2194 | TCHAR wbuf[MAX_PATH]; |
| 2195 | DWORD errcode; |
| 2196 | int tl_num; |
| 2197 | SIZE map_size; |
| 2198 | extern int total_tiles_used; |
| 2199 | |
| 2200 | /* no file - no tile */ |
| 2201 | if (!(iflags.wc_tile_file && *iflags.wc_tile_file)) |
| 2202 | return TRUE; |
| 2203 | |
| 2204 | /* load bitmap */ |
| 2205 | hBmp = LoadImage(GetNHApp()->hApp, |
| 2206 | NH_A2W(iflags.wc_tile_file, wbuf, MAX_PATH), |
| 2207 | IMAGE_BITMAP, 0, 0, LR_LOADFROMFILE | LR_DEFAULTSIZE); |
| 2208 | if (hBmp == NULL) { |
| 2209 | char errmsg[BUFSZ]; |
| 2210 | |
| 2211 | errcode = GetLastError(); |
| 2212 | Sprintf(errmsg, "%s (0x%lx).", |
| 2213 | "Cannot load tiles from the file. Reverting back to default", |
| 2214 | errcode); |
| 2215 | raw_print(errmsg); |
| 2216 | return FALSE; |
| 2217 | } |
| 2218 | |
| 2219 | /* calculate tile dimensions */ |
| 2220 | GetObject(hBmp, sizeof(BITMAP), (LPVOID) &bm); |
| 2221 | if (bm.bmWidth % iflags.wc_tile_width |
| 2222 | || bm.bmHeight % iflags.wc_tile_height) { |
| 2223 | DeleteObject(hBmp); |
| 2224 | raw_print("Tiles bitmap does not match tile_width and tile_height " |
| 2225 | "options. Reverting back to default."); |
| 2226 | return FALSE; |
| 2227 | } |
| 2228 | |
| 2229 | tl_num = (bm.bmWidth / iflags.wc_tile_width) |
| 2230 | * (bm.bmHeight / iflags.wc_tile_height); |
| 2231 | if (tl_num < total_tiles_used) { |
| 2232 | DeleteObject(hBmp); |
| 2233 | raw_print("Number of tiles in the bitmap is less than required by " |
| 2234 | "the game. Reverting back to default."); |
| 2235 | return FALSE; |
| 2236 | } |
| 2237 | |
| 2238 | /* set the tile information */ |
| 2239 | if (GetNHApp()->bmpMapTiles != GetNHApp()->bmpTiles) { |
| 2240 | DeleteObject(GetNHApp()->bmpMapTiles); |
| 2241 | } |
| 2242 | |
| 2243 | GetNHApp()->bmpMapTiles = hBmp; |
| 2244 | GetNHApp()->mapTile_X = iflags.wc_tile_width; |
| 2245 | GetNHApp()->mapTile_Y = iflags.wc_tile_height; |
| 2246 | GetNHApp()->mapTilesPerLine = bm.bmWidth / iflags.wc_tile_width; |
no test coverage detected