Jump to content
Sign in to follow this  
pcc

Allow buying units/weapons outside of baserange (warfare)

Recommended Posts

I could set default base range to 9999

BIS_WF_Constants SetVariable["BASERANGE",150];

However, it seems to glitch AI squads functions that takes base range into calculation like in  Advanced_UpdateSquad.sqs.  Also noticed sometimes units just sits in base even with assigned mission.

if (_leader Distance _base > (BIS_WF_Constants GetVariable "BASERANGE")) then {Goto "FindHostileBase"};

I've tried editing Client_UpdateAvailableActions Action_UseNearbyStructure to remove structure baserange checks for buy menu but was unsuccessful.  I'd appreciate any help. 

Share this post


Link to post
Share on other sites

Client\Functions\Client_PlayerRespawn.sqf has the addactions:

 

Spoiler

player AddAction [localize "STR_Client_PlayerRespawn.sqf0",corePath + "Client\GUI\GUI_buyPrepareMenu.sqf", ['gear'], 100, false, true, "", "BIS_WF_BuyGearInRange"]; //"Buy weapons"
player AddAction [localize "STR_Client_PlayerRespawn.sqf1",corePath + "Client\GUI\GUI_buyPrepareMenu.sqf", ['units'], 100, false, true, "", "BIS_WF_BuyUnitsInRange"]; //"Buy units"

 

 

The conditions are that BIS_WF_BuyGearInRange or BIS_WF_BuyUnitsInRange have to return true.

 

Client\GUI\GUI_UpdateOptions.sqf shows what the conditions are for them to be true:

 

Spoiler

BIS_WF_BuyGearInRange = !IsNull BIS_WF_CampInRange || !IsNull BIS_WF_BarracksInRange || !IsNull BIS_WF_DepotInRange; //also used for enabling action
BIS_WF_BuyUnitsInRange = (!IsNull BIS_WF_BarracksInRange || !IsNull BIS_WF_LightFactoryInRange || !IsNull BIS_WF_HeavyFactoryInRange || !IsNull BIS_WF_AircraftFactoryInRange || !IsNull BIS_WF_AirportInRange || !IsNull BIS_WF_DepotInRange || _constructedCamp) && player == Leader player; //also used for enabling action

 

 

I don't suggest simply changing any of these to "true", because then the options become available when structures don't exist, resulting in script failures.

 

Client\Client_UpdateAvailableObjects.sqf shows what the conditions are for the "in range" variables to return not null.  The command nearEntities is used to find which structures are within different ranges from the player.

 

But nearEntities is an FPS demanding command.  The larger the radius, the more drag on the processor, as it locates and has to process more entities found.  Small radius like CONSTRUCTIONRANGE, CAMPRANGE, BASERANGE, hardly any lag.  But if you extend its radius to cover the map you'll suffer a major (possibly unrecoverable) lag each update.

 

I would think you would want to change the conditions here to things which do not rely on nearEntities (or nearObjects, same issue).  There are varying conditions for the structures, and you'd have to consider each.  Distance command doesn't have that drag, but you need the objects to get distance from.  Maybe use baseStructures array, it's the maintained array of base structures on each client.

  • Like 1

Share this post


Link to post
Share on other sites
9 hours ago, opusfmspol said:

I would think you would want to change the conditions here to things which do not rely on nearEntities (or nearObjects, same issue).  There are varying conditions for the structures, and you'd have to consider each.  Distance command doesn't have that drag, but you need the objects to get distance from.  Maybe use baseStructures array, it's the maintained array of base structures on each client.

So if I assign the base structure in place of _objects Select (_types Find _structure); would that bypass nearEntities checks?  I'm not really sure how to do it though or call the baseStructures arrays.

Client\Client_UpdateAvailableObjects.sqf 

if (Count _structures > 1) then
	{
		_structure = _structures Select 1;
		if (_structure In _types) then
			{
				BIS_WF_LightFactoryInRange = _objects Select (_types Find _structure);
			;
	};

I wish the structures would made usable without within range checks.  That way I could buy backup when away from base.

Share this post


Link to post
Share on other sites

Found BIS_WF_SortByDistance, it uses Distance command rather than nearestObjects, nearEntities, nearObjects, etc., which is helpful.

 

For the base structures, to cover the entire map use it with a copy of baseStructures array.

 

Spoiler

//	_objects = NearestObjects[Vehicle player,_structures,(BIS_WF_Constants GetVariable "BASERANGE")] Call GetUndestroyedUnits;

	_objects = +baseStructures;	// make a copy so the actual array won't be affected.
	_objects = [Vehicle Player, _objects] Call BIS_WF_SortByDistance;
	_objects = _objects Call GetUndestroyedUnits;

	_types = [];
	{_types = _types + [TypeOf _x]} ForEach _objects;


	BIS_WF_BarracksInRange = ObjNull;
	if (Count _structures > 0) then
	{
		_structure = _structures Select 0;
		if (_structure In _types) then
		{
			BIS_WF_BarracksInRange = _objects Select (_types Find _structure);
		};
	};

 

 

 

When a custom max range is intended, the range can be passed into the call as third element (select 2):

 

Spoiler

	// _objects = NearestObjects[Vehicle player,_structures,(BIS_WF_Constants GetVariable "BASERANGE")] Call GetUndestroyedUnits;

	_objects = +baseStructures;
	_objects = [Vehicle Player, _objects, 10000] Call BIS_WF_SortByDistance;
	_objects = _objects Call GetUndestroyedUnits;

	_types = [];
	{_types = _types + [TypeOf _x]} ForEach _objects;

 

 

  • Like 1

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
Sign in to follow this  

×