1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game |
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 |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * the Free Software Foundation; either version 2 of the License, or |
10 | (at your option) any later version. |
11 | * (at your option) any later version. |
11 | |
12 | * |
12 | This program is distributed in the hope that it will be useful, |
13 | * This program is distributed in the hope that it will be useful, |
13 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
14 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
15 | GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
16 | |
17 | * |
17 | You should have received a copy of the GNU General Public License |
18 | * You should have received a copy of the GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * along with this program; if not, write to the Free Software |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | /* |
25 | /* |
25 | * Routines that is executed from objects based on their speed have been |
26 | * Routines that is executed from objects based on their speed have been |
26 | * collected in this file. |
27 | * collected in this file. |
27 | */ |
28 | */ |
28 | |
|
|
29 | #include <global.h> |
29 | #include <global.h> |
30 | #include <spells.h> |
30 | #include <spells.h> |
31 | #ifndef __CEXTRACT__ |
|
|
32 | # include <sproto.h> |
31 | #include <sproto.h> |
33 | #endif |
|
|
34 | |
32 | |
35 | /* The following removes doors. The functions check to see if similar |
33 | /* 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 |
34 | * 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.) |
35 | * so those will be removed shortly (in a cascade like fashion.) |
38 | */ |
36 | */ |
39 | |
|
|
40 | void |
37 | void |
41 | remove_door (object *op) |
38 | remove_door (object *op) |
42 | { |
39 | { |
43 | int i; |
40 | int i; |
44 | object *tmp; |
41 | object *tmp; |
45 | |
42 | |
46 | for (i = 1; i < 9; i += 2) |
43 | 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) |
44 | if ((tmp = present (DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i])) != NULL) |
48 | { |
45 | { |
49 | tmp->speed = 0.1; |
46 | tmp->set_speed (0.1); |
50 | update_ob_speed (tmp); |
|
|
51 | tmp->speed_left = -0.2; |
47 | tmp->speed_left = -0.2; |
52 | } |
48 | } |
53 | |
49 | |
54 | if (op->other_arch) |
50 | if (op->other_arch) |
55 | { |
51 | { |
… | |
… | |
73 | for (i = 1; i < 9; i += 2) |
69 | for (i = 1; i < 9; i += 2) |
74 | { |
70 | { |
75 | tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]); |
71 | tmp = present (LOCKED_DOOR, op->map, op->x + freearr_x[i], op->y + freearr_y[i]); |
76 | if (tmp && tmp->slaying == op->slaying) |
72 | if (tmp && tmp->slaying == op->slaying) |
77 | { /* same key both doors */ |
73 | { /* same key both doors */ |
78 | tmp->speed = 0.1; |
74 | tmp->set_speed (0.1); |
79 | update_ob_speed (tmp); |
|
|
80 | tmp->speed_left = -0.2; |
75 | tmp->speed_left = -0.2; |
81 | } |
76 | } |
82 | } |
77 | } |
|
|
78 | |
83 | if (op->other_arch) |
79 | if (op->other_arch) |
84 | { |
80 | { |
85 | tmp = arch_to_object (op->other_arch); |
81 | tmp = arch_to_object (op->other_arch); |
86 | tmp->x = op->x; |
82 | tmp->x = op->x; |
87 | tmp->y = op->y; |
83 | tmp->y = op->y; |
… | |
… | |
91 | } |
87 | } |
92 | |
88 | |
93 | op->destroy (); |
89 | op->destroy (); |
94 | } |
90 | } |
95 | |
91 | |
|
|
92 | static void |
|
|
93 | generate_monster_tail (object *gen, object *op) |
|
|
94 | { |
|
|
95 | op->expand_tail (); |
|
|
96 | |
|
|
97 | int i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9); |
|
|
98 | if (i >= 0) |
|
|
99 | { |
|
|
100 | if (insert_ob_in_map_at (op, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i])) |
|
|
101 | { |
|
|
102 | if (rndm (0, 9)) |
|
|
103 | generate_artifact (op, gen->map->difficulty); |
|
|
104 | |
|
|
105 | if (op->has_random_items ()) |
|
|
106 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty); |
|
|
107 | |
|
|
108 | return; |
|
|
109 | } |
|
|
110 | } |
|
|
111 | |
|
|
112 | op->destroy (); |
|
|
113 | } |
|
|
114 | |
96 | /* Will generate a monster according to content |
115 | /* Will generate a monster according to content |
97 | * of generator. |
116 | * of generator. |
98 | */ |
117 | */ |
99 | void |
118 | static void |
100 | generate_monster_inv (object *gen) |
119 | generate_monster_inv (object *gen) |
101 | { |
120 | { |
102 | int i; |
121 | if (!gen->inv) |
103 | object *op, *head = NULL; |
|
|
104 | |
|
|
105 | int qty = 0; |
|
|
106 | |
|
|
107 | /* Code below assumes the generator is on a map, as it tries |
|
|
108 | * to place the monster on the map. So if the generator |
|
|
109 | * isn't on a map, complain and exit. |
|
|
110 | */ |
|
|
111 | if (gen->map == NULL) |
|
|
112 | { |
|
|
113 | //LOG(llevError,"Generator (%s) not on a map?\n", gen->name); |
|
|
114 | return; |
|
|
115 | } |
|
|
116 | /*First count numer of objects in inv */ |
|
|
117 | for (op = gen->inv; op; op = op->below) |
|
|
118 | qty++; |
|
|
119 | if (!qty) |
|
|
120 | { |
|
|
121 | LOG (llevError, "Generator (%s) has no inventory in generate_monster_inv?\n", &gen->name); |
|
|
122 | return; /*No inventory */ |
|
|
123 | } |
|
|
124 | qty = rndm (0, qty - 1); |
|
|
125 | for (op = gen->inv; qty; qty--) |
|
|
126 | op = op->below; |
|
|
127 | i = find_free_spot (op, gen->map, gen->x, gen->y, 1, 9); |
|
|
128 | if (i == -1) |
|
|
129 | return; |
122 | return; |
|
|
123 | |
|
|
124 | /* First count number of objects in inv */ |
|
|
125 | int index = 0; |
|
|
126 | object *op; |
|
|
127 | for (object *tmp = gen->inv; tmp; tmp = tmp->below) |
|
|
128 | if (!rndm (++index)) |
|
|
129 | op = tmp; |
|
|
130 | |
130 | head = object_create_clone (op); |
131 | op = object_create_clone (op); |
|
|
132 | |
131 | CLEAR_FLAG (head, FLAG_IS_A_TEMPLATE); |
133 | CLEAR_FLAG (op, FLAG_IS_A_TEMPLATE); |
132 | unflag_inv (head, FLAG_IS_A_TEMPLATE); |
134 | unflag_inv (op, FLAG_IS_A_TEMPLATE); |
133 | if (rndm (0, 9)) |
135 | |
134 | generate_artifact (head, gen->map->difficulty); |
136 | generate_monster_tail (gen, op); |
135 | insert_ob_in_map_at (head, gen->map, gen, 0, gen->x + freearr_x[i], gen->y + freearr_y[i]); |
137 | } |
136 | if (QUERY_FLAG (head, FLAG_FREED)) |
138 | |
|
|
139 | static void |
|
|
140 | generate_monster_arch (object *gen) |
|
|
141 | { |
|
|
142 | if (archetype *at = gen->other_arch) |
|
|
143 | generate_monster_tail (gen, arch_to_object (at)); |
|
|
144 | } |
|
|
145 | |
|
|
146 | void |
|
|
147 | generate_monster (object *gen) |
|
|
148 | { |
|
|
149 | if (!gen->map) |
137 | return; |
150 | return; |
138 | if (head->has_random_items ()) |
|
|
139 | create_treasure (head->randomitems, head, GT_APPLY, gen->map->difficulty, 0); |
|
|
140 | } |
|
|
141 | |
|
|
142 | void |
|
|
143 | generate_monster_arch (object *gen) |
|
|
144 | { |
|
|
145 | int i; |
|
|
146 | object *op, *head = NULL, *prev = NULL; |
|
|
147 | archetype *at = gen->other_arch; |
|
|
148 | |
|
|
149 | if (gen->other_arch == NULL) |
|
|
150 | { |
|
|
151 | //LOG(llevError,"Generator without other_arch: %s\n",gen->name); |
|
|
152 | return; |
|
|
153 | } |
|
|
154 | /* Code below assumes the generator is on a map, as it tries |
|
|
155 | * to place the monster on the map. So if the generator |
|
|
156 | * isn't on a map, complain and exit. |
|
|
157 | */ |
|
|
158 | if (gen->map == NULL) |
|
|
159 | { |
|
|
160 | //LOG(llevError,"Generator (%s) not on a map?\n", gen->name); |
|
|
161 | return; |
|
|
162 | } |
|
|
163 | i = find_free_spot (&at->clone, gen->map, gen->x, gen->y, 1, 9); |
|
|
164 | if (i == -1) |
|
|
165 | return; |
|
|
166 | while (at != NULL) |
|
|
167 | { |
|
|
168 | op = arch_to_object (at); |
|
|
169 | op->x = gen->x + freearr_x[i] + at->clone.x; |
|
|
170 | op->y = gen->y + freearr_y[i] + at->clone.y; |
|
|
171 | |
|
|
172 | if (head != NULL) |
|
|
173 | op->head = head, prev->more = op; |
|
|
174 | |
|
|
175 | if (rndm (0, 9)) |
|
|
176 | generate_artifact (op, gen->map->difficulty); |
|
|
177 | insert_ob_in_map (op, gen->map, gen, 0); |
|
|
178 | if (QUERY_FLAG (op, FLAG_FREED)) |
|
|
179 | return; |
|
|
180 | if (op->has_random_items ()) |
|
|
181 | create_treasure (op->randomitems, op, GT_APPLY, gen->map->difficulty, 0); |
|
|
182 | if (head == NULL) |
|
|
183 | head = op; |
|
|
184 | prev = op; |
|
|
185 | at = at->more; |
|
|
186 | } |
|
|
187 | } |
|
|
188 | |
|
|
189 | void |
|
|
190 | generate_monster (object *gen) |
|
|
191 | { |
|
|
192 | |
151 | |
193 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
152 | if (GENERATE_SPEED (gen) && rndm (0, GENERATE_SPEED (gen) - 1)) |
194 | return; |
153 | return; |
|
|
154 | |
195 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
155 | if (QUERY_FLAG (gen, FLAG_CONTENT_ON_GEN)) |
196 | generate_monster_inv (gen); |
156 | generate_monster_inv (gen); |
197 | else |
157 | else |
198 | generate_monster_arch (gen); |
158 | generate_monster_arch (gen); |
199 | |
159 | |
… | |
… | |
203 | remove_force (object *op) |
163 | remove_force (object *op) |
204 | { |
164 | { |
205 | if (--op->duration > 0) |
165 | if (--op->duration > 0) |
206 | return; |
166 | return; |
207 | |
167 | |
|
|
168 | if (op->env) |
208 | switch (op->subtype) |
169 | switch (op->subtype) |
209 | { |
170 | { |
210 | case FORCE_CONFUSION: |
171 | case FORCE_CONFUSION: |
211 | if (op->env != NULL) |
|
|
212 | { |
|
|
213 | CLEAR_FLAG (op->env, FLAG_CONFUSED); |
172 | CLEAR_FLAG (op->env, FLAG_CONFUSED); |
214 | new_draw_info (NDI_UNIQUE, 0, op->env, "You regain your senses.\n"); |
173 | new_draw_info (NDI_UNIQUE, 0, op->env, "You regain your senses.\n"); |
215 | } |
|
|
216 | |
174 | |
217 | default: |
175 | default: |
218 | if (op->env != NULL) |
|
|
219 | { |
|
|
220 | CLEAR_FLAG (op, FLAG_APPLIED); |
176 | CLEAR_FLAG (op, FLAG_APPLIED); |
221 | change_abil (op->env, op); |
177 | change_abil (op->env, op); |
222 | fix_player (op->env); |
178 | op->env->update_stats (); |
223 | } |
|
|
224 | } |
179 | } |
225 | |
180 | |
226 | op->destroy (); |
181 | op->destroy (); |
227 | } |
182 | } |
228 | |
183 | |
229 | void |
184 | void |
… | |
… | |
232 | if (--op->stats.food > 0) |
187 | if (--op->stats.food > 0) |
233 | return; |
188 | return; |
234 | |
189 | |
235 | CLEAR_FLAG (op, FLAG_APPLIED); |
190 | CLEAR_FLAG (op, FLAG_APPLIED); |
236 | |
191 | |
237 | if (op->env != NULL) |
192 | if (op->env) |
238 | { |
193 | { |
239 | change_abil (op->env, op); |
194 | change_abil (op->env, op); |
240 | fix_player (op->env); |
195 | op->env->update_stats (); |
241 | } |
196 | } |
242 | |
197 | |
243 | op->destroy (); |
198 | op->destroy (); |
244 | } |
199 | } |
245 | |
200 | |
… | |
… | |
252 | return; |
207 | return; |
253 | } |
208 | } |
254 | |
209 | |
255 | if (op->stats.food == 1) |
210 | if (op->stats.food == 1) |
256 | { |
211 | { |
257 | /* need to remove the object before fix_player is called, else fix_player |
212 | /* need to unapply the object before update_stats is called, else fix_player |
258 | * will not do anything. |
213 | * will not do anything. |
259 | */ |
214 | */ |
260 | if (op->env->type == PLAYER) |
215 | if (op->env->type == PLAYER) |
261 | { |
216 | { |
262 | CLEAR_FLAG (op, FLAG_APPLIED); |
217 | CLEAR_FLAG (op, FLAG_APPLIED); |
263 | fix_player (op->env); |
218 | op->env->update_stats (); |
264 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now."); |
219 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel much better now."); |
265 | } |
220 | } |
266 | |
221 | |
267 | op->destroy (); |
222 | op->destroy (); |
268 | return; |
223 | return; |
… | |
… | |
271 | if (op->env->type == PLAYER) |
226 | if (op->env->type == PLAYER) |
272 | { |
227 | { |
273 | op->env->stats.food--; |
228 | op->env->stats.food--; |
274 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel very sick..."); |
229 | new_draw_info (NDI_UNIQUE, 0, op->env, "You feel very sick..."); |
275 | } |
230 | } |
|
|
231 | |
276 | (void) hit_player (op->env, op->stats.dam, op, AT_INTERNAL, 1); |
232 | hit_player (op->env, op->stats.dam, op, AT_INTERNAL, 1); |
277 | } |
233 | } |
278 | |
234 | |
279 | |
235 | |
280 | void |
236 | void |
281 | move_gate (object *op) |
237 | move_gate (object *op) |
… | |
… | |
295 | { /* Reached bottom, let's stop */ |
251 | { /* Reached bottom, let's stop */ |
296 | op->stats.wc = 0; |
252 | op->stats.wc = 0; |
297 | if (op->arch->clone.speed) |
253 | if (op->arch->clone.speed) |
298 | op->value = 0; |
254 | op->value = 0; |
299 | else |
255 | else |
300 | { |
|
|
301 | op->speed = 0; |
256 | op->set_speed (0); |
302 | update_ob_speed (op); |
|
|
303 | } |
257 | } |
304 | } |
258 | |
305 | if ((int) op->stats.wc < (NUM_ANIMATIONS (op) / 2 + 1)) |
259 | if ((int) op->stats.wc < (NUM_ANIMATIONS (op) / 2 + 1)) |
306 | { |
260 | { |
307 | op->move_block = 0; |
261 | op->move_block = 0; |
308 | CLEAR_FLAG (op, FLAG_BLOCKSVIEW); |
262 | CLEAR_FLAG (op, FLAG_BLOCKSVIEW); |
309 | update_all_los (op->map, op->x, op->y); |
263 | update_all_los (op->map, op->x, op->y); |
310 | } |
264 | } |
|
|
265 | |
311 | SET_ANIMATION (op, op->stats.wc); |
266 | SET_ANIMATION (op, op->stats.wc); |
312 | update_object (op, UP_OBJ_CHANGE); |
267 | update_object (op, UP_OBJ_CHANGE); |
313 | return; |
268 | return; |
314 | } |
269 | } |
315 | |
270 | |
… | |
… | |
332 | if (tmp == NULL) |
287 | if (tmp == NULL) |
333 | { |
288 | { |
334 | if (op->arch->clone.speed) |
289 | if (op->arch->clone.speed) |
335 | op->value = 1; |
290 | op->value = 1; |
336 | else |
291 | else |
337 | { |
|
|
338 | op->speed = 0; |
292 | op->set_speed (0); |
339 | update_ob_speed (op); /* Reached top, let's stop */ |
293 | |
340 | } |
|
|
341 | return; |
294 | return; |
342 | } |
295 | } |
343 | } |
296 | } |
344 | |
297 | |
345 | if (op->stats.food) |
298 | if (op->stats.food) |
… | |
… | |
436 | } |
389 | } |
437 | if (--op->stats.hp <= 0) |
390 | if (--op->stats.hp <= 0) |
438 | { /* keep gate down */ |
391 | { /* keep gate down */ |
439 | move_gate (op); |
392 | move_gate (op); |
440 | if (op->value != v) |
393 | if (op->value != v) |
441 | { /* ready ? */ |
|
|
442 | op->speed = 0; |
394 | op->set_speed (0); |
443 | update_ob_speed (op); |
|
|
444 | } |
|
|
445 | } |
395 | } |
446 | } |
396 | } |
447 | |
397 | |
448 | /* slaying: name of the thing the detector is to look for |
398 | /* slaying: name of the thing the detector is to look for |
449 | * speed: frequency of 'glances' |
399 | * speed: frequency of 'glances' |
… | |
… | |
467 | |
417 | |
468 | if (op->stats.hp) |
418 | if (op->stats.hp) |
469 | { |
419 | { |
470 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
420 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
471 | { |
421 | { |
472 | if (op->slaying && !strcmp (op->slaying, tmp->name)) |
422 | if (op->slaying && op->slaying == tmp->name) |
473 | detected = 1; |
423 | detected = 1; |
|
|
424 | |
474 | if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) |
425 | if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying) |
475 | detected = 1; |
426 | detected = 1; |
476 | } |
427 | } |
477 | } |
428 | } |
|
|
429 | |
478 | if (op->slaying && !strcmp (op->slaying, tmp->name)) |
430 | if (op->slaying && op->slaying == tmp->name) |
479 | { |
|
|
480 | detected = 1; |
431 | detected = 1; |
481 | } |
|
|
482 | else if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying) |
432 | else if (tmp->type == SPECIAL_KEY && tmp->slaying == op->slaying) |
483 | detected = 1; |
433 | detected = 1; |
484 | } |
434 | } |
485 | |
435 | |
486 | /* the detector sets the button if detection is found */ |
436 | /* the detector sets the button if detection is found */ |
… | |
… | |
536 | if (op->value) |
486 | if (op->value) |
537 | { /* We're opening */ |
487 | { /* We're opening */ |
538 | if (--op->stats.wc <= 0) |
488 | if (--op->stats.wc <= 0) |
539 | { /* Opened, let's stop */ |
489 | { /* Opened, let's stop */ |
540 | op->stats.wc = 0; |
490 | op->stats.wc = 0; |
541 | op->speed = 0; |
491 | op->set_speed (0); |
542 | update_ob_speed (op); |
|
|
543 | |
492 | |
544 | /* Hard coding this makes sense for holes I suppose */ |
493 | /* Hard coding this makes sense for holes I suppose */ |
545 | op->move_on = MOVE_WALK; |
494 | op->move_on = MOVE_WALK; |
546 | for (tmp = op->above; tmp != NULL; tmp = next) |
495 | for (tmp = op->above; tmp != NULL; tmp = next) |
547 | { |
496 | { |
548 | next = tmp->above; |
497 | next = tmp->above; |
549 | move_apply (op, tmp, tmp); |
498 | move_apply (op, tmp, tmp); |
550 | } |
499 | } |
551 | } |
500 | } |
|
|
501 | |
552 | SET_ANIMATION (op, op->stats.wc); |
502 | SET_ANIMATION (op, op->stats.wc); |
553 | update_object (op, UP_OBJ_FACE); |
503 | update_object (op, UP_OBJ_FACE); |
554 | return; |
504 | return; |
555 | } |
505 | } |
556 | /* We're closing */ |
506 | /* We're closing */ |
557 | op->move_on = 0; |
507 | op->move_on = 0; |
558 | |
508 | |
559 | op->stats.wc++; |
509 | op->stats.wc++; |
560 | if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) |
510 | if ((int) op->stats.wc >= NUM_ANIMATIONS (op)) |
561 | op->stats.wc = NUM_ANIMATIONS (op) - 1; |
511 | op->stats.wc = NUM_ANIMATIONS (op) - 1; |
|
|
512 | |
562 | SET_ANIMATION (op, op->stats.wc); |
513 | SET_ANIMATION (op, op->stats.wc); |
563 | update_object (op, UP_OBJ_FACE); |
514 | update_object (op, UP_OBJ_FACE); |
564 | if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) |
515 | if ((unsigned char) op->stats.wc == (NUM_ANIMATIONS (op) - 1)) |
565 | { |
|
|
566 | op->speed = 0; |
|
|
567 | update_ob_speed (op); /* closed, let's stop */ |
516 | op->set_speed (0); /* closed, let's stop */ |
568 | return; |
|
|
569 | } |
|
|
570 | } |
517 | } |
571 | |
518 | |
572 | |
519 | |
573 | /* stop_item() returns a pointer to the stopped object. The stopped object |
520 | /* stop_item() returns a pointer to the stopped object. The stopped object |
574 | * may or may not have been removed from maps or inventories. It will not |
521 | * may or may not have been removed from maps or inventories. It will not |
… | |
… | |
600 | op->destroy (); |
547 | op->destroy (); |
601 | return payload; |
548 | return payload; |
602 | } |
549 | } |
603 | |
550 | |
604 | case ARROW: |
551 | case ARROW: |
605 | if (op->speed >= MIN_ACTIVE_SPEED) |
552 | if (op->has_active_speed ()) |
606 | op = fix_stopped_arrow (op); |
553 | op = fix_stopped_arrow (op); |
607 | return op; |
554 | return op; |
608 | |
555 | |
609 | default: |
556 | default: |
610 | return op; |
557 | return op; |
… | |
… | |
619 | void |
566 | void |
620 | fix_stopped_item (object *op, maptile *map, object *originator) |
567 | fix_stopped_item (object *op, maptile *map, object *originator) |
621 | { |
568 | { |
622 | if (map == NULL) |
569 | if (map == NULL) |
623 | return; |
570 | return; |
|
|
571 | |
624 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
572 | if (QUERY_FLAG (op, FLAG_REMOVED)) |
625 | insert_ob_in_map (op, map, originator, 0); |
573 | insert_ob_in_map (op, map, originator, 0); |
626 | else if (op->type == ARROW) |
574 | else if (op->type == ARROW) |
627 | merge_ob (op, NULL); /* only some arrows actually need this */ |
575 | merge_ob (op, NULL); /* only some arrows actually need this */ |
628 | } |
576 | } |
629 | |
577 | |
630 | |
|
|
631 | object * |
578 | object * |
632 | fix_stopped_arrow (object *op) |
579 | fix_stopped_arrow (object *op) |
633 | { |
580 | { |
634 | if (rndm (0, 99) < op->stats.food) |
581 | if (rndm (0, 99) < op->stats.food) |
635 | { |
582 | { |
636 | /* Small chance of breaking */ |
583 | /* Small chance of breaking */ |
637 | op->destroy (); |
584 | op->destroy (); |
638 | return NULL; |
585 | return NULL; |
639 | } |
586 | } |
640 | |
587 | |
|
|
588 | op->set_speed (0); |
641 | op->direction = 0; |
589 | op->direction = 0; |
642 | op->move_on = 0; |
590 | op->move_on = 0; |
643 | op->move_type = 0; |
591 | op->move_type = 0; |
644 | op->speed = 0; |
|
|
645 | update_ob_speed (op); |
|
|
646 | op->stats.wc = op->stats.sp; |
592 | op->stats.wc = op->stats.sp; |
647 | op->stats.dam = op->stats.hp; |
593 | op->stats.dam = op->stats.hp; |
648 | op->attacktype = op->stats.grace; |
594 | op->attacktype = op->stats.grace; |
649 | op->slaying = 0; |
595 | op->slaying = 0; |
650 | op->skill = 0; |
596 | op->skill = 0; |
… | |
… | |
664 | op->stats.hp = 0; |
610 | op->stats.hp = 0; |
665 | op->stats.grace = 0; |
611 | op->stats.grace = 0; |
666 | op->level = 0; |
612 | op->level = 0; |
667 | op->face = op->arch->clone.face; |
613 | op->face = op->arch->clone.face; |
668 | op->owner = NULL; /* So that stopped arrows will be saved */ |
614 | op->owner = NULL; /* So that stopped arrows will be saved */ |
669 | update_object (op, UP_OBJ_FACE); |
615 | update_object (op, UP_OBJ_CHANGE); |
670 | return op; |
616 | return op; |
671 | } |
617 | } |
672 | |
618 | |
673 | /* stop_arrow() - what to do when a non-living flying object |
619 | /* stop_arrow() - what to do when a non-living flying object |
674 | * has to stop. Sept 96 - I added in thrown object code in |
620 | * has to stop. Sept 96 - I added in thrown object code in |
675 | * here too. -b.t. |
621 | * here too. -b.t. |
676 | * |
622 | * |
677 | * Returns a pointer to the stopped object (which will have been removed |
623 | * Returns a pointer to the stopped object (which will have been removed |
678 | * from maps or inventories), or NULL if was destroyed. |
624 | * from maps or inventories), or NULL if was destroyed. |
679 | */ |
625 | */ |
680 | |
|
|
681 | static void |
626 | static void |
682 | stop_arrow (object *op) |
627 | stop_arrow (object *op) |
683 | { |
628 | { |
684 | if (INVOKE_OBJECT (STOP, op)) |
629 | if (INVOKE_OBJECT (STOP, op)) |
685 | return; |
630 | return; |
… | |
… | |
701 | } |
646 | } |
702 | } |
647 | } |
703 | |
648 | |
704 | /* Move an arrow along its course. op is the arrow or thrown object. |
649 | /* Move an arrow along its course. op is the arrow or thrown object. |
705 | */ |
650 | */ |
706 | |
|
|
707 | void |
651 | void |
708 | move_arrow (object *op) |
652 | move_arrow (object *op) |
709 | { |
653 | { |
710 | object *tmp; |
654 | object *tmp; |
711 | sint16 new_x, new_y; |
655 | sint16 new_x, new_y; |
… | |
… | |
782 | * as below. (Note that for living creatures there is a small |
726 | * as below. (Note that for living creatures there is a small |
783 | * chance that reflect_missile fails.) |
727 | * chance that reflect_missile fails.) |
784 | */ |
728 | */ |
785 | if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) |
729 | if (QUERY_FLAG (tmp, FLAG_REFL_MISSILE) && (rndm (0, 99)) < (90 - op->level / 10)) |
786 | { |
730 | { |
787 | int number = op->face->number; |
731 | int number = op->face; |
788 | |
732 | |
789 | op->direction = absdir (op->direction + 4); |
733 | op->direction = absdir (op->direction + 4); |
790 | op->state = 0; |
734 | update_turn_face (op); |
791 | |
|
|
792 | if (GET_ANIM_ID (op)) |
|
|
793 | { |
|
|
794 | number += 4; |
|
|
795 | |
|
|
796 | if (number > GET_ANIMATION (op, 8)) |
|
|
797 | number -= 8; |
|
|
798 | |
|
|
799 | op->face = &new_faces[number]; |
|
|
800 | } |
|
|
801 | |
|
|
802 | was_reflected = 1; /* skip normal movement calculations */ |
735 | was_reflected = 1; /* skip normal movement calculations */ |
803 | } |
736 | } |
804 | else |
737 | else |
805 | { |
738 | { |
806 | /* Attack the object. */ |
739 | /* Attack the object. */ |
… | |
… | |
980 | * there is an old multipart teleporter in which the other parts |
913 | * there is an old multipart teleporter in which the other parts |
981 | * have speed, we don't really want to call it twice for the same |
914 | * have speed, we don't really want to call it twice for the same |
982 | * function - in fact, as written below, part N would get called |
915 | * function - in fact, as written below, part N would get called |
983 | * N times without the speed check. |
916 | * N times without the speed check. |
984 | */ |
917 | */ |
985 | if (op->more && FABS (op->more->speed) < MIN_ACTIVE_SPEED) |
918 | if (op->more && !op->more->has_active_speed ()) |
986 | move_teleporter (op->more); |
919 | move_teleporter (op->more); |
987 | |
920 | |
988 | if (op->head) |
921 | if (op->head) |
989 | head = op->head; |
922 | head = op->head; |
990 | |
923 | |
… | |
… | |
1001 | if (tmp->type == PLAYER) |
934 | if (tmp->type == PLAYER) |
1002 | { |
935 | { |
1003 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
936 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (tmp))) |
1004 | return; |
937 | return; |
1005 | |
938 | |
1006 | enter_exit (tmp, head); |
939 | tmp->enter_exit (head); |
1007 | } |
940 | } |
1008 | else |
941 | else |
1009 | /* Currently only players can transfer maps */ |
942 | /* Currently only players can transfer maps */ |
1010 | return; |
943 | return; |
1011 | } |
944 | } |
… | |
… | |
1036 | /* This object will teleport someone to a different map |
969 | /* This object will teleport someone to a different map |
1037 | and will also apply changes to the player from its inventory. |
970 | and will also apply changes to the player from its inventory. |
1038 | This was invented for giving classes, but there's no reason it |
971 | This was invented for giving classes, but there's no reason it |
1039 | can't be generalized. |
972 | can't be generalized. |
1040 | */ |
973 | */ |
1041 | |
|
|
1042 | void |
974 | void |
1043 | move_player_changer (object *op) |
975 | move_player_changer (object *op) |
1044 | { |
976 | { |
1045 | object *player; |
977 | object *player; |
1046 | object *walk; |
978 | object *walk; |
1047 | char c; |
|
|
1048 | |
979 | |
1049 | if (!op->above || !EXIT_PATH (op)) |
980 | if (!op->above || !EXIT_PATH (op)) |
1050 | return; |
981 | return; |
1051 | |
982 | |
1052 | /* This isn't all that great - means that the player_mover |
983 | /* This isn't all that great - means that the player_mover |
1053 | * needs to be on top. |
984 | * needs to be on top. |
1054 | */ |
985 | */ |
1055 | if (op->above->type == PLAYER) |
986 | if (op->above->type == PLAYER) |
1056 | { |
987 | { |
1057 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (player))) |
988 | if (INVOKE_OBJECT (TRIGGER, op, ARG_OBJECT (player))) |
1058 | return; |
989 | return; |
|
|
990 | |
1059 | player = op->above; |
991 | player = op->above; |
1060 | |
992 | |
1061 | for (walk = op->inv; walk != NULL; walk = walk->below) |
993 | for (walk = op->inv; walk; walk = walk->below) |
1062 | apply_changes_to_player (player, walk); |
994 | apply_changes_to_player (player, walk); |
1063 | |
995 | |
1064 | fix_player (player); |
996 | player->update_stats (); |
1065 | |
997 | |
1066 | esrv_send_inventory (op->above, op->above); |
998 | esrv_send_inventory (op->above, op->above); |
1067 | esrv_update_item (UPD_FACE, op->above, op->above); |
999 | esrv_update_item (UPD_FACE, op->above, op->above); |
1068 | |
1000 | |
1069 | /* update players death & WoR home-position */ |
1001 | /* update players death & WoR home-position */ |
1070 | sscanf (EXIT_PATH (op), "%c", &c); |
1002 | if (*EXIT_PATH (op) == '/') |
1071 | if (c == '/') |
|
|
1072 | { |
1003 | { |
1073 | strcpy (player->contr->savebed_map, EXIT_PATH (op)); |
1004 | player->contr->savebed_map = EXIT_PATH (op); |
1074 | player->contr->bed_x = EXIT_X (op); |
1005 | player->contr->bed_x = EXIT_X (op); |
1075 | player->contr->bed_y = EXIT_Y (op); |
1006 | player->contr->bed_y = EXIT_Y (op); |
1076 | } |
1007 | } |
1077 | else |
1008 | else |
1078 | LOG (llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", &EXIT_PATH (op)); |
1009 | LOG (llevDebug, "WARNING: destination '%s' in player_changer must be an absolute path!\n", &EXIT_PATH (op)); |
1079 | |
1010 | |
1080 | enter_exit (op->above, op); |
1011 | op->above->enter_exit (op); |
1081 | save_player (player, 1); |
|
|
1082 | } |
1012 | } |
1083 | } |
1013 | } |
1084 | |
1014 | |
1085 | /* firewalls fire other spells. |
1015 | /* firewalls fire other spells. |
1086 | * The direction of the wall is stored in op->stats.sp. |
1016 | * The direction of the wall is stored in op->stats.sp. |
… | |
… | |
1093 | |
1023 | |
1094 | if (!op->map) |
1024 | if (!op->map) |
1095 | return; /* dm has created a firewall in his inventory */ |
1025 | return; /* dm has created a firewall in his inventory */ |
1096 | |
1026 | |
1097 | spell = op->inv; |
1027 | spell = op->inv; |
|
|
1028 | |
1098 | if (!spell || spell->type != SPELL) |
1029 | if (!spell || spell->type != SPELL) |
1099 | spell = &op->other_arch->clone; |
1030 | spell = &op->other_arch->clone; |
|
|
1031 | |
1100 | if (!spell) |
1032 | if (!spell) |
1101 | { |
1033 | { |
1102 | LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, op->map->name, op->x, op->y); |
1034 | LOG (llevError, "move_firewall: no spell specified (%s, %s, %d, %d)\n", &op->name, &op->map->name, op->x, op->y); |
1103 | return; |
1035 | return; |
1104 | } |
1036 | } |
1105 | |
1037 | |
1106 | cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL); |
1038 | cast_spell (op, op, op->stats.sp ? op->stats.sp : rndm (1, 8), spell, NULL); |
1107 | } |
1039 | } |
1108 | |
|
|
1109 | |
1040 | |
1110 | /* move_player_mover: this function takes a "player mover" as an |
1041 | /* move_player_mover: this function takes a "player mover" as an |
1111 | * argument, and performs the function of a player mover, which is: |
1042 | * argument, and performs the function of a player mover, which is: |
1112 | * |
1043 | * |
1113 | * a player mover finds any players that are sitting on it. It |
1044 | * a player mover finds any players that are sitting on it. It |
… | |
… | |
1146 | nx = op->x + freearr_x[dir]; |
1077 | nx = op->x + freearr_x[dir]; |
1147 | ny = op->y + freearr_y[dir]; |
1078 | ny = op->y + freearr_y[dir]; |
1148 | m = op->map; |
1079 | m = op->map; |
1149 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) |
1080 | if (get_map_flags (m, &m, nx, ny, &nx, &ny) & P_OUT_OF_MAP) |
1150 | { |
1081 | { |
1151 | LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", m->path, op->x, op->y); |
1082 | LOG (llevError, "move_player_mover: Trying to push player off the map! map=%s (%d, %d)\n", &m->path, op->x, op->y); |
1152 | return; |
1083 | return; |
1153 | } |
1084 | } |
1154 | |
1085 | |
1155 | if (should_director_abort (op, victim)) |
1086 | if (should_director_abort (op, victim)) |
1156 | return; |
1087 | return; |
… | |
… | |
1217 | { |
1148 | { |
1218 | object *tmp; |
1149 | object *tmp; |
1219 | |
1150 | |
1220 | if (!op->other_arch) |
1151 | if (!op->other_arch) |
1221 | { |
1152 | { |
1222 | LOG (llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? op->map->path : "nullmap"); |
1153 | LOG (llevInfo, "Duplicator with no other_arch! %d %d %s\n", op->x, op->y, op->map ? &op->map->path : "nullmap"); |
1223 | return; |
1154 | return; |
1224 | } |
1155 | } |
1225 | |
1156 | |
1226 | if (op->above == NULL) |
1157 | if (op->above == NULL) |
1227 | return; |
1158 | return; |
|
|
1159 | |
1228 | for (tmp = op->above; tmp != NULL; tmp = tmp->above) |
1160 | for (tmp = op->above; tmp; tmp = tmp->above) |
1229 | { |
1161 | { |
1230 | if (strcmp (op->other_arch->name, tmp->arch->name) == 0) |
1162 | if (op->other_arch->name == tmp->arch->name) |
1231 | { |
1163 | { |
1232 | if (op->level <= 0) |
1164 | if (op->level <= 0) |
1233 | tmp->destroy (); |
1165 | tmp->destroy (); |
1234 | else |
1166 | else |
1235 | { |
1167 | { |
… | |
… | |
1292 | } |
1224 | } |
1293 | else |
1225 | else |
1294 | { |
1226 | { |
1295 | if (creator->other_arch == NULL) |
1227 | if (creator->other_arch == NULL) |
1296 | { |
1228 | { |
1297 | LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", &creator->name, creator->map->path, |
1229 | LOG (llevError, "move_creator: Creator doesn't have other arch set: %s (%s, %d, %d)\n", |
1298 | creator->x, creator->y); |
1230 | &creator->name, &creator->map->path, creator->x, creator->y); |
1299 | return; |
1231 | return; |
1300 | } |
1232 | } |
1301 | |
1233 | |
1302 | new_ob = object_create_arch (creator->other_arch); |
1234 | new_ob = object_create_arch (creator->other_arch); |
1303 | fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); |
1235 | fix_generated_item (new_ob, creator, 0, 0, GT_MINIMAL); |
… | |
… | |
1326 | with a specific code as the slaying field. |
1258 | with a specific code as the slaying field. |
1327 | At that time, it writes the contents of its own message |
1259 | At that time, it writes the contents of its own message |
1328 | field to the player. The marker will decrement hp to |
1260 | field to the player. The marker will decrement hp to |
1329 | 0 and then delete itself every time it grants a mark. |
1261 | 0 and then delete itself every time it grants a mark. |
1330 | unless hp was zero to start with, in which case it is infinite.*/ |
1262 | unless hp was zero to start with, in which case it is infinite.*/ |
1331 | |
|
|
1332 | void |
1263 | void |
1333 | move_marker (object *op) |
1264 | move_marker (object *op) |
1334 | { |
1265 | { |
|
|
1266 | if (object *tmp = op->ms ().player ()) |
|
|
1267 | { |
1335 | object *tmp, *tmp2; |
1268 | object *tmp2; |
1336 | |
1269 | |
1337 | for (tmp = GET_MAP_OB (op->map, op->x, op->y); tmp != NULL; tmp = tmp->above) |
|
|
1338 | { |
|
|
1339 | if (tmp->type == PLAYER) |
|
|
1340 | { /* we've got someone to MARK */ |
|
|
1341 | |
|
|
1342 | /* remove an old force with a slaying field == op->name */ |
1270 | /* remove an old force with a slaying field == op->name */ |
1343 | for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) |
1271 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
|
|
1272 | if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->name) |
1344 | { |
1273 | { |
1345 | if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->name)) |
|
|
1346 | break; |
|
|
1347 | } |
|
|
1348 | |
|
|
1349 | if (tmp2) |
|
|
1350 | tmp2->destroy (); |
1274 | tmp2->destroy (); |
|
|
1275 | break; |
|
|
1276 | } |
1351 | |
1277 | |
1352 | /* cycle through his inventory to look for the MARK we want to |
1278 | /* cycle through his inventory to look for the MARK we want to |
1353 | * place |
1279 | * place |
1354 | */ |
1280 | */ |
1355 | for (tmp2 = tmp->inv; tmp2 != NULL; tmp2 = tmp2->below) |
1281 | for (tmp2 = tmp->inv; tmp2; tmp2 = tmp2->below) |
1356 | { |
|
|
1357 | if (tmp2->type == FORCE && tmp2->slaying && !strcmp (tmp2->slaying, op->slaying)) |
1282 | if (tmp2->type == FORCE && tmp2->slaying && tmp2->slaying == op->slaying) |
1358 | break; |
1283 | break; |
1359 | } |
|
|
1360 | |
1284 | |
1361 | /* if we didn't find our own MARK */ |
1285 | /* if we didn't find our own MARK */ |
1362 | if (tmp2 == NULL) |
1286 | if (!tmp2) |
1363 | { |
1287 | { |
1364 | object *force = get_archetype (FORCE_NAME); |
1288 | object *force = get_archetype (FORCE_NAME); |
1365 | |
1289 | |
1366 | force->speed = 0; |
|
|
1367 | if (op->stats.food) |
1290 | if (op->stats.food) |
|
|
1291 | { |
|
|
1292 | force->set_speed (0.01); |
|
|
1293 | force->speed_left = -op->stats.food; |
|
|
1294 | } |
|
|
1295 | else |
|
|
1296 | force->set_speed (0); |
|
|
1297 | |
|
|
1298 | /* put in the lock code */ |
|
|
1299 | force->slaying = op->slaying; |
|
|
1300 | |
|
|
1301 | if (op->lore) |
|
|
1302 | force->lore = op->lore; |
|
|
1303 | |
|
|
1304 | insert_ob_in_ob (force, tmp); |
|
|
1305 | if (op->msg) |
|
|
1306 | new_draw_info (NDI_UNIQUE | NDI_NAVY, 0, tmp, op->msg); |
|
|
1307 | |
|
|
1308 | if (op->stats.hp > 0) |
|
|
1309 | { |
|
|
1310 | op->stats.hp--; |
|
|
1311 | if (op->stats.hp == 0) |
1368 | { |
1312 | { |
1369 | force->speed = 0.01; |
1313 | /* marker expires--granted mark number limit */ |
1370 | force->speed_left = -op->stats.food; |
1314 | op->destroy (); |
|
|
1315 | return; |
1371 | } |
1316 | } |
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 | op->destroy (); |
|
|
1390 | return; |
|
|
1391 | } |
|
|
1392 | } |
1317 | } |
1393 | } /* if tmp2 == NULL */ |
1318 | } |
1394 | } /* if tmp->type == PLAYER */ |
1319 | } |
1395 | } /* For all objects on this space */ |
|
|
1396 | } |
1320 | } |
1397 | |
1321 | |
1398 | int |
1322 | int |
1399 | process_object (object *op) |
1323 | process_object (object *op) |
1400 | { |
1324 | { |
… | |
… | |
1484 | return 0; |
1408 | return 0; |
1485 | |
1409 | |
1486 | case THROWN_OBJ: |
1410 | case THROWN_OBJ: |
1487 | case ARROW: |
1411 | case ARROW: |
1488 | move_arrow (op); |
1412 | move_arrow (op); |
1489 | return 0; |
|
|
1490 | |
|
|
1491 | case LIGHTNING: /* It now moves twice as fast */ |
|
|
1492 | move_bolt (op); |
|
|
1493 | return 0; |
1413 | return 0; |
1494 | |
1414 | |
1495 | case DOOR: |
1415 | case DOOR: |
1496 | remove_door (op); |
1416 | remove_door (op); |
1497 | return 0; |
1417 | return 0; |