Difference for random_maps/exit.c from version 1.8 to 1.9


version 1.8 version 1.9
Line 1
 
Line 1
 /*  /*
  * static char *rcsid_exit_c =   * static char *rcsid_exit_c =
  *   "$Id: exit.c,v 1.8 2000/12/15 03:09:19 peterm Exp $";   *   "$Id: exit.c,v 1.9 2000/12/18 06:15:05 peterm Exp $";
  */   */
   
 /*  /*
Line 30
 
Line 30
 #include <sproto.h>  #include <sproto.h>
 #include <rproto.h>  #include <rproto.h>
   
   
   /*  find a character in the layout.  fx and fy are pointers to
       where to find the char.  fx,fy = -1 if not found. */
   void find_in_layout(int mode, char target,int *fx,int *fy,char **layout,RMParms *RP) {
     int M;
     int i,j;
     *fx=-1;
     *fy=-1;
   
     /* if a starting point isn't given, pick one */
     if(mode < 1 || mode > 4) M=RANDOM() % 4 + 1 ;
     else M = mode;
   
     /* four different search starting points and methods so that
        we can do something different for symmetrical maps instead of
        the same damned thing every time. */
     switch(M) {
     case 1: {  /* search from top left down/right */
       for(i=1;i<RP->Xsize;i++)
         for(j=1;j<RP->Ysize;j++) {
           if(layout[i][j]==target) {
             *fx = i; *fy = j;
             return;
           }
         }
       break;
     }
     case 2: { /* Search from top right down/left */
       for(i=RP->Xsize-2;i>0;i--)
         for(j=1;j<RP->Ysize-1;j++) {
           if(layout[i][j]==target) {
             *fx = i; *fy = j;
             return;
           }
         }
       break;
     }
     case 3: { /* search from bottom-left up-right */
       for(i=1;i<RP->Xsize-1;i++)
         for(j=RP->Ysize-2;j>0;j--) {
           if(layout[i][j]==target) {
             *fx = i; *fy = j;
             return;
           }
         }
       break;
     }
     case 4: { /* search from bottom-right up-left */
       for(i=RP->Xsize-2;i>0;i--)
         for(j=RP->Ysize-2;j>0;j--) {
           if(layout[i][j]==target) {
             *fx = i; *fy = j;
             return;
           }
         }
       break;
     }
     }
   }
          
      
      
   
    
    
 /* orientation:  0 means random,  /* orientation:  0 means random,
   1 means descending dungeon    1 means descending dungeon
   2 means ascending dungeon    2 means ascending dungeon
Line 47
 
Line 112
   object *the_exit_up;          /* easier maze */    object *the_exit_up;          /* easier maze */
   object *random_sign;          /* magic mouth saying this is a random map. */    object *random_sign;          /* magic mouth saying this is a random map. */
   int cx=-1,cy=-1;  /* location of a map center */    int cx=-1,cy=-1;  /* location of a map center */
     int upx=-1,upy=-1;  /* location of up exit */
     int downx=-1,downy=-1;
   
   if(orientation == 0) orientation = RANDOM() % 6 + 1;    if(orientation == 0) orientation = RANDOM() % 6 + 1;
   
Line 92
 
Line 159
     }      }
   else the_exit_down = 0;    else the_exit_down = 0;
   
   /* set up the down exit */    /* set up the up exit */
   the_exit_up->stats.hp = RP->origin_x;    the_exit_up->stats.hp = RP->origin_x;
   the_exit_up->stats.sp = RP->origin_y;    the_exit_up->stats.sp = RP->origin_y;
   the_exit_up->slaying = add_string(RP->origin_map);    the_exit_up->slaying = add_string(RP->origin_map);
Line 100
 
