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.251 by root, Wed Apr 28 11:19:09 2010 UTC vs.
Revision 1.275 by root, Sun Nov 18 16:32:27 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 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
33typedef int tag_t; 34typedef int tag_t;
34 35
35// also see common/item.C 36// also see common/item.C
36enum 37enum
37{ 38{
38 body_skill, 39# define def(name, use, nonuse) body_ ## name,
39 body_combat, 40# include "slotinc.h"
40 body_range, 41# undef def
41 body_shield,
42 body_arm,
43 body_torso,
44 body_head,
45 body_neck,
46 body_finger,
47 body_shoulder,
48 body_foot,
49 body_hand,
50 body_wrist,
51 body_waist,
52 NUM_BODY_LOCATIONS 42 NUM_BODY_LOCATIONS
53}; 43};
54 44
55/* See common/item.c */ 45/* See common/item.c */
56 46
57typedef struct Body_Locations 47struct Body_Locations
58{ 48{
49 const char *name; /* Short name/identifier */
59 keyword save_name; /* Name used to load/save it to disk */ 50 keyword kw; /* Name used to load/save it to disk */
60 const char *use_name; /* Name used when describing an item we can use */ 51 const char *use_name; /* Name used when describing an item we can use */
61 const char *nonuse_name; /* Name to describe objects we can't use */ 52 const char *nonuse_name; /* Name to describe objects we can't use */
62} Body_Locations; 53};
63 54
64extern Body_Locations body_locations[NUM_BODY_LOCATIONS]; 55extern Body_Locations body_locations[NUM_BODY_LOCATIONS];
56
57// for each set of directions (1 == up, 2 == right, 4 == down, 8 == left)
58// contains the wall suffix (0, 1_3, 1_4 and so on).
59extern const char *wall_suffix[16];
65 60
66#define NUM_COINS 4 /* number of coin types */ 61#define NUM_COINS 4 /* number of coin types */
67extern const char *const coins[NUM_COINS + 1]; 62extern const char *const coins[NUM_COINS + 1];
68 63
69// restart server when object_count reaches this value 64// restart server when object_count reaches this value
79 * accessing the list directly. 74 * accessing the list directly.
80 * Exception is if you want to walk this list for some reason. 75 * Exception is if you want to walk this list for some reason.
81 */ 76 */
82struct key_value : slice_allocated 77struct key_value : slice_allocated
83{ 78{
84 key_value *next; 79 key_value *next; // must be first element
85 shstr key, value; 80 shstr key, value;
81};
82
83// "crossfires version of a perl hash."
84struct key_values
85{
86 key_value *first; // must be first element
87
88 bool empty() const
89 {
90 return !first;
91 }
92
93 void clear ();
94 shstr_tmp get (shstr_tmp key) const;
95 void del (shstr_tmp key);
96 void set (shstr_tmp key, shstr_tmp value);
97
98 void add (shstr_tmp key, shstr_tmp value); // liek set, but doesn't check for duplicates
99 void reverse (); // reverses the ordering, to be used after loading an object
100 key_values &operator =(const key_values &kv);
101
102 // custom extra fields management
103 struct access_proxy
104 {
105 key_values &kv;
106 shstr_tmp key;
107
108 access_proxy (key_values &kv, shstr_tmp key)
109 : kv (kv), key (key)
110 {
111 }
112
113 const access_proxy &operator =(shstr_tmp value) const
114 {
115 kv.set (key, value);
116 return *this;
117 }
118
119 operator const shstr_tmp () const { return kv.get (key); }
120 operator const char *() const { return kv.get (key); }
121
122 private:
123 void operator =(int);
124 };
125
126 const access_proxy operator [](shstr_tmp key)
127 {
128 return access_proxy (*this, key);
129 }
86}; 130};
87 131
88//-GPL 132//-GPL
89 133
90struct UUID 134struct UUID
251 295
252 // 8 free bits 296 // 8 free bits
253 297
254 //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 */
255 // /* races/classes can need less/more exp to gain levels */ 299 // /* races/classes can need less/more exp to gain levels */
256 static const float expmul = 1.0;//D 300 constexpr static const float expmul = 1.0;//D
257 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 */
258 302
259 /* Following are values used by any object */ 303 /* Following are values used by any object */
260 /* this objects turns into or what this object creates */ 304 /* this objects turns into or what this object creates */
261 treasurelist *ACC (RW, randomitems); /* Items to be generated */ 305 treasurelist *ACC (RW, randomitems); /* Items to be generated */
328 object *ACC (RW, env); /* Pointer to the object which is the environment. 372 object *ACC (RW, env); /* Pointer to the object which is the environment.
329 * This is typically the container that the object is in. 373 * This is typically the container that the object is in.
330 */ 374 */
331 object *ACC (RW, more); /* Pointer to the rest of a large body of objects */ 375 object *ACC (RW, more); /* Pointer to the rest of a large body of objects */
332 object *head; /* Points to the main object of a large body */ // NO ACC, perl semantics are different 376 object *head; /* Points to the main object of a large body */ // NO ACC, perl semantics are different
333 key_value *key_values; /* Fields not explictly known by the loader. */
334 377
335 MTH void set_flag (int flagnum) 378 MTH void set_flag (int flagnum)
336 { 379 {
337 flag [flagnum] = true; 380 flag [flagnum] = true;
338 } 381 }
340 MTH void clr_flag (int flagnum) 383 MTH void clr_flag (int flagnum)
341 { 384 {
342 flag [flagnum] = false; 385 flag [flagnum] = false;
343 } 386 }
344 387
345 // privates / perl 388 // extra key value pairs
346 shstr_tmp kv_get (shstr_tmp key) const; 389 key_values kv;
347 void kv_del (shstr_tmp key);
348 void kv_set (shstr_tmp key, shstr_tmp value);
349 390
350//-GPL 391//-GPL
351
352 // custom extra fields management
353 struct key_value_access_proxy
354 {
355 object &ob;
356 shstr_tmp key;
357
358 key_value_access_proxy (object &ob, shstr_tmp key)
359 : ob (ob), key (key)
360 {
361 }
362
363 const key_value_access_proxy &operator =(shstr_tmp value) const
364 {
365 ob.kv_set (key, value);
366 return *this;
367 }
368
369 operator const shstr_tmp () const { return ob.kv_get (key); }
370 operator const char *() const { return ob.kv_get (key); }
371
372 private:
373 void operator =(int);
374 };
375
376 // operator [] is too annoying to use
377 const key_value_access_proxy kv (shstr_tmp key)
378 {
379 return key_value_access_proxy (*this, key);
380 }
381 392
382 bool parse_kv (object_thawer &f); // parse kv pairs, (ab-)used by archetypes, which should not exist at all 393 bool parse_kv (object_thawer &f); // parse kv pairs, (ab-)used by archetypes, which should not exist at all
383 MTH void post_load_check (); // do some adjustments after parsing 394 MTH void post_load_check (); // do some adjustments after parsing
384 static object *read (object_thawer &f, maptile *map = 0); // map argument due to toal design bogosity, must go. 395 static object *read (object_thawer &f, maptile *map = 0); // map argument due to toal design bogosity, must go.
385 bool write (object_freezer &f); 396 bool write (object_freezer &f);
425 // object op is trying to move in direction dir. 436 // object op is trying to move in direction dir.
426 // originator is typically the same as op, but 437 // originator is typically the same as op, but
427 // can be different if originator is causing op to 438 // can be different if originator is causing op to
428 // move (originator is pushing op) 439 // move (originator is pushing op)
429 // 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
430 // desired space, 1 otherwise (in which case we also 441 // desired space, 1 otherwise (in which case we also
431 // move the object accordingly. This function is 442 // move the object accordingly. This function is
432 // very similiar to move_object. 443 // very similiar to move_object.
433 int move (int dir, object *originator); 444 int move (int dir, object *originator);
434 445
435 int move (int dir) 446 int move (int dir)
448 return op1->value == op2->value 459 return op1->value == op2->value
449 && op1->name == op2->name 460 && op1->name == op2->name
450 && can_merge_slow (op1, op2); 461 && can_merge_slow (op1, op2);
451 } 462 }
452 463
453 MTH void set_owner (object *owner); 464 MTH void set_owner (object_ornull *owner);
454 MTH void set_speed (float speed); 465 MTH void set_speed (float speed);
455 MTH void set_glow_radius (sint8 rad); 466 MTH void set_glow_radius (sint8 rad);
456 467
457 MTH void open_container (object *new_container); 468 MTH void open_container (object *new_container);
458 MTH void close_container () 469 MTH void close_container ()
471 // strangely enough, using ?: here causes code to inflate 482 // strangely enough, using ?: here causes code to inflate
472 return type == CONTAINER 483 return type == CONTAINER
473 && ((env && env->container_ () == this) 484 && ((env && env->container_ () == this)
474 || (!env && flag [FLAG_APPLIED])); 485 || (!env && flag [FLAG_APPLIED]));
475 } 486 }
487
488 MTH object *find_spell (const_utf8_string prefix) const;
476 489
477 MTH object *force_find (shstr_tmp name); 490 MTH object *force_find (shstr_tmp name);
478 MTH void force_set_timer (int duration); 491 MTH void force_set_timer (int duration);
479 MTH object *force_add (shstr_tmp name, int duration = 0); 492 MTH object *force_add (shstr_tmp name, int duration = 0);
480 493
511 MTH int number_of () const 524 MTH int number_of () const
512 { 525 {
513 return nrof ? nrof : 1; 526 return nrof ? nrof : 1;
514 } 527 }
515 528
516 MTH sint32 total_weight () const 529 MTH weight_t total_weight () const
517 { 530 {
518 return (weight + carrying) * number_of (); 531 return sint64 (weight + carrying) * number_of ();
519 } 532 }
520 533
521 MTH void update_weight (); 534 MTH void update_weight ();
522 535
523 // return the dominant material of this item, always return something 536 // return the dominant material of this item, always return something
525 { 538 {
526 return material; 539 return material;
527 } 540 }
528 541
529 // return the volume of this object in cm³ 542 // return the volume of this object in cm³
530 MTH uint64 volume () const 543 MTH volume_t volume () const
531 { 544 {
532 return (uint64)total_weight () 545 return (volume_t)total_weight ()
533 * 1024 // 1000 actually 546 * 1024 // 1000 actually
534 * (type == CONTAINER ? 128 : 1) 547 * (type == CONTAINER ? 128 : 1)
535 / dominant_material ()->density; // ugh, division 548 / dominant_material ()->density; // ugh, division
536 } 549 }
537 550
570 583
571 static bool msg_has_dialogue (const char *msg) { return *msg == '@'; } 584 static bool msg_has_dialogue (const char *msg) { return *msg == '@'; }
572 585
573 MTH bool has_dialogue () const { return msg_has_dialogue (&msg); } 586 MTH bool has_dialogue () const { return msg_has_dialogue (&msg); }
574 587
575 /* need_identify returns true if the item should be identified. This 588 /* need_identify returns true if the item should be identified. This
576 * function really should not exist - by default, any item not identified 589 * function really should not exist - by default, any item not identified
577 * should need it. 590 * should need it.
578 */ 591 */
579 MTH bool need_identify () const; 592 MTH bool need_identify () const;
580 593
691 MTH void activate (); 704 MTH void activate ();
692 MTH void deactivate (); 705 MTH void deactivate ();
693 MTH void activate_recursive (); 706 MTH void activate_recursive ();
694 MTH void deactivate_recursive (); 707 MTH void deactivate_recursive ();
695 708
709 // prefetch and activate the surrounding area
710 MTH void prefetch_surrounding_maps ();
711
696 // set the given flag on all objects in the inventory recursively 712 // set the given flag on all objects in the inventory recursively
697 MTH void set_flag_inv (int flag, int value = 1); 713 MTH void set_flag_inv (int flag, int value = 1);
698 714
699 void enter_exit (object *exit); // perl 715 void enter_exit (object *exit); // perl
700 MTH bool enter_map (maptile *newmap, int x, int y); 716 MTH bool enter_map (maptile *newmap, int x, int y);
701 void player_goto (const_utf8_string path, int x, int y); // only for players 717 void player_goto (const_utf8_string path, int x, int y); // only for players
702 MTH bool apply (object *ob, int aflags = AP_APPLY); // ob may be 0 718 MTH bool apply (object *ob, int aflags = AP_APPLY); // ob may be 0
703 719
704 MTH object *mark () const; 720 MTH object *mark () const;
721 MTH void splay_marked ();
705 722
706 // returns the mapspace this object is in 723 // returns the mapspace this object is in
707 mapspace &ms () const; 724 mapspace &ms () const;
708 725
709 // fully recursive iterator 726 // fully recursive iterator
787 * range from 0 through 7. 804 * range from 0 through 7.
788 */ 805 */
789 MTH int anim_frames () const { return anim ().num_animations; } 806 MTH int anim_frames () const { return anim ().num_animations; }
790 MTH int anim_facings () const { return anim ().facings; } 807 MTH int anim_facings () const { return anim ().facings; }
791 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
792 MTH utf8_string as_string (); 813 MTH utf8_string as_string ();
793 814
794 // low-level management, statistics, ... 815 // low-level management, statistics, ...
795 static uint32_t ACC (RW, object_count); 816 static uint32_t ACC (RW, object_count);
796 static uint32_t ACC (RW, free_count); 817 static uint32_t ACC (RW, free_count);
868 MTH object *instance (); 889 MTH object *instance ();
869 890
870 MTH void post_load_check (); // do some adjustments after parsing 891 MTH void post_load_check (); // do some adjustments after parsing
871 892
872 object_vector_index ACC (RW, archid); // index in archvector 893 object_vector_index ACC (RW, archid); // index in archvector
873 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */ 894 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */
874 895
875 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...) */
876 897
877 // support for archetype loading 898 // support for archetype loading
878 static archetype *read (object_thawer &f); 899 static archetype *read (object_thawer &f);
910// "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
911// quite horrible, that's why its hidden in some macro 932// quite horrible, that's why its hidden in some macro
912#define for_inv_removable(op,var) \ 933#define for_inv_removable(op,var) \
913 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; )
914 935
915#define for_all_objects(var) \ 936#define for_all_objects(var) \
916 for (unsigned _i = 0; _i < objects.size (); ++_i) \ 937 for (unsigned _i = 0; _i < objects.size (); ++_i) \
917 statementvar (object *, var, objects [_i]) 938 statementvar (object *, var, objects [_i])
918 939
919#define for_all_actives(var) \ 940#define for_all_actives(var) \
920 for (unsigned _i = 0; _i < actives.size (); ++_i) \ 941 for (unsigned _i = 0; _i < actives.size (); ++_i) \
921 statementvar (object *, var, actives [_i]) 942 statementvar (object *, var, actives [_i])
922 943
923#define for_all_archetypes(var) \ 944#define for_all_archetypes(var) \
924 for (unsigned _i = 0; _i < archetypes.size (); ++_i) \ 945 for (unsigned _i = 0; _i < archetypes.size (); ++_i) \
925 statementvar (archetype *, var, archetypes [_i]) 946 statementvar (archetype *, var, archetypes [_i])
926 947
927//+GPL 948//+GPL
928 949
929/* 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
930 * being added or removed. 951 * being added or removed.
931 */ 952 */
932#define UP_OBJ_INSERT 1 953#define UP_OBJ_INSERT 1 // object was inserted
933#define UP_OBJ_REMOVE 2 954#define UP_OBJ_REMOVE 2 // object was removed
934#define UP_OBJ_CHANGE 3 955#define UP_OBJ_CHANGE 3 // object has changed in some unspecified way
935#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
936 957
937/* These are flags passed to insert_ob_in_map and 958/* These are flags passed to insert_ob_in_map and
938 * 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
939 * for both functions. 960 * for both functions.
940 * Most are fairly explanatory: 961 * Most are fairly explanatory:
941 * 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
942 * on space. 963 * on space.
943 * INS_ABOVE_FLOOR_ONLY: Put object immediatly above the floor. 964 * INS_ABOVE_FLOOR_ONLY: Put object immediatly above the floor.
944 * 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
945 * originator - saves cpu time if you know the inserted object 966 * originator - saves cpu time if you know the inserted object
946 * is not meaningful in terms of having an effect. 967 * is not meaningful in terms of having an effect.
947 * 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
948 * files from disk and ordering needs to be preserved. 969 * files from disk and ordering needs to be preserved.
949 * INS_BELOW_ORIGINATOR: Insert new object immediately below originator - 970 * INS_BELOW_ORIGINATOR: Insert new object immediately below originator -
950 * 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
951 * beneath the player, but not actually above it. Note - the 972 * beneath the player, but not actually above it. Note - the
952 * 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
953 * match the originator. 974 * match the originator.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines