void UnoccupiedTiles::SortList(sint32 *list, sint32 numItems, sint32 dominant) { sint32 comparePos ; BOOL swap, optimum ; Assert(numItems>0) ; Assert(list) ; Assert((list==m_bestFoodTiles) || (list==m_bestProductionTiles) || (list==m_bestGoldTiles)) ; Assert((dominant==DOMINANT_FOOD) || (dominant==DOMINANT_PRODUCTION) || (dominant==DOMINANT_GOLD)) ; if (numItems <= 1) { return ; } optimum = FALSE ; comparePos = numItems - 1 ; while (!optimum) { if (comparePos == 0) { break ; } Assert(comparePos>=1) ; swap = CompareTiles(list, comparePos, comparePos - 1, dominant) ; if (swap) { SwitchTiles(list, numItems, comparePos, comparePos - 1) ; comparePos-- ; } else { optimum = TRUE ; } } }
int CTileHandler::FindCloseTile(CBitmap* bm,int forbidden) { FastStat fs=CalcFastStat(bm); for(int a=0;a<usedTiles;++a){ if(a!=forbidden && abs(fs.r-fastStats[a].r)<meanThreshold && abs(fs.g-fastStats[a].g)<meanThreshold && abs(fs.b-fastStats[a].b)<meanThreshold && abs(fs.rx-fastStats[a].rx)<meanDirThreshold && abs(fs.gx-fastStats[a].gx)<meanDirThreshold && abs(fs.bx-fastStats[a].bx)<meanDirThreshold && abs(fs.ry-fastStats[a].ry)<meanDirThreshold && abs(fs.gy-fastStats[a].gy)<meanDirThreshold && abs(fs.by-fastStats[a].by)<meanDirThreshold && CompareTiles(bm,tiles[a])) return a; } fastStats[usedTiles]=fs; return -1; }