ANIM.CPP 61 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333
  1. //
  2. // Copyright 2020 Electronic Arts Inc.
  3. //
  4. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is free
  5. // software: you can redistribute it and/or modify it under the terms of
  6. // the GNU General Public License as published by the Free Software Foundation,
  7. // either version 3 of the License, or (at your option) any later version.
  8. // TiberianDawn.DLL and RedAlert.dll and corresponding source code is distributed
  9. // in the hope that it will be useful, but with permitted additional restrictions
  10. // under Section 7 of the GPL. See the GNU General Public License in LICENSE.TXT
  11. // distributed with this program. You should have received a copy of the
  12. // GNU General Public License along with permitted additional restrictions
  13. // with this program. If not, see https://github.com/electronicarts/CnC_Remastered_Collection
  14. /* $Header: F:\projects\c&c\vcs\code\anim.cpv 2.18 16 Oct 1995 16:48:48 JOE_BOSTIC $ */
  15. /***********************************************************************************************
  16. *** C O N F I D E N T I A L --- W E S T W O O D S T U D I O S ***
  17. ***********************************************************************************************
  18. * *
  19. * Project Name : Dune *
  20. * *
  21. * File Name : ANIM.CPP *
  22. * *
  23. * Programmer : Joe L. Bostic *
  24. * *
  25. * Start Date : June 3, 1991 *
  26. * *
  27. *---------------------------------------------------------------------------------------------*
  28. * Functions: *
  29. * AnimClass::AI -- This is the low level anim processor. *
  30. * AnimClass::Adjust_Coord -- Adjusts anim coordinates *
  31. * AnimClass::AnimClass -- The constructor for animation objects. *
  32. * AnimClass::As_Target -- Converts the animation into a target value. *
  33. * AnimClass::Attach_To -- Attaches animation to object specified. *
  34. * AnimClass::Sort_Above -- Sorts the animation above the target specified. *
  35. * AnimClass::Center_Coord -- Determine center of animation. *
  36. * AnimClass::Detach -- Remove animation if attached to target. *
  37. * AnimClass::Draw_It -- Draws the animation at the location specified. *
  38. * AnimClass::In_Which_Layer -- Determines what render layer the anim should be in. *
  39. * AnimClass::Init -- Performs pre-scenario initialization. *
  40. * AnimClass::Mark -- Signals to map that redrawing is necessary. *
  41. * AnimClass::Middle -- Processes any middle events. *
  42. * AnimClass::Occupy_List -- Determines the occupy list for the animation. *
  43. * AnimClass::Overlap_List -- Determines the overlap list for the animation. *
  44. * AnimClass::Render -- Draws an animation object. *
  45. * AnimClass::Sort_Y -- Returns with the sorting coordinate for the animation. *
  46. * AnimClass::Start -- Processes initial animation side effects. *
  47. * AnimClass::delete -- Returns an anim object back to the free pool. *
  48. * AnimClass::new -- Allocates an anim object from the pool. *
  49. * AnimClass::~AnimClass -- Destructor for anim objects. *
  50. * AnimClass::Validate -- validates anim pointer *
  51. * Shorten_Attached_Anims -- Reduces attached animation durations. *
  52. * - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - */
  53. #include "function.h"
  54. /*
  55. ** This contains the value of the Virtual Function Table Pointer
  56. */
  57. void * AnimClass::VTable;
  58. /***********************************************************************************************
  59. * AnimClass::Validate -- validates anim pointer *
  60. * *
  61. * INPUT: *
  62. * none. *
  63. * *
  64. * OUTPUT: *
  65. * 1 = ok, 0 = error *
  66. * *
  67. * WARNINGS: *
  68. * none. *
  69. * *
  70. * HISTORY: *
  71. * 08/09/1995 BRR : Created. *
  72. *=============================================================================================*/
  73. #ifdef CHEAT_KEYS
  74. int AnimClass::Validate(void) const
  75. {
  76. int num;
  77. num = Anims.ID(this);
  78. if (num < 0 || num >= ANIM_MAX) {
  79. Validate_Error("ANIM");
  80. return (0);
  81. }
  82. else
  83. return (1);
  84. }
  85. #else
  86. #define Validate()
  87. #endif
  88. /***********************************************************************************************
  89. * Shorten_Attached_Anims -- Reduces attached animation durations. *
  90. * *
  91. * This routine is used to reduce the amount of time any attached animations will process. *
  92. * Typical use of this is when an object is on fire and the object should now be destroyed *
  93. * but the attached animations are to run until completion before destruction can follow. *
  94. * This routine will make the animation appear to run its course, but in as short of time *
  95. * as possible. The shortening effect is achieved by reducing the number of times the *
  96. * animation will loop. *
  97. * *
  98. * INPUT: obj -- Pointer to the object that all attached animations will be processed. *
  99. * *
  100. * OUTPUT: none *
  101. * *
  102. * WARNINGS: none *
  103. * *
  104. * HISTORY: *
  105. * 12/11/1994 JLB : Created. *
  106. *=============================================================================================*/
  107. void Shorten_Attached_Anims(ObjectClass * obj)
  108. {
  109. if (obj) {
  110. for (int index = 0; index < Anims.Count(); index++) {
  111. AnimClass & anim = *Anims.Ptr(index);
  112. if (anim.Object == obj) {
  113. anim.Loops = 0;
  114. }
  115. }
  116. }
  117. }
  118. /***********************************************************************************************
  119. * AnimClass::Sort_Y -- Returns with the sorting coordinate for the animation. *
  120. * *
  121. * This routine is used by the sorting system. Animations that are located in the ground *
  122. * layer will be sorted by this the value returned from this function. *
  123. * *
  124. * INPUT: none *
  125. * *
  126. * OUTPUT: Returns with the sort coordinate to use for this animation. *
  127. * *
  128. * WARNINGS: none *
  129. * *
  130. * HISTORY: *
  131. * 10/17/1994 JLB : Created. *
  132. * 12/15/1994 JLB : Handles flat anims (infantry decay anims). *
  133. *=============================================================================================*/
  134. COORDINATE AnimClass::Sort_Y(void) const
  135. {
  136. Validate();
  137. if (Object) {
  138. return(Coord_Add(Object->Sort_Y(), 0x00010000L));
  139. }
  140. if (Target_Legal(SortTarget)) {
  141. ObjectClass * obj = As_Object(SortTarget);
  142. if (obj && obj->IsActive) {
  143. return(Coord_Add(obj->Sort_Y(), 0x00010000L));
  144. }
  145. }
  146. if (*this == ANIM_MOVE_FLASH) {
  147. return(Coord_Add(Center_Coord(), XYP_COORD(0, -24)));
  148. }
  149. if (*this == ANIM_LZ_SMOKE) {
  150. return(Coord_Add(Center_Coord(), XYP_COORD(0, 14)));
  151. }
  152. return(Coord);
  153. }
  154. /***********************************************************************************************
  155. * AnimClass::Center_Coord -- Determine center of animation. *
  156. * *
  157. * This support function will return the "center" of the animation. The actual coordinate *
  158. * of the animation may be dependant on if the the animation is attached to an object. *
  159. * In such a case, it must factor in the object's location. *
  160. * *
  161. * INPUT: none *
  162. * *
  163. * OUTPUT: Returns the coordinate of the center of the animation. The coordinate is in real *
  164. * game coordinates -- taking into consideration if the animation is attached. *
  165. * *
  166. * WARNINGS: none *
  167. * *
  168. * HISTORY: *
  169. * 09/19/1994 JLB : Created. *
  170. *=============================================================================================*/
  171. COORDINATE AnimClass::Center_Coord(void) const
  172. {
  173. Validate();
  174. if (Object) {
  175. return(Coord_Add(Coord, Object->Center_Coord()));
  176. }
  177. return(Coord);
  178. }
  179. /***********************************************************************************************
  180. * AnimClass::Render -- Draws an animation object. *
  181. * *
  182. * This is the working routine that renders the animation shape. It gets called once *
  183. * per animation per frame. It needs to be fast. *
  184. * *
  185. * INPUT: bool; Should the animation be rendered in spite of render flag? *
  186. * *
  187. * OUTPUT: bool; Was the animation rendered? *
  188. * *
  189. * WARNINGS: none *
  190. * *
  191. * HISTORY: *
  192. * 05/31/1994 JLB : Created. *
  193. *=============================================================================================*/
  194. bool AnimClass::Render(bool forced)
  195. {
  196. Validate();
  197. if (Delay) return(false);
  198. IsToDisplay = true;
  199. return(ObjectClass::Render(forced));
  200. }
  201. /***********************************************************************************************
  202. * AnimClass::Draw_It -- Draws the animation at the location specified. *
  203. * *
  204. * This routine is used to render the animation object at the location specified. This is *
  205. * how the map imagery gets updated. *
  206. * *
  207. * INPUT: x,y -- The pixel coordinates to draw the animation at. *
  208. * *
  209. * window -- The to base the draw coordinates upon. *
  210. * *
  211. * OUTPUT: none *
  212. * *
  213. * WARNINGS: none *
  214. * *
  215. * HISTORY: *
  216. * 09/24/1994 JLB : Created. *
  217. * 05/19/1995 JLB : Added white translucent effect. *
  218. *=============================================================================================*/
  219. //#pragma off (unreferenced)
  220. void AnimClass::Draw_It(int x, int y, WindowNumberType window)
  221. {
  222. Validate();
  223. bool render_legacy = !IsInvisible && (Class->VirtualAnim == ANIM_NONE || window != WINDOW_VIRTUAL);
  224. bool render_virtual = VirtualAnim != NULL && window == WINDOW_VIRTUAL;
  225. if (render_legacy) {
  226. void const * shapefile = Class->Get_Image_Data();
  227. if (shapefile) {
  228. void const * transtable = NULL;
  229. int shapenum = Class->Start + Fetch_Stage();
  230. void const * remap = NULL;
  231. ShapeFlags_Type flags = SHAPE_CENTER|SHAPE_WIN_REL;
  232. int width = 0;
  233. int height = 0;
  234. /*
  235. ** Some animations require special fixups.
  236. */
  237. switch (Class->Type) {
  238. case ANIM_ION_CANNON:
  239. if (window != WINDOW_VIRTUAL) {
  240. y -= Get_Build_Frame_Height(shapefile) >> 1;
  241. } else {
  242. flags = flags | SHAPE_BOTTOM;
  243. }
  244. y += 12;
  245. break;
  246. case ANIM_RAPT_DIE:
  247. case ANIM_STEG_DIE:
  248. case ANIM_TREX_DIE:
  249. case ANIM_TRIC_DIE:
  250. case ANIM_ATOM_BLAST:
  251. transtable = Map.UnitShadow;
  252. break;
  253. case ANIM_FLAG:
  254. x += (ICON_PIXEL_W / 2) - 2;
  255. y += (3 * ICON_PIXEL_H / 4) - Get_Build_Frame_Height(shapefile);
  256. transtable = Map.UnitShadow;
  257. break;
  258. case ANIM_BEACON_VIRTUAL:
  259. width = 29;
  260. height = 39;
  261. flags = flags | SHAPE_BOTTOM | SHAPE_COMPACT;
  262. break;
  263. }
  264. /*
  265. ** If the translucent table hasn't been determined yet, then check to see if it
  266. ** should use the white or normal translucent tables.
  267. */
  268. if (!transtable && Class->IsWhiteTrans) transtable = Map.WhiteTranslucentTable;
  269. if (!transtable && Class->IsTranslucent) transtable = Map.TranslucentTable;
  270. /*
  271. ** Set the shape flags to properly take into account any fading or ghosting
  272. ** table necessary.
  273. */
  274. if (IsAlternate) {
  275. flags = flags | SHAPE_FADING;
  276. if (OwnerHouse != HOUSE_NONE) {
  277. remap = HouseClass::As_Pointer(OwnerHouse)->Remap_Table(false, false);
  278. } else {
  279. remap = Map.RemapTables[HOUSE_GOOD][0];
  280. }
  281. }
  282. if (transtable) flags = flags | SHAPE_GHOST;
  283. /*
  284. ** Draw the animation shape, but ignore legacy if beyond normal stage count.
  285. */
  286. if ((window == WINDOW_VIRTUAL) || (Fetch_Stage() < Class->Stages)) {
  287. CC_Draw_Shape(this, shapefile, shapenum, x, y, window, flags, remap, transtable, Class->VirtualScale, width, height);
  288. }
  289. }
  290. }
  291. if (render_virtual) {
  292. VirtualAnim->Make_Visible();
  293. VirtualAnim->Draw_It(x, y, window);
  294. VirtualAnim->Make_Invisible();
  295. }
  296. }
  297. /***********************************************************************************************
  298. * AnimClass::Mark -- Signals to map that redrawing is necessary. *
  299. * *
  300. * This routine is used by the animation logic system to inform the map that the cells *
  301. * under the animation must be rerendered. *
  302. * *
  303. * INPUT: *
  304. * *
  305. * OUTPUT: none *
  306. * *
  307. * WARNINGS: none *
  308. * *
  309. * HISTORY: *
  310. * 05/31/1994 JLB : Created. *
  311. *=============================================================================================*/
  312. bool AnimClass::Mark(MarkType mark)
  313. {
  314. Validate();
  315. if (ObjectClass::Mark(mark)) {
  316. Map.Refresh_Cells(Coord_Cell(Center_Coord()), Overlap_List());
  317. // ObjectClass::Mark(mark);
  318. return(true);
  319. }
  320. return(false);
  321. }
  322. /***********************************************************************************************
  323. * AnimClass::Overlap_List -- Determines the overlap list for the animation. *
  324. * *
  325. * Use this routine to fetch the overlap list for the animation. This overlap list is the *
  326. * cells that this animation spills over. *
  327. * *
  328. * INPUT: none *
  329. * *
  330. * OUTPUT: Returns a pointer to the overlap list for this particular instance of the *
  331. * animation. *
  332. * *
  333. * WARNINGS: none *
  334. * *
  335. * HISTORY: *
  336. * 03/19/1995 JLB : Created. *
  337. *=============================================================================================*/
  338. short const * AnimClass::Overlap_List(void) const
  339. {
  340. Validate();
  341. static short const OverlapN[] = {0, -MAP_CELL_W, -(MAP_CELL_W+1), -(MAP_CELL_W-1), -(2*MAP_CELL_W), -(2*MAP_CELL_W-1), -(2*MAP_CELL_W+1), REFRESH_EOL};
  342. static short const OverlapNW[] = {0, -1, -MAP_CELL_W, -(MAP_CELL_W+1), -(MAP_CELL_W+2), -(MAP_CELL_W*2+2), -(MAP_CELL_W*2+1), REFRESH_EOL};
  343. static short const OverlapW[] = {0, -1, -2, -(MAP_CELL_W+1), -(MAP_CELL_W+2), REFRESH_EOL};
  344. static short const OverlapSW[] = {0, -1, MAP_CELL_W, (MAP_CELL_W-1), (MAP_CELL_W-2), (MAP_CELL_W*2-2), (MAP_CELL_W*2-1), REFRESH_EOL};
  345. static short const OverlapS[] = {0, MAP_CELL_W-1, MAP_CELL_W, MAP_CELL_W+1, 2*MAP_CELL_W+1, 2*MAP_CELL_W, 2*MAP_CELL_W-1, REFRESH_EOL};
  346. static short const OverlapSE[] = {0, 1, MAP_CELL_W, (MAP_CELL_W+1), (MAP_CELL_W+2), (MAP_CELL_W*2+2), (MAP_CELL_W*2+1), REFRESH_EOL};
  347. static short const OverlapE[] = {0, 1, 2, -(MAP_CELL_W-1), -(MAP_CELL_W-2), REFRESH_EOL};
  348. static short const OverlapNE[] = {0, 1, -MAP_CELL_W, -(MAP_CELL_W-1), -(MAP_CELL_W-2), -(MAP_CELL_W*2-2), -(MAP_CELL_W*2-1), REFRESH_EOL};
  349. static short const OverlapIon[] = {
  350. (-MAP_CELL_W * 7) - 1, (-MAP_CELL_W * 7), (-MAP_CELL_W * 7) + 1,
  351. (-MAP_CELL_W * 6) - 1, (-MAP_CELL_W * 6), (-MAP_CELL_W * 6) + 1,
  352. (-MAP_CELL_W * 5) - 1, (-MAP_CELL_W * 5), (-MAP_CELL_W * 5) + 1,
  353. (-MAP_CELL_W * 4) - 1, (-MAP_CELL_W * 4), (-MAP_CELL_W * 4) + 1,
  354. (-MAP_CELL_W * 3) - 1, (-MAP_CELL_W * 3), (-MAP_CELL_W * 3) + 1,
  355. (-MAP_CELL_W * 2) - 1, (-MAP_CELL_W * 2), (-MAP_CELL_W * 2) + 1,
  356. (-MAP_CELL_W * 1) - 1, (-MAP_CELL_W * 1), (-MAP_CELL_W * 1) + 1,
  357. (-MAP_CELL_W * 0) - 1, (-MAP_CELL_W * 0), (-MAP_CELL_W * 0) + 1,
  358. REFRESH_EOL
  359. };
  360. static short const OverlapAtom[] = {
  361. (-MAP_CELL_W * 2) - 1, (-MAP_CELL_W * 2), (-MAP_CELL_W * 2) + 1,
  362. (-MAP_CELL_W * 1) - 1, (-MAP_CELL_W * 1), (-MAP_CELL_W * 1) + 1,
  363. (-MAP_CELL_W * 0) - 1, (-MAP_CELL_W * 0), (-MAP_CELL_W * 0) + 1,
  364. ( MAP_CELL_W * 1) - 1, ( MAP_CELL_W * 1), ( MAP_CELL_W * 1) + 1,
  365. ( MAP_CELL_W * 2) - 1, ( MAP_CELL_W * 2), ( MAP_CELL_W * 2) + 1,
  366. REFRESH_EOL
  367. };
  368. static short const OverlapFlag[] = { 0, 1, -MAP_CELL_W, -(MAP_CELL_W-1), MAP_CELL_W, MAP_CELL_W+1, REFRESH_EOL };
  369. switch (Class->Type) {
  370. case ANIM_CHEM_N:
  371. case ANIM_FLAME_N:
  372. return(OverlapN);
  373. case ANIM_CHEM_NW:
  374. case ANIM_FLAME_NW:
  375. return(OverlapNW);
  376. case ANIM_CHEM_W:
  377. case ANIM_FLAME_W:
  378. return(OverlapW);
  379. case ANIM_CHEM_SW:
  380. case ANIM_FLAME_SW:
  381. return(OverlapSW);
  382. case ANIM_CHEM_S:
  383. case ANIM_FLAME_S:
  384. return(OverlapS);
  385. case ANIM_CHEM_SE:
  386. case ANIM_FLAME_SE:
  387. return(OverlapSE);
  388. case ANIM_CHEM_E:
  389. case ANIM_FLAME_E:
  390. return(OverlapE);
  391. case ANIM_CHEM_NE:
  392. case ANIM_FLAME_NE:
  393. return(OverlapNE);
  394. case ANIM_ION_CANNON:
  395. return(OverlapIon);
  396. case ANIM_ATOM_BLAST:
  397. return(OverlapAtom);
  398. case ANIM_FLAG:
  399. return(OverlapFlag);
  400. default:
  401. break;
  402. }
  403. return(Coord_Spillage_List(Center_Coord(), Class->Size));
  404. }
  405. /***********************************************************************************************
  406. * AnimClass::Occupy_List -- Determines the occupy list for the animation. *
  407. * *
  408. * Animations always occupy only the cell that their center is located over. As such, this *
  409. * routine always returns a simple (center cell) occupation list. *
  410. * *
  411. * INPUT: none *
  412. * *
  413. * OUTPUT: Returns with the occupation list for the animation. *
  414. * *
  415. * WARNINGS: none *
  416. * *
  417. * HISTORY: *
  418. * 03/19/1995 JLB : Created. *
  419. *=============================================================================================*/
  420. short const * AnimClass::Occupy_List(void) const
  421. {
  422. Validate();
  423. static short _simple[] = {REFRESH_EOL};
  424. return(_simple);
  425. }
  426. /***********************************************************************************************
  427. * AnimClass::Init -- Performs pre-scenario initialization. *
  428. * *
  429. * This routine is used to initialize the animation system prior to a scenario being loaded *
  430. * or reloaded. It effectively removes all animations from the system. *
  431. * *
  432. * INPUT: none *
  433. * *
  434. * OUTPUT: none *
  435. * *
  436. * WARNINGS: none *
  437. * *
  438. * HISTORY: *
  439. * 05/31/1994 JLB : Created. *
  440. *=============================================================================================*/
  441. void AnimClass::Init(void)
  442. {
  443. AnimClass *ptr;
  444. Anims.Free_All();
  445. ptr = new AnimClass();
  446. VTable = ((void **)(((char *)ptr) + sizeof(AbstractClass) - 4))[0];
  447. delete ptr;
  448. }
  449. /***********************************************************************************************
  450. * AnimClass::new -- Allocates an anim object from the pool. *
  451. * *
  452. * This routine is used to allocate a free anim class object from the preallocated pool *
  453. * in the near heap. If there are no free animation objects, then null is returned. *
  454. * *
  455. * INPUT: none *
  456. * *
  457. * OUTPUT: Returns with a pointer to a free anim object. *
  458. * *
  459. * WARNINGS: none *
  460. * *
  461. * HISTORY: *
  462. * 05/31/1994 JLB : Created. *
  463. *=============================================================================================*/
  464. void *AnimClass::operator new(size_t)
  465. {
  466. void * ptr = Anims.Allocate();
  467. if (ptr) {
  468. ((AnimClass *)ptr)->Set_Active();
  469. }
  470. return(ptr);
  471. }
  472. /***********************************************************************************************
  473. * AnimClass::delete -- Returns an anim object back to the free pool. *
  474. * *
  475. * This routine is used to return an anim object back to the pool of free anim objects. *
  476. * Anim objects so returned are available to be reallocated for the next animation. *
  477. * *
  478. * INPUT: ptr -- Pointer to the anim object to return to the pool. *
  479. * *
  480. * OUTPUT: none *
  481. * *
  482. * WARNINGS: none *
  483. * *
  484. * HISTORY: *
  485. * 05/31/1994 JLB : Created. *
  486. *=============================================================================================*/
  487. void AnimClass::operator delete(void *ptr)
  488. {
  489. if (ptr) {
  490. ((AnimClass *)ptr)->IsActive = false;
  491. }
  492. Anims.Free((AnimClass *)ptr);
  493. //Map.Validate();
  494. }
  495. /***********************************************************************************************
  496. * AnimClass::AnimClass -- The constructor for animation objects. *
  497. * *
  498. * This routine is used as the constructor of animation objects. It initializes and adds *
  499. * the animation object to the display and logic systems. *
  500. * *
  501. * INPUT: animnum -- The animation number to start. *
  502. * *
  503. * coord -- The location of the animation. *
  504. * *
  505. * timedelay-- The delay before the animation starts. *
  506. * *
  507. * loop -- The number of times to loop this animation. *
  508. * *
  509. * OUTPUT: none *
  510. * *
  511. * WARNINGS: none *
  512. * *
  513. * HISTORY: *
  514. * 05/31/1994 JLB : Created. *
  515. * 08/03/1994 JLB : Added a delayed affect parameter. *
  516. *=============================================================================================*/
  517. AnimClass::AnimClass(AnimType animnum, COORDINATE coord, unsigned char timedelay, char loop, bool alt) :
  518. Class(&AnimTypeClass::As_Reference(animnum))
  519. {
  520. Object = 0;
  521. SortTarget = TARGET_NONE;
  522. OwnerHouse = HOUSE_NONE;
  523. KillTime = 0ULL;
  524. if (Class->Stages == -1) {
  525. ((int&)Class->Stages) = Get_Build_Frame_Count(Class->Get_Image_Data());
  526. }
  527. if (Class->LoopEnd == -1) {
  528. ((int&)Class->LoopEnd) = Class->Stages;
  529. }
  530. if (Class->IsNormalized) {
  531. Set_Rate(Options.Normalize_Delay(Class->Delay));
  532. } else {
  533. Set_Rate(Class->Delay);
  534. }
  535. Set_Stage(0);
  536. Accum = 0;
  537. coord = Adjust_Coord(coord);
  538. Unlimbo(coord);
  539. VisibleFlags = static_cast<unsigned int>(-1);
  540. /*
  541. ** Drop zone smoke always reveals the map around itself.
  542. */
  543. if (*this == ANIM_LZ_SMOKE) {
  544. // Added PlayerPtr here as Sight_From now needs to know who to perform the action for. This should be OK as it's not used in MP. ST - 3/28/2019 2:43PM
  545. Map.Sight_From(PlayerPtr, Coord_Cell(coord), 4, false);
  546. }
  547. /*
  548. ** Determine the time before the first animation process. For time delayed
  549. ** animations, this is the value passed as a parameter.
  550. */
  551. Delay = timedelay;
  552. if (Class->Loops >= 0) {
  553. Loops = (char)(MAX(loop, (char)1) * Class->Loops);
  554. Loops = (char)MAX(Loops, (char)1);
  555. } else {
  556. Loops = Class->Loops;
  557. }
  558. IsToDelete = false;
  559. IsBrandNew = true;
  560. IsAlternate = alt;
  561. IsInvisible = false;
  562. /*
  563. ** If the animation starts immediately, then play the associated sound effect now.
  564. */
  565. if (!Delay) {
  566. Start();
  567. }
  568. /*
  569. ** Check for a virtual animation
  570. */
  571. if (Class->VirtualAnim != ANIM_NONE) {
  572. VirtualAnim = new AnimClass(Class->VirtualAnim, Coord, timedelay, loop, alt);
  573. if (VirtualAnim != NULL) {
  574. VirtualAnim->Make_Invisible();
  575. }
  576. } else {
  577. VirtualAnim = NULL;
  578. }
  579. }
  580. /***********************************************************************************************
  581. * AnimClass::~AnimClass -- Destructor for anim objects. *
  582. * *
  583. * This destructor handles removing the animation object from the system. It might require *
  584. * informing any object this animation is attached to that it is no longer attached. *
  585. * *
  586. * INPUT: none *
  587. * *
  588. * OUTPUT: none *
  589. * *
  590. * WARNINGS: none *
  591. * *
  592. * HISTORY: *
  593. * 11/29/1994 JLB : Created. *
  594. *=============================================================================================*/
  595. AnimClass::~AnimClass(void)
  596. {
  597. Validate();
  598. if (GameActive) {
  599. /*
  600. ** If this anim is attached to another object
  601. ** then check to see if this is the last anim attached to it. If this
  602. ** is the case, then inform the object that it is no longer attached to
  603. ** an animation.
  604. */
  605. if (Object) {
  606. /*
  607. ** Remove the object from the appropriate display list.
  608. */
  609. Map.Remove(this, In_Which_Layer());
  610. /*
  611. ** Scan for any other animations that are attached to the object that
  612. ** this animation is attached to. If there are no others, then inform the
  613. ** attached object of this fact.
  614. */
  615. int index;
  616. for (index = 0; index < Anims.Count(); index++) {
  617. if (Anims.Ptr(index) != this && Anims.Ptr(index)->Object == Object) break;
  618. }
  619. /*
  620. ** Tell the object that it is no longer being damaged.
  621. */
  622. if (index == Anims.Count()) {
  623. Object->Fire_Out();
  624. if (Object->In_Which_Layer() == LAYER_GROUND) Object->Mark(MARK_OVERLAP_UP);
  625. Object->IsAnimAttached = false;
  626. if (Object->In_Which_Layer() == LAYER_GROUND) Object->Mark(MARK_OVERLAP_DOWN);
  627. }
  628. Coord = Coord_Add(Object->Center_Coord(), Coord);
  629. Object = NULL;
  630. }
  631. Limbo();
  632. }
  633. }
  634. /***********************************************************************************************
  635. * AnimClass::AI -- This is the low level anim processor. *
  636. * *
  637. * This routine is called once per frame per animation. It handles transition between *
  638. * animation frames and marks the map for redraw as necessary. *
  639. * *
  640. * INPUT: none *
  641. * *
  642. * OUTPUT: none *
  643. * *
  644. * WARNINGS: Speed is of upmost importance. *
  645. * *
  646. * HISTORY: *
  647. * 05/31/1994 JLB : Created. *
  648. *=============================================================================================*/
  649. void AnimClass::AI(void)
  650. {
  651. Validate();
  652. /*
  653. ** For ground level based animations (ones that can run slowly as well as
  654. ** occur behind other ground objects) always cause the cell to be redrawn.
  655. */
  656. if (!Delay && Class->IsGroundLayer) {
  657. Map.Refresh_Cells(Coord_Cell(Center_Coord()), Overlap_List());
  658. }
  659. /*
  660. ** Special case check to make sure that building on top of a smoke marker
  661. ** causes the smoke marker to vanish.
  662. */
  663. if (Class->Type == ANIM_LZ_SMOKE && Map[Coord_Cell(Center_Coord())].Cell_Building()) {
  664. IsToDelete = true;
  665. }
  666. /*
  667. ** Check the kill time.
  668. */
  669. if (KillTime > 0ULL) {
  670. FILETIME ft;
  671. GetSystemTimeAsFileTime(&ft);
  672. unsigned long long now = (unsigned long long)ft.dwLowDateTime + ((unsigned long long)ft.dwHighDateTime << 32ULL);
  673. if (now >= KillTime) {
  674. IsToDelete = true;
  675. }
  676. }
  677. /*
  678. ** Delete this animation and bail early if the animation is flagged to be deleted
  679. ** immediately.
  680. */
  681. if (IsToDelete) {
  682. Delete_This();
  683. return;
  684. }
  685. /*
  686. ** If this is a brand new animation, then don't process it the first logic pass
  687. ** since it might end up skipping the first animation frame before it has had a
  688. ** chance to draw it.
  689. */
  690. if (IsBrandNew) {
  691. IsBrandNew = false;
  692. return;
  693. }
  694. /*
  695. ** Lazy-initialize animation data (for loaded saves).
  696. */
  697. if (Class->Stages == -1) {
  698. ((int&)Class->Stages) = Get_Build_Frame_Count(Class->Get_Image_Data());
  699. }
  700. if (Class->LoopEnd == -1) {
  701. ((int&)Class->LoopEnd) = Class->Stages;
  702. }
  703. if (Delay) {
  704. Delay--;
  705. if (!Delay) {
  706. Start();
  707. }
  708. } else {
  709. /*
  710. ** This is necessary because there is no recording of animations on the map
  711. ** and thus the animation cannot be intelligently flagged for redraw. Most
  712. ** animations move fast enough that they would need to be redrawn every
  713. ** game frame anyway so this isn't TOO bad.
  714. */
  715. Mark(MARK_CHANGE);
  716. if (StageClass::Graphic_Logic()) {
  717. int stage = Fetch_Stage();
  718. /*
  719. ** If this animation is attached to another object and it is a
  720. ** damaging kind of animation, then do the damage to the other
  721. ** object.
  722. */
  723. if (Object && Class->Damage && stage < Class->Stages) {
  724. unsigned int accum = Accum;
  725. accum += Class->Damage;
  726. if (accum > 255) {
  727. /*
  728. ** Administer the damage. If the object was destroyed by this anim,
  729. ** then the attached damaging anim is also destroyed.
  730. */
  731. int damage = accum >> 8;
  732. if (Object->Take_Damage(damage, 0, WARHEAD_FIRE) == RESULT_DESTROYED) {
  733. //Object = 0;
  734. if (VirtualAnim != NULL) {
  735. VirtualAnim->Delete_This();
  736. }
  737. Delete_This();
  738. return;
  739. }
  740. }
  741. Accum = (unsigned char)(accum & 0x00FF);
  742. }
  743. /*
  744. ** During the biggest stage (covers the most ground), perform any ground altering
  745. ** action required. This masks craters and scorch marks, so that they appear
  746. ** naturally rather than "popping" into existance while in plain sight.
  747. */
  748. if (Class->Start+stage == Class->Biggest) {
  749. Middle();
  750. }
  751. /*
  752. ** Check to see if the last frame has been displayed. If so, then the
  753. ** animation either ends or loops.
  754. */
  755. if ((Loops <= 1 && stage >= Class->Stages) || (Loops > 1 && stage >= Class->LoopEnd-Class->Start)) {
  756. /*
  757. ** Determine if this animation should loop another time. If so, then start the loop
  758. ** but if not, then proceed into the animation termination handler.
  759. */
  760. if (Loops > 0) Loops--;
  761. if (Loops != 0) {
  762. Set_Stage(Class->LoopStart);
  763. } else {
  764. if (Class->VirtualAnim != ANIM_NONE) {
  765. Make_Invisible();
  766. if (VirtualAnim == NULL) {
  767. if (Class->ChainTo != ANIM_NONE) {
  768. Chain();
  769. }
  770. else {
  771. Delete_This();
  772. }
  773. }
  774. }
  775. else {
  776. if ((Class->VirtualStages < 0) || (stage >= Class->VirtualStages)) {
  777. if (Class->ChainTo != ANIM_NONE) {
  778. Chain();
  779. }
  780. else {
  781. Delete_This();
  782. }
  783. }
  784. }
  785. }
  786. }
  787. }
  788. }
  789. }
  790. /***********************************************************************************************
  791. * AnimClass::Attach_To -- Attaches animation to object specified. *
  792. * *
  793. * An animation can be "attached" to an object. In such cases, the animation is rendered *
  794. * as an offset from the center of the object it is attached to. This allows affects such *
  795. * as fire or smoke to be consistently placed on the vehicle it is associated with. *
  796. * *
  797. * INPUT: obj -- Pointer to the object to attach the animation to. *
  798. * *
  799. * OUTPUT: none *
  800. * *
  801. * WARNINGS: none *
  802. * *
  803. * HISTORY: *
  804. * 09/19/1994 JLB : Created. *
  805. *=============================================================================================*/
  806. void AnimClass::Attach_To(ObjectClass * obj)
  807. {
  808. Validate();
  809. if (!obj) return;
  810. if (obj->In_Which_Layer() == LAYER_GROUND) obj->Mark(MARK_OVERLAP_UP);
  811. obj->IsAnimAttached = true;
  812. if (obj->In_Which_Layer() == LAYER_GROUND) obj->Mark(MARK_OVERLAP_DOWN);
  813. Map.Remove(this, In_Which_Layer());
  814. Object = obj;
  815. Map.Submit(this, In_Which_Layer());
  816. Coord = Coord_Sub(Coord, obj->Center_Coord());
  817. }
  818. /***********************************************************************************************
  819. * AnimClass::Sort_Above -- Sorts the animation right above the specified target. *
  820. * *
  821. * Allows an animation to always be sorted above a particular target. Typically used *
  822. * for explosions and other effects that look weird beneath those objects. *
  823. * *
  824. * INPUT: target -- Target to sort above. *
  825. * *
  826. * OUTPUT: none *
  827. * *
  828. * WARNINGS: none *
  829. * *
  830. * HISTORY: *
  831. * 08/14/2019 SKY : Created. *
  832. *=============================================================================================*/
  833. void AnimClass::Sort_Above(TARGET target)
  834. {
  835. SortTarget = target;
  836. }
  837. /***********************************************************************************************
  838. * AnimClass::In_Which_Layer -- Determines what render layer the anim should be in. *
  839. * *
  840. * Use this routine to find out which display layer (ground or air) that the animation *
  841. * should be in. This information is used to place the animation into the correct display *
  842. * list. *
  843. * *
  844. * INPUT: none *
  845. * *
  846. * OUTPUT: Returns with the layer that the animation should exist in. *
  847. * *
  848. * WARNINGS: none *
  849. * *
  850. * HISTORY: *
  851. * 12/25/1994 JLB : Created. *
  852. *=============================================================================================*/
  853. LayerType AnimClass::In_Which_Layer(void) const
  854. {
  855. Validate();
  856. if (Object || Class->IsGroundLayer) {
  857. return(LAYER_GROUND);
  858. }
  859. return(LAYER_AIR);
  860. }
  861. /***********************************************************************************************
  862. * AnimClass::Start -- Processes initial animation side effects. *
  863. * *
  864. * This routine is called when the animation first starts. Sometimes there are side effects *
  865. * associated with this animation that must occur immediately. Typically, this is the *
  866. * sound effect assigned to this animation. If this animation is supposed to attach itself *
  867. * to any object at its location, then do so at this time as well. *
  868. * *
  869. * INPUT: none *
  870. * *
  871. * OUTPUT: none *
  872. * *
  873. * WARNINGS: none *
  874. * *
  875. * HISTORY: *
  876. * 06/30/1995 JLB : Created. *
  877. *=============================================================================================*/
  878. void AnimClass::Start(void)
  879. {
  880. Validate();
  881. CELL cell = Coord_Cell(Coord);
  882. Mark();
  883. /*
  884. ** Play the sound effect for this animation.
  885. */
  886. Sound_Effect(Class->Sound, Coord);
  887. /*
  888. ** If the stage where collateral effects occur is the first stage of the animation, then
  889. ** perform this action now. Subsiquent checks against this stage value starts with the
  890. ** second frame of the animation.
  891. */
  892. if (!Class->Biggest) {
  893. Middle();
  894. }
  895. /*
  896. ** If this is the kind of animation that sticks to whatever object is in the same
  897. ** location, then attach the animation to the object. If the animation is already
  898. ** attached, then do nothing.
  899. */
  900. if (!Object && Class->IsSticky && Map.In_Radar(cell)) {
  901. UnitClass * unit = Map[cell].Cell_Unit();
  902. if (unit && *unit == UNIT_GUNBOAT) {
  903. Attach_To(unit);
  904. }
  905. }
  906. }
  907. /***********************************************************************************************
  908. * AnimClass::Middle -- Processes any middle events. *
  909. * *
  910. * This routine is called when the animation as reached its largest stage. Typically, this *
  911. * routine is used to cause scorches or craters to appear at a cosmetically pleasing *
  912. * moment. *
  913. * *
  914. * INPUT: none *
  915. * *
  916. * OUTPUT: none *
  917. * *
  918. * WARNINGS: none *
  919. * *
  920. * HISTORY: *
  921. * 06/30/1995 JLB : Created. *
  922. *=============================================================================================*/
  923. void AnimClass::Middle(void)
  924. {
  925. Validate();
  926. CELL cell = Coord_Cell(Center_Coord());
  927. CellClass * cellptr = &Map[cell];
  928. if (Class->Type == ANIM_ATOM_BLAST) {
  929. /*
  930. ** Find someone to blame the explosion on. This is necessary in
  931. ** order to properly enact retribution and record the kill for
  932. ** score purposes.
  933. */
  934. BuildingClass * building = NULL;
  935. TechnoClass * backup = NULL;
  936. if (OwnerHouse != HOUSE_NONE) {
  937. for (int index = 0; index < Logic.Count(); index++) {
  938. ObjectClass * obj = Logic[index];
  939. if (obj && obj->Is_Techno() && obj->Owner() == OwnerHouse) {
  940. backup = (TechnoClass *)obj;
  941. if (obj->What_Am_I() == RTTI_BUILDING && *((BuildingClass *)obj) == STRUCT_TEMPLE) {
  942. building = (BuildingClass *)obj;
  943. break;
  944. }
  945. }
  946. }
  947. if (!building) building = (BuildingClass *)backup;
  948. }
  949. int radius = 3;
  950. int rawdamage = 200;
  951. if (GameToPlay == GAME_NORMAL) {
  952. radius = 4;
  953. rawdamage = 1000;
  954. Fade_Palette_To(WhitePalette, 30, NULL);
  955. }
  956. for (int x = -radius; x <= radius; x++) {
  957. for (int y = -radius; y <= radius; y++) {
  958. int xpos = Cell_X(cell) + x;
  959. int ypos = Cell_Y(cell) + y;
  960. /*
  961. ** If the potential damage cell is outside of the map bounds,
  962. ** then don't process it. This unusual check method ensures that
  963. ** damage won't wrap from one side of the map to the other.
  964. */
  965. if ((unsigned)xpos > MAP_CELL_W) {
  966. continue;
  967. }
  968. if ((unsigned)ypos > MAP_CELL_H) {
  969. continue;
  970. }
  971. CELL tcell = XY_Cell(xpos, ypos);
  972. if (!Map.In_Radar(tcell)) continue;
  973. int damage = rawdamage / ((ABS(radius)/2)+1);
  974. Explosion_Damage(Cell_Coord(tcell), damage, building, WARHEAD_FIRE);
  975. new SmudgeClass(Random_Pick(SMUDGE_SCORCH1, SMUDGE_SCORCH6), Cell_Coord(tcell));
  976. }
  977. }
  978. Shake_The_Screen(3);
  979. if (GameToPlay == GAME_NORMAL) {
  980. Fade_Palette_To(GamePalette, 15, NULL);
  981. }
  982. }
  983. /*
  984. ** If this animation leaves scorch marks (e.g., napalm), then do so at this time.
  985. */
  986. if (Class->IsScorcher) {
  987. new SmudgeClass(Random_Pick(SMUDGE_SCORCH1, SMUDGE_SCORCH6), Center_Coord());
  988. }
  989. /*
  990. ** Some animations leave a crater when they occur. Artillery is a good example.
  991. ** Craters always remove the Tiberium where they occur.
  992. */
  993. if (Class->IsCraterForming) {
  994. /*
  995. ** Craters reduce the level of Tiberium in the cell.
  996. */
  997. cellptr->Reduce_Tiberium(6);
  998. /*
  999. ** If there already is a crater in the cell, then just expand the
  1000. ** crater.
  1001. */
  1002. new SmudgeClass(SMUDGE_CRATER1, Center_Coord());
  1003. }
  1004. /*
  1005. ** Flame throwers leave scorch marks in unusual positions. In addition, they leave fire
  1006. ** shards in unusual positions as well.
  1007. */
  1008. if (Class->IsFlameThrower) {
  1009. COORDINATE c2 = Coord_Move(Center_Coord(), (DirType)((Class->Type - ANIM_FLAME_N)<<5), 0x00E0);
  1010. CELL cell = Coord_Cell(c2);
  1011. COORDINATE c3 = Map.Closest_Free_Spot(Coord_Move(Center_Coord(), (DirType)((Class->Type - ANIM_FLAME_N)<<5), 0x0140), true);
  1012. c2 = Map.Closest_Free_Spot(c2, true);
  1013. if (c3 && (Random_Pick(0, 1) == 1)) {
  1014. if (!Map[Coord_Cell(c3)].Cell_Terrain()) {
  1015. new AnimClass(ANIM_FIRE_SMALL, c3, 0, 2);
  1016. }
  1017. }
  1018. if (c2 && (Random_Pick(0, 1) == 1)) {
  1019. if (!Map[Coord_Cell(c2)].Cell_Terrain()) {
  1020. new AnimClass(ANIM_FIRE_SMALL, c2, 0, 2);
  1021. }
  1022. }
  1023. new SmudgeClass(SMUDGE_SCORCH1, c2);
  1024. if (c3 && (Random_Pick(0, 1) == 1)) {
  1025. if (!Map[Coord_Cell(c3)].Cell_Terrain()) {
  1026. new AnimClass(ANIM_SMOKE_M, c3);
  1027. }
  1028. }
  1029. }
  1030. AnimClass * newanim;
  1031. /*
  1032. ** If this animation spawns side effects during its lifetime, then
  1033. ** do so now.
  1034. */
  1035. switch (Class->Type) {
  1036. case ANIM_ION_CANNON: {
  1037. BuildingClass * building = NULL;
  1038. TechnoClass * backup = NULL;
  1039. if (OwnerHouse != HOUSE_NONE) {
  1040. for (int index = 0; index < Logic.Count(); index++) {
  1041. ObjectClass * obj = Logic[index];
  1042. if (obj && obj->Is_Techno() && obj->Owner() == OwnerHouse && !obj->IsInLimbo) {
  1043. backup = (TechnoClass *)obj;
  1044. if (obj->What_Am_I() == RTTI_BUILDING && *((BuildingClass *)obj) == STRUCT_EYE) {
  1045. building = (BuildingClass *)obj;
  1046. break;
  1047. }
  1048. }
  1049. }
  1050. if (!building) building = (BuildingClass *)backup;
  1051. }
  1052. Explosion_Damage(Center_Coord(), 600, building, WARHEAD_PB);
  1053. }
  1054. break;
  1055. case ANIM_NAPALM1:
  1056. case ANIM_NAPALM2:
  1057. case ANIM_NAPALM3:
  1058. new AnimClass(ANIM_FIRE_SMALL, Map.Closest_Free_Spot(Coord_Scatter(Center_Coord(), 0x0040), true), 0, ((Random_Pick(0, 1) == 1) ? 1 : 2));
  1059. if (Random_Pick(0, 1) == 1) {
  1060. new AnimClass(ANIM_FIRE_SMALL, Map.Closest_Free_Spot(Coord_Scatter(Center_Coord(), 0x00A0), true), 0, ((Random_Pick(0, 1) == 1) ? 1 : 2));
  1061. }
  1062. if (Random_Pick(0, 1) == 1) {
  1063. new AnimClass(ANIM_FIRE_MED, Map.Closest_Free_Spot(Coord_Scatter(Center_Coord(), 0x0070), true), 0, ((Random_Pick(0, 1) == 1) ? 1 : 2));
  1064. }
  1065. break;
  1066. case ANIM_FIRE_MED:
  1067. case ANIM_FIRE_MED2:
  1068. newanim = new AnimClass(ANIM_FIRE_SMALL, Center_Coord(), 0, ((Random_Pick(0, 1) == 1) ? 1 : 2));
  1069. if (newanim && Object) {
  1070. newanim->Attach_To(Object);
  1071. }
  1072. break;
  1073. default:
  1074. break;
  1075. }
  1076. }
  1077. void AnimClass::Chain(void)
  1078. {
  1079. /*
  1080. ** The animation should end now, but first check to see if
  1081. ** it needs to chain into another animation. If so, then the
  1082. ** animation isn't technically over. It metamorphoses into the
  1083. ** new form.
  1084. */
  1085. if (Class->ChainTo != ANIM_NONE) {
  1086. ((AnimTypeClass const *&)Class) = &AnimTypeClass::As_Reference(Class->ChainTo);
  1087. if (Class->IsNormalized) {
  1088. Set_Rate(Options.Normalize_Delay(Class->Delay));
  1089. } else {
  1090. Set_Rate(Class->Delay);
  1091. }
  1092. Set_Stage(Class->Start);
  1093. }
  1094. }
  1095. /***********************************************************************************************
  1096. * AnimClass::As_Target -- Converts the animation into a target value. *
  1097. * *
  1098. * This support routine is used to convert the animation (as a pointer) into a target *
  1099. * value (which is a number). *
  1100. * *
  1101. * INPUT: none *
  1102. * *
  1103. * OUTPUT: Returns the animation as a target value. *
  1104. * *
  1105. * WARNINGS: none *
  1106. * *
  1107. * HISTORY: *
  1108. * 09/08/1994 JLB : Created. *
  1109. *=============================================================================================*/
  1110. TARGET AnimClass::As_Target(void) const
  1111. {
  1112. Validate();
  1113. return(Build_Target(KIND_ANIMATION, Anims.ID(this)));
  1114. }
  1115. /***************************************************************************
  1116. * AnimClass::Adjust_Coord -- Adjusts anim coordinates *
  1117. * *
  1118. * INPUT: none *
  1119. * *
  1120. * OUTPUT: none *
  1121. * *
  1122. * HISTORY: *
  1123. * 05/17/1995 PWG : Created. *
  1124. *=========================================================================*/
  1125. COORDINATE AnimClass::Adjust_Coord(COORDINATE coord)
  1126. {
  1127. Validate();
  1128. int x,y;
  1129. switch (Class->Type) {
  1130. case ANIM_ATOM_DOOR:
  1131. x = -1;
  1132. y = -36;
  1133. break;
  1134. default:
  1135. return(coord);
  1136. }
  1137. COORDINATE addval = XYPixel_Coord(x, y);
  1138. coord = Coord_Add(coord, addval);
  1139. return(coord);
  1140. }
  1141. /***********************************************************************************************
  1142. * AnimClass::Detach -- Remove animation if attached to target. *
  1143. * *
  1144. * This routine is called when the specified target is being removed from the game. If this *
  1145. * animation happens to be attached to this object, then the animation must be remove as *
  1146. * well. *
  1147. * *
  1148. * INPUT: target -- The target that is about to be destroyed. *
  1149. * *
  1150. * all -- Is the target being destroyed RIGHT NOW? If not, then it will be *
  1151. * destroyed soon. In that case, the animation should continue to remain *
  1152. * attached for cosmetic reasons. *
  1153. * *
  1154. * OUTPUT: none *
  1155. * *
  1156. * WARNINGS: none *
  1157. * *
  1158. * HISTORY: *
  1159. * 06/30/1995 JLB : Created. *
  1160. * 07/02/1995 JLB : Detach is a precursor to animation destruction. *
  1161. *=============================================================================================*/
  1162. void AnimClass::Detach(TARGET target, bool all)
  1163. {
  1164. Validate();
  1165. if (all) {
  1166. if (VirtualAnim && VirtualAnim->As_Target() == target) {
  1167. VirtualAnim = NULL;
  1168. if (IsInvisible) {
  1169. IsToDelete = true;
  1170. }
  1171. }
  1172. if (Object && Object->As_Target() == target) {
  1173. Map.Remove(this, In_Which_Layer());
  1174. Object = NULL;
  1175. IsToDelete = true;
  1176. }
  1177. }
  1178. }
  1179. void AnimClass::Set_Owner(HousesType owner)
  1180. {
  1181. OwnerHouse = owner;
  1182. if (VirtualAnim != NULL) {
  1183. VirtualAnim->Set_Owner(owner);
  1184. }
  1185. }
  1186. void AnimClass::Set_Visible_Flags(unsigned flags)
  1187. {
  1188. VisibleFlags = flags;
  1189. if (VirtualAnim != NULL) {
  1190. VirtualAnim->Set_Visible_Flags(flags);
  1191. }
  1192. }