| 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/Briefing.cpp $ |
| 21 | * $Revision: 57 $ |
| 22 | * $Date: 4/14/99 2:50a $ |
| 23 | * $Author: Jeff $ |
| 24 | * |
| 25 | * Briefing system |
| 26 | * |
| 27 | * $Log: /DescentIII/main/Briefing.cpp $ |
| 28 | * |
| 29 | * 57 4/14/99 2:50a Jeff |
| 30 | * fixed some case mismatched #includes |
| 31 | * |
| 32 | * 56 2/25/99 11:56a Jeff |
| 33 | * added embedded hottag support |
| 34 | * |
| 35 | * 55 1/04/99 6:12p Jeff |
| 36 | * put in handling of mission state flags |
| 37 | * |
| 38 | * 54 1/04/99 12:32p Jeff |
| 39 | * added support for mission flag parsing |
| 40 | * |
| 41 | * 53 12/15/98 4:28p Jeff |
| 42 | * don't die if the briefing file doesn't exist |
| 43 | * |
| 44 | * 52 10/12/98 8:32p Jeff |
| 45 | * changed the way focus is handled |
| 46 | * |
| 47 | * 51 9/11/98 10:34a Jeff |
| 48 | * Briefing Editor completed |
| 49 | * |
| 50 | * 50 9/09/98 7:02p Jeff |
| 51 | * |
| 52 | * 49 8/28/98 12:57p Jeff |
| 53 | * added sounds and some key functionality |
| 54 | * |
| 55 | * 48 8/27/98 2:51p Jeff |
| 56 | * New TelCom finally checked in |
| 57 | * |
| 58 | * 47 8/19/98 1:38p Jeff |
| 59 | * removed update2dsound |
| 60 | * |
| 61 | * 46 8/18/98 11:57a Jeff |
| 62 | * fixed sound problem |
| 63 | * |
| 64 | * 45 7/11/98 9:16p Jeff |
| 65 | * moved automatically drawing monitor overlay graphics from update() to a |
| 66 | * function of it's own, that way the TelCom API can be avoided if needed |
| 67 | * |
| 68 | * 44 7/09/98 8:33p Samir |
| 69 | * changes for new streaming interface. |
| 70 | * |
| 71 | * 43 6/26/98 2:49p Jeff |
| 72 | * fixed the bug where is you aborted parsing in the middle of a screen |
| 73 | * you'd crash |
| 74 | * |
| 75 | * 42 6/25/98 12:44p Jeff |
| 76 | * Added ESC to escape out of TelCom while it's initializing. Added |
| 77 | * DestroyScratch to Monitor |
| 78 | * |
| 79 | * 41 6/19/98 6:05p Jeff |
| 80 | * changes made due to voice system |
| 81 | * |
| 82 | * 40 6/18/98 5:18p Jeff |
| 83 | * use new streamaudio system |
| 84 | * |
| 85 | * 39 6/17/98 8:08p Jeff |
| 86 | * removed call to DoVoiceFrame |
| 87 | * |
| 88 | * 38 6/08/98 3:56p Jeff |
| 89 | * added voice support |
| 90 | * |
| 91 | * 37 5/19/98 3:40p Jeff |
| 92 | * poly models functional |
| 93 | * |
| 94 | * 36 5/18/98 4:20p Jeff |
| 95 | * setup TelCom so D3_FAST zips it through |
| 96 | * |
| 97 | * 35 5/18/98 3:37p Jeff |
| 98 | * added glow parameter to $button |
| 99 | * |
| 100 | * 34 5/15/98 5:16p Jeff |
| 101 | * various changes |
| 102 | * |
| 103 | * 33 5/11/98 6:20p Jeff |
| 104 | * added glitch and static keywords |
| 105 | * |
| 106 | * 32 5/08/98 12:39p Jeff |
| 107 | * various cleanups |
| 108 | * |
| 109 | * 31 5/06/98 6:34p Jeff |
| 110 | * capped framerate for mouse |
| 111 | * |
| 112 | * 30 5/04/98 5:29p Jeff |
| 113 | * Added sound frames and mouse cursor drawing |
| 114 | * |
| 115 | * 29 5/04/98 1:35p Jeff |
| 116 | * Changes made for mouse handling |
| 117 | * |
| 118 | * 28 5/04/98 11:01a Jeff |
| 119 | * added scroll param to text |
| 120 | * |
| 121 | * 27 5/03/98 7:59p Jeff |
| 122 | * little changes |
| 123 | * |
| 124 | * 26 5/01/98 2:16p Jeff |
| 125 | * added $title and $sound |
| 126 | * |
| 127 | * 25 4/30/98 7:16p Jeff |
| 128 | * added $font, exiting to mainmenu |
| 129 | * |
| 130 | * 24 4/29/98 4:36p Jeff |
| 131 | * increased text buffer size |
| 132 | * |
| 133 | * 23 4/28/98 6:58p Jeff |
| 134 | * Added new poly model effect driver |
| 135 | * |
| 136 | * 22 4/26/98 7:22p Jeff |
| 137 | * fixed fade ping pong bug, implemented new invert and stretch bitmaps |
| 138 | * |
| 139 | * 21 4/26/98 2:53a Jeff |
| 140 | * Made changes needed for new Effect driver system |
| 141 | * |
| 142 | * 20 4/24/98 6:35p Jeff |
| 143 | * Added space bar page forward |
| 144 | * |
| 145 | * 19 4/24/98 3:29p Jeff |
| 146 | * fixed powerup effect |
| 147 | * |
| 148 | * 18 4/23/98 7:09p Jeff |
| 149 | * added power up/down support |
| 150 | * |
| 151 | * 17 4/22/98 7:44p Jeff |
| 152 | * added flashing buttons |
| 153 | * |
| 154 | * 16 4/21/98 4:22p Jeff |
| 155 | * Call a general purpose function to draw entire telcom screen |
| 156 | * |
| 157 | * 15 4/20/98 6:45p Jeff |
| 158 | * added multiple screen handling and on screen buttons |
| 159 | * |
| 160 | * 14 4/17/98 6:55p Jeff |
| 161 | * Added button support |
| 162 | * |
| 163 | * 13 4/15/98 6:28p Jeff |
| 164 | * Got parsing working for most of the keywords |
| 165 | * |
| 166 | * 12 3/23/98 9:55a Jeff |
| 167 | * Made changes to remove old telcom |
| 168 | * |
| 169 | * 11 3/12/98 3:32p Jeff |
| 170 | * Initial changes started for New TelCom |
| 171 | * |
| 172 | * 10 2/03/98 12:21p Jeff |
| 173 | * changed default font to briefing font |
| 174 | * |
| 175 | * 9 1/26/98 4:19p Jeff |
| 176 | * Added "blur in" bitmap effect |
| 177 | * |
| 178 | * 8 1/20/98 9:16p Jeff |
| 179 | * Added back in fading bitmaps |
| 180 | * |
| 181 | * 7 1/20/98 6:04p Jeff |
| 182 | * Added support for fading fonts |
| 183 | * |
| 184 | * 6 1/20/98 10:43a Jeff |
| 185 | * |
| 186 | * 5 1/19/98 5:37p Jeff |
| 187 | * Got briefing up to par, and even better than before, added timer so |
| 188 | * scroll and type fonts are time based. |
| 189 | * |
| 190 | * 4 1/16/98 2:40p Jeff |
| 191 | * Adjusted so everything is displayed in correct spots, took out |
| 192 | * DefaultControl timer, added support for non fading bitmaps |
| 193 | * |
| 194 | * 3 1/15/98 11:14a Jeff |
| 195 | * Changed some code in TelComCallMission() to get Telcom working again |
| 196 | * |
| 197 | * 2 11/17/97 3:56p Matt |
| 198 | * Added the briefing system code |
| 199 | * |
| 200 | * 1 11/12/97 10:44a Matt |
| 201 | * |
| 202 | * $NoKeywords: $ |
| 203 | */ |
| 204 | |
| 205 | #include "Briefing.h" |
| 206 | #include "BriefingParse.h" |
| 207 | #include <stdlib.h> |
| 208 | #include <string.h> |
| 209 | #include <ctype.h> |
| 210 | #include "game.h" |
| 211 | #include "mem.h" |
| 212 | #include "hlsoundlib.h" |
| 213 | #include "voice.h" |
| 214 | #include "streamaudio.h" |
| 215 | #include "pserror.h" |
| 216 | #include "ddio.h" |
| 217 | #include "descent.h" |
| 218 | #include "TelCom.h" |
| 219 | #include "TelComEffects.h" |
| 220 | #include "Mission.h" |
| 221 | |
| 222 | struct tBriefingTag { |
| 223 | const char *name; |
| 224 | int id; |
| 225 | int length; |
| 226 | }; |
| 227 | |
| 228 | #define TAG_LEVELNUM 0 |
| 229 | #define TAG_PLEVELNUM 1 |
| 230 | #define TAG_NLEVELNUM 2 |
| 231 | |
| 232 | static tBriefingTag HotTags[] = { |
| 233 | {"#LEVELNUM#", TAG_LEVELNUM, -1}, |
| 234 | {"#PLEVELNUM#", TAG_PLEVELNUM, -1}, |
| 235 | {"#NLEVELNUM#", TAG_NLEVELNUM, -1}, |
| 236 | }; |
| 237 | static const int NumHotTags = sizeof(HotTags) / sizeof(tBriefingTag); |
| 238 | |
| 239 | static int osb_xoff = 0, osb_yoff = 0; |
| 240 | static int current_screen = -1; |
| 241 | static tTelComInfo *pb_tcs = NULL; |
| 242 | static bool gottitle = false; |
| 243 | static bool pbfirst_call; |
| 244 | static char pbtitle[100]; |
| 245 | static bool ok_to_parse_screen = false; |
| 246 | static int skipped_screens; |
| 247 | |
| 248 | static bool IsMissionMaskOK(uint32_t set, uint32_t unset); |
| 249 | static void ReplaceHotTag(char *string, int tag); |
| 250 | static bool ParseForHotTags(const char *src, char **dest); |
| 251 | static bool PlayBriefing(tTelComInfo *tcs); |
| 252 | static void PBAddTextEffect(TCTEXTDESC* desc, char *text, char *description, int id); |
| 253 | static void PBAddBmpEffect(TCBMPDESC* desc, char *description); |
| 254 | static void PBAddMovieEffect(TCMOVIEDESC* desc, char *description); |
| 255 | static void PBAddBkgEffect(TCBKGDESC* desc, char *description); |
| 256 | static void PBAddPolyEffect(TCPOLYDESC* desc, char *description); |
| 257 | static void PBAddButtonEffect(TCBUTTONDESC* desc, char *description, int id); |
| 258 | static void PBStartScreen(int screen_num, char *description, char *layout, uint32_t mask_set, uint32_t mask_unset); |
| 259 | static void PBEndScreen(); |
| 260 | static bool PBLoopCallback(); |
| 261 | static void PBSetTitle(char *title); |
| 262 | static void PBSetStatic(float amount); |
| 263 | static void PBSetGlitch(float amount); |
| 264 | static void PBAddVoice(char *filename, int flags, char *description); |
| 265 | |
| 266 | bool IsMissionMaskOK(uint32_t set, uint32_t unset) { |
| 267 | uint32_t Gamemissionmask = Current_mission.game_state_flags; |
| 268 | |
| 269 | uint32_t fGamemissionmask; |
| 270 | fGamemissionmask = Gamemissionmask ^ 0xFFFFFFFF; |
| 271 | |
| 272 | if (!(((set & Gamemissionmask) == set) && ((unset & fGamemissionmask) == unset))) { |
| 273 | return false; |
| 274 | } |
| 275 | |
| 276 | return true; |
| 277 | } |
| 278 | |
| 279 | void ReplaceHotTag(char *string, int tag) { |
| 280 | if (tag < 0 || tag >= NumHotTags) { |
| 281 | *string = '\0'; |
| 282 | return; |
| 283 | } |
| 284 | |
| 285 | switch (tag) { |
| 286 | case TAG_LEVELNUM: |
| 287 | sprintf(string, "%d", Current_mission.cur_level); |
| 288 | break; |
| 289 | case TAG_PLEVELNUM: |
| 290 | sprintf(string, "%d", Current_mission.cur_level - 1); |
| 291 | break; |
| 292 | case TAG_NLEVELNUM: |
| 293 | sprintf(string, "%d", Current_mission.cur_level + 1); |
| 294 | break; |
| 295 | } |
| 296 | } |
| 297 | |
| 298 | // returns true if there were hot tags and it had to allocate memory for dest (so it needs to be freed) |
| 299 | #define MEMORY_BLOCK 50 |
| 300 | bool ParseForHotTags(const char *src, char **dest) { |
| 301 | bool ret = false; |
| 302 | const char *curr_ptr = src; |
| 303 | char *dest_ptr; |
| 304 | *dest = NULL; |
| 305 | |
| 306 | bool done = false; |
| 307 | int length = strlen(src) + 1; |
| 308 | int curr_size = length; |
| 309 | int curr_index = 0; |
| 310 | |
| 311 | dest_ptr = *dest = (char *)mem_malloc(length); |
| 312 | if (!dest_ptr) |
| 313 | return false; |
| 314 | char replacement[256]; |
| 315 | |
| 316 | while (!done) { |
| 317 | if (*curr_ptr != '#') { |
| 318 | if (*curr_ptr == '\0') { |
| 319 | done = true; |
| 320 | } else { |
| 321 | *dest_ptr = *curr_ptr; |
| 322 | dest_ptr++; |
| 323 | curr_ptr++; |
| 324 | curr_index++; |
| 325 | length--; |
| 326 | |
| 327 | if (length < 1) { |
| 328 | // we need to allocate some more memory |
| 329 | char *new_mem = (char *)mem_malloc(curr_size + MEMORY_BLOCK); |
| 330 | if (!new_mem) { |
| 331 | // out of memory |
| 332 | mem_free((*dest)); |
| 333 | *dest = NULL; |
| 334 | return false; |
| 335 | } |
| 336 | |
| 337 | memcpy(new_mem, (*dest), curr_index); |
| 338 | mem_free(*dest); |
| 339 | *dest = new_mem; |
| 340 | dest_ptr = &new_mem[curr_index]; |
| 341 | curr_size += MEMORY_BLOCK; |
| 342 | length += MEMORY_BLOCK; |
| 343 | } |
| 344 | } |
| 345 | } else { |
| 346 | int is_hot_tag = -1; |
| 347 | |
| 348 | // see if it's a hot tag |
| 349 | for (int i = 0; i < NumHotTags; i++) { |
| 350 | if (HotTags[i].length == -1) |
| 351 | HotTags[i].length = strlen(HotTags[i].name); |
| 352 | |
| 353 | if (!strnicmp(curr_ptr, HotTags[i].name, HotTags[i].length)) { |
| 354 | // this is a hot tag!!!!! |
| 355 | mprintf(0, "Found Embedded HotTag: %s\n", HotTags[i].name); |
| 356 | is_hot_tag = i; |
| 357 | ret = true; |
| 358 | break; |
| 359 | } |
| 360 | } |
| 361 | |
| 362 | if (is_hot_tag == -1) { |
| 363 | // it wasn't a hot tag continue on |
| 364 | *dest_ptr = *curr_ptr; |
| 365 | dest_ptr++; |
| 366 | curr_ptr++; |
| 367 | curr_index++; |
| 368 | length--; |
| 369 | |
| 370 | if (length < 1) { |
| 371 | // we need to allocate some more memory |
| 372 | char *new_mem = (char *)mem_malloc(curr_size + MEMORY_BLOCK); |
| 373 | if (!new_mem) { |
| 374 | // out of memory |
| 375 | mem_free((*dest)); |
| 376 | *dest = NULL; |
| 377 | return false; |
| 378 | } |
| 379 | |
| 380 | memcpy(new_mem, (*dest), curr_index); |
| 381 | mem_free(*dest); |
| 382 | *dest = new_mem; |
| 383 | dest_ptr = &new_mem[curr_index]; |
| 384 | curr_size += MEMORY_BLOCK; |
| 385 | length += MEMORY_BLOCK; |
| 386 | } |
| 387 | } else { |
| 388 | // we need to replace the hot tag |
| 389 | ReplaceHotTag(replacement, is_hot_tag); |
| 390 | curr_ptr += HotTags[is_hot_tag].length; // skip past hot tag |
| 391 | |
| 392 | int dest_left = strlen(replacement); |
| 393 | char *r_ptr = replacement; |
| 394 | |
| 395 | while (dest_left > 0) { |
| 396 | *dest_ptr = *r_ptr; |
| 397 | dest_ptr++; |
| 398 | curr_index++; |
| 399 | length--; |
| 400 | |
| 401 | if (length < 1) { |
| 402 | // we need to allocate some more memory |
| 403 | char *new_mem = (char *)mem_malloc(curr_size + MEMORY_BLOCK); |
| 404 | if (!new_mem) { |
| 405 | // out of memory |
| 406 | mem_free((*dest)); |
| 407 | *dest = NULL; |
| 408 | return false; |
| 409 | } |
| 410 | |
| 411 | memcpy(new_mem, (*dest), curr_index); |
| 412 | mem_free(*dest); |
| 413 | *dest = new_mem; |
| 414 | dest_ptr = &new_mem[curr_index]; |
| 415 | curr_size += MEMORY_BLOCK; |
| 416 | length += MEMORY_BLOCK; |
| 417 | } |
| 418 | |
| 419 | dest_left--; |
| 420 | r_ptr++; |
| 421 | } |
| 422 | } |
| 423 | } |
| 424 | } |
| 425 | *dest_ptr = '\0'; |
| 426 | |
| 427 | if (!ret) { |
| 428 | mem_free((*dest)); |
| 429 | *dest = NULL; |
| 430 | } |
| 431 | |
| 432 | return ret; |
| 433 | } |
| 434 | |
| 435 | bool PlayBriefing(tTelComInfo *tcs) { |
| 436 | TelcomRenderSetScreen(0); |
| 437 | bool done = false; |
| 438 | |
| 439 | while (!done) { |
| 440 | Sound_system.BeginSoundFrame(Telcom_called_from_game); |
| 441 | |
| 442 | if (tcs->state == TCS_POWEROFF || tcs->current_status != TS_MISSION) { |
| 443 | // we're done with the loop |
| 444 | done = true; |
| 445 | } |
| 446 | // Process all waiting events for the TelCom (we may only want to handle this once a frame!) |
| 447 | TelComHandleAllEvents(tcs); |
| 448 | |
| 449 | TelcomRenderScreen(); |
| 450 | Descent->defer(); |
| 451 | if (KEY_STATE(KEY_ESC)) |
| 452 | tcs->state = TCS_POWEROFF; |
| 453 | |
| 454 | Sound_system.EndSoundFrame(); |
| 455 | } |
| 456 | return true; |
| 457 | } |
| 458 | |
| 459 | void PBAddTextEffect(TCTEXTDESC* desc, char *text, char *description, int id) { |
| 460 | if (IsMissionMaskOK(desc->mission_mask_set, desc->mission_mask_unset) && ok_to_parse_screen) { |
| 461 | char *new_text = NULL; |
| 462 | const bool new_stuff = ParseForHotTags(text, &new_text); |
| 463 | |
| 464 | CreateTextEffect(desc, new_stuff ? new_text : text, MONITOR_MAIN, current_screen, id); |
| 465 | |
| 466 | if (new_text) { |
| 467 | mem_free(new_text); |
| 468 | } |
| 469 | } |
| 470 | } |
| 471 | |
| 472 | void PBAddBmpEffect(TCBMPDESC* desc, char *description) { |
| 473 | if (IsMissionMaskOK(desc->mission_mask_set, desc->mission_mask_unset) && ok_to_parse_screen) |
| 474 | CreateBitmapEffect(desc, MONITOR_MAIN, current_screen); |
| 475 | } |
| 476 | |
| 477 | void PBAddMovieEffect(TCMOVIEDESC* desc, char *description) { |
| 478 | if (IsMissionMaskOK(desc->mission_mask_set, desc->mission_mask_unset) && ok_to_parse_screen) |
| 479 | CreateMovieEffect(desc, MONITOR_MAIN, current_screen); |
| 480 | } |
| 481 | |
| 482 | void PBAddBkgEffect(TCBKGDESC* desc, char *description) { |
| 483 | if (IsMissionMaskOK(desc->mission_mask_set, desc->mission_mask_unset) && ok_to_parse_screen) { |
| 484 | mprintf(0, "PB: Add Bkg\n"); |
| 485 | } |
| 486 | } |
| 487 | |
| 488 | void PBAddPolyEffect(TCPOLYDESC* desc, char *description) { |
| 489 | if (IsMissionMaskOK(desc->mission_mask_set, desc->mission_mask_unset) && ok_to_parse_screen) |
| 490 | CreatePolyModelEffect(desc, MONITOR_MAIN, current_screen); |
| 491 | } |
| 492 | |
| 493 | void PBAddSoundEffect(TCSNDDESC* desc, char *description) { |
| 494 | if (IsMissionMaskOK(desc->mission_mask_set, desc->mission_mask_unset) && ok_to_parse_screen) |
| 495 | CreateSoundEffect(desc, MONITOR_MAIN, current_screen); |
| 496 | } |
| 497 | |
| 498 | void PBAddButtonEffect(TCBUTTONDESC* desc, char *description, int id) { |
| 499 | if (IsMissionMaskOK(desc->mission_mask_set, desc->mission_mask_unset) && ok_to_parse_screen) { |
| 500 | desc->x += osb_xoff; |
| 501 | desc->y += osb_yoff; |
| 502 | desc->tab_stop = false; // no briefing buttons can have focus |
| 503 | CreateButtonEffect(desc, MONITOR_MAIN, current_screen, id); |
| 504 | } |
| 505 | } |
| 506 | |
| 507 | void PBStartScreen(int screen_num, char *description, char *layout, uint32_t mask_set, uint32_t mask_unset) { |
| 508 | if (!IsMissionMaskOK(mask_set, mask_unset)) { |
| 509 | ok_to_parse_screen = false; |
| 510 | skipped_screens++; |
| 511 | return; |
| 512 | } |
| 513 | int real_screen_num = screen_num - skipped_screens; |
| 514 | ok_to_parse_screen = true; |
| 515 | |
| 516 | TelcomStartScreen(real_screen_num); |
| 517 | current_screen = real_screen_num; |
| 518 | |
| 519 | TCBKGDESC backg; |
| 520 | backg.color = BACKGROUND_COLOR; |
| 521 | backg.caps = TCBGD_COLOR; |
| 522 | backg.type = TC_BACK_STATIC; |
| 523 | CreateBackgroundEffect(&backg, MONITOR_TOP, current_screen); |
| 524 | if (gottitle) { |
| 525 | TCTEXTDESC textd; |
| 526 | textd.color = GR_RGB(200, 200, 200); |
| 527 | textd.type = TC_TEXT_STATIC; |
| 528 | textd.font = BBRIEF_FONT_INDEX; |
| 529 | textd.textbox.left = 4; |
| 530 | textd.textbox.right = 300; |
| 531 | textd.textbox.top = 2; |
| 532 | textd.textbox.bottom = 80; |
| 533 | textd.caps = TCTD_COLOR | TCTD_FONT | TCTD_TEXTBOX; |
| 534 | CreateTextEffect(&textd, pbtitle, MONITOR_TOP, current_screen); |
| 535 | } |
| 536 | |
| 537 | if (layout) { |
| 538 | TCBMPDESC bmpd; |
| 539 | bmpd.caps = TCBD_XY; |
| 540 | bmpd.type = TC_BMP_STATIC; |
| 541 | bmpd.flags = 0; |
| 542 | bmpd.x = bmpd.y = 0; |
| 543 | strcpy(bmpd.filename, layout); |
| 544 | CreateBitmapEffect(&bmpd, MONITOR_MAIN, current_screen); |
| 545 | } |
| 546 | } |
| 547 | |
| 548 | void PBEndScreen() { |
| 549 | if (ok_to_parse_screen) { |
| 550 | TelcomEndScreen(); |
| 551 | current_screen = -1; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | bool PBLoopCallback() { |
| 556 | if (!pbfirst_call) { |
| 557 | Sound_system.EndSoundFrame(); |
| 558 | } else |
| 559 | pbfirst_call = false; |
| 560 | |
| 561 | bool ret = false; |
| 562 | Sound_system.BeginSoundFrame(Telcom_called_from_game); |
| 563 | |
| 564 | if (pb_tcs->state == TCS_POWEROFF || pb_tcs->current_status != TS_MISSION) { |
| 565 | // we're done with the loop |
| 566 | ret = true; |
| 567 | } |
| 568 | |
| 569 | // Process all waiting events for the TelCom (we may only want to handle this once a frame!) |
| 570 | TelComHandleAllEvents(pb_tcs); |
| 571 | TelcomRenderScreen(); |
| 572 | |
| 573 | Descent->defer(); |
| 574 | if (KEY_STATE(KEY_ESC)) { |
| 575 | pb_tcs->state = TCS_POWEROFF; |
| 576 | ret = true; |
| 577 | } |
| 578 | |
| 579 | return ret; |
| 580 | } |
| 581 | |
| 582 | void PBSetTitle(char *title) { |
| 583 | gottitle = true; |
| 584 | strcpy(pbtitle, title); |
| 585 | } |
| 586 | |
| 587 | void PBSetStatic(float amount) { |
| 588 | if (amount > 0) |
| 589 | TelcomEnableStatic(amount); |
| 590 | } |
| 591 | |
| 592 | void PBSetGlitch(float amount) { |
| 593 | if (amount > 0) |
| 594 | TelcomEnableGlitch(amount); |
| 595 | } |
| 596 | |
| 597 | void PBAddVoice(char *filename, int flags,char *description) {} |
| 598 | |
| 599 | bool ParseBriefing(const char *filename, tTelComInfo *tcs) { |
| 600 | if (!cfexist(filename)) { |
| 601 | tcs->state = TCS_POWEROFF; |
| 602 | return false; |
| 603 | } |
| 604 | |
| 605 | osb_xoff = tcs->Monitor_coords[MONITOR_MAIN].left; |
| 606 | osb_yoff = tcs->Monitor_coords[MONITOR_MAIN].top; |
| 607 | current_screen = -1; |
| 608 | pb_tcs = tcs; |
| 609 | gottitle = false; |
| 610 | pbtitle[0] = '\0'; |
| 611 | pbfirst_call = true; |
| 612 | |
| 613 | CBriefParse engine; |
| 614 | tBriefParseCallbacks pb_callbacks; |
| 615 | |
| 616 | pb_callbacks.AddTextEffect = PBAddTextEffect; |
| 617 | pb_callbacks.AddBmpEffect = PBAddBmpEffect; |
| 618 | pb_callbacks.AddMovieEffect = PBAddMovieEffect; |
| 619 | pb_callbacks.AddBkgEffect = PBAddBkgEffect; |
| 620 | pb_callbacks.AddPolyEffect = PBAddPolyEffect; |
| 621 | pb_callbacks.AddSoundEffect = PBAddSoundEffect; |
| 622 | pb_callbacks.AddButtonEffect = PBAddButtonEffect; |
| 623 | pb_callbacks.StartScreen = PBStartScreen; |
| 624 | pb_callbacks.EndScreen = PBEndScreen; |
| 625 | pb_callbacks.LoopCallback = PBLoopCallback; |
| 626 | pb_callbacks.SetTitle = PBSetTitle; |
| 627 | pb_callbacks.SetStatic = PBSetStatic; |
| 628 | pb_callbacks.SetGlitch = PBSetGlitch; |
| 629 | pb_callbacks.AddVoice = PBAddVoice; |
| 630 | |
| 631 | engine.SetCallbacks(&pb_callbacks); |
| 632 | |
| 633 | DestroyAllScreens(); |
| 634 | TelcomRenderSetScreen(DUMMY_SCREEN); |
| 635 | |
| 636 | skipped_screens = 0; |
| 637 | int ret = engine.ParseBriefing(filename); |
| 638 | Sound_system.EndSoundFrame(); |
| 639 | |
| 640 | if (ret == PBERR_NOERR) { |
| 641 | PlayBriefing(tcs); |
| 642 | } |
| 643 | |
| 644 | DestroyAllScreens(true); |
| 645 | TelcomCreateDummyScreen(); |
| 646 | TelcomRenderSetScreen(DUMMY_SCREEN); |
| 647 | |
| 648 | TelcomDisableStatic(); |
| 649 | TelcomDisableGlitch(); |
| 650 | |
| 651 | return false; |
| 652 | } |