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 | |
291 | const char *query_weight (const object *op); |
290 | const_utf8_string query_weight (const object *op); |
292 | const char *query_short_name (const object *op); |
291 | const_utf8_string query_short_name (const object *op); |
293 | const char *query_name (const object *op); |
292 | const_utf8_string query_name (const object *op); |
294 | const char *query_base_name (const object *op, int plural); |
293 | const_utf8_string query_base_name (const object *op, int plural); |
295 | |
294 | |
296 | struct object : zero_initialised, object_copy |
295 | struct 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]) |
… | |
… | |
469 | MTH void drain_stat (); |
468 | MTH void drain_stat (); |
470 | MTH void drain_specific_stat (int deplete_stats); |
469 | MTH void drain_specific_stat (int deplete_stats); |
471 | MTH void change_luck (int value); |
470 | MTH void change_luck (int value); |
472 | |
471 | |
473 | // info must hold 256 * 3 bytes currently |
472 | // info must hold 256 * 3 bytes currently |
474 | const char *debug_desc (char *info) const; |
473 | const_utf8_string debug_desc (char *info) const; |
475 | 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 |
476 | const char *flag_desc (char *desc, int len) const; |
475 | const_utf8_string flag_desc (char *desc, int len) const; |
477 | |
476 | |
478 | 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 |
479 | MTH object *split (sint32 nr = 1); // return 0 on failure |
478 | MTH object *split (sint32 nr = 1); // return 0 on failure |
480 | |
479 | |
481 | MTH int number_of () const |
480 | MTH int number_of () const |
… | |
… | |
489 | } |
488 | } |
490 | |
489 | |
491 | MTH void update_weight (); |
490 | MTH void update_weight (); |
492 | |
491 | |
493 | // return the dominant material of this item, always return something |
492 | // return the dominant material of this item, always return something |
494 | const materialtype_t *dominant_material () const; |
493 | const materialtype_t *dominant_material () const |
|
|
494 | { |
|
|
495 | return material; |
|
|
496 | } |
495 | |
497 | |
496 | // return the volume of this object in cm³ |
498 | // return the volume of this object in cm³ |
497 | MTH uint64 volume () const |
499 | MTH uint64 volume () const |
498 | { |
500 | { |
499 | return (uint64)total_weight () |
501 | return (uint64)total_weight () |
500 | * 1000 |
502 | * 1024 // 1000 actually |
501 | * (type == CONTAINER ? 1000 : 1) |
503 | * (type == CONTAINER ? 128 : 1) |
502 | / dominant_material ()->density; |
504 | / dominant_material ()->density; // ugh, division |
503 | } |
505 | } |
504 | |
506 | |
505 | MTH bool is_arch () const { return this == (const object *)(const archetype *)arch; } |
507 | MTH bool is_arch () const { return this == (const object *)(const archetype *)arch; } |
506 | |
508 | |
507 | MTH bool is_wiz () const { return flag [FLAG_WIZ]; } |
509 | MTH bool is_wiz () const { return flag [FLAG_WIZ]; } |
… | |
… | |
516 | MTH bool is_arrow () const { return type == ARROW |
518 | MTH bool is_arrow () const { return type == ARROW |
517 | || (type == SPELL_EFFECT |
519 | || (type == SPELL_EFFECT |
518 | && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); } |
520 | && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); } |
519 | 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; } |
520 | |
522 | |
|
|
523 | MTH bool is_dragon () const; |
|
|
524 | |
521 | MTH bool has_active_speed () const { return fabs (speed) >= MIN_ACTIVE_SPEED; } |
525 | MTH bool has_active_speed () const { return speed >= MIN_ACTIVE_SPEED; } |
522 | |
526 | |
523 | // temporary: wether the object can be saved in a map file |
527 | // temporary: wether the object can be saved in a map file |
524 | // contr => is a player |
528 | // contr => is a player |
525 | // head => only save head of a multitile object |
529 | // head => only save head of a multitile object |
526 | // owner => can not reference owner yet |
530 | // owner => can not reference owner yet |
… | |
… | |
614 | MTH std::string long_desc (object *who = 0); // query_name . " " . describe |
618 | MTH std::string long_desc (object *who = 0); // query_name . " " . describe |
615 | MTH std::string describe_monster (object *who = 0); |
619 | MTH std::string describe_monster (object *who = 0); |
616 | MTH std::string describe_item (object *who = 0); |
620 | MTH std::string describe_item (object *who = 0); |
617 | MTH std::string describe (object *who = 0); // long description, without name |
621 | MTH std::string describe (object *who = 0); // long description, without name |
618 | |
622 | |
619 | MTH const char *query_weight () { return ::query_weight (this); } |
623 | MTH const_utf8_string query_weight () { return ::query_weight (this); } |
620 | MTH const char *query_name () { return ::query_name (this); } |
624 | MTH const_utf8_string query_name () { return ::query_name (this); } |
621 | MTH const char *query_short_name () { return ::query_short_name (this); } |
625 | 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); } |
626 | MTH const_utf8_string query_base_name (bool plural) { return ::query_base_name (this, plural); } |
623 | |
627 | |
624 | // If this object has no extra parts but should have them, |
628 | // If this object has no extra parts but should have them, |
625 | // add them, effectively expanding heads into multipart |
629 | // add them, effectively expanding heads into multipart |
626 | // objects. This method only works on objects not inserted |
630 | // objects. This method only works on objects not inserted |
627 | // anywhere. |
631 | // anywhere. |
… | |
… | |
644 | // set the given flag on all objects in the inventory recursively |
648 | // set the given flag on all objects in the inventory recursively |
645 | MTH void set_flag_inv (int flag, int value = 1); |
649 | MTH void set_flag_inv (int flag, int value = 1); |
646 | |
650 | |
647 | void enter_exit (object *exit);//Perl |
651 | void enter_exit (object *exit);//Perl |
648 | MTH void enter_map (maptile *newmap, int x, int y); |
652 | MTH void enter_map (maptile *newmap, int x, int y); |
649 | 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 |
650 | |
654 | |
651 | // returns the mapspace this object is in |
655 | // returns the mapspace this object is in |
652 | mapspace &ms () const; |
656 | mapspace &ms () const; |
653 | |
657 | |
654 | // fully recursive iterator |
658 | // fully recursive iterator |
… | |
… | |
705 | return weight + carrying; |
709 | return weight + carrying; |
706 | } |
710 | } |
707 | |
711 | |
708 | MTH struct region *region () const; |
712 | MTH struct region *region () const; |
709 | |
713 | |
710 | void statusmsg (const char *msg, int color = NDI_BLACK); |
714 | void statusmsg (const_utf8_string msg, int color = NDI_BLACK); |
711 | void failmsg (const char *msg, int color = NDI_RED); |
715 | void failmsg (const_utf8_string msg, int color = NDI_RED); |
712 | |
716 | |
713 | const char *query_inventory (object *who = 0, const char *indent = ""); |
717 | const_utf8_string query_inventory (object *who = 0, const_utf8_string indent = ""); |
714 | |
718 | |
715 | 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 |
716 | 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 |
717 | |
721 | |
718 | // make some noise with given item into direction dir, |
722 | // make some noise with given item into direction dir, |
… | |
… | |
731 | * range from 0 through 7. |
735 | * range from 0 through 7. |
732 | */ |
736 | */ |
733 | MTH int anim_frames () const { return anim ().num_animations; } |
737 | MTH int anim_frames () const { return anim ().num_animations; } |
734 | MTH int anim_facings () const { return anim ().facings; } |
738 | MTH int anim_facings () const { return anim ().facings; } |
735 | |
739 | |
736 | MTH char *as_string (); |
740 | MTH utf8_string as_string (); |
737 | |
741 | |
738 | protected: |
742 | protected: |
739 | void link (); |
743 | void link (); |
740 | void unlink (); |
744 | void unlink (); |
741 | |
745 | |
… | |
… | |
766 | return ob; |
770 | return ob; |
767 | } |
771 | } |
768 | |
772 | |
769 | //+GPL |
773 | //+GPL |
770 | |
774 | |
771 | object *find_skill_by_name_fuzzy (object *who, const char *name); |
775 | object *find_skill_by_name_fuzzy (object *who, const_utf8_string name); |
772 | object *find_skill_by_name (object *who, shstr_cmp sh); |
776 | object *find_skill_by_name (object *who, shstr_cmp sh); |
773 | object *find_skill_by_number (object *who, int skillno); |
777 | object *find_skill_by_number (object *who, int skillno); |
774 | |
778 | |
775 | /* |
779 | /* |
776 | * 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 |
… | |
… | |
787 | struct archetype : object |
791 | struct archetype : object |
788 | { |
792 | { |
789 | static arch_ptr empty; // the empty_archetype |
793 | static arch_ptr empty; // the empty_archetype |
790 | MTH static void gc (); |
794 | MTH static void gc (); |
791 | |
795 | |
792 | archetype (const char *name); |
796 | archetype (const_utf8_string name); |
793 | ~archetype (); |
797 | ~archetype (); |
794 | void gather_callbacks (AV *&callbacks, event_type event) const; |
798 | void gather_callbacks (AV *&callbacks, event_type event) const; |
795 | |
799 | |
796 | MTH static archetype *find (const_utf8_string name); |
800 | MTH static archetype *find (const_utf8_string name); |
797 | |
801 | |
798 | MTH void link (); |
802 | MTH void link (); |
799 | MTH void unlink (); |
803 | MTH void unlink (); |
800 | |
804 | |
801 | MTH static object *get (const char *name); // (find() || singularity)->instance() |
805 | MTH static object *get (const_utf8_string name); // (find() || singularity)->instance() |
802 | MTH object *instance (); |
806 | MTH object *instance (); |
803 | |
807 | |
804 | MTH void post_load_check (); // do some adjustments after parsing |
808 | MTH void post_load_check (); // do some adjustments after parsing |
805 | |
809 | |
806 | object_vector_index ACC (RW, archid); // index in archvector |
810 | object_vector_index ACC (RW, archid); // index in archvector |
… | |
… | |
813 | static archetype *read (object_thawer &f); |
817 | static archetype *read (object_thawer &f); |
814 | 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 |
815 | 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 */ |
816 | }; |
820 | }; |
817 | |
821 | |
818 | // compatbiility, remove once replaced by ->instance |
822 | // returns whether the objetc is a dragon player, which are often specialcased |
819 | inline object * |
823 | inline bool |
820 | arch_to_object (archetype *at) |
824 | object::is_dragon () const |
821 | { |
825 | { |
822 | return at->instance (); |
826 | return arch->race == shstr_dragon && is_player (); |
823 | } |
827 | } |
824 | |
828 | |
825 | inline void |
829 | inline void |
826 | object_freezer::put (keyword k, archetype *v) |
830 | object_freezer::put (const keyword_string k, archetype *v) |
827 | { |
831 | { |
828 | put (k, v ? &v->archname : (const char *)0); |
832 | if (expect_true (v)) |
|
|
833 | put (k, v->archname); |
|
|
834 | else |
|
|
835 | put (k); |
829 | } |
836 | } |
830 | |
837 | |
831 | typedef object_vector<object, &object::index > objectvec; |
838 | typedef object_vector<object, &object::index > objectvec; |
832 | typedef object_vector<object, &object::active> activevec; |
839 | typedef object_vector<object, &object::active> activevec; |
833 | typedef object_vector<archetype, &archetype::archid> archvec; |
840 | typedef object_vector<archetype, &archetype::archid> archvec; |