DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
eastking.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3
4#include "eastking.hpp"
5
6#include <cstdio>
7#include <cstring>
8
9#include "clsmes.hpp"
10#include "dataread.hpp"
11#include "gamepad.hpp"
12#include "menu_draw.hpp"
13#include "menu_inventory.hpp"
14#include "menu_manual.hpp"
15#include "savedata.hpp"
16#include "snd.hpp"
17#include "texture.hpp"
18
24 char unk_04[6];
27 char unk_0E[2];
28 u_long128 *load_buffer;
29 s16 mode;
30 char unk_16[2];
32};
33
34STATIC_ASSERT(sizeof(EAST_KING_EVENT_STATE) == 0x1C);
35
41 s16 unk_02;
43 s16 unk_06;
44 s16 unk_08;
45 s16 alpha;
46};
47
48STATIC_ASSERT(sizeof(EAST_KING_MESSAGE_STATE) == 0xC);
49
51enum EAST_KING_EVENT_MODE {
52 EAST_KING_LOADING,
53 EAST_KING_CLOSING,
54 EAST_KING_DIALOGUE,
55 EAST_KING_MESSAGE_FADE_OUT,
56 EAST_KING_MESSAGE_FADE_IN,
57};
58
59ClsMes *ManualMsg;
60
62s16 PrevEastKingSndNo;
63
64s16 PrevEastKingSndVol;
65
67u_int *EastKingSndReadBuf;
68
69ClsMes EastKingMsgCls;
70
73
75EAST_KING_MESSAGE_STATE EastKingMsg;
76
78s8 EastKingMsgMax[12] = {2, 2, 3, 3, 2, 3, 2, 2, 2, 2, 6, 1};
79
83static inline void ResetEastKingMessage() {
84 EastKingMsgCls.text_columns = MES_WIN_COLUMNS;
85 EastKingMsgCls.text_rows = 10;
86 EastKingMsgCls.text_len = 0;
87 EastKingMsgCls.text_width = 0;
88 EastKingMsgCls.text_height = 0;
89 EastKingMsgCls.fade = 0.0f;
90 EastKingMsgCls.fade_in = true;
91 EastKingMsgCls.text_rate = EastKingMsgCls.text_rate_set;
92 EastKingMsgCls.waiting = false;
93 EastKingMsgCls.text_at = 0.0f;
94 EastKingMsgCls.text_no = 0;
95 EastKingMsgCls.text_from = 0;
96 EastKingMsgCls.page_from = 0;
97 EastKingMsgCls.InitMesWinTbl();
98 EastKingMsgCls.clut_now = EastKingMsgCls.clut_default;
99 EastKingMsgCls.wait = 0;
100 EastKingMsgCls.blink = 0;
101 EastKingMsgCls.auto_page_wait = 0;
102 EastKingMsgCls.mes_made = -1;
103 EastKingMsgCls.edge_alpha = 0x80;
104
105 for (int slot = 0; slot < 10; slot++) {
106 EastKingMsgCls.mes_no[slot] = -1;
107 }
108
109 for (int value_no = 0; value_no < 8; value_no++) {
110 EastKingMsgCls.values[value_no] = 0;
111 }
112
113 EastKingMsgCls.value = 0;
114 EastKingMsgCls.value_signed = false;
115 EastKingMsgCls.value_show = true;
116 EastKingMsgCls.value_narrow = false;
117 EastKingMsgCls.space_width = -1;
118 EastKingMsgCls.space_area = -1;
119 EastKingMsgCls.cursor_row = -1;
120 EastKingMsgCls.cursor_y = 0;
121 EastKingMsgCls.cursor_lit = false;
122
123 for (int line = 0; line < 10; line++) {
124 EastKingMsgCls.line_pos[line].x = -1;
125 EastKingMsgCls.line_pos[line].y = -1;
126 }
127}
128
129void EastKingTextureEnter() {
130 if (EastKing.resources_ready == 0 && ReadBGSync() == 0 && SndBgmSyncBG() == 0) {
131 LOADTEXTURE_INFO2 textures[] = {
132 {"#frame_image#640#" SCREEN_HEIGHT_STR "#4", EastKing.texture_block, 0},
133 {NULL, EastKing.texture_block, 0},
134 {NULL, 0, 0},
135 };
136 BG_READ_INFO *archive = GetReadBGFile(0);
137 char image_name[64] = "st.img";
138 sprintf(image_name, image_name, EastKing.event_no);
139 textures[1].name = (char *) GetPackFile((u_int *) archive->buffer, image_name, NULL);
140 TexManager.DeleteTextureBlock(EastKing.texture_block);
141 TexManager.CleanUpTextureList();
142 TexManager.LoadTextureBlockEX(-1, textures);
143
144 u_long128 *buffer_end = EastKing.load_buffer + (archive->size >> 4) + 1;
145 s16 *messages = (s16 *) GetPackFile((u_int *) archive->buffer, "eastking.bin", NULL);
146 ResetEastKingMessage();
147 EastKingMsgCls.SetMesFukidashi(MES_FUKIDASHI_LARGE_TABLE_EDGE);
148#ifdef PAL
149 s8 font_width[8] = {16, 14, 14, 15, 15, 15, 15};
150#else
151 s8 font_width[] = {16, 14, 14, 14, 14, 14, 14};
152#endif
153 EastKingMsgCls.char_width = font_width[GetMenuLangFlag()];
154#ifdef PAL
155 EastKingMsgCls.char_height = 0x1A;
156#else
157 EastKingMsgCls.char_height = 0x16;
158#endif
159 EastKingMsgCls.columns = 0x1E;
160 EastKingMsgCls.text_rate = 0.0f;
161 EastKingMsgCls.text_rate_set = 0.0f;
162 EastKingMsgCls.centre_rows = true;
163 EastKingMsgCls.tex_block = 0x1A;
164 EastKingMsgCls.tex_buff = buffer_end;
165 EastKingMsgCls.SetBuff(messages);
166 EastKingMsgCls.mes_made = -1;
167 EastKingMsgCls.unk_02C = 0x10;
168 EastKingMsgCls.init_030 = 0x10;
169 EastKingMsgCls.page_arrow = true;
170 EastKing.resources_ready = true;
171 EastKingMsg.draw_message = true;
172 SndBgmPlay(0);
173 }
174}
175
183static void EastKingMsgDraw() {
184 if (EastKing.resources_ready != 0 && EastKingMsgCls.mes_made != EastKingMsg.message_no && EastKingMsg.draw_message != 0) {
185 EastKingMsgCls.MakeMesWin(EastKingMsg.message_no);
186 }
187
188 MenuTextureReload(EastKingMsgCls.tex_block);
189
190 switch (EastKing.mode) {
191 case EAST_KING_LOADING:
192 if (EastKing.resources_ready == 0) {
193 break;
194 }
195 // The window fades in once the loading has finished.
196 case EAST_KING_DIALOGUE:
197 case EAST_KING_MESSAGE_FADE_IN:
198 EastKingMsg.alpha += 2;
199 break;
200 case EAST_KING_CLOSING:
201 case EAST_KING_MESSAGE_FADE_OUT:
202 EastKingMsg.alpha -= 2;
203 break;
204 }
205
206 if (EastKingMsg.alpha < 0) {
207 EastKingMsg.alpha = 0;
208 }
209
210 if (EastKingMsg.alpha > 0x80) {
211 EastKingMsg.alpha = 0x80;
212 }
213
214 if (EastKing.resources_ready != 0) {
215 int half_width = EastKingMsgCls.char_width >> 1;
216 GetMenuCommonPutXY(&EastKingMsgCls, 0x14C - half_width);
217#ifdef PAL
218 EastKingMsgCls.text_y = 0x156;
219#else
220 EastKingMsgCls.text_y = 0x132;
221#endif
222 EastKingMsgCls.edge_alpha = EastKingMsg.alpha;
223 EastKingMsgCls.Step();
224 EastKingMsgCls.DrawMesWin();
225 }
226}
227
228void GetPrevEastKingSndVol() {
229 PrevEastKingSndVol = SndGetBgmVol();
230}
231
232#ifdef PAL
233int InitEastKingEvent(int event_no, int *texture_block, u_long128 *load_buffer) {
234#else
235void InitEastKingEvent(int event_no, int *texture_block, u_long128 *load_buffer) {
236#endif
237 char path[76];
238 int size;
239
240 GetPathReadDifferntLang(path);
241 strcat(path, "eastk/st%d.pak");
242 sprintf(path, path, event_no + 1);
243 EastKing.load_buffer = load_buffer;
244 EastKing.load_buffer = MenuCalcBufAlignment(EastKing.load_buffer);
245 StartReadBG();
246 LoadFileBG(path, EastKing.load_buffer, &size);
247 ReadBG();
248 EastKingSndReadBuf = (u_int *) (EastKing.load_buffer + size / 16 + 0x10);
249 EastKingSndReadBuf = (u_int *) MenuCalcBufAlignment((u_long128 *) EastKingSndReadBuf);
250 PrevEastKingSndNo = SndGetBgmNo();
251 SndBgmLoadBG(0x16, EastKingSndReadBuf, &size);
252 EastKing.resources_ready = false;
253 EastKing.texture_block = *texture_block;
254 EastKing.event_no = event_no;
255 EastKing.mode = EAST_KING_LOADING;
256 EastKing.transition_frame = 0;
257 EastKingMsg.message_no = EastKing.event_no * 100 + 100;
258 EastKingMsg.unk_02 = 0;
259 EastKingMsg.alpha = 0;
260 EastKingMsg.draw_message = false;
261
262 if (SaveData->GetGameFlag(EastKing.event_no + 0xE6) == 0) {
263 SaveData->SetGameFlag(EastKing.event_no + 0xE6, 1);
264 }
265
266#ifdef PAL
267 return 1;
268#endif
269}
270
271int EastKingEventKey() {
272 int finished = 0;
273 int size;
274
275 ReadBG();
276
277 switch (EastKing.mode) {
278 case EAST_KING_LOADING:
279 EastKing.transition_frame++;
280 EastKingTextureEnter();
281
282 if (EastKing.transition_frame > 0x40 && EastKingMsg.alpha >= 0x80 && EastKing.resources_ready != 0) {
283 EastKing.mode = EAST_KING_DIALOGUE;
284 EastKing.transition_frame = 0;
285 EastKingMsg.draw_message = true;
286 }
287
288 break;
289 case EAST_KING_CLOSING:
290 if (EastKing.transition_frame == 0x32) {
291 SndBgmStop();
292 }
293
294 if (EastKing.transition_frame == 0x3A) {
295 StartReadBG();
296 SndBgmLoadBG(PrevEastKingSndNo, EastKingSndReadBuf, &size);
297 }
298
299 EastKing.transition_frame++;
300
301 if (EastKing.transition_frame > 0x40 && SndBgmSyncBG() == 0) {
302 finished = 1;
303 SndBgmFadeIn(0x3C, PrevEastKingSndVol, 0);
304 SndBgmPlay(0);
305 }
306
307 break;
308 case EAST_KING_DIALOGUE:
309 if (GamePad.Down(PAD_CROSS) != 0 && EastKingMsgCls.State() == CLSMES_SHOWN) {
310 if (EastKingMsg.message_no + 1 > EastKing.event_no * 100 + 100 + EastKingMsgMax[EastKing.event_no]) {
311 EastKing.mode = EAST_KING_CLOSING;
312 EastKing.transition_frame = 0;
313 SndBgmFadeOut(0x5A, 0);
314 } else {
315 EastKing.mode = EAST_KING_MESSAGE_FADE_OUT;
316 EastKing.transition_frame = 0;
317 EastKingMsg.draw_message = false;
318 }
319 } else if (GamePad.Down(PAD_CIRCLE) != 0) {
320 EastKing.transition_frame = 0;
321 EastKing.mode = EAST_KING_CLOSING;
322 }
323
324 break;
325 case EAST_KING_MESSAGE_FADE_OUT:
326 EastKing.transition_frame++;
327
328 if (EastKingMsg.alpha <= 0) {
329 EastKing.mode = EAST_KING_MESSAGE_FADE_IN;
330 EastKingMsg.alpha = 0;
331 EastKingMsg.message_no++;
332 EastKing.transition_frame = 0;
333 EastKingMsg.draw_message = true;
334 }
335
336 break;
337 case EAST_KING_MESSAGE_FADE_IN:
338 EastKing.transition_frame++;
339
340 if (EastKingMsg.alpha >= 0x80) {
341 EastKing.mode = EAST_KING_DIALOGUE;
342 EastKing.transition_frame = 0;
343 }
344
345 break;
346 }
347
348 SndStep();
349 return finished;
350}
351
352void EastKingEventDraw() {
353 AllFadeForMenu(0x80);
354
355 if (EastKing.resources_ready != 0) {
356 MenuTextureReload(EastKing.texture_block);
357 CTexture *picture = TexManager.GetTexture("st", EastKing.texture_block);
358
359 if (EastKing.event_no == 2 && EastKingMsg.message_no == 0x12F) {
360 picture = TexManager.GetTexture("st1", EastKing.texture_block);
361 }
362
363 DrawFullSizePicture(picture, 0, 0, 0x80);
364 EastKingMsgDraw();
365 }
366
367 int fade = 0;
368
369 switch (EastKing.mode) {
370 case EAST_KING_LOADING:
371 fade = 0x80 - EastKing.transition_frame * 2;
372 break;
373 case EAST_KING_CLOSING:
374 fade = EastKing.transition_frame * 2;
375 break;
376 case EAST_KING_MESSAGE_FADE_OUT:
377 if (EastKing.event_no == 2 && EastKingMsg.message_no == 0x12E) {
378 fade = EastKing.transition_frame * 3;
379 }
380
381 break;
382 case EAST_KING_MESSAGE_FADE_IN:
383 if (EastKing.event_no == 2 && EastKingMsg.message_no == 0x12F) {
384 fade = 0x80 - EastKing.transition_frame * 3;
385 }
386
387 break;
388 }
389
390 if (fade < 0) {
391 fade = 0;
392 }
393
394 if (fade > 0x80) {
395 fade = 0x80;
396 }
397
398 AllFadeForMenu(fade);
399}
int Down(int mask)
Definition gamepad.cpp:583
int GetGameFlag(int flag_no)
Definition savedata.cpp:258
int SetGameFlag(int flag_no, int value)
Definition savedata.cpp:279
s32 text_rows
Definition clsmes.hpp:158
s32 text_y
Definition clsmes.hpp:152
s32 text_from
Definition clsmes.hpp:198
s32 cursor_y
Definition clsmes.hpp:225
float text_rate_set
Definition clsmes.hpp:193
void DrawMesWin()
Definition clsmes.cpp:2619
s32 wait
Definition clsmes.hpp:204
s32 text_no
Definition clsmes.hpp:197
s32 char_height
Definition clsmes.hpp:154
void Step()
Definition clsmes.cpp:575
s32 mes_no[10]
Definition clsmes.hpp:216
s32 page_from
Definition clsmes.hpp:199
s32 page_arrow
Definition clsmes.hpp:209
s32 text_height
Definition clsmes.hpp:161
s32 text_width
Definition clsmes.hpp:160
s32 char_width
Definition clsmes.hpp:153
s32 text_columns
Definition clsmes.hpp:157
s32 text_len
Definition clsmes.hpp:159
s32 value
Definition clsmes.hpp:218
void InitMesWinTbl()
Definition clsmes.cpp:1265
s32 waiting
Definition clsmes.hpp:194
s32 cursor_lit
Definition clsmes.hpp:226
s32 auto_page_wait
Definition clsmes.hpp:206
s32 centre_rows
Definition clsmes.hpp:211
s32 fade_in
Definition clsmes.hpp:188
s32 space_width
Definition clsmes.hpp:222
s32 clut_now
Definition clsmes.hpp:203
s32 blink
Definition clsmes.hpp:205
void * tex_buff
Definition clsmes.hpp:233
s32 cursor_row
Definition clsmes.hpp:224
float fade
Definition clsmes.hpp:187
void SetBuff(short *buff)
Definition clsmes.cpp:456
s32 columns
Definition clsmes.hpp:155
s32 mes_made
Definition clsmes.hpp:207
s32 values[8]
Definition clsmes.hpp:217
s32 value_narrow
Definition clsmes.hpp:221
s32 tex_block
Definition clsmes.hpp:227
s32 value_signed
Definition clsmes.hpp:219
void SetMesFukidashi(int style)
Definition clsmes.cpp:511
float text_rate
Definition clsmes.hpp:192
s32 edge_alpha
Definition clsmes.hpp:213
s32 clut_default
Definition clsmes.hpp:202
MES_LINE_POS line_pos[10]
Definition clsmes.hpp:228
int MakeMesWin(int mes_no)
Definition clsmes.cpp:1669
s32 value_show
Definition clsmes.hpp:220
int State()
Definition clsmes.cpp:637
s32 init_030
Definition clsmes.hpp:163
s32 space_area
Definition clsmes.hpp:223
float text_at
Definition clsmes.hpp:196
u_long128 * buffer
Definition dataread.hpp:29
u_long128 * load_buffer
Definition eastking.cpp:28