summary refs log tree commit diff
path: root/src/config.zig
diff options
context:
space:
mode:
authorNguyễn Gia Phong <mcsinyx@disroot.org>2021-10-29 18:27:46 +0700
committerNguyễn Gia Phong <mcsinyx@disroot.org>2021-10-29 18:31:49 +0700
commit2432be0c7f788270221b6f9eaf3f765b6118d8c2 (patch)
treeb69df71ede09554c6c8792b96f598b486a982832 /src/config.zig
parent6b871944a9b2df0f84cbe3682244e07cb415fe79 (diff)
downloadblackshades-2.4.3.tar.gz
Sort imports and clean up 2.4.3
Diffstat (limited to 'src/config.zig')
-rw-r--r--src/config.zig41
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")) {