| 1 |
/** |
| 2 |
* Game status bar |
| 3 |
|
| 4 |
* Copyright (C) 1997, 1998, 1999, 2002, 2003 Seth A. Robinson |
| 5 |
* Copyright (C) 2005, 2007, 2008, 2009, 2010, 2012, 2014, 2015 Sylvain Beucler |
| 6 |
|
| 7 |
* This file is part of GNU FreeDink |
| 8 |
|
| 9 |
* GNU FreeDink is free software; you can redistribute it and/or |
| 10 |
* modify it under the terms of the GNU General Public License as |
| 11 |
* published by the Free Software Foundation; either version 3 of the |
| 12 |
* License, or (at your option) any later version. |
| 13 |
|
| 14 |
* GNU FreeDink is distributed in the hope that it will be useful, but |
| 15 |
* WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 17 |
* General Public License for more details. |
| 18 |
|
| 19 |
* You should have received a copy of the GNU General Public License |
| 20 |
* along with this program. If not, see |
| 21 |
* <http://www.gnu.org/licenses/>. |
| 22 |
*/ |
| 23 |
|
| 24 |
#ifdef HAVE_CONFIG_H |
| 25 |
#include <config.h> |
| 26 |
#endif |
| 27 |
|
| 28 |
#include "status.h" |
| 29 |
#define SEQ_EXPLEVEL_NUMS 442 |
| 30 |
|
| 31 |
#include "SDL.h" |
| 32 |
#include <string.h> /* strlen */ |
| 33 |
#include "IOGfxPrimitives.h" /* gfx_blit_nocolorkey */ |
| 34 |
#include "gfx.h" |
| 35 |
#include "gfx_sprites.h" /* GFX_k */ |
| 36 |
#include "dinkini.h" /* check_seq_status */ |
| 37 |
#include "live_sprites_manager.h" /* spr */ |
| 38 |
#include "sfx.h" |
| 39 |
#include "game_choice.h" /* game_choice.active */ |
| 40 |
#include "game_engine.h" /* show_inventory */ |
| 41 |
|
| 42 |
/* Status animations */ |
| 43 |
int flife; |
| 44 |
static int fstrength, fdefense, fmagic, |
| 45 |
last_magic_draw, |
| 46 |
/* flife, */ flifemax, |
| 47 |
fgold, |
| 48 |
fexp, fraise; |
| 49 |
|
| 50 |
static void draw_num(int mseq, char* nums, int mx, int my) { |
| 51 |
int length = 0; |
| 52 |
int rnum = 0; |
| 53 |
|
| 54 |
for (unsigned int i = 0; i < strlen(nums); i++) { |
| 55 |
if (nums[i] == '0') rnum = 10; |
| 56 |
else if (nums[i] == '1') rnum = 1; |
| 57 |
else if (nums[i] == '2') rnum = 2; |
| 58 |
else if (nums[i] == '3') rnum = 3; |
| 59 |
else if (nums[i] == '4') rnum = 4; |
| 60 |
else if (nums[i] == '5') rnum = 5; |
| 61 |
else if (nums[i] == '6') rnum = 6; |
| 62 |
else if (nums[i] == '7') rnum = 7; |
| 63 |
else if (nums[i] == '8') rnum = 8; |
| 64 |
else if (nums[i] == '9') rnum = 9; |
| 65 |
else if (nums[i] == '/') rnum = 11; |
| 66 |
if (rnum == 11 || mseq == SEQ_EXPLEVEL_NUMS) { |
| 67 |
SDL_Rect dst = {mx+length, my}; |
| 68 |
IOGFX_background->blit(GFX_k[seq[mseq].frame[rnum]].k, NULL, &dst); |
| 69 |
} else { |
| 70 |
SDL_Rect dst = {mx+length, my}; |
| 71 |
IOGFX_background->blitNoColorKey(GFX_k[seq[mseq].frame[rnum]].k, NULL, &dst); |
| 72 |
} |
| 73 |
|
| 74 |
length += k[seq[mseq].frame[rnum]].box.right; |
| 75 |
} |
| 76 |
} |
| 77 |
|
| 78 |
|
| 79 |
void draw_exp() |
| 80 |
{ |
| 81 |
char buffer[5+1]; |
| 82 |
char final[5+1+5+1]; |
| 83 |
|
| 84 |
strcpy(final, ""); |
| 85 |
snprintf(buffer, sizeof(buffer), "%05d", fexp); |
| 86 |
strcat(final, buffer); |
| 87 |
strcat(final,"/"); |
| 88 |
|
| 89 |
snprintf(buffer, sizeof(buffer), "%05d", fraise); |
| 90 |
strcat(final, buffer); |
| 91 |
draw_num(181, final, 404, 459); |
| 92 |
} |
| 93 |
|
| 94 |
void draw_strength() |
| 95 |
{ |
| 96 |
char final[3+1]; |
| 97 |
snprintf(final, sizeof(final), "%03d", fstrength); |
| 98 |
draw_num(182, final, 81, 415); |
| 99 |
} |
| 100 |
|
| 101 |
void draw_defense() |
| 102 |
{ |
| 103 |
char final[3+1]; |
| 104 |
snprintf(final, sizeof(final), "%03d", fdefense); |
| 105 |
draw_num(183, final, 81, 437); |
| 106 |
} |
| 107 |
|
| 108 |
void draw_magic() |
| 109 |
{ |
| 110 |
char final[3+1]; |
| 111 |
snprintf(final, sizeof(final), "%03d", fmagic); |
| 112 |
draw_num(184, final, 81, 459); |
| 113 |
} |
| 114 |
|
| 115 |
void draw_level() |
| 116 |
{ |
| 117 |
char final[2+1]; |
| 118 |
snprintf(final, sizeof(final), "%d", *plevel); |
| 119 |
|
| 120 |
if (strlen(final) == 1) |
| 121 |
draw_num(SEQ_EXPLEVEL_NUMS, final, 528, 456); |
| 122 |
else |
| 123 |
draw_num(SEQ_EXPLEVEL_NUMS, final, 523, 456); |
| 124 |
|
| 125 |
} |
| 126 |
|
| 127 |
void draw_gold() |
| 128 |
{ |
| 129 |
char final[6+1]; |
| 130 |
snprintf(final, sizeof(final), |
| 131 |
(fgold < 100000) ? "%05d" : "%06d", |
| 132 |
fgold); |
| 133 |
draw_num(185, final, 298, 457); |
| 134 |
} |
| 135 |
|
| 136 |
|
| 137 |
void draw_bar(int life, int seqman) |
| 138 |
{ |
| 139 |
int cur = 0; |
| 140 |
int curx = 284; |
| 141 |
int cury = 412; |
| 142 |
int rnum = 3; |
| 143 |
int curx_start = curx; |
| 144 |
|
| 145 |
rect box; |
| 146 |
while(1) |
| 147 |
{ |
| 148 |
cur++; |
| 149 |
if (cur > life) |
| 150 |
{ |
| 151 |
cur--; |
| 152 |
int rem = (cur) - (cur / 10) * 10; |
| 153 |
if (rem != 0) |
| 154 |
{ |
| 155 |
rect_copy(&box, &k[seq[seqman].frame[rnum]].box); |
| 156 |
box.right = (box.right * ((rem) * 10)/100); |
| 157 |
//woah, there is part of a bar remaining. Lets do it. |
| 158 |
SDL_Rect src, dst; |
| 159 |
src.x = 0; src.y = 0; |
| 160 |
src.w = k[seq[seqman].frame[rnum]].box.right * (rem * 10) / 100; |
| 161 |
src.h = k[seq[seqman].frame[rnum]].box.bottom; |
| 162 |
dst.x = curx; dst.y = cury; |
| 163 |
IOGFX_background->blitNoColorKey(GFX_k[seq[seqman].frame[rnum]].k, &src, &dst); |
| 164 |
} |
| 165 |
//are we done? |
| 166 |
return; |
| 167 |
} |
| 168 |
|
| 169 |
rnum = 2; |
| 170 |
if (cur < 11) rnum = 1; |
| 171 |
if (cur == *plifemax) rnum = 3; |
| 172 |
|
| 173 |
if ((cur / 10) * 10 == cur) |
| 174 |
{ |
| 175 |
SDL_Rect dst; |
| 176 |
dst.x = curx; |
| 177 |
dst.y = cury; |
| 178 |
IOGFX_background->blitNoColorKey(GFX_k[seq[seqman].frame[rnum]].k, NULL, &dst); |
| 179 |
|
| 180 |
curx += k[seq[seqman].frame[rnum]].box.right; |
| 181 |
if (cur == 110) |
| 182 |
{cury += k[seq[seqman].frame[rnum]].box.bottom+5; |
| 183 |
curx = curx_start; |
| 184 |
|
| 185 |
} |
| 186 |
|
| 187 |
if (cur == 220) return; |
| 188 |
} |
| 189 |
} |
| 190 |
} |
| 191 |
|
| 192 |
|
| 193 |
void draw_health( void ) |
| 194 |
{ |
| 195 |
flifemax = *plifemax; |
| 196 |
draw_bar(flifemax, 190); |
| 197 |
flife = *plife; |
| 198 |
draw_bar(flife, 451); |
| 199 |
} |
| 200 |
|
| 201 |
void draw_icons() |
| 202 |
{ |
| 203 |
if (*pcur_weapon >= 1 && *pcur_weapon <= NB_ITEMS && play.item[*pcur_weapon - 1].active) |
| 204 |
{ |
| 205 |
check_seq_status(play.item[*pcur_weapon - 1].seq); |
| 206 |
SDL_Rect dst = {557, 413}; |
| 207 |
IOGFX_background->blit(GFX_k[seq[play.item[*pcur_weapon - 1].seq].frame[play.item[*pcur_weapon - 1].frame]].k, |
| 208 |
NULL, &dst); |
| 209 |
} |
| 210 |
|
| 211 |
if (*pcur_magic >= 1 && *pcur_magic <= NB_MITEMS && play.mitem[*pcur_magic - 1].active) |
| 212 |
{ |
| 213 |
check_seq_status(play.mitem[*pcur_magic - 1].seq); |
| 214 |
SDL_Rect dst = {153, 413}; |
| 215 |
IOGFX_background->blit(GFX_k[seq[play.mitem[*pcur_magic - 1].seq].frame[play.mitem[*pcur_magic - 1].frame]].k, |
| 216 |
NULL, &dst); |
| 217 |
} |
| 218 |
} |
| 219 |
|
| 220 |
|
| 221 |
/** draw_virtical, draw_hor, draw_virt2, draw_hor2: used to draw the |
| 222 |
magic jauge (in that order) (dinkvar.cpp:draw_mlevel() only) **/ |
| 223 |
|
| 224 |
void draw_mgauge_ver1(int percent, int mx, int my, int mseq, int mframe) |
| 225 |
{ |
| 226 |
int cut; |
| 227 |
if (percent > 25) percent = 25; |
| 228 |
percent = (percent * 4); |
| 229 |
rect myrect; |
| 230 |
rect_copy(&myrect, &k[seq[mseq].frame[mframe]].box); |
| 231 |
int full = myrect.bottom; |
| 232 |
cut = (full * percent) / 100; |
| 233 |
myrect.bottom = cut; |
| 234 |
|
| 235 |
my += (full - cut); |
| 236 |
|
| 237 |
SDL_Rect src, dst; |
| 238 |
src.x = src.y = 0; |
| 239 |
src.w = k[seq[mseq].frame[mframe]].box.right; |
| 240 |
src.h = k[seq[mseq].frame[mframe]].box.bottom * percent / 100; |
| 241 |
dst.x = mx; |
| 242 |
dst.y = my; |
| 243 |
IOGFX_background->blitNoColorKey(GFX_k[seq[mseq].frame[mframe]].k, &src, &dst); |
| 244 |
} |
| 245 |
|
| 246 |
void draw_mgauge_ver2(int percent, int mx, int my, int mseq, int mframe) |
| 247 |
{ |
| 248 |
int cut; |
| 249 |
if (percent > 25) percent = 25; |
| 250 |
percent = (percent * 4); |
| 251 |
rect myrect; |
| 252 |
rect_copy(&myrect, &k[seq[mseq].frame[mframe]].box); |
| 253 |
int full = myrect.bottom; |
| 254 |
cut = (full * percent) / 100; |
| 255 |
myrect.bottom = cut; |
| 256 |
|
| 257 |
SDL_Rect src, dst; |
| 258 |
src.x = src.y = 0; |
| 259 |
src.w = k[seq[mseq].frame[mframe]].box.right; |
| 260 |
src.h = k[seq[mseq].frame[mframe]].box.bottom * percent / 100; |
| 261 |
dst.x = mx; dst.y = my; |
| 262 |
IOGFX_background->blitNoColorKey(GFX_k[seq[mseq].frame[mframe]].k, &src, &dst); |
| 263 |
} |
| 264 |
|
| 265 |
void draw_mgauge_hor1(int percent, int mx, int my, int mseq, int mframe) |
| 266 |
{ |
| 267 |
int cut; |
| 268 |
if (percent > 25) percent = 25; |
| 269 |
percent = (percent * 4); |
| 270 |
rect myrect; |
| 271 |
rect_copy(&myrect, &k[seq[mseq].frame[mframe]].box); |
| 272 |
int full = myrect.right; |
| 273 |
cut = (full * percent) / 100; |
| 274 |
full = cut; |
| 275 |
myrect.right = full; |
| 276 |
|
| 277 |
SDL_Rect src, dst; |
| 278 |
src.x = src.y = 0; |
| 279 |
src.w = k[seq[mseq].frame[mframe]].box.right * percent / 100; |
| 280 |
src.h = k[seq[mseq].frame[mframe]].box.bottom; |
| 281 |
dst.x = mx; dst.y = my; |
| 282 |
IOGFX_background->blitNoColorKey(GFX_k[seq[mseq].frame[mframe]].k, &src, &dst); |
| 283 |
} |
| 284 |
|
| 285 |
void draw_mgauge_hor2(int percent, int mx, int my, int mseq, int mframe) |
| 286 |
{ |
| 287 |
int cut; |
| 288 |
if (percent > 25) percent = 25; |
| 289 |
percent = (percent * 4); |
| 290 |
rect myrect; |
| 291 |
rect_copy(&myrect, &k[seq[mseq].frame[mframe]].box); |
| 292 |
int full = myrect.right; |
| 293 |
cut = (full * percent) / 100; |
| 294 |
|
| 295 |
myrect.right = cut; |
| 296 |
mx += (full - cut); |
| 297 |
|
| 298 |
SDL_Rect src, dst; |
| 299 |
src.x = src.y = 0; |
| 300 |
src.w = k[seq[mseq].frame[mframe]].box.right * percent / 100; |
| 301 |
src.h = k[seq[mseq].frame[mframe]].box.bottom; |
| 302 |
dst.x = mx; |
| 303 |
dst.y = my; |
| 304 |
IOGFX_background->blitNoColorKey(GFX_k[seq[mseq].frame[mframe]].k, &src, &dst); |
| 305 |
} |
| 306 |
|
| 307 |
void draw_mgauge(int percent) |
| 308 |
{ |
| 309 |
//if (*pmagic_level < 1) return; |
| 310 |
|
| 311 |
int mseq = 180; |
| 312 |
int bary = 6; |
| 313 |
int barx = 7; |
| 314 |
|
| 315 |
if (percent > 0) draw_mgauge_ver1(percent, 149, 411, mseq, bary); |
| 316 |
percent -= 25; |
| 317 |
if (percent > 0) draw_mgauge_hor1(percent, 149, 409, mseq, barx); |
| 318 |
percent -= 25; |
| 319 |
if (percent > 0) draw_mgauge_ver2(percent, 215, 411, mseq, bary); |
| 320 |
percent -= 25; |
| 321 |
if (percent > 0) draw_mgauge_hor2(percent, 149, 466, mseq, barx); |
| 322 |
} |
| 323 |
|
| 324 |
|
| 325 |
/** |
| 326 |
* Sync status with player stats, and redraw full status |
| 327 |
*/ |
| 328 |
void draw_status_all(void) |
| 329 |
{ |
| 330 |
{ |
| 331 |
SDL_Rect src = {0, 0, 640, 80}, dst = {0, 400}; |
| 332 |
IOGFX_background->blitNoColorKey(GFX_k[seq[180].frame[3]].k, &src, &dst); |
| 333 |
} |
| 334 |
{ |
| 335 |
SDL_Rect src = {0, 0, 20, 400}, dst1 = {0, 0}, dst2 = {620, 0}; |
| 336 |
IOGFX_background->blitNoColorKey(GFX_k[seq[180].frame[1]].k, &src, &dst1); |
| 337 |
IOGFX_background->blitNoColorKey(GFX_k[seq[180].frame[2]].k, &src, &dst2); |
| 338 |
} |
| 339 |
|
| 340 |
fraise = next_raise(); |
| 341 |
if (*pexp < fraise) |
| 342 |
fexp = *pexp; |
| 343 |
else |
| 344 |
fexp = fraise - 1; |
| 345 |
fstrength = *pstrength; |
| 346 |
fmagic = *pmagic; |
| 347 |
fgold = *pgold; |
| 348 |
fdefense = *pdefense; |
| 349 |
last_magic_draw = 0; |
| 350 |
draw_exp(); |
| 351 |
draw_health(); |
| 352 |
draw_strength(); |
| 353 |
draw_defense(); |
| 354 |
draw_magic(); |
| 355 |
draw_gold(); |
| 356 |
draw_level(); |
| 357 |
draw_icons(); |
| 358 |
if (*pmagic_cost > 0 && *pmagic_level > 0) |
| 359 |
draw_mgauge(*pmagic_level * 100 / *pmagic_cost); |
| 360 |
} |
| 361 |
|
| 362 |
/** |
| 363 |
* Draw screen lateral bar, with screenlock skin |
| 364 |
*/ |
| 365 |
void drawscreenlock() { |
| 366 |
IOGFX_backbuffer->blitNoColorKey(GFX_k[seq[423].frame[9]].k, NULL, NULL); |
| 367 |
SDL_Rect dst = {620, 0}; |
| 368 |
IOGFX_backbuffer->blitNoColorKey(GFX_k[seq[423].frame[10]].k, NULL, &dst); |
| 369 |
} |
| 370 |
|
| 371 |
/** |
| 372 |
* Update player stats, and render status bar only as needed |
| 373 |
*/ |
| 374 |
void update_status_all() { |
| 375 |
bool drawexp = false; |
| 376 |
int next = next_raise(); |
| 377 |
|
| 378 |
if (next != fraise) { |
| 379 |
fraise += next / 40; |
| 380 |
|
| 381 |
if (fraise > next) |
| 382 |
fraise = next; |
| 383 |
|
| 384 |
drawexp = true; |
| 385 |
SoundPlayEffect(13,15050, 0,0 ,0); |
| 386 |
} |
| 387 |
|
| 388 |
if (*pexp != fexp |
| 389 |
&& ((game_choice.active == 0 && show_inventory == 0 && spr[1].freeze == 0) |
| 390 |
|| fexp + 10 < fraise)) { |
| 391 |
//update screen experience |
| 392 |
fexp += 10; |
| 393 |
//make noise here |
| 394 |
|
| 395 |
if (fexp > *pexp) |
| 396 |
fexp = *pexp; |
| 397 |
|
| 398 |
drawexp = true; |
| 399 |
SoundPlayEffect(13,29050, 0,0 ,0); |
| 400 |
|
| 401 |
if (fexp >= fraise) { |
| 402 |
*pexp -= next; |
| 403 |
fexp = 0; |
| 404 |
|
| 405 |
int script = load_script("lraise", 1); |
| 406 |
if (locate(script, "raise")) run_script(script); |
| 407 |
} |
| 408 |
} |
| 409 |
|
| 410 |
if (drawexp) { |
| 411 |
draw_exp(); |
| 412 |
} |
| 413 |
|
| 414 |
if (flifemax != *plifemax || flife != *plife) { |
| 415 |
if (flifemax < *plifemax) flifemax++; |
| 416 |
if (flifemax > *plifemax) flifemax--; |
| 417 |
if (flife > *plife) flife--; |
| 418 |
if (flife < *plife) flife++; |
| 419 |
if (flife > *plife) flife--; |
| 420 |
if (flife < *plife) flife++; |
| 421 |
draw_bar(flifemax, 190); |
| 422 |
draw_bar(flife, 451); |
| 423 |
} |
| 424 |
|
| 425 |
if (fstrength != *pstrength) { |
| 426 |
if (fstrength < *pstrength) fstrength++; |
| 427 |
if (fstrength > *pstrength) fstrength--; |
| 428 |
SoundPlayEffect( 22,22050, 0,0 ,0); |
| 429 |
draw_strength(); |
| 430 |
} |
| 431 |
|
| 432 |
if (fdefense != *pdefense) { |
| 433 |
if (fdefense < *pdefense) fdefense++; |
| 434 |
if (fdefense > *pdefense) fdefense--; |
| 435 |
SoundPlayEffect( 22,22050, 0,0 ,0); |
| 436 |
draw_defense(); |
| 437 |
} |
| 438 |
|
| 439 |
if (fmagic != *pmagic) { |
| 440 |
if (fmagic < *pmagic) fmagic++; |
| 441 |
if (fmagic > *pmagic) fmagic--; |
| 442 |
SoundPlayEffect( 22,22050, 0,0 ,0); |
| 443 |
draw_magic(); |
| 444 |
} |
| 445 |
|
| 446 |
if (fgold != *pgold) { |
| 447 |
if (fgold < *pgold) { |
| 448 |
fgold += 20; |
| 449 |
if (fgold > *pgold) fgold = *pgold; |
| 450 |
} |
| 451 |
|
| 452 |
if (fgold > *pgold) { |
| 453 |
fgold -= 20; |
| 454 |
if (fgold < *pgold) fgold = *pgold; |
| 455 |
} |
| 456 |
SoundPlayEffect( 14,22050, 0,0 ,0); |
| 457 |
draw_gold(); |
| 458 |
} |
| 459 |
|
| 460 |
if (*pmagic_level < *pmagic_cost) { |
| 461 |
if (show_inventory == 0) |
| 462 |
*pmagic_level += *pmagic; |
| 463 |
if (*pmagic_level > *pmagic_cost) *pmagic_level = *pmagic_cost; |
| 464 |
} |
| 465 |
|
| 466 |
if (*pmagic_cost > 0) if (*pmagic_level > 0) { |
| 467 |
int mnum = *pmagic_level * 100 / *pmagic_cost; |
| 468 |
if (mnum != last_magic_draw) { |
| 469 |
draw_mgauge(mnum); |
| 470 |
last_magic_draw = mnum; |
| 471 |
} |
| 472 |
} |
| 473 |
|
| 474 |
spr[1].strength = fstrength; |
| 475 |
spr[1].defense = fdefense; |
| 476 |
|
| 477 |
if (flife < 1) { |
| 478 |
int script = load_script("dinfo", 1000); |
| 479 |
if (locate(script, "die")) |
| 480 |
run_script(script); |
| 481 |
} |
| 482 |
} |