~ubuntu-branches/debian/squeeze/openttd/squeeze

« back to all changes in this revision

Viewing changes to src/signal.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Matthijs Kooijman, Jordi Mallach
  • Date: 2009-04-15 18:22:10 UTC
  • mfrom: (1.1.6 upstream) (2.1.3 squeeze)
  • Revision ID: james.westby@ubuntu.com-20090415182210-22ktb8kdbp2tf3bm
[ Matthijs Kooijman ]
* New upstream release.
* Remove Debian specific desktop file, upstream provides one now. 
* Add debian/watch file.

[ Jordi Mallach ]
* Bump Standards-Version to 3.8.1, with no changes required.
* Move to debhelper compat 7. Bump Build-Depends accordingly.
* Use dh_prep.
* Add "set -e" to config script.
* Remove a few extra doc files that get installed by upstream Makefile.
* Add more complete copyright information.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
/* $Id: signal.cpp 14259 2008-09-07 11:54:00Z rubidium $ */
 
1
/* $Id: signal.cpp 15299 2009-01-31 20:16:06Z smatz $ */
2
2
 
3
3
/** @file signal.cpp functions related to rail signals updating */
4
4
 
5
5
#include "stdafx.h"
6
 
#include "openttd.h"
7
6
#include "debug.h"
8
 
#include "tile_cmd.h"
9
 
#include "rail_map.h"
10
 
#include "road_map.h"
11
7
#include "station_map.h"
12
8
#include "tunnelbridge_map.h"
13
9
#include "vehicle_func.h"
14
 
#include "train.h"
15
 
#include "newgrf_station.h"
 
10
#include "vehicle_base.h"
16
11
#include "functions.h"
17
 
#include "track_type.h"
18
 
#include "track_func.h"
19
 
#include "signal_func.h"
20
 
#include "player_func.h"
21
12
 
22
13
 
23
14
/** these are the maximums used for updating signal blocks */
192
183
 
193
184
 
194
185
/** Check whether there is a train on rail, not in a depot */
195
 
static void *TrainOnTileEnum(Vehicle *v, void *)
 
186
static Vehicle *TrainOnTileEnum(Vehicle *v, void *)
196
187
{
197
188
        if (v->type != VEH_TRAIN || v->u.rail.track == TRACK_BIT_DEPOT) return NULL;
198
189
 
256
247
        SF_GREEN  = 1 << 3, ///< green exitsignal found
257
248
        SF_GREEN2 = 1 << 4, ///< two or more green exits found
258
249
        SF_FULL   = 1 << 5, ///< some of buffers was full, do not continue
 
250
        SF_PBS    = 1 << 6, ///< pbs signal found
259
251
};
260
252
 
261
253
DECLARE_ENUM_AS_BIT_SET(SigFlags)
323
315
                                                Trackdir trackdir = (Trackdir)FindFirstBit((tracks * 0x101) & _enterdir_to_trackdirbits[enterdir]);
324
316
                                                Trackdir reversedir = ReverseTrackdir(trackdir);
325
317
                                                /* add (tile, reversetrackdir) to 'to-be-updated' set when there is
326
 
                                                 * ANY signal in REVERSE direction
 
318
                                                 * ANY conventional signal in REVERSE direction
327
319
                                                 * (if it is a presignal EXIT and it changes, it will be added to 'to-be-done' set later) */
328
320
                                                if (HasSignalOnTrackdir(tile, reversedir)) {
329
 
                                                        if (!_tbuset.Add(tile, reversedir)) return flags | SF_FULL;
 
321
                                                        if (IsPbsSignal(sig)) {
 
322
                                                                flags |= SF_PBS;
 
323
                                                        } else if (!_tbuset.Add(tile, reversedir)) {
 
324
                                                                return flags | SF_FULL;
 
325
                                                        }
330
326
                                                }
 
327
                                                if (HasSignalOnTrackdir(tile, trackdir) && !IsOnewaySignal(tile, track)) flags |= SF_PBS;
 
328
 
331
329
                                                /* if it is a presignal EXIT in OUR direction and we haven't found 2 green exits yes, do special check */
332
 
                                                if (!(flags & SF_GREEN2) && (sig & SIGTYPE_EXIT) && HasSignalOnTrackdir(tile, trackdir)) { // found presignal exit
 
330
                                                if (!(flags & SF_GREEN2) && IsPresignalExit(tile, track) && HasSignalOnTrackdir(tile, trackdir)) { // found presignal exit
333
331
                                                        if (flags & SF_EXIT) flags |= SF_EXIT2; // found two (or more) exits
334
332
                                                        flags |= SF_EXIT; // found at least one exit - allow for compiler optimizations
335
333
                                                        if (GetSignalStateByTrackdir(tile, trackdir) == SIGNAL_STATE_GREEN) { // found green presignal exit
337
335
                                                                flags |= SF_GREEN;
338
336
                                                        }
339
337
                                                }
 
338
 
340
339
                                                continue;
341
340
                                        }
342
341
                                }
423
422
                        /* train in the segment */
424
423
                        newstate = SIGNAL_STATE_RED;
