MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // thing/description.c -- Lichtsystemkomponenten fuer Standardobjekte |
| 4 | // |
| 5 | // $Id: description.c 7635 2010-08-19 21:21:30Z Zesstra $ |
| 6 | |
| 7 | #pragma strict_types |
| 8 | #pragma save_types,rtt_checks |
| 9 | #pragma range_check |
| 10 | #pragma no_clone |
| 11 | #pragma pedantic |
| 12 | |
| 13 | #define NEED_PROTOTYPES |
| 14 | #include <thing/properties.h> |
| 15 | #include <thing/language.h> |
| 16 | #include <hook.h> |
| 17 | #undef NEED_PROTOTYPES |
| 18 | |
| 19 | #include <thing/lighttypes.h> |
| 20 | #include <properties.h> |
| 21 | |
| 22 | // ##################### |
| 23 | //######################## System-Funktionen ############################ |
| 24 | // ##################### |
| 25 | |
| 26 | // Objekt erzeugen |
| 27 | protected void create() |
| 28 | { |
| 29 | Set( P_LIGHT, 0 ); |
| 30 | Set( P_LIGHT_TYPE, LT_MISC); |
| 31 | } |
| 32 | |
| 33 | protected void create_super() { |
| 34 | set_next_reset(-1); |
| 35 | } |
| 36 | |
| 37 | // Lichtsy ... sys ... |
| 38 | static int _query_total_light() { return QueryProp(P_LIGHT); } |
| 39 | |
| 40 | static int _set_light( int light ) |
| 41 | { |
| 42 | object env = this_object(); |
| 43 | |
| 44 | // TODO: Temporaer Lichtlevel in geeignete Wertefenster zwingen. |
| 45 | if (light > 100) |
| 46 | light = 100; |
| 47 | else if (light < -100) |
| 48 | light = -100; |
Arathorn | 12d0516 | 2016-08-20 12:32:38 +0200 | [diff] [blame] | 49 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 50 | while ( objectp(env = environment(env)) ) |
| 51 | // Ja. Man ruft die _set_xxx()-Funktionen eigentlich nicht direkt auf. |
| 52 | // Aber das Lichtsystem ist schon *so* rechenintensiv und gerade der |
| 53 | // P_LAST_CONTENT_CHANGE-Cache wird *so* oft benoetigt, dass es mir |
| 54 | // da um jedes bisschen Rechenzeit geht. |
| 55 | // Der Zweck heiligt ja bekanntlich die Mittel. ;-) |
| 56 | // |
| 57 | // Tiamak |
| 58 | env->_set_last_content_change(); |
Arathorn | 12d0516 | 2016-08-20 12:32:38 +0200 | [diff] [blame] | 59 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 60 | return Set( P_LIGHT, light, F_VALUE); |
| 61 | } |
| 62 | |
Arathorn | 12d0516 | 2016-08-20 12:32:38 +0200 | [diff] [blame] | 63 | |
| 64 | // ############## |
| 65 | //######################## Lichttypen ############################ |
| 66 | // ############## |
| 67 | |
| 68 | // Lichttypen pruefen |
Zesstra | 02e8b68 | 2018-11-28 22:28:15 +0100 | [diff] [blame] | 69 | public varargs int CheckLightType(int lighttype, int mode) |
Arathorn | 12d0516 | 2016-08-20 12:32:38 +0200 | [diff] [blame] | 70 | { |
| 71 | int my_light_type = QueryProp(P_LIGHT_TYPE); |
| 72 | |
| 73 | switch( mode ) |
| 74 | { |
| 75 | // mind. alle angegebenen muessen vertreten sein |
| 76 | case LT_CHECK_ALL: |
| 77 | return ((lighttype & my_light_type) == lighttype); |
| 78 | // Genau diese Typen muessen vertreten sein. |
| 79 | case LT_CHECK_MATCH: |
| 80 | return (lighttype == my_light_type); |
| 81 | // Es darf kein Typ vertreten sein. |
| 82 | case LT_CHECK_NONE: |
| 83 | return !(lighttype & my_light_type); |
| 84 | // mind. einer der uebergebenen Typen muss vertreten sein |
| 85 | case LT_CHECK_ANY: |
| 86 | default: |
| 87 | return (lighttype & my_light_type); |
| 88 | } |
| 89 | return 0; |
| 90 | } |