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.303 by root, Tue Nov 10 04:38:45 2009 UTC vs.
Revision 1.311 by root, Sat Jan 16 13:41:37 2010 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,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009,2010 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 it under 8 * Deliantra is free software: you can redistribute it and/or modify it under
9 * the terms of the Affero GNU General Public License as published by the 9 * the terms of the Affero GNU General Public License as published by the
26#include <stdio.h> 26#include <stdio.h>
27#include <sys/types.h> 27#include <sys/types.h>
28#include <sys/uio.h> 28#include <sys/uio.h>
29#include <object.h> 29#include <object.h>
30#include <sproto.h> 30#include <sproto.h>
31#include <loader.h>
32 31
33#include <bitset> 32#include <bitset>
34 33
35UUID UUID::cur; 34UUID UUID::cur;
36static uint64_t seq_next_save; 35static uint64_t seq_next_save;
77 CALL_CALL ("cf::write_uuid", G_DISCARD); 76 CALL_CALL ("cf::write_uuid", G_DISCARD);
78 CALL_END; 77 CALL_END;
79} 78}
80 79
81static void 80static void
82read_uuid (void) 81read_uuid ()
83{ 82{
84 char filename[MAX_BUF]; 83 char filename[MAX_BUF];
85 84
86 sprintf (filename, "%s/uuid", settings.localdir); 85 sprintf (filename, "%s/uuid", settings.localdir);
87 86
248 * Improvements made with merge: Better checking on potion, and also 247 * Improvements made with merge: Better checking on potion, and also
249 * check weight 248 * check weight
250 */ 249 */
251bool object::can_merge_slow (object *ob1, object *ob2) 250bool object::can_merge_slow (object *ob1, object *ob2)
252{ 251{
253 /* A couple quicksanity checks */ 252 /* A couple quick sanity checks */
254 if (ob1 == ob2 253 if (ob1 == ob2
255 || ob1->type != ob2->type 254 || ob1->type != ob2->type
256 || fabs (ob1->speed - ob2->speed) >= MIN_ACTIVE_SPEED
257 || ob1->value != ob2->value 255 || ob1->value != ob2->value
258 || ob1->name != ob2->name) 256 || ob1->name != ob2->name
257 || fabs (ob1->speed - ob2->speed) >= MIN_ACTIVE_SPEED)
259 return 0; 258 return 0;
260 259
261 /* Do not merge objects if nrof would overflow, assume nrof 260 /* Do not merge objects if nrof would overflow, assume nrof
262 * is always 0 .. 2**31-1 */ 261 * is always 0 .. 2**31-1 */
263 if (ob1->nrof > 0x7fffffff - ob2->nrof) 262 if (ob1->nrof > 0x7fffffff - ob2->nrof)
284 || ob1->magic != ob2->magic 283 || ob1->magic != ob2->magic
285 || ob1->slaying != ob2->slaying 284 || ob1->slaying != ob2->slaying
286 || ob1->skill != ob2->skill 285 || ob1->skill != ob2->skill
287 || ob1->value != ob2->value 286 || ob1->value != ob2->value
288 || ob1->animation_id != ob2->animation_id 287 || ob1->animation_id != ob2->animation_id
289 || (ob1->face != ob2->face && !ob1->animation_id) // face and animation are dependent on each other 288 || (ob1->face != ob2->face && !ob1->animation_id) // face and animation are dependend on each other
290 || ob1->client_type != ob2->client_type 289 || ob1->client_type != ob2->client_type
291 || ob1->material != ob2->material 290 || ob1->material != ob2->material
292 || ob1->lore != ob2->lore 291 || ob1->lore != ob2->lore
293 || ob1->subtype != ob2->subtype 292 || ob1->subtype != ob2->subtype
294 || ob1->move_type != ob2->move_type 293 || ob1->move_type != ob2->move_type
687 tail = new_link; 686 tail = new_link;
688 } 687 }
689 } 688 }
690 } 689 }
691 690
692 if (speed < 0)
693 dst->speed_left -= rndm ();
694
695 dst->activate (); 691 dst->activate ();
696} 692}
697 693
698void 694void
699object::instantiate () 695object::instantiate ()
700{ 696{
701 if (!uuid.seq) // HACK 697 if (!uuid.seq) // HACK
702 uuid = UUID::gen (); 698 uuid = UUID::gen ();
703 699
700 // TODO: unclean state changes, should nt be done in copy_to AND instantiate
701 if (flag [FLAG_RANDOM_SPEED] && speed)
702 speed_left = - speed - rndm (); // TODO animation
703 else
704 speed_left = -0.1f; 704 speed_left = -1.;
705
705 /* copy the body_info to the body_used - this is only really 706 /* copy the body_info to the body_used - this is only really
706 * need for monsters, but doesn't hurt to do it for everything. 707 * need for monsters, but doesn't hurt to do it for everything.
707 * by doing so, when a monster is created, it has good starting 708 * by doing so, when a monster is created, it has good starting
708 * values for the body_used info, so when items are created 709 * values for the body_used info, so when items are created
709 * for it, they can be properly equipped. 710 * for it, they can be properly equipped.
717object * 718object *
718object::clone () 719object::clone ()
719{ 720{
720 object *neu = create (); 721 object *neu = create ();
721 copy_to (neu); 722 copy_to (neu);
723
724 // TODO: unclean state changes, should not be done in clone AND instantiate
725 if (neu->flag [FLAG_RANDOM_SPEED] && neu->speed)
726 neu->speed_left = - neu->speed - rndm (); // TODO animation
727
722 neu->map = map; // not copied by copy_to 728 neu->map = map; // not copied by copy_to
723 return neu; 729 return neu;
724} 730}
725 731
726/* 732/*
845{ 851{
846 SET_FLAG (this, FLAG_REMOVED); 852 SET_FLAG (this, FLAG_REMOVED);
847 853
848 //expmul = 1.0; declared const for the time being 854 //expmul = 1.0; declared const for the time being
849 face = blank_face; 855 face = blank_face;
850 material = &material_null; 856 material = MATERIAL_NULL;
851} 857}
852 858
853object::~object () 859object::~object ()
854{ 860{
855 unlink (); 861 unlink ();
1126 1132
1127 above = 0; 1133 above = 0;
1128 below = 0; 1134 below = 0;
1129 env = 0; 1135 env = 0;
1130 1136
1131 /* NO_FIX_PLAYER is set when a great many changes are being 1137 if (pl && pl->is_player ())
1132 * made to players inventory. If set, avoiding the call
1133 * to save cpu time.
1134 */
1135 if (pl)
1136 if (pl->is_player () && (glow_radius || !QUERY_FLAG (pl, FLAG_NO_FIX_PLAYER)))
1137 { 1138 {
1138 pl->update_stats (); 1139 pl->contr->queue_stats_update ();
1139 1140
1140 if (glow_radius && pl->is_on_map ()) 1141 if (glow_radius && pl->is_on_map ())
1141 update_all_los (pl->map, pl->x, pl->y); 1142 update_all_los (pl->map, pl->x, pl->y);
1142 } 1143 }
1143 } 1144 }
1144 else if (map) 1145 else if (map)
1145 { 1146 {
1146 map->dirty = true; 1147 map->dirty = true;
1147 mapspace &ms = this->ms (); 1148 mapspace &ms = this->ms ();
1267 1268
1268 object *prev = this; 1269 object *prev = this;
1269 1270
1270 for (archetype *at = (archetype *)arch->more; at; at = (archetype *)at->more) 1271 for (archetype *at = (archetype *)arch->more; at; at = (archetype *)at->more)
1271 { 1272 {
1272 object *op = arch_to_object (at); 1273 object *op = at->instance ();
1273 1274
1274 op->name = name; 1275 op->name = name;
1275 op->name_pl = name_pl; 1276 op->name_pl = name_pl;
1276 op->title = title; 1277 op->title = title;
1277 1278
1552 1553
1553 for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above) 1554 for (object *tmp = op->ms ().bot; tmp; tmp = tmp->above)
1554 if (tmp->arch->archname == archname) /* same archetype */ 1555 if (tmp->arch->archname == archname) /* same archetype */
1555 tmp->destroy (); 1556 tmp->destroy ();
1556 1557
1557 object *tmp = arch_to_object (archetype::find (archname)); 1558 object *tmp = archetype::find (archname)->instance ();
1558 1559
1559 tmp->x = op->x; 1560 tmp->x = op->x;
1560 tmp->y = op->y; 1561 tmp->y = op->y;
1561 1562
1562 insert_ob_in_map (tmp, op->map, op, 0); 1563 insert_ob_in_map (tmp, op->map, op, 0);
1738 if (op->glow_radius && is_on_map ()) 1739 if (op->glow_radius && is_on_map ())
1739 { 1740 {
1740 update_stats (); 1741 update_stats ();
1741 update_all_los (map, x, y); 1742 update_all_los (map, x, y);
1742 } 1743 }
1743 else if (is_player () && !flag [FLAG_NO_FIX_PLAYER]) 1744 else if (is_player ())
1744 // if this is a player's inventory, update stats 1745 // if this is a player's inventory, update stats
1745 update_stats (); 1746 contr->queue_stats_update ();
1746 1747
1747 INVOKE_OBJECT (INSERT, this); 1748 INVOKE_OBJECT (INSERT, this);
1748 1749
1749 return op; 1750 return op;
1750} 1751}
2561 // TODO: this does not seem to serve any purpose anymore? 2562 // TODO: this does not seem to serve any purpose anymore?
2562#if 0 2563#if 0
2563 // insert the "Close Container" object. 2564 // insert the "Close Container" object.
2564 if (archetype *closer = new_container->other_arch) 2565 if (archetype *closer = new_container->other_arch)
2565 { 2566 {
2566 object *closer = arch_to_object (new_container->other_arch); 2567 object *closer = new_container->other_arch->instance ();
2567 closer->flag [FLAG_NO_MAP_SAVE] = 1; 2568 closer->flag [FLAG_NO_MAP_SAVE] = 1;
2568 new_container->insert (closer); 2569 new_container->insert (closer);
2569 } 2570 }
2570#endif 2571#endif
2571 2572

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines