forked from Mirrors/openclonk
make friendly fire rule also work for lightning strikes and punches
parent
65c279233e
commit
73dbc72f34
|
@ -98,16 +98,8 @@ protected func FxLightningMoveTimer(object target, effect fx, int time)
|
||||||
if (obj && !obj->~RejectLightningStrike(this, damage))
|
if (obj && !obj->~RejectLightningStrike(this, damage))
|
||||||
{
|
{
|
||||||
var is_attractor = obj.IsLightningAttractor;
|
var is_attractor = obj.IsLightningAttractor;
|
||||||
// Do a callback notifying the object that it has been struck by lightning.
|
// Perform the strike on the object.
|
||||||
obj->~OnLightningStrike(this, damage);
|
PerformLightningStrike(obj, damage);
|
||||||
// Damage or hurt objects. Lightning strikes may have a controller, thus pass this for kill tracing.
|
|
||||||
if (obj)
|
|
||||||
{
|
|
||||||
if (obj->GetOCF() & OCF_Alive)
|
|
||||||
Punch(obj, damage);
|
|
||||||
else
|
|
||||||
obj->DoDamage(damage, FX_Call_DmgScript, GetController());
|
|
||||||
}
|
|
||||||
// Reduce strength of the lightning if an object is struck.
|
// Reduce strength of the lightning if an object is struck.
|
||||||
strength -= damage;
|
strength -= damage;
|
||||||
// Remove lightning if too weak or an attractor has been struck.
|
// Remove lightning if too weak or an attractor has been struck.
|
||||||
|
@ -173,6 +165,21 @@ private func DrawLightningLine(int x1, int y1, int x2, int y2, int distance, int
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private func PerformLightningStrike(object target, int damage)
|
||||||
|
{
|
||||||
|
// Do a callback notifying the object that it has been struck by lightning.
|
||||||
|
target->~OnLightningStrike(this, damage);
|
||||||
|
// Damage or hurt objects. Lightning strikes may have a controller, thus pass this for kill tracing.
|
||||||
|
if (target)
|
||||||
|
{
|
||||||
|
if (target->GetOCF() & OCF_Alive)
|
||||||
|
Punch(target, damage);
|
||||||
|
else
|
||||||
|
target->DoDamage(damage, FX_Call_DmgScript, GetController());
|
||||||
|
}
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
// Don't save in scenarios.
|
// Don't save in scenarios.
|
||||||
func SaveScenarioObject() { return false; }
|
func SaveScenarioObject() { return false; }
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,13 @@
|
||||||
|
// Disable friendly fire for lightning strikes if rule is active.
|
||||||
|
|
||||||
|
#appendto Lightning
|
||||||
|
|
||||||
|
private func PerformLightningStrike(object target, int damage)
|
||||||
|
{
|
||||||
|
var w_controller = this->GetController();
|
||||||
|
var t_controller = target->GetController();
|
||||||
|
if (FindObject(Find_ID(Rule_NoFriendlyFire)))
|
||||||
|
if (w_controller != NO_OWNER && t_controller != NO_OWNER && !Hostile(w_controller, t_controller))
|
||||||
|
return;
|
||||||
|
return _inherited(target, damage, ...);
|
||||||
|
}
|
|
@ -0,0 +1,15 @@
|
||||||
|
// Disable friendly fire for damage done through the Punch function.
|
||||||
|
// This needs be done by overloading because the callback QueryCatchBlow
|
||||||
|
// only halves the damage and prevents the tumbling.
|
||||||
|
|
||||||
|
global func Punch(object obj, int strength)
|
||||||
|
{
|
||||||
|
var w_controller = NO_OWNER;
|
||||||
|
if (this)
|
||||||
|
w_controller = this->GetController();
|
||||||
|
var t_controller = obj->GetController();
|
||||||
|
if (FindObject(Find_ID(Rule_NoFriendlyFire)))
|
||||||
|
if (w_controller != NO_OWNER && t_controller != NO_OWNER && !Hostile(w_controller, t_controller))
|
||||||
|
return false;
|
||||||
|
return _inherited(obj, strength, ...);
|
||||||
|
}
|
|
@ -1,6 +1,6 @@
|
||||||
/**
|
/**
|
||||||
No Friendly Fire Rule
|
No Friendly Fire Rule
|
||||||
If this rule is activate non-hostile crew members can't hit each other.
|
If this rule is active non-hostile crew members can't hit each other.
|
||||||
Some of the implementation is in appendto scripts.
|
Some of the implementation is in appendto scripts.
|
||||||
|
|
||||||
@author Maikel
|
@author Maikel
|
||||||
|
|
Loading…
Reference in New Issue