|
@@ -14,6 +14,7 @@ FluidBlock::FluidBlock(int typeId, Framework::Vec3<int> pos)
|
|
|
tickSource = 1;
|
|
|
interactable = 0;
|
|
|
fluidAmount = 0;
|
|
|
+ lastBroadcastedAmount = fluidAmount;
|
|
|
}
|
|
|
|
|
|
FluidBlock::~FluidBlock() {}
|
|
@@ -43,18 +44,17 @@ bool FluidBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
|
|
|
zNeighbours[getDirectionIndex(Direction::BOTTOM)]);
|
|
|
if (below->fluidAmount < 1000)
|
|
|
{
|
|
|
- int transferAmount
|
|
|
- = MIN(this->fluidAmount, 1000 - below->fluidAmount);
|
|
|
- below->fluidAmount += transferAmount;
|
|
|
- this->fluidAmount -= transferAmount;
|
|
|
+ short transferAmount
|
|
|
+ = (short)MIN(this->fluidAmount, (short)1000 - below->fluidAmount);
|
|
|
+ below->fluidAmount = (short)(below->fluidAmount + transferAmount);
|
|
|
+ this->fluidAmount = (short)(this->fluidAmount - transferAmount);
|
|
|
}
|
|
|
}
|
|
|
- int neighborCount = 0;
|
|
|
+ short neighborCount = 0;
|
|
|
Inventory* others[4];
|
|
|
for (int i = 1; i < 5; i++)
|
|
|
{
|
|
|
- if (neighbourTypes[i] == BlockTypeEnum::FLUID && zNeighbours[i]
|
|
|
- && zNeighbours[i]->zBlockType()->getId() == typeId)
|
|
|
+ if (neighbourTypes[i] == typeId && zNeighbours[i])
|
|
|
{
|
|
|
others[neighborCount] = zNeighbours[i];
|
|
|
neighborCount++;
|
|
@@ -73,8 +73,8 @@ bool FluidBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
|
|
|
}
|
|
|
// order other fluids increasing by fluid amount
|
|
|
sortByAmound(otherFluids, neighborCount);
|
|
|
- int distCount = 0;
|
|
|
- int targetAmount = 0;
|
|
|
+ short distCount = 0;
|
|
|
+ short targetAmount = 0;
|
|
|
for (int i = 1; i <= neighborCount; i++)
|
|
|
{
|
|
|
int fluidAmount = this->fluidAmount;
|
|
@@ -84,8 +84,8 @@ bool FluidBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
|
|
|
}
|
|
|
if (fluidAmount / (i + 1) > this->fluidAmount)
|
|
|
{
|
|
|
- targetAmount = fluidAmount / (i + 1);
|
|
|
- distCount = i;
|
|
|
+ targetAmount = (short)(fluidAmount / (i + 1));
|
|
|
+ distCount = (short)i;
|
|
|
}
|
|
|
else
|
|
|
{
|
|
@@ -94,26 +94,46 @@ bool FluidBlock::onTick(TickQueue* zQueue, int numTicks, bool& blocked)
|
|
|
}
|
|
|
for (int i = 0; i < distCount; i++)
|
|
|
{
|
|
|
- int transferAmount
|
|
|
- = targetAmount - otherFluids[i]->fluidAmount;
|
|
|
- otherFluids[i]->fluidAmount += transferAmount;
|
|
|
- this->fluidAmount -= transferAmount;
|
|
|
+ short transferAmount
|
|
|
+ = (short)(targetAmount - otherFluids[i]->fluidAmount);
|
|
|
+ otherFluids[i]->fluidAmount
|
|
|
+ = (short)(otherFluids[i]->fluidAmount + transferAmount);
|
|
|
+ this->fluidAmount = (short)(this->fluidAmount - transferAmount);
|
|
|
}
|
|
|
- // TODO: distribute fluids
|
|
|
} // unlock
|
|
|
neighborCount = 0;
|
|
|
- for (int i = 1; i < 5; i++)
|
|
|
+ for (int i = 0; i < 6; i++)
|
|
|
{
|
|
|
- int neighbor = neighbourTypes[i];
|
|
|
- if (neighbor == BlockTypeEnum::AIR
|
|
|
- && fluidAmount > neighborCount + 1)
|
|
|
+ if (getDirectionFromIndex(i) != Direction::BOTTOM
|
|
|
+ && getDirectionFromIndex(i) != Direction::TOP)
|
|
|
{
|
|
|
- nextFlow |= 1 << i;
|
|
|
- neighborCount++;
|
|
|
+ int neighbor = neighbourTypes[i];
|
|
|
+ if (neighbor == BlockTypeEnum::AIR
|
|
|
+ && fluidAmount > neighborCount + 1)
|
|
|
+ {
|
|
|
+ nextFlow |= 1 << i;
|
|
|
+ neighborCount++;
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
}
|
|
|
+ return 1;
|
|
|
+}
|
|
|
+
|
|
|
+void FluidBlock::broadcastAmount()
|
|
|
+{
|
|
|
+ if (lastBroadcastedAmount != fluidAmount)
|
|
|
+ {
|
|
|
+ lastBroadcastedAmount = fluidAmount;
|
|
|
+ NetworkMessage* changeMsg = new NetworkMessage();
|
|
|
+ changeMsg->addressBlock(this);
|
|
|
+ char* msg = new char[3];
|
|
|
+ msg[0] = 2; // fluid amount change
|
|
|
+ *(short*)(msg + 1) = fluidAmount;
|
|
|
+ changeMsg->setMessage(msg, 3);
|
|
|
+ Game::INSTANCE->broadcastMessage(changeMsg);
|
|
|
+ }
|
|
|
}
|
|
|
|
|
|
void FluidBlock::onPostTick()
|
|
@@ -145,6 +165,10 @@ void FluidBlock::onPostTick()
|
|
|
.zElement(BlockTypeEnum::AIR)
|
|
|
->createBlockAt(getPos(), 0));
|
|
|
}
|
|
|
+ else
|
|
|
+ {
|
|
|
+ broadcastAmount();
|
|
|
+ }
|
|
|
});
|
|
|
}
|
|
|
}
|
|
@@ -217,7 +241,7 @@ void FluidBlock::sortByAmound(FluidBlock** array, int count)
|
|
|
}
|
|
|
|
|
|
FluidBlockType::FluidBlockType(int id, ModelInfo model, const char* name)
|
|
|
- : BlockType(id, 0, model, 1, 10, 0, name)
|
|
|
+ : BlockType(id, 0, model, 1, 10, 0, name, true)
|
|
|
{}
|
|
|
|
|
|
void FluidBlockType::loadSuperBlock(
|