… | |
… | |
93 | |
93 | |
94 | struct UUID |
94 | struct UUID |
95 | { |
95 | { |
96 | uint64 seq; |
96 | uint64 seq; |
97 | |
97 | |
|
|
98 | enum { MAX_LEN = 3 + 16 + 1 + 1 }; // <1. + hex + > + \0 |
|
|
99 | |
98 | static UUID cur; // last uuid generated |
100 | static UUID cur; // last uuid generated |
99 | static void init (); |
101 | static void init (); |
100 | static UUID gen (); |
102 | static UUID gen (); |
101 | |
103 | |
102 | UUID () { } |
104 | UUID () { } |
103 | UUID (uint64 seq) : seq(seq) { } |
105 | UUID (uint64 seq) : seq(seq) { } |
104 | operator uint64() { return seq; } |
106 | operator uint64() { return seq; } |
105 | void operator =(uint64 seq) { this->seq = seq; } |
107 | void operator =(uint64 seq) { this->seq = seq; } |
106 | |
108 | |
107 | typedef char BUF [32]; |
|
|
108 | |
|
|
109 | bool parse (const char *s) |
109 | bool parse (const char *s); |
110 | { |
110 | char *append (char *buf) const; |
111 | return sscanf (s, "<1.%" SCNx64 ">", &seq) == 1; |
|
|
112 | } |
|
|
113 | |
|
|
114 | const char *c_str (char *buf, int len) const |
|
|
115 | { |
|
|
116 | snprintf (buf, len, "<1.%" PRIx64 ">", seq); |
|
|
117 | |
|
|
118 | return buf; |
|
|
119 | } |
|
|
120 | |
|
|
121 | const char *c_str () const |
111 | char *c_str () const; |
122 | { |
|
|
123 | static BUF buf; |
|
|
124 | |
|
|
125 | return c_str (buf, sizeof (buf)); |
|
|
126 | } |
|
|
127 | }; |
112 | }; |
128 | |
113 | |
129 | //+GPL |
114 | //+GPL |
130 | |
115 | |
131 | /* Definition for WILL_APPLY values. Replaces having harcoded values |
116 | /* Definition for WILL_APPLY values. Replaces having harcoded values |
… | |
… | |
180 | flags_t flag; /* various flags */ |
165 | flags_t flag; /* various flags */ |
181 | #if FOR_PERL |
166 | #if FOR_PERL |
182 | bool ACC (RW, flag[NUM_FLAGS]); |
167 | bool ACC (RW, flag[NUM_FLAGS]); |
183 | #endif |
168 | #endif |
184 | |
169 | |
185 | shstr ACC (RW, materialname); /* specific material name */ |
170 | materialtype_t *material; // What material this object consists of //TODO, make perl-accessible |
186 | shstr ACC (RW, skill); /* Name of the skill this object uses/grants */ |
171 | shstr ACC (RW, skill); /* Name of the skill this object uses/grants */ |
187 | // materialtype_t *ACC (RW, material); /* What material this object consists of */ |
|
|
188 | object_ptr ACC (RW, owner); /* Pointer to the object which controls this one */ |
172 | object_ptr ACC (RW, owner); /* Pointer to the object which controls this one */ |
189 | object_ptr ACC (RW, enemy); /* Monster/player to follow even if not closest */ |
173 | object_ptr ACC (RW, enemy); /* Monster/player to follow even if not closest */ |
190 | object_ptr ACC (RW, attacked_by); /* This object start to attack us! only player & monster */ |
174 | object_ptr ACC (RW, attacked_by); /* This object start to attack us! only player & monster */ |
191 | object_ptr ACC (RW, chosen_skill); /* the skill chosen to use */ |
175 | object_ptr ACC (RW, chosen_skill); /* the skill chosen to use */ |
192 | object_ptr ACC (RW, spellitem); /* Spell ability monster is choosing to use */ |
176 | object_ptr ACC (RW, spellitem); /* Spell ability monster is choosing to use */ |
… | |
… | |
504 | } |
488 | } |
505 | |
489 | |
506 | MTH void update_weight (); |
490 | MTH void update_weight (); |
507 | |
491 | |
508 | // return the dominant material of this item, always return something |
492 | // return the dominant material of this item, always return something |
509 | const materialtype_t *dominant_material () const; |
493 | const materialtype_t *dominant_material () const |
|
|
494 | { |
|
|
495 | return material; |
|
|
496 | } |
510 | |
497 | |
511 | // return the volume of this object in cm³ |
498 | // return the volume of this object in cm³ |
512 | MTH uint64 volume () const |
499 | MTH uint64 volume () const |
513 | { |
500 | { |
514 | return (uint64)total_weight () |
501 | return (uint64)total_weight () |
515 | * 1000 |
502 | * 1024 // 1000 actually |
516 | * (type == CONTAINER ? 1000 : 1) |
503 | * (type == CONTAINER ? 128 : 1) |
517 | / dominant_material ()->density; |
504 | / dominant_material ()->density; // ugh, division |
518 | } |
505 | } |
519 | |
506 | |
520 | MTH bool is_arch () const { return this == (const object *)(const archetype *)arch; } |
507 | MTH bool is_arch () const { return this == (const object *)(const archetype *)arch; } |
521 | |
508 | |
522 | MTH bool is_wiz () const { return flag [FLAG_WIZ]; } |
509 | MTH bool is_wiz () const { return flag [FLAG_WIZ]; } |
… | |
… | |
531 | MTH bool is_arrow () const { return type == ARROW |
518 | MTH bool is_arrow () const { return type == ARROW |
532 | || (type == SPELL_EFFECT |
519 | || (type == SPELL_EFFECT |
533 | && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); } |
520 | && (subtype == SP_BULLET || subtype == SP_MAGIC_MISSILE)); } |
534 | MTH bool is_range () const { return type == BOW || type == ROD || type == WAND || type == HORN; } |
521 | MTH bool is_range () const { return type == BOW || type == ROD || type == WAND || type == HORN; } |
535 | |
522 | |
536 | MTH bool has_active_speed () const { return fabs (speed) >= MIN_ACTIVE_SPEED; } |
523 | MTH bool has_active_speed () const { return speed >= MIN_ACTIVE_SPEED; } |
537 | |
524 | |
538 | // temporary: wether the object can be saved in a map file |
525 | // temporary: wether the object can be saved in a map file |
539 | // contr => is a player |
526 | // contr => is a player |
540 | // head => only save head of a multitile object |
527 | // head => only save head of a multitile object |
541 | // owner => can not reference owner yet |
528 | // owner => can not reference owner yet |
… | |
… | |
828 | static archetype *read (object_thawer &f); |
815 | static archetype *read (object_thawer &f); |
829 | MTH static void commit_load (); // commit any objects loaded, resolves cyclic dependencies and more |
816 | MTH static void commit_load (); // commit any objects loaded, resolves cyclic dependencies and more |
830 | static void postpone_arch_ref (arch_ptr &ref, const_utf8_string other_arch); /* postpone other_arch reference */ |
817 | static void postpone_arch_ref (arch_ptr &ref, const_utf8_string other_arch); /* postpone other_arch reference */ |
831 | }; |
818 | }; |
832 | |
819 | |
833 | // compatbiility, remove once replaced by ->instance |
|
|
834 | inline object * |
|
|
835 | arch_to_object (archetype *at) |
|
|
836 | { |
|
|
837 | return at->instance (); |
|
|
838 | } |
|
|
839 | |
|
|
840 | inline void |
820 | inline void |
841 | object_freezer::put (keyword k, archetype *v) |
821 | object_freezer::put (const keyword_string k, archetype *v) |
842 | { |
822 | { |
843 | put (k, v ? &v->archname : (const char *)0); |
823 | if (expect_true (v)) |
|
|
824 | put (k, v->archname); |
|
|
825 | else |
|
|
826 | put (k); |
844 | } |
827 | } |
845 | |
828 | |
846 | typedef object_vector<object, &object::index > objectvec; |
829 | typedef object_vector<object, &object::index > objectvec; |
847 | typedef object_vector<object, &object::active> activevec; |
830 | typedef object_vector<object, &object::active> activevec; |
848 | typedef object_vector<archetype, &archetype::archid> archvec; |
831 | typedef object_vector<archetype, &archetype::archid> archvec; |