Code
4522int CvLuaPlayer::lGetTradeRoutesAvailable(lua_State* L)4523{4524 CvPlayerAI* pkPlayer = GetInstance(L);4525 lua_createtable(L, 0, 0);4526 int index = 1;45274528 //CvGameTrade* pTrade = GC.getGame().GetGameTrade();4529 CvPlayerTrade* pPlayerTrade = pkPlayer->GetTrade();4530 // for each domain type4531 // for each origin city4532 // for each destination city4533 // display if a connection can be made45344535 int iOriginCityLoop;4536 CvCity* pOriginCity = NULL;4537 for (pOriginCity = pkPlayer->firstCity(&iOriginCityLoop); pOriginCity != NULL; pOriginCity = pkPlayer->nextCity(&iOriginCityLoop))4538 {4539 PlayerTypes eOtherPlayer = NO_PLAYER;4540 for (uint ui = 0; ui < MAX_CIV_PLAYERS; ui++)4541 {4542 eOtherPlayer = (PlayerTypes)ui;45434544 if (!GET_PLAYER(eOtherPlayer).isAlive())4545 {4546 continue;4547 }45484549 if (GET_PLAYER(eOtherPlayer).isBarbarian())4550 {4551 continue;4552 }45534554 int iDestCityLoop;4555 CvCity* pDestCity = NULL;4556 for (pDestCity = GET_PLAYER(eOtherPlayer).firstCity(&iDestCityLoop); pDestCity != NULL; pDestCity = GET_PLAYER(eOtherPlayer).nextCity(&iDestCityLoop))4557 {4558 // if this is the same city4559 if (pOriginCity == pDestCity)4560 {4561 continue;4562 }45634564 DomainTypes eDomain = NO_DOMAIN;4565 for (eDomain = (DomainTypes)0; eDomain < NUM_DOMAIN_TYPES; eDomain = (DomainTypes)(eDomain + 1))4566 {4567 // if this isn't a valid trade domain, ignore4568 if (eDomain != DOMAIN_LAND && eDomain != DOMAIN_SEA)4569 {4570 continue;4571 }45724573 bool bCheckPath = true;4574 TradeConnectionType eConnection = NUM_TRADE_CONNECTION_TYPES;4575 for (uint uiConnectionTypes = 0; uiConnectionTypes < NUM_TRADE_CONNECTION_TYPES; uiConnectionTypes++)4576 {4577 eConnection = (TradeConnectionType)uiConnectionTypes;4578 4579 bool bTradeAvailable = pPlayerTrade->CanCreateTradeRoute(pOriginCity, pDestCity, eDomain, eConnection, true, bCheckPath);4580 if (!bTradeAvailable)4581 {4582 continue;4583 }45844585 bCheckPath = false; // Once a trade route is valid for a domain, all further connections can assume the path is valid.45864587 lua_createtable(L, 0, 0);4588 const int t = lua_gettop(L);45894590 TradeConnection kConnection;4591 kConnection.m_iOriginX = pOriginCity->getX();4592 kConnection.m_iOriginY = pOriginCity->getY();4593 kConnection.m_iDestX = pDestCity->getX();4594 kConnection.m_iDestY = pDestCity->getY();4595 kConnection.m_eConnectionType = eConnection;4596 kConnection.m_eDomain = eDomain;4597 kConnection.m_eOriginOwner = pOriginCity->getOwner();4598 kConnection.m_eDestOwner = pDestCity->getOwner();45994600 int iTurnsLeft = -1;4601 TradeConnection* pConnection = pPlayerTrade->GetTradeConnection(pOriginCity, pDestCity);4602 if (pConnection && pConnection->m_eDomain == eDomain)4603 {4604 iTurnsLeft = pConnection->m_iTurnRouteComplete - GC.getGame().getGameTurn();4605 }46064607#if defined(MOD_API_LUA_EXTENSIONS) && defined(MOD_API_TRADEROUTES)4608 lua_pushinteger(L, kConnection.m_eConnectionType);4609 lua_setfield(L, t, "TradeConnectionType");4610#endif4611 lua_pushinteger(L, eDomain);4612 lua_setfield(L, t, "Domain");4613 lua_pushinteger(L, pkPlayer->getCivilizationType());4614 lua_setfield(L, t, "FromCivilizationType");4615 lua_pushinteger(L , pkPlayer->GetID());4616 lua_setfield(L, t, "FromID");4617 lua_pushstring(L, pOriginCity->getName());4618 lua_setfield(L, t, "FromCityName");4619 CvLuaCity::Push(L, pOriginCity);4620 lua_setfield(L, t, "FromCity");4621 lua_pushinteger(L, GET_PLAYER(eOtherPlayer).getCivilizationType());4622 lua_setfield(L, t, "ToCivilizationType");4623 lua_pushinteger(L, eOtherPlayer);4624 lua_setfield(L, t, "ToID");4625 lua_pushstring(L, pDestCity->getName());4626 lua_setfield(L, t, "ToCityName");4627 CvLuaCity::Push(L, pDestCity);4628 lua_setfield(L, t, "ToCity");4629 lua_pushinteger(L, pkPlayer->GetTrade()->GetTradeConnectionValueTimes100(kConnection, YIELD_GOLD, true));4630 lua_setfield(L, t, "FromGPT");4631 lua_pushinteger(L, GET_PLAYER(eOtherPlayer).GetTrade()->GetTradeConnectionValueTimes100(kConnection, YIELD_GOLD, false));4632 lua_setfield(L, t, "ToGPT");4633 lua_pushinteger(L, GET_PLAYER(eOtherPlayer).GetTrade()->GetTradeConnectionValueTimes100(kConnection, YIELD_FOOD, false));4634 lua_setfield(L, t, "ToFood");4635 lua_pushinteger(L, GET_PLAYER(eOtherPlayer).GetTrade()->GetTradeConnectionValueTimes100(kConnection, YIELD_PRODUCTION, false));4636 lua_setfield(L, t, "ToProduction");4637 lua_pushinteger(L, GET_PLAYER(eOtherPlayer).GetTrade()->GetTradeConnectionValueTimes100(kConnection, YIELD_SCIENCE, true));4638 lua_setfield(L, t, "FromScience");4639 lua_pushinteger(L, GET_PLAYER(eOtherPlayer).GetTrade()->GetTradeConnectionValueTimes100(kConnection, YIELD_SCIENCE, false));4640 lua_setfield(L, t, "ToScience");46414642 ReligionTypes eToReligion = NO_RELIGION;4643 int iToPressure = 0;4644 ReligionTypes eFromReligion = NO_RELIGION;4645 int iFromPressure = 0;46464647 pOriginCity->GetCityReligions()->WouldExertTradeRoutePressureToward(pDestCity, eToReligion, iToPressure);4648 pDestCity->GetCityReligions()->WouldExertTradeRoutePressureToward(pOriginCity, eFromReligion, iFromPressure);46494650 if (iTurnsLeft < 0)4651 {4652 int iTradeReligionModifer = pkPlayer->GetPlayerTraits()->GetTradeReligionModifier();4653 if (iTradeReligionModifer != 0)4654 {4655 iToPressure *= 100 + iTradeReligionModifer;4656 iToPressure /= 100;4657 }4658 }46594660 // Internally pressure is now 10 times greater than what is shown to user4661 iToPressure /= GC.getRELIGION_MISSIONARY_PRESSURE_MULTIPLIER();4662 iFromPressure /= GC.getRELIGION_MISSIONARY_PRESSURE_MULTIPLIER();46634664 lua_pushinteger(L, eToReligion);4665 lua_setfield(L, t, "ToReligion");4666 lua_pushinteger(L, iToPressure);4667 lua_setfield(L, t, "ToPressure");4668 lua_pushinteger(L, eFromReligion);4669 lua_setfield(L, t, "FromReligion");4670 lua_pushinteger(L, iFromPressure);4671 lua_setfield(L, t, "FromPressure");46724673 int iToDelta = pOriginCity->GetCityCulture()->GetBaseTourism() * pOriginCity->GetCityCulture()->GetTourismMultiplier(eOtherPlayer, true, true, false, true, true);4674 int iFromDelta = pDestCity->GetCityCulture()->GetBaseTourism() * pDestCity->GetCityCulture()->GetTourismMultiplier(pkPlayer->GetID(), true, true, false, true, true);4675 lua_pushinteger(L, iFromDelta);4676 lua_setfield(L, t, "FromTourism");4677 lua_pushinteger(L, iToDelta);4678 lua_setfield(L, t, "ToTourism");46794680 lua_pushinteger(L, iTurnsLeft);4681 lua_setfield(L, t, "TurnsLeft");46824683 lua_rawseti(L, -2, index++);468446854686 }4687 }4688 }4689 }4690 }46914692 return 1;4693}