summaryrefslogtreecommitdiff
path: root/tools/gendata.js
blob: 317c565b2be71f2e1bd2bea6a10f46a15a8c8d65 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
"use strict"

const fs = require("fs")

let data = {}

const RURAL = 1
const URBAN = 2
const REMOTE = 3
const COUNTRY = 4

let locations = {}
let areas = []
let zone_areas = {}
let next_location_id = 0

function def_area(id, name, type, zone, x, y, w, h) {
    let loc = next_location_id++
    areas.push({loc, id, name, type, zone, x, y, w, h})
    if (zone) {
        if (!(zone in zone_areas)) {
            zone_areas[zone] = []
        }
        zone_areas[zone].push(loc)
    }
}

// special locations
def_area("NONE", "None")
def_area("DEPLOY", "Deployment")
def_area("ELIMINATED", "Eliminated")

// countries
def_area("FRANCE", "France", COUNTRY, null, 1690.3, 244.8, 94, 94)
def_area("TUNISIA", "Tunisia", COUNTRY, "TUNISIA", 2499.9, 1667.6, 94, 94)
def_area("MOROCCO", "Morocco", COUNTRY, "MOROCCO", 109, 1765, 94, 94)

def_area("I-1", "Barika", RURAL, "I", 1708.1, 1117.9)
def_area("I-2", "Batna", REMOTE, "I", 2185.6, 1390.9)
def_area("I-3", "Biskra", REMOTE, "I", 1853.6, 1620.9)
def_area("I-4", "Tebessa", RURAL, "I", 2299.6, 1120.9)

def_area("CONSTANTINE", "Constantine", URBAN, "II", 2066.6, 315.8)
def_area("II-1", "Setif", RURAL, "II", 1917.6, 800.8)
def_area("II-2", "Phillippeville", RURAL, "II", 2200.6, 584.9)
def_area("II-3", "Souk Ahras", RURAL, "II", 2347.6, 848.9)

def_area("III-1", "Tizi Ouzou", RURAL, "III", 1473.6, 578.9)
def_area("III-2", "Bordj Bou Arreridj", RURAL, "III", 1465.6, 832.9)
def_area("III-3", "Bougie", RURAL, "III", 1703.6, 616.9)

def_area("ALGIERS", "Algiers", URBAN, "IV", 1185.6, 346.8)
def_area("IV-1", "Medea", RURAL, "IV", 1212, 727)
def_area("IV-2", "Orleansville", RURAL, "IV", 982, 780.2)

def_area("ORAN", "Oran", URBAN, "V", 430.6, 588.8)
def_area("V-1", "Mecheria", REMOTE, "V", 234, 1485.7)
def_area("V-2", "Tlemcen", RURAL, "V", 173, 1140.9)
def_area("V-3", "Sidi Bel Abbes", RURAL, "V", 476, 1038)
def_area("V-4", "Mostaganem", RURAL, "V", 741, 863.9)
def_area("V-5", "Saida", REMOTE, "V", 501, 1419.1)
def_area("V-6", "Mascara", REMOTE, "V", 785, 1302.9)
def_area("V-7", "Ain Sefra", REMOTE, "V", 752, 1670.9)
def_area("V-8", "Laghouat", REMOTE, "V", 1191, 1615.6)

def_area("VI-1", "Sidi Aissa", REMOTE, "VI", 1385, 1186)
def_area("VI-2", "Ain Qussera", RURAL, "VI", 1070.6, 1235.6)

let adjecents = {}

function def_adjecent(id, neighbours) {
    function add_adjecent(from, to) {
        const from_id = locations[from]
        if (!(from_id in adjecents)) {
            adjecents[from_id] = []
        }
        adjecents[from_id].push(locations[to])
    }
    for (const n of neighbours) {
        add_adjecent(id, n)
        add_adjecent(n, id)
    }
}

