prevent over-buying cargo
This commit is contained in:
+12
-4
@@ -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) {
|
if (input_buffer[0] == 'q' || user_pressed_esc) {
|
||||||
should_quit = true;
|
should_quit = true;
|
||||||
}
|
}
|
||||||
renderStrToBuffer(tui->frame_buffer, box.x+2, box.y+1, SHIP_TYPE_STRINGS[state->me.type], screen_dimensions);
|
u32 yoff = box.y+1;
|
||||||
renderStrToBuffer(tui->frame_buffer, box.x+2, box.y+2, "Credits: ", screen_dimensions);
|
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);
|
MemoryZero(sbuf, 512);
|
||||||
sprintf(sbuf, "%.2f", state->me.credits);
|
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++) {
|
for (u32 i = 0; i < Commodity_Count; i++) {
|
||||||
MemoryZero(sbuf, 512);
|
MemoryZero(sbuf, 512);
|
||||||
sprintf(sbuf, "%-42s %d", COMMODITY_STRINGS[i], state->me.commodities[i]);
|
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;
|
} break;
|
||||||
case TabStation: {
|
case TabStation: {
|
||||||
|
|||||||
+3
-4
@@ -625,15 +625,14 @@ fn void* gameLoop(void* params) {
|
|||||||
bool is_buying_from_system = msg.byte;
|
bool is_buying_from_system = msg.byte;
|
||||||
Account* account = &state.accounts[client->account_id];
|
Account* account = &state.accounts[client->account_id];
|
||||||
StarSystem* sys = findAccountsSystem(account);
|
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 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 qty_traded = 0;
|
||||||
u32 credit_value = 0;
|
u32 credit_value = 0;
|
||||||
if (is_buying_from_system) {
|
if (is_buying_from_system) {
|
||||||
printf("is buying from system\n");
|
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--) {
|
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);
|
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;
|
amount_to_buy = 0;
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -324,6 +324,14 @@ typedef struct PlayerShip {
|
|||||||
u32 commodities[Commodity_Count];
|
u32 commodities[Commodity_Count];
|
||||||
} PlayerShip;
|
} 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 {
|
typedef enum PlanetType {
|
||||||
PlanetTypeNull,
|
PlanetTypeNull,
|
||||||
PlanetTypeEarth,
|
PlanetTypeEarth,
|
||||||
|
|||||||
Reference in New Issue
Block a user