2 @Copyright Looking Glass Studios, Inc.
3 1996,1997,1998,1999,2000 Unpublished Work.
6 ///////////////////////////////////////////////////////////////////////////////
7 // $Header: r:/t2repos/thief2/src/script/litscrpt.cpp,v 1.4 1999/05/30 16:14:23 XEMU Exp $
29 // Include this last, please.
32 ///////////////////////////////////////////////////////////////////////////////
34 // Message implementations
38 ///////////////////////////////////////////////////////////////////////////////
40 // CLASS: cLightScrSrv
44 DECLARE_SCRIPT_SERVICE_IMPL(cLightScrSrv
, Light
)
48 STDMETHOD_ (void, Set
)(const object ref obj
, int mode
,
49 float min_brightness
, float max_brightness
)
51 sAnimLightProp
*pAnimLight
;
53 if (GetAnimLight(obj
, &pAnimLight
))
54 SetCore(obj
, pAnimLight
, mode
, min_brightness
, max_brightness
);
57 STDMETHOD_ (void, SetMode
)(const object ref obj
, int mode
)
59 sAnimLightProp
*pAnimLight
;
61 if (GetAnimLight(obj
, &pAnimLight
))
62 SetCore(obj
, pAnimLight
, mode
, pAnimLight
->animation
.min_brightness
,
63 pAnimLight
->animation
.max_brightness
);
66 STDMETHOD_(int, GetMode
)(const object ref obj
)
68 sAnimLightProp
*pAnimLight
;
70 if (GetAnimLight(obj
, &pAnimLight
))
71 return(pAnimLight
->animation
.mode
);
76 STDMETHOD_ (void, Activate
)(const object ref obj
)
78 sAnimLightProp
*pAnimLight
;
80 if (GetAnimLight(obj
, &pAnimLight
))
81 pAnimLight
->animation
.inactive
= FALSE
;
84 STDMETHOD_ (void, Deactivate
)(const object ref obj
)
86 sAnimLightProp
*pAnimLight
;
88 if (GetAnimLight(obj
, &pAnimLight
))
89 pAnimLight
->animation
.inactive
= TRUE
;
92 STDMETHOD_ (void, Subscribe
)(const object ref obj
)
94 sAnimLightProp
*pAnimLight
;
96 if (GetAnimLight(obj
, &pAnimLight
))
97 pAnimLight
->notify_script
= obj
;
100 STDMETHOD_ (void, Unsubscribe
)(const object ref obj
)
102 sAnimLightProp
*pAnimLight
;
104 if (GetAnimLight(obj
, &pAnimLight
))
105 pAnimLight
->notify_script
= OBJ_NULL
;
110 // simple wrapper to spew if prop not on object
111 // 5/29/99 Xemu: changed to spew
112 BOOL
GetAnimLight(ObjID obj
, sAnimLightProp
**pAnimLight
)
114 if (!(g_AnimLightProp
->Get(obj
, pAnimLight
))) {
115 ConfigSpew("LightSpew",("Light script service: no anim light property on %d\n",
123 // internal: assumes valid prop struct
124 void SetCore(ObjID obj
, sAnimLightProp
*pAnimLight
, int mode
,
125 float min_brightness
, float max_brightness
)
127 int countdown
= pAnimLight
->animation
.countdown_ms
;
128 BOOL isRising
= pAnimLight
->animation
.is_rising
;
130 #ifdef NEW_NETWORK_ENABLED
131 if (pAnimLight
->animation
.mode
!= mode
) {
132 // Tell the clients that we're changing the light:
133 BroadcastAnimLightMode(obj
, mode
);
137 // We slam the countdown to a value which preserves the light
138 // level. We also slam the isRising field for the whacky modes.
139 if ((mode
== ANIM_LIGHT_MODE_SMOOTH
&& isRising
)
140 || (mode
== ANIM_LIGHT_MODE_SMOOTH_BRIGHTEN
)) {
141 countdown
= TimeLeft(pAnimLight
->animation
.brightness
,
142 max_brightness
, min_brightness
,
143 pAnimLight
->animation
.time_rising_ms
);
144 pAnimLight
->animation
.is_rising
= TRUE
;
147 if ((mode
== ANIM_LIGHT_MODE_SMOOTH
&& !isRising
)
148 || (mode
== ANIM_LIGHT_MODE_SMOOTH_DIM
)) {
149 countdown
= TimeLeft(pAnimLight
->animation
.brightness
,
150 min_brightness
, max_brightness
,
151 pAnimLight
->animation
.time_falling_ms
);
152 pAnimLight
->animation
.is_rising
= FALSE
;
155 pAnimLight
->animation
.countdown_ms
= countdown
;
156 pAnimLight
->animation
.mode
= mode
;
157 pAnimLight
->animation
.inactive
= FALSE
;
161 int TimeLeft(float current
, float start
, float end
, int ms
)
163 float ratio
= (current
- start
) / (end
- start
); // how far along time
164 if (ratio
> 1.0) // clamp to given start & end
168 return (int) (ratio
* (float) ms
);
172 IMPLEMENT_SCRIPT_SERVICE_IMPL(cLightScrSrv
, Light
);
174 ///////////////////////////////////////////////////////////////////////////////