1 | #ifdef _WIN32 |
1 | #ifdef _WIN32 |
2 | # define WIN32_LEAN_AND_MEAN |
2 | # define WIN32_LEAN_AND_MEAN |
3 | # define _WIN32_WINNT 0x0500 // needed to get win2000 api calls |
3 | # define _WIN32_WINNT 0x0500 // needed to get win2000 api calls |
4 | # include <malloc.h> |
4 | # include <malloc.h> |
5 | # include <windows.h> |
5 | # include <windows.h> |
|
|
6 | # include <wininet.h> |
6 | # pragma warning(disable:4244) |
7 | # pragma warning(disable:4244) |
7 | #endif |
8 | #endif |
8 | |
9 | |
9 | #include "EXTERN.h" |
10 | #include "EXTERN.h" |
10 | #include "perl.h" |
11 | #include "perl.h" |
… | |
… | |
169 | float s, t; |
170 | float s, t; |
170 | uint8_t r, g, b, a; |
171 | uint8_t r, g, b, a; |
171 | } maptex; |
172 | } maptex; |
172 | |
173 | |
173 | typedef struct { |
174 | typedef struct { |
|
|
175 | uint32_t player; |
|
|
176 | mapface face[3]; |
174 | uint16_t darkness; |
177 | uint16_t darkness; |
175 | mapface face[3]; |
178 | uint8_t stat_width, stat_hp, flags; |
176 | uint8_t stat_hp; |
|
|
177 | } mapcell; |
179 | } mapcell; |
178 | |
180 | |
179 | typedef struct { |
181 | typedef struct { |
180 | int32_t c0, c1; |
182 | int32_t c0, c1; |
181 | mapcell *col; |
183 | mapcell *col; |
… | |
… | |
294 | static void |
296 | static void |
295 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
297 | map_blank (CFPlus__Map self, int x0, int y0, int w, int h) |
296 | { |
298 | { |
297 | int x, y; |
299 | int x, y; |
298 | maprow *row; |
300 | maprow *row; |
|
|
301 | mapcell *cell; |
299 | |
302 | |
300 | for (y = y0; y < y0 + h; y++) |
303 | for (y = y0; y < y0 + h; y++) |
301 | if (y >= 0) |
304 | if (y >= 0) |
302 | { |
305 | { |
303 | if (y >= self->rows) |
306 | if (y >= self->rows) |
… | |
… | |
309 | if (x >= row->c0) |
312 | if (x >= row->c0) |
310 | { |
313 | { |
311 | if (x >= row->c1) |
314 | if (x >= row->c1) |
312 | break; |
315 | break; |
313 | |
316 | |
314 | row->col[x - row->c0].darkness = 0; |
317 | cell = row->col + x - row->c0; |
|
|
318 | |
|
|
319 | cell->darkness = 0; |
|
|
320 | cell->stat_hp = 0; |
|
|
321 | cell->flags = 0; |
|
|
322 | cell->player = 0; |
315 | } |
323 | } |
316 | } |
324 | } |
317 | } |
325 | } |
318 | |
326 | |
319 | static void |
327 | static void |
… | |
… | |
644 | #ifndef _WIN32 |
652 | #ifndef _WIN32 |
645 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
653 | setsockopt (fd, IPPROTO_TCP, TCP_NODELAY, &val, sizeof (val)); |
646 | #endif |
654 | #endif |
647 | |
655 | |
648 | void |
656 | void |
|
|
657 | win32_proxy_info () |
|
|
658 | PPCODE: |
|
|
659 | { |
|
|
660 | #ifdef _WIN32 |
|
|
661 | INTERNET_PROXY_INFO proxyinfo; |
|
|
662 | char buffer[2048]; |
|
|
663 | DWORD buflen; |
|
|
664 | |
|
|
665 | EXTEND (SP, 3); |
|
|
666 | |
|
|
667 | buflen = sizeof (buffer); |
|
|
668 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY, (void *)buffer, &buflen)) |
|
|
669 | if (((INTERNET_PROXY_INFO *)buffer)->dwAccessType == INTERNET_OPEN_TYPE_PROXY) |
|
|
670 | { |
|
|
671 | PUSHs (newSVpv (((INTERNET_PROXY_INFO *)buffer)->lpszProxy, 0)); |
|
|
672 | |
|
|
673 | buflen = sizeof (buffer); |
|
|
674 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_USERNAME, (void *)buffer, &buflen)) |
|
|
675 | { |
|
|
676 | PUSHs (newSVpv (buffer, 0)); |
|
|
677 | |
|
|
678 | buflen = sizeof (buffer); |
|
|
679 | if (InternetQueryOption (0, INTERNET_OPTION_PROXY_PASSWORD, (void *)buffer, &buflen)) |
|
|
680 | PUSHs (newSVpv (buffer, 0)); |
|
|
681 | } |
|
|
682 | } |
|
|
683 | #endif |
|
|
684 | } |
|
|
685 | |
|
|
686 | void |
649 | add_font (char *file) |
687 | add_font (char *file) |
650 | CODE: |
688 | CODE: |
651 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
689 | FcConfigAppFontAddFile (0, (const FcChar8 *)file); |
652 | |
690 | |
653 | void |
691 | void |
… | |
… | |
755 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
793 | MessageBox (0, message, "Crossfire+ Fatal Error", MB_OK | MB_ICONERROR); |
756 | #endif |
794 | #endif |
757 | _exit (1); |
795 | _exit (1); |
758 | |
796 | |
759 | void |
797 | void |
760 | _exit (int retval) |
798 | _exit (int retval = 0) |
761 | CODE: |
799 | CODE: |
762 | _exit (retval); |
800 | _exit (retval); |
763 | |
801 | |
764 | MODULE = CFPlus PACKAGE = CFPlus::Font |
802 | MODULE = CFPlus PACKAGE = CFPlus::Font |
765 | |
803 | |
… | |
… | |
1239 | void |
1277 | void |
1240 | scroll (CFPlus::Map self, int dx, int dy) |
1278 | scroll (CFPlus::Map self, int dx, int dy) |
1241 | CODE: |
1279 | CODE: |
1242 | { |
1280 | { |
1243 | if (dx > 0) |
1281 | if (dx > 0) |
1244 | map_blank (self, self->x, self->y, dx - 1, self->h); |
1282 | map_blank (self, self->x, self->y, dx, self->h); |
1245 | else if (dx < 0) |
1283 | else if (dx < 0) |
1246 | map_blank (self, self->x + self->w + dx + 1, self->y, 1 - dx, self->h); |
1284 | map_blank (self, self->x + self->w + dx + 1, self->y, -dx, self->h); |
1247 | |
1285 | |
1248 | if (dy > 0) |
1286 | if (dy > 0) |
1249 | map_blank (self, self->x, self->y, self->w, dy - 1); |
1287 | map_blank (self, self->x, self->y, self->w, dy); |
1250 | else if (dy < 0) |
1288 | else if (dy < 0) |
1251 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, 1 - dy); |
1289 | map_blank (self, self->x, self->y + self->h + dy + 1, self->w, -dy); |
1252 | |
1290 | |
1253 | self->ox += dx; self->x += dx; |
1291 | self->ox += dx; self->x += dx; |
1254 | self->oy += dy; self->y += dy; |
1292 | self->oy += dy; self->y += dy; |
1255 | |
1293 | |
1256 | while (self->y < 0) |
1294 | while (self->y < 0) |
… | |
… | |
1269 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1307 | uint8_t *data = (uint8_t *)SvPVbyte_nolen (data_); |
1270 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1308 | uint8_t *data_end = (uint8_t *)SvEND (data_); |
1271 | mapcell *cell; |
1309 | mapcell *cell; |
1272 | int x, y, flags; |
1310 | int x, y, flags; |
1273 | |
1311 | |
1274 | while (data < data_end) |
1312 | while (data < data_end - 1) |
1275 | { |
1313 | { |
1276 | flags = (data [0] << 8) + data [1]; data += 2; |
1314 | flags = (data [0] << 8) + data [1]; data += 2; |
1277 | |
1315 | |
1278 | x = self->x + ((flags >> 10) & 63); |
1316 | x = self->x + ((flags >> 10) & 63); |
1279 | y = self->y + ((flags >> 4) & 63); |
1317 | y = self->y + ((flags >> 4) & 63); |
… | |
… | |
1282 | |
1320 | |
1283 | if (flags & 15) |
1321 | if (flags & 15) |
1284 | { |
1322 | { |
1285 | if (!cell->darkness) |
1323 | if (!cell->darkness) |
1286 | { |
1324 | { |
|
|
1325 | memset (cell, 0, sizeof (*cell)); |
1287 | cell->darkness = 256; |
1326 | cell->darkness = 256; |
1288 | cell->face [0] = 0; |
|
|
1289 | cell->face [1] = 0; |
|
|
1290 | cell->face [2] = 0; |
|
|
1291 | cell->stat_hp = 0; |
|
|
1292 | } |
1327 | } |
1293 | |
1328 | |
1294 | //TODO: don't trust server data to be in-range(!) |
1329 | //TODO: don't trust server data to be in-range(!) |
1295 | |
1330 | |
1296 | if (flags & 8) |
1331 | if (flags & 8) |
… | |
… | |
1302 | do |
1337 | do |
1303 | { |
1338 | { |
1304 | ext = *data++; |
1339 | ext = *data++; |
1305 | cmd = ext & 0x3f; |
1340 | cmd = ext & 0x3f; |
1306 | |
1341 | |
1307 | if (ext < 4) |
1342 | if (cmd < 4) |
1308 | cell->darkness = 255 - ext * 64 + 1; |
1343 | cell->darkness = 255 - ext * 64 + 1; |
1309 | else if (ext == 5) // health |
1344 | else if (cmd == 5) // health |
|
|
1345 | { |
|
|
1346 | cell->stat_width = 1; |
1310 | cell->stat_hp = *data++; |
1347 | cell->stat_hp = *data++; |
|
|
1348 | } |
|
|
1349 | else if (cmd == 6) // monster width |
|
|
1350 | cell->stat_width = *data++ + 1; |
|
|
1351 | else if (cmd == 0x47) // monster width |
|
|
1352 | { |
|
|
1353 | if (*data == 4) |
|
|
1354 | ; // decode player tag |
|
|
1355 | |
|
|
1356 | data += *data + 1; |
|
|
1357 | } |
|
|
1358 | else if (cmd == 8) // cell flags |
|
|
1359 | cell->flags = *data++; |
1311 | else if (ext & 0x40) // unknown, multibyte => skip |
1360 | else if (ext & 0x40) // unknown, multibyte => skip |
1312 | data += *data + 1; |
1361 | data += *data + 1; |
|
|
1362 | else |
|
|
1363 | data++; |
1313 | } |
1364 | } |
1314 | while (cmd & 0x80); |
1365 | while (ext & 0x80); |
1315 | } |
1366 | } |
1316 | else |
1367 | else |
1317 | cell->darkness = *data++ + 1; |
1368 | cell->darkness = *data++ + 1; |
1318 | } |
1369 | } |
1319 | |
1370 | |
… | |
… | |
1441 | { |
1492 | { |
1442 | mapcell *cell = row->col + (x + vx - row->c0); |
1493 | mapcell *cell = row->col + (x + vx - row->c0); |
1443 | |
1494 | |
1444 | face = cell->face [z]; |
1495 | face = cell->face [z]; |
1445 | |
1496 | |
1446 | if (face) |
1497 | if (face && face < self->texs) |
1447 | { |
1498 | { |
1448 | maptex tex = self->tex [face]; |
1499 | maptex tex = self->tex [face]; |
1449 | |
|
|
1450 | int px = (x + 1) * 32 - tex.w; |
1500 | int px = (x + 1) * 32 - tex.w; |
1451 | int py = (y + 1) * 32 - tex.h; |
1501 | int py = (y + 1) * 32 - tex.h; |
1452 | |
1502 | |
1453 | if (last_name != tex.name) |
1503 | if (last_name != tex.name) |
1454 | { |
1504 | { |
1455 | glEnd (); |
1505 | glEnd (); |
1456 | last_name = tex.name; |
|
|
1457 | glBindTexture (GL_TEXTURE_2D, last_name); |
1506 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
1458 | glBegin (GL_QUADS); |
1507 | glBegin (GL_QUADS); |
1459 | } |
1508 | } |
1460 | |
1509 | |
1461 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1510 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
1462 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1511 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
1463 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1512 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
1464 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1513 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
1465 | } |
1514 | } |
|
|
1515 | |
|
|
1516 | if (cell->flags && z == 2) |
|
|
1517 | { |
|
|
1518 | if (cell->flags & 1) |
|
|
1519 | { |
|
|
1520 | maptex tex = self->tex [1]; |
|
|
1521 | int px = (x + 1) * 32 - tex.w + 2; |
|
|
1522 | int py = (y + 1) * 32 - tex.h - 6; |
|
|
1523 | |
|
|
1524 | glEnd (); |
|
|
1525 | glBindTexture (GL_TEXTURE_2D, last_name = tex.name); |
|
|
1526 | glBegin (GL_QUADS); |
|
|
1527 | |
|
|
1528 | glTexCoord2f (0 , 0 ); glVertex2f (px , py ); |
|
|
1529 | glTexCoord2f (0 , tex.t); glVertex2f (px , py + tex.h); |
|
|
1530 | glTexCoord2f (tex.s, tex.t); glVertex2f (px + tex.w, py + tex.h); |
|
|
1531 | glTexCoord2f (tex.s, 0 ); glVertex2f (px + tex.w, py ); |
|
|
1532 | } |
|
|
1533 | } |
1466 | } |
1534 | } |
1467 | } |
1535 | } |
1468 | |
1536 | |
1469 | glEnd (); |
1537 | glEnd (); |
1470 | |
1538 | |
1471 | glDisable (GL_TEXTURE_2D); |
1539 | glDisable (GL_TEXTURE_2D); |
1472 | glDisable (GL_BLEND); |
1540 | glDisable (GL_BLEND); |
1473 | |
1541 | |
|
|
1542 | // top layer: overlays such as the health bar |
1474 | for (y = 0; y < sh; y++) |
1543 | for (y = 0; y < sh; y++) |
1475 | if (0 <= y + vy && y + vy < self->rows) |
1544 | if (0 <= y + vy && y + vy < self->rows) |
1476 | { |
1545 | { |
1477 | maprow *row = self->row + (y + vy); |
1546 | maprow *row = self->row + (y + vy); |
1478 | |
1547 | |
… | |
… | |
1484 | int px = x * 32; |
1553 | int px = x * 32; |
1485 | int py = y * 32; |
1554 | int py = y * 32; |
1486 | |
1555 | |
1487 | if (cell->stat_hp) |
1556 | if (cell->stat_hp) |
1488 | { |
1557 | { |
|
|
1558 | int width = cell->stat_width * 32; |
|
|
1559 | int thick = sh / 28 + 1 + cell->stat_width; |
|
|
1560 | |
1489 | glColor3ub (0, 0, 0); |
1561 | glColor3ub (0, 0, 0); |
1490 | glRectf (px + 1, py + 1, px + 31, py + 4); |
1562 | glRectf (px + 1, py - thick - 2, |
|
|
1563 | px + width - 1, py); |
1491 | |
1564 | |
1492 | glColor3ub (0, 255, 0); |
1565 | glColor3ub (cell->stat_hp, 255 - cell->stat_hp, 0); |
1493 | glBegin (GL_LINES); |
|
|
1494 | glVertex2f (px + 2, py + 2.5f); |
1566 | glRectf (px + 2, |
1495 | glVertex2f (px + 29.f - cell->stat_hp * (28.f / 255.f), py + 2.5f); |
1567 | py - thick - 1, |
1496 | glEnd (); |
1568 | px + width - 2 - cell->stat_hp * (width - 4) / 255, py - 1); |
1497 | } |
1569 | } |
1498 | } |
1570 | } |
1499 | } |
1571 | } |
1500 | } |
1572 | } |
1501 | |
1573 | |