SCROLL.CPP 11 KB

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