Skip to content

Commit 0560b34

Browse files
committed
Beefs up ViaductResolver, adds ViaductRuleGenerator and enables its compilation.
1 parent 5adc225 commit 0560b34

3 files changed

Lines changed: 99 additions & 19 deletions

File tree

src/main/scala/module/CompileAllMetarules.scala

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,5 +46,7 @@ object CompileAllMetarules {
4646
CompileOnslopeCode.start(tileOrientationCache = tileOrientationCache)
4747
LOGGER.info("compiling Roundabout metarule code")
4848
CompileRoundaboutCode.start(tileOrientationCache = tileOrientationCache)
49+
LOGGER.info("compiling Viaduct metarule code")
50+
CompileViaductCode.start(tileOrientationCache = tileOrientationCache)
4951
}
5052
}

src/main/scala/module/ViaductResolver.scala

Lines changed: 64 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -29,20 +29,22 @@ object ViaductResolver {
2929

3030
0x1a00 -> Tla3, 0x1b00 -> Ave2, 0x1c00 -> Ard3,
3131
0x1d00 -> Owr1, 0x1e00 -> Owr3, 0x1f00 -> Nrd4,
32-
0x2000 -> Tla5, 0x2100 -> Owr4, 0x2180 -> Owr4m, 0x2200 -> Owr5,
32+
0x2000 -> Tla5, 0x2100 -> Owr4, 0x2b00 -> Owr4m, 0x2200 -> Owr5,
3333
0x2300 -> Rd4, 0x2400 -> Rd6, 0x2500 -> Ave6,
3434
0x2580 -> Tla7m, 0x2600 -> Ave8, 0x2680 -> Ave6m,
3535
// 0x2700 Tram-on-Street, 0x2800 Tram-in-Road, 0x2805 Tram-on-Road, 0x2a00 Tram-in-Avenue
3636
).map(_.swap))
37-
3837
}
3938

