Code
1986//1987// allocate1988//1989void CvGlobals::init()1990{1991#if defined(MOD_DEBUG_MINIDUMP)1992 /* Enable our custom exception that will write the minidump for us. */1993 SetUnhandledExceptionFilter(CustomFilter);1994 CUSTOMLOG("MiniDump exception handler installed");1995#endif19961997 //1998 // These vars are used to initialize the globals.1999 //2000 int aiPlotDirectionX[NUM_DIRECTION_TYPES] =2001 {2002 0, // DIRECTION_NORTHEAST2003 1, // DIRECTION_EAST2004 1, // DIRECTION_SOUTHEAST2005 0, // DIRECTION_SOUTHWEST2006 -1, // DIRECTION_WEST2007 -1, // DIRECTION_NORTHWEST2008 };20092010 int aiPlotDirectionY[NUM_DIRECTION_TYPES] =2011 {2012 1, // DIRECTION_NORTHEAST2013 0, // DIRECTION_EAST2014 -1, // DIRECTION_SOUTHEAST2015 -1, // DIRECTION_SOUTHWEST2016 0, // DIRECTION_WEST2017 1, // DIRECTION_NORTHWEST2018 };20192020 // these are now in hex-space coords2021#if defined(MOD_GLOBAL_CITY_WORKING)2022 int aiCityPlotX[MAX_CITY_PLOTS] =2023#else2024 int aiCityPlotX[NUM_CITY_PLOTS] =2025#endif2026 {2027 // 02028 0,2029 // 1 2 3 4 5 62030 0, 1, 1, 0, -1, -1,2031 // 7 8 9 10 11 12 13 14 15 16 17 182032 0, 1, 2, 2, 2, 1, 0, -1, -2, -2, -2, -1,2033 // 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 362034 0, 1, 2, 3, 3, 3, 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -2, -1,2035#if defined(MOD_GLOBAL_CITY_WORKING)2036 // 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 602037 0, 1, 2, 3, 4, 4, 4, 4, 4, 3, 2, 1, 0, -1, -2, -3, -4, -4, -4, -4, -4, -3, -2, -1,2038 // 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 902039 0, 1, 2, 3, 4, 5, 5, 5, 5, 5, 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -5, -5, -5, -5, -5, -4, -3, -2, -1,2040 // The pattern for the Nth ring is 0 .. N, (N-1) * N, N .. -N, (N-1) * -N, -N .. -12041#else2042 // 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 602043 // 0, 1, 2, 3, 4, 4, 4, 4, 4, 3, 2, 1, 0, -1, -2, -3, -4, -4, -4, -4, -4, -3, -2, -1,2044#endif2045 };20462047#if defined(MOD_GLOBAL_CITY_WORKING)2048 int aiCityPlotY[MAX_CITY_PLOTS] =2049#else2050 int aiCityPlotY[NUM_CITY_PLOTS] =2051#endif2052 {2053 // 02054 0,2055 // 1 2 3 4 5 62056 1, 0, -1, -1, 0, 1,2057 // 7 8 9 10 11 12 13 14 15 16 17 182058 2, 1, 0, -1, -2, -2, -2, -1, 0, 1, 2, 2,2059 // 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 362060 3, 2, 1, 0, -1, -2, -3, -3, -3, -3, -2, -1, 0, 1, 2, 3, 3, 3,2061#if defined(MOD_GLOBAL_CITY_WORKING)2062 // 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 602063 4, 3, 2, 1, 0, -1, -2, -3, -4, -4, -4, -4, -4, -3, -2, -1, 0, 1, 2, 3, 4, 4, 4, 4,2064 // 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 902065 5, 4, 3, 2, 1, 0, -1, -2, -3, -4, -5, -5, -5, -5, -5, -5, -4, -3, -2, -1, 0, 1, 2, 3, 4, 5, 5, 5, 5, 5,2066 // The pattern for the Nth ring is N .. -N, (N-1) * -N, -N .. N, (N-1) * N2067#else2068 // 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 602069 // 4, 3, 2, 1, 0, -1, -2, -3, -4, -4, -4, -4, -4, -3, -2, -1, 0, 1, 2, 3, 4, 4, 4, 4,2070#endif2071 };20722073#if defined(MOD_GLOBAL_CITY_WORKING)2074 int aiCityPlotPriority[MAX_CITY_PLOTS] =2075#else2076 int aiCityPlotPriority[NUM_CITY_PLOTS] =2077#endif2078 {2079 0,2080 1, 1, 1, 1, 1, 1,2081 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2,2082 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3, 3,2083#if defined(MOD_GLOBAL_CITY_WORKING)2084 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,2085 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5, 5,2086 // The pattern for the Nth ring is (6*N) N2087#else2088 //4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4,2089#endif2090 };20912092#if defined(MOD_GLOBAL_CITY_WORKING)2093 int aaiXYCityPlot[2*MAX_CITY_RADIUS+1][2*MAX_CITY_RADIUS+1] =2094#else2095 int aaiXYCityPlot[CITY_PLOTS_DIAMETER][CITY_PLOTS_DIAMETER] =2096#endif2097 {2098#if defined(MOD_GLOBAL_CITY_WORKING)2099 // this is the 5 ring layout2100 // -5 -4 -3 -2 -1 0 1 2 3 4 5 -- in the Y direction2101 {-1, -1, -1, -1, -1, 81, 82, 83, 84, 85, 86,}, // -5 hex-space x2102 {-1, -1, -1, -1, 80, 53, 54, 55, 56, 57, 87,}, // -4 hex-space x2103 {-1, -1, -1, 79, 52, 31, 32, 33, 34, 58, 88,}, // -3 hex-space x2104 {-1, -1, 78, 51, 30, 15, 16, 17, 35, 59, 89,}, // -2 hex-space x2105 {-1, 77, 50, 29, 14, 5, 6, 18, 36, 60, 90,}, // -1 hex-space x2106 {76, 49, 28, 13, 4, 0, 1, 7, 19, 37, 61,}, // 0 hex-space x2107 {75, 48, 27, 12, 3, 2, 8, 20, 38, 62, -1,}, // 1 hex-space x2108 {74, 47, 26, 11, 10, 9, 21, 39, 63, -1, -1,}, // 2 hex-space x2109 {73, 46, 25, 24, 23, 22, 40, 64, -1, -1, -1,}, // 3 hex-space x2110 {72, 45, 44, 43, 42, 41, 65, -1, -1, -1, -1,}, // 4 hex-space x2111 {71, 70, 69, 68, 67, 66, -1, -1, -1, -1, -1,}, // 5 hex-space x2112 // There is no pattern to this, adding a ring requires adding a new row at the top and bottom AND a -1 entry at the start and end of each existing row2113#endif2114 // this is the 4 ring layout2115 /*2116 // -4 -3 -2 -1 0 1 2 3 4 -- in the Y direction2117 {-1, -1, -1, -1, 53, 54, 55, 56, 57,}, // -4 hex-space x2118 {-1, -1, -1, 52, 31, 32, 33, 34, 58,}, // -3 hex-space x2119 {-1, -1, 51, 30, 15, 16, 17, 35, 59,}, // -2 hex-space x2120 {-1, 50, 29, 14, 5, 6, 18, 36, 60,}, // -1 hex-space x2121 {49, 28, 13, 4, 0, 1, 7, 19, 37,}, // 0 hex-space x2122 {48, 27, 12, 3, 2, 8, 20, 38, -1,}, // 1 hex-space x2123 {47, 26, 11, 10, 9, 21, 39, -1, -1,}, // 2 hex-space x2124 {46, 25, 24, 23, 22, 40, -1, -1, -1,}, // 3 hex-space x2125 {45, 44, 43, 42, 41, -1, -1, -1, -1,}, // 4 hex-space x2126 */2127#if !defined(MOD_GLOBAL_CITY_WORKING)2128 // this is the 3 ring layout2129 // -3 -2 -1 0 1 2 3 -- in the Y direction2130 {-1, -1, -1, 31, 32, 33, 34,}, // -3 hex-space x2131 {-1, -1, 30, 15, 16, 17, 35,}, // -2 hex-space x2132 {-1, 29, 14, 5, 6, 18, 36,}, // -1 hex-space x2133 {28, 13, 4, 0, 1, 7, 19,}, // 0 hex-space x2134 {27, 12, 3, 2, 8, 20, -1,}, // 1 hex-space x2135 {26, 11, 10, 9, 21, -1, -1,}, // 2 hex-space x2136 {25, 24, 23, 22, -1, -1, -1,}, // 3 hex-space x2137#endif2138 /*2139 // this is the 2 ring layout2140 // -2 -1 0 1 2 -- in the Y direction2141 {-1, -1, 16, 17, 18,}, // -2 hex-space x2142 {-1, 15, 5, 6, 7,}, // -1 hex-space x2143 {14, 4, 0, 1, 8,}, // 0 hex-space x2144 {13, 3, 2, 9, -1,}, // 1 hex-space x2145 {12, 11, 10, -1, -1,}, // 2 hex-space x2146 */2147 };21482149 DirectionTypes aeTurnRightDirection[NUM_DIRECTION_TYPES] =2150 {2151 DIRECTION_EAST, // DIRECTION_NORTHEAST or DIRECTION_NORTH (deprecated)2152 DIRECTION_SOUTHEAST, // DIRECTION_EAST2153 DIRECTION_SOUTHWEST, // DIRECTION_SOUTHEAST2154 DIRECTION_WEST, // DIRECTION_SOUTHWEST or DIRECTION_SOUTH (deprecated)2155 DIRECTION_NORTHWEST, // DIRECTION_WEST2156 DIRECTION_NORTHEAST, // DIRECTION_NORTHWEST2157 };21582159 DirectionTypes aeTurnLeftDirection[NUM_DIRECTION_TYPES] =2160 {2161 DIRECTION_NORTHWEST, // DIRECTION_NORTHEAST or DIRECTION_NORTH (deprecated)2162 DIRECTION_NORTHEAST, // DIRECTION_EAST2163 DIRECTION_EAST, // DIRECTION_SOUTHEAST2164 DIRECTION_SOUTHEAST, // DIRECTION_SOUTHWEST or DIRECTION_SOUTH (deprecated)2165 DIRECTION_SOUTHWEST, // DIRECTION_WEST2166 DIRECTION_WEST, // DIRECTION_NORTHWEST2167 };21682169 CvAssertMsg(gDLL != NULL, "Civ app needs to set gDLL");2170 m_asyncRand = FNEW(CvRandom, c_eCiv5GameplayDLL, 0);21712172 gDLL->InitGlobals(); // some globals need to be allocated outside the dll21732174 m_game = FNEW(CvGame, c_eCiv5GameplayDLL, 0);2175 m_map = FNEW(CvMap, c_eCiv5GameplayDLL, 0);21762177 m_pEconomicAIStrategies = FNEW(CvEconomicAIStrategyXMLEntries, c_eCiv5GameplayDLL, 0);2178 m_pCitySpecializations = FNEW(CvCitySpecializationXMLEntries, c_eCiv5GameplayDLL, 0);2179 m_pTacticalMoves = FNEW(CvTacticalMoveXMLEntries, c_eCiv5GameplayDLL, 0);2180 m_pMilitaryAIStrategies = FNEW(CvMilitaryAIStrategyXMLEntries, c_eCiv5GameplayDLL, 0);2181 m_pAIGrandStrategies = FNEW(CvAIGrandStrategyXMLEntries, c_eCiv5GameplayDLL, 0);2182 m_pAICityStrategies = FNEW(CvAICityStrategies, c_eCiv5GameplayDLL, 0);2183 m_pPolicies = FNEW(CvPolicyXMLEntries, c_eCiv5GameplayDLL, 0);2184 m_pTechs = FNEW(CvTechXMLEntries, c_eCiv5GameplayDLL, 0);2185 m_pBuildings = FNEW(CvBuildingXMLEntries, c_eCiv5GameplayDLL, 0);2186 m_pUnits = FNEW(CvUnitXMLEntries, c_eCiv5GameplayDLL, 0);2187 m_pProjects = FNEW(CvProjectXMLEntries, c_eCiv5GameplayDLL, 0);2188 m_pPromotions = FNEW(CvPromotionXMLEntries, c_eCiv5GameplayDLL, 0);2189 m_pImprovements = FNEW(CvImprovementXMLEntries, c_eCiv5GameplayDLL, 0);2190 m_pEmphases = FNEW(CvEmphasisXMLEntries, c_eCiv5GameplayDLL, 0);2191 m_pTraits = FNEW(CvTraitXMLEntries, c_eCiv5GameplayDLL, 0);2192 m_pReligions = FNEW(CvReligionXMLEntries, c_eCiv5GameplayDLL, 0);2193 m_pBeliefs = FNEW(CvBeliefXMLEntries, c_eCiv5GameplayDLL, 0);2194 m_pLeagueSpecialSessions = FNEW(CvLeagueSpecialSessionXMLEntries, c_eCiv5GameplayDLL, 0);2195 m_pLeagueNames = FNEW(CvLeagueNameXMLEntries, c_eCiv5GameplayDLL, 0);2196 m_pLeagueProjects = FNEW(CvLeagueProjectXMLEntries, c_eCiv5GameplayDLL, 0);2197 m_pLeagueProjectRewards = FNEW(CvLeagueProjectRewardXMLEntries, c_eCiv5GameplayDLL, 0);2198 m_pResolutions = FNEW(CvResolutionXMLEntries, c_eCiv5GameplayDLL, 0);2199 m_pNotifications = FNEW(CvNotificationXMLEntries, c_eCiv5GameplayDLL, 0);2200#if defined(MOD_API_ACHIEVEMENTS) || defined(ACHIEVEMENT_HACKS)2201 m_pAchievements = FNEW(CvAchievementXMLEntries, c_eCiv5GameplayDLL, 0);2202#endif22032204 auto_ptr<ICvDLLDatabaseUtility1> pkLoader(getDatabaseLoadUtility());22052206 Database::Connection* pDB = GetGameDatabase();2207 pDB->Execute(m_kGlobalDefinesLookup, "SELECT Value from Defines where Name = ? LIMIT 1");22082209 pkLoader->PerformDatabasePostProcessing();2210 pkLoader->CacheGameDatabaseData();22112212 CvPlayerAI::initStatics();2213 CvTeam::initStatics();22142215 memcpy(m_aiPlotDirectionX, aiPlotDirectionX, sizeof(m_aiPlotDirectionX));2216 memcpy(m_aiPlotDirectionY, aiPlotDirectionY, sizeof(m_aiPlotDirectionY));2217 memcpy(m_aiCityPlotX, aiCityPlotX, sizeof(m_aiCityPlotX));2218 memcpy(m_aiCityPlotY, aiCityPlotY, sizeof(m_aiCityPlotY));2219 memcpy(m_aiCityPlotPriority, aiCityPlotPriority, sizeof(m_aiCityPlotPriority));2220 memcpy(m_aeTurnLeftDirection, aeTurnLeftDirection, sizeof(m_aeTurnLeftDirection));2221 memcpy(m_aeTurnRightDirection, aeTurnRightDirection, sizeof(m_aeTurnRightDirection));2222 memcpy(m_aaiXYCityPlot, aaiXYCityPlot, sizeof(m_aaiXYCityPlot));22232224 setPathFinder(FNEW(CvTwoLayerPathFinder, c_eCiv5GameplayDLL, 0));2225 setInterfacePathFinder(FNEW(CvTwoLayerPathFinder, c_eCiv5GameplayDLL, 0));2226 setIgnoreUnitsPathFinder(FNEW(CvIgnoreUnitsPathFinder, c_eCiv5GameplayDLL, 0));2227 setStepFinder(FNEW(CvStepPathFinder, c_eCiv5GameplayDLL, 0));2228 setRouteFinder(FNEW(CvAStar, c_eCiv5GameplayDLL, 0));2229 SetWaterRouteFinder(FNEW(CvAStar, c_eCiv5GameplayDLL, 0));2230 setAreaFinder(FNEW(CvAStar, c_eCiv5GameplayDLL, 0));2231 setInfluenceFinder(FNEW(CvAStar, c_eCiv5GameplayDLL, 0));2232 SetBuildRouteFinder(FNEW(CvAStar, c_eCiv5GameplayDLL, 0));2233 SetInternationalTradeRouteLandFinder(FNEW(CvAStar, c_eCiv5GameplayDLL, 0));2234 SetInternationalTradeRouteWaterFinder(FNEW(CvAStar, c_eCiv5GameplayDLL, 0));2235 SetTacticalAnalysisMapFinder(FNEW(CvTwoLayerPathFinder, c_eCiv5GameplayDLL, 0));2236}