GLvoid CImp::checkNearestForClaiming() { if(m_impState != IS_IDLE) return; std::vector<CBlock*> unclaimedBlocks,claimedBlocks,possBlocks; std::vector<CBlock*>::iterator unclaimedBlocksIter, claimedBlocksIter; CBlock *block; if(CV_GAME_MANAGER->getLevelManager()->isBlockTypeNear(CV_BLOCK_TYPE_UNCLAIMED_LAND_ID,cml::vector2i((int)floor(mPosition[0]/CV_BLOCK_WIDTH),(int)floor(mPosition[2]/CV_BLOCK_DEPTH)),true,CV_PLAYER_UNDEFINED,&unclaimedBlocks)) { int oldSearchLimit = CV_GAME_MANAGER->getPathManager()->getSearchLimit(); CV_GAME_MANAGER->getPathManager()->setSearchLimit(2); for(unclaimedBlocksIter=unclaimedBlocks.begin(); unclaimedBlocksIter!=unclaimedBlocks.end(); unclaimedBlocksIter++) { block = *unclaimedBlocksIter; if(block->isTaken()) continue; claimedBlocks.clear(); if(CV_GAME_MANAGER->getLevelManager()->isBlockClaimable(block->getLogicalPosition(),this->getOwner(),&claimedBlocks)) { path.clear(); if(CV_GAME_MANAGER->getPathManager()->findPath(cml::vector2i((int)floor(mPosition[0]/CV_BLOCK_WIDTH),(int)floor(mPosition[2]/CV_BLOCK_DEPTH)),block->getLogicalPosition(),&path)) possBlocks.push_back(block); } } CV_GAME_MANAGER->getPathManager()->setSearchLimit(oldSearchLimit); if(possBlocks.size()>0) { GLint blockNum = rand()%possBlocks.size(); path.clear(); mCurrentBlock = possBlocks[blockNum]; path.push_back(mCurrentBlock->getLogicalPosition()); mCurrentBlock->setTaken(true); m_impState = IS_GOING_TO_CLAIMING_DESTINATION; return; } } }
GLvoid CImp::checkNearestForWalling() { if(m_impState != IS_IDLE) return; std::vector<CBlock*> unfortifiedBlocks,claimedBlocks,possBlocks; std::vector<CBlock*>::iterator unfortifiedBlocksIter; CBlock *block; if(CV_GAME_MANAGER->getLevelManager()->isBlockTypeNear(CV_BLOCK_TYPE_EARTH_ID,cml::vector2i((int)floor(mPosition[0]/CV_BLOCK_WIDTH),(int)floor(mPosition[2]/CV_BLOCK_DEPTH)),true,CV_PLAYER_UNDEFINED,&unfortifiedBlocks)) { int oldSearchLimit = CV_GAME_MANAGER->getPathManager()->getSearchLimit(); CV_GAME_MANAGER->getPathManager()->setSearchLimit(2); bool oldDiagonalMoves = CV_GAME_MANAGER->getPathManager()->getDiagonalMoves(); CV_GAME_MANAGER->getPathManager()->setDiagonalMoves(false); for(unfortifiedBlocksIter=unfortifiedBlocks.begin(); unfortifiedBlocksIter!=unfortifiedBlocks.end(); unfortifiedBlocksIter++) { block = *unfortifiedBlocksIter; claimedBlocks.clear(); if(CV_GAME_MANAGER->getLevelManager()->isBlockClaimable(block->getLogicalPosition(),this->getOwner(),&claimedBlocks)) { path.clear(); if(CV_GAME_MANAGER->getPathManager()->findPath(cml::vector2i((int)floor(mPosition[0]/CV_BLOCK_WIDTH),(int)floor(mPosition[2]/CV_BLOCK_DEPTH)),block->getLogicalPosition(),&path)) possBlocks.push_back(block); } } CV_GAME_MANAGER->getPathManager()->setSearchLimit(oldSearchLimit); CV_GAME_MANAGER->getPathManager()->setDiagonalMoves(oldDiagonalMoves); if(possBlocks.size()>0) { GLint blockNum = rand()%possBlocks.size(); mCurrentBlock = possBlocks[blockNum]; path.clear(); m_impState = IS_AT_WALLING_BLOCK; return; } } }
GLvoid CImp::checkNearestForDigging() { if(impState != IS_IDLE) return; std::vector<CBlock*> markedBlocks,possBlocks; std::vector<CBlock*>::iterator markedBlocksIter; CBlock *block; if(CV_GAME_MANAGER->getLevelManager()->isBlockTypeNear(CV_BLOCK_TYPE_EARTH_ID,cml::vector2i((int)floor(position[0]/CV_BLOCK_WIDTH),(int)floor(position[2]/CV_BLOCK_DEPTH)),true,CV_PLAYER_UNDEFINED,&markedBlocks)) { int oldSearchLimit = CV_GAME_MANAGER->getPathManager()->getSearchLimit(); CV_GAME_MANAGER->getPathManager()->setSearchLimit(2); bool oldDiagonalMoves = CV_GAME_MANAGER->getPathManager()->getDiagonalMoves(); CV_GAME_MANAGER->getPathManager()->setDiagonalMoves(false); for(markedBlocksIter=markedBlocks.begin(); markedBlocksIter!=markedBlocks.end(); markedBlocksIter++) { block = *markedBlocksIter; if(!block->isMarked()) continue; path.clear(); if(CV_GAME_MANAGER->getPathManager()->findPath(cml::vector2i((int)floor(position[0]/CV_BLOCK_WIDTH),(int)floor(position[2]/CV_BLOCK_DEPTH)),block->getLogicalPosition(),&path)) possBlocks.push_back(block); } CV_GAME_MANAGER->getPathManager()->setSearchLimit(oldSearchLimit); CV_GAME_MANAGER->getPathManager()->setDiagonalMoves(oldDiagonalMoves); if(possBlocks.size()>0) { GLint blockNum = rand()%possBlocks.size(); currBlock = possBlocks[blockNum]; path.clear(); impState = IS_AT_DIGGING_BLOCK; return; } } }