diff --git a/README.md b/README.md index 2470fbd..fc1f8a4 100644 --- a/README.md +++ b/README.md @@ -45,6 +45,9 @@ space-trader-multiplayer-boardgame-esque: - players can trade with each other while at the same station - certain stations have shipyards, with mortgages available for trade-in/upgrading ships drives/storage capacity, etc. - all systems have a safety rating, indicating likelyhood of piracy. High risk systems often have higher profitablilty + - "safe" stations have high risk of being inspected for illegal goods + - "criminal" stations have high risk of piracy + - but it's always a dice roll that some event happens at all when you arrive in system. - AI station trading agent for haggling deal-making? - transport contracts available at stations randomly. - in a system, you can fly out to the asteroid belt and try to buy from miners directly, but it's a gamble on even finding any of them. diff --git a/src/server.c b/src/server.c index 0076117..a74d415 100644 --- a/src/server.c +++ b/src/server.c @@ -121,6 +121,7 @@ typedef struct State { StringArena string_arena; ParsedClientCommandThreadQueue* network_recv_queue; OutgoingMessageQueue* network_send_queue; + StarSystem map[STAR_SYSTEM_COUNT]; } State; ///// Global Variables @@ -695,6 +696,48 @@ i32 main(i32 argc, ptr argv[]) { state.clients.capacity = SERVER_MAX_CLIENTS; state.clients.length = 1; // making entry 0 to be a "null" client state.clients.items = (Client*)arenaAllocArray(&permanent_arena, Client, SERVER_MAX_CLIENTS); + // set position of all star systems + for (u32 i = 0; i < STAR_SYSTEM_COUNT; i++) { + state.map[i].name = STAR_NAMES[i]; + state.map[i].crime = rand() % 100; + state.map[i].x = rand() % MAP_WIDTH; + state.map[i].y = rand() % MAP_HEIGHT; + bool conflicting_pos = false; + for (u32 ii = 0; ii < i; ii++) { + if (state.map[ii].x == state.map[i].x && state.map[ii].y == state.map[i].y) { + conflicting_pos = true; + } + } + if (conflicting_pos) { + i--; + } + } + for (u32 i = 0; i < STAR_SYSTEM_COUNT; i++) { + u32 planet_count = rand() % MAX_PLANETS + 1; + for (u32 ii = 0; ii < planet_count; ii++) { + state.map[i].planets[ii].type = (PlanetType)(rand() % PlanetType_Count); + switch (state.map[i].planets[ii].type) { + case PlanetTypeEarth: { + // TODO: roll the initial commodity counts + // AND roll the initial (excess) production levels + // earth planets do a lot of food + } break; + case PlanetTypeGas: { + // a lot of fuel and chemicals + } break; + case PlanetTypeMoon: { + // a lot of manufactured goods + } break; + case PlanetTypeAsteroid: { + // a lot of raw metals + } break; + case PlanetTypeStation: { + // a lot of ??? drugs? + } break; + case PlanetType_Count: {} break; + } + } + } // 2. spin off sendNetworkUpdates() infinite loop thread UDPServer listener = createUDPServer(SERVER_PORT); diff --git a/src/shared.h b/src/shared.h index 8fefef4..a3d7619 100644 --- a/src/shared.h +++ b/src/shared.h @@ -6,7 +6,10 @@ ///// #define some game-tunable constants #define STARTING_DOWN_PAYMENT (10000) -#define GAME_CONSTANT_TWO (2) +#define STAR_SYSTEM_COUNT (40) +#define MAP_WIDTH (40) +#define MAP_HEIGHT (10) +#define MAX_PLANETS (16) typedef enum EntityFeature { FeatureWalksAround, @@ -52,6 +55,7 @@ typedef struct ShipTemplate { u16 smugglers_hold_cu_m; u32 base_cost; } ShipTemplate; + global ShipTemplate SHIPS[] = { { .type = ShipSparrow, .drive_efficiency = 1, .life_support_efficiency = 2, @@ -136,107 +140,121 @@ typedef struct PlayerShip { u64 id; } PlayerShip; +typedef enum EquipmentType { + EquipmentTypeAquaponicsSystem, + EquipmentType3DPrinter, + EquipmentTypeAutoTailor, + EquipmentType_Count, +} EquipmentType; + typedef enum CommodityType { - CommodityNull, CommodityHydrogenFuel, CommodityOxygen, CommodityWater, - CommodityWheat, - CommodityRice, - CommodityCorn, - CommodityPotatoes, - CommodityBeef, - CommodityChicken, - CommodityButter, - CommodityOliveOil, - CommodityLiquor, - CommodityBeer, - CommodityFertilizer, - CommodityCleaningSupplies, - CommodityAirFilters, - CommodityIndustrialChemicals, + CommodityGrain, + CommodityMeat, + CommoditySpices, + CommodityAlcohol, CommodityClothes, CommodityRawTextiles, - 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, + //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, Commodity_Count, } CommodityType; + static const char* COMMODITY_STRINGS[] = { - "NULL", "Hydrogen Fuel", "Oxygen", "Water", - "Wheat", - "Rice", - "Corn", - "Potatoes", - "Beef", - "Chicken", - "Butter", - "Olive Oil", - "Liquor", - "Beer", - "Fertilizer", - "Cleaning Supplies", - "Air Filters", - "Industrial Chemicals", + "Grain", + "Meat", + "Spices", + "Alcohol", "Clothes", "Raw Textiles", - "Electronics", - "Construction Parts", - "3d Printer Parts", - "Hand Tools", - "Cutlery", - "Robots", - "Plastics", - "Hand Weapons", - "Batteries", - "Solar Panels", - "Medicines", - "Optical Components", - "Glass", + //"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", }; typedef struct Commodity { @@ -247,17 +265,72 @@ typedef struct Commodity { u32 m3_per_kg; } Commodity; -typedef struct StarSystem { - StringChunkList name; -} StarSystem; +typedef enum PlanetType { + PlanetTypeEarth, + PlanetTypeGas, + PlanetTypeMoon, + PlanetTypeAsteroid, + PlanetTypeStation, + PlanetType_Count, +} PlanetType; typedef struct Planet { - StringChunkList name; - bool habitable; - u32 population; + PlanetType type; u32 commodities[Commodity_Count]; + u32 production[Commodity_Count]; } Planet; +typedef struct StarSystem { + u32 x; + u32 y; + u32 crime; + str name; + Planet planets[MAX_PLANETS]; +} StarSystem; + +global str STAR_NAMES[STAR_SYSTEM_COUNT] = { + "Achernar", + "Aldebaran", + "Mining Colony 17", + "Antares", + "Arcturus", + "Barnard's Star", + "Betelgeuse", + "Canopus", + "Capella", + "Castor", + "Centauri Prime", + "Deneb", + "Epsilon Eridani", + "Fomalhaut", + "Gliese 581", + "Hadar", + "Izar", + "Kepler-186", + "Lacaille 8760", + "Lalande 21185", + "Mintaka", + "Mirach", + "Polaris", + "Pollux", + "Procyon", + "Proxima", + "Regulus", + "Rigel", + "Ross 154", + "Sirius", + "Spica", + "Tau Ceti", + "Trappist-1", + "Vega", + "Wolf 359", + "Zeta Reticuli", + "Alnitak", + "Bellatrix", + "Denebola", + "Eltanin", +}; + typedef struct { i32 x; i32 y;