… | |
… | |
171 | } maptex; |
171 | } maptex; |
172 | |
172 | |
173 | typedef struct { |
173 | typedef struct { |
174 | uint16_t darkness; |
174 | uint16_t darkness; |
175 | mapface face[3]; |
175 | mapface face[3]; |
176 | uint8_t stat_hp; |
176 | uint8_t stat_width, stat_hp; |
177 | } mapcell; |
177 | } mapcell; |
178 | |
178 | |
179 | typedef struct { |
179 | typedef struct { |
180 | int32_t c0, c1; |
180 | int32_t c0, c1; |
181 | mapcell *col; |
181 | mapcell *col; |
… | |
… | |
294 | static void |
294 | static void |
295 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
295 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
296 | { |
296 | { |
297 | int x, y; |
297 | int x, y; |
298 | maprow *row; |
298 | maprow *row; |
|
|
299 | mapcell *cell; |
299 | |
300 | |
300 | for (y = y0; y < y0 + h; y++) |
301 | for (y = y0; y < y0 + h; y++) |
301 | if (y >= 0) |
302 | if (y >= 0) |
302 | { |
303 | { |
303 | if (y >= self->rows) |
304 | if (y >= self->rows) |
… | |
… | |
309 | if (x >= row->c0) |
310 | if (x >= row->c0) |
310 | { |
311 | { |
311 | if (x >= row->c1) |
312 | if (x >= row->c1) |
312 | break; |
313 | break; |
313 | |
314 | |
314 | row->col[x - row->c0].darkness = 0; |
315 | cell = row->col + x - row->c0; |
|
|
316 | |
|
|
317 | cell->darkness = 0; |
|
|
318 | cell->stat_hp = 0; |
315 | } |
319 | } |
316 | } |
320 | } |
317 | } |
321 | } |
318 | |
322 | |
319 | static void |
323 | static void |
… | |
… | |
1299 | uint8_t ext, cmd; |
1303 | uint8_t ext, cmd; |
1300 | |
1304 | |
1301 | do |
1305 | do |
1302 | { |
1306 | { |
1303 | ext = *data++; |
1307 | ext = *data++; |
1304 | cmd = ext & 0x7f; |
1308 | cmd = ext & 0x3f; |
1305 | |
1309 | |
1306 | if (ext < 4) |
1310 | if (cmd < 4) |
1307 | cell->darkness = 255 - ext * 64 + 1; |
1311 | cell->darkness = 255 - ext * 64 + 1; |
1308 | else if (ext == 5) // health |
1312 | else if (cmd == 5) // health |
|
|
1313 | { |
|
|
1314 | cell->stat_width = 1; |
1309 | cell->stat_hp = *data++; |
1315 | cell->stat_hp = *data++; |
|
|
1316 | } |
|
|
1317 | else if (cmd == 6) // monster width |
|
|
1318 | cell->stat_width = *data++ + 1; |
|
|
1319 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1320 | data += *data + 1; |
|
|
1321 | else |
|
|
1322 | data++; |
1310 | } |
1323 | } |
1311 | while (cmd & 0x80); |
1324 | while (ext & 0x80); |
1312 | } |
1325 | } |
1313 | else |
1326 | else |
1314 | cell->darkness = *data++ + 1; |
1327 | cell->darkness = *data++ + 1; |
1315 | } |
1328 | } |
1316 | |
1329 | |
… | |
… | |
1328 | { |
1341 | { |
1329 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1342 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1330 | } |
1343 | } |
1331 | } |
1344 | } |
1332 | else |
1345 | else |
|
|
1346 | { |
1333 | cell->darkness = 0; |
1347 | cell->darkness = 0; |
|
|
1348 | cell->stat_hp = 0; |
|
|
1349 | } |
1334 | } |
1350 | } |
1335 | } |
1351 | } |
1336 | |
1352 | |
1337 | SV * |
1353 | SV * |
1338 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1354 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
… | |
… | |
1438 | { |
1454 | { |
1439 | mapcell *cell = row->col + (x + vx - row->c0); |
1455 | mapcell *cell = row->col + (x + vx - row->c0); |
1440 | |
1456 | |
1441 | face = cell->face [z]; |
1457 | face = cell->face [z]; |
1442 | |
1458 | |
1443 | if (face) |
1459 | if (face && face < self->texs) |
1444 | { |
1460 | { |
1445 | maptex tex = self->tex [face]; |
1461 | maptex tex = self->tex [face]; |
1446 | |
1462 | |
1447 | int px = (x + 1) * 32 - tex.w; |
1463 | int px = (x + 1) * 32 - tex.w; |
1448 | int py = (y + 1) * 32 - tex.h; |
1464 | int py = (y + 1) * 32 - tex.h; |
… | |
… | |
1464 | } |
1480 | } |
1465 | |
1481 | |
1466 | glEnd (); |
1482 | glEnd (); |
1467 | |
1483 | |
1468 | glDisable (GL_TEXTURE_2D); |
1484 | glDisable (GL_TEXTURE_2D); |
|
|
1485 | |
|
|
1486 | // top layer: overlays such as the health bar |
|
|
1487 | for (y = 0; y < sh; y++) |
|
|
1488 | if (0 <= y + vy && y + vy < self->rows) |
|
|
1489 | { |
|
|
1490 | maprow *row = self->row + (y + vy); |
|
|
1491 | |
|
|
1492 | for (x = 0; x < sw; x++) |
|
|
1493 | if (row->c0 <= x + vx && x + vx < row->c1) |
|
|
1494 | { |
|
|
1495 | mapcell *cell = row->col + (x + vx - row->c0); |
|
|
1496 | |
|
|
1497 | int px = x * 32; |
|
|
1498 | int py = y * 32; |
|
|
1499 | |
|
|
1500 | if (cell->stat_hp) |
|
|
1501 | { |
|
|
1502 | int width = cell->stat_width * 32; |
|
|
1503 | int thick = sh / 28 + 1 + cell->stat_width; |
|
|
1504 | |
|
|
1505 | glColor4ub (0, 0, 0, 128); |
|
|
1506 | glRectf (px + 1, py, |
|
|
1507 | px + width - 1, py + thick + 2); |
|
|
1508 | |
|
|
1509 | glColor4ub (cell->stat_hp, 255 - cell->stat_hp, 0, 192); |
|
|
1510 | glRectf (px + 2, |
|
|
1511 | py + 1, |
|
|
1512 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py + thick + 1); |
|
|
1513 | } |
|
|
1514 | } |
|
|
1515 | } |
|
|
1516 | |
1469 | glDisable (GL_BLEND); |
1517 | glDisable (GL_BLEND); |
1470 | } |
1518 | } |
1471 | |
1519 | |
1472 | void |
1520 | void |
1473 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1521 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
… | |
… | |
1555 | if (row->c0 <= x + vx && x + vx < row->c1) |
1603 | if (row->c0 <= x + vx && x + vx < row->c1) |
1556 | { |
1604 | { |
1557 | mapcell *cell = row->col + (x + vx - row->c0); |
1605 | mapcell *cell = row->col + (x + vx - row->c0); |
1558 | |
1606 | |
1559 | darkness[y * sw4 + x] = cell->darkness |
1607 | darkness[y * sw4 + x] = cell->darkness |
1560 | ? 255 - cell->darkness + 1 |
1608 | ? 255 - (cell->darkness - 1) |
1561 | : 255 - FOW_DARKNESS; |
1609 | : 255 - FOW_DARKNESS; |
1562 | } |
1610 | } |
1563 | } |
1611 | } |
1564 | |
1612 | |
1565 | EXTEND (SP, 3); |
1613 | EXTEND (SP, 3); |
… | |
… | |
1681 | |
1729 | |
1682 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1730 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1683 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1731 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1684 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1732 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1685 | |
1733 | |
1686 | if (cell->darkness <= 1) |
1734 | if (cell->darkness == 0) |
1687 | { |
1735 | { |
1688 | cell->darkness = 0; |
1736 | cell->darkness = 0; |
1689 | |
1737 | |
1690 | for (z = 0; z <= 2; z++) |
1738 | for (z = 0; z <= 2; z++) |
1691 | { |
1739 | { |