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.192 by root, Sun Dec 28 06:59:27 2008 UTC vs.
Revision 1.199 by elmex, Mon Jan 12 00:17:23 2009 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 (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team 4 * Copyright (©) 2005,2006,2007,2008,2009 Marc Alexander Lehmann / Robin Redeker / the Deliantra team
5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team 5 * Copyright (©) 2001,2007 Mark Wedel & Crossfire Development Team
6 * Copyright (©) 1992,2007 Frank Tore Johansen 6 * Copyright (©) 1992,2007 Frank Tore Johansen
7 * 7 *
8 * Deliantra is free software: you can redistribute it and/or modify 8 * Deliantra is free software: you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by 9 * it under the terms of the GNU General Public License as published by
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 */
278 shstr ACC (RW, lore); /* Obscure information about this object, */ 291 shstr ACC (RW, lore); /* Obscure information about this object, */
279 /* To get put into books and the like. */ 292 /* To get put into books and the like. */
280 shstr ACC (RW, custom_name); /* Custom name assigned by player */ 293 shstr ACC (RW, custom_name); /* Custom name assigned by player */
281}; 294};
282 295
296const char *query_weight (const object *op);
297const char *query_short_name (const object *op);
298const char *query_name (const object *op);
299const char *query_base_name (const object *op, int plural);
300
283struct object : zero_initialised, object_copy 301struct object : zero_initialised, object_copy
284{ 302{
285 // These variables are not changed by ->copy_to 303 // These variables are not changed by ->copy_to
286 maptile *ACC (RW, map); /* Pointer to the map in which this object is present */ 304 maptile *ACC (RW, map); /* Pointer to the map in which this object is present */
287 305
308 object *head; /* Points to the main object of a large body */ // NO ACC, perl semantics are different 326 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? 327 client_container *seen_by; // seen by which player/container currently?
310 key_value *key_values; /* Fields not explictly known by the loader. */ 328 key_value *key_values; /* Fields not explictly known by the loader. */
311 329
312 // privates / perl 330 // privates / perl
313 const shstr &kv_get (const shstr &key) const; 331 shstr_tmp kv_get (shstr_tmp key) const;
314 void kv_del (const shstr &key); 332 void kv_del (shstr_tmp key);
315 void kv_set (const shstr &key, const shstr &value); 333 void kv_set (shstr_tmp key, shstr_tmp value);
316 334
317 // custom extra fields management 335 // custom extra fields management
318 struct key_value_access_proxy 336 struct key_value_access_proxy
319 { 337 {
320 object &ob; 338 object &ob;
321 shstr key; 339 shstr_tmp key;
322 340
323 key_value_access_proxy (object &ob, const shstr &key) 341 key_value_access_proxy (object &ob, shstr_tmp key)
324 : ob (ob), key (key) 342 : ob (ob), key (key)
325 { 343 {
326 } 344 }
327 345
328 const key_value_access_proxy &operator =(const shstr &value) const 346 const key_value_access_proxy &operator =(shstr_tmp value) const
329 { 347 {
330 ob.kv_set (key, value); 348 ob.kv_set (key, value);
331 return *this; 349 return *this;
332 } 350 }
333 351
334 operator const shstr &() const { return ob.kv_get (key); } 352 operator const shstr_tmp () const { return ob.kv_get (key); }
335 operator const char *() const { return ob.kv_get (key); } 353 operator const char *() const { return ob.kv_get (key); }
336 354
337 private: 355 private:
338 void operator =(int); 356 void operator =(int);
339 }; 357 };
340 358
341 // operator [] is too annoying to use 359 // operator [] is too annoying to use
342 const key_value_access_proxy kv (const shstr &key) 360 const key_value_access_proxy kv (shstr_tmp key)
343 { 361 {
344 return key_value_access_proxy (*this, key); 362 return key_value_access_proxy (*this, key);
345 } 363 }
346 364
347 bool parse_kv (object_thawer &f); // parse kv pairs, (ab-)used by archetypes, which should not exist at all 365 bool parse_kv (object_thawer &f); // parse kv pairs, (ab-)used by archetypes, which should not exist at all
365 } 383 }
366 384
367 // recursively destroy all objects in inventory, optionally dropping them to the ground instead 385 // recursively destroy all objects in inventory, optionally dropping them to the ground instead
368 MTH void destroy_inv (bool drop_to_ground = false); 386 MTH void destroy_inv (bool drop_to_ground = false);
369 MTH object *insert (object *item); // insert into inventory 387 MTH object *insert (object *item); // insert into inventory
370 MTH void play_sound (faceidx sound); 388 MTH void play_sound (faceidx sound) const;
389 MTH void say_msg (const char *msg) const;
371 390
372 void do_remove (); 391 void do_remove ();
373 MTH void remove () 392 MTH void remove ()
374 { 393 {
375 if (!flag [FLAG_REMOVED]) 394 if (!flag [FLAG_REMOVED])
403 && can_merge_slow (op1, op2); 422 && can_merge_slow (op1, op2);
404 } 423 }
405 424
406 MTH void set_owner (object *owner); 425 MTH void set_owner (object *owner);
407 MTH void set_speed (float speed); 426 MTH void set_speed (float speed);
427 MTH void set_glow_radius (sint8 rad);
408 MTH bool change_weapon (object *ob); 428 MTH bool change_weapon (object *ob);
409 MTH bool change_skill (object *ob); 429 MTH bool change_skill (object *ob);
410 430
411 MTH void open_container (object *new_container); 431 MTH void open_container (object *new_container);
412 MTH void close_container () 432 MTH void close_container ()
413 { 433 {
414 open_container (0); 434 open_container (0);
415 } 435 }
416 436
417 MTH object *force_find (const shstr name); 437 MTH object *force_find (shstr_tmp name);
418 MTH object *force_add (const shstr name, int duration = 0); 438 MTH object *force_add (shstr_tmp name, int duration = 0);
439
440 oblinkpt *find_link () const;
441 MTH void add_link (maptile *map, shstr_tmp id);
442 MTH void remove_link ();
419 443
420 // overwrite the attachable should_invoke function with a version that also checks ev_want_type 444 // overwrite the attachable should_invoke function with a version that also checks ev_want_type
421 bool should_invoke (event_type event) 445 bool should_invoke (event_type event)
422 { 446 {
423 return ev_want_event [event] || ev_want_type [type] || cb; 447 return ev_want_event [event] || ev_want_type [type] || cb;
506 530
507 return op; 531 return op;
508 } 532 }
509 533
510 // returns the outermost environment, never returns 0 534 // returns the outermost environment, never returns 0
511 MTH object *outer_env () 535 MTH object *outer_env () const
512 { 536 {
513 object *op; 537 const object *op;
514 538
515 for (op = this; op->env; op = op->env) 539 for (op = this; op->env; op = op->env)
516 ; 540 ;
517 541
518 return op; 542 return const_cast<object *>(op);
519 } 543 }
520 544
521 // returns the player that has this object in his inventory, or 0 545 // returns the player that has this object in his inventory, or 0
522 // we assume the player is always the outer env 546 // we assume the player is always the outer env
523 MTH object *in_player () 547 MTH object *in_player () const
524 { 548 {
525 object *op = outer_env (); 549 object *op = outer_env ();
526 550
527 return op->type == PLAYER ? op : 0; 551 return op->type == PLAYER ? op : 0;
528 } 552 }
529 553
530 // "temporary" helper function 554 // "temporary" helper function
531 MTH object *head_ () 555 MTH object *head_ () const
532 { 556 {
533 return head ? head : this; 557 return head ? head : const_cast<object *>(this);
534 } 558 }
535 559
536 MTH bool is_head () 560 MTH bool is_head () const
537 { 561 {
538 return head_ () == this; 562 return head_ () == this;
539 } 563 }
540 564
541 MTH bool is_on_map () const 565 MTH bool is_on_map () const
554 } 578 }
555 579
556 MTH bool affects_los () const 580 MTH bool affects_los () const
557 { 581 {
558 return glow_radius || flag [FLAG_BLOCKSVIEW]; 582 return glow_radius || flag [FLAG_BLOCKSVIEW];
583 }
584
585 MTH bool has_carried_lights () const
586 {
587 return glow_radius;
559 } 588 }
560 589
561 // returns the player that cna see this object, if any 590 // returns the player that cna see this object, if any
562 MTH object *visible_to () const; 591 MTH object *visible_to () const;
563 592
564 MTH std::string long_desc (object *who = 0); 593 MTH std::string long_desc (object *who = 0);
565 MTH std::string describe_monster (object *who = 0); 594 MTH std::string describe_monster (object *who = 0);
566 MTH std::string describe_item (object *who = 0); 595 MTH std::string describe_item (object *who = 0);
567 MTH std::string describe (object *who = 0); 596 MTH std::string describe (object *who = 0);
597
598 MTH const char *query_weight () { return ::query_weight (this); }
599 MTH const char *query_name () { return ::query_name (this); }
600 MTH const char *query_short_name () { return ::query_short_name (this); }
601 MTH const char *query_base_name (bool plural) { return ::query_base_name (this, plural); }
568 602
569 // If this object has no extra parts but should have them, 603 // If this object has no extra parts but should have them,
570 // add them, effectively expanding heads into multipart 604 // add them, effectively expanding heads into multipart
571 // objects. This method only works on objects not inserted 605 // objects. This method only works on objects not inserted
572 // anywhere. 606 // anywhere.
692 } 726 }
693 727
694 return ob; 728 return ob;
695} 729}
696 730
697typedef struct oblnk
698{ /* Used to link together several objects */
699 object_ptr ob;
700 struct oblnk *next;
701} objectlink;
702
703typedef struct oblinkpt
704{ /* Used to link together several object links */
705 struct oblnk *link;
706 sint32 value; /* Used as connected value in buttons/gates */
707 struct oblinkpt *next;
708} oblinkpt;
709
710object *find_skill_by_name (object *who, const char *name); 731object *find_skill_by_name_fuzzy (object *who, const char *name);
711object *find_skill_by_name (object *who, const shstr &sh); 732object *find_skill_by_name (object *who, shstr_cmp sh);
712object *find_skill_by_number (object *who, int skillno); 733object *find_skill_by_number (object *who, int skillno);
713 734
714/* 735/*
715 * The archetype structure is a set of rules on how to generate and manipulate 736 * The archetype structure is a set of rules on how to generate and manipulate
716 * objects which point to archetypes. 737 * objects which point to archetypes.

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines