MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // MorgenGrauen MUDlib |
| 2 | // |
| 3 | // envchk.c -- verhindern, dass objekte ohne env herumfliegen |
| 4 | // |
| 5 | // $Id: thing.c 6283 2007-05-09 21:30:33Z Zesstra $ |
| 6 | |
| 7 | #pragma strict_types |
| 8 | #pragma save_types |
| 9 | #pragma range_check |
| 10 | #pragma no_clone |
| 11 | #pragma pedantic |
| 12 | |
| 13 | #include <moving.h> |
| 14 | #define NEED_PROTOTYPES |
| 15 | #include <thing/moving.h> |
Zesstra | f17d3a0 | 2018-11-12 22:29:00 +0100 | [diff] [blame] | 16 | #include <thing/properties.h> |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 17 | |
| 18 | protected void check_for_environment(string cloner) |
| 19 | { |
| 20 | // Clones, die innerhalb von 10 Sekunden kein Environment haben, |
| 21 | // sollen auf -debug scrollen. |
| 22 | if ( clonep() && !environment() ) { |
| 23 | // mal in den Muellraum bewegen, damit diese Objekte zwar nicht zerstoert |
| 24 | // werden, aber zumindest hinterher noch einfach auffindbar sind. (Und |
| 25 | // entweder per hand oder automatisch aufgeraeumt werden koennen.) |
| 26 | move("/room/muellraum",M_NOCHECK|M_SILENT); |
| 27 | if ( !stringp(cloner) || !sizeof(cloner) ) |
| 28 | cloner = "<Unbekannt>"; |
| 29 | raise_error("Objekt hat kein Environment. Cloner: ["+cloner+"] "); |
| 30 | } |
| 31 | } |
| 32 | |
Zesstra | f17d3a0 | 2018-11-12 22:29:00 +0100 | [diff] [blame] | 33 | protected void create() |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 34 | { |
Zesstra | f17d3a0 | 2018-11-12 22:29:00 +0100 | [diff] [blame] | 35 | if( clonep() ) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 36 | call_out(#'check_for_environment, 3, object_name(previous_object())); |
| 37 | } |
Zesstra | f17d3a0 | 2018-11-12 22:29:00 +0100 | [diff] [blame] | 38 | |
| 39 | // Kein Envcheck fuer Auto-Objekte, dafuer entfernen diese sich im naechsten |
| 40 | // Reset, sofern sie noch kein Environment haben. |
| 41 | // BTW: Abschalten des Resets sorgt fuer kein Aufraeumen. |
| 42 | public int SetAutoObject(int autostate) |
| 43 | { |
| 44 | if (autostate) |
| 45 | { |
| 46 | Set("p_lib_autoobject", 1, F_VALUE); |
| 47 | Set("p_lib_autoobject", PROTECTED|NOSETMETHOD, F_MODE_AS); |
| 48 | remove_call_out(#'check_for_environment); |
| 49 | if (autostate > 1) |
| 50 | set_next_reset(autostate); |
| 51 | // else: Standardresetzeit |
| 52 | } |
| 53 | else |
| 54 | { |
| 55 | // (Re-)Enable envchk |
| 56 | Set("p_lib_autoobject", 0, F_VALUE); |
| 57 | Set("p_lib_autoobject", PROTECTED|NOSETMETHOD, F_MODE_AD); |
| 58 | if (clonep() && find_call_out(#'check_for_environment) == -1) |
| 59 | call_out(#'check_for_environment, 3, object_name(previous_object())); |
| 60 | } |
| 61 | return autostate; |
| 62 | } |
| 63 | |
| 64 | void reset() |
| 65 | { |
| 66 | // wenn kein env und Autoobject: zerstoeren |
| 67 | if (clonep() && !environment() |
| 68 | && Query("p_lib_autoobject", F_VALUE)) |
| 69 | { |
| 70 | remove(1); |
| 71 | // hier wirklich erzwingen, um unter allen Umstaenden zu vermeiden, dass |
| 72 | // sich dauerhaft Clones ansammeln, die niemand mehr referenziert. |
| 73 | if (objectp(this_object())) |
| 74 | destruct(this_object()); |
| 75 | } |
| 76 | } |