1 | /* |
1 | /* |
2 | CrossFire, A Multiplayer game for X-windows |
2 | * This file is part of Deliantra, the Roguelike Realtime MMORPG. |
3 | |
3 | * |
|
|
4 | * Copyright (©) 2005,2006,2007,2008 Marc Alexander Lehmann / Robin Redeker / the Deliantra team |
4 | Copyright (C) 2002 Mark Wedel & Crossfire Development Team |
5 | * Copyright (©) 2002,2007 Mark Wedel & Crossfire Development Team |
5 | Copyright (C) 1992 Frank Tore Johansen |
6 | * Copyright (©) 1992,2007 Frank Tore Johansen |
6 | |
7 | * |
7 | This program is free software; you can redistribute it and/or modify |
8 | * Deliantra is free software: you can redistribute it and/or modify it under |
8 | it under the terms of the GNU General Public License as published by |
9 | * the terms of the Affero GNU General Public License as published by the |
9 | the Free Software Foundation; either version 2 of the License, or |
10 | * Free Software Foundation, either version 3 of the License, or (at your |
10 | (at your option) any later version. |
11 | * 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 Affero GNU General Public License |
18 | along with this program; if not, write to the Free Software |
19 | * and the GNU General Public License along with this program. If not, see |
19 | Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. |
20 | * <http://www.gnu.org/licenses/>. |
20 | |
21 | * |
21 | The authors can be reached via e-mail at <crossfire@schmorp.de> |
22 | * The authors can be reached via e-mail to <support@deliantra.net> |
22 | */ |
23 | */ |
23 | |
24 | |
24 | #include <global.h> |
25 | #include <global.h> |
25 | #ifndef __CEXTRACT__ |
|
|
26 | # include <sproto.h> |
26 | #include <sproto.h> |
27 | #endif |
|
|
28 | |
27 | |
29 | /* given that 'pet' is a friendly object, this function returns a |
28 | /* given that 'pet' is a friendly object, this function returns a |
30 | * monster the pet should attack, NULL if nothing appropriate is |
29 | * monster the pet should attack, NULL if nothing appropriate is |
31 | * found. it basically looks for nasty things around the owner |
30 | * found. it basically looks for nasty things around the owner |
32 | * of the pet to attack. |
31 | * of the pet to attack. |
33 | * this is now tilemap aware. |
32 | * this is now tilemap aware. |
34 | */ |
33 | */ |
35 | |
|
|
36 | object * |
34 | object * |
37 | get_pet_enemy (object *pet, rv_vector * rv) |
35 | get_pet_enemy (object *pet, rv_vector * rv) |
38 | { |
36 | { |
39 | object *owner, *tmp, *attacker, *tmp3; |
37 | object *tmp, *attacker, *tmp3; |
40 | int i; |
38 | int i; |
41 | sint16 x, y; |
39 | sint16 x, y; |
42 | mapstruct *nm; |
40 | maptile *nm; |
43 | int search_arr[SIZEOFFREE]; |
41 | int search_arr[SIZEOFFREE]; |
44 | int mflags; |
42 | int mflags; |
45 | |
43 | |
46 | attacker = pet->attacked_by; /*pointer to attacking enemy */ |
44 | attacker = pet->attacked_by; /*pointer to attacking enemy */ |
47 | pet->attacked_by = NULL; /*clear this, since we are dealing with it */ |
45 | pet->attacked_by = NULL; /*clear this, since we are dealing with it */ |
48 | |
46 | |
49 | if ((owner = get_owner (pet)) != NULL) |
47 | object *owner = pet->owner; |
50 | { |
48 | |
51 | /* If the owner has turned on the pet, make the pet |
49 | if (!owner) |
52 | * unfriendly. |
|
|
53 | */ |
|
|
54 | if ((check_enemy (owner, rv)) == pet) |
|
|
55 | { |
|
|
56 | CLEAR_FLAG (pet, FLAG_FRIENDLY); |
|
|
57 | remove_friendly_object (pet); |
|
|
58 | pet->attack_movement &= ~PETMOVE; |
|
|
59 | return owner; |
|
|
60 | } |
|
|
61 | } |
50 | { |
62 | else |
|
|
63 | { |
|
|
64 | /* else the owner is no longer around, so the |
51 | /* the owner is no longer around, so the |
65 | * pet no longer needs to be friendly. |
52 | * pet no longer needs to be friendly. |
66 | */ |
53 | */ |
67 | CLEAR_FLAG (pet, FLAG_FRIENDLY); |
|
|
68 | remove_friendly_object (pet); |
54 | remove_friendly_object (pet); |
69 | pet->attack_movement &= ~PETMOVE; |
55 | pet->attack_movement &= ~PETMOVE; |
70 | return NULL; |
56 | return 0; |
|
|
57 | } |
|
|
58 | |
|
|
59 | /* If the owner has turned on the pet, make the pet |
|
|
60 | * unfriendly. |
|
|
61 | */ |
|
|
62 | if (check_enemy (owner, rv) == pet) |
71 | } |
63 | { |
|
|
64 | remove_friendly_object (pet); |
|
|
65 | pet->attack_movement &= ~PETMOVE; |
|
|
66 | return owner; |
|
|
67 | } |
|
|
68 | |
72 | /* If they are not on the same map, the pet won't be agressive */ |
69 | /* If they are not on the same map, the pet won't be agressive */ |
73 | if (!on_same_map (pet, owner)) |
70 | //if (!on_same_map (pet, owner)) |
74 | return NULL; |
71 | // return 0; |
75 | |
72 | |
76 | /* See if the pet has an existing enemy. If so, don't start a new one */ |
73 | /* See if the pet has an existing enemy. If so, don't start a new one */ |
77 | if ((tmp = check_enemy (pet, rv)) != NULL) |
74 | if (tmp = check_enemy (pet, rv)) |
78 | { |
75 | { |
79 | if (tmp == owner && !QUERY_FLAG (pet, FLAG_CONFUSED) && QUERY_FLAG (pet, FLAG_FRIENDLY)) |
76 | if (tmp == owner && !QUERY_FLAG (pet, FLAG_CONFUSED) && QUERY_FLAG (pet, FLAG_FRIENDLY)) |
80 | /* without this check, you can actually get pets with |
77 | /* without this check, you can actually get pets with |
81 | * enemy set to owner! |
78 | * enemy set to owner! |
82 | */ |
79 | */ |
83 | pet->enemy = NULL; |
80 | pet->enemy = 0; |
84 | else |
81 | else |
85 | return tmp; |
82 | return tmp; |
86 | } |
83 | } |
|
|
84 | |
87 | get_search_arr (search_arr); |
85 | get_search_arr (search_arr); |
88 | |
86 | |
89 | if (owner->type == PLAYER && owner->contr->petmode > pet_normal) |
87 | if (owner->type == PLAYER && owner->contr->petmode > pet_normal) |
90 | { |
88 | { |
91 | if (owner->contr->petmode == pet_sad) |
89 | if (owner->contr->petmode == pet_sad) |
92 | { |
90 | { |
93 | tmp = find_nearest_living_creature (pet); |
91 | tmp = find_nearest_living_creature (pet); |
94 | if (tmp != NULL) |
92 | if (tmp != 0) |
95 | { |
93 | { |
96 | get_rangevector (pet, tmp, rv, 0); |
94 | get_rangevector (pet, tmp, rv, 0); |
97 | if (check_enemy (pet, rv) != NULL) |
95 | if (check_enemy (pet, rv) != 0) |
98 | return tmp; |
96 | return tmp; |
99 | else |
97 | else |
100 | pet->enemy = NULL; |
98 | pet->enemy = 0; |
101 | } |
99 | } |
102 | /* if we got here we have no enemy */ |
100 | /* if we got here we have no enemy */ |
103 | /* we return NULL to avoid heading back to the owner */ |
101 | /* we return 0 to avoid heading back to the owner */ |
104 | pet->enemy = NULL; |
102 | pet->enemy = 0; |
105 | return NULL; |
103 | return 0; |
106 | } |
104 | } |
107 | } |
105 | } |
108 | |
106 | |
109 | /* Since the pet has no existing enemy, look for anything nasty |
107 | /* Since the pet has no existing enemy, look for anything nasty |
110 | * around the owner that it should go and attack. |
108 | * around the owner that it should go and attack. (if the owner is |
|
|
109 | * still on a map) |
111 | */ |
110 | */ |
112 | tmp3 = NULL; |
111 | // owners sometimes are not on a map but in the inventory of somehting else |
|
|
112 | if (!owner->flag [FLAG_REMOVED] && owner->map) |
|
|
113 | { |
|
|
114 | tmp3 = 0; |
|
|
115 | |
113 | for (i = 0; i < SIZEOFFREE; i++) |
116 | for (i = 0; i < SIZEOFFREE; i++) |
114 | { |
117 | { |
115 | x = owner->x + freearr_x[search_arr[i]]; |
118 | x = owner->x + freearr_x[search_arr[i]]; |
116 | y = owner->y + freearr_y[search_arr[i]]; |
119 | y = owner->y + freearr_y[search_arr[i]]; |
117 | nm = owner->map; |
120 | nm = owner->map; |
118 | /* Only look on the space if there is something alive there. */ |
121 | /* Only look on the space if there is something alive there. */ |
119 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
122 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
|
|
123 | |
120 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
124 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
121 | { |
125 | { |
122 | for (tmp = get_map_ob (nm, x, y); tmp != NULL; tmp = tmp->above) |
126 | for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) |
123 | { |
|
|
124 | object *tmp2 = tmp->head == NULL ? tmp : tmp->head; |
|
|
125 | |
|
|
126 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
|
|
127 | (tmp2->type != PLAYER)) || |
|
|
128 | should_arena_attack (pet, owner, tmp2)) |
|
|
129 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
|
|
130 | { |
127 | { |
|
|
128 | object *tmp2 = tmp->head == 0 ? tmp : tmp->head; |
131 | |
129 | |
132 | if (!can_see_enemy (pet, tmp2)) |
130 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
|
|
131 | (tmp2->type != PLAYER)) || |
|
|
132 | should_arena_attack (pet, owner, tmp2)) |
|
|
133 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
133 | { |
134 | { |
|
|
135 | |
|
|
136 | if (!can_see_enemy (pet, tmp2)) |
|
|
137 | { |
134 | if (tmp3 != NULL) |
138 | if (tmp3 != 0) |
135 | tmp3 = tmp2; |
139 | tmp3 = tmp2; |
136 | } |
140 | } |
137 | else |
|
|
138 | { |
|
|
139 | pet->enemy = tmp2; |
|
|
140 | if (check_enemy (pet, rv) != NULL) |
|
|
141 | return tmp2; |
|
|
142 | else |
141 | else |
|
|
142 | { |
|
|
143 | pet->enemy = tmp2; |
|
|
144 | if (check_enemy (pet, rv) != 0) |
|
|
145 | return tmp2; |
|
|
146 | else |
143 | pet->enemy = NULL; |
147 | pet->enemy = 0; |
144 | } |
148 | } |
145 | } /* if this is a valid enemy */ |
149 | } /* if this is a valid enemy */ |
146 | } /* for objects on this space */ |
150 | } /* for objects on this space */ |
147 | } /* if there is something living on this space */ |
151 | } /* if there is something living on this space */ |
148 | } /* for loop of spaces around the owner */ |
152 | } /* for loop of spaces around the owner */ |
149 | |
153 | |
150 | /* fine, we went through the whole loop and didn't find one we could |
154 | /* fine, we went through the whole loop and didn't find one we could |
151 | see, take what we have */ |
155 | see, take what we have */ |
152 | if (tmp3 != NULL) |
156 | if (tmp3 != 0) |
153 | { |
157 | { |
154 | pet->enemy = tmp3; |
158 | pet->enemy = tmp3; |
155 | if (check_enemy (pet, rv) != NULL) |
159 | if (check_enemy (pet, rv) != 0) |
156 | return tmp3; |
160 | return tmp3; |
157 | else |
161 | else |
158 | pet->enemy = NULL; |
162 | pet->enemy = 0; |
|
|
163 | } |
159 | } |
164 | } |
160 | |
165 | |
161 | /* No threat to owner, check to see if the pet has an attacker */ |
166 | /* No threat to owner, check to see if the pet has an attacker */ |
162 | if (attacker) |
167 | if (attacker) |
163 | { |
168 | { |
… | |
… | |
165 | /* or otherwise non-hostile, and is an appropriate target */ |
170 | /* or otherwise non-hostile, and is an appropriate target */ |
166 | if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker)) |
171 | if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker)) |
167 | { |
172 | { |
168 | pet->enemy = attacker; |
173 | pet->enemy = attacker; |
169 | |
174 | |
170 | if (check_enemy (pet, rv) != NULL) |
175 | if (check_enemy (pet, rv) != 0) |
171 | return attacker; |
176 | return attacker; |
172 | else |
177 | else |
173 | pet->enemy = NULL; |
178 | pet->enemy = 0; |
174 | } |
179 | } |
175 | } |
180 | } |
176 | |
181 | |
177 | /* Don't have an attacker or legal enemy, so look for a new one!. |
182 | /* Don't have an attacker or legal enemy, so look for a new one!. |
178 | * This looks for one around where the pet is. Thus, you could lead |
183 | * This looks for one around where the pet is. Thus, you could lead |
179 | * a pet to danger, then take a few steps back. This code is basically |
184 | * a pet to danger, then take a few steps back. This code is basically |
180 | * the same as the code that looks around the owner. |
185 | * the same as the code that looks around the owner. |
181 | */ |
186 | */ |
182 | if (owner->type == PLAYER && owner->contr->petmode != pet_defend) |
187 | if (owner->type == PLAYER && owner->contr->petmode != pet_defend) |
183 | { |
188 | { |
184 | tmp3 = NULL; |
189 | tmp3 = 0; |
185 | for (i = 0; i < SIZEOFFREE; i++) |
190 | for (i = 0; i < SIZEOFFREE; i++) |
186 | { |
191 | { |
187 | x = pet->x + freearr_x[search_arr[i]]; |
192 | x = pet->x + freearr_x[search_arr[i]]; |
188 | y = pet->y + freearr_y[search_arr[i]]; |
193 | y = pet->y + freearr_y[search_arr[i]]; |
189 | nm = pet->map; |
194 | nm = pet->map; |
190 | /* Only look on the space if there is something alive there. */ |
195 | /* Only look on the space if there is something alive there. */ |
191 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
196 | mflags = get_map_flags (nm, &nm, x, y, &x, &y); |
192 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
197 | if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) |
193 | { |
198 | { |
194 | for (tmp = get_map_ob (nm, x, y); tmp != NULL; tmp = tmp->above) |
199 | for (tmp = GET_MAP_OB (nm, x, y); tmp != 0; tmp = tmp->above) |
195 | { |
200 | { |
196 | object *tmp2 = tmp->head == NULL ? tmp : tmp->head; |
201 | object *tmp2 = tmp->head == 0 ? tmp : tmp->head; |
197 | |
202 | |
198 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
203 | if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && |
199 | (tmp2->type != PLAYER)) || |
204 | (tmp2->type != PLAYER)) || |
200 | should_arena_attack (pet, owner, tmp2)) |
205 | should_arena_attack (pet, owner, tmp2)) |
201 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
206 | && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv)) |
202 | { |
207 | { |
203 | |
208 | |
204 | if (!can_see_enemy (pet, tmp2)) |
209 | if (!can_see_enemy (pet, tmp2)) |
205 | { |
210 | { |
206 | if (tmp3 != NULL) |
211 | if (tmp3 != 0) |
207 | tmp3 = tmp2; |
212 | tmp3 = tmp2; |
208 | } |
213 | } |
209 | else |
214 | else |
210 | { |
215 | { |
211 | pet->enemy = tmp2; |
216 | pet->enemy = tmp2; |
212 | if (check_enemy (pet, rv) != NULL) |
217 | if (check_enemy (pet, rv) != 0) |
213 | return tmp2; |
218 | return tmp2; |
214 | else |
219 | else |
215 | pet->enemy = NULL; |
220 | pet->enemy = 0; |
216 | } |
221 | } |
217 | } /* make sure we can get to the bugger */ |
222 | } /* make sure we can get to the bugger */ |
218 | } /* for objects on this space */ |
223 | } /* for objects on this space */ |
219 | } /* if there is something living on this space */ |
224 | } /* if there is something living on this space */ |
220 | } /* for loop of spaces around the pet */ |
225 | } /* for loop of spaces around the pet */ |
|
|
226 | |
|
|
227 | /* fine, we went through the whole loop and didn't find one we could |
|
|
228 | see, take what we have */ |
|
|
229 | if (tmp3 != 0) |
|
|
230 | { |
|
|
231 | pet->enemy = tmp3; |
|
|
232 | if (check_enemy (pet, rv) != 0) |
|
|
233 | return tmp3; |
|
|
234 | else |
|
|
235 | pet->enemy = 0; |
|
|
236 | } |
221 | } /* pet in defence mode */ |
237 | } /* pet in defence mode */ |
222 | |
238 | |
223 | /* fine, we went through the whole loop and didn't find one we could |
239 | object *enemy = check_enemy (pet, rv); |
224 | see, take what we have */ |
240 | // we have a summoned pet here and the owners enemy isn't set or can't |
225 | if (tmp3 != NULL) |
241 | // be reached => search for a player around us and set it as our new enemy!! |
226 | { |
242 | if (!enemy && pet->owner && pet->owner->type != PLAYER) |
227 | pet->enemy = tmp3; |
243 | enemy = get_nearest_player (pet); |
228 | if (check_enemy (pet, rv) != NULL) |
|
|
229 | return tmp3; |
|
|
230 | else |
|
|
231 | pet->enemy = NULL; |
|
|
232 | } |
|
|
233 | |
244 | |
234 | /* Didn't find anything - return the owner's enemy or NULL */ |
245 | /* Didn't find anything - return the owner's enemy or 0 */ |
235 | return check_enemy (pet, rv); |
246 | return enemy; |
236 | } |
247 | } |
237 | |
248 | |
238 | void |
249 | void |
239 | terminate_all_pets (object *owner) |
250 | terminate_all_pets (object *owner) |
240 | { |
251 | { |
241 | objectlink *obl, *next; |
252 | objectlink *obl, *next; |
242 | |
253 | |
243 | for (obl = first_friendly_object; obl != NULL; obl = next) |
254 | for (obl = first_friendly_object; obl; obl = next) |
244 | { |
255 | { |
245 | object *ob = obl->ob; |
256 | object *ob = obl->ob; |
246 | |
|
|
247 | next = obl->next; |
257 | next = obl->next; |
|
|
258 | |
248 | if (get_owner (ob) == owner) |
259 | if (ob->owner == owner) |
249 | { |
260 | ob->drop_and_destroy (); |
250 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
|
|
251 | remove_ob (ob); |
|
|
252 | remove_friendly_object (ob); |
|
|
253 | free_object (ob); |
|
|
254 | } |
|
|
255 | } |
261 | } |
256 | } |
262 | } |
257 | |
263 | |
258 | /* |
264 | /* |
259 | * Unfortunately, sometimes, the owner of a pet is in the |
265 | * Unfortunately, sometimes, the owner of a pet is in the |
… | |
… | |
261 | * Thus the map isn't loaded yet, and we have to remove |
267 | * Thus the map isn't loaded yet, and we have to remove |
262 | * the pet... |
268 | * the pet... |
263 | * Interesting enough, we don't use the passed map structure in |
269 | * Interesting enough, we don't use the passed map structure in |
264 | * this function. |
270 | * this function. |
265 | */ |
271 | */ |
266 | |
|
|
267 | void |
272 | void |
268 | remove_all_pets (mapstruct *map) |
273 | remove_all_pets (maptile *map) |
269 | { |
274 | { |
270 | objectlink *obl, *next; |
275 | objectlink *obl, *next; |
271 | object *owner; |
276 | object *owner; |
272 | |
277 | |
273 | for (obl = first_friendly_object; obl != NULL; obl = next) |
278 | for (obl = first_friendly_object; obl; obl = next) |
274 | { |
279 | { |
275 | next = obl->next; |
280 | next = obl->next; |
276 | if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) && |
281 | |
277 | (owner = get_owner (obl->ob)) != NULL && !on_same_map (owner, obl->ob)) |
282 | if (obl->ob->type != PLAYER |
|
|
283 | && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) |
|
|
284 | && (owner = obl->ob->owner) != 0 |
|
|
285 | && !on_same_map (owner, obl->ob)) |
278 | { |
286 | { |
279 | /* follow owner checks map status for us */ |
287 | /* follow owner checks map status for us */ |
280 | follow_owner (obl->ob, owner); |
288 | follow_owner (obl->ob, owner); |
281 | } |
289 | } |
282 | } |
290 | } |
283 | } |
291 | } |
284 | |
292 | |
285 | int |
293 | int |
286 | follow_owner (object *ob, object *owner) |
294 | follow_owner (object *ob, object *owner) |
287 | { |
295 | { |
288 | object *tmp; |
296 | if (owner->flag [FLAG_REMOVED]) |
289 | int dir; |
297 | return 0; // do nothing if the owner is removed |
290 | |
298 | else if (!owner->map || owner->map->in_memory != MAP_ACTIVE) |
291 | if (!QUERY_FLAG (ob, FLAG_REMOVED)) |
299 | LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name); |
292 | remove_ob (ob); |
300 | else |
293 | |
|
|
294 | if (owner->map == NULL) |
|
|
295 | { |
|
|
296 | LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name); |
|
|
297 | goto fail; |
|
|
298 | } |
301 | { |
299 | if (owner->map->in_memory != MAP_IN_MEMORY) |
|
|
300 | { |
|
|
301 | LOG (llevError, "Owner of the pet not on a map in memory!?\n"); |
|
|
302 | goto fail; |
|
|
303 | } |
|
|
304 | |
|
|
305 | dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); |
302 | int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); |
306 | |
303 | |
307 | if (dir == -1) |
304 | if (dir >= 0) |
308 | { |
|
|
309 | LOG (llevMonster, "No space for pet to follow, freeing %s.\n", &ob->name); |
|
|
310 | goto fail; |
|
|
311 | } |
|
|
312 | for (tmp = ob; tmp != NULL; tmp = tmp->more) |
|
|
313 | { |
|
|
314 | tmp->x = owner->x + freearr_x[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x); |
|
|
315 | tmp->y = owner->y + freearr_y[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y); |
|
|
316 | tmp->map = owner->map; |
|
|
317 | if (OUT_OF_REAL_MAP (tmp->map, tmp->x, tmp->y)) |
|
|
318 | { |
|
|
319 | tmp->map = get_map_from_coord (tmp->map, &tmp->x, &tmp->y); |
|
|
320 | } |
305 | { |
321 | } |
306 | owner->map->insert (ob, owner->x + freearr_x[dir], owner->y + freearr_y[dir]); |
322 | insert_ob_in_map (ob, ob->map, NULL, 0); |
307 | |
323 | if (owner->type == PLAYER) /* Uh, I hope this is always true... */ |
308 | if (owner->type == PLAYER) /* Uh, I hope this is always true... */ |
324 | new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); |
309 | new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); |
325 | |
310 | |
326 | return 0; |
311 | return 0; |
|
|
312 | } |
|
|
313 | } |
327 | |
314 | |
328 | fail: |
315 | ob->drop_and_destroy (); |
329 | remove_friendly_object (ob); |
|
|
330 | free_object (ob); |
|
|
331 | |
316 | |
332 | return 1; |
317 | return 1; |
333 | } |
318 | } |
334 | |
319 | |
335 | void |
320 | void |
336 | pet_move (object *ob) |
321 | pet_move (object *ob) |
337 | { |
322 | { |
338 | int dir, tag, i; |
323 | int dir = 0, i; |
339 | sint16 dx, dy; |
324 | sint16 dx, dy; |
340 | object *ob2, *owner; |
325 | object *ob2, *owner; |
341 | mapstruct *m; |
326 | maptile *m; |
342 | |
327 | |
343 | /* Check to see if player pulled out */ |
328 | /* Check to see if player pulled out */ |
344 | if ((owner = get_owner (ob)) == NULL) |
329 | if ((owner = ob->owner) == NULL) |
345 | { |
330 | { |
346 | remove_ob (ob); /* Will be freed when returning */ |
331 | ob->drop_and_destroy (); |
347 | remove_friendly_object (ob); |
|
|
348 | free_object (ob); |
|
|
349 | LOG (llevMonster, "Pet: no owner, leaving.\n"); |
332 | LOG (llevMonster, "Pet: no owner, leaving.\n"); |
350 | return; |
333 | return; |
351 | } |
334 | } |
352 | |
335 | |
353 | /* move monster into the owners map if not in the same map */ |
336 | /* move monster into the owners map if not in the same map |
354 | if (!on_same_map (ob, owner)) |
337 | * except when the owner is removed. |
|
|
338 | */ |
|
|
339 | if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED]) |
355 | { |
340 | { |
356 | follow_owner (ob, owner); |
341 | follow_owner (ob, owner); |
357 | return; |
342 | return; |
358 | } |
343 | } |
|
|
344 | |
359 | /* Calculate Direction */ |
345 | /* Calculate Direction */ |
360 | if (owner->type == PLAYER && owner->contr->petmode == pet_sad) |
346 | if (owner->type == PLAYER && owner->contr->petmode == pet_sad) |
361 | { |
347 | { |
362 | /* in S&D mode, if we have no enemy, run randomly about. */ |
348 | /* in S&D mode, if we have no enemy, run randomly about. */ |
363 | for (i = 0; i < 15; i++) |
349 | for (i = 0; i < 15; i++) |
… | |
… | |
372 | continue; |
358 | continue; |
373 | else |
359 | else |
374 | break; |
360 | break; |
375 | } |
361 | } |
376 | } |
362 | } |
377 | else |
363 | else if (!owner->flag [FLAG_REMOVED]) // only get vector to owner when owner not removed |
378 | { |
364 | { |
379 | struct rv_vector rv; |
365 | struct rv_vector rv; |
380 | |
366 | |
381 | get_rangevector (ob, ob->owner, &rv, 0); |
367 | get_rangevector (ob, ob->owner, &rv, 0); |
382 | dir = rv.direction; |
368 | dir = rv.direction; |
383 | } |
369 | } |
|
|
370 | |
384 | ob->direction = dir; |
371 | ob->direction = dir; |
385 | |
372 | |
386 | tag = ob->count; |
|
|
387 | /* move_ob returns 0 if the object couldn't move. If that is the |
373 | /* move_ob returns 0 if the object couldn't move. If that is the |
388 | * case, lets do some other work. |
374 | * case, lets do some other work. |
389 | */ |
375 | */ |
390 | if (!(move_ob (ob, dir, ob))) |
376 | if (!(move_ob (ob, dir, ob))) |
391 | { |
377 | { |
392 | object *part; |
378 | object *part; |
393 | |
379 | |
394 | /* the failed move_ob above may destroy the pet, so check here */ |
380 | /* the failed move_ob above may destroy the pet, so check here */ |
395 | if (was_destroyed (ob, tag)) |
381 | if (ob->destroyed ()) |
396 | return; |
382 | return; |
397 | |
383 | |
398 | for (part = ob; part != NULL; part = part->more) |
384 | for (part = ob; part != NULL; part = part->more) |
399 | { |
385 | { |
400 | dx = part->x + freearr_x[dir]; |
386 | dx = part->x + freearr_x[dir]; |
401 | dy = part->y + freearr_y[dir]; |
387 | dy = part->y + freearr_y[dir]; |
402 | m = get_map_from_coord (part->map, &dx, &dy); |
388 | m = get_map_from_coord (part->map, &dx, &dy); |
403 | if (!m) |
389 | if (!m) |
404 | continue; |
390 | continue; |
405 | |
391 | |
406 | for (ob2 = get_map_ob (m, dx, dy); ob2 != NULL; ob2 = ob2->above) |
392 | for (ob2 = GET_MAP_OB (m, dx, dy); ob2 != NULL; ob2 = ob2->above) |
407 | { |
393 | { |
408 | object *new_ob; |
394 | object *new_ob; |
409 | |
395 | |
410 | new_ob = ob2->head ? ob2->head : ob2; |
396 | new_ob = ob2->head ? ob2->head : ob2; |
|
|
397 | |
411 | if (new_ob == ob) |
398 | if (new_ob == ob) |
412 | break; |
399 | break; |
|
|
400 | |
413 | if (new_ob == ob->owner) |
401 | if (new_ob == ob->owner) |
414 | return; |
402 | return; |
|
|
403 | |
415 | if (get_owner (new_ob) == ob->owner) |
404 | if (new_ob->owner == ob->owner) |
416 | break; |
405 | break; |
417 | |
406 | |
418 | /* Hmm. Did we try to move into an enemy monster? If so, |
407 | /* Hmm. Did we try to move into an enemy monster? If so, |
419 | * make it our enemy. |
408 | * make it our enemy. |
420 | */ |
409 | */ |
… | |
… | |
433 | return; |
422 | return; |
434 | } |
423 | } |
435 | } |
424 | } |
436 | } |
425 | } |
437 | /* Try a different course */ |
426 | /* Try a different course */ |
438 | dir = absdir (dir + 4 - (RANDOM () % 5) - (RANDOM () % 5)); |
427 | dir = absdir (dir + 4 - (rndm (5)) - (rndm (5))); |
439 | (void) move_ob (ob, dir, ob); |
428 | move_ob (ob, dir, ob); |
440 | } |
429 | } |
441 | return; |
|
|
442 | } |
430 | } |
443 | |
431 | |
444 | /**************************************************************************** |
432 | /**************************************************************************** |
445 | * |
433 | * |
446 | * GOLEM SPELL CODE |
434 | * GOLEM SPELL CODE |
… | |
… | |
451 | * proper for map insertion. |
439 | * proper for map insertion. |
452 | * at is the archetype, op is the caster of the spell, dir is the |
440 | * at is the archetype, op is the caster of the spell, dir is the |
453 | * direction the monster should be placed in. |
441 | * direction the monster should be placed in. |
454 | * is_golem is to note that this is a golem spell. |
442 | * is_golem is to note that this is a golem spell. |
455 | */ |
443 | */ |
456 | object * |
444 | static object * |
457 | fix_summon_pet (archetype *at, object *op, int dir, int is_golem) |
445 | fix_summon_pet (archetype *at, object *op, int dir, int is_golem) |
458 | { |
446 | { |
459 | archetype *atmp; |
|
|
460 | object *tmp = NULL, *prev = NULL, *head = NULL; |
447 | object *tmp = NULL, *prev = NULL, *head = NULL; |
461 | |
448 | |
462 | for (atmp = at; atmp != NULL; atmp = atmp->more) |
449 | for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more) |
463 | { |
450 | { |
464 | tmp = arch_to_object (atmp); |
451 | tmp = atmp->instance (); |
|
|
452 | |
465 | if (atmp == at) |
453 | if (atmp == at) |
466 | { |
454 | { |
467 | if (!is_golem) |
455 | if (!is_golem) |
468 | SET_FLAG (tmp, FLAG_MONSTER); |
456 | SET_FLAG (tmp, FLAG_MONSTER); |
|
|
457 | |
469 | set_owner (tmp, op); |
458 | tmp->set_owner (op); |
|
|
459 | |
470 | if (op->type == PLAYER) |
460 | if (op->type == PLAYER) |
471 | { |
461 | { |
472 | tmp->stats.exp = 0; |
462 | tmp->stats.exp = 0; |
473 | add_friendly_object (tmp); |
463 | add_friendly_object (tmp); |
474 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
475 | if (is_golem) |
464 | if (is_golem) |
476 | CLEAR_FLAG (tmp, FLAG_MONSTER); |
465 | CLEAR_FLAG (tmp, FLAG_MONSTER); |
477 | } |
466 | } |
478 | else |
467 | else |
479 | { |
468 | { |
480 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
469 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
481 | { |
470 | { |
482 | object *owner = get_owner (op); |
471 | object *owner = op->owner; |
483 | |
472 | |
484 | if (owner != NULL) |
473 | if (owner) |
485 | { /* For now, we transfer ownership */ |
474 | { /* For now, we transfer ownership */ |
486 | set_owner (tmp, owner); |
475 | tmp->set_owner (owner); |
487 | tmp->attack_movement = PETMOVE; |
476 | tmp->attack_movement = PETMOVE; |
488 | add_friendly_object (tmp); |
477 | add_friendly_object (tmp); |
489 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
490 | } |
478 | } |
491 | } |
479 | } |
492 | } |
480 | } |
|
|
481 | |
493 | if (op->type != PLAYER || !is_golem) |
482 | if (op->type != PLAYER || !is_golem) |
494 | { |
483 | { |
495 | tmp->attack_movement = PETMOVE; |
484 | tmp->attack_movement = PETMOVE; |
496 | tmp->speed_left = -1; |
485 | tmp->speed_left = -1; |
497 | tmp->type = 0; |
486 | tmp->type = 0; |
… | |
… | |
499 | } |
488 | } |
500 | else |
489 | else |
501 | tmp->type = GOLEM; |
490 | tmp->type = GOLEM; |
502 | |
491 | |
503 | } |
492 | } |
|
|
493 | |
504 | if (head == NULL) |
494 | if (!head) |
505 | head = tmp; |
495 | head = tmp; |
|
|
496 | |
506 | tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x; |
497 | tmp->x = op->x + freearr_x[dir] + tmp->arch->x; |
507 | tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y; |
498 | tmp->y = op->y + freearr_y[dir] + tmp->arch->y; |
508 | tmp->map = op->map; |
499 | tmp->map = op->map; |
|
|
500 | |
509 | if (tmp->invisible) |
501 | if (tmp->invisible) |
510 | tmp->invisible = 0; |
502 | tmp->invisible = 0; |
|
|
503 | |
511 | if (head != tmp) |
504 | if (head != tmp) |
512 | tmp->head = head, prev->more = tmp; |
505 | tmp->head = head, prev->more = tmp; |
|
|
506 | |
513 | prev = tmp; |
507 | prev = tmp; |
514 | } |
508 | } |
|
|
509 | |
515 | head->direction = dir; |
510 | head->direction = dir; |
516 | |
511 | |
517 | /* need to change some monster attr to prevent problems/crashing */ |
512 | /* need to change some monster attr to prevent problems/crashing */ |
518 | head->last_heal = 0; |
513 | head->last_heal = 0; |
519 | head->last_eat = 0; |
514 | head->last_eat = 0; |
… | |
… | |
530 | |
525 | |
531 | return head; |
526 | return head; |
532 | } |
527 | } |
533 | |
528 | |
534 | /* updated this to allow more than the golem 'head' to attack */ |
529 | /* updated this to allow more than the golem 'head' to attack */ |
535 | |
|
|
536 | /* op is the golem to be moved. */ |
530 | /* op is the golem to be moved. */ |
537 | |
|
|
538 | void |
531 | void |
539 | move_golem (object *op) |
532 | move_golem (object *op) |
540 | { |
533 | { |
541 | int made_attack = 0; |
534 | int made_attack = 0; |
542 | object *tmp; |
535 | object *tmp; |
543 | tag_t tag; |
|
|
544 | |
536 | |
545 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
537 | if (QUERY_FLAG (op, FLAG_MONSTER)) |
546 | return; /* Has already been moved */ |
538 | return; /* Has already been moved */ |
547 | |
539 | |
548 | if (get_owner (op) == NULL) |
540 | if (!op->owner) |
549 | { |
541 | { |
550 | LOG (llevDebug, "Golem without owner destructed.\n"); |
542 | LOG (llevDebug, "Golem without owner destructed.\n"); |
551 | remove_ob (op); |
543 | op->drop_and_destroy (); |
552 | free_object (op); |
|
|
553 | return; |
544 | return; |
554 | } |
545 | } |
|
|
546 | |
555 | /* It would be nice to have a cleaner way of what message to print |
547 | /* It would be nice to have a cleaner way of what message to print |
556 | * when the golem expires than these hard coded entries. |
548 | * when the golem expires than these hard coded entries. |
557 | * Note it is intentional that a golems duration is based on its |
549 | * Note it is intentional that a golems duration is based on its |
558 | * hp, and not duration |
550 | * hp, and not duration |
559 | */ |
551 | */ |
560 | if (--op->stats.hp < 0) |
552 | if (--op->stats.hp < 0) |
561 | { |
553 | { |
562 | if (op->msg) |
554 | if (op->msg) |
563 | new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); |
555 | new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); |
564 | op->owner->contr->ranges[range_golem] = NULL; |
556 | |
565 | op->owner->contr->golem_count = 0; |
557 | op->drop_and_destroy (); |
566 | remove_friendly_object (op); |
|
|
567 | remove_ob (op); |
|
|
568 | free_object (op); |
|
|
569 | return; |
558 | return; |
570 | } |
559 | } |
571 | |
560 | |
572 | /* Do golem attacks/movement for single & multisq golems. |
561 | /* Do golem attacks/movement for single & multisq golems. |
573 | * Assuming here that op is the 'head' object. Pass only op to |
562 | * Assuming here that op is the 'head' object. Pass only op to |
574 | * move_ob (makes recursive calls to other parts) |
563 | * move_ob (makes recursive calls to other parts) |
575 | * move_ob returns 0 if the creature was not able to move. |
564 | * move_ob returns 0 if the creature was not able to move. |
576 | */ |
565 | */ |
577 | tag = op->count; |
|
|
578 | if (move_ob (op, op->direction, op)) |
566 | if (move_ob (op, op->direction, op)) |
579 | return; |
567 | return; |
580 | if (was_destroyed (op, tag)) |
568 | |
|
|
569 | if (op->destroyed ()) |
581 | return; |
570 | return; |
582 | |
571 | |
583 | for (tmp = op; tmp; tmp = tmp->more) |
572 | for (tmp = op; tmp; tmp = tmp->more) |
584 | { |
573 | { |
585 | sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; |
574 | sint16 x = tmp->x + freearr_x[op->direction], y = tmp->y + freearr_y[op->direction]; |
586 | object *victim; |
575 | object *victim; |
587 | mapstruct *m; |
576 | maptile *m; |
588 | int mflags; |
577 | int mflags; |
589 | |
578 | |
590 | m = op->map; |
579 | m = op->map; |
591 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
580 | mflags = get_map_flags (m, &m, x, y, &x, &y); |
592 | |
581 | |
593 | if (mflags & P_OUT_OF_MAP) |
582 | if (mflags & P_OUT_OF_MAP) |
594 | continue; |
583 | continue; |
595 | |
584 | |
596 | for (victim = get_map_ob (op->map, x, y); victim; victim = victim->above) |
585 | for (victim = GET_MAP_OB (m, x, y); victim; victim = victim->above) |
597 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
586 | if (QUERY_FLAG (victim, FLAG_ALIVE)) |
598 | break; |
587 | break; |
599 | |
588 | |
600 | /* We used to call will_hit_self to make sure we don't |
589 | /* We used to call will_hit_self to make sure we don't |
601 | * hit ourselves, but that didn't work, and I don't really |
590 | * hit ourselves, but that didn't work, and I don't really |
… | |
… | |
604 | * but since we are not trying to dereferance that pointer, |
593 | * but since we are not trying to dereferance that pointer, |
605 | * that isn't a problem. |
594 | * that isn't a problem. |
606 | */ |
595 | */ |
607 | if (victim && victim != op && victim->head != op) |
596 | if (victim && victim != op && victim->head != op) |
608 | { |
597 | { |
609 | |
|
|
610 | /* for golems with race fields, we don't attack |
598 | /* for golems with race fields, we don't attack |
611 | * aligned races |
599 | * aligned races |
612 | */ |
600 | */ |
613 | |
601 | |
614 | if (victim->race && op->race && strstr (op->race, victim->race)) |
602 | if (victim->race && op->race && op->race.contains (victim->race)) |
615 | { |
603 | { |
616 | if (op->owner) |
604 | if (op->owner) |
617 | new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name); |
605 | new_draw_info_format (NDI_UNIQUE, 0, op->owner, "%s avoids damaging %s.", &op->name, &victim->name); |
618 | } |
606 | } |
619 | else if (victim == op->owner) |
607 | else if (victim == op->owner) |
… | |
… | |
626 | attack_ob (victim, op); |
614 | attack_ob (victim, op); |
627 | made_attack = 1; |
615 | made_attack = 1; |
628 | } |
616 | } |
629 | } /* If victim */ |
617 | } /* If victim */ |
630 | } |
618 | } |
|
|
619 | |
631 | if (made_attack) |
620 | if (made_attack) |
632 | update_object (op, UP_OBJ_FACE); |
621 | update_object (op, UP_OBJ_FACE); |
633 | } |
622 | } |
634 | |
623 | |
635 | /* this is a really stupid function when you get down and |
624 | /* this is a really stupid function when you get down and |
… | |
… | |
641 | control_golem (object *op, int dir) |
630 | control_golem (object *op, int dir) |
642 | { |
631 | { |
643 | op->direction = dir; |
632 | op->direction = dir; |
644 | } |
633 | } |
645 | |
634 | |
646 | /* summon golem: summons a monster for 'op'. caster is the object |
635 | /* summon golem: summons a monster for 'op'. caster is the object |
647 | * casting the spell, dir is the direction to place the monster, |
636 | * casting the spell, dir is the direction to place the monster, |
648 | * at is the archetype of the monster, and spob is the spell |
637 | * at is the archetype of the monster, and spob is the spell |
649 | * object. At this stage, all spob is really used for is to |
638 | * object. At this stage, all spob is really used for is to |
650 | * adjust some values in the monster. |
639 | * adjust some values in the monster. |
651 | */ |
640 | */ |
652 | int |
641 | int |
653 | summon_golem (object *op, object *caster, int dir, object *spob) |
642 | summon_golem (object *op, object *caster, int dir, object *spob) |
654 | { |
643 | { |
655 | object *tmp, *god = NULL; |
644 | object *tmp, *god = NULL; |
656 | archetype *at; |
645 | archetype *at; |
657 | char buf[MAX_BUF]; |
|
|
658 | |
646 | |
659 | /* Because there can be different golem spells, player may want to |
647 | /* Because there can be different golem spells, player may want to |
660 | * 'lose' their old golem. |
648 | * 'lose' their old golem. |
661 | */ |
649 | */ |
662 | if (op->type == PLAYER && op->contr->ranges[range_golem] != NULL && op->contr->golem_count == op->contr->ranges[range_golem]->count) |
650 | if (op->type == PLAYER && op->contr->golem) |
663 | { |
651 | { |
664 | new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); |
652 | new_draw_info (NDI_UNIQUE, 0, op, "You dismiss your existing golem."); |
665 | remove_ob (op->contr->ranges[range_golem]); |
653 | op->contr->golem->drop_and_destroy (); |
666 | free_object (op->contr->ranges[range_golem]); |
654 | op->contr->golem = 0; |
667 | op->contr->ranges[range_golem] = NULL; |
|
|
668 | op->contr->golem_count = (uint32) - 1; |
|
|
669 | } |
655 | } |
670 | |
656 | |
671 | if (spob->other_arch) |
657 | if (spob->other_arch) |
672 | at = spob->other_arch; |
658 | at = spob->other_arch; |
673 | else if (spob->race) |
659 | else if (spob->race) |
… | |
… | |
693 | LOG (llevError, "Spell %s lacks other_arch\n", &spob->name); |
679 | LOG (llevError, "Spell %s lacks other_arch\n", &spob->name); |
694 | return 0; |
680 | return 0; |
695 | } |
681 | } |
696 | |
682 | |
697 | if (!dir) |
683 | if (!dir) |
698 | dir = find_free_spot (NULL, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
684 | dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); |
699 | |
685 | |
700 | if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
686 | if (dir < 0 || at->blocked (op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) |
701 | { |
687 | { |
702 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
688 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
703 | return 0; |
689 | return 0; |
704 | } |
690 | } |
|
|
691 | |
705 | /* basically want to get proper map/coordinates for this object */ |
692 | /* basically want to get proper map/coordinates for this object */ |
706 | |
693 | |
707 | if (!(tmp = fix_summon_pet (at, op, dir, GOLEM))) |
694 | if (!(tmp = fix_summon_pet (at, op, dir, GOLEM))) |
708 | { |
695 | { |
709 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails."); |
696 | new_draw_info (NDI_UNIQUE, 0, op, "Your spell fails."); |
… | |
… | |
711 | } |
698 | } |
712 | |
699 | |
713 | if (op->type == PLAYER) |
700 | if (op->type == PLAYER) |
714 | { |
701 | { |
715 | tmp->type = GOLEM; |
702 | tmp->type = GOLEM; |
716 | set_owner (tmp, op); |
703 | op->contr->golem = tmp; |
|
|
704 | /* give the player control of the golem */ |
717 | set_spell_skill (op, caster, spob, tmp); |
705 | set_spell_skill (op, caster, spob, tmp); |
718 | op->contr->ranges[range_golem] = tmp; |
|
|
719 | op->contr->golem_count = tmp->count; |
|
|
720 | /* give the player control of the golem */ |
|
|
721 | op->contr->shoottype = range_golem; |
|
|
722 | } |
|
|
723 | else |
|
|
724 | { |
706 | } |
725 | if (QUERY_FLAG (op, FLAG_FRIENDLY)) |
|
|
726 | { |
|
|
727 | object *owner = get_owner (op); |
|
|
728 | |
707 | |
729 | if (owner != NULL) |
|
|
730 | { /* For now, we transfer ownership */ |
|
|
731 | set_owner (tmp, owner); |
|
|
732 | tmp->attack_movement = PETMOVE; |
|
|
733 | add_friendly_object (tmp); |
|
|
734 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
735 | } |
|
|
736 | } |
|
|
737 | |
|
|
738 | SET_FLAG (tmp, FLAG_MONSTER); |
|
|
739 | } |
|
|
740 | |
|
|
741 | /* make the speed positive. */ |
|
|
742 | tmp->speed = FABS (tmp->speed); |
|
|
743 | |
|
|
744 | /* This sets the level dependencies on dam and hp for monsters */ |
708 | /* This sets the level dependencies on dam and hp for monsters */ |
745 | /* players can't cope with too strong summonings. */ |
709 | /* players can't cope with too strong summonings. */ |
746 | /* but monsters can. reserve these for players. */ |
710 | /* but monsters can. reserve these for players. */ |
747 | if (op->type == PLAYER) |
711 | if (op->type == PLAYER) |
748 | { |
712 | { |
749 | tmp->stats.hp += spob->duration + SP_level_duration_adjust (caster, spob); |
713 | tmp->stats.hp += spob->duration + SP_level_duration_adjust (caster, spob); |
… | |
… | |
752 | tmp->stats.dam += SP_level_dam_adjust (caster, spob); |
716 | tmp->stats.dam += SP_level_dam_adjust (caster, spob); |
753 | else |
717 | else |
754 | 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); |
755 | |
719 | |
756 | tmp->speed += .02 * SP_level_range_adjust (caster, spob); |
720 | tmp->speed += .02 * SP_level_range_adjust (caster, spob); |
757 | tmp->speed = MIN (tmp->speed, 1.0); |
721 | tmp->speed = min (tmp->speed, 1.0); |
758 | |
722 | |
759 | if (spob->attacktype) |
723 | if (spob->attacktype) |
760 | tmp->attacktype = spob->attacktype; |
724 | tmp->attacktype = spob->attacktype; |
761 | } |
725 | } |
762 | |
726 | |
… | |
… | |
766 | |
730 | |
767 | /* make experience increase in proportion to the strength. |
731 | /* make experience increase in proportion to the strength. |
768 | * 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 |
769 | * often the sp doubles and use that as the ratio. |
733 | * often the sp doubles and use that as the ratio. |
770 | */ |
734 | */ |
771 | 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); |
772 | tmp->speed_left = 0; |
736 | tmp->speed_left = 0; |
773 | tmp->direction = dir; |
737 | tmp->direction = dir; |
774 | |
738 | |
775 | /* Holy spell - some additional tailoring */ |
739 | /* Holy spell - some additional tailoring */ |
776 | if (god) |
740 | if (god) |
777 | { |
741 | { |
778 | object *tmp2; |
|
|
779 | |
|
|
780 | sprintf (buf, "%s of %s", &spob->name, &god->name); |
742 | char *buf = format ("%s of %s", &spob->name, &god->name); |
781 | buf[0] = toupper (buf[0]); |
743 | buf[0] = toupper (buf[0]); |
782 | |
744 | |
783 | for (tmp2 = tmp; tmp2; tmp2 = tmp2->more) |
745 | for (object *tmp2 = tmp; tmp2; tmp2 = tmp2->more) |
784 | tmp2->name = buf; |
746 | tmp2->name = buf; |
785 | |
747 | |
786 | tmp->attacktype |= god->attacktype; |
748 | tmp->attacktype |= god->attacktype; |
787 | memcpy (tmp->resist, god->resist, sizeof (tmp->resist)); |
749 | memcpy (tmp->resist, god->resist, sizeof (tmp->resist)); |
788 | tmp->race = god->race; |
750 | tmp->race = god->race; |
… | |
… | |
792 | if (!(tmp->attacktype & AT_PHYSICAL)) |
754 | if (!(tmp->attacktype & AT_PHYSICAL)) |
793 | tmp->attacktype |= AT_PHYSICAL; |
755 | tmp->attacktype |= AT_PHYSICAL; |
794 | } |
756 | } |
795 | |
757 | |
796 | insert_ob_in_map (tmp, tmp->map, op, 0); |
758 | insert_ob_in_map (tmp, tmp->map, op, 0); |
|
|
759 | |
797 | return 1; |
760 | return 1; |
798 | } |
761 | } |
799 | |
762 | |
800 | |
763 | |
801 | /*************************************************************************** |
764 | /*************************************************************************** |
… | |
… | |
807 | /* Returns a monster (chosen at random) that this particular player (and his |
770 | /* Returns a monster (chosen at random) that this particular player (and his |
808 | * god) find acceptable. This checks level, races allowed by god, etc |
771 | * god) find acceptable. This checks level, races allowed by god, etc |
809 | * to determine what is acceptable. |
772 | * to determine what is acceptable. |
810 | * This returns NULL if no match was found. |
773 | * This returns NULL if no match was found. |
811 | */ |
774 | */ |
812 | |
775 | static object * |
813 | object * |
|
|
814 | choose_cult_monster (object *pl, object *god, int summon_level) |
776 | choose_cult_monster (object *pl, object *god, int summon_level) |
815 | { |
777 | { |
816 | char buf[MAX_BUF]; |
778 | char buf[MAX_BUF]; |
817 | const char *race; |
779 | const char *race; |
818 | int racenr, mon_nr, i; |
780 | int racenr, mon_nr, i; |
… | |
… | |
872 | * a valid entry, assuming nothing is available and quit. |
834 | * a valid entry, assuming nothing is available and quit. |
873 | */ |
835 | */ |
874 | if (!mon_nr) |
836 | if (!mon_nr) |
875 | return NULL; |
837 | return NULL; |
876 | |
838 | |
877 | mon_nr = rndm (0, mon_nr - 1); |
839 | mon_nr = rndm (mon_nr - 1); |
878 | for (tobl = list->member; tobl; tobl = tobl->next) |
840 | for (tobl = list->member; tobl; tobl = tobl->next) |
879 | { |
841 | { |
880 | otmp = tobl->ob; |
842 | otmp = tobl->ob; |
881 | if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) |
843 | if (!otmp || !QUERY_FLAG (otmp, FLAG_MONSTER)) |
882 | continue; |
844 | continue; |
|
|
845 | |
883 | if (otmp->level <= summon_level && !mon_nr--) |
846 | if (otmp->level <= summon_level && !mon_nr--) |
884 | return otmp; |
847 | return otmp; |
885 | } |
848 | } |
|
|
849 | |
886 | /* This should not happen */ |
850 | /* This should not happen */ |
887 | LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n"); |
851 | LOG (llevDebug, "choose_cult_monster() mon_nr was set, but did not find a monster\n"); |
888 | return NULL; |
852 | return NULL; |
889 | } |
853 | } |
890 | |
854 | |
891 | int |
855 | int |
892 | summon_object (object *op, object *caster, object *spell_ob, int dir, const char *stringarg) |
856 | summon_object (object *op, object *caster, object *spell_ob, int dir, const char *stringarg) |
893 | { |
857 | { |
894 | sint16 x, y, nrof = 1, i; |
858 | int nrof = 1; |
895 | archetype *summon_arch; |
859 | archetype *summon_arch; |
896 | int ndir; |
860 | int ndir; |
897 | |
861 | |
898 | if (spell_ob->other_arch) |
862 | if (spell_ob->other_arch) |
899 | summon_arch = spell_ob->other_arch; |
863 | summon_arch = spell_ob->other_arch; |
900 | else if (spell_ob->randomitems) |
864 | else if (spell_ob->randomitems) |
901 | { |
865 | { |
902 | int level = caster_level (caster, spell_ob); |
866 | int level = casting_level (caster, spell_ob); |
903 | treasure *tr, *lasttr = NULL; |
867 | treasure *tr, *lasttr = NULL; |
904 | |
868 | |
905 | shstr_cmp sparam (stringarg); |
869 | shstr_cmp sparam (stringarg); |
906 | |
870 | |
907 | /* In old code, this was a very convoluted for statement, |
871 | /* In old code, this was a very convoluted for statement, |
908 | * with all the checks in the 'for' portion itself. Much |
872 | * with all the checks in the 'for' portion itself. Much |
909 | * more readable to break some of the conditions out. |
873 | * more readable to break some of the conditions out. |
910 | */ |
874 | */ |
911 | for (tr = spell_ob->randomitems->items; tr; tr = tr->next) |
875 | for (tr = spell_ob->randomitems->items; tr; tr = tr->next) |
912 | { |
876 | { |
|
|
877 | if (!tr->item) |
|
|
878 | continue; |
|
|
879 | |
913 | if (level < tr->magic) |
880 | if (level < tr->magic) |
914 | break; |
881 | break; |
915 | |
882 | |
916 | lasttr = tr; |
883 | lasttr = tr; |
917 | |
884 | |
918 | if (tr->item->name == sparam) |
885 | if (tr->item->archname == sparam) |
919 | break; |
|
|
920 | |
|
|
921 | if (!tr->next || !tr->next->item) |
|
|
922 | break; |
886 | break; |
923 | } |
887 | } |
924 | |
888 | |
925 | if (!lasttr) |
889 | if (!lasttr) |
926 | { |
890 | { |
… | |
… | |
928 | new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters."); |
892 | new_draw_info (NDI_UNIQUE, 0, op, "The spell fails to summon any monsters."); |
929 | return 0; |
893 | return 0; |
930 | } |
894 | } |
931 | |
895 | |
932 | summon_arch = lasttr->item; |
896 | summon_arch = lasttr->item; |
933 | nrof = lasttr->nrof; |
897 | nrof = lasttr->nrof; |
934 | } |
898 | } |
935 | else if (spell_ob->race && !strcmp (spell_ob->race, "GODCULTMON")) |
899 | else if (spell_ob->race == shstr_GODCULTMON) |
936 | { |
900 | { |
937 | object *god = find_god (determine_god (op)), *mon, *owner; |
901 | object *god = find_god (determine_god (op)), *mon, *owner; |
938 | int summon_level, tries; |
902 | int summon_level, tries; |
939 | |
903 | |
940 | if (!god && ((owner = get_owner (op)) != NULL)) |
904 | if (!god && ((owner = op->owner) != NULL)) |
941 | god = find_god (determine_god (owner)); |
905 | god = find_god (determine_god (owner)); |
942 | |
906 | |
943 | /* If we can't find a god, can't get what monster to summon */ |
907 | /* If we can't find a god, can't get what monster to summon */ |
944 | if (!god) |
908 | if (!god) |
945 | return 0; |
909 | return 0; |
… | |
… | |
949 | 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); |
950 | return 0; |
914 | return 0; |
951 | } |
915 | } |
952 | |
916 | |
953 | /* the summon level */ |
917 | /* the summon level */ |
954 | summon_level = caster_level (caster, spell_ob); |
918 | summon_level = casting_level (caster, spell_ob); |
955 | if (summon_level == 0) |
919 | if (summon_level == 0) |
956 | summon_level = 1; |
920 | summon_level = 1; |
957 | |
921 | |
958 | tries = 0; |
922 | tries = 0; |
959 | do |
923 | do |
… | |
… | |
968 | ndir = dir; |
932 | ndir = dir; |
969 | |
933 | |
970 | if (!ndir) |
934 | if (!ndir) |
971 | 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); |
972 | |
936 | |
973 | if (ndir == -1 || 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])) |
974 | { |
938 | { |
975 | ndir = -1; |
939 | ndir = -1; |
976 | if (++tries == 5) |
940 | if (++tries == 5) |
977 | { |
941 | { |
978 | 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."); |
… | |
… | |
999 | { |
963 | { |
1000 | new_draw_info (NDI_UNIQUE, 0, op, "There is no monsters available for summoning."); |
964 | new_draw_info (NDI_UNIQUE, 0, op, "There is no monsters available for summoning."); |
1001 | return 0; |
965 | return 0; |
1002 | } |
966 | } |
1003 | |
967 | |
1004 | for (i = 1; i <= nrof; i++) |
968 | for (int i = 1; i <= nrof; i++) |
1005 | { |
969 | { |
1006 | archetype *atmp; |
|
|
1007 | object *prev = NULL, *head = NULL, *tmp; |
970 | object *prev = NULL, *head = NULL, *tmp; |
1008 | |
971 | |
1009 | if (dir) |
972 | if (dir) |
1010 | { |
973 | { |
1011 | ndir = dir; |
974 | ndir = dir; |
1012 | dir = absdir (dir + 1); |
975 | dir = absdir (dir + 1); |
1013 | } |
976 | } |
1014 | else |
977 | else |
1015 | ndir = find_free_spot (&summon_arch->clone, op->map, op->x, op->y, 1, SIZEOFFREE); |
978 | ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE); |
1016 | |
979 | |
1017 | if (ndir > 0) |
|
|
1018 | { |
|
|
1019 | x = freearr_x[ndir]; |
980 | sint16 x = freearr_x [ndir]; |
1020 | y = freearr_y[ndir]; |
981 | sint16 y = freearr_y [ndir]; |
1021 | } |
|
|
1022 | |
982 | |
1023 | if (ndir == -1 || ob_blocked (&summon_arch->clone, op->map, op->x + x, op->y + y)) |
983 | if (ndir < 0 || summon_arch->blocked (op->map, op->x + x, op->y + y)) |
1024 | { |
984 | { |
1025 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
985 | new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); |
1026 | if (nrof > 1) |
986 | if (nrof > 1) |
1027 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
987 | new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); |
1028 | |
988 | |
1029 | return nrof > 1; |
989 | return nrof > 1; |
1030 | } |
990 | } |
1031 | |
991 | |
1032 | for (atmp = summon_arch; atmp != NULL; atmp = atmp->more) |
992 | for (archetype *atmp = summon_arch; atmp; atmp = (archetype *)atmp->more) |
1033 | { |
993 | { |
1034 | tmp = arch_to_object (atmp); |
994 | tmp = atmp->instance (); |
1035 | if (atmp == summon_arch) |
995 | if (atmp == summon_arch) |
1036 | { |
996 | { |
1037 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
997 | if (QUERY_FLAG (tmp, FLAG_MONSTER)) |
1038 | { |
998 | { |
1039 | set_owner (tmp, op); |
999 | tmp->set_owner (op); |
1040 | set_spell_skill (op, caster, spell_ob, tmp); |
1000 | set_spell_skill (op, caster, spell_ob, tmp); |
1041 | tmp->enemy = op->enemy; |
1001 | tmp->enemy = op->enemy; |
1042 | tmp->type = 0; |
1002 | tmp->type = 0; |
1043 | CLEAR_FLAG (tmp, FLAG_SLEEP); |
1003 | CLEAR_FLAG (tmp, FLAG_SLEEP); |
1044 | |
1004 | |
1045 | if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) |
1005 | if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) |
1046 | { |
1006 | { |
1047 | /* If this is not set, we make it friendly */ |
1007 | /* If this is not set, we make it friendly */ |
1048 | if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) |
1008 | if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) |
1049 | { |
1009 | { |
1050 | SET_FLAG (tmp, FLAG_FRIENDLY); |
|
|
1051 | add_friendly_object (tmp); |
1010 | add_friendly_object (tmp); |
1052 | tmp->stats.exp = 0; |
1011 | tmp->stats.exp = 0; |
1053 | |
1012 | |
1054 | if (spell_ob->attack_movement) |
1013 | if (spell_ob->attack_movement) |
1055 | tmp->attack_movement = spell_ob->attack_movement; |
1014 | tmp->attack_movement = spell_ob->attack_movement; |
1056 | |
1015 | |
1057 | if (get_owner (op)) |
1016 | if (op->owner) |
1058 | set_owner (tmp, get_owner (op)); |
1017 | tmp->set_owner (op->owner); |
1059 | } |
1018 | } |
1060 | } |
1019 | } |
1061 | } |
1020 | } |
1062 | |
1021 | |
1063 | if (tmp->speed > MIN_ACTIVE_SPEED) |
1022 | if (tmp->speed > MIN_ACTIVE_SPEED) |
… | |
… | |
1071 | tmp->head = head; |
1030 | tmp->head = head; |
1072 | prev->more = tmp; |
1031 | prev->more = tmp; |
1073 | } |
1032 | } |
1074 | |
1033 | |
1075 | prev = tmp; |
1034 | prev = tmp; |
1076 | tmp->x = op->x + x + tmp->arch->clone.x; |
1035 | tmp->x = op->x + x + tmp->arch->x; |
1077 | tmp->y = op->y + y + tmp->arch->clone.y; |
1036 | tmp->y = op->y + y + tmp->arch->y; |
1078 | tmp->map = op->map; |
1037 | tmp->map = op->map; |
1079 | } |
1038 | } |
1080 | |
1039 | |
1081 | head->direction = freedir[ndir]; |
1040 | head->direction = freedir[ndir]; |
1082 | head->stats.exp = 0; |
1041 | head->stats.exp = 0; |
1083 | head = insert_ob_in_map (head, head->map, op, 0); |
1042 | head = insert_ob_in_map (head, head->map, op, 0); |
1084 | |
1043 | |
1085 | if (head && head->randomitems) |
1044 | if (head && head->randomitems) |
1086 | { |
1045 | { |
1087 | object *tmp; |
|
|
1088 | |
|
|
1089 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
1046 | create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); |
|
|
1047 | |
1090 | for (tmp = head->inv; tmp; tmp = tmp->below) |
1048 | for (object *tmp = head->inv; tmp; tmp = tmp->below) |
1091 | if (!tmp->nrof) |
|
|
1092 | SET_FLAG (tmp, FLAG_NO_DROP); |
1049 | SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH); |
1093 | } |
1050 | } |
1094 | } /* for i < nrof */ |
1051 | } /* for i < nrof */ |
1095 | |
1052 | |
1096 | return 1; |
1053 | return 1; |
1097 | } |
|
|
1098 | |
|
|
1099 | /* recursively look through the owner property of objects until the real owner |
|
|
1100 | is found */ |
|
|
1101 | object * |
|
|
1102 | get_real_owner (object *ob) |
|
|
1103 | { |
|
|
1104 | object *realowner = ob; |
|
|
1105 | |
|
|
1106 | if (realowner == NULL) |
|
|
1107 | return NULL; |
|
|
1108 | |
|
|
1109 | while (get_owner (realowner) != NULL) |
|
|
1110 | { |
|
|
1111 | realowner = get_owner (realowner); |
|
|
1112 | } |
|
|
1113 | return realowner; |
|
|
1114 | } |
1054 | } |
1115 | |
1055 | |
1116 | /* determines if checks so pets don't attack players or other pets should be |
1056 | /* determines if checks so pets don't attack players or other pets should be |
1117 | overruled by the arena petmode */ |
1057 | overruled by the arena petmode */ |
1118 | int |
1058 | int |
… | |
… | |
1124 | if ((target == NULL) || (pet == NULL) || (owner == NULL)) |
1064 | if ((target == NULL) || (pet == NULL) || (owner == NULL)) |
1125 | return 0; |
1065 | return 0; |
1126 | |
1066 | |
1127 | /* get the owners of itself and the target, this is to deal with pets of |
1067 | /* get the owners of itself and the target, this is to deal with pets of |
1128 | pets */ |
1068 | pets */ |
1129 | rowner = get_real_owner (owner); |
1069 | rowner = owner->outer_owner (); |
1130 | if (target->type != PLAYER) |
1070 | towner = target->is_player () ? 0 : target->outer_owner (); |
1131 | { |
|
|
1132 | towner = get_real_owner (target); |
|
|
1133 | } |
|
|
1134 | else |
|
|
1135 | { |
|
|
1136 | towner = 0; |
|
|
1137 | } |
|
|
1138 | |
1071 | |
1139 | /* if the pet has now owner, exit with error */ |
1072 | /* if the pet has now owner, exit with error */ |
1140 | if (rowner == NULL) |
1073 | if (!rowner) |
1141 | { |
1074 | { |
1142 | LOG (llevError, "Pet has no owner.\n"); |
1075 | LOG (llevError, "Pet has no owner.\n"); |
1143 | return 0; |
1076 | return 0; |
1144 | } |
1077 | } |
1145 | |
1078 | |
1146 | /* if the target is not a player, and has no owner, we shouldn't be here |
1079 | /* if the target is not a player, and has no owner, we shouldn't be here |
1147 | */ |
1080 | */ |
1148 | if ((towner == NULL) && (target->type != PLAYER)) |
1081 | if (!towner && !target->is_player ()) |
1149 | { |
1082 | { |
1150 | LOG (llevError, "Target is not a player but has no owner. We should not be here.\n"); |
1083 | LOG (llevError, "Target is not a player but has no owner. We should not be here.\n"); |
1151 | return 0; |
1084 | return 0; |
1152 | } |
1085 | } |
1153 | |
1086 | |
1154 | /* make sure that the owner is a player */ |
1087 | /* make sure that the owner is a player */ |
1155 | if (rowner->type != PLAYER) |
1088 | if (!rowner->is_player ()) |
1156 | return 0; |
1089 | return 0; |
1157 | |
1090 | |
1158 | /* abort if the petmode is not arena */ |
1091 | /* abort if the petmode is not arena */ |
1159 | if (rowner->contr->petmode != pet_arena) |
1092 | if (rowner->contr->petmode != pet_arena) |
1160 | return 0; |
1093 | return 0; |
… | |
… | |
1162 | /* abort if the pet, it's owner, or the target is not on battleground */ |
1095 | /* abort if the pet, it's owner, or the target is not on battleground */ |
1163 | if (!(op_on_battleground (pet, NULL, NULL) && op_on_battleground (owner, NULL, NULL) && op_on_battleground (target, NULL, NULL))) |
1096 | if (!(op_on_battleground (pet, NULL, NULL) && op_on_battleground (owner, NULL, NULL) && op_on_battleground (target, NULL, NULL))) |
1164 | return 0; |
1097 | return 0; |
1165 | |
1098 | |
1166 | /* if the target is a monster, make sure it's owner is not the same */ |
1099 | /* if the target is a monster, make sure it's owner is not the same */ |
1167 | if ((target->type != PLAYER) && (rowner == towner)) |
1100 | if (!target->is_player () && rowner == towner) |
1168 | return 0; |
1101 | return 0; |
1169 | |
1102 | |
1170 | /* check if the target is a player which affects how it will handle |
1103 | /* check if the target is a player which affects how it will handle |
1171 | parties */ |
1104 | parties */ |
1172 | if (target->type != PLAYER) |
1105 | if (!target->is_player ()) |
1173 | { |
1106 | { |
1174 | /* if the target is owned by a player make sure than make sure |
1107 | /* if the target is owned by a player make sure than make sure |
1175 | it's not in the same party */ |
1108 | it's not in the same party */ |
1176 | if ((towner->type == PLAYER) && (rowner->contr->party != NULL)) |
1109 | if (towner->is_player () && rowner->contr->party) |
1177 | { |
|
|
1178 | if (rowner->contr->party == towner->contr->party) |
1110 | if (rowner->contr->party == towner->contr->party) |
1179 | return 0; |
1111 | return 0; |
1180 | } |
|
|
1181 | } |
1112 | } |
1182 | else |
1113 | else |
1183 | { |
1114 | { |
1184 | /* if the target is a player make sure than make sure it's not |
1115 | /* if the target is a player make sure than make sure it's not |
1185 | in the same party */ |
1116 | in the same party */ |
1186 | if (rowner->contr->party != NULL) |
1117 | if (rowner->contr->party) |
1187 | { |
|
|
1188 | if (rowner->contr->party == target->contr->party) |
1118 | if (rowner->contr->party == target->contr->party) |
1189 | return 0; |
1119 | return 0; |
1190 | } |
|
|
1191 | } |
1120 | } |
1192 | |
1121 | |
1193 | return 1; |
1122 | return 1; |
1194 | } |
1123 | } |
|
|
1124 | |