]> icculus.org git repositories - divverent/nexuiz.git/blob - data/qcsrc/server/gamec/urrebot_nn_search.c
fixed repeating sound with weapons stay
[divverent/nexuiz.git] / data / qcsrc / server / gamec / urrebot_nn_search.c
1 /* --- CheckNavNode ---\r
2 Evaluates travel cost and wether to continue search or not in this direction*/\r
3 \r
4 float(entity from, entity to, float lflag) CheckNavNode =\r
5 {\r
6         local float addcost;\r
7         local vector foundpoint;\r
8         local entity optpoint;\r
9 \r
10         if (!to)\r
11                 return FALSE;\r
12 \r
13         if (!(lflag & LF_NOWALK))\r
14         if (!(lflag & LF_NOLINK))\r
15         {\r
16                 if (from.sflags & S_TELEPORT) // teleporter exception\r
17                         foundpoint = from.origin;\r
18                 else\r
19                 {\r
20                         optpoint = world;\r
21                         if (urrebots_navopt)\r
22                                 optpoint = MatchOptPoint(from, from.goallist, to);\r
23                         if (optpoint)\r
24                                 foundpoint = optpoint.origin;\r
25                         else\r
26                                 foundpoint = ClampPointToSpace(from.pointl, from, to);\r
27                 }\r
28                 addcost = vlen(from.pointl - foundpoint);\r
29                 addcost = addcost + from.costl;\r
30                 if (addcost <= search_distance)\r
31                 if (to.costl > addcost)\r
32                 {\r
33                         to.lmark = TRUE;\r
34                         to.goallist = from;\r
35                         to.costl = addcost;\r
36                         to.pointl = foundpoint;\r
37                 }\r
38         }\r
39         return TRUE;\r
40 };\r
41 \r
42 /* --- MarkRoute ---\r
43 Searches as far as possible, and gives all navnodes a travel cost and shortest\r
44 travel point, which is then used for goal evaluation\r
45 \r
46 Starts by clearing all navnodes, and searches breadth first from the starting navnode*/\r
47 \r
48 void(float sdist) MarkRoute =\r
49 {\r
50         local entity t, start;\r
51         local float searching;\r
52 \r
53         start = FindCurrentNavNode(self.origin, self.mins, self.maxs);\r
54 \r
55         if(!start)\r
56                 return;\r
57 \r
58         search_distance = sdist;\r
59 \r
60         t = navnode_chain;\r
61         while (t)\r
62         {\r
63                 t.goallist = world;\r
64                 t.lmark = FALSE;\r
65                 t.costl = 10000000;\r
66                 t.pointl = '0 0 0';\r
67                 t = t.list;\r
68         }\r
69 \r
70         start.lmark = TRUE;\r
71         start.costl = 0;\r
72         start.pointl = self.origin;\r
73 \r
74         searching = TRUE;\r
75         while(searching)\r
76         {\r
77                 searching = FALSE;\r
78                 t = navnode_chain;\r
79                 while(t)\r
80                 {\r
81                         if(t.lmark)\r
82                         {\r
83                                 searching = TRUE;\r
84                                 t.lmark = FALSE;\r
85                                 if (CheckNavNode(t, t.link0, t.lflags0))\r
86                                 if (CheckNavNode(t, t.link1, t.lflags1))\r
87                                 if (CheckNavNode(t, t.link2, t.lflags2))\r
88                                 if (CheckNavNode(t, t.link3, t.lflags3))\r
89                                 if (CheckNavNode(t, t.link4, t.lflags4))\r
90                                 if (CheckNavNode(t, t.link5, t.lflags5))\r
91                                 if (CheckNavNode(t, t.link6, t.lflags6))\r
92                                 if (CheckNavNode(t, t.link7, t.lflags7))\r
93                                 if (CheckNavNode(t, t.link8, t.lflags8))\r
94                                 if (CheckNavNode(t, t.link9, t.lflags9))\r
95                                 if (CheckNavNode(t, t.link10, t.lflags10))\r
96                                 if (CheckNavNode(t, t.link11, t.lflags11))\r
97                                 if (CheckNavNode(t, t.link12, t.lflags12))\r
98                                 if (CheckNavNode(t, t.link13, t.lflags13))\r
99                                 if (CheckNavNode(t, t.link14, t.lflags14))\r
100                                 if (CheckNavNode(t, t.link15, t.lflags15))\r
101                                 if (CheckNavNode(t, t.link16, t.lflags16))\r
102                                 if (CheckNavNode(t, t.link17, t.lflags17))\r
103                                 if (CheckNavNode(t, t.link18, t.lflags18))\r
104                                 CheckNavNode(t, t.link19, t.lflags19);\r
105                         }\r
106                         t = t.list;\r
107                 }\r
108         }\r
109 };