Ensure the building still exists and is in a valid state. It can disappear for lots of reasons, such as running the game with the buildingplan plugin disabled, manually removing the building, modifying it via the API, etc.
| 120 | // for lots of reasons, such as running the game with the buildingplan plugin |
| 121 | // disabled, manually removing the building, modifying it via the API, etc. |
| 122 | df::building * PlannedBuilding::getBuildingIfValidOrRemoveIfNot(color_ostream &out, bool skip_remove) { |
| 123 | auto bld = df::building::find(id); |
| 124 | bool valid = bld && bld->getBuildStage() == 0; |
| 125 | if (!valid) { |
| 126 | if (!skip_remove) |
| 127 | remove(out); |
| 128 | return NULL; |
| 129 | } |
| 130 | return bld; |
| 131 | } |
no test coverage detected