From 85a3cd984d2a6cc1b793a44a17551a3e934092cc Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Wed, 10 Feb 2016 17:06:33 +0100 Subject: [PATCH] - fixed: ParseParameter should not make any assumptions about the necessity of a type cast between int and float. With late resolving it cannot be guaranteed at this point and caused some incorrectly compiled code. Since the cast gets optimized away anyway when not needed there's no point being this selective with applying it. --- src/p_interaction.cpp | 76 ++++++++++++++++----------------- src/thingdef/thingdef_parse.cpp | 10 +---- 2 files changed, 40 insertions(+), 46 deletions(-) diff --git a/src/p_interaction.cpp b/src/p_interaction.cpp index eb3c6d354..dba66ca9b 100644 --- a/src/p_interaction.cpp +++ b/src/p_interaction.cpp @@ -1043,58 +1043,58 @@ int P_DamageMobj (AActor *target, AActor *inflictor, AActor *source, int damage, if ((rawdamage < TELEFRAG_DAMAGE) || (target->flags7 & MF7_LAXTELEFRAGDMG)) // TELEFRAG_DAMAGE may only be reduced with LAXTELEFRAGDMG or it may not guarantee its effect. { if (player && damage > 1) - { - // Take half damage in trainer mode - damage = FixedMul(damage, G_SkillProperty(SKILLP_DamageFactor)); - } - // Special damage types - if (inflictor) - { - if (inflictor->flags4 & MF4_SPECTRAL) { - if (player != NULL) - { - if (!deathmatch && inflictor->FriendPlayer > 0) - return -1; - } - else if (target->flags4 & MF4_SPECTRAL) - { - if (inflictor->FriendPlayer == 0 && !target->IsHostile(inflictor)) - return -1; - } + // Take half damage in trainer mode + damage = FixedMul(damage, G_SkillProperty(SKILLP_DamageFactor)); } + // Special damage types + if (inflictor) + { + if (inflictor->flags4 & MF4_SPECTRAL) + { + if (player != NULL) + { + if (!deathmatch && inflictor->FriendPlayer > 0) + return -1; + } + else if (target->flags4 & MF4_SPECTRAL) + { + if (inflictor->FriendPlayer == 0 && !target->IsHostile(inflictor)) + return -1; + } + } damage = inflictor->DoSpecialDamage(target, damage, mod); if (damage < 0) - { - return -1; + { + return -1; + } } - } int olddam = damage; if (damage > 0 && source != NULL) { - damage = FixedMul(damage, source->DamageMultiply); + damage = FixedMul(damage, source->DamageMultiply); // Handle active damage modifiers (e.g. PowerDamage) if (damage > 0 && source->Inventory != NULL) { source->Inventory->ModifyDamage(damage, mod, damage, false); + } } - } - // Handle passive damage modifiers (e.g. PowerProtection), provided they are not afflicted with protection penetrating powers. + // Handle passive damage modifiers (e.g. PowerProtection), provided they are not afflicted with protection penetrating powers. if (damage > 0 && (target->Inventory != NULL) && !(flags & DMG_NO_PROTECT)) - { + { target->Inventory->ModifyDamage(damage, mod, damage, true); } if (damage > 0 && !(flags & DMG_NO_FACTOR)) - { - damage = FixedMul(damage, target->DamageFactor); - if (damage > 0) { - damage = DamageTypeDefinition::ApplyMobjDamageFactor(damage, mod, target->GetClass()->DamageFactors); - } + damage = FixedMul(damage, target->DamageFactor); + if (damage > 0) + { + damage = DamageTypeDefinition::ApplyMobjDamageFactor(damage, mod, target->GetClass()->DamageFactors); + } } if (damage >= 0) @@ -1105,23 +1105,23 @@ int P_DamageMobj (AActor *target, AActor *inflictor, AActor *source, int damage, // '<0' is handled below. This only handles the case where damage gets reduced to 0. if (damage == 0 && olddam > 0) { - { // Still allow FORCEPAIN - if (forcedPain) + { // Still allow FORCEPAIN + if (forcedPain) { - goto dopain; + goto dopain; } - else if (fakedPain) + else if (fakedPain) { - goto fakepain; + goto fakepain; } - return -1; + return -1; + } } } - } if (target->flags5 & MF5_NODAMAGE) { damage = 0; - } + } } if (damage < 0) { diff --git a/src/thingdef/thingdef_parse.cpp b/src/thingdef/thingdef_parse.cpp index cf76fb10b..2cd271ad5 100644 --- a/src/thingdef/thingdef_parse.cpp +++ b/src/thingdef/thingdef_parse.cpp @@ -88,17 +88,11 @@ FxExpression *ParseParameter(FScanner &sc, PClassActor *cls, PType *type, bool c // Do automatic coercion between ints and floats. if (type == TypeSInt32) { - if (x->ValueType != VAL_Int) - { - x = new FxIntCast(x); - } + x = new FxIntCast(x); } else { - if (x->ValueType != VAL_Float) - { - x = new FxFloatCast(x); - } + x = new FxFloatCast(x); } } else if (type == TypeName || type == TypeString)