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