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.44 by root, Tue Apr 15 14:21:04 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 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#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
31 * this is now tilemap aware. 31 * this is now tilemap aware.
32 */ 32 */
33object * 33object *
34get_pet_enemy (object *pet, rv_vector * rv) 34get_pet_enemy (object *pet, rv_vector * rv)
35{ 35{
36 object *owner, *tmp, *attacker, *tmp3; 36 object *tmp, *attacker, *tmp3;
37 int i; 37 int i;
38 sint16 x, y; 38 sint16 x, y;
39 maptile *nm; 39 maptile *nm;
40 int search_arr[SIZEOFFREE]; 40 int search_arr[SIZEOFFREE];
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 object *owner = pet->owner;
47 { 47
48 /* If the owner has turned on the pet, make the pet 48 if (!owner)
49 * unfriendly.
50 */
51 if ((check_enemy (owner, rv)) == pet)
52 {
53 CLEAR_FLAG (pet, FLAG_FRIENDLY);
54 remove_friendly_object (pet);
55 pet->attack_movement &= ~PETMOVE;
56 return owner;
57 }
58 } 49 {
59 else
60 {
61 /* else the owner is no longer around, so the 50 /* the owner is no longer around, so the
62 * pet no longer needs to be friendly. 51 * pet no longer needs to be friendly.
63 */ 52 */
64 CLEAR_FLAG (pet, FLAG_FRIENDLY);
65 remove_friendly_object (pet); 53 remove_friendly_object (pet);
66 pet->attack_movement &= ~PETMOVE; 54 pet->attack_movement &= ~PETMOVE;
67 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)
68 } 62 {
63 remove_friendly_object (pet);
64 pet->attack_movement &= ~PETMOVE;
65 return owner;
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 297 else if (!owner->map || owner->map->in_memory != MAP_ACTIVE)
289 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);
290 ob->remove (); 299 else
291
292 if (owner->map == NULL)
293 {
294 LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name);
295 goto fail;
296 } 300 {
297 if (owner->map->in_memory != MAP_IN_MEMORY)
298 {
299 LOG (llevError, "Owner of the pet not on a map in memory!?\n");
300 goto fail;
301 }
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.
595 mflags = get_map_flags (m, &m, x, y, &x, &y); 575 mflags = get_map_flags (m, &m, x, y, &x, &y);
596 576
597 if (mflags & P_OUT_OF_MAP) 577 if (mflags & P_OUT_OF_MAP)
598 continue; 578 continue;
599 579
600 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)
601 if (QUERY_FLAG (victim, FLAG_ALIVE)) 581 if (QUERY_FLAG (victim, FLAG_ALIVE))
602 break; 582 break;
603 583
604 /* 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
605 * 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
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 || at->blocked (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
715 } 695 }
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 op->contr->golem = tmp;
701 /* give the player control of the golem */
721 set_spell_skill (op, caster, spob, tmp); 702 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 }
726 else
727 {
728 if (QUERY_FLAG (op, FLAG_FRIENDLY))
729 {
730 object *owner = op->owner;
731
732 if (owner)
733 { /* For now, we transfer ownership */
734 tmp->set_owner (owner);
735 tmp->attack_movement = PETMOVE;
736 add_friendly_object (tmp);
737 SET_FLAG (tmp, FLAG_FRIENDLY);
738 }
739 }
740
741 SET_FLAG (tmp, FLAG_MONSTER);
742 } 703 }
743 704
744 /* make the speed positive. */ 705 /* make the speed positive. */
745 tmp->speed = FABS (tmp->speed); 706 tmp->speed = FABS (tmp->speed);
746 707
919 if (level < tr->magic) 880 if (level < tr->magic)
920 break; 881 break;
921 882
922 lasttr = tr; 883 lasttr = tr;
923 884
924 if (tr->item->name == sparam) 885 if (tr->item->archname == sparam)
925 break; 886 break;
926 } 887 }
927 888
928 if (!lasttr) 889 if (!lasttr)
929 { 890 {
971 ndir = dir; 932 ndir = dir;
972 933
973 if (!ndir) 934 if (!ndir)
974 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); 935 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE);
975 936
976 if (ndir == -1 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) 937 if (ndir < 0 || mon->blocked (op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir]))
977 { 938 {
978 ndir = -1; 939 ndir = -1;
979 if (++tries == 5) 940 if (++tries == 5)
980 { 941 {
981 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 942 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1004 return 0; 965 return 0;
1005 } 966 }
1006 967
1007 for (i = 1; i <= nrof; i++) 968 for (i = 1; i <= nrof; i++)
1008 { 969 {
1009 archetype *atmp;
1010 object *prev = NULL, *head = NULL, *tmp; 970 object *prev = NULL, *head = NULL, *tmp;
1011 971
1012 if (dir) 972 if (dir)
1013 { 973 {
1014 ndir = dir; 974 ndir = dir;
1015 dir = absdir (dir + 1); 975 dir = absdir (dir + 1);
1016 } 976 }
1017 else 977 else
1018 ndir = find_free_spot (&summon_arch->clone, op->map, op->x, op->y, 1, SIZEOFFREE); 978 ndir = find_free_spot (summon_arch, op->map, op->x, op->y, 1, SIZEOFFREE);
1019 979
1020 if (ndir > 0) 980 if (ndir > 0)
1021 { 981 {
1022 x = freearr_x[ndir]; 982 x = freearr_x[ndir];
1023 y = freearr_y[ndir]; 983 y = freearr_y[ndir];
1024 } 984 }
1025 985
1026 if (ndir == -1 || ob_blocked (&summon_arch->clone, op->map, op->x + x, op->y + y)) 986 if (ndir < 0 || summon_arch->blocked (op->map, op->x + x, op->y + y))
1027 { 987 {
1028 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 988 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1029 if (nrof > 1) 989 if (nrof > 1)
1030 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting."); 990 new_draw_info (NDI_UNIQUE, 0, op, "No more pets for this casting.");
1031 991
1032 return nrof > 1; 992 return nrof > 1;
1033 } 993 }
1034 994
1035 for (atmp = summon_arch; atmp != NULL; atmp = atmp->more) 995 for (archetype *atmp = summon_arch; atmp != NULL; atmp = (archetype *)atmp->more)
1036 { 996 {
1037 tmp = arch_to_object (atmp); 997 tmp = arch_to_object (atmp);
1038 if (atmp == summon_arch) 998 if (atmp == summon_arch)
1039 { 999 {
1040 if (QUERY_FLAG (tmp, FLAG_MONSTER)) 1000 if (QUERY_FLAG (tmp, FLAG_MONSTER))
1048 if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY)) 1008 if (op->type == PLAYER || QUERY_FLAG (op, FLAG_FRIENDLY))
1049 { 1009 {
1050 /* If this is not set, we make it friendly */ 1010 /* If this is not set, we make it friendly */
1051 if (!QUERY_FLAG (spell_ob, FLAG_MONSTER)) 1011 if (!QUERY_FLAG (spell_ob, FLAG_MONSTER))
1052 { 1012 {
1053 SET_FLAG (tmp, FLAG_FRIENDLY);
1054 add_friendly_object (tmp); 1013 add_friendly_object (tmp);
1055 tmp->stats.exp = 0; 1014 tmp->stats.exp = 0;
1056 1015
1057 if (spell_ob->attack_movement) 1016 if (spell_ob->attack_movement)
1058 tmp->attack_movement = spell_ob->attack_movement; 1017 tmp->attack_movement = spell_ob->attack_movement;
1074 tmp->head = head; 1033 tmp->head = head;
1075 prev->more = tmp; 1034 prev->more = tmp;
1076 } 1035 }
1077 1036
1078 prev = tmp; 1037 prev = tmp;
1079 tmp->x = op->x + x + tmp->arch->clone.x; 1038 tmp->x = op->x + x + tmp->arch->x;
1080 tmp->y = op->y + y + tmp->arch->clone.y; 1039 tmp->y = op->y + y + tmp->arch->y;
1081 tmp->map = op->map; 1040 tmp->map = op->map;
1082 } 1041 }
1083 1042
1084 head->direction = freedir[ndir]; 1043 head->direction = freedir[ndir];
1085 head->stats.exp = 0; 1044 head->stats.exp = 0;
1088 if (head && head->randomitems) 1047 if (head && head->randomitems)
1089 { 1048 {
1090 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0); 1049 create_treasure (head->randomitems, head, GT_APPLY | GT_STARTEQUIP, 6, 0);
1091 1050
1092 for (object *tmp = head->inv; tmp; tmp = tmp->below) 1051 for (object *tmp = head->inv; tmp; tmp = tmp->below)
1093 SET_FLAG (tmp, FLAG_NO_DROP); 1052 SET_FLAG (tmp, FLAG_DESTROY_ON_DEATH);
1094 } 1053 }
1095 } /* for i < nrof */ 1054 } /* for i < nrof */
1096 1055
1097 return 1; 1056 return 1;
1098} 1057}
1126 return 0; 1085 return 0;
1127 1086
1128 /* get the owners of itself and the target, this is to deal with pets of 1087 /* get the owners of itself and the target, this is to deal with pets of
1129 pets */ 1088 pets */
1130 rowner = get_real_owner (owner); 1089 rowner = get_real_owner (owner);
1131 if (target->type != PLAYER) 1090 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 1091
1140 /* if the pet has now owner, exit with error */ 1092 /* if the pet has now owner, exit with error */
1141 if (rowner == NULL) 1093 if (!rowner)
1142 { 1094 {
1143 LOG (llevError, "Pet has no owner.\n"); 1095 LOG (llevError, "Pet has no owner.\n");
1144 return 0; 1096 return 0;
1145 } 1097 }
1146 1098

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines