CvMap.cpp 34 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451
  1. //
  2. // FILE: CvMap.cpp
  3. // AUTHOR: Soren Johnson
  4. // PURPOSE: Game map class
  5. //-----------------------------------------------------------------------------
  6. // Copyright (c) 2004 Firaxis Games, Inc. All rights reserved.
  7. //-----------------------------------------------------------------------------
  8. //
  9. #include "CvGameCoreDLL.h"
  10. #include "CvMap.h"
  11. #include "CvCity.h"
  12. #include "CvPlotGroup.h"
  13. #include "CvGlobals.h"
  14. #include "CvGameAI.h"
  15. #include "CvPlayerAI.h"
  16. #include "CvRandom.h"
  17. #include "CvGameCoreUtils.h"
  18. #include "CvFractal.h"
  19. #include "CvPlot.h"
  20. #include "CvGameCoreUtils.h"
  21. #include "CvMap.h"
  22. #include "CvMapGenerator.h"
  23. #include "FAStarNode.h"
  24. #include "CvInitCore.h"
  25. #include "CvInfos.h"
  26. #include "FProfiler.h"
  27. #include "CyArgsList.h"
  28. #include "CvDLLEngineIFaceBase.h"
  29. #include "CvDLLIniParserIFaceBase.h"
  30. #include "CvDLLFAStarIFaceBase.h"
  31. #include "CvDLLFAStarIFaceBase.h"
  32. #include "CvDLLPythonIFaceBase.h"
  33. // Public Functions...
  34. CvMap::CvMap()
  35. {
  36. CvMapInitData defaultMapData;
  37. m_paiNumBonus = NULL;
  38. m_paiNumBonusOnLand = NULL;
  39. m_pMapPlots = NULL;
  40. reset(&defaultMapData);
  41. }
  42. CvMap::~CvMap()
  43. {
  44. uninit();
  45. }
  46. // FUNCTION: init()
  47. // Initializes the map.
  48. // Parameters:
  49. // pInitInfo - Optional init structure (used for WB load)
  50. // Returns:
  51. // nothing.
  52. void CvMap::init(CvMapInitData* pInitInfo/*=NULL*/)
  53. {
  54. int iX, iY;
  55. PROFILE("CvMap::init");
  56. gDLL->logMemState( CvString::format("CvMap::init begin - world size=%s, climate=%s, sealevel=%s, num custom options=%6",
  57. GC.getWorldInfo(GC.getInitCore().getWorldSize()).getDescription(),
  58. GC.getClimateInfo(GC.getInitCore().getClimate()).getDescription(),
  59. GC.getSeaLevelInfo(GC.getInitCore().getSeaLevel()).getDescription(),
  60. GC.getInitCore().getNumCustomMapOptions()).c_str() );
  61. gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "beforeInit");
  62. //--------------------------------
  63. // Init saved data
  64. reset(pInitInfo);
  65. //--------------------------------
  66. // Init containers
  67. m_areas.init();
  68. //--------------------------------
  69. // Init non-saved data
  70. setup();
  71. //--------------------------------
  72. // Init other game data
  73. gDLL->logMemState("CvMap before init plots");
  74. m_pMapPlots = new CvPlot[numPlotsINLINE()];
  75. for (iX = 0; iX < getGridWidthINLINE(); iX++)
  76. {
  77. gDLL->callUpdater();
  78. for (iY = 0; iY < getGridHeightINLINE(); iY++)
  79. {
  80. plotSorenINLINE(iX, iY)->init(iX, iY);
  81. }
  82. }
  83. calculateAreas();
  84. gDLL->logMemState("CvMap after init plots");
  85. }
  86. void CvMap::uninit()
  87. {
  88. SAFE_DELETE_ARRAY(m_paiNumBonus);
  89. SAFE_DELETE_ARRAY(m_paiNumBonusOnLand);
  90. SAFE_DELETE_ARRAY(m_pMapPlots);
  91. m_areas.uninit();
  92. }
  93. // FUNCTION: reset()
  94. // Initializes data members that are serialized.
  95. void CvMap::reset(CvMapInitData* pInitInfo)
  96. {
  97. int iI;
  98. //--------------------------------
  99. // Uninit class
  100. uninit();
  101. //
  102. // set grid size
  103. // initially set in terrain cell units
  104. //
  105. m_iGridWidth = (GC.getInitCore().getWorldSize() != NO_WORLDSIZE) ? GC.getWorldInfo(GC.getInitCore().getWorldSize()).getGridWidth (): 0; //todotw:tcells wide
  106. m_iGridHeight = (GC.getInitCore().getWorldSize() != NO_WORLDSIZE) ? GC.getWorldInfo(GC.getInitCore().getWorldSize()).getGridHeight (): 0;
  107. // allow grid size override
  108. if (pInitInfo)
  109. {
  110. m_iGridWidth = pInitInfo->m_iGridW;
  111. m_iGridHeight = pInitInfo->m_iGridH;
  112. }
  113. else
  114. {
  115. // check map script for grid size override
  116. if (GC.getInitCore().getWorldSize() != NO_WORLDSIZE)
  117. {
  118. std::vector<int> out;
  119. CyArgsList argsList;
  120. argsList.add(GC.getInitCore().getWorldSize());
  121. bool ok = gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "getGridSize", argsList.makeFunctionArgs(), &out);
  122. if (ok && !gDLL->getPythonIFace()->pythonUsingDefaultImpl() && out.size() == 2)
  123. {
  124. m_iGridWidth = out[0];
  125. m_iGridHeight = out[1];
  126. FAssertMsg(m_iGridWidth > 0 && m_iGridHeight > 0, "the width and height returned by python getGridSize() must be positive");
  127. }
  128. }
  129. // convert to plot dimensions
  130. if (GC.getNumLandscapeInfos() > 0)
  131. {
  132. m_iGridWidth *= GC.getLandscapeInfo(GC.getActiveLandscapeID()).getPlotsPerCellX();
  133. m_iGridHeight *= GC.getLandscapeInfo(GC.getActiveLandscapeID()).getPlotsPerCellY();
  134. }
  135. }
  136. m_iLandPlots = 0;
  137. m_iOwnedPlots = 0;
  138. if (pInitInfo)
  139. {
  140. m_iTopLatitude = pInitInfo->m_iTopLatitude;
  141. m_iBottomLatitude = pInitInfo->m_iBottomLatitude;
  142. }
  143. else
  144. {
  145. // Check map script for latitude override (map script beats ini file)
  146. long resultTop = -1, resultBottom = -1;
  147. bool okX = gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "getTopLatitude", NULL, &resultTop);
  148. bool overrideX = !gDLL->getPythonIFace()->pythonUsingDefaultImpl();
  149. bool okY = gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "getBottomLatitude", NULL, &resultBottom);
  150. bool overrideY = !gDLL->getPythonIFace()->pythonUsingDefaultImpl();
  151. if (okX && okY && overrideX && overrideY && resultTop != -1 && resultBottom != -1)
  152. {
  153. m_iTopLatitude = resultTop;
  154. m_iBottomLatitude = resultBottom;
  155. }
  156. }
  157. m_iTopLatitude = std::min(m_iTopLatitude, 90);
  158. m_iTopLatitude = std::max(m_iTopLatitude, -90);
  159. m_iBottomLatitude = std::min(m_iBottomLatitude, 90);
  160. m_iBottomLatitude = std::max(m_iBottomLatitude, -90);
  161. m_iNextRiverID = 0;
  162. //
  163. // set wrapping
  164. //
  165. m_bWrapX = true;
  166. m_bWrapY = false;
  167. if (pInitInfo)
  168. {
  169. m_bWrapX = pInitInfo->m_bWrapX;
  170. m_bWrapY = pInitInfo->m_bWrapY;
  171. }
  172. else
  173. {
  174. // Check map script for wrap override (map script beats ini file)
  175. long resultX = -1, resultY = -1;
  176. bool okX = gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "getWrapX", NULL, &resultX);
  177. bool overrideX = !gDLL->getPythonIFace()->pythonUsingDefaultImpl();
  178. bool okY = gDLL->getPythonIFace()->callFunction(gDLL->getPythonIFace()->getMapScriptModule(), "getWrapY", NULL, &resultY);
  179. bool overrideY = !gDLL->getPythonIFace()->pythonUsingDefaultImpl();
  180. if (okX && okY && overrideX && overrideY && resultX != -1 && resultY != -1)
  181. {
  182. m_bWrapX = (resultX != 0);
  183. m_bWrapY = (resultY != 0);
  184. }
  185. }
  186. if (GC.getNumBonusInfos())
  187. {
  188. FAssertMsg((0 < GC.getNumBonusInfos()), "GC.getNumBonusInfos() is not greater than zero but an array is being allocated in CvMap::reset");
  189. FAssertMsg(m_paiNumBonus==NULL, "mem leak m_paiNumBonus");
  190. m_paiNumBonus = new int[GC.getNumBonusInfos()];
  191. FAssertMsg(m_paiNumBonusOnLand==NULL, "mem leak m_paiNumBonusOnLand");
  192. m_paiNumBonusOnLand = new int[GC.getNumBonusInfos()];
  193. for (iI = 0; iI < GC.getNumBonusInfos(); iI++)
  194. {
  195. m_paiNumBonus[iI] = 0;
  196. m_paiNumBonusOnLand[iI] = 0;
  197. }
  198. }
  199. m_areas.removeAll();
  200. }
  201. // FUNCTION: setup()
  202. // Initializes all data that is not serialized but needs to be initialized after loading.
  203. void CvMap::setup()
  204. {
  205. PROFILE("CvMap::setup");
  206. gDLL->getFAStarIFace()->Initialize(&GC.getPathFinder(), getGridWidthINLINE(), getGridHeightINLINE(), isWrapXINLINE(), isWrapYINLINE(), pathDestValid, pathHeuristic, pathCost, pathValid, pathAdd, NULL, NULL);
  207. gDLL->getFAStarIFace()->Initialize(&GC.getInterfacePathFinder(), getGridWidthINLINE(), getGridHeightINLINE(), isWrapXINLINE(), isWrapYINLINE(), pathDestValid, pathHeuristic, pathCost, pathValid, pathAdd, NULL, NULL);
  208. gDLL->getFAStarIFace()->Initialize(&GC.getStepFinder(), getGridWidthINLINE(), getGridHeightINLINE(), isWrapXINLINE(), isWrapYINLINE(), stepDestValid, stepHeuristic, stepCost, stepValid, stepAdd, NULL, NULL);
  209. gDLL->getFAStarIFace()->Initialize(&GC.getRouteFinder(), getGridWidthINLINE(), getGridHeightINLINE(), isWrapXINLINE(), isWrapYINLINE(), NULL, NULL, NULL, routeValid, NULL, NULL, NULL);
  210. gDLL->getFAStarIFace()->Initialize(&GC.getBorderFinder(), getGridWidthINLINE(), getGridHeightINLINE(), isWrapXINLINE(), isWrapYINLINE(), NULL, NULL, NULL, borderValid, NULL, NULL, NULL);
  211. gDLL->getFAStarIFace()->Initialize(&GC.getAreaFinder(), getGridWidthINLINE(), getGridHeightINLINE(), isWrapXINLINE(), isWrapYINLINE(), NULL, NULL, NULL, areaValid, NULL, joinArea, NULL);
  212. gDLL->getFAStarIFace()->Initialize(&GC.getPlotGroupFinder(), getGridWidthINLINE(), getGridHeightINLINE(), isWrapXINLINE(), isWrapYINLINE(), NULL, NULL, NULL, plotGroupValid, NULL, countPlotGroup, NULL);
  213. }
  214. //////////////////////////////////////
  215. // graphical only setup
  216. //////////////////////////////////////
  217. void CvMap::setupGraphical()
  218. {
  219. if (!GC.IsGraphicsInitialized())
  220. return;
  221. if (m_pMapPlots != NULL)
  222. {
  223. int iI;
  224. for (iI = 0; iI < numPlotsINLINE(); iI++)
  225. {
  226. gDLL->callUpdater(); // allow windows msgs to update
  227. plotByIndexINLINE(iI)->setupGraphical();
  228. }
  229. }
  230. }
  231. void CvMap::erasePlots()
  232. {
  233. int iI;
  234. for (iI = 0; iI < numPlotsINLINE(); iI++)
  235. {
  236. plotByIndexINLINE(iI)->erase();
  237. }
  238. }
  239. void CvMap::setRevealedPlots(TeamTypes eTeam, bool bNewValue, bool bTerrainOnly)
  240. {
  241. PROFILE_FUNC();
  242. int iI;
  243. for (iI = 0; iI < numPlotsINLINE(); iI++)
  244. {
  245. plotByIndexINLINE(iI)->setRevealed(eTeam, bNewValue, bTerrainOnly, NO_TEAM, false);
  246. }
  247. GC.getGameINLINE().updatePlotGroups();
  248. }
  249. void CvMap::setAllPlotTypes(PlotTypes ePlotType)
  250. {
  251. //float startTime = (float) timeGetTime();
  252. for(int i=0;i<numPlotsINLINE();i++)
  253. {
  254. plotByIndexINLINE(i)->setPlotType(ePlotType, false, false);
  255. }
  256. recalculateAreas();
  257. //rebuild landscape
  258. gDLL->getEngineIFace()->RebuildAllPlots();
  259. //mark minimap as dirty
  260. gDLL->getEngineIFace()->SetDirty(MinimapTexture_DIRTY_BIT, true);
  261. gDLL->getEngineIFace()->SetDirty(GlobeTexture_DIRTY_BIT, true);
  262. //float endTime = (float) timeGetTime();
  263. //OutputDebugString(CvString::format("[Jason] setAllPlotTypes: %f\n", endTime - startTime).c_str());
  264. }
  265. // XXX generalize these funcs? (macro?)
  266. void CvMap::doTurn()
  267. {
  268. PROFILE("CvMap::doTurn()")
  269. int iI;
  270. for (iI = 0; iI < numPlotsINLINE(); iI++)
  271. {
  272. plotByIndexINLINE(iI)->doTurn();
  273. }
  274. }
  275. void CvMap::updateFlagSymbols()
  276. {
  277. PROFILE_FUNC();
  278. CvPlot* pLoopPlot;
  279. int iI;
  280. for (iI = 0; iI < numPlotsINLINE(); iI++)
  281. {
  282. pLoopPlot = plotByIndexINLINE(iI);
  283. if (pLoopPlot->isFlagDirty())
  284. {
  285. pLoopPlot->updateFlagSymbol();
  286. pLoopPlot->setFlagDirty(false);
  287. }
  288. }
  289. }
  290. void CvMap::updateFog()
  291. {
  292. int iI;
  293. for (iI = 0; iI < numPlotsINLINE(); iI++)
  294. {
  295. plotByIndexINLINE(iI)->updateFog();
  296. }
  297. }
  298. void CvMap::updateVisibility()
  299. {
  300. int iI;
  301. for (iI = 0; iI < numPlotsINLINE(); iI++)
  302. {
  303. plotByIndexINLINE(iI)->updateVisibility();
  304. }
  305. }
  306. void CvMap::updateSymbolVisibility()
  307. {
  308. int iI;
  309. for (iI = 0; iI < numPlotsINLINE(); iI++)
  310. {
  311. plotByIndexINLINE(iI)->updateSymbolVisibility();
  312. }
  313. }
  314. void CvMap::updateSymbols()
  315. {
  316. int iI;
  317. for (iI = 0; iI < numPlotsINLINE(); iI++)
  318. {
  319. plotByIndexINLINE(iI)->updateSymbols();
  320. }
  321. }
  322. void CvMap::updateMinimapColor()
  323. {
  324. int iI;
  325. for (iI = 0; iI < numPlotsINLINE(); iI++)
  326. {
  327. plotByIndexINLINE(iI)->updateMinimapColor();
  328. }
  329. }
  330. void CvMap::updateSight(bool bIncrement)
  331. {
  332. for (int iI = 0; iI < numPlotsINLINE(); iI++)
  333. {
  334. plotByIndexINLINE(iI)->updateSight(bIncrement, false);
  335. }
  336. GC.getGameINLINE().updatePlotGroups();
  337. }
  338. void CvMap::updateIrrigated()
  339. {
  340. int iI;
  341. for (iI = 0; iI < numPlotsINLINE(); iI++)
  342. {
  343. plotByIndexINLINE(iI)->updateIrrigated();
  344. }
  345. }
  346. void CvMap::updateCenterUnit()
  347. {
  348. int iI;
  349. for (iI = 0; iI < numPlotsINLINE(); iI++)
  350. {
  351. plotByIndexINLINE(iI)->updateCenterUnit();
  352. }
  353. }
  354. void CvMap::updateWorkingCity()
  355. {
  356. int iI;
  357. for (iI = 0; iI < numPlotsINLINE(); iI++)
  358. {
  359. plotByIndexINLINE(iI)->updateWorkingCity();
  360. }
  361. }
  362. void CvMap::updateMinOriginalStartDist(CvArea* pArea)
  363. {
  364. PROFILE_FUNC();
  365. CvPlot* pStartingPlot;
  366. CvPlot* pLoopPlot;
  367. int iDist;
  368. int iI, iJ;
  369. for (iI = 0; iI < numPlotsINLINE(); iI++)
  370. {
  371. pLoopPlot = plotByIndexINLINE(iI);
  372. if (pLoopPlot->area() == pArea)
  373. {
  374. pLoopPlot->setMinOriginalStartDist(-1);
  375. }
  376. }
  377. for (iI = 0; iI < MAX_CIV_PLAYERS; iI++)
  378. {
  379. pStartingPlot = GET_PLAYER((PlayerTypes)iI).getStartingPlot();
  380. if (pStartingPlot != NULL)
  381. {
  382. if (pStartingPlot->area() == pArea)
  383. {
  384. for (iJ = 0; iJ < numPlotsINLINE(); iJ++)
  385. {
  386. pLoopPlot = plotByIndexINLINE(iJ);
  387. if (pLoopPlot->area() == pArea)
  388. {
  389. //iDist = GC.getMapINLINE().calculatePathDistance(pStartingPlot, pLoopPlot);
  390. iDist = stepDistance(pStartingPlot->getX_INLINE(), pStartingPlot->getY_INLINE(), pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE());
  391. if (iDist != -1)
  392. {
  393. //int iCrowDistance = plotDistance(pStartingPlot->getX_INLINE(), pStartingPlot->getY_INLINE(), pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE());
  394. //iDist = std::min(iDist, iCrowDistance * 2);
  395. if ((pLoopPlot->getMinOriginalStartDist() == -1) || (iDist < pLoopPlot->getMinOriginalStartDist()))
  396. {
  397. pLoopPlot->setMinOriginalStartDist(iDist);
  398. }
  399. }
  400. }
  401. }
  402. }
  403. }
  404. }
  405. }
  406. void CvMap::updateYield()
  407. {
  408. int iI;
  409. for (iI = 0; iI < numPlotsINLINE(); iI++)
  410. {
  411. plotByIndexINLINE(iI)->updateYield();
  412. }
  413. }
  414. void CvMap::verifyUnitValidPlot()
  415. {
  416. for (int iI = 0; iI < numPlotsINLINE(); iI++)
  417. {
  418. plotByIndexINLINE(iI)->verifyUnitValidPlot();
  419. }
  420. }
  421. void CvMap::combinePlotGroups(PlayerTypes ePlayer, CvPlotGroup* pPlotGroup1, CvPlotGroup* pPlotGroup2)
  422. {
  423. CLLNode<XYCoords>* pPlotNode;
  424. CvPlotGroup* pNewPlotGroup;
  425. CvPlotGroup* pOldPlotGroup;
  426. CvPlot* pPlot;
  427. FAssertMsg(pPlotGroup1 != NULL, "pPlotGroup is not assigned to a valid value");
  428. FAssertMsg(pPlotGroup2 != NULL, "pPlotGroup is not assigned to a valid value");
  429. if (pPlotGroup1 == pPlotGroup2)
  430. {
  431. return;
  432. }
  433. if (pPlotGroup1->getLengthPlots() > pPlotGroup2->getLengthPlots())
  434. {
  435. pNewPlotGroup = pPlotGroup1;
  436. pOldPlotGroup = pPlotGroup2;
  437. }
  438. else
  439. {
  440. pNewPlotGroup = pPlotGroup2;
  441. pOldPlotGroup = pPlotGroup1;
  442. }
  443. pPlotNode = pOldPlotGroup->headPlotsNode();
  444. while (pPlotNode != NULL)
  445. {
  446. pPlot = plotSorenINLINE(pPlotNode->m_data.iX, pPlotNode->m_data.iY);
  447. pNewPlotGroup->addPlot(pPlot);
  448. pPlotNode = pOldPlotGroup->deletePlotsNode(pPlotNode);
  449. }
  450. }
  451. CvPlot* CvMap::syncRandPlot(int iFlags, int iArea, int iMinUnitDistance, int iTimeout)
  452. {
  453. CvPlot* pPlot;
  454. CvPlot* pTestPlot;
  455. CvPlot* pLoopPlot;
  456. bool bValid;
  457. int iCount;
  458. int iDX, iDY;
  459. pPlot = NULL;
  460. iCount = 0;
  461. while (iCount < iTimeout)
  462. {
  463. pTestPlot = plotSorenINLINE(GC.getGameINLINE().getSorenRandNum(getGridWidthINLINE(), "Rand Plot Width"), GC.getGameINLINE().getSorenRandNum(getGridHeightINLINE(), "Rand Plot Height"));
  464. FAssertMsg(pTestPlot != NULL, "TestPlot is not assigned a valid value");
  465. if ((iArea == -1) || (pTestPlot->getArea() == iArea))
  466. {
  467. bValid = true;
  468. if (bValid)
  469. {
  470. if (iMinUnitDistance != -1)
  471. {
  472. for (iDX = -(iMinUnitDistance); iDX <= iMinUnitDistance; iDX++)
  473. {
  474. for (iDY = -(iMinUnitDistance); iDY <= iMinUnitDistance; iDY++)
  475. {
  476. pLoopPlot = plotXY(pTestPlot->getX_INLINE(), pTestPlot->getY_INLINE(), iDX, iDY);
  477. if (pLoopPlot != NULL)
  478. {
  479. if (pLoopPlot->isUnit())
  480. {
  481. bValid = false;
  482. }
  483. }
  484. }
  485. }
  486. }
  487. }
  488. if (bValid)
  489. {
  490. if (iFlags & RANDPLOT_LAND)
  491. {
  492. if (pTestPlot->isWater())
  493. {
  494. bValid = false;
  495. }
  496. }
  497. }
  498. if (bValid)
  499. {
  500. if (iFlags & RANDPLOT_UNOWNED)
  501. {
  502. if (pTestPlot->isOwned())
  503. {
  504. bValid = false;
  505. }
  506. }
  507. }
  508. if (bValid)
  509. {
  510. if (iFlags & RANDPLOT_ADJACENT_UNOWNED)
  511. {
  512. if (pTestPlot->isAdjacentOwned())
  513. {
  514. bValid = false;
  515. }
  516. }
  517. }
  518. if (bValid)
  519. {
  520. if (iFlags & RANDPLOT_ADJACENT_LAND)
  521. {
  522. if (!(pTestPlot->isAdjacentToLand()))
  523. {
  524. bValid = false;
  525. }
  526. }
  527. }
  528. if (bValid)
  529. {
  530. if (iFlags & RANDPLOT_PASSIBLE)
  531. {
  532. if (pTestPlot->isImpassable())
  533. {
  534. bValid = false;
  535. }
  536. }
  537. }
  538. if (bValid)
  539. {
  540. if (iFlags & RANDPLOT_NOT_VISIBLE_TO_CIV)
  541. {
  542. if (pTestPlot->isVisibleToCivTeam())
  543. {
  544. bValid = false;
  545. }
  546. }
  547. }
  548. if (bValid)
  549. {
  550. if (iFlags & RANDPLOT_NOT_CITY)
  551. {
  552. if (pTestPlot->isCity())
  553. {
  554. bValid = false;
  555. }
  556. }
  557. }
  558. if (bValid)
  559. {
  560. pPlot = pTestPlot;
  561. break;
  562. }
  563. }
  564. iCount++;
  565. }
  566. return pPlot;
  567. }
  568. CvCity* CvMap::findCity(int iX, int iY, PlayerTypes eOwner, TeamTypes eTeam, bool bSameArea, bool bCoastalOnly, TeamTypes eTeamAtWarWith, DirectionTypes eDirection, CvCity* pSkipCity)
  569. {
  570. PROFILE_FUNC();
  571. CvCity* pLoopCity;
  572. CvCity* pBestCity;
  573. int iValue;
  574. int iBestValue;
  575. int iLoop;
  576. int iI;
  577. // XXX look for barbarian cities???
  578. iBestValue = MAX_INT;
  579. pBestCity = NULL;
  580. for (iI = 0; iI < MAX_PLAYERS; iI++)
  581. {
  582. if (GET_PLAYER((PlayerTypes)iI).isAlive())
  583. {
  584. if ((eOwner == NO_PLAYER) || (iI == eOwner))
  585. {
  586. if ((eTeam == NO_TEAM) || (GET_PLAYER((PlayerTypes)iI).getTeam() == eTeam))
  587. {
  588. for (pLoopCity = GET_PLAYER((PlayerTypes)iI).firstCity(&iLoop); pLoopCity != NULL; pLoopCity = GET_PLAYER((PlayerTypes)iI).nextCity(&iLoop))
  589. {
  590. if (!bSameArea || (pLoopCity->area() == plotINLINE(iX, iY)->area()) || (bCoastalOnly && (pLoopCity->waterArea() == plotINLINE(iX, iY)->area())))
  591. {
  592. if (!bCoastalOnly || pLoopCity->isCoastal(GC.getMIN_WATER_SIZE_FOR_OCEAN()))
  593. {
  594. if ((eTeamAtWarWith == NO_TEAM) || atWar(GET_PLAYER((PlayerTypes)iI).getTeam(), eTeamAtWarWith))
  595. {
  596. if ((eDirection == NO_DIRECTION) || (estimateDirection(dxWrap(pLoopCity->getX_INLINE() - iX), dyWrap(pLoopCity->getY_INLINE() - iY)) == eDirection))
  597. {
  598. if ((pSkipCity == NULL) || (pLoopCity != pSkipCity))
  599. {
  600. iValue = plotDistance(iX, iY, pLoopCity->getX_INLINE(), pLoopCity->getY_INLINE());
  601. if (iValue < iBestValue)
  602. {
  603. iBestValue = iValue;
  604. pBestCity = pLoopCity;
  605. }
  606. }
  607. }
  608. }
  609. }
  610. }
  611. }
  612. }
  613. }
  614. }
  615. }
  616. return pBestCity;
  617. }
  618. CvSelectionGroup* CvMap::findSelectionGroup(int iX, int iY, PlayerTypes eOwner, bool bReadyToSelect, bool bWorkers)
  619. {
  620. CvSelectionGroup* pLoopSelectionGroup;
  621. CvSelectionGroup* pBestSelectionGroup;
  622. int iValue;
  623. int iBestValue;
  624. int iLoop;
  625. int iI;
  626. // XXX look for barbarian cities???
  627. iBestValue = MAX_INT;
  628. pBestSelectionGroup = NULL;
  629. for (iI = 0; iI < MAX_PLAYERS; iI++)
  630. {
  631. if (GET_PLAYER((PlayerTypes)iI).isAlive())
  632. {
  633. if ((eOwner == NO_PLAYER) || (iI == eOwner))
  634. {
  635. for(pLoopSelectionGroup = GET_PLAYER((PlayerTypes)iI).firstSelectionGroup(&iLoop); pLoopSelectionGroup != NULL; pLoopSelectionGroup = GET_PLAYER((PlayerTypes)iI).nextSelectionGroup(&iLoop))
  636. {
  637. if (!bReadyToSelect || pLoopSelectionGroup->readyToSelect())
  638. {
  639. if (!bWorkers || pLoopSelectionGroup->hasWorker())
  640. {
  641. iValue = plotDistance(iX, iY, pLoopSelectionGroup->getX(), pLoopSelectionGroup->getY());
  642. if (iValue < iBestValue)
  643. {
  644. iBestValue = iValue;
  645. pBestSelectionGroup = pLoopSelectionGroup;
  646. }
  647. }
  648. }
  649. }
  650. }
  651. }
  652. }
  653. return pBestSelectionGroup;
  654. }
  655. CvArea* CvMap::findBiggestArea(bool bWater)
  656. {
  657. CvArea* pLoopArea;
  658. CvArea* pBestArea;
  659. int iValue;
  660. int iBestValue;
  661. int iLoop;
  662. iBestValue = 0;
  663. pBestArea = NULL;
  664. for(pLoopArea = firstArea(&iLoop); pLoopArea != NULL; pLoopArea = nextArea(&iLoop))
  665. {
  666. if (pLoopArea->isWater() == bWater)
  667. {
  668. iValue = pLoopArea->getNumTiles();
  669. if (iValue > iBestValue)
  670. {
  671. iBestValue = iValue;
  672. pBestArea = pLoopArea;
  673. }
  674. }
  675. }
  676. return pBestArea;
  677. }
  678. int CvMap::getMapFractalFlags()
  679. {
  680. int wrapX = 0;
  681. if (isWrapXINLINE())
  682. {
  683. wrapX = (int)CvFractal::FRAC_WRAP_X;
  684. }
  685. int wrapY = 0;
  686. if (isWrapYINLINE())
  687. {
  688. wrapY = (int)CvFractal::FRAC_WRAP_Y;
  689. }
  690. return (wrapX | wrapY);
  691. }
  692. //"Check plots for wetlands or seaWater. Returns true if found"
  693. bool CvMap::findWater(CvPlot* pPlot, int iRange, bool bFreshWater)
  694. {
  695. PROFILE("CvMap::findWater()");
  696. CvPlot* pLoopPlot;
  697. int iDX, iDY;
  698. for (iDX = -(iRange); iDX <= iRange; iDX++)
  699. {
  700. for (iDY = -(iRange); iDY <= iRange; iDY++)
  701. {
  702. pLoopPlot = plotXY(pPlot->getX_INLINE(), pPlot->getY_INLINE(), iDX, iDY);
  703. if (pLoopPlot != NULL)
  704. {
  705. if (bFreshWater)
  706. {
  707. if (pLoopPlot->isFreshWater())
  708. {
  709. return true;
  710. }
  711. }
  712. else
  713. {
  714. if (pLoopPlot->isWater())
  715. {
  716. return true;
  717. }
  718. }
  719. }
  720. }
  721. }
  722. return false;
  723. }
  724. bool CvMap::isPlot(int iX, int iY) const
  725. {
  726. return isPlotINLINE(iX, iY);
  727. }
  728. int CvMap::numPlots() const
  729. {
  730. return numPlotsINLINE();
  731. }
  732. int CvMap::plotNum(int iX, int iY) const
  733. {
  734. return plotNumINLINE(iX, iY);
  735. }
  736. int CvMap::plotX(int iIndex) const
  737. {
  738. return (iIndex % getGridWidthINLINE());
  739. }
  740. int CvMap::plotY(int iIndex) const
  741. {
  742. return (iIndex / getGridWidthINLINE());
  743. }
  744. int CvMap::pointXToPlotX(float fX)
  745. {
  746. float fWidth, fHeight;
  747. gDLL->getEngineIFace()->GetLandscapeGameDimensions(fWidth, fHeight);
  748. return (int)(((fX + (fWidth/2.0f)) / fWidth) * getGridWidthINLINE());
  749. }
  750. float CvMap::plotXToPointX(int iX)
  751. {
  752. float fWidth, fHeight;
  753. gDLL->getEngineIFace()->GetLandscapeGameDimensions(fWidth, fHeight);
  754. return ((iX * fWidth) / ((float)getGridWidthINLINE())) - (fWidth / 2.0f) + (GC.getPLOT_SIZE() / 2.0f);
  755. }
  756. int CvMap::pointYToPlotY(float fY)
  757. {
  758. float fWidth, fHeight;
  759. gDLL->getEngineIFace()->GetLandscapeGameDimensions(fWidth, fHeight);
  760. return (int)(((fY + (fHeight/2.0f)) / fHeight) * getGridHeightINLINE());
  761. }
  762. float CvMap::plotYToPointY(int iY)
  763. {
  764. float fWidth, fHeight;
  765. gDLL->getEngineIFace()->GetLandscapeGameDimensions(fWidth, fHeight);
  766. return ((iY * fHeight) / ((float)getGridHeightINLINE())) - (fHeight / 2.0f) + (GC.getPLOT_SIZE() / 2.0f);
  767. }
  768. float CvMap::getWidthCoords()
  769. {
  770. return (GC.getPLOT_SIZE() * ((float)getGridWidthINLINE()));
  771. }
  772. float CvMap::getHeightCoords()
  773. {
  774. return (GC.getPLOT_SIZE() * ((float)getGridHeightINLINE()));
  775. }
  776. int CvMap::maxPlotDistance()
  777. {
  778. return std::max(1, plotDistance(0, 0, ((isWrapXINLINE()) ? (getGridWidthINLINE() / 2) : (getGridWidthINLINE() - 1)), ((isWrapYINLINE()) ? (getGridHeightINLINE() / 2) : (getGridHeightINLINE() - 1))));
  779. }
  780. int CvMap::maxStepDistance()
  781. {
  782. return std::max(1, stepDistance(0, 0, ((isWrapXINLINE()) ? (getGridWidthINLINE() / 2) : (getGridWidthINLINE() - 1)), ((isWrapYINLINE()) ? (getGridHeightINLINE() / 2) : (getGridHeightINLINE() - 1))));
  783. }
  784. int CvMap::getGridWidth() const
  785. {
  786. return getGridWidthINLINE();
  787. }
  788. int CvMap::getGridHeight() const
  789. {
  790. return getGridHeightINLINE();
  791. }
  792. int CvMap::getLandPlots()
  793. {
  794. return m_iLandPlots;
  795. }
  796. void CvMap::changeLandPlots(int iChange)
  797. {
  798. m_iLandPlots = (m_iLandPlots + iChange);
  799. FAssert(getLandPlots() >= 0);
  800. }
  801. int CvMap::getOwnedPlots()
  802. {
  803. return m_iOwnedPlots;
  804. }
  805. void CvMap::changeOwnedPlots(int iChange)
  806. {
  807. m_iOwnedPlots = (m_iOwnedPlots + iChange);
  808. FAssert(getOwnedPlots() >= 0);
  809. }
  810. int CvMap::getTopLatitude()
  811. {
  812. return m_iTopLatitude;
  813. }
  814. int CvMap::getBottomLatitude()
  815. {
  816. return m_iBottomLatitude;
  817. }
  818. int CvMap::getNextRiverID()
  819. {
  820. return m_iNextRiverID;
  821. }
  822. void CvMap::incrementNextRiverID()
  823. {
  824. m_iNextRiverID++;
  825. }
  826. bool CvMap::isWrapX()
  827. {
  828. return isWrapXINLINE();
  829. }
  830. bool CvMap::isWrapY()
  831. {
  832. return isWrapYINLINE();
  833. }
  834. bool CvMap::isWrap()
  835. {
  836. return isWrapINLINE();
  837. }
  838. WorldSizeTypes CvMap::getWorldSize()
  839. {
  840. return GC.getInitCore().getWorldSize();
  841. }
  842. ClimateTypes CvMap::getClimate()
  843. {
  844. return GC.getInitCore().getClimate();
  845. }
  846. SeaLevelTypes CvMap::getSeaLevel()
  847. {
  848. return GC.getInitCore().getSeaLevel();
  849. }
  850. int CvMap::getNumCustomMapOptions()
  851. {
  852. return GC.getInitCore().getNumCustomMapOptions();
  853. }
  854. CustomMapOptionTypes CvMap::getCustomMapOption(int iOption)
  855. {
  856. return GC.getInitCore().getCustomMapOption(iOption);
  857. }
  858. int CvMap::getNumBonuses(BonusTypes eIndex)
  859. {
  860. FAssertMsg(eIndex >= 0, "eIndex is expected to be non-negative (invalid Index)");
  861. FAssertMsg(eIndex < GC.getNumBonusInfos(), "eIndex is expected to be within maximum bounds (invalid Index)");
  862. return m_paiNumBonus[eIndex];
  863. }
  864. void CvMap::changeNumBonuses(BonusTypes eIndex, int iChange)
  865. {
  866. FAssertMsg(eIndex >= 0, "eIndex is expected to be non-negative (invalid Index)");
  867. FAssertMsg(eIndex < GC.getNumBonusInfos(), "eIndex is expected to be within maximum bounds (invalid Index)");
  868. m_paiNumBonus[eIndex] = (m_paiNumBonus[eIndex] + iChange);
  869. FAssert(getNumBonuses(eIndex) >= 0);
  870. }
  871. int CvMap::getNumBonusesOnLand(BonusTypes eIndex)
  872. {
  873. FAssertMsg(eIndex >= 0, "eIndex is expected to be non-negative (invalid Index)");
  874. FAssertMsg(eIndex < GC.getNumBonusInfos(), "eIndex is expected to be within maximum bounds (invalid Index)");
  875. return m_paiNumBonusOnLand[eIndex];
  876. }
  877. void CvMap::changeNumBonusesOnLand(BonusTypes eIndex, int iChange)
  878. {
  879. FAssertMsg(eIndex >= 0, "eIndex is expected to be non-negative (invalid Index)");
  880. FAssertMsg(eIndex < GC.getNumBonusInfos(), "eIndex is expected to be within maximum bounds (invalid Index)");
  881. m_paiNumBonusOnLand[eIndex] = (m_paiNumBonusOnLand[eIndex] + iChange);
  882. FAssert(getNumBonusesOnLand(eIndex) >= 0);
  883. }
  884. CvPlot* CvMap::plotByIndex(int iIndex) const
  885. {
  886. return plotByIndexINLINE(iIndex);
  887. }
  888. CvPlot* CvMap::plot(int iX, int iY) const
  889. {
  890. return plotINLINE(iX, iY);
  891. }
  892. CvPlot* CvMap::pointToPlot(float fX, float fY)
  893. {
  894. return plotINLINE(pointXToPlotX(fX), pointYToPlotY(fY));
  895. }
  896. int CvMap::getIndexAfterLastArea()
  897. {
  898. return m_areas.getIndexAfterLast();
  899. }
  900. int CvMap::getNumAreas()
  901. {
  902. return m_areas.getCount();
  903. }
  904. int CvMap::getNumLandAreas()
  905. {
  906. CvArea* pLoopArea;
  907. int iNumLandAreas;
  908. int iLoop;
  909. iNumLandAreas = 0;
  910. for(pLoopArea = GC.getMap().firstArea(&iLoop); pLoopArea != NULL; pLoopArea = GC.getMap().nextArea(&iLoop))
  911. {
  912. if (!(pLoopArea->isWater()))
  913. {
  914. iNumLandAreas++;
  915. }
  916. }
  917. return iNumLandAreas;
  918. }
  919. CvArea* CvMap::getArea(int iID)
  920. {
  921. return m_areas.getAt(iID);
  922. }
  923. CvArea* CvMap::addArea()
  924. {
  925. return m_areas.add();
  926. }
  927. void CvMap::deleteArea(int iID)
  928. {
  929. m_areas.removeAt(iID);
  930. }
  931. CvArea* CvMap::firstArea(int *pIterIdx, bool bRev)
  932. {
  933. return !bRev ? m_areas.beginIter(pIterIdx) : m_areas.endIter(pIterIdx);
  934. }
  935. CvArea* CvMap::nextArea(int *pIterIdx, bool bRev)
  936. {
  937. return !bRev ? m_areas.nextIter(pIterIdx) : m_areas.prevIter(pIterIdx);
  938. }
  939. void CvMap::recalculateAreas()
  940. {
  941. PROFILE("CvMap::recalculateAreas");
  942. int iI;
  943. for (iI = 0; iI < numPlotsINLINE(); iI++)
  944. {
  945. plotByIndexINLINE(iI)->setArea(FFreeList::INVALID_INDEX);
  946. }
  947. m_areas.removeAll();
  948. calculateAreas();
  949. }
  950. void CvMap::resetPathDistance()
  951. {
  952. gDLL->getFAStarIFace()->ForceReset(&GC.getStepFinder());
  953. }
  954. // Super Forts begin *canal* *choke*
  955. int CvMap::calculatePathDistance(CvPlot *pSource, CvPlot *pDest, CvPlot *pInvalidPlot)
  956. // Super Forts end
  957. {
  958. FAStarNode* pNode;
  959. if (pSource == NULL || pDest == NULL)
  960. {
  961. return -1;
  962. }
  963. // Super Forts begin *canal* *choke*
  964. // 1 must be added because 0 is already being used as the default value for iInfo in GeneratePath()
  965. int iInvalidPlot = (pInvalidPlot == NULL) ? 0 : GC.getMapINLINE().plotNum(pInvalidPlot->getX_INLINE(), pInvalidPlot->getY_INLINE()) + 1;
  966. if (gDLL->getFAStarIFace()->GeneratePath(&GC.getStepFinder(), pSource->getX_INLINE(), pSource->getY_INLINE(), pDest->getX_INLINE(), pDest->getY_INLINE(), false, iInvalidPlot, true))
  967. // Super Forts end
  968. {
  969. pNode = gDLL->getFAStarIFace()->GetLastNode(&GC.getStepFinder());
  970. if (pNode != NULL)
  971. {
  972. return pNode->m_iData1;
  973. }
  974. }
  975. return -1; // no passable path exists
  976. }
  977. // Super Forts begin *canal* *choke*
  978. void CvMap::calculateCanalAndChokePoints()
  979. {
  980. int iI;
  981. for(iI = 0; iI < numPlotsINLINE(); iI++)
  982. {
  983. plotByIndexINLINE(iI)->calculateCanalValue();
  984. plotByIndexINLINE(iI)->calculateChokeValue();
  985. // TEMPORARY HARD CODE for testing purposes
  986. /*if((plotByIndexINLINE(iI)->getChokeValue() > 0) || (plotByIndexINLINE(iI)->getCanalValue() > 0))
  987. {
  988. ImprovementTypes eImprovement = (ImprovementTypes) (plotByIndexINLINE(iI)->isWater() ? GC.getInfoTypeForString("IMPROVEMENT_WHALING_BOATS") : GC.getInfoTypeForString("IMPROVEMENT_FORT"));
  989. plotByIndexINLINE(iI)->setImprovementType(eImprovement);
  990. }
  991. else
  992. {
  993. plotByIndexINLINE(iI)->setImprovementType(NO_IMPROVEMENT);
  994. }*/
  995. }
  996. }
  997. // Super Forts end
  998. /************************************************************************************************/
  999. /* BETTER_BTS_AI_MOD 08/21/09 jdog5000 */
  1000. /* */
  1001. /* Efficiency */
  1002. /************************************************************************************************/
  1003. // Plot danger cache
  1004. void CvMap::invalidateIsActivePlayerNoDangerCache()
  1005. {
  1006. PROFILE_FUNC();
  1007. int iI;
  1008. CvPlot* pLoopPlot;
  1009. for( iI = 0; iI < numPlotsINLINE(); iI++ )
  1010. {
  1011. pLoopPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
  1012. if( pLoopPlot != NULL )
  1013. {
  1014. pLoopPlot->setIsActivePlayerNoDangerCache(false);
  1015. }
  1016. }
  1017. }
  1018. void CvMap::invalidateIsTeamBorderCache(TeamTypes eTeam)
  1019. {
  1020. PROFILE_FUNC();
  1021. int iI;
  1022. CvPlot* pLoopPlot;
  1023. for( iI = 0; iI < numPlotsINLINE(); iI++ )
  1024. {
  1025. pLoopPlot = GC.getMapINLINE().plotByIndexINLINE(iI);
  1026. if( pLoopPlot != NULL )
  1027. {
  1028. pLoopPlot->setIsTeamBorderCache(eTeam, false);
  1029. }
  1030. }
  1031. }
  1032. /************************************************************************************************/
  1033. /* BETTER_BTS_AI_MOD END */
  1034. /************************************************************************************************/
  1035. //
  1036. // read object from a stream
  1037. // used during load
  1038. //
  1039. void CvMap::read(FDataStreamBase* pStream)
  1040. {
  1041. CvMapInitData defaultMapData;
  1042. // Init data before load
  1043. reset(&defaultMapData);
  1044. uint uiFlag=0;
  1045. pStream->Read(&uiFlag); // flags for expansion
  1046. pStream->Read(&m_iGridWidth);
  1047. pStream->Read(&m_iGridHeight);
  1048. pStream->Read(&m_iLandPlots);
  1049. pStream->Read(&m_iOwnedPlots);
  1050. pStream->Read(&m_iTopLatitude);
  1051. pStream->Read(&m_iBottomLatitude);
  1052. pStream->Read(&m_iNextRiverID);
  1053. pStream->Read(&m_bWrapX);
  1054. pStream->Read(&m_bWrapY);
  1055. FAssertMsg((0 < GC.getNumBonusInfos()), "GC.getNumBonusInfos() is not greater than zero but an array is being allocated");
  1056. pStream->Read(GC.getNumBonusInfos(), m_paiNumBonus);
  1057. pStream->Read(GC.getNumBonusInfos(), m_paiNumBonusOnLand);
  1058. if (numPlotsINLINE() > 0)
  1059. {
  1060. m_pMapPlots = new CvPlot[numPlotsINLINE()];
  1061. int iI;
  1062. for (iI = 0; iI < numPlotsINLINE(); iI++)
  1063. {
  1064. m_pMapPlots[iI].read(pStream);
  1065. }
  1066. }
  1067. // call the read of the free list CvArea class allocations
  1068. ReadStreamableFFreeListTrashArray(m_areas, pStream);
  1069. setup();
  1070. }
  1071. // save object to a stream
  1072. // used during save
  1073. //
  1074. void CvMap::write(FDataStreamBase* pStream)
  1075. {
  1076. uint uiFlag=0;
  1077. pStream->Write(uiFlag); // flag for expansion
  1078. pStream->Write(m_iGridWidth);
  1079. pStream->Write(m_iGridHeight);
  1080. pStream->Write(m_iLandPlots);
  1081. pStream->Write(m_iOwnedPlots);
  1082. pStream->Write(m_iTopLatitude);
  1083. pStream->Write(m_iBottomLatitude);
  1084. pStream->Write(m_iNextRiverID);
  1085. pStream->Write(m_bWrapX);
  1086. pStream->Write(m_bWrapY);
  1087. FAssertMsg((0 < GC.getNumBonusInfos()), "GC.getNumBonusInfos() is not greater than zero but an array is being allocated");
  1088. pStream->Write(GC.getNumBonusInfos(), m_paiNumBonus);
  1089. pStream->Write(GC.getNumBonusInfos(), m_paiNumBonusOnLand);
  1090. int iI;
  1091. for (iI = 0; iI < numPlotsINLINE(); iI++)
  1092. {
  1093. m_pMapPlots[iI].write(pStream);
  1094. }
  1095. // call the read of the free list CvArea class allocations
  1096. WriteStreamableFFreeListTrashArray(m_areas, pStream);
  1097. }
  1098. //
  1099. // used for loading WB maps
  1100. //
  1101. void CvMap::rebuild(int iGridW, int iGridH, int iTopLatitude, int iBottomLatitude, bool bWrapX, bool bWrapY, WorldSizeTypes eWorldSize, ClimateTypes eClimate, SeaLevelTypes eSeaLevel, int iNumCustomMapOptions, CustomMapOptionTypes * aeCustomMapOptions)
  1102. {
  1103. CvMapInitData initData(iGridW, iGridH, iTopLatitude, iBottomLatitude, bWrapX, bWrapY);
  1104. // Set init core data
  1105. GC.getInitCore().setWorldSize(eWorldSize);
  1106. GC.getInitCore().setClimate(eClimate);
  1107. GC.getInitCore().setSeaLevel(eSeaLevel);
  1108. GC.getInitCore().setCustomMapOptions(iNumCustomMapOptions, aeCustomMapOptions);
  1109. // Init map
  1110. init(&initData);
  1111. }
  1112. //////////////////////////////////////////////////////////////////////////
  1113. // Protected Functions...
  1114. //////////////////////////////////////////////////////////////////////////
  1115. void CvMap::calculateAreas()
  1116. {
  1117. PROFILE("CvMap::calculateAreas");
  1118. CvPlot* pLoopPlot;
  1119. CvArea* pArea;
  1120. int iArea;
  1121. int iI;
  1122. for (iI = 0; iI < numPlotsINLINE(); iI++)
  1123. {
  1124. pLoopPlot = plotByIndexINLINE(iI);
  1125. gDLL->callUpdater();
  1126. FAssertMsg(pLoopPlot != NULL, "LoopPlot is not assigned a valid value");
  1127. if (pLoopPlot->getArea() == FFreeList::INVALID_INDEX)
  1128. {
  1129. pArea = addArea();
  1130. pArea->init(pArea->getID(), pLoopPlot->isWater());
  1131. iArea = pArea->getID();
  1132. pLoopPlot->setArea(iArea);
  1133. gDLL->getFAStarIFace()->GeneratePath(&GC.getAreaFinder(), pLoopPlot->getX_INLINE(), pLoopPlot->getY_INLINE(), -1, -1, pLoopPlot->isWater(), iArea);
  1134. }
  1135. }
  1136. }
  1137. // Private Functions...