Hooks
static bool BeforeCvWorldBuilderMapLoader_GetMapPreview(lua_State* L, int& result);static void AfterCvWorldBuilderMapLoader_GetMapPreview(lua_State* L, int& result);static int ReplaceCvWorldBuilderMapLoader_GetMapPreview(int (*original)(lua_State*), lua_State* L);CivRegisterBefore<CivHooks::CvWorldBuilderMapLoader_GetMapPreview>(host, &BeforeCvWorldBuilderMapLoader_GetMapPreview);CivRegisterAfter<CivHooks::CvWorldBuilderMapLoader_GetMapPreview>(host, &AfterCvWorldBuilderMapLoader_GetMapPreview);CivRegisterReplace<CivHooks::CvWorldBuilderMapLoader_GetMapPreview>(host, &ReplaceCvWorldBuilderMapLoader_GetMapPreview);
Code
1928int CvWorldBuilderMapLoader::GetMapPreview(lua_State* L)1929{1930 if(L == NULL)1931 {1932 FAssertMsg(L, "Seriously, you really need a lua state for this.");1933 return 0;1934 }19351936 const char* szUTF8MapFile = luaL_checkstring(L, 1);19371938 wchar_t wszMapFile[MAX_PATH] = {0};1939 MultiByteToWideChar(CP_UTF8, 0, szUTF8MapFile, -1, wszMapFile, MAX_PATH);19401941 if(CheckTempMap(wszMapFile) || sg_kTempMap.Load(wszMapFile, sg_kMapTypeDesc))1942 {1943 TempMapLoaded(wszMapFile);19441945 WorldSizeTypes eWorldSize = GetWorldSizeType(sg_kTempMap);19461947 const char* szDefaultSpeed = sg_kTempMap.GetDefaultGameSpeed();1948 GameSpeedTypes eDefaultSpeed = (GameSpeedTypes)GC.getSTANDARD_GAMESPEED();1949 const int iSpeedCount = GC.getNumGameSpeedInfos();1950 for(int i = 0; i < iSpeedCount; ++i)1951 {1952 const GameSpeedTypes eSpeed = (GameSpeedTypes)i;1953 const CvGameSpeedInfo* pkSpeed = GC.getGameSpeedInfo(eSpeed);1954 if(pkSpeed != NULL && strcmp(pkSpeed->GetType(), szDefaultSpeed) == 0)1955 {1956 eDefaultSpeed = eSpeed;1957 break;1958 }1959 }19601961 const char* szStartEra = "";1962 for(int i = 0; i < sg_kTempMap.GetPlayerCount(); ++i)1963 {1964 const CvWorldBuilderMap::Player& kPlayer = sg_kTempMap.GetPlayer(i);1965 if(kPlayer.m_bPlayable)1966 {1967 bool bFound = false;1968 for(int iEra = 0; iEra < GC.getNumEraInfos(); ++iEra)1969 {1970 CvEraInfo* pkEraInfo = GC.getEraInfo((EraTypes)iEra);1971 if(pkEraInfo != NULL && strcmp(pkEraInfo->GetType(), kPlayer.m_szEra) == 0)1972 {1973 szStartEra = pkEraInfo->GetText();1974 bFound = true;1975 break;1976 }1977 }19781979 if(bFound)1980 break;1981 }1982 }19831984 lua_createtable(L, 0, 8);19851986 lua_pushstring(L, "MapSize");1987 lua_pushinteger(L, eWorldSize);1988 lua_rawset(L, -3);19891990 lua_pushstring(L, "Name");1991 lua_pushstring(L, sg_kTempMap.m_sMapName);1992 lua_rawset(L, -3);19931994 lua_pushstring(L, "Description");1995 lua_pushstring(L, sg_kTempMap.m_sMapDescription);1996 lua_rawset(L, -3);19971998 lua_pushstring(L, "PlayerCount");1999 lua_pushnumber(L, sg_kTempMap.GetPlayerCount());2000 lua_rawset(L, -3);20012002 lua_pushstring(L, "CityStateCount");2003 lua_pushnumber(L, sg_kTempMap.GetCityStateCount());2004 lua_rawset(L, -3);20052006 lua_pushstring(L, "MaxTurns");2007 lua_pushnumber(L, sg_kTempMap.GetMaxTurns());2008 lua_rawset(L, -3);20092010 lua_pushstring(L, "StartEra");2011 lua_pushstring(L, szStartEra);2012 lua_rawset(L, -3);20132014 lua_pushstring(L, "DefaultSpeed");2015 lua_pushinteger(L, eDefaultSpeed);2016 lua_rawset(L, -3);20172018 const int iVictoryTypes = GC.getNumVictoryInfos();2019 lua_pushstring(L, "VictoryTypes");2020 lua_createtable(L, iVictoryTypes, 0);2021 for(int i = 0; i < iVictoryTypes; ++i)2022 {2023 const char* szVictoryType = "";2024 const CvVictoryInfo* pkInfo = GC.getVictoryInfo((VictoryTypes)i);2025 if(pkInfo != NULL)2026 szVictoryType = pkInfo->GetType();20272028 lua_pushstring(L, szVictoryType);2029 lua_rawseti(L, -2, i + 1);2030 }2031 lua_rawset(L, -3);2032 }2033 else2034 {2035 lua_pushnil(L);2036 }20372038 return 1;2039}