Crossfire Archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

CF: patch for pit bug



The following is a temporary patch for pit bug.
Now we can play raffle in Pupland. :)


I fixed the function find_free_spot() and 
added/modified the guard statement 
for the "cannot find free spot" exception at all function call.

Thanks,
S.Nishita

------- 8< ------ 8= --------

diff -cr crossfire-0.95.2/common/object.c- crossfire-0.95.2/common/object.c
*** crossfire-0.95.2/common/object.c-	Thu Feb  4 12:51:39 1999
--- crossfire-0.95.2/common/object.c	Thu Feb  4 12:55:40 1999
***************
*** 1780,1786 ****
      else if(wall(m,x+freearr_x[i],y+freearr_y[i])&&maxfree[i]<stop)
        stop=maxfree[i];
    }
!   if(!index) return 0;
    return altern[RANDOM()%index];
  }
  
--- 1780,1789 ----
      else if(wall(m,x+freearr_x[i],y+freearr_y[i])&&maxfree[i]<stop)
        stop=maxfree[i];
    }
!   /* -1 means "I couldn't found any free spot."
!   /* 0  means "I found free spot (x,y)". */
!   /* if(!index) return 0; */
!   if(!index) return -1;
    return altern[RANDOM()%index];
  }
  
diff -cr crossfire-0.95.2/server/apply.c- crossfire-0.95.2/server/apply.c
*** crossfire-0.95.2/server/apply.c-	Thu Feb  4 12:56:01 1999
--- crossfire-0.95.2/server/apply.c	Thu Feb  4 12:56:49 1999
***************
*** 1222,1228 ****
  	object *part;
  
  	/* If no free spot, return */
