| 362 | } |
| 363 | |
| 364 | void Trap::notifyCarryingStateChanged(Creature* carrier, GameEntity* carriedEntity) |
| 365 | { |
| 366 | if(carriedEntity == nullptr) |
| 367 | return; |
| 368 | |
| 369 | for(Tile* tile : mCoveredTiles) |
| 370 | { |
| 371 | auto it = mTileData.find(tile); |
| 372 | if(it == mTileData.end()) |
| 373 | continue; |
| 374 | |
| 375 | TrapTileData* trapTileData = static_cast<TrapTileData*>(it->second); |
| 376 | if(trapTileData->isActivated()) |
| 377 | continue; |
| 378 | if(trapTileData->getCarriedCraftedTrap() != carriedEntity) |
| 379 | continue; |
| 380 | |
| 381 | // We check if the carrier is at the expected destination |
| 382 | Tile* carrierTile = carrier->getPositionTile(); |
| 383 | if(carrierTile == nullptr) |
| 384 | { |
| 385 | OD_LOG_ERR("carrier=" + carrier->getName()); |
| 386 | trapTileData->setCarriedCraftedTrap(nullptr); |
| 387 | return; |
| 388 | } |
| 389 | |
| 390 | Tile* tileExpected = getGameMap()->getTile(tile->getX(), tile->getY()); |
| 391 | if(tileExpected != carrierTile) |
| 392 | { |
| 393 | trapTileData->setCarriedCraftedTrap(nullptr); |
| 394 | return; |
| 395 | } |
| 396 | |
| 397 | // The carrier has brought carried trap |
| 398 | CraftedTrap* craftedTrap = trapTileData->getCarriedCraftedTrap(); |
| 399 | craftedTrap->removeEntityFromPositionTile(); |
| 400 | craftedTrap->removeFromGameMap(); |
| 401 | craftedTrap->deleteYourself(); |
| 402 | activate(tile); |
| 403 | trapTileData->setCarriedCraftedTrap(nullptr); |
| 404 | } |
| 405 | // We couldn't find the entity in the list. That may happen if the active spot has |
| 406 | // been erased between the time the carrier tried to come and the time it arrived. |
| 407 | // In any case, nothing to do |
| 408 | } |
| 409 | |
| 410 | bool Trap::isAttackable(Tile* tile, Seat* seat) const |
| 411 | { |
no test coverage detected