DCDecomp
A decompilation of Dark Cloud for the PlayStation 2
Loading...
Searching...
No Matches
sysmes.cpp
1#pragma helper_mask_gpr 0x30
2#pragma helper_mask_fpr 0x1000
3#pragma name_counter 361
4
5#include "sysmes.hpp"
6
7#include <cstdio>
8#include <cstring>
9
10#include "clsmes.hpp"
11#include "dataread.hpp"
12#include "gamepad.hpp"
13#include "itemdata.hpp"
14#include "mainselect.hpp"
15#include "memcard.hpp"
16#include "mglib.hpp"
17#include "snd.hpp"
18#include "texture.hpp"
19
20extern "C" int SkipSpace__FR9input_str__3(input_str &input) {
21 char *text;
22 int position;
23
24 text = input.data;
25 position = input.pos;
26
27 while (position < input.size) {
28 if (CheckChar__Fc__3(text[position])) {
29 break;
30 }
31
32 position++;
33 }
34
35 input.pos = position;
36
37 if (position >= input.size) {
38 return 0;
39 }
40
41 return 1;
42}
43
44extern "C" int CheckChar__Fc__3(char value) {
45 int whitespace = 0;
46
47 if (value == ' ') {
48 whitespace = 1;
49 }
50
51 if (value == '\t') {
52 whitespace = 1;
53 }
54
55 if (value == '\n') {
56 whitespace = 1;
57 }
58
59 if (value == '\r') {
60 whitespace = 1;
61 }
62
63 return !whitespace;
64}
65
66extern "C" void PreProcess__FR9input_str__2(input_str &input) {
67 u8 *text = (u8 *) input.data;
68 int position = 0;
69
70 while (position < input.size) {
71 if (text[position] == '/' && text[position + 1] == '/') {
72 while (position < input.size) {
73 if (text[position] == '\n' || text[position] == '\r') {
74 break;
75 }
76
77 text[position] = ' ';
78 position++;
79 }
80 }
81
82 if (text[position] == '/' && text[position + 1] == '*') {
83 while (position < input.size) {
84 if (text[position] == '*' && text[position + 1] == '/') {
85 text[position] = ' ';
86 text[position + 1] = ' ';
87 break;
88 }
89
90 text[position] = ' ';
91 position++;
92 }
93
94 continue;
95 }
96
97 position++;
98 }
99}
100
101/* The town's own message window, which everything with something to say to the player goes through
102 and which the map editor's gate calls into before doing the same thing to a window of its own.
103 It is set up once and asks for none of what the class can do — no speech bubble, no typing
104 animation, no page marker — so a system message is one line of at most 26 characters that
105 appears whole, sits under the picture for as many frames as its caller asked for, and goes. */
106ClsMes SystemMessage;
107
108/* The message file is read straight into this one off the disc, and the drive transfers by DMA
109 into whole cache lines. */
110short mes_data[24000] __attribute__((aligned(64)));
111
112char mes_buff[65536];
113
114int SystemMesNo = -1;
115
116int SystemMesPosition = MES_POS_BOTTOM;
117
118int SystemMesCount;
119
120int SystemMesWait;
121
122int SystemMesInputKey;
123
124/* The language is spelled into the file name rather than chosen between names, and the read that
125 fails falls back to one fixed file rather than to no text at all. */
126void InitSystemMes() {
127 short *data = mes_data;
128 int size;
129
130 char name[64] = "meswin/system_a";
131
132 if (LanguageCode > LANG_JAPANESE) {
133 sprintf(name, "meswin/system_a_%d", LanguageCode);
134 }
135
136 strcat(name, ".mes");
137
138 if (!LoadFile2(name, data, &size, 0)) {
139 LoadFile("meswin/system_ae.bin", data, &size);
140 }
141
142 SystemMessage.Preset(MES_PRESET_SYSTEM);
143 SystemMessage.fukidashi = false;
144 SystemMessage.stay_frame = true;
145 SystemMessage.text_rate = 0;
146 SystemMessage.text_rate_set = 0;
147 SystemMessage.style = MES_EDGE_NONE;
148 SystemMessage.page_arrow = false;
149 SystemMessage.fade_speed = 1.0f;
150 SystemMessage.columns = 26;
151 SystemMessage.rows = 1;
152 SystemMessage.centre_rows = false;
153 SystemMessage.style = MES_EDGE_BLACK;
154 SystemMessage.tex_buff = mes_buff;
155 SystemMessage.tex_block = 26;
156 SystemMessage.SetBuff(data);
157 SystemMessage.SetBuff_system(SystemMes);
158}
159
160void ClearSystemMes() {
161 SystemMessage.MakeMesWin(-1);
162 SystemMesNo = -1;
163 SystemMesCount = 0;
164 SystemMesInputKey = 0;
165 SystemMesWait = 0;
166}
167
168int SystemMesCheck() {
169 return SystemMesCount > 0;
170}
171
172/* A message counts down to nothing and is cleared at one rather than at zero, so the frame that
173 would have shown it empty is the frame it goes away on. A message that asked for a button holds
174 at two until the button is pressed. */
175void SystemMesStep() {
176 if (SystemMesWait > 0) {
177 SystemMesWait--;
178 return;
179 }
180
181 if (SystemMesCount == 1) {
182 ClearSystemMes();
183 }
184
185 if (SystemMesNo > 0) {
186 SystemMessage.Step();
187 }
188
189 if (SystemMesInputKey == 0 || SystemMesCount != 2 || GamePad.Down(PAD_CROSS)) {
190 if (SystemMesCount > 0) {
191 SystemMesCount--;
192 }
193 }
194}
195
196/* The window's own textures are put back every frame it is drawn, because whatever the game drew
197 in between is free to have taken the video memory they were in. The line is centred by the width
198 the text actually laid out to, which is not known until the window has been made. */
199void SystemMesDraw() {
200 int x;
201 int columns;
202
203 if (SystemMesWait > 0) {
204 return;
205 }
206
207 if (SystemMesNo <= 0) {
208 return;
209 }
210
211 TexManager.ReloadTexture(Vif1Packet, SystemMessage.tex_block);
212 columns = SystemMessage.text_columns;
213 x = 320;
214 x -= columns * 14 / 2;
215 setbilinear(0);
216 SystemMessage.text_x = x;
217 SystemMessage.text_y = 345;
218 SystemMessage.auto_pos = SystemMesPosition;
219 SystemMessage.DrawMesWin();
220}
221
222/* Which message an item announces is decided by the band its number falls in, and the fourth band
223 is the common items, whose message the item's own record names. */
224void ItemGetMes(int item_no, int value, int frames, int input_key) {
225 int *number_ptr;
226 int message_no;
227 COM_ITEM_INFO *info;
228
229 int mes_args[4] = {-1, -1, -1, -1};
230 int numbers[4] = {0, 0, 0, 0};
231
232 number_ptr = numbers;
233 numbers[0] = value;
234 SystemMessage.value_show = false;
235 SystemMessage.value_signed = true;
236
237 if (value < 0) {
238 numbers[0] = 0;
239 SystemMessage.value_signed = false;
240 }
241
242 mes_args[0] = item_no + 100;
243 message_no = 10;
244
245 if (item_no >= ITEM_ATTACH_START) {
246 message_no += 10;
247 }
248
249 if (item_no >= ITEM_REGULAR_WATER) {
250 message_no += 10;
251 }
252
253 if (item_no >= ITEM_WEAPON_START) {
254 message_no = 10;
255 info = GetCommonItemInfo(item_no);
256
257 if (!info) {
258 printf("item_no: %d is NULL\n", item_no);
259 } else {
260 mes_args[0] = info->msg + 100;
261 }
262 }
263
264 SetSystemMes(message_no, frames, MES_POS_BOTTOM, input_key, mes_args, number_ptr);
265}
266
267void AtraGetMes(int map_no, int element, int frames) {
268 int mes_args[4] = {-1, -1, -1, -1};
269
270 mes_args[0] = GetAtraMsgNo(map_no, element);
271 SetSystemMes(40, frames, MES_POS_BOTTOM, 1, mes_args, 0);
272}
273
274void TecGetMes(int technique, int frames) {
275 int mes_args[4] = {-1, -1, -1, -1};
276
277 mes_args[0] = technique + 500;
278 SetSystemMes(50, frames, MES_POS_BOTTOM, 1, mes_args, 0);
279}
280
281void MaxUpMes(int value, int frames) {
282 int numbers[4] = {0, -1, -1, -1};
283
284 numbers[0] = value;
285 SetSystemMes(51, frames, MES_POS_BOTTOM, 1, 0, numbers);
286}
287
288/* A party member out of range names the first one rather than saying nothing, which is the clamp
289 the message further down makes one member along. */
290void DeadMes(int member, int frames) {
291 if (member < 0 || member > 5) {
292 member = 0;
293 }
294
295 int mes_args[4] = {0, -1, -1, -1};
296
297 mes_args[0] = member + 50;
298 SetSystemMes(60, frames, MES_POS_BOTTOM, 1, mes_args, 0);
299}
300
301void AllDeadMes(int frames) {
302 SetSystemMes(61, frames, MES_POS_BOTTOM, 1, 0, 0);
303}
304
305void NotGetAtraMes(int member, int frames) {
306 if (member < 0 || member > 5) {
307 member = 1;
308 }
309
310 int mes_args[4] = {0, -1, -1, -1};
311
312 mes_args[0] = member + 50;
313 SetSystemMes(70, frames, MES_POS_BOTTOM, 0, mes_args, 0);
314}
315
316void DontGetItemMes(int kind) {
317 int message_no;
318
319 message_no = 72;
320
321 if (kind == 2) {
322 message_no = 81;
323 }
324
325 SetSystemMes(message_no, 40, MES_POS_BOTTOM, 1, 0, 0);
326}
327
328/* A negative entry in either list means *leave the slot empty* rather than substitute a negative
329 number, so every slot is cleared before it is written and only four of each are ever filled. */
330void SetSystemMes(int message_no, int frames, int position, int input_key, int *args, int *numbers) {
331 int i;
332
333 SystemMesInputKey = input_key;
334
335 if (args) {
336 for (i = 0; i < 4; i++) {
337 SystemMessage.mes_no[i] = -1;
338
339 if (*args >= 0) {
340 SystemMessage.mes_no[i] = *args;
341 }
342
343 args++;
344 }
345 }
346
347 if (numbers) {
348 for (i = 0; i < 4; i++) {
349 SystemMessage.values[i] = -1;
350
351 if (*numbers >= 0) {
352 SystemMessage.values[i] = *numbers;
353 }
354
355 numbers++;
356 }
357 }
358
359 SystemMessage.MakeMesWin(message_no);
360 SystemMesNo = message_no;
361 SystemMesCount = frames;
362 SystemMesPosition = position;
363}
int Down(int mask)
Definition gamepad.cpp:583
s32 auto_pos
Definition clsmes.hpp:172
s32 text_y
Definition clsmes.hpp:152
s32 text_x
Definition clsmes.hpp:151
float text_rate_set
Definition clsmes.hpp:193
void DrawMesWin()
Definition clsmes.cpp:2619
void Step()
Definition clsmes.cpp:575
s32 mes_no[10]
Definition clsmes.hpp:216
s32 page_arrow
Definition clsmes.hpp:209
float fade_speed
Definition clsmes.hpp:186
s32 fukidashi
Definition clsmes.hpp:164
s32 text_columns
Definition clsmes.hpp:157
s32 centre_rows
Definition clsmes.hpp:211
void * tex_buff
Definition clsmes.hpp:233
void SetBuff(short *buff)
Definition clsmes.cpp:456
s32 columns
Definition clsmes.hpp:155
s32 values[8]
Definition clsmes.hpp:217
s32 style
Definition clsmes.hpp:208
s32 tex_block
Definition clsmes.hpp:227
s32 value_signed
Definition clsmes.hpp:219
float text_rate
Definition clsmes.hpp:192
s32 stay_frame
Definition clsmes.hpp:189
int MakeMesWin(int mes_no)
Definition clsmes.cpp:1669
s32 value_show
Definition clsmes.hpp:220
void SetBuff_system(short *buff)
Definition clsmes.cpp:462
void Preset(int style)
Definition clsmes.cpp:468
s32 rows
Definition clsmes.hpp:156
int pos
Definition sysmes.hpp:13
char * data
Definition sysmes.hpp:11
int size
Definition sysmes.hpp:12