Skip to content

Commit

Permalink
bCombat v0.18 BETA
Browse files Browse the repository at this point in the history
Beta 2
  • Loading branch information
fabrizioT committed Feb 15, 2015
1 parent 922e801 commit e7cef28
Show file tree
Hide file tree
Showing 9 changed files with 190 additions and 161 deletions.
Binary file modified addons/bcombat.pbo
Binary file not shown.
164 changes: 117 additions & 47 deletions bcombat.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,7 @@ bcombat = true; // avoid having multiple instances running

if(isNil "bcombat_enable") then { bcombat_enable = true; };

bcombat_debug_enable = false;
bcombat_debug_levels = [1];
bcombat_debug_chat = true;


bcombat_name = "bcombat AI Infantry mod";
bcombat_short_name = "bcombat";
Expand Down Expand Up @@ -107,7 +105,7 @@ if(isNil "bcombat_penalty_recovery") then { bcombat_penalty_recovery = 2; };

// Investigate
if(isNil "bcombat_allow_investigate") then { bcombat_allow_investigate = false; };
if(isNil "bcombat_investigate_max_distance") then { bcombat_investigate_max_distance = 200; };
if(isNil "bcombat_investigate_max_distance") then { bcombat_investigate_max_distance = 250; };

// Move to cover
if(isNil "bcombat_allow_cover") then { bcombat_allow_cover = false; };
Expand Down Expand Up @@ -177,35 +175,67 @@ if(isNil "bcombat_skill_multiplier") then { bcombat_skill_multiplier = 1; };
// Skill linearity
if(isNil "bcombat_skill_linearity") then { bcombat_skill_linearity = 1; };

// Ballistics handler
if(isNil "bcombat_ballistics_native_handler") then { bcombat_ballistics_native_handler = false; };

// -----------------------------
// Libs loading
// -----------------------------

if( !(bcombat_enable) ) exitWith{};
call compile preprocessFileLineNumbers "\@bcombat\bdetect.sqf";

call compile preprocessFileLineNumbers "\@bcombat\lib\common.sqf";
call compile preprocessFileLineNumbers "\@bcombat\lib\suppression.sqf";
call compile preprocessFileLineNumbers "\@bcombat\lib\fsm.sqf";
call compile preprocessFileLineNumbers "\@bcombat\lib\task.sqf";

bdetect_enable = false;

_nil = [] spawn
{
// -----------------------------
// bDetect init
// -----------------------------

bdetect_enable = true;
bdetect_debug_enable = false;
bdetect_debug_levels = [];
bdetect_debug_chat = true;
bdetect_mp_enable = false;
bdetect_degradation_distance = bcombat_degradation_distance;
bdetect_callback = "bcombat_fnc_bullet_incoming";
if( bcombat_ballistics_native_handler ) then
{
}
else
{
bdetect_enable = true;
bdetect_debug_enable = false;
bdetect_debug_levels = [];
bdetect_debug_chat = true;
bdetect_mp_enable = false;
bdetect_degradation_distance = bcombat_degradation_distance;
bdetect_callback = "bcombat_fnc_bullet_incoming";
bdetect_startup_hint = false;

bdetect_bullet_max_distance = 600; // (Meters) Maximum travelled distance for a bullet (to cause suppression)
bdetect_bullet_max_lifespan = 2.5; // (Seconds) Maximum lifespan for bullet
bdetect_bullet_max_proximity = 7.5; // (Meters) Maximum distance from unit for bullet (to cause suppression)
bdetect_bullet_max_height = 7.5; // (Meters) Maximum height on ground for bullet (to cause suppression)

if( bdetect_enable ) then {
call compile preprocessFileLineNumbers "\@bcombat\bdetect.sqf";
call bdetect_fnc_init;
waitUntil { !(isNil "bdetect_init_done") };
};
};

call bdetect_fnc_init;
waitUntil { !(isNil "bdetect_init_done") };
if ( bcombat_dev_mode ) then
{

//[] spawn bcombat_fnc_debug_text; // Uncomment this line to activare bCombat debug text overlays (as alternative to bcombat_fnc_debug_balloons or bcombat_fnc_fps)
call bcombat_fnc_debug_balloons; // Uncomment this line to activare bCombat debug balloons (as alternative to bcombat_fnc_debug_text or bcombat_fnc_fps)

if( bdetect_enable ) then { call bdetect_fnc_benchmark; }; // Uncomment this line to activate bDetect live stats panel (as alternative to bcombat_fnc_fps)
//[] spawn bcombat_fnc_fps; // Uncomment this line to activate FPS stats panel (as alternative to bdetect_fnc_benchmark;)
// call bcombat_fnc_stats;

OnMapSingleClick "player setpos _pos"; // Uncomment this line to make player able to instantly move to any position by single clicking the map
};

// -----------------------------
// bCombat init
// -----------------------------
Expand All @@ -221,6 +251,7 @@ _nil = [] spawn
};
};


