CvUnit::GetScrapGold() const
- Defined in
- CvUnit.cpp, line 3990
- Class
- CvUnit
- Hook name
CivHooks::CvUnit_GetScrapGold
Hooks
static bool BeforeCvUnit_GetScrapGold(const CvUnit* self, int& result);static void AfterCvUnit_GetScrapGold(const CvUnit* self, int& result);static int ReplaceCvUnit_GetScrapGold(int (*original)(const CvUnit*), const CvUnit* self);CivRegisterBefore<CivHooks::CvUnit_GetScrapGold>(host, &BeforeCvUnit_GetScrapGold);CivRegisterAfter<CivHooks::CvUnit_GetScrapGold>(host, &AfterCvUnit_GetScrapGold);CivRegisterReplace<CivHooks::CvUnit_GetScrapGold>(host, &ReplaceCvUnit_GetScrapGold);
Code
3989/// How much gold do we get?3990int CvUnit::GetScrapGold() const3991{3992 int iNumGold = getUnitInfo().GetProductionCost();39933994 if(iNumGold <= 0)3995 return 0;39963997 iNumGold *= /*10*/ GC.getDISBAND_UNIT_REFUND_PERCENT();3998 iNumGold /= 100;39994000 // Modify amount based on current health4001#if defined(MOD_UNITS_MAX_HP)4002 iNumGold *= 100 * (GetMaxHitPoints() - getDamage()) / GetMaxHitPoints();4003#else4004 iNumGold *= 100 * (GC.getMAX_HIT_POINTS() - getDamage()) / GC.getMAX_HIT_POINTS();4005#endif4006 iNumGold /= 100;400740084009 // slewis - moved this out of the plot check because the game speed should effect all scrap gold calculations, not just the ones that are in the owner's plot4010 // Modify for game speed4011 iNumGold *= GC.getGame().getGameSpeedInfo().getTrainPercent();4012 iNumGold /= 100;401340144015 // Check to see if we are transporting other units and add in their scrap value as well.4016 CvPlot* pPlot = plot();4017 if(pPlot)4018 {4019 const IDInfo* pUnitNode = pPlot->headUnitNode();4020 while(pUnitNode)4021 {4022 const CvUnit* pLoopUnit = ::getUnit(*pUnitNode);40234024 if(pLoopUnit != NULL)4025 {4026 if(pLoopUnit->getTransportUnit() == this) // Is this the transport for the search unit?4027 {4028 iNumGold += pLoopUnit->GetScrapGold();4029 }4030 }40314032 pUnitNode = pPlot->nextUnitNode(pUnitNode);4033 }4034 }40354036 return iNumGold;4037}
Calls
- CvGame::getGameSpeedInfo() const
- CvGameSpeedInfo::getTrainPercent() const
- CvGlobals::getDISBAND_UNIT_REFUND_PERCENT()
- CvGlobals::getGame()
- CvPlot::headUnitNode()
- CvPlot::nextUnitNode(const IDInfo *) const
- CvUnit::getDamage() const
- CvUnit::GetMaxHitPoints() const
- CvUnit::getTransportUnit() const
- CvUnit::getUnitInfo() const
- CvUnit::plot() const
- CvUnitEntry::GetProductionCost() const
- getUnit(const IDInfo &)