Map Edgepoints.c 65 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897
  1. #ifdef PRECOMPILEDHEADERS
  2. #include "TileEngine All.h"
  3. #else
  4. #include <memory.h>
  5. #include "Map Edgepoints.h"
  6. #include "Soldier Control.h"
  7. #include "pathai.h"
  8. #include "ai.h"
  9. #include "Map Information.h"
  10. #include "renderworld.h"
  11. #include "Isometric Utils.h"
  12. #include "debug.h"
  13. #include "Random.h"
  14. #include "strategic.h"
  15. #include "Animation Control.h"
  16. #include "Render Fun.h"
  17. #include "strategicmap.h"
  18. #endif
  19. //dynamic arrays that contain the valid gridno's for each edge
  20. INT16 *gps1stNorthEdgepointArray = NULL;
  21. INT16 *gps1stEastEdgepointArray = NULL;
  22. INT16 *gps1stSouthEdgepointArray = NULL;
  23. INT16 *gps1stWestEdgepointArray = NULL;
  24. //contains the size for each array
  25. UINT16 gus1stNorthEdgepointArraySize = 0;
  26. UINT16 gus1stEastEdgepointArraySize = 0;
  27. UINT16 gus1stSouthEdgepointArraySize = 0;
  28. UINT16 gus1stWestEdgepointArraySize = 0;
  29. //contains the index value for the first array index of the second row of each edgepoint array.
  30. //Because each edgepoint side has two rows, the outside most row is calculated first, then the inside row.
  31. //For purposes of AI, it may become necessary to avoid this.
  32. UINT16 gus1stNorthEdgepointMiddleIndex = 0;
  33. UINT16 gus1stEastEdgepointMiddleIndex = 0;
  34. UINT16 gus1stSouthEdgepointMiddleIndex = 0;
  35. UINT16 gus1stWestEdgepointMiddleIndex = 0;
  36. //dynamic arrays that contain the valid gridno's for each edge
  37. INT16 *gps2ndNorthEdgepointArray = NULL;
  38. INT16 *gps2ndEastEdgepointArray = NULL;
  39. INT16 *gps2ndSouthEdgepointArray = NULL;
  40. INT16 *gps2ndWestEdgepointArray = NULL;
  41. //contains the size for each array
  42. UINT16 gus2ndNorthEdgepointArraySize = 0;
  43. UINT16 gus2ndEastEdgepointArraySize = 0;
  44. UINT16 gus2ndSouthEdgepointArraySize = 0;
  45. UINT16 gus2ndWestEdgepointArraySize = 0;
  46. //contains the index value for the first array index of the second row of each edgepoint array.
  47. //Because each edgepoint side has two rows, the outside most row is calculated first, then the inside row.
  48. //For purposes of AI, it may become necessary to avoid this.
  49. UINT16 gus2ndNorthEdgepointMiddleIndex = 0;
  50. UINT16 gus2ndEastEdgepointMiddleIndex = 0;
  51. UINT16 gus2ndSouthEdgepointMiddleIndex = 0;
  52. UINT16 gus2ndWestEdgepointMiddleIndex = 0;
  53. BOOLEAN gfEdgepointsExist = FALSE;
  54. BOOLEAN gfGeneratingMapEdgepoints = FALSE;
  55. INT16 gsTLGridNo = 13286;
  56. INT16 gsTRGridNo = 1043;
  57. INT16 gsBLGridNo = 24878;
  58. INT16 gsBRGridNo = 12635;
  59. BOOLEAN VerifyEdgepoint( SOLDIERTYPE *pSoldier, INT16 sEdgepoint );
  60. BOOLEAN EdgepointsClose( SOLDIERTYPE *pSoldier, INT16 sEdgepoint1, INT16 sEdgepoint2 );
  61. extern UINT8 gubTacticalDirection;
  62. void TrashMapEdgepoints()
  63. {
  64. //Primary edgepoints
  65. if( gps1stNorthEdgepointArray )
  66. MemFree( gps1stNorthEdgepointArray );
  67. if( gps1stEastEdgepointArray )
  68. MemFree( gps1stEastEdgepointArray );
  69. if( gps1stSouthEdgepointArray )
  70. MemFree( gps1stSouthEdgepointArray );
  71. if( gps1stWestEdgepointArray )
  72. MemFree( gps1stWestEdgepointArray );
  73. gps1stNorthEdgepointArray = NULL;
  74. gps1stEastEdgepointArray = NULL;
  75. gps1stSouthEdgepointArray = NULL;
  76. gps1stWestEdgepointArray = NULL;
  77. gus1stNorthEdgepointArraySize = 0;
  78. gus1stEastEdgepointArraySize = 0;
  79. gus1stSouthEdgepointArraySize = 0;
  80. gus1stWestEdgepointArraySize = 0;
  81. gus1stNorthEdgepointMiddleIndex = 0;
  82. gus1stEastEdgepointMiddleIndex = 0;
  83. gus1stSouthEdgepointMiddleIndex = 0;
  84. gus1stWestEdgepointMiddleIndex = 0;
  85. //Secondary edgepoints
  86. if( gps2ndNorthEdgepointArray )
  87. MemFree( gps2ndNorthEdgepointArray );
  88. if( gps2ndEastEdgepointArray )
  89. MemFree( gps2ndEastEdgepointArray );
  90. if( gps2ndSouthEdgepointArray )
  91. MemFree( gps2ndSouthEdgepointArray );
  92. if( gps2ndWestEdgepointArray )
  93. MemFree( gps2ndWestEdgepointArray );
  94. gps2ndNorthEdgepointArray = NULL;
  95. gps2ndEastEdgepointArray = NULL;
  96. gps2ndSouthEdgepointArray = NULL;
  97. gps2ndWestEdgepointArray = NULL;
  98. gus2ndNorthEdgepointArraySize = 0;
  99. gus2ndEastEdgepointArraySize = 0;
  100. gus2ndSouthEdgepointArraySize = 0;
  101. gus2ndWestEdgepointArraySize = 0;
  102. gus2ndNorthEdgepointMiddleIndex = 0;
  103. gus2ndEastEdgepointMiddleIndex = 0;
  104. gus2ndSouthEdgepointMiddleIndex = 0;
  105. gus2ndWestEdgepointMiddleIndex = 0;
  106. }
  107. //This final step eliminates some edgepoints which actually don't path directly to the edge of the map.
  108. //Cases would include an area that is close to the edge, but a fence blocks it from direct access to the edge
  109. //of the map.
  110. void ValidateEdgepoints()
  111. {
  112. INT32 i;
  113. UINT16 usValidEdgepoints;
  114. SOLDIERTYPE Soldier;
  115. memset( &Soldier, 0, sizeof( SOLDIERTYPE ) );
  116. Soldier.bTeam = 1;
  117. //north
  118. usValidEdgepoints = 0;
  119. for( i = 0; i < gus1stNorthEdgepointArraySize; i++ )
  120. {
  121. if( VerifyEdgepoint( &Soldier, gps1stNorthEdgepointArray[ i ] ) )
  122. {
  123. gps1stNorthEdgepointArray[ usValidEdgepoints ] = gps1stNorthEdgepointArray[ i ];
  124. if( i == gus1stNorthEdgepointMiddleIndex )
  125. { //adjust the middle index to the new one.
  126. gus1stNorthEdgepointMiddleIndex = usValidEdgepoints;
  127. }
  128. usValidEdgepoints++;
  129. }
  130. else if( i == gus1stNorthEdgepointMiddleIndex )
  131. { //increment the middle index because it's edgepoint is no longer valid.
  132. gus1stNorthEdgepointMiddleIndex++;
  133. }
  134. }
  135. gus1stNorthEdgepointArraySize = usValidEdgepoints;
  136. //East
  137. usValidEdgepoints = 0;
  138. for( i = 0; i < gus1stEastEdgepointArraySize; i++ )
  139. {
  140. if( VerifyEdgepoint( &Soldier, gps1stEastEdgepointArray[ i ] ) )
  141. {
  142. gps1stEastEdgepointArray[ usValidEdgepoints ] = gps1stEastEdgepointArray[ i ];
  143. if( i == gus1stEastEdgepointMiddleIndex )
  144. { //adjust the middle index to the new one.
  145. gus1stEastEdgepointMiddleIndex = usValidEdgepoints;
  146. }
  147. usValidEdgepoints++;
  148. }
  149. else if( i == gus1stEastEdgepointMiddleIndex )
  150. { //increment the middle index because it's edgepoint is no longer valid.
  151. gus1stEastEdgepointMiddleIndex++;
  152. }
  153. }
  154. gus1stEastEdgepointArraySize = usValidEdgepoints;
  155. //South
  156. usValidEdgepoints = 0;
  157. for( i = 0; i < gus1stSouthEdgepointArraySize; i++ )
  158. {
  159. if( VerifyEdgepoint( &Soldier, gps1stSouthEdgepointArray[ i ] ) )
  160. {
  161. gps1stSouthEdgepointArray[ usValidEdgepoints ] = gps1stSouthEdgepointArray[ i ];
  162. if( i == gus1stSouthEdgepointMiddleIndex )
  163. { //adjust the middle index to the new one.
  164. gus1stSouthEdgepointMiddleIndex = usValidEdgepoints;
  165. }
  166. usValidEdgepoints++;
  167. }
  168. else if( i == gus1stSouthEdgepointMiddleIndex )
  169. { //increment the middle index because it's edgepoint is no longer valid.
  170. gus1stSouthEdgepointMiddleIndex++;
  171. }
  172. }
  173. gus1stSouthEdgepointArraySize = usValidEdgepoints;
  174. //West
  175. usValidEdgepoints = 0;
  176. for( i = 0; i < gus1stWestEdgepointArraySize; i++ )
  177. {
  178. if( VerifyEdgepoint( &Soldier, gps1stWestEdgepointArray[ i ] ) )
  179. {
  180. gps1stWestEdgepointArray[ usValidEdgepoints ] = gps1stWestEdgepointArray[ i ];
  181. if( i == gus1stWestEdgepointMiddleIndex )
  182. { //adjust the middle index to the new one.
  183. gus1stWestEdgepointMiddleIndex = usValidEdgepoints;
  184. }
  185. usValidEdgepoints++;
  186. }
  187. else if( i == gus1stWestEdgepointMiddleIndex )
  188. { //increment the middle index because it's edgepoint is no longer valid.
  189. gus1stWestEdgepointMiddleIndex++;
  190. }
  191. }
  192. gus1stWestEdgepointArraySize = usValidEdgepoints;
  193. //north
  194. usValidEdgepoints = 0;
  195. for( i = 0; i < gus2ndNorthEdgepointArraySize; i++ )
  196. {
  197. if( VerifyEdgepoint( &Soldier, gps2ndNorthEdgepointArray[ i ] ) )
  198. {
  199. gps2ndNorthEdgepointArray[ usValidEdgepoints ] = gps2ndNorthEdgepointArray[ i ];
  200. if( i == gus2ndNorthEdgepointMiddleIndex )
  201. { //adjust the middle index to the new one.
  202. gus2ndNorthEdgepointMiddleIndex = usValidEdgepoints;
  203. }
  204. usValidEdgepoints++;
  205. }
  206. else if( i == gus2ndNorthEdgepointMiddleIndex )
  207. { //increment the middle index because it's edgepoint is no longer valid.
  208. gus2ndNorthEdgepointMiddleIndex++;
  209. }
  210. }
  211. gus2ndNorthEdgepointArraySize = usValidEdgepoints;
  212. //East
  213. usValidEdgepoints = 0;
  214. for( i = 0; i < gus2ndEastEdgepointArraySize; i++ )
  215. {
  216. if( VerifyEdgepoint( &Soldier, gps2ndEastEdgepointArray[ i ] ) )
  217. {
  218. gps2ndEastEdgepointArray[ usValidEdgepoints ] = gps2ndEastEdgepointArray[ i ];
  219. if( i == gus2ndEastEdgepointMiddleIndex )
  220. { //adjust the middle index to the new one.
  221. gus2ndEastEdgepointMiddleIndex = usValidEdgepoints;
  222. }
  223. usValidEdgepoints++;
  224. }
  225. else if( i == gus2ndEastEdgepointMiddleIndex )
  226. { //increment the middle index because it's edgepoint is no longer valid.
  227. gus2ndEastEdgepointMiddleIndex++;
  228. }
  229. }
  230. gus2ndEastEdgepointArraySize = usValidEdgepoints;
  231. //South
  232. usValidEdgepoints = 0;
  233. for( i = 0; i < gus2ndSouthEdgepointArraySize; i++ )
  234. {
  235. if( VerifyEdgepoint( &Soldier, gps2ndSouthEdgepointArray[ i ] ) )
  236. {
  237. gps2ndSouthEdgepointArray[ usValidEdgepoints ] = gps2ndSouthEdgepointArray[ i ];
  238. if( i == gus2ndSouthEdgepointMiddleIndex )
  239. { //adjust the middle index to the new one.
  240. gus2ndSouthEdgepointMiddleIndex = usValidEdgepoints;
  241. }
  242. usValidEdgepoints++;
  243. }
  244. else if( i == gus2ndSouthEdgepointMiddleIndex )
  245. { //increment the middle index because it's edgepoint is no longer valid.
  246. gus2ndSouthEdgepointMiddleIndex++;
  247. }
  248. }
  249. gus2ndSouthEdgepointArraySize = usValidEdgepoints;
  250. //West
  251. usValidEdgepoints = 0;
  252. for( i = 0; i < gus2ndWestEdgepointArraySize; i++ )
  253. {
  254. if( VerifyEdgepoint( &Soldier, gps2ndWestEdgepointArray[ i ] ) )
  255. {
  256. gps2ndWestEdgepointArray[ usValidEdgepoints ] = gps2ndWestEdgepointArray[ i ];
  257. if( i == gus2ndWestEdgepointMiddleIndex )
  258. { //adjust the middle index to the new one.
  259. gus2ndWestEdgepointMiddleIndex = usValidEdgepoints;
  260. }
  261. usValidEdgepoints++;
  262. }
  263. else if( i == gus2ndWestEdgepointMiddleIndex )
  264. { //increment the middle index because it's edgepoint is no longer valid.
  265. gus2ndWestEdgepointMiddleIndex++;
  266. }
  267. }
  268. gus2ndWestEdgepointArraySize = usValidEdgepoints;
  269. }
  270. void CompactEdgepointArray( INT16 **psArray, UINT16 *pusMiddleIndex, UINT16 *pusArraySize )
  271. {
  272. INT32 i;
  273. UINT16 usArraySize, usValidIndex = 0;
  274. usArraySize = *pusArraySize;
  275. for( i = 0; i < usArraySize; i++ )
  276. {
  277. if( (*psArray)[ i ] == -1 )
  278. {
  279. (*pusArraySize)--;
  280. if( i < *pusMiddleIndex )
  281. {
  282. (*pusMiddleIndex)--;
  283. }
  284. }
  285. else
  286. {
  287. if( usValidIndex != i )
  288. {
  289. (*psArray)[ usValidIndex ] = (*psArray)[ i ];
  290. }
  291. usValidIndex++;
  292. }
  293. }
  294. *psArray = (INT16*)MemRealloc( *psArray, *pusArraySize * sizeof( INT16) );
  295. Assert( *psArray );
  296. }
  297. void InternallyClassifyEdgepoints( SOLDIERTYPE *pSoldier, INT16 sGridNo,
  298. INT16 **psArray1, UINT16 *pusMiddleIndex1, UINT16 *pusArraySize1,
  299. INT16 **psArray2, UINT16 *pusMiddleIndex2, UINT16 *pusArraySize2 )
  300. {
  301. INT32 i;
  302. UINT16 us1stBenchmarkID, us2ndBenchmarkID;
  303. us1stBenchmarkID = us2ndBenchmarkID = 0xffff;
  304. if( !(*psArray2) )
  305. {
  306. *psArray2 = (INT16*)MemAlloc( sizeof( INT16 ) * 400 );
  307. }
  308. for( i = 0; i < *pusArraySize1; i++ )
  309. {
  310. if( sGridNo == (*psArray1)[ i ] )
  311. {
  312. if( i < *pusMiddleIndex1 )
  313. { //in the first half of the array
  314. us1stBenchmarkID = (UINT16)i;
  315. //find the second benchmark
  316. for( i = *pusMiddleIndex1; i < *pusArraySize1; i++ )
  317. {
  318. if( EdgepointsClose( pSoldier, (*psArray1)[ us1stBenchmarkID ], (*psArray1)[ i ] ) )
  319. {
  320. us2ndBenchmarkID = (UINT16)i;
  321. break;
  322. }
  323. }
  324. }
  325. else
  326. { //in the second half of the array
  327. us2ndBenchmarkID = (UINT16)i;
  328. //find the first benchmark
  329. for( i = 0; i < *pusMiddleIndex1; i++ )
  330. {
  331. if( EdgepointsClose( pSoldier, (*psArray1)[ us2ndBenchmarkID ], (*psArray1)[ i ] ) )
  332. {
  333. us1stBenchmarkID = (UINT16)i;
  334. break;
  335. }
  336. }
  337. }
  338. break;
  339. }
  340. }
  341. //Now we have found the two benchmarks, so go in both directions for each one to determine which entrypoints
  342. //are going to be used in the primary array. All rejections will be positioned in the secondary array for
  343. //use for isolated entry when tactically traversing.
  344. if( us1stBenchmarkID != 0xffff )
  345. {
  346. for( i = us1stBenchmarkID; i > 0; i-- )
  347. {
  348. if( !EdgepointsClose( pSoldier, (*psArray1)[ i ], (*psArray1)[ i-1 ] ) )
  349. { //All edgepoints from index 0 to i-1 are rejected.
  350. while( i )
  351. {
  352. i--;
  353. (*psArray2)[ *pusArraySize2 ] = (*psArray1)[ i ];
  354. (*pusMiddleIndex2)++;
  355. (*pusArraySize2)++;
  356. (*psArray1)[ i ] = -1;
  357. }
  358. break;
  359. }
  360. }
  361. for( i = us1stBenchmarkID; i < *pusMiddleIndex1 - 1; i++ )
  362. {
  363. if( !EdgepointsClose( pSoldier, (*psArray1)[ i ], (*psArray1)[ i+1 ] ) )
  364. { //All edgepoints from index i+1 to 1st middle index are rejected.
  365. while( i < *pusMiddleIndex1 - 1 )
  366. {
  367. i++;
  368. (*psArray2)[ *pusArraySize2 ] = (*psArray1)[ i ];
  369. (*pusMiddleIndex2)++;
  370. (*pusArraySize2)++;
  371. (*psArray1)[ i ] = -1;
  372. }
  373. break;
  374. }
  375. }
  376. }
  377. if( us2ndBenchmarkID != 0xffff )
  378. {
  379. for( i = us2ndBenchmarkID; i > *pusMiddleIndex1; i-- )
  380. {
  381. if( !EdgepointsClose( pSoldier, (*psArray1)[ i ], (*psArray1)[ i-1 ] ) )
  382. { //All edgepoints from 1st middle index to i-1 are rejected.
  383. while( i > *pusMiddleIndex1 )
  384. {
  385. i--;
  386. (*psArray2)[ *pusArraySize2 ] = (*psArray1)[ i ];
  387. (*pusArraySize2)++;
  388. (*psArray1)[ i ] = -1;
  389. }
  390. break;
  391. }
  392. }
  393. for( i = us2ndBenchmarkID; i < *pusArraySize1 - 1; i++ )
  394. {
  395. if( !EdgepointsClose( pSoldier, (*psArray1)[ i ], (*psArray1)[ i+1 ] ) )
  396. { //All edgepoints from index 0 to i-1 are rejected.
  397. while( i < *pusArraySize1 - 1 )
  398. {
  399. i++;
  400. (*psArray2)[ (*pusArraySize2) ] = (*psArray1)[ i ];
  401. (*pusArraySize2)++;
  402. (*psArray1)[ i ] = -1;
  403. }
  404. break;
  405. }
  406. }
  407. }
  408. //Now compact the primary array, because some edgepoints have been removed.
  409. CompactEdgepointArray( psArray1, pusMiddleIndex1, pusArraySize1 );
  410. (*psArray2) = (INT16*)MemRealloc( (*psArray2), *pusArraySize2 * sizeof( INT16 ) );
  411. }
  412. void ClassifyEdgepoints()
  413. {
  414. SOLDIERTYPE Soldier;
  415. INT16 sGridNo = -1;
  416. memset( &Soldier, 0, sizeof( SOLDIERTYPE ) );
  417. Soldier.bTeam = 1;
  418. //north
  419. if( gMapInformation.sNorthGridNo != -1 )
  420. {
  421. sGridNo = FindNearestEdgepointOnSpecifiedEdge( gMapInformation.sNorthGridNo, NORTH_EDGEPOINT_SEARCH );
  422. if( sGridNo != NOWHERE )
  423. {
  424. InternallyClassifyEdgepoints( &Soldier, sGridNo,
  425. &gps1stNorthEdgepointArray, &gus1stNorthEdgepointMiddleIndex, &gus1stNorthEdgepointArraySize,
  426. &gps2ndNorthEdgepointArray, &gus2ndNorthEdgepointMiddleIndex, &gus2ndNorthEdgepointArraySize );
  427. }
  428. }
  429. //east
  430. if( gMapInformation.sEastGridNo != -1 )
  431. {
  432. sGridNo = FindNearestEdgepointOnSpecifiedEdge( gMapInformation.sEastGridNo, EAST_EDGEPOINT_SEARCH );
  433. if( sGridNo != NOWHERE )
  434. {
  435. InternallyClassifyEdgepoints( &Soldier, sGridNo,
  436. &gps1stEastEdgepointArray, &gus1stEastEdgepointMiddleIndex, &gus1stEastEdgepointArraySize,
  437. &gps2ndEastEdgepointArray, &gus2ndEastEdgepointMiddleIndex, &gus2ndEastEdgepointArraySize );
  438. }
  439. }
  440. //south
  441. if( gMapInformation.sSouthGridNo != -1 )
  442. {
  443. sGridNo = FindNearestEdgepointOnSpecifiedEdge( gMapInformation.sSouthGridNo, SOUTH_EDGEPOINT_SEARCH );
  444. if( sGridNo != NOWHERE )
  445. {
  446. InternallyClassifyEdgepoints( &Soldier, sGridNo,
  447. &gps1stSouthEdgepointArray, &gus1stSouthEdgepointMiddleIndex, &gus1stSouthEdgepointArraySize,
  448. &gps2ndSouthEdgepointArray, &gus2ndSouthEdgepointMiddleIndex, &gus2ndSouthEdgepointArraySize );
  449. }
  450. }
  451. //west
  452. if( gMapInformation.sWestGridNo != -1 )
  453. {
  454. sGridNo = FindNearestEdgepointOnSpecifiedEdge( gMapInformation.sWestGridNo, WEST_EDGEPOINT_SEARCH );
  455. if( sGridNo != NOWHERE )
  456. {
  457. InternallyClassifyEdgepoints( &Soldier, sGridNo,
  458. &gps1stWestEdgepointArray, &gus1stWestEdgepointMiddleIndex, &gus1stWestEdgepointArraySize,
  459. &gps2ndWestEdgepointArray, &gus2ndWestEdgepointMiddleIndex, &gus2ndWestEdgepointArraySize );
  460. }
  461. }
  462. }
  463. void GenerateMapEdgepoints()
  464. {
  465. INT32 i=-1;
  466. INT16 sGridNo=-1;
  467. INT16 sVGridNo[400];
  468. UINT8 gubSaveNPCAPBudget=0;
  469. UINT8 gubSaveNPCDistLimit=0;
  470. //Get rid of the current edgepoint lists.
  471. TrashMapEdgepoints();
  472. gfGeneratingMapEdgepoints = TRUE;
  473. if( gMapInformation.sNorthGridNo != -1 )
  474. sGridNo = gMapInformation.sNorthGridNo;
  475. else if( gMapInformation.sEastGridNo != -1 )
  476. sGridNo = gMapInformation.sEastGridNo;
  477. else if( gMapInformation.sSouthGridNo != -1 )
  478. sGridNo = gMapInformation.sSouthGridNo;
  479. else if( gMapInformation.sWestGridNo != -1 )
  480. sGridNo = gMapInformation.sWestGridNo;
  481. else if( gMapInformation.sCenterGridNo != -1 )
  482. sGridNo = gMapInformation.sCenterGridNo;
  483. else
  484. return;
  485. GlobalReachableTest( sGridNo );
  486. //Calculate the north edges
  487. if( gMapInformation.sNorthGridNo != -1 )
  488. {
  489. //1st row
  490. sGridNo = gsTLGridNo;
  491. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  492. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  493. sVGridNo[ gus1stNorthEdgepointArraySize++ ] = sGridNo;
  494. while( sGridNo > gsTRGridNo )
  495. {
  496. sGridNo++;
  497. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  498. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  499. sVGridNo[ gus1stNorthEdgepointArraySize++ ] = sGridNo;
  500. sGridNo -= 160;
  501. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  502. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  503. sVGridNo[ gus1stNorthEdgepointArraySize++ ] = sGridNo;
  504. }
  505. //2nd row
  506. gus1stNorthEdgepointMiddleIndex = gus1stNorthEdgepointArraySize;
  507. sGridNo = gsTLGridNo + 161;
  508. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  509. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  510. sVGridNo[ gus1stNorthEdgepointArraySize++ ] = sGridNo;
  511. while( sGridNo > gsTRGridNo + 161 )
  512. {
  513. sGridNo++;
  514. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  515. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  516. sVGridNo[ gus1stNorthEdgepointArraySize++ ] = sGridNo;
  517. sGridNo -= 160;
  518. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  519. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  520. sVGridNo[ gus1stNorthEdgepointArraySize++ ] = sGridNo;
  521. }
  522. if( gus1stNorthEdgepointArraySize )
  523. {
  524. //Allocate and copy over the valid gridnos.
  525. gps1stNorthEdgepointArray = (INT16*)MemAlloc( gus1stNorthEdgepointArraySize * sizeof( INT16) );
  526. for( i = 0; i < gus1stNorthEdgepointArraySize; i++ )
  527. gps1stNorthEdgepointArray[ i ] = sVGridNo[ i ];
  528. }
  529. }
  530. //Calculate the east edges
  531. if( gMapInformation.sEastGridNo != -1 )
  532. {
  533. //1st row
  534. sGridNo = gsTRGridNo;
  535. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  536. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  537. sVGridNo[ gus1stEastEdgepointArraySize++ ] = sGridNo;
  538. while( sGridNo < gsBRGridNo )
  539. {
  540. sGridNo += 160;
  541. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  542. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  543. sVGridNo[ gus1stEastEdgepointArraySize++ ] = sGridNo;
  544. sGridNo++;
  545. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  546. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  547. sVGridNo[ gus1stEastEdgepointArraySize++ ] = sGridNo;
  548. }
  549. //2nd row
  550. gus1stEastEdgepointMiddleIndex = gus1stEastEdgepointArraySize;
  551. sGridNo = gsTRGridNo + 159;
  552. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  553. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  554. sVGridNo[ gus1stEastEdgepointArraySize++ ] = sGridNo;
  555. while( sGridNo < gsBRGridNo + 159 )
  556. {
  557. sGridNo += 160;
  558. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  559. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  560. sVGridNo[ gus1stEastEdgepointArraySize++ ] = sGridNo;
  561. sGridNo++;
  562. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  563. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  564. sVGridNo[ gus1stEastEdgepointArraySize++ ] = sGridNo;
  565. }
  566. if( gus1stEastEdgepointArraySize )
  567. { //Allocate and copy over the valid gridnos.
  568. gps1stEastEdgepointArray = (INT16*)MemAlloc( gus1stEastEdgepointArraySize * sizeof( INT16) );
  569. for( i = 0; i < gus1stEastEdgepointArraySize; i++ )
  570. gps1stEastEdgepointArray[ i ] = sVGridNo[ i ];
  571. }
  572. }
  573. //Calculate the south edges
  574. if( gMapInformation.sSouthGridNo != -1 )
  575. {
  576. //1st row
  577. sGridNo = gsBLGridNo;
  578. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  579. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  580. sVGridNo[ gus1stSouthEdgepointArraySize++ ] = sGridNo;
  581. while( sGridNo > gsBRGridNo )
  582. {
  583. sGridNo++;
  584. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  585. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  586. sVGridNo[ gus1stSouthEdgepointArraySize++ ] = sGridNo;
  587. sGridNo -= 160;
  588. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  589. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  590. sVGridNo[ gus1stSouthEdgepointArraySize++ ] = sGridNo;
  591. }
  592. //2nd row
  593. gus1stSouthEdgepointMiddleIndex = gus1stSouthEdgepointArraySize;
  594. sGridNo = gsBLGridNo - 161;
  595. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  596. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  597. sVGridNo[ gus1stSouthEdgepointArraySize++ ] = sGridNo;
  598. while( sGridNo > gsBRGridNo - 161 )
  599. {
  600. sGridNo++;
  601. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  602. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  603. sVGridNo[ gus1stSouthEdgepointArraySize++ ] = sGridNo;
  604. sGridNo -= 160;
  605. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  606. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  607. sVGridNo[ gus1stSouthEdgepointArraySize++ ] = sGridNo;
  608. }
  609. if( gus1stSouthEdgepointArraySize )
  610. { //Allocate and copy over the valid gridnos.
  611. gps1stSouthEdgepointArray = (INT16*)MemAlloc( gus1stSouthEdgepointArraySize * sizeof( INT16) );
  612. for( i = 0; i < gus1stSouthEdgepointArraySize; i++ )
  613. gps1stSouthEdgepointArray[ i ] = sVGridNo[ i ];
  614. }
  615. }
  616. //Calculate the west edges
  617. if( gMapInformation.sWestGridNo != -1 )
  618. {
  619. //1st row
  620. sGridNo = gsTLGridNo;
  621. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  622. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  623. sVGridNo[ gus1stWestEdgepointArraySize++ ] = sGridNo;
  624. while( sGridNo < gsBLGridNo )
  625. {
  626. sGridNo++;
  627. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  628. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  629. sVGridNo[ gus1stWestEdgepointArraySize++ ] = sGridNo;
  630. sGridNo += 160;
  631. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  632. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  633. sVGridNo[ gus1stWestEdgepointArraySize++ ] = sGridNo;
  634. }
  635. //2nd row
  636. gus1stWestEdgepointMiddleIndex = gus1stWestEdgepointArraySize;
  637. sGridNo = gsTLGridNo - 159;
  638. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  639. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  640. sVGridNo[ gus1stWestEdgepointArraySize++ ] = sGridNo;
  641. while( sGridNo < gsBLGridNo - 159 )
  642. {
  643. sGridNo++;
  644. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  645. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  646. sVGridNo[ gus1stWestEdgepointArraySize++ ] = sGridNo;
  647. sGridNo += 160;
  648. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  649. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  650. sVGridNo[ gus1stWestEdgepointArraySize++ ] = sGridNo;
  651. }
  652. if( gus1stWestEdgepointArraySize )
  653. { //Allocate and copy over the valid gridnos.
  654. gps1stWestEdgepointArray = (INT16*)MemAlloc( gus1stWestEdgepointArraySize * sizeof( INT16) );
  655. for( i = 0; i < gus1stWestEdgepointArraySize; i++ )
  656. gps1stWestEdgepointArray[ i ] = sVGridNo[ i ];
  657. }
  658. }
  659. //CHECK FOR ISOLATED EDGEPOINTS (but only if the entrypoint is ISOLATED!!!)
  660. if( gMapInformation.sIsolatedGridNo != -1 && !(gpWorldLevelData[ gMapInformation.sIsolatedGridNo ].uiFlags & MAPELEMENT_REACHABLE) )
  661. {
  662. GlobalReachableTest( gMapInformation.sIsolatedGridNo );
  663. if( gMapInformation.sNorthGridNo != -1 )
  664. {
  665. //1st row
  666. sGridNo = gsTLGridNo;
  667. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  668. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  669. sVGridNo[ gus2ndNorthEdgepointArraySize++ ] = sGridNo;
  670. while( sGridNo > gsTRGridNo )
  671. {
  672. sGridNo++;
  673. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  674. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  675. sVGridNo[ gus2ndNorthEdgepointArraySize++ ] = sGridNo;
  676. sGridNo -= 160;
  677. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  678. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  679. sVGridNo[ gus2ndNorthEdgepointArraySize++ ] = sGridNo;
  680. }
  681. //2nd row
  682. gus2ndNorthEdgepointMiddleIndex = gus2ndNorthEdgepointArraySize;
  683. sGridNo = gsTLGridNo + 161;
  684. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  685. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  686. sVGridNo[ gus2ndNorthEdgepointArraySize++ ] = sGridNo;
  687. while( sGridNo > gsTRGridNo + 161 )
  688. {
  689. sGridNo++;
  690. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  691. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  692. sVGridNo[ gus2ndNorthEdgepointArraySize++ ] = sGridNo;
  693. sGridNo -= 160;
  694. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  695. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  696. sVGridNo[ gus2ndNorthEdgepointArraySize++ ] = sGridNo;
  697. }
  698. if( gus2ndNorthEdgepointArraySize )
  699. {
  700. //Allocate and copy over the valid gridnos.
  701. gps2ndNorthEdgepointArray = (INT16*)MemAlloc( gus2ndNorthEdgepointArraySize * sizeof( INT16) );
  702. for( i = 0; i < gus2ndNorthEdgepointArraySize; i++ )
  703. gps2ndNorthEdgepointArray[ i ] = sVGridNo[ i ];
  704. }
  705. }
  706. //Calculate the east edges
  707. if( gMapInformation.sEastGridNo != -1 )
  708. {
  709. //1st row
  710. sGridNo = gsTRGridNo;
  711. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  712. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  713. sVGridNo[ gus2ndEastEdgepointArraySize++ ] = sGridNo;
  714. while( sGridNo < gsBRGridNo )
  715. {
  716. sGridNo += 160;
  717. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  718. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  719. sVGridNo[ gus2ndEastEdgepointArraySize++ ] = sGridNo;
  720. sGridNo++;
  721. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  722. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  723. sVGridNo[ gus2ndEastEdgepointArraySize++ ] = sGridNo;
  724. }
  725. //2nd row
  726. gus2ndEastEdgepointMiddleIndex = gus2ndEastEdgepointArraySize;
  727. sGridNo = gsTRGridNo + 159;
  728. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  729. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  730. sVGridNo[ gus2ndEastEdgepointArraySize++ ] = sGridNo;
  731. while( sGridNo < gsBRGridNo + 159 )
  732. {
  733. sGridNo += 160;
  734. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  735. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  736. sVGridNo[ gus2ndEastEdgepointArraySize++ ] = sGridNo;
  737. sGridNo++;
  738. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  739. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  740. sVGridNo[ gus2ndEastEdgepointArraySize++ ] = sGridNo;
  741. }
  742. if( gus2ndEastEdgepointArraySize )
  743. { //Allocate and copy over the valid gridnos.
  744. gps2ndEastEdgepointArray = (INT16*)MemAlloc( gus2ndEastEdgepointArraySize * sizeof( INT16) );
  745. for( i = 0; i < gus2ndEastEdgepointArraySize; i++ )
  746. gps2ndEastEdgepointArray[ i ] = sVGridNo[ i ];
  747. }
  748. }
  749. //Calculate the south edges
  750. if( gMapInformation.sSouthGridNo != -1 )
  751. {
  752. //1st row
  753. sGridNo = gsBLGridNo;
  754. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  755. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  756. sVGridNo[ gus2ndSouthEdgepointArraySize++ ] = sGridNo;
  757. while( sGridNo > gsBRGridNo )
  758. {
  759. sGridNo++;
  760. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  761. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  762. sVGridNo[ gus2ndSouthEdgepointArraySize++ ] = sGridNo;
  763. sGridNo -= 160;
  764. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  765. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  766. sVGridNo[ gus2ndSouthEdgepointArraySize++ ] = sGridNo;
  767. }
  768. //2nd row
  769. gus2ndSouthEdgepointMiddleIndex = gus2ndSouthEdgepointArraySize;
  770. sGridNo = gsBLGridNo - 161;
  771. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  772. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  773. sVGridNo[ gus2ndSouthEdgepointArraySize++ ] = sGridNo;
  774. while( sGridNo > gsBRGridNo - 161 )
  775. {
  776. sGridNo++;
  777. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  778. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  779. sVGridNo[ gus2ndSouthEdgepointArraySize++ ] = sGridNo;
  780. sGridNo -= 160;
  781. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  782. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  783. sVGridNo[ gus2ndSouthEdgepointArraySize++ ] = sGridNo;
  784. }
  785. if( gus2ndSouthEdgepointArraySize )
  786. { //Allocate and copy over the valid gridnos.
  787. gps2ndSouthEdgepointArray = (INT16*)MemAlloc( gus2ndSouthEdgepointArraySize * sizeof( INT16) );
  788. for( i = 0; i < gus2ndSouthEdgepointArraySize; i++ )
  789. gps2ndSouthEdgepointArray[ i ] = sVGridNo[ i ];
  790. }
  791. }
  792. //Calculate the west edges
  793. if( gMapInformation.sWestGridNo != -1 )
  794. {
  795. //1st row
  796. sGridNo = gsTLGridNo;
  797. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  798. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  799. sVGridNo[ gus2ndWestEdgepointArraySize++ ] = sGridNo;
  800. while( sGridNo < gsBLGridNo )
  801. {
  802. sGridNo++;
  803. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  804. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  805. sVGridNo[ gus2ndWestEdgepointArraySize++ ] = sGridNo;
  806. sGridNo += 160;
  807. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  808. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  809. sVGridNo[ gus2ndWestEdgepointArraySize++ ] = sGridNo;
  810. }
  811. //2nd row
  812. gus2ndWestEdgepointMiddleIndex = gus2ndWestEdgepointArraySize;
  813. sGridNo = gsTLGridNo - 159;
  814. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  815. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  816. sVGridNo[ gus2ndWestEdgepointArraySize++ ] = sGridNo;
  817. while( sGridNo < gsBLGridNo - 159 )
  818. {
  819. sGridNo++;
  820. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  821. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  822. sVGridNo[ gus2ndWestEdgepointArraySize++ ] = sGridNo;
  823. sGridNo += 160;
  824. if( gpWorldLevelData[ sGridNo ].uiFlags & MAPELEMENT_REACHABLE &&
  825. (!gubWorldRoomInfo[ sGridNo ] || gfBasement) )
  826. sVGridNo[ gus2ndWestEdgepointArraySize++ ] = sGridNo;
  827. }
  828. if( gus2ndWestEdgepointArraySize )
  829. { //Allocate and copy over the valid gridnos.
  830. gps2ndWestEdgepointArray = (INT16*)MemAlloc( gus2ndWestEdgepointArraySize * sizeof( INT16) );
  831. for( i = 0; i < gus2ndWestEdgepointArraySize; i++ )
  832. gps2ndWestEdgepointArray[ i ] = sVGridNo[ i ];
  833. }
  834. }
  835. }
  836. //Eliminates any edgepoints not accessible to the edge of the world. This is done to the primary edgepoints
  837. ValidateEdgepoints();
  838. //Second step is to process the primary edgepoints and determine if any of the edgepoints aren't accessible from
  839. //the associated entrypoint. These edgepoints that are rejected are placed in the secondary list.
  840. if( gMapInformation.sIsolatedGridNo != -1 )
  841. { //only if there is an isolated gridno in the map. There is a flaw in the design of this system. The classification
  842. //process will automatically assign areas to be isolated if there is an obstacle between one normal edgepoint and another
  843. //causing a 5 tile connection check to fail. So, all maps with isolated edgepoints will need to be checked manually to
  844. //make sure there are no obstacles causing this to happen (except for obstacles between normal areas and the isolated area)
  845. //Good thing most maps don't have isolated sections. This is one expensive function to call! Maybe 200MI!
  846. ClassifyEdgepoints();
  847. }
  848. gfGeneratingMapEdgepoints = FALSE;
  849. }
  850. void SaveMapEdgepoints( HWFILE fp )
  851. {
  852. //1st priority edgepoints -- for common entry -- tactical placement gui uses only these points.
  853. FileWrite( fp, &gus1stNorthEdgepointArraySize, 2, NULL );
  854. FileWrite( fp, &gus1stNorthEdgepointMiddleIndex, 2, NULL );
  855. if( gus1stNorthEdgepointArraySize )
  856. FileWrite( fp, gps1stNorthEdgepointArray, gus1stNorthEdgepointArraySize * sizeof( INT16 ), NULL );
  857. FileWrite( fp, &gus1stEastEdgepointArraySize, 2, NULL );
  858. FileWrite( fp, &gus1stEastEdgepointMiddleIndex, 2, NULL );
  859. if( gus1stEastEdgepointArraySize )
  860. FileWrite( fp, gps1stEastEdgepointArray, gus1stEastEdgepointArraySize * sizeof( INT16 ), NULL );
  861. FileWrite( fp, &gus1stSouthEdgepointArraySize, 2, NULL );
  862. FileWrite( fp, &gus1stSouthEdgepointMiddleIndex, 2, NULL );
  863. if( gus1stSouthEdgepointArraySize )
  864. FileWrite( fp, gps1stSouthEdgepointArray, gus1stSouthEdgepointArraySize * sizeof( INT16 ), NULL );
  865. FileWrite( fp, &gus1stWestEdgepointArraySize, 2, NULL );
  866. FileWrite( fp, &gus1stWestEdgepointMiddleIndex, 2, NULL );
  867. if( gus1stWestEdgepointArraySize )
  868. FileWrite( fp, gps1stWestEdgepointArray, gus1stWestEdgepointArraySize * sizeof( INT16 ), NULL );
  869. //2nd priority edgepoints -- for isolated areas. Okay to be zero
  870. FileWrite( fp, &gus2ndNorthEdgepointArraySize, 2, NULL );
  871. FileWrite( fp, &gus2ndNorthEdgepointMiddleIndex, 2, NULL );
  872. if( gus2ndNorthEdgepointArraySize )
  873. FileWrite( fp, gps2ndNorthEdgepointArray, gus2ndNorthEdgepointArraySize * sizeof( INT16 ), NULL );
  874. FileWrite( fp, &gus2ndEastEdgepointArraySize, 2, NULL );
  875. FileWrite( fp, &gus2ndEastEdgepointMiddleIndex, 2, NULL );
  876. if( gus2ndEastEdgepointArraySize )
  877. FileWrite( fp, gps2ndEastEdgepointArray, gus2ndEastEdgepointArraySize * sizeof( INT16 ), NULL );
  878. FileWrite( fp, &gus2ndSouthEdgepointArraySize, 2, NULL );
  879. FileWrite( fp, &gus2ndSouthEdgepointMiddleIndex, 2, NULL );
  880. if( gus2ndSouthEdgepointArraySize )
  881. FileWrite( fp, gps2ndSouthEdgepointArray, gus2ndSouthEdgepointArraySize * sizeof( INT16 ), NULL );
  882. FileWrite( fp, &gus2ndWestEdgepointArraySize, 2, NULL );
  883. FileWrite( fp, &gus2ndWestEdgepointMiddleIndex, 2, NULL );
  884. if( gus2ndWestEdgepointArraySize )
  885. FileWrite( fp, gps2ndWestEdgepointArray, gus2ndWestEdgepointArraySize * sizeof( INT16 ), NULL );
  886. }
  887. void OldLoadMapEdgepoints( INT8 **hBuffer )
  888. {
  889. LOADDATA( &gus1stNorthEdgepointArraySize, *hBuffer, 2 );
  890. LOADDATA( &gus1stNorthEdgepointMiddleIndex, *hBuffer, 2 );
  891. if( gus1stNorthEdgepointArraySize )
  892. {
  893. gps1stNorthEdgepointArray = (INT16*)MemAlloc( gus1stNorthEdgepointArraySize * sizeof( INT16 ) );
  894. Assert( gps1stNorthEdgepointArray );
  895. LOADDATA( gps1stNorthEdgepointArray, *hBuffer, gus1stNorthEdgepointArraySize * sizeof( INT16 ) );
  896. }
  897. LOADDATA( &gus1stEastEdgepointArraySize, *hBuffer, 2 );
  898. LOADDATA( &gus1stEastEdgepointMiddleIndex, *hBuffer, 2 );
  899. if( gus1stEastEdgepointArraySize )
  900. {
  901. gps1stEastEdgepointArray = (INT16*)MemAlloc( gus1stEastEdgepointArraySize * sizeof( INT16 ) );
  902. Assert( gps1stEastEdgepointArray );
  903. LOADDATA( gps1stEastEdgepointArray, *hBuffer, gus1stEastEdgepointArraySize * sizeof( INT16 ) );
  904. }
  905. LOADDATA( &gus1stSouthEdgepointArraySize, *hBuffer, 2 );
  906. LOADDATA( &gus1stSouthEdgepointMiddleIndex, *hBuffer, 2 );
  907. if( gus1stSouthEdgepointArraySize )
  908. {
  909. gps1stSouthEdgepointArray = (INT16*)MemAlloc( gus1stSouthEdgepointArraySize * sizeof( INT16 ) );
  910. Assert( gps1stSouthEdgepointArray );
  911. LOADDATA( gps1stSouthEdgepointArray, *hBuffer, gus1stSouthEdgepointArraySize * sizeof( INT16 ) );
  912. }
  913. LOADDATA( &gus1stWestEdgepointArraySize, *hBuffer, 2 );
  914. LOADDATA( &gus1stWestEdgepointMiddleIndex, *hBuffer, 2 );
  915. if( gus1stWestEdgepointArraySize )
  916. {
  917. gps1stWestEdgepointArray = (INT16*)MemAlloc( gus1stWestEdgepointArraySize * sizeof( INT16 ) );
  918. Assert( gps1stWestEdgepointArray );
  919. LOADDATA( gps1stWestEdgepointArray, *hBuffer, gus1stWestEdgepointArraySize * sizeof( INT16 ) );
  920. }
  921. }
  922. BOOLEAN LoadMapEdgepoints( INT8 **hBuffer )
  923. {
  924. TrashMapEdgepoints();
  925. if( gMapInformation.ubMapVersion < 17 )
  926. { //To prevent invalidation of older maps, which only used one layer of edgepoints, and a UINT8 for
  927. //containing the size, we will preserve that paradigm, then kill the loaded edgepoints and
  928. //regenerate them.
  929. OldLoadMapEdgepoints( hBuffer );
  930. TrashMapEdgepoints();
  931. return FALSE;
  932. }
  933. LOADDATA( &gus1stNorthEdgepointArraySize, *hBuffer, 2 );
  934. LOADDATA( &gus1stNorthEdgepointMiddleIndex, *hBuffer, 2 );
  935. if( gus1stNorthEdgepointArraySize )
  936. {
  937. gps1stNorthEdgepointArray = (INT16*)MemAlloc( gus1stNorthEdgepointArraySize * sizeof( INT16 ) );
  938. Assert( gps1stNorthEdgepointArray );
  939. LOADDATA( gps1stNorthEdgepointArray, *hBuffer, gus1stNorthEdgepointArraySize * sizeof( INT16 ) );
  940. }
  941. LOADDATA( &gus1stEastEdgepointArraySize, *hBuffer, 2 );
  942. LOADDATA( &gus1stEastEdgepointMiddleIndex, *hBuffer, 2 );
  943. if( gus1stEastEdgepointArraySize )
  944. {
  945. gps1stEastEdgepointArray = (INT16*)MemAlloc( gus1stEastEdgepointArraySize * sizeof( INT16 ) );
  946. Assert( gps1stEastEdgepointArray );
  947. LOADDATA( gps1stEastEdgepointArray, *hBuffer, gus1stEastEdgepointArraySize * sizeof( INT16 ) );
  948. }
  949. LOADDATA( &gus1stSouthEdgepointArraySize, *hBuffer, 2 );
  950. LOADDATA( &gus1stSouthEdgepointMiddleIndex, *hBuffer, 2 );
  951. if( gus1stSouthEdgepointArraySize )
  952. {
  953. gps1stSouthEdgepointArray = (INT16*)MemAlloc( gus1stSouthEdgepointArraySize * sizeof( INT16 ) );
  954. Assert( gps1stSouthEdgepointArray );
  955. LOADDATA( gps1stSouthEdgepointArray, *hBuffer, gus1stSouthEdgepointArraySize * sizeof( INT16 ) );
  956. }
  957. LOADDATA( &gus1stWestEdgepointArraySize, *hBuffer, 2 );
  958. LOADDATA( &gus1stWestEdgepointMiddleIndex, *hBuffer, 2 );
  959. if( gus1stWestEdgepointArraySize )
  960. {
  961. gps1stWestEdgepointArray = (INT16*)MemAlloc( gus1stWestEdgepointArraySize * sizeof( INT16 ) );
  962. Assert( gps1stWestEdgepointArray );
  963. LOADDATA( gps1stWestEdgepointArray, *hBuffer, gus1stWestEdgepointArraySize * sizeof( INT16 ) );
  964. }
  965. LOADDATA( &gus2ndNorthEdgepointArraySize, *hBuffer, 2 );
  966. LOADDATA( &gus2ndNorthEdgepointMiddleIndex, *hBuffer, 2 );
  967. if( gus2ndNorthEdgepointArraySize )
  968. {
  969. gps2ndNorthEdgepointArray = (INT16*)MemAlloc( gus2ndNorthEdgepointArraySize * sizeof( INT16 ) );
  970. Assert( gps2ndNorthEdgepointArray );
  971. LOADDATA( gps2ndNorthEdgepointArray, *hBuffer, gus2ndNorthEdgepointArraySize * sizeof( INT16 ) );
  972. }
  973. LOADDATA( &gus2ndEastEdgepointArraySize, *hBuffer, 2 );
  974. LOADDATA( &gus2ndEastEdgepointMiddleIndex, *hBuffer, 2 );
  975. if( gus2ndEastEdgepointArraySize )
  976. {
  977. gps2ndEastEdgepointArray = (INT16*)MemAlloc( gus2ndEastEdgepointArraySize * sizeof( INT16 ) );
  978. Assert( gps2ndEastEdgepointArray );
  979. LOADDATA( gps2ndEastEdgepointArray, *hBuffer, gus2ndEastEdgepointArraySize * sizeof( INT16 ) );
  980. }
  981. LOADDATA( &gus2ndSouthEdgepointArraySize, *hBuffer, 2 );
  982. LOADDATA( &gus2ndSouthEdgepointMiddleIndex, *hBuffer, 2 );
  983. if( gus2ndSouthEdgepointArraySize )
  984. {
  985. gps2ndSouthEdgepointArray = (INT16*)MemAlloc( gus2ndSouthEdgepointArraySize * sizeof( INT16 ) );
  986. Assert( gps2ndSouthEdgepointArray );
  987. LOADDATA( gps2ndSouthEdgepointArray, *hBuffer, gus2ndSouthEdgepointArraySize * sizeof( INT16 ) );
  988. }
  989. LOADDATA( &gus2ndWestEdgepointArraySize, *hBuffer, 2 );
  990. LOADDATA( &gus2ndWestEdgepointMiddleIndex, *hBuffer, 2 );
  991. if( gus2ndWestEdgepointArraySize )
  992. {
  993. gps2ndWestEdgepointArray = (INT16*)MemAlloc( gus2ndWestEdgepointArraySize * sizeof( INT16 ) );
  994. Assert( gps2ndWestEdgepointArray );
  995. LOADDATA( gps2ndWestEdgepointArray, *hBuffer, gus2ndWestEdgepointArraySize * sizeof( INT16 ) );
  996. }
  997. if( gMapInformation.ubMapVersion < 22 )
  998. { //regenerate them.
  999. TrashMapEdgepoints();
  1000. return FALSE;
  1001. }
  1002. return TRUE;
  1003. }
  1004. UINT16 ChooseMapEdgepoint( UINT8 ubStrategicInsertionCode )
  1005. {
  1006. INT16 *psArray=NULL;
  1007. UINT16 usArraySize=0;
  1008. static INT32 randomVal=0;
  1009. //First validate and get access to the correct array based on strategic direction.
  1010. //We will use the selected array to choose insertion gridno's.
  1011. switch( ubStrategicInsertionCode )
  1012. {
  1013. case INSERTION_CODE_NORTH:
  1014. psArray = gps1stNorthEdgepointArray;
  1015. usArraySize = gus1stNorthEdgepointArraySize;
  1016. break;
  1017. case INSERTION_CODE_EAST:
  1018. psArray = gps1stEastEdgepointArray;
  1019. usArraySize = gus1stEastEdgepointArraySize;
  1020. break;
  1021. case INSERTION_CODE_SOUTH:
  1022. psArray = gps1stSouthEdgepointArray;
  1023. usArraySize = gus1stSouthEdgepointArraySize;
  1024. break;
  1025. case INSERTION_CODE_WEST:
  1026. psArray = gps1stWestEdgepointArray;
  1027. usArraySize = gus1stWestEdgepointArraySize;
  1028. break;
  1029. default:
  1030. AssertMsg( 0, "ChooseMapEdgepoints: Failed to pass a valid strategic insertion code." );
  1031. break;
  1032. }
  1033. if( !usArraySize )
  1034. {
  1035. return NOWHERE;
  1036. }
  1037. return psArray[ Random( usArraySize ) ];
  1038. }
  1039. void ChooseMapEdgepoints( MAPEDGEPOINTINFO *pMapEdgepointInfo, UINT8 ubStrategicInsertionCode, UINT8 ubNumDesiredPoints )
  1040. {
  1041. INT16 *psArray=NULL;
  1042. UINT16 usArraySize=0;
  1043. INT32 i=-1;
  1044. UINT16 usSlots, usCurrSlot;
  1045. INT16 *psTempArray = NULL;
  1046. AssertMsg( ubNumDesiredPoints > 0 && ubNumDesiredPoints <= 32,
  1047. String( "ChooseMapEdgepoints: Desired points = %d, valid range is 1-32", ubNumDesiredPoints ) );
  1048. //First validate and get access to the correct array based on strategic direction.
  1049. //We will use the selected array to choose insertion gridno's.
  1050. switch( ubStrategicInsertionCode )
  1051. {
  1052. case INSERTION_CODE_NORTH:
  1053. psArray = gps1stNorthEdgepointArray;
  1054. usArraySize = gus1stNorthEdgepointArraySize;
  1055. break;
  1056. case INSERTION_CODE_EAST:
  1057. psArray = gps1stEastEdgepointArray;
  1058. usArraySize = gus1stEastEdgepointArraySize;
  1059. break;
  1060. case INSERTION_CODE_SOUTH:
  1061. psArray = gps1stSouthEdgepointArray;
  1062. usArraySize = gus1stSouthEdgepointArraySize;
  1063. break;
  1064. case INSERTION_CODE_WEST:
  1065. psArray = gps1stWestEdgepointArray;
  1066. usArraySize = gus1stWestEdgepointArraySize;
  1067. break;
  1068. default:
  1069. AssertMsg( 0, "ChooseMapEdgepoints: Failed to pass a valid strategic insertion code." );
  1070. break;
  1071. }
  1072. pMapEdgepointInfo->ubStrategicInsertionCode = ubStrategicInsertionCode;
  1073. #ifdef JA2BETAVERSION
  1074. if( !psArray || !usArraySize )
  1075. {
  1076. if( gMapInformation.sNorthGridNo == -1 && gMapInformation.sEastGridNo == -1 &&
  1077. gMapInformation.sSouthGridNo == -1 && gMapInformation.sWestGridNo == -1 &&
  1078. gMapInformation.sCenterGridNo == -1 )
  1079. {
  1080. if( gbWorldSectorZ )
  1081. {
  1082. AssertMsg( 0,
  1083. String( "Map %c%d_b%d(_a) doesn't have ANY entry points which means that it is impossible to generate map edgepoints. (LC : 1)",
  1084. gWorldSectorY + 'A' - 1, gWorldSectorX, gbWorldSectorZ ) );
  1085. }
  1086. else
  1087. {
  1088. AssertMsg( 0,
  1089. String( "Map %c%d(_a) doesn't have ANY entry points which means that it is impossible to generate map edgepoints. (LC : 1)",
  1090. gWorldSectorY + 'A' - 1, gWorldSectorX ) );
  1091. }
  1092. }
  1093. else switch( ubStrategicInsertionCode )
  1094. {
  1095. case INSERTION_CODE_NORTH:
  1096. AssertMsg( 0, "This map doesn't have any north mapedgepoints. Possibly because there is no north entry point. (LC : 1)" );
  1097. break;
  1098. case INSERTION_CODE_EAST:
  1099. AssertMsg( 0, "This map doesn't have any east mapedgepoints. Possibly because there is no east entry point. (LC : 1)" );
  1100. break;
  1101. case INSERTION_CODE_SOUTH:
  1102. AssertMsg( 0, "This map doesn't have any south mapedgepoints. Possibly because there is no south entry point. (LC : 1)" );
  1103. break;
  1104. case INSERTION_CODE_WEST:
  1105. AssertMsg( 0, "This map doesn't have any west mapedgepoints. Possibly because there is no west entry point. NOTE: Teleportation always uses the west entrypoint. Some maps shouldn't have west entrypoints. (LC : 1)" );
  1106. break;
  1107. }
  1108. }
  1109. #endif
  1110. if( !usArraySize )
  1111. {
  1112. pMapEdgepointInfo->ubNumPoints = 0;
  1113. return;
  1114. }
  1115. // JA2 Gold: don't place people in the water.
  1116. // If any of the waypoints is on a water spot, we're going to have to remove it
  1117. psTempArray = MemAlloc( sizeof(INT16) * usArraySize );
  1118. memcpy(psTempArray, psArray, sizeof(INT16) * usArraySize );
  1119. psArray = psTempArray;
  1120. for (i = 0; i < usArraySize; i++)
  1121. {
  1122. if (GetTerrainType(psArray[ i ]) == MED_WATER || GetTerrainType(psArray[ i ]) == DEEP_WATER)
  1123. {
  1124. if (i == usArraySize - 1)
  1125. {
  1126. // just axe it and we're done.
  1127. psArray[ i ] = 0;
  1128. usArraySize--;
  1129. break;
  1130. }
  1131. else
  1132. {
  1133. // replace this element in the array with the LAST element in the array, then decrement
  1134. // the array size
  1135. psArray[ i ] = psArray[usArraySize-1];
  1136. usArraySize--;
  1137. // we're going to have to check the array element we just copied into this spot, too
  1138. i--;
  1139. }
  1140. }
  1141. }
  1142. if( ubNumDesiredPoints >= usArraySize )
  1143. { //We don't have enough points for everyone, return them all.
  1144. pMapEdgepointInfo->ubNumPoints = (UINT8)usArraySize;
  1145. for( i = 0; i < usArraySize; i++ )
  1146. pMapEdgepointInfo->sGridNo[i] = psArray[i];
  1147. // JA2Gold: free the temp array
  1148. MemFree(psTempArray);
  1149. return;
  1150. }
  1151. //We have more points, so choose them randomly.
  1152. usSlots = usArraySize;
  1153. usCurrSlot = 0;
  1154. pMapEdgepointInfo->ubNumPoints = ubNumDesiredPoints;
  1155. for( i = 0; i < usArraySize; i++ )
  1156. {
  1157. if( Random( usSlots ) < ubNumDesiredPoints )
  1158. {
  1159. pMapEdgepointInfo->sGridNo[ usCurrSlot++ ] = psArray[ i ];
  1160. ubNumDesiredPoints--;
  1161. }
  1162. usSlots--;
  1163. }
  1164. // JA2Gold: free the temp array
  1165. MemFree(psTempArray);
  1166. }
  1167. INT16 *gpReservedGridNos = NULL;
  1168. INT16 gsReservedIndex = 0;
  1169. void BeginMapEdgepointSearch()
  1170. {
  1171. INT16 sGridNo;
  1172. //Create the reserved list
  1173. AssertMsg( !gpReservedGridNos, "Attempting to BeginMapEdgepointSearch that has already been created." );
  1174. gpReservedGridNos = (INT16*)MemAlloc( 20 * sizeof( INT16 ) );
  1175. Assert( gpReservedGridNos );
  1176. gsReservedIndex = 0;
  1177. if( gMapInformation.sNorthGridNo != -1 )
  1178. sGridNo = gMapInformation.sNorthGridNo;
  1179. else if( gMapInformation.sEastGridNo != -1 )
  1180. sGridNo = gMapInformation.sEastGridNo;
  1181. else if( gMapInformation.sSouthGridNo != -1 )
  1182. sGridNo = gMapInformation.sSouthGridNo;
  1183. else if( gMapInformation.sWestGridNo != -1 )
  1184. sGridNo = gMapInformation.sWestGridNo;
  1185. else
  1186. return;
  1187. GlobalReachableTest( sGridNo );
  1188. //Now, we have the path values calculated. Now, we can check for closest edgepoints.
  1189. }
  1190. void EndMapEdgepointSearch()
  1191. {
  1192. AssertMsg( gpReservedGridNos, "Attempting to EndMapEdgepointSearch that has already been removed." );
  1193. MemFree( gpReservedGridNos );
  1194. gpReservedGridNos = NULL;
  1195. gsReservedIndex = 0;
  1196. }
  1197. //THIS CODE ISN'T RECOMMENDED FOR TIME CRITICAL AREAS.
  1198. INT16 SearchForClosestPrimaryMapEdgepoint( INT16 sGridNo, UINT8 ubInsertionCode )
  1199. {
  1200. INT32 i, iDirectionLoop;
  1201. INT16 *psArray=NULL;
  1202. INT16 sRadius, sDistance, sDirection, sOriginalGridNo;
  1203. UINT16 usArraySize=0;
  1204. BOOLEAN fReserved;
  1205. if( gsReservedIndex >= 20 )
  1206. { //Everything is reserved.
  1207. AssertMsg( 0, "All closest map edgepoints have been reserved. We should only have 20 soldiers maximum...");
  1208. }
  1209. switch( ubInsertionCode )
  1210. {
  1211. case INSERTION_CODE_NORTH:
  1212. psArray = gps1stNorthEdgepointArray;
  1213. usArraySize = gus1stNorthEdgepointArraySize;
  1214. if( !usArraySize )
  1215. AssertMsg( 0, String( "Sector %c%d level %d doesn't have any north mapedgepoints. LC:1",
  1216. gWorldSectorY + 'A' - 1, gWorldSectorX, gbWorldSectorZ ) );
  1217. break;
  1218. case INSERTION_CODE_EAST:
  1219. psArray = gps1stEastEdgepointArray;
  1220. usArraySize = gus1stEastEdgepointArraySize;
  1221. if( !usArraySize )
  1222. AssertMsg( 0, String( "Sector %c%d level %d doesn't have any east mapedgepoints. LC:1",
  1223. gWorldSectorY + 'A' - 1, gWorldSectorX, gbWorldSectorZ ) );
  1224. break;
  1225. case INSERTION_CODE_SOUTH:
  1226. psArray = gps1stSouthEdgepointArray;
  1227. usArraySize = gus1stSouthEdgepointArraySize;
  1228. if( !usArraySize )
  1229. AssertMsg( 0, String( "Sector %c%d level %d doesn't have any south mapedgepoints. LC:1",
  1230. gWorldSectorY + 'A' - 1, gWorldSectorX, gbWorldSectorZ ) );
  1231. break;
  1232. case INSERTION_CODE_WEST:
  1233. psArray = gps1stWestEdgepointArray;
  1234. usArraySize = gus1stWestEdgepointArraySize;
  1235. if( !usArraySize )
  1236. AssertMsg( 0, String( "Sector %c%d level %d doesn't have any west mapedgepoints. LC:1",
  1237. gWorldSectorY + 'A' - 1, gWorldSectorX, gbWorldSectorZ ) );
  1238. break;
  1239. }
  1240. if( !usArraySize )
  1241. {
  1242. return NOWHERE;
  1243. }
  1244. //Check the initial gridno, to see if it is available and an edgepoint.
  1245. fReserved = FALSE;
  1246. for( i = 0; i < gsReservedIndex; i++ )
  1247. {
  1248. if( gpReservedGridNos[ i ] == sGridNo )
  1249. {
  1250. fReserved = TRUE;
  1251. break;
  1252. }
  1253. }
  1254. if( !fReserved )
  1255. { //Not reserved, so see if we can find this gridno in the edgepoint array.
  1256. for( i = 0 ; i < usArraySize; i++ )
  1257. {
  1258. if( psArray[ i ] == sGridNo )
  1259. { //Yes, the gridno is in the edgepoint array.
  1260. gpReservedGridNos[ gsReservedIndex ] = sGridNo;
  1261. gsReservedIndex++;
  1262. return sGridNo;
  1263. }
  1264. }
  1265. }
  1266. //spiral outwards, until we find an unreserved mapedgepoint.
  1267. //
  1268. // 09 08 07 06
  1269. // 10 01 00 05
  1270. // 11 02 03 04
  1271. // 12 13 14 15 ..
  1272. sRadius = 1;
  1273. sDirection = WORLD_COLS;
  1274. sOriginalGridNo = sGridNo;
  1275. while( sRadius < (INT16)(gbWorldSectorZ ? 30 : 10) )
  1276. {
  1277. sGridNo = sOriginalGridNo + (-1 - WORLD_COLS)*sRadius; //start at the TOP-LEFT gridno
  1278. for( iDirectionLoop = 0; iDirectionLoop < 4; iDirectionLoop++ )
  1279. {
  1280. switch( iDirectionLoop )
  1281. {
  1282. case 0: sDirection = WORLD_COLS; break;
  1283. case 1: sDirection = 1; break;
  1284. case 2: sDirection = -WORLD_COLS; break;
  1285. case 3: sDirection = -1; break;
  1286. }
  1287. sDistance = sRadius * 2;
  1288. while( sDistance-- )
  1289. {
  1290. sGridNo += sDirection;
  1291. if( sGridNo < 0 || sGridNo >= WORLD_MAX )
  1292. continue;
  1293. //Check the gridno, to see if it is available and an edgepoint.
  1294. fReserved = FALSE;
  1295. for( i = 0; i < gsReservedIndex; i++ )
  1296. {
  1297. if( gpReservedGridNos[ i ] == sGridNo )
  1298. {
  1299. fReserved = TRUE;
  1300. break;
  1301. }
  1302. }
  1303. if( !fReserved )
  1304. { //Not reserved, so see if we can find this gridno in the edgepoint array.
  1305. for( i = 0 ; i < usArraySize; i++ )
  1306. {
  1307. if( psArray[ i ] == sGridNo )
  1308. { //Yes, the gridno is in the edgepoint array.
  1309. gpReservedGridNos[ gsReservedIndex ] = sGridNo;
  1310. gsReservedIndex++;
  1311. return sGridNo;
  1312. }
  1313. }
  1314. }
  1315. }
  1316. }
  1317. sRadius++;
  1318. }
  1319. return NOWHERE ;
  1320. }
  1321. INT16 SearchForClosestSecondaryMapEdgepoint( INT16 sGridNo, UINT8 ubInsertionCode )
  1322. {
  1323. INT32 i, iDirectionLoop;
  1324. INT16 *psArray=NULL;
  1325. INT16 sRadius, sDistance, sDirection, sOriginalGridNo;
  1326. UINT16 usArraySize=0;
  1327. BOOLEAN fReserved;
  1328. if( gsReservedIndex >= 20 )
  1329. { //Everything is reserved.
  1330. AssertMsg( 0, "All closest map edgepoints have been reserved. We should only have 20 soldiers maximum...");
  1331. }
  1332. switch( ubInsertionCode )
  1333. {
  1334. case INSERTION_CODE_NORTH:
  1335. psArray = gps2ndNorthEdgepointArray;
  1336. usArraySize = gus2ndNorthEdgepointArraySize;
  1337. if( !usArraySize )
  1338. AssertMsg( 0, String( "Sector %c%d level %d doesn't have any isolated north mapedgepoints. KM:1",
  1339. gWorldSectorY + 'A' - 1, gWorldSectorX, gbWorldSectorZ ) );
  1340. break;
  1341. case INSERTION_CODE_EAST:
  1342. psArray = gps2ndEastEdgepointArray;
  1343. usArraySize = gus2ndEastEdgepointArraySize;
  1344. if( !usArraySize )
  1345. AssertMsg( 0, String( "Sector %c%d level %d doesn't have any isolated east mapedgepoints. KM:1",
  1346. gWorldSectorY + 'A' - 1, gWorldSectorX, gbWorldSectorZ ) );
  1347. break;
  1348. case INSERTION_CODE_SOUTH:
  1349. psArray = gps2ndSouthEdgepointArray;
  1350. usArraySize = gus2ndSouthEdgepointArraySize;
  1351. if( !usArraySize )
  1352. AssertMsg( 0, String( "Sector %c%d level %d doesn't have any isolated south mapedgepoints. KM:1",
  1353. gWorldSectorY + 'A' - 1, gWorldSectorX, gbWorldSectorZ ) );
  1354. break;
  1355. case INSERTION_CODE_WEST:
  1356. psArray = gps2ndWestEdgepointArray;
  1357. usArraySize = gus2ndWestEdgepointArraySize;
  1358. if( !usArraySize )
  1359. AssertMsg( 0, String( "Sector %c%d level %d doesn't have any isolated west mapedgepoints. KM:1",
  1360. gWorldSectorY + 'A' - 1, gWorldSectorX, gbWorldSectorZ ) );
  1361. break;
  1362. }
  1363. if( !usArraySize )
  1364. {
  1365. return NOWHERE;
  1366. }
  1367. //Check the initial gridno, to see if it is available and an edgepoint.
  1368. fReserved = FALSE;
  1369. for( i = 0; i < gsReservedIndex; i++ )
  1370. {
  1371. if( gpReservedGridNos[ i ] == sGridNo )
  1372. {
  1373. fReserved = TRUE;
  1374. break;
  1375. }
  1376. }
  1377. if( !fReserved )
  1378. { //Not reserved, so see if we can find this gridno in the edgepoint array.
  1379. for( i = 0 ; i < usArraySize; i++ )
  1380. {
  1381. if( psArray[ i ] == sGridNo )
  1382. { //Yes, the gridno is in the edgepoint array.
  1383. gpReservedGridNos[ gsReservedIndex ] = sGridNo;
  1384. gsReservedIndex++;
  1385. return sGridNo;
  1386. }
  1387. }
  1388. }
  1389. //spiral outwards, until we find an unreserved mapedgepoint.
  1390. //
  1391. // 09 08 07 06
  1392. // 10 01 00 05
  1393. // 11 02 03 04
  1394. // 12 13 14 15 ..
  1395. sRadius = 1;
  1396. sDirection = WORLD_COLS;
  1397. sOriginalGridNo = sGridNo;
  1398. while( sRadius < (INT16)(gbWorldSectorZ ? 30 : 10) )
  1399. {
  1400. sGridNo = sOriginalGridNo + (-1 - WORLD_COLS)*sRadius; //start at the TOP-LEFT gridno
  1401. for( iDirectionLoop = 0; iDirectionLoop < 4; iDirectionLoop++ )
  1402. {
  1403. switch( iDirectionLoop )
  1404. {
  1405. case 0: sDirection = WORLD_COLS; break;
  1406. case 1: sDirection = 1; break;
  1407. case 2: sDirection = -WORLD_COLS; break;
  1408. case 3: sDirection = -1; break;
  1409. }
  1410. sDistance = sRadius * 2;
  1411. while( sDistance-- )
  1412. {
  1413. sGridNo += sDirection;
  1414. if( sGridNo < 0 || sGridNo >= WORLD_MAX )
  1415. continue;
  1416. //Check the gridno, to see if it is available and an edgepoint.
  1417. fReserved = FALSE;
  1418. for( i = 0; i < gsReservedIndex; i++ )
  1419. {
  1420. if( gpReservedGridNos[ i ] == sGridNo )
  1421. {
  1422. fReserved = TRUE;
  1423. break;
  1424. }
  1425. }
  1426. if( !fReserved )
  1427. { //Not reserved, so see if we can find this gridno in the edgepoint array.
  1428. for( i = 0 ; i < usArraySize; i++ )
  1429. {
  1430. if( psArray[ i ] == sGridNo )
  1431. { //Yes, the gridno is in the edgepoint array.
  1432. gpReservedGridNos[ gsReservedIndex ] = sGridNo;
  1433. gsReservedIndex++;
  1434. return sGridNo;
  1435. }
  1436. }
  1437. }
  1438. }
  1439. }
  1440. sRadius++;
  1441. }
  1442. return NOWHERE ;
  1443. }
  1444. #define EDGE_OF_MAP_SEARCH 5
  1445. BOOLEAN VerifyEdgepoint( SOLDIERTYPE * pSoldier, INT16 sEdgepoint )
  1446. {
  1447. INT32 iSearchRange;
  1448. INT16 sMaxLeft, sMaxRight, sMaxUp, sMaxDown, sXOffset, sYOffset;
  1449. INT16 sGridNo;
  1450. INT8 bDirection;
  1451. pSoldier->sGridNo = sEdgepoint;
  1452. iSearchRange = EDGE_OF_MAP_SEARCH;
  1453. // determine maximum horizontal limits
  1454. sMaxLeft = min( iSearchRange, (pSoldier->sGridNo % MAXCOL));
  1455. //NumMessage("sMaxLeft = ",sMaxLeft);
  1456. sMaxRight = min( iSearchRange, MAXCOL - ((pSoldier->sGridNo % MAXCOL) + 1));
  1457. //NumMessage("sMaxRight = ",sMaxRight);
  1458. // determine maximum vertical limits
  1459. sMaxUp = min( iSearchRange, (pSoldier->sGridNo / MAXROW));
  1460. //NumMessage("sMaxUp = ",sMaxUp);
  1461. sMaxDown = min( iSearchRange, MAXROW - ((pSoldier->sGridNo / MAXROW) + 1));
  1462. // Call FindBestPath to set flags in all locations that we can
  1463. // walk into within range. We have to set some things up first...
  1464. // set the distance limit of the square region
  1465. gubNPCDistLimit = EDGE_OF_MAP_SEARCH;
  1466. // reset the "reachable" flags in the region we're looking at
  1467. for (sYOffset = -sMaxUp; sYOffset <= sMaxDown; sYOffset++)
  1468. {
  1469. for (sXOffset = -sMaxLeft; sXOffset <= sMaxRight; sXOffset++)
  1470. {
  1471. sGridNo = sEdgepoint + sXOffset + (MAXCOL * sYOffset);
  1472. gpWorldLevelData[sGridNo].uiFlags &= ~(MAPELEMENT_REACHABLE);
  1473. }
  1474. }
  1475. FindBestPath( pSoldier, NOWHERE, pSoldier->bLevel, WALKING, COPYREACHABLE, PATH_THROUGH_PEOPLE );
  1476. // Turn off the "reachable" flag for the current location
  1477. // so we don't consider it
  1478. //gpWorldLevelData[sEdgepoint].uiFlags &= ~(MAPELEMENT_REACHABLE);
  1479. // SET UP DOUBLE-LOOP TO STEP THROUGH POTENTIAL GRID #s
  1480. for (sYOffset = -sMaxUp; sYOffset <= sMaxDown; sYOffset++)
  1481. {
  1482. for (sXOffset = -sMaxLeft; sXOffset <= sMaxRight; sXOffset++)
  1483. {
  1484. // calculate the next potential gridno
  1485. sGridNo = sEdgepoint + sXOffset + (MAXCOL * sYOffset);
  1486. if (!(gpWorldLevelData[sGridNo].uiFlags & MAPELEMENT_REACHABLE))
  1487. {
  1488. continue;
  1489. }
  1490. if (GridNoOnEdgeOfMap( sGridNo, &bDirection ) )
  1491. {
  1492. // ok!
  1493. return TRUE;
  1494. }
  1495. }
  1496. }
  1497. // no spots right on edge of map within 5 tiles
  1498. return FALSE;
  1499. }
  1500. BOOLEAN EdgepointsClose( SOLDIERTYPE *pSoldier, INT16 sEdgepoint1, INT16 sEdgepoint2 )
  1501. {
  1502. INT32 iSearchRange;
  1503. INT16 sMaxLeft, sMaxRight, sMaxUp, sMaxDown, sXOffset, sYOffset;
  1504. INT16 sGridNo;
  1505. pSoldier->sGridNo = sEdgepoint1;
  1506. if( gWorldSectorX == 14 && gWorldSectorY == 9 && !gbWorldSectorZ )
  1507. { //BRUTAL CODE -- special case map.
  1508. iSearchRange = 250;
  1509. }
  1510. else
  1511. {
  1512. iSearchRange = EDGE_OF_MAP_SEARCH;
  1513. }
  1514. // determine maximum horizontal limits
  1515. sMaxLeft = min( iSearchRange, (pSoldier->sGridNo % MAXCOL));
  1516. //NumMessage("sMaxLeft = ",sMaxLeft);
  1517. sMaxRight = min( iSearchRange, MAXCOL - ((pSoldier->sGridNo % MAXCOL) + 1));
  1518. //NumMessage("sMaxRight = ",sMaxRight);
  1519. // determine maximum vertical limits
  1520. sMaxUp = min( iSearchRange, (pSoldier->sGridNo / MAXROW));
  1521. //NumMessage("sMaxUp = ",sMaxUp);
  1522. sMaxDown = min( iSearchRange, MAXROW - ((pSoldier->sGridNo / MAXROW) + 1));
  1523. // Call FindBestPath to set flags in all locations that we can
  1524. // walk into within range. We have to set some things up first...
  1525. // set the distance limit of the square region
  1526. gubNPCDistLimit = (UINT8)iSearchRange;
  1527. // reset the "reachable" flags in the region we're looking at
  1528. for (sYOffset = -sMaxUp; sYOffset <= sMaxDown; sYOffset++)
  1529. {
  1530. for (sXOffset = -sMaxLeft; sXOffset <= sMaxRight; sXOffset++)
  1531. {
  1532. sGridNo = sEdgepoint1 + sXOffset + (MAXCOL * sYOffset);
  1533. gpWorldLevelData[sGridNo].uiFlags &= ~(MAPELEMENT_REACHABLE);
  1534. }
  1535. }
  1536. if( FindBestPath( pSoldier, sEdgepoint2, pSoldier->bLevel, WALKING, COPYREACHABLE, PATH_THROUGH_PEOPLE ) )
  1537. {
  1538. return TRUE;
  1539. }
  1540. return FALSE;
  1541. }
  1542. UINT8 CalcMapEdgepointClassInsertionCode( INT16 sGridNo )
  1543. {
  1544. SOLDIERTYPE Soldier;
  1545. INT32 iLoop;
  1546. INT16 *psEdgepointArray1, *psEdgepointArray2;
  1547. INT32 iEdgepointArraySize1, iEdgepointArraySize2;
  1548. INT16 sClosestSpot1 = NOWHERE, sClosestDist1 = 0x7FFF, sTempDist;
  1549. INT16 sClosestSpot2 = NOWHERE, sClosestDist2 = 0x7FFF;
  1550. BOOLEAN fPrimaryValid = FALSE, fSecondaryValid = FALSE;
  1551. memset( &Soldier, 0, sizeof( SOLDIERTYPE ) );
  1552. Soldier.bTeam = 1;
  1553. Soldier.sGridNo = sGridNo;
  1554. if( gMapInformation.sIsolatedGridNo == -1 )
  1555. { //If the map has no isolated area, then all edgepoints are primary.
  1556. return INSERTION_CODE_PRIMARY_EDGEINDEX;
  1557. }
  1558. switch( gubTacticalDirection )
  1559. {
  1560. case NORTH:
  1561. psEdgepointArray1 = gps1stNorthEdgepointArray;
  1562. iEdgepointArraySize1 = gus1stNorthEdgepointArraySize;
  1563. psEdgepointArray2 = gps2ndNorthEdgepointArray;
  1564. iEdgepointArraySize2 = gus2ndNorthEdgepointArraySize;
  1565. break;
  1566. case EAST:
  1567. psEdgepointArray1 = gps1stEastEdgepointArray;
  1568. iEdgepointArraySize1 = gus1stEastEdgepointArraySize;
  1569. psEdgepointArray2 = gps2ndEastEdgepointArray;
  1570. iEdgepointArraySize2 = gus2ndEastEdgepointArraySize;
  1571. break;
  1572. case SOUTH:
  1573. psEdgepointArray1 = gps1stSouthEdgepointArray;
  1574. iEdgepointArraySize1 = gus1stSouthEdgepointArraySize;
  1575. psEdgepointArray2 = gps2ndSouthEdgepointArray;
  1576. iEdgepointArraySize2 = gus2ndSouthEdgepointArraySize;
  1577. break;
  1578. case WEST:
  1579. psEdgepointArray1 = gps1stWestEdgepointArray;
  1580. iEdgepointArraySize1 = gus1stWestEdgepointArraySize;
  1581. psEdgepointArray2 = gps2ndWestEdgepointArray;
  1582. iEdgepointArraySize2 = gus2ndWestEdgepointArraySize;
  1583. break;
  1584. default:
  1585. // WTF???
  1586. return INSERTION_CODE_PRIMARY_EDGEINDEX;
  1587. }
  1588. // Do a 2D search to find the closest map edgepoint and
  1589. // try to create a path there
  1590. for ( iLoop = 0; iLoop < iEdgepointArraySize1; iLoop++ )
  1591. {
  1592. sTempDist = PythSpacesAway( sGridNo, psEdgepointArray1[ iLoop ] );
  1593. if ( sTempDist < sClosestDist1 )
  1594. {
  1595. sClosestDist1 = sTempDist;
  1596. sClosestSpot1 = psEdgepointArray1[ iLoop ];
  1597. }
  1598. }
  1599. for ( iLoop = 0; iLoop < iEdgepointArraySize2; iLoop++ )
  1600. {
  1601. sTempDist = PythSpacesAway( sGridNo, psEdgepointArray2[ iLoop ] );
  1602. if ( sTempDist < sClosestDist2 )
  1603. {
  1604. sClosestDist2 = sTempDist;
  1605. sClosestSpot2 = psEdgepointArray2[ iLoop ];
  1606. }
  1607. }
  1608. // set the distance limit of the square region
  1609. gubNPCDistLimit = 15;
  1610. if( !sClosestDist1 || FindBestPath( &Soldier, sClosestSpot1, 0, WALKING, NO_COPYROUTE, PATH_THROUGH_PEOPLE ) )
  1611. {
  1612. fPrimaryValid = TRUE;
  1613. }
  1614. if( !sClosestDist2 || FindBestPath( &Soldier, sClosestSpot2, 0, WALKING, NO_COPYROUTE, PATH_THROUGH_PEOPLE ) )
  1615. {
  1616. fSecondaryValid = TRUE;
  1617. }
  1618. if( fPrimaryValid == fSecondaryValid )
  1619. {
  1620. if( sClosestDist2 < sClosestDist1 )
  1621. {
  1622. return INSERTION_CODE_SECONDARY_EDGEINDEX;
  1623. }
  1624. return INSERTION_CODE_PRIMARY_EDGEINDEX;
  1625. }
  1626. if( fPrimaryValid )
  1627. {
  1628. return INSERTION_CODE_PRIMARY_EDGEINDEX;
  1629. }
  1630. return INSERTION_CODE_SECONDARY_EDGEINDEX;
  1631. }
  1632. #ifdef JA2BETAVERSION
  1633. #include "worldman.h"
  1634. #include "message.h"
  1635. void ShowMapEdgepoints()
  1636. {
  1637. INT32 i, usIllegal1 = 0, usIllegal2 = 0;
  1638. for( i = 0 ; i < gus1stNorthEdgepointArraySize; i++ )
  1639. {
  1640. if( gps1stNorthEdgepointArray[ i ] != -1 )
  1641. {
  1642. AddTopmostToTail( gps1stNorthEdgepointArray[ i ], FIRSTPOINTERS5 );
  1643. }
  1644. else
  1645. {
  1646. usIllegal1++;
  1647. }
  1648. }
  1649. for( i = 0 ; i < gus1stEastEdgepointArraySize; i++ )
  1650. {
  1651. if( gps1stEastEdgepointArray[ i ] != -1 )
  1652. {
  1653. AddTopmostToTail( gps1stEastEdgepointArray[ i ], FIRSTPOINTERS5 );
  1654. }
  1655. else
  1656. {
  1657. usIllegal1++;
  1658. }
  1659. }
  1660. for( i = 0 ; i < gus1stSouthEdgepointArraySize; i++ )
  1661. {
  1662. if( gps1stSouthEdgepointArray[ i ] != -1 )
  1663. {
  1664. AddTopmostToTail( gps1stSouthEdgepointArray[ i ], FIRSTPOINTERS5 );
  1665. }
  1666. else
  1667. {
  1668. usIllegal1++;
  1669. }
  1670. }
  1671. for( i = 0 ; i < gus1stWestEdgepointArraySize; i++ )
  1672. {
  1673. if( gps1stWestEdgepointArray[ i ] != -1 )
  1674. {
  1675. AddTopmostToTail( gps1stWestEdgepointArray[ i ], FIRSTPOINTERS5 );
  1676. }
  1677. else
  1678. {
  1679. usIllegal1++;
  1680. }
  1681. }
  1682. for( i = 0 ; i < gus2ndNorthEdgepointArraySize; i++ )
  1683. {
  1684. if( gps2ndNorthEdgepointArray[ i ] != -1 )
  1685. {
  1686. AddTopmostToTail( gps2ndNorthEdgepointArray[ i ], FIRSTPOINTERS6 );
  1687. }
  1688. else
  1689. {
  1690. usIllegal2++;
  1691. }
  1692. }
  1693. for( i = 0 ; i < gus2ndEastEdgepointArraySize; i++ )
  1694. {
  1695. if( gps2ndEastEdgepointArray[ i ] != -1 )
  1696. {
  1697. AddTopmostToTail( gps2ndEastEdgepointArray[ i ], FIRSTPOINTERS6 );
  1698. }
  1699. else
  1700. {
  1701. usIllegal2++;
  1702. }
  1703. }
  1704. for( i = 0 ; i < gus2ndSouthEdgepointArraySize; i++ )
  1705. {
  1706. if( gps2ndSouthEdgepointArray[ i ] != -1 )
  1707. {
  1708. AddTopmostToTail( gps2ndSouthEdgepointArray[ i ], FIRSTPOINTERS6 );
  1709. }
  1710. else
  1711. {
  1712. usIllegal2++;
  1713. }
  1714. }
  1715. for( i = 0 ; i < gus2ndWestEdgepointArraySize; i++ )
  1716. {
  1717. if( gps2ndWestEdgepointArray[ i ] != -1 )
  1718. {
  1719. AddTopmostToTail( gps2ndWestEdgepointArray[ i ], FIRSTPOINTERS6 );
  1720. }
  1721. else
  1722. {
  1723. usIllegal2++;
  1724. }
  1725. }
  1726. if( !usIllegal1 && !usIllegal2 )
  1727. {
  1728. ScreenMsg( 0, MSG_TESTVERSION, L"Showing display of map edgepoints" );
  1729. }
  1730. else
  1731. {
  1732. ScreenMsg( 0, MSG_TESTVERSION, L"Showing display of map edgepoints (%d illegal primary, %d illegal secondary)" );
  1733. }
  1734. ScreenMsg( 0, MSG_TESTVERSION, L"N:%d:%d E:%d:%d S:%d:%d W:%d:%d",
  1735. gus1stNorthEdgepointArraySize, gus2ndNorthEdgepointArraySize,
  1736. gus1stEastEdgepointArraySize, gus2ndEastEdgepointArraySize,
  1737. gus1stSouthEdgepointArraySize, gus2ndSouthEdgepointArraySize,
  1738. gus1stWestEdgepointArraySize, gus2ndWestEdgepointArraySize );
  1739. }
  1740. void HideMapEdgepoints()
  1741. {
  1742. INT32 i;
  1743. ScreenMsg( 0, MSG_TESTVERSION, L"Removing display of map edgepoints" );
  1744. for( i = 0 ; i < gus1stNorthEdgepointArraySize; i++ )
  1745. {
  1746. if( gps1stNorthEdgepointArray[ i ] != -1 )
  1747. {
  1748. RemoveAllTopmostsOfTypeRange( gps1stNorthEdgepointArray[ i ], FIRSTPOINTERS, FIRSTPOINTERS );
  1749. }
  1750. }
  1751. for( i = 0 ; i < gus1stEastEdgepointArraySize; i++ )
  1752. {
  1753. if( gps1stEastEdgepointArray[ i ] != -1 )
  1754. {
  1755. RemoveAllTopmostsOfTypeRange( gps1stEastEdgepointArray[ i ], FIRSTPOINTERS, FIRSTPOINTERS );
  1756. }
  1757. }
  1758. for( i = 0 ; i < gus1stSouthEdgepointArraySize; i++ )
  1759. {
  1760. if( gps1stSouthEdgepointArray[ i ] != -1 )
  1761. {
  1762. RemoveAllTopmostsOfTypeRange( gps1stSouthEdgepointArray[ i ], FIRSTPOINTERS, FIRSTPOINTERS );
  1763. }
  1764. }
  1765. for( i = 0 ; i < gus1stWestEdgepointArraySize; i++ )
  1766. {
  1767. if( gps1stWestEdgepointArray[ i ] != -1 )
  1768. {
  1769. RemoveAllTopmostsOfTypeRange( gps1stWestEdgepointArray[ i ], FIRSTPOINTERS, FIRSTPOINTERS );
  1770. }
  1771. }
  1772. for( i = 0 ; i < gus2ndNorthEdgepointArraySize; i++ )
  1773. {
  1774. if( gps2ndNorthEdgepointArray[ i ] != -1 )
  1775. {
  1776. RemoveAllTopmostsOfTypeRange( gps2ndNorthEdgepointArray[ i ], FIRSTPOINTERS, FIRSTPOINTERS );
  1777. }
  1778. }
  1779. for( i = 0 ; i < gus2ndEastEdgepointArraySize; i++ )
  1780. {
  1781. if( gps2ndEastEdgepointArray[ i ] != -1 )
  1782. {
  1783. RemoveAllTopmostsOfTypeRange( gps2ndEastEdgepointArray[ i ], FIRSTPOINTERS, FIRSTPOINTERS );
  1784. }
  1785. }
  1786. for( i = 0 ; i < gus2ndSouthEdgepointArraySize; i++ )
  1787. {
  1788. if( gps2ndSouthEdgepointArray[ i ] != -1 )
  1789. {
  1790. RemoveAllTopmostsOfTypeRange( gps2ndSouthEdgepointArray[ i ], FIRSTPOINTERS, FIRSTPOINTERS );
  1791. }
  1792. }
  1793. for( i = 0 ; i < gus2ndWestEdgepointArraySize; i++ )
  1794. {
  1795. if( gps2ndWestEdgepointArray[ i ] != -1 )
  1796. {
  1797. RemoveAllTopmostsOfTypeRange( gps2ndWestEdgepointArray[ i ], FIRSTPOINTERS, FIRSTPOINTERS );
  1798. }
  1799. }
  1800. }
  1801. #endif