From 88676234d1ecbf681255de2e5f74e5772052d0d5 Mon Sep 17 00:00:00 2001 From: Wyqer Date: Thu, 5 Sep 2019 20:09:50 +0200 Subject: [PATCH] Dynamic range for building defence ai --- .../scripts/server/ai/building_defence_ai.sqf | 33 ++++++++++--------- README.md | 1 + 2 files changed, 19 insertions(+), 15 deletions(-) diff --git a/Missionframework/scripts/server/ai/building_defence_ai.sqf b/Missionframework/scripts/server/ai/building_defence_ai.sqf index fa84a80c..f287c5bf 100644 --- a/Missionframework/scripts/server/ai/building_defence_ai.sqf +++ b/Missionframework/scripts/server/ai/building_defence_ai.sqf @@ -3,27 +3,30 @@ params ["_unit", ["_sector", ""]]; _unit setUnitPos "UP"; _unit disableAI "MOVE"; private _move_is_disabled = true; -private _resume_movement = false; +private _hostiles = 0; +private _ratio = 0.4; +private _range = 40; while {_move_is_disabled && local _unit && alive _unit && !(captive _unit)} do { - private _hostilecount = {alive _x && side _x == GRLIB_side_friendly} count ((getpos _unit) nearEntities [["Man"], 40]); - if ((_hostilecount > 0) || (damage _unit > 0.25)) then { - _resume_movement = true; + if !(_sector isEqualTo "") then { + _ratio = [_sector] call F_getForceRatio; }; - if (_sector != "") then { - if (_sector in blufor_sectors) then { - _resume_movement = true; - }; - }; + _range = floor (linearConversion [0, 1, _ratio, 0, GRLIB_capture_size / 3 * 2, true]); - if (_resume_movement) then { - if (_move_is_disabled) then { - _move_is_disabled = false; - _unit enableAI "MOVE"; - _unit setUnitPos "AUTO"; - }; + _hostiles = ((getPos _unit) nearEntities [["Man"], _range]) select {side _x == GRLIB_side_friendly}; + + if (_move_is_disabled && + { + (_sector in blufor_sectors) || + {!(_hostiles isEqualTo [])} || + {damage _unit > 0.25} + } + ) then { + _move_is_disabled = false; + _unit enableAI "MOVE"; + _unit setUnitPos "AUTO"; }; if (_move_is_disabled) then { diff --git a/README.md b/README.md index a351ba94..1a0f8d74 100644 --- a/README.md +++ b/README.md @@ -196,6 +196,7 @@ class Missions * Tweaked: Initial FOB box doesn't have equipment in the inventory anmore. * Tweaked: Height check for mobile respawn now relies on `isTouchingGround` instead of z value of position. * Tweaked: Transport config heights on M977 vehicles. Thanks to [FishAI](https://github.com/FishAI) +* Tweaked: AI in building now has a dynamic radius to look for enemies until they start moving again depending on blufor/opfor ratio in sector. * Fixed: Potato 01 was created after server restart, even if there was one saved. * Fixed: Missing variable `stats_blufor_teamkills_by_players`. Also no separation between by players or not by players for teamkills anymore. * Fixed: Factory storages could disappear randomly on save load.