ANIM.CPP.BAK 52 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062
  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: F:\projects\c&c0\vcs\code\anim.cpv 4.78 03 Oct 1996 09:20:46 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 : Dune *
  24. * *
  25. * File Name : ANIM.CPP *
  26. * *
  27. * Programmer : Joe L. Bostic *
  28. * *
  29. * Start Date : June 3, 1991 *
  30. * *
  31. *---------------------------------------------------------------------------------------------*
  32. * Functions: *
  33. * AnimClass::AI -- This is the low level anim processor. *
  34. * AnimClass::AnimClass -- The constructor for animation objects. *
  35. * AnimClass::Attach_To -- Attaches animation to object specified. *
  36. * AnimClass::Center_Coord -- Determine center of animation. *
  37. * AnimClass::Detach -- Remove animation if attached to target. *
  38. * AnimClass::Do_Atom_Damage -- Do atom bomb damage centered around the cell specified. *
  39. * AnimClass::Draw_It -- Draws the animation at the location specified. *
  40. * AnimClass::In_Which_Layer -- Determines what render layer the anim should be in. *
  41. * AnimClass::Init -- Performs pre-scenario initialization. *
  42. * AnimClass::Mark -- Signals to map that redrawing is necessary. *
  43. * AnimClass::Middle -- Processes any middle events. *
  44. * AnimClass::Occupy_List -- Determines the occupy list for the animation. *
  45. * AnimClass::Overlap_List -- Determines the overlap list for the animation. *
  46. * AnimClass::Render -- Draws an animation object. *
  47. * AnimClass::Sort_Y -- Returns with the sorting coordinate for the animation. *
  48. * AnimClass::Start -- Processes initial animation side effects. *
  49. * AnimClass::delete -- Returns an anim object back to the free pool. *
  50. * AnimClass::new -- Allocates an anim object from the pool. *
  51. * AnimClass::~AnimClass -- Destructor for anim objects. *
  52. * Anim_From_Name -- Given a name, this finds the corresponding anim type. *
  53. * Shorten_Attached_Anims -- Reduces attached animation durations. *
  54. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  55. #include "function.h"
  56. /***********************************************************************************************
  57. * Anim_From_Name -- Given a name, this finds the corresponding anim type. *
  58. * *
  59. * This routine will convert the supplied ASCII name into the animation type that it *
  60. * represents. *
  61. * *
  62. * INPUT: name -- Pointer to the ASCII name to convert. *
  63. * *
  64. * OUTPUT: Returns with the animation type that matches the name specified. If no match could *
  65. * be found, then ANIM_NONE is returned. *
  66. * *
  67. * WARNINGS: none *
  68. * *
  69. * HISTORY: *
  70. * 07/06/1996 JLB : Created. *
  71. *=============================================================================================*/
  72. AnimType Anim_From_Name(char const * name)
  73. {
  74. #ifdef 0
  75. if (name == NULL) return(ANIM_NONE);
  76. for (AnimType anim = ANIM_FIRST; anim < ANIM_COUNT; anim++) {
  77. if (stricmp(AnimTypeClass::As_Reference(anim).IniName, name) == 0) {
  78. return(anim);
  79. }
  80. }
  81. #endif
  82. return(ANIM_NONE);
  83. }
  84. /***********************************************************************************************
  85. * Shorten_Attached_Anims -- Reduces attached animation durations. *
  86. * *
  87. * This routine is used to reduce the amount of time any attached animations will process. *
  88. * Typical use of this is when an object is on fire and the object should now be destroyed *
  89. * but the attached animations are to run until completion before destruction can follow. *
  90. * This routine will make the animation appear to run its course, but in as short of time *
  91. * as possible. The shortening effect is achieved by reducing the number of times the *
  92. * animation will loop. *
  93. * *
  94. * INPUT: obj -- Pointer to the object that all attached animations will be processed. *
  95. * *
  96. * OUTPUT: none *
  97. * *
  98. * WARNINGS: none *
  99. * *
  100. * HISTORY: *
  101. * 12/11/1994 JLB : Created. *
  102. *=============================================================================================*/
  103. void Shorten_Attached_Anims(ObjectClass * obj)
  104. {
  105. if (obj != NULL) {
  106. for (int index = 0; index < Anims.Count(); index++) {
  107. AnimClass & anim = * Anims.Ptr(index);
  108. if (As_Object(anim.xObject) == obj) {
  109. anim.Loops = 0;
  110. }
  111. }
  112. }
  113. }
  114. /***********************************************************************************************
  115. * AnimClass::Sort_Y -- Returns with the sorting coordinate for the animation. *
  116. * *
  117. * This routine is used by the sorting system. Animations that are located in the ground *
  118. * layer will be sorted by this the value returned from this function. *
  119. * *
  120. * INPUT: none *
  121. * *
  122. * OUTPUT: Returns with the sort coordinate to use for this animation. *
  123. * *
  124. * WARNINGS: none *
  125. * *
  126. * HISTORY: *
  127. * 10/17/1994 JLB : Created. *
  128. * 12/15/1994 JLB : Handles flat anims (infantry decay anims). *
  129. *=============================================================================================*/
  130. COORDINATE AnimClass::Sort_Y(void) const
  131. {
  132. #ifdef 0
  133. assert(Anims.ID(this) == ID);
  134. assert(IsActive);
  135. if (xObject != TARGET_NONE) {
  136. return(Coord_Add(As_Object(xObject)->Sort_Y(), 0x00010000L));
  137. }
  138. if (*this == ANIM_MOVE_FLASH) {
  139. return(Coord_Add(Center_Coord(), XYP_COORD(0, -24)));
  140. }
  141. if (Class->IsGroundLayer || *this == ANIM_LZ_SMOKE) {
  142. return(Coord_Add(Center_Coord(), XYP_COORD(0, 14)));
  143. }
  144. #endif
  145. return(Coord);
  146. }
  147. /***********************************************************************************************
  148. * AnimClass::Center_Coord -- Determine center of animation. *
  149. * *
  150. * This support function will return the "center" of the animation. The actual coordinate *
  151. * of the animation may be dependant on if the the animation is attached to an object. *
  152. * In such a case, it must factor in the object's location. *
  153. * *
  154. * INPUT: none *
  155. * *
  156. * OUTPUT: Returns the coordinate of the center of the animation. The coordinate is in real *
  157. * game coordinates -- taking into consideration if the animation is attached. *
  158. * *
  159. * WARNINGS: none *
  160. * *
  161. * HISTORY: *
  162. * 09/19/1994 JLB : Created. *
  163. * 02/02/1996 JLB : Coordinate based on visual center of object. *
  164. *=============================================================================================*/
  165. COORDINATE AnimClass::Center_Coord(void) const
  166. {
  167. #ifdef 0
  168. assert(Anims.ID(this) == ID);
  169. assert(IsActive);
  170. if (xObject != TARGET_NONE) {
  171. return(Coord_Add(Coord, As_Object(xObject)->Target_Coord()));
  172. }
  173. #endif
  174. return(Coord);
  175. }
  176. /***********************************************************************************************
  177. * AnimClass::Render -- Draws an animation object. *
  178. * *
  179. * This is the working routine that renders the animation shape. It gets called once *
  180. * per animation per frame. It needs to be fast. *
  181. * *
  182. * INPUT: bool; Should the animation be rendered in spite of render flag? *
  183. * *
  184. * OUTPUT: bool; Was the animation rendered? *
  185. * *
  186. * WARNINGS: none *
  187. * *
  188. * HISTORY: *
  189. * 05/31/1994 JLB : Created. *
  190. *=============================================================================================*/
  191. bool AnimClass::Render(bool forced) const
  192. {
  193. #ifdef 0
  194. assert(Anims.ID(this) == ID);
  195. assert(IsActive);
  196. if (Delay) return(false);
  197. if (Map[Center_Coord()].IsVisible) {
  198. IsToDisplay = true;
  199. }
  200. #endif
  201. return(ObjectClass::Render(forced));
  202. }
  203. /***********************************************************************************************
  204. * AnimClass::Draw_It -- Draws the animation at the location specified. *
  205. * *
  206. * This routine is used to render the animation object at the location specified. This is *
  207. * how the map imagery gets updated. *
  208. * *
  209. * INPUT: x,y -- The pixel coordinates to draw the animation at. *
  210. * *
  211. * window -- The to base the draw coordinates upon. *
  212. * *
  213. * OUTPUT: none *
  214. * *
  215. * WARNINGS: none *
  216. * *
  217. * HISTORY: *
  218. * 09/24/1994 JLB : Created. *
  219. * 05/19/1995 JLB : Added white translucent effect. *
  220. *=============================================================================================*/
  221. void AnimClass::Draw_It(int x, int y, WindowNumberType window) const
  222. {
  223. #ifdef 0
  224. assert(Anims.ID(this) == ID);
  225. assert(IsActive);
  226. if (!IsInvisible) {
  227. BStart(BENCH_ANIMS);
  228. void const * shapefile = Get_Image_Data();
  229. if (shapefile != NULL) {
  230. void const * transtable = NULL;
  231. int shapenum = Class->Start + Fetch_Stage();
  232. void const * remap = NULL;
  233. /*
  234. ** If the translucent table hasn't been determined yet, then check to see if it
  235. ** should use the white or normal translucent tables.
  236. */
  237. if (transtable == NULL && Class->IsWhiteTrans) transtable = DisplayClass::WhiteTranslucentTable;
  238. if (transtable == NULL && Class->IsTranslucent) transtable = DisplayClass::TranslucentTable;
  239. if (Class->Type == ANIM_ATOM_BLAST) transtable = Map.UnitShadow;
  240. /*
  241. ** Set the shape flags to properly take into account any fading or ghosting
  242. ** table necessary.
  243. */
  244. ShapeFlags_Type flags = SHAPE_CENTER|SHAPE_WIN_REL;
  245. if (transtable != NULL) flags = flags | SHAPE_GHOST;
  246. /*
  247. ** Draw the animation shape.
  248. */
  249. CC_Draw_Shape(shapefile, shapenum, x, y, window, flags, remap, transtable);
  250. }
  251. BEnd(BENCH_ANIMS);
  252. }
  253. #endif
  254. }
  255. /***********************************************************************************************
  256. * AnimClass::Mark -- Signals to map that redrawing is necessary. *
  257. * *
  258. * This routine is used by the animation logic system to inform the map that the cells *
  259. * under the animation must be rerendered. *
  260. * *
  261. * INPUT: *
  262. * *
  263. * OUTPUT: none *
  264. * *
  265. * WARNINGS: none *
  266. * *
  267. * HISTORY: *
  268. * 05/31/1994 JLB : Created. *
  269. *=============================================================================================*/
  270. bool AnimClass::Mark(MarkType mark)
  271. {
  272. #ifdef 0
  273. assert(Anims.ID(this) == ID);
  274. assert(IsActive);
  275. if (ObjectClass::Mark(mark)) {
  276. Map.Refresh_Cells(Coord_Cell(Center_Coord()), Overlap_List());
  277. // ObjectClass::Mark(mark);
  278. return(true);
  279. }
  280. #endif
  281. return(false);
  282. }
  283. /***********************************************************************************************
  284. * AnimClass::Overlap_List -- Determines the overlap list for the animation. *
  285. * *
  286. * Use this routine to fetch the overlap list for the animation. This overlap list is the *
  287. * cells that this animation spills over. *
  288. * *
  289. * INPUT: none *
  290. * *
  291. * OUTPUT: Returns a pointer to the overlap list for this particular instance of the *
  292. * animation. *
  293. * *
  294. * WARNINGS: none *
  295. * *
  296. * HISTORY: *
  297. * 03/19/1995 JLB : Created. *
  298. *=============================================================================================*/
  299. short const * AnimClass::Overlap_List(void) const
  300. {
  301. #ifdef 0
  302. assert(Anims.ID(this) == ID);
  303. assert(IsActive);
  304. static short const OverlapAtom[] = {
  305. (-MAP_CELL_W * 2) - 1, (-MAP_CELL_W * 2), (-MAP_CELL_W * 2) + 1,
  306. (-MAP_CELL_W * 1) - 1, (-MAP_CELL_W * 1), (-MAP_CELL_W * 1) + 1,
  307. (-MAP_CELL_W * 0) - 1, (-MAP_CELL_W * 0), (-MAP_CELL_W * 0) + 1,
  308. ( MAP_CELL_W * 1) - 1, ( MAP_CELL_W * 1), ( MAP_CELL_W * 1) + 1,
  309. ( MAP_CELL_W * 2) - 1, ( MAP_CELL_W * 2), ( MAP_CELL_W * 2) + 1,
  310. REFRESH_EOL
  311. };
  312. if (IsToDelete) {
  313. static short const _list[] = {REFRESH_EOL};
  314. return(_list);
  315. }
  316. if (Class->Type == ANIM_ATOM_BLAST) {
  317. return(OverlapAtom);
  318. }
  319. #ifdef PARTIAL
  320. if (Class->Get_Image_Data() != NULL) {
  321. int shapenum = Class->Start + Fetch_Stage();
  322. int count = Get_Build_Frame_Count(Class->Get_Image_Data());
  323. shapenum = min(shapenum, count-1);
  324. if (Class->DimensionData == NULL) {
  325. Class->DimensionData = new Rect [count];
  326. }
  327. if (Class->DimensionData != NULL && !Class->DimensionData[shapenum].Is_Valid()) {
  328. Class->DimensionData[shapenum] = Shape_Dimensions(Class->Get_Image_Data(), shapenum);
  329. return(Coord_Spillage_List(Center_Coord(), Class->DimensionData[shapenum]));
  330. }
  331. }
  332. #endif
  333. #endif
  334. return(Coord_Spillage_List(Center_Coord(), Class->Size));
  335. }
  336. /***********************************************************************************************
  337. * AnimClass::Occupy_List -- Determines the occupy list for the animation. *
  338. * *
  339. * Animations always occupy only the cell that their center is located over. As such, this *
  340. * routine always returns a simple (center cell) occupation list. *
  341. * *
  342. * INPUT: none *
  343. * *
  344. * OUTPUT: Returns with the occupation list for the animation. *
  345. * *
  346. * WARNINGS: none *
  347. * *
  348. * HISTORY: *
  349. * 03/19/1995 JLB : Created. *
  350. *=============================================================================================*/
  351. short const * AnimClass::Occupy_List(bool) const
  352. {
  353. #ifdef 0
  354. assert(Anims.ID(this) == ID);
  355. assert(IsActive);
  356. static short _simple[] = {REFRESH_EOL};
  357. #endif
  358. return(_simple);
  359. }
  360. /***********************************************************************************************
  361. * AnimClass::Init -- Performs pre-scenario initialization. *
  362. * *
  363. * This routine is used to initialize the animation system prior to a scenario being loaded *
  364. * or reloaded. It effectively removes all animations from the system. *
  365. * *
  366. * INPUT: none *
  367. * *
  368. * OUTPUT: none *
  369. * *
  370. * WARNINGS: none *
  371. * *
  372. * HISTORY: *
  373. * 05/31/1994 JLB : Created. *
  374. *=============================================================================================*/
  375. void AnimClass::Init(void)
  376. {
  377. Anims.Free_All();
  378. }
  379. /***********************************************************************************************
  380. * AnimClass::new -- Allocates an anim object from the pool. *
  381. * *
  382. * This routine is used to allocate a free anim class object from the preallocated pool *
  383. * in the near heap. If there are no free animation objects, then null is returned. *
  384. * *
  385. * INPUT: none *
  386. * *
  387. * OUTPUT: Returns with a pointer to a free anim object. *
  388. * *
  389. * WARNINGS: none *
  390. * *
  391. * HISTORY: *
  392. * 05/31/1994 JLB : Created. *
  393. *=============================================================================================*/
  394. void * AnimClass::operator new(size_t)
  395. {
  396. void * ptr = Anims.Allocate();
  397. if (ptr != NULL) {
  398. ((AnimClass *)ptr)->IsActive = true;
  399. }
  400. return(ptr);
  401. }
  402. /***********************************************************************************************
  403. * AnimClass::delete -- Returns an anim object back to the free pool. *
  404. * *
  405. * This routine is used to return an anim object back to the pool of free anim objects. *
  406. * Anim objects so returned are available to be reallocated for the next animation. *
  407. * *
  408. * INPUT: ptr -- Pointer to the anim object to return to the pool. *
  409. * *
  410. * OUTPUT: none *
  411. * *
  412. * WARNINGS: none *
  413. * *
  414. * HISTORY: *
  415. * 05/31/1994 JLB : Created. *
  416. *=============================================================================================*/
  417. void AnimClass::operator delete(void * ptr)
  418. {
  419. if (ptr != NULL) {
  420. ((AnimClass *)ptr)->IsActive = false;
  421. }
  422. Anims.Free((AnimClass *)ptr);
  423. }
  424. /***********************************************************************************************
  425. * AnimClass::AnimClass -- The constructor for animation objects. *
  426. * *
  427. * This routine is used as the constructor of animation objects. It initializes and adds *
  428. * the animation object to the display and logic systems. *
  429. * *
  430. * INPUT: animnum -- The animation number to start. *
  431. * *
  432. * coord -- The location of the animation. *
  433. * *
  434. * timedelay-- The delay before the animation starts. *
  435. * *
  436. * loop -- The number of times to loop this animation. *
  437. * *
  438. * OUTPUT: none *
  439. * *
  440. * WARNINGS: none *
  441. * *
  442. * HISTORY: *
  443. * 05/31/1994 JLB : Created. *
  444. * 08/03/1994 JLB : Added a delayed affect parameter. *
  445. *=============================================================================================*/
  446. AnimClass::AnimClass(AnimType animnum, COORDINATE coord, unsigned char timedelay, unsigned char loop) :
  447. ObjectClass(RTTI_ANIM, Anims.ID(this)),
  448. Class(AnimTypes.Ptr((int)animnum)),
  449. xObject(TARGET_NONE),
  450. OwnerHouse(HOUSE_NONE),
  451. Loops(1),
  452. IsToDelete(false),
  453. IsBrandNew(true),
  454. IsInvisible(false),
  455. Delay(timedelay),
  456. Accum(0)
  457. {
  458. #ifdef 0
  459. if (Class->Stages == -1) {
  460. ((int&)Class->Stages) = Get_Build_Frame_Count(Class->Get_Image_Data());
  461. }
  462. if (Class->LoopEnd == -1) {
  463. ((int&)Class->LoopEnd) = Class->Stages;
  464. }
  465. if (Class->IsNormalized) {
  466. Set_Rate(Options.Normalize_Delay(Class->Delay));
  467. } else {
  468. Set_Rate(Class->Delay);
  469. }
  470. Set_Stage(0);
  471. if (Class->IsGroundLayer) {
  472. Height = FLIGHT_LEVEL;
  473. }
  474. AnimClass::Unlimbo(coord);
  475. /*
  476. ** Drop zone smoke always reveals the map around itself.
  477. */
  478. if (*this == ANIM_LZ_SMOKE) {
  479. Map.Sight_From(Coord_Cell(coord), Rule.DropZoneRadius / CELL_LEPTON_W, PlayerPtr, false);
  480. }
  481. Loops = (unsigned char)(max(loop, 1) * Class->Loops);
  482. Loops = (unsigned char)max(Loops, 1);
  483. /*
  484. ** If the animation starts immediately, then play the associated sound effect now.
  485. */
  486. if (!Delay) {
  487. Start();
  488. }
  489. #endif
  490. }
  491. /***********************************************************************************************
  492. * AnimClass::~AnimClass -- Destructor for anim objects. *
  493. * *
  494. * This destructor handles removing the animation object from the system. It might require *
  495. * informing any object this animation is attached to that it is no longer attached. *
  496. * *
  497. * INPUT: none *
  498. * *
  499. * OUTPUT: none *
  500. * *
  501. * WARNINGS: none *
  502. * *
  503. * HISTORY: *
  504. * 11/29/1994 JLB : Created. *
  505. *=============================================================================================*/
  506. AnimClass::~AnimClass(void)
  507. {
  508. #ifdef 0
  509. assert(Anims.ID(this) == ID);
  510. assert(IsActive);
  511. if (GameActive) {
  512. /*
  513. ** If this anim is attached to another object
  514. ** then check to see if this is the last anim attached to it. If this
  515. ** is the case, then inform the object that it is no longer attached to
  516. ** an animation.
  517. */
  518. if (Target_Legal(xObject) && As_Object(xObject) != NULL) {
  519. ObjectClass * to = As_Object(xObject);
  520. /*
  521. ** Remove the object from the appropriate display list.
  522. */
  523. Map.Remove(this, In_Which_Layer());
  524. /*
  525. ** Scan for any other animations that are attached to the object that
  526. ** this animation is attached to. If there are no others, then inform the
  527. ** attached object of this fact.
  528. */
  529. for (int index = 0; index < Anims.Count(); index++) {
  530. if (Anims.Ptr(index) != this && Anims.Ptr(index)->xObject == xObject) break;
  531. }
  532. /*
  533. ** Tell the object that it is no longer being damaged.
  534. */
  535. if (index == Anims.Count()) {
  536. to->Fire_Out();
  537. to->Mark(MARK_OVERLAP_UP);
  538. to->IsAnimAttached = false;
  539. to->Mark(MARK_OVERLAP_DOWN);
  540. }
  541. Coord = Coord_Add(to->Center_Coord(), Coord);
  542. xObject = TARGET_NONE;
  543. }
  544. Limbo();
  545. }
  546. xObject = TARGET_NONE;
  547. Class = 0;
  548. ID = -1;
  549. #endif
  550. }
  551. /***********************************************************************************************
  552. * AnimClass::AI -- This is the low level anim processor. *
  553. * *
  554. * This routine is called once per frame per animation. It handles transition between *
  555. * animation frames and marks the map for redraw as necessary. *
  556. * *
  557. * INPUT: none *
  558. * *
  559. * OUTPUT: none *
  560. * *
  561. * WARNINGS: Speed is of upmost importance. *
  562. * *
  563. * HISTORY: *
  564. * 05/31/1994 JLB : Created. *
  565. *=============================================================================================*/
  566. void AnimClass::AI(void)
  567. {
  568. #ifdef 0
  569. assert(Anims.ID(this) == ID);
  570. assert(IsActive);
  571. /*
  572. ** For ground level based animations (ones that can run slowly as well as
  573. ** occur behind other ground objects) always cause the cell to be redrawn.
  574. */
  575. #ifdef PARTIAL
  576. if (!Delay && Class->IsGroundLayer) {
  577. Map.Refresh_Cells(Coord_Cell(Center_Coord()), Overlap_List());
  578. }
  579. #else
  580. Map.Refresh_Cells(Coord_Cell(Center_Coord()), Overlap_List());
  581. #endif
  582. /*
  583. ** Special case check to make sure that building on top of a smoke marker
  584. ** causes the smoke marker to vanish.
  585. */
  586. if (Class->Type == ANIM_LZ_SMOKE && Map[Center_Coord()].Cell_Building()) {
  587. IsToDelete = true;
  588. }
  589. /*
  590. ** Delete this animation and bail early if the animation is flagged to be deleted
  591. ** immediately.
  592. */
  593. if (IsToDelete) {
  594. delete this;
  595. return;
  596. }
  597. /*
  598. ** If this is a brand new animation, then don't process it the first logic pass
  599. ** since it might end up skipping the first animation frame before it has had a
  600. ** chance to draw it.
  601. */
  602. if (IsBrandNew) {
  603. IsBrandNew = false;
  604. return;
  605. }
  606. if (Delay) {
  607. Delay--;
  608. if (!Delay) {
  609. Start();
  610. }
  611. } else {
  612. /*
  613. ** This is necessary because there is no recording of animations on the map
  614. ** and thus the animation cannot be intelligently flagged for redraw. Most
  615. ** animations move fast enough that they would need to be redrawn every
  616. ** game frame anyway so this isn't TOO bad.
  617. */
  618. Mark(MARK_CHANGE);
  619. if (StageClass::Graphic_Logic()) {
  620. int stage = Fetch_Stage();
  621. /*
  622. ** If this animation is attached to another object and it is a
  623. ** damaging kind of animation, then do the damage to the other
  624. ** object.
  625. */
  626. if (xObject != TARGET_NONE && Class->Damage > 0) {
  627. Accum += Class->Damage;
  628. if (Accum >= 1) {
  629. /*
  630. ** Administer the damage. If the object was destroyed by this anim,
  631. ** then the attached damaging anim is also destroyed.
  632. */
  633. int damage = Accum;
  634. Accum -= damage;
  635. if (As_Object(xObject)->Take_Damage(damage, 0, WARHEAD_FIRE) == RESULT_DESTROYED) {
  636. delete this;
  637. return;
  638. }
  639. }
  640. }
  641. /*
  642. ** During the biggest stage (covers the most ground), perform any ground altering
  643. ** action required. This masks craters and scorch marks, so that they appear
  644. ** naturally rather than "popping" into existence while in plain sight.
  645. */
  646. if (Class->Biggest && Class->Start+stage == Class->Biggest) {
  647. Middle();
  648. }
  649. /*
  650. ** Check to see if the last frame has been displayed. If so, then the
  651. ** animation either ends or loops.
  652. */
  653. if ((Loops <= 1 && stage >= Class->Stages) || (Loops > 1 && stage >= Class->LoopEnd-Class->Start)) {
  654. /*
  655. ** Determine if this animation should loop another time. If so, then start the loop
  656. ** but if not, then proceed into the animation termination handler.
  657. */
  658. if (Loops) Loops--;
  659. if (Loops) {
  660. Set_Stage(Class->LoopStart);
  661. } else {
  662. /*
  663. ** The animation should end now, but first check to see if
  664. ** it needs to chain into another animation. If so, then the
  665. ** animation isn't technically over. It metamorphoses into the
  666. ** new form.
  667. */
  668. if (Class->ChainTo != ANIM_NONE) {
  669. Class = (AnimTypeClass *)&AnimTypeClass::As_Reference(Class->ChainTo);
  670. if (Class->Stages == -1) {
  671. ((int&)Class->Stages) = Get_Build_Frame_Count(Class->Get_Image_Data());
  672. }
  673. if (Class->LoopEnd == -1) {
  674. ((int&)Class->LoopEnd) = Class->Stages;
  675. }
  676. IsToDelete = false;
  677. Loops = Class->Loops;
  678. Accum = 0;
  679. if (Class->IsNormalized) {
  680. Set_Rate(Options.Normalize_Delay(Class->Delay));
  681. } else {
  682. Set_Rate(Class->Delay);
  683. }
  684. Set_Stage(Class->Start);
  685. Start();
  686. } else {
  687. delete this;
  688. }
  689. }
  690. }
  691. }
  692. }
  693. #endif
  694. }
  695. /***********************************************************************************************
  696. * AnimClass::Attach_To -- Attaches animation to object specified. *
  697. * *
  698. * An animation can be "attached" to an object. In such cases, the animation is rendered *
  699. * as an offset from the center of the object it is attached to. This allows affects such *
  700. * as fire or smoke to be consistently placed on the vehicle it is associated with. *
  701. * *
  702. * INPUT: obj -- Pointer to the object to attach the animation to. *
  703. * *
  704. * OUTPUT: none *
  705. * *
  706. * WARNINGS: none *
  707. * *
  708. * HISTORY: *
  709. * 09/19/1994 JLB : Created. *
  710. *=============================================================================================*/
  711. void AnimClass::Attach_To(ObjectClass * obj)
  712. {
  713. #ifdef 0
  714. assert(Anims.ID(this) == ID);
  715. assert(IsActive);
  716. if (obj == NULL) return;
  717. assert(obj->IsActive);
  718. obj->Mark(MARK_OVERLAP_UP);
  719. obj->IsAnimAttached = true;
  720. obj->Mark(MARK_OVERLAP_DOWN);
  721. Map.Remove(this, In_Which_Layer());
  722. xObject = obj->As_Target();
  723. Map.Submit(this, In_Which_Layer());
  724. Coord = Coord_Sub(Coord, obj->Target_Coord());
  725. #endif
  726. }
  727. /***********************************************************************************************
  728. * AnimClass::In_Which_Layer -- Determines what render layer the anim should be in. *
  729. * *
  730. * Use this routine to find out which display layer (ground or air) that the animation *
  731. * should be in. This information is used to place the animation into the correct display *
  732. * list. *
  733. * *
  734. * INPUT: none *
  735. * *
  736. * OUTPUT: Returns with the layer that the animation should exist in. *
  737. * *
  738. * WARNINGS: none *
  739. * *
  740. * HISTORY: *
  741. * 12/25/1994 JLB : Created. *
  742. *=============================================================================================*/
  743. LayerType AnimClass::In_Which_Layer(void) const
  744. {
  745. #ifdef 0
  746. assert(Anims.ID(this) == ID);
  747. assert(IsActive);
  748. if (Target_Legal(xObject) || Class->IsGroundLayer) {
  749. return(LAYER_GROUND);
  750. }
  751. return(LAYER_AIR);
  752. }
  753. /***********************************************************************************************
  754. * AnimClass::Start -- Processes initial animation side effects. *
  755. * *
  756. * This routine is called when the animation first starts. Sometimes there are side effects *
  757. * associated with this animation that must occur immediately. Typically, this is the *
  758. * sound effect assigned to this animation. If this animation is supposed to attach itself *
  759. * to any object at its location, then do so at this time as well. *
  760. * *
  761. * INPUT: none *
  762. * *
  763. * OUTPUT: none *
  764. * *
  765. * WARNINGS: none *
  766. * *
  767. * HISTORY: *
  768. * 06/30/1995 JLB : Created. *
  769. *=============================================================================================*/
  770. void AnimClass::Start(void)
  771. {
  772. assert(Anims.ID(this) == ID);
  773. assert(IsActive);
  774. Mark();
  775. /*
  776. ** Play the sound effect for this animation.
  777. */
  778. Sound_Effect(Class->Sound, Coord);
  779. /*
  780. ** If the stage where collateral effects occur is the first stage of the animation, then
  781. ** perform this action now. Subsequent checks against this stage value starts with the
  782. ** second frame of the animation.
  783. */
  784. if (!Class->Biggest) {
  785. Middle();
  786. }
  787. }
  788. /***********************************************************************************************
  789. * AnimClass::Middle -- Processes any middle events. *
  790. * *
  791. * This routine is called when the animation as reached its largest stage. Typically, this *
  792. * routine is used to cause scorches or craters to appear at a cosmetically pleasing *
  793. * moment. *
  794. * *
  795. * INPUT: none *
  796. * *
  797. * OUTPUT: none *
  798. * *
  799. * WARNINGS: none *
  800. * *
  801. * HISTORY: *
  802. * 06/30/1995 JLB : Created. *
  803. * 10/17/1995 JLB : Ion camera added. *
  804. *=============================================================================================*/
  805. void AnimClass::Middle(void)
  806. {
  807. assert(Anims.ID(this) == ID);
  808. assert(IsActive);
  809. CELL cell = Coord_Cell(Center_Coord());
  810. CellClass * cellptr = &Map[cell];
  811. if (Class->Type == ANIM_ATOM_BLAST) {
  812. Do_Atom_Damage(OwnerHouse, cell);
  813. }
  814. /*
  815. ** If this animation leaves scorch marks (e.g., napalm), then do so at this time.
  816. */
  817. if (Class->IsScorcher) {
  818. new SmudgeClass(Random_Pick(SMUDGE_SCORCH1, SMUDGE_SCORCH6), Center_Coord());
  819. }
  820. /*
  821. ** Some animations leave a crater when they occur. Artillery is a good example.
  822. ** Craters always remove the Tiberium where they occur.
  823. */
  824. if (Class->IsCraterForming) {
  825. /*
  826. ** Craters reduce the level of Tiberium in the cell.
  827. */
  828. cellptr->Reduce_Tiberium(6);
  829. /*
  830. ** If there already is a crater in the cell, then just expand the
  831. ** crater.
  832. */
  833. new SmudgeClass(SMUDGE_CRATER1, Center_Coord());
  834. }
  835. AnimClass * newanim;
  836. /*
  837. ** If this animation spawns side effects during its lifetime, then
  838. ** do so now. Usually, these side effects are in the form of other
  839. ** animations.
  840. */
  841. switch (Class->Type) {
  842. case ANIM_NAPALM1:
  843. case ANIM_NAPALM2:
  844. case ANIM_NAPALM3:
  845. new AnimClass(ANIM_FIRE_SMALL, Map.Closest_Free_Spot(Coord_Scatter(Center_Coord(), 0x0040), true), 0, Random_Pick(1, 2));
  846. if (Percent_Chance(50)) {
  847. new AnimClass(ANIM_FIRE_SMALL, Map.Closest_Free_Spot(Coord_Scatter(Center_Coord(), 0x00A0), true), 0, Random_Pick(1, 2));
  848. }
  849. if (Percent_Chance(50)) {
  850. new AnimClass(ANIM_FIRE_MED, Map.Closest_Free_Spot(Coord_Scatter(Center_Coord(), 0x0070), true), 0, Random_Pick(1, 2));
  851. }
  852. break;
  853. case ANIM_FIRE_MED:
  854. case ANIM_FIRE_MED2:
  855. newanim = new AnimClass(ANIM_FIRE_SMALL, Center_Coord(), 0, Random_Pick(1, 2));
  856. if (newanim != NULL && xObject != TARGET_NONE) {
  857. newanim->Attach_To(As_Object(xObject));
  858. }
  859. break;
  860. default:
  861. break;
  862. }
  863. }
  864. /***********************************************************************************************
  865. * AnimClass::Detach -- Remove animation if attached to target. *
  866. * *
  867. * This routine is called when the specified target is being removed from the game. If this *
  868. * animation happens to be attached to this object, then the animation must be remove as *
  869. * well. *
  870. * *
  871. * INPUT: target -- The target that is about to be destroyed. *
  872. * *
  873. * all -- Is the target being destroyed RIGHT NOW? If not, then it will be *
  874. * destroyed soon. In that case, the animation should continue to remain *
  875. * attached for cosmetic reasons. *
  876. * *
  877. * OUTPUT: none *
  878. * *
  879. * WARNINGS: none *
  880. * *
  881. * HISTORY: *
  882. * 06/30/1995 JLB : Created. *
  883. * 07/02/1995 JLB : Detach is a precursor to animation destruction. *
  884. *=============================================================================================*/
  885. void AnimClass::Detach(TARGET target, bool all)
  886. {
  887. assert(Anims.ID(this) == ID);
  888. assert(IsActive);
  889. if (xObject == target && all) {
  890. Map.Remove(this, In_Which_Layer());
  891. xObject = TARGET_NONE;
  892. IsToDelete = true;
  893. Mark(MARK_UP);
  894. }
  895. }
  896. /***********************************************************************************************
  897. * AnimClass::Do_Atom_Damage -- Do atom bomb damage centered around the cell specified. *
  898. * *
  899. * This routine will apply damage around the ground-zero cell specified. *
  900. * *
  901. * INPUT: ownerhouse -- The owner of this atom bomb. *
  902. * *
  903. * cell -- The ground zero location to apply the atom bomb damage. *
  904. * *
  905. * OUTPUT: none *
  906. * *
  907. * WARNINGS: none *
  908. * *
  909. * HISTORY: *
  910. * 07/06/1996 JLB : Created. *
  911. *=============================================================================================*/
  912. void AnimClass::Do_Atom_Damage(HousesType ownerhouse, CELL cell)
  913. {
  914. /*
  915. ** Find someone to blame the explosion on. This is necessary in
  916. ** order to properly enact retribution and record the kill for
  917. ** score purposes.
  918. */
  919. BuildingClass * building = NULL;
  920. TechnoClass * backup = NULL;
  921. if (ownerhouse != HOUSE_NONE) {
  922. for (int index = 0; index < Logic.Count(); index++) {
  923. ObjectClass * obj = Logic[index];
  924. if (obj != NULL && obj->Is_Techno() && obj->Owner() == ownerhouse) {
  925. backup = (TechnoClass *)obj;
  926. if (obj->What_Am_I() == RTTI_BUILDING && *((BuildingClass *)obj) == STRUCT_MSLO) {
  927. building = (BuildingClass *)obj;
  928. break;
  929. }
  930. }
  931. }
  932. if (building == NULL) building = (BuildingClass *)backup;
  933. }
  934. int radius;
  935. int rawdamage;
  936. if (Session.Type == GAME_NORMAL) {
  937. radius = 4;
  938. rawdamage = Rule.AtomDamage;
  939. WhitePalette.Set(FADE_PALETTE_SLOW, Call_Back);
  940. } else {
  941. radius = 3;
  942. rawdamage = Rule.AtomDamage/5;
  943. }
  944. Wide_Area_Damage(Cell_Coord(cell), radius * CELL_LEPTON_W, rawdamage, building, WARHEAD_FIRE);
  945. Shake_The_Screen(3);
  946. if (Session.Type == GAME_NORMAL) {
  947. GamePalette.Set(FADE_PALETTE_SLOW, Call_Back);
  948. }
  949. }