Hooks
static bool BeforeCvLuaPlayer_GetPotentialInternationalTradeRouteDestinationsHelper(lua_State* L, CvPlayerAI* pkPlayer, CvUnit* pkUnit, CvPlot* pkUnitPlot, int& result);static void AfterCvLuaPlayer_GetPotentialInternationalTradeRouteDestinationsHelper(lua_State* L, CvPlayerAI* pkPlayer, CvUnit* pkUnit, CvPlot* pkUnitPlot, int& result);static int ReplaceCvLuaPlayer_GetPotentialInternationalTradeRouteDestinationsHelper(int (*original)(lua_State*, CvPlayerAI*, CvUnit*, CvPlot*), lua_State* L, CvPlayerAI* pkPlayer, CvUnit* pkUnit, CvPlot* pkUnitPlot);CivRegisterBefore<CivHooks::CvLuaPlayer_GetPotentialInternationalTradeRouteDestinationsHelper>(host, &BeforeCvLuaPlayer_GetPotentialInternationalTradeRouteDestinationsHelper);CivRegisterAfter<CivHooks::CvLuaPlayer_GetPotentialInternationalTradeRouteDestinationsHelper>(host, &AfterCvLuaPlayer_GetPotentialInternationalTradeRouteDestinationsHelper);CivRegisterReplace<CivHooks::CvLuaPlayer_GetPotentialInternationalTradeRouteDestinationsHelper>(host, &ReplaceCvLuaPlayer_GetPotentialInternationalTradeRouteDestinationsHelper);
Code
3505int CvLuaPlayer::GetPotentialInternationalTradeRouteDestinationsHelper(lua_State* L, CvPlayerAI* pkPlayer, CvUnit* pkUnit, CvPlot* pkUnitPlot)3506{3507#else3508int CvLuaPlayer::lGetPotentialInternationalTradeRouteDestinations(lua_State* L)3509{3510 CvPlayerAI* pkPlayer = GetInstance(L);3511 CvUnit* pkUnit = CvLuaUnit::GetInstance(L, 2, false);3512 CvPlot* pkUnitPlot = pkUnit->plot();3513#endif35143515 CvPlayerTrade* pPlayerTrade = pkPlayer->GetTrade();35163517 int iOriginX = pkUnitPlot->getX();3518 int iOriginY = pkUnitPlot->getY();3519 CvCity* pOriginCity = pkUnitPlot->getPlotCity();35203521 lua_createtable(L, 0, 0);3522 int index = 1;35233524 if (pkUnit->canMakeTradeRoute(pkUnitPlot))3525 {3526 TradeConnection kTradeConnection;3527 kTradeConnection.m_eOriginOwner = pkPlayer->GetID();3528 kTradeConnection.m_iOriginX = iOriginX;3529 kTradeConnection.m_iOriginY = iOriginY;3530 kTradeConnection.m_eDomain = pkUnit->getDomainType();35313532 PlayerTypes ePlayer = NO_PLAYER;3533 for (uint ui = 0; ui < MAX_CIV_PLAYERS; ui++)3534 {3535 ePlayer = (PlayerTypes)ui;35363537 if (!GET_PLAYER(ePlayer).isAlive())3538 {3539 continue;3540 }35413542 if (GET_PLAYER(ePlayer).isBarbarian())3543 {3544 continue;3545 }35463547 CvPlayerTrade* pOtherPlayerTrade = GET_PLAYER(ePlayer).GetTrade();35483549 int iCityLoop;3550 CvCity* pLoopCity = NULL;3551 for(pLoopCity = GET_PLAYER(ePlayer).firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER(ePlayer).nextCity(&iCityLoop))3552 {3553 int iLoopCityX = pLoopCity->getX();3554 int iLoopCityY = pLoopCity->getY();35553556 for (uint uiConnectionType = 0; uiConnectionType < NUM_TRADE_CONNECTION_TYPES; uiConnectionType++)3557 {3558 TradeConnectionType eConnectionType = (TradeConnectionType)uiConnectionType;3559 if (pkUnit->canMakeTradeRouteAt(pkUnitPlot, iLoopCityX, iLoopCityY, eConnectionType))3560 {3561 kTradeConnection.m_iDestX = iLoopCityX;3562 kTradeConnection.m_iDestY = iLoopCityY;3563 kTradeConnection.m_eDestOwner = ePlayer;3564 kTradeConnection.m_eConnectionType = eConnectionType;35653566 lua_createtable(L, 0, 0);3567 const int t = lua_gettop(L);3568 lua_pushinteger(L, pLoopCity->getX());3569 lua_setfield(L, t, "X");3570 lua_pushinteger(L, pLoopCity->getY());3571 lua_setfield(L, t, "Y");3572 lua_pushinteger(L, uiConnectionType);3573 lua_setfield(L, t, "TradeConnectionType");3574 3575 ReligionTypes eToReligion = NO_RELIGION;3576 int iToPressureAmount = 0;3577 ReligionTypes eFromReligion = NO_RELIGION;3578 int iFromPressureAmount = 0;35793580 pOriginCity->GetCityReligions()->WouldExertTradeRoutePressureToward(pLoopCity, eToReligion, iToPressureAmount);3581 pLoopCity->GetCityReligions()->WouldExertTradeRoutePressureToward(pOriginCity, eFromReligion, iFromPressureAmount);35823583 int iTradeReligionModifer = pkPlayer->GetPlayerTraits()->GetTradeReligionModifier();3584 if (iTradeReligionModifer != 0)3585 {3586 iToPressureAmount *= 100 + iTradeReligionModifer;3587 iToPressureAmount /= 100;3588 }35893590 // Internally pressure is now 10 times greater than what is shown to user3591 iToPressureAmount /= GC.getRELIGION_MISSIONARY_PRESSURE_MULTIPLIER();3592 iFromPressureAmount /= GC.getRELIGION_MISSIONARY_PRESSURE_MULTIPLIER();35933594 lua_pushinteger(L, eToReligion);3595 lua_setfield(L, t, "ToReligion");3596 lua_pushinteger(L, iToPressureAmount);3597 lua_setfield(L, t, "ToPressureAmount");3598 lua_pushinteger(L, eFromReligion);3599 lua_setfield(L, t, "FromReligion");3600 lua_pushinteger(L, iFromPressureAmount);3601 lua_setfield(L, t, "FromPressureAmount");36023603 lua_pushboolean(L, pPlayerTrade->IsPreviousTradeRoute(pOriginCity, pLoopCity, pkUnit->getDomainType(), eConnectionType));3604 lua_setfield(L, t, "OldTradeRoute");36053606 int iInnerIndex = 1;3607 lua_createtable(L, 0, 0);3608 for (uint uiYield = 0; uiYield < NUM_YIELD_TYPES; uiYield++)3609 {3610 lua_createtable(L, 0, 0);3611 const int t2 = lua_gettop(L);3612 lua_pushinteger(L, pPlayerTrade->GetTradeConnectionValueTimes100(kTradeConnection, (YieldTypes)uiYield, true));3613 lua_setfield(L, t2, "Mine");3614 lua_pushinteger(L, pOtherPlayerTrade->GetTradeConnectionValueTimes100(kTradeConnection, (YieldTypes)uiYield, false));3615 lua_setfield(L, t2, "Theirs");3616 lua_rawseti(L, -2, iInnerIndex++);3617 }3618 lua_setfield(L, t, "Yields");3619 lua_rawseti(L, -2, index++);3620 }3621 }3622 }3623 }3624 }36253626 return 1;3627}