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.231 by root, Sat Apr 3 02:27:24 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 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992 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
10 * Free Software Foundation, either version 3 of the License, or (at your 10 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 11 * option) any later version.
32 32
33//+GPL 33//+GPL
34 34
35typedef int tag_t; 35typedef int tag_t;
36 36
37// also see common/item.C
37enum { 38enum {
38 body_skill, 39 body_skill,
39 body_combat, 40 body_combat,
40 body_range, 41 body_range,
41 body_shield, 42 body_shield,
285 shstr ACC (RW, lore); /* Obscure information about this object, */ 286 shstr ACC (RW, lore); /* Obscure information about this object, */
286 /* To get put into books and the like. */ 287 /* To get put into books and the like. */
287 shstr ACC (RW, custom_name); /* Custom name assigned by player */ 288 shstr ACC (RW, custom_name); /* Custom name assigned by player */
288}; 289};
289 290
290const char *query_weight (const object *op); 291const_utf8_string query_weight (const object *op);
291const char *query_short_name (const object *op); 292const_utf8_string query_short_name (const object *op);
292const char *query_name (const object *op); 293const_utf8_string query_name (const object *op);
293const char *query_base_name (const object *op, int plural); 294const_utf8_string query_base_name (const object *op, int plural);
294 295
295struct object : zero_initialised, object_copy 296struct object : zero_initialised, object_copy
296{ 297{
297 // These variables are not changed by ->copy_to 298 // These variables are not changed by ->copy_to
298 maptile *ACC (RW, map); /* Pointer to the map in which this object is present */ 299 maptile *ACC (RW, map); /* Pointer to the map in which this object is present */
379 380
380 // recursively destroy all objects in inventory, optionally dropping them to the ground instead 381 // recursively destroy all objects in inventory, optionally dropping them to the ground instead
381 MTH void destroy_inv (bool drop_to_ground = false); 382 MTH void destroy_inv (bool drop_to_ground = false);
382 MTH object *insert (object *item); // insert into inventory 383 MTH object *insert (object *item); // insert into inventory
383 MTH void play_sound (faceidx sound) const; 384 MTH void play_sound (faceidx sound) const;
384 MTH void say_msg (const char *msg) const; 385 MTH void say_msg (const_utf8_string msg) const;
385 386
386 void do_remove (); 387 void do_remove ();
387 MTH void remove () 388 MTH void remove ()
388 { 389 {
389 if (!flag [FLAG_REMOVED]) 390 if (!flag [FLAG_REMOVED])
397 remove (); 398 remove ();
398 *this = pos; 399 *this = pos;
399 insert_at (this, this); 400 insert_at (this, this);
400 } 401 }
401 402
402 // high-level move functions, return true if successful 403 // high-level move method.
404 // object op is trying to move in direction dir.
405 // originator is typically the same as op, but
406 // can be different if originator is causing op to
407 // move (originator is pushing op)
408 // returns 0 if the object is not able to move to the
409 // desired space, 1 otherwise (in which case we also
410 // move the object accordingly. This function is
411 // very similiar to move_object.
403 int move (int dir, object *originator); 412 int move (int dir, object *originator);
404 413
405 int move (int dir) 414 int move (int dir)
406 { 415 {
407 return move (dir, this); 416 return move (dir, this);
408 } 417 }
418
419 // changes move_type to a new value - handles move_on/move_off effects
420 MTH void change_move_type (MoveType mt);
409 421
410 static bool can_merge_slow (object *op1, object *op2); 422 static bool can_merge_slow (object *op1, object *op2);
411 423
412 // this is often used in time-critical code, so optimise 424 // this is often used in time-critical code, so optimise
413 MTH static bool can_merge (object *op1, object *op2) 425 MTH static bool can_merge (object *op1, object *op2)
418 } 430 }
419 431
420 MTH void set_owner (object *owner); 432 MTH void set_owner (object *owner);
421 MTH void set_speed (float speed); 433 MTH void set_speed (float speed);
422 MTH void set_glow_radius (sint8 rad); 434 MTH void set_glow_radius (sint8 rad);
423 MTH bool change_weapon (object *ob);
424 MTH bool change_skill (object *ob); 435 MTH bool change_skill (object *ob); // deprecated?
425 436
426 MTH void open_container (object *new_container); 437 MTH void open_container (object *new_container);
427 MTH void close_container () 438 MTH void close_container ()
428 { 439 {
429 open_container (0); 440 open_container (0);
468 MTH void drain_stat (); 479 MTH void drain_stat ();
469 MTH void drain_specific_stat (int deplete_stats); 480 MTH void drain_specific_stat (int deplete_stats);
470 MTH void change_luck (int value); 481 MTH void change_luck (int value);
471 482
472 // info must hold 256 * 3 bytes currently 483 // info must hold 256 * 3 bytes currently
473 const char *debug_desc (char *info) const; 484 const_utf8_string debug_desc (char *info) const;
474 MTH const char *debug_desc () const; // uses at least 3 round-robin buffers 485 MTH const_utf8_string debug_desc () const; // uses at least 3 round-robin buffers
475 const char *flag_desc (char *desc, int len) const; 486 const_utf8_string flag_desc (char *desc, int len) const;
476 487
477 MTH bool decrease (sint32 nr = 1); // returns true if anything is left 488 MTH bool decrease (sint32 nr = 1); // returns true if anything is left
478 MTH object *split (sint32 nr = 1); // return 0 on failure 489 MTH object *split (sint32 nr = 1); // return 0 on failure
479 490
480 MTH int number_of () const 491 MTH int number_of () const
518 MTH bool is_arrow () const { return type == ARROW 529 MTH bool is_arrow () const { return type == ARROW
519 || (type == SPELL_EFFECT 530 || (type == SPELL_EFFECT
520 && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); } 531 && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); }
521 MTH bool is_range () const { return type == BOW || type == ROD || type == WAND || type == HORN; } 532 MTH bool is_range () const { return type == BOW || type == ROD || type == WAND || type == HORN; }
522 533
534 MTH bool is_dragon () const;
535
523 MTH bool has_active_speed () const { return fabs (speed) >= MIN_ACTIVE_SPEED; } 536 MTH bool has_active_speed () const { return speed >= MIN_ACTIVE_SPEED; }
524 537
525 // temporary: wether the object can be saved in a map file 538 // temporary: wether the object can be saved in a map file
526 // contr => is a player 539 // contr => is a player
527 // head => only save head of a multitile object 540 // head => only save head of a multitile object
528 // owner => can not reference owner yet 541 // owner => can not reference owner yet
616 MTH std::string long_desc (object *who = 0); // query_name . " " . describe 629 MTH std::string long_desc (object *who = 0); // query_name . " " . describe
617 MTH std::string describe_monster (object *who = 0); 630 MTH std::string describe_monster (object *who = 0);
618 MTH std::string describe_item (object *who = 0); 631 MTH std::string describe_item (object *who = 0);
619 MTH std::string describe (object *who = 0); // long description, without name 632 MTH std::string describe (object *who = 0); // long description, without name
620 633
621 MTH const char *query_weight () { return ::query_weight (this); } 634 MTH const_utf8_string query_weight () { return ::query_weight (this); }
622 MTH const char *query_name () { return ::query_name (this); } 635 MTH const_utf8_string query_name () { return ::query_name (this); }
623 MTH const char *query_short_name () { return ::query_short_name (this); } 636 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); } 637 MTH const_utf8_string query_base_name (bool plural) { return ::query_base_name (this, plural); }
625 638
626 // If this object has no extra parts but should have them, 639 // If this object has no extra parts but should have them,
627 // add them, effectively expanding heads into multipart 640 // add them, effectively expanding heads into multipart
628 // objects. This method only works on objects not inserted 641 // objects. This method only works on objects not inserted
629 // anywhere. 642 // anywhere.
646 // set the given flag on all objects in the inventory recursively 659 // set the given flag on all objects in the inventory recursively
647 MTH void set_flag_inv (int flag, int value = 1); 660 MTH void set_flag_inv (int flag, int value = 1);
648 661
649 void enter_exit (object *exit);//Perl 662 void enter_exit (object *exit);//Perl
650 MTH void enter_map (maptile *newmap, int x, int y); 663 MTH void enter_map (maptile *newmap, int x, int y);
651 void player_goto (const char *path, int x, int y); // only for players 664 void player_goto (const_utf8_string path, int x, int y); // only for players
665 MTH bool apply (object *ob, int aflags = AP_APPLY); // ob may be 0
652 666
653 // returns the mapspace this object is in 667 // returns the mapspace this object is in
654 mapspace &ms () const; 668 mapspace &ms () const;
655 669
656 // fully recursive iterator 670 // fully recursive iterator
707 return weight + carrying; 721 return weight + carrying;
708 } 722 }
709 723
710 MTH struct region *region () const; 724 MTH struct region *region () const;
711 725
712 void statusmsg (const char *msg, int color = NDI_BLACK); 726 void statusmsg (const_utf8_string msg, int color = NDI_BLACK);
713 void failmsg (const char *msg, int color = NDI_RED); 727 void failmsg (const_utf8_string msg, int color = NDI_RED);
714 728
715 const char *query_inventory (object *who = 0, const char *indent = ""); 729 const_utf8_string query_inventory (object *who = 0, const_utf8_string indent = "");
716 730
717 MTH const_octet_string ref () const; // creates and returns a consistent persistent object reference 731 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 732 static object *deref (const_octet_string ref); // returns the object from the generated refreence, if possible
719 733
720 // make some noise with given item into direction dir, 734 // make some noise with given item into direction dir,
733 * range from 0 through 7. 747 * range from 0 through 7.
734 */ 748 */
735 MTH int anim_frames () const { return anim ().num_animations; } 749 MTH int anim_frames () const { return anim ().num_animations; }
736 MTH int anim_facings () const { return anim ().facings; } 750 MTH int anim_facings () const { return anim ().facings; }
737 751
738 MTH char *as_string (); 752 MTH utf8_string as_string ();
739 753
740protected: 754protected:
741 void link (); 755 void link ();
742 void unlink (); 756 void unlink ();
743 757
768 return ob; 782 return ob;
769} 783}
770 784
771//+GPL 785//+GPL
772 786
773object *find_skill_by_name_fuzzy (object *who, const char *name); 787object *find_skill_by_name_fuzzy (object *who, const_utf8_string name);
774object *find_skill_by_name (object *who, shstr_cmp sh); 788object *find_skill_by_name (object *who, shstr_cmp sh);
775object *find_skill_by_number (object *who, int skillno); 789object *find_skill_by_number (object *who, int skillno);
776 790
777/* 791/*
778 * The archetype structure is a set of rules on how to generate and manipulate 792 * The archetype structure is a set of rules on how to generate and manipulate
789struct archetype : object 803struct archetype : object
790{ 804{
791 static arch_ptr empty; // the empty_archetype 805 static arch_ptr empty; // the empty_archetype
792 MTH static void gc (); 806 MTH static void gc ();
793 807
794 archetype (const char *name); 808 archetype (const_utf8_string name);
795 ~archetype (); 809 ~archetype ();
796 void gather_callbacks (AV *&callbacks, event_type event) const; 810 void gather_callbacks (AV *&callbacks, event_type event) const;
797 811
798 MTH static archetype *find (const_utf8_string name); 812 MTH static archetype *find (const_utf8_string name);
799 813
800 MTH void link (); 814 MTH void link ();
801 MTH void unlink (); 815 MTH void unlink ();
802 816
803 MTH static object *get (const char *name); // (find() || singularity)->instance() 817 MTH static object *get (const_utf8_string name); // (find() || singularity)->instance()
804 MTH object *instance (); 818 MTH object *instance ();
805 819
806 MTH void post_load_check (); // do some adjustments after parsing 820 MTH void post_load_check (); // do some adjustments after parsing
807 821
808 object_vector_index ACC (RW, archid); // index in archvector 822 object_vector_index ACC (RW, archid); // index in archvector
809 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */ 823 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */
810 824
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...) */ 825 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 826
814 // support for archetype loading 827 // support for archetype loading
815 static archetype *read (object_thawer &f); 828 static archetype *read (object_thawer &f);
816 MTH static void commit_load (); // commit any objects loaded, resolves cyclic dependencies and more 829 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 */ 830 static void postpone_arch_ref (arch_ptr &ref, const_utf8_string other_arch); /* postpone other_arch reference */
818}; 831};
819 832
820// compatbiility, remove once replaced by ->instance 833// returns whether the object is a dragon player, which are often specialcased
821inline object * 834inline bool
822arch_to_object (archetype *at) 835object::is_dragon () const
823{ 836{
824 return at->instance (); 837 return arch->race == shstr_dragon && is_player ();
825} 838}
826 839
827inline void 840inline void
828object_freezer::put (keyword k, archetype *v) 841object_freezer::put (const keyword_string k, archetype *v)
829{ 842{
830 put (k, v ? &v->archname : (const char *)0); 843 if (expect_true (v))
844 put (k, v->archname);
845 else
846 put (k);
831} 847}
832 848
833typedef object_vector<object, &object::index > objectvec; 849typedef object_vector<object, &object::index > objectvec;
834typedef object_vector<object, &object::active> activevec; 850typedef object_vector<object, &object::active> activevec;
835typedef object_vector<archetype, &archetype::archid> archvec; 851typedef object_vector<archetype, &archetype::archid> archvec;

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines