--- deliantra/Deliantra-Client/Client.xs 2006/08/18 01:27:15 1.142 +++ deliantra/Deliantra-Client/Client.xs 2006/08/19 18:18:36 1.152 @@ -173,7 +173,7 @@ typedef struct { uint16_t darkness; mapface face[3]; - uint8_t stat_hp; + uint8_t stat_width, stat_hp; } mapcell; typedef struct { @@ -296,6 +296,7 @@ { int x, y; maprow *row; + mapcell *cell; for (y = y0; y < y0 + h; y++) if (y >= 0) @@ -311,7 +312,10 @@ if (x >= row->c1) break; - row->col[x - row->c0].darkness = 0; + cell = row->col + x - row->c0; + + cell->darkness = 0; + cell->stat_hp = 0; } } } @@ -1271,7 +1275,7 @@ mapcell *cell; int x, y, flags; - while (data < data_end) + while (data < data_end - 1) { flags = (data [0] << 8) + data [1]; data += 2; @@ -1301,14 +1305,23 @@ do { ext = *data++; - cmd = ext & 0x7f; + cmd = ext & 0x3f; - if (ext < 4) + if (cmd < 4) cell->darkness = 255 - ext * 64 + 1; - else if (ext == 5) // health - cell->stat_hp = *data++; + else if (cmd == 5) // health + { + cell->stat_width = 1; + cell->stat_hp = *data++; + } + else if (cmd == 6) // monster width + cell->stat_width = *data++ + 1; + else if (ext & 0x40) // unknown, multibyte => skip + data += *data + 1; + else + data++; } - while (cmd & 0x80); + while (ext & 0x80); } else cell->darkness = *data++ + 1; @@ -1330,7 +1343,10 @@ } } else - cell->darkness = 0; + { + cell->darkness = 0; + cell->stat_hp = 0; + } } } @@ -1440,7 +1456,7 @@ face = cell->face [z]; - if (face) + if (face && face < self->texs) { maptex tex = self->tex [face]; @@ -1467,6 +1483,37 @@ 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 = cell->stat_width * 32; + int thick = sh / 28 + 1 + cell->stat_width; + + glColor3ub (0, 0, 0); + glRectf (px + 1, py - thick - 2, + px + width - 1, py); + + glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); + glRectf (px + 2, + py - thick - 1, + px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); + } + } + } } void @@ -1557,7 +1604,7 @@ mapcell *cell = row->col + (x + vx - row->c0); darkness[y * sw4 + x] = cell->darkness - ? 255 - cell->darkness + 1 + ? 255 - (cell->darkness - 1) : 255 - FOW_DARKNESS; } } @@ -1683,7 +1730,7 @@ if (flags & 2) { face[1] = *data++ << 8; face[1] |= *data++; } if (flags & 4) { face[2] = *data++ << 8; face[2] |= *data++; } - if (cell->darkness <= 1) + if (cell->darkness == 0) { cell->darkness = 0;