MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 36 | #pragma range_check |
| 37 | |
| 38 | inherit "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... |
| 58 | nosave int fuel, max_fuel; |
| 59 | nosave bool lighted ; |
| 60 | nosave int call_time ; |
| 61 | |
| 62 | void 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 | |
| 81 | void test_remove() |
| 82 | { if (QueryProp(P_DO_DESTRUCT)) remove(); } |
| 83 | |
| 84 | /* |
| 85 | * Lichtquelle anzuenden |
| 86 | */ |
| 87 | bool 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 |
bugfix | d94d093 | 2020-04-08 11:27:13 +0200 | [diff] [blame] | 126 | ({int})env->_set_last_content_change(); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 127 | call_time = (fuel < CALL_OUT_TIME)? fuel : CALL_OUT_TIME ; |
| 128 | call_out( "out_of_fuel", call_time ) ; |
Zesstra | 6e0caf1 | 2020-04-07 19:21:01 +0200 | [diff] [blame] | 129 | if( ({int})PL->QueryProp(P_PLAYER_LIGHT) == 1 ) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 130 | write( "Du kannst wieder etwas sehen.\n" ) ; |
| 131 | else write( "Ok.\n" ) ; |
Zesstra | 6e0caf1 | 2020-04-07 19:21:01 +0200 | [diff] [blame] | 132 | say(({string})PL->Name(WER) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 133 | + " zuendet " + name( WEN, 0 ) + " an.\n" ) ; |
| 134 | |
| 135 | return TRUE ; |
| 136 | } |
| 137 | |
| 138 | bool 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 |
bugfix | d94d093 | 2020-04-08 11:27:13 +0200 | [diff] [blame] | 174 | ({int})env->_set_last_content_change(); |
Zesstra | 6e0caf1 | 2020-04-07 19:21:01 +0200 | [diff] [blame] | 175 | if ( ({int})this_player()->QueryProp(P_PLAYER_LIGHT) == 0 ) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 176 | { |
| 177 | write( "Es wird dunkel.\n" ) ; |
Zesstra | 6e0caf1 | 2020-04-07 19:21:01 +0200 | [diff] [blame] | 178 | say(({string})PL->Name(WER) + " macht das Licht aus.\n" ) ; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 179 | } |
| 180 | else |
| 181 | { |
| 182 | write( "Ok.\n" ) ; |
Zesstra | 6e0caf1 | 2020-04-07 19:21:01 +0200 | [diff] [blame] | 183 | say(({string})PL->Name(WER) + " loescht " + name( WEN, 0 ) |
| 184 | + " aus.\n" ) ; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 185 | } |
| 186 | |
| 187 | if( fuel <= 0 ) test_remove() ; |
| 188 | return TRUE ; |
| 189 | } |
| 190 | |
| 191 | bool unlight() |
| 192 | { |
| 193 | int ti; |
| 194 | object env; |
| 195 | |
| 196 | if( !lighted ) |
| 197 | return FALSE ; |
| 198 | |
bugfix | d94d093 | 2020-04-08 11:27:13 +0200 | [diff] [blame] | 199 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 200 | 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 ;^) |
bugfix | d94d093 | 2020-04-08 11:27:13 +0200 | [diff] [blame] | 208 | ({int})env->_set_last_content_change(); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 209 | if( fuel <= 0 ) test_remove() ; |
| 210 | return TRUE ; |
| 211 | } |
| 212 | |
| 213 | void 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. |
bugfix | d94d093 | 2020-04-08 11:27:13 +0200 | [diff] [blame] | 228 | ({int})env->_set_last_content_change(); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 229 | |
| 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--) |
bugfix | d94d093 | 2020-04-08 11:27:13 +0200 | [diff] [blame] | 236 | if (({int})inv[i]->QueryProp(P_PLAYER_LIGHT)<=0) |
| 237 | tell_object(inv[i], "Es wird dunkel, als " + ({string})environment()->name(WESSEN) + |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 238 | " " + QueryProp(P_NAME) + " erlischt.\n" ) ; |
| 239 | else tell_object(inv[i], CAP( name( WER, 0 ) ) + " erlischt.\n" ) ; |
bugfix | d94d093 | 2020-04-08 11:27:13 +0200 | [diff] [blame] | 240 | if (({int})environment()->QueryProp(P_PLAYER_LIGHT)<=0) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 241 | tell_object(environment(), |
Arathorn | d7ddef7 | 2018-08-29 22:21:30 +0200 | [diff] [blame] | 242 | CAP( name( WER, 1 ) ) + " erlischt, und es wird dunkel.\n" ) ; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 243 | 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--) |
bugfix | d94d093 | 2020-04-08 11:27:13 +0200 | [diff] [blame] | 249 | if (({int})inv[i]->QueryProp(P_PLAYER_LIGHT)<=0) |
Arathorn | d7ddef7 | 2018-08-29 22:21:30 +0200 | [diff] [blame] | 250 | tell_object(inv[i], "Es wird dunkel, als " + name(WER,1) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 251 | + " erlischt.\n" ) ; |
| 252 | else tell_object(inv[i], CAP( name( WER, 0 ) ) + " erlischt.\n" ) ; |
| 253 | } |
| 254 | } |
| 255 | test_remove() ; |
| 256 | } |
| 257 | |
| 258 | // Brennstoff nachfuellen |
| 259 | void AddFuel(int f) |
| 260 | { fuel += f ; } |
| 261 | |
| 262 | // Property - Funktionen |
| 263 | |
| 264 | static void _set_lighted(bool l) |
| 265 | { lighted = l ; } |
| 266 | |
| 267 | bool _query_lighted() |
| 268 | { return lighted ; } |
| 269 | |
| 270 | static void _set_fuel(int f) |
| 271 | { |
| 272 | if (f>max_fuel) max_fuel=f; |
| 273 | fuel = f ; |
| 274 | } |
| 275 | |
| 276 | static 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 | |
| 285 | static string _query_lightdesc() |
| 286 | { |
Arathorn | 9845d11 | 2020-01-08 22:02:03 +0100 | [diff] [blame] | 287 | string|string* l_desc = Query(P_LIGHTDESC); |
| 288 | if (!pointerp(l_desc)) |
| 289 | return (string)l_desc; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 290 | |
Arathorn | 9845d11 | 2020-01-08 22:02:03 +0100 | [diff] [blame] | 291 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 296 | } |
| 297 | |
| 298 | static int _query_light() |
| 299 | { return (lighted ? Query(P_LIGHT) : 0); } |
| 300 | |
| 301 | /* |
| 302 | * short() ueberladen |
| 303 | */ |
| 304 | string short() |
| 305 | { |
| 306 | string s; |
| 307 | string desc; |
| 308 | |
| 309 | if(!(s=QueryProp(P_SHORT))) |
| 310 | return 0; |
| 311 | return s + ( (lighted)? (" ("+QueryProp( P_LIGHTDESC ) +").\n") : ".\n" ); |
| 312 | } |