|
@@ -7,13 +7,20 @@
|
|
|
#include "RecipieLoader.h"
|
|
#include "RecipieLoader.h"
|
|
|
|
|
|
|
|
FireBasedProcessingBlockComponent::FireBasedProcessingBlockComponent()
|
|
FireBasedProcessingBlockComponent::FireBasedProcessingBlockComponent()
|
|
|
- : BlockComponent()
|
|
|
|
|
|
|
+ : BlockComponent(),
|
|
|
|
|
+ burnLight(0),
|
|
|
|
|
+ ticksNeeded(0),
|
|
|
|
|
+ currentRecipie(0),
|
|
|
|
|
+ maxFuelBuffer(0),
|
|
|
|
|
+ fuelBuffer(0),
|
|
|
|
|
+ burning(0)
|
|
|
{}
|
|
{}
|
|
|
|
|
|
|
|
FireBasedProcessingBlockComponent::~FireBasedProcessingBlockComponent() {}
|
|
FireBasedProcessingBlockComponent::~FireBasedProcessingBlockComponent() {}
|
|
|
|
|
|
|
|
-void FireBasedProcessingBlockComponent::findRecipie()
|
|
|
|
|
|
|
+bool FireBasedProcessingBlockComponent::findRecipie()
|
|
|
{
|
|
{
|
|
|
|
|
+ bool changed = 0;
|
|
|
RecipieList* zRecipies
|
|
RecipieList* zRecipies
|
|
|
= Game::INSTANCE->zRecipies()->zRecipieList(recipieGroup.getText());
|
|
= Game::INSTANCE->zRecipies()->zRecipieList(recipieGroup.getText());
|
|
|
if (zRecipies)
|
|
if (zRecipies)
|
|
@@ -25,13 +32,16 @@ void FireBasedProcessingBlockComponent::findRecipie()
|
|
|
recipie->consumeInputs(this);
|
|
recipie->consumeInputs(this);
|
|
|
currentRecipie = recipie;
|
|
currentRecipie = recipie;
|
|
|
ticksNeeded = recipie->getTicksNeeded();
|
|
ticksNeeded = recipie->getTicksNeeded();
|
|
|
|
|
+ changed = 1;
|
|
|
}
|
|
}
|
|
|
zBlock->unlock();
|
|
zBlock->unlock();
|
|
|
}
|
|
}
|
|
|
|
|
+ return changed;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-void FireBasedProcessingBlockComponent::consumeFuel()
|
|
|
|
|
|
|
+bool FireBasedProcessingBlockComponent::consumeFuel()
|
|
|
{
|
|
{
|
|
|
|
|
+ bool changed = 0;
|
|
|
zBlock->lock();
|
|
zBlock->lock();
|
|
|
ItemSlot* fireStartingSlot = 0;
|
|
ItemSlot* fireStartingSlot = 0;
|
|
|
ItemSlot* fuelSlot = 0;
|
|
ItemSlot* fuelSlot = 0;
|
|
@@ -66,7 +76,9 @@ void FireBasedProcessingBlockComponent::consumeFuel()
|
|
|
{
|
|
{
|
|
|
// TODO: check if item is burnable and how much fuel it provides
|
|
// TODO: check if item is burnable and how much fuel it provides
|
|
|
fuelBuffer += 100;
|
|
fuelBuffer += 100;
|
|
|
|
|
+ maxFuelBuffer = fuelBuffer;
|
|
|
fuelStack->release();
|
|
fuelStack->release();
|
|
|
|
|
+ changed = 1;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -96,13 +108,35 @@ void FireBasedProcessingBlockComponent::consumeFuel()
|
|
|
{
|
|
{
|
|
|
// TODO: check if item is burnable and how much fuel it provides
|
|
// TODO: check if item is burnable and how much fuel it provides
|
|
|
fuelBuffer += 100;
|
|
fuelBuffer += 100;
|
|
|
|
|
+ maxFuelBuffer = fuelBuffer;
|
|
|
burning = true;
|
|
burning = true;
|
|
|
fuelStack->release();
|
|
fuelStack->release();
|
|
|
fireStartingStack->release();
|
|
fireStartingStack->release();
|
|
|
|
|
+ changed = 1;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
zBlock->unlock();
|
|
zBlock->unlock();
|
|
|
|
|
+ return changed;
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void FireBasedProcessingBlockComponent::createProgressMessage(
|
|
|
|
|
+ NetworkMessage* message) const
|
|
|
|
|
+{
|
|
|
|
|
+ char* msg = new char[8];
|
|
|
|
|
+ *(int*)msg = currentRecipie ? currentRecipie->getTicksNeeded() : 0;
|
|
|
|
|
+ *(int*)(msg + 4)
|
|
|
|
|
+ = currentRecipie ? currentRecipie->getTicksNeeded() - ticksNeeded : 0;
|
|
|
|
|
+ message->setMessage(msg, 8);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+void FireBasedProcessingBlockComponent::createFuelMessage(
|
|
|
|
|
+ NetworkMessage* message) const
|
|
|
|
|
+{
|
|
|
|
|
+ char* msg = new char[8];
|
|
|
|
|
+ *(int*)msg = maxFuelBuffer;
|
|
|
|
|
+ *(int*)(msg + 4) = fuelBuffer;
|
|
|
|
|
+ message->setMessage(msg, 8);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
void FireBasedProcessingBlockComponent::initialize(Block* zBlock)
|
|
void FireBasedProcessingBlockComponent::initialize(Block* zBlock)
|
|
@@ -113,11 +147,13 @@ void FireBasedProcessingBlockComponent::initialize(Block* zBlock)
|
|
|
bool FireBasedProcessingBlockComponent::tick(int numTicks)
|
|
bool FireBasedProcessingBlockComponent::tick(int numTicks)
|
|
|
{
|
|
{
|
|
|
bool active = 0;
|
|
bool active = 0;
|
|
|
|
|
+ bool progressChanged = 0;
|
|
|
|
|
+ bool fuelChanged = 0;
|
|
|
while (numTicks > 0)
|
|
while (numTicks > 0)
|
|
|
{
|
|
{
|
|
|
if (!fuelBuffer)
|
|
if (!fuelBuffer)
|
|
|
{
|
|
{
|
|
|
- consumeFuel();
|
|
|
|
|
|
|
+ fuelChanged |= consumeFuel();
|
|
|
}
|
|
}
|
|
|
if (!burning)
|
|
if (!burning)
|
|
|
{
|
|
{
|
|
@@ -125,7 +161,7 @@ bool FireBasedProcessingBlockComponent::tick(int numTicks)
|
|
|
}
|
|
}
|
|
|
if (!currentRecipie)
|
|
if (!currentRecipie)
|
|
|
{
|
|
{
|
|
|
- findRecipie();
|
|
|
|
|
|
|
+ progressChanged |= findRecipie();
|
|
|
}
|
|
}
|
|
|
bool processed = false;
|
|
bool processed = false;
|
|
|
if (currentRecipie)
|
|
if (currentRecipie)
|
|
@@ -134,7 +170,7 @@ bool FireBasedProcessingBlockComponent::tick(int numTicks)
|
|
|
= fuelBuffer / currentRecipie->getFuelPerTickNeeded();
|
|
= fuelBuffer / currentRecipie->getFuelPerTickNeeded();
|
|
|
if (!possibleTicks)
|
|
if (!possibleTicks)
|
|
|
{
|
|
{
|
|
|
- consumeFuel();
|
|
|
|
|
|
|
+ fuelChanged |= consumeFuel();
|
|
|
possibleTicks
|
|
possibleTicks
|
|
|
= fuelBuffer / currentRecipie->getFuelPerTickNeeded();
|
|
= fuelBuffer / currentRecipie->getFuelPerTickNeeded();
|
|
|
}
|
|
}
|
|
@@ -158,6 +194,8 @@ bool FireBasedProcessingBlockComponent::tick(int numTicks)
|
|
|
-= currentRecipie->getFuelPerTickNeeded() * numTicks;
|
|
-= currentRecipie->getFuelPerTickNeeded() * numTicks;
|
|
|
numTicks = 0;
|
|
numTicks = 0;
|
|
|
}
|
|
}
|
|
|
|
|
+ progressChanged = 1;
|
|
|
|
|
+ fuelChanged = 1;
|
|
|
processed = true;
|
|
processed = true;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
@@ -173,6 +211,8 @@ bool FireBasedProcessingBlockComponent::tick(int numTicks)
|
|
|
ticksNeeded = 0;
|
|
ticksNeeded = 0;
|
|
|
currentRecipie = 0;
|
|
currentRecipie = 0;
|
|
|
processed = true;
|
|
processed = true;
|
|
|
|
|
+ fuelChanged = 1;
|
|
|
|
|
+ progressChanged = 1;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
@@ -181,6 +221,8 @@ bool FireBasedProcessingBlockComponent::tick(int numTicks)
|
|
|
* possibleTicks;
|
|
* possibleTicks;
|
|
|
ticksNeeded -= possibleTicks;
|
|
ticksNeeded -= possibleTicks;
|
|
|
processed = possibleTicks > 0;
|
|
processed = possibleTicks > 0;
|
|
|
|
|
+ progressChanged = possibleTicks > 0;
|
|
|
|
|
+ fuelChanged = possibleTicks > 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
@@ -191,21 +233,123 @@ bool FireBasedProcessingBlockComponent::tick(int numTicks)
|
|
|
{
|
|
{
|
|
|
fuelBuffer -= numTicks;
|
|
fuelBuffer -= numTicks;
|
|
|
numTicks = 0;
|
|
numTicks = 0;
|
|
|
|
|
+ fuelChanged = 1;
|
|
|
}
|
|
}
|
|
|
else
|
|
else
|
|
|
{
|
|
{
|
|
|
|
|
+ fuelChanged = fuelBuffer > 0;
|
|
|
numTicks -= fuelBuffer;
|
|
numTicks -= fuelBuffer;
|
|
|
fuelBuffer = 0;
|
|
fuelBuffer = 0;
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
active = 1;
|
|
active = 1;
|
|
|
}
|
|
}
|
|
|
|
|
+ if (fuelChanged)
|
|
|
|
|
+ {
|
|
|
|
|
+ NetworkMessage* fuelMessage = new NetworkMessage();
|
|
|
|
|
+ createFuelMessage(fuelMessage);
|
|
|
|
|
+ fuelObservable.notifyObservers(fuelMessage);
|
|
|
|
|
+ }
|
|
|
|
|
+ if (progressChanged)
|
|
|
|
|
+ {
|
|
|
|
|
+ NetworkMessage* progressMessage = new NetworkMessage();
|
|
|
|
|
+ createProgressMessage(progressMessage);
|
|
|
|
|
+ progressObservable.notifyObservers(progressMessage);
|
|
|
|
|
+ }
|
|
|
return active;
|
|
return active;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
-Framework::XML::Element* FireBasedProcessingBlockComponent::getUIML() const
|
|
|
|
|
|
|
+void FireBasedProcessingBlockComponent::api(Framework::StreamReader* zRequest,
|
|
|
|
|
+ NetworkMessage* zResponse,
|
|
|
|
|
+ Entity* zSource)
|
|
|
|
|
+{
|
|
|
|
|
+ char type;
|
|
|
|
|
+ zRequest->lese(&type, 1);
|
|
|
|
|
+ switch (type)
|
|
|
|
|
+ {
|
|
|
|
|
+ case 0: // subscribe to fuel
|
|
|
|
|
+ {
|
|
|
|
|
+ char idLen;
|
|
|
|
|
+ zRequest->lese(&idLen, 1);
|
|
|
|
|
+ char* id = new char[idLen + 1];
|
|
|
|
|
+ zRequest->lese(id, idLen);
|
|
|
|
|
+ id[(int)idLen] = 0;
|
|
|
|
|
+ int processor;
|
|
|
|
|
+ zRequest->lese((char*)&processor, 4);
|
|
|
|
|
+ fuelObservable.addObserver(zSource, id, processor);
|
|
|
|
|
+ createFuelMessage(zResponse);
|
|
|
|
|
+ zResponse->addressUIElement(id, processor);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case 1: // subscribe to progress
|
|
|
|
|
+ {
|
|
|
|
|
+ char idLen;
|
|
|
|
|
+ zRequest->lese(&idLen, 1);
|
|
|
|
|
+ char* id = new char[idLen + 1];
|
|
|
|
|
+ zRequest->lese(id, idLen);
|
|
|
|
|
+ id[(int)idLen] = 0;
|
|
|
|
|
+ int processor;
|
|
|
|
|
+ zRequest->lese((char*)&processor, 4);
|
|
|
|
|
+ progressObservable.addObserver(zSource, id, processor);
|
|
|
|
|
+ createProgressMessage(zResponse);
|
|
|
|
|
+ zResponse->addressUIElement(id, processor);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case 2: // unsubscribe to fuel
|
|
|
|
|
+ {
|
|
|
|
|
+ char idLen;
|
|
|
|
|
+ zRequest->lese(&idLen, 1);
|
|
|
|
|
+ char* id = new char[idLen + 1];
|
|
|
|
|
+ zRequest->lese(id, idLen);
|
|
|
|
|
+ id[(int)idLen] = 0;
|
|
|
|
|
+ int processor;
|
|
|
|
|
+ zRequest->lese((char*)&processor, 4);
|
|
|
|
|
+ fuelObservable.removeObserver(zSource, id, processor);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ case 3: // unsubscribe to progress
|
|
|
|
|
+ {
|
|
|
|
|
+ char idLen;
|
|
|
|
|
+ zRequest->lese(&idLen, 1);
|
|
|
|
|
+ char* id = new char[idLen + 1];
|
|
|
|
|
+ zRequest->lese(id, idLen);
|
|
|
|
|
+ id[(int)idLen] = 0;
|
|
|
|
|
+ int processor;
|
|
|
|
|
+ zRequest->lese((char*)&processor, 4);
|
|
|
|
|
+ progressObservable.removeObserver(zSource, id, processor);
|
|
|
|
|
+ break;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
+Framework::XML::Element*
|
|
|
|
|
+FireBasedProcessingBlockComponent::getTooltipUIML() const
|
|
|
{
|
|
{
|
|
|
- return nullptr;
|
|
|
|
|
|
|
+ if (currentRecipie)
|
|
|
|
|
+ {
|
|
|
|
|
+ Framework::XML::Element* result = new Framework::XML::Element(
|
|
|
|
|
+ "<text width=\"auto\" height=\"auto\"></text>");
|
|
|
|
|
+ Framework::Text content;
|
|
|
|
|
+ content.append() << "Processing: ";
|
|
|
|
|
+ int first = 1;
|
|
|
|
|
+ for (const ItemInfo& output : currentRecipie->getOutput())
|
|
|
|
|
+ {
|
|
|
|
|
+ if (!first)
|
|
|
|
|
+ {
|
|
|
|
|
+ content.append() << ", ";
|
|
|
|
|
+ }
|
|
|
|
|
+ content.append()
|
|
|
|
|
+ << output.count << " "
|
|
|
|
|
+ << Game::INSTANCE->zItemType(output.type)->getTooltipUIML();
|
|
|
|
|
+ first = 0;
|
|
|
|
|
+ }
|
|
|
|
|
+ content.append()
|
|
|
|
|
+ << " ("
|
|
|
|
|
+ << (int)((ticksNeeded / currentRecipie->getTicksNeeded()) * 100)
|
|
|
|
|
+ << "%)";
|
|
|
|
|
+ result->setText(content);
|
|
|
|
|
+ }
|
|
|
|
|
+ return 0;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
bool FireBasedProcessingBlockComponent::isAllAvailable(
|
|
bool FireBasedProcessingBlockComponent::isAllAvailable(
|
|
@@ -249,6 +393,7 @@ void FireBasedProcessingBlockComponent::loadComponent(
|
|
|
Framework::StreamReader* zReader)
|
|
Framework::StreamReader* zReader)
|
|
|
{
|
|
{
|
|
|
zReader->lese((char*)&ticksNeeded, 4);
|
|
zReader->lese((char*)&ticksNeeded, 4);
|
|
|
|
|
+ zReader->lese((char*)&maxFuelBuffer, 4);
|
|
|
zReader->lese((char*)&fuelBuffer, 4);
|
|
zReader->lese((char*)&fuelBuffer, 4);
|
|
|
zReader->lese((char*)&burning, 1);
|
|
zReader->lese((char*)&burning, 1);
|
|
|
int index = 0;
|
|
int index = 0;
|
|
@@ -270,6 +415,7 @@ void FireBasedProcessingBlockComponent::saveComponent(
|
|
|
Framework::StreamWriter* zWriter) const
|
|
Framework::StreamWriter* zWriter) const
|
|
|
{
|
|
{
|
|
|
zWriter->schreibe((char*)&ticksNeeded, 4);
|
|
zWriter->schreibe((char*)&ticksNeeded, 4);
|
|
|
|
|
+ zWriter->schreibe((char*)&maxFuelBuffer, 4);
|
|
|
zWriter->schreibe((char*)&fuelBuffer, 4);
|
|
zWriter->schreibe((char*)&fuelBuffer, 4);
|
|
|
zWriter->schreibe((char*)&burning, 1);
|
|
zWriter->schreibe((char*)&burning, 1);
|
|
|
int index = -1;
|
|
int index = -1;
|