… | |
… | |
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 | uint32_t player; |
|
|
175 | mapface face[3]; |
174 | uint16_t darkness; |
176 | uint16_t darkness; |
175 | mapface face[3]; |
177 | uint8_t stat_width, stat_hp, flags; |
176 | uint8_t stat_hp; |
|
|
177 | } mapcell; |
178 | } mapcell; |
178 | |
179 | |
179 | typedef struct { |
180 | typedef struct { |
180 | int32_t c0, c1; |
181 | int32_t c0, c1; |
181 | mapcell *col; |
182 | mapcell *col; |
… | |
… | |
294 | static void |
295 | static void |
295 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
296 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
296 | { |
297 | { |
297 | int x, y; |
298 | int x, y; |
298 | maprow *row; |
299 | maprow *row; |
|
|
300 | mapcell *cell; |
299 | |
301 | |
300 | for (y = y0; y < y0 + h; y++) |
302 | for (y = y0; y < y0 + h; y++) |
301 | if (y >= 0) |
303 | if (y >= 0) |
302 | { |
304 | { |
303 | if (y >= self->rows) |
305 | if (y >= self->rows) |
… | |
… | |
309 | if (x >= row->c0) |
311 | if (x >= row->c0) |
310 | { |
312 | { |
311 | if (x >= row->c1) |
313 | if (x >= row->c1) |
312 | break; |
314 | break; |
313 | |
315 | |
314 | row->col[x - row->c0].darkness = 0; |
316 | cell = row->col + x - row->c0; |
|
|
317 | |
|
|
318 | cell->darkness = 0; |
|
|
319 | cell->stat_hp = 0; |
|
|
320 | cell->flags = 0; |
|
|
321 | cell->player = 0; |
315 | } |
322 | } |
316 | } |
323 | } |
317 | } |
324 | } |
318 | |
325 | |
319 | static void |
326 | static void |
… | |
… | |
1239 | void |
1246 | void |
1240 | scroll (CFPlus::Map self, int dx, int dy) |
1247 | scroll (CFPlus::Map self, int dx, int dy) |
1241 | CODE: |
1248 | CODE: |
1242 | { |
1249 | { |
1243 | if (dx > 0) |
1250 | if (dx > 0) |
1244 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1251 | map_blank (self, self->x, self->y, dx, self->h); |
1245 | else if (dx < 0) |
1252 | else if (dx < 0) |
1246 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
1253 | map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); |
1247 | |
1254 | |
1248 | if (dy > 0) |
1255 | if (dy > 0) |
1249 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1256 | map_blank (self, self->x, self->y, self->w, dy); |
1250 | else if (dy < 0) |
1257 | else if (dy < 0) |
1251 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
1258 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); |
1252 | |
1259 | |
1253 | self->ox += dx; self->x += dx; |
1260 | self->ox += dx; self->x += dx; |
1254 | self->oy += dy; self->y += dy; |
1261 | self->oy += dy; self->y += dy; |
1255 | |
1262 | |
1256 | while (self->y < 0) |
1263 | while (self->y < 0) |
… | |
… | |
1269 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1276 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1270 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1277 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1271 | mapcell *cell; |
1278 | mapcell *cell; |
1272 | int x, y, flags; |
1279 | int x, y, flags; |
1273 | |
1280 | |
1274 | while (data < data_end) |
1281 | while (data < data_end - 1) |
1275 | { |
1282 | { |
1276 | flags = (data [0] << 8) + data [1]; data += 2; |
1283 | flags = (data [0] << 8) + data [1]; data += 2; |
1277 | |
1284 | |
1278 | x = self->x + ((flags >> 10) & 63); |
1285 | x = self->x + ((flags >> 10) & 63); |
1279 | y = self->y + ((flags >> 4) & 63); |
1286 | y = self->y + ((flags >> 4) & 63); |
… | |
… | |
1282 | |
1289 | |
1283 | if (flags & 15) |
1290 | if (flags & 15) |
1284 | { |
1291 | { |
1285 | if (!cell->darkness) |
1292 | if (!cell->darkness) |
1286 | { |
1293 | { |
|
|
1294 | memset (cell, 0, sizeof (*cell)); |
1287 | cell->darkness = 256; |
1295 | cell->darkness = 256; |
1288 | cell->face [0] = 0; |
|
|
1289 | cell->face [1] = 0; |
|
|
1290 | cell->face [2] = 0; |
|
|
1291 | cell->stat_hp = 0; |
|
|
1292 | } |
1296 | } |
1293 | |
1297 | |
1294 | //TODO: don't trust server data to be in-range(!) |
1298 | //TODO: don't trust server data to be in-range(!) |
1295 | |
1299 | |
1296 | if (flags & 8) |
1300 | if (flags & 8) |
… | |
… | |
1302 | do |
1306 | do |
1303 | { |
1307 | { |
1304 | ext = *data++; |
1308 | ext = *data++; |
1305 | cmd = ext & 0x3f; |
1309 | cmd = ext & 0x3f; |
1306 | |
1310 | |
1307 | if (ext < 4) |
1311 | if (cmd < 4) |
1308 | cell->darkness = 255 - ext * 64 + 1; |
1312 | cell->darkness = 255 - ext * 64 + 1; |
1309 | else if (ext == 5) // health |
1313 | else if (cmd == 5) // health |
|
|
1314 | { |
|
|
1315 | cell->stat_width = 1; |
1310 | cell->stat_hp = *data++; |
1316 | cell->stat_hp = *data++; |
|
|
1317 | } |
|
|
1318 | else if (cmd == 6) // monster width |
|
|
1319 | cell->stat_width = *data++ + 1; |
|
|
1320 | else if (cmd == 0x47) // monster width |
|
|
1321 | { |
|
|
1322 | if (*data == 4) |
|
|
1323 | ; // decode player tag |
|
|
1324 | |
|
|
1325 | data += *data + 1; |
|
|
1326 | } |
|
|
1327 | else if (cmd == 8) // cell flags |
|
|
1328 | cell->flags = *data++; |
1311 | else if (ext & 0x40) // unknown, multibyte => skip |
1329 | else if (ext & 0x40) // unknown, multibyte => skip |
1312 | data += *data + 1; |
1330 | data += *data + 1; |
|
|
1331 | else |
|
|
1332 | data++; |
1313 | } |
1333 | } |
1314 | while (cmd & 0x80); |
1334 | while (ext & 0x80); |
1315 | } |
1335 | } |
1316 | else |
1336 | else |
1317 | cell->darkness = *data++ + 1; |
1337 | cell->darkness = *data++ + 1; |
1318 | } |
1338 | } |
1319 | |
1339 | |
… | |
… | |
1441 | { |
1461 | { |
1442 | mapcell *cell = row->col + (x + vx - row->c0); |
1462 | mapcell *cell = row->col + (x + vx - row->c0); |
1443 | |
1463 | |
1444 | face = cell->face [z]; |
1464 | face = cell->face [z]; |
1445 | |
1465 | |
1446 | if (face) |
1466 | if (face && face < self->texs) |
1447 | { |
1467 | { |
1448 | maptex tex = self->tex [face]; |
1468 | maptex tex = self->tex [face]; |
1449 | |
|
|
1450 | int px = (x + 1) * 32 - tex.w; |
1469 | int px = (x + 1) * 32 - tex.w; |
1451 | int py = (y + 1) * 32 - tex.h; |
1470 | int py = (y + 1) * 32 - tex.h; |
1452 | |
1471 | |
1453 | if (last_name != tex.name) |
1472 | if (last_name != tex.name) |
1454 | { |
1473 | { |
1455 | glEnd (); |
1474 | glEnd (); |
1456 | last_name = tex.name; |
|
|
1457 | glBindTexture (GL_TEXTURE_2D, last_name); |
1475 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1458 | glBegin (GL_QUADS); |
1476 | glBegin (GL_QUADS); |
1459 | } |
1477 | } |
1460 | |
1478 | |
1461 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1479 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1462 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1480 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1463 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1481 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1464 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1482 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1465 | } |
1483 | } |
|
|
1484 | |
|
|
1485 | if (cell->flags && z == 2) |
|
|
1486 | { |
|
|
1487 | if (cell->flags & 1) |
|
|
1488 | { |
|
|
1489 | maptex tex = self->tex [1]; |
|
|
1490 | int px = (x + 1) * 32 - tex.w + 2; |
|
|
1491 | int py = (y + 1) * 32 - tex.h - 6; |
|
|
1492 | |
|
|
1493 | glEnd (); |
|
|
1494 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1495 | glBegin (GL_QUADS); |
|
|
1496 | |
|
|
1497 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1498 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
|
|
1499 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1500 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1501 | } |
|
|
1502 | } |
1466 | } |
1503 | } |
1467 | } |
1504 | } |
1468 | |
1505 | |
1469 | glEnd (); |
1506 | glEnd (); |
1470 | |
1507 | |
1471 | glDisable (GL_TEXTURE_2D); |
1508 | glDisable (GL_TEXTURE_2D); |
1472 | glDisable (GL_BLEND); |
1509 | glDisable (GL_BLEND); |
1473 | |
1510 | |
|
|
1511 | // top layer: overlays such as the health bar |
1474 | for (y = 0; y < sh; y++) |
1512 | for (y = 0; y < sh; y++) |
1475 | if (0 <= y + vy && y + vy < self->rows) |
1513 | if (0 <= y + vy && y + vy < self->rows) |
1476 | { |
1514 | { |
1477 | maprow *row = self->row + (y + vy); |
1515 | maprow *row = self->row + (y + vy); |
1478 | |
1516 | |
… | |
… | |
1484 | int px = x * 32; |
1522 | int px = x * 32; |
1485 | int py = y * 32; |
1523 | int py = y * 32; |
1486 | |
1524 | |
1487 | if (cell->stat_hp) |
1525 | if (cell->stat_hp) |
1488 | { |
1526 | { |
|
|
1527 | int width = cell->stat_width * 32; |
|
|
1528 | int thick = sh / 28 + 1 + cell->stat_width; |
|
|
1529 | |
1489 | glColor3ub (0, 0, 0); |
1530 | glColor3ub (0, 0, 0); |
1490 | glRectf (px + 1, py + 1, px + 31, py + 4); |
1531 | glRectf (px + 1, py - thick - 2, |
|
|
1532 | px + width - 1, py); |
1491 | |
1533 | |
1492 | glColor3ub (0, 255, 0); |
1534 | glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); |
1493 | glBegin (GL_LINES); |
|
|
1494 | glVertex2f (px + 2, py + 2.5f); |
1535 | glRectf (px + 2, |
1495 | glVertex2f (px + 29.f - cell->stat_hp * (28.f / 255.f), py + 2.5f); |
1536 | py - thick - 1, |
1496 | glEnd (); |
1537 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
1497 | } |
1538 | } |
1498 | } |
1539 | } |
1499 | } |
1540 | } |
1500 | } |
1541 | } |
1501 | |
1542 | |