Digimon World 3 decomp
The European version, SLES_039.36
Loading...
Searching...
No Matches
speech.c
Go to the documentation of this file.
1/* The message boxes and the talk boxes that follow an actor */
2
3#include "field/field_mode.h"
4
5/* Where a talk box goes: beside its actor's head on the screen, on the side
6 its type says */
7void FIELDSTG_getSpeechPos(Speech *task, Vec2 *out) {
8 Vec2 pos;
9
10 pos.x = task->actor->tile.x;
11 pos.y = task->actor->tile.y;
12 if (task->actor->key1 == 0xD6) {
13 pos.y -= 0x15;
14 }
16 if (task->type == 2 || task->type == 3) {
17 pos.x -= 0xB;
18 } else {
19 pos.x += 0xB;
20 }
21 if (task->type == 0 || task->type == 2) {
22 pos.y -= 0x13;
23 } else {
24 pos.y -= 7;
25 }
26 *out = pos;
27}
28
29/* A speech's update: opens its message box or talk box, moves the talk box
30 with its actor, and ends with it */
31void FIELDSTG_updateSpeech(Speech *task, void **box) {
32 Vec2 pos;
33 Vec2 newPos;
34 TalkBox *talkBox;
35
36 switch (task->state) {
37 case TASK_INIT:
38 default:
39 if (task->isMessage != 0) {
40 *box = createMessageBox(FIELD_LAYER_TEXT, task->text, task->entry);
41 } else {
42 FIELDSTG_getSpeechPos(task, &pos);
43 *box = createTalkBox(FIELD_LAYER_TEXT, pos.x, pos.y, task->text, task->entry, task->type);
44 }
45 task->nextState(task);
46 break;
47 case TASK_RUN:
48 if (*box == NULL) {
49 task->setState(task, TASK_KILL);
50 } else if (task->isMessage == 0) {
51 FIELDSTG_getSpeechPos(task, &newPos);
52 talkBox = *box;
53 talkBox->setPos(talkBox, newPos.x, newPos.y);
54 }
55 break;
56 case TASK_DONE:
57 case TASK_KILL:
58 break;
59 }
60}
61
62/* Creates the speech of an event's text entry: a message box, or a talk box
63 of a type */
64Speech *FIELDSTG_createSpeech(Actor *actor, s32 entry, s32 type, s32 isMessage) {
65 Speech *task = createTask(FIELDSTG_updateSpeech, sizeof(Speech), 4);
66
67 task->actor = actor;
68 task->entry = entry;
69 task->type = type;
70 task->isMessage = isMessage;
72 return task;
73}
74
75/* Creates the talk box of an actor's text entry, on the side of the screen
76 away from where it faces and the edges */
78 Speech *task = createTask(FIELDSTG_updateSpeech, sizeof(Speech), 4);
79 Vec2 pos;
80
81 task->actor = actor;
82 task->entry = entry;
84 pos = actor->tile;
86 switch (actor->dir) {
87 case 0:
88 case 1:
89 case 2:
90 case 6:
91 case 7:
92 default:
93 if (pos.x >= 0xA0) {
94 task->type = 0;
95 } else {
96 task->type = 2;
97 }
98 break;
99 case 3:
100 case 4:
101 case 5:
102 if (pos.x >= 0xA0) {
103 task->type = 1;
104 } else {
105 task->type = 3;
106 }
107 break;
108 }
109 switch (task->type) {
110 case 0:
111 if (pos.y < 0x79) {
112 task->type = 1;
113 }
114 break;
115 case 2:
116 if (pos.y < 0x79) {
117 task->type = 3;
118 }
119 break;
120 case 1:
121 if (pos.y >= 0xAC) {
122 task->type = 0;
123 }
124 break;
125 case 3:
126 if (pos.y >= 0xAC) {
127 task->type = 2;
128 }
129 break;
130 }
131 task->isMessage = 0;
132 return task;
133}
#define NULL
Definition common.h:17
signed int s32
Definition common.h:11
#define TASK_RUN
Definition task.h:35
#define TASK_KILL
Definition task.h:37
#define TASK_INIT
Tasks: every game object is a task, a heap block that starts with this header and is updated once per...
Definition task.h:34
#define TASK_DONE
Definition task.h:36
#define FIELD_LAYER_TEXT
the message and talk boxes
Definition field_map.h:22
FIELDSTG.PRO: the field mode, where the player walks around the map.
void(* FIELDSTG_scriptHelpers[])()
the script helpers (FIELDSTG_toScreenPos...)
Definition fieldstg.c:3581
FieldState FIELDSTG_state
Definition fieldstg.c:2641
FileCache FILE_CACHE
The file cache.
Definition file_cache.c:7
Task * createMessageBox(s32 layerId, void *strings, s32 index)
A message box with string index of a table, typed out in three-line pages.
Speech * FIELDSTG_createTalk(Actor *actor, s32 entry)
Creates the talk box of an actor's text entry, on the side of the screen away from where it faces and...
Definition speech.c:77
void FIELDSTG_updateSpeech(Speech *task, void **box)
A speech's update: opens its message box or talk box, moves the talk box with its actor,...
Definition speech.c:31
void FIELDSTG_getSpeechPos(Speech *task, Vec2 *out)
Where a talk box goes: beside its actor's head on the screen, on the side its type says.
Definition speech.c:7
Speech * FIELDSTG_createSpeech(Actor *actor, s32 entry, s32 type, s32 isMessage)
Creates the speech of an event's text entry: a message box, or a talk box of a type.
Definition speech.c:64
A character on the field (FIELDSTG_createActor): the player (kind 0) and the other characters.
Definition field_map.h:334
Vec2 tile
Definition field_map.h:337
s32 dir
Definition field_map.h:338
s32 key1
Definition field_map.h:335
s32 eventText
the running event's text file and entry
Definition field_map.h:462
s32 textFile
the stage's text file, for the talks
Definition field_map.h:461
void *(* load)(u32 file)
Definition file.h:92
void *(* getEntry)(u32 fileAndIndex)
Definition file.h:96
A message box, or a talk box that follows an actor (FIELDSTG_createSpeech, FIELDSTG_createTalk)
Definition field_mode.h:195
s32 isMessage
a message box
Definition field_mode.h:200
s32 type
the talk box's (createTalkBox), its corner
Definition field_mode.h:199
void(* setState)(struct Speech *task, s32 state)
Definition field_mode.h:196
void(* nextState)(struct Speech *task)
Definition field_mode.h:196
s32 entry
the text's entry
Definition field_mode.h:198
Actor * actor
Definition field_mode.h:197
void * text
FILE_CACHE.getEntry's.
Definition field_mode.h:201
s32 state
Definition field_mode.h:196
A box with a speaker's name and a message (createTalkBox).
Definition text.h:70
void(* setPos)(struct TalkBox *box, s32 x, s32 y)
Definition text.h:80
Definition gfx.h:352
s32 y
Definition gfx.h:354
s32 x
Definition gfx.h:353
TalkBox * createTalkBox(s32 id, s16 x, s16 y, void *strings, s32 index, u32 type)
A talk box with string index of a table (an optional speaker's name between 02 07 codes),...
Definition talk_box.c:359
void * createTask(void(*update)(), s32 size, s32 childrenSize)
createTaskWithId for a task nothing needs to find
Definition task.c:105