Bazaar developer reference

CvLuaGame::lGetLongestCityConnectionPlots(lua_State *)

Defined in
Lua/CvLuaGame.cpp, line 2910
Class
CvLuaGame
Hook name
CivHooks::CvLuaGame_lGetLongestCityConnectionPlots

Hooks

static bool BeforeCvLuaGame_lGetLongestCityConnectionPlots(lua_State* L, int& result);static void AfterCvLuaGame_lGetLongestCityConnectionPlots(lua_State* L, int& result);static int ReplaceCvLuaGame_lGetLongestCityConnectionPlots(int (*original)(lua_State*), lua_State* L);CivRegisterBefore<CivHooks::CvLuaGame_lGetLongestCityConnectionPlots>(host, &BeforeCvLuaGame_lGetLongestCityConnectionPlots);CivRegisterAfter<CivHooks::CvLuaGame_lGetLongestCityConnectionPlots>(host, &AfterCvLuaGame_lGetLongestCityConnectionPlots);CivRegisterReplace<CivHooks::CvLuaGame_lGetLongestCityConnectionPlots>(host, &ReplaceCvLuaGame_lGetLongestCityConnectionPlots);

Code

2910int CvLuaGame::lGetLongestCityConnectionPlots(lua_State* L)2911{2912	CvPlot* pPlot1 = NULL;2913	CvPlot* pPlot2 = NULL;29142915	int iFurthestPlotDistance = 0;29162917	GC.getRouteFinder().SetNumExtraChildrenFunc(NULL);2918	GC.getRouteFinder().SetExtraChildGetterFunc(NULL);29192920	for(uint ui = 0; ui < MAX_MAJOR_CIVS; ui++)2921	{2922		PlayerTypes ePlayer = (PlayerTypes)ui;29232924		CvCity* pFirstCity = NULL;2925		CvCity* pSecondCity = NULL;2926		int iLoop1;2927		int iLoop2;29282929		for (pFirstCity = GET_PLAYER(ePlayer).firstCity(&iLoop1); pFirstCity != NULL; pFirstCity = GET_PLAYER(ePlayer).nextCity(&iLoop1))2930		{2931			CvPlot* pFirstCityPlot = pFirstCity->plot();29322933			for (pSecondCity = GET_PLAYER(ePlayer).firstCity(&iLoop2); pSecondCity != NULL; pSecondCity = GET_PLAYER(ePlayer).nextCity(&iLoop2))2934			{2935				// don't measure distance to same city2936				if (pFirstCity == pSecondCity)2937				{2938					continue;2939				}29402941				CvPlot* pSecondCityPlot = pSecondCity->plot();29422943#if !defined(NO_ACHIEVEMENTS)2944				bool bUsingXP2Scenario2 = gDLL->IsModActivated(CIV5_XP2_SCENARIO2_MODID) || gDLL->IsModActivated(CIV5_COMPLETE_SCENARIO1_MODID);2945				if(bUsingXP2Scenario2)2946				{2947					// active player2948					if (GC.getGame().getActivePlayer() == ePlayer)2949					{2950						const char* szCivKey = GET_PLAYER(ePlayer).getCivilizationTypeKey();2951						if (strcmp(szCivKey, "CIVILIZATION_ENGLAND") == 0)2952						{2953							if (pFirstCityPlot->getX() == 41 && pFirstCityPlot->getY() == 62 && // cairo2954								pSecondCityPlot->getX() == 32 && pSecondCityPlot->getY() == 6) // cape town2955							{2956								// assuming that there are fewer than 256 players2957								int iRouteValue = ROUTE_RAILROAD + 1;2958								int iPathfinderFlags = ui;2959								iPathfinderFlags |= (iRouteValue << 8);29602961								if (GC.getRouteFinder().GeneratePath(pFirstCityPlot->getX(), pFirstCityPlot->getY(), pSecondCityPlot->getX(), pSecondCityPlot->getY(), iPathfinderFlags, true))2962								{2963									gDLL->UnlockAchievement(ACHIEVEMENT_XP2_53);2964								}								2965							}2966						}2967					}2968				}2969#endif29702971				int iThisPlotDistance = plotDistance(pFirstCityPlot->getX(), pFirstCityPlot->getY(), pSecondCityPlot->getX(), pSecondCityPlot->getY());2972				if (iThisPlotDistance > iFurthestPlotDistance)2973				{2974					// assuming that there are fewer than 256 players2975					int iRouteValue = ROUTE_RAILROAD + 1;2976					int iPathfinderFlags = ui;2977					iPathfinderFlags |= (iRouteValue << 8);29782979					if (GC.getRouteFinder().GeneratePath(pFirstCityPlot->getX(), pFirstCityPlot->getY(), pSecondCityPlot->getX(), pSecondCityPlot->getY(), iPathfinderFlags, true))2980					{2981						// found a connection2982						pPlot1 = pFirstCityPlot;2983						pPlot2 = pSecondCityPlot;2984						iFurthestPlotDistance = iThisPlotDistance;2985					}2986				}2987			}2988		}2989	}29902991	// reconnect the land route pathfinder water methods2992	GC.getRouteFinder().SetNumExtraChildrenFunc(RouteGetNumExtraChildren);2993	GC.getRouteFinder().SetExtraChildGetterFunc(RouteGetExtraChild);29942995	CvLuaPlot::Push(L, pPlot1);2996	CvLuaPlot::Push(L, pPlot2);2997	return 2;2998}

Calls

Called by