--- deliantra/Deliantra-Client/Client.xs 2006/08/14 03:41:25 1.140 +++ deliantra/Deliantra-Client/Client.xs 2006/08/19 02:49:53 1.146 @@ -171,8 +171,9 @@ } maptex; typedef struct { - int16_t darkness; + uint16_t darkness; mapface face[3]; + uint8_t stat_hp; } mapcell; typedef struct { @@ -295,6 +296,7 @@ { int x, y; maprow *row; + mapcell *cell; for (y = y0; y < y0 + h; y++) if (y >= 0) @@ -310,7 +312,10 @@ if (x >= row->c1) break; - row->col[x - row->c0].darkness = -1; + cell = row->col + x - row->c0; + + cell->darkness = 0; + cell->stat_hp = 0; } } } @@ -1262,7 +1267,7 @@ } void -map1a_update (CFPlus::Map self, SV *data_) +map1a_update (CFPlus::Map self, SV *data_, int extmap) CODE: { uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); @@ -1281,18 +1286,40 @@ if (flags & 15) { - if (cell->darkness < 0) + if (!cell->darkness) { - cell->darkness = 0; + cell->darkness = 256; cell->face [0] = 0; cell->face [1] = 0; cell->face [2] = 0; } - cell->darkness = flags & 8 ? *data++ : 255; - //TODO: don't trust server data to be in-range(!) + if (flags & 8) + { + if (extmap) + { + uint8_t ext, cmd; + + do + { + ext = *data++; + cmd = ext & 0x3f; + + if (ext < 4) + cell->darkness = 255 - ext * 64 + 1; + else if (ext == 5) // health + cell->stat_hp = *data++; + else if (ext & 0x40) // unknown, multibyte => skip + data += *data + 1; + } + while (cmd & 0x80); + } + else + cell->darkness = *data++ + 1; + } + if (flags & 4) { cell->face [0] = self->face [(data [0] << 8) + data [1]]; data += 2; @@ -1309,7 +1336,10 @@ } } else - cell->darkness = -1; + { + cell->darkness = 0; + cell->stat_hp = 0; + } } } @@ -1419,7 +1449,7 @@ face = cell->face [z]; - if (face) + if (face && face < self->texs) { maptex tex = self->tex [face]; @@ -1446,6 +1476,33 @@ glDisable (GL_TEXTURE_2D); glDisable (GL_BLEND); + + // top layer: overlays such as the health bar + for (y = 0; y < sh; y++) + if (0 <= y + vy && y + vy < self->rows) + { + maprow *row = self->row + (y + vy); + + for (x = 0; x < sw; x++) + if (row->c0 <= x + vx && x + vx < row->c1) + { + mapcell *cell = row->col + (x + vx - row->c0); + + int px = x * 32; + int py = y * 32; + + if (cell->stat_hp) + { + int width = sh / 28 + 1; + + glColor3ub (0, 0, 0); + glRectf (px + 1, py, px + 31, py + width + 2); + + glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); + glRectf (px + 2, py + 1, px + 30 - cell->stat_hp * 28 / 255, py + width + 1); + } + } + } } void @@ -1535,9 +1592,9 @@ { mapcell *cell = row->col + (x + vx - row->c0); - darkness[y * sw4 + x] = cell->darkness < 0 - ? 255 - FOW_DARKNESS - : 255 - cell->darkness; + darkness[y * sw4 + x] = cell->darkness + ? 255 - (cell->darkness - 1) + : 255 - FOW_DARKNESS; } } @@ -1662,9 +1719,9 @@ if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } - if (cell->darkness <= 0) + if (cell->darkness == 0) { - cell->darkness = -1; + cell->darkness = 0; for (z = 0; z <= 2; z++) {