1  /********************************************************************** <BR>


2  This file is part of Crack dot Com's free source code release of


3  Golgotha. <a href="http://www.crack.com/golgotha_release"> <BR> for


4  information about compiling & licensing issues visit this URL</a>


5  <PRE> If that doesn't help, contact Jonathan Clark at


6  golgotha_source@usa.net (Subject should have "GOLG" in it)


7  ***********************************************************************/


8 


9  #include "solvemap_breadth.hh"


10  #include "path_api.hh"


11  #include "memory/malloc.hh"


12  #include "error/error.hh"


13 


14  void g1_breadth_first_map_solver_class::set_block_map(g1_block_map_class *_block)


15  //{{{


16  {


17  block = _block;


18  if (!solve_map  block>width()!=wx  block>height()!=wy)


19  {


20  if (solve_map)


21  i4_free(solve_map);


22  wx = block>width();


23  wy = block>height();


24  solve_map = (w8*)i4_malloc(wx*wy,"solve_map");


25  }


26  }


27  //}}}


28 


29  g1_breadth_first_map_solver_class::~g1_breadth_first_map_solver_class()


30  //{{{


31  {


32  if (solve_map)


33  i4_free(solve_map);


34  }


35  //}}}


36 


37  i4_bool g1_breadth_first_map_solver_class::add_cell(w32 x,w32 y,w8 d, w32 length)


38  //{{{


39  {


40  if (d>0 &&


41  (x<0  x>=wx  y<0  y>=wy  is_visited(x,y)  block>is_blocked(x,y,d)))


42  return i4_F;


43 


44  set_solve_dir(x,y,d);


45  visit(x,y);


46 


47  cnx[head] = x;


48  cny[head] = y;


49  cnl[head] = length;


50  if (++head>=queue_length) head=0;


51 


52  if (head==tail)


53  i4_warning("queue overrun.");


54 


55  return i4_T;


56  }


57  //}}}


58 


59  i4_bool g1_breadth_first_map_solver_class::get_next_cell(w32 &x,w32 &y, w32 &length)


60  //{{{


61  {


62  if (tail==head)


63  return i4_F;


64 


65  x = cnx[tail];


66  y = cny[tail];


67  length = cnl[tail];


68  if (++tail>=queue_length) tail=0;


69 


70  return i4_T;


71  }


72  //}}}


73 


74  i4_bool g1_breadth_first_map_solver_class::path_solve(w32 startx, w32 starty,


75  w32 destx, w32 desty,


76  w8 sizex, w8 sizey, w8 grade,


77  i4_float *point, w16 &points)


78  //{{{


79  {


80  w32 x,y,l;


81 


82  clear_queue();


83  clear_solve();


84 


85  add_cell(startx,


86  starty,


87  0,0);


88 


89  int found=0;


90 


91  while (get_next_cell(x,y,l) && (x!=destx  y!=desty))


92  {


93  add_cell(x,y1,G1_NORTH,l+1);


94  add_cell(x,y+1,G1_SOUTH,l+1);


95  add_cell(x+1,y,G1_WEST,l+1);


96  add_cell(x1,y,G1_EAST,l+1);


97  }


98 


99  x = destx;


100  y = desty;


101 


102  w32 last_dir=0;


103  points = 0;


104  if (solve_dir(x,y)==0)


105  return i4_F;


106  while (x!=startx  y!=starty)


107  {


108  ok(x,y);


109  if (solve_dir(x,y)!=last_dir)


110  {


111  last_dir = solve_dir(x,y);


112  point[points*2]= i4_float(x)+0.5;


113  point[points*2+1]= i4_float(y)+0.5;


114  points++;


115  }


116  switch (solve_dir(x,y))


117  {


118  case G1_NORTH: y++; break;


119  case G1_SOUTH: y; break;


120  case G1_WEST: x; break;


121  case G1_EAST: x++; break;


122  default:


123  I4_ASSERT(0,"busted path solving!\n");


124  break;


125  }


126  }


127  ok(x,y);


128  point[points*2]= i4_float(x)+0.5;


129  point[points*2+1]=i4_float(y)+0.5;


130  points++;


131 


132  return i4_T;


133  }


134  //}}}


135 


136  //{{{ Emacs Locals


137  // Local Variables:


138  // foldedfile: t


139  // End:


140  //}}}

