// Add a ship, and all its outfits, to the depreciation record. void Depreciation::Buy(const Ship &ship, int day, Depreciation *source) { // First, add records for all outfits the ship is carrying. for(const auto &it : ship.Outfits()) for(int i = 0; i < it.second; ++i) Buy(it.first, day, source); // Then, check the base day for the ship chassis itself. const Ship *base = GameData::Ships().Get(ship.ModelName()); if(source) { // Check if the source has any instances of this ship. auto it = source->ships.find(base); if(it != source->ships.end() && !it->second.empty()) { day = source->Sell(it->second); if(it->second.empty()) source->ships.erase(it); } else if(isStock) { // If we're a planet buying from the player, and the player has no // record of how old this ship is, it's fully depreciated. day -= MAX_AGE; } } // Increment our count for this ship on this day. ++ships[base][day]; }
void ShopPanel::DrawShip(const Ship &ship, const Point ¢er, bool isSelected) const { const Sprite *sprite = ship.GetSprite().GetSprite(); const Sprite *back = SpriteSet::Get( isSelected ? "ui/shipyard selected" : "ui/shipyard unselected"); SpriteShader::Draw(back, center); // Make sure the ship sprite leaves 10 pixels padding all around. float zoomSize = SHIP_SIZE - 60.f; // Draw the ship name. const string &name = ship.Name().empty() ? ship.ModelName() : ship.Name(); const Font &font = FontSet::Get(14); Point offset(-.5f * font.Width(name), -.5f * SHIP_SIZE + 10.f); font.Draw(name, center + offset, *GameData::Colors().Get("bright")); float zoom = min(1.f, zoomSize / max(sprite->Width(), sprite->Height())); int swizzle = GameData::PlayerGovernment()->GetSwizzle(); SpriteShader::Draw(sprite, center, zoom, swizzle); }