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.281 by root, Sun Jan 11 06:08:40 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] = {
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
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 */
1495void 1498void
1496replace_insert_ob_in_map (const char *arch_string, object *op) 1499replace_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 */
2056int 2059int
2057find_dir (maptile *m, int x, int y, object *exclude) 2060find_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;
2184 * This basically means that if direction is 15, then it could either go 2174 * 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. 2175 * 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 2176 * Moved from spell_util.c to object.c with the other related direction
2187 * functions. 2177 * functions.
2188 */ 2178 */
2189int reduction_dir[SIZEOFFREE][3] = { 2179const int reduction_dir[SIZEOFFREE][3] = {
2190 {0, 0, 0}, /* 0 */ 2180 {0, 0, 0}, /* 0 */
2191 {0, 0, 0}, /* 1 */ 2181 {0, 0, 0}, /* 1 */
2192 {0, 0, 0}, /* 2 */ 2182 {0, 0, 0}, /* 2 */
2193 {0, 0, 0}, /* 3 */ 2183 {0, 0, 0}, /* 3 */
2194 {0, 0, 0}, /* 4 */ 2184 {0, 0, 0}, /* 4 */
2332 return tmp; 2322 return tmp;
2333 2323
2334 return 0; 2324 return 0;
2335} 2325}
2336 2326
2337const shstr & 2327shstr_tmp
2338object::kv_get (const shstr &key) const 2328object::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
2347void 2337void
2348object::kv_set (const shstr &key, const shstr &value) 2338object::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
2366void 2356void
2367object::kv_del (const shstr &key) 2357object::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;
2503 container = 0; 2493 container = 0;
2504 2494
2505 // client needs item update to make it work, client bug requires this to be separate 2495 // client needs item update to make it work, client bug requires this to be separate
2506 esrv_update_item (UPD_FLAGS, this, old_container); 2496 esrv_update_item (UPD_FLAGS, this, old_container);
2507 2497
2508 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", query_name (old_container)); 2498 new_draw_info_format (NDI_UNIQUE, 0, this, "You close %s.", old_container->query_name ());
2509 play_sound (sound_find ("chest_close")); 2499 play_sound (sound_find ("chest_close"));
2510 } 2500 }
2511 2501
2512 if (new_container) 2502 if (new_container)
2513 { 2503 {
2523 closer->flag [FLAG_NO_MAP_SAVE] = 1; 2513 closer->flag [FLAG_NO_MAP_SAVE] = 1;
2524 new_container->insert (closer); 2514 new_container->insert (closer);
2525 } 2515 }
2526#endif 2516#endif
2527 2517
2528 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", query_name (new_container)); 2518 new_draw_info_format (NDI_UNIQUE, 0, this, "You open %s.", new_container->query_name ());
2529 2519
2530 // make sure the container is available, client bug requires this to be separate 2520 // make sure the container is available, client bug requires this to be separate
2531 esrv_send_item (this, new_container); 2521 esrv_send_item (this, new_container);
2532 2522
2533 new_container->flag [FLAG_APPLIED] = true; 2523 new_container->flag [FLAG_APPLIED] = true;
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
2545object * 2535object *
2546object::force_find (const shstr name) 2536object::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
2558object * 2548object *
2559object::force_add (const shstr name, int duration) 2549object::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);
2573 2563
2574 return insert (force); 2564 return insert (force);
2575} 2565}
2576 2566
2577void 2567void
2578object::play_sound (faceidx sound) 2568object::play_sound (faceidx sound) const
2579{ 2569{
2580 if (!sound) 2570 if (!sound)
2581 return; 2571 return;
2582 2572
2583 if (flag [FLAG_REMOVED]) 2573 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); 2574 map->play_sound (sound, x, y);
2575 else if (object *pl = in_player ())
2576 pl->contr->play_sound (sound);
2577}
2578
2579void
2580object::say_msg (const char *msg) const
2581{
2582 if (is_on_map ())
2583 map->say_msg (msg, x, y);
2584 else if (object *pl = in_player ())
2585 pl->contr->play_sound (sound);
2593} 2586}
2594 2587
2595void 2588void
2596object::make_noise () 2589object::make_noise ()
2597{ 2590{

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines