-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathflag-definitions.js
116 lines (107 loc) · 4.38 KB
/
flag-definitions.js
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
"use strict"
const AbilityData = new Map(require('./data/AbilityData.json'));
const UnitBalance = new Map(require('./data/UnitBalance.json'));
const UnitData = new Map(require('./data/UnitData.json'));
const UnitWeapons = new Map(require('./data/UnitWeapons.json'));
const UpgradeData = new Map(require('./data/UpgradeData.json'));
const UnitFunc = new Map(require('./data/UnitFunc.json'));
const UnitStrings = new Map(require('./data/UnitStrings.json'));
function objectCostsToSource() {
let output = [];
for (const [id, {goldcost, lumbercost, prev}] of UnitBalance) {
if (goldcost) output.push(`call SaveInteger(udg_RFObjectCost, 0, '${id}', ${goldcost})`);
if (lumbercost) output.push(`call SaveInteger(udg_RFObjectCost, 1, '${id}', ${lumbercost})`);
if (prev) { // Delta = Upgrade cost
output.push(`call SaveInteger(udg_RFObjectCost, 2, '${id}', ${goldcost - UnitBalance.get(prev).goldcost})`);
output.push(`call SaveInteger(udg_RFObjectCost, 3, '${id}', ${lumbercost - UnitBalance.get(prev).lumbercost})`);
}
}
for (const [id, {goldbase, goldmod, lumberbase, lumbermod}] of UpgradeData) {
if (goldbase) output.push(`call SaveInteger(udg_RFObjectCost, 0, '${id}', ${goldbase})`);
if (lumberbase) output.push(`call SaveInteger(udg_RFObjectCost, 1, '${id}', ${lumberbase})`);
if (goldmod) output.push(`call SaveInteger(udg_RFObjectCost, 2, '${id}', ${goldmod})`);
if (lumbermod) output.push(`call SaveInteger(udg_RFObjectCost, 3, '${id}', ${lumbermod})`);
}
return output.map((x, i) => i ? ` `.repeat(4) + x : x).join(`\r\n`);
}
function objectNamesToSource() {
let output = [];
let openingUnits = new Set([
'hfoo', 'hrif', 'ogru', 'ohun',
'ugho', 'ucry', 'earc', 'esen',
]);
for (const [id, {Name}] of UnitStrings) {
if (!Name) continue;
let targetType = UnitData.get(id)?.targType;
let race = UnitData.get(id)?.race;
let classification = UnitData.get(id)?.type;
let defType = UnitBalance.get(id)?.defType;
if (id[0] === 'R' || id === 'ugol' || id === 'egol' || targetType === 'structure' || defType === 'hero' ||
classification?.includes('TownHall') || classification?.includes('Peon') || openingUnits.has(id) ||
race === 'human' || race === 'undead' || race === 'nightelf' || race === 'orc') {
let names = Name.split(',');
for (let i = 0; i < names.length; i++) {
output.push(`call SaveStringBJ(${JSON.stringify(names[i])}, '${id}', ${i}, udg_RFObjectName)`);
}
}
}
return output.map((x, i) => i ? ` `.repeat(4) + x : x).join(`\r\n`);
}
function sunderingUnitsToSource() {
let output = [];
for (const [id, {defType}] of UnitBalance) {
if (defType === 'medium') output.push(`call SaveInteger(udg_RFSunderingUnits, 0, '${id}', 1)`);
}
return output.map(x => ` `.repeat(4) + x).join(`\r\n`);
}
function meleeUnitsToSource() {
let output = [];
/*for (const [id, {weapsOn, rangeN1, rangeN2, targs1, targs2}] of UnitWeapons) {*/
for (const [id, {movetp}] of UnitData) {
if (!UnitWeapons.has(id)) {
continue; // nmrf
}
if (movetp === 'foot' || movetp === 'horse' || movetp === 'hover' || movetp === 'float') {
const {weapsOn, rangeN1, rangeN2} = UnitWeapons.get(id);
if ((weapsOn & 1) && rangeN1 < 128 || (weapsOn & 2) && rangeN2 < 128) {
output.push(`call SaveInteger(udg_RFMeleeUnits, 0, '${id}', 1)`);
}
}
}
return output.map((x, i) => i ? ` `.repeat(4) + x : x).join(`\r\n`);
}
function heroAbilitiesToSource() {
let output = [];
for (const [id, {hero}] of AbilityData) {
if (hero) {
output.push(`call SaveInteger(udg_RFHeroAbilities, 0, '${id}', 1)`);
}
}
return output.map((x, i) => i ? ` `.repeat(4) + x : x).join(`\r\n`);
}
function unitButtonsToSource() {
let output = [];
for (const [id, {Art}] of UnitStrings) {
if (Art) {
output.push(`call SaveStringBJ(${JSON.stringify(Art)}, '${id}', 0, udg_RFUnitButtons)`);
}
}
return output.map((x, i) => i ? ` `.repeat(4) + x : x).join(`\r\n`);
}
const cachedSources = new Map();
function cached(fn) {
return function () {
if (cachedSources.has(fn)) return cachedSources.get(fn);
const result = fn();
cachedSources.set(fn, result);
return result;
};
}
module.exports = {
objectCostsToSource: cached(objectCostsToSource),
objectNamesToSource: cached(objectNamesToSource),
sunderingUnitsToSource: cached(sunderingUnitsToSource),
meleeUnitsToSource: cached(meleeUnitsToSource),
heroAbilitiesToSource: cached(heroAbilitiesToSource),
unitButtonsToSource: cached(unitButtonsToSource),
};