Files
factorygame/tiles/miner.c
2025-06-07 00:57:00 +02:00

48 lines
1.7 KiB
C

//
// Created by bruno on 2.6.2025.
//
#include "miner.h"
#include "tile.h"
#include "../util/audio.h"
const ItemType MinerRecipes[TILEREGISTRY_SIZE] = {
[BGType_IRON_ORE] = IRON_ORE,
[BGType_SILVER_ORE] = SILVER_ORE,
[BGType_GOLD_ORE] = GOLD_ORE,
[BGType_PLATINUM_ORE] = PLATINUM_ORE
};
void updateMiner(Tile *tile) {
ItemOnBelt *outItem = &tile->items[MINER_OUTPUT_SLOT];
BackgroundType bgt = backgroundMap[tile->rect.y][tile->rect.x].type;
ItemType targetOutItemType = MinerRecipes[bgt];
Item targetOutItem = ItemRegistry[targetOutItemType];
if (targetOutItemType != TYPE_AIR && outItem->type == 0) {
if (tile->miscVal == 0) {
tile->audioCh = getAvailableChannel();
tile->fixedFrame = 0;
if (tile->audioCh < NUM_SYNTH_VOICES) {
audioData.synthVoices[tile->audioCh].volume = 64;
audioData.synthVoices[tile->audioCh].phase = 0;
audioData.synthVoices[tile->audioCh].sourceRect.x = TILE_SIZE * tile->rect.x;
audioData.synthVoices[tile->audioCh].sourceRect.y = TILE_SIZE * tile->rect.y;
audioData.synthVoices[tile->audioCh].waveform = WAVE_NOISE;
audioData.synthVoices[tile->audioCh].frequency = 400;
}
}
if (outItem->type == 0 && ++tile->miscVal >= targetOutItem.miscVal) {
if (tile->audioCh < NUM_SYNTH_VOICES) {
audioData.synthVoices[tile->audioCh].volume = 0;
}
tile->fixedFrame = 1;
tile->miscVal = 0;
outItem->type = targetOutItemType;
outItem->offset = -0.5f;
}
} else {
tile->fixedFrame = 1;
}
}