1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * CrossFire, A Multiplayer game for X-windows |
3 | |
3 | * |
|
|
4 | * Copyright (C) 2005, 2006, 2007 Marc Lehmann & Crossfire+ Development Team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (C) 1992 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * This program is free software; you can redistribute it and/or modify |
8 | it under the terms of the GNU General Public License as published by |
9 | * it under the terms of the GNU General Public License as published by |
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 | #include <global.h> |
25 | #include <global.h> |
25 | #include <sproto.h> |
26 | #include <sproto.h> |
26 | |
27 | |
27 | /* given that 'pet' is a friendly object, this function returns a |
28 | /* given that 'pet' is a friendly object, this function returns a |
… | |
… | |
266 | remove_all_pets (maptile *map) |
267 | remove_all_pets (maptile *map) |
267 | { |
268 | { |
268 | objectlink *obl, *next; |
269 | objectlink *obl, *next; |
269 | object *owner; |
270 | object *owner; |
270 | |
271 | |
271 | for (obl = first_friendly_object; obl != NULL; obl = next) |
272 | for (obl = first_friendly_object; obl; obl = next) |
272 | { |
273 | { |
273 | next = obl->next; |
274 | next = obl->next; |
274 | if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) && |
275 | |
275 | (owner = obl->ob->owner) != NULL && !on_same_map (owner, obl->ob)) |
276 | if (obl->ob->type != PLAYER |
|
|
277 | && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) |
|
|
278 | && (owner = obl->ob->owner) != 0 |
|
|
279 | && !on_same_map (owner, obl->ob)) |
276 | { |
280 | { |
277 | /* follow owner checks map status for us */ |
281 | /* follow owner checks map status for us */ |
278 | follow_owner (obl->ob, owner); |
282 | follow_owner (obl->ob, owner); |
279 | } |
283 | } |
280 | } |
284 | } |
281 | } |
285 | } |
282 | |
286 | |
283 | int |
287 | int |
284 | follow_owner (object *ob, object *owner) |
288 | follow_owner (object *ob, object *owner) |
285 | { |
289 | { |
286 | object *tmp; |
|
|
287 | int dir; |
|
|
288 | |
|
|
289 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
|
|
290 | ob->remove (); |
|
|
291 | |
|
|
292 | if (owner->map == NULL) |
290 | if (!owner->map) |
293 | { |
|
|
294 | LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name); |
291 | LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name); |
295 | goto fail; |
|
|
296 | } |
|
|
297 | if (owner->map->in_memory != MAP_IN_MEMORY) |
292 | else if (owner->map->in_memory != MAP_IN_MEMORY) |
298 | { |
|
|
299 | LOG (llevError, "Owner of the pet not on a map in memory!?\n"); |
293 | LOG (llevError, "Owner of the pet not on a map in memory!?\n"); |
300 | goto fail; |
294 | else |
301 | } |
295 | { |
302 | |
|
|
303 | dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); |
296 | int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); |
304 | |
297 | |
305 | if (dir == -1) |
298 | if (dir >= 0) |
306 | { |
|
|
307 | LOG (llevMonster, "No space for pet to follow, freeing %s.\n", &ob->name); |
|
|
308 | goto fail; |
|
|
309 | } |
|
|
310 | for (tmp = ob; tmp != NULL; tmp = tmp->more) |
|
|
311 | { |
|
|
312 | tmp->x = owner->x + freearr_x[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); |
|
|
313 | tmp->y = owner->y + freearr_y[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
|
|
314 | tmp->map = owner->map; |
|
|
315 | if (OUT_OF_REAL_MAP (tmp->map, tmp->x, tmp->y)) |
|
|
316 | { |
|
|
317 | tmp->map = get_map_from_coord (tmp->map, &tmp->x, &tmp->y); |
|
|
318 | } |
299 | { |
319 | } |
300 | owner->map->insert (ob, owner->x + freearr_x[dir], owner->y + freearr_y[dir]); |
320 | insert_ob_in_map (ob, ob->map, NULL, 0); |
301 | |
321 | if (owner->type == PLAYER) /* Uh, I hope this is always true... */ |
302 | if (owner->type == PLAYER) /* Uh, I hope this is always true... */ |
322 | new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); |
303 | new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); |
323 | |
304 | |
324 | return 0; |
305 | return 0; |
|
|
306 | } |
|
|
307 | } |
325 | |
308 | |
326 | fail: |
|
|
327 | remove_friendly_object (ob); |
|
|
328 | ob->destroy (); |
309 | ob->destroy (); |
329 | |
|
|
330 | return 1; |
310 | return 1; |
331 | } |
311 | } |
332 | |
312 | |
333 | void |
313 | void |
334 | pet_move (object *ob) |
314 | pet_move (object *ob) |
… | |
… | |
430 | return; |
410 | return; |
431 | } |
411 | } |
432 | } |
412 | } |
433 | } |
413 | } |
434 | /* Try a different course */ |
414 | /* Try a different course */ |
435 | dir = absdir (dir + 4 - (RANDOM () % 5) - (RANDOM () % 5)); |
415 | dir = absdir (dir + 4 - (rndm (5)) - (rndm (5))); |
436 | (void) move_ob (ob, dir, ob); |
416 | (void) move_ob (ob, dir, ob); |
437 | } |
417 | } |
438 | return; |
418 | return; |
439 | } |
419 | } |
440 | |
420 | |
… | |
… | |
468 | tmp->set_owner (op); |
448 | tmp->set_owner (op); |
469 | if (op->type == PLAYER) |
449 | if (op->type == PLAYER) |
470 | { |
450 | { |
471 | tmp->stats.exp = 0; |
451 | tmp->stats.exp = 0; |
472 | add_friendly_object (tmp); |
452 | add_friendly_object (tmp); |
473 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
474 | if (is_golem) |
453 | if (is_golem) |
475 | CLEAR_FLAG (tmp, FLAG_MONSTER); |
454 | CLEAR_FLAG (tmp, FLAG_MONSTER); |
476 | } |
455 | } |
477 | else |
456 | else |
478 | { |
457 | { |
… | |
… | |
483 | if (owner) |
462 | if (owner) |
484 | { /* For now, we transfer ownership */ |
463 | { /* For now, we transfer ownership */ |
485 | tmp->set_owner (owner); |
464 | tmp->set_owner (owner); |
486 | tmp->attack_movement = PETMOVE; |
465 | tmp->attack_movement = PETMOVE; |
487 | add_friendly_object (tmp); |
466 | add_friendly_object (tmp); |
488 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
489 | } |
467 | } |
490 | } |
468 | } |
491 | } |
469 | } |
492 | |
470 | |
493 | if (op->type != PLAYER || !is_golem) |
471 | if (op->type != PLAYER || !is_golem) |
… | |
… | |
698 | } |
676 | } |
699 | |
677 | |
700 | if (!dir) |
678 | if (!dir) |
701 | dir = find_free_spot (NULL, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
679 | dir = find_free_spot (NULL, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
702 | |
680 | |
703 | if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
681 | if (dir < 0 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
704 | { |
682 | { |
705 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
683 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
706 | return 0; |
684 | return 0; |
707 | } |
685 | } |
708 | |
686 | |
… | |
… | |
732 | if (owner) |
710 | if (owner) |
733 | { /* For now, we transfer ownership */ |
711 | { /* For now, we transfer ownership */ |
734 | tmp->set_owner (owner); |
712 | tmp->set_owner (owner); |
735 | tmp->attack_movement = PETMOVE; |
713 | tmp->attack_movement = PETMOVE; |
736 | add_friendly_object (tmp); |
714 | add_friendly_object (tmp); |
737 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
738 | } |
715 | } |
739 | } |
716 | } |
740 | |
717 | |
741 | SET_FLAG (tmp, FLAG_MONSTER); |
718 | SET_FLAG (tmp, FLAG_MONSTER); |
742 | } |
719 | } |
… | |
… | |
971 | ndir = dir; |
948 | ndir = dir; |
972 | |
949 | |
973 | if (!ndir) |
950 | if (!ndir) |
974 | ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); |
951 | ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); |
975 | |
952 | |
976 | if (ndir == -1 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) |
953 | if (ndir < 0 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) |
977 | { |
954 | { |
978 | ndir = -1; |
955 | ndir = -1; |
979 | if (++tries == 5) |
956 | if (++tries == 5) |
980 | { |
957 | { |
981 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
958 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
… | |
… | |
1021 | { |
998 | { |
1022 | x = freearr_x[ndir]; |
999 | x = freearr_x[ndir]; |
1023 | y = freearr_y[ndir]; |
1000 | y = freearr_y[ndir]; |
1024 | } |
1001 | } |
1025 | |
1002 | |
1026 | if (ndir == -1 || ob_blocked (&summon_arch->clone, op->map, op->x + x, op->y + y)) |
1003 | if (ndir < 0 || ob_blocked (&summon_arch->clone, op->map, op->x + x, op->y + y)) |
1027 | { |
1004 | { |
1028 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
1005 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
1029 | if (nrof > 1) |
1006 | if (nrof > 1) |
1030 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
1007 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
1031 | |
1008 | |
… | |
… | |
1048 | if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) |
1025 | if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) |
1049 | { |
1026 | { |
1050 | /* If this is not set, we make it friendly */ |
1027 | /* If this is not set, we make it friendly */ |
1051 | if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) |
1028 | if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) |
1052 | { |
1029 | { |
1053 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
1054 | add_friendly_object (tmp); |
1030 | add_friendly_object (tmp); |
1055 | tmp->stats.exp = 0; |
1031 | tmp->stats.exp = 0; |
1056 | |
1032 | |
1057 | if (spell_ob->attack_movement) |
1033 | if (spell_ob->attack_movement) |
1058 | tmp->attack_movement = spell_ob->attack_movement; |
1034 | tmp->attack_movement = spell_ob->attack_movement; |
… | |
… | |
1088 | if (head && head->randomitems) |
1064 | if (head && head->randomitems) |
1089 | { |
1065 | { |
1090 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
1066 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
1091 | |
1067 | |
1092 | for (object *tmp = head->inv; tmp; tmp = tmp->below) |
1068 | for (object *tmp = head->inv; tmp; tmp = tmp->below) |
1093 | SET_FLAG (tmp, FLAG_NO_DROP); |
1069 | SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH); |
1094 | } |
1070 | } |
1095 | } /* for i < nrof */ |
1071 | } /* for i < nrof */ |
1096 | |
1072 | |
1097 | return 1; |
1073 | return 1; |
1098 | } |
1074 | } |