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

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines