1 #include <stdio.h>
2 #include <strings.h>
3 
4 #include "handwave.h"
5 #include "internal.h"
6 
7 static char bigbuf[512];
8 
9 void log_text();
10 
init_transcript(self)11 void init_transcript(self)
12 struct realgame *self;
13 {
14     self->gamelog_size = 4096;
15     self->gamelog = (char *)malloc(sizeof(char) * self->gamelog_size);
16     strcpy(self->gamelog, "");
17     self->gamelog_pos = 0;
18 
19     log_text(self, "Spellcast Game Transcript\n\n");
20 }
21 
log_text(self,str)22 void log_text(self, str)
23 struct realgame *self;
24 char *str;
25 {
26     int len;
27 
28     if (!str)
29 	return;
30     len = strlen(str);
31     if (len+self->gamelog_pos >= self->gamelog_size) {
32 	while (len+self->gamelog_pos >= self->gamelog_size) {
33 	    self->gamelog_size *= 2;
34 	}
35 	self->gamelog = (char *)realloc(self->gamelog, sizeof(char) * self->gamelog_size);
36     }
37 
38     strcpy(self->gamelog+self->gamelog_pos, str);
39     self->gamelog_pos += len;
40 }
41 
LogInTranscript(pgame,str)42 void LogInTranscript(pgame, str)
43 game *pgame;
44 char *str;
45 {
46     log_text((struct realgame *)pgame, str);
47 }
48 
cheap_untranslate(val)49 static char cheap_untranslate(val)
50 int val;
51 {
52     switch (val) {
53 	case Gesture_PALM:
54 	    return 'P';
55 	case Gesture_DIGIT:
56 	    return 'D';
57 	case Gesture_FINGERS:
58 	    return 'F';
59 	case Gesture_WAVE:
60 	    return 'W';
61 	case Gesture_SNAP:
62 	    return 'S';
63 	case Gesture_CLAPHALF:
64 	    return 'C';
65 	case Gesture_KNIFE:
66 	    return 'K';
67 	case Gesture_NOTHING:
68 	    return '.';
69 	case Gesture_ANTISPELL:
70 	    return '=';
71 	default:
72 	    return '?';
73     }
74 }
75 
log_round_header(self)76 void log_round_header(self)
77 struct realgame *self;
78 {
79     char *cx;
80     int ix, gnum;
81 
82     switch (self->turntype) {
83 	case Turn_TIMESTOP:
84 	    cx = " (Time Stop)";
85 	    break;
86 	case Turn_HASTE:
87 	    cx = " (Haste)";
88 	    break;
89 	default:
90 	    cx = "";
91 	    break;
92     }
93 
94     sprintf(bigbuf, "\n\tTurn %d%s:\n", self->turn, cx);
95     log_text(self, bigbuf);
96 
97     for (ix=0; ix<self->numplayers; ix++) {
98 	struct wizard *wiz = self->wiz[ix];
99 	if (wiz->alive) {
100 	    if (self->turnactive[ix]) {
101 		gnum = wiz->numgests-1;
102 		sprintf(bigbuf, "%s (%d): %c %c\n", wiz->name, wiz->hitpoints,
103 				cheap_untranslate(wiz->gests[gnum].did[0]),
104 				cheap_untranslate(wiz->gests[gnum].did[1]));
105 	    }
106 	    else {
107 		sprintf(bigbuf, "%s (%d): [no gestures]\n", wiz->name,
108 				wiz->hitpoints);
109 	    }
110 	    log_text(self, bigbuf);
111 	}
112     }
113     for (ix=0; ix<self->numcres; ix++) {
114 	struct creature *thud = &(self->cre[ix]);
115 	if (thud->alive) {
116 	    sprintf(bigbuf, "%s (%d)\n", thud->name, thud->hitpoints);
117 	    log_text(self, bigbuf);
118 	}
119     }
120     log_text(self, "\n");
121 }
122 
123 #define ABBREVLEN (8)
124 
WriteTranscript(pgame,f)125 void WriteTranscript(pgame, f)
126 game *pgame;
127 FILE *f;
128 {
129     struct realgame *self = (struct realgame *)pgame;
130 
131     fputs(self->gamelog, f);
132 }
133