summaryrefslogtreecommitdiff
path: root/includes/bitset.inc
blob: f45beb17871897d0f154f700140d9d7e3aca9d26 (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
<?php

function parseBitset ($bitset) {
    $bin = str_repeat("0", 48 - strlen(decbin($bitset))) . decbin($bitset);

    $sharedMemory = bindec(substr($bin, 24, 2));
    $little = bindec(substr($bin, 27, 2));
    $food = bindec(substr($bin, 16, 2));
    $nonverbal = substr($bin, 15, 1) !== "0";
    $lessFrequent = substr($bin, 14, 1) !== "0";
    $sexuallyActive = substr($bin, 13, 1) !== "0";
    $leader = substr($bin, 11, 1) !== "0";
    $persecutor = substr($bin, 10, 1) !== "0";
    $protector = substr($bin, 29, 1) !== "0";
    $fictive = substr($bin, 30, 1) !== "0";
    $robot = substr($bin, 45, 1) !== "0";
    $plush = substr($bin, 46, 1) !== "0";
    $polyamorous1 = substr($bin, 18, 1) !== "0";
    $polyamorous2 = substr($bin, 19, 1) !== "0";
    $species1 = substr($bin, 33, 4);
    $species2 = substr($bin, 37, 4);
    $alignment1 = substr($bin, 41, 4);
    $alignment2 = substr($bin, 20, 4);

    $species1 = match ($species1) {
        "0001" => "earth",
        "0010" => "unicorn",
        "0011" => "pegasus",
        "0100" => "alicorn",
        "0101" => "batpony",
        "0110" => "crystal",
        "0111" => "changeling",
        default => null,
    };

    $species2 = match ($species2) {
        "0001" => "earth",
        "0010" => "unicorn",
        "0011" => "pegasus",
        "0100" => "alicorn",
        "0101" => "batpony",
        "0110" => "crystal",
        "0111" => "changeling",
        default => null,
    };

    $alignment1 = match ($alignment1) {
        "0000" => "aroace",
        "0001" => "hetero",
        "0010" => "homo",
        "0011" => "bi",
        "0100" => "pan",
        default => null,
    };

    $alignment2 = match ($alignment2) {
        "0000" => "aroace",
        "0001" => "hetero",
        "0010" => "homo",
        "0011" => "bi",
        "0100" => "pan",
        default => null,
    };

    if ($little === 1) $little = 0;

    return [
        'shared_memory' => $sharedMemory,
        'median' => false,
        'protector' => $protector,
        'fictive' => $fictive,
        'little' => $little,
        'not_talking' => false,
        'host' => false,
        'robot' => $robot,
        'magic' => 0,
        'sensitivity' => 0,
        'food' => $food,
        'plush' => $plush,
        'nonverbal' => $nonverbal,
        'less_frequent' => $lessFrequent,
        'age_spells' => false,
        'age_regressor' => false,
        'leader' => $leader,
        'persecutor' => $persecutor,
        'sexually_active' => $sexuallyActive,
        'polyamorous' => [
            'romantic' => $polyamorous1,
            'sexual' => $polyamorous2
        ],
        'alignment' => [
            'romantic' => $alignment1,
            'sexual' => $alignment2
        ],
        'species' => array_filter([
            $species1,
            $species2
        ], function ($i) {
            return isset($i);
        })
    ];
}

function parseMetadata ($metadata) {
    if (isset($metadata)) {
        if ($metadata["bitset"]) {
            $m = parseBitset($metadata["bitset"]);
            $m["marefriends"] = $metadata["marefriends"] ?? [];
            $m["bitset"] = $metadata["bitset"] ?? 0;
            $m["sisters"] = $metadata["sisters"] ?? [];
            $m["regression"] = $metadata["regression"] ?? null;
            $m["caretakers"] = $metadata["caretakers"] ?? [];
            $m["median"] = $metadata["median"] ?? null;
            $m["birth"] = $metadata["birth"] ?? null;
            $m["heat"] = $metadata["heat"] ?? null;
            $m["code"] = $metadata["code"] ?? null;
        } else {
            $m = $metadata;
        }

        return $m;
    } else {
        return $metadata;
    }
}