PageRenderTime 48ms CodeModel.GetById 24ms RepoModel.GetById 0ms app.codeStats 0ms

/rott-1.1/rott/cin_evnt.c

#
C | 530 lines | 344 code | 64 blank | 122 comment | 57 complexity | 1fc35166a80e1c9b0cfa26f1d05c52fa MD5 | raw file
Possible License(s): GPL-2.0
  1. /*
  2. Copyright (C) 1994-1995 Apogee Software, Ltd.
  3. This program is free software; you can redistribute it and/or
  4. modify it under the terms of the GNU General Public License
  5. as published by the Free Software Foundation; either version 2
  6. of the License, or (at your option) any later version.
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  10. See the GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
  14. */
  15. #include "cin_glob.h"
  16. #include "cin_evnt.h"
  17. #include "cin_efct.h"
  18. #include "cin_actr.h"
  19. #include "cin_def.h"
  20. #include "scriplib.h"
  21. #include "lumpy.h"
  22. #include "w_wad.h"
  23. #include "z_zone.h"
  24. #include <string.h>
  25. //MED
  26. #include "memcheck.h"
  27. eventtype * firstevent;
  28. eventtype * lastevent;
  29. // LOCALS
  30. static int numevents=0;
  31. static boolean eventsystemstarted=false;
  32. /*
  33. ===============
  34. =
  35. = AddEvent
  36. =
  37. ===============
  38. */
  39. void AddEvent (eventtype * event)
  40. {
  41. if (!firstevent)
  42. firstevent = event;
  43. else
  44. {
  45. event->prev = lastevent;
  46. lastevent->next = event;
  47. }
  48. lastevent = event;
  49. }
  50. /*
  51. ===============
  52. =
  53. = DeleteEvent
  54. =
  55. ===============
  56. */
  57. void DeleteEvent(eventtype * event)
  58. {
  59. if (event == lastevent)
  60. lastevent = event->prev;
  61. else
  62. event->next->prev = event->prev;
  63. if (event == firstevent)
  64. firstevent = event->next;
  65. else
  66. event->prev->next = event->next;
  67. event->prev = NULL;
  68. event->next = NULL;
  69. SafeFree ( event );
  70. }
  71. /*
  72. ===============
  73. =
  74. = GetNewEvent
  75. =
  76. ===============
  77. */
  78. eventtype * GetNewEvent ( void )
  79. {
  80. eventtype * event;
  81. numevents++;
  82. if ( numevents > MAXCINEMATICEVENTS )
  83. Error ("Too many Cinematic events\n");
  84. event = SafeMalloc( sizeof (eventtype) );
  85. event->next=NULL;
  86. event->prev=NULL;
  87. return event;
  88. }
  89. /*
  90. ===============
  91. =
  92. = StartupEvents
  93. =
  94. ===============
  95. */
  96. void StartupEvents ( void )
  97. {
  98. if (eventsystemstarted==true)
  99. return;
  100. eventsystemstarted=true;
  101. firstevent = NULL;
  102. lastevent = NULL;
  103. numevents=0;
  104. }
  105. /*
  106. ===============
  107. =
  108. = ShutdownEvents
  109. =
  110. ===============
  111. */
  112. void ShutdownEvents ( void )
  113. {
  114. eventtype * event;
  115. if (eventsystemstarted==false)
  116. return;
  117. eventsystemstarted=false;
  118. event=firstevent;
  119. while (event != NULL)
  120. {
  121. eventtype * nextevent;
  122. nextevent=event->next;
  123. DeleteEvent(event);
  124. event=nextevent;
  125. }
  126. }
  127. /*
  128. ===============
  129. =
  130. = CreateEvent
  131. =
  132. ===============
  133. */
  134. eventtype * CreateEvent ( int time, int type )
  135. {
  136. eventtype * event;
  137. event = GetNewEvent ();
  138. event->time = time;
  139. event->effecttype = type;
  140. event->effect = NULL;
  141. AddEvent (event);
  142. return event;
  143. }
  144. /*
  145. ===============
  146. =
  147. = GetEventType
  148. =
  149. = Gets event type from token
  150. =
  151. ===============
  152. */
  153. enum_eventtype GetEventType ( void )
  154. {
  155. // Get Event Token
  156. GetToken (false);
  157. if (!strcmpi (token,"BACKGROUND"))
  158. {
  159. GetToken (false);
  160. if (!strcmpi (token,"SCROLL"))
  161. {
  162. return background_scrolling;
  163. }
  164. else if (!strcmpi (token,"NOSCROLL"))
  165. {
  166. return background_noscrolling;
  167. }
  168. else if (!strcmpi (token,"MULTISCROLL"))
  169. {
  170. return background_multi;
  171. }
  172. else
  173. {
  174. Error("Illegal Background Scrolling token\n");
  175. }
  176. }
  177. else if (!strcmpi (token,"BACKDROP"))
  178. {
  179. GetToken (false);
  180. if (!strcmpi (token,"SCROLL"))
  181. {
  182. return backdrop_scrolling;
  183. }
  184. else if (!strcmpi (token,"NOSCROLL"))
  185. {
  186. return backdrop_noscrolling;
  187. }
  188. else
  189. {
  190. Error("Illegal Backdrop Scrolling token\n");
  191. }
  192. }
  193. else if (!strcmpi (token,"BACKGROUNDSPRITE"))
  194. {
  195. return sprite_background;
  196. }
  197. else if (!strcmpi (token,"FOREGROUNDSPRITE"))
  198. {
  199. return sprite_foreground;
  200. }
  201. else if (!strcmpi (token,"PALETTE"))
  202. {
  203. return palette;
  204. }
  205. else if (!strcmpi (token,"FADEOUT"))
  206. {
  207. return fadeout;
  208. }
  209. else if (!strcmpi (token,"FLIC"))
  210. {
  211. return flic;
  212. }
  213. else if (!strcmpi (token,"MOVIEEND"))
  214. {
  215. return cinematicend;
  216. }
  217. else if (!strcmpi (token,"BLANKSCREEN"))
  218. {
  219. return blankscreen;
  220. }
  221. else if (!strcmpi (token,"CLEARBUFFER"))
  222. {
  223. return clearbuffer;
  224. }
  225. else
  226. {
  227. Error("GetEventType: Illegal Token %s\n",token);
  228. }
  229. return -1;
  230. }
  231. /*
  232. ===============
  233. =
  234. = ParseBack
  235. =
  236. ===============
  237. */
  238. void ParseBack ( eventtype * event )
  239. {
  240. char name[10];
  241. char name2[10];
  242. int duration;
  243. int yoffset;
  244. int width;
  245. int startx;
  246. int endx;
  247. GetToken (false);
  248. strcpy(&(name[0]),token);
  249. if (event->effecttype==background_multi)
  250. {
  251. GetToken (false);
  252. strcpy(&(name2[0]),token);
  253. }
  254. GetToken (false);
  255. duration=ParseNum(token);
  256. GetToken (false);
  257. yoffset=ParseNum(token);
  258. if (
  259. (event->effecttype==background_noscrolling) ||
  260. (event->effecttype==background_scrolling)
  261. )
  262. {
  263. lpic_t * lpic;
  264. lpic = (lpic_t *)W_CacheLumpName(name,PU_CACHE, Cvt_lpic_t, 1);
  265. width = lpic->width;
  266. }
  267. else if (event->effecttype!=background_multi)
  268. {
  269. patch_t * patch;
  270. patch = (patch_t *)W_CacheLumpName(name,PU_CACHE, Cvt_lpic_t, 1);
  271. width = patch->width;
  272. }
  273. startx=0;
  274. endx=0;
  275. if (
  276. (event->effecttype==backdrop_scrolling) ||
  277. (event->effecttype==background_scrolling) ||
  278. (event->effecttype==background_multi)
  279. )
  280. {
  281. GetToken (false);
  282. startx=ParseNum(token);
  283. GetToken (false);
  284. endx=ParseNum(token);
  285. }
  286. if (event->effecttype==background_multi)
  287. event->effect = SpawnCinematicMultiBack ( name, name2, duration, startx, endx, yoffset);
  288. else
  289. event->effect = SpawnCinematicBack ( name, duration, width, startx, endx, yoffset);
  290. }
  291. /*
  292. ===============
  293. =
  294. = ParseSprite
  295. =
  296. ===============
  297. */
  298. void ParseSprite ( eventtype * event )
  299. {
  300. char name[10];
  301. int duration;
  302. int numframes;
  303. int framedelay;
  304. int x,y,scale;
  305. int endx,endy,endscale;
  306. GetToken (false);
  307. strcpy(&(name[0]),token);
  308. GetToken (false);
  309. duration=ParseNum(token);
  310. GetToken (false);
  311. numframes=ParseNum(token);
  312. GetToken (false);
  313. framedelay=ParseNum(token);
  314. GetToken (false);
  315. x=ParseNum(token);
  316. GetToken (false);
  317. y=ParseNum(token);
  318. GetToken (false);
  319. scale=ParseNum(token);
  320. GetToken (false);
  321. endx=ParseNum(token);
  322. GetToken (false);
  323. endy=ParseNum(token);
  324. GetToken (false);
  325. endscale=ParseNum(token);
  326. event->effect = SpawnCinematicSprite ( name, duration, numframes,
  327. framedelay, x, y, scale,
  328. endx, endy, endscale
  329. );
  330. }
  331. /*
  332. ===============
  333. =
  334. = ParseFlic
  335. =
  336. ===============
  337. */
  338. void ParseFlic ( eventtype * event )
  339. {
  340. char name[10];
  341. boolean loop;
  342. boolean usefile;
  343. GetToken (false);
  344. strcpy(&(name[0]),token);
  345. GetToken (false);
  346. if (!strcmpi (token,"LOOP"))
  347. {
  348. loop = true;
  349. }
  350. else if (!strcmpi (token,"NOLOOP"))
  351. {
  352. loop = false;
  353. }
  354. else
  355. Error("ParseFlic: Illegal or missing flic loop token %s\n",token);
  356. GetToken (false);
  357. if (!strcmpi (token,"FILE"))
  358. {
  359. usefile=true;
  360. }
  361. else if (!strcmpi (token,"LUMP"))
  362. {
  363. usefile=false;
  364. }
  365. else
  366. Error("ParseFlic: Illegal or missing flic use token %s\n",token);
  367. event->effect = SpawnCinematicFlic ( name, loop, usefile );
  368. }
  369. /*
  370. ===============
  371. =
  372. = ParsePalette
  373. =
  374. ===============
  375. */
  376. void ParsePalette ( eventtype * event )
  377. {
  378. char name[10];
  379. GetToken (false);
  380. strcpy(&(name[0]),token);
  381. event->effect = SpawnCinematicPalette ( name );
  382. }
  383. /*
  384. ===============
  385. =
  386. = ParseEvent
  387. =
  388. ===============
  389. */
  390. void ParseEvent ( int time )
  391. {
  392. eventtype * event;
  393. event = CreateEvent ( time, GetEventType() );
  394. switch (event->effecttype)
  395. {
  396. case background_noscrolling:
  397. case background_scrolling:
  398. case background_multi:
  399. case backdrop_scrolling:
  400. case backdrop_noscrolling:
  401. ParseBack(event);
  402. break;
  403. case sprite_background:
  404. case sprite_foreground:
  405. ParseSprite(event);
  406. break;
  407. case palette:
  408. ParsePalette(event);
  409. break;
  410. case flic:
  411. ParseFlic(event);
  412. break;
  413. case fadeout:
  414. case blankscreen:
  415. case clearbuffer:
  416. case cinematicend:
  417. break;
  418. }
  419. }
  420. /*
  421. ===============
  422. =
  423. = UpdateCinematicEvents
  424. =
  425. ===============
  426. */
  427. void UpdateCinematicEvents ( int time )
  428. {
  429. eventtype * event;
  430. for (event=firstevent;event != NULL;)
  431. {
  432. if (event->time==time)
  433. {
  434. eventtype * nextevent;
  435. nextevent=event->next;
  436. SpawnCinematicActor ( event->effecttype, event->effect );
  437. DeleteEvent(event);
  438. event=nextevent;
  439. }
  440. else if (event->time>time)
  441. break;
  442. else
  443. event=event->next;
  444. }
  445. }
  446. /*
  447. ===============
  448. =
  449. = PrecacheCinematic
  450. =
  451. ===============
  452. */
  453. void PrecacheCinematic ( void )
  454. {
  455. eventtype * event;
  456. for (event=firstevent;event != NULL;)
  457. {
  458. PrecacheCinematicEffect ( event->effecttype, event->effect );
  459. event=event->next;
  460. }
  461. }