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.223 by root, Sun Nov 29 17:41:07 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
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])
404 404
405 int move (int dir) 405 int move (int dir)
406 { 406 {
407 return move (dir, this); 407 return move (dir, this);
408 } 408 }
409
410 // changes move_type to a new value - handles move_on/move_off effects
411 void change_move_type (MoveType mt);
409 412
410 static bool can_merge_slow (object *op1, object *op2); 413 static bool can_merge_slow (object *op1, object *op2);
411 414
412 // this is often used in time-critical code, so optimise 415 // this is often used in time-critical code, so optimise
413 MTH static bool can_merge (object *op1, object *op2) 416 MTH static bool can_merge (object *op1, object *op2)
468 MTH void drain_stat (); 471 MTH void drain_stat ();
469 MTH void drain_specific_stat (int deplete_stats); 472 MTH void drain_specific_stat (int deplete_stats);
470 MTH void change_luck (int value); 473 MTH void change_luck (int value);
471 474
472 // info must hold 256 * 3 bytes currently 475 // info must hold 256 * 3 bytes currently
473 const char *debug_desc (char *info) const; 476 const_utf8_string debug_desc (char *info) const;
474 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
475 const char *flag_desc (char *desc, int len) const; 478 const_utf8_string flag_desc (char *desc, int len) const;
476 479
477 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
478 MTH object *split (sint32 nr = 1); // return 0 on failure 481 MTH object *split (sint32 nr = 1); // return 0 on failure
479 482
480 MTH int number_of () const 483 MTH int number_of () const
518 MTH bool is_arrow () const { return type == ARROW 521 MTH bool is_arrow () const { return type == ARROW
519 || (type == SPELL_EFFECT 522 || (type == SPELL_EFFECT
520 && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); } 523 && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); }
521 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; }
522 525
526 MTH bool is_dragon () const;
527
523 MTH bool has_active_speed () const { return speed >= MIN_ACTIVE_SPEED; } 528 MTH bool has_active_speed () const { return speed >= MIN_ACTIVE_SPEED; }
524 529
525 // temporary: wether the object can be saved in a map file 530 // temporary: wether the object can be saved in a map file
526 // contr => is a player 531 // contr => is a player
527 // head => only save head of a multitile object 532 // head => only save head of a multitile object
616 MTH std::string long_desc (object *who = 0); // query_name . " " . describe 621 MTH std::string long_desc (object *who = 0); // query_name . " " . describe
617 MTH std::string describe_monster (object *who = 0); 622 MTH std::string describe_monster (object *who = 0);
618 MTH std::string describe_item (object *who = 0); 623 MTH std::string describe_item (object *who = 0);
619 MTH std::string describe (object *who = 0); // long description, without name 624 MTH std::string describe (object *who = 0); // long description, without name
620 625
621 MTH const char *query_weight () { return ::query_weight (this); } 626 MTH const_utf8_string query_weight () { return ::query_weight (this); }
622 MTH const char *query_name () { return ::query_name (this); } 627 MTH const_utf8_string query_name () { return ::query_name (this); }
623 MTH const char *query_short_name () { return ::query_short_name (this); } 628 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); } 629 MTH const_utf8_string query_base_name (bool plural) { return ::query_base_name (this, plural); }
625 630
626 // If this object has no extra parts but should have them, 631 // If this object has no extra parts but should have them,
627 // add them, effectively expanding heads into multipart 632 // add them, effectively expanding heads into multipart
628 // objects. This method only works on objects not inserted 633 // objects. This method only works on objects not inserted
629 // anywhere. 634 // anywhere.
646 // set the given flag on all objects in the inventory recursively 651 // set the given flag on all objects in the inventory recursively
647 MTH void set_flag_inv (int flag, int value = 1); 652 MTH void set_flag_inv (int flag, int value = 1);
648 653
649 void enter_exit (object *exit);//Perl 654 void enter_exit (object *exit);//Perl
650 MTH void enter_map (maptile *newmap, int x, int y); 655 MTH void enter_map (maptile *newmap, int x, int y);
651 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
652 657
653 // returns the mapspace this object is in 658 // returns the mapspace this object is in
654 mapspace &ms () const; 659 mapspace &ms () const;
655 660
656 // fully recursive iterator 661 // fully recursive iterator
707 return weight + carrying; 712 return weight + carrying;
708 } 713 }
709 714
710 MTH struct region *region () const; 715 MTH struct region *region () const;
711 716
712 void statusmsg (const char *msg, int color = NDI_BLACK); 717 void statusmsg (const_utf8_string msg, int color = NDI_BLACK);
713 void failmsg (const char *msg, int color = NDI_RED); 718 void failmsg (const_utf8_string msg, int color = NDI_RED);
714 719
715 const char *query_inventory (object *who = 0, const char *indent = ""); 720 const_utf8_string query_inventory (object *who = 0, const_utf8_string indent = "");
716 721
717 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
718 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
719 724
720 // make some noise with given item into direction dir, 725 // make some noise with given item into direction dir,
733 * range from 0 through 7. 738 * range from 0 through 7.
734 */ 739 */
735 MTH int anim_frames () const { return anim ().num_animations; } 740 MTH int anim_frames () const { return anim ().num_animations; }
736 MTH int anim_facings () const { return anim ().facings; } 741 MTH int anim_facings () const { return anim ().facings; }
737 742
738 MTH char *as_string (); 743 MTH utf8_string as_string ();
739 744
740protected: 745protected:
741 void link (); 746 void link ();
742 void unlink (); 747 void unlink ();
743 748
768 return ob; 773 return ob;
769} 774}
770 775
771//+GPL 776//+GPL
772 777
773object *find_skill_by_name_fuzzy (object *who, const char *name); 778object *find_skill_by_name_fuzzy (object *who, const_utf8_string name);
774object *find_skill_by_name (object *who, shstr_cmp sh); 779object *find_skill_by_name (object *who, shstr_cmp sh);
775object *find_skill_by_number (object *who, int skillno); 780object *find_skill_by_number (object *who, int skillno);
776 781
777/* 782/*
778 * 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
789struct archetype : object 794struct archetype : object
790{ 795{
791 static arch_ptr empty; // the empty_archetype 796 static arch_ptr empty; // the empty_archetype
792 MTH static void gc (); 797 MTH static void gc ();
793 798
794 archetype (const char *name); 799 archetype (const_utf8_string name);
795 ~archetype (); 800 ~archetype ();
796 void gather_callbacks (AV *&callbacks, event_type event) const; 801 void gather_callbacks (AV *&callbacks, event_type event) const;
797 802
798 MTH static archetype *find (const_utf8_string name); 803 MTH static archetype *find (const_utf8_string name);
799 804
800 MTH void link (); 805 MTH void link ();
801 MTH void unlink (); 806 MTH void unlink ();
802 807
803 MTH static object *get (const char *name); // (find() || singularity)->instance() 808 MTH static object *get (const_utf8_string name); // (find() || singularity)->instance()
804 MTH object *instance (); 809 MTH object *instance ();
805 810
806 MTH void post_load_check (); // do some adjustments after parsing 811 MTH void post_load_check (); // do some adjustments after parsing
807 812
808 object_vector_index ACC (RW, archid); // index in archvector 813 object_vector_index ACC (RW, archid); // index in archvector
809 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */ 814 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */
810 815
811 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...) */
812 sint8 ACC (RW, max_x), ACC (RW, max_y);
813 817
814 // support for archetype loading 818 // support for archetype loading
815 static archetype *read (object_thawer &f); 819 static archetype *read (object_thawer &f);
816 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
817 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 */
818}; 822};
823
824// returns whether the object is a dragon player, which are often specialcased
825inline bool
826object::is_dragon () const
827{
828 return arch->race == shstr_dragon && is_player ();
829}
819 830
820inline void 831inline void
821object_freezer::put (const keyword_string k, archetype *v) 832object_freezer::put (const keyword_string k, archetype *v)
822{ 833{
823 if (expect_true (v)) 834 if (expect_true (v))

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines