| 1 |
/* Emacs style mode select -*- C -*- |
| 2 |
*----------------------------------------------------------------------------- |
| 3 |
* |
| 4 |
* |
| 5 |
* PrBoom: a Doom port merged with LxDoom and LSDLDoom |
| 6 |
* based on BOOM, a modified and improved DOOM engine |
| 7 |
* Copyright (C) 1999 by |
| 8 |
* id Software, Chi Hoang, Lee Killough, Jim Flynn, Rand Phares, Ty Halderman |
| 9 |
* Copyright (C) 1999-2000 by |
| 10 |
* Jess Haas, Nicolas Kalkhof, Colin Phipps, Florian Schulze |
| 11 |
* Copyright 2005, 2006 by |
| 12 |
* Florian Schulze, Colin Phipps, Neil Stevens, Andrey Budko |
| 13 |
* |
| 14 |
* This program is free software; you can redistribute it and/or |
| 15 |
* modify it under the terms of the GNU General Public License |
| 16 |
* as published by the Free Software Foundation; either version 2 |
| 17 |
* of the License, or (at your option) any later version. |
| 18 |
* |
| 19 |
* This program is distributed in the hope that it will be useful, |
| 20 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 21 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 22 |
* GNU General Public License for more details. |
| 23 |
* |
| 24 |
* You should have received a copy of the GNU General Public License |
| 25 |
* along with this program; if not, write to the Free Software |
| 26 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA |
| 27 |
* 02111-1307, USA. |
| 28 |
* |
| 29 |
* DESCRIPTION: Heads-up displays |
| 30 |
* |
| 31 |
*----------------------------------------------------------------------------- |
| 32 |
*/ |
| 33 |
|
| 34 |
// killough 5/3/98: remove unnecessary headers |
| 35 |
|
| 36 |
#include "doomstat.h" |
| 37 |
#include "hu_stuff.h" |
| 38 |
#include "hu_lib.h" |
| 39 |
#include "st_stuff.h" /* jff 2/16/98 need loc of status bar */ |
| 40 |
#include "s_sound.h" |
| 41 |
#include "dstrings.h" |
| 42 |
#include "sounds.h" |
| 43 |
#include "d_deh.h" /* Ty 03/27/98 - externalization of mapnamesx arrays */ |
| 44 |
#include "g_game.h" |
| 45 |
#include "r_main.h" |
| 46 |
#include "p_inter.h" |
| 47 |
#include "p_tick.h" |
| 48 |
#include "p_map.h" |
| 49 |
#include "sc_man.h" |
| 50 |
#include "m_menu.h" |
| 51 |
#include "m_misc.h" |
| 52 |
#include "r_main.h" |
| 53 |
#include "lprintf.h" |
| 54 |
#include "p_setup.h" |
| 55 |
#include "w_wad.h" |
| 56 |
#include "e6y.h" //e6y |
| 57 |
#include "g_overflow.h" |
| 58 |
|
| 59 |
#include "dsda.h" |
| 60 |
#include "dsda/exhud.h" |
| 61 |
#include "dsda/map_format.h" |
| 62 |
#include "dsda/mapinfo.h" |
| 63 |
#include "dsda/messenger.h" |
| 64 |
#include "dsda/pause.h" |
| 65 |
#include "dsda/settings.h" |
| 66 |
#include "dsda/stretch.h" |
| 67 |
|
| 68 |
static player_t* plr; |
| 69 |
|
| 70 |
typedef struct custom_message_s |
| 71 |
{ |
| 72 |
int ticks; |
| 73 |
int sfx; |
| 74 |
const char *msg; |
| 75 |
} custom_message_t; |
| 76 |
|
| 77 |
static custom_message_t custom_message[MAX_MAXPLAYERS]; |
| 78 |
static custom_message_t *custom_message_p; |
| 79 |
|
| 80 |
//jff 2/16/98 status color change levels |
| 81 |
int hud_ammo_red; // ammo percent less than which status is red |
| 82 |
int hud_ammo_yellow; // ammo percent less is yellow more green |
| 83 |
int hud_health_red; // health amount less than which status is red |
| 84 |
int hud_health_yellow; // health amount less than which status is yellow |
| 85 |
int hud_health_green; // health amount above is blue, below is green |
| 86 |
|
| 87 |
void HU_InitThresholds(void) |
| 88 |
{ |
| 89 |
hud_health_red = dsda_IntConfig(dsda_config_hud_health_red); |
| 90 |
hud_health_yellow = dsda_IntConfig(dsda_config_hud_health_yellow); |
| 91 |
hud_health_green = dsda_IntConfig(dsda_config_hud_health_green); |
| 92 |
hud_ammo_red = dsda_IntConfig(dsda_config_hud_ammo_red); |
| 93 |
hud_ammo_yellow = dsda_IntConfig(dsda_config_hud_ammo_yellow); |
| 94 |
} |
| 95 |
|
| 96 |
dsda_string_t hud_title; |
| 97 |
|
| 98 |
static void HU_FetchTitle(void) |
| 99 |
{ |
| 100 |
if (hud_title.string) |
| 101 |
dsda_FreeString(&hud_title); |
| 102 |
|
| 103 |
dsda_HUTitle(&hud_title); |
| 104 |
} |
| 105 |
|
| 106 |
static void HU_InitMessages(void) |
| 107 |
{ |
| 108 |
custom_message_p = &custom_message[displayplayer]; |
| 109 |
custom_message_p->ticks = 0; |
| 110 |
} |
| 111 |
|
| 112 |
static void HU_InitPlayer(void) |
| 113 |
{ |
| 114 |
// killough 3/7/98 |
| 115 |
plr = &players[displayplayer]; |
| 116 |
} |
| 117 |
|
| 118 |
typedef struct crosshair_s |
| 119 |
{ |
| 120 |
int lump; |
| 121 |
int w, h, flags; |
| 122 |
int target_x, target_y, target_z, target_sprite; |
| 123 |
float target_screen_x, target_screen_y; |
| 124 |
} crosshair_t; |
| 125 |
|
| 126 |
static crosshair_t crosshair; |
| 127 |
|
| 128 |
static const char *crosshair_nam[HU_CROSSHAIRS] = |
| 129 |
{ NULL, "CROSS1", "CROSS2", "CROSS3", "CROSS4", "CROSS5", "CROSS6", "CROSS7" }; |
| 130 |
|
| 131 |
static int hudadd_crosshair; |
| 132 |
static int hudadd_crosshair_scale; |
| 133 |
static int hudadd_crosshair_health; |
| 134 |
static int hudadd_crosshair_target; |
| 135 |
static int hudadd_crosshair_lock_target; |
| 136 |
|
| 137 |
void HU_InitCrosshair(void) |
| 138 |
{ |
| 139 |
hudadd_crosshair_scale = dsda_IntConfig(dsda_config_hudadd_crosshair_scale); |
| 140 |
hudadd_crosshair_health = dsda_IntConfig(dsda_config_hudadd_crosshair_health); |
| 141 |
hudadd_crosshair_target = dsda_IntConfig(dsda_config_hudadd_crosshair_target); |
| 142 |
hudadd_crosshair_lock_target = dsda_IntConfig(dsda_config_hudadd_crosshair_lock_target); |
| 143 |
hudadd_crosshair = dsda_IntConfig(dsda_config_hudadd_crosshair); |
| 144 |
|
| 145 |
if (!hudadd_crosshair || !crosshair_nam[hudadd_crosshair]) |
| 146 |
return; |
| 147 |
|
| 148 |
crosshair.lump = W_CheckNumForNameInternal(crosshair_nam[hudadd_crosshair]); |
| 149 |
if (crosshair.lump == LUMP_NOT_FOUND) |
| 150 |
return; |
| 151 |
|
| 152 |
crosshair.w = R_NumPatchWidth(crosshair.lump); |
| 153 |
crosshair.h = R_NumPatchHeight(crosshair.lump); |
| 154 |
|
| 155 |
crosshair.flags = VPT_TRANS; |
| 156 |
if (hudadd_crosshair_scale) |
| 157 |
crosshair.flags |= VPT_STRETCH; |
| 158 |
} |
| 159 |
|
| 160 |
dboolean HU_CrosshairEnabled(void) |
| 161 |
{ |
| 162 |
return hudadd_crosshair > 0; |
| 163 |
} |
| 164 |
|
| 165 |
void SetCrosshairTarget(void) |
| 166 |
{ |
| 167 |
crosshair.target_screen_x = 0.0f; |
| 168 |
crosshair.target_screen_y = 0.0f; |
| 169 |
|
| 170 |
if (hudadd_crosshair_lock_target && crosshair.target_sprite >= 0) |
| 171 |
{ |
| 172 |
float x, y, z; |
| 173 |
float winx, winy, winz; |
| 174 |
|
| 175 |
x = -(float)crosshair.target_x / MAP_SCALE; |
| 176 |
z = (float)crosshair.target_y / MAP_SCALE; |
| 177 |
y = (float)crosshair.target_z / MAP_SCALE; |
| 178 |
|
| 179 |
if (R_Project(x, y, z, &winx, &winy, &winz)) |
| 180 |
{ |
| 181 |
int top, bottom, h; |
| 182 |
stretch_param_t *params = dsda_StretchParams(crosshair.flags); |
| 183 |
|
| 184 |
if (V_IsSoftwareMode()) |
| 185 |
{ |
| 186 |
winy += (float)(viewheight/2 - centery); |
| 187 |
} |
| 188 |
|
| 189 |
top = SCREENHEIGHT; |
| 190 |
h = crosshair.h; |
| 191 |
if (hudadd_crosshair_scale) |
| 192 |
{ |
| 193 |
h = h * params->video->height / 200; |
| 194 |
} |
| 195 |
bottom = top - viewheight + h; |
| 196 |
winy = BETWEEN(bottom, top, winy); |
| 197 |
|
| 198 |
if (!hudadd_crosshair_scale) |
| 199 |
{ |
| 200 |
crosshair.target_screen_x = winx - (crosshair.w / 2); |
| 201 |
crosshair.target_screen_y = SCREENHEIGHT - winy - (crosshair.h / 2); |
| 202 |
} |
| 203 |
else |
| 204 |
{ |
| 205 |
crosshair.target_screen_x = (winx - params->deltax1) * 320.0f / params->video->width - (crosshair.w / 2); |
| 206 |
crosshair.target_screen_y = 200 - (winy - params->deltay1) * 200.0f / params->video->height - (crosshair.h / 2); |
| 207 |
} |
| 208 |
} |
| 209 |
} |
| 210 |
} |
| 211 |
|
| 212 |
mobj_t *HU_Target(void) |
| 213 |
{ |
| 214 |
angle_t an = plr->mo->angle; |
| 215 |
|
| 216 |
// intercepts overflow guard |
| 217 |
overflows_enabled = false; |
| 218 |
P_AimLineAttack(plr->mo, an, 16*64*FRACUNIT, 0); |
| 219 |
if (plr->readyweapon == wp_missile || plr->readyweapon == wp_plasma || plr->readyweapon == wp_bfg) |
| 220 |
{ |
| 221 |
if (!linetarget) |
| 222 |
P_AimLineAttack(plr->mo, an += 1<<26, 16*64*FRACUNIT, 0); |
| 223 |
if (!linetarget) |
| 224 |
P_AimLineAttack(plr->mo, an -= 2<<26, 16*64*FRACUNIT, 0); |
| 225 |
} |
| 226 |
overflows_enabled = true; |
| 227 |
|
| 228 |
return linetarget; |
| 229 |
} |
| 230 |
|
| 231 |
void HU_DrawCrosshair(void) |
| 232 |
{ |
| 233 |
int cm; |
| 234 |
|
| 235 |
if (!hudadd_crosshair) |
| 236 |
return; |
| 237 |
|
| 238 |
crosshair.target_sprite = -1; |
| 239 |
|
| 240 |
if ( |
| 241 |
!crosshair_nam[hudadd_crosshair] || |
| 242 |
crosshair.lump == -1 || |
| 243 |
automap_active || |
| 244 |
menuactive || |
| 245 |
dsda_Paused() |
| 246 |
) |
| 247 |
{ |
| 248 |
return; |
| 249 |
} |
| 250 |
|
| 251 |
if (hudadd_crosshair_health) |
| 252 |
cm = ST_HealthColor(plr->health); |
| 253 |
else |
| 254 |
cm = dsda_IntConfig(dsda_config_hudadd_crosshair_color); |
| 255 |
|
| 256 |
if (hudadd_crosshair_target || hudadd_crosshair_lock_target) |
| 257 |
{ |
| 258 |
mobj_t *target; |
| 259 |
|
| 260 |
target = HU_Target(); |
| 261 |
|
| 262 |
if (target && !(target->flags & MF_SHADOW)) |
| 263 |
{ |
| 264 |
crosshair.target_x = target->x; |
| 265 |
crosshair.target_y = target->y; |
| 266 |
crosshair.target_z = target->z; |
| 267 |
crosshair.target_z += target->height / 2 + target->height / 8; |
| 268 |
crosshair.target_sprite = target->sprite; |
| 269 |
|
| 270 |
if (hudadd_crosshair_target) |
| 271 |
cm = dsda_IntConfig(dsda_config_hudadd_crosshair_target_color); |
| 272 |
} |
| 273 |
} |
| 274 |
|
| 275 |
SetCrosshairTarget(); |
| 276 |
|
| 277 |
if (crosshair.target_screen_x != 0) |
| 278 |
{ |
| 279 |
float x = crosshair.target_screen_x; |
| 280 |
float y = crosshair.target_screen_y; |
| 281 |
V_DrawNumPatchPrecise(x, y, 0, crosshair.lump, cm, crosshair.flags); |
| 282 |
} |
| 283 |
else |
| 284 |
{ |
| 285 |
int x, y, st_height; |
| 286 |
|
| 287 |
if (!hudadd_crosshair_scale) |
| 288 |
{ |
| 289 |
st_height = (R_PartialView() ? ST_SCALED_HEIGHT : 0); |
| 290 |
x = (SCREENWIDTH - crosshair.w) / 2; |
| 291 |
y = (SCREENHEIGHT - st_height - crosshair.h) / 2; |
| 292 |
} |
| 293 |
else |
| 294 |
{ |
| 295 |
st_height = (R_PartialView() ? ST_HEIGHT : 0); |
| 296 |
x = (320 - crosshair.w) / 2; |
| 297 |
y = (200 - st_height - crosshair.h) / 2; |
| 298 |
} |
| 299 |
|
| 300 |
V_DrawNumPatch(x, y, 0, crosshair.lump, cm, crosshair.flags); |
| 301 |
} |
| 302 |
} |
| 303 |
|
| 304 |
void HU_AnnounceMap(void) |
| 305 |
{ |
| 306 |
if (dsda_IntConfig(dsda_config_announce_map)) |
| 307 |
{ |
| 308 |
static int last_gamemap; |
| 309 |
static int last_gameepisode; |
| 310 |
|
| 311 |
if (gamemap != last_gamemap || gameepisode != last_gameepisode) |
| 312 |
{ |
| 313 |
const char *author; |
| 314 |
|
| 315 |
last_gamemap = gamemap; |
| 316 |
last_gameepisode = gameepisode; |
| 317 |
|
| 318 |
author = dsda_MapAuthor(); |
| 319 |
if (author && author[0]) |
| 320 |
{ |
| 321 |
dsda_string_t message; |
| 322 |
|
| 323 |
dsda_StringPrintF(&message, "%s by %s", hud_title.string, author); |
| 324 |
dsda_AddAlert(message.string); |
| 325 |
dsda_FreeString(&message); |
| 326 |
} |
| 327 |
else |
| 328 |
{ |
| 329 |
dsda_AddAlert(hud_title.string); |
| 330 |
} |
| 331 |
} |
| 332 |
} |
| 333 |
} |
| 334 |
|
| 335 |
// |
| 336 |
// HU_Start(void) |
| 337 |
// |
| 338 |
// Create and initialize the heads-up display |
| 339 |
// |
| 340 |
// This routine must be called after any change to the heads up configuration |
| 341 |
// in order for the changes to take effect in the actual displays |
| 342 |
// |
| 343 |
// Passed nothing, returns nothing |
| 344 |
// |
| 345 |
void HU_Start(void) |
| 346 |
{ |
| 347 |
HU_InitThresholds(); |
| 348 |
HU_InitPlayer(); |
| 349 |
HU_InitMessages(); |
| 350 |
HU_FetchTitle(); |
| 351 |
HU_InitCrosshair(); |
| 352 |
|
| 353 |
dsda_InitExHud(); |
| 354 |
|
| 355 |
HU_AnnounceMap(); |
| 356 |
} |
| 357 |
|
| 358 |
// |
| 359 |
// HU_Drawer() |
| 360 |
// |
| 361 |
// Draw all the pieces of the heads-up display |
| 362 |
// |
| 363 |
// Passed nothing, returns nothing |
| 364 |
// |
| 365 |
void HU_Drawer(void) |
| 366 |
{ |
| 367 |
V_BeginUIDraw(); |
| 368 |
|
| 369 |
HU_DrawCrosshair(); |
| 370 |
|
| 371 |
dsda_DrawExHud(); |
| 372 |
|
| 373 |
V_EndUIDraw(); |
| 374 |
} |
| 375 |
|
| 376 |
char* secret_message; |
| 377 |
|
| 378 |
static void HU_UpdateSecretMessage(const char* message) |
| 379 |
{ |
| 380 |
if (secret_message) |
| 381 |
Z_Free(secret_message); |
| 382 |
|
| 383 |
secret_message = Z_Strdup(message); |
| 384 |
} |
| 385 |
|
| 386 |
char* HU_SecretMessage(void) { |
| 387 |
return custom_message_p->ticks > 0 ? secret_message : NULL; |
| 388 |
} |
| 389 |
|
| 390 |
// |
| 391 |
// HU_Ticker() |
| 392 |
// |
| 393 |
// Update the hud displays once per frame |
| 394 |
// |
| 395 |
// Passed nothing, returns nothing |
| 396 |
// |
| 397 |
void HU_Ticker(void) |
| 398 |
{ |
| 399 |
int i; |
| 400 |
|
| 401 |
dsda_UpdateMessenger(); |
| 402 |
|
| 403 |
// centered messages |
| 404 |
for (i = 0; i < g_maxplayers; i++) |
| 405 |
{ |
| 406 |
if (custom_message[i].ticks > 0) |
| 407 |
custom_message[i].ticks--; |
| 408 |
} |
| 409 |
|
| 410 |
if (custom_message_p->msg) |
| 411 |
{ |
| 412 |
HU_UpdateSecretMessage(custom_message_p->msg); |
| 413 |
|
| 414 |
custom_message_p->msg = NULL; |
| 415 |
|
| 416 |
if (custom_message_p->sfx > 0 && custom_message_p->sfx < num_sfx) |
| 417 |
{ |
| 418 |
S_StartVoidSound(custom_message_p->sfx); |
| 419 |
} |
| 420 |
} |
| 421 |
|
| 422 |
dsda_UpdateExHud(); |
| 423 |
} |
| 424 |
|
| 425 |
// |
| 426 |
// HU_Responder() |
| 427 |
// |
| 428 |
// Responds to input events that affect the heads up displays |
| 429 |
// |
| 430 |
// Passed the event to respond to, returns true if the event was handled |
| 431 |
// |
| 432 |
dboolean HU_Responder(event_t *ev) |
| 433 |
{ |
| 434 |
if (dsda_InputActivated(dsda_input_repeat_message)) // phares |
| 435 |
{ |
| 436 |
dsda_ReplayMessage(); |
| 437 |
|
| 438 |
return true; |
| 439 |
} |
| 440 |
|
| 441 |
return false; |
| 442 |
} |
| 443 |
|
| 444 |
int SetCustomMessage(int plr, const char *msg, int ticks, int sfx) |
| 445 |
{ |
| 446 |
custom_message_t item; |
| 447 |
|
| 448 |
if (plr < 0 || plr >= g_maxplayers || !msg || ticks < 0 || sfx < 0 || sfx >= num_sfx) |
| 449 |
{ |
| 450 |
return false; |
| 451 |
} |
| 452 |
|
| 453 |
item.msg = msg; |
| 454 |
item.ticks = ticks; |
| 455 |
item.sfx = sfx; |
| 456 |
|
| 457 |
custom_message[plr] = item; |
| 458 |
|
| 459 |
return true; |
| 460 |
} |