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.9 by root, Thu Sep 14 22:34:04 2006 UTC vs.
Revision 1.48 by root, Mon Sep 29 10:31:32 2008 UTC

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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines