EXPAND.CPP 13 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header$ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Command & Conquer *
  20. * *
  21. * File Name : EXPAND.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : 11/03/95 *
  26. * *
  27. * Last Update : November 3, 1995 [JLB] *
  28. * *
  29. *---------------------------------------------------------------------------------------------*
  30. * Functions: *
  31. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  32. #include "function.h"
  33. #ifdef NEWMENU
  34. bool Expansion_Present(void)
  35. {
  36. CCFileClass file("EXPAND.DAT");
  37. return(file.Is_Available());
  38. }
  39. class EListClass : public ListClass
  40. {
  41. public:
  42. EListClass(int id, int x, int y, int w, int h, TextPrintType flags, void const * up, void const * down) :
  43. ListClass(id, x, y, w, h, flags, up, down) {};
  44. protected:
  45. virtual void Draw_Entry(int index, int x, int y, int width, int selected);
  46. };
  47. void EListClass::Draw_Entry(int index, int x, int y, int width, int selected)
  48. {
  49. if (TextFlags & TPF_6PT_GRAD) {
  50. TextPrintType flags = TextFlags;
  51. if (selected) {
  52. flags = flags | TPF_BRIGHT_COLOR;
  53. LogicPage->Fill_Rect (x, y, x + width - 1, y + LineHeight - 1, CC_GREEN_SHADOW);
  54. } else {
  55. if (!(flags & TPF_USE_GRAD_PAL)) {
  56. flags = flags | TPF_MEDIUM_COLOR;
  57. }
  58. }
  59. Conquer_Clip_Text_Print(List[index]+sizeof(int), x, y, CC_GREEN, TBLACK, flags, width, Tabs);
  60. } else {
  61. Conquer_Clip_Text_Print(List[index]+sizeof(int), x, y, (selected ? BLUE : WHITE), TBLACK, TextFlags, width, Tabs);
  62. }
  63. }
  64. bool Expansion_Dialog(void)
  65. {
  66. int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
  67. int option_width = 236 * factor;
  68. int option_height = 162 * factor;
  69. int option_x = (320*factor - option_width) /2;
  70. int option_y = (200*factor - option_height) /2;
  71. GadgetClass * buttons = NULL;
  72. void const *up_button;
  73. void const *down_button;
  74. if (InMainLoop){
  75. up_button = Hires_Retrieve("BTN-UP.SHP");
  76. down_button = Hires_Retrieve("BTN-DN.SHP");
  77. }else{
  78. up_button = Hires_Retrieve("BTN-UP2.SHP");
  79. down_button = Hires_Retrieve("BTN-DN2.SHP");
  80. }
  81. TextButtonClass ok(200, TXT_OK, TPF_6PT_GRAD|TPF_NOSHADOW, option_x+25*factor, option_y+option_height-15*factor);
  82. TextButtonClass cancel(201, TXT_CANCEL, TPF_6PT_GRAD|TPF_NOSHADOW, option_x+option_width-50*factor, option_y+option_height-15*factor);
  83. EListClass list(202, option_x+10*factor, option_y+20*factor, option_width-20*factor, option_height-40*factor, TPF_6PT_GRAD|TPF_NOSHADOW, up_button, down_button);
  84. buttons = &ok;
  85. cancel.Add(*buttons);
  86. list.Add(*buttons);
  87. /*
  88. ** Add in all the expansion scenarios.
  89. */
  90. char * sbuffer = (char*)_ShapeBuffer;
  91. int index;
  92. for (index = 20; index < 60; index++) {
  93. char buffer[128];
  94. CCFileClass file;
  95. Set_Scenario_Name(buffer, index, SCEN_PLAYER_GDI, SCEN_DIR_EAST, SCEN_VAR_A);
  96. strcat(buffer, ".INI");
  97. file.Set_Name(buffer);
  98. if (file.Is_Available()) {
  99. file.Read(sbuffer, 1000);
  100. sbuffer[1000] = '\r';
  101. sbuffer[1000+1] = '\n';
  102. sbuffer[1000+2] = '\0';
  103. WWGetPrivateProfileString("Basic", "Name", "x", buffer, sizeof(buffer), sbuffer);
  104. char * data = new char [strlen(buffer)+1+sizeof(int)+25];
  105. *((int*)&data[0]) = index;
  106. strcpy(&data[sizeof(int)], "GDI: ");
  107. strcat(&data[sizeof(int)], buffer);
  108. list.Add_Item(data);
  109. }
  110. }
  111. for (index = 20; index < 60; index++) {
  112. char buffer[128];
  113. CCFileClass file;
  114. Set_Scenario_Name(buffer, index, SCEN_PLAYER_NOD, SCEN_DIR_EAST, SCEN_VAR_A);
  115. strcat(buffer, ".INI");
  116. file.Set_Name(buffer);
  117. if (file.Is_Available()) {
  118. file.Read(sbuffer, 1000);
  119. sbuffer[1000] = '\r';
  120. sbuffer[1000+1] = '\n';
  121. sbuffer[1000+2] = '\0';
  122. WWGetPrivateProfileString("Basic", "Name", "x", buffer, sizeof(buffer), sbuffer);
  123. char * data = new char [strlen(buffer)+1+sizeof(int)+25];
  124. *((int*)&data[0]) = index;
  125. strcpy(&data[sizeof(int)], "NOD: ");
  126. strcat(&data[sizeof(int)], buffer);
  127. list.Add_Item(data);
  128. }
  129. }
  130. Set_Logic_Page(SeenBuff);
  131. bool recalc = true;
  132. bool display = true;
  133. bool process = true;
  134. bool okval = true;
  135. while (process) {
  136. Call_Back();
  137. /*
  138. ** If we have just received input focus again after running in the background then
  139. ** we need to redraw.
  140. */
  141. if (AllSurfaces.SurfacesRestored){
  142. AllSurfaces.SurfacesRestored=FALSE;
  143. display=TRUE;
  144. }
  145. if (display) {
  146. display = false;
  147. Hide_Mouse();
  148. /*
  149. ** Load the background picture.
  150. */
  151. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  152. Blit_Hid_Page_To_Seen_Buff();
  153. Dialog_Box(option_x, option_y, option_width, option_height);
  154. Draw_Caption(TXT_MISSION_DESCRIPTION, option_x, option_y, option_width);
  155. buttons->Draw_All();
  156. Show_Mouse();
  157. }
  158. KeyNumType input = buttons->Input();
  159. switch (input) {
  160. case KN_RETURN:
  161. case 200|KN_BUTTON:
  162. if (list.Current_Item()[sizeof(int)] == 'G') {
  163. ScenPlayer = SCEN_PLAYER_GDI;
  164. } else {
  165. ScenPlayer = SCEN_PLAYER_NOD;
  166. }
  167. ScenDir = SCEN_DIR_EAST;
  168. Whom = HOUSE_GOOD;
  169. Scenario = *(int *)list.Current_Item();
  170. process = false;
  171. okval = true;
  172. break;
  173. case KN_ESC:
  174. case 201|KN_BUTTON:
  175. ScenPlayer = SCEN_PLAYER_GDI;
  176. ScenDir = SCEN_DIR_EAST;
  177. Whom = HOUSE_GOOD;
  178. Scenario = *(int *)list.Current_Item();
  179. process = false;
  180. okval = false;
  181. break;
  182. default:
  183. break;
  184. }
  185. }
  186. /*
  187. ** Free up the allocations for the text lines in the list box.
  188. */
  189. for (index = 0; index < list.Count(); index++) {
  190. delete [] (char *)list.Get_Item(index);
  191. }
  192. return(okval);
  193. }
  194. /***********************************************************************************************
  195. * Bonus_Dialog -- Asks the user which bonus mission he wants to play *
  196. * *
  197. * *
  198. * *
  199. * INPUT: Nothing *
  200. * *
  201. * OUTPUT: Nothing *
  202. * *
  203. * WARNINGS: None *
  204. * *
  205. * HISTORY: *
  206. * 3/26/97 11:07AM ST : Created *
  207. *=============================================================================================*/
  208. bool Bonus_Dialog(void)
  209. {
  210. int factor = (SeenBuff.Get_Width() == 320) ? 1 : 2;
  211. int option_width = 236 * factor;
  212. int option_height = 162 * factor;
  213. int option_x = (320*factor - option_width) /2;
  214. int option_y = (200*factor - option_height) /2;
  215. GadgetClass * buttons = NULL;
  216. void const *up_button;
  217. void const *down_button;
  218. if (InMainLoop){
  219. up_button = Hires_Retrieve("BTN-UP.SHP");
  220. down_button = Hires_Retrieve("BTN-DN.SHP");
  221. }else{
  222. up_button = Hires_Retrieve("BTN-UP2.SHP");
  223. down_button = Hires_Retrieve("BTN-DN2.SHP");
  224. }
  225. TextButtonClass ok(200, TXT_OK, TPF_6PT_GRAD|TPF_NOSHADOW, option_x+25*factor, option_y+option_height-15*factor);
  226. TextButtonClass cancel(201, TXT_CANCEL, TPF_6PT_GRAD|TPF_NOSHADOW, option_x+option_width-50*factor, option_y+option_height-15*factor);
  227. EListClass list(202, option_x+10*factor, option_y+20*factor, option_width-20*factor, option_height-40*factor, TPF_6PT_GRAD|TPF_NOSHADOW, up_button, down_button);
  228. buttons = &ok;
  229. cancel.Add(*buttons);
  230. list.Add(*buttons);
  231. /*
  232. ** Add in all the expansion scenarios.
  233. */
  234. char * sbuffer = (char*)_ShapeBuffer;
  235. int gdi_scen_names[3]={
  236. TXT_BONUS_MISSION_1,
  237. TXT_BONUS_MISSION_2,
  238. TXT_BONUS_MISSION_3
  239. };
  240. int nod_scen_names[2]={
  241. TXT_BONUS_MISSION_4,
  242. TXT_BONUS_MISSION_5
  243. };
  244. int index;
  245. for (index = 60; index < 63; index++) {
  246. char buffer[128];
  247. CCFileClass file;
  248. Set_Scenario_Name(buffer, index, SCEN_PLAYER_GDI, SCEN_DIR_EAST, SCEN_VAR_A);
  249. strcat(buffer, ".INI");
  250. file.Set_Name(buffer);
  251. if (file.Is_Available()) {
  252. memcpy (buffer, Text_String (gdi_scen_names[index-60]), 1+strlen(Text_String (gdi_scen_names[index-60])));
  253. char * data = new char [strlen(buffer)+1+sizeof(int)+25];
  254. *((int*)&data[0]) = index;
  255. strcpy(&data[sizeof(int)], "GDI: ");
  256. strcat(&data[sizeof(int)], buffer);
  257. list.Add_Item(data);
  258. }
  259. }
  260. for (index = 60; index < 62; index++) {
  261. char buffer[128];
  262. CCFileClass file;
  263. Set_Scenario_Name(buffer, index, SCEN_PLAYER_NOD, SCEN_DIR_EAST, SCEN_VAR_A);
  264. strcat(buffer, ".INI");
  265. file.Set_Name(buffer);
  266. if (file.Is_Available()) {
  267. memcpy (buffer, Text_String (nod_scen_names[index-60]), 1+strlen(Text_String (nod_scen_names[index-60])));
  268. char * data = new char [strlen(buffer)+1+sizeof(int)+25];
  269. *((int*)&data[0]) = index;
  270. strcpy(&data[sizeof(int)], "NOD: ");
  271. strcat(&data[sizeof(int)], buffer);
  272. list.Add_Item(data);
  273. }
  274. }
  275. Set_Logic_Page(SeenBuff);
  276. bool recalc = true;
  277. bool display = true;
  278. bool process = true;
  279. bool okval = true;
  280. while (process) {
  281. Call_Back();
  282. /*
  283. ** If we have just received input focus again after running in the background then
  284. ** we need to redraw.
  285. */
  286. if (AllSurfaces.SurfacesRestored){
  287. AllSurfaces.SurfacesRestored=FALSE;
  288. display=TRUE;
  289. }
  290. if (display) {
  291. display = false;
  292. Hide_Mouse();
  293. /*
  294. ** Load the background picture.
  295. */
  296. Load_Title_Screen("HTITLE.PCX", &HidPage, Palette);
  297. Blit_Hid_Page_To_Seen_Buff();
  298. Dialog_Box(option_x, option_y, option_width, option_height);
  299. Draw_Caption(TXT_BONUS_MISSIONS, option_x, option_y, option_width);
  300. buttons->Draw_All();
  301. Show_Mouse();
  302. }
  303. KeyNumType input = buttons->Input();
  304. switch (input) {
  305. case KN_RETURN:
  306. case 200|KN_BUTTON:
  307. if (list.Current_Item()[sizeof(int)] == 'G') {
  308. ScenPlayer = SCEN_PLAYER_GDI;
  309. } else {
  310. ScenPlayer = SCEN_PLAYER_NOD;
  311. }
  312. ScenDir = SCEN_DIR_EAST;
  313. Whom = HOUSE_GOOD;
  314. Scenario = *(int *)list.Current_Item();
  315. process = false;
  316. okval = true;
  317. break;
  318. case KN_ESC:
  319. case 201|KN_BUTTON:
  320. ScenPlayer = SCEN_PLAYER_GDI;
  321. ScenDir = SCEN_DIR_EAST;
  322. Whom = HOUSE_GOOD;
  323. Scenario = *(int *)list.Current_Item();
  324. process = false;
  325. okval = false;
  326. break;
  327. default:
  328. break;
  329. }
  330. }
  331. /*
  332. ** Free up the allocations for the text lines in the list box.
  333. */
  334. for (index = 0; index < list.Count(); index++) {
  335. delete [] (char *)list.Get_Item(index);
  336. }
  337. return(okval);
  338. }
  339. #endif