* The craft info can change * after going into other screens. */
| 170 | * after going into other screens. |
| 171 | */ |
| 172 | void CraftInfoState::init() |
| 173 | { |
| 174 | State::init(); |
| 175 | |
| 176 | _craft = _base->getCrafts()->at(_craftId); |
| 177 | |
| 178 | _edtCraft->setText(_craft->getName(_game->getLanguage())); |
| 179 | |
| 180 | SurfaceSet *texture = _game->getResourcePack()->getSurfaceSet("BASEBITS.PCK"); |
| 181 | texture->getFrame(_craft->getRules()->getSprite() + 33)->setX(0); |
| 182 | texture->getFrame(_craft->getRules()->getSprite() + 33)->setY(0); |
| 183 | texture->getFrame(_craft->getRules()->getSprite() + 33)->blit(_sprite); |
| 184 | |
| 185 | std::wostringstream ss; |
| 186 | ss << tr("STR_DAMAGE_UC_").arg(Text::formatPercentage(_craft->getDamagePercentage())); |
| 187 | if (_craft->getStatus() == "STR_REPAIRS" && _craft->getDamage() > 0) |
| 188 | { |
| 189 | int damageHours = (int)ceil((double)_craft->getDamage() / _craft->getRules()->getRepairRate()); |
| 190 | ss << formatTime(damageHours); |
| 191 | } |
| 192 | _txtDamage->setText(ss.str()); |
| 193 | |
| 194 | std::wostringstream ss2; |
| 195 | ss2 << tr("STR_FUEL").arg(Text::formatPercentage(_craft->getFuelPercentage())); |
| 196 | if (_craft->getStatus() == "STR_REFUELLING" && _craft->getRules()->getMaxFuel() - _craft->getFuel() > 0) |
| 197 | { |
| 198 | int fuelHours = (int)ceil((double)(_craft->getRules()->getMaxFuel() - _craft->getFuel()) / _craft->getRules()->getRefuelRate() / 2.0); |
| 199 | ss2 << formatTime(fuelHours); |
| 200 | } |
| 201 | _txtFuel->setText(ss2.str()); |
| 202 | |
| 203 | if (_craft->getRules()->getSoldiers() > 0) |
| 204 | { |
| 205 | _crew->clear(); |
| 206 | _equip->clear(); |
| 207 | |
| 208 | Surface *frame1 = texture->getFrame(38); |
| 209 | frame1->setY(0); |
| 210 | for (int i = 0, x = 0; i < _craft->getNumSoldiers(); ++i, x += 10) |
| 211 | { |
| 212 | frame1->setX(x); |
| 213 | frame1->blit(_crew); |
| 214 | } |
| 215 | |
| 216 | Surface *frame2 = texture->getFrame(40); |
| 217 | frame2->setY(0); |
| 218 | int x = 0; |
| 219 | for (int i = 0; i < _craft->getNumVehicles(); ++i, x += 10) |
| 220 | { |
| 221 | frame2->setX(x); |
| 222 | frame2->blit(_equip); |
| 223 | } |
| 224 | Surface *frame3 = texture->getFrame(39); |
| 225 | for (int i = 0; i < _craft->getNumEquipment(); i += 4, x += 10) |
| 226 | { |
| 227 | frame3->setX(x); |
| 228 | frame3->blit(_equip); |
| 229 | } |
nothing calls this directly
no test coverage detected