Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

New component: Hide VFX from invisible enemies #116

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cdtweaks/languages/english/weidu.tra
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ The uninstall messages above are normal and expected.
@25400 = ~Moderately decreased brightness~
@25500 = ~Original color~

@26000 = "Hide VFX from invisible enemies [Luke, EEex]"

/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
///// \\\\\
Expand Down
2 changes: 2 additions & 0 deletions cdtweaks/languages/italian/weidu.tra
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ o rimpiazzata da - un'altra facente parte di uno dei mods installati.~

@22000 = ~Sovrapposizioni migliorate per i giocatori daltonici [Fouinto]~

@26000 = "Nascondi gli effetti visivi dai nemici invisibili [Luke, EEex]"

/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
///// \\\\\
Expand Down
15 changes: 15 additions & 0 deletions cdtweaks/lib/comp_260.tpa
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
///// \\\\\
///// Hide VFX from invisible enemies \\\\\
///// \\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\

WITH_SCOPE BEGIN
INCLUDE "cdtweaks\luke\misc.tph"
//
INCLUDE "cdtweaks\lib\hide_vfx.tph"
//
LAF "HIDE_VFX" END
END
4 changes: 4 additions & 0 deletions cdtweaks/lib/hide_vfx.tph
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
DEFINE_ACTION_FUNCTION "HIDE_VFX"
BEGIN
LAF "APPEND_LUA_FUNCTION" STR_VAR "description" = "Misc Tweaks" "sourceFileSpec" = "cdtweaks\luke\lua\tweaks\hide_vfx.lua" "destRes" = "m_gttwks" END
END
154 changes: 154 additions & 0 deletions cdtweaks/luke/lua/tweaks/hide_vfx.lua
Original file line number Diff line number Diff line change
@@ -0,0 +1,154 @@
--[[
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
| cdtweaks: hide op215 and hardcoded animations played by opcodes 153, 155, 156, 201, 204, 205, 223, 226, 259, 197, 198, 200, 202, 203, 207, 227, 228, 299 from invisible enemies |
+---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+
--]]

function GTHIDEAN(op403CGameEffect, CGameEffect, CGameSprite)
local spriteActiveStats = EEex_Sprite_GetActiveStats(CGameSprite)
--
local hideVFX = function(effect)
if effect.m_effectId == 0xD7 then -- Play visual effect (215)
effect.m_res2:set(effect.m_res:get()) -- store it for later restoration
effect.m_res:set("") -- blank VFX
elseif (effect.m_effectId == 0x99 -- Sanctuary (153)
or effect.m_effectId == 0x9B -- Minor globe overlay (155)
or effect.m_effectId == 0x9C) -- Protection from normal missiles overlay (156)
then
effect.m_effectAmount = effect.m_dWFlags -- store it for later restoration
effect.m_res2:set(effect.m_res:get()) -- store it for later restoration
effect.m_res:set("") -- blank VFX
effect.m_dWFlags = 1 -- mode: custom
end
end
-- if invisible, hide incoming VFX
if EEex_IsBitSet(spriteActiveStats.m_generalState, 0x4) then
if CGameEffect.m_effectId == 0xD7 then -- Play visual effect (215)
CGameSprite:setLocalInt("gtHideVFXIfInvisible", 1)
--
CGameEffect.m_res2:set(CGameEffect.m_res:get()) -- store it for later restoration
CGameEffect.m_res:set("") -- blank VFX
elseif (CGameEffect.m_effectId == 0x99 -- Sanctuary (153)
or CGameEffect.m_effectId == 0x9B -- Minor globe overlay (155)
or CGameEffect.m_effectId == 0x9C) -- Protection from normal missiles overlay (156)
then
CGameSprite:setLocalInt("gtHideVFXIfInvisible", 1)
--
CGameEffect.m_effectAmount = CGameEffect.m_dWFlags -- store it for later restoration
CGameEffect.m_res2:set(CGameEffect.m_res:get()) -- store it for later restoration
CGameEffect.m_res:set("") -- blank VFX
CGameEffect.m_dWFlags = 1 -- mode: custom
end
else
-- if about to turn invisible, hide existing VFX
if CGameEffect.m_effectId == 0x14 and CGameEffect.m_dWFlags == 0 then -- Invisibility (20)
CGameSprite:setLocalInt("gtHideVFXIfInvisible", 1)
--
EEex_Utility_IterateCPtrList(CGameSprite.m_timedEffectList, hideVFX)
EEex_Utility_IterateCPtrList(CGameSprite.m_equipedEffectList, hideVFX)
-- suppress hardcoded animations
EEex_GameObject_ApplyEffect(CGameSprite,
{
["effectID"] = 0x123, -- Disable visual effects (291)
["dwFlags"] = 1,
["durationType"] = CGameEffect.m_durationType,
["duration"] = CGameEffect.m_duration,
["m_sourceRes"] = "GTRMV291",
["sourceID"] = CGameSprite.m_id,
["sourceTarget"] = CGameSprite.m_id,
})
end
end
end

-- restore VFX if no longer invisible --

