SCROLL.CPP 11 KB

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