blob: bb427180ef56d2cf8ad0b6b28054779823b72d73 [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");
Bugfixa992fe02022-01-07 22:00:59 +0100138 // Zuerst nur Spieler suchen, wenn keine existieren auch andere Livings.
139 target = (find_player(dest) || find_living_nr(dest));
140 if(objectp(target) && environment(target))
MG Mud User88f12472016-06-24 23:31:02 +0200141 {
Bugfixa992fe02022-01-07 22:00:59 +0100142 target = environment(target);
MG Mud User88f12472016-06-24 23:31:02 +0200143 }
Bugfixa992fe02022-01-07 22:00:59 +0100144 else
145 {
146 // Kein passendes Living, jetzt Raeume suchen.
147 string target2;
148 target2 = target = normalize_path(dest, getuid(), 1);
149 if (!find_object(target))
150 {
151 // ggf. .c dranhaengen
152 if (target2[<2..<1]!=".c") target2+=".c";
153 notify_fail(sprintf("goto: Datei %O nicht vorhanden.\n",target));
154 // Erst schauen, ob die Datei existiert, falls nicht pruefen, ob im
155 // gleichen Verzeichnis ein VC vorhanden ist, der sie liefern koennte.
156 // Die Ueberpruefung ob das File moeglicherweise Ladbar sein koennte
157 // vor load_object() dient einer spezifischeren Fehlermeldung.
158 // Die Variable vc dient nur dazu, weniger Zeilenumbrueche in
159 // der if-Abfrage zu haben und sie damit besser lesbar zu machen.
160 string vc;
161 vc = implode(explode(target, "/")[0..<2], "/") + "/virtual_compiler.c";
162 if(file_size(target2) > FSIZE_NOFILE ||
163 (file_size(vc) > FSIZE_NOFILE) &&
164 ({int})vc->QueryValidObject(target2))
165 {
166 string err = catch(load_object(target));
167 if(stringp(err))
168 {
169 notify_fail(sprintf("goto: Fehler beim Teleport nach %O:\n%s\n",
170 dest,implode(explode(err,"\n")," ")));
171 }
172 }
173 else
174 {
175 // Kein Ziel gefunden.
176 return 0;
177 }
178 }
179 }
180 if(!target)
181 return 0;
MG Mud User88f12472016-06-24 23:31:02 +0200182 if (verfolger()) _verfolge("");
Bugfixa992fe02022-01-07 22:00:59 +0100183 if (move(target,M_TPORT|M_NOCHECK) != MOVE_OK)
MG Mud User88f12472016-06-24 23:31:02 +0200184 printf("Bewegung fehlgeschlagen!\n");
185 return 1;
186}
187
188// ########
189//############################ HOME ############################
190// ########
191
192static int _home()
193{
194 string dest;
195 if (verfolger()) _verfolge("");
196 dest="/players/" + getuid() + "/workroom";
Zesstra5485d162018-11-08 20:51:27 +0100197 if (file_size(dest+".c")<0||catch(load_object(dest)))
MG Mud User88f12472016-06-24 23:31:02 +0200198 {
199 printf("Fehler beim Laden Deines Workrooms.\n"
200 "Gehe zum Magiertreff.\n");
201 dest="/secure/merlin";
202 }
Zesstra5485d162018-11-08 20:51:27 +0100203
MG Mud User88f12472016-06-24 23:31:02 +0200204 if (move(dest,M_TPORT|M_NOCHECK)<0)
205 printf("Bewegung fehlgeschlagen!\n");
206 return 1;
207}
208
209// ###############
210//######################### +MAGIERNAME ##########################
211// ###############
212
213static int _go_wiz_home(string str)
214{
215 _notify_fail("Syntax: '+magiername'\n");
216 if(sizeof(query_verb())>1) str=query_verb()[1..];
217 if(!sizeof(str)) return 0;
218 if(query_verb()[0]!='+') return 0;
219 str=(old_explode(str," ")-({0}))[0];
220 if(!sizeof(str)) return 0;
221 str=lower_case(str);
222 if (str=="merlin")
223 {
224 move("/secure/merlin",M_TPORT|M_NOCHECK);
225 return 1;
226 }
Zesstra434c7302020-01-21 21:09:13 +0100227 if (!IS_LEARNER(str))
MG Mud User88f12472016-06-24 23:31:02 +0200228 {
229 printf("Es gibt keinen Magier namens %s.\n",
230 capitalize(str));
231 return 1;
232 }
Zesstra5485d162018-11-08 20:51:27 +0100233 if (file_size("/players/"+str+"/workroom.c")<0)
MG Mud User88f12472016-06-24 23:31:02 +0200234 {
235 printf("%s hat keinen Workroom.\n",capitalize(str));
236 return 1;
237 }
Zesstra5485d162018-11-08 20:51:27 +0100238 if (catch(load_object("/players/"+str+"/workroom")))
MG Mud User88f12472016-06-24 23:31:02 +0200239 {
240 printf("Der Workroom von %s hat Fehler.\n",capitalize(str));
241 return 1;
242 }
243 move("/players/"+str+"/workroom",M_TPORT|M_NOCHECK);
244 return 1;
245}
246
247
248static mixed _query_localcmds()
249{
250 return
251 ({({"goto","_goto",0,LEARNER_LVL}),
252 ({"in","_in_room",0,LEARNER_LVL}),
253 ({"at","_at_player",0,LEARNER_LVL}),
254 ({"home","_home",0,WIZARD_LVL}),
255 ({"+","_go_wiz_home",1,LEARNER_LVL})});
256}