MetaEvent.cpp 35 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726
  1. /*
  2. ** Command & Conquer Generals Zero Hour(tm)
  3. ** Copyright 2025 Electronic Arts Inc.
  4. **
  5. ** This program is free software: you can redistribute it and/or modify
  6. ** it under the terms of the GNU General Public License as published by
  7. ** the Free Software Foundation, either version 3 of the License, or
  8. ** (at your option) any later version.
  9. **
  10. ** This program is distributed in the hope that it will be useful,
  11. ** but WITHOUT ANY WARRANTY; without even the implied warranty of
  12. ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  13. ** GNU General Public License for more details.
  14. **
  15. ** You should have received a copy of the GNU General Public License
  16. ** along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. ////////////////////////////////////////////////////////////////////////////////
  19. // //
  20. // (c) 2001-2003 Electronic Arts Inc. //
  21. // //
  22. ////////////////////////////////////////////////////////////////////////////////
  23. // FILE: MetaEvent.cpp ////////////////////////////////////////////////////////////////////////////
  24. // Created: Colin Day, September 2001
  25. // Desc: Translating keystrokes into event command messages
  26. ///////////////////////////////////////////////////////////////////////////////////////////////////
  27. // INCLUDES ///////////////////////////////////////////////////////////////////////////////////////
  28. #include "PreRTS.h" // This must go first in EVERY cpp file int the GameEngine
  29. #include "Common/INI.h"
  30. #include "Common/MessageStream.h"
  31. #include "Common/Player.h"
  32. #include "Common/PlayerList.h"
  33. #include "Common/Team.h"
  34. #include "Common/ThingTemplate.h"
  35. #include "GameClient/Drawable.h"
  36. #include "GameClient/Mouse.h"
  37. #include "GameClient/GameClient.h"
  38. #include "GameClient/InGameUI.h"
  39. #include "GameClient/KeyDefs.h"
  40. #include "GameClient/ParticleSys.h" // for ParticleSystemDebugDisplay
  41. #include "GameClient/Shell.h"
  42. #include "GameClient/WindowLayout.h"
  43. #include "GameClient/GUICallbacks.h"
  44. #include "GameClient/DebugDisplay.h" // for AudioDebugDisplay
  45. #include "GameClient/GameText.h"
  46. #include "GameClient/MetaEvent.h"
  47. #include "GameLogic/GameLogic.h" // for TheGameLogic->getFrame()
  48. #define dont_DUMP_ALL_KEYS_TO_LOG
  49. #ifdef DUMP_ALL_KEYS_TO_LOG
  50. #include "GameClient\Keyboard.h"
  51. #endif
  52. MetaMap *TheMetaMap = NULL;
  53. #ifdef _INTERNAL
  54. // for occasional debugging...
  55. //#pragma optimize("", off)
  56. //#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  57. #endif
  58. // DEFINES ////////////////////////////////////////////////////////////////////
  59. // PRIVATE TYPES //////////////////////////////////////////////////////////////////////////////////
  60. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  61. static const LookupListRec GameMessageMetaTypeNames[] =
  62. {
  63. { "SAVE_VIEW1", GameMessage::MSG_META_SAVE_VIEW1 },
  64. { "SAVE_VIEW2", GameMessage::MSG_META_SAVE_VIEW2 },
  65. { "SAVE_VIEW3", GameMessage::MSG_META_SAVE_VIEW3 },
  66. { "SAVE_VIEW4", GameMessage::MSG_META_SAVE_VIEW4 },
  67. { "SAVE_VIEW5", GameMessage::MSG_META_SAVE_VIEW5 },
  68. { "SAVE_VIEW6", GameMessage::MSG_META_SAVE_VIEW6 },
  69. { "SAVE_VIEW7", GameMessage::MSG_META_SAVE_VIEW7 },
  70. { "SAVE_VIEW8", GameMessage::MSG_META_SAVE_VIEW8 },
  71. { "VIEW_VIEW1", GameMessage::MSG_META_VIEW_VIEW1 },
  72. { "VIEW_VIEW2", GameMessage::MSG_META_VIEW_VIEW2 },
  73. { "VIEW_VIEW3", GameMessage::MSG_META_VIEW_VIEW3 },
  74. { "VIEW_VIEW4", GameMessage::MSG_META_VIEW_VIEW4 },
  75. { "VIEW_VIEW5", GameMessage::MSG_META_VIEW_VIEW5 },
  76. { "VIEW_VIEW6", GameMessage::MSG_META_VIEW_VIEW6 },
  77. { "VIEW_VIEW7", GameMessage::MSG_META_VIEW_VIEW7 },
  78. { "VIEW_VIEW8", GameMessage::MSG_META_VIEW_VIEW8 },
  79. { "CREATE_TEAM0", GameMessage::MSG_META_CREATE_TEAM0 },
  80. { "CREATE_TEAM1", GameMessage::MSG_META_CREATE_TEAM1 },
  81. { "CREATE_TEAM2", GameMessage::MSG_META_CREATE_TEAM2 },
  82. { "CREATE_TEAM3", GameMessage::MSG_META_CREATE_TEAM3 },
  83. { "CREATE_TEAM4", GameMessage::MSG_META_CREATE_TEAM4 },
  84. { "CREATE_TEAM5", GameMessage::MSG_META_CREATE_TEAM5 },
  85. { "CREATE_TEAM6", GameMessage::MSG_META_CREATE_TEAM6 },
  86. { "CREATE_TEAM7", GameMessage::MSG_META_CREATE_TEAM7 },
  87. { "CREATE_TEAM8", GameMessage::MSG_META_CREATE_TEAM8 },
  88. { "CREATE_TEAM9", GameMessage::MSG_META_CREATE_TEAM9 },
  89. { "SELECT_TEAM0", GameMessage::MSG_META_SELECT_TEAM0 },
  90. { "SELECT_TEAM1", GameMessage::MSG_META_SELECT_TEAM1 },
  91. { "SELECT_TEAM2", GameMessage::MSG_META_SELECT_TEAM2 },
  92. { "SELECT_TEAM3", GameMessage::MSG_META_SELECT_TEAM3 },
  93. { "SELECT_TEAM4", GameMessage::MSG_META_SELECT_TEAM4 },
  94. { "SELECT_TEAM5", GameMessage::MSG_META_SELECT_TEAM5 },
  95. { "SELECT_TEAM6", GameMessage::MSG_META_SELECT_TEAM6 },
  96. { "SELECT_TEAM7", GameMessage::MSG_META_SELECT_TEAM7 },
  97. { "SELECT_TEAM8", GameMessage::MSG_META_SELECT_TEAM8 },
  98. { "SELECT_TEAM9", GameMessage::MSG_META_SELECT_TEAM9 },
  99. { "ADD_TEAM0", GameMessage::MSG_META_ADD_TEAM0 },
  100. { "ADD_TEAM1", GameMessage::MSG_META_ADD_TEAM1 },
  101. { "ADD_TEAM2", GameMessage::MSG_META_ADD_TEAM2 },
  102. { "ADD_TEAM3", GameMessage::MSG_META_ADD_TEAM3 },
  103. { "ADD_TEAM4", GameMessage::MSG_META_ADD_TEAM4 },
  104. { "ADD_TEAM5", GameMessage::MSG_META_ADD_TEAM5 },
  105. { "ADD_TEAM6", GameMessage::MSG_META_ADD_TEAM6 },
  106. { "ADD_TEAM7", GameMessage::MSG_META_ADD_TEAM7 },
  107. { "ADD_TEAM8", GameMessage::MSG_META_ADD_TEAM8 },
  108. { "ADD_TEAM9", GameMessage::MSG_META_ADD_TEAM9 },
  109. { "VIEW_TEAM0", GameMessage::MSG_META_VIEW_TEAM0 },
  110. { "VIEW_TEAM1", GameMessage::MSG_META_VIEW_TEAM1 },
  111. { "VIEW_TEAM2", GameMessage::MSG_META_VIEW_TEAM2 },
  112. { "VIEW_TEAM3", GameMessage::MSG_META_VIEW_TEAM3 },
  113. { "VIEW_TEAM4", GameMessage::MSG_META_VIEW_TEAM4 },
  114. { "VIEW_TEAM5", GameMessage::MSG_META_VIEW_TEAM5 },
  115. { "VIEW_TEAM6", GameMessage::MSG_META_VIEW_TEAM6 },
  116. { "VIEW_TEAM7", GameMessage::MSG_META_VIEW_TEAM7 },
  117. { "VIEW_TEAM8", GameMessage::MSG_META_VIEW_TEAM8 },
  118. { "VIEW_TEAM9", GameMessage::MSG_META_VIEW_TEAM9 },
  119. { "SELECT_MATCHING_UNITS", GameMessage::MSG_META_SELECT_MATCHING_UNITS },
  120. { "SELECT_NEXT_UNIT", GameMessage::MSG_META_SELECT_NEXT_UNIT },
  121. { "SELECT_PREV_UNIT", GameMessage::MSG_META_SELECT_PREV_UNIT },
  122. { "SELECT_NEXT_WORKER", GameMessage::MSG_META_SELECT_NEXT_WORKER },
  123. { "SELECT_PREV_WORKER", GameMessage::MSG_META_SELECT_PREV_WORKER },
  124. { "SELECT_HERO", GameMessage::MSG_META_SELECT_HERO },
  125. { "SELECT_ALL", GameMessage::MSG_META_SELECT_ALL },
  126. { "SELECT_ALL_AIRCRAFT", GameMessage::MSG_META_SELECT_ALL_AIRCRAFT },
  127. { "VIEW_COMMAND_CENTER", GameMessage::MSG_META_VIEW_COMMAND_CENTER },
  128. { "VIEW_LAST_RADAR_EVENT", GameMessage::MSG_META_VIEW_LAST_RADAR_EVENT },
  129. { "SCATTER", GameMessage::MSG_META_SCATTER },
  130. { "STOP", GameMessage::MSG_META_STOP },
  131. { "DEPLOY", GameMessage::MSG_META_DEPLOY },
  132. { "CREATE_FORMATION", GameMessage::MSG_META_CREATE_FORMATION },
  133. { "FOLLOW", GameMessage::MSG_META_FOLLOW },
  134. { "CHAT_PLAYERS", GameMessage::MSG_META_CHAT_PLAYERS },
  135. { "CHAT_ALLIES", GameMessage::MSG_META_CHAT_ALLIES },
  136. { "CHAT_EVERYONE", GameMessage::MSG_META_CHAT_EVERYONE },
  137. { "DIPLOMACY", GameMessage::MSG_META_DIPLOMACY },
  138. { "PLACE_BEACON", GameMessage::MSG_META_PLACE_BEACON },
  139. { "DELETE_BEACON", GameMessage::MSG_META_REMOVE_BEACON },
  140. { "OPTIONS", GameMessage::MSG_META_OPTIONS },
  141. { "TOGGLE_LOWER_DETAILS", GameMessage::MSG_META_TOGGLE_LOWER_DETAILS },
  142. { "TOGGLE_CONTROL_BAR", GameMessage::MSG_META_TOGGLE_CONTROL_BAR },
  143. { "BEGIN_PATH_BUILD", GameMessage::MSG_META_BEGIN_PATH_BUILD },
  144. { "END_PATH_BUILD", GameMessage::MSG_META_END_PATH_BUILD },
  145. { "BEGIN_FORCEATTACK", GameMessage::MSG_META_BEGIN_FORCEATTACK },
  146. { "END_FORCEATTACK", GameMessage::MSG_META_END_FORCEATTACK },
  147. { "BEGIN_FORCEMOVE", GameMessage::MSG_META_BEGIN_FORCEMOVE },
  148. { "END_FORCEMOVE", GameMessage::MSG_META_END_FORCEMOVE },
  149. { "BEGIN_WAYPOINTS", GameMessage::MSG_META_BEGIN_WAYPOINTS },
  150. { "END_WAYPOINTS", GameMessage::MSG_META_END_WAYPOINTS },
  151. { "BEGIN_PREFER_SELECTION", GameMessage::MSG_META_BEGIN_PREFER_SELECTION },
  152. { "END_PREFER_SELECTION", GameMessage::MSG_META_END_PREFER_SELECTION },
  153. { "TAKE_SCREENSHOT", GameMessage::MSG_META_TAKE_SCREENSHOT },
  154. { "ALL_CHEER", GameMessage::MSG_META_ALL_CHEER },
  155. { "BEGIN_CAMERA_ROTATE_LEFT", GameMessage::MSG_META_BEGIN_CAMERA_ROTATE_LEFT },
  156. { "END_CAMERA_ROTATE_LEFT", GameMessage::MSG_META_END_CAMERA_ROTATE_LEFT },
  157. { "BEGIN_CAMERA_ROTATE_RIGHT", GameMessage::MSG_META_BEGIN_CAMERA_ROTATE_RIGHT },
  158. { "END_CAMERA_ROTATE_RIGHT", GameMessage::MSG_META_END_CAMERA_ROTATE_RIGHT },
  159. { "BEGIN_CAMERA_ZOOM_IN", GameMessage::MSG_META_BEGIN_CAMERA_ZOOM_IN },
  160. { "END_CAMERA_ZOOM_IN", GameMessage::MSG_META_END_CAMERA_ZOOM_IN },
  161. { "BEGIN_CAMERA_ZOOM_OUT", GameMessage::MSG_META_BEGIN_CAMERA_ZOOM_OUT },
  162. { "END_CAMERA_ZOOM_OUT", GameMessage::MSG_META_END_CAMERA_ZOOM_OUT },
  163. { "CAMERA_RESET", GameMessage::MSG_META_CAMERA_RESET },
  164. { "TOGGLE_CAMERA_TRACKING_DRAWABLE", GameMessage::MSG_META_TOGGLE_CAMERA_TRACKING_DRAWABLE },
  165. { "TOGGLE_FAST_FORWARD_REPLAY", GameMessage::MSG_META_TOGGLE_FAST_FORWARD_REPLAY },
  166. { "DEMO_INSTANT_QUIT", GameMessage::MSG_META_DEMO_INSTANT_QUIT },
  167. #if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)//may be defined in GameCommon.h
  168. { "CHEAT_RUNSCRIPT1", GameMessage::MSG_CHEAT_RUNSCRIPT1 },
  169. { "CHEAT_RUNSCRIPT2", GameMessage::MSG_CHEAT_RUNSCRIPT2 },
  170. { "CHEAT_RUNSCRIPT3", GameMessage::MSG_CHEAT_RUNSCRIPT3 },
  171. { "CHEAT_RUNSCRIPT4", GameMessage::MSG_CHEAT_RUNSCRIPT4 },
  172. { "CHEAT_RUNSCRIPT5", GameMessage::MSG_CHEAT_RUNSCRIPT5 },
  173. { "CHEAT_RUNSCRIPT6", GameMessage::MSG_CHEAT_RUNSCRIPT6 },
  174. { "CHEAT_RUNSCRIPT7", GameMessage::MSG_CHEAT_RUNSCRIPT7 },
  175. { "CHEAT_RUNSCRIPT8", GameMessage::MSG_CHEAT_RUNSCRIPT8 },
  176. { "CHEAT_RUNSCRIPT9", GameMessage::MSG_CHEAT_RUNSCRIPT9 },
  177. { "CHEAT_TOGGLE_SPECIAL_POWER_DELAYS", GameMessage::MSG_CHEAT_TOGGLE_SPECIAL_POWER_DELAYS },
  178. { "CHEAT_SWITCH_TEAMS", GameMessage::MSG_CHEAT_SWITCH_TEAMS },
  179. { "CHEAT_KILL_SELECTION", GameMessage::MSG_CHEAT_KILL_SELECTION },
  180. { "CHEAT_TOGGLE_HAND_OF_GOD_MODE", GameMessage::MSG_CHEAT_TOGGLE_HAND_OF_GOD_MODE },
  181. { "CHEAT_INSTANT_BUILD", GameMessage::MSG_CHEAT_INSTANT_BUILD },
  182. { "CHEAT_DESHROUD", GameMessage::MSG_CHEAT_DESHROUD },
  183. { "CHEAT_ADD_CASH", GameMessage::MSG_CHEAT_ADD_CASH },
  184. { "CHEAT_GIVE_ALL_SCIENCES", GameMessage::MSG_CHEAT_GIVE_ALL_SCIENCES },
  185. { "CHEAT_GIVE_SCIENCEPURCHASEPOINTS", GameMessage::MSG_CHEAT_GIVE_SCIENCEPURCHASEPOINTS },
  186. { "CHEAT_SHOW_HEALTH", GameMessage::MSG_CHEAT_SHOW_HEALTH },
  187. { "CHEAT_TOGGLE_MESSAGE_TEXT", GameMessage::MSG_CHEAT_TOGGLE_MESSAGE_TEXT },
  188. #endif
  189. #if defined(_DEBUG) || defined(_INTERNAL)
  190. { "HELP", GameMessage::MSG_META_HELP },
  191. { "DEMO_TOGGLE_BEHIND_BUILDINGS", GameMessage::MSG_META_DEMO_TOGGLE_BEHIND_BUILDINGS },
  192. { "DEMO_LOD_DECREASE", GameMessage::MSG_META_DEMO_LOD_DECREASE },
  193. { "DEMO_LOD_INCREASE", GameMessage::MSG_META_DEMO_LOD_INCREASE },
  194. { "DEMO_TOGGLE_LETTERBOX", GameMessage::MSG_META_DEMO_TOGGLE_LETTERBOX },
  195. { "DEMO_TOGGLE_MESSAGE_TEXT", GameMessage::MSG_META_DEMO_TOGGLE_MESSAGE_TEXT },
  196. { "DEMO_GIVE_ALL_SCIENCES", GameMessage::MSG_META_DEMO_GIVE_ALL_SCIENCES },
  197. { "DEMO_GIVE_RANKLEVEL", GameMessage::MSG_META_DEMO_GIVE_RANKLEVEL },
  198. { "DEMO_TAKE_RANKLEVEL", GameMessage::MSG_META_DEMO_TAKE_RANKLEVEL },
  199. { "DEMO_GIVE_SCIENCEPURCHASEPOINTS", GameMessage::MSG_META_DEMO_GIVE_SCIENCEPURCHASEPOINTS },
  200. { "DEMO_SWITCH_TEAMS", GameMessage::MSG_META_DEMO_SWITCH_TEAMS },
  201. { "DEMO_SWITCH_TEAMS_CHINA_USA", GameMessage::MSG_META_DEMO_SWITCH_TEAMS_BETWEEN_CHINA_USA },
  202. { "DEMO_TOGGLE_CASHMAPDEBUG", GameMessage::MSG_META_DEMO_TOGGLE_CASHMAPDEBUG },
  203. { "DEMO_TOGGLE_GRAPHICALFRAMERATEBAR", GameMessage::MSG_META_DEMO_TOGGLE_GRAPHICALFRAMERATEBAR },
  204. { "DEMO_TOGGLE_PARTICLEDEBUG", GameMessage::MSG_META_DEMO_TOGGLE_PARTICLEDEBUG },
  205. { "DEMO_TOGGLE_THREATDEBUG", GameMessage::MSG_META_DEMO_TOGGLE_THREATDEBUG },
  206. { "DEMO_TOGGLE_VISIONDEBUG", GameMessage::MSG_META_DEMO_TOGGLE_VISIONDEBUG },
  207. { "DEMO_TOGGLE_PROJECTILEDEBUG", GameMessage::MSG_META_DEMO_TOGGLE_PROJECTILEDEBUG },
  208. { "DEMO_LOD_DECREASE", GameMessage::MSG_META_DEMO_LOD_DECREASE },
  209. { "DEMO_LOD_INCREASE", GameMessage::MSG_META_DEMO_LOD_INCREASE },
  210. { "DEMO_TOGGLE_SHADOW_VOLUMES", GameMessage::MSG_META_DEMO_TOGGLE_SHADOW_VOLUMES },
  211. { "DEMO_TOGGLE_FOGOFWAR", GameMessage::MSG_META_DEMO_TOGGLE_FOGOFWAR },
  212. { "DEMO_KILL_ALL_ENEMIES", GameMessage::MSG_META_DEMO_KILL_ALL_ENEMIES },
  213. { "DEMO_KILL_SELECTION", GameMessage::MSG_META_DEMO_KILL_SELECTION },
  214. { "DEMO_TOGGLE_HURT_ME_MODE", GameMessage::MSG_META_DEMO_TOGGLE_HURT_ME_MODE },
  215. { "DEMO_TOGGLE_HAND_OF_GOD_MODE", GameMessage::MSG_META_DEMO_TOGGLE_HAND_OF_GOD_MODE },
  216. { "DEMO_DEBUG_SELECTION", GameMessage::MSG_META_DEMO_DEBUG_SELECTION },
  217. { "DEMO_LOCK_CAMERA_TO_SELECTION", GameMessage::MSG_META_DEMO_LOCK_CAMERA_TO_SELECTION },
  218. { "DEMO_TOGGLE_SOUND", GameMessage::MSG_META_DEMO_TOGGLE_SOUND },
  219. { "DEMO_TOGGLE_TRACKMARKS", GameMessage::MSG_META_DEMO_TOGGLE_TRACKMARKS },
  220. { "DEMO_TOGGLE_WATERPLANE", GameMessage::MSG_META_DEMO_TOGGLE_WATERPLANE },
  221. { "DEMO_TIME_OF_DAY", GameMessage::MSG_META_DEMO_TIME_OF_DAY },
  222. { "DEMO_TOGGLE_MILITARY_SUBTITLES", GameMessage::MSG_META_DEMO_TOGGLE_MILITARY_SUBTITLES },
  223. { "DEMO_TOGGLE_MUSIC", GameMessage::MSG_META_DEMO_TOGGLE_MUSIC },
  224. { "DEMO_MUSIC_NEXT_TRACK", GameMessage::MSG_META_DEMO_MUSIC_NEXT_TRACK },
  225. { "DEMO_MUSIC_PREV_TRACK", GameMessage::MSG_META_DEMO_MUSIC_PREV_TRACK },
  226. { "DEMO_NEXT_OBJECTIVE_MOVIE", GameMessage::MSG_META_DEMO_NEXT_OBJECTIVE_MOVIE },
  227. { "DEMO_PLAY_OBJECTIVE_MOVIE1", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE1 },
  228. { "DEMO_PLAY_OBJECTIVE_MOVIE2", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE2 },
  229. { "DEMO_PLAY_OBJECTIVE_MOVIE3", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE3 },
  230. { "DEMO_PLAY_OBJECTIVE_MOVIE4", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE4 },
  231. { "DEMO_PLAY_OBJECTIVE_MOVIE5", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE5 },
  232. { "DEMO_PLAY_OBJECTIVE_MOVIE6", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE6 },
  233. { "DEMO_BEGIN_ADJUST_PITCH", GameMessage::MSG_META_DEMO_BEGIN_ADJUST_PITCH },
  234. { "DEMO_END_ADJUST_PITCH", GameMessage::MSG_META_DEMO_END_ADJUST_PITCH },
  235. { "DEMO_BEGIN_ADJUST_FOV", GameMessage::MSG_META_DEMO_BEGIN_ADJUST_FOV },
  236. { "DEMO_END_ADJUST_FOV", GameMessage::MSG_META_DEMO_END_ADJUST_FOV },
  237. { "DEMO_LOCK_CAMERA_TO_PLANES", GameMessage::MSG_META_DEMO_LOCK_CAMERA_TO_PLANES },
  238. { "DEMO_REMOVE_PREREQ", GameMessage::MSG_META_DEMO_REMOVE_PREREQ },
  239. { "DEMO_RUNSCRIPT1", GameMessage::MSG_META_DEMO_RUNSCRIPT1 },
  240. { "DEMO_RUNSCRIPT2", GameMessage::MSG_META_DEMO_RUNSCRIPT2 },
  241. { "DEMO_RUNSCRIPT3", GameMessage::MSG_META_DEMO_RUNSCRIPT3 },
  242. { "DEMO_RUNSCRIPT4", GameMessage::MSG_META_DEMO_RUNSCRIPT4 },
  243. { "DEMO_RUNSCRIPT5", GameMessage::MSG_META_DEMO_RUNSCRIPT5 },
  244. { "DEMO_RUNSCRIPT6", GameMessage::MSG_META_DEMO_RUNSCRIPT6 },
  245. { "DEMO_RUNSCRIPT7", GameMessage::MSG_META_DEMO_RUNSCRIPT7 },
  246. { "DEMO_RUNSCRIPT8", GameMessage::MSG_META_DEMO_RUNSCRIPT8 },
  247. { "DEMO_RUNSCRIPT9", GameMessage::MSG_META_DEMO_RUNSCRIPT9 },
  248. { "DEMO_ADDCASH", GameMessage::MSG_META_DEMO_ADD_CASH },
  249. { "DEMO_TOGGLE_RENDER", GameMessage::MSG_META_DEMO_TOGGLE_RENDER },
  250. { "DEMO_TOGGLE_BW_VIEW", GameMessage::MSG_META_DEMO_TOGGLE_BW_VIEW },
  251. { "DEMO_TOGGLE_RED_VIEW", GameMessage::MSG_META_DEMO_TOGGLE_RED_VIEW },
  252. { "DEMO_TOGGLE_GREEN_VIEW", GameMessage::MSG_META_DEMO_TOGGLE_GREEN_VIEW },
  253. { "DEMO_TOGGLE_MOTION_BLUR_ZOOM", GameMessage::MSG_META_DEMO_TOGGLE_MOTION_BLUR_ZOOM },
  254. { "DEMO_SHOW_EXTENTS", GameMessage::MSG_META_DEBUG_SHOW_EXTENTS },
  255. { "DEMO_SHOW_AUDIO_LOCATIONS", GameMessage::MSG_META_DEBUG_SHOW_AUDIO_LOCATIONS },
  256. { "DEMO_SHOW_HEALTH", GameMessage::MSG_META_DEBUG_SHOW_HEALTH },
  257. { "DEMO_GIVE_VETERANCY", GameMessage::MSG_META_DEBUG_GIVE_VETERANCY },
  258. { "DEMO_TAKE_VETERANCY", GameMessage::MSG_META_DEBUG_TAKE_VETERANCY },
  259. { "DEMO_BATTLE_CRY", GameMessage::MSG_META_DEMO_BATTLE_CRY },
  260. #ifdef ALLOW_SURRENDER
  261. { "DEMO_TEST_SURRENDER", GameMessage::MSG_META_DEMO_TEST_SURRENDER },
  262. #endif
  263. { "DEMO_TOGGLE_AVI", GameMessage::MSG_META_DEMO_TOGGLE_AVI },
  264. { "DEMO_PLAY_CAMEO_MOVIE", GameMessage::MSG_META_DEMO_PLAY_CAMEO_MOVIE },
  265. { "DEMO_TOGGLE_ZOOM_LOCK", GameMessage::MSG_META_DEMO_TOGGLE_ZOOM_LOCK },
  266. { "DEMO_TOGGLE_SPECIAL_POWER_DELAYS", GameMessage::MSG_META_DEMO_TOGGLE_SPECIAL_POWER_DELAYS },
  267. { "DEMO_TOGGLE_METRICS", GameMessage::MSG_META_DEMO_TOGGLE_METRICS},
  268. { "DEMO_DESHROUD", GameMessage::MSG_META_DEMO_DESHROUD },
  269. { "DEMO_ENSHROUD", GameMessage::MSG_META_DEMO_ENSHROUD },
  270. { "DEMO_TOGGLE_AI_DEBUG", GameMessage::MSG_META_DEMO_TOGGLE_AI_DEBUG },
  271. { "DEMO_TOGGLE_SUPPLY_CENTER_PLACEMENT", GameMessage::MSG_META_DEMO_TOGGLE_SUPPLY_CENTER_PLACEMENT },
  272. { "DEMO_TOGGLE_NO_DRAW", GameMessage::MSG_NO_DRAW },
  273. { "DEMO_CYCLE_LOD_LEVEL", GameMessage::MSG_META_DEMO_CYCLE_LOD_LEVEL },
  274. { "DEMO_DUMP_ASSETS", GameMessage::MSG_META_DEBUG_DUMP_ASSETS},
  275. { "DEMO_INSTANT_BUILD", GameMessage::MSG_META_DEMO_INSTANT_BUILD },
  276. { "DEMO_TOGGLE_CAMERA_DEBUG", GameMessage::MSG_META_DEMO_TOGGLE_CAMERA_DEBUG },
  277. /// Begin VTUNE
  278. { "DEMO_VTUNE_ON", GameMessage::MSG_META_DEBUG_VTUNE_ON },
  279. { "DEMO_VTUNE_OFF", GameMessage::MSG_META_DEBUG_VTUNE_OFF },
  280. /// End VTUNE
  281. //lorenzen's feather water
  282. { "DEMO_TOGGLE_FEATHER_WATER", GameMessage::MSG_META_DEBUG_TOGGLE_FEATHER_WATER },
  283. { "DEMO_INCR_ANIM_SKATE_SPEED", GameMessage::MSG_META_DEBUG_INCR_ANIM_SKATE_SPEED },
  284. { "DEMO_DECR_ANIM_SKATE_SPEED", GameMessage::MSG_META_DEBUG_DECR_ANIM_SKATE_SPEED },
  285. { "DEMO_CYCLE_EXTENT_TYPE", GameMessage::MSG_META_DEBUG_CYCLE_EXTENT_TYPE },
  286. { "DEMO_INCR_EXTENT_MAJOR", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MAJOR },
  287. { "DEMO_DECR_EXTENT_MAJOR", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MAJOR },
  288. { "DEMO_INCR_EXTENT_MAJOR_LARGE", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MAJOR_BIG },
  289. { "DEMO_DECR_EXTENT_MAJOR_LARGE", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MAJOR_BIG },
  290. { "DEMO_INCR_EXTENT_MINOR", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MINOR },
  291. { "DEMO_DECR_EXTENT_MINOR", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MINOR },
  292. { "DEMO_INCR_EXTENT_MINOR_LARGE", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MINOR_BIG },
  293. { "DEMO_DECR_EXTENT_MINOR_LARGE", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MINOR_BIG },
  294. { "DEMO_INCR_EXTENT_HEIGHT", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_HEIGHT },
  295. { "DEMO_DECR_EXTENT_HEIGHT", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_HEIGHT },
  296. { "DEMO_INCR_EXTENT_HEIGHT_LARGE", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_HEIGHT_BIG },
  297. { "DEMO_DECR_EXTENT_HEIGHT_LARGE", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_HEIGHT_BIG },
  298. { "DEMO_TOGGLE_NETWORK", GameMessage::MSG_META_DEBUG_TOGGLE_NETWORK },
  299. { "DEBUG_DUMP_PLAYER_OBJECTS", GameMessage::MSG_META_DEBUG_DUMP_PLAYER_OBJECTS },
  300. { "DEBUG_DUMP_ALL_PLAYER_OBJECTS", GameMessage::MSG_META_DEBUG_DUMP_ALL_PLAYER_OBJECTS },
  301. { "DEMO_WIN", GameMessage::MSG_META_DEBUG_WIN },
  302. { "DEMO_TOGGLE_DEBUG_STATS", GameMessage::MSG_META_DEMO_TOGGLE_DEBUG_STATS },
  303. { "DEBUG_OBJECT_ID_PERFORMANCE", GameMessage::MSG_META_DEBUG_OBJECT_ID_PERFORMANCE },
  304. { "DEBUG_DRAWABLE_ID_PERFORMANCE", GameMessage::MSG_META_DEBUG_DRAWABLE_ID_PERFORMANCE },
  305. { "DEBUG_SLEEPY_UPDATE_PERFORMANCE", GameMessage::MSG_META_DEBUG_SLEEPY_UPDATE_PERFORMANCE },
  306. #endif // defined(_DEBUG) || defined(_INTERNAL)
  307. #if defined(_INTERNAL) || defined(_DEBUG)
  308. { "DEMO_TOGGLE_AUDIODEBUG", GameMessage::MSG_META_DEMO_TOGGLE_AUDIODEBUG },
  309. #endif//defined(_INTERNAL) || defined(_DEBUG)
  310. #ifdef DUMP_PERF_STATS
  311. { "DEMO_PERFORM_STATISTICAL_DUMP", GameMessage::MSG_META_DEMO_PERFORM_STATISTICAL_DUMP },
  312. #endif//DUMP_PERF_STATS
  313. { NULL, 0 }// keep this last!
  314. };
  315. ///////////////////////////////////////////////////////////////////////////////////////////////////
  316. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  317. ///////////////////////////////////////////////////////////////////////////////////////////////////
  318. static const FieldParse TheMetaMapFieldParseTable[] =
  319. {
  320. { "Key", INI::parseLookupList, KeyNames, offsetof( MetaMapRec, m_key ) },
  321. { "Transition", INI::parseLookupList, TransitionNames, offsetof( MetaMapRec, m_transition ) },
  322. { "Modifiers", INI::parseLookupList, ModifierNames, offsetof( MetaMapRec, m_modState ) },
  323. { "UseableIn", INI::parseBitString32, TheCommandUsableInNames, offsetof( MetaMapRec, m_usableIn ) },
  324. { "Category", INI::parseLookupList, CategoryListName, offsetof( MetaMapRec, m_category ) },
  325. { "Description", INI::parseAndTranslateLabel, 0, offsetof( MetaMapRec, m_description ) },
  326. { "DisplayName", INI::parseAndTranslateLabel, 0, offsetof( MetaMapRec, m_displayName ) },
  327. { NULL, NULL, 0, 0 } // keep this last
  328. };
  329. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////////////////////////
  330. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  331. //-------------------------------------------------------------------------------------------------
  332. MetaEventTranslator::MetaEventTranslator() :
  333. m_lastKeyDown(MK_NONE),
  334. m_lastModState(0)
  335. {
  336. for (Int i = 0; i < NUM_MOUSE_BUTTONS; ++i) {
  337. m_nextUpShouldCreateDoubleClick[i] = FALSE;
  338. }
  339. }
  340. //-------------------------------------------------------------------------------------------------
  341. MetaEventTranslator::~MetaEventTranslator()
  342. {
  343. }
  344. //-------------------------------------------------------------------------------------------------
  345. static const char * findGameMessageNameByType(GameMessage::Type type)
  346. {
  347. for (const LookupListRec* metaNames = GameMessageMetaTypeNames; metaNames->name; metaNames++)
  348. if (metaNames->value == (Int)type)
  349. return metaNames->name;
  350. DEBUG_CRASH(("MetaTypeName %d not found -- did you remember to add it to GameMessageMetaTypeNames[] ?\n"));
  351. return "???";
  352. }
  353. //-------------------------------------------------------------------------------------------------
  354. GameMessageDisposition MetaEventTranslator::translateGameMessage(const GameMessage *msg)
  355. {
  356. GameMessageDisposition disp = KEEP_MESSAGE;
  357. GameMessage::Type t = msg->getType();
  358. if (t == GameMessage::MSG_RAW_KEY_DOWN || t == GameMessage::MSG_RAW_KEY_UP)
  359. {
  360. MappableKeyType key = (MappableKeyType)msg->getArgument(0)->integer;
  361. Int keyState = msg->getArgument(1)->integer;
  362. // for our purposes here, we don't care to distinguish between right and left keys,
  363. // so just fudge a little to simplify things.
  364. Int newModState = 0;
  365. if( keyState & KEY_STATE_CONTROL )
  366. {
  367. newModState |= CTRL;
  368. }
  369. if( keyState & KEY_STATE_SHIFT )
  370. {
  371. newModState |= SHIFT;
  372. }
  373. if( keyState & KEY_STATE_ALT )
  374. {
  375. newModState |= ALT;
  376. }
  377. for (const MetaMapRec *map = TheMetaMap->getFirstMetaMapRec(); map; map = map->m_next)
  378. {
  379. DEBUG_ASSERTCRASH(map->m_meta > GameMessage::MSG_BEGIN_META_MESSAGES &&
  380. map->m_meta < GameMessage::MSG_END_META_MESSAGES, ("hmm, expected only meta-msgs here"));
  381. //
  382. // if this command is *only* usable in the game, we will ignore it if the game client
  383. // has not yet incremented to frame 1 (keeps us from doing in-game commands during
  384. // a map load, which throws the input system into wack because there isn't a
  385. // client frame for the input event, and in the case of a command that pauses the
  386. // game, like the quit menu, the client frame will never get beyond 0 and we
  387. // lose the ability to process any input
  388. //
  389. if( map->m_usableIn == COMMANDUSABLE_GAME && TheGameClient->getFrame() < 1 )
  390. continue;
  391. // if the shell is active, and this command is not usable in shell, continue
  392. if (TheShell && TheShell->isShellActive() && !(map->m_usableIn & COMMANDUSABLE_SHELL) )
  393. continue;
  394. // if the shell is not active and this command is not usable in the game, continue
  395. if (TheShell && !TheShell->isShellActive() && !(map->m_usableIn & COMMANDUSABLE_GAME) )
  396. continue;
  397. // check for the special case of mods-only-changed.
  398. if (
  399. map->m_key == MK_NONE &&
  400. newModState != m_lastModState &&
  401. (
  402. (map->m_transition == UP && map->m_modState == m_lastModState) ||
  403. (map->m_transition == DOWN && map->m_modState == newModState)
  404. )
  405. )
  406. {
  407. //DEBUG_LOG(("Frame %d: MetaEventTranslator::translateGameMessage() Mods-only change: %s\n", TheGameLogic->getFrame(), findGameMessageNameByType(map->m_meta)));
  408. /*GameMessage *metaMsg =*/ TheMessageStream->appendMessage(map->m_meta);
  409. disp = DESTROY_MESSAGE;
  410. break;
  411. }
  412. // ok, now check for "normal" key transitions.
  413. if (
  414. map->m_key == key &&
  415. map->m_modState == newModState &&
  416. (
  417. (map->m_transition == UP && (keyState & KEY_STATE_UP)) ||
  418. (map->m_transition == DOWN && (keyState & KEY_STATE_DOWN)) //||
  419. //(map->m_transition == DOUBLEDOWN && (keyState & KEY_STATE_DOWN) && m_lastKeyDown == key)
  420. )
  421. )
  422. {
  423. if( keyState & KEY_STATE_AUTOREPEAT )
  424. {
  425. // if it's an autorepeat of a "known" key, don't generate the meta-event,
  426. // but DO eat the keystroke so no one else can mess with it
  427. //DEBUG_LOG(("Frame %d: MetaEventTranslator::translateGameMessage() auto-repeat: %s\n", TheGameLogic->getFrame(), findGameMessageNameByType(map->m_meta)));
  428. }
  429. else
  430. {
  431. // THIS IS A GREASY HACK... MESSAGE SHOULD BE HANDLED IN A TRANSLATOR, BUT DURING CINEMATICS THE TRANSLATOR IS DISABLED
  432. if( map->m_meta == GameMessage::MSG_META_TOGGLE_FAST_FORWARD_REPLAY)
  433. {
  434. #if defined(_ALLOW_DEBUG_CHEATS_IN_RELEASE)//may be defined in GameCommon.h
  435. if( TheGlobalData )
  436. #else
  437. if( TheGlobalData && TheGameLogic->isInReplayGame())
  438. #endif
  439. {
  440. if ( TheWritableGlobalData )
  441. TheWritableGlobalData->m_TiVOFastMode = 1 - TheGlobalData->m_TiVOFastMode;
  442. if ( TheInGameUI )
  443. TheInGameUI->message( TheGlobalData->m_TiVOFastMode ? TheGameText->fetch("GUI:FF_ON") : TheGameText->fetch("GUI:FF_OFF") );
  444. }
  445. disp = KEEP_MESSAGE; // cause for goodness sake, this key gets used a lot by non-replay hotkeys
  446. break;
  447. }
  448. /*GameMessage *metaMsg =*/ TheMessageStream->appendMessage(map->m_meta);
  449. //DEBUG_LOG(("Frame %d: MetaEventTranslator::translateGameMessage() normal: %s\n", TheGameLogic->getFrame(), findGameMessageNameByType(map->m_meta)));
  450. }
  451. disp = DESTROY_MESSAGE;
  452. break;
  453. }
  454. }
  455. if (t == GameMessage::MSG_RAW_KEY_DOWN)
  456. {
  457. m_lastKeyDown = key;
  458. #ifdef DUMP_ALL_KEYS_TO_LOG
  459. WideChar Wkey = TheKeyboard->getPrintableKey(key, 0);
  460. UnicodeString uKey;
  461. uKey.set(&Wkey);
  462. AsciiString aKey;
  463. aKey.translate(uKey);
  464. DEBUG_LOG(("^%s ", aKey.str()));
  465. #endif
  466. }
  467. m_lastModState = newModState;
  468. }
  469. if (t > GameMessage::MSG_RAW_MOUSE_BEGIN && t < GameMessage::MSG_RAW_MOUSE_END )
  470. {
  471. Int index = 0;
  472. switch (t)
  473. {
  474. case GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_DOWN:
  475. case GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_DOWN:
  476. case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN:
  477. {
  478. // Fill out which the current mouse down position
  479. if (t == GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_DOWN)
  480. index = 1;
  481. else if (t == GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN)
  482. index = 2;
  483. // else index == 0
  484. m_mouseDownPosition[index] = msg->getArgument(0)->pixel;
  485. m_nextUpShouldCreateDoubleClick[index] = FALSE;
  486. break;
  487. }
  488. case GameMessage::MSG_RAW_MOUSE_LEFT_DOUBLE_CLICK:
  489. case GameMessage::MSG_RAW_MOUSE_MIDDLE_DOUBLE_CLICK:
  490. case GameMessage::MSG_RAW_MOUSE_RIGHT_DOUBLE_CLICK:
  491. {
  492. if (t == GameMessage::MSG_RAW_MOUSE_MIDDLE_DOUBLE_CLICK)
  493. index = 1;
  494. else if (t == GameMessage::MSG_RAW_MOUSE_RIGHT_DOUBLE_CLICK)
  495. index = 2;
  496. // else index == 0
  497. m_nextUpShouldCreateDoubleClick[index] = TRUE;
  498. break;
  499. }
  500. case GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP:
  501. case GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP:
  502. case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP:
  503. {
  504. ICoord2D location = msg->getArgument(0)->pixel;
  505. // Fill out which the current mouse down position
  506. if (t == GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP)
  507. index = 1;
  508. else if (t == GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP)
  509. index = 2;
  510. // else index == 0
  511. GameMessage *newMessage = NULL;
  512. if (t == GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP)
  513. {
  514. if (m_nextUpShouldCreateDoubleClick[index])
  515. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_LEFT_DOUBLE_CLICK, const_cast<GameMessage*>(msg));
  516. else
  517. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_LEFT_CLICK, const_cast<GameMessage*>(msg));
  518. m_nextUpShouldCreateDoubleClick[index] = FALSE;
  519. }
  520. else if (t == GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP)
  521. {
  522. if (m_nextUpShouldCreateDoubleClick[index])
  523. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_MIDDLE_DOUBLE_CLICK, const_cast<GameMessage*>(msg));
  524. else
  525. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_MIDDLE_CLICK, const_cast<GameMessage*>(msg));
  526. m_nextUpShouldCreateDoubleClick[index] = FALSE;
  527. }
  528. else if (t == GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP)
  529. {
  530. if (m_nextUpShouldCreateDoubleClick[index])
  531. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_RIGHT_DOUBLE_CLICK, const_cast<GameMessage*>(msg));
  532. else
  533. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_RIGHT_CLICK, const_cast<GameMessage*>(msg));
  534. m_nextUpShouldCreateDoubleClick[index] = FALSE;
  535. }
  536. IRegion2D pixelRegion;
  537. buildRegion( &m_mouseDownPosition[index], &location, &pixelRegion );
  538. if (abs(pixelRegion.hi.x - pixelRegion.lo.x) < TheMouse->m_dragTolerance &&
  539. abs(pixelRegion.hi.y - pixelRegion.lo.y) < TheMouse->m_dragTolerance)
  540. {
  541. pixelRegion.hi.x = pixelRegion.lo.x;
  542. pixelRegion.hi.y = pixelRegion.lo.y;
  543. }
  544. newMessage->appendPixelRegionArgument( pixelRegion );
  545. // append the modifier keys to the message.
  546. newMessage->appendIntegerArgument( msg->getArgument(1)->integer );
  547. break;
  548. }
  549. }
  550. }
  551. return disp;
  552. }
  553. //-------------------------------------------------------------------------------------------------
  554. //-------------------------------------------------------------------------------------------------
  555. //-------------------------------------------------------------------------------------------------
  556. //-------------------------------------------------------------------------------------------------
  557. MetaMap::MetaMap() :
  558. m_metaMaps(NULL)
  559. {
  560. }
  561. //-------------------------------------------------------------------------------------------------
  562. MetaMap::~MetaMap()
  563. {
  564. while (m_metaMaps)
  565. {
  566. MetaMapRec *next = m_metaMaps->m_next;
  567. m_metaMaps->deleteInstance();
  568. m_metaMaps = next;
  569. }
  570. }
  571. //-------------------------------------------------------------------------------------------------
  572. GameMessage::Type MetaMap::findGameMessageMetaType(const char* name)
  573. {
  574. for (const LookupListRec* metaNames = GameMessageMetaTypeNames; metaNames->name; metaNames++)
  575. if (stricmp(metaNames->name, name) == 0)
  576. return (GameMessage::Type)metaNames->value;
  577. DEBUG_CRASH(("MetaTypeName %s not found -- did you remember to add it to GameMessageMetaTypeNames[] ?", name));
  578. return GameMessage::MSG_INVALID;
  579. }
  580. //-------------------------------------------------------------------------------------------------
  581. MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
  582. {
  583. for (MetaMapRec *map = m_metaMaps; map; map = map->m_next)
  584. {
  585. if (map->m_meta == t)
  586. return map;
  587. }
  588. // not found.. create a new one.
  589. MetaMapRec *m = newInstance(MetaMapRec);
  590. m->m_meta = t;
  591. m->m_key = MK_NONE;
  592. m->m_transition = DOWN;
  593. m->m_modState = NONE;
  594. m->m_usableIn = COMMANDUSABLE_NONE;
  595. m->m_category = CATEGORY_MISC;
  596. m->m_description.clear();
  597. m->m_displayName.clear();
  598. m->m_next = m_metaMaps;
  599. m_metaMaps = m;
  600. return m;
  601. }
  602. //-------------------------------------------------------------------------------------------------
  603. /*static */ void MetaMap::parseMetaMap(INI* ini)
  604. {
  605. // read and ignore the meta-map name
  606. const char *c = ini->getNextToken();
  607. GameMessage::Type t = TheMetaMap->findGameMessageMetaType(c);
  608. if (t == GameMessage::MSG_INVALID)
  609. throw INI_INVALID_DATA;
  610. MetaMapRec *map = TheMetaMap->getMetaMapRec(t);
  611. if (map == NULL)
  612. throw INI_INVALID_DATA;
  613. ini->initFromINI(map, TheMetaMapFieldParseTable);
  614. }
  615. //-------------------------------------------------------------------------------------------------
  616. /*static*/ void INI::parseMetaMapDefinition( INI* ini )
  617. {
  618. MetaMap::parseMetaMap(ini);
  619. }