rail_cmd.c
changeset 22 fe6f35cc987b
parent 13 3e7c1f74a996
child 39 d177340ed556
equal deleted inserted replaced
21:67cde01e8359 22:fe6f35cc987b
     6 #include "pathfind.h"
     6 #include "pathfind.h"
     7 #include "town.h"
     7 #include "town.h"
     8 
     8 
     9 void ShowTrainDepotWindow(uint tile);
     9 void ShowTrainDepotWindow(uint tile);
    10 
    10 
    11 enum {
    11 enum { /* These values are bitmasks for the map5 byte */
    12 	RAIL_TYPE_NORMAL = 0,
    12 	RAIL_TYPE_NORMAL = 0,
    13 	RAIL_TYPE_SIGNALS = 0x40,
    13 	RAIL_TYPE_SIGNALS = 0x40,
    14 	RAIL_TYPE_SPECIAL = 0x80, // If this bit is set, then it's not a regular track.
    14 	RAIL_TYPE_SPECIAL = 0x80, // If this bit is set, then it's not a regular track.
    15 	RAIL_TYPE_DEPOT = 0xC0,
    15 	RAIL_TYPE_DEPOT = 0xC0,
    16 	RAIL_TYPE_MASK = 0xC0,
    16 	RAIL_TYPE_MASK = 0xC0,
    38 /* Format of rail map5 byte.
    38 /* Format of rail map5 byte.
    39  * 00 abcdef  => Normal rail
    39  * 00 abcdef  => Normal rail
    40  * 01 abcdef  => Rail with signals
    40  * 01 abcdef  => Rail with signals
    41  * 10 ??????  => Unused
    41  * 10 ??????  => Unused
    42  * 11 ????dd  => Depot
    42  * 11 ????dd  => Depot
       
    43  *
       
    44  * abcdef is a bitmask, which contains ones for all present tracks. Below the
       
    45  * value for each track is given. 
    43  */
    46  */
    44 
    47 
    45 /*         4
    48 /*         4
    46  *     ---------
    49  *     ---------
    47  *    |\       /|
    50  *    |\       /|
    75 	RAIL_GROUND_FENCE_HORIZ2 = 11,
    78 	RAIL_GROUND_FENCE_HORIZ2 = 11,
    76 	RAIL_GROUND_ICE_DESERT = 12,
    79 	RAIL_GROUND_ICE_DESERT = 12,
    77 };
    80 };
    78 
    81 
    79 
    82 
    80 /* MAP2 byte:    abcd???? => Signal On?
    83 /* MAP2 byte:    abcd???? => Signal On? Same coding as map3lo
    81  * MAP3LO byte:  abcd???? => Signal Exists?
    84  * MAP3LO byte:  abcd???? => Signal Exists? 
       
    85  *				 a and b are for diagonals, upper and left,
       
    86  *				 one for each direction. (ie a == NE->SW, b ==
       
    87  *				 SW->NE, or v.v., I don't know. b and c are
       
    88  *				 similar for lower and right.
    82  * MAP2 byte:    ????abcd => Type of ground.
    89  * MAP2 byte:    ????abcd => Type of ground.
    83  * MAP3LO byte:  ????abcd => Type of rail.
    90  * MAP3LO byte:  ????abcd => Type of rail.
    84  * MAP5:         00abcdef => rail
    91  * MAP5:         00abcdef => rail
    85  *               01abcdef => rail w/ signals
    92  *               01abcdef => rail w/ signals
    86  *               10uuuuuu => unused
    93  *               10uuuuuu => unused
  1794 
  1801 
  1795 	if (!(m5 & RAIL_TYPE_SPECIAL)) {
  1802 	if (!(m5 & RAIL_TYPE_SPECIAL)) {
  1796 		ret = (m5 | (m5 << 8)) & 0x3F3F;
  1803 		ret = (m5 | (m5 << 8)) & 0x3F3F;
  1797 		if (!(m5 & RAIL_TYPE_SIGNALS)) {
  1804 		if (!(m5 & RAIL_TYPE_SIGNALS)) {
  1798 			if ( (ret & 0xFF) == 3)
  1805 			if ( (ret & 0xFF) == 3)
       
  1806 			/* Diagonal crossing? */
  1799 				ret |= 0x40;
  1807 				ret |= 0x40;
  1800 		} else {
  1808 		} else {
  1801 			/* has_signals */
  1809 			/* has_signals */
  1802 
  1810 
  1803 			a = _map3_lo[tile];
  1811 			a = _map3_lo[tile];
  1804 			b = _map2[tile];
  1812 			b = _map2[tile];
  1805 
  1813 
  1806 			b &= a;
  1814 			b &= a;
  1807 
  1815 
       
  1816 			/* When signals are not present (in neither
       
  1817 			 * direction), we pretend them to be green. (So if
       
  1818 			 * signals are only one way, the other way will
       
  1819 			 * implicitely become `red' */
  1808 			if ((a & 0xC0) == 0) { b |= 0xC0; }
  1820 			if ((a & 0xC0) == 0) { b |= 0xC0; }
  1809 			if ((a & 0x30) == 0) { b |= 0x30; }
  1821 			if ((a & 0x30) == 0) { b |= 0x30; }
  1810 
  1822 
  1811 			if ( (b & 0x80) == 0)	ret |= 0x10070000;
  1823 			if ( (b & 0x80) == 0)	ret |= 0x10070000;
  1812 			if ( (b & 0x40) == 0)	ret |= 0x7100000;
  1824 			if ( (b & 0x40) == 0)	ret |= 0x7100000;