Bazaar developer reference

CvLuaPlayer::lGetPotentialAdmiralNewPort(lua_State *)

Defined in
Lua/CvLuaPlayer.cpp, line 3964
Class
CvLuaPlayer
Hook name
CivHooks::CvLuaPlayer_lGetPotentialAdmiralNewPort

Hooks

static bool BeforeCvLuaPlayer_lGetPotentialAdmiralNewPort(lua_State* L, int& result);static void AfterCvLuaPlayer_lGetPotentialAdmiralNewPort(lua_State* L, int& result);static int ReplaceCvLuaPlayer_lGetPotentialAdmiralNewPort(int (*original)(lua_State*), lua_State* L);CivRegisterBefore<CivHooks::CvLuaPlayer_lGetPotentialAdmiralNewPort>(host, &BeforeCvLuaPlayer_lGetPotentialAdmiralNewPort);CivRegisterAfter<CivHooks::CvLuaPlayer_lGetPotentialAdmiralNewPort>(host, &AfterCvLuaPlayer_lGetPotentialAdmiralNewPort);CivRegisterReplace<CivHooks::CvLuaPlayer_lGetPotentialAdmiralNewPort>(host, &ReplaceCvLuaPlayer_lGetPotentialAdmiralNewPort);

Code

3964int CvLuaPlayer::lGetPotentialAdmiralNewPort(lua_State* L)3965{3966	CvPlayerAI* pkPlayer = GetInstance(L);3967	CvUnit* pkUnit = CvLuaUnit::GetInstance(L, 2, false);3968	CvPlot* pkUnitPlot = pkUnit->plot();39693970	lua_createtable(L, 0, 0);3971	int index = 1;39723973	if (pkUnit->canChangeAdmiralPort(pkUnitPlot))3974	{3975		int iCityLoop;3976		CvCity* pLoopCity = NULL;3977		for(pLoopCity = pkPlayer->firstCity(&iCityLoop); pLoopCity != NULL; pLoopCity = pkPlayer->nextCity(&iCityLoop))3978		{3979			int iLoopCityX = pLoopCity->getX();3980			int iLoopCityY = pLoopCity->getY();39813982			// can't change to its own home city3983			if (pLoopCity->plot() == pkUnitPlot)3984			{3985				continue;3986			}39873988			if (pkUnit->canChangeAdmiralPortAt(pkUnitPlot, iLoopCityX, iLoopCityY))3989			{3990				lua_createtable(L, 0, 0);3991				const int t = lua_gettop(L);3992				lua_pushinteger(L, pLoopCity->getX());3993				lua_setfield(L, t, "X");3994				lua_pushinteger(L, pLoopCity->getY());3995				lua_setfield(L, t, "Y");3996				lua_rawseti(L, -2, index++);3997			}3998		}3999	}40004001	return 1;4002}

Calls

Called by