… | |
… | |
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. */ |
|
|
27 | |
27 | #include <global.h> |
28 | #include <global.h> |
28 | #include <stdio.h> |
29 | #include <stdio.h> |
29 | #include <sys/types.h> |
30 | #include <sys/types.h> |
30 | #include <sys/uio.h> |
31 | #include <sys/uio.h> |
31 | #include <object.h> |
32 | #include <object.h> |
… | |
… | |
34 | #include <loader.h> |
35 | #include <loader.h> |
35 | |
36 | |
36 | #include <bitset> |
37 | #include <bitset> |
37 | |
38 | |
38 | UUID UUID::cur; |
39 | UUID UUID::cur; |
|
|
40 | static uint64_t seq_next_save; |
39 | static const uint64 UUID_SKIP = 1<<19; |
41 | static const uint64 UUID_GAP = 1<<19; |
40 | |
42 | |
41 | objectvec objects; |
43 | objectvec objects; |
42 | activevec actives; |
44 | activevec actives; |
43 | |
45 | |
44 | 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, |
46 | short freearr_x[SIZEOFFREE] = { |
|
|
47 | 0, |
|
|
48 | 0, 1, 1, 1, 0, -1, -1, -1, |
|
|
49 | 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, -2, -2, -2, -1, |
45 | 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 |
50 | 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -3, -3, -3, -2, -1 |
46 | }; |
51 | }; |
47 | 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, |
52 | short freearr_y[SIZEOFFREE] = { |
|
|
53 | 0, |
|
|
54 | -1, -1, 0, 1, 1, 1, 0, -1, |
|
|
55 | -2, -2, -2, -1, 0, 1, 2, 2, 2, 2, 2, 1, 0, -1, -2, -2, |
48 | -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3 |
56 | -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3 |
49 | }; |
57 | }; |
50 | 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, |
58 | int maxfree[SIZEOFFREE] = { |
|
|
59 | 0, |
|
|
60 | 9, 10, 13, 14, 17, 18, 21, 22, |
|
|
61 | 25, 26, 27, 30, 31, 32, 33, 36, 37, 39, 39, 42, 43, 44, 45, 48, |
51 | 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 |
62 | 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49, 49 |
52 | }; |
63 | }; |
53 | int freedir[SIZEOFFREE] = { |
64 | int freedir[SIZEOFFREE] = { |
54 | 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, |
65 | 0, |
|
|
66 | 1, 2, 3, 4, 5, 6, 7, 8, |
|
|
67 | 1, 2, 2, 2, 3, 4, 4, 4, 5, 6, 6, 6, 7, 8, 8, 8, |
55 | 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 |
68 | 1, 2, 2, 2, 2, 2, 3, 4, 4, 4, 4, 4, 5, 6, 6, 6, 6, 6, 7, 8, 8, 8, 8, 8 |
56 | }; |
69 | }; |
57 | |
70 | |
58 | static void |
71 | static void |
59 | write_uuid (void) |
72 | write_uuid (uval64 skip, bool sync) |
60 | { |
73 | { |
61 | char filename1[MAX_BUF], filename2[MAX_BUF]; |
74 | CALL_BEGIN (2); |
62 | |
75 | CALL_ARG_SV (newSVval64 (skip)); |
63 | sprintf (filename1, "%s/uuid", settings.localdir); |
76 | CALL_ARG_SV (boolSV (sync)); |
64 | sprintf (filename2, "%s/uuid~", settings.localdir); |
77 | CALL_CALL ("cf::write_uuid", G_DISCARD); |
65 | |
78 | CALL_END; |
66 | FILE *fp; |
|
|
67 | |
|
|
68 | if (!(fp = fopen (filename2, "w"))) |
|
|
69 | { |
|
|
70 | LOG (llevError, "ERROR: cannot open %s for writing, unable to write UUID!\n", filename2); |
|
|
71 | return; |
|
|
72 | } |
|
|
73 | |
|
|
74 | fprintf (fp, "<1,%llx>\n", (unsigned long long)UUID::cur.seq + UUID_SKIP * 2); |
|
|
75 | fclose (fp); |
|
|
76 | rename (filename2, filename1); |
|
|
77 | } |
79 | } |
78 | |
80 | |
79 | static void |
81 | static void |
80 | read_uuid (void) |
82 | read_uuid (void) |
81 | { |
83 | { |
82 | char filename[MAX_BUF]; |
84 | char filename[MAX_BUF]; |
83 | |
85 | |
84 | sprintf (filename, "%s/uuid", settings.localdir); |
86 | sprintf (filename, "%s/uuid", settings.localdir); |
85 | |
87 | |
|
|
88 | seq_next_save = 0; |
|
|
89 | |
86 | FILE *fp; |
90 | FILE *fp; |
87 | |
91 | |
88 | if (!(fp = fopen (filename, "r"))) |
92 | if (!(fp = fopen (filename, "r"))) |
89 | { |
93 | { |
90 | if (errno == ENOENT) |
94 | if (errno == ENOENT) |
91 | { |
95 | { |
92 | LOG (llevInfo, "RESET uid to 1\n"); |
96 | LOG (llevInfo, "RESET uid to 1\n"); |
93 | UUID::cur.seq = 0; |
97 | UUID::cur.seq = 0; |
94 | write_uuid (); |
98 | write_uuid (UUID_GAP, true); |
95 | return; |
99 | return; |
96 | } |
100 | } |
97 | |
101 | |
98 | LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); |
102 | LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); |
99 | _exit (1); |
103 | _exit (1); |
100 | } |
104 | } |
101 | |
105 | |
102 | int version; |
106 | UUID::BUF buf; |
103 | unsigned long long uid; |
107 | buf[0] = 0; |
104 | if (2 != fscanf (fp, "<%d,%llx>\n", &version, &uid) || version != 1) |
108 | fgets (buf, sizeof (buf), fp); |
|
|
109 | |
|
|
110 | if (!UUID::cur.parse (buf)) |
105 | { |
111 | { |
106 | LOG (llevError, "FATAL: error reading uid from %s!\n", filename); |
112 | LOG (llevError, "FATAL: error reading uid from %s (%s)!\n", filename, buf); |
107 | _exit (1); |
113 | _exit (1); |
108 | } |
114 | } |
109 | |
115 | |
110 | UUID::cur.seq = uid; |
116 | LOG (llevDebug, "read UUID: %s\n", UUID::cur.c_str ()); |
111 | write_uuid (); |
117 | |
112 | LOG (llevDebug, "read UID: %" PRId64 "\n", uid); |
118 | write_uuid (UUID_GAP, true); |
113 | fclose (fp); |
119 | fclose (fp); |
114 | } |
120 | } |
115 | |
121 | |
116 | UUID |
122 | UUID |
117 | UUID::gen () |
123 | UUID::gen () |
118 | { |
124 | { |
119 | UUID uid; |
125 | UUID uid; |
120 | |
126 | |
121 | uid.seq = ++cur.seq; |
127 | uid.seq = ++cur.seq; |
122 | |
128 | |
123 | if (!(cur.seq & (UUID_SKIP - 1))) |
129 | if (expect_false (cur.seq >= seq_next_save)) |
124 | write_uuid (); |
130 | { |
|
|
131 | seq_next_save = UUID::cur.seq + (UUID_GAP >> 1); |
|
|
132 | write_uuid (UUID_GAP, false); |
|
|
133 | } |
|
|
134 | |
125 | |
135 | |
126 | return uid; |
136 | return uid; |
127 | } |
137 | } |
128 | |
138 | |
129 | void |
139 | void |
… | |
… | |
131 | { |
141 | { |
132 | read_uuid (); |
142 | read_uuid (); |
133 | } |
143 | } |
134 | |
144 | |
135 | /* Returns TRUE if every key_values in wants has a partner with the same value in has. */ |
145 | /* Returns TRUE if every key_values in wants has a partner with the same value in has. */ |
136 | static int |
146 | static bool |
137 | compare_ob_value_lists_one (const object *wants, const object *has) |
147 | compare_ob_value_lists_one (const object *wants, const object *has) |
138 | { |
148 | { |
139 | key_value *wants_field; |
149 | key_value *wants_field; |
140 | |
150 | |
141 | /* n-squared behaviour (see get_ob_key_link()), but I'm hoping both |
151 | /* n-squared behaviour (see get_ob_key_link()), but I'm hoping both |
… | |
… | |
149 | key_value *has_field; |
159 | key_value *has_field; |
150 | |
160 | |
151 | /* Look for a field in has with the same key. */ |
161 | /* Look for a field in has with the same key. */ |
152 | has_field = get_ob_key_link (has, wants_field->key); |
162 | has_field = get_ob_key_link (has, wants_field->key); |
153 | |
163 | |
154 | if (has_field == NULL) |
164 | if (!has_field) |
155 | { |
|
|
156 | /* No field with that name. */ |
165 | return 0; /* No field with that name. */ |
157 | return FALSE; |
|
|
158 | } |
|
|
159 | |
166 | |
160 | /* Found the matching field. */ |
167 | /* Found the matching field. */ |
161 | if (has_field->value != wants_field->value) |
168 | if (has_field->value != wants_field->value) |
162 | { |
|
|
163 | /* Values don't match, so this half of the comparison is false. */ |
169 | return 0; /* Values don't match, so this half of the comparison is false. */ |
164 | return FALSE; |
|
|
165 | } |
|
|
166 | |
170 | |
167 | /* If we get here, we found a match. Now for the next field in wants. */ |
171 | /* If we get here, we found a match. Now for the next field in wants. */ |
168 | } |
172 | } |
169 | |
173 | |
170 | /* If we get here, every field in wants has a matching field in has. */ |
174 | /* If we get here, every field in wants has a matching field in has. */ |
171 | return TRUE; |
175 | return 1; |
172 | } |
176 | } |
173 | |
177 | |
174 | /* Returns TRUE if ob1 has the same key_values as ob2. */ |
178 | /* Returns TRUE if ob1 has the same key_values as ob2. */ |
175 | static int |
179 | static bool |
176 | compare_ob_value_lists (const object *ob1, const object *ob2) |
180 | compare_ob_value_lists (const object *ob1, const object *ob2) |
177 | { |
181 | { |
178 | /* However, there may be fields in has which aren't partnered in wants, |
182 | /* However, there may be fields in has which aren't partnered in wants, |
179 | * so we need to run the comparison *twice*. :( |
183 | * so we need to run the comparison *twice*. :( |
180 | */ |
184 | */ |
… | |
… | |
201 | || ob1->speed != ob2->speed |
205 | || ob1->speed != ob2->speed |
202 | || ob1->value != ob2->value |
206 | || ob1->value != ob2->value |
203 | || ob1->name != ob2->name) |
207 | || ob1->name != ob2->name) |
204 | return 0; |
208 | return 0; |
205 | |
209 | |
206 | //TODO: this ain't working well, use nicer and correct overflow check |
210 | /* Do not merge objects if nrof would overflow. First part checks |
207 | /* Do not merge objects if nrof would overflow. We use 1UL<<31 since that |
211 | * for unsigned overflow (2c), second part checks wether the result |
208 | * value could not be stored in a sint32 (which unfortunately sometimes is |
212 | * would fit into a 32 bit signed int, which is often used to hold |
209 | * used to store nrof). |
213 | * nrof values. |
210 | */ |
214 | */ |
211 | if (ob1->nrof + ob2->nrof >= 1UL << 31) |
215 | if (~ob1->nrof < ob2->nrof || ob1->nrof + ob2->nrof > (1UL << 31)) |
212 | return 0; |
216 | return 0; |
213 | |
217 | |
214 | /* If the objects have been identified, set the BEEN_APPLIED flag. |
218 | /* If the objects have been identified, set the BEEN_APPLIED flag. |
215 | * This is to the comparison of the flags below will be OK. We |
219 | * This is to the comparison of the flags below will be OK. We |
216 | * just can't ignore the been applied or identified flags, as they |
220 | * just can't ignore the been applied or identified flags, as they |
217 | * are not equal - just if it has been identified, the been_applied |
221 | * are not equal - just if it has been identified, the been_applied |
218 | * flags lose any meaning. |
222 | * flags lose any meaning. |
219 | */ |
223 | */ |
220 | if (QUERY_FLAG (ob1, FLAG_IDENTIFIED)) |
224 | if (QUERY_FLAG (ob1, FLAG_IDENTIFIED)) |
… | |
… | |
248 | || ob1->move_off != ob2->move_off |
252 | || ob1->move_off != ob2->move_off |
249 | || ob1->move_slow != ob2->move_slow |
253 | || ob1->move_slow != ob2->move_slow |
250 | || ob1->move_slow_penalty != ob2->move_slow_penalty) |
254 | || ob1->move_slow_penalty != ob2->move_slow_penalty) |
251 | return 0; |
255 | return 0; |
252 | |
256 | |
253 | /* This is really a spellbook check - really, we should |
257 | /* This is really a spellbook check - we should in general |
254 | * check all objects in the inventory. |
258 | * not merge objects with real inventories, as splitting them |
|
|
259 | * is hard. |
255 | */ |
260 | */ |
256 | if (ob1->inv || ob2->inv) |
261 | if (ob1->inv || ob2->inv) |
257 | { |
262 | { |
258 | if (!(ob1->inv && ob2->inv)) |
263 | if (!(ob1->inv && ob2->inv)) |
259 | return 0; /* inventories differ in length */ |
264 | return 0; /* inventories differ in length */ |
260 | |
265 | |
261 | if (ob1->inv->below || ob2->inv->below) |
266 | if (ob1->inv->below || ob2->inv->below) |
262 | return 0; /* more than one object in inv */ |
267 | return 0; /* more than one object in inv */ |
263 | |
268 | |
264 | if (!object::can_merge (ob1->inv, ob2->inv)) |
269 | if (!object::can_merge (ob1->inv, ob2->inv)) |
265 | return 0; /* inventory objexts differ */ |
270 | return 0; /* inventory objects differ */ |
266 | |
271 | |
267 | /* inventory ok - still need to check rest of this object to see |
272 | /* inventory ok - still need to check rest of this object to see |
268 | * if it is valid. |
273 | * if it is valid. |
269 | */ |
274 | */ |
270 | } |
275 | } |
… | |
… | |
289 | if (ob1->level != ob2->level) |
294 | if (ob1->level != ob2->level) |
290 | return 0; |
295 | return 0; |
291 | break; |
296 | break; |
292 | } |
297 | } |
293 | |
298 | |
294 | if (ob1->key_values != NULL || ob2->key_values != NULL) |
299 | if (ob1->key_values || ob2->key_values) |
295 | { |
300 | { |
296 | /* At least one of these has key_values. */ |
301 | /* At least one of these has key_values. */ |
297 | if ((ob1->key_values == NULL) != (ob2->key_values == NULL)) |
302 | if ((!ob1->key_values) != (!ob2->key_values)) |
298 | /* One has fields, but the other one doesn't. */ |
303 | /* One has fields, but the other one doesn't. */ |
299 | return 0; |
304 | return 0; |
300 | else if (!compare_ob_value_lists (ob1, ob2)) |
305 | else if (!compare_ob_value_lists (ob1, ob2)) |
301 | return 0; |
306 | return 0; |
302 | } |
307 | } |
… | |
… | |
322 | |
327 | |
323 | /* Everything passes, must be OK. */ |
328 | /* Everything passes, must be OK. */ |
324 | return 1; |
329 | return 1; |
325 | } |
330 | } |
326 | |
331 | |
|
|
332 | static sint32 |
|
|
333 | weight_adjust (object *op, sint32 weight) |
|
|
334 | { |
|
|
335 | return op->type == CONTAINER |
|
|
336 | ? lerp (weight, 0, 100, 0, 100 - op->stats.Str) |
|
|
337 | : weight; |
|
|
338 | } |
|
|
339 | |
327 | /* |
340 | /* |
|
|
341 | * add_weight(object, weight) adds the specified weight to an object, |
|
|
342 | * and also updates how much the environment(s) is/are carrying. |
|
|
343 | */ |
|
|
344 | static void |
|
|
345 | add_weight (object *op, sint32 weight) |
|
|
346 | { |
|
|
347 | while (op) |
|
|
348 | { |
|
|
349 | weight = weight_adjust (op, weight); |
|
|
350 | |
|
|
351 | op->carrying += weight; |
|
|
352 | op = op->env; |
|
|
353 | } |
|
|
354 | } |
|
|
355 | |
|
|
356 | /* |
|
|
357 | * sub_weight() recursively (outwards) subtracts a number from the |
|
|
358 | * weight of an object (and what is carried by it's environment(s)). |
|
|
359 | */ |
|
|
360 | static void |
|
|
361 | sub_weight (object *op, long weight) |
|
|
362 | { |
|
|
363 | add_weight (op, -weight); |
|
|
364 | } |
|
|
365 | |
|
|
366 | /* |
328 | * sum_weight() is a recursive function which calculates the weight |
367 | * this is a recursive function which calculates the weight |
329 | * an object is carrying. It goes through in figures out how much |
368 | * an object is carrying. It goes through op and figures out how much |
330 | * containers are carrying, and sums it up. |
369 | * containers are carrying, and sums it up. |
331 | */ |
370 | */ |
332 | long |
371 | void |
333 | sum_weight (object *op) |
372 | object::update_weight () |
334 | { |
373 | { |
335 | long sum; |
374 | sint32 sum = 0; |
336 | object *inv; |
|
|
337 | |
375 | |
338 | for (sum = 0, inv = op->inv; inv; inv = inv->below) |
376 | for (object *op = inv; op; op = op->below) |
339 | { |
377 | { |
340 | if (inv->inv) |
378 | if (op->inv) |
341 | sum_weight (inv); |
379 | op->update_weight (); |
342 | |
380 | |
343 | sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1); |
381 | sum += op->total_weight (); |
344 | } |
382 | } |
345 | |
383 | |
346 | if (op->type == CONTAINER && op->stats.Str) |
384 | carrying = weight_adjust (this, sum); |
347 | sum = (sum * (100 - op->stats.Str)) / 100; |
|
|
348 | |
|
|
349 | if (op->carrying != sum) |
|
|
350 | op->carrying = sum; |
|
|
351 | |
|
|
352 | return sum; |
|
|
353 | } |
|
|
354 | |
|
|
355 | /** |
|
|
356 | * Return the outermost environment object for a given object. |
|
|
357 | */ |
|
|
358 | |
|
|
359 | object * |
|
|
360 | object_get_env_recursive (object *op) |
|
|
361 | { |
|
|
362 | while (op->env != NULL) |
|
|
363 | op = op->env; |
|
|
364 | return op; |
|
|
365 | } |
385 | } |
366 | |
386 | |
367 | /* |
387 | /* |
368 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
388 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
369 | * Some error messages. |
389 | * Some error messages. |
… | |
… | |
859 | * if some form of movement is allowed, let objects |
879 | * if some form of movement is allowed, let objects |
860 | * drop on that space. |
880 | * drop on that space. |
861 | */ |
881 | */ |
862 | if (!drop_to_ground |
882 | if (!drop_to_ground |
863 | || !map |
883 | || !map |
864 | || map->in_memory != MAP_IN_MEMORY |
884 | || map->in_memory != MAP_ACTIVE |
865 | || map->nodrop |
885 | || map->nodrop |
866 | || ms ().move_block == MOVE_ALL) |
886 | || ms ().move_block == MOVE_ALL) |
867 | { |
887 | { |
868 | while (inv) |
888 | while (inv) |
869 | { |
889 | { |
… | |
… | |
931 | freed_map->width = 3; |
951 | freed_map->width = 3; |
932 | freed_map->height = 3; |
952 | freed_map->height = 3; |
933 | freed_map->nodrop = 1; |
953 | freed_map->nodrop = 1; |
934 | |
954 | |
935 | freed_map->alloc (); |
955 | freed_map->alloc (); |
936 | freed_map->in_memory = MAP_IN_MEMORY; |
956 | freed_map->in_memory = MAP_ACTIVE; |
937 | } |
957 | } |
938 | |
958 | |
939 | map = freed_map; |
959 | map = freed_map; |
940 | x = 1; |
960 | x = 1; |
941 | y = 1; |
961 | y = 1; |
… | |
… | |
970 | play_sound (sound_destroy); |
990 | play_sound (sound_destroy); |
971 | else if (flag [FLAG_MONSTER]) |
991 | else if (flag [FLAG_MONSTER]) |
972 | play_sound (sound_find ("monster_destroy")); // quick hack, too lazy to create a generic mechanism |
992 | play_sound (sound_find ("monster_destroy")); // quick hack, too lazy to create a generic mechanism |
973 | |
993 | |
974 | attachable::destroy (); |
994 | attachable::destroy (); |
975 | } |
|
|
976 | |
|
|
977 | /* |
|
|
978 | * sub_weight() recursively (outwards) subtracts a number from the |
|
|
979 | * weight of an object (and what is carried by it's environment(s)). |
|
|
980 | */ |
|
|
981 | void |
|
|
982 | sub_weight (object *op, signed long weight) |
|
|
983 | { |
|
|
984 | while (op != NULL) |
|
|
985 | { |
|
|
986 | if (op->type == CONTAINER) |
|
|
987 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
|
|
988 | |
|
|
989 | op->carrying -= weight; |
|
|
990 | op = op->env; |
|
|
991 | } |
|
|
992 | } |
995 | } |
993 | |
996 | |
994 | /* op->remove (): |
997 | /* op->remove (): |
995 | * This function removes the object op from the linked list of objects |
998 | * This function removes the object op from the linked list of objects |
996 | * which it is currently tied to. When this function is done, the |
999 | * which it is currently tied to. When this function is done, the |
… | |
… | |
1475 | } |
1478 | } |
1476 | |
1479 | |
1477 | object * |
1480 | object * |
1478 | object::insert_at (object *where, object *originator, int flags) |
1481 | object::insert_at (object *where, object *originator, int flags) |
1479 | { |
1482 | { |
|
|
1483 | if (where->env) |
|
|
1484 | return where->env->insert (this); |
|
|
1485 | else |
1480 | return where->map->insert (this, where->x, where->y, originator, flags); |
1486 | return where->map->insert (this, where->x, where->y, originator, flags); |
1481 | } |
1487 | } |
1482 | |
1488 | |
1483 | /* |
1489 | /* |
1484 | * get_split_ob(ob,nr) splits up ob into two parts. The part which |
1490 | * 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 |
1491 | * is returned contains nr objects, and the remaining parts contains |
… | |
… | |
1505 | orig_ob->destroy (1); |
1511 | orig_ob->destroy (1); |
1506 | else if (!is_removed) |
1512 | else if (!is_removed) |
1507 | { |
1513 | { |
1508 | if (orig_ob->env != NULL) |
1514 | if (orig_ob->env != NULL) |
1509 | sub_weight (orig_ob->env, orig_ob->weight * nr); |
1515 | sub_weight (orig_ob->env, orig_ob->weight * nr); |
1510 | if (orig_ob->env == NULL && orig_ob->map->in_memory != MAP_IN_MEMORY) |
1516 | if (orig_ob->env == NULL && orig_ob->map->in_memory != MAP_ACTIVE) |
1511 | { |
1517 | { |
1512 | strcpy (errmsg, "Tried to split object whose map is not in memory."); |
1518 | 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"); |
1519 | LOG (llevDebug, "Error, Tried to split object whose map is not in memory.\n"); |
1514 | return NULL; |
1520 | return NULL; |
1515 | } |
1521 | } |
… | |
… | |
1602 | return op; |
1608 | return op; |
1603 | else |
1609 | else |
1604 | { |
1610 | { |
1605 | op->destroy (); |
1611 | op->destroy (); |
1606 | return 0; |
1612 | return 0; |
1607 | } |
|
|
1608 | } |
|
|
1609 | |
|
|
1610 | /* |
|
|
1611 | * add_weight(object, weight) adds the specified weight to an object, |
|
|
1612 | * and also updates how much the environment(s) is/are carrying. |
|
|
1613 | */ |
|
|
1614 | void |
|
|
1615 | add_weight (object *op, signed long weight) |
|
|
1616 | { |
|
|
1617 | while (op != NULL) |
|
|
1618 | { |
|
|
1619 | if (op->type == CONTAINER) |
|
|
1620 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
|
|
1621 | |
|
|
1622 | op->carrying += weight; |
|
|
1623 | op = op->env; |
|
|
1624 | } |
1613 | } |
1625 | } |
1614 | } |
1626 | |
1615 | |
1627 | object * |
1616 | object * |
1628 | insert_ob_in_ob (object *op, object *where) |
1617 | insert_ob_in_ob (object *op, object *where) |
… | |
… | |
2607 | { |
2596 | { |
2608 | char flagdesc[512]; |
2597 | char flagdesc[512]; |
2609 | char info2[256 * 4]; |
2598 | char info2[256 * 4]; |
2610 | char *p = info; |
2599 | char *p = info; |
2611 | |
2600 | |
2612 | p += snprintf (p, 512, "{cnt:%d,uuid:<1.%" PRIx64 ">,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2601 | p += snprintf (p, 512, "{cnt:%d,uuid:%s,name:\"%s\"%s%s,flags:[%s],type:%d}", |
2613 | count, uuid.seq, |
2602 | count, |
|
|
2603 | uuid.c_str (), |
2614 | &name, |
2604 | &name, |
2615 | title ? "\",title:\"" : "", |
2605 | title ? "\",title:\"" : "", |
2616 | title ? (const char *)title : "", |
2606 | title ? (const char *)title : "", |
2617 | flag_desc (flagdesc, 512), type); |
2607 | flag_desc (flagdesc, 512), type); |
2618 | |
2608 | |