| 1 | /* |
| 2 | * OpenTyrian: A modern cross-platform port of Tyrian |
| 3 | * Copyright (C) 2007-2009 The OpenTyrian Development Team |
| 4 | * |
| 5 | * This program is free software; you can redistribute it and/or |
| 6 | * modify it under the terms of the GNU General Public License |
| 7 | * as published by the Free Software Foundation; either version 2 |
| 8 | * of the License, or (at your option) any later version. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * along with this program; if not, write to the Free Software |
| 17 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. |
| 18 | */ |
| 19 | #include "fonthand.h" |
| 20 | |
| 21 | #include "network.h" |
| 22 | #include "nortsong.h" |
| 23 | #include "nortvars.h" |
| 24 | #include "opentyr.h" |
| 25 | #include "params.h" |
| 26 | #include "sprite.h" |
| 27 | #include "vga256d.h" |
| 28 | #include "video.h" |
| 29 | |
| 30 | const int font_ascii[256] = |
| 31 | { |
| 32 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 33 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 34 | -1, 26, 33, 60, 61, 62, -1, 32, 64, 65, 63, 84, 29, 83, 28, 80, // !"#$%&'()*+,-./ |
| 35 | 79, 70, 71, 72, 73, 74, 75, 76, 77, 78, 31, 30, -1, 85, -1, 27, // 0123456789:;<=>? |
| 36 | -1, 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, // @ABCDEFGHIJKLMNO |
| 37 | 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 68, 82, 69, -1, -1, // PQRSTUVWXYZ[\]^_ |
| 38 | -1, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, // `abcdefghijklmno |
| 39 | 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 66, 81, 67, -1, -1, // pqrstuvwxyz{|}~⌂ |
| 40 | |
| 41 | 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96, 97, 98, 99, 100, 101, // ÇüéâäàåçêëèïîìÄÅ |
| 42 | 102, 103, 104, 105, 106, 107, 108, 109, 110, 111, 112, 113, 114, 115, 116, 117, // ÉæÆôöòûùÿÖÜ¢£¥₧ƒ |
| 43 | 118, 119, 120, 121, 122, 123, 124, 125, 126, -1, -1, -1, -1, -1, -1, -1, // áíóúñѪº¿ |
| 44 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 45 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 46 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 47 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 48 | -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, -1, |
| 49 | }; |
| 50 | |
| 51 | /* shape constants included in newshape.h */ |
| 52 | |
| 53 | JE_byte textGlowFont, textGlowBrightness = 6; |
| 54 | |
| 55 | JE_boolean levelWarningDisplay; |
| 56 | JE_byte levelWarningLines; |
| 57 | char levelWarningText[10][61]; /* [1..10] of string [60] */ |
| 58 | JE_boolean warningRed; |
| 59 | |
| 60 | JE_byte warningSoundDelay; |
| 61 | JE_word armorShipDelay; |
| 62 | JE_byte warningCol; |
| 63 | JE_shortint warningColChange; |
| 64 | |
| 65 | void JE_dString(SDL_Surface * screen, int x, int y, const char *s, unsigned int font) |
| 66 | { |
| 67 | const int defaultBrightness = -3; |
| 68 | |
| 69 | int bright = 0; |
| 70 | |
| 71 | for (int i = 0; s[i] != '\0'; ++i) |
| 72 | { |
| 73 | int sprite_id = font_ascii[(unsigned char)s[i]]; |
| 74 | |
| 75 | switch (s[i]) |
| 76 | { |
| 77 | case ' ': |
| 78 | x += 6; |
| 79 | break; |
| 80 | |
| 81 | case '~': |
| 82 | bright = (bright == 0) ? 2 : 0; |
| 83 | break; |
| 84 | |
| 85 | default: |
| 86 | if (sprite_id != -1) |
| 87 | { |
| 88 | blit_sprite_dark(screen, x + 2, y + 2, font, sprite_id, false); |
| 89 | blit_sprite_hv_unsafe(screen, x, y, font, sprite_id, 0xf, defaultBrightness + bright); |
| 90 | |
| 91 | x += sprite(font, sprite_id)->width + 1; |
| 92 | } |
| 93 | break; |
| 94 | } |
| 95 | } |
| 96 | } |
| 97 | |
| 98 | int JE_fontCenter(const char *s, unsigned int font) |
| 99 | { |
| 100 | return 160 - (JE_textWidth(s, font) / 2); |
| 101 | } |
| 102 | |
| 103 | int JE_textWidth(const char *s, unsigned int font) |
| 104 | { |
| 105 | int x = 0; |
| 106 | |
| 107 | for (int i = 0; s[i] != '\0'; ++i) |
| 108 | { |
| 109 | int sprite_id = font_ascii[(unsigned char)s[i]]; |
| 110 | |
| 111 | if (s[i] == ' ') |
| 112 | x += 6; |
| 113 | else if (sprite_id != -1) |
| 114 | x += sprite(font, sprite_id)->width + 1; |
| 115 | } |
| 116 | |
| 117 | return x; |
| 118 | } |
| 119 | |
| 120 | void JE_textShade(SDL_Surface * screen, int x, int y, const char *s, unsigned int colorbank, int brightness, unsigned int shadetype) |
| 121 | { |
| 122 | switch (shadetype) |
| 123 | { |
| 124 | case PART_SHADE: |
| 125 | JE_outText(screen, x+1, y+1, s, 0, -1); |
| 126 | JE_outText(screen, x, y, s, colorbank, brightness); |
| 127 | break; |
| 128 | case FULL_SHADE: |
| 129 | JE_outText(screen, x-1, y, s, 0, -1); |
| 130 | JE_outText(screen, x+1, y, s, 0, -1); |
| 131 | JE_outText(screen, x, y-1, s, 0, -1); |
| 132 | JE_outText(screen, x, y+1, s, 0, -1); |
| 133 | JE_outText(screen, x, y, s, colorbank, brightness); |
| 134 | break; |
| 135 | case DARKEN: |
| 136 | JE_outTextAndDarken(screen, x+1, y+1, s, colorbank, brightness, TINY_FONT); |
| 137 | break; |
| 138 | case TRICK: |
| 139 | JE_outTextModify(screen, x, y, s, colorbank, brightness, TINY_FONT); |
| 140 | break; |
| 141 | } |
| 142 | } |
| 143 | |
| 144 | void JE_outText(SDL_Surface * screen, int x, int y, const char *s, unsigned int colorbank, int brightness) |
| 145 | { |
| 146 | int bright = 0; |
| 147 | |
| 148 | for (int i = 0; s[i] != '\0'; ++i) |
| 149 | { |
| 150 | int sprite_id = font_ascii[(unsigned char)s[i]]; |
| 151 | |
| 152 | switch (s[i]) |
| 153 | { |
| 154 | case ' ': |
| 155 | x += 6; |
| 156 | break; |
| 157 | |
| 158 | case '~': |
| 159 | bright = (bright == 0) ? 4 : 0; |
| 160 | break; |
| 161 | |
| 162 | default: |
| 163 | if (sprite_id != -1 && sprite_exists(TINY_FONT, sprite_id)) |
| 164 | { |
| 165 | if (brightness >= 0) |
| 166 | blit_sprite_hv_unsafe(screen, x, y, TINY_FONT, sprite_id, colorbank, brightness + bright); |
| 167 | else |
| 168 | blit_sprite_dark(screen, x, y, TINY_FONT, sprite_id, true); |
| 169 | |
| 170 | x += sprite(TINY_FONT, sprite_id)->width + 1; |
| 171 | } |
| 172 | break; |
| 173 | } |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | void JE_outTextModify(SDL_Surface * screen, int x, int y, const char *s, unsigned int filter, unsigned int brightness, unsigned int font) |
| 178 | { |
| 179 | for (int i = 0; s[i] != '\0'; ++i) |
| 180 | { |
| 181 | int sprite_id = font_ascii[(unsigned char)s[i]]; |
| 182 | |
| 183 | if (s[i] == ' ') |
| 184 | { |
| 185 | x += 6; |
| 186 | } |
| 187 | else if (sprite_id != -1) |
| 188 | { |
| 189 | blit_sprite_hv_blend(screen, x, y, font, sprite_id, filter, brightness); |
| 190 | |
| 191 | x += sprite(font, sprite_id)->width + 1; |
| 192 | } |
| 193 | } |
| 194 | } |
| 195 | |
| 196 | void JE_outTextAdjust(SDL_Surface * screen, int x, int y, const char *s, unsigned int filter, int brightness, unsigned int font, JE_boolean shadow) |
| 197 | { |
| 198 | int bright = 0; |
| 199 | |
| 200 | for (int i = 0; s[i] != '\0'; ++i) |
| 201 | { |
| 202 | int sprite_id = font_ascii[(unsigned char)s[i]]; |
| 203 | |
| 204 | switch (s[i]) |
| 205 | { |
| 206 | case ' ': |
| 207 | x += 6; |
| 208 | break; |
| 209 | |
| 210 | case '~': |
| 211 | bright = (bright == 0) ? 4 : 0; |
| 212 | break; |
| 213 | |
| 214 | default: |
| 215 | if (sprite_id != -1 && sprite_exists(TINY_FONT, sprite_id)) |
| 216 | { |
| 217 | if (shadow) |
| 218 | blit_sprite_dark(screen, x + 2, y + 2, font, sprite_id, false); |
| 219 | blit_sprite_hv(screen, x, y, font, sprite_id, filter, brightness + bright); |
| 220 | |
| 221 | x += sprite(font, sprite_id)->width + 1; |
| 222 | } |
| 223 | break; |
| 224 | } |
| 225 | } |
| 226 | } |
| 227 | |
| 228 | void JE_outTextAndDarken(SDL_Surface * screen, int x, int y, const char *s, unsigned int colorbank, unsigned int brightness, unsigned int font) |
| 229 | { |
| 230 | int bright = 0; |
| 231 | |
| 232 | for (int i = 0; s[i] != '\0'; ++i) |
| 233 | { |
| 234 | int sprite_id = font_ascii[(unsigned char)s[i]]; |
| 235 | |
| 236 | switch (s[i]) |
| 237 | { |
| 238 | case ' ': |
| 239 | x += 6; |
| 240 | break; |
| 241 | |
| 242 | case '~': |
| 243 | bright = (bright == 0) ? 4 : 0; |
| 244 | break; |
| 245 | |
| 246 | default: |
| 247 | if (sprite_id != -1 && sprite_exists(TINY_FONT, sprite_id)) |
| 248 | { |
| 249 | blit_sprite_dark(screen, x + 1, y + 1, font, sprite_id, false); |
| 250 | blit_sprite_hv_unsafe(screen, x, y, font, sprite_id, colorbank, brightness + bright); |
| 251 | |
| 252 | x += sprite(font, sprite_id)->width + 1; |
| 253 | } |
| 254 | break; |
| 255 | } |
| 256 | } |
| 257 | } |
| 258 | |
| 259 | void JE_updateWarning(SDL_Surface * screen) |
| 260 | { |
| 261 | if (getDelayTicks2() == 0) |
| 262 | { /*Update Color Bars*/ |
| 263 | |
| 264 | warningCol += warningColChange; |
| 265 | if (warningCol > 14 * 16 + 10 || warningCol < 14 * 16 + 4) |
| 266 | { |
| 267 | warningColChange = -warningColChange; |
| 268 | } |
| 269 | fill_rectangle_xy(screen, 0, 0, 319, 5, warningCol); |
| 270 | fill_rectangle_xy(screen, 0, 194, 319, 199, warningCol); |
| 271 | JE_showVGA(); |
| 272 | |
| 273 | setDelay2(6); |
| 274 | |
| 275 | if (warningSoundDelay > 0) |
| 276 | { |
| 277 | warningSoundDelay--; |
| 278 | } |
| 279 | else |
| 280 | { |
| 281 | warningSoundDelay = 14; |
| 282 | JE_playSampleNum(S_WARNING); |
| 283 | } |
| 284 | } |
| 285 | } |
| 286 | |
| 287 | void JE_outTextGlow(SDL_Surface * screen, int x, int y, const char *s) |
| 288 | { |
| 289 | JE_integer z; |
| 290 | JE_byte c = 15; |
| 291 | |
| 292 | if (warningRed) |
| 293 | { |
| 294 | c = 7; |
| 295 | } |
| 296 | |
| 297 | JE_outTextAdjust(screen, x - 1, y, s, 0, -12, textGlowFont, false); |
| 298 | JE_outTextAdjust(screen, x, y - 1, s, 0, -12, textGlowFont, false); |
| 299 | JE_outTextAdjust(screen, x + 1, y, s, 0, -12, textGlowFont, false); |
| 300 | JE_outTextAdjust(screen, x, y + 1, s, 0, -12, textGlowFont, false); |
| 301 | if (frameCountMax > 0) |
| 302 | for (z = 1; z <= 12; z++) |
| 303 | { |
| 304 | setDelay(frameCountMax); |
| 305 | JE_outTextAdjust(screen, x, y, s, c, z - 10, textGlowFont, false); |
| 306 | if (JE_anyButton()) |
| 307 | { |
| 308 | frameCountMax = 0; |
| 309 | } |
| 310 | |
| 311 | NETWORK_KEEP_ALIVE(); |
| 312 | |
| 313 | JE_showVGA(); |
| 314 | |
| 315 | wait_delay(); |
| 316 | } |
| 317 | for (z = (frameCountMax == 0) ? 6 : 12; z >= textGlowBrightness; z--) |
| 318 | { |
| 319 | setDelay(frameCountMax); |
| 320 | JE_outTextAdjust(screen, x, y, s, c, z - 10, textGlowFont, false); |
| 321 | if (JE_anyButton()) |
| 322 | { |
| 323 | frameCountMax = 0; |
| 324 | } |
| 325 | |
| 326 | NETWORK_KEEP_ALIVE(); |
| 327 | |
| 328 | JE_showVGA(); |
| 329 | |
| 330 | wait_delay(); |
| 331 | } |
| 332 | textGlowBrightness = 6; |
| 333 | } |