From e96c8910ff9e9c17b0c708d18b0efe018dd8c978 Mon Sep 17 00:00:00 2001 From: Aldrik Ramaekers Date: Mon, 25 Nov 2024 16:05:26 +0100 Subject: close #10 --- src/include/ui/colors.h | 4 ++++ src/include/world.h | 1 + src/world.c | 37 +++++++++++++++++++++++++++++++++++-- 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/src/include/ui/colors.h b/src/include/ui/colors.h index f8a7f91..20a36e8 100644 --- a/src/include/ui/colors.h +++ b/src/include/ui/colors.h @@ -13,6 +13,9 @@ #define COLOR_INSPECT_ACTIVE_JOB_LINE_CONNECTION rgb(40,40,40) #define COLOR_DOT_HOVERED rgb(100,220,100) +#define COLOR_CONNECTION_BETWEEN_LOCATION_ACCESSIBLE rgb(220,220,220) +#define COLOR_CONNECTION_BETWEEN_LOCATION_INACCESSIBLE rgb(30, 30, 30) + #define COLOR_TEXT_NEGATIVE rgb(226,86,86) #define COLOR_TITLE rgb(8, 10, 12) #define COLOR_TEXT_SHADOW rgb(24,24,24) @@ -29,6 +32,7 @@ #define COLOR_BUTTON_HIGHLIGHTED_ACTIVE rgb(92, 60, 56) #define COLOR_BUTTON_DISABLED rgb(27, 26, 25) +#define COLOR_LOCATION_DOT_UNACCESSIBLE rgb(60, 60, 60) #define COLOR_LOCATION_DOT_UNOWNED rgb(220,220,220) #define COLOR_LOCATION_DOT_OWNED rgb(220,100,100) diff --git a/src/include/world.h b/src/include/world.h index d2e9bfc..2c32581 100644 --- a/src/include/world.h +++ b/src/include/world.h @@ -251,6 +251,7 @@ typedef struct t_world_location // Dynamic array connections; bool is_hovered; + bool is_accessible; u32 id; } world_location; diff --git a/src/world.c b/src/world.c index ab90371..fb917b3 100644 --- a/src/world.c +++ b/src/world.c @@ -96,6 +96,7 @@ static world_location world_create_location(u8 size, double latitude, double lon location.resumes = array_create(sizeof(resume)); location.id = assets_hash_path(location.name); location.reliability = 1.0f; + location.score = 0.0f; return location; } @@ -1306,6 +1307,30 @@ static vec2f get_world_location_for_job(platform_window* window, world* world, a return (vec2f){0.0f, 0.0f}; } +static bool world_check_location_accessibility(world_location* orig, world_location* source, int depth, double dist) +{ + if (orig->is_owned) return true; + for (s32 d = 0; d < source->connections.length; d++) + { + world_location* destination = *(world_location**)array_at(&source->connections, d); + if (destination == source) continue; + if (destination == orig) continue; + + if (destination->is_owned && world_get_max_depth_for_location(orig) >= depth) { + return true; + } + else if (distance_between_location(destination, orig) > dist){ + bool result = world_check_location_accessibility(orig, destination, depth+1, distance_between_location(destination, orig)); + if (result) return true; + } + else if (depth > world_get_max_depth_for_location(orig)) { + return false; + } + } + + return false; +} + world_update_result world_render(platform_window* window, world* world) { world_update_result result = {0,0}; @@ -1327,8 +1352,9 @@ world_update_result world_render(platform_window* window, world* world) s32 circle_x = location->map_position_x - dotsize/2; s32 circle_y = location->map_position_y - dotsize/2; bool hovered = mouse_interacts(circle_x, circle_y, dotsize, dotsize); + location->is_accessible = world_check_location_accessibility(location, location, 1, 0); location->is_hovered = hovered; - if (hovered) { + if (hovered && location->is_accessible) { platform_set_cursor(window, CURSOR_POINTER); if (is_left_clicked()) { result.clicked_location = location; @@ -1340,6 +1366,10 @@ world_update_result world_render(platform_window* window, world* world) if (location->is_hovered) { tint = COLOR_DOT_HOVERED; } + + if (!location->is_accessible) { + tint = COLOR_LOCATION_DOT_UNACCESSIBLE; + } renderer->render_image_tint(img_locationdot, circle_x, circle_y, dotsize, dotsize, tint); } @@ -1369,13 +1399,16 @@ world_update_result world_render(platform_window* window, world* world) for (s32 i = 0; i < world->locations.length; i++) { world_location* source = array_at(&world->locations, i); + for (s32 d = 0; d < source->connections.length; d++) { world_location* destination = *(world_location**)array_at(&source->connections, d); if (destination == source) continue; - renderer->render_line(source->map_position_x, source->map_position_y, destination->map_position_x, destination->map_position_y, 1, rgb(255,0,0)); + color line_clr = COLOR_CONNECTION_BETWEEN_LOCATION_ACCESSIBLE; + if (!source->is_accessible) line_clr = COLOR_CONNECTION_BETWEEN_LOCATION_INACCESSIBLE; + renderer->render_line(source->map_position_x, source->map_position_y, destination->map_position_x, destination->map_position_y, 1, line_clr); } } -- cgit v1.2.3-70-g09d2