* Perform the effects stored in the object to the simulator world. * @param sim Simulator object to modify. * @post Effects have been copied to the simulator world, and the #ToolEffects * object is ready for the next use. */
| 111 | * object is ready for the next use. |
| 112 | */ |
| 113 | void ToolEffects::modifyWorld() |
| 114 | { |
| 115 | WorldModificationsMap::const_iterator modIter; |
| 116 | FrontendMessages::const_iterator msgIter; |
| 117 | Micropolis *mpolis = this->sim; |
| 118 | |
| 119 | mpolis->spend(this->cost); // Spend the costs |
| 120 | mpolis->updateFunds(); |
| 121 | |
| 122 | /* Modify the world. */ |
| 123 | for (modIter = this->modifications.begin(); |
| 124 | modIter != this->modifications.end(); modIter++) { |
| 125 | Position pos(modIter->first); |
| 126 | mpolis->map[pos.posX][pos.posY] = modIter->second; |
| 127 | } |
| 128 | |
| 129 | /* And finally send the messages. */ |
| 130 | for (msgIter = this->frontendMessages.begin(); |
| 131 | msgIter != this->frontendMessages.end(); msgIter++) { |
| 132 | (*msgIter)->sendMessage(mpolis); |
| 133 | } |
| 134 | |
| 135 | this->clear(); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * If there are enough funds, apply the effects. |
no test coverage detected