Bazaar developer reference

CvDllScriptSystemUtility::PushReplayFromStream(lua_State *, FDataStream &)

Defined in
CvDllScriptSystemUtility.cpp, line 142
Class
CvDllScriptSystemUtility
Hook name
CivHooks::CvDllScriptSystemUtility_PushReplayFromStream

Hooks

static bool BeforeCvDllScriptSystemUtility_PushReplayFromStream(CvDllScriptSystemUtility* self, lua_State* L, FDataStream& stream);static void AfterCvDllScriptSystemUtility_PushReplayFromStream(CvDllScriptSystemUtility* self, lua_State* L, FDataStream& stream);static void ReplaceCvDllScriptSystemUtility_PushReplayFromStream(void (*original)(CvDllScriptSystemUtility*, lua_State*, FDataStream&), CvDllScriptSystemUtility* self, lua_State* L, FDataStream& stream);// CivHooks.h gives this hook point no types, so nothing checks these hooks' parameters.host->RegisterHook(host->pluginIndex, CivHooks::CvDllScriptSystemUtility_PushReplayFromStream::ID, CIV_HOOK_BEFORE, (void*)&BeforeCvDllScriptSystemUtility_PushReplayFromStream);host->RegisterHook(host->pluginIndex, CivHooks::CvDllScriptSystemUtility_PushReplayFromStream::ID, CIV_HOOK_AFTER, (void*)&AfterCvDllScriptSystemUtility_PushReplayFromStream);host->RegisterHook(host->pluginIndex, CivHooks::CvDllScriptSystemUtility_PushReplayFromStream::ID, CIV_HOOK_REPLACE, (void*)&ReplaceCvDllScriptSystemUtility_PushReplayFromStream);

Code

