ANIM.CPP 53 KB

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