Move.h 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652
  1. //***************************************************************************
  2. //
  3. // Move.h -- Defs for Movement/Pathfinding routines
  4. //
  5. //---------------------------------------------------------------------------//
  6. // Copyright (C) Microsoft Corporation. All rights reserved. //
  7. //===========================================================================//
  8. #ifndef MOVE_H
  9. #define MOVE_H
  10. //***************************************************************************
  11. //--------------
  12. // Include Files
  13. #ifndef MCLIB_H
  14. #include "mclib.h"
  15. #endif
  16. #ifndef DMOVEMGR_H
  17. #include "dmovemgr.h"
  18. #endif
  19. #ifndef TERRAIN_H
  20. #include "terrain.h"
  21. #endif
  22. #ifndef DOBJCLASS_H
  23. #include "dobjclass.h"
  24. #endif
  25. #ifndef DOBJBLCK_H
  26. #include "dobjblck.h"
  27. #endif
  28. #ifndef DGAMELOG_H
  29. #include "dgamelog.h"
  30. #endif
  31. #include <gameos.hpp>
  32. //***************************************************************************
  33. #define USE_FORESTS 0
  34. #define MAX_GLOBALMAP_DOORS 10000
  35. #define MAX_GLOBALMAP_AREAS 10000
  36. #define NUM_EXTRA_DOOR_LINKS 2
  37. //#define INNER_SPHERE TEAM1
  38. //#define CLANS TEAM2
  39. //#define ALLIED TEAM3
  40. //#define NEUTRAL 0xff //NEUTRALS are NOT part of the eight Teams!
  41. //These are inanimate things like buildings, trees, rocks, etc.
  42. #define SIMPLE_PATHMAP 0
  43. #define SECTOR_PATHMAP 1
  44. typedef enum {
  45. DOOR_OFFSET_START,
  46. DOOR_OFFSET_GOAL,
  47. NUM_DOOR_OFFSETS
  48. } GlobalMapDoorOffset;
  49. #define SECTOR_DIM 30
  50. #define MOVEMAP_WIDTH 12 // Used outside of move file
  51. #define MOVEMAP_MAX_CELLOBJECTS 4
  52. #define TILE_PRESERVED_FLAG 0x8000
  53. #define NUM_DIRECTIONS 8
  54. #define HPRIME_NOT_CALCED 0xFFFFFFFF
  55. #define MOVEFLAG_OPEN 1
  56. #define MOVEFLAG_CLOSED 2
  57. #define MOVEFLAG_STEP 4
  58. #define MOVEFLAG_GOAL 8
  59. #define MOVEFLAG_MOVER_HERE 16
  60. #define MOVEFLAG_GOAL_BLOCKED 32
  61. #define MOVEFLAG_OFFMAP 64
  62. #define CELLSTATE_OPEN 0
  63. #define CELLSTATE_BLOCKED 1
  64. #define FOREST_INCREMENT 2
  65. //----------------
  66. // cell move costs
  67. #define COST_CLEAR 100
  68. #define COST_BLOCKED 10000
  69. #define OVERLAYINDEX_NULL 41
  70. #define IS_DIRTROAD_OVERLAY 0
  71. #define IS_PAVEDROAD_OVERLAY 1
  72. #define IS_RAILROAD_OVERLAY 2
  73. #define SCENARIOMAP_MAX_ELEVATION 63
  74. #define SCENARIOMAP_MAX_TILETYPE 127
  75. #define SCENARIOMAP_MAX_OVERLAYTYPE 127
  76. //#define SCENARIOMAP_LAST_BASETYPE_INDEX 63
  77. //TileType and OverlayType now in terrain.h!
  78. typedef enum {
  79. OVERLAY_WEIGHT_VEHICLE,
  80. OVERLAY_WEIGHT_MECH,
  81. OVERLAY_WEIGHT_OTHER1,
  82. OVERLAY_WEIGHT_OTHER2,
  83. OVERLAY_WEIGHT_OTHER3,
  84. NUM_OVERLAY_WEIGHT_CLASSES
  85. } OverlayWeightClass;
  86. //------------------
  87. // class Definitions
  88. #define MOVEPARAM_NONE 0
  89. #define MOVEPARAM_FACE_TARGET 1
  90. #define MOVEPARAM_DIR_OFFSET 2
  91. #define MOVEPARAM_BACK_UP 4
  92. #define MOVEPARAM_SOMEWHERE_ELSE 8
  93. #define MOVEPARAM_MOVING_MOVERS 16
  94. #define MOVEPARAM_MYSTERY_PARAM 32
  95. #define MOVEPARAM_STATIONARY_MOVERS 64
  96. #define MOVEPARAM_AVOID_PATHLOCKS 128
  97. #define MOVEPARAM_INIT 256
  98. #define MOVEPARAM_RECALC 512
  99. #define MOVEPARAM_STEP_TOWARD_TARGET 1024
  100. #define MOVEPARAM_PLAYER 2048
  101. #define MOVEPARAM_RADIO_RESULT 4096
  102. #define MOVEPARAM_ESCAPE_TILE 8192
  103. #define MOVEPARAM_STEP_ADJACENT_TARGET 16384
  104. #define MOVEPARAM_SWEEP_MINES 32768
  105. #define MOVEPARAM_FOLLOW_ROADS 65536
  106. #define MOVEPARAM_WATER_SHALLOW 131072
  107. #define MOVEPARAM_WATER_DEEP 262144
  108. #define MOVEPARAM_RANDOM_OPTIMAL 524288
  109. #define MOVEPARAM_JUMP 1048576
  110. #define TACORDER_PARAM_NONE 0
  111. #define TACORDER_PARAM_RUN (1<<0)
  112. #define TACORDER_PARAM_WAIT (1<<1)
  113. #define TACORDER_PARAM_FACE_OBJECT (1<<2)
  114. #define TACORDER_PARAM_LAY_MINES (1<<3)
  115. #define TACORDER_PARAM_PURSUE (1<<4)
  116. #define TACORDER_PARAM_OBLITERATE (1<<5)
  117. #define TACORDER_PARAM_ESCAPE_TILE (1<<6)
  118. #define TACORDER_PARAM_SCAN (1<<7)
  119. #define TACORDER_PARAM_ATTACK_DFA (1<<8)
  120. #define TACORDER_PARAM_ATTACK_RAMMING (1<<9)
  121. #define TACORDER_PARAM_RANGE_RAMMING (1<<10)
  122. #define TACORDER_PARAM_RANGE_LONGEST (1<<11)
  123. #define TACORDER_PARAM_RANGE_OPTIMAL (1<<12)
  124. #define TACORDER_PARAM_RANGE_SHORT (1<<13)
  125. #define TACORDER_PARAM_RANGE_MEDIUM (1<<14)
  126. #define TACORDER_PARAM_RANGE_LONG (1<<15)
  127. #define TACORDER_PARAM_AIM_HEAD (1<<16)
  128. #define TACORDER_PARAM_AIM_LEG (1<<17)
  129. #define TACORDER_PARAM_AIM_ARM (1<<18)
  130. #define TACORDER_PARAM_DONT_SET_ORDER (1<<19)
  131. #define TACORDER_PARAM_JUMP (1<<20)
  132. #define TACORDER_PARAM_DONT_KEEP_MOVING (1<<21)
  133. #define TACORDER_PARAM_TACTIC_FLANK_RIGHT (1<<22) //4194304
  134. #define TACORDER_PARAM_TACTIC_FLANK_LEFT (1<<23) //8388608
  135. #define TACORDER_PARAM_TACTIC_FLANK_REAR (1<<24) //16777216
  136. #define TACORDER_PARAM_TACTIC_STOP_AND_FIRE (1<<25) //33554432
  137. #define TACORDER_PARAM_TACTIC_TURRET (1<<26) //67108864
  138. #define TACORDER_PARAM_TACTIC_JOUST (1<<27) //134217728
  139. #define TACORDER_ATTACK_MASK 0x00000300
  140. #define TACORDER_RANGE_MASK 0x0000FC00
  141. #define TACORDER_AIM_MASK 0x00070000
  142. #define TACORDER_TACTIC_MASK 0x0FC00000
  143. #define RELPOS_FLAG_ABS 1
  144. #define RELPOS_FLAG_PASSABLE_START 2
  145. #define RELPOS_FLAG_PASSABLE_GOAL 4
  146. #define MAX_GLOBAL_PATH 50
  147. #define NUM_MOVE_LEVELS 2
  148. #define MAX_WALL_OBJECTS 2000
  149. #define MAX_GATES_OBJECT 1000
  150. #define MAX_CELL_COORDS 5000
  151. #define FILL_STACK_SIZE 810000
  152. //***************************************************************************
  153. #pragma pack(1)
  154. //---------------------------------------------------------------------------
  155. #define CELL_INFO_FLAG_PASSABLE 1
  156. #define CELL_INFO_FLAG_LOS 2
  157. #define CELL_INFO_FLAG_WATER_DEEP 4
  158. #define CELL_INFO_FLAG_WATER_SHALLOW 8
  159. #define SPECIAL_NONE 0
  160. #define SPECIAL_WALL 1
  161. #define SPECIAL_GATE 2
  162. #define SPECIAL_LAND_BRIDGE 3
  163. #define SPECIAL_FOREST 4
  164. #define MINE_NONE 0
  165. #define MINE_INTACT 1
  166. #define MINE_EXPLODED 2
  167. typedef struct _ScenarioMapCellInfo {
  168. unsigned char terrain;
  169. unsigned char overlay;
  170. bool road;
  171. bool gate;
  172. bool forest;
  173. char mine;
  174. unsigned char specialType;
  175. short specialID;
  176. bool passable;
  177. long lineOfSight;
  178. } MissionMapCellInfo;
  179. //---------------------------------------------------------------------------
  180. #define MAPCELL_TERRAIN_SHIFT 0
  181. #define MAPCELL_TERRAIN_MASK 0x0000000F
  182. #define MAPCELL_OVERLAY_SHIFT 4
  183. #define MAPCELL_OVERLAY_MASK 0x00000030
  184. #define MAPCELL_MOVER_SHIFT 6
  185. #define MAPCELL_MOVER_MASK 0x00000040
  186. #define MAPCELL_UNUSED1_SHIFT 7 // THIS BIT AVAILABLE!
  187. #define MAPCELL_UNUSED1_MASK 0x00000080
  188. #define MAPCELL_GATE_SHIFT 8
  189. #define MAPCELL_GATE_MASK 0x00000100
  190. #define MAPCELL_OFFMAP_SHIFT 9
  191. #define MAPCELL_OFFMAP_MASK 0x00000200
  192. #define MAPCELL_PASSABLE_SHIFT 10
  193. #define MAPCELL_PASSABLE_MASK 0x00000400
  194. #define MAPCELL_PATHLOCK_SHIFT 11
  195. #define MAPCELL_PATHLOCK_MASK 0x00001800
  196. #define MAPCELL_PATHLOCK_BASE 0x00000800
  197. #define MAPCELL_MINE_SHIFT 13
  198. #define MAPCELL_MINE_MASK 0x0001E000
  199. #define MAPCELL_PRESERVED_SHIFT 17
  200. #define MAPCELL_PRESERVED_MASK 0x00020000
  201. #define MAPCELL_HEIGHT_SHIFT 18
  202. #define MAPCELL_HEIGHT_MASK 0x003C0000
  203. #define MAPCELL_DEBUG_SHIFT 22
  204. #define MAPCELL_DEBUG_MASK 0x00C00000
  205. #define MAPCELL_WALL_SHIFT 24
  206. #define MAPCELL_WALL_MASK 0x01000000
  207. #define MAPCELL_ROAD_SHIFT 25
  208. #define MAPCELL_ROAD_MASK 0x02000000
  209. #define MAPCELL_SHALLOW_SHIFT 26
  210. #define MAPCELL_SHALLOW_MASK 0x04000000
  211. #define MAPCELL_DEEP_SHIFT 27
  212. #define MAPCELL_DEEP_MASK 0x08000000
  213. #define MAPCELL_FOREST_SHIFT 28
  214. #define MAPCELL_FOREST_MASK 0x10000000
  215. //------------------------------------------------------
  216. // The following are used ONLY when building map data...
  217. #define MAPCELL_BUILD_WALL_SHIFT 29
  218. #define MAPCELL_BUILD_WALL_MASK 0x20000000
  219. #define MAPCELL_BUILD_GATE_SHIFT 30
  220. #define MAPCELL_BUILD_GATE_MASK 0x40000000
  221. #define MAPCELL_BUILD_LAND_BRIDGE_SHIFT 11
  222. #define MAPCELL_BUILD_LAND_BRIDGE_MASK 0x00000800
  223. #define MAPCELL_BUILD_SPECIAL_MASK 0x60000800
  224. #define MAPCELL_BUILD_NOT_SET_SHIFT 31
  225. #define MAPCELL_BUILD_NOT_SET_MASK 0x80000000
  226. typedef struct _MapCell {
  227. unsigned long data;
  228. unsigned long getTerrain (void) {
  229. return((data & MAPCELL_TERRAIN_MASK) >> MAPCELL_TERRAIN_SHIFT);
  230. }
  231. void setTerrain (unsigned long terrain) {
  232. data &= (MAPCELL_TERRAIN_MASK ^ 0xFFFFFFFF);
  233. data |= (terrain << MAPCELL_TERRAIN_SHIFT);
  234. }
  235. unsigned long getOverlay (void) {
  236. return((data & MAPCELL_OVERLAY_MASK) >> MAPCELL_OVERLAY_SHIFT);
  237. }
  238. void setOverlay (unsigned long overlay) {
  239. data &= (MAPCELL_OVERLAY_MASK ^ 0xFFFFFFFF);
  240. data |= (overlay << MAPCELL_OVERLAY_SHIFT);
  241. }
  242. bool getMover (void) {
  243. return((data & MAPCELL_MOVER_MASK) ? true : false);
  244. }
  245. void setMover (bool moverHere ) {
  246. data &= (MAPCELL_MOVER_MASK ^ 0xFFFFFFFF);
  247. if (moverHere)
  248. data |= MAPCELL_MOVER_MASK;
  249. }
  250. unsigned long getGate (void) {
  251. return((data & MAPCELL_GATE_MASK) >> MAPCELL_GATE_SHIFT);
  252. }
  253. void setGate (unsigned long gate) {
  254. data &= (MAPCELL_GATE_MASK ^ 0xFFFFFFFF);
  255. data |= (gate << MAPCELL_GATE_SHIFT);
  256. }
  257. bool getPassable (void) {
  258. return((data & MAPCELL_PASSABLE_MASK) ? true : false);
  259. }
  260. void setPassable (bool passable) {
  261. data &= (MAPCELL_PASSABLE_MASK ^ 0xFFFFFFFF);
  262. if (passable)
  263. data |= MAPCELL_PASSABLE_MASK;
  264. }
  265. bool getPathlock (DWORD level) {
  266. return((data & (MAPCELL_PATHLOCK_BASE << level)) ? true : false);
  267. }
  268. void setPathlock (DWORD level, bool pathlock) {
  269. DWORD bit = MAPCELL_PATHLOCK_BASE << level;
  270. data &= (bit ^ 0xFFFFFFFF);
  271. if (pathlock)
  272. data |= bit;
  273. }
  274. unsigned long getMine (void) {
  275. return((data & MAPCELL_MINE_MASK) >> MAPCELL_MINE_SHIFT);
  276. }
  277. void setMine (unsigned long mine) {
  278. data &= (MAPCELL_MINE_MASK ^ 0xFFFFFFFF);
  279. data |= (mine << MAPCELL_MINE_SHIFT);
  280. }
  281. bool getPreserved (void) {
  282. return((data & MAPCELL_PRESERVED_MASK) ? true : false);
  283. }
  284. void setPreserved (bool preserved) {
  285. data &= (MAPCELL_PRESERVED_MASK ^ 0xFFFFFFFF);
  286. if (preserved)
  287. data |= MAPCELL_PRESERVED_MASK;
  288. }
  289. void setLocalHeight (DWORD localElevation) {
  290. data &= (MAPCELL_HEIGHT_MASK ^ 0xFFFFFFFF);
  291. data |= (localElevation << MAPCELL_HEIGHT_SHIFT);
  292. }
  293. DWORD getLocalHeight (void) {
  294. return((data & MAPCELL_HEIGHT_MASK) >> MAPCELL_HEIGHT_SHIFT);
  295. }
  296. void setDebug (DWORD value) {
  297. data &= (MAPCELL_DEBUG_MASK ^ 0xFFFFFFFF);
  298. data |= (value << MAPCELL_DEBUG_SHIFT);
  299. }
  300. DWORD getDebug (void) {
  301. return((data & MAPCELL_DEBUG_MASK) >> MAPCELL_DEBUG_SHIFT);
  302. }
  303. bool getWall (void) {
  304. return((data & MAPCELL_WALL_MASK) ? true : false);
  305. }
  306. void setWall (bool wallHere) {
  307. data &= (MAPCELL_WALL_MASK ^ 0xFFFFFFFF);
  308. if (wallHere)
  309. data |= MAPCELL_WALL_MASK;
  310. }
  311. bool getRoad (void) {
  312. return((data & MAPCELL_ROAD_MASK) ? true : false);
  313. }
  314. void setRoad (bool roadHere) {
  315. data &= (MAPCELL_ROAD_MASK ^ 0xFFFFFFFF);
  316. if (roadHere)
  317. data |= MAPCELL_ROAD_MASK;
  318. }
  319. bool getShallowWater (void) {
  320. return((data & MAPCELL_SHALLOW_MASK) ? true : false);
  321. }
  322. void setShallowWater (bool shallowWaterHere) {
  323. data &= (MAPCELL_SHALLOW_MASK ^ 0xFFFFFFFF);
  324. if (shallowWaterHere)
  325. data |= MAPCELL_SHALLOW_MASK;
  326. }
  327. bool getDeepWater (void) {
  328. return((data & MAPCELL_DEEP_MASK) ? true : false);
  329. }
  330. void setDeepWater (bool deepWaterHere) {
  331. data &= (MAPCELL_DEEP_MASK ^ 0xFFFFFFFF);
  332. if (deepWaterHere)
  333. data |= MAPCELL_DEEP_MASK;
  334. }
  335. bool getBuildGate (void) {
  336. return((data & MAPCELL_BUILD_GATE_MASK) ? true : false);
  337. }
  338. void setBuildGate (bool set) {
  339. data &= (MAPCELL_BUILD_GATE_MASK ^ 0xFFFFFFFF);
  340. if (set)
  341. data |= MAPCELL_BUILD_GATE_MASK;
  342. }
  343. bool getBuildWall (void) {
  344. return((data & MAPCELL_BUILD_WALL_MASK) ? true : false);
  345. }
  346. void setBuildWall (bool set) {
  347. data &= (MAPCELL_BUILD_WALL_MASK ^ 0xFFFFFFFF);
  348. if (set)
  349. data |= MAPCELL_BUILD_WALL_MASK;
  350. }
  351. bool getBuildLandBridge (void) {
  352. return((data & MAPCELL_BUILD_LAND_BRIDGE_MASK) ? true : false);
  353. }
  354. void setBuildLandBridge (bool set) {
  355. data &= (MAPCELL_BUILD_LAND_BRIDGE_MASK ^ 0xFFFFFFFF);
  356. if (set)
  357. data |= MAPCELL_BUILD_LAND_BRIDGE_MASK;
  358. }
  359. bool getForest (void) {
  360. return((data & MAPCELL_FOREST_MASK) ? true : false);
  361. }
  362. void setForest (bool set) {
  363. data &= (MAPCELL_FOREST_MASK ^ 0xFFFFFFFF);
  364. if (set)
  365. data |= MAPCELL_FOREST_MASK;
  366. }
  367. bool getOffMap (void) {
  368. return((data & MAPCELL_OFFMAP_MASK) ? true : false);
  369. }
  370. void setOffMap (bool set) {
  371. data &= (MAPCELL_OFFMAP_MASK ^ 0xFFFFFFFF);
  372. if (set)
  373. data |= MAPCELL_OFFMAP_MASK;
  374. }
  375. bool getBuildSpecial (void) {
  376. return((data & MAPCELL_BUILD_SPECIAL_MASK) ? true : false);
  377. }
  378. bool getBuildNotSet (void) {
  379. return((data & MAPCELL_BUILD_NOT_SET_MASK) ? true : false);
  380. }
  381. void setBuildNotSet (bool set) {
  382. data &= (MAPCELL_BUILD_NOT_SET_MASK ^ 0xFFFFFFFF);
  383. if (set)
  384. data |= MAPCELL_BUILD_NOT_SET_MASK;
  385. }
  386. } MapCell;
  387. typedef MapCell* MapCellPtr;
  388. typedef struct _PreservedCell {
  389. short row;
  390. short col;
  391. unsigned long data;
  392. } PreservedCell;
  393. typedef PreservedCell* PreservedCellPtr;
  394. #pragma pack()
  395. //---------------------------------------------------------------------------
  396. extern float VerticesMapSideDivTwo;
  397. extern float MetersMapSideDivTwo;
  398. #define MAX_DEBUG_CELLS 1000
  399. class MissionMap {
  400. public:
  401. MapCellPtr map;
  402. long height;
  403. long width;
  404. long planet;
  405. bool preserveCells;
  406. long numPreservedCells;
  407. PreservedCell preservedCells[MAX_MOVERS];
  408. long numDebugCells;
  409. long debugCells[MAX_DEBUG_CELLS][3];
  410. void (*placeMoversCallback) (void);
  411. public:
  412. void* operator new (size_t mySize);
  413. void operator delete (void* us);
  414. void init (void) {
  415. map = NULL;
  416. height = 0;
  417. width = 0;
  418. preserveCells = false;
  419. numPreservedCells = 0;
  420. placeMoversCallback = NULL;
  421. numDebugCells = 0;
  422. }
  423. MissionMap (void) {
  424. init();
  425. }
  426. void destroy (void);
  427. ~MissionMap (void) {
  428. destroy();
  429. }
  430. void init (long h, long w);
  431. long init (long curHeight, long curWidth, long curPlanet, MissionMapCellInfo* mapData);
  432. void setPassable (long row, long col, char* footPrint, bool passable);
  433. long init (PacketFile* packetFile, long whichPacket = 0);
  434. long initOld (File* mapFile);
  435. long write (PacketFile* packetFile, long whichPacket = 0);
  436. unsigned long getTerrain (long row, long col) {
  437. return(map[row * width + col].getTerrain());
  438. }
  439. void setTerrain (long row, long col, unsigned long terrain) {
  440. map[row * width + col].setTerrain(terrain);
  441. }
  442. unsigned long getOverlay (long row, long col) {
  443. return(map[row * width + col].getOverlay());
  444. }
  445. void setOverlay (long row, long col, unsigned long overlay) {
  446. map[row * width + col].setOverlay(overlay);
  447. }
  448. bool getMover (long row, long col) {
  449. return(map[row * width + col].getMover());
  450. }
  451. void setMover (long row, long col, bool moverHere) {
  452. map[row * width + col].setMover(moverHere);
  453. }
  454. unsigned long getGate (long row, long col) {
  455. return(map[row * width + col].getGate());
  456. }
  457. void setGate (long row, long col, unsigned long gate) {
  458. map[row * width + col].setGate(gate);
  459. }
  460. bool getPassable (long row, long col) {
  461. return(map[row * width + col].getPassable());
  462. }
  463. void setPassable (long row, long col, bool passable) {
  464. map[row * width + col].setPassable(passable);
  465. }
  466. bool getPassable (Stuff::Vector3D cellPosition);
  467. bool getPathlock (long level, long row, long col) {
  468. return(map[row * width + col].getPathlock(level));
  469. }
  470. void setPathlock (long level, long row, long col, bool pathlock) {
  471. map[row * width + col].setPathlock(level, pathlock);
  472. }
  473. unsigned long getMine (long row, long col) {
  474. return(map[row * width + col].getMine());
  475. }
  476. void setMine (long row, long col, unsigned long mine) {
  477. map[row * width + col].setMine(mine);
  478. }
  479. bool getPreserved (long row, long col) {
  480. return(map[row * width + col].getPreserved());
  481. }
  482. void setPreserved (long row, long col, bool preserved) {
  483. map[row * width + col].setPreserved(preserved);
  484. }
  485. void setLocalHeight (long row, long col, DWORD localElevation) {
  486. map[row * width + col].setLocalHeight(localElevation);
  487. }
  488. DWORD getLocalHeight (long row, long col) {
  489. return(map[row * width + col].getLocalHeight());
  490. }
  491. void setCellDebug (long row, long col, DWORD value, DWORD level) {
  492. if( row >= 0 && row < height && col >= 0 && col < width )
  493. {
  494. DWORD curValue = map[row * width + col].getDebug();
  495. if (curValue && (curValue != value)) {
  496. for (long i = 0; i < numDebugCells; i++)
  497. if (debugCells[i][0] == row)
  498. if (debugCells[i][1] == col) {
  499. if (debugCells[i][2] < level)
  500. break;
  501. return;
  502. }
  503. }
  504. if (value == 0) {
  505. // remove it...
  506. for (long i = 0; i < numDebugCells; i++)
  507. if (debugCells[i][0] == row)
  508. if (debugCells[i][1] == col) {
  509. numDebugCells--;
  510. debugCells[i][0] = debugCells[numDebugCells][0];
  511. debugCells[i][1] = debugCells[numDebugCells][1];
  512. debugCells[i][2] = debugCells[numDebugCells][2];
  513. break;
  514. }
  515. map[row * width + col].setDebug(0);
  516. }
  517. else {
  518. if (numDebugCells < MAX_DEBUG_CELLS) {
  519. debugCells[numDebugCells][0] = row;
  520. debugCells[numDebugCells][1] = col;
  521. debugCells[numDebugCells][2] = level;
  522. numDebugCells++;
  523. map[row * width + col].setDebug(value);
  524. }
  525. }
  526. }
  527. }
  528. void clearCellDebugs (void) {
  529. for (long i = 0; i < numDebugCells; i++)
  530. map[debugCells[i][0] * width + debugCells[i][1]].setDebug(0);
  531. numDebugCells = 0;
  532. }
  533. void clearCellDebugs (long level) {
  534. long i = 0;
  535. while (i < numDebugCells) {
  536. if (debugCells[i][2] == level) {
  537. numDebugCells--;
  538. map[debugCells[i][0] * width + debugCells[i][1]].setDebug(0);
  539. debugCells[i][0] = debugCells[numDebugCells][0];
  540. debugCells[i][1] = debugCells[numDebugCells][1];
  541. debugCells[i][2] = debugCells[numDebugCells][2];
  542. }
  543. else
  544. i++;
  545. }
  546. }
  547. DWORD getCellDebug (long row, long col) {
  548. return(map[row * width + col].getDebug());
  549. }
  550. bool getWall (long row, long col) {
  551. return(map[row * width + col].getWall());
  552. }
  553. void setWall (long row, long col, bool wallHere) {
  554. map[row * width + col].setWall(wallHere);
  555. }
  556. bool getRoad (long row, long col) {
  557. return(map[row * width + col].getRoad());
  558. }
  559. void setRoad (long row, long col, bool roadHere) {
  560. map[row * width + col].setRoad(roadHere);
  561. }
  562. bool getShallowWater (long row, long col) {
  563. return(map[row * width + col].getShallowWater());
  564. }
  565. void setShallowWater (long row, long col, bool shallowWaterHere) {
  566. map[row * width + col].setShallowWater(shallowWaterHere);
  567. }
  568. bool getDeepWater (long row, long col) {
  569. return(map[row * width + col].getDeepWater());
  570. }
  571. void setDeepWater (long row, long col, bool deepWaterHere) {
  572. map[row * width + col].setDeepWater(deepWaterHere);
  573. }
  574. bool getBuildGate (long row, long col) {
  575. return(map[row * width + col].getBuildGate());
  576. }
  577. void setBuildGate (long row, long col, bool set) {
  578. map[row * width + col].setBuildGate(set);
  579. }
  580. bool getBuildWall (long row, long col) {
  581. return(map[row * width + col].getBuildWall());
  582. }
  583. void setBuildWall (long row, long col, bool set) {
  584. map[row * width + col].setBuildWall(set);
  585. }
  586. bool getBuildLandBridge (long row, long col) {
  587. return(map[row * width + col].getBuildLandBridge());
  588. }
  589. void setBuildLandBridge (long row, long col, bool set) {
  590. map[row * width + col].setBuildLandBridge(set);
  591. }
  592. bool getForest (long row, long col) {
  593. return(map[row * width + col].getForest());
  594. }
  595. void setForest (long row, long col, bool set) {
  596. map[row * width + col].setForest(set);
  597. }
  598. bool getOffMap (long row, long col) {
  599. return(map[row * width + col].getOffMap());
  600. }
  601. void setOffMap (long row, long col, bool set) {
  602. map[row * width + col].setOffMap(set);
  603. }
  604. bool getBuildSpecial (long row, long col) {
  605. return(map[row * width + col].getBuildSpecial());
  606. }
  607. bool getBuildNotSet (long row, long col) {
  608. return(map[row * width + col].getBuildNotSet());
  609. }
  610. void setBuildNotSet (long row, long col, bool set) {
  611. map[row * width + col].setBuildNotSet(set);
  612. }
  613. long getHeight (void) {
  614. return(height);
  615. }
  616. long getWidth (void) {
  617. return(width);
  618. }
  619. bool inBounds (long row, long col) {
  620. return((row > -1) && (row < height) && (col > -1) && (col < width));
  621. }
  622. MapCellPtr getCell (long row, long col) {
  623. gosASSERT(inBounds(row, col));
  624. return(&map[row * width + col]);
  625. }
  626. void preserveCell (long row, long col) {
  627. preservedCells[numPreservedCells].data = map[row * width + col].data;
  628. preservedCells[numPreservedCells].row = row;
  629. preservedCells[numPreservedCells].col = col;
  630. map[row * width + col].setPreserved(1);
  631. numPreservedCells++;
  632. }
  633. long getLOF (Stuff::Vector3D position);
  634. unsigned long cellPassable (Stuff::Vector3D cellPosition);
  635. void lineOfSensor (Stuff::Vector3D start, Stuff::Vector3D target, long& numBlockingTiles, long& numBlockingObjects);
  636. long getOverlayWeight (long row, long col, long moverOverlayWeightClass, long moverRelation);
  637. void spreadState (long r, long c, long radius);
  638. long placeObject (Stuff::Vector3D position, float radius);
  639. void placeTerrainObject (long row,
  640. long col,
  641. long objectClass,
  642. long objectTypeID,
  643. __int64 footPrint,
  644. bool blocksLineOfFire,
  645. long mineType);
  646. void print (char* fileName);
  647. };
  648. typedef MissionMap* MissionMapPtr;
  649. //***************************************************************************
  650. class MovePath;
  651. typedef MovePath* MovePathPtr;
  652. //---------------------------------------------------------------------------
  653. #define MAX_STEPS_PER_MOVEPATH 200
  654. typedef struct _PathStep {
  655. short cell[2]; // obvious
  656. float distanceToGoal; // dist, in meters, to goal from this step
  657. Stuff::Vector3D destination; // world pos of this step
  658. char direction; // 0 thru 7 direction into this step
  659. short area;
  660. } PathStep;
  661. typedef PathStep* PathStepPtr;
  662. class MovePath {
  663. public:
  664. Stuff::Vector3D goal; // world pos of path goal
  665. Stuff::Vector3D target; // world pos of object target
  666. long numSteps; // if paused or no steps, == 0, else == numStepsWhenNotPaused
  667. long numStepsWhenNotPaused; // total number of steps
  668. long curStep; // cuurent step we're headed for
  669. long cost; // total cost of path
  670. PathStep stepList[MAX_STEPS_PER_MOVEPATH]; // actual steps :)
  671. bool marked; // is it currently marked
  672. long globalStep; // if part of a complex path
  673. public:
  674. void* operator new (size_t mySize);
  675. void operator delete (void* us);
  676. void init (void) {
  677. goal.Zero();
  678. numSteps = 0;
  679. numStepsWhenNotPaused = 0;
  680. curStep = 0;
  681. cost = 0;
  682. marked = false;
  683. globalStep = -1;
  684. }
  685. long init (long numberOfSteps);
  686. void clear (void);
  687. void setDirection (long stepNumber, char direction) {
  688. stepList[stepNumber].direction = direction;
  689. }
  690. long getDirection (long stepNumber) {
  691. return(stepList[stepNumber].direction);
  692. }
  693. void setDistanceToGoal (long stepNumber, float distance) {
  694. stepList[stepNumber].distanceToGoal = distance;
  695. }
  696. float getDistanceToGoal (long stepNumber) {
  697. return(stepList[stepNumber].distanceToGoal);
  698. }
  699. void setDestination (long stepNumber, Stuff::Vector3D v) {
  700. stepList[stepNumber].destination = v;
  701. }
  702. Stuff::Vector3D getDestination (long stepNumber) {
  703. return(stepList[stepNumber].destination);
  704. }
  705. void setCell (long stepNumber, long r, long c) {
  706. stepList[stepNumber].cell[0] = r;
  707. stepList[stepNumber].cell[1] = c;
  708. }
  709. float getDistanceLeft (Stuff::Vector3D position, long stepNumber = -1);
  710. void lock (long level, long start, long range, bool setting);
  711. bool isLocked (long level, long start, long range, bool* reachedEnd = NULL);
  712. bool isBlocked (long start, long range, bool* reachedEnd = NULL);
  713. long crossesBridge (long start, long range);
  714. long crossesCell (long start, long range, long cellR, long cellC);
  715. long crossesClosedClanGate (long start, long range);
  716. long crossesClosedISGate (long start, long range);
  717. long crossesClosedGate (long start, long range);
  718. MovePath (void) {
  719. init();
  720. }
  721. void destroy (void);
  722. ~MovePath (void) {
  723. destroy();
  724. }
  725. void setCurStep (long _curStep) {
  726. curStep = _curStep;
  727. }
  728. long getNumSteps (void);
  729. long getCost (void) {
  730. return(cost);
  731. }
  732. };
  733. //******************************************************************************************
  734. //******************************************************************************************
  735. #define GLOBAL_FLAG_SPECIAL_IMPOSSIBLE 0x80
  736. #define GLOBAL_FLAG_SPECIAL_CALC 0x40
  737. #define GLOBAL_FLAG_NORMAL_OPENS 0x20
  738. #define GLOBAL_FLAG_NORMAL_CLOSES 0x10
  739. #define GLOBAL_CONFIDENCE_BAD 0
  740. #define GLOBAL_CONFIDENCE_AT_LEAST 1
  741. #define GLOBAL_CONFIDENCE_GOOD 2
  742. #define GLOBALPATH_EXISTS_UNKNOWN 0
  743. #define GLOBALPATH_EXISTS_TRUE 1
  744. #define GLOBALPATH_EXISTS_FALSE 2
  745. #pragma pack(1)
  746. typedef struct _DoorLink {
  747. short doorIndex;
  748. char doorSide;
  749. long cost;
  750. long openCost;
  751. } DoorLink;
  752. typedef DoorLink* DoorLinkPtr;
  753. typedef struct _GlobalMapDoor {
  754. //----------------
  755. // Map layout data
  756. short row;
  757. short col;
  758. char length; // in cells
  759. bool open;
  760. char teamID;
  761. short area[2];
  762. short areaCost[2];
  763. char direction[2];
  764. short numLinks[2];
  765. DoorLinkPtr links[2];
  766. //------------------
  767. // Pathfinding data
  768. long cost;
  769. long parent;
  770. long fromAreaIndex;
  771. unsigned long flags;
  772. long g;
  773. long hPrime;
  774. long fPrime;
  775. } GlobalMapDoor;
  776. typedef GlobalMapDoor* GlobalMapDoorPtr;
  777. typedef struct _DoorInfo {
  778. short doorIndex;
  779. char doorSide;
  780. } DoorInfo;
  781. typedef DoorInfo* DoorInfoPtr;
  782. typedef enum _AreaType {
  783. AREA_TYPE_NORMAL,
  784. AREA_TYPE_WALL,
  785. AREA_TYPE_GATE,
  786. AREA_TYPE_LAND_BRIDGE,
  787. AREA_TYPE_FOREST,
  788. NUM_AREA_TYPES
  789. } AreaType;
  790. typedef enum _WaterType {
  791. WATER_TYPE_NONE,
  792. WATER_TYPE_SHALLOW,
  793. WATER_TYPE_DEEP,
  794. NUM_WATER_TYPES
  795. } WaterType;
  796. typedef struct _GlobalMapArea {
  797. //----------------
  798. // Map layout data
  799. short sectorR;
  800. short sectorC;
  801. DoorInfoPtr doors;
  802. AreaType type;
  803. short numDoors;
  804. long ownerWID;
  805. char teamID;
  806. bool offMap;
  807. bool open;
  808. short* cellsCovered;
  809. } GlobalMapArea;
  810. #pragma pack()
  811. typedef GlobalMapArea* GlobalMapAreaPtr;
  812. typedef struct _GlobalPathStep {
  813. long startDoor;
  814. long thruArea;
  815. long goalDoor;
  816. Stuff::Vector3D start; // "start" in this area
  817. Stuff::Vector3D goal; // "goal" in this area
  818. long goalCell[2]; // which cell did we actually exit thru
  819. long costToGoal;
  820. } GlobalPathStep;
  821. typedef GlobalPathStep* GlobalPathStepPtr;
  822. #define MAX_SPECIAL_AREAS 1500
  823. #define MAX_SPECIAL_SUB_AREAS 25
  824. #define MAX_CELLS_PER_SUB_AREA 49
  825. #define MAX_OFFMAP_AREAS 60
  826. #define MAX_GAME_OBJECT_CELLS 64
  827. typedef struct _GameObjectFootPrint {
  828. short cellPositionRow;
  829. short cellPositionCol;
  830. short preNumCells;
  831. short numCells;
  832. short cells[MAX_GAME_OBJECT_CELLS][2];
  833. } GameObjectFootPrint;
  834. typedef struct _GlobalSpecialAreaInfo {
  835. unsigned char type;
  836. short numSubAreas;
  837. short subAreas[MAX_SPECIAL_SUB_AREAS];
  838. short numCells;
  839. short cells[MAX_CELLS_PER_SUB_AREA][2];
  840. } GlobalSpecialAreaInfo;
  841. class GlobalMap {
  842. public:
  843. long height; // in cells
  844. long width; // in cells
  845. long sectorDim; // in cells
  846. long sectorHeight; // in sectors
  847. long sectorWidth; // in sectors
  848. long numAreas;
  849. long numDoors;
  850. long numDoorInfos;
  851. long numDoorLinks;
  852. short* areaMap;
  853. GlobalMapAreaPtr areas;
  854. GlobalMapDoorPtr doors;
  855. DoorInfoPtr doorInfos;
  856. DoorLinkPtr doorLinks;
  857. GlobalMapDoorPtr doorBuildList;
  858. #ifdef USE_PATH_COST_TABLE
  859. unsigned char* pathCostTable;
  860. #endif
  861. unsigned char* pathExistsTable;
  862. long numSpecialAreas;
  863. GlobalSpecialAreaInfo* specialAreas; // used when building data
  864. bool closes;
  865. bool opens;
  866. long goalArea;
  867. long goalSector[2];
  868. long startCell[2];
  869. long goalCell[2];
  870. bool blank;
  871. bool hover;
  872. bool useClosedAreas;
  873. char moverTeamID;
  874. bool badLoad;
  875. bool calcedPathCost;
  876. long numOffMapAreas;
  877. short offMapAreas[MAX_OFFMAP_AREAS];
  878. bool (*isGateDisabledCallback) (long objectWID);
  879. bool (*isGateOpenCallback) (long objectWID);
  880. static long minRow;
  881. static long maxRow;
  882. static long minCol;
  883. static long maxCol;
  884. static GameLogPtr log;
  885. static bool logEnabled;
  886. public:
  887. void* operator new (size_t mySize);
  888. void operator delete (void* us);
  889. void init (void) {
  890. height = 0;
  891. width = 0;
  892. sectorDim = 30;
  893. sectorHeight = 0;
  894. sectorWidth = 0;
  895. numAreas = 0;
  896. areaMap = NULL;
  897. areas = NULL;
  898. numDoors = 0;
  899. numDoorInfos = 0;
  900. numDoorLinks = 0;
  901. doors = NULL;
  902. doorInfos = NULL;
  903. doorLinks = NULL;
  904. doorBuildList = NULL;
  905. goalSector[0] = goalSector[1] = 0;
  906. blank = false;
  907. hover = false;
  908. useClosedAreas = false;
  909. badLoad = false;
  910. calcedPathCost = false;
  911. startCell[0] = -1;
  912. startCell[1] = -1;
  913. goalCell[0] = -1;
  914. goalCell[1] = -1;
  915. specialAreas = NULL;
  916. closes = false;
  917. opens = false;
  918. numOffMapAreas = 0;
  919. log = NULL;
  920. logEnabled = false;
  921. isGateDisabledCallback = NULL;
  922. isGateOpenCallback = NULL;
  923. }
  924. GlobalMap (void) {
  925. init();
  926. }
  927. void destroy (void);
  928. ~GlobalMap (void) {
  929. destroy();
  930. }
  931. void init (long h, long w);
  932. long build (MissionMapCellInfo* mapData);
  933. long init (PacketFilePtr mapFile, long whichPacket = 0);
  934. long write (PacketFile* packetFile, long whichPacket = 0);
  935. long setTempArea (long row, long col, long cost);
  936. bool fillNorthSouthBridgeArea (long row, long col, long area);
  937. bool fillEastWestBridgeArea (long row, long col, long area);
  938. bool fillNorthSouthRailroadBridgeArea (long row, long col, long area);
  939. bool fillEastWestRailroadBridgeArea (long row, long col, long area);
  940. bool fillSpecialArea (long row, long col, long area, long wallGateID);
  941. bool fillArea (long row, long col, long area, bool offMap);
  942. void calcSectorAreas (long sectorR, long sectorC);
  943. void beginDoorProcessing (void);
  944. long numAreaDoors (long area);
  945. void getAreaDoors (long area, DoorInfoPtr dorrList);
  946. void addDoor (long adjArea, long curArea, long row, long col, long length, long dir);
  947. void endDoorProcessing (void);
  948. void calcAreas (void);
  949. void calcSpecialAreas (MissionMapCellInfo* mapData);
  950. void calcCellsCovered (void);
  951. void calcSpecialTypes (void);
  952. void calcGlobalDoors (void);
  953. void calcAreaDoors (void);
  954. long calcLinkCost (long startDoor, long thruArea, long goalDoor);
  955. void changeAreaLinkCost (long area, long cost);
  956. void calcDoorLinks (void);
  957. long getPathCost (long startArea, long goalArea, bool withSpecialAreas, long& confidence, bool calcIt);
  958. #ifdef USE_PATH_COST_TABLE
  959. void initPathCostTable (void);
  960. void resetPathCostTable (void);
  961. void calcPathCostTable (void);
  962. void setPathCost (long startArea, long goalArea, bool withSpecialAreas, unsigned char cost);
  963. void setPathFlag (long startArea, long goalArea, unsigned char flag, bool set);
  964. long getPathFlag (long startArea, long goalArea, unsigned char flag);
  965. #endif
  966. void clearPathExistsTable (void);
  967. void setPathExists (long fromArea, long toArea, unsigned char set);
  968. unsigned char getPathExists (long fromArea, long toArea);
  969. long exitDirection (long doorIndex, long fromArea);
  970. void setStartDoor (long startArea);
  971. void resetStartDoor (long startArea);
  972. void setAreaTeamID (long area, char teamID);
  973. void setAreaOwnerWID (long area, long objWID);
  974. void setGoalDoor (long goalArea);
  975. void resetGoalDoor (long goalArea);
  976. long calcHPrime (long area);
  977. //void propogateCost (long area, long g);
  978. void propogateCost (long door, long cost, long fromAreaIndex, long g);
  979. long calcPath (long startArea,
  980. long goalArea,
  981. GlobalPathStepPtr path,
  982. long startRow = -1,
  983. long startCol = -1,
  984. long goalRow = -1,
  985. long goalCol = -1);
  986. long calcPath (Stuff::Vector3D start, Stuff::Vector3D goal, GlobalPathStepPtr path);
  987. long calcArea (long row, long col) {
  988. long areaId = areaMap[row * width + col];
  989. if (areaId < 0)
  990. return(-1);
  991. return(areaId);
  992. }
  993. void getDoorTiles (long area, long door, GlobalMapDoorPtr areaDoor);
  994. void getSectorCoords (long area, long& sectorR, long& sectorC) {
  995. sectorR = areas[area].sectorR;
  996. sectorC = areas[area].sectorC;
  997. }
  998. Stuff::Vector3D getDoorWorldPos (long area, long door, long* goalCell);
  999. void openDoor (long door);
  1000. void closeDoor (long door);
  1001. void closeArea (long area);
  1002. void closeArea (long row, long col) {
  1003. long area = calcArea(row, col);
  1004. gosASSERT(area > -1);
  1005. closeArea(area);
  1006. }
  1007. void openArea (long area);
  1008. void openArea (long row, long col) {
  1009. long area = calcArea(row, col);
  1010. gosASSERT(area > -1);
  1011. openArea(area);
  1012. }
  1013. void openOffMapAreas (void) {
  1014. for (long i = 0; i < numOffMapAreas; i++)
  1015. openArea(offMapAreas[i]);
  1016. }
  1017. void closeOffMapAreas (void) {
  1018. for (long i = 0; i < numOffMapAreas; i++)
  1019. closeArea(offMapAreas[i]);
  1020. }
  1021. bool getDoorOpen (long door) {
  1022. return(doors[door].open);
  1023. }
  1024. bool isClosedArea (long area) {
  1025. return(!areas[area].open);
  1026. }
  1027. bool getAdjacentAreaCell (long area, long adjacentArea, long& cellRow, long& cellCol);
  1028. void print (char* fileName);
  1029. static bool toggleLog (void);
  1030. static void writeLog (char* s);
  1031. };
  1032. typedef GlobalMap* GlobalMapPtr;
  1033. //******************************************************************************************
  1034. #define NUM_ADJ_CELLS 8
  1035. typedef struct _MoveMapNode {
  1036. short adjCells[NUM_ADJ_CELLS];
  1037. long cost; // normal cost to travel here, based upon terrain
  1038. long parent; // where we came from (parent cell)
  1039. unsigned long flags; // CLOSED, OPEN, STEP flags
  1040. long g; // known cost from START to this node
  1041. long hPrime; // estimated cost from this node to GOAL
  1042. long fPrime; // = g + hPrime
  1043. void setFlag (unsigned long flag) {
  1044. flags |= flag;
  1045. }
  1046. void clearFlag (unsigned long flag) {
  1047. flags &= (flag ^ 0xFFFFFFFF);
  1048. }
  1049. } MoveMapNode;
  1050. typedef MoveMapNode* MoveMapNodePtr;
  1051. #define DISTANCE_TABLE_DIM 80
  1052. class MoveMap {
  1053. public:
  1054. long ULr; // upper-left cell row
  1055. long ULc; // upper-left cell col
  1056. long width;
  1057. long height;
  1058. long minRow;
  1059. long maxRow;
  1060. long minCol;
  1061. long maxCol;
  1062. long maxWidth;
  1063. long maxHeight;
  1064. MoveMapNodePtr map;
  1065. long* mapRowStartTable;
  1066. long* mapRowTable;
  1067. long* mapColTable;
  1068. long moveLevel;
  1069. Stuff::Vector3D start;
  1070. long startR;
  1071. long startC;
  1072. Stuff::Vector3D goal; // actual world-coord goal
  1073. long goalR; // cell goal row relative to move map
  1074. long goalC; // cell goal col relative to move map
  1075. long thruAreas[2];
  1076. long door;
  1077. long doorSide;
  1078. long doorDirection; // if goal is not a door, set to -1
  1079. Stuff::Vector3D target; // actual world-coord target
  1080. long clearCost; // cost, in tenths of secs, to move to clear cell
  1081. long jumpCost; // cost, in tenths of secs, to jump to cell
  1082. long numOffsets; // set by calcMovePath function (don't touch:)
  1083. float calcTime;
  1084. long* overlayWeightTable;
  1085. long moverWID;
  1086. long moverTeamID;
  1087. bool moverLayingMines;
  1088. bool moverWithdrawing;
  1089. bool travelOffMap;
  1090. bool cannotEnterOffMap;
  1091. void (*blockedDoorCallback) (long moveLevel, long door, char* openCells);
  1092. void (*placeStationaryMoversCallback) (MoveMapPtr map);
  1093. static float distanceFloat[DISTANCE_TABLE_DIM][DISTANCE_TABLE_DIM];
  1094. static long distanceLong[DISTANCE_TABLE_DIM][DISTANCE_TABLE_DIM];
  1095. static long forestCost;
  1096. protected:
  1097. bool adjacentCellOpen (long mapCellIndex, long dir);
  1098. bool adjacentCellOpenJUMP (long r, long c, long dir);
  1099. void propogateCost (long mapCellIndex, long cost, long g);
  1100. void propogateCostJUMP (long r, long c, long cost, long g);
  1101. long calcHPrime (long r, long c);
  1102. public:
  1103. void* operator new (size_t mySize);
  1104. void operator delete (void* us);
  1105. void init (void) {
  1106. ULr = 0;
  1107. ULc = 0;
  1108. maxHeight = 0;
  1109. maxWidth = 0;
  1110. height = 0;
  1111. width = 0;
  1112. minRow = 0;
  1113. maxRow = 0;
  1114. minCol = 0;
  1115. maxCol = 0;
  1116. map = NULL;
  1117. mapRowTable = NULL;
  1118. moveLevel = 0;
  1119. startR = -1;
  1120. startC = -1;
  1121. goalR = -1;
  1122. goalC = -1;
  1123. thruAreas[0] = -1;
  1124. thruAreas[1] = -1;
  1125. goal.Zero();
  1126. door = -1;
  1127. doorSide = -1;
  1128. doorDirection = -1;
  1129. target.x = -999999.0;
  1130. target.y = -999999.0;
  1131. target.z = -999999.0;
  1132. clearCost = 1;
  1133. jumpCost = 0;
  1134. numOffsets = 8;
  1135. calcTime = 0.0;
  1136. travelOffMap = false;
  1137. cannotEnterOffMap = true;
  1138. overlayWeightTable = NULL;
  1139. blockedDoorCallback = NULL;
  1140. placeStationaryMoversCallback = NULL;
  1141. }
  1142. MoveMap (void) {
  1143. init();
  1144. }
  1145. void destroy (void);
  1146. ~MoveMap (void) {
  1147. destroy();
  1148. }
  1149. void init (long h, long w);
  1150. long init (FitIniFile* mapFile);
  1151. long setUp (long ULr,
  1152. long ULc,
  1153. long height,
  1154. long width,
  1155. long moveLevel,
  1156. Stuff::Vector3D* startPos,
  1157. long startRow,
  1158. long startCol,
  1159. Stuff::Vector3D goalPos,
  1160. long goalRow,
  1161. long goalCol,
  1162. long clearCellCost,
  1163. long jumpCellCost,
  1164. long offsets,
  1165. unsigned long params = MOVEPARAM_NONE);
  1166. long setUp (long moveLevel,
  1167. Stuff::Vector3D* startPos,
  1168. long startRow,
  1169. long startCol,
  1170. long thruArea[2],
  1171. long goalDoor,
  1172. Stuff::Vector3D finalGoal,
  1173. long clearCellCost,
  1174. long jumpCellCost,
  1175. long offsets,
  1176. unsigned long params = MOVEPARAM_NONE);
  1177. void clear (void);
  1178. void placeMovers (bool stationaryOnly);
  1179. void setOverlayWeightTable (long* table) {
  1180. overlayWeightTable = table;
  1181. }
  1182. void setStart (Stuff::Vector3D* startPos, long startCellRow, long startCellCol);
  1183. void setGoal (Stuff::Vector3D goalPos, long goalCellRow, long goalCellCol);
  1184. void setGoal (long thruArea, long goalDoor);
  1185. long markGoals (Stuff::Vector3D finalGoal);
  1186. long markEscapeGoals (Stuff::Vector3D finalGoal);
  1187. void setTarget (Stuff::Vector3D targetPos);
  1188. char getCost (long row, long col) {
  1189. return(map[row * width + col].cost);
  1190. }
  1191. void setCost (long row, long col, long newCost);
  1192. void adjustCost (long row, long col, long costAdj) {
  1193. long index = row * width + col;
  1194. long cost = map[index].cost + costAdj;
  1195. if (cost < 1)
  1196. cost = 1;
  1197. map[index].cost = cost;
  1198. }
  1199. void setStart (long row, long col) {
  1200. startR = row;
  1201. startC = col;
  1202. }
  1203. void setClearCost (long cost) {
  1204. clearCost = cost;
  1205. }
  1206. void setJumpCost (long cost, long offsets = 8) {
  1207. jumpCost = cost;
  1208. numOffsets = offsets;
  1209. }
  1210. void setMover (long watchID, long teamID = 0, bool layingMines = false, bool withdrawing = false) {
  1211. moverWID = watchID;
  1212. moverTeamID = teamID;
  1213. moverLayingMines = layingMines;
  1214. moverWithdrawing = withdrawing;
  1215. }
  1216. long calcPath (MovePathPtr path, Stuff::Vector3D* goalWorldPos, long* goalCell);
  1217. long calcPathJUMP (MovePathPtr path, Stuff::Vector3D* goalWorldPos, long* goalCell);
  1218. long calcEscapePath (MovePathPtr path, Stuff::Vector3D* goalWorldPos, long* goalCell);
  1219. float getDistanceFloat (long rowDelta, long colDelta) {
  1220. return(distanceFloat[rowDelta][colDelta]);
  1221. }
  1222. float getDistanceLong (long rowDelta, long colDelta) {
  1223. return(distanceLong[rowDelta][colDelta]);
  1224. }
  1225. void writeDebug (File* debugFile);
  1226. bool inBounds (long row, long col) {
  1227. return((row >= minRow) && (row <= maxRow) && (col >= minCol) && (col <= maxCol));
  1228. }
  1229. };
  1230. //---------------------------------------------------------------------------
  1231. inline void MoveMap::setCost (long row, long col, long newCost) {
  1232. map[row * maxWidth + col].cost = newCost;
  1233. }
  1234. //---------------------------------------------------------------------------
  1235. void SaveMapCells (char* fileName, long height, long width, MissionMapCellInfo* mapData);
  1236. MissionMapCellInfo* LoadMapCells (char* fileName, long& height, long& width);
  1237. void DeleteMapCells (MissionMapCellInfo* mapData);
  1238. void MOVE_init (long moveRange);
  1239. void MOVE_buildData (long height, long width, MissionMapCellInfo* mapData, long numSpecialAreas, GameObjectFootPrint* specialAreaFootPrints);
  1240. long MOVE_saveData (PacketFile* packetFile, long whichPacket = 0);
  1241. long MOVE_readData (PacketFile* packetFile, long whichPacket);
  1242. void MOVE_cleanup (void);
  1243. //long BuildAndSaveMoveData (char* fileName, long height, long width, MissionMapCellInfo* mapData);
  1244. //***************************************************************************
  1245. extern MissionMapPtr GameMap;
  1246. extern GlobalMapPtr GlobalMoveMap[3];
  1247. extern MoveMapPtr PathFindMap[2];
  1248. extern long SimpleMovePathRange;
  1249. //***************************************************************************
  1250. #endif