Skip to content

Commit

Permalink
Merge pull request #576 from akaAgar/attack-custom-damage-color
Browse files Browse the repository at this point in the history
Added DAMAGE.FLASH_COLOUR field for custom flash colors
  • Loading branch information
dashodanger committed Oct 6, 2023
2 parents bbcf79a + 645c3c4 commit e334bbc
Show file tree
Hide file tree
Showing 9 changed files with 42 additions and 9 deletions.
1 change: 1 addition & 0 deletions source_files/ddf/attack.cc
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const commandlist_t damage_commands[] =
DF("DAMAGE_IF_BENEFIT", damage_if, DDF_MobjGetBenefit),
DF("ALL_PLAYERS", all_players, DDF_MainGetBoolean), // Doesn't do anything (yet)
DF("GROUNDED_MONSTERS_ONLY", grounded_monsters, DDF_MainGetBoolean),
DF("FLASH_COLOUR", damage_flash_colour, DDF_MainGetRGB),

DF("OBITUARY", obituary, DDF_MainGetString),
DF("PAIN_STATE", pain, DDF_AtkGetLabel),
Expand Down
4 changes: 4 additions & 0 deletions source_files/ddf/main.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1913,6 +1913,7 @@ void damage_c::Copy(damage_c &src)
overkill = src.overkill;

no_armour = src.no_armour;
damage_flash_colour = src.damage_flash_colour;

bypass_all = src.bypass_all;
instakill = src.instakill;
Expand Down Expand Up @@ -1953,6 +1954,7 @@ void damage_c::Default(damage_c::default_e def)
damage_unless = nullptr;
damage_if = nullptr;
grounded_monsters = false;
damage_flash_colour = T_RED;
all_players = false;
break;
}
Expand All @@ -1969,6 +1971,7 @@ void damage_c::Default(damage_c::default_e def)
damage_unless = nullptr;
damage_if = nullptr;
grounded_monsters = false;
damage_flash_colour = T_RED;
all_players = false;
break;
}
Expand All @@ -1987,6 +1990,7 @@ void damage_c::Default(damage_c::default_e def)
damage_unless = nullptr;
damage_if = nullptr;
grounded_monsters = false;
damage_flash_colour = T_RED;
all_players = false;
break;
}
Expand Down
3 changes: 3 additions & 0 deletions source_files/ddf/thing.h
Original file line number Diff line number Diff line change
Expand Up @@ -749,6 +749,9 @@ class damage_c
// armour -- and vice versa.
bool no_armour;

// Color of the flash when player is hit by this damage type
rgbcol_t damage_flash_colour;

// Apply damange unconditionally
bool bypass_all;
// Damage is always health+1 with no resistances applied
Expand Down
2 changes: 2 additions & 0 deletions source_files/edge/e_player.cc
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,7 @@ void G_PlayerFinishLevel(player_t *p, bool keep_cards)
p->damage_pain = 0;
p->bonuscount = 0;
p->grin_count = 0;
p->last_damage_colour = T_RED;

//Lobo 2023: uncomment if still getting
// "INTERNAL ERROR: player has a removed attacker"
Expand Down Expand Up @@ -198,6 +199,7 @@ void player_s::Reborn()
damage_pain = 0;
extralight = 0;
flash = false;
last_damage_colour = T_RED;

attacker = NULL;

Expand Down
3 changes: 3 additions & 0 deletions source_files/edge/e_player.h
Original file line number Diff line number Diff line change
Expand Up @@ -278,6 +278,9 @@ typedef struct player_s
// how much damage was done (used for status bar)
float damage_pain;

// damage flash colour of last damage type inflicted
rgbcol_t last_damage_colour;

// So gun flashes light up the screen.
int extralight;
bool flash;
Expand Down
6 changes: 6 additions & 0 deletions source_files/edge/p_inter.cc
Original file line number Diff line number Diff line change
Expand Up @@ -1541,6 +1541,12 @@ void P_DamageMobj(mobj_t * target, mobj_t * inflictor, mobj_t * source,
// add damage after armour / invuln detection
if (damage > 0)
{
// Change damage color if new inflicted damage is greater than current processed damage
if (damage >= player->damagecount)
{
player->last_damage_colour = damtype->damage_flash_colour;
}

player->damagecount += (int)MAX(damage, DAMAGE_ADD_MIN);
player->damage_pain += damage;
}
Expand Down
28 changes: 21 additions & 7 deletions source_files/edge/r_colormap.cc
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,10 @@ void V_SetPalette(int type, float amount)

switch (type)
{
case PALETTE_PAIN:
palette = (int)(PAIN_PALS + amount * NUM_PAIN_PALS);
break;
// Pain color fading is now handled differently in V_IndexColourToRGB
// case PALETTE_PAIN:
// palette = (int)(PAIN_PALS + amount * NUM_PAIN_PALS);
// break;

case PALETTE_BONUS:
palette = (int)(BONUS_PALS + amount * NUM_BONUS_PALS);
Expand Down Expand Up @@ -549,11 +550,24 @@ void V_ColourNewFrame(void)
// Returns an RGB value from an index value - used the current
// palette. The byte pointer is assumed to point a 3-byte array.
//
void V_IndexColourToRGB(int indexcol, byte *returncol)
void V_IndexColourToRGB(int indexcol, byte *returncol, rgbcol_t last_damage_colour, float damageAmount)
{
returncol[0] = playpal_data[cur_palette][indexcol][0];
returncol[1] = playpal_data[cur_palette][indexcol][1];
returncol[2] = playpal_data[cur_palette][indexcol][2];
if ((cur_palette == PALETTE_NORMAL) || (cur_palette == PALETTE_PAIN))
{
float r = (float)RGB_RED(last_damage_colour) / 255.0;
float g = (float)RGB_GRN(last_damage_colour) / 255.0;
float b = (float)RGB_BLU(last_damage_colour) / 255.0;

returncol[0] = (byte)MAX(0, MIN(255, r * damageAmount * 2.5));
returncol[1] = (byte)MAX(0, MIN(255, g * damageAmount * 2.5));
returncol[2] = (byte)MAX(0, MIN(255, b * damageAmount * 2.5));
}
else
{
returncol[0] = playpal_data[cur_palette][indexcol][0];
returncol[1] = playpal_data[cur_palette][indexcol][1];
returncol[2] = playpal_data[cur_palette][indexcol][2];
}
}

rgbcol_t V_LookupColour(int col)
Expand Down
2 changes: 1 addition & 1 deletion source_files/edge/r_colormap.h
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ void V_InitPalette(void);
void V_InitColour(void);

// -ACB- 1999/10/11 Gets an RGB colour from the current palette
void V_IndexColourToRGB(int indexcol, byte *returncol);
void V_IndexColourToRGB(int indexcol, byte *returncol, rgbcol_t last_damage_colour, float damageAmount);

rgbcol_t V_LookupColour(int col);

Expand Down
2 changes: 1 addition & 1 deletion source_files/edge/r_effects.cc
Original file line number Diff line number Diff line change
Expand Up @@ -240,7 +240,7 @@ void RGL_PaletteEffect(player_t *player)
}
else
{
V_IndexColourToRGB(pal_black, rgb_data);
V_IndexColourToRGB(pal_black, rgb_data, player->last_damage_colour, player->damagecount);

int rgb_max = MAX(rgb_data[0], MAX(rgb_data[1], rgb_data[2]));

Expand Down

0 comments on commit e334bbc

Please sign in to comment.