diff --git a/src/client.c b/src/client.c index 81457d6..e58128e 100644 --- a/src/client.c +++ b/src/client.c @@ -779,15 +779,23 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count if (input_buffer[0] == 'q' || user_pressed_esc) { should_quit = true; } - renderStrToBuffer(tui->frame_buffer, box.x+2, box.y+1, SHIP_TYPE_STRINGS[state->me.type], screen_dimensions); - renderStrToBuffer(tui->frame_buffer, box.x+2, box.y+2, "Credits: ", screen_dimensions); + u32 yoff = box.y+1; + renderStrToBuffer(tui->frame_buffer, box.x+2, yoff++, SHIP_TYPE_STRINGS[state->me.type], screen_dimensions); + + renderStrToBuffer(tui->frame_buffer, box.x+2, yoff, "Credits: ", screen_dimensions); MemoryZero(sbuf, 512); sprintf(sbuf, "%.2f", state->me.credits); - renderStrToBuffer(tui->frame_buffer, box.x+15, box.y+2, sbuf, screen_dimensions); + renderStrToBuffer(tui->frame_buffer, box.x+15, yoff++, sbuf, screen_dimensions); + + u32 used_cargo = usedVacuumCargoSlots(state->me); + MemoryZero(sbuf, 512); + sprintf(sbuf, "Cargo: %d / %d", used_cargo, state->me.vacuum_cargo_slots); + renderStrToBuffer(tui->frame_buffer, box.x+2, yoff++, sbuf, screen_dimensions); + for (u32 i = 0; i < Commodity_Count; i++) { MemoryZero(sbuf, 512); sprintf(sbuf, "%-42s %d", COMMODITY_STRINGS[i], state->me.commodities[i]); - renderStrToBuffer(tui->frame_buffer, box.x+4, box.y+4+i, sbuf, screen_dimensions); + renderStrToBuffer(tui->frame_buffer, box.x+4, yoff+4+i, sbuf, screen_dimensions); } } break; case TabStation: { diff --git a/src/server.c b/src/server.c index 8660b7e..407e02f 100644 --- a/src/server.c +++ b/src/server.c @@ -625,15 +625,14 @@ fn void* gameLoop(void* params) { bool is_buying_from_system = msg.byte; Account* account = &state.accounts[client->account_id]; StarSystem* sys = findAccountsSystem(account); - printf("%d %lld %s\n", account->id, account->ship.id, sys->name); u32 total_available = sys->planets[0].commodities[msg.commodity] + sys->planets[1].commodities[msg.commodity] + sys->planets[2].commodities[msg.commodity]; u32 qty_traded = 0; u32 credit_value = 0; if (is_buying_from_system) { - printf("is buying from system\n"); - for (u32 amount_to_buy = Min(msg.qty, total_available); amount_to_buy > 0; amount_to_buy--, total_available--) { + u32 ship_space = account->ship.vacuum_cargo_slots - usedVacuumCargoSlots(account->ship); + for (u32 amount_to_buy = Min(msg.qty, total_available); amount_to_buy > 0; amount_to_buy--, total_available--, ship_space--) { u32 price = priceForCommodity(msg.commodity, total_available, false); - if (price > account->ship.credits) { + if (price > account->ship.credits || ship_space == 0) { amount_to_buy = 0; break; } diff --git a/src/shared.h b/src/shared.h index ee9ce9d..e543e20 100644 --- a/src/shared.h +++ b/src/shared.h @@ -324,6 +324,14 @@ typedef struct PlayerShip { u32 commodities[Commodity_Count]; } PlayerShip; +fn u32 usedVacuumCargoSlots(PlayerShip ship) { + u32 used_cargo = 0; + for (u32 i = 0; i < Commodity_Count; i++) { + used_cargo += ship.commodities[i]; + } + return used_cargo; +} + typedef enum PlanetType { PlanetTypeNull, PlanetTypeEarth,