This repository has been archived by the owner on Oct 27, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 7
/
toheart_etc.c
461 lines (415 loc) · 10.5 KB
/
toheart_etc.c
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
/*
* LEAF Visual Novel System For X
* (c) Copyright 1999,2000 Go Watanabe mailto:[email protected]
* All rights reserverd.
*
* ORIGINAL LVNS (c) Copyright 1996-1999 LEAF/AQUAPLUS Inc.
*
* $Id: toheart_etc.c,v 1.30 2001/08/20 14:15:26 tf Exp $
*/
/*
* ToHeart 各種処理ルーチン
*/
#include <stdio.h>
#include <stdlib.h>
#include "toheart.h"
/*
* ToHeart キャラ/背景合成処理
*/
void
ToHeartMergeCharacter(Lvns *lvns)
{
static int xpos[3] = { 0, 320, 160 };
ToHeartState *state = (ToHeartState *)lvns->system_state;
int bgtime = lvns->bg_no / 50;
int cno = lvns->vram->palette_num;
if (state->title) {
lvnsimage_set_palette3(lvns->vram,
state->title->palette, cno,
state->title->palette_num);
lvnsimage_add_mask(state->title, lvns->vram, 0, 0,
state->title_mask, cno);
lvns->vram->palette_num += state->title->palette_num;
} else {
int i;
for (i=0;i<2;i++) {
int pos = state->colflag[i];
if (pos >= 0 && state->character[pos]) {
lvnsimage_set_palette4(lvns->vram,
state->charpal[lvns->character_no[pos]>>8][bgtime],
cno, 48);
lvnsimage_add4(state->character[pos],
lvns->vram, xpos[pos], 0, cno);
cno = lvns->vram->palette_num = cno + 48;
}
}
}
}
/*
* ToHeart 画像消去
*/
void
ToHeartClearScreen(Lvns *lvns)
{
ToHeartLoadBG(lvns, 0);
ToHeartClearCharacter(lvns, 3);
}
static void
set_colflag(Lvns *lvns, int pos)
{
ToHeartState *state = (ToHeartState *)lvns->system_state;
if (state->colflag[0] < 0 || state->colflag[0] == pos) {
state->colflag[0] = pos;
} else if (state->colflag[1] < 0 || state->colflag[1] == pos) {
state->colflag[1] = pos;
} else {
fprintf(stderr, "warning: can't load 3 characters");
}
}
/*
* ToHeart キャラクタロード
*/
void
ToHeartLoadCharacter(Lvns *lvns, int no, int pos)
{
ToHeartState *state = (ToHeartState *)lvns->system_state;
char name[100];
if (no == 0xffff) {
ToHeartClearCharacter(lvns, pos);
return;
}
/* あかり専用処理 */
if ((no >> 8) == 0) {
if ((state->flag[TOHEART_FLAG_AKARI] & 0x01)) { /* 髪型変更 */
no |= 0x80;
}
no |= 0x100;
}
sprintf(name, "C%04x.LF2", no);
lvnsimage_delete(state->character[pos]);
state->character[pos] = LvnsLoadImage(lvns, name, NULL);
set_colflag(lvns, pos);
lvns->character_no[pos] = no;
}
static void
clear_colflag(Lvns *lvns, int pos)
{
ToHeartState *state = (ToHeartState *)lvns->system_state;
if (state->colflag[0] == pos)
state->colflag[0] = -1;
if (state->colflag[1] == pos)
state->colflag[1] = -1;
}
/*
* ToHeart キャラクタ消去
*/
void
ToHeartClearCharacter(Lvns *lvns, int pos)
{
ToHeartState *state = (ToHeartState *)lvns->system_state;
if (pos > 2) {
int i;
lvnsimage_delete(state->title);
state->title = NULL;
for (i=0;i<3;i++) {
lvnsimage_delete(state->character[i]);
state->character[i] = NULL;
lvns->character_no[i] = NOCHARACTER;
}
state->colflag[0] = -1;
state->colflag[1] = -1;
} else {
lvnsimage_delete(state->character[pos]);
state->character[pos] = NULL;
clear_colflag(lvns, pos);
lvns->character_no[pos] = NOCHARACTER;
}
}
/*
* ToHeart 背景画像ロード
*/
void
ToHeartLoadBG(Lvns *lvns, int no)
{
static u_char haikeiflag[] = { 'D', 'E', 'N', 'X', };
static char name[20] = "S%02dD.LF2";
lvns->bg_type = LVNS_BACKGROUND;
lvns->bg_no = no;
if (no == 0) {
lvnsimage_clear(lvns->background);
} else if (no == 254) {
char pal[] = {255,255,255};
lvnsimage_set_palette(lvns->background, pal, 1);
lvnsimage_clear_index(lvns->background, 0);
} else {
name[5] = haikeiflag[no / 50];
LvnsLoadBackground(lvns, name, no % 50);
}
ToHeartClearCharacter(lvns, 3);
}
/*
* ToHeart 通常ビジュアルシーンロード
*/
void
ToHeartLoadVisual(Lvns *lvns, int no)
{
ToHeartState *state = (ToHeartState *)lvns->system_state;
lvns->bg_type = LVNS_VISUAL;
lvns->bg_no = no;
if (no == 0) {
lvnsimage_clear(lvns->background);
} else {
/* あかりの髪型処理… */
if ((no == 0x11 || no == 0x13) &&
(state->flag[TOHEART_FLAG_AKARI] & 0x01)) {
no = 0x12;
}
/* レミィパンティ */
if (no == 0x80) {
}
LvnsLoadBackground(lvns, "V%02x.LF2", no);
}
ToHeartClearCharacter(lvns, 3);
}
/*
* ToHeart Hビジュアルシーンロード
*/
void
ToHeartLoadHVisual(Lvns *lvns, int no)
{
lvns->bg_type = LVNS_HCG;
lvns->bg_no = no;
LvnsLoadBackground(lvns, "H%02x.LF2", no);
ToHeartClearCharacter(lvns, 3);
}
/*
* ToHeart シナリオのテキストロード
*/
void
ToHeartSetTextScenarioState(Lvns *lvns, int no)
{
ToHeartState *state = (ToHeartState *)lvns->system_state;
/* 既読情報登録 */
if (!lvns->seen_mode &&
!(state->seen_flag[lvns->scn_current/8] & (1 << (lvns->scn_current%8)))) {
lvns->seen = False;
if (!lvns->force_skip)
lvns->skip = False; /* すっ飛ばし解除 */
lvns->fast_text = False;
} else {
lvns->seen = True;
if (lvns->fast_when_seen)
lvns->fast_text = True; /* 見た文書は速く表示する */
}
}
void
ToHeartLoadScenario(Lvns *lvns, int no, int blk)
{
ToHeartState *state = (ToHeartState *)lvns->system_state;
/* 現在のシナリオを既読化… */
state->seen_flag[lvns->scn_current/8] |= (1 << (lvns->scn_current%8));
LvnsLoadScenario(lvns, no, blk);
}
#ifndef USE_MGL
static void
drawChar(Lvns *lvns, int x, int y, int code, int attr)
{
u_char *data = lvns->leaf_font_data + (code - 1) * 24 * 3;
lvns->putPattern2(lvns, x+1, y+1, TOHEART_COL_BLACK, data);
lvns->putPattern2(lvns, x+2, y+1, TOHEART_COL_BLACK, data);
if (!attr)
lvns->putPattern2(lvns, x, y, TOHEART_COL_WHITE, data);
else
lvns->putPattern2(lvns, x, y, TOHEART_COL_GRAY, data);
}
#else
static void
drawChar(Lvns *lvns, int x, int y, int code, int attr)
{
static int black[] = {
COLOR_TRANSPARENT, COLOR_BLACK, COLOR_BLACK, COLOR_BLACK
};
static int gray[] = {
COLOR_TRANSPARENT, 0x00000006, 0x00000007, 0x0000008
};
static int white[] = {
COLOR_TRANSPARENT, 0x00000008, 0x0000000c, 0x000000f
};
#ifdef FONT_PLUS
if( lvns->font){
x += MGL_XOFFSET;
code--;
lvnsfont_draw( lvns->font, x + 1, y + 1, code, black);
if( !attr){
lvnsfont_draw( lvns->font, x, y, code, white);
} else {
lvnsfont_draw( lvns->font, x, y, code, gray);
}
} else {
#endif /* FONT_PLUS */
char buf[3];
#if 0
if (lvns->skip && !attr)
MglGetEvent(lvns, 1);
#endif
buf[0] = lvns->leaf_to_euc[code * 2];
buf[1] = lvns->leaf_to_euc[code * 2 + 1];
buf[2] = 0;
x += MGL_XOFFSET;
set_font(12, 0);
set_color(COLOR_BLACK);
draw_string(x + 1, y + 1, buf, DIR_NORTH);
draw_string(x + 2, y + 1, buf, DIR_NORTH);
if (!attr) {
set_color(COLOR_WHITE);
} else {
set_color(COLOR_LIGHTGRAY);
}
draw_string(x, y, buf, DIR_NORTH);
#ifdef FONT_PLUS
}
#endif /* FONT_PLUS */
}
#endif
/*
* 仮想 VRAM に直接 EUC 文字列を描画
*/
#ifndef USE_MGL
void
ToHeartPutsVRAM(Lvns *lvns, int x, int y, const u_char *str, int idx)
{
int code;
u_char *data;
while (*str) {
code = ((str[0]&0x7f)-33) * 94 + (str[1]&0x7f)-33;
code = lvns->jis_to_leaf[code];
data = lvns->leaf_font_data + (code - 1) * 24 * 3;
lvnsimage_put_pattern24(lvns->vram, x, y, idx, data);
x += 24;
str += 2;
}
}
#else
void
ToHeartPutsVRAM(Lvns *lvns, int x, int y, const u_char *str, int color)
{
mglimage_draw_string(lvns->vram, x, y, str, color);
}
#endif
/*
* テキストレイヤに直接 EUC 文字列を描画
*/
void
ToHeartPutsTEXT(Lvns *lvns, int x, int y, const u_char *str, int attr)
{
int code;
u_char *data;
while (*str) {
code = ((str[0]&0x7f)-33) * 94 + (str[1]&0x7f)-33;
code = lvns->jis_to_leaf[code];
drawChar(lvns, x, y, code, attr);
x += 24;
str += 2;
}
}
static
LvnsCommandInfo command[] = {
{ "select", False }, /* 次の選択肢までとばす */
{ "image", False }, /* 画像表示 */
{ "before", False }, /* 前の選択肢まで戻る */
{ "title", False }, /* タイトルに戻る */
{ NULL, False }
};
LvnsCommandInfo *
ToHeartGetCommandList(Lvns *lvns)
{
command[0].enable =
command[1].enable =
command[2].enable =
command[3].enable = False;
#if 0
if (lvns->scn_func == ToHeartScenarioEngine) {
if (LVNSSTATE == LVNS_WAIT_KEY ||
LVNSSTATE == LVNS_WAIT_PAGE ||
LVNSSTATE == LVNS_WAIT_SELECT) {
if (!lvns->select_mode) {
command[0].enable = True;
}
command[1].enable =
command[2].enable =
command[3].enable = True;
}
}
#endif
return command;
}
void
ToHeartExecCommand(Lvns *lvns, const char *command)
{
if (!strcmp(command, "select")) {
LvnsSkipTillSelect(lvns);
} else if (!strcmp(command, "image")) {
LvnsImageMode(lvns);
} else if (!strcmp(command, "before")) {
/* 選択肢に戻る */
ToHeartState *state = (ToHeartState*)lvns->system_state;
lvns->savepoint = lvns->selectpoint;
memcpy(state->flag_save, state->flag_select, sizeof state->flag);
} else if (!strcmp(command, "title")) {
/* タイトルに戻る */
}
}
void KizuatoJingle(Lvns *lvns);
extern MenuData toheart_menu;
static LvnsSystemState toheart_state_base = {
#ifndef USE_MGL
640,
480,
#else
320,
240,
#endif
235, /* XXX */
"LVNS3DAT.PAK",
"LVNS3SCN.PAK",
"%04x.SCN",
"thfont.tbl",
&toheart_menu,
ToHeartStart,
KizuatoJingle,
ToHeartOpening,
ToHeartTitle,
ToHeartMain,
ToHeartMergeCharacter,
ToHeartClearScreen,
ToHeartLoadBG,
ToHeartGetCommandList,
ToHeartExecCommand,
drawChar,
ToHeartDispHistory,
#if !defined(USE_MGL) || defined(FONT_PLUS)
250, /* キー入力待ち */
253 /* 改ページ待ち */
#else
2770, /* キー入力待ち */
1, /* 改ページ待ち */
#endif
};
void ToHeartInitialize(Lvns *lvns)
{
ToHeartState *state =
(ToHeartState *)lvns->system_state = malloc(sizeof(ToHeartState));
state->state = toheart_state_base;
state->sakura_num = 0;
state->sakura_disp_num = 0;
state->character[0] = NULL;
state->character[1] = NULL;
state->character[2] = NULL;
state->title = NULL;
state->title_mask = 16;
state->roll = NULL;
state->light = NULL;
state->fast_calendar = False;
state->fast_clock = False;
ToHeartSioriInit(lvns);
}