MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 1 | // 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 10 | |
Zesstra | 876b0d6 | 2018-11-08 20:52:22 +0100 | [diff] [blame] | 11 | protected functions virtual inherit "/std/util/path"; |
| 12 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 13 | #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> |
Bugfix | a992fe0 | 2022-01-07 22:00:59 +0100 | [diff] [blame] | 22 | #include <files.h> |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 23 | |
| 24 | private 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 | |
| 36 | static 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 | |
| 68 | static 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(); |
Zesstra | 876b0d6 | 2018-11-08 20:52:22 +0100 | [diff] [blame] | 79 | room=normalize_path(room, getuid(), 1); |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 80 | if (err=catch(move_object(room))) |
| 81 | { |
Zesstra | 5485d16 | 2018-11-08 20:51:27 +0100 | [diff] [blame] | 82 | if (catch(size=file_size(room+".c"))||size < 0) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 83 | 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 | |
| 92 | static 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 | |
| 119 | static 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 | |
Bugfix | a992fe0 | 2022-01-07 22:00:59 +0100 | [diff] [blame] | 131 | static int _goto(string dest) |
| 132 | { |
| 133 | string|object target; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 134 | |
Bugfix | a992fe0 | 2022-01-07 22:00:59 +0100 | [diff] [blame] | 135 | dest = _unparsed_args(); |
| 136 | if(!sizeof(dest)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 137 | return USAGE("goto [lebewesen|filename]\n"); |
Bugfix | 1bb96a2 | 2022-01-07 20:41:56 +0100 | [diff] [blame] | 138 | int flags; |
| 139 | dest = parseargs(dest, &flags, GOTO_OPTS, 0)[0]; |
| 140 | if((flags & GOTO_L) && (flags & GOTO_R)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 141 | { |
Bugfix | 1bb96a2 | 2022-01-07 20:41:56 +0100 | [diff] [blame] | 142 | notify_fail( |
| 143 | "goto: -r und -l koennen nicht gleichzeitig verwendet werden.\n"); |
| 144 | return 0; |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 145 | } |
Bugfix | 1bb96a2 | 2022-01-07 20:41:56 +0100 | [diff] [blame] | 146 | 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) |
Bugfix | a992fe0 | 2022-01-07 22:00:59 +0100 | [diff] [blame] | 161 | { |
| 162 | // Kein passendes Living, jetzt Raeume suchen. |
Bugfix | 1bb96a2 | 2022-01-07 20:41:56 +0100 | [diff] [blame] | 163 | string path = normalize_path(dest, getuid(), 1); |
| 164 | target = find_object(path); |
| 165 | if(!target) |
Bugfix | a992fe0 | 2022-01-07 22:00:59 +0100 | [diff] [blame] | 166 | { |
Bugfix | 1bb96a2 | 2022-01-07 20:41:56 +0100 | [diff] [blame] | 167 | notify_fail(sprintf("goto: Datei %O nicht vorhanden.\n",path)); |
Bugfix | a992fe0 | 2022-01-07 22:00:59 +0100 | [diff] [blame] | 168 | // ggf. .c dranhaengen |
Bugfix | 1bb96a2 | 2022-01-07 20:41:56 +0100 | [diff] [blame] | 169 | if (path[<2..<1]!=".c") path+=".c"; |
Bugfix | a992fe0 | 2022-01-07 22:00:59 +0100 | [diff] [blame] | 170 | // 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; |
Bugfix | 1bb96a2 | 2022-01-07 20:41:56 +0100 | [diff] [blame] | 177 | vc = implode(explode(path, "/")[0..<2], "/") + "/virtual_compiler.c"; |
| 178 | if(file_size(path) > FSIZE_NOFILE || |
Bugfix | a992fe0 | 2022-01-07 22:00:59 +0100 | [diff] [blame] | 179 | (file_size(vc) > FSIZE_NOFILE) && |
Bugfix | 1bb96a2 | 2022-01-07 20:41:56 +0100 | [diff] [blame] | 180 | ({int})vc->QueryValidObject(path)) |
Bugfix | a992fe0 | 2022-01-07 22:00:59 +0100 | [diff] [blame] | 181 | { |
Bugfix | 1bb96a2 | 2022-01-07 20:41:56 +0100 | [diff] [blame] | 182 | string err = catch(target = load_object(path)); |
Bugfix | a992fe0 | 2022-01-07 22:00:59 +0100 | [diff] [blame] | 183 | 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 User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 198 | if (verfolger()) _verfolge(""); |
Bugfix | a992fe0 | 2022-01-07 22:00:59 +0100 | [diff] [blame] | 199 | if (move(target,M_TPORT|M_NOCHECK) != MOVE_OK) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 200 | printf("Bewegung fehlgeschlagen!\n"); |
| 201 | return 1; |
| 202 | } |
| 203 | |
| 204 | // ######## |
| 205 | //############################ HOME ############################ |
| 206 | // ######## |
| 207 | |
| 208 | static int _home() |
| 209 | { |
| 210 | string dest; |
| 211 | if (verfolger()) _verfolge(""); |
| 212 | dest="/players/" + getuid() + "/workroom"; |
Zesstra | 5485d16 | 2018-11-08 20:51:27 +0100 | [diff] [blame] | 213 | if (file_size(dest+".c")<0||catch(load_object(dest))) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 214 | { |
| 215 | printf("Fehler beim Laden Deines Workrooms.\n" |
| 216 | "Gehe zum Magiertreff.\n"); |
| 217 | dest="/secure/merlin"; |
| 218 | } |
Zesstra | 5485d16 | 2018-11-08 20:51:27 +0100 | [diff] [blame] | 219 | |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 220 | if (move(dest,M_TPORT|M_NOCHECK)<0) |
| 221 | printf("Bewegung fehlgeschlagen!\n"); |
| 222 | return 1; |
| 223 | } |
| 224 | |
| 225 | // ############### |
| 226 | //######################### +MAGIERNAME ########################## |
| 227 | // ############### |
| 228 | |
| 229 | static 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 | } |
Zesstra | 434c730 | 2020-01-21 21:09:13 +0100 | [diff] [blame] | 243 | if (!IS_LEARNER(str)) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 244 | { |
| 245 | printf("Es gibt keinen Magier namens %s.\n", |
| 246 | capitalize(str)); |
| 247 | return 1; |
| 248 | } |
Zesstra | 5485d16 | 2018-11-08 20:51:27 +0100 | [diff] [blame] | 249 | if (file_size("/players/"+str+"/workroom.c")<0) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 250 | { |
| 251 | printf("%s hat keinen Workroom.\n",capitalize(str)); |
| 252 | return 1; |
| 253 | } |
Zesstra | 5485d16 | 2018-11-08 20:51:27 +0100 | [diff] [blame] | 254 | if (catch(load_object("/players/"+str+"/workroom"))) |
MG Mud User | 88f1247 | 2016-06-24 23:31:02 +0200 | [diff] [blame] | 255 | { |
| 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 | |
| 264 | static 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 | } |