working on the trading menu
This commit is contained in:
+54
-1
@@ -85,6 +85,7 @@ typedef struct ParsedServerMessage {
|
||||
XYZ xyz;
|
||||
Pos2u8 positions[STAR_SYSTEM_COUNT];
|
||||
PlanetType planet_types[MAX_PLANETS*STAR_SYSTEM_COUNT];
|
||||
StarSystem sys;
|
||||
//Entity entities[PARSED_CLIENT_ENTITY_LEN];
|
||||
//u64 ids[PARSED_IDS_LEN];
|
||||
} ParsedServerMessage;
|
||||
@@ -130,6 +131,7 @@ typedef struct GameState {
|
||||
StringChunkList message_input;
|
||||
StarSystem map[STAR_SYSTEM_COUNT];
|
||||
Pos2 pos;
|
||||
StarSystem current;
|
||||
} GameState;
|
||||
|
||||
///// GLOBALS
|
||||
@@ -380,6 +382,15 @@ fn void handleIncomingMessage(u8* message, u32 len, SocketAddress sender, i32 so
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case MessageSystemCommodities: {
|
||||
parsed.id = (u64)message[msg_pos++];
|
||||
u32 planet_count = message[msg_pos++];
|
||||
for (u32 i = 0; i < planet_count; i++) {
|
||||
for (u32 ii = 0; ii < Commodity_Count; ii++) {
|
||||
parsed.sys.planets[i].commodities[ii] = message[msg_pos++];
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case MessageCharacterId: {
|
||||
parsed.id = readU64FromBufferLE(message + 1);
|
||||
} break;
|
||||
@@ -450,6 +461,15 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case MessageSystemCommodities: {
|
||||
u32 sys_idx = msg.id;
|
||||
state->current.name = STAR_NAMES[sys_idx];
|
||||
for (u32 i = 0; i < MAX_PLANETS; i++) {
|
||||
for (u32 ii = 0; ii < Commodity_Count; ii++) {
|
||||
state->current.planets[i].commodities[ii] = msg.sys.planets[i].commodities[ii];
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case MessageNewAccountCreated: {
|
||||
state->screen = ScreenCreateCharacter;
|
||||
} break;
|
||||
@@ -710,7 +730,40 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
|
||||
}
|
||||
} break;
|
||||
case TabShip: {} break;
|
||||
case TabStation: {} break;
|
||||
case TabStation: {
|
||||
renderStrToBuffer(tui->frame_buffer, box.x+2, box.y+1, "Welcome to ", screen_dimensions);
|
||||
renderStrToBuffer(tui->frame_buffer, box.x+2+11, box.y+1, state->current.name, screen_dimensions);
|
||||
|
||||
char tmp_buffer[64] = {0};
|
||||
u32 table_x = box.x+2;
|
||||
u32 line = box.y+3;
|
||||
str cols[4] = {"Commodity", "#", "Bid", "Ask"};
|
||||
u32 lens[4] = { 24, 6, 6, 6};
|
||||
u32 col_x_pos = 0;
|
||||
// render headers
|
||||
for (u32 i = 0; i < 4; col_x_pos += lens[i++]) {
|
||||
renderStrToBuffer(tui->frame_buffer, table_x+col_x_pos, line, cols[i], screen_dimensions);
|
||||
for (u32 ii = 0; ii < lens[i]; ii++) {
|
||||
renderUtf8CharToBuffer(tui->frame_buffer, table_x+col_x_pos+ii, line+1, "━", screen_dimensions);
|
||||
}
|
||||
}
|
||||
line += 2;
|
||||
// render rows
|
||||
for (u32 i = 0; i < Commodity_Count; i++) {
|
||||
col_x_pos = 0;
|
||||
for (u32 ii = 0; ii < 4; col_x_pos += lens[ii++]) {
|
||||
MemoryZero(tmp_buffer, 64);
|
||||
if (ii == 0) {
|
||||
sprintf(tmp_buffer, "%s", COMMODITY_STRINGS[i]);
|
||||
} else if (ii == 1) {
|
||||
sprintf(tmp_buffer, "%d", state->current.planets[0].commodities[i]);
|
||||
} else {
|
||||
tmp_buffer[0] = '-';
|
||||
}
|
||||
renderStrToBuffer(tui->frame_buffer, table_x+col_x_pos, line+i, tmp_buffer, screen_dimensions);
|
||||
}
|
||||
}
|
||||
} break;
|
||||
case Tab_Count: {} break;
|
||||
}
|
||||
} break;
|
||||
|
||||
@@ -70,6 +70,7 @@ typedef struct Entity {
|
||||
|
||||
typedef struct Account {
|
||||
u32 id; // the index in the array
|
||||
Pos2 pos;
|
||||
String name;
|
||||
String pw;
|
||||
PlayerShip ship;
|
||||
@@ -618,6 +619,10 @@ fn void* gameLoop(void* params) {
|
||||
};
|
||||
account.ship = player_ship;
|
||||
printf("ship_type=%s, client_handle=%d, acct_id=%d\n", SHIP_TYPE_STRINGS[msg.byte], client_handle, account.id);
|
||||
u32 starting_system_idx = rand() % STAR_SYSTEM_COUNT;
|
||||
StarSystem starting_system = state.map[starting_system_idx];
|
||||
account.pos.x = starting_system.x;
|
||||
account.pos.y = starting_system.y;
|
||||
|
||||
// tell the client their account id
|
||||
outgoing_message.address = sender;
|
||||
@@ -641,6 +646,26 @@ fn void* gameLoop(void* params) {
|
||||
}
|
||||
outgoingMessageQueuePush(state.network_send_queue, &outgoing_message);
|
||||
printf("%s sent\n", MESSAGE_STRINGS[outgoing_message.bytes[0]]);
|
||||
|
||||
u32 planet_count = 0;
|
||||
for (u32 i = 0; i < MAX_PLANETS; i++) {
|
||||
if (starting_system.planets[i].type != PlanetTypeNull) {
|
||||
planet_count++;
|
||||
}
|
||||
}
|
||||
outgoing_message.bytes_len = 1 + 1 + 1 + (planet_count * Commodity_Count);
|
||||
u32 msg_i = 0;
|
||||
outgoing_message.bytes[msg_i++] = (u8)MessageSystemCommodities;
|
||||
outgoing_message.bytes[msg_i++] = (u8)starting_system_idx;
|
||||
outgoing_message.bytes[msg_i++] = (u8)planet_count;
|
||||
for (u32 i = 0; i < planet_count; i++) {
|
||||
for (u32 ii = 0; ii < Commodity_Count; ii++) {
|
||||
outgoing_message.bytes[msg_i++] = starting_system.planets[i].commodities[ii];
|
||||
}
|
||||
}
|
||||
outgoingMessageQueuePush(state.network_send_queue, &outgoing_message);
|
||||
printf("%s sent\n", MESSAGE_STRINGS[outgoing_message.bytes[0]]);
|
||||
|
||||
} else {
|
||||
printf("client tried to create a character when he already has one.");
|
||||
}
|
||||
@@ -731,6 +756,10 @@ i32 main(i32 argc, ptr argv[]) {
|
||||
u32 planet_count = rand() % MAX_PLANETS + 1;
|
||||
for (u32 ii = 0; ii < planet_count; ii++) {
|
||||
state.map[i].planets[ii].type = 1+(PlanetType)(rand() % (PlanetType_Count -1));
|
||||
for (u32 iii = 0; iii < Commodity_Count; iii++) {
|
||||
state.map[i].planets[ii].commodities[iii] = rand() % 1000;
|
||||
state.map[i].planets[ii].production[iii] = rand() % 10;
|
||||
}
|
||||
switch (state.map[i].planets[ii].type) {
|
||||
case PlanetTypeEarth: {
|
||||
// TODO: roll the initial commodity counts
|
||||
|
||||
+26
-87
@@ -151,70 +151,23 @@ typedef enum CommodityType {
|
||||
CommodityHydrogenFuel,
|
||||
CommodityOxygen,
|
||||
CommodityWater,
|
||||
CommodityFertilizer,
|
||||
CommodityRawTextiles,
|
||||
CommodityLowGradeOre,
|
||||
CommodityHighGradeOre,
|
||||
CommodityPlastics,
|
||||
CommodityGrain,
|
||||
CommodityMeat,
|
||||
CommoditySpices,
|
||||
CommodityElectronics,
|
||||
CommodityGlass,
|
||||
CommodityHandTools,
|
||||
CommoditySemiConductors,
|
||||
CommodityCommonMetals,
|
||||
CommodityRareMetals,
|
||||
CommodityAlcohol,
|
||||
CommodityClothes,
|
||||
CommodityRawTextiles,
|
||||
//CommodityWheat,
|
||||
//CommodityRice,
|
||||
//CommodityCorn,
|
||||
//CommodityPotatoes,
|
||||
//CommodityBeef,
|
||||
//CommodityChicken,
|
||||
//CommodityButter,
|
||||
//CommodityOliveOil,
|
||||
//CommodityLiquor,
|
||||
//CommodityBeer,
|
||||
//CommodityFertilizer,
|
||||
//CommodityCleaningSupplies,
|
||||
//CommodityAirFilters,
|
||||
//CommodityIndustrialChemicals,
|
||||
//CommodityElectronics,
|
||||
//CommodityConstructionParts,
|
||||
//Commodity3dPrinterParts,
|
||||
//CommodityHandTools,
|
||||
//CommodityCutlery,
|
||||
//CommodityRobots,
|
||||
//CommodityPlastics,
|
||||
//CommodityHandWeapons,
|
||||
//CommodityBatteries,
|
||||
//CommoditySolarPanels,
|
||||
//CommodityMedicines,
|
||||
//CommodityOpticalComponents,
|
||||
//CommodityGlass,
|
||||
//CommodityLithium,
|
||||
//CommodityBerylium,
|
||||
//CommodityMagnesium,
|
||||
//CommodityAluminium,
|
||||
//CommoditySilicon,
|
||||
//CommodityScandium,
|
||||
//CommodityTitanium,
|
||||
//CommodityVanadium,
|
||||
//CommodityChromium,
|
||||
//CommodityManganese,
|
||||
//CommodityIron,
|
||||
//CommodityCobalt,
|
||||
//CommodityNickel,
|
||||
//CommodityCopper,
|
||||
//CommodityZinc,
|
||||
//CommoditySelenium,
|
||||
//CommodityZirconium,
|
||||
//CommodityMolybdenum,
|
||||
//CommodityRuthenium,
|
||||
//CommodityRhodium,
|
||||
//CommodityPalladium,
|
||||
//CommoditySilver,
|
||||
//CommodityCadmium,
|
||||
//CommodityTin,
|
||||
//CommodityTungsten,
|
||||
//CommodityRhenium,
|
||||
//CommodityIridium,
|
||||
//CommodityPlatinum,
|
||||
//CommodityGold,
|
||||
//CommodityMercury,
|
||||
//CommodityLead,
|
||||
CommodityPersonalSundries,
|
||||
Commodity_Count,
|
||||
} CommodityType;
|
||||
|
||||
@@ -222,39 +175,23 @@ static const char* COMMODITY_STRINGS[] = {
|
||||
"Hydrogen Fuel",
|
||||
"Oxygen",
|
||||
"Water",
|
||||
"Fertilizer",
|
||||
"Raw Textiles",
|
||||
"Low grade Ore",
|
||||
"High grade Ore",
|
||||
"Plastics",
|
||||
"Grain",
|
||||
"Meat",
|
||||
"Spices",
|
||||
"Electronics",
|
||||
"Glass",
|
||||
"Hand Tools",
|
||||
"Semi-conductors (Silicon, Arsenic, Boron)",
|
||||
"Common Metals (Iron, Nickel, Zinc)",
|
||||
"Rare Metals (Titanium, Chromium)",
|
||||
"Alcohol",
|
||||
"Clothes",
|
||||
"Raw Textiles",
|
||||
//"Wheat",
|
||||
//"Rice",
|
||||
//"Corn",
|
||||
//"Potatoes",
|
||||
//"Beef",
|
||||
//"Chicken",
|
||||
//"Butter",
|
||||
//"Olive Oil",
|
||||
//"Liquor",
|
||||
//"Beer",
|
||||
//"Fertilizer",
|
||||
//"Cleaning Supplies",
|
||||
//"Air Filters",
|
||||
//"Industrial Chemicals",
|
||||
//"Electronics",
|
||||
//"Construction Parts",
|
||||
//"3d Printer Parts",
|
||||
//"Hand Tools",
|
||||
//"Cutlery",
|
||||
//"Robots",
|
||||
//"Plastics",
|
||||
//"Hand Weapons",
|
||||
//"Batteries",
|
||||
//"Solar Panels",
|
||||
//"Medicines",
|
||||
//"Optical Components",
|
||||
//"Glass",
|
||||
"Personal Sundries (Cutlery, Storage, Buckles, Toys, Furnishings)",
|
||||
};
|
||||
|
||||
typedef struct Commodity {
|
||||
@@ -371,6 +308,7 @@ typedef enum Message {
|
||||
MessageBadPw,
|
||||
MessageNewAccountCreated,
|
||||
MessageStarPositions,
|
||||
MessageSystemCommodities,
|
||||
Message_Count,
|
||||
} Message;
|
||||
static const char* MESSAGE_STRINGS[] = {
|
||||
@@ -379,6 +317,7 @@ static const char* MESSAGE_STRINGS[] = {
|
||||
"BadPw",
|
||||
"NewAccountCreated",
|
||||
"StarPositions",
|
||||
"SystemCommodities",
|
||||
};
|
||||
|
||||
#endif //GAMESHARED_H
|
||||
|
||||
Reference in New Issue
Block a user