EEex_Opcode_AddListsResolvedListener(function(sprite)
-- sanity check
if not EEex_GameObject_IsSprite(sprite) then
return
end
--
local restoreVFX = function(effect)
if effect.m_effectId == 0xD7 then -- Play visual effect (215)
effect.m_res:set(effect.m_res2:get())
effect.m_res2:set("")
elseif (effect.m_effectId == 0x99 -- Sanctuary (153)
or effect.m_effectId == 0x9B -- Minor globe overlay (155)
or effect.m_effectId == 0x9C) -- Protection from normal missiles overlay (156)
then
effect.m_dWFlags = effect.m_effectAmount
effect.m_res:set(effect.m_res2:get())
effect.m_res2:set("")
effect.m_effectAmount = 0
end
end
-- Check creature's state
-- since ``EEex_Opcode_AddListsResolvedListener`` is running after the effect lists have been evaluated, ``m_bonusStats`` has already been added to ``m_derivedStats`` by the engine
local spriteGeneralState = sprite.m_derivedStats.m_generalState
--
if sprite:getLocalInt("gtHideVFXIfInvisible") == 1 and EEex_IsBitUnset(spriteGeneralState, 0x4) then
sprite:setLocalInt("gtHideVFXIfInvisible", 0)
-- remove op291
sprite:applyEffect({
["effectID"] = 321, -- Remove effects by resource
["res"] = "GTRMV291",
["sourceID"] = sprite.m_id,
["sourceTarget"] = sprite.m_id,
})
--
EEex_Utility_IterateCPtrList(sprite.m_timedEffectList, restoreVFX)
EEex_Utility_IterateCPtrList(sprite.m_equipedEffectList, restoreVFX)
end
end)

--

EEex_Opcode_AddListsResolvedListener(function(sprite)
-- sanity check
if not EEex_GameObject_IsSprite(sprite) then
return
end
-- internal function that applies the actual condition
local apply = function()
-- Mark the creature as 'condition applied'
sprite:setLocalInt("cdtweaksHideAnimations", 1)
--
sprite:applyEffect({
["effectID"] = 321, -- Remove effects by resource
["res"] = "GTHIDEAN",
["sourceID"] = sprite.m_id,
["sourceTarget"] = sprite.m_id,
})
sprite:applyEffect({
["effectID"] = 403, -- Screen effects
["durationType"] = 9,
["res"] = "GTHIDEAN", -- lua function
["m_sourceRes"] = "GTHIDEAN",
["sourceID"] = sprite.m_id,
["sourceTarget"] = sprite.m_id,
})
end
-- Check creature's EA
local applyCondition = sprite.m_typeAI.m_EnemyAlly > 200 -- EVILCUTOFF
--
if sprite:getLocalInt("cdtweaksHideAnimations") == 0 then
if applyCondition then
apply()
end
else
if applyCondition then
-- do nothing
else
-- Mark the creature as 'condition removed'
sprite:setLocalInt("cdtweaksHideAnimations", 0)
--
sprite:applyEffect({
["effectID"] = 321, -- Remove effects by resource
["res"] = "GTHIDEAN",
["sourceID"] = sprite.m_id,
["sourceTarget"] = sprite.m_id,
})
end
end
end)
4 changes: 4 additions & 0 deletions cdtweaks/readme-cdtweaks.html
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,10 @@ <h3> <a id="contents_cosmetic" name="contents_cosmetic"></a>Cosmetic Changes </h
<li> <em>Moderately decreased brightness:</em> Suitable for brighter GUIs.</li>
<li> <em>Original color:</em> Looks more natural but may be very dark or bright in some instances.</li>
</ul>

<p> <strong>Hide VFX from invisible enemies [Luke]</strong><br />
<em><abbr title="Baldur's Gate: Enhanced Edition">EEex</abbr></em></p>
<p>This component simply makes sure that VFX are hidden from invisible enemies (in so doing, the player will no longer be able to "see" invisible mages just because they previously cast something like Fire Shield or Globe of Invulnerability).</p>
</div>
<div class="ribbon_rectangle_h3">
<h3> <a id="contents_content" name="contents_content"></a>Content Changes </h3>
Expand Down
14 changes: 14 additions & 0 deletions cdtweaks/setup-cdtweaks.tp2
Original file line number Diff line number Diff line change
Expand Up @@ -669,6 +669,20 @@ REQUIRE_PREDICATE GAME_IS ~bgee bg2ee eet iwdee~ @25
REQUIRE_PREDICATE FILE_EXISTS_IN_GAME ~ui.menu~ @25
LABEL ~cd_tweaks_colorize_npc_names_color_original~

/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
///// \\\\\
///// Hide VFX from invisible enemies \\\\\
///// \\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\

BEGIN @26000 DESIGNATED 260
GROUP @11
REQUIRE_PREDICATE GAME_IS ~bgee bg2ee eet iwdee~ @25
REQUIRE_PREDICATE MOD_IS_INSTALLED ~EEex.tp2~ 0 @29
LABEL ~cd_tweaks_hide_vfx_from_invisible_enemies~

/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\/////\\\\\
///// \\\\\
Expand Down