diff --git a/.vscode/launch.json b/.vscode/launch.json index eb018be..11264b7 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -12,6 +12,18 @@ "environment": [], "externalConsole": true, "MIMode": "lldb" + }, + { + "name": "Debug Server", + "type": "cppdbg", + "request": "launch", + "program": "${workspaceFolder}/build/server", + "args": [], + "stopAtEntry": false, + "cwd": "${workspaceFolder}", + "environment": [], + "externalConsole": true, + "MIMode": "lldb" } ] } diff --git a/src/client.c b/src/client.c index ed04fdd..48b8c2f 100644 --- a/src/client.c +++ b/src/client.c @@ -1139,8 +1139,8 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count for (u32 i = 0; i < Commodity_Count; i++) { if (i == CommodityOxygen || i == CommodityHydrogenFuel || state->me.commodities[i] > 0) { MemoryZero(sbuf, SBUFLEN); - sprintf(sbuf, "%-42s %d", COMMODITIES[i].name, state->me.commodities[i]); - renderStrToBuffer(tui->frame_buffer, box.x+4, yoff+3+i, sbuf, screen_dimensions); + sprintf(sbuf, "%-18s %d", COMMODITIES[i].name, state->me.commodities[i]); + renderStrToBuffer(tui->frame_buffer, box.x+4, (++yoff)+3, sbuf, screen_dimensions); } } @@ -1222,6 +1222,16 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count sprintf(sbuf, "Welcome to %s", curr.name); renderStrToBuffer(tui->frame_buffer, box.x+((screen_dimensions.width - strlen(sbuf))/2), line++, sbuf, screen_dimensions); + if (state->market_tab_state == MarketTabStateComparisonTable) { + MemoryZero(sbuf, SBUFLEN); + sprintf(sbuf, "(press ESC to view Commodities list)"); + renderStrToBuffer(tui->frame_buffer, box.x+((screen_dimensions.width - strlen(sbuf))/2), line++, sbuf, screen_dimensions); + } else { + MemoryZero(sbuf, SBUFLEN); + sprintf(sbuf, "(press SPACE to compare prices)"); + renderStrToBuffer(tui->frame_buffer, box.x+((screen_dimensions.width - strlen(sbuf))/2), line++, sbuf, screen_dimensions); + } + // the table TableDrawInfo info = { .x_offset = box.x+2, .y_offset = ++line, diff --git a/src/server.c b/src/server.c index 0b78ff1..ca59f2d 100644 --- a/src/server.c +++ b/src/server.c @@ -1153,7 +1153,7 @@ fn void setHighProductionCommodity(Planet* p, CommodityType t) { p->commodities[t] = (COMMODITIES[t].qty / 2) + (rand() % COMMODITIES[t].qty); p->production[t] = COMMODITIES[t].consumption + (rand() % COMMODITIES[t].consumption); if (t == CommodityHydrogenFuel || t == CommodityOxygen) { - p->commodities[t] = COMMODITIES[t].qty * 2; + p->commodities[t] = COMMODITIES[t].qty; } } @@ -1161,7 +1161,7 @@ fn void setLowProductionCommodity(Planet* p, CommodityType t) { p->commodities[t] = rand() % (COMMODITIES[t].qty / 2); p->production[t] = rand() % (COMMODITIES[t].consumption / 2); if (t == CommodityHydrogenFuel || t == CommodityOxygen) { - p->commodities[t] = COMMODITIES[t].qty; + p->commodities[t] = COMMODITIES[t].qty / 2; } } @@ -1195,6 +1195,23 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count // show what ip to connect to renderStrToBuffer(tui->frame_buffer, screen_dimensions.width - 18, 1, state->server_ip_address.bytes, screen_dimensions); + if (input_buffer[0] == 'q' || user_pressed_esc) { + should_quit = true; + } + if (state->someone_won) { + for (u32 i = 0; i < ACCOUNT_LEN; i++) { + Account* acct = &state->accounts[i]; + if (!shipIsNull(&acct->ship)) { + if (acct->ship.remaining_mortgage == 0) { + MemoryZero(sbuf, SBUFLEN); + sprintf(sbuf, "%s WON!!!", acct->name.bytes); + renderStrToBuffer(tui->frame_buffer, (screen_dimensions.width-strlen(sbuf)) /2, 10, sbuf, screen_dimensions); + return should_quit; + } + } + } + } + // draw the tabs box u32 tabs_y = 0; u32 box_y = tabs_y + 2; @@ -1217,13 +1234,10 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count switch (state->tab) { case TabDebug: { - if (input_buffer[0] == 'q' || user_pressed_esc) { - should_quit = true; - } renderSystemMessages(tui->frame_buffer, tui->screen_dimensions, box); } break; case TabMap: { - u8 COLORS[] = {ANSI_HIGHLIGHT_RED, ANSI_HIGHLIGHT_BLUE, ANSI_HIGHLIGHT_YELLOW, ANSI_HIGHLIGHT_GREEN, ANSI_HIGHLIGHT_GRAY}; + u8 COLORS[] = {ANSI_HIGHLIGHT_RED, ANSI_HIGHLIGHT_BLUE, ANSI_HIGHLIGHT_YELLOW, ANSI_HIGHLIGHT_GREEN, ANSI_WHITE}; u32 xw = 4; u32 yh = 2; if (box.width <= MAP_WIDTH*xw) { @@ -1257,11 +1271,6 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count } } } - //if (state->pos.x == sysx && state->pos.y == sysy) { - // tui->frame_buffer[bufpos].background = ANSI_WHITE; - // tui->frame_buffer[bufpos].foreground = ANSI_BLACK; - //} else { - //} } } for (u32 i = 0; i < STAR_SYSTEM_COUNT; i++) { @@ -1294,33 +1303,22 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count sysy +1, strForPlanet(sys.planets[2].type) ); - } - for (u32 i = 0; i < STAR_SYSTEM_COUNT; i++) { - StarSystem sys = state->map[i]; - u32 sysx = x_off + xw*sys.x; - u32 sysy = y_off + yh*sys.y; - if (sysx == tui->cursor.x && sysy == tui->cursor.y) { - renderStrToBuffer(tui->frame_buffer, sysx, sysy+2, STAR_NAMES[i], screen_dimensions); - } + renderStrToBuffer(tui->frame_buffer, sysx-((strlen(STAR_NAMES[i])-4)/2), sysy-1, STAR_NAMES[i], screen_dimensions); } // TODO fix the background bleed from previous line // map key y_off += 1+(MAP_HEIGHT*yh); - u32 original_x_off = x_off; - for (u32 i = 0; i < ACCOUNT_LEN; i++) { + x_off = box.x + 3; + for (u32 i = 0; i < ACCOUNT_LEN; i++, x_off += 18) { Account* acct = &state->accounts[i]; if (acct->name.length > 0) { Box current_key = { .height = yh, .width = xw, .x = x_off, .y = y_off }; colorizeBox(tui, current_key, COLORS[i], 0, ' '); renderStrToBuffer(tui->frame_buffer, x_off+5, y_off, acct->name.bytes, screen_dimensions); - - if (i % 2 == 0) { - x_off += 20; - } else if (i % 2 == 1) { - y_off += 3; - x_off = original_x_off; - } + MemoryZero(sbuf, SBUFLEN); + sprintf(sbuf, "$%d", acct->ship.remaining_mortgage); + renderStrToBuffer(tui->frame_buffer, x_off+5, y_off+1, sbuf, screen_dimensions); } } @@ -1337,7 +1335,7 @@ i32 main(i32 argc, ptr argv[]) { osInit(); // multi-thread architecture: // - the gameLoop() which just inifinite loops every "tick" and processes user input and updates gameworld state - // - TODO: actually make this N "lanes" as described https://www.rfleury.com/p/multi-core-by-default + // - this is N "lanes" as described https://www.rfleury.com/p/multi-core-by-default // such that we can split room-work among all the various cores on our machine // - one is the sendNetworkUpdates() infinite loop, which sends a UDP snapshot-or-delta update to each connected client N/sec // - one is the receiveNetworkUpdates() infinte loop, which waits for new UDP messages from clients @@ -1417,8 +1415,8 @@ i32 main(i32 argc, ptr argv[]) { p->production[iii] = 1 + (rand() % COMMODITIES[iii].consumption); } // everyone starts with "a lot" of fuel and o2 - p->commodities[CommodityHydrogenFuel] = COMMODITIES[CommodityHydrogenFuel].qty * 2; - p->commodities[CommodityOxygen] = COMMODITIES[CommodityOxygen].qty * 2; + p->commodities[CommodityHydrogenFuel] = COMMODITIES[CommodityHydrogenFuel].qty; + p->commodities[CommodityOxygen] = COMMODITIES[CommodityOxygen].qty; // now, override for the "specialty" of the planet switch (p->type) { case PlanetTypeEarth: { diff --git a/src/shared.h b/src/shared.h index 8b60b1c..7b50701 100644 --- a/src/shared.h +++ b/src/shared.h @@ -183,11 +183,11 @@ global Commodity COMMODITIES[Commodity_Count] = { }, { .type = CommodityHandTools, .unit = StorageUnitContainer, .name = "Hand Tools", - .price = 20000, .qty = 5, .consumption = 1, + .price = 12000, .qty = 9, .consumption = 2, }, { .type = CommodityElectronics, .unit = StorageUnitContainer, .name = "Electronics", - .price = 40000, .qty = 40, .consumption = 6, + .price = 21000, .qty = 20, .consumption = 3, }, }; @@ -404,7 +404,7 @@ static const char* MESSAGE_STRINGS[] = { fn u32 fuelCostForTravel(u32 drive_efficiency, Pos2 current, Pos2 dest) { u32 x_distance = Max(current.x, dest.x) - Min(current.x, dest.x); u32 y_distance = Max(current.y, dest.y) - Min(current.y, dest.y); - u32 fuel_per_dist = 100 - drive_efficiency*10; + u32 fuel_per_dist = 100 - drive_efficiency*5; return (x_distance + y_distance) * fuel_per_dist; }