Jump to content
Rydygier

How many vehicles can you cram with SQF within given area without a collision?

Recommended Posts

I was solving some usual "safe but close" vehicle spawn problem, I found satisfactory solution for my needs, but I thought, how far one could take this? There could be actually interesting scripting puzzle challenge in this, as in the title.

 

Proposed rules:

 

Challenge: spawn in as many empty vehicles at a time within given area (on the ground, all vehicle's 0 boundingBoxReal vertices must stay not farther, than given radius from given center, measured in 2D), as possible without any model collisions with map objects or other vehicles. The vehicle class is given for clarity, but best, if the code would be universal, working with any number of vehicle classes (able to spawn into the area various vehicles) and any area.

 

Location: Malden, circular area at position: [5552,7011,0], radius: 100 meters. (Arudy town).

 

Vehicle to be spawned: "B_Truck_01_box_F" (HEMTT Box).

 

Allowed means: SQF only.

 

Not allowed: changing any vehicle object properties (geometry, vectors, simulation, disabling collisions etc.) after the spawn apart from horizontal direction (azimuth) and position (treat this as 2D puzzle). Spawning by manually typed/picked list of coords (it's not, what we're after here, right? Spawn positions should be determined procedurally).

 

The important factor here is amount of safely spawned in vehicles, other factors like time or CPU load or code complexicity matter only when comparing two codes giving same amount of vehicles. 

 

It may sound as unproductive time eater, but there may appear some inventive solutions having practical applications, so there may be actually useful outcome from this. Also it seems to be good scripting excersize. So, anyone interested/bored enough? 🙂

  • Like 2
  • Thanks 1

Share this post


Link to post
Share on other sites

@Rydygier,

About 40.
That was a fun activity. I'm curious to see to what limit this can be pushed with a better script and faster computer. There's definitely room at the coordinates for more.

Spoiler

you_fnc_truckChall={
params [["_position", locationNull], ["_typeVeh", objNull], ["_maxCount", 1], ["_truckCount", 0], ["_safeZone", 5], ["_area", 100]];

if (_truckCount<_maxCount) then {
	private	_pos = _position findEmptyPosition [_safeZone,_area,_typeVeh];
	private	_obj = _typeVeh createVehicle _pos;
waitUntil {sleep 1; !isNull _obj};
	_truckCount=_truckCount+1;
hint str _truckCount;
	[_position, _typeVeh, _maxCount,_truckCount, _safeZone, _area] spawn you_fnc_truckChall;
} else { systemChat "Area full"};
};

[[5552,7011],"B_Truck_01_box_F", 40,0,5,100] spawn you_fnc_truckChall;

 

Increasing the sleep may allow for more trucks over a greater time. (I always max out around 45-48 no matter what)

Have fun!

Edited by wogz187
updated script
  • Like 4

Share this post


Link to post
Share on other sites

Aaaand I crashed arma.

Got a bit too carried away, heh.

 

Gonna give it another run on the weekend.

 

Edit: Theoretical maximum might be 83 considering visual bounding box diameter of 9.53448m for the aforementioned truck and no buildings in the way, doubt it's possible to place more than 40, heh.

Using a circle packing algorithm that is, most likely more efficient to grab a rectangle packer.

 

Cheers

  • Like 1
  • Haha 3

Share this post


Link to post
Share on other sites

There is a BI function that spawns and crews a load of vehicles on a grid. I forgot the name of it, I'm afk atm. Preview somethingorother

  • Like 1

Share this post


Link to post
Share on other sites

And maybe this is already being done somewhere, but I think a "weekly scripting challenge" or similar would be cool. It's always interesting to see different peoples' approaches to a problem, and it's a good opportunity to learn some new commands/functions along the way.

  • Like 4

Share this post


Link to post
Share on other sites

I got 52 but used KillzoneKid's fnc_isFlatEmpty off the notes here https://community.bistudio.com/wiki/isFlatEmpty 

 

Spoiler

fnc_isFlatEmpty = 
{ 
	params ["_pos", "_params"]; 
	_pos = _pos findEmptyPosition [5, _params select 0]; 
	if (_pos isEqualTo []) exitWith {[]}; 
	_params =+ _params; 
	_params set [0, -1]; 
	_pos = _pos isFlatEmpty _params; 
	if (_pos isEqualTo []) exitWith {[]}; 
	_pos 
}; 
_box = "Land_VR_Shape_01_cube_1m_F" createVehicle [5552,7011,0]; 
_vehType = "B_Truck_01_box_F";
for "_i" from 0 to 360 step 1 do  
{ 
	for "_j" from 0 to 100 step 1 do  
	{ 
		_relpos = _box getRelPos [_j, _i]; 
		_empty = [_relpos, [-1, -1, -1, -1, -1, false, objNull]] call fnc_isFlatEmpty; 
		if !(_empty isEqualTo []) then  
		{ 
			_empty set [2,0]; 
			_nearest = nearestObjects [_empty, [_vehType], 11]; 
			if !(count _nearest >0) then  
			{ 
				_markerName = createMarker [str _relpos, _empty]; 	 
				_markerName setMarkerType "hd_dot"; 
				_veh = _vehType createVehicle [0,0,0]; 
				_veh setDir _i; 
				_veh setPos _empty; 
				_vehPos = getPos _veh;   
			}; 
		}; 
	};  
}; 
_mrkrCount = count allMapMarkers; 
systemChat format ["%1", _mrkrCount];

 

 

 

  • Like 3

Share this post


Link to post
Share on other sites
Quote

Am I doing it wrong if I use disableCollisionWith?

 

Quote

Not allowed: changing any vehicle object properties (geometry, vectors, simulation, disabling collisions etc.)

 

🙂 So yes, it's not, what we're after here. 

Share this post


Link to post
Share on other sites

Managed to get 52 every time without that other fnc. Crashed the game way too many times messing with this
 

_box = "Land_VR_Shape_01_cube_1m_F" createVehicle [5552,7011,0]; 
_vehType = "B_Truck_01_box_F";
for "_i" from 0 to 360 step 1 do  
{ 
	for "_j" from 0 to 92 step 1 do  
	{ 
		_relpos = _box getRelPos [_j, _i]; 
		_empty = _relpos findEmptyPosition [5,8,_vehType];
		if !(_empty isEqualTo []) then  
		{ 
			_empty set [2,0]; 
			_nearest = nearestObjects [_empty, [_vehType], 11]; 
			if !(count _nearest >0) then  
			{ 
				_markerName = createMarker [str _relpos, _empty];
				_markerName setMarkerType "hd_dot"; 
				_veh = _vehType createVehicle [0,0,0]; 
				_veh setDir _i; 
				_veh setPos _empty; 
				_vehPos = getPos _veh;   
			}; 
		}; 
	};  
}; 
_mrkrCount = count allMapMarkers; 
systemChat format ["%1", _mrkrCount];

 

  • Like 3

Share this post


Link to post
Share on other sites

Ok, last one. Not as many are spawning now but seems to work well with all land vehicles.
Totals -
B_Truck_01_box_F - 49
B_G_Quadbike_01_F - 154
C_man_1 - 259
 

// -------------[position, vehicle classname] call fnc_allTheSpots;
// -------------[[5552,7011,0],"B_Truck_01_box_F"] call fnc_allTheSpots;

fnc_allTheSpots = 
{
	_box = "Land_VR_Shape_01_cube_1m_F" createVehicle (_this select 0); 
	_vehType = _this select 1;
	_veh = _vehType createVehicle [0,0,0]; 
	_bBox = boundingBoxReal _veh;
	_sphereSize = _bBox select 2;
	_vehSize = _sphereSize * 1.2;
	deleteVehicle _veh;
	for "_i" from 0 to 360 step 1 do  
	{ 
		for "_j" from 0 to 92 step 1 do  
		{ 
			_relpos = _box getRelPos [_j, _i]; 
			_empty = _relpos findEmptyPosition [5,8,_vehType];
			if !(_empty isEqualTo []) then  
			{ 
				_empty set [2,0]; 
				_nearest = nearestObjects [_empty, [_vehType],_vehSize]; 
				if !(count _nearest >0) then  
				{ 
					_markerName = createMarker [str _relpos, _empty];
					_markerName setMarkerType "hd_dot"; 
					_veh = _vehType createVehicle [0,0,0]; 
					_veh setDir _i; 
					_veh setPos _empty;   
				}; 
			}; 
		};  
	}; 
	_mrkrCount = count allMapMarkers; 
	systemChat format ["%1", _mrkrCount];
};

 

  • Like 2

Share this post


Link to post
Share on other sites

Please sign in to comment

You will be able to leave a comment after signing in



Sign In Now

×