1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007 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 | * Crossfire TRT 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 |
10 | * the Free Software Foundation, either version 3 of the License, or |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
24 | /* Eneq(@csd.uu.se): Added weight-modifiers in environment of objects. |
25 | sub/add_weight will transcend the environment updating the carrying |
25 | sub/add_weight will transcend the environment updating the carrying |
26 | variable. */ |
26 | variable. */ |
… | |
… | |
33 | #include <sproto.h> |
33 | #include <sproto.h> |
34 | #include <loader.h> |
34 | #include <loader.h> |
35 | |
35 | |
36 | #include <bitset> |
36 | #include <bitset> |
37 | |
37 | |
38 | int nrofallocobjects = 0; |
38 | UUID UUID::cur; |
39 | static UUID uuid; |
39 | static uint64_t seq_next_save; |
40 | const uint64 UUID_SKIP = 1<<19; |
40 | static const uint64 UUID_GAP = 1<<19; |
41 | |
41 | |
42 | objectvec objects; |
42 | objectvec objects; |
43 | activevec actives; |
43 | activevec actives; |
44 | |
44 | |
45 | short freearr_x[SIZEOFFREE] = { 0, 0, 1, 1, 1, 0, -1, -1, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, |
45 | short freearr_x[SIZEOFFREE] = { |
|
|
46 | 0, |
|
|
47 | 0, 1, 1, 1, 0, -1, -1, -1, |
|
|
48 | 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, |
46 | 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 |
49 | 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 |
47 | }; |
50 | }; |
48 | short freearr_y[SIZEOFFREE] = { 0, -1, -1, 0, 1, 1, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, |
51 | short freearr_y[SIZEOFFREE] = { |
|
|
52 | 0, |
|
|
53 | -1, -1, 0, 1, 1, 1, 0, -1, |
|
|
54 | -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, |
49 | -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3 |
55 | -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3 |
50 | }; |
56 | }; |
51 | int maxfree[SIZEOFFREE] = { 0, 9, 10, 13, 14, 17, 18, 21, 22, 25, 26, 27, 30, 31, 32, 33, 36, 37, 39, 39, 42, 43, 44, 45, |
57 | int maxfree[SIZEOFFREE] = { |
|
|
58 | 0, |
|
|
59 | 9, 10, 13, 14, 17, 18, 21, 22, |
|
|
60 | 25, 26, 27, 30, 31, 32, 33, 36, 37, 39, 39, 42, 43, 44, 45, 48, |
52 | 48, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 |
61 | 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 |
53 | }; |
62 | }; |
54 | int freedir[SIZEOFFREE] = { |
63 | int freedir[SIZEOFFREE] = { |
55 | 0, 1, 2, 3, 4, 5, 6, 7, 8, 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, |
64 | 0, |
|
|
65 | 1, 2, 3, 4, 5, 6, 7, 8, |
|
|
66 | 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, |
56 | 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 |
67 | 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 |
57 | }; |
68 | }; |
58 | |
69 | |
59 | static void |
70 | static void |
60 | write_uuid (void) |
71 | write_uuid (uval64 skip, bool sync) |
61 | { |
72 | { |
62 | char filename1[MAX_BUF], filename2[MAX_BUF]; |
73 | CALL_BEGIN (2); |
63 | |
74 | CALL_ARG_SV (newSVval64 (skip)); |
64 | sprintf (filename1, "%s/uuid", settings.localdir); |
75 | CALL_ARG_SV (boolSV (sync)); |
65 | sprintf (filename2, "%s/uuid~", settings.localdir); |
76 | CALL_CALL ("cf::write_uuid", G_DISCARD); |
66 | |
77 | CALL_END; |
67 | FILE *fp; |
|
|
68 | |
|
|
69 | if (!(fp = fopen (filename2, "w"))) |
|
|
70 | { |
|
|
71 | LOG (llevError, "ERROR: cannot open %s for writing, unable to write UUID!\n", filename2); |
|
|
72 | return; |
|
|
73 | } |
|
|
74 | |
|
|
75 | fprintf (fp, "<1,%llx>\n", (unsigned long long)uuid.seq + UUID_SKIP * 2); |
|
|
76 | fclose (fp); |
|
|
77 | rename (filename2, filename1); |
|
|
78 | } |
78 | } |
79 | |
79 | |
80 | static void |
80 | static void |
81 | read_uuid (void) |
81 | read_uuid (void) |
82 | { |
82 | { |
83 | char filename[MAX_BUF]; |
83 | char filename[MAX_BUF]; |
84 | |
84 | |
85 | sprintf (filename, "%s/uuid", settings.localdir); |
85 | sprintf (filename, "%s/uuid", settings.localdir); |
86 | |
86 | |
|
|
87 | seq_next_save = 0; |
|
|
88 | |
87 | FILE *fp; |
89 | FILE *fp; |
88 | |
90 | |
89 | if (!(fp = fopen (filename, "r"))) |
91 | if (!(fp = fopen (filename, "r"))) |
90 | { |
92 | { |
91 | if (errno == ENOENT) |
93 | if (errno == ENOENT) |
92 | { |
94 | { |
93 | LOG (llevInfo, "RESET uid to 1\n"); |
95 | LOG (llevInfo, "RESET uid to 1\n"); |
94 | uuid.seq = 0; |
96 | UUID::cur.seq = 0; |
95 | write_uuid (); |
97 | write_uuid (UUID_GAP, true); |
96 | return; |
98 | return; |
97 | } |
99 | } |
98 | |
100 | |
99 | LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); |
101 | LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); |
100 | _exit (1); |
102 | _exit (1); |
101 | } |
103 | } |
102 | |
104 | |
103 | int version; |
105 | UUID::BUF buf; |
104 | unsigned long long uid; |
106 | buf[0] = 0; |
105 | if (2 != fscanf (fp, "<%d,%llx>\n", &version, &uid) || version != 1) |
107 | fgets (buf, sizeof (buf), fp); |
|
|
108 | |
|
|
109 | if (!UUID::cur.parse (buf)) |
106 | { |
110 | { |
107 | LOG (llevError, "FATAL: error reading uid from %s!\n", filename); |
111 | LOG (llevError, "FATAL: error reading uid from %s (%s)!\n", filename, buf); |
108 | _exit (1); |
112 | _exit (1); |
109 | } |
113 | } |
110 | |
114 | |
111 | uuid.seq = uid; |
115 | LOG (llevDebug, "read UUID: %s\n", UUID::cur.c_str ()); |
112 | write_uuid (); |
116 | |
113 | LOG (llevDebug, "read UID: %" PRId64 "\n", uid); |
117 | write_uuid (UUID_GAP, true); |
114 | fclose (fp); |
118 | fclose (fp); |
115 | } |
119 | } |
116 | |
120 | |
117 | UUID |
121 | UUID |
118 | gen_uuid () |
122 | UUID::gen () |
119 | { |
123 | { |
120 | UUID uid; |
124 | UUID uid; |
121 | |
125 | |
122 | uid.seq = ++uuid.seq; |
126 | uid.seq = ++cur.seq; |
123 | |
127 | |
124 | if (!(uuid.seq & (UUID_SKIP - 1))) |
128 | if (expect_false (cur.seq >= seq_next_save)) |
125 | write_uuid (); |
129 | { |
|
|
130 | seq_next_save = UUID::cur.seq + (UUID_GAP >> 1); |
|
|
131 | write_uuid (UUID_GAP, false); |
|
|
132 | } |
|
|
133 | |
126 | |
134 | |
127 | return uid; |
135 | return uid; |
128 | } |
136 | } |
129 | |
137 | |
130 | void |
138 | void |
131 | init_uuid () |
139 | UUID::init () |
132 | { |
140 | { |
133 | read_uuid (); |
141 | read_uuid (); |
134 | } |
142 | } |
135 | |
143 | |
136 | /* Returns TRUE if every key_values in wants has a partner with the same value in has. */ |
144 | /* Returns TRUE if every key_values in wants has a partner with the same value in has. */ |
137 | static int |
145 | static bool |
138 | compare_ob_value_lists_one (const object *wants, const object *has) |
146 | compare_ob_value_lists_one (const object *wants, const object *has) |
139 | { |
147 | { |
140 | key_value *wants_field; |
148 | key_value *wants_field; |
141 | |
149 | |
142 | /* n-squared behaviour (see get_ob_key_link()), but I'm hoping both |
150 | /* n-squared behaviour (see get_ob_key_link()), but I'm hoping both |
… | |
… | |
150 | key_value *has_field; |
158 | key_value *has_field; |
151 | |
159 | |
152 | /* Look for a field in has with the same key. */ |
160 | /* Look for a field in has with the same key. */ |
153 | has_field = get_ob_key_link (has, wants_field->key); |
161 | has_field = get_ob_key_link (has, wants_field->key); |
154 | |
162 | |
155 | if (has_field == NULL) |
163 | if (!has_field) |
156 | { |
|
|
157 | /* No field with that name. */ |
164 | return 0; /* No field with that name. */ |
158 | return FALSE; |
|
|
159 | } |
|
|
160 | |
165 | |
161 | /* Found the matching field. */ |
166 | /* Found the matching field. */ |
162 | if (has_field->value != wants_field->value) |
167 | if (has_field->value != wants_field->value) |
163 | { |
|
|
164 | /* Values don't match, so this half of the comparison is false. */ |
168 | return 0; /* Values don't match, so this half of the comparison is false. */ |
165 | return FALSE; |
|
|
166 | } |
|
|
167 | |
169 | |
168 | /* If we get here, we found a match. Now for the next field in wants. */ |
170 | /* If we get here, we found a match. Now for the next field in wants. */ |
169 | } |
171 | } |
170 | |
172 | |
171 | /* If we get here, every field in wants has a matching field in has. */ |
173 | /* If we get here, every field in wants has a matching field in has. */ |
172 | return TRUE; |
174 | return 1; |
173 | } |
175 | } |
174 | |
176 | |
175 | /* Returns TRUE if ob1 has the same key_values as ob2. */ |
177 | /* Returns TRUE if ob1 has the same key_values as ob2. */ |
176 | static int |
178 | static bool |
177 | compare_ob_value_lists (const object *ob1, const object *ob2) |
179 | compare_ob_value_lists (const object *ob1, const object *ob2) |
178 | { |
180 | { |
179 | /* However, there may be fields in has which aren't partnered in wants, |
181 | /* However, there may be fields in has which aren't partnered in wants, |
180 | * so we need to run the comparison *twice*. :( |
182 | * so we need to run the comparison *twice*. :( |
181 | */ |
183 | */ |
… | |
… | |
202 | || ob1->speed != ob2->speed |
204 | || ob1->speed != ob2->speed |
203 | || ob1->value != ob2->value |
205 | || ob1->value != ob2->value |
204 | || ob1->name != ob2->name) |
206 | || ob1->name != ob2->name) |
205 | return 0; |
207 | return 0; |
206 | |
208 | |
207 | //TODO: this ain't working well, use nicer and correct overflow check |
209 | /* Do not merge objects if nrof would overflow. First part checks |
208 | /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that |
210 | * for unsigned overflow (2c), second part checks wether the result |
209 | * value could not be stored in a sint32 (which unfortunately sometimes is |
211 | * would fit into a 32 bit signed int, which is often used to hold |
210 | * used to store nrof). |
212 | * nrof values. |
211 | */ |
213 | */ |
212 | if (ob1->nrof + ob2->nrof >= 1UL << 31) |
214 | if (~ob1->nrof < ob2->nrof || ob1->nrof + ob2->nrof > (1UL << 31)) |
213 | return 0; |
215 | return 0; |
214 | |
216 | |
215 | /* If the objects have been identified, set the BEEN_APPLIED flag. |
217 | /* If the objects have been identified, set the BEEN_APPLIED flag. |
216 | * This is to the comparison of the flags below will be OK. We |
218 | * This is to the comparison of the flags below will be OK. We |
217 | * just can't ignore the been applied or identified flags, as they |
219 | * just can't ignore the been applied or identified flags, as they |
218 | * are not equal - just if it has been identified, the been_applied |
220 | * are not equal - just if it has been identified, the been_applied |
219 | * flags lose any meaning. |
221 | * flags lose any meaning. |
220 | */ |
222 | */ |
221 | if (QUERY_FLAG (ob1, FLAG_IDENTIFIED)) |
223 | if (QUERY_FLAG (ob1, FLAG_IDENTIFIED)) |
… | |
… | |
249 | || ob1->move_off != ob2->move_off |
251 | || ob1->move_off != ob2->move_off |
250 | || ob1->move_slow != ob2->move_slow |
252 | || ob1->move_slow != ob2->move_slow |
251 | || ob1->move_slow_penalty != ob2->move_slow_penalty) |
253 | || ob1->move_slow_penalty != ob2->move_slow_penalty) |
252 | return 0; |
254 | return 0; |
253 | |
255 | |
254 | /* This is really a spellbook check - really, we should |
256 | /* This is really a spellbook check - we should in general |
255 | * check all objects in the inventory. |
257 | * not merge objects with real inventories, as splitting them |
|
|
258 | * is hard. |
256 | */ |
259 | */ |
257 | if (ob1->inv || ob2->inv) |
260 | if (ob1->inv || ob2->inv) |
258 | { |
261 | { |
259 | if (!(ob1->inv && ob2->inv)) |
262 | if (!(ob1->inv && ob2->inv)) |
260 | return 0; /* inventories differ in length */ |
263 | return 0; /* inventories differ in length */ |
261 | |
264 | |
262 | if (ob1->inv->below || ob2->inv->below) |
265 | if (ob1->inv->below || ob2->inv->below) |
263 | return 0; /* more than one object in inv */ |
266 | return 0; /* more than one object in inv */ |
264 | |
267 | |
265 | if (!object::can_merge (ob1->inv, ob2->inv)) |
268 | if (!object::can_merge (ob1->inv, ob2->inv)) |
266 | return 0; /* inventory objexts differ */ |
269 | return 0; /* inventory objects differ */ |
267 | |
270 | |
268 | /* inventory ok - still need to check rest of this object to see |
271 | /* inventory ok - still need to check rest of this object to see |
269 | * if it is valid. |
272 | * if it is valid. |
270 | */ |
273 | */ |
271 | } |
274 | } |
… | |
… | |
290 | if (ob1->level != ob2->level) |
293 | if (ob1->level != ob2->level) |
291 | return 0; |
294 | return 0; |
292 | break; |
295 | break; |
293 | } |
296 | } |
294 | |
297 | |
295 | if (ob1->key_values != NULL || ob2->key_values != NULL) |
298 | if (ob1->key_values || ob2->key_values) |
296 | { |
299 | { |
297 | /* At least one of these has key_values. */ |
300 | /* At least one of these has key_values. */ |
298 | if ((ob1->key_values == NULL) != (ob2->key_values == NULL)) |
301 | if ((!ob1->key_values) != (!ob2->key_values)) |
299 | /* One has fields, but the other one doesn't. */ |
302 | /* One has fields, but the other one doesn't. */ |
300 | return 0; |
303 | return 0; |
301 | else if (!compare_ob_value_lists (ob1, ob2)) |
304 | else if (!compare_ob_value_lists (ob1, ob2)) |
302 | return 0; |
305 | return 0; |
303 | } |
306 | } |
… | |
… | |
429 | break; |
432 | break; |
430 | |
433 | |
431 | return op; |
434 | return op; |
432 | } |
435 | } |
433 | |
436 | |
434 | void |
|
|
435 | free_all_object_data () |
|
|
436 | { |
|
|
437 | LOG (llevDebug, "%d allocated objects\n", nrofallocobjects); |
|
|
438 | } |
|
|
439 | |
|
|
440 | /* |
437 | /* |
441 | * Sets the owner and sets the skill and exp pointers to owner's current |
438 | * Sets the owner and sets the skill and exp pointers to owner's current |
442 | * skill and experience objects. |
439 | * skill and experience objects. |
443 | * ACTUALLY NO! investigate! TODO |
440 | * ACTUALLY NO! investigate! TODO |
444 | */ |
441 | */ |
… | |
… | |
447 | { |
444 | { |
448 | // allow objects which own objects |
445 | // allow objects which own objects |
449 | if (owner) |
446 | if (owner) |
450 | while (owner->owner) |
447 | while (owner->owner) |
451 | owner = owner->owner; |
448 | owner = owner->owner; |
|
|
449 | |
|
|
450 | if (flag [FLAG_FREED]) |
|
|
451 | { |
|
|
452 | LOG (llevError | logBacktrace, "tried to set owner of %s to %s\n", debug_desc (), owner->debug_desc ()); |
|
|
453 | return; |
|
|
454 | } |
452 | |
455 | |
453 | this->owner = owner; |
456 | this->owner = owner; |
454 | } |
457 | } |
455 | |
458 | |
456 | int |
459 | int |
… | |
… | |
597 | |
600 | |
598 | void |
601 | void |
599 | object::instantiate () |
602 | object::instantiate () |
600 | { |
603 | { |
601 | if (!uuid.seq) // HACK |
604 | if (!uuid.seq) // HACK |
602 | uuid = gen_uuid (); |
605 | uuid = UUID::gen (); |
603 | |
606 | |
604 | speed_left = -0.1f; |
607 | speed_left = -0.1f; |
605 | /* copy the body_info to the body_used - this is only really |
608 | /* copy the body_info to the body_used - this is only really |
606 | * need for monsters, but doesn't hurt to do it for everything. |
609 | * need for monsters, but doesn't hurt to do it for everything. |
607 | * by doing so, when a monster is created, it has good starting |
610 | * by doing so, when a monster is created, it has good starting |
… | |
… | |
766 | static int object_count; |
769 | static int object_count; |
767 | |
770 | |
768 | void object::link () |
771 | void object::link () |
769 | { |
772 | { |
770 | assert (!index);//D |
773 | assert (!index);//D |
771 | uuid = gen_uuid (); |
774 | uuid = UUID::gen (); |
772 | count = ++object_count; |
775 | count = ++object_count; |
773 | |
776 | |
774 | refcnt_inc (); |
777 | refcnt_inc (); |
775 | objects.insert (this); |
778 | objects.insert (this); |
776 | } |
779 | } |
… | |
… | |
860 | * if some form of movement is allowed, let objects |
863 | * if some form of movement is allowed, let objects |
861 | * drop on that space. |
864 | * drop on that space. |
862 | */ |
865 | */ |
863 | if (!drop_to_ground |
866 | if (!drop_to_ground |
864 | || !map |
867 | || !map |
865 | || map->in_memory != MAP_IN_MEMORY |
868 | || map->in_memory != MAP_ACTIVE |
866 | || map->nodrop |
869 | || map->nodrop |
867 | || ms ().move_block == MOVE_ALL) |
870 | || ms ().move_block == MOVE_ALL) |
868 | { |
871 | { |
869 | while (inv) |
872 | while (inv) |
870 | { |
873 | { |
… | |
… | |
929 | |
932 | |
930 | freed_map->path = "<freed objects map>"; |
933 | freed_map->path = "<freed objects map>"; |
931 | freed_map->name = "/internal/freed_objects_map"; |
934 | freed_map->name = "/internal/freed_objects_map"; |
932 | freed_map->width = 3; |
935 | freed_map->width = 3; |
933 | freed_map->height = 3; |
936 | freed_map->height = 3; |
|
|
937 | freed_map->nodrop = 1; |
934 | |
938 | |
935 | freed_map->alloc (); |
939 | freed_map->alloc (); |
936 | freed_map->in_memory = MAP_IN_MEMORY; |
940 | freed_map->in_memory = MAP_ACTIVE; |
937 | } |
941 | } |
938 | |
942 | |
939 | map = freed_map; |
943 | map = freed_map; |
940 | x = 1; |
944 | x = 1; |
941 | y = 1; |
945 | y = 1; |
… | |
… | |
1475 | } |
1479 | } |
1476 | |
1480 | |
1477 | object * |
1481 | object * |
1478 | object::insert_at (object *where, object *originator, int flags) |
1482 | object::insert_at (object *where, object *originator, int flags) |
1479 | { |
1483 | { |
|
|
1484 | if (where->env) |
|
|
1485 | return where->env->insert (this); |
|
|
1486 | else |
1480 | return where->map->insert (this, where->x, where->y, originator, flags); |
1487 | return where->map->insert (this, where->x, where->y, originator, flags); |
1481 | } |
1488 | } |
1482 | |
1489 | |
1483 | /* |
1490 | /* |
1484 | * get_split_ob(ob,nr) splits up ob into two parts. The part which |
1491 | * get_split_ob(ob,nr) splits up ob into two parts. The part which |
1485 | * is returned contains nr objects, and the remaining parts contains |
1492 | * is returned contains nr objects, and the remaining parts contains |
… | |
… | |
1505 | orig_ob->destroy (1); |
1512 | orig_ob->destroy (1); |
1506 | else if (!is_removed) |
1513 | else if (!is_removed) |
1507 | { |
1514 | { |
1508 | if (orig_ob->env != NULL) |
1515 | if (orig_ob->env != NULL) |
1509 | sub_weight (orig_ob->env, orig_ob->weight * nr); |
1516 | sub_weight (orig_ob->env, orig_ob->weight * nr); |
1510 | if (orig_ob->env == NULL && orig_ob->map->in_memory != MAP_IN_MEMORY) |
1517 | if (orig_ob->env == NULL && orig_ob->map->in_memory != MAP_ACTIVE) |
1511 | { |
1518 | { |
1512 | strcpy (errmsg, "Tried to split object whose map is not in memory."); |
1519 | strcpy (errmsg, "Tried to split object whose map is not in memory."); |
1513 | LOG (llevDebug, "Error, Tried to split object whose map is not in memory.\n"); |
1520 | LOG (llevDebug, "Error, Tried to split object whose map is not in memory.\n"); |
1514 | return NULL; |
1521 | return NULL; |
1515 | } |
1522 | } |
… | |
… | |
1952 | * activate recursively a flag on an object inventory |
1959 | * activate recursively a flag on an object inventory |
1953 | */ |
1960 | */ |
1954 | void |
1961 | void |
1955 | flag_inv (object *op, int flag) |
1962 | flag_inv (object *op, int flag) |
1956 | { |
1963 | { |
1957 | if (op->inv) |
|
|
1958 | for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below) |
1964 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1959 | { |
1965 | { |
1960 | SET_FLAG (tmp, flag); |
1966 | SET_FLAG (tmp, flag); |
1961 | flag_inv (tmp, flag); |
1967 | flag_inv (tmp, flag); |
1962 | } |
1968 | } |
1963 | } |
1969 | } |
1964 | |
1970 | |
1965 | /* |
1971 | /* |
1966 | * deactivate recursively a flag on an object inventory |
1972 | * deactivate recursively a flag on an object inventory |
1967 | */ |
1973 | */ |
1968 | void |
1974 | void |
1969 | unflag_inv (object *op, int flag) |
1975 | unflag_inv (object *op, int flag) |
1970 | { |
1976 | { |
1971 | if (op->inv) |
|
|
1972 | for (object *tmp = op->inv; tmp != NULL; tmp = tmp->below) |
1977 | for (object *tmp = op->inv; tmp; tmp = tmp->below) |
1973 | { |
1978 | { |
1974 | CLEAR_FLAG (tmp, flag); |
1979 | CLEAR_FLAG (tmp, flag); |
1975 | unflag_inv (tmp, flag); |
1980 | unflag_inv (tmp, flag); |
1976 | } |
1981 | } |
1977 | } |
1982 | } |
1978 | |
1983 | |
1979 | /* |
1984 | /* |
1980 | * find_free_spot(object, map, x, y, start, stop) will search for |
1985 | * find_free_spot(object, map, x, y, start, stop) will search for |
1981 | * a spot at the given map and coordinates which will be able to contain |
1986 | * a spot at the given map and coordinates which will be able to contain |
… | |
… | |
1983 | * to search (see the freearr_x/y[] definition). |
1988 | * to search (see the freearr_x/y[] definition). |
1984 | * It returns a random choice among the alternatives found. |
1989 | * It returns a random choice among the alternatives found. |
1985 | * start and stop are where to start relative to the free_arr array (1,9 |
1990 | * start and stop are where to start relative to the free_arr array (1,9 |
1986 | * does all 4 immediate directions). This returns the index into the |
1991 | * does all 4 immediate directions). This returns the index into the |
1987 | * array of the free spot, -1 if no spot available (dir 0 = x,y) |
1992 | * array of the free spot, -1 if no spot available (dir 0 = x,y) |
1988 | * Note - this only checks to see if there is space for the head of the |
|
|
1989 | * object - if it is a multispace object, this should be called for all |
|
|
1990 | * pieces. |
|
|
1991 | * Note2: This function does correctly handle tiled maps, but does not |
1993 | * Note: This function does correctly handle tiled maps, but does not |
1992 | * inform the caller. However, insert_ob_in_map will update as |
1994 | * inform the caller. However, insert_ob_in_map will update as |
1993 | * necessary, so the caller shouldn't need to do any special work. |
1995 | * necessary, so the caller shouldn't need to do any special work. |
1994 | * Note - updated to take an object instead of archetype - this is necessary |
1996 | * Note - updated to take an object instead of archetype - this is necessary |
1995 | * because arch_blocked (now ob_blocked) needs to know the movement type |
1997 | * because arch_blocked (now ob_blocked) needs to know the movement type |
1996 | * to know if the space in question will block the object. We can't use |
1998 | * to know if the space in question will block the object. We can't use |
… | |
… | |
2017 | |
2019 | |
2018 | /* However, often |
2020 | /* However, often |
2019 | * ob doesn't have any move type (when used to place exits) |
2021 | * ob doesn't have any move type (when used to place exits) |
2020 | * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work. |
2022 | * so the AND operation in OB_TYPE_MOVE_BLOCK doesn't work. |
2021 | */ |
2023 | */ |
2022 | if (ob->move_type == 0 && ms.move_block != MOVE_ALL) |
2024 | if (ob && ob->move_type == 0 && ms.move_block != MOVE_ALL) |
2023 | { |
2025 | { |
2024 | altern [index++] = i; |
2026 | altern [index++] = i; |
2025 | continue; |
2027 | continue; |
2026 | } |
2028 | } |
2027 | |
2029 | |
… | |
… | |
2041 | |
2043 | |
2042 | /* Note it is intentional that we check ob - the movement type of the |
2044 | /* Note it is intentional that we check ob - the movement type of the |
2043 | * head of the object should correspond for the entire object. |
2045 | * head of the object should correspond for the entire object. |
2044 | */ |
2046 | */ |
2045 | if (OB_TYPE_MOVE_BLOCK (ob, ms.move_block)) |
2047 | if (OB_TYPE_MOVE_BLOCK (ob, ms.move_block)) |
|
|
2048 | continue; |
|
|
2049 | |
|
|
2050 | if (ob->blocked (m, pos.x, pos.y)) |
2046 | continue; |
2051 | continue; |
2047 | |
2052 | |
2048 | altern [index++] = i; |
2053 | altern [index++] = i; |
2049 | } |
2054 | } |
2050 | |
2055 | |
… | |
… | |
2609 | { |
2614 | { |
2610 | char flagdesc[512]; |
2615 | char flagdesc[512]; |
2611 | char info2[256 * 4]; |
2616 | char info2[256 * 4]; |
2612 | char *p = info; |
2617 | char *p = info; |
2613 | |
2618 | |
2614 | p += snprintf (p, 512, "{cnt:%d,uuid:<1.%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2619 | p += snprintf (p, 512, "{cnt:%d,uuid:%s,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2615 | count, uuid.seq, |
2620 | count, |
|
|
2621 | uuid.c_str (), |
2616 | &name, |
2622 | &name, |
2617 | title ? "\",title:\"" : "", |
2623 | title ? "\",title:\"" : "", |
2618 | title ? (const char *)title : "", |
2624 | title ? (const char *)title : "", |
2619 | flag_desc (flagdesc, 512), type); |
2625 | flag_desc (flagdesc, 512), type); |
2620 | |
2626 | |