ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/common/map.C
(Generate patch)

Comparing deliantra/server/common/map.C (file contents):
Revision 1.201 by root, Sat Jul 10 21:07:47 2010 UTC vs.
Revision 1.215 by root, Sun May 8 12:40:41 2011 UTC

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
363void 363void
364maptile::activate () 364maptile::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
372void 378void
373maptile::deactivate () 379maptile::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
381bool 391bool
382maptile::_save_objects (object_freezer &f, int flags) 392maptile::_save_objects (object_freezer &f, int flags)
383{ 393{
427} 437}
428 438
429void 439void
430maptile::init () 440maptile::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;
661 case KW_value: case KW_swap_time: thawer.get (timeout); break; 671 case KW_value: case KW_swap_time: thawer.get (timeout); break;
662 case KW_level: case KW_difficulty: thawer.get (difficulty); difficulty = clamp (difficulty, 1, settings.max_level); break; 672 case KW_level: case KW_difficulty: thawer.get (difficulty); difficulty = clamp (difficulty, 1, settings.max_level); break;
663 case KW_invisible: case KW_darkness: thawer.get (darkness); break; 673 case KW_invisible: case KW_darkness: thawer.get (darkness); break;
664 case KW_stand_still: case KW_fixed_resettime: thawer.get (fixed_resettime); break; 674 case KW_stand_still: case KW_fixed_resettime: thawer.get (fixed_resettime); break;
665 675
666 case KW_tile_path_1: thawer.get (tile_path [0]); break; 676 case KW_tile_path_1: thawer.get (tile_path [TILE_NORTH]); break;
667 case KW_tile_path_2: thawer.get (tile_path [1]); break; 677 case KW_tile_path_2: thawer.get (tile_path [TILE_EAST ]); break;
668 case KW_tile_path_3: thawer.get (tile_path [2]); break; 678 case KW_tile_path_3: thawer.get (tile_path [TILE_SOUTH]); break;
669 case KW_tile_path_4: thawer.get (tile_path [3]); break; 679 case KW_tile_path_4: thawer.get (tile_path [TILE_WEST ]); break;
680 case KW_tile_path_5: thawer.get (tile_path [TILE_UP ]); break;
681 case KW_tile_path_6: thawer.get (tile_path [TILE_DOWN ]); 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
753 if (maplore) freezer.put (KW(maplore), KW(endmaplore), maplore); 765 if (maplore) freezer.put (KW(maplore), KW(endmaplore), maplore);
754 766
755 MAP_OUT (per_player); 767 MAP_OUT (per_player);
756 MAP_OUT (per_party); 768 MAP_OUT (per_party);
757 769
758 if (tile_path [0]) MAP_OUT2 (tile_path_1, tile_path [0]); 770 if (tile_path [TILE_NORTH]) MAP_OUT2 (tile_path_1, tile_path [TILE_NORTH]);
759 if (tile_path [1]) MAP_OUT2 (tile_path_2, tile_path [1]); 771 if (tile_path [TILE_EAST ]) MAP_OUT2 (tile_path_2, tile_path [TILE_EAST ]);
760 if (tile_path [2]) MAP_OUT2 (tile_path_3, tile_path [2]); 772 if (tile_path [TILE_SOUTH]) MAP_OUT2 (tile_path_3, tile_path [TILE_SOUTH]);
761 if (tile_path [3]) MAP_OUT2 (tile_path_4, tile_path [3]); 773 if (tile_path [TILE_WEST ]) MAP_OUT2 (tile_path_4, tile_path [TILE_WEST ]);
774 if (tile_path [TILE_UP ]) MAP_OUT2 (tile_path_5, tile_path [TILE_UP ]);
775 if (tile_path [TILE_DOWN ]) MAP_OUT2 (tile_path_6, tile_path [TILE_DOWN ]);
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
832maptile::~maptile () 846maptile::~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
850void 864void
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 // set lower map transparent floor flag if applicable
1201 if (floor && floor->flag [FLAG_IS_TRANSPARENT_FLOOR] && !middle && !top)
1202 {
1203 floor->set_anim_frame (0);
1204
1205 if (maptile *m = floor->map->tile_map [TILE_DOWN])
1206 {
1207 mapspace &ms = m->at (floor->x, floor->y);
1208 ms.update ();
1209
1210 if (object *floor2 = ms.faces_obj [2])
1211 if (!floor2->flag [FLAG_IS_TRANSPARENT_FLOOR])
1212 {
1213 floor->set_anim_frame (1);
1214 top = floor;
1215 middle = ms.faces_obj [0];
1216 floor = floor2;
1217 }
1218
1219 ms.pflags |= PF_VIS_UP;
1220 }
1221 }
1222
1186#if 0 1223#if 0
1187 faces_obj [0] = top; 1224 faces_obj [0] = top;
1188 faces_obj [1] = middle; 1225 faces_obj [1] = middle;
1189 faces_obj [2] = floor; 1226 faces_obj [2] = floor;
1190#endif 1227#endif
1191} 1228}
1192 1229
1230void
1231mapspace::update_up ()
1232{
1233 // invalidate up
1234 if (!(pflags & PF_VIS_UP))
1235 return;
1236
1237 pflags &= ~PF_VIS_UP;
1238
1239 if (bot)
1240 if (maptile *m = bot->map->tile_map [TILE_UP])
1241 m->at (bot->x, bot->y).invalidate ();
1242}
1243
1193maptile * 1244maptile *
1194maptile::tile_available (int dir, bool load) 1245maptile::tile_available (int dir, bool load)
1195{ 1246{
1247 // map is there and we don't need to load it OR it's loaded => return what we have
1248 if (tile_map [dir] && (!load || tile_map [dir]->linkable ()))
1249 return tile_map [dir];
1250
1196 if (tile_path[dir]) 1251 if (tile_path [dir])
1197 { 1252 {
1198 if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_ACTIVE)) 1253 // well, try to locate it then, if possible - maybe it's there already
1254 // this is the ONLY place in the server that links maps with each other,
1255 // so any kind of inter-map stuff has to be initiated here.
1256 if (maptile *m = find_async (tile_path [dir], this, load))
1257 {
1258 bool mismatch = false;
1259
1260 if (dir == TILE_NORTH || dir == TILE_SOUTH || dir == TILE_UP || dir == TILE_DOWN)
1261 if (width != m->width)
1262 mismatch = true;
1263
1264 if (dir == TILE_EAST || dir == TILE_WEST || dir == TILE_UP || dir == TILE_DOWN)
1265 if (height != m->height)
1266 mismatch = true;
1267
1268 if (mismatch)
1269 {
1270 LOG (llevError, "tile dimension mismatch for direction %d from %s to %s\n",
1271 dir, &path, &m->path);
1272 m = 0;
1273 }
1274
1275 // as an optimisation, link us against the other map if the other map
1276 // has us as neighbour, which is very common, but not guaranteed.
1277 int dir2 = REVERSE_TILE_DIR (dir);
1278
1279 if (m->tile_path [dir2] == path)
1280 m->tile_map [dir2] = this;
1281
1199 return tile_map[dir]; 1282 return tile_map [dir] = m;
1200 1283 }
1201 if ((tile_map[dir] = find_async (tile_path[dir], this, load)))
1202 return tile_map[dir];
1203 } 1284 }
1204 1285
1205 return 0; 1286 return 0;
1206} 1287}
1207 1288
1223 if (!m) 1304 if (!m)
1224 return 0; 1305 return 0;
1225 1306
1226 if (x < 0) 1307 if (x < 0)
1227 { 1308 {
1228 if (!m->tile_available (3)) 1309 if (!m->tile_available (TILE_WEST))
1229 return 1; 1310 return 1;
1230 1311
1231 return out_of_map (m->tile_map[3], x + m->tile_map[3]->width, y); 1312 return out_of_map (m->tile_map [TILE_WEST], x + m->tile_map [TILE_WEST]->width, y);
1232 } 1313 }
1233 1314
1234 if (x >= m->width) 1315 if (x >= m->width)
1235 { 1316 {
1236 if (!m->tile_available (1)) 1317 if (!m->tile_available (TILE_EAST))
1237 return 1; 1318 return 1;
1238 1319
1239 return out_of_map (m->tile_map[1], x - m->width, y); 1320 return out_of_map (m->tile_map [TILE_EAST], x - m->width, y);
1240 } 1321 }
1241 1322
1242 if (y < 0) 1323 if (y < 0)
1243 { 1324 {
1244 if (!m->tile_available (0)) 1325 if (!m->tile_available (TILE_NORTH))
1245 return 1; 1326 return 1;
1246 1327
1247 return out_of_map (m->tile_map[0], x, y + m->tile_map[0]->height); 1328 return out_of_map (m->tile_map [TILE_NORTH], x, y + m->tile_map [TILE_NORTH]->height);
1248 } 1329 }
1249 1330
1250 if (y >= m->height) 1331 if (y >= m->height)
1251 { 1332 {
1252 if (!m->tile_available (2)) 1333 if (!m->tile_available (TILE_SOUTH))
1253 return 1; 1334 return 1;
1254 1335
1255 return out_of_map (m->tile_map[2], x, y - m->height); 1336 return out_of_map (m->tile_map [TILE_SOUTH], x, y - m->height);
1256 } 1337 }
1257 1338
1258 /* Simple case - coordinates are within this local 1339 /* Simple case - coordinates are within this local
1259 * map. 1340 * map.
1260 */ 1341 */
1272maptile * 1353maptile *
1273maptile::xy_find (sint16 &x, sint16 &y) 1354maptile::xy_find (sint16 &x, sint16 &y)
1274{ 1355{
1275 if (x < 0) 1356 if (x < 0)
1276 { 1357 {
1277 if (!tile_available (3)) 1358 if (!tile_available (TILE_WEST))
1278 return 0; 1359 return 0;
1279 1360
1280 x += tile_map[3]->width; 1361 x += tile_map [TILE_WEST]->width;
1281 return tile_map[3]->xy_find (x, y); 1362 return tile_map [TILE_WEST]->xy_find (x, y);
1282 } 1363 }
1283 1364
1284 if (x >= width) 1365 if (x >= width)
1285 { 1366 {
1286 if (!tile_available (1)) 1367 if (!tile_available (TILE_EAST))
1287 return 0; 1368 return 0;
1288 1369
1289 x -= width; 1370 x -= width;
1290 return tile_map[1]->xy_find (x, y); 1371 return tile_map [TILE_EAST]->xy_find (x, y);
1291 } 1372 }
1292 1373
1293 if (y < 0) 1374 if (y < 0)
1294 { 1375 {
1295 if (!tile_available (0)) 1376 if (!tile_available (TILE_NORTH))
1296 return 0; 1377 return 0;
1297 1378
1298 y += tile_map[0]->height; 1379 y += tile_map [TILE_NORTH]->height;
1299 return tile_map[0]->xy_find (x, y); 1380 return tile_map [TILE_NORTH]->xy_find (x, y);
1300 } 1381 }
1301 1382
1302 if (y >= height) 1383 if (y >= height)
1303 { 1384 {
1304 if (!tile_available (2)) 1385 if (!tile_available (TILE_SOUTH))
1305 return 0; 1386 return 0;
1306 1387
1307 y -= height; 1388 y -= height;
1308 return tile_map[2]->xy_find (x, y); 1389 return tile_map [TILE_SOUTH]->xy_find (x, y);
1309 } 1390 }
1310 1391
1311 /* Simple case - coordinates are within this local 1392 /* Simple case - coordinates are within this local
1312 * map. 1393 * map.
1313 */ 1394 */
1329 if (map1 == map2) 1410 if (map1 == map2)
1330 { 1411 {
1331 *dx = 0; 1412 *dx = 0;
1332 *dy = 0; 1413 *dy = 0;
1333 } 1414 }
1334 else if (map1->tile_available (0, false) == map2) 1415 else if (map1->tile_available (TILE_NORTH, false) == map2)
1335 { /* up */ 1416 {
1336 *dx = 0; 1417 *dx = 0;
1337 *dy = -map2->height; 1418 *dy = -map2->height;
1338 } 1419 }
1339 else if (map1->tile_available (1, false) == map2) 1420 else if (map1->tile_available (TILE_EAST , false) == map2)
1340 { /* right */ 1421 {
1341 *dx = map1->width; 1422 *dx = map1->width;
1342 *dy = 0; 1423 *dy = 0;
1343 } 1424 }
1344 else if (map1->tile_available (2, false) == map2) 1425 else if (map1->tile_available (TILE_SOUTH, false) == map2)
1345 { /* down */ 1426 {
1346 *dx = 0; 1427 *dx = 0;
1347 *dy = map1->height; 1428 *dy = map1->height;
1348 } 1429 }
1349 else if (map1->tile_available (3, false) == map2) 1430 else if (map1->tile_available (TILE_WEST , false) == map2)
1350 { /* left */ 1431 {
1351 *dx = -map2->width; 1432 *dx = -map2->width;
1352 *dy = 0; 1433 *dy = 0;
1353 } 1434 }
1354 else if (map1->tile_map[0] && map1->tile_map[0]->tile_available (1, false) == map2) 1435 else if (map1->tile_map[TILE_NORTH] && map1->tile_map[TILE_NORTH]->tile_available (TILE_EAST , false) == map2)
1355 { /* up right */ 1436 { /* up right */
1356 *dx = map1->tile_map[0]->width; 1437 *dx = +map1->tile_map[TILE_NORTH]->width;
1357 *dy = -map1->tile_map[0]->height; 1438 *dy = -map1->tile_map[TILE_NORTH]->height;
1358 } 1439 }
1359 else if (map1->tile_map[0] && map1->tile_map[0]->tile_available (3, false) == map2) 1440 else if (map1->tile_map[TILE_NORTH] && map1->tile_map[TILE_NORTH]->tile_available (TILE_WEST , false) == map2)
1360 { /* up left */ 1441 { /* up left */
1361 *dx = -map2->width; 1442 *dx = -map2->width;
1362 *dy = -map1->tile_map[0]->height; 1443 *dy = -map1->tile_map[TILE_NORTH]->height;
1363 } 1444 }
1364 else if (map1->tile_map[1] && map1->tile_map[1]->tile_available (0, false) == map2) 1445 else if (map1->tile_map[TILE_EAST ] && map1->tile_map[TILE_EAST ]->tile_available (TILE_NORTH, false) == map2)
1365 { /* right up */ 1446 { /* right up */
1366 *dx = map1->width; 1447 *dx = +map1->width;
1367 *dy = -map2->height; 1448 *dy = -map2->height;
1368 } 1449 }
1369 else if (map1->tile_map[1] && map1->tile_map[1]->tile_available (2, false) == map2) 1450 else if (map1->tile_map[TILE_EAST ] && map1->tile_map[TILE_EAST ]->tile_available (TILE_SOUTH, false) == map2)
1370 { /* right down */ 1451 { /* right down */
1371 *dx = map1->width; 1452 *dx = +map1->width;
1372 *dy = map1->tile_map[1]->height; 1453 *dy = +map1->tile_map[TILE_EAST]->height;
1373 } 1454 }
1374 else if (map1->tile_map[2] && map1->tile_map[2]->tile_available (1, false) == map2) 1455 else if (map1->tile_map[TILE_SOUTH] && map1->tile_map[TILE_SOUTH]->tile_available (TILE_EAST , false) == map2)
1375 { /* down right */ 1456 { /* down right */
1376 *dx = map1->tile_map[2]->width; 1457 *dx = +map1->tile_map[TILE_SOUTH]->width;
1377 *dy = map1->height; 1458 *dy = +map1->height;
1378 } 1459 }
1379 else if (map1->tile_map[2] && map1->tile_map[2]->tile_available (3, false) == map2) 1460 else if (map1->tile_map[TILE_SOUTH] && map1->tile_map[TILE_SOUTH]->tile_available (TILE_WEST , false) == map2)
1380 { /* down left */ 1461 { /* down left */
1381 *dx = -map2->width; 1462 *dx = -map2->width;
1382 *dy = map1->height; 1463 *dy = +map1->height;
1383 } 1464 }
1384 else if (map1->tile_map[3] && map1->tile_map[3]->tile_available (0, false) == map2) 1465 else if (map1->tile_map[TILE_WEST ] && map1->tile_map[TILE_WEST ]->tile_available (TILE_NORTH, false) == map2)
1385 { /* left up */ 1466 { /* left up */
1386 *dx = -map1->tile_map[3]->width; 1467 *dx = -map1->tile_map[TILE_WEST]->width;
1387 *dy = -map2->height; 1468 *dy = -map2->height;
1388 } 1469 }
1389 else if (map1->tile_map[3] && map1->tile_map[3]->tile_available (2, false) == map2) 1470 else if (map1->tile_map[TILE_WEST ] && map1->tile_map[TILE_WEST ]->tile_available (TILE_SOUTH, false) == map2)
1390 { /* left down */ 1471 { /* left down */
1391 *dx = -map1->tile_map[3]->width; 1472 *dx = -map1->tile_map[TILE_WEST]->width;
1392 *dy = map1->tile_map[3]->height; 1473 *dy = +map1->tile_map[TILE_WEST]->height;
1393 } 1474 }
1394 else 1475 else
1395 return 0; 1476 return 0;
1396 1477
1397 return 1; 1478 return 1;
1629split_to_tiles (dynbuf &buf, maptile *m, int x0, int y0, int x1, int y1, int dx, int dy) 1710split_to_tiles (dynbuf &buf, maptile *m, int x0, int y0, int x1, int y1, int dx, int dy)
1630{ 1711{
1631 // clip to map to the left 1712 // clip to map to the left
1632 if (x0 < 0) 1713 if (x0 < 0)
1633 { 1714 {
1634 if (maptile *tile = m->tile_available (TILE_LEFT, 1)) 1715 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); 1716 split_to_tiles (buf, tile, x0 + tile->width, y0, min (x1 + tile->width, tile->width), y1, dx - tile->width, dy);
1636 1717
1637 if (x1 < 0) // entirely to the left 1718 if (x1 < 0) // entirely to the left
1638 return; 1719 return;
1639 1720
1641 } 1722 }
1642 1723
1643 // clip to map to the right 1724 // clip to map to the right
1644 if (x1 > m->width) 1725 if (x1 > m->width)
1645 { 1726 {
1646 if (maptile *tile = m->tile_available (TILE_RIGHT, 1)) 1727 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); 1728 split_to_tiles (buf, tile, max (x0 - m->width, 0), y0, x1 - m->width, y1, dx + m->width, dy);
1648 1729
1649 if (x0 > m->width) // entirely to the right 1730 if (x0 > m->width) // entirely to the right
1650 return; 1731 return;
1651 1732
1653 } 1734 }
1654 1735
1655 // clip to map above 1736 // clip to map above
1656 if (y0 < 0) 1737 if (y0 < 0)
1657 { 1738 {
1658 if (maptile *tile = m->tile_available (TILE_UP, 1)) 1739 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); 1740 split_to_tiles (buf, tile, x0, y0 + tile->height, x1, min (y1 + tile->height, tile->height), dx, dy - tile->height);
1660 1741
1661 if (y1 < 0) // entirely above 1742 if (y1 < 0) // entirely above
1662 return; 1743 return;
1663 1744
1665 } 1746 }
1666 1747
1667 // clip to map below 1748 // clip to map below
1668 if (y1 > m->height) 1749 if (y1 > m->height)
1669 { 1750 {
1670 if (maptile *tile = m->tile_available (TILE_DOWN, 1)) 1751 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); 1752 split_to_tiles (buf, tile, x0, max (y0 - m->height, 0), x1, y1 - m->height, dx, dy + m->height);
1672 1753
1673 if (y0 > m->height) // entirely below 1754 if (y0 > m->height) // entirely below
1674 return; 1755 return;
1675 1756

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines