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.188 by root, Sun Nov 16 03:52:12 2008 UTC vs.
Revision 1.197 by root, Thu Jan 8 19:23:44 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
365 } 378 }
366 379
367 // recursively destroy all objects in inventory, optionally dropping them to the ground instead 380 // recursively destroy all objects in inventory, optionally dropping them to the ground instead
368 MTH void destroy_inv (bool drop_to_ground = false); 381 MTH void destroy_inv (bool drop_to_ground = false);
369 MTH object *insert (object *item); // insert into inventory 382 MTH object *insert (object *item); // insert into inventory
370 MTH void play_sound (faceidx sound); 383 MTH void play_sound (faceidx sound) const;
384 MTH void say_msg (const char *msg) const;
371 385
372 void do_remove (); 386 void do_remove ();
373 MTH void remove () 387 MTH void remove ()
374 { 388 {
375 if (!flag [FLAG_REMOVED]) 389 if (!flag [FLAG_REMOVED])
381 void move_to (const mapxy &pos) 395 void move_to (const mapxy &pos)
382 { 396 {
383 remove (); 397 remove ();
384 *this = pos; 398 *this = pos;
385 insert_at (this, this); 399 insert_at (this, this);
400 }
401
402 // high-level move functions, return true if successful
403 int move (int dir, object *originator);
404
405 int move (int dir)
406 {
407 return move (dir, this);
386 } 408 }
387 409
388 static bool can_merge_slow (object *op1, object *op2); 410 static bool can_merge_slow (object *op1, object *op2);
389 411
390 // this is often used in time-critical code, so optimise 412 // this is often used in time-critical code, so optimise
404 MTH void close_container () 426 MTH void close_container ()
405 { 427 {
406 open_container (0); 428 open_container (0);
407 } 429 }
408 430
409 MTH object *force_find (const shstr name); 431 MTH object *force_find (shstr_tmp name);
410 MTH void force_add (const shstr name, int duration = 0); 432 MTH object *force_add (shstr_tmp name, int duration = 0);
433
434 oblinkpt *find_link () const;
435 MTH void add_link (maptile *map, shstr_tmp id);
436 MTH void remove_link ();
411 437
412 // overwrite the attachable should_invoke function with a version that also checks ev_want_type 438 // overwrite the attachable should_invoke function with a version that also checks ev_want_type
413 bool should_invoke (event_type event) 439 bool should_invoke (event_type event)
414 { 440 {
415 return ev_want_event [event] || ev_want_type [type] || cb; 441 return ev_want_event [event] || ev_want_type [type] || cb;
451 const materialtype_t *dominant_material () const; 477 const materialtype_t *dominant_material () const;
452 478
453 // return the volume of this object in cm³ 479 // return the volume of this object in cm³
454 MTH uint64 volume () const 480 MTH uint64 volume () const
455 { 481 {
456 return total_weight () 482 return (uint64)total_weight ()
457 * 1000 483 * 1000
458 * (type == CONTAINER ? 1000 : 1) 484 * (type == CONTAINER ? 1000 : 1)
459 / dominant_material ()->density; 485 / dominant_material ()->density;
460 } 486 }
461 487
498 524
499 return op; 525 return op;
500 } 526 }
501 527
502 // returns the outermost environment, never returns 0 528 // returns the outermost environment, never returns 0
503 MTH object *outer_env () 529 MTH object *outer_env () const
504 { 530 {
505 object *op; 531 const object *op;
506 532
507 for (op = this; op->env; op = op->env) 533 for (op = this; op->env; op = op->env)
508 ; 534 ;
509 535
510 return op; 536 return const_cast<object *>(op);
511 } 537 }
512 538
513 // returns the player that has this object in his inventory, or 0 539 // returns the player that has this object in his inventory, or 0
514 // we assume the player is always the outer env 540 // we assume the player is always the outer env
515 MTH object *in_player () 541 MTH object *in_player () const
516 { 542 {
517 object *op = outer_env (); 543 object *op = outer_env ();
518 544
519 return op->type == PLAYER ? op : 0; 545 return op->type == PLAYER ? op : 0;
520 } 546 }
521 547
522 // "temporary" helper function 548 // "temporary" helper function
523 MTH object *head_ () 549 MTH object *head_ () const
524 { 550 {
525 return head ? head : this; 551 return head ? head : const_cast<object *>(this);
526 } 552 }
527 553
528 MTH bool is_head () 554 MTH bool is_head () const
529 { 555 {
530 return head_ () == this; 556 return head_ () == this;
531 } 557 }
532 558
533 MTH bool is_on_map () const 559 MTH bool is_on_map () const
536 } 562 }
537 563
538 MTH bool is_inserted () const 564 MTH bool is_inserted () const
539 { 565 {
540 return !flag [FLAG_REMOVED]; 566 return !flag [FLAG_REMOVED];
567 }
568
569 MTH bool is_player () const
570 {
571 return !!contr;
572 }
573
574 MTH bool affects_los () const
575 {
576 return glow_radius || flag [FLAG_BLOCKSVIEW];
577 }
578
579 MTH bool has_carried_lights () const
580 {
581 return glow_radius;
541 } 582 }
542 583
543 // returns the player that cna see this object, if any 584 // returns the player that cna see this object, if any
544 MTH object *visible_to () const; 585 MTH object *visible_to () const;
545 586
638 const char *query_inventory (object *who = 0, const char *indent = ""); 679 const char *query_inventory (object *who = 0, const char *indent = "");
639 680
640 MTH const_octet_string ref () const; // creates and returns a consistent persistent object reference 681 MTH const_octet_string ref () const; // creates and returns a consistent persistent object reference
641 static object *deref (const_octet_string ref); // returns the object from the generated refreence, if possible 682 static object *deref (const_octet_string ref); // returns the object from the generated refreence, if possible
642 683
684 // make some noise with given item into direction dir,
685 // currently only used for players to make them temporarily visible
686 // when they are invisible.
687 MTH void make_noise ();
688
643protected: 689protected:
644 void link (); 690 void link ();
645 void unlink (); 691 void unlink ();
646 692
647 object (); 693 object ();
669 } 715 }
670 716
671 return ob; 717 return ob;
672} 718}
673 719
674typedef struct oblnk
675{ /* Used to link together several objects */
676 object_ptr ob;
677 struct oblnk *next;
678} objectlink;
679
680typedef struct oblinkpt
681{ /* Used to link together several object links */
682 struct oblnk *link;
683 sint32 value; /* Used as connected value in buttons/gates */
684 struct oblinkpt *next;
685} oblinkpt;
686
687object *find_skill_by_name (object *who, const char *name); 720object *find_skill_by_name_fuzzy (object *who, const char *name);
688object *find_skill_by_name (object *who, const shstr &sh); 721object *find_skill_by_name (object *who, shstr_cmp sh);
689object *find_skill_by_number (object *who, int skillno); 722object *find_skill_by_number (object *who, int skillno);
690 723
691/* 724/*
692 * The archetype structure is a set of rules on how to generate and manipulate 725 * The archetype structure is a set of rules on how to generate and manipulate
693 * objects which point to archetypes. 726 * objects which point to archetypes.
747extern objectvec objects; 780extern objectvec objects;
748extern activevec actives; 781extern activevec actives;
749extern archvec archetypes; 782extern archvec archetypes;
750 783
751// "safely" iterate over inv in a way such that the current item is removable 784// "safely" iterate over inv in a way such that the current item is removable
752// quite horrible, thats why its hidden in some macro 785// quite horrible, that's why its hidden in some macro
753#define for_inv_removable(op,var) \ 786#define for_inv_removable(op,var) \
754 for (object *var, *next_ = (op)->inv; (var = next_), var && (next_ = var->below), var; ) 787 for (object *var, *next_ = (op)->inv; (var = next_), var && (next_ = var->below), var; )
755 788
756#define for_all_objects(var) \ 789#define for_all_objects(var) \
757 for (unsigned _i = 0; _i < objects.size (); ++_i) \ 790 for (unsigned _i = 0; _i < objects.size (); ++_i) \

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines