… | |
… | |
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 | |
|
|
141 | typedef struct oblnk |
|
|
142 | { /* Used to link together several objects */ |
|
|
143 | object_ptr ob; |
|
|
144 | struct oblnk *next; |
|
|
145 | } objectlink; |
|
|
146 | |
|
|
147 | typedef 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 | |
141 | INTERFACE_CLASS (object) |
154 | INTERFACE_CLASS (object) |
142 | // these are being copied |
155 | // these are being copied |
143 | struct object_copy : attachable |
156 | struct 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 void 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 | |
|
|
573 | MTH bool affects_los () const |
|
|
574 | { |
|
|
575 | return glow_radius || flag [FLAG_BLOCKSVIEW]; |
|
|
576 | } |
|
|
577 | |
|
|
578 | MTH bool has_carried_lights () const |
|
|
579 | { |
|
|
580 | return glow_radius; |
|
|
581 | } |
|
|
582 | |
543 | // returns the player that cna see this object, if any |
583 | // returns the player that cna see this object, if any |
544 | MTH object *visible_to () const; |
584 | MTH object *visible_to () const; |
545 | |
585 | |
546 | MTH std::string long_desc (object *who = 0); |
586 | MTH std::string long_desc (object *who = 0); |
547 | MTH std::string describe_monster (object *who = 0); |
587 | MTH std::string describe_monster (object *who = 0); |
… | |
… | |
638 | const char *query_inventory (object *who = 0, const char *indent = ""); |
678 | const char *query_inventory (object *who = 0, const char *indent = ""); |
639 | |
679 | |
640 | MTH const_octet_string ref () const; // creates and returns a consistent persistent object reference |
680 | 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 |
681 | static object *deref (const_octet_string ref); // returns the object from the generated refreence, if possible |
642 | |
682 | |
|
|
683 | // make some noise with given item into direction dir, |
|
|
684 | // currently only used for players to make them temporarily visible |
|
|
685 | // when they are invisible. |
|
|
686 | MTH void make_noise (); |
|
|
687 | |
643 | protected: |
688 | protected: |
644 | void link (); |
689 | void link (); |
645 | void unlink (); |
690 | void unlink (); |
646 | |
691 | |
647 | object (); |
692 | object (); |
… | |
… | |
669 | } |
714 | } |
670 | |
715 | |
671 | return ob; |
716 | return ob; |
672 | } |
717 | } |
673 | |
718 | |
674 | typedef struct oblnk |
|
|
675 | { /* Used to link together several objects */ |
|
|
676 | object_ptr ob; |
|
|
677 | struct oblnk *next; |
|
|
678 | } objectlink; |
|
|
679 | |
|
|
680 | typedef 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 | |
|
|
687 | object *find_skill_by_name (object *who, const char *name); |
719 | object *find_skill_by_name_fuzzy (object *who, const char *name); |
688 | object *find_skill_by_name (object *who, const shstr &sh); |
720 | object *find_skill_by_name (object *who, shstr_cmp sh); |
689 | object *find_skill_by_number (object *who, int skillno); |
721 | object *find_skill_by_number (object *who, int skillno); |
690 | |
722 | |
691 | /* |
723 | /* |
692 | * 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 |
693 | * objects which point to archetypes. |
725 | * objects which point to archetypes. |
… | |
… | |
747 | extern objectvec objects; |
779 | extern objectvec objects; |
748 | extern activevec actives; |
780 | extern activevec actives; |
749 | extern archvec archetypes; |
781 | extern archvec archetypes; |
750 | |
782 | |
751 | // "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 |
752 | // quite horrible, thats why its hidden in some macro |
784 | // quite horrible, that's why its hidden in some macro |
753 | #define for_inv_removable(op,var) \ |
785 | #define for_inv_removable(op,var) \ |
754 | 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; ) |
755 | |
787 | |
756 | #define for_all_objects(var) \ |
788 | #define for_all_objects(var) \ |
757 | for (unsigned _i = 0; _i < objects.size (); ++_i) \ |
789 | for (unsigned _i = 0; _i < objects.size (); ++_i) \ |