Closed Tuupertunut closed 1 year ago
I think the wiki is actually wrong here and it actually means empty radius around the vehicle.
And you were correct. The Bohemia wiki has been updated.
I suggest that we lower the radius to 5 or even 0. There might however be downsides where a vehicle might spawn in a tight space and could not get out. What do you think?
Preferably we want vehicles to spawn in the largest possible space. I think the smartest solution would be to write a function that tries to find an area of a given size, and if it can't find one, it searches for a smaller area until an area is found. For example, give the function 15 meters as a preferred size, but it can't find it, so it searches for a 10 meter area, which it does find, and returns that instead. This guarantees that a position is found.
As for performance, execution time will be multiplied by the amount of checks done, though I don't think it will be substantial as all common areas are precalculated with findEmptyPositionReady
. Step size is also a factor, maybe a reduction of 20% in diameter each time would be suitable?
That's a good solution.
I looked a bit further and it seems like the code above is actually for spawning soldiers for the car and the car spawning code is further, right here:
It is already doing something similar to what you suggested. That SHK_pos_fnc_pos
is basically just really fancy way of calling findEmptyPosition
with radius = 0. If radius 15 fails, it is trying radius 0.
So the actual bug is not really that it fails to spawn the car, but that it fails to spawn the soldiers for it. For some reason the soldier spawning code also checks for a 15m radius just for the soldiers but that code doesn't fall back to radius 0.
Fix: We could just spawn the soldiers all in one position and not check for empty space, as they will be moved into a car anyway.
In Swarog base in Livonia, there is not enough space for a NATO car to spawn. This causes script errors when NATO tries to spawn reinforcements there.
https://github.com/rekterakathom/Overthrow/blob/23a8af0f361fdf1d7d08eb556dcf6c197cd02b14/addons/overthrow_main/functions/factions/NATO/fn_NATOGroundReinforcements.sqf#L13-L14
In this code, if there is not enough room around
_frompos
,findEmptyPosition
will return an empty position array andcreateUnit
will fail. This is what happens in Swarog base.However, looking at a picture of the actual base:![Screenshot_20221220_080958](https://user-images.githubusercontent.com/1782631/208596576-31ce1c18-2cc7-454f-a361-7d561c951467.png)
There is more than enough space for a simple car. What's wrong?
Now Bohemia wiki tells us that a parameter of
findEmptyPosition
, calledradius
, means minimum distance from the center from where to start finding empty positions. I think the wiki is actually wrong here and it actually means empty radius around the vehicle. I will ask about this in the Arma Discord.This would make much more sense. The value of
radius
in the above code is 15, and there is no empty circle of radius 15m inside the Swarog base. If I lower the value to 5, the NATO cars are able to spawn, as there are empty radius 5m circles. Note that even ifradius
is 0, the game would still check that a vehicle of type_vehtype
fits there.I suggest that we lower the
radius
to 5 or even 0. There might however be downsides where a vehicle might spawn in a tight space and could not get out. What do you think?