Пример #1
0
int	Monster::UpdateQueue(Tile* p_tile, int p_parent, int p_toStart, int p_toGoal, vector<AstarItem>& p_queue)
{
    int index = FindTile(p_tile, p_queue);
    if (index >= 0 && p_queue[index].distance() > p_toStart + p_toGoal)
    {
        p_queue[index].toStart = p_toStart;
        p_queue[index].toGoal = p_toGoal;
        p_queue[index].parent = p_parent;
        while (index < (int)(p_queue.size()-1) && p_queue[index].distance() < p_queue[index+1].distance())
        {
            AstarItem temp = p_queue[index];
            p_queue[index] = p_queue[index+1];
            p_queue[index+1] = temp;
            index++;
        }
    }
    else
    {
        AstarItem star;
        star.toStart = p_toStart;
        star.toGoal = p_toGoal;
        star.tile = p_tile;
        star.parent = p_parent;
        p_queue.push_back(star);
        index = p_queue.size() - 1;
        while (index > 0 && p_queue[index].distance() > p_queue[index-1].distance())
        {
            AstarItem temp = p_queue[index];
            p_queue[index] = p_queue[index-1];
            p_queue[index-1] = temp;
            index--;
        }
    }
    return 0;
}
Пример #2
0
void GPath::FindAdjacent(GNode* gnode) {
  int x = gnode->GetX();
  int y = gnode->GetY(); 
 
  int dir = DIR_HV; 
 
  //App->Log << "Left\n";
  FindTile(gnode, x-1, y, dir);
  //App->Log << "Right\n";
  FindTile(gnode, x+1, y, dir);
  //App->Log << "Up\n";
  FindTile(gnode, x, y-1, dir);
  //App->Log << "Down\n";
  FindTile(gnode, x, y+1, dir);

  if (CalcDiag) {
    dir = DIR_DIAG;
    FindTile(gnode, x-1, y-1, dir);
    FindTile(gnode, x+1, y-1, dir);
    FindTile(gnode, x-1, y+1, dir);
    FindTile(gnode, x+1, y+1, dir);
  }
  //App->Log << "Quit adjacent\n";
}