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.19 by root, Wed Jan 3 20:32:13 2007 UTC vs.
Revision 1.38 by root, Sun Jul 1 05:00:20 2007 UTC

1/* 1/*
2 CrossFire, A Multiplayer game for X-windows 2 * This file is part of Crossfire TRT, the Roguelike Realtime MORPG.
3 3 *
4 * Copyright (©) 2005,2006,2007 Marc Alexander Lehmann / Robin Redeker / the Crossfire TRT 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 * Crossfire TRT 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 at <crossfire@schmorp.de> 21 * The authors can be reached via e-mail to <crossfire@schmorp.de>
22*/ 22 */
23 23
24#include <global.h> 24#include <global.h>
25#include <sproto.h> 25#include <sproto.h>
26 26
27/* given that 'pet' is a friendly object, this function returns a 27/* given that 'pet' is a friendly object, this function returns a
41 int mflags; 41 int mflags;
42 42
43 attacker = pet->attacked_by; /*pointer to attacking enemy */ 43 attacker = pet->attacked_by; /*pointer to attacking enemy */
44 pet->attacked_by = NULL; /*clear this, since we are dealing with it */ 44 pet->attacked_by = NULL; /*clear this, since we are dealing with it */
45 45
46 if ((owner = pet->owner) != NULL) 46 if (owner = pet->owner)
47 { 47 {
48 /* If the owner has turned on the pet, make the pet 48 /* If the owner has turned on the pet, make the pet
49 * unfriendly. 49 * unfriendly.
50 */ 50 */
51 if ((check_enemy (owner, rv)) == pet) 51 if (check_enemy (owner, rv) == pet)
52 { 52 {
53 CLEAR_FLAG (pet, FLAG_FRIENDLY);
54 remove_friendly_object (pet); 53 remove_friendly_object (pet);
55 pet->attack_movement &= ~PETMOVE; 54 pet->attack_movement &= ~PETMOVE;
56 return owner; 55 return owner;
57 } 56 }
58 } 57 }
59 else 58 else
60 { 59 {
61 /* else the owner is no longer around, so the 60 /* else the owner is no longer around, so the
62 * pet no longer needs to be friendly. 61 * pet no longer needs to be friendly.
63 */ 62 */
64 CLEAR_FLAG (pet, FLAG_FRIENDLY);
65 remove_friendly_object (pet); 63 remove_friendly_object (pet);
66 pet->attack_movement &= ~PETMOVE; 64 pet->attack_movement &= ~PETMOVE;
67 return NULL; 65 return 0;
68 } 66 }
67
69 /* 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 */
70 if (!on_same_map (pet, owner)) 69 //if (!on_same_map (pet, owner))
71 return NULL; 70 // return 0;
72 71
73 /* 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 */
74 if ((tmp = check_enemy (pet, rv)) != NULL) 73 if (tmp = check_enemy (pet, rv))
75 { 74 {
76 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))
77 /* without this check, you can actually get pets with 76 /* without this check, you can actually get pets with
78 * enemy set to owner! 77 * enemy set to owner!
79 */ 78 */
80 pet->enemy = NULL; 79 pet->enemy = 0;
81 else 80 else
82 return tmp; 81 return tmp;
83 } 82 }
84 83
85 get_search_arr (search_arr); 84 get_search_arr (search_arr);
87 if (owner->type == PLAYER && owner->contr->petmode > pet_normal) 86 if (owner->type == PLAYER && owner->contr->petmode > pet_normal)
88 { 87 {
89 if (owner->contr->petmode == pet_sad) 88 if (owner->contr->petmode == pet_sad)
90 { 89 {
91 tmp = find_nearest_living_creature (pet); 90 tmp = find_nearest_living_creature (pet);
92 if (tmp != NULL) 91 if (tmp != 0)
93 { 92 {
94 get_rangevector (pet, tmp, rv, 0); 93 get_rangevector (pet, tmp, rv, 0);
95 if (check_enemy (pet, rv) != NULL) 94 if (check_enemy (pet, rv) != 0)
96 return tmp; 95 return tmp;
97 else 96 else
98 pet->enemy = NULL; 97 pet->enemy = 0;
99 } 98 }
100 /* if we got here we have no enemy */ 99 /* if we got here we have no enemy */
101 /* we return NULL to avoid heading back to the owner */ 100 /* we return 0 to avoid heading back to the owner */
102 pet->enemy = NULL; 101 pet->enemy = 0;
103 return NULL; 102 return 0;
104 } 103 }
105 } 104 }
106 105
107 /* Since the pet has no existing enemy, look for anything nasty 106 /* Since the pet has no existing enemy, look for anything nasty
108 * 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)
109 */ 109 */
110 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
111 for (i = 0; i < SIZEOFFREE; i++) 115 for (i = 0; i < SIZEOFFREE; i++)
112 { 116 {
113 x = owner->x + freearr_x[search_arr[i]]; 117 x = owner->x + freearr_x[search_arr[i]];
114 y = owner->y + freearr_y[search_arr[i]]; 118 y = owner->y + freearr_y[search_arr[i]];
115 nm = owner->map; 119 nm = owner->map;
116 /* Only look on the space if there is something alive there. */ 120 /* Only look on the space if there is something alive there. */
117 mflags = get_map_flags (nm, &nm, x, y, &x, &y); 121 mflags = get_map_flags (nm, &nm, x, y, &x, &y);
118 122
119 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) 123 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE)
120 { 124 {
121 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)
122 {
123 object *tmp2 = tmp->head == NULL ? tmp : tmp->head;
124
125 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) &&
126 (tmp2->type != PLAYER)) ||
127 should_arena_attack (pet, owner, tmp2))
128 && !QUERY_FLAG (tmp2, FLAG_UNAGGRESSIVE) && tmp2 != pet && tmp2 != owner && can_detect_enemy (pet, tmp2, rv))
129 { 126 {
127 object *tmp2 = tmp->head == 0 ? tmp : tmp->head;
130 128
131 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))
132 { 133 {
134
135 if (!can_see_enemy (pet, tmp2))
136 {
133 if (tmp3 != NULL) 137 if (tmp3 != 0)
134 tmp3 = tmp2; 138 tmp3 = tmp2;
135 } 139 }
136 else
137 {
138 pet->enemy = tmp2;
139 if (check_enemy (pet, rv) != NULL)
140 return tmp2;
141 else 140 else
141 {
142 pet->enemy = tmp2;
143 if (check_enemy (pet, rv) != 0)
144 return tmp2;
145 else
142 pet->enemy = NULL; 146 pet->enemy = 0;
143 } 147 }
144 } /* if this is a valid enemy */ 148 } /* if this is a valid enemy */
145 } /* for objects on this space */ 149 } /* for objects on this space */
146 } /* if there is something living on this space */ 150 } /* if there is something living on this space */
147 } /* for loop of spaces around the owner */ 151 } /* for loop of spaces around the owner */
148 152
149 /* 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
150 see, take what we have */ 154 see, take what we have */
151 if (tmp3 != NULL) 155 if (tmp3 != 0)
152 { 156 {
153 pet->enemy = tmp3; 157 pet->enemy = tmp3;
154 if (check_enemy (pet, rv) != NULL) 158 if (check_enemy (pet, rv) != 0)
155 return tmp3; 159 return tmp3;
156 else 160 else
157 pet->enemy = NULL; 161 pet->enemy = 0;
162 }
158 } 163 }
159 164
160 /* 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 */
161 if (attacker) 166 if (attacker)
162 { 167 {
164 /* or otherwise non-hostile, and is an appropriate target */ 169 /* or otherwise non-hostile, and is an appropriate target */
165 if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker)) 170 if (!QUERY_FLAG (attacker, FLAG_FRIENDLY) && on_same_map (pet, attacker))
166 { 171 {
167 pet->enemy = attacker; 172 pet->enemy = attacker;
168 173
169 if (check_enemy (pet, rv) != NULL) 174 if (check_enemy (pet, rv) != 0)
170 return attacker; 175 return attacker;
171 else 176 else
172 pet->enemy = NULL; 177 pet->enemy = 0;
173 } 178 }
174 } 179 }
175 180
176 /* 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!.
177 * 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
178 * 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
179 * the same as the code that looks around the owner. 184 * the same as the code that looks around the owner.
180 */ 185 */
181 if (owner->type == PLAYER && owner->contr->petmode != pet_defend) 186 if (owner->type == PLAYER && owner->contr->petmode != pet_defend)
182 { 187 {
183 tmp3 = NULL; 188 tmp3 = 0;
184 for (i = 0; i < SIZEOFFREE; i++) 189 for (i = 0; i < SIZEOFFREE; i++)
185 { 190 {
186 x = pet->x + freearr_x[search_arr[i]]; 191 x = pet->x + freearr_x[search_arr[i]];
187 y = pet->y + freearr_y[search_arr[i]]; 192 y = pet->y + freearr_y[search_arr[i]];
188 nm = pet->map; 193 nm = pet->map;
189 /* Only look on the space if there is something alive there. */ 194 /* Only look on the space if there is something alive there. */
190 mflags = get_map_flags (nm, &nm, x, y, &x, &y); 195 mflags = get_map_flags (nm, &nm, x, y, &x, &y);
191 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE) 196 if (!(mflags & P_OUT_OF_MAP) && mflags & P_IS_ALIVE)
192 { 197 {
193 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)
194 { 199 {
195 object *tmp2 = tmp->head == NULL ? tmp : tmp->head; 200 object *tmp2 = tmp->head == 0 ? tmp : tmp->head;
196 201
197 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) && 202 if (QUERY_FLAG (tmp2, FLAG_ALIVE) && ((!QUERY_FLAG (tmp2, FLAG_FRIENDLY) &&
198 (tmp2->type != PLAYER)) || 203 (tmp2->type != PLAYER)) ||
199 should_arena_attack (pet, owner, tmp2)) 204 should_arena_attack (pet, owner, tmp2))
200 && !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))
201 { 206 {
202 207
203 if (!can_see_enemy (pet, tmp2)) 208 if (!can_see_enemy (pet, tmp2))
204 { 209 {
205 if (tmp3 != NULL) 210 if (tmp3 != 0)
206 tmp3 = tmp2; 211 tmp3 = tmp2;
207 } 212 }
208 else 213 else
209 { 214 {
210 pet->enemy = tmp2; 215 pet->enemy = tmp2;
211 if (check_enemy (pet, rv) != NULL) 216 if (check_enemy (pet, rv) != 0)
212 return tmp2; 217 return tmp2;
213 else 218 else
214 pet->enemy = NULL; 219 pet->enemy = 0;
215 } 220 }
216 } /* make sure we can get to the bugger */ 221 } /* make sure we can get to the bugger */
217 } /* for objects on this space */ 222 } /* for objects on this space */
218 } /* if there is something living on this space */ 223 } /* if there is something living on this space */
219 } /* 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 }
220 } /* pet in defence mode */ 236 } /* pet in defence mode */
221 237
222 /* fine, we went through the whole loop and didn't find one we could 238 object *enemy = check_enemy (pet, rv);
223 see, take what we have */ 239 // we have a summoned pet here and the owners enemy isn't set or can't
224 if (tmp3 != NULL) 240 // be reached => search for a player around us and set it as our new enemy!!
225 { 241 if (!enemy && pet->owner && pet->owner->type != PLAYER)
226 pet->enemy = tmp3; 242 enemy = get_nearest_player (pet);
227 if (check_enemy (pet, rv) != NULL)
228 return tmp3;
229 else
230 pet->enemy = NULL;
231 }
232 243
233 /* Didn't find anything - return the owner's enemy or NULL */ 244 /* Didn't find anything - return the owner's enemy or 0 */
234 return check_enemy (pet, rv); 245 return enemy;
235} 246}
236 247
237void 248void
238terminate_all_pets (object *owner) 249terminate_all_pets (object *owner)
239{ 250{
240 objectlink *obl, *next; 251 objectlink *obl, *next;
241 252
242 for (obl = first_friendly_object; obl != NULL; obl = next) 253 for (obl = first_friendly_object; obl; obl = next)
243 { 254 {
244 object *ob = obl->ob; 255 object *ob = obl->ob;
245
246 next = obl->next; 256 next = obl->next;
257
247 if (ob->owner == owner) 258 if (ob->owner == owner)
248 {
249 if (!QUERY_FLAG (ob, FLAG_REMOVED))
250 ob->remove ();
251 remove_friendly_object (ob);
252 ob->destroy (); 259 ob->destroy ();
253 }
254 } 260 }
255} 261}
256 262
257/* 263/*
258 * Unfortunately, sometimes, the owner of a pet is in the 264 * Unfortunately, sometimes, the owner of a pet is in the
266remove_all_pets (maptile *map) 272remove_all_pets (maptile *map)
267{ 273{
268 objectlink *obl, *next; 274 objectlink *obl, *next;
269 object *owner; 275 object *owner;
270 276
271 for (obl = first_friendly_object; obl != NULL; obl = next) 277 for (obl = first_friendly_object; obl; obl = next)
272 { 278 {
273 next = obl->next; 279 next = obl->next;
274 if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) && 280
275 (owner = obl->ob->owner) != 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))
276 { 285 {
277 /* follow owner checks map status for us */ 286 /* follow owner checks map status for us */
278 follow_owner (obl->ob, owner); 287 follow_owner (obl->ob, owner);
279 } 288 }
280 } 289 }
281} 290}
282 291
283int 292int
284follow_owner (object *ob, object *owner) 293follow_owner (object *ob, object *owner)
285{ 294{
286 object *tmp; 295 if (owner->flag [FLAG_REMOVED])
287 int dir; 296 return 0; // do nothing if the owner is removed
288
289 if (!QUERY_FLAG (ob, FLAG_REMOVED))
290 ob->remove ();
291
292 if (owner->map == NULL)
293 {
294 LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name);
295 goto fail;
296 }
297 if (owner->map->in_memory != MAP_IN_MEMORY) 297 else if (!owner->map || owner->map->in_memory != MAP_IN_MEMORY)
298 {
299 LOG (llevError, "Owner of the pet not on a map in memory!?\n"); 298 LOG (llevError, "owner '%s' of the pet '%s' not on a map in memory!?\n", &owner->name, &ob->name);
300 goto fail; 299 else
301 } 300 {
302
303 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);
304 302
305 if (dir == -1) 303 if (dir >= 0)
306 {
307 LOG (llevMonster, "No space for pet to follow, freeing %s.\n", &ob->name);
308 goto fail;
309 }
310 for (tmp = ob; tmp != NULL; tmp = tmp->more)
311 {
312 tmp->x = owner->x + freearr_x[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x);
313 tmp->y = owner->y + freearr_y[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
314 tmp->map = owner->map;
315 if (OUT_OF_REAL_MAP (tmp->map, tmp->x, tmp->y))
316 {
317 tmp->map = get_map_from_coord (tmp->map, &tmp->x, &tmp->y);
318 } 304 {
319 } 305 owner->map->insert (ob, owner->x + freearr_x[dir], owner->y + freearr_y[dir]);
320 insert_ob_in_map (ob, ob->map, NULL, 0); 306
321 if (owner->type == PLAYER) /* Uh, I hope this is always true... */ 307 if (owner->type == PLAYER) /* Uh, I hope this is always true... */
322 new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); 308 new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you");
323 309
324 return 0; 310 return 0;
311 }
312 }
325 313
326fail:
327 remove_friendly_object (ob);
328 ob->destroy (); 314 ob->destroy ();
329
330 return 1; 315 return 1;
331} 316}
332 317
333void 318void
334pet_move (object *ob) 319pet_move (object *ob)
335{ 320{
336 int dir, i; 321 int dir = 0, i;
337 sint16 dx, dy; 322 sint16 dx, dy;
338 object *ob2, *owner; 323 object *ob2, *owner;
339 maptile *m; 324 maptile *m;
340 325
341 /* Check to see if player pulled out */ 326 /* Check to see if player pulled out */
342 if ((owner = ob->owner) == NULL) 327 if ((owner = ob->owner) == NULL)
343 { 328 {
344 ob->remove (); /* Will be freed when returning */
345 remove_friendly_object (ob);
346 ob->destroy (); 329 ob->destroy ();
347 LOG (llevMonster, "Pet: no owner, leaving.\n"); 330 LOG (llevMonster, "Pet: no owner, leaving.\n");
348 return; 331 return;
349 } 332 }
350 333
351 /* move monster into the owners map if not in the same map */ 334 /* move monster into the owners map if not in the same map
352 if (!on_same_map (ob, owner)) 335 * except when the owner is removed.
336 */
337 if (!on_same_map (ob, owner) && !owner->flag [FLAG_REMOVED])
353 { 338 {
354 follow_owner (ob, owner); 339 follow_owner (ob, owner);
355 return; 340 return;
356 } 341 }
357 /* Calculate Direction */ 342 /* Calculate Direction */
370 continue; 355 continue;
371 else 356 else
372 break; 357 break;
373 } 358 }
374 } 359 }
375 else 360 else if (!owner->flag [FLAG_REMOVED]) // only get vector to owner when owner not removed
376 { 361 {
377 struct rv_vector rv; 362 struct rv_vector rv;
378 363
379 get_rangevector (ob, ob->owner, &rv, 0); 364 get_rangevector (ob, ob->owner, &rv, 0);
380 dir = rv.direction; 365 dir = rv.direction;
430 return; 415 return;
431 } 416 }
432 } 417 }
433 } 418 }
434 /* Try a different course */ 419 /* Try a different course */
435 dir = absdir (dir + 4 - (RANDOM () % 5) - (RANDOM () % 5)); 420 dir = absdir (dir + 4 - (rndm (5)) - (rndm (5)));
436 (void) move_ob (ob, dir, ob); 421 (void) move_ob (ob, dir, ob);
437 } 422 }
438 return; 423 return;
439} 424}
440 425
451 * is_golem is to note that this is a golem spell. 436 * is_golem is to note that this is a golem spell.
452 */ 437 */
453object * 438object *
454fix_summon_pet (archetype *at, object *op, int dir, int is_golem) 439fix_summon_pet (archetype *at, object *op, int dir, int is_golem)
455{ 440{
456 archetype *atmp;
457 object *tmp = NULL, *prev = NULL, *head = NULL; 441 object *tmp = NULL, *prev = NULL, *head = NULL;
458 442
459 for (atmp = at; atmp; atmp = atmp->more) 443 for (archetype *atmp = at; atmp; atmp = (archetype *)atmp->more)
460 { 444 {
461 tmp = arch_to_object (atmp); 445 tmp = arch_to_object (atmp);
462 446
463 if (atmp == at) 447 if (atmp == at)
464 { 448 {
465 if (!is_golem) 449 if (!is_golem)
466 SET_FLAG (tmp, FLAG_MONSTER); 450 SET_FLAG (tmp, FLAG_MONSTER);
467 451
468 tmp->set_owner (op); 452 tmp->set_owner (op);
453
469 if (op->type == PLAYER) 454 if (op->type == PLAYER)
470 { 455 {
471 tmp->stats.exp = 0; 456 tmp->stats.exp = 0;
472 add_friendly_object (tmp); 457 add_friendly_object (tmp);
473 SET_FLAG (tmp, FLAG_FRIENDLY);
474 if (is_golem) 458 if (is_golem)
475 CLEAR_FLAG (tmp, FLAG_MONSTER); 459 CLEAR_FLAG (tmp, FLAG_MONSTER);
476 } 460 }
477 else 461 else
478 { 462 {
483 if (owner) 467 if (owner)
484 { /* For now, we transfer ownership */ 468 { /* For now, we transfer ownership */
485 tmp->set_owner (owner); 469 tmp->set_owner (owner);
486 tmp->attack_movement = PETMOVE; 470 tmp->attack_movement = PETMOVE;
487 add_friendly_object (tmp); 471 add_friendly_object (tmp);
488 SET_FLAG (tmp, FLAG_FRIENDLY);
489 } 472 }
490 } 473 }
491 } 474 }
492 475
493 if (op->type != PLAYER || !is_golem) 476 if (op->type != PLAYER || !is_golem)
503 } 486 }
504 487
505 if (!head) 488 if (!head)
506 head = tmp; 489 head = tmp;
507 490
508 tmp->x = op->x + freearr_x[dir] + tmp->arch->clone.x; 491 tmp->x = op->x + freearr_x[dir] + tmp->arch->x;
509 tmp->y = op->y + freearr_y[dir] + tmp->arch->clone.y; 492 tmp->y = op->y + freearr_y[dir] + tmp->arch->y;
510 tmp->map = op->map; 493 tmp->map = op->map;
511 494
512 if (tmp->invisible) 495 if (tmp->invisible)
513 tmp->invisible = 0; 496 tmp->invisible = 0;
514 497
546 object *tmp; 529 object *tmp;
547 530
548 if (QUERY_FLAG (op, FLAG_MONSTER)) 531 if (QUERY_FLAG (op, FLAG_MONSTER))
549 return; /* Has already been moved */ 532 return; /* Has already been moved */
550 533
551 if (op->owner == NULL) 534 if (!op->owner)
552 { 535 {
553 LOG (llevDebug, "Golem without owner destructed.\n"); 536 LOG (llevDebug, "Golem without owner destructed.\n");
554 op->remove (); 537 op->remove ();
555 op->destroy (); 538 op->destroy ();
556 return; 539 return;
564 if (--op->stats.hp < 0) 547 if (--op->stats.hp < 0)
565 { 548 {
566 if (op->msg) 549 if (op->msg)
567 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg); 550 new_draw_info (NDI_UNIQUE, 0, op->owner, op->msg);
568 551
569 op->owner->contr->ranges[range_golem] = 0;
570 remove_friendly_object (op);
571 op->remove ();
572 op->destroy (); 552 op->destroy ();
573 return; 553 return;
574 } 554 }
575 555
576 /* Do golem attacks/movement for single & multisq golems. 556 /* Do golem attacks/movement for single & multisq golems.
608 * but since we are not trying to dereferance that pointer, 588 * but since we are not trying to dereferance that pointer,
609 * that isn't a problem. 589 * that isn't a problem.
610 */ 590 */
611 if (victim && victim != op && victim->head != op) 591 if (victim && victim != op && victim->head != op)
612 { 592 {
613
614 /* for golems with race fields, we don't attack 593 /* for golems with race fields, we don't attack
615 * aligned races 594 * aligned races
616 */ 595 */
617 596
618 if (victim->race && op->race && strstr (op->race, victim->race)) 597 if (victim->race && op->race && strstr (op->race, victim->race))
630 attack_ob (victim, op); 609 attack_ob (victim, op);
631 made_attack = 1; 610 made_attack = 1;
632 } 611 }
633 } /* If victim */ 612 } /* If victim */
634 } 613 }
614
635 if (made_attack) 615 if (made_attack)
636 update_object (op, UP_OBJ_FACE); 616 update_object (op, UP_OBJ_FACE);
637} 617}
638 618
639/* this is a really stupid function when you get down and 619/* this is a really stupid function when you get down and
661 char buf[MAX_BUF]; 641 char buf[MAX_BUF];
662 642
663 /* Because there can be different golem spells, player may want to 643 /* Because there can be different golem spells, player may want to
664 * 'lose' their old golem. 644 * 'lose' their old golem.
665 */ 645 */
666 if (op->type == PLAYER && op->contr->ranges[range_golem]) 646 if (op->type == PLAYER && op->contr->golem)
667 { 647 {
668 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.");
669 op->contr->ranges[range_golem]->remove (); 649 op->contr->golem->remove ();
670 op->contr->ranges[range_golem]->destroy (); 650 op->contr->golem->destroy ();
671 op->contr->ranges[range_golem] = 0; 651 op->contr->golem = 0;
672 } 652 }
673 653
674 if (spob->other_arch) 654 if (spob->other_arch)
675 at = spob->other_arch; 655 at = spob->other_arch;
676 else if (spob->race) 656 else if (spob->race)
696 LOG (llevError, "Spell %s lacks other_arch\n", &spob->name); 676 LOG (llevError, "Spell %s lacks other_arch\n", &spob->name);
697 return 0; 677 return 0;
698 } 678 }
699 679
700 if (!dir) 680 if (!dir)
701 dir = find_free_spot (NULL, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); 681 dir = find_free_spot (at, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1);
702 682
703 if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) 683 if (dir < 0 || ob_blocked (at, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir]))
704 { 684 {
705 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 685 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
706 return 0; 686 return 0;
707 } 687 }
708 688
716 696
717 if (op->type == PLAYER) 697 if (op->type == PLAYER)
718 { 698 {
719 tmp->type = GOLEM; 699 tmp->type = GOLEM;
720 tmp->set_owner (op); 700 tmp->set_owner (op);
701 op->contr->golem = tmp;
702 /* give the player control of the golem */
721 set_spell_skill (op, caster, spob, tmp); 703 set_spell_skill (op, caster, spob, tmp);
722 op->contr->ranges[range_golem] = tmp;
723 /* give the player control of the golem */
724 op->contr->shoottype = range_golem;
725 } 704 }
726 else 705 else
727 { 706 {
728 if (QUERY_FLAG (op, FLAG_FRIENDLY)) 707 if (QUERY_FLAG (op, FLAG_FRIENDLY))
729 { 708 {
732 if (owner) 711 if (owner)
733 { /* For now, we transfer ownership */ 712 { /* For now, we transfer ownership */
734 tmp->set_owner (owner); 713 tmp->set_owner (owner);
735 tmp->attack_movement = PETMOVE; 714 tmp->attack_movement = PETMOVE;
736 add_friendly_object (tmp); 715 add_friendly_object (tmp);
737 SET_FLAG (tmp, FLAG_FRIENDLY);
738 } 716 }
739 } 717 }
740 718
741 SET_FLAG (tmp, FLAG_MONSTER); 719 SET_FLAG (tmp, FLAG_MONSTER);
742 } 720 }
919 if (level < tr->magic) 897 if (level < tr->magic)
920 break; 898 break;
921 899
922 lasttr = tr; 900 lasttr = tr;
923 901
924 if (tr->item->name == sparam) 902 if (tr->item->archname == sparam)
925 break; 903 break;
926 } 904 }
927 905
928 if (!lasttr) 906 if (!lasttr)
929 { 907 {
971 ndir = dir; 949 ndir = dir;
972 950
973 if (!ndir) 951 if (!ndir)
974 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); 952 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE);
975 953
976 if (ndir == -1 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) 954 if (ndir < 0 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir]))
977 { 955 {
978 ndir = -1; 956 ndir = -1;
979 if (++tries == 5) 957 if (++tries == 5)
980 { 958 {
981 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 959 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1004 return 0; 982 return 0;
1005 } 983 }
1006 984
1007 for (i = 1; i <= nrof; i++) 985 for (i = 1; i <= nrof; i++)
1008 { 986 {
1009 archetype *atmp;
1010 object *prev = NULL, *head = NULL, *tmp; 987 object *prev = NULL, *head = NULL, *tmp;
1011 988
1012 if (dir) 989 if (dir)
1013 { 990 {
1014 ndir = dir; 991 ndir = dir;
1015 dir = absdir (dir + 1); 992 dir = absdir (dir + 1);
1016 } 993 }
1017 else 994 else
1018 ndir = find_free_spot (&summon_arch->clone, op->map, op->x, op->y, 1, SIZEOFFREE); 995 ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE);
1019 996
1020 if (ndir > 0) 997 if (ndir > 0)
1021 { 998 {
1022 x = freearr_x[ndir]; 999 x = freearr_x[ndir];
1023 y = freearr_y[ndir]; 1000 y = freearr_y[ndir];
1024 } 1001 }
1025 1002
1026 if (ndir == -1 || ob_blocked (&summon_arch->clone, op->map, op->x + x, op->y + y)) 1003 if (ndir < 0 || ob_blocked (summon_arch, op->map, op->x + x, op->y + y))
1027 { 1004 {
1028 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 1005 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1029 if (nrof > 1) 1006 if (nrof > 1)
1030 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); 1007 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting.");
1031 1008
1032 return nrof > 1; 1009 return nrof > 1;
1033 } 1010 }
1034 1011
1035 for (atmp = summon_arch; atmp != NULL; atmp = atmp->more) 1012 for (archetype *atmp = summon_arch; atmp != NULL; atmp = (archetype *)atmp->more)
1036 { 1013 {
1037 tmp = arch_to_object (atmp); 1014 tmp = arch_to_object (atmp);
1038 if (atmp == summon_arch) 1015 if (atmp == summon_arch)
1039 { 1016 {
1040 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 1017 if (QUERY_FLAG (tmp, FLAG_MONSTER))
1048 if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) 1025 if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY))
1049 { 1026 {
1050 /* If this is not set, we make it friendly */ 1027 /* If this is not set, we make it friendly */
1051 if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) 1028 if (!QUERY_FLAG (spell_ob, FLAG_MONSTER))
1052 { 1029 {
1053 SET_FLAG (tmp, FLAG_FRIENDLY);
1054 add_friendly_object (tmp); 1030 add_friendly_object (tmp);
1055 tmp->stats.exp = 0; 1031 tmp->stats.exp = 0;
1056 1032
1057 if (spell_ob->attack_movement) 1033 if (spell_ob->attack_movement)
1058 tmp->attack_movement = spell_ob->attack_movement; 1034 tmp->attack_movement = spell_ob->attack_movement;
1074 tmp->head = head; 1050 tmp->head = head;
1075 prev->more = tmp; 1051 prev->more = tmp;
1076 } 1052 }
1077 1053
1078 prev = tmp; 1054 prev = tmp;
1079 tmp->x = op->x + x + tmp->arch->clone.x; 1055 tmp->x = op->x + x + tmp->arch->x;
1080 tmp->y = op->y + y + tmp->arch->clone.y; 1056 tmp->y = op->y + y + tmp->arch->y;
1081 tmp->map = op->map; 1057 tmp->map = op->map;
1082 } 1058 }
1083 1059
1084 head->direction = freedir[ndir]; 1060 head->direction = freedir[ndir];
1085 head->stats.exp = 0; 1061 head->stats.exp = 0;
1088 if (head && head->randomitems) 1064 if (head && head->randomitems)
1089 { 1065 {
1090 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); 1066 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0);
1091 1067
1092 for (object *tmp = head->inv; tmp; tmp = tmp->below) 1068 for (object *tmp = head->inv; tmp; tmp = tmp->below)
1093 SET_FLAG (tmp, FLAG_NO_DROP); 1069 SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH);
1094 } 1070 }
1095 } /* for i < nrof */ 1071 } /* for i < nrof */
1096 1072
1097 return 1; 1073 return 1;
1098} 1074}
1126 return 0; 1102 return 0;
1127 1103
1128 /* get the owners of itself and the target, this is to deal with pets of 1104 /* get the owners of itself and the target, this is to deal with pets of
1129 pets */ 1105 pets */
1130 rowner = get_real_owner (owner); 1106 rowner = get_real_owner (owner);
1131 if (target->type != PLAYER) 1107 towner = target->type == PLAYER ? 0 : get_real_owner (target);
1132 {
1133 towner = get_real_owner (target);
1134 }
1135 else
1136 {
1137 towner = 0;
1138 }
1139 1108
1140 /* if the pet has now owner, exit with error */ 1109 /* if the pet has now owner, exit with error */
1141 if (rowner == NULL) 1110 if (!rowner)
1142 { 1111 {
1143 LOG (llevError, "Pet has no owner.\n"); 1112 LOG (llevError, "Pet has no owner.\n");
1144 return 0; 1113 return 0;
1145 } 1114 }
1146 1115

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines