1 | /* |
1 | /* |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
|
|
4 | * Copyright (©) 2017,2018 Marc Alexander Lehmann / the Deliantra team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2005,2006,2007,2008,2009,2010,2011,2012,2013,2014,2015,2016 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 2002 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * Copyright (©) 1992 Frank Tore Johansen |
7 | * |
8 | * |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * Deliantra is free software: you can redistribute it and/or modify it under |
9 | * it under the terms of the GNU General Public License as published by |
10 | * the terms of the Affero GNU General Public License as published by the |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * Free Software Foundation, either version 3 of the License, or (at your |
11 | * (at your option) any later version. |
12 | * option) any later version. |
12 | * |
13 | * |
13 | * This program is distributed in the hope that it will be useful, |
14 | * This program is distributed in the hope that it will be useful, |
14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
16 | * GNU General Public License for more details. |
17 | * GNU General Public License for more details. |
17 | * |
18 | * |
18 | * You should have received a copy of the GNU General Public License |
19 | * You should have received a copy of the Affero GNU General Public License |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * and the GNU General Public License along with this program. If not, see |
|
|
21 | * <http://www.gnu.org/licenses/>. |
20 | * |
22 | * |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
23 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
24 | */ |
23 | |
25 | |
24 | #include <global.h> |
26 | #include <global.h> |
25 | #include <sproto.h> |
27 | #include <sproto.h> |
… | |
… | |
70 | // return 0; |
72 | // return 0; |
71 | |
73 | |
72 | /* See if the pet has an existing enemy. If so, don't start a new one */ |
74 | /* See if the pet has an existing enemy. If so, don't start a new one */ |
73 | if (tmp = check_enemy (pet, rv)) |
75 | if (tmp = check_enemy (pet, rv)) |
74 | { |
76 | { |
75 | if (tmp == owner && !QUERY_FLAG (pet, FLAG_CONFUSED) && QUERY_FLAG (pet, FLAG_FRIENDLY)) |
77 | if (tmp == owner && !pet->flag [FLAG_CONFUSED] && pet->flag [FLAG_FRIENDLY]) |
76 | /* without this check, you can actually get pets with |
78 | /* without this check, you can actually get pets with |
77 | * enemy set to owner! |
79 | * enemy set to owner! |
78 | */ |
80 | */ |
79 | pet->enemy = 0; |
81 | pet->enemy = 0; |
80 | else |
82 | else |
81 | return tmp; |
83 | return tmp; |
82 | } |
84 | } |
… | |
… | |
101 | pet->enemy = 0; |
103 | pet->enemy = 0; |
102 | return 0; |
104 | return 0; |
103 | } |
105 | } |
104 | } |
106 | } |
105 | |
107 | |
106 | /* Since the pet has no existing enemy, look for anything nasty |
108 | /* Since the pet has no existing enemy, look for anything nasty |
107 | * around the owner that it should go and attack. (if the owner is |
109 | * around the owner that it should go and attack. (if the owner is |
108 | * still on a map) |
110 | * still on a map) |
109 | */ |
111 | */ |
110 | // owners sometimes are not on a map but in the inventory of somehting else |
112 | // owners sometimes are not on a map but in the inventory of somehting else |
111 | if (!owner->flag [FLAG_REMOVED] && owner->map) |
113 | if (!owner->flag [FLAG_REMOVED] && owner->map) |
112 | { |
114 | { |
113 | tmp3 = 0; |
115 | tmp3 = 0; |
114 | |
116 | |
115 | for (i = 0; i < SIZEOFFREE; i++) |
117 | for (i = 0; i < SIZEOFFREE; i++) |
116 | { |
118 | { |
117 | x = owner->x + freearr_x[search_arr[i]]; |
119 | x = owner->x + DIRX (search_arr[i]); |
118 | y = owner->y + freearr_y[search_arr[i]]; |
120 | y = owner->y + DIRY (search_arr[i]); |
119 | nm = owner->map; |
121 | nm = owner->map; |
120 | /* Only look on the space if there is something alive there. */ |
122 | /* Only look on the space if there is something alive there. */ |
121 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
123 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
122 | |
124 | |
123 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
125 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
124 | { |
126 | { |
125 | for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) |
127 | for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) |
126 | { |
128 | { |
127 | object *tmp2 = tmp->head == 0 ? tmp : tmp->head; |
129 | object *tmp2 = tmp->head == 0 ? tmp : tmp->head; |
128 | |
130 | |
129 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
131 | if (tmp2->flag [FLAG_ALIVE] && ((!tmp2->flag [FLAG_FRIENDLY] && |
130 | (tmp2->type != PLAYER)) || |
132 | (tmp2->type != PLAYER)) || |
131 | should_arena_attack (pet, owner, tmp2)) |
133 | should_arena_attack (pet, owner, tmp2)) |
132 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
134 | && !tmp2->flag [FLAG_UNAGGRESSIVE] && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
133 | { |
135 | { |
134 | |
136 | |
135 | if (!can_see_enemy (pet, tmp2)) |
137 | if (!can_see_enemy (pet, tmp2)) |
136 | { |
138 | { |
137 | if (tmp3 != 0) |
139 | if (tmp3 != 0) |
… | |
… | |
165 | /* No threat to owner, check to see if the pet has an attacker */ |
167 | /* No threat to owner, check to see if the pet has an attacker */ |
166 | if (attacker) |
168 | if (attacker) |
167 | { |
169 | { |
168 | /* also need to check to make sure it is not freindly */ |
170 | /* also need to check to make sure it is not freindly */ |
169 | /* or otherwise non-hostile, and is an appropriate target */ |
171 | /* or otherwise non-hostile, and is an appropriate target */ |
170 | if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker)) |
172 | if (!attacker->flag [FLAG_FRIENDLY] && on_same_map (pet, attacker)) |
171 | { |
173 | { |
172 | pet->enemy = attacker; |
174 | pet->enemy = attacker; |
173 | |
175 | |
174 | if (check_enemy (pet, rv) != 0) |
176 | if (check_enemy (pet, rv) != 0) |
175 | return attacker; |
177 | return attacker; |
… | |
… | |
186 | if (owner->type == PLAYER && owner->contr->petmode != pet_defend) |
188 | if (owner->type == PLAYER && owner->contr->petmode != pet_defend) |
187 | { |
189 | { |
188 | tmp3 = 0; |
190 | tmp3 = 0; |
189 | for (i = 0; i < SIZEOFFREE; i++) |
191 | for (i = 0; i < SIZEOFFREE; i++) |
190 | { |
192 | { |
191 | x = pet->x + freearr_x[search_arr[i]]; |
193 | x = pet->x + DIRX (search_arr[i]); |
192 | y = pet->y + freearr_y[search_arr[i]]; |
194 | y = pet->y + DIRY (search_arr[i]); |
193 | nm = pet->map; |
195 | nm = pet->map; |
194 | /* Only look on the space if there is something alive there. */ |
196 | /* Only look on the space if there is something alive there. */ |
195 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
197 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
196 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
198 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
197 | { |
199 | { |
198 | for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) |
200 | for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) |
199 | { |
201 | { |
200 | object *tmp2 = tmp->head == 0 ? tmp : tmp->head; |
202 | object *tmp2 = tmp->head == 0 ? tmp : tmp->head; |
201 | |
203 | |
202 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
204 | if (tmp2->flag [FLAG_ALIVE] && ((!tmp2->flag [FLAG_FRIENDLY] && |
203 | (tmp2->type != PLAYER)) || |
205 | (tmp2->type != PLAYER)) || |
204 | should_arena_attack (pet, owner, tmp2)) |
206 | should_arena_attack (pet, owner, tmp2)) |
205 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
207 | && !tmp2->flag [FLAG_UNAGGRESSIVE] && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
206 | { |
208 | { |
207 | |
209 | |
208 | if (!can_see_enemy (pet, tmp2)) |
210 | if (!can_see_enemy (pet, tmp2)) |
209 | { |
211 | { |
210 | if (tmp3 != 0) |
212 | if (tmp3 != 0) |
… | |
… | |
261 | } |
263 | } |
262 | |
264 | |
263 | /* |
265 | /* |
264 | * Unfortunately, sometimes, the owner of a pet is in the |
266 | * Unfortunately, sometimes, the owner of a pet is in the |
265 | * process of entering a new map when this is called. |
267 | * process of entering a new map when this is called. |
266 | * Thus the map isn't loaded yet, and we have to remove |
|
|
267 | * the pet... |
|
|
268 | * Interesting enough, we don't use the passed map structure in |
268 | * Interesting enough, we don't use the passed map structure in |
269 | * this function. |
269 | * this function. |
270 | */ |
270 | */ |
271 | void |
271 | void |
272 | remove_all_pets (maptile *map) |
272 | move_all_pets () |
273 | { |
273 | { |
274 | objectlink *obl, *next; |
274 | objectlink *obl, *next; |
275 | object *owner; |
275 | object *owner; |
276 | |
276 | |
277 | for (obl = first_friendly_object; obl; obl = next) |
277 | for (obl = first_friendly_object; obl; obl = next) |
278 | { |
278 | { |
279 | next = obl->next; |
279 | next = obl->next; |
280 | |
280 | |
281 | if (obl->ob->type != PLAYER |
281 | if (obl->ob->type != PLAYER |
282 | && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) |
282 | && obl->ob->flag [FLAG_FRIENDLY] |
283 | && (owner = obl->ob->owner) != 0 |
283 | && (owner = obl->ob->owner) |
284 | && !on_same_map (owner, obl->ob)) |
284 | && !on_same_map (owner, obl->ob)) |
285 | { |
285 | { |
286 | /* follow owner checks map status for us */ |
286 | /* follow owner checks map status for us */ |
287 | follow_owner (obl->ob, owner); |
287 | follow_owner (obl->ob, owner); |
288 | } |
288 | } |
… | |
… | |
292 | int |
292 | int |
293 | follow_owner (object *ob, object *owner) |
293 | follow_owner (object *ob, object *owner) |
294 | { |
294 | { |
295 | if (owner->flag [FLAG_REMOVED]) |
295 | if (owner->flag [FLAG_REMOVED]) |
296 | return 0; // do nothing if the owner is removed |
296 | return 0; // do nothing if the owner is removed |
297 | else if (!owner->map || owner->map->in_memory != MAP_ACTIVE) |
297 | else if (!owner->map || owner->map->state != MAP_ACTIVE) |
298 | LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name); |
298 | LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name); |
299 | else |
299 | else |
300 | { |
300 | { |
301 | int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); |
301 | int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); |
302 | |
302 | |
303 | if (dir >= 0) |
303 | if (dir >= 0) |
304 | { |
304 | { |
305 | owner->map->insert (ob, owner->x + freearr_x[dir], owner->y + freearr_y[dir]); |
305 | owner->map->insert (ob, owner->x + DIRX (dir), owner->y + DIRY (dir)); |
306 | |
306 | |
307 | if (owner->type == PLAYER) /* Uh, I hope this is always true... */ |
307 | if (owner->type == PLAYER) /* Uh, I hope this is always true... */ |
308 | new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); |
308 | new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); |
309 | |
309 | |
310 | return 0; |
310 | return 0; |
… | |
… | |
326 | |
326 | |
327 | /* Check to see if player pulled out */ |
327 | /* Check to see if player pulled out */ |
328 | if ((owner = ob->owner) == NULL) |
328 | if ((owner = ob->owner) == NULL) |
329 | { |
329 | { |
330 | ob->drop_and_destroy (); |
330 | ob->drop_and_destroy (); |
331 | LOG (llevMonster, "Pet: no owner, leaving.\n"); |
331 | LOG (llevTrace, "Pet: no owner, leaving.\n"); |
332 | return; |
332 | return; |
333 | } |
333 | } |
334 | |
334 | |
335 | /* move monster into the owners map if not in the same map |
335 | /* move monster into the owners map if not in the same map |
336 | * except when the owner is removed. |
336 | * except when the owner is removed. |
… | |
… | |
338 | if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED]) |
338 | if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED]) |
339 | { |
339 | { |
340 | follow_owner (ob, owner); |
340 | follow_owner (ob, owner); |
341 | return; |
341 | return; |
342 | } |
342 | } |
|
|
343 | |
343 | /* Calculate Direction */ |
344 | /* Calculate Direction */ |
344 | if (owner->type == PLAYER && owner->contr->petmode == pet_sad) |
345 | if (owner->type == PLAYER && owner->contr->petmode == pet_sad) |
345 | { |
346 | { |
346 | /* in S&D mode, if we have no enemy, run randomly about. */ |
347 | /* in S&D mode, if we have no enemy, run randomly about. */ |
347 | for (i = 0; i < 15; i++) |
348 | for (i = 0; i < 15; i++) |
348 | { |
349 | { |
349 | dir = rndm (1, 8); |
350 | dir = rndm (1, 8); |
350 | dx = ob->x + freearr_x[dir]; |
351 | dx = ob->x + DIRX (dir); |
351 | dy = ob->y + freearr_y[dir]; |
352 | dy = ob->y + DIRY (dir); |
352 | m = ob->map; |
353 | m = ob->map; |
353 | if (get_map_flags (ob->map, &m, dx, dy, &dx, &dy) & P_OUT_OF_MAP) |
354 | if (get_map_flags (ob->map, &m, dx, dy, &dx, &dy) & P_OUT_OF_MAP) |
354 | continue; |
355 | continue; |
355 | else if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m, dx, dy))) |
356 | else if (OB_TYPE_MOVE_BLOCK (ob, GET_MAP_MOVE_BLOCK (m, dx, dy))) |
356 | continue; |
357 | continue; |
… | |
… | |
363 | struct rv_vector rv; |
364 | struct rv_vector rv; |
364 | |
365 | |
365 | get_rangevector (ob, ob->owner, &rv, 0); |
366 | get_rangevector (ob, ob->owner, &rv, 0); |
366 | dir = rv.direction; |
367 | dir = rv.direction; |
367 | } |
368 | } |
|
|
369 | |
368 | ob->direction = dir; |
370 | ob->direction = dir; |
369 | |
371 | |
370 | /* move_ob returns 0 if the object couldn't move. If that is the |
372 | /* move_ob returns 0 if the object couldn't move. If that is the |
371 | * case, lets do some other work. |
373 | * case, lets do some other work. |
372 | */ |
374 | */ |
373 | if (!(move_ob (ob, dir, ob))) |
375 | if (!(ob->move (dir))) |
374 | { |
376 | { |
375 | object *part; |
377 | object *part; |
376 | |
378 | |
377 | /* the failed move_ob above may destroy the pet, so check here */ |
379 | /* the failed move_ob above may destroy the pet, so check here */ |
378 | if (ob->destroyed ()) |
380 | if (ob->destroyed ()) |
379 | return; |
381 | return; |
380 | |
382 | |
381 | for (part = ob; part != NULL; part = part->more) |
383 | for (part = ob; part != NULL; part = part->more) |
382 | { |
384 | { |
383 | dx = part->x + freearr_x[dir]; |
385 | dx = part->x + DIRX (dir); |
384 | dy = part->y + freearr_y[dir]; |
386 | dy = part->y + DIRY (dir); |
385 | m = get_map_from_coord (part->map, &dx, &dy); |
387 | m = get_map_from_coord (part->map, &dx, &dy); |
386 | if (!m) |
388 | if (!m) |
387 | continue; |
389 | continue; |
388 | |
390 | |
389 | for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above) |
391 | for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above) |
390 | { |
392 | { |
391 | object *new_ob; |
393 | object *new_ob; |
392 | |
394 | |
393 | new_ob = ob2->head ? ob2->head : ob2; |
395 | new_ob = ob2->head ? ob2->head : ob2; |
|
|
396 | |
394 | if (new_ob == ob) |
397 | if (new_ob == ob) |
395 | break; |
398 | break; |
|
|
399 | |
396 | if (new_ob == ob->owner) |
400 | if (new_ob == ob->owner) |
397 | return; |
401 | return; |
|
|
402 | |
398 | if (new_ob->owner == ob->owner) |
403 | if (new_ob->owner == ob->owner) |
399 | break; |
404 | break; |
400 | |
405 | |
401 | /* Hmm. Did we try to move into an enemy monster? If so, |
406 | /* Hmm. Did we try to move into an enemy monster? If so, |
402 | * make it our enemy. |
407 | * make it our enemy. |
403 | */ |
408 | */ |
404 | if (QUERY_FLAG (new_ob, FLAG_ALIVE) && !QUERY_FLAG (ob, FLAG_UNAGGRESSIVE) |
409 | if (new_ob->flag [FLAG_ALIVE] && !ob->flag [FLAG_UNAGGRESSIVE] |
405 | && !QUERY_FLAG (new_ob, FLAG_UNAGGRESSIVE) && !QUERY_FLAG (new_ob, FLAG_FRIENDLY)) |
410 | && !new_ob->flag [FLAG_UNAGGRESSIVE] && !new_ob->flag [FLAG_FRIENDLY]) |
406 | { |
411 | { |
407 | |
412 | |
408 | ob->enemy = new_ob; |
413 | ob->enemy = new_ob; |
409 | if (new_ob->enemy == NULL) |
414 | if (new_ob->enemy == NULL) |
410 | new_ob->enemy = ob; |
415 | new_ob->enemy = ob; |
… | |
… | |
417 | } |
422 | } |
418 | } |
423 | } |
419 | } |
424 | } |
420 | /* Try a different course */ |
425 | /* Try a different course */ |
421 | dir = absdir (dir + 4 - (rndm (5)) - (rndm (5))); |
426 | dir = absdir (dir + 4 - (rndm (5)) - (rndm (5))); |
422 | (void) move_ob (ob, dir, ob); |
427 | ob->move (dir); |
423 | } |
428 | } |
424 | return; |
|
|
425 | } |
429 | } |
426 | |
430 | |
427 | /**************************************************************************** |
431 | /**************************************************************************** |
428 | * |
432 | * |
429 | * GOLEM SPELL CODE |
433 | * GOLEM SPELL CODE |
430 | * |
434 | * |
431 | ****************************************************************************/ |
435 | ****************************************************************************/ |
432 | |
436 | |
433 | /* fix_summon_pet() - this makes multisquare/single square monsters |
437 | /* fix_summon_pet() - this makes multisquare/single square monsters |
434 | * proper for map insertion. |
438 | * proper for map insertion. |
435 | * at is the archetype, op is the caster of the spell, dir is the |
439 | * at is the archetype, op is the caster of the spell, dir is the |
436 | * direction the monster should be placed in. |
440 | * direction the monster should be placed in. |
437 | * is_golem is to note that this is a golem spell. |
441 | * is_golem is to note that this is a golem spell. |
438 | */ |
442 | */ |
439 | object * |
443 | static object * |
440 | fix_summon_pet (archetype *at, object *op, int dir, int is_golem) |
444 | fix_summon_pet (archetype *at, object *op, int dir, int is_golem) |
441 | { |
445 | { |
442 | object *tmp = NULL, *prev = NULL, *head = NULL; |
446 | object *tmp = NULL, *prev = NULL, *head = NULL; |
443 | |
447 | |
444 | for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
448 | for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
445 | { |
449 | { |
446 | tmp = arch_to_object (atmp); |
450 | tmp = atmp->instance (); |
447 | |
451 | |
448 | if (atmp == at) |
452 | if (atmp == at) |
449 | { |
453 | { |
450 | if (!is_golem) |
454 | if (!is_golem) |
451 | SET_FLAG (tmp, FLAG_MONSTER); |
455 | tmp->set_flag (FLAG_MONSTER); |
452 | |
456 | |
453 | tmp->set_owner (op); |
457 | tmp->set_owner (op); |
454 | |
458 | |
455 | if (op->type == PLAYER) |
459 | if (op->type == PLAYER) |
456 | { |
460 | { |
457 | tmp->stats.exp = 0; |
461 | tmp->stats.exp = 0; |
458 | add_friendly_object (tmp); |
462 | add_friendly_object (tmp); |
459 | if (is_golem) |
463 | if (is_golem) |
460 | CLEAR_FLAG (tmp, FLAG_MONSTER); |
464 | tmp->clr_flag (FLAG_MONSTER); |
461 | } |
465 | } |
462 | else |
466 | else |
463 | { |
467 | { |
464 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
468 | if (op->flag [FLAG_FRIENDLY]) |
465 | { |
469 | { |
466 | object *owner = op->owner; |
470 | object *owner = op->owner; |
467 | |
471 | |
468 | if (owner) |
472 | if (owner) |
469 | { /* For now, we transfer ownership */ |
473 | { /* For now, we transfer ownership */ |
… | |
… | |
487 | } |
491 | } |
488 | |
492 | |
489 | if (!head) |
493 | if (!head) |
490 | head = tmp; |
494 | head = tmp; |
491 | |
495 | |
492 | tmp->x = op->x + freearr_x[dir] + tmp->arch->x; |
496 | tmp->x = op->x + DIRX (dir) + tmp->arch->x; |
493 | tmp->y = op->y + freearr_y[dir] + tmp->arch->y; |
497 | tmp->y = op->y + DIRY (dir) + tmp->arch->y; |
494 | tmp->map = op->map; |
498 | tmp->map = op->map; |
495 | |
499 | |
496 | if (tmp->invisible) |
500 | if (tmp->invisible) |
497 | tmp->invisible = 0; |
501 | tmp->invisible = 0; |
498 | |
502 | |
… | |
… | |
509 | head->last_eat = 0; |
513 | head->last_eat = 0; |
510 | head->last_grace = 0; |
514 | head->last_grace = 0; |
511 | head->last_sp = 0; |
515 | head->last_sp = 0; |
512 | head->other_arch = NULL; |
516 | head->other_arch = NULL; |
513 | head->stats.exp = 0; |
517 | head->stats.exp = 0; |
514 | CLEAR_FLAG (head, FLAG_CHANGING); |
518 | head->clr_flag (FLAG_CHANGING); |
515 | CLEAR_FLAG (head, FLAG_STAND_STILL); |
519 | head->clr_flag (FLAG_STAND_STILL); |
516 | CLEAR_FLAG (head, FLAG_GENERATOR); |
520 | head->clr_flag (FLAG_GENERATOR); |
517 | CLEAR_FLAG (head, FLAG_SPLITTING); |
521 | head->clr_flag (FLAG_SPLITTING); |
518 | if (head->attacktype & AT_GHOSTHIT) |
522 | if (head->attacktype & AT_GHOSTHIT) |
519 | head->attacktype = (AT_PHYSICAL | AT_DRAIN); |
523 | head->attacktype = (AT_PHYSICAL | AT_DRAIN); |
520 | |
524 | |
521 | return head; |
525 | return head; |
522 | } |
526 | } |
… | |
… | |
527 | move_golem (object *op) |
531 | move_golem (object *op) |
528 | { |
532 | { |
529 | int made_attack = 0; |
533 | int made_attack = 0; |
530 | object *tmp; |
534 | object *tmp; |
531 | |
535 | |
532 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
536 | if (op->flag [FLAG_MONSTER]) |
533 | return; /* Has already been moved */ |
537 | return; /* Has already been moved */ |
534 | |
538 | |
535 | if (!op->owner) |
539 | if (!op->owner) |
536 | { |
540 | { |
537 | LOG (llevDebug, "Golem without owner destructed.\n"); |
541 | LOG (llevDebug, "Golem without owner destructed.\n"); |
… | |
… | |
551 | |
555 | |
552 | op->drop_and_destroy (); |
556 | op->drop_and_destroy (); |
553 | return; |
557 | return; |
554 | } |
558 | } |
555 | |
559 | |
556 | /* Do golem attacks/movement for single & multisq golems. |
560 | /* Do golem attacks/movement for single & multisq golems. |
557 | * Assuming here that op is the 'head' object. Pass only op to |
561 | * Assuming here that op is the 'head' object. Pass only op to |
558 | * move_ob (makes recursive calls to other parts) |
562 | * ->move (makes recursive calls to other parts) |
559 | * move_ob returns 0 if the creature was not able to move. |
563 | * move_ob returns 0 if the creature was not able to move. |
560 | */ |
564 | */ |
561 | if (move_ob (op, op->direction, op)) |
565 | if (op->move (op->direction, op)) |
562 | return; |
566 | return; |
563 | |
567 | |
564 | if (op->destroyed ()) |
568 | if (op->destroyed ()) |
565 | return; |
569 | return; |
566 | |
570 | |
567 | for (tmp = op; tmp; tmp = tmp->more) |
571 | for (tmp = op; tmp; tmp = tmp->more) |
568 | { |
572 | { |
569 | sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; |
573 | sint16 x = tmp->x + DIRX (op->direction), y = tmp->y + DIRY (op->direction); |
570 | object *victim; |
574 | object *victim; |
571 | maptile *m; |
575 | maptile *m; |
572 | int mflags; |
576 | int mflags; |
573 | |
577 | |
574 | m = op->map; |
578 | m = op->map; |
… | |
… | |
576 | |
580 | |
577 | if (mflags & P_OUT_OF_MAP) |
581 | if (mflags & P_OUT_OF_MAP) |
578 | continue; |
582 | continue; |
579 | |
583 | |
580 | for (victim = GET_MAP_OB (m, x, y); victim; victim = victim->above) |
584 | for (victim = GET_MAP_OB (m, x, y); victim; victim = victim->above) |
581 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
585 | if (victim->flag [FLAG_ALIVE]) |
582 | break; |
586 | break; |
583 | |
587 | |
584 | /* We used to call will_hit_self to make sure we don't |
588 | /* We used to call will_hit_self to make sure we don't |
585 | * hit ourselves, but that didn't work, and I don't really |
589 | * hit ourselves, but that didn't work, and I don't really |
586 | * know if that was more efficient anyways than this. |
590 | * know if that was more efficient anyways than this. |
… | |
… | |
589 | * that isn't a problem. |
593 | * that isn't a problem. |
590 | */ |
594 | */ |
591 | if (victim && victim != op && victim->head != op) |
595 | if (victim && victim != op && victim->head != op) |
592 | { |
596 | { |
593 | /* for golems with race fields, we don't attack |
597 | /* for golems with race fields, we don't attack |
594 | * aligned races |
598 | * aligned races |
595 | */ |
599 | */ |
596 | |
600 | |
597 | if (victim->race && op->race && strstr (op->race, victim->race)) |
601 | if (victim->race && op->race && op->race.contains (victim->race)) |
598 | { |
602 | { |
599 | if (op->owner) |
603 | if (op->owner) |
600 | new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name); |
604 | new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name); |
601 | } |
605 | } |
602 | else if (victim == op->owner) |
606 | else if (victim == op->owner) |
… | |
… | |
636 | int |
640 | int |
637 | summon_golem (object *op, object *caster, int dir, object *spob) |
641 | summon_golem (object *op, object *caster, int dir, object *spob) |
638 | { |
642 | { |
639 | object *tmp, *god = NULL; |
643 | object *tmp, *god = NULL; |
640 | archetype *at; |
644 | archetype *at; |
641 | char buf[MAX_BUF]; |
|
|
642 | |
645 | |
643 | /* Because there can be different golem spells, player may want to |
646 | /* Because there can be different golem spells, player may want to |
644 | * 'lose' their old golem. |
647 | * 'lose' their old golem. |
645 | */ |
648 | */ |
646 | if (op->type == PLAYER && op->contr->golem) |
649 | if (op->type == PLAYER && op->contr->golem) |
… | |
… | |
677 | } |
680 | } |
678 | |
681 | |
679 | if (!dir) |
682 | if (!dir) |
680 | dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
683 | dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
681 | |
684 | |
682 | if (dir < 0 || at->blocked (op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
685 | if (dir < 0 || at->blocked (op->map, op->x + DIRX (dir), op->y + DIRY (dir))) |
683 | { |
686 | { |
684 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
687 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
685 | return 0; |
688 | return 0; |
686 | } |
689 | } |
687 | |
690 | |
… | |
… | |
699 | op->contr->golem = tmp; |
702 | op->contr->golem = tmp; |
700 | /* give the player control of the golem */ |
703 | /* give the player control of the golem */ |
701 | set_spell_skill (op, caster, spob, tmp); |
704 | set_spell_skill (op, caster, spob, tmp); |
702 | } |
705 | } |
703 | |
706 | |
704 | /* make the speed positive. */ |
|
|
705 | tmp->speed = fabs (tmp->speed); |
|
|
706 | |
|
|
707 | /* This sets the level dependencies on dam and hp for monsters */ |
707 | /* This sets the level dependencies on dam and hp for monsters */ |
708 | /* players can't cope with too strong summonings. */ |
708 | /* players can't cope with too strong summonings. */ |
709 | /* but monsters can. reserve these for players. */ |
709 | /* but monsters can. reserve these for players. */ |
710 | if (op->type == PLAYER) |
710 | if (op->type == PLAYER) |
711 | { |
711 | { |
712 | tmp->stats.hp += spob->duration + SP_level_duration_adjust (caster, spob); |
712 | tmp->stats.hp += spob->duration + SP_level_duration_adjust (caster, spob); |
… | |
… | |
714 | if (!spob->stats.dam) |
714 | if (!spob->stats.dam) |
715 | tmp->stats.dam += SP_level_dam_adjust (caster, spob); |
715 | tmp->stats.dam += SP_level_dam_adjust (caster, spob); |
716 | else |
716 | else |
717 | tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob); |
717 | tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob); |
718 | |
718 | |
719 | tmp->speed += .02 * SP_level_range_adjust (caster, spob); |
719 | tmp->set_speed (min (1.f, tmp->speed + .02f * SP_level_range_adjust (caster, spob))); |
720 | tmp->speed = min (tmp->speed, 1.0); |
|
|
721 | |
720 | |
722 | if (spob->attacktype) |
721 | if (spob->attacktype) |
723 | tmp->attacktype = spob->attacktype; |
722 | tmp->attacktype = spob->attacktype; |
724 | } |
723 | } |
725 | |
724 | |
… | |
… | |
736 | tmp->direction = dir; |
735 | tmp->direction = dir; |
737 | |
736 | |
738 | /* Holy spell - some additional tailoring */ |
737 | /* Holy spell - some additional tailoring */ |
739 | if (god) |
738 | if (god) |
740 | { |
739 | { |
741 | object *tmp2; |
|
|
742 | |
|
|
743 | sprintf (buf, "%s of %s", &spob->name, &god->name); |
740 | char *buf = format ("%s of %s", &spob->name, &god->name); |
744 | buf[0] = toupper (buf[0]); |
741 | buf[0] = toupper (buf[0]); |
745 | |
742 | |
746 | for (tmp2 = tmp; tmp2; tmp2 = tmp2->more) |
743 | for (object *tmp2 = tmp; tmp2; tmp2 = tmp2->more) |
747 | tmp2->name = buf; |
744 | tmp2->name = buf; |
748 | |
745 | |
749 | tmp->attacktype |= god->attacktype; |
746 | tmp->attacktype |= god->attacktype; |
750 | memcpy (tmp->resist, god->resist, sizeof (tmp->resist)); |
747 | memcpy (tmp->resist, god->resist, sizeof (tmp->resist)); |
751 | tmp->race = god->race; |
748 | tmp->race = god->race; |
… | |
… | |
771 | /* Returns a monster (chosen at random) that this particular player (and his |
768 | /* Returns a monster (chosen at random) that this particular player (and his |
772 | * god) find acceptable. This checks level, races allowed by god, etc |
769 | * god) find acceptable. This checks level, races allowed by god, etc |
773 | * to determine what is acceptable. |
770 | * to determine what is acceptable. |
774 | * This returns NULL if no match was found. |
771 | * This returns NULL if no match was found. |
775 | */ |
772 | */ |
776 | object * |
773 | static object * |
777 | choose_cult_monster (object *pl, object *god, int summon_level) |
774 | choose_cult_monster (object *pl, object *god, int summon_level) |
778 | { |
775 | { |
779 | char buf[MAX_BUF]; |
776 | char buf[MAX_BUF]; |
780 | const char *race; |
777 | const char *race; |
781 | int racenr, mon_nr, i; |
778 | int racenr, mon_nr, i; |
… | |
… | |
821 | /* search for an apprplritate monster on this race list */ |
818 | /* search for an apprplritate monster on this race list */ |
822 | mon_nr = 0; |
819 | mon_nr = 0; |
823 | for (tobl = list->member; tobl; tobl = tobl->next) |
820 | for (tobl = list->member; tobl; tobl = tobl->next) |
824 | { |
821 | { |
825 | otmp = tobl->ob; |
822 | otmp = tobl->ob; |
826 | if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) |
823 | if (!otmp || !otmp->flag [FLAG_MONSTER]) |
827 | continue; |
824 | continue; |
828 | if (otmp->level <= summon_level) |
825 | if (otmp->level <= summon_level) |
829 | mon_nr++; |
826 | mon_nr++; |
830 | } |
827 | } |
831 | |
828 | |
… | |
… | |
839 | |
836 | |
840 | mon_nr = rndm (mon_nr - 1); |
837 | mon_nr = rndm (mon_nr - 1); |
841 | for (tobl = list->member; tobl; tobl = tobl->next) |
838 | for (tobl = list->member; tobl; tobl = tobl->next) |
842 | { |
839 | { |
843 | otmp = tobl->ob; |
840 | otmp = tobl->ob; |
844 | if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) |
841 | if (!otmp || !otmp->flag [FLAG_MONSTER]) |
845 | continue; |
842 | continue; |
846 | |
843 | |
847 | if (otmp->level <= summon_level && !mon_nr--) |
844 | if (otmp->level <= summon_level && !mon_nr--) |
848 | return otmp; |
845 | return otmp; |
849 | } |
846 | } |
… | |
… | |
854 | } |
851 | } |
855 | |
852 | |
856 | int |
853 | int |
857 | summon_object (object *op, object *caster, object *spell_ob, int dir, const char *stringarg) |
854 | summon_object (object *op, object *caster, object *spell_ob, int dir, const char *stringarg) |
858 | { |
855 | { |
859 | sint16 x, y, nrof = 1, i; |
856 | int nrof = 1; |
860 | archetype *summon_arch; |
857 | archetype *summon_arch; |
861 | int ndir; |
858 | int ndir; |
862 | |
859 | |
863 | if (spell_ob->other_arch) |
860 | if (spell_ob->other_arch) |
864 | summon_arch = spell_ob->other_arch; |
861 | summon_arch = spell_ob->other_arch; |
… | |
… | |
867 | int level = casting_level (caster, spell_ob); |
864 | int level = casting_level (caster, spell_ob); |
868 | treasure *tr, *lasttr = NULL; |
865 | treasure *tr, *lasttr = NULL; |
869 | |
866 | |
870 | shstr_cmp sparam (stringarg); |
867 | shstr_cmp sparam (stringarg); |
871 | |
868 | |
872 | /* In old code, this was a very convoluted for statement, |
869 | /* In old code, this was a very convoluted for statement, |
873 | * with all the checks in the 'for' portion itself. Much |
870 | * with all the checks in the 'for' portion itself. Much |
874 | * more readable to break some of the conditions out. |
871 | * more readable to break some of the conditions out. |
875 | */ |
872 | */ |
876 | for (tr = spell_ob->randomitems->items; tr; tr = tr->next) |
873 | for (tr = spell_ob->randomitems->items; tr; tr = tr->next) |
877 | { |
874 | { |
… | |
… | |
895 | } |
892 | } |
896 | |
893 | |
897 | summon_arch = lasttr->item; |
894 | summon_arch = lasttr->item; |
898 | nrof = lasttr->nrof; |
895 | nrof = lasttr->nrof; |
899 | } |
896 | } |
900 | else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) |
897 | else if (spell_ob->race == shstr_GODCULTMON) |
901 | { |
898 | { |
902 | object *god = find_god (determine_god (op)), *mon, *owner; |
899 | object *god = find_god (determine_god (op)), *mon, *owner; |
903 | int summon_level, tries; |
900 | int summon_level, tries; |
904 | |
901 | |
905 | if (!god && ((owner = op->owner) != NULL)) |
902 | if (!god && ((owner = op->owner) != NULL)) |
… | |
… | |
933 | ndir = dir; |
930 | ndir = dir; |
934 | |
931 | |
935 | if (!ndir) |
932 | if (!ndir) |
936 | ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); |
933 | ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); |
937 | |
934 | |
938 | if (ndir < 0 || mon->blocked (op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) |
935 | if (ndir < 0 || mon->blocked (op->map, op->x + DIRX (ndir), op->y + DIRY (ndir))) |
939 | { |
936 | { |
940 | ndir = -1; |
937 | ndir = -1; |
941 | if (++tries == 5) |
938 | if (++tries == 5) |
942 | { |
939 | { |
943 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
940 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
… | |
… | |
964 | { |
961 | { |
965 | new_draw_info (NDI_UNIQUE, 0, op, "There is no monsters available for summoning."); |
962 | new_draw_info (NDI_UNIQUE, 0, op, "There is no monsters available for summoning."); |
966 | return 0; |
963 | return 0; |
967 | } |
964 | } |
968 | |
965 | |
969 | for (i = 1; i <= nrof; i++) |
966 | for (int i = 1; i <= nrof; i++) |
970 | { |
967 | { |
971 | object *prev = NULL, *head = NULL, *tmp; |
968 | object *prev = NULL, *head = NULL, *tmp; |
972 | |
969 | |
973 | if (dir) |
970 | if (dir) |
974 | { |
971 | { |
… | |
… | |
976 | dir = absdir (dir + 1); |
973 | dir = absdir (dir + 1); |
977 | } |
974 | } |
978 | else |
975 | else |
979 | ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE); |
976 | ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE); |
980 | |
977 | |
981 | if (ndir > 0) |
978 | sint16 x = DIRX (ndir); |
982 | { |
979 | sint16 y = DIRY (ndir); |
983 | x = freearr_x[ndir]; |
|
|
984 | y = freearr_y[ndir]; |
|
|
985 | } |
|
|
986 | |
980 | |
987 | if (ndir < 0 || summon_arch->blocked (op->map, op->x + x, op->y + y)) |
981 | if (ndir < 0 || summon_arch->blocked (op->map, op->x + x, op->y + y)) |
988 | { |
982 | { |
989 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
983 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
990 | if (nrof > 1) |
984 | if (nrof > 1) |
991 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
985 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
992 | |
986 | |
993 | return nrof > 1; |
987 | return nrof > 1; |
994 | } |
988 | } |
995 | |
989 | |
996 | for (archetype *atmp = summon_arch; atmp != NULL; atmp = (archetype *)atmp->more) |
990 | for (archetype *atmp = summon_arch; atmp; atmp = (archetype *)atmp->more) |
997 | { |
991 | { |
998 | tmp = arch_to_object (atmp); |
992 | tmp = atmp->instance (); |
999 | if (atmp == summon_arch) |
993 | if (atmp == summon_arch) |
1000 | { |
994 | { |
1001 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
995 | if (tmp->flag [FLAG_MONSTER]) |
1002 | { |
996 | { |
1003 | tmp->set_owner (op); |
997 | tmp->set_owner (op); |
1004 | set_spell_skill (op, caster, spell_ob, tmp); |
998 | set_spell_skill (op, caster, spell_ob, tmp); |
1005 | tmp->enemy = op->enemy; |
999 | tmp->enemy = op->enemy; |
1006 | tmp->type = 0; |
1000 | tmp->type = 0; |
1007 | CLEAR_FLAG (tmp, FLAG_SLEEP); |
1001 | tmp->clr_flag (FLAG_SLEEP); |
1008 | |
1002 | |
1009 | if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) |
1003 | if (op->type == PLAYER || op->flag [FLAG_FRIENDLY]) |
1010 | { |
1004 | { |
1011 | /* If this is not set, we make it friendly */ |
1005 | /* If this is not set, we make it friendly */ |
1012 | if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) |
1006 | if (!spell_ob->flag [FLAG_MONSTER]) |
1013 | { |
1007 | { |
1014 | add_friendly_object (tmp); |
1008 | add_friendly_object (tmp); |
1015 | tmp->stats.exp = 0; |
1009 | tmp->stats.exp = 0; |
1016 | |
1010 | |
1017 | if (spell_ob->attack_movement) |
1011 | if (spell_ob->attack_movement) |
… | |
… | |
1021 | tmp->set_owner (op->owner); |
1015 | tmp->set_owner (op->owner); |
1022 | } |
1016 | } |
1023 | } |
1017 | } |
1024 | } |
1018 | } |
1025 | |
1019 | |
1026 | if (tmp->speed > MIN_ACTIVE_SPEED) |
1020 | if (tmp->has_active_speed ()) |
1027 | tmp->speed_left = -1; |
1021 | tmp->speed_left = -1; |
1028 | } |
1022 | } |
1029 | |
1023 | |
1030 | if (head == NULL) |
1024 | if (head == NULL) |
1031 | head = tmp; |
1025 | head = tmp; |
… | |
… | |
1048 | if (head && head->randomitems) |
1042 | if (head && head->randomitems) |
1049 | { |
1043 | { |
1050 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
1044 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
1051 | |
1045 | |
1052 | for (object *tmp = head->inv; tmp; tmp = tmp->below) |
1046 | for (object *tmp = head->inv; tmp; tmp = tmp->below) |
1053 | SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH); |
1047 | tmp->set_flag (FLAG_DESTROY_ON_DEATH); |
1054 | } |
1048 | } |
1055 | } /* for i < nrof */ |
1049 | } /* for i < nrof */ |
1056 | |
1050 | |
1057 | return 1; |
1051 | return 1; |
1058 | } |
1052 | } |