13 float m_LifetimeEnd = -1;
14 float m_FadeOutTime = -1;
15 float m_FadeInTime = -1;
24 float m_BrightnessSpeedOfChange = 1;
25 float m_RadiusSpeedOfChange = 1;
26 float m_OptimizeShadowsRadius = 0;
33 bool m_IsDebugEnabled =
false;
42 static ref set<ScriptedLightBase> m_NightTimeOnlyLights =
new set<ScriptedLightBase>();
55 if (m_NightTimeOnlyLights)
57 int index = m_NightTimeOnlyLights.Find(
this);
60 m_NightTimeOnlyLights.Remove(index);
67 if (!IsVisibleDuringDaylight())
70 if (player && player.m_UndergroundPresence)
71 SetVisibleDuringDaylight(
true);
72 m_NightTimeOnlyLights.Insert(
this);
87 item.GetInventory().GetCurrentInventoryLocation( il );
97 UpdateLightMode(slotName);
113 m_DeleteTimer.Run( 0.03 ,
this,
"DeleteLightNow", NULL,
true);
147 SetOrientation(local_ori);
149 parent.AddChild(
this, -1);
162 if (parent.MemoryPointExists(memory_point_start))
164 m_LocalPos = parent.GetMemoryPointPos(memory_point_start);
167 if (memory_point_target !=
"" )
169 if (parent.MemoryPointExists(memory_point_target))
171 vector target_pos = parent.GetSelectionPositionLS(memory_point_target);
177 ErrorEx(
"memory point 'memory_point_target' not found when attaching light");
180 AttachOnObject(parent,
m_LocalPos, local_ori);
185 ErrorEx(
"memory point 'memory_point_start' not found when attaching light");
199 if ( !
m_Parent.ToDelete() && !ToDelete() )
213 if (target.MemoryPointExists(memory_point_start))
216 light.AttachOnMemoryPoint(target, memory_point_start, memory_point_target);
232 Error(
"Error! Light entity of name " +
name.
ToString() +
" cannot be spawned! This name is incorrect or not inherited from ScriptedLightBase." );
236 if (fade_in_time_in_s != 0)
238 light_instance.FadeIn(fade_in_time_in_s);
245 Error(
"An instance of ScriptedLightBase was attempted to spawn on server side! Lights are CLIENT SIDE ONLY!");
249 return light_instance;
255 m_Brightness = value;
256 m_BrightnessTarget = value;
257 SetBrightness(m_Brightness * m_BrightnessPulse);
258 CorrectLightPulseDuringDaylight();
264 if (m_Brightness < 100)
266 float v = m_Brightness * 0.01;
270 float brightness_compesation = 1 / v;
271 float compenset_brightness = (m_Brightness * m_BrightnessPulse) * brightness_compesation;
272 SetBrightness(compenset_brightness);
285 m_BrightnessTarget = value;
289 m_BrightnessSpeedOfChange = 9999;
293 m_BrightnessSpeedOfChange =
Math.
AbsFloat(m_Brightness - m_BrightnessTarget) / time_in_s;
301 m_RadiusTarget = value;
308 m_RadiusTarget = value;
312 m_RadiusSpeedOfChange = 9999;
326 DeleteLightWithDelay();
341 m_FadeOutTime = time_in_s * 1000;
347 float time_in_ms = time_in_s * 1000;
351 float kill_time_in_s = m_FadeOutTime*0.001;
353 FadeBrightnessTo(0, kill_time_in_s);
354 FadeRadiusTo(0, kill_time_in_s);
355 SetLifetime(kill_time_in_s);
359 FadeBrightnessTo(0, time_in_s);
360 FadeRadiusTo(0, time_in_s);
361 SetLifetime(time_in_s);
368 float brightness = m_Brightness;
370 FadeBrightnessTo(brightness, time_in_s);
376 m_LifetimeEnd += life_in_s * 1000;
391 if ( CheckLifetime(current_time) )
400 HandleFlickering(current_time - m_LifetimeStart, timeSlice);
401 HandleDancingShadows(current_time - m_LifetimeStart, timeSlice);
402 CheckFadeOut(current_time);
403 HandleBrightnessFadeing(timeSlice);
404 HandleRadiusFadeing(timeSlice);
406 CheckIfParentIsInCargo();
407 TryShadowOptimization();
408 OnFrameLightSource(other, timeSlice);
410 HandleBlinking(current_time);
416 m_DancingShadowsAmplitude =
Math.
AbsFloat(max_deviation_in_meters);
422 m_DancingShadowsSpeed =
Math.
AbsFloat(speed_in_meters_per_frame);
428 return m_DancingShadowsAmplitude;
434 return m_DancingShadowsSpeed;
440 m_IsDebugEnabled = state;
446 if (m_DancingShadowsAmplitude > 0)
448 for (
int i = 0; i < 3; i++ )
450 m_DancingShadowsLocalPos[i] = m_DancingShadowsLocalPos[i] + (
Math.
RandomFloat(-m_DancingShadowsSpeed,m_DancingShadowsSpeed) * timeSlice) ;
452 if (m_DancingShadowsLocalPos[i] > m_DancingShadowsAmplitude)
453 m_DancingShadowsLocalPos[i] = m_DancingShadowsAmplitude;
455 if (m_DancingShadowsLocalPos[i] < -m_DancingShadowsAmplitude)
456 m_DancingShadowsLocalPos[i] = -m_DancingShadowsAmplitude;
471 if (m_IsDebugEnabled)
479 m_DancingShadowsLocalPos =
Vector(0,0,0);
486 if (m_BrightnessPulseAmplitudeMax > 0)
488 m_BrightnessPulse += (
Math.
RandomFloat(-m_BrightnessPulseSpeed, m_BrightnessPulseSpeed) ) * timeSlice;
490 if (m_BrightnessPulse < m_BrightnessPulseAmplitudeMin + 1)
491 m_BrightnessPulse = m_BrightnessPulseAmplitudeMin + 1;
493 if (m_BrightnessPulse > m_BrightnessPulseAmplitudeMax + 1)
494 m_BrightnessPulse = m_BrightnessPulseAmplitudeMax + 1;
499 m_BrightnessPulse = 1;
506 m_BrightnessPulseSpeed = speed;
518 m_BrightnessPulseAmplitudeMax = coef;
523 m_BrightnessPulseAmplitudeMin = coef;
529 return m_BrightnessPulseSpeed;
535 return m_BrightnessPulseAmplitudeMax;
541 return m_BrightnessPulseAmplitudeMin;
547 if (m_OptimizeShadowsRadius > 0)
551 if (distance_to_camera < m_OptimizeShadowsRadius)
553 SetCastShadow(
false);
565 m_OptimizeShadowsRadius = radius_in_m;
571 return m_OptimizeShadowsRadius;
592 EntityAI parent2 = parent_EAI.GetHierarchyParent();
594 if (parent2 && parent2.GetInventory())
596 is_in_cargo = parent2.GetInventory().IsInCargo();
616 if ( current_time > m_LifetimeEnd && m_LifetimeEnd != -1 )
629 if ( m_FadeOutTime != -1 && m_LifetimeEnd != -1 && current_time > m_LifetimeEnd - m_FadeOutTime )
633 float time_left_in_s = (m_LifetimeEnd - current_time) * 0.001;
634 FadeBrightnessTo(0, time_left_in_s);
635 FadeRadiusTo(0, time_left_in_s);
642 if ( m_Brightness != m_BrightnessTarget )
644 float brightness_difference = m_Brightness - m_BrightnessTarget;
646 if (brightness_difference > m_BrightnessSpeedOfChange*timeSlice)
647 brightness_difference = m_BrightnessSpeedOfChange*timeSlice;
649 if (brightness_difference < -m_BrightnessSpeedOfChange*timeSlice)
650 brightness_difference = -m_BrightnessSpeedOfChange*timeSlice;
652 m_Brightness -= brightness_difference;
654 if ( m_Brightness > 0 || m_BrightnessTarget > 0)
656 SetBrightness(m_Brightness * m_BrightnessPulse);
657 CorrectLightPulseDuringDaylight();
667 SetBrightness(m_Brightness * m_BrightnessPulse);
668 CorrectLightPulseDuringDaylight();
677 float radius_difference =
m_Radius - m_RadiusTarget;
679 if (radius_difference > m_RadiusSpeedOfChange*timeSlice)
680 radius_difference = m_RadiusSpeedOfChange*timeSlice;
682 if (radius_difference < -m_RadiusSpeedOfChange*timeSlice)
683 radius_difference = -m_RadiusSpeedOfChange*timeSlice;
687 if (
m_Radius > 0 || m_RadiusTarget > 0)
706 m_BlinkingSpeed = _speed;
712 return m_BlinkingSpeed;
718 if ( m_BlinkingSpeed <= 0 )
723 multiplier =
Math.
Sin(time * 0.001 * m_BlinkingSpeed);
724 multiplier = (multiplier + 1)/2;
727 SetBrightness(m_Brightness * multiplier);
protected vector m_LocalOri
Local orientation set by SetAttachedLocalOri, only used by EffectParticle.
protected vector m_LocalPos
Cached local pos.
protected ref Timer m_DeleteTimer
protected void CreateLight()
InventoryLocationType
types of Inventory Location
void ParticleManager(ParticleManagerSettings settings)
Constructor (ctor)
protected Widget m_Parent
class JsonUndergroundAreaTriggerData GetPosition
proto native void ObjectDelete(Object obj)
proto int GetTime()
returns mission time in milliseconds
void SetFlickerSpeed(float speed)
Sets speed of light flickering (random brightness coefficient change per second)
void SetFadeOutTime(float time_in_s)
Sets the fade out time in seconds. Fade out begins automatically as the light nears the end of its li...
void SetDisableShadowsWithinRadius(float radius_in_m)
When the light source gets within this radius (radius_in_m) around the camera, then it's shadows are ...
static ScriptedLightBase CreateLight(typename name, vector global_pos="0 0 0", float fade_in_time_in_s=0)
Creates an instance of light on the given position. Optionally, use fade_in_time_in_s parameter to ma...
float m_DancingShadowsSpeed
void FadeIn(float time_in_s)
Makes the light fade into existence. Works only at the moment the light is created....
void CorrectLightPulseDuringDaylight()
Call this after using SetBrightness(...) to fix light's intensity during daytime.
void DetachFromParent()
Detaches this light from its parent entity.
void AddLifetime(float life_in_s)
Prolongs the lifetime of the light in seconds. Use negative number to shorten its lifetime.
float GetBlinkingSpeed()
Returns the speed of blinks.
void SetDancingShadowsMovementSpeed(float speed_in_meters_per_frame)
Sets the maximum speed of the point light within the dancing shadows effect.
float GetDisableShadowsWithinRadius()
Returns the range you put inside SetDisableShadowsWithinRadius(...)
void AttachOnObject(Object parent, vector local_pos="0 0 0", vector local_ori="0 0 0")
Attaches this light on the parent entity, with optional position and orientation offset.
void SetLifetime(float life_in_s)
Makes the light destroy itself after the given time in seconds. The light will fade out if it's set t...
private void CheckFadeOut(int current_time)
void ~ScriptedLightBase()
void CheckIfParentIsInCargo()
private void DeleteLightWithDelay()
Correct way of deleting light from memory. It is necesarry to have this delay due to hierarchy.
void FadeBrightnessTo(float value, float time_in_s)
Fades the brightness of the light to the given value.
private void UpdateLightMode(string slotName)
static ScriptedLightBase CreateLightAtObjMemoryPoint(typename name, notnull Object target, string memory_point_start, string memory_point_target="", vector global_pos="0 0 0", float fade_in_time_in_s=0)
float m_BrightnessPulseSpeed
float m_DancingShadowsAmplitude
vector m_DancingShadowsLocalPos
private bool CheckLifetime(int current_time)
float GetFlickerAmplitudeCoefMin()
Returns flicker amplitude minimum.
float GetDancingShadowsAmplitude()
Returns max movement range of pointlight within the dancing shadow effect.
void ScriptedLightBase()
Constructor. Everything here is executed before the constructor of all children.
float m_BrightnessPulseAmplitudeMin
void AttachOnMemoryPoint(Object parent, string memory_point_start, string memory_point_target="")
Attaches this light on the parent entity's memory point, with optional direction target memory point.
void SetBlinkingSpeed(float _speed)
Sets blinking speed (no blinking if speed <= 0)
private void HandleRadiusFadeing(float timeSlice)
override bool IsScriptedLight()
void FadeOut(float time_in_s=-1)
Starts the fade out process and destroys the light when its done. Optional parameter allows you to se...
private void DeleteLightNow()
void SetBrightnessTo(float value)
Sets the brightness of the light.
private void HandleBlinking(float time)
float m_BrightnessPulseAmplitudeMax
void EnableDebug(bool state)
Enables some debug functionality of this light.
void HandleFlickering(float time, float timeSlice)
private void HandleBrightnessFadeing(float timeSlice)
float GetFlickerAmplitudeCoefMax()
Returns flicker amplitude maximum.
override void EOnInit(IEntity other, int extra)
float GetDancingShadowsMovementSpeed()
Returns max movement speed of pointlight within the dancing shadow effect.
void HandleDancingShadows(float time, float timeSlice)
void Destroy()
Switches off the light and deletes it from memory.
void SetFlickerAmplitude(float coef)
Sets the change coefficient of flickering light. (0.0 - 1.0 values, result of greater values are peri...
void SetFlickerAmplitudeMax(float coef)
void FadeRadiusTo(float value, float time_in_s)
Fades the radius of the light to the given value.
void SetFlickerAmplitudeMin(float coef)
float GetFlickerSpeed()
Returns flicker speed.
void SetRadiusTo(float value)
Sets the radius of the light.
void SetDancingShadowsAmplitude(float max_deviation_in_meters)
Sets the maximum range of the point light within the dancing shadows effect.
override void EOnFrame(IEntity other, float timeSlice)
On frame event. If you want to control your light within your own rules then override the event OnFra...
void OnFrameLightSource(IEntity other, float timeSlice)
Override this for custom functionality.
void TryShadowOptimization()
Optimizes shadows by disabling them on this light source while it's within the given radius around th...
Object GetAttachmentParent()
Returns attachment parent.
script counterpart to engine's class Inventory
bool IsInCargo()
Returns true if this Inventory owner is in cargo of something.
proto native int GetType()
returns type of InventoryLocation
proto native int GetSlot()
returns slot id if current type is Attachment
provides access to slot configuration
static proto native owned string GetSlotName(int id)
converts slot_id to string
Legacy way of using particles in the game.
void SetParticleParam(int parameter_id, float value)
Set the value of a parameter of all emitors in the particle.
static const int DEBUG_DOT
static proto native float Distance(vector v1, vector v2)
Returns the distance between tips of two 3D vectors.
proto vector VectorToAngles()
Converts vector to spherical coordinates with radius = 1.
static vector Direction(vector p1, vector p2)
Returns direction vector from point p1 to point p2.
proto native CGame GetGame()
void Error(string err)
Messagebox with error message.
proto native void SetPosition(vector position)
Set the world position of the Effect.
proto native void Destroy()
Cleans up the Effect, including unregistering if needed.
EntityEvent
Entity events for event-mask, or throwing event from code.
proto native vector Vector(float x, float y, float z)
Vector constructor from components.
static proto float Round(float f)
Returns mathematical round of value.
static proto float RandomFloat(float min, float max)
Returns a random float number between and min[inclusive] and max[exclusive].
static proto float AbsFloat(float f)
Returns absolute value.
static proto float Sin(float angle)
Returns sinus of angle in radians.
static proto string ToString(void var, bool type=false, bool name=false, bool quotes=true)
Return string representation of variable.