blob: 4d99b3278b85693e74e81d405844d6844c76d750 [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>
22
23private mixed verfolger()
24{
25 mixed *pur;
26
27 if (!pointerp(pur=QueryProp(P_PURSUERS))) return 0;
28 else return pur[0];
29}
30
31// #########
32//########################## IN+AT ############################
33// #########
34
35static int _move_base(object target, object old_room, string cmd)
36{
37 if (environment()!=target)
38 if (IS_ARCH(this_object()))
39 {
40 __set_environment(this_object(),target);
41 printf("%s: Bewegung hat nicht geklappt. Versuche es mit "
42 "set_environment... %s.\n.",query_verb(),
43 environment()==target?"hat geklappt":"erfolglos");
44 }
45 else
46 printf("%s: Bewegung hat nicht geklappt.\n",query_verb());
47 if (environment()!=target) return 1;
48 command(cmd);
49 if (old_room) move_object(old_room);
50 else
51 return printf("%s: Ursprungsraum wurde zerstoert.\n",query_verb()),1;
52 if (environment()!=old_room)
53 {
54 if (IS_ARCH(this_object()))
55 {
56 __set_environment(this_object(),old_room);
57 printf("%s: Zurueckbewegen hat nicht geklappt. Versuche es mit "
58 "set_environment ... %s.\n",query_verb(),
59 environment()==old_room?"hat geklappt":"erfolglos");
60 }
61 else
62 printf("at: Zurueckbewegen hat nicht geklappt.\n");
63 }
64 return 1;
65}
66
67static int _in_room(string str)
68{
69 string room;int size;
70 object old_room;
71 string cmd,err;
72
73 if (!sizeof(str=_unparsed_args()) ||
74 !sizeof(str=regreplace(str,"^ *","",1)) ||
75 sscanf(str, "%s %s", room, cmd) != 2)
76 return USAGE("in <raum> <befehl>\n");
77 old_room = environment();
Zesstra876b0d62018-11-08 20:52:22 +010078 room=normalize_path(room, getuid(), 1);
MG Mud User88f12472016-06-24 23:31:02 +020079 if (err=catch(move_object(room)))
80 {
Zesstra5485d162018-11-08 20:51:27 +010081 if (catch(size=file_size(room+".c"))||size < 0)
MG Mud User88f12472016-06-24 23:31:02 +020082 printf("%s: %s.c: Datei nicht vorhanden.\n",query_verb(),room);
83 else
84 printf("%s: Bewegung nach %s hat nicht funktioniert: %s\n",
85 query_verb(),room,err);
86 return 1;
87 }
88 return _move_base(find_object(room),old_room,cmd);
89}
90
91static int _at_player(string dest)
92{
93 object ob,old_room;
94 mixed tmp;
95 string cmd;
96
97 if (!sizeof(dest=_unparsed_args()) ||
98 !sizeof(dest=regreplace(dest,"^ *","",1)) ||
99 sscanf(dest, "%s %s", dest, cmd) != 2)
100 return USAGE("at <lebewesen> <befehl>\n");
101 if (!(ob=find_living(dest)))
102 {
103 tmp=match_living(dest,1);
104 if (stringp(tmp)) ob = find_living(tmp);
105 }
106 if (!ob||!(ob=environment(ob)))
107 return _notify_fail(sprintf("at: Lebewesen \'%s\' nicht gefunden.\n",
108 dest)),0;
109 old_room=environment();
110 move_object(ob);
111 return _move_base(ob,old_room,cmd);
112}
113
114// ########
115//############################ GOTO ############################
116// ########
117
118static object find_living_nr(string str)
119{ string name,check;
120 int nr;
121 object*livings;
122 if(sscanf(str,"%s %d%s",name,nr,check)<2||sizeof(check))
123 return find_living(str);
124 if(!sizeof(livings=filter((find_livings(name)||({})),#'environment))
125 ||nr<1||sizeof(livings)<nr)
126 return 0;
127 return livings[nr-1];
128}
129
130static int _goto(string dest){
131 mixed target;
132 string target2,err;
133
134 if (!sizeof(dest=_unparsed_args()))
135 return USAGE("goto [lebewesen|filename]\n");
136 if (!((target=find_living_nr(dest)) && (target=environment(target))))
137 {
Zesstra876b0d62018-11-08 20:52:22 +0100138 target2=target=normalize_path(dest, getuid(), 1);
MG Mud User88f12472016-06-24 23:31:02 +0200139 if (!find_object(target))
140 {
Zesstra5485d162018-11-08 20:51:27 +0100141 // ggf. .c dranhaengen
MG Mud User88f12472016-06-24 23:31:02 +0200142 if (target2[<2..<1]!=".c") target2+=".c";
143 notify_fail(sprintf("goto: Datei %O nicht vorhanden.\n",target));
144 if (!(file_size(target2)>-1||
145 file_size(implode(explode(target,"/")[0..<2],"/")+
Zesstra5485d162018-11-08 20:51:27 +0100146 "/virtual_compiler.c")>-1)||(err=catch(load_object(target))))
MG Mud User88f12472016-06-24 23:31:02 +0200147 {
148 if (err)
149 notify_fail(sprintf("goto: Fehler beim Teleport nach %O:\n%s\n",
150 dest,implode(explode(err,"\n")," ")));
151 target=match_living(dest,1);
152 if (!(stringp(target)&&(target=find_living(target))&&
153 (target=environment(target))))
154 return 0;
155 }
156 }
157 }
158 if (verfolger()) _verfolge("");
159 if (move(target,M_TPORT|M_NOCHECK)<0)
160 printf("Bewegung fehlgeschlagen!\n");
161 return 1;
162}
163
164// ########
165//############################ HOME ############################
166// ########
167
168static int _home()
169{
170 string dest;
171 if (verfolger()) _verfolge("");
172 dest="/players/" + getuid() + "/workroom";
Zesstra5485d162018-11-08 20:51:27 +0100173 if (file_size(dest+".c")<0||catch(load_object(dest)))
MG Mud User88f12472016-06-24 23:31:02 +0200174 {
175 printf("Fehler beim Laden Deines Workrooms.\n"
176 "Gehe zum Magiertreff.\n");
177 dest="/secure/merlin";
178 }
Zesstra5485d162018-11-08 20:51:27 +0100179
MG Mud User88f12472016-06-24 23:31:02 +0200180 if (move(dest,M_TPORT|M_NOCHECK)<0)
181 printf("Bewegung fehlgeschlagen!\n");
182 return 1;
183}
184
185// ###############
186//######################### +MAGIERNAME ##########################
187// ###############
188
189static int _go_wiz_home(string str)
190{
191 _notify_fail("Syntax: '+magiername'\n");
192 if(sizeof(query_verb())>1) str=query_verb()[1..];
193 if(!sizeof(str)) return 0;
194 if(query_verb()[0]!='+') return 0;
195 str=(old_explode(str," ")-({0}))[0];
196 if(!sizeof(str)) return 0;
197 str=lower_case(str);
198 if (str=="merlin")
199 {
200 move("/secure/merlin",M_TPORT|M_NOCHECK);
201 return 1;
202 }
Zesstra434c7302020-01-21 21:09:13 +0100203 if (!IS_LEARNER(str))
MG Mud User88f12472016-06-24 23:31:02 +0200204 {
205 printf("Es gibt keinen Magier namens %s.\n",
206 capitalize(str));
207 return 1;
208 }
Zesstra5485d162018-11-08 20:51:27 +0100209 if (file_size("/players/"+str+"/workroom.c")<0)
MG Mud User88f12472016-06-24 23:31:02 +0200210 {
211 printf("%s hat keinen Workroom.\n",capitalize(str));
212 return 1;
213 }
Zesstra5485d162018-11-08 20:51:27 +0100214 if (catch(load_object("/players/"+str+"/workroom")))
MG Mud User88f12472016-06-24 23:31:02 +0200215 {
216 printf("Der Workroom von %s hat Fehler.\n",capitalize(str));
217 return 1;
218 }
219 move("/players/"+str+"/workroom",M_TPORT|M_NOCHECK);
220 return 1;
221}
222
223
224static mixed _query_localcmds()
225{
226 return
227 ({({"goto","_goto",0,LEARNER_LVL}),
228 ({"in","_in_room",0,LEARNER_LVL}),
229 ({"at","_at_player",0,LEARNER_LVL}),
230 ({"home","_home",0,WIZARD_LVL}),
231 ({"+","_go_wiz_home",1,LEARNER_LVL})});
232}