1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2001-2003 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2001-2003 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | * the terms of the Affero GNU General Public License as published by the |
… | |
… | |
361 | } |
361 | } |
362 | |
362 | |
363 | void |
363 | void |
364 | maptile::activate () |
364 | maptile::activate () |
365 | { |
365 | { |
366 | if (spaces) |
366 | if (state != MAP_INACTIVE) |
|
|
367 | return; |
|
|
368 | |
367 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
369 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
368 | for (object *op = ms->bot; op; op = op->above) |
370 | for (object *op = ms->bot; op; op = op->above) |
369 | op->activate_recursive (); |
371 | op->activate_recursive (); |
|
|
372 | |
|
|
373 | state = MAP_ACTIVE; |
|
|
374 | |
|
|
375 | activate_physics (); |
370 | } |
376 | } |
371 | |
377 | |
372 | void |
378 | void |
373 | maptile::deactivate () |
379 | maptile::deactivate () |
374 | { |
380 | { |
375 | if (spaces) |
381 | if (state != MAP_ACTIVE) |
|
|
382 | return; |
|
|
383 | |
376 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
384 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
377 | for (object *op = ms->bot; op; op = op->above) |
385 | for (object *op = ms->bot; op; op = op->above) |
378 | op->deactivate_recursive (); |
386 | op->deactivate_recursive (); |
|
|
387 | |
|
|
388 | state = MAP_INACTIVE; |
379 | } |
389 | } |
380 | |
390 | |
381 | bool |
391 | bool |
382 | maptile::_save_objects (object_freezer &f, int flags) |
392 | maptile::_save_objects (object_freezer &f, int flags) |
383 | { |
393 | { |
… | |
… | |
427 | } |
437 | } |
428 | |
438 | |
429 | void |
439 | void |
430 | maptile::init () |
440 | maptile::init () |
431 | { |
441 | { |
432 | in_memory = MAP_SWAPPED; |
442 | state = MAP_SWAPPED; |
433 | |
443 | |
434 | /* The maps used to pick up default x and y values from the |
444 | /* The maps used to pick up default x and y values from the |
435 | * map archetype. Mimic that behaviour. |
445 | * map archetype. Mimic that behaviour. |
436 | */ |
446 | */ |
437 | width = 16; |
447 | width = 16; |
… | |
… | |
614 | { |
624 | { |
615 | case KW_msg: |
625 | case KW_msg: |
616 | thawer.get_ml (KW_endmsg, msg); |
626 | thawer.get_ml (KW_endmsg, msg); |
617 | break; |
627 | break; |
618 | |
628 | |
619 | case KW_lore: // CF+ extension |
629 | case KW_lore: // deliantra extension |
620 | thawer.get_ml (KW_endlore, maplore); |
630 | thawer.get_ml (KW_endlore, maplore); |
621 | break; |
631 | break; |
622 | |
632 | |
623 | case KW_maplore: |
633 | case KW_maplore: |
624 | thawer.get_ml (KW_endmaplore, maplore); |
634 | thawer.get_ml (KW_endmaplore, maplore); |
… | |
… | |
665 | |
675 | |
666 | case KW_tile_path_1: thawer.get (tile_path [0]); break; |
676 | case KW_tile_path_1: thawer.get (tile_path [0]); break; |
667 | case KW_tile_path_2: thawer.get (tile_path [1]); break; |
677 | case KW_tile_path_2: thawer.get (tile_path [1]); break; |
668 | case KW_tile_path_3: thawer.get (tile_path [2]); break; |
678 | case KW_tile_path_3: thawer.get (tile_path [2]); break; |
669 | case KW_tile_path_4: thawer.get (tile_path [3]); break; |
679 | case KW_tile_path_4: thawer.get (tile_path [3]); break; |
|
|
680 | case KW_tile_path_5: thawer.get (tile_path [4]); break; |
|
|
681 | case KW_tile_path_6: thawer.get (tile_path [5]); break; |
670 | |
682 | |
671 | case KW_ERROR: |
683 | case KW_ERROR: |
672 | set_key_text (thawer.kw_str, thawer.value); |
684 | set_key_text (thawer.kw_str, thawer.value); |
673 | break; |
685 | break; |
674 | |
686 | |
… | |
… | |
757 | |
769 | |
758 | if (tile_path [0]) MAP_OUT2 (tile_path_1, tile_path [0]); |
770 | if (tile_path [0]) MAP_OUT2 (tile_path_1, tile_path [0]); |
759 | if (tile_path [1]) MAP_OUT2 (tile_path_2, tile_path [1]); |
771 | if (tile_path [1]) MAP_OUT2 (tile_path_2, tile_path [1]); |
760 | if (tile_path [2]) MAP_OUT2 (tile_path_3, tile_path [2]); |
772 | if (tile_path [2]) MAP_OUT2 (tile_path_3, tile_path [2]); |
761 | if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); |
773 | if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); |
|
|
774 | if (tile_path [4]) MAP_OUT2 (tile_path_5, tile_path [4]); |
|
|
775 | if (tile_path [5]) MAP_OUT2 (tile_path_6, tile_path [5]); |
762 | |
776 | |
763 | freezer.put (this); |
777 | freezer.put (this); |
764 | freezer.put (KW(end)); |
778 | freezer.put (KW(end)); |
765 | |
779 | |
766 | return true; |
780 | return true; |
… | |
… | |
823 | msg = 0; |
837 | msg = 0; |
824 | maplore = 0; |
838 | maplore = 0; |
825 | shoprace = 0; |
839 | shoprace = 0; |
826 | delete [] shopitems, shopitems = 0; |
840 | delete [] shopitems, shopitems = 0; |
827 | |
841 | |
828 | for (int i = 0; i < 4; i++) |
842 | for (int i = 0; i < array_length (tile_path); i++) |
829 | tile_path [i] = 0; |
843 | tile_path [i] = 0; |
830 | } |
844 | } |
831 | |
845 | |
832 | maptile::~maptile () |
846 | maptile::~maptile () |
833 | { |
847 | { |
… | |
… | |
840 | /* We need to look through all the maps and see if any maps |
854 | /* We need to look through all the maps and see if any maps |
841 | * are pointing at this one for tiling information. Since |
855 | * are pointing at this one for tiling information. Since |
842 | * tiling can be asymetric, we just can not look to see which |
856 | * tiling can be asymetric, we just can not look to see which |
843 | * maps this map tiles with and clears those. |
857 | * maps this map tiles with and clears those. |
844 | */ |
858 | */ |
845 | for (int i = 0; i < 4; i++) |
859 | for (int i = 0; i < array_length (tile_path); i++) |
846 | if (tile_map[i] == m) |
860 | if (tile_map[i] == m) |
847 | tile_map[i] = 0; |
861 | tile_map[i] = 0; |
848 | } |
862 | } |
849 | |
863 | |
850 | void |
864 | void |
… | |
… | |
1181 | middle = 0; |
1195 | middle = 0; |
1182 | |
1196 | |
1183 | if (top == middle) |
1197 | if (top == middle) |
1184 | middle = 0; |
1198 | middle = 0; |
1185 | |
1199 | |
|
|
1200 | // dire hack to handle "transparent" floors - currently only open_space |
|
|
1201 | if (floor && floor->arch->archname == shstr_quad_open_space) |
|
|
1202 | { |
|
|
1203 | floor->set_anim_frame (0); |
|
|
1204 | |
|
|
1205 | if (maptile *m = floor->map->tile_map [TILE_DOWN]) |
|
|
1206 | { |
|
|
1207 | // mirror the floor - very unreliable because usually outdated, |
|
|
1208 | // but somewhta works because floors do not change often :/ |
|
|
1209 | middle = floor; |
|
|
1210 | |
|
|
1211 | mapspace &ms = m->at (floor->x, floor->y); |
|
|
1212 | |
|
|
1213 | ms.update (); |
|
|
1214 | |
|
|
1215 | if (object *floor2 = ms.faces_obj [2]) |
|
|
1216 | if (floor2->arch->archname != shstr_quad_open_space && !middle) |
|
|
1217 | { |
|
|
1218 | floor->set_anim_frame (1); |
|
|
1219 | middle = floor; |
|
|
1220 | floor = floor2; |
|
|
1221 | } |
|
|
1222 | } |
|
|
1223 | } |
|
|
1224 | |
1186 | #if 0 |
1225 | #if 0 |
1187 | faces_obj [0] = top; |
1226 | faces_obj [0] = top; |
1188 | faces_obj [1] = middle; |
1227 | faces_obj [1] = middle; |
1189 | faces_obj [2] = floor; |
1228 | faces_obj [2] = floor; |
1190 | #endif |
1229 | #endif |
… | |
… | |
1193 | maptile * |
1232 | maptile * |
1194 | maptile::tile_available (int dir, bool load) |
1233 | maptile::tile_available (int dir, bool load) |
1195 | { |
1234 | { |
1196 | if (tile_path[dir]) |
1235 | if (tile_path[dir]) |
1197 | { |
1236 | { |
|
|
1237 | // map is there and we don't need to load it OR it's loaded => return what we have |
1198 | if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_ACTIVE)) |
1238 | if (tile_map[dir] && (!load || tile_map[dir]->linkable ())) |
1199 | return tile_map[dir]; |
1239 | return tile_map[dir]; |
1200 | |
1240 | |
|
|
1241 | // well, try to locate it then, if possible - maybe it's there already |
1201 | if ((tile_map[dir] = find_async (tile_path[dir], this, load))) |
1242 | if ((tile_map[dir] = find_async (tile_path[dir], this, load))) |
1202 | return tile_map[dir]; |
1243 | return tile_map[dir]; |
1203 | } |
1244 | } |
1204 | |
1245 | |
1205 | return 0; |
1246 | return 0; |
… | |
… | |
1329 | if (map1 == map2) |
1370 | if (map1 == map2) |
1330 | { |
1371 | { |
1331 | *dx = 0; |
1372 | *dx = 0; |
1332 | *dy = 0; |
1373 | *dy = 0; |
1333 | } |
1374 | } |
1334 | else if (map1->tile_available (0, false) == map2) |
1375 | else if (map1->tile_available (TILE_NORTH, false) == map2) |
1335 | { /* up */ |
1376 | { |
1336 | *dx = 0; |
1377 | *dx = 0; |
1337 | *dy = -map2->height; |
1378 | *dy = -map2->height; |
1338 | } |
1379 | } |
1339 | else if (map1->tile_available (1, false) == map2) |
1380 | else if (map1->tile_available (TILE_EAST , false) == map2) |
1340 | { /* right */ |
1381 | { |
1341 | *dx = map1->width; |
1382 | *dx = map1->width; |
1342 | *dy = 0; |
1383 | *dy = 0; |
1343 | } |
1384 | } |
1344 | else if (map1->tile_available (2, false) == map2) |
1385 | else if (map1->tile_available (TILE_SOUTH, false) == map2) |
1345 | { /* down */ |
1386 | { |
1346 | *dx = 0; |
1387 | *dx = 0; |
1347 | *dy = map1->height; |
1388 | *dy = map1->height; |
1348 | } |
1389 | } |
1349 | else if (map1->tile_available (3, false) == map2) |
1390 | else if (map1->tile_available (TILE_WEST , false) == map2) |
1350 | { /* left */ |
1391 | { |
1351 | *dx = -map2->width; |
1392 | *dx = -map2->width; |
1352 | *dy = 0; |
1393 | *dy = 0; |
1353 | } |
1394 | } |
1354 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_available (1, false) == map2) |
1395 | else if (map1->tile_map[TILE_NORTH] && map1->tile_map[TILE_NORTH]->tile_available (TILE_EAST , false) == map2) |
1355 | { /* up right */ |
1396 | { /* up right */ |
1356 | *dx = map1->tile_map[0]->width; |
1397 | *dx = +map1->tile_map[TILE_NORTH]->width; |
1357 | *dy = -map1->tile_map[0]->height; |
1398 | *dy = -map1->tile_map[TILE_NORTH]->height; |
1358 | } |
1399 | } |
1359 | else if (map1->tile_map[0] && map1->tile_map[0]->tile_available (3, false) == map2) |
1400 | else if (map1->tile_map[TILE_NORTH] && map1->tile_map[TILE_NORTH]->tile_available (TILE_WEST , false) == map2) |
1360 | { /* up left */ |
1401 | { /* up left */ |
1361 | *dx = -map2->width; |
1402 | *dx = -map2->width; |
1362 | *dy = -map1->tile_map[0]->height; |
1403 | *dy = -map1->tile_map[TILE_NORTH]->height; |
1363 | } |
1404 | } |
1364 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_available (0, false) == map2) |
1405 | else if (map1->tile_map[TILE_EAST ] && map1->tile_map[TILE_EAST ]->tile_available (TILE_NORTH, false) == map2) |
1365 | { /* right up */ |
1406 | { /* right up */ |
1366 | *dx = map1->width; |
1407 | *dx = +map1->width; |
1367 | *dy = -map2->height; |
1408 | *dy = -map2->height; |
1368 | } |
1409 | } |
1369 | else if (map1->tile_map[1] && map1->tile_map[1]->tile_available (2, false) == map2) |
1410 | else if (map1->tile_map[TILE_EAST ] && map1->tile_map[TILE_EAST ]->tile_available (TILE_SOUTH, false) == map2) |
1370 | { /* right down */ |
1411 | { /* right down */ |
1371 | *dx = map1->width; |
1412 | *dx = +map1->width; |
1372 | *dy = map1->tile_map[1]->height; |
1413 | *dy = +map1->tile_map[TILE_EAST]->height; |
1373 | } |
1414 | } |
1374 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_available (1, false) == map2) |
1415 | else if (map1->tile_map[TILE_SOUTH] && map1->tile_map[TILE_SOUTH]->tile_available (TILE_EAST , false) == map2) |
1375 | { /* down right */ |
1416 | { /* down right */ |
1376 | *dx = map1->tile_map[2]->width; |
1417 | *dx = +map1->tile_map[TILE_SOUTH]->width; |
1377 | *dy = map1->height; |
1418 | *dy = +map1->height; |
1378 | } |
1419 | } |
1379 | else if (map1->tile_map[2] && map1->tile_map[2]->tile_available (3, false) == map2) |
1420 | else if (map1->tile_map[TILE_SOUTH] && map1->tile_map[TILE_SOUTH]->tile_available (TILE_WEST , false) == map2) |
1380 | { /* down left */ |
1421 | { /* down left */ |
1381 | *dx = -map2->width; |
1422 | *dx = -map2->width; |
1382 | *dy = map1->height; |
1423 | *dy = +map1->height; |
1383 | } |
1424 | } |
1384 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_available (0, false) == map2) |
1425 | else if (map1->tile_map[TILE_WEST ] && map1->tile_map[TILE_WEST ]->tile_available (TILE_NORTH, false) == map2) |
1385 | { /* left up */ |
1426 | { /* left up */ |
1386 | *dx = -map1->tile_map[3]->width; |
1427 | *dx = -map1->tile_map[TILE_WEST]->width; |
1387 | *dy = -map2->height; |
1428 | *dy = -map2->height; |
1388 | } |
1429 | } |
1389 | else if (map1->tile_map[3] && map1->tile_map[3]->tile_available (2, false) == map2) |
1430 | else if (map1->tile_map[TILE_WEST ] && map1->tile_map[TILE_WEST ]->tile_available (TILE_SOUTH, false) == map2) |
1390 | { /* left down */ |
1431 | { /* left down */ |
1391 | *dx = -map1->tile_map[3]->width; |
1432 | *dx = -map1->tile_map[TILE_WEST]->width; |
1392 | *dy = map1->tile_map[3]->height; |
1433 | *dy = +map1->tile_map[TILE_WEST]->height; |
1393 | } |
1434 | } |
1394 | else |
1435 | else |
1395 | return 0; |
1436 | return 0; |
1396 | |
1437 | |
1397 | return 1; |
1438 | return 1; |
… | |
… | |
1629 | split_to_tiles (dynbuf &buf, maptile *m, int x0, int y0, int x1, int y1, int dx, int dy) |
1670 | split_to_tiles (dynbuf &buf, maptile *m, int x0, int y0, int x1, int y1, int dx, int dy) |
1630 | { |
1671 | { |
1631 | // clip to map to the left |
1672 | // clip to map to the left |
1632 | if (x0 < 0) |
1673 | if (x0 < 0) |
1633 | { |
1674 | { |
1634 | if (maptile *tile = m->tile_available (TILE_LEFT, 1)) |
1675 | if (maptile *tile = m->tile_available (TILE_WEST, 1)) |
1635 | split_to_tiles (buf, tile, x0 + tile->width, y0, min (x1 + tile->width, tile->width), y1, dx - tile->width, dy); |
1676 | split_to_tiles (buf, tile, x0 + tile->width, y0, min (x1 + tile->width, tile->width), y1, dx - tile->width, dy); |
1636 | |
1677 | |
1637 | if (x1 < 0) // entirely to the left |
1678 | if (x1 < 0) // entirely to the left |
1638 | return; |
1679 | return; |
1639 | |
1680 | |
… | |
… | |
1641 | } |
1682 | } |
1642 | |
1683 | |
1643 | // clip to map to the right |
1684 | // clip to map to the right |
1644 | if (x1 > m->width) |
1685 | if (x1 > m->width) |
1645 | { |
1686 | { |
1646 | if (maptile *tile = m->tile_available (TILE_RIGHT, 1)) |
1687 | if (maptile *tile = m->tile_available (TILE_EAST, 1)) |
1647 | split_to_tiles (buf, tile, max (x0 - m->width, 0), y0, x1 - m->width, y1, dx + m->width, dy); |
1688 | split_to_tiles (buf, tile, max (x0 - m->width, 0), y0, x1 - m->width, y1, dx + m->width, dy); |
1648 | |
1689 | |
1649 | if (x0 > m->width) // entirely to the right |
1690 | if (x0 > m->width) // entirely to the right |
1650 | return; |
1691 | return; |
1651 | |
1692 | |
… | |
… | |
1653 | } |
1694 | } |
1654 | |
1695 | |
1655 | // clip to map above |
1696 | // clip to map above |
1656 | if (y0 < 0) |
1697 | if (y0 < 0) |
1657 | { |
1698 | { |
1658 | if (maptile *tile = m->tile_available (TILE_UP, 1)) |
1699 | if (maptile *tile = m->tile_available (TILE_NORTH, 1)) |
1659 | split_to_tiles (buf, tile, x0, y0 + tile->height, x1, min (y1 + tile->height, tile->height), dx, dy - tile->height); |
1700 | split_to_tiles (buf, tile, x0, y0 + tile->height, x1, min (y1 + tile->height, tile->height), dx, dy - tile->height); |
1660 | |
1701 | |
1661 | if (y1 < 0) // entirely above |
1702 | if (y1 < 0) // entirely above |
1662 | return; |
1703 | return; |
1663 | |
1704 | |
… | |
… | |
1665 | } |
1706 | } |
1666 | |
1707 | |
1667 | // clip to map below |
1708 | // clip to map below |
1668 | if (y1 > m->height) |
1709 | if (y1 > m->height) |
1669 | { |
1710 | { |
1670 | if (maptile *tile = m->tile_available (TILE_DOWN, 1)) |
1711 | if (maptile *tile = m->tile_available (TILE_SOUTH, 1)) |
1671 | split_to_tiles (buf, tile, x0, max (y0 - m->height, 0), x1, y1 - m->height, dx, dy + m->height); |
1712 | split_to_tiles (buf, tile, x0, max (y0 - m->height, 0), x1, y1 - m->height, dx, dy + m->height); |
1672 | |
1713 | |
1673 | if (y0 > m->height) // entirely below |
1714 | if (y0 > m->height) // entirely below |
1674 | return; |
1715 | return; |
1675 | |
1716 | |