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.262 by root, Mon Oct 1 01:43:39 2012 UTC vs.
Revision 1.276 by root, Wed Dec 5 19:03:26 2018 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 (©) 2018 Marc Alexander Lehmann / the Deliantra team
4 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 5 * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team 6 * Copyright (©) 2001 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992 Frank Tore Johansen 7 * Copyright (©) 1992 Frank Tore Johansen
7 * 8 *
8 * Deliantra is free software: you can redistribute it and/or modify it under 9 * 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 10 * 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 11 * Free Software Foundation, either version 3 of the License, or (at your
11 * option) any later version. 12 * option) any later version.
12 * 13 *
13 * This program is distributed in the hope that it will be useful, 14 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of 15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details. 17 * GNU General Public License for more details.
17 * 18 *
18 * You should have received a copy of the Affero GNU General Public License 19 * You should have received a copy of the Affero GNU General Public License
19 * and the GNU General Public License along with this program. If not, see 20 * and the GNU General Public License along with this program. If not, see
20 * <http://www.gnu.org/licenses/>. 21 * <http://www.gnu.org/licenses/>.
21 * 22 *
22 * The authors can be reached via e-mail to <support@deliantra.net> 23 * The authors can be reached via e-mail to <support@deliantra.net>
23 */ 24 */
24 25
25#ifndef OBJECT_H 26#ifndef OBJECT_H
26#define OBJECT_H 27#define OBJECT_H
294 295
295 // 8 free bits 296 // 8 free bits
296 297
297 //float ACC (RW, expmul) = 1.0; /* needed experience = (calc_exp*expmul) - means some */ 298 //float ACC (RW, expmul) = 1.0; /* needed experience = (calc_exp*expmul) - means some */
298 // /* races/classes can need less/more exp to gain levels */ 299 // /* races/classes can need less/more exp to gain levels */
299 static const float expmul = 1.0;//D 300 constexpr static const float expmul = 1.0;//D
300 float ACC (RW, move_slow_penalty); /* How much this slows down the object */ 301 float ACC (RW, move_slow_penalty); /* How much this slows down the object */
301 302
302 /* Following are values used by any object */ 303 /* Following are values used by any object */
303 /* this objects turns into or what this object creates */ 304 /* this objects turns into or what this object creates */
304 treasurelist *ACC (RW, randomitems); /* Items to be generated */ 305 treasurelist *ACC (RW, randomitems); /* Items to be generated */
435 // object op is trying to move in direction dir. 436 // object op is trying to move in direction dir.
436 // originator is typically the same as op, but 437 // originator is typically the same as op, but
437 // can be different if originator is causing op to 438 // can be different if originator is causing op to
438 // move (originator is pushing op) 439 // move (originator is pushing op)
439 // returns 0 if the object is not able to move to the 440 // returns 0 if the object is not able to move to the
440 // desired space, 1 otherwise (in which case we also 441 // desired space, 1 otherwise (in which case we also
441 // move the object accordingly. This function is 442 // move the object accordingly. This function is
442 // very similiar to move_object. 443 // very similiar to move_object.
443 int move (int dir, object *originator); 444 int move (int dir, object *originator);
444 445
445 int move (int dir) 446 int move (int dir)
481 // strangely enough, using ?: here causes code to inflate 482 // strangely enough, using ?: here causes code to inflate
482 return type == CONTAINER 483 return type == CONTAINER
483 && ((env && env->container_ () == this) 484 && ((env && env->container_ () == this)
484 || (!env && flag [FLAG_APPLIED])); 485 || (!env && flag [FLAG_APPLIED]));
485 } 486 }
487
488 MTH object *find_spell (const_utf8_string prefix) const;
486 489
487 MTH object *force_find (shstr_tmp name); 490 MTH object *force_find (shstr_tmp name);
488 MTH void force_set_timer (int duration); 491 MTH void force_set_timer (int duration);
489 MTH object *force_add (shstr_tmp name, int duration = 0); 492 MTH object *force_add (shstr_tmp name, int duration = 0);
490 493
521 MTH int number_of () const 524 MTH int number_of () const
522 { 525 {
523 return nrof ? nrof : 1; 526 return nrof ? nrof : 1;
524 } 527 }
525 528
526 MTH sint32 total_weight () const 529 MTH weight_t total_weight () const
527 { 530 {
528 return (weight + carrying) * number_of (); 531 return sint64 (weight + carrying) * number_of ();
529 } 532 }
530 533
531 MTH void update_weight (); 534 MTH void update_weight ();
532 535
533 // return the dominant material of this item, always return something 536 // return the dominant material of this item, always return something
535 { 538 {
536 return material; 539 return material;
537 } 540 }
538 541
539 // return the volume of this object in cm³ 542 // return the volume of this object in cm³
540 MTH uint64 volume () const 543 MTH volume_t volume () const
541 { 544 {
542 return (uint64)total_weight () 545 return (volume_t)total_weight ()
543 * 1024 // 1000 actually 546 * 1024 // 1000 actually
544 * (type == CONTAINER ? 128 : 1) 547 * (type == CONTAINER ? 128 : 1)
545 / dominant_material ()->density; // ugh, division 548 / dominant_material ()->density; // ugh, division
546 } 549 }
547 550
580 583
581 static bool msg_has_dialogue (const char *msg) { return *msg == '@'; } 584 static bool msg_has_dialogue (const char *msg) { return *msg == '@'; }
582 585
583 MTH bool has_dialogue () const { return msg_has_dialogue (&msg); } 586 MTH bool has_dialogue () const { return msg_has_dialogue (&msg); }
584 587
585 /* need_identify returns true if the item should be identified. This 588 /* need_identify returns true if the item should be identified. This
586 * function really should not exist - by default, any item not identified 589 * function really should not exist - by default, any item not identified
587 * should need it. 590 * should need it.
588 */ 591 */
589 MTH bool need_identify () const; 592 MTH bool need_identify () const;
590 593
801 * range from 0 through 7. 804 * range from 0 through 7.
802 */ 805 */
803 MTH int anim_frames () const { return anim ().num_animations; } 806 MTH int anim_frames () const { return anim ().num_animations; }
804 MTH int anim_facings () const { return anim ().facings; } 807 MTH int anim_facings () const { return anim ().facings; }
805 808
809 // sets a new animation frame, if the object has animation frames,
810 // and updates the face
811 MTH void update_anim_frame (int frame);
812
806 MTH utf8_string as_string (); 813 MTH utf8_string as_string ();
807 814
808 // low-level management, statistics, ... 815 // low-level management, statistics, ...
809 static uint32_t ACC (RW, object_count); 816 static uint32_t ACC (RW, object_count);
810 static uint32_t ACC (RW, free_count); 817 static uint32_t ACC (RW, free_count);
882 MTH object *instance (); 889 MTH object *instance ();
883 890
884 MTH void post_load_check (); // do some adjustments after parsing 891 MTH void post_load_check (); // do some adjustments after parsing
885 892
886 object_vector_index ACC (RW, archid); // index in archvector 893 object_vector_index ACC (RW, archid); // index in archvector
887 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */ 894 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */
888 895
889 sint8 ACC (RW, max_x); /* extents, compared to the head (min_x, min_y should be zero, but aren't...) */ 896 sint8 ACC (RW, max_x); /* extents, compared to the head (min_x, min_y should be zero, but aren't...) */
890 897
891 // support for archetype loading 898 // support for archetype loading
892 static archetype *read (object_thawer &f); 899 static archetype *read (object_thawer &f);
905} 912}
906 913
907inline void 914inline void
908object_freezer::put (const keyword_string k, archetype *v) 915object_freezer::put (const keyword_string k, archetype *v)
909{ 916{
910 if (expect_true (v)) 917 if (ecb_expect_true (v))
911 put (k, v->archname); 918 put (k, v->archname);
912 else 919 else
913 put (k); 920 put (k);
914} 921}
915 922
924// "safely" iterate over inv in a way such that the current item is removable 931// "safely" iterate over inv in a way such that the current item is removable
925// quite horrible, that's why its hidden in some macro 932// quite horrible, that's why its hidden in some macro
926#define for_inv_removable(op,var) \ 933#define for_inv_removable(op,var) \
927 for (object *var, *next_ = (op)->inv; (var = next_), var && (next_ = var->below), var; ) 934 for (object *var, *next_ = (op)->inv; (var = next_), var && (next_ = var->below), var; )
928 935
929#define for_all_objects(var) \ 936#define for_all_objects(var) \
930 for (unsigned _i = 0; _i < objects.size (); ++_i) \ 937 for (unsigned _i = 0; _i < objects.size (); ++_i) \
931 statementvar (object *, var, objects [_i]) 938 statementvar (object *, var, objects [_i])
932 939
933#define for_all_actives(var) \ 940#define for_all_actives(var) \
934 for (unsigned _i = 0; _i < actives.size (); ++_i) \ 941 for (unsigned _i = 0; _i < actives.size (); ++_i) \
935 statementvar (object *, var, actives [_i]) 942 statementvar (object *, var, actives [_i])
936 943
937#define for_all_archetypes(var) \ 944#define for_all_archetypes(var) \
938 for (unsigned _i = 0; _i < archetypes.size (); ++_i) \ 945 for (unsigned _i = 0; _i < archetypes.size (); ++_i) \
939 statementvar (archetype *, var, archetypes [_i]) 946 statementvar (archetype *, var, archetypes [_i])
940 947
941//+GPL 948//+GPL
942 949
943/* Used by update_object to know if the object being passed is 950/* Used by update_object to know if the object being passed is
944 * being added or removed. 951 * being added or removed.
945 */ 952 */
946#define UP_OBJ_INSERT 1 953#define UP_OBJ_INSERT 1 // object was inserted
947#define UP_OBJ_REMOVE 2 954#define UP_OBJ_REMOVE 2 // object was removed
948#define UP_OBJ_CHANGE 3 955#define UP_OBJ_CHANGE 3 // object has changed in some unspecified way
949#define UP_OBJ_FACE 4 /* Only thing that changed was the face */ 956#define UP_OBJ_FACE 4 // only thing that changed was the face
950 957
951/* These are flags passed to insert_ob_in_map and 958/* These are flags passed to insert_ob_in_map and
952 * insert_ob_in_ob. Note that all flags may not be meaningful 959 * insert_ob_in_ob. Note that all flags may not be meaningful
953 * for both functions. 960 * for both functions.
954 * Most are fairly explanatory: 961 * Most are fairly explanatory:
955 * INS_NO_MERGE: don't try to merge inserted object with ones alrady 962 * INS_NO_MERGE: don't try to merge inserted object with ones alrady
956 * on space. 963 * on space.
957 * INS_ABOVE_FLOOR_ONLY: Put object immediatly above the floor. 964 * INS_ABOVE_FLOOR_ONLY: Put object immediatly above the floor.
958 * INS_NO_WALK_ON: Don't call check_walk_on against the 965 * INS_NO_WALK_ON: Don't call check_walk_on against the
959 * originator - saves cpu time if you know the inserted object 966 * originator - saves cpu time if you know the inserted object
960 * is not meaningful in terms of having an effect. 967 * is not meaningful in terms of having an effect.
961 * INS_ON_TOP: Always put object on top. Generally only needed when loading 968 * INS_ON_TOP: Always put object on top. Generally only needed when loading
962 * files from disk and ordering needs to be preserved. 969 * files from disk and ordering needs to be preserved.
963 * INS_BELOW_ORIGINATOR: Insert new object immediately below originator - 970 * INS_BELOW_ORIGINATOR: Insert new object immediately below originator -
964 * Use for treasure chests so the new object is the highest thing 971 * Use for treasure chests so the new object is the highest thing
965 * beneath the player, but not actually above it. Note - the 972 * beneath the player, but not actually above it. Note - the
966 * map and x,y coordinates for the object to be inserted must 973 * map and x,y coordinates for the object to be inserted must
967 * match the originator. 974 * match the originator.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines