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.108 by root, Sun Jan 7 02:39:13 2007 UTC vs.
Revision 1.116 by pippijn, Mon Jan 15 21:06:18 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * CrossFire, A Multiplayer game for X-windows
3 3 *
4 Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team 4 * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team
5 Copyright (C) 2001 Mark Wedel & Crossfire Development Team 5 * Copyright (C) 2001 Mark Wedel & Crossfire Development Team
6 Copyright (C) 1992 Frank Tore Johansen 6 * Copyright (C) 1992 Frank Tore Johansen
7 7 *
8 This program is free software; you can redistribute it and/or modify 8 * This program 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
10 the Free Software Foundation; either version 2 of the License, or 10 * the Free Software Foundation; either version 2 of the License, or
11 (at your option) any later version. 11 * (at your option) any later version.
12 12 *
13 This program is distributed in the hope that it will be useful, 13 * This program is distributed in the hope that it will be useful,
14 but WITHOUT ANY WARRANTY; without even the implied warranty of 14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 GNU General Public License for more details. 16 * GNU General Public License for more details.
17 17 *
18 You should have received a copy of the GNU General Public License 18 * You should have received a copy of the GNU General Public License
19 along with this program; if not, write to the Free Software 19 * along with this program; if not, write to the Free Software
20 Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 20 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
21 21 *
22 The authors can be reached via e-mail at <crossfire@schmorp.de> 22 * The authors can be reached via e-mail at <crossfire@schmorp.de>
23*/ 23 */
24 24
25/* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. 25/* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects.
26 sub/add_weight will transcend the environment updating the carrying 26 sub/add_weight will transcend the environment updating the carrying
27 variable. */ 27 variable. */
28#include <global.h> 28#include <global.h>
395 * Returns the object which has the count-variable equal to the argument. 395 * Returns the object which has the count-variable equal to the argument.
396 */ 396 */
397object * 397object *
398find_object (tag_t i) 398find_object (tag_t i)
399{ 399{
400 return ((unsigned int)i) < objects.size () 400 for_all_objects (op)
401 ? objects [i] 401 if (op->count == i)
402 : 0; 402 return op;
403
404 return 0;
403} 405}
404 406
405/* 407/*
406 * Returns the first object which has a name equal to the argument. 408 * Returns the first object which has a name equal to the argument.
407 * Used only by the patch command, but not all that useful. 409 * Used only by the patch command, but not all that useful.
658 660
659 if (op->more) 661 if (op->more)
660 update_object (op->more, action); 662 update_object (op->more, action);
661} 663}
662 664
663object *object::first;
664
665object::object () 665object::object ()
666{ 666{
667 SET_FLAG (this, FLAG_REMOVED); 667 SET_FLAG (this, FLAG_REMOVED);
668 668
669 expmul = 1.0; 669 expmul = 1.0;
673object::~object () 673object::~object ()
674{ 674{
675 free_key_values (this); 675 free_key_values (this);
676} 676}
677 677
678static int object_count;
679
678void object::link () 680void object::link ()
679{ 681{
682 assert (!index);//D
680 uuid = gen_uuid (); 683 uuid = gen_uuid ();
684 count = ++object_count;
681 685
686 refcnt_inc ();
682 objects.insert (this); 687 objects.insert (this);
683} 688}
684 689
685void object::unlink () 690void object::unlink ()
686{ 691{
692 assert (index);//D
687 objects.erase (this); 693 objects.erase (this);
694 refcnt_dec ();
688} 695}
689 696
690void 697void
691object::activate () 698object::activate ()
692{ 699{
782 789
783 if (op->flag [FLAG_STARTEQUIP] 790 if (op->flag [FLAG_STARTEQUIP]
784 || op->flag [FLAG_NO_DROP] 791 || op->flag [FLAG_NO_DROP]
785 || op->type == RUNE 792 || op->type == RUNE
786 || op->type == TRAP 793 || op->type == TRAP
787 || op->flag [FLAG_IS_A_TEMPLATE]) 794 || op->flag [FLAG_IS_A_TEMPLATE]
795 || op->flag [FLAG_DESTROY_ON_DEATH])
788 op->destroy (); 796 op->destroy ();
789 else 797 else
790 map->insert (op, x, y); 798 map->insert (op, x, y);
791 } 799 }
792 } 800 }
800} 808}
801 809
802void 810void
803object::do_destroy () 811object::do_destroy ()
804{ 812{
813 attachable::do_destroy ();
814
805 if (flag [FLAG_IS_LINKED]) 815 if (flag [FLAG_IS_LINKED])
806 remove_button_link (this); 816 remove_button_link (this);
807 817
808 if (flag [FLAG_FRIENDLY]) 818 if (flag [FLAG_FRIENDLY])
809 remove_friendly_object (this); 819 remove_friendly_object (this);
810 820
811 if (!flag [FLAG_REMOVED]) 821 if (!flag [FLAG_REMOVED])
812 remove (); 822 remove ();
813 823
814 if (flag [FLAG_FREED]) 824 destroy_inv (true);
815 return;
816 825
817 set_speed (0); 826 deactivate ();
827 unlink ();
818 828
819 flag [FLAG_FREED] = 1; 829 flag [FLAG_FREED] = 1;
820
821 attachable::do_destroy ();
822
823 destroy_inv (true);
824 unlink ();
825 830
826 // hack to ensure that freed objects still have a valid map 831 // hack to ensure that freed objects still have a valid map
827 { 832 {
828 static maptile *freed_map; // freed objects are moved here to avoid crashes 833 static maptile *freed_map; // freed objects are moved here to avoid crashes
829 834
2158 2163
2159 return 3; 2164 return 3;
2160} 2165}
2161 2166
2162/* 2167/*
2163 * absdir(int): Returns a number between 1 and 8, which represent
2164 * the "absolute" direction of a number (it actually takes care of
2165 * "overflow" in previous calculations of a direction).
2166 */
2167
2168int
2169absdir (int d)
2170{
2171 while (d < 1)
2172 d += 8;
2173
2174 while (d > 8)
2175 d -= 8;
2176
2177 return d;
2178}
2179
2180/*
2181 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is 2168 * dirdiff(dir1, dir2) returns how many 45-degrees differences there is
2182 * between two directions (which are expected to be absolute (see absdir()) 2169 * between two directions (which are expected to be absolute (see absdir())
2183 */ 2170 */
2184
2185int 2171int
2186dirdiff (int dir1, int dir2) 2172dirdiff (int dir1, int dir2)
2187{ 2173{
2188 int d; 2174 int d;
2189 2175
2628{ 2614{
2629 static char info[256 * 4]; 2615 static char info[256 * 4];
2630 return debug_desc (info); 2616 return debug_desc (info);
2631} 2617}
2632 2618
2619const char *
2620object::debug_desc2 () const
2621{
2622 static char info[256 * 4];
2623 return debug_desc (info);
2624}
2625

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines