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