Difference for server/pets.c from version 1.14 to 1.15


version 1.14 version 1.15
Line 1
 
Line 1
 /*  /*
  * static char *rcsid_pets_c =   * static char *rcsid_pets_c =
  *    "$Id: pets.c,v 1.14 2002/09/24 05:43:15 mwedel Exp $";   *    "$Id: pets.c,v 1.15 2002/12/25 06:45:46 garbled Exp $";
  */   */
   
 /*  /*
Line 39
 
Line 39
  */   */
   
 object *get_pet_enemy(object * pet, rv_vector *rv){  object *get_pet_enemy(object * pet, rv_vector *rv){
     object *owner, *tmp, *attacker;      object *owner, *tmp, *attacker, *tmp3;
     int i,x,y;      int i,j,x,y;
     mapstruct *nm;      mapstruct *nm;
     int search_arr[SIZEOFFREE];      int search_arr[SIZEOFFREE];
   
Line 84
 
Line 84
     }      }
     get_search_arr(search_arr);      get_search_arr(search_arr);
   
       if (owner->type == PLAYER && owner->contr->petmode > pet_normal) {
    if (owner->contr->petmode == pet_sad) {
        tmp = find_nearest_living_creature(pet);
        if (tmp != NULL) {
    get_rangevector(pet, tmp, rv, 0);
    if(check_enemy(pet, rv) != NULL)
                       return tmp;
                   else
                       pet->enemy = NULL;
        }
        /* if we got here we have no enemy */
        /* we return NULL to avoid heading back to the owner */
        pet->enemy = NULL;
        return NULL;
    }
       }
   
     /* Since the pet has no existing enemy, look for anything nasty       /* Since the pet has no existing enemy, look for anything nasty
      * around the owner that it should go and attack.       * around the owner that it should go and attack.
      */       */
       tmp3 = NULL;
     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]];
Line 100
 
Line 117
      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 &&
    can_detect_enemy(pet, tmp2, rv)) {
   
    if (!can_see_enemy(pet, tmp2)) {
        if (tmp3 != NULL)
    tmp3 = tmp2;
    } else {
  pet->enemy = tmp2;   pet->enemy = tmp2;
  /* Check to see if this is a valid enemy before committing */  
  if(check_enemy(pet, rv)!=NULL)   if(check_enemy(pet, rv)!=NULL)
      return tmp2;       return tmp2;
  else   else
      pet->enemy = NULL;       pet->enemy = NULL;
    }
      } /* 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 */   } /* 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
          see, take what we have */
       if (tmp3 != NULL) {
    pet->enemy = tmp3;
    if (check_enemy(pet, rv) != NULL)
        return tmp3;
    else
        pet->enemy = NULL;
       }
   
     /* No threat to owner, check to see if the pet has an attacker*/      /* No threat to owner, check to see if the pet has an attacker*/
     if(attacker)      if(attacker)
     {      {
Line 138
 
Line 170
      * a pet to danger, then take a few steps back.  This code is basically       * a pet to danger, then take a few steps back.  This code is basically
      * the same as the code that looks around the owner.       * the same as the code that looks around the owner.
      */       */
       if (owner->type == PLAYER && owner->contr->petmode != pet_defend) {
    tmp3 = NULL;
     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]];
Line 148
 
Line 182
      if (GET_MAP_FLAGS(nm, x,y)&P_IS_ALIVE) {       if (GET_MAP_FLAGS(nm, 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) &&   && !QUERY_FLAG(tmp2,FLAG_UNAGGRESSIVE) &&
  tmp2 != pet && tmp2 != owner && tmp2->type != PLAYER)       tmp2 != pet && tmp2 != owner && tmp2->type != PLAYER &&
      {       can_detect_enemy(pet, tmp2, rv))
    if (!can_see_enemy(pet, tmp2)) {
        if (tmp3 != NULL)
    tmp3 = tmp2;
    } else {
          pet->enemy = tmp2;           pet->enemy = tmp2;
          if(check_enemy(pet, rv)!=NULL)           if(check_enemy(pet, rv)!=NULL)
              return tmp2;               return tmp2;
Line 162
 
Line 201
      } /* if there is something living on this space */       } /* if there is something living on this space */
  } /* this is a valid space on the map */   } /* 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 */
   
       /* fine, we went through the whole loop and didn't find one we could
          see, take what we have */
       if (tmp3 != NULL) {
    pet->enemy = tmp3;
    if (check_enemy(pet, rv) != NULL)
        return tmp3;
    else
        pet->enemy = NULL;
       }
   
     /* Didn't find anything - return the owner's enemy or NULL */      /* Didn't find anything - return the owner's enemy or NULL */
     return check_enemy(pet, rv);      return check_enemy(pet, rv);
Line 243
 
Line 293
   
 void pet_move(object * ob)  void pet_move(object * ob)
 {  {
     int dir,tag, dx, dy;      int dir, tag, dx, dy, i;
     object *ob2, *owner;      object *ob2, *owner;
     mapstruct *m;      mapstruct *m;
   
Line 262
 
Line 312
  return;   return;
     }      }
     /* Calculate Direction */      /* Calculate Direction */
       if (owner->contr->petmode == pet_sad) {
    /* in S&D mode, if we have no enemy, run randomly about. */
    for (i=0; i < 15; i++) {
        dir = rndm(1, 8);
        dx = ob->x + freearr_x[dir];
        dy = ob->y + freearr_y[dir];
        if (out_of_map(owner->map, dx, dy) || wall(owner->map, dx, dy))
    continue;
        else
    break;
    }
       } else {
     dir = find_dir_2(ob->x - ob->owner->x, ob->y - ob->owner->y);      dir = find_dir_2(ob->x - ob->owner->x, ob->y - ob->owner->y);
       }
     ob->direction = dir;      ob->direction = dir;
   
     tag = ob->count;      tag = ob->count;


Legend:
line(s) removed in v.1.14 
line(s) changed
 line(s) added in v.1.15

File made using version 1.98 of cvs2html by leaf at 2011-07-21 17:39