// only adjecent with neighbour zones are tracked, defined one way but they are bidirectional
def_adjecent("TUNISIA", ["I-2", "I-3", "I-4", "II-3"])
def_adjecent("MOROCCO", ["V-1", "V-2", "V-7"])

def_adjecent("I-1", ["II-1", "III-2", "VI-1"])
def_adjecent("I-3", ["V-8", "VI-1"])
def_adjecent("I-4", ["II-1", "II-2", "II-3"])

def_adjecent("II-1", ["III-2", "III-3"])

def_adjecent("III-1", ["IV-1"])
def_adjecent("III-2", ["IV-1", "VI-1"])

def_adjecent("IV-1", ["VI-1", "VI-2"])
def_adjecent("IV-2", ["V-4", "VI-2"])

def_adjecent("V-4", ["VI-2"])
def_adjecent("V-6", ["VI-2"])
def_adjecent("V-8", ["VI-1", "VI-2"])

data.locations = locations
data.areas = areas
data.zone_areas = zone_areas
data.adjecents = adjecents

let units = []

const FLN = 0
const GOV = 1

// unit types

const FR_XX = 0
const FR_X = 1
const EL_X = 2
const AL_X = 3
const POL = 4
const FAILEK = 5
const BAND = 6
const CADRE = 7
const FRONT = 8

function def_unit(side, type, name, klass, count = 1) {
    for (let i = 0; i < count; ++i) {
        units.push({side, type, name, class: klass})
    }
}

def_unit(GOV, FR_XX, "French 2nd division", "fr_xx_2")
def_unit(GOV, FR_XX, "French 4th division", "fr_xx_4")
def_unit(GOV, FR_XX, "French 9th division", "fr_xx_9")
def_unit(GOV, FR_XX, "French 12th division", "fr_xx_12")
def_unit(GOV, FR_XX, "French 13th division", "fr_xx_13")
def_unit(GOV, FR_XX, "French 14th division", "fr_xx_14")
def_unit(GOV, FR_XX, "French 19th division", "fr_xx_19")
def_unit(GOV, FR_XX, "French 20th division", "fr_xx_20")
def_unit(GOV, FR_XX, "French 21th division", "fr_xx_21")
def_unit(GOV, FR_XX, "French 29th division", "fr_xx_29")

def_unit(GOV, FR_XX, "French 27th division", "fr_xx_27")
def_unit(GOV, FR_XX, "French 5th division", "fr_xx_5")
def_unit(GOV, FR_XX, "French 7th division", "fr_xx_7") // rules errata: - The French light mechanized division (circle with slash through it) should be numbered "7", not "2"

def_unit(GOV, FR_X, "French brigade", "fr_x", 4)
def_unit(GOV, EL_X, "French elite brigade", "fr_elite_x_para", 3)
def_unit(GOV, EL_X, "French elite brigade", "fr_elite_x_inf")
def_unit(GOV, EL_X, "French elite brigade", "fr_elite_x_marine", 3)

def_unit(GOV, AL_X, "Algerian brigade", "alg_x", 6)
def_unit(GOV, POL, "Police", "alg_police", 10)

def_unit(FLN, FAILEK, "Failek", "fln_failek", 10)
def_unit(FLN, BAND, "Band", "fln_band", 24)
def_unit(FLN, CADRE, "Cadre", "fln_cadre", 30)
def_unit(FLN, FRONT, "Front", "fln_front", 16)

console.log("const area_count =", areas.length)
console.log("const unit_count =", units.length)
console.log("const first_gov_unit =", units.findIndex((u) => u.side === GOV))
console.log("const last_gov_unit =", units.findLastIndex((u) => u.side === GOV))
console.log("const first_fln_unit =", units.findIndex((u) => u.side === FLN))
console.log("const last_fln_unit =", units.findLastIndex((u) => u.side === FLN))

data.units = units

fs.writeFileSync("data.js", "const data = " + JSON.stringify(data, 0, 0) + "\nif (typeof module !== 'undefined') module.exports = data\n")