-
Notifications
You must be signed in to change notification settings - Fork 19
/
game_mediator.cpp
226 lines (190 loc) · 7.98 KB
/
game_mediator.cpp
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
#include "game_mediator.h"
extern std::string FILEPATH;
extern std::string GAMEPATH;
#include "soundlib.h"
extern soundLib soundManager;
// Global static pointer used to ensure a single instance of the class.
GameMediator* GameMediator::_instance = NULL;
GameMediator *GameMediator::get_instance()
{
if (!_instance) {
_instance = new GameMediator();
}
return _instance;
}
Mix_Chunk* GameMediator::get_sfx(std::string filename)
{
std::map<std::string, Mix_Chunk*>::iterator it = sfx_map.find(filename);
if (it == sfx_map.end()) {
Mix_Chunk* sfx = soundManager.sfx_from_file(filename);
sfx_map.insert(std::pair<std::string, Mix_Chunk*>(filename, sfx));
return sfx;
} else {
return it->second;
}
}
CURRENT_FILE_FORMAT::file_projectilev3 GameMediator::get_projectile(int n)
{
if (n < 0 || n >= projectile_list.size()) {
return projectile_list.at(0);
}
return projectile_list.at(n);
}
int GameMediator::get_projectile_list_size()
{
return projectile_list.size();
}
CURRENT_FILE_FORMAT::file_npc_v3_1_2* GameMediator::get_enemy(int n)
{
// boss not yet set
if (n < 0 || n >= enemy_list.size()) {
// return first NPC to avoid errors
n = 0;
}
return &enemy_list.at(n);
}
int GameMediator::get_enemy_list_size()
{
return enemy_list.size();
}
#ifdef WII
void GameMediator::short_to_little_endian(short &s)
{
s = (s>>8) | (s<<8);
}
void GameMediator::u_short_to_little_endian(unsigned short &s)
{
short temp_short = s;
short_to_little_endian(temp_short);
s = temp_short;
}
void GameMediator::sint16_to_little_endian(int16_t &i)
{
i = (i << 8) | ((i >> 8) & 0xFF);
}
void GameMediator::int_to_little_endian(int &i)
{
i = (i<<24)|((i<<8)&0xFF0000)|((i>>8)&0xFF00)|(i>>24);
}
void GameMediator::uint16_to_little_endian(Uint16 &i)
{
int16_t temp = i;
sint16_to_little_endian(temp);
i = temp;
}
void GameMediator::wii_convert_npc_list() {
for (int i=0; i<enemy_list.size(); i++) {
short_to_little_endian(enemy_list.at(i).hp.total);
short_to_little_endian(enemy_list.at(i).hp.current);
sint16_to_little_endian(enemy_list.at(i).walk_range);
sint16_to_little_endian(enemy_list.at(i).start_point.x);
sint16_to_little_endian(enemy_list.at(i).start_point.y);
for (int j=0; j<ANIM_TYPE_COUNT; j++) {
for (int k=0; k<ANIM_FRAMES_COUNT; k++) {
uint16_to_little_endian(enemy_list.at(i).sprites[j][k].duration);
sint16_to_little_endian(enemy_list.at(i).sprites[j][k].collision_rect.x);
sint16_to_little_endian(enemy_list.at(i).sprites[j][k].collision_rect.y);
sint16_to_little_endian(enemy_list.at(i).sprites[j][k].collision_rect.w);
sint16_to_little_endian(enemy_list.at(i).sprites[j][k].collision_rect.h);
}
}
sint16_to_little_endian(enemy_list.at(i).sprites_pos_bg.x);
sint16_to_little_endian(enemy_list.at(i).sprites_pos_bg.y);
sint16_to_little_endian(enemy_list.at(i).walk_range);
int_to_little_endian(enemy_list.at(i).respawn_delay);
}
}
void GameMediator::wii_convert_object_list() {
for (int i=0; i<object_list.size(); i++) {
sint16_to_little_endian(object_list.at(i).distance);
sint16_to_little_endian(object_list.at(i).frame_duration);
int_to_little_endian(object_list.at(i).timer);
}
}
void GameMediator::wii_convert_ai_list() {
for (int i=0; i<ai_list.size(); i++) {
for (int j=0; j<AI_MAX_STATES; j++) {
int_to_little_endian(ai_list.at(i).states[j].chance);
int_to_little_endian(ai_list.at(i).states[j].action);
int_to_little_endian(ai_list.at(i).states[j].go_to);
int_to_little_endian(ai_list.at(i).states[j].go_to_delay);
int_to_little_endian(ai_list.at(i).states[j].extra_parameter);
}
for (int j=0; j<MAX_AI_REACTIONS; j++) {
int_to_little_endian(ai_list.at(i).reactions[j].action);
int_to_little_endian(ai_list.at(i).reactions[j].go_to);
int_to_little_endian(ai_list.at(i).reactions[j].go_to_delay);
int_to_little_endian(ai_list.at(i).reactions[j].extra_parameter);
}
}
}
void GameMediator::wii_convert_projectile_list() {
for (int i=0; i<projectile_list.size(); i++) {
sint16_to_little_endian(projectile_list.at(i).size.width);
sint16_to_little_endian(projectile_list.at(i).size.height);
Uint16 trajectory = projectile_list.at(i).trajectory;
uint16_to_little_endian(trajectory);
}
}
void GameMediator::wii_convert_player_list() {
for (int i=0; i<player_list.size(); i++) {
sint16_to_little_endian(player_list.at(i).sprite_hit_area.x);
sint16_to_little_endian(player_list.at(i).sprite_hit_area.y);
sint16_to_little_endian(player_list.at(i).sprite_hit_area.w);
sint16_to_little_endian(player_list.at(i).sprite_hit_area.h);
for (int j=0; j<ANIM_TYPE_COUNT; j++) {
for (int k=0; k<ANIM_FRAMES_COUNT; k++) {
uint16_to_little_endian(player_list.at(i).sprites[j][k].duration);
sint16_to_little_endian(player_list.at(i).sprites[j][k].collision_rect.x);
sint16_to_little_endian(player_list.at(i).sprites[j][k].collision_rect.y);
sint16_to_little_endian(player_list.at(i).sprites[j][k].collision_rect.w);
sint16_to_little_endian(player_list.at(i).sprites[j][k].collision_rect.h);
}
}
for (int j=0; j<MAX_WEAPON_N; j++) {
sint16_to_little_endian(player_list.at(i).weapon_colors[j].color1.r);
sint16_to_little_endian(player_list.at(i).weapon_colors[j].color1.g);
sint16_to_little_endian(player_list.at(i).weapon_colors[j].color1.b);
sint16_to_little_endian(player_list.at(i).weapon_colors[j].color2.r);
sint16_to_little_endian(player_list.at(i).weapon_colors[j].color2.g);
sint16_to_little_endian(player_list.at(i).weapon_colors[j].color2.b);
sint16_to_little_endian(player_list.at(i).weapon_colors[j].color3.r);
sint16_to_little_endian(player_list.at(i).weapon_colors[j].color3.g);
sint16_to_little_endian(player_list.at(i).weapon_colors[j].color3.b);
}
}
}
void GameMediator::wii_convert_anim_tile_list() {
for (int i=0; i<anim_tile_list.size(); i++) {
for (int j=0; j<FS_ANIM_TILE_MAX_FRAMES; j++) {
int_to_little_endian(anim_tile_list.at(i).frame_delay[j]);
}
}
}
#endif
GameMediator::GameMediator()
{
enemy_list = fio_cmm.load_from_disk<CURRENT_FILE_FORMAT::file_npc_v3_1_2>("game_enemy_list_3_1_2.dat");
object_list = fio_cmm.load_from_disk<CURRENT_FILE_FORMAT::file_object>("game_object_list.dat");
ai_list = fio_cmm.load_from_disk<CURRENT_FILE_FORMAT::file_artificial_inteligence>("game_ai_list.dat");
projectile_list = fio_cmm.load_from_disk<CURRENT_FILE_FORMAT::file_projectilev3>("data/game_projectile_list_v3.dat");
anim_tile_list = fio_cmm.load_from_disk<CURRENT_FILE_FORMAT::file_anim_block>("anim_block_list.dat");
player_list_v3_1 = fio_cmm.load_from_disk<CURRENT_FILE_FORMAT::file_player_v3_1_1>("player_list_v3_1_1.dat");
#ifdef WII
wii_convert_npc_list();
wii_convert_object_list();
wii_convert_ai_list();
wii_convert_projectile_list();
wii_convert_player_list();
wii_convert_anim_tile_list();
#endif
// add some dummy data for game not to crash
if (projectile_list.size() == 0) {
projectile_list.push_back(CURRENT_FILE_FORMAT::file_projectilev3());
}
if (player_list_v3_1.size() == 0) {
for (int i=0; i<FS_MAX_PLAYERS; i++) {
player_list_v3_1.push_back(CURRENT_FILE_FORMAT::file_player_v3_1_1(i));
}
}
}