Debian Codegraph @

Descent3/gamecinematics.cpp

raw symbols SCIP
1 /*
2 * Descent 3
3 * Copyright (C) 2024 Parallax Software
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 --- HISTORICAL COMMENTS FOLLOW ---
19
20 * $Logfile: /DescentIII/main/gamecinematics.cpp $
21 * $Revision: 49 $
22 * $Date: 4/06/00 9:25a $
23 * $Author: Matt $
24 *
25 * In-Game Cinematics system
26 *
27 * $Log: /DescentIII/main/gamecinematics.cpp $
28 *
29 * 49 4/06/00 9:25a Matt
30 * Fixed a screen clear problem on at ATI Rage Fury Maxx in dual-chip mode
31 * by forcing the screen to clear four times (instead of three).
32 *
33 * 48 10/08/99 4:14p 3dsmax
34 * complex cinematic paths with only one node issue fixed.
35 *
36 * 47 5/22/99 12:07a Jeff
37 * properly set the target handle when faking a canned cinematic
38 *
39 * 46 5/19/99 12:52p Samir
40 * clear player weapon firing when entering cinematics,
41 *
42 * 45 5/07/99 7:48p Jeff
43 * fixed demo recording during cinematics
44 *
45 * 44 5/07/99 1:44p Chris
46 * Made in-game cinematics use the ORIENT_PATH_NODE for player ships
47 *
48 * 43 5/04/99 6:52p Jeff
49 * added new canned cinematic to fade screen to white and endlevel. Fixed
50 * crash bug with invalid player path for canned cine with player paths
51 *
52 * 42 4/28/99 3:32a Jeff
53 * created cinematic level reset function
54 *
55 * 41 4/27/99 5:58p Jeff
56 * fixed for coop
57 *
58 * 40 4/27/99 5:41p Jeff
59 * hopefully fixed coop/multiplayer issues
60 *
61 * 39 4/24/99 2:20a Chris
62 * Added the Neutral_till_hit flag
63 *
64 * 38 4/15/99 11:40a Jeff
65 * changes layout of igc intro
66 *
67 * 37 4/14/99 3:56a Jeff
68 * fixed case mismatch in #includes
69 *
70 * 36 4/06/99 4:34p Jeff
71 * fixed screenmode bug during endlevel
72 *
73 * 35 4/06/99 2:54p Jeff
74 * fixed 1 node end level sequence path bug
75 *
76 * 34 4/02/99 11:33p Jeff
77 * able to turn off IGC in debug mode. Better handling of cinematics
78 * quick exit if playing via alt-p
79 *
80 * 33 3/31/99 8:34p Jeff
81 * different bitmap for trans
82 *
83 * 32 3/30/99 4:47p Jeff
84 * added level events for when IGC occurs for a player
85 *
86 * 31 3/27/99 7:22p Jeff
87 * fixed cinematics when going from one cut to another immediatly. Added
88 * start transition
89 *
90 * 30 3/19/99 9:39a Nate
91 * Jeff - fixed crash bug
92 *
93 * 29 3/17/99 11:48a Jeff
94 * intro cams are letterbox
95 *
96 * 28 3/10/99 6:44p Jeff
97 * fixed exported game cinematic function for canned cinematics, so it's
98 * prototype doesn't change (oem patch friendly)
99 *
100 * 27 3/10/99 6:20p Jeff
101 * many fixes to demo system. Fixed IGC so cameras move...fixed osiris to
102 * be restored correctly, and it handles errors on restore
103 *
104 * 26 3/10/99 11:27a Jeff
105 * fixed saving cinematic data when writing cinematics that use paths
106 *
107 * 25 3/08/99 3:24p Jeff
108 * fixed end level sequencing where if the level ended while the player
109 * was dead.
110 *
111 * 24 3/08/99 12:04p Jeff
112 * fixed ship jitter in in-game cinematics (intro/end level)
113 *
114 * 23 3/04/99 3:57p Jeff
115 * make player's burners on in intro/end level seqeunces if on a path
116 *
117 * 22 3/03/99 1:18p Jeff
118 * turn off afterburner
119 *
120 * 21 3/01/99 5:35p Jeff
121 * didn't change much
122 *
123 * 20 2/28/99 8:31p Jeff
124 * added fade and move player dallas action. Fixed the end-level sequence
125 * changing view back to player for split second.
126 *
127 * 19 2/28/99 6:55p Jeff
128 * orient the player correctly when 1 node path for level intro
129 *
130 * 18 2/26/99 6:38p Mark
131 * fixed screen clearing problem
132 *
133 * 17 2/23/99 12:44a Jeff
134 * added support for in-game-cinematics in demo system
135 *
136 * 16 2/22/99 1:20a Jeff
137 * added support for inventory (simple) in dallas. Moved end-level
138 * sequence to use IGC. Add position clipboard stuff for dallas. Fixed
139 * some inventory bug with storing object handles
140 *
141 * 15 2/21/99 8:35p Jeff
142 * misc changes to handle new matcen and path types of dallas
143 *
144 * 14 2/20/99 4:15p Jeff
145 * add cinematic text to game messages
146 *
147 * 13 2/18/99 6:47p Jeff
148 * added call to start/stop special cinematics music
149 *
150 * 12 2/18/99 3:00p Jeff
151 * smoother rotation/autolevel
152 *
153 * 11 2/16/99 9:36p Jeff
154 * new add gamefile dialog
155 *
156 * 10 2/16/99 6:15p Jeff
157 * pause hud messages when in cinematics
158 *
159 * 9 2/14/99 1:16a Jeff
160 * added canned cinematic function/structures. Added a flag to push
161 * target to end of path if on a path (quick exit). Added canned intro
162 * cine. Determine correct velocity on player ship for intro cine.
163 *
164 * 8 2/12/99 2:45a Jeff
165 * added end-cinematic transitions
166 *
167 * 7 2/10/99 1:47p Matt
168 * Changed object handle symbolic constants
169 *
170 * 6 2/04/99 3:56p Jeff
171 * no cinematics in multiplayer
172 *
173 * 5 2/02/99 3:58p Jeff
174 * started to implement level intro cinematic (need ai functions first).
175 * No longer need camera object to do cinematic (auto-created)...path
176 * cameras use speed based on distance needed to travel.
177 *
178 * 4 2/02/99 12:32p Jeff
179 * added ai notify events for movie start and stop
180 *
181 * 3 2/01/99 12:55p Jeff
182 * restore correct hud mode, added flag to stop cinematics if target dies
183 *
184 * 2 1/31/99 8:48p Jeff
185 * new in game cinematics system finished
186 *
187 * $NoKeywords: $
188 */
189
190 #include "pstypes.h"
191 #include "pserror.h"
192 #include "grtext.h"
193 #include "renderer.h"
194 #include "gamecinematics.h"
195 #include "vecmat.h"
196 #include "mem.h"
197 #include "gamepath.h"
198 #include <stdio.h>
199 #include <stdlib.h>
200 #include <string.h>
201 #include "game.h"
202 #include "AIGoal.h"
203 #include "aipath.h"
204 #include "objinfo.h"
205 #include "player.h"
206 #include "ddio.h"
207 #include "gamefont.h"
208 #include "AIMain.h"
209 #include "controls.h"
210 #include "d3music.h"
211 #include "gamesequence.h"
212 #include "demofile.h"
213 #include "osiris_dll.h"
214 #include "multi.h"
215 #include "weapon.h"
216
217 #include <algorithm>
218
219 #if (defined(_DEBUG) || defined(EDITOR))
220 bool Cinematics_enabled = true;
221 extern int DoAI;
222 #ifdef EDITOR
223 extern bool Game_being_played_from_quick_play;
224 #endif
225 #endif
226 extern uint16_t Demo_obj_map[MAX_OBJECTS];
227
228 struct {
229 // some important, pre-computed times
230 float text_display_start, text_display_stop;
231 float track_start, track_stop;
232 float player_start, player_stop;
233 float camera_start, camera_stop;
234 float exit_start, exit_end;
235 float end_time;
236
237 void (*callback)(int type);
238
239 int pathnum;
240 int room;
241 vector position;
242
243 int target_objhandle;
244 int camera_objhandle;
245
246 int bmp_handle;
247 int longest_line;
248
249 uint32_t flags;
250
251 tHUDMode old_hudmode;
252
253 int num_lines;
254 int end_transition_type; // what kind of ending transition should the cinematic have
255 int start_transition_type; // what kind of starting transition should the cinematic have
256 char *text;
257 bool target_triggered; // whether the notify event has been sent to the object yet
258
259 bool doing_end_transition; // we're processing an end transition still
260 float end_transition_start_time; // Gametime that the end transition started
261 float end_transition_end_time; // Gametime that the end transition should end
262
263 float start_transition_start_time;
264 float start_transition_end_time;
265
266 // some transition data
267 float early_trans_end_start_time;
268
269 bool controls_suspended;
270 } GameCinema;
271
272 #define CDI_NOT_CANNED 0
273 #define CDI_CANNED 1
274
275 struct tCinematicDemoInfo {
276 uint8_t cinematic_type; // canned/not canned
277 int camera_objhandle; // object handle for camera to use
278
279 char *text_string; // not canned text string
280
281 union {
282 tCannedCinematicInfo *canned_data; // data to start a canned cinematic
283 tGameCinematic *cinematic_data; // data to start a regular cinematic
284 };
285
286 };
287
288 static void Cinematic_WriteDemoFileData(tCinematicDemoInfo *info);
289 static bool Cinematic_StartCine(tGameCinematic *info, const char *text_string, int camera_objhandle);
290
291 static void Cinematic_DrawText(void);
292 static void Cinematic_DoEndTransition(void);
293 static void Cinematic_DoStartTransition(void);
294
295 bool Cinematic_inuse;
296 static tGameCinematic Cinematic_fake_info;
297 bool Cinematic_fake_queued = false;
298
299 static int gc_fade_bmp_handle = BAD_BITMAP_HANDLE;
300 static int gc_fadewhite_bmp_handle = BAD_BITMAP_HANDLE;
301 static int gc_wacky_bmp_handle = BAD_BITMAP_HANDLE;
302 static int gc_temp_bmp_handle = BAD_BITMAP_HANDLE;
303
304 #define END_TRANSITION_TIME 1.0f
305
306 static float Cine_GetPathTravelSpeed(int pathnum, float time);
307 static void Cinematic_PerformFake(void);
308 static void Cinematic_SetForFakeCinematic(tGameCinematic *info);
309 static inline void verify_percentranage(PercentageRange *range);
310 static inline int Cinematics_CreateCamera(void);
311 static inline void Cinematic_DeleteCamera(int objhandle);
312 static inline bool Cinematic_IsPlayerDead(void);
313 static bool Cinematic_IsKeyPressed(void);
314 static void CannedCinematicIntroCallback(int type);
315 static void CannedCinematic_Intro(int PathID, char *Text, int PlayerPath, float Seconds, int camera_handle);
316 static void CannedCinematicEndLevelCallback(int type);
317 static void CannedCinematic_EndLevelPath(int PathID, char *Text, int PlayerPath, float Seconds, int camera_handle);
318 static void CannedCinematic_EndLevelPoint(vector *pos, int room, char *Text, int PlayerPath, float Seconds,
319 int camera_handle);
320 static void CannedCinematicMovePlayerFadeCallback(int type);
321 static void CannedCinematic_MovePlayerFade(object *player, int room, vector *pos, matrix *orient, int camera_handle);
322 static void CannedCinematicLevelEndFadeWhiteCallback(int type);
323 static void CannedCinematic_LevelEndFadeWhite(int camera_handle, float time, char *text_to_display);
324 static void Cinematic_DoFakeCannedCinematics(tCannedCinematicInfo *info);
325
326 // Returns the hud mode before cinematics
327 tHUDMode Cinematic_GetOldHudMode(void) { return GameCinema.old_hudmode; }
328
329 // Cinematic_Close
330 //
331 // Closes the in-game cinematics
332 void Cinematic_Close(void) {
333 if (Cinematic_inuse) {
334 Cinematic_Stop();
335 }
336
337 if (gc_fade_bmp_handle > BAD_BITMAP_HANDLE) {
338 bm_FreeBitmap(gc_fade_bmp_handle);
339 gc_fade_bmp_handle = BAD_BITMAP_HANDLE;
340 }
341
342 if (gc_fadewhite_bmp_handle > BAD_BITMAP_HANDLE) {
343 bm_FreeBitmap(gc_fadewhite_bmp_handle);
344 gc_fadewhite_bmp_handle = BAD_BITMAP_HANDLE;
345 }
346
347 if (gc_temp_bmp_handle > BAD_BITMAP_HANDLE) {
348 bm_FreeBitmap(gc_temp_bmp_handle);
349 gc_temp_bmp_handle = BAD_BITMAP_HANDLE;
350 }
351
352 if (gc_wacky_bmp_handle > BAD_BITMAP_HANDLE) {
353 bm_FreeBitmap(gc_wacky_bmp_handle);
354 gc_wacky_bmp_handle = BAD_BITMAP_HANDLE;
355 }
356
357 GameCinema.doing_end_transition = false;
358 }
359
360 // Cinematic_Init
361 //
362 // Initializes the in-game cinematics
363 void Cinematic_Init(void) {
364 static bool called_once = false;
365 Cinematic_inuse = false;
366
367 memset(&GameCinema, 0, sizeof(GameCinema));
368
369 GameCinema.doing_end_transition = false;
370 gc_fade_bmp_handle = BAD_BITMAP_HANDLE;
371
372 gc_fade_bmp_handle = bm_AllocBitmap(32, 32, 0);
373 if (gc_fade_bmp_handle > BAD_BITMAP_HANDLE) {
374 uint16_t *data = bm_data(gc_fade_bmp_handle, 0);
375 int i, size = 32 * 32;
376
377 for (i = 0; i < size; i++)
378 data[i] = GR_RGB16(0, 0, 0) | OPAQUE_FLAG;
379 }
380
381 gc_wacky_bmp_handle = bm_AllocLoadFileBitmap("ShieldBitmap.ogf", 0);
382
383 gc_fadewhite_bmp_handle = bm_AllocBitmap(32, 32, 0);
384 if (gc_fadewhite_bmp_handle > BAD_BITMAP_HANDLE) {
385 uint16_t *data = bm_data(gc_fadewhite_bmp_handle, 0);
386 int i, size = 32 * 32;
387
388 for (i = 0; i < size; i++)
389 data[i] = GR_RGB16(255, 255, 255) | OPAQUE_FLAG;
390 }
391
392 gc_temp_bmp_handle = bm_AllocBitmap(32, 32, 0);
393
394 if (!called_once) {
395 atexit(Cinematic_Close);
396 called_once = true;
397 }
398 }
399
400 void Cinematic_LevelInit(void) {
401 Cinematic_inuse = false;
402 Cinematic_fake_queued = false;
403 GameCinema.doing_end_transition = false;
404 }
405
406 static inline void verify_percentranage(PercentageRange *range) {
407 if (range->min < 0.0f)
408 range->min = 0.0f;
409 if (range->min > 1.0f)
410 range->min = 1.0f;
411 if (range->max < 0.0f)
412 range->max = 0.0f;
413 if (range->max > 1.0f)
414 range->max = 1.0f;
415
416 if (range->max < range->min) {
417 float temp = range->max;
418 range->max = range->min;
419 range->min = temp;
420 }
421 }
422
423 // Cinematic_PerformFake
424 //
425 // Performs a fake cinematic...just calls certain functions that may need to be
426 // called for certain things to happen. For instance, some bosses are triggered when
427 // their boss intro cam is started, but in multiplayer there is no cinematics, so calling
428 // this would do what's needed.
429 void Cinematic_PerformFake(void) {
430 Cinematic_fake_queued = false;
431 mprintf(0, "Cinematics: Faking Cinematic\n");
432 object *target = ObjGet(Cinematic_fake_info.target_objhandle);
433 if (!target) {
434 mprintf(0, "Cinematics: Invalid target...can't fake\n");
435 return;
436 }
437
438 // tell the target it's the focus of a cinematic
439 AINotify(target, AIN_MOVIE_START, NULL);
440 AINotify(target, AIN_MOVIE_END, NULL);
441
442 if (target->type == OBJ_PLAYER) {
443 tOSIRISEventInfo ei;
444
445 Osiris_CallLevelEvent(EVT_PLAYER_MOVIE_START, &ei);
446 Osiris_CallLevelEvent(EVT_PLAYER_MOVIE_END, &ei);
447 }
448 }
449
450 void Cinematic_SetForFakeCinematic(tGameCinematic *info) {
451 ASSERT(Cinematic_fake_queued == false); // ack trying to play 2 cinematics in one frame!?
452
453 memcpy(&Cinematic_fake_info, info, sizeof(tGameCinematic));
454 Cinematic_fake_queued = true;
455 }
456
457 static inline int Cinematics_CreateCamera(void) {
458 int objnum = ObjCreate(OBJ_CAMERA, 0, Player_object->roomnum, &Player_object->pos, NULL);
459 if (objnum == -1)
460 return OBJECT_HANDLE_NONE;
461
462 if (Demo_flags == DF_RECORDING) {
463 DemoWriteObjCreate(OBJ_CAMERA, 0, Player_object->roomnum, &Player_object->pos, NULL, OBJECT_HANDLE_NONE,
464 &Objects[objnum]);
465 }
466
467 return Objects[objnum].handle;
468 }
469
470 // Cinematic_Start
471 //
472 // Starts an in-game cinematic sequence. text_string is the text to be displayed
473 // use pipes (|) to seperate lines. (calls demo routines to record)
474 bool Cinematic_Start(tGameCinematic *info, char *text_string) {
475 if (Demo_flags == DF_PLAYBACK)
476 return true; // demo system calls Cinematic_StartCine itself
477
478 ASSERT(info != NULL);
479 ASSERT(text_string != NULL);
480 if (!info || !text_string)
481 return false;
482
483 if (Cinematic_inuse) {
484 Cinematic_SetForFakeCinematic(info);
485 return false;
486 }
487
488 if (Game_mode & GM_MULTI) {
489 Cinematic_SetForFakeCinematic(info);
490 return false; // no cinematics in multiplayer
491 }
492
493 if ((info->flags & GCF_CAMERAPLACEMENT) == GCF_USEPATH) {
494 info->orient = NULL; // ensure that this is NULL
495 }
496
497 int camera_handle = Cinematics_CreateCamera();
498
499 if (Demo_flags == DF_RECORDING) {
500 tCinematicDemoInfo demo_data;
501 demo_data.cinematic_type = CDI_NOT_CANNED;
502 demo_data.text_string = text_string;
503 demo_data.cinematic_data = info;
504 demo_data.camera_objhandle = camera_handle;
505 Cinematic_WriteDemoFileData(&demo_data);
506 }
507
508 return Cinematic_StartCine(info, text_string, camera_handle);
509 }
510
511 static inline void Cinematic_DeleteCamera(int objhandle) {
512 object *obj = ObjGet(objhandle);
513 if (obj) {
514 SetObjectDeadFlag(obj);
515 }
516 }
517
518 // Cinematic_StartCine
519 //
520 // Starts an in-game cinematic sequence. text_string is the text to be displayed
521 // use pipes (|) to seperate lines. (does not call demo routines)
522 bool Cinematic_StartCine(tGameCinematic *info, const char *text_string, int camera_objhandle) {
523 ASSERT(info != NULL);
524 ASSERT(text_string != NULL);
525 if (!info || !text_string) {
526 Cinematic_DeleteCamera(camera_objhandle);
527 return false;
528 }
529
530 if (Cinematic_inuse) {
531 Cinematic_SetForFakeCinematic(info);
532 Cinematic_DeleteCamera(camera_objhandle);
533 return false;
534 }
535
536 if (Game_mode & GM_MULTI) {
537 Cinematic_SetForFakeCinematic(info);
538 Cinematic_DeleteCamera(camera_objhandle);
539 return false; // no cinematics in multiplayer
540 }
541
542 #ifdef _DEBUG
543 if (!Cinematics_enabled) {
544 Cinematic_SetForFakeCinematic(info);
545 Cinematic_DeleteCamera(camera_objhandle);
546 AddBlinkingHUDMessage("Cinematic: Not Displayed, they are disabled (DEL-SHIFT-C)");
547 return true;
548 }
549
550 if (!DoAI) {
551 Cinematic_SetForFakeCinematic(info);
552 Cinematic_DeleteCamera(camera_objhandle);
553 AddBlinkingHUDMessage("Cinematic: Not Displayed, AI is not turned on (DEL-A)");
554 return true;
555 }
556 #endif
557
558 // take the given values and setup the struct
559 memset(&GameCinema, 0, sizeof(GameCinema));
560
561 // verify passed in values
562 verify_percentranage(&info->text_display);
563 verify_percentranage(&info->track_target);
564 verify_percentranage(&info->player_disabled);
565 verify_percentranage(&info->in_camera_view);
566 verify_percentranage(&info->quick_exit);
567
568 GameCinema.flags = info->flags;
569 GameCinema.target_objhandle = info->target_objhandle;
570 GameCinema.callback = info->callback;
571 GameCinema.old_hudmode = GetHUDMode();
572
573 int objnum;
574 object *c = ObjGet(camera_objhandle);
575 if (c) {
576 objnum = OBJNUM(c);
577 } else {
578 mprintf(0, "Unable to create camera\n");
579 return false;
580 }
581
582 if ((info->flags & GCF_CAMERAPLACEMENT) == GCF_USEPOINT) {
583 GameCinema.room = info->room;
584 GameCinema.position = info->position;
585 // objnum = ObjCreate(OBJ_CAMERA,0,info->room,&info->position,info->orient);
586 ObjSetPos(c, &info->position, info->room, info->orient, false);
587
588 } else {
589 GameCinema.pathnum = info->pathid;
590 if (GameCinema.pathnum == -1) {
591 mprintf(0, "Invalid Path given\n");
592 return false;
593 }
594 // Abort if not a good path
595 if (((info->flags & GCF_CAMERAPLACEMENT) == GCF_USEPOINT)) {
596 if (GamePaths[GameCinema.pathnum].num_nodes < 2) {
597 mprintf(0, "Not a good path passed to Cinematic_Start\n");
598 return false;
599 }
600 }
601
602 // objnum =
603 // ObjCreate(OBJ_CAMERA,0,GamePaths[GameCinema.pathnum].pathnodes[0].roomnum,&GamePaths[GameCinema.pathnum].pathnodes[0].pos,NULL);
604 ObjSetPos(c, &GamePaths[GameCinema.pathnum].pathnodes[0].pos, GamePaths[GameCinema.pathnum].pathnodes[0].roomnum,
605 NULL, false);
606 }
607
608 /*
609 if(objnum==-1){
610 //couldn't create camera
611 mprintf(0,"Unable to create camera\n");
612 return false;
613 }
614 */
615
616 GameCinema.camera_objhandle = Objects[objnum].handle;
617 GameCinema.target_triggered = false;
618 object *camera = &Objects[objnum];
619
620 // parse the text line and extract the lines
621 GameCinema.num_lines = 0;
622 GameCinema.text = mem_strdup(text_string);
623 char *ptr = GameCinema.text;
624 if (!ptr) {
625 Error("Out of Memory\n");
626 }
627 while (*ptr) {
628 if (*ptr == '|') {
629 *ptr = '\0';
630 GameCinema.num_lines++;
631 }
632 ptr++;
633 }
634 GameCinema.num_lines++;
635
636 float start_time = Gametime;
637 GameCinema.end_time = start_time + info->max_time_play;
638 GameCinema.text_display_start = start_time + (info->max_time_play * info->text_display.min);
639 GameCinema.text_display_stop = start_time + (info->max_time_play * info->text_display.max);
640 GameCinema.track_start = start_time + (info->max_time_play * info->track_target.min);
641 GameCinema.track_stop = start_time + (info->max_time_play * info->track_target.max);
642 GameCinema.player_start = start_time + (info->max_time_play * info->player_disabled.min);
643 GameCinema.player_stop = start_time + (info->max_time_play * info->player_disabled.max);
644 GameCinema.camera_start = start_time + (info->max_time_play * info->in_camera_view.min);
645 GameCinema.camera_stop = start_time + (info->max_time_play * info->in_camera_view.max);
646 GameCinema.exit_start = start_time + (info->max_time_play * info->quick_exit.min);
647 GameCinema.exit_end = start_time + (info->max_time_play * info->quick_exit.max);
648 GameCinema.start_transition_type = info->start_transition;
649 GameCinema.end_transition_type = info->end_transition;
650 GameCinema.doing_end_transition = false; // stop all pending end transitions
651 GameCinema.controls_suspended = false;
652
653 if (GameCinema.end_transition_type == GCTT_WACKY || GameCinema.end_transition_type == GCTT_FADEINOUT) {
654 GameCinema.early_trans_end_start_time = start_time + info->max_time_play - (END_TRANSITION_TIME / 2.0f);
655 }
656
657 if (GameCinema.end_transition_type == GCTT_FADEWHITE) {
658 GameCinema.early_trans_end_start_time = start_time;
659 }
660
661 if (GameCinema.start_transition_type == GCTT_NONE) {
662 GameCinema.start_transition_start_time = start_time;
663 GameCinema.start_transition_end_time = start_time;
664 } else {
665 GameCinema.start_transition_start_time = GameCinema.start_transition_end_time = -1.0f;
666 }
667
668 // The structs are setup, time to setup the camera and objects
669
670 mprintf(0, "Cinematic_Start\n");
671
672 Player_object->flags &= ~OF_DESTROYABLE;
673 Players[Player_num].flags &= ~PLAYER_FLAGS_AFTERBURN_ON;
674 camera->flags &= ~OF_DESTROYABLE;
675
676 // setup camera physics
677 camera->movement_type = MT_PHYSICS;
678 camera->mtype.phys_info.flags &= ~PF_USES_THRUST;
679 // camera->mtype.phys_info.flags |= PF_LEVELING;
680 camera->mtype.phys_info.flags &= ~PF_LEVELING;
681 camera->mtype.phys_info.drag = 0.1f;
682 camera->mtype.phys_info.mass = 2.0f;
683 camera->mtype.phys_info.rotdrag = 0.1f;
684
685 vm_MakeZero(&camera->mtype.phys_info.thrust);
686 vm_MakeZero(&camera->mtype.phys_info.rotthrust);
687 vm_MakeZero(&camera->mtype.phys_info.rotvel);
688 vm_MakeZero(&camera->mtype.phys_info.velocity);
689
690 // setup camera AI
691 SetObjectControlType(camera, CT_AI);
692 memset(camera->ai_info, 0, sizeof(ai_frame));
693
694 camera->ai_info->ai_class = AIC_STATIC;
695 camera->ai_info->ai_type = AIT_AIS;
696
697 GoalInitTypeGoals(camera, AIT_AIS);
698
699 float velocity_to_use = 75.0f;
700
701 if ((info->flags & GCF_CAMERAPLACEMENT) == GCF_USEPATH) {
702 // determine velocity based on distance to travel on path
703 velocity_to_use = Cine_GetPathTravelSpeed(GameCinema.pathnum, info->max_time_play);
704 }
705
706 camera->ai_info->flags =
707 AIF_PERSISTANT | AIF_DISABLE_FIRING | AIF_DISABLE_MELEE | AIF_FORCE_AWARENESS | AIF_DETERMINE_TARGET;
708 camera->ai_info->max_velocity = velocity_to_use; // Slightly faster than the real ship
709 camera->ai_info->max_delta_velocity = 40.0f;
710 camera->ai_info->max_turn_rate = 14000;
711 camera->ai_info->awareness = AWARE_MOSTLY;
712 camera->ai_info->movement_type = MC_FLYING;
713 camera->ai_info->next_movement = AI_INVALID_INDEX;
714 camera->ai_info->anim_sound_handle = 0;
715 camera->ai_info->status_reg = 0;
716 camera->ai_info->last_played_sound_index = -1;
717 camera->ai_info->weapon_speed = 0.0f;
718 camera->ai_info->animation_type = AS_ALERT;
719 camera->ai_info->next_melee_time = Gametime;
720 camera->ai_info->next_flinch_time = Gametime;
721 camera->ai_info->target_handle = OBJECT_HANDLE_NONE;
722 camera->ai_info->next_check_see_target_time = Gametime;
723 camera->ai_info->last_see_target_time = Gametime;
724 camera->ai_info->last_render_time = -1.0f;
725 camera->ai_info->next_target_update_time = Gametime;
726 camera->ai_info->notify_flags |= AI_NOTIFIES_ALWAYS_ON;
727 camera->ai_info->last_see_target_pos = Zero_vector;
728 camera->ai_info->dodge_vel_percent = 1.0f;
729 camera->ai_info->attack_vel_percent = 1.0f;
730 camera->ai_info->fight_same = 0.0f;
731 camera->ai_info->agression = 0.0f;
732 camera->ai_info->avoid_friends_distance = 0.0f;
733 camera->ai_info->biased_flight_importance = 0.0f;
734 camera->ai_info->circle_distance = 0.0f;
735 camera->ai_info->dodge_percent = 0.0f;
736 camera->ai_info->fight_team = 0.0;
737
738 AIPathInitPath(&camera->ai_info->path);
739
740 // Move camera to start position
741 vector c_pos;
742 int c_room;
743 matrix c_orient;
744
745 if ((info->flags & GCF_CAMERAPLACEMENT) == GCF_USEPOINT) {
746 c_room = GameCinema.room;
747 c_pos = GameCinema.position;
748 if (info->orient)
749 c_orient = *info->orient;
750 else
751 vm_MakeIdentity(&c_orient);
752 } else {
753 // Set up path info
754 path_information pi;
755
756 pi.path_id = GameCinema.pathnum;
757 pi.start_node = 0;
758 pi.end_node = GamePaths[GameCinema.pathnum].num_nodes - 1;
759
760 if (GamePaths[GameCinema.pathnum].num_nodes == 1) {
761 vm_VectorToMatrix(&c_orient, &GamePaths[GameCinema.pathnum].pathnodes[0].fvec,
762 &GamePaths[GameCinema.pathnum].pathnodes[0].uvec, NULL);
763 pi.next_node = 0;
764 } else {
765 vector fvec = GamePaths[GameCinema.pathnum].pathnodes[1].pos - GamePaths[GameCinema.pathnum].pathnodes[0].pos;
766 vm_VectorToMatrix(&c_orient, &fvec, NULL, NULL);
767 pi.next_node = 1;
768 }
769
770 c_pos = GamePaths[GameCinema.pathnum].pathnodes[0].pos;
771 c_room = GamePaths[GameCinema.pathnum].pathnodes[0].roomnum;
772
773 // Make the player follow the path
774 GoalAddGoal(camera, AIG_FOLLOW_PATH, (void *)&pi, 0, 10.0f, GF_ORIENT_TARGET | GF_FORCE_AWARENESS);
775 }
776
777 ObjSetPos(camera, &c_pos, c_room, &c_orient, true);
778
779 // Switch to correct hud mode
780 switch (GameCinema.flags & GCF_SCREENFORMAT) {
781 case GCF_LETTERBOX:
782 SetHUDMode(HUD_LETTERBOX);
783 break;
784 case GCF_FULLSCREEN:
785 SetHUDMode(HUD_OBSERVER);
786 break;
787 }
788
789 GameCinema.bmp_handle = -1;
790 GameCinema.longest_line = 0;
791
792 if ((GameCinema.flags & GCF_TEXT_MASK) == GCF_TEXT_WIPEIN) {
793
794 // create overlay bitmap
795 GameCinema.bmp_handle = bm_AllocBitmap(128, 128, 0);
796 if (GameCinema.bmp_handle > BAD_BITMAP_HANDLE) {
797 uint16_t *data = bm_data(GameCinema.bmp_handle, 0);
798 for (int j = 0; j < 128 * 128; j++) {
799 data[j] = GR_RGB16(0, 0, 0) | OPAQUE_FLAG;
800 }
801 }
802 }
803
804 // determine longest line and add text to game messages
805 int old_font = grtext_GetFont();
806 grtext_SetFont(BIG_BRIEFING_FONT);
807 int pos = 0, len;
808 char *str_ptr;
809
810 for (int i = 0; i < GameCinema.num_lines; i++) {
811 int l;
812
813 len = strlen(&GameCinema.text[pos]);
814
815 l = grtext_GetTextLineWidth(&GameCinema.text[pos]);
816 if (GameCinema.longest_line < l)
817 GameCinema.longest_line = l;
818
819 // add text to game messages
820 str_ptr = &GameCinema.text[pos];
821 while (*str_ptr && (*str_ptr == ' ' || *str_ptr == '\t'))
822 str_ptr++;
823 if (*str_ptr)
824 AddGameMessage(str_ptr);
825
826 pos += len + 1;
827 }
828 GameCinema.longest_line += 10;
829 grtext_SetFont(old_font);
830
831 Cinematic_inuse = true;
832 HUDPauseMessages();
833 D3MusicStartCinematic();
834
835 if (GameCinema.camera_start <= Gametime) {
836 Viewer_object = camera;
837
838 object *target;
839 target = ObjGet(GameCinema.target_objhandle);
840
841 if (GameCinema.track_start <= Gametime && target) {
842 // face target immediatly
843 vector u_axis;
844 angle goal_angle;
845
846 vector turn_to = target->pos - camera->pos;
847 vm_NormalizeVector(&turn_to);
848
849 if (turn_to == Zero_vector) {
850 mprintf(0, "Cine: No turn_to or less than 1 degree off goal\n");
851 goto continue_start;
852 }
853
854 goal_angle = vm_DeltaAngVecNorm(&camera->orient.fvec, &turn_to, &u_axis);
855 if (goal_angle == 0) {
856 mprintf(0, "Cine: Goal angle is zero\n");
857 goto continue_start;
858 }
859
860 camera->orient.fvec = turn_to;
861
862 camera->orient.uvec.x = camera->orient.uvec.z = 0.0f;
863 camera->orient.uvec.y = 1.0f;
864
865 vm_Orthogonalize(&camera->orient);
866 ObjSetOrient(camera, &camera->orient);
867
868 } else if ((GameCinema.flags & GCF_CAMERAPLACEMENT) == GCF_USEPATH) {
869 // adjust to path node orientation (if we are on a path)
870 int cur_path = camera->ai_info->path.cur_path;
871 int cur_node = camera->ai_info->path.cur_node;
872 int end_node = camera->ai_info->path.path_end_node[cur_path];
873 int next_node = std::min(cur_node + 1, end_node);
874 int path_num = camera->ai_info->path.path_id[cur_path];
875
876 if (cur_node != next_node) {
877 vector fvec = GamePaths[path_num].pathnodes[next_node].pos - GamePaths[path_num].pathnodes[cur_node].pos;
878 vm_VectorToMatrix(&camera->orient, &fvec, NULL, NULL);
879 vm_Orthogonalize(&camera->orient);
880 ObjSetOrient(camera, &camera->orient);
881 }
882 }
883
884 continue_start:;
885 }
886
887 if (GameCinema.callback)
888 (*GameCinema.callback)(GCCT_START);
889
890 return true;
891 }
892
893 static inline bool Cinematic_IsPlayerDead(void) {
894 if (!Player_object || (Player_object->type == OBJ_GHOST) ||
895 (Player_object->type == OBJ_PLAYER &&
896 Players[Player_object->id].flags & (PLAYER_FLAGS_DYING | PLAYER_FLAGS_DEAD))) {
897 return true;
898 }
899 return false;
900 }
901
902 // Cinematic_Stop
903 //
904 // Stops and clears up a in-game cinematic.
905 void Cinematic_Stop(void) {
906 if (!Cinematic_inuse)
907 return;
908
909 if (GameCinema.text) {
910 mem_free(GameCinema.text);
911 GameCinema.text = NULL;
912 }
913
914 // tell the target object the cinematic is over
915 object *target = ObjGet(GameCinema.target_objhandle);
916
917 if (GameCinema.callback)
918 (*GameCinema.callback)(GCCT_STOP);
919
920 // reset things back to normal, anything that might be messed up
921 bool dont_restore_viewer = false;
922 if (GameCinema.flags & GCF_DONTRESTOREVIEWER) {
923 mprintf(0, "********NOT RESTORING VIEW TO PLAYER*************\n");
924 dont_restore_viewer = true;
925 }
926
927 if (!dont_restore_viewer) {
928 Viewer_object = Player_object;
929 }
930 Players[Player_object->id].controller_bitflags = 0xFFFFFFFF;
931 Player_object->flags |= OF_DESTROYABLE;
932 ResumeControls();
933
934 // go back to full screen
935 if (!Cinematic_IsPlayerDead() && GetScreenMode() == SM_GAME) // player death cam has started
936 SetHUDMode(Cinematic_GetOldHudMode());
937
938 if (GameCinema.bmp_handle > BAD_BITMAP_HANDLE) {
939 bm_FreeBitmap(GameCinema.bmp_handle);
940 }
941
942 // delete the camera
943 if (!dont_restore_viewer) {
944 object *cam = ObjGet(GameCinema.camera_objhandle);
945 if (cam) {
946 SetObjectDeadFlag(cam);
947 }
948 }
949
950 Cinematic_inuse = false;
951 HUDUnpauseMessages();
952 D3MusicStopCinematic();
953
954 // Start fade out transition
955 if (GameCinema.end_transition_type == GCTT_FADE) {
956 GameCinema.doing_end_transition = true;
957 GameCinema.end_transition_start_time = Gametime;
958 GameCinema.end_transition_end_time = Gametime + END_TRANSITION_TIME;
959 } else if (GameCinema.end_transition_type == GCTT_WACKY) {
960 // only start the wacky transition if it already hasn't (early break)
961 if (!GameCinema.doing_end_transition) {
962 GameCinema.doing_end_transition = true;
963 GameCinema.end_transition_start_time = Gametime - (END_TRANSITION_TIME / 2);
964 GameCinema.end_transition_end_time = Gametime + (END_TRANSITION_TIME / 2);
965 }
966 } else if (GameCinema.end_transition_type == GCTT_FADEINOUT) {
967 // only start if it already hasn't
968 if (!GameCinema.doing_end_transition) {
969 GameCinema.doing_end_transition = true;
970 GameCinema.end_transition_start_time = Gametime - (END_TRANSITION_TIME / 2);
971 GameCinema.end_transition_end_time = Gametime + (END_TRANSITION_TIME / 2);
972 }
973 } else if (GameCinema.end_transition_type == GCTT_FADEWHITE) {
974 if (!GameCinema.doing_end_transition) {
975 GameCinema.doing_end_transition = true;
976 GameCinema.end_transition_start_time = GameCinema.early_trans_end_start_time;
977 GameCinema.end_transition_end_time = GameCinema.end_time;
978 }
979 }
980
981 if (target) {
982 AINotify(target, AIN_MOVIE_END, NULL);
983
984 if (target->type == OBJ_PLAYER) {
985 tOSIRISEventInfo ei;
986 Osiris_CallLevelEvent(EVT_PLAYER_MOVIE_END, &ei);
987 }
988 }
989 }
990
991 bool Cinematic_IsKeyPressed(void) {
992 for (int i = 0; i < DDIO_MAX_KEYS; i++) {
993 if (ddio_InternalKeyState(i))
994 return true;
995 }
996
997 return false;
998 }
999
1000 // Cinematic_Frame
1001 //
1002 // Processes a frame for the Cinematics
1003 void Cinematic_Frame(void) {
1004 if (Cinematic_fake_queued) {
1005 Cinematic_PerformFake();
1006 }
1007
1008 if (!Cinematic_inuse) {
1009 return;
1010 }
1011
1012 // check to see if the player died somehow
1013 if ((!(GameCinema.flags & GCF_IGNOREPLAYERDEAD)) && Cinematic_IsPlayerDead()) {
1014 Cinematic_Stop();
1015 return;
1016 }
1017
1018 // check for end of cinematic
1019 if (Gametime > GameCinema.end_time) {
1020 Cinematic_Stop();
1021 return;
1022 }
1023
1024 // check for keyboard quick exit
1025 if (Gametime >= GameCinema.exit_start && Gametime <= GameCinema.exit_end) {
1026 if (Cinematic_IsKeyPressed()) {
1027 // a key has been pressed, quick exit!
1028 ddio_KeyFlush();
1029
1030 if (GameCinema.flags & GCF_FORCETARGETTOEND) {
1031 // move object to end of path
1032 object *target = ObjGet(GameCinema.target_objhandle);
1033 if (target && target->ai_info && target->ai_info->path.num_paths > 0) {
1034 bool shouldmove = true;
1035
1036 #if defined(_DEBUG) && defined(EDITOR)
1037 extern bool Game_being_played_from_quick_play;
1038
1039 if (Game_being_played_from_quick_play && target->type == OBJ_PLAYER) {
1040 shouldmove = false;
1041 }
1042 #endif
1043
1044 // its a target on a path
1045 matrix orient;
1046 vector pos;
1047 int room;
1048
1049 int currpath = target->ai_info->path.path_id[target->ai_info->path.cur_path];
1050 int endnode = GamePaths[currpath].num_nodes - 1;
1051
1052 vm_VectorToMatrix(&orient, &GamePaths[currpath].pathnodes[endnode].fvec,
1053 &GamePaths[currpath].pathnodes[endnode].uvec, NULL);
1054
1055 pos = GamePaths[currpath].pathnodes[endnode].pos;
1056 room = GamePaths[currpath].pathnodes[endnode].roomnum;
1057
1058 if (shouldmove) {
1059 ObjSetPos(target, &pos, room, &orient, true);
1060 }
1061 }
1062 }
1063 Cinematic_Stop();
1064 return;
1065 }
1066 }
1067
1068 object *camera = ObjGet(GameCinema.camera_objhandle);
1069 object *target = ObjGet(GameCinema.target_objhandle);
1070
1071 if (!target && GameCinema.flags & GCF_STOPIFTAGETDEAD) {
1072 Cinematic_Stop();
1073 return;
1074 }
1075
1076 // tell the target it's the focus of a cinematic
1077 if (target && !GameCinema.target_triggered) {
1078 GameCinema.target_triggered = true;
1079 AINotify(target, AIN_MOVIE_START, NULL);
1080
1081 if (target->type == OBJ_PLAYER) {
1082 tOSIRISEventInfo ei;
1083 Osiris_CallLevelEvent(EVT_PLAYER_MOVIE_START, &ei);
1084 }
1085 }
1086
1087 // check to see if we should be looking through the camera
1088 if (Gametime >= GameCinema.camera_start && Gametime <= GameCinema.camera_stop && camera != NULL) {
1089 // camera should be the viewer
1090 Viewer_object = camera;
1091 } else {
1092 Viewer_object = Player_object;
1093 }
1094
1095 // check to see if we should be disabling player controls
1096 if (Gametime >= GameCinema.player_start && Gametime <= GameCinema.player_stop) {
1097 // disable controls
1098 Players[Player_object->id].controller_bitflags = 0;
1099
1100 // make sure play controls are suspended
1101 if (!GameCinema.controls_suspended) {
1102 SuspendControls();
1103 GameCinema.controls_suspended = true;
1104 }
1105 } else {
1106 // make sure controls are enabled
1107 Players[Player_object->id].controller_bitflags = 0xFFFFFFFF;
1108
1109 // make sure play controls are enabled
1110 if (GameCinema.controls_suspended) {
1111 ResumeControls();
1112 GameCinema.controls_suspended = false;
1113 }
1114 }
1115
1116 // adjust view to target
1117 if (Gametime >= GameCinema.track_start && Gametime <= GameCinema.track_stop && target) {
1118 // track target
1119
1120 vector u_axis;
1121 angle goal_angle;
1122
1123 vector turn_to = target->pos - camera->pos;
1124 vm_NormalizeVector(&turn_to);
1125
1126 if (turn_to == Zero_vector) {
1127 mprintf(0, "Cine: No turn_to or less than 1 degree off goal\n");
1128 goto continue_frame;
1129 }
1130
1131 goal_angle = vm_DeltaAngVecNorm(&camera->orient.fvec, &turn_to, &u_axis);
1132 if (goal_angle == 0) {
1133 mprintf(0, "Cine: Goal angle is zero\n");
1134 goto continue_frame;
1135 }
1136
1137 camera->orient.fvec = turn_to;
1138
1139 camera->orient.uvec.x = camera->orient.uvec.z = 0.0f;
1140 camera->orient.uvec.y = 1.0f;
1141
1142 vm_Orthogonalize(&camera->orient);
1143 ObjSetOrient(camera, &camera->orient);
1144
1145 } else if ((GameCinema.flags & GCF_CAMERAPLACEMENT) == GCF_USEPATH) {
1146 // adjust to path node orientation (if we are on a path)
1147 int cur_path = camera->ai_info->path.cur_path;
1148 int cur_node = camera->ai_info->path.cur_node;
1149 int end_node = camera->ai_info->path.path_end_node[cur_path];
1150 int next_node = std::min(cur_node + 1, end_node);
1151 int path_num = camera->ai_info->path.path_id[cur_path];
1152
1153 if (cur_node != next_node) {
1154 vector fvec = GamePaths[path_num].pathnodes[next_node].pos - GamePaths[path_num].pathnodes[cur_node].pos;
1155 vm_VectorToMatrix(&camera->orient, &fvec, NULL, NULL);
1156 vm_Orthogonalize(&camera->orient);
1157 ObjSetOrient(camera, &camera->orient);
1158 }
1159 } else {
1160 // don't adjust at all
1161 }
1162
1163 continue_frame:
1164
1165 if (GameCinema.end_transition_type == GCTT_WACKY || GameCinema.end_transition_type == GCTT_FADEINOUT) {
1166 if (Gametime > GameCinema.early_trans_end_start_time && !GameCinema.doing_end_transition) {
1167 // start the transition early
1168 GameCinema.doing_end_transition = true;
1169 GameCinema.end_transition_start_time = Gametime;
1170 GameCinema.end_transition_end_time = Gametime + END_TRANSITION_TIME;
1171 }
1172 }
1173
1174 if (GameCinema.end_transition_type == GCTT_FADEWHITE) {
1175 if (Gametime > GameCinema.early_trans_end_start_time && !GameCinema.doing_end_transition) {
1176 // start the transition early
1177 GameCinema.doing_end_transition = true;
1178 GameCinema.end_transition_start_time = GameCinema.early_trans_end_start_time;
1179 GameCinema.end_transition_end_time = GameCinema.end_time;
1180 }
1181 }
1182 }
1183
1184 // Renders anything that needs to be rendered for the cinematic frame
1185 void Cinematic_RenderFrame(void) {
1186 if (!Cinematic_inuse) {
1187 if (GameCinema.doing_end_transition)
1188 Cinematic_DoEndTransition();
1189 return;
1190 }
1191
1192 if (GetHUDMode() == HUD_LETTERBOX) {
1193 // clear letterbox areas
1194 Clear_screen = 4;
1195 }
1196
1197 if (GameCinema.start_transition_type != GCTT_NONE) {
1198 Cinematic_DoStartTransition();
1199 }
1200
1201 if (GameCinema.flags & GCF_DOTRANSBEFORETEXT) {
1202 // some end transitions start early...process now
1203 if (GameCinema.doing_end_transition)
1204 Cinematic_DoEndTransition();
1205
1206 // see if we should be displaying text
1207 if (Gametime >= GameCinema.text_display_start && Gametime < GameCinema.text_display_stop) {
1208 // Display text
1209 Cinematic_DrawText();
1210 }
1211
1212 } else {
1213 // see if we should be displaying text
1214 if (Gametime >= GameCinema.text_display_start && Gametime < GameCinema.text_display_stop) {
1215 // Display text
1216 Cinematic_DrawText();
1217 }
1218
1219 // some end transitions start early...process now
1220 if (GameCinema.doing_end_transition)
1221 Cinematic_DoEndTransition();
1222 }
1223
1224 if (GameCinema.callback)
1225 (*GameCinema.callback)(GCCT_FRAME);
1226 }
1227
1228 void Cinematic_DrawText(void) {
1229 int font_height = grfont_GetHeight(BIG_BRIEFING_FONT) + 2;
1230 int old_font = grtext_GetFont();
1231 grtext_SetFont(BIG_BRIEFING_FONT);
1232 grtext_SetColor(GR_RGB(255, 255, 255));
1233
1234 int start_y;
1235 int end_y;
1236
1237 // determine y positions
1238 switch (GameCinema.flags & GCF_LAYOUT_MASK) {
1239 case GCF_LAYOUT_LOW: {
1240 end_y = 0.6667f * (float)(Max_window_h);
1241 start_y = end_y - (GameCinema.num_lines * font_height);
1242
1243 ASSERT(start_y >= 0); // too many lines of text!
1244
1245 } break;
1246 case GCF_LAYOUT_BOTTOM: {
1247 end_y = Max_window_h;
1248 start_y = end_y - (GameCinema.num_lines * font_height);
1249
1250 ASSERT(start_y >= 0); // too many lines of text!
1251 } break;
1252 case GCF_LAYOUT_TOP: {
1253 start_y = 2;
1254 end_y = (GameCinema.num_lines * font_height) + start_y;
1255
1256 ASSERT(end_y < Max_window_h); // too many lines of text!
1257 } break;
1258 case GCF_LAYOUT_MIDDLE: {
1259 int total_height = GameCinema.num_lines * font_height;
1260 start_y = (Max_window_h / 2) - (total_height / 2);
1261 end_y = start_y + total_height;
1262
1263 ASSERT(start_y >= 0 && end_y < Max_window_h); // too many lines of text
1264
1265 } break;
1266 }
1267
1268 if ((GameCinema.flags & GCF_TEXT_MASK) == GCF_TEXT_WIPEIN) {
1269 // see if this mode is allowed (only if letterbox and not in middle layout)
1270 if ((GameCinema.flags & GCF_SCREENFORMAT) != GCF_LETTERBOX) {
1271 GameCinema.flags &= ~GCF_TEXT_WIPEIN;
1272 GameCinema.flags |= GCF_TEXT_FADEINOUT;
1273 } else {
1274 // it's letter box, make sure it's not middle
1275 if ((GameCinema.flags & GCF_LAYOUT_MASK) == GCF_LAYOUT_MIDDLE) {
1276 GameCinema.flags &= ~GCF_TEXT_WIPEIN;
1277 GameCinema.flags |= GCF_TEXT_FADEINOUT;
1278 }
1279 if ((GameCinema.flags & GCF_LAYOUT_MASK) == GCF_LAYOUT_LOW) {
1280 GameCinema.flags &= ~GCF_TEXT_WIPEIN;
1281 GameCinema.flags |= GCF_TEXT_FADEINOUT;
1282 }
1283 }
1284 }
1285
1286 float total_text_time = GameCinema.text_display_stop - GameCinema.text_display_start;
1287 if (total_text_time <= 0.0f) {
1288 grtext_SetFont(old_font);
1289 return;
1290 }
1291
1292 float time_in = Gametime - GameCinema.text_display_start;
1293 float perc = time_in / total_text_time;
1294 if (perc < 0.0f)
1295 perc = 0.0f;
1296 if (perc > 1.0f)
1297 perc = 1.0f;
1298
1299 switch (GameCinema.flags & GCF_TEXT_MASK) {
1300 case GCF_TEXT_WIPEIN: {
1301 // first 1/3 is alpha in
1302 // last 2/3 is solid
1303 uint8_t alpha = 0;
1304
1305 if (perc > 0.33f) {
1306 // middle 1/3
1307 alpha = 255;
1308 } else if (perc <= 0.33f) {
1309 // first 1/3
1310 float new_p = perc / 0.33f;
1311 alpha = (uint8_t)(new_p * 255.0f);
1312 }
1313 grtext_SetAlpha(alpha);
1314
1315 int len, pos = 0;
1316 int y = start_y;
1317 for (int i = 0; i < GameCinema.num_lines; i++) {
1318 len = strlen(&GameCinema.text[pos]);
1319 grtext_CenteredPrintf(0, y, &GameCinema.text[pos]);
1320
1321 y += font_height;
1322 pos += len + 1;
1323 }
1324 grtext_Flush();
1325
1326 // Due alpha overlay effect
1327 if (GameCinema.bmp_handle > BAD_BITMAP_HANDLE) {
1328 float alphas[4] = {0.0f, 1.0f, 1.0f, 0.0f};
1329 float p = (perc > 0.18f) ? 1.0f : (perc / 0.18f);
1330
1331 int gl, gr, gt, gb;
1332 grtext_GetParameters(&gl, &gt, &gr, &gb, NULL);
1333
1334 int width = (1.0f - p) * GameCinema.longest_line;
1335 int rx = gl + (gr - gl) / 2 + (GameCinema.longest_line / 2);
1336 int lx = gl + rx - width;
1337
1338 rend_SetAlphaType(AT_VERTEX);
1339 rend_SetLighting(LS_NONE);
1340 rend_SetColorModel(CM_MONO);
1341 rend_SetOverlayType(OT_NONE);
1342 rend_SetFiltering(0);
1343 rend_SetWrapType(WT_CLAMP);
1344 rend_SetZBufferState(0);
1345
1346 int t_y, b_y;
1347 if ((GameCinema.flags & GCF_LAYOUT_MASK) == GCF_LAYOUT_TOP) {
1348 t_y = 0;
1349 b_y = Game_window_y;
1350 } else {
1351 t_y = Game_window_y + Game_window_h;
1352 b_y = Max_window_h;
1353 }
1354
1355 rend_DrawScaledBitmap(lx, t_y, rx, b_y, GameCinema.bmp_handle, 0, 0, 1, 1, -1, alphas);
1356
1357 rend_SetFiltering(1);
1358 rend_SetZBufferState(1);
1359 }
1360 } break;
1361 case GCF_TEXT_FADEINOUT: {
1362 // first 1/3 is alpha in
1363 // middle 1/3 is solid
1364 // last 1/3 is alpha out
1365 uint8_t alpha;
1366
1367 if (perc > 0.33f && perc <= 0.66f) {
1368 // middle 1/3
1369 alpha = 255;
1370 } else if (perc <= 0.33f) {
1371 // first 1/3
1372 float new_p = perc / 0.33f;
1373 alpha = (uint8_t)(new_p * 255.0f);
1374 } else {
1375 // last 1/3
1376 float new_p = (perc - 0.66f) / 0.33f;
1377 if (new_p < 0.0f)
1378 new_p = 0.0f;
1379 if (new_p > 1.0f)
1380 new_p = 1.0f;
1381 alpha = (uint8_t)(255.0f - (new_p * 255.0f));
1382 }
1383 grtext_SetAlpha(alpha);
1384
1385 int len, pos = 0;
1386 int y = start_y;
1387 for (int i = 0; i < GameCinema.num_lines; i++) {
1388 len = strlen(&GameCinema.text[pos]);
1389 grtext_CenteredPrintf(0, y, &GameCinema.text[pos]);
1390
1391 y += font_height;
1392 pos += len + 1;
1393 }
1394 grtext_Flush();
1395 } break;
1396 case GCF_TEXT_NOEFFECT: {
1397 int len, pos = 0;
1398 int y = start_y;
1399 for (int i = 0; i < GameCinema.num_lines; i++) {
1400 len = strlen(&GameCinema.text[pos]);
1401 grtext_CenteredPrintf(0, y, &GameCinema.text[pos]);
1402
1403 y += font_height;
1404 pos += len + 1;
1405 }
1406 grtext_Flush();
1407 } break;
1408 }
1409
1410 grtext_SetFont(old_font);
1411 }
1412
1413 void Cinematic_DoStartTransition(void) {
1414 if (GameCinema.start_transition_type == GCTT_NONE)
1415 return;
1416
1417 if (GameCinema.start_transition_start_time == -1.0f) {
1418 // calculate
1419 GameCinema.start_transition_start_time = Gametime;
1420 GameCinema.start_transition_end_time = Gametime + 2.0f;
1421 }
1422
1423 if (GameCinema.start_transition_end_time < Gametime)
1424 return;
1425
1426 float total_time = GameCinema.start_transition_end_time - GameCinema.start_transition_start_time;
1427 float time_in = Gametime - GameCinema.start_transition_start_time;
1428
1429 if (time_in < 0 || time_in > total_time)
1430 return;
1431
1432 float perc = time_in / total_time;
1433
1434 if (perc < 0.0f)
1435 perc = 0.0f;
1436 if (perc > 1.0f)
1437 perc = 1.0f;
1438
1439 if (gc_fade_bmp_handle <= BAD_BITMAP_HANDLE || gc_fadewhite_bmp_handle <= BAD_BITMAP_HANDLE) {
1440 GameCinema.start_transition_type = GCTT_NONE;
1441 return;
1442 }
1443
1444 float alpha = 1.0f - perc;
1445
1446 rend_SetAlphaType(AT_CONSTANT);
1447 rend_SetAlphaValue(alpha * 255.0f);
1448 rend_SetLighting(LS_NONE);
1449 rend_SetColorModel(CM_MONO);
1450 rend_SetOverlayType(OT_NONE);
1451 rend_SetWrapType(WT_CLAMP);
1452 rend_SetFiltering(0);
1453 rend_SetZBufferState(0);
1454
1455 rend_DrawScaledBitmap(
1456 0, 0, Max_window_w, Max_window_h,
1457 (GameCinema.start_transition_type == GCTT_FADEWHITE) ? gc_fadewhite_bmp_handle : gc_fade_bmp_handle, 0, 0, 1, 1);
1458
1459 rend_SetFiltering(1);
1460 rend_SetZBufferState(1);
1461 }
1462
1463 void Cinematic_DoEndTransition(void) {
1464 if (!GameCinema.doing_end_transition)
1465 return;
1466
1467 if (Gametime > GameCinema.end_transition_end_time) {
1468 GameCinema.doing_end_transition = false;
1469 return;
1470 }
1471
1472 if (Gametime < GameCinema.end_transition_start_time) {
1473 GameCinema.doing_end_transition = false;
1474 return;
1475 }
1476
1477 float time_in = Gametime - GameCinema.end_transition_start_time;
1478 float time_full = GameCinema.end_transition_end_time - GameCinema.end_transition_start_time;
1479 float perc = time_in / time_full;
1480
1481 if (perc < 0.0f)
1482 perc = 0.0f;
1483 if (perc > 1.0f)
1484 perc = 1.0f;
1485
1486 switch (GameCinema.end_transition_type) {
1487 case GCTT_WACKY: {
1488 if (gc_wacky_bmp_handle <= BAD_BITMAP_HANDLE) {
1489 GameCinema.doing_end_transition = false;
1490 return;
1491 }
1492 int w, h;
1493 w = bm_w(gc_wacky_bmp_handle, 0);
1494 h = bm_h(gc_wacky_bmp_handle, 0);
1495
1496 float wscale, hscale;
1497 wscale = (float)(Max_window_w) / (float)(w);
1498 hscale = (float)(Max_window_h) / (float)(h);
1499
1500 if (wscale < hscale) {
1501 float whratio = (float)(w) / (float)(h);
1502
1503 // width is bigger
1504 h = Max_window_h * whratio;
1505 w = Max_window_w;
1506 } else {
1507 float hwratio = (float)(h) / (float)(w);
1508
1509 // height is bigger
1510 h = Max_window_h;
1511 w = Max_window_w * hwratio;
1512 }
1513
1514 float ratio = 0.0f;
1515
1516 if (perc < 0.5f) {
1517 // small->large
1518 ratio = perc / 0.5f;
1519 } else {
1520 // large->small
1521 ratio = 1.0f - ((perc - 0.5f) / 0.5f);
1522 }
1523
1524 w *= ratio;
1525 h *= ratio;
1526
1527 int x, y;
1528
1529 x = (Max_window_w / 2) - (w / 2);
1530 y = (Max_window_h / 2) - (h / 2);
1531
1532 rend_SetAlphaType(AT_TEXTURE);
1533 rend_SetLighting(LS_NONE);
1534 rend_SetColorModel(CM_MONO);
1535 rend_SetOverlayType(OT_NONE);
1536 rend_SetWrapType(WT_CLAMP);
1537 rend_SetFiltering(0);
1538 rend_SetZBufferState(0);
1539
1540 rend_DrawScaledBitmap(x, y, x + w, y + h, gc_wacky_bmp_handle, 0, 0, 1, 1);
1541
1542 rend_SetFiltering(1);
1543 rend_SetZBufferState(1);
1544
1545 } break;
1546
1547 case GCTT_FADE: {
1548 if (gc_fade_bmp_handle <= BAD_BITMAP_HANDLE) {
1549 GameCinema.doing_end_transition = false;
1550 return;
1551 }
1552
1553 float alpha = 1.0f - perc;
1554
1555 rend_SetAlphaType(AT_CONSTANT);
1556 rend_SetAlphaValue(alpha * 255.0f);
1557 rend_SetLighting(LS_NONE);
1558 rend_SetColorModel(CM_MONO);
1559 rend_SetOverlayType(OT_NONE);
1560 rend_SetWrapType(WT_CLAMP);
1561 rend_SetFiltering(0);
1562 rend_SetZBufferState(0);
1563
1564 rend_DrawScaledBitmap(0, 0, Max_window_w, Max_window_h, gc_fade_bmp_handle, 0, 0, 1, 1);
1565
1566 rend_SetFiltering(1);
1567 rend_SetZBufferState(1);
1568
1569 } break;
1570
1571 case GCTT_FADEINOUT: {
1572 if (gc_fade_bmp_handle <= BAD_BITMAP_HANDLE) {
1573 GameCinema.doing_end_transition = false;
1574 return;
1575 }
1576
1577 float alpha = 0.0f;
1578
1579 if (perc < 0.5f) {
1580 // transparent->opaque
1581 alpha = perc / 0.5f;
1582 } else {
1583 // opaque->transparent
1584 alpha = 1.0f - ((perc - 0.5f) / 0.5f);
1585 }
1586
1587 rend_SetAlphaType(AT_CONSTANT);
1588 rend_SetAlphaValue(alpha * 255.0f);
1589 rend_SetLighting(LS_NONE);
1590 rend_SetColorModel(CM_MONO);
1591 rend_SetOverlayType(OT_NONE);
1592 rend_SetWrapType(WT_CLAMP);
1593 rend_SetFiltering(0);
1594 rend_SetZBufferState(0);
1595
1596 rend_DrawScaledBitmap(0, 0, Max_window_w, Max_window_h, gc_fade_bmp_handle, 0, 0, 1, 1);
1597
1598 rend_SetFiltering(1);
1599 rend_SetZBufferState(1);
1600
1601 } break;
1602 case GCTT_FADEWHITE: {
1603 if (gc_fade_bmp_handle <= BAD_BITMAP_HANDLE) {
1604 GameCinema.doing_end_transition = false;
1605 return;
1606 }
1607
1608 #define CUTOFF 0.8f
1609
1610 float alpha;
1611 bool use_white;
1612 if (perc < CUTOFF) {
1613 // to white
1614 alpha = perc / CUTOFF;
1615 use_white = true;
1616 } else {
1617 // to black
1618 alpha = 1.0f;
1619 use_white = false;
1620 }
1621
1622 rend_SetAlphaType(AT_CONSTANT);
1623 rend_SetAlphaValue(alpha * 255.0f);
1624 rend_SetLighting(LS_NONE);
1625 rend_SetColorModel(CM_MONO);
1626 rend_SetOverlayType(OT_NONE);
1627 rend_SetWrapType(WT_CLAMP);
1628 rend_SetFiltering(0);
1629 rend_SetZBufferState(0);
1630
1631 if (use_white) {
1632 rend_DrawScaledBitmap(0, 0, Max_window_w, Max_window_h, gc_fadewhite_bmp_handle, 0, 0, 1, 1);
1633 } else {
1634 if (gc_temp_bmp_handle > BAD_BITMAP_HANDLE) {
1635 float fade_out_perc = 1.0f - ((perc - CUTOFF) / (1.0f - CUTOFF));
1636 int grey = 255.0f * fade_out_perc;
1637 uint16_t *data = bm_data(gc_temp_bmp_handle, 0);
1638 int i, size = 32 * 32;
1639
1640 for (i = 0; i < size; i++)
1641 data[i] = GR_RGB16(grey, grey, grey) | OPAQUE_FLAG;
1642
1643 GameBitmaps[gc_temp_bmp_handle].flags |= BF_CHANGED;
1644
1645 rend_DrawScaledBitmap(0, 0, Max_window_w, Max_window_h, gc_temp_bmp_handle, 0, 0, 1, 1);
1646 }
1647 }
1648
1649 rend_SetFiltering(1);
1650 rend_SetZBufferState(1);
1651
1652 } break;
1653
1654 case GCTT_NONE:
1655 GameCinema.doing_end_transition = false;
1656 return;
1657 break;
1658 }
1659 }
1660
1661 float Cine_GetPathTravelSpeed(int pathnum, float time) {
1662 float velocity_to_use = 75.0f;
1663
1664 // determine velocity based on distance to travel on path
1665 int num_nodes = GamePaths[pathnum].num_nodes;
1666 float distance;
1667 distance = 0;
1668
1669 for (int n = 0; n < num_nodes - 1; n++) {
1670 distance += vm_VectorDistance(&GamePaths[pathnum].pathnodes[n].pos, &GamePaths[pathnum].pathnodes[n + 1].pos);
1671 }
1672
1673 if (time > 0)
1674 velocity_to_use = distance / time;
1675
1676 return velocity_to_use;
1677 }
1678
1679 /*
1680 ***********************************************************************
1681 Intro Movie Canned Cinematic
1682 ***********************************************************************
1683 */
1684
1685 struct {
1686 int player_path;
1687 float cinematic_time;
1688 bool should_thrust;
1689 } CannedCinematicIntro;
1690
1691 void CannedCinematicIntroCallback(int type) {
1692 switch (type) {
1693 case GCCT_START: {
1694 // start the player on the path
1695 mprintf(0, "START PLAYER ON PATH\n");
1696
1697 // determine how fast they need to travel
1698 int pathnum = CannedCinematicIntro.player_path;
1699 float velocity = Cine_GetPathTravelSpeed(pathnum, CannedCinematicIntro.cinematic_time);
1700
1701 SuspendControls();
1702
1703 if (Players[Player_num].objnum > -1) {
1704 object *playerobj = &Objects[Players[Player_num].objnum];
1705 ClearPlayerFiring(playerobj, PW_PRIMARY);
1706 ClearPlayerFiring(playerobj, PW_SECONDARY);
1707 }
1708
1709 PlayerSetControlToAI(Player_num, velocity);
1710
1711 // move the target (player) to the first node of the path
1712 // this makes it multiplayer friendly since this will only be called
1713 // in a single player game
1714 vector pos;
1715 matrix orient;
1716 int roomnum;
1717 int next_node;
1718
1719 if (pathnum == -1) {
1720 mprintf(0, "ILLEGAL PATH FOR PLAYER\n");
1721 break;
1722 }
1723
1724 if (GamePaths[pathnum].num_nodes > 1) {
1725 next_node = 1;
1726 vector fvec = GamePaths[pathnum].pathnodes[1].pos - GamePaths[pathnum].pathnodes[0].pos;
1727 vm_VectorToMatrix(&orient, &fvec, NULL, NULL);
1728
1729 // see if it is a hacked 2 node path (i.e. its such a small distance he should move
1730 if (GamePaths[pathnum].num_nodes == 2) {
1731 if (fabs(vm_VectorDistance(&GamePaths[pathnum].pathnodes[1].pos, &GamePaths[pathnum].pathnodes[0].pos)) >
1732 30.0f) {
1733 CannedCinematicIntro.should_thrust = true;
1734 mprintf(0, "Player should thrust\n");
1735 } else {
1736 CannedCinematicIntro.should_thrust = false;
1737 mprintf(0, "Player should NOT thrust\n");
1738 }
1739 } else {
1740 CannedCinematicIntro.should_thrust = true;
1741 mprintf(0, "Player should thrust\n");
1742 }
1743 } else {
1744 next_node = 0;
1745 CannedCinematicIntro.should_thrust = false;
1746 mprintf(0, "Player should NOT thrust\n");
1747 vm_VectorToMatrix(&orient, &GamePaths[pathnum].pathnodes[0].fvec, &GamePaths[pathnum].pathnodes[0].uvec, NULL);
1748 }
1749 pos = GamePaths[pathnum].pathnodes[0].pos;
1750 roomnum = GamePaths[pathnum].pathnodes[0].roomnum;
1751
1752 ObjSetPos(Player_object, &pos, roomnum, &orient, true);
1753
1754 if (CannedCinematicIntro.should_thrust) {
1755 // Set up path info
1756 path_information pi;
1757 pi.path_id = pathnum;
1758 pi.start_node = 0;
1759 pi.next_node = next_node;
1760 pi.end_node = GamePaths[pathnum].num_nodes - 1;
1761
1762 // Make the player follow the path
1763 GoalAddGoal(Player_object, AIG_FOLLOW_PATH, (void *)&pi, 0, 1.0f, GF_ORIENT_PATH_NODE | GF_FORCE_AWARENESS);
1764 }
1765 } break;
1766 case GCCT_STOP: {
1767 // stop the player on the path
1768 mprintf(0, "STOP PLAYER ON PATH\n");
1769 ResetPlayerControlType(Player_num);
1770 ResumeControls();
1771
1772 vm_MakeZero(&Player_object->mtype.phys_info.velocity);
1773
1774 Players[Player_num].flags &= ~PLAYER_FLAGS_THRUSTED;
1775
1776 } break;
1777 case GCCT_FRAME: {
1778 if (CannedCinematicIntro.should_thrust)
1779 Players[Player_num].flags |= PLAYER_FLAGS_THRUSTED;
1780 else
1781 Players[Player_num].flags &= ~PLAYER_FLAGS_THRUSTED;
1782 } break;
1783 }
1784 }
1785
1786 void CannedCinematic_Intro(int PathID, const char *Text, int PlayerPath, float Seconds, int camera_handle) {
1787 CannedCinematicIntro.player_path = PlayerPath;
1788 CannedCinematicIntro.cinematic_time = Seconds;
1789
1790 tGameCinematic info;
1791 info.flags = 0;
1792 info.flags = (GCF_LETTERBOX | GCF_USEPATH | GCF_TEXT_FADEINOUT | GCF_LAYOUT_BOTTOM | GCF_FORCETARGETTOEND);
1793 info.target_objhandle = Player_object->handle;
1794 info.max_time_play = Seconds;
1795 info.callback = CannedCinematicIntroCallback;
1796 info.text_display.min = 0.40f;
1797 info.text_display.max = 0.80f;
1798 info.track_target.min = 0.0f;
1799 info.track_target.max = 1.0f;
1800 info.player_disabled.min = 0.0f;
1801 info.player_disabled.max = 1.0f;
1802 info.in_camera_view.min = 0.0f;
1803 info.in_camera_view.max = 1.0f;
1804 info.quick_exit.min = 0.25f;
1805 info.quick_exit.max = 1.0f;
1806
1807 info.end_transition = GCTT_FADEINOUT;
1808 info.start_transition = GCTT_FADE;
1809 info.pathid = PathID;
1810
1811 Cinematic_StartCine(&info, Text, camera_handle);
1812 }
1813
1814 struct {
1815 int player_path;
1816 float cinematic_time;
1817 bool should_thrust;
1818 } CannedCinematicEndLevel;
1819 extern bool EndLevel();
1820
1821 void CannedCinematicEndLevelCallback(int type) {
1822 switch (type) {
1823 case GCCT_START: {
1824 // if the player is dead, bring them back from the dead
1825 if ((Players[Player_num].flags & PLAYER_FLAGS_DYING) || (Players[Player_num].flags & PLAYER_FLAGS_DEAD)) {
1826 // the player is currently dead
1827 mprintf(0, "Bringing player back from the dead\n");
1828 Players[Player_num].flags &= ~(PLAYER_FLAGS_DYING | PLAYER_FLAGS_DEAD);
1829 Player_object->shields = 1.0f;
1830 }
1831
1832 // Make player invulnerable
1833 MakePlayerInvulnerable(Player_num, CannedCinematicEndLevel.cinematic_time, false);
1834
1835 // start the player on the path
1836 mprintf(0, "START PLAYER ON PATH\n");
1837
1838 // determine how fast they need to travel
1839 int pathnum = CannedCinematicEndLevel.player_path;
1840
1841 if (pathnum == -1) {
1842 mprintf(0, "ILLEGAL PATH FOR PLAYER\n");
1843 break;
1844 }
1845
1846 float velocity = Cine_GetPathTravelSpeed(pathnum, CannedCinematicEndLevel.cinematic_time);
1847
1848 SuspendControls();
1849 if (Players[Player_num].objnum > -1) {
1850 object *playerobj = &Objects[Players[Player_num].objnum];
1851 ClearPlayerFiring(playerobj, PW_PRIMARY);
1852 ClearPlayerFiring(playerobj, PW_SECONDARY);
1853 }
1854
1855 PlayerSetControlToAI(Player_num, velocity);
1856
1857 // move the target (player) to the first node of the path
1858 // this makes it multiplayer friendly since this will only be called
1859 // in a single player game
1860 vector pos;
1861 matrix orient;
1862 int roomnum;
1863 int next_node;
1864
1865 if (GamePaths[pathnum].num_nodes > 1) {
1866 next_node = 1;
1867 vector fvec = GamePaths[pathnum].pathnodes[1].pos - GamePaths[pathnum].pathnodes[0].pos;
1868 vm_VectorToMatrix(&orient, &fvec, NULL, NULL);
1869
1870 if (GamePaths[pathnum].num_nodes == 2) {
1871 if (fabs(vm_VectorDistance(&GamePaths[pathnum].pathnodes[1].pos, &GamePaths[pathnum].pathnodes[0].pos)) >
1872 30.0f) {
1873 CannedCinematicEndLevel.should_thrust = true;
1874 } else {
1875 CannedCinematicEndLevel.should_thrust = false;
1876 }
1877 } else {
1878 CannedCinematicEndLevel.should_thrust = true;
1879 }
1880 } else {
1881 next_node = 0;
1882 vm_VectorToMatrix(&orient, &GamePaths[pathnum].pathnodes[0].fvec, &GamePaths[pathnum].pathnodes[0].uvec, NULL);
1883 CannedCinematicEndLevel.should_thrust = false;
1884 }
1885 pos = GamePaths[pathnum].pathnodes[0].pos;
1886 roomnum = GamePaths[pathnum].pathnodes[0].roomnum;
1887
1888 ObjSetPos(Player_object, &pos, roomnum, &orient, true);
1889
1890 if (CannedCinematicEndLevel.should_thrust) {
1891
1892 // Set up path info
1893 path_information pi;
1894 pi.path_id = pathnum;
1895 pi.start_node = 0;
1896 pi.next_node = next_node;
1897 pi.end_node = GamePaths[pathnum].num_nodes - 1;
1898
1899 // Make the player follow the path
1900 GoalAddGoal(Player_object, AIG_FOLLOW_PATH, (void *)&pi, 0, 1.0f, GF_ORIENT_PATH_NODE | GF_FORCE_AWARENESS);
1901 }
1902 } break;
1903 case GCCT_STOP: {
1904 // stop the player on the path
1905 mprintf(0, "STOP PLAYER ON PATH\n");
1906 ResetPlayerControlType(Player_num);
1907 ResumeControls();
1908
1909 vm_MakeZero(&Player_object->mtype.phys_info.velocity);
1910
1911 SetGameState(GAMESTATE_LVLEND);
1912 } break;
1913 case GCCT_FRAME: {
1914 if (CannedCinematicEndLevel.should_thrust)
1915 Players[Player_num].flags |= PLAYER_FLAGS_THRUSTED;
1916 else
1917 Players[Player_num].flags &= ~PLAYER_FLAGS_THRUSTED;
1918 } break;
1919 }
1920 }
1921
1922 void CannedCinematic_EndLevelPath(int PathID, const char *Text, int PlayerPath, float Seconds, int camera_handle) {
1923 CannedCinematicEndLevel.player_path = PlayerPath;
1924 CannedCinematicEndLevel.cinematic_time = Seconds;
1925
1926 tGameCinematic info;
1927 info.flags = 0;
1928 info.flags = (GCF_LETTERBOX | GCF_USEPATH | GCF_TEXT_WIPEIN | GCF_LAYOUT_BOTTOM | GCF_FORCETARGETTOEND |
1929 GCF_DONTRESTOREVIEWER);
1930 info.target_objhandle = Player_object->handle;
1931 info.max_time_play = Seconds;
1932 info.callback = CannedCinematicEndLevelCallback;
1933 info.text_display.min = 0.40f;
1934 info.text_display.max = 0.80f;
1935 info.track_target.min = 0.0f;
1936 info.track_target.max = 1.0f;
1937 info.player_disabled.min = 0.0f;
1938 info.player_disabled.max = 1.0f;
1939 info.in_camera_view.min = 0.0f;
1940 info.in_camera_view.max = 1.0f;
1941 info.quick_exit.min = 1.0f;
1942 info.quick_exit.max = 1.0f;
1943
1944 info.end_transition = GCTT_FADEINOUT;
1945 info.start_transition = GCTT_FADE;
1946 info.pathid = PathID;
1947
1948 Cinematic_StartCine(&info, Text, camera_handle);
1949 }
1950
1951 void CannedCinematic_EndLevelPoint(vector *pos, int room, const char *Text, int PlayerPath, float Seconds,
1952 int camera_handle) {
1953 CannedCinematicEndLevel.player_path = PlayerPath;
1954 CannedCinematicEndLevel.cinematic_time = Seconds;
1955
1956 tGameCinematic info;
1957 info.flags = 0;
1958 info.flags = (GCF_LETTERBOX | GCF_USEPOINT | GCF_TEXT_WIPEIN | GCF_LAYOUT_BOTTOM | GCF_FORCETARGETTOEND |
1959 GCF_DONTRESTOREVIEWER);
1960 info.target_objhandle = Player_object->handle;
1961 info.max_time_play = Seconds;
1962 info.callback = CannedCinematicEndLevelCallback;
1963 info.text_display.min = 0.40f;
1964 info.text_display.max = 0.80f;
1965 info.track_target.min = 0.0f;
1966 info.track_target.max = 1.0f;
1967 info.player_disabled.min = 0.0f;
1968 info.player_disabled.max = 1.0f;
1969 info.in_camera_view.min = 0.0f;
1970 info.in_camera_view.max = 1.0f;
1971 info.quick_exit.min = 1.0f;
1972 info.quick_exit.max = 1.0f;
1973 info.end_transition = GCTT_FADEINOUT;
1974 info.start_transition = GCTT_FADE;
1975
1976 info.position = *pos;
1977 info.room = room;
1978 info.orient = NULL;
1979
1980 Cinematic_StartCine(&info, Text, camera_handle);
1981 }
1982
1983 struct {
1984 object *player;
1985 int room;
1986 vector pos;
1987 matrix orient;
1988 } CannedCinematicMovePlayerFade;
1989
1990 void CannedCinematicMovePlayerFadeCallback(int type) {
1991 switch (type) {
1992 case GCCT_FRAME:
1993 object *player = CannedCinematicMovePlayerFade.player;
1994 ObjSetPos(player, &CannedCinematicMovePlayerFade.pos, CannedCinematicMovePlayerFade.room,
1995 &CannedCinematicMovePlayerFade.orient, true);
1996 break;
1997 }
1998 }
1999
2000 void CannedCinematic_MovePlayerFade(object *player, int room, vector *pos, matrix *orient, int camera_handle) {
2001 CannedCinematicMovePlayerFade.player = player;
2002 CannedCinematicMovePlayerFade.room = room;
2003 CannedCinematicMovePlayerFade.pos = *pos;
2004 CannedCinematicMovePlayerFade.orient = *orient;
2005
2006 tGameCinematic info;
2007 info.flags = 0;
2008 info.flags = (GCF_FULLSCREEN | GCF_USEPOINT | GCF_TEXT_NOEFFECT | GCF_LAYOUT_BOTTOM);
2009 info.target_objhandle = OBJECT_HANDLE_NONE;
2010 info.max_time_play = 1.0f;
2011 info.callback = CannedCinematicMovePlayerFadeCallback;
2012 info.text_display.min = 1.0f;
2013 info.text_display.max = 1.0f;
2014 info.track_target.min = 1.0f;
2015 info.track_target.max = 1.0f;
2016 info.player_disabled.min = 1.0f;
2017 info.player_disabled.max = 1.0f;
2018 info.in_camera_view.min = 0.0f;
2019 info.in_camera_view.max = 1.0f;
2020 info.quick_exit.min = 1.0f;
2021 info.quick_exit.max = 1.0f;
2022 info.end_transition = GCTT_FADEINOUT;
2023 info.start_transition = GCTT_NONE;
2024
2025 info.position = player->pos;
2026 info.room = player->roomnum;
2027 info.orient = &player->orient;
2028
2029 Cinematic_StartCine(&info, "", camera_handle);
2030 }
2031
2032 struct {
2033 float start_time;
2034 float max_time;
2035 } CannedCinematicLevelEndFadeWhite;
2036
2037 void CannedCinematicLevelEndFadeWhiteCallback(int type) {
2038 switch (type) {
2039 case GCCT_START:
2040 break;
2041 case GCCT_FRAME:
2042 break;
2043 case GCCT_STOP:
2044 SetGameState(GAMESTATE_LVLEND);
2045 break;
2046 }
2047 }
2048
2049 void CannedCinematic_LevelEndFadeWhite(int camera_handle, float time, const char *text_to_display) {
2050 CannedCinematicLevelEndFadeWhite.start_time = Gametime;
2051 CannedCinematicLevelEndFadeWhite.max_time = time;
2052
2053 tGameCinematic info;
2054 info.flags = (GCF_LETTERBOX | GCF_USEPOINT | GCF_TEXT_NOEFFECT | GCF_LAYOUT_MIDDLE | GCF_DONTRESTOREVIEWER |
2055 GCF_IGNOREPLAYERDEAD | GCF_DOTRANSBEFORETEXT);
2056 info.target_objhandle = OBJECT_HANDLE_NONE;
2057 info.max_time_play = time;
2058 info.callback = CannedCinematicLevelEndFadeWhiteCallback;
2059 info.text_display.min = 0.0f;
2060 info.text_display.max = 1.0f;
2061 info.track_target.min = 1.0f;
2062 info.track_target.max = 1.0f;
2063 info.player_disabled.min = 1.0f;
2064 info.player_disabled.max = 1.0f;
2065 info.in_camera_view.min = 1.0f;
2066 info.in_camera_view.max = 1.0f;
2067 info.quick_exit.min = 1.0f;
2068 info.quick_exit.max = 1.0f;
2069 info.end_transition = GCTT_FADEWHITE;
2070 info.start_transition = GCTT_NONE;
2071
2072 info.position = Player_object->pos;
2073 info.room = Player_object->roomnum;
2074 info.orient = &Player_object->orient;
2075
2076 Cinematic_StartCine(&info, (text_to_display) ? text_to_display : "", camera_handle);
2077 }
2078
2079 //==============================================================================
2080 // Canned Cinematic interface
2081
2082 void Cinematic_DoFakeCannedCinematics(tCannedCinematicInfo *info) {
2083 switch (info->type) {
2084 case CANNED_LEVEL_INTRO:
2085 break;
2086 case CANNED_LEVEL_END_PATH:
2087 case CANNED_LEVEL_END_POINT:
2088 case CANNED_LEVEL_END_FADE_WHITE:
2089 if (Game_mode & GM_MULTI) {
2090 MultiEndLevel();
2091 } else {
2092 SetGameState(GAMESTATE_LVLEND);
2093 }
2094 break;
2095 case CANNED_MOVE_PLAYER_FADE:
2096 break;
2097 }
2098 }
2099
2100 void Cinematic_StartCannedScript(tCannedCinematicInfo *info) {
2101 if (Demo_flags == DF_PLAYBACK)
2102 return; // demo system calls Cinematic_StartCanned itself
2103
2104 Cinematic_StartCanned(info);
2105 }
2106
2107 void Cinematic_StartCanned(tCannedCinematicInfo *info, int camera_handle) {
2108 if (Cinematic_inuse) {
2109 tGameCinematic gc;
2110 memset(&gc, 0, sizeof(tGameCinematic));
2111 switch (info->type) {
2112 case CANNED_LEVEL_INTRO:
2113 case CANNED_LEVEL_END_PATH:
2114 case CANNED_LEVEL_END_POINT:
2115 case CANNED_MOVE_PLAYER_FADE:
2116 case CANNED_LEVEL_END_FADE_WHITE:
2117 gc.target_objhandle = Player_object->handle;
2118 break;
2119 default: {
2120 gc.target_objhandle = OBJECT_HANDLE_NONE;
2121 } break;
2122 }
2123
2124 Cinematic_SetForFakeCinematic(&gc);
2125 Cinematic_DoFakeCannedCinematics(info);
2126 if (camera_handle != -1)
2127 Cinematic_DeleteCamera(camera_handle);
2128 return;
2129 }
2130
2131 if (Game_mode & GM_MULTI) {
2132 tGameCinematic gc;
2133 memset(&gc, 0, sizeof(tGameCinematic));
2134 switch (info->type) {
2135 case CANNED_LEVEL_INTRO:
2136 case CANNED_LEVEL_END_PATH:
2137 case CANNED_LEVEL_END_POINT:
2138 case CANNED_MOVE_PLAYER_FADE:
2139 case CANNED_LEVEL_END_FADE_WHITE:
2140 gc.target_objhandle = Player_object->handle;
2141 break;
2142 default: {
2143 gc.target_objhandle = OBJECT_HANDLE_NONE;
2144 } break;
2145 }
2146
2147 Cinematic_SetForFakeCinematic(&gc);
2148 Cinematic_DoFakeCannedCinematics(info);
2149 if (camera_handle != -1)
2150 Cinematic_DeleteCamera(camera_handle);
2151 return; // no cinematics in multiplayer
2152 }
2153
2154 if (camera_handle == -1) {
2155 // when playing back a demo, this should have a value
2156 ASSERT(Demo_flags != DF_PLAYBACK);
2157 camera_handle = Cinematics_CreateCamera();
2158 }
2159
2160 if (Demo_flags == DF_RECORDING) {
2161 tCinematicDemoInfo demo_data;
2162 demo_data.cinematic_type = CDI_CANNED;
2163 demo_data.text_string = NULL;
2164 demo_data.canned_data = info;
2165 demo_data.camera_objhandle = camera_handle;
2166 Cinematic_WriteDemoFileData(&demo_data);
2167 }
2168
2169 switch (info->type) {
2170 case CANNED_LEVEL_INTRO:
2171 CannedCinematic_Intro(info->camera_pathid, info->text_to_display, info->target_pathid, info->time, camera_handle);
2172 break;
2173 case CANNED_LEVEL_END_PATH:
2174 CannedCinematic_EndLevelPath(info->camera_pathid, info->text_to_display, info->target_pathid, info->time,
2175 camera_handle);
2176 break;
2177 case CANNED_LEVEL_END_POINT: {
2178 object *cam = ObjGet(info->object_to_use_for_point);
2179 if (cam) {
2180 CannedCinematic_EndLevelPoint(&cam->pos, cam->roomnum, info->text_to_display, info->target_pathid, info->time,
2181 camera_handle);
2182 } else {
2183 mprintf(0, "Passed in object handle for canned cinematic (level end) for camera position does not exist\n");
2184 Cinematic_DeleteCamera(camera_handle);
2185 SetGameState(GAMESTATE_LVLEND);
2186 }
2187 } break;
2188 case CANNED_MOVE_PLAYER_FADE: {
2189 object *player = ObjGet(info->target_objhandle);
2190 if (!player || player->type != OBJ_PLAYER) {
2191 mprintf(0, "Invalid player passed to CANNED_MOVE_PLAYER_FADE\n");
2192 Cinematic_DeleteCamera(camera_handle);
2193 return;
2194 }
2195
2196 CannedCinematic_MovePlayerFade(player, info->room, &info->pos, &info->orient, camera_handle);
2197
2198 } break;
2199 case CANNED_LEVEL_END_FADE_WHITE: {
2200 CannedCinematic_LevelEndFadeWhite(camera_handle, info->time, info->text_to_display);
2201 } break;
2202 default: {
2203 Cinematic_DeleteCamera(camera_handle);
2204 } break;
2205 }
2206 }
2207
2208 //==================================================
2209 // Demo file support
2210 //==================================================
2211 static void mf_WriteInt(uint8_t *buffer, int *pointer, int data);
2212 static void mf_WriteShort(uint8_t *buffer, int *pointer, int16_t data);
2213 static void mf_WriteByte(uint8_t *buffer, int *pointer, uint8_t data);
2214 static void mf_WriteFloat(uint8_t *buffer, int *pointer, float data);
2215 static void mf_WriteBytes(uint8_t *buffer, int *pointer, uint8_t *data, int len);
2216 static void mf_WriteString(uint8_t *buffer, int *pointer, const char *string);
2217 static int mf_ReadInt(uint8_t *buffer, int *pointer);
2218 static int16_t mf_ReadShort(uint8_t *buffer, int *pointer);
2219 static uint8_t mf_ReadByte(uint8_t *buffer, int *pointer);
2220 static float mf_ReadFloat(uint8_t *buffer, int *pointer);
2221 static void mf_ReadBytes(uint8_t *buffer, int *pointer, uint8_t *data, int len);
2222 static void mf_ReadString(uint8_t *buffer, int *pointer, char *string);
2223
2224 void Cinematic_DoDemoFileData(uint8_t *buffer) {
2225 int count = 0;
2226 char text_string[512];
2227 tCannedCinematicInfo canned_data;
2228 tGameCinematic cinematic_data;
2229 int old_camera_objnum, camera_objnum, camera_handle;
2230
2231 // see what kind of cinematic we are loading
2232 switch (mf_ReadByte(buffer, &count)) {
2233 case CDI_NOT_CANNED: {
2234 matrix fake_orient;
2235 vm_MakeIdentity(&fake_orient);
2236
2237 cinematic_data.orient = &fake_orient;
2238 cinematic_data.callback = NULL;
2239 cinematic_data.flags = mf_ReadInt(buffer, &count);
2240 cinematic_data.target_objhandle = mf_ReadInt(buffer, &count);
2241 cinematic_data.end_transition = mf_ReadInt(buffer, &count);
2242 cinematic_data.start_transition = mf_ReadInt(buffer, &count);
2243 cinematic_data.pathid = mf_ReadInt(buffer, &count);
2244 cinematic_data.position.x = mf_ReadFloat(buffer, &count);
2245 cinematic_data.position.y = mf_ReadFloat(buffer, &count);
2246 cinematic_data.position.z = mf_ReadFloat(buffer, &count);
2247 cinematic_data.room = mf_ReadInt(buffer, &count);
2248 if (mf_ReadByte(buffer, &count)) {
2249 fake_orient.fvec.x = mf_ReadFloat(buffer, &count);
2250 fake_orient.fvec.y = mf_ReadFloat(buffer, &count);
2251 fake_orient.fvec.z = mf_ReadFloat(buffer, &count);
2252 fake_orient.uvec.x = mf_ReadFloat(buffer, &count);
2253 fake_orient.uvec.y = mf_ReadFloat(buffer, &count);
2254 fake_orient.uvec.z = mf_ReadFloat(buffer, &count);
2255 fake_orient.rvec.x = mf_ReadFloat(buffer, &count);
2256 fake_orient.rvec.y = mf_ReadFloat(buffer, &count);
2257 fake_orient.rvec.z = mf_ReadFloat(buffer, &count);
2258 }
2259
2260 cinematic_data.max_time_play = mf_ReadFloat(buffer, &count);
2261 cinematic_data.text_display.max = mf_ReadFloat(buffer, &count);
2262 cinematic_data.text_display.min = mf_ReadFloat(buffer, &count);
2263 cinematic_data.track_target.max = mf_ReadFloat(buffer, &count);
2264 cinematic_data.track_target.min = mf_ReadFloat(buffer, &count);
2265 cinematic_data.player_disabled.max = mf_ReadFloat(buffer, &count);
2266 cinematic_data.player_disabled.min = mf_ReadFloat(buffer, &count);
2267 cinematic_data.in_camera_view.max = mf_ReadFloat(buffer, &count);
2268 cinematic_data.in_camera_view.min = mf_ReadFloat(buffer, &count);
2269 cinematic_data.quick_exit.max = mf_ReadFloat(buffer, &count);
2270 cinematic_data.quick_exit.min = mf_ReadFloat(buffer, &count);
2271 mf_ReadString(buffer, &count, text_string);
2272
2273 old_camera_objnum = mf_ReadInt(buffer, &count);
2274 ASSERT(old_camera_objnum >= 0 && old_camera_objnum < MAX_OBJECTS);
2275 camera_objnum = Demo_obj_map[old_camera_objnum];
2276 ASSERT(camera_objnum >= 0 && camera_objnum < MAX_OBJECTS && Objects[camera_objnum].type == OBJ_CAMERA);
2277 camera_handle = Objects[camera_objnum].handle;
2278
2279 Cinematic_StartCine(&cinematic_data, text_string, camera_handle);
2280
2281 } break;
2282 case CDI_CANNED: {
2283 canned_data.type = mf_ReadInt(buffer, &count);
2284 canned_data.camera_pathid = mf_ReadInt(buffer, &count);
2285 canned_data.target_pathid = mf_ReadInt(buffer, &count);
2286 canned_data.target_objhandle = mf_ReadInt(buffer, &count);
2287 canned_data.time = mf_ReadFloat(buffer, &count);
2288 canned_data.object_to_use_for_point = mf_ReadInt(buffer, &count);
2289 canned_data.room = mf_ReadInt(buffer, &count);
2290 canned_data.pos.x = mf_ReadFloat(buffer, &count);
2291 canned_data.pos.y = mf_ReadFloat(buffer, &count);
2292 canned_data.pos.z = mf_ReadFloat(buffer, &count);
2293 canned_data.orient.fvec.x = mf_ReadFloat(buffer, &count);
2294 canned_data.orient.fvec.y = mf_ReadFloat(buffer, &count);
2295 canned_data.orient.fvec.z = mf_ReadFloat(buffer, &count);
2296 canned_data.orient.uvec.x = mf_ReadFloat(buffer, &count);
2297 canned_data.orient.uvec.y = mf_ReadFloat(buffer, &count);
2298 canned_data.orient.uvec.z = mf_ReadFloat(buffer, &count);
2299 canned_data.orient.rvec.x = mf_ReadFloat(buffer, &count);
2300 canned_data.orient.rvec.y = mf_ReadFloat(buffer, &count);
2301 canned_data.orient.rvec.z = mf_ReadFloat(buffer, &count);
2302
2303 mf_ReadString(buffer, &count, text_string);
2304 canned_data.text_to_display = text_string;
2305
2306 old_camera_objnum = mf_ReadInt(buffer, &count);
2307 ASSERT(old_camera_objnum >= 0 && old_camera_objnum < MAX_OBJECTS);
2308 camera_objnum = Demo_obj_map[old_camera_objnum];
2309 ASSERT(camera_objnum >= 0 && camera_objnum < MAX_OBJECTS && Objects[camera_objnum].type == OBJ_CAMERA);
2310 camera_handle = Objects[camera_objnum].handle;
2311
2312 Cinematic_StartCanned(&canned_data, camera_handle);
2313
2314 } break;
2315 }
2316 }
2317
2318 void Cinematic_WriteDemoFileData(tCinematicDemoInfo *info) {
2319 uint8_t buffer[1500];
2320 int count = 0;
2321
2322 // what kind of cinematic are we saving
2323 mf_WriteByte(buffer, &count, info->cinematic_type);
2324
2325 switch (info->cinematic_type) {
2326 case CDI_NOT_CANNED: {
2327
2328 mf_WriteInt(buffer, &count, info->cinematic_data->flags);
2329 mf_WriteInt(buffer, &count, info->cinematic_data->target_objhandle);
2330 mf_WriteInt(buffer, &count, info->cinematic_data->end_transition);
2331 mf_WriteInt(buffer, &count, info->cinematic_data->start_transition);
2332 mf_WriteInt(buffer, &count, info->cinematic_data->pathid);
2333 mf_WriteFloat(buffer, &count, info->cinematic_data->position.x);
2334 mf_WriteFloat(buffer, &count, info->cinematic_data->position.y);
2335 mf_WriteFloat(buffer, &count, info->cinematic_data->position.z);
2336 mf_WriteInt(buffer, &count, info->cinematic_data->room);
2337
2338 if (info->cinematic_data->orient) {
2339 mf_WriteByte(buffer, &count, 1);
2340 mf_WriteFloat(buffer, &count, info->cinematic_data->orient->fvec.x);
2341 mf_WriteFloat(buffer, &count, info->cinematic_data->orient->fvec.y);
2342 mf_WriteFloat(buffer, &count, info->cinematic_data->orient->fvec.z);
2343 mf_WriteFloat(buffer, &count, info->cinematic_data->orient->uvec.x);
2344 mf_WriteFloat(buffer, &count, info->cinematic_data->orient->uvec.y);
2345 mf_WriteFloat(buffer, &count, info->cinematic_data->orient->uvec.z);
2346 mf_WriteFloat(buffer, &count, info->cinematic_data->orient->rvec.x);
2347 mf_WriteFloat(buffer, &count, info->cinematic_data->orient->rvec.y);
2348 mf_WriteFloat(buffer, &count, info->cinematic_data->orient->rvec.z);
2349
2350 } else {
2351 mf_WriteByte(buffer, &count, 0);
2352 }
2353
2354 mf_WriteFloat(buffer, &count, info->cinematic_data->max_time_play);
2355 mf_WriteFloat(buffer, &count, info->cinematic_data->text_display.max);
2356 mf_WriteFloat(buffer, &count, info->cinematic_data->text_display.min);
2357 mf_WriteFloat(buffer, &count, info->cinematic_data->track_target.max);
2358 mf_WriteFloat(buffer, &count, info->cinematic_data->track_target.min);
2359 mf_WriteFloat(buffer, &count, info->cinematic_data->player_disabled.max);
2360 mf_WriteFloat(buffer, &count, info->cinematic_data->player_disabled.min);
2361 mf_WriteFloat(buffer, &count, info->cinematic_data->in_camera_view.max);
2362 mf_WriteFloat(buffer, &count, info->cinematic_data->in_camera_view.min);
2363 mf_WriteFloat(buffer, &count, info->cinematic_data->quick_exit.max);
2364 mf_WriteFloat(buffer, &count, info->cinematic_data->quick_exit.min);
2365
2366 if (info->text_string)
2367 mf_WriteString(buffer, &count, info->text_string);
2368 else
2369 mf_WriteByte(buffer, &count, 0);
2370
2371 object *obj = ObjGet(info->camera_objhandle);
2372 ASSERT(obj && obj->type == OBJ_CAMERA);
2373 mf_WriteInt(buffer, &count, OBJNUM(obj));
2374
2375 } break;
2376 case CDI_CANNED: {
2377
2378 mf_WriteInt(buffer, &count, info->canned_data->type);
2379 mf_WriteInt(buffer, &count, info->canned_data->camera_pathid);
2380 mf_WriteInt(buffer, &count, info->canned_data->target_pathid);
2381 mf_WriteInt(buffer, &count, info->canned_data->target_objhandle);
2382 mf_WriteFloat(buffer, &count, info->canned_data->time);
2383 mf_WriteInt(buffer, &count, info->canned_data->object_to_use_for_point);
2384 mf_WriteInt(buffer, &count, info->canned_data->room);
2385 mf_WriteFloat(buffer, &count, info->canned_data->pos.x);
2386 mf_WriteFloat(buffer, &count, info->canned_data->pos.y);
2387 mf_WriteFloat(buffer, &count, info->canned_data->pos.z);
2388 mf_WriteFloat(buffer, &count, info->canned_data->orient.fvec.x);
2389 mf_WriteFloat(buffer, &count, info->canned_data->orient.fvec.y);
2390 mf_WriteFloat(buffer, &count, info->canned_data->orient.fvec.z);
2391 mf_WriteFloat(buffer, &count, info->canned_data->orient.uvec.x);
2392 mf_WriteFloat(buffer, &count, info->canned_data->orient.uvec.y);
2393 mf_WriteFloat(buffer, &count, info->canned_data->orient.uvec.z);
2394 mf_WriteFloat(buffer, &count, info->canned_data->orient.rvec.x);
2395 mf_WriteFloat(buffer, &count, info->canned_data->orient.rvec.y);
2396 mf_WriteFloat(buffer, &count, info->canned_data->orient.rvec.z);
2397
2398 if (info->canned_data->text_to_display)
2399 mf_WriteString(buffer, &count, info->canned_data->text_to_display);
2400 else
2401 mf_WriteByte(buffer, &count, 0);
2402
2403 object *obj = ObjGet(info->camera_objhandle);
2404 ASSERT(obj && obj->type == OBJ_CAMERA);
2405 mf_WriteInt(buffer, &count, OBJNUM(obj));
2406
2407 } break;
2408 }
2409
2410 DemoWriteCinematics(buffer, count);
2411 }
2412
2413 void mf_WriteInt(uint8_t *buffer, int *pointer, int data) {
2414 memcpy(&buffer[(*pointer)], &data, sizeof(int));
2415 (*pointer) += sizeof(int);
2416 }
2417
2418 void mf_WriteShort(uint8_t *buffer, int *pointer, int16_t data) {
2419 memcpy(&buffer[(*pointer)], &data, sizeof(int16_t));
2420 (*pointer) += sizeof(int16_t);
2421 }
2422
2423 void mf_WriteByte(uint8_t *buffer, int *pointer, uint8_t data) {
2424 memcpy(&buffer[(*pointer)], &data, sizeof(uint8_t));
2425 (*pointer) += sizeof(uint8_t);
2426 }
2427
2428 void mf_WriteFloat(uint8_t *buffer, int *pointer, float data) {
2429 memcpy(&buffer[(*pointer)], &data, sizeof(float));
2430 (*pointer) += sizeof(float);
2431 }
2432
2433 void mf_WriteBytes(uint8_t *buffer, int *pointer, uint8_t *data, int len) {
2434 memcpy(&buffer[(*pointer)], data, len);
2435 (*pointer) += len;
2436 }
2437
2438 void mf_WriteString(uint8_t *buffer, int *pointer, const char *string) {
2439 while (*string) {
2440 mf_WriteByte(buffer, pointer, (*string));
2441 string++;
2442 }
2443 mf_WriteByte(buffer, pointer, (*string));
2444 }
2445
2446 int mf_ReadInt(uint8_t *buffer, int *pointer) {
2447 int value;
2448 memcpy(&value, &buffer[(*pointer)], sizeof(value));
2449 (*pointer) += sizeof(value);
2450 return value;
2451 }
2452
2453 int16_t mf_ReadShort(uint8_t *buffer, int *pointer) {
2454 int16_t value;
2455 memcpy(&value, &buffer[(*pointer)], sizeof(value));
2456 (*pointer) += sizeof(value);
2457 return value;
2458 }
2459
2460 uint8_t mf_ReadByte(uint8_t *buffer, int *pointer) {
2461 uint8_t value;
2462 memcpy(&value, &buffer[(*pointer)], sizeof(value));
2463 (*pointer) += sizeof(value);
2464 return value;
2465 }
2466
2467 float mf_ReadFloat(uint8_t *buffer, int *pointer) {
2468 float value;
2469 memcpy(&value, &buffer[(*pointer)], sizeof(value));
2470 (*pointer) += sizeof(value);
2471 return value;
2472 }
2473
2474 void mf_ReadBytes(uint8_t *buffer, int *pointer, uint8_t *data, int len) {
2475 memcpy(data, &buffer[(*pointer)], len);
2476 (*pointer) += len;
2477 }
2478
2479 void mf_ReadString(uint8_t *buffer, int *pointer, char *string) {
2480 uint8_t data;
2481 data = mf_ReadByte(buffer, pointer);
2482 while (data) {
2483 *string = data;
2484 string++;
2485 data = mf_ReadByte(buffer, pointer);
2486 }
2487 *string = '\0';
2488 }