Hooks
static bool BeforeCvWorldBuilderMapLoader_GetMapPlayers(lua_State* L, int& result);static void AfterCvWorldBuilderMapLoader_GetMapPlayers(lua_State* L, int& result);static int ReplaceCvWorldBuilderMapLoader_GetMapPlayers(int (*original)(lua_State*), lua_State* L);CivRegisterBefore<CivHooks::CvWorldBuilderMapLoader_GetMapPlayers>(host, &BeforeCvWorldBuilderMapLoader_GetMapPlayers);CivRegisterAfter<CivHooks::CvWorldBuilderMapLoader_GetMapPlayers>(host, &AfterCvWorldBuilderMapLoader_GetMapPlayers);CivRegisterReplace<CivHooks::CvWorldBuilderMapLoader_GetMapPlayers>(host, &ReplaceCvWorldBuilderMapLoader_GetMapPlayers);
Code
2041int CvWorldBuilderMapLoader::GetMapPlayers(lua_State* L)2042{2043 if(L == NULL)2044 {2045 FAssertMsg(L, "Seriously, you really need a lua state for this.");2046 return 0;2047 }20482049 const char* szUTF8MapFile = luaL_checkstring(L, 1);20502051 wchar_t wszMapFile[MAX_PATH] = {0};2052 MultiByteToWideChar(CP_UTF8, 0, szUTF8MapFile, -1, wszMapFile, MAX_PATH);20532054 if(CheckTempMap(wszMapFile) || sg_kTempMap.Load(wszMapFile, sg_kMapTypeDesc))2055 {2056 TempMapLoaded(wszMapFile);20572058 const uint uiPlayerCount = sg_kTempMap.GetPlayerCount();2059 const int iCivCount = GC.getNumCivilizationInfos();2060 const int iHandicapCount = GC.getNumHandicapInfos();20612062 lua_createtable(L, uiPlayerCount, 0);2063 for(uint uiPlayer = 0; uiPlayer < uiPlayerCount; ++uiPlayer)2064 {2065 const CvWorldBuilderMap::Player& kPlayer = sg_kTempMap.GetPlayer(uiPlayer);20662067 CivilizationTypes eCivType = NO_CIVILIZATION;2068 for(int iCiv = 0; iCiv < iCivCount; ++iCiv)2069 {2070 const CivilizationTypes eCurrentCiv = (CivilizationTypes)iCiv;2071 const CvCivilizationInfo* pkCiv = GC.getCivilizationInfo(eCurrentCiv);2072 if(pkCiv != NULL && strcmp(pkCiv->GetType(), kPlayer.m_szCivType) == 0)2073 {2074 eCivType = eCurrentCiv;2075 break;2076 }2077 }20782079 HandicapTypes eHandicapType = (HandicapTypes)GC.getSTANDARD_HANDICAP();2080 for(int iHandicap = 0; iHandicap < iHandicapCount; ++iHandicap)2081 {2082 const HandicapTypes eCurrentHandicap = (HandicapTypes)iHandicap;2083 const CvHandicapInfo* pkHandicap = GC.getHandicapInfo(eCurrentHandicap);2084 if(pkHandicap != NULL && strcmp(pkHandicap->GetType(), kPlayer.m_szHandicap) == 0)2085 {2086 eHandicapType = eCurrentHandicap;2087 break;2088 }2089 }20902091 lua_createtable(L, 0, 2);20922093 lua_pushstring(L, "CivType");2094 lua_pushinteger(L, eCivType);2095 lua_rawset(L, -3);20962097 lua_pushstring(L, "Playable");2098 lua_pushboolean(L, kPlayer.m_bPlayable);2099 lua_rawset(L, -3);21002101 lua_pushstring(L, "DefaultHandicap");2102 lua_pushinteger(L, eHandicapType);2103 lua_rawset(L, -3);21042105 lua_rawseti(L, -2, uiPlayer + 1);2106 }2107 }2108 else2109 {2110 lua_pushnil(L);2111 }21122113 return 1;2114}