├── .github
└── workflows
│ └── compile.yml
├── .gitignore
├── LICENSE
├── README.md
└── addons
└── sourcemod
└── scripting
├── include
└── navmesh.inc
├── navmesh-test.sp
└── navmesh.sp
/.github/workflows/compile.yml:
--------------------------------------------------------------------------------
1 | name: Compile
2 |
3 | on:
4 | push:
5 | branches: [master]
6 | paths:
7 | - "**.sp"
8 | - "**.inc"
9 | tags:
10 | - v*
11 | pull_request:
12 | branches: [master]
13 | paths:
14 | - "**.sp"
15 | - "**.inc"
16 |
17 | jobs:
18 | build:
19 | runs-on: ubuntu-latest
20 |
21 | steps:
22 | - uses: actions/checkout@v2
23 | with:
24 | submodules: true
25 |
26 | - name: SourceMod
27 | run: |
28 | wget -q "http://www.sourcemod.net/latest.php?version=1.10&os=linux" -O sourcemod.tar.gz
29 | tar -xf sourcemod.tar.gz
30 | - name: Compile
31 | working-directory: ./addons/sourcemod/scripting
32 | run: |
33 | ./spcomp navmesh.sp -o navmesh.smx
34 | - name: Compile Test Plugin
35 | working-directory: ./addons/sourcemod/scripting
36 | run: |
37 | ./spcomp navmesh-test.sp -o navmesh-test.smx
38 | - name: Release
39 | uses: softprops/action-gh-release@v0.1.5
40 | if: startsWith(github.ref, 'refs/tags/')
41 | env:
42 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
43 | with:
44 | files: |
45 | ./addons/sourcemod/scripting/include/navmesh.inc
46 | ./addons/sourcemod/scripting/navmesh.smx
47 | ./addons/sourcemod/scripting/navmesh-test.smx
48 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | .vscode/
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | GNU GENERAL PUBLIC LICENSE
2 | Version 3, 29 June 2007
3 |
4 | Copyright (C) 2007 Free Software Foundation, Inc.
5 | Everyone is permitted to copy and distribute verbatim copies
6 | of this license document, but changing it is not allowed.
7 |
8 | Preamble
9 |
10 | The GNU General Public License is a free, copyleft license for
11 | software and other kinds of works.
12 |
13 | The licenses for most software and other practical works are designed
14 | to take away your freedom to share and change the works. By contrast,
15 | the GNU General Public License is intended to guarantee your freedom to
16 | share and change all versions of a program--to make sure it remains free
17 | software for all its users. We, the Free Software Foundation, use the
18 | GNU General Public License for most of our software; it applies also to
19 | any other work released this way by its authors. You can apply it to
20 | your programs, too.
21 |
22 | When we speak of free software, we are referring to freedom, not
23 | price. Our General Public Licenses are designed to make sure that you
24 | have the freedom to distribute copies of free software (and charge for
25 | them if you wish), that you receive source code or can get it if you
26 | want it, that you can change the software or use pieces of it in new
27 | free programs, and that you know you can do these things.
28 |
29 | To protect your rights, we need to prevent others from denying you
30 | these rights or asking you to surrender the rights. Therefore, you have
31 | certain responsibilities if you distribute copies of the software, or if
32 | you modify it: responsibilities to respect the freedom of others.
33 |
34 | For example, if you distribute copies of such a program, whether
35 | gratis or for a fee, you must pass on to the recipients the same
36 | freedoms that you received. You must make sure that they, too, receive
37 | or can get the source code. And you must show them these terms so they
38 | know their rights.
39 |
40 | Developers that use the GNU GPL protect your rights with two steps:
41 | (1) assert copyright on the software, and (2) offer you this License
42 | giving you legal permission to copy, distribute and/or modify it.
43 |
44 | For the developers' and authors' protection, the GPL clearly explains
45 | that there is no warranty for this free software. For both users' and
46 | authors' sake, the GPL requires that modified versions be marked as
47 | changed, so that their problems will not be attributed erroneously to
48 | authors of previous versions.
49 |
50 | Some devices are designed to deny users access to install or run
51 | modified versions of the software inside them, although the manufacturer
52 | can do so. This is fundamentally incompatible with the aim of
53 | protecting users' freedom to change the software. The systematic
54 | pattern of such abuse occurs in the area of products for individuals to
55 | use, which is precisely where it is most unacceptable. Therefore, we
56 | have designed this version of the GPL to prohibit the practice for those
57 | products. If such problems arise substantially in other domains, we
58 | stand ready to extend this provision to those domains in future versions
59 | of the GPL, as needed to protect the freedom of users.
60 |
61 | Finally, every program is threatened constantly by software patents.
62 | States should not allow patents to restrict development and use of
63 | software on general-purpose computers, but in those that do, we wish to
64 | avoid the special danger that patents applied to a free program could
65 | make it effectively proprietary. To prevent this, the GPL assures that
66 | patents cannot be used to render the program non-free.
67 |
68 | The precise terms and conditions for copying, distribution and
69 | modification follow.
70 |
71 | TERMS AND CONDITIONS
72 |
73 | 0. Definitions.
74 |
75 | "This License" refers to version 3 of the GNU General Public License.
76 |
77 | "Copyright" also means copyright-like laws that apply to other kinds of
78 | works, such as semiconductor masks.
79 |
80 | "The Program" refers to any copyrightable work licensed under this
81 | License. Each licensee is addressed as "you". "Licensees" and
82 | "recipients" may be individuals or organizations.
83 |
84 | To "modify" a work means to copy from or adapt all or part of the work
85 | in a fashion requiring copyright permission, other than the making of an
86 | exact copy. The resulting work is called a "modified version" of the
87 | earlier work or a work "based on" the earlier work.
88 |
89 | A "covered work" means either the unmodified Program or a work based
90 | on the Program.
91 |
92 | To "propagate" a work means to do anything with it that, without
93 | permission, would make you directly or secondarily liable for
94 | infringement under applicable copyright law, except executing it on a
95 | computer or modifying a private copy. Propagation includes copying,
96 | distribution (with or without modification), making available to the
97 | public, and in some countries other activities as well.
98 |
99 | To "convey" a work means any kind of propagation that enables other
100 | parties to make or receive copies. Mere interaction with a user through
101 | a computer network, with no transfer of a copy, is not conveying.
102 |
103 | An interactive user interface displays "Appropriate Legal Notices"
104 | to the extent that it includes a convenient and prominently visible
105 | feature that (1) displays an appropriate copyright notice, and (2)
106 | tells the user that there is no warranty for the work (except to the
107 | extent that warranties are provided), that licensees may convey the
108 | work under this License, and how to view a copy of this License. If
109 | the interface presents a list of user commands or options, such as a
110 | menu, a prominent item in the list meets this criterion.
111 |
112 | 1. Source Code.
113 |
114 | The "source code" for a work means the preferred form of the work
115 | for making modifications to it. "Object code" means any non-source
116 | form of a work.
117 |
118 | A "Standard Interface" means an interface that either is an official
119 | standard defined by a recognized standards body, or, in the case of
120 | interfaces specified for a particular programming language, one that
121 | is widely used among developers working in that language.
122 |
123 | The "System Libraries" of an executable work include anything, other
124 | than the work as a whole, that (a) is included in the normal form of
125 | packaging a Major Component, but which is not part of that Major
126 | Component, and (b) serves only to enable use of the work with that
127 | Major Component, or to implement a Standard Interface for which an
128 | implementation is available to the public in source code form. A
129 | "Major Component", in this context, means a major essential component
130 | (kernel, window system, and so on) of the specific operating system
131 | (if any) on which the executable work runs, or a compiler used to
132 | produce the work, or an object code interpreter used to run it.
133 |
134 | The "Corresponding Source" for a work in object code form means all
135 | the source code needed to generate, install, and (for an executable
136 | work) run the object code and to modify the work, including scripts to
137 | control those activities. However, it does not include the work's
138 | System Libraries, or general-purpose tools or generally available free
139 | programs which are used unmodified in performing those activities but
140 | which are not part of the work. For example, Corresponding Source
141 | includes interface definition files associated with source files for
142 | the work, and the source code for shared libraries and dynamically
143 | linked subprograms that the work is specifically designed to require,
144 | such as by intimate data communication or control flow between those
145 | subprograms and other parts of the work.
146 |
147 | The Corresponding Source need not include anything that users
148 | can regenerate automatically from other parts of the Corresponding
149 | Source.
150 |
151 | The Corresponding Source for a work in source code form is that
152 | same work.
153 |
154 | 2. Basic Permissions.
155 |
156 | All rights granted under this License are granted for the term of
157 | copyright on the Program, and are irrevocable provided the stated
158 | conditions are met. This License explicitly affirms your unlimited
159 | permission to run the unmodified Program. The output from running a
160 | covered work is covered by this License only if the output, given its
161 | content, constitutes a covered work. This License acknowledges your
162 | rights of fair use or other equivalent, as provided by copyright law.
163 |
164 | You may make, run and propagate covered works that you do not
165 | convey, without conditions so long as your license otherwise remains
166 | in force. You may convey covered works to others for the sole purpose
167 | of having them make modifications exclusively for you, or provide you
168 | with facilities for running those works, provided that you comply with
169 | the terms of this License in conveying all material for which you do
170 | not control copyright. Those thus making or running the covered works
171 | for you must do so exclusively on your behalf, under your direction
172 | and control, on terms that prohibit them from making any copies of
173 | your copyrighted material outside their relationship with you.
174 |
175 | Conveying under any other circumstances is permitted solely under
176 | the conditions stated below. Sublicensing is not allowed; section 10
177 | makes it unnecessary.
178 |
179 | 3. Protecting Users' Legal Rights From Anti-Circumvention Law.
180 |
181 | No covered work shall be deemed part of an effective technological
182 | measure under any applicable law fulfilling obligations under article
183 | 11 of the WIPO copyright treaty adopted on 20 December 1996, or
184 | similar laws prohibiting or restricting circumvention of such
185 | measures.
186 |
187 | When you convey a covered work, you waive any legal power to forbid
188 | circumvention of technological measures to the extent such circumvention
189 | is effected by exercising rights under this License with respect to
190 | the covered work, and you disclaim any intention to limit operation or
191 | modification of the work as a means of enforcing, against the work's
192 | users, your or third parties' legal rights to forbid circumvention of
193 | technological measures.
194 |
195 | 4. Conveying Verbatim Copies.
196 |
197 | You may convey verbatim copies of the Program's source code as you
198 | receive it, in any medium, provided that you conspicuously and
199 | appropriately publish on each copy an appropriate copyright notice;
200 | keep intact all notices stating that this License and any
201 | non-permissive terms added in accord with section 7 apply to the code;
202 | keep intact all notices of the absence of any warranty; and give all
203 | recipients a copy of this License along with the Program.
204 |
205 | You may charge any price or no price for each copy that you convey,
206 | and you may offer support or warranty protection for a fee.
207 |
208 | 5. Conveying Modified Source Versions.
209 |
210 | You may convey a work based on the Program, or the modifications to
211 | produce it from the Program, in the form of source code under the
212 | terms of section 4, provided that you also meet all of these conditions:
213 |
214 | a) The work must carry prominent notices stating that you modified
215 | it, and giving a relevant date.
216 |
217 | b) The work must carry prominent notices stating that it is
218 | released under this License and any conditions added under section
219 | 7. This requirement modifies the requirement in section 4 to
220 | "keep intact all notices".
221 |
222 | c) You must license the entire work, as a whole, under this
223 | License to anyone who comes into possession of a copy. This
224 | License will therefore apply, along with any applicable section 7
225 | additional terms, to the whole of the work, and all its parts,
226 | regardless of how they are packaged. This License gives no
227 | permission to license the work in any other way, but it does not
228 | invalidate such permission if you have separately received it.
229 |
230 | d) If the work has interactive user interfaces, each must display
231 | Appropriate Legal Notices; however, if the Program has interactive
232 | interfaces that do not display Appropriate Legal Notices, your
233 | work need not make them do so.
234 |
235 | A compilation of a covered work with other separate and independent
236 | works, which are not by their nature extensions of the covered work,
237 | and which are not combined with it such as to form a larger program,
238 | in or on a volume of a storage or distribution medium, is called an
239 | "aggregate" if the compilation and its resulting copyright are not
240 | used to limit the access or legal rights of the compilation's users
241 | beyond what the individual works permit. Inclusion of a covered work
242 | in an aggregate does not cause this License to apply to the other
243 | parts of the aggregate.
244 |
245 | 6. Conveying Non-Source Forms.
246 |
247 | You may convey a covered work in object code form under the terms
248 | of sections 4 and 5, provided that you also convey the
249 | machine-readable Corresponding Source under the terms of this License,
250 | in one of these ways:
251 |
252 | a) Convey the object code in, or embodied in, a physical product
253 | (including a physical distribution medium), accompanied by the
254 | Corresponding Source fixed on a durable physical medium
255 | customarily used for software interchange.
256 |
257 | b) Convey the object code in, or embodied in, a physical product
258 | (including a physical distribution medium), accompanied by a
259 | written offer, valid for at least three years and valid for as
260 | long as you offer spare parts or customer support for that product
261 | model, to give anyone who possesses the object code either (1) a
262 | copy of the Corresponding Source for all the software in the
263 | product that is covered by this License, on a durable physical
264 | medium customarily used for software interchange, for a price no
265 | more than your reasonable cost of physically performing this
266 | conveying of source, or (2) access to copy the
267 | Corresponding Source from a network server at no charge.
268 |
269 | c) Convey individual copies of the object code with a copy of the
270 | written offer to provide the Corresponding Source. This
271 | alternative is allowed only occasionally and noncommercially, and
272 | only if you received the object code with such an offer, in accord
273 | with subsection 6b.
274 |
275 | d) Convey the object code by offering access from a designated
276 | place (gratis or for a charge), and offer equivalent access to the
277 | Corresponding Source in the same way through the same place at no
278 | further charge. You need not require recipients to copy the
279 | Corresponding Source along with the object code. If the place to
280 | copy the object code is a network server, the Corresponding Source
281 | may be on a different server (operated by you or a third party)
282 | that supports equivalent copying facilities, provided you maintain
283 | clear directions next to the object code saying where to find the
284 | Corresponding Source. Regardless of what server hosts the
285 | Corresponding Source, you remain obligated to ensure that it is
286 | available for as long as needed to satisfy these requirements.
287 |
288 | e) Convey the object code using peer-to-peer transmission, provided
289 | you inform other peers where the object code and Corresponding
290 | Source of the work are being offered to the general public at no
291 | charge under subsection 6d.
292 |
293 | A separable portion of the object code, whose source code is excluded
294 | from the Corresponding Source as a System Library, need not be
295 | included in conveying the object code work.
296 |
297 | A "User Product" is either (1) a "consumer product", which means any
298 | tangible personal property which is normally used for personal, family,
299 | or household purposes, or (2) anything designed or sold for incorporation
300 | into a dwelling. In determining whether a product is a consumer product,
301 | doubtful cases shall be resolved in favor of coverage. For a particular
302 | product received by a particular user, "normally used" refers to a
303 | typical or common use of that class of product, regardless of the status
304 | of the particular user or of the way in which the particular user
305 | actually uses, or expects or is expected to use, the product. A product
306 | is a consumer product regardless of whether the product has substantial
307 | commercial, industrial or non-consumer uses, unless such uses represent
308 | the only significant mode of use of the product.
309 |
310 | "Installation Information" for a User Product means any methods,
311 | procedures, authorization keys, or other information required to install
312 | and execute modified versions of a covered work in that User Product from
313 | a modified version of its Corresponding Source. The information must
314 | suffice to ensure that the continued functioning of the modified object
315 | code is in no case prevented or interfered with solely because
316 | modification has been made.
317 |
318 | If you convey an object code work under this section in, or with, or
319 | specifically for use in, a User Product, and the conveying occurs as
320 | part of a transaction in which the right of possession and use of the
321 | User Product is transferred to the recipient in perpetuity or for a
322 | fixed term (regardless of how the transaction is characterized), the
323 | Corresponding Source conveyed under this section must be accompanied
324 | by the Installation Information. But this requirement does not apply
325 | if neither you nor any third party retains the ability to install
326 | modified object code on the User Product (for example, the work has
327 | been installed in ROM).
328 |
329 | The requirement to provide Installation Information does not include a
330 | requirement to continue to provide support service, warranty, or updates
331 | for a work that has been modified or installed by the recipient, or for
332 | the User Product in which it has been modified or installed. Access to a
333 | network may be denied when the modification itself materially and
334 | adversely affects the operation of the network or violates the rules and
335 | protocols for communication across the network.
336 |
337 | Corresponding Source conveyed, and Installation Information provided,
338 | in accord with this section must be in a format that is publicly
339 | documented (and with an implementation available to the public in
340 | source code form), and must require no special password or key for
341 | unpacking, reading or copying.
342 |
343 | 7. Additional Terms.
344 |
345 | "Additional permissions" are terms that supplement the terms of this
346 | License by making exceptions from one or more of its conditions.
347 | Additional permissions that are applicable to the entire Program shall
348 | be treated as though they were included in this License, to the extent
349 | that they are valid under applicable law. If additional permissions
350 | apply only to part of the Program, that part may be used separately
351 | under those permissions, but the entire Program remains governed by
352 | this License without regard to the additional permissions.
353 |
354 | When you convey a copy of a covered work, you may at your option
355 | remove any additional permissions from that copy, or from any part of
356 | it. (Additional permissions may be written to require their own
357 | removal in certain cases when you modify the work.) You may place
358 | additional permissions on material, added by you to a covered work,
359 | for which you have or can give appropriate copyright permission.
360 |
361 | Notwithstanding any other provision of this License, for material you
362 | add to a covered work, you may (if authorized by the copyright holders of
363 | that material) supplement the terms of this License with terms:
364 |
365 | a) Disclaiming warranty or limiting liability differently from the
366 | terms of sections 15 and 16 of this License; or
367 |
368 | b) Requiring preservation of specified reasonable legal notices or
369 | author attributions in that material or in the Appropriate Legal
370 | Notices displayed by works containing it; or
371 |
372 | c) Prohibiting misrepresentation of the origin of that material, or
373 | requiring that modified versions of such material be marked in
374 | reasonable ways as different from the original version; or
375 |
376 | d) Limiting the use for publicity purposes of names of licensors or
377 | authors of the material; or
378 |
379 | e) Declining to grant rights under trademark law for use of some
380 | trade names, trademarks, or service marks; or
381 |
382 | f) Requiring indemnification of licensors and authors of that
383 | material by anyone who conveys the material (or modified versions of
384 | it) with contractual assumptions of liability to the recipient, for
385 | any liability that these contractual assumptions directly impose on
386 | those licensors and authors.
387 |
388 | All other non-permissive additional terms are considered "further
389 | restrictions" within the meaning of section 10. If the Program as you
390 | received it, or any part of it, contains a notice stating that it is
391 | governed by this License along with a term that is a further
392 | restriction, you may remove that term. If a license document contains
393 | a further restriction but permits relicensing or conveying under this
394 | License, you may add to a covered work material governed by the terms
395 | of that license document, provided that the further restriction does
396 | not survive such relicensing or conveying.
397 |
398 | If you add terms to a covered work in accord with this section, you
399 | must place, in the relevant source files, a statement of the
400 | additional terms that apply to those files, or a notice indicating
401 | where to find the applicable terms.
402 |
403 | Additional terms, permissive or non-permissive, may be stated in the
404 | form of a separately written license, or stated as exceptions;
405 | the above requirements apply either way.
406 |
407 | 8. Termination.
408 |
409 | You may not propagate or modify a covered work except as expressly
410 | provided under this License. Any attempt otherwise to propagate or
411 | modify it is void, and will automatically terminate your rights under
412 | this License (including any patent licenses granted under the third
413 | paragraph of section 11).
414 |
415 | However, if you cease all violation of this License, then your
416 | license from a particular copyright holder is reinstated (a)
417 | provisionally, unless and until the copyright holder explicitly and
418 | finally terminates your license, and (b) permanently, if the copyright
419 | holder fails to notify you of the violation by some reasonable means
420 | prior to 60 days after the cessation.
421 |
422 | Moreover, your license from a particular copyright holder is
423 | reinstated permanently if the copyright holder notifies you of the
424 | violation by some reasonable means, this is the first time you have
425 | received notice of violation of this License (for any work) from that
426 | copyright holder, and you cure the violation prior to 30 days after
427 | your receipt of the notice.
428 |
429 | Termination of your rights under this section does not terminate the
430 | licenses of parties who have received copies or rights from you under
431 | this License. If your rights have been terminated and not permanently
432 | reinstated, you do not qualify to receive new licenses for the same
433 | material under section 10.
434 |
435 | 9. Acceptance Not Required for Having Copies.
436 |
437 | You are not required to accept this License in order to receive or
438 | run a copy of the Program. Ancillary propagation of a covered work
439 | occurring solely as a consequence of using peer-to-peer transmission
440 | to receive a copy likewise does not require acceptance. However,
441 | nothing other than this License grants you permission to propagate or
442 | modify any covered work. These actions infringe copyright if you do
443 | not accept this License. Therefore, by modifying or propagating a
444 | covered work, you indicate your acceptance of this License to do so.
445 |
446 | 10. Automatic Licensing of Downstream Recipients.
447 |
448 | Each time you convey a covered work, the recipient automatically
449 | receives a license from the original licensors, to run, modify and
450 | propagate that work, subject to this License. You are not responsible
451 | for enforcing compliance by third parties with this License.
452 |
453 | An "entity transaction" is a transaction transferring control of an
454 | organization, or substantially all assets of one, or subdividing an
455 | organization, or merging organizations. If propagation of a covered
456 | work results from an entity transaction, each party to that
457 | transaction who receives a copy of the work also receives whatever
458 | licenses to the work the party's predecessor in interest had or could
459 | give under the previous paragraph, plus a right to possession of the
460 | Corresponding Source of the work from the predecessor in interest, if
461 | the predecessor has it or can get it with reasonable efforts.
462 |
463 | You may not impose any further restrictions on the exercise of the
464 | rights granted or affirmed under this License. For example, you may
465 | not impose a license fee, royalty, or other charge for exercise of
466 | rights granted under this License, and you may not initiate litigation
467 | (including a cross-claim or counterclaim in a lawsuit) alleging that
468 | any patent claim is infringed by making, using, selling, offering for
469 | sale, or importing the Program or any portion of it.
470 |
471 | 11. Patents.
472 |
473 | A "contributor" is a copyright holder who authorizes use under this
474 | License of the Program or a work on which the Program is based. The
475 | work thus licensed is called the contributor's "contributor version".
476 |
477 | A contributor's "essential patent claims" are all patent claims
478 | owned or controlled by the contributor, whether already acquired or
479 | hereafter acquired, that would be infringed by some manner, permitted
480 | by this License, of making, using, or selling its contributor version,
481 | but do not include claims that would be infringed only as a
482 | consequence of further modification of the contributor version. For
483 | purposes of this definition, "control" includes the right to grant
484 | patent sublicenses in a manner consistent with the requirements of
485 | this License.
486 |
487 | Each contributor grants you a non-exclusive, worldwide, royalty-free
488 | patent license under the contributor's essential patent claims, to
489 | make, use, sell, offer for sale, import and otherwise run, modify and
490 | propagate the contents of its contributor version.
491 |
492 | In the following three paragraphs, a "patent license" is any express
493 | agreement or commitment, however denominated, not to enforce a patent
494 | (such as an express permission to practice a patent or covenant not to
495 | sue for patent infringement). To "grant" such a patent license to a
496 | party means to make such an agreement or commitment not to enforce a
497 | patent against the party.
498 |
499 | If you convey a covered work, knowingly relying on a patent license,
500 | and the Corresponding Source of the work is not available for anyone
501 | to copy, free of charge and under the terms of this License, through a
502 | publicly available network server or other readily accessible means,
503 | then you must either (1) cause the Corresponding Source to be so
504 | available, or (2) arrange to deprive yourself of the benefit of the
505 | patent license for this particular work, or (3) arrange, in a manner
506 | consistent with the requirements of this License, to extend the patent
507 | license to downstream recipients. "Knowingly relying" means you have
508 | actual knowledge that, but for the patent license, your conveying the
509 | covered work in a country, or your recipient's use of the covered work
510 | in a country, would infringe one or more identifiable patents in that
511 | country that you have reason to believe are valid.
512 |
513 | If, pursuant to or in connection with a single transaction or
514 | arrangement, you convey, or propagate by procuring conveyance of, a
515 | covered work, and grant a patent license to some of the parties
516 | receiving the covered work authorizing them to use, propagate, modify
517 | or convey a specific copy of the covered work, then the patent license
518 | you grant is automatically extended to all recipients of the covered
519 | work and works based on it.
520 |
521 | A patent license is "discriminatory" if it does not include within
522 | the scope of its coverage, prohibits the exercise of, or is
523 | conditioned on the non-exercise of one or more of the rights that are
524 | specifically granted under this License. You may not convey a covered
525 | work if you are a party to an arrangement with a third party that is
526 | in the business of distributing software, under which you make payment
527 | to the third party based on the extent of your activity of conveying
528 | the work, and under which the third party grants, to any of the
529 | parties who would receive the covered work from you, a discriminatory
530 | patent license (a) in connection with copies of the covered work
531 | conveyed by you (or copies made from those copies), or (b) primarily
532 | for and in connection with specific products or compilations that
533 | contain the covered work, unless you entered into that arrangement,
534 | or that patent license was granted, prior to 28 March 2007.
535 |
536 | Nothing in this License shall be construed as excluding or limiting
537 | any implied license or other defenses to infringement that may
538 | otherwise be available to you under applicable patent law.
539 |
540 | 12. No Surrender of Others' Freedom.
541 |
542 | If conditions are imposed on you (whether by court order, agreement or
543 | otherwise) that contradict the conditions of this License, they do not
544 | excuse you from the conditions of this License. If you cannot convey a
545 | covered work so as to satisfy simultaneously your obligations under this
546 | License and any other pertinent obligations, then as a consequence you may
547 | not convey it at all. For example, if you agree to terms that obligate you
548 | to collect a royalty for further conveying from those to whom you convey
549 | the Program, the only way you could satisfy both those terms and this
550 | License would be to refrain entirely from conveying the Program.
551 |
552 | 13. Use with the GNU Affero General Public License.
553 |
554 | Notwithstanding any other provision of this License, you have
555 | permission to link or combine any covered work with a work licensed
556 | under version 3 of the GNU Affero General Public License into a single
557 | combined work, and to convey the resulting work. The terms of this
558 | License will continue to apply to the part which is the covered work,
559 | but the special requirements of the GNU Affero General Public License,
560 | section 13, concerning interaction through a network will apply to the
561 | combination as such.
562 |
563 | 14. Revised Versions of this License.
564 |
565 | The Free Software Foundation may publish revised and/or new versions of
566 | the GNU General Public License from time to time. Such new versions will
567 | be similar in spirit to the present version, but may differ in detail to
568 | address new problems or concerns.
569 |
570 | Each version is given a distinguishing version number. If the
571 | Program specifies that a certain numbered version of the GNU General
572 | Public License "or any later version" applies to it, you have the
573 | option of following the terms and conditions either of that numbered
574 | version or of any later version published by the Free Software
575 | Foundation. If the Program does not specify a version number of the
576 | GNU General Public License, you may choose any version ever published
577 | by the Free Software Foundation.
578 |
579 | If the Program specifies that a proxy can decide which future
580 | versions of the GNU General Public License can be used, that proxy's
581 | public statement of acceptance of a version permanently authorizes you
582 | to choose that version for the Program.
583 |
584 | Later license versions may give you additional or different
585 | permissions. However, no additional obligations are imposed on any
586 | author or copyright holder as a result of your choosing to follow a
587 | later version.
588 |
589 | 15. Disclaimer of Warranty.
590 |
591 | THERE IS NO WARRANTY FOR THE PROGRAM, TO THE EXTENT PERMITTED BY
592 | APPLICABLE LAW. EXCEPT WHEN OTHERWISE STATED IN WRITING THE COPYRIGHT
593 | HOLDERS AND/OR OTHER PARTIES PROVIDE THE PROGRAM "AS IS" WITHOUT WARRANTY
594 | OF ANY KIND, EITHER EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO,
595 | THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
596 | PURPOSE. THE ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE PROGRAM
597 | IS WITH YOU. SHOULD THE PROGRAM PROVE DEFECTIVE, YOU ASSUME THE COST OF
598 | ALL NECESSARY SERVICING, REPAIR OR CORRECTION.
599 |
600 | 16. Limitation of Liability.
601 |
602 | IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING
603 | WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MODIFIES AND/OR CONVEYS
604 | THE PROGRAM AS PERMITTED ABOVE, BE LIABLE TO YOU FOR DAMAGES, INCLUDING ANY
605 | GENERAL, SPECIAL, INCIDENTAL OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE
606 | USE OR INABILITY TO USE THE PROGRAM (INCLUDING BUT NOT LIMITED TO LOSS OF
607 | DATA OR DATA BEING RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD
608 | PARTIES OR A FAILURE OF THE PROGRAM TO OPERATE WITH ANY OTHER PROGRAMS),
609 | EVEN IF SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF
610 | SUCH DAMAGES.
611 |
612 | 17. Interpretation of Sections 15 and 16.
613 |
614 | If the disclaimer of warranty and limitation of liability provided
615 | above cannot be given local legal effect according to their terms,
616 | reviewing courts shall apply local law that most closely approximates
617 | an absolute waiver of all civil liability in connection with the
618 | Program, unless a warranty or assumption of liability accompanies a
619 | copy of the Program in return for a fee.
620 |
621 | END OF TERMS AND CONDITIONS
622 |
623 | How to Apply These Terms to Your New Programs
624 |
625 | If you develop a new program, and you want it to be of the greatest
626 | possible use to the public, the best way to achieve this is to make it
627 | free software which everyone can redistribute and change under these terms.
628 |
629 | To do so, attach the following notices to the program. It is safest
630 | to attach them to the start of each source file to most effectively
631 | state the exclusion of warranty; and each file should have at least
632 | the "copyright" line and a pointer to where the full notice is found.
633 |
634 |
635 | Copyright (C)
636 |
637 | This program is free software: you can redistribute it and/or modify
638 | it under the terms of the GNU General Public License as published by
639 | the Free Software Foundation, either version 3 of the License, or
640 | (at your option) any later version.
641 |
642 | This program is distributed in the hope that it will be useful,
643 | but WITHOUT ANY WARRANTY; without even the implied warranty of
644 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
645 | GNU General Public License for more details.
646 |
647 | You should have received a copy of the GNU General Public License
648 | along with this program. If not, see .
649 |
650 | Also add information on how to contact you by electronic and paper mail.
651 |
652 | If the program does terminal interaction, make it output a short
653 | notice like this when it starts in an interactive mode:
654 |
655 | Copyright (C)
656 | This program comes with ABSOLUTELY NO WARRANTY; for details type `show w'.
657 | This is free software, and you are welcome to redistribute it
658 | under certain conditions; type `show c' for details.
659 |
660 | The hypothetical commands `show w' and `show c' should show the appropriate
661 | parts of the General Public License. Of course, your program's commands
662 | might be different; for a GUI interface, you would use an "about box".
663 |
664 | You should also get your employer (if you work as a programmer) or school,
665 | if any, to sign a "copyright disclaimer" for the program, if necessary.
666 | For more information on this, and how to apply and follow the GNU GPL, see
667 | .
668 |
669 | The GNU General Public License does not permit incorporating your program
670 | into proprietary programs. If your program is a subroutine library, you
671 | may consider it more useful to permit linking proprietary applications with
672 | the library. If this is what you want to do, use the GNU Lesser General
673 | Public License instead of this License. But first, please read
674 | .
675 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SourcePawn NavMesh
2 | 
3 |
4 | This is basically a SourceMod plugin that can parse .NAV files and make data out of it that
5 | SourceMod plugins can read from. This plugin by itself doesn't do anything other than read
6 | data from the .NAV file. Other plugins have to utilize this plugin's features in order for
7 | this to have any purpose.
8 |
9 | Special thanks goes to Anthony Iacano (pimpinjuice) for the parser code, which can be found here:
10 | https://github.com/AnthonyIacono/War3SourceV2/tree/master/Nav
11 |
12 | ## Requirements
13 |
14 | - SourceMod 1.10+
15 |
16 | ## Game Compatibility
17 |
18 | | Name | Supported? |
19 | | -------------------------------- | :----------------: |
20 | | Team Fortress 2 | :heavy_check_mark: |
21 | | Counter-Strike: Global Offensive | :heavy_check_mark: |
22 | | Counter-Strike: Source | :heavy_check_mark: |
23 | | Left 4 Dead 2 | :heavy_check_mark: |
24 |
25 | If your game isn't listed here, there's a _slight_ chance it may still work, just that it's never been tested. You really have to pray to God that the game doesn't append any custom data to the NavMesh and/or its areas (which, realistically, is hardly ever the case). It'll get pretty obvious that it doesn't work if you see the script loading in an infinite amount of areas, or you get a memory overflow, or the script execution just times out... whatever comes first, really.
26 |
27 | If your game doesn't natively support .NAV files, can you still use this plugin? [Yes.](../../wiki/Using-the-plugin-in-non-native-games)
28 |
29 | Want to reverse a .NAV format for a game? [Read here.](../../wiki/Reversing-a-.NAV-File-Format)
30 |
31 | ## Current Dev. Goals
32 |
33 | - **Move away from using `ArrayStack`.** Transition functions to push to a given `ArrayList` rather than allocate an `ArrayStack`.
34 | - **Replace NavMeshArea\_\* natives with CNavArea methodmap natives.**
35 |
--------------------------------------------------------------------------------
/addons/sourcemod/scripting/include/navmesh.inc:
--------------------------------------------------------------------------------
1 | #if defined _navmesh_included
2 | #endinput
3 | #endif
4 | #define _navmesh_included
5 |
6 | #define HalfHumanHeight 35.5
7 | #define StepHeight 18.0
8 |
9 | #define NAV_MAGIC_NUMBER 0xFEEDFACE
10 |
11 | #define WALK_THRU_PROP_DOORS 0x01
12 | #define WALK_THRU_FUNC_DOORS 0x02
13 | #define WALK_THRU_DOORS (WALK_THRU_PROP_DOORS | WALK_THRU_FUNC_DOORS)
14 | #define WALK_THRU_BREAKABLES 0x04
15 | #define WALK_THRU_TOGGLE_BRUSHES 0x08
16 | #define WALK_THRU_EVERYTHING (WALK_THRU_DOORS | WALK_THRU_BREAKABLES | WALK_THRU_TOGGLE_BRUSHES)
17 |
18 | enum
19 | {
20 | NAV_DIR_NORTH = 0,
21 | NAV_DIR_EAST,
22 | NAV_DIR_SOUTH,
23 | NAV_DIR_WEST,
24 | NAV_DIR_COUNT
25 | };
26 |
27 | enum
28 | {
29 | NAV_LADDER_DIR_UP = 0,
30 | NAV_LADDER_DIR_DOWN,
31 | NAV_LADDER_DIR_COUNT
32 | };
33 |
34 | enum
35 | {
36 | NAV_MESH_CROUCH = 0x0001,
37 | NAV_MESH_JUMP = 0x0002,
38 | NAV_MESH_PRECISE = 0x0004,
39 | NAV_MESH_NO_JUMP = 0x0008,
40 | NAV_MESH_STOP = 0x0010,
41 | NAV_MESH_RUN = 0x0020,
42 | NAV_MESH_WALK = 0x0040,
43 | NAV_MESH_AVOID = 0x0080,
44 | NAV_MESH_TRANSIENT = 0x0100,
45 | NAV_MESH_DONT_HIDE = 0x0200,
46 | NAV_MESH_STAND = 0x0400,
47 | NAV_MESH_NO_HOSTAGES = 0x0800
48 | };
49 |
50 | enum
51 | {
52 | GO_NORTH = 0,
53 | GO_EAST,
54 | GO_SOUTH,
55 | GO_WEST,
56 | GO_LADDER_UP,
57 | GO_LADDER_DOWN,
58 | GO_JUMP,
59 | NUM_TRAVERSE_TYPES
60 | };
61 |
62 | enum NavCornerType
63 | {
64 | NAV_CORNER_NORTH_WEST = 0,
65 | NAV_CORNER_NORTH_EAST,
66 | NAV_CORNER_SOUTH_EAST,
67 | NAV_CORNER_SOUTH_WEST,
68 | NAV_CORNER_COUNT
69 | };
70 |
71 | const CNavArea INVALID_NAV_AREA = view_as(-1);
72 | const CNavLadder INVALID_NAV_LADDER = view_as(-1);
73 | const HidingSpot INVALID_NAV_HIDING_SPOT = view_as(-1);
74 |
75 | typedef NavPathCostFunctor = function int(CNavArea area, CNavArea from, CNavLadder ladder, any data);
76 |
77 |
78 | // NavMesh
79 |
80 | /**
81 | * Called when the plugin finishes loading the navigation mesh, even if it fails. Called within the
82 | * OnMapStart() forward.
83 | *
84 | * @param success true if sucessful, false otherwise.
85 | */
86 | forward void OnNavMeshLoaded(bool success);
87 |
88 | native bool NavMesh_Exists();
89 |
90 | native int NavMesh_GetMagicNumber();
91 |
92 | native int NavMesh_GetVersion();
93 |
94 | native int NavMesh_GetSubVersion();
95 |
96 | native int NavMesh_GetSaveBSPSize();
97 |
98 | native bool NavMesh_IsAnalyzed();
99 |
100 | native bool NavMesh_GetGroundHeight(const float pos[3], float &height=-1.0, float normal[3]=NULL_VECTOR);
101 |
102 | native CNavArea NavMesh_FindAreaByID( int areaID );
103 |
104 | native CNavArea NavMesh_GetArea(const float pos[3], float beneathLimit=120.0);
105 |
106 | native CNavArea NavMesh_GetNearestArea(const float pos[3], bool anyZ=false, float maxDist=10000.0, bool checkLOS=false, bool checkGround=true, int team=-2);
107 |
108 | native HidingSpot NavMesh_FindHidingSpotByID(int hidingSpotID);
109 |
110 | native HidingSpot NavMesh_GetRandomHidingSpot();
111 |
112 | // These grid functions are more internal than anything.
113 | native int NavMesh_WorldToGridX(float wx);
114 |
115 | native int NavMesh_WorldToGridY(float wy);
116 |
117 | native void NavMesh_GetAreasOnGrid(ArrayStack hStack, int x, int y);
118 |
119 | native int NavMesh_GetGridSizeX();
120 |
121 | native int NavMesh_GetGridSizeY();
122 |
123 |
124 | native void NavMesh_CollectSurroundingAreas(ArrayStack hStack, CNavArea startArea, float travelDistLimit=1500.0, float maxStepUpLimit=StepHeight, float maxDropDownLimit=100.0);
125 |
126 | native bool NavMesh_BuildPath(CNavArea startArea, CNavArea goalArea, const float goalPos[3], NavPathCostFunctor costFunctor, any costData=0, CNavArea &closestArea=INVALID_NAV_AREA, float maxPathLength=0.0, float flMaxStepSize=0.0);
127 |
128 | enum CNavMesh
129 | {
130 | TheNavMesh
131 | }
132 |
133 | methodmap CNavMesh
134 | {
135 | }
136 |
137 | // CNavArea
138 |
139 | native int NavMeshArea_GetID(int areaIndex);
140 |
141 | native int NavMeshArea_GetFlags(int areaIndex);
142 |
143 | native void NavMeshArea_GetPlace(int areaIndex, char[] buffer, int maxlen);
144 |
145 | native bool NavMeshArea_GetCenter(int areaIndex, float buffer[3]);
146 |
147 | native void NavMeshArea_GetAdjacentList(ArrayStack buffer, int areaIndex, int dir);
148 |
149 | native void NavMeshArea_GetLadderList(ArrayStack buffer, int areaIndex, int dir);
150 |
151 | native void NavMeshArea_GetHidingSpots(ArrayStack buffer, int areaIndex);
152 |
153 | native void NavMeshArea_GetClosestPointOnArea(int areaIndex, const float pos[3], float closePos[3]);
154 |
155 | native int NavMeshArea_GetTotalCost(int areaIndex);
156 |
157 | native int NavMeshArea_GetCostSoFar(int areaIndex);
158 |
159 | native int NavMeshArea_GetParent(int areaIndex);
160 |
161 | native int NavMeshArea_GetParentHow(int areaIndex);
162 |
163 | native void NavMeshArea_SetParent(int areaIndex, int parentAreaIndex);
164 |
165 | native void NavMeshArea_SetParentHow(int areaIndex, int parentHow);
166 |
167 | native bool NavMeshArea_GetExtentLow(int areaIndex, float buffer[3]);
168 |
169 | native bool NavMeshArea_GetExtentHigh(int areaIndex, float buffer[3]);
170 |
171 | native bool NavMeshArea_IsOverlappingPoint(int areaIndex, const float pos[3], float tolerance);
172 |
173 | native bool NavMeshArea_IsOverlappingArea(int areaIndex, int targetAreaIndex);
174 |
175 | native float NavMeshArea_GetNECornerZ(int areaIndex);
176 |
177 | native float NavMeshArea_GetSWCornerZ(int areaIndex);
178 |
179 | native void NavMeshArea_GetCorner(int areaIndex, NavCornerType corner, float buffer[3]);
180 |
181 | native float NavMeshArea_GetZ(int areaIndex, const float pos[3]);
182 |
183 | native float NavMeshArea_GetZFromXAndY(int areaIndex, float x, float y);
184 |
185 | native bool NavMeshArea_IsEdge(int areaIndex, int dir);
186 |
187 | native bool NavMeshArea_Contains(int areaIndex, const float pos[3]);
188 |
189 | native void NavMeshArea_GetRandomPoint(int areaIndex, float buffer[3]);
190 |
191 | native bool NavMeshArea_IsConnected(int areaIndex, int targetAreaIndex, int dir);
192 |
193 | native bool NavMeshArea_ComputePortal(int areaIndex, int areaToIndex, int dir, float center[3], float &halfWidth);
194 |
195 | native bool NavMeshArea_ComputeClosestPointInPortal(int areaIndex, int areaToIndex, int dir, const float fromPos[3], float closePos[3]);
196 |
197 | native int NavMeshArea_ComputeDirection(int areaIndex, const float pos[3]);
198 |
199 | native float NavMeshArea_GetLightIntensity(int areaIndex, const float pos[3]);
200 |
201 | methodmap CNavArea
202 | {
203 | public CNavArea( int index )
204 | {
205 | return view_as(index);
206 | }
207 |
208 | property int Index
209 | {
210 | public get() { return view_as(this); }
211 | }
212 |
213 | property int ID
214 | {
215 | public get() { return NavMeshArea_GetID(this.Index); }
216 | }
217 |
218 | property int Attributes
219 | {
220 | public get() { return NavMeshArea_GetFlags(this.Index); }
221 | }
222 |
223 | property CNavArea Parent
224 | {
225 | public get() { return CNavArea(NavMeshArea_GetParent(this.Index)); }
226 | public set( CNavArea area ) { NavMeshArea_SetParent(this.Index, area.Index); }
227 | }
228 |
229 | property int ParentHow
230 | {
231 | public get() { return NavMeshArea_GetParentHow(this.Index); }
232 | public set( int how ) { NavMeshArea_SetParentHow(this.Index, how); }
233 | }
234 |
235 | property int TotalCost
236 | {
237 | public get() { return NavMeshArea_GetTotalCost(this.Index); }
238 | }
239 |
240 | property int CostSoFar
241 | {
242 | public get() { return NavMeshArea_GetCostSoFar(this.Index); }
243 | }
244 |
245 | property float NECornerZ
246 | {
247 | public get() { return NavMeshArea_GetNECornerZ(this.Index); }
248 | }
249 |
250 | property float SWCornerZ
251 | {
252 | public get() { return NavMeshArea_GetSWCornerZ(this.Index); }
253 | }
254 |
255 | public void GetPlace( char[] buffer, int maxlen )
256 | {
257 | NavMeshArea_GetPlace(this.Index, buffer, maxlen);
258 | }
259 |
260 | public bool GetCenter( float buffer[3] )
261 | {
262 | return NavMeshArea_GetCenter(this.Index, buffer);
263 | }
264 |
265 | public bool GetExtentLow( float buffer[3] )
266 | {
267 | return NavMeshArea_GetExtentLow(this.Index, buffer);
268 | }
269 |
270 | public bool GetExtentHigh( float buffer[3] )
271 | {
272 | return NavMeshArea_GetExtentHigh(this.Index, buffer);
273 | }
274 |
275 | public void GetCorner( NavCornerType corner, float buffer[3] )
276 | {
277 | NavMeshArea_GetCorner( this.Index, corner, buffer );
278 | }
279 |
280 | public float GetZ( const float point[3] )
281 | {
282 | return NavMeshArea_GetZ(this.Index, point);
283 | }
284 |
285 | public float GetZFromXAndY( float x, float y )
286 | {
287 | return NavMeshArea_GetZFromXAndY(this.Index, x, y);
288 | }
289 |
290 | /**
291 | * Returns whether or not the area overlaps the given point. The Z-axis is not checked.
292 | *
293 | * @param point The point to check.
294 | * @param tolerance How many units the point can be away from the edge of the area.
295 | * @return true if overlapping, false otherwise.
296 | */
297 | public bool IsOverlappingPoint( const float point[3], float tolerance=0.0 )
298 | {
299 | return NavMeshArea_IsOverlappingPoint(this.Index, point, tolerance);
300 | }
301 |
302 | /**
303 | * Returns whether or not the area overlaps the given area. The Z-axis is not checked.
304 | *
305 | * @param area The area to check.
306 | * @return true if overlapping, false otherwise.
307 | */
308 | public bool IsOverlappingArea( CNavArea area )
309 | {
310 | return NavMeshArea_IsOverlappingArea(this.Index, area.Index);
311 | }
312 |
313 | /**
314 | * Returns whether or not the given point is contained by the area.
315 | *
316 | * Note: If the point overlaps the area, the given point can be at most StepHeight units above the
317 | * area to still be considered "contained".
318 | *
319 | * @param point The point to check.
320 | * @return true if the point is contained by the area, false otherwise.
321 | */
322 | public bool Contains( const float point[3] )
323 | {
324 | return NavMeshArea_Contains(this.Index, point);
325 | }
326 |
327 | /**
328 | * Returns whether or not if there are no bi-directional links in the given direction of the area.
329 | *
330 | * Note: For the longest time this only checked for presence of an outgoing connection, regardless
331 | * if the connection was two-way or not. This has been recently changed to properly reflect
332 | * CNavArea::IsEdge( NavDirType dir )'s functionality.
333 | *
334 | * @param dir Direction to check.
335 | * @return true if there are no bi-directional connections; false otherwise.
336 | */
337 | public bool IsEdge( int dir )
338 | {
339 | return NavMeshArea_IsEdge(this.Index, dir);
340 | }
341 |
342 | public void GetRandomPoint( float buffer[3] )
343 | {
344 | NavMeshArea_GetRandomPoint(this.Index, buffer);
345 | }
346 |
347 | /**
348 | * Returns whether or not there exists a bi-directional/outgoing one-way link to targetArea in
349 | * the provided direction.
350 | *
351 | * @param targetArea The area to check for.
352 | * @param dir The direction to check. If NAV_DIR_COUNT is the direction, all directions will be checked.
353 | * @return true if there exists a link, false otherwise.
354 | */
355 | public bool IsConnected( CNavArea targetArea, int dir )
356 | {
357 | return NavMeshArea_IsConnected(this.Index, targetArea.Index, dir);
358 | }
359 |
360 | public void GetClosestPointOnArea( const float pos[3], float buffer[3] )
361 | {
362 | NavMeshArea_GetClosestPointOnArea(this.Index, pos, buffer);
363 | }
364 |
365 | /**
366 | * Retrieves all bi-directional and one-way OUTGOING connections from this area and stores CNavArea's in the
367 | * provided buffer.
368 | *
369 | * Note: This does NOT include one-way INCOMING connections. Use GetIncomingConnections() for that.
370 | *
371 | * @param dir Direction to check.
372 | * @param buffer An ArrayStack to insert the CNavArea's in.
373 | * @deprecated Use CNavArea.GetAdjacentList() instead.
374 | */
375 | #pragma deprecated Use CNavArea.GetAdjacentList() instead.
376 | public void GetAdjacentAreas( int dir, ArrayStack buffer )
377 | {
378 | NavMeshArea_GetAdjacentList( buffer, this.Index, dir );
379 | }
380 |
381 | /**
382 | * Retrieves all bi-directional and one-way OUTGOING connections from this area and stores CNavArea's in the
383 | * provided buffer.
384 | *
385 | * Note: This does NOT include one-way INCOMING connections. Use GetIncomingConnections() for that.
386 | *
387 | * @param dir Direction to check. If NAV_DIR_COUNT is the direction, all directions will be checked.
388 | * @param buffer An ArrayList to insert the CNavArea's in.
389 | */
390 | public native void GetAdjacentList( int dir, ArrayList buffer );
391 |
392 | public CNavArea GetRandomAdjacentArea( int dir )
393 | {
394 | ArrayList list = new ArrayList();
395 | this.GetAdjacentList(dir, list);
396 | CNavArea area = list.Length > 0 ? CNavArea( list.Get( GetRandomInt(0, list.Length - 1) ) ) : INVALID_NAV_AREA;
397 | delete list;
398 | return area;
399 | }
400 |
401 | /**
402 | * Returns the amount of bi-directional and one-way OUTGOING connections from this area in the provided
403 | * direction.
404 | *
405 | * Note: This does NOT count one-way INCOMING connections.
406 | *
407 | * @param dir Direction to check. If NAV_DIR_COUNT is the direction, all directions will be checked.
408 | * @return The amount of connections.
409 | */
410 | public int GetAdjacentCount( int dir )
411 | {
412 | int count = 0;
413 | ArrayList list = new ArrayList();
414 | this.GetAdjacentList(dir, list);
415 | count = list.Length;
416 | delete list;
417 | return count;
418 | }
419 |
420 | /**
421 | * Retrieves all one-way INCOMING connections to this area and stores CNavArea's in the provided
422 | * buffer.
423 | *
424 | * @param dir Direction to check. If NAV_DIR_COUNT is the direction, all directions will be checked.
425 | * @param buffer An ArrayList to insert the CNavArea's in.
426 | */
427 | public native void GetIncomingConnections( int dir, ArrayList buffer );
428 |
429 | public void GetLadders( int dir, ArrayStack buffer )
430 | {
431 | NavMeshArea_GetLadderList( buffer, this.Index, dir );
432 | }
433 |
434 | public void GetHidingSpots( ArrayStack buffer )
435 | {
436 | NavMeshArea_GetHidingSpots( buffer, this.Index );
437 | }
438 |
439 | public void ComputePortal( CNavArea to, int dir, float center[3], float &halfWidth )
440 | {
441 | NavMeshArea_ComputePortal(this.Index, to.Index, dir, center, halfWidth);
442 | }
443 |
444 | public void ComputeClosestPointInPortal( CNavArea to, int dir, const float fromPos[3], float closePos[3] )
445 | {
446 | NavMeshArea_ComputeClosestPointInPortal(this.Index, to.Index, dir, fromPos, closePos);
447 | }
448 |
449 | public int ComputeDirection( const float point[3] )
450 | {
451 | return NavMeshArea_ComputeDirection(this.Index, point);
452 | }
453 |
454 | public float GetLightIntensity( const float point[3] )
455 | {
456 | return NavMeshArea_GetLightIntensity(this.Index, point);
457 | }
458 | }
459 |
460 | // CTFNavArea
461 | // Admittedly VERY questionable to include this (because it's from the recent leak), but feel free to not use them if you so please.
462 | // Bitflags for CTFNavArea's AttributeFlags property.
463 | enum
464 | {
465 | TF_NAV_INVALID = 0x00000000,
466 |
467 | TF_NAV_BLOCKED = 0x00000001,
468 | TF_NAV_SPAWN_ROOM_RED = 0x00000002,
469 | TF_NAV_SPAWN_ROOM_BLUE = 0x00000004,
470 | TF_NAV_SPAWN_ROOM_EXIT = 0x00000008,
471 | TF_NAV_HAS_AMMO = 0x00000010,
472 | TF_NAV_HAS_HEALTH = 0x00000020,
473 | TF_NAV_CONTROL_POINT = 0x00000040,
474 |
475 | TF_NAV_BLUE_SENTRY_DANGER = 0x00000080, // sentry can potentially fire upon enemies in this area
476 | TF_NAV_RED_SENTRY_DANGER = 0x00000100,
477 |
478 | TF_NAV_BLUE_SETUP_GATE = 0x00000800, // this area is blocked until the setup period is over
479 | TF_NAV_RED_SETUP_GATE = 0x00001000, // this area is blocked until the setup period is over
480 | TF_NAV_BLOCKED_AFTER_POINT_CAPTURE = 0x00002000, // this area becomes blocked after the first point is capped
481 | TF_NAV_BLOCKED_UNTIL_POINT_CAPTURE = 0x00004000, // this area is blocked until the first point is capped, then is unblocked
482 | TF_NAV_BLUE_ONE_WAY_DOOR = 0x00008000,
483 | TF_NAV_RED_ONE_WAY_DOOR = 0x00010000,
484 |
485 | TF_NAV_WITH_SECOND_POINT = 0x00020000,
486 | TF_NAV_WITH_THIRD_POINT = 0x00040000,
487 | TF_NAV_WITH_FOURTH_POINT = 0x00080000,
488 | TF_NAV_WITH_FIFTH_POINT = 0x00100000,
489 |
490 | TF_NAV_SNIPER_SPOT = 0x00200000, // this is a good place for a sniper to lurk
491 | TF_NAV_SENTRY_SPOT = 0x00400000, // this is a good place to build a sentry
492 |
493 | TF_NAV_ESCAPE_ROUTE = 0x00800000, // for Raid mode
494 | TF_NAV_ESCAPE_ROUTE_VISIBLE = 0x01000000, // all areas that have visibility to the escape route
495 |
496 | TF_NAV_NO_SPAWNING = 0x02000000, // don't spawn bots in this area
497 |
498 | TF_NAV_RESCUE_CLOSET = 0x04000000, // for respawning friends in Raid mode
499 |
500 | TF_NAV_BOMB_CAN_DROP_HERE = 0x08000000, // the bomb can be dropped here and reached by the invaders in MvM
501 |
502 | TF_NAV_DOOR_NEVER_BLOCKS = 0x10000000,
503 | TF_NAV_DOOR_ALWAYS_BLOCKS = 0x20000000,
504 |
505 | TF_NAV_UNBLOCKABLE = 0x40000000, // this area cannot be blocked
506 |
507 | // save/load these manually set flags, and don't clear them between rounds
508 | TF_NAV_PERSISTENT_ATTRIBUTES = TF_NAV_SNIPER_SPOT | TF_NAV_SENTRY_SPOT | TF_NAV_NO_SPAWNING | TF_NAV_BLUE_SETUP_GATE | TF_NAV_RED_SETUP_GATE | TF_NAV_BLOCKED_AFTER_POINT_CAPTURE | TF_NAV_BLOCKED_UNTIL_POINT_CAPTURE | TF_NAV_BLUE_ONE_WAY_DOOR | TF_NAV_RED_ONE_WAY_DOOR | TF_NAV_DOOR_NEVER_BLOCKS | TF_NAV_DOOR_ALWAYS_BLOCKS | TF_NAV_UNBLOCKABLE | TF_NAV_WITH_SECOND_POINT | TF_NAV_WITH_THIRD_POINT | TF_NAV_WITH_FOURTH_POINT | TF_NAV_WITH_FIFTH_POINT | TF_NAV_RESCUE_CLOSET
509 | };
510 |
511 | methodmap CTFNavArea < CNavArea
512 | {
513 | property int AttributeFlags
514 | {
515 | public native get();
516 | }
517 | }
518 |
519 | // CCSNavArea
520 | enum struct CCSNavArea_ApproachInfo
521 | {
522 | int HereArea;
523 | int PrevArea;
524 | int PrevToHereHow;
525 | int NextArea;
526 | int HereToNextHow;
527 | }
528 |
529 | methodmap CCSNavArea < CNavArea
530 | {
531 | public native void GetApproachInfoList( ArrayList buffer );
532 | }
533 |
534 | // TerrorNavArea
535 | // Bitflags for TerrorNavArea.SpawnAttributes
536 | enum
537 | {
538 | TERROR_NAV_EMPTY = 2,
539 | TERROR_NAV_STOP = 4,
540 | TERROR_NAV_FINALE = 0x40,
541 | TERROR_NAV_BATTLEFIELD = 0x100,
542 | TERROR_NAV_PLAYER_START = 0x80,
543 | TERROR_NAV_IGNORE_VISIBILITY = 0x200,
544 | TERROR_NAV_NOT_CLEARABLE = 0x400,
545 | TERROR_NAV_CHECKPOINT = 0x800,
546 | TERROR_NAV_OBSCURED = 0x1000,
547 | TERROR_NAV_NO_MOBS = 0x2000,
548 | TERROR_NAV_THREAT = 0x4000,
549 | TERROR_NAV_NOTHREAT = 0x80000,
550 | TERROR_NAV_LYINGDOWN = 0x100000,
551 | TERROR_NAV_RESCUE_CLOSET = 0x10000,
552 | TERROR_NAV_RESCUE_VEHICLE = 0x8000
553 | }
554 |
555 | methodmap TerrorNavArea < CNavArea
556 | {
557 | property int SpawnAttributes
558 | {
559 | public native get();
560 | }
561 | }
562 |
563 | methodmap TerrorNavMesh < CNavMesh
564 | {
565 | property float NavMaxViewDistance
566 | {
567 | public native get();
568 | }
569 |
570 | public native void GetZombiePopulation(char[] buffer, int maxSize);
571 | }
572 |
573 | // HidingSpot
574 |
575 | enum
576 | {
577 | NAV_HIDING_SPOT_IN_COVER = 0x01,
578 | NAV_HIDING_SPOT_GOOD_SNIPER_SPOT = 0x02,
579 | NAV_HIDING_SPOT_IDEAL_SNIPER_SPOT = 0x04,
580 | NAV_HIDING_SPOT_EXPOSED = 0x08
581 | }
582 |
583 | native int NavHidingSpot_GetID(int hidingSpotIndex);
584 |
585 | native int NavHidingSpot_GetFlags(int hidingSpotIndex);
586 |
587 | native void NavHidingSpot_GetPosition(int hidingSpotIndex, float buffer[3]);
588 |
589 | native CNavArea NavHidingSpot_GetArea(int hidingSpotIndex);
590 |
591 | methodmap HidingSpot
592 | {
593 | public HidingSpot( int index )
594 | {
595 | return view_as(index);
596 | }
597 |
598 | property int Index
599 | {
600 | public get() { return view_as(this); }
601 | }
602 |
603 | property int ID
604 | {
605 | public get() { return NavHidingSpot_GetID( this.Index ); }
606 | }
607 |
608 | property int Flags
609 | {
610 | public get() { return NavHidingSpot_GetFlags( this.Index ); }
611 | }
612 |
613 | public void GetPosition( float buffer[3] )
614 | {
615 | NavHidingSpot_GetPosition( this.Index, buffer );
616 | }
617 |
618 | public bool HasGoodCover()
619 | {
620 | return this.Flags & NAV_HIDING_SPOT_IN_COVER ? true : false;
621 | }
622 |
623 | public bool IsGoodSniperSpot()
624 | {
625 | return this.Flags & NAV_HIDING_SPOT_GOOD_SNIPER_SPOT ? true : false;
626 | }
627 |
628 | public bool IsIdealSniperSpot()
629 | {
630 | return this.Flags & NAV_HIDING_SPOT_IDEAL_SNIPER_SPOT ? true : false;
631 | }
632 |
633 | public bool IsExposed()
634 | {
635 | return this.Flags & NAV_HIDING_SPOT_EXPOSED ? true : false;
636 | }
637 |
638 | public CNavArea GetArea()
639 | {
640 | return NavHidingSpot_GetArea(this.Index);
641 | }
642 | }
643 |
644 |
645 | // CNavLadder
646 |
647 | native float NavMeshLadder_GetLength(int ladderIndex);
648 |
649 | native float NavMeshLadder_GetWidth(int ladderIndex);
650 |
651 | native CNavArea NavMeshLadder_GetTopForwardArea(int ladderIndex);
652 |
653 | native CNavArea NavMeshLadder_GetTopLeftArea(int ladderIndex);
654 |
655 | native CNavArea NavMeshLadder_GetTopRightArea(int ladderIndex);
656 |
657 | native CNavArea NavMeshLadder_GetTopBehindArea(int ladderIndex);
658 |
659 | native CNavArea NavMeshLadder_GetBottomArea(int ladderIndex);
660 |
661 | native void NavMeshLadder_GetTop(int ladderIndex, float buffer[3]);
662 |
663 | native void NavMeshLadder_GetBottom(int ladderIndex, float buffer[3]);
664 |
665 | methodmap CNavLadder
666 | {
667 | public CNavLadder( int index )
668 | {
669 | return view_as(index);
670 | }
671 |
672 | property int Index
673 | {
674 | public get() { return view_as(this); }
675 | }
676 |
677 | property float Length
678 | {
679 | public get() { return NavMeshLadder_GetLength(this.Index); }
680 | }
681 |
682 | property float Width
683 | {
684 | public get() { return NavMeshLadder_GetWidth(this.Index); }
685 | }
686 |
687 | property CNavArea TopForwardArea
688 | {
689 | public get() { return NavMeshLadder_GetTopForwardArea(this.Index); }
690 | }
691 |
692 | property CNavArea TopLeftArea
693 | {
694 | public get() { return NavMeshLadder_GetTopLeftArea(this.Index); }
695 | }
696 |
697 | property CNavArea TopRightArea
698 | {
699 | public get() { return NavMeshLadder_GetTopRightArea(this.Index); }
700 | }
701 |
702 | property CNavArea TopBehindArea
703 | {
704 | public get() { return NavMeshLadder_GetTopBehindArea(this.Index); }
705 | }
706 |
707 | property CNavArea BottomArea
708 | {
709 | public get() { return NavMeshLadder_GetBottomArea(this.Index); }
710 | }
711 |
712 | public void GetTop( float buffer[3] )
713 | {
714 | NavMeshLadder_GetTop(this.Index, buffer);
715 | }
716 |
717 | public void GetBottom( float buffer[3] )
718 | {
719 | NavMeshLadder_GetBottom(this.Index, buffer);
720 | }
721 | }
722 |
723 |
724 | // SpotEncounter
725 |
726 | native CNavArea NavSpotEncounter_GetFrom(int spotEncounterIndex);
727 |
728 | native int NavSpotEncounter_GetFromDirection(int spotEncounterIndex);
729 |
730 | native CNavArea NavSpotEncounter_GetTo(int spotEncounterIndex);
731 |
732 | native int NavSpotEncounter_GetToDirection(int spotEncounterIndex);
733 |
734 | native void NavSpotEncounter_GetSpots(int spotEncounterIndex, ArrayStack buffer);
735 |
736 | methodmap SpotEncounter
737 | {
738 | public SpotEncounter( int index )
739 | {
740 | return view_as(index);
741 | }
742 |
743 | property int Index
744 | {
745 | public get() { return view_as(this); }
746 | }
747 |
748 | property CNavArea From
749 | {
750 | public get() { return NavSpotEncounter_GetFrom(this.Index); }
751 | }
752 |
753 | property int FromDirection
754 | {
755 | public get() { return NavSpotEncounter_GetFromDirection(this.Index); }
756 | }
757 |
758 | property CNavArea To
759 | {
760 | public get() { return NavSpotEncounter_GetTo(this.Index); }
761 | }
762 |
763 | property int ToDirection
764 | {
765 | public get() { return NavSpotEncounter_GetToDirection(this.Index); }
766 | }
767 |
768 | public void GetSpots( ArrayStack buffer )
769 | {
770 | NavSpotEncounter_GetSpots(this.Index, buffer);
771 | }
772 | }
773 |
774 |
775 | // SpotOrder
776 |
777 | native HidingSpot NavSpotOrder_GetHidingSpot(int spotOrderIndex);
778 |
779 | native int NavSpotOrder_GetParametricDistance(int spotOrderIndex);
780 |
781 | methodmap SpotOrder
782 | {
783 | public SpotOrder( int index )
784 | {
785 | return view_as(index);
786 | }
787 |
788 | property int Index
789 | {
790 | public get() { return view_as(this); }
791 | }
792 |
793 | property HidingSpot HidingSpot
794 | {
795 | public get() { return NavSpotOrder_GetHidingSpot(this.Index); }
796 | }
797 |
798 | property int ParametricDistance
799 | {
800 | public get() { return NavSpotOrder_GetParametricDistance(this.Index); }
801 | }
802 | }
803 |
804 |
805 | // Shortest-path cost function for NavMesh_BuildPath.
806 | public int NavMeshShortestPathCost(CNavArea area, CNavArea from, CNavLadder ladder, any data)
807 | {
808 | if (from == INVALID_NAV_AREA)
809 | {
810 | return 0;
811 | }
812 | else
813 | {
814 | int iDist = 0;
815 | if (ladder != INVALID_NAV_LADDER)
816 | {
817 | iDist = RoundFloat(ladder.Length);
818 | }
819 | else
820 | {
821 | float flAreaCenter[3]; float flFromAreaCenter[3];
822 | area.GetCenter(flAreaCenter);
823 | from.GetCenter(flFromAreaCenter);
824 |
825 | iDist = RoundFloat(GetVectorDistance(flAreaCenter, flFromAreaCenter));
826 | }
827 |
828 | int iCost = iDist + from.CostSoFar;
829 | int iAreaFlags = area.Attributes;
830 | if (iAreaFlags & NAV_MESH_CROUCH) iCost += 20;
831 | if (iAreaFlags & NAV_MESH_JUMP) iCost += (5 * iDist);
832 | return iCost;
833 | }
834 | }
835 |
836 | // stocks
837 |
838 | stock bool IsEntityWalkable(int iEnt, int iFlags)
839 | {
840 | char sClass[64];
841 | GetEntityClassname(iEnt, sClass, sizeof(sClass));
842 |
843 | if (!strcmp(sClass, "worldspawn")) return false;
844 | if (!strcmp(sClass, "player")) return false;
845 |
846 | if (!strcmp(sClass, "func_door*"))
847 | {
848 | return (iFlags & WALK_THRU_PROP_DOORS) ? true : false;
849 | }
850 |
851 | if (!strcmp(sClass, "prop_door*"))
852 | {
853 | return (iFlags & WALK_THRU_PROP_DOORS) ? true : false;
854 | }
855 |
856 | if (!strcmp(sClass, "func_brush"))
857 | {
858 | int iSolidity = GetEntProp(iEnt, Prop_Data, "m_iSolidity");
859 |
860 | switch (iSolidity)
861 | {
862 | case 2: // BRUSHSOLID_ALWAYS
863 | {
864 | return false;
865 | }
866 | case 1: // BRUSHSOLID_NEVER
867 | {
868 | return true;
869 | }
870 | case 0: // BRUSHSOLID_TOGGLE
871 | {
872 | return (iFlags & WALK_THRU_TOGGLE_BRUSHES) ? true : false;
873 | }
874 | }
875 |
876 | return (iFlags & WALK_THRU_PROP_DOORS) ? true : false;
877 | }
878 |
879 | if (!strcmp(sClass, "func_breakable") && GetEntProp(iEnt, Prop_Data, "m_iHealth") && GetEntProp(iEnt, Prop_Data, "m_takedamage") == 2) // DAMAGE_YES
880 | {
881 | return (iFlags & WALK_THRU_BREAKABLES) ? true : false;
882 | }
883 |
884 | if (!strcmp(sClass, "func_playerinfected_clip"))
885 | {
886 | return true;
887 | }
888 |
889 | return false;
890 | }
891 |
892 | stock bool IsWalkableTraceLineClear(const float flFrom[3], const float flTo[3], int iFlags)
893 | {
894 | float flUseFrom[3];
895 | flUseFrom[0] = flFrom[0];
896 | flUseFrom[1] = flFrom[1];
897 | flUseFrom[2] = flFrom[2];
898 |
899 | Handle hTrace;
900 |
901 | float flFraction = 0.0;
902 |
903 | for (int t = 0; t < 50; t++)
904 | {
905 | hTrace = TR_TraceRayFilterEx(flUseFrom, flTo, MASK_NPCSOLID, RayType_EndPoint, TraceFilterWalkableEntities, iFlags);
906 | flFraction = TR_GetFraction(hTrace);
907 | int iResEnt = TR_GetEntityIndex(hTrace);
908 | float flResPos[3];
909 | TR_GetEndPosition(flResPos, hTrace);
910 | delete hTrace;
911 |
912 | if (flFraction != 1.0 && IsEntityWalkable(iResEnt, iFlags))
913 | {
914 | float flDir[3];
915 | SubtractVectors(flTo, flFrom, flDir);
916 | NormalizeVector(flDir, flDir);
917 | ScaleVector(flDir, 5.0);
918 | AddVectors(flResPos, flDir, flUseFrom);
919 | }
920 | else
921 | {
922 | break;
923 | }
924 | }
925 |
926 | if (flFraction == 1.0) return true;
927 |
928 | return false;
929 | }
930 |
931 | public bool TraceFilterWalkableEntities(int entity, int mask, any iFlags)
932 | {
933 | return !IsEntityWalkable(entity, iFlags);
934 | }
935 |
936 |
937 | public SharedPlugin __pl_navmesh =
938 | {
939 | name = "navmesh",
940 | file = "navmesh.smx",
941 | #if defined REQUIRE_PLUGIN
942 | required = 1,
943 | #else
944 | required = 0,
945 | #endif
946 | };
--------------------------------------------------------------------------------
/addons/sourcemod/scripting/navmesh-test.sp:
--------------------------------------------------------------------------------
1 | #include
2 | #include
3 | #include
4 |
5 | #pragma newdecls required
6 | #include
7 |
8 | #define PLUGIN_VERSION "1.0.6"
9 |
10 | int g_iPathLaserModelIndex = -1;
11 |
12 | public Plugin myinfo =
13 | {
14 | name = "SourcePawn Navigation Mesh Test",
15 | author = "KitRifty, Benoist3012",
16 | description = "Testing plugin of the Navigation Mesh plugin.",
17 | version = PLUGIN_VERSION,
18 | url = ""
19 | }
20 |
21 | float g_flTrackNavAreaThinkRate = 0.1;
22 | float g_flTrackNavAreaNextThink = 0.0;
23 |
24 | bool g_bPlayerTrackNavArea[MAXPLAYERS + 1] = { false, ... };
25 | Handle g_hPlayerTrackNavAreaInfoHudSync = null;
26 |
27 | public void OnPluginStart()
28 | {
29 | RegAdminCmd("sm_navmesh_collectsurroundingareas", Command_NavMeshCollectSurroundingAreas, ADMFLAG_CHEATS, "");
30 | RegAdminCmd("sm_navmesh_buildpath", Command_NavMeshBuildPath, ADMFLAG_CHEATS, "");
31 | RegAdminCmd("sm_navmesh_getnearestarea", Command_GetNearestArea, ADMFLAG_CHEATS, "");
32 | RegAdminCmd("sm_navmesh_show", Command_Show, ADMFLAG_CHEATS, "");
33 |
34 | g_hPlayerTrackNavAreaInfoHudSync = CreateHudSynchronizer();
35 | }
36 |
37 | public void OnMapStart()
38 | {
39 | g_iPathLaserModelIndex = PrecacheModel("materials/sprites/laserbeam.vmt");
40 |
41 | g_flTrackNavAreaNextThink = 0.0;
42 | }
43 |
44 | void DrawNavArea( int client, CNavArea area, const int color[4], float duration=0.15 )
45 | {
46 | if ( !IsClientInGame(client) || area == INVALID_NAV_AREA )
47 | return;
48 |
49 | float from[3], to[3];
50 | area.GetCorner( NAV_CORNER_NORTH_WEST, from );
51 | area.GetCorner( NAV_CORNER_NORTH_EAST, to );
52 | from[2] += 2; to[2] += 2;
53 |
54 | TE_SetupBeamPoints(from, to, g_iPathLaserModelIndex, g_iPathLaserModelIndex, 0, 30, duration, 1.0, 1.0, 0, 0.0, color, 1);
55 | TE_SendToClient(client);
56 |
57 | area.GetCorner( NAV_CORNER_NORTH_EAST, from );
58 | area.GetCorner( NAV_CORNER_SOUTH_EAST, to );
59 | from[2] += 2; to[2] += 2;
60 |
61 | TE_SetupBeamPoints(from, to, g_iPathLaserModelIndex, g_iPathLaserModelIndex, 0, 30, duration, 1.0, 1.0, 0, 0.0, color, 1);
62 | TE_SendToClient(client);
63 |
64 | area.GetCorner( NAV_CORNER_SOUTH_EAST, from );
65 | area.GetCorner( NAV_CORNER_SOUTH_WEST, to );
66 | from[2] += 2; to[2] += 2;
67 |
68 | TE_SetupBeamPoints(from, to, g_iPathLaserModelIndex, g_iPathLaserModelIndex, 0, 30, duration, 1.0, 1.0, 0, 0.0, color, 1);
69 | TE_SendToClient(client);
70 |
71 | area.GetCorner( NAV_CORNER_SOUTH_WEST, from );
72 | area.GetCorner( NAV_CORNER_NORTH_WEST, to );
73 | from[2] += 2; to[2] += 2;
74 |
75 | TE_SetupBeamPoints(from, to, g_iPathLaserModelIndex, g_iPathLaserModelIndex, 0, 30, duration, 1.0, 1.0, 0, 0.0, color, 1);
76 | TE_SendToClient(client);
77 | }
78 |
79 | public void OnGameFrame()
80 | {
81 | EngineVersion engineVersion = GetEngineVersion();
82 |
83 | if ( GetGameTime() >= g_flTrackNavAreaNextThink )
84 | {
85 | g_flTrackNavAreaNextThink = GetGameTime() + g_flTrackNavAreaThinkRate;
86 |
87 | for (int client = 1; client <= MaxClients; client++)
88 | {
89 | static const int DefaultAreaColor[] = { 255, 0, 0, 255 };
90 | static const int FocusedAreaColor[] = { 255, 255, 0, 255 };
91 |
92 | if (!IsClientInGame(client))
93 | continue;
94 |
95 | if ( g_bPlayerTrackNavArea[client] )
96 | {
97 | float flEyePos[3], flEyeDir[3], flEndPos[3];
98 | GetClientEyePosition(client, flEyePos);
99 | GetClientEyeAngles(client, flEyeDir);
100 | GetAngleVectors(flEyeDir, flEyeDir, NULL_VECTOR, NULL_VECTOR);
101 | NormalizeVector(flEyeDir, flEyeDir);
102 | ScaleVector(flEyeDir, 1000.0);
103 | AddVectors(flEyePos, flEyeDir, flEndPos);
104 |
105 | Handle hTrace = TR_TraceRayFilterEx(flEyePos,
106 | flEndPos,
107 | MASK_PLAYERSOLID_BRUSHONLY,
108 | RayType_EndPoint,
109 | TraceRayDontHitEntity,
110 | client);
111 |
112 | TR_GetEndPosition(flEndPos, hTrace);
113 | delete hTrace;
114 |
115 | CNavArea area = NavMesh_GetNearestArea(flEndPos);
116 | if (area == INVALID_NAV_AREA)
117 | continue;
118 |
119 | DrawNavArea( client, area, FocusedAreaColor );
120 |
121 | ArrayList connections = new ArrayList();
122 | area.GetAdjacentList(NAV_DIR_COUNT, connections);
123 | ArrayList incomingConnections = new ArrayList();
124 | area.GetIncomingConnections(NAV_DIR_COUNT, incomingConnections);
125 |
126 | for (int i = 0; i < connections.Length; i++)
127 | {
128 | DrawNavArea(client, connections.Get(i), DefaultAreaColor);
129 | }
130 |
131 | for (int i = 0; i < incomingConnections.Length; i++)
132 | {
133 | }
134 |
135 | switch (engineVersion)
136 | {
137 | case Engine_Left4Dead2:
138 | {
139 | PrintHintText(client, "ID: %d, # Connections: %d, # Incoming: %d", area.ID, connections.Length, incomingConnections.Length);
140 | }
141 | default:
142 | {
143 | SetHudTextParams(-1.0, 0.75, 0.2, 255, 255, 0, 150, 0, 0.0, 0.0, 0.0);
144 | ShowSyncHudText(client, g_hPlayerTrackNavAreaInfoHudSync, "ID: %d\n# Connections: %d\n# Incoming: %d\n", area.ID, connections.Length, incomingConnections.Length);
145 | }
146 | }
147 |
148 | delete connections;
149 | delete incomingConnections;
150 | }
151 | }
152 | }
153 | }
154 |
155 | public void OnClientDisconnect(int client)
156 | {
157 | g_bPlayerTrackNavArea[client] = false;
158 | }
159 |
160 | public Action Command_Show(int client,int args)
161 | {
162 | if (!NavMesh_Exists()) return Plugin_Handled;
163 |
164 | if ( args < 1 )
165 | {
166 | ReplyToCommand(client, "Usage: sm_navmesh_show <0/1>");
167 | return Plugin_Handled;
168 | }
169 |
170 | char sArg[16];
171 | GetCmdArg(1, sArg, sizeof(sArg));
172 | g_bPlayerTrackNavArea[client] = (StringToInt(sArg) != 0);
173 |
174 | return Plugin_Handled;
175 | }
176 |
177 | public Action Command_GetNearestArea(int client,int args)
178 | {
179 | if (!NavMesh_Exists()) return Plugin_Handled;
180 | float flEyePos[3], flEyeDir[3], flEndPos[3];
181 | GetClientEyePosition(client, flEyePos);
182 | GetClientEyeAngles(client, flEyeDir);
183 | GetAngleVectors(flEyeDir, flEyeDir, NULL_VECTOR, NULL_VECTOR);
184 | NormalizeVector(flEyeDir, flEyeDir);
185 | ScaleVector(flEyeDir, 1000.0);
186 | AddVectors(flEyePos, flEyeDir, flEndPos);
187 |
188 | Handle hTrace = TR_TraceRayFilterEx(flEyePos,
189 | flEndPos,
190 | MASK_PLAYERSOLID_BRUSHONLY,
191 | RayType_EndPoint,
192 | TraceRayDontHitEntity,
193 | client);
194 |
195 | TR_GetEndPosition(flEndPos, hTrace);
196 | CloseHandle(hTrace);
197 |
198 | CNavArea area = NavMesh_GetNearestArea(flEndPos);
199 | if (area != INVALID_NAV_AREA)
200 | {
201 | PrintToChat(client, "Nearest area ID: %d", area.ID);
202 | }
203 | else
204 | {
205 | PrintToChat(client, "Could not find an area.");
206 | }
207 |
208 | return Plugin_Handled;
209 | }
210 |
211 | public Action Command_NavMeshCollectSurroundingAreas(int client,int args)
212 | {
213 | return Plugin_Handled;
214 | }
215 |
216 | public Action Command_NavMeshBuildPath(int client,int args)
217 | {
218 | if (args < 2)
219 | {
220 | ReplyToCommand(client, "Usage: sm_navmesh_buildpath ");
221 | return Plugin_Handled;
222 | }
223 |
224 | if (!NavMesh_Exists()) return Plugin_Handled;
225 |
226 | char sStartAreaID[64], sGoalAreaID[64];
227 | GetCmdArg(1, sStartAreaID, sizeof(sStartAreaID));
228 | GetCmdArg(2, sGoalAreaID, sizeof(sGoalAreaID));
229 |
230 | CNavArea startArea = NavMesh_FindAreaByID(StringToInt(sStartAreaID));
231 | CNavArea goalArea = NavMesh_FindAreaByID(StringToInt(sGoalAreaID));
232 |
233 | if (startArea == INVALID_NAV_AREA || goalArea == INVALID_NAV_AREA) return Plugin_Handled;
234 |
235 | float flGoalPos[3];
236 | goalArea.GetCenter(flGoalPos);
237 |
238 | int iColor[4] = { 0, 255, 0, 255 };
239 |
240 | float flMaxPathLength = 0.0;
241 | if (args > 2)
242 | {
243 | char sMaxPathLength[64];
244 | GetCmdArg(3, sMaxPathLength, sizeof(sMaxPathLength));
245 | flMaxPathLength = StringToFloat(sMaxPathLength);
246 |
247 | if (flMaxPathLength < 0.0) return Plugin_Handled;
248 | }
249 |
250 | float flMaxStepSize = 0.0;
251 | if (args > 3)
252 | {
253 | char sMaxStepSize[64];
254 | GetCmdArg(4, sMaxStepSize, sizeof(sMaxStepSize));
255 | flMaxStepSize = StringToFloat(sMaxStepSize);
256 | }
257 |
258 | CNavArea closestArea = INVALID_NAV_AREA;
259 |
260 | Profiler profiler = CreateProfiler();
261 | profiler.Start();
262 |
263 | bool bBuiltPath = NavMesh_BuildPath(startArea, goalArea, flGoalPos, NavMeshShortestPathCost, _, closestArea, flMaxPathLength, flMaxStepSize);
264 |
265 | profiler.Stop();
266 | float flProfileTime = profiler.Time;
267 | delete profiler;
268 |
269 | if (client > 0)
270 | {
271 | PrintToChat(client, "Build path time: %f\nReached goal: %d", flProfileTime, bBuiltPath);
272 |
273 | CNavArea tempArea = closestArea;
274 | CNavArea parentArea = tempArea.Parent;
275 |
276 | int iNavDirection;
277 | float flHalfWidth;
278 | float flCenterPortal[3], flClosestPoint[3];
279 |
280 | ArrayList positions = new ArrayList(3);
281 | positions.PushArray(flGoalPos, 3);
282 |
283 | while (parentArea != INVALID_NAV_AREA)
284 | {
285 | float flTempAreaCenter[3], flParentAreaCenter[3];
286 | tempArea.GetCenter(flTempAreaCenter);
287 | parentArea.GetCenter(flParentAreaCenter);
288 |
289 | iNavDirection = tempArea.ComputeDirection(flParentAreaCenter);
290 | tempArea.ComputePortal(parentArea, iNavDirection, flCenterPortal, flHalfWidth);
291 | tempArea.ComputeClosestPointInPortal(parentArea, iNavDirection, flCenterPortal, flClosestPoint);
292 |
293 | flClosestPoint[2] = tempArea.GetZ(flClosestPoint);
294 | positions.PushArray(flClosestPoint, 3);
295 |
296 | tempArea = parentArea;
297 | parentArea = tempArea.Parent;
298 | }
299 |
300 | float flStartPos[3];
301 | startArea.GetCenter(flStartPos);
302 | positions.PushArray(flStartPos, 3);
303 |
304 | for (int i = positions.Length - 1; i > 0; i--)
305 | {
306 | float flFromPos[3], flToPos[3];
307 | positions.GetArray(i, flFromPos, 3);
308 | positions.GetArray(i - 1, flToPos, 3);
309 |
310 | TE_SetupBeamPoints(flFromPos, flToPos, g_iPathLaserModelIndex, g_iPathLaserModelIndex, 0, 30, 5.0, 5.0, 5.0, 5, 0.0, iColor, 30);
311 | TE_SendToClient(client);
312 | }
313 | }
314 | else
315 | {
316 | PrintToServer("Path built!\nBuild path time: %f\nReached goal: %d", flProfileTime, bBuiltPath);
317 | }
318 |
319 | return Plugin_Handled;
320 | }
321 |
322 | public bool TraceRayDontHitEntity(int entity,int mask, any data)
323 | {
324 | if (entity == data) return false;
325 | return true;
326 | }
--------------------------------------------------------------------------------
/addons/sourcemod/scripting/navmesh.sp:
--------------------------------------------------------------------------------
1 | // Huge huge HUGE props and credits to Anthony Iacono (pimpinjuice) and his Nav-file parser code,
2 | // which can be found here: https://github.com/AnthonyIacono/War3SourceV2/tree/master/Nav
3 |
4 | #include
5 | #include
6 | #include
7 | #include
8 |
9 | #define PLUGIN_VERSION "1.0.6b"
10 |
11 | public Plugin myinfo =
12 | {
13 | name = "SourcePawn Navigation Mesh Parser",
14 | author = "KitRifty, Benoist3012, (with modifications by sigsegv)",
15 | description = "A plugin that can read Valve's Navigation Mesh.",
16 | version = PLUGIN_VERSION,
17 | url = ""
18 | }
19 |
20 | #define UNSIGNED_INT_BYTE_SIZE 4
21 | #define UNSIGNED_CHAR_BYTE_SIZE 1
22 | #define UNSIGNED_SHORT_BYTE_SIZE 2
23 | #define FLOAT_BYTE_SIZE 4
24 |
25 | enum
26 | {
27 | NavMeshArea_ID = 0,
28 | NavMeshArea_Flags,
29 | NavMeshArea_PlaceID,
30 | NavMeshArea_X1,
31 | NavMeshArea_Y1,
32 | NavMeshArea_Z1,
33 | NavMeshArea_X2,
34 | NavMeshArea_Y2,
35 | NavMeshArea_Z2,
36 | NavMeshArea_CenterX,
37 | NavMeshArea_CenterY,
38 | NavMeshArea_CenterZ,
39 | NavMeshArea_InvDxCorners,
40 | NavMeshArea_InvDyCorners,
41 | NavMeshArea_NECornerZ,
42 | NavMeshArea_SWCornerZ,
43 |
44 | NavMeshArea_ConnectionsStartIndex,
45 | NavMeshArea_ConnectionsEndIndex,
46 |
47 | NavMeshArea_IncomingConnectionsStartIndex,
48 | NavMeshArea_IncomingConnectionsEndIndex,
49 |
50 | NavMeshArea_HidingSpotsStartIndex,
51 | NavMeshArea_HidingSpotsEndIndex,
52 |
53 | NavMeshArea_EncounterPathsStartIndex,
54 | NavMeshArea_EncounterPathsEndIndex,
55 |
56 | NavMeshArea_LadderConnectionsStartIndex,
57 | NavMeshArea_LadderConnectionsEndIndex,
58 |
59 | NavMeshArea_CornerLightIntensityNW,
60 | NavMeshArea_CornerLightIntensityNE,
61 | NavMeshArea_CornerLightIntensitySE,
62 | NavMeshArea_CornerLightIntensitySW,
63 |
64 | NavMeshArea_VisibleAreasStartIndex,
65 | NavMeshArea_VisibleAreasEndIndex,
66 |
67 | NavMeshArea_InheritVisibilityFrom,
68 | NavMeshArea_EarliestOccupyTimeFirstTeam,
69 | NavMeshArea_EarliestOccupyTimeSecondTeam,
70 | NavMeshArea_Blocked,
71 |
72 | // A* pathfinding
73 | NavMeshArea_Parent,
74 | NavMeshArea_ParentHow,
75 | NavMeshArea_CostSoFar,
76 | NavMeshArea_TotalCost,
77 | NavMeshArea_Marker,
78 | NavMeshArea_OpenMarker,
79 | NavMeshArea_PrevOpenIndex,
80 | NavMeshArea_NextOpenIndex,
81 | NavMeshArea_PathLengthSoFar,
82 |
83 | NavMeshArea_NearSearchMarker,
84 |
85 | TFNavArea_AttributeFlags,
86 |
87 | CSNavArea_ApproachInfoStartIndex,
88 | CSNavArea_ApproachInfoEndIndex,
89 |
90 | TerrorNavArea_SpawnAttributes,
91 |
92 | NavMeshArea_MaxStats
93 | };
94 |
95 | enum
96 | {
97 | NavMeshConnection_AreaIndex = 0,
98 | NavMeshConnection_Direction,
99 | NavMeshConnection_FromAreaIndex,
100 | NavMeshConnection_MaxStats
101 | };
102 |
103 | enum
104 | {
105 | NavMeshHidingSpot_ID = 0,
106 | NavMeshHidingSpot_X,
107 | NavMeshHidingSpot_Y,
108 | NavMeshHidingSpot_Z,
109 | NavMeshHidingSpot_Flags,
110 | NavMeshHidingSpot_AreaIndex,
111 | NavMeshHidingSpot_MaxStats
112 | };
113 |
114 | enum
115 | {
116 | NavMeshEncounterPath_FromAreaIndex = 0,
117 | NavMeshEncounterPath_FromDirection,
118 | NavMeshEncounterPath_ToAreaIndex,
119 | NavMeshEncounterPath_ToDirection,
120 | NavMeshEncounterPath_SpotsStartIndex,
121 | NavMeshEncounterPath_SpotsEndIndex,
122 | NavMeshEncounterPath_MaxStats
123 | };
124 |
125 | enum
126 | {
127 | NavMeshEncounterSpot_HidingSpotIndex = 0,
128 | NavMeshEncounterSpot_ParametricDistance,
129 | NavMeshEncounterSpot_MaxStats
130 | };
131 |
132 | enum
133 | {
134 | NavMeshLadderConnection_LadderIndex = 0,
135 | NavMeshLadderConnection_Direction,
136 | NavMeshLadderConnection_MaxStats
137 | };
138 |
139 | enum struct AreaBindInfo
140 | {
141 | int AreaIndex;
142 | int Attributes;
143 | }
144 |
145 | enum
146 | {
147 | NavMeshVisibleArea_Index = 0,
148 | NavMeshVisibleArea_Attributes,
149 | NavMeshVisibleArea_MaxStats
150 | };
151 |
152 | enum
153 | {
154 | NavMeshLadder_ID = 0,
155 | NavMeshLadder_Width,
156 | NavMeshLadder_Length,
157 | NavMeshLadder_TopX,
158 | NavMeshLadder_TopY,
159 | NavMeshLadder_TopZ,
160 | NavMeshLadder_BottomX,
161 | NavMeshLadder_BottomY,
162 | NavMeshLadder_BottomZ,
163 | NavMeshLadder_Direction,
164 | NavMeshLadder_TopForwardAreaIndex,
165 | NavMeshLadder_TopLeftAreaIndex,
166 | NavMeshLadder_TopRightAreaIndex,
167 | NavMeshLadder_TopBehindAreaIndex,
168 | NavMeshLadder_BottomAreaIndex,
169 | NavMeshLadder_MaxStats
170 | };
171 |
172 | enum
173 | {
174 | NavMeshGrid_ListStartIndex = 0,
175 | NavMeshGrid_ListEndIndex,
176 | NavMeshGrid_MaxStats
177 | };
178 |
179 | enum
180 | {
181 | NavMeshGridList_AreaIndex = 0,
182 | NavMeshGridList_Owner,
183 | NavMeshGridList_MaxStats
184 | };
185 |
186 | ArrayList g_hNavMeshPlaces;
187 | ArrayList g_hNavMeshAreas;
188 | ArrayList g_hNavMeshAreaConnections;
189 | ArrayList g_hNavMeshAreaIncomingConnections;
190 | ArrayList g_hNavMeshAreaHidingSpots;
191 | ArrayList g_hNavMeshAreaEncounterPaths;
192 | ArrayList g_hNavMeshAreaEncounterSpots;
193 | ArrayList g_hNavMeshAreaLadderConnections;
194 | ArrayList g_hNavMeshAreaVisibleAreas;
195 |
196 | ArrayList g_hNavMeshLadders;
197 |
198 | StringMap g_hNavMeshAreaIdToIndexMap;
199 | StringMap g_hNavMeshHidingSpotIdToIndexMap;
200 | StringMap g_hNavMeshLadderIdToIndexMap;
201 |
202 | int g_iNavMeshMagicNumber;
203 | int g_iNavMeshVersion;
204 | int g_iNavMeshSubVersion;
205 | int g_iNavMeshSaveBSPSize;
206 | bool g_bNavMeshAnalyzed;
207 |
208 | ArrayList g_hNavMeshGrid;
209 | ArrayList g_hNavMeshGridLists;
210 |
211 | float g_flNavMeshGridCellSize = 300.0;
212 | float g_flNavMeshMinX;
213 | float g_flNavMeshMinY;
214 | int g_iNavMeshGridSizeX;
215 | int g_iNavMeshGridSizeY;
216 |
217 | #define HighExtent 99999999.9
218 | #define LowExtent -99999999.9
219 |
220 | float g_flNavMeshExtentLow[2] = { HighExtent, HighExtent };
221 | float g_flNavMeshExtentHigh[2] = { LowExtent, LowExtent };
222 |
223 | bool g_bNavMeshBuilt = false;
224 |
225 | // For A* pathfinding.
226 | static int g_iNavMeshAreaOpenListIndex = -1;
227 | static int g_iNavMeshAreaOpenListTailIndex = -1;
228 | static int g_iNavMeshAreaMasterMarker = 0;
229 |
230 | GlobalForward g_hNavMeshPostLoadForward;
231 |
232 | // CSGO
233 | ArrayList g_hCSNavAreaApproachInfo;
234 |
235 | // L4D
236 | char g_TerrorNavMeshZombiePopulation[64];
237 | float g_TerrorNavMeshNavMaxViewDistance;
238 |
239 | public APLRes AskPluginLoad2(Handle myself, bool late, char[] error, int err_max)
240 | {
241 | RegPluginLibrary("navmesh");
242 |
243 | CreateNative("NavMesh_Exists", Native_NavMeshExists);
244 | CreateNative("NavMesh_GetMagicNumber", Native_NavMeshGetMagicNumber);
245 | CreateNative("NavMesh_GetVersion", Native_NavMeshGetVersion);
246 | CreateNative("NavMesh_GetSubVersion", Native_NavMeshGetSubVersion);
247 | CreateNative("NavMesh_GetSaveBSPSize", Native_NavMeshGetSaveBSPSize);
248 | CreateNative("NavMesh_IsAnalyzed", Native_NavMeshIsAnalyzed);
249 | //CreateNative("NavMesh_GetPlaces", Native_NavMeshGetPlaces);
250 | //CreateNative("NavMesh_GetAreas", Native_NavMeshGetAreas);
251 | //CreateNative("NavMesh_GetLadders", Native_NavMeshGetLadders);
252 |
253 | CreateNative("NavMesh_CollectSurroundingAreas", Native_NavMeshCollectSurroundingAreas);
254 | CreateNative("NavMesh_BuildPath", Native_NavMeshBuildPath);
255 |
256 | CreateNative("NavMesh_FindAreaByID", Native_NavMeshFindAreaByID);
257 | CreateNative("NavMesh_GetArea", Native_NavMeshGetArea);
258 | CreateNative("NavMesh_GetNearestArea", Native_NavMeshGetNearestArea);
259 |
260 | CreateNative("NavMesh_FindHidingSpotByID", Native_NavMeshFindHidingSpotByID);
261 | CreateNative("NavMesh_GetRandomHidingSpot", Native_NavMeshGetRandomHidingSpot);
262 |
263 | CreateNative("NavMesh_WorldToGridX", Native_NavMeshWorldToGridX);
264 | CreateNative("NavMesh_WorldToGridY", Native_NavMeshWorldToGridY);
265 | CreateNative("NavMesh_GetAreasOnGrid", Native_NavMeshGridGetAreas);
266 | CreateNative("NavMesh_GetGridSizeX", Native_NavMeshGetGridSizeX);
267 | CreateNative("NavMesh_GetGridSizeY", Native_NavMeshGetGridSizeY);
268 |
269 | CreateNative("NavMesh_GetGroundHeight", Native_NavMeshGetGroundHeight);
270 |
271 | CreateNative("NavMeshArea_GetMasterMarker", Native_NavMeshAreaGetMasterMarker);
272 | CreateNative("NavMeshArea_ChangeMasterMarker", Native_NavMeshAreaChangeMasterMarker);
273 |
274 | CreateNative("NavMeshArea_GetID", Native_NavMeshAreaGetID);
275 | CreateNative("NavMeshArea_GetFlags", Native_NavMeshAreaGetFlags);
276 | CreateNative("NavMeshArea_GetPlace", Native_NavMeshAreaGetPlace);
277 | CreateNative("NavMeshArea_GetCenter", Native_NavMeshAreaGetCenter);
278 | CreateNative("NavMeshArea_GetAdjacentList", Native_NavMeshAreaGetAdjacentList);
279 | CreateNative("NavMeshArea_GetLadderList", Native_NavMeshAreaGetLadderList);
280 | CreateNative("NavMeshArea_GetHidingSpots", Native_NavMeshAreaGetHidingSpots);
281 | CreateNative("NavMeshArea_GetClosestPointOnArea", Native_NavMeshAreaGetClosestPointOnArea);
282 | CreateNative("NavMeshArea_GetTotalCost", Native_NavMeshAreaGetTotalCost);
283 | CreateNative("NavMeshArea_GetParent", Native_NavMeshAreaGetParent);
284 | CreateNative("NavMeshArea_GetParentHow", Native_NavMeshAreaGetParentHow);
285 | CreateNative("NavMeshArea_SetParent", Native_NavMeshAreaSetParent);
286 | CreateNative("NavMeshArea_SetParentHow", Native_NavMeshAreaSetParentHow);
287 | CreateNative("NavMeshArea_GetCostSoFar", Native_NavMeshAreaGetCostSoFar);
288 | CreateNative("NavMeshArea_GetExtentLow", Native_NavMeshAreaGetExtentLow);
289 | CreateNative("NavMeshArea_GetExtentHigh", Native_NavMeshAreaGetExtentHigh);
290 | CreateNative("NavMeshArea_IsOverlappingPoint", Native_NavMeshAreaIsOverlappingPoint);
291 | CreateNative("NavMeshArea_IsOverlappingArea", Native_NavMeshAreaIsOverlappingArea);
292 | CreateNative("NavMeshArea_GetNECornerZ", Native_NavMeshAreaGetNECornerZ);
293 | CreateNative("NavMeshArea_GetSWCornerZ", Native_NavMeshAreaGetSWCornerZ);
294 | CreateNative("NavMeshArea_GetCorner", Native_NavMeshAreaGetCorner);
295 | CreateNative("NavMeshArea_GetZ", Native_NavMeshAreaGetZ);
296 | CreateNative("NavMeshArea_GetZFromXAndY", Native_NavMeshAreaGetZFromXAndY);
297 | CreateNative("NavMeshArea_IsEdge", Native_NavMeshAreaIsEdge);
298 | CreateNative("NavMeshArea_Contains", Native_NavMeshAreaContains);
299 | CreateNative("NavMeshArea_GetRandomPoint", Native_NavMeshAreaGetRandomPoint);
300 | CreateNative("NavMeshArea_IsConnected", Native_NavMeshAreaIsConnected);
301 | CreateNative("NavMeshArea_ComputePortal", Native_NavMeshAreaComputePortal);
302 | CreateNative("NavMeshArea_ComputeClosestPointInPortal", Native_NavMeshAreaComputeClosestPointInPortal);
303 | CreateNative("NavMeshArea_ComputeDirection", Native_NavMeshAreaComputeDirection);
304 | CreateNative("NavMeshArea_GetLightIntensity", Native_NavMeshAreaGetLightIntensity);
305 |
306 | CreateNative("CNavArea.GetAdjacentList", Native_NavMeshAreaGetAdjacentAreas);
307 | CreateNative("CNavArea.GetIncomingConnections", Native_NavMeshAreaGetIncomingConnections);
308 |
309 | CreateNative("NavHidingSpot_GetID", Native_NavHidingSpotGetID);
310 | CreateNative("NavHidingSpot_GetFlags", Native_NavHidingSpotGetFlags);
311 | CreateNative("NavHidingSpot_GetPosition", Native_NavHidingSpotGetPosition);
312 | CreateNative("NavHidingSpot_GetArea", Native_NavHidingSpotGetArea);
313 |
314 | CreateNative("NavMeshLadder_GetLength", Native_NavMeshLadderGetLength);
315 | CreateNative("NavMeshLadder_GetWidth", Native_NavMeshLadderGetWidth);
316 | CreateNative("NavMeshLadder_GetTopForwardArea", Native_NavMeshLadderGetTopForwardArea);
317 | CreateNative("NavMeshLadder_GetTopLeftArea", Native_NavMeshLadderGetTopLeftArea);
318 | CreateNative("NavMeshLadder_GetTopRightArea", Native_NavMeshLadderGetTopRightArea);
319 | CreateNative("NavMeshLadder_GetTopBehindArea", Native_NavMeshLadderGetTopBehindArea);
320 | CreateNative("NavMeshLadder_GetBottomArea", Native_NavMeshLadderGetBottomArea);
321 | CreateNative("NavMeshLadder_GetTop", Native_NavMeshLadderGetTop);
322 | CreateNative("NavMeshLadder_GetBottom", Native_NavMeshLadderGetBottom);
323 |
324 | CreateNative("NavSpotEncounter_GetFrom", Native_NavSpotEncounterGetFrom);
325 | CreateNative("NavSpotEncounter_GetFromDirection", Native_NavSpotEncounterGetFromDirection);
326 | CreateNative("NavSpotEncounter_GetTo", Native_NavSpotEncounterGetTo);
327 | CreateNative("NavSpotEncounter_GetToDirection", Native_NavSpotEncounterGetToDirection);
328 | CreateNative("NavSpotEncounter_GetSpots", Native_NavSpotEncounterGetSpots);
329 |
330 | CreateNative("NavSpotOrder_GetHidingSpot", Native_NavSpotOrderGetHidingSpot);
331 | CreateNative("NavSpotOrder_GetParametricDistance", Native_NavSpotOrderGetParametricDistance);
332 |
333 | switch (GetEngineVersion())
334 | {
335 | case Engine_TF2:
336 | {
337 | CreateNative("CTFNavArea.AttributeFlags.get", Native_TFNavAreaGetAttributeFlags);
338 | }
339 | case Engine_CSGO, Engine_CSS:
340 | {
341 | CreateNative("CCSNavArea.GetApproachInfoList", Native_CSNavAreaGetApproachInfoList);
342 | }
343 | case Engine_Left4Dead2:
344 | {
345 | CreateNative("TerrorNavMesh.GetZombiePopulation", Native_TerrorNavMeshGetZombiePopulation);
346 | CreateNative("TerrorNavMesh.NavMaxViewDistance.get", Native_TerrorNavMeshGetNavMaxViewDistance);
347 | CreateNative("TerrorNavArea.SpawnAttributes.get", Native_TerrorNavAreaGetSpawnAttributes);
348 | }
349 | }
350 | }
351 |
352 | public void OnPluginStart()
353 | {
354 | g_hNavMeshPlaces = new ArrayList(256);
355 | g_hNavMeshAreas = new ArrayList(NavMeshArea_MaxStats);
356 | g_hNavMeshAreaConnections = new ArrayList(NavMeshConnection_MaxStats);
357 | g_hNavMeshAreaIncomingConnections = new ArrayList(NavMeshConnection_MaxStats);
358 | g_hNavMeshAreaHidingSpots = new ArrayList(NavMeshHidingSpot_MaxStats);
359 | g_hNavMeshAreaEncounterPaths = new ArrayList(NavMeshEncounterPath_MaxStats);
360 | g_hNavMeshAreaEncounterSpots = new ArrayList(NavMeshEncounterSpot_MaxStats);
361 | g_hNavMeshAreaLadderConnections = new ArrayList(NavMeshLadderConnection_MaxStats);
362 | g_hNavMeshAreaVisibleAreas = new ArrayList(NavMeshVisibleArea_MaxStats);
363 |
364 | g_hNavMeshLadders = new ArrayList(NavMeshLadder_MaxStats);
365 |
366 | g_hNavMeshGrid = new ArrayList(NavMeshGrid_MaxStats);
367 | g_hNavMeshGridLists = new ArrayList(NavMeshGridList_MaxStats);
368 |
369 | g_hNavMeshAreaIdToIndexMap = new StringMap();
370 | g_hNavMeshHidingSpotIdToIndexMap = new StringMap();
371 | g_hNavMeshLadderIdToIndexMap = new StringMap();
372 |
373 | HookEventEx("nav_blocked", Event_NavAreaBlocked);
374 |
375 | g_hNavMeshPostLoadForward = new GlobalForward("OnNavMeshLoaded", ET_Ignore, Param_Cell);
376 |
377 | switch (GetEngineVersion())
378 | {
379 | case Engine_CSGO, Engine_CSS:
380 | {
381 | g_hCSNavAreaApproachInfo = new ArrayList(sizeof(CCSNavArea_ApproachInfo));
382 | }
383 | case Engine_Left4Dead2:
384 | {
385 | }
386 | }
387 | }
388 |
389 | public void OnMapStart()
390 | {
391 | NavMeshDestroy();
392 |
393 | char sMap[256];
394 | GetCurrentMap(sMap, sizeof(sMap));
395 |
396 | g_bNavMeshBuilt = NavMeshLoad(sMap);
397 | }
398 |
399 | public void Event_NavAreaBlocked(Event event, const char[] name, bool dB)
400 | {
401 | if (!g_bNavMeshBuilt) return;
402 |
403 | int iAreaID = event.GetInt("area");
404 | int iAreaIndex = NavMeshFindAreaByID(iAreaID); // Wow, this isn't terrible anymore.
405 | if (iAreaIndex != -1)
406 | {
407 | bool bBlocked = view_as(event.GetInt("blocked"));
408 | g_hNavMeshAreas.Set(iAreaIndex, bBlocked, NavMeshArea_Blocked);
409 | }
410 | }
411 |
412 | stock int OppositeDirection(int iNavDirection)
413 | {
414 | switch (iNavDirection)
415 | {
416 | case NAV_DIR_NORTH: return NAV_DIR_SOUTH;
417 | case NAV_DIR_SOUTH: return NAV_DIR_NORTH;
418 | case NAV_DIR_EAST: return NAV_DIR_WEST;
419 | case NAV_DIR_WEST: return NAV_DIR_EAST;
420 | }
421 |
422 | return NAV_DIR_NORTH;
423 | }
424 |
425 | stock float NavMeshAreaComputeAdjacentConnectionHeightChange(int iAreaIndex, int iTargetAreaIndex)
426 | {
427 | bool bFoundArea = false;
428 | int iNavDirection;
429 |
430 | for (iNavDirection = 0; iNavDirection < NAV_DIR_COUNT; iNavDirection++)
431 | {
432 | ArrayStack hConnections = NavMeshAreaGetAdjacentList(iAreaIndex, iNavDirection);
433 | if (hConnections == null) continue;
434 |
435 | while (!hConnections.Empty)
436 | {
437 | int iTempAreaIndex = -1;
438 | PopStackCell(hConnections, iTempAreaIndex);
439 |
440 | if (iTempAreaIndex == iTargetAreaIndex)
441 | {
442 | bFoundArea = true;
443 | break;
444 | }
445 | }
446 |
447 | delete hConnections;
448 |
449 | if (bFoundArea) break;
450 | }
451 |
452 | if (!bFoundArea) return 99999999.9;
453 |
454 | float flMyEdge[3];
455 | float flHalfWidth;
456 | NavMeshAreaComputePortal(iAreaIndex, iTargetAreaIndex, iNavDirection, flMyEdge, flHalfWidth);
457 |
458 | float flOtherEdge[3];
459 | NavMeshAreaComputePortal(iAreaIndex, iTargetAreaIndex, OppositeDirection(iNavDirection), flOtherEdge, flHalfWidth);
460 |
461 | return flOtherEdge[2] - flMyEdge[2];
462 | }
463 |
464 | ArrayStack NavMeshCollectSurroundingAreas(int iStartAreaIndex, float flTravelDistanceLimit=1500.0, float flMaxStepUpLimit=StepHeight, float flMaxDropDownLimit=100.0)
465 | {
466 | if (!g_bNavMeshBuilt)
467 | {
468 | LogError("Could not search surrounding areas because the nav mesh does not exist!");
469 | return null;
470 | }
471 |
472 | if (iStartAreaIndex == -1)
473 | {
474 | LogError("Could not search surrounding areas because the starting area does not exist!");
475 | return null;
476 | }
477 |
478 | ArrayStack hNearAreasList = new ArrayStack();
479 |
480 | NavMeshAreaClearSearchLists();
481 |
482 | NavMeshAreaAddToOpenList(iStartAreaIndex);
483 | g_hNavMeshAreas.Set(iStartAreaIndex, 0, NavMeshArea_TotalCost);
484 | g_hNavMeshAreas.Set(iStartAreaIndex, 0, NavMeshArea_CostSoFar);
485 | g_hNavMeshAreas.Set(iStartAreaIndex, -1, NavMeshArea_Parent);
486 | g_hNavMeshAreas.Set(iStartAreaIndex, NUM_TRAVERSE_TYPES, NavMeshArea_ParentHow);
487 | NavMeshAreaMark(iStartAreaIndex);
488 |
489 | while (!NavMeshAreaIsOpenListEmpty())
490 | {
491 | int iAreaIndex = NavMeshAreaPopOpenList();
492 | if (flTravelDistanceLimit > 0.0 &&
493 | float(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_CostSoFar)) > flTravelDistanceLimit)
494 | {
495 | continue;
496 | }
497 |
498 | int iAreaParent = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Parent);
499 | if (iAreaParent != -1)
500 | {
501 | float flDeltaZ = NavMeshAreaComputeAdjacentConnectionHeightChange(iAreaParent, iAreaIndex);
502 | if (flDeltaZ > flMaxStepUpLimit) continue;
503 | if (flDeltaZ < -flMaxDropDownLimit) continue;
504 | }
505 |
506 | hNearAreasList.Push(iAreaIndex);
507 |
508 | NavMeshAreaMark(iAreaIndex);
509 |
510 | for (int iNavDir = 0; iNavDir < NAV_DIR_COUNT; iNavDir++)
511 | {
512 | ArrayStack hConnections = NavMeshAreaGetAdjacentList(iAreaIndex, iNavDir);
513 | if (hConnections != null)
514 | {
515 | while (!hConnections.Empty)
516 | {
517 | int iAdjacentAreaIndex = -1;
518 | PopStackCell(hConnections, iAdjacentAreaIndex);
519 |
520 | if (view_as(g_hNavMeshAreas.Get(iAdjacentAreaIndex, NavMeshArea_Blocked))) continue;
521 |
522 | if (!NavMeshAreaIsMarked(iAdjacentAreaIndex))
523 | {
524 | g_hNavMeshAreas.Set(iAdjacentAreaIndex, 0, NavMeshArea_TotalCost);
525 | g_hNavMeshAreas.Set(iAdjacentAreaIndex, iAreaIndex, NavMeshArea_Parent);
526 | g_hNavMeshAreas.Set(iAdjacentAreaIndex, iNavDir, NavMeshArea_ParentHow);
527 |
528 | int iDistAlong = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_CostSoFar);
529 |
530 | float flAdjacentAreaCenter[3];
531 | float flAreaCenter[3];
532 | NavMeshAreaGetCenter(iAreaIndex, flAreaCenter);
533 | NavMeshAreaGetCenter(iAdjacentAreaIndex, flAdjacentAreaCenter);
534 |
535 | iDistAlong += RoundToFloor(GetVectorDistance(flAdjacentAreaCenter, flAreaCenter));
536 | g_hNavMeshAreas.Set(iAdjacentAreaIndex, iDistAlong, NavMeshArea_CostSoFar);
537 | NavMeshAreaAddToOpenList(iAdjacentAreaIndex);
538 | }
539 | }
540 |
541 | delete hConnections;
542 | }
543 | }
544 | }
545 |
546 | return hNearAreasList;
547 | }
548 |
549 | bool NavMeshBuildPath(int iStartAreaIndex,
550 | int iGoalAreaIndex,
551 | const float flGoalPos[3],
552 | Handle hCostFunctionPlugin,
553 | NavPathCostFunctor iCostFunction,
554 | any iCostData=0,
555 | int &iClosestAreaIndex=-1,
556 | float flMaxPathLength=0.0,
557 | float flMaxStepSize=0.0)
558 | {
559 | if (!g_bNavMeshBuilt)
560 | {
561 | return false;
562 | }
563 |
564 | iClosestAreaIndex = iStartAreaIndex;
565 |
566 | if (iStartAreaIndex == -1)
567 | {
568 | return false;
569 | }
570 |
571 | g_hNavMeshAreas.Set(iStartAreaIndex, -1, NavMeshArea_Parent);
572 | g_hNavMeshAreas.Set(iStartAreaIndex, NUM_TRAVERSE_TYPES, NavMeshArea_ParentHow);
573 |
574 | if (iGoalAreaIndex == -1)
575 | {
576 | return false;
577 | }
578 |
579 | if (iStartAreaIndex == iGoalAreaIndex) return true;
580 |
581 | // Start the search.
582 | NavMeshAreaClearSearchLists();
583 |
584 | // Compute estimate of path length.
585 | float flStartAreaCenter[3];
586 | NavMeshAreaGetCenter(iStartAreaIndex, flStartAreaCenter);
587 |
588 | int iStartTotalCost = RoundFloat(GetVectorDistance(flStartAreaCenter, flGoalPos));
589 | g_hNavMeshAreas.Set(iStartAreaIndex, iStartTotalCost, NavMeshArea_TotalCost);
590 |
591 | int iInitCost = 0;
592 |
593 | Call_StartFunction(hCostFunctionPlugin, iCostFunction);
594 | Call_PushCell(iStartAreaIndex);
595 | Call_PushCell(-1);
596 | Call_PushCell(-1);
597 | Call_PushCell(iCostData);
598 | Call_Finish(iInitCost);
599 |
600 | if (iInitCost < 0) return false;
601 |
602 | g_hNavMeshAreas.Set(iStartAreaIndex, 0, NavMeshArea_CostSoFar);
603 | g_hNavMeshAreas.Set(iStartAreaIndex, 0.0, NavMeshArea_PathLengthSoFar);
604 | NavMeshAreaAddToOpenList(iStartAreaIndex);
605 |
606 | int iClosestAreaDist = iStartTotalCost;
607 |
608 | bool bHaveMaxPathLength = (flMaxPathLength != 0.0);
609 |
610 | // Perform A* search.
611 | while (!NavMeshAreaIsOpenListEmpty())
612 | {
613 | int iAreaIndex = NavMeshAreaPopOpenList();
614 |
615 | if (view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Blocked)))
616 | {
617 | // Don't consider blocked areas.
618 | continue;
619 | }
620 |
621 | if (iAreaIndex == iGoalAreaIndex ||
622 | (iGoalAreaIndex == -1 && NavMeshAreaContains(iAreaIndex, flGoalPos)))
623 | {
624 | iClosestAreaIndex = iGoalAreaIndex;
625 |
626 | return true;
627 | }
628 |
629 | // No support for elevator areas yet.
630 | static int SEARCH_FLOOR = 0;
631 | static int SEARCH_LADDERS = 1;
632 |
633 | int iSearchWhere = SEARCH_FLOOR;
634 | int iSearchDir = NAV_DIR_NORTH;
635 |
636 | ArrayStack hFloorList = NavMeshAreaGetAdjacentList(iAreaIndex, iSearchDir);
637 |
638 | bool bLadderUp = true;
639 | ArrayStack hLadderList = null;
640 | int iLadderTopDir = 0;
641 |
642 | for (;;)
643 | {
644 | int iNewAreaIndex = -1;
645 | int iNavTraverseHow = 0;
646 | int iLadderIndex = -1;
647 |
648 | if (iSearchWhere == SEARCH_FLOOR)
649 | {
650 | if (hFloorList == null || hFloorList.Empty)
651 | {
652 | iSearchDir++;
653 | if (hFloorList != null) delete hFloorList;
654 |
655 | if (iSearchDir == NAV_DIR_COUNT)
656 | {
657 | iSearchWhere = SEARCH_LADDERS;
658 |
659 | hLadderList = NavMeshAreaGetLadderList(iAreaIndex, NAV_LADDER_DIR_UP);
660 | iLadderTopDir = 0;
661 | }
662 | else
663 | {
664 | hFloorList = NavMeshAreaGetAdjacentList(iAreaIndex, iSearchDir);
665 | }
666 |
667 | continue;
668 | }
669 |
670 | PopStackCell(hFloorList, iNewAreaIndex);
671 | iNavTraverseHow = iSearchDir;
672 | }
673 | else if (iSearchWhere == SEARCH_LADDERS)
674 | {
675 | if (hLadderList == null || hLadderList.Empty)
676 | {
677 | if (hLadderList != null) delete hLadderList;
678 |
679 | if (!bLadderUp)
680 | {
681 | iLadderIndex = -1;
682 | break;
683 | }
684 | else
685 | {
686 | bLadderUp = false;
687 | hLadderList = NavMeshAreaGetLadderList(iAreaIndex, NAV_LADDER_DIR_DOWN);
688 | }
689 |
690 | continue;
691 | }
692 |
693 | PopStackCell(hLadderList, iLadderIndex);
694 |
695 | if (bLadderUp)
696 | {
697 | switch (iLadderTopDir)
698 | {
699 | case 0:
700 | {
701 | iNewAreaIndex = g_hNavMeshLadders.Get(iLadderIndex, NavMeshLadder_TopForwardAreaIndex);
702 | }
703 | case 1:
704 | {
705 | iNewAreaIndex = g_hNavMeshLadders.Get(iLadderIndex, NavMeshLadder_TopLeftAreaIndex);
706 | }
707 | case 2:
708 | {
709 | iNewAreaIndex = g_hNavMeshLadders.Get(iLadderIndex, NavMeshLadder_TopRightAreaIndex);
710 | }
711 | default:
712 | {
713 | iLadderTopDir = 0;
714 | continue;
715 | }
716 | }
717 |
718 | iNavTraverseHow = GO_LADDER_UP;
719 | iLadderTopDir++;
720 | }
721 | else
722 | {
723 | iNewAreaIndex = g_hNavMeshLadders.Get(iLadderIndex, NavMeshLadder_BottomAreaIndex);
724 | iNavTraverseHow = GO_LADDER_DOWN;
725 | }
726 |
727 | if (iNewAreaIndex == -1) continue;
728 | }
729 |
730 | if (g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Parent) == iNewAreaIndex)
731 | {
732 | // Don't backtrack.
733 | continue;
734 | }
735 |
736 | if (iNewAreaIndex == iAreaIndex)
737 | {
738 | continue;
739 | }
740 |
741 | if (view_as(g_hNavMeshAreas.Get(iNewAreaIndex, NavMeshArea_Blocked)))
742 | {
743 | // Don't consider blocked areas.
744 | continue;
745 | }
746 |
747 | int iNewCostSoFar = 0;
748 |
749 | Call_StartFunction(hCostFunctionPlugin, iCostFunction);
750 | Call_PushCell(iNewAreaIndex);
751 | Call_PushCell(iAreaIndex);
752 | Call_PushCell(iLadderIndex);
753 | Call_PushCell(iCostData);
754 | Call_Finish(iNewCostSoFar);
755 |
756 | if (iNewCostSoFar < 0) continue;
757 |
758 | if (flMaxStepSize > 0.0)
759 | {
760 | float flDeltaZ = NavMeshAreaComputeAdjacentConnectionHeightChange(iAreaIndex, iNewAreaIndex);
761 | if (flDeltaZ > flMaxStepSize) continue;
762 | }
763 |
764 | float flNewAreaCenter[3];
765 | NavMeshAreaGetCenter(iNewAreaIndex, flNewAreaCenter);
766 |
767 | if (bHaveMaxPathLength)
768 | {
769 | float flAreaCenter[3];
770 | NavMeshAreaGetCenter(iAreaIndex, flAreaCenter);
771 |
772 | float flDeltaLength = GetVectorDistance(flNewAreaCenter, flAreaCenter);
773 | float flNewLengthSoFar = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_PathLengthSoFar)) + flDeltaLength;
774 | if (flNewLengthSoFar > flMaxPathLength)
775 | {
776 | continue;
777 | }
778 |
779 | g_hNavMeshAreas.Set(iNewAreaIndex, flNewLengthSoFar, NavMeshArea_PathLengthSoFar);
780 | }
781 |
782 | if ((NavMeshAreaIsOpen(iNewAreaIndex) || NavMeshAreaIsClosed(iNewAreaIndex)) &&
783 | g_hNavMeshAreas.Get(iNewAreaIndex, NavMeshArea_CostSoFar) <= iNewCostSoFar)
784 | {
785 | continue;
786 | }
787 | else
788 | {
789 | int iNewCostRemaining = RoundFloat(GetVectorDistance(flNewAreaCenter, flGoalPos));
790 |
791 | if (iClosestAreaIndex != -1 && iNewCostRemaining < iClosestAreaDist)
792 | {
793 | iClosestAreaIndex = iNewAreaIndex;
794 | iClosestAreaDist = iNewCostRemaining;
795 | }
796 |
797 | g_hNavMeshAreas.Set(iNewAreaIndex, iNewCostSoFar, NavMeshArea_CostSoFar);
798 | g_hNavMeshAreas.Set(iNewAreaIndex, iNewCostSoFar + iNewCostRemaining, NavMeshArea_TotalCost);
799 |
800 | /*
801 | if (NavMeshAreaIsClosed(iNewAreaIndex))
802 | {
803 | NavMeshAreaRemoveFromClosedList(iNewAreaIndex);
804 | }
805 | */
806 |
807 | if (NavMeshAreaIsOpen(iNewAreaIndex))
808 | {
809 | NavMeshAreaUpdateOnOpenList(iNewAreaIndex);
810 | }
811 | else
812 | {
813 | NavMeshAreaAddToOpenList(iNewAreaIndex);
814 | }
815 |
816 | g_hNavMeshAreas.Set(iNewAreaIndex, iAreaIndex, NavMeshArea_Parent);
817 | g_hNavMeshAreas.Set(iNewAreaIndex, iNavTraverseHow, NavMeshArea_ParentHow);
818 | }
819 | }
820 |
821 | NavMeshAreaAddToClosedList(iAreaIndex);
822 | }
823 |
824 | return false;
825 | }
826 |
827 | NavMeshAreaClearSearchLists()
828 | {
829 | g_iNavMeshAreaMasterMarker++;
830 | g_iNavMeshAreaOpenListIndex = -1;
831 | g_iNavMeshAreaOpenListTailIndex = -1;
832 | }
833 |
834 | bool NavMeshAreaIsMarked(iAreaIndex)
835 | {
836 | return view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Marker) == g_iNavMeshAreaMasterMarker);
837 | }
838 |
839 | void NavMeshAreaMark(iAreaIndex)
840 | {
841 | g_hNavMeshAreas.Set(iAreaIndex, g_iNavMeshAreaMasterMarker, NavMeshArea_Marker);
842 | }
843 |
844 | bool NavMeshAreaIsOpen(iAreaIndex)
845 | {
846 | return view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_OpenMarker) == g_iNavMeshAreaMasterMarker);
847 | }
848 |
849 | bool NavMeshAreaIsOpenListEmpty()
850 | {
851 | return view_as(g_iNavMeshAreaOpenListIndex == -1);
852 | }
853 |
854 | void NavMeshAreaAddToOpenList(int iAreaIndex)
855 | {
856 | if (NavMeshAreaIsOpen(iAreaIndex)) return;
857 |
858 | g_hNavMeshAreas.Set(iAreaIndex, g_iNavMeshAreaMasterMarker, NavMeshArea_OpenMarker);
859 |
860 | if (g_iNavMeshAreaOpenListIndex == -1)
861 | {
862 | g_iNavMeshAreaOpenListIndex = iAreaIndex;
863 | g_iNavMeshAreaOpenListTailIndex = iAreaIndex;
864 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_PrevOpenIndex);
865 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_NextOpenIndex);
866 | return;
867 | }
868 |
869 | int iTotalCost = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_TotalCost);
870 |
871 | int iTempAreaIndex = -1;
872 | int iLastAreaIndex = -1;
873 | for (iTempAreaIndex = g_iNavMeshAreaOpenListIndex; iTempAreaIndex != -1; iTempAreaIndex = g_hNavMeshAreas.Get(iTempAreaIndex, NavMeshArea_NextOpenIndex))
874 | {
875 | if (iTotalCost < g_hNavMeshAreas.Get(iTempAreaIndex, NavMeshArea_TotalCost)) break;
876 | iLastAreaIndex = iTempAreaIndex;
877 | }
878 |
879 | if (iTempAreaIndex != -1)
880 | {
881 | int iPrevOpenIndex = g_hNavMeshAreas.Get(iTempAreaIndex, NavMeshArea_PrevOpenIndex);
882 | g_hNavMeshAreas.Set(iAreaIndex, iPrevOpenIndex, NavMeshArea_PrevOpenIndex);
883 |
884 | if (iPrevOpenIndex != -1)
885 | {
886 | g_hNavMeshAreas.Set(iPrevOpenIndex, iAreaIndex, NavMeshArea_NextOpenIndex);
887 | }
888 | else
889 | {
890 | g_iNavMeshAreaOpenListIndex = iAreaIndex;
891 | }
892 |
893 | g_hNavMeshAreas.Set(iAreaIndex, iTempAreaIndex, NavMeshArea_NextOpenIndex);
894 | g_hNavMeshAreas.Set(iTempAreaIndex, iAreaIndex, NavMeshArea_PrevOpenIndex);
895 | }
896 | else
897 | {
898 | g_hNavMeshAreas.Set(iLastAreaIndex, iAreaIndex, NavMeshArea_NextOpenIndex);
899 | g_hNavMeshAreas.Set(iAreaIndex, iLastAreaIndex, NavMeshArea_PrevOpenIndex);
900 |
901 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_NextOpenIndex);
902 |
903 | g_iNavMeshAreaOpenListTailIndex = iAreaIndex;
904 | }
905 | }
906 |
907 | stock void NavMeshAreaAddToOpenListTail(int iAreaIndex)
908 | {
909 | if (NavMeshAreaIsOpen(iAreaIndex)) return;
910 |
911 | g_hNavMeshAreas.Set(iAreaIndex, g_iNavMeshAreaMasterMarker, NavMeshArea_OpenMarker);
912 |
913 | if (g_iNavMeshAreaOpenListIndex == -1)
914 | {
915 | g_iNavMeshAreaOpenListIndex = iAreaIndex;
916 | g_iNavMeshAreaOpenListTailIndex = iAreaIndex;
917 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_PrevOpenIndex);
918 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_NextOpenIndex);
919 | return;
920 | }
921 |
922 | g_hNavMeshAreas.Set(g_iNavMeshAreaOpenListTailIndex, iAreaIndex, NavMeshArea_NextOpenIndex);
923 |
924 | g_hNavMeshAreas.Set(iAreaIndex, g_iNavMeshAreaOpenListTailIndex, NavMeshArea_PrevOpenIndex);
925 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_NextOpenIndex);
926 |
927 | g_iNavMeshAreaOpenListTailIndex = iAreaIndex;
928 | }
929 |
930 | void NavMeshAreaUpdateOnOpenList(int iAreaIndex)
931 | {
932 | int iTotalCost = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_TotalCost);
933 |
934 | int iPrevIndex = -1;
935 |
936 | while ((iPrevIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_PrevOpenIndex)) != -1 &&
937 | iTotalCost < (g_hNavMeshAreas.Get(iPrevIndex, NavMeshArea_TotalCost)))
938 | {
939 | int iOtherIndex = iPrevIndex;
940 | int iBeforeIndex = g_hNavMeshAreas.Get(iPrevIndex, NavMeshArea_PrevOpenIndex);
941 | int iAfterIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_NextOpenIndex);
942 |
943 | g_hNavMeshAreas.Set(iAreaIndex, iPrevIndex, NavMeshArea_NextOpenIndex);
944 | g_hNavMeshAreas.Set(iAreaIndex, iBeforeIndex, NavMeshArea_PrevOpenIndex);
945 |
946 | g_hNavMeshAreas.Set(iOtherIndex, iAreaIndex, NavMeshArea_PrevOpenIndex);
947 | g_hNavMeshAreas.Set(iOtherIndex, iAfterIndex, NavMeshArea_NextOpenIndex);
948 |
949 | if (iBeforeIndex != -1)
950 | {
951 | g_hNavMeshAreas.Set(iBeforeIndex, iAreaIndex, NavMeshArea_NextOpenIndex);
952 | }
953 | else
954 | {
955 | g_iNavMeshAreaOpenListIndex = iAreaIndex;
956 | }
957 |
958 | if (iAfterIndex != -1)
959 | {
960 | g_hNavMeshAreas.Set(iAfterIndex, iOtherIndex, NavMeshArea_PrevOpenIndex);
961 | }
962 | else
963 | {
964 | g_iNavMeshAreaOpenListTailIndex = iAreaIndex;
965 | }
966 | }
967 | }
968 |
969 | void NavMeshAreaRemoveFromOpenList(int iAreaIndex)
970 | {
971 | if (g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_OpenMarker) == 0) return;
972 |
973 | int iPrevOpenIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_PrevOpenIndex);
974 | int iNextOpenIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_NextOpenIndex);
975 |
976 | if (iPrevOpenIndex != -1)
977 | {
978 | g_hNavMeshAreas.Set(iPrevOpenIndex, iNextOpenIndex, NavMeshArea_NextOpenIndex);
979 | }
980 | else
981 | {
982 | g_iNavMeshAreaOpenListIndex = iNextOpenIndex;
983 | }
984 |
985 | if (iNextOpenIndex != -1)
986 | {
987 | g_hNavMeshAreas.Set(iNextOpenIndex, iPrevOpenIndex, NavMeshArea_PrevOpenIndex);
988 | }
989 | else
990 | {
991 | g_iNavMeshAreaOpenListTailIndex = iPrevOpenIndex;
992 | }
993 |
994 | g_hNavMeshAreas.Set(iAreaIndex, 0, NavMeshArea_OpenMarker);
995 | }
996 |
997 | int NavMeshAreaPopOpenList()
998 | {
999 | if (g_iNavMeshAreaOpenListIndex != -1)
1000 | {
1001 | int iOpenListIndex = g_iNavMeshAreaOpenListIndex;
1002 |
1003 | NavMeshAreaRemoveFromOpenList(iOpenListIndex);
1004 | g_hNavMeshAreas.Set(iOpenListIndex, -1, NavMeshArea_PrevOpenIndex);
1005 | g_hNavMeshAreas.Set(iOpenListIndex, -1, NavMeshArea_NextOpenIndex);
1006 |
1007 | return iOpenListIndex;
1008 | }
1009 |
1010 | return -1;
1011 | }
1012 |
1013 | bool NavMeshAreaIsClosed(int iAreaIndex)
1014 | {
1015 | if (NavMeshAreaIsMarked(iAreaIndex) && !NavMeshAreaIsOpen(iAreaIndex)) return true;
1016 | return false;
1017 | }
1018 |
1019 | void NavMeshAreaAddToClosedList(int iAreaIndex)
1020 | {
1021 | NavMeshAreaMark(iAreaIndex);
1022 | }
1023 |
1024 | /*
1025 | static NavMeshAreaRemoveFromClosedList(iAreaIndex)
1026 | {
1027 | }
1028 | */
1029 |
1030 | int g_AreaConnectionsListStartIndex = 0;
1031 | int g_AreaHidingSpotsListStartIndex = 0;
1032 | int g_AreaEncounterPathsListStartIndex = 0;
1033 | int g_AreaEncounterSpotsListStartIndex = 0;
1034 | int g_AreaLadderConnectionsListStartIndex = 0;
1035 | int g_AreaVisibleAreasListStartIndex = 0;
1036 |
1037 | bool NavMeshLoad(const char[] sMapName)
1038 | {
1039 | g_hNavMeshAreas.Clear();
1040 | g_hNavMeshAreaConnections.Clear();
1041 | g_hNavMeshAreaIncomingConnections.Clear();
1042 | g_hNavMeshAreaEncounterPaths.Clear();
1043 | g_hNavMeshAreaHidingSpots.Clear();
1044 | g_hNavMeshAreaLadderConnections.Clear();
1045 | g_hNavMeshLadders.Clear();
1046 |
1047 | g_hNavMeshAreaIdToIndexMap.Clear();
1048 | g_hNavMeshHidingSpotIdToIndexMap.Clear();
1049 | g_hNavMeshLadderIdToIndexMap.Clear();
1050 |
1051 | g_flNavMeshExtentLow[0] = LowExtent; g_flNavMeshExtentLow[1] = LowExtent;
1052 | g_flNavMeshExtentHigh[0] = HighExtent; g_flNavMeshExtentHigh[1] = HighExtent;
1053 |
1054 | g_AreaConnectionsListStartIndex = 0;
1055 | g_AreaHidingSpotsListStartIndex = 0;
1056 | g_AreaEncounterPathsListStartIndex = 0;
1057 | g_AreaEncounterSpotsListStartIndex = 0;
1058 | g_AreaLadderConnectionsListStartIndex = 0;
1059 | g_AreaVisibleAreasListStartIndex = 0;
1060 |
1061 | switch (GetEngineVersion())
1062 | {
1063 | case Engine_CSGO, Engine_CSS:
1064 | {
1065 | g_hCSNavAreaApproachInfo.Clear();
1066 | }
1067 | case Engine_Left4Dead2:
1068 | {
1069 | strcopy(g_TerrorNavMeshZombiePopulation, sizeof(g_TerrorNavMeshZombiePopulation), "");
1070 | g_TerrorNavMeshNavMaxViewDistance = 0.0;
1071 | }
1072 | }
1073 |
1074 | char sNavFilePath[PLATFORM_MAX_PATH];
1075 | Format(sNavFilePath, sizeof(sNavFilePath), "maps\\%s.nav", sMapName);
1076 |
1077 | File hFile = OpenFile(sNavFilePath, "rb");
1078 | if (hFile == null)
1079 | {
1080 | // Try opening it from the Valve file system.
1081 | hFile = OpenFile(sNavFilePath, "rb", true, NULL_STRING);
1082 | }
1083 |
1084 | if (hFile == null)
1085 | {
1086 | // Try finding the file ourselves.
1087 | new bool:bFound = false;
1088 |
1089 | switch (GetEngineVersion())
1090 | {
1091 | case Engine_CSGO:
1092 | {
1093 | // Search addon directories.
1094 | DirectoryListing hDir = OpenDirectory("addons");
1095 | if (hDir != null)
1096 | {
1097 | LogMessage("Couldn't find .nav file in maps folder, checking addon folders...");
1098 |
1099 | char sFolderName[PLATFORM_MAX_PATH];
1100 | FileType iFileType;
1101 | while (hDir.GetNext(sFolderName, sizeof(sFolderName), iFileType))
1102 | {
1103 | if (iFileType == FileType_Directory)
1104 | {
1105 | Format(sNavFilePath, sizeof(sNavFilePath), "addons\\%s\\maps\\%s.nav", sFolderName, sMapName);
1106 | hFile = OpenFile(sNavFilePath, "rb");
1107 | if (hFile != INVALID_HANDLE)
1108 | {
1109 | bFound = true;
1110 | break;
1111 | }
1112 | }
1113 | }
1114 |
1115 | delete hDir;
1116 | }
1117 | }
1118 | case Engine_TF2, Engine_CSS:
1119 | {
1120 | // Search custom directories.
1121 | DirectoryListing hDir = OpenDirectory("custom");
1122 | if (hDir != INVALID_HANDLE)
1123 | {
1124 | LogMessage("Couldn't find .nav file in maps folder, checking custom folders...");
1125 |
1126 | char sFolderName[PLATFORM_MAX_PATH];
1127 | FileType iFileType;
1128 | while (hDir.GetNext(sFolderName, sizeof(sFolderName), iFileType))
1129 | {
1130 | if (iFileType == FileType_Directory)
1131 | {
1132 | Format(sNavFilePath, sizeof(sNavFilePath), "custom\\%s\\maps\\%s.nav", sFolderName, sMapName);
1133 | hFile = OpenFile(sNavFilePath, "rb");
1134 | if (hFile != INVALID_HANDLE)
1135 | {
1136 | bFound = true;
1137 | break;
1138 | }
1139 | }
1140 | }
1141 |
1142 | delete hDir;
1143 | }
1144 | }
1145 | }
1146 |
1147 | if (!bFound)
1148 | {
1149 | LogMessage(".NAV file for %s could not be found", sMapName);
1150 | NavMeshPostLoad(false);
1151 | return false;
1152 | }
1153 | }
1154 |
1155 | LogMessage("Found .NAV file in %s", sNavFilePath);
1156 |
1157 | // Get magic number.
1158 | int iNavMagicNumber = 0;
1159 | int iElementsRead = ReadFileCell(hFile, iNavMagicNumber, UNSIGNED_INT_BYTE_SIZE);
1160 |
1161 | if (iElementsRead != 1)
1162 | {
1163 | delete hFile;
1164 | LogError("Error reading magic number value from navigation mesh: %s", sNavFilePath);
1165 | NavMeshPostLoad(false);
1166 | return false;
1167 | }
1168 |
1169 | if (iNavMagicNumber != NAV_MAGIC_NUMBER)
1170 | {
1171 | delete hFile;
1172 | LogError("Invalid magic number value from navigation mesh: %s [%p]", sNavFilePath, iNavMagicNumber);
1173 | NavMeshPostLoad(false);
1174 | return false;
1175 | }
1176 |
1177 | // Get the version.
1178 | int iNavVersion;
1179 | iElementsRead = ReadFileCell(hFile, iNavVersion, UNSIGNED_INT_BYTE_SIZE);
1180 |
1181 | if (iElementsRead != 1)
1182 | {
1183 | delete hFile;
1184 | LogError("Error reading version number from navigation mesh: %s", sNavFilePath);
1185 | NavMeshPostLoad(false);
1186 | return false;
1187 | }
1188 |
1189 | if (iNavVersion < 6 || iNavVersion > 16)
1190 | {
1191 | delete hFile;
1192 | LogError("Invalid version number value from navigation mesh: %s [%d]", sNavFilePath, iNavVersion);
1193 | NavMeshPostLoad(false);
1194 | return false;
1195 | }
1196 |
1197 | // Get the sub version, if supported.
1198 | int iNavSubVersion = 0;
1199 | if (iNavVersion >= 10)
1200 | {
1201 | ReadFileCell(hFile, iNavSubVersion, UNSIGNED_INT_BYTE_SIZE);
1202 | }
1203 |
1204 | // Get the save bsp size.
1205 | int iNavSaveBspSize = 0;
1206 | if (iNavVersion >= 4)
1207 | {
1208 | ReadFileCell(hFile, iNavSaveBspSize, UNSIGNED_INT_BYTE_SIZE);
1209 | }
1210 |
1211 | // Check if the nav mesh was analyzed.
1212 | int iNavMeshAnalyzed = 0;
1213 | if (iNavVersion >= 14)
1214 | {
1215 | ReadFileCell(hFile, iNavMeshAnalyzed, UNSIGNED_CHAR_BYTE_SIZE);
1216 | LogMessage("Is mesh analyzed: %d", iNavMeshAnalyzed);
1217 | }
1218 |
1219 | LogMessage("Nav version: %d; SubVersion: %d (v10+); BSPSize: %d; MagicNumber: %d", iNavVersion, iNavSubVersion, iNavSaveBspSize, iNavMagicNumber);
1220 |
1221 | NavMeshLoadPlaceDirectory(hFile, iNavVersion, iNavSubVersion);
1222 |
1223 | NavMeshLoadCustomDataPreArea(hFile, iNavVersion, iNavSubVersion);
1224 |
1225 | // Get area count.
1226 | int iAreaCount = 0;
1227 | ReadFileCell(hFile, iAreaCount, UNSIGNED_INT_BYTE_SIZE);
1228 |
1229 | LogMessage("Area count: %d", iAreaCount);
1230 | if (iAreaCount == 0)
1231 | {
1232 | delete hFile;
1233 | return false;
1234 | }
1235 |
1236 | if (iAreaCount > 0)
1237 | {
1238 | Profiler profiler = new Profiler();
1239 | profiler.Start();
1240 |
1241 | // Ensure capacity to reduce some overhead.
1242 | g_hNavMeshAreas.Resize(iAreaCount);
1243 |
1244 | for (int iAreaIndex = 0; iAreaIndex < iAreaCount; iAreaIndex++)
1245 | {
1246 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_Parent);
1247 | g_hNavMeshAreas.Set(iAreaIndex, NUM_TRAVERSE_TYPES, NavMeshArea_ParentHow);
1248 | g_hNavMeshAreas.Set(iAreaIndex, 0, NavMeshArea_TotalCost);
1249 | g_hNavMeshAreas.Set(iAreaIndex, 0, NavMeshArea_CostSoFar);
1250 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_Marker);
1251 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_OpenMarker);
1252 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_PrevOpenIndex);
1253 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_NextOpenIndex);
1254 | g_hNavMeshAreas.Set(iAreaIndex, 0.0, NavMeshArea_PathLengthSoFar);
1255 | g_hNavMeshAreas.Set(iAreaIndex, false, NavMeshArea_Blocked);
1256 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_NearSearchMarker);
1257 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_IncomingConnectionsStartIndex);
1258 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_IncomingConnectionsEndIndex);
1259 |
1260 | int iAreaID = -1;
1261 | ReadFileCell(hFile, iAreaID, UNSIGNED_INT_BYTE_SIZE);
1262 | g_hNavMeshAreas.Set(iAreaIndex, iAreaID, NavMeshArea_ID);
1263 |
1264 | char szAreaID[16];
1265 | IntToString(iAreaID, szAreaID, 16);
1266 | g_hNavMeshAreaIdToIndexMap.SetValue(szAreaID, iAreaIndex);
1267 |
1268 | // LogMessage("Area ID: %d [file pos %x]", iAreaID, hFile.Position);
1269 |
1270 | int iAreaFlags = 0;
1271 |
1272 | if (iNavVersion <= 8)
1273 | {
1274 | ReadFileCell(hFile, iAreaFlags, UNSIGNED_CHAR_BYTE_SIZE);
1275 | }
1276 | else if (iNavVersion < 13)
1277 | {
1278 | ReadFileCell(hFile, iAreaFlags, UNSIGNED_SHORT_BYTE_SIZE);
1279 | }
1280 | else
1281 | {
1282 | ReadFileCell(hFile, iAreaFlags, UNSIGNED_INT_BYTE_SIZE);
1283 | }
1284 |
1285 | g_hNavMeshAreas.Set(iAreaIndex, iAreaFlags, NavMeshArea_Flags);
1286 |
1287 | // LogMessage("Area Flags: %d", iAreaFlags);
1288 |
1289 | float x1; float y1; float z1;
1290 | ReadFileCell(hFile, view_as(x1), FLOAT_BYTE_SIZE);
1291 | ReadFileCell(hFile, view_as(y1), FLOAT_BYTE_SIZE);
1292 | ReadFileCell(hFile, view_as(z1), FLOAT_BYTE_SIZE);
1293 |
1294 | g_hNavMeshAreas.Set(iAreaIndex, x1, NavMeshArea_X1);
1295 | g_hNavMeshAreas.Set(iAreaIndex, y1, NavMeshArea_Y1);
1296 | g_hNavMeshAreas.Set(iAreaIndex, z1, NavMeshArea_Z1);
1297 |
1298 | float x2; float y2; float z2;
1299 | ReadFileCell(hFile, view_as(x2), FLOAT_BYTE_SIZE);
1300 | ReadFileCell(hFile, view_as(y2), FLOAT_BYTE_SIZE);
1301 | ReadFileCell(hFile, view_as(z2), FLOAT_BYTE_SIZE);
1302 |
1303 | g_hNavMeshAreas.Set(iAreaIndex, x2, NavMeshArea_X2);
1304 | g_hNavMeshAreas.Set(iAreaIndex, y2, NavMeshArea_Y2);
1305 | g_hNavMeshAreas.Set(iAreaIndex, z2, NavMeshArea_Z2);
1306 |
1307 | // LogMessage("Area extent: (%f, %f, %f), (%f, %f, %f)", x1, y1, z1, x2, y2, z2);
1308 |
1309 | g_flNavMeshExtentLow[0] = (iAreaIndex == 0 || x1 < g_flNavMeshExtentLow[0]) ? x1 : g_flNavMeshExtentLow[0];
1310 | g_flNavMeshExtentLow[1] = (iAreaIndex == 0 || y1 < g_flNavMeshExtentLow[1]) ? y1 : g_flNavMeshExtentLow[1];
1311 | g_flNavMeshExtentHigh[0] = (iAreaIndex == 0 || x2 > g_flNavMeshExtentHigh[0]) ? x2 : g_flNavMeshExtentHigh[0];
1312 | g_flNavMeshExtentHigh[1] = (iAreaIndex == 0 || y2 > g_flNavMeshExtentHigh[1]) ? y2 : g_flNavMeshExtentHigh[1];
1313 |
1314 | // Cache the center position.
1315 | float flAreaCenter[3];
1316 | flAreaCenter[0] = (x1 + x2) / 2.0;
1317 | flAreaCenter[1] = (y1 + y2) / 2.0;
1318 | flAreaCenter[2] = (z1 + z2) / 2.0;
1319 |
1320 | g_hNavMeshAreas.Set(iAreaIndex, flAreaCenter[0], NavMeshArea_CenterX);
1321 | g_hNavMeshAreas.Set(iAreaIndex, flAreaCenter[1], NavMeshArea_CenterY);
1322 | g_hNavMeshAreas.Set(iAreaIndex, flAreaCenter[2], NavMeshArea_CenterZ);
1323 |
1324 | float flInvDxCorners = 0.0;
1325 | float flInvDyCorners = 0.0;
1326 |
1327 | if ((x2 - x1) > 0.0 && (y2 - y1) > 0.0)
1328 | {
1329 | flInvDxCorners = 1.0 / (x2 - x1);
1330 | flInvDyCorners = 1.0 / (y2 - y1);
1331 | }
1332 |
1333 | g_hNavMeshAreas.Set(iAreaIndex, flInvDxCorners, NavMeshArea_InvDxCorners);
1334 | g_hNavMeshAreas.Set(iAreaIndex, flInvDyCorners, NavMeshArea_InvDyCorners);
1335 |
1336 | float flNECornerZ = 0.0;
1337 | float flSWCornerZ = 0.0;
1338 | ReadFileCell(hFile, view_as(flNECornerZ), FLOAT_BYTE_SIZE);
1339 | ReadFileCell(hFile, view_as(flSWCornerZ), FLOAT_BYTE_SIZE);
1340 |
1341 | g_hNavMeshAreas.Set(iAreaIndex, flNECornerZ, NavMeshArea_NECornerZ);
1342 | g_hNavMeshAreas.Set(iAreaIndex, flSWCornerZ, NavMeshArea_SWCornerZ);
1343 |
1344 | //LogMessage("Corners: NW(%f), SW(%f)", flNECornerZ, flSWCornerZ);
1345 |
1346 | int iConnectionsStartIndex = -1;
1347 | int iConnectionsEndIndex = -1;
1348 |
1349 | // Find connections.
1350 | for (int iDirection = 0; iDirection < NAV_DIR_COUNT; iDirection++)
1351 | {
1352 | int iConnectionCount = 0;
1353 | ReadFileCell(hFile, iConnectionCount, UNSIGNED_INT_BYTE_SIZE);
1354 |
1355 | //LogMessage("Connection count: %d", iConnectionCount);
1356 |
1357 | if (iConnectionCount > 0)
1358 | {
1359 | if (iConnectionsStartIndex == -1) iConnectionsStartIndex = g_AreaConnectionsListStartIndex;
1360 |
1361 | for (int i = 0; i < iConnectionCount; i++)
1362 | {
1363 | int iConnectingAreaID = 0;
1364 | ReadFileCell(hFile, iConnectingAreaID, UNSIGNED_INT_BYTE_SIZE);
1365 |
1366 | int iConnectionIndex = g_hNavMeshAreaConnections.Push(iConnectingAreaID);
1367 | g_hNavMeshAreaConnections.Set(iConnectionIndex, iDirection, NavMeshConnection_Direction);
1368 | g_hNavMeshAreaConnections.Set(iConnectionIndex, iAreaIndex, NavMeshConnection_FromAreaIndex);
1369 |
1370 | iConnectionsEndIndex = g_AreaConnectionsListStartIndex++;
1371 | }
1372 | }
1373 | }
1374 |
1375 | g_hNavMeshAreas.Set(iAreaIndex, iConnectionsStartIndex, NavMeshArea_ConnectionsStartIndex);
1376 | g_hNavMeshAreas.Set(iAreaIndex, iConnectionsEndIndex, NavMeshArea_ConnectionsEndIndex);
1377 |
1378 | // Get hiding spots.
1379 | int iHidingSpotCount = 0;
1380 | ReadFileCell(hFile, iHidingSpotCount, UNSIGNED_CHAR_BYTE_SIZE);
1381 |
1382 | //LogMessage("Hiding spot count: %d", iHidingSpotCount);
1383 |
1384 | int iHidingSpotsStartIndex = -1;
1385 | int iHidingSpotsEndIndex = -1;
1386 |
1387 | if (iHidingSpotCount > 0)
1388 | {
1389 | iHidingSpotsStartIndex = g_AreaHidingSpotsListStartIndex;
1390 |
1391 | for (int iHidingSpotIndex = 0; iHidingSpotIndex < iHidingSpotCount; iHidingSpotIndex++)
1392 | {
1393 | NavMeshLoadHidingSpot(hFile, iAreaIndex);
1394 | iHidingSpotsEndIndex = g_AreaHidingSpotsListStartIndex++;
1395 | }
1396 | }
1397 |
1398 | g_hNavMeshAreas.Set(iAreaIndex, iHidingSpotsStartIndex, NavMeshArea_HidingSpotsStartIndex);
1399 | g_hNavMeshAreas.Set(iAreaIndex, iHidingSpotsEndIndex, NavMeshArea_HidingSpotsEndIndex);
1400 |
1401 | // Get approach areas (old version, only used to read data)
1402 | if (iNavVersion < 15)
1403 | {
1404 | int iApproachAreaCount = 0;
1405 | ReadFileCell(hFile, iApproachAreaCount, UNSIGNED_CHAR_BYTE_SIZE);
1406 |
1407 | for (int iApproachAreaIndex = 0; iApproachAreaIndex < iApproachAreaCount; iApproachAreaIndex++)
1408 | {
1409 | int iApproachHereID;
1410 | ReadFileCell(hFile, iApproachHereID, UNSIGNED_INT_BYTE_SIZE);
1411 |
1412 | int iApproachPrevID;
1413 | ReadFileCell(hFile, iApproachPrevID, UNSIGNED_INT_BYTE_SIZE);
1414 |
1415 | int iApproachType;
1416 | ReadFileCell(hFile, iApproachType, UNSIGNED_CHAR_BYTE_SIZE);
1417 |
1418 | int iApproachNextID;
1419 | ReadFileCell(hFile, iApproachNextID, UNSIGNED_INT_BYTE_SIZE);
1420 |
1421 | int iApproachHow;
1422 | ReadFileCell(hFile, iApproachHow, UNSIGNED_CHAR_BYTE_SIZE);
1423 | }
1424 | }
1425 |
1426 | // Get encounter paths.
1427 | int iEncounterPathCount;
1428 | ReadFileCell(hFile, iEncounterPathCount, UNSIGNED_INT_BYTE_SIZE);
1429 |
1430 | // LogMessage("Encounter Path Count: %d", iEncounterPathCount);
1431 |
1432 | int iEncounterPathsStartIndex = -1;
1433 | int iEncounterPathsEndIndex = -1;
1434 |
1435 | if (iEncounterPathCount > 0)
1436 | {
1437 | iEncounterPathsStartIndex = g_AreaEncounterPathsListStartIndex;
1438 |
1439 | for (int h = 0; h < iEncounterPathCount; h++)
1440 | {
1441 | int iEncounterFromID;
1442 | ReadFileCell(hFile, iEncounterFromID, UNSIGNED_INT_BYTE_SIZE);
1443 |
1444 | int iEncounterFromDirection;
1445 | ReadFileCell(hFile, iEncounterFromDirection, UNSIGNED_CHAR_BYTE_SIZE);
1446 |
1447 | int iEncounterToID;
1448 | ReadFileCell(hFile, iEncounterToID, UNSIGNED_INT_BYTE_SIZE);
1449 |
1450 | int iEncounterToDirection;
1451 | ReadFileCell(hFile, iEncounterToDirection, UNSIGNED_CHAR_BYTE_SIZE);
1452 |
1453 | int iEncounterSpotCount;
1454 | ReadFileCell(hFile, iEncounterSpotCount, UNSIGNED_CHAR_BYTE_SIZE);
1455 |
1456 | //LogMessage("Encounter [from ID %d] [from dir %d] [to ID %d] [to dir %d] [spot count %d]", iEncounterFromID, iEncounterFromDirection, iEncounterToID, iEncounterToDirection, iEncounterSpotCount);
1457 |
1458 | int iEncounterSpotsStartIndex = -1;
1459 | int iEncounterSpotsEndIndex = -1;
1460 |
1461 | if (iEncounterSpotCount > 0)
1462 | {
1463 | iEncounterSpotsStartIndex = g_AreaEncounterSpotsListStartIndex;
1464 |
1465 | for (int i = 0; i < iEncounterSpotCount; i++)
1466 | {
1467 | int iEncounterSpotOrderID;
1468 | ReadFileCell(hFile, iEncounterSpotOrderID, UNSIGNED_INT_BYTE_SIZE);
1469 |
1470 | int iEncounterSpotT;
1471 | ReadFileCell(hFile, iEncounterSpotT, UNSIGNED_CHAR_BYTE_SIZE);
1472 |
1473 | float flEncounterSpotParametricDistance = float(iEncounterSpotT) / 255.0;
1474 |
1475 | int iEncounterSpotIndex = g_hNavMeshAreaEncounterSpots.Push(iEncounterSpotOrderID);
1476 | g_hNavMeshAreaEncounterSpots.Set(iEncounterSpotIndex, flEncounterSpotParametricDistance, NavMeshEncounterSpot_ParametricDistance);
1477 |
1478 | iEncounterSpotsEndIndex = g_AreaEncounterSpotsListStartIndex++;
1479 |
1480 | //LogMessage("Encounter spot [order id %d] and [T %d]", iEncounterSpotOrderID, iEncounterSpotT);
1481 | }
1482 | }
1483 |
1484 | int iEncounterPathIndex = g_hNavMeshAreaEncounterPaths.Push(iEncounterFromID);
1485 | g_hNavMeshAreaEncounterPaths.Set(iEncounterPathIndex, iEncounterFromDirection, NavMeshEncounterPath_FromDirection);
1486 | g_hNavMeshAreaEncounterPaths.Set(iEncounterPathIndex, iEncounterToID, NavMeshEncounterPath_ToAreaIndex);
1487 | g_hNavMeshAreaEncounterPaths.Set(iEncounterPathIndex, iEncounterToDirection, NavMeshEncounterPath_ToDirection);
1488 | g_hNavMeshAreaEncounterPaths.Set(iEncounterPathIndex, iEncounterSpotsStartIndex, NavMeshEncounterPath_SpotsStartIndex);
1489 | g_hNavMeshAreaEncounterPaths.Set(iEncounterPathIndex, iEncounterSpotsEndIndex, NavMeshEncounterPath_SpotsEndIndex);
1490 |
1491 | iEncounterPathsEndIndex = g_AreaEncounterPathsListStartIndex++;
1492 | }
1493 | }
1494 |
1495 | g_hNavMeshAreas.Set(iAreaIndex, iEncounterPathsStartIndex, NavMeshArea_EncounterPathsStartIndex);
1496 | g_hNavMeshAreas.Set(iAreaIndex, iEncounterPathsEndIndex, NavMeshArea_EncounterPathsEndIndex);
1497 |
1498 | int iPlaceID = -1;
1499 | ReadFileCell(hFile, iPlaceID, UNSIGNED_SHORT_BYTE_SIZE);
1500 | g_hNavMeshAreas.Set(iAreaIndex, iPlaceID, NavMeshArea_PlaceID);
1501 |
1502 | // LogMessage("Place ID: %d", iPlaceID);
1503 |
1504 | // Get ladder connections.
1505 |
1506 | int iLadderConnectionsStartIndex = -1;
1507 | int iLadderConnectionsEndIndex = -1;
1508 |
1509 | for (int iLadderDirection = 0; iLadderDirection < NAV_LADDER_DIR_COUNT; iLadderDirection++)
1510 | {
1511 | int iLadderConnectionCount;
1512 | ReadFileCell(hFile, iLadderConnectionCount, UNSIGNED_INT_BYTE_SIZE);
1513 |
1514 | //LogMessage("Ladder Connection Count: %d", iLadderConnectionCount);
1515 |
1516 | if (iLadderConnectionCount > 0)
1517 | {
1518 | iLadderConnectionsStartIndex = g_AreaLadderConnectionsListStartIndex;
1519 |
1520 | for (int i = 0; i < iLadderConnectionCount; i++)
1521 | {
1522 | int iLadderConnectionID;
1523 | ReadFileCell(hFile, iLadderConnectionID, UNSIGNED_INT_BYTE_SIZE);
1524 |
1525 | int iLadderConnectionIndex = g_hNavMeshAreaLadderConnections.Push(iLadderConnectionID);
1526 | g_hNavMeshAreaLadderConnections.Set(iLadderConnectionIndex, iLadderDirection, NavMeshLadderConnection_Direction);
1527 |
1528 | iLadderConnectionsEndIndex = g_AreaLadderConnectionsListStartIndex++;
1529 |
1530 | //LogMessage("Parsed ladder connect [ID %d]\n", iLadderConnectionID);
1531 | }
1532 | }
1533 | }
1534 |
1535 | g_hNavMeshAreas.Set(iAreaIndex, iLadderConnectionsStartIndex, NavMeshArea_LadderConnectionsStartIndex);
1536 | g_hNavMeshAreas.Set(iAreaIndex, iLadderConnectionsEndIndex, NavMeshArea_LadderConnectionsEndIndex);
1537 |
1538 | float flEarliestOccupyTimeFirstTeam = 0.0;
1539 | float flEarliestOccupyTimeSecondTeam = 0.0;
1540 | ReadFileCell(hFile, view_as(flEarliestOccupyTimeFirstTeam), FLOAT_BYTE_SIZE);
1541 | ReadFileCell(hFile, view_as(flEarliestOccupyTimeSecondTeam), FLOAT_BYTE_SIZE);
1542 |
1543 | g_hNavMeshAreas.Set(iAreaIndex, flEarliestOccupyTimeFirstTeam, NavMeshArea_EarliestOccupyTimeFirstTeam);
1544 | g_hNavMeshAreas.Set(iAreaIndex, flEarliestOccupyTimeSecondTeam, NavMeshArea_EarliestOccupyTimeSecondTeam);
1545 |
1546 | float flNavCornerLightIntensityNW = 0.0;
1547 | float flNavCornerLightIntensityNE = 0.0;
1548 | float flNavCornerLightIntensitySE = 0.0;
1549 | float flNavCornerLightIntensitySW = 0.0;
1550 |
1551 | int iVisibleAreasStartIndex = -1;
1552 | int iVisibleAreasEndIndex = -1;
1553 |
1554 | int iInheritVisibilityFrom = -1;
1555 |
1556 | if (iNavVersion >= 11)
1557 | {
1558 | ReadFileCell(hFile, view_as(flNavCornerLightIntensityNW), FLOAT_BYTE_SIZE);
1559 | ReadFileCell(hFile, view_as(flNavCornerLightIntensityNE), FLOAT_BYTE_SIZE);
1560 | ReadFileCell(hFile, view_as(flNavCornerLightIntensitySE), FLOAT_BYTE_SIZE);
1561 | ReadFileCell(hFile, view_as(flNavCornerLightIntensitySW), FLOAT_BYTE_SIZE);
1562 |
1563 | if (iNavVersion >= 16)
1564 | {
1565 | switch (GetEngineVersion())
1566 | {
1567 | case Engine_Left4Dead2:
1568 | {
1569 | // L4D2 inserts its own custom data before visible area set.
1570 | }
1571 | default:
1572 | {
1573 | int iVisibleAreaCount = 0;
1574 | ReadFileCell(hFile, iVisibleAreaCount, UNSIGNED_INT_BYTE_SIZE);
1575 |
1576 | // LogMessage("Visible area count: %d", iVisibleAreaCount);
1577 |
1578 | if (iVisibleAreaCount > 0)
1579 | {
1580 | iVisibleAreasStartIndex = g_hNavMeshAreaVisibleAreas.Length;
1581 |
1582 | for (int i = 0; i < iVisibleAreaCount; i++)
1583 | {
1584 | AreaBindInfo bindInfo;
1585 | ReadFileCell(hFile, bindInfo.AreaIndex, UNSIGNED_INT_BYTE_SIZE);
1586 | ReadFileCell(hFile, bindInfo.Attributes, UNSIGNED_CHAR_BYTE_SIZE);
1587 | g_hNavMeshAreaVisibleAreas.PushArray(bindInfo, sizeof(bindInfo));
1588 |
1589 | iVisibleAreasEndIndex = g_AreaVisibleAreasListStartIndex++;
1590 |
1591 | //LogMessage("Parsed visible area [%d] with attr [%d]", iVisibleAreaID, iVisibleAreaAttributes);
1592 | }
1593 |
1594 | iVisibleAreasEndIndex = g_hNavMeshAreaVisibleAreas.Length - 1;
1595 | }
1596 |
1597 | ReadFileCell(hFile, iInheritVisibilityFrom, UNSIGNED_INT_BYTE_SIZE);
1598 |
1599 | // LogMessage("Inherit visibilty from: %d", iInheritVisibilityFrom);
1600 | }
1601 | }
1602 | }
1603 | }
1604 |
1605 | g_hNavMeshAreas.Set(iAreaIndex, flNavCornerLightIntensityNW, NavMeshArea_CornerLightIntensityNW);
1606 | g_hNavMeshAreas.Set(iAreaIndex, flNavCornerLightIntensityNE, NavMeshArea_CornerLightIntensityNE);
1607 | g_hNavMeshAreas.Set(iAreaIndex, flNavCornerLightIntensitySE, NavMeshArea_CornerLightIntensitySE);
1608 | g_hNavMeshAreas.Set(iAreaIndex, flNavCornerLightIntensitySW, NavMeshArea_CornerLightIntensitySW);
1609 |
1610 | g_hNavMeshAreas.Set(iAreaIndex, iVisibleAreasStartIndex, NavMeshArea_VisibleAreasStartIndex);
1611 | g_hNavMeshAreas.Set(iAreaIndex, iVisibleAreasEndIndex, NavMeshArea_VisibleAreasEndIndex);
1612 |
1613 | g_hNavMeshAreas.Set(iAreaIndex, iInheritVisibilityFrom, NavMeshArea_InheritVisibilityFrom);
1614 |
1615 | NavMeshLoadAreaCustomData(hFile, iAreaIndex, iNavVersion, iNavSubVersion);
1616 | }
1617 |
1618 | profiler.Stop();
1619 | LogMessage("Parsed %d areas in %f seconds.", iAreaCount, profiler.Time);
1620 |
1621 | delete profiler;
1622 | }
1623 |
1624 | // Set up the grid.
1625 | NavMeshGridAllocate(g_flNavMeshExtentLow[0], g_flNavMeshExtentHigh[0], g_flNavMeshExtentLow[1], g_flNavMeshExtentHigh[1]);
1626 |
1627 | for (int i = 0; i < iAreaCount; i++)
1628 | {
1629 | NavMeshAddAreaToGrid(i);
1630 | }
1631 |
1632 | NavMeshGridFinalize();
1633 |
1634 | // Read ladders.
1635 | int iLadderCount = 0;
1636 | ReadFileCell(hFile, iLadderCount, UNSIGNED_INT_BYTE_SIZE);
1637 |
1638 | LogMessage("Ladder count: %d", iLadderCount);
1639 |
1640 | if (iLadderCount > 0)
1641 | {
1642 | Profiler profiler = new Profiler();
1643 | profiler.Start();
1644 |
1645 | g_hNavMeshLadders.Resize(iLadderCount);
1646 |
1647 | for (int iLadderIndex = 0; iLadderIndex < iLadderCount; iLadderIndex++)
1648 | {
1649 | NavMeshLoadLadder(hFile, iLadderIndex);
1650 | }
1651 |
1652 | profiler.Stop();
1653 | LogMessage("Parsed %d ladders in %f seconds.", iLadderCount, profiler.Time);
1654 |
1655 | delete profiler;
1656 | }
1657 |
1658 | g_iNavMeshMagicNumber = iNavMagicNumber;
1659 | g_iNavMeshVersion = iNavVersion;
1660 | g_iNavMeshSubVersion = iNavSubVersion;
1661 | g_iNavMeshSaveBSPSize = iNavSaveBspSize;
1662 | g_bNavMeshAnalyzed = view_as(iNavMeshAnalyzed);
1663 |
1664 | NavMeshLoadCustomData(hFile, iNavVersion, iNavSubVersion);
1665 |
1666 | delete hFile;
1667 |
1668 | // File parsing is all done. Convert referenced IDs to array indexes for faster performance and
1669 | // lesser lookup time in the future.
1670 |
1671 | if (g_hNavMeshAreaConnections.Length > 0)
1672 | {
1673 | for (int iIndex = 0, iSize = g_hNavMeshAreaConnections.Length; iIndex < iSize; iIndex++)
1674 | {
1675 | int id = g_hNavMeshAreaConnections.Get(iIndex, NavMeshConnection_AreaIndex);
1676 | g_hNavMeshAreaConnections.Set(iIndex, NavMeshFindAreaByID(id), NavMeshConnection_AreaIndex);
1677 | }
1678 | }
1679 |
1680 | if (g_hNavMeshAreaVisibleAreas.Length > 0)
1681 | {
1682 | for (int iIndex = 0, iSize = g_hNavMeshAreaVisibleAreas.Length; iIndex < iSize; iIndex++)
1683 | {
1684 | int id = g_hNavMeshAreaVisibleAreas.Get(iIndex, NavMeshVisibleArea_Index);
1685 | g_hNavMeshAreaVisibleAreas.Set(iIndex, NavMeshFindAreaByID(id), NavMeshVisibleArea_Index);
1686 | }
1687 | }
1688 |
1689 | if (g_hNavMeshAreaEncounterPaths.Length > 0)
1690 | {
1691 | for (int iIndex = 0, iSize = g_hNavMeshAreaEncounterPaths.Length; iIndex < iSize; iIndex++)
1692 | {
1693 | int id = g_hNavMeshAreaEncounterPaths.Get(iIndex, NavMeshEncounterPath_FromAreaIndex);
1694 | g_hNavMeshAreaEncounterPaths.Set(iIndex, NavMeshFindAreaByID(id), NavMeshEncounterPath_FromAreaIndex);
1695 |
1696 | id = g_hNavMeshAreaEncounterPaths.Get(iIndex, NavMeshEncounterPath_ToAreaIndex);
1697 | g_hNavMeshAreaEncounterPaths.Set(iIndex, NavMeshFindAreaByID(id), NavMeshEncounterPath_ToAreaIndex);
1698 | }
1699 | }
1700 |
1701 | if (g_hNavMeshAreaEncounterSpots.Length > 0)
1702 | {
1703 | for (int iIndex = 0, iSize = g_hNavMeshAreaEncounterSpots.Length; iIndex < iSize; iIndex++)
1704 | {
1705 | int id = g_hNavMeshAreaEncounterSpots.Get(iIndex, NavMeshEncounterSpot_HidingSpotIndex);
1706 | g_hNavMeshAreaEncounterSpots.Set(iIndex, NavMeshFindHidingSpotByID(id), NavMeshEncounterSpot_HidingSpotIndex);
1707 | }
1708 | }
1709 |
1710 | if (g_hNavMeshAreaLadderConnections.Length > 0)
1711 | {
1712 | for (int iIndex = 0, iSize = g_hNavMeshAreaLadderConnections.Length; iIndex < iSize; iIndex++)
1713 | {
1714 | int id = g_hNavMeshAreaLadderConnections.Get(iIndex, NavMeshLadderConnection_LadderIndex);
1715 | g_hNavMeshAreaLadderConnections.Set(iIndex, NavMeshFindLadderByID(id), NavMeshLadderConnection_LadderIndex);
1716 | }
1717 | }
1718 |
1719 | if (g_hNavMeshLadders.Length > 0)
1720 | {
1721 | for (int iLadderIndex = 0; iLadderIndex < iLadderCount; iLadderIndex++)
1722 | {
1723 | int iTopForwardAreaID = GetArrayCell(g_hNavMeshLadders, iLadderIndex, NavMeshLadder_TopForwardAreaIndex);
1724 | g_hNavMeshLadders.Set(iLadderIndex, NavMeshFindAreaByID(iTopForwardAreaID), NavMeshLadder_TopForwardAreaIndex);
1725 |
1726 | int iTopLeftAreaID = GetArrayCell(g_hNavMeshLadders, iLadderIndex, NavMeshLadder_TopLeftAreaIndex);
1727 | g_hNavMeshLadders.Set(iLadderIndex, NavMeshFindAreaByID(iTopLeftAreaID), NavMeshLadder_TopLeftAreaIndex);
1728 |
1729 | int iTopRightAreaID = GetArrayCell(g_hNavMeshLadders, iLadderIndex, NavMeshLadder_TopRightAreaIndex);
1730 | g_hNavMeshLadders.Set(iLadderIndex, NavMeshFindAreaByID(iTopRightAreaID), NavMeshLadder_TopRightAreaIndex);
1731 |
1732 | int iTopBehindAreaID = GetArrayCell(g_hNavMeshLadders, iLadderIndex, NavMeshLadder_TopBehindAreaIndex);
1733 | g_hNavMeshLadders.Set(iLadderIndex, NavMeshFindAreaByID(iTopBehindAreaID), NavMeshLadder_TopBehindAreaIndex);
1734 |
1735 | int iBottomAreaID = GetArrayCell(g_hNavMeshLadders, iLadderIndex, NavMeshLadder_BottomAreaIndex);
1736 | g_hNavMeshLadders.Set(iLadderIndex, NavMeshFindAreaByID(iBottomAreaID), NavMeshLadder_BottomAreaIndex);
1737 | }
1738 | }
1739 |
1740 | // Using an ArrayList because a dynamic-allocated array for large meshes results in nasty heap overflow.
1741 | ArrayList hIncomingConnectionsArray = new ArrayList();
1742 | hIncomingConnectionsArray.Resize(iAreaCount);
1743 | for (int i = 0; i < iAreaCount; i++)
1744 | {
1745 | hIncomingConnectionsArray.Set(i, INVALID_HANDLE);
1746 | }
1747 |
1748 | for (int iAreaIndex = 0; iAreaIndex < iAreaCount; iAreaIndex++)
1749 | {
1750 | int startIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_ConnectionsStartIndex);
1751 | if (startIndex == -1)
1752 | continue;
1753 | int endIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_ConnectionsEndIndex);
1754 |
1755 | for (int i = startIndex; i <= endIndex; i++) {
1756 | int iToAreaIndex = g_hNavMeshAreaConnections.Get(i, NavMeshConnection_AreaIndex);
1757 | if (iToAreaIndex == -1)
1758 | continue;
1759 |
1760 | int direction = g_hNavMeshAreaConnections.Get(i, NavMeshConnection_Direction);
1761 |
1762 | if (!NavMeshAreaIsConnected(iToAreaIndex, iAreaIndex, OppositeDirection(direction))) {
1763 | ArrayList incomingConnections = hIncomingConnectionsArray.Get(iToAreaIndex);
1764 | if (incomingConnections == INVALID_HANDLE)
1765 | {
1766 | incomingConnections = new ArrayList(NavMeshConnection_MaxStats);
1767 | hIncomingConnectionsArray.Set(iToAreaIndex, incomingConnections);
1768 | }
1769 |
1770 | int index = incomingConnections.Push(iAreaIndex);
1771 | incomingConnections.Set(index, OppositeDirection(direction), NavMeshConnection_Direction);
1772 | incomingConnections.Set(index, iToAreaIndex, NavMeshConnection_FromAreaIndex);
1773 | }
1774 | }
1775 | }
1776 |
1777 | int iIncomingConnections = 0;
1778 |
1779 | for (int iAreaIndex = 0; iAreaIndex < iAreaCount; iAreaIndex++)
1780 | {
1781 | ArrayList incomingConnections = hIncomingConnectionsArray.Get(iAreaIndex);
1782 | if (incomingConnections == INVALID_HANDLE)
1783 | continue;
1784 |
1785 | int startIndex = -1;
1786 | int endIndex = -1;
1787 |
1788 | for (int j = 0; j < incomingConnections.Length; j++)
1789 | {
1790 | if (startIndex == -1) startIndex = iIncomingConnections;
1791 |
1792 | int incConnection = g_hNavMeshAreaIncomingConnections.Push(incomingConnections.Get(j, NavMeshConnection_AreaIndex));
1793 | g_hNavMeshAreaIncomingConnections.Set(incConnection, incomingConnections.Get(j, NavMeshConnection_Direction), NavMeshConnection_Direction);
1794 | g_hNavMeshAreaIncomingConnections.Set(incConnection, incomingConnections.Get(j, NavMeshConnection_FromAreaIndex), NavMeshConnection_FromAreaIndex);
1795 | endIndex = iIncomingConnections++;
1796 | }
1797 |
1798 | delete incomingConnections;
1799 | hIncomingConnectionsArray.Set(iAreaIndex, INVALID_HANDLE);
1800 |
1801 | g_hNavMeshAreas.Set(iAreaIndex, startIndex, NavMeshArea_IncomingConnectionsStartIndex);
1802 | g_hNavMeshAreas.Set(iAreaIndex, endIndex, NavMeshArea_IncomingConnectionsEndIndex);
1803 | }
1804 |
1805 | delete hIncomingConnectionsArray;
1806 |
1807 | NavMeshPostLoad(true);
1808 |
1809 | return true;
1810 | }
1811 |
1812 | bool NavMeshLoadPlaceDirectory(File hFile, int iNavVersion, int iNavSubVersion)
1813 | {
1814 | if (iNavVersion >= 5)
1815 | {
1816 | int iPlaceCount = 0;
1817 | ReadFileCell(hFile, iPlaceCount, UNSIGNED_SHORT_BYTE_SIZE);
1818 | LogMessage("Place count: %d", iPlaceCount);
1819 |
1820 | // Parse through places.
1821 | for (int iPlaceIndex = 0; iPlaceIndex < iPlaceCount; iPlaceIndex++)
1822 | {
1823 | int iPlaceStringSize = 0;
1824 | ReadFileCell(hFile, iPlaceStringSize, UNSIGNED_SHORT_BYTE_SIZE);
1825 |
1826 | char sPlaceName[256];
1827 | ReadFileString(hFile, sPlaceName, sizeof(sPlaceName), iPlaceStringSize);
1828 |
1829 | g_hNavMeshPlaces.PushString(sPlaceName);
1830 |
1831 | //LogMessage("Parsed place \"%s\" [index: %d]", sPlaceName, iPlaceIndex);
1832 | }
1833 |
1834 | // Get any unnamed areas.
1835 | int iNavUnnamedAreas = 0;
1836 | if (iNavVersion > 11)
1837 | {
1838 | ReadFileCell(hFile, iNavUnnamedAreas, UNSIGNED_CHAR_BYTE_SIZE);
1839 | LogMessage("Has unnamed areas: %s", iNavUnnamedAreas ? "true" : "false");
1840 | }
1841 | }
1842 | }
1843 |
1844 | int NavMeshLoadHidingSpot(File hFile, int iOwnerAreaIndex)
1845 | {
1846 | int iHidingSpotID;
1847 | ReadFileCell(hFile, iHidingSpotID, UNSIGNED_INT_BYTE_SIZE);
1848 |
1849 | float flHidingSpotX; float flHidingSpotY; float flHidingSpotZ;
1850 | ReadFileCell(hFile, view_as(flHidingSpotX), FLOAT_BYTE_SIZE);
1851 | ReadFileCell(hFile, view_as(flHidingSpotY), FLOAT_BYTE_SIZE);
1852 | ReadFileCell(hFile, view_as(flHidingSpotZ), FLOAT_BYTE_SIZE);
1853 |
1854 | int iHidingSpotFlags;
1855 | ReadFileCell(hFile, iHidingSpotFlags, UNSIGNED_CHAR_BYTE_SIZE);
1856 |
1857 | int iIndex = g_hNavMeshAreaHidingSpots.Push(iHidingSpotID);
1858 | g_hNavMeshAreaHidingSpots.Set(iIndex, flHidingSpotX, NavMeshHidingSpot_X);
1859 | g_hNavMeshAreaHidingSpots.Set(iIndex, flHidingSpotY, NavMeshHidingSpot_Y);
1860 | g_hNavMeshAreaHidingSpots.Set(iIndex, flHidingSpotZ, NavMeshHidingSpot_Z);
1861 | g_hNavMeshAreaHidingSpots.Set(iIndex, iHidingSpotFlags, NavMeshHidingSpot_Flags);
1862 | g_hNavMeshAreaHidingSpots.Set(iIndex, iOwnerAreaIndex, NavMeshHidingSpot_AreaIndex);
1863 |
1864 | char szHidingSpotID[16];
1865 | IntToString(iHidingSpotID, szHidingSpotID, 16);
1866 | g_hNavMeshHidingSpotIdToIndexMap.SetValue(szHidingSpotID, iIndex);
1867 |
1868 | //LogMessage("Parsed hiding spot (%f, %f, %f) with ID [%d] and flags [%d]", flHidingSpotX, flHidingSpotY, flHidingSpotZ, iHidingSpotID, iHidingSpotFlags);
1869 |
1870 | return iIndex;
1871 | }
1872 |
1873 | // Loads game-specific custom data for the mesh before areas are parsed.
1874 | bool NavMeshLoadCustomDataPreArea(File hFile, int iNavVersion, int iNavSubVersion)
1875 | {
1876 | switch (GetEngineVersion())
1877 | {
1878 | // Insert other game-specific data stored in the mesh here.
1879 |
1880 | case Engine_Left4Dead2:
1881 | {
1882 | if (7 < iNavSubVersion)
1883 | {
1884 | if (iNavSubVersion >= 12)
1885 | {
1886 | ReadFileString(hFile, g_TerrorNavMeshZombiePopulation, sizeof(g_TerrorNavMeshZombiePopulation));
1887 | LogMessage("Population type: %s", g_TerrorNavMeshZombiePopulation);
1888 | }
1889 |
1890 | int fogPlaceCount = 0;
1891 | ReadFileCell(hFile, fogPlaceCount, UNSIGNED_SHORT_BYTE_SIZE);
1892 | if (fogPlaceCount > 0)
1893 | {
1894 | for (int i = 0; i < fogPlaceCount; i++)
1895 | {
1896 | int uFogPlaceLen = 0;
1897 | ReadFileCell(hFile, uFogPlaceLen, UNSIGNED_SHORT_BYTE_SIZE);
1898 |
1899 | char sFogPlaceName[256];
1900 | ReadFileString(hFile, sFogPlaceName, sizeof(sFogPlaceName), uFogPlaceLen);
1901 |
1902 | // LogMessage("Parsed fog place \"%s\"", sFogPlaceName);
1903 | }
1904 | }
1905 | }
1906 | }
1907 | }
1908 |
1909 | return true;
1910 | }
1911 |
1912 | // Loads game-specific custom data.
1913 | bool NavMeshLoadAreaCustomData(File hFile, int iAreaIndex, int iNavVersion, int iNavSubVersion)
1914 | {
1915 | switch (GetEngineVersion())
1916 | {
1917 | // Insert other game-specific data stored in the area here.
1918 |
1919 | case Engine_TF2:
1920 | {
1921 | int attributeFlags;
1922 | ReadFileCell(hFile, attributeFlags, UNSIGNED_INT_BYTE_SIZE);
1923 |
1924 | g_hNavMeshAreas.Set(iAreaIndex, attributeFlags, TFNavArea_AttributeFlags);
1925 | }
1926 | case Engine_CSGO, Engine_CSS:
1927 | {
1928 | g_hNavMeshAreas.Set(iAreaIndex, -1, CSNavArea_ApproachInfoStartIndex);
1929 | g_hNavMeshAreas.Set(iAreaIndex, -1, CSNavArea_ApproachInfoEndIndex);
1930 |
1931 | switch (iNavSubVersion)
1932 | {
1933 | case 1:
1934 | {
1935 | int approachCount = 0;
1936 | ReadFileCell(hFile, approachCount, UNSIGNED_CHAR_BYTE_SIZE);
1937 |
1938 | if (approachCount > 0)
1939 | {
1940 | int startIndex = g_hCSNavAreaApproachInfo.Length;
1941 |
1942 | for (int i = 0; i < approachCount; i++)
1943 | {
1944 | CCSNavArea_ApproachInfo approachInfo;
1945 | ReadFileCell(hFile, approachInfo.HereArea, UNSIGNED_INT_BYTE_SIZE);
1946 | ReadFileCell(hFile, approachInfo.PrevArea, UNSIGNED_INT_BYTE_SIZE);
1947 | ReadFileCell(hFile, approachInfo.PrevToHereHow, UNSIGNED_CHAR_BYTE_SIZE);
1948 | ReadFileCell(hFile, approachInfo.NextArea, UNSIGNED_INT_BYTE_SIZE);
1949 | ReadFileCell(hFile, approachInfo.HereToNextHow, UNSIGNED_CHAR_BYTE_SIZE);
1950 |
1951 | g_hCSNavAreaApproachInfo.PushArray(approachInfo);
1952 | }
1953 |
1954 | int endIndex = g_hCSNavAreaApproachInfo.Length - 1;
1955 |
1956 | g_hNavMeshAreas.Set(iAreaIndex, startIndex, CSNavArea_ApproachInfoStartIndex);
1957 | g_hNavMeshAreas.Set(iAreaIndex, endIndex, CSNavArea_ApproachInfoEndIndex);
1958 | }
1959 | }
1960 | }
1961 | }
1962 | case Engine_Left4Dead2:
1963 | {
1964 | if (iNavSubVersion == 0)
1965 | return true;
1966 |
1967 | // 0x300
1968 | int spawnAttributes = 0;
1969 | ReadFileCell(hFile, spawnAttributes, UNSIGNED_INT_BYTE_SIZE);
1970 |
1971 | g_hNavMeshAreas.Set(iAreaIndex, spawnAttributes, TerrorNavArea_SpawnAttributes);
1972 | // LogMessage("SpawnAttributes = 0x%x", spawnAttributes);
1973 |
1974 | if (iNavSubVersion < 2)
1975 | {
1976 | // Set some sort of property based on spawnAttributes.
1977 | }
1978 | else
1979 | {
1980 | if (iNavSubVersion < 10)
1981 | {
1982 | int unk01 = 0;
1983 | ReadFileCell(hFile, unk01, UNSIGNED_INT_BYTE_SIZE);
1984 |
1985 | if (3 < iNavSubVersion)
1986 | {
1987 | int unk02 = 0;
1988 | ReadFileCell(hFile, unk02, UNSIGNED_INT_BYTE_SIZE);
1989 |
1990 | if (iNavSubVersion - 5 < 8 )
1991 | {
1992 | int unk03 = 0;
1993 | ReadFileCell(hFile, unk03, UNSIGNED_INT_BYTE_SIZE);
1994 | }
1995 | }
1996 | }
1997 | else
1998 | {
1999 | if (iNavSubVersion - 5 < 8 )
2000 | {
2001 | int unk01 = 0;
2002 | ReadFileCell(hFile, unk01, UNSIGNED_INT_BYTE_SIZE);
2003 | }
2004 | }
2005 |
2006 | if (7 < iNavSubVersion)
2007 | {
2008 | int fogPlaceId = 0;
2009 | ReadFileCell(hFile, fogPlaceId, UNSIGNED_SHORT_BYTE_SIZE);
2010 | // LogMessage("ushort %d [line %d]", fogPlaceId, __LINE__);
2011 | }
2012 | }
2013 |
2014 | if ((spawnAttributes & 8) != 0 && iNavSubVersion < 10)
2015 | {
2016 | int unk01 = 0;
2017 | ReadFileCell(hFile, unk01, UNSIGNED_INT_BYTE_SIZE);
2018 | // LogMessage("uint %d [line %d]", unk01, __LINE__);
2019 |
2020 | int unk02 = 0;
2021 | ReadFileCell(hFile, unk02, UNSIGNED_INT_BYTE_SIZE);
2022 | // LogMessage("uint %d [line %d]", unk02, __LINE__);
2023 |
2024 | float unk03 = 0.0;
2025 | ReadFileCell(hFile, view_as(unk03), FLOAT_BYTE_SIZE);
2026 | // LogMessage("float %f [line %d]", unk03, __LINE__);
2027 |
2028 | float unk04 = 0.0;
2029 | ReadFileCell(hFile, view_as(unk04), FLOAT_BYTE_SIZE);
2030 | // LogMessage("float %f [line %d]", unk04, __LINE__);
2031 |
2032 | int unk05 = 0;
2033 | ReadFileCell(hFile, unk05, UNSIGNED_INT_BYTE_SIZE);
2034 | // LogMessage("uint %d [line %d]", unk05, __LINE__);
2035 | }
2036 |
2037 | if (iNavSubVersion - 3 < 7)
2038 | {
2039 | int unk01 = 0;
2040 | ReadFileCell(hFile, unk01, UNSIGNED_CHAR_BYTE_SIZE);
2041 | // LogMessage("uchar %d [line %d]", unk01, __LINE__);
2042 |
2043 | if (unk01 > 0)
2044 | {
2045 | for (int i = 0; i < unk01; i++)
2046 | {
2047 | int unk02 = 0;
2048 | ReadFileCell(hFile, unk02, UNSIGNED_INT_BYTE_SIZE);
2049 | // LogMessage("uint %d [line %d]", unk02, __LINE__);
2050 | }
2051 | }
2052 | }
2053 |
2054 | if (iNavSubVersion >= 5)
2055 | {
2056 | int visibleAreaCount = 0;
2057 | ReadFileCell(hFile, visibleAreaCount, UNSIGNED_INT_BYTE_SIZE);
2058 | // LogMessage("uint %d [line %d]", visibleAreaCount, __LINE__);
2059 |
2060 | if (visibleAreaCount > 0)
2061 | {
2062 | int startIndex = g_hNavMeshAreaVisibleAreas.Length;
2063 | int endIndex = -1;
2064 |
2065 | for (int i = 0; i < visibleAreaCount; i++)
2066 | {
2067 | AreaBindInfo bindInfo;
2068 | bindInfo.Attributes = 0;
2069 | ReadFileCell(hFile, bindInfo.AreaIndex, UNSIGNED_INT_BYTE_SIZE);
2070 |
2071 | if (iNavSubVersion >= 9)
2072 | {
2073 | ReadFileCell(hFile, bindInfo.Attributes, UNSIGNED_CHAR_BYTE_SIZE);
2074 | }
2075 |
2076 | g_hNavMeshAreaVisibleAreas.PushArray(bindInfo, sizeof(bindInfo));
2077 | }
2078 |
2079 | endIndex = g_hNavMeshAreaVisibleAreas.Length - 1;
2080 |
2081 | g_hNavMeshAreas.Set(iAreaIndex, startIndex, NavMeshArea_VisibleAreasStartIndex);
2082 | g_hNavMeshAreas.Set(iAreaIndex, endIndex, NavMeshArea_VisibleAreasEndIndex);
2083 | }
2084 | else
2085 | {
2086 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_VisibleAreasStartIndex);
2087 | g_hNavMeshAreas.Set(iAreaIndex, -1, NavMeshArea_VisibleAreasEndIndex);
2088 | }
2089 |
2090 | int inheritVisibilityFrom = -1;
2091 | if (10 < iNavSubVersion)
2092 | {
2093 | ReadFileCell(hFile, inheritVisibilityFrom, UNSIGNED_INT_BYTE_SIZE);
2094 | }
2095 |
2096 | g_hNavMeshAreas.Set(iAreaIndex, inheritVisibilityFrom, NavMeshArea_InheritVisibilityFrom);
2097 | }
2098 | }
2099 | }
2100 |
2101 | return true;
2102 | }
2103 |
2104 | bool NavMeshLoadLadder(File hFile, int iLadderIndex)
2105 | {
2106 | int iLadderID = -1;
2107 | ReadFileCell(hFile, iLadderID, UNSIGNED_INT_BYTE_SIZE);
2108 | g_hNavMeshLadders.Set(iLadderIndex, iLadderID, NavMeshLadder_ID);
2109 |
2110 | char szLadderID[16];
2111 | IntToString(iLadderID, szLadderID, 16);
2112 | g_hNavMeshLadderIdToIndexMap.SetValue(szLadderID, iLadderIndex);
2113 |
2114 | float flLadderWidth;
2115 | ReadFileCell(hFile, view_as(flLadderWidth), FLOAT_BYTE_SIZE);
2116 | g_hNavMeshLadders.Set(iLadderIndex, flLadderWidth, NavMeshLadder_Width);
2117 |
2118 | float flLadderTopX; float flLadderTopY; float flLadderTopZ;
2119 | ReadFileCell(hFile, view_as(flLadderTopX), FLOAT_BYTE_SIZE);
2120 | ReadFileCell(hFile, view_as(flLadderTopY), FLOAT_BYTE_SIZE);
2121 | ReadFileCell(hFile, view_as(flLadderTopZ), FLOAT_BYTE_SIZE);
2122 | g_hNavMeshLadders.Set(iLadderIndex, flLadderTopX, NavMeshLadder_TopX);
2123 | g_hNavMeshLadders.Set(iLadderIndex, flLadderTopY, NavMeshLadder_TopY);
2124 | g_hNavMeshLadders.Set(iLadderIndex, flLadderTopZ, NavMeshLadder_TopZ);
2125 |
2126 | float flLadderBottomX; float flLadderBottomY; float flLadderBottomZ;
2127 | ReadFileCell(hFile, view_as(flLadderBottomX), FLOAT_BYTE_SIZE);
2128 | ReadFileCell(hFile, view_as(flLadderBottomY), FLOAT_BYTE_SIZE);
2129 | ReadFileCell(hFile, view_as(flLadderBottomZ), FLOAT_BYTE_SIZE);
2130 | g_hNavMeshLadders.Set(iLadderIndex, flLadderBottomX, NavMeshLadder_BottomX);
2131 | g_hNavMeshLadders.Set(iLadderIndex, flLadderBottomY, NavMeshLadder_BottomY);
2132 | g_hNavMeshLadders.Set(iLadderIndex, flLadderBottomZ, NavMeshLadder_BottomZ);
2133 |
2134 | float flLadderLength;
2135 | ReadFileCell(hFile, view_as(flLadderLength), FLOAT_BYTE_SIZE);
2136 | g_hNavMeshLadders.Set(iLadderIndex, flLadderLength, NavMeshLadder_Length);
2137 |
2138 | int iLadderDirection;
2139 | ReadFileCell(hFile, iLadderDirection, UNSIGNED_INT_BYTE_SIZE);
2140 | g_hNavMeshLadders.Set(iLadderIndex, iLadderDirection, NavMeshLadder_Direction);
2141 |
2142 | int iLadderTopForwardAreaID;
2143 | ReadFileCell(hFile, iLadderTopForwardAreaID, UNSIGNED_INT_BYTE_SIZE);
2144 | g_hNavMeshLadders.Set(iLadderIndex, iLadderTopForwardAreaID, NavMeshLadder_TopForwardAreaIndex);
2145 |
2146 | int iLadderTopLeftAreaID;
2147 | ReadFileCell(hFile, iLadderTopLeftAreaID, UNSIGNED_INT_BYTE_SIZE);
2148 | g_hNavMeshLadders.Set(iLadderIndex, iLadderTopLeftAreaID, NavMeshLadder_TopLeftAreaIndex);
2149 |
2150 | int iLadderTopRightAreaID;
2151 | ReadFileCell(hFile, iLadderTopRightAreaID, UNSIGNED_INT_BYTE_SIZE);
2152 | g_hNavMeshLadders.Set(iLadderIndex, iLadderTopRightAreaID, NavMeshLadder_TopRightAreaIndex);
2153 |
2154 | int iLadderTopBehindAreaID;
2155 | ReadFileCell(hFile, iLadderTopBehindAreaID, UNSIGNED_INT_BYTE_SIZE);
2156 | g_hNavMeshLadders.Set(iLadderIndex, iLadderTopBehindAreaID, NavMeshLadder_TopBehindAreaIndex);
2157 |
2158 | int iLadderBottomAreaID;
2159 | ReadFileCell(hFile, iLadderBottomAreaID, UNSIGNED_INT_BYTE_SIZE);
2160 | g_hNavMeshLadders.Set(iLadderIndex, iLadderBottomAreaID, NavMeshLadder_BottomAreaIndex);
2161 |
2162 | /*
2163 | LogMessage("Ladder ID - %d, Width: %0.1f, Top: %0.1f %0.1f %0.1f, Bottom: %0.1f %0.1f %0.1f, Length: %0.1f, Dir: %d, TopForwardArea: %d, TopLeftArea: %d, TopRightArea: %d, TopBehindArea: %d, BottomArea: %d",
2164 | iLadderID, flLadderWidth, flLadderTopX, flLadderTopY, flLadderTopZ, flLadderBottomX, flLadderBottomY,
2165 | flLadderBottomZ, flLadderLength, iLadderDirection, iLadderTopForwardAreaID,
2166 | iLadderTopLeftAreaID, iLadderTopRightAreaID, iLadderTopBehindAreaID, iLadderBottomAreaID
2167 | );
2168 | */
2169 |
2170 | return true;
2171 | }
2172 |
2173 | // Loads game-specific custom data.
2174 | bool NavMeshLoadCustomData(File hFile, int iNavVersion, int iNavSubVersion)
2175 | {
2176 | switch (GetEngineVersion())
2177 | {
2178 | // Insert other game-specific data stored in the mesh here.
2179 |
2180 | case Engine_Left4Dead2:
2181 | {
2182 | ReadFileCell(hFile, view_as(g_TerrorNavMeshNavMaxViewDistance), FLOAT_BYTE_SIZE);
2183 | }
2184 | }
2185 |
2186 | return true;
2187 | }
2188 |
2189 | void NavMeshDestroy()
2190 | {
2191 | g_hNavMeshPlaces.Clear();
2192 | g_hNavMeshAreas.Clear();
2193 | g_hNavMeshAreaConnections.Clear();
2194 | g_hNavMeshAreaIncomingConnections.Clear();
2195 | g_hNavMeshAreaHidingSpots.Clear();
2196 | g_hNavMeshAreaEncounterPaths.Clear();
2197 | g_hNavMeshAreaEncounterSpots.Clear();
2198 | g_hNavMeshAreaLadderConnections.Clear();
2199 | g_hNavMeshAreaVisibleAreas.Clear();
2200 | g_hNavMeshLadders.Clear();
2201 |
2202 | g_hNavMeshGrid.Clear();
2203 | g_hNavMeshGridLists.Clear();
2204 |
2205 | g_iNavMeshMagicNumber = 0;
2206 | g_iNavMeshVersion = 0;
2207 | g_iNavMeshSubVersion = 0;
2208 | g_iNavMeshSaveBSPSize = 0;
2209 | g_bNavMeshAnalyzed = false;
2210 |
2211 | g_bNavMeshBuilt = false;
2212 |
2213 | g_iNavMeshAreaOpenListIndex = -1;
2214 | g_iNavMeshAreaOpenListTailIndex = -1;
2215 | g_iNavMeshAreaMasterMarker = 0;
2216 |
2217 | g_hNavMeshAreaIdToIndexMap.Clear();
2218 | g_hNavMeshHidingSpotIdToIndexMap.Clear();
2219 | g_hNavMeshLadderIdToIndexMap.Clear();
2220 |
2221 | switch (GetEngineVersion())
2222 | {
2223 | case Engine_CSGO, Engine_CSS:
2224 | {
2225 | g_hCSNavAreaApproachInfo.Clear();
2226 | }
2227 | }
2228 | }
2229 |
2230 | void NavMeshPostLoad(bool success)
2231 | {
2232 | if (success)
2233 | {
2234 | switch (GetEngineVersion())
2235 | {
2236 | case Engine_CSGO, Engine_CSS:
2237 | {
2238 | for ( int i = 0; i < g_hCSNavAreaApproachInfo.Length; i++ )
2239 | {
2240 | CCSNavArea_ApproachInfo approachInfo;
2241 | g_hCSNavAreaApproachInfo.GetArray(i, approachInfo, sizeof(approachInfo));
2242 |
2243 | approachInfo.HereArea = NavMeshFindAreaByID(approachInfo.HereArea);
2244 | approachInfo.PrevArea = NavMeshFindAreaByID(approachInfo.PrevArea);
2245 | approachInfo.NextArea = NavMeshFindAreaByID(approachInfo.NextArea);
2246 |
2247 | g_hCSNavAreaApproachInfo.SetArray(i, approachInfo, sizeof(approachInfo));
2248 | }
2249 | }
2250 | }
2251 | }
2252 |
2253 | Call_StartForward(g_hNavMeshPostLoadForward);
2254 | Call_PushCell(success);
2255 | Call_Finish();
2256 | }
2257 |
2258 | void NavMeshGridAllocate(float flMinX, float flMaxX, float flMinY, float flMaxY)
2259 | {
2260 | g_hNavMeshGrid.Clear();
2261 | g_hNavMeshGridLists.Clear();
2262 |
2263 | g_flNavMeshMinX = flMinX;
2264 | g_flNavMeshMinY = flMinY;
2265 |
2266 | g_iNavMeshGridSizeX = IntCast((flMaxX - flMinX) / g_flNavMeshGridCellSize) + 1;
2267 | g_iNavMeshGridSizeY = IntCast((flMaxY - flMinY) / g_flNavMeshGridCellSize) + 1;
2268 |
2269 | int iArraySize = g_iNavMeshGridSizeX * g_iNavMeshGridSizeY;
2270 | g_hNavMeshGrid.Resize(iArraySize);
2271 |
2272 | for (int iGridIndex = 0; iGridIndex < iArraySize; iGridIndex++)
2273 | {
2274 | g_hNavMeshGrid.Set(iGridIndex, -1, NavMeshGrid_ListStartIndex);
2275 | g_hNavMeshGrid.Set(iGridIndex, -1, NavMeshGrid_ListEndIndex);
2276 | }
2277 | }
2278 |
2279 | void NavMeshGridFinalize()
2280 | {
2281 | bool bAllIn = true;
2282 |
2283 | SortADTArrayCustom(g_hNavMeshGridLists, SortNavMeshGridLists);
2284 |
2285 | for (int iGridIndex = 0, iSize = g_hNavMeshGrid.Length; iGridIndex < iSize; iGridIndex++)
2286 | {
2287 | int iStartIndex = -1;
2288 | int iEndIndex = -1;
2289 | NavMeshGridGetListBounds(iGridIndex, iStartIndex, iEndIndex);
2290 | g_hNavMeshGrid.Set(iGridIndex, iStartIndex, NavMeshGrid_ListStartIndex);
2291 | g_hNavMeshGrid.Set(iGridIndex, iEndIndex, NavMeshGrid_ListEndIndex);
2292 |
2293 | if (iStartIndex != -1)
2294 | {
2295 | for (int iListIndex = iStartIndex; iListIndex <= iEndIndex; iListIndex++)
2296 | {
2297 | int iAreaIndex = GetArrayCell(g_hNavMeshGridLists, iListIndex);
2298 | if (iAreaIndex != -1)
2299 | {
2300 |
2301 | }
2302 | else
2303 | {
2304 | LogError("Warning! Invalid nav area found in list of grid index %d!", iGridIndex);
2305 | bAllIn = false;
2306 | }
2307 | }
2308 | }
2309 | }
2310 |
2311 | if (!bAllIn)
2312 | {
2313 | LogError("Warning! Not all nav areas were parsed into the grid! Please check your nav mesh!");
2314 | }
2315 | }
2316 |
2317 | // The following functions should ONLY be called during NavMeshLoad(), due to displacement of
2318 | // array indexes!
2319 |
2320 | // Some things to take into account: because we're adding things into the
2321 | // array, it's inevitable that the indexes will change over time. Therefore,
2322 | // we can't assign array indexes while this function is running, since it
2323 | // will shift preceding array indexes.
2324 |
2325 | // The array indexes should be assigned afterwards using NavMeshGridFinalize().
2326 |
2327 | public int SortNavMeshGridLists(int index1, int index2, Handle ar, Handle hndl)
2328 | {
2329 | ArrayList array = view_as(ar);
2330 | int iGridIndex1 = array.Get(index1, NavMeshGridList_Owner);
2331 | int iGridIndex2 = array.Get(index2, NavMeshGridList_Owner);
2332 |
2333 | if (iGridIndex1 < iGridIndex2) return -1;
2334 | else if (iGridIndex1 > iGridIndex2) return 1;
2335 | return 0;
2336 | }
2337 |
2338 | void NavMeshGridAddAreaToList(int iGridIndex, int iAreaIndex)
2339 | {
2340 | int iIndex = g_hNavMeshGridLists.Push(iAreaIndex);
2341 |
2342 | if (iIndex != -1)
2343 | {
2344 | g_hNavMeshGridLists.Set(iIndex, iGridIndex, NavMeshGridList_Owner);
2345 | }
2346 | }
2347 |
2348 | void NavMeshGridGetListBounds(int iGridIndex, int &iStartIndex, int &iEndIndex)
2349 | {
2350 | iStartIndex = -1;
2351 | iEndIndex = -1;
2352 |
2353 | for (int i = 0, iSize = g_hNavMeshGridLists.Length; i < iSize; i++)
2354 | {
2355 | if (g_hNavMeshGridLists.Get(i, NavMeshGridList_Owner) == iGridIndex)
2356 | {
2357 | if (iStartIndex == -1) iStartIndex = i;
2358 | iEndIndex = i;
2359 | }
2360 | }
2361 | }
2362 |
2363 | void NavMeshAddAreaToGrid(iAreaIndex)
2364 | {
2365 | float flExtentLow[2]; float flExtentHigh[2];
2366 | // NavMeshAreaGetExtentLow(iAreaIndex, flExtentLow);
2367 | // NavMeshAreaGetExtentHigh(iAreaIndex, flExtentHigh);
2368 |
2369 | flExtentLow[0] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_X1));
2370 | flExtentLow[1] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Y1));
2371 | flExtentHigh[0] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_X2));
2372 | flExtentHigh[1] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Y2));
2373 |
2374 | int loX = NavMeshWorldToGridX(flExtentLow[0]);
2375 | int loY = NavMeshWorldToGridY(flExtentLow[1]);
2376 | int hiX = NavMeshWorldToGridX(flExtentHigh[0]);
2377 | int hiY = NavMeshWorldToGridY(flExtentHigh[1]);
2378 |
2379 | for (int y = loY; y <= hiY; ++y)
2380 | {
2381 | for (int x = loX; x <= hiX; ++x)
2382 | {
2383 | int iGridIndex = x + y * g_iNavMeshGridSizeX;
2384 | NavMeshGridAddAreaToList(iGridIndex, iAreaIndex);
2385 | }
2386 | }
2387 | }
2388 |
2389 | // The following functions are stock functions associated with the navmesh grid. These
2390 | // are safe to use after the grid has been finalized using NavMeshGridFinalize(), and
2391 | // can be included in other stock functions as well.
2392 |
2393 | stock int IntCast(float val)
2394 | {
2395 | if (val < 0.0) return RoundToFloor(val);
2396 | return RoundToCeil(val);
2397 | }
2398 |
2399 | stock int NavMeshWorldToGridX(float flWX)
2400 | {
2401 | int x = IntCast((flWX - g_flNavMeshMinX) / g_flNavMeshGridCellSize);
2402 |
2403 | if (x < 0) x = 0;
2404 | else if (x >= g_iNavMeshGridSizeX)
2405 | {
2406 | x = g_iNavMeshGridSizeX - 1;
2407 | }
2408 |
2409 | return x;
2410 | }
2411 |
2412 | stock int NavMeshWorldToGridY(float flWY)
2413 | {
2414 | new y = IntCast((flWY - g_flNavMeshMinY) / g_flNavMeshGridCellSize);
2415 |
2416 | if (y < 0) y = 0;
2417 | else if (y >= g_iNavMeshGridSizeY)
2418 | {
2419 | y = g_iNavMeshGridSizeY - 1;
2420 | }
2421 |
2422 | return y;
2423 | }
2424 |
2425 | stock ArrayStack NavMeshGridGetAreas(x, y)
2426 | {
2427 | int iGridIndex = x + y * g_iNavMeshGridSizeX;
2428 | int iListStartIndex = g_hNavMeshGrid.Get(iGridIndex, NavMeshGrid_ListStartIndex);
2429 | int iListEndIndex = g_hNavMeshGrid.Get(iGridIndex, NavMeshGrid_ListEndIndex);
2430 |
2431 | if (iListStartIndex == -1) return null;
2432 |
2433 | ArrayStack hStack = new ArrayStack();
2434 |
2435 | for (int i = iListStartIndex; i <= iListEndIndex; i++)
2436 | {
2437 | hStack.Push(g_hNavMeshGridLists.Get(i, NavMeshGridList_AreaIndex));
2438 | }
2439 |
2440 | return hStack;
2441 | }
2442 |
2443 | stock int NavMeshGetNearestArea(float flPos[3], bool bAnyZ=false, float flMaxDist=10000.0, bool bCheckLOS=false, bool bCheckGround=true, int iTeam=-2)
2444 | {
2445 | if (g_hNavMeshGridLists.Length == 0) return -1;
2446 |
2447 | int iClosestAreaIndex = -1;
2448 | float flClosestDistSq = flMaxDist * flMaxDist;
2449 |
2450 | if (!bCheckLOS && !bCheckGround)
2451 | {
2452 | iClosestAreaIndex = NavMeshGetArea(flPos);
2453 | if (iClosestAreaIndex != -1) return iClosestAreaIndex;
2454 | }
2455 |
2456 | float flSource[3];
2457 | flSource[0] = flPos[0];
2458 | flSource[1] = flPos[1];
2459 |
2460 | float flNormal[3];
2461 | if (!NavMeshGetGroundHeight(flPos, flSource[2], flNormal))
2462 | {
2463 | if (!bCheckGround)
2464 | {
2465 | flSource[2] = flPos[2];
2466 | }
2467 | else
2468 | {
2469 | return -1;
2470 | }
2471 | }
2472 |
2473 | flSource[2] += HalfHumanHeight;
2474 |
2475 | static int iSearchMarker = -1;
2476 | if (iSearchMarker == -1) iSearchMarker = GetRandomInt(0, 1024 * 1024);
2477 |
2478 | iSearchMarker++;
2479 | if (iSearchMarker == 0) iSearchMarker++;
2480 |
2481 | int iOriginX = NavMeshWorldToGridX(flPos[0]);
2482 | int iOriginY = NavMeshWorldToGridY(flPos[1]);
2483 |
2484 | int iShiftLimit = RoundToCeil(flMaxDist / g_flNavMeshGridCellSize);
2485 |
2486 | for (int iShift = 0; iShift <= iShiftLimit; ++iShift)
2487 | {
2488 | for (int x = (iOriginX - iShift); x <= (iOriginX + iShift); ++x)
2489 | {
2490 | if (x < 0 || x >= g_iNavMeshGridSizeX) continue;
2491 |
2492 | for (int y = (iOriginY - iShift); y <= (iOriginY + iShift); ++y)
2493 | {
2494 | if (y < 0 || y >= g_iNavMeshGridSizeY) continue;
2495 |
2496 | if (x > (iOriginX - iShift) &&
2497 | x < (iOriginX + iShift) &&
2498 | y > (iOriginY - iShift) &&
2499 | y < (iOriginY + iShift))
2500 | {
2501 | continue;
2502 | }
2503 |
2504 | ArrayStack hAreas = NavMeshGridGetAreas(x, y);
2505 | if (hAreas != null)
2506 | {
2507 | while (!hAreas.Empty)
2508 | {
2509 | int iAreaIndex = -1;
2510 | PopStackCell(hAreas, iAreaIndex);
2511 |
2512 | int iAreaNearSearchMarker = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_NearSearchMarker);
2513 | if (iAreaNearSearchMarker == iSearchMarker) continue;
2514 |
2515 | if (g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Blocked))
2516 | {
2517 | continue;
2518 | }
2519 |
2520 | g_hNavMeshAreas.Set(iAreaIndex, iSearchMarker, NavMeshArea_NearSearchMarker);
2521 |
2522 | float flAreaPos[3];
2523 | NavMeshAreaGetClosestPointOnArea(iAreaIndex, flSource, flAreaPos);
2524 |
2525 | float flDistSq = Pow(GetVectorDistance(flPos, flAreaPos), 2.0);
2526 |
2527 | if (flDistSq >= flClosestDistSq) continue;
2528 |
2529 | if (bCheckLOS)
2530 | {
2531 | float flSafePos[3];
2532 | float flStartPos[3];
2533 | float flEndPos[3];
2534 | flEndPos[0] = flPos[0];
2535 | flEndPos[1] = flPos[1];
2536 | flEndPos[2] = flPos[2] + StepHeight;
2537 |
2538 | Handle hTrace = TR_TraceRayFilterEx(flPos, flEndPos, MASK_NPCSOLID_BRUSHONLY, RayType_EndPoint, TraceRayIgnoreCustom);
2539 | float flFraction = TR_GetFraction(hTrace);
2540 | TR_GetEndPosition(flEndPos, hTrace);
2541 | delete hTrace;
2542 |
2543 | if (flFraction == 0.0)
2544 | {
2545 | flSafePos[0] = flEndPos[0];
2546 | flSafePos[1] = flEndPos[1];
2547 | flSafePos[2] = flEndPos[2] + 1.0;
2548 | }
2549 | else
2550 | {
2551 | flSafePos[0] = flPos[0];
2552 | flSafePos[1] = flPos[1];
2553 | flSafePos[2] = flPos[2];
2554 | }
2555 |
2556 | float flHeightDelta = FloatAbs(flAreaPos[2] - flSafePos[2]);
2557 | if (flHeightDelta > StepHeight)
2558 | {
2559 | flStartPos[0] = flAreaPos[0];
2560 | flStartPos[1] = flAreaPos[1];
2561 | flStartPos[2] = flAreaPos[2] + StepHeight;
2562 |
2563 | flEndPos[0] = flAreaPos[0];
2564 | flEndPos[1] = flAreaPos[1];
2565 | flEndPos[2] = flSafePos[2];
2566 |
2567 | hTrace = TR_TraceRayFilterEx(flStartPos, flEndPos, MASK_NPCSOLID_BRUSHONLY, RayType_EndPoint, TraceRayIgnoreCustom);
2568 | flFraction = TR_GetFraction(hTrace);
2569 | delete hTrace;
2570 |
2571 | if (flFraction != 1.0)
2572 | {
2573 | continue;
2574 | }
2575 | }
2576 |
2577 | flEndPos[0] = flAreaPos[0];
2578 | flEndPos[1] = flAreaPos[1];
2579 | flEndPos[2] = flSafePos[2] + StepHeight;
2580 |
2581 | hTrace = TR_TraceRayFilterEx(flSafePos, flEndPos, MASK_NPCSOLID_BRUSHONLY, RayType_EndPoint, TraceRayIgnoreCustom);
2582 | flFraction = TR_GetFraction(hTrace);
2583 | delete hTrace;
2584 |
2585 | if (flFraction != 1.0)
2586 | {
2587 | continue;
2588 | }
2589 | }
2590 |
2591 | flClosestDistSq = flDistSq;
2592 | iClosestAreaIndex = iAreaIndex;
2593 |
2594 | iShiftLimit = iShift + 1;
2595 | }
2596 |
2597 | delete hAreas;
2598 | }
2599 | }
2600 | }
2601 | }
2602 |
2603 | return iClosestAreaIndex;
2604 | }
2605 |
2606 | stock void NavMeshAreaGetClosestPointOnArea(int iAreaIndex, const float flPos[3], float flClose[3])
2607 | {
2608 | float x; float y; float z;
2609 |
2610 | float flExtentLow[3]; float flExtentHigh[3];
2611 | NavMeshAreaGetExtentLow(iAreaIndex, flExtentLow);
2612 | NavMeshAreaGetExtentHigh(iAreaIndex, flExtentHigh);
2613 |
2614 | x = fsel(flPos[0] - flExtentLow[0], flPos[0], flExtentLow[0]);
2615 | x = fsel(x - flExtentHigh[0], flExtentHigh[0], x);
2616 |
2617 | y = fsel(flPos[1] - flExtentLow[1], flPos[1], flExtentLow[1]);
2618 | y = fsel(y - flExtentHigh[1], flExtentHigh[1], y);
2619 |
2620 | z = NavMeshAreaGetZFromXAndY(iAreaIndex, x, y);
2621 |
2622 | flClose[0] = x;
2623 | flClose[1] = y;
2624 | flClose[2] = z;
2625 | }
2626 |
2627 | stock float fsel(float a, float b, float c)
2628 | {
2629 | return a >= 0.0 ? b : c;
2630 | }
2631 |
2632 | stock int NavMeshAreaGetID(int iAreaIndex)
2633 | {
2634 | if (!g_bNavMeshBuilt) return -1;
2635 |
2636 | return g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_ID);
2637 | }
2638 |
2639 | stock int NavMeshFindAreaByID(int iAreaID)
2640 | {
2641 | if (iAreaID == -1)
2642 | return -1;
2643 |
2644 | char szAreaID[16];
2645 | IntToString(iAreaID, szAreaID, 16);
2646 | int iAreaIndex = -1;
2647 | if (g_hNavMeshAreaIdToIndexMap.GetValue(szAreaID, iAreaIndex))
2648 | return iAreaIndex;
2649 |
2650 | return -1;
2651 | }
2652 |
2653 | stock int NavMeshAreaGetFlags(int iAreaIndex)
2654 | {
2655 | if (!g_bNavMeshBuilt) return 0;
2656 |
2657 | return g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Flags);
2658 | }
2659 |
2660 | stock void NavMeshAreaGetPlace(int iAreaIndex, char[] buffer, int maxlen)
2661 | {
2662 | int placeIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_PlaceID);
2663 |
2664 | if (placeIndex < 0 || placeIndex >= g_hNavMeshPlaces.Length)
2665 | {
2666 | strcopy(buffer, maxlen, "");
2667 | return;
2668 | }
2669 |
2670 | g_hNavMeshPlaces.GetString(placeIndex, buffer, maxlen);
2671 | }
2672 |
2673 | stock bool NavMeshAreaGetCenter(int iAreaIndex, float flBuffer[3])
2674 | {
2675 | if (!g_bNavMeshBuilt) return false;
2676 |
2677 | flBuffer[0] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_CenterX));
2678 | flBuffer[1] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_CenterY));
2679 | flBuffer[2] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_CenterZ));
2680 | return true;
2681 | }
2682 |
2683 | stock void NavMeshAreaGetCorner(int iAreaIndex, NavCornerType corner, float buffer[3])
2684 | {
2685 | switch (corner)
2686 | {
2687 | case NAV_CORNER_NORTH_WEST:
2688 | {
2689 | NavMeshAreaGetExtentLow( iAreaIndex, buffer );
2690 | }
2691 | case NAV_CORNER_NORTH_EAST:
2692 | {
2693 | buffer[0] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_X2));
2694 | buffer[1] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Y1));
2695 | buffer[2] = NavMeshAreaGetNECornerZ(iAreaIndex);
2696 | }
2697 | case NAV_CORNER_SOUTH_WEST:
2698 | {
2699 | buffer[0] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_X1));
2700 | buffer[1] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Y2));
2701 | buffer[2] = NavMeshAreaGetSWCornerZ(iAreaIndex);
2702 | }
2703 | case NAV_CORNER_SOUTH_EAST:
2704 | {
2705 | NavMeshAreaGetExtentHigh( iAreaIndex, buffer );
2706 | }
2707 | }
2708 | }
2709 |
2710 | stock void NavMeshAreaGetRandomPoint(int iAreaIndex, float buffer[3])
2711 | {
2712 | float extentLow[3];
2713 | float extentHigh[3];
2714 | NavMeshAreaGetExtentLow(iAreaIndex, extentLow);
2715 | NavMeshAreaGetExtentHigh(iAreaIndex, extentHigh);
2716 |
2717 | buffer[0] = GetRandomFloat(extentLow[0], extentHigh[0]);
2718 | buffer[1] = GetRandomFloat(extentLow[1], extentHigh[1]);
2719 | buffer[2] = NavMeshAreaGetZ(iAreaIndex, buffer);
2720 | }
2721 |
2722 | stock ArrayStack NavMeshAreaGetAdjacentList(int iAreaIndex, int iNavDirection)
2723 | {
2724 | if (!g_bNavMeshBuilt) return null;
2725 |
2726 | int iConnectionsStartIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_ConnectionsStartIndex);
2727 | if (iConnectionsStartIndex == -1) return null;
2728 |
2729 | int iConnectionsEndIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_ConnectionsEndIndex);
2730 |
2731 | ArrayStack hStack = new ArrayStack();
2732 |
2733 | for (int i = iConnectionsStartIndex; i <= iConnectionsEndIndex; i++)
2734 | {
2735 | if (g_hNavMeshAreaConnections.Get(i, NavMeshConnection_Direction) == iNavDirection)
2736 | {
2737 | hStack.Push(g_hNavMeshAreaConnections.Get(i, NavMeshConnection_AreaIndex));
2738 | }
2739 | }
2740 |
2741 | return hStack;
2742 | }
2743 |
2744 | stock ArrayStack NavMeshAreaGetIncomingConnectionsList(int iAreaIndex, int iNavDirection)
2745 | {
2746 | if (!g_bNavMeshBuilt) return null;
2747 |
2748 | int iConnectionsStartIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_IncomingConnectionsStartIndex);
2749 | if (iConnectionsStartIndex == -1) return null;
2750 |
2751 | int iConnectionsEndIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_IncomingConnectionsEndIndex);
2752 |
2753 | ArrayStack hStack = new ArrayStack();
2754 |
2755 | for (int i = iConnectionsStartIndex; i <= iConnectionsEndIndex; i++)
2756 | {
2757 | if (g_hNavMeshAreaIncomingConnections.Get(i, NavMeshConnection_Direction) == iNavDirection)
2758 | {
2759 | hStack.Push(g_hNavMeshAreaIncomingConnections.Get(i, NavMeshConnection_AreaIndex));
2760 | }
2761 | }
2762 |
2763 | return hStack;
2764 | }
2765 |
2766 | stock ArrayStack NavMeshAreaGetLadderList(int iAreaIndex, int iLadderDir)
2767 | {
2768 | if (!g_bNavMeshBuilt) return null;
2769 |
2770 | int iLadderConnectionsStartIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_LadderConnectionsStartIndex);
2771 | if (iLadderConnectionsStartIndex == -1) return null;
2772 |
2773 | int iLadderConnectionsEndIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_LadderConnectionsEndIndex);
2774 |
2775 | ArrayStack hStack = new ArrayStack();
2776 |
2777 | for (int i = iLadderConnectionsStartIndex; i <= iLadderConnectionsEndIndex; i++)
2778 | {
2779 | if (g_hNavMeshAreaLadderConnections.Get(i, NavMeshLadderConnection_Direction) == iLadderDir)
2780 | {
2781 | hStack.Push(g_hNavMeshAreaLadderConnections.Get(i, NavMeshLadderConnection_LadderIndex));
2782 | }
2783 | }
2784 |
2785 | return hStack;
2786 | }
2787 |
2788 | stock ArrayStack NavMeshAreaGetHidingSpots(int iAreaIndex)
2789 | {
2790 | if (!g_bNavMeshBuilt) return null;
2791 |
2792 | int startIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_HidingSpotsStartIndex);
2793 | if (startIndex == -1) return null;
2794 |
2795 | int endIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_HidingSpotsEndIndex);
2796 |
2797 | ArrayStack hStack = new ArrayStack();
2798 | for (int i = startIndex; i <= endIndex; i++) hStack.Push(i);
2799 |
2800 | return hStack;
2801 | }
2802 |
2803 | stock int NavMeshAreaGetTotalCost(int iAreaIndex)
2804 | {
2805 | if (!g_bNavMeshBuilt) return 0;
2806 |
2807 | return g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_TotalCost);
2808 | }
2809 |
2810 | stock int NavMeshAreaGetCostSoFar(int iAreaIndex)
2811 | {
2812 | if (!g_bNavMeshBuilt) return 0;
2813 |
2814 | return g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_CostSoFar);
2815 | }
2816 |
2817 | stock int NavMeshAreaGetParent(int iAreaIndex)
2818 | {
2819 | if (!g_bNavMeshBuilt) return -1;
2820 |
2821 | return g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Parent);
2822 | }
2823 |
2824 | stock int NavMeshAreaGetParentHow(int iAreaIndex)
2825 | {
2826 | if (!g_bNavMeshBuilt) return NUM_TRAVERSE_TYPES;
2827 |
2828 | return g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_ParentHow);
2829 | }
2830 |
2831 | stock void NavMeshAreaSetParent(int iAreaIndex, int iParentAreaIndex)
2832 | {
2833 | if (!g_bNavMeshBuilt) return;
2834 |
2835 | g_hNavMeshAreas.Set(iAreaIndex, iParentAreaIndex, NavMeshArea_Parent);
2836 | }
2837 |
2838 | stock void NavMeshAreaSetParentHow(int iAreaIndex, int iParentHow)
2839 | {
2840 | if (!g_bNavMeshBuilt) return;
2841 |
2842 | g_hNavMeshAreas.Set(iAreaIndex, iParentHow, NavMeshArea_ParentHow);
2843 | }
2844 |
2845 | stock bool NavMeshAreaGetExtentLow(int iAreaIndex, float flBuffer[3])
2846 | {
2847 | if (!g_bNavMeshBuilt) return false;
2848 |
2849 | flBuffer[0] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_X1));
2850 | flBuffer[1] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Y1));
2851 | flBuffer[2] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Z1));
2852 | return true;
2853 | }
2854 |
2855 | stock bool NavMeshAreaGetExtentHigh(int iAreaIndex, float flBuffer[3])
2856 | {
2857 | if (!g_bNavMeshBuilt) return false;
2858 |
2859 | flBuffer[0] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_X2));
2860 | flBuffer[1] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Y2));
2861 | flBuffer[2] = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_Z2));
2862 | return true;
2863 | }
2864 |
2865 | stock bool NavMeshAreaIsOverlappingPoint(int iAreaIndex, const float flPos[3], float flTolerance)
2866 | {
2867 | if (!g_bNavMeshBuilt) return false;
2868 |
2869 | float flExtentLow[3]; float flExtentHigh[3];
2870 | NavMeshAreaGetExtentLow(iAreaIndex, flExtentLow);
2871 | NavMeshAreaGetExtentHigh(iAreaIndex, flExtentHigh);
2872 |
2873 | if (flPos[0] + flTolerance >= flExtentLow[0] &&
2874 | flPos[0] - flTolerance <= flExtentHigh[0] &&
2875 | flPos[1] + flTolerance >= flExtentLow[1] &&
2876 | flPos[1] - flTolerance <= flExtentHigh[1])
2877 | {
2878 | return true;
2879 | }
2880 |
2881 | return false;
2882 | }
2883 |
2884 | stock bool NavMeshAreaIsOverlappingArea(int iAreaIndex, int iTargetAreaIndex)
2885 | {
2886 | if (!g_bNavMeshBuilt) return false;
2887 |
2888 | float flExtentLow[3]; float flExtentHigh[3];
2889 | NavMeshAreaGetExtentLow(iAreaIndex, flExtentLow);
2890 | NavMeshAreaGetExtentHigh(iAreaIndex, flExtentHigh);
2891 |
2892 | float flTargetExtentLow[3]; float flTargetExtentHigh[3];
2893 | NavMeshAreaGetExtentLow(iTargetAreaIndex, flTargetExtentLow);
2894 | NavMeshAreaGetExtentHigh(iTargetAreaIndex, flTargetExtentHigh);
2895 |
2896 | if (flTargetExtentLow[0] < flExtentHigh[0] &&
2897 | flTargetExtentHigh[0] > flExtentLow[0] &&
2898 | flTargetExtentLow[1] < flExtentHigh[1] &&
2899 | flTargetExtentHigh[1] > flExtentLow[1])
2900 | {
2901 | return true;
2902 | }
2903 |
2904 | return false;
2905 | }
2906 |
2907 | stock float NavMeshAreaGetNECornerZ(int iAreaIndex)
2908 | {
2909 | if (!g_bNavMeshBuilt) return 0.0;
2910 | return view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_NECornerZ));
2911 | }
2912 |
2913 | stock float NavMeshAreaGetSWCornerZ(int iAreaIndex)
2914 | {
2915 | if (!g_bNavMeshBuilt) return 0.0;
2916 | return view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_SWCornerZ));
2917 | }
2918 |
2919 | stock float NavMeshAreaGetZ(int iAreaIndex, const float flPos[3])
2920 | {
2921 | if (!g_bNavMeshBuilt) return 0.0;
2922 |
2923 | float flExtentLow[3]; float flExtentHigh[3];
2924 | NavMeshAreaGetExtentLow(iAreaIndex, flExtentLow);
2925 | NavMeshAreaGetExtentHigh(iAreaIndex, flExtentHigh);
2926 |
2927 | float dx = flExtentHigh[0] - flExtentLow[0];
2928 | float dy = flExtentHigh[1] - flExtentLow[1];
2929 |
2930 | float flNEZ = NavMeshAreaGetNECornerZ(iAreaIndex);
2931 |
2932 | if (dx == 0.0 || dy == 0.0)
2933 | {
2934 | return flNEZ;
2935 | }
2936 |
2937 | float u = (flPos[0] - flExtentLow[0]) / dx;
2938 | float v = (flPos[1] - flExtentLow[1]) / dy;
2939 |
2940 | u = fsel(u, u, 0.0);
2941 | u = fsel(u - 1.0, 1.0, u);
2942 |
2943 | v = fsel(v, v, 0.0);
2944 | v = fsel(v - 1.0, 1.0, v);
2945 |
2946 | float flSWZ = NavMeshAreaGetSWCornerZ(iAreaIndex);
2947 |
2948 | float flNorthZ = flExtentLow[2] + u * (flNEZ - flExtentLow[2]);
2949 | float flSouthZ = flSWZ + u * (flExtentHigh[2] - flSWZ);
2950 |
2951 | return flNorthZ + v * (flSouthZ - flNorthZ);
2952 | }
2953 |
2954 | stock float NavMeshAreaGetZFromXAndY(int iAreaIndex, float x, float y)
2955 | {
2956 | if (!g_bNavMeshBuilt) return 0.0;
2957 |
2958 | float flInvDxCorners = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_InvDxCorners));
2959 | float flInvDyCorners = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_InvDyCorners));
2960 |
2961 | float flNECornerZ = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_NECornerZ));
2962 |
2963 | if (flInvDxCorners == 0.0 || flInvDyCorners == 0.0)
2964 | {
2965 | return flNECornerZ;
2966 | }
2967 |
2968 | float flExtentLow[3]; float flExtentHigh[3];
2969 | NavMeshAreaGetExtentLow(iAreaIndex, flExtentLow);
2970 | NavMeshAreaGetExtentHigh(iAreaIndex, flExtentHigh);
2971 |
2972 | float u = (x - flExtentLow[0]) * flInvDxCorners;
2973 | float v = (y - flExtentLow[1]) * flInvDyCorners;
2974 |
2975 | u = FloatClamp(u, 0.0, 1.0);
2976 | v = FloatClamp(v, 0.0, 1.0);
2977 |
2978 | float flSWCornerZ = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_SWCornerZ));
2979 |
2980 | float flNorthZ = flExtentLow[2] + u * (flNECornerZ - flExtentLow[2]);
2981 | float flSouthZ = flSWCornerZ + u * (flExtentHigh[2] - flSWCornerZ);
2982 |
2983 | return flNorthZ + v * (flSouthZ - flNorthZ);
2984 | }
2985 |
2986 | stock bool NavMeshAreaContains(int iAreaIndex, const float flPos[3])
2987 | {
2988 | if (!g_bNavMeshBuilt) return false;
2989 |
2990 | if (!NavMeshAreaIsOverlappingPoint(iAreaIndex, flPos, 0.0)) return false;
2991 |
2992 | float flMyZ = NavMeshAreaGetZ(iAreaIndex, flPos);
2993 |
2994 | if ((flMyZ - StepHeight) > flPos[2]) return false;
2995 |
2996 | for (new i = 0, iSize = g_hNavMeshAreas.Length; i < iSize; i++)
2997 | {
2998 | if (i == iAreaIndex) continue;
2999 |
3000 | if (!NavMeshAreaIsOverlappingArea(iAreaIndex, i)) continue;
3001 |
3002 | float flTheirZ = NavMeshAreaGetZ(i, flPos);
3003 | if ((flTheirZ - StepHeight) > flPos[2]) continue;
3004 |
3005 | if (flTheirZ > flMyZ)
3006 | {
3007 | return false;
3008 | }
3009 | }
3010 |
3011 | return true;
3012 | }
3013 |
3014 | stock bool NavMeshAreaComputePortal(int iAreaIndex, int iAreaToIndex, int iNavDirection, float flCenter[3], float &flHalfWidth)
3015 | {
3016 | if (!g_bNavMeshBuilt) return false;
3017 |
3018 | float flAreaExtentLow[3]; float flAreaExtentHigh[3];
3019 | NavMeshAreaGetExtentLow(iAreaIndex, flAreaExtentLow);
3020 | NavMeshAreaGetExtentHigh(iAreaIndex, flAreaExtentHigh);
3021 |
3022 | float flAreaToExtentLow[3]; float flAreaToExtentHigh[3];
3023 | NavMeshAreaGetExtentLow(iAreaToIndex, flAreaToExtentLow);
3024 | NavMeshAreaGetExtentHigh(iAreaToIndex, flAreaToExtentHigh);
3025 |
3026 | if (iNavDirection == NAV_DIR_NORTH || iNavDirection == NAV_DIR_SOUTH)
3027 | {
3028 | if (iNavDirection == NAV_DIR_NORTH)
3029 | {
3030 | flCenter[1] = flAreaExtentLow[1];
3031 | }
3032 | else
3033 | {
3034 | flCenter[1] = flAreaExtentHigh[1];
3035 | }
3036 |
3037 | float flLeft = flAreaExtentLow[0] > flAreaToExtentLow[0] ? flAreaExtentLow[0] : flAreaToExtentLow[0];
3038 | float flRight = flAreaExtentHigh[0] < flAreaToExtentHigh[0] ? flAreaExtentHigh[0] : flAreaToExtentHigh[0];
3039 |
3040 | if (flLeft < flAreaExtentLow[0]) flLeft = flAreaExtentLow[0];
3041 | else if (flLeft > flAreaExtentHigh[0]) flLeft = flAreaExtentHigh[0];
3042 |
3043 | if (flRight < flAreaExtentLow[0]) flRight = flAreaExtentLow[0];
3044 | else if (flRight > flAreaExtentHigh[0]) flRight = flAreaExtentHigh[0];
3045 |
3046 | flCenter[0] = (flLeft + flRight) / 2.0;
3047 | flHalfWidth = (flRight - flLeft) / 2.0;
3048 | }
3049 | else
3050 | {
3051 | if (iNavDirection == NAV_DIR_WEST)
3052 | {
3053 | flCenter[0] = flAreaExtentLow[0];
3054 | }
3055 | else
3056 | {
3057 | flCenter[0] = flAreaExtentHigh[0];
3058 | }
3059 |
3060 | float flTop = flAreaExtentLow[1] > flAreaToExtentLow[1] ? flAreaExtentLow[1] : flAreaToExtentLow[1];
3061 | float flBottom = flAreaExtentHigh[1] < flAreaToExtentHigh[1] ? flAreaExtentHigh[1] : flAreaToExtentHigh[1];
3062 |
3063 | if (flTop < flAreaExtentLow[1]) flTop = flAreaExtentLow[1];
3064 | else if (flTop > flAreaExtentHigh[1]) flTop = flAreaExtentHigh[1];
3065 |
3066 | if (flBottom < flAreaExtentLow[1]) flBottom = flAreaExtentLow[1];
3067 | else if (flBottom > flAreaExtentHigh[1]) flBottom = flAreaExtentHigh[1];
3068 |
3069 | flCenter[1] = (flTop + flBottom) / 2.0;
3070 | flHalfWidth = (flBottom - flTop) / 2.0;
3071 | }
3072 |
3073 | flCenter[2] = NavMeshAreaGetZFromXAndY(iAreaIndex, flCenter[0], flCenter[1]);
3074 |
3075 | return true;
3076 | }
3077 |
3078 | stock bool NavMeshAreaIsConnected(int iAreaIndex, int iTargetAreaIndex, int iNavDirection)
3079 | {
3080 | if (iAreaIndex == iTargetAreaIndex) return true;
3081 |
3082 | if (iNavDirection == NAV_DIR_COUNT)
3083 | {
3084 | for (int dir = 0; dir < NAV_DIR_COUNT; dir++)
3085 | {
3086 | if (NavMeshAreaIsConnected(iAreaIndex, iTargetAreaIndex, dir))
3087 | {
3088 | return true;
3089 | }
3090 | }
3091 |
3092 | // TODO: Check ladder connections.
3093 | }
3094 | else
3095 | {
3096 | int connectionsStartIndex = g_hNavMeshAreas.Get( iAreaIndex, NavMeshArea_ConnectionsStartIndex );
3097 | if (connectionsStartIndex == -1)
3098 | return false;
3099 |
3100 | int connectionsEndIndex = g_hNavMeshAreas.Get( iAreaIndex, NavMeshArea_ConnectionsEndIndex );
3101 | for ( int i = connectionsStartIndex; i <= connectionsEndIndex; i++ )
3102 | {
3103 | if ( g_hNavMeshAreaConnections.Get(i, NavMeshConnection_Direction) != iNavDirection )
3104 | continue;
3105 |
3106 | if ( g_hNavMeshAreaConnections.Get(i, NavMeshConnection_AreaIndex) == iTargetAreaIndex )
3107 | return true;
3108 | }
3109 | }
3110 |
3111 | return false;
3112 | }
3113 |
3114 | stock float FloatMin(float a, float b)
3115 | {
3116 | if (a < b) return a;
3117 | return b;
3118 | }
3119 |
3120 | stock float FloatMax(float a, float b)
3121 | {
3122 | if (a > b) return a;
3123 | return b;
3124 | }
3125 |
3126 | stock bool NavMeshAreaComputeClosestPointInPortal(int iAreaIndex, int iAreaToIndex, int iNavDirection, const float flFromPos[3], float flClosestPos[3])
3127 | {
3128 | if (!g_bNavMeshBuilt) return false;
3129 |
3130 | static float flMargin = 25.0; // GenerationStepSize = 25.0;
3131 |
3132 | float flAreaExtentLow[3]; float flAreaExtentHigh[3];
3133 | NavMeshAreaGetExtentLow(iAreaIndex, flAreaExtentLow);
3134 | NavMeshAreaGetExtentHigh(iAreaIndex, flAreaExtentHigh);
3135 |
3136 | float flAreaToExtentLow[3]; float flAreaToExtentHigh[3];
3137 | NavMeshAreaGetExtentLow(iAreaToIndex, flAreaToExtentLow);
3138 | NavMeshAreaGetExtentHigh(iAreaToIndex, flAreaToExtentHigh);
3139 |
3140 | if (iNavDirection == NAV_DIR_NORTH || iNavDirection == NAV_DIR_SOUTH)
3141 | {
3142 | if (iNavDirection == NAV_DIR_NORTH)
3143 | {
3144 | flClosestPos[1] = flAreaExtentLow[1];
3145 | }
3146 | else
3147 | {
3148 | flClosestPos[1] = flAreaExtentHigh[1];
3149 | }
3150 |
3151 | float flLeft = FloatMax(flAreaExtentLow[0], flAreaToExtentLow[0]);
3152 | float flRight = FloatMin(flAreaExtentHigh[0], flAreaToExtentHigh[0]);
3153 |
3154 | float flLeftMargin = NavMeshAreaIsEdge(iAreaToIndex, NAV_DIR_WEST) ? (flLeft + flMargin) : flLeft;
3155 | float flRightMargin = NavMeshAreaIsEdge(iAreaToIndex, NAV_DIR_EAST) ? (flRight - flMargin) : flRight;
3156 |
3157 | if (flLeftMargin > flRightMargin)
3158 | {
3159 | float flMid = (flLeft + flRight) / 2.0;
3160 | flLeftMargin = flMid;
3161 | flRightMargin = flMid;
3162 | }
3163 |
3164 | if (flFromPos[0] < flLeftMargin)
3165 | {
3166 | flClosestPos[0] = flLeftMargin;
3167 | }
3168 | else if (flFromPos[0] > flRightMargin)
3169 | {
3170 | flClosestPos[0] = flRightMargin;
3171 | }
3172 | else
3173 | {
3174 | flClosestPos[0] = flFromPos[0];
3175 | }
3176 | }
3177 | else
3178 | {
3179 | if (iNavDirection == NAV_DIR_WEST)
3180 | {
3181 | flClosestPos[0] = flAreaExtentLow[0];
3182 | }
3183 | else
3184 | {
3185 | flClosestPos[0] = flAreaExtentHigh[0];
3186 | }
3187 |
3188 | float flTop = FloatMax(flAreaExtentLow[1], flAreaToExtentLow[1]);
3189 | float flBottom = FloatMin(flAreaExtentHigh[1], flAreaToExtentHigh[1]);
3190 |
3191 | float flTopMargin = NavMeshAreaIsEdge(iAreaToIndex, NAV_DIR_NORTH) ? (flTop + flMargin) : flTop;
3192 | float flBottomMargin = NavMeshAreaIsEdge(iAreaToIndex, NAV_DIR_SOUTH) ? (flBottom - flMargin) : flBottom;
3193 |
3194 | if (flTopMargin > flBottomMargin)
3195 | {
3196 | float flMid = (flTop + flBottom) / 2.0;
3197 | flTopMargin = flMid;
3198 | flBottomMargin = flMid;
3199 | }
3200 |
3201 | if (flFromPos[1] < flTopMargin)
3202 | {
3203 | flClosestPos[1] = flTopMargin;
3204 | }
3205 | else if (flFromPos[1] > flBottomMargin)
3206 | {
3207 | flClosestPos[1] = flBottomMargin;
3208 | }
3209 | else
3210 | {
3211 | flClosestPos[1] = flFromPos[1];
3212 | }
3213 | }
3214 |
3215 | flClosestPos[2] = NavMeshAreaGetZFromXAndY(iAreaIndex, flClosestPos[0], flClosestPos[1]);
3216 |
3217 | return true;
3218 | }
3219 |
3220 | stock int NavMeshAreaComputeDirection(int iAreaIndex, const float flPos[3])
3221 | {
3222 | if (!g_bNavMeshBuilt) return NAV_DIR_COUNT;
3223 |
3224 | float flExtentLow[3]; float flExtentHigh[3];
3225 | NavMeshAreaGetExtentLow(iAreaIndex, flExtentLow);
3226 | NavMeshAreaGetExtentHigh(iAreaIndex, flExtentHigh);
3227 |
3228 | if (flPos[0] >= flExtentLow[0] && flPos[0] <= flExtentHigh[0])
3229 | {
3230 | if (flPos[1] < flExtentLow[1])
3231 | {
3232 | return NAV_DIR_NORTH;
3233 | }
3234 | else if (flPos[1] > flExtentHigh[1])
3235 | {
3236 | return NAV_DIR_SOUTH;
3237 | }
3238 | }
3239 | else if (flPos[1] >= flExtentLow[1] && flPos[1] <= flExtentHigh[1])
3240 | {
3241 | if (flPos[0] < flExtentLow[0])
3242 | {
3243 | return NAV_DIR_WEST;
3244 | }
3245 | else if (flPos[0] > flExtentHigh[0])
3246 | {
3247 | return NAV_DIR_EAST;
3248 | }
3249 | }
3250 |
3251 | float flCenter[3];
3252 | NavMeshAreaGetCenter(iAreaIndex, flCenter);
3253 |
3254 | float flTo[3];
3255 | SubtractVectors(flPos, flCenter, flTo);
3256 |
3257 | if (FloatAbs(flTo[0]) > FloatAbs(flTo[1]))
3258 | {
3259 | if (flTo[0] > 0.0) return NAV_DIR_EAST;
3260 |
3261 | return NAV_DIR_WEST;
3262 | }
3263 | else
3264 | {
3265 | if (flTo[1] > 0.0) return NAV_DIR_SOUTH;
3266 |
3267 | return NAV_DIR_NORTH;
3268 | }
3269 | }
3270 |
3271 | stock float NavMeshAreaGetLightIntensity(int iAreaIndex, const float flPos[3])
3272 | {
3273 | if (!g_bNavMeshBuilt) return 0.0;
3274 |
3275 | float flExtentLow[3]; float flExtentHigh[3];
3276 | NavMeshAreaGetExtentLow(iAreaIndex, flExtentLow);
3277 | NavMeshAreaGetExtentHigh(iAreaIndex, flExtentHigh);
3278 |
3279 | float flTestPos[3];
3280 | flTestPos[0] = FloatClamp(flPos[0], flExtentLow[0], flExtentHigh[0]);
3281 | flTestPos[1] = FloatClamp(flPos[1], flExtentLow[1], flExtentHigh[1]);
3282 | flTestPos[2] = flPos[2];
3283 |
3284 | float dX = (flTestPos[0] - flExtentLow[0]) / (flExtentHigh[0] - flExtentLow[0]);
3285 | float dY = (flTestPos[1] - flExtentLow[1]) / (flExtentHigh[1] - flExtentLow[1]);
3286 |
3287 | float flCornerLightIntensityNW = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_CornerLightIntensityNW));
3288 | float flCornerLightIntensityNE = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_CornerLightIntensityNE));
3289 | float flCornerLightIntensitySW = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_CornerLightIntensitySW));
3290 | float flCornerLightIntensitySE = view_as(g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_CornerLightIntensitySE));
3291 |
3292 | float flNorthLight = flCornerLightIntensityNW * (1.0 - dX) + flCornerLightIntensityNE * dX;
3293 | float flSouthLight = flCornerLightIntensitySW * (1.0 - dX) + flCornerLightIntensitySE * dX;
3294 |
3295 | return (flNorthLight * (1.0 - dY) + flSouthLight * dY);
3296 | }
3297 |
3298 |
3299 | stock float FloatClamp(float a, float min, float max)
3300 | {
3301 | if (a < min) a = min;
3302 | if (a > max) a = max;
3303 | return a;
3304 | }
3305 |
3306 | stock bool NavMeshAreaIsEdge(int iAreaIndex, int iNavDirection)
3307 | {
3308 | if (!g_bNavMeshBuilt) return false;
3309 |
3310 | int iConnectionsStartIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_ConnectionsStartIndex);
3311 | if (iConnectionsStartIndex == -1) return true;
3312 |
3313 | int iConnectionsEndIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_ConnectionsEndIndex);
3314 |
3315 | for (int i = iConnectionsStartIndex; i <= iConnectionsEndIndex; i++)
3316 | {
3317 | int iToAreaIndex = g_hNavMeshAreaConnections.Get(i, NavMeshConnection_AreaIndex);
3318 | if (iToAreaIndex == -1)
3319 | continue;
3320 |
3321 | int direction = g_hNavMeshAreaConnections.Get(i, NavMeshConnection_Direction);
3322 | if (g_hNavMeshAreaConnections.Get(i, NavMeshConnection_Direction) != iNavDirection)
3323 | continue;
3324 |
3325 | if (NavMeshAreaIsConnected(iToAreaIndex, iAreaIndex, OppositeDirection(direction)))
3326 | return false;
3327 | }
3328 |
3329 | return true;
3330 | }
3331 |
3332 | stock float NavMeshLadderGetWidth(int iLadderIndex)
3333 | {
3334 | if (!g_bNavMeshBuilt) return 0.0;
3335 |
3336 | return view_as(g_hNavMeshLadders.Get(iLadderIndex, NavMeshLadder_Width));
3337 | }
3338 |
3339 | stock float NavMeshLadderGetLength(int iLadderIndex)
3340 | {
3341 | if (!g_bNavMeshBuilt) return 0.0;
3342 |
3343 | return view_as(g_hNavMeshLadders.Get(iLadderIndex, NavMeshLadder_Length));
3344 | }
3345 |
3346 | stock int NavMeshGetArea(const float flPos[3], float flBeneathLimit=120.0)
3347 | {
3348 | if (!g_bNavMeshBuilt) return -1;
3349 |
3350 | int x = NavMeshWorldToGridX(flPos[0]);
3351 | int y = NavMeshWorldToGridY(flPos[1]);
3352 |
3353 | ArrayStack hAreas = NavMeshGridGetAreas(x, y);
3354 |
3355 | int iUseAreaIndex = -1;
3356 | float flUseZ = -99999999.9;
3357 | float flTestPos[3];
3358 | flTestPos[0] = flPos[0];
3359 | flTestPos[1] = flPos[1];
3360 | flTestPos[2] = flPos[2] + 5.0;
3361 |
3362 | if (hAreas != null)
3363 | {
3364 | while (!hAreas.Empty)
3365 | {
3366 | int iAreaIndex = -1;
3367 | PopStackCell(hAreas, iAreaIndex);
3368 |
3369 | if (NavMeshAreaIsOverlappingPoint(iAreaIndex, flTestPos, 0.0))
3370 | {
3371 | float z = NavMeshAreaGetZ(iAreaIndex, flTestPos);
3372 |
3373 | if (z > flTestPos[2]) continue;
3374 |
3375 | if (z < flPos[2] - flBeneathLimit) continue;
3376 |
3377 | if (z > flUseZ)
3378 | {
3379 | iUseAreaIndex = iAreaIndex;
3380 | flUseZ = z;
3381 | }
3382 | }
3383 | }
3384 |
3385 | delete hAreas;
3386 | }
3387 |
3388 | return iUseAreaIndex;
3389 | }
3390 |
3391 | stock bool NavMeshGetGroundHeight(const float flPos[3], float &flHeight, float flNormal[3])
3392 | {
3393 | static float flMaxOffset = 100.0;
3394 |
3395 | float flTo[3]; float flFrom[3];
3396 | flTo[0] = flPos[0];
3397 | flTo[1] = flPos[1];
3398 | flTo[2] = flPos[2] - 10000.0;
3399 |
3400 | flFrom[0] = flPos[0];
3401 | flFrom[1] = flPos[1];
3402 | flFrom[2] = flPos[2] + HalfHumanHeight + 0.001;
3403 |
3404 | while (flTo[2] - flPos[2] < flMaxOffset)
3405 | {
3406 | Handle hTrace = TR_TraceRayFilterEx(flFrom, flTo, MASK_NPCSOLID_BRUSHONLY, RayType_EndPoint, TraceRayIgnoreCustom);
3407 | float flFraction = TR_GetFraction(hTrace);
3408 | float flPlaneNormal[3];
3409 | float flEndPos[3];
3410 | TR_GetEndPosition(flEndPos, hTrace);
3411 | TR_GetPlaneNormal(hTrace, flPlaneNormal);
3412 | delete hTrace;
3413 |
3414 | if (flFraction == 1.0 || ((flFrom[2] - flEndPos[2]) >= HalfHumanHeight))
3415 | {
3416 | flHeight = flEndPos[2];
3417 | flNormal[0] = flPlaneNormal[0];
3418 | flNormal[1] = flPlaneNormal[1];
3419 | flNormal[2] = flPlaneNormal[2];
3420 | return true;
3421 | }
3422 |
3423 | flTo[2] = (flFraction == 0.0) ? flFrom[2] : flEndPos[2];
3424 | flFrom[2] = flTo[2] + HalfHumanHeight + 0.001;
3425 | }
3426 |
3427 | flHeight = 0.0;
3428 | flNormal[0] = 0.0;
3429 | flNormal[1] = 0.0;
3430 | flNormal[2] = 1.0;
3431 |
3432 | return false;
3433 | }
3434 |
3435 | stock int NavMeshFindLadderByID(int iID)
3436 | {
3437 | char szID[16];
3438 | IntToString(iID, szID, 16);
3439 | int iIndex = -1;
3440 | if (g_hNavMeshLadderIdToIndexMap.GetValue(szID, iIndex))
3441 | return iIndex;
3442 | return -1;
3443 | }
3444 |
3445 | stock int NavMeshFindHidingSpotByID(int hidingSpotID)
3446 | {
3447 | char szHidingSpotID[16];
3448 | IntToString(hidingSpotID, szHidingSpotID, 16);
3449 | int iHidingSpotIndex = -1;
3450 | if (g_hNavMeshHidingSpotIdToIndexMap.GetValue(szHidingSpotID, iHidingSpotIndex))
3451 | return iHidingSpotIndex;
3452 | return -1;
3453 | }
3454 |
3455 | stock int NavSpotEncounterGetFrom(int spotEncounterIndex)
3456 | {
3457 | return g_hNavMeshAreaEncounterPaths.Get(spotEncounterIndex, NavMeshEncounterPath_FromAreaIndex);
3458 | }
3459 |
3460 | stock int NavSpotEncounterGetFromDirection(int spotEncounterIndex)
3461 | {
3462 | return g_hNavMeshAreaEncounterPaths.Get(spotEncounterIndex, NavMeshEncounterPath_FromDirection);
3463 | }
3464 |
3465 | stock int NavSpotEncounterGetTo(int spotEncounterIndex)
3466 | {
3467 | return g_hNavMeshAreaEncounterPaths.Get(spotEncounterIndex, NavMeshEncounterPath_ToAreaIndex);
3468 | }
3469 |
3470 | stock int NavSpotEncounterGetToDirection(int spotEncounterIndex)
3471 | {
3472 | return g_hNavMeshAreaEncounterPaths.Get(spotEncounterIndex, NavMeshEncounterPath_ToDirection);
3473 | }
3474 |
3475 | stock ArrayStack NavSpotEncounterGetSpots(int spotEncounterIndex)
3476 | {
3477 | int startIndex = g_hNavMeshAreaEncounterPaths.Get(spotEncounterIndex, NavMeshEncounterPath_SpotsStartIndex);
3478 | if (startIndex == -1) return null;
3479 |
3480 | ArrayStack buffer = new ArrayStack();
3481 | int endIndex = g_hNavMeshAreaEncounterPaths.Get(spotEncounterIndex, NavMeshEncounterPath_SpotsEndIndex);
3482 | for (int i = startIndex; i <= endIndex; i++)
3483 | {
3484 | buffer.Push(i);
3485 | }
3486 |
3487 | return buffer;
3488 | }
3489 |
3490 | stock int NavSpotOrderGetHidingSpot(int spotOrderIndex)
3491 | {
3492 | return g_hNavMeshAreaEncounterSpots.Get(spotOrderIndex, NavMeshEncounterSpot_HidingSpotIndex);
3493 | }
3494 |
3495 | stock int NavSpotOrderGetParametricDistance(int spotOrderIndex)
3496 | {
3497 | return g_hNavMeshAreaEncounterSpots.Get(spotOrderIndex, NavMeshEncounterSpot_ParametricDistance);
3498 | }
3499 |
3500 | public bool TraceRayIgnoreCustom(int entity,int mask, any data)
3501 | {
3502 | if (entity > 0 && entity <= MaxClients) return false;
3503 |
3504 | if (IsValidEdict(entity))
3505 | {
3506 | char sClass[64];
3507 | GetEntityNetClass(entity, sClass, sizeof(sClass));
3508 | if (StrEqual(sClass, "CFuncRespawnRoomVisualizer")) return false;
3509 | else if (StrEqual(sClass, "CBaseDoor")) return false;
3510 | else if (StrEqual(sClass, "CTFBaseBoss")) return false;
3511 | }
3512 | return true;
3513 | }
3514 | // ==================================
3515 | // API
3516 | // ==================================
3517 |
3518 | public int Native_NavMeshExists(Handle plugin, int numParams)
3519 | {
3520 | return g_bNavMeshBuilt;
3521 | }
3522 |
3523 | public int Native_NavMeshGetMagicNumber(Handle plugin, int numParams)
3524 | {
3525 | if (!g_bNavMeshBuilt)
3526 | {
3527 | LogError("Could not retrieve magic number because the nav mesh doesn't exist!");
3528 | return -1;
3529 | }
3530 |
3531 | return g_iNavMeshMagicNumber;
3532 | }
3533 |
3534 | public int Native_NavMeshGetVersion(Handle plugin, int numParams)
3535 | {
3536 | if (!g_bNavMeshBuilt)
3537 | {
3538 | LogError("Could not retrieve version because the nav mesh doesn't exist!");
3539 | return -1;
3540 | }
3541 |
3542 | return g_iNavMeshVersion;
3543 | }
3544 |
3545 | public int Native_NavMeshGetSubVersion(Handle plugin, int numParams)
3546 | {
3547 | if (!g_bNavMeshBuilt)
3548 | {
3549 | LogError("Could not retrieve subversion because the nav mesh doesn't exist!");
3550 | return -1;
3551 | }
3552 |
3553 | return g_iNavMeshSubVersion;
3554 | }
3555 |
3556 | public int Native_NavMeshGetSaveBSPSize(Handle plugin, int numParams)
3557 | {
3558 | if (!g_bNavMeshBuilt)
3559 | {
3560 | LogError("Could not retrieve save BSP size because the nav mesh doesn't exist!");
3561 | return -1;
3562 | }
3563 |
3564 | return g_iNavMeshSaveBSPSize;
3565 | }
3566 |
3567 | public int Native_NavMeshIsAnalyzed(Handle plugin, int numParams)
3568 | {
3569 | if (!g_bNavMeshBuilt)
3570 | {
3571 | LogError("Could not retrieve analysis state because the nav mesh doesn't exist!");
3572 | return 0;
3573 | }
3574 |
3575 | return g_bNavMeshAnalyzed;
3576 | }
3577 |
3578 | public int Native_NavMeshGetPlaces(Handle plugin, int numParams)
3579 | {
3580 | if (!g_bNavMeshBuilt)
3581 | {
3582 | LogError("Could not retrieve place list because the nav mesh doesn't exist!");
3583 | return 0;
3584 | }
3585 |
3586 | return view_as(g_hNavMeshPlaces);
3587 | }
3588 |
3589 | public int Native_NavMeshGetAreas(Handle plugin, int numParams)
3590 | {
3591 | if (!g_bNavMeshBuilt)
3592 | {
3593 | LogError("Could not retrieve area list because the nav mesh doesn't exist!");
3594 | return 0;
3595 | }
3596 |
3597 | return view_as(g_hNavMeshAreas);
3598 | }
3599 |
3600 | public int Native_NavMeshGetLadders(Handle plugin, int numParams)
3601 | {
3602 | if (!g_bNavMeshBuilt)
3603 | {
3604 | LogError("Could not retrieve ladder list because the nav mesh doesn't exist!");
3605 | return 0;
3606 | }
3607 |
3608 | return view_as(g_hNavMeshLadders);
3609 | }
3610 |
3611 | public int Native_NavMeshCollectSurroundingAreas(Handle plugin, int numParams)
3612 | {
3613 | ArrayStack hTarget = view_as(GetNativeCell(1));
3614 | ArrayStack hDummy = NavMeshCollectSurroundingAreas(view_as(GetNativeCell(2)), view_as(GetNativeCell(3)), view_as(GetNativeCell(4)), view_as(GetNativeCell(5)));
3615 |
3616 | if (hDummy != null)
3617 | {
3618 | while (!IsStackEmpty(hDummy))
3619 | {
3620 | int iAreaIndex = -1;
3621 | PopStackCell(hDummy, iAreaIndex);
3622 | hTarget.Push(iAreaIndex);
3623 | }
3624 |
3625 | delete hDummy;
3626 | }
3627 | }
3628 |
3629 | public int Native_NavMeshBuildPath(Handle plugin, int numParams)
3630 | {
3631 | float flGoalPos[3];
3632 | GetNativeArray(3, flGoalPos, 3);
3633 |
3634 | int iClosestIndex = view_as(GetNativeCellRef(6));
3635 |
3636 | bool bResult = NavMeshBuildPath(view_as(GetNativeCell(1)),
3637 | view_as(GetNativeCell(2)),
3638 | flGoalPos,
3639 | plugin,
3640 | view_as(GetNativeFunction(4)),
3641 | GetNativeCell(5),
3642 | iClosestIndex,
3643 | view_as(GetNativeCell(7)),
3644 | view_as(GetNativeCell(8)));
3645 |
3646 | SetNativeCellRef(6, iClosestIndex);
3647 | return bResult;
3648 | }
3649 |
3650 | public int Native_NavMeshGetArea(Handle plugin, int numParams)
3651 | {
3652 | float flPos[3];
3653 | GetNativeArray(1, flPos, 3);
3654 |
3655 | return NavMeshGetArea(flPos, view_as(GetNativeCell(2)));
3656 | }
3657 |
3658 | public int Native_NavMeshGetNearestArea(Handle plugin, int numParams)
3659 | {
3660 | float flPos[3];
3661 | GetNativeArray(1, flPos, 3);
3662 |
3663 | return NavMeshGetNearestArea(flPos, view_as(GetNativeCell(2)), view_as(GetNativeCell(3)), view_as(GetNativeCell(4)), view_as(GetNativeCell(5)), GetNativeCell(6));
3664 | }
3665 |
3666 | public int Native_NavMeshFindHidingSpotByID(Handle plugin, int numParams)
3667 | {
3668 | return NavMeshFindHidingSpotByID(GetNativeCell(1));
3669 | }
3670 |
3671 | public int Native_NavMeshGetRandomHidingSpot(Handle plugin, int numParams)
3672 | {
3673 | return GetRandomInt(0, g_hNavMeshAreaHidingSpots.Length - 1);
3674 | }
3675 |
3676 | public int Native_NavMeshWorldToGridX(Handle plugin, int numParams)
3677 | {
3678 | return NavMeshWorldToGridX(view_as(GetNativeCell(1)));
3679 | }
3680 |
3681 | public int Native_NavMeshWorldToGridY(Handle plugin, int numParams)
3682 | {
3683 | return NavMeshWorldToGridY(view_as(GetNativeCell(1)));
3684 | }
3685 |
3686 | public int Native_NavMeshGridGetAreas(Handle plugin, int numParams)
3687 | {
3688 | ArrayStack hTarget = view_as(GetNativeCell(1));
3689 | ArrayStack hDummy = NavMeshGridGetAreas(GetNativeCell(2), GetNativeCell(3));
3690 |
3691 | if (hDummy != null)
3692 | {
3693 | while (!hDummy.Empty)
3694 | {
3695 | int iAreaIndex = -1;
3696 | PopStackCell(hDummy, iAreaIndex);
3697 | hTarget.Push(iAreaIndex);
3698 | }
3699 |
3700 | delete hDummy;
3701 | }
3702 | }
3703 |
3704 | public int Native_NavMeshGetGridSizeX(Handle plugin, int numParams)
3705 | {
3706 | return g_iNavMeshGridSizeX;
3707 | }
3708 |
3709 | public int Native_NavMeshGetGridSizeY(Handle plugin, int numParams)
3710 | {
3711 | return g_iNavMeshGridSizeY;
3712 | }
3713 |
3714 | public int Native_NavMeshAreaGetClosestPointOnArea(Handle plugin, int numParams)
3715 | {
3716 | float flPos[3]; float flClose[3];
3717 | GetNativeArray(2, flPos, 3);
3718 | NavMeshAreaGetClosestPointOnArea(GetNativeCell(1), flPos, flClose);
3719 | SetNativeArray(3, flClose, 3);
3720 | }
3721 |
3722 | public int Native_NavMeshGetGroundHeight(Handle plugin, int numParams)
3723 | {
3724 | float flPos[3]; float flNormal[3];
3725 | GetNativeArray(1, flPos, 3);
3726 | float flHeight = view_as(GetNativeCellRef(2));
3727 | bool bResult = NavMeshGetGroundHeight(flPos, flHeight, flNormal);
3728 | SetNativeCellRef(2, flHeight);
3729 | SetNativeArray(3, flNormal, 3);
3730 | return bResult;
3731 | }
3732 |
3733 | public int Native_NavMeshFindAreaByID(Handle plugin, int numParams)
3734 | {
3735 | return NavMeshFindAreaByID(GetNativeCell(1));
3736 | }
3737 |
3738 | public int Native_NavMeshAreaGetMasterMarker(Handle plugin, int numParams)
3739 | {
3740 | return g_iNavMeshAreaMasterMarker;
3741 | }
3742 |
3743 | public int Native_NavMeshAreaChangeMasterMarker(Handle plugin, int numParams)
3744 | {
3745 | g_iNavMeshAreaMasterMarker++;
3746 | }
3747 |
3748 | public int Native_NavMeshAreaGetID(Handle plugin, int numParams)
3749 | {
3750 | return NavMeshAreaGetID(GetNativeCell(1));
3751 | }
3752 |
3753 | public int Native_NavMeshAreaGetFlags(Handle plugin, int numParams)
3754 | {
3755 | return NavMeshAreaGetFlags(GetNativeCell(1));
3756 | }
3757 |
3758 | public int Native_NavMeshAreaGetPlace(Handle plugin, int numParams)
3759 | {
3760 | int maxlen = GetNativeCell(3);
3761 | char[] buffer = new char[maxlen];
3762 | GetNativeString(2, buffer, maxlen);
3763 | NavMeshAreaGetPlace(GetNativeCell(1), buffer, maxlen);
3764 | SetNativeString(2, buffer, maxlen);
3765 | }
3766 |
3767 | public int Native_NavMeshAreaGetCenter(Handle plugin, int numParams)
3768 | {
3769 | float flResult[3];
3770 | if (NavMeshAreaGetCenter(GetNativeCell(1), flResult))
3771 | {
3772 | SetNativeArray(2, flResult, 3);
3773 | return true;
3774 | }
3775 |
3776 | return false;
3777 | }
3778 |
3779 | public int Native_NavMeshAreaGetAdjacentList(Handle plugin, int numParams)
3780 | {
3781 | ArrayStack hTarget = view_as(GetNativeCell(1));
3782 | ArrayStack hDummy = NavMeshAreaGetAdjacentList(GetNativeCell(2), GetNativeCell(3));
3783 |
3784 | if (hDummy != null)
3785 | {
3786 | while (!hDummy.Empty)
3787 | {
3788 | new iAreaIndex = -1;
3789 | PopStackCell(hDummy, iAreaIndex);
3790 | hTarget.Push(iAreaIndex);
3791 | }
3792 |
3793 | delete hDummy;
3794 | }
3795 | }
3796 |
3797 | public int Native_NavMeshAreaGetAdjacentAreas(Handle plugin, int numParams)
3798 | {
3799 | int iAreaIndex = GetNativeCell(1);
3800 | int iNavDirection = GetNativeCell(2);
3801 | ArrayList hTarget = view_as(GetNativeCell(3));
3802 |
3803 | int iConnectionsStartIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_ConnectionsStartIndex);
3804 | if (iConnectionsStartIndex == -1) return;
3805 |
3806 | int iConnectionsEndIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_ConnectionsEndIndex);
3807 |
3808 | for (int i = iConnectionsStartIndex; i <= iConnectionsEndIndex; i++)
3809 | {
3810 | int iToAreaIndex = g_hNavMeshAreaConnections.Get(i, NavMeshConnection_AreaIndex);
3811 | if (iToAreaIndex == -1)
3812 | continue;
3813 |
3814 | if (iNavDirection != NAV_DIR_COUNT && g_hNavMeshAreaConnections.Get(i, NavMeshConnection_Direction) != iNavDirection)
3815 | continue;
3816 |
3817 | hTarget.Push(iToAreaIndex);
3818 | }
3819 | }
3820 |
3821 | public int Native_NavMeshAreaGetIncomingConnections(Handle plugin, int numParams)
3822 | {
3823 | int iAreaIndex = GetNativeCell(1);
3824 | int iNavDirection = GetNativeCell(2);
3825 | ArrayList hTarget = view_as(GetNativeCell(3));
3826 |
3827 | int iConnectionsStartIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_IncomingConnectionsStartIndex);
3828 | if (iConnectionsStartIndex == -1) return;
3829 |
3830 | int iConnectionsEndIndex = g_hNavMeshAreas.Get(iAreaIndex, NavMeshArea_IncomingConnectionsEndIndex);
3831 |
3832 | for (int i = iConnectionsStartIndex; i <= iConnectionsEndIndex; i++)
3833 | {
3834 | int iFromAreaIndex = g_hNavMeshAreaIncomingConnections.Get(i, NavMeshConnection_FromAreaIndex);
3835 | if (iFromAreaIndex == -1)
3836 | continue;
3837 |
3838 | if (iNavDirection != NAV_DIR_COUNT && g_hNavMeshAreaIncomingConnections.Get(i, NavMeshConnection_Direction) != iNavDirection)
3839 | continue;
3840 |
3841 | hTarget.Push(iFromAreaIndex);
3842 | }
3843 | }
3844 |
3845 | public int Native_NavMeshAreaGetLadderList(Handle plugin, int numParams)
3846 | {
3847 | ArrayStack hTarget = view_as(GetNativeCell(1));
3848 | ArrayStack hDummy = NavMeshAreaGetLadderList(GetNativeCell(2), GetNativeCell(3));
3849 |
3850 | if (hDummy != null)
3851 | {
3852 | while (!IsStackEmpty(hDummy))
3853 | {
3854 | int iAreaIndex = -1;
3855 | PopStackCell(hDummy, iAreaIndex);
3856 | PushStackCell(hTarget, iAreaIndex);
3857 | }
3858 |
3859 | delete hDummy;
3860 | }
3861 | }
3862 |
3863 | public int Native_NavMeshAreaGetHidingSpots(Handle plugin, int numParams)
3864 | {
3865 | ArrayStack hTarget = view_as(GetNativeCell(1));
3866 | ArrayStack hDummy = NavMeshAreaGetHidingSpots(GetNativeCell(2));
3867 |
3868 | if (hDummy != null)
3869 | {
3870 | while (!IsStackEmpty(hDummy))
3871 | {
3872 | int iAreaIndex = -1;
3873 | PopStackCell(hDummy, iAreaIndex);
3874 | PushStackCell(hTarget, iAreaIndex);
3875 | }
3876 |
3877 | delete hDummy;
3878 | }
3879 | }
3880 |
3881 | public int Native_NavMeshAreaGetTotalCost(Handle plugin, int numParams)
3882 | {
3883 | return NavMeshAreaGetTotalCost(GetNativeCell(1));
3884 | }
3885 |
3886 | public int Native_NavMeshAreaGetCostSoFar(Handle plugin, int numParams)
3887 | {
3888 | return NavMeshAreaGetCostSoFar(GetNativeCell(1));
3889 | }
3890 |
3891 | public int Native_NavMeshAreaGetParent(Handle plugin, int numParams)
3892 | {
3893 | return NavMeshAreaGetParent(GetNativeCell(1));
3894 | }
3895 |
3896 | public int Native_NavMeshAreaGetParentHow(Handle plugin, int numParams)
3897 | {
3898 | return NavMeshAreaGetParentHow(GetNativeCell(1));
3899 | }
3900 |
3901 | public int Native_NavMeshAreaSetParent(Handle plugin, int numParams)
3902 | {
3903 | NavMeshAreaSetParent(GetNativeCell(1), GetNativeCell(2));
3904 | }
3905 |
3906 | public int Native_NavMeshAreaSetParentHow(Handle plugin, int numParams)
3907 | {
3908 | NavMeshAreaSetParentHow(GetNativeCell(1), GetNativeCell(2));
3909 | }
3910 |
3911 | public int Native_NavMeshAreaGetExtentLow(Handle plugin, int numParams)
3912 | {
3913 | float flExtent[3];
3914 | if (NavMeshAreaGetExtentLow(GetNativeCell(1), flExtent))
3915 | {
3916 | SetNativeArray(2, flExtent, 3);
3917 | return true;
3918 | }
3919 |
3920 | return false;
3921 | }
3922 |
3923 | public int Native_NavMeshAreaGetExtentHigh(Handle plugin, int numParams)
3924 | {
3925 | float flExtent[3];
3926 | if (NavMeshAreaGetExtentHigh(GetNativeCell(1), flExtent))
3927 | {
3928 | SetNativeArray(2, flExtent, 3);
3929 | return true;
3930 | }
3931 |
3932 | return false;
3933 | }
3934 |
3935 | public int Native_NavMeshAreaIsOverlappingPoint(Handle plugin, int numParams)
3936 | {
3937 | float flPos[3];
3938 | GetNativeArray(2, flPos, 3);
3939 |
3940 | return NavMeshAreaIsOverlappingPoint(GetNativeCell(1), flPos, view_as(GetNativeCell(3)));
3941 | }
3942 |
3943 | public int Native_NavMeshAreaIsOverlappingArea(Handle plugin, int numParams)
3944 | {
3945 | return NavMeshAreaIsOverlappingArea(GetNativeCell(1), GetNativeCell(2));
3946 | }
3947 |
3948 | public int Native_NavMeshAreaGetNECornerZ(Handle plugin, int numParams)
3949 | {
3950 | return view_as(NavMeshAreaGetNECornerZ(GetNativeCell(1)));
3951 | }
3952 |
3953 | public int Native_NavMeshAreaGetSWCornerZ(Handle plugin, int numParams)
3954 | {
3955 | return view_as(NavMeshAreaGetSWCornerZ(GetNativeCell(1)));
3956 | }
3957 |
3958 | public int Native_NavMeshAreaGetCorner(Handle plugin, int numParams)
3959 | {
3960 | float buffer[3];
3961 | GetNativeArray(3, buffer, 3);
3962 | NavMeshAreaGetCorner(GetNativeCell(1), view_as(GetNativeCell(2)), buffer);
3963 | SetNativeArray(3, buffer, 3);
3964 | }
3965 |
3966 | public int Native_NavMeshAreaGetZ(Handle plugin, int numParams)
3967 | {
3968 | float flPos[3];
3969 | GetNativeArray(2, flPos, 3);
3970 |
3971 | return view_as(NavMeshAreaGetZ(GetNativeCell(1), flPos));
3972 | }
3973 |
3974 | public int Native_NavMeshAreaGetZFromXAndY(Handle plugin, int numParams)
3975 | {
3976 | return view_as(NavMeshAreaGetZFromXAndY(GetNativeCell(1), view_as(GetNativeCell(2)), view_as(GetNativeCell(3))));
3977 | }
3978 |
3979 | public int Native_NavMeshAreaIsEdge(Handle plugin, int numParams)
3980 | {
3981 | return NavMeshAreaIsEdge(GetNativeCell(1), GetNativeCell(2));
3982 | }
3983 |
3984 | public int Native_NavMeshAreaContains(Handle plugin, int numParams)
3985 | {
3986 | float flPos[3];
3987 | GetNativeArray(2, flPos, 3);
3988 |
3989 | return NavMeshAreaContains(GetNativeCell(1), flPos);
3990 | }
3991 |
3992 | public int Native_NavMeshAreaGetRandomPoint(Handle plugin, int numParams)
3993 | {
3994 | float buffer[3];
3995 | GetNativeArray(2, buffer, 3);
3996 | NavMeshAreaGetRandomPoint(GetNativeCell(1), buffer);
3997 | SetNativeArray(2, buffer, 3);
3998 | }
3999 |
4000 | public int Native_NavMeshAreaComputePortal(Handle plugin, int numParams)
4001 | {
4002 | float flCenter[3];
4003 | float flHalfWidth = GetNativeCellRef(5);
4004 |
4005 | bool bResult = NavMeshAreaComputePortal(GetNativeCell(1),
4006 | GetNativeCell(2),
4007 | GetNativeCell(3),
4008 | flCenter,
4009 | flHalfWidth);
4010 |
4011 | SetNativeArray(4, flCenter, 3);
4012 | SetNativeCellRef(5, flHalfWidth);
4013 | return bResult;
4014 | }
4015 |
4016 | public int Native_NavMeshAreaIsConnected(Handle plugin, int numParams)
4017 | {
4018 | return NavMeshAreaIsConnected(GetNativeCell(1), GetNativeCell(2), GetNativeCell(3));
4019 | }
4020 |
4021 | public int Native_NavMeshAreaComputeClosestPointInPortal(Handle plugin, int numParams)
4022 | {
4023 | float flFromPos[3];
4024 | GetNativeArray(4, flFromPos, 3);
4025 |
4026 | float flClosestPos[3];
4027 |
4028 | bool bResult = NavMeshAreaComputeClosestPointInPortal(GetNativeCell(1),
4029 | GetNativeCell(2),
4030 | GetNativeCell(3),
4031 | flFromPos,
4032 | flClosestPos);
4033 |
4034 | SetNativeArray(5, flClosestPos, 3);
4035 | return bResult;
4036 | }
4037 |
4038 | public int Native_NavMeshAreaComputeDirection(Handle plugin, int numParams)
4039 | {
4040 | float flPos[3];
4041 | GetNativeArray(2, flPos, 3);
4042 |
4043 | return NavMeshAreaComputeDirection(GetNativeCell(1), flPos);
4044 | }
4045 |
4046 | public int Native_NavMeshAreaGetLightIntensity(Handle plugin, int numParams)
4047 | {
4048 | float flPos[3];
4049 | GetNativeArray(2, flPos, 3);
4050 |
4051 | return view_as(NavMeshAreaGetLightIntensity(GetNativeCell(1), flPos));
4052 | }
4053 |
4054 | public int Native_NavHidingSpotGetID(Handle plugin, int numParams)
4055 | {
4056 | return g_hNavMeshAreaHidingSpots.Get(GetNativeCell(1), NavMeshHidingSpot_ID);
4057 | }
4058 |
4059 | public int Native_NavHidingSpotGetFlags(Handle plugin, int numParams)
4060 | {
4061 | return g_hNavMeshAreaHidingSpots.Get(GetNativeCell(1), NavMeshHidingSpot_Flags);
4062 | }
4063 |
4064 | public int Native_NavHidingSpotGetPosition(Handle plugin, int numParams)
4065 | {
4066 | float buffer[3];
4067 | GetNativeArray(2, buffer, 3);
4068 |
4069 | int hidingSpotIndex = GetNativeCell(1);
4070 |
4071 | buffer[0] = view_as(g_hNavMeshAreaHidingSpots.Get(hidingSpotIndex, NavMeshHidingSpot_X));
4072 | buffer[1] = view_as(g_hNavMeshAreaHidingSpots.Get(hidingSpotIndex, NavMeshHidingSpot_Y));
4073 | buffer[2] = view_as(g_hNavMeshAreaHidingSpots.Get(hidingSpotIndex, NavMeshHidingSpot_Z));
4074 |
4075 | SetNativeArray(2, buffer, 3);
4076 | }
4077 |
4078 | public int Native_NavHidingSpotGetArea(Handle plugin, int numParams)
4079 | {
4080 | return g_hNavMeshAreaHidingSpots.Get(GetNativeCell(1), NavMeshHidingSpot_AreaIndex);
4081 | }
4082 |
4083 | public int Native_NavMeshLadderGetWidth(Handle plugin, int numParams)
4084 | {
4085 | return view_as(NavMeshLadderGetWidth(GetNativeCell(1)));
4086 | }
4087 |
4088 | public int Native_NavMeshLadderGetLength(Handle plugin, int numParams)
4089 | {
4090 | return view_as(NavMeshLadderGetLength(GetNativeCell(1)));
4091 | }
4092 |
4093 | public int Native_NavMeshLadderGetTopForwardArea(Handle plugin, int numParams)
4094 | {
4095 | return g_hNavMeshLadders.Get(GetNativeCell(1), NavMeshLadder_TopForwardAreaIndex);
4096 | }
4097 |
4098 | public int Native_NavMeshLadderGetTopLeftArea(Handle plugin, int numParams)
4099 | {
4100 | return g_hNavMeshLadders.Get(GetNativeCell(1), NavMeshLadder_TopLeftAreaIndex);
4101 | }
4102 |
4103 | public int Native_NavMeshLadderGetTopRightArea(Handle plugin, int numParams)
4104 | {
4105 | return g_hNavMeshLadders.Get(GetNativeCell(1), NavMeshLadder_TopRightAreaIndex);
4106 | }
4107 |
4108 | public int Native_NavMeshLadderGetTopBehindArea(Handle plugin, int numParams)
4109 | {
4110 | return g_hNavMeshLadders.Get(GetNativeCell(1), NavMeshLadder_TopBehindAreaIndex);
4111 | }
4112 |
4113 | public int Native_NavMeshLadderGetBottomArea(Handle plugin, int numParams)
4114 | {
4115 | return g_hNavMeshLadders.Get(GetNativeCell(1), NavMeshLadder_BottomAreaIndex);
4116 | }
4117 |
4118 | public int Native_NavMeshLadderGetTop(Handle plugin, int numParams)
4119 | {
4120 | float buffer[3];
4121 | GetNativeArray(2, buffer, 3);
4122 |
4123 | buffer[0] = view_as(g_hNavMeshLadders.Get(GetNativeCell(1), NavMeshLadder_TopX));
4124 | buffer[1] = view_as(g_hNavMeshLadders.Get(GetNativeCell(1), NavMeshLadder_TopY));
4125 | buffer[2] = view_as(g_hNavMeshLadders.Get(GetNativeCell(1), NavMeshLadder_TopZ));
4126 |
4127 | SetNativeArray(2, buffer, 3);
4128 | }
4129 |
4130 | public int Native_NavMeshLadderGetBottom(Handle plugin, int numParams)
4131 | {
4132 | float buffer[3];
4133 | GetNativeArray(2, buffer, 3);
4134 |
4135 | buffer[0] = view_as(g_hNavMeshLadders.Get(GetNativeCell(1), NavMeshLadder_BottomX));
4136 | buffer[1] = view_as(g_hNavMeshLadders.Get(GetNativeCell(1), NavMeshLadder_BottomY));
4137 | buffer[2] = view_as(g_hNavMeshLadders.Get(GetNativeCell(1), NavMeshLadder_BottomZ));
4138 |
4139 | SetNativeArray(2, buffer, 3);
4140 | }
4141 |
4142 | public int Native_NavSpotEncounterGetFrom(Handle plugin, int numParams)
4143 | {
4144 | return NavSpotEncounterGetFrom(GetNativeCell(1));
4145 | }
4146 |
4147 | public int Native_NavSpotEncounterGetFromDirection(Handle plugin, int numParams)
4148 | {
4149 | return NavSpotEncounterGetFromDirection(GetNativeCell(1));
4150 | }
4151 |
4152 | public int Native_NavSpotEncounterGetTo(Handle plugin, int numParams)
4153 | {
4154 | return NavSpotEncounterGetTo(GetNativeCell(1));
4155 | }
4156 |
4157 | public int Native_NavSpotEncounterGetToDirection(Handle plugin, int numParams)
4158 | {
4159 | return NavSpotEncounterGetToDirection(GetNativeCell(1));
4160 | }
4161 |
4162 | public int Native_NavSpotEncounterGetSpots(Handle plugin, int numParams)
4163 | {
4164 | ArrayStack buffer = view_as(GetNativeCell(2));
4165 | ArrayStack dummy = NavSpotEncounterGetSpots(GetNativeCell(1));
4166 | if (dummy != null)
4167 | {
4168 | while (!dummy.Empty)
4169 | {
4170 | int val;
4171 | PopStackCell(dummy, val);
4172 | buffer.Push(val);
4173 | }
4174 | delete dummy;
4175 | }
4176 | }
4177 |
4178 | public int Native_NavSpotOrderGetHidingSpot(Handle plugin, int numParams)
4179 | {
4180 | return NavSpotOrderGetHidingSpot(GetNativeCell(1));
4181 | }
4182 |
4183 | public int Native_NavSpotOrderGetParametricDistance(Handle plugin, int numParams)
4184 | {
4185 | return NavSpotOrderGetParametricDistance(GetNativeCell(1));
4186 | }
4187 |
4188 | public int Native_TFNavAreaGetAttributeFlags(Handle plugin, int numParams)
4189 | {
4190 | if (!g_bNavMeshBuilt) return 0;
4191 | return g_hNavMeshAreas.Get(GetNativeCell(1), TFNavArea_AttributeFlags);
4192 | }
4193 |
4194 | public int Native_CSNavAreaGetApproachInfoList(Handle plugin, int numParams)
4195 | {
4196 | if (!g_bNavMeshBuilt) return;
4197 |
4198 | int areaIndex = GetNativeCell(1);
4199 | ArrayList buffer = view_as(GetNativeCell(2));
4200 |
4201 | int startIndex = g_hNavMeshAreas.Get(areaIndex, CSNavArea_ApproachInfoStartIndex);
4202 | if ( startIndex == -1 )
4203 | return;
4204 |
4205 | int endIndex = g_hNavMeshAreas.Get(areaIndex, CSNavArea_ApproachInfoEndIndex);
4206 | for (int i = startIndex; i <= endIndex; i++)
4207 | {
4208 | CCSNavArea_ApproachInfo approachInfo;
4209 | g_hCSNavAreaApproachInfo.GetArray( i, approachInfo, sizeof(approachInfo) );
4210 | buffer.PushArray(approachInfo, sizeof(approachInfo));
4211 | }
4212 | }
4213 |
4214 | public int Native_TerrorNavMeshGetZombiePopulation(Handle plugin, int numParams)
4215 | {
4216 | SetNativeString(2, g_TerrorNavMeshZombiePopulation, GetNativeCell(3));
4217 | }
4218 |
4219 | public int Native_TerrorNavMeshGetNavMaxViewDistance(Handle plugin, int numParams)
4220 | {
4221 | return g_TerrorNavMeshNavMaxViewDistance;
4222 | }
4223 |
4224 | public int Native_TerrorNavAreaGetSpawnAttributes(Handle plugin, int numParams)
4225 | {
4226 | if (!g_bNavMeshBuilt) return 0;
4227 | return g_hNavMeshAreas.Get(GetNativeCell(1), TerrorNavArea_SpawnAttributes);
4228 | }
--------------------------------------------------------------------------------