SCROLL.CPP 11 KB

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