From b683e47499fc7568e50bf3c2bacdf64a95f6b1ea Mon Sep 17 00:00:00 2001 From: Sven Eberhardt Date: Wed, 16 Sep 2015 21:13:00 -0400 Subject: [PATCH] Add LightOffset property to allow light sources to origin from locations other than the object center. --- docs/sdk/script/fn/SetLightRange.xml | 10 ++++++++++ src/landscape/fow/C4FoWLight.cpp | 10 +++++++++- src/script/C4StringTable.cpp | 1 + src/script/C4StringTable.h | 1 + 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/docs/sdk/script/fn/SetLightRange.xml b/docs/sdk/script/fn/SetLightRange.xml index 01cf6cec1..744f7955f 100644 --- a/docs/sdk/script/fn/SetLightRange.xml +++ b/docs/sdk/script/fn/SetLightRange.xml @@ -24,6 +24,7 @@ Sets the light reach of the object. When a clonk is added to the crew via MakeCrewMember, a light is added automatically with the default range of 300 and a fadeout of 80. + A local offset for the light center can be defined by setting the object property LightRange to an array with two elements for X- and Y-offset respectively. func ControlUse(object clonk) @@ -34,6 +35,15 @@ } Confused the acid phile with the eye drops, did ya? + + func Construction() +{ + SetLightRange(100, 100); + this.LightRange = [0,-100]; + return true; +} + Script for a lamp post. A light coming from 100 pixel above the object center is enabled when the object is created. + SetPlrView diff --git a/src/landscape/fow/C4FoWLight.cpp b/src/landscape/fow/C4FoWLight.cpp index 036ca24b9..248b3b4f4 100644 --- a/src/landscape/fow/C4FoWLight.cpp +++ b/src/landscape/fow/C4FoWLight.cpp @@ -96,8 +96,16 @@ void C4FoWLight::SetColor(uint32_t iValue) void C4FoWLight::Update(C4Rect Rec) { - // Update position from object. Clear if we moved in any way + // Update position from object. int32_t iNX = fixtoi(pObj->fix_x), iNY = fixtoi(pObj->fix_y); + // position may be affected by LightOffset property + C4ValueArray *light_offset = pObj->GetPropertyArray(P_LightOffset); + if (light_offset) + { + iNX += light_offset->GetItem(0).getInt(); + iNY += light_offset->GetItem(1).getInt(); + } + // Clear if we moved in any way if (iNX != iX || iNY != iY) { for(size_t i = 0; i < sections.size(); ++i ) diff --git a/src/script/C4StringTable.cpp b/src/script/C4StringTable.cpp index 71c629e91..a895ecf2c 100644 --- a/src/script/C4StringTable.cpp +++ b/src/script/C4StringTable.cpp @@ -236,6 +236,7 @@ C4StringTable::C4StringTable() P[P_Equalizer_Mid2_Width] = "Equalizer_Mid2_Width"; P[P_Equalizer_High_Gain] = "Equalizer_High_Gain"; P[P_Equalizer_High_Cutoff] = "Equalizer_High_Cutoff"; + P[P_LightOffset] = "LightOffset"; P[DFA_WALK] = "WALK"; P[DFA_FLIGHT] = "FLIGHT"; P[DFA_KNEEL] = "KNEEL"; diff --git a/src/script/C4StringTable.h b/src/script/C4StringTable.h index 64990665f..3f1ca44a4 100644 --- a/src/script/C4StringTable.h +++ b/src/script/C4StringTable.h @@ -438,6 +438,7 @@ enum C4PropertyName P_Equalizer_Mid2_Width, P_Equalizer_High_Gain, P_Equalizer_High_Cutoff, + P_LightOffset, // Default Action Procedures DFA_WALK, DFA_FLIGHT,