From 1b85aeaf9882e29c15b116b683acdab41bb3e94a Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Mon, 2 Dec 2024 15:14:30 +0100 Subject: new locations, multi day trip view in schedule --- src/scenery.c | 2 +- src/scenes/place_detail.c | 24 +++++++++++-- src/world.c | 90 +++++++++++++++++++++++++++++++++++++++++++---- 3 files changed, 107 insertions(+), 9 deletions(-) (limited to 'src') diff --git a/src/scenery.c b/src/scenery.c index cb8f9c6..0b40aa4 100644 --- a/src/scenery.c +++ b/src/scenery.c @@ -51,7 +51,7 @@ void update_render_scenery(world* world) { } renderer->render_reset_scissor(); -#if 0 +#if 1 if (is_left_clicked()) { vec2f coords = px_to_coords(main_window, _global_mouse.x, _global_mouse.y); printf("Location: \"latitude\": %f, \"longitude\":%f\n", coords.y, coords.x); diff --git a/src/scenes/place_detail.c b/src/scenes/place_detail.c index 7e4b20a..1d52e5e 100644 --- a/src/scenes/place_detail.c +++ b/src/scenes/place_detail.c @@ -967,7 +967,7 @@ static void draw_duration_of_scheduled_job_entry(scheduled_job job, scheduled_jo s32 duration_of_job_measured_in_timeslots_max = ceil((job.offer.duration_sec_max/60.0f) / (60.0f/TIME_SLOTS_PER_HOUR)); if (!scheduled_time.stay_at_destination) duration_of_job_measured_in_timeslots_max*=2; - log_assert(duration_of_job_measured_in_timeslots_max < 36*TIME_SLOTS_PER_HOUR, "Multi-day trip not supported yet in schedule preview."); + //log_assert(duration_of_job_measured_in_timeslots_max < 36*TIME_SLOTS_PER_HOUR, "Multi-day trip not supported yet in schedule preview."); s32 slots_outside_of_schedule = (24-(WORK_HOUR_END-WORK_HOUR_START))*TIME_SLOTS_PER_HOUR; s32 overflow_to_next_day = -(((TIME_SLOTS_PER_DAY-scheduled_time.timeslot) - @@ -982,7 +982,27 @@ static void draw_duration_of_scheduled_job_entry(scheduled_job job, scheduled_jo renderer->render_rectangle(tx, ty, highlight_w, timeslot_h, tile_color_bg); s32 highlight_y = ty+timeslot_h; if (scheduled_time.day == SUNDAY) highlight_y = TILE_Y(MONDAY); - if (overflow_to_next_day > 0) renderer->render_rectangle(TILE_X(0), highlight_y, timeslot_w*overflow_to_next_day, timeslot_h, tile_color_bg); + + if (overflow_to_next_day > 0) { + int extra_days = overflow_to_next_day / TIME_SLOTS_PER_DAY; + int curr_day = scheduled_time.day; + for (int xx = 0; xx < extra_days; xx++) { + s32 overflow = overflow_to_next_day % TIME_SLOTS_PER_DAY; + if (xx != extra_days-1) overflow = TIME_SLOTS_PER_DAY; + + if (curr_day == SUNDAY) { + curr_day = MONDAY; + highlight_y = TILE_Y(MONDAY); + } + + printf("%d %d %d\n", overflow_to_next_day, extra_days, overflow); + renderer->render_rectangle(TILE_X(0), highlight_y, timeslot_w*overflow, timeslot_h, tile_color_bg); + overflow_to_next_day -= TIME_SLOTS_PER_DAY; + highlight_y += timeslot_h; + curr_day++; + if (curr_day == 7) curr_day = 0; + } + } } static bool termination_popup_active = false; diff --git a/src/world.c b/src/world.c index e9401b4..31ba752 100644 --- a/src/world.c +++ b/src/world.c @@ -118,6 +118,11 @@ static void connect_locations(world* world, char* str1, char* str2) world_location* loc1 = world_get_location_by_name(world, str1); world_location* loc2 = world_get_location_by_name(world, str2); + if (loc1 == 0 || loc2 == 0) { + printf("XD: %s %s\n", str1, str2); + return; + } + array_push(&loc1->connections, &loc2); array_push(&loc2->connections, &loc1); } @@ -137,6 +142,74 @@ static void world_create_manual_connections(world* world) connect_locations(world, "Tabriz", "Baku"); connect_locations(world, "Kuwait", "Dammam"); connect_locations(world, "Cairo", "Amman"); + connect_locations(world, "Marrakesh", "Algiers"); + connect_locations(world, "Tunis", "Algiers"); + connect_locations(world, "Vredendal", "Cape Town"); + connect_locations(world, "Vredendal", "Bloemfontein"); + connect_locations(world, "Bloemfontein", "Cape Town"); + connect_locations(world, "Bloemfontein", "Gqeberha"); + connect_locations(world, "Dammam", "Riyadh"); + connect_locations(world, "Madinah", "Riyadh"); + connect_locations(world, "Jeddah", "Madinah"); + connect_locations(world, "Rostov-on-Don", "Volgograd"); + connect_locations(world, "Amman", "Madinah"); + connect_locations(world, "Bishek", "Karaganda"); + connect_locations(world, "Dushanbe", "Kabul"); + connect_locations(world, "Karachi", "Lahore"); + connect_locations(world, "Karachi", "Jaipur"); + connect_locations(world, "Jaipur", "Lahore"); + connect_locations(world, "Bengaluru", "Hyderabad"); + connect_locations(world, "Mumbai", "Hyderabad"); + connect_locations(world, "Surat", "Karachi"); + connect_locations(world, "Surat", "Jaipur"); + connect_locations(world, "Kathmandu", "Jaipur"); + connect_locations(world, "Kathmandu", "New Delhi"); + connect_locations(world, "Lahore", "Tehran"); + connect_locations(world, "Madinah", "Baghdad"); + connect_locations(world, "Buenos Aires", "Rosario"); + connect_locations(world, "Mendoza", "Cordoba"); + connect_locations(world, "Santa Fe", "Asunción"); + connect_locations(world, "Curitiba", "Asunción"); + connect_locations(world, "São Paulo", "Asunción"); + connect_locations(world, "Campo Grande", "Asunción"); + connect_locations(world, "São Paulo", "Campo Grande"); + connect_locations(world, "Campo Grande", "Franca"); + connect_locations(world, "Campo Grande", "Goiânia"); + connect_locations(world, "Franca", "Goiânia"); + connect_locations(world, "Buenos Aires", "Curitiba"); + connect_locations(world, "São Paulo", "Rio de Janeiro"); + connect_locations(world, "São Paulo", "Franca"); + connect_locations(world, "Rio de Janeiro", "Franca"); + connect_locations(world, "Rio de Janeiro", "Belo Horizonte"); + connect_locations(world, "Rio de Janeiro", "Vitoria"); + connect_locations(world, "Belo Horizonte", "Vitoria"); + + connect_locations(world, "Janaúba", "Belo Horizonte"); + connect_locations(world, "Janaúba", "Brasilia"); + connect_locations(world, "Janaúba", "Salvador"); + connect_locations(world, "Recife", "Salvador"); + connect_locations(world, "São Luís", "Natal"); + connect_locations(world, "São Luís", "Belém"); + + + // Sea routes + connect_locations(world, "Lissabon", "New York City"); + connect_locations(world, "Lissabon", "Natal"); + connect_locations(world, "Cape Town", "Recife"); +} + +static bool connection_is_sea_route(world_location* loc1, world_location* loc2) +{ + if (strcmp(loc1->name, "Lissabon") == 0 && strcmp(loc2->name, "New York City") == 0) return true; + if (strcmp(loc2->name, "Lissabon") == 0 && strcmp(loc1->name, "New York City") == 0) return true; + + if (strcmp(loc1->name, "Lissabon") == 0 && strcmp(loc2->name, "Natal") == 0) return true; + if (strcmp(loc2->name, "Lissabon") == 0 && strcmp(loc1->name, "Natal") == 0) return true; + + if (strcmp(loc1->name, "Cape Town") == 0 && strcmp(loc2->name, "Recife") == 0) return true; + if (strcmp(loc2->name, "Cape Town") == 0 && strcmp(loc1->name, "Recife") == 0) return true; + + return false; } static void world_create_connections(world* world) @@ -560,10 +633,10 @@ world* world_create_new() world* new_world = mem_alloc(sizeof(world)); new_world->simulation_time = time(NULL); new_world->start_year = gmtime(&new_world->simulation_time)->tm_year; - new_world->money = 100000.0f; + new_world->money = 10000000.0f; new_world->next_id = 1; new_world->active_jobs = array_create(sizeof(active_job)); - new_world->investments = (company_investments){0}; + new_world->investments = (company_investments){10000,10000,10000,10000}; new_world->simulation_speed = 1; new_world->days_since_last_random_event = 0;//-365; // No random events in the first year. new_world->log.events = array_create(sizeof(event)); @@ -780,11 +853,16 @@ static void world_assign_new_job_offers(world* world, bool force) world_find_location_deep(amount_of_connections, location, &new_offer.connections); float total_dist = 0.0; + float boat_distance = 0.0f; for (s32 d = 0; d < new_offer.connections.length-1; d++) { world_location* source = *(world_location**)array_at(&new_offer.connections, d); world_location* dest = *(world_location**)array_at(&new_offer.connections, d+1); - total_dist += distance_between_location(source, dest); + + //if (!connection_is_sea_route(source, dest)) + total_dist += distance_between_location(source, dest); + //else + // boat_distance += distance_between_location(source, dest); } new_offer.total_distance = total_dist; new_offer.reward = (u32)((new_offer.total_distance * 2.1) * @@ -1405,7 +1483,7 @@ static void world_update_location_scores(world* world) for (s32 i = 0; i < world->locations.length; i++) { world_location* location = array_at(&world->locations, i); - location->is_accessible = world_check_location_accessibility(location, location, 1, 0); + location->is_accessible = true;//world_check_location_accessibility(location, location, 1, 0); if (!location->is_owned) continue; @@ -1545,10 +1623,10 @@ void world_update(platform_window* window, world* world) { static float delta = 0; delta += frame_delta; - if (delta >= (1/60.0f)) { // tick runs at 60 ticks per second regardless of fps. + //if (delta >= (1/60.0f)) { // tick runs at 60 ticks per second regardless of fps. world_run_simulation_tick(world); delta = 0; - } + //} } static vec2f get_world_location_for_job(platform_window* window, world* world, active_job* job) -- cgit v1.2.3-70-g09d2