minor cleanup from playtest

This commit is contained in:
Tenari
2026-03-20 07:29:27 -05:00
parent 711a812145
commit b84a120d70
3 changed files with 72 additions and 159 deletions
+4 -15
View File
@@ -284,6 +284,7 @@ fn void renderStaticAssetToPixelBuffer(TuiState* tui, u8* asset, u32 len, u16 x,
fn void resetTabRow(Tab tab) { fn void resetTabRow(Tab tab) {
if (state.menu.selected_index == TabMarket) { if (state.menu.selected_index == TabMarket) {
state.market_tab_state = MarketTabStateTable;
state.row.len = Commodity_Count; state.row.len = Commodity_Count;
state.row.selected_index = 0; state.row.selected_index = 0;
state.modal_choice.selected_index = 0; state.modal_choice.selected_index = 0;
@@ -875,9 +876,6 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
renderStrToBuffer(tui->frame_buffer, box.x+2, box.y+1, "You haven't heard anything interesting lately...", screen_dimensions); renderStrToBuffer(tui->frame_buffer, box.x+2, box.y+1, "You haven't heard anything interesting lately...", screen_dimensions);
} break;*/ } break;*/
case TabMap: { case TabMap: {
if (input_buffer[0] == 'q' || user_pressed_esc) {
should_quit = true;
}
if (user_pressed_up) { if (user_pressed_up) {
state->pos.y -= 1; state->pos.y -= 1;
} else if (user_pressed_down) { } else if (user_pressed_down) {
@@ -1053,9 +1051,6 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
} break; } break;
case TabShip: { case TabShip: {
if (state->ship_tab_states == ShipTabStateMain) { if (state->ship_tab_states == ShipTabStateMain) {
if (input_buffer[0] == 'q' || user_pressed_esc) {
should_quit = true;
}
moveRowUpDown(user_pressed_up, user_pressed_down); moveRowUpDown(user_pressed_up, user_pressed_down);
} }
@@ -1141,10 +1136,12 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
} }
for (u32 i = 0; i < Commodity_Count; i++) { for (u32 i = 0; i < Commodity_Count; i++) {
if (i == CommodityOxygen || i == CommodityHydrogenFuel || state->me.commodities[i] > 0) {
MemoryZero(sbuf, SBUFLEN); MemoryZero(sbuf, SBUFLEN);
sprintf(sbuf, "%-42s %d", COMMODITIES[i].name, state->me.commodities[i]); sprintf(sbuf, "%-42s %d", COMMODITIES[i].name, state->me.commodities[i]);
renderStrToBuffer(tui->frame_buffer, box.x+4, yoff+3+i, sbuf, screen_dimensions); renderStrToBuffer(tui->frame_buffer, box.x+4, yoff+3+i, sbuf, screen_dimensions);
} }
}
Box modal_outline = defaultModal(tui); Box modal_outline = defaultModal(tui);
u32 y_off = modal_outline.y+2; u32 y_off = modal_outline.y+2;
@@ -1211,12 +1208,8 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
} break; } break;
case TabMarket: { case TabMarket: {
if (input_buffer[0] == 'q' || user_pressed_esc) { if (input_buffer[0] == 'q' || user_pressed_esc) {
if (state->market_tab_state == MarketTabStateTable) {
should_quit = true;
} else {
state->market_tab_state = MarketTabStateTable; state->market_tab_state = MarketTabStateTable;
} }
}
u32 line = box.y + 1; u32 line = box.y + 1;
@@ -1422,13 +1415,9 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
} break; } break;
case TabPassengers: { case TabPassengers: {
if (input_buffer[0] == 'q' || user_pressed_esc) { if (input_buffer[0] == 'q' || user_pressed_esc || user_pressed_backspace) {
if (state->passenger_tab_state == PassengersTabStateTable) {
should_quit = true;
} else {
state->passenger_tab_state = PassengersTabStateTable; state->passenger_tab_state = PassengersTabStateTable;
} }
}
u32 line = box.y + 1; u32 line = box.y + 1;
+32 -41
View File
@@ -32,7 +32,7 @@
#define CHUNK_SIZE 64 #define CHUNK_SIZE 64
#define ACCOUNT_LEN (16) #define ACCOUNT_LEN (16)
#define PARSED_CLIENT_COMMAND_THREAD_QUEUE_LEN 64 #define PARSED_CLIENT_COMMAND_THREAD_QUEUE_LEN 64
#define SYSTEM_MESSAGES_LEN 32 #define SYSTEM_MESSAGES_LEN 40
#define MAX_SYSTEM_MESSAGE_LEN 512 #define MAX_SYSTEM_MESSAGE_LEN 512
#define SBUFLEN (512) #define SBUFLEN (512)
@@ -106,6 +106,7 @@ typedef struct State {
u64 frame; u64 frame;
Arena game_scratch; Arena game_scratch;
StringArena string_arena; StringArena string_arena;
String server_ip_address;
ParsedClientCommandThreadQueue* network_recv_queue; ParsedClientCommandThreadQueue* network_recv_queue;
OutgoingMessageQueue* network_send_queue; OutgoingMessageQueue* network_send_queue;
StarSystem map[STAR_SYSTEM_COUNT]; StarSystem map[STAR_SYSTEM_COUNT];
@@ -1185,8 +1186,11 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
state->tab = state->tab == TabDebug ? TabMap : TabDebug; state->tab = state->tab == TabDebug ? TabMap : TabDebug;
} }
// show what ip to connect to
renderStrToBuffer(tui->frame_buffer, screen_dimensions.width - 18, 1, state->server_ip_address.bytes, screen_dimensions);
// draw the tabs box // draw the tabs box
u32 tabs_y = 1; u32 tabs_y = 0;
u32 box_y = tabs_y + 2; u32 box_y = tabs_y + 2;
Box box = { Box box = {
.x = 1, .x = 1,
@@ -1355,6 +1359,18 @@ i32 main(i32 argc, ptr argv[]) {
system_messages[i].length = 0; system_messages[i].length = 0;
system_messages[i].items = arenaAllocArraySized(&permanent_arena, sizeof(u8), MAX_SYSTEM_MESSAGE_LEN); system_messages[i].items = arenaAllocArraySized(&permanent_arena, sizeof(u8), MAX_SYSTEM_MESSAGE_LEN);
} }
state.server_ip_address.bytes = arenaAllocArraySized(&permanent_arena, sizeof(u8), 16);
state.server_ip_address.capacity = 16;
{
struct ifaddrs* ifaddr, *ifa;
getifaddrs(&ifaddr);
for (ifa = ifaddr; ifa; ifa = ifa->ifa_next) {
if (!ifa->ifa_addr || ifa->ifa_addr->sa_family != AF_INET) continue;
if (strcmp(ifa->ifa_name, "en0") != 0) continue;
inet_ntop(AF_INET, &((struct sockaddr_in*)ifa->ifa_addr)->sin_addr, state.server_ip_address.bytes, 16);
}
freeifaddrs(ifaddr);
}
// GAME LOGIC SETUP // GAME LOGIC SETUP
@@ -1393,80 +1409,58 @@ i32 main(i32 argc, ptr argv[]) {
p->commodities[iii] = (COMMODITIES[iii].qty / 5) + (rand() % COMMODITIES[iii].qty); p->commodities[iii] = (COMMODITIES[iii].qty / 5) + (rand() % COMMODITIES[iii].qty);
p->production[iii] = 1 + (rand() % COMMODITIES[iii].consumption); p->production[iii] = 1 + (rand() % COMMODITIES[iii].consumption);
} }
p->commodities[CommodityHydrogenFuel] = COMMODITIES[CommodityHydrogenFuel].qty * 2;
p->commodities[CommodityOxygen] = COMMODITIES[CommodityOxygen].qty * 2;
// now, override for the "specialty" of the planet // now, override for the "specialty" of the planet
switch (p->type) { switch (p->type) {
case PlanetTypeEarth: { case PlanetTypeEarth: {
setHighProductionCommodity(p, CommodityWater); setHighProductionCommodity(p, CommodityWater);
setHighProductionCommodity(p, CommodityFertilizer); setHighProductionCommodity(p, CommodityFood);
setHighProductionCommodity(p, CommodityGrain);
setHighProductionCommodity(p, CommodityMeat);
setHighProductionCommodity(p, CommoditySpices);
setHighProductionCommodity(p, CommodityAlcohol);
setLowProductionCommodity(p, CommodityHydrogenFuel); setLowProductionCommodity(p, CommodityHydrogenFuel);
setLowProductionCommodity(p, CommodityLowGradeOre); setLowProductionCommodity(p, CommodityOre);
setLowProductionCommodity(p, CommodityHighGradeOre); setLowProductionCommodity(p, CommodityMetals);
setLowProductionCommodity(p, CommodityCommonMetals);
setLowProductionCommodity(p, CommodityRareMetals);
//setLowProductionCommodity(p, CommodityPreciousMetals);
} break; } break;
case PlanetTypeGas: { case PlanetTypeGas: {
// a lot of fuel and chemicals // a lot of fuel and chemicals
setHighProductionCommodity(p, CommodityHydrogenFuel); setHighProductionCommodity(p, CommodityHydrogenFuel);
setHighProductionCommodity(p, CommodityOxygen); setHighProductionCommodity(p, CommodityOxygen);
setHighProductionCommodity(p, CommodityWater); setHighProductionCommodity(p, CommodityWater);
setHighProductionCommodity(p, CommodityIndustrialChemicals);
setHighProductionCommodity(p, CommodityPlastics); setHighProductionCommodity(p, CommodityPlastics);
setLowProductionCommodity(p, CommodityLowGradeOre); setLowProductionCommodity(p, CommodityOre);
setLowProductionCommodity(p, CommodityHighGradeOre); setLowProductionCommodity(p, CommodityMetals);
setLowProductionCommodity(p, CommodityCommonMetals);
setLowProductionCommodity(p, CommodityRareMetals);
//setLowProductionCommodity(p, CommodityPreciousMetals);
setLowProductionCommodity(p, CommodityClothes);
setLowProductionCommodity(p, CommodityRawTextiles); setLowProductionCommodity(p, CommodityRawTextiles);
setLowProductionCommodity(p, CommodityGlass); setLowProductionCommodity(p, CommodityGlass);
setLowProductionCommodity(p, CommodityPersonalSundries);
setLowProductionCommodity(p, CommodityHandTools); setLowProductionCommodity(p, CommodityHandTools);
setLowProductionCommodity(p, CommodityMeat);
} break; } break;
case PlanetTypeMoon: { case PlanetTypeMoon: {
// a lot of manufactured goods // a lot of manufactured goods
setHighProductionCommodity(p, CommodityPersonalSundries);
setHighProductionCommodity(p, CommodityClothes);
setHighProductionCommodity(p, CommodityAlcohol);
setHighProductionCommodity(p, CommodityElectronics); setHighProductionCommodity(p, CommodityElectronics);
setHighProductionCommodity(p, CommodityGlass);
setLowProductionCommodity(p, CommodityHighGradeOre); setLowProductionCommodity(p, CommodityOre);
setLowProductionCommodity(p, CommodityHydrogenFuel); setLowProductionCommodity(p, CommodityHydrogenFuel);
setLowProductionCommodity(p, CommodityOxygen); setLowProductionCommodity(p, CommodityOxygen);
setLowProductionCommodity(p, CommodityWater); setLowProductionCommodity(p, CommodityWater);
setLowProductionCommodity(p, CommodityFertilizer); setLowProductionCommodity(p, CommodityFood);
} break; } break;
case PlanetTypeAsteroid: { case PlanetTypeAsteroid: {
// a lot of raw metals // a lot of raw metals
setHighProductionCommodity(p, CommodityLowGradeOre); setHighProductionCommodity(p, CommodityOre);
setHighProductionCommodity(p, CommodityHighGradeOre); setHighProductionCommodity(p, CommodityMetals);
setHighProductionCommodity(p, CommodityCommonMetals);
setHighProductionCommodity(p, CommodityRareMetals);
//setHighProductionCommodity(p, CommodityPreciousMetals);
setHighProductionCommodity(p, CommoditySemiConductors); setHighProductionCommodity(p, CommoditySemiConductors);
setLowProductionCommodity(p, CommodityHydrogenFuel); setLowProductionCommodity(p, CommodityHydrogenFuel);
setLowProductionCommodity(p, CommodityOxygen); setLowProductionCommodity(p, CommodityOxygen);
setLowProductionCommodity(p, CommodityWater); setLowProductionCommodity(p, CommodityWater);
setLowProductionCommodity(p, CommodityFertilizer); setLowProductionCommodity(p, CommodityFood);
setLowProductionCommodity(p, CommodityPersonalSundries);
setLowProductionCommodity(p, CommodityClothes);
setLowProductionCommodity(p, CommodityElectronics); setLowProductionCommodity(p, CommodityElectronics);
setLowProductionCommodity(p, CommodityPlastics); setLowProductionCommodity(p, CommodityPlastics);
setLowProductionCommodity(p, CommodityHandTools); setLowProductionCommodity(p, CommodityHandTools);
} break; } break;
case PlanetTypeStation: { case PlanetTypeStation: {
// a lot of ??? drugs? // a lot of ??? drugs?
setHighProductionCommodity(p, CommodityAlcohol);
setHighProductionCommodity(p, CommodityPersonalSundries);
setHighProductionCommodity(p, CommodityClothes);
setHighProductionCommodity(p, CommodityElectronics); setHighProductionCommodity(p, CommodityElectronics);
setHighProductionCommodity(p, CommodityPlastics); setHighProductionCommodity(p, CommodityPlastics);
setHighProductionCommodity(p, CommodityHandTools); setHighProductionCommodity(p, CommodityHandTools);
@@ -1474,10 +1468,7 @@ i32 main(i32 argc, ptr argv[]) {
setLowProductionCommodity(p, CommodityHydrogenFuel); setLowProductionCommodity(p, CommodityHydrogenFuel);
setLowProductionCommodity(p, CommodityOxygen); setLowProductionCommodity(p, CommodityOxygen);
setLowProductionCommodity(p, CommodityWater); setLowProductionCommodity(p, CommodityWater);
setLowProductionCommodity(p, CommodityFertilizer); setLowProductionCommodity(p, CommodityFood);
setLowProductionCommodity(p, CommodityMeat);
setLowProductionCommodity(p, CommodityGrain);
setLowProductionCommodity(p, CommoditySpices);
} break; } break;
case PlanetTypeNull: case PlanetTypeNull:
case PlanetType_Count: case PlanetType_Count:
+31 -98
View File
@@ -8,7 +8,7 @@
#define STARTING_DOWN_PAYMENT (10000) #define STARTING_DOWN_PAYMENT (10000)
#define SHIP_DETAIL_COUNT (8) #define SHIP_DETAIL_COUNT (8)
#define STAR_SYSTEM_COUNT (16) #define STAR_SYSTEM_COUNT (16)
#define MAP_WIDTH (36) #define MAP_WIDTH (32)
#define MAP_HEIGHT (12) #define MAP_HEIGHT (12)
#define MAX_PLANETS (3) #define MAX_PLANETS (3)
#define MAX_PASSENGER_JOB_OFFERS (16) #define MAX_PASSENGER_JOB_OFFERS (16)
@@ -87,36 +87,19 @@ global FieldDescriptor SHIP_FIELDS[SHIP_DETAIL_COUNT] = {
{ "O2 Tank", FieldTypeU32, offsetof(ShipTemplate, cu_m_o2), 8 }, { "O2 Tank", FieldTypeU32, offsetof(ShipTemplate, cu_m_o2), 8 },
}; };
typedef enum EquipmentType {
EquipmentTypeAquaponicsSystem,
EquipmentType3DPrinter,
EquipmentTypeAutoTailor,
EquipmentType_Count,
} EquipmentType;
typedef enum CommodityType { typedef enum CommodityType {
CommodityHydrogenFuel, CommodityHydrogenFuel,
CommodityOxygen, CommodityOxygen,
CommodityWater, CommodityWater,
CommodityFertilizer, CommodityFood,
CommodityRawTextiles, CommodityRawTextiles,
CommodityLowGradeOre, CommodityOre,
CommodityHighGradeOre,
CommodityPlastics, CommodityPlastics,
CommodityGrain, CommoditySemiConductors,
CommodityMeat, CommodityMetals,
CommoditySpices,
CommodityElectronics,
CommodityGlass, CommodityGlass,
CommodityHandTools, CommodityHandTools,
CommoditySemiConductors, CommodityElectronics,
CommodityCommonMetals,
CommodityRareMetals,
// CommodityPreciousMetals,
CommodityAlcohol,
CommodityClothes,
CommodityPersonalSundries,
CommodityIndustrialChemicals,
Commodity_Count, Commodity_Count,
} CommodityType; } CommodityType;
@@ -124,25 +107,15 @@ global str COMMODITY_STRINGS[Commodity_Count] = {
"Hydrogen Fuel", "Hydrogen Fuel",
"Oxygen", "Oxygen",
"Water", "Water",
"Fertilizer", "Food",
"Raw Textiles", "Raw Textiles",
"Low Grade Ore", "Ore",
"High Grade Ore",
"Plastics", "Plastics",
"Grain", "Semi-conductors",
"Meat", "Metals",
"Spices",
"Electronics",
"Glass", "Glass",
"Hand Tools", "Hand Tools",
"Semi-conductors",//"Semi-conductors (Silicon, Arsenic, Boron)", "Electronics",
"Common Metals",//"Common Metals (Iron, Nickel, Zinc)",
"Rare Metals",//"Rare Metals (Titanium, Chromium)",
// "Precious Metals (Silver, Gold, Platinum)",
"Alcohol",
"Clothes",
"Personal Sundries",//"Personal Sundries (Cutlery, Toys, Misc)",
"Industrial Chemicals",
}; };
typedef enum StorageUnit { typedef enum StorageUnit {
@@ -178,83 +151,43 @@ global Commodity COMMODITIES[Commodity_Count] = {
}, },
{ .type = CommodityWater, .unit = StorageUnitContainer, { .type = CommodityWater, .unit = StorageUnitContainer,
.name = "Water", .name = "Water",
.price = 700, .qty = 100, .consumption = 10, .price = 100, .qty = 100, .consumption = 10,
}, },
{ .type = CommodityFertilizer, .unit = StorageUnitContainer, { .type = CommodityFood, .unit = StorageUnitContainer,
.name = "Fertilizer", .name = "Food",
.price = 1200, .qty = 70, .consumption = 10, .price = 200, .qty = 70, .consumption = 10,
}, },
{ .type = CommodityRawTextiles, .unit = StorageUnitContainer, { .type = CommodityRawTextiles, .unit = StorageUnitContainer,
.name = "Raw Textiles", .name = "Raw Textiles",
.price = 1800, .qty = 40, .consumption = 3, .price = 500, .qty = 40, .consumption = 3,
}, },
{ .type = CommodityLowGradeOre, .unit = StorageUnitContainer, { .type = CommodityOre, .unit = StorageUnitContainer,
.name = "Low Grade Ore", .name = "Ore",
.price = 800, .qty = 100, .consumption = 8, .price = 1000, .qty = 100, .consumption = 8,
},
{ .type = CommodityHighGradeOre, .unit = StorageUnitContainer,
.name = "High Grade Ore",
.price = 1200, .qty = 10, .consumption = 2,
}, },
{ .type = CommodityPlastics, .unit = StorageUnitContainer, { .type = CommodityPlastics, .unit = StorageUnitContainer,
.name = "Plastics", .name = "Plastics",
.price = 2000, .qty = 30, .consumption = 5, .price = 2000, .qty = 30, .consumption = 5,
}, },
{ .type = CommodityGrain, .unit = StorageUnitContainer, { .type = CommoditySemiConductors, .unit = StorageUnitContainer,
.name = "Grain", .name = "Semi-conductors",
.price = 1900, .qty = 200, .consumption = 30, .price = 4000, .qty = 40, .consumption = 3,
}, },
{ .type = CommodityMeat, .unit = StorageUnitContainer, { .type = CommodityMetals, .unit = StorageUnitContainer,
.name = "Meat", .name = "Metals",
.price = 2100, .qty = 90, .consumption = 15, .price = 5000, .qty = 40, .consumption = 3,
},
{ .type = CommoditySpices, .unit = StorageUnitContainer,
.name = "Spices",
.price = 3900, .qty = 6, .consumption = 1,
},
{ .type = CommodityElectronics, .unit = StorageUnitContainer,
.name = "Electronics",
.price = 9500, .qty = 40, .consumption = 6,
}, },
{ .type = CommodityGlass, .unit = StorageUnitContainer, { .type = CommodityGlass, .unit = StorageUnitContainer,
.name = "Glass", .name = "Glass",
.price = 1400, .qty = 50, .consumption = 5, .price = 9200, .qty = 50, .consumption = 5,
}, },
{ .type = CommodityHandTools, .unit = StorageUnitContainer, { .type = CommodityHandTools, .unit = StorageUnitContainer,
.name = "Hand Tools", .name = "Hand Tools",
.price = 5000, .qty = 5, .consumption = 1, .price = 20000, .qty = 5, .consumption = 1,
}, },
{ .type = CommoditySemiConductors, .unit = StorageUnitContainer, { .type = CommodityElectronics, .unit = StorageUnitContainer,
.name = "Semi-conductors",//"Semi-conductors (Silicon, Arsenic, Boron)", .name = "Electronics",
.price = 1800, .qty = 40, .consumption = 3, .price = 40000, .qty = 40, .consumption = 6,
},
{ .type = CommodityCommonMetals, .unit = StorageUnitContainer,
.name = "Common Metals",//"Common Metals (Iron, Nickel, Zinc)",
.price = 1800, .qty = 40, .consumption = 3,
},
{ .type = CommodityRareMetals, .unit = StorageUnitContainer,
.name = "Rare Metals",//"Rare Metals (Titanium, Chromium)",
.price = 1800, .qty = 40, .consumption = 3,
},
/* { .type = CommodityPreciousMetals, .unit = StorageUnitKg,
.name = "Precious Metals (Silver, Gold, Platinum)",
.price = 1800, .qty = 40, .consumption = 3,
},*/
{ .type = CommodityAlcohol, .unit = StorageUnitContainer,
.name = "Alcohol",
.price = 1800, .qty = 40, .consumption = 3,
},
{ .type = CommodityClothes, .unit = StorageUnitContainer,
.name = "Clothes",
.price = 1800, .qty = 40, .consumption = 3,
},
{ .type = CommodityPersonalSundries, .unit = StorageUnitContainer,
.name = "Personal Sundries",//"Personal Sundries (Cutlery, Toys, Misc)",
.price = 1800, .qty = 40, .consumption = 3,
},
{ .type = CommodityIndustrialChemicals, .unit = StorageUnitContainer,
.name = "Industrial Chemicals",
.price = 3800, .qty = 20, .consumption = 5,
}, },
}; };
@@ -471,7 +404,7 @@ static const char* MESSAGE_STRINGS[] = {
fn u32 fuelCostForTravel(u32 drive_efficiency, Pos2 current, Pos2 dest) { fn u32 fuelCostForTravel(u32 drive_efficiency, Pos2 current, Pos2 dest) {
u32 x_distance = Max(current.x, dest.x) - Min(current.x, dest.x); 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 y_distance = Max(current.y, dest.y) - Min(current.y, dest.y);
u32 fuel_per_dist = 100 - drive_efficiency; u32 fuel_per_dist = 100 - drive_efficiency*10;
return (x_distance + y_distance) * fuel_per_dist; return (x_distance + y_distance) * fuel_per_dist;
} }