blob: 1fe19a4f3e6b9543bc3abe6d60da60e08748585d [file] [log] [blame]
MG Mud User88f12472016-06-24 23:31:02 +02001// MorgenGrauen MUDlib
2//
3// inpc/walking.c -- Intelligent herumlaufen
4//
5// $Id: walking.c 8755 2014-04-26 13:13:40Z Zesstra $
6#pragma strong_types
7#pragma save_types
8#pragma range_check
9#pragma no_clone
MG Mud User88f12472016-06-24 23:31:02 +020010
11#define NEED_PROTOTYPES
12#include <thing/properties.h>
13#include <thing.h>
14#undef NEED_PROTOTYPES
15
16#include <inpc.h>
17#include <properties.h>
18#include <moving.h>
19
20#define ME this_object()
21#define ENV environment()
22
23int _set_inpc_walk_delay(int del) {
24 if (del && del<5) del=5;
25 return Set(P_INPC_WALK_DELAYS,del);
26}
27
28mixed _query_inpc_home() {
29 mixed res;
30
31 res=Query(P_INPC_HOME);
32 if (!res) return "/room/void";
33 return res;
34}
35
36int area_check(string fn) {
37 mixed area;
38 string *words;
39 int i;
40
41 if (!(area=QueryProp(P_INPC_WALK_AREA)))
42 return 1; // Keine Beschraenkung im Gebiet?
43 if (mappingp(area)) {
44 if (area[fn])
45 return 1; // Explizit erlaubter Raum
46 words=old_explode(fn,"/");
47 for (i=sizeof(words)-2;i>=0;i--)
48 if (area[implode(words[0..i],"/")])
49 return 1; // Erlaubtes Gebiet
50 return 0; // Nicht erlaubtes Gebiet
51 }
52 if (pointerp(area)) {
53 for (i=sizeof(area)-1;i>=0;i--)
54 if (fn[0..(sizeof(area[i])-1)]==area[i])
55 return 1; // Erlaubtes Gebiet
56 return 0; // Nicht erlaubtes Gebiet
57 }
58 return 1;
59}
60
61int may_enter_room(mixed room) {
62 int flags;
63 string fn;
64 object ob;
65
66 if (objectp(room)) {
67 fn=object_name(room);
68 ob=room;
69 } else if (stringp(room)) {
70 fn=room;
71 ob=find_object(room);
72 } else
73 return 1; // Dann sollte move schon nen Fehler machen
74 if (fn=="/room/void") // Void darf IMMER betreten werden
75 return 1;
76 flags=QueryProp(P_INPC_WALK_FLAGS);
77 if (!(flags & WF_MAY_LOAD)
78 && !objectp(ob))
79 return 0; // Darf nicht in nicht geladene Raeume folgen.
80 if (!(flags & WF_MAY_WALK_BACK)
81 && ob==QueryProp(P_INPC_LAST_ENVIRONMENT))
82 return 0; // Darf nicht in den vorherigen Raum
83 return area_check(fn);
84}
85
86int walk_random() {
87 string *ex,*ex2;
88 object env;
89 int i,r,flags;
90
91 if (!objectp(env=ENV))
92 return 0;
93 ex=m_indices(ENV->QueryProp(P_EXITS));
94 flags=QueryProp(P_CAN_FLAGS);
95 if (flags & WF_MAY_USE_SPECIAL)
96 ex+=m_indices(ENV->QueryProp(P_SPECIAL_EXITS));
97 ex2=ex[0..];
98 while (i=sizeof(ex)) {
99 r=random(i);
100 command(ex[r]);
101 if (ENV!=env)
102 return 1;
103 ex-=({ex[r]});
104 }
105 if (!(flags & WF_MAY_WALK_BACK)) {
106 SetProp(P_INPC_LAST_ENVIRONMENT,0);//Dirty Hack, um Sackgassen zu verlassen
107 ex=ex2;
108 while (i=sizeof(ex)) {
109 r=random(i);
110 command(ex[r]);
111 if (ENV!=env)
112 return 1;
113 ex-=({ex[r]});
114 }
115 }
116 return move(QueryProp(P_INPC_HOME),M_TPORT);
117}
118
119int walk_route() {
120}
121
122int walk_to() {
123}
124
125int walk_follow() {
126}
127
128int walk_flee() {
129}