I think the passengers system works

This commit is contained in:
Tenari
2026-03-18 07:27:01 -05:00
parent 6ec461ef3e
commit 58b80e53d0
4 changed files with 84 additions and 13 deletions
+32
View File
@@ -907,6 +907,14 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
strForPlanet(sys.planets[2].type) 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);
}
}
// map key // map key
y_off += 1+(MAP_HEIGHT*yh); y_off += 1+(MAP_HEIGHT*yh);
@@ -952,6 +960,30 @@ fn bool updateAndRender(TuiState* tui, void* s, u8* input_buffer, u64 loop_count
} }
renderStrToBuffer(tui->frame_buffer, x_off, y_off++, sbuf, screen_dimensions); renderStrToBuffer(tui->frame_buffer, x_off, y_off++, sbuf, screen_dimensions);
u32 projected_oxy_cost = oxyCostForTravel(&state->me, curr_pos, dest_pos);
bool have_enough_oxy = projected_oxy_cost <= state->me.commodities[CommodityOxygen];
MemoryZero(sbuf, SBUFLEN);
if (have_enough_oxy) {
sprintf(
sbuf,
"Oxygen Cost: %dkg / %dkg",
projected_oxy_cost,
state->me.commodities[CommodityOxygen]
);
} else {
sprintf(
sbuf,
"Not enough Oxygen! Need %dkg more",
projected_oxy_cost - state->me.commodities[CommodityOxygen]
);
Range1u32 range = {
.min = XYToPos(x_off, y_off, screen_dimensions.width),
.max = XYToPos(x_off+strlen(sbuf), y_off, screen_dimensions.width),
};
colorizeRange(tui, range, ANSI_HIGHLIGHT_RED, 0);
}
renderStrToBuffer(tui->frame_buffer, x_off, y_off++, sbuf, screen_dimensions);
if (user_pressed_enter) { if (user_pressed_enter) {
for (u32 i = 0; i < STAR_SYSTEM_COUNT; i++) { for (u32 i = 0; i < STAR_SYSTEM_COUNT; i++) {
if (state->pos.x == state->map[i].x && state->pos.y == state->map[i].y) { if (state->pos.x == state->map[i].x && state->pos.y == state->map[i].y) {
+3
View File
@@ -240,6 +240,9 @@ fn void renderStrToBuffer(Pixel* buf, u16 x, u16 y, str text, Dim2 screen_dimens
u32 pos = x + (screen_dimensions.width*y); u32 pos = x + (screen_dimensions.width*y);
for (u32 i = 0; i < strlen(text); i++) { for (u32 i = 0; i < strlen(text); i++) {
buf[pos+i].bytes[0] = text[i]; buf[pos+i].bytes[0] = text[i];
buf[pos+i].bytes[1] = 0;
buf[pos+i].bytes[2] = 0;
buf[pos+i].bytes[3] = 0;
} }
} }
+29 -2
View File
@@ -964,10 +964,15 @@ fn void* gameLoop(void* params) {
Pos2 dest_pos = {dest.x, dest.y}; Pos2 dest_pos = {dest.x, dest.y};
Pos2 curr_pos = {current.x, current.y}; Pos2 curr_pos = {current.x, current.y};
u32 projected_fuel_cost = fuelCostForTravel(acct->ship.drive_efficiency, curr_pos, dest_pos); u32 projected_fuel_cost = fuelCostForTravel(acct->ship.drive_efficiency, curr_pos, dest_pos);
bool have_enough_fuel = projected_fuel_cost < acct->ship.commodities[CommodityHydrogenFuel]; bool have_enough_fuel = projected_fuel_cost <= acct->ship.commodities[CommodityHydrogenFuel];
if (have_enough_fuel) { u32 projected_oxygen_cost = oxyCostForTravel(&acct->ship, curr_pos, dest_pos);
bool have_enough_oxy = projected_oxygen_cost <= acct->ship.commodities[CommodityOxygen];
if (have_enough_fuel || have_enough_oxy) {
// remove the fuel they used on the journey // remove the fuel they used on the journey
acct->ship.commodities[CommodityHydrogenFuel] -= projected_fuel_cost; acct->ship.commodities[CommodityHydrogenFuel] -= projected_fuel_cost;
// remove the oxygen they used on the journey
acct->ship.commodities[CommodityOxygen] -= projected_oxygen_cost;
// set the pos to be the system they had as destination // set the pos to be the system they had as destination
acct->ship.system_idx = acct->destination_sys_idx; acct->ship.system_idx = acct->destination_sys_idx;
} }
@@ -981,6 +986,28 @@ fn void* gameLoop(void* params) {
acct->ship.remaining_mortgage += (u32)compounding; acct->ship.remaining_mortgage += (u32)compounding;
} }
} }
// check for the completion of a passenger job (MUST COME AFTER acct->ship.system_idx is updated)
for (u32 ii = 0; ii < MAX_PASSENGER_BERTHS; ii++) {
Passenger* job = &acct->ship.passengers[ii];
bool is_valid_job = job->people > 0;
bool is_at_job_destination = job->goal_system_idx == acct->ship.system_idx;
if (is_valid_job) {
if (is_at_job_destination) {
acct->ship.credits += job->reward;
printf("%d credits awarded to %s for finishing passenger job\n", job->reward, acct->name.bytes);
MemoryZero(job, sizeof(Passenger));
// TODO send a job completion message?
} else {
job->turns_remaining -= 1;
if (job->turns_remaining == 0) {
// they failed the job
// TODO send a job failed message?
MemoryZero(job, sizeof(Passenger));
}
}
}
}
} }
} }
+20 -11
View File
@@ -6,8 +6,8 @@
///// #define some game-tunable constants ///// #define some game-tunable constants
#define STARTING_DOWN_PAYMENT (10000) #define STARTING_DOWN_PAYMENT (10000)
#define SHIP_DETAIL_COUNT (7) #define SHIP_DETAIL_COUNT (8)
#define STAR_SYSTEM_COUNT (40) #define STAR_SYSTEM_COUNT (16)
#define MAP_WIDTH (36) #define MAP_WIDTH (36)
#define MAP_HEIGHT (12) #define MAP_HEIGHT (12)
#define MAX_PLANETS (3) #define MAX_PLANETS (3)
@@ -79,12 +79,12 @@ global ShipTemplate SHIPS[] = {
global FieldDescriptor SHIP_FIELDS[SHIP_DETAIL_COUNT] = { global FieldDescriptor SHIP_FIELDS[SHIP_DETAIL_COUNT] = {
{ "Type", FieldTypeEnum, offsetof(ShipTemplate, type), 16, (str*)&SHIP_TYPE_STRINGS }, { "Type", FieldTypeEnum, offsetof(ShipTemplate, type), 16, (str*)&SHIP_TYPE_STRINGS },
{ "Cost", FieldTypeU32, offsetof(ShipTemplate, base_cost), 8 }, { "Cost", FieldTypeU32, offsetof(ShipTemplate, base_cost), 8 },
{ "Cargo", FieldTypeU16, offsetof(ShipTemplate, vacuum_cargo_slots), 7 },
{ "PassengerBerths", FieldTypeU16, offsetof(ShipTemplate, passenger_berths), 16 },
{ "DriveEff", FieldTypeU8, offsetof(ShipTemplate, drive_efficiency), 8 }, { "DriveEff", FieldTypeU8, offsetof(ShipTemplate, drive_efficiency), 8 },
{ "LifeSupp", FieldTypeU8, offsetof(ShipTemplate, life_support_efficiency), 8 }, { "LifeSupp", FieldTypeU8, offsetof(ShipTemplate, life_support_efficiency), 8 },
{ "Cargo", FieldTypeU16, offsetof(ShipTemplate, vacuum_cargo_slots), 7 },
{ "FuelTank", FieldTypeU32, offsetof(ShipTemplate, cu_m_fuel), 8 }, { "FuelTank", FieldTypeU32, offsetof(ShipTemplate, cu_m_fuel), 8 },
{ "O2 Tank", FieldTypeU32, offsetof(ShipTemplate, cu_m_o2), 8 }, { "O2 Tank", FieldTypeU32, offsetof(ShipTemplate, cu_m_o2), 8 },
// { "SmugglersHold", FieldTypeU16, offsetof(ShipTemplate, smugglers_hold_cu_m), 13 },
}; };
typedef enum EquipmentType { typedef enum EquipmentType {
@@ -355,14 +355,14 @@ typedef struct StarSystem {
} StarSystem; } StarSystem;
global str STAR_NAMES[STAR_SYSTEM_COUNT] = { global str STAR_NAMES[STAR_SYSTEM_COUNT] = {
"Achernar", "Vega",
"Aldebaran", "Aldebaran",
"Mining Colony 17", "Mining Colony 17",
"Antares", "Antares",
"Arcturus", "Mintaka",
"Barnard's Star", "Barnard's Star",
"Betelgeuse", "Betelgeuse",
"Canopus", "Tau Ceti",
"Capella", "Capella",
"Castor", "Castor",
"Centauri Prime", "Centauri Prime",
@@ -371,11 +371,13 @@ global str STAR_NAMES[STAR_SYSTEM_COUNT] = {
"Fomalhaut", "Fomalhaut",
"Gliese 581", "Gliese 581",
"Hadar", "Hadar",
"Izar", /* "Izar",
"Achernar",
"Kepler-186", "Kepler-186",
"Lacaille 8760", "Lacaille 8760",
"Lalande 21185", "Lalande 21185",
"Mintaka", "Arcturus",
"Canopus",
"Mirach", "Mirach",
"Polaris", "Polaris",
"Pollux", "Pollux",
@@ -386,15 +388,14 @@ global str STAR_NAMES[STAR_SYSTEM_COUNT] = {
"Ross 154", "Ross 154",
"Sirius", "Sirius",
"Spica", "Spica",
"Tau Ceti",
"Trappist-1", "Trappist-1",
"Vega",
"Wolf 359", "Wolf 359",
"Zeta Reticuli", "Zeta Reticuli",
"Alnitak", "Alnitak",
"Bellatrix", "Bellatrix",
"Denebola", "Denebola",
"Eltanin", "Eltanin",
*/
}; };
typedef enum Direction { typedef enum Direction {
@@ -544,4 +545,12 @@ fn u32 shipAvailablePassengerBerths(PlayerShip ship) {
return (u32)ship.passenger_berths - shipUsedPassengerBerths(ship); return (u32)ship.passenger_berths - shipUsedPassengerBerths(ship);
} }
fn u32 oxyCostForTravel(PlayerShip* ship, 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 oxy_per_person_per_dist = 15 - ship->life_support_efficiency;
// +1 because the pilot uses oxy as well
return (x_distance + y_distance) * oxy_per_person_per_dist * (shipTotalPassengers(*ship) + 1);
}
#endif //GAMESHARED_H #endif //GAMESHARED_H