version 1.16 | | version 1.17 |
---|
| | |
/* | | /* |
* static char *rcsid_pets_c = | | * static char *rcsid_pets_c = |
* "$Id: pets.c,v 1.16 2003/01/05 23:50:15 mwedel Exp $"; | | * "$Id: pets.c,v 1.17 2003/01/08 08:39:20 mwedel Exp $"; |
*/ | | */ |
| | |
/* | | /* |
| | |
| | |
object *get_pet_enemy(object * pet, rv_vector *rv){ | | object *get_pet_enemy(object * pet, rv_vector *rv){ |
object *owner, *tmp, *attacker, *tmp3; | | object *owner, *tmp, *attacker, *tmp3; |
int i,x,y; | | int i; |
| | sint16 x,y; |
mapstruct *nm; | | mapstruct *nm; |
int search_arr[SIZEOFFREE]; | | int search_arr[SIZEOFFREE]; |
| | |
| | |
for (i = 0; i < SIZEOFFREE; i++) { | | for (i = 0; i < SIZEOFFREE; i++) { |
x = owner->x + freearr_x[search_arr[i]]; | | x = owner->x + freearr_x[search_arr[i]]; |
y = owner->y + freearr_y[search_arr[i]]; | | y = owner->y + freearr_y[search_arr[i]]; |
if (out_of_map(owner->map, x, y)) continue; | | nm = owner->map; |
else { | | |
nm = get_map_from_coord(owner->map, &x, &y); | | |
/* Only look on the space if there is something alive there. */ | | /* Only look on the space if there is something alive there. */ |
if (GET_MAP_FLAGS(nm, x,y)&P_IS_ALIVE) { | | if (get_map_flags(nm, &nm, x, y, &x, &y) & P_IS_ALIVE) { |
for (tmp = get_map_ob(nm, x, y); tmp != NULL; tmp = tmp->above) { | | for (tmp = get_map_ob(nm, x, y); tmp != NULL; tmp = tmp->above) { |
object *tmp2 = tmp->head == NULL?tmp:tmp->head; | | object *tmp2 = tmp->head == NULL?tmp:tmp->head; |
| | |
if (QUERY_FLAG(tmp2,FLAG_ALIVE) && !QUERY_FLAG(tmp2,FLAG_FRIENDLY) | | if (QUERY_FLAG(tmp2,FLAG_ALIVE) && !QUERY_FLAG(tmp2,FLAG_FRIENDLY) |
&& !QUERY_FLAG(tmp2,FLAG_UNAGGRESSIVE) && tmp2 != pet && | | && !QUERY_FLAG(tmp2,FLAG_UNAGGRESSIVE) && tmp2 != pet && |
tmp2 != owner && tmp2->type != PLAYER && | | tmp2 != owner && tmp2->type != PLAYER && |
| | |
} /* if this is a valid enemy */ | | } /* if this is a valid enemy */ |
} /* for objects on this space */ | | } /* for objects on this space */ |
} /* if there is something living on this space */ | | } /* if there is something living on this space */ |
} /* this is a valid space on the map */ | | |
} /* for loop of spaces around the owner */ | | } /* for loop of spaces around the owner */ |
| | |
/* fine, we went through the whole loop and didn't find one we could | | /* fine, we went through the whole loop and didn't find one we could |
| | |
for (i = 0; i < SIZEOFFREE; i++) { | | for (i = 0; i < SIZEOFFREE; i++) { |
x = pet->x + freearr_x[search_arr[i]]; | | x = pet->x + freearr_x[search_arr[i]]; |
y = pet->y + freearr_y[search_arr[i]]; | | y = pet->y + freearr_y[search_arr[i]]; |
if (out_of_map(pet->map, x, y)) continue; | | nm = pet->map; |
else { | | |
nm = get_map_from_coord(pet->map, &x, &y); | | |
/* Only look on the space if there is something alive there. */ | | /* Only look on the space if there is something alive there. */ |
if (GET_MAP_FLAGS(nm, x,y)&P_IS_ALIVE) { | | if (get_map_flags(nm, &nm, x,y, &x, &y) & P_IS_ALIVE) { |
for (tmp = get_map_ob(nm, x, y); tmp != NULL; tmp = tmp->above) { | | for (tmp = get_map_ob(nm, x, y); tmp != NULL; tmp = tmp->above) { |
object *tmp2 = tmp->head == NULL?tmp:tmp->head; | | object *tmp2 = tmp->head == NULL?tmp:tmp->head; |
| | |
if (QUERY_FLAG(tmp2,FLAG_ALIVE) && | | if (QUERY_FLAG(tmp2,FLAG_ALIVE) && |
!QUERY_FLAG(tmp2,FLAG_FRIENDLY) | | !QUERY_FLAG(tmp2,FLAG_FRIENDLY) |
&& !QUERY_FLAG(tmp2,FLAG_UNAGGRESSIVE) && | | && !QUERY_FLAG(tmp2,FLAG_UNAGGRESSIVE) && |
| | |
} /* make sure we can get to the bugger */ | | } /* make sure we can get to the bugger */ |
} /* for objects on this space */ | | } /* for objects on this space */ |
} /* if there is something living on this space */ | | } /* if there is something living on this space */ |
} /* this is a valid space on the map */ | | |
} /* for loop of spaces around the pet */ | | } /* for loop of spaces around the pet */ |
} /* pet in defence mode */ | | } /* pet in defence mode */ |
| | |
| | |
dir = rndm(1, 8); | | dir = rndm(1, 8); |
dx = ob->x + freearr_x[dir]; | | dx = ob->x + freearr_x[dir]; |
dy = ob->y + freearr_y[dir]; | | dy = ob->y + freearr_y[dir]; |
if (out_of_map(owner->map, dx, dy) || wall(owner->map, dx, dy)) | | if (get_map_flags(owner->map, NULL, dx, dy, NULL, NULL) & (P_WALL | P_OUT_OF_MAP)) |
continue; | | continue; |
else | | else |
break; | | break; |