… | |
… | |
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]; |
|
|
176 | uint8_t stat_width, stat_hp; |
177 | uint8_t stat_width, stat_hp, flags; |
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; |
… | |
… | |
314 | |
315 | |
315 | cell = row->col + x - row->c0; |
316 | cell = row->col + x - row->c0; |
316 | |
317 | |
317 | cell->darkness = 0; |
318 | cell->darkness = 0; |
318 | cell->stat_hp = 0; |
319 | cell->stat_hp = 0; |
|
|
320 | cell->flags = 0; |
|
|
321 | cell->player = 0; |
319 | } |
322 | } |
320 | } |
323 | } |
321 | } |
324 | } |
322 | |
325 | |
323 | static void |
326 | static void |
… | |
… | |
1243 | void |
1246 | void |
1244 | scroll (CFPlus::Map self, int dx, int dy) |
1247 | scroll (CFPlus::Map self, int dx, int dy) |
1245 | CODE: |
1248 | CODE: |
1246 | { |
1249 | { |
1247 | if (dx > 0) |
1250 | if (dx > 0) |
1248 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1251 | map_blank (self, self->x, self->y, dx, self->h); |
1249 | else if (dx < 0) |
1252 | else if (dx < 0) |
1250 | 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); |
1251 | |
1254 | |
1252 | if (dy > 0) |
1255 | if (dy > 0) |
1253 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1256 | map_blank (self, self->x, self->y, self->w, dy); |
1254 | else if (dy < 0) |
1257 | else if (dy < 0) |
1255 | 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); |
1256 | |
1259 | |
1257 | self->ox += dx; self->x += dx; |
1260 | self->ox += dx; self->x += dx; |
1258 | self->oy += dy; self->y += dy; |
1261 | self->oy += dy; self->y += dy; |
1259 | |
1262 | |
1260 | while (self->y < 0) |
1263 | while (self->y < 0) |
… | |
… | |
1273 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1276 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1274 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1277 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1275 | mapcell *cell; |
1278 | mapcell *cell; |
1276 | int x, y, flags; |
1279 | int x, y, flags; |
1277 | |
1280 | |
1278 | while (data < data_end) |
1281 | while (data < data_end - 1) |
1279 | { |
1282 | { |
1280 | flags = (data [0] << 8) + data [1]; data += 2; |
1283 | flags = (data [0] << 8) + data [1]; data += 2; |
1281 | |
1284 | |
1282 | x = self->x + ((flags >> 10) & 63); |
1285 | x = self->x + ((flags >> 10) & 63); |
1283 | y = self->y + ((flags >> 4) & 63); |
1286 | y = self->y + ((flags >> 4) & 63); |
… | |
… | |
1286 | |
1289 | |
1287 | if (flags & 15) |
1290 | if (flags & 15) |
1288 | { |
1291 | { |
1289 | if (!cell->darkness) |
1292 | if (!cell->darkness) |
1290 | { |
1293 | { |
|
|
1294 | memset (cell, 0, sizeof (*cell)); |
1291 | cell->darkness = 256; |
1295 | cell->darkness = 256; |
1292 | cell->face [0] = 0; |
|
|
1293 | cell->face [1] = 0; |
|
|
1294 | cell->face [2] = 0; |
|
|
1295 | } |
1296 | } |
1296 | |
1297 | |
1297 | //TODO: don't trust server data to be in-range(!) |
1298 | //TODO: don't trust server data to be in-range(!) |
1298 | |
1299 | |
1299 | if (flags & 8) |
1300 | if (flags & 8) |
… | |
… | |
1314 | cell->stat_width = 1; |
1315 | cell->stat_width = 1; |
1315 | cell->stat_hp = *data++; |
1316 | cell->stat_hp = *data++; |
1316 | } |
1317 | } |
1317 | else if (cmd == 6) // monster width |
1318 | else if (cmd == 6) // monster width |
1318 | cell->stat_width = *data++ + 1; |
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++; |
1319 | else if (ext & 0x40) // unknown, multibyte => skip |
1329 | else if (ext & 0x40) // unknown, multibyte => skip |
1320 | data += *data + 1; |
1330 | data += *data + 1; |
1321 | else |
1331 | else |
1322 | data++; |
1332 | data++; |
1323 | } |
1333 | } |
… | |
… | |
1341 | { |
1351 | { |
1342 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1352 | cell->face [2] = self->face [(data [0] << 8) + data [1]]; data += 2; |
1343 | } |
1353 | } |
1344 | } |
1354 | } |
1345 | else |
1355 | else |
1346 | { |
|
|
1347 | cell->darkness = 0; |
1356 | cell->darkness = 0; |
1348 | cell->stat_hp = 0; |
|
|
1349 | } |
|
|
1350 | } |
1357 | } |
1351 | } |
1358 | } |
1352 | |
1359 | |
1353 | SV * |
1360 | SV * |
1354 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
1361 | mapmap (CFPlus::Map self, int x0, int y0, int w, int h) |
… | |
… | |
1457 | face = cell->face [z]; |
1464 | face = cell->face [z]; |
1458 | |
1465 | |
1459 | if (face && face < self->texs) |
1466 | if (face && face < self->texs) |
1460 | { |
1467 | { |
1461 | maptex tex = self->tex [face]; |
1468 | maptex tex = self->tex [face]; |
1462 | |
|
|
1463 | int px = (x + 1) * 32 - tex.w; |
1469 | int px = (x + 1) * 32 - tex.w; |
1464 | int py = (y + 1) * 32 - tex.h; |
1470 | int py = (y + 1) * 32 - tex.h; |
1465 | |
1471 | |
1466 | if (last_name != tex.name) |
1472 | if (last_name != tex.name) |
1467 | { |
1473 | { |
1468 | glEnd (); |
1474 | glEnd (); |
1469 | last_name = tex.name; |
|
|
1470 | glBindTexture (GL_TEXTURE_2D, last_name); |
1475 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1471 | glBegin (GL_QUADS); |
1476 | glBegin (GL_QUADS); |
1472 | } |
1477 | } |
1473 | |
1478 | |
1474 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1479 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1475 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1480 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1476 | 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); |
1477 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1482 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1478 | } |
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 | } |
1479 | } |
1503 | } |
1480 | } |
1504 | } |
1481 | |
1505 | |
1482 | glEnd (); |
1506 | glEnd (); |
1483 | |
1507 | |
1484 | glDisable (GL_TEXTURE_2D); |
1508 | glDisable (GL_TEXTURE_2D); |
|
|
1509 | glDisable (GL_BLEND); |
1485 | |
1510 | |
1486 | // top layer: overlays such as the health bar |
1511 | // top layer: overlays such as the health bar |
1487 | for (y = 0; y < sh; y++) |
1512 | for (y = 0; y < sh; y++) |
1488 | if (0 <= y + vy && y + vy < self->rows) |
1513 | if (0 <= y + vy && y + vy < self->rows) |
1489 | { |
1514 | { |
… | |
… | |
1500 | if (cell->stat_hp) |
1525 | if (cell->stat_hp) |
1501 | { |
1526 | { |
1502 | int width = cell->stat_width * 32; |
1527 | int width = cell->stat_width * 32; |
1503 | int thick = sh / 28 + 1 + cell->stat_width; |
1528 | int thick = sh / 28 + 1 + cell->stat_width; |
1504 | |
1529 | |
1505 | glColor4ub (0, 0, 0, 223); |
1530 | glColor3ub (0, 0, 0); |
1506 | glRectf (px + 1, py, |
1531 | glRectf (px + 1, py - thick - 2, |
1507 | px + width - 1, py + thick + 2); |
1532 | px + width - 1, py); |
1508 | |
1533 | |
1509 | glColor4ub (cell->stat_hp, 255 - cell->stat_hp, 0, 223); |
1534 | glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); |
1510 | glRectf (px + 2, |
1535 | glRectf (px + 2, |
1511 | py + 1, |
1536 | py - thick - 1, |
1512 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py + thick + 1); |
1537 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
1513 | } |
1538 | } |
1514 | } |
1539 | } |
1515 | } |
1540 | } |
1516 | |
|
|
1517 | glDisable (GL_BLEND); |
|
|
1518 | } |
1541 | } |
1519 | |
1542 | |
1520 | void |
1543 | void |
1521 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1544 | draw_magicmap (CFPlus::Map self, int dx, int dy, int w, int h, unsigned char *data) |
1522 | CODE: |
1545 | CODE: |