AINodeStorage.cpp 17 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688
  1. /*
  2. * AINodeStorage.cpp, part of VCMI engine
  3. *
  4. * Authors: listed in file AUTHORS in main folder
  5. *
  6. * License: GNU General Public License v2.0 or later
  7. * Full text of license available in license.txt file, in main folder
  8. *
  9. */
  10. #include "StdInc.h"
  11. #include "AINodeStorage.h"
  12. #include "Actions/TownPortalAction.h"
  13. #include "../Goals/Goals.h"
  14. #include "../../../CCallback.h"
  15. #include "../../../lib/mapping/CMap.h"
  16. #include "../../../lib/mapObjects/MapObjects.h"
  17. #include "../../../lib/PathfinderUtil.h"
  18. #include "../../../lib/CPlayerState.h"
  19. AINodeStorage::AINodeStorage(const int3 & Sizes)
  20. : sizes(Sizes)
  21. {
  22. nodes.resize(boost::extents[sizes.x][sizes.y][sizes.z][EPathfindingLayer::NUM_LAYERS][NUM_CHAINS]);
  23. dangerEvaluator.reset(new FuzzyHelper());
  24. }
  25. AINodeStorage::~AINodeStorage() = default;
  26. void AINodeStorage::initialize(const PathfinderOptions & options, const CGameState * gs)
  27. {
  28. if(heroChainPass)
  29. return;
  30. //TODO: fix this code duplication with NodeStorage::initialize, problem is to keep `resetTile` inline
  31. int3 pos;
  32. const PlayerColor player = ai->playerID;
  33. const int3 sizes = gs->getMapSize();
  34. const auto & fow = static_cast<const CGameInfoCallback *>(gs)->getPlayerTeam(player)->fogOfWarMap;
  35. //make 200% sure that these are loop invariants (also a bit shorter code), let compiler do the rest(loop unswitching)
  36. const bool useFlying = options.useFlying;
  37. const bool useWaterWalking = options.useWaterWalking;
  38. for(pos.x=0; pos.x < sizes.x; ++pos.x)
  39. {
  40. for(pos.y=0; pos.y < sizes.y; ++pos.y)
  41. {
  42. for(pos.z=0; pos.z < sizes.z; ++pos.z)
  43. {
  44. const TerrainTile * tile = &gs->map->getTile(pos);
  45. switch(tile->terType)
  46. {
  47. case ETerrainType::ROCK:
  48. break;
  49. case ETerrainType::WATER:
  50. resetTile(pos, ELayer::SAIL, PathfinderUtil::evaluateAccessibility<ELayer::SAIL>(pos, tile, fow, player, gs));
  51. if(useFlying)
  52. resetTile(pos, ELayer::AIR, PathfinderUtil::evaluateAccessibility<ELayer::AIR>(pos, tile, fow, player, gs));
  53. if(useWaterWalking)
  54. resetTile(pos, ELayer::WATER, PathfinderUtil::evaluateAccessibility<ELayer::WATER>(pos, tile, fow, player, gs));
  55. break;
  56. default:
  57. resetTile(pos, ELayer::LAND, PathfinderUtil::evaluateAccessibility<ELayer::LAND>(pos, tile, fow, player, gs));
  58. if(useFlying)
  59. resetTile(pos, ELayer::AIR, PathfinderUtil::evaluateAccessibility<ELayer::AIR>(pos, tile, fow, player, gs));
  60. break;
  61. }
  62. }
  63. }
  64. }
  65. }
  66. void AINodeStorage::clear()
  67. {
  68. actors.clear();
  69. heroChainPass = false;
  70. }
  71. const AIPathNode * AINodeStorage::getAINode(const CGPathNode * node) const
  72. {
  73. return static_cast<const AIPathNode *>(node);
  74. }
  75. void AINodeStorage::updateAINode(CGPathNode * node, std::function<void(AIPathNode *)> updater)
  76. {
  77. auto aiNode = static_cast<AIPathNode *>(node);
  78. updater(aiNode);
  79. }
  80. boost::optional<AIPathNode *> AINodeStorage::getOrCreateNode(
  81. const int3 & pos,
  82. const EPathfindingLayer layer,
  83. const ChainActor * actor)
  84. {
  85. auto chains = nodes[pos.x][pos.y][pos.z][layer];
  86. for(AIPathNode & node : chains)
  87. {
  88. if(node.actor == actor)
  89. {
  90. return &node;
  91. }
  92. if(!node.actor)
  93. {
  94. node.actor = actor;
  95. return &node;
  96. }
  97. }
  98. return boost::none;
  99. }
  100. std::vector<CGPathNode *> AINodeStorage::getInitialNodes()
  101. {
  102. if(heroChainPass)
  103. return heroChain;
  104. std::vector<CGPathNode *> initialNodes;
  105. for(auto actorPtr : actors)
  106. {
  107. ChainActor * actor = actorPtr.get();
  108. AIPathNode * initialNode =
  109. getOrCreateNode(actor->initialPosition, actor->layer, actor)
  110. .get();
  111. initialNode->turns = actor->initialTurn;
  112. initialNode->moveRemains = actor->initialMovement;
  113. initialNode->danger = 0;
  114. initialNode->cost = actor->initialTurn;
  115. initialNode->action = CGPathNode::ENodeAction::NORMAL;
  116. if(actor->isMovable)
  117. {
  118. initialNodes.push_back(initialNode);
  119. }
  120. else
  121. {
  122. initialNode->locked = true;
  123. }
  124. }
  125. return initialNodes;
  126. }
  127. void AINodeStorage::resetTile(const int3 & coord, EPathfindingLayer layer, CGPathNode::EAccessibility accessibility)
  128. {
  129. for(int i = 0; i < NUM_CHAINS; i++)
  130. {
  131. AIPathNode & heroNode = nodes[coord.x][coord.y][coord.z][layer][i];
  132. heroNode.actor = nullptr;
  133. heroNode.danger = 0;
  134. heroNode.manaCost = 0;
  135. heroNode.specialAction.reset();
  136. heroNode.armyLoss = 0;
  137. heroNode.chainOther = nullptr;
  138. heroNode.update(coord, layer, accessibility);
  139. }
  140. }
  141. void AINodeStorage::commit(CDestinationNodeInfo & destination, const PathNodeInfo & source)
  142. {
  143. const AIPathNode * srcNode = getAINode(source.node);
  144. updateAINode(destination.node, [&](AIPathNode * dstNode)
  145. {
  146. commit(dstNode, srcNode, destination.action, destination.turn, destination.movementLeft, destination.cost);
  147. if(dstNode->specialAction && dstNode->actor)
  148. {
  149. dstNode->specialAction->applyOnDestination(dstNode->actor->hero, destination, source, dstNode, srcNode);
  150. }
  151. #ifdef VCMI_TRACE_PATHFINDER_EX
  152. logAi->trace(
  153. "Commited %s -> %s, cost: %f, hero: %s, mask: %i",
  154. source.coord.toString(),
  155. destination.coord.toString(),
  156. destination.cost,
  157. dstNode->actor->hero->name,
  158. dstNode->actor->chainMask);
  159. #endif
  160. });
  161. }
  162. void AINodeStorage::commit(
  163. AIPathNode * destination,
  164. const AIPathNode * source,
  165. CGPathNode::ENodeAction action,
  166. int turn,
  167. int movementLeft,
  168. float cost) const
  169. {
  170. destination->action = action;
  171. destination->cost = cost;
  172. destination->moveRemains = movementLeft;
  173. destination->turns = turn;
  174. destination->armyLoss = source->armyLoss;
  175. destination->manaCost = source->manaCost;
  176. destination->danger = source->danger;
  177. destination->theNodeBefore = source->theNodeBefore;
  178. destination->chainOther = nullptr;
  179. }
  180. std::vector<CGPathNode *> AINodeStorage::calculateNeighbours(
  181. const PathNodeInfo & source,
  182. const PathfinderConfig * pathfinderConfig,
  183. const CPathfinderHelper * pathfinderHelper)
  184. {
  185. std::vector<CGPathNode *> neighbours;
  186. neighbours.reserve(16);
  187. const AIPathNode * srcNode = getAINode(source.node);
  188. auto accessibleNeighbourTiles = pathfinderHelper->getNeighbourTiles(source);
  189. for(auto & neighbour : accessibleNeighbourTiles)
  190. {
  191. for(EPathfindingLayer i = EPathfindingLayer::LAND; i <= EPathfindingLayer::AIR; i.advance(1))
  192. {
  193. auto nextNode = getOrCreateNode(neighbour, i, srcNode->actor);
  194. if(!nextNode || nextNode.get()->accessible == CGPathNode::NOT_SET)
  195. continue;
  196. neighbours.push_back(nextNode.get());
  197. }
  198. }
  199. return neighbours;
  200. }
  201. bool AINodeStorage::calculateHeroChain()
  202. {
  203. heroChainPass = true;
  204. heroChain.resize(0);
  205. std::vector<AIPathNode *> buffer;
  206. buffer.reserve(NUM_CHAINS);
  207. foreach_tile_pos([&](const int3 & pos) {
  208. auto layer = EPathfindingLayer::LAND;
  209. auto chains = nodes[pos.x][pos.y][pos.z][layer];
  210. buffer.resize(0);
  211. for(AIPathNode & node : chains)
  212. {
  213. if(node.turns <= heroChainMaxTurns && node.action != CGPathNode::ENodeAction::UNKNOWN)
  214. buffer.push_back(&node);
  215. }
  216. for(AIPathNode * node : buffer)
  217. {
  218. addHeroChain(node, buffer);
  219. }
  220. });
  221. return heroChain.size();
  222. }
  223. void AINodeStorage::addHeroChain(AIPathNode * srcNode, std::vector<AIPathNode *> variants)
  224. {
  225. for(AIPathNode * node : variants)
  226. {
  227. if(node == srcNode || !node->actor || node->turns > heroChainMaxTurns
  228. || node->action == CGPathNode::ENodeAction::UNKNOWN && node->actor->hero)
  229. {
  230. continue;
  231. }
  232. #ifdef VCMI_TRACE_PATHFINDER_EX
  233. logAi->trace(
  234. "Thy exchange %s[%i] -> %s[%i] at %s",
  235. node->actor->hero->name,
  236. node->actor->chainMask,
  237. srcNode->actor->hero->name,
  238. srcNode->actor->chainMask,
  239. srcNode->coord.toString());
  240. #endif
  241. addHeroChain(srcNode, node);
  242. //addHeroChain(&node, srcNode);
  243. }
  244. }
  245. void AINodeStorage::addHeroChain(AIPathNode * carrier, AIPathNode * other)
  246. {
  247. if(carrier->actor->canExchange(other->actor))
  248. {
  249. #ifdef VCMI_TRACE_PATHFINDER_EX
  250. logAi->trace(
  251. "Exchange allowed %s[%i] -> %s[%i] at %s",
  252. other->actor->hero->name,
  253. other->actor->chainMask,
  254. carrier->actor->hero->name,
  255. carrier->actor->chainMask,
  256. carrier->coord.toString());
  257. #endif
  258. bool hasLessMp = carrier->turns > other->turns || carrier->moveRemains < other->moveRemains;
  259. bool hasLessExperience = carrier->actor->hero->exp < other->actor->hero->exp;
  260. if(hasLessMp && hasLessExperience)
  261. {
  262. #ifdef VCMI_TRACE_PATHFINDER_EX
  263. logAi->trace("Exchange at %s is ineficient. Blocked.", carrier->coord.toString());
  264. #endif
  265. return;
  266. }
  267. auto newActor = carrier->actor->exchange(other->actor);
  268. auto chainNodeOptional = getOrCreateNode(carrier->coord, carrier->layer, newActor);
  269. if(!chainNodeOptional)
  270. {
  271. #ifdef VCMI_TRACE_PATHFINDER_EX
  272. logAi->trace("Exchange at %s can not allocate node. Blocked.", carrier->coord.toString());
  273. #endif
  274. return;
  275. }
  276. auto chainNode = chainNodeOptional.get();
  277. if(chainNode->action != CGPathNode::ENodeAction::UNKNOWN)
  278. {
  279. #ifdef VCMI_TRACE_PATHFINDER_EX
  280. logAi->trace("Exchange at %s node is already in use. Blocked.", carrier->coord.toString());
  281. #endif
  282. return;
  283. }
  284. if(commitExchange(chainNode, carrier, other))
  285. {
  286. #ifdef VCMI_TRACE_PATHFINDER_EX
  287. logAi->trace(
  288. "Chain accepted at %s %s -> %s, mask %i, cost %f",
  289. chainNode->coord.toString(),
  290. other->actor->hero->name,
  291. chainNode->actor->hero->name,
  292. chainNode->actor->chainMask,
  293. chainNode->cost);
  294. #endif
  295. heroChain.push_back(chainNode);
  296. }
  297. }
  298. }
  299. bool AINodeStorage::commitExchange(
  300. AIPathNode * exchangeNode,
  301. AIPathNode * carrierParentNode,
  302. AIPathNode * otherParentNode) const
  303. {
  304. auto carrierActor = carrierParentNode->actor;
  305. auto exchangeActor = exchangeNode->actor;
  306. auto otherActor = otherParentNode->actor;
  307. auto armyLoss = carrierParentNode->armyLoss + otherParentNode->armyLoss;
  308. auto turns = carrierParentNode->turns;
  309. auto cost = carrierParentNode->cost + otherParentNode->cost / 1000.0;
  310. auto movementLeft = carrierParentNode->moveRemains;
  311. if(carrierParentNode->turns < otherParentNode->turns)
  312. {
  313. int moveRemains = exchangeActor->hero->maxMovePoints(exchangeNode->layer);
  314. float waitingCost = otherParentNode->turns - carrierParentNode->turns - 1
  315. + carrierParentNode->moveRemains / (float)moveRemains;
  316. turns = otherParentNode->turns;
  317. cost += waitingCost;
  318. movementLeft = moveRemains;
  319. }
  320. if(exchangeNode->turns != 0xFF && exchangeNode->cost < cost)
  321. {
  322. #ifdef VCMI_TRACE_PATHFINDER_EX
  323. logAi->trace("Exchange at %s is is not effective enough. %f < %f", exchangeNode->coord.toString(), exchangeNode->cost, cost);
  324. #endif
  325. return false;
  326. }
  327. commit(exchangeNode, carrierParentNode, carrierParentNode->action, turns, movementLeft, cost);
  328. exchangeNode->chainOther = otherParentNode;
  329. exchangeNode->armyLoss = armyLoss;
  330. return true;
  331. }
  332. const CGHeroInstance * AINodeStorage::getHero(const CGPathNode * node) const
  333. {
  334. auto aiNode = getAINode(node);
  335. return aiNode->actor->hero;
  336. }
  337. const std::set<const CGHeroInstance *> AINodeStorage::getAllHeroes() const
  338. {
  339. std::set<const CGHeroInstance *> heroes;
  340. for(auto actor : actors)
  341. {
  342. if(actor->hero)
  343. heroes.insert(actor->hero);
  344. }
  345. return heroes;
  346. }
  347. void AINodeStorage::setHeroes(std::vector<HeroPtr> heroes, const VCAI * _ai)
  348. {
  349. cb = _ai->myCb.get();
  350. ai = _ai;
  351. for(auto & hero : heroes)
  352. {
  353. uint64_t mask = 1 << actors.size();
  354. actors.push_back(std::make_shared<HeroActor>(hero.get(), mask));
  355. }
  356. }
  357. std::vector<CGPathNode *> AINodeStorage::calculateTeleportations(
  358. const PathNodeInfo & source,
  359. const PathfinderConfig * pathfinderConfig,
  360. const CPathfinderHelper * pathfinderHelper)
  361. {
  362. std::vector<CGPathNode *> neighbours;
  363. if(source.isNodeObjectVisitable())
  364. {
  365. auto accessibleExits = pathfinderHelper->getTeleportExits(source);
  366. auto srcNode = getAINode(source.node);
  367. for(auto & neighbour : accessibleExits)
  368. {
  369. auto node = getOrCreateNode(neighbour, source.node->layer, srcNode->actor);
  370. if(!node)
  371. continue;
  372. neighbours.push_back(node.get());
  373. }
  374. }
  375. if(source.isInitialPosition)
  376. {
  377. calculateTownPortalTeleportations(source, neighbours);
  378. }
  379. return neighbours;
  380. }
  381. void AINodeStorage::calculateTownPortalTeleportations(
  382. const PathNodeInfo & source,
  383. std::vector<CGPathNode *> & neighbours)
  384. {
  385. SpellID spellID = SpellID::TOWN_PORTAL;
  386. const CSpell * townPortal = spellID.toSpell();
  387. auto srcNode = getAINode(source.node);
  388. auto hero = srcNode->actor->hero;
  389. if(hero->canCastThisSpell(townPortal) && hero->mana >= hero->getSpellCost(townPortal))
  390. {
  391. auto towns = cb->getTownsInfo(false);
  392. vstd::erase_if(towns, [&](const CGTownInstance * t) -> bool
  393. {
  394. return cb->getPlayerRelations(hero->tempOwner, t->tempOwner) == PlayerRelations::ENEMIES;
  395. });
  396. if(!towns.size())
  397. {
  398. return;
  399. }
  400. // TODO: Copy/Paste from TownPortalMechanics
  401. auto skillLevel = hero->getSpellSchoolLevel(townPortal);
  402. auto movementCost = GameConstants::BASE_MOVEMENT_COST * (skillLevel >= 3 ? 2 : 3);
  403. if(hero->movement < movementCost)
  404. {
  405. return;
  406. }
  407. if(skillLevel < SecSkillLevel::ADVANCED)
  408. {
  409. const CGTownInstance * nearestTown = *vstd::minElementByFun(towns, [&](const CGTownInstance * t) -> int
  410. {
  411. return hero->visitablePos().dist2dSQ(t->visitablePos());
  412. });
  413. towns = std::vector<const CGTownInstance *>{ nearestTown };
  414. }
  415. for(const CGTownInstance * targetTown : towns)
  416. {
  417. if(targetTown->visitingHero)
  418. continue;
  419. auto nodeOptional = getOrCreateNode(targetTown->visitablePos(), EPathfindingLayer::LAND, srcNode->actor->castActor);
  420. if(nodeOptional)
  421. {
  422. #ifdef VCMI_TRACE_PATHFINDER
  423. logAi->trace("Adding town portal node at %s", targetTown->name);
  424. #endif
  425. AIPathNode * node = nodeOptional.get();
  426. node->theNodeBefore = source.node;
  427. node->specialAction.reset(new AIPathfinding::TownPortalAction(targetTown));
  428. node->moveRemains = source.node->moveRemains;
  429. neighbours.push_back(node);
  430. }
  431. }
  432. }
  433. }
  434. bool AINodeStorage::hasBetterChain(const PathNodeInfo & source, CDestinationNodeInfo & destination) const
  435. {
  436. auto pos = destination.coord;
  437. auto chains = nodes[pos.x][pos.y][pos.z][EPathfindingLayer::LAND];
  438. auto destinationNode = getAINode(destination.node);
  439. for(const AIPathNode & node : chains)
  440. {
  441. auto sameNode = node.actor == destinationNode->actor;
  442. if(sameNode || node.action == CGPathNode::ENodeAction::UNKNOWN)
  443. {
  444. continue;
  445. }
  446. if(node.danger <= destinationNode->danger && destinationNode->actor == node.actor->battleActor)
  447. {
  448. if(node.cost < destinationNode->cost)
  449. {
  450. #ifdef VCMI_TRACE_PATHFINDER
  451. logAi->trace(
  452. "Block ineficient move %s:->%s, mask=%i, mp diff: %i",
  453. source.coord.toString(),
  454. destination.coord.toString(),
  455. destinationNode->actor->chainMask,
  456. node.moveRemains - destinationNode->moveRemains);
  457. #endif
  458. return true;
  459. }
  460. }
  461. }
  462. return false;
  463. }
  464. bool AINodeStorage::isTileAccessible(const HeroPtr & hero, const int3 & pos, const EPathfindingLayer layer) const
  465. {
  466. auto chains = nodes[pos.x][pos.y][pos.z][layer];
  467. for(const AIPathNode & node : chains)
  468. {
  469. if(node.action != CGPathNode::ENodeAction::UNKNOWN
  470. && node.actor && node.actor->hero == hero.h)
  471. {
  472. return true;
  473. }
  474. }
  475. return false;
  476. }
  477. std::vector<AIPath> AINodeStorage::getChainInfo(const int3 & pos, bool isOnLand) const
  478. {
  479. std::vector<AIPath> paths;
  480. paths.reserve(NUM_CHAINS / 4);
  481. auto chains = nodes[pos.x][pos.y][pos.z][isOnLand ? EPathfindingLayer::LAND : EPathfindingLayer::SAIL];
  482. for(const AIPathNode & node : chains)
  483. {
  484. if(node.action == CGPathNode::ENodeAction::UNKNOWN || !node.actor || !node.actor->hero)
  485. {
  486. continue;
  487. }
  488. AIPath path;
  489. path.targetHero = node.actor->hero;
  490. path.heroArmy = node.actor->creatureSet;
  491. path.armyLoss = node.armyLoss;
  492. path.targetObjectDanger = evaluateDanger(pos, path.targetHero);
  493. path.chainMask = node.actor->chainMask;
  494. fillChainInfo(&node, path);
  495. paths.push_back(path);
  496. }
  497. return paths;
  498. }
  499. void AINodeStorage::fillChainInfo(const AIPathNode * node, AIPath & path) const
  500. {
  501. while(node != nullptr)
  502. {
  503. if(!node->actor->hero)
  504. return;
  505. if(node->chainOther)
  506. fillChainInfo(node->chainOther, path);
  507. if(node->actor->hero->visitablePos() != node->coord)
  508. {
  509. AIPathNodeInfo pathNode;
  510. pathNode.cost = node->cost;
  511. pathNode.targetHero = node->actor->hero;
  512. pathNode.turns = node->turns;
  513. pathNode.danger = node->danger;
  514. pathNode.coord = node->coord;
  515. path.nodes.push_back(pathNode);
  516. }
  517. path.specialAction = node->specialAction;
  518. node = getAINode(node->theNodeBefore);
  519. }
  520. }
  521. AIPath::AIPath()
  522. : nodes({})
  523. {
  524. }
  525. int3 AIPath::firstTileToGet() const
  526. {
  527. if(nodes.size())
  528. {
  529. return nodes.back().coord;
  530. }
  531. return int3(-1, -1, -1);
  532. }
  533. const AIPathNodeInfo & AIPath::firstNode() const
  534. {
  535. return nodes.back();
  536. }
  537. uint64_t AIPath::getPathDanger() const
  538. {
  539. if(nodes.size())
  540. {
  541. return nodes.front().danger;
  542. }
  543. return 0;
  544. }
  545. float AIPath::movementCost() const
  546. {
  547. if(nodes.size())
  548. {
  549. return nodes.front().cost;
  550. }
  551. // TODO: boost:optional?
  552. return 0.0;
  553. }
  554. uint64_t AIPath::getHeroStrength() const
  555. {
  556. return targetHero->getFightingStrength() * heroArmy->getArmyStrength();
  557. }
  558. uint64_t AIPath::getTotalDanger(HeroPtr hero) const
  559. {
  560. uint64_t pathDanger = getPathDanger();
  561. uint64_t danger = pathDanger > targetObjectDanger ? pathDanger : targetObjectDanger;
  562. return danger;
  563. }