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.284 by root, Sat Jun 27 08:35:03 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] = {
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{
962 963
963void 964void
964object::do_destroy () 965object::do_destroy ()
965{ 966{
966 if (flag [FLAG_IS_LINKED]) 967 if (flag [FLAG_IS_LINKED])
967 remove_button_link (this); 968 remove_link ();
968 969
969 if (flag [FLAG_FRIENDLY]) 970 if (flag [FLAG_FRIENDLY])
970 remove_friendly_object (this); 971 remove_friendly_object (this);
971 972
972 remove (); 973 remove ();
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
1295 if (object *more = op->more) 1298 if (object *more = op->more)
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 op->flag [FLAG_REMOVED] = false;
1300 1303 op->env = 0;
1301 op->map = m; 1304 op->map = newmap;
1305
1302 mapspace &ms = op->ms (); 1306 mapspace &ms = op->ms ();
1303 1307
1304 /* this has to be done after we translate the coordinates. 1308 /* this has to be done after we translate the coordinates.
1305 */ 1309 */
1306 if (op->nrof && !(flag & INS_NO_MERGE)) 1310 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"); 1331 LOG (llevError, "insert_ob_in_map called with INS_BELOW_ORIGINATOR when originator not on same space!\n");
1328 abort (); 1332 abort ();
1329 } 1333 }
1330 1334
1331 if (!originator->is_on_map ()) 1335 if (!originator->is_on_map ())
1336 {
1332 LOG (llevDebug | logBacktrace, "insert_ob_in_map(%s) called with INS_BELOW_ORIGINATOR when originator '%s' not on map", 1337 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 ()); 1338 op->debug_desc (), originator->debug_desc ());
1339 abort ();
1340 }
1334 1341
1335 op->above = originator; 1342 op->above = originator;
1336 op->below = originator->below; 1343 op->below = originator->below;
1337 originator->below = op; 1344 originator->below = op;
1338 1345
1491/* this function inserts an object in the map, but if it 1498/* 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. 1499 * 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. 1500 * op is the object to insert it under: supplies x and the map.
1494 */ 1501 */
1495void 1502void
1496replace_insert_ob_in_map (const char *arch_string, object *op) 1503replace_insert_ob_in_map (shstr_tmp archname, object *op)
1497{ 1504{
1498 /* first search for itself and remove any old instances */ 1505 /* first search for itself and remove any old instances */
1499 1506
1500 for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above) 1507 for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above)
1501 if (!strcmp (tmp->arch->archname, arch_string)) /* same archetype */ 1508 if (tmp->arch->archname == archname) /* same archetype */
1502 tmp->destroy (); 1509 tmp->destroy ();
1503 1510
1504 object *tmp = arch_to_object (archetype::find (arch_string)); 1511 object *tmp = arch_to_object (archetype::find (archname));
1505 1512
1506 tmp->x = op->x; 1513 tmp->x = op->x;
1507 tmp->y = op->y; 1514 tmp->y = op->y;
1508 1515
1509 insert_ob_in_map (tmp, op->map, op, 0); 1516 insert_ob_in_map (tmp, op->map, op, 0);
2054 * there is capable of. 2061 * there is capable of.
2055 */ 2062 */
2056int 2063int
2057find_dir (maptile *m, int x, int y, object *exclude) 2064find_dir (maptile *m, int x, int y, object *exclude)
2058{ 2065{
2059 int i, max = SIZEOFFREE, mflags; 2066 int max = SIZEOFFREE, mflags;
2060
2061 sint16 nx, ny;
2062 object *tmp;
2063 maptile *mp;
2064
2065 MoveType blocked, move_type; 2067 MoveType move_type;
2066 2068
2067 if (exclude && exclude->head_ () != exclude) 2069 if (exclude && exclude->head_ () != exclude)
2068 { 2070 {
2069 exclude = exclude->head; 2071 exclude = exclude->head;
2070 move_type = exclude->move_type; 2072 move_type = exclude->move_type;
2073 { 2075 {
2074 /* If we don't have anything, presume it can use all movement types. */ 2076 /* If we don't have anything, presume it can use all movement types. */
2075 move_type = MOVE_ALL; 2077 move_type = MOVE_ALL;
2076 } 2078 }
2077 2079
2078 for (i = 1; i < max; i++) 2080 for (int i = 1; i < max; i++)
2079 { 2081 {
2080 mp = m; 2082 mapxy pos (m, x, y);
2081 nx = x + freearr_x[i]; 2083 pos.move (i);
2082 ny = y + freearr_y[i];
2083 2084
2084 mflags = get_map_flags (m, &mp, nx, ny, &nx, &ny); 2085 if (!pos.normalise ())
2085
2086 if (mflags & P_OUT_OF_MAP)
2087 max = maxfree[i]; 2086 max = maxfree[i];
2088 else 2087 else
2089 { 2088 {
2090 mapspace &ms = mp->at (nx, ny); 2089 mapspace &ms = *pos;
2091 2090
2092 blocked = ms.move_block;
2093
2094 if ((move_type & blocked) == move_type) 2091 if ((move_type & ms.move_block) == move_type)
2095 max = maxfree[i]; 2092 max = maxfree [i];
2096 else if (mflags & P_IS_ALIVE) 2093 else if (ms.flags () & P_IS_ALIVE)
2097 { 2094 {
2098 for (tmp = ms.bot; tmp; tmp = tmp->above) 2095 for (object *tmp = ms.bot; tmp; tmp = tmp->above)
2099 if ((tmp->flag [FLAG_MONSTER] || tmp->is_player ()) 2096 if ((tmp->flag [FLAG_MONSTER] || tmp->is_player ())
2100 && (tmp != exclude || (tmp->head_ () != tmp && tmp->head_ () != exclude))) 2097 && (tmp != exclude || (tmp->head_ () != tmp && tmp->head_ () != exclude)))
2101 break;
2102
2103 if (tmp)
2104 return freedir[i]; 2098 return freedir [i];
2105 } 2099 }
2106 } 2100 }
2107 } 2101 }
2108 2102
2109 return 0; 2103 return 0;
2184 * This basically means that if direction is 15, then it could either go 2178 * 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. 2179 * 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 2180 * Moved from spell_util.c to object.c with the other related direction
2187 * functions. 2181 * functions.
2188 */ 2182 */
2189int reduction_dir[SIZEOFFREE][3] = { 2183const int reduction_dir[SIZEOFFREE][3] = {
2190 {0, 0, 0}, /* 0 */ 2184 {0, 0, 0}, /* 0 */
2191 {0, 0, 0}, /* 1 */ 2185 {0, 0, 0}, /* 1 */
2192 {0, 0, 0}, /* 2 */ 2186 {0, 0, 0}, /* 2 */
2193 {0, 0, 0}, /* 3 */ 2187 {0, 0, 0}, /* 3 */
2194 {0, 0, 0}, /* 4 */ 2188 {0, 0, 0}, /* 4 */
2332 return tmp; 2326 return tmp;
2333 2327
2334 return 0; 2328 return 0;
2335} 2329}
2336 2330
2337const shstr & 2331shstr_tmp
2338object::kv_get (const shstr &key) const 2332object::kv_get (shstr_tmp key) const
2339{ 2333{
2340 for (key_value *kv = key_values; kv; kv = kv->next) 2334 for (key_value *kv = key_values; kv; kv = kv->next)
2341 if (kv->key == key) 2335 if (kv->key == key)
2342 return kv->value; 2336 return kv->value;
2343 2337
2344 return shstr_null; 2338 return shstr ();
2345} 2339}
2346 2340
2347void 2341void
2348object::kv_set (const shstr &key, const shstr &value) 2342object::kv_set (shstr_tmp key, shstr_tmp value)
2349{ 2343{
2350 for (key_value *kv = key_values; kv; kv = kv->next) 2344 for (key_value *kv = key_values; kv; kv = kv->next)
2351 if (kv->key == key) 2345 if (kv->key == key)
2352 { 2346 {
2353 kv->value = value; 2347 kv->value = value;
2362 2356
2363 key_values = kv; 2357 key_values = kv;
2364} 2358}
2365 2359
2366void 2360void
2367object::kv_del (const shstr &key) 2361object::kv_del (shstr_tmp key)
2368{ 2362{
2369 for (key_value **kvp = &key_values; *kvp; kvp = &(*kvp)->next) 2363 for (key_value **kvp = &key_values; *kvp; kvp = &(*kvp)->next)
2370 if ((*kvp)->key == key) 2364 if ((*kvp)->key == key)
2371 { 2365 {
2372 key_value *kv = *kvp; 2366 key_value *kv = *kvp;
2503 container = 0; 2497 container = 0;
2504 2498
2505 // client needs item update to make it work, client bug requires this to be separate 2499 // client needs item update to make it work, client bug requires this to be separate
2506 esrv_update_item (UPD_FLAGS, this, old_container); 2500 esrv_update_item (UPD_FLAGS, this, old_container);
2507 2501
2508 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); 2502 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", old_container->query_name ());
2509 play_sound (sound_find ("chest_close")); 2503 play_sound (sound_find ("chest_close"));
2510 } 2504 }
2511 2505
2512 if (new_container) 2506 if (new_container)
2513 { 2507 {
2523 closer->flag [FLAG_NO_MAP_SAVE] = 1; 2517 closer->flag [FLAG_NO_MAP_SAVE] = 1;
2524 new_container->insert (closer); 2518 new_container->insert (closer);
2525 } 2519 }
2526#endif 2520#endif
2527 2521
2528 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); 2522 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", new_container->query_name ());
2529 2523
2530 // make sure the container is available, client bug requires this to be separate 2524 // make sure the container is available, client bug requires this to be separate
2531 esrv_send_item (this, new_container); 2525 esrv_send_item (this, new_container);
2532 2526
2533 new_container->flag [FLAG_APPLIED] = true; 2527 new_container->flag [FLAG_APPLIED] = true;
2541// else if (!old_container->env && contr && contr->ns) 2535// else if (!old_container->env && contr && contr->ns)
2542// contr->ns->floorbox_reset (); 2536// contr->ns->floorbox_reset ();
2543} 2537}
2544 2538
2545object * 2539object *
2546object::force_find (const shstr name) 2540object::force_find (shstr_tmp name)
2547{ 2541{
2548 /* cycle through his inventory to look for the MARK we want to 2542 /* cycle through his inventory to look for the MARK we want to
2549 * place 2543 * place
2550 */ 2544 */
2551 for (object *tmp = inv; tmp; tmp = tmp->below) 2545 for (object *tmp = inv; tmp; tmp = tmp->below)
2554 2548
2555 return 0; 2549 return 0;
2556} 2550}
2557 2551
2558object * 2552object *
2559object::force_add (const shstr name, int duration) 2553object::force_add (shstr_tmp name, int duration)
2560{ 2554{
2561 if (object *force = force_find (name)) 2555 if (object *force = force_find (name))
2562 force->destroy (); 2556 force->destroy ();
2563 2557
2564 object *force = get_archetype (FORCE_NAME); 2558 object *force = get_archetype (FORCE_NAME);
2573 2567
2574 return insert (force); 2568 return insert (force);
2575} 2569}
2576 2570
2577void 2571void
2578object::play_sound (faceidx sound) 2572object::play_sound (faceidx sound) const
2579{ 2573{
2580 if (!sound) 2574 if (!sound)
2581 return; 2575 return;
2582 2576
2583 if (flag [FLAG_REMOVED]) 2577 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); 2578 map->play_sound (sound, x, y);
2579 else if (object *pl = in_player ())
2580 pl->contr->play_sound (sound);
2581}
2582
2583void
2584object::say_msg (const char *msg) const
2585{
2586 if (is_on_map ())
2587 map->say_msg (msg, x, y);
2588 else if (object *pl = in_player ())
2589 pl->contr->play_sound (sound);
2593} 2590}
2594 2591
2595void 2592void
2596object::make_noise () 2593object::make_noise ()
2597{ 2594{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines