blob: 834c8b7ca95baa1e7f3ade47a9a0cce36107b514 [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
bugfixd94d0932020-04-08 11:27:13 +0200126 ({int})env->_set_last_content_change();
MG Mud User88f12472016-06-24 23:31:02 +0200127 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
bugfixd94d0932020-04-08 11:27:13 +0200174 ({int})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
bugfixd94d0932020-04-08 11:27:13 +0200199
MG Mud User88f12472016-06-24 23:31:02 +0200200 if( ( ti = remove_call_out( "out_of_fuel" ) ) == -1 )
201 ti = 0 ;
202
203 fuel -= (call_time - ti) ;
204 lighted = FALSE ;
205 env=this_object();
206 while (objectp(env=environment(env)))
207 // Kommentar siehe oben ;^)
bugfixd94d0932020-04-08 11:27:13 +0200208 ({int})env->_set_last_content_change();
MG Mud User88f12472016-06-24 23:31:02 +0200209 if( fuel <= 0 ) test_remove() ;
210 return TRUE ;
211}
212
213void out_of_fuel()
214{
215 int i;
216 object *inv, env;
217
218 fuel -= call_time ;
219
220 if (fuel>0) {
221 call_out( "out_of_fuel", call_time ) ;
222 return ;
223 }
224 lighted=FALSE;
225 env=this_object();
226 while (objectp(env=environment(env)))
227 // Immer noch nicht wirklich sauber. Aber Begruendung siehe oben.
bugfixd94d0932020-04-08 11:27:13 +0200228 ({int})env->_set_last_content_change();
MG Mud User88f12472016-06-24 23:31:02 +0200229
230 if (environment())
231 {
232 if ( living(environment()) && environment(environment()) )
233 {
234 inv=(users() & all_inventory(environment(environment())))-({ environment() });
235 for (i=sizeof(inv)-1; i>=0; i--)
bugfixd94d0932020-04-08 11:27:13 +0200236 if (({int})inv[i]->QueryProp(P_PLAYER_LIGHT)<=0)
237 tell_object(inv[i], "Es wird dunkel, als " + ({string})environment()->name(WESSEN) +
MG Mud User88f12472016-06-24 23:31:02 +0200238 " " + QueryProp(P_NAME) + " erlischt.\n" ) ;
239 else tell_object(inv[i], CAP( name( WER, 0 ) ) + " erlischt.\n" ) ;
bugfixd94d0932020-04-08 11:27:13 +0200240 if (({int})environment()->QueryProp(P_PLAYER_LIGHT)<=0)
MG Mud User88f12472016-06-24 23:31:02 +0200241 tell_object(environment(),
Arathornd7ddef72018-08-29 22:21:30 +0200242 CAP( name( WER, 1 ) ) + " erlischt, und es wird dunkel.\n" ) ;
MG Mud User88f12472016-06-24 23:31:02 +0200243 else tell_object(environment(), CAP( name( WER, 1 ) ) + " erlischt.\n" ) ;
244 }
245 else
246 {
247 inv=(users() & all_inventory(environment()));
248 for (i=sizeof(inv)-1; i>=0; i--)
bugfixd94d0932020-04-08 11:27:13 +0200249 if (({int})inv[i]->QueryProp(P_PLAYER_LIGHT)<=0)
Arathornd7ddef72018-08-29 22:21:30 +0200250 tell_object(inv[i], "Es wird dunkel, als " + name(WER,1)
MG Mud User88f12472016-06-24 23:31:02 +0200251 + " erlischt.\n" ) ;
252 else tell_object(inv[i], CAP( name( WER, 0 ) ) + " erlischt.\n" ) ;
253 }
254 }
255 test_remove() ;
256}
257
258// Brennstoff nachfuellen
259void AddFuel(int f)
260{ fuel += f ; }
261
262// Property - Funktionen
263
264static void _set_lighted(bool l)
265{ lighted = l ; }
266
267bool _query_lighted()
268{ return lighted ; }
269
270static void _set_fuel(int f)
271{
272 if (f>max_fuel) max_fuel=f;
273 fuel = f ;
274}
275
276static int _query_fuel()
277{
278 int tmp;
279
280 if ((tmp=find_call_out("out_of_fuel"))>=0)
281 return fuel-call_time+tmp;
282 else return fuel;
283}
284
285static string _query_lightdesc()
286{
Arathorn9845d112020-01-08 22:02:03 +0100287 string|string* l_desc = Query(P_LIGHTDESC);
288 if (!pointerp(l_desc))
289 return (string)l_desc;
MG Mud User88f12472016-06-24 23:31:02 +0200290
Arathorn9845d112020-01-08 22:02:03 +0100291 int n = sizeof(l_desc);
292 int i = n * _query_fuel() / max_fuel;
293 if (i>=n)
294 i = n-1;
295 return l_desc[i];
MG Mud User88f12472016-06-24 23:31:02 +0200296}
297
298static int _query_light()
299{ return (lighted ? Query(P_LIGHT) : 0); }
300
301/*
302 * short() ueberladen
303 */
304string short()
305{
306 string s;
MG Mud User88f12472016-06-24 23:31:02 +0200307
308 if(!(s=QueryProp(P_SHORT)))
309 return 0;
310 return s + ( (lighted)? (" ("+QueryProp( P_LIGHTDESC ) +").\n") : ".\n" );
311}