• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

traintastic / traintastic / 21925098429

11 Feb 2026 10:12PM UTC coverage: 27.986% (+0.002%) from 27.984%
21925098429

push

github

reinder
[lua] added missing pathfinder support and manual entries

1 of 1 new or added line in 1 file covered. (100.0%)

9 existing lines in 1 file now uncovered.

8172 of 29200 relevant lines covered (27.99%)

194.65 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

29.41
/server/src/board/pathfinder/trainpathfinder.cpp
1
/**
2
 * This file is part of Traintastic,
3
 * see <https://github.com/traintastic/traintastic>.
4
 *
5
 * Copyright (C) 2026 Reinder Feenstra
6
 *
7
 * This program is free software; you can redistribute it and/or
8
 * modify it under the terms of the GNU General Public License
9
 * as published by the Free Software Foundation; either version 2
10
 * of the License, or (at your option) any later version.
11
 *
12
 * This program is distributed in the hope that it will be useful,
13
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15
 * GNU General Public License for more details.
16
 *
17
 * You should have received a copy of the GNU General Public License
18
 * along with this program; if not, write to the Free Software
19
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
20
 */
21

22
#include "trainpathfinder.hpp"
23
#include <traintastic/enum/blocktraindirection.hpp>
24
#include "../map/blockpath.hpp"
25
#include "../../core/method.tpp"
26
#include "../../core/objectproperty.tpp"
27
#include "../../board/tile/rail/blockrailtile.hpp"
28
#include "../../train/trainblockstatus.hpp"
29

30
TrainPathFinder::TrainPathFinder(Object& parent_, std::string_view parentPropertyName)
211✔
31
  : PathFinder(parent_, parentPropertyName)
32
  , reserve{*this, "reserve", MethodFlags::ScriptCallable,
211✔
UNCOV
33
      [](const std::shared_ptr<BlockRailTile>& fromBlock, BlockTrainDirection fromDirection, const std::shared_ptr<BlockRailTile>& toBlock, BlockTrainDirection toDirection)
×
34
      {
UNCOV
35
        if(!fromBlock || fromBlock->trains.empty() || !isKnown(fromDirection) || !toBlock || !isKnown(toDirection)) [[unlikely]]
×
36
        {
UNCOV
37
          return false;
×
38
        }
39

40
        const auto fromSide = (fromDirection == BlockTrainDirection::TowardsA) ? BlockSide::A : BlockSide::B;
×
UNCOV
41
        const auto toSide = (toDirection == BlockTrainDirection::TowardsB) ? BlockSide::A : BlockSide::B;
×
42

43
        // FIXME: for now only support block to block (direct path only)
44

UNCOV
45
        for(const auto& path : fromBlock->paths())
×
46
        {
UNCOV
47
          if(path->fromSide() == fromSide && path->toBlock() == toBlock && path->toSide() == toSide)
×
48
          {
49
            const auto train =
50
              (fromDirection == BlockTrainDirection::TowardsB)
51
                ? fromBlock->trains.back()->train.value()
×
UNCOV
52
                : fromBlock->trains.front()->train.value();
×
53

54
            return path->reserve(train);
×
UNCOV
55
          }
×
56
        }
57

UNCOV
58
        return false;
×
59
      }}
211✔
60
{
61
  m_interfaceItems.add(reserve);
211✔
62
}
211✔
63

64

STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc