diff options
| author | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-11-25 16:05:26 +0100 |
|---|---|---|
| committer | Aldrik Ramaekers <aldrikboy@gmail.com> | 2024-11-25 16:05:26 +0100 |
| commit | e96c8910ff9e9c17b0c708d18b0efe018dd8c978 (patch) | |
| tree | 2717238e388077b2caba0354fa3d77177c03a0d9 /src/world.c | |
| parent | eba92835cee8e4c5564ce0e23db15db5b04ad279 (diff) | |
close #10
Diffstat (limited to 'src/world.c')
| -rw-r--r-- | src/world.c | 37 |
1 files changed, 35 insertions, 2 deletions
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);
}
}
|
