Debian Codegraph @

src/uk/me/parabola/imgfmt/app/lbl/Highway.java

raw symbols SCIP
1 /*
2 * Copyright (C) 2007 Steve Ratcliffe
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation.
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 *
14 * Author: Steve Ratcliffe
15 * Create date: Jan 1, 2008
16 */
17 package uk.me.parabola.imgfmt.app.lbl;
18
19 import java.util.ArrayList;
20 import java.util.List;
21
22 import uk.me.parabola.imgfmt.app.ImgFileWriter;
23 import uk.me.parabola.imgfmt.app.Label;
24 import uk.me.parabola.imgfmt.app.trergn.Subdivision;
25
26 /**
27 * A highway is in a region.
28 *
29 * @author Mark Burton
30 */
31 public class Highway {
32
33 class ExitPoint implements Comparable<ExitPoint> {
34 final String name;
35 final int index;
36 final Subdivision div;
37 public ExitPoint(String name, int index, Subdivision div) {
38 this.name = name;
39 this.index = index;
40 this.div = div;
41 }
42
43 public int compareTo(ExitPoint o) {
44 return name.compareTo(o.name);
45 }
46 }
47
48 private final int index;
49
50 private final Region region;
51
52 private final List<ExitPoint> exits = new ArrayList<>();
53
54 private Label label;
55
56 private int extraDataOffset; // in 3-byte records - 1 based
57
58 public Highway(Region region, int index) {
59 this.region = region;
60 this.index = index;
61 }
62
63 void write(ImgFileWriter writer, boolean extraData) {
64 if(extraData) {
65 writer.put1u(0);
66 writer.put2u(region == null? 0 : region.getIndex());
67 exits.sort(null);
68 for(ExitPoint ep : exits) {
69 writer.put1u(ep.index);
70 writer.put2u(ep.div.getNumber());
71 }
72 }
73 else {
74 assert extraDataOffset != 0;
75 writer.put3u(label.getOffset());
76 writer.put2u(extraDataOffset);
77 writer.put1u(0); // unknown (setting any of 0x3f stops exits being found)
78 }
79 }
80
81 public int getIndex() {
82 return index;
83 }
84
85 public void setLabel(Label label) {
86 this.label = label;
87 }
88
89 public void setExtraDataOffset(int extraDataOffset) {
90 this.extraDataOffset = extraDataOffset / 3 + 1;
91 }
92
93 public int getExtraDataSize() {
94 return (1 + exits.size()) * 3;
95 }
96
97 public void addExitPoint(String name, int index, Subdivision div) {
98 exits.add(new ExitPoint(name, index, div));
99 }
100 }