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.252 by root, Sun May 9 21:29:20 2010 UTC vs.
Revision 1.273 by root, Sat Nov 17 23:33:18 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
136{ /* Used to link together several object links */ 180{ /* Used to link together several object links */
137 struct oblnk *link; 181 struct oblnk *link;
138 struct oblinkpt *next; 182 struct oblinkpt *next;
139 shstr id; /* Used as connected value in buttons/gates */ 183 shstr id; /* Used as connected value in buttons/gates */
140} oblinkpt; 184} oblinkpt;
185
186// temporary hack to find the culprit who corrupts face numbers. maybe. hopefully.
187struct faceidx_debug
188{
189 faceidx x;
190
191 operator faceidx () const
192 {
193 return x;
194 }
195
196 faceidx operator =(faceidx i)
197 {
198 if (ecb_expect_false (i >= faces.size ()))
199 {
200 fork_abort ("illegal faceidx assignment");
201 i = blank_face;
202 }
203
204 return x = i;
205 }
206};
207
208#if CFPERL
209static inline void sv_to (SV *sv, faceidx_debug &v) { v = SvIV (sv); }
210#endif
141 211
142INTERFACE_CLASS (object) 212INTERFACE_CLASS (object)
143// these are being copied 213// these are being copied
144struct object_copy : attachable 214struct object_copy : attachable
145{ 215{
209 sint8 ACC (RW, glow_radius); /* indicates the glow radius of the object */ 279 sint8 ACC (RW, glow_radius); /* indicates the glow radius of the object */
210 uint8 ACC (RW, weapontype); /* type of weapon */ 280 uint8 ACC (RW, weapontype); /* type of weapon */
211 281
212 body_slot slot [NUM_BODY_LOCATIONS]; 282 body_slot slot [NUM_BODY_LOCATIONS];
213 283
214 faceidx ACC (RW, face); /* the graphical face */ 284 faceidx_debug ACC (RW, face); /* the graphical face */
215 285
216 faceidx ACC (RW, sound); /* the sound face */ 286 faceidx ACC (RW, sound); /* the sound face */
217 faceidx ACC (RW, sound_destroy); /* played on destroy */ 287 faceidx ACC (RW, sound_destroy); /* played on destroy */
218 288
219 sint32 ACC (RW, weight); /* Attributes of the object */ 289 sint32 ACC (RW, weight); /* Attributes of the object */
251 321
252 // 8 free bits 322 // 8 free bits
253 323
254 //float ACC (RW, expmul) = 1.0; /* needed experience = (calc_exp*expmul) - means some */ 324 //float ACC (RW, expmul) = 1.0; /* needed experience = (calc_exp*expmul) - means some */
255 // /* races/classes can need less/more exp to gain levels */ 325 // /* races/classes can need less/more exp to gain levels */
256 static const float expmul = 1.0;//D 326 constexpr static const float expmul = 1.0;//D
257 float ACC (RW, move_slow_penalty); /* How much this slows down the object */ 327 float ACC (RW, move_slow_penalty); /* How much this slows down the object */
258 328
259 /* Following are values used by any object */ 329 /* Following are values used by any object */
260 /* this objects turns into or what this object creates */ 330 /* this objects turns into or what this object creates */
261 treasurelist *ACC (RW, randomitems); /* Items to be generated */ 331 treasurelist *ACC (RW, randomitems); /* Items to be generated */
328 object *ACC (RW, env); /* Pointer to the object which is the environment. 398 object *ACC (RW, env); /* Pointer to the object which is the environment.
329 * This is typically the container that the object is in. 399 * This is typically the container that the object is in.
330 */ 400 */
331 object *ACC (RW, more); /* Pointer to the rest of a large body of objects */ 401 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 402 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 403
335 MTH void set_flag (int flagnum) 404 MTH void set_flag (int flagnum)
336 { 405 {
337 flag [flagnum] = true; 406 flag [flagnum] = true;
338 } 407 }
340 MTH void clr_flag (int flagnum) 409 MTH void clr_flag (int flagnum)
341 { 410 {
342 flag [flagnum] = false; 411 flag [flagnum] = false;
343 } 412 }
344 413
345 // privates / perl 414 // extra key value pairs
346 shstr_tmp kv_get (shstr_tmp key) const; 415 key_values kv;
347 void kv_del (shstr_tmp key);
348 void kv_set (shstr_tmp key, shstr_tmp value);
349 416
350//-GPL 417//-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 418
382 bool parse_kv (object_thawer &f); // parse kv pairs, (ab-)used by archetypes, which should not exist at all 419 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 420 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. 421 static object *read (object_thawer &f, maptile *map = 0); // map argument due to toal design bogosity, must go.
385 bool write (object_freezer &f); 422 bool write (object_freezer &f);
425 // object op is trying to move in direction dir. 462 // object op is trying to move in direction dir.
426 // originator is typically the same as op, but 463 // originator is typically the same as op, but
427 // can be different if originator is causing op to 464 // can be different if originator is causing op to
428 // move (originator is pushing op) 465 // move (originator is pushing op)
429 // returns 0 if the object is not able to move to the 466 // returns 0 if the object is not able to move to the
430 // desired space, 1 otherwise (in which case we also 467 // desired space, 1 otherwise (in which case we also
431 // move the object accordingly. This function is 468 // move the object accordingly. This function is
432 // very similiar to move_object. 469 // very similiar to move_object.
433 int move (int dir, object *originator); 470 int move (int dir, object *originator);
434 471
435 int move (int dir) 472 int move (int dir)
448 return op1->value == op2->value 485 return op1->value == op2->value
449 && op1->name == op2->name 486 && op1->name == op2->name
450 && can_merge_slow (op1, op2); 487 && can_merge_slow (op1, op2);
451 } 488 }
452 489
453 MTH void set_owner (object *owner); 490 MTH void set_owner (object_ornull *owner);
454 MTH void set_speed (float speed); 491 MTH void set_speed (float speed);
455 MTH void set_glow_radius (sint8 rad); 492 MTH void set_glow_radius (sint8 rad);
456 493
457 MTH void open_container (object *new_container); 494 MTH void open_container (object *new_container);
458 MTH void close_container () 495 MTH void close_container ()
471 // strangely enough, using ?: here causes code to inflate 508 // strangely enough, using ?: here causes code to inflate
472 return type == CONTAINER 509 return type == CONTAINER
473 && ((env && env->container_ () == this) 510 && ((env && env->container_ () == this)
474 || (!env && flag [FLAG_APPLIED])); 511 || (!env && flag [FLAG_APPLIED]));
475 } 512 }
513
514 MTH object *find_spell (const_utf8_string prefix) const;
476 515
477 MTH object *force_find (shstr_tmp name); 516 MTH object *force_find (shstr_tmp name);
478 MTH void force_set_timer (int duration); 517 MTH void force_set_timer (int duration);
479 MTH object *force_add (shstr_tmp name, int duration = 0); 518 MTH object *force_add (shstr_tmp name, int duration = 0);
480 519
511 MTH int number_of () const 550 MTH int number_of () const
512 { 551 {
513 return nrof ? nrof : 1; 552 return nrof ? nrof : 1;
514 } 553 }
515 554
516 MTH sint32 total_weight () const 555 MTH weight_t total_weight () const
517 { 556 {
518 return (weight + carrying) * number_of (); 557 return sint64 (weight + carrying) * number_of ();
519 } 558 }
520 559
521 MTH void update_weight (); 560 MTH void update_weight ();
522 561
523 // return the dominant material of this item, always return something 562 // return the dominant material of this item, always return something
525 { 564 {
526 return material; 565 return material;
527 } 566 }
528 567
529 // return the volume of this object in cm³ 568 // return the volume of this object in cm³
530 MTH uint64 volume () const 569 MTH volume_t volume () const
531 { 570 {
532 return (uint64)total_weight () 571 return (volume_t)total_weight ()
533 * 1024 // 1000 actually 572 * 1024 // 1000 actually
534 * (type == CONTAINER ? 128 : 1) 573 * (type == CONTAINER ? 128 : 1)
535 / dominant_material ()->density; // ugh, division 574 / dominant_material ()->density; // ugh, division
536 } 575 }
537 576
570 609
571 static bool msg_has_dialogue (const char *msg) { return *msg == '@'; } 610 static bool msg_has_dialogue (const char *msg) { return *msg == '@'; }
572 611
573 MTH bool has_dialogue () const { return msg_has_dialogue (&msg); } 612 MTH bool has_dialogue () const { return msg_has_dialogue (&msg); }
574 613
575 /* need_identify returns true if the item should be identified. This 614 /* need_identify returns true if the item should be identified. This
576 * function really should not exist - by default, any item not identified 615 * function really should not exist - by default, any item not identified
577 * should need it. 616 * should need it.
578 */ 617 */
579 MTH bool need_identify () const; 618 MTH bool need_identify () const;
580 619
691 MTH void activate (); 730 MTH void activate ();
692 MTH void deactivate (); 731 MTH void deactivate ();
693 MTH void activate_recursive (); 732 MTH void activate_recursive ();
694 MTH void deactivate_recursive (); 733 MTH void deactivate_recursive ();
695 734
735 // prefetch and activate the surrounding area
736 MTH void prefetch_surrounding_maps ();
737
696 // set the given flag on all objects in the inventory recursively 738 // set the given flag on all objects in the inventory recursively
697 MTH void set_flag_inv (int flag, int value = 1); 739 MTH void set_flag_inv (int flag, int value = 1);
698 740
699 void enter_exit (object *exit); // perl 741 void enter_exit (object *exit); // perl
700 MTH bool enter_map (maptile *newmap, int x, int y); 742 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 743 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 744 MTH bool apply (object *ob, int aflags = AP_APPLY); // ob may be 0
703 745
704 MTH object *mark () const; 746 MTH object *mark () const;
747 MTH void splay_marked ();
705 748
706 // returns the mapspace this object is in 749 // returns the mapspace this object is in
707 mapspace &ms () const; 750 mapspace &ms () const;
708 751
709 // fully recursive iterator 752 // fully recursive iterator
767 void failmsgf (const_utf8_string format, ...); // always NDI_RED... 810 void failmsgf (const_utf8_string format, ...); // always NDI_RED...
768 811
769 MTH const_utf8_string query_inventory (object *who = 0, const_utf8_string indent = ""); 812 MTH const_utf8_string query_inventory (object *who = 0, const_utf8_string indent = "");
770 813
771 MTH const_octet_string ref () const; // creates and returns a consistent persistent object reference 814 MTH const_octet_string ref () const; // creates and returns a consistent persistent object reference
772 MTH static object *deref (const_octet_string ref); // returns the object from the generated reference, if possible 815 static object *deref (const_octet_string ref); // returns the object from the generated reference, if possible
773 816
774 // make some noise with given item into direction dir, 817 // make some noise with given item into direction dir,
775 // currently only used for players to make them temporarily visible 818 // currently only used for players to make them temporarily visible
776 // when they are invisible. 819 // when they are invisible.
777 MTH void make_noise (); 820 MTH void make_noise ();
868 MTH object *instance (); 911 MTH object *instance ();
869 912
870 MTH void post_load_check (); // do some adjustments after parsing 913 MTH void post_load_check (); // do some adjustments after parsing
871 914
872 object_vector_index ACC (RW, archid); // index in archvector 915 object_vector_index ACC (RW, archid); // index in archvector
873 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */ 916 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */
874 917
875 sint8 ACC (RW, max_x); /* extents, compared to the head (min_x, min_y should be zero, but aren't...) */ 918 sint8 ACC (RW, max_x); /* extents, compared to the head (min_x, min_y should be zero, but aren't...) */
876 919
877 // support for archetype loading 920 // support for archetype loading
878 static archetype *read (object_thawer &f); 921 static archetype *read (object_thawer &f);
910// "safely" iterate over inv in a way such that the current item is removable 953// "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 954// quite horrible, that's why its hidden in some macro
912#define for_inv_removable(op,var) \ 955#define for_inv_removable(op,var) \
913 for (object *var, *next_ = (op)->inv; (var = next_), var && (next_ = var->below), var; ) 956 for (object *var, *next_ = (op)->inv; (var = next_), var && (next_ = var->below), var; )
914 957
915#define for_all_objects(var) \ 958#define for_all_objects(var) \
916 for (unsigned _i = 0; _i < objects.size (); ++_i) \ 959 for (unsigned _i = 0; _i < objects.size (); ++_i) \
917 statementvar (object *, var, objects [_i]) 960 statementvar (object *, var, objects [_i])
918 961
919#define for_all_actives(var) \ 962#define for_all_actives(var) \
920 for (unsigned _i = 0; _i < actives.size (); ++_i) \ 963 for (unsigned _i = 0; _i < actives.size (); ++_i) \
921 statementvar (object *, var, actives [_i]) 964 statementvar (object *, var, actives [_i])
922 965
923#define for_all_archetypes(var) \ 966#define for_all_archetypes(var) \
924 for (unsigned _i = 0; _i < archetypes.size (); ++_i) \ 967 for (unsigned _i = 0; _i < archetypes.size (); ++_i) \
925 statementvar (archetype *, var, archetypes [_i]) 968 statementvar (archetype *, var, archetypes [_i])
926 969
927//+GPL 970//+GPL
928 971
929/* Used by update_object to know if the object being passed is 972/* Used by update_object to know if the object being passed is
932#define UP_OBJ_INSERT 1 975#define UP_OBJ_INSERT 1
933#define UP_OBJ_REMOVE 2 976#define UP_OBJ_REMOVE 2
934#define UP_OBJ_CHANGE 3 977#define UP_OBJ_CHANGE 3
935#define UP_OBJ_FACE 4 /* Only thing that changed was the face */ 978#define UP_OBJ_FACE 4 /* Only thing that changed was the face */
936 979
937/* These are flags passed to insert_ob_in_map and 980/* These are flags passed to insert_ob_in_map and
938 * insert_ob_in_ob. Note that all flags may not be meaningful 981 * insert_ob_in_ob. Note that all flags may not be meaningful
939 * for both functions. 982 * for both functions.
940 * Most are fairly explanatory: 983 * Most are fairly explanatory:
941 * INS_NO_MERGE: don't try to merge inserted object with ones alrady 984 * INS_NO_MERGE: don't try to merge inserted object with ones alrady
942 * on space. 985 * on space.
943 * INS_ABOVE_FLOOR_ONLY: Put object immediatly above the floor. 986 * INS_ABOVE_FLOOR_ONLY: Put object immediatly above the floor.
944 * INS_NO_WALK_ON: Don't call check_walk_on against the 987 * INS_NO_WALK_ON: Don't call check_walk_on against the
945 * originator - saves cpu time if you know the inserted object 988 * originator - saves cpu time if you know the inserted object
946 * is not meaningful in terms of having an effect. 989 * is not meaningful in terms of having an effect.
947 * INS_ON_TOP: Always put object on top. Generally only needed when loading 990 * INS_ON_TOP: Always put object on top. Generally only needed when loading
948 * files from disk and ordering needs to be preserved. 991 * files from disk and ordering needs to be preserved.
949 * INS_BELOW_ORIGINATOR: Insert new object immediately below originator - 992 * INS_BELOW_ORIGINATOR: Insert new object immediately below originator -
950 * Use for treasure chests so the new object is the highest thing 993 * Use for treasure chests so the new object is the highest thing
951 * beneath the player, but not actually above it. Note - the 994 * beneath the player, but not actually above it. Note - the
952 * map and x,y coordinates for the object to be inserted must 995 * map and x,y coordinates for the object to be inserted must
953 * match the originator. 996 * match the originator.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines