Debian Codegraph @

terps/scott/ai_uk/seasofblood.c

raw symbols SCIP
1 //
2 // seasofblood.c
3 // Part of ScottFree, an interpreter for adventures in Scott Adams format
4 //
5 // Created by Petter Sjölund on 2022-01-08.
6 //
7
8 #include <ctype.h>
9 #include <stdarg.h>
10 #include <stdlib.h>
11 #include <string.h>
12
13 #include "sagadraw.h"
14 #include "scott.h"
15 #include "seasofblood.h"
16
17 #include "decompresstext.h"
18
19 winid_t LeftDiceWin, RightDiceWin, BattleRight;
20 glui32 background_colour;
21
22 extern const char *battle_messages[33];
23 extern uint8_t enemy_table[126];
24 uint8_t *blood_image_data;
25 extern uint8_t buffer[384][9];
26
27 #define VICTORY 0
28 #define LOSS 1
29 #define DRAW 2
30 #define FLEE 3
31 #define ERROR 99
32
33 glui32 dice_pixel_size, dice_x_offset, dice_y_offset;
34
35 int get_enemy_stats(int *strike, int *stamina, int *boatflag);
36 void battle_loop(int strike, int stamina, int boatflag);
37 void swap_stamina_and_crew_strength(void);
38 void blood_battle(void);
39
40 void AdventureSheet(void)
41 {
42 glk_stream_set_current(glk_window_get_stream(Bottom));
43 glk_set_style(style_Preformatted);
44 Output("\nADVENTURE SHEET\n\n");
45 Output("SKILL :");
46 OutputNumber(9);
47 Output(" STAMINA :");
48 OutputNumber(Counters[3]);
49 Output("\nLOG :");
50 OutputNumber(Counters[6]);
51 if (Counters[6] < 10)
52 Output(" PROVISIONS :");
53 else
54 Output(" PROVISIONS :"); // one less space!
55 OutputNumber(Counters[5]);
56 Output("\nCREW STRIKE:");
57 OutputNumber(9);
58 Output(" CREW STRENGTH:");
59 OutputNumber(Counters[7]);
60 Output("\n\n * * * * * * * * * * * * * * * * * * * * *\n\n");
61 ListInventory(0);
62 Output("\n");
63 glk_set_style(style_Normal);
64 }
65
66 void BloodAction(int p)
67 {
68 switch (p) {
69 case 0:
70 break;
71 case 1:
72 // Update LOG
73 Counters[6]++;
74 break;
75 case 2:
76 // Battle
77 Look();
78 Output("You are attacked \n");
79 Output("<HIT ENTER> \n");
80 HitEnter();
81 blood_battle();
82 break;
83 default:
84 fprintf(stderr, "Unhandled special action %d!\n", p);
85 break;
86 }
87 }
88
89 #pragma mark Image drawing
90
91 void mirror_left_half(void)
92 {
93 for (int line = 0; line < 12; line++) {
94 for (int col = 32; col > 16; col--) {
95 buffer[line * 32 + col - 1][8] = buffer[line * 32 + (32 - col)][8];
96 for (int pixrow = 0; pixrow < 8; pixrow++)
97 buffer[line * 32 + col - 1][pixrow] = buffer[line * 32 + (32 - col)][pixrow];
98 Flip(buffer[line * 32 + col - 1]);
99 }
100 }
101 }
102
103 void replace_colour(uint8_t before, uint8_t after)
104 {
105
106 // I don't think any of the data has bit 7 set,
107 // so masking it is probably unnecessary, but this is what
108 // the original code does.
109 uint8_t beforeink = before & 7;
110 uint8_t afterink = after & 7;
111 uint8_t inkmask = 0x07;
112
113 uint8_t beforepaper = beforeink << 3;
114 uint8_t afterpaper = afterink << 3;
115 uint8_t papermask = 0x38;
116
117 for (int j = 0; j < 384; j++) {
118 if ((buffer[j][8] & inkmask) == beforeink) {
119 buffer[j][8] = (buffer[j][8] & ~inkmask) | afterink;
120 }
121
122 if ((buffer[j][8] & papermask) == beforepaper) {
123 buffer[j][8] = (buffer[j][8] & ~papermask) | afterpaper;
124 }
125 }
126 }
127
128 void draw_colour(uint8_t x, uint8_t y, uint8_t colour, uint8_t length)
129 {
130 for (int i = 0; i < length; i++) {
131 buffer[y * 32 + x + i][8] = colour;
132 }
133 }
134
135 void make_light(void)
136 {
137 for (int i = 0; i < 384; i++) {
138 buffer[i][8] = buffer[i][8] | 0x40;
139 }
140 }
141
142 void flip_image(void)
143 {
144
145 uint8_t mirror[384][9];
146
147 for (int line = 0; line < 12; line++) {
148 for (int col = 32; col > 0; col--) {
149 for (int pixrow = 0; pixrow < 9; pixrow++)
150 mirror[line * 32 + col - 1][pixrow] = buffer[line * 32 + (32 - col)][pixrow];
151 Flip(mirror[line * 32 + col - 1]);
152 }
153 }
154
155 memcpy(buffer, mirror, 384 * 9);
156 }
157
158 int should_draw_object_images;
159
160 void draw_object_image(uint8_t x, uint8_t y)
161 {
162 for (int i = 0; i < GameHeader.NumItems; i++) {
163 if (Items[i].Flag != MyLoc)
164 continue;
165 if (Items[i].Location != MyLoc)
166 continue;
167 DrawSagaPictureAtPos(Items[i].Image, x, y);
168 should_draw_object_images = 0;
169 }
170 }
171
172 void draw_blood(int loc)
173 {
174 memset(buffer, 0, 384 * 9);
175 uint8_t *ptr = blood_image_data;
176 for (int i = 0; i < loc; i++) {
177 while (*(ptr) != 0xff)
178 ptr++;
179 ptr++;
180 }
181 while (ptr < blood_image_data + 2010) {
182 switch (*ptr) {
183 case 0xff:
184 if (loc == 13) {
185 buffer[8 * 32 + 18][8] = buffer[8 * 32 + 18][8] & ~0x40;
186 buffer[8 * 32 + 17][8] = buffer[8 * 32 + 17][8] & ~0x40;
187
188 buffer[8 * 32 + 9][8] = buffer[8 * 32 + 9][8] & ~0x40;
189 buffer[8 * 32 + 10][8] = buffer[8 * 32 + 10][8] & ~0x40;
190 }
191 return;
192 case 0xfe:
193 mirror_left_half();
194 break;
195 case 0xfD:
196 replace_colour(*(ptr + 1), *(ptr + 2));
197 ptr += 2;
198 break;
199 case 0xfc: // Draw colour: x, y, attribute, length
200 draw_colour(*(ptr + 1), *(ptr + 2), *(ptr + 3), *(ptr + 4));
201 ptr = ptr + 4;
202 break;
203 case 0xfb: // Make all screen colours bright
204 make_light();
205 break;
206 case 0xfa: // Flip entire image horizontally
207 flip_image();
208 break;
209 case 0xf9: // Draw object image (if present) at x, y
210 draw_object_image(*(ptr + 1), *(ptr + 2));
211 ptr = ptr + 2;
212 break;
213 default: // else draw image *ptr at x, y
214 DrawSagaPictureAtPos(*ptr, *(ptr + 1), *(ptr + 2));
215 ptr = ptr + 2;
216 }
217 ptr++;
218 }
219 }
220
221 void SeasOfBloodRoomImage(void)
222 {
223 should_draw_object_images = 1;
224 draw_blood(MyLoc);
225 for (int ct = 0; ct <= GameHeader.NumItems; ct++)
226 if (Items[ct].Image && should_draw_object_images) {
227 if ((Items[ct].Flag & 127) == MyLoc && Items[ct].Location == MyLoc) {
228 DrawImage(Items[ct].Image);
229 }
230 }
231 DrawSagaPictureFromBuffer();
232 }
233
234 #pragma mark Battles
235
236 static void SOBPrint(winid_t w, const char *fmt, ...)
237 #ifdef __GNUC__
238 __attribute__((__format__(__printf__, 2, 3)))
239 #endif
240 ;
241
242 static void SOBPrint(winid_t w, const char *fmt, ...)
243 {
244 va_list ap;
245 char msg[2048];
246
247 int size = sizeof msg;
248
249 va_start(ap, fmt);
250 vsnprintf(msg, size, fmt, ap);
251 va_end(ap);
252
253 glk_put_string_stream(glk_window_get_stream(w), msg);
254 }
255
256 static glui32 optimal_dice_pixel_size(glui32 *width, glui32 *height)
257 {
258 int ideal_width = 8;
259 int ideal_height = 8;
260
261 *width = ideal_width;
262 *height = ideal_height;
263 int multiplier = 1;
264 glui32 graphwidth, graphheight;
265 glk_window_get_size(LeftDiceWin, &graphwidth, &graphheight);
266 multiplier = graphheight / ideal_height;
267 if ((glui32)(ideal_width * multiplier) > graphwidth)
268 multiplier = graphwidth / ideal_width;
269
270 if (multiplier < 2)
271 multiplier = 2;
272
273 multiplier = multiplier / 2;
274
275 *width = ideal_width * multiplier;
276 *height = ideal_height * multiplier;
277
278 return multiplier;
279 }
280
281 static void draw_border(winid_t win)
282 {
283 glui32 width, height;
284 glk_stream_set_current(glk_window_get_stream(win));
285 glk_window_get_size(win, &width, &height);
286 height--;
287 width -= 2;
288 glk_window_move_cursor(win, 0, 0);
289 glk_put_char_uni(0x250F); // Top left corner
290 for (glui32 i = 1; i < width; i++)
291 glk_put_char_uni(0x2501); // Top
292 glk_put_char_uni(0x2513); // Top right corner
293 for (glui32 i = 1; i < height; i++) {
294 glk_window_move_cursor(win, 0, i);
295 glk_put_char_uni(0x2503);
296 glk_window_move_cursor(win, width, i);
297 glk_put_char_uni(0x2503);
298 }
299 glk_window_move_cursor(win, 0, height);
300 glk_put_char_uni(0x2517);
301 for (glui32 i = 1; i < width; i++)
302 glk_put_char_uni(0x2501);
303 glk_put_char_uni(0x251B);
304 }
305
306 static void redraw_static_text(winid_t win, int boatflag)
307 {
308 glk_stream_set_current(glk_window_get_stream(win));
309 glk_window_move_cursor(win, 2, 4);
310
311 if (boatflag) {
312 glk_put_string("STRIKE :\n");
313 glk_window_move_cursor(win, 2, 5);
314 glk_put_string("CRW STR :");
315 } else {
316 glk_put_string("SKILL :\n");
317 glk_window_move_cursor(win, 2, 5);
318 glk_put_string("STAMINA :");
319 }
320
321 if (win == BattleRight) {
322 glui32 width;
323 glk_window_get_size(BattleRight, &width, 0);
324 glk_window_move_cursor(BattleRight, width - 6, 1);
325 glk_put_string("YOU");
326 }
327 }
328
329 static void redraw_battle_screen(int boatflag)
330 {
331 glui32 graphwidth, graphheight, optimal_width, optimal_height;
332
333 glk_window_get_size(LeftDiceWin, &graphwidth, &graphheight);
334
335 dice_pixel_size = optimal_dice_pixel_size(&optimal_width, &optimal_height);
336 dice_x_offset = (graphwidth - optimal_width) / 2;
337 dice_y_offset = (graphheight - optimal_height - dice_pixel_size) / 2;
338
339 draw_border(Top);
340 draw_border(BattleRight);
341
342 redraw_static_text(Top, boatflag);
343 redraw_static_text(BattleRight, boatflag);
344 }
345
346 static void setup_battle_screen(int boatflag)
347 {
348 winid_t parent = glk_window_get_parent(Top);
349 glk_window_set_arrangement(parent, winmethod_Above | winmethod_Fixed, 7, Top);
350
351 glk_window_clear(Top);
352 glk_window_clear(Bottom);
353 BattleRight = glk_window_open(Top, winmethod_Right | winmethod_Proportional,
354 50, wintype_TextGrid, 0);
355
356 LeftDiceWin = glk_window_open(Top, winmethod_Right | winmethod_Proportional,
357 30, wintype_Graphics, 0);
358 RightDiceWin = glk_window_open(BattleRight, winmethod_Left | winmethod_Proportional, 30,
359 wintype_Graphics, 0);
360
361 /* Set the graphics window background to match
362 * the top window background, best as we can,
363 * and clear the window.
364 */
365 if (glk_style_measure(Top, style_Normal, stylehint_BackColor,
366 &background_colour)) {
367 glk_window_set_background_color(LeftDiceWin, background_colour);
368 glk_window_set_background_color(RightDiceWin, background_colour);
369
370 glk_window_clear(LeftDiceWin);
371 glk_window_clear(RightDiceWin);
372 }
373
374 if (palchosen >= C64A)
375 dice_colour = 0x5f48e9;
376 else
377 dice_colour = 0xff0000;
378
379 redraw_battle_screen(boatflag);
380 }
381
382 void blood_battle(void)
383 {
384 int enemy, strike, stamina, boatflag;
385 enemy = get_enemy_stats(&strike, &stamina, &boatflag); // Determine their stats
386 if (enemy == 0) {
387 fprintf(stderr, "Seas of blood battle: No enemy in location?\n");
388 return;
389 }
390 setup_battle_screen(boatflag);
391 battle_loop(strike, stamina, boatflag); // Into the battle loops
392 if (boatflag)
393 swap_stamina_and_crew_strength(); // Switch back stamina - crew strength
394 glk_window_close(LeftDiceWin, NULL);
395 glk_window_close(RightDiceWin, NULL);
396 glk_window_close(BattleRight, NULL);
397 CloseGraphicsWindow();
398 OpenGraphicsWindow();
399 SeasOfBloodRoomImage();
400 }
401
402 int get_enemy_stats(int *strike, int *stamina, int *boatflag)
403 {
404 int enemy, i = 0;
405 while (i < 124) {
406 enemy = enemy_table[i];
407 if (Items[enemy].Location == MyLoc) {
408 i++;
409 *strike = enemy_table[i++];
410 *stamina = enemy_table[i++];
411 *boatflag = enemy_table[i];
412 if (*boatflag) {
413 swap_stamina_and_crew_strength(); // Switch stamina - crew strength
414 }
415
416 return enemy;
417 }
418 i = i + 4; // Skip to next entry
419 }
420 return 0;
421 }
422
423 void draw_rect(winid_t win, int32_t x, int32_t y, int32_t width, int32_t height,
424 int32_t color)
425 {
426 glk_window_fill_rect(win, color, x * dice_pixel_size + dice_x_offset,
427 y * dice_pixel_size + dice_y_offset,
428 width * dice_pixel_size, height * dice_pixel_size);
429 }
430
431 void draw_graphical_dice(winid_t win, int number)
432 {
433 // The eye-less dice backgrounds consist of two rectangles on top of each
434 // other
435 draw_rect(win, 1, 2, 7, 5, dice_colour);
436 draw_rect(win, 2, 1, 5, 7, dice_colour);
437
438 switch (number + 1) {
439 case 1:
440 draw_rect(win, 4, 4, 1, 1, background_colour);
441 break;
442 case 2:
443 draw_rect(win, 2, 6, 1, 1, background_colour);
444 draw_rect(win, 6, 2, 1, 1, background_colour);
445 break;
446 case 3:
447 draw_rect(win, 2, 6, 1, 1, background_colour);
448 draw_rect(win, 4, 4, 1, 1, background_colour);
449 draw_rect(win, 6, 2, 1, 1, background_colour);
450 break;
451 case 4:
452 draw_rect(win, 2, 6, 1, 1, background_colour);
453 draw_rect(win, 6, 2, 1, 1, background_colour);
454 draw_rect(win, 2, 2, 1, 1, background_colour);
455 draw_rect(win, 6, 6, 1, 1, background_colour);
456 break;
457 case 5:
458 draw_rect(win, 2, 6, 1, 1, background_colour);
459 draw_rect(win, 6, 2, 1, 1, background_colour);
460 draw_rect(win, 2, 2, 1, 1, background_colour);
461 draw_rect(win, 6, 6, 1, 1, background_colour);
462 draw_rect(win, 4, 4, 1, 1, background_colour);
463 break;
464 case 6:
465 draw_rect(win, 2, 6, 1, 1, background_colour);
466 draw_rect(win, 6, 2, 1, 1, background_colour);
467 draw_rect(win, 2, 2, 1, 1, background_colour);
468 draw_rect(win, 2, 4, 1, 1, background_colour);
469 draw_rect(win, 6, 4, 1, 1, background_colour);
470 draw_rect(win, 6, 6, 1, 1, background_colour);
471 break;
472 default:
473 break;
474 }
475 }
476
477 void update_dice(int our_turn, int left_dice, int right_dice)
478 {
479 left_dice--;
480 right_dice--;
481 glk_window_clear(LeftDiceWin);
482 glk_window_clear(RightDiceWin);
483
484 dice_x_offset = dice_x_offset - dice_pixel_size;
485 draw_graphical_dice(LeftDiceWin, left_dice);
486 dice_x_offset = dice_x_offset + dice_pixel_size;
487 draw_graphical_dice(RightDiceWin, right_dice);
488
489 winid_t win = our_turn ? BattleRight : Top;
490
491 glk_window_move_cursor(win, 2, 1);
492
493 glk_stream_set_current(glk_window_get_stream(win));
494
495 glk_put_char_uni(0x2680 + left_dice);
496 glk_put_char('+');
497 glk_put_char_uni(0x2680 + right_dice);
498
499 glk_window_move_cursor(win, 2, 2);
500 SOBPrint(win, "%d %d", left_dice + 1, right_dice + 1);
501 }
502
503 void print_sum(int our_turn, int sum, int strike)
504 {
505 winid_t win = our_turn ? BattleRight : Top;
506 glk_stream_set_current(glk_window_get_stream(win));
507
508 glk_window_move_cursor(win, 6, 1);
509
510 SOBPrint(win, "+ %d = %d", strike, sum);
511
512 glk_stream_set_current(glk_window_get_stream(BattleRight));
513 glk_window_move_cursor(BattleRight, 6, 1);
514 glk_put_string("+ 9 = ");
515 }
516
517 void update_result(int our_turn, int strike, int stamina, int boatflag)
518 {
519 winid_t win = our_turn ? BattleRight : Top;
520 glk_stream_set_current(glk_window_get_stream(win));
521
522 glk_window_move_cursor(win, 2, 4);
523
524 if (boatflag) {
525 SOBPrint(win, "STRIKE : %d\n", strike);
526 glk_window_move_cursor(win, 2, 5);
527 SOBPrint(win, "CRW STR : %d", stamina);
528 } else {
529 SOBPrint(win, "SKILL : %d\n", strike);
530 glk_window_move_cursor(win, 2, 5);
531 SOBPrint(win, "STAMINA : %d", stamina);
532 }
533 }
534
535 void clear_result(void)
536 {
537 winid_t win = Top;
538
539 glui32 width;
540 for (int j = 0; j < 2; j++) {
541 glk_window_get_size(win, &width, 0);
542 glk_stream_set_current(glk_window_get_stream(win));
543
544 glk_window_move_cursor(win, 11, 1);
545 for (int i = 0; i < 10; i++)
546 glk_put_string(" ");
547 draw_border(win);
548 win = BattleRight;
549 }
550 }
551
552 void clear_stamina(void)
553 {
554 winid_t win = Top;
555
556 glui32 width;
557 for (int j = 0; j < 2; j++) {
558 glk_window_get_size(win, &width, 0);
559 glk_stream_set_current(glk_window_get_stream(win));
560
561 glk_window_move_cursor(win, 11, 5);
562 for (int i = 0; i < (int)width - 13; i++)
563 glk_put_string(" ");
564 draw_border(win);
565 win = BattleRight;
566 }
567 }
568
569 static void RearrangeBattleDisplay(int strike, int stamina, int boatflag)
570 {
571 UpdateSettings();
572 glk_cancel_char_event(Top);
573 CloseGraphicsWindow();
574 glk_window_close(BattleRight, NULL);
575 glk_window_close(LeftDiceWin, NULL);
576 glk_window_close(RightDiceWin, NULL);
577 SeasOfBloodRoomImage();
578 setup_battle_screen(boatflag);
579 update_result(0, strike, stamina, boatflag);
580 update_result(1, 9, Counters[3], boatflag);
581 draw_border(Top);
582 draw_border(BattleRight);
583 redraw_static_text(Top, boatflag);
584 redraw_static_text(BattleRight, boatflag);
585 glk_request_char_event(Top);
586 }
587
588 int roll_dice(int strike, int stamina, int boatflag)
589 {
590 clear_result();
591 redraw_static_text(BattleRight, boatflag);
592
593 glk_request_timer_events(60);
594 int rolls = 0;
595 int our_turn = 0;
596 int left_dice = 1 + rand() % 6;
597 int right_dice = 1 + rand() % 6;
598 int our_result;
599 int their_result = 0;
600 int their_dice_stopped = 0;
601
602 event_t event;
603 int enemy_rolls = 20 + rand() % 10;
604 glk_cancel_char_event(Top);
605 glk_request_char_event(Top);
606
607 glk_stream_set_current(glk_window_get_stream(Bottom));
608 glk_put_string("Their throw");
609
610 int delay = 60;
611
612 while (1) {
613 glk_select(&event);
614 if (event.type == evtype_Timer) {
615 if (their_dice_stopped) {
616 glk_request_timer_events(60);
617 their_dice_stopped = 0;
618 print_sum(our_turn, their_result, strike);
619 our_turn = 1;
620 glk_cancel_char_event(Top);
621 glk_stream_set_current(glk_window_get_stream(Bottom));
622 SOBPrint(Bottom, "\n");
623 glk_window_clear(Bottom);
624 glk_put_string("Your throw\n<ENTER> to stop dice");
625 if (!boatflag)
626 glk_put_string(" <X> to run");
627 glk_request_char_event(Top);
628 } else if (our_turn == 0) {
629 glk_request_timer_events((glui32)delay);
630 }
631
632 rolls++;
633
634 if (rolls & 1)
635 left_dice = 1 + rand() % 6;
636 else
637 right_dice = 1 + rand() % 6;
638
639 update_dice(our_turn, left_dice, right_dice);
640 if (our_turn == 0 && rolls == enemy_rolls) {
641 SOBPrint(Bottom, "\n");
642 glk_window_clear(Bottom);
643 their_result = left_dice + right_dice + strike;
644 SOBPrint(Bottom, "Their result: %d + %d + %d = %d\n", left_dice,
645 right_dice, strike, their_result);
646 glk_request_timer_events(1000);
647 their_dice_stopped = 1;
648 }
649 }
650
651 if (event.type == evtype_CharInput) {
652 if (our_turn && (event.val1 == keycode_Return)) {
653 update_dice(our_turn, left_dice, right_dice);
654 our_result = left_dice + right_dice + 9;
655 print_sum(our_turn, our_result, 9);
656 SOBPrint(Bottom, "\nYour result: %d + %d + %d = %d\n", left_dice,
657 right_dice, strike, our_result);
658 if (their_result > our_result) {
659 return LOSS;
660 } else if (our_result > their_result) {
661 return VICTORY;
662 } else {
663 return DRAW;
664 }
665 } else if (MyLoc != 1 && (event.val1 == 'X' || event.val1 == 'x')) {
666 MyLoc = SavedRoom;
667 return FLEE;
668 } else {
669 glk_request_char_event(Top);
670 }
671 }
672 if (event.type == evtype_Arrange) {
673 RearrangeBattleDisplay(strike, stamina, boatflag);
674 }
675 }
676 return ERROR;
677 }
678
679 void BattleHitEnter(int strike, int stamina, int boatflag)
680 {
681 glk_request_char_event(Bottom);
682 event_t ev;
683 int result = 0;
684 do {
685 glk_select(&ev);
686 if (ev.type == evtype_CharInput) {
687 if (ev.val1 == keycode_Return) {
688 result = 1;
689 } else {
690 glk_request_char_event(Bottom);
691 }
692 }
693
694 if (ev.type == evtype_Arrange) {
695 RearrangeBattleDisplay(strike, stamina, boatflag);
696 }
697
698 } while (result == 0);
699 return;
700 }
701
702 void battle_loop(int strike, int stamina, int boatflag)
703 {
704 update_result(0, strike, stamina, boatflag);
705 update_result(1, 9, Counters[3], boatflag);
706 do {
707 int result = roll_dice(strike, stamina, boatflag);
708 glk_cancel_char_event(Top);
709 SOBPrint(Bottom, "\n");
710 glk_window_clear(Bottom);
711 clear_stamina();
712 glk_stream_set_current(glk_window_get_stream(Bottom));
713 if (result == LOSS) {
714 Counters[3] -= 2;
715
716 if (Counters[3] <= 0) {
717 SOBPrint(Bottom, "%s",
718 boatflag ? "THE BANSHEE HAS BEEN SUNK!"
719 : "YOU HAVE BEEN KILLED!");
720 Counters[3] = 0;
721 SetBitFlag(6);
722 Counters[7] = 0;
723 } else {
724 SOBPrint(Bottom, "%s", battle_messages[1 + rand() % 5 + 16 * boatflag]);
725 }
726 } else if (result == VICTORY) {
727 stamina -= 2;
728 if (stamina <= 0) {
729 glk_put_string("YOU HAVE WON!");
730 ClearBitFlag(6);
731 stamina = 0;
732 } else {
733 SOBPrint(Bottom, "%s", battle_messages[6 + rand() % 5 + 16 * boatflag]);
734 }
735 } else if (result == FLEE) {
736 SetBitFlag(6);
737 MyLoc = SavedRoom;
738 return;
739 } else {
740 SOBPrint(Bottom, "%s", battle_messages[11 + rand() % 5 + 16 * boatflag]);
741 }
742
743 if (Counters[3] > 0 && stamina > 0) {
744 glk_put_string("\n\n<ENTER> to roll dice");
745 if (!boatflag)
746 glk_put_string(" <X> to run");
747 }
748
749 update_result(0, strike, stamina, boatflag);
750 update_result(1, 9, Counters[3], boatflag);
751
752 BattleHitEnter(strike, stamina, boatflag);
753 SOBPrint(Bottom, "\n\n");
754 glk_window_clear(Bottom);
755
756 } while (stamina > 0 && Counters[3] > 0);
757 }
758
759 void swap_stamina_and_crew_strength(void)
760 {
761 uint8_t temp = Counters[7]; // Crew strength
762 Counters[7] = Counters[3]; // Stamina
763 Counters[3] = temp;
764 }
765
766 extern int draw_to_buffer;
767
768 void LoadExtraSeasOfBloodData(int c64)
769 {
770 draw_to_buffer = 1;
771
772 #pragma mark Enemy table
773
774 int offset = file_baseline_offset + ((c64 == 1) ? 0x3fee: 0x47b7);
775
776 uint8_t *ptr = SeekToPos(entire_file, offset);
777
778 int ct;
779
780 for (ct = 0; ct < 124; ct++) {
781 enemy_table[ct] = *(ptr++);
782 if (enemy_table[ct] == 0xff)
783 break;
784 }
785
786 #pragma mark Battle messages
787
788 offset = file_baseline_offset + ((c64 == 1) ? 0x82f6 : 0x71da);
789
790 ptr = SeekToPos(entire_file, offset);
791
792 for (int i = 0; i < 32; i++) {
793 battle_messages[i] = DecompressText(ptr, i);
794 }
795
796 #pragma mark Extra image data
797
798 offset = file_baseline_offset + ((c64 == 1) ? 0x5299: 0x3b10);
799
800 int data_length = 2010;
801
802 blood_image_data = MemAlloc(data_length);
803
804 ptr = SeekToPos(entire_file, offset);
805
806 memcpy(blood_image_data, ptr, data_length);
807
808 #pragma mark System messages
809
810 if (c64 == 1) {
811 SysMessageType messagekey[] = {
812 NORTH,
813 SOUTH,
814 EAST,
815 WEST,
816 UP,
817 DOWN,
818 EXITS,
819 YOU_SEE,
820 YOU_ARE,
821 YOU_CANT_GO_THAT_WAY,
822 OK,
823 WHAT_NOW,
824 HUH,
825 YOU_HAVE_IT,
826 YOU_HAVENT_GOT_IT,
827 DROPPED,
828 TAKEN,
829 INVENTORY,
830 YOU_DONT_SEE_IT,
831 THATS_BEYOND_MY_POWER,
832 DIRECTION,
833 YOURE_CARRYING_TOO_MUCH,
834 PLAY_AGAIN,
835 RESUME_A_SAVED_GAME,
836 YOU_CANT_DO_THAT_YET,
837 I_DONT_UNDERSTAND,
838 NOTHING
839 };
840
841 for (int i = 0; i < 27; i++) {
842 sys[messagekey[i]] = system_messages[i];
843 }
844 } else {
845 for (int i = I_DONT_UNDERSTAND; i <= THATS_BEYOND_MY_POWER; i++)
846 sys[i] = system_messages[4 - I_DONT_UNDERSTAND + i];
847
848 for (int i = YOU_ARE; i <= HIT_ENTER; i++)
849 sys[i] = system_messages[13 - YOU_ARE + i];
850
851 sys[OK] = system_messages[2];
852 sys[PLAY_AGAIN] = system_messages[3];
853 sys[YOURE_CARRYING_TOO_MUCH] = system_messages[27];
854
855 Items[125].Text = "A loose plank";
856 Items[125].AutoGet = "PLAN";
857 }
858 }