// -----------------------------
// LOOP
// -----------------------------
Expand Down Expand Up @@ -261,10 +292,13 @@ _nil = [] spawn
};

if(
!(isPlayer _unit)
[_unit] call bcombat_fnc_is_active
&& { !(isPlayer _unit) }
&& { !(isPlayer (leader _unit)) }
&& { !(fleeing _unit) }
&& { !(captive _unit) }
&& { behaviour _unit == "COMBAT" }

// && { _unit distance player < bcombat_degradation_distance }
) then {
// unstuck unit
Expand All @@ -274,28 +308,77 @@ _nil = [] spawn
&& { !([_unit] call bcombat_fnc_is_stopped) }
&& { !([_unit] call bcombat_fnc_has_task) }
&& { _unit == formLeader _unit }
&& { leader _unit == _unit || _unit distance (leader _unit) > 50 }
&& { _unit distance ((expecteddestination _unit) select 0) < 5 && ((expecteddestination _unit) select 1) in ["LEADER PLANNED", "DoNotPlan"] }
&& { ( _unit getVariable ["bcombat_suppression_level", 0] <= 25 ) }
//&& { leader _unit == _unit || _unit distance (leader _unit) > 50 }
&& { !( currentCommand _unit in ["HIDE", "HEAL", "HEAL SELF", "REPAIR", "REFUEL", "REARM", "SUPPORT", "GET IN", "GET OUT"]) }
//&& { random 1 > .5 }
) then {


// player globalchat format["%1 - UNSTUCK %2", time, _unit];
// _unit domove getPos _unit;

if( _unit == leader _unit ) then
{
_unit dofollow _unit;
}
else
if(
( isNull (assignedTarget _unit) || !([_unit, assignedTarget _unit] call bcombat_fnc_is_visible) )
) then
{
//_unit dofollow (leader _unit);
_unit dofollow _unit;
if( _unit distance ((expecteddestination _unit) select 0) > 25 && ((expecteddestination _unit) select 1) in ["LEADER PLANNED", "DoNotPlan"] ) then // && { leader _unit != _unit }
{
if( _unit distance ((expecteddestination _unit) select 0) < 100000) then
{

_stop = false;
_p1 = ((expecteddestination _unit) select 0);
_follow = objNull;

Scopename "regroupLoop";

{
if(_unit == _x) then { _stop = true; };

if( ! _stop ) then
{
_p2 = ((expecteddestination _x) select 0);

if ( _x distance _unit < 25
//&& _p1 distance _p2 < 50
&& (_x distance _p2) / (_unit distance _x) >= 3

) then
{
_follow = _x;
breakTo "regroupLoop";
};
};

} foreach units (group _unit);

if(! isNull(_follow) ) then
{
dostop _unit;
_unit dofollow _follow;
// player globalchat format["---> %1 follow %2!!!!!!!", _unit, _follow];
}
else
{
_unit domove ((expecteddestination _unit) select 0);
};
}
else
{
_unit dofollow (formationLeader _unit);
};
}
else
{
if( ( unitready _unit || _unit distance ((expecteddestination _unit) select 0) < 5 ) && ((expecteddestination _unit) select 1) in ["LEADER PLANNED", "DoNotPlan"] ) then
{
_unit dofollow (formationLeader _unit);
};
};
};
};

_enemy = _unit findnearestEnemy _unit;

// If leader, pick nearest enemy as target
// If leader and alone, pick nearest enemy as target
/*
if( _unit == leader _unit) then
{
if( bcombat_allow_targeting
Expand All @@ -310,7 +393,7 @@ _nil = [] spawn
) then {
_unit doTarget _enemy;
};
};
};*/

