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.225 by root, Sat Jan 30 23:30:26 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 is_dragon () const;
524
523 MTH bool has_active_speed () const { return fabs (speed) >= MIN_ACTIVE_SPEED; } 525 MTH bool has_active_speed () const { return speed >= MIN_ACTIVE_SPEED; }
524 526
525 // temporary: wether the object can be saved in a map file 527 // temporary: wether the object can be saved in a map file
526 // contr => is a player 528 // contr => is a player
527 // head => only save head of a multitile object 529 // head => only save head of a multitile object
528 // owner => can not reference owner yet 530 // owner => can not reference owner yet
616 MTH std::string long_desc (object *who = 0); // query_name . " " . describe 618 MTH std::string long_desc (object *who = 0); // query_name . " " . describe
617 MTH std::string describe_monster (object *who = 0); 619 MTH std::string describe_monster (object *who = 0);
618 MTH std::string describe_item (object *who = 0); 620 MTH std::string describe_item (object *who = 0);
619 MTH std::string describe (object *who = 0); // long description, without name 621 MTH std::string describe (object *who = 0); // long description, without name
620 622
621 MTH const char *query_weight () { return ::query_weight (this); } 623 MTH const_utf8_string query_weight () { return ::query_weight (this); }
622 MTH const char *query_name () { return ::query_name (this); } 624 MTH const_utf8_string query_name () { return ::query_name (this); }
623 MTH const char *query_short_name () { return ::query_short_name (this); } 625 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); } 626 MTH const_utf8_string query_base_name (bool plural) { return ::query_base_name (this, plural); }
625 627
626 // If this object has no extra parts but should have them, 628 // If this object has no extra parts but should have them,
627 // add them, effectively expanding heads into multipart 629 // add them, effectively expanding heads into multipart
628 // objects. This method only works on objects not inserted 630 // objects. This method only works on objects not inserted
629 // anywhere. 631 // anywhere.
646 // set the given flag on all objects in the inventory recursively 648 // set the given flag on all objects in the inventory recursively
647 MTH void set_flag_inv (int flag, int value = 1); 649 MTH void set_flag_inv (int flag, int value = 1);
648 650
649 void enter_exit (object *exit);//Perl 651 void enter_exit (object *exit);//Perl
650 MTH void enter_map (maptile *newmap, int x, int y); 652 MTH void enter_map (maptile *newmap, int x, int y);
651 void player_goto (const char *path, int x, int y); // only for players 653 void player_goto (const_utf8_string path, int x, int y); // only for players
652 654
653 // returns the mapspace this object is in 655 // returns the mapspace this object is in
654 mapspace &ms () const; 656 mapspace &ms () const;
655 657
656 // fully recursive iterator 658 // fully recursive iterator
707 return weight + carrying; 709 return weight + carrying;
708 } 710 }
709 711
710 MTH struct region *region () const; 712 MTH struct region *region () const;
711 713
712 void statusmsg (const char *msg, int color = NDI_BLACK); 714 void statusmsg (const_utf8_string msg, int color = NDI_BLACK);
713 void failmsg (const char *msg, int color = NDI_RED); 715 void failmsg (const_utf8_string msg, int color = NDI_RED);
714 716
715 const char *query_inventory (object *who = 0, const char *indent = ""); 717 const_utf8_string query_inventory (object *who = 0, const_utf8_string indent = "");
716 718
717 MTH const_octet_string ref () const; // creates and returns a consistent persistent object reference 719 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 720 static object *deref (const_octet_string ref); // returns the object from the generated refreence, if possible
719 721
720 // make some noise with given item into direction dir, 722 // make some noise with given item into direction dir,
733 * range from 0 through 7. 735 * range from 0 through 7.
734 */ 736 */
735 MTH int anim_frames () const { return anim ().num_animations; } 737 MTH int anim_frames () const { return anim ().num_animations; }
736 MTH int anim_facings () const { return anim ().facings; } 738 MTH int anim_facings () const { return anim ().facings; }
737 739
738 MTH char *as_string (); 740 MTH utf8_string as_string ();
739 741
740protected: 742protected:
741 void link (); 743 void link ();
742 void unlink (); 744 void unlink ();
743 745
768 return ob; 770 return ob;
769} 771}
770 772
771//+GPL 773//+GPL
772 774
773object *find_skill_by_name_fuzzy (object *who, const char *name); 775object *find_skill_by_name_fuzzy (object *who, const_utf8_string name);
774object *find_skill_by_name (object *who, shstr_cmp sh); 776object *find_skill_by_name (object *who, shstr_cmp sh);
775object *find_skill_by_number (object *who, int skillno); 777object *find_skill_by_number (object *who, int skillno);
776 778
777/* 779/*
778 * The archetype structure is a set of rules on how to generate and manipulate 780 * The archetype structure is a set of rules on how to generate and manipulate
789struct archetype : object 791struct archetype : object
790{ 792{
791 static arch_ptr empty; // the empty_archetype 793 static arch_ptr empty; // the empty_archetype
792 MTH static void gc (); 794 MTH static void gc ();
793 795
794 archetype (const char *name); 796 archetype (const_utf8_string name);
795 ~archetype (); 797 ~archetype ();
796 void gather_callbacks (AV *&callbacks, event_type event) const; 798 void gather_callbacks (AV *&callbacks, event_type event) const;
797 799
798 MTH static archetype *find (const_utf8_string name); 800 MTH static archetype *find (const_utf8_string name);
799 801
800 MTH void link (); 802 MTH void link ();
801 MTH void unlink (); 803 MTH void unlink ();
802 804
803 MTH static object *get (const char *name); // (find() || singularity)->instance() 805 MTH static object *get (const_utf8_string name); // (find() || singularity)->instance()
804 MTH object *instance (); 806 MTH object *instance ();
805 807
806 MTH void post_load_check (); // do some adjustments after parsing 808 MTH void post_load_check (); // do some adjustments after parsing
807 809
808 object_vector_index ACC (RW, archid); // index in archvector 810 object_vector_index ACC (RW, archid); // index in archvector
815 static archetype *read (object_thawer &f); 817 static archetype *read (object_thawer &f);
816 MTH static void commit_load (); // commit any objects loaded, resolves cyclic dependencies and more 818 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 */ 819 static void postpone_arch_ref (arch_ptr &ref, const_utf8_string other_arch); /* postpone other_arch reference */
818}; 820};
819 821
820// compatbiility, remove once replaced by ->instance 822// returns whether the objetc is a dragon player, which are often specialcased
821inline object * 823inline bool
822arch_to_object (archetype *at) 824object::is_dragon () const
823{ 825{
824 return at->instance (); 826 return arch->race == shstr_dragon && is_player ();
825} 827}
826 828
827inline void 829inline void
828object_freezer::put (keyword k, archetype *v) 830object_freezer::put (const keyword_string k, archetype *v)
829{ 831{
830 put (k, v ? &v->archname : (const char *)0); 832 if (expect_true (v))
833 put (k, v->archname);
834 else
835 put (k);
831} 836}
832 837
833typedef object_vector<object, &object::index > objectvec; 838typedef object_vector<object, &object::index > objectvec;
834typedef object_vector<object, &object::active> activevec; 839typedef object_vector<object, &object::active> activevec;
835typedef object_vector<archetype, &archetype::archid> archvec; 840typedef object_vector<archetype, &archetype::archid> archvec;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines