1 |
/* |
2 |
* This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 |
* |
4 |
* Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 |
* Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 |
* Copyright (©) 1992,2007 Frank Tore Johansen |
7 |
* |
8 |
* Deliantra is free software: you can redistribute it and/or modify |
9 |
* it under the terms of the GNU General Public License as published by |
10 |
* the Free Software Foundation, either version 3 of the License, or |
11 |
* (at your option) any later version. |
12 |
* |
13 |
* This program is distributed in the hope that it will be useful, |
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 |
* GNU General Public License for more details. |
17 |
* |
18 |
* You should have received a copy of the GNU General Public License |
19 |
* along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 |
* |
21 |
* The authors can be reached via e-mail to <support@deliantra.net> |
22 |
*/ |
23 |
|
24 |
/* |
25 |
* Routines that is executed from objects based on their speed have been |
26 |
* collected in this file. |
27 |
*/ |
28 |
#include <global.h> |
29 |
#include <spells.h> |
30 |
#include <sproto.h> |
31 |
|
32 |
/* The following removes doors. The functions check to see if similar |
33 |
* doors are next to the one that is being removed, and if so, set it |
34 |
* so those will be removed shortly (in a cascade like fashion.) |
35 |
*/ |
36 |
void |
37 |
remove_door (object *op) |
38 |
{ |
39 |
for (int i = 1; i < SIZEOFFREE1 + 1; i += 2) |
40 |
{ |
41 |
object *tmp; |
42 |
mapxy pos (op); |
43 |
pos.move (i); |
44 |
if (pos.normalise () |
45 |
&& (tmp = present (DOOR, pos.m, pos.x, pos.y))) |
46 |
{ |
47 |
tmp->set_speed (0.1f); |
48 |
tmp->speed_left = -0.2f; |
49 |
} |
50 |
} |
51 |
|
52 |
if (op->other_arch) |
53 |
{ |
54 |
object *tmp = arch_to_object (op->other_arch); |
55 |
tmp->x = op->x; |
56 |
tmp->y = op->y; |
57 |
tmp->map = op->map; |
58 |
tmp->level = op->level; |
59 |
insert_ob_in_map (tmp, op->map, op, 0); |
60 |
} |
61 |
|
62 |
op->drop_and_destroy (); |
63 |
} |
64 |
|
65 |
void |
66 |
remove_door2 (object *op) |
67 |
{ |
68 |
int i; |
69 |
object *tmp; |
70 |
|
71 |
for (i = 1; i < 9; i += 2) |
72 |
{ |
73 |
tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]); |
74 |
if (tmp && tmp->slaying == op->slaying) |
75 |
{ /* same key both doors */ |
76 |
tmp->set_speed (0.1f); |
77 |
tmp->speed_left = -0.2f; |
78 |
} |
79 |
} |
80 |
|
81 |
if (op->other_arch) |
82 |
{ |
83 |
tmp = arch_to_object (op->other_arch); |
84 |
tmp->x = op->x; |
85 |
tmp->y = op->y; |
86 |
tmp->map = op->map; |
87 |
tmp->level = op->level; |
88 |
insert_ob_in_map (tmp, op->map, op, 0); |
89 |
} |
90 |
|
91 |
op->drop_and_destroy (); |
92 |
} |
93 |
|
94 |
void |
95 |
generate_monster (object *gen) |
96 |
{ |
97 |
if (!gen->map) |
98 |
return; |
99 |
|
100 |
if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
101 |
return; |
102 |
|
103 |
// sleeping generators won't generate, this will make monsters like |
104 |
// centipedes not generate more centipedes when being asleep. |
105 |
if (gen->flag [FLAG_SLEEP]) |
106 |
return; |
107 |
|
108 |
object *op; |
109 |
int dir; |
110 |
|
111 |
if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
112 |
{ |
113 |
// either copy one item from the inventory... |
114 |
if (!gen->inv) |
115 |
return; |
116 |
|
117 |
// first select one item from the inventory |
118 |
int index = 0; |
119 |
for (object *tmp = gen->inv; tmp; tmp = tmp->below) |
120 |
if (!rndm (++index)) |
121 |
op = tmp; |
122 |
|
123 |
dir = find_free_spot (op, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1); |
124 |
if (dir < 0) |
125 |
return; |
126 |
|
127 |
op = op->deep_clone (); |
128 |
|
129 |
CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); |
130 |
unflag_inv (op, FLAG_IS_A_TEMPLATE); |
131 |
} |
132 |
else if (gen->other_arch) |
133 |
{ |
134 |
// ...or use other_arch |
135 |
dir = find_free_spot (gen->other_arch, gen->map, gen->x, gen->y, 1, SIZEOFFREE1 + 1); |
136 |
if (dir < 0) |
137 |
return; |
138 |
|
139 |
op = arch_to_object (gen->other_arch); |
140 |
} |
141 |
else |
142 |
return; |
143 |
|
144 |
op->expand_tail (); |
145 |
|
146 |
mapxy pos (gen); pos.move (dir); |
147 |
|
148 |
if (pos.insert (op, gen)) |
149 |
{ |
150 |
if (rndm (0, 9)) |
151 |
generate_artifact (op, gen->map->difficulty); |
152 |
|
153 |
if (op->has_random_items ()) |
154 |
create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); |
155 |
|
156 |
return; |
157 |
} |
158 |
|
159 |
op->destroy (); |
160 |
} |
161 |
|
162 |
void |
163 |
remove_force (object *op) |
164 |
{ |
165 |
if (--op->duration > 0) |
166 |
return; |
167 |
|
168 |
if (op->env) |
169 |
switch (op->subtype) |
170 |
{ |
171 |
case FORCE_CONFUSION: |
172 |
CLEAR_FLAG (op->env, FLAG_CONFUSED); |
173 |
new_draw_info (NDI_UNIQUE, 0, op->env, "You regain your senses.\n"); |
174 |
|
175 |
default: |
176 |
CLEAR_FLAG (op, FLAG_APPLIED); |
177 |
change_abil (op->env, op); |
178 |
op->env->update_stats (); |
179 |
} |
180 |
|
181 |
op->destroy (); |
182 |
} |
183 |
|
184 |
void |
185 |
remove_blindness (object *op) |
186 |
{ |
187 |
if (--op->stats.food > 0) |
188 |
return; |
189 |
|
190 |
CLEAR_FLAG (op, FLAG_APPLIED); |
191 |
|
192 |
if (op->env) |
193 |
{ |
194 |
change_abil (op->env, op); |
195 |
op->env->update_stats (); |
196 |
} |
197 |
|
198 |
op->destroy (); |
199 |
} |
200 |
|
201 |
void |
202 |
poison_more (object *op) |
203 |
{ |
204 |
if (op->env == NULL || !QUERY_FLAG (op->env, FLAG_ALIVE) || op->env->stats.hp < 0) |
205 |
{ |
206 |
op->destroy (); |
207 |
return; |
208 |
} |
209 |
|
210 |
if (op->stats.food == 1) |
211 |
{ |
212 |
/* need to unapply the object before update_stats is called, else fix_player |
213 |
* will not do anything. |
214 |
*/ |
215 |
if (op->env->type == PLAYER) |
216 |
{ |
217 |
CLEAR_FLAG (op, FLAG_APPLIED); |
218 |
op->env->update_stats (); |
219 |
new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now."); |
220 |
} |
221 |
|
222 |
op->destroy (); |
223 |
return; |
224 |
} |
225 |
|
226 |
if (op->env->type == PLAYER) |
227 |
{ |
228 |
op->env->stats.food--; |
229 |
new_draw_info (NDI_UNIQUE, 0, op->env, "You feel very sick..."); |
230 |
} |
231 |
|
232 |
hit_player (op->env, op->stats.dam, op, AT_INTERNAL, 1); |
233 |
} |
234 |
|
235 |
|
236 |
void |
237 |
move_gate (object *op) |
238 |
{ /* 1 = going down, 0 = going up */ |
239 |
object *tmp; |
240 |
|
241 |
if (op->stats.wc < 0 || (int) op->stats.wc >= NUM_ANIMATIONS (op)) |
242 |
{ |
243 |
LOG (llevError, "Gate error: animation was %d, max=%d\n", op->stats.wc, NUM_ANIMATIONS (op)); |
244 |
op->stats.wc = 0; |
245 |
} |
246 |
|
247 |
/* We're going down */ |
248 |
if (op->value) |
249 |
{ |
250 |
if (--op->stats.wc <= 0) |
251 |
{ /* Reached bottom, let's stop */ |
252 |
op->stats.wc = 0; |
253 |
if (op->arch->speed) |
254 |
op->value = 0; |
255 |
else |
256 |
op->set_speed (0); |
257 |
} |
258 |
|
259 |
if ((int) op->stats.wc < (NUM_ANIMATIONS (op) / 2 + 1)) |
260 |
{ |
261 |
op->move_block = 0; |
262 |
CLEAR_FLAG (op, FLAG_BLOCKSVIEW); |
263 |
update_all_los (op->map, op->x, op->y); |
264 |
} |
265 |
|
266 |
SET_ANIMATION (op, op->stats.wc); |
267 |
update_object (op, UP_OBJ_CHANGE); |
268 |
return; |
269 |
} |
270 |
|
271 |
/* We're going up */ |
272 |
|
273 |
/* First, lets see if we are already at the top */ |
274 |
if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) |
275 |
{ |
276 |
|
277 |
/* Check to make sure that only non pickable and non rollable |
278 |
* objects are above the gate. If so, we finish closing the gate, |
279 |
* otherwise, we fall through to the code below which should lower |
280 |
* the gate slightly. |
281 |
*/ |
282 |
|
283 |
for (tmp = op->above; tmp; tmp = tmp->above) |
284 |
if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE)) |
285 |
break; |
286 |
|
287 |
if (!tmp) |
288 |
{ |
289 |
if (op->arch->speed) |
290 |
op->value = 1; |
291 |
else |
292 |
op->set_speed (0); |
293 |
|
294 |
return; |
295 |
} |
296 |
} |
297 |
|
298 |
if (op->stats.food) |
299 |
{ /* The gate is going temporarily down */ |
300 |
if (--op->stats.wc <= 0) |
301 |
{ /* Gone all the way down? */ |
302 |
op->stats.food = 0; /* Then let's try again */ |
303 |
op->stats.wc = 0; |
304 |
} |
305 |
} |
306 |
else |
307 |
{ /* The gate is still going up */ |
308 |
op->stats.wc++; |
309 |
|
310 |
if (op->stats.wc >= NUM_ANIMATIONS (op)) |
311 |
op->stats.wc = NUM_ANIMATIONS (op) - 1; |
312 |
|
313 |
/* If there is something on top of the gate, we try to roll it off. |
314 |
* If a player/monster, we don't roll, we just hit them with damage |
315 |
*/ |
316 |
if (op->stats.wc >= NUM_ANIMATIONS (op) / 2) |
317 |
{ |
318 |
/* Halfway or further, check blocks */ |
319 |
/* First, get the top object on the square. */ |
320 |
for (tmp = op->above; tmp && tmp->above; tmp = tmp->above) |
321 |
; |
322 |
|
323 |
if (tmp) |
324 |
{ |
325 |
if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
326 |
{ |
327 |
hit_player (tmp, random_roll (0, op->stats.dam, tmp, PREFER_LOW), op, AT_PHYSICAL, 1); |
328 |
op->play_sound (sound_find ("blocked_gate")); |
329 |
|
330 |
if (tmp->type == PLAYER) |
331 |
new_draw_info_format (NDI_UNIQUE, 0, tmp, "You are crushed by the %s!", &op->name); |
332 |
} |
333 |
/* If the object is not alive, and the object either can |
334 |
* be picked up or the object rolls, move the object |
335 |
* off the gate. |
336 |
*/ |
337 |
else if (!QUERY_FLAG (tmp, FLAG_ALIVE) && (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL))) |
338 |
{ |
339 |
/* If it has speed, it should move itself, otherwise: */ |
340 |
int i = find_free_spot (tmp, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
341 |
|
342 |
/* If there is a free spot, move the object someplace */ |
343 |
if (i > 0) |
344 |
{ |
345 |
mapxy pos (tmp); |
346 |
pos.move (i); |
347 |
if (pos.normalise ()) |
348 |
tmp->move_to (pos); |
349 |
} |
350 |
} |
351 |
} |
352 |
|
353 |
/* See if there is still anything blocking the gate */ |
354 |
for (tmp = op->above; tmp; tmp = tmp->above) |
355 |
if (!QUERY_FLAG (tmp, FLAG_NO_PICK) || QUERY_FLAG (tmp, FLAG_CAN_ROLL) || QUERY_FLAG (tmp, FLAG_ALIVE)) |
356 |
break; |
357 |
|
358 |
/* IF there is, start putting the gate down */ |
359 |
if (tmp) |
360 |
op->stats.food = 1; |
361 |
else |
362 |
{ |
363 |
op->move_block = MOVE_ALL; |
364 |
|
365 |
if (!op->arch->stats.ac) |
366 |
SET_FLAG (op, FLAG_BLOCKSVIEW); |
367 |
update_all_los (op->map, op->x, op->y); |
368 |
} |
369 |
} /* gate is halfway up */ |
370 |
|
371 |
SET_ANIMATION (op, op->stats.wc); |
372 |
update_object (op, UP_OBJ_CHANGE); |
373 |
} /* gate is going up */ |
374 |
} |
375 |
|
376 |
/* hp : how long door is open/closed |
377 |
* maxhp : initial value for hp |
378 |
* sp : 1 = open, 0 = close |
379 |
*/ |
380 |
void |
381 |
move_timed_gate (object *op) |
382 |
{ |
383 |
int v = op->value; |
384 |
|
385 |
if (op->stats.sp) |
386 |
{ |
387 |
move_gate (op); |
388 |
|
389 |
if (op->value != v) /* change direction ? */ |
390 |
op->stats.sp = 0; |
391 |
return; |
392 |
} |
393 |
|
394 |
if (--op->stats.hp <= 0) |
395 |
{ /* keep gate down */ |
396 |
move_gate (op); |
397 |
|
398 |
if (op->value != v) |
399 |
op->set_speed (0); |
400 |
} |
401 |
} |
402 |
|
403 |
/* slaying: name of the thing the detector is to look for |
404 |
* speed: frequency of 'glances' |
405 |
* connected: connected value of detector |
406 |
* sp: 1 if detection sets buttons |
407 |
* -1 if detection unsets buttons |
408 |
*/ |
409 |
|
410 |
void |
411 |
move_detector (object *op) |
412 |
{ |
413 |
object *tmp; |
414 |
int last = op->value; |
415 |
int detected; |
416 |
|
417 |
detected = 0; |
418 |
|
419 |
for (tmp = op->ms ().bot; tmp && !detected; tmp = tmp->above) |
420 |
{ |
421 |
object *tmp2; |
422 |
|
423 |
if (op->stats.hp) |
424 |
{ |
425 |
for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
426 |
{ |
427 |
if (op->slaying && op->slaying == tmp->name) |
428 |
detected = 1; |
429 |
|
430 |
if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying) |
431 |
detected = 1; |
432 |
} |
433 |
} |
434 |
|
435 |
if (op->slaying && op->slaying == tmp->name) |
436 |
detected = 1; |
437 |
else if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying) |
438 |
detected = 1; |
439 |
} |
440 |
|
441 |
/* the detector sets the button if detection is found */ |
442 |
if (op->stats.sp == 1) |
443 |
{ |
444 |
if (detected && last == 0) |
445 |
{ |
446 |
op->value = 1; |
447 |
push_button (op, tmp); |
448 |
} |
449 |
|
450 |
if (!detected && last == 1) |
451 |
{ |
452 |
op->value = 0; |
453 |
push_button (op, tmp); |
454 |
} |
455 |
} |
456 |
else |
457 |
{ /* in this case, we unset buttons */ |
458 |
if (detected && last == 1) |
459 |
{ |
460 |
op->value = 0; |
461 |
push_button (op, tmp); |
462 |
} |
463 |
|
464 |
if (!detected && last == 0) |
465 |
{ |
466 |
op->value = 1; |
467 |
push_button (op, tmp); |
468 |
} |
469 |
} |
470 |
} |
471 |
|
472 |
void |
473 |
animate_trigger (object *op) |
474 |
{ |
475 |
if ((unsigned char) ++op->stats.wc >= NUM_ANIMATIONS (op)) |
476 |
{ |
477 |
op->stats.wc = 0; |
478 |
check_trigger (op, NULL); |
479 |
} |
480 |
else |
481 |
{ |
482 |
SET_ANIMATION (op, op->stats.wc); |
483 |
update_object (op, UP_OBJ_FACE); |
484 |
} |
485 |
} |
486 |
|
487 |
void |
488 |
move_hole (object *op) |
489 |
{ /* 1 = opening, 0 = closing */ |
490 |
if (op->value) |
491 |
{ /* We're opening */ |
492 |
if (--op->stats.wc <= 0) |
493 |
{ /* Opened, let's stop */ |
494 |
op->stats.wc = 0; |
495 |
op->set_speed (0); |
496 |
|
497 |
/* Hard coding this makes sense for holes I suppose */ |
498 |
op->move_on = MOVE_WALK; |
499 |
for (object *next, *tmp = op->above; tmp; tmp = next) |
500 |
{ |
501 |
next = tmp->above; |
502 |
move_apply (op, tmp, tmp); |
503 |
} |
504 |
} |
505 |
|
506 |
SET_ANIMATION (op, op->stats.wc); |
507 |
update_object (op, UP_OBJ_FACE); |
508 |
return; |
509 |
} |
510 |
|
511 |
/* We're closing */ |
512 |
op->move_on = 0; |
513 |
|
514 |
op->stats.wc++; |
515 |
if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) |
516 |
op->stats.wc = NUM_ANIMATIONS (op) - 1; |
517 |
|
518 |
SET_ANIMATION (op, op->stats.wc); |
519 |
update_object (op, UP_OBJ_FACE); |
520 |
if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) |
521 |
op->set_speed (0); /* closed, let's stop */ |
522 |
} |
523 |
|
524 |
|
525 |
/* stop_item() returns a pointer to the stopped object. The stopped object |
526 |
* may or may not have been removed from maps or inventories. It will not |
527 |
* have been merged with other items. |
528 |
* |
529 |
* This function assumes that only items on maps need special treatment. |
530 |
* |
531 |
* If the object can't be stopped, or it was destroyed while trying to stop |
532 |
* it, NULL is returned. |
533 |
* |
534 |
* fix_stopped_item() should be used if the stopped item should be put on |
535 |
* the map. |
536 |
*/ |
537 |
object * |
538 |
stop_item (object *op) |
539 |
{ |
540 |
if (op->map == NULL) |
541 |
return op; |
542 |
|
543 |
switch (op->type) |
544 |
{ |
545 |
case THROWN_OBJ: |
546 |
{ |
547 |
object *payload = op->inv; |
548 |
|
549 |
if (payload == NULL) |
550 |
return NULL; |
551 |
|
552 |
payload->remove (); |
553 |
op->destroy (); |
554 |
return payload; |
555 |
} |
556 |
|
557 |
case ARROW: |
558 |
if (op->has_active_speed ()) |
559 |
op = fix_stopped_arrow (op); |
560 |
return op; |
561 |
|
562 |
default: |
563 |
return op; |
564 |
} |
565 |
} |
566 |
|
567 |
/* fix_stopped_item() - put stopped item where stop_item() had found it. |
568 |
* Inserts item into the old map, or merges it if it already is on the map. |
569 |
* |
570 |
* 'map' must be the value of op->map before stop_item() was called. |
571 |
*/ |
572 |
void |
573 |
fix_stopped_item (object *op, maptile *map, object *originator) |
574 |
{ |
575 |
if (map == NULL) |
576 |
return; |
577 |
|
578 |
if (QUERY_FLAG (op, FLAG_REMOVED)) |
579 |
insert_ob_in_map (op, map, originator, 0); |
580 |
else if (op->type == ARROW) |
581 |
merge_ob (op, NULL); /* only some arrows actually need this */ |
582 |
} |
583 |
|
584 |
object * |
585 |
fix_stopped_arrow (object *op) |
586 |
{ |
587 |
if (rndm (0, 99) < op->stats.food) |
588 |
{ |
589 |
/* Small chance of breaking */ |
590 |
op->destroy (); |
591 |
return NULL; |
592 |
} |
593 |
|
594 |
op->set_speed (0); |
595 |
op->direction = 0; |
596 |
op->move_on = 0; |
597 |
op->move_type = 0; |
598 |
op->skill = 0; // really? |
599 |
|
600 |
// restore original wc, dam, attacktype and slaying |
601 |
op->stats.wc = op->stats.sp; |
602 |
op->stats.dam = op->stats.hp; |
603 |
op->attacktype = op->stats.grace; |
604 |
|
605 |
if (op->spellarg) |
606 |
{ |
607 |
op->slaying = op->spellarg; |
608 |
free (op->spellarg); |
609 |
op->spellarg = 0; |
610 |
} |
611 |
else |
612 |
op->slaying = 0; |
613 |
|
614 |
/* Reset these to zero, so that object::can_merge will work properly */ |
615 |
op->spellarg = NULL; |
616 |
op->stats.sp = 0; |
617 |
op->stats.hp = 0; |
618 |
op->stats.grace = 0; |
619 |
op->level = 0; |
620 |
op->face = op->arch->face; |
621 |
op->owner = NULL; /* So that stopped arrows will be saved */ |
622 |
update_object (op, UP_OBJ_CHANGE); |
623 |
return op; |
624 |
} |
625 |
|
626 |
/* stop_arrow() - what to do when a non-living flying object |
627 |
* has to stop. Sept 96 - I added in thrown object code in |
628 |
* here too. -b.t. |
629 |
* |
630 |
* Returns a pointer to the stopped object (which will have been removed |
631 |
* from maps or inventories), or NULL if was destroyed. |
632 |
*/ |
633 |
static void |
634 |
stop_arrow (object *op) |
635 |
{ |
636 |
if (INVOKE_OBJECT (STOP, op)) |
637 |
return; |
638 |
|
639 |
if (op->inv) |
640 |
{ |
641 |
// replace this by straightforward drop to ground? |
642 |
object *payload = op->inv; |
643 |
|
644 |
payload->owner = 0; |
645 |
insert_ob_in_map (payload, op->map, payload, 0); |
646 |
op->destroy (); |
647 |
} |
648 |
else |
649 |
{ |
650 |
op = fix_stopped_arrow (op); |
651 |
|
652 |
if (op) |
653 |
merge_ob (op, 0); |
654 |
} |
655 |
} |
656 |
|
657 |
/* Move an arrow along its course. op is the arrow or thrown object. |
658 |
*/ |
659 |
void |
660 |
move_arrow (object *op) |
661 |
{ |
662 |
int was_reflected; |
663 |
|
664 |
if (!op->map) |
665 |
{ |
666 |
LOG (llevError, "BUG: Arrow had no map.\n"); |
667 |
op->destroy (); |
668 |
return; |
669 |
} |
670 |
|
671 |
/* we need to stop thrown objects at some point. Like here. */ |
672 |
if (op->type == THROWN_OBJ) |
673 |
{ |
674 |
/* If the object that the THROWN_OBJ encapsulates disappears, |
675 |
* we need to have this object go away also - otherwise, you get |
676 |
* left over remnants on the map. Where this currently happens |
677 |
* is if the player throws a bomb - the bomb explodes on its own, |
678 |
* but this object sticks around. We could handle the cleanup in the |
679 |
* bomb code, but there are potential other cases where that could happen, |
680 |
* and it is easy enough to clean it up here. |
681 |
*/ |
682 |
if (!op->inv) |
683 |
{ |
684 |
op->destroy (); |
685 |
return; |
686 |
} |
687 |
|
688 |
if (op->last_sp-- < 0) |
689 |
{ |
690 |
stop_arrow (op); |
691 |
return; |
692 |
} |
693 |
} |
694 |
|
695 |
/* if the arrow is moving too slow.. stop it. 0.5 was chosen as lower |
696 |
values look rediculous. */ |
697 |
if (op->speed < 0.5 && op->type == ARROW) |
698 |
{ |
699 |
stop_arrow (op); |
700 |
return; |
701 |
} |
702 |
|
703 |
/* Calculate target map square */ |
704 |
was_reflected = 0; |
705 |
|
706 |
mapxy pos (op); pos.move (op->direction); |
707 |
|
708 |
if (!pos.normalise ()) |
709 |
{ |
710 |
stop_arrow (op); |
711 |
return; |
712 |
} |
713 |
|
714 |
/* only need to look for living creatures if this flag is set */ |
715 |
if (pos->flags () & P_IS_ALIVE) |
716 |
{ |
717 |
object *tmp; |
718 |
|
719 |
for (tmp = pos->bot; tmp; tmp = tmp->above) |
720 |
if (QUERY_FLAG (tmp, FLAG_ALIVE)) |
721 |
break; |
722 |
|
723 |
/* Not really fair, but don't let monsters hit themselves with |
724 |
* their own arrow - this can be because they fire it then |
725 |
* move into it. |
726 |
*/ |
727 |
if (tmp && tmp != op->owner) |
728 |
{ |
729 |
/* Found living object, but it is reflecting the missile. Update |
730 |
* as below. (Note that for living creatures there is a small |
731 |
* chance that reflect_missile fails.) |
732 |
*/ |
733 |
if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) |
734 |
{ |
735 |
int number = op->face; |
736 |
|
737 |
op->direction = absdir (op->direction + 4); |
738 |
update_turn_face (op); |
739 |
was_reflected = 1; /* skip normal movement calculations */ |
740 |
} |
741 |
else |
742 |
{ |
743 |
/* Attack the object. */ |
744 |
op = hit_with_arrow (op, tmp); |
745 |
|
746 |
if (!op) |
747 |
return; |
748 |
} |
749 |
} /* if this is not hitting its owner */ |
750 |
} /* if there is something alive on this space */ |
751 |
|
752 |
if (OB_TYPE_MOVE_BLOCK (op, pos->move_block)) |
753 |
{ |
754 |
int retry = 0; |
755 |
|
756 |
/* if the object doesn't reflect, stop the arrow from moving |
757 |
* note that this code will now catch cases where a monster is |
758 |
* on a wall but has reflecting - the arrow won't reflect. |
759 |
* Mapmakers shouldn't put monsters on top of wall in the first |
760 |
* place, so I don't consider that a problem. |
761 |
*/ |
762 |
if (!QUERY_FLAG (op, FLAG_REFLECTING) || !(rndm (0, 19))) |
763 |
{ |
764 |
stop_arrow (op); |
765 |
return; |
766 |
} |
767 |
else |
768 |
{ |
769 |
/* If one of the major directions (n,s,e,w), just reverse it */ |
770 |
if (op->direction & 1) |
771 |
{ |
772 |
op->direction = absdir (op->direction + 4); |
773 |
retry = 1; |
774 |
} |
775 |
|
776 |
/* There were two blocks with identical code - |
777 |
* use this retry here to make this one block |
778 |
* that did the same thing. |
779 |
*/ |
780 |
while (retry < 2) |
781 |
{ |
782 |
retry++; |
783 |
|
784 |
/* Need to check for P_OUT_OF_MAP: if the arrow is travelling |
785 |
* over a corner in a tiled map, it is possible that |
786 |
* op->direction is within an adjacent map but either |
787 |
* op->direction-1 or op->direction+1 does not exist. |
788 |
*/ |
789 |
mapxy pos1 (pos); pos1.move (absdir (op->direction - 1)); |
790 |
bool left = pos1.normalise () && OB_TYPE_MOVE_BLOCK (op, pos1->move_block); |
791 |
|
792 |
mapxy pos2 (pos); pos2.move (absdir (op->direction + 1)); |
793 |
bool right = pos2.normalise () && OB_TYPE_MOVE_BLOCK (op, pos2->move_block); |
794 |
|
795 |
if (left == right) |
796 |
op->direction = absdir (op->direction + 4); |
797 |
else if (left) |
798 |
op->direction = absdir (op->direction + 2); |
799 |
else if (right) |
800 |
op->direction = absdir (op->direction - 2); |
801 |
|
802 |
/* If this space is not out of the map and not blocked, valid space - |
803 |
* don't need to retry again. |
804 |
*/ |
805 |
mapxy pos3 (pos); pos3.move (op->direction); |
806 |
if (pos3.normalise () && !OB_TYPE_MOVE_BLOCK (op, pos3->move_block)) |
807 |
break; |
808 |
} |
809 |
|
810 |
/* Couldn't find a direction to move the arrow to - just |
811 |
* stop it from moving. |
812 |
*/ |
813 |
if (retry == 2) |
814 |
{ |
815 |
stop_arrow (op); |
816 |
return; |
817 |
} |
818 |
|
819 |
/* update object image for new facing */ |
820 |
/* many thrown objects *don't* have more than one face */ |
821 |
if (GET_ANIM_ID (op)) |
822 |
SET_ANIMATION (op, op->direction); |
823 |
} /* object is reflected */ |
824 |
} /* object ran into a wall */ |
825 |
|
826 |
/* decrease the speed as it flies. 0.05 means a standard bow will shoot |
827 |
* about 17 squares. Tune as needed. |
828 |
*/ |
829 |
op->speed -= 0.05; |
830 |
|
831 |
/* Move the arrow. */ |
832 |
op->move_to (pos); |
833 |
} |
834 |
|
835 |
void |
836 |
change_object (object *op) |
837 |
{ /* Doesn`t handle linked objs yet */ |
838 |
int i, j; |
839 |
|
840 |
if (!op->other_arch) |
841 |
{ |
842 |
LOG (llevError, "Change object (%s) without other_arch error.\n", op->debug_desc ()); |
843 |
return; |
844 |
} |
845 |
|
846 |
/* In non-living items only change when food value is 0 */ |
847 |
if (!QUERY_FLAG (op, FLAG_ALIVE)) |
848 |
{ |
849 |
if (op->stats.food-- > 0) |
850 |
return; |
851 |
|
852 |
op->stats.food = 1; /* so 1 other_arch is made */ |
853 |
} |
854 |
|
855 |
object *env = op->env; |
856 |
|
857 |
op->remove (); |
858 |
for (i = 0; i < op->stats.food; i++) |
859 |
{ |
860 |
object *tmp = arch_to_object (op->other_arch); |
861 |
|
862 |
tmp->stats.hp = op->stats.hp; /* The only variable it keeps. */ |
863 |
|
864 |
if (env) |
865 |
env->insert (tmp); |
866 |
else |
867 |
{ |
868 |
j = find_first_free_spot (tmp, op->map, op->x, op->y); |
869 |
if (j < 0) /* No free spot */ |
870 |
tmp->destroy (); |
871 |
else |
872 |
{ |
873 |
mapxy pos (op); pos.move (j); |
874 |
|
875 |
if (pos.normalise ()) |
876 |
pos.insert (tmp, op); |
877 |
} |
878 |
} |
879 |
} |
880 |
|
881 |
op->destroy (); |
882 |
} |
883 |
|
884 |
void |
885 |
move_teleporter (object *op) |
886 |
{ |
887 |
object *tmp, *head = op; |
888 |
|
889 |
/* if this is a multipart teleporter, handle the other parts |
890 |
* The check for speed isn't strictly needed - basically, if |
891 |
* there is an old multipart teleporter in which the other parts |
892 |
* have speed, we don't really want to call it twice for the same |
893 |
* function - in fact, as written below, part N would get called |
894 |
* N times without the speed check. |
895 |
*/ |
896 |
if (op->more && !op->more->has_active_speed ()) |
897 |
move_teleporter (op->more); |
898 |
|
899 |
if (op->head) |
900 |
head = op->head; |
901 |
|
902 |
for (tmp = op->above; tmp; tmp = tmp->above) |
903 |
if (!QUERY_FLAG (tmp, FLAG_IS_FLOOR)) |
904 |
break; |
905 |
|
906 |
/* If nothing above us to move, nothing to do */ |
907 |
if (!tmp || QUERY_FLAG (tmp, FLAG_WIZPASS)) |
908 |
return; |
909 |
|
910 |
if (EXIT_PATH (head)) |
911 |
{ |
912 |
if (tmp->type == PLAYER) |
913 |
{ |
914 |
if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
915 |
return; |
916 |
|
917 |
tmp->enter_exit (head); |
918 |
} |
919 |
else |
920 |
/* Currently only players can transfer maps */ |
921 |
return; |
922 |
} |
923 |
else if (EXIT_X (head) || EXIT_Y (head)) |
924 |
{ |
925 |
if (out_of_map (head->map, EXIT_X (head), EXIT_Y (head))) |
926 |
{ |
927 |
LOG (llevError, "Removed illegal teleporter.\n"); |
928 |
head->destroy (); |
929 |
return; |
930 |
} |
931 |
|
932 |
if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
933 |
return; |
934 |
|
935 |
transfer_ob (tmp, EXIT_X (head), EXIT_Y (head), 0, head); |
936 |
} |
937 |
else |
938 |
{ |
939 |
/* Random teleporter */ |
940 |
if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
941 |
return; |
942 |
|
943 |
teleport (head, TELEPORTER, tmp); |
944 |
} |
945 |
} |
946 |
|
947 |
/* This object will teleport someone to a different map |
948 |
and will also apply changes to the player from its inventory. |
949 |
This was invented for giving classes, but there's no reason it |
950 |
can't be generalized. |
951 |
*/ |
952 |
void |
953 |
move_player_changer (object *op) |
954 |
{ |
955 |
object *player; |
956 |
object *walk; |
957 |
|
958 |
if (!op->above || !EXIT_PATH (op)) |
959 |
return; |
960 |
|
961 |
/* This isn't all that great - means that the player_mover |
962 |
* needs to be on top. |
963 |
*/ |
964 |
if (op->above->type == PLAYER) |
965 |
{ |
966 |
if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (player))) |
967 |
return; |
968 |
|
969 |
player = op->above; |
970 |
|
971 |
for (walk = op->inv; walk; walk = walk->below) |
972 |
apply_changes_to_player (player, walk); |
973 |
|
974 |
player->update_stats (); |
975 |
|
976 |
esrv_send_inventory (op->above, op->above); |
977 |
esrv_update_item (UPD_FACE, op->above, op->above); |
978 |
|
979 |
/* update players death & WoR home-position */ |
980 |
if (*EXIT_PATH (op) == '/') |
981 |
{ |
982 |
player->contr->savebed_map = EXIT_PATH (op); |
983 |
player->contr->bed_x = EXIT_X (op); |
984 |
player->contr->bed_y = EXIT_Y (op); |
985 |
} |
986 |
else |
987 |
LOG (llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", &EXIT_PATH (op)); |
988 |
|
989 |
op->above->enter_exit (op); |
990 |
} |
991 |
} |
992 |
|
993 |
/* firewalls fire other spells. |
994 |
* The direction of the wall is stored in op->stats.sp. |
995 |
* walls can have hp, so they can be torn down. |
996 |
*/ |
997 |
void |
998 |
move_firewall (object *op) |
999 |
{ |
1000 |
object *spell; |
1001 |
|
1002 |
if (!op->map) |
1003 |
return; /* dm has created a firewall in his inventory */ |
1004 |
|
1005 |
spell = op->inv; |
1006 |
|
1007 |
if (!spell || spell->type != SPELL) |
1008 |
spell = op->other_arch; |
1009 |
|
1010 |
if (!spell) |
1011 |
{ |
1012 |
LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, &op->map->name, op->x, op->y); |
1013 |
return; |
1014 |
} |
1015 |
|
1016 |
cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL); |
1017 |
} |
1018 |
|
1019 |
/* move_player_mover: this function takes a "player mover" as an |
1020 |
* argument, and performs the function of a player mover, which is: |
1021 |
* |
1022 |
* a player mover finds any players that are sitting on it. It |
1023 |
* moves them in the op->stats.sp direction. speed is how often it'll move. |
1024 |
* If attacktype is nonzero it will paralyze the player. If lifesave is set, |
1025 |
* it'll dissapear after hp+1 moves. If hp is set and attacktype is set, |
1026 |
* it'll paralyze the victim for hp*his speed/op->speed |
1027 |
*/ |
1028 |
void |
1029 |
move_player_mover (object *op) |
1030 |
{ |
1031 |
int dir = op->stats.sp; |
1032 |
sint16 nx, ny; |
1033 |
maptile *m; |
1034 |
|
1035 |
/* Determine direction now for random movers so we do the right thing */ |
1036 |
if (!dir) |
1037 |
dir = rndm (1, 8); |
1038 |
|
1039 |
for (object *victim = op->ms ().bot; victim; victim = victim->above) |
1040 |
{ |
1041 |
if (QUERY_FLAG (victim, FLAG_ALIVE) && !QUERY_FLAG (victim, FLAG_WIZPASS) && |
1042 |
(victim->move_type & op->move_type || !victim->move_type)) |
1043 |
{ |
1044 |
|
1045 |
if (victim->head) |
1046 |
victim = victim->head; |
1047 |
|
1048 |
if (QUERY_FLAG (op, FLAG_LIFESAVE) && op->stats.hp-- < 0) |
1049 |
{ |
1050 |
op->remove (); |
1051 |
return; |
1052 |
} |
1053 |
|
1054 |
nx = op->x + freearr_x[dir]; |
1055 |
ny = op->y + freearr_y[dir]; |
1056 |
m = op->map; |
1057 |
if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) |
1058 |
{ |
1059 |
LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", &m->path, op->x, op->y); |
1060 |
return; |
1061 |
} |
1062 |
|
1063 |
if (should_director_abort (op, victim)) |
1064 |
return; |
1065 |
|
1066 |
for (object *nextmover = m->at (nx, ny).bot; nextmover; nextmover = nextmover->above) |
1067 |
{ |
1068 |
if (nextmover->type == PLAYERMOVER) |
1069 |
nextmover->speed_left = -.99f; |
1070 |
|
1071 |
if (QUERY_FLAG (nextmover, FLAG_ALIVE)) |
1072 |
op->speed_left = -1.1f; /* wait until the next thing gets out of the way */ |
1073 |
} |
1074 |
|
1075 |
if (victim->type == PLAYER) |
1076 |
{ |
1077 |
/* only level >=1 movers move people */ |
1078 |
if (op->level) |
1079 |
{ |
1080 |
/* Following is a bit of hack. We need to make sure it |
1081 |
* is cleared, otherwise the player will get stuck in |
1082 |
* place. This can happen if the player used a spell to |
1083 |
* get to this space. |
1084 |
*/ |
1085 |
victim->contr->fire_on = 0; |
1086 |
victim->speed_left = 1.f; |
1087 |
move_player (victim, dir); |
1088 |
} |
1089 |
else |
1090 |
return; |
1091 |
} |
1092 |
else |
1093 |
move_object (victim, dir); |
1094 |
|
1095 |
if (!op->stats.maxsp && op->attacktype) |
1096 |
op->stats.maxsp = 2; |
1097 |
|
1098 |
if (op->attacktype) |
1099 |
{ /* flag to paralyze the player */ |
1100 |
victim->speed_left = max (-5.f, -FABS (op->stats.maxsp * victim->speed / op->speed)); |
1101 |
} |
1102 |
} |
1103 |
} |
1104 |
} |
1105 |
|
1106 |
/* |
1107 |
* Will duplicate a specified object placed on top of it. |
1108 |
* connected: what will trigger it. |
1109 |
* level: multiplier. 0 to destroy. |
1110 |
* other_arch: the object to look for and duplicate. |
1111 |
*/ |
1112 |
|
1113 |
void |
1114 |
move_duplicator (object *op) |
1115 |
{ |
1116 |
object *tmp; |
1117 |
|
1118 |
if (!op->other_arch) |
1119 |
{ |
1120 |
LOG (llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? &op->map->path : "nullmap"); |
1121 |
return; |
1122 |
} |
1123 |
|
1124 |
if (op->above == NULL) |
1125 |
return; |
1126 |
|
1127 |
for (tmp = op->above; tmp; tmp = tmp->above) |
1128 |
{ |
1129 |
if (op->other_arch->archname == tmp->arch->archname) |
1130 |
{ |
1131 |
if (op->level <= 0) |
1132 |
tmp->destroy (); |
1133 |
else |
1134 |
{ |
1135 |
uint64 new_nrof = (uint64) tmp->nrof * op->level; |
1136 |
|
1137 |
if (new_nrof >= 1UL << 31) |
1138 |
new_nrof = 1UL << 31; |
1139 |
|
1140 |
tmp->nrof = new_nrof; |
1141 |
} |
1142 |
|
1143 |
break; |
1144 |
} |
1145 |
} |
1146 |
} |
1147 |
|
1148 |
/* move_creator (by peterm) |
1149 |
* it has the creator object create it's other_arch right on top of it. |
1150 |
* connected: what will trigger it |
1151 |
* hp: how many times it may create before stopping |
1152 |
* lifesave: if set, it'll never disappear but will go on creating |
1153 |
* everytime it's triggered |
1154 |
* other_arch: the object to create |
1155 |
* Note this can create large objects, however, in that case, it |
1156 |
* has to make sure that there is in fact space for the object. |
1157 |
* It should really do this for small objects also, but there is |
1158 |
* more concern with large objects, most notably a part being placed |
1159 |
* outside of the map which would cause the server to crash |
1160 |
*/ |
1161 |
void |
1162 |
move_creator (object *creator) |
1163 |
{ |
1164 |
object *new_ob; |
1165 |
|
1166 |
if (!QUERY_FLAG (creator, FLAG_LIFESAVE) && --creator->stats.hp < 0) |
1167 |
{ |
1168 |
creator->stats.hp = -1; |
1169 |
return; |
1170 |
} |
1171 |
|
1172 |
if (creator->inv) |
1173 |
{ |
1174 |
object *ob; |
1175 |
int i; |
1176 |
object *ob_to_copy; |
1177 |
|
1178 |
/* select random object from inventory to copy */ |
1179 |
ob_to_copy = creator->inv; |
1180 |
for (ob = creator->inv->below, i = 1; ob != NULL; ob = ob->below, i++) |
1181 |
{ |
1182 |
if (rndm (0, i) == 0) |
1183 |
{ |
1184 |
ob_to_copy = ob; |
1185 |
} |
1186 |
} |
1187 |
new_ob = ob_to_copy->deep_clone (); |
1188 |
CLEAR_FLAG (new_ob, FLAG_IS_A_TEMPLATE); |
1189 |
unflag_inv (new_ob, FLAG_IS_A_TEMPLATE); |
1190 |
} |
1191 |
else |
1192 |
{ |
1193 |
if (!creator->other_arch) |
1194 |
{ |
1195 |
LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", |
1196 |
&creator->name, &creator->map->path, creator->x, creator->y); |
1197 |
return; |
1198 |
} |
1199 |
|
1200 |
new_ob = object_create_arch (creator->other_arch); |
1201 |
fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); |
1202 |
} |
1203 |
|
1204 |
/* Make sure this multipart object fits */ |
1205 |
if (new_ob->arch->more && new_ob->blocked (creator->map, creator->x, creator->y)) |
1206 |
{ |
1207 |
new_ob->destroy (); |
1208 |
return; |
1209 |
} |
1210 |
|
1211 |
// for now lets try to identify everything generated here, it mostly |
1212 |
// happens automated, so this will at least fix many identify-experience holes |
1213 |
SET_FLAG (new_ob, FLAG_IDENTIFIED); |
1214 |
|
1215 |
insert_ob_in_map_at (new_ob, creator->map, creator, 0, creator->x, creator->y); |
1216 |
if (QUERY_FLAG (new_ob, FLAG_FREED)) |
1217 |
return; |
1218 |
|
1219 |
if (creator->slaying) |
1220 |
new_ob->name = new_ob->title = creator->slaying; |
1221 |
} |
1222 |
|
1223 |
/* move_marker --peterm@soda.csua.berkeley.edu |
1224 |
when moved, a marker will search for a player sitting above |
1225 |
it, and insert an invisible, weightless force into him |
1226 |
with a specific code as the slaying field. |
1227 |
At that time, it writes the contents of its own message |
1228 |
field to the player. The marker will decrement hp to |
1229 |
0 and then delete itself every time it grants a mark. |
1230 |
unless hp was zero to start with, in which case it is infinite.*/ |
1231 |
void |
1232 |
move_marker (object *op) |
1233 |
{ |
1234 |
if (object *tmp = op->ms ().player ()) |
1235 |
{ |
1236 |
/* remove an old force with a slaying field == op->name */ |
1237 |
if (object *force = tmp->force_find (op->name)) |
1238 |
force->destroy (); |
1239 |
|
1240 |
if (!tmp->force_find (op->slaying)) |
1241 |
{ |
1242 |
tmp->force_add (op->slaying, op->stats.food); |
1243 |
|
1244 |
if (op->msg) |
1245 |
new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); |
1246 |
|
1247 |
if (op->stats.hp > 0) |
1248 |
{ |
1249 |
op->stats.hp--; |
1250 |
|
1251 |
if (op->stats.hp == 0) |
1252 |
{ |
1253 |
/* marker expires--granted mark number limit */ |
1254 |
op->destroy (); |
1255 |
return; |
1256 |
} |
1257 |
} |
1258 |
} |
1259 |
} |
1260 |
} |
1261 |
|
1262 |
// mapscript objects activate themselves (only) then their timer fires |
1263 |
// TODO: maybe they should simply trigger the link like any other object? |
1264 |
void |
1265 |
move_mapscript (object *op) |
1266 |
{ |
1267 |
op->set_speed (0); |
1268 |
cfperl_mapscript_activate (op, true, op, 0); |
1269 |
} |
1270 |
|
1271 |
void move_lamp (object *op) |
1272 |
{ |
1273 |
// if the lamp/torch is off, we should disable it. |
1274 |
if (!op->glow_radius) |
1275 |
{ |
1276 |
op->set_speed (0); |
1277 |
return; |
1278 |
} |
1279 |
else |
1280 |
{ |
1281 |
// check whether the face might needs to be updated |
1282 |
// (currently this is needed to have already switched on torches |
1283 |
// on maps, as they just set the glow_radius in the archetype) |
1284 |
if (op->other_arch |
1285 |
&& ( |
1286 |
(op->flag [FLAG_ANIMATE] != op->other_arch->flag [FLAG_ANIMATE]) |
1287 |
|| (op->flag [FLAG_ANIMATE] |
1288 |
? (op->animation_id != op->other_arch->animation_id) |
1289 |
: (op->face != op->other_arch->face)) |
1290 |
)) |
1291 |
get_animation_from_arch (op, op->other_arch); |
1292 |
} |
1293 |
|
1294 |
// lamps and torches auf maps don't use up their fuel |
1295 |
if (op->is_on_map ()) |
1296 |
return; |
1297 |
|
1298 |
if (op->stats.food > 0) |
1299 |
{ |
1300 |
op->stats.food--; |
1301 |
return; |
1302 |
} |
1303 |
|
1304 |
apply_lamp (op, false); |
1305 |
} |
1306 |
|
1307 |
void |
1308 |
process_object (object *op) |
1309 |
{ |
1310 |
if (expect_false (QUERY_FLAG (op, FLAG_IS_A_TEMPLATE))) |
1311 |
return; |
1312 |
|
1313 |
if (expect_false (INVOKE_OBJECT (TICK, op))) |
1314 |
return; |
1315 |
|
1316 |
if (QUERY_FLAG (op, FLAG_MONSTER)) |
1317 |
if (move_monster (op) || QUERY_FLAG (op, FLAG_FREED)) |
1318 |
return; |
1319 |
|
1320 |
if (QUERY_FLAG (op, FLAG_ANIMATE) && op->anim_speed == 0) |
1321 |
{ |
1322 |
animate_object (op, op->contr ? op->facing : op->direction); |
1323 |
|
1324 |
if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |
1325 |
make_sure_seen (op); |
1326 |
} |
1327 |
|
1328 |
if (expect_false ( |
1329 |
op->flag [FLAG_GENERATOR] |
1330 |
|| op->flag [FLAG_CHANGING] |
1331 |
|| op->flag [FLAG_IS_USED_UP] |
1332 |
)) |
1333 |
{ |
1334 |
if (QUERY_FLAG (op, FLAG_CHANGING) && !op->state) |
1335 |
{ |
1336 |
change_object (op); |
1337 |
return; |
1338 |
} |
1339 |
|
1340 |
if (QUERY_FLAG (op, FLAG_GENERATOR) && !QUERY_FLAG (op, FLAG_FRIENDLY)) |
1341 |
generate_monster (op); |
1342 |
|
1343 |
if (QUERY_FLAG (op, FLAG_IS_USED_UP) && --op->stats.food <= 0) |
1344 |
{ |
1345 |
if (QUERY_FLAG (op, FLAG_APPLIED)) |
1346 |
remove_force (op); |
1347 |
else |
1348 |
{ |
1349 |
op->remove (); // TODO: really necessary? |
1350 |
|
1351 |
if (QUERY_FLAG (op, FLAG_SEE_ANYWHERE)) |
1352 |
make_sure_not_seen (op); |
1353 |
|
1354 |
op->drop_and_destroy (); |
1355 |
} |
1356 |
|
1357 |
return; |
1358 |
} |
1359 |
} |
1360 |
|
1361 |
switch (op->type) |
1362 |
{ |
1363 |
case SPELL_EFFECT: |
1364 |
move_spell_effect (op); |
1365 |
break; |
1366 |
|
1367 |
case ROD: |
1368 |
case HORN: |
1369 |
regenerate_rod (op); |
1370 |
break; |
1371 |
|
1372 |
case FORCE: |
1373 |
case POTION_EFFECT: |
1374 |
remove_force (op); |
1375 |
break; |
1376 |
|
1377 |
case BLINDNESS: |
1378 |
remove_blindness (op); |
1379 |
break; |
1380 |
|
1381 |
case POISONING: |
1382 |
poison_more (op); |
1383 |
break; |
1384 |
|
1385 |
case DISEASE: |
1386 |
move_disease (op); |
1387 |
break; |
1388 |
|
1389 |
case SYMPTOM: |
1390 |
move_symptom (op); |
1391 |
break; |
1392 |
|
1393 |
case THROWN_OBJ: |
1394 |
case ARROW: |
1395 |
move_arrow (op); |
1396 |
break; |
1397 |
|
1398 |
case DOOR: |
1399 |
remove_door (op); |
1400 |
break; |
1401 |
|
1402 |
case LOCKED_DOOR: |
1403 |
remove_door2 (op); |
1404 |
break; |
1405 |
|
1406 |
case TELEPORTER: |
1407 |
move_teleporter (op); |
1408 |
break; |
1409 |
|
1410 |
case GOLEM: |
1411 |
move_golem (op); |
1412 |
break; |
1413 |
|
1414 |
case EARTHWALL: |
1415 |
hit_player (op, 2, op, AT_PHYSICAL, 1); |
1416 |
break; |
1417 |
|
1418 |
case FIREWALL: |
1419 |
move_firewall (op); |
1420 |
if (op->stats.maxsp) |
1421 |
animate_turning (op); |
1422 |
break; |
1423 |
|
1424 |
case MOOD_FLOOR: |
1425 |
do_mood_floor (op); |
1426 |
break; |
1427 |
|
1428 |
case GATE: |
1429 |
move_gate (op); |
1430 |
break; |
1431 |
|
1432 |
case TIMED_GATE: |
1433 |
move_timed_gate (op); |
1434 |
break; |
1435 |
|
1436 |
case TRIGGER: |
1437 |
case TRIGGER_BUTTON: |
1438 |
case TRIGGER_PEDESTAL: |
1439 |
case TRIGGER_ALTAR: |
1440 |
animate_trigger (op); |
1441 |
break; |
1442 |
|
1443 |
case DETECTOR: |
1444 |
move_detector (op); |
1445 |
|
1446 |
case DIRECTOR: |
1447 |
if (op->stats.maxsp) |
1448 |
animate_turning (op); |
1449 |
break; |
1450 |
|
1451 |
case HOLE: |
1452 |
move_hole (op); |
1453 |
break; |
1454 |
|
1455 |
case DEEP_SWAMP: |
1456 |
move_deep_swamp (op); |
1457 |
break; |
1458 |
|
1459 |
case RUNE: |
1460 |
case TRAP: |
1461 |
move_rune (op); |
1462 |
break; |
1463 |
|
1464 |
case PLAYERMOVER: |
1465 |
move_player_mover (op); |
1466 |
break; |
1467 |
|
1468 |
case CREATOR: |
1469 |
move_creator (op); |
1470 |
break; |
1471 |
|
1472 |
case MARKER: |
1473 |
move_marker (op); |
1474 |
break; |
1475 |
|
1476 |
case PLAYER_CHANGER: |
1477 |
move_player_changer (op); |
1478 |
break; |
1479 |
|
1480 |
case PEACEMAKER: |
1481 |
move_peacemaker (op); |
1482 |
break; |
1483 |
|
1484 |
case PLAYER: |
1485 |
// players have their own speed-management, so undo the --speed_left |
1486 |
++op->speed_left; |
1487 |
break; |
1488 |
|
1489 |
case MAPSCRIPT: |
1490 |
move_mapscript (op); |
1491 |
break; |
1492 |
|
1493 |
case LAMP: |
1494 |
case TORCH: |
1495 |
move_lamp (op); |
1496 |
break; |
1497 |
} |
1498 |
} |
1499 |
|