18
0
mirror of https://github.com/MaSzyna-EU07/maszyna.git synced 2026-11-28 22:03:20 +01:00
Files
maszyna/world/RoadSurfaceType.h
jerrrrycho 169527f333 feat(editor): dirt road type with looser layout limits in the road tool (#491)
* feat(editor): dirt road type with looser layout limits in the road tool

Every road shared the limits of a built road, so the road tool refused
field tracks that bend tight, kink, have very short straights and fork
at sharp angles (#347).

Roads now have a type, paved (the default, with the limits as they
were) or dirt, chosen in the road settings and saved with each piece as
"surfacetype dirt". A dirt road bends down to a 3 m radius instead of
6 m, can be 1 m long instead of 2 m, leaves other roads at 15 degrees
instead of 30, may lead off square to the far end when both ends are
tied, and may turn up to 240 degrees in a hairpin. The limits come from
one table, editor/editorRoadLimits.hpp, whose paved row holds the old
constants.

A paved road writes nothing new, so existing sceneries load and save
byte for byte as before. Switching a road to dirt turns the default
asphalt into the field road texture droga_polna from the game data and
drops the white markings; a material picked by hand stays.

* fix(editor): no bend of a road tighter than the road is wide, pi from <numbers>, the type's name as a string_view
2026-11-26 22:28:58 +01:00

64 lines
1.8 KiB
C++

/*
This Source Code Form is subject to the
terms of the Mozilla Public License, v.
2.0. If a copy of the MPL was not
distributed with this file, You can
obtain one at
http://mozilla.org/MPL/2.0/.
*/
#pragma once
#include <string>
#include <string_view>
// what a road is made of, as far as laying it out goes. a paved road (asphalt, concrete, setts) keeps to the bends and the angles
// of a built road; a dirt road (a track between fields, through a forest) turns tighter, comes in shorter stretches
// and leaves other roads at sharper angles.
// scenery entry: surfacetype <paved|dirt>, written for a dirt road only
enum class road_surface_type
{
paved,
dirt
};
namespace road_surface
{
// the word the scenery uses for the type
inline char const *name(road_surface_type const Type)
{
return Type == road_surface_type::dirt ? "dirt" : "paved";
}
// the type going by specified word. returns: false if there's no such type, with Type left as it was
inline bool from_name(std::string_view const Name, road_surface_type &Type)
{
if (Name == "paved")
{
Type = road_surface_type::paved;
return true;
}
if (Name == "dirt")
{
Type = road_surface_type::dirt;
return true;
}
return false;
}
// the scenery entry of the type, followed by a space. a paved road, which all the roads made before the types are, writes nothing,
// so the sceneries are saved as they were
inline std::string entry(road_surface_type const Type)
{
return Type == road_surface_type::paved ? std::string{} : std::string{"surfacetype "} + name(Type) + ' ';
}
// the material the surface of a road of the type gets unless told otherwise: the default asphalt, or the field road of the game's textures
inline char const *default_material(road_surface_type const Type)
{
return Type == road_surface_type::dirt ? "droga_polna" : "asphaltdark1";
}
} // namespace road_surface