4039
class ViaductResolver extends IdResolver {
4140
def isDefinedAt(t: Tile): Boolean = tileMap.isDefinedAt(t)
4241
def apply(tile: Tile): IdTile = tileMap(tile)
4342

4443
val tileMap = {
45-
val builder = new ResolverBuilder
44+
val builder = new ResolverBuilder(
45+
// To simplify adding shared diagonals, we automatically add them for avenue-like networks going in the wrong direction.
46+
remap = (tile: Tile) => NP.transformSharedDiagonals(tile),
47+
)
4648
import builder.add
4749

4850
// curves
@@ -85,40 +87,65 @@ class ViaductResolver extends IdResolver {
8587
add(n~NS & n2~orientA(EW), id + 0x0000)
8688

8789
// O×D
88-
if (!n2.isNwm && !Viaducts.contains(n2)) {
90+
if (!Viaducts.contains(n2)) {
8991
val ne = if (n2.typ == AvenueLike) SharedDiagLeft else NE
92+
val en = if (n2.typ == AvenueLike) SharedDiagLeft else EN
93+
val ws = if (n2.typ == AvenueLike) SharedDiagLeft else WS
9094
if (n.typ == AvenueLike) {
91-
add(n~NS & n2~SW, id + 0x3000 + rev00)
92-
add(n~NS & n2~NE, id + 0x3000 + rev01, when = !n2.isSymm)
93-
add(n~NS & n2~ne, id + 0x3000 + rev10, when = !n.isSymm) // TODO Monorail swaps 0x80 and 0x00 -> model issue only
94-
// add(n~??? & n2~???, id + 0x3000 + rev11, when = !n.isSymm && (n2.typ == Asymmetrical))
95+
if (!NP.isTripleTile(n2) || !n2.isSymm) {
96+
add(n~NS & n2~SW, id + 0x3000 + rev00)
97+
add(n~NS & n2~NE, id + 0x3000 + rev01, when = !n2.isSymm)
98+
add(n~NS & n2~en, id + 0x3000 + rev10, when = !n.isSymm) // TODO Monorail swaps 0x80 and 0x00 -> model issue only
99+
add(n~NS & n2~WS, id + 0x3000 + rev11, when = !n.isSymm && (n2.typ == Asymmetrical))
100+
}
101+
if (NP.isTripleTile(n2) && n2.isSymm) {
102+
add(n~NS & n2~SW, id + 0x2F8E)
103+
add(n~NS & n2~en, id + 0x300E) // TODO Monorail swaps 0x80 and 0x00 -> model issue only
104+
}
95105
} else {
96106
add(n~NS & n2~SW, id + 0x3000 + rev00)
97-
add(n~NS & n2~ne, id + 0x3000 + rev01, when = !n2.isSymm)
107+
add(n~NS & n2~ws, id + 0x3000 + rev01, when = !n2.isSymm && (n2 != Owr4 && n2 != Owr4m))
98108
}
99109
}
100110
// D×O
101-
if (!n2.isNwm && !Viaducts.contains(n2)) {
111+
if (!Viaducts.contains(n2)) {
102112
if (n.typ == AvenueLike) {
103113
add(n~NE & n2~NS, id + 0x6000 + rev00)
104114
add(n~NE & n2~SN, id + 0x6000 + rev01, when = !n2.isSymm)
105-
add(n~SharedDiagLeft & n2~NS, id + 0x6000 + rev10, when = !n.isSymm)
106-
// add(n~??? & n2~???, id + 0x6000 + rev11, when = (n.typ == Asymmetrical) && !n2.isSymm)
115+
add(n~SharedDiagLeft & n2~NS, id + 0x6000 + rev01, when = !n.isSymm && NP.isTripleTile(n2) && n2.isSymm)
116+
add(n~SharedDiagLeft & n2~NS, id + 0x6000 + rev10, when = !n.isSymm && !NP.isTripleTile(n2))
117+
add(n~SharedDiagLeft & n2~NS, id + 0x600E, when = !n.isSymm && (NP.isTripleTile(n2) && !n2.isSymm))
118+
add(n~SharedDiagLeft & n2~SN, id + 0x6000 + rev11, when = (n.typ == Asymmetrical) && !n2.isSymm && !NP.isTripleTile(n2))
107119
} else {
108-
add(n~ES & n2~WE, id + 0x6000 + rev00)
109-
add(n~ES & n2~EW, id + 0x6000 + rev10, when = !n2.isSymm)
120+
add(n~ES & n2~EW, id + 0x6000 + rev00)
121+
add(n~ES & n2~WE, id + 0x6000 + rev01, when = !n2.isSymm)
110122
}
111123
}
112124
// D×D
113-
if (!n2.isNwm && !Viaducts.contains(n2)) {
125+
if (!Viaducts.contains(n2)) {
114126
val se = if (n2.typ == AvenueLike) SharedDiagRight else SE
127+
val es = if (n2.typ == AvenueLike) SharedDiagRight else ES
115128
if (n.typ == AvenueLike) {
116-
add(n~NE & n2~ES, id + 0x9000 + rev00)
117-
add(n~NE & n2~SharedDiagRight, id + 0x9000 + rev01, when = n2.typ == AvenueLike)
118-
add(n~SharedDiagLeft & n2~se, id + 0x9000 + rev10, when = !n.isSymm)
119-
add(n~SharedDiagLeft & n2~WN, id + 0x9000 + rev11, when = !n.isSymm && !n2.isSymm)
129+
if (!NP.isTripleTile(n2)) {
130+
add(n~NE & n2~ES, id + 0x9000 + rev00)
131+
add(n~NE & n2~se, id + 0x9000 + rev01, when = n2.typ == AvenueLike)
132+
add(n~NE & n2~se, id + 0x9000 + rev01, when = n2.typ != AvenueLike && !n2.isSymm)
133+
add(n~SharedDiagLeft & n2~se, id + 0x9000 + rev10, when = !n.isSymm)
134+
add(n~SharedDiagLeft & n2~WN, id + 0x9000 + rev11, when = !n.isSymm && !n2.isSymm)
135+
}
136+
if (!n2.isSymm && NP.isTripleTile(n2)) {
137+
add(n~NE & n2~ES, id + 0x9000 + rev00)
138+
add(n~NE & n2~se, id + 0x9000 + rev01, when = n2.typ != AvenueLike && !n2.isSymm)
139+
add(n~SharedDiagLeft & n2~se, id + 0x9000 + rev10, when = !n.isSymm)
140+
add(n~SharedDiagLeft & n2~WN, id + 0x9000 + rev11, when = !n.isSymm && !n2.isSymm)
141+
}
142+
if (n2.isSymm && NP.isTripleTile(n2)) {
143+
add(n~NE & n2~ES, id + 0x8F8E, when = n2.isSymm && NP.isTripleTile(n2))
144+
add(n~SharedDiagLeft & n2~se, id + 0x900E, when = !n.isSymm && n2.isSymm && NP.isTripleTile(n2))
145+
}
120146
} else {
121147
add(n~ES & n2~SW, id + 0x9000 + rev00)
148+
add(n~ES & n2~WS, id + 0x9000 + rev01, when = !n2.isSymm && n2.typ != AvenueLike)
122149
add(n~ES & n2~SharedDiagLeft, id + 0x9000 + rev10, when = n2.typ == AvenueLike)
123150
}
124151
}
@@ -160,6 +187,24 @@ class ViaductResolver extends IdResolver {
160187
add(0x5c080010, L2Avenue~NC & L1Avenue~CS)
161188
add(0x5c080100, L2Avenue~NC & Avenue~CS)
162189

190+
191+
add(0x5C005105, L1Road~NS & Owr4m~SE & Owr4~NW) // Owr4/Owr4m
192+
add(0x5C015105, L1Onewayroad~NS & Owr4m~SE & Owr4~NW) // Owr4/Owr4m
193+
add(0x5C02510E, L1Avenue~NS & Owr4m~SE & Owr4~NW) // Owr4/Owr4m
194+
add(0x5C02518E, L1Avenue~NS & Owr4m~WS & Owr4~EN) // Owr4/Owr4m
195+
add(0x5C035105, L2Road~NS & Owr4m~SE & Owr4~NW) // Owr4/Owr4m
196+
add(0x5C045105, L2Onewayroad~NS & Owr4m~SE & Owr4~NW) // Owr4/Owr4m
197+
add(0x5C05510E, L2Avenue~NS & Owr4m~SE & Owr4~NW) // Owr4/Owr4m
198+
add(0x5C05518E, L2Avenue~NS & Owr4m~WS & Owr4~EN) // Owr4/Owr4m
199+
add(0x5C00B105, L1Road~ES & Owr4m~WS & Owr4~EN) // Owr4/Owr4m
200+
add(0x5C01B105, L1Onewayroad~ES & Owr4m~WS & Owr4~EN) // Owr4/Owr4m
201+
add(0x5C02B105, L1Avenue~NE & Owr4m~SE & Owr4~NW) // Owr4/Owr4m
202+
add(0x5C02B180, L1Avenue~SharedDiagLeft & Owr4m~SE & Owr4~NW) // Owr4/Owr4m
203+
add(0x5C03B105, L2Road~ES & Owr4m~WS & Owr4~EN) // Owr4/Owr4m
204+
add(0x5C04B105, L2Onewayroad~ES & Owr4m~WS & Owr4~EN) // Owr4/Owr4m
205+
add(0x5C05B105, L2Avenue~NE & Owr4m~SE & Owr4~NW) // Owr4/Owr4m
206+
add(0x5C05B180, L2Avenue~SharedDiagLeft & Owr4m~SE & Owr4~NW) // Owr4/Owr4m
207+
163208
builder.result()
164209
}
165210
}
Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package com.sc4nam.module
2+
3+
import io.github.memo33.metarules.meta._, syntax._
4+
import Network._, Flags._, Flag._, RotFlip._, Implicits._, group.SymGroup._
5+
import NetworkProperties._
6+
7+
class ViaductRuleGenerator(var context: RuleTransducer.Context) extends RuleGenerator with Curve45Generator with CrossingGenerator {
8+
9+
def start(): Unit = {
10+
for (main <- Viaducts; base <- main.base) {
11+
Rules += main~WE | (base ~> main)~WE // ortho
12+
Rules += main~WE | (base ~> main)~WC // ortho stub
13+
withSharedDiagonals {
14+
Rules += main~SE~ES | (base ~> main)~WN~NW // diagonal
15+
}
16+
// curves
17+
createCurve45Rules(main)
18+
createCurve90Rules(main)
19+
20+
// crossings (O×O, O×D, D×O, D×D)
21+
for (minor <- CrossingGenerator.crossingNetworksOf(main)) {
22+
createCrossingRules(main, minor)
23+
}
24+
}
25+
}
26+
}
27+
28+
// Compile individually with `sbt "runMain com.sc4nam.module.CompileViaductCode"`.
29+
object CompileViaductCode extends AbstractMain {
30+
lazy val resolve: IdResolver = new MiscResolver orElse new RealRailwayResolver orElse new RhwResolver orElse new NwmResolver orElse new ViaductResolver
31+
val generator = new ViaductRuleGenerator(_)
32+
lazy val file = new java.io.File("target/ViaductMetaGenerated_MANAGED.txt")
33+
}

0 commit comments

Comments
 (0)