… | |
… | |
169 | float s, t; |
169 | float s, t; |
170 | uint8_t r, g, b, a; |
170 | uint8_t r, g, b, a; |
171 | } maptex; |
171 | } maptex; |
172 | |
172 | |
173 | typedef struct { |
173 | typedef struct { |
174 | int16_t darkness; |
174 | uint16_t darkness; |
175 | mapface face[3]; |
175 | mapface face[3]; |
|
|
176 | uint8_t stat_hp; |
176 | } mapcell; |
177 | } mapcell; |
177 | |
178 | |
178 | typedef struct { |
179 | typedef struct { |
179 | int32_t c0, c1; |
180 | int32_t c0, c1; |
180 | mapcell *col; |
181 | mapcell *col; |
… | |
… | |
293 | static void |
294 | static void |
294 | 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) |
295 | { |
296 | { |
296 | int x, y; |
297 | int x, y; |
297 | maprow *row; |
298 | maprow *row; |
|
|
299 | mapcell *cell; |
298 | |
300 | |
299 | for (y = y0; y < y0 + h; y++) |
301 | for (y = y0; y < y0 + h; y++) |
300 | if (y >= 0) |
302 | if (y >= 0) |
301 | { |
303 | { |
302 | if (y >= self->rows) |
304 | if (y >= self->rows) |
… | |
… | |
308 | if (x >= row->c0) |
310 | if (x >= row->c0) |
309 | { |
311 | { |
310 | if (x >= row->c1) |
312 | if (x >= row->c1) |
311 | break; |
313 | break; |
312 | |
314 | |
313 | row->col[x - row->c0].darkness = -1; |
315 | cell = row->col + x - row->c0; |
|
|
316 | |
|
|
317 | cell->darkness = 0; |
|
|
318 | cell->stat_hp = 0; |
314 | } |
319 | } |
315 | } |
320 | } |
316 | } |
321 | } |
317 | |
322 | |
318 | static void |
323 | static void |
… | |
… | |
1260 | self->y += MAP_EXTEND_Y; |
1265 | self->y += MAP_EXTEND_Y; |
1261 | } |
1266 | } |
1262 | } |
1267 | } |
1263 | |
1268 | |
1264 | void |
1269 | void |
1265 | map1a_update (CFPlus::Map self, SV *data_) |
1270 | map1a_update (CFPlus::Map self, SV *data_, int extmap) |
1266 | CODE: |
1271 | CODE: |
1267 | { |
1272 | { |
1268 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1273 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1269 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1274 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1270 | mapcell *cell; |
1275 | mapcell *cell; |
… | |
… | |
1279 | |
1284 | |
1280 | cell = map_get_cell (self, x, y); |
1285 | cell = map_get_cell (self, x, y); |
1281 | |
1286 | |
1282 | if (flags & 15) |
1287 | if (flags & 15) |
1283 | { |
1288 | { |
1284 | if (cell->darkness < 0) |
1289 | if (!cell->darkness) |
1285 | { |
1290 | { |
1286 | cell->darkness = 0; |
1291 | cell->darkness = 256; |
1287 | cell->face [0] = 0; |
1292 | cell->face [0] = 0; |
1288 | cell->face [1] = 0; |
1293 | cell->face [1] = 0; |
1289 | cell->face [2] = 0; |
1294 | cell->face [2] = 0; |
1290 | } |
1295 | } |
1291 | |
1296 | |
1292 | cell->darkness = flags & 8 ? *data++ : 255; |
|
|
1293 | |
|
|
1294 | //TODO: don't trust server data to be in-range(!) |
1297 | //TODO: don't trust server data to be in-range(!) |
|
|
1298 | |
|
|
1299 | if (flags & 8) |
|
|
1300 | { |
|
|
1301 | if (extmap) |
|
|
1302 | { |
|
|
1303 | uint8_t ext, cmd; |
|
|
1304 | |
|
|
1305 | do |
|
|
1306 | { |
|
|
1307 | ext = *data++; |
|
|
1308 | cmd = ext & 0x3f; |
|
|
1309 | |
|
|
1310 | if (ext < 4) |
|
|
1311 | cell->darkness = 255 - ext * 64 + 1; |
|
|
1312 | else if (ext == 5) // health |
|
|
1313 | cell->stat_hp = *data++; |
|
|
1314 | else if (ext & 0x40) // unknown, multibyte => skip |
|
|
1315 | data += *data + 1; |
|
|
1316 | } |
|
|
1317 | while (cmd & 0x80); |
|
|
1318 | } |
|
|
1319 | else |
|
|
1320 | cell->darkness = *data++ + 1; |
|
|
1321 | } |
1295 | |
1322 | |
1296 | if (flags & 4) |
1323 | if (flags & 4) |
1297 | { |
1324 | { |
1298 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1325 | cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1299 | } |
1326 | } |
… | |
… | |
1307 | { |
1334 | { |
1308 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1335 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1309 | } |
1336 | } |
1310 | } |
1337 | } |
1311 | else |
1338 | else |
|
|
1339 | { |
1312 | cell->darkness = -1; |
1340 | cell->darkness = 0; |
|
|
1341 | cell->stat_hp = 0; |
|
|
1342 | } |
1313 | } |
1343 | } |
1314 | } |
1344 | } |
1315 | |
1345 | |
1316 | SV * |
1346 | SV * |
1317 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1347 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
… | |
… | |
1417 | { |
1447 | { |
1418 | mapcell *cell = row->col + (x + vx - row->c0); |
1448 | mapcell *cell = row->col + (x + vx - row->c0); |
1419 | |
1449 | |
1420 | face = cell->face [z]; |
1450 | face = cell->face [z]; |
1421 | |
1451 | |
1422 | if (face) |
1452 | if (face && face < self->texs) |
1423 | { |
1453 | { |
1424 | maptex tex = self->tex [face]; |
1454 | maptex tex = self->tex [face]; |
1425 | |
1455 | |
1426 | int px = (x + 1) * 32 - tex.w; |
1456 | int px = (x + 1) * 32 - tex.w; |
1427 | int py = (y + 1) * 32 - tex.h; |
1457 | int py = (y + 1) * 32 - tex.h; |
… | |
… | |
1444 | |
1474 | |
1445 | glEnd (); |
1475 | glEnd (); |
1446 | |
1476 | |
1447 | glDisable (GL_TEXTURE_2D); |
1477 | glDisable (GL_TEXTURE_2D); |
1448 | glDisable (GL_BLEND); |
1478 | glDisable (GL_BLEND); |
|
|
1479 | |
|
|
1480 | // top layer: overlays such as the health bar |
|
|
1481 | for (y = 0; y < sh; y++) |
|
|
1482 | if (0 <= y + vy && y + vy < self->rows) |
|
|
1483 | { |
|
|
1484 | maprow *row = self->row + (y + vy); |
|
|
1485 | |
|
|
1486 | for (x = 0; x < sw; x++) |
|
|
1487 | if (row->c0 <= x + vx && x + vx < row->c1) |
|
|
1488 | { |
|
|
1489 | mapcell *cell = row->col + (x + vx - row->c0); |
|
|
1490 | |
|
|
1491 | int px = x * 32; |
|
|
1492 | int py = y * 32; |
|
|
1493 | |
|
|
1494 | if (cell->stat_hp) |
|
|
1495 | { |
|
|
1496 | int width = sh / 28 + 1; |
|
|
1497 | |
|
|
1498 | glColor3ub (0, 0, 0); |
|
|
1499 | glRectf (px + 1, py, px + 31, py + width + 2); |
|
|
1500 | |
|
|
1501 | glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); |
|
|
1502 | glRectf (px + 2, py + 1, px + 30 - cell->stat_hp * 28 / 255, py + width + 1); |
|
|
1503 | } |
|
|
1504 | } |
|
|
1505 | } |
1449 | } |
1506 | } |
1450 | |
1507 | |
1451 | void |
1508 | void |
1452 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1509 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1453 | CODE: |
1510 | CODE: |
… | |
… | |
1533 | for (x = 0; x < sw; x++) |
1590 | for (x = 0; x < sw; x++) |
1534 | if (row->c0 <= x + vx && x + vx < row->c1) |
1591 | if (row->c0 <= x + vx && x + vx < row->c1) |
1535 | { |
1592 | { |
1536 | mapcell *cell = row->col + (x + vx - row->c0); |
1593 | mapcell *cell = row->col + (x + vx - row->c0); |
1537 | |
1594 | |
1538 | darkness[y * sw4 + x] = cell->darkness < 0 |
1595 | darkness[y * sw4 + x] = cell->darkness |
|
|
1596 | ? 255 - (cell->darkness - 1) |
1539 | ? 255 - FOW_DARKNESS |
1597 | : 255 - FOW_DARKNESS; |
1540 | : 255 - cell->darkness; |
|
|
1541 | } |
1598 | } |
1542 | } |
1599 | } |
1543 | |
1600 | |
1544 | EXTEND (SP, 3); |
1601 | EXTEND (SP, 3); |
1545 | PUSHs (sv_2mortal (newSViv (sw4))); |
1602 | PUSHs (sv_2mortal (newSViv (sw4))); |
… | |
… | |
1660 | |
1717 | |
1661 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1718 | if (flags & 1) { face[0] = *data++ << 8; face[0] |= *data++; } |
1662 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1719 | if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } |
1663 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1720 | if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } |
1664 | |
1721 | |
1665 | if (cell->darkness <= 0) |
1722 | if (cell->darkness == 0) |
1666 | { |
1723 | { |
1667 | cell->darkness = -1; |
1724 | cell->darkness = 0; |
1668 | |
1725 | |
1669 | for (z = 0; z <= 2; z++) |
1726 | for (z = 0; z <= 2; z++) |
1670 | { |
1727 | { |
1671 | cell->face[z] = face[z]; |
1728 | cell->face[z] = face[z]; |
1672 | |
1729 | |