MAPEDSEL.CPP 19 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588
  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/MAPEDSEL.CPP 1 3/03/97 10:25a Joe_bostic $ */
  19. /***************************************************************************
  20. ** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S **
  21. ***************************************************************************
  22. * *
  23. * Project Name : Command & Conquer *
  24. * *
  25. * File Name : MAPEDSEL.CPP *
  26. * *
  27. * Programmer : Bill Randolph *
  28. * *
  29. * Start Date : November 18, 1994 *
  30. * *
  31. * Last Update : April 30, 1996 [JLB] *
  32. * *
  33. *-------------------------------------------------------------------------*
  34. * Object-selection & manipulation routines *
  35. *-------------------------------------------------------------------------*
  36. * Functions: *
  37. * MapEditClass::Change_House -- changes CurrentObject's house *
  38. * MapEditClass::Grab_Object -- grabs the current object *
  39. * MapEditClass::Move_Grabbed_Object -- moves the grabbed object *
  40. * MapEditClass::Popup_Controls -- shows/hides the pop-up object controls*
  41. * MapEditClass::Select_Next -- selects next object on the map *
  42. * MapEditClass::Select_Object -- selects an object for processing *
  43. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  44. #include "function.h"
  45. #ifdef SCENARIO_EDITOR
  46. /***************************************************************************
  47. * Select_Object -- selects an object for processing *
  48. * *
  49. * INPUT: *
  50. * none. *
  51. * *
  52. * OUTPUT: *
  53. * 0 = object selected, -1 = none *
  54. * *
  55. * WARNINGS: *
  56. * none. *
  57. * *
  58. * HISTORY: *
  59. * 11/04/1994 BR : Created. *
  60. *=========================================================================*/
  61. int MapEditClass::Select_Object(void)
  62. {
  63. ObjectClass * object=NULL; // Generic object clicked on.
  64. int x,y;
  65. CELL cell; // Cell that was selected.
  66. int rc=0;
  67. /*
  68. ** See if an object was clicked on
  69. */
  70. x = Keyboard->MouseQX;
  71. y = Keyboard->MouseQY;
  72. /*
  73. ** Get cell for x,y
  74. */
  75. cell = Click_Cell_Calc(x, y);
  76. /*
  77. ** Convert x,y to offset from cell upper-left
  78. */
  79. x = (x-TacPixelX) % ICON_PIXEL_W;
  80. y = (y-TacPixelY) % ICON_PIXEL_H;
  81. /*
  82. ** Get object at that x,y
  83. */
  84. object = Cell_Object(cell, x, y);
  85. /*
  86. ** If no object, unselect the current one
  87. */
  88. if (!object) {
  89. if (CurrentObject.Count()) {
  90. /*
  91. ** Unselect all current objects
  92. */
  93. Unselect_All();
  94. /*
  95. ** Turn off object controls
  96. */
  97. Popup_Controls();
  98. }
  99. rc = -1;
  100. } else {
  101. /*
  102. ** Select object only if it's different
  103. */
  104. if (!CurrentObject.Count() || (CurrentObject.Count() && object != CurrentObject[0])) {
  105. /*
  106. ** Unselect all current objects
  107. */
  108. Unselect_All();
  109. object->Select();
  110. /*
  111. ** Set mouse shape back to normal
  112. */
  113. Set_Default_Mouse(MOUSE_NORMAL);
  114. Override_Mouse_Shape(MOUSE_NORMAL);
  115. /*
  116. ** Show the popup controls
  117. */
  118. Popup_Controls();
  119. }
  120. }
  121. /*
  122. ** Force map to redraw
  123. */
  124. HidPage.Clear();
  125. Flag_To_Redraw(true);
  126. return(rc);
  127. }
  128. /***************************************************************************
  129. * MapEditClass::Select_Next -- selects next object on the map *
  130. * *
  131. * INPUT: *
  132. * none. *
  133. * *
  134. * OUTPUT: *
  135. * none *
  136. * *
  137. * WARNINGS: *
  138. * none. *
  139. * *
  140. * HISTORY: *
  141. * 11/22/1994 BR : Created. *
  142. *=========================================================================*/
  143. void MapEditClass::Select_Next(void)
  144. {
  145. ObjectClass * obj;
  146. CELL obj_cell;
  147. int smap_w; // screen map width in icons
  148. int smap_h; // screen map height in icons
  149. int cell_x; // cell-x of next object
  150. int cell_y; // cell-y of next object
  151. int tcell_x; // cell-x of TacticalCell
  152. int tcell_y; // cell-y of TacticalCell
  153. /*
  154. ** Get next object on the map
  155. */
  156. obj = Map.Next_Object(CurrentObject[0]);
  157. if (obj) {
  158. /*
  159. ** Unselect current object if there is one
  160. */
  161. Unselect_All();
  162. /*
  163. ** Select this object
  164. */
  165. obj->Select();
  166. }
  167. /*
  168. ** Restore mouse shape to normal
  169. */
  170. Set_Default_Mouse(MOUSE_NORMAL);
  171. Override_Mouse_Shape(MOUSE_NORMAL);
  172. /*
  173. ** Show pop-up controls
  174. */
  175. Popup_Controls();
  176. /*
  177. ** Make sure object is shown on the screen
  178. */
  179. /*
  180. ** compute screen map dimensions
  181. */
  182. smap_w = Lepton_To_Cell(TacLeptonWidth);
  183. smap_h = Lepton_To_Cell(TacLeptonHeight);
  184. /*
  185. ** compute x,y of object's cell
  186. */
  187. obj_cell = Coord_Cell(CurrentObject[0]->Coord);
  188. cell_x = Cell_X(obj_cell);
  189. cell_y = Cell_Y(obj_cell);
  190. tcell_x = Coord_XCell(TacticalCoord);
  191. tcell_y = Coord_YCell(TacticalCoord);
  192. /*
  193. ** If object is off-screen, move map
  194. */
  195. if (cell_x < tcell_x) {
  196. tcell_x = cell_x;
  197. } else {
  198. if (cell_x >= tcell_x + smap_w) {
  199. tcell_x = cell_x - smap_w + 1;
  200. }
  201. }
  202. if (cell_y < tcell_y) {
  203. tcell_y = cell_y;
  204. } else {
  205. if (cell_y >= tcell_y + smap_h) {
  206. tcell_y = cell_y - smap_h + 1;
  207. }
  208. }
  209. ScenarioInit++;
  210. Set_Tactical_Position(XY_Coord(Cell_To_Lepton(tcell_x), Cell_To_Lepton(tcell_y)));
  211. ScenarioInit--;
  212. /*
  213. ** Force map to redraw
  214. */
  215. HidPage.Clear();
  216. Flag_To_Redraw(true);
  217. }
  218. /***************************************************************************
  219. * MapEditClass::Popup_Controls -- shows/hides the pop-up object controls *
  220. * *
  221. * Call this routine whenever the CurrentObject changes. The routine will *
  222. * selectively enable or disable the popup controls based on whether *
  223. * CurrentObject is NULL, or if it's a Techno object, or what type of *
  224. * Techno object it is. *
  225. * *
  226. * INPUT: *
  227. * none. *
  228. * *
  229. * OUTPUT: *
  230. * none. *
  231. * *
  232. * WARNINGS: *
  233. * none. *
  234. * *
  235. * HISTORY: *
  236. * 11/22/1994 BR : Created. *
  237. * 04/30/1996 JLB : Revamped for new buttons and stuff. *
  238. *=========================================================================*/
  239. void MapEditClass::Popup_Controls(void)
  240. {
  241. const TechnoTypeClass * objtype = NULL;
  242. HousesType owner; // object's current owner
  243. int mission_index; // object's current mission
  244. int strength; // object's 0-255 strength value
  245. int i;
  246. /*
  247. ** Remove all buttons from GScreen's button list (so none of them provide
  248. ** input any more); then, destroy the list by Zapping each button. Then,
  249. ** we'll have to add at least the MapArea button back to the Input button
  250. ** list before we return, plus any other buttons to process input for. We
  251. ** always must add MapArea LAST in the list, so it doesn't intercept the
  252. ** other buttons' input.
  253. */
  254. Remove_A_Button(*HouseList);
  255. Remove_A_Button(*MissionList);
  256. Remove_A_Button(*HealthGauge);
  257. Remove_A_Button(*HealthText);
  258. Remove_A_Button(*FacingDial);
  259. Remove_A_Button(*BaseGauge);
  260. Remove_A_Button(*BaseLabel);
  261. Remove_A_Button(*MapArea);
  262. Remove_A_Button(*Sellable);
  263. Remove_A_Button(*Rebuildable);
  264. /*
  265. ** If no current object, hide the list
  266. */
  267. if (!CurrentObject.Count()) {
  268. Add_A_Button(*BaseGauge);
  269. Add_A_Button(*BaseLabel);
  270. Add_A_Button(*MapArea);
  271. return;
  272. }
  273. /*
  274. ** If not Techno, no need for editing buttons
  275. */
  276. if (!CurrentObject[0]->Is_Techno()) {
  277. Add_A_Button(*BaseGauge);
  278. Add_A_Button(*BaseLabel);
  279. Add_A_Button(*MapArea);
  280. return;
  281. }
  282. objtype = (TechnoTypeClass const *)&CurrentObject[0]->Class_Of();
  283. /*
  284. ** Get object's current values
  285. */
  286. owner = CurrentObject[0]->Owner();
  287. mission_index = 0;
  288. for (i = 0; i < NUM_EDIT_MISSIONS; i++) {
  289. if (CurrentObject[0]->Get_Mission() == MapEditMissions[i]) {
  290. mission_index = i;
  291. }
  292. }
  293. strength = CurrentObject[0]->Health_Ratio()*256;
  294. switch (objtype->What_Am_I()) {
  295. case RTTI_VESSELTYPE:
  296. case RTTI_UNITTYPE:
  297. case RTTI_INFANTRYTYPE:
  298. case RTTI_AIRCRAFTTYPE:
  299. MissionList->Set_Selected_Index(mission_index);
  300. HealthGauge->Set_Value(strength);
  301. sprintf(HealthBuf, "%d", CurrentObject[0]->Strength);
  302. FacingDial->Set_Direction(((TechnoClass *)CurrentObject[0])->PrimaryFacing);
  303. /*
  304. ** Make the list.
  305. */
  306. Add_A_Button(*HealthGauge);
  307. Add_A_Button(*HouseList);
  308. HouseList->Set_Selected_Index(owner);
  309. Add_A_Button(*MissionList);
  310. Add_A_Button(*HealthText);
  311. Add_A_Button(*FacingDial);
  312. break;
  313. case RTTI_BUILDINGTYPE:
  314. HealthGauge->Set_Value(strength);
  315. sprintf(HealthBuf, "%d", CurrentObject[0]->Strength);
  316. Add_A_Button(*HealthGauge);
  317. Add_A_Button(*HouseList);
  318. HouseList->Set_Selected_Index(owner);
  319. Add_A_Button(*HealthText);
  320. Add_A_Button(*Sellable);
  321. if (((BuildingClass*)CurrentObject[0])->IsAllowedToSell) {
  322. Sellable->Turn_On();
  323. } else {
  324. Sellable->Turn_Off();
  325. }
  326. Add_A_Button(*Rebuildable);
  327. if (((BuildingClass*)CurrentObject[0])->IsToRebuild) {
  328. Rebuildable->Turn_On();
  329. } else {
  330. Rebuildable->Turn_Off();
  331. }
  332. if (objtype->IsTurretEquipped) {
  333. FacingDial->Set_Direction(((TechnoClass *) CurrentObject[0])->PrimaryFacing);
  334. Add_A_Button(*FacingDial);
  335. }
  336. break;
  337. }
  338. /*
  339. ** Add the map area last, so it's "underneath" the other buttons, and won't
  340. ** intercept input for those buttons.
  341. */
  342. Add_A_Button(*BaseGauge);
  343. Add_A_Button(*BaseLabel);
  344. Add_A_Button(*MapArea);
  345. }
  346. /***************************************************************************
  347. * MapEditClass::Grab_Object -- grabs the current object *
  348. * *
  349. * INPUT: *
  350. * none. *
  351. * *
  352. * OUTPUT: *
  353. * none. *
  354. * *
  355. * WARNINGS: *
  356. * none. *
  357. * *
  358. * HISTORY: *
  359. * 11/07/1994 BR : Created. *
  360. *=========================================================================*/
  361. void MapEditClass::Grab_Object(void)
  362. {
  363. CELL cell;
  364. if (CurrentObject.Count()) {
  365. GrabbedObject = CurrentObject[0];
  366. /*
  367. ** Find out which cell 'ZoneCell' is in relation to the object's current cell
  368. */
  369. cell = Coord_Cell(GrabbedObject->Coord);
  370. GrabOffset = cell - ZoneCell;
  371. }
  372. }
  373. /***************************************************************************
  374. * MapEditClass::Move_Grabbed_Object -- moves the grabbed object *
  375. * *
  376. * INPUT: *
  377. * none. *
  378. * *
  379. * OUTPUT: *
  380. * 0 = object moved, -1 = it didn't *
  381. * *
  382. * WARNINGS: *
  383. * none. *
  384. * *
  385. * HISTORY: *
  386. * 11/07/1994 BR : Created. *
  387. *=========================================================================*/
  388. int MapEditClass::Move_Grabbed_Object(void)
  389. {
  390. COORDINATE new_coord = 0;
  391. int retval = -1;
  392. /*
  393. ** Lift up the object
  394. */
  395. GrabbedObject->Mark(MARK_UP);
  396. /*
  397. ** If infantry, use a free spot in this cell
  398. */
  399. if (GrabbedObject->Is_Infantry()) {
  400. if (Is_Spot_Free(Pixel_To_Coord(Get_Mouse_X(), Get_Mouse_Y()))) {
  401. new_coord = Closest_Free_Spot(Pixel_To_Coord(Get_Mouse_X(), Get_Mouse_Y()));
  402. /*
  403. ** Clear the occupied bit in this infantry's cell.
  404. */
  405. ((InfantryClass *)GrabbedObject)->Clear_Occupy_Bit(GrabbedObject->Coord);
  406. } else {
  407. new_coord = NULL;
  408. }
  409. } else {
  410. /*
  411. ** Non-infantry: use cell's center coordinate
  412. */
  413. new_coord = Cell_Coord(ZoneCell + GrabOffset);
  414. if (GrabbedObject->What_Am_I() == RTTI_BUILDING ||
  415. GrabbedObject->What_Am_I() == RTTI_TERRAIN) {
  416. new_coord = Coord_Whole(new_coord);
  417. }
  418. /*
  419. ** Try to place object at new coordinate
  420. */
  421. if (GrabbedObject->Can_Enter_Cell(Coord_Cell(new_coord)) != MOVE_OK) {
  422. new_coord = NULL;
  423. }
  424. }
  425. if (new_coord != NULL) {
  426. /*
  427. ** If this object is part of the AI's Base list, change the coordinate
  428. ** in the Base's Node list.
  429. */
  430. if (GrabbedObject->What_Am_I()==RTTI_BUILDING &&
  431. Base.Get_Node((BuildingClass *)GrabbedObject))
  432. Base.Get_Node((BuildingClass *)GrabbedObject)->Cell = Coord_Cell(new_coord);
  433. GrabbedObject->Coord = new_coord;
  434. retval = 0;
  435. }
  436. GrabbedObject->Mark(MARK_DOWN);
  437. /*
  438. ** For infantry, set the bit in its new cell marking that spot as occupied.
  439. */
  440. if (GrabbedObject->Is_Infantry()) {
  441. ((InfantryClass *)GrabbedObject)->Set_Occupy_Bit(new_coord);
  442. }
  443. /*
  444. ** Re-select the object, and reset the mouse pointer
  445. */
  446. Set_Default_Mouse(MOUSE_NORMAL);
  447. Override_Mouse_Shape(MOUSE_NORMAL);
  448. Flag_To_Redraw(true);
  449. return(retval);
  450. }
  451. /***************************************************************************
  452. * MapEditClass::Change_House -- changes CurrentObject's house *
  453. * *
  454. * INPUT: *
  455. * newhouse house to change to *
  456. * *
  457. * OUTPUT: *
  458. * 1 = house was changed, 0 = it wasn't *
  459. * *
  460. * WARNINGS: *
  461. * none. *
  462. * *
  463. * HISTORY: *
  464. * 11/17/1994 BR : Created. *
  465. *=========================================================================*/
  466. bool MapEditClass::Change_House(HousesType newhouse)
  467. {
  468. TechnoClass *tp;
  469. /*
  470. ** Return if no current object
  471. */
  472. if (!CurrentObject.Count()) {
  473. return(false);
  474. }
  475. /*
  476. ** Only techno objects can be owned by a house; return if not a techno
  477. */
  478. if (!CurrentObject[0]->Is_Techno()) {
  479. return(false);
  480. }
  481. /*
  482. ** You can't change the house if the object is part of the AI's Base.
  483. */
  484. if (CurrentObject[0]->What_Am_I()==RTTI_BUILDING && Base.Is_Node((BuildingClass *)CurrentObject[0])) {
  485. return(false);
  486. }
  487. /*
  488. ** Verify that the target house exists
  489. */
  490. if (HouseClass::As_Pointer(newhouse)==NULL) {
  491. return(false);
  492. }
  493. /*
  494. ** Verify that this is a valid owner
  495. */
  496. // if (!Verify_House(newhouse, &CurrentObject[0]->Class_Of())) {
  497. // return(false);
  498. // }
  499. /*
  500. ** Change the house
  501. */
  502. tp = (TechnoClass *)CurrentObject[0];
  503. tp->House = HouseClass::As_Pointer(newhouse);
  504. tp->IsOwnedByPlayer = false;
  505. if (tp->House == PlayerPtr) {
  506. tp->IsOwnedByPlayer = true;
  507. }
  508. return(true);
  509. }
  510. #endif