Bazaar developer reference

CvLuaPlayer::lGetTradeRoutesToYou(lua_State *)

Defined in
Lua/CvLuaPlayer.cpp, line 4696
Class
CvLuaPlayer
Hook name
CivHooks::CvLuaPlayer_lGetTradeRoutesToYou

Hooks

static bool BeforeCvLuaPlayer_lGetTradeRoutesToYou(lua_State* L, int& result);static void AfterCvLuaPlayer_lGetTradeRoutesToYou(lua_State* L, int& result);static int ReplaceCvLuaPlayer_lGetTradeRoutesToYou(int (*original)(lua_State*), lua_State* L);CivRegisterBefore<CivHooks::CvLuaPlayer_lGetTradeRoutesToYou>(host, &BeforeCvLuaPlayer_lGetTradeRoutesToYou);CivRegisterAfter<CivHooks::CvLuaPlayer_lGetTradeRoutesToYou>(host, &AfterCvLuaPlayer_lGetTradeRoutesToYou);CivRegisterReplace<CivHooks::CvLuaPlayer_lGetTradeRoutesToYou>(host, &ReplaceCvLuaPlayer_lGetTradeRoutesToYou);

Code

4696int CvLuaPlayer::lGetTradeRoutesToYou(lua_State* L)4697{4698	CvPlayerAI* pkPlayer = GetInstance(L);46994700	lua_createtable(L, 0, 0);4701	int index = 1;47024703	CvGameTrade* pTrade = GC.getGame().GetGameTrade();4704	for (uint ui = 0; ui < pTrade->m_aTradeConnections.size(); ui++)4705	{4706		if (pTrade->IsTradeRouteIndexEmpty(ui))4707		{4708			continue;4709		}47104711		TradeConnection* pConnection = &(pTrade->m_aTradeConnections[ui]);4712		// internal trade route. Ignore.4713		if (pConnection->m_eOriginOwner == pConnection->m_eDestOwner)4714		{4715			continue;4716		}47174718		// trade route does not involve target player. Ignore.4719		if (pConnection->m_eDestOwner != pkPlayer->GetID())4720		{4721			continue;4722		}47234724		CvCity* pFromCity = GC.getMap().plot(pConnection->m_iOriginX, pConnection->m_iOriginY)->getPlotCity();4725		CvCity* pToCity = GC.getMap().plot(pConnection->m_iDestX, pConnection->m_iDestY)->getPlotCity();47264727		CvPlayer* pFromPlayer = &GET_PLAYER(pFromCity->getOwner());4728		CvPlayer* pToPlayer = &GET_PLAYER(pToCity->getOwner());47294730		lua_createtable(L, 0, 0);4731		const int t = lua_gettop(L);47324733#if defined(MOD_API_LUA_EXTENSIONS) && defined(MOD_API_TRADEROUTES)4734		lua_pushinteger(L, pConnection->m_eConnectionType);4735		lua_setfield(L, t, "TradeConnectionType");4736#endif4737		lua_pushinteger(L, pConnection->m_eDomain);4738		lua_setfield(L, t, "Domain");4739		lua_pushinteger(L, pkPlayer->getCivilizationType());4740		lua_setfield(L, t, "FromCivilizationType");4741		lua_pushinteger(L , pFromCity->getOwner());4742		lua_setfield(L, t, "FromID");4743		lua_pushstring(L, pFromCity->getName());4744		lua_setfield(L, t, "FromCityName");4745		CvLuaCity::Push(L, pFromCity);4746		lua_setfield(L, t, "FromCity");4747		lua_pushinteger(L, GET_PLAYER(pConnection->m_eDestOwner).getCivilizationType());4748		lua_setfield(L, t, "ToCivilizationType");4749		lua_pushinteger(L, pToCity->getOwner());4750		lua_setfield(L, t, "ToID");4751		lua_pushstring(L, pToCity->getName());4752		lua_setfield(L, t, "ToCityName");4753		CvLuaCity::Push(L, pToCity);4754		lua_setfield(L, t, "ToCity");4755		lua_pushinteger(L, pFromPlayer->GetTrade()->GetTradeConnectionValueTimes100(*pConnection, YIELD_GOLD, true));4756		lua_setfield(L, t, "FromGPT");4757		lua_pushinteger(L, pToPlayer->GetTrade()->GetTradeConnectionValueTimes100(*pConnection, YIELD_GOLD, false));4758		lua_setfield(L, t, "ToGPT");4759		lua_pushinteger(L, pToPlayer->GetTrade()->GetTradeConnectionValueTimes100(*pConnection, YIELD_FOOD, false));4760		lua_setfield(L, t, "ToFood");4761		lua_pushinteger(L, pToPlayer->GetTrade()->GetTradeConnectionValueTimes100(*pConnection, YIELD_PRODUCTION, false));4762		lua_setfield(L, t, "ToProduction");4763		lua_pushinteger(L, pFromPlayer->GetTrade()->GetTradeConnectionValueTimes100(*pConnection, YIELD_SCIENCE, true));4764		lua_setfield(L, t, "FromScience");4765		lua_pushinteger(L, pToPlayer->GetTrade()->GetTradeConnectionValueTimes100(*pConnection, YIELD_SCIENCE, false));4766		lua_setfield(L, t, "ToScience");47674768		ReligionTypes eToReligion = NO_RELIGION;4769		int iToPressure = 0;4770		ReligionTypes eFromReligion = NO_RELIGION;4771		int iFromPressure = 0;47724773		pFromCity->GetCityReligions()->WouldExertTradeRoutePressureToward(pToCity, eToReligion, iToPressure);4774		pToCity->GetCityReligions()->WouldExertTradeRoutePressureToward(pFromCity, eFromReligion, iFromPressure);47754776		// Internally pressure is now 10 times greater than what is shown to user4777		iToPressure /= GC.getRELIGION_MISSIONARY_PRESSURE_MULTIPLIER();4778		iFromPressure /= GC.getRELIGION_MISSIONARY_PRESSURE_MULTIPLIER();47794780		lua_pushinteger(L, eToReligion);4781		lua_setfield(L, t, "ToReligion");4782		lua_pushinteger(L, iToPressure);4783		lua_setfield(L, t, "ToPressure");4784		lua_pushinteger(L, eFromReligion);4785		lua_setfield(L, t, "FromReligion");4786		lua_pushinteger(L, iFromPressure);4787		lua_setfield(L, t, "FromPressure");47884789		int iToDelta = pFromCity->GetCityCulture()->GetBaseTourism() * pFromCity->GetCityCulture()->GetTourismMultiplier(pToPlayer->GetID(), true, true, false, true, true);4790		int iFromDelta = pToCity->GetCityCulture()->GetBaseTourism() * pToCity->GetCityCulture()->GetTourismMultiplier(pkPlayer->GetID(), true, true, false, true, true);4791		lua_pushinteger(L, iFromDelta);4792		lua_setfield(L, t, "FromTourism");4793		lua_pushinteger(L, iToDelta);4794		lua_setfield(L, t, "ToTourism");47954796		lua_pushinteger(L, GC.getGame().getGameTurn() - pConnection->m_iTurnRouteComplete);4797		lua_setfield(L, t, "TurnsLeft");47984799		lua_rawseti(L, -2, index++);4800	}48014802	return 1;4803}

Calls

Called by