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.23 by pippijn, Mon Jan 15 21:06:20 2007 UTC vs.
Revision 1.24 by root, Thu Jan 18 16:19:34 2007 UTC

267remove_all_pets (maptile *map) 267remove_all_pets (maptile *map)
268{ 268{
269 objectlink *obl, *next; 269 objectlink *obl, *next;
270 object *owner; 270 object *owner;
271 271
272 for (obl = first_friendly_object; obl != NULL; obl = next) 272 for (obl = first_friendly_object; obl; obl = next)
273 { 273 {
274 next = obl->next; 274 next = obl->next;
275 if (obl->ob->type != PLAYER && QUERY_FLAG (obl->ob, FLAG_FRIENDLY) && 275
276 (owner = obl->ob->owner) != NULL && !on_same_map (owner, obl->ob)) 276 if (obl->ob->type != PLAYER
277 && QUERY_FLAG (obl->ob, FLAG_FRIENDLY)
278 && (owner = obl->ob->owner) != 0
279 && !on_same_map (owner, obl->ob))
277 { 280 {
278 /* follow owner checks map status for us */ 281 /* follow owner checks map status for us */
279 follow_owner (obl->ob, owner); 282 follow_owner (obl->ob, owner);
280 } 283 }
281 } 284 }
282} 285}
283 286
284int 287int
285follow_owner (object *ob, object *owner) 288follow_owner (object *ob, object *owner)
286{ 289{
287 object *tmp;
288 int dir;
289
290 if (!QUERY_FLAG (ob, FLAG_REMOVED))
291 ob->remove ();
292
293 if (owner->map == NULL) 290 if (!owner->map)
294 {
295 LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name); 291 LOG (llevError, "Can't follow owner (%d): no map.\n", &owner->name);
296 goto fail;
297 }
298 if (owner->map->in_memory != MAP_IN_MEMORY) 292 else if (owner->map->in_memory != MAP_IN_MEMORY)
299 {
300 LOG (llevError, "Owner of the pet not on a map in memory!?\n"); 293 LOG (llevError, "Owner of the pet not on a map in memory!?\n");
301 goto fail; 294 else
302 } 295 {
303
304 dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE); 296 int dir = find_free_spot (ob, owner->map, owner->x, owner->y, 1, SIZEOFFREE);
305 297
306 if (dir == -1) 298 if (dir >= 0)
307 {
308 LOG (llevMonster, "No space for pet to follow, freeing %s.\n", &ob->name);
309 goto fail;
310 }
311 for (tmp = ob; tmp != NULL; tmp = tmp->more)
312 {
313 tmp->x = owner->x + freearr_x[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.x);
314 tmp->y = owner->y + freearr_y[dir] + (tmp->arch == NULL ? 0 : tmp->arch->clone.y);
315 tmp->map = owner->map;
316 if (OUT_OF_REAL_MAP (tmp->map, tmp->x, tmp->y))
317 {
318 tmp->map = get_map_from_coord (tmp->map, &tmp->x, &tmp->y);
319 } 299 {
320 } 300 owner->map->insert (ob, owner->x + freearr_x[dir], owner->y + freearr_y[dir]);
321 insert_ob_in_map (ob, ob->map, NULL, 0); 301
322 if (owner->type == PLAYER) /* Uh, I hope this is always true... */ 302 if (owner->type == PLAYER) /* Uh, I hope this is always true... */
323 new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you"); 303 new_draw_info (NDI_UNIQUE, 0, owner, "Your pet magically appears next to you");
324 304
325 return 0; 305 return 0;
306 }
307 }
326 308
327fail:
328 remove_friendly_object (ob);
329 ob->destroy (); 309 ob->destroy ();
330
331 return 1; 310 return 1;
332} 311}
333 312
334void 313void
335pet_move (object *ob) 314pet_move (object *ob)
697 } 676 }
698 677
699 if (!dir) 678 if (!dir)
700 dir = find_free_spot (NULL, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1); 679 dir = find_free_spot (NULL, op->map, op->x, op->y, 1, SIZEOFFREE1 + 1);
701 680
702 if (dir == -1 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir])) 681 if (dir < 0 || ob_blocked (&at->clone, op->map, op->x + freearr_x[dir], op->y + freearr_y[dir]))
703 { 682 {
704 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 683 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
705 return 0; 684 return 0;
706 } 685 }
707 686
969 ndir = dir; 948 ndir = dir;
970 949
971 if (!ndir) 950 if (!ndir)
972 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE); 951 ndir = find_free_spot (mon, op->map, op->x, op->y, 1, SIZEOFFREE);
973 952
974 if (ndir == -1 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir])) 953 if (ndir < 0 || ob_blocked (mon, op->map, op->x + freearr_x[ndir], op->y + freearr_y[ndir]))
975 { 954 {
976 ndir = -1; 955 ndir = -1;
977 if (++tries == 5) 956 if (++tries == 5)
978 { 957 {
979 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way."); 958 new_draw_info (NDI_UNIQUE, 0, op, "There is something in the way.");
1019 { 998 {
1020 x = freearr_x[ndir]; 999 x = freearr_x[ndir];
1021 y = freearr_y[ndir]; 1000 y = freearr_y[ndir];
1022 } 1001 }
1023 1002
1024 if (ndir == -1 || ob_blocked (&summon_arch->clone, op->map, op->x + x, op->y + y)) 1003 if (ndir < 0 || ob_blocked (&summon_arch->clone, op->map, op->x + x, op->y + y))
1025 { 1004 {
1026 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.");
1027 if (nrof > 1) 1006 if (nrof > 1)
1028 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.");
1029 1008

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines