1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496
|
/* File: cmovie.c */
/* Purpose: play cmovie files -DarkGod-Improv- */
#include "angband.h"
/*
* Play a given cmovie
*/
s16b do_play_cmovie(cptr cmov_file)
{
FILE *fff;
int y, line = 0, x;
int delay;
char *s;
char buf[1024];
char cbuf[90];
char ch;
char mode = 0;
/* Cmovie files are moved to the user directory on the multiuser systems */
/* Build the filename */
path_build(buf, 1024, ANGBAND_DIR_CMOV, cmov_file);
/* File type is "TEXT" */
FILE_TYPE(FILE_TYPE_TEXT);
/* Read the file */
fff = my_fopen(buf, "r");
/* Failure */
if (!fff) return ( -1);
/* Save screen */
character_icky = TRUE;
Term_save();
Term_clear();
/* Give some usefull info */
prt("While viewing the movie you can press Escape to exit, t/Space to switch between", 0, 0);
prt("fluid more and step by step mode and any other key to step a frame in step by", 1, 0);
prt("step mode.", 2, 0);
prt("You can press D to do an html screenshot of the current frame.", 3, 0);
prt("You can also use + and - to speed up/down the playing speed.", 5, 0);
prt("Press any key when ready.", 8, 0);
inkey();
Term_clear();
line = -1;
delay = 1;
/* Init to white */
for (x = 0; x < 80; x++)
{
cbuf[x] = 'w';
}
/* Parse */
while (0 == my_fgets(fff, buf, 1024))
{
/* Do not wait */
inkey_scan = TRUE;
ch = inkey();
/* Stop */
if (ch == ESCAPE) break;
/* Change mode */
else if (ch == 't')
{
mode = FALSE;
}
else if (ch == ' ')
{
mode = TRUE;
}
/* Change speed */
else if (ch == '+')
{
delay--;
if (delay < 0) delay = 0;
}
else if (ch == '-')
{
delay++;
if (delay > 5) delay = 5;
}
else if (ch == 'D')
{
do_cmd_html_dump();
}
line++;
/* Skip comments and blank lines */
if (!buf[0] || (buf[0] == '#')) continue;
/* Verify correct "colon" format */
if (buf[1] != ':') break;
/* Clean screen */
if (buf[0] == 'C')
{
Term_clear();
/* Next */
continue;
}
/* Displays a textbox */
if (buf[0] == 'B')
{
int len = strlen(buf + 2);
/* Clear the line */
Term_erase(0, 0, 255);
/* Display the message */
c_put_str(TERM_VIOLET, "###", 0, 0);
c_put_str(TERM_ORANGE, buf + 2, 0, 3);
c_put_str(TERM_VIOLET, "###", 0, 3 + len);
c_put_str(TERM_WHITE, "(more)", 0, 6 + len);
/* Next */
continue;
}
/* Wait a key */
if (buf[0] == 'W')
{
inkey();
/* Next */
continue;
}
/* Sleep */
if (buf[0] == 'S')
{
long msec;
/* Scan for the values */
if (1 != sscanf(buf + 2, "%ld:", &msec))
{
return ( -2);
}
if (!mode)
{
Term_xtra(TERM_XTRA_DELAY, msec);
}
else
{
bool_ stop = FALSE;
while (TRUE)
{
ch = inkey();
/* Stop */
if (ch == ESCAPE)
{
stop = TRUE;
break;
}
/* Change mode */
else if (ch == 't')
{
mode = FALSE;
break;
}
/* Change mode */
else if (ch == ' ')
{
if (mode) continue;
mode = TRUE;
break;
}
/* Change speed */
else if (ch == '+')
{
delay--;
if (delay < 0) delay = 0;
}
else if (ch == '-')
{
delay++;
if (delay > 5) delay = 5;
}
else if (ch == 'D')
{
do_cmd_html_dump();
}
else break;
}
if (stop) break;
}
/* Next */
continue;
}
/* Get color for the NEXT L line */
if (buf[0] == 'E')
{
/* Find the colon before the name */
s = strchr(buf + 2, ':');
/* Verify that colon */
if (!s) return ( -2);
/* Nuke the colon, advance to the name */
*s++ = '\0';
/* Paranoia -- require a name */
if (!*s) return ( -2);
/* Get the index */
y = atoi(buf + 2);
C_COPY(cbuf, s, 80, char);
/* Next... */
continue;
}
/* Print a line */
if (buf[0] == 'L')
{
/* Find the colon before the name */
s = strchr(buf + 2, ':');
/* Verify that colon */
if (!s) return ( -2);
/* Nuke the colon, advance to the name */
*s++ = '\0';
/* Paranoia -- require a name */
if (!*s) return ( -2);
/* Get the index */
y = atoi(buf + 2);
for (x = 0; x < 80; x++)
{
Term_putch(x, y, color_char_to_attr(cbuf[x]), s[x]);
/* Reinit to white */
cbuf[x] = 'w';
}
Term_redraw_section(0, y, 79, y);
/* Next... */
continue;
}
/* Update 1 char */
if (buf[0] == 'P')
{
int x, y, a, c;
/* Scan for the values */
if (4 != sscanf(buf + 2, "%d:%d:%d:%d",
&x, &y, &c, &a))
{
a = 'w';
if (3 != sscanf(buf + 2, "%d:%d:%d",
&x, &y, &c)) return ( -2);
}
Term_putch(x, y, color_char_to_attr(cbuf[x]), c);
Term_redraw_section(x, y, x + 1, y + 1);
/* Next... */
continue;
}
}
/* Load screen */
Term_load();
character_icky = FALSE;
/* Close */
my_fclose(fff);
return (0);
}
/*
* Start the recording of a cmovie
*/
void do_record_cmovie(cptr cmovie)
{
char buf[1024];
int fd = -1;
int y;
/* Build the filename */
path_build(buf, 1024, ANGBAND_DIR_CMOV, cmovie);
/* File type is "TEXT" */
FILE_TYPE(FILE_TYPE_TEXT);
/* Check for existing file */
fd = fd_open(buf, O_RDONLY);
/* Existing file */
if (fd >= 0)
{
char out_val[160];
/* Close the file */
(void)fd_close(fd);
/* Build query */
(void)sprintf(out_val, "Replace existing file %s? ", cmovie);
/* Ask */
if (get_check(out_val)) fd = -1;
}
/* Be sure */
if (!get_check("Ready to record(Press ctrl+D to enter a textual note while recording)?")) return;
/* Open the non-existing file */
if (fd < 0) movfile = my_fopen(buf, "w");
/* Invalid file */
if (movfile == NULL)
{
msg_format("Cmovie recording failed!");
return;
}
/* First thing: Record clear screen then enable the recording */
fprintf(movfile, "# Generated by %s\n",
get_version_string());
fprintf(movfile, "C:\n");
last_paused = 0;
do_movies = 1;
cmovie_init_second();
/* Mega Hack, get the screen */
for (y = 0; y < Term->hgt; y++)
{
cmovie_record_line(y);
}
}
/*
* Stop the recording
*/
void do_stop_cmovie()
{
if (do_movies == 1)
{
do_movies = 0;
my_fclose(movfile);
}
}
/*
* Start a cmovie
*/
void do_start_cmovie()
{
char name[90], rname[94];
/* Should never happen */
if (do_movies == 1) return;
/* Default */
sprintf(name, "%s", player_base);
if (get_string("Cmovie name: ", name, 80))
{
if (name[0] && (name[0] != ' '))
{
sprintf(rname, "%s.cmv", name);
if (get_check("Record(y), Play(n)?")) do_record_cmovie(rname);
else do_play_cmovie(rname);
}
}
}
void cmovie_clean_line(int y, char *abuf, char *cbuf)
{
const byte *ap = Term->scr->a[y];
const char *cp = Term->scr->c[y];
byte a;
char c;
int x;
int wid, hgt;
int screen_wid, screen_hgt;
/* Retrieve current screen size */
Term_get_size(&wid, &hgt);
/* Calculate the size of dungeon map area */
screen_wid = wid - (COL_MAP + 1);
screen_hgt = hgt - (ROW_MAP + 1);
/* For the time being, assume 80 column display XXX XXX XXX */
for (x = 0; x < wid; x++)
{
/* Convert dungeon map into default attr/chars */
if (!character_icky &&
((x - COL_MAP) >= 0) &&
((x - COL_MAP) < screen_wid) &&
((y - ROW_MAP) >= 0) &&
((y - ROW_MAP) < screen_hgt))
{
/* Retrieve default attr/char */
map_info_default(y + panel_row_prt, x + panel_col_prt, &a, &c);
abuf[x] = conv_color[a & 0xf];
if (c == '\0') cbuf[x] = ' ';
else cbuf[x] = c;
}
else
{
abuf[x] = conv_color[ap[x] & 0xf];
cbuf[x] = cp[x];
}
}
/* Null-terminate the prepared strings */
abuf[x] = '\0';
cbuf[x] = '\0';
}
/*
* Write a record of a screen row into a cmovie file
*/
void cmovie_record_line(int y)
{
char abuf[256];
char cbuf[256];
cmovie_clean_line(y, abuf, cbuf);
/* Write a colour record */
fprintf(movfile, "E:%d:%.80s\n", y, abuf);
/* Write a char record */
fprintf(movfile, "L:%d:%.80s\n", y, cbuf);
}
/*
* Record a "text box"
*/
void do_cmovie_insert()
{
char buf[81] = "";
/* Dont record */
do_movies = 2;
while (get_string("Textbox(ESC to end): ", buf, 80))
{
fprintf(movfile, "B:%s\nW:\n", buf);
buf[0] = '\0';
}
/* We reinit the time as to not count the time the user needed ot enter the text */
cmovie_init_second();
/* Continue recording */
do_movies = 1;
}
|