142void CvDllScriptSystemUtility::PushReplayFromStream(lua_State* L, FDataStream& stream)143{144	CvReplayInfo* pkReplay = FNEW(CvReplayInfo(), c_eMPoolTypeGame, 0);145	if(pkReplay)146	{147		if(!pkReplay->read(stream))148		{149			delete pkReplay;150			pkReplay = NULL;151		}152	}153154	if(pkReplay)155	{156		lua_createtable(L, 0, 0);157		const int t = lua_gettop(L);158159		lua_pushstring(L, pkReplay->getMapScriptName());160		lua_setfield(L, t, "MapScriptName");161162		lua_pushinteger(L, pkReplay->getActivePlayer());163		lua_setfield(L, t, "ActivePlayer");164165		lua_pushinteger(L, pkReplay->getWorldSize());166		lua_setfield(L, t, "WorldSize");167168		lua_pushinteger(L, pkReplay->getClimate());169		lua_setfield(L, t, "Climate");170171		lua_pushinteger(L, pkReplay->getSeaLevel());172		lua_setfield(L, t, "SeaLevel");173174		lua_pushinteger(L, pkReplay->getEra());175		lua_setfield(L, t, "Era");176177		lua_pushinteger(L, pkReplay->getGameSpeed());178		lua_setfield(L, t, "GameSpeed");179180		lua_pushinteger(L, pkReplay->getVictoryType());181		lua_setfield(L, t, "VictoryType");182183		lua_pushinteger(L, pkReplay->getGameType());184		lua_setfield(L, t, "GameType");185186		lua_pushinteger(L, pkReplay->getInitialTurn());187		lua_setfield(L, t, "InitialTurn");188189		lua_pushinteger(L, pkReplay->getFinalTurn());190		lua_setfield(L, t, "FinalTurn");191192		lua_pushinteger(L, pkReplay->getStartYear());193		lua_setfield(L, t, "StartYear");194195		lua_pushstring(L, pkReplay->getFinalDate());196		lua_setfield(L, t, "FinalDate");197198		lua_pushinteger(L, pkReplay->getCalendar());199		lua_setfield(L, t, "Calendar");200201		lua_pushinteger(L, pkReplay->getNormalizedScore());202		lua_setfield(L, t, "NormalizedScore");203204		lua_pushinteger(L, pkReplay->getMapHeight());205		lua_setfield(L, t, "MapHeight");206207		lua_pushinteger(L, pkReplay->getMapWidth());208		lua_setfield(L, t, "MapWidth");209210		const int numPlayers = pkReplay->getNumPlayers();211		lua_createtable(L, numPlayers, 0);212213		const unsigned int uiNumDataSets = pkReplay->getNumPlayerDataSets();214215		for(int iPlayer = 0; iPlayer < numPlayers; iPlayer++)216		{217			lua_createtable(L, 0, 0);218			const int playerIdx = lua_gettop(L);219220			lua_pushinteger(L, pkReplay->getPlayerCivilization(iPlayer));221			lua_setfield(L, playerIdx, "Civilization");222223			lua_pushinteger(L, pkReplay->getPlayerLeader(iPlayer));224			lua_setfield(L, playerIdx, "Leader");225226			lua_pushinteger(L, pkReplay->getPlayerColor(iPlayer));227			lua_setfield(L, playerIdx, "PlayerColor");228229			lua_pushinteger(L, pkReplay->getPlayerDifficulty(iPlayer));230			lua_setfield(L, playerIdx, "Difficulty");231232			lua_pushstring(L , pkReplay->getPlayerLeaderName(iPlayer));233			lua_setfield(L, playerIdx, "LeaderName");234235			lua_pushstring(L, pkReplay->getPlayerCivDescription(iPlayer));236			lua_setfield(L, playerIdx, "CivDescription");237238			lua_pushstring(L, pkReplay->getPlayerShortCivDescription(iPlayer));239			lua_setfield(L, playerIdx, "CivShortDescription");240241			lua_pushstring(L, pkReplay->getPlayerCivAdjective(iPlayer));242			lua_setfield(L, playerIdx, "CivAdjective");243244			lua_createtable(L, 0, 0);245			int iFinalTurn = pkReplay->getFinalTurn();246247			for(int iTurn = pkReplay->getInitialTurn(); iTurn <= iFinalTurn; ++iTurn)248			{249				lua_createtable(L, 0, 0);250251				for(unsigned int uiDataSet = 0; uiDataSet < uiNumDataSets; ++uiDataSet)252				{253					int iValue = 0;254					if(pkReplay->getPlayerDataSetValue(iPlayer, uiDataSet, iTurn, iValue))255					{256						lua_pushinteger(L, iValue);257						lua_setfield(L, -2, pkReplay->getPlayerDataSetName(uiDataSet));258					}259				}260261				lua_rawseti(L, -2, iTurn);262			}263			lua_setfield(L, playerIdx, "Scores");264265			lua_rawseti(L, -2, iPlayer + 1);	//Adjust iPlayer to be 1-based instead of 0-based.266		}267		lua_setfield(L, t, "PlayerInfo");268269		const int numReplayMessages = pkReplay->getNumReplayMessages();270		lua_createtable(L, numReplayMessages, 0);271		for(int i = 0; i < numReplayMessages; i++)272		{273			const CvReplayMessage* pkMessage = pkReplay->getReplayMessage(i);274			lua_createtable(L, 0, 0);275276			lua_pushinteger(L, pkMessage->getTurn());277			lua_setfield(L, -2, "Turn");278279			lua_pushinteger(L, pkMessage->getType());280			lua_setfield(L, -2, "Type");281282			int iPlayer = pkMessage->getPlayer();283			lua_pushinteger(L, (iPlayer > -1)? iPlayer + 1 : iPlayer);	//Adjust iPlayer to match the 1-based index scheme.284			lua_setfield(L, -2, "Player");285286			lua_pushstring(L, pkMessage->getText());287			lua_setfield(L, -2, "Text");288289			const int numPlots = pkMessage->getNumPlots();290			lua_createtable(L, numPlots, 0);291			for(int iPlot = 0; iPlot < numPlots; ++iPlot)292			{293				int iPlotX = 0;294				int iPlotY = 0;295				pkMessage->getPlot(iPlot, iPlotX, iPlotY);296297				lua_createtable(L, 0, 2);298				lua_pushinteger(L, iPlotX);299				lua_setfield(L, -2, "X");300301				lua_pushinteger(L, iPlotY);302				lua_setfield(L, -2, "Y");303304				lua_rawseti(L, -2, iPlot + 1);305			}306			lua_setfield(L, -2, "Plots");307308			lua_rawseti(L, -2, i);309		}310		lua_setfield(L, t, "Messages");311312		const int uiHeight = pkReplay->getMapHeight();313		const int uiWidth = pkReplay->getMapWidth();314315		lua_createtable(L, uiHeight * uiWidth, 0);316		int idx = 1;317		for(int uiY = 0; uiY < uiHeight; ++uiY)318		{319			for(int uiX = 0; uiX < uiWidth; ++uiX)320			{321				lua_createtable(L, 0, 0);322				for(int i = pkReplay->getInitialTurn(); i <= pkReplay->getFinalTurn(); ++i)323				{324					CvReplayInfo::PlotState plotState;325					if(pkReplay->getPlotState(uiX, uiY, i, plotState))326					{327						lua_createtable(L, 6, 0);328329						lua_pushinteger(L, plotState.m_ePlotType);330						lua_setfield(L, -2, "PlotType");331332						lua_pushinteger(L, plotState.m_eTerrain);333						lua_setfield(L, -2, "TerrainType");334335						lua_pushinteger(L, plotState.m_eFeature);336						lua_setfield(L, -2, "FeatureType");337338						lua_pushinteger(L, plotState.m_bNEOfRiver);339						lua_setfield(L, -2, "NEOfRiver");340341						lua_pushinteger(L, plotState.m_bWOfRiver);342						lua_setfield(L, -2, "WOfRiver");343344						lua_pushinteger(L, plotState.m_bNWOfRiver);345						lua_setfield(L, -2, "NWOfRiver");346347						lua_rawseti(L, -2, i);348					}349				}350351				lua_rawseti(L, -2, idx++);352			}353		}354		lua_setfield(L, t, "Plots");355356		delete pkReplay;357	}358}

Calls