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.189 by root, Tue Dec 23 00:39:48 2008 UTC vs.
Revision 1.196 by root, Thu Jan 8 03:03:24 2009 UTC

136{ 136{
137 signed char info:4; /* body info as loaded from the file */ 137 signed char info:4; /* body info as loaded from the file */
138 signed char used:4; /* Calculated value based on items equipped */ 138 signed char used:4; /* Calculated value based on items equipped */
139}; 139};
140 140
141typedef struct oblnk
142{ /* Used to link together several objects */
143 object_ptr ob;
144 struct oblnk *next;
145} objectlink;
146
147typedef struct oblinkpt
148{ /* Used to link together several object links */
149 struct oblnk *link;
150 struct oblinkpt *next;
151 shstr id; /* Used as connected value in buttons/gates */
152} oblinkpt;
153
141INTERFACE_CLASS (object) 154INTERFACE_CLASS (object)
142// these are being copied 155// these are being copied
143struct object_copy : attachable 156struct object_copy : attachable
144{ 157{
145 sint16 ACC (RW, x), ACC (RW, y); /* Position in the map for this object */ 158 sint16 ACC (RW, x), ACC (RW, y); /* Position in the map for this object */
308 object *head; /* Points to the main object of a large body */ // NO ACC, perl semantics are different 321 object *head; /* Points to the main object of a large body */ // NO ACC, perl semantics are different
309 client_container *seen_by; // seen by which player/container currently? 322 client_container *seen_by; // seen by which player/container currently?
310 key_value *key_values; /* Fields not explictly known by the loader. */ 323 key_value *key_values; /* Fields not explictly known by the loader. */
311 324
312 // privates / perl 325 // privates / perl
313 const shstr &kv_get (const shstr &key) const; 326 shstr_tmp kv_get (shstr_tmp key) const;
314 void kv_del (const shstr &key); 327 void kv_del (shstr_tmp key);
315 void kv_set (const shstr &key, const shstr &value); 328 void kv_set (shstr_tmp key, shstr_tmp value);
316 329
317 // custom extra fields management 330 // custom extra fields management
318 struct key_value_access_proxy 331 struct key_value_access_proxy
319 { 332 {
320 object &ob; 333 object &ob;
321 shstr key; 334 shstr_tmp key;
322 335
323 key_value_access_proxy (object &ob, const shstr &key) 336 key_value_access_proxy (object &ob, shstr_tmp key)
324 : ob (ob), key (key) 337 : ob (ob), key (key)
325 { 338 {
326 } 339 }
327 340
328 const key_value_access_proxy &operator =(const shstr &value) const 341 const key_value_access_proxy &operator =(shstr_tmp value) const
329 { 342 {
330 ob.kv_set (key, value); 343 ob.kv_set (key, value);
331 return *this; 344 return *this;
332 } 345 }
333 346
334 operator const shstr &() const { return ob.kv_get (key); } 347 operator const shstr_tmp () const { return ob.kv_get (key); }
335 operator const char *() const { return ob.kv_get (key); } 348 operator const char *() const { return ob.kv_get (key); }
336 349
337 private: 350 private:
338 void operator =(int); 351 void operator =(int);
339 }; 352 };
340 353
341 // operator [] is too annoying to use 354 // operator [] is too annoying to use
342 const key_value_access_proxy kv (const shstr &key) 355 const key_value_access_proxy kv (shstr_tmp key)
343 { 356 {
344 return key_value_access_proxy (*this, key); 357 return key_value_access_proxy (*this, key);
345 } 358 }
346 359
347 bool parse_kv (object_thawer &f); // parse kv pairs, (ab-)used by archetypes, which should not exist at all 360 bool parse_kv (object_thawer &f); // parse kv pairs, (ab-)used by archetypes, which should not exist at all
383 remove (); 396 remove ();
384 *this = pos; 397 *this = pos;
385 insert_at (this, this); 398 insert_at (this, this);
386 } 399 }
387 400
401 // high-level move functions, return true if successful
402 int move (int dir, object *originator);
403
404 int move (int dir)
405 {
406 return move (dir, this);
407 }
408
388 static bool can_merge_slow (object *op1, object *op2); 409 static bool can_merge_slow (object *op1, object *op2);
389 410
390 // this is often used in time-critical code, so optimise 411 // this is often used in time-critical code, so optimise
391 MTH static bool can_merge (object *op1, object *op2) 412 MTH static bool can_merge (object *op1, object *op2)
392 { 413 {
404 MTH void close_container () 425 MTH void close_container ()
405 { 426 {
406 open_container (0); 427 open_container (0);
407 } 428 }
408 429
409 MTH object *force_find (const shstr name); 430 MTH object *force_find (shstr_tmp name);
410 MTH object *force_add (const shstr name, int duration = 0); 431 MTH object *force_add (shstr_tmp name, int duration = 0);
432
433 oblinkpt *find_link () const;
434 MTH void add_link (maptile *map, shstr_tmp id);
435 MTH void remove_link ();
411 436
412 // overwrite the attachable should_invoke function with a version that also checks ev_want_type 437 // overwrite the attachable should_invoke function with a version that also checks ev_want_type
413 bool should_invoke (event_type event) 438 bool should_invoke (event_type event)
414 { 439 {
415 return ev_want_event [event] || ev_want_type [type] || cb; 440 return ev_want_event [event] || ev_want_type [type] || cb;
451 const materialtype_t *dominant_material () const; 476 const materialtype_t *dominant_material () const;
452 477
453 // return the volume of this object in cm³ 478 // return the volume of this object in cm³
454 MTH uint64 volume () const 479 MTH uint64 volume () const
455 { 480 {
456 return total_weight () 481 return (uint64)total_weight ()
457 * 1000 482 * 1000
458 * (type == CONTAINER ? 1000 : 1) 483 * (type == CONTAINER ? 1000 : 1)
459 / dominant_material ()->density; 484 / dominant_material ()->density;
460 } 485 }
461 486
538 MTH bool is_inserted () const 563 MTH bool is_inserted () const
539 { 564 {
540 return !flag [FLAG_REMOVED]; 565 return !flag [FLAG_REMOVED];
541 } 566 }
542 567
568 MTH bool is_player () const
569 {
570 return !!contr;
571 }
572
543 MTH bool affects_los () const 573 MTH bool affects_los () const
544 { 574 {
545 return glow_radius || flag [FLAG_BLOCKSVIEW]; 575 return glow_radius || flag [FLAG_BLOCKSVIEW];
576 }
577
578 MTH bool has_carried_lights () const
579 {
580 return glow_radius;
546 } 581 }
547 582
548 // returns the player that cna see this object, if any 583 // returns the player that cna see this object, if any
549 MTH object *visible_to () const; 584 MTH object *visible_to () const;
550 585
679 } 714 }
680 715
681 return ob; 716 return ob;
682} 717}
683 718
684typedef struct oblnk
685{ /* Used to link together several objects */
686 object_ptr ob;
687 struct oblnk *next;
688} objectlink;
689
690typedef struct oblinkpt
691{ /* Used to link together several object links */
692 struct oblnk *link;
693 sint32 value; /* Used as connected value in buttons/gates */
694 struct oblinkpt *next;
695} oblinkpt;
696
697object *find_skill_by_name (object *who, const char *name); 719object *find_skill_by_name_fuzzy (object *who, const char *name);
698object *find_skill_by_name (object *who, const shstr &sh); 720object *find_skill_by_name (object *who, shstr_cmp sh);
699object *find_skill_by_number (object *who, int skillno); 721object *find_skill_by_number (object *who, int skillno);
700 722
701/* 723/*
702 * The archetype structure is a set of rules on how to generate and manipulate 724 * The archetype structure is a set of rules on how to generate and manipulate
703 * objects which point to archetypes. 725 * objects which point to archetypes.
757extern objectvec objects; 779extern objectvec objects;
758extern activevec actives; 780extern activevec actives;
759extern archvec archetypes; 781extern archvec archetypes;
760 782
761// "safely" iterate over inv in a way such that the current item is removable 783// "safely" iterate over inv in a way such that the current item is removable
762// quite horrible, thats why its hidden in some macro 784// quite horrible, that's why its hidden in some macro
763#define for_inv_removable(op,var) \ 785#define for_inv_removable(op,var) \
764 for (object *var, *next_ = (op)->inv; (var = next_), var && (next_ = var->below), var; ) 786 for (object *var, *next_ = (op)->inv; (var = next_), var && (next_ = var->below), var; )
765 787
766#define for_all_objects(var) \ 788#define for_all_objects(var) \
767 for (unsigned _i = 0; _i < objects.size (); ++_i) \ 789 for (unsigned _i = 0; _i < objects.size (); ++_i) \

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines