blob: 3095a3f9fabd378588ecc75f6d94960272080f0c [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
12#define NEED_PROTOTYPES
13#include <magier.h>
14#include <thing/properties.h>
15#include <living/moving.h>
16#include <player.h>
17#undef NEED_PROTOTYPES
18#include <wizlevels.h>
19#include <moving.h>
20#include <properties.h>
21
22private mixed verfolger()
23{
24 mixed *pur;
25
26 if (!pointerp(pur=QueryProp(P_PURSUERS))) return 0;
27 else return pur[0];
28}
29
30// #########
31//########################## IN+AT ############################
32// #########
33
34static int _move_base(object target, object old_room, string cmd)
35{
36 if (environment()!=target)
37 if (IS_ARCH(this_object()))
38 {
39 __set_environment(this_object(),target);
40 printf("%s: Bewegung hat nicht geklappt. Versuche es mit "
41 "set_environment... %s.\n.",query_verb(),
42 environment()==target?"hat geklappt":"erfolglos");
43 }
44 else
45 printf("%s: Bewegung hat nicht geklappt.\n",query_verb());
46 if (environment()!=target) return 1;
47 command(cmd);
48 if (old_room) move_object(old_room);
49 else
50 return printf("%s: Ursprungsraum wurde zerstoert.\n",query_verb()),1;
51 if (environment()!=old_room)
52 {
53 if (IS_ARCH(this_object()))
54 {
55 __set_environment(this_object(),old_room);
56 printf("%s: Zurueckbewegen hat nicht geklappt. Versuche es mit "
57 "set_environment ... %s.\n",query_verb(),
58 environment()==old_room?"hat geklappt":"erfolglos");
59 }
60 else
61 printf("at: Zurueckbewegen hat nicht geklappt.\n");
62 }
63 return 1;
64}
65
66static int _in_room(string str)
67{
68 string room;int size;
69 object old_room;
70 string cmd,err;
71
72 if (!sizeof(str=_unparsed_args()) ||
73 !sizeof(str=regreplace(str,"^ *","",1)) ||
74 sscanf(str, "%s %s", room, cmd) != 2)
75 return USAGE("in <raum> <befehl>\n");
76 old_room = environment();
77 room=(string)call_other(master(),"_get_path",room,getuid());
78 if (err=catch(move_object(room)))
79 {
80 if (catch(size=file_size(room+".c"))||size<1)
81 printf("%s: %s.c: Datei nicht vorhanden.\n",query_verb(),room);
82 else
83 printf("%s: Bewegung nach %s hat nicht funktioniert: %s\n",
84 query_verb(),room,err);
85 return 1;
86 }
87 return _move_base(find_object(room),old_room,cmd);
88}
89
90static int _at_player(string dest)
91{
92 object ob,old_room;
93 mixed tmp;
94 string cmd;
95
96 if (!sizeof(dest=_unparsed_args()) ||
97 !sizeof(dest=regreplace(dest,"^ *","",1)) ||
98 sscanf(dest, "%s %s", dest, cmd) != 2)
99 return USAGE("at <lebewesen> <befehl>\n");
100 if (!(ob=find_living(dest)))
101 {
102 tmp=match_living(dest,1);
103 if (stringp(tmp)) ob = find_living(tmp);
104 }
105 if (!ob||!(ob=environment(ob)))
106 return _notify_fail(sprintf("at: Lebewesen \'%s\' nicht gefunden.\n",
107 dest)),0;
108 old_room=environment();
109 move_object(ob);
110 return _move_base(ob,old_room,cmd);
111}
112
113// ########
114//############################ GOTO ############################
115// ########
116
117static object find_living_nr(string str)
118{ string name,check;
119 int nr;
120 object*livings;
121 if(sscanf(str,"%s %d%s",name,nr,check)<2||sizeof(check))
122 return find_living(str);
123 if(!sizeof(livings=filter((find_livings(name)||({})),#'environment))
124 ||nr<1||sizeof(livings)<nr)
125 return 0;
126 return livings[nr-1];
127}
128
129static int _goto(string dest){
130 mixed target;
131 string target2,err;
132
133 if (!sizeof(dest=_unparsed_args()))
134 return USAGE("goto [lebewesen|filename]\n");
135 if (!((target=find_living_nr(dest)) && (target=environment(target))))
136 {
137 target2=target=(mixed)call_other(master(),"_get_path",dest,getuid());
138 if (!find_object(target))
139 {
140 if (target2[<1]=='.') target2+="c";
141 if (target2[<2..<1]!=".c") target2+=".c";
142 notify_fail(sprintf("goto: Datei %O nicht vorhanden.\n",target));
143 if (!(file_size(target2)>-1||
144 file_size(implode(explode(target,"/")[0..<2],"/")+
145 "/virtual_compiler.c")>-1)||(err=catch(call_other(target,"?"))))
146 {
147 if (err)
148 notify_fail(sprintf("goto: Fehler beim Teleport nach %O:\n%s\n",
149 dest,implode(explode(err,"\n")," ")));
150 target=match_living(dest,1);
151 if (!(stringp(target)&&(target=find_living(target))&&
152 (target=environment(target))))
153 return 0;
154 }
155 }
156 }
157 if (verfolger()) _verfolge("");
158 if (move(target,M_TPORT|M_NOCHECK)<0)
159 printf("Bewegung fehlgeschlagen!\n");
160 return 1;
161}
162
163// ########
164//############################ HOME ############################
165// ########
166
167static int _home()
168{
169 string dest;
170 if (verfolger()) _verfolge("");
171 dest="/players/" + getuid() + "/workroom";
172 if (file_size(dest+".c")<1||catch(call_other(dest,"???")))
173 {
174 printf("Fehler beim Laden Deines Workrooms.\n"
175 "Gehe zum Magiertreff.\n");
176 dest="/secure/merlin";
177 }
178
179 if (move(dest,M_TPORT|M_NOCHECK)<0)
180 printf("Bewegung fehlgeschlagen!\n");
181 return 1;
182}
183
184// ###############
185//######################### +MAGIERNAME ##########################
186// ###############
187
188static int _go_wiz_home(string str)
189{
190 _notify_fail("Syntax: '+magiername'\n");
191 if(sizeof(query_verb())>1) str=query_verb()[1..];
192 if(!sizeof(str)) return 0;
193 if(query_verb()[0]!='+') return 0;
194 str=(old_explode(str," ")-({0}))[0];
195 if(!sizeof(str)) return 0;
196 str=lower_case(str);
197 if (str=="merlin")
198 {
199 move("/secure/merlin",M_TPORT|M_NOCHECK);
200 return 1;
201 }
202 if ((!call_other(master(),"get_userinfo",str))||
203 !IS_LEARNER(str))
204 {
205 printf("Es gibt keinen Magier namens %s.\n",
206 capitalize(str));
207 return 1;
208 }
209 if (file_size("/players/"+str+"/workroom.c")<1)
210 {
211 printf("%s hat keinen Workroom.\n",capitalize(str));
212 return 1;
213 }
214 if (catch(call_other("/players/"+str+"/workroom","???")))
215 {
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}