1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | CrossFire, A Multiplayer game for X-windows |
3 | |
3 | |
|
|
4 | Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | |
7 | This program is free software; you can redistribute it and/or modify |
8 | This program is free software; you can redistribute it and/or modify |
8 | 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 |
… | |
… | |
26 | * collected in this file. |
27 | * collected in this file. |
27 | */ |
28 | */ |
28 | |
29 | |
29 | #include <global.h> |
30 | #include <global.h> |
30 | #include <spells.h> |
31 | #include <spells.h> |
31 | #ifndef __CEXTRACT__ |
|
|
32 | # include <sproto.h> |
32 | #include <sproto.h> |
33 | #endif |
|
|
34 | |
33 | |
35 | /* The following removes doors. The functions check to see if similar |
34 | /* The following removes doors. The functions check to see if similar |
36 | * doors are next to the one that is being removed, and if so, set it |
35 | * doors are next to the one that is being removed, and if so, set it |
37 | * so those will be removed shortly (in a cascade like fashion.) |
36 | * so those will be removed shortly (in a cascade like fashion.) |
38 | */ |
37 | */ |
… | |
… | |
44 | object *tmp; |
43 | object *tmp; |
45 | |
44 | |
46 | for (i = 1; i < 9; i += 2) |
45 | for (i = 1; i < 9; i += 2) |
47 | if ((tmp = present (DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i])) != NULL) |
46 | if ((tmp = present (DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i])) != NULL) |
48 | { |
47 | { |
49 | tmp->speed = 0.1; |
48 | tmp->set_speed (0.1); |
50 | update_ob_speed (tmp); |
|
|
51 | tmp->speed_left = -0.2; |
49 | tmp->speed_left = -0.2; |
52 | } |
50 | } |
53 | |
51 | |
54 | if (op->other_arch) |
52 | if (op->other_arch) |
55 | { |
53 | { |
… | |
… | |
58 | tmp->y = op->y; |
56 | tmp->y = op->y; |
59 | tmp->map = op->map; |
57 | tmp->map = op->map; |
60 | tmp->level = op->level; |
58 | tmp->level = op->level; |
61 | insert_ob_in_map (tmp, op->map, op, 0); |
59 | insert_ob_in_map (tmp, op->map, op, 0); |
62 | } |
60 | } |
63 | remove_ob (op); |
61 | |
64 | free_object (op); |
62 | op->destroy (); |
65 | } |
63 | } |
66 | |
64 | |
67 | void |
65 | void |
68 | remove_door2 (object *op) |
66 | remove_door2 (object *op) |
69 | { |
67 | { |
… | |
… | |
73 | for (i = 1; i < 9; i += 2) |
71 | for (i = 1; i < 9; i += 2) |
74 | { |
72 | { |
75 | tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]); |
73 | tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]); |
76 | if (tmp && tmp->slaying == op->slaying) |
74 | if (tmp && tmp->slaying == op->slaying) |
77 | { /* same key both doors */ |
75 | { /* same key both doors */ |
78 | tmp->speed = 0.1; |
76 | tmp->set_speed (0.1); |
79 | update_ob_speed (tmp); |
|
|
80 | tmp->speed_left = -0.2; |
77 | tmp->speed_left = -0.2; |
81 | } |
78 | } |
82 | } |
79 | } |
|
|
80 | |
83 | if (op->other_arch) |
81 | if (op->other_arch) |
84 | { |
82 | { |
85 | tmp = arch_to_object (op->other_arch); |
83 | tmp = arch_to_object (op->other_arch); |
86 | tmp->x = op->x; |
84 | tmp->x = op->x; |
87 | tmp->y = op->y; |
85 | tmp->y = op->y; |
88 | tmp->map = op->map; |
86 | tmp->map = op->map; |
89 | tmp->level = op->level; |
87 | tmp->level = op->level; |
90 | insert_ob_in_map (tmp, op->map, op, 0); |
88 | insert_ob_in_map (tmp, op->map, op, 0); |
91 | } |
89 | } |
92 | remove_ob (op); |
90 | |
93 | free_object (op); |
91 | op->destroy (); |
94 | } |
92 | } |
95 | |
93 | |
96 | /* Will generate a monster according to content |
94 | /* Will generate a monster according to content |
97 | * of generator. |
95 | * of generator. |
98 | */ |
96 | */ |
… | |
… | |
133 | if (rndm (0, 9)) |
131 | if (rndm (0, 9)) |
134 | generate_artifact (head, gen->map->difficulty); |
132 | generate_artifact (head, gen->map->difficulty); |
135 | insert_ob_in_map_at (head, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]); |
133 | insert_ob_in_map_at (head, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]); |
136 | if (QUERY_FLAG (head, FLAG_FREED)) |
134 | if (QUERY_FLAG (head, FLAG_FREED)) |
137 | return; |
135 | return; |
138 | if (HAS_RANDOM_ITEMS (head)) |
136 | if (head->has_random_items ()) |
139 | create_treasure (head->randomitems, head, GT_APPLY, gen->map->difficulty, 0); |
137 | create_treasure (head->randomitems, head, GT_APPLY, gen->map->difficulty, 0); |
140 | } |
138 | } |
141 | |
139 | |
142 | void |
140 | void |
143 | generate_monster_arch (object *gen) |
141 | generate_monster_arch (object *gen) |
144 | { |
142 | { |
145 | int i; |
143 | int i; |
146 | object *op, *head = NULL, *prev = NULL; |
144 | object *op, *head = NULL, *prev = NULL; |
147 | archetype *at = gen->other_arch; |
145 | archetype *at = gen->other_arch; |
148 | |
146 | |
149 | if (gen->other_arch == NULL) |
147 | if (!gen->other_arch) |
150 | { |
|
|
151 | //LOG(llevError,"Generator without other_arch: %s\n",gen->name); |
|
|
152 | return; |
148 | return; |
153 | } |
149 | |
154 | /* Code below assumes the generator is on a map, as it tries |
150 | /* Code below assumes the generator is on a map, as it tries |
155 | * to place the monster on the map. So if the generator |
151 | * to place the monster on the map. So if the generator |
156 | * isn't on a map, complain and exit. |
152 | * isn't on a map, complain and exit. |
157 | */ |
153 | */ |
158 | if (gen->map == NULL) |
154 | if (!gen->map) |
159 | { |
|
|
160 | //LOG(llevError,"Generator (%s) not on a map?\n", gen->name); |
|
|
161 | return; |
155 | return; |
162 | } |
156 | |
163 | i = find_free_spot (&at->clone, gen->map, gen->x, gen->y, 1, 9); |
157 | i = find_free_spot (&at->clone, gen->map, gen->x, gen->y, 1, 9); |
164 | if (i == -1) |
158 | if (i == -1) |
165 | return; |
159 | return; |
|
|
160 | |
166 | while (at != NULL) |
161 | while (at) |
167 | { |
162 | { |
168 | op = arch_to_object (at); |
163 | op = arch_to_object (at); |
169 | op->x = gen->x + freearr_x[i] + at->clone.x; |
164 | op->x = gen->x + freearr_x[i] + at->clone.x; |
170 | op->y = gen->y + freearr_y[i] + at->clone.y; |
165 | op->y = gen->y + freearr_y[i] + at->clone.y; |
171 | |
166 | |
172 | if (head != NULL) |
167 | if (head) |
173 | op->head = head, prev->more = op; |
168 | op->head = head, prev->more = op; |
174 | |
169 | |
175 | if (rndm (0, 9)) |
170 | if (rndm (0, 9)) |
176 | generate_artifact (op, gen->map->difficulty); |
171 | generate_artifact (op, gen->map->difficulty); |
|
|
172 | |
177 | insert_ob_in_map (op, gen->map, gen, 0); |
173 | insert_ob_in_map (op, gen->map, gen, 0); |
178 | if (QUERY_FLAG (op, FLAG_FREED)) |
174 | if (QUERY_FLAG (op, FLAG_FREED)) |
179 | return; |
175 | return; |
180 | if (HAS_RANDOM_ITEMS (op)) |
176 | |
|
|
177 | if (op->has_random_items ()) |
181 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty, 0); |
178 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty, 0); |
|
|
179 | |
182 | if (head == NULL) |
180 | if (head == NULL) |
183 | head = op; |
181 | head = op; |
|
|
182 | |
184 | prev = op; |
183 | prev = op; |
185 | at = at->more; |
184 | at = at->more; |
186 | } |
185 | } |
187 | } |
186 | } |
188 | |
187 | |
… | |
… | |
190 | generate_monster (object *gen) |
189 | generate_monster (object *gen) |
191 | { |
190 | { |
192 | |
191 | |
193 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
192 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
194 | return; |
193 | return; |
|
|
194 | |
195 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
195 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
196 | generate_monster_inv (gen); |
196 | generate_monster_inv (gen); |
197 | else |
197 | else |
198 | generate_monster_arch (gen); |
198 | generate_monster_arch (gen); |
199 | |
199 | |
… | |
… | |
203 | remove_force (object *op) |
203 | remove_force (object *op) |
204 | { |
204 | { |
205 | if (--op->duration > 0) |
205 | if (--op->duration > 0) |
206 | return; |
206 | return; |
207 | |
207 | |
|
|
208 | if (op->env) |
208 | switch (op->subtype) |
209 | switch (op->subtype) |
209 | { |
210 | { |
210 | case FORCE_CONFUSION: |
211 | case FORCE_CONFUSION: |
211 | if (op->env != NULL) |
|
|
212 | { |
|
|
213 | CLEAR_FLAG (op->env, FLAG_CONFUSED); |
212 | CLEAR_FLAG (op->env, FLAG_CONFUSED); |
214 | new_draw_info (NDI_UNIQUE, 0, op->env, "You regain your senses.\n"); |
213 | new_draw_info (NDI_UNIQUE, 0, op->env, "You regain your senses.\n"); |
215 | } |
|
|
216 | |
214 | |
217 | default: |
215 | default: |
218 | if (op->env != NULL) |
|
|
219 | { |
|
|
220 | CLEAR_FLAG (op, FLAG_APPLIED); |
216 | CLEAR_FLAG (op, FLAG_APPLIED); |
221 | change_abil (op->env, op); |
217 | change_abil (op->env, op); |
222 | fix_player (op->env); |
218 | op->env->update_stats (); |
223 | } |
|
|
224 | } |
219 | } |
225 | remove_ob (op); |
220 | |
226 | free_object (op); |
221 | op->destroy (); |
227 | } |
222 | } |
228 | |
223 | |
229 | void |
224 | void |
230 | remove_blindness (object *op) |
225 | remove_blindness (object *op) |
231 | { |
226 | { |
232 | if (--op->stats.food > 0) |
227 | if (--op->stats.food > 0) |
233 | return; |
228 | return; |
|
|
229 | |
234 | CLEAR_FLAG (op, FLAG_APPLIED); |
230 | CLEAR_FLAG (op, FLAG_APPLIED); |
|
|
231 | |
235 | if (op->env != NULL) |
232 | if (op->env) |
236 | { |
233 | { |
237 | change_abil (op->env, op); |
234 | change_abil (op->env, op); |
238 | fix_player (op->env); |
235 | op->env->update_stats (); |
239 | } |
236 | } |
240 | remove_ob (op); |
237 | |
241 | free_object (op); |
238 | op->destroy (); |
242 | } |
239 | } |
243 | |
240 | |
244 | void |
241 | void |
245 | poison_more (object *op) |
242 | poison_more (object *op) |
246 | { |
243 | { |
247 | if (op->env == NULL || !QUERY_FLAG (op->env, FLAG_ALIVE) || op->env->stats.hp < 0) |
244 | if (op->env == NULL || !QUERY_FLAG (op->env, FLAG_ALIVE) || op->env->stats.hp < 0) |
248 | { |
245 | { |
249 | remove_ob (op); |
246 | op->destroy (); |
250 | free_object (op); |
|
|
251 | return; |
247 | return; |
252 | } |
248 | } |
|
|
249 | |
253 | if (op->stats.food == 1) |
250 | if (op->stats.food == 1) |
254 | { |
251 | { |
255 | /* need to remove the object before fix_player is called, else fix_player |
252 | /* need to remove the object before fix_player is called, else fix_player |
256 | * will not do anything. |
253 | * will not do anything. |
257 | */ |
254 | */ |
258 | if (op->env->type == PLAYER) |
255 | if (op->env->type == PLAYER) |
259 | { |
256 | { |
260 | CLEAR_FLAG (op, FLAG_APPLIED); |
257 | CLEAR_FLAG (op, FLAG_APPLIED); |
261 | fix_player (op->env); |
258 | op->env->update_stats (); |
262 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now."); |
259 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now."); |
263 | } |
260 | } |
264 | remove_ob (op); |
261 | |
265 | free_object (op); |
262 | op->destroy (); |
266 | return; |
263 | return; |
267 | } |
264 | } |
|
|
265 | |
268 | if (op->env->type == PLAYER) |
266 | if (op->env->type == PLAYER) |
269 | { |
267 | { |
270 | op->env->stats.food--; |
268 | op->env->stats.food--; |
271 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel very sick..."); |
269 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel very sick..."); |
272 | } |
270 | } |
|
|
271 | |
273 | (void) hit_player (op->env, op->stats.dam, op, AT_INTERNAL, 1); |
272 | hit_player (op->env, op->stats.dam, op, AT_INTERNAL, 1); |
274 | } |
273 | } |
275 | |
274 | |
276 | |
275 | |
277 | void |
276 | void |
278 | move_gate (object *op) |
277 | move_gate (object *op) |
… | |
… | |
280 | object *tmp; |
279 | object *tmp; |
281 | |
280 | |
282 | if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op)) |
281 | if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op)) |
283 | { |
282 | { |
284 | LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op)); |
283 | LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op)); |
285 | dump_object (op); |
|
|
286 | LOG (llevError, "%s\n", errmsg); |
|
|
287 | op->stats.wc = 0; |
284 | op->stats.wc = 0; |
288 | } |
285 | } |
289 | |
286 | |
290 | /* We're going down */ |
287 | /* We're going down */ |
291 | if (op->value) |
288 | if (op->value) |
… | |
… | |
294 | { /* Reached bottom, let's stop */ |
291 | { /* Reached bottom, let's stop */ |
295 | op->stats.wc = 0; |
292 | op->stats.wc = 0; |
296 | if (op->arch->clone.speed) |
293 | if (op->arch->clone.speed) |
297 | op->value = 0; |
294 | op->value = 0; |
298 | else |
295 | else |
299 | { |
|
|
300 | op->speed = 0; |
296 | op->set_speed (0); |
301 | update_ob_speed (op); |
|
|
302 | } |
297 | } |
303 | } |
298 | |
304 | if ((int) op->stats.wc < (NUM_ANIMATIONS (op) / 2 + 1)) |
299 | if ((int) op->stats.wc < (NUM_ANIMATIONS (op) / 2 + 1)) |
305 | { |
300 | { |
306 | op->move_block = 0; |
301 | op->move_block = 0; |
307 | CLEAR_FLAG (op, FLAG_BLOCKSVIEW); |
302 | CLEAR_FLAG (op, FLAG_BLOCKSVIEW); |
308 | update_all_los (op->map, op->x, op->y); |
303 | update_all_los (op->map, op->x, op->y); |
309 | } |
304 | } |
|
|
305 | |
310 | SET_ANIMATION (op, op->stats.wc); |
306 | SET_ANIMATION (op, op->stats.wc); |
311 | update_object (op, UP_OBJ_CHANGE); |
307 | update_object (op, UP_OBJ_CHANGE); |
312 | return; |
308 | return; |
313 | } |
309 | } |
314 | |
310 | |
… | |
… | |
331 | if (tmp == NULL) |
327 | if (tmp == NULL) |
332 | { |
328 | { |
333 | if (op->arch->clone.speed) |
329 | if (op->arch->clone.speed) |
334 | op->value = 1; |
330 | op->value = 1; |
335 | else |
331 | else |
336 | { |
|
|
337 | op->speed = 0; |
332 | op->set_speed (0); |
338 | update_ob_speed (op); /* Reached top, let's stop */ |
333 | |
339 | } |
|
|
340 | return; |
334 | return; |
341 | } |
335 | } |
342 | } |
336 | } |
343 | |
337 | |
344 | if (op->stats.food) |
338 | if (op->stats.food) |
… | |
… | |
384 | int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); |
378 | int i = find_free_spot (tmp, op->map, op->x, op->y, 1, 9); |
385 | |
379 | |
386 | /* If there is a free spot, move the object someplace */ |
380 | /* If there is a free spot, move the object someplace */ |
387 | if (i != -1) |
381 | if (i != -1) |
388 | { |
382 | { |
389 | remove_ob (tmp); |
383 | tmp->remove (); |
390 | tmp->x += freearr_x[i], tmp->y += freearr_y[i]; |
384 | tmp->x += freearr_x[i], tmp->y += freearr_y[i]; |
391 | insert_ob_in_map (tmp, op->map, op, 0); |
385 | insert_ob_in_map (tmp, op->map, op, 0); |
392 | } |
386 | } |
393 | } |
387 | } |
394 | } |
388 | } |
… | |
… | |
435 | } |
429 | } |
436 | if (--op->stats.hp <= 0) |
430 | if (--op->stats.hp <= 0) |
437 | { /* keep gate down */ |
431 | { /* keep gate down */ |
438 | move_gate (op); |
432 | move_gate (op); |
439 | if (op->value != v) |
433 | if (op->value != v) |
440 | { /* ready ? */ |
|
|
441 | op->speed = 0; |
434 | op->set_speed (0); |
442 | update_ob_speed (op); |
|
|
443 | } |
|
|
444 | } |
435 | } |
445 | } |
436 | } |
446 | |
437 | |
447 | /* slaying: name of the thing the detector is to look for |
438 | /* slaying: name of the thing the detector is to look for |
448 | * speed: frequency of 'glances' |
439 | * speed: frequency of 'glances' |
… | |
… | |
458 | int last = op->value; |
449 | int last = op->value; |
459 | int detected; |
450 | int detected; |
460 | |
451 | |
461 | detected = 0; |
452 | detected = 0; |
462 | |
453 | |
463 | for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL && !detected; tmp = tmp->above) |
454 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL && !detected; tmp = tmp->above) |
464 | { |
455 | { |
465 | object *tmp2; |
456 | object *tmp2; |
466 | |
457 | |
467 | if (op->stats.hp) |
458 | if (op->stats.hp) |
468 | { |
459 | { |
… | |
… | |
535 | if (op->value) |
526 | if (op->value) |
536 | { /* We're opening */ |
527 | { /* We're opening */ |
537 | if (--op->stats.wc <= 0) |
528 | if (--op->stats.wc <= 0) |
538 | { /* Opened, let's stop */ |
529 | { /* Opened, let's stop */ |
539 | op->stats.wc = 0; |
530 | op->stats.wc = 0; |
540 | op->speed = 0; |
531 | op->set_speed (0); |
541 | update_ob_speed (op); |
|
|
542 | |
532 | |
543 | /* Hard coding this makes sense for holes I suppose */ |
533 | /* Hard coding this makes sense for holes I suppose */ |
544 | op->move_on = MOVE_WALK; |
534 | op->move_on = MOVE_WALK; |
545 | for (tmp = op->above; tmp != NULL; tmp = next) |
535 | for (tmp = op->above; tmp != NULL; tmp = next) |
546 | { |
536 | { |
547 | next = tmp->above; |
537 | next = tmp->above; |
548 | move_apply (op, tmp, tmp); |
538 | move_apply (op, tmp, tmp); |
549 | } |
539 | } |
550 | } |
540 | } |
|
|
541 | |
551 | SET_ANIMATION (op, op->stats.wc); |
542 | SET_ANIMATION (op, op->stats.wc); |
552 | update_object (op, UP_OBJ_FACE); |
543 | update_object (op, UP_OBJ_FACE); |
553 | return; |
544 | return; |
554 | } |
545 | } |
555 | /* We're closing */ |
546 | /* We're closing */ |
556 | op->move_on = 0; |
547 | op->move_on = 0; |
557 | |
548 | |
558 | op->stats.wc++; |
549 | op->stats.wc++; |
559 | if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) |
550 | if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) |
560 | op->stats.wc = NUM_ANIMATIONS (op) - 1; |
551 | op->stats.wc = NUM_ANIMATIONS (op) - 1; |
|
|
552 | |
561 | SET_ANIMATION (op, op->stats.wc); |
553 | SET_ANIMATION (op, op->stats.wc); |
562 | update_object (op, UP_OBJ_FACE); |
554 | update_object (op, UP_OBJ_FACE); |
563 | if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) |
555 | if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) |
564 | { |
|
|
565 | op->speed = 0; |
|
|
566 | update_ob_speed (op); /* closed, let's stop */ |
556 | op->set_speed (0); /* closed, let's stop */ |
567 | return; |
|
|
568 | } |
|
|
569 | } |
557 | } |
570 | |
558 | |
571 | |
559 | |
572 | /* stop_item() returns a pointer to the stopped object. The stopped object |
560 | /* stop_item() returns a pointer to the stopped object. The stopped object |
573 | * may or may not have been removed from maps or inventories. It will not |
561 | * may or may not have been removed from maps or inventories. It will not |
… | |
… | |
593 | { |
581 | { |
594 | object *payload = op->inv; |
582 | object *payload = op->inv; |
595 | |
583 | |
596 | if (payload == NULL) |
584 | if (payload == NULL) |
597 | return NULL; |
585 | return NULL; |
598 | remove_ob (payload); |
586 | payload->remove (); |
599 | remove_ob (op); |
587 | op->destroy (); |
600 | free_object (op); |
|
|
601 | return payload; |
588 | return payload; |
602 | } |
589 | } |
603 | |
590 | |
604 | case ARROW: |
591 | case ARROW: |
605 | if (op->speed >= MIN_ACTIVE_SPEED) |
592 | if (op->has_active_speed ()) |
606 | op = fix_stopped_arrow (op); |
593 | op = fix_stopped_arrow (op); |
607 | return op; |
594 | return op; |
608 | |
595 | |
609 | default: |
596 | default: |
610 | return op; |
597 | return op; |
… | |
… | |
632 | fix_stopped_arrow (object *op) |
619 | fix_stopped_arrow (object *op) |
633 | { |
620 | { |
634 | if (rndm (0, 99) < op->stats.food) |
621 | if (rndm (0, 99) < op->stats.food) |
635 | { |
622 | { |
636 | /* Small chance of breaking */ |
623 | /* Small chance of breaking */ |
637 | remove_ob (op); |
624 | op->destroy (); |
638 | free_object (op); |
|
|
639 | return NULL; |
625 | return NULL; |
640 | } |
626 | } |
641 | |
627 | |
|
|
628 | op->set_speed (0); |
642 | op->direction = 0; |
629 | op->direction = 0; |
643 | op->move_on = 0; |
630 | op->move_on = 0; |
644 | op->move_type = 0; |
631 | op->move_type = 0; |
645 | op->speed = 0; |
|
|
646 | update_ob_speed (op); |
|
|
647 | op->stats.wc = op->stats.sp; |
632 | op->stats.wc = op->stats.sp; |
648 | op->stats.dam = op->stats.hp; |
633 | op->stats.dam = op->stats.hp; |
649 | op->attacktype = op->stats.grace; |
634 | op->attacktype = op->stats.grace; |
650 | op->slaying = 0; |
635 | op->slaying = 0; |
651 | op->skill = 0; |
636 | op->skill = 0; |
… | |
… | |
657 | op->spellarg = NULL; |
642 | op->spellarg = NULL; |
658 | } |
643 | } |
659 | else |
644 | else |
660 | op->slaying = NULL; |
645 | op->slaying = NULL; |
661 | |
646 | |
662 | /* Reset these to zero, so that CAN_MERGE will work properly */ |
647 | /* Reset these to zero, so that object::can_merge will work properly */ |
663 | op->spellarg = NULL; |
648 | op->spellarg = NULL; |
664 | op->stats.sp = 0; |
649 | op->stats.sp = 0; |
665 | op->stats.hp = 0; |
650 | op->stats.hp = 0; |
666 | op->stats.grace = 0; |
651 | op->stats.grace = 0; |
667 | op->level = 0; |
652 | op->level = 0; |
… | |
… | |
676 | * here too. -b.t. |
661 | * here too. -b.t. |
677 | * |
662 | * |
678 | * Returns a pointer to the stopped object (which will have been removed |
663 | * Returns a pointer to the stopped object (which will have been removed |
679 | * from maps or inventories), or NULL if was destroyed. |
664 | * from maps or inventories), or NULL if was destroyed. |
680 | */ |
665 | */ |
681 | |
|
|
682 | static void |
666 | static void |
683 | stop_arrow (object *op) |
667 | stop_arrow (object *op) |
684 | { |
668 | { |
685 | if (INVOKE_OBJECT (STOP, op)) |
669 | if (INVOKE_OBJECT (STOP, op)) |
686 | return; |
670 | return; |
687 | |
671 | |
688 | if (op->inv) |
672 | if (op->inv) |
689 | { |
673 | { |
690 | object *payload = op->inv; |
674 | object *payload = op->inv; |
691 | |
675 | |
692 | remove_ob (payload); |
676 | payload->remove (); |
693 | clear_owner (payload); |
677 | payload->owner = 0; |
694 | insert_ob_in_map (payload, op->map, payload, 0); |
678 | insert_ob_in_map (payload, op->map, payload, 0); |
695 | remove_ob (op); |
679 | op->destroy (); |
696 | free_object (op); |
|
|
697 | } |
680 | } |
698 | else |
681 | else |
699 | { |
682 | { |
700 | op = fix_stopped_arrow (op); |
683 | op = fix_stopped_arrow (op); |
701 | if (op) |
684 | if (op) |
… | |
… | |
715 | maptile *m; |
698 | maptile *m; |
716 | |
699 | |
717 | if (op->map == NULL) |
700 | if (op->map == NULL) |
718 | { |
701 | { |
719 | LOG (llevError, "BUG: Arrow had no map.\n"); |
702 | LOG (llevError, "BUG: Arrow had no map.\n"); |
720 | remove_ob (op); |
703 | op->destroy (); |
721 | free_object (op); |
|
|
722 | return; |
704 | return; |
723 | } |
705 | } |
724 | |
706 | |
725 | /* we need to stop thrown objects at some point. Like here. */ |
707 | /* we need to stop thrown objects at some point. Like here. */ |
726 | if (op->type == THROWN_OBJ) |
708 | if (op->type == THROWN_OBJ) |
… | |
… | |
733 | * bomb code, but there are potential other cases where that could happen, |
715 | * bomb code, but there are potential other cases where that could happen, |
734 | * and it is easy enough to clean it up here. |
716 | * and it is easy enough to clean it up here. |
735 | */ |
717 | */ |
736 | if (op->inv == NULL) |
718 | if (op->inv == NULL) |
737 | { |
719 | { |
738 | remove_ob (op); |
720 | op->destroy (); |
739 | free_object (op); |
|
|
740 | return; |
721 | return; |
741 | } |
722 | } |
|
|
723 | |
742 | if (op->last_sp-- < 0) |
724 | if (op->last_sp-- < 0) |
743 | { |
725 | { |
744 | stop_arrow (op); |
726 | stop_arrow (op); |
745 | return; |
727 | return; |
746 | } |
728 | } |
… | |
… | |
769 | } |
751 | } |
770 | |
752 | |
771 | /* only need to look for living creatures if this flag is set */ |
753 | /* only need to look for living creatures if this flag is set */ |
772 | if (mflags & P_IS_ALIVE) |
754 | if (mflags & P_IS_ALIVE) |
773 | { |
755 | { |
774 | for (tmp = get_map_ob (m, new_x, new_y); tmp != NULL; tmp = tmp->above) |
756 | for (tmp = GET_MAP_OB (m, new_x, new_y); tmp != NULL; tmp = tmp->above) |
775 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
757 | if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
776 | break; |
758 | break; |
777 | |
|
|
778 | |
759 | |
779 | /* Not really fair, but don't let monsters hit themselves with |
760 | /* Not really fair, but don't let monsters hit themselves with |
780 | * their own arrow - this can be because they fire it then |
761 | * their own arrow - this can be because they fire it then |
781 | * move into it. |
762 | * move into it. |
782 | */ |
763 | */ |
783 | |
|
|
784 | if (tmp != NULL && tmp != op->owner) |
764 | if (tmp && tmp != op->owner) |
785 | { |
765 | { |
786 | /* Found living object, but it is reflecting the missile. Update |
766 | /* Found living object, but it is reflecting the missile. Update |
787 | * as below. (Note that for living creatures there is a small |
767 | * as below. (Note that for living creatures there is a small |
788 | * chance that reflect_missile fails.) |
768 | * chance that reflect_missile fails.) |
789 | */ |
769 | */ |
790 | |
|
|
791 | if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) |
770 | if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) |
792 | { |
771 | { |
793 | |
|
|
794 | int number = op->face->number; |
772 | int number = op->face->number; |
795 | |
773 | |
796 | op->direction = absdir (op->direction + 4); |
774 | op->direction = absdir (op->direction + 4); |
797 | op->state = 0; |
775 | op->state = 0; |
|
|
776 | |
798 | if (GET_ANIM_ID (op)) |
777 | if (GET_ANIM_ID (op)) |
799 | { |
778 | { |
800 | number += 4; |
779 | number += 4; |
|
|
780 | |
801 | if (number > GET_ANIMATION (op, 8)) |
781 | if (number > GET_ANIMATION (op, 8)) |
802 | number -= 8; |
782 | number -= 8; |
|
|
783 | |
803 | op->face = &new_faces[number]; |
784 | op->face = &new_faces[number]; |
804 | } |
785 | } |
|
|
786 | |
805 | was_reflected = 1; /* skip normal movement calculations */ |
787 | was_reflected = 1; /* skip normal movement calculations */ |
806 | } |
788 | } |
807 | else |
789 | else |
808 | { |
790 | { |
809 | /* Attack the object. */ |
791 | /* Attack the object. */ |
810 | op = hit_with_arrow (op, tmp); |
792 | op = hit_with_arrow (op, tmp); |
|
|
793 | |
811 | if (op == NULL) |
794 | if (!op) |
812 | return; |
795 | return; |
813 | } |
796 | } |
814 | } /* if this is not hitting its owner */ |
797 | } /* if this is not hitting its owner */ |
815 | } /* if there is something alive on this space */ |
798 | } /* if there is something alive on this space */ |
816 | |
|
|
817 | |
799 | |
818 | if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) |
800 | if (OB_TYPE_MOVE_BLOCK (op, GET_MAP_MOVE_BLOCK (m, new_x, new_y))) |
819 | { |
801 | { |
820 | int retry = 0; |
802 | int retry = 0; |
821 | |
803 | |
… | |
… | |
893 | SET_ANIMATION (op, op->direction); |
875 | SET_ANIMATION (op, op->direction); |
894 | } /* object is reflected */ |
876 | } /* object is reflected */ |
895 | } /* object ran into a wall */ |
877 | } /* object ran into a wall */ |
896 | |
878 | |
897 | /* Move the arrow. */ |
879 | /* Move the arrow. */ |
898 | remove_ob (op); |
880 | op->remove (); |
899 | op->x = new_x; |
881 | op->x = new_x; |
900 | op->y = new_y; |
882 | op->y = new_y; |
901 | |
883 | |
902 | /* decrease the speed as it flies. 0.05 means a standard bow will shoot |
884 | /* decrease the speed as it flies. 0.05 means a standard bow will shoot |
903 | * about 17 squares. Tune as needed. |
885 | * about 17 squares. Tune as needed. |
… | |
… | |
911 | * Modified this routine to allow held objects. b.t. */ |
893 | * Modified this routine to allow held objects. b.t. */ |
912 | |
894 | |
913 | void |
895 | void |
914 | change_object (object *op) |
896 | change_object (object *op) |
915 | { /* Doesn`t handle linked objs yet */ |
897 | { /* Doesn`t handle linked objs yet */ |
916 | object *tmp, *env, *pl; |
|
|
917 | int i, j; |
898 | int i, j; |
918 | |
899 | |
919 | if (op->other_arch == NULL) |
900 | if (op->other_arch == NULL) |
920 | { |
901 | { |
921 | LOG (llevError, "Change object (%s) without other_arch error.\n", &op->name); |
902 | LOG (llevError, "Change object (%s) without other_arch error.\n", &op->name); |
… | |
… | |
928 | if (op->stats.food-- > 0) |
909 | if (op->stats.food-- > 0) |
929 | return; |
910 | return; |
930 | else |
911 | else |
931 | op->stats.food = 1; /* so 1 other_arch is made */ |
912 | op->stats.food = 1; /* so 1 other_arch is made */ |
932 | } |
913 | } |
|
|
914 | |
|
|
915 | object *pl = op->in_player (); |
933 | env = op->env; |
916 | object *env = op->env; |
934 | remove_ob (op); |
917 | |
|
|
918 | op->remove (); |
935 | for (i = 0; i < NROFNEWOBJS (op); i++) |
919 | for (i = 0; i < NROFNEWOBJS (op); i++) |
936 | { |
920 | { |
937 | tmp = arch_to_object (op->other_arch); |
921 | object *tmp = arch_to_object (op->other_arch); |
|
|
922 | |
938 | if (op->type == LAMP) |
923 | if (op->type == LAMP) |
939 | tmp->stats.food = op->stats.food - 1; |
924 | tmp->stats.food = op->stats.food - 1; |
|
|
925 | |
940 | tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ |
926 | tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ |
941 | if (env) |
927 | if (env) |
942 | { |
928 | { |
943 | tmp->x = env->x, tmp->y = env->y; |
929 | tmp->x = env->x, tmp->y = env->y; |
944 | tmp = insert_ob_in_ob (tmp, env); |
930 | tmp = insert_ob_in_ob (tmp, env); |
|
|
931 | |
945 | /* If this object is the players inventory, we need to tell the |
932 | /* If this object is the players inventory, we need to tell the |
946 | * client of the change. Insert_ob_in_map takes care of the |
933 | * client of the change. Insert_ob_in_map takes care of the |
947 | * updating the client, so we don't need to do that below. |
934 | * updating the client, so we don't need to do that below. |
948 | */ |
935 | */ |
949 | if ((pl = is_player_inv (env)) != NULL) |
936 | if (pl) |
950 | { |
937 | { |
951 | esrv_del_item (pl->contr, op->count); |
938 | esrv_del_item (pl->contr, op->count); |
952 | esrv_send_item (pl, tmp); |
939 | esrv_send_item (pl, tmp); |
953 | } |
940 | } |
954 | } |
941 | } |
955 | else |
942 | else |
956 | { |
943 | { |
957 | j = find_first_free_spot (tmp, op->map, op->x, op->y); |
944 | j = find_first_free_spot (tmp, op->map, op->x, op->y); |
958 | if (j == -1) /* No free spot */ |
945 | if (j == -1) /* No free spot */ |
959 | free_object (tmp); |
946 | tmp->destroy (); |
960 | else |
947 | else |
961 | { |
948 | { |
962 | tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; |
949 | tmp->x = op->x + freearr_x[j], tmp->y = op->y + freearr_y[j]; |
963 | insert_ob_in_map (tmp, op->map, op, 0); |
950 | insert_ob_in_map (tmp, op->map, op, 0); |
964 | } |
951 | } |
965 | } |
952 | } |
966 | } |
953 | } |
967 | free_object (op); |
954 | |
|
|
955 | op->destroy (); |
968 | } |
956 | } |
969 | |
957 | |
970 | void |
958 | void |
971 | move_teleporter (object *op) |
959 | move_teleporter (object *op) |
972 | { |
960 | { |
… | |
… | |
977 | * there is an old multipart teleporter in which the other parts |
965 | * there is an old multipart teleporter in which the other parts |
978 | * have speed, we don't really want to call it twice for the same |
966 | * have speed, we don't really want to call it twice for the same |
979 | * function - in fact, as written below, part N would get called |
967 | * function - in fact, as written below, part N would get called |
980 | * N times without the speed check. |
968 | * N times without the speed check. |
981 | */ |
969 | */ |
982 | if (op->more && FABS (op->more->speed) < MIN_ACTIVE_SPEED) |
970 | if (op->more && !op->more->has_active_speed ()) |
983 | move_teleporter (op->more); |
971 | move_teleporter (op->more); |
984 | |
972 | |
985 | if (op->head) |
973 | if (op->head) |
986 | head = op->head; |
974 | head = op->head; |
987 | |
975 | |
… | |
… | |
998 | if (tmp->type == PLAYER) |
986 | if (tmp->type == PLAYER) |
999 | { |
987 | { |
1000 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
988 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
1001 | return; |
989 | return; |
1002 | |
990 | |
1003 | enter_exit (tmp, head); |
991 | tmp->enter_exit (head); |
1004 | } |
992 | } |
1005 | else |
993 | else |
1006 | /* Currently only players can transfer maps */ |
994 | /* Currently only players can transfer maps */ |
1007 | return; |
995 | return; |
1008 | } |
996 | } |
1009 | else if (EXIT_X (head) || EXIT_Y (head)) |
997 | else if (EXIT_X (head) || EXIT_Y (head)) |
1010 | { |
998 | { |
1011 | if (out_of_map (head->map, EXIT_X (head), EXIT_Y (head))) |
999 | if (out_of_map (head->map, EXIT_X (head), EXIT_Y (head))) |
1012 | { |
1000 | { |
1013 | LOG (llevError, "Removed illegal teleporter.\n"); |
1001 | LOG (llevError, "Removed illegal teleporter.\n"); |
1014 | remove_ob (head); |
1002 | head->destroy (); |
1015 | free_object (head); |
|
|
1016 | return; |
1003 | return; |
1017 | } |
1004 | } |
|
|
1005 | |
1018 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
1006 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
1019 | return; |
1007 | return; |
|
|
1008 | |
1020 | transfer_ob (tmp, EXIT_X (head), EXIT_Y (head), 0, head); |
1009 | transfer_ob (tmp, EXIT_X (head), EXIT_Y (head), 0, head); |
1021 | } |
1010 | } |
1022 | else |
1011 | else |
1023 | { |
1012 | { |
1024 | /* Random teleporter */ |
1013 | /* Random teleporter */ |
… | |
… | |
1032 | /* This object will teleport someone to a different map |
1021 | /* This object will teleport someone to a different map |
1033 | and will also apply changes to the player from its inventory. |
1022 | and will also apply changes to the player from its inventory. |
1034 | This was invented for giving classes, but there's no reason it |
1023 | This was invented for giving classes, but there's no reason it |
1035 | can't be generalized. |
1024 | can't be generalized. |
1036 | */ |
1025 | */ |
1037 | |
|
|
1038 | void |
1026 | void |
1039 | move_player_changer (object *op) |
1027 | move_player_changer (object *op) |
1040 | { |
1028 | { |
1041 | object *player; |
1029 | object *player; |
1042 | object *walk; |
1030 | object *walk; |
… | |
… | |
1055 | player = op->above; |
1043 | player = op->above; |
1056 | |
1044 | |
1057 | for (walk = op->inv; walk != NULL; walk = walk->below) |
1045 | for (walk = op->inv; walk != NULL; walk = walk->below) |
1058 | apply_changes_to_player (player, walk); |
1046 | apply_changes_to_player (player, walk); |
1059 | |
1047 | |
1060 | fix_player (player); |
1048 | player->update_stats (); |
1061 | |
1049 | |
1062 | esrv_send_inventory (op->above, op->above); |
1050 | esrv_send_inventory (op->above, op->above); |
1063 | esrv_update_item (UPD_FACE, op->above, op->above); |
1051 | esrv_update_item (UPD_FACE, op->above, op->above); |
1064 | |
1052 | |
1065 | /* update players death & WoR home-position */ |
1053 | /* update players death & WoR home-position */ |
1066 | sscanf (EXIT_PATH (op), "%c", &c); |
1054 | sscanf (EXIT_PATH (op), "%c", &c); |
1067 | if (c == '/') |
1055 | if (c == '/') |
1068 | { |
1056 | { |
1069 | strcpy (player->contr->savebed_map, EXIT_PATH (op)); |
1057 | player->contr->savebed_map = EXIT_PATH (op); |
1070 | player->contr->bed_x = EXIT_X (op); |
1058 | player->contr->bed_x = EXIT_X (op); |
1071 | player->contr->bed_y = EXIT_Y (op); |
1059 | player->contr->bed_y = EXIT_Y (op); |
1072 | } |
1060 | } |
1073 | else |
1061 | else |
1074 | LOG (llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", &EXIT_PATH (op)); |
1062 | LOG (llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", &EXIT_PATH (op)); |
1075 | |
1063 | |
1076 | enter_exit (op->above, op); |
1064 | op->above->enter_exit (op); |
1077 | save_player (player, 1); |
1065 | player->contr->save (); |
1078 | } |
1066 | } |
1079 | } |
1067 | } |
1080 | |
1068 | |
1081 | /* firewalls fire other spells. |
1069 | /* firewalls fire other spells. |
1082 | * The direction of the wall is stored in op->stats.sp. |
1070 | * The direction of the wall is stored in op->stats.sp. |
… | |
… | |
1089 | |
1077 | |
1090 | if (!op->map) |
1078 | if (!op->map) |
1091 | return; /* dm has created a firewall in his inventory */ |
1079 | return; /* dm has created a firewall in his inventory */ |
1092 | |
1080 | |
1093 | spell = op->inv; |
1081 | spell = op->inv; |
|
|
1082 | |
1094 | if (!spell || spell->type != SPELL) |
1083 | if (!spell || spell->type != SPELL) |
1095 | spell = &op->other_arch->clone; |
1084 | spell = &op->other_arch->clone; |
|
|
1085 | |
1096 | if (!spell) |
1086 | if (!spell) |
1097 | { |
1087 | { |
1098 | LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, op->map->name, op->x, op->y); |
1088 | LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, &op->map->name, op->x, op->y); |
1099 | return; |
1089 | return; |
1100 | } |
1090 | } |
1101 | |
1091 | |
1102 | cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL); |
1092 | cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL); |
1103 | } |
1093 | } |
1104 | |
|
|
1105 | |
1094 | |
1106 | /* move_player_mover: this function takes a "player mover" as an |
1095 | /* move_player_mover: this function takes a "player mover" as an |
1107 | * argument, and performs the function of a player mover, which is: |
1096 | * argument, and performs the function of a player mover, which is: |
1108 | * |
1097 | * |
1109 | * a player mover finds any players that are sitting on it. It |
1098 | * a player mover finds any players that are sitting on it. It |
… | |
… | |
1122 | |
1111 | |
1123 | /* Determine direction now for random movers so we do the right thing */ |
1112 | /* Determine direction now for random movers so we do the right thing */ |
1124 | if (!dir) |
1113 | if (!dir) |
1125 | dir = rndm (1, 8); |
1114 | dir = rndm (1, 8); |
1126 | |
1115 | |
1127 | for (victim = get_map_ob (op->map, op->x, op->y); victim != NULL; victim = victim->above) |
1116 | for (victim = GET_MAP_OB (op->map, op->x, op->y); victim != NULL; victim = victim->above) |
1128 | { |
1117 | { |
1129 | if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_WIZPASS) && |
1118 | if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_WIZPASS) && |
1130 | (victim->move_type & op->move_type || !victim->move_type)) |
1119 | (victim->move_type & op->move_type || !victim->move_type)) |
1131 | { |
1120 | { |
1132 | |
1121 | |
1133 | if (victim->head) |
1122 | if (victim->head) |
1134 | victim = victim->head; |
1123 | victim = victim->head; |
1135 | |
1124 | |
1136 | if (QUERY_FLAG (op, FLAG_LIFESAVE) && op->stats.hp-- < 0) |
1125 | if (QUERY_FLAG (op, FLAG_LIFESAVE) && op->stats.hp-- < 0) |
1137 | { |
1126 | { |
1138 | remove_ob (op); |
1127 | op->remove (); |
1139 | free_object (op); |
|
|
1140 | return; |
1128 | return; |
1141 | } |
1129 | } |
|
|
1130 | |
1142 | nx = op->x + freearr_x[dir]; |
1131 | nx = op->x + freearr_x[dir]; |
1143 | ny = op->y + freearr_y[dir]; |
1132 | ny = op->y + freearr_y[dir]; |
1144 | m = op->map; |
1133 | m = op->map; |
1145 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) |
1134 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) |
1146 | { |
1135 | { |
1147 | LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", m->path, op->x, op->y); |
1136 | LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", &m->path, op->x, op->y); |
1148 | return; |
1137 | return; |
1149 | } |
1138 | } |
1150 | |
1139 | |
1151 | if (should_director_abort (op, victim)) |
1140 | if (should_director_abort (op, victim)) |
1152 | return; |
1141 | return; |
1153 | |
1142 | |
1154 | for (nextmover = get_map_ob (m, nx, ny); nextmover != NULL; nextmover = nextmover->above) |
1143 | for (nextmover = GET_MAP_OB (m, nx, ny); nextmover != NULL; nextmover = nextmover->above) |
1155 | { |
1144 | { |
1156 | if (nextmover->type == PLAYERMOVER) |
1145 | if (nextmover->type == PLAYERMOVER) |
1157 | nextmover->speed_left = -.99; |
1146 | nextmover->speed_left = -.99; |
1158 | if (QUERY_FLAG (nextmover, FLAG_ALIVE)) |
1147 | if (QUERY_FLAG (nextmover, FLAG_ALIVE)) |
1159 | { |
1148 | { |
… | |
… | |
1213 | { |
1202 | { |
1214 | object *tmp; |
1203 | object *tmp; |
1215 | |
1204 | |
1216 | if (!op->other_arch) |
1205 | if (!op->other_arch) |
1217 | { |
1206 | { |
1218 | LOG (llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? op->map->path : "nullmap"); |
1207 | LOG (llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? &op->map->path : "nullmap"); |
1219 | return; |
1208 | return; |
1220 | } |
1209 | } |
1221 | |
1210 | |
1222 | if (op->above == NULL) |
1211 | if (op->above == NULL) |
1223 | return; |
1212 | return; |
1224 | for (tmp = op->above; tmp != NULL; tmp = tmp->above) |
1213 | for (tmp = op->above; tmp != NULL; tmp = tmp->above) |
1225 | { |
1214 | { |
1226 | if (strcmp (op->other_arch->name, tmp->arch->name) == 0) |
1215 | if (strcmp (op->other_arch->name, tmp->arch->name) == 0) |
1227 | { |
1216 | { |
1228 | if (op->level <= 0) |
1217 | if (op->level <= 0) |
1229 | { |
1218 | tmp->destroy (); |
1230 | remove_ob (tmp); |
|
|
1231 | free_object (tmp); |
|
|
1232 | } |
|
|
1233 | else |
1219 | else |
1234 | { |
1220 | { |
1235 | uint64 new_nrof = (uint64) tmp->nrof * op->level; |
1221 | uint64 new_nrof = (uint64) tmp->nrof * op->level; |
1236 | |
1222 | |
1237 | if (new_nrof >= 1UL << 31) |
1223 | if (new_nrof >= 1UL << 31) |
1238 | new_nrof = 1UL << 31; |
1224 | new_nrof = 1UL << 31; |
|
|
1225 | |
1239 | tmp->nrof = new_nrof; |
1226 | tmp->nrof = new_nrof; |
1240 | } |
1227 | } |
|
|
1228 | |
1241 | break; |
1229 | break; |
1242 | } |
1230 | } |
1243 | } |
1231 | } |
1244 | } |
1232 | } |
1245 | |
1233 | |
… | |
… | |
1289 | } |
1277 | } |
1290 | else |
1278 | else |
1291 | { |
1279 | { |
1292 | if (creator->other_arch == NULL) |
1280 | if (creator->other_arch == NULL) |
1293 | { |
1281 | { |
1294 | LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", &creator->name, creator->map->path, |
1282 | LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", |
1295 | creator->x, creator->y); |
1283 | &creator->name, &creator->map->path, creator->x, creator->y); |
1296 | return; |
1284 | return; |
1297 | } |
1285 | } |
1298 | |
1286 | |
1299 | new_ob = object_create_arch (creator->other_arch); |
1287 | new_ob = object_create_arch (creator->other_arch); |
1300 | fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); |
1288 | fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); |
1301 | } |
1289 | } |
1302 | |
1290 | |
1303 | /* Make sure this multipart object fits */ |
1291 | /* Make sure this multipart object fits */ |
1304 | if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y)) |
1292 | if (new_ob->arch->more && ob_blocked (new_ob, creator->map, creator->x, creator->y)) |
1305 | { |
1293 | { |
1306 | free_object (new_ob); |
1294 | new_ob->destroy (); |
1307 | return; |
1295 | return; |
1308 | } |
1296 | } |
1309 | |
1297 | |
1310 | insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); |
1298 | insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); |
1311 | if (QUERY_FLAG (new_ob, FLAG_FREED)) |
1299 | if (QUERY_FLAG (new_ob, FLAG_FREED)) |
… | |
… | |
1327 | unless hp was zero to start with, in which case it is infinite.*/ |
1315 | unless hp was zero to start with, in which case it is infinite.*/ |
1328 | |
1316 | |
1329 | void |
1317 | void |
1330 | move_marker (object *op) |
1318 | move_marker (object *op) |
1331 | { |
1319 | { |
|
|
1320 | if (object *tmp = op->ms ().player ()) |
|
|
1321 | { |
1332 | object *tmp, *tmp2; |
1322 | object *tmp2; |
1333 | |
1323 | |
1334 | for (tmp = get_map_ob (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
|
|
1335 | { |
|
|
1336 | if (tmp->type == PLAYER) |
|
|
1337 | { /* we've got someone to MARK */ |
|
|
1338 | |
|
|
1339 | /* remove an old force with a slaying field == op->name */ |
1324 | /* remove an old force with a slaying field == op->name */ |
1340 | for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) |
1325 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
1341 | { |
|
|
1342 | if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->name)) |
1326 | if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->name)) |
1343 | break; |
|
|
1344 | } |
|
|
1345 | |
|
|
1346 | if (tmp2) |
|
|
1347 | { |
1327 | { |
1348 | remove_ob (tmp2); |
1328 | tmp2->destroy (); |
1349 | free_object (tmp2); |
1329 | break; |
1350 | } |
1330 | } |
1351 | |
1331 | |
1352 | /* cycle through his inventory to look for the MARK we want to |
1332 | /* cycle through his inventory to look for the MARK we want to |
1353 | * place |
1333 | * place |
1354 | */ |
1334 | */ |
1355 | for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) |
1335 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
1356 | { |
|
|
1357 | if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) |
1336 | if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) |
1358 | break; |
1337 | break; |
1359 | } |
|
|
1360 | |
1338 | |
1361 | /* if we didn't find our own MARK */ |
1339 | /* if we didn't find our own MARK */ |
1362 | if (tmp2 == NULL) |
1340 | if (tmp2 == NULL) |
1363 | { |
1341 | { |
1364 | object *force = get_archetype (FORCE_NAME); |
1342 | object *force = get_archetype (FORCE_NAME); |
1365 | |
1343 | |
1366 | force->speed = 0; |
|
|
1367 | if (op->stats.food) |
1344 | if (op->stats.food) |
|
|
1345 | { |
|
|
1346 | force->set_speed (0.01); |
|
|
1347 | force->speed_left = -op->stats.food; |
|
|
1348 | } |
|
|
1349 | else |
|
|
1350 | force->set_speed (0); |
|
|
1351 | |
|
|
1352 | /* put in the lock code */ |
|
|
1353 | force->slaying = op->slaying; |
|
|
1354 | |
|
|
1355 | if (op->lore) |
|
|
1356 | force->lore = op->lore; |
|
|
1357 | |
|
|
1358 | insert_ob_in_ob (force, tmp); |
|
|
1359 | if (op->msg) |
|
|
1360 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); |
|
|
1361 | |
|
|
1362 | if (op->stats.hp > 0) |
|
|
1363 | { |
|
|
1364 | op->stats.hp--; |
|
|
1365 | if (op->stats.hp == 0) |
1368 | { |
1366 | { |
1369 | force->speed = 0.01; |
1367 | /* marker expires--granted mark number limit */ |
1370 | force->speed_left = -op->stats.food; |
1368 | op->destroy (); |
|
|
1369 | return; |
1371 | } |
1370 | } |
1372 | update_ob_speed (force); |
|
|
1373 | /* put in the lock code */ |
|
|
1374 | force->slaying = op->slaying; |
|
|
1375 | |
|
|
1376 | if (op->lore) |
|
|
1377 | force->lore = op->lore; |
|
|
1378 | |
|
|
1379 | insert_ob_in_ob (force, tmp); |
|
|
1380 | if (op->msg) |
|
|
1381 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); |
|
|
1382 | |
|
|
1383 | if (op->stats.hp > 0) |
|
|
1384 | { |
|
|
1385 | op->stats.hp--; |
|
|
1386 | if (op->stats.hp == 0) |
|
|
1387 | { |
|
|
1388 | /* marker expires--granted mark number limit */ |
|
|
1389 | remove_ob (op); |
|
|
1390 | free_object (op); |
|
|
1391 | return; |
|
|
1392 | } |
|
|
1393 | } |
1371 | } |
1394 | } /* if tmp2 == NULL */ |
1372 | } |
1395 | } /* if tmp->type == PLAYER */ |
1373 | } |
1396 | } /* For all objects on this space */ |
|
|
1397 | } |
1374 | } |
1398 | |
1375 | |
1399 | int |
1376 | int |
1400 | process_object (object *op) |
1377 | process_object (object *op) |
1401 | { |
1378 | { |
… | |
… | |
1434 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
1411 | if (QUERY_FLAG (op, FLAG_APPLIED)) |
1435 | remove_force (op); |
1412 | remove_force (op); |
1436 | else |
1413 | else |
1437 | { |
1414 | { |
1438 | /* IF necessary, delete the item from the players inventory */ |
1415 | /* IF necessary, delete the item from the players inventory */ |
1439 | object *pl = is_player_inv (op); |
1416 | object *pl = op->in_player (); |
1440 | |
1417 | |
1441 | if (pl) |
1418 | if (pl) |
1442 | esrv_del_item (pl->contr, op->count); |
1419 | esrv_del_item (pl->contr, op->count); |
1443 | |
1420 | |
1444 | remove_ob (op); |
1421 | op->remove (); |
1445 | |
1422 | |
1446 | if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |
1423 | if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |
1447 | make_sure_not_seen (op); |
1424 | make_sure_not_seen (op); |
1448 | |
1425 | |
1449 | free_object (op); |
1426 | op->destroy (); |
1450 | } |
1427 | } |
1451 | |
1428 | |
1452 | return 1; |
1429 | return 1; |
1453 | } |
1430 | } |
1454 | |
1431 | |
… | |
… | |
1485 | return 0; |
1462 | return 0; |
1486 | |
1463 | |
1487 | case THROWN_OBJ: |
1464 | case THROWN_OBJ: |
1488 | case ARROW: |
1465 | case ARROW: |
1489 | move_arrow (op); |
1466 | move_arrow (op); |
1490 | return 0; |
|
|
1491 | |
|
|
1492 | case LIGHTNING: /* It now moves twice as fast */ |
|
|
1493 | move_bolt (op); |
|
|
1494 | return 0; |
1467 | return 0; |
1495 | |
1468 | |
1496 | case DOOR: |
1469 | case DOOR: |
1497 | remove_door (op); |
1470 | remove_door (op); |
1498 | return 0; |
1471 | return 0; |