blob: 9263ea3ab667a5c374b6e0390948c4d8f4c6d474 [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// player/objects.c -- object handling for player
4//
5// $Id: objects.c 8675 2014-02-18 20:39:54Z Zesstra $
6#pragma strong_types
7#pragma save_types
8#pragma range_check
9#pragma no_clone
10#pragma pedantic
11
12#define NEED_PROTOTYPES
13#include "/sys/player/filesys.h"
14
15#include <config.h>
16#include <player.h>
17#include <properties.h>
18#include <language.h>
19#include <moving.h>
20#include <wizlevels.h>
21#include <thing/moving.h>
22
23static int update_object(string str) {
24 object ob;
25 string upd_file;
26 if (!(str=_unparsed_args())) {
27 notify_fail("Usage: Update <object_path>\n"); return 0;
28 }
29 upd_file = find_file(str,".c");
30 if (!upd_file) upd_file=find_file(str);
31 if (!upd_file) {
32 notify_fail(str+": No such file.\n"); return 0;
33 }
34 ob = find_object(upd_file);
35 if (!ob) {
36 notify_fail(upd_file+": No such object.\n"); return 0;
37 }
38 destruct(ob);
39 write(upd_file + ": will be reloaded at next reference.\n");
40 return 1;
41}
42
43/*
44 * "soft" means that the object is given the chance to self-destruct, thus
45 * allowing it to do necessary cleanup like subtracting from the carried
46 * weight of the environment(). We call remove() in the object to be
47 * destructed.
48 */
49static int soft_update_object(string str)
50{
51 object ob;
52 string upd_file;
53 if (!(str=_unparsed_args())) {
54 notify_fail("Usage: update <object_path>\n"); return 0;
55 }
56 upd_file = find_file(str,".c");
57 if (!upd_file) upd_file=find_file(str);
58 if (!upd_file) {
59 notify_fail(str+": No such file.\n"); return 0;
60 }
61 ob = find_object(upd_file);
62 if (!ob) {
63 notify_fail(upd_file+": No such object.\n"); return 0;
64 }
65 if (ob->remove() == 0) {
66 notify_fail(upd_file+": doesn't want to be destructed!\n"); return 0;
67 }
68 write(upd_file + ": will be reloaded at next reference.\n");
69 return 1;
70}
71
72int clone(string str)
73{
74 object ob;
75 string clone_file;
76
77 if (!(str=_unparsed_args())){
78 notify_fail("Usage: clone <object_path>\n"); return 0;
79 }
80 clone_file = find_file(str,".c");
81 if (!clone_file) clone_file=find_file(str);
82 if (!clone_file) {
83 notify_fail(str+": No such file.\n"); return 0;
84 }
85 if (!(ob = clone_object(clone_file)))
86 return notify_fail(str+": Failed to load.\n"), 0;
87
88 /* Some objects destruct themselves rather fast */
89 if (!objectp(ob))
90 return notify_fail(str+": Destructed whilst created.\n"), 0;
91
92 /* try to move the object to my environment */
93 if ((ob->move(this_object(),M_GET)>0) ||
94 (ob->move(environment(),M_NOCHECK)>0))
95 {
96 if (!objectp(ob))
97 return notify_fail(str+": Destructed whilst created.\n"), 0;
98 write("Cloned "+object_name(ob)+".\n");
99 say(this_player()->name(WER,1) + " "
100 + this_player()->QueryProp(P_CLONE_MSG)+".\n");
101 return 1;
102 }
103 say(this_player()->name(WER,1)+" malt wilde Zeichen in die Luft und "
104 +"murmelt vor sich hin, aber nichts passiert...\n");
105 destruct(ob);
106 write(clone_file+": failed to move\n");
107 return 1;
108}
109
110/*
111 * "soft" means that the object is given the chance to self-destruct, thus
112 * allowing it to do necessary cleanup like subtracting from the carried
113 * weight of the environment(). We call remove() in the object to be
114 * destructed.
115 */
116static int soft_destruct_object(string str)
117{
118 object ob;
119 object *obs;
120 string strWER,strWEN;
121
122 if (!(str=_unparsed_args())){
123 notify_fail("Usage: destruct <objectname>\n"); return 0;
124 }
125 strWER = lower_case(str);
126 obs = this_player()->find_obs(strWER,PUT_GET_NONE);
127 if (!obs || !sizeof(obs)) {
128 notify_fail("Kein \"" + str + "\" gefunden.\n");
129 return 0;
130 }
131 ob=obs[0];
132 strWER=ob->name(WER);
133 strWEN=ob->name(WEN);
134 if (!strWER)
135 strWER="jemand";
136 if (!strWEN)
137 strWEN="jemanden";
138
139 if (ob->remove() == 0) {
140 notify_fail(strWER+" will nicht 'destructed' werden!\n");
141 say(this_player()->name(WER,1)+" versucht vergeblich, "+strWEN+
142 " zu atomisieren.\n");
143 return 0;
144 }
145 say(capitalize(strWER)+" "+this_player()->QueryProp(P_DESTRUCT_MSG)+".\n");
146 write(capitalize(strWER)+" wird von dir zerstaeubt.\n");
147 return 1;
148}
149
150static int destruct_object(string str)
151{
152 object ob;
153 object *obs;
154 string strWER,strWEN;
155
156 if (!(str=_unparsed_args())) {
157 notify_fail("Usage: Destruct <objectname>\n"); return 0;
158 }
159 strWER = lower_case(str);
160 obs = this_player()->find_obs(strWER,PUT_GET_NONE);
161 if (!obs || !sizeof(obs)) {
162 notify_fail("Kein \"" + str + "\" gefunden.\n"); return 0;
163 }
164 ob=obs[0];
165 strWER=ob->name(WER);
166 strWEN=ob->name(WEN);
167
168 say(capitalize(strWER)+" "+this_player()->QueryProp(P_DESTRUCT_MSG)+".\n");
169 destruct( ob );
170 write(capitalize(strWER)+" wird von dir zerstaeubt.\n");
171 return 1;
172}
173
174static int load(string str)
175{
176 object env;
177 string file;
178 string err;
179
180 if (!(str=_unparsed_args())) {
181 notify_fail("Usage: load <object_path>\n"); return 0;
182 }
183 file = find_file(str,".c");
184 if (!file) file=find_file(str);
185 if (!file) {
186 notify_fail(str+": No such file.\n"); return 0;
187 }
188 if ( err = catch(load_object(file);publish) )
189 printf("Cannot load %O, err = %O\n",file,err);
190 else write(file+"\n");
191 return 1;
192}
193
194static int exec_playerob(string name)
195{
196 object ob, *inv;
197 int i;
198
199 if (!IS_LORD(this_object())) return 0;
200 if (this_player() != this_interactive()) return 0;
201 if (this_player() != this_object()) return 0;
202 if (!(name=_unparsed_args())) return 0;
203 name="secure/master"->_get_path(name,getuid(this_object()));
204 if (catch(load_object(name);publish) )
205 {
206 write("BUG in "+name+"\n");
207 return 1;
208 }
209 ob=clone_object(name);
210 if (!ob) return 0;
211 if (getuid(ob) != getuid(this_object()))
212 {
213 write("UID conflict.\n");
214 destruct(ob);
215 return 1;
216 }
217 log_file("EXEC", getuid(this_object())+" "+name+" "+dtime(time()));
218 disable_commands();
219 exec(ob,this_object());
220 if (interactive(this_object()) || !interactive(ob))
221 {
222 enable_commands();
223 write("Fehler in exec\n");
224 return 1;
225 }
226 inv=all_inventory(this_object());
227 ob->start_player(capitalize(getuid(this_object())));
228 remove();
229 return 1;
230}
231
232static mixed _query_localcmds()
233{
234 return ({
235 ({"clone","clone",0,WIZARD_LVL}),
236 ({"destruct","soft_destruct_object",0,LEARNER_LVL}),
237 ({"Destruct","destruct_object",0,LEARNER_LVL}),
238 ({"load","load",0,WIZARD_LVL}),
239 ({"update","soft_update_object",0,LEARNER_LVL}),
240 ({"Update","update_object",0,LEARNER_LVL}),
241 ({"exec","exec_playerob",0,LEARNER_LVL})
242 });
243}