1 /* ScummVM - Graphic Adventure Engine
2 *
3 * ScummVM is the legal property of its developers, whose names
4 * are too numerous to list here. Please refer to the COPYRIGHT
5 * file distributed with this source distribution.
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License
9 * as published by the Free Software Foundation; either version 2
10 * of the License, or (at your option) any later version.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
20 *
21 */
22
23 #include "ultima/nuvie/core/nuvie_defs.h"
24 #include "ultima/nuvie/misc/u6_misc.h"
25 #include "ultima/nuvie/files/nuvie_io_file.h"
26 #include "ultima/nuvie/conf/configuration.h"
27 #include "ultima/nuvie/screen/screen.h"
28 #include "ultima/nuvie/screen/dither.h"
29 #include "ultima/nuvie/screen/game_palette.h"
30
31 namespace Ultima {
32 namespace Nuvie {
33
GamePalette(Screen * s,Configuration * cfg)34 GamePalette::GamePalette(Screen *s, Configuration *cfg) {
35 screen = s;
36 config = cfg;
37
38 palette = (uint8 *)malloc(768);
39 memset(palette, 0, 768);
40
41 this->loadPalette();
42
43 set_palette();
44
45 counter = 0;
46 }
47
~GamePalette()48 GamePalette::~GamePalette() {
49 free(palette);
50 }
51
set_palette()52 void GamePalette::set_palette() {
53 screen->set_palette(palette);
54 }
55
loadPalette()56 bool GamePalette::loadPalette() {
57 uint16 i, j;
58 Std::string filename;
59 NuvieIOFileRead file;
60 unsigned char *buf;
61 uint8 *pal_ptr;
62 Std::string game_name, game_id, pal_name;
63 uint8 dither_mode;
64
65 config->value("config/GameName", game_name);
66 config->value("config/GameID", game_id);
67
68 pal_name.assign(game_id);
69 pal_name.append("pal");
70
71 config_get_path(config, pal_name, filename);
72
73 if (file.open(filename) == false) {
74 DEBUG(0, LEVEL_ERROR, "loading palette.\n");
75 return false;
76 }
77
78 buf = file.readAll();
79
80 pal_ptr = palette;
81
82 for (i = 0, j = 0; i < 256; i++, j += 3) {
83 pal_ptr[0] = buf[j] << 2;
84 pal_ptr[1] = buf[j + 1] << 2;
85 pal_ptr[2] = buf[j + 2] << 2;
86 pal_ptr += 3;
87 }
88
89 free(buf);
90
91 /*
92 printf("GIMP Palette\nName: SE\n#\n");
93 for (int i = 0; i < 0x100; i++)
94 {
95 for (int j = 0; j < 3; j++)
96 {
97 printf("% 3d ", palette[i*3+j]);
98 }
99 printf(" untitled\n");
100 }
101 */
102 dither_mode = Game::get_game()->get_dither()->get_mode();
103 if (Game::get_game()->get_game_type() == NUVIE_GAME_U6) {
104 if (dither_mode == DITHER_NONE)
105 bg_color = 0x31;
106 else
107 bg_color = 0xf;
108 } else if (Game::get_game()->get_game_type() == NUVIE_GAME_MD)
109 bg_color = 220;
110 else // SE
111 bg_color = 72;
112 return true;
113 }
114
loadPaletteIntoBuffer(unsigned char * pal)115 bool GamePalette::loadPaletteIntoBuffer(unsigned char *pal) {
116 uint16 i, j;
117 Std::string filename;
118 NuvieIOFileRead file;
119 unsigned char *buf;
120 uint8 *pal_ptr;
121 Std::string game_name, game_id, pal_name;
122
123 config->value("config/GameName", game_name);
124 config->value("config/GameID", game_id);
125
126 pal_name.assign(game_id);
127 pal_name.append("pal");
128
129 config_get_path(config, pal_name, filename);
130
131 if (file.open(filename) == false) {
132 DEBUG(0, LEVEL_ERROR, "loading palette.\n");
133 return false;
134 }
135
136 buf = file.readAll();
137
138 pal_ptr = pal;
139
140 for (i = 0, j = 0; i < 256; i++, j += 3) {
141 pal_ptr[0] = buf[j] << 2;
142 pal_ptr[1] = buf[j + 1] << 2;
143 pal_ptr[2] = buf[j + 2] << 2;
144 pal_ptr[3] = 0;
145 pal_ptr += 4;
146 }
147
148 free(buf);
149
150 return true;
151 }
152
rotatePalette()153 void GamePalette::rotatePalette() {
154 if (Game::get_game()->anims_paused())
155 return;
156
157 screen->rotate_palette(0xe0, 8); // Fires, braziers, candles
158 screen->rotate_palette(0xe8, 8); // BluGlo[tm] magical items
159
160 if (counter == 0) {
161 screen->rotate_palette(0xf0, 4); //
162 screen->rotate_palette(0xf4, 4); // Kitchen Cauldrons
163 screen->rotate_palette(0xf8, 4); // Poison Field
164 counter = 1;
165 } else
166 counter = 0;
167
168 }
169
170 } // End of namespace Nuvie
171 } // End of namespace Ultima
172