Bazaar developer reference

CvPlayer::DoUnresearchedTechBonusFromKill(CvUnit *, UnitTypes, int, int, int &)

Defined in
CvPlayer.cpp, line 11045
Class
CvPlayer
Hook name
CivHooks::CvPlayer_DoUnresearchedTechBonusFromKill

Hooks

static bool BeforeCvPlayer_DoUnresearchedTechBonusFromKill(CvPlayer* self, CvUnit* pKilledUnit, UnitTypes eKilledUnitType, int iX, int iY, int & iNumBonuses);static void AfterCvPlayer_DoUnresearchedTechBonusFromKill(CvPlayer* self, CvUnit* pKilledUnit, UnitTypes eKilledUnitType, int iX, int iY, int & iNumBonuses);static void ReplaceCvPlayer_DoUnresearchedTechBonusFromKill(void (*original)(CvPlayer*, CvUnit*, UnitTypes, int, int, int &), CvPlayer* self, CvUnit* pKilledUnit, UnitTypes eKilledUnitType, int iX, int iY, int & iNumBonuses);CivRegisterBefore<CivHooks::CvPlayer_DoUnresearchedTechBonusFromKill>(host, &BeforeCvPlayer_DoUnresearchedTechBonusFromKill);CivRegisterAfter<CivHooks::CvPlayer_DoUnresearchedTechBonusFromKill>(host, &AfterCvPlayer_DoUnresearchedTechBonusFromKill);CivRegisterReplace<CivHooks::CvPlayer_DoUnresearchedTechBonusFromKill>(host, &ReplaceCvPlayer_DoUnresearchedTechBonusFromKill);

Code

11042/// Apply and show a bonus towards unresearched tech when we defeat a unit of that tech11043/// If a bonus is applied, iNumBonuses must be incremented to stagger the UI text with other bonuses11044#if defined(MOD_API_EXTENSIONS)11045void CvPlayer::DoUnresearchedTechBonusFromKill(CvUnit* pKilledUnit, UnitTypes eKilledUnitType, int iX, int iY, int &iNumBonuses)11046#else11047void CvPlayer::DoUnresearchedTechBonusFromKill(UnitTypes eKilledUnitType, int iX, int iY, int &iNumBonuses)11048#endif11049{11050	CvAssertMsg(eKilledUnitType != NO_UNIT, "Killed unit's type is NO_TYPE. Please send Anton your save file and version.");11051	if (eKilledUnitType == NO_UNIT) return;1105211053	int iPercent = GetPlayerTraits()->GetUnresearchedTechBonusFromKills();1105411055	if (iPercent > 0)11056	{11057		int iValue = 0;1105811059		CvUnitEntry* pkUnitInfo = GC.getUnitInfo(eKilledUnitType);11060		if(pkUnitInfo)11061		{11062			TechTypes ePrereq = (TechTypes) pkUnitInfo->GetPrereqAndTech();11063			if (ePrereq != NO_TECH)11064			{11065				CvTechEntry* pkTechInfo = GC.getTechInfo(ePrereq);11066				if (pkTechInfo && !GET_TEAM(getTeam()).GetTeamTechs()->HasTech(ePrereq))11067				{11068#if defined(MOD_API_EXTENSIONS)11069					int iCombatStrength = pKilledUnit ? max(pKilledUnit->GetBaseCombatStrength(), pKilledUnit->GetBaseRangedCombatStrength()) : max(pkUnitInfo->GetCombat(), pkUnitInfo->GetRangedCombat());11070#else11071					int iCombatStrength = max(pkUnitInfo->GetCombat(), pkUnitInfo->GetRangedCombat());11072#endif11073					if (iCombatStrength > 0)11074					{11075						int iTechCost = GetPlayerTechs()->GetResearchCost(ePrereq);11076						iValue = (iTechCost * iPercent) / 100;1107711078						// Cannot be greater than the tech's cost11079						int iRemainingCost = iTechCost - GetPlayerTechs()->GetResearchProgress(ePrereq);11080						if (iValue > iRemainingCost)11081						{11082							iValue = iRemainingCost;11083						}1108411085						if (iValue > 0)11086						{11087							GET_TEAM(getTeam()).GetTeamTechs()->ChangeResearchProgress(ePrereq, iValue, GetID());11088							iNumBonuses++;11089							ReportYieldFromKill(YIELD_SCIENCE, iValue, iX, iY, iNumBonuses);11090						}11091					}11092				}11093			}11094		}11095	}11096}

Calls

Called by