… | |
… | |
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> |
… | |
… | |
33 | #include <sproto.h> |
34 | #include <sproto.h> |
34 | #include <loader.h> |
35 | #include <loader.h> |
35 | |
36 | |
36 | #include <bitset> |
37 | #include <bitset> |
37 | |
38 | |
38 | int nrofallocobjects = 0; |
39 | UUID UUID::cur; |
39 | static UUID uuid; |
40 | static uint64_t seq_next_save; |
40 | const uint64 UUID_SKIP = 1<<19; |
41 | static const uint64 UUID_GAP = 1<<19; |
41 | |
42 | |
42 | objectvec objects; |
43 | objectvec objects; |
43 | activevec actives; |
44 | activevec actives; |
44 | |
45 | |
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, |
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, |
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 |
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 |
47 | }; |
51 | }; |
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, |
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, |
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 |
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 |
50 | }; |
57 | }; |
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, |
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, |
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 |
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 |
53 | }; |
63 | }; |
54 | int freedir[SIZEOFFREE] = { |
64 | 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, |
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, |
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 |
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 |
57 | }; |
69 | }; |
58 | |
70 | |
59 | static void |
71 | static void |
60 | write_uuid (void) |
72 | write_uuid (uval64 skip, bool sync) |
61 | { |
73 | { |
62 | char filename1[MAX_BUF], filename2[MAX_BUF]; |
74 | CALL_BEGIN (2); |
63 | |
75 | CALL_ARG_SV (newSVval64 (skip)); |
64 | sprintf (filename1, "%s/uuid", settings.localdir); |
76 | CALL_ARG_SV (boolSV (sync)); |
65 | sprintf (filename2, "%s/uuid~", settings.localdir); |
77 | CALL_CALL ("cf::write_uuid", G_DISCARD); |
66 | |
78 | 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 | } |
79 | } |
79 | |
80 | |
80 | static void |
81 | static void |
81 | read_uuid (void) |
82 | read_uuid (void) |
82 | { |
83 | { |
83 | char filename[MAX_BUF]; |
84 | char filename[MAX_BUF]; |
84 | |
85 | |
85 | sprintf (filename, "%s/uuid", settings.localdir); |
86 | sprintf (filename, "%s/uuid", settings.localdir); |
86 | |
87 | |
|
|
88 | seq_next_save = 0; |
|
|
89 | |
87 | FILE *fp; |
90 | FILE *fp; |
88 | |
91 | |
89 | if (!(fp = fopen (filename, "r"))) |
92 | if (!(fp = fopen (filename, "r"))) |
90 | { |
93 | { |
91 | if (errno == ENOENT) |
94 | if (errno == ENOENT) |
92 | { |
95 | { |
93 | LOG (llevInfo, "RESET uid to 1\n"); |
96 | LOG (llevInfo, "RESET uid to 1\n"); |
94 | uuid.seq = 0; |
97 | UUID::cur.seq = 0; |
95 | write_uuid (); |
98 | write_uuid (UUID_GAP, true); |
96 | return; |
99 | return; |
97 | } |
100 | } |
98 | |
101 | |
99 | LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); |
102 | LOG (llevError, "FATAL: cannot open %s for reading!\n", filename); |
100 | _exit (1); |
103 | _exit (1); |
101 | } |
104 | } |
102 | |
105 | |
103 | int version; |
106 | UUID::BUF buf; |
104 | unsigned long long uid; |
107 | buf[0] = 0; |
105 | if (2 != fscanf (fp, "<%d,%llx>\n", &version, &uid) || version != 1) |
108 | fgets (buf, sizeof (buf), fp); |
|
|
109 | |
|
|
110 | if (!UUID::cur.parse (buf)) |
106 | { |
111 | { |
107 | LOG (llevError, "FATAL: error reading uid from %s!\n", filename); |
112 | LOG (llevError, "FATAL: error reading uid from %s (%s)!\n", filename, buf); |
108 | _exit (1); |
113 | _exit (1); |
109 | } |
114 | } |
110 | |
115 | |
111 | uuid.seq = uid; |
116 | LOG (llevDebug, "read UUID: %s\n", UUID::cur.c_str ()); |
112 | write_uuid (); |
117 | |
113 | LOG (llevDebug, "read UID: %" PRId64 "\n", uid); |
118 | write_uuid (UUID_GAP, true); |
114 | fclose (fp); |
119 | fclose (fp); |
115 | } |
120 | } |
116 | |
121 | |
117 | UUID |
122 | UUID |
118 | gen_uuid () |
123 | UUID::gen () |
119 | { |
124 | { |
120 | UUID uid; |
125 | UUID uid; |
121 | |
126 | |
122 | uid.seq = ++uuid.seq; |
127 | uid.seq = ++cur.seq; |
123 | |
128 | |
124 | if (!(uuid.seq & (UUID_SKIP - 1))) |
129 | if (expect_false (cur.seq >= seq_next_save)) |
125 | write_uuid (); |
130 | { |
|
|
131 | seq_next_save = UUID::cur.seq + (UUID_GAP >> 1); |
|
|
132 | write_uuid (UUID_GAP, false); |
|
|
133 | } |
|
|
134 | |
126 | |
135 | |
127 | return uid; |
136 | return uid; |
128 | } |
137 | } |
129 | |
138 | |
130 | void |
139 | void |
131 | init_uuid () |
140 | UUID::init () |
132 | { |
141 | { |
133 | read_uuid (); |
142 | read_uuid (); |
134 | } |
143 | } |
135 | |
144 | |
136 | /* 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. */ |
137 | static int |
146 | static bool |
138 | compare_ob_value_lists_one (const object *wants, const object *has) |
147 | compare_ob_value_lists_one (const object *wants, const object *has) |
139 | { |
148 | { |
140 | key_value *wants_field; |
149 | key_value *wants_field; |
141 | |
150 | |
142 | /* 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 |
… | |
… | |
150 | key_value *has_field; |
159 | key_value *has_field; |
151 | |
160 | |
152 | /* Look for a field in has with the same key. */ |
161 | /* Look for a field in has with the same key. */ |
153 | has_field = get_ob_key_link (has, wants_field->key); |
162 | has_field = get_ob_key_link (has, wants_field->key); |
154 | |
163 | |
155 | if (has_field == NULL) |
164 | if (!has_field) |
156 | { |
|
|
157 | /* No field with that name. */ |
165 | return 0; /* No field with that name. */ |
158 | return FALSE; |
|
|
159 | } |
|
|
160 | |
166 | |
161 | /* Found the matching field. */ |
167 | /* Found the matching field. */ |
162 | if (has_field->value != wants_field->value) |
168 | if (has_field->value != wants_field->value) |
163 | { |
|
|
164 | /* 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. */ |
165 | return FALSE; |
|
|
166 | } |
|
|
167 | |
170 | |
168 | /* 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. */ |
169 | } |
172 | } |
170 | |
173 | |
171 | /* 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. */ |
172 | return TRUE; |
175 | return 1; |
173 | } |
176 | } |
174 | |
177 | |
175 | /* Returns TRUE if ob1 has the same key_values as ob2. */ |
178 | /* Returns TRUE if ob1 has the same key_values as ob2. */ |
176 | static int |
179 | static bool |
177 | compare_ob_value_lists (const object *ob1, const object *ob2) |
180 | compare_ob_value_lists (const object *ob1, const object *ob2) |
178 | { |
181 | { |
179 | /* 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, |
180 | * so we need to run the comparison *twice*. :( |
183 | * so we need to run the comparison *twice*. :( |
181 | */ |
184 | */ |
… | |
… | |
202 | || ob1->speed != ob2->speed |
205 | || ob1->speed != ob2->speed |
203 | || ob1->value != ob2->value |
206 | || ob1->value != ob2->value |
204 | || ob1->name != ob2->name) |
207 | || ob1->name != ob2->name) |
205 | return 0; |
208 | return 0; |
206 | |
209 | |
207 | //TODO: this ain't working well, use nicer and correct overflow check |
210 | /* 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 |
211 | * for unsigned overflow (2c), second part checks wether the result |
209 | * 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 |
210 | * used to store nrof). |
213 | * nrof values. |
211 | */ |
214 | */ |
212 | if (ob1->nrof + ob2->nrof >= 1UL << 31) |
215 | if (~ob1->nrof < ob2->nrof || ob1->nrof + ob2->nrof > (1UL << 31)) |
213 | return 0; |
216 | return 0; |
214 | |
217 | |
215 | /* If the objects have been identified, set the BEEN_APPLIED flag. |
218 | /* 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 |
219 | * 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 |
220 | * 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 |
221 | * are not equal - just if it has been identified, the been_applied |
219 | * flags lose any meaning. |
222 | * flags lose any meaning. |
220 | */ |
223 | */ |
221 | if (QUERY_FLAG (ob1, FLAG_IDENTIFIED)) |
224 | if (QUERY_FLAG (ob1, FLAG_IDENTIFIED)) |
… | |
… | |
249 | || ob1->move_off != ob2->move_off |
252 | || ob1->move_off != ob2->move_off |
250 | || ob1->move_slow != ob2->move_slow |
253 | || ob1->move_slow != ob2->move_slow |
251 | || ob1->move_slow_penalty != ob2->move_slow_penalty) |
254 | || ob1->move_slow_penalty != ob2->move_slow_penalty) |
252 | return 0; |
255 | return 0; |
253 | |
256 | |
254 | /* This is really a spellbook check - really, we should |
257 | /* This is really a spellbook check - we should in general |
255 | * check all objects in the inventory. |
258 | * not merge objects with real inventories, as splitting them |
|
|
259 | * is hard. |
256 | */ |
260 | */ |
257 | if (ob1->inv || ob2->inv) |
261 | if (ob1->inv || ob2->inv) |
258 | { |
262 | { |
259 | if (!(ob1->inv && ob2->inv)) |
263 | if (!(ob1->inv && ob2->inv)) |
260 | return 0; /* inventories differ in length */ |
264 | return 0; /* inventories differ in length */ |
261 | |
265 | |
262 | if (ob1->inv->below || ob2->inv->below) |
266 | if (ob1->inv->below || ob2->inv->below) |
263 | return 0; /* more than one object in inv */ |
267 | return 0; /* more than one object in inv */ |
264 | |
268 | |
265 | if (!object::can_merge (ob1->inv, ob2->inv)) |
269 | if (!object::can_merge (ob1->inv, ob2->inv)) |
266 | return 0; /* inventory objexts differ */ |
270 | return 0; /* inventory objects differ */ |
267 | |
271 | |
268 | /* 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 |
269 | * if it is valid. |
273 | * if it is valid. |
270 | */ |
274 | */ |
271 | } |
275 | } |
… | |
… | |
290 | if (ob1->level != ob2->level) |
294 | if (ob1->level != ob2->level) |
291 | return 0; |
295 | return 0; |
292 | break; |
296 | break; |
293 | } |
297 | } |
294 | |
298 | |
295 | if (ob1->key_values != NULL || ob2->key_values != NULL) |
299 | if (ob1->key_values || ob2->key_values) |
296 | { |
300 | { |
297 | /* At least one of these has key_values. */ |
301 | /* At least one of these has key_values. */ |
298 | if ((ob1->key_values == NULL) != (ob2->key_values == NULL)) |
302 | if ((!ob1->key_values) != (!ob2->key_values)) |
299 | /* One has fields, but the other one doesn't. */ |
303 | /* One has fields, but the other one doesn't. */ |
300 | return 0; |
304 | return 0; |
301 | else if (!compare_ob_value_lists (ob1, ob2)) |
305 | else if (!compare_ob_value_lists (ob1, ob2)) |
302 | return 0; |
306 | return 0; |
303 | } |
307 | } |
… | |
… | |
323 | |
327 | |
324 | /* Everything passes, must be OK. */ |
328 | /* Everything passes, must be OK. */ |
325 | return 1; |
329 | return 1; |
326 | } |
330 | } |
327 | |
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 | |
328 | /* |
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 | /* |
329 | * sum_weight() is a recursive function which calculates the weight |
367 | * this is a recursive function which calculates the weight |
330 | * 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 |
331 | * containers are carrying, and sums it up. |
369 | * containers are carrying, and sums it up. |
332 | */ |
370 | */ |
333 | long |
371 | void |
334 | sum_weight (object *op) |
372 | object::update_weight () |
335 | { |
373 | { |
336 | long sum; |
374 | sint32 sum = 0; |
337 | object *inv; |
|
|
338 | |
375 | |
339 | for (sum = 0, inv = op->inv; inv; inv = inv->below) |
376 | for (object *op = inv; op; op = op->below) |
340 | { |
377 | { |
341 | if (inv->inv) |
378 | if (op->inv) |
342 | sum_weight (inv); |
379 | op->update_weight (); |
343 | |
380 | |
344 | sum += inv->carrying + inv->weight * (inv->nrof ? inv->nrof : 1); |
381 | sum += op->total_weight (); |
345 | } |
382 | } |
346 | |
383 | |
347 | if (op->type == CONTAINER && op->stats.Str) |
384 | carrying = weight_adjust (this, sum); |
348 | sum = (sum * (100 - op->stats.Str)) / 100; |
|
|
349 | |
|
|
350 | if (op->carrying != sum) |
|
|
351 | op->carrying = sum; |
|
|
352 | |
|
|
353 | return sum; |
|
|
354 | } |
|
|
355 | |
|
|
356 | /** |
|
|
357 | * Return the outermost environment object for a given object. |
|
|
358 | */ |
|
|
359 | |
|
|
360 | object * |
|
|
361 | object_get_env_recursive (object *op) |
|
|
362 | { |
|
|
363 | while (op->env != NULL) |
|
|
364 | op = op->env; |
|
|
365 | return op; |
|
|
366 | } |
385 | } |
367 | |
386 | |
368 | /* |
387 | /* |
369 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
388 | * Used by: Crossedit: dump. Server DM commands: dumpbelow, dump. |
370 | * Some error messages. |
389 | * Some error messages. |
… | |
… | |
427 | for_all_objects (op) |
446 | for_all_objects (op) |
428 | if (op->name == str_) |
447 | if (op->name == str_) |
429 | break; |
448 | break; |
430 | |
449 | |
431 | return op; |
450 | return op; |
432 | } |
|
|
433 | |
|
|
434 | void |
|
|
435 | free_all_object_data () |
|
|
436 | { |
|
|
437 | LOG (llevDebug, "%d allocated objects\n", nrofallocobjects); |
|
|
438 | } |
451 | } |
439 | |
452 | |
440 | /* |
453 | /* |
441 | * Sets the owner and sets the skill and exp pointers to owner's current |
454 | * Sets the owner and sets the skill and exp pointers to owner's current |
442 | * skill and experience objects. |
455 | * skill and experience objects. |
… | |
… | |
603 | |
616 | |
604 | void |
617 | void |
605 | object::instantiate () |
618 | object::instantiate () |
606 | { |
619 | { |
607 | if (!uuid.seq) // HACK |
620 | if (!uuid.seq) // HACK |
608 | uuid = gen_uuid (); |
621 | uuid = UUID::gen (); |
609 | |
622 | |
610 | speed_left = -0.1f; |
623 | speed_left = -0.1f; |
611 | /* copy the body_info to the body_used - this is only really |
624 | /* copy the body_info to the body_used - this is only really |
612 | * need for monsters, but doesn't hurt to do it for everything. |
625 | * need for monsters, but doesn't hurt to do it for everything. |
613 | * by doing so, when a monster is created, it has good starting |
626 | * by doing so, when a monster is created, it has good starting |
… | |
… | |
772 | static int object_count; |
785 | static int object_count; |
773 | |
786 | |
774 | void object::link () |
787 | void object::link () |
775 | { |
788 | { |
776 | assert (!index);//D |
789 | assert (!index);//D |
777 | uuid = gen_uuid (); |
790 | uuid = UUID::gen (); |
778 | count = ++object_count; |
791 | count = ++object_count; |
779 | |
792 | |
780 | refcnt_inc (); |
793 | refcnt_inc (); |
781 | objects.insert (this); |
794 | objects.insert (this); |
782 | } |
795 | } |
… | |
… | |
866 | * if some form of movement is allowed, let objects |
879 | * if some form of movement is allowed, let objects |
867 | * drop on that space. |
880 | * drop on that space. |
868 | */ |
881 | */ |
869 | if (!drop_to_ground |
882 | if (!drop_to_ground |
870 | || !map |
883 | || !map |
871 | || map->in_memory != MAP_IN_MEMORY |
884 | || map->in_memory != MAP_ACTIVE |
872 | || map->nodrop |
885 | || map->nodrop |
873 | || ms ().move_block == MOVE_ALL) |
886 | || ms ().move_block == MOVE_ALL) |
874 | { |
887 | { |
875 | while (inv) |
888 | while (inv) |
876 | { |
889 | { |
… | |
… | |
938 | freed_map->width = 3; |
951 | freed_map->width = 3; |
939 | freed_map->height = 3; |
952 | freed_map->height = 3; |
940 | freed_map->nodrop = 1; |
953 | freed_map->nodrop = 1; |
941 | |
954 | |
942 | freed_map->alloc (); |
955 | freed_map->alloc (); |
943 | freed_map->in_memory = MAP_IN_MEMORY; |
956 | freed_map->in_memory = MAP_ACTIVE; |
944 | } |
957 | } |
945 | |
958 | |
946 | map = freed_map; |
959 | map = freed_map; |
947 | x = 1; |
960 | x = 1; |
948 | y = 1; |
961 | y = 1; |
… | |
… | |
977 | play_sound (sound_destroy); |
990 | play_sound (sound_destroy); |
978 | else if (flag [FLAG_MONSTER]) |
991 | else if (flag [FLAG_MONSTER]) |
979 | 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 |
980 | |
993 | |
981 | attachable::destroy (); |
994 | attachable::destroy (); |
982 | } |
|
|
983 | |
|
|
984 | /* |
|
|
985 | * sub_weight() recursively (outwards) subtracts a number from the |
|
|
986 | * weight of an object (and what is carried by it's environment(s)). |
|
|
987 | */ |
|
|
988 | void |
|
|
989 | sub_weight (object *op, signed long weight) |
|
|
990 | { |
|
|
991 | while (op != NULL) |
|
|
992 | { |
|
|
993 | if (op->type == CONTAINER) |
|
|
994 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
|
|
995 | |
|
|
996 | op->carrying -= weight; |
|
|
997 | op = op->env; |
|
|
998 | } |
|
|
999 | } |
995 | } |
1000 | |
996 | |
1001 | /* op->remove (): |
997 | /* op->remove (): |
1002 | * 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 |
1003 | * 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 |
… | |
… | |
1482 | } |
1478 | } |
1483 | |
1479 | |
1484 | object * |
1480 | object * |
1485 | object::insert_at (object *where, object *originator, int flags) |
1481 | object::insert_at (object *where, object *originator, int flags) |
1486 | { |
1482 | { |
|
|
1483 | if (where->env) |
|
|
1484 | return where->env->insert (this); |
|
|
1485 | else |
1487 | return where->map->insert (this, where->x, where->y, originator, flags); |
1486 | return where->map->insert (this, where->x, where->y, originator, flags); |
1488 | } |
1487 | } |
1489 | |
1488 | |
1490 | /* |
1489 | /* |
1491 | * 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 |
1492 | * is returned contains nr objects, and the remaining parts contains |
1491 | * is returned contains nr objects, and the remaining parts contains |
… | |
… | |
1512 | orig_ob->destroy (1); |
1511 | orig_ob->destroy (1); |
1513 | else if (!is_removed) |
1512 | else if (!is_removed) |
1514 | { |
1513 | { |
1515 | if (orig_ob->env != NULL) |
1514 | if (orig_ob->env != NULL) |
1516 | sub_weight (orig_ob->env, orig_ob->weight * nr); |
1515 | sub_weight (orig_ob->env, orig_ob->weight * nr); |
1517 | 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) |
1518 | { |
1517 | { |
1519 | 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."); |
1520 | 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"); |
1521 | return NULL; |
1520 | return NULL; |
1522 | } |
1521 | } |
… | |
… | |
1609 | return op; |
1608 | return op; |
1610 | else |
1609 | else |
1611 | { |
1610 | { |
1612 | op->destroy (); |
1611 | op->destroy (); |
1613 | return 0; |
1612 | return 0; |
1614 | } |
|
|
1615 | } |
|
|
1616 | |
|
|
1617 | /* |
|
|
1618 | * add_weight(object, weight) adds the specified weight to an object, |
|
|
1619 | * and also updates how much the environment(s) is/are carrying. |
|
|
1620 | */ |
|
|
1621 | void |
|
|
1622 | add_weight (object *op, signed long weight) |
|
|
1623 | { |
|
|
1624 | while (op != NULL) |
|
|
1625 | { |
|
|
1626 | if (op->type == CONTAINER) |
|
|
1627 | weight = (signed long) (weight * (100 - op->stats.Str) / 100); |
|
|
1628 | |
|
|
1629 | op->carrying += weight; |
|
|
1630 | op = op->env; |
|
|
1631 | } |
1613 | } |
1632 | } |
1614 | } |
1633 | |
1615 | |
1634 | object * |
1616 | object * |
1635 | insert_ob_in_ob (object *op, object *where) |
1617 | insert_ob_in_ob (object *op, object *where) |
… | |
… | |
2614 | { |
2596 | { |
2615 | char flagdesc[512]; |
2597 | char flagdesc[512]; |
2616 | char info2[256 * 4]; |
2598 | char info2[256 * 4]; |
2617 | char *p = info; |
2599 | char *p = info; |
2618 | |
2600 | |
2619 | 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}", |
2620 | count, uuid.seq, |
2602 | count, |
|
|
2603 | uuid.c_str (), |
2621 | &name, |
2604 | &name, |
2622 | title ? "\",title:\"" : "", |
2605 | title ? "\",title:\"" : "", |
2623 | title ? (const char *)title : "", |
2606 | title ? (const char *)title : "", |
2624 | flag_desc (flagdesc, 512), type); |
2607 | flag_desc (flagdesc, 512), type); |
2625 | |
2608 | |