! 	if (i==0) return 0;
  	remove_ob(op);
  	for (part=op; part!=NULL; part=part->more) {
  	    part->x=EXIT_X(tmp)+freearr_x[i] + (part->arch?part->arch->clone.x:0);
--- 1222,1228 ----
  	object *part;
  
  	/* If no free spot, return */
! 	if (i==-1) return 0;
  	remove_ob(op);
  	for (part=op; part!=NULL; part=part->more) {
  	    part->x=EXIT_X(tmp)+freearr_x[i] + (part->arch?part->arch->clone.x:0);
***************
*** 1258,1264 ****
        if(op->type!=PLAYER) {
          if(QUERY_FLAG(op, FLAG_UNPAID)) { /* Just move the item to an adjacent place */
            int i=find_free_spot(op->arch,op->map,op->x,op->y,1,9);
!           if(!i) return 1;
            transfer_ob(op,op->x+freearr_x[i],op->y+freearr_y[i]);
            CLEAR_FLAG(op, FLAG_NO_APPLY);
            return 1;
--- 1258,1264 ----
        if(op->type!=PLAYER) {
          if(QUERY_FLAG(op, FLAG_UNPAID)) { /* Just move the item to an adjacent place */
            int i=find_free_spot(op->arch,op->map,op->x,op->y,1,9);
!           if(i==-1) return 1;
            transfer_ob(op,op->x+freearr_x[i],op->y+freearr_y[i]);
            CLEAR_FLAG(op, FLAG_NO_APPLY);
            return 1;
***************
*** 1275,1281 ****
        }
        else {
          int i=find_free_spot(op->arch,op->map,op->x,op->y,1,9);
!         if(!i)
            LOG(llevError,"Internal shop-mat problem.\n");
          else {
            remove_ob(op);
--- 1275,1281 ----
        }
        else {
          int i=find_free_spot(op->arch,op->map,op->x,op->y,1,9);
!         if(i==-1)
            LOG(llevError,"Internal shop-mat problem.\n");
          else {
            remove_ob(op);
diff -cr crossfire-0.95.2/server/main.c- crossfire-0.95.2/server/main.c
*** crossfire-0.95.2/server/main.c-	Thu Feb  4 13:02:34 1999
--- crossfire-0.95.2/server/main.c	Thu Feb  4 13:08:19 1999
***************
*** 463,468 ****
--- 463,470 ----
      int i = find_free_spot(op->arch,op->map,
                             EXIT_X(op->map->map_object),
  			   EXIT_Y(op->map->map_object),1,9);
+     /* if there is no free space, put players at map entrance */
+     if (i == -1) i=0;
      op->x = EXIT_X(op->map->map_object) + freearr_x[i];
      op->y = EXIT_Y(op->map->map_object) + freearr_y[i];
      if (out_of_map (op->map, op->x, op->y)) {
diff -cr crossfire-0.95.2/server/c_wiz.c- crossfire-0.95.2/server/c_wiz.c
*** crossfire-0.95.2/server/c_wiz.c-	Sat Jan 30 17:30:32 1999
--- crossfire-0.95.2/server/c_wiz.c	Thu Feb  4 13:01:34 1999
***************
*** 210,215 ****
--- 210,216 ----
          return 1;
        }
        i=find_free_spot(op->arch,op->map,op->x,op->y,1,8);
+       if (i==-1) i=0; /* I don't know how to do for the wizard. (?_?) */
        dummy=get_object();
        EXIT_PATH(dummy)=add_string(op->map->path);
        EXIT_X(dummy)=op->x+freearr_x[i];
diff -cr crossfire-0.95.2/server/move.c- crossfire-0.95.2/server/move.c
*** crossfire-0.95.2/server/move.c-	Thu Feb  4 13:04:45 1999
--- crossfire-0.95.2/server/move.c	Thu Feb  4 13:05:09 1999
***************
*** 187,194 ****
      return;
    }
    other_teleporter=altern[RANDOM()%nrofalt];
!   if(!(k=find_free_spot(teleported->arch,other_teleporter->map,
!                         other_teleporter->x,other_teleporter->y,1,9)))
      return;
    remove_ob(teleported);
    for(tmp=teleported;tmp!=NULL;tmp=tmp->more)
--- 187,194 ----
      return;
    }
    other_teleporter=altern[RANDOM()%nrofalt];
!   if((k=find_free_spot(teleported->arch,other_teleporter->map,
!                         other_teleporter->x,other_teleporter->y,1,9))==-1)
      return;
    remove_ob(teleported);
    for(tmp=teleported;tmp!=NULL;tmp=tmp->more)
diff -cr crossfire-0.95.2/server/pets.c- crossfire-0.95.2/server/pets.c
*** crossfire-0.95.2/server/pets.c-	Thu Feb  4 13:05:15 1999
--- crossfire-0.95.2/server/pets.c	Thu Feb  4 13:05:34 1999
***************
*** 191,197 ****
    }
    dir = find_free_spot(ob->arch, owner->map,
                         owner->x, owner->y, 1, SIZEOFFREE);
!   if (!dir) {
      LOG(llevMonster,"No space for pet to follow, freeing %s.\n",ob->name);
      return; /* Will be freed since it's removed */
    }
--- 191,197 ----
    }
    dir = find_free_spot(ob->arch, owner->map,
                         owner->x, owner->y, 1, SIZEOFFREE);
!   if (dir==-1) {
      LOG(llevMonster,"No space for pet to follow, freeing %s.\n",ob->name);
      return; /* Will be freed since it's removed */
    }
diff -cr crossfire-0.95.2/server/player.c- crossfire-0.95.2/server/player.c
*** crossfire-0.95.2/server/player.c-	Thu Feb  4 13:08:30 1999
--- crossfire-0.95.2/server/player.c	Thu Feb  4 13:10:43 1999
***************
*** 168,173 ****
--- 168,175 ----
      } else {
  	i=find_free_spot(NULL,m,EXIT_X(m->map_object),EXIT_Y(m->map_object),
  			 0,SIZEOFFREE);
+ 	/* put player in the wall, if there is no free spot */
+ 	if (i==-1) i=0;
  	op->x=EXIT_X(m->map_object)+freearr_x[i];
  	op->y=EXIT_Y(m->map_object)+freearr_y[i];
      }
diff -cr crossfire-0.95.2/server/spell_effect.c- crossfire-0.95.2/server/spell_effect.c
*** crossfire-0.95.2/server/spell_effect.c-	Thu Feb  4 13:10:56 1999
--- crossfire-0.95.2/server/spell_effect.c	Thu Feb  4 13:16:23 1999
***************
*** 1430,1436 ****
    }
    if (!dir)
      dir = find_free_spot(at, op->map, op->x, op->y, 1, SIZEOFFREE);
!   if(arch_blocked(at,op->map, op->x + freearr_x[dir], op->y+freearr_y[dir]))
    {
      new_draw_info(NDI_UNIQUE, 0,op, "There is something in the way.");
      if(op->type == PLAYER)
--- 1430,1437 ----
    }
    if (!dir)
      dir = find_free_spot(at, op->map, op->x, op->y, 1, SIZEOFFREE);
!   if(dir == -1
!      || arch_blocked(at,op->map, op->x + freearr_x[dir], op->y+freearr_y[dir]))
    {
      new_draw_info(NDI_UNIQUE, 0,op, "There is something in the way.");
      if(op->type == PLAYER)
***************
*** 2545,2551 ****
        
    if (!dir)                               
      dir = find_free_spot(at, op->map, op->x, op->y, 1, SIZEOFFREE);
!   if(arch_blocked(at,op->map, op->x + freearr_x[dir], op->y+freearr_y[dir]))
    {  
      new_draw_info(NDI_UNIQUE, 0,op, "There is something in the way.");
      if(op->type == PLAYER)
--- 2546,2553 ----
        
    if (!dir)                               
      dir = find_free_spot(at, op->map, op->x, op->y, 1, SIZEOFFREE);
!   if(dir == -1
!      || arch_blocked(at,op->map, op->x + freearr_x[dir], op->y+freearr_y[dir]))
    {  
      new_draw_info(NDI_UNIQUE, 0,op, "There is something in the way.");
      if(op->type == PLAYER)
***************
*** 2646,2652 ****
    if(!dir)
      dir = find_free_spot(at, op->map, op->x, op->y, 1, SIZEOFFREE);
  
!   if(arch_blocked(at,op->map, op->x + freearr_x[dir], op->y+freearr_y[dir])) { 
      new_draw_info(NDI_UNIQUE, 0,op,"There is something in the way.");
      if(op->type==PLAYER)
        op->contr->count_left=0;
--- 2648,2656 ----
    if(!dir)
      dir = find_free_spot(at, op->map, op->x, op->y, 1, SIZEOFFREE);
  
!   if(dir == -1
!      || arch_blocked(at,op->map, op->x + freearr_x[dir], op->y+freearr_y[dir]))
!   { 
      new_draw_info(NDI_UNIQUE, 0,op,"There is something in the way.");
      if(op->type==PLAYER)
        op->contr->count_left=0;
***************
*** 2871,2877 ****
      }
    if(!dir) 
      dir=find_free_spot(NULL,op->map,op->x,op->y,1,9);
!   if(blocked(op->map,op->x+freearr_x[dir],op->y+freearr_y[dir])) {
      new_draw_info(NDI_UNIQUE, 0,op,"There is something in the way.");
      if(op->type==PLAYER)
        op->contr->count_left=0;
--- 2875,2881 ----
      }
    if(!dir) 
      dir=find_free_spot(NULL,op->map,op->x,op->y,1,9);
!   if(dir == -1 || blocked(op->map,op->x+freearr_x[dir],op->y+freearr_y[dir])) {
      new_draw_info(NDI_UNIQUE, 0,op,"There is something in the way.");
      if(op->type==PLAYER)
        op->contr->count_left=0;
diff -cr crossfire-0.95.2/server/spell_util.c- crossfire-0.95.2/server/spell_util.c
*** crossfire-0.95.2/server/spell_util.c-	Thu Feb  4 13:16:41 1999
--- crossfire-0.95.2/server/spell_util.c	Thu Feb  4 13:17:09 1999
***************
*** 789,795 ****
      }
    if(!dir)
      dir=find_free_spot(NULL,op->map,op->x,op->y,1,9);
!   if(blocked(op->map,op->x+freearr_x[dir],op->y+freearr_y[dir])) {
      new_draw_info(NDI_UNIQUE, 0,op,"There is something in the way.");
      if(op->type==PLAYER)
        op->contr->count_left=0;
--- 789,795 ----
      }
    if(!dir)
      dir=find_free_spot(NULL,op->map,op->x,op->y,1,9);
!   if(dir == -1 || blocked(op->map,op->x+freearr_x[dir],op->y+freearr_y[dir])) {
      new_draw_info(NDI_UNIQUE, 0,op,"There is something in the way.");
      if(op->type==PLAYER)
        op->contr->count_left=0;
diff -cr crossfire-0.95.2/server/time.c- crossfire-0.95.2/server/time.c
*** crossfire-0.95.2/server/time.c-	Thu Feb  4 13:17:19 1999
--- crossfire-0.95.2/server/time.c	Thu Feb  4 13:18:58 1999
***************
*** 82,88 ****
      return;
    }
    i=find_free_spot(at,gen->map,gen->x,gen->y,1,9);
!   if(!i) return;
    while(at!=NULL) {
      op=arch_to_object(at);
      op->x=gen->x+freearr_x[i]+at->clone.x;
--- 82,88 ----
      return;
    }
    i=find_free_spot(at,gen->map,gen->x,gen->y,1,9);
!   if(i==-1) return;
    while(at!=NULL) {
      op=arch_to_object(at);
      op->x=gen->x+freearr_x[i]+at->clone.x;
***************
*** 287,296 ****
  			   ||QUERY_FLAG(tmp,FLAG_CAN_ROLL))) {
  		    /* If it has speed, it should move itself, otherwise: */
  		    int i=find_free_spot(tmp->arch,op->map,op->x,op->y,1,9);
! 
! 		    remove_ob(tmp);
! 		    tmp->x+=freearr_x[i],tmp->y+=freearr_y[i];
! 		    insert_ob_in_map(tmp,op->map);
  		}
  	    }
  
--- 287,298 ----
  			   ||QUERY_FLAG(tmp,FLAG_CAN_ROLL))) {
  		    /* If it has speed, it should move itself, otherwise: */
  		    int i=find_free_spot(tmp->arch,op->map,op->x,op->y,1,9);
! 		    /* If free spot is found,.. */
! 		    if (i!=-1) {
! 		        remove_ob(tmp);
! 		        tmp->x+=freearr_x[i],tmp->y+=freearr_y[i];
! 		        insert_ob_in_map(tmp,op->map);
! 		    }
  		}
  	    }
  


--------8< ---------- 8= -----------

--------------------------------------------------------------------------
Seikoh Nishita		      |	Dep't. of Information & Computer Sciences
			      |	Faculty of Engineering Science
[e-mail]		      |	Osaka University
s-nisita@ics.es.osaka-u.ac.jp |	Toyonaka, Osaka 560, Japan

-
[you can put yourself on the announcement list only or unsubscribe altogether
by sending an email stating your wishes to crossfire-request@ifi.uio.no]