8 private SoundOnVehicle m_LoopSoundEntity;
10 bool m_CanReceiveUpgrade;
11 bool m_IsBeingDestructed =
false;
13 float m_BurnTimePerRagEx;
14 float m_BurnTimePerFullLardEx;
15 float m_BurnTimePerFullFuelDoseEx;
16 float m_MaxConsumableLardQuantityEx;
17 float m_MaxConsumableFuelQuantityEx;
18 float m_WaterEvaporationByFireIntensityEx = 0.001;
19 int m_StartFadeOutOfLightAtQuantityEx = 3;
21 int m_RagsUpgradedCount;
22 bool m_ConsumeRagFlipFlop;
25 string m_DecraftResult =
"WoodenStick";
31 protected ref UniversalTemperatureSourceLambdaConstant m_UTSLConstant;
33 override void DeferredInit()
35 if(m_RagsUpgradedCount)
43 if ( m_BurnTimePerRagEx == 0 || m_BurnTimePerFullLardEx == 0 || m_MaxConsumableLardQuantityEx == 0 || m_MaxConsumableFuelQuantityEx == 0 )
45 string cfg_path =
"CfgVehicles " +
GetType();
46 m_BurnTimePerRagEx =
GetGame().ConfigGetFloat( cfg_path +
" burnTimePerRag" );
47 m_BurnTimePerFullLardEx =
GetGame().ConfigGetFloat( cfg_path +
" burnTimePerFullLardDose" );
48 m_BurnTimePerFullFuelDoseEx =
GetGame().ConfigGetFloat( cfg_path +
" burnTimePerFullFuelDose" );
49 m_MaxConsumableLardQuantityEx =
GetGame().ConfigGetFloat( cfg_path +
" maxConsumableLardDose" );
50 m_MaxConsumableFuelQuantityEx =
GetGame().ConfigGetFloat( cfg_path +
" maxConsumableFuelDose" );
52 RegisterNetSyncVariableBool(
"m_CanReceiveUpgrade");
55 override void EEInit()
70 m_UTSLConstant =
new UniversalTemperatureSourceLambdaConstant();
76 override vector GetUniversalTemperatureSourcePosition()
78 if (GetHierarchyRoot())
80 return GetHierarchyRoot().GetPosition();
83 return super.GetPosition();
86 override void EEDelete(
EntityAI parent)
88 super.EEDelete(parent);
89 if ( m_LoopSoundEntity != NULL &&
GetGame() != NULL )
91 GetGame().ObjectDelete( m_LoopSoundEntity );
97 override bool CanReceiveAttachment(
EntityAI attachment,
int slotId)
100 if (att && att.IsFullQuantity())
103 return super.CanReceiveAttachment(attachment, slotId);
106 override bool CanPutInCargo(
EntityAI parent )
108 if( !super.CanPutInCargo(parent) ) {
return false;}
109 return CanBeTakenAsCargo();
112 override bool CanReleaseAttachment(
EntityAI attachment)
114 if( !super.CanReleaseAttachment( attachment ) )
116 return !GetCompEM().IsWorking();
119 override bool CanRemoveFromCargo(
EntityAI parent)
121 return CanBeTakenAsCargo();
124 override bool CanPutAsAttachment (
EntityAI parent)
126 return !GetCompEM().IsWorking();
129 bool CanBeTakenAsCargo()
132 return !GetCompEM().IsWorking();
135 override bool IsIgnited()
137 return GetCompEM().IsWorking();
140 override bool CanIgniteItem(
EntityAI ignite_target = NULL)
142 return GetCompEM().IsWorking();
145 override bool HasFlammableMaterial()
151 override bool CanBeIgnitedBy(
EntityAI igniter = NULL)
153 if ( !GetCompEM().CheckWetness() )
158 if (rag && GetCompEM().
GetEnergy() < GetCompEM().GetEnergyUsage() * GetCompEM().GetUpdateInterval() )
160 if (IsRagDryEnough(rag))
164 if ( !GetCompEM().CanWork() )
173 if (
this != player.GetItemInHands())
184 float wetness = rag.GetWet();
185 bool is_dry_enough = wetness <= 1-GetCompEM().GetWetnessExposure();
186 return is_dry_enough;
189 void UpdateCheckForReceivingUpgrade()
193 m_CanReceiveUpgrade = GetRagQuantity() > 0 && m_RagsUpgradedCount < GetRagQuantity() || (m_BurnTimePerRagEx * (m_RagsUpgradedCount + GetRagQuantity()) - GetCompEM().GetEnergy()) > 1;
198 override void OnIgnitedThis(
EntityAI fire_source)
200 if ( !GetCompEM().HasEnoughStoredEnergy() )
205 GetCompEM().SwitchOn();
208 override void OnSwitchOn()
210 if (!GetCompEM().HasEnoughStoredEnergy())
212 GetCompEM().SwitchOff();
221 override void OnSwitchOff()
229 void SetTorchDecraftResult(
string type)
231 m_DecraftResult = type;
240 if (rag.GetQuantity() <= 1)
254 void ConsumeLard(Lard lard)
258 float lard_quant = lard.GetQuantity();
260 float available_lard_quant = lard_quant;
262 if ( available_lard_quant > m_MaxConsumableLardQuantityEx )
263 available_lard_quant = m_MaxConsumableLardQuantityEx;
265 float available_lard_coef = available_lard_quant / m_MaxConsumableLardQuantityEx;
267 float add_energy = m_BurnTimePerFullLardEx * available_lard_coef;
268 float add_energy_coef = 1;
270 float energy_limit = GetCompEM().GetEnergyMax() - GetCompEM().GetEnergy();
272 if (add_energy > energy_limit )
274 add_energy_coef = energy_limit / add_energy;
275 add_energy = energy_limit;
276 available_lard_quant = available_lard_quant * add_energy_coef;
279 GetCompEM().AddEnergy( add_energy );
280 lard.AddQuantity(-available_lard_quant);
284 UpdateCheckForReceivingUpgrade();
296 float torchCurrentEnergy = GetCompEM().GetEnergy();
297 float sourceQuantity = 100000;
301 sourceQuantity = source.GetQuantity();
304 float maxOverallCapacity = GetRagQuantity() * 2 * m_BurnTimePerRagEx;
306 float currentlyUpgraded =
Math.Max(0, torchCurrentEnergy - (GetRagQuantity() * m_BurnTimePerRagEx));
308 float freeUpgradeCapacity = maxOverallCapacity - torchCurrentEnergy;
309 float upgradeQuantity =
Math.Min(freeUpgradeCapacity, sourceQuantity);
310 int upgradedRags =
Math.Ceil((upgradeQuantity + currentlyUpgraded) / m_BurnTimePerRagEx);
311 upgradedRags =
Math.Min(GetRagQuantity(), upgradedRags);
312 m_RagsUpgradedCount = upgradedRags;
313 GetCompEM().AddEnergy(upgradeQuantity);
314 m_ConsumeRagFlipFlop = 0;
317 source.AddQuantity(-upgradeQuantity);
320 UpdateCheckForReceivingUpgrade();
325 void ConsumeFuelFromBottle(
ItemBase vessel)
329 float vessel_quant = vessel.GetQuantity();
331 float available_vessel_quant = vessel_quant;
333 if ( available_vessel_quant > m_MaxConsumableFuelQuantityEx )
334 available_vessel_quant = m_MaxConsumableFuelQuantityEx;
336 float available_vessel_coef = available_vessel_quant / m_MaxConsumableFuelQuantityEx;
338 float add_energy = m_BurnTimePerFullFuelDoseEx * available_vessel_coef;
339 float add_energy_coef = 1;
341 float energy_limit = GetCompEM().GetEnergyMax() - GetCompEM().GetEnergy();
343 if (add_energy > energy_limit )
345 add_energy_coef = energy_limit / add_energy;
346 add_energy = energy_limit;
347 available_vessel_quant = available_vessel_quant * add_energy_coef;
350 GetCompEM().AddEnergy( add_energy );
351 vessel.AddQuantity(-available_vessel_quant);
355 UpdateCheckForReceivingUpgrade();
359 void ConsumeFuelFromGasStation()
361 float add_energy = m_BurnTimePerFullFuelDoseEx;
362 float add_energy_coef = 1;
364 float energy_limit = GetCompEM().GetEnergyMax() - GetCompEM().GetEnergy();
366 if (add_energy > energy_limit )
368 add_energy_coef = energy_limit / add_energy;
369 add_energy = energy_limit;
372 GetCompEM().AddEnergy( add_energy );
374 UpdateCheckForReceivingUpgrade();
388 override void OnInventoryExit(Man player)
390 super.OnInventoryExit(player);
400 GetGame().SurfaceGetType ( position[0], position[2], surface_type );
401 bool is_surface_soft =
GetGame().IsSurfaceDigable(surface_type);
403 if ( is_surface_soft && !IsRuined() )
405 vector ori_rotate =
"0 0 0";
406 ori_rotate[0] =
Math.RandomFloat(0, 360);
407 ori_rotate[1] =
Math.RandomFloat(0, 10);
408 SetOrientation(ori_rotate);
416 void CalculateQuantity()
424 bool CanReceiveUpgrade()
426 return m_CanReceiveUpgrade;
429 void CraftingInit(
float quantity)
431 GetCompEM().SetEnergy(m_BurnTimePerRagEx * quantity);
432 m_CanReceiveUpgrade =
true;
437 override void EEItemAttached(
EntityAI item,
string slot_name )
439 super.EEItemAttached( item, slot_name );
441 UpdateCheckForReceivingUpgrade();
445 override void EEItemDetached(
EntityAI item,
string slot_name )
447 super.EEItemDetached( item, slot_name );
449 if (m_IsBeingDestructed)
455 MiscGameplayFunctions.TransferItemProperties(item, rags);
461 UpdateCheckForReceivingUpgrade();
465 bool CanTransformIntoStick()
467 if ((
GetGame().IsServer() || !
GetGame().IsMultiplayer()) && !IsIgnited() && !GetRag() && !IsSetForDeletion() )
473 void TryTransformIntoStick()
476 if ( m_IsBeingDestructed || (player && player.IsPlayerDisconnected()) )
479 if ( CanTransformIntoStick() )
481 m_IsBeingDestructed =
true;
488 player.ServerReplaceItemInHandsWithNew(lambda);
496 if (
GetType() ==
"WoodenStick" )
497 ori = ori +
Vector(0,90,0);
500 ApplyResultModifications(stick);
501 stick.SetPosition(pos);
502 stick.PlaceOnSurface();
504 if ( stick.GetType() ==
"LongWoodenStick" )
506 pos = stick.GetPosition() +
Vector(0,-0.3,0);
507 stick.SetPosition(pos);
510 stick.SetOrientation(ori);
517 override void OnWorkStart()
524 void StopAllParticles()
528 m_FireParticle.Stop();
534 return Rag.Cast( GetAttachmentByType(Rag) );
537 void LockRags(
bool do_lock)
546 else if (!m_RagsUpgradedCount)
548 rag.UnlockFromParent();
558 m_Light.AttachOnObject(
this, m_ParticleLocalPos +
Vector (0,0.2,0));
563 Object direct_particle = m_FireParticle.GetDirectParticleEffect();
565 if (direct_particle && direct_particle !=
m_Light.GetAttachmentParent())
571 float update_interval = GetCompEM().GetUpdateInterval();
573 if (
GetQuantity() <= m_StartFadeOutOfLightAtQuantityEx)
575 float brightness_coef =
GetQuantity() / m_StartFadeOutOfLightAtQuantityEx;
576 float radius_coef =
GetQuantity() / m_StartFadeOutOfLightAtQuantityEx;
578 if (radius_coef < m_StartFadeOutOfLightAtQuantityEx/10)
579 radius_coef = m_StartFadeOutOfLightAtQuantityEx/10;
581 if (brightness_coef < m_StartFadeOutOfLightAtQuantityEx/10)
582 brightness_coef = m_StartFadeOutOfLightAtQuantityEx/10;
584 m_Light.FadeBrightnessTo(
m_Light.m_TorchBrightness * brightness_coef, update_interval);
585 m_Light.FadeRadiusTo(
m_Light.m_TorchRadius * radius_coef, update_interval);
589 m_Light.FadeBrightnessTo(
m_Light.m_TorchBrightness, update_interval);
594 override void OnItemInHandsPlayerSwimStart(
PlayerBase player)
596 GetCompEM().SwitchOff();
600 override void OnWork(
float consumed_energy )
605 if (GetCompEM().
GetEnergy() < ((GetRagQuantity() + m_RagsUpgradedCount) - 1) * m_BurnTimePerRagEx)
607 if (m_RagsUpgradedCount==0)
611 else if (m_ConsumeRagFlipFlop)
614 m_ConsumeRagFlipFlop = !m_ConsumeRagFlipFlop;
618 m_RagsUpgradedCount--;
619 m_ConsumeRagFlipFlop = !m_ConsumeRagFlipFlop;
622 if (GetRag() && GetCompEM().
GetEnergy() == 0 && GetRagQuantity() > 0)
624 GetRag().SetQuantity(0);
630 UpdateCheckForReceivingUpgrade();
632 AddWet( -m_WaterEvaporationByFireIntensityEx * GetCompEM().GetUpdateInterval() );
638 rag.AddWet( -m_WaterEvaporationByFireIntensityEx * GetCompEM().GetUpdateInterval() );
642 if ( !m_LoopSoundEntity &&
GetGame() && ( !
GetGame().IsDedicatedServer() ) )
644 m_LoopSoundEntity = PlaySoundLoop(GetSoundName(), 50);
648 if ( !
GetGame().IsDedicatedServer() )
656 string GetSoundName()
661 void UpdateParticle()
676 m_FireParticle.ScaleParticleParamFromOriginal(
EmitorParam.SIZE, scale);
677 m_FireParticle.ScaleParticleParamFromOriginal(
EmitorParam.VELOCITY, scale);
678 m_FireParticle.ScaleParticleParamFromOriginal(
EmitorParam.VELOCITY_RND, scale);
682 if ( !m_FireParticle || m_FireParticle.GetParticleID() !=
ParticleList.TORCH_T2 )
687 m_FireParticle.Stop();
695 override void OnWorkStop()
701 if ( m_LoopSoundEntity &&
GetGame() && ( !
GetGame().IsDedicatedServer() ) )
703 GetGame().ObjectDelete( m_LoopSoundEntity );
704 m_LoopSoundEntity = NULL;
709 m_FireParticle.Stop();
710 m_FireParticle = NULL;
714 UpdateCheckForReceivingUpgrade();
720 if (GetRag() && GetCompEM().
GetEnergy() == 0 && GetRagQuantity() > 0)
722 GetRag().SetQuantity(0);
726 TryTransformIntoStick();
731 override int GetMeleeMode()
733 if ( GetCompEM().IsWorking() )
739 override int GetMeleeHeavyMode()
741 if ( GetCompEM().IsWorking() )
747 override int GetMeleeSprintMode()
749 if ( GetCompEM().IsWorking() )
755 override void SetActions()
762 override void OnAttachmentQuantityChangedEx(
ItemBase item,
float delta)
764 super.OnAttachmentQuantityChangedEx(item, delta);
767 GetCompEM().AddEnergy(m_BurnTimePerRagEx * delta);
769 UpdateCheckForReceivingUpgrade();
774 override bool DisassembleOnLastDetach()
779 override void OnDebugSpawn()
781 GetInventory().CreateAttachment(
"Rag");
782 CraftingInit(GetRagQuantity());
795 string GetBurningMaterial()
800 string GetBurntMaterial()
805 void UpdateMaterial()
809 if (GetCompEM().IsWorking())
811 if (GetBurningMaterial())
813 SetObjectMaterial(0, GetBurningMaterial());
818 if (GetBurntMaterial())
820 SetObjectMaterial(0, GetBurntMaterial());
829 super.OnStoreSave(ctx);
836 if (!super.OnStoreLoad(ctx, version))
842 if (!ctx.Read( m_WasLit ))
851 void ApplyResultModifications(
ItemBase result)
853 result.SetQuantity(1);
860 override void GetDebugActions(out TSelectableActionInfoArrayEx outputList)
865 super.GetDebugActions(outputList);
870 if (super.OnAction(action_id, player, ctx))
874 if (action_id ==
EActions.ACTIVATE_ENTITY)
887 debug_output = super.GetDebugText();
889 if(
GetGame().IsDedicatedServer())
891 debug_output+=
"m_RagsUpgradedCount:"+m_RagsUpgradedCount+
"\n";
892 debug_output+=
"m_ConsumeRagFlipFlop:"+m_ConsumeRagFlipFlop+
"\n";
893 if (IsIgnited() && m_ConsumeRagFlipFlop)
895 debug_output+=
"Burning rag \n";
897 else if (IsIgnited())
899 debug_output+=
"Burning lard/fuel \n";
916 static float m_BurnTimePerFullLard;
917 static float m_BurnTimePerFullFuelDose;
918 static float m_MaxConsumableLardQuantity;
919 static float m_MaxConsumableFuelQuantity;
920 static float m_WaterEvaporationByFireIntensity = 0.001;
921 static int m_StartFadeOutOfLightAtQuantity = 3;
930 m_BurnTimePerFullLard = m_BurnTimePerFullLardEx;
931 m_BurnTimePerFullFuelDose = m_BurnTimePerFullFuelDoseEx;
932 m_MaxConsumableLardQuantity = m_MaxConsumableLardQuantityEx;
933 m_MaxConsumableFuelQuantity = m_MaxConsumableFuelQuantityEx;
947 super.OnWasAttached(parent, slot_id);
955 super.OnWasDetached(parent, slot_id);
963 super.OnStoreSave(ctx);
964 ctx.Write(m_ConsumeRagFlipFlop);
965 ctx.Write(m_RagsUpgradedCount);
971 if (!super.OnStoreLoad(ctx, version))
978 if (!ctx.Read( m_ConsumeRagFlipFlop ))
983 if (!ctx.Read( m_RagsUpgradedCount ))
988 UpdateCheckForReceivingUpgrade();
995 override void CopyOldPropertiesToNew (notnull
EntityAI old_item,
EntityAI new_item)
997 super.CopyOldPropertiesToNew(old_item, new_item);
1001 Class.CastTo(stick, new_item);
1002 if (stick && flammable)
1004 flammable.ApplyResultModifications(stick);