3 string m_DefaultMaterial;
6 ChemlightLight m_Light;
8 private int m_Efficiency0To10;
9 static private float m_EfficiencyDecayStart = 0.05;
12 float GetEfficiency0To1()
14 return m_Efficiency0To10 / 10;
18 float GetEfficiencyDecayStart()
20 return m_EfficiencyDecayStart;
23 override void OnEnergyConsumed()
25 super.OnEnergyConsumed();
29 float energy_coef = GetCompEM().GetEnergy0To1();
31 if ( energy_coef < m_EfficiencyDecayStart && m_EfficiencyDecayStart > 0 )
33 m_Efficiency0To10 =
Math.Round( (energy_coef / m_EfficiencyDecayStart) * 10 );
39 override void EEHealthLevelChanged(
int oldLevel,
int newLevel,
string zone)
41 super.EEHealthLevelChanged(oldLevel,newLevel,zone);
43 SetObjectMaterial( 0, GetMaterialForDamageState(GetCompEM().IsWorking(),newLevel) );
49 array<string> config_materials = GetHiddenSelectionsMaterials();
51 if (config_materials.Count() == 2)
53 m_DefaultMaterial = config_materials[0];
54 m_GlowMaterial = config_materials[1];
58 string error =
"Error! Item " +
GetType() +
" must have 2 entries in config array hiddenSelectionsMaterials[]. One for the default state, the other one for the glowing state. Currently it has " + config_materials.Count() +
".";
62 m_Efficiency0To10 = 10;
63 RegisterNetSyncVariableInt(
"m_Efficiency0To10");
68 SetObjectMaterial( 0, GetMaterialForDamageState(
true) );
73 m_Light.AttachOnMemoryPoint(
this,
"light");
79 case "Chemlight_White":
85 case "Chemlight_Green":
88 case "Chemlight_Blue":
91 case "Chemlight_Yellow":
95 default: {
m_Light.SetColorToWhite(); };
100 override void OnWorkStart()
106 override void OnInventoryExit(Man player)
108 super.OnInventoryExit(player);
115 if (
GetGame().IsServer() && GetCompEM().IsWorking() )
117 vector ori_rotate =
"0 0 0";
118 SetOrientation(ori_rotate);
122 override void OnWorkStop()
124 SetObjectMaterial( 0, GetMaterialForDamageState(
false) );
141 override void OnWork (
float consumed_energy)
149 float efficiency = GetEfficiency0To1();
151 if ( efficiency < 1 )
153 m_Light.SetIntensity( efficiency, GetCompEM().GetUpdateInterval() );
158 override void SetActions()
165 string GetMaterialForDamageState(
bool glowing,
int healthLevel = -1)
167 int currentHealthLevel;
171 if (healthLevel == -1)
172 currentHealthLevel = GetHealthLevel();
174 currentHealthLevel = healthLevel;
177 base = m_GlowMaterial;
179 base = m_DefaultMaterial;
181 suffixIndex = base.IndexOf(
".rvmat");
182 if (suffixIndex == -1)
184 Error(
"Error - no valid rvmat found for chemlight");
187 base = base.Substring(0,suffixIndex);
191 base = base +
"_damage";
195 base = base +
"_destruct";
198 return base +
".rvmat";