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

Comparing deliantra/server/include/object.h (file contents):
Revision 1.220 by root, Tue Nov 10 05:05:22 2009 UTC vs.
Revision 1.224 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
285 shstr ACC (RW, lore); /* Obscure information about this object, */ 285 shstr ACC (RW, lore); /* Obscure information about this object, */
286 /* To get put into books and the like. */ 286 /* To get put into books and the like. */
287 shstr ACC (RW, custom_name); /* Custom name assigned by player */ 287 shstr ACC (RW, custom_name); /* Custom name assigned by player */
288}; 288};
289 289
290const char *query_weight (const object *op); 290const_utf8_string query_weight (const object *op);
291const char *query_short_name (const object *op); 291const_utf8_string query_short_name (const object *op);
292const char *query_name (const object *op); 292const_utf8_string query_name (const object *op);
293const char *query_base_name (const object *op, int plural); 293const_utf8_string query_base_name (const object *op, int plural);
294 294
295struct object : zero_initialised, object_copy 295struct object : zero_initialised, object_copy
296{ 296{
297 // These variables are not changed by ->copy_to 297 // These variables are not changed by ->copy_to
298 maptile *ACC (RW, map); /* Pointer to the map in which this object is present */ 298 maptile *ACC (RW, map); /* Pointer to the map in which this object is present */
379 379
380 // recursively destroy all objects in inventory, optionally dropping them to the ground instead 380 // recursively destroy all objects in inventory, optionally dropping them to the ground instead
381 MTH void destroy_inv (bool drop_to_ground = false); 381 MTH void destroy_inv (bool drop_to_ground = false);
382 MTH object *insert (object *item); // insert into inventory 382 MTH object *insert (object *item); // insert into inventory
383 MTH void play_sound (faceidx sound) const; 383 MTH void play_sound (faceidx sound) const;
384 MTH void say_msg (const char *msg) const; 384 MTH void say_msg (const_utf8_string msg) const;
385 385
386 void do_remove (); 386 void do_remove ();
387 MTH void remove () 387 MTH void remove ()
388 { 388 {
389 if (!flag [FLAG_REMOVED]) 389 if (!flag [FLAG_REMOVED])
468 MTH void drain_stat (); 468 MTH void drain_stat ();
469 MTH void drain_specific_stat (int deplete_stats); 469 MTH void drain_specific_stat (int deplete_stats);
470 MTH void change_luck (int value); 470 MTH void change_luck (int value);
471 471
472 // info must hold 256 * 3 bytes currently 472 // info must hold 256 * 3 bytes currently
473 const char *debug_desc (char *info) const; 473 const_utf8_string debug_desc (char *info) const;
474 MTH const char *debug_desc () const; // uses at least 3 round-robin buffers 474 MTH const_utf8_string debug_desc () const; // uses at least 3 round-robin buffers
475 const char *flag_desc (char *desc, int len) const; 475 const_utf8_string flag_desc (char *desc, int len) const;
476 476
477 MTH bool decrease (sint32 nr = 1); // returns true if anything is left 477 MTH bool decrease (sint32 nr = 1); // returns true if anything is left
478 MTH object *split (sint32 nr = 1); // return 0 on failure 478 MTH object *split (sint32 nr = 1); // return 0 on failure
479 479
480 MTH int number_of () const 480 MTH int number_of () const
518 MTH bool is_arrow () const { return type == ARROW 518 MTH bool is_arrow () const { return type == ARROW
519 || (type == SPELL_EFFECT 519 || (type == SPELL_EFFECT
520 && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); } 520 && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); }
521 MTH bool is_range () const { return type == BOW || type == ROD || type == WAND || type == HORN; } 521 MTH bool is_range () const { return type == BOW || type == ROD || type == WAND || type == HORN; }
522 522
523 MTH bool has_active_speed () const { return fabs (speed) >= MIN_ACTIVE_SPEED; } 523 MTH bool has_active_speed () const { return speed >= MIN_ACTIVE_SPEED; }
524 524
525 // temporary: wether the object can be saved in a map file 525 // temporary: wether the object can be saved in a map file
526 // contr => is a player 526 // contr => is a player
527 // head => only save head of a multitile object 527 // head => only save head of a multitile object
528 // owner => can not reference owner yet 528 // owner => can not reference owner yet
616 MTH std::string long_desc (object *who = 0); // query_name . " " . describe 616 MTH std::string long_desc (object *who = 0); // query_name . " " . describe
617 MTH std::string describe_monster (object *who = 0); 617 MTH std::string describe_monster (object *who = 0);
618 MTH std::string describe_item (object *who = 0); 618 MTH std::string describe_item (object *who = 0);
619 MTH std::string describe (object *who = 0); // long description, without name 619 MTH std::string describe (object *who = 0); // long description, without name
620 620
621 MTH const char *query_weight () { return ::query_weight (this); } 621 MTH const_utf8_string query_weight () { return ::query_weight (this); }
622 MTH const char *query_name () { return ::query_name (this); } 622 MTH const_utf8_string query_name () { return ::query_name (this); }
623 MTH const char *query_short_name () { return ::query_short_name (this); } 623 MTH const_utf8_string query_short_name () { return ::query_short_name (this); }
624 MTH const char *query_base_name (bool plural) { return ::query_base_name (this, plural); } 624 MTH const_utf8_string query_base_name (bool plural) { return ::query_base_name (this, plural); }
625 625
626 // If this object has no extra parts but should have them, 626 // If this object has no extra parts but should have them,
627 // add them, effectively expanding heads into multipart 627 // add them, effectively expanding heads into multipart
628 // objects. This method only works on objects not inserted 628 // objects. This method only works on objects not inserted
629 // anywhere. 629 // anywhere.
646 // set the given flag on all objects in the inventory recursively 646 // set the given flag on all objects in the inventory recursively
647 MTH void set_flag_inv (int flag, int value = 1); 647 MTH void set_flag_inv (int flag, int value = 1);
648 648
649 void enter_exit (object *exit);//Perl 649 void enter_exit (object *exit);//Perl
650 MTH void enter_map (maptile *newmap, int x, int y); 650 MTH void enter_map (maptile *newmap, int x, int y);
651 void player_goto (const char *path, int x, int y); // only for players 651 void player_goto (const_utf8_string path, int x, int y); // only for players
652 652
653 // returns the mapspace this object is in 653 // returns the mapspace this object is in
654 mapspace &ms () const; 654 mapspace &ms () const;
655 655
656 // fully recursive iterator 656 // fully recursive iterator
707 return weight + carrying; 707 return weight + carrying;
708 } 708 }
709 709
710 MTH struct region *region () const; 710 MTH struct region *region () const;
711 711
712 void statusmsg (const char *msg, int color = NDI_BLACK); 712 void statusmsg (const_utf8_string msg, int color = NDI_BLACK);
713 void failmsg (const char *msg, int color = NDI_RED); 713 void failmsg (const_utf8_string msg, int color = NDI_RED);
714 714
715 const char *query_inventory (object *who = 0, const char *indent = ""); 715 const_utf8_string query_inventory (object *who = 0, const_utf8_string indent = "");
716 716
717 MTH const_octet_string ref () const; // creates and returns a consistent persistent object reference 717 MTH const_octet_string ref () const; // creates and returns a consistent persistent object reference
718 static object *deref (const_octet_string ref); // returns the object from the generated refreence, if possible 718 static object *deref (const_octet_string ref); // returns the object from the generated refreence, if possible
719 719
720 // make some noise with given item into direction dir, 720 // make some noise with given item into direction dir,
733 * range from 0 through 7. 733 * range from 0 through 7.
734 */ 734 */
735 MTH int anim_frames () const { return anim ().num_animations; } 735 MTH int anim_frames () const { return anim ().num_animations; }
736 MTH int anim_facings () const { return anim ().facings; } 736 MTH int anim_facings () const { return anim ().facings; }
737 737
738 MTH char *as_string (); 738 MTH utf8_string as_string ();
739 739
740protected: 740protected:
741 void link (); 741 void link ();
742 void unlink (); 742 void unlink ();
743 743
768 return ob; 768 return ob;
769} 769}
770 770
771//+GPL 771//+GPL
772 772
773object *find_skill_by_name_fuzzy (object *who, const char *name); 773object *find_skill_by_name_fuzzy (object *who, const_utf8_string name);
774object *find_skill_by_name (object *who, shstr_cmp sh); 774object *find_skill_by_name (object *who, shstr_cmp sh);
775object *find_skill_by_number (object *who, int skillno); 775object *find_skill_by_number (object *who, int skillno);
776 776
777/* 777/*
778 * The archetype structure is a set of rules on how to generate and manipulate 778 * The archetype structure is a set of rules on how to generate and manipulate
789struct archetype : object 789struct archetype : object
790{ 790{
791 static arch_ptr empty; // the empty_archetype 791 static arch_ptr empty; // the empty_archetype
792 MTH static void gc (); 792 MTH static void gc ();
793 793
794 archetype (const char *name); 794 archetype (const_utf8_string name);
795 ~archetype (); 795 ~archetype ();
796 void gather_callbacks (AV *&callbacks, event_type event) const; 796 void gather_callbacks (AV *&callbacks, event_type event) const;
797 797
798 MTH static archetype *find (const_utf8_string name); 798 MTH static archetype *find (const_utf8_string name);
799 799
800 MTH void link (); 800 MTH void link ();
801 MTH void unlink (); 801 MTH void unlink ();
802 802
803 MTH static object *get (const char *name); // (find() || singularity)->instance() 803 MTH static object *get (const_utf8_string name); // (find() || singularity)->instance()
804 MTH object *instance (); 804 MTH object *instance ();
805 805
806 MTH void post_load_check (); // do some adjustments after parsing 806 MTH void post_load_check (); // do some adjustments after parsing
807 807
808 object_vector_index ACC (RW, archid); // index in archvector 808 object_vector_index ACC (RW, archid); // index in archvector
815 static archetype *read (object_thawer &f); 815 static archetype *read (object_thawer &f);
816 MTH static void commit_load (); // commit any objects loaded, resolves cyclic dependencies and more 816 MTH static void commit_load (); // commit any objects loaded, resolves cyclic dependencies and more
817 static void postpone_arch_ref (arch_ptr &ref, const_utf8_string other_arch); /* postpone other_arch reference */ 817 static void postpone_arch_ref (arch_ptr &ref, const_utf8_string other_arch); /* postpone other_arch reference */
818}; 818};
819 819
820// compatbiility, remove once replaced by ->instance
821inline object *
822arch_to_object (archetype *at)
823{
824 return at->instance ();
825}
826
827inline void 820inline void
828object_freezer::put (keyword k, archetype *v) 821object_freezer::put (const keyword_string k, archetype *v)
829{ 822{
830 put (k, v ? &v->archname : (const char *)0); 823 if (expect_true (v))
824 put (k, v->archname);
825 else
826 put (k);
831} 827}
832 828
833typedef object_vector<object, &object::index > objectvec; 829typedef object_vector<object, &object::index > objectvec;
834typedef object_vector<object, &object::active> activevec; 830typedef object_vector<object, &object::active> activevec;
835typedef object_vector<archetype, &archetype::archid> archvec; 831typedef object_vector<archetype, &archetype::archid> archvec;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines