51 lines
1.7 KiB
C
51 lines
1.7 KiB
C
//
|
|
// Created by bruno on 31.5.2025.
|
|
//
|
|
|
|
#include "furnace.h"
|
|
#include "tile.h"
|
|
#include "../util/audio.h"
|
|
|
|
const ItemType FurnaceRecipes[ITEMREGISTRY_SIZE] = {
|
|
[IRON_ORE] = IRON_INGOT,
|
|
[SILVER_ORE] = SILVER_INGOT,
|
|
[GOLD_ORE] = GOLD_INGOT,
|
|
[PLATINUM_ORE] = PLATINUM_INGOT
|
|
};
|
|
|
|
|
|
void updateFurnace(Tile *tile) {
|
|
ItemOnBelt *inItem = &tile->items[FURNACE_INPUT_SLOT];
|
|
ItemOnBelt *outItem = &tile->items[FURNACE_OUTPUT_SLOT];
|
|
Item inItemType = ItemRegistry[inItem->type];
|
|
|
|
ItemType targetOutItemType = FurnaceRecipes[inItem->type];
|
|
|
|
Item targetOutItem = ItemRegistry[targetOutItemType];
|
|
|
|
if (targetOutItemType != TYPE_AIR) {
|
|
if (tile->miscVal == 0) {
|
|
tile->audioCh = getAvailableChannel();
|
|
if (tile->audioCh < NUM_SYNTH_VOICES) {
|
|
audioData.synthVoices[tile->audioCh].volume = 1;
|
|
audioData.synthVoices[tile->audioCh].phase = 0;
|
|
audioData.synthVoices[tile->audioCh].sourceRect.x = TILE_SIZE * tile->x;
|
|
audioData.synthVoices[tile->audioCh].sourceRect.y = TILE_SIZE * tile->y;
|
|
audioData.synthVoices[tile->audioCh].waveform = WAVE_TRIANGLE;
|
|
audioData.synthVoices[tile->audioCh].frequency = 99;
|
|
}
|
|
}
|
|
if (tile->audioCh < NUM_SYNTH_VOICES) {
|
|
audioData.synthVoices[tile->audioCh].frequency++;
|
|
}
|
|
if (outItem->type == 0 && ++tile->miscVal >= targetOutItem.miscVal) {
|
|
if (tile->audioCh < NUM_SYNTH_VOICES) {
|
|
audioData.synthVoices[tile->audioCh].volume = 0;
|
|
}
|
|
tile->miscVal = 0;
|
|
inItem->type = 0;
|
|
outItem->type = targetOutItemType;
|
|
outItem->offset = -0.5f;
|
|
}
|
|
}
|
|
} |