blob: 129121d7d8b1dcdda2999f3ecd6e6f2dc60cc95d [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// lightsource.c -- standard light source
4//
5// $Id: lightsource.c 7806 2011-07-11 20:28:17Z Zesstra $
6
7// std/lightsource.c
8//
9// Original von Miril April '92
10// Neufassung von Sir Dezember '92 ( unter Boings Aegide :)
11// Version : 1.0
12//
13// Bugfixes von Sir Juni '93
14// Version : 1.2
15//
16// Wichtige Funktionen, die man in create() aufrufen sollte :
17//
18// Setzen der Brennstoffmenge :
19// SetProp( P_FUEL, int ) int gibt die Brennzeit in Sekunden an
20//
21// Setzen der Beschreibung wenn Objekt angezuendet( default : "brennend" ) :
22// SetProp( P_LIGHTDESC, string )
23//
24// Legt fest, ob ein Leuchtobjekt nach seinem Abbrennen destructed wird
25// SetProp( P_DO_DESTRUCT, int )
26//
27// Legt fest, wie hell die Fackel leuchtet.
28// SetProp( P_LIGHT, int )
29//
30// Ansonsten sind die Standardfuktionen wie z.B. SetProp( P_GENDER, MALE )
31// aufzurufen
32
33#pragma strict_types
34#pragma save_types
35#pragma no_clone
MG Mud User88f12472016-06-24 23:31:02 +020036#pragma range_check
37
38inherit "std/thing" ;
39
40#include <properties.h>
41#include <language.h>
42#include <defines.h>
43
44#define TRUE 1
45#define FALSE 0
46#define bool int
47
48#define DFLT_FUEL 20 // 20 Sekunden
49#define DFLT_LIGHTDESC "brennend"
50#define DFLT_LIGHT 2
51
52// So ergibt sich die Moeglichkeit sie wieder auzufuellen
53#define CALL_OUT_TIME 100
54
55#undef DEBUG
56
57// TODO: Private waer langfristig nett...
58nosave int fuel, max_fuel;
59nosave bool lighted ;
60nosave int call_time ;
61
62void create()
63{
64 thing::create() ;
65
66 SetProp( P_NAME, "Lichtquelle" ) ;
67 SetProp( P_SHORT, "Eine Lichtquelle" ) ;
68 SetProp( P_LONG, "Du siehst nichts besonderes.\n" ) ;
69 SetProp( P_GENDER, FEMALE ) ;
70 SetProp( P_FUEL, DFLT_FUEL ) ;
71 SetProp( P_LIGHTDESC, DFLT_LIGHTDESC ) ;
72 SetProp( P_LIGHT, DFLT_LIGHT );
73 SetProp( P_DO_DESTRUCT, TRUE ) ;
74 SetProp( P_VALUE, 5 ) ;
75
76 AddId( ({ "lichtquelle", "\nlichtquelle" }) ) ;
77 AddCmd( ({ "zuende", "zuend" }), "light" );
78 AddCmd( ({ "loesche", "loesch" }), "extinguish" );
79}
80
81void test_remove()
82{ if (QueryProp(P_DO_DESTRUCT)) remove(); }
83
84/*
85 * Lichtquelle anzuenden
86 */
87bool light(string str)
88{
89 string tmp ;
90 object env;
91
92 _notify_fail( "Zuende was an?\n" ) ;
93
94 if( (!str) || (!sscanf( str, "%s an", tmp )) || (!id( tmp )) )
95 return FALSE ;
96
97 if( environment() != PL ) // Player hat es nicht
98 {
99 _notify_fail( "Erstmal musst Du " + name( WEN, 0 ) + " haben.\n" ) ;
100 return FALSE ;
101 }
102
103 if( lighted )
104 {
105 _notify_fail( CAP( name( WER, 1 ) ) + " brennt schon.\n" ) ;
106 return FALSE ;
107 }
108
109 if( fuel <= 0 )
110 {
111 _notify_fail( CAP( name( WER, 1 ) ) + " ist abgebrannt.\n" ) ;
112 test_remove() ;
113 return FALSE ;
114 }
115
116 lighted = TRUE ;
117 env=this_object();
118 while (objectp(env=environment(env)))
119 // Ja. Man ruft die _set_xxx()-Funktionen eigentlich nicht direkt auf.
120 // Aber das Lichtsystem ist schon *so* rechenintensiv und gerade der
121 // P_LAST_CONTENT_CHANGE-Cache wird *so* oft benoetigt, dass es mir
122 // da um jedes bisschen Rechenzeit geht.
123 // Der Zweck heiligt ja bekanntlich die Mittel. ;-)
124 //
125 // Tiamak
126 env->_set_last_content_change();
127 call_time = (fuel < CALL_OUT_TIME)? fuel : CALL_OUT_TIME ;
128 call_out( "out_of_fuel", call_time ) ;
Zesstra6e0caf12020-04-07 19:21:01 +0200129 if( ({int})PL->QueryProp(P_PLAYER_LIGHT) == 1 )
MG Mud User88f12472016-06-24 23:31:02 +0200130 write( "Du kannst wieder etwas sehen.\n" ) ;
131 else write( "Ok.\n" ) ;
Zesstra6e0caf12020-04-07 19:21:01 +0200132 say(({string})PL->Name(WER)
MG Mud User88f12472016-06-24 23:31:02 +0200133 + " zuendet " + name( WEN, 0 ) + " an.\n" ) ;
134
135 return TRUE ;
136}
137
138bool extinguish(string str)
139{
140 int ti;
141 object env;
142
143 _notify_fail( "Welche Lichtquelle moechtest Du loeschen?\n" ) ;
144
145 if( (!str) || (!id( str )) )
146 return FALSE ;
147
148 if( !lighted )
149 {
150 _notify_fail( CAP( name( WER, 1 ) ) + " brennt gar nicht.\n" ) ;
151 return FALSE ;
152 }
153
154 if( environment() != PL )
155 {
156 _notify_fail( "Erstmal musst Du " + name( WEN, 0 ) + " haben.\n" ) ;
157 return FALSE ;
158 }
159
160 if( ( ti = remove_call_out( "out_of_fuel" ) ) == -1 )
161 ti = 0 ;
162
163 fuel -= (call_time - ti) ;
164 lighted = FALSE ;
165 env=this_object();
166 while (objectp(env=environment(env)))
167 // Ja. Man ruft die _set_xxx()-Funktionen eigentlich nicht direkt auf.
168 // Aber das Lichtsystem ist schon *so* rechenintensiv und gerade der
169 // P_LAST_CONTENT_CHANGE-Cache wird *so* oft benoetigt, dass es mir
170 // da um jedes bisschen Rechenzeit geht.
171 // Der Zweck heiligt ja bekanntlich die Mittel. ;-)
172 //
173 // Tiamak
174 env->_set_last_content_change();
Zesstra6e0caf12020-04-07 19:21:01 +0200175 if ( ({int})this_player()->QueryProp(P_PLAYER_LIGHT) == 0 )
MG Mud User88f12472016-06-24 23:31:02 +0200176 {
177 write( "Es wird dunkel.\n" ) ;
Zesstra6e0caf12020-04-07 19:21:01 +0200178 say(({string})PL->Name(WER) + " macht das Licht aus.\n" ) ;
MG Mud User88f12472016-06-24 23:31:02 +0200179 }
180 else
181 {
182 write( "Ok.\n" ) ;
Zesstra6e0caf12020-04-07 19:21:01 +0200183 say(({string})PL->Name(WER) + " loescht " + name( WEN, 0 )
184 + " aus.\n" ) ;
MG Mud User88f12472016-06-24 23:31:02 +0200185 }
186
187 if( fuel <= 0 ) test_remove() ;
188 return TRUE ;
189}
190
191bool unlight()
192{
193 int ti;
194 object env;
195
196 if( !lighted )
197 return FALSE ;
198
199 if( ( ti = remove_call_out( "out_of_fuel" ) ) == -1 )
200 ti = 0 ;
201
202 fuel -= (call_time - ti) ;
203 lighted = FALSE ;
204 env=this_object();
205 while (objectp(env=environment(env)))
206 // Kommentar siehe oben ;^)
207 env->_set_last_content_change();
208 if( fuel <= 0 ) test_remove() ;
209 return TRUE ;
210}
211
212void out_of_fuel()
213{
214 int i;
215 object *inv, env;
216
217 fuel -= call_time ;
218
219 if (fuel>0) {
220 call_out( "out_of_fuel", call_time ) ;
221 return ;
222 }
223 lighted=FALSE;
224 env=this_object();
225 while (objectp(env=environment(env)))
226 // Immer noch nicht wirklich sauber. Aber Begruendung siehe oben.
227 env->_set_last_content_change();
228
229 if (environment())
230 {
231 if ( living(environment()) && environment(environment()) )
232 {
233 inv=(users() & all_inventory(environment(environment())))-({ environment() });
234 for (i=sizeof(inv)-1; i>=0; i--)
235 if (inv[i]->QueryProp(P_PLAYER_LIGHT)<=0)
Arathornd7ddef72018-08-29 22:21:30 +0200236 tell_object(inv[i], "Es wird dunkel, als " + environment()->name(WESSEN) +
MG Mud User88f12472016-06-24 23:31:02 +0200237 " " + QueryProp(P_NAME) + " erlischt.\n" ) ;
238 else tell_object(inv[i], CAP( name( WER, 0 ) ) + " erlischt.\n" ) ;
239 if (environment()->QueryProp(P_PLAYER_LIGHT)<=0)
240 tell_object(environment(),
Arathornd7ddef72018-08-29 22:21:30 +0200241 CAP( name( WER, 1 ) ) + " erlischt, und es wird dunkel.\n" ) ;
MG Mud User88f12472016-06-24 23:31:02 +0200242 else tell_object(environment(), CAP( name( WER, 1 ) ) + " erlischt.\n" ) ;
243 }
244 else
245 {
246 inv=(users() & all_inventory(environment()));
247 for (i=sizeof(inv)-1; i>=0; i--)
248 if (inv[i]->QueryProp(P_PLAYER_LIGHT)<=0)
Arathornd7ddef72018-08-29 22:21:30 +0200249 tell_object(inv[i], "Es wird dunkel, als " + name(WER,1)
MG Mud User88f12472016-06-24 23:31:02 +0200250 + " erlischt.\n" ) ;
251 else tell_object(inv[i], CAP( name( WER, 0 ) ) + " erlischt.\n" ) ;
252 }
253 }
254 test_remove() ;
255}
256
257// Brennstoff nachfuellen
258void AddFuel(int f)
259{ fuel += f ; }
260
261// Property - Funktionen
262
263static void _set_lighted(bool l)
264{ lighted = l ; }
265
266bool _query_lighted()
267{ return lighted ; }
268
269static void _set_fuel(int f)
270{
271 if (f>max_fuel) max_fuel=f;
272 fuel = f ;
273}
274
275static int _query_fuel()
276{
277 int tmp;
278
279 if ((tmp=find_call_out("out_of_fuel"))>=0)
280 return fuel-call_time+tmp;
281 else return fuel;
282}
283
284static string _query_lightdesc()
285{
Arathorn9845d112020-01-08 22:02:03 +0100286 string|string* l_desc = Query(P_LIGHTDESC);
287 if (!pointerp(l_desc))
288 return (string)l_desc;
MG Mud User88f12472016-06-24 23:31:02 +0200289
Arathorn9845d112020-01-08 22:02:03 +0100290 int n = sizeof(l_desc);
291 int i = n * _query_fuel() / max_fuel;
292 if (i>=n)
293 i = n-1;
294 return l_desc[i];
MG Mud User88f12472016-06-24 23:31:02 +0200295}
296
297static int _query_light()
298{ return (lighted ? Query(P_LIGHT) : 0); }
299
300/*
301 * short() ueberladen
302 */
303string short()
304{
305 string s;
306 string desc;
307
308 if(!(s=QueryProp(P_SHORT)))
309 return 0;
310 return s + ( (lighted)? (" ("+QueryProp( P_LIGHTDESC ) +").\n") : ".\n" );
311}