Line 167
   /* figure out where to put the entrance */    /* figure out where to put the entrance */
   /* begin a logical block */    /* begin a logical block */
   {    {
     int ex=-1,ey=-1;  
     int i,j;      int i,j;
     /* first, look for a C, the map center.  */      /* First, look for a '<' char */
     for(i=0;i<RP->Xsize&&cx==-1;i++)      find_in_layout(0,'<',&upx,&upy,maze,RP);
       for(j=0;j<RP->Ysize;j++) {  
    if(maze[i][j]=='C') {      /* next, look for a C, the map center.  */
  cx = i; cy=j; break;      find_in_layout(0,'C',&cx,&cy,maze,RP);
    }  
       }     
     if(cx!=-1) {      /* if we didn't find an up, find an empty place far from the center */
       if(cx > RP->Xsize/2) ex = 1;      if(upx==-1 && cx!=-1) {
       else ex = RP->Xsize -2;        if(cx > RP->Xsize/2) upx = 1;
       if(cy > RP->Ysize/2) ey = 1;        else upx = RP->Xsize -2;
       else ey = RP->Ysize -2;        if(cy > RP->Ysize/2) upy = 1;
     }        else upy = RP->Ysize -2;
     else {        /* find an empty place far from the center */
  ex = RANDOM() % (RP->Xsize-2) +1;        if(upx==1 && upy==1) find_in_layout(1,0,&upx,&upy,maze,RP);
  ey = RANDOM() % (RP->Ysize-2) +1;        else
           if(upx==1 && upy>1) find_in_layout(3,0,&upx,&upy,maze,RP);
           else
             if(upx>1 && upy==1) find_in_layout(2,0,&upx,&upy,maze,RP);
             else
               if(upx>1 && upy>1) find_in_layout(4,0,&upx,&upy,maze,RP);
     }      }
  i = find_first_free_spot(the_exit_up->arch,map,ex,ey);     
  the_exit_up->x = ex + freearr_x[i];      /* no indication of where to place the exit, so just place it. */
  the_exit_up->y = ey + freearr_y[i];      if(upx==-1) find_in_layout(0,0,&upx,&upy,maze,RP);
   
       the_exit_up->x = upx;
       the_exit_up->y = upy;
   
  /* surround the exits with notices that this is a random map. */   /* surround the exits with notices that this is a random map. */
  for(j=1;j<9;j++) {   for(j=1;j<9;j++) {
Line 140
 
Line 214
  map->map_object->stats.hp=the_exit_up->x;   map->map_object->stats.hp=the_exit_up->x;
  map->map_object->stats.sp=the_exit_up->y;   map->map_object->stats.sp=the_exit_up->y;
         
       /* first, look for a '>' character */
       find_in_layout(0,'>',&downx,&downy,maze,RP);
       /* if no > is found use C */
       if(downx==-1) { downx = cx; downy=cy;};
          
  /* make the other exit far away from this one if   /* make the other exit far away from this one if
  there's no center. */   there's no center. */
  if(cx==-1) {      if(downx==-1) {
  if(ex > RP->Xsize/2) cx = 1;        if(upx > RP->Xsize/2) downx = 1;
  else cx = RP->Xsize -2;        else downx = RP->Xsize -2;
  if(ey > RP->Ysize/2) cy = 1;        if(upy > RP->Ysize/2) downy = 1;
  else cy = RP->Ysize -2;        else downy = RP->Ysize -2;
  };        /* find an empty place far from the entrance */
         if(downx==1 && downy==1) find_in_layout(1,0,&downx,&downy,maze,RP);
         else
           if(downx==1 && downy>1) find_in_layout(3,0,&downx,&downy,maze,RP);
           else
             if(downx>1 && downy==1) find_in_layout(2,0,&downx,&downy,maze,RP);
             else
               if(downx>1 && downy>1) find_in_layout(4,0,&downx,&downy,maze,RP);
   
       }
       /* no indication of where to place the down exit, so just place it */
       if(downx==-1) find_in_layout(0,0,&downx,&downy,maze,RP);
  if(the_exit_down) {   if(the_exit_down) {
  char buf[2048];   char buf[2048];
  i = find_first_free_spot(the_exit_down->arch,map,cx,cy);        i = find_first_free_spot(the_exit_down->arch,map,downx,downy);
  the_exit_down->x = cx + freearr_x[i];        the_exit_down->x = downx + freearr_x[i];
  the_exit_down->y = cy + freearr_y[i];        the_exit_down->y = downy + freearr_y[i];
  RP->origin_x = the_exit_down->x;   RP->origin_x = the_exit_down->x;
  RP->origin_y = the_exit_down->y;   RP->origin_y = the_exit_down->y;
  write_map_parameters_to_string(buf,RP);   write_map_parameters_to_string(buf,RP);


Legend:
line(s) removed in v.1.8 
line(s) changed
 line(s) added in v.1.9

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