Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- void InfluenceWorld::BFSToAddInfluence(int startingIndex)
- {
- float influence = 1.0f;
- std::queue<std::pair<int, float>> workingSet;
- std::map<int, bool> finishedSet;
- workingSet.push(std::make_pair(startingIndex, influence));
- while (!workingSet.empty())
- {
- std::pair<int, float> curIndexInfluencePair = workingSet.front();
- workingSet.pop();
- if (finishedSet.find(curIndexInfluencePair.first) != finishedSet.end())
- {
- continue;
- }
- int gridX = -1;
- int gridY = -1;
- GetGridPointFromIndex(curIndexInfluencePair.first, gridX, gridY);
- int neighborIndex = -1;
- if (curIndexInfluencePair.second / 2 >= 0.125)
- {
- if (gridX > 0)
- {
- neighborIndex = curIndexInfluencePair.first - 1;
- workingSet.push(std::make_pair(neighborIndex, (curIndexInfluencePair.second / 2)));
- }
- if (gridX < kWorldWidth - 1)
- {
- neighborIndex = curIndexInfluencePair.first + 1;
- workingSet.push(std::make_pair(neighborIndex, (curIndexInfluencePair.second / 2)));
- }
- if (gridY > 0)
- {
- neighborIndex = curIndexInfluencePair.first - kWorldWidth;
- workingSet.push(std::make_pair(neighborIndex, (curIndexInfluencePair.second / 2)));
- }
- if (gridY < kWorldHeight - 1)
- {
- neighborIndex = curIndexInfluencePair.first + kWorldWidth;
- workingSet.push(std::make_pair(neighborIndex, (curIndexInfluencePair.second / 2)));
- }
- }
- m_pTiles[curIndexInfluencePair.first]->AddInfluence(curIndexInfluencePair.second);
- finishedSet[curIndexInfluencePair.first] = true;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement