From ba345065bbdc71309c17a187a5b766e9d37765ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dominik=20Madar=C3=A1sz?= Date: Wed, 11 Aug 2021 10:54:52 +0200 Subject: [PATCH] code: fix ents on Vehicle UnSet --- code/modules/modules/systems.c | 2 ++ code/modules/source/system_vehicle.c | 12 ++++++++++++ 2 files changed, 14 insertions(+) diff --git a/code/modules/modules/systems.c b/code/modules/modules/systems.c index 15d094f..4874cc0 100644 --- a/code/modules/modules/systems.c +++ b/code/modules/modules/systems.c @@ -116,4 +116,6 @@ void SystemsImport(ecs_world_t *ecs) { ECS_SYSTEM(ecs, IntegratePositions, EcsOnValidate, components.Position, components.Velocity); ECS_SYSTEM(ecs, UpdateTrackerPos, EcsPostUpdate, components.Position); + + ECS_SYSTEM(ecs, ClearVehicle, EcsUnSet, components.Vehicle); } diff --git a/code/modules/source/system_vehicle.c b/code/modules/source/system_vehicle.c index 0bc2da0..99ef4f5 100644 --- a/code/modules/source/system_vehicle.c +++ b/code/modules/source/system_vehicle.c @@ -124,3 +124,15 @@ void VehicleHandling(ecs_iter_t *it) { car->heading = zpl_arctan2(fr_y - bk_y, fr_x - bk_x); } } + +void ClearVehicle(ecs_iter_t *it) { + Vehicle *veh = ecs_column(it, Vehicle, 1); + + for (int i = 0; i < it->count; i++) { + for (int k = 0; k < 4; k++) { + if (veh[i].seats[k] != 0) { + ecs_remove(it->world, veh[i].seats[k], IsInVehicle); + } + } + } +}