425
424
                } else {
426
 
                        /* is it a bidir combo? - then do not count its other signal direction as exit */
 
425
                        /* is it a bidir combo? - then do not count its other signal direction as exit */
427
426
                        if (sig == SIGTYPE_COMBO && HasSignalOnTrackdir(tile, ReverseTrackdir(trackdir))) {
428
427
                                /* at least one more exit */
429
428
                                if (flags & SF_EXIT2 &&
430
 
                                                /* no green exit */
 
429
                                                /* no green exit */
431
430
                                                (!(flags & SF_GREEN) ||
432
431
                                                /* only one green exit, and it is this one - so all other exits are red */
433
432
                                                (!(flags & SF_GREEN2) && GetSignalStateByTrackdir(tile, ReverseTrackdir(trackdir)) == SIGNAL_STATE_GREEN))) {
434
433
                                        newstate = SIGNAL_STATE_RED;
435
434
                                }
436
435
                        } else { // entry, at least one exit, no green exit
437
 
                                if (sig & SIGTYPE_ENTRY && (flags & SF_EXIT && !(flags & SF_GREEN))) newstate = SIGNAL_STATE_RED;
 
436
                                if (IsPresignalEntry(tile, TrackdirToTrack(trackdir)) && flags & SF_EXIT && !(flags & SF_GREEN)) newstate = SIGNAL_STATE_RED;
438
437
                        }
439
438
                }
440
439
 
441
440
                /* only when the state changes */
442
441
                if (newstate != GetSignalStateByTrackdir(tile, trackdir)) {
443
 
                        if (sig & SIGTYPE_EXIT) {
 
442
                        if (IsPresignalExit(tile, TrackdirToTrack(trackdir))) {
444
443
                                /* for pre-signal exits, add block to the global set */
445
444
                                DiagDirection exitdir = TrackdirToExitdir(ReverseTrackdir(trackdir));
446
445
                                _globset.Add(tile, exitdir); // do not check for full global set, first update all signals
465
464
/**
466
465
 * Updates blocks in _globset buffer
467
466
 *
468
 
 * @param owner player whose signals we are updating
469
 
 * @return false iff presignal entry would be green (needed for trains leaving depot)
470
 
 * @pre IsValidPlayer(owner)
 
467
 * @param owner company whose signals we are updating
 
468
 * @return state of the first block from _globset
 
469
 * @pre IsValidCompanyID(owner)
471
470
 */
472
 
static bool UpdateSignalsInBuffer(Owner owner)
 
471
static SigSegState UpdateSignalsInBuffer(Owner owner)
473
472
{
474
 
        assert(IsValidPlayer(owner));
 
473
        assert(IsValidCompanyID(owner));
475
474
 
476
475
        bool first = true;  // first block?
477
 
        bool state = false; // value to return
 
476
        SigSegState state = SIGSEG_FREE; // value to return
478
477
 
479
478
        TileIndex tile;
480
479
        DiagDirection dir;
508
507
                        case MP_STATION:
509
508
                        case MP_ROAD:
510
509
                                if ((TrackStatusToTrackBits(GetTileTrackStatus(tile, TRANSPORT_RAIL, 0)) & _enterdir_to_trackbits[dir]) != TRACK_BIT_NONE) {
511
 
                                        /* only add to set when there is some 'interesting' track */
 
510
                                        /* only add to set when there is some 'interesting' track */
512
511
                                        _tbdset.Add(tile, dir);
513
512
                                        _tbdset.Add(tile + TileOffsByDiagDir(dir), ReverseDiagDir(dir));
514
513
                                        break;
533
532
 
534
533
                if (first) {
535
534
                        first = false;
536
 
                        state = (flags & SF_TRAIN) || (flags & SF_EXIT && !(flags & SF_GREEN)) || (flags & SF_FULL); // true iff train CAN'T leave the depot
 
535
                        /* SIGSEG_FREE is set by default */
 
536
                        if (flags & SF_PBS) {
 
537
                                state = SIGSEG_PBS;
 
538
                        } else if (flags & SF_TRAIN || (flags & SF_EXIT && !(flags & SF_GREEN)) || flags & SF_FULL) {
 
539
                                state = SIGSEG_FULL;
 
540
                        }
537
541
                }
538
542
 
539
543
                /* do not do anything when some buffer was full */
581
585
                DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NW, DIAGDIR_SW, DIAGDIR_NW, DIAGDIR_NE
582
586
        };
583
587
 
584
 
        /* do not allow signal updates for two players in one run */
 
588
        /* do not allow signal updates for two companies in one run */
585
589
        assert(_globset.IsEmpty() || owner == _last_owner);
586
590
 
587
591
        _last_owner = owner;
606
610
 */
607
611
void AddSideToSignalBuffer(TileIndex tile, DiagDirection side, Owner owner)
608
612
{
609
 
        /* do not allow signal updates for two players in one run */
 
613
        /* do not allow signal updates for two companies in one run */
610
614
        assert(_globset.IsEmpty() || owner == _last_owner);
611
615
 
612
616
        _last_owner = owner;
628
632
 * @param tile tile where we start
629
633
 * @param side side of tile
630
634
 * @param owner owner whose signals we will update
631
 
 * @return false iff train can leave depot
 
635
 * @return the state of the signal segment
632
636
 */
633
 
bool UpdateSignalsOnSegment(TileIndex tile, DiagDirection side, Owner owner)
 
637
SigSegState UpdateSignalsOnSegment(TileIndex tile, DiagDirection side, Owner owner)
634
638
{
635
639
        assert(_globset.IsEmpty());
636
640
        _globset.Add(tile, side);