MCPcopy Create free account
hub / github.com/OpenDungeons/OpenDungeons / lookForGold

Method lookForGold

source/ai/KeeperAI.cpp:358–513  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

356}
357
358bool KeeperAI::lookForGold()
359{
360 if (mNoMoreReachableGold)
361 return false;
362
363 if(mCooldownLookingForGold > 0)
364 {
365 --mCooldownLookingForGold;
366 return false;
367 }
368
369 mCooldownLookingForGold = Random::Int(70,120);
370
371 // Do we need gold ?
372 int emptyStorage = 0;
373 for(Room* room : mGameMap.getRooms())
374 {
375 if(room->getSeat() != mPlayer.getSeat())
376 continue;
377
378 emptyStorage += (room->getTotalGoldStorage() - room->getTotalGoldStored());
379 }
380
381 // No need to search for gold
382 if(emptyStorage < 100)
383 return false;
384
385 Tile* central = getDungeonTemple()->getCentralTile();
386 int widerSide = mGameMap.getMapSizeX() > mGameMap.getMapSizeY() ?
387 mGameMap.getMapSizeX() : mGameMap.getMapSizeY();
388
389 // We search for the closest gold tile
390 Tile* firstGoldTile = nullptr;
391 for(int32_t distance = 1; distance < widerSide; ++distance)
392 {
393 for(int k = 0; k <= distance; ++k)
394 {
395 Tile* t;
396 // North-East
397 t = mGameMap.getTile(central->getX() + k, central->getY() + distance);
398 if(t != nullptr && t->getType() == TileType::gold && t->getFullness() > 0.0)
399 {
400 // If we already have a tile at same distance, we randomly change to
401 // try to not be too predictable
402 if((firstGoldTile == nullptr) || (Random::Uint(1,2) == 1))
403 firstGoldTile = t;
404 }
405 // North-West
406 if(k > 0)
407 {
408 t = mGameMap.getTile(central->getX() - k, central->getY() + distance);
409 if(t != nullptr && t->getType() == TileType::gold && t->getFullness() > 0.0)
410 {
411 if((firstGoldTile == nullptr) || (Random::Uint(1,2) == 1))
412 firstGoldTile = t;
413 }
414 }
415 // South-East

Callers

nothing calls this directly

Calls 14

IntFunction · 0.85
UintFunction · 0.85
getCentralTileMethod · 0.80
getMapSizeXMethod · 0.80
getMapSizeYMethod · 0.80
getFullnessMethod · 0.80
setMarkedForDiggingMethod · 0.80
getSeatMethod · 0.45
getTotalGoldStorageMethod · 0.45
getTotalGoldStoredMethod · 0.45
getTileMethod · 0.45
getXMethod · 0.45

Tested by

no test coverage detected