#include "game_types.h"

/* Collectible_Init @ 0x08000F9C (real 130B) -- initializes 5 collectible bar slots with count select. Mirrors src/matched/Collectible_Init.c. */
/* Initializes 5 slots (+84 zeroed, +104 values, +124 shifted window copy),
   selecting values by the count at +168 (small-count lerp vs big-count
   230-form), then sets byte 164. Sibling of Collectible_Init2. */
void Collectible_Init(int *p)
{
    int i = 0;
    int ip = -8;
    int x = 238;
    int off = 0;
    do {
        int v, n;
        *(int *)((char *)p + 84 + off) = 0;
        n = *(int *)((char *)p + 168);
        if (n > 5) {
            if (i == 0)
                v = 230 - (n > 9 ? 16 : 8);
            else
                v = ip + 240;
        } else if (i < n) {
            v = x - n * 8;
        } else {
            v = (i - n) * 8;
        }
        *(int *)((char *)p + 104 + off) = v;
        *(int *)((char *)p + 124 + off) =
            *(int *)((char *)p + 144 + off);
        ip += 8;
        x += 8;
        off += 4;
        i++;
    } while (i <= 4);
    ((char *)p)[164] = 1;
}
