Loading
#openttdcoop - Paste
Archives
Trending
Docs
Login
ABAP
ActionScript
ActionScript 3
Ada
AIMMS3
ALGOL 68
Apache configuration
AppleScript
Apt sources
ARM ASSEMBLER
ASM
ASP
asymptote
Autoconf
Autohotkey
AutoIt
AviSynth
awk
BASCOM AVR
Bash
Basic4GL
BibTeX
BlitzBasic
bnf
Boo
Brainfuck
C
C#
C (LoadRunner)
C (Mac)
C (WinAPI)
C++
C++ (Qt)
C++ (WinAPI)
CAD DCL
CAD Lisp
CFDG
ChaiScript
Chapel
CIL
Clojure
CMake
COBOL
CoffeeScript
ColdFusion
CSS
Cuesheet
D
Dart
DCL
DCPU-16 Assembly
DCS
Delphi
Diff
DIV
DOS
dot
E
ECMAScript
Eiffel
eMail (mbox)
EPC
Erlang
Euphoria
EZT
F#
Falcon
FO (abas-ERP)
Formula One
Fortran
FreeBasic
FreeSWITCH
GADV 4CS
GAMBAS
GDB
genero
Genie
glSlang
GML
GNU/Octave
GNU Gettext
GNU make
Gnuplot
Go
Groovy
GwBasic
Haskell
Haxe
HicEst
HQ9+
HTML
HTML5
Icon
INI
Inno
INTERCAL
Io
ISPF Panel
J
Java
Java(TM) 2 Platform Standard Edition 5.0
Javascript
JCL
jQuery
KiXtart
KLone C
KLone C++
LaTeX
LDIF
Liberty BASIC
Lisp
LLVM Intermediate Representation
Locomotive Basic
Logtalk
LOLcode
Lotus Notes @Formulas
LotusScript
LScript
LSL2
Lua
MagikSF
MapBasic
Matlab M
Microchip Assembler
Microsoft Registry
mIRC Scripting
MMIX
Modula-2
Modula-3
MOS 6502 (6510) ACME Cross Assembler format
MOS 6502 (6510) Kick Assembler format
MOS 6502 (6510) TASM/64TASS 1.46 Assembler format
Motorola 68000 - HiSoft Devpac ST 2 Assembler format
Motorola 68000 Assembler
MXML
MySQL
Nagios
NetRexx
newlisp
nginx
Nimrod
NML NewGRF Meta Language
NSIS
Oberon-2
Objeck Programming Language
Objective-C
OCaml
OCaml (brief)
ooRexx
OpenBSD Packet Filter
OpenOffice.org Basic
Oracle 8 SQL
Oracle 11 SQL
Oxygene
OZ
ParaSail
PARI/GP
Pascal
PCRE
per
Perl
Perl 6
PHP
PHP (brief)
PIC16
Pike
Pixel Bender 1.0
PL/I
PL/SQL
PostgreSQL
PostScript
POVRAY
PowerBuilder
PowerShell
ProFTPd configuration
Progress
Prolog
PROPERTIES
ProvideX
Puppet
PureBasic
Python
Python for S60
q/kdb+
QBasic/QuickBASIC
QML
R / S+
Racket
Rails
RBScript
REBOL
rexx
robots.txt
RPM Specification File
Ruby
Rust
SAS
Scala
Scheme
SciLab
SCL
sdlBasic
Smalltalk
Smarty
SPARK
SPARQL
SQL
Squirrel Script
Squirrel Script with OpenTTD AI/GS
StandardML
StoneScript
SystemVerilog
T-SQL
TCL
Tera Term Macro
Text
thinBasic
TypoScript
Unicon (Unified Extended Dialect of Icon)
Uno Idl
Unreal Script
UPC
Urbi
Vala
vb.net
VBScript
Vedit macro language
Verilog
VHDL
Vim Script
Visual Basic
Visual Fox Pro
Visual Prolog
Whitespace
Whois (RPSL format)
Winbatch
X++
XBasic
XML
Xorg configuration
YAML
ZiLOG Z80 Assembler
ZXBasic
diff --git a/src/map.cpp b/src/map.cpp index 81985be..d79f910 100644 --- a/src/map.cpp +++ b/src/map.cpp @@ -495,27 +495,51 @@ TileOwner VoxelWorld::GetTileOwner(uint16 x, uint16 y) return this->GetStack(x, y)->owner; } -/** Map of imploded base ground slope to mask of fence nibbles at the base voxel. */ +/** + * At ground level of each voxel stack are 4 fences, one at each edge (ordered as #EDGE_NE .. # EDGE_NW). + * Due to slopes, some fences are at the bottom voxel (the base voxel) of the ground level, the other + * fences are at the top voxel. The rule for placement is + * - Both fences near the top edge of a steep slope are in the top voxel. + * - Both fences near the bottom edge of a steep slope are in the bottom voxel. + * - Fences on edges of non-steep slopes with both corners raised are in the top voxel. + * - Other fences of non-steep slopes are in the bottom voxel. + * + * Each voxel has the possibility to store 4 fences (one at each edge). In the general case with a + * base voxel and a top voxel, there are 8 positions for fences, where 4 of them are used to store + * ground level fences. Below is the mask for getting the fences at base voxel level, for each non-top slope. + * A \c 0xF nibble means the fence is stored in the base voxel, a \c 0x0 nibble means the fence is stored + * in the top voxel. (Top-slopes make no sense to include here, as they only describe the top voxel.) + * + * To work with the masks, the following functions exist: + * - #MergeGroundFencesAtBase sets the given fences for the base voxel. + * - #HasTopVoxelFences tells whether the slope has any fences in the top voxel (that is, does it have a top voxel at all?) + * - #MergeGroundFencesAtTop sets the given fences for the top voxel. + * + * The following functions interact with the map. + * - #GetGroundFencesFromMap gets the fences at ground level from a voxel stack. + * - #AddGroundFencesToMap sets the fences to a voxel stack. + * + */ static const uint16 _fences_mask_at_base[] = { - 0xFFFF, // 0 - 0xFFFF, // 1 - 0xFFFF, // 2 - 0xFFF0, // 3 - 0xFFFF, // 4 - 0xFFFF, // 5 - 0xFF0F, // 6 - 0xFF00, // 7 - 0xFFFF, // 8 - 0x0FFF, // 9 - 0xFFFF, // 10 - 0x0FF0, // 11 - 0xF0FF, // 12 - 0x00FF, // 13 - 0xF00F, // 14 - 0x0FF0, // 15 base steep north - 0xFF00, // 16 base steep east - 0xF00F, // 17 base steep south - 0x00FF, // 18 base steep west + 0xFFFF, // Imploded ground slope 0 + 0xFFFF, // Imploded ground slope 1 + 0xFFFF, // Imploded ground slope 2 + 0xFFF0, // Imploded ground slope 3 + 0xFFFF, // Imploded ground slope 4 + 0xFFFF, // Imploded ground slope 5 + 0xFF0F, // Imploded ground slope 6 + 0xFF00, // Imploded ground slope 7 + 0xFFFF, // Imploded ground slope 8 + 0x0FFF, // Imploded ground slope 9 + 0xFFFF, // Imploded ground slope 10 + 0x0FF0, // Imploded ground slope 11 + 0xF0FF, // Imploded ground slope 12 + 0x00FF, // Imploded ground slope 13 + 0xF00F, // Imploded ground slope 14 + 0x0FF0, // Imploded ground slope 15 (base steep north) + 0xFF00, // Imploded ground slope 16 (base steep east) + 0xF00F, // Imploded ground slope 17 (base steep south) + 0x00FF, // Imploded ground slope 18 (base steep west) }; /** @@ -529,8 +553,8 @@ uint16 MergeGroundFencesAtBase(uint16 vxbase_fences, uint16 fences, uint8 base_t { assert(base_tile_slope < lengthof(_fences_mask_at_base)); // Top steep slopes are not allowed. uint16 mask = _fences_mask_at_base[base_tile_slope]; - fences &= mask; - mask ^= 0xFFFF; + fences &= mask; // Kill any fence not in the base voxel. + mask ^= 0xFFFF; // Swap mask to keep only non-fences of the current voxel data. return (vxbase_fences & mask) | fences; } @@ -556,8 +580,8 @@ uint16 MergeGroundFencesAtTop(uint16 vxtop_fences, uint16 fences, uint8 base_til { assert(base_tile_slope < lengthof(_fences_mask_at_base)); // Top steep slopes are not allowed. uint16 mask = _fences_mask_at_base[base_tile_slope]; - vxtop_fences &= mask; - mask ^= 0xFFFF; + vxtop_fences &= mask; // Keep fences of top voxel that are at ground level in the base voxel. + mask ^= 0xFFFF; // Swap mask to keep fences that belong in the top voxel. return (fences & mask) | vxtop_fences; } @@ -592,12 +616,12 @@ uint16 GetGroundFencesFromMap(const VoxelStack *stack, int base_z) assert(slope < lengthof(_fences_mask_at_base)); // Top steep slopes are not allowed. uint16 mask = _fences_mask_at_base[slope]; - uint16 fences = v->GetFences() & mask; + uint16 fences = v->GetFences() & mask; // Get ground level fences of the base voxel. if (HasTopVoxelFences(slope)) { v = stack->Get(base_z + 1); uint top_fences = (v != nullptr) ? v->GetFences() : ALL_INVALID_FENCES; - mask ^= 0xFFFF; - fences |= top_fences & mask; + mask ^= 0xFFFF; // Swap all bits to top voxel mask. + fences |= top_fences & mask; // Add fences of the top voxel. } return fences; }
Mark as private
for 30 minutes
for 6 hours
for 1 day
for 1 week
for 1 month
for 1 year
forever