1 | /* |
1 | /* |
2 | * This file is part of Crossfire TRT, the Roguelike Realtime MORPG. |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | * |
3 | * |
4 | * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT team |
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
7 | * |
7 | * |
8 | * Crossfire TRT is free software: you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify |
9 | * it under the terms of the GNU General Public License as published by |
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 |
10 | * the Free Software Foundation, either version 3 of the License, or |
11 | * (at your option) any later version. |
11 | * (at your option) any later version. |
12 | * |
12 | * |
13 | * 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, |
… | |
… | |
16 | * GNU General Public License for more details. |
16 | * GNU General Public License for more details. |
17 | * |
17 | * |
18 | * 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 |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
19 | * along with this program. If not, see <http://www.gnu.org/licenses/>. |
20 | * |
20 | * |
21 | * The authors can be reached via e-mail to <crossfire@schmorp.de> |
21 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
22 | */ |
23 | |
23 | |
24 | #include <global.h> |
24 | #include <global.h> |
25 | #include <sproto.h> |
25 | #include <sproto.h> |
26 | |
26 | |
… | |
… | |
31 | * this is now tilemap aware. |
31 | * this is now tilemap aware. |
32 | */ |
32 | */ |
33 | object * |
33 | object * |
34 | get_pet_enemy (object *pet, rv_vector * rv) |
34 | get_pet_enemy (object *pet, rv_vector * rv) |
35 | { |
35 | { |
36 | object *owner, *tmp, *attacker, *tmp3; |
36 | object *tmp, *attacker, *tmp3; |
37 | int i; |
37 | int i; |
38 | sint16 x, y; |
38 | sint16 x, y; |
39 | maptile *nm; |
39 | maptile *nm; |
40 | int search_arr[SIZEOFFREE]; |
40 | int search_arr[SIZEOFFREE]; |
41 | int mflags; |
41 | int mflags; |
42 | |
42 | |
43 | attacker = pet->attacked_by; /*pointer to attacking enemy */ |
43 | attacker = pet->attacked_by; /*pointer to attacking enemy */ |
44 | pet->attacked_by = NULL; /*clear this, since we are dealing with it */ |
44 | pet->attacked_by = NULL; /*clear this, since we are dealing with it */ |
45 | |
45 | |
46 | if (owner = pet->owner) |
46 | object *owner = pet->owner; |
47 | { |
47 | |
48 | /* If the owner has turned on the pet, make the pet |
48 | if (!owner) |
49 | * unfriendly. |
|
|
50 | */ |
|
|
51 | if (check_enemy (owner, rv) == pet) |
|
|
52 | { |
|
|
53 | remove_friendly_object (pet); |
|
|
54 | pet->attack_movement &= ~PETMOVE; |
|
|
55 | return owner; |
|
|
56 | } |
|
|
57 | } |
49 | { |
58 | else |
|
|
59 | { |
|
|
60 | /* else the owner is no longer around, so the |
50 | /* the owner is no longer around, so the |
61 | * pet no longer needs to be friendly. |
51 | * pet no longer needs to be friendly. |
62 | */ |
52 | */ |
63 | remove_friendly_object (pet); |
53 | remove_friendly_object (pet); |
64 | pet->attack_movement &= ~PETMOVE; |
54 | pet->attack_movement &= ~PETMOVE; |
65 | return 0; |
55 | return 0; |
|
|
56 | } |
|
|
57 | |
|
|
58 | /* If the owner has turned on the pet, make the pet |
|
|
59 | * unfriendly. |
|
|
60 | */ |
|
|
61 | if (check_enemy (owner, rv) == pet) |
|
|
62 | { |
|
|
63 | remove_friendly_object (pet); |
|
|
64 | pet->attack_movement &= ~PETMOVE; |
|
|
65 | return owner; |
66 | } |
66 | } |
67 | |
67 | |
68 | /* If they are not on the same map, the pet won't be agressive */ |
68 | /* If they are not on the same map, the pet won't be agressive */ |
69 | //if (!on_same_map (pet, owner)) |
69 | //if (!on_same_map (pet, owner)) |
70 | // return 0; |
70 | // return 0; |
… | |
… | |
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_IN_MEMORY) |
297 | else if (!owner->map || owner->map->in_memory != 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 | |
… | |
… | |
575 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
575 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
576 | |
576 | |
577 | if (mflags & P_OUT_OF_MAP) |
577 | if (mflags & P_OUT_OF_MAP) |
578 | continue; |
578 | continue; |
579 | |
579 | |
580 | for (victim = GET_MAP_OB (op->map, x, y); victim; victim = victim->above) |
580 | for (victim = GET_MAP_OB (m, x, y); victim; victim = victim->above) |
581 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
581 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
582 | break; |
582 | break; |
583 | |
583 | |
584 | /* We used to call will_hit_self to make sure we don't |
584 | /* 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 |
585 | * hit ourselves, but that didn't work, and I don't really |
… | |
… | |
678 | } |
678 | } |
679 | |
679 | |
680 | if (!dir) |
680 | if (!dir) |
681 | dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
681 | dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
682 | |
682 | |
683 | if (dir < 0 || ob_blocked (at, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
683 | if (dir < 0 || at->blocked (op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
684 | { |
684 | { |
685 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
685 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
686 | return 0; |
686 | return 0; |
687 | } |
687 | } |
688 | |
688 | |
… | |
… | |
695 | } |
695 | } |
696 | |
696 | |
697 | if (op->type == PLAYER) |
697 | if (op->type == PLAYER) |
698 | { |
698 | { |
699 | tmp->type = GOLEM; |
699 | tmp->type = GOLEM; |
700 | tmp->set_owner (op); |
|
|
701 | op->contr->golem = tmp; |
700 | op->contr->golem = tmp; |
702 | /* give the player control of the golem */ |
701 | /* give the player control of the golem */ |
703 | set_spell_skill (op, caster, spob, tmp); |
702 | set_spell_skill (op, caster, spob, tmp); |
704 | } |
703 | } |
705 | else |
|
|
706 | { |
|
|
707 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
|
|
708 | { |
|
|
709 | object *owner = op->owner; |
|
|
710 | |
|
|
711 | if (owner) |
|
|
712 | { /* For now, we transfer ownership */ |
|
|
713 | tmp->set_owner (owner); |
|
|
714 | tmp->attack_movement = PETMOVE; |
|
|
715 | add_friendly_object (tmp); |
|
|
716 | } |
|
|
717 | } |
|
|
718 | |
|
|
719 | SET_FLAG (tmp, FLAG_MONSTER); |
|
|
720 | } |
|
|
721 | |
704 | |
722 | /* make the speed positive. */ |
705 | /* make the speed positive. */ |
723 | tmp->speed = FABS (tmp->speed); |
706 | tmp->speed = fabs (tmp->speed); |
724 | |
707 | |
725 | /* This sets the level dependencies on dam and hp for monsters */ |
708 | /* This sets the level dependencies on dam and hp for monsters */ |
726 | /* players can't cope with too strong summonings. */ |
709 | /* players can't cope with too strong summonings. */ |
727 | /* but monsters can. reserve these for players. */ |
710 | /* but monsters can. reserve these for players. */ |
728 | if (op->type == PLAYER) |
711 | if (op->type == PLAYER) |
… | |
… | |
733 | tmp->stats.dam += SP_level_dam_adjust (caster, spob); |
716 | tmp->stats.dam += SP_level_dam_adjust (caster, spob); |
734 | else |
717 | else |
735 | tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob); |
718 | tmp->stats.dam = spob->stats.dam + SP_level_dam_adjust (caster, spob); |
736 | |
719 | |
737 | tmp->speed += .02 * SP_level_range_adjust (caster, spob); |
720 | tmp->speed += .02 * SP_level_range_adjust (caster, spob); |
738 | tmp->speed = MIN (tmp->speed, 1.0); |
721 | tmp->speed = min (tmp->speed, 1.0); |
739 | |
722 | |
740 | if (spob->attacktype) |
723 | if (spob->attacktype) |
741 | tmp->attacktype = spob->attacktype; |
724 | tmp->attacktype = spob->attacktype; |
742 | } |
725 | } |
743 | |
726 | |
… | |
… | |
747 | |
730 | |
748 | /* make experience increase in proportion to the strength. |
731 | /* make experience increase in proportion to the strength. |
749 | * this is a bit simplistic - we are basically just looking at how |
732 | * this is a bit simplistic - we are basically just looking at how |
750 | * often the sp doubles and use that as the ratio. |
733 | * often the sp doubles and use that as the ratio. |
751 | */ |
734 | */ |
752 | tmp->stats.exp *= 1 + (MAX (spob->stats.maxgrace, spob->stats.sp) / caster_level (caster, spob)); |
735 | tmp->stats.exp *= 1 + max (spob->stats.maxgrace, spob->stats.sp) / casting_level (caster, spob); |
753 | tmp->speed_left = 0; |
736 | tmp->speed_left = 0; |
754 | tmp->direction = dir; |
737 | tmp->direction = dir; |
755 | |
738 | |
756 | /* Holy spell - some additional tailoring */ |
739 | /* Holy spell - some additional tailoring */ |
757 | if (god) |
740 | if (god) |
… | |
… | |
878 | |
861 | |
879 | if (spell_ob->other_arch) |
862 | if (spell_ob->other_arch) |
880 | summon_arch = spell_ob->other_arch; |
863 | summon_arch = spell_ob->other_arch; |
881 | else if (spell_ob->randomitems) |
864 | else if (spell_ob->randomitems) |
882 | { |
865 | { |
883 | int level = caster_level (caster, spell_ob); |
866 | int level = casting_level (caster, spell_ob); |
884 | treasure *tr, *lasttr = NULL; |
867 | treasure *tr, *lasttr = NULL; |
885 | |
868 | |
886 | shstr_cmp sparam (stringarg); |
869 | shstr_cmp sparam (stringarg); |
887 | |
870 | |
888 | /* In old code, this was a very convoluted for statement, |
871 | /* In old code, this was a very convoluted for statement, |
… | |
… | |
930 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name); |
913 | new_draw_info_format (NDI_UNIQUE, 0, op, "%s has no creatures that you may summon!", &god->name); |
931 | return 0; |
914 | return 0; |
932 | } |
915 | } |
933 | |
916 | |
934 | /* the summon level */ |
917 | /* the summon level */ |
935 | summon_level = caster_level (caster, spell_ob); |
918 | summon_level = casting_level (caster, spell_ob); |
936 | if (summon_level == 0) |
919 | if (summon_level == 0) |
937 | summon_level = 1; |
920 | summon_level = 1; |
938 | |
921 | |
939 | tries = 0; |
922 | tries = 0; |
940 | do |
923 | do |
… | |
… | |
949 | ndir = dir; |
932 | ndir = dir; |
950 | |
933 | |
951 | if (!ndir) |
934 | if (!ndir) |
952 | ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); |
935 | ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); |
953 | |
936 | |
954 | if (ndir < 0 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) |
937 | if (ndir < 0 || mon->blocked (op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) |
955 | { |
938 | { |
956 | ndir = -1; |
939 | ndir = -1; |
957 | if (++tries == 5) |
940 | if (++tries == 5) |
958 | { |
941 | { |
959 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
942 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
… | |
… | |
998 | { |
981 | { |
999 | x = freearr_x[ndir]; |
982 | x = freearr_x[ndir]; |
1000 | y = freearr_y[ndir]; |
983 | y = freearr_y[ndir]; |
1001 | } |
984 | } |
1002 | |
985 | |
1003 | if (ndir < 0 || ob_blocked (summon_arch, op->map, op->x + x, op->y + y)) |
986 | if (ndir < 0 || summon_arch->blocked (op->map, op->x + x, op->y + y)) |
1004 | { |
987 | { |
1005 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
988 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
1006 | if (nrof > 1) |
989 | if (nrof > 1) |
1007 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
990 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
1008 | |
991 | |