SIDEBAR.CPP 109 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067106810691070107110721073107410751076107710781079108010811082108310841085108610871088108910901091109210931094109510961097109810991100110111021103110411051106110711081109111011111112111311141115111611171118111911201121112211231124112511261127112811291130113111321133113411351136113711381139114011411142114311441145114611471148114911501151115211531154115511561157115811591160116111621163116411651166116711681169117011711172117311741175117611771178117911801181118211831184118511861187118811891190119111921193119411951196119711981199120012011202120312041205120612071208120912101211121212131214121512161217121812191220122112221223122412251226122712281229123012311232123312341235123612371238123912401241124212431244124512461247124812491250125112521253125412551256125712581259126012611262126312641265126612671268126912701271127212731274127512761277127812791280128112821283128412851286128712881289129012911292129312941295129612971298129913001301130213031304130513061307130813091310131113121313131413151316131713181319132013211322132313241325132613271328132913301331133213331334133513361337133813391340134113421343134413451346134713481349135013511352135313541355135613571358135913601361136213631364136513661367136813691370137113721373137413751376137713781379138013811382138313841385138613871388138913901391139213931394139513961397139813991400140114021403140414051406140714081409141014111412141314141415141614171418141914201421142214231424142514261427142814291430143114321433143414351436143714381439144014411442144314441445144614471448144914501451145214531454145514561457145814591460146114621463146414651466146714681469147014711472147314741475147614771478147914801481148214831484148514861487148814891490149114921493149414951496149714981499150015011502150315041505150615071508150915101511151215131514151515161517151815191520152115221523152415251526152715281529153015311532153315341535153615371538153915401541154215431544154515461547154815491550155115521553155415551556155715581559156015611562156315641565156615671568156915701571157215731574157515761577157815791580158115821583158415851586158715881589159015911592159315941595159615971598159916001601160216031604160516061607160816091610161116121613161416151616161716181619162016211622162316241625162616271628162916301631163216331634163516361637163816391640164116421643164416451646164716481649165016511652165316541655165616571658165916601661166216631664166516661667166816691670167116721673167416751676167716781679168016811682168316841685168616871688168916901691169216931694169516961697169816991700170117021703170417051706170717081709171017111712171317141715171617171718171917201721172217231724172517261727172817291730173117321733173417351736173717381739174017411742174317441745174617471748174917501751175217531754175517561757175817591760176117621763176417651766176717681769177017711772177317741775177617771778177917801781178217831784178517861787178817891790179117921793179417951796179717981799180018011802180318041805180618071808180918101811181218131814181518161817181818191820182118221823182418251826182718281829183018311832183318341835183618371838183918401841184218431844184518461847184818491850185118521853185418551856185718581859186018611862186318641865186618671868186918701871187218731874187518761877187818791880188118821883188418851886188718881889189018911892189318941895189618971898189919001901190219031904190519061907190819091910191119121913191419151916191719181919192019211922192319241925192619271928192919301931193219331934193519361937193819391940194119421943194419451946194719481949195019511952195319541955195619571958195919601961196219631964196519661967196819691970197119721973197419751976197719781979198019811982198319841985198619871988198919901991199219931994199519961997199819992000200120022003200420052006200720082009201020112012201320142015201620172018201920202021202220232024202520262027202820292030203120322033203420352036203720382039204020412042204320442045204620472048204920502051205220532054205520562057205820592060206120622063206420652066206720682069207020712072207320742075207620772078207920802081208220832084208520862087208820892090209120922093209420952096209720982099210021012102210321042105210621072108210921102111211221132114211521162117211821192120212121222123212421252126212721282129213021312132213321342135213621372138213921402141214221432144214521462147214821492150215121522153215421552156215721582159216021612162216321642165216621672168216921702171217221732174217521762177217821792180218121822183218421852186218721882189219021912192219321942195219621972198219922002201220222032204220522062207220822092210221122122213221422152216221722182219222022212222222322242225222622272228222922302231223222332234223522362237223822392240224122422243224422452246224722482249225022512252225322542255225622572258225922602261226222632264226522662267226822692270227122722273227422752276227722782279228022812282228322842285228622872288228922902291229222932294229522962297229822992300230123022303230423052306230723082309231023112312231323142315231623172318231923202321232223232324232523262327232823292330233123322333233423352336233723382339234023412342234323442345234623472348234923502351235223532354235523562357235823592360236123622363236423652366236723682369237023712372237323742375237623772378237923802381238223832384238523862387238823892390239123922393239423952396239723982399240024012402240324042405240624072408240924102411241224132414241524162417241824192420242124222423242424252426242724282429243024312432
  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/SIDEBAR.CPP 2 3/17/97 1:05a Steve_tall $ */
  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 : SIDEBAR.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : October 20, 1994 *
  30. * *
  31. * Last Update : October 9, 1996 [JLB] *
  32. * *
  33. *---------------------------------------------------------------------------------------------*
  34. * Functions: *
  35. * SidebarClass::AI -- Handles player clicking on sidebar area. *
  36. * SidebarClass::Abandon_Production -- Stops production of the object specified. *
  37. * SidebarClass::Activate -- Controls the sidebar activation. *
  38. * SidebarClass::Activate_Demolish -- Controls the demolish button on the sidebar. *
  39. * SidebarClass::Activate_Repair -- Controls the repair button on the sidebar. *
  40. * SidebarClass::Activate_Upgrade -- Controls the upgrade button on the sidebar. *
  41. * SidebarClass::Add -- Adds a game object to the sidebar list. *
  42. * SidebarClass::Draw_It -- Renders the sidebar display. *
  43. * SidebarClass::Factory_Link -- Links a factory to a sidebar strip. *
  44. * SidebarClass::Init_Clear -- Sets sidebar to a known (and deactivated) state *
  45. * SidebarClass::Init_IO -- Adds buttons to the button list *
  46. * SidebarClass::Init_Theater -- Performs theater-specific initialization *
  47. * SidebarClass::One_Time -- Handles the one time game initializations. *
  48. * SidebarClass::One_Time -- Handles the one time game initializations. *
  49. * SidebarClass::Recalc -- Examines the sidebar data and updates it as necessary. *
  50. * SidebarClass::Refresh_Cells -- Intercepts the refresh, looking for sidebar controls. *
  51. * SidebarClass::SBGadgetClass::Action -- Special function that controls the mouse over the s*
  52. * SidebarClass::Scroll -- Handles scrolling the sidebar object strip. *
  53. * SidebarClass::Set_Current -- Sets a specified object that controls the sidebar display. *
  54. * SidebarClass::SidebarClass -- Default constructor for the sidebar. *
  55. * SidebarClass::SidebarClass -- This is the no initialization constructor for the sidebar. *
  56. * SidebarClass::StripClass::AI -- Input and AI processing for the side strip. *
  57. * SidebarClass::StripClass::Abandon_Produ -- Abandons production associated with sidebar. *
  58. * SidebarClass::StripClass::Activate -- Adds the strip buttons to the input system. *
  59. * SidebarClass::StripClass::Add -- Add an object to the side strip. *
  60. * SidebarClass::StripClass::Deactivate -- Removes the side strip buttons from the input syst*
  61. * SidebarClass::StripClass::Draw_It -- Render the sidebar display. *
  62. * SidebarClass::StripClass::Factory_Link -- Links a factory to a sidebar button. *
  63. * SidebarClass::StripClass::Flag_To_Redra -- Flags the sidebar strip to be redrawn. *
  64. * SidebarClass::StripClass::Get_Special_Cameo -- Fetches the special event cameo shape. *
  65. * SidebarClass::StripClass::Init_Clear -- Sets sidebar to a known (and deactivated) state *
  66. * SidebarClass::StripClass::Init_IO -- Adds buttons to the button list *
  67. * SidebarClass::StripClass::Init_Theater -- Performs theater-specific initialization *
  68. * SidebarClass::StripClass::One_Time -- Performs one time actions necessary for the side str*
  69. * SidebarClass::StripClass::Recalc -- Revalidates the current sidebar list of objects. *
  70. * SidebarClass::StripClass::Scroll -- Causes the side strip to scroll. *
  71. * SidebarClass::StripClass::SelectClass:: -- Action function when buildable cameo is selecte*
  72. * SidebarClass::StripClass::SelectClass:: -- Assigns special values to a buildable select bu*
  73. * SidebarClass::StripClass::SelectClass::SelectClass -- Default constructor. *
  74. * SidebarClass::StripClass::StripClass -- Default constructor for the side strip class. *
  75. * SidebarClass::Which_Column -- Determines which column a given type should appear. *
  76. * SidebarClass::Zoom_Mode_Control -- Handles the zoom mode toggle operation. *
  77. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  78. #include "function.h"
  79. void * SidebarClass::SidebarShape = NULL;
  80. void * SidebarClass::SidebarMiddleShape = NULL;
  81. void * SidebarClass::SidebarBottomShape = NULL;
  82. /***************************************************************************
  83. ** This holds the translucent table for use with the construction clock
  84. ** animation.
  85. */
  86. char SidebarClass::StripClass::ClockTranslucentTable[(1+1)*256];
  87. /***************************************************************************
  88. ** This points to the main sidebar shapes. These include the upgrade and
  89. ** repair buttons.
  90. */
  91. //TheaterType SidebarClass::StripClass::LastTheater = THEATER_NONE;
  92. typedef enum ButtonNumberType {
  93. BUTTON_RADAR = 100,
  94. BUTTON_REPAIR,
  95. BUTTON_DEMOLISH,
  96. BUTTON_UPGRADE,
  97. BUTTON_SELECT,
  98. BUTTON_ZOOM
  99. } ButtonNumberType;
  100. /*
  101. ** Sidebar buttons
  102. */
  103. SidebarClass::SBGadgetClass SidebarClass::Background;
  104. ShapeButtonClass SidebarClass::Repair;
  105. ShapeButtonClass SidebarClass::Upgrade;
  106. ShapeButtonClass SidebarClass::Zoom;
  107. ShapeButtonClass SidebarClass::StripClass::UpButton[COLUMNS];
  108. ShapeButtonClass SidebarClass::StripClass::DownButton[COLUMNS];
  109. SidebarClass::StripClass::SelectClass
  110. SidebarClass::StripClass::SelectButton[COLUMNS][MAX_VISIBLE];
  111. /*
  112. ** Shape data pointers
  113. */
  114. void * SidebarClass::StripClass::LogoShapes = NULL;
  115. void const * SidebarClass::StripClass::ClockShapes;
  116. void const * SidebarClass::StripClass::SpecialShapes[SPC_COUNT];
  117. /***********************************************************************************************
  118. * SidebarClass::SidebarClass -- Default constructor for the sidebar. *
  119. * *
  120. * Constructor for the sidebar handler. It basically sets up the sidebar to the empty *
  121. * condition. *
  122. * *
  123. * INPUT: none *
  124. * *
  125. * OUTPUT: none *
  126. * *
  127. * WARNINGS: none *
  128. * *
  129. * HISTORY: *
  130. * 11/17/1994 JLB : Created. *
  131. *=============================================================================================*/
  132. SidebarClass::SidebarClass(void) :
  133. IsSidebarActive(false),
  134. IsToRedraw(true),
  135. IsRepairActive(false),
  136. IsUpgradeActive(false),
  137. IsDemolishActive(false)
  138. {
  139. /*
  140. ** This sets up the clipping window. This window is used by the shape drawing
  141. ** code so that as the sidebar buildable buttons scroll, they get properly
  142. ** clipped at the top and bottom edges.
  143. */
  144. WindowList[WINDOW_SIDEBAR][WINDOWX] = (SIDE_X+8);
  145. WindowList[WINDOW_SIDEBAR][WINDOWY] = SIDE_Y + 1 + TOP_HEIGHT;
  146. WindowList[WINDOW_SIDEBAR][WINDOWWIDTH] = SIDE_WIDTH;
  147. WindowList[WINDOW_SIDEBAR][WINDOWHEIGHT] = StripClass::MAX_VISIBLE * StripClass::OBJECT_HEIGHT;
  148. // WindowList[WINDOW_SIDEBAR][WINDOWHEIGHT] = StripClass::MAX_VISIBLE * StripClass::OBJECT_HEIGHT-1;
  149. /*
  150. ** Set up the coordinates for the sidebar strips. These coordinates are for
  151. ** the upper left corner.
  152. */
  153. new (&Column[0]) StripClass(InitClass());
  154. new (&Column[1]) StripClass(InitClass());
  155. Column[0].X = COLUMN_ONE_X * RESFACTOR;
  156. Column[0].Y = COLUMN_ONE_Y * RESFACTOR;
  157. Column[1].X = COLUMN_TWO_X * RESFACTOR;
  158. Column[1].Y = COLUMN_TWO_Y * RESFACTOR;
  159. }
  160. /***********************************************************************************************
  161. * SidebarClass::SidebarClass -- This is the no initialization constructor for the sidebar. *
  162. * *
  163. * Unlike the normal constructor, this one doesn't do any initialization. There is one *
  164. * exception to this. The stip classes can't call an explicit NoInitClass constructor *
  165. * since they are an array. Since the default constructor is called for these strips, we *
  166. * must reset the X and Y location to what we know they should be. *
  167. * *
  168. * INPUT: flag to indicate that this is a no initialization constructor. *
  169. * *
  170. * OUTPUT: none *
  171. * *
  172. * WARNINGS: none *
  173. * *
  174. * HISTORY: *
  175. * 08/06/1996 JLB : Created. *
  176. *=============================================================================================*/
  177. SidebarClass::SidebarClass(NoInitClass const & x) : PowerClass(x)
  178. {
  179. /*
  180. ** Set up the coordinates for the sidebar strips. These coordinates are for
  181. ** the upper left corner.
  182. */
  183. // Column[0].X = COLUMN_ONE_X * RESFACTOR;
  184. // Column[0].Y = COLUMN_ONE_Y * RESFACTOR;
  185. // Column[1].X = COLUMN_TWO_X * RESFACTOR;
  186. // Column[1].Y = COLUMN_TWO_Y * RESFACTOR;
  187. }
  188. /***********************************************************************************************
  189. * SidebarClass::One_Time -- Handles the one time game initializations. *
  190. * *
  191. * This routine is used to load the graphic data that is needed by the sidebar display. It *
  192. * should only be called ONCE. *
  193. * *
  194. * INPUT: none *
  195. * *
  196. * OUTPUT: none *
  197. * *
  198. * WARNINGS: Only call this routine once when the game first starts. *
  199. * *
  200. * HISTORY: *
  201. * 10/28/94 JLB : Created. *
  202. *=============================================================================================*/
  203. void SidebarClass::One_Time(void)
  204. {
  205. PowerClass::One_Time();
  206. /*
  207. ** This sets up the clipping window. This window is used by the shape drawing
  208. ** code so that as the sidebar buildable buttons scroll, they get properly
  209. ** clipped at the top and bottom edges.
  210. */
  211. WindowList[WINDOW_SIDEBAR][WINDOWX] = ((SIDE_X+8)) * RESFACTOR;
  212. WindowList[WINDOW_SIDEBAR][WINDOWY] = (SIDE_Y + 1 + TOP_HEIGHT) * RESFACTOR;
  213. WindowList[WINDOW_SIDEBAR][WINDOWWIDTH] = (SIDE_WIDTH) * RESFACTOR;
  214. WindowList[WINDOW_SIDEBAR][WINDOWHEIGHT] = (StripClass::MAX_VISIBLE * StripClass::OBJECT_HEIGHT) * RESFACTOR;
  215. // WindowList[WINDOW_SIDEBAR][WINDOWHEIGHT] = (StripClass::MAX_VISIBLE * StripClass::OBJECT_HEIGHT-1) * RESFACTOR;
  216. /*
  217. ** Top of the window seems to be wrong for the new sidebar. ST - 5/2/96 2:49AM
  218. */
  219. WindowList[WINDOW_SIDEBAR][WINDOWY] -= 1*RESFACTOR;
  220. /*
  221. ** Set up the coordinates for the sidebar strips. These coordinates are for
  222. ** the upper left corner.
  223. */
  224. // Column[0].X = COLUMN_ONE_X * RESFACTOR;
  225. // Column[0].Y = COLUMN_ONE_Y * RESFACTOR;
  226. // Column[1].X = COLUMN_TWO_X * RESFACTOR;
  227. // Column[1].Y = COLUMN_TWO_Y * RESFACTOR;
  228. Column[0].One_Time(0);
  229. Column[1].One_Time(1);
  230. /*
  231. ** Load the sidebar shape in at this time. (Hi-Res sidebar is theater dependant)
  232. */
  233. if (SidebarShape == NULL) {
  234. SidebarShape = (void*)MFCD::Retrieve("SIDEBAR.SHP");
  235. }
  236. }
  237. /***********************************************************************************************
  238. * SidebarClass::Init_Clear -- Sets sidebar to a known (and deactivated) state *
  239. * *
  240. * INPUT: none *
  241. * *
  242. * OUTPUT: none *
  243. * *
  244. * WARNINGS: none *
  245. * *
  246. * HISTORY: *
  247. * 12/24/1994 JLB : Created. *
  248. *=============================================================================================*/
  249. void SidebarClass::Init_Clear(void)
  250. {
  251. PowerClass::Init_Clear();
  252. IsToRedraw = true;
  253. IsRepairActive = false;
  254. IsUpgradeActive = false;
  255. IsDemolishActive = false;
  256. Column[0].Init_Clear();
  257. Column[1].Init_Clear();
  258. Activate(false);
  259. }
  260. /***********************************************************************************************
  261. * SidebarClass::Init_IO -- Adds buttons to the button list *
  262. * *
  263. * INPUT: none *
  264. * *
  265. * OUTPUT: none *
  266. * *
  267. * WARNINGS: none *
  268. * *
  269. * HISTORY: *
  270. * 12/24/1994 JLB : Created. *
  271. *=============================================================================================*/
  272. void SidebarClass::Init_IO(void)
  273. {
  274. PowerClass::Init_IO();
  275. /*
  276. ** Add the sidebar's buttons only if we're not in editor mode.
  277. */
  278. if (!Debug_Map) {
  279. Repair.IsSticky = true;
  280. Repair.ID = BUTTON_REPAIR;
  281. Repair.X = (0x1f2/2)*RESFACTOR;
  282. Repair.Y = (0x96/2)*RESFACTOR;
  283. Repair.IsPressed = false;
  284. Repair.IsToggleType = true;
  285. Repair.ReflectButtonState = true;
  286. Repair.Set_Shape(MFCD::Retrieve("REPAIR.SHP"));
  287. Upgrade.IsSticky = true;
  288. Upgrade.ID = BUTTON_UPGRADE;
  289. #ifdef WIN32
  290. Upgrade.X = 0x21f;
  291. #else
  292. Upgrade.X = ((0x21f/2)+1)*RESFACTOR;
  293. #endif
  294. Upgrade.Y = (0x96/2)*RESFACTOR;
  295. Upgrade.IsPressed = false;
  296. Upgrade.IsToggleType = true;
  297. Upgrade.ReflectButtonState = true;
  298. Upgrade.Set_Shape(MFCD::Retrieve("SELL.SHP"));
  299. Zoom.IsSticky = true;
  300. Zoom.ID = BUTTON_ZOOM;
  301. Zoom.X = (0x24c/2)*RESFACTOR;
  302. Zoom.Y = (0x96/2)*RESFACTOR;
  303. Zoom.IsPressed = false;
  304. Zoom.Set_Shape(MFCD::Retrieve("MAP.SHP"));
  305. if ((IsRadarActive && Is_Zoomable()) || Session.Type != GAME_NORMAL) {
  306. Zoom.Enable();
  307. } else {
  308. Zoom.Disable();
  309. }
  310. Column[0].Init_IO(0);
  311. Column[1].Init_IO(1);
  312. /*
  313. ** If a game was loaded & the sidebar was enabled, pop it up now
  314. */
  315. if (IsSidebarActive) {
  316. IsSidebarActive = false;
  317. Activate(1);
  318. // Background.Zap();
  319. // Add_A_Button(Background);
  320. }
  321. }
  322. }
  323. /***********************************************************************************************
  324. * SidebarClass::Init_Theater -- Performs theater-specific initialization *
  325. * *
  326. * INPUT: theater -- The theater that is being initialized. Sometimes this has an effect on *
  327. * the data that is loaded. *
  328. * *
  329. * OUTPUT: none *
  330. * *
  331. * WARNINGS: none *
  332. * *
  333. * HISTORY: *
  334. * 12/24/1994 JLB : Created. *
  335. *=============================================================================================*/
  336. void SidebarClass::Init_Theater(TheaterType theater)
  337. {
  338. Reload_Sidebar();
  339. PowerClass::Init_Theater(theater);
  340. Column[0].Init_Theater(theater);
  341. Column[1].Init_Theater(theater);
  342. }
  343. /***********************************************************************************************
  344. * SidebarClass::Reload_Sidebar -- Loads appropriate sidebar shapes depending on house *
  345. * *
  346. * INPUT: none *
  347. * *
  348. * OUTPUT: none *
  349. * *
  350. * WARNINGS: none *
  351. * *
  352. * HISTORY: *
  353. * 9/18/1996 BWG : Created. *
  354. *=============================================================================================*/
  355. void SidebarClass::Reload_Sidebar(void)
  356. {
  357. static char * sidebarnames[]={
  358. "SIDE?NA.SHP", //NATO
  359. "SIDE?NA.SHP",
  360. "SIDE?US.SHP", //USSR
  361. "SIDE?NA.SHP",
  362. "SIDE?US.SHP", //UKRAINE
  363. "SIDE?NA.SHP",
  364. "SIDE?NA.SHP",
  365. "SIDE?NA.SHP",
  366. "SIDE?NA.SHP", //HOUSE_GOOD
  367. "SIDE?US.SHP" //HOUSE_BAD
  368. };
  369. int houseloaded = 0;
  370. if(PlayerPtr) {
  371. houseloaded = PlayerPtr->ActLike;
  372. }
  373. char * sidename = sidebarnames[houseloaded];
  374. *(sidename+4) = '1';
  375. SidebarShape = (void*)MFCD::Retrieve(sidename);
  376. *(sidename+4) = '2';
  377. SidebarMiddleShape = (void*)MFCD::Retrieve(sidename);
  378. *(sidename+4) = '3';
  379. SidebarBottomShape = (void*)MFCD::Retrieve(sidename);
  380. Column[0].Reload_LogoShapes();
  381. Column[1].Reload_LogoShapes();
  382. }
  383. /***********************************************************************************************
  384. * SidebarClass::Which_Column -- Determines which column a given type should appear. *
  385. * *
  386. * Use this function to resolve what column the specified object type should be placed *
  387. * into. *
  388. * *
  389. * INPUT: otype -- Pointer to the object type class of the object in question. *
  390. * *
  391. * OUTPUT: Returns with the column number that the object should be placed in. *
  392. * *
  393. * WARNINGS: none *
  394. * *
  395. * HISTORY: *
  396. * 01/01/1995 JLB : Created. *
  397. *=============================================================================================*/
  398. int SidebarClass::Which_Column(RTTIType type)
  399. {
  400. if (type == RTTI_BUILDINGTYPE || type == RTTI_BUILDING) {
  401. return(0);
  402. }
  403. return(1);
  404. }
  405. /***********************************************************************************************
  406. * SidebarClass::Factory_Link -- Links a factory to a sidebar strip. *
  407. * *
  408. * This routine will link the specified factory to the sidebar strip. A factory must be *
  409. * linked to the sidebar so that as the factory production progresses, the sidebar will *
  410. * show the production progress. *
  411. * *
  412. * INPUT: factory -- The factory number to attach. *
  413. * *
  414. * type -- The object type number. *
  415. * *
  416. * id -- The object sub-type number. *
  417. * *
  418. * OUTPUT: Was the factory successfully attached to the sidebar strip? *
  419. * *
  420. * WARNINGS: none *
  421. * *
  422. * HISTORY: *
  423. * 05/19/1995 JLB : Created. *
  424. *=============================================================================================*/
  425. bool SidebarClass::Factory_Link(int factory, RTTIType type, int id)
  426. {
  427. assert((unsigned)type < RTTI_COUNT);
  428. assert(id >= 0);
  429. return(Column[Which_Column(type)].Factory_Link(factory, type, id));
  430. }
  431. /***********************************************************************************************
  432. * SidebarClass::Refresh_Cells -- Intercepts the refresh, looking for sidebar controls. *
  433. * *
  434. * This routine intercepts the Refresh_Cells call in order to see if the sidebar needs *
  435. * to be refreshed as well. If the special code to refresh the sidebar was found, it *
  436. * flags the sidebar to be redrawn and then removes the code from the list. *
  437. * *
  438. * INPUT: cell -- The cell to base the refresh list on. *
  439. * *
  440. * list -- Pointer to the cell offset list that elaborates all the cells that *
  441. * need to be flagged for redraw. *
  442. * *
  443. * OUTPUT: none *
  444. * *
  445. * WARNINGS: none *
  446. * *
  447. * HISTORY: *
  448. * 01/19/1995 JLB : Created. *
  449. *=============================================================================================*/
  450. void SidebarClass::Refresh_Cells(CELL cell, short const * list)
  451. {
  452. if (*list == REFRESH_SIDEBAR) {
  453. IsToRedraw = true;
  454. Column[0].IsToRedraw = true;
  455. Column[1].IsToRedraw = true;
  456. Flag_To_Redraw(false);
  457. }
  458. PowerClass::Refresh_Cells(cell, list);
  459. }
  460. /***********************************************************************************************
  461. * SidebarClass::Activate_Repair -- Controls the repair button on the sidebar. *
  462. * *
  463. * Use this routine to turn the repair sidebar button on and off. Typically, the button *
  464. * is enabled when the currently selected structure is friendly and damaged. *
  465. * *
  466. * INPUT: control -- The controls how the button is to be activated or deactivated; *
  467. * 0 -- Turn button off. *
  468. * 1 -- Turn button on. *
  469. * -1 -- Toggle button state. *
  470. * *
  471. * OUTPUT: bool; Was the button previously activated? *
  472. * *
  473. * WARNINGS: none *
  474. * *
  475. * HISTORY: *
  476. * 12/24/1994 JLB : Created. *
  477. *=============================================================================================*/
  478. bool SidebarClass::Activate_Repair(int control)
  479. {
  480. bool old = IsRepairActive;
  481. if (control == -1) {
  482. control = IsRepairActive ? 0 : 1;
  483. }
  484. switch (control) {
  485. case 1:
  486. IsRepairActive = true;
  487. break;
  488. default:
  489. case 0:
  490. IsRepairActive = false;
  491. break;
  492. }
  493. if (old != IsRepairActive) {
  494. Flag_To_Redraw(false);
  495. IsToRedraw = true;
  496. if (!IsRepairActive) {
  497. Help_Text(TXT_NONE);
  498. Set_Default_Mouse(MOUSE_NORMAL, false);
  499. }
  500. }
  501. return(old);
  502. }
  503. /***********************************************************************************************
  504. * SidebarClass::Activate_Upgrade -- Controls the upgrade button on the sidebar. *
  505. * *
  506. * Use this routine to turn the upgrade sidebar button on and off. Typically, the button *
  507. * is enabled when the currently selected structure can be upgraded and disabled otherwise. *
  508. * *
  509. * INPUT: control -- The controls how the button is to be activated or deactivated; *
  510. * 0 -- Turn button off. *
  511. * 1 -- Turn button on. *
  512. * -1 -- Toggle button state. *
  513. * *
  514. * OUTPUT: bool; Was the button previously activated? *
  515. * *
  516. * WARNINGS: none *
  517. * *
  518. * HISTORY: *
  519. * 12/24/1994 JLB : Created. *
  520. *=============================================================================================*/
  521. bool SidebarClass::Activate_Upgrade(int control)
  522. {
  523. bool old = IsUpgradeActive;
  524. if (control == -1) {
  525. control = IsUpgradeActive ? 0 : 1;
  526. }
  527. switch (control) {
  528. case 1:
  529. IsUpgradeActive = true;
  530. break;
  531. default:
  532. case 0:
  533. IsUpgradeActive = false;
  534. break;
  535. }
  536. if (old != IsUpgradeActive) {
  537. Flag_To_Redraw(false);
  538. IsToRedraw = true;
  539. if (!IsUpgradeActive) {
  540. Set_Default_Mouse(MOUSE_NORMAL, false);
  541. }
  542. }
  543. return(old);
  544. }
  545. /***********************************************************************************************
  546. * SidebarClass::Activate_Demolish -- Controls the demolish button on the sidebar. *
  547. * *
  548. * Use this routine to turn the demolish/dismantle sidebar button on and off. Typically, *
  549. * the button is enabled when a friendly building is selected and disabled otherwise. *
  550. * *
  551. * INPUT: control -- The controls how the button is to be activated or deactivated; *
  552. * 0 -- Turn button off. *
  553. * 1 -- Turn button on. *
  554. * -1 -- Toggle button state. *
  555. * *
  556. * OUTPUT: bool; Was the button previously activated? *
  557. * *
  558. * WARNINGS: none *
  559. * *
  560. * HISTORY: *
  561. * 12/24/1994 JLB : Created. *
  562. *=============================================================================================*/
  563. bool SidebarClass::Activate_Demolish(int control)
  564. {
  565. bool old = IsDemolishActive;
  566. if (control == -1) {
  567. control = IsDemolishActive ? 0 : 1;
  568. }
  569. switch (control) {
  570. case 1:
  571. IsDemolishActive = true;
  572. break;
  573. default:
  574. case 0:
  575. IsDemolishActive = false;
  576. break;
  577. }
  578. if (old != IsDemolishActive) {
  579. Flag_To_Redraw(false);
  580. IsToRedraw = true;
  581. if (!IsDemolishActive) {
  582. Set_Default_Mouse(MOUSE_NORMAL, false);
  583. }
  584. }
  585. return(old);
  586. }
  587. /***********************************************************************************************
  588. * SidebarClass::Add -- Adds a game object to the sidebar list. *
  589. * *
  590. * This routine is used to add a game object to the sidebar. Call this routine when a *
  591. * factory type building is created. It handles the case of adding an item that has already *
  592. * been added -- it just ignores it. *
  593. * *
  594. * INPUT: object -- Pointer to the object that is being added. *
  595. * *
  596. * OUTPUT: bool; Was the object added to the sidebar? *
  597. * *
  598. * WARNINGS: none *
  599. * *
  600. * HISTORY: *
  601. * 11/17/1994 JLB : Created. *
  602. *=============================================================================================*/
  603. bool SidebarClass::Add(RTTIType type, int id)
  604. {
  605. assert((unsigned)type < RTTI_COUNT);
  606. /*
  607. ** Add the sidebar only if we're not in editor mode.
  608. */
  609. if (!Debug_Map) {
  610. int column = Which_Column(type);
  611. if (Column[column].Add(type, id)) {
  612. Activate(1);
  613. IsToRedraw = true;
  614. Flag_To_Redraw(false);
  615. return(true);
  616. }
  617. return(false);
  618. }
  619. return(false);
  620. }
  621. /***********************************************************************************************
  622. * SidebarClass::Scroll -- Handles scrolling the sidebar object strip. *
  623. * *
  624. * This routine is used to scroll the sidebar strip of objects. The strip appears whenever *
  625. * a building is selected that can produce units. If the number of units to produce is *
  626. * greater than what the sidebar can hold, this routine is used to scroll the other object *
  627. * into view so they can be selected. *
  628. * *
  629. * INPUT: up -- Should the scroll be upwards? Upward scrolling reveals object that are *
  630. * later in the list of objects. *
  631. * *
  632. * OUTPUT: bool; Did scrolling occur? *
  633. * *
  634. * WARNINGS: none *
  635. * *
  636. * HISTORY: *
  637. * 10/28/94 JLB : Created. *
  638. *=============================================================================================*/
  639. bool SidebarClass::Scroll(bool up, int column)
  640. {
  641. if (column == -1) {
  642. bool scr = false;
  643. scr |= Column[0].Scroll(up);
  644. scr |= Column[1].Scroll(up);
  645. if (!scr) {
  646. Sound_Effect(VOC_SCOLD);
  647. }
  648. if (scr) {
  649. IsToRedraw = true;
  650. Flag_To_Redraw(false);
  651. return(true);
  652. }
  653. return(false);
  654. }
  655. if (Column[column].Scroll(up)) {
  656. // No need to redraw the whole sidebar juts because we scrolled a strip is there? ST - 10/15/96 7:29PM
  657. //IsToRedraw = true;
  658. Flag_To_Redraw(false);
  659. return(true);
  660. }
  661. return(false);
  662. }
  663. /***********************************************************************************************
  664. * SidebarClass::Draw_It -- Renders the sidebar display. *
  665. * *
  666. * This routine performs the actual drawing of the sidebar display. *
  667. * *
  668. * INPUT: none *
  669. * *
  670. * OUTPUT: bool; Was the sidebar imagery changed at all? *
  671. * *
  672. * WARNINGS: none *
  673. * *
  674. * HISTORY: *
  675. * 10/28/94 JLB : Created. *
  676. * 12/31/1994 JLB : Split rendering off into the sidebar strip class. *
  677. *=============================================================================================*/
  678. void SidebarClass::Draw_It(bool complete)
  679. {
  680. PowerClass::Draw_It(complete);
  681. BStart(BENCH_SIDEBAR);
  682. if (IsSidebarActive && (IsToRedraw || complete) && !Debug_Map) {
  683. IsToRedraw = false;
  684. if (LogicPage->Lock()) {
  685. /*
  686. ** Draw the outline box around the sidebar buttons.
  687. */
  688. int shape = complete ? 0 : 1;
  689. /*
  690. ** The sidebar shape is too big in 640x400 so it needs to be drawn in three chunks.
  691. */
  692. CC_Draw_Shape(SidebarShape, 0, SIDE_X * RESFACTOR, 8*RESFACTOR, WINDOW_MAIN, SHAPE_WIN_REL);
  693. CC_Draw_Shape(SidebarMiddleShape, shape, SIDE_X * RESFACTOR, (8+80)*RESFACTOR, WINDOW_MAIN, SHAPE_WIN_REL);
  694. CC_Draw_Shape(SidebarBottomShape, shape, SIDE_X * RESFACTOR, (8+80+50)*RESFACTOR, WINDOW_MAIN, SHAPE_WIN_REL);
  695. Repair.Draw_Me(true);
  696. Upgrade.Draw_Me(true);
  697. Zoom.Draw_Me(true);
  698. LogicPage->Unlock();
  699. }
  700. }
  701. /*
  702. ** Draw the side strip elements by calling their respective draw functions.
  703. */
  704. if (IsSidebarActive) {
  705. Column[0].Draw_It(complete);
  706. Column[1].Draw_It(complete);
  707. if (complete || IsToRedraw) {
  708. Repair.Draw_Me(true);
  709. Upgrade.Draw_Me(true);
  710. Zoom.Draw_Me(true);
  711. }
  712. }
  713. IsToRedraw = false;
  714. BEnd(BENCH_SIDEBAR);
  715. }
  716. /***********************************************************************************************
  717. * SidebarClass::AI -- Handles player clicking on sidebar area. *
  718. * *
  719. * This routine handles the processing necessary when the player clicks on the sidebar. *
  720. * Typically, this is selection of the item to build. *
  721. * *
  722. * INPUT: input -- Reference to the keyboard input value. *
  723. * *
  724. * x,y -- Mouse coordinates at time of input. *
  725. * *
  726. * OUTPUT: bool; Was the click handled? *
  727. * *
  728. * WARNINGS: none *
  729. * *
  730. * HISTORY: *
  731. * 10/28/94 JLB : Created. *
  732. * 11/11/1994 JLB : Processes input directly. *
  733. * 12/26/1994 JLB : Uses factory manager class for construction handling. *
  734. * 12/31/1994 JLB : Simplified to use the sidebar strip class handlers. *
  735. * 12/31/1994 JLB : Uses mouse coordinate parameters. *
  736. * 06/27/1995 JLB : <TAB> key toggles sidebar. *
  737. *=============================================================================================*/
  738. void SidebarClass::AI(KeyNumType & input, int x, int y)
  739. {
  740. bool redraw = false;
  741. /*
  742. ** Toggle the sidebar in and out with the <TAB> key.
  743. */
  744. #ifndef WIN32
  745. if (input == KN_TAB) {
  746. Activate(-1);
  747. }
  748. #else
  749. if (!Debug_Map) {
  750. Activate(1); // Force the sidebar always on in Win95 mode
  751. }
  752. #endif //WIN32
  753. if (!Debug_Map) {
  754. Column[0].AI(input, x, y);
  755. Column[1].AI(input, x, y);
  756. }
  757. #ifdef NEVER
  758. if (IsSidebarActive && !Debug_Map) {
  759. if (input == KN_DOWN) {
  760. int scr = 0;
  761. scr |= Column[0].Scroll(false);
  762. scr |= Column[1].Scroll(false);
  763. if (!scr) {
  764. Sound_Effect(VOC_SCOLD);
  765. }
  766. redraw |= scr;
  767. input = KN_NONE;
  768. }
  769. if (input == KN_UP) {
  770. int scr = 0;
  771. scr |= Column[0].Scroll(true);
  772. scr |= Column[1].Scroll(true);
  773. if (!scr) {
  774. Sound_Effect(VOC_SCOLD);
  775. }
  776. redraw |= scr;
  777. input = KN_NONE;
  778. }
  779. }
  780. #endif
  781. if (IsSidebarActive) {
  782. /*
  783. ** If there are any buildings in the payer's inventory, then allow the repair
  784. ** option.
  785. */
  786. if (PlayerPtr->BScan) {
  787. Activate_Repair(true);
  788. } else {
  789. Activate_Repair(false);
  790. }
  791. if (input == (BUTTON_REPAIR|KN_BUTTON)) {
  792. Repair_Mode_Control(-1);
  793. }
  794. if (input == (BUTTON_ZOOM|KN_BUTTON)) {
  795. Zoom_Mode_Control();
  796. }
  797. if (input == (BUTTON_UPGRADE|KN_BUTTON)) {
  798. Sell_Mode_Control(-1);
  799. }
  800. if (redraw) {
  801. //IsToRedraw = true;
  802. Column[0].Flag_To_Redraw();
  803. Column[1].Flag_To_Redraw();
  804. Flag_To_Redraw(false);
  805. }
  806. }
  807. if ((!IsRepairMode) && Repair.IsOn) {
  808. Repair.Turn_Off();
  809. }
  810. if ((!IsSellMode) && Upgrade.IsOn) {
  811. Upgrade.Turn_Off();
  812. }
  813. PowerClass::AI(input, x, y);
  814. }
  815. /***********************************************************************************************
  816. * SidebarClass::Recalc -- Examines the sidebar data and updates it as necessary. *
  817. * *
  818. * Occasionally a factory gets destroyed. This routine must be called in such a case *
  819. * because it might be possible that sidebar object need to be removed. This routine will *
  820. * examine all existing objects in the sidebar class and if no possible factory can *
  821. * produce it, then it will be removed. *
  822. * *
  823. * INPUT: none *
  824. * *
  825. * OUTPUT: none *
  826. * *
  827. * WARNINGS: This routine is exhaustive and thus time consuming. Only call it when really *
  828. * necessary. Such as when a factory is destroyed rather than when a non-factory *
  829. * is destroyed. *
  830. * *
  831. * HISTORY: *
  832. * 11/30/1994 JLB : Created. *
  833. *=============================================================================================*/
  834. void SidebarClass::Recalc(void)
  835. {
  836. bool redraw = false;
  837. redraw |= Column[0].Recalc();
  838. redraw |= Column[1].Recalc();
  839. if (redraw) {
  840. IsToRedraw = true;
  841. Flag_To_Redraw(false);
  842. }
  843. }
  844. /***********************************************************************************************
  845. * SidebarClass::Activate -- Controls the sidebar activation. *
  846. * *
  847. * Use this routine to turn the sidebar on or off. This routine handles updating the *
  848. * necessary flags. *
  849. * *
  850. * INPUT: control -- Tells what to do with the sidebar according to the following: *
  851. * 0 = Turn sidebar off. *
  852. * 1 = Turn sidebar on. *
  853. * -1= Toggle sidebar on or off. *
  854. * *
  855. * OUTPUT: bool; Was the sidebar already on? *
  856. * *
  857. * WARNINGS: none *
  858. * *
  859. * HISTORY: *
  860. * 12/09/1994 JLB : Created. *
  861. *=============================================================================================*/
  862. bool SidebarClass::Activate(int control)
  863. {
  864. bool old = IsSidebarActive;
  865. if (Session.Play)
  866. return (old);
  867. /*
  868. ** Determine the new state of the sidebar.
  869. */
  870. switch (control) {
  871. case -1:
  872. IsSidebarActive = IsSidebarActive == false;
  873. break;
  874. case 1:
  875. IsSidebarActive = true;
  876. break;
  877. default:
  878. case 0:
  879. IsSidebarActive = false;
  880. break;
  881. }
  882. /*
  883. ** Only if there is a change in the state of the sidebar will anything
  884. ** be done to change it.
  885. */
  886. if (IsSidebarActive != old) {
  887. /*
  888. ** If the sidebar is activated but was on the right side of the screen, then
  889. ** activate it on the left side of the screen.
  890. */
  891. if (IsSidebarActive /*&& X*/) {
  892. Set_View_Dimensions(0, 8 * RESFACTOR, ((320-SIDE_WIDTH)/ICON_PIXEL_W) * RESFACTOR);
  893. IsToRedraw = true;
  894. Help_Text(TXT_NONE);
  895. Repair.Zap();
  896. Add_A_Button(Repair);
  897. Upgrade.Zap();
  898. Add_A_Button(Upgrade);
  899. Zoom.Zap();
  900. Add_A_Button(Zoom);
  901. Column[0].Activate();
  902. Column[1].Activate();
  903. Background.Zap();
  904. Add_A_Button(Background);
  905. Map.RadarButton.Zap();
  906. Add_A_Button(Map.RadarButton);
  907. Map.PowerButton.Zap();
  908. Add_A_Button(Map.PowerButton);
  909. } else {
  910. Help_Text(TXT_NONE);
  911. Set_View_Dimensions(0, 8 * RESFACTOR);
  912. Remove_A_Button(Repair);
  913. Remove_A_Button(Upgrade);
  914. Remove_A_Button(Zoom);
  915. Remove_A_Button(Background);
  916. Column[0].Deactivate();
  917. Column[1].Deactivate();
  918. Remove_A_Button(Map.RadarButton);
  919. Remove_A_Button(Map.PowerButton);
  920. }
  921. /*
  922. ** Since the sidebar status has changed, update the map so that the graphics
  923. ** will be rendered correctly.
  924. */
  925. Flag_To_Redraw(true);
  926. }
  927. return(old);
  928. }
  929. /***********************************************************************************************
  930. * SidebarClass::StripClass::StripClass -- Default constructor for the side strip class. *
  931. * *
  932. * This constructor is used to reset the side strip to default empty state. *
  933. * *
  934. * INPUT: none *
  935. * *
  936. * OUTPUT: none *
  937. * *
  938. * WARNINGS: none *
  939. * *
  940. * HISTORY: *
  941. * 12/31/1994 JLB : Created. *
  942. *=============================================================================================*/
  943. SidebarClass::StripClass::StripClass(InitClass const & ) :
  944. X(0),
  945. Y(0),
  946. ID(0),
  947. IsToRedraw(true),
  948. IsBuilding(false),
  949. IsScrollingDown(false),
  950. IsScrolling(false),
  951. Flasher(-1),
  952. TopIndex(0),
  953. Scroller(0),
  954. Slid(0),
  955. BuildableCount(0)
  956. {
  957. for (int index = 0; index < MAX_BUILDABLES; index++) {
  958. Buildables[index].BuildableID = 0;
  959. Buildables[index].BuildableType = RTTI_NONE;
  960. Buildables[index].Factory = -1;
  961. }
  962. }
  963. /***********************************************************************************************
  964. * SidebarClass::StripClass::One_Time -- Performs one time actions necessary for the side stri *
  965. * *
  966. * Call this routine ONCE at the beginning of the game. It handles retrieving pointers to *
  967. * the shape files it needs for rendering. *
  968. * *
  969. * INPUT: none *
  970. * *
  971. * OUTPUT: none *
  972. * *
  973. * WARNINGS: none *
  974. * *
  975. * HISTORY: *
  976. * 12/31/1994 JLB : Created. *
  977. *=============================================================================================*/
  978. void SidebarClass::StripClass::One_Time(int )
  979. {
  980. /*
  981. ** Sidebar is player team specific in Hires
  982. */
  983. ClockShapes = MFCD::Retrieve("CLOCK.SHP");
  984. for (SpecialWeaponType lp = SPC_FIRST; lp < SPC_COUNT; lp++) {
  985. char buffer[_MAX_FNAME];
  986. sprintf(buffer, "%sICON", SpecialWeaponFile[lp]);
  987. char fullname[_MAX_FNAME+_MAX_EXT];
  988. _makepath(fullname, NULL, NULL, buffer, ".SHP");
  989. SpecialShapes[lp] = MFCD::Retrieve(fullname);
  990. }
  991. }
  992. /***********************************************************************************************
  993. * SidebarClass::StripClass::Get_Special_Cameo -- Fetches the special event cameo shape. *
  994. * *
  995. * This routine will return with a pointer to the cameo data for the special objects that *
  996. * can appear on the sidebar (e.g., nuclear bomb). *
  997. * *
  998. * INPUT: type -- The special type to fetch the cameo imagery for. *
  999. * *
  1000. * OUTPUT: Returns with a pointer to the cameo imagery for the specified special object. *
  1001. * *
  1002. * WARNINGS: none *
  1003. * *
  1004. * HISTORY: *
  1005. * 05/19/1995 JLB : commented *
  1006. *=============================================================================================*/
  1007. void const * SidebarClass::StripClass::Get_Special_Cameo(SpecialWeaponType type)
  1008. {
  1009. if ((unsigned)type < SPC_COUNT) {
  1010. return(SpecialShapes[type]);
  1011. }
  1012. return(0);
  1013. }
  1014. /***********************************************************************************************
  1015. * SidebarClass::StripClass::Init_Clear -- Sets sidebar to a known (and deactivated) state *
  1016. * *
  1017. * INPUT: none *
  1018. * *
  1019. * OUTPUT: none *
  1020. * *
  1021. * WARNINGS: none *
  1022. * *
  1023. * HISTORY: *
  1024. * 12/24/1994 JLB : Created. *
  1025. *=============================================================================================*/
  1026. void SidebarClass::StripClass::Init_Clear(void)
  1027. {
  1028. IsScrollingDown = false;
  1029. IsScrolling = false;
  1030. IsBuilding = false;
  1031. Flasher = -1;
  1032. TopIndex = 0;
  1033. Slid = 0;
  1034. BuildableCount = 0;
  1035. /*
  1036. ** Since we're resetting the strips, clear out all the buildables & factory pointers.
  1037. */
  1038. for (int index = 0; index < MAX_BUILDABLES; index++) {
  1039. Buildables[index].BuildableID = 0;
  1040. Buildables[index].BuildableType = RTTI_NONE;
  1041. Buildables[index].Factory = -1;
  1042. }
  1043. }
  1044. /***********************************************************************************************
  1045. * SidebarClass::StripClass::Init_IO -- Initializes the strip's buttons *
  1046. * *
  1047. * This routine doesn't actually add any buttons to the list. *
  1048. * *
  1049. * INPUT: none *
  1050. * *
  1051. * OUTPUT: none *
  1052. * *
  1053. * WARNINGS: none *
  1054. * *
  1055. * HISTORY: *
  1056. * 12/24/1994 JLB : Created. *
  1057. *=============================================================================================*/
  1058. void SidebarClass::StripClass::Init_IO(int id)
  1059. {
  1060. ID = id;
  1061. UpButton[ID].IsSticky = true;
  1062. UpButton[ID].ID = BUTTON_UP+id;
  1063. UpButton[ID].X = X+(UP_X_OFFSET * RESFACTOR);
  1064. UpButton[ID].Y = Y+(UP_Y_OFFSET * RESFACTOR);
  1065. #if (FRENCH)
  1066. #ifdef WIN32
  1067. UpButton[ID].Set_Shape(MFCD::Retrieve("STRIPUP.SHP"));
  1068. #else
  1069. UpButton[ID].Set_Shape(MFCD::Retrieve("STUP_FIX.SHP"));
  1070. #endif
  1071. #else //FRENCH
  1072. UpButton[ID].Set_Shape(MFCD::Retrieve("STRIPUP.SHP"));
  1073. #endif //FRENCH
  1074. DownButton[ID].IsSticky = true;
  1075. DownButton[ID].ID = BUTTON_DOWN+id;
  1076. DownButton[ID].X = X+(DOWN_X_OFFSET * RESFACTOR);
  1077. DownButton[ID].Y = Y+(DOWN_Y_OFFSET * RESFACTOR);
  1078. /*
  1079. ** Buttons are in a slightly different position in the new sidebar
  1080. */
  1081. UpButton[ID].Y--;
  1082. DownButton[ID].Y--;
  1083. DownButton[ID].Set_Shape(MFCD::Retrieve("STRIPDN.SHP"));
  1084. for (int index = 0; index < MAX_VISIBLE; index++) {
  1085. SelectClass & g = SelectButton[ID][index];
  1086. g.ID = BUTTON_SELECT;
  1087. g.X = X;
  1088. g.Y = Y + ((OBJECT_HEIGHT*index) * RESFACTOR);
  1089. g.Width = OBJECT_WIDTH * RESFACTOR;
  1090. g.Height = OBJECT_HEIGHT * RESFACTOR;
  1091. g.Set_Owner(*this, index);
  1092. }
  1093. }
  1094. /***********************************************************************************************
  1095. * SidebarClass::StripClass::Init_Theater -- Performs theater-specific initialization *
  1096. * *
  1097. * INPUT: theater *
  1098. * *
  1099. * OUTPUT: none *
  1100. * *
  1101. * WARNINGS: none *
  1102. * *
  1103. * HISTORY: *
  1104. * 12/24/1994 JLB : Created. *
  1105. *=============================================================================================*/
  1106. void SidebarClass::StripClass::Init_Theater(TheaterType theater)
  1107. {
  1108. Reload_LogoShapes();
  1109. if ( (theater != THEATER_NONE) && (theater != ::LastTheater)) {
  1110. static TLucentType const ClockCols[1] = {
  1111. {GREEN, BLACK, 100, 0}
  1112. // {GREEN, LTGREY, 180, 0}
  1113. };
  1114. /*
  1115. ** Make sure that remapping doesn't occur on the colors that cycle.
  1116. */
  1117. PaletteClass pal = OriginalPalette;
  1118. memset(&pal[CYCLE_COLOR_START*3], 0x3f, CYCLE_COLOR_COUNT*3);
  1119. Build_Translucent_Table(pal, &ClockCols[0], 1, (void*)ClockTranslucentTable);
  1120. // Mem_Copy(GamePalette, OriginalPalette, 768);
  1121. // memset(&GamePalette[CYCLE_COLOR_START*3], 0x3f, CYCLE_COLOR_COUNT*3);
  1122. /*
  1123. ** Create the translucent table used for the sidebar.
  1124. */
  1125. // Build_Translucent_Table(GamePalette, &ClockCols[0], 1, (void*)ClockTranslucentTable);
  1126. // GamePalette = OriginalPalette;
  1127. Conquer_Build_Fading_Table(GamePalette, &ClockTranslucentTable[256], BLACK, 100);
  1128. }
  1129. }
  1130. void SidebarClass::StripClass::Reload_LogoShapes(void)
  1131. {
  1132. /*
  1133. ** Load hi-res strip art here since it is player side specific
  1134. */
  1135. static char * stripnames[]={
  1136. "stripna.shp", //Nato
  1137. "stripna.shp",
  1138. "stripus.shp", //USSR
  1139. "stripna.shp",
  1140. "stripus.shp", //UKRAINE
  1141. "stripna.shp",
  1142. "stripna.shp",
  1143. "stripna.shp",
  1144. "stripna.shp", //HOUSE_GOOD
  1145. "stripus.shp", //HOUSE_BAD
  1146. };
  1147. int houseloaded = 0;
  1148. /*
  1149. ** Sidebar art is dependent on the side of the player
  1150. */
  1151. if(PlayerPtr) {
  1152. houseloaded = PlayerPtr->ActLike;
  1153. }
  1154. LogoShapes = (void*)MFCD::Retrieve(stripnames[houseloaded]);
  1155. }
  1156. /***********************************************************************************************
  1157. * SidebarClass::StripClass::Activate -- Adds the strip buttons to the input system. *
  1158. * *
  1159. * This routine will add the side strip buttons to the map's input system. This routine *
  1160. * should be called once when the sidebar activates. *
  1161. * *
  1162. * INPUT: none *
  1163. * *
  1164. * OUTPUT: none *
  1165. * *
  1166. * WARNINGS: Never call this routine a second time without first calling Deactivate(). *
  1167. * *
  1168. * HISTORY: *
  1169. * 01/19/1995 JLB : Created. *
  1170. *=============================================================================================*/
  1171. void SidebarClass::StripClass::Activate(void)
  1172. {
  1173. UpButton[ID].Zap();
  1174. Map.Add_A_Button(UpButton[ID]);
  1175. DownButton[ID].Zap();
  1176. Map.Add_A_Button(DownButton[ID]);
  1177. for (int index = 0; index < MAX_VISIBLE; index++) {
  1178. SelectButton[ID][index].Zap();
  1179. Map.Add_A_Button(SelectButton[ID][index]);
  1180. }
  1181. }
  1182. /***********************************************************************************************
  1183. * SidebarClass::StripClass::Deactivate -- Removes the side strip buttons from the input syste *
  1184. * *
  1185. * Call this routine to remove all the buttons on the side strip from the map's input *
  1186. * system. *
  1187. * *
  1188. * INPUT: none *
  1189. * *
  1190. * OUTPUT: none *
  1191. * *
  1192. * WARNINGS: Never call this routine unless the Activate() function was previously called. *
  1193. * *
  1194. * HISTORY: *
  1195. * 01/19/1995 JLB : Created. *
  1196. *=============================================================================================*/
  1197. void SidebarClass::StripClass::Deactivate(void)
  1198. {
  1199. Map.Remove_A_Button(UpButton[ID]);
  1200. Map.Remove_A_Button(DownButton[ID]);
  1201. for (int index = 0; index < MAX_VISIBLE; index++) {
  1202. Map.Remove_A_Button(SelectButton[ID][index]);
  1203. }
  1204. }
  1205. /***********************************************************************************************
  1206. * SidebarClass::StripClass::Add -- Add an object to the side strip. *
  1207. * *
  1208. * Use this routine to add a buildable object to the side strip. *
  1209. * *
  1210. * INPUT: object -- Pointer to the object type that can be built and is to be added to *
  1211. * the side strip. *
  1212. * *
  1213. * OUTPUT: bool; Was the object successfully added to the side strip? Failure could be the *
  1214. * result of running out of room in the side strip array or the object might *
  1215. * already be in the list. *
  1216. * *
  1217. * WARNINGS: none. *
  1218. * *
  1219. * HISTORY: *
  1220. * 12/31/1994 JLB : Created. *
  1221. *=============================================================================================*/
  1222. bool SidebarClass::StripClass::Add(RTTIType type, int id)
  1223. {
  1224. if (BuildableCount <= MAX_BUILDABLES) {
  1225. for (int index = 0; index < BuildableCount; index++) {
  1226. if (Buildables[index].BuildableType == type && Buildables[index].BuildableID == id) {
  1227. return(false);
  1228. }
  1229. }
  1230. if (!ScenarioInit && type != RTTI_SPECIAL) {
  1231. Speak(VOX_NEW_CONSTRUCT);
  1232. }
  1233. Buildables[BuildableCount].BuildableType = type;
  1234. Buildables[BuildableCount].BuildableID = id;
  1235. BuildableCount++;
  1236. IsToRedraw = true;
  1237. return(true);
  1238. }
  1239. return(false);
  1240. }
  1241. /***********************************************************************************************
  1242. * SidebarClass::StripClass::Scroll -- Causes the side strip to scroll. *
  1243. * *
  1244. * Use this routine to flag the side strip to scroll. The direction scrolled is controlled *
  1245. * by the parameter. Scrolling is merely initiated by this routine. Subsequent calls to *
  1246. * the AI function and the Draw_It function are required to properly give the appearance *
  1247. * of scrolling. *
  1248. * *
  1249. * INPUT: bool; Should the side strip scroll UP? If it is to scroll down then pass false. *
  1250. * *
  1251. * OUTPUT: bool; Was the side strip started to scroll in the desired direction? *
  1252. * *
  1253. * WARNINGS: none *
  1254. * *
  1255. * HISTORY: *
  1256. * 12/31/1994 JLB : Created. *
  1257. * 07/29/1995 JLB : Simplified scrolling logic. *
  1258. *=============================================================================================*/
  1259. bool SidebarClass::StripClass::Scroll(bool up)
  1260. {
  1261. if (up) {
  1262. if (!TopIndex) return(false);
  1263. Scroller--;
  1264. } else {
  1265. if (TopIndex+MAX_VISIBLE >= BuildableCount) return(false);
  1266. Scroller++;
  1267. }
  1268. return(true);
  1269. }
  1270. /***********************************************************************************************
  1271. * SidebarClass::StripClass::Flag_To_Redra -- Flags the sidebar strip to be redrawn. *
  1272. * *
  1273. * This utility routine is called when something changes on the sidebar and it must be *
  1274. * reflected the next time drawing is performed. *
  1275. * *
  1276. * INPUT: none *
  1277. * *
  1278. * OUTPUT: none *
  1279. * *
  1280. * WARNINGS: none *
  1281. * *
  1282. * HISTORY: *
  1283. * 05/18/1995 JLB : Created. *
  1284. *=============================================================================================*/
  1285. void SidebarClass::StripClass::Flag_To_Redraw(void)
  1286. {
  1287. IsToRedraw = true;
  1288. //Map.SidebarClass::IsToRedraw = true;
  1289. Map.Flag_To_Redraw(false);
  1290. }
  1291. /***********************************************************************************************
  1292. * SidebarClass::StripClass::AI -- Input and AI processing for the side strip. *
  1293. * *
  1294. * The side strip AI processing is performed by this function. This function not only *
  1295. * checks for player input, but also handles any graphic logic updating necessary as a *
  1296. * result of flashing or construction animation. *
  1297. * *
  1298. * INPUT: input -- The player input code. *
  1299. * *
  1300. * x,y -- Mouse coordinate to use. *
  1301. * *
  1302. * OUTPUT: bool; Did the AI detect that it will need a rendering change? If this routine *
  1303. * returns true, then the Draw_It function should be called at the *
  1304. * earliest opportunity. *
  1305. * *
  1306. * WARNINGS: none *
  1307. * *
  1308. * HISTORY: *
  1309. * 12/31/1994 JLB : Created. *
  1310. * 12/31/1994 JLB : Uses mouse coordinate parameters. *
  1311. *=============================================================================================*/
  1312. bool SidebarClass::StripClass::AI(KeyNumType & input, int , int )
  1313. {
  1314. bool redraw = false;
  1315. /*
  1316. ** If this is scroll button for this side strip, then scroll the strip as
  1317. ** indicated.
  1318. */
  1319. if (input == (UpButton[ID].ID|KN_BUTTON)) { // && !IsScrolling
  1320. UpButton[ID].IsPressed = false;
  1321. if (!Scroll(true)) {
  1322. Sound_Effect(VOC_SCOLD);
  1323. }
  1324. }
  1325. if (input == (DownButton[ID].ID|KN_BUTTON)) { // && !IsScrolling
  1326. DownButton[ID].IsPressed = false;
  1327. if (!Scroll(false)) {
  1328. Sound_Effect(VOC_SCOLD);
  1329. }
  1330. }
  1331. /*
  1332. ** Reflect the scroll desired direction/value into the scroll
  1333. ** logic handler. This might result in up or down scrolling.
  1334. */
  1335. if (!IsScrolling && Scroller) {
  1336. if (BuildableCount <= MAX_VISIBLE) {
  1337. Scroller = 0;
  1338. } else {
  1339. /*
  1340. ** Top of list is moving toward lower ordered entries in the object list. It looks like
  1341. ** the "window" to the object list is moving up even though the actual object images are
  1342. ** scrolling downward.
  1343. */
  1344. if (Scroller < 0) {
  1345. if (!TopIndex) {
  1346. Scroller = 0;
  1347. } else {
  1348. Scroller++;
  1349. IsScrollingDown = false;
  1350. IsScrolling = true;
  1351. TopIndex--;
  1352. Slid = 0;
  1353. }
  1354. } else {
  1355. if (TopIndex+MAX_VISIBLE >= BuildableCount) {
  1356. Scroller = 0;
  1357. } else {
  1358. Scroller--;
  1359. Slid = OBJECT_HEIGHT;
  1360. IsScrollingDown = true;
  1361. IsScrolling = true;
  1362. }
  1363. }
  1364. }
  1365. }
  1366. /*
  1367. ** Scroll logic is handled here.
  1368. */
  1369. if (IsScrolling) {
  1370. if (IsScrollingDown) {
  1371. Slid -= SCROLL_RATE;
  1372. if (Slid <= 0) {
  1373. IsScrolling = false;
  1374. Slid = 0;
  1375. TopIndex++;
  1376. }
  1377. } else {
  1378. Slid += SCROLL_RATE;
  1379. if (Slid >= OBJECT_HEIGHT) {
  1380. IsScrolling = false;
  1381. Slid = 0;
  1382. }
  1383. }
  1384. redraw = true;
  1385. }
  1386. /*
  1387. ** Handle any flashing logic. Flashing occurs when the player selects an object
  1388. ** and provides the visual feedback of a recognized and legal selection.
  1389. */
  1390. if (Flasher != -1) {
  1391. if (Graphic_Logic()) {
  1392. redraw = true;
  1393. if (Fetch_Stage() >= 7) {
  1394. Set_Rate(0);
  1395. Set_Stage(0);
  1396. Flasher = -1;
  1397. }
  1398. }
  1399. }
  1400. /*
  1401. ** Handle any building clock animation logic.
  1402. */
  1403. if (IsBuilding) {
  1404. for (int index = 0; index < BuildableCount; index++) {
  1405. int factoryid = Buildables[index].Factory;
  1406. if (factoryid != -1) {
  1407. FactoryClass * factory = Factories.Raw_Ptr(factoryid);
  1408. if (factory && factory->Has_Changed()) {
  1409. redraw = true;
  1410. if (factory->Has_Completed()) {
  1411. /*
  1412. ** Construction has been completed. Announce this fact to the player and
  1413. ** try to get the object to automatically leave the factory. Buildings are
  1414. ** the main exception to the ability to leave the factory under their own
  1415. ** power.
  1416. */
  1417. TechnoClass * pending = factory->Get_Object();
  1418. if (pending != NULL) {
  1419. switch (pending->What_Am_I()) {
  1420. case RTTI_VESSEL:
  1421. case RTTI_UNIT:
  1422. case RTTI_AIRCRAFT:
  1423. OutList.Add(EventClass(EventClass::PLACE, pending->What_Am_I(), -1));
  1424. Speak(VOX_UNIT_READY);
  1425. break;
  1426. case RTTI_BUILDING:
  1427. Speak(VOX_CONSTRUCTION);
  1428. break;
  1429. case RTTI_INFANTRY:
  1430. OutList.Add(EventClass(EventClass::PLACE, pending->What_Am_I(), -1));
  1431. Speak(VOX_UNIT_READY);
  1432. break;
  1433. }
  1434. }
  1435. }
  1436. }
  1437. }
  1438. }
  1439. }
  1440. /*
  1441. ** If any of the logic determined that this side strip needs to be redrawn, then
  1442. ** set the redraw flag for this side strip.
  1443. */
  1444. if (redraw) {
  1445. Flag_To_Redraw();
  1446. }
  1447. return(redraw);
  1448. }
  1449. /***********************************************************************************************
  1450. * SidebarClass::StripClass::Draw_It -- Render the sidebar display. *
  1451. * *
  1452. * Use this routine to render the sidebar display. It checks to see if it needs to be *
  1453. * redrawn and only redraw if necessary. If the "complete" parameter is true, then it *
  1454. * will force redraw the entire strip. *
  1455. * *
  1456. * INPUT: complete -- Should the redraw be forced? A force redraw will ignore the redraw *
  1457. * flag. *
  1458. * *
  1459. * OUTPUT: none *
  1460. * *
  1461. * WARNINGS: none *
  1462. * *
  1463. * HISTORY: *
  1464. * 12/31/1994 JLB : Created. *
  1465. * 08/06/1995 JLB : Handles multi factory tracking in same strip. *
  1466. *=============================================================================================*/
  1467. void SidebarClass::StripClass::Draw_It(bool complete)
  1468. {
  1469. if (IsToRedraw || complete) {
  1470. IsToRedraw = false;
  1471. SidebarRedraws++;
  1472. /*
  1473. ** Fills the background to the side strip. We shouldnt need to do this if the strip
  1474. ** has a full complement of icons.
  1475. */
  1476. /*
  1477. ** New sidebar needs to be drawn not filled
  1478. */
  1479. if (BuildableCount < MAX_VISIBLE) {
  1480. CC_Draw_Shape(LogoShapes, ID, X+(2*RESFACTOR), Y, WINDOW_MAIN, SHAPE_WIN_REL|SHAPE_NORMAL, 0);
  1481. }
  1482. /*
  1483. ** Redraw the scroll buttons.
  1484. */
  1485. UpButton[ID].Draw_Me(true);
  1486. DownButton[ID].Draw_Me(true);
  1487. /*
  1488. ** Loop through all the buildable objects that are visible in the strip and render
  1489. ** them. Their Y offset may be adjusted if the strip is in the process of scrolling.
  1490. */
  1491. for (int i = 0; i < MAX_VISIBLE + (IsScrolling ? 1 : 0); i++) {
  1492. bool production;
  1493. bool completed;
  1494. int stage;
  1495. bool darken = false;
  1496. void const * shapefile = 0;
  1497. int shapenum = 0;
  1498. void const * remapper = 0;
  1499. FactoryClass * factory = 0;
  1500. int index = i+TopIndex;
  1501. int x = X;
  1502. int y = Y + (i*OBJECT_HEIGHT * RESFACTOR);
  1503. /*
  1504. ** If the strip is scrolling, then the offset is adjusted accordingly.
  1505. */
  1506. if (IsScrolling) {
  1507. y -= (OBJECT_HEIGHT - Slid) * RESFACTOR;
  1508. // y -= OBJECT_HEIGHT - Slid;
  1509. }
  1510. /*
  1511. ** Fetch the shape number for the object type located at this current working
  1512. ** slot. This shape pointer is used to draw the underlying graphic there.
  1513. */
  1514. if ((unsigned)index < BuildableCount) {
  1515. ObjectTypeClass const * obj = NULL;
  1516. SpecialWeaponType spc = SPC_NONE;
  1517. if (Buildables[index].BuildableType != RTTI_SPECIAL) {
  1518. obj = Fetch_Techno_Type(Buildables[index].BuildableType, Buildables[index].BuildableID);
  1519. if (obj != NULL) {
  1520. /*
  1521. ** Fetch the remap table that is appropriate for this object
  1522. ** type.
  1523. */
  1524. remapper = PlayerPtr->Remap_Table(false, ((TechnoTypeClass const *)obj)->Remap);
  1525. /*
  1526. ** If there is already a factory producing this kind of object, then all
  1527. ** objects of this type are displays in a disabled state.
  1528. */
  1529. bool isbusy = (PlayerPtr->Fetch_Factory(Buildables[index].BuildableType) != NULL);
  1530. if (!isbusy && PlayerPtr->Is_Hack_Prevented(Buildables[index].BuildableType, Buildables[index].BuildableID)) {
  1531. isbusy = true;
  1532. }
  1533. /*
  1534. ** Infantry don't get remapped in the sidebar (special case).
  1535. */
  1536. if (Buildables[index].BuildableType == RTTI_INFANTRYTYPE) {
  1537. remapper = 0;
  1538. }
  1539. shapefile = obj->Get_Cameo_Data();
  1540. shapenum = 0;
  1541. if (Buildables[index].Factory != -1) {
  1542. factory = Factories.Raw_Ptr(Buildables[index].Factory);
  1543. production = true;
  1544. completed = factory->Has_Completed();
  1545. stage = factory->Completion();
  1546. darken = false;
  1547. } else {
  1548. production = false;
  1549. // darken = IsBuilding;
  1550. /*
  1551. ** Darken the imagery if a factory of a matching type is
  1552. ** already busy.
  1553. */
  1554. darken = isbusy;
  1555. }
  1556. } else {
  1557. darken = PlayerPtr->Is_Hack_Prevented(Buildables[index].BuildableType, Buildables[index].BuildableID);
  1558. }
  1559. } else {
  1560. spc = SpecialWeaponType(Buildables[index].BuildableID);
  1561. shapefile = Get_Special_Cameo(spc);
  1562. shapenum = 0;
  1563. production = true;
  1564. completed = PlayerPtr->SuperWeapon[spc].Is_Ready();
  1565. stage = PlayerPtr->SuperWeapon[spc].Anim_Stage();
  1566. darken = false;
  1567. }
  1568. if (obj != NULL || spc != SPC_NONE) {
  1569. /*
  1570. ** If this item is flashing then take care of it.
  1571. **
  1572. */
  1573. if (Flasher == index && (Fetch_Stage() & 0x01)) {
  1574. remapper = Map.FadingLight;
  1575. }
  1576. } else {
  1577. shapefile = LogoShapes;
  1578. if (!darken) {
  1579. shapenum = SB_BLANK;
  1580. }
  1581. }
  1582. } else {
  1583. shapefile = LogoShapes;
  1584. shapenum = SB_BLANK;
  1585. production = false;
  1586. }
  1587. remapper = 0;
  1588. /*
  1589. ** Now that the shape of the object at the current working slot has been found,
  1590. ** draw it and any graphic overlays as necessary.
  1591. **
  1592. ** Don't draw blank shapes over the new 640x400 sidebar art - ST 5/1/96 6:01PM
  1593. */
  1594. if (shapenum != SB_BLANK || shapefile != LogoShapes) {
  1595. CC_Draw_Shape(shapefile, shapenum,
  1596. x-(WindowList[WINDOW_SIDEBAR][WINDOWX])+(LEFT_EDGE_OFFSET * RESFACTOR),
  1597. y-WindowList[WINDOW_SIDEBAR][WINDOWY],
  1598. WINDOW_SIDEBAR,
  1599. SHAPE_NORMAL|SHAPE_WIN_REL| (remapper ? SHAPE_FADING : SHAPE_NORMAL),
  1600. remapper);
  1601. /*
  1602. ** Darken this object because it cannot be produced or is otherwise
  1603. ** unavailable.
  1604. */
  1605. if (darken) {
  1606. CC_Draw_Shape(ClockShapes, 0,
  1607. x-(WindowList[WINDOW_SIDEBAR][WINDOWX])+(LEFT_EDGE_OFFSET * RESFACTOR),
  1608. y-WindowList[WINDOW_SIDEBAR][WINDOWY],
  1609. WINDOW_SIDEBAR,
  1610. SHAPE_NORMAL|SHAPE_WIN_REL|SHAPE_GHOST,
  1611. NULL, ClockTranslucentTable);
  1612. }
  1613. }
  1614. /*
  1615. ** Draw the overlapping clock shape if this is object is being constructed.
  1616. ** If the object is completed, then display "Ready" with no clock shape.
  1617. */
  1618. if (production) {
  1619. if (completed) {
  1620. /*
  1621. ** Display text showing that the object is ready to place.
  1622. */
  1623. CC_Draw_Shape(ObjectTypeClass::PipShapes, PIP_READY,
  1624. (x-(WindowList[WINDOW_SIDEBAR][WINDOWX]))+(LEFT_EDGE_OFFSET+15) * RESFACTOR,
  1625. (y-WindowList[WINDOW_SIDEBAR][WINDOWY])+(4 * RESFACTOR),
  1626. WINDOW_SIDEBAR, SHAPE_CENTER);
  1627. } else {
  1628. CC_Draw_Shape(ClockShapes, stage+1,
  1629. x-(WindowList[WINDOW_SIDEBAR][WINDOWX])+(LEFT_EDGE_OFFSET * RESFACTOR),
  1630. y-WindowList[WINDOW_SIDEBAR][WINDOWY],
  1631. WINDOW_SIDEBAR,
  1632. SHAPE_NORMAL|SHAPE_WIN_REL|SHAPE_GHOST,
  1633. NULL, ClockTranslucentTable);
  1634. /*
  1635. ** Display text showing that the construction is temporarily on hold.
  1636. */
  1637. if (factory && !factory->Is_Building()) {
  1638. CC_Draw_Shape(ObjectTypeClass::PipShapes, PIP_HOLDING,
  1639. (x-(WindowList[WINDOW_SIDEBAR][WINDOWX])) + ((LEFT_EDGE_OFFSET+15) * RESFACTOR),
  1640. (y-WindowList[WINDOW_SIDEBAR][WINDOWY])+(4 * RESFACTOR),
  1641. WINDOW_SIDEBAR, SHAPE_CENTER);
  1642. }
  1643. }
  1644. }
  1645. }
  1646. LastSlid = Slid;
  1647. }
  1648. }
  1649. /***********************************************************************************************
  1650. * SidebarClass::StripClass::Recalc -- Revalidates the current sidebar list of objects. *
  1651. * *
  1652. * This routine will revalidate all the buildable objects in the sidebar. This routine *
  1653. * comes in handy when a factory has been destroyed, and the sidebar needs to reflect any *
  1654. * change that this requires. It checks every object to see if there is a factory available *
  1655. * that could produce it. If none can be found, then the object is removed from the *
  1656. * sidebar. *
  1657. * *
  1658. * INPUT: none *
  1659. * *
  1660. * OUTPUT: bool; The sidebar has changed as a result of this call? *
  1661. * *
  1662. * WARNINGS: none *
  1663. * *
  1664. * HISTORY: *
  1665. * 01/19/1995 JLB : Created. *
  1666. * 06/26/1995 JLB : Doesn't collapse sidebar when buildables removed. *
  1667. *=============================================================================================*/
  1668. bool SidebarClass::StripClass::Recalc(void)
  1669. {
  1670. int ok;
  1671. if (Debug_Map || !BuildableCount) {
  1672. return(false);
  1673. }
  1674. /*
  1675. ** Sweep through all objects listed in the sidebar. If any of those object can
  1676. ** not be created -- even in theory -- then they must be removed form the sidebar and
  1677. ** any current production must be abandoned.
  1678. */
  1679. bool redraw = false;
  1680. for (int index = 0; index < BuildableCount; index++) {
  1681. TechnoTypeClass const * tech = Fetch_Techno_Type(Buildables[index].BuildableType, Buildables[index].BuildableID);
  1682. if (tech != NULL) {
  1683. ok = tech->Who_Can_Build_Me(true, false, PlayerPtr->Class->House) != NULL;
  1684. } else {
  1685. if ((unsigned)Buildables[index].BuildableID < SPC_COUNT) {
  1686. ok = PlayerPtr->SuperWeapon[Buildables[index].BuildableID].Is_Present();
  1687. } else {
  1688. ok = false;
  1689. }
  1690. }
  1691. if (!ok) {
  1692. /*
  1693. ** Removes this entry from the list.
  1694. */
  1695. if (BuildableCount > 1 && index < BuildableCount-1) {
  1696. memcpy(&Buildables[index], &Buildables[index+1], sizeof(Buildables[0])*((BuildableCount-index)-1));
  1697. }
  1698. TopIndex = 0;
  1699. IsToRedraw = true;
  1700. redraw = true;
  1701. BuildableCount--;
  1702. index--;
  1703. }
  1704. }
  1705. #ifdef NEVER
  1706. /*
  1707. ** If there are no more buildable objects to display, make the sidebar go away.
  1708. */
  1709. if (!BuildableCount) {
  1710. Map.SidebarClass::Activate(0);
  1711. }
  1712. #endif
  1713. return(redraw);
  1714. }
  1715. /***********************************************************************************************
  1716. * SidebarClass::StripClass::SelectClass::SelectClass -- Default constructor. *
  1717. * *
  1718. * This is the default constructor for the button that controls the buildable cameos on *
  1719. * the sidebar strip. *
  1720. * *
  1721. * INPUT: none *
  1722. * *
  1723. * OUTPUT: none *
  1724. * *
  1725. * WARNINGS: The coordinates are set to zero by this routine. They must be set to the *
  1726. * correct values before this button will function. *
  1727. * *
  1728. * HISTORY: *
  1729. * 01/19/1995 JLB : Created. *
  1730. *=============================================================================================*/
  1731. SidebarClass::StripClass::SelectClass::SelectClass(void) :
  1732. ControlClass(0, 0, 0, (OBJECT_WIDTH-1) * RESFACTOR, OBJECT_HEIGHT * RESFACTOR, LEFTPRESS|RIGHTPRESS|LEFTUP),
  1733. Strip(0),
  1734. Index(0)
  1735. {
  1736. }
  1737. /***********************************************************************************************
  1738. * SidebarClass::StripClass::SelectClass:: -- Assigns special values to a buildable select but *
  1739. * *
  1740. * Use this routine to set custom buildable vars for this particular select button. It *
  1741. * uses this information to properly know what buildable object to start or stop production *
  1742. * on. *
  1743. * *
  1744. * INPUT: strip -- Reference to the strip that owns this buildable button. *
  1745. * *
  1746. * index -- The index (0 .. MAX_VISIBLE-1) of this button. This is used to let *
  1747. * the owning strip know what index this button refers to. *
  1748. * *
  1749. * OUTPUT: none *
  1750. * *
  1751. * WARNINGS: none *
  1752. * *
  1753. * HISTORY: *
  1754. * 01/19/1995 JLB : Created. *
  1755. *=============================================================================================*/
  1756. void SidebarClass::StripClass::SelectClass::Set_Owner(StripClass & strip, int index)
  1757. {
  1758. Strip = &strip;
  1759. Index = index;
  1760. X = strip.X;
  1761. Y = strip.Y + ((index * OBJECT_HEIGHT) * RESFACTOR);
  1762. }
  1763. /***********************************************************************************************
  1764. * SidebarClass::StripClass::SelectClass:: -- Action function when buildable cameo is selected *
  1765. * *
  1766. * This function is called when the buildable icon (cameo) is clicked on. It handles *
  1767. * starting and stopping production as indicated. *
  1768. * *
  1769. * INPUT: flags -- The input event that triggered the call. *
  1770. * *
  1771. * key -- The keyboard value at the time of the input. *
  1772. * *
  1773. * OUTPUT: Returns with whether the input list should be scanned further. *
  1774. * *
  1775. * WARNINGS: none *
  1776. * *
  1777. * HISTORY: *
  1778. * 01/19/1995 JLB : Created. *
  1779. * 10/09/1996 JLB : Sonar pulse converted to regular event type. *
  1780. *=============================================================================================*/
  1781. int SidebarClass::StripClass::SelectClass::Action(unsigned flags, KeyNumType & key)
  1782. {
  1783. int index = Strip->TopIndex + Index;
  1784. RTTIType otype = Strip->Buildables[index].BuildableType;
  1785. int oid = Strip->Buildables[index].BuildableID;
  1786. int fnumber = Strip->Buildables[index].Factory;
  1787. RemapControlType * scheme = GadgetClass::Get_Color_Scheme();
  1788. ObjectTypeClass const * choice = NULL;
  1789. SpecialWeaponType spc = SPC_NONE;
  1790. /*
  1791. ** Determine the factory number that would apply to objects of the type
  1792. ** the mouse is currently addressing. This doesn't mean that the factory number
  1793. ** fetched is actually producing the indicated object, merely that that particular
  1794. ** kind of factory is specified by the "genfactory" value. This can be used to see
  1795. ** if the factory type is currently busy or not.
  1796. */
  1797. FactoryClass * factory = PlayerPtr->Fetch_Factory(otype);
  1798. Map.Override_Mouse_Shape(MOUSE_NORMAL);
  1799. if (index < Strip->BuildableCount) {
  1800. if (otype != RTTI_SPECIAL) {
  1801. choice = Fetch_Techno_Type(otype, oid);
  1802. } else {
  1803. spc = SpecialWeaponType(oid);
  1804. }
  1805. if (fnumber != -1) {
  1806. factory = Factories.Raw_Ptr(fnumber);
  1807. }
  1808. } else {
  1809. Map.Help_Text(TXT_NONE);
  1810. }
  1811. if (spc != SPC_NONE) {
  1812. /*
  1813. ** Display the help text if the mouse is over the button.
  1814. */
  1815. if (flags & LEFTUP) {
  1816. Map.Help_Text(SpecialWeaponHelp[spc], X, Y, scheme->Color, true);
  1817. flags &= ~LEFTUP;
  1818. }
  1819. /*
  1820. ** A right mouse button signals "cancel". If we are in targeting
  1821. ** mode then we don't want to be any more.
  1822. */
  1823. if (flags & RIGHTPRESS) {
  1824. Map.IsTargettingMode = SPC_NONE;
  1825. }
  1826. /*
  1827. ** A left mouse press signal "activate". If our weapon type is
  1828. ** available then we should activate it.
  1829. */
  1830. if (flags & LEFTPRESS) {
  1831. if ((unsigned)spc < SPC_COUNT) {
  1832. if (PlayerPtr->SuperWeapon[spc].Is_Ready()) {
  1833. if (spc != SPC_SONAR_PULSE) {
  1834. Map.IsTargettingMode = spc;
  1835. Unselect_All();
  1836. Speak(VOX_SELECT_TARGET);
  1837. } else {
  1838. OutList.Add(EventClass(EventClass::SPECIAL_PLACE, SPC_SONAR_PULSE, 0));
  1839. }
  1840. } else {
  1841. PlayerPtr->SuperWeapon[spc].Impatient_Click();
  1842. }
  1843. }
  1844. }
  1845. } else {
  1846. if (choice != NULL) {
  1847. /*
  1848. ** Display the help text if the mouse is over the button.
  1849. */
  1850. if (flags & LEFTUP) {
  1851. Map.Help_Text(choice->Full_Name(), X, Y, scheme->Color, true);
  1852. Map.Set_Cost(choice->Cost_Of() * PlayerPtr->CostBias);
  1853. flags &= ~LEFTUP;
  1854. }
  1855. /*
  1856. ** A right mouse button signals "cancel".
  1857. */
  1858. if (flags & RIGHTPRESS) {
  1859. /*
  1860. ** If production is in progress, put it on hold. If production is already
  1861. ** on hold, then abandon it. Money will be refunded, the factory
  1862. ** manager deleted, and the object under construction is returned to
  1863. ** the free pool.
  1864. */
  1865. if (factory != NULL) {
  1866. /*
  1867. ** Cancels placement mode if the sidebar factory is abandoned or
  1868. ** suspended.
  1869. */
  1870. if (Map.PendingObjectPtr && Map.PendingObjectPtr->Is_Techno()) {
  1871. Map.PendingObjectPtr = 0;
  1872. Map.PendingObject = 0;
  1873. Map.PendingHouse = HOUSE_NONE;
  1874. Map.Set_Cursor_Shape(0);
  1875. }
  1876. if (!factory->Is_Building()) {
  1877. Speak(VOX_CANCELED);
  1878. OutList.Add(EventClass(EventClass::ABANDON, otype, oid));
  1879. } else {
  1880. Speak(VOX_SUSPENDED);
  1881. OutList.Add(EventClass(EventClass::SUSPEND, otype, oid));
  1882. Map.Column[0].IsToRedraw = true;
  1883. Map.Column[1].IsToRedraw = true;
  1884. }
  1885. }
  1886. }
  1887. if (flags & LEFTPRESS) {
  1888. /*
  1889. ** If there is already a factory attached to this strip but the player didn't click
  1890. ** on the icon that has the attached factory, then say that the factory is busy and
  1891. ** ignore the click.
  1892. */
  1893. if (fnumber == -1 && factory != NULL) {
  1894. Speak(VOX_NO_FACTORY);
  1895. ControlClass::Action(flags, key);
  1896. return(true);
  1897. }
  1898. if (factory != NULL) {
  1899. /*
  1900. ** If this object is currently being built, then give a scold sound and text and then
  1901. ** bail.
  1902. */
  1903. if (factory->Is_Building()) {
  1904. Speak(VOX_NO_FACTORY);
  1905. } else {
  1906. /*
  1907. ** If production has completed, then attempt to have the object exit
  1908. ** the factory or go into placement mode.
  1909. */
  1910. if (factory->Has_Completed()) {
  1911. TechnoClass * pending = factory->Get_Object();
  1912. if (!pending && factory->Get_Special_Item()) {
  1913. Map.IsTargettingMode = SPC_ANY;
  1914. } else {
  1915. BuildingClass * builder = pending->Who_Can_Build_Me(false, false);
  1916. if (!builder) {
  1917. OutList.Add(EventClass(EventClass::ABANDON, otype, oid));
  1918. Speak(VOX_NO_FACTORY);
  1919. } else {
  1920. /*
  1921. ** If the completed object is a building, then change the
  1922. ** game state into building placement mode. This fact is
  1923. ** not transmitted to any linked computers until the moment
  1924. ** the building is actually placed down.
  1925. */
  1926. if (pending->What_Am_I() == RTTI_BUILDING) {
  1927. PlayerPtr->Manual_Place(builder, (BuildingClass *)pending);
  1928. } else {
  1929. /*
  1930. ** For objects that can leave the factory under their own
  1931. ** power, queue this event and process through normal house
  1932. ** production channels.
  1933. */
  1934. OutList.Add(EventClass(EventClass::PLACE, otype, -1));
  1935. }
  1936. }
  1937. }
  1938. } else {
  1939. if (PlayerPtr->Is_Hack_Prevented(otype, oid)) {
  1940. // Eva scolds the player here.
  1941. } else {
  1942. /*
  1943. ** The factory must have been in a suspended state. Resume construction
  1944. ** normally.
  1945. */
  1946. if (otype == RTTI_INFANTRYTYPE) {
  1947. Speak(VOX_TRAINING);
  1948. } else {
  1949. Speak(VOX_BUILDING);
  1950. }
  1951. OutList.Add(EventClass(EventClass::PRODUCE, Strip->Buildables[index].BuildableType, Strip->Buildables[index].BuildableID));
  1952. }
  1953. }
  1954. }
  1955. } else {
  1956. if (PlayerPtr->Is_Hack_Prevented(otype, oid)) {
  1957. // Eva scolds the player here.
  1958. } else {
  1959. /*
  1960. ** If this side strip is already busy with production, then ignore the
  1961. ** input and announce this fact.
  1962. */
  1963. if (otype == RTTI_INFANTRYTYPE) {
  1964. Speak(VOX_TRAINING);
  1965. } else {
  1966. Speak(VOX_BUILDING);
  1967. }
  1968. OutList.Add(EventClass(EventClass::PRODUCE, Strip->Buildables[index].BuildableType, Strip->Buildables[index].BuildableID));
  1969. }
  1970. }
  1971. }
  1972. } else {
  1973. flags = 0;
  1974. }
  1975. }
  1976. ControlClass::Action(flags, key);
  1977. return(true);
  1978. }
  1979. /***********************************************************************************************
  1980. * SidebarClass::SBGadgetClass::Action -- Special function that controls the mouse over the si *
  1981. * *
  1982. * This routine is called whenever the mouse is over the sidebar. It makes sure that the *
  1983. * mouse is always the normal shape while over the sidebar. *
  1984. * *
  1985. * INPUT: flags -- The event flags that resulted in this routine being called. *
  1986. * *
  1987. * key -- Reference the keyboard code that may be present. *
  1988. * *
  1989. * OUTPUT: Returns that no further keyboard processing is necessary. *
  1990. * *
  1991. * WARNINGS: none *
  1992. * *
  1993. * HISTORY: *
  1994. * 03/28/1995 JLB : Created. *
  1995. *=============================================================================================*/
  1996. int SidebarClass::SBGadgetClass::Action(unsigned , KeyNumType & )
  1997. {
  1998. Map.Help_Text(TXT_NONE);
  1999. Map.Override_Mouse_Shape(MOUSE_NORMAL, false);
  2000. return(true);
  2001. }
  2002. /***********************************************************************************************
  2003. * SidebarClass::StripClass::Factory_Link -- Links a factory to a sidebar button. *
  2004. * *
  2005. * This routine will link the specified factory to this sidebar strip. The exact button to *
  2006. * link to is determined from the object type and id specified. A linked button is one that *
  2007. * will show appropriate construction animation (clock shape) that matches the state of *
  2008. * the factory. *
  2009. * *
  2010. * INPUT: factory -- The factory number to link to the sidebar. *
  2011. * *
  2012. * type -- The object type that this factory refers to. *
  2013. * *
  2014. * id -- The object sub-type that this factory refers to. *
  2015. * *
  2016. * OUTPUT: Was the factory successfully attached? Failure would indicate that there is no *
  2017. * object of the specified type and sub-type in the sidebar list. *
  2018. * *
  2019. * WARNINGS: none *
  2020. * *
  2021. * HISTORY: *
  2022. * 05/18/1995 JLB : Created. *
  2023. *=============================================================================================*/
  2024. bool SidebarClass::StripClass::Factory_Link(int factory, RTTIType type, int id)
  2025. {
  2026. for (int index = 0; index < BuildableCount; index++) {
  2027. if (Buildables[index].BuildableType == type && Buildables[index].BuildableID == id) {
  2028. Buildables[index].Factory = factory;
  2029. IsBuilding = true;
  2030. /*
  2031. ** Flag that all the icons on this strip need to be redrawn
  2032. */
  2033. Flag_To_Redraw();
  2034. return(true);
  2035. }
  2036. }
  2037. return(false);
  2038. }
  2039. /***********************************************************************************************
  2040. * SidebarClass::Abandon_Production -- Stops production of the object specified. *
  2041. * *
  2042. * This routine is used to abandon production of the object specified. The factory will *
  2043. * be completely disabled by this call. *
  2044. * *
  2045. * INPUT: type -- The object type that is to be abandoned. The sub-type is not needed *
  2046. * since it is presumed there can be only one type in production at any *
  2047. * one time. *
  2048. * *
  2049. * factory -- The factory number that is doing the production. *
  2050. * *
  2051. * OUTPUT: Was the factory successfully abandoned? *
  2052. * *
  2053. * WARNINGS: none *
  2054. * *
  2055. * HISTORY: *
  2056. * 05/18/1995 JLB : Created. *
  2057. *=============================================================================================*/
  2058. bool SidebarClass::Abandon_Production(RTTIType type, int factory)
  2059. {
  2060. return(Column[Which_Column(type)].Abandon_Production(factory));
  2061. }
  2062. /***********************************************************************************************
  2063. * SidebarClass::StripClass::Abandon_Produ -- Abandons production associated with sidebar. *
  2064. * *
  2065. * Production of the object associated with this sidebar is abandoned when this routine is *
  2066. * called. *
  2067. * *
  2068. * INPUT: factory -- The factory index that is to be suspended. *
  2069. * *
  2070. * OUTPUT: Was the production abandonment successful? *
  2071. * *
  2072. * WARNINGS: none *
  2073. * *
  2074. * HISTORY: *
  2075. * 05/18/1995 JLB : Created. *
  2076. * 08/06/1995 JLB : More intelligent abandon logic for multiple factories. *
  2077. *=============================================================================================*/
  2078. bool SidebarClass::StripClass::Abandon_Production(int factory)
  2079. {
  2080. bool noprod = true;
  2081. bool abandon = false;
  2082. for (int index = 0; index < BuildableCount; index++) {
  2083. if (Buildables[index].Factory == factory) {
  2084. Factories.Raw_Ptr(factory)->Abandon();
  2085. Buildables[index].Factory = -1;
  2086. abandon = true;
  2087. } else {
  2088. if (Buildables[index].Factory != -1) {
  2089. noprod = false;
  2090. }
  2091. }
  2092. }
  2093. /*
  2094. ** If there was a change to the strip, then flag the strip to be redrawn.
  2095. */
  2096. if (abandon) {
  2097. Flag_To_Redraw();
  2098. }
  2099. /*
  2100. ** If there is no production whatsoever on this strip, then flag it so.
  2101. */
  2102. if (noprod) {
  2103. IsBuilding = false;
  2104. }
  2105. return(abandon);
  2106. }
  2107. /***********************************************************************************************
  2108. * SidebarClass::Zoom_Mode_Control -- Handles the zoom mode toggle operation. *
  2109. * *
  2110. * This is the function that is called when the map button is pressed. It will toggle *
  2111. * between the different modes that the radar map can assume. *
  2112. * *
  2113. * INPUT: none *
  2114. * *
  2115. * OUTPUT: none *
  2116. * *
  2117. * WARNINGS: none *
  2118. * *
  2119. * HISTORY: *
  2120. * 07/31/1996 JLB : Created. *
  2121. *=============================================================================================*/
  2122. void SidebarClass::Zoom_Mode_Control(void)
  2123. {
  2124. #ifdef WIN32
  2125. /*
  2126. ** If radar is active, cycle as follows:
  2127. ** Zoomed => not zoomed
  2128. ** not zoomed => player status (multiplayer only)
  2129. ** player status => radar spying readout
  2130. ** radar spying readout => zoomed
  2131. */
  2132. if (IsRadarActive) {
  2133. if (Is_Zoomed() || Session.Type==GAME_NORMAL) {
  2134. if (Is_Zoomed() || !Spy_Next_House()) {
  2135. Zoom_Mode(Coord_Cell(TacticalCoord));
  2136. }
  2137. } else {
  2138. if (!Spying_On_House() && !Is_Player_Names()) {
  2139. Player_Names(1);
  2140. } else {
  2141. Player_Names(0);
  2142. if (!Spy_Next_House()) {
  2143. Zoom_Mode(Coord_Cell(TacticalCoord));
  2144. }
  2145. }
  2146. }
  2147. } else {
  2148. if (Session.Type!=GAME_NORMAL) {
  2149. Player_Names(Is_Player_Names()==0);
  2150. }
  2151. }
  2152. #else
  2153. /*
  2154. ** If radar is active, cycle as follows:
  2155. ** not zoomed => player status (multiplayer only)
  2156. ** player status => radar spying readout
  2157. ** radar spying readout => not zoomed
  2158. */
  2159. if (IsRadarActive) {
  2160. if (Session.Type==GAME_NORMAL) {
  2161. if (!Spy_Next_House()) {
  2162. Zoom_Mode(Coord_Cell(TacticalCoord));
  2163. }
  2164. } else {
  2165. if (!Spying_On_House() && !Is_Player_Names()) {
  2166. Player_Names(1);
  2167. } else {
  2168. Player_Names(0);
  2169. if (!Spy_Next_House()) {
  2170. Zoom_Mode(Coord_Cell(TacticalCoord));
  2171. }
  2172. }
  2173. }
  2174. } else {
  2175. if (Session.Type!=GAME_NORMAL) {
  2176. Player_Names(Is_Player_Names()==0);
  2177. }
  2178. }
  2179. #endif
  2180. }