`RandomChance` type, and two new item fields: `MagicEffectChance`, `MagicEffectDuration`
[k8-i-v-a-n.git] / utils / idatool.d
blob3239c4fdbfd912dad0eec7c6e3219673b14d91c8
1 /* coded by Ketmar // Invisible Vector <ketmar@ketmar.no-ip.org>
2 * Understanding is not required. Only obedience.
4 * This program is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 module idatool is aliced;
19 import std.path : buildPath;
21 import iv.cmdcon;
22 import iv.strex;
23 import iv.vfs.io;
25 import parser;
28 // ////////////////////////////////////////////////////////////////////////// //
29 __gshared string commIvanRoot = "/home/ketmar/k8prj/I.V.A.N./_community/_git";
30 __gshared string k8IvanRoot = "/home/ketmar/k8prj/I.V.A.N.";
31 __gshared bool optIgnoreDups = false;
34 // ////////////////////////////////////////////////////////////////////////// //
35 VFile findAndOpenDat(string type) (const(char)[] fname) if (type == "k8" || type == "comm") {
36 try {
37 static if (type == "k8") auto fl = VFile(buildPath(k8IvanRoot, "script", fname));
38 else static if (type == "comm") auto fl = VFile(buildPath(commIvanRoot, "script", fname));
39 else static assert(0, "i am just a safeguard");
40 return fl;
41 } catch (Exception e) {}
42 try {
43 auto fl = VFile(buildPath("script", fname));
44 return fl;
45 } catch (Exception e) {}
46 throw new Exception("dat file '"~fname.idup~"' not found");
50 // ////////////////////////////////////////////////////////////////////////// //
51 SimpleDefList loadlist (VFile fl) {
52 auto res = new SimpleDefList();
53 res.parse(fl, optIgnoreDups);
54 return res;
58 // ////////////////////////////////////////////////////////////////////////// //
60 SimpleDefList loadk8listdir (string path) {
61 import std.file;
62 auto defs = new SimpleDefList();
63 foreach (DirEntry de; dirEntries(path, "*.dat", SpanMode.shallow)) {
64 if (!de.isFile) continue;
65 defs.parse(VFile(de.name));
67 if (defs.maindef is null) assert(0, "k8: main def not found");
68 return defs;
73 // ////////////////////////////////////////////////////////////////////////// //
74 SimpleDefList loadk8list (VFile fl) {
75 import std.file;
76 auto defs = new SimpleDefList();
77 defs.parse(new IvanParser(fl), optIgnoreDups);
78 if (defs.maindef is null) assert(0, "k8: main def not found");
79 return defs;
83 // ////////////////////////////////////////////////////////////////////////// //
84 void diffDefs (SimpleDefList d0, SimpleDefList d1) {
85 bool[string] hit;
86 foreach (SimpleDef def; d0.defs.byValue) {
87 if (def.name !in d1.defs) continue;
88 hit[def.name] = true;
89 auto diff = def.diff(d1.defs[def.name]);
90 if (diff.length) {
91 writeln("======== ", def.name, " ========");
92 foreach (string s; diff) writeln(s);
93 writeln;
99 // ////////////////////////////////////////////////////////////////////////// //
100 void diffItems () {
101 auto itdefs = loadlist(findAndOpenDat!"comm"("item.dat"));
102 auto mydefs = loadk8list(findAndOpenDat!"k8"("item.dat"));
103 diffDefs(mydefs, itdefs);
107 // ////////////////////////////////////////////////////////////////////////// //
108 void diffChars () {
109 auto itdefs = loadlist(findAndOpenDat!"comm"("char.dat"));
110 auto mydefs = loadk8list(findAndOpenDat!"k8"("char.dat"));
111 diffDefs(mydefs, itdefs);
115 // ////////////////////////////////////////////////////////////////////////// //
116 void checkBrokenConfigs (SimpleDefList list) {
117 foreach (SimpleDef def; list.defs) {
118 if (def.name == "potion") continue; // potions always morphed into brokenbottle
119 foreach (SimpleConfig cfg; def.configs) {
120 if (cfg.broken) continue;
121 // skip abstract definitions
122 auto fld = cfg["IsAbstract"];
123 if (fld !is null && fld.asBool) continue;
124 fld = list[def.name, cfg.name, "CanBeBroken"];
125 if (fld is null || !fld.asBool) continue;
126 if (!def.hasBrokenConfig(cfg.name)) writeln("WARNING: NO BROKEN CONFIG FOR ", def.name, " : ", cfg.name);
127 //writeln(def.name, " : ", cfg.name);
133 // ////////////////////////////////////////////////////////////////////////// //
134 void main (string[] args) {
135 vfsIgnoreCaseDisk = true;
137 conRegVar!commIvanRoot("comm_root", "community fork root dir");
138 conRegVar!k8IvanRoot("k8_root", "k8 fork root dir");
139 conRegVar!optIgnoreDups("p_ignore_dups", "don't fail on duplicates");
141 conProcessQueue(); // load config
142 conProcessArgs!true(args);
144 enum Action { None, DiffItems, DiffChars, CheckBrokenComm, CheckBrokenK8 }
146 Action action = Action.None;
148 foreach (string arg; args[1..$]) {
149 switch (arg) {
150 case "diff-items":
151 if (action != Action.None) assert(0, "duplicate action");
152 action = Action.DiffItems;
153 break;
154 case "diff-chars":
155 if (action != Action.None) assert(0, "duplicate action");
156 action = Action.DiffChars;
157 break;
158 case "check-broken-comm":
159 if (action != Action.None) assert(0, "duplicate action");
160 action = Action.CheckBrokenComm;
161 break;
162 case "check-broken-k8":
163 if (action != Action.None) assert(0, "duplicate action");
164 action = Action.CheckBrokenK8;
165 break;
166 default:
167 assert(0, "unknown command: '"~arg~"'");
171 if (action == Action.None) assert(0, "sorry, i don't know what to do.");
173 writeln("k8 I.V.A.N. root : ", k8IvanRoot);
174 writeln("comm I.V.A.N. root: ", commIvanRoot);
176 final switch (action) {
177 case Action.None: assert(0, "the thing that should not be");
178 case Action.DiffItems:
179 writeln("************* DIFF ITEMS *************");
180 diffItems();
181 break;
182 case Action.DiffChars:
183 writeln("************* DIFF CHARS *************");
184 diffChars();
185 break;
186 case Action.CheckBrokenComm:
187 writeln("************* CHECKING CHARS IN COMM FORK *************");
188 loadlist(findAndOpenDat!"comm"("char.dat"));
189 writeln("************* CHECKING BROKEN ITEM CONFIGS IN COMM FORK *************");
190 checkBrokenConfigs(loadlist(findAndOpenDat!"comm"("item.dat")));
191 break;
192 case Action.CheckBrokenK8:
193 writeln("************* CHECKING CHARS IN K8 FORK *************");
194 loadk8list(findAndOpenDat!"k8"("char.dat"));
195 writeln("************* CHECKING BROKEN ITEM CONFIGS IN K8 FORK *************");
196 checkBrokenConfigs(loadk8list(findAndOpenDat!"k8"("item.dat")));
197 break;