SCROLL.CPP 12 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: /CounterStrike/SCROLL.CPP 1 3/03/97 10:25a Joe_bostic $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : SCROLL.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 01/08/95 *
  26. * *
  27. * Last Update : August 25, 1995 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * ScrollClass::AI -- Handles scroll AI processing. *
  32. * ScrollClass::ScrollClass -- Constructor for the scroll class object. *
  33. * ScrollClass::Set_Autoscroll -- Turns autoscrolling on or off. *
  34. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  35. #include "function.h"
  36. #ifdef WIN32
  37. #define SCROLL_DELAY 1
  38. #else
  39. #define SCROLL_DELAY 2
  40. #endif
  41. CDTimerClass<SystemTimerClass> ScrollClass::Counter;
  42. /***********************************************************************************************
  43. * ScrollClass::ScrollClass -- Constructor for the scroll class object. *
  44. * *
  45. * This is the constructor for the scroll class object. *
  46. * *
  47. * INPUT: none *
  48. * *
  49. * OUTPUT: none *
  50. * *
  51. * WARNINGS: none *
  52. * *
  53. * HISTORY: *
  54. * 08/10/1995 JLB : Created. *
  55. *=============================================================================================*/
  56. ScrollClass::ScrollClass(void) :
  57. IsAutoScroll(true)
  58. {
  59. Counter = SCROLL_DELAY;
  60. Inertia = 0;
  61. }
  62. /***********************************************************************************************
  63. * ScrollClass::AI -- Handles scroll AI processing. *
  64. * *
  65. * This routine is called every game frame for purposes of input processing. *
  66. * *
  67. * INPUT: input -- Reference to the keyboard/mouse event that just occurred. *
  68. * *
  69. * x,y -- The mouse coordinates. *
  70. * *
  71. * OUTPUT: none *
  72. * *
  73. * WARNINGS: none *
  74. * *
  75. * HISTORY: *
  76. * 08/10/1995 JLB : Created. *
  77. * 08/10/1995 JLB : Revamped for free smooth scrolling. *
  78. * 08/25/1995 JLB : Handles new scrolling option. *
  79. *=============================================================================================*/
  80. #define EVA_WIDTH 80
  81. void ScrollClass::AI(KeyNumType &input, int x, int y)
  82. {
  83. #if 0
  84. bool player_scrolled=false;
  85. static DirType direction;
  86. int rate;
  87. /*
  88. ** If rubber band mode is in progress, then don't allow scrolling of the tactical map.
  89. */
  90. if (!IsRubberBand /*&& !IsTentative*/) {
  91. /*
  92. ** Special check to not scroll within the special no-scroll regions.
  93. */
  94. bool noscroll = false;
  95. if (!noscroll) {
  96. bool at_screen_edge = (y == 0 || x == 0 || x >= SeenBuff.Get_Width()-1 || y >= SeenBuff.Get_Height()-1);
  97. /*
  98. ** Verify that the mouse is over a scroll region.
  99. */
  100. if (Inertia || at_screen_edge) {
  101. if (at_screen_edge) {
  102. player_scrolled=true;
  103. /*
  104. ** Adjust the mouse coordinates to emphasize the
  105. ** cardinal directions over the diagonals.
  106. */
  107. int altx = x;
  108. if (altx < 50 * RESFACTOR) altx -= ((50 * RESFACTOR)-altx);
  109. altx = max(altx, 0);
  110. if (altx > ((320-50) * RESFACTOR)) altx += altx-((320-50) * RESFACTOR);
  111. altx = min(altx, (320 * RESFACTOR));
  112. if (altx > (50 * RESFACTOR) && altx < ((320-50) * RESFACTOR)) {
  113. altx += (((320/2) * RESFACTOR)-altx)/2;
  114. }
  115. int alty = y;
  116. if (alty < (50 * RESFACTOR)) alty -= (50 * RESFACTOR)-alty;
  117. alty = max(alty, 0);
  118. if (alty > (150 * RESFACTOR)) alty += alty-(150 * RESFACTOR);
  119. alty = min(alty, 200 * RESFACTOR);
  120. direction = (DirType)Desired_Facing256((320/2) * RESFACTOR, (200/2) * RESFACTOR, altx, alty);
  121. }
  122. int control = Dir_Facing(direction);
  123. /*
  124. ** The mouse is over a scroll region so set the mouse shape accordingly if the map
  125. ** can be scrolled in the direction indicated.
  126. */
  127. static int _rate[9] = {
  128. 0x00E0*RESFACTOR,
  129. 0x00C0*RESFACTOR,
  130. 0x00A0*RESFACTOR,
  131. 0x0080*RESFACTOR,
  132. 0x0060*RESFACTOR,
  133. 0x0040*RESFACTOR,
  134. 0x0020*RESFACTOR,
  135. 0x0010*RESFACTOR,
  136. 0x0008*RESFACTOR
  137. };
  138. if (Debug_Map) {
  139. rate = Options.ScrollRate+1;
  140. } else {
  141. rate = 8-Inertia;
  142. }
  143. if (rate < Options.ScrollRate+1) {
  144. rate = Options.ScrollRate+1;
  145. Inertia = 8-rate;
  146. }
  147. /*
  148. ** Increase the scroll rate if the mouse button is held down.
  149. */
  150. // if (Keyboard->Down(KN_LMOUSE)) {
  151. // rate = Bound(rate-3, 0, 4);
  152. // }
  153. if (Keyboard->Down(KN_RMOUSE)) {
  154. rate = Bound(rate+1, 4, (int)(sizeof(_rate)/sizeof(_rate[0]))-1);
  155. }
  156. /*
  157. ** If options indicate that scrolling should be forced to
  158. ** one of the 8 facings, then adjust the direction value
  159. ** accordingly.
  160. */
  161. direction = Facing_Dir(Dir_Facing(direction));
  162. int distance = _rate[rate]/2;
  163. if (!Scroll_Map(direction, distance, false)) {
  164. Override_Mouse_Shape((MouseType)(MOUSE_NO_N+control), false);
  165. } else {
  166. Override_Mouse_Shape((MouseType)(MOUSE_N+control), false);
  167. /*
  168. ** If the mouse button is pressed or auto scrolling is active, then scroll
  169. ** the map if the delay counter indicates.
  170. */
  171. if (Keyboard->Down(KN_LMOUSE) || IsAutoScroll) {
  172. distance = _rate[rate];
  173. if (Debug_Map) {
  174. Scroll_Map(direction, distance, true);
  175. Counter = SCROLL_DELAY;
  176. } else {
  177. distance = _rate[rate];
  178. Scroll_Map(direction, distance, true);
  179. if (Counter == 0 && player_scrolled) {
  180. Counter = SCROLL_DELAY;
  181. Inertia++;
  182. }
  183. }
  184. }
  185. }
  186. }
  187. if (!Debug_Map && !player_scrolled) {
  188. if (!Counter) {
  189. Inertia--;
  190. if (Inertia<0) Inertia++;
  191. Counter = SCROLL_DELAY;
  192. }
  193. }
  194. }
  195. }
  196. #endif
  197. HelpClass::AI(input, x, y);
  198. }
  199. /***********************************************************************************************
  200. * ScrollClass::Set_Autoscroll -- Turns autoscrolling on or off. *
  201. * *
  202. * This routine controls the autoscrolling setting. Autoscroll, when active, will cause the *
  203. * map to scroll if the mouse is held over the scroll region. This is regardless of whether *
  204. * any mouse button is held down or not. *
  205. * *
  206. * INPUT: control -- Should the autoscroll be turned on? *
  207. * 0 = turn off *
  208. * 1 = turn on *
  209. * -1 = toggle current setting *
  210. * *
  211. * OUTPUT: Returns with the old setting of the autoscroll flag. *
  212. * *
  213. * WARNINGS: none *
  214. * *
  215. * HISTORY: *
  216. * 08/10/1995 JLB : Created. *
  217. *=============================================================================================*/
  218. bool ScrollClass::Set_Autoscroll(int control)
  219. {
  220. bool old = IsAutoScroll;
  221. switch (control) {
  222. case -1:
  223. IsAutoScroll = !IsAutoScroll;
  224. break;
  225. default:
  226. IsAutoScroll = control;
  227. break;
  228. }
  229. return(old);
  230. }