Cleaned up Fire.c a bit

rope
Maikel de Vries 2012-05-01 20:50:21 +02:00
parent 35524e6b64
commit 90ee070f33
1 changed files with 103 additions and 60 deletions

View File

@ -9,46 +9,61 @@
// fire drawing modes
static const C4Fx_FireMode_Default = 0; // determine mode by category
static const C4Fx_FireMode_LivingVeg = 2 ;// C4D_Living and C4D_StaticBack
static const C4Fx_FireMode_StructVeh = 1; // C4D_Structure and C4D_Vehicle
static const C4Fx_FireMode_Object = 3; // other (C4D_Object and no bit set (magic))
static const C4Fx_FireMode_Last = 3; // largest valid fire mode
static const C4Fx_FireMode_Default = 0; // determine mode by category
static const C4Fx_FireMode_LivingVeg = 2; // C4D_Living and C4D_StaticBack
static const C4Fx_FireMode_StructVeh = 1; // C4D_Structure and C4D_Vehicle
static const C4Fx_FireMode_Object = 3; // other (C4D_Object and no bit set (magic))
static const C4Fx_FireMode_Last = 3; // largest valid fire mode
// Returns whether the object is burning.
global func OnFire()
{
if(!this) return false;
if (!this)
return false;
var effect;
if(!(effect=GetEffect("Fire", this))) return false;
if (!(effect=GetEffect("Fire", this)))
return false;
return effect.strength;
}
// Extinguishes the calling object with specified strength.
global func Extinguish(strength)
{
if(!this) return false;
if(strength == nil) strength=100;
else if(!strength) return false;
if (!this)
return false;
if (strength == nil)
strength = 100;
else if (!strength)
return false;
var effect=GetEffect("Fire", this);
if(!effect) return false;
var effect = GetEffect("Fire", this);
if (!effect)
return false;
effect.strength = BoundBy(effect.strength - strength, 0, 100);
if(effect.strength == 0) RemoveEffect(nil, this, effect);
if (effect.strength == 0)
RemoveEffect(nil, this, effect);
return true;
}
// Incinerates the calling object with specified strength.
global func Incinerate(strength, int caused_by, blasted, incinerating_object)
{
if(!this) return false;
if(strength == nil) strength=100;
else if(!strength) return false;
if (!this)
return false;
if (strength == nil)
strength = 100;
else if (!strength)
return false;
var effect=GetEffect("Fire", this);
if(effect) {effect.strength = BoundBy(effect.strength + strength, 0, 100); return true;}
else AddEffect("Fire", this, 100, 2, this, nil, caused_by, !!blasted, incinerating_object, strength);
var effect = GetEffect("Fire", this);
if (effect)
{
effect.strength = BoundBy(effect.strength + strength, 0, 100);
return true;
}
else
AddEffect("Fire", this, 100, 2, this, nil, caused_by, !!blasted, incinerating_object, strength);
return true;
}
@ -83,7 +98,7 @@ global func FxIntNonFlammableEffect(string new_name)
return 0;
}
global func FxFireStart(object target, effect, bool temp, int caused_by, bool blasted, object incinerating_object, strength)
global func FxFireStart(object target, proplist effect, int temp, int caused_by, bool blasted, object incinerating_object, strength)
{
// safety
if (!target) return -1;
@ -101,30 +116,35 @@ global func FxFireStart(object target, effect, bool temp, int caused_by, bool bl
var burn_to = target.BurnTo;
var mat;
if (MaterialName(mat = GetMaterial(target->GetX(), target->GetY())))
if (GetMaterialVal("Extinguisher", "[Material]", mat, 0))
if (GetMaterialVal("Extinguisher", "[Material]", mat))
{
// blasts should changedef in water, too!
if (blasted) if(burn_to != nil) target->ChangeDef(burn_to);
if (blasted)
if (burn_to != nil)
target->ChangeDef(burn_to);
// no fire caused
fire_caused = false;
}
// BurnTurnTo
if (fire_caused) if(burn_to != nil) target->ChangeDef(burn_to);
if (fire_caused)
if (burn_to != nil)
target->ChangeDef(burn_to);
// eject contents
var obj;
if (!target->GetDefCoreVal("IncompleteActivity", "DefCore") && !target.NoBurnDecay)
{
for(var i=target->ContentsCount(); obj=target->Contents(--i);)
for (var i = target->ContentsCount(); obj = target->Contents(--i);)
{
if(target->Contained()) obj->Enter(target->Contained());
else obj->Exit();
}
if (target->Contained())
obj->Enter(target->Contained());
else
obj->Exit();
}
// Detach attached objects
for(obj in FindObjects(Find_ActionTarget(target)))
for (obj in FindObjects(Find_ActionTarget(target)))
{
if(obj->GetProcedure() == "ATTACH")
if (obj->GetProcedure() == "ATTACH")
obj->SetAction(nil);
}
}
@ -132,14 +152,14 @@ global func FxFireStart(object target, effect, bool temp, int caused_by, bool bl
// fire caused?
if (!fire_caused)
{
// if object was blasted but not incinerated (i.e., inside extinguisher)
// do a script callback
if (blasted) target->~IncinerationEx(caused_by);
// if object was blasted but not incinerated (i.e., inside extinguisher), do a script callback
if (blasted)
target->~IncinerationEx(caused_by);
return -1;
}
// determine fire appearance
var fire_mode;
if (!(fire_mode=target->~GetFireMode()))
if (!(fire_mode = target->~GetFireMode()))
{
// set default fire modes
var cat = target->GetCategory();
@ -165,8 +185,10 @@ global func FxFireStart(object target, effect, bool temp, int caused_by, bool bl
// Set values
//target->FirePhase=Random(MaxFirePhase);
if((target->GetDefCoreVal("Width", "DefCore") * target->GetDefCoreVal("Height", "DefCore")) > 500) target->Sound("Inflame", false, 100);
if(target->GetMass() >= 100) target->Sound("Fire", false, 100, 0, true);
if ((target->GetDefCoreVal("Width", "DefCore") * target->GetDefCoreVal("Height", "DefCore")) > 500)
target->Sound("Inflame", false, 100);
if (target->GetMass() >= 100)
target->Sound("Fire", false, 100, 0, true);
// callback
target->~Incineration(effect.caused_by);
@ -186,24 +208,30 @@ global func FxFireTimer(object target, effect, int time)
// strength changes over time
if(time % 4 == 0)
{
if(effect.strength < 50){ if(time % 8 == 0) effect.strength=Max(effect.strength-1, 0); if(effect.strength <= 0) return FX_Execute_Kill;}
else effect.strength=Min(effect.strength+1, 100);
if (effect.strength < 50)
{
if (time % 8 == 0)
effect.strength = Max(effect.strength - 1, 0);
if (effect.strength <= 0)
return FX_Execute_Kill;
}
else
effect.strength = Min(effect.strength + 1, 100);
}
var width=target->GetDefCoreVal("Width", "DefCore")/2;
var height=target->GetDefCoreVal("Height", "DefCore")/2;
var width = target->GetDefCoreVal("Width", "DefCore") / 2;
var height = target->GetDefCoreVal("Height", "DefCore") / 2;
// target is in liquid?
if(time % 24 == 0)
{
if (time % 24 == 0)
{
var mat;
if(mat = GetMaterial())
if(GetMaterialVal("Extinguisher", "Material", mat))
if (mat = GetMaterial())
if (GetMaterialVal("Extinguisher", "Material", mat))
return FX_Execute_Kill;
// check spreading of fire
if(effect.strength > 10)
if (effect.strength > 10)
{
// If contained only incinerate objects inside the same container and the container itself.
var container = target->Contained(), inc_objs;
@ -220,13 +248,17 @@ global func FxFireTimer(object target, effect, int time)
// Loop through the selected set of objects and check contact incinerate.
for (var obj in inc_objs)
{
if(obj->GetCategory() & C4D_Living) if(!obj->GetAlive()) continue;
if (obj->GetCategory() & C4D_Living)
if (!obj->GetAlive())
continue;
var inf = obj.ContactIncinerate;
if(!inf) continue;
var amount = (effect.strength/3) / Max(1, inf);
if (!inf)
continue;
var amount = (effect.strength / 3) / Max(1, inf);
if(!amount) continue;
if (!amount)
continue;
obj->Incinerate(Max(10, amount), effect.caused_by, false, effect.incinerating_obj);
}
}
@ -235,23 +267,26 @@ global func FxFireTimer(object target, effect, int time)
//if(time % 20 == 0)target->Message(Format("<c ee0000>%d</c>", effect.strength));
// causes on object
//target->ExecFire(effect_number, caused_by);
if(target->GetAlive())
if (target->GetAlive())
{
target->DoEnergy(-effect.strength*4, true, FX_Call_EngFire, effect.caused_by);
}
else
{
if((time*10) % 100 <= effect.strength)
if ((time*10) % 100 <= effect.strength)
{
target->DoDamage(2, true, FX_Call_DmgFire, effect.caused_by);
if(target) if(!Random(2)) if(!effect.no_burn_decay) target->DoCon(-1);
if (target && !Random(2) && !effect.no_burn_decay)
target->DoCon(-1);
}
}
if(!target) return FX_Execute_Kill;
if (!target)
return FX_Execute_Kill;
//if(!(time % 2 == 0)) return FX_OK;
//if(!target->OnFire()) {return FX_Execute_Kill;}
if(target->Contained()) return FX_OK;
if (target->Contained())
return FX_OK;
// particles
//var smoke;//, sparks, bright;
@ -261,10 +296,16 @@ global func FxFireTimer(object target, effect, int time)
if(time % 4 == 0)
{
var size = BoundBy(10*Max(width, height), 50, 800);
if(size > 300) if(time % 8 == 0) return;
if (size > 300)
if (time % 8 == 0)
return;
var wind=BoundBy(GetWind(target->GetX(), target->GetY()), -5, 5);
var smoke_color; if(effect.strength < 50) smoke_color=RGBa(255,255,255, 50); else smoke_color=RGBa(100, 100, 100, 50);
var wind = BoundBy(GetWind(target->GetX(), target->GetY()), -5, 5);
var smoke_color;
if(effect.strength < 50)
smoke_color = RGBa(255,255,255, 50);
else
smoke_color = RGBa(100, 100, 100, 50);
CreateParticle("ExploSmoke", RandomX(-width, width), RandomX(-height, height), wind, -effect.strength/8, size, smoke_color);
}
@ -285,14 +326,16 @@ global func FxFireTimer(object target, effect, int time)
global func FxFireStop(object target, int effect_number, int reason, bool temp)
{
// safety
if (!target) return false;
if (!target)
return false;
// only if real removal is done
if (temp)
{
return true;
}
// stop sound
if (target->GetMass() >=100) target->Sound("Fire", false, 1, 0, false);
if (target->GetMass() >= 100)
target->Sound("Fire", false, 1, 0, false);
// done, success
return true;
}