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.258 by root, Sat Apr 23 04:56:49 2011 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,2011 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
73 * accessing the list directly. 74 * accessing the list directly.
74 * 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.
75 */ 76 */
76struct key_value : slice_allocated 77struct key_value : slice_allocated
77{ 78{
78 key_value *next; 79 key_value *next; // must be first element
79 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 }
80}; 130};
81 131
82//-GPL 132//-GPL
83 133
84struct UUID 134struct UUID
130{ /* Used to link together several object links */ 180{ /* Used to link together several object links */
131 struct oblnk *link; 181 struct oblnk *link;
132 struct oblinkpt *next; 182 struct oblinkpt *next;
133 shstr id; /* Used as connected value in buttons/gates */ 183 shstr id; /* Used as connected value in buttons/gates */
134} 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
135 211
136INTERFACE_CLASS (object) 212INTERFACE_CLASS (object)
137// these are being copied 213// these are being copied
138struct object_copy : attachable 214struct object_copy : attachable
139{ 215{
203 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 */
204 uint8 ACC (RW, weapontype); /* type of weapon */ 280 uint8 ACC (RW, weapontype); /* type of weapon */
205 281
206 body_slot slot [NUM_BODY_LOCATIONS]; 282 body_slot slot [NUM_BODY_LOCATIONS];
207 283
208 faceidx ACC (RW, face); /* the graphical face */ 284 faceidx_debug ACC (RW, face); /* the graphical face */
209 285
210 faceidx ACC (RW, sound); /* the sound face */ 286 faceidx ACC (RW, sound); /* the sound face */
211 faceidx ACC (RW, sound_destroy); /* played on destroy */ 287 faceidx ACC (RW, sound_destroy); /* played on destroy */
212 288
213 sint32 ACC (RW, weight); /* Attributes of the object */ 289 sint32 ACC (RW, weight); /* Attributes of the object */
245 321
246 // 8 free bits 322 // 8 free bits
247 323
248 //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 */
249 // /* races/classes can need less/more exp to gain levels */ 325 // /* races/classes can need less/more exp to gain levels */
250 static const float expmul = 1.0;//D 326 constexpr static const float expmul = 1.0;//D
251 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 */
252 328
253 /* Following are values used by any object */ 329 /* Following are values used by any object */
254 /* this objects turns into or what this object creates */ 330 /* this objects turns into or what this object creates */
255 treasurelist *ACC (RW, randomitems); /* Items to be generated */ 331 treasurelist *ACC (RW, randomitems); /* Items to be generated */
322 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.
323 * This is typically the container that the object is in. 399 * This is typically the container that the object is in.
324 */ 400 */
325 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 */
326 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
327 key_value *key_values; /* Fields not explictly known by the loader. */
328 403
329 MTH void set_flag (int flagnum) 404 MTH void set_flag (int flagnum)
330 { 405 {
331 flag [flagnum] = true; 406 flag [flagnum] = true;
332 } 407 }
334 MTH void clr_flag (int flagnum) 409 MTH void clr_flag (int flagnum)
335 { 410 {
336 flag [flagnum] = false; 411 flag [flagnum] = false;
337 } 412 }
338 413
339 // privates / perl 414 // extra key value pairs
340 shstr_tmp kv_get (shstr_tmp key) const; 415 key_values kv;
341 void kv_del (shstr_tmp key);
342 void kv_set (shstr_tmp key, shstr_tmp value);
343 416
344//-GPL 417//-GPL
345
346 // custom extra fields management
347 struct key_value_access_proxy
348 {
349 object &ob;
350 shstr_tmp key;
351
352 key_value_access_proxy (object &ob, shstr_tmp key)
353 : ob (ob), key (key)
354 {
355 }
356
357 const key_value_access_proxy &operator =(shstr_tmp value) const
358 {
359 ob.kv_set (key, value);
360 return *this;
361 }
362
363 operator const shstr_tmp () const { return ob.kv_get (key); }
364 operator const char *() const { return ob.kv_get (key); }
365
366 private:
367 void operator =(int);
368 };
369
370 // operator [] is too annoying to use
371 const key_value_access_proxy kv (shstr_tmp key)
372 {
373 return key_value_access_proxy (*this, key);
374 }
375 418
376 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
377 MTH void post_load_check (); // do some adjustments after parsing 420 MTH void post_load_check (); // do some adjustments after parsing
378 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.
379 bool write (object_freezer &f); 422 bool write (object_freezer &f);
419 // object op is trying to move in direction dir. 462 // object op is trying to move in direction dir.
420 // originator is typically the same as op, but 463 // originator is typically the same as op, but
421 // can be different if originator is causing op to 464 // can be different if originator is causing op to
422 // move (originator is pushing op) 465 // move (originator is pushing op)
423 // 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
424 // desired space, 1 otherwise (in which case we also 467 // desired space, 1 otherwise (in which case we also
425 // move the object accordingly. This function is 468 // move the object accordingly. This function is
426 // very similiar to move_object. 469 // very similiar to move_object.
427 int move (int dir, object *originator); 470 int move (int dir, object *originator);
428 471
429 int move (int dir) 472 int move (int dir)
442 return op1->value == op2->value 485 return op1->value == op2->value
443 && op1->name == op2->name 486 && op1->name == op2->name
444 && can_merge_slow (op1, op2); 487 && can_merge_slow (op1, op2);
445 } 488 }
446 489
447 MTH void set_owner (object *owner); 490 MTH void set_owner (object_ornull *owner);
448 MTH void set_speed (float speed); 491 MTH void set_speed (float speed);
449 MTH void set_glow_radius (sint8 rad); 492 MTH void set_glow_radius (sint8 rad);
450 493
451 MTH void open_container (object *new_container); 494 MTH void open_container (object *new_container);
452 MTH void close_container () 495 MTH void close_container ()
465 // strangely enough, using ?: here causes code to inflate 508 // strangely enough, using ?: here causes code to inflate
466 return type == CONTAINER 509 return type == CONTAINER
467 && ((env && env->container_ () == this) 510 && ((env && env->container_ () == this)
468 || (!env && flag [FLAG_APPLIED])); 511 || (!env && flag [FLAG_APPLIED]));
469 } 512 }
513
514 MTH object *find_spell (const_utf8_string prefix) const;
470 515
471 MTH object *force_find (shstr_tmp name); 516 MTH object *force_find (shstr_tmp name);
472 MTH void force_set_timer (int duration); 517 MTH void force_set_timer (int duration);
473 MTH object *force_add (shstr_tmp name, int duration = 0); 518 MTH object *force_add (shstr_tmp name, int duration = 0);
474 519
505 MTH int number_of () const 550 MTH int number_of () const
506 { 551 {
507 return nrof ? nrof : 1; 552 return nrof ? nrof : 1;
508 } 553 }
509 554
510 MTH sint32 total_weight () const 555 MTH weight_t total_weight () const
511 { 556 {
512 return (weight + carrying) * number_of (); 557 return sint64 (weight + carrying) * number_of ();
513 } 558 }
514 559
515 MTH void update_weight (); 560 MTH void update_weight ();
516 561
517 // return the dominant material of this item, always return something 562 // return the dominant material of this item, always return something
519 { 564 {
520 return material; 565 return material;
521 } 566 }
522 567
523 // return the volume of this object in cm³ 568 // return the volume of this object in cm³
524 MTH uint64 volume () const 569 MTH volume_t volume () const
525 { 570 {
526 return (uint64)total_weight () 571 return (volume_t)total_weight ()
527 * 1024 // 1000 actually 572 * 1024 // 1000 actually
528 * (type == CONTAINER ? 128 : 1) 573 * (type == CONTAINER ? 128 : 1)
529 / dominant_material ()->density; // ugh, division 574 / dominant_material ()->density; // ugh, division
530 } 575 }
531 576
564 609
565 static bool msg_has_dialogue (const char *msg) { return *msg == '@'; } 610 static bool msg_has_dialogue (const char *msg) { return *msg == '@'; }
566 611
567 MTH bool has_dialogue () const { return msg_has_dialogue (&msg); } 612 MTH bool has_dialogue () const { return msg_has_dialogue (&msg); }
568 613
569 /* need_identify returns true if the item should be identified. This 614 /* need_identify returns true if the item should be identified. This
570 * function really should not exist - by default, any item not identified 615 * function really should not exist - by default, any item not identified
571 * should need it. 616 * should need it.
572 */ 617 */
573 MTH bool need_identify () const; 618 MTH bool need_identify () const;
574 619
684 729
685 MTH void activate (); 730 MTH void activate ();
686 MTH void deactivate (); 731 MTH void deactivate ();
687 MTH void activate_recursive (); 732 MTH void activate_recursive ();
688 MTH void deactivate_recursive (); 733 MTH void deactivate_recursive ();
734
735 // prefetch and activate the surrounding area
736 MTH void prefetch_surrounding_maps ();
689 737
690 // set the given flag on all objects in the inventory recursively 738 // set the given flag on all objects in the inventory recursively
691 MTH void set_flag_inv (int flag, int value = 1); 739 MTH void set_flag_inv (int flag, int value = 1);
692 740
693 void enter_exit (object *exit); // perl 741 void enter_exit (object *exit); // perl
863 MTH object *instance (); 911 MTH object *instance ();
864 912
865 MTH void post_load_check (); // do some adjustments after parsing 913 MTH void post_load_check (); // do some adjustments after parsing
866 914
867 object_vector_index ACC (RW, archid); // index in archvector 915 object_vector_index ACC (RW, archid); // index in archvector
868 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */ 916 shstr ACC (RW, archname); /* More definite name, like "generate_kobold" */
869 917
870 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...) */
871 919
872 // support for archetype loading 920 // support for archetype loading
873 static archetype *read (object_thawer &f); 921 static archetype *read (object_thawer &f);
905// "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
906// quite horrible, that's why its hidden in some macro 954// quite horrible, that's why its hidden in some macro
907#define for_inv_removable(op,var) \ 955#define for_inv_removable(op,var) \
908 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; )
909 957
910#define for_all_objects(var) \ 958#define for_all_objects(var) \
911 for (unsigned _i = 0; _i < objects.size (); ++_i) \ 959 for (unsigned _i = 0; _i < objects.size (); ++_i) \
912 statementvar (object *, var, objects [_i]) 960 statementvar (object *, var, objects [_i])
913 961
914#define for_all_actives(var) \ 962#define for_all_actives(var) \
915 for (unsigned _i = 0; _i < actives.size (); ++_i) \ 963 for (unsigned _i = 0; _i < actives.size (); ++_i) \
916 statementvar (object *, var, actives [_i]) 964 statementvar (object *, var, actives [_i])
917 965
918#define for_all_archetypes(var) \ 966#define for_all_archetypes(var) \
919 for (unsigned _i = 0; _i < archetypes.size (); ++_i) \ 967 for (unsigned _i = 0; _i < archetypes.size (); ++_i) \
920 statementvar (archetype *, var, archetypes [_i]) 968 statementvar (archetype *, var, archetypes [_i])
921 969
922//+GPL 970//+GPL
923 971
924/* 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
927#define UP_OBJ_INSERT 1 975#define UP_OBJ_INSERT 1
928#define UP_OBJ_REMOVE 2 976#define UP_OBJ_REMOVE 2
929#define UP_OBJ_CHANGE 3 977#define UP_OBJ_CHANGE 3
930#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 */
931 979
932/* These are flags passed to insert_ob_in_map and 980/* These are flags passed to insert_ob_in_map and
933 * 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
934 * for both functions. 982 * for both functions.
935 * Most are fairly explanatory: 983 * Most are fairly explanatory:
936 * 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
937 * on space. 985 * on space.
938 * INS_ABOVE_FLOOR_ONLY: Put object immediatly above the floor. 986 * INS_ABOVE_FLOOR_ONLY: Put object immediatly above the floor.
939 * 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
940 * originator - saves cpu time if you know the inserted object 988 * originator - saves cpu time if you know the inserted object
941 * is not meaningful in terms of having an effect. 989 * is not meaningful in terms of having an effect.
942 * 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
943 * files from disk and ordering needs to be preserved. 991 * files from disk and ordering needs to be preserved.
944 * INS_BELOW_ORIGINATOR: Insert new object immediately below originator - 992 * INS_BELOW_ORIGINATOR: Insert new object immediately below originator -
945 * 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
946 * beneath the player, but not actually above it. Note - the 994 * beneath the player, but not actually above it. Note - the
947 * 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
948 * match the originator. 996 * match the originator.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines