Beispiel #1
0
/// Find a route for trade caravanes
unsigned char GameWorldGame::FindTradePath(const MapPoint start, 
        const MapPoint dest,  const unsigned char player,  const unsigned max_route,  const bool random_route, 
        std::vector<unsigned char>* route,  unsigned* length, 
        const bool record) const
{
    //unsigned tt = GetTickCount();
    //static unsigned cc = 0;
    //++cc;

    unsigned char pp = GetNode(dest).owner;
    if(!(pp == 0 || GetPlayer(player).IsAlly(pp - 1)))
        return 0xff;
    bool is_warehouse_at_goal = false;
    if(GetNO(dest)->GetType() == NOP_BUILDING)
    {
        if(GetSpecObj<noBuilding>(dest)->IsWarehouse())
            is_warehouse_at_goal = true;
    }

    if(!IsNodeForFigures(dest) && !is_warehouse_at_goal )
        return 0xff;

    unsigned char first_dir = 0xFF;
    FindFreePath(start,  dest,  random_route,  max_route,  route,  length,  &first_dir,  IsPointOK_TradePath, 
                 IsPointToDestOK_TradePath,  &player,  record);

    //if(GetTickCount()-tt > 100)
    //  printf("%u: %u ms; (%u, %u) to (%u, %u)\n", cc, GetTickCount()-tt, start.x, start.y, dest.x, dest.y);

    return first_dir;
}
Beispiel #2
0
/// Find a route for trade caravanes
unsigned char GameWorldGame::FindTradePath(const MapPoint start, const MapPoint dest, unsigned char player, unsigned max_route, bool random_route, 
        std::vector<unsigned char>* route, unsigned* length) const
{
    unsigned char owner = GetNode(dest).owner;
    if(owner != 0 && !GetPlayer(player).IsAlly(owner -1))
        return INVALID_DIR;
    
    RTTR_Assert(GetNO(dest)->GetType() == NOP_FLAG); // Goal should be the flag of a wh

    if(!IsNodeForFigures(dest))
        return INVALID_DIR;

    unsigned char first_dir = INVALID_DIR;
    GetFreePathFinder().FindPath(start, dest, random_route, max_route, route, length, &first_dir, PathConditionTrade(*this, player));

    return first_dir;
}