| 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/BriefingParse.cpp $ |
| 21 |
* $Revision: 11 $ |
| 22 |
* $Date: 4/14/99 2:50a $ |
| 23 |
* $Author: Jeff $ |
| 24 |
* |
| 25 |
* Parse functions to parse a briefing file |
| 26 |
* |
| 27 |
* $Log: /DescentIII/main/BriefingParse.cpp $ |
| 28 |
* |
| 29 |
* 11 4/14/99 2:50a Jeff |
| 30 |
* fixed some case mismatched #includes |
| 31 |
* |
| 32 |
* 10 2/17/99 6:55p Jeff |
| 33 |
* added jump button type. Added no early render flag for bitmaps. Fixed |
| 34 |
* color bug for type text |
| 35 |
* |
| 36 |
* 9 2/17/99 11:12a Doug |
| 37 |
* set movie type to TC_MOVIE_STATIC (Jeff) |
| 38 |
* |
| 39 |
* 8 1/13/99 8:01p Jeff |
| 40 |
* initialize text_ptr (even though it really doesn't get used till it's |
| 41 |
* init), to get rid of warning |
| 42 |
* |
| 43 |
* 7 1/04/99 12:32p Jeff |
| 44 |
* added support for mission flag parsing |
| 45 |
* |
| 46 |
* 6 11/17/98 3:39p Jeff |
| 47 |
* handle any length line when parsing |
| 48 |
* |
| 49 |
* 5 10/12/98 8:32p Jeff |
| 50 |
* changed the way focus is handled |
| 51 |
* |
| 52 |
* 4 9/17/98 2:28p Jeff |
| 53 |
* added focus filenames to button effect |
| 54 |
* |
| 55 |
* 3 9/11/98 6:06p Jeff |
| 56 |
* Briefing Editor completed |
| 57 |
* |
| 58 |
* 2 9/09/98 7:02p Jeff |
| 59 |
* Initial Creation |
| 60 |
* |
| 61 |
* $NoKeywords: $ |
| 62 |
*/ |
| 63 |
#include "BriefingParse.h" |
| 64 |
#include "TelComEffects.h" |
| 65 |
#include <stdlib.h> |
| 66 |
#include <string.h> |
| 67 |
#include <ctype.h> |
| 68 |
#include "cfile.h" |
| 69 |
#include "pserror.h" |
| 70 |
#include "game.h" |
| 71 |
#include "mem.h" |
| 72 |
#include "voice.h" |
| 73 |
#include "streamaudio.h" |
| 74 |
#include "ddio.h" |
| 75 |
|
| 76 |
// constructor |
| 77 |
CBriefParse::CBriefParse() { |
| 78 |
AddTextEffect = NULL; |
| 79 |
AddBmpEffect = NULL; |
| 80 |
AddMovieEffect = NULL; |
| 81 |
AddBkgEffect = NULL; |
| 82 |
AddPolyEffect = NULL; |
| 83 |
AddSoundEffect = NULL; |
| 84 |
AddButtonEffect = NULL; |
| 85 |
StartScreen = NULL; |
| 86 |
EndScreen = NULL; |
| 87 |
LoopCallback = NULL; |
| 88 |
SetTitle = NULL; |
| 89 |
SetStatic = NULL; |
| 90 |
SetGlitch = NULL; |
| 91 |
AddVoice = NULL; |
| 92 |
linenum = 0; |
| 93 |
parse_error = false; |
| 94 |
} |
| 95 |
|
| 96 |
// destructor |
| 97 |
CBriefParse::~CBriefParse() {} |
| 98 |
|
| 99 |
// SetCallbacks |
| 100 |
// |
| 101 |
// Registers (or changes) the callbacks of the class |
| 102 |
void CBriefParse::SetCallbacks(tBriefParseCallbacks *cb) { |
| 103 |
AddTextEffect = cb->AddTextEffect; |
| 104 |
AddBmpEffect = cb->AddBmpEffect; |
| 105 |
AddMovieEffect = cb->AddMovieEffect; |
| 106 |
AddBkgEffect = cb->AddBkgEffect; |
| 107 |
AddPolyEffect = cb->AddPolyEffect; |
| 108 |
AddSoundEffect = cb->AddSoundEffect; |
| 109 |
AddButtonEffect = cb->AddButtonEffect; |
| 110 |
StartScreen = cb->StartScreen; |
| 111 |
EndScreen = cb->EndScreen; |
| 112 |
LoopCallback = cb->LoopCallback; |
| 113 |
SetTitle = cb->SetTitle; |
| 114 |
SetStatic = cb->SetStatic; |
| 115 |
SetGlitch = cb->SetGlitch; |
| 116 |
AddVoice = cb->AddVoice; |
| 117 |
} |
| 118 |
|
| 119 |
//////////////////////////////////////////////////////////////////////////////// |
| 120 |
|
| 121 |
// Keyword IDs. These must match the keyword strings below |
| 122 |
#define K_NONE -1 |
| 123 |
#define K_SCREEN 0 |
| 124 |
#define K_BUTTON 1 |
| 125 |
#define K_TEXT 2 |
| 126 |
#define K_ENDTEXT 3 |
| 127 |
#define K_BITMAP 4 |
| 128 |
#define K_ENDSCREEN 5 |
| 129 |
#define K_MOVIE 6 |
| 130 |
#define K_POLY 7 |
| 131 |
#define K_TITLE 8 |
| 132 |
#define K_SOUND 9 |
| 133 |
#define K_STATIC 10 |
| 134 |
#define K_GLITCH 11 |
| 135 |
#define K_VOICE 12 |
| 136 |
#define NUM_KEYWORDS 13 |
| 137 |
|
| 138 |
// Button types |
| 139 |
#define B_DISP 1 // display a screen |
| 140 |
#define B_BACK 2 // go back a page |
| 141 |
#define B_FORWARD 3 // go forward a page |
| 142 |
#define B_QUIT 4 // exit TelCom |
| 143 |
|
| 144 |
// Keywords. These must match the keyword IDs above |
| 145 |
static const char *const keywords[] = {"screen", "button", "text", "endtext", "bitmap", "endscreen", "movie", |
| 146 |
"poly", "title", "sound", "static", "glitch", "voice"}; |
| 147 |
|
| 148 |
#define tfxNONE 0 |
| 149 |
#define tfxFLASH 1 |
| 150 |
#define tfxSCROLL_L2R 2 |
| 151 |
#define tfxSCROLL_R2L 3 |
| 152 |
#define tfxSCROLL_T2B 4 |
| 153 |
#define tfxSCROLL_B2T 5 |
| 154 |
#define tfxFADE_IN_AND_OUT 6 |
| 155 |
#define tfxFADE_IN 7 |
| 156 |
#define tfxFADE_OUT 8 |
| 157 |
|
| 158 |
#define fntSMBRIEF 0 |
| 159 |
#define fntLGBRIEF 1 |
| 160 |
static const char *const FontNames[] = {"sm_brief", "lg_brief", NULL}; |
| 161 |
|
| 162 |
static const char *const TextEffectstr[] = {"None", "flash", "scroll_l2r", "scroll_r2l", "scroll_t2b", |
| 163 |
"scroll_b2t", "fade_in_and_out", "fade_in", "fade_out", NULL}; |
| 164 |
#define bfxNONE 0 |
| 165 |
#define bfxFADE_IN 1 |
| 166 |
#define bfxFADE_OUT 2 |
| 167 |
#define bfxBLUR_IN 3 |
| 168 |
#define bfxBLUR_OUT 4 |
| 169 |
#define bfxSCAN_IN 5 |
| 170 |
#define bfxSCAN_OUT 6 |
| 171 |
#define bfxINVERT_IN 7 |
| 172 |
#define bfxINVERT_OUT 8 |
| 173 |
#define bfxSTRETCH_IN 9 |
| 174 |
#define bfxSTRETCH_OUT 10 |
| 175 |
|
| 176 |
static const char *const BitmapEffectstr[] = {"None", "Fade_in", "Fade_out", "Blur_in", |
| 177 |
"Blur_out", "Scan_in", "Scan_out", "Invert_in", |
| 178 |
"Invert_out", "Stretch_in", "Stretch_out", NULL}; |
| 179 |
|
| 180 |
//////////////////////////////////////////// |
| 181 |
// These are the types of on screen buttons |
| 182 |
#define osbDOWN_ARROW 0 |
| 183 |
#define osbUP_ARROW 1 |
| 184 |
#define osbNEXT_PAGE 2 |
| 185 |
#define osbPREV_PAGE 3 |
| 186 |
#define osbQUIT 4 |
| 187 |
#define osbJUMP_PAGE 5 |
| 188 |
|
| 189 |
static const char *const OnScreenButtonTypes[] = {"Down", "Up", "Next", "Prev", "Quit", "Jump", NULL}; |
| 190 |
|
| 191 |
///////////////////////////////////////////// |
| 192 |
// These are the different ways an onscreen button will respond to mouse clicks |
| 193 |
#define oscHOLD_DOWN 0 |
| 194 |
#define oscCLICK_DOWN 1 |
| 195 |
#define oscCLICK_UP 2 |
| 196 |
|
| 197 |
static const char *const OnScreenButtonClickTypes[] = {"HoldDown", "ClickDown", "ClickUp", NULL}; |
| 198 |
|
| 199 |
#define PARSE_INT(i) \ |
| 200 |
do { \ |
| 201 |
p = ParseInt(p, &(i)); \ |
| 202 |
if (!p) \ |
| 203 |
goto done_parsing; \ |
| 204 |
} while (0) |
| 205 |
#define PARSE_FLOAT(i) \ |
| 206 |
do { \ |
| 207 |
p = ParseFloat(p, &(i)); \ |
| 208 |
if (!p) \ |
| 209 |
goto done_parsing; \ |
| 210 |
} while (0) |
| 211 |
#define PARSE_COMMA() \ |
| 212 |
do { \ |
| 213 |
p = ParseComma(p); \ |
| 214 |
if (!p) \ |
| 215 |
goto done_parsing; \ |
| 216 |
} while (0) |
| 217 |
#define PARSE_STRING(buf) \ |
| 218 |
do { \ |
| 219 |
p = ParseString(p, buf, sizeof(buf)); \ |
| 220 |
if (!p) \ |
| 221 |
goto done_parsing; \ |
| 222 |
} while (0) |
| 223 |
#define PARSE_TOKEN(buf) \ |
| 224 |
do { \ |
| 225 |
p = ParseToken(p, buf, sizeof(buf)); \ |
| 226 |
if (!p) \ |
| 227 |
goto done_parsing; \ |
| 228 |
} while (0) |
| 229 |
|
| 230 |
static int ReadFullLine(char **data, CFILE *ifile) { |
| 231 |
int counter, readin; |
| 232 |
char buffer[512]; |
| 233 |
bool done; |
| 234 |
|
| 235 |
counter = 0; |
| 236 |
done = false; |
| 237 |
readin = 0; |
| 238 |
*data = NULL; |
| 239 |
char c; |
| 240 |
|
| 241 |
while (!done) { |
| 242 |
|
| 243 |
// read in a byte |
| 244 |
c = cfgetc(ifile); |
| 245 |
|
| 246 |
if ((c == EOF) || (!(ifile->flags & CFF_TEXT) && (c == 0)) || ((ifile->flags & CFF_TEXT) && (c == '\n'))) { |
| 247 |
// we've hit the end of the line |
| 248 |
done = true; |
| 249 |
} else { |
| 250 |
buffer[readin] = c; |
| 251 |
readin++; |
| 252 |
} |
| 253 |
|
| 254 |
// check if we have a full temp buffer |
| 255 |
if (readin == sizeof(buffer)) { |
| 256 |
// we have a full temp buffer |
| 257 |
char *temp_buffer; |
| 258 |
temp_buffer = (char *)mem_malloc(counter + sizeof(buffer)); // allocate another buffer full |
| 259 |
if (*data) { |
| 260 |
// copy over existing data |
| 261 |
memcpy(temp_buffer, *data, counter); |
| 262 |
// free it |
| 263 |
mem_free(*data); |
| 264 |
} |
| 265 |
// copy over new data |
| 266 |
memcpy(&temp_buffer[counter], buffer, sizeof(buffer)); |
| 267 |
|
| 268 |
// reset our buffer for the temp buffer |
| 269 |
counter += readin; |
| 270 |
readin = 0; |
| 271 |
|
| 272 |
*data = temp_buffer; |
| 273 |
} |
| 274 |
} |
| 275 |
|
| 276 |
// append all the data thats in the tempbuffer into the final buffer |
| 277 |
char *temp_buffer; |
| 278 |
temp_buffer = (char *)mem_malloc(counter + readin + 1); // allocate what we need (plus for NULL term) |
| 279 |
if (*data) { |
| 280 |
// copy over existing data |
| 281 |
memcpy(temp_buffer, *data, counter); |
| 282 |
// free it |
| 283 |
mem_free(*data); |
| 284 |
} |
| 285 |
// copy over new data |
| 286 |
memcpy(&temp_buffer[counter], buffer, readin); |
| 287 |
|
| 288 |
counter += (readin + 1); |
| 289 |
*data = temp_buffer; |
| 290 |
|
| 291 |
temp_buffer[counter - 1] = '\0'; |
| 292 |
|
| 293 |
return counter; |
| 294 |
} |
| 295 |
|
| 296 |
// ParseBriefing |
| 297 |
// |
| 298 |
// Parses the briefing file (calling the callbacks throughout), check return code |
| 299 |
int CBriefParse::ParseBriefing(const char *filename) { |
| 300 |
CFILE *ifile; |
| 301 |
bool retvalue = false; |
| 302 |
bool voice_def_screen = false; |
| 303 |
char text_buf[8192], *text_ptr = NULL; |
| 304 |
bool abort = 0; |
| 305 |
bool gottitle = false; |
| 306 |
char *linebuf = NULL; |
| 307 |
|
| 308 |
int beffect = bfxNONE; |
| 309 |
int x = 0, y = 0; |
| 310 |
char filen[40]; |
| 311 |
bool emergency_exit = false; |
| 312 |
|
| 313 |
// the following block of 'globals' are for when parsing a text block, the information is stored |
| 314 |
// here until a $endtext is hit |
| 315 |
char title_buf[128]; |
| 316 |
bool reading_text = false; |
| 317 |
tTextBufferDesc text_buffer_desc = {}; |
| 318 |
text_buffer_desc.text_id = -1; // id # for current textblock |
| 319 |
text_buffer_desc.teffect = tfxNONE; |
| 320 |
|
| 321 |
int current_screen = -1; |
| 322 |
char title[100]; |
| 323 |
|
| 324 |
strcpy(title, " "); |
| 325 |
|
| 326 |
mprintf(0, "Parsing <%s>\n", filename); |
| 327 |
|
| 328 |
// Open the file |
| 329 |
ifile = cfopen(filename, "rt"); |
| 330 |
if (!ifile) |
| 331 |
return PBERR_FILENOTEXIST; |
| 332 |
|
| 333 |
// Initialize vars |
| 334 |
linenum = 0; |
| 335 |
parse_error = 0; |
| 336 |
title_buf[0] = 0; |
| 337 |
|
| 338 |
// Read & parse lines |
| 339 |
int bytes_read; |
| 340 |
const char *p; |
| 341 |
|
| 342 |
linebuf = NULL; |
| 343 |
|
| 344 |
while ((!cfeof(ifile) && !parse_error && !abort)) { |
| 345 |
if (linebuf) { |
| 346 |
mem_free(linebuf); |
| 347 |
linebuf = NULL; |
| 348 |
} |
| 349 |
|
| 350 |
if (LoopCallback) { |
| 351 |
abort = (*LoopCallback)(); |
| 352 |
} |
| 353 |
|
| 354 |
// Read the line |
| 355 |
bytes_read = ReadFullLine(&linebuf, ifile); |
| 356 |
linenum++; |
| 357 |
|
| 358 |
if (!linebuf) { |
| 359 |
// no more data? or empty line |
| 360 |
continue; |
| 361 |
} |
| 362 |
|
| 363 |
// Check for line too long |
| 364 |
//@@if (bytes_read >= sizeof(linebuf)-1) { |
| 365 |
//@@ ParseError("Line too long"); |
| 366 |
//@@ break; |
| 367 |
//@@} |
| 368 |
|
| 369 |
// Check for keyword |
| 370 |
if (linebuf[0] == '$') { |
| 371 |
int keyword_id; |
| 372 |
|
| 373 |
// Get the keyword id |
| 374 |
p = ParseKeyword(linebuf, &keyword_id); |
| 375 |
|
| 376 |
switch (keyword_id) { |
| 377 |
case K_TITLE: { |
| 378 |
if (gottitle) |
| 379 |
ParseError("$TITLE already defined\n"); |
| 380 |
PARSE_STRING(title); |
| 381 |
gottitle = true; |
| 382 |
if (SetTitle) |
| 383 |
(*SetTitle)(title); |
| 384 |
} break; |
| 385 |
case K_STATIC: { |
| 386 |
float s; |
| 387 |
PARSE_FLOAT(s); |
| 388 |
if (SetStatic) |
| 389 |
(*SetStatic)(s); |
| 390 |
} break; |
| 391 |
case K_GLITCH: { |
| 392 |
float g; |
| 393 |
PARSE_FLOAT(g); |
| 394 |
if (SetGlitch) |
| 395 |
(*SetGlitch)(g); |
| 396 |
} break; |
| 397 |
case K_SOUND: { |
| 398 |
// add a sound effect |
| 399 |
char buffer[20]; |
| 400 |
char d[128]; |
| 401 |
d[0] = '\0'; |
| 402 |
TCSNDDESC snddesc; |
| 403 |
snddesc.caps = 0; |
| 404 |
bool play = false; |
| 405 |
snddesc.mission_mask_set = snddesc.mission_mask_unset = 0; |
| 406 |
|
| 407 |
while (!play) { |
| 408 |
PARSE_TOKEN(buffer); |
| 409 |
if (!stricmp(buffer, "play")) |
| 410 |
play = true; |
| 411 |
else if (!stricmp(buffer, "once")) { |
| 412 |
snddesc.caps |= TCSD_ONCE; |
| 413 |
snddesc.once = true; |
| 414 |
} else if (!stricmp(buffer, "starttime")) { |
| 415 |
snddesc.caps |= TCSD_WAITTIME; |
| 416 |
PARSE_FLOAT(snddesc.waittime); |
| 417 |
} else if (!stricmp(buffer, "isset")) { |
| 418 |
int value, bit = 0x01; |
| 419 |
PARSE_INT(value); |
| 420 |
if (value >= 0 && value < 32) { |
| 421 |
bit = bit << value; |
| 422 |
snddesc.mission_mask_set |= bit; |
| 423 |
} |
| 424 |
} else if (!stricmp(buffer, "isnset")) { |
| 425 |
int value, bit = 0x01; |
| 426 |
PARSE_INT(value); |
| 427 |
if (value >= 0 && value < 32) { |
| 428 |
bit = bit << value; |
| 429 |
snddesc.mission_mask_unset |= bit; |
| 430 |
} |
| 431 |
} else if (!stricmp(buffer, "desc")) { |
| 432 |
PARSE_STRING(d); |
| 433 |
} else |
| 434 |
ParseError("Illegal parameter in $SOUND"); |
| 435 |
} |
| 436 |
PARSE_STRING(snddesc.filename); |
| 437 |
if (AddSoundEffect) |
| 438 |
(*AddSoundEffect)(&snddesc, d); |
| 439 |
} break; |
| 440 |
case K_VOICE: { |
| 441 |
// define the voice for this screen |
| 442 |
bool play = false; |
| 443 |
char d[128]; |
| 444 |
d[0] = '\0'; |
| 445 |
if (current_screen == -1) |
| 446 |
ParseError("Voice keyword found outside a $screen block\n"); |
| 447 |
if (voice_def_screen) |
| 448 |
ParseError("A Voice is already defined for screen\n"); |
| 449 |
|
| 450 |
char buffer[_MAX_PATH]; |
| 451 |
char token[30]; |
| 452 |
int vflags = 0; |
| 453 |
bool bitdepthset = false; |
| 454 |
while (!play) { |
| 455 |
PARSE_TOKEN(token); |
| 456 |
if (!stricmp(token, "play")) |
| 457 |
play = true; |
| 458 |
else if (!stricmp(token, "8bit")) { |
| 459 |
vflags |= VF_8BIT; |
| 460 |
bitdepthset = true; |
| 461 |
} else if (!stricmp(token, "compressed")) { |
| 462 |
vflags |= VF_COMPRESSED; |
| 463 |
} else if (!stricmp(token, "stereo")) { |
| 464 |
vflags |= VF_STEREO; |
| 465 |
} else if (!stricmp(buffer, "isset")) { |
| 466 |
int value, bit = 0x01; |
| 467 |
PARSE_INT(value); |
| 468 |
if (value >= 0 && value < 32) { |
| 469 |
bit = bit << value; |
| 470 |
// snddesc.mission_mask_set |= bit; |
| 471 |
} |
| 472 |
} else if (!stricmp(buffer, "isnset")) { |
| 473 |
int value, bit = 0x01; |
| 474 |
PARSE_INT(value); |
| 475 |
if (value >= 0 && value < 32) { |
| 476 |
bit = bit << value; |
| 477 |
// snddesc.mission_mask_unset |= bit; |
| 478 |
} |
| 479 |
} else if (!stricmp(token, "desc")) { |
| 480 |
PARSE_STRING(d); |
| 481 |
} else |
| 482 |
ParseError("Illegal parameter in $VOICE"); |
| 483 |
} |
| 484 |
if (!bitdepthset) |
| 485 |
vflags |= VF_16BIT | VF_INTERUPT | VF_FORCE; |
| 486 |
|
| 487 |
PARSE_STRING(buffer); |
| 488 |
|
| 489 |
/* |
| 490 |
if(AddVoice) |
| 491 |
(*AddVoice)(buffer,flags); |
| 492 |
*/ |
| 493 |
|
| 494 |
voice_def_screen = true; |
| 495 |
} break; |
| 496 |
case K_POLY: { |
| 497 |
// add a poly effect |
| 498 |
char name[32]; |
| 499 |
float pos_x, pos_y, pos_z; |
| 500 |
float rot_x, rot_y, rot_z; |
| 501 |
float ori_x, ori_y, ori_z; |
| 502 |
|
| 503 |
PARSE_FLOAT(pos_x); |
| 504 |
PARSE_COMMA(); |
| 505 |
PARSE_FLOAT(pos_y); |
| 506 |
PARSE_COMMA(); |
| 507 |
PARSE_FLOAT(pos_z); |
| 508 |
|
| 509 |
PARSE_FLOAT(ori_x); |
| 510 |
PARSE_COMMA(); |
| 511 |
PARSE_FLOAT(ori_y); |
| 512 |
PARSE_COMMA(); |
| 513 |
PARSE_FLOAT(ori_z); |
| 514 |
|
| 515 |
PARSE_FLOAT(rot_x); |
| 516 |
PARSE_COMMA(); |
| 517 |
PARSE_FLOAT(rot_y); |
| 518 |
PARSE_COMMA(); |
| 519 |
PARSE_FLOAT(rot_z); |
| 520 |
|
| 521 |
PARSE_STRING(name); |
| 522 |
TCPOLYDESC polydesc; |
| 523 |
polydesc.caps = 0; |
| 524 |
polydesc.pos_x = pos_x; |
| 525 |
polydesc.pos_y = pos_y; |
| 526 |
polydesc.pos_z = pos_z; |
| 527 |
polydesc.ori_x = ori_x; |
| 528 |
polydesc.ori_y = ori_y; |
| 529 |
polydesc.ori_z = ori_z; |
| 530 |
polydesc.rot_x = rot_x; |
| 531 |
polydesc.rot_y = rot_y; |
| 532 |
polydesc.rot_z = rot_z; |
| 533 |
polydesc.mission_mask_set = 0; |
| 534 |
polydesc.mission_mask_unset = 0; |
| 535 |
strcpy(polydesc.polyname, name); |
| 536 |
if (AddPolyEffect) |
| 537 |
(*AddPolyEffect)(&polydesc, NULL); |
| 538 |
} break; |
| 539 |
case K_BUTTON: { |
| 540 |
if (!ParseButtonEffect(p)) |
| 541 |
goto done_parsing; |
| 542 |
} break; |
| 543 |
case K_SCREEN: { |
| 544 |
// define a screen |
| 545 |
char description[128]; |
| 546 |
char buffer[64]; |
| 547 |
bool done = false; |
| 548 |
bool layout_found = false; |
| 549 |
char layout_scr[_MAX_PATH]; |
| 550 |
uint32_t mission_mask_set = 0, mission_mask_unset = 0; |
| 551 |
description[0] = '\0'; |
| 552 |
PARSE_INT(current_screen); |
| 553 |
|
| 554 |
if ((current_screen < 0) || (current_screen >= MAX_TELCOM_SCREENS)) |
| 555 |
ParseError("Illegal Screen number\n"); |
| 556 |
|
| 557 |
while (!done) { |
| 558 |
PARSE_TOKEN(buffer); |
| 559 |
if (!stricmp(buffer, "start")) { |
| 560 |
done = 1; |
| 561 |
} else if (!stricmp(buffer, "desc")) { |
| 562 |
PARSE_STRING(description); |
| 563 |
} else if (!stricmp(buffer, "isset")) { |
| 564 |
int value, bit = 0x01; |
| 565 |
PARSE_INT(value); |
| 566 |
if (value >= 0 && value < 32) { |
| 567 |
bit = bit << value; |
| 568 |
mission_mask_set |= bit; |
| 569 |
} |
| 570 |
} else if (!stricmp(buffer, "isnset")) { |
| 571 |
int value, bit = 0x01; |
| 572 |
PARSE_INT(value); |
| 573 |
if (value >= 0 && value < 32) { |
| 574 |
bit = bit << value; |
| 575 |
mission_mask_unset |= bit; |
| 576 |
} |
| 577 |
} else if (!stricmp(buffer, "layout")) { |
| 578 |
PARSE_STRING(layout_scr); |
| 579 |
layout_found = true; |
| 580 |
} |
| 581 |
} |
| 582 |
|
| 583 |
if (StartScreen) |
| 584 |
(*StartScreen)(current_screen, description, (layout_found) ? layout_scr : NULL, mission_mask_set, |
| 585 |
mission_mask_unset); |
| 586 |
|
| 587 |
voice_def_screen = false; |
| 588 |
} break; |
| 589 |
case K_ENDSCREEN: { |
| 590 |
if ((current_screen >= 0) && (current_screen < MAX_TELCOM_SCREENS)) { |
| 591 |
if (EndScreen) |
| 592 |
(*EndScreen)(); |
| 593 |
} else { |
| 594 |
// invalid screen |
| 595 |
ParseError("Illegal screen number or missing $SCREEN\n"); |
| 596 |
} |
| 597 |
current_screen = -1; |
| 598 |
} break; |
| 599 |
case K_TEXT: { |
| 600 |
reading_text = true; |
| 601 |
text_ptr = text_buf; |
| 602 |
text_buffer_desc.text_id = -1; |
| 603 |
|
| 604 |
if (!ParseTextEffect(p, &text_buffer_desc)) |
| 605 |
goto done_parsing; |
| 606 |
} break; |
| 607 |
case K_ENDTEXT: { |
| 608 |
if (!reading_text) |
| 609 |
ParseError("Found $ENDTEXT without $TEXT"); |
| 610 |
reading_text = false; |
| 611 |
text_buffer_desc.textdesc.looping = false; |
| 612 |
text_buffer_desc.textdesc.caps |= TCTD_LOOPING; |
| 613 |
if (AddTextEffect) |
| 614 |
(*AddTextEffect)(&text_buffer_desc.textdesc, text_buf, text_buffer_desc.description, |
| 615 |
text_buffer_desc.text_id); |
| 616 |
text_buffer_desc.text_id = -1; |
| 617 |
text_ptr = NULL; |
| 618 |
} break; |
| 619 |
case K_BITMAP: { |
| 620 |
char buffer[64]; |
| 621 |
char d[128]; |
| 622 |
d[0] = '\0'; |
| 623 |
bool done = 0; |
| 624 |
bool found; |
| 625 |
float speed, starttime; |
| 626 |
int i; |
| 627 |
|
| 628 |
speed = 1.0f; |
| 629 |
starttime = 0; |
| 630 |
|
| 631 |
TCBMPDESC bmpdesc; |
| 632 |
bmpdesc.caps = 0; |
| 633 |
bmpdesc.type = TC_BMP_STATIC; |
| 634 |
bmpdesc.flags = 0; |
| 635 |
bmpdesc.mission_mask_set = 0; |
| 636 |
bmpdesc.mission_mask_unset = 0; |
| 637 |
while (!done) { |
| 638 |
PARSE_TOKEN(buffer); |
| 639 |
if (!stricmp(buffer, "show")) { |
| 640 |
done = 1; |
| 641 |
} else if (!stricmp(buffer, "no_early_rend")) { |
| 642 |
bmpdesc.flags |= TC_NOEARLYRENDER; |
| 643 |
} else if (!stricmp(buffer, "effect")) { |
| 644 |
found = false; |
| 645 |
i = 0; |
| 646 |
PARSE_TOKEN(buffer); |
| 647 |
while (!found) { |
| 648 |
if (!BitmapEffectstr[i]) |
| 649 |
found = true; |
| 650 |
else if (!strnicmp(BitmapEffectstr[i], buffer, strlen(BitmapEffectstr[i]))) { |
| 651 |
beffect = i; |
| 652 |
found = true; |
| 653 |
} |
| 654 |
i++; |
| 655 |
} |
| 656 |
bmpdesc.type = TC_BMP_STATIC; |
| 657 |
switch (beffect) { |
| 658 |
case bfxBLUR_IN: |
| 659 |
bmpdesc.type = TC_BMP_BLUR; |
| 660 |
bmpdesc.flags |= TC_BMPF_IN; |
| 661 |
break; |
| 662 |
case bfxBLUR_OUT: |
| 663 |
bmpdesc.type = TC_BMP_BLUR; |
| 664 |
bmpdesc.flags |= TC_BMPF_OUT; |
| 665 |
break; |
| 666 |
case bfxSCAN_IN: |
| 667 |
bmpdesc.type = TC_BMP_SCANLINE; |
| 668 |
bmpdesc.flags |= TC_BMPF_IN; |
| 669 |
break; |
| 670 |
case bfxSCAN_OUT: |
| 671 |
bmpdesc.type = TC_BMP_SCANLINE; |
| 672 |
bmpdesc.flags |= TC_BMPF_OUT; |
| 673 |
break; |
| 674 |
case bfxINVERT_IN: |
| 675 |
bmpdesc.type = TC_BMP_INVERT; |
| 676 |
bmpdesc.flags |= TC_BMPF_IN; |
| 677 |
break; |
| 678 |
case bfxINVERT_OUT: |
| 679 |
bmpdesc.type = TC_BMP_INVERT; |
| 680 |
bmpdesc.flags |= TC_BMPF_OUT; |
| 681 |
break; |
| 682 |
case bfxSTRETCH_IN: |
| 683 |
bmpdesc.type = TC_BMP_STRETCH; |
| 684 |
bmpdesc.flags |= TC_BMPF_IN; |
| 685 |
break; |
| 686 |
case bfxSTRETCH_OUT: |
| 687 |
bmpdesc.type = TC_BMP_STRETCH; |
| 688 |
bmpdesc.flags |= TC_BMPF_OUT; |
| 689 |
break; |
| 690 |
case bfxFADE_IN: |
| 691 |
case bfxFADE_OUT: |
| 692 |
default: |
| 693 |
bmpdesc.type |= TC_BMP_STATIC; |
| 694 |
break; |
| 695 |
} |
| 696 |
} else if (!stricmp(buffer, "speed")) { |
| 697 |
PARSE_FLOAT(speed); |
| 698 |
bmpdesc.speed = speed; |
| 699 |
bmpdesc.caps |= TCBD_SPEED; |
| 700 |
} else if (!stricmp(buffer, "starttime")) { |
| 701 |
PARSE_FLOAT(starttime); |
| 702 |
bmpdesc.waittime = starttime; |
| 703 |
bmpdesc.caps |= TCBD_WAITTIME; |
| 704 |
} else if (!stricmp(buffer, "position")) { |
| 705 |
PARSE_INT(x); |
| 706 |
PARSE_COMMA(); |
| 707 |
PARSE_INT(y); |
| 708 |
bmpdesc.caps |= TCBD_XY; |
| 709 |
bmpdesc.x = x; |
| 710 |
bmpdesc.y = y; |
| 711 |
} else if (!stricmp(buffer, "isset")) { |
| 712 |
int value, bit = 0x01; |
| 713 |
PARSE_INT(value); |
| 714 |
if (value >= 0 && value < 32) { |
| 715 |
bit = bit << value; |
| 716 |
bmpdesc.mission_mask_set |= bit; |
| 717 |
} |
| 718 |
} else if (!stricmp(buffer, "isnset")) { |
| 719 |
int value, bit = 0x01; |
| 720 |
PARSE_INT(value); |
| 721 |
if (value >= 0 && value < 32) { |
| 722 |
bit = bit << value; |
| 723 |
bmpdesc.mission_mask_unset |= bit; |
| 724 |
} |
| 725 |
} else if (!stricmp(buffer, "desc")) { |
| 726 |
PARSE_STRING(d); |
| 727 |
} else |
| 728 |
ParseError("Illegal parameter in $BITMAP"); |
| 729 |
} |
| 730 |
PARSE_STRING(filen); |
| 731 |
strcpy(bmpdesc.filename, filen); |
| 732 |
if (AddBmpEffect) |
| 733 |
(*AddBmpEffect)(&bmpdesc, d); |
| 734 |
} break; |
| 735 |
case K_MOVIE: { |
| 736 |
int x = 0, y = 0; |
| 737 |
char movie_name[128]; |
| 738 |
char d[128]; |
| 739 |
d[0] = '\0'; |
| 740 |
float fps = 20.0; |
| 741 |
TCMOVIEDESC moviedesc; |
| 742 |
float starttime = 0; |
| 743 |
moviedesc.caps = 0; |
| 744 |
bool done = false; |
| 745 |
char buffer[30]; |
| 746 |
moviedesc.caps = 0; |
| 747 |
moviedesc.mission_mask_set = 0; |
| 748 |
moviedesc.mission_mask_unset = 0; |
| 749 |
moviedesc.type = TC_MOVIE_STATIC; |
| 750 |
while (!done) { |
| 751 |
PARSE_TOKEN(buffer); |
| 752 |
|
| 753 |
if (!stricmp(buffer, "show")) { |
| 754 |
done = 1; |
| 755 |
} else if (!stricmp(buffer, "position")) { |
| 756 |
PARSE_INT(x); |
| 757 |
PARSE_COMMA(); |
| 758 |
PARSE_INT(y); |
| 759 |
moviedesc.x = x; |
| 760 |
moviedesc.y = y; |
| 761 |
moviedesc.caps |= TCMD_XY; |
| 762 |
} else if (!stricmp(buffer, "fps")) { |
| 763 |
PARSE_FLOAT(fps); |
| 764 |
moviedesc.fps = fps; |
| 765 |
moviedesc.caps |= TCMD_FPS; |
| 766 |
} else if (!stricmp(buffer, "looping")) { |
| 767 |
moviedesc.looping = true; |
| 768 |
moviedesc.caps |= TCMD_LOOPING; |
| 769 |
} else if (!stricmp(buffer, "starttime")) { |
| 770 |
PARSE_FLOAT(starttime); |
| 771 |
moviedesc.waittime = starttime; |
| 772 |
moviedesc.caps |= TCMD_WAITTIME; |
| 773 |
} else if (!stricmp(buffer, "isset")) { |
| 774 |
int value, bit = 0x01; |
| 775 |
PARSE_INT(value); |
| 776 |
if (value >= 0 && value < 32) { |
| 777 |
bit = bit << value; |
| 778 |
moviedesc.mission_mask_set |= bit; |
| 779 |
} |
| 780 |
} else if (!stricmp(buffer, "isnset")) { |
| 781 |
int value, bit = 0x01; |
| 782 |
PARSE_INT(value); |
| 783 |
if (value >= 0 && value < 32) { |
| 784 |
bit = bit << value; |
| 785 |
moviedesc.mission_mask_unset |= bit; |
| 786 |
} |
| 787 |
} else if (!stricmp(buffer, "desc")) { |
| 788 |
PARSE_STRING(d); |
| 789 |
} else |
| 790 |
ParseError("Illegal parameter in $MOVIE"); |
| 791 |
} |
| 792 |
|
| 793 |
PARSE_STRING(movie_name); |
| 794 |
strcpy(moviedesc.filename, movie_name); |
| 795 |
if (AddMovieEffect) |
| 796 |
(*AddMovieEffect)(&moviedesc, d); |
| 797 |
} break; |
| 798 |
case K_NONE: |
| 799 |
ParseError("Unknown keyword", p); |
| 800 |
break; |
| 801 |
default: |
| 802 |
Int3(); // Programming error: unknown keyword ID |
| 803 |
} |
| 804 |
continue; |
| 805 |
} else if (reading_text && text_ptr) { // a line of text |
| 806 |
if (text_ptr != text_buf) |
| 807 |
*text_ptr++ = '\n'; |
| 808 |
if (text_ptr - text_buf + strlen(linebuf) > sizeof(text_buf)) |
| 809 |
ParseError("Text buffer overflow"); |
| 810 |
else { |
| 811 |
strcpy(text_ptr, linebuf); |
| 812 |
text_ptr += strlen(text_ptr); |
| 813 |
} |
| 814 |
} else if ((linebuf[0] == ';') || (linebuf[0] == 0)) // Check for comment or blank line |
| 815 |
continue; |
| 816 |
else { |
| 817 |
// Not a comment, keyword, or text, so it's an error |
| 818 |
ParseError("Unexpected text on line", p); |
| 819 |
} |
| 820 |
} |
| 821 |
|
| 822 |
done_parsing:; |
| 823 |
|
| 824 |
if (abort) { |
| 825 |
mprintf(0, "Parse aborted\n"); |
| 826 |
} else if (!parse_error) { |
| 827 |
if (reading_text) { |
| 828 |
ParseError("Missing '$endtext'"); |
| 829 |
} else { |
| 830 |
mprintf(0, "Parse sucessful\n"); |
| 831 |
} |
| 832 |
} |
| 833 |
|
| 834 |
// Close the file |
| 835 |
cfclose(ifile); |
| 836 |
|
| 837 |
if (linebuf) { |
| 838 |
// make sure all memory is freed |
| 839 |
mem_free(linebuf); |
| 840 |
linebuf = NULL; |
| 841 |
} |
| 842 |
|
| 843 |
return PBERR_NOERR; |
| 844 |
} |
| 845 |
|
| 846 |
// Parses the keyword description for an OnScreenButton |
| 847 |
bool CBriefParse::ParseButtonEffect(const char *p) { |
| 848 |
int type = osbPREV_PAGE, ctype = oscCLICK_UP; |
| 849 |
// creates an input button |
| 850 |
int x, y, screen; |
| 851 |
int osflags = 0; |
| 852 |
char buffer[20]; |
| 853 |
bool show = false, flasher = false; |
| 854 |
int p_id = -1, s_id = -1; |
| 855 |
int id = -1; |
| 856 |
float flash_time = -1; |
| 857 |
char flash_name[256]; |
| 858 |
char flash_name_focus[256]; |
| 859 |
char d[128]; |
| 860 |
uint32_t mission_mask_set = 0, mission_mask_unset = 0; |
| 861 |
d[0] = '\0'; |
| 862 |
|
| 863 |
strcpy(flash_name, " "); |
| 864 |
strcpy(flash_name_focus, " "); |
| 865 |
screen = -1; |
| 866 |
|
| 867 |
PARSE_INT(x); |
| 868 |
PARSE_COMMA(); |
| 869 |
PARSE_INT(y); |
| 870 |
PARSE_TOKEN(buffer); |
| 871 |
|
| 872 |
while (!show) { |
| 873 |
if (!stricmp(buffer, "show")) |
| 874 |
show = true; |
| 875 |
else if (!stricmp(buffer, "flash")) { |
| 876 |
flasher = true; |
| 877 |
osflags |= OBF_FLASH; |
| 878 |
PARSE_FLOAT(flash_time); |
| 879 |
PARSE_STRING(flash_name); |
| 880 |
PARSE_STRING(flash_name_focus); |
| 881 |
} else if (!stricmp(buffer, "id")) { |
| 882 |
PARSE_INT(id); |
| 883 |
} else if (!stricmp(buffer, "parent_id")) { |
| 884 |
PARSE_INT(p_id); |
| 885 |
} else if (!stricmp(buffer, "sibling_id")) { |
| 886 |
PARSE_INT(s_id); |
| 887 |
} else if (!stricmp(buffer, "desc")) { |
| 888 |
PARSE_STRING(d); |
| 889 |
} else if (!stricmp(buffer, "type")) { |
| 890 |
char btype_buf[30]; |
| 891 |
bool found = false; |
| 892 |
int i = 0; |
| 893 |
|
| 894 |
PARSE_TOKEN(btype_buf); |
| 895 |
while (!found) { |
| 896 |
if (!OnScreenButtonTypes[i]) |
| 897 |
found = true; |
| 898 |
else if (!strnicmp(OnScreenButtonTypes[i], btype_buf, strlen(OnScreenButtonTypes[i]))) { |
| 899 |
type = i; |
| 900 |
found = true; |
| 901 |
} |
| 902 |
i++; |
| 903 |
} |
| 904 |
if (type == osbJUMP_PAGE) { |
| 905 |
// parse what screen to jump to |
| 906 |
PARSE_INT(screen); |
| 907 |
} |
| 908 |
} else if (!stricmp(buffer, "click")) { |
| 909 |
char ctype_buf[30]; |
| 910 |
bool found = false; |
| 911 |
int i = 0; |
| 912 |
|
| 913 |
PARSE_TOKEN(ctype_buf); |
| 914 |
while (!found) { |
| 915 |
if (!OnScreenButtonClickTypes[i]) |
| 916 |
found = true; |
| 917 |
else if (!strnicmp(OnScreenButtonClickTypes[i], ctype_buf, strlen(OnScreenButtonClickTypes[i]))) { |
| 918 |
ctype = i; |
| 919 |
found = true; |
| 920 |
} |
| 921 |
i++; |
| 922 |
} |
| 923 |
} else if (!stricmp(buffer, "isset")) { |
| 924 |
int value, bit = 0x01; |
| 925 |
PARSE_INT(value); |
| 926 |
if (value >= 0 && value < 32) { |
| 927 |
bit = bit << value; |
| 928 |
mission_mask_set |= bit; |
| 929 |
} |
| 930 |
} else if (!stricmp(buffer, "isnset")) { |
| 931 |
int value, bit = 0x01; |
| 932 |
PARSE_INT(value); |
| 933 |
if (value >= 0 && value < 32) { |
| 934 |
bit = bit << value; |
| 935 |
mission_mask_unset |= bit; |
| 936 |
} |
| 937 |
} else if (!stricmp(buffer, "glow")) { |
| 938 |
flasher = true; |
| 939 |
osflags |= OBF_GLOW; |
| 940 |
} else |
| 941 |
ParseError("Illegal parameter in $BUTTON"); |
| 942 |
|
| 943 |
if (!show) |
| 944 |
PARSE_TOKEN(buffer); |
| 945 |
} |
| 946 |
|
| 947 |
char name[256]; |
| 948 |
char name_focus[256]; |
| 949 |
PARSE_STRING(name); |
| 950 |
PARSE_STRING(name_focus); |
| 951 |
|
| 952 |
if (flasher && osflags == OBF_GLOW) { |
| 953 |
// see if user specified a glow, but gave no flash, so we need to get a filename |
| 954 |
PARSE_STRING(flash_name); |
| 955 |
PARSE_STRING(flash_name_focus); |
| 956 |
flash_time = -1; |
| 957 |
} |
| 958 |
|
| 959 |
// Fill in the button description struct |
| 960 |
TCBUTTONDESC desc; |
| 961 |
desc.sibling_id = s_id; |
| 962 |
desc.parent_id = p_id; |
| 963 |
desc.mission_mask_set = mission_mask_set; |
| 964 |
desc.mission_mask_unset = mission_mask_unset; |
| 965 |
|
| 966 |
// determine what type of button this is |
| 967 |
switch (type) { |
| 968 |
case osbDOWN_ARROW: |
| 969 |
desc.button_type = BUTT_DOWNARROW; |
| 970 |
break; |
| 971 |
case osbUP_ARROW: |
| 972 |
desc.button_type = BUTT_UPARROW; |
| 973 |
break; |
| 974 |
case osbNEXT_PAGE: |
| 975 |
desc.button_type = BUTT_NEXTPAGE; |
| 976 |
break; |
| 977 |
case osbPREV_PAGE: |
| 978 |
desc.button_type = BUTT_PREVPAGE; |
| 979 |
break; |
| 980 |
case osbQUIT: |
| 981 |
desc.button_type = BUTT_QUIT; |
| 982 |
break; |
| 983 |
case osbJUMP_PAGE: |
| 984 |
desc.button_type = BUTT_JUMP; |
| 985 |
desc.jump_page = screen; |
| 986 |
break; |
| 987 |
default: |
| 988 |
Int3(); // Illegal button type |
| 989 |
desc.button_type = BUTT_NEXTPAGE; |
| 990 |
break; |
| 991 |
}; |
| 992 |
|
| 993 |
// determine what type of click the button wants |
| 994 |
switch (ctype) { |
| 995 |
case oscHOLD_DOWN: |
| 996 |
desc.click_type = CLICKTYPE_DOWN; |
| 997 |
break; |
| 998 |
case oscCLICK_DOWN: |
| 999 |
desc.click_type = CLICKTYPE_CLICKDOWN; |
| 1000 |
break; |
| 1001 |
case oscCLICK_UP: |
| 1002 |
desc.click_type = CLICKTYPE_CLICKUP; |
| 1003 |
break; |
| 1004 |
default: |
| 1005 |
Int3(); // Illegal click type |
| 1006 |
desc.click_type = CLICKTYPE_CLICKUP; |
| 1007 |
break; |
| 1008 |
}; |
| 1009 |
|
| 1010 |
// fill in the rest of the information and create the button |
| 1011 |
desc.x = x; |
| 1012 |
desc.y = y; |
| 1013 |
strcpy(desc.filename, name); |
| 1014 |
strcpy(desc.filename_focus, name_focus); |
| 1015 |
strcpy(desc.flash_filename, flash_name); |
| 1016 |
strcpy(desc.flash_filename_focus, flash_name_focus); |
| 1017 |
desc.flash_time = flash_time; |
| 1018 |
desc.osflags = osflags; |
| 1019 |
desc.flasher = flasher; |
| 1020 |
|
| 1021 |
if (AddButtonEffect) |
| 1022 |
(*AddButtonEffect)(&desc, d, id); |
| 1023 |
return true; |
| 1024 |
|
| 1025 |
done_parsing: |
| 1026 |
return false; |
| 1027 |
} |
| 1028 |
|
| 1029 |
// Parses a text keyword description |
| 1030 |
bool CBriefParse::ParseTextEffect(const char *p, tTextBufferDesc *tbd) { |
| 1031 |
tbd->textdesc.caps = 0; |
| 1032 |
tbd->textdesc.type = TC_TEXT_STATIC; |
| 1033 |
tbd->textdesc.flags = 0; |
| 1034 |
tbd->textdesc.mission_mask_set = 0; |
| 1035 |
tbd->textdesc.mission_mask_unset = 0; |
| 1036 |
char buffer[64]; |
| 1037 |
bool done = 0; |
| 1038 |
bool found; |
| 1039 |
float speed, starttime; |
| 1040 |
int i, lx, rx, ty, by; |
| 1041 |
tbd->description[0] = '\0'; |
| 1042 |
|
| 1043 |
while (!done) { |
| 1044 |
PARSE_TOKEN(buffer); |
| 1045 |
|
| 1046 |
if (!stricmp(buffer, "show")) { |
| 1047 |
done = 1; |
| 1048 |
} else if (!stricmp(buffer, "id")) { |
| 1049 |
PARSE_INT(tbd->text_id); |
| 1050 |
} else if (!stricmp(buffer, "desc")) { |
| 1051 |
PARSE_STRING(tbd->description); |
| 1052 |
} else if (!stricmp(buffer, "isset")) { |
| 1053 |
int value, bit = 0x01; |
| 1054 |
PARSE_INT(value); |
| 1055 |
if (value >= 0 && value < 32) { |
| 1056 |
bit = bit << value; |
| 1057 |
tbd->textdesc.mission_mask_set |= bit; |
| 1058 |
} |
| 1059 |
} else if (!stricmp(buffer, "isnset")) { |
| 1060 |
int value, bit = 0x01; |
| 1061 |
PARSE_INT(value); |
| 1062 |
if (value >= 0 && value < 32) { |
| 1063 |
bit = bit << value; |
| 1064 |
tbd->textdesc.mission_mask_unset |= bit; |
| 1065 |
} |
| 1066 |
} else if (!stricmp(buffer, "tabstop")) { |
| 1067 |
tbd->textdesc.caps |= TCTD_TABSTOP; |
| 1068 |
} else if (!stricmp(buffer, "effect")) { |
| 1069 |
found = false; |
| 1070 |
i = 0; |
| 1071 |
PARSE_TOKEN(buffer); |
| 1072 |
while (!found) { |
| 1073 |
if (!TextEffectstr[i]) |
| 1074 |
found = true; |
| 1075 |
else if (!strnicmp(TextEffectstr[i], buffer, strlen(TextEffectstr[i]))) { |
| 1076 |
tbd->teffect = i; |
| 1077 |
found = true; |
| 1078 |
} |
| 1079 |
i++; |
| 1080 |
} |
| 1081 |
switch (tbd->teffect) { |
| 1082 |
case tfxFLASH: |
| 1083 |
tbd->textdesc.type = TC_TEXT_FLASH; |
| 1084 |
break; |
| 1085 |
case tfxSCROLL_L2R: |
| 1086 |
tbd->textdesc.type = TC_TEXT_SCROLL; |
| 1087 |
tbd->textdesc.flags = TC_TEXTF_L2R; |
| 1088 |
break; |
| 1089 |
case tfxSCROLL_R2L: |
| 1090 |
tbd->textdesc.type = TC_TEXT_SCROLL; |
| 1091 |
tbd->textdesc.flags = TC_TEXTF_R2L; |
| 1092 |
break; |
| 1093 |
case tfxSCROLL_T2B: |
| 1094 |
tbd->textdesc.type = TC_TEXT_SCROLL; |
| 1095 |
tbd->textdesc.flags = TC_TEXTF_T2B; |
| 1096 |
break; |
| 1097 |
case tfxSCROLL_B2T: |
| 1098 |
tbd->textdesc.type = TC_TEXT_SCROLL; |
| 1099 |
tbd->textdesc.flags = TC_TEXTF_B2T; |
| 1100 |
break; |
| 1101 |
case tfxFADE_IN: |
| 1102 |
tbd->textdesc.type = TC_TEXT_FADE; |
| 1103 |
tbd->textdesc.flags = TC_TEXTF_IN; |
| 1104 |
break; |
| 1105 |
case tfxFADE_OUT: |
| 1106 |
tbd->textdesc.type = TC_TEXT_FADE; |
| 1107 |
tbd->textdesc.flags = TC_TEXTF_OUT; |
| 1108 |
break; |
| 1109 |
case tfxFADE_IN_AND_OUT: |
| 1110 |
tbd->textdesc.type = TC_TEXT_FADE; |
| 1111 |
tbd->textdesc.flags = TC_TEXTF_PINGPONG; |
| 1112 |
break; |
| 1113 |
default: |
| 1114 |
break; |
| 1115 |
} |
| 1116 |
} else if (!stricmp(buffer, "scroll")) { |
| 1117 |
tbd->textdesc.caps |= TCTD_SCROLL; |
| 1118 |
} else if (!stricmp(buffer, "speed")) { |
| 1119 |
PARSE_FLOAT(speed); |
| 1120 |
tbd->textdesc.speed = speed; |
| 1121 |
tbd->textdesc.caps |= TCTD_SPEED; |
| 1122 |
} else if (!stricmp(buffer, "color")) { |
| 1123 |
int r, g, b; |
| 1124 |
PARSE_INT(r); |
| 1125 |
PARSE_COMMA(); |
| 1126 |
PARSE_INT(g); |
| 1127 |
PARSE_COMMA(); |
| 1128 |
PARSE_INT(b); |
| 1129 |
tbd->textdesc.color = GR_RGB(r, g, b); |
| 1130 |
tbd->textdesc.caps |= TCTD_COLOR; |
| 1131 |
} else if (!stricmp(buffer, "font")) { |
| 1132 |
char buffer[20]; |
| 1133 |
bool found = false; |
| 1134 |
int i = 0; |
| 1135 |
int feffect = 0; |
| 1136 |
int text_font; |
| 1137 |
|
| 1138 |
PARSE_TOKEN(buffer); |
| 1139 |
while (!found) { |
| 1140 |
if (!FontNames[i]) |
| 1141 |
found = true; |
| 1142 |
else if (!strnicmp(FontNames[i], buffer, strlen(FontNames[i]))) { |
| 1143 |
feffect = i; |
| 1144 |
found = true; |
| 1145 |
} |
| 1146 |
i++; |
| 1147 |
} |
| 1148 |
switch (feffect) { |
| 1149 |
case fntSMBRIEF: |
| 1150 |
text_font = BRIEF_FONT_INDEX; |
| 1151 |
break; |
| 1152 |
case fntLGBRIEF: |
| 1153 |
text_font = BBRIEF_FONT_INDEX; |
| 1154 |
break; |
| 1155 |
} |
| 1156 |
|
| 1157 |
tbd->textdesc.font = text_font; |
| 1158 |
tbd->textdesc.caps |= TCTD_FONT; |
| 1159 |
} else if (!stricmp(buffer, "starttime")) { |
| 1160 |
PARSE_FLOAT(starttime); |
| 1161 |
tbd->textdesc.waittime = starttime; |
| 1162 |
tbd->textdesc.caps |= TCTD_WAITTIME; |
| 1163 |
} else if (!stricmp(buffer, "box")) { |
| 1164 |
PARSE_INT(lx); |
| 1165 |
PARSE_COMMA(); |
| 1166 |
PARSE_INT(rx); |
| 1167 |
PARSE_COMMA(); |
| 1168 |
PARSE_INT(ty); |
| 1169 |
PARSE_COMMA(); |
| 1170 |
PARSE_INT(by); |
| 1171 |
tbd->textdesc.textbox.left = lx; |
| 1172 |
tbd->textdesc.textbox.right = rx; |
| 1173 |
tbd->textdesc.textbox.top = ty; |
| 1174 |
tbd->textdesc.textbox.bottom = by; |
| 1175 |
tbd->textdesc.caps |= TCTD_TEXTBOX; |
| 1176 |
} else |
| 1177 |
ParseError("Illegal parameter in $TEXT"); |
| 1178 |
} |
| 1179 |
|
| 1180 |
return true; |
| 1181 |
|
| 1182 |
done_parsing: |
| 1183 |
return false; |
| 1184 |
} |
| 1185 |
|
| 1186 |
// Generates an parsing error |
| 1187 |
void CBriefParse::ParseError(const char *msg, const char *p) { |
| 1188 |
mprintf(0, "ERROR, line %d: %s\n", linenum, msg); |
| 1189 |
if (p) { |
| 1190 |
mprintf(0, " %s\n", p); |
| 1191 |
} |
| 1192 |
|
| 1193 |
parse_error = 1; |
| 1194 |
} |
| 1195 |
|
| 1196 |
// Parses a keyword |
| 1197 |
const char *CBriefParse::ParseKeyword(const char *p, int *keyword_id) { |
| 1198 |
int i; |
| 1199 |
|
| 1200 |
*keyword_id = K_NONE; |
| 1201 |
|
| 1202 |
ASSERT(*p == '$'); |
| 1203 |
|
| 1204 |
for (i = 0, p++; i < NUM_KEYWORDS; i++) { |
| 1205 |
int len = strlen(keywords[i]); |
| 1206 |
|
| 1207 |
if (!strnicmp(p, keywords[i], len)) { |
| 1208 |
if (!isalnum(p[len])) { |
| 1209 |
*keyword_id = i; |
| 1210 |
return p + strlen(keywords[i]); |
| 1211 |
} |
| 1212 |
} |
| 1213 |
} |
| 1214 |
// Error -- return initial pointer |
| 1215 |
return p; |
| 1216 |
} |
| 1217 |
|
| 1218 |
// Removes whitespace from the start of the given string. |
| 1219 |
// Returns a pointer to the first non-white character |
| 1220 |
const char *CBriefParse::SkipWhite(const char *p) { |
| 1221 |
while (isspace(*p)) |
| 1222 |
p++; |
| 1223 |
|
| 1224 |
return p; |
| 1225 |
} |
| 1226 |
|
| 1227 |
// Parses a sequence of non-space characters |
| 1228 |
const char *CBriefParse::ParseToken(const char *p, char *buf, int bufsize) { |
| 1229 |
const char *save_p; |
| 1230 |
|
| 1231 |
p = SkipWhite(p); |
| 1232 |
|
| 1233 |
save_p = p; |
| 1234 |
|
| 1235 |
while (!isspace(*p) && (*p != ',') && *p && --bufsize) |
| 1236 |
*buf++ = *p++; |
| 1237 |
|
| 1238 |
*buf = 0; |
| 1239 |
|
| 1240 |
// Check for buffer overflow |
| 1241 |
if (bufsize <= 0) { |
| 1242 |
ParseError("Token too long", save_p); |
| 1243 |
return NULL; |
| 1244 |
} |
| 1245 |
|
| 1246 |
return p; |
| 1247 |
} |
| 1248 |
|
| 1249 |
// Parses a quoted string |
| 1250 |
// Returns true if got string ok, else false |
| 1251 |
const char *CBriefParse::ParseString(const char *p, char *buf, int bufsize) { |
| 1252 |
const char *save_p; |
| 1253 |
|
| 1254 |
p = SkipWhite(p); |
| 1255 |
|
| 1256 |
save_p = p; |
| 1257 |
|
| 1258 |
if (*p != '"') { |
| 1259 |
ParseError("Missing quote", p); |
| 1260 |
return NULL; |
| 1261 |
} else |
| 1262 |
p++; // skip initial quote |
| 1263 |
|
| 1264 |
// Copy chars until endquote or out of space |
| 1265 |
while (*p && (*p != '"') && --bufsize) |
| 1266 |
*buf++ = *p++; |
| 1267 |
|
| 1268 |
// Check for buffer overflow |
| 1269 |
if (bufsize <= 0) { |
| 1270 |
ParseError("String too long", save_p); |
| 1271 |
return NULL; |
| 1272 |
} |
| 1273 |
|
| 1274 |
// Check for missing endquote |
| 1275 |
if (!*p) { |
| 1276 |
ParseError("Missing endquote", save_p); |
| 1277 |
return NULL; |
| 1278 |
} |
| 1279 |
|
| 1280 |
// Write terminator |
| 1281 |
*buf = 0; |
| 1282 |
|
| 1283 |
// Return new pointer (move over a char for end quote) |
| 1284 |
return p + 1; |
| 1285 |
} |
| 1286 |
|
| 1287 |
// Parses an integer value |
| 1288 |
const char *CBriefParse::ParseInt(const char *p, int *i) { |
| 1289 |
const char *t; |
| 1290 |
bool got_digit = 0; |
| 1291 |
|
| 1292 |
t = p = SkipWhite(p); |
| 1293 |
|
| 1294 |
// Check for negative sign |
| 1295 |
if (*t == '-') |
| 1296 |
t++; |
| 1297 |
|
| 1298 |
// Check for valid characters in number |
| 1299 |
while (isdigit(*t)) { |
| 1300 |
t++; |
| 1301 |
got_digit = 1; |
| 1302 |
} |
| 1303 |
|
| 1304 |
// Make sure at least one digit |
| 1305 |
if (!got_digit) |
| 1306 |
ParseError("Expecting digit", p); |
| 1307 |
|
| 1308 |
// Check for valid seperator, and convert |
| 1309 |
if ((*t == 0) || isspace(*t) || (*t == ',')) { // valid number |
| 1310 |
*i = atoi(p); |
| 1311 |
return t; |
| 1312 |
} else { |
| 1313 |
ParseError("Invalid character in integer", p); |
| 1314 |
return NULL; |
| 1315 |
} |
| 1316 |
} |
| 1317 |
|
| 1318 |
// Parses a floating-point value |
| 1319 |
const char *CBriefParse::ParseFloat(const char *p, float *f) { |
| 1320 |
const char *t; |
| 1321 |
bool got_digit = 0; |
| 1322 |
|
| 1323 |
t = p = SkipWhite(p); |
| 1324 |
|
| 1325 |
// Check for negative sign |
| 1326 |
if (*t == '-') |
| 1327 |
t++; |
| 1328 |
|
| 1329 |
// Check for valid characters in number |
| 1330 |
while (isdigit(*t)) { |
| 1331 |
got_digit = 1; |
| 1332 |
t++; |
| 1333 |
} |
| 1334 |
|
| 1335 |
// Check for decimal point |
| 1336 |
if (*t == '.') { |
| 1337 |
t++; |
| 1338 |
|
| 1339 |
// Check for more digits |
| 1340 |
while (isdigit(*t)) { |
| 1341 |
got_digit = 1; |
| 1342 |
t++; |
| 1343 |
} |
| 1344 |
} |
| 1345 |
|
| 1346 |
// Make sure at least one digit |
| 1347 |
if (!got_digit) { |
| 1348 |
ParseError("Expecting digit", p); |
| 1349 |
return NULL; |
| 1350 |
} |
| 1351 |
|
| 1352 |
// Check for valid seperator, and convert |
| 1353 |
if ((*t == 0) || isspace(*t) || (*t == ',')) { // valid number |
| 1354 |
*f = atof(p); |
| 1355 |
return t; |
| 1356 |
} else { |
| 1357 |
ParseError("Invalid character in floating-point number", p); |
| 1358 |
return NULL; |
| 1359 |
} |
| 1360 |
} |
| 1361 |
|
| 1362 |
// Parses a comma |
| 1363 |
const char *CBriefParse::ParseComma(const char *p) { |
| 1364 |
p = SkipWhite(p); |
| 1365 |
|
| 1366 |
if (*p != ',') { |
| 1367 |
ParseError("Comma expected"); |
| 1368 |
return NULL; |
| 1369 |
} |
| 1370 |
|
| 1371 |
return p + 1; |
| 1372 |
} |