| 111 | } |
| 112 | |
| 113 | void Trap::doUpkeep() |
| 114 | { |
| 115 | Building::doUpkeep(); |
| 116 | |
| 117 | // We remove trap entities if we can |
| 118 | for(auto it = mTrapEntitiesWaitingRemove.begin(); it != mTrapEntitiesWaitingRemove.end();) |
| 119 | { |
| 120 | BuildingObject* trapEntity = *it; |
| 121 | if(!trapEntity->notifyRemoveAsked()) |
| 122 | { |
| 123 | ++it; |
| 124 | continue; |
| 125 | } |
| 126 | |
| 127 | removeBuildingObject(trapEntity); |
| 128 | it = mTrapEntitiesWaitingRemove.erase(it); |
| 129 | } |
| 130 | |
| 131 | if (numCoveredTiles() <= 0) |
| 132 | return; |
| 133 | |
| 134 | for(Tile* tile : mCoveredTiles) |
| 135 | { |
| 136 | // If the trap is deactivated, it cannot shoot |
| 137 | TrapTileData* trapTileData = static_cast<TrapTileData*>(mTileData[tile]); |
| 138 | if (!trapTileData->isActivated()) |
| 139 | continue; |
| 140 | |
| 141 | if(trapTileData->decreaseReloadTime()) |
| 142 | continue; |
| 143 | |
| 144 | if(shoot(tile)) |
| 145 | { |
| 146 | trapTileData->setReloadTime(mReloadTime); |
| 147 | if(!trapTileData->decreaseShoot()) |
| 148 | deactivate(tile); |
| 149 | |
| 150 | const std::vector<Seat*>& seats = tile->getSeatsWithVision(); |
| 151 | trapTileData->seatsSawTriggering(seats); |
| 152 | |
| 153 | for(Seat* seat : trapTileData->mSeatsVision) |
| 154 | seat->setVisibleBuildingOnTile(this, tile); |
| 155 | } |
| 156 | } |
| 157 | } |
| 158 | |
| 159 | int32_t Trap::getNbNeededCraftedTrap() const |
| 160 | { |
no test coverage detected