// Chase actual target
if( bcombat_allow_targeting
Expand Down Expand Up @@ -338,24 +421,11 @@ _nil = [] spawn
&& { [_unit, getPosATL _target] call bcombat_fnc_unit_can_inspect_pos }
) then {

//if( _unit != leader _unit || _dist > 100 ) then
//{
// player globalchat format["### '%1' chase '%2'", _unit, _target];

// _unit doWatch _target;
[_unit, getPosATL _target] call bcombat_fnc_move_team;
//};

/*
if( _prec < 5 ) then {
_unit domove getPosATL _target;
} else {
_unit domove ([getPosATL _target, _prec] call bcombat_fnc_random_pos);
};*/
[_unit, getPosATL _target] call bcombat_fnc_move_team;
};
};

// Avoid individually attacking in urban areas
// Avoid individually attacks in urban areas
if( _unit == leader _unit) then
{
_unit call bcombat_fnc_blacklist_purge;
Expand All @@ -364,8 +434,8 @@ _nil = [] spawn
{
if( !(isNull _enemy)

&& { _unit distance _enemy <= 250 }
&& { count (nearestObjects [_unit, ["house"], 50]) < 5 }
&& { _unit distance _enemy <= 500 }
&& { count (nearestObjects [_unit, ["house"], 75]) < 4 }
) then
{
_unit enableAttack true;
Expand Down
52 changes: 15 additions & 37 deletions config.sqf
Original file line number Diff line number Diff line change
@@ -1,13 +1,3 @@
//><
// -----------------------
// CORE bDetect FEATURES
// -----------------------

bdetect_bullet_max_distance = 600; // (Meters) Maximum travelled distance for a bullet (to cause suppression)
bdetect_bullet_max_lifespan = 2.5; // (Seconds) Maximum lifespan for bullet
bdetect_bullet_max_proximity = 7.5; // (Meters) Maximum distance from unit for bullet (to cause suppression)
bdetect_bullet_max_height = 7.5; // (Meters) Maximum height on ground for bullet (to cause suppression)

//><
// -----------------------
// CORE bCombat FEATURES
Expand All @@ -17,9 +7,15 @@ bdetect_bullet_max_height = 7.5; // (Meters) Maximum height on ground for

bcombat_enable = true; // (Boolean) Toggle feature on / off

// Description: use BIS native close-cullet detection (true) or bDetect (false)

bcombat_ballistics_native_handler = false; // (Boolean) Toggle feature on / off

// Description: toggle debugging information on (true) or off (false)

bcombat_dev_mode = false; // (Boolean) Toggle feature on / off
bcombat_dev_mode = true; // (Boolean) Toggle feature on / off
bcombat_debug_levels = []; // Debug levels
bcombat_debug_chat = true; // Debug in chat

// Description: minimum timeout since last incoming bullet, for the current one to cause suppression.
// As default no more than 5 ( = 1 / 0.2 ) bullets / second would cause suppression on a single AI unit.
Expand All @@ -31,7 +27,7 @@ bcombat_danger_fsm_timeout = 0.1; // (Seconds)
bcombat_danger_distance = 250; // (Meters) Minimum distance from shooter, for groups to automatically switch to "combat" behaviour
bcombat_features_clock = 3; // (Seconds) Additional features clocking
bcombat_damage_multiplier = 1.0; // (0-1) Damage multiplier. Received damage is multiplied by this value. Only infantrymen are affected. Zero makes units invulnerable.
bcombat_degradation_distance = 1500; // (Meters) some bCombat features are cut when some unit is farther than this from player
bcombat_degradation_distance = 1250; // (Meters) some bCombat features are cut when some unit is farther than this from player

//><
// -----------------------------------------------------------------------------------------------------
Expand All @@ -40,20 +36,20 @@ bcombat_degradation_distance = 1500; // (Meters) some bCombat features are cu

// Description: Bullet penalty
// Triggered: whenever under fire and a close bullet is intercepted
// Effect: Up to 5% of skill penalty is applied
// Effect: Up to 3% of skill penalty is applied

bcombat_penalty_bullet = 3; // (Percent) %

// Description: Flanking penalty
// Triggered: whenever under fire and shooter is firing from flank / back,
// Effect: Adds up to 5% further skill penalty

bcombat_penalty_flanking = 3; // (Percent) %
bcombat_penalty_flanking = 5; // (Percent) %

// Description: Enemy unknown penalty
// Adds further penalty to bcombat_penalty_bullet
// Triggered: whenever under fire, if shooter is unknown
// Effect: Adds up to 5% further skill penalty
// Effect: Adds up to 2% further skill penalty

bcombat_penalty_enemy_unknown = 2; // (Percent) %

Expand All @@ -65,7 +61,7 @@ bcombat_penalty_enemy_contact = 25; // (Percent) %

// Description: Explosion / ricochet penalty
// Triggered: on shell exploding nearby, or close ricochet
// Effect: up to 5% skill penalty
// Effect: up to 25% skill penalty

bcombat_penalty_explosion = 2; // (Percent) %

Expand Down Expand Up @@ -130,7 +126,7 @@ bcombat_allow_fleeing = true; // (Boolean) Toggle feature on / off
// Effect: unit plays a surrender animation and gets locked there as captive
// Note: needs bcombat_allow_fleeing = true

bcombat_allow_surrender = true; // (Boolean) Toggle feature on / off
bcombat_allow_surrender = false; // (Boolean) Toggle feature on / off

// Description: slow down leader
// Triggered: whenever a target of opportunity is spotted, or under fire
Expand Down Expand Up @@ -169,7 +165,7 @@ bcombat_suppressive_fire_distance = [50, 150]; // (Array) [minimum distance fr
// Effect: unit is hinted about the shooter, depending on criteria such as visibility and distance.

bcombat_allow_hearing = true; // (Boolean) Toggle feature on / off
bcombat_allow_hearing_coef = 2.5; // (Number) Bullet speed / bcombat_allow_hearing_coef = max. hearing distance (e.g. 900 meters/sec : 3 = max. hearing distance 300m.)
bcombat_allow_hearing_coef = 2; // (Number) Bullet speed / bcombat_allow_hearing_coef = max. hearing distance (e.g. 900 meters/sec : 3 = max. hearing distance 300m.)
bcombat_allow_hearing_grenade_distance = 250; // (Meters) Max. distance for grenade hearing

// Description: CQB hand grenade throwing
Expand Down Expand Up @@ -212,7 +208,7 @@ bcombat_allow_fatigue = false; // (Boolean) Toggle feature on / off

bcombat_allow_cover = true; // (Boolean) Toggle feature on / off
bcombat_cover_mode = 1; // (0,1) 0 = apply only to leader, 1 = apply to all units
bcombat_cover_radius = [20, 0]; // (Array) [ maximum distance from object, maximum distance from building]
bcombat_cover_radius = [15, 0]; // (Array) [ maximum distance from object, maximum distance from building]

// Description: "target and chase" behaviour
// Triggered: whenever unit has no target and it's close to a enemy
Expand Down Expand Up @@ -286,24 +282,6 @@ bcombat_skill_min_player_group = 0.5; // (0-1) enforce minimum skill for unit
// Effect: show / hides bCombat startup hint

bcombat_startup_hint = true;
bdetect_startup_hint = false;

//><
// -----------------------------------------------------------------------------------------------------
// bCombat MISC CALLS
// -----------------------------------------------------------------------------------------------------

if ( bcombat_dev_mode ) then
{

[] spawn bcombat_fnc_debug_text; // Uncomment this line to activare bCombat debug text overlays (as alternative to bcombat_fnc_debug_balloons or bcombat_fnc_fps)
//call bcombat_fnc_debug_balloons; // Uncomment this line to activare bCombat debug balloons (as alternative to bcombat_fnc_debug_text or bcombat_fnc_fps)

call bdetect_fnc_benchmark; // Uncomment this line to activate bDetect live stats panel (as alternative to bcombat_fnc_fps)
//[] spawn bcombat_fnc_fps; // Uncomment this line to activate FPS stats panel (as alternative to bdetect_fnc_benchmark;)
// call bcombat_fnc_stats;

OnMapSingleClick "player setpos _pos"; // Uncomment this line to make player able to instantly move to any position by single clicking the map
};

//><
Loading

0 comments on commit e7cef28

Please sign in to comment.