yapf/yapf_costbase.hpp
author celestar
Wed, 27 Dec 2006 12:38:02 +0000
changeset 5385 3868f2e6db9b
parent 5139 7bdb1b79daa5
permissions -rw-r--r--
(svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     1
/* $Id$ */
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     2
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     3
#ifndef  YAPF_COSTBASE_HPP
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     4
#define  YAPF_COSTBASE_HPP
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     5
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     6
struct CYapfCostBase {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     7
	static const TrackdirBits   c_upwards_slopes[16];
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     8
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
     9
	FORCEINLINE static bool stSlopeCost(TileIndex tile, Trackdir td)
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    10
	{
5139
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    11
		if (IsDiagonalTrackdir(td)) {
5385
3868f2e6db9b (svn r7573) -Merged the bridge branch. Allows to build bridges of arbitrary rail/road combinations (including signals)
celestar
parents: 5139
diff changeset
    12
			if (IsBridgeTile(tile)) {
5139
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    13
				// it is bridge ramp, check if we are entering the bridge
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    14
				if (GetBridgeRampDirection(tile) != TrackdirToExitdir(td)) return false; // no, we are living it, no penalty
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    15
				// we are entering the bridge
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    16
				// if the tile slope is downwards, then bridge ramp has not upward slope
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    17
				uint tile_slope = GetTileSlope(tile, NULL) & 0x0F;
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    18
				if ((c_upwards_slopes[tile_slope] & TrackdirToTrackdirBits(ReverseTrackdir(td))) != 0) return false; // tile under ramp goes down, no penalty
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    19
				// tile under ramp isn't going down, so ramp must go up
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    20
				return true;
5139
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    21
			} else {
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    22
				// not bridge ramp
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    23
				if (IsTunnelTile(tile)) return false; // tunnel entry/exit doesn't slope
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    24
				uint tile_slope = GetTileSlope(tile, NULL) & 0x0F;
7bdb1b79daa5 (svn r7227) -Fix: [YAPF] Bridge YAPF Penalty Incorrect. The penalty for upward slope was incorrectly applied on bridge exit. (Danny)
KUDr
parents: 5018
diff changeset
    25
				if ((c_upwards_slopes[tile_slope] & TrackdirToTrackdirBits(td)) != 0) return true; // slopes uphill => apply penalty
3900
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    26
			}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    27
		}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    28
		return false;
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    29
	}
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    30
};
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    31
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    32
struct CostRailSettings {
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    33
	// look-ahead signal penalty
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    34
};
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    35
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    36
2c84ed52709d (svn r4987) Feature: Merged YAPF into trunk. Thanks to devs for continuous support and users for testing.
KUDr
parents:
diff changeset
    37
#endif /* YAPF_COSTBASE_HPP */