blob: ccb5535b3cd0d8fbd53011de59b7a846c2a5170c [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
10#pragma pedantic
11
Zesstra876b0d62018-11-08 20:52:22 +010012protected functions virtual inherit "/std/util/path";
13
MG Mud User88f12472016-06-24 23:31:02 +020014#define NEED_PROTOTYPES
15#include <magier.h>
16#include <thing/properties.h>
17#include <living/moving.h>
18#include <player.h>
19#undef NEED_PROTOTYPES
20#include <wizlevels.h>
21#include <moving.h>
22#include <properties.h>
23
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
131static int _goto(string dest){
132 mixed target;
133 string target2,err;
134
135 if (!sizeof(dest=_unparsed_args()))
136 return USAGE("goto [lebewesen|filename]\n");
137 if (!((target=find_living_nr(dest)) && (target=environment(target))))
138 {
Zesstra876b0d62018-11-08 20:52:22 +0100139 target2=target=normalize_path(dest, getuid(), 1);
MG Mud User88f12472016-06-24 23:31:02 +0200140 if (!find_object(target))
141 {
Zesstra5485d162018-11-08 20:51:27 +0100142 // ggf. .c dranhaengen
MG Mud User88f12472016-06-24 23:31:02 +0200143 if (target2[<2..<1]!=".c") target2+=".c";
144 notify_fail(sprintf("goto: Datei %O nicht vorhanden.\n",target));
145 if (!(file_size(target2)>-1||
146 file_size(implode(explode(target,"/")[0..<2],"/")+
Zesstra5485d162018-11-08 20:51:27 +0100147 "/virtual_compiler.c")>-1)||(err=catch(load_object(target))))
MG Mud User88f12472016-06-24 23:31:02 +0200148 {
149 if (err)
150 notify_fail(sprintf("goto: Fehler beim Teleport nach %O:\n%s\n",
151 dest,implode(explode(err,"\n")," ")));
152 target=match_living(dest,1);
153 if (!(stringp(target)&&(target=find_living(target))&&
154 (target=environment(target))))
155 return 0;
156 }
157 }
158 }
159 if (verfolger()) _verfolge("");
160 if (move(target,M_TPORT|M_NOCHECK)<0)
161 printf("Bewegung fehlgeschlagen!\n");
162 return 1;
163}
164
165// ########
166//############################ HOME ############################
167// ########
168
169static int _home()
170{
171 string dest;
172 if (verfolger()) _verfolge("");
173 dest="/players/" + getuid() + "/workroom";
Zesstra5485d162018-11-08 20:51:27 +0100174 if (file_size(dest+".c")<0||catch(load_object(dest)))
MG Mud User88f12472016-06-24 23:31:02 +0200175 {
176 printf("Fehler beim Laden Deines Workrooms.\n"
177 "Gehe zum Magiertreff.\n");
178 dest="/secure/merlin";
179 }
Zesstra5485d162018-11-08 20:51:27 +0100180
MG Mud User88f12472016-06-24 23:31:02 +0200181 if (move(dest,M_TPORT|M_NOCHECK)<0)
182 printf("Bewegung fehlgeschlagen!\n");
183 return 1;
184}
185
186// ###############
187//######################### +MAGIERNAME ##########################
188// ###############
189
190static int _go_wiz_home(string str)
191{
192 _notify_fail("Syntax: '+magiername'\n");
193 if(sizeof(query_verb())>1) str=query_verb()[1..];
194 if(!sizeof(str)) return 0;
195 if(query_verb()[0]!='+') return 0;
196 str=(old_explode(str," ")-({0}))[0];
197 if(!sizeof(str)) return 0;
198 str=lower_case(str);
199 if (str=="merlin")
200 {
201 move("/secure/merlin",M_TPORT|M_NOCHECK);
202 return 1;
203 }
204 if ((!call_other(master(),"get_userinfo",str))||
205 !IS_LEARNER(str))
206 {
207 printf("Es gibt keinen Magier namens %s.\n",
208 capitalize(str));
209 return 1;
210 }
Zesstra5485d162018-11-08 20:51:27 +0100211 if (file_size("/players/"+str+"/workroom.c")<0)
MG Mud User88f12472016-06-24 23:31:02 +0200212 {
213 printf("%s hat keinen Workroom.\n",capitalize(str));
214 return 1;
215 }
Zesstra5485d162018-11-08 20:51:27 +0100216 if (catch(load_object("/players/"+str+"/workroom")))
MG Mud User88f12472016-06-24 23:31:02 +0200217 {
218 printf("Der Workroom von %s hat Fehler.\n",capitalize(str));
219 return 1;
220 }
221 move("/players/"+str+"/workroom",M_TPORT|M_NOCHECK);
222 return 1;
223}
224
225
226static mixed _query_localcmds()
227{
228 return
229 ({({"goto","_goto",0,LEARNER_LVL}),
230 ({"in","_in_room",0,LEARNER_LVL}),
231 ({"at","_at_player",0,LEARNER_LVL}),
232 ({"home","_home",0,WIZARD_LVL}),
233 ({"+","_go_wiz_home",1,LEARNER_LVL})});
234}