bool CSpaceObject::GetArmorRepairPrice (const CItem &Item, int iHPToRepair, DWORD dwFlags, int *retiPrice) // GetArmorRepairPrice // // Returns the price to repair the given number of HP for the given armor item. { if (IsAbandoned()) return false; // See if we have an override CTradingDesc *pTradeOverride = GetTradeDescOverride(); if (pTradeOverride && pTradeOverride->GetArmorRepairPrice(this, Item, iHPToRepair, dwFlags, retiPrice)) return true; // Otherwise, ask our design type CDesignType *pType = GetType(); if (pType == NULL) return false; CTradingDesc *pTrade = pType->GetTradingDesc(); if (pTrade && pTrade->GetArmorRepairPrice(this, Item, iHPToRepair, dwFlags, retiPrice)) return true; // For compatibility, any ship prior to version 23 has a default. // [For API Version 23 and above, ships must have a <Trade> descriptor.] if (pType->GetAPIVersion() < 23 && pType->GetType() == designShipClass) { if (retiPrice) *retiPrice = CTradingDesc::CalcPriceForService(serviceRepairArmor, this, Item, iHPToRepair, dwFlags); return true; } // Otherwise, we do not repair return false; }
int CSpaceObject::GetSellPrice (const CItem &Item, DWORD dwFlags) // GetSellPrice // // Returns the price at which the station will sell the given // item. Returns 0 if the station cannot or will not sell the // item. { bool bHasTradeDirective = false; int iPrice = -1; if (IsAbandoned()) return false; // See if we have an override price CTradingDesc *pTradeOverride = GetTradeDescOverride(); if (pTradeOverride) { pTradeOverride->Sells(this, Item, dwFlags, &iPrice); bHasTradeDirective = true; } // See if our type has a price CDesignType *pType = GetType(); if (iPrice == -1) { CTradingDesc *pTrade = (pType ? pType->GetTradingDesc() : NULL); if (pTrade) { pTrade->Sells(this, Item, dwFlags, &iPrice); bHasTradeDirective = true; } } // If we still have no price, then try to figure out a default. if (iPrice == -1) { // If we have Trade directives and they specify no price, then we can't // sell any. if (bHasTradeDirective) return 0; // For compatibility, any ship prior to version 23 has a default. // [For API Version 23 and above, ships must have a <Trade> descriptor.] else if (pType && pType->GetAPIVersion() < 23 && pType->GetType() == designShipClass) iPrice = CTradingDesc::CalcPriceForService(serviceSell, this, Item, 1, dwFlags); // Otherwise, get the price from the item itself else iPrice = (int)GetDefaultEconomy()->Exchange(Item.GetCurrencyType(), Item.GetTradePrice(this)); } // If we don't have any of the item, then we don't sell any if (!(dwFlags & CTradingDesc::FLAG_NO_INVENTORY_CHECK)) { CItemListManipulator ItemList(GetItemList()); if (!ItemList.SetCursorAtItem(Item)) return 0; } // Return the price return iPrice; }
bool CSpaceObject::GetRefuelItemAndPrice (CSpaceObject *pObjToRefuel, CItemType **retpItemType, int *retiPrice) // GetRefuelItemAndPrice // // Returns the appropriate item to use for refueling (based on the trading // directives). { int i; if (IsAbandoned()) return false; // See if we have an override CTradingDesc *pTradeOverride = GetTradeDescOverride(); if (pTradeOverride && pTradeOverride->GetRefuelItemAndPrice(this, pObjToRefuel, 0, retpItemType, retiPrice)) return true; // Otherwise, ask our design type CDesignType *pType = GetType(); if (pType == NULL) return false; CTradingDesc *pTrade = pType->GetTradingDesc(); if (pTrade && pTrade->GetRefuelItemAndPrice(this, pObjToRefuel, 0, retpItemType, retiPrice)) return true; // For compatibility, any ship prior to version 23 has a default. // [For API Version 23 and above, ships must have a <Trade> descriptor.] if (pType->GetAPIVersion() < 23 && pType->GetType() == designShipClass) { // Get the ship CShip *pShipToRefuel = pObjToRefuel->AsShip(); if (pShipToRefuel == NULL) return false; // Find the highest-level item that can be used by the ship int iBestLevel = 0; int iBestPrice = 0; CItemType *pBestItem = NULL; for (i = 0; i < g_pUniverse->GetItemTypeCount(); i++) { CItemType *pType = g_pUniverse->GetItemType(i); CItem Item(pType, 1); if (pShipToRefuel->IsFuelCompatible(Item)) { if (pBestItem == NULL || pType->GetLevel() > iBestPrice) { // Compute the price, because if we don't sell it, then we // skip it. // // NOTE: Unlike selling, we allow 0 prices because some // stations give fuel for free. int iPrice = CTradingDesc::CalcPriceForService(serviceRefuel, this, Item, 1, 0); if (iPrice >= 0) { pBestItem = pType; iBestLevel = pType->GetLevel(); iBestPrice = iPrice; } } } } if (pBestItem == NULL) return false; // Done if (retpItemType) *retpItemType = pBestItem; if (retiPrice) *retiPrice = iBestPrice; return true; } // Otherwise, we do not refuel return false; }