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