… | |
… | |
32 | #include <bitset> |
32 | #include <bitset> |
33 | |
33 | |
34 | UUID UUID::cur; |
34 | UUID UUID::cur; |
35 | static uint64_t seq_next_save; |
35 | static uint64_t seq_next_save; |
36 | static const uint64 UUID_GAP = 1<<19; |
36 | static const uint64 UUID_GAP = 1<<19; |
|
|
37 | uint32_t mapspace::smellcount = 10000; |
37 | |
38 | |
38 | objectvec objects; |
39 | objectvec objects; |
39 | activevec actives; |
40 | activevec actives; |
40 | |
41 | |
41 | short freearr_x[SIZEOFFREE] = { |
42 | short freearr_x[SIZEOFFREE] = { |
… | |
… | |
1096 | |
1097 | |
1097 | if (object *pl = ms.player ()) |
1098 | if (object *pl = ms.player ()) |
1098 | { |
1099 | { |
1099 | if (is_player ()) |
1100 | if (is_player ()) |
1100 | { |
1101 | { |
|
|
1102 | if (!flag [FLAG_WIZPASS]) |
1101 | ms.smell = pticks; // remember the smell of the player |
1103 | ms.smell = ++mapspace::smellcount; // remember the smell of the player |
1102 | |
1104 | |
1103 | // leaving a spot always closes any open container on the ground |
1105 | // leaving a spot always closes any open container on the ground |
1104 | if (container && !container->env) |
1106 | if (container && !container->env) |
1105 | // this causes spurious floorbox updates, but it ensures |
1107 | // this causes spurious floorbox updates, but it ensures |
1106 | // that the CLOSE event is being sent. |
1108 | // that the CLOSE event is being sent. |
… | |
… | |
1284 | |
1286 | |
1285 | /* Ideally, the caller figures this out. However, it complicates a lot |
1287 | /* Ideally, the caller figures this out. However, it complicates a lot |
1286 | * of areas of callers (eg, anything that uses find_free_spot would now |
1288 | * of areas of callers (eg, anything that uses find_free_spot would now |
1287 | * need extra work |
1289 | * need extra work |
1288 | */ |
1290 | */ |
|
|
1291 | maptile *newmap = m; |
1289 | if (!xy_normalise (m, op->x, op->y)) |
1292 | if (!xy_normalise (newmap, op->x, op->y)) |
1290 | { |
1293 | { |
1291 | op->head_ ()->destroy ();// remove head_ once all tail object destroyers found |
1294 | op->head_ ()->destroy ();// remove head_ once all tail object destroyers found |
1292 | return 0; |
1295 | return 0; |
1293 | } |
1296 | } |
1294 | |
1297 | |
… | |
… | |
1296 | if (!insert_ob_in_map (more, m, originator, flag)) |
1299 | if (!insert_ob_in_map (more, m, originator, flag)) |
1297 | return 0; |
1300 | return 0; |
1298 | |
1301 | |
1299 | CLEAR_FLAG (op, FLAG_REMOVED); |
1302 | CLEAR_FLAG (op, FLAG_REMOVED); |
1300 | |
1303 | |
1301 | op->map = m; |
1304 | op->map = newmap; |
1302 | mapspace &ms = op->ms (); |
1305 | mapspace &ms = op->ms (); |
1303 | |
1306 | |
1304 | /* this has to be done after we translate the coordinates. |
1307 | /* this has to be done after we translate the coordinates. |
1305 | */ |
1308 | */ |
1306 | if (op->nrof && !(flag & INS_NO_MERGE)) |
1309 | if (op->nrof && !(flag & INS_NO_MERGE)) |
… | |
… | |
1491 | /* this function inserts an object in the map, but if it |
1494 | /* this function inserts an object in the map, but if it |
1492 | * finds an object of its own type, it'll remove that one first. |
1495 | * finds an object of its own type, it'll remove that one first. |
1493 | * op is the object to insert it under: supplies x and the map. |
1496 | * op is the object to insert it under: supplies x and the map. |
1494 | */ |
1497 | */ |
1495 | void |
1498 | void |
1496 | replace_insert_ob_in_map (const char *arch_string, object *op) |
1499 | replace_insert_ob_in_map (shstr_tmp archname, object *op) |
1497 | { |
1500 | { |
1498 | /* first search for itself and remove any old instances */ |
1501 | /* first search for itself and remove any old instances */ |
1499 | |
1502 | |
1500 | for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above) |
1503 | for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above) |
1501 | if (!strcmp (tmp->arch->archname, arch_string)) /* same archetype */ |
1504 | if (tmp->arch->archname == archname) /* same archetype */ |
1502 | tmp->destroy (); |
1505 | tmp->destroy (); |
1503 | |
1506 | |
1504 | object *tmp = arch_to_object (archetype::find (arch_string)); |
1507 | object *tmp = arch_to_object (archetype::find (archname)); |
1505 | |
1508 | |
1506 | tmp->x = op->x; |
1509 | tmp->x = op->x; |
1507 | tmp->y = op->y; |
1510 | tmp->y = op->y; |
1508 | |
1511 | |
1509 | insert_ob_in_map (tmp, op->map, op, 0); |
1512 | insert_ob_in_map (tmp, op->map, op, 0); |
… | |
… | |
2054 | * there is capable of. |
2057 | * there is capable of. |
2055 | */ |
2058 | */ |
2056 | int |
2059 | int |
2057 | find_dir (maptile *m, int x, int y, object *exclude) |
2060 | find_dir (maptile *m, int x, int y, object *exclude) |
2058 | { |
2061 | { |
2059 | int i, max = SIZEOFFREE, mflags; |
2062 | int max = SIZEOFFREE, mflags; |
2060 | |
|
|
2061 | sint16 nx, ny; |
|
|
2062 | object *tmp; |
|
|
2063 | maptile *mp; |
|
|
2064 | |
|
|
2065 | MoveType blocked, move_type; |
2063 | MoveType move_type; |
2066 | |
2064 | |
2067 | if (exclude && exclude->head_ () != exclude) |
2065 | if (exclude && exclude->head_ () != exclude) |
2068 | { |
2066 | { |
2069 | exclude = exclude->head; |
2067 | exclude = exclude->head; |
2070 | move_type = exclude->move_type; |
2068 | move_type = exclude->move_type; |
… | |
… | |
2073 | { |
2071 | { |
2074 | /* If we don't have anything, presume it can use all movement types. */ |
2072 | /* If we don't have anything, presume it can use all movement types. */ |
2075 | move_type = MOVE_ALL; |
2073 | move_type = MOVE_ALL; |
2076 | } |
2074 | } |
2077 | |
2075 | |
2078 | for (i = 1; i < max; i++) |
2076 | for (int i = 1; i < max; i++) |
2079 | { |
2077 | { |
2080 | mp = m; |
2078 | mapxy pos (m, x, y); |
2081 | nx = x + freearr_x[i]; |
2079 | pos.move (i); |
2082 | ny = y + freearr_y[i]; |
|
|
2083 | |
2080 | |
2084 | mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); |
2081 | if (!pos.normalise ()) |
2085 | |
|
|
2086 | if (mflags & P_OUT_OF_MAP) |
|
|
2087 | max = maxfree[i]; |
2082 | max = maxfree[i]; |
2088 | else |
2083 | else |
2089 | { |
2084 | { |
2090 | mapspace &ms = mp->at (nx, ny); |
2085 | mapspace &ms = *pos; |
2091 | |
2086 | |
2092 | blocked = ms.move_block; |
|
|
2093 | |
|
|
2094 | if ((move_type & blocked) == move_type) |
2087 | if ((move_type & ms.move_block) == move_type) |
2095 | max = maxfree[i]; |
2088 | max = maxfree [i]; |
2096 | else if (mflags & P_IS_ALIVE) |
2089 | else if (ms.flags () & P_IS_ALIVE) |
2097 | { |
2090 | { |
2098 | for (tmp = ms.bot; tmp; tmp = tmp->above) |
2091 | for (object *tmp = ms.bot; tmp; tmp = tmp->above) |
2099 | if ((tmp->flag [FLAG_MONSTER] || tmp->is_player ()) |
2092 | if ((tmp->flag [FLAG_MONSTER] || tmp->is_player ()) |
2100 | && (tmp != exclude || (tmp->head_ () != tmp && tmp->head_ () != exclude))) |
2093 | && (tmp != exclude || (tmp->head_ () != tmp && tmp->head_ () != exclude))) |
2101 | break; |
|
|
2102 | |
|
|
2103 | if (tmp) |
|
|
2104 | return freedir[i]; |
2094 | return freedir [i]; |
2105 | } |
2095 | } |
2106 | } |
2096 | } |
2107 | } |
2097 | } |
2108 | |
2098 | |
2109 | return 0; |
2099 | return 0; |
… | |
… | |
2332 | return tmp; |
2322 | return tmp; |
2333 | |
2323 | |
2334 | return 0; |
2324 | return 0; |
2335 | } |
2325 | } |
2336 | |
2326 | |
2337 | const shstr & |
2327 | shstr_tmp |
2338 | object::kv_get (const shstr &key) const |
2328 | object::kv_get (shstr_tmp key) const |
2339 | { |
2329 | { |
2340 | for (key_value *kv = key_values; kv; kv = kv->next) |
2330 | for (key_value *kv = key_values; kv; kv = kv->next) |
2341 | if (kv->key == key) |
2331 | if (kv->key == key) |
2342 | return kv->value; |
2332 | return kv->value; |
2343 | |
2333 | |
2344 | return shstr_null; |
2334 | return shstr (); |
2345 | } |
2335 | } |
2346 | |
2336 | |
2347 | void |
2337 | void |
2348 | object::kv_set (const shstr &key, const shstr &value) |
2338 | object::kv_set (shstr_tmp key, shstr_tmp value) |
2349 | { |
2339 | { |
2350 | for (key_value *kv = key_values; kv; kv = kv->next) |
2340 | for (key_value *kv = key_values; kv; kv = kv->next) |
2351 | if (kv->key == key) |
2341 | if (kv->key == key) |
2352 | { |
2342 | { |
2353 | kv->value = value; |
2343 | kv->value = value; |
… | |
… | |
2362 | |
2352 | |
2363 | key_values = kv; |
2353 | key_values = kv; |
2364 | } |
2354 | } |
2365 | |
2355 | |
2366 | void |
2356 | void |
2367 | object::kv_del (const shstr &key) |
2357 | object::kv_del (shstr_tmp key) |
2368 | { |
2358 | { |
2369 | for (key_value **kvp = &key_values; *kvp; kvp = &(*kvp)->next) |
2359 | for (key_value **kvp = &key_values; *kvp; kvp = &(*kvp)->next) |
2370 | if ((*kvp)->key == key) |
2360 | if ((*kvp)->key == key) |
2371 | { |
2361 | { |
2372 | key_value *kv = *kvp; |
2362 | key_value *kv = *kvp; |
… | |
… | |
2541 | // else if (!old_container->env && contr && contr->ns) |
2531 | // else if (!old_container->env && contr && contr->ns) |
2542 | // contr->ns->floorbox_reset (); |
2532 | // contr->ns->floorbox_reset (); |
2543 | } |
2533 | } |
2544 | |
2534 | |
2545 | object * |
2535 | object * |
2546 | object::force_find (const shstr name) |
2536 | object::force_find (shstr_tmp name) |
2547 | { |
2537 | { |
2548 | /* cycle through his inventory to look for the MARK we want to |
2538 | /* cycle through his inventory to look for the MARK we want to |
2549 | * place |
2539 | * place |
2550 | */ |
2540 | */ |
2551 | for (object *tmp = inv; tmp; tmp = tmp->below) |
2541 | for (object *tmp = inv; tmp; tmp = tmp->below) |
… | |
… | |
2554 | |
2544 | |
2555 | return 0; |
2545 | return 0; |
2556 | } |
2546 | } |
2557 | |
2547 | |
2558 | object * |
2548 | object * |
2559 | object::force_add (const shstr name, int duration) |
2549 | object::force_add (shstr_tmp name, int duration) |
2560 | { |
2550 | { |
2561 | if (object *force = force_find (name)) |
2551 | if (object *force = force_find (name)) |
2562 | force->destroy (); |
2552 | force->destroy (); |
2563 | |
2553 | |
2564 | object *force = get_archetype (FORCE_NAME); |
2554 | object *force = get_archetype (FORCE_NAME); |