ViewVC Help
View File | Revision Log | Show Annotations | Download File
/cvs/deliantra/server/server/pets.C
(Generate patch)

Comparing deliantra/server/server/pets.C (file contents):
Revision 1.2 by root, Tue Aug 29 08:01:37 2006 UTC vs.
Revision 1.50 by root, Thu Jan 1 15:43:35 2009 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines