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.218 by root, Mon Nov 9 03:08:24 2009 UTC vs.
Revision 1.227 by root, Fri Mar 26 00:05:45 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
165 flags_t flag; /* various flags */ 165 flags_t flag; /* various flags */
166#if FOR_PERL 166#if FOR_PERL
167 bool ACC (RW, flag[NUM_FLAGS]); 167 bool ACC (RW, flag[NUM_FLAGS]);
168#endif 168#endif
169 169
170 shstr ACC (RW, materialname); /* specific material name */ 170 materialtype_t *material; // What material this object consists of //TODO, make perl-accessible
171 shstr ACC (RW, skill); /* Name of the skill this object uses/grants */ 171 shstr ACC (RW, skill); /* Name of the skill this object uses/grants */
172// materialtype_t *ACC (RW, material); /* What material this object consists of */
173 object_ptr ACC (RW, owner); /* Pointer to the object which controls this one */ 172 object_ptr ACC (RW, owner); /* Pointer to the object which controls this one */
174 object_ptr ACC (RW, enemy); /* Monster/player to follow even if not closest */ 173 object_ptr ACC (RW, enemy); /* Monster/player to follow even if not closest */
175 object_ptr ACC (RW, attacked_by); /* This object start to attack us! only player & monster */ 174 object_ptr ACC (RW, attacked_by); /* This object start to attack us! only player & monster */
176 object_ptr ACC (RW, chosen_skill); /* the skill chosen to use */ 175 object_ptr ACC (RW, chosen_skill); /* the skill chosen to use */
177 object_ptr ACC (RW, spellitem); /* Spell ability monster is choosing to use */ 176 object_ptr ACC (RW, spellitem); /* Spell ability monster is choosing to use */
286 shstr ACC (RW, lore); /* Obscure information about this object, */ 285 shstr ACC (RW, lore); /* Obscure information about this object, */
287 /* To get put into books and the like. */ 286 /* To get put into books and the like. */
288 shstr ACC (RW, custom_name); /* Custom name assigned by player */ 287 shstr ACC (RW, custom_name); /* Custom name assigned by player */
289}; 288};
290 289
291const char *query_weight (const object *op); 290const_utf8_string query_weight (const object *op);
292const char *query_short_name (const object *op); 291const_utf8_string query_short_name (const object *op);
293const char *query_name (const object *op); 292const_utf8_string query_name (const object *op);
294const char *query_base_name (const object *op, int plural); 293const_utf8_string query_base_name (const object *op, int plural);
295 294
296struct object : zero_initialised, object_copy 295struct object : zero_initialised, object_copy
297{ 296{
298 // These variables are not changed by ->copy_to 297 // These variables are not changed by ->copy_to
299 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 */
380 379
381 // 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
382 MTH void destroy_inv (bool drop_to_ground = false); 381 MTH void destroy_inv (bool drop_to_ground = false);
383 MTH object *insert (object *item); // insert into inventory 382 MTH object *insert (object *item); // insert into inventory
384 MTH void play_sound (faceidx sound) const; 383 MTH void play_sound (faceidx sound) const;
385 MTH void say_msg (const char *msg) const; 384 MTH void say_msg (const_utf8_string msg) const;
386 385
387 void do_remove (); 386 void do_remove ();
388 MTH void remove () 387 MTH void remove ()
389 { 388 {
390 if (!flag [FLAG_REMOVED]) 389 if (!flag [FLAG_REMOVED])
405 404
406 int move (int dir) 405 int move (int dir)
407 { 406 {
408 return move (dir, this); 407 return move (dir, this);
409 } 408 }
409
410 // changes move_type to a new value - handles move_on/move_off effects
411 void change_move_type (MoveType mt);
410 412
411 static bool can_merge_slow (object *op1, object *op2); 413 static bool can_merge_slow (object *op1, object *op2);
412 414
413 // this is often used in time-critical code, so optimise 415 // this is often used in time-critical code, so optimise
414 MTH static bool can_merge (object *op1, object *op2) 416 MTH static bool can_merge (object *op1, object *op2)
469 MTH void drain_stat (); 471 MTH void drain_stat ();
470 MTH void drain_specific_stat (int deplete_stats); 472 MTH void drain_specific_stat (int deplete_stats);
471 MTH void change_luck (int value); 473 MTH void change_luck (int value);
472 474
473 // info must hold 256 * 3 bytes currently 475 // info must hold 256 * 3 bytes currently
474 const char *debug_desc (char *info) const; 476 const_utf8_string debug_desc (char *info) const;
475 MTH const char *debug_desc () const; // uses at least 3 round-robin buffers 477 MTH const_utf8_string debug_desc () const; // uses at least 3 round-robin buffers
476 const char *flag_desc (char *desc, int len) const; 478 const_utf8_string flag_desc (char *desc, int len) const;
477 479
478 MTH bool decrease (sint32 nr = 1); // returns true if anything is left 480 MTH bool decrease (sint32 nr = 1); // returns true if anything is left
479 MTH object *split (sint32 nr = 1); // return 0 on failure 481 MTH object *split (sint32 nr = 1); // return 0 on failure
480 482
481 MTH int number_of () const 483 MTH int number_of () const
489 } 491 }
490 492
491 MTH void update_weight (); 493 MTH void update_weight ();
492 494
493 // return the dominant material of this item, always return something 495 // return the dominant material of this item, always return something
494 const materialtype_t *dominant_material () const; 496 const materialtype_t *dominant_material () const
497 {
498 return material;
499 }
495 500
496 // return the volume of this object in cm³ 501 // return the volume of this object in cm³
497 MTH uint64 volume () const 502 MTH uint64 volume () const
498 { 503 {
499 return (uint64)total_weight () 504 return (uint64)total_weight ()
500 * 1000 505 * 1024 // 1000 actually
501 * (type == CONTAINER ? 1000 : 1) 506 * (type == CONTAINER ? 128 : 1)
502 / dominant_material ()->density; 507 / dominant_material ()->density; // ugh, division
503 } 508 }
504 509
505 MTH bool is_arch () const { return this == (const object *)(const archetype *)arch; } 510 MTH bool is_arch () const { return this == (const object *)(const archetype *)arch; }
506 511
507 MTH bool is_wiz () const { return flag [FLAG_WIZ]; } 512 MTH bool is_wiz () const { return flag [FLAG_WIZ]; }
516 MTH bool is_arrow () const { return type == ARROW 521 MTH bool is_arrow () const { return type == ARROW
517 || (type == SPELL_EFFECT 522 || (type == SPELL_EFFECT
518 && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); } 523 && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); }
519 MTH bool is_range () const { return type == BOW || type == ROD || type == WAND || type == HORN; } 524 MTH bool is_range () const { return type == BOW || type == ROD || type == WAND || type == HORN; }
520 525
526 MTH bool is_dragon () const;
527
521 MTH bool has_active_speed () const { return fabs (speed) >= MIN_ACTIVE_SPEED; } 528 MTH bool has_active_speed () const { return speed >= MIN_ACTIVE_SPEED; }
522 529
523 // temporary: wether the object can be saved in a map file 530 // temporary: wether the object can be saved in a map file
524 // contr => is a player 531 // contr => is a player
525 // head => only save head of a multitile object 532 // head => only save head of a multitile object
526 // owner => can not reference owner yet 533 // owner => can not reference owner yet
614 MTH std::string long_desc (object *who = 0); // query_name . " " . describe 621 MTH std::string long_desc (object *who = 0); // query_name . " " . describe
615 MTH std::string describe_monster (object *who = 0); 622 MTH std::string describe_monster (object *who = 0);
616 MTH std::string describe_item (object *who = 0); 623 MTH std::string describe_item (object *who = 0);
617 MTH std::string describe (object *who = 0); // long description, without name 624 MTH std::string describe (object *who = 0); // long description, without name
618 625
619 MTH const char *query_weight () { return ::query_weight (this); } 626 MTH const_utf8_string query_weight () { return ::query_weight (this); }
620 MTH const char *query_name () { return ::query_name (this); } 627 MTH const_utf8_string query_name () { return ::query_name (this); }
621 MTH const char *query_short_name () { return ::query_short_name (this); } 628 MTH const_utf8_string query_short_name () { return ::query_short_name (this); }
622 MTH const char *query_base_name (bool plural) { return ::query_base_name (this, plural); } 629 MTH const_utf8_string query_base_name (bool plural) { return ::query_base_name (this, plural); }
623 630
624 // If this object has no extra parts but should have them, 631 // If this object has no extra parts but should have them,
625 // add them, effectively expanding heads into multipart 632 // add them, effectively expanding heads into multipart
626 // objects. This method only works on objects not inserted 633 // objects. This method only works on objects not inserted
627 // anywhere. 634 // anywhere.
644 // set the given flag on all objects in the inventory recursively 651 // set the given flag on all objects in the inventory recursively
645 MTH void set_flag_inv (int flag, int value = 1); 652 MTH void set_flag_inv (int flag, int value = 1);
646 653
647 void enter_exit (object *exit);//Perl 654 void enter_exit (object *exit);//Perl
648 MTH void enter_map (maptile *newmap, int x, int y); 655 MTH void enter_map (maptile *newmap, int x, int y);
649 void player_goto (const char *path, int x, int y); // only for players 656 void player_goto (const_utf8_string path, int x, int y); // only for players
650 657
651 // returns the mapspace this object is in 658 // returns the mapspace this object is in
652 mapspace &ms () const; 659 mapspace &ms () const;
653 660
654 // fully recursive iterator 661 // fully recursive iterator
705 return weight + carrying; 712 return weight + carrying;
706 } 713 }
707 714
708 MTH struct region *region () const; 715 MTH struct region *region () const;
709 716
710 void statusmsg (const char *msg, int color = NDI_BLACK); 717 void statusmsg (const_utf8_string msg, int color = NDI_BLACK);
711 void failmsg (const char *msg, int color = NDI_RED); 718 void failmsg (const_utf8_string msg, int color = NDI_RED);
712 719
713 const char *query_inventory (object *who = 0, const char *indent = ""); 720 const_utf8_string query_inventory (object *who = 0, const_utf8_string indent = "");
714 721
715 MTH const_octet_string ref () const; // creates and returns a consistent persistent object reference 722 MTH const_octet_string ref () const; // creates and returns a consistent persistent object reference
716 static object *deref (const_octet_string ref); // returns the object from the generated refreence, if possible 723 static object *deref (const_octet_string ref); // returns the object from the generated refreence, if possible
717 724
718 // make some noise with given item into direction dir, 725 // make some noise with given item into direction dir,
731 * range from 0 through 7. 738 * range from 0 through 7.
732 */ 739 */
733 MTH int anim_frames () const { return anim ().num_animations; } 740 MTH int anim_frames () const { return anim ().num_animations; }
734 MTH int anim_facings () const { return anim ().facings; } 741 MTH int anim_facings () const { return anim ().facings; }
735 742
736 MTH char *as_string (); 743 MTH utf8_string as_string ();
737 744
738protected: 745protected:
739 void link (); 746 void link ();
740 void unlink (); 747 void unlink ();
741 748
766 return ob; 773 return ob;
767} 774}
768 775
769//+GPL 776//+GPL
770 777
771object *find_skill_by_name_fuzzy (object *who, const char *name); 778object *find_skill_by_name_fuzzy (object *who, const_utf8_string name);
772object *find_skill_by_name (object *who, shstr_cmp sh); 779object *find_skill_by_name (object *who, shstr_cmp sh);
773object *find_skill_by_number (object *who, int skillno); 780object *find_skill_by_number (object *who, int skillno);
774 781
775/* 782/*
776 * The archetype structure is a set of rules on how to generate and manipulate 783 * The archetype structure is a set of rules on how to generate and manipulate
787struct archetype : object 794struct archetype : object
788{ 795{
789 static arch_ptr empty; // the empty_archetype 796 static arch_ptr empty; // the empty_archetype
790 MTH static void gc (); 797 MTH static void gc ();
791 798
792 archetype (const char *name); 799 archetype (const_utf8_string name);
793 ~archetype (); 800 ~archetype ();
794 void gather_callbacks (AV *&callbacks, event_type event) const; 801 void gather_callbacks (AV *&callbacks, event_type event) const;
795 802
796 MTH static archetype *find (const_utf8_string name); 803 MTH static archetype *find (const_utf8_string name);
797 804
798 MTH void link (); 805 MTH void link ();
799 MTH void unlink (); 806 MTH void unlink ();
800 807
801 MTH static object *get (const char *name); // (find() || singularity)->instance() 808 MTH static object *get (const_utf8_string name); // (find() || singularity)->instance()
802 MTH object *instance (); 809 MTH object *instance ();
803 810
804 MTH void post_load_check (); // do some adjustments after parsing 811 MTH void post_load_check (); // do some adjustments after parsing
805 812
806 object_vector_index ACC (RW, archid); // index in archvector 813 object_vector_index ACC (RW, archid); // index in archvector
807 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */ 814 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */
808 815
809 sint8 ACC (RW, min_x), ACC (RW, min_y); /* extents, compared to the head (min_x, min_y should be zero, but aren't...) */ 816 sint8 ACC (RW, max_x); /* extents, compared to the head (min_x, min_y should be zero, but aren't...) */
810 sint8 ACC (RW, max_x), ACC (RW, max_y);
811 817
812 // support for archetype loading 818 // support for archetype loading
813 static archetype *read (object_thawer &f); 819 static archetype *read (object_thawer &f);
814 MTH static void commit_load (); // commit any objects loaded, resolves cyclic dependencies and more 820 MTH static void commit_load (); // commit any objects loaded, resolves cyclic dependencies and more
815 static void postpone_arch_ref (arch_ptr &ref, const_utf8_string other_arch); /* postpone other_arch reference */ 821 static void postpone_arch_ref (arch_ptr &ref, const_utf8_string other_arch); /* postpone other_arch reference */
816}; 822};
817 823
818// compatbiility, remove once replaced by ->instance 824// returns whether the object is a dragon player, which are often specialcased
819inline object * 825inline bool
820arch_to_object (archetype *at) 826object::is_dragon () const
821{ 827{
822 return at->instance (); 828 return arch->race == shstr_dragon && is_player ();
823} 829}
824 830
825inline void 831inline void
826object_freezer::put (keyword k, archetype *v) 832object_freezer::put (const keyword_string k, archetype *v)
827{ 833{
828 put (k, v ? &v->archname : (const char *)0); 834 if (expect_true (v))
835 put (k, v->archname);
836 else
837 put (k);
829} 838}
830 839
831typedef object_vector<object, &object::index > objectvec; 840typedef object_vector<object, &object::index > objectvec;
832typedef object_vector<object, &object::active> activevec; 841typedef object_vector<object, &object::active> activevec;
833typedef object_vector<archetype, &archetype::archid> archvec; 842typedef object_vector<archetype, &archetype::archid> archvec;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines