diff --git a/Source/cross.h b/Source/cross.h new file mode 100644 index 00000000..468868e1 --- /dev/null +++ b/Source/cross.h @@ -0,0 +1,44 @@ +// Copyright © 2013-2022 Fabian Greffrath +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// +// DESCRIPTION: +// crosshair patches + +static unsigned char cross1[] = { + 5,0,5,0,0,0,0,0,28,0,0,0,34,0,0,0,40,0,0,0,53,0,0,0,59,0,0,0,2,1,0,184,0,255, + 2,1,0,184,0,255,0,2,0,184,184,0,3,2,0,184,184,0,255,2,1,0,184,0,255,2,1,0, + 184,0,255, +}; +static unsigned char cross2[] = { + 5,0,5,0,0,0,0,0,28,0,0,0,29,0,0,0,30,0,0,0,38,0,0,0,44,0,0,0,255,255,2,3,0, + 184,184,184,0,255,2,1,0,184,0,255,2,1,0,184,0,255, +}; +static unsigned char cross3[] = { + 5,0,5,0,0,0,0,0,28,0,0,0,29,0,0,0,30,0,0,0,36,0,0,0,37,0,0,0,255,255,2,1,0, + 184,0,255,255,255, +}; +static unsigned char cross4[] = { + 0x09, 0x00, 0x09, 0x00, 0x00, 0x00, 0x00, 0x00, 0x2c, 0x00, 0x00, 0x00, + 0x32, 0x00, 0x00, 0x00, 0x38, 0x00, 0x00, 0x00, 0x3e, 0x00, 0x00, 0x00, + 0x3f, 0x00, 0x00, 0x00, 0x4e, 0x00, 0x00, 0x00, 0x4f, 0x00, 0x00, 0x00, + 0x55, 0x00, 0x00, 0x00, 0x5b, 0x00, 0x00, 0x00, 0x04, 0x01, 0xb8, 0xb8, + 0xb8, 0xff, 0x04, 0x01, 0xb8, 0xb8, 0xb8, 0xff, 0x04, 0x01, 0xb8, 0xb8, + 0xb8, 0xff, 0xff, 0x00, 0x03, 0xb8, 0xb8, 0xb8, 0xb8, 0xb8, 0x06, 0x03, + 0xb8, 0xb8, 0xb8, 0xb8, 0xb8, 0xff, 0xff, 0x04, 0x01, 0xb8, 0xb8, 0xb8, + 0xff, 0x04, 0x01, 0xb8, 0xb8, 0xb8, 0xff, 0x04, 0x01, 0xb8, 0xb8, 0xb8, + 0xff +}; diff --git a/Source/hu_stuff.c b/Source/hu_stuff.c index b627d559..56cd2f82 100644 --- a/Source/hu_stuff.c +++ b/Source/hu_stuff.c @@ -38,6 +38,7 @@ #include "d_deh.h" /* Ty 03/27/98 - externalization of mapnamesx arrays */ #include "r_draw.h" #include "m_input.h" +#include "p_map.h" // crosshair (linetarget) // global heads up display controls @@ -218,6 +219,13 @@ int hud_msg_timer = HU_MSGTIMEOUT * (1000/TICRATE); // killough 11/98 int message_timer = HU_MSGTIMEOUT * (1000/TICRATE); // killough 11/98 int chat_msg_timer = HU_MSGTIMEOUT * (1000/TICRATE); // killough 11/98 +static void HU_InitCrosshair(void); +int hud_crosshair; +boolean hud_crosshair_health; +boolean hud_crosshair_target; +int hud_crosshair_color; +int hud_crosshair_target_color; + //jff 2/16/98 initialization strings for ammo, health, armor widgets static char hud_coordstrx[32]; static char hud_coordstry[32]; @@ -708,6 +716,10 @@ void HU_Start(void) HUlib_initIText(&w_inputbuffer[i], 0, 0, 0, 0, colrngs[hudcolor_chat], &always_off); + // init crosshair + if (hud_crosshair) + HU_InitCrosshair(); + // now allow the heads-up display to run headsupactive = true; } @@ -823,6 +835,82 @@ static void HU_widget_build_sttime(void) HUlib_addCharToTextLine(&w_sttime, *s++); } +typedef struct +{ + patch_t *patch; + int w, h, x, y; + char *cr; +} crosshair_t; + +static crosshair_t crosshair; + +const char *crosshair_nam[HU_CROSSHAIRS] = + { NULL, "CROSS1", "CROSS2", "CROSS3", "CROSS4" }; +const char *crosshair_str[HU_CROSSHAIRS+1] = + { "none", "cross", "angle", "dot", "big", NULL }; + +static void HU_InitCrosshair(void) +{ + if (crosshair.patch) + Z_ChangeTag(crosshair.patch, PU_CACHE); + + crosshair.patch = W_CacheLumpName(crosshair_nam[hud_crosshair], PU_STATIC); + + crosshair.w = SHORT(crosshair.patch->width)/2; + crosshair.h = SHORT(crosshair.patch->height)/2; + crosshair.x = ORIGWIDTH/2; +} + +static void HU_UpdateCrosshair(void) +{ + crosshair.y = (screenblocks <= 10) ? (ORIGHEIGHT-ST_HEIGHT)/2 : ORIGHEIGHT/2; + + if (hud_crosshair_health) + { + int health = plr->health; + + if (health < health_red) + crosshair.cr = colrngs[CR_RED]; + else if (health < health_yellow) + crosshair.cr = colrngs[CR_GOLD]; + else if (health <= health_green) + crosshair.cr = colrngs[CR_GREEN]; + else + crosshair.cr = colrngs[CR_BLUE]; + } + else + crosshair.cr = colrngs[hud_crosshair_color]; + + if (hud_crosshair_target) + { + angle_t an = plr->mo->angle; + ammotype_t ammo = weaponinfo[plr->readyweapon].ammo; + fixed_t range = (ammo == am_noammo) ? MELEERANGE : 16*64*FRACUNIT; + + P_AimLineAttack(plr->mo, an, range, 0); + if (ammo == am_misl || ammo == am_cell) + { + if (!linetarget) + P_AimLineAttack(plr->mo, an += 1<<26, range, 0); + if (!linetarget) + P_AimLineAttack(plr->mo, an -= 2<<26, range, 0); + } + + if (linetarget && !(linetarget->flags & MF_SHADOW)) + { + crosshair.cr = colrngs[hud_crosshair_target_color]; + } + } +} + +static void HU_DrawCrosshair(void) +{ + if (crosshair.patch) + V_DrawPatchTranslated(crosshair.x - crosshair.w, + crosshair.y - crosshair.h, + 0, crosshair.patch, crosshair.cr, 0); +} + // [FG] level stats and level time widgets int map_player_coords, map_level_stats, map_level_time; @@ -1405,6 +1493,10 @@ void HU_Drawer(void) // display the interactive buffer for chat entry HUlib_drawIText(&w_chat); + + // display crosshair + if (hud_crosshair) + HU_DrawCrosshair(); } // @@ -1632,6 +1724,10 @@ void HU_Ticker(void) HU_widget_build_sttime(); HU_widget_build_monsec(); } + + // update crosshair properties + if (hud_crosshair) + HU_UpdateCrosshair(); } #define QUEUESIZE 128 diff --git a/Source/hu_stuff.h b/Source/hu_stuff.h index 267172cb..dfcde2fc 100644 --- a/Source/hu_stuff.h +++ b/Source/hu_stuff.h @@ -88,6 +88,16 @@ extern int hud_secret_message; // "A secret is revealed!" message extern int map_player_coords, map_level_stats, map_level_time; // [FG] level stats and level time widgets extern int hud_timests; // Time/STS above status bar +extern int hud_crosshair; +extern boolean hud_crosshair_health; +extern boolean hud_crosshair_target; +extern int hud_crosshair_color; +extern int hud_crosshair_target_color; + +#define HU_CROSSHAIRS 5 +extern const char *crosshair_nam[HU_CROSSHAIRS]; +extern const char *crosshair_str[HU_CROSSHAIRS+1]; + #endif //---------------------------------------------------------------------------- diff --git a/Source/info.c b/Source/info.c index 63df5f4b..7a1c7a78 100644 --- a/Source/info.c +++ b/Source/info.c @@ -7866,6 +7866,9 @@ static const char cr_white[] = // [FG] replace embedded non-free plasma ball sprites #include "beta.h" +// [FG] crosshair patches +#include "cross.h" + // killough 1/31/98: // Table of predefined lumps, used to make up for any wad deficiencies. // Always overriden by iwad or pwads. @@ -7935,6 +7938,12 @@ const lumpinfo_t predefined_lumps[]={ { "BOXLC", sizeof boxlc, boxlc }, { "BOXLR", sizeof boxlr, boxlr }, + // [FG] crosshair patches + { "CROSS1", sizeof cross1, cross1 }, + { "CROSS2", sizeof cross2, cross2 }, + { "CROSS3", sizeof cross3, cross3 }, + { "CROSS4", sizeof cross4, cross4 }, + // killough 8/98: remove ENDBOOM lump, use id's ENDOOM instead { "S_START"}, // killough 3/21/98 diff --git a/Source/m_menu.c b/Source/m_menu.c index 04d657cc..067495f8 100644 --- a/Source/m_menu.c +++ b/Source/m_menu.c @@ -3126,6 +3126,14 @@ setup_menu_t stat_settings2[] = {"\"A SECRET IS REVEALED!\" MESSAGE",S_YESNO,m_null,ST_X,ST_Y+6*8, {"hud_secret_message"}}, {"SHOW TIME/STS ABOVE STATUS BAR",S_YESNO,m_null,ST_X,ST_Y+7*8, {"hud_timests"}}, + {"CROSSHAIR",S_SKIP|S_TITLE,m_null,ST_X,ST_Y+ 9*8 }, + + {"ENABLE CROSSHAIR", S_CHOICE,m_null,ST_X,ST_Y+10*8, {"hud_crosshair"}, 0, NULL, crosshair_str}, + {"COLOR BY PLAYER HEALTH",S_YESNO, m_null,ST_X,ST_Y+11*8, {"hud_crosshair_health"}}, + {"HIGHLIGHT ON TARGET", S_YESNO, m_null,ST_X,ST_Y+12*8, {"hud_crosshair_target"}}, + {"DEFAULT COLOR", S_CRITEM,m_null,ST_X,ST_Y+13*8, {"hud_crosshair_color"}}, + {"HIGHLIGHT COLOR", S_CRITEM,m_null,ST_X,ST_Y+14*8, {"hud_crosshair_target_color"}}, + {"<- PREV" ,S_SKIP|S_PREV,m_null,KB_PREV,KB_Y+17*8, {stat_settings1}}, // Final entry diff --git a/Source/m_misc.c b/Source/m_misc.c index 0d3c0e70..550bd0db 100644 --- a/Source/m_misc.c +++ b/Source/m_misc.c @@ -1800,6 +1800,41 @@ default_t defaults[] = { "1 to enable display of time/STS above status bar" }, + { + "hud_crosshair", + (config_t *) &hud_crosshair, NULL, + {0}, {0,HU_CROSSHAIRS-1}, number, ss_none, wad_no, + "enable crosshair" + }, + + { + "hud_crosshair_health", + (config_t *) &hud_crosshair_health, NULL, + {0}, {0,1}, number, ss_none, wad_no, + "1 to change crosshair color by player health" + }, + + { + "hud_crosshair_target", + (config_t *) &hud_crosshair_target, NULL, + {0}, {0,1}, number, ss_none, wad_no, + "1 to change crosshair color on target" + }, + + { + "hud_crosshair_color", + (config_t *) &hud_crosshair_color, NULL, + {CR_GRAY}, {0,9}, number, ss_none, wad_no, + "default crosshair color" + }, + + { + "hud_crosshair_target_color", + (config_t *) &hud_crosshair_target_color, NULL, + {CR_YELLOW}, {0,9}, number, ss_none, wad_no, + "target crosshair color" + }, + { // killough 2/8/98: weapon preferences set by user: "weapon_choice_1", (config_t *) &weapon_preferences[0][0], NULL,