MetaEvent.cpp 31 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641
  1. /*
  2. ** Command & Conquer Generals(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/MetaEvent.h"
  46. #include "GameLogic/GameLogic.h" // for TheGameLogic->getFrame()
  47. MetaMap *TheMetaMap = NULL;
  48. #ifdef _INTERNAL
  49. // for occasional debugging...
  50. ///#pragma optimize("", off)
  51. ///#pragma MESSAGE("************************************** WARNING, optimization disabled for debugging purposes")
  52. #endif
  53. // DEFINES ////////////////////////////////////////////////////////////////////
  54. // PRIVATE TYPES //////////////////////////////////////////////////////////////////////////////////
  55. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  56. static const LookupListRec GameMessageMetaTypeNames[] =
  57. {
  58. { "SAVE_VIEW1", GameMessage::MSG_META_SAVE_VIEW1 },
  59. { "SAVE_VIEW2", GameMessage::MSG_META_SAVE_VIEW2 },
  60. { "SAVE_VIEW3", GameMessage::MSG_META_SAVE_VIEW3 },
  61. { "SAVE_VIEW4", GameMessage::MSG_META_SAVE_VIEW4 },
  62. { "SAVE_VIEW5", GameMessage::MSG_META_SAVE_VIEW5 },
  63. { "SAVE_VIEW6", GameMessage::MSG_META_SAVE_VIEW6 },
  64. { "SAVE_VIEW7", GameMessage::MSG_META_SAVE_VIEW7 },
  65. { "SAVE_VIEW8", GameMessage::MSG_META_SAVE_VIEW8 },
  66. { "VIEW_VIEW1", GameMessage::MSG_META_VIEW_VIEW1 },
  67. { "VIEW_VIEW2", GameMessage::MSG_META_VIEW_VIEW2 },
  68. { "VIEW_VIEW3", GameMessage::MSG_META_VIEW_VIEW3 },
  69. { "VIEW_VIEW4", GameMessage::MSG_META_VIEW_VIEW4 },
  70. { "VIEW_VIEW5", GameMessage::MSG_META_VIEW_VIEW5 },
  71. { "VIEW_VIEW6", GameMessage::MSG_META_VIEW_VIEW6 },
  72. { "VIEW_VIEW7", GameMessage::MSG_META_VIEW_VIEW7 },
  73. { "VIEW_VIEW8", GameMessage::MSG_META_VIEW_VIEW8 },
  74. { "CREATE_TEAM0", GameMessage::MSG_META_CREATE_TEAM0 },
  75. { "CREATE_TEAM1", GameMessage::MSG_META_CREATE_TEAM1 },
  76. { "CREATE_TEAM2", GameMessage::MSG_META_CREATE_TEAM2 },
  77. { "CREATE_TEAM3", GameMessage::MSG_META_CREATE_TEAM3 },
  78. { "CREATE_TEAM4", GameMessage::MSG_META_CREATE_TEAM4 },
  79. { "CREATE_TEAM5", GameMessage::MSG_META_CREATE_TEAM5 },
  80. { "CREATE_TEAM6", GameMessage::MSG_META_CREATE_TEAM6 },
  81. { "CREATE_TEAM7", GameMessage::MSG_META_CREATE_TEAM7 },
  82. { "CREATE_TEAM8", GameMessage::MSG_META_CREATE_TEAM8 },
  83. { "CREATE_TEAM9", GameMessage::MSG_META_CREATE_TEAM9 },
  84. { "SELECT_TEAM0", GameMessage::MSG_META_SELECT_TEAM0 },
  85. { "SELECT_TEAM1", GameMessage::MSG_META_SELECT_TEAM1 },
  86. { "SELECT_TEAM2", GameMessage::MSG_META_SELECT_TEAM2 },
  87. { "SELECT_TEAM3", GameMessage::MSG_META_SELECT_TEAM3 },
  88. { "SELECT_TEAM4", GameMessage::MSG_META_SELECT_TEAM4 },
  89. { "SELECT_TEAM5", GameMessage::MSG_META_SELECT_TEAM5 },
  90. { "SELECT_TEAM6", GameMessage::MSG_META_SELECT_TEAM6 },
  91. { "SELECT_TEAM7", GameMessage::MSG_META_SELECT_TEAM7 },
  92. { "SELECT_TEAM8", GameMessage::MSG_META_SELECT_TEAM8 },
  93. { "SELECT_TEAM9", GameMessage::MSG_META_SELECT_TEAM9 },
  94. { "ADD_TEAM0", GameMessage::MSG_META_ADD_TEAM0 },
  95. { "ADD_TEAM1", GameMessage::MSG_META_ADD_TEAM1 },
  96. { "ADD_TEAM2", GameMessage::MSG_META_ADD_TEAM2 },
  97. { "ADD_TEAM3", GameMessage::MSG_META_ADD_TEAM3 },
  98. { "ADD_TEAM4", GameMessage::MSG_META_ADD_TEAM4 },
  99. { "ADD_TEAM5", GameMessage::MSG_META_ADD_TEAM5 },
  100. { "ADD_TEAM6", GameMessage::MSG_META_ADD_TEAM6 },
  101. { "ADD_TEAM7", GameMessage::MSG_META_ADD_TEAM7 },
  102. { "ADD_TEAM8", GameMessage::MSG_META_ADD_TEAM8 },
  103. { "ADD_TEAM9", GameMessage::MSG_META_ADD_TEAM9 },
  104. { "VIEW_TEAM0", GameMessage::MSG_META_VIEW_TEAM0 },
  105. { "VIEW_TEAM1", GameMessage::MSG_META_VIEW_TEAM1 },
  106. { "VIEW_TEAM2", GameMessage::MSG_META_VIEW_TEAM2 },
  107. { "VIEW_TEAM3", GameMessage::MSG_META_VIEW_TEAM3 },
  108. { "VIEW_TEAM4", GameMessage::MSG_META_VIEW_TEAM4 },
  109. { "VIEW_TEAM5", GameMessage::MSG_META_VIEW_TEAM5 },
  110. { "VIEW_TEAM6", GameMessage::MSG_META_VIEW_TEAM6 },
  111. { "VIEW_TEAM7", GameMessage::MSG_META_VIEW_TEAM7 },
  112. { "VIEW_TEAM8", GameMessage::MSG_META_VIEW_TEAM8 },
  113. { "VIEW_TEAM9", GameMessage::MSG_META_VIEW_TEAM9 },
  114. { "SELECT_MATCHING_UNITS", GameMessage::MSG_META_SELECT_MATCHING_UNITS },
  115. { "SELECT_NEXT_UNIT", GameMessage::MSG_META_SELECT_NEXT_UNIT },
  116. { "SELECT_PREV_UNIT", GameMessage::MSG_META_SELECT_PREV_UNIT },
  117. { "SELECT_NEXT_WORKER", GameMessage::MSG_META_SELECT_NEXT_WORKER },
  118. { "SELECT_PREV_WORKER", GameMessage::MSG_META_SELECT_PREV_WORKER },
  119. { "SELECT_HERO", GameMessage::MSG_META_SELECT_HERO },
  120. { "SELECT_ALL", GameMessage::MSG_META_SELECT_ALL },
  121. { "VIEW_COMMAND_CENTER", GameMessage::MSG_META_VIEW_COMMAND_CENTER },
  122. { "VIEW_LAST_RADAR_EVENT", GameMessage::MSG_META_VIEW_LAST_RADAR_EVENT },
  123. { "SCATTER", GameMessage::MSG_META_SCATTER },
  124. { "STOP", GameMessage::MSG_META_STOP },
  125. { "DEPLOY", GameMessage::MSG_META_DEPLOY },
  126. { "CREATE_FORMATION", GameMessage::MSG_META_CREATE_FORMATION },
  127. { "FOLLOW", GameMessage::MSG_META_FOLLOW },
  128. { "CHAT_PLAYERS", GameMessage::MSG_META_CHAT_PLAYERS },
  129. { "CHAT_ALLIES", GameMessage::MSG_META_CHAT_ALLIES },
  130. { "CHAT_EVERYONE", GameMessage::MSG_META_CHAT_EVERYONE },
  131. { "DIPLOMACY", GameMessage::MSG_META_DIPLOMACY },
  132. { "PLACE_BEACON", GameMessage::MSG_META_PLACE_BEACON },
  133. { "DELETE_BEACON", GameMessage::MSG_META_REMOVE_BEACON },
  134. { "OPTIONS", GameMessage::MSG_META_OPTIONS },
  135. { "TOGGLE_LOWER_DETAILS", GameMessage::MSG_META_TOGGLE_LOWER_DETAILS },
  136. { "TOGGLE_CONTROL_BAR", GameMessage::MSG_META_TOGGLE_CONTROL_BAR },
  137. { "BEGIN_PATH_BUILD", GameMessage::MSG_META_BEGIN_PATH_BUILD },
  138. { "END_PATH_BUILD", GameMessage::MSG_META_END_PATH_BUILD },
  139. { "BEGIN_FORCEATTACK", GameMessage::MSG_META_BEGIN_FORCEATTACK },
  140. { "END_FORCEATTACK", GameMessage::MSG_META_END_FORCEATTACK },
  141. { "BEGIN_FORCEMOVE", GameMessage::MSG_META_BEGIN_FORCEMOVE },
  142. { "END_FORCEMOVE", GameMessage::MSG_META_END_FORCEMOVE },
  143. { "BEGIN_WAYPOINTS", GameMessage::MSG_META_BEGIN_WAYPOINTS },
  144. { "END_WAYPOINTS", GameMessage::MSG_META_END_WAYPOINTS },
  145. { "BEGIN_PREFER_SELECTION", GameMessage::MSG_META_BEGIN_PREFER_SELECTION },
  146. { "END_PREFER_SELECTION", GameMessage::MSG_META_END_PREFER_SELECTION },
  147. { "TAKE_SCREENSHOT", GameMessage::MSG_META_TAKE_SCREENSHOT },
  148. { "ALL_CHEER", GameMessage::MSG_META_ALL_CHEER },
  149. { "BEGIN_CAMERA_ROTATE_LEFT", GameMessage::MSG_META_BEGIN_CAMERA_ROTATE_LEFT },
  150. { "END_CAMERA_ROTATE_LEFT", GameMessage::MSG_META_END_CAMERA_ROTATE_LEFT },
  151. { "BEGIN_CAMERA_ROTATE_RIGHT", GameMessage::MSG_META_BEGIN_CAMERA_ROTATE_RIGHT },
  152. { "END_CAMERA_ROTATE_RIGHT", GameMessage::MSG_META_END_CAMERA_ROTATE_RIGHT },
  153. { "BEGIN_CAMERA_ZOOM_IN", GameMessage::MSG_META_BEGIN_CAMERA_ZOOM_IN },
  154. { "END_CAMERA_ZOOM_IN", GameMessage::MSG_META_END_CAMERA_ZOOM_IN },
  155. { "BEGIN_CAMERA_ZOOM_OUT", GameMessage::MSG_META_BEGIN_CAMERA_ZOOM_OUT },
  156. { "END_CAMERA_ZOOM_OUT", GameMessage::MSG_META_END_CAMERA_ZOOM_OUT },
  157. { "CAMERA_RESET", GameMessage::MSG_META_CAMERA_RESET },
  158. #if defined(_DEBUG) || defined(_INTERNAL)
  159. { "HELP", GameMessage::MSG_META_HELP },
  160. { "DEMO_INSTANT_QUIT", GameMessage::MSG_META_DEMO_INSTANT_QUIT },
  161. { "DEMO_TOGGLE_BEHIND_BUILDINGS", GameMessage::MSG_META_DEMO_TOGGLE_BEHIND_BUILDINGS },
  162. { "DEMO_LOD_DECREASE", GameMessage::MSG_META_DEMO_LOD_DECREASE },
  163. { "DEMO_LOD_INCREASE", GameMessage::MSG_META_DEMO_LOD_INCREASE },
  164. { "DEMO_TOGGLE_LETTERBOX", GameMessage::MSG_META_DEMO_TOGGLE_LETTERBOX },
  165. { "DEMO_TOGGLE_MESSAGE_TEXT", GameMessage::MSG_META_DEMO_TOGGLE_MESSAGE_TEXT },
  166. { "DEMO_GIVE_ALL_SCIENCES", GameMessage::MSG_META_DEMO_GIVE_ALL_SCIENCES },
  167. { "DEMO_GIVE_RANKLEVEL", GameMessage::MSG_META_DEMO_GIVE_RANKLEVEL },
  168. { "DEMO_TAKE_RANKLEVEL", GameMessage::MSG_META_DEMO_TAKE_RANKLEVEL },
  169. { "DEMO_GIVE_SCIENCEPURCHASEPOINTS", GameMessage::MSG_META_DEMO_GIVE_SCIENCEPURCHASEPOINTS },
  170. { "DEMO_SWITCH_TEAMS", GameMessage::MSG_META_DEMO_SWITCH_TEAMS },
  171. { "DEMO_SWITCH_TEAMS_CHINA_USA", GameMessage::MSG_META_DEMO_SWITCH_TEAMS_BETWEEN_CHINA_USA },
  172. { "DEMO_TOGGLE_CASHMAPDEBUG", GameMessage::MSG_META_DEMO_TOGGLE_CASHMAPDEBUG },
  173. { "DEMO_TOGGLE_GRAPHICALFRAMERATEBAR", GameMessage::MSG_META_DEMO_TOGGLE_GRAPHICALFRAMERATEBAR },
  174. { "DEMO_TOGGLE_PARTICLEDEBUG", GameMessage::MSG_META_DEMO_TOGGLE_PARTICLEDEBUG },
  175. { "DEMO_TOGGLE_THREATDEBUG", GameMessage::MSG_META_DEMO_TOGGLE_THREATDEBUG },
  176. { "DEMO_TOGGLE_VISIONDEBUG", GameMessage::MSG_META_DEMO_TOGGLE_VISIONDEBUG },
  177. { "DEMO_TOGGLE_PROJECTILEDEBUG", GameMessage::MSG_META_DEMO_TOGGLE_PROJECTILEDEBUG },
  178. { "DEMO_LOD_DECREASE", GameMessage::MSG_META_DEMO_LOD_DECREASE },
  179. { "DEMO_LOD_INCREASE", GameMessage::MSG_META_DEMO_LOD_INCREASE },
  180. { "DEMO_TOGGLE_SHADOW_VOLUMES", GameMessage::MSG_META_DEMO_TOGGLE_SHADOW_VOLUMES },
  181. { "DEMO_TOGGLE_FOGOFWAR", GameMessage::MSG_META_DEMO_TOGGLE_FOGOFWAR },
  182. { "DEMO_KILL_ALL_ENEMIES", GameMessage::MSG_META_DEMO_KILL_ALL_ENEMIES },
  183. { "DEMO_KILL_SELECTION", GameMessage::MSG_META_DEMO_KILL_SELECTION },
  184. { "DEMO_TOGGLE_HURT_ME_MODE", GameMessage::MSG_META_DEMO_TOGGLE_HURT_ME_MODE },
  185. { "DEMO_TOGGLE_HAND_OF_GOD_MODE", GameMessage::MSG_META_DEMO_TOGGLE_HAND_OF_GOD_MODE },
  186. { "DEMO_DEBUG_SELECTION", GameMessage::MSG_META_DEMO_DEBUG_SELECTION },
  187. { "DEMO_LOCK_CAMERA_TO_SELECTION", GameMessage::MSG_META_DEMO_LOCK_CAMERA_TO_SELECTION },
  188. { "DEMO_TOGGLE_SOUND", GameMessage::MSG_META_DEMO_TOGGLE_SOUND },
  189. { "DEMO_TOGGLE_TRACKMARKS", GameMessage::MSG_META_DEMO_TOGGLE_TRACKMARKS },
  190. { "DEMO_TOGGLE_WATERPLANE", GameMessage::MSG_META_DEMO_TOGGLE_WATERPLANE },
  191. { "DEMO_TIME_OF_DAY", GameMessage::MSG_META_DEMO_TIME_OF_DAY },
  192. { "DEMO_TOGGLE_MILITARY_SUBTITLES", GameMessage::MSG_META_DEMO_TOGGLE_MILITARY_SUBTITLES },
  193. { "DEMO_TOGGLE_MUSIC", GameMessage::MSG_META_DEMO_TOGGLE_MUSIC },
  194. { "DEMO_MUSIC_NEXT_TRACK", GameMessage::MSG_META_DEMO_MUSIC_NEXT_TRACK },
  195. { "DEMO_MUSIC_PREV_TRACK", GameMessage::MSG_META_DEMO_MUSIC_PREV_TRACK },
  196. { "DEMO_NEXT_OBJECTIVE_MOVIE", GameMessage::MSG_META_DEMO_NEXT_OBJECTIVE_MOVIE },
  197. { "DEMO_PLAY_OBJECTIVE_MOVIE1", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE1 },
  198. { "DEMO_PLAY_OBJECTIVE_MOVIE2", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE2 },
  199. { "DEMO_PLAY_OBJECTIVE_MOVIE3", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE3 },
  200. { "DEMO_PLAY_OBJECTIVE_MOVIE4", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE4 },
  201. { "DEMO_PLAY_OBJECTIVE_MOVIE5", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE5 },
  202. { "DEMO_PLAY_OBJECTIVE_MOVIE6", GameMessage::MSG_META_DEMO_PLAY_OBJECTIVE_MOVIE6 },
  203. { "DEMO_BEGIN_ADJUST_PITCH", GameMessage::MSG_META_DEMO_BEGIN_ADJUST_PITCH },
  204. { "DEMO_END_ADJUST_PITCH", GameMessage::MSG_META_DEMO_END_ADJUST_PITCH },
  205. { "DEMO_BEGIN_ADJUST_FOV", GameMessage::MSG_META_DEMO_BEGIN_ADJUST_FOV },
  206. { "DEMO_END_ADJUST_FOV", GameMessage::MSG_META_DEMO_END_ADJUST_FOV },
  207. { "DEMO_LOCK_CAMERA_TO_PLANES", GameMessage::MSG_META_DEMO_LOCK_CAMERA_TO_PLANES },
  208. { "DEMO_REMOVE_PREREQ", GameMessage::MSG_META_DEMO_REMOVE_PREREQ },
  209. { "DEMO_RUNSCRIPT1", GameMessage::MSG_META_DEMO_RUNSCRIPT1 },
  210. { "DEMO_RUNSCRIPT2", GameMessage::MSG_META_DEMO_RUNSCRIPT2 },
  211. { "DEMO_RUNSCRIPT3", GameMessage::MSG_META_DEMO_RUNSCRIPT3 },
  212. { "DEMO_RUNSCRIPT4", GameMessage::MSG_META_DEMO_RUNSCRIPT4 },
  213. { "DEMO_RUNSCRIPT5", GameMessage::MSG_META_DEMO_RUNSCRIPT5 },
  214. { "DEMO_RUNSCRIPT6", GameMessage::MSG_META_DEMO_RUNSCRIPT6 },
  215. { "DEMO_RUNSCRIPT7", GameMessage::MSG_META_DEMO_RUNSCRIPT7 },
  216. { "DEMO_RUNSCRIPT8", GameMessage::MSG_META_DEMO_RUNSCRIPT8 },
  217. { "DEMO_RUNSCRIPT9", GameMessage::MSG_META_DEMO_RUNSCRIPT9 },
  218. { "DEMO_ADDCASH", GameMessage::MSG_META_DEMO_ADD_CASH },
  219. { "DEMO_TOGGLE_RENDER", GameMessage::MSG_META_DEMO_TOGGLE_RENDER },
  220. { "DEMO_TOGGLE_BW_VIEW", GameMessage::MSG_META_DEMO_TOGGLE_BW_VIEW },
  221. { "DEMO_TOGGLE_RED_VIEW", GameMessage::MSG_META_DEMO_TOGGLE_RED_VIEW },
  222. { "DEMO_TOGGLE_GREEN_VIEW", GameMessage::MSG_META_DEMO_TOGGLE_GREEN_VIEW },
  223. { "DEMO_TOGGLE_MOTION_BLUR_ZOOM", GameMessage::MSG_META_DEMO_TOGGLE_MOTION_BLUR_ZOOM },
  224. { "DEMO_SHOW_EXTENTS", GameMessage::MSG_META_DEBUG_SHOW_EXTENTS },
  225. { "DEMO_SHOW_HEALTH", GameMessage::MSG_META_DEBUG_SHOW_HEALTH },
  226. { "DEMO_GIVE_VETERANCY", GameMessage::MSG_META_DEBUG_GIVE_VETERANCY },
  227. { "DEMO_TAKE_VETERANCY", GameMessage::MSG_META_DEBUG_TAKE_VETERANCY },
  228. { "DEMO_BATTLE_CRY", GameMessage::MSG_META_DEMO_BATTLE_CRY },
  229. #ifdef ALLOW_SURRENDER
  230. { "DEMO_TEST_SURRENDER", GameMessage::MSG_META_DEMO_TEST_SURRENDER },
  231. #endif
  232. { "DEMO_TOGGLE_AVI", GameMessage::MSG_META_DEMO_TOGGLE_AVI },
  233. { "DEMO_PLAY_CAMEO_MOVIE", GameMessage::MSG_META_DEMO_PLAY_CAMEO_MOVIE },
  234. { "DEMO_TOGGLE_ZOOM_LOCK", GameMessage::MSG_META_DEMO_TOGGLE_ZOOM_LOCK },
  235. { "DEMO_TOGGLE_SPECIAL_POWER_DELAYS", GameMessage::MSG_META_DEMO_TOGGLE_SPECIAL_POWER_DELAYS },
  236. { "DEMO_TOGGLE_METRICS", GameMessage::MSG_META_DEMO_TOGGLE_METRICS},
  237. { "DEMO_DESHROUD", GameMessage::MSG_META_DEMO_DESHROUD },
  238. { "DEMO_ENSHROUD", GameMessage::MSG_META_DEMO_ENSHROUD },
  239. { "DEMO_TOGGLE_AI_DEBUG", GameMessage::MSG_META_DEMO_TOGGLE_AI_DEBUG },
  240. { "DEMO_TOGGLE_NO_DRAW", GameMessage::MSG_NO_DRAW },
  241. { "DEMO_CYCLE_LOD_LEVEL", GameMessage::MSG_META_DEMO_CYCLE_LOD_LEVEL },
  242. { "DEMO_DUMP_ASSETS", GameMessage::MSG_META_DEBUG_DUMP_ASSETS},
  243. { "DEMO_INSTANT_BUILD", GameMessage::MSG_META_DEMO_INSTANT_BUILD },
  244. { "DEMO_TOGGLE_CAMERA_DEBUG", GameMessage::MSG_META_DEMO_TOGGLE_CAMERA_DEBUG },
  245. /// Begin VTUNE
  246. { "DEMO_VTUNE_ON", GameMessage::MSG_META_DEBUG_VTUNE_ON },
  247. { "DEMO_VTUNE_OFF", GameMessage::MSG_META_DEBUG_VTUNE_OFF },
  248. /// End VTUNE
  249. //lorenzen's feather water
  250. { "DEMO_TOGGLE_FEATHER_WATER", GameMessage::MSG_META_DEBUG_TOGGLE_FEATHER_WATER },
  251. { "DEMO_INCR_ANIM_SKATE_SPEED", GameMessage::MSG_META_DEBUG_INCR_ANIM_SKATE_SPEED },
  252. { "DEMO_DECR_ANIM_SKATE_SPEED", GameMessage::MSG_META_DEBUG_DECR_ANIM_SKATE_SPEED },
  253. { "DEMO_CYCLE_EXTENT_TYPE", GameMessage::MSG_META_DEBUG_CYCLE_EXTENT_TYPE },
  254. { "DEMO_INCR_EXTENT_MAJOR", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MAJOR },
  255. { "DEMO_DECR_EXTENT_MAJOR", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MAJOR },
  256. { "DEMO_INCR_EXTENT_MAJOR_LARGE", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MAJOR_BIG },
  257. { "DEMO_DECR_EXTENT_MAJOR_LARGE", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MAJOR_BIG },
  258. { "DEMO_INCR_EXTENT_MINOR", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MINOR },
  259. { "DEMO_DECR_EXTENT_MINOR", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MINOR },
  260. { "DEMO_INCR_EXTENT_MINOR_LARGE", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_MINOR_BIG },
  261. { "DEMO_DECR_EXTENT_MINOR_LARGE", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_MINOR_BIG },
  262. { "DEMO_INCR_EXTENT_HEIGHT", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_HEIGHT },
  263. { "DEMO_DECR_EXTENT_HEIGHT", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_HEIGHT },
  264. { "DEMO_INCR_EXTENT_HEIGHT_LARGE", GameMessage::MSG_META_DEBUG_INCREASE_EXTENT_HEIGHT_BIG },
  265. { "DEMO_DECR_EXTENT_HEIGHT_LARGE", GameMessage::MSG_META_DEBUG_DECREASE_EXTENT_HEIGHT_BIG },
  266. { "DEMO_TOGGLE_NETWORK", GameMessage::MSG_META_DEBUG_TOGGLE_NETWORK },
  267. { "DEBUG_DUMP_PLAYER_OBJECTS", GameMessage::MSG_META_DEBUG_DUMP_PLAYER_OBJECTS },
  268. { "DEBUG_DUMP_ALL_PLAYER_OBJECTS", GameMessage::MSG_META_DEBUG_DUMP_ALL_PLAYER_OBJECTS },
  269. { "DEMO_WIN", GameMessage::MSG_META_DEBUG_WIN },
  270. { "DEMO_TOGGLE_DEBUG_STATS", GameMessage::MSG_META_DEMO_TOGGLE_DEBUG_STATS },
  271. #endif // defined(_DEBUG) || defined(_INTERNAL)
  272. #if defined(_INTERNAL) || defined(_DEBUG) || defined(_PLAYTEST)
  273. { "DEMO_TOGGLE_AUDIODEBUG", GameMessage::MSG_META_DEMO_TOGGLE_AUDIODEBUG },
  274. #endif//defined(_INTERNAL) || defined(_DEBUG) || defined(_PLAYTEST)
  275. #ifdef DUMP_PERF_STATS
  276. { "DEMO_PERFORM_STATISTICAL_DUMP", GameMessage::MSG_META_DEMO_PERFORM_STATISTICAL_DUMP },
  277. #endif//DUMP_PERF_STATS
  278. { NULL, 0 }// keep this last!
  279. };
  280. ///////////////////////////////////////////////////////////////////////////////////////////////////
  281. // PRIVATE DATA ///////////////////////////////////////////////////////////////////////////////////
  282. ///////////////////////////////////////////////////////////////////////////////////////////////////
  283. static const FieldParse TheMetaMapFieldParseTable[] =
  284. {
  285. { "Key", INI::parseLookupList, KeyNames, offsetof( MetaMapRec, m_key ) },
  286. { "Transition", INI::parseLookupList, TransitionNames, offsetof( MetaMapRec, m_transition ) },
  287. { "Modifiers", INI::parseLookupList, ModifierNames, offsetof( MetaMapRec, m_modState ) },
  288. { "UseableIn", INI::parseBitString32, TheCommandUsableInNames, offsetof( MetaMapRec, m_usableIn ) },
  289. { "Category", INI::parseLookupList, CategoryListName, offsetof( MetaMapRec, m_category ) },
  290. { "Description", INI::parseAndTranslateLabel, 0, offsetof( MetaMapRec, m_description ) },
  291. { "DisplayName", INI::parseAndTranslateLabel, 0, offsetof( MetaMapRec, m_displayName ) },
  292. { NULL, NULL, 0, 0 } // keep this last
  293. };
  294. // PRIVATE FUNCTIONS //////////////////////////////////////////////////////////////////////////////
  295. // PUBLIC FUNCTIONS ///////////////////////////////////////////////////////////////////////////////
  296. //-------------------------------------------------------------------------------------------------
  297. MetaEventTranslator::MetaEventTranslator() :
  298. m_lastKeyDown(MK_NONE),
  299. m_lastModState(0)
  300. {
  301. for (Int i = 0; i < NUM_MOUSE_BUTTONS; ++i) {
  302. m_nextUpShouldCreateDoubleClick[i] = FALSE;
  303. }
  304. }
  305. //-------------------------------------------------------------------------------------------------
  306. MetaEventTranslator::~MetaEventTranslator()
  307. {
  308. }
  309. //-------------------------------------------------------------------------------------------------
  310. static const char * findGameMessageNameByType(GameMessage::Type type)
  311. {
  312. for (const LookupListRec* metaNames = GameMessageMetaTypeNames; metaNames->name; metaNames++)
  313. if (metaNames->value == (Int)type)
  314. return metaNames->name;
  315. DEBUG_CRASH(("MetaTypeName %d not found -- did you remember to add it to GameMessageMetaTypeNames[] ?\n"));
  316. return "???";
  317. }
  318. //-------------------------------------------------------------------------------------------------
  319. GameMessageDisposition MetaEventTranslator::translateGameMessage(const GameMessage *msg)
  320. {
  321. GameMessageDisposition disp = KEEP_MESSAGE;
  322. GameMessage::Type t = msg->getType();
  323. if (t == GameMessage::MSG_RAW_KEY_DOWN || t == GameMessage::MSG_RAW_KEY_UP)
  324. {
  325. MappableKeyType key = (MappableKeyType)msg->getArgument(0)->integer;
  326. Int keyState = msg->getArgument(1)->integer;
  327. // for our purposes here, we don't care to distinguish between right and left keys,
  328. // so just fudge a little to simplify things.
  329. Int newModState = 0;
  330. if( keyState & KEY_STATE_CONTROL )
  331. {
  332. newModState |= CTRL;
  333. }
  334. if( keyState & KEY_STATE_SHIFT )
  335. {
  336. newModState |= SHIFT;
  337. }
  338. if( keyState & KEY_STATE_ALT )
  339. {
  340. newModState |= ALT;
  341. }
  342. for (const MetaMapRec *map = TheMetaMap->getFirstMetaMapRec(); map; map = map->m_next)
  343. {
  344. DEBUG_ASSERTCRASH(map->m_meta > GameMessage::MSG_BEGIN_META_MESSAGES &&
  345. map->m_meta < GameMessage::MSG_END_META_MESSAGES, ("hmm, expected only meta-msgs here"));
  346. //
  347. // if this command is *only* usable in the game, we will ignore it if the game client
  348. // has not yet incremented to frame 1 (keeps us from doing in-game commands during
  349. // a map load, which throws the input system into wack because there isn't a
  350. // client frame for the input event, and in the case of a command that pauses the
  351. // game, like the quit menu, the client frame will never get beyond 0 and we
  352. // lose the ability to process any input
  353. //
  354. if( map->m_usableIn == COMMANDUSABLE_GAME && TheGameClient->getFrame() < 1 )
  355. continue;
  356. // if the shell is active, and this command is not usable in shell, continue
  357. if (TheShell && TheShell->isShellActive() && !(map->m_usableIn & COMMANDUSABLE_SHELL) )
  358. continue;
  359. // if the shell is not active and this command is not usable in the game, continue
  360. if (TheShell && !TheShell->isShellActive() && !(map->m_usableIn & COMMANDUSABLE_GAME) )
  361. continue;
  362. // check for the special case of mods-only-changed.
  363. if (
  364. map->m_key == MK_NONE &&
  365. newModState != m_lastModState &&
  366. (
  367. (map->m_transition == UP && map->m_modState == m_lastModState) ||
  368. (map->m_transition == DOWN && map->m_modState == newModState)
  369. )
  370. )
  371. {
  372. //DEBUG_LOG(("Frame %d: MetaEventTranslator::translateGameMessage() Mods-only change: %s\n", TheGameLogic->getFrame(), findGameMessageNameByType(map->m_meta)));
  373. /*GameMessage *metaMsg =*/ TheMessageStream->appendMessage(map->m_meta);
  374. disp = DESTROY_MESSAGE;
  375. break;
  376. }
  377. // ok, now check for "normal" key transitions.
  378. if (
  379. map->m_key == key &&
  380. map->m_modState == newModState &&
  381. (
  382. (map->m_transition == UP && (keyState & KEY_STATE_UP)) ||
  383. (map->m_transition == DOWN && (keyState & KEY_STATE_DOWN)) //||
  384. //(map->m_transition == DOUBLEDOWN && (keyState & KEY_STATE_DOWN) && m_lastKeyDown == key)
  385. )
  386. )
  387. {
  388. if( keyState & KEY_STATE_AUTOREPEAT )
  389. {
  390. // if it's an autorepeat of a "known" key, don't generate the meta-event,
  391. // but DO eat the keystroke so no one else can mess with it
  392. //DEBUG_LOG(("Frame %d: MetaEventTranslator::translateGameMessage() auto-repeat: %s\n", TheGameLogic->getFrame(), findGameMessageNameByType(map->m_meta)));
  393. }
  394. else
  395. {
  396. /*GameMessage *metaMsg =*/ TheMessageStream->appendMessage(map->m_meta);
  397. //DEBUG_LOG(("Frame %d: MetaEventTranslator::translateGameMessage() normal: %s\n", TheGameLogic->getFrame(), findGameMessageNameByType(map->m_meta)));
  398. }
  399. disp = DESTROY_MESSAGE;
  400. break;
  401. }
  402. }
  403. if (t == GameMessage::MSG_RAW_KEY_DOWN)
  404. m_lastKeyDown = key;
  405. m_lastModState = newModState;
  406. }
  407. if (t > GameMessage::MSG_RAW_MOUSE_BEGIN && t < GameMessage::MSG_RAW_MOUSE_END )
  408. {
  409. Int index = 0;
  410. switch (t)
  411. {
  412. case GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_DOWN:
  413. case GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_DOWN:
  414. case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN:
  415. {
  416. // Fill out which the current mouse down position
  417. if (t == GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_DOWN)
  418. index = 1;
  419. else if (t == GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_DOWN)
  420. index = 2;
  421. // else index == 0
  422. m_mouseDownPosition[index] = msg->getArgument(0)->pixel;
  423. m_nextUpShouldCreateDoubleClick[index] = FALSE;
  424. break;
  425. }
  426. case GameMessage::MSG_RAW_MOUSE_LEFT_DOUBLE_CLICK:
  427. case GameMessage::MSG_RAW_MOUSE_MIDDLE_DOUBLE_CLICK:
  428. case GameMessage::MSG_RAW_MOUSE_RIGHT_DOUBLE_CLICK:
  429. {
  430. if (t == GameMessage::MSG_RAW_MOUSE_MIDDLE_DOUBLE_CLICK)
  431. index = 1;
  432. else if (t == GameMessage::MSG_RAW_MOUSE_RIGHT_DOUBLE_CLICK)
  433. index = 2;
  434. // else index == 0
  435. m_nextUpShouldCreateDoubleClick[index] = TRUE;
  436. break;
  437. }
  438. case GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP:
  439. case GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP:
  440. case GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP:
  441. {
  442. ICoord2D location = msg->getArgument(0)->pixel;
  443. // Fill out which the current mouse down position
  444. if (t == GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP)
  445. index = 1;
  446. else if (t == GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP)
  447. index = 2;
  448. // else index == 0
  449. GameMessage *newMessage = NULL;
  450. if (t == GameMessage::MSG_RAW_MOUSE_LEFT_BUTTON_UP)
  451. {
  452. if (m_nextUpShouldCreateDoubleClick[index])
  453. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_LEFT_DOUBLE_CLICK, const_cast<GameMessage*>(msg));
  454. else
  455. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_LEFT_CLICK, const_cast<GameMessage*>(msg));
  456. m_nextUpShouldCreateDoubleClick[index] = FALSE;
  457. }
  458. else if (t == GameMessage::MSG_RAW_MOUSE_MIDDLE_BUTTON_UP)
  459. {
  460. if (m_nextUpShouldCreateDoubleClick[index])
  461. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_MIDDLE_DOUBLE_CLICK, const_cast<GameMessage*>(msg));
  462. else
  463. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_MIDDLE_CLICK, const_cast<GameMessage*>(msg));
  464. m_nextUpShouldCreateDoubleClick[index] = FALSE;
  465. }
  466. else if (t == GameMessage::MSG_RAW_MOUSE_RIGHT_BUTTON_UP)
  467. {
  468. if (m_nextUpShouldCreateDoubleClick[index])
  469. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_RIGHT_DOUBLE_CLICK, const_cast<GameMessage*>(msg));
  470. else
  471. newMessage = TheMessageStream->insertMessage(GameMessage::MSG_MOUSE_RIGHT_CLICK, const_cast<GameMessage*>(msg));
  472. m_nextUpShouldCreateDoubleClick[index] = FALSE;
  473. }
  474. IRegion2D pixelRegion;
  475. buildRegion( &m_mouseDownPosition[index], &location, &pixelRegion );
  476. if (abs(pixelRegion.hi.x - pixelRegion.lo.x) < TheMouse->m_dragTolerance &&
  477. abs(pixelRegion.hi.y - pixelRegion.lo.y) < TheMouse->m_dragTolerance)
  478. {
  479. pixelRegion.hi.x = pixelRegion.lo.x;
  480. pixelRegion.hi.y = pixelRegion.lo.y;
  481. }
  482. newMessage->appendPixelRegionArgument( pixelRegion );
  483. // append the modifier keys to the message.
  484. newMessage->appendIntegerArgument( msg->getArgument(1)->integer );
  485. break;
  486. }
  487. }
  488. }
  489. return disp;
  490. }
  491. //-------------------------------------------------------------------------------------------------
  492. //-------------------------------------------------------------------------------------------------
  493. //-------------------------------------------------------------------------------------------------
  494. //-------------------------------------------------------------------------------------------------
  495. MetaMap::MetaMap() :
  496. m_metaMaps(NULL)
  497. {
  498. }
  499. //-------------------------------------------------------------------------------------------------
  500. MetaMap::~MetaMap()
  501. {
  502. while (m_metaMaps)
  503. {
  504. MetaMapRec *next = m_metaMaps->m_next;
  505. m_metaMaps->deleteInstance();
  506. m_metaMaps = next;
  507. }
  508. }
  509. //-------------------------------------------------------------------------------------------------
  510. GameMessage::Type MetaMap::findGameMessageMetaType(const char* name)
  511. {
  512. for (const LookupListRec* metaNames = GameMessageMetaTypeNames; metaNames->name; metaNames++)
  513. if (stricmp(metaNames->name, name) == 0)
  514. return (GameMessage::Type)metaNames->value;
  515. DEBUG_CRASH(("MetaTypeName %s not found -- did you remember to add it to GameMessageMetaTypeNames[] ?", name));
  516. return GameMessage::MSG_INVALID;
  517. }
  518. //-------------------------------------------------------------------------------------------------
  519. MetaMapRec *MetaMap::getMetaMapRec(GameMessage::Type t)
  520. {
  521. for (MetaMapRec *map = m_metaMaps; map; map = map->m_next)
  522. {
  523. if (map->m_meta == t)
  524. return map;
  525. }
  526. // not found.. create a new one.
  527. MetaMapRec *m = newInstance(MetaMapRec);
  528. m->m_meta = t;
  529. m->m_key = MK_NONE;
  530. m->m_transition = DOWN;
  531. m->m_modState = NONE;
  532. m->m_usableIn = COMMANDUSABLE_NONE;
  533. m->m_category = CATEGORY_MISC;
  534. m->m_description.clear();
  535. m->m_displayName.clear();
  536. m->m_next = m_metaMaps;
  537. m_metaMaps = m;
  538. return m;
  539. }
  540. //-------------------------------------------------------------------------------------------------
  541. /*static */ void MetaMap::parseMetaMap(INI* ini)
  542. {
  543. // read and ignore the meta-map name
  544. const char *c = ini->getNextToken();
  545. GameMessage::Type t = TheMetaMap->findGameMessageMetaType(c);
  546. if (t == GameMessage::MSG_INVALID)
  547. throw INI_INVALID_DATA;
  548. MetaMapRec *map = TheMetaMap->getMetaMapRec(t);
  549. if (map == NULL)
  550. throw INI_INVALID_DATA;
  551. ini->initFromINI(map, TheMetaMapFieldParseTable);
  552. }
  553. //-------------------------------------------------------------------------------------------------
  554. /*static*/ void INI::parseMetaMapDefinition( INI* ini )
  555. {
  556. MetaMap::parseMetaMap(ini);
  557. }