DirTree *DirTree_FindExact(const DirTree *Tree, const char *Path) { static char Buff[_MAX_PATH]; DirTree * Siblings; assert(Tree); assert(Path); if (*Path == '\\') return NULL; if (*Path == '\0') return (DirTree *)Tree; Path = GetNextDir(Path, Buff); Siblings = Tree->Children; while (Siblings) { if (!stricmp(Siblings->Name, Buff)) { if (!*Path) return Siblings; return DirTree_FindExact(Siblings, Path); } Siblings = Siblings->Siblings; } return NULL; }
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); }