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

Comparing deliantra/server/common/object.C (file contents):
Revision 1.270 by root, Sat Dec 27 02:31:19 2008 UTC vs.
Revision 1.286 by root, Wed Sep 2 16:54:20 2009 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 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
32#include <bitset> 32#include <bitset>
33 33
34UUID UUID::cur; 34UUID UUID::cur;
35static uint64_t seq_next_save; 35static uint64_t seq_next_save;
36static const uint64 UUID_GAP = 1<<19; 36static const uint64 UUID_GAP = 1<<19;
37uint32_t mapspace::smellcount = 10000;
37 38
38objectvec objects; 39objectvec objects;
39activevec actives; 40activevec actives;
40 41
41short freearr_x[SIZEOFFREE] = { 42short freearr_x[SIZEOFFREE] = {
327 // the player inventory itself is always visible 328 // the player inventory itself is always visible
328 if (env->is_player ()) 329 if (env->is_player ())
329 return env; 330 return env;
330 331
331 // else a player could have our env open 332 // else a player could have our env open
332 object *envest = env->outer_env (); 333 object *envest = env->outer_env_or_self ();
333 334
334 // the player itself is always on a map, so we will find him here 335 // the player itself is always on a map, so we will find him here
335 // even if our inv is in a player. 336 // even if our inv is in a player.
336 if (envest->is_on_map ()) 337 if (envest->is_on_map ())
337 if (object *pl = envest->ms ().player ()) 338 if (object *pl = envest->ms ().player ())
791 792
792object::object () 793object::object ()
793{ 794{
794 SET_FLAG (this, FLAG_REMOVED); 795 SET_FLAG (this, FLAG_REMOVED);
795 796
796 expmul = 1.0; 797 //expmul = 1.0; declared const for the time being
797 face = blank_face; 798 face = blank_face;
798} 799}
799 800
800object::~object () 801object::~object ()
801{ 802{
830{ 831{
831 /* If already on active list, don't do anything */ 832 /* If already on active list, don't do anything */
832 if (active) 833 if (active)
833 return; 834 return;
834 835
835 if (has_active_speed () && flag [FLAG_FREED]) LOG (llevError | logBacktrace, "BUG: tried to activate freed object %s\n", debug_desc ());//D
836 if (has_active_speed () && flag [FLAG_DEBUG]) LOG (llevError | logBacktrace, "BUG: tried to activate DEBUG object %s\n", debug_desc ());//D temp
837
838 if (has_active_speed ()) 836 if (has_active_speed ())
837 {
838 if (flag [FLAG_FREED])
839 LOG (llevError | logBacktrace, "BUG: tried to activate freed object %s\n", debug_desc ());//D
840
839 actives.insert (this); 841 actives.insert (this);
842 }
840} 843}
841 844
842void 845void
843object::activate_recursive () 846object::activate_recursive ()
844{ 847{
962 965
963void 966void
964object::do_destroy () 967object::do_destroy ()
965{ 968{
966 if (flag [FLAG_IS_LINKED]) 969 if (flag [FLAG_IS_LINKED])
967 remove_button_link (this); 970 remove_link ();
968 971
969 if (flag [FLAG_FRIENDLY]) 972 if (flag [FLAG_FRIENDLY])
970 remove_friendly_object (this); 973 remove_friendly_object (this);
971 974
972 remove (); 975 remove ();
1096 1099
1097 if (object *pl = ms.player ()) 1100 if (object *pl = ms.player ())
1098 { 1101 {
1099 if (is_player ()) 1102 if (is_player ())
1100 { 1103 {
1104 if (!flag [FLAG_WIZPASS])
1101 ms.smell = pticks; // remember the smell of the player 1105 ms.smell = ++mapspace::smellcount; // remember the smell of the player
1102 1106
1103 // leaving a spot always closes any open container on the ground 1107 // leaving a spot always closes any open container on the ground
1104 if (container && !container->env) 1108 if (container && !container->env)
1105 // this causes spurious floorbox updates, but it ensures 1109 // this causes spurious floorbox updates, but it ensures
1106 // that the CLOSE event is being sent. 1110 // that the CLOSE event is being sent.
1284 1288
1285 /* Ideally, the caller figures this out. However, it complicates a lot 1289 /* 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 1290 * of areas of callers (eg, anything that uses find_free_spot would now
1287 * need extra work 1291 * need extra work
1288 */ 1292 */
1293 maptile *newmap = m;
1289 if (!xy_normalise (m, op->x, op->y)) 1294 if (!xy_normalise (newmap, op->x, op->y))
1290 { 1295 {
1291 op->head_ ()->destroy ();// remove head_ once all tail object destroyers found 1296 op->head_ ()->destroy ();// remove head_ once all tail object destroyers found
1292 return 0; 1297 return 0;
1293 } 1298 }
1294 1299
1295 if (object *more = op->more) 1300 if (object *more = op->more)
1296 if (!insert_ob_in_map (more, m, originator, flag)) 1301 if (!insert_ob_in_map (more, m, originator, flag))
1297 return 0; 1302 return 0;
1298 1303
1299 CLEAR_FLAG (op, FLAG_REMOVED); 1304 op->flag [FLAG_REMOVED] = false;
1300 1305 op->env = 0;
1301 op->map = m; 1306 op->map = newmap;
1307
1302 mapspace &ms = op->ms (); 1308 mapspace &ms = op->ms ();
1303 1309
1304 /* this has to be done after we translate the coordinates. 1310 /* this has to be done after we translate the coordinates.
1305 */ 1311 */
1306 if (op->nrof && !(flag & INS_NO_MERGE)) 1312 if (op->nrof && !(flag & INS_NO_MERGE))
1327 LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n"); 1333 LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n");
1328 abort (); 1334 abort ();
1329 } 1335 }
1330 1336
1331 if (!originator->is_on_map ()) 1337 if (!originator->is_on_map ())
1338 {
1332 LOG (llevDebug | logBacktrace, "insert_ob_in_map(%s) called with INS_BELOW_ORIGINATOR when originator '%s' not on map", 1339 LOG (llevError, "insert_ob_in_map(%s) called with INS_BELOW_ORIGINATOR when originator '%s' not on map",
1333 op->debug_desc (), originator->debug_desc ()); 1340 op->debug_desc (), originator->debug_desc ());
1341 abort ();
1342 }
1334 1343
1335 op->above = originator; 1344 op->above = originator;
1336 op->below = originator->below; 1345 op->below = originator->below;
1337 originator->below = op; 1346 originator->below = op;
1338 1347
1491/* this function inserts an object in the map, but if it 1500/* 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. 1501 * 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. 1502 * op is the object to insert it under: supplies x and the map.
1494 */ 1503 */
1495void 1504void
1496replace_insert_ob_in_map (const char *arch_string, object *op) 1505replace_insert_ob_in_map (shstr_tmp archname, object *op)
1497{ 1506{
1498 /* first search for itself and remove any old instances */ 1507 /* first search for itself and remove any old instances */
1499 1508
1500 for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above) 1509 for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above)
1501 if (!strcmp (tmp->arch->archname, arch_string)) /* same archetype */ 1510 if (tmp->arch->archname == archname) /* same archetype */
1502 tmp->destroy (); 1511 tmp->destroy ();
1503 1512
1504 object *tmp = arch_to_object (archetype::find (arch_string)); 1513 object *tmp = arch_to_object (archetype::find (archname));
1505 1514
1506 tmp->x = op->x; 1515 tmp->x = op->x;
1507 tmp->y = op->y; 1516 tmp->y = op->y;
1508 1517
1509 insert_ob_in_map (tmp, op->map, op, 0); 1518 insert_ob_in_map (tmp, op->map, op, 0);
2054 * there is capable of. 2063 * there is capable of.
2055 */ 2064 */
2056int 2065int
2057find_dir (maptile *m, int x, int y, object *exclude) 2066find_dir (maptile *m, int x, int y, object *exclude)
2058{ 2067{
2059 int i, max = SIZEOFFREE, mflags; 2068 int max = SIZEOFFREE, mflags;
2060
2061 sint16 nx, ny;
2062 object *tmp;
2063 maptile *mp;
2064
2065 MoveType blocked, move_type; 2069 MoveType move_type;
2066 2070
2067 if (exclude && exclude->head_ () != exclude) 2071 if (exclude && exclude->head_ () != exclude)
2068 { 2072 {
2069 exclude = exclude->head; 2073 exclude = exclude->head;
2070 move_type = exclude->move_type; 2074 move_type = exclude->move_type;
2073 { 2077 {
2074 /* If we don't have anything, presume it can use all movement types. */ 2078 /* If we don't have anything, presume it can use all movement types. */
2075 move_type = MOVE_ALL; 2079 move_type = MOVE_ALL;
2076 } 2080 }
2077 2081
2078 for (i = 1; i < max; i++) 2082 for (int i = 1; i < max; i++)
2079 { 2083 {
2080 mp = m; 2084 mapxy pos (m, x, y);
2081 nx = x + freearr_x[i]; 2085 pos.move (i);
2082 ny = y + freearr_y[i];
2083 2086
2084 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); 2087 if (!pos.normalise ())
2085
2086 if (mflags & P_OUT_OF_MAP)
2087 max = maxfree[i]; 2088 max = maxfree[i];
2088 else 2089 else
2089 { 2090 {
2090 mapspace &ms = mp->at (nx, ny); 2091 mapspace &ms = *pos;
2091 2092
2092 blocked = ms.move_block;
2093
2094 if ((move_type & blocked) == move_type) 2093 if ((move_type & ms.move_block) == move_type)
2095 max = maxfree[i]; 2094 max = maxfree [i];
2096 else if (mflags & P_IS_ALIVE) 2095 else if (ms.flags () & P_IS_ALIVE)
2097 { 2096 {
2098 for (tmp = ms.bot; tmp; tmp = tmp->above) 2097 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
2099 if ((tmp->flag [FLAG_MONSTER] || tmp->is_player ()) 2098 if ((tmp->flag [FLAG_MONSTER] || tmp->is_player ())
2100 && (tmp != exclude || (tmp->head_ () != tmp && tmp->head_ () != exclude))) 2099 && (tmp != exclude || (tmp->head_ () != tmp && tmp->head_ () != exclude)))
2101 break;
2102
2103 if (tmp)
2104 return freedir[i]; 2100 return freedir [i];
2105 } 2101 }
2106 } 2102 }
2107 } 2103 }
2108 2104
2109 return 0; 2105 return 0;
2184 * This basically means that if direction is 15, then it could either go 2180 * This basically means that if direction is 15, then it could either go
2185 * direction 4, 14, or 16 to get back to where we are. 2181 * direction 4, 14, or 16 to get back to where we are.
2186 * Moved from spell_util.c to object.c with the other related direction 2182 * Moved from spell_util.c to object.c with the other related direction
2187 * functions. 2183 * functions.
2188 */ 2184 */
2189int reduction_dir[SIZEOFFREE][3] = { 2185const int reduction_dir[SIZEOFFREE][3] = {
2190 {0, 0, 0}, /* 0 */ 2186 {0, 0, 0}, /* 0 */
2191 {0, 0, 0}, /* 1 */ 2187 {0, 0, 0}, /* 1 */
2192 {0, 0, 0}, /* 2 */ 2188 {0, 0, 0}, /* 2 */
2193 {0, 0, 0}, /* 3 */ 2189 {0, 0, 0}, /* 3 */
2194 {0, 0, 0}, /* 4 */ 2190 {0, 0, 0}, /* 4 */
2332 return tmp; 2328 return tmp;
2333 2329
2334 return 0; 2330 return 0;
2335} 2331}
2336 2332
2337const shstr & 2333shstr_tmp
2338object::kv_get (const shstr &key) const 2334object::kv_get (shstr_tmp key) const
2339{ 2335{
2340 for (key_value *kv = key_values; kv; kv = kv->next) 2336 for (key_value *kv = key_values; kv; kv = kv->next)
2341 if (kv->key == key) 2337 if (kv->key == key)
2342 return kv->value; 2338 return kv->value;
2343 2339
2344 return shstr_null; 2340 return shstr ();
2345} 2341}
2346 2342
2347void 2343void
2348object::kv_set (const shstr &key, const shstr &value) 2344object::kv_set (shstr_tmp key, shstr_tmp value)
2349{ 2345{
2350 for (key_value *kv = key_values; kv; kv = kv->next) 2346 for (key_value *kv = key_values; kv; kv = kv->next)
2351 if (kv->key == key) 2347 if (kv->key == key)
2352 { 2348 {
2353 kv->value = value; 2349 kv->value = value;
2362 2358
2363 key_values = kv; 2359 key_values = kv;
2364} 2360}
2365 2361
2366void 2362void
2367object::kv_del (const shstr &key) 2363object::kv_del (shstr_tmp key)
2368{ 2364{
2369 for (key_value **kvp = &key_values; *kvp; kvp = &(*kvp)->next) 2365 for (key_value **kvp = &key_values; *kvp; kvp = &(*kvp)->next)
2370 if ((*kvp)->key == key) 2366 if ((*kvp)->key == key)
2371 { 2367 {
2372 key_value *kv = *kvp; 2368 key_value *kv = *kvp;
2503 container = 0; 2499 container = 0;
2504 2500
2505 // client needs item update to make it work, client bug requires this to be separate 2501 // client needs item update to make it work, client bug requires this to be separate
2506 esrv_update_item (UPD_FLAGS, this, old_container); 2502 esrv_update_item (UPD_FLAGS, this, old_container);
2507 2503
2508 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); 2504 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", old_container->query_name ());
2509 play_sound (sound_find ("chest_close")); 2505 play_sound (sound_find ("chest_close"));
2510 } 2506 }
2511 2507
2512 if (new_container) 2508 if (new_container)
2513 { 2509 {
2523 closer->flag [FLAG_NO_MAP_SAVE] = 1; 2519 closer->flag [FLAG_NO_MAP_SAVE] = 1;
2524 new_container->insert (closer); 2520 new_container->insert (closer);
2525 } 2521 }
2526#endif 2522#endif
2527 2523
2528 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); 2524 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", new_container->query_name ());
2529 2525
2530 // make sure the container is available, client bug requires this to be separate 2526 // make sure the container is available, client bug requires this to be separate
2531 esrv_send_item (this, new_container); 2527 esrv_send_item (this, new_container);
2532 2528
2533 new_container->flag [FLAG_APPLIED] = true; 2529 new_container->flag [FLAG_APPLIED] = true;
2541// else if (!old_container->env && contr && contr->ns) 2537// else if (!old_container->env && contr && contr->ns)
2542// contr->ns->floorbox_reset (); 2538// contr->ns->floorbox_reset ();
2543} 2539}
2544 2540
2545object * 2541object *
2546object::force_find (const shstr name) 2542object::force_find (shstr_tmp name)
2547{ 2543{
2548 /* cycle through his inventory to look for the MARK we want to 2544 /* cycle through his inventory to look for the MARK we want to
2549 * place 2545 * place
2550 */ 2546 */
2551 for (object *tmp = inv; tmp; tmp = tmp->below) 2547 for (object *tmp = inv; tmp; tmp = tmp->below)
2554 2550
2555 return 0; 2551 return 0;
2556} 2552}
2557 2553
2558object * 2554object *
2559object::force_add (const shstr name, int duration) 2555object::force_add (shstr_tmp name, int duration)
2560{ 2556{
2561 if (object *force = force_find (name)) 2557 if (object *force = force_find (name))
2562 force->destroy (); 2558 force->destroy ();
2563 2559
2564 object *force = get_archetype (FORCE_NAME); 2560 object *force = get_archetype (FORCE_NAME);
2573 2569
2574 return insert (force); 2570 return insert (force);
2575} 2571}
2576 2572
2577void 2573void
2578object::play_sound (faceidx sound) 2574object::play_sound (faceidx sound) const
2579{ 2575{
2580 if (!sound) 2576 if (!sound)
2581 return; 2577 return;
2582 2578
2583 if (flag [FLAG_REMOVED]) 2579 if (is_on_map ())
2584 return;
2585
2586 if (env)
2587 {
2588 if (object *pl = in_player ())
2589 pl->contr->play_sound (sound);
2590 }
2591 else
2592 map->play_sound (sound, x, y); 2580 map->play_sound (sound, x, y);
2581 else if (object *pl = in_player ())
2582 pl->contr->play_sound (sound);
2583}
2584
2585void
2586object::say_msg (const char *msg) const
2587{
2588 if (is_on_map ())
2589 map->say_msg (msg, x, y);
2590 else if (object *pl = in_player ())
2591 pl->contr->play_sound (sound);
2593} 2592}
2594 2593
2595void 2594void
2596object::make_noise () 2595object::make_noise ()
2597{ 2596{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines