diff options
Diffstat (limited to 'src/config.zig')
-rw-r--r-- | src/config.zig | 41 |
1 files changed, 12 insertions, 29 deletions
diff --git a/src/config.zig b/src/config.zig index 2e028f1..d204ead 100644 --- a/src/config.zig +++ b/src/config.zig @@ -18,23 +18,27 @@ const Dir = std.fs.Dir; const File = std.fs.File; -const Key = @import("gfz").Key; +const IntegerBitSet = std.bit_set.IntegerBitSet; const allocator = std.heap.c_allocator; -const c = @import("main.zig").c; const cwd = std.fs.cwd; -const data_dir = @import("build_options").data_dir; +const endian = @import("builtin").target.cpu.arch.endian(); const eql = std.mem.eql; -const ini = @import("ini"); const join = std.fs.path.join; const maxInt = std.math.maxInt; const mkdir = std.os.mkdir; -const parseBool = @import("misc.zig").parseBool; const parseFloat = std.fmt.parseFloat; const parseInt = std.fmt.parseInt; const std = @import("std"); const stringToEnum = std.meta.stringToEnum; const tokenize = std.mem.tokenize; +const Key = @import("gfz").Key; +const ini = @import("ini"); + +const data_dir = @import("build_options").data_dir; +const c = @import("cimport.zig"); +const parseBool = @import("misc.zig").parseBool; + const default_levels_len = 13; /// Open the given file for reading, @@ -58,18 +62,6 @@ const Level = extern struct { difficulty: f32, }; -const Weapons = packed struct { - // TODO: remove nogun and sort - jaw: bool = false, - sniper_rifle: bool = false, - assault_rifle: bool = false, - magnum: bool = false, - handgun: bool = false, - grenade: bool = false, - knife: bool = false, - shotgun: bool = false, -}; - fn parseLevels(dir_path: []const u8, length: usize) ![*]Level { var dir = try cwd().makeOpenPath(dir_path, .{}); defer dir.close(); @@ -99,20 +91,11 @@ fn parseLevels(dir_path: []const u8, length: usize) ![*]Level { c.night_environment else return error.InvalidData; } else if (eql(u8, kv.key, "evil weapons")) { - var weapons = Weapons{}; + var weapons = IntegerBitSet(8).initEmpty(); var enums = tokenize(kv.value, " "); while (enums.next()) |weapon| - switch (try parseInt(u3, weapon, 10)) { - c.nogun => weapons.jaw = true, - c.sniperrifle => weapons.sniper_rifle = true, - c.assaultrifle => weapons.assault_rifle = true, - c.handgun1 => weapons.magnum = true, - c.handgun2 => weapons.handgun = true, - c.grenade => weapons.grenade = true, - c.knife => weapons.knife = true, - c.shotgun => weapons.shotgun = true, - }; - levels[i].evil_weapons = @bitCast(u8, weapons); + weapons.set(try parseInt(u3, weapon, 10)); + levels[i].evil_weapons = weapons.mask; } else if (eql(u8, kv.key, "evil rarity")) { levels[i].evil_rarity = try parseInt(u8, kv.value, 10); } else if (eql(u8, kv.key, "guard weapon")) { |