… | |
… | |
355 | } |
355 | } |
356 | |
356 | |
357 | void |
357 | void |
358 | maptile::activate () |
358 | maptile::activate () |
359 | { |
359 | { |
360 | active = true; |
|
|
361 | |
|
|
362 | if (spaces) |
360 | if (spaces) |
363 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
361 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
364 | for (object *op = ms->bot; op; op = op->above) |
362 | for (object *op = ms->bot; op; op = op->above) |
365 | op->activate_recursive (); |
363 | op->activate_recursive (); |
366 | } |
364 | } |
367 | |
365 | |
368 | void |
366 | void |
369 | maptile::deactivate () |
367 | maptile::deactivate () |
370 | { |
368 | { |
371 | active = false; |
|
|
372 | |
|
|
373 | if (spaces) |
369 | if (spaces) |
374 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
370 | for (mapspace *ms = spaces + size (); ms-- > spaces; ) |
375 | for (object *op = ms->bot; op; op = op->above) |
371 | for (object *op = ms->bot; op; op = op->above) |
376 | op->deactivate_recursive (); |
372 | op->deactivate_recursive (); |
377 | } |
373 | } |
… | |
… | |
1228 | vol += op->volume (); |
1224 | vol += op->volume (); |
1229 | |
1225 | |
1230 | return vol; |
1226 | return vol; |
1231 | } |
1227 | } |
1232 | |
1228 | |
1233 | /* this updates the orig_map->tile_map[tile_num] value after finding |
1229 | bool |
1234 | * the map. It also takes care of linking back the freshly found |
1230 | maptile::tile_available (int dir, bool load) |
1235 | * maps tile_map values if it tiles back to this one. It returns |
|
|
1236 | * the value of orig_map->tile_map[tile_num]. |
|
|
1237 | */ |
|
|
1238 | static inline maptile * |
|
|
1239 | find_and_link (maptile *orig_map, int tile_num) |
|
|
1240 | { |
1231 | { |
1241 | maptile *mp = orig_map->tile_map [tile_num]; |
1232 | if (!tile_path[dir]) |
|
|
1233 | return 0; |
1242 | |
1234 | |
1243 | if (!mp) |
1235 | if (tile_map[dir] && (!load || tile_map[dir]->in_memory == MAP_IN_MEMORY)) |
1244 | { |
1236 | return 1; |
1245 | mp = orig_map->find_sync (orig_map->tile_path [tile_num], orig_map); |
|
|
1246 | |
1237 | |
1247 | if (!mp) |
1238 | if ((tile_map[dir] = find_async (tile_path[dir], this, load))) |
1248 | { |
1239 | return 1; |
1249 | // emergency mode, manufacture a dummy map, this creates a memleak, but thats fine |
|
|
1250 | LOG (llevError, "FATAL: cannot load tiled map %s from %s, leaking memory and worse!\n", |
|
|
1251 | &orig_map->tile_path[tile_num], &orig_map->path); |
|
|
1252 | mp = new maptile (1, 1); |
|
|
1253 | mp->alloc (); |
|
|
1254 | mp->in_memory = MAP_IN_MEMORY; |
|
|
1255 | } |
|
|
1256 | } |
|
|
1257 | |
1240 | |
1258 | int dest_tile = (tile_num + 2) % 4; |
|
|
1259 | |
|
|
1260 | orig_map->tile_map [tile_num] = mp; |
|
|
1261 | |
|
|
1262 | // optimisation: back-link map to origin map if euclidean |
|
|
1263 | //TODO: non-euclidean maps MUST GO |
|
|
1264 | if (orig_map->tile_map[tile_num]->tile_path[dest_tile] == orig_map->path) |
|
|
1265 | orig_map->tile_map[tile_num]->tile_map[dest_tile] = orig_map; |
|
|
1266 | |
|
|
1267 | return mp; |
1241 | return 0; |
1268 | } |
|
|
1269 | |
|
|
1270 | static inline void |
|
|
1271 | load_and_link (maptile *orig_map, int tile_num) |
|
|
1272 | { |
|
|
1273 | find_and_link (orig_map, tile_num)->load_sync (); |
|
|
1274 | } |
1242 | } |
1275 | |
1243 | |
1276 | /* this returns TRUE if the coordinates (x,y) are out of |
1244 | /* this returns TRUE if the coordinates (x,y) are out of |
1277 | * map m. This function also takes into account any |
1245 | * map m. This function also takes into account any |
1278 | * tiling considerations, loading adjacant maps as needed. |
1246 | * tiling considerations, loading adjacant maps as needed. |
… | |
… | |
1291 | if (!m) |
1259 | if (!m) |
1292 | return 0; |
1260 | return 0; |
1293 | |
1261 | |
1294 | if (x < 0) |
1262 | if (x < 0) |
1295 | { |
1263 | { |
1296 | if (!m->tile_path[3]) |
1264 | if (!m->tile_available (3, 0)) |
1297 | return 1; |
1265 | return 1; |
1298 | |
1266 | |
1299 | if (!m->tile_map[3] || m->tile_map[3]->in_memory != MAP_IN_MEMORY) |
|
|
1300 | find_and_link (m, 3); |
|
|
1301 | |
|
|
1302 | return out_of_map (m->tile_map[3], x + m->tile_map[3]->width, y); |
1267 | return out_of_map (m->tile_map[3], x + m->tile_map[3]->width, y); |
1303 | } |
1268 | } |
1304 | |
1269 | |
1305 | if (x >= m->width) |
1270 | if (x >= m->width) |
1306 | { |
1271 | { |
1307 | if (!m->tile_path[1]) |
1272 | if (!m->tile_available (1, 0)) |
1308 | return 1; |
1273 | return 1; |
1309 | |
1274 | |
1310 | if (!m->tile_map[1] || m->tile_map[1]->in_memory != MAP_IN_MEMORY) |
|
|
1311 | find_and_link (m, 1); |
|
|
1312 | |
|
|
1313 | return out_of_map (m->tile_map[1], x - m->width, y); |
1275 | return out_of_map (m->tile_map[1], x - m->width, y); |
1314 | } |
1276 | } |
1315 | |
1277 | |
1316 | if (y < 0) |
1278 | if (y < 0) |
1317 | { |
1279 | { |
1318 | if (!m->tile_path[0]) |
1280 | if (!m->tile_available (0, 0)) |
1319 | return 1; |
1281 | return 1; |
1320 | |
1282 | |
1321 | if (!m->tile_map[0] || m->tile_map[0]->in_memory != MAP_IN_MEMORY) |
|
|
1322 | find_and_link (m, 0); |
|
|
1323 | |
|
|
1324 | return out_of_map (m->tile_map[0], x, y + m->tile_map[0]->height); |
1283 | return out_of_map (m->tile_map[0], x, y + m->tile_map[0]->height); |
1325 | } |
1284 | } |
1326 | |
1285 | |
1327 | if (y >= m->height) |
1286 | if (y >= m->height) |
1328 | { |
1287 | { |
1329 | if (!m->tile_path[2]) |
1288 | if (!m->tile_available (2, 0)) |
1330 | return 1; |
1289 | return 1; |
1331 | |
|
|
1332 | if (!m->tile_map[2] || m->tile_map[2]->in_memory != MAP_IN_MEMORY) |
|
|
1333 | find_and_link (m, 2); |
|
|
1334 | |
1290 | |
1335 | return out_of_map (m->tile_map[2], x, y - m->height); |
1291 | return out_of_map (m->tile_map[2], x, y - m->height); |
1336 | } |
1292 | } |
1337 | |
1293 | |
1338 | /* Simple case - coordinates are within this local |
1294 | /* Simple case - coordinates are within this local |
… | |
… | |
1352 | maptile * |
1308 | maptile * |
1353 | maptile::xy_find (sint16 &x, sint16 &y) |
1309 | maptile::xy_find (sint16 &x, sint16 &y) |
1354 | { |
1310 | { |
1355 | if (x < 0) |
1311 | if (x < 0) |
1356 | { |
1312 | { |
1357 | if (!tile_path[3]) |
1313 | if (!tile_available (3, 1)) |
1358 | return 0; |
1314 | return 0; |
1359 | |
1315 | |
1360 | find_and_link (this, 3); |
|
|
1361 | x += tile_map[3]->width; |
1316 | x += tile_map[3]->width; |
1362 | return tile_map[3]->xy_find (x, y); |
1317 | return tile_map[3]->xy_find (x, y); |
1363 | } |
1318 | } |
1364 | |
1319 | |
1365 | if (x >= width) |
1320 | if (x >= width) |
1366 | { |
1321 | { |
1367 | if (!tile_path[1]) |
1322 | if (!tile_available (1, 1)) |
1368 | return 0; |
1323 | return 0; |
1369 | |
1324 | |
1370 | find_and_link (this, 1); |
|
|
1371 | x -= width; |
1325 | x -= width; |
1372 | return tile_map[1]->xy_find (x, y); |
1326 | return tile_map[1]->xy_find (x, y); |
1373 | } |
1327 | } |
1374 | |
1328 | |
1375 | if (y < 0) |
1329 | if (y < 0) |
1376 | { |
1330 | { |
1377 | if (!tile_path[0]) |
1331 | if (!tile_available (0, 1)) |
1378 | return 0; |
1332 | return 0; |
1379 | |
1333 | |
1380 | find_and_link (this, 0); |
|
|
1381 | y += tile_map[0]->height; |
1334 | y += tile_map[0]->height; |
1382 | return tile_map[0]->xy_find (x, y); |
1335 | return tile_map[0]->xy_find (x, y); |
1383 | } |
1336 | } |
1384 | |
1337 | |
1385 | if (y >= height) |
1338 | if (y >= height) |
1386 | { |
1339 | { |
1387 | if (!tile_path[2]) |
1340 | if (!tile_available (2, 1)) |
1388 | return 0; |
1341 | return 0; |
1389 | |
1342 | |
1390 | find_and_link (this, 2); |
|
|
1391 | y -= height; |
1343 | y -= height; |
1392 | return tile_map[2]->xy_find (x, y); |
1344 | return tile_map[2]->xy_find (x, y); |
1393 | } |
1345 | } |
1394 | |
1346 | |
1395 | /* Simple case - coordinates are within this local |
1347 | /* Simple case - coordinates are within this local |
… | |
… | |
1670 | |
1622 | |
1671 | // instead of crashing in the unlikely(?) case, try to return *something* |
1623 | // instead of crashing in the unlikely(?) case, try to return *something* |
1672 | return get_archetype ("blocked"); |
1624 | return get_archetype ("blocked"); |
1673 | } |
1625 | } |
1674 | |
1626 | |
1675 | /** |
|
|
1676 | * Maximum distance a player may hear a sound from. |
|
|
1677 | * This is only used for new client/server sound. If the sound source |
|
|
1678 | * on the map is farther away than this, we don't sent it to the client. |
|
|
1679 | */ |
|
|
1680 | #define MAX_SOUND_DISTANCE 10 |
|
|
1681 | |
|
|
1682 | void |
1627 | void |
1683 | maptile::play_sound (faceidx sound, int x, int y) const |
1628 | maptile::play_sound (faceidx sound, int x, int y) const |
1684 | { |
1629 | { |
1685 | if (!sound) |
1630 | if (!sound) |
1686 | return; |
1631 | return; |