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