703 |
703 |
704 if (flags & DC_EXEC) { |
704 if (flags & DC_EXEC) { |
705 if (!HasSignals(tile)) { |
705 if (!HasSignals(tile)) { |
706 /* there are no signals at all on this tile yet */ |
706 /* there are no signals at all on this tile yet */ |
707 SetHasSignals(tile, true); |
707 SetHasSignals(tile, true); |
708 _m[tile].m2 |= 0xF0; // all signals are on |
708 SetSignalStates(tile, 0xF); // all signals are on |
709 _m[tile].m3 &= ~0xF0; // no signals built by default |
709 SetPresentSignals(tile, 0); // no signals built by default |
710 SetSignalType(tile, SIGTYPE_NORMAL); |
710 SetSignalType(tile, SIGTYPE_NORMAL); |
711 SetSignalVariant(tile, sigvar); |
711 SetSignalVariant(tile, sigvar); |
712 } |
712 } |
713 |
713 |
714 if (p2 == 0) { |
714 if (p2 == 0) { |
715 if (!HasSignalOnTrack(tile, track)) { |
715 if (!HasSignalOnTrack(tile, track)) { |
716 /* build new signals */ |
716 /* build new signals */ |
717 _m[tile].m3 |= SignalOnTrack(track); |
717 SetPresentSignals(tile, GetPresentSignals(tile) | SignalOnTrack(track)); |
718 } else { |
718 } else { |
719 if (pre_signal) { |
719 if (pre_signal) { |
720 /* cycle between normal -> pre -> exit -> combo -> ... */ |
720 /* cycle between normal -> pre -> exit -> combo -> ... */ |
721 SignalType type = GetSignalType(tile); |
721 SignalType type = GetSignalType(tile); |
722 |
722 |
726 } |
726 } |
727 } |
727 } |
728 } else { |
728 } else { |
729 /* If CmdBuildManySignals is called with copying signals, just copy the |
729 /* If CmdBuildManySignals is called with copying signals, just copy the |
730 * direction of the first signal given as parameter by CmdBuildManySignals */ |
730 * direction of the first signal given as parameter by CmdBuildManySignals */ |
731 _m[tile].m3 &= ~SignalOnTrack(track); |
731 SetPresentSignals(tile, (GetPresentSignals(tile) & ~SignalOnTrack(track)) | (p2 & SignalOnTrack(track))); |
732 _m[tile].m3 |= p2 & SignalOnTrack(track); |
|
733 SetSignalVariant(tile, sigvar); |
732 SetSignalVariant(tile, sigvar); |
734 } |
733 } |
735 |
734 |
736 MarkTileDirtyByTile(tile); |
735 MarkTileDirtyByTile(tile); |
737 SetSignalsOnBothDir(tile, track); |
736 SetSignalsOnBothDir(tile, track); |
782 |
781 |
783 track = TrackdirToTrack(trackdir); /* trackdir might have changed, keep track in sync */ |
782 track = TrackdirToTrack(trackdir); /* trackdir might have changed, keep track in sync */ |
784 |
783 |
785 /* copy the signal-style of the first rail-piece if existing */ |
784 /* copy the signal-style of the first rail-piece if existing */ |
786 if (HasSignals(tile)) { |
785 if (HasSignals(tile)) { |
787 signals = _m[tile].m3 & SignalOnTrack(track); |
786 signals = GetPresentSignals(tile) & SignalOnTrack(track); |
788 if (signals == 0) signals = SignalOnTrack(track); /* Can this actually occur? */ |
787 if (signals == 0) signals = SignalOnTrack(track); /* Can this actually occur? */ |
789 |
788 |
790 /* copy signal/semaphores style (independent of CTRL) */ |
789 /* copy signal/semaphores style (independent of CTRL) */ |
791 semaphores = GetSignalVariant(tile) != SIG_ELECTRIC; |
790 semaphores = GetSignalVariant(tile) != SIG_ELECTRIC; |
792 } else { // no signals exist, drag a two-way signal stretch |
791 } else { // no signals exist, drag a two-way signal stretch |
872 |
871 |
873 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
872 SET_EXPENSES_TYPE(EXPENSES_CONSTRUCTION); |
874 |
873 |
875 /* Do it? */ |
874 /* Do it? */ |
876 if (flags & DC_EXEC) { |
875 if (flags & DC_EXEC) { |
877 _m[tile].m3 &= ~SignalOnTrack(track); |
876 SetPresentSignals(tile, GetPresentSignals(tile) & ~SignalOnTrack(track)); |
878 |
877 |
879 /* removed last signal from tile? */ |
878 /* removed last signal from tile? */ |
880 if (GB(_m[tile].m3, 4, 4) == 0) { |
879 if (GetPresentSignals(tile) == 0) { |
881 SB(_m[tile].m2, 4, 4, 0); |
880 SetSignalStates(tile, 0); |
882 SetHasSignals(tile, false); |
881 SetHasSignals(tile, false); |
883 SetSignalVariant(tile, SIG_ELECTRIC); // remove any possible semaphores |
882 SetSignalVariant(tile, SIG_ELECTRIC); // remove any possible semaphores |
884 } |
883 } |
885 |
884 |
886 SetSignalsOnBothDir(tile, track); |
885 SetSignalsOnBothDir(tile, track); |
1664 |
1663 |
1665 /* then mark the signals in the segment accordingly */ |
1664 /* then mark the signals in the segment accordingly */ |
1666 for (i = 0; i != ssd->cur; i++) { |
1665 for (i = 0; i != ssd->cur; i++) { |
1667 TileIndex tile = ssd->tile[i]; |
1666 TileIndex tile = ssd->tile[i]; |
1668 byte bit = SignalAgainstTrackdir(ssd->bit[i]); |
1667 byte bit = SignalAgainstTrackdir(ssd->bit[i]); |
1669 uint16 m2 = _m[tile].m2; |
1668 uint signals = GetSignalStates(tile); |
1670 |
1669 |
1671 /* presignals don't turn green if there is at least one presignal exit and none are free */ |
1670 /* presignals don't turn green if there is at least one presignal exit and none are free */ |
1672 if (IsPresignalEntry(tile)) { |
1671 if (IsPresignalEntry(tile)) { |
1673 int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free; |
1672 int ex = ssd->presignal_exits, exfree = ssd->presignal_exits_free; |
1674 |
1673 |
1684 |
1683 |
1685 /* check if the signal is unaffected. */ |
1684 /* check if the signal is unaffected. */ |
1686 if (ssd->stop) { |
1685 if (ssd->stop) { |
1687 make_red: |
1686 make_red: |
1688 /* turn red */ |
1687 /* turn red */ |
1689 if ((bit & m2) == 0) continue; |
1688 if ((bit & signals) == 0) continue; |
1690 } else { |
1689 } else { |
1691 /* turn green */ |
1690 /* turn green */ |
1692 if ((bit & m2) != 0) continue; |
1691 if ((bit & signals) != 0) continue; |
1693 } |
1692 } |
1694 |
1693 |
1695 /* Update signals on the other side of this exit-combo signal; it changed. */ |
1694 /* Update signals on the other side of this exit-combo signal; it changed. */ |
1696 if (IsPresignalExit(tile)) { |
1695 if (IsPresignalExit(tile)) { |
1697 if (ssd->cur_stack != NUM_SSD_STACK) { |
1696 if (ssd->cur_stack != NUM_SSD_STACK) { |
1702 DEBUG(misc, 0, "NUM_SSD_STACK too small"); /// @todo WTF is this??? |
1701 DEBUG(misc, 0, "NUM_SSD_STACK too small"); /// @todo WTF is this??? |
1703 } |
1702 } |
1704 } |
1703 } |
1705 |
1704 |
1706 /* it changed, so toggle it */ |
1705 /* it changed, so toggle it */ |
1707 _m[tile].m2 = m2 ^ bit; |
1706 SetSignalStates(tile, signals ^ bit); |
1708 MarkTileDirtyByTile(tile); |
1707 MarkTileDirtyByTile(tile); |
1709 } |
1708 } |
1710 } |
1709 } |
1711 |
1710 |
1712 |
1711 |
1926 return (rails == TRACK_BIT_CROSS) ? ret | 0x40 : ret; |
1925 return (rails == TRACK_BIT_CROSS) ? ret | 0x40 : ret; |
1927 } |
1926 } |
1928 |
1927 |
1929 case RAIL_TILE_SIGNALS: { |
1928 case RAIL_TILE_SIGNALS: { |
1930 uint32 ret = GetTrackBits(tile) * 0x101; |
1929 uint32 ret = GetTrackBits(tile) * 0x101; |
1931 byte a; |
1930 byte a = GetPresentSignals(tile); |
1932 uint16 b; |
1931 uint b = GetSignalStates(tile); |
1933 |
|
1934 a = _m[tile].m3; |
|
1935 b = _m[tile].m2; |
|
1936 |
1932 |
1937 b &= a; |
1933 b &= a; |
1938 |
1934 |
1939 /* When signals are not present (in neither |
1935 /* When signals are not present (in neither |
1940 * direction), we pretend them to be green. (So if |
1936 * direction), we pretend them to be green. (So if |
1941 * signals are only one way, the other way will |
1937 * signals are only one way, the other way will |
1942 * implicitely become `red' */ |
1938 * implicitely become `red' */ |
1943 if ((a & 0xC0) == 0) b |= 0xC0; |
1939 if ((a & 0xC) == 0) b |= 0xC; |
1944 if ((a & 0x30) == 0) b |= 0x30; |
1940 if ((a & 0x3) == 0) b |= 0x3; |
1945 |
1941 |
1946 if ((b & 0x80) == 0) ret |= 0x10070000; |
1942 if ((b & 0x8) == 0) ret |= 0x10070000; |
1947 if ((b & 0x40) == 0) ret |= 0x07100000; |
1943 if ((b & 0x4) == 0) ret |= 0x07100000; |
1948 if ((b & 0x20) == 0) ret |= 0x20080000; |
1944 if ((b & 0x2) == 0) ret |= 0x20080000; |
1949 if ((b & 0x10) == 0) ret |= 0x08200000; |
1945 if ((b & 0x1) == 0) ret |= 0x08200000; |
1950 |
1946 |
1951 return ret; |
1947 return ret; |
1952 } |
1948 } |
1953 |
1949 |
1954 case RAIL_TILE_DEPOT: return AxisToTrackBits(DiagDirToAxis(GetRailDepotDirection(tile))) * 0x101; |
1950 case RAIL_TILE_DEPOT: return AxisToTrackBits(DiagDirToAxis(GetRailDepotDirection(tile))) * 0x101; |