blob: 4f756b99997763d9df7976e61e3eb80320b84eec [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// moving.c
4//
5// $Id: moving.c 9142 2015-02-04 22:17:29Z Zesstra $
6#pragma strict_types
7#pragma save_types
8#pragma range_check
9#pragma no_clone
MG Mud User88f12472016-06-24 23:31:02 +020010
Zesstra876b0d62018-11-08 20:52:22 +010011protected functions virtual inherit "/std/util/path";
12
MG Mud User88f12472016-06-24 23:31:02 +020013#define NEED_PROTOTYPES
14#include <magier.h>
15#include <thing/properties.h>
16#include <living/moving.h>
17#include <player.h>
18#undef NEED_PROTOTYPES
19#include <wizlevels.h>
20#include <moving.h>
21#include <properties.h>
Bugfixa992fe02022-01-07 22:00:59 +010022#include <files.h>
MG Mud User88f12472016-06-24 23:31:02 +020023
24private mixed verfolger()
25{
26 mixed *pur;
27
28 if (!pointerp(pur=QueryProp(P_PURSUERS))) return 0;
29 else return pur[0];
30}
31
32// #########
33//########################## IN+AT ############################
34// #########
35
36static int _move_base(object target, object old_room, string cmd)
37{
38 if (environment()!=target)
39 if (IS_ARCH(this_object()))
40 {
41 __set_environment(this_object(),target);
42 printf("%s: Bewegung hat nicht geklappt. Versuche es mit "
43 "set_environment... %s.\n.",query_verb(),
44 environment()==target?"hat geklappt":"erfolglos");
45 }
46 else
47 printf("%s: Bewegung hat nicht geklappt.\n",query_verb());
48 if (environment()!=target) return 1;
49 command(cmd);
50 if (old_room) move_object(old_room);
51 else
52 return printf("%s: Ursprungsraum wurde zerstoert.\n",query_verb()),1;
53 if (environment()!=old_room)
54 {
55 if (IS_ARCH(this_object()))
56 {
57 __set_environment(this_object(),old_room);
58 printf("%s: Zurueckbewegen hat nicht geklappt. Versuche es mit "
59 "set_environment ... %s.\n",query_verb(),
60 environment()==old_room?"hat geklappt":"erfolglos");
61 }
62 else
63 printf("at: Zurueckbewegen hat nicht geklappt.\n");
64 }
65 return 1;
66}
67
68static int _in_room(string str)
69{
70 string room;int size;
71 object old_room;
72 string cmd,err;
73
74 if (!sizeof(str=_unparsed_args()) ||
75 !sizeof(str=regreplace(str,"^ *","",1)) ||
76 sscanf(str, "%s %s", room, cmd) != 2)
77 return USAGE("in <raum> <befehl>\n");
78 old_room = environment();
Zesstra876b0d62018-11-08 20:52:22 +010079 room=normalize_path(room, getuid(), 1);
MG Mud User88f12472016-06-24 23:31:02 +020080 if (err=catch(move_object(room)))
81 {
Zesstra5485d162018-11-08 20:51:27 +010082 if (catch(size=file_size(room+".c"))||size < 0)
MG Mud User88f12472016-06-24 23:31:02 +020083 printf("%s: %s.c: Datei nicht vorhanden.\n",query_verb(),room);
84 else
85 printf("%s: Bewegung nach %s hat nicht funktioniert: %s\n",
86 query_verb(),room,err);
87 return 1;
88 }
89 return _move_base(find_object(room),old_room,cmd);
90}
91
92static int _at_player(string dest)
93{
94 object ob,old_room;
95 mixed tmp;
96 string cmd;
97
98 if (!sizeof(dest=_unparsed_args()) ||
99 !sizeof(dest=regreplace(dest,"^ *","",1)) ||
100 sscanf(dest, "%s %s", dest, cmd) != 2)
101 return USAGE("at <lebewesen> <befehl>\n");
102 if (!(ob=find_living(dest)))
103 {
104 tmp=match_living(dest,1);
105 if (stringp(tmp)) ob = find_living(tmp);
106 }
107 if (!ob||!(ob=environment(ob)))
108 return _notify_fail(sprintf("at: Lebewesen \'%s\' nicht gefunden.\n",
109 dest)),0;
110 old_room=environment();
111 move_object(ob);
112 return _move_base(ob,old_room,cmd);
113}
114
115// ########
116//############################ GOTO ############################
117// ########
118
119static object find_living_nr(string str)
120{ string name,check;
121 int nr;
122 object*livings;
123 if(sscanf(str,"%s %d%s",name,nr,check)<2||sizeof(check))
124 return find_living(str);
125 if(!sizeof(livings=filter((find_livings(name)||({})),#'environment))
126 ||nr<1||sizeof(livings)<nr)
127 return 0;
128 return livings[nr-1];
129}
130
Bugfixa992fe02022-01-07 22:00:59 +0100131static int _goto(string dest)
132{
133 string|object target;
MG Mud User88f12472016-06-24 23:31:02 +0200134
Bugfixa992fe02022-01-07 22:00:59 +0100135 dest = _unparsed_args();
136 if(!sizeof(dest))
MG Mud User88f12472016-06-24 23:31:02 +0200137 return USAGE("goto [lebewesen|filename]\n");
Bugfix1bb96a22022-01-07 20:41:56 +0100138 int flags;
139 dest = parseargs(dest, &flags, GOTO_OPTS, 0)[0];
140 if((flags & GOTO_L) && (flags & GOTO_R))
MG Mud User88f12472016-06-24 23:31:02 +0200141 {
Bugfix1bb96a22022-01-07 20:41:56 +0100142 notify_fail(
143 "goto: -r und -l koennen nicht gleichzeitig verwendet werden.\n");
144 return 0;
MG Mud User88f12472016-06-24 23:31:02 +0200145 }
Bugfix1bb96a22022-01-07 20:41:56 +0100146 if(!(flags & GOTO_R))
147 {
148 // Zuerst nur Spieler suchen, wenn keine existieren auch andere Livings.
149 object lv = (find_player(dest) || find_living_nr(dest));
150 if(objectp(lv) && environment(lv))
151 {
152 target = environment(lv);
153 }
154 else
155 {
156 notify_fail(
157 "goto: Kein Lebewesen mit dem Namen " + dest + " gefunden.\n");
158 }
159 }
160 if(!(flags & GOTO_L) && !target)
Bugfixa992fe02022-01-07 22:00:59 +0100161 {
162 // Kein passendes Living, jetzt Raeume suchen.
Bugfix1bb96a22022-01-07 20:41:56 +0100163 string path = normalize_path(dest, getuid(), 1);
164 target = find_object(path);
165 if(!target)
Bugfixa992fe02022-01-07 22:00:59 +0100166 {
Bugfix1bb96a22022-01-07 20:41:56 +0100167 notify_fail(sprintf("goto: Datei %O nicht vorhanden.\n",path));
Bugfixa992fe02022-01-07 22:00:59 +0100168 // ggf. .c dranhaengen
Bugfix1bb96a22022-01-07 20:41:56 +0100169 if (path[<2..<1]!=".c") path+=".c";
Bugfixa992fe02022-01-07 22:00:59 +0100170 // Erst schauen, ob die Datei existiert, falls nicht pruefen, ob im
171 // gleichen Verzeichnis ein VC vorhanden ist, der sie liefern koennte.
172 // Die Ueberpruefung ob das File moeglicherweise Ladbar sein koennte
173 // vor load_object() dient einer spezifischeren Fehlermeldung.
174 // Die Variable vc dient nur dazu, weniger Zeilenumbrueche in
175 // der if-Abfrage zu haben und sie damit besser lesbar zu machen.
176 string vc;
Bugfix1bb96a22022-01-07 20:41:56 +0100177 vc = implode(explode(path, "/")[0..<2], "/") + "/virtual_compiler.c";
178 if(file_size(path) > FSIZE_NOFILE ||
Bugfixa992fe02022-01-07 22:00:59 +0100179 (file_size(vc) > FSIZE_NOFILE) &&
Bugfix1bb96a22022-01-07 20:41:56 +0100180 ({int})vc->QueryValidObject(path))
Bugfixa992fe02022-01-07 22:00:59 +0100181 {
Bugfix1bb96a22022-01-07 20:41:56 +0100182 string err = catch(target = load_object(path));
Bugfixa992fe02022-01-07 22:00:59 +0100183 if(stringp(err))
184 {
185 notify_fail(sprintf("goto: Fehler beim Teleport nach %O:\n%s\n",
186 dest,implode(explode(err,"\n")," ")));
187 }
188 }
189 else
190 {
191 // Kein Ziel gefunden.
192 return 0;
193 }
194 }
195 }
196 if(!target)
197 return 0;
MG Mud User88f12472016-06-24 23:31:02 +0200198 if (verfolger()) _verfolge("");
Bugfixa992fe02022-01-07 22:00:59 +0100199 if (move(target,M_TPORT|M_NOCHECK) != MOVE_OK)
MG Mud User88f12472016-06-24 23:31:02 +0200200 printf("Bewegung fehlgeschlagen!\n");
201 return 1;
202}
203
204// ########
205//############################ HOME ############################
206// ########
207
208static int _home()
209{
210 string dest;
211 if (verfolger()) _verfolge("");
212 dest="/players/" + getuid() + "/workroom";
Zesstra5485d162018-11-08 20:51:27 +0100213 if (file_size(dest+".c")<0||catch(load_object(dest)))
MG Mud User88f12472016-06-24 23:31:02 +0200214 {
215 printf("Fehler beim Laden Deines Workrooms.\n"
216 "Gehe zum Magiertreff.\n");
217 dest="/secure/merlin";
218 }
Zesstra5485d162018-11-08 20:51:27 +0100219
MG Mud User88f12472016-06-24 23:31:02 +0200220 if (move(dest,M_TPORT|M_NOCHECK)<0)
221 printf("Bewegung fehlgeschlagen!\n");
222 return 1;
223}
224
225// ###############
226//######################### +MAGIERNAME ##########################
227// ###############
228
229static int _go_wiz_home(string str)
230{
231 _notify_fail("Syntax: '+magiername'\n");
232 if(sizeof(query_verb())>1) str=query_verb()[1..];
233 if(!sizeof(str)) return 0;
234 if(query_verb()[0]!='+') return 0;
235 str=(old_explode(str," ")-({0}))[0];
236 if(!sizeof(str)) return 0;
237 str=lower_case(str);
238 if (str=="merlin")
239 {
240 move("/secure/merlin",M_TPORT|M_NOCHECK);
241 return 1;
242 }
Zesstra434c7302020-01-21 21:09:13 +0100243 if (!IS_LEARNER(str))
MG Mud User88f12472016-06-24 23:31:02 +0200244 {
245 printf("Es gibt keinen Magier namens %s.\n",
246 capitalize(str));
247 return 1;
248 }
Zesstra5485d162018-11-08 20:51:27 +0100249 if (file_size("/players/"+str+"/workroom.c")<0)
MG Mud User88f12472016-06-24 23:31:02 +0200250 {
251 printf("%s hat keinen Workroom.\n",capitalize(str));
252 return 1;
253 }
Zesstra5485d162018-11-08 20:51:27 +0100254 if (catch(load_object("/players/"+str+"/workroom")))
MG Mud User88f12472016-06-24 23:31:02 +0200255 {
256 printf("Der Workroom von %s hat Fehler.\n",capitalize(str));
257 return 1;
258 }
259 move("/players/"+str+"/workroom",M_TPORT|M_NOCHECK);
260 return 1;
261}
262
263
264static mixed _query_localcmds()
265{
266 return
267 ({({"goto","_goto",0,LEARNER_LVL}),
268 ({"in","_in_room",0,LEARNER_LVL}),
269 ({"at","_at_player",0,LEARNER_LVL}),
270 ({"home","_home",0,WIZARD_LVL}),
271 ({"+","_go_wiz_home",1,LEARNER_LVL})});
272}