Hooks
static bool BeforeCvLuaPlayer_lGetTradeYourRoutesTTString(lua_State* L, int& result);static void AfterCvLuaPlayer_lGetTradeYourRoutesTTString(lua_State* L, int& result);static int ReplaceCvLuaPlayer_lGetTradeYourRoutesTTString(int (*original)(lua_State*), lua_State* L);CivRegisterBefore<CivHooks::CvLuaPlayer_lGetTradeYourRoutesTTString>(host, &BeforeCvLuaPlayer_lGetTradeYourRoutesTTString);CivRegisterAfter<CivHooks::CvLuaPlayer_lGetTradeYourRoutesTTString>(host, &AfterCvLuaPlayer_lGetTradeYourRoutesTTString);CivRegisterReplace<CivHooks::CvLuaPlayer_lGetTradeYourRoutesTTString>(host, &ReplaceCvLuaPlayer_lGetTradeYourRoutesTTString);
Code
4040int CvLuaPlayer::lGetTradeYourRoutesTTString(lua_State* L)4041{4042 CvPlayerAI* pkPlayer = GetInstance(L);4043 CvGameTrade* pTrade = GC.getGame().GetGameTrade();4044 CvPlayerTrade* pPlayerTrade = pkPlayer->GetTrade();40454046 CvString strResult = ""; 40474048 TradeConnection* pConnection = NULL;4049 for (uint ui = 0; ui < pTrade->m_aTradeConnections.size(); ui++)4050 {4051 if (pTrade->IsTradeRouteIndexEmpty(ui))4052 {4053 continue;4054 }40554056 pConnection = &(pTrade->m_aTradeConnections[ui]);4057 if (pConnection->m_eOriginOwner == pkPlayer->GetID())4058 {4059 CvPlot* pOriginPlot = GC.getMap().plot(pConnection->m_iOriginX, pConnection->m_iOriginY);4060 CvPlot* pDestPlot = GC.getMap().plot(pConnection->m_iDestX, pConnection->m_iDestY);4061 if (pOriginPlot == NULL || pDestPlot == NULL)4062 {4063 continue;4064 }40654066 CvCity* pOriginCity = pOriginPlot->getPlotCity();4067 CvCity* pDestCity = pDestPlot->getPlotCity();40684069 if (pOriginCity == NULL || pDestCity == NULL)4070 {4071 continue;4072 }407340744075 CvString strOriginYieldsStr = "";4076 for (uint uiYield = 0; uiYield < NUM_YIELD_TYPES; uiYield++)4077 {4078 YieldTypes eYield = (YieldTypes)uiYield;4079 int iYieldQuantity = pPlayerTrade->GetTradeConnectionValueTimes100(*pConnection, eYield, true);4080 if (iYieldQuantity != 0)4081 {4082 if (strOriginYieldsStr != "") 4083 {4084 strOriginYieldsStr += ", ";4085 }40864087 switch (eYield)4088 {4089 case YIELD_FOOD:4090 strOriginYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_FOOD_YIELD_TT", iYieldQuantity / 100);4091 break;4092 case YIELD_PRODUCTION:4093 strOriginYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_PRODUCTION_YIELD_TT", iYieldQuantity / 100);4094 break;4095 case YIELD_GOLD:4096 strOriginYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_GOLD_YIELD_TT", iYieldQuantity / 100);4097 break;4098 case YIELD_SCIENCE:4099 strOriginYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_SCIENCE_YIELD_TT", iYieldQuantity / 100);4100 break;4101 case YIELD_CULTURE:4102 strOriginYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_CULTURE_YIELD_TT", iYieldQuantity / 100);4103 break;4104 case YIELD_FAITH:4105 strOriginYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_FAITH_YIELD_TT", iYieldQuantity / 100);4106 break;4107#if defined(MOD_API_UNIFIED_YIELDS_TOURISM)4108 case YIELD_TOURISM:4109 strOriginYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_TOURISM_YIELD_TT", iYieldQuantity / 100);4110 break;4111#endif4112#if defined(MOD_API_UNIFIED_YIELDS_GOLDEN_AGE)4113 case YIELD_GOLDEN_AGE_POINTS:4114 strOriginYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_GOLDEN_AGE_POINTS_YIELD_TT", iYieldQuantity / 100);4115 break;4116#endif4117 }4118 }4119 }41204121 CvString strDestYieldsStr = "";4122 for (uint uiYield = 0; uiYield < NUM_YIELD_TYPES; uiYield++)4123 {4124 YieldTypes eYield = (YieldTypes)uiYield;4125 int iYieldQuantity = pPlayerTrade->GetTradeConnectionValueTimes100(*pConnection, eYield, false);4126 if (iYieldQuantity != 0)4127 {4128 switch (eYield)4129 {4130 case YIELD_FOOD:4131 strDestYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_FOOD_YIELD_TT", iYieldQuantity / 100);4132 break;4133 case YIELD_PRODUCTION:4134 strDestYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_PRODUCTION_YIELD_TT", iYieldQuantity / 100);4135 break;4136 case YIELD_GOLD:4137 strDestYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_GOLD_YIELD_TT", iYieldQuantity / 100);4138 break;4139 case YIELD_SCIENCE:4140 strDestYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_SCIENCE_YIELD_TT", iYieldQuantity / 100);4141 break;4142 case YIELD_CULTURE:4143 strDestYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_CULTURE_YIELD_TT", iYieldQuantity / 100);4144 break;4145 case YIELD_FAITH:4146 strDestYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_FAITH_YIELD_TT", iYieldQuantity / 100);4147 break;4148#if defined(MOD_API_UNIFIED_YIELDS_TOURISM)4149 case YIELD_TOURISM:4150 strDestYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_TOURISM_YIELD_TT", iYieldQuantity / 100);4151 break;4152#endif4153#if defined(MOD_API_UNIFIED_YIELDS_GOLDEN_AGE)4154 case YIELD_GOLDEN_AGE_POINTS:4155 strDestYieldsStr += GetLocalizedText("TXT_KEY_TOP_PANEL_ITR_GOLDEN_AGE_POINTS_YIELD_TT", iYieldQuantity / 100);4156 break;4157#endif4158 }4159 }4160 }41614162 //CvUnitEntry* pUnitEntry = GC.getUnitInfo(pPlayerTrade->GetTradeUnit(pConnection->m_eDomain));41634164 Localization::String strBuffer;4165 if (pConnection->m_eConnectionType == TRADE_CONNECTION_INTERNATIONAL)4166 {4167 if (strOriginYieldsStr != "" && strDestYieldsStr != "")4168 {4169 strBuffer = Localization::Lookup("TXT_KEY_TOP_PANEL_ITR_YOUR_ROUTE_BOTH_TT");4170 }4171 else if (strOriginYieldsStr != "")4172 {4173 strBuffer = Localization::Lookup("TXT_KEY_TOP_PANEL_ITR_YOUR_ROUTE_ONLY_ORIGIN_TT");4174 }4175 else if (strDestYieldsStr != "")4176 {4177 strBuffer = Localization::Lookup("TXT_KEY_TOP_PANEL_ITR_YOUR_ROUTE_ONLY_DEST_TT");4178 }4179 }4180 else4181 {4182 if (strOriginYieldsStr != "" && strDestYieldsStr != "")4183 {4184 strBuffer = Localization::Lookup("TXT_KEY_TOP_PANEL_ITR_INTERNAL_YOUR_ROUTE_BOTH_TT");4185 }4186 else if (strOriginYieldsStr != "")4187 {4188 strBuffer = Localization::Lookup("TXT_KEY_TOP_PANEL_ITR_INTERNAL_YOUR_ROUTE_ONLY_ORIGIN_TT");4189 }4190 else if (strDestYieldsStr != "")4191 {4192 strBuffer = Localization::Lookup("TXT_KEY_TOP_PANEL_ITR_INTERNAL_YOUR_ROUTE_ONLY_DEST_TT");4193 }4194 }41954196 strBuffer << pOriginCity->getNameKey();4197 if (strOriginYieldsStr != "")4198 {4199 strBuffer << strOriginYieldsStr;4200 }4201 4202 if (pConnection->m_eConnectionType == TRADE_CONNECTION_INTERNATIONAL)4203 {4204 if (GET_PLAYER(pDestCity->getOwner()).isMinorCiv())4205 {4206 strBuffer << "TXT_KEY_TOP_PANEL_ITR_CITY_STATE_TT";4207 }4208 else4209 {4210 strBuffer << GET_PLAYER(pDestCity->getOwner()).getCivilizationShortDescription();4211 }4212 }42134214 strBuffer << pDestCity->getNameKey();4215 if (strDestYieldsStr != "")4216 {4217 strBuffer << strDestYieldsStr;4218 }42194220 if (strResult != "")4221 {4222 strResult += "[NEWLINE]";4223 }42244225 strResult += strBuffer.toUTF8();4226 }4227 }4228 4229 lua_pushstring(L, strResult);42304231 return 1;4232}