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

63 lines
2.2 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) {
if (outItem->type != TYPE_AIR) {
if (tile->audioCh < NUM_SYNTH_VOICES) {
audioData.synthVoices[tile->audioCh].volume = 0;
}
tile->fixedFrame = 1;
return;
}
tile->audioCh = getAvailableChannel();
if (tile->audioCh < NUM_SYNTH_VOICES) {
audioData.synthVoices[tile->audioCh].volume = 255;
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_SINE;
audioData.synthVoices[tile->audioCh].frequency = 200;
}
tile->fixedFrame = 0;
}
++audioData.synthVoices[tile->audioCh].frequency;
if (audioData.synthVoices[tile->audioCh].volume < 255) {
audioData.synthVoices[tile->audioCh].volume++;
}
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;
inItem->type = 0;
outItem->type = targetOutItemType;
outItem->offset = -0.5f;
}
} else {
tile->fixedFrame = 1;
}
}