void nofTradeDonkey::Walked()
{
	if(next_dirs.size()<1)
	{
		//WanderFailedTrade();
		gwg->RemoveFigure(this,x,y);
	    return;
	}
	unsigned char next_dir = GetNextDir();
	// Are we now at the goal?
	if(next_dir == REACHED_GOAL)
	{
		noBase * nob = gwg->GetNO(x,y);
		bool invalid_goal = false;
		if(nob->GetType() != NOP_BUILDING)
			invalid_goal = true; 
		else if(!static_cast<noBuilding*>(nob)->IsWarehouse())
			invalid_goal = true;

		if(invalid_goal)
		{
			CancelTradeCaravane();
			WanderFailedTrade();
			return;
		}

		gwg->GetPlayer(static_cast<nobBaseWarehouse*>(nob)->GetPlayer())
			->IncreaseInventoryJob(this->GetJobType(),1);
		gwg->RemoveFigure(this,x,y);
		static_cast<nobBaseWarehouse*>(nob)->AddFigure(this);
		
		// Add also our ware if we carry one
		if(gt != GD_NOTHING)
		{
			Goods goods;
			goods.goods[gt] = 1;
			static_cast<nobBaseWarehouse*>(nob)->AddGoods(goods);
			gwg->GetPlayer(static_cast<nobBaseWarehouse*>(nob)->GetPlayer())
				->IncreaseInventoryWare(gt,1);

		}
	}
	else
	{
		if(next_dir!=NO_PATH)
			StartWalking(next_dir);
		else
		{
			CancelTradeCaravane();
			WanderFailedTrade();
		}
	}
	if(successor)
		successor->AddNextDir(next_dir);
}
void nofTradeLeader::Walked()
{
    // Exception handling: goal destroyed or sth. like this
    if(fails > 1)
    {
        WanderFailedTrade();
        return;
    }
    bool invalid_goal = false;

    noBase* nob = gwg->GetNO(goal_);
    if(nob->GetType() != NOP_BUILDING)
        invalid_goal = true;
    if(!static_cast<noBuilding*>(nob)->IsWarehouse())
        invalid_goal = true;

    unsigned char next_dir;
    if(invalid_goal)
    {
        TryToGoHome();
        next_dir = tr.GetNextDir();
        StartWalking(next_dir);
    }
    else
    {

        next_dir = tr.GetNextDir();
        // Are we now at the goal?
        if(next_dir == REACHED_GOAL)
        {
            gwg->GetPlayer(static_cast<nobBaseWarehouse*>(nob)->GetPlayer()).IncreaseInventoryJob(this->GetJobType(), 1);
            gwg->RemoveFigure(this, pos);
            static_cast<nobBaseWarehouse*>(nob)->AddFigure(this);
        }
        else if(next_dir != NO_PATH)
            StartWalking(next_dir);
        else
        {
            TryToGoHome();
            next_dir = tr.GetNextDir();
            if(next_dir == NO_PATH)
            {
                CancelTradeCaravane();
                next_dir = GetCurMoveDir();
                //StartWanderingFailedTrade();
            }
            StartWalking(next_dir);
            //next_dir=tr.GetNextDir();
            //next_dir = dir;
        }

    }

    //if(successor&&next_dir!=NO_PATH)
    if(successor)
    {
        successor->AddNextDir(next_dir);
    }
}