forked from townforge/townforge
game: fix double counting of blocks when building
This commit is contained in:
parent
836b362159
commit
de89dfa53b
@ -345,7 +345,6 @@ bool Flag::push_tiles(PlayerState *player, uint32_t px0, uint32_t py0, uint32_t
|
||||
const uint32_t w = x1 - x0 + 1;
|
||||
uint32_t done = 0;
|
||||
const uint32_t owner = player ? player->id : 0;
|
||||
uint32_t items_needed[NUM_ITEMS] = {0};
|
||||
for (uint32_t ty = py0; ty <= py1; ++ty)
|
||||
{
|
||||
for (uint32_t tx = px0; tx <= px1; ++tx)
|
||||
@ -354,8 +353,6 @@ bool Flag::push_tiles(PlayerState *player, uint32_t px0, uint32_t py0, uint32_t
|
||||
if (decoded_types[done])
|
||||
{
|
||||
uint16_t build_height = std::max(min_height, t.get_height());
|
||||
items_needed[ITEM_LABOUR] += cc::get_build_labour_cost_for_height(build_height);
|
||||
++items_needed[decoded_types[done]];
|
||||
while (t.get_height() < build_height)
|
||||
t.push(0);
|
||||
t.push(decoded_types[done]);
|
||||
@ -364,18 +361,6 @@ bool Flag::push_tiles(PlayerState *player, uint32_t px0, uint32_t py0, uint32_t
|
||||
}
|
||||
}
|
||||
|
||||
if (player)
|
||||
{
|
||||
for (uint32_t idx = 1; idx < NUM_ITEMS; ++idx)
|
||||
{
|
||||
if (items_needed[idx] > budget[idx])
|
||||
{
|
||||
printf("Not enough blocks of type %u (%u, needs %u)\n", idx, budget[idx], items_needed[idx]);
|
||||
goto undo;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (uint32_t ty = py0; ty <= py1; ++ty)
|
||||
{
|
||||
for (uint32_t tx = px0; tx <= px1; ++tx)
|
||||
@ -387,12 +372,6 @@ bool Flag::push_tiles(PlayerState *player, uint32_t px0, uint32_t py0, uint32_t
|
||||
}
|
||||
}
|
||||
|
||||
if (player)
|
||||
{
|
||||
for (uint32_t idx = 1; idx < NUM_ITEMS; ++idx)
|
||||
budget[idx] -= items_needed[idx];
|
||||
}
|
||||
|
||||
return true;
|
||||
|
||||
undo:
|
||||
@ -442,7 +421,6 @@ bool Flag::pop_tiles(PlayerState *player, uint32_t px0, uint32_t py0, uint32_t p
|
||||
}
|
||||
|
||||
uint32_t done = 0;
|
||||
uint32_t labour_cost = 0;
|
||||
const uint32_t w = x1 - x0 + 1;
|
||||
for (uint32_t ty = py0; ty <= py1; ++ty)
|
||||
{
|
||||
@ -456,20 +434,9 @@ bool Flag::pop_tiles(PlayerState *player, uint32_t px0, uint32_t py0, uint32_t p
|
||||
printf("Empty\n");
|
||||
return false;
|
||||
}
|
||||
labour_cost += BLOCK_POP_COST;
|
||||
}
|
||||
}
|
||||
|
||||
if (player)
|
||||
{
|
||||
if (labour_cost > budget[ITEM_LABOUR])
|
||||
{
|
||||
printf("Not enough labour balance (%u, needs %u)\n", budget[ITEM_LABOUR], labour_cost);
|
||||
return false;
|
||||
}
|
||||
budget[ITEM_LABOUR] -= labour_cost;
|
||||
}
|
||||
|
||||
uint16_t check_height[width+2][height+2];
|
||||
for (uint32_t y = 0; y < (uint32_t)height + 2; ++y)
|
||||
for (uint32_t x = 0; x < (uint32_t)width + 2; ++x)
|
||||
|
Loading…
Reference in New Issue
Block a user