File size: 22,096 Bytes
b6a38d7 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 732 733 734 735 736 737 738 739 740 741 742 743 744 745 746 747 748 749 750 751 752 753 754 755 756 757 758 759 760 761 762 763 764 765 766 767 768 769 770 771 772 773 774 775 776 777 778 779 780 781 782 783 784 785 786 787 788 789 790 791 792 793 794 795 796 797 798 799 800 801 802 803 804 805 806 807 808 809 810 811 812 813 814 815 816 817 818 819 820 821 822 823 824 825 826 827 828 829 830 831 832 833 834 835 836 837 838 839 840 841 842 843 844 845 846 847 848 849 850 851 852 853 854 855 856 857 858 859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875 876 877 878 879 880 881 882 883 884 885 886 887 888 889 890 891 892 893 894 895 896 897 898 899 900 901 902 903 904 905 906 907 908 909 910 911 912 913 914 915 916 917 918 919 920 921 |
# terrain Overview
The terrain is represented by two raster grids - type grid and height grid.
The materials used to texture the terrain are in the TerrainTextures table. Each material consists of several PBR textures similar to other materials in the game - base color, normal map, roughness / metallic, etc.
The layout of these materials on the terrain is controlled by the terrain type grid, which describes what material to use for each grid tile. Each tile can reference only one material. However, materials are blended along type pixel boundaries with a fairly wide blending border, to avoid obvious pixelation.The values in the pixels are 8 - bit indices in the TerrainTextures table.
The geometry of the terrain is described by a dense heightfield, with the same density as the type grid. Each grid value indicates the height in this point, as a 16 - bit number. That number is then scaled to obtain the final height in game units (i.e.centimeters). The height grid samples are located at the type grid tile corners, i.e. the height grid is 1 pixel bigger than the type grid.
# terrain reference
## terrain.AreaPassable
Checks if there is enough connected passable tiles at a given location (forming a connected area).
bool **terrain.AreaPassable**(point pos, int area, [int pfclass = 0, bool bUseTunnels = false])
bool **terrain.AreaPassable**(int x, int y, int z, int area, [int pfclass = 0, bool bUseTunnels = false])
bool **terrain.AreaPassable**(object obj, int area, [bool bUseTunnels = false])
point pos
: position to check.
int x, y, z
: position to check.
object obj
: position and pfclass to check.
int area
: number of connected passable tiles.
int pfclass
: pfclass to use (optional, default 0).
bool bAvoidTunnels
: ignore connectivity through tunnels (optional, default false).
## terrain.ChangeHeight
Modifies all values in the height grid by given value
void **terrain.ChangeHeight**(diff)
int diff
: value to add.
## terrain.CirclePassable
Checks if a circle area with given radius is passable.
Usefull to verify if there is enough space to fit safely something at a given position.
bool **terrain.CirclePassable**(point pos, int radius, [int pfclass = 0])
bool **terrain.CirclePassable**(int x, int y, int z, int radius, [int pfclass = 0])
bool **terrain.CirclePassable**(object obj, int radius)
point pos
: position to check.
int x, y, z
: position to check.
object obj
: position and pfclass to check.
int radius
: radius to check.
int pfclass
: pfclass to use (optional, default 0).
## terrain.ClampBox
Clamp a box with the map bounding box.
box **terrain.ClampBox**(box, border)
box box
: box to clamp
int border
: optional, if specified the function will shrink the map boundaries by this amount for the purpose of the clamp.
## terrain.ClampPoint
Clamp a position with the map bounding box.
point **terrain.ClampPoint**(pos, border)
point pos
: position to clamp
int border
: optional, if specified the function will shrink the map boundaries by this amount for the purpose of the clamp.
## terrain.ClampVector
Clamp a vector with the map bounding box.
point, point **terrain.ClampVector**(ptFrom, ptTo)
point ptFrom
: vector begin point to clamp
point ptTo
: vector end point to clamp
## terrain.ClearWater
Clears all water from the map.
void **terrain.ClearWater**()
## terrain.CountPassable
Counts the passable tiles in a circle area with given radius.
Usefull to estimate how passable is a given area compared to another.
int **terrain.CountPassable**(point pos, int radius, [int pfclass = 0])
int **terrain.CountPassable**(int x, int y, int z, int radius, [int pfclass = 0])
int **terrain.CountPassable**(object obj, int radius)
point pos
: position to check.
int x, y, z
: position to check.
object obj
: position and pfclass to check.
int radius
: radius to check.
int pfclass
: pfclass to use (optional, default 0).
## terrain.FindAreaPassable
Search a position with enough connected passable tiles (forming a connected area) starting from a given position.
Different passability levels could be considered when tunnels are allowed only.
bool **terrain.FindAreaPassable**(point pos, int area, int radius, [int pfclass = 0, bool bUseTunnels = false, function filter = false, ...])
bool **terrain.FindAreaPassable**(int x, int y, int z, int area, int radius, [int pfclass = 0, bool bUseTunnels = false, function filter = false, ...])
bool **terrain.FindAreaPassable**(object unit, int area, int radius, [bool bUseTunnels = false, bool bCanDestlock = false, function filter = false, ...])
point pos
: position to check.
int x, y, z
: position to check.
object unit
: unit at position and pfclass to check.
int area
: number of connected passable tiles.
int radius
: search radius around the position to check.
int pfclass
: pfclass to use (optional, default 0).
bool bAvoidTunnels
: restrict search in a single level and ignore connectivity through tunnels (optional, default false).
bool bCanDestlock
: if an unit is provided, check for destlockable positions only.
function filter
: if provided, each position (x, y, z) will be tested with. All remaing parameters are forwarded.
## terrain.FindPassableTile
Search for the nearest passable tile around a center position, according to certain criteria, specified by flags.
The initial position is tested without tile alignment, to handle the trivial case where the center position is passable.
The function is faster than *terrain.FindPassable*.
point **terrain.FindPassableTile**(obj, tfp_flags, ...)
point **terrain.FindPassableTile**(pos, tfp_flags, ...)
point **terrain.FindPassableTile**(x, y, z, tfp_flags, ...)
CObject obj
: search center. The pass class and pass flags are deduced from it, in case there is a path component.
point pos
: search center.
int x, y, z
: search center.
int tfp_flags
: Flag based number defining different modifications to the default behavior. If some of the behaviors require aditional params, they should follow in the correct order. The available flags are:
-- const.tfpLimitDist
Limits the search between min/max distance.
Additional param: max_dist, min_dist (int)
-- const.tfpPassClass
Specifies a pass class, overriding the pass class in *obj* param, if any. Exepcts a pf class index or an object.
Additional param: pfclass (int/object)
-- const.tfpCanDestlock
Searches for destlockable positions only. Exepcts a deslocking radius, an object or a boolean too indicate to use the one found in *obj*.
Additional params: destlock_radius (int/object/bool)
-- const.tfpVoxelCenters
Restricts the search to voxel centers only.
-- const.tfpReturnXYZ
Forces the result to be the point coordinates instead.
-- const.tfpCollectList
Forces the result to be a list of all pass positions in a list, instead of the first one. Exepcts max results count, or a boolean.
Requires *const.tfpLimitDist*. Incompatible with *const.tfpReturnXYZ*.
Additional params: max_results (int,bool)
-- const.tfpLuaFilter
A Lua filter expecting as parameters coordinates: x, y, z
Any additional parameters passed after the *filter* are passsed back to it when called, after the coordinates.
Additional params: filter (function)
_returns_ point pass_pos
: a passable position if found (or its coordinates if *const.tfpReturnXYZ* is specified, or a list with all positions matching the criteria if *const.tfpReturnList* is specified).
Example:
~~~~ Lua
local nsp_flags = const.tfpLimitDist | const.tfpLuaFilter
local max_dist, min_dist = 16*guim, 2*guim
local danger_pos, danger_dist = self:FindDangerAround()
local pos = terrain.FindPassableTile(self, nsp_flags, max_dist, min_dist, function(x, y, z, danger_pos, danger_dist)
return not danger_pos or not IsCloser(danger_pos, x, y, z, danger_dist)
end, danger_pos, danger_dist)
~~~~
## terrain.FindPassableZ
Returns the closest passable Z in the specified range.
void **terrain.FindPassableZ**(pt, pfclass, max_below, max_above)
void **terrain.FindPassableZ**(x, y, z, pfclass, max_below, max_above)
void **terrain.FindPassableZ**(obj, max_below, max_above)
point pt
: map position.
int x, y, z
: map position as coordinates.
Object obj
: game object to use as position and pf class.
int pfclass
: pf class to check (0 by default)
int max_below, max_above
: search range (unlimited by default).
_returns_ : int pass_z
: the pass Z if found or nil.
## terrain.FindReachable
Search for a reachable passable position around a given start position (or unit), according to a set of rules.
Supports several rules for filtering, weighting and randomizing the results.
The search is 3D but wont change passability levels unless via a tunnel. Thus providing a starting point on impassable would search around within the provided limits, ignoring passable positions on adjacent layers.
The only case where the starting layer is changed, is for positions with valid Z exactly on the terrain, resulting from providing visual position of units.
point **terrain.FindReachable**(obj, rule, ..., [rule2, ...], ..., [ruleN, ...])
point **terrain.FindReachable**(start_pos, pf_class, rule, ..., [rule2, ...], ..., [ruleN, ...])
CObject obj
: object to be used as starting position, applying its pf class
point start_pos
: starting search position
int pf_class
: pathfinding class
int rule
: operation rule. Each rule have different input parameters expected after its declaration:
-- const.tfrResCount, count
*count* results are expected (1 by default). Unlimited results can be specified by providing -1.
-- const.tfrResCollect, results, start_idx
Pushes the results into the given table *results* instead into the stack. If no table is providied (false), then such table is created and pushed into the stack. Always pushes the collected count into the stack as well. If *start_idx* is false then the results are pushed at the end of the table.
-- const.tfrRandom, seed
The result(s) are randomized based on the given *seed*
-- const.tfrDir, angle
Sets the orientation to *angle* (used by some of the operation rules)
-- const.tfrLimitDist, max_dist, min_dist
The result(s) are located between *min_dist* and *max_dist* traversed distance from the start.
-- const.tfrLimitDir, max_angle, min_angle
The result(s) are located between *min_angle* and *max_angle* absolute deviation form the given orientation (the object*s angle by default).
-- const.tfrBoxFilter, filter_box
The result(s) are accepted only if inside the provided box (2D).
-- const.tfrCenterRadius, max_radius, min_radius, center_pos
The result(s) are located between *min_radius* and *max_radius* linear distance around the *center_pos* (the object's pos by default).
This rule can co-exists with *const.tfrLimitDist* to make it possible to apply constraints by 2 different positions (e.g. *Roam* behavior).
The *start_pos* can be outside the allowed *max_radius* around *center_pos*, but in that case the results are not guaranteed to be the best possible.
-- const.tfrWeightDir, max_angle_weight, min_angle_weight, angle_weight_distrib
Apply weights to the results according to how close/far they are to a given orientation (the object's angle by default). The weight distribution law can be linear (1), quadratic (2), etc.
-- const.tfrWeightDist, max_dist_weight, min_dist_weight, dist_weight_distrib
Apply weights to the results according to how close/far they are to the start position (according to the traversed distance). The weight distribution law can be linear (1), quadratic (2), etc.
-- const.tfrWeightRadius, max_radius_weight, min_radius_weight, radius_weight_distrib
Apply weights to the results according to how close/far they are to the center position (according to the linear 2D distance). The weight distribution law can be linear (1), quadratic (2), etc.
-- const.tfrPassCost, max_cost, min_cost
Filter the result(s) by pathfinding cost.
-- const.tfrPassLOS
Restrict the results to have passable LOS to the start position. Tunnels are therefore ignored in this rule.
-- const.tfrPassClass, pfclass
Specify a pf class.
-- const.tfrVoxelCenters
Results will be confined to voxel centers only.
-- const.tfrPassBorder, pass_border
Limit the result(s) to those located at a minimum distance *pass_border* to impassable.
-- const.tfrCanDestlock, destlock_radius
Restrict the results to be destlockable positions.
You can set a custom destlock_radius (-1 sets it to to the given unit's destlock radius).
If a point is given, in stead of a unit, destlock_radius is necessary
-- const.tfrDbgStats
Debug only: print statistics.
-- const.tfrDbgMap
Debug only: return point to weight map as first result
-- const.tfrLuaFilter, filter, [filter_params]
Call a Lua filter for each result.
The function is called with the coordinates *x*, *y* and *z*, followed by all *filter_params*.
This should be the last rule in the parameters as everything after it is considered as filter parameters.
_returns_ point pos1, pos2, ...
: Number of results specified by rule const.tfrResCount (1 by default)
Multiple rules can be requested in the same call by providing them in succession.
Example:
~~~~ Lua
local pos = terrain.FindReachable(self,
const.tfrRandom, seed,
const.tfrLimitDist, max_dist, min_dist,
const.tfrCenterRadius, max_radius, min_radius, center_pos,
const.tfrWeightDir, max_angle_weight, min_angle_weight, angle_weight_distrib,
const.tfrPassCost, max_cost, min_cost,
const.tfrLuaFilter, filter, ...)
~~~~
## terrain.FixHeightBorder
Fix any discontinuities at the height border, as some operation are not applied there.
void **terrain.FixHeightBorder**()
## terrain.GetAreaHeight
Returns the average height of the specified circle area. If no parameters are specified, then the average for the whole map is computed.
int **terrain.GetAreaHeight**(pos, radius)
point pos
: optional, center of the circle area.
int radius
: optional, radius of the circle area.
## terrain.GetGrassDensity
Returns the grass density at given position.
int **terrain.GetGrassDensity**(pos)
point pos
: position to check.
## terrain.GetHeight
Returns the terrain height at given position.
int **terrain.GetHeight**(pos)
point pos
: position to check.
## terrain.GetMapHeight
Returns the map height/sizey.
int **terrain.GetMapHeight**()
## terrain.GetMapSize
Returns the size of the map (terrain) rectangle as two integers (sizex and sizey).
int, int **terrain.GetMapSize**()
## terrain.GetMapWidth
Returns the map width/sizex.
int **terrain.GetMapWidth**()
## terrain.GetMinMaxHeight
Returns the min & max terrain height in a given box. The box bounderies are rounded up to the height grid alignment.
int, int **terrain.GetMinMaxHeight**(bbox)
## terrain.GetPassId
Returns an unique number defining the passability state of the terrain.
Different pass ID-s can denote the same passability state, but the same ID cannot denote two different passability states.
int **terrain.GetPassId**()
## terrain.GetSlopeOrientation
Returns the orientation angle of the terrain normal projection at the given position.
int **terrain.GetSlopeOrientation**(pos)
point pos
: position to check.
## terrain.GetSurfaceHeight
Returns the max surface height at given position (e.g. water).
int **terrain.GetSurfaceHeight**(pos)
point pos
: position to check.
## terrain.GetSurfaceNormal
Returns the normal to the terrain surface, with all components multiplied by 100.
point **terrain.GetSurfaceNormal**(pos)
point pos
: position to check.
## terrain.GetTerrainNormal
Returns the normal to the terrain, with all components multiplied by 100.
point **terrain.GetTerrainNormal**(pos)
point pos
: position to check.
## terrain.GetTerrainSlope
Returns the slope angle of the terrain at the given position, as determined by the terrain normal.
int **terrain.GetTerrainSlope**(pos)
point pos
: position to check.
## terrain.GetTerrainType
Returns the terrain type at the given map position.
int **terrain.GetTerrainType**(pos)
point pos
: position to check.
## terrain.GetTerrainsCount
Returns the number of available terrain types.
int **terrain.GetTerrainsCount**()
## terrain.GetWaterHeight
Returns the water height at given position.
int **terrain.GetWaterHeight**(pos)
point pos
: position to check.
## terrain.HeightMapSize
Returns the x and y sizes of the heightmap grid.
int, int **terrain.HeightMapSize**()
## terrain.IntersectRay
Returns the intersection point of a ray with the terrain.
point **terrain.IntersectRay**(pt1, pt2)
point pt1
: start point of the ray.
point pt2
: end point of the ray.
## terrain.IntersectSegment
Returns the intersection point of a segment with the terrain.
point **terrain.IntersectSegment**(pt1, pt2)
point pt1
: start point of the segment.
point pt2
: end point of the segment.
## terrain.InvalidateType
Forces a recalculation of the typemap in the specified area or the entire map.
void **terrain.InvalidateType**(area)
box area
: optional, area to recalculate.
## terrain.InvlidateHeight
Forces a recalculation of the height values in the specified area or the entire map.
void **terrain.InvlidateHeight**(area)
box area
: optional, area to recalculate.
## terrain.IsMapBox
Checks if a box is the same or bigger than the map bounding box.
bool **terrain.IsMapBox**(box)
box box
: box to check
## terrain.IsPointInBounds
Returns true if the specified point is inside the terrain boundaries.
bool **terrain.IsPointInBounds**(pos, [border])
point pos
: position to check.
int border
: optional, if specified the function will shrink the map boundaries by this amount for the purpose of the check.
## terrain.IsVerticalTerrain
Returns true if the specified point is s considered vertical terrain depending on the terrain normal.
bool **terrain.IsVerticalTerrain**(pos)
point pos
: position to check.
## terrain.IsWater
Returns whether water is present at given position.
int **terrain.IsWater**(pos)
point pos
: position to check.
## terrain.IsWaterNearby
Checks for water/land in a given radius.
bool **terrain.IsWaterNearby**(pos, radius)
point pos
: position to check.
int radius
: check radius.
## terrain.ReplaceTypeCircle
Replaced the terrain type in a circle area.
void **terrain.ReplaceTypeCircle**(ptCenter, nRadius, hTypeOld, vType)
point ptCenter
: center of the circle area to change.
int nRadius
: radius of the circle area to change.
int hTypeOld
: terrain type to be replaced.
int hTypeNew
: terrain type to apply.
int vType
: optional, alternative terrain type to apply on vertical terrain areas.
## terrain.ScaleHeight
Scales all values in the height grid by given nominator and denominator.
void **terrain.ScaleHeight**(mul, div)
int mul
: nominator value to apply.
int div
: denominator value to apply.
## terrain.SetHeight
Sets the terrain height at the given position to the specified value.
void **terrain.SetHeight**(pos, height)
point pos
: the position to alter.
int height
: the new height to set.
## terrain.SetHeightCircle
Calculates the average height in the given circle, then modifies it by the given value
void **terrain.SetHeightCircle**(pt, nInnerRadius, nOuterRadius, nHeightDiff)
point pt
: the center of the circle area to alter.
int nInnerRadius
: radius of the inner circle, where the desired height will be set without smoothing.
int nOuterRadius
: radius of the outer ring, where the new height will be smoothed toward the current values.
int nHeightDiff
: value to add to the computed average height.
## terrain.SetHeightCircle
Sets the height values in the given circle, smoothing the height in the outer ring toward the existing values
void **terrain.SetHeightCircle**(pt, nInnerRadius, nOuterRadius, nHeight, mode)
point pt
: the center of the circle area to alter.
int nInnerRadius
: radius of the inner circle, where the desired height will be set without smoothing.
int nOuterRadius
: radius of the outer ring, where the new height will be smoothed toward the current values.
int nHeight
: new height to set.
int mode
: optional, can be const.hsDefault (default, set target values directly), const.hsMin (new_height = Min(new_height, current)) or const.hsMax (new_height = Max(new_height, current)).
## terrain.SetTerrainType
Sets the terrain type at the given position.
void **terrain.SetTerrainType**(pos, type)
point pos
: position to change.
int type
: new terrain type.
## terrain.SetTypeBox
Sets the terrain type in a rectangular area.
void **terrain.SetTypeBox**(box, type)
box b
: the area to change.
int nType
: terrain type to apply.
## terrain.SetTypeCircle
Sets the terrain type in a circle area.
void **terrain.SetTypeCircle**(ptCenter, nRadius, hType, vType)
point ptCenter
: center of the circle area to change.
int nRadius
: radius of the circle area to change.
int hType
: terrain type to apply.
int vType
: optional, alternative terrain type to apply on vertical terrain areas.
## terrain.SmoothHeightCircle
Smooths the terrain height in the given circle.
void **terrain.SmoothHeightCircle**(pt, radius)
point pt
: the center of the circle area to smooth.
int radius
: the radius of circle area to smooth.
string mode
: (optional) you can specify "min" or "max" to be used when setting the terrain height at each point.
## terrain.TypeMapSize
Returns the x and y sizes of the typemap grid.
int, int **terrain.TypeMapSize**()
## terrain.UpdateWaterGridFromObject
Sets the water height from the position of a given object.
void **terrain.UpdateWaterGridFromObject**(obj)
object obj
: object to use (or it's position).
(insert footer.md.html here)
<link rel="stylesheet" type="text/css" href="Style.css" />
<!-- Markdeep: --><style class="fallback">body{visibility:hidden;white-space:pre;font-family:monospace}</style><script src="markdeep.min.js" charset="utf-8"></script><script>window.alreadyProcessedMarkdeep||(document.body.style.visibility="visible")</script> |