Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: Unscheduled with btc_delay_createUnit #799

Merged
merged 16 commits into from
Mar 31, 2020
Merged
1 change: 1 addition & 0 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/def/mission.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private _allClassSorted = _allClassVehicles select {getNumber (_cfgVehicles >> _

if (isServer) then {
btc_final_phase = false;
btc_delay_createUnit = 0;

//City
btc_city_radius = _p_city_radius;
Expand Down
31 changes: 18 additions & 13 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/city/activate.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ params [
_wp_ratios params ["_wp_house", "_wp_sentry"];

if (btc_debug) then {
("Activate " + str _id) call CBA_fnc_notify;
[str _id, __FILE__, [btc_debug, btc_debug_log, true]] call btc_fnc_debug_message;
};

private _city = btc_city_all select _id;
Expand Down Expand Up @@ -129,14 +129,6 @@ if !(_data_units isEqualTo []) then {
};
};

if (_has_en) then {
private _trigger = createTrigger ["EmptyDetector", getPos _city];
_trigger setTriggerArea [_radius_x + _radius_y, _radius_x + _radius_y, 0, false];
_trigger setTriggerActivation [str btc_enemy_side, "NOT PRESENT", false];
_trigger setTriggerStatements ["this", format ["[%1] call btc_fnc_city_set_clear", _id], ""];
_city setVariable ["trigger", _trigger];
};

if (_city getVariable ["spawn_more", false]) then {
_city setVariable ["spawn_more", false];
for "_i" from 1 to (round (_p_mil_group_ratio * (2 + random 3))) do {
Expand All @@ -150,9 +142,10 @@ if (_city getVariable ["spawn_more", false]) then {
};
};

if !(btc_cache_pos isEqualTo []) then {
if !(btc_cache_pos isEqualTo [] && {!(btc_cache_obj getVariable ["btc_cache_unitsSpawned", false])}) then {
if (_city inArea [btc_cache_pos, _radius_x + _radius_y, _radius_x + _radius_y, 0, false]) then {
if (count (btc_cache_pos nearEntities ["Man", 30]) > 3) exitWith {};
btc_cache_obj setVariable ["btc_cache_unitsSpawned", true];

[btc_cache_pos, 8, 3, _wp_house] call btc_fnc_mil_create_group;
[btc_cache_pos, 60, 4, _wp_sentry] call btc_fnc_mil_create_group;
if (btc_p_veh_armed_spawn_more) then {
Expand Down Expand Up @@ -205,7 +198,19 @@ if !(_city getVariable ["has_suicider", false]) then {
};
};

_city setVariable ["activating", false];
[{
params ["_has_en", "_city", "_radius_x", "_radius_y", "_id"];

if (_has_en) then {
private _trigger = createTrigger ["EmptyDetector", getPos _city];
_trigger setTriggerArea [_radius_x + _radius_y, _radius_x + _radius_y, 0, false];
_trigger setTriggerActivation [str btc_enemy_side, "NOT PRESENT", false];
_trigger setTriggerStatements ["this", format ["[%1] call btc_fnc_city_set_clear", _id], ""];
_city setVariable ["trigger", _trigger];
};

_city setVariable ["activating", false];
}, [_has_en, _city, _radius_x, _radius_y, _id], btc_delay_createUnit] call CBA_fnc_waitAndExecute;

//Patrol
btc_patrol_active = btc_patrol_active - [grpNull];
Expand All @@ -218,7 +223,7 @@ if (_number_patrol_active < _p_patrol_max) then {
private _d = _n - _av;
_r = if (_d > 0) then {_n - _d;} else {_n;};
for "_i" from 1 to _r do {
[1 + round random 1, _city, _radius_x + _radius_y + btc_patrol_area] spawn btc_fnc_mil_create_patrol;
[1 + round random 1, _city, _radius_x + _radius_y + btc_patrol_area] call btc_fnc_mil_create_patrol;
};

if (btc_debug_log) then {
Expand Down
16 changes: 9 additions & 7 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/city/cleanUp.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -37,13 +37,15 @@ _toRemove append (allDead select {
(_playableUnits inAreaArray [getPosWorld _dead, 500, 500]) isEqualTo [] && !(_dead getVariable ["btc_dont_delete", false])
});

_toRemove append (allGroups select {
units _x select {alive _x} isEqualTo [] &&
!(
_x in btc_patrol_active ||
_x in btc_civ_veh_active
)
});
if (btc_delay_createUnit < 0.001) then { // Don't remove group during units creation.
_toRemove append (allGroups select {
units _x select {alive _x} isEqualTo [] &&
!(
_x in btc_patrol_active ||
_x in btc_civ_veh_active
)
});
};

_toRemove call CBA_fnc_deleteEntity;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if !(_city getVariable ["active", false]) exitWith {};
params ["_city", "_id"];

if (btc_debug) then {
("DE-Activate " + str _id) call CBA_fnc_notify;
[str _id, __FILE__, [btc_debug, btc_debug_log, true]] call btc_fnc_debug_message;
};

//Save all and delete
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ params [
private _trigger = createTrigger ["EmptyDetector", _position];
_trigger setTriggerArea [_radius_x + _radius_y + btc_city_radius, _radius_x + _radius_y + btc_city_radius, 0, false];
_trigger setTriggerActivation ["ANYPLAYER", "PRESENT", true];
_trigger setTriggerStatements [btc_p_trigger, format ["[%1] spawn btc_fnc_city_activate", _id], format ["[%1] call btc_fnc_city_de_activate", _id]];
_trigger setTriggerStatements [btc_p_trigger, format ["[%1] call btc_fnc_city_activate", _id], format ["[%1] call btc_fnc_city_de_activate", _id]];
_city setVariable ["trigger_player_side", _trigger];

if (btc_debug) then {
Expand Down
37 changes: 15 additions & 22 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/civ/create_patrol.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -57,32 +57,25 @@ if (_roads isEqualTo []) then {
_veh_type = selectRandom btc_civ_type_veh;
};

private _veh = createVehicle [_veh_type, _safe_pos, [], 0, "FLY"];
[_veh, "", []] call BIS_fnc_initvehicle;

private _group = createGroup [civilian, true];
private _group = createGroup civilian;
btc_civ_veh_active pushBack _group;
_group setVariable ["no_cache", true];
_group setVariable ["btc_patrol_id", btc_civilian_id, btc_debug];
btc_civilian_id = btc_civilian_id - 1;
(selectRandom btc_civ_type_units) createUnit [_safe_pos, _group, "this moveinDriver _veh; this assignAsDriver _veh;"];
_veh setVariable ["btc_crews", _group];

[_group] call btc_fnc_civ_unit_create;

[_veh, "HandleDamage", "btc_fnc_patrol_disabled"] call btc_fnc_eh_persistOnLocalityChange;
[_veh, "Fuel", "btc_fnc_patrol_eh"] call btc_fnc_eh_persistOnLocalityChange;
[_veh, "GetOut", "btc_fnc_patrol_eh"] call btc_fnc_eh_persistOnLocalityChange;
[_veh, "HandleDamage", "btc_fnc_rep_hd"] call btc_fnc_eh_persistOnLocalityChange;
if (_p_chem) then {
_veh addEventHandler ["GetIn", {
[_this select 0, _this select 2] call btc_fnc_chem_propagate;
_this
}];
};

[_group, [_start_city, _active_city], _area, _pos_isWater] call btc_fnc_patrol_init;

[[_group]] call btc_fnc_set_groupsOwner;
[_group, _veh_type, [selectRandom btc_civ_type_units], _safe_pos, {
params ["_veh", "_group"];
_veh setVariable ["btc_crews", _group];
[_veh, "HandleDamage", "btc_fnc_patrol_disabled"] call btc_fnc_eh_persistOnLocalityChange;
[_veh, "Fuel", "btc_fnc_patrol_eh"] call btc_fnc_eh_persistOnLocalityChange;
[_veh, "GetOut", "btc_fnc_patrol_eh"] call btc_fnc_eh_persistOnLocalityChange;
[_veh, "HandleDamage", "btc_fnc_rep_hd"] call btc_fnc_eh_persistOnLocalityChange;
}] call btc_fnc_delay_createVehicle;

[{
[_this select 0] call btc_fnc_civ_unit_create;
_this call btc_fnc_patrol_init;
[[_this select 0]] call btc_fnc_set_groupsOwner;
}, [_group, [_start_city, _active_city], _area, _pos_isWater], btc_delay_createUnit] call CBA_fnc_waitAndExecute;

true
14 changes: 9 additions & 5 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/civ/populate.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,16 @@ for "_i" from 1 to _n do {
if (_houses isEqualTo []) exitWith {};

private _house = selectRandom _houses;
private _unit_type = selectRandom btc_civ_type_units;

private _pos = _house buildingPos 0;
private _group = createGroup civilian;
_group createUnit [_unit_type, _house buildingPos 0, [], 0, "NONE"];
_group setVariable ["btc_data_inhouse", [_house buildingPos 0]];
[_group] call btc_fnc_civ_addWP;
[_group] call btc_fnc_civ_unit_create;
_group setVariable ["btc_data_inhouse", [_pos]];
[_group, _pos] call btc_fnc_civ_addWP;
[_group, selectRandom btc_civ_type_units, _pos] call btc_fnc_delay_createUnit;

[{
_this call btc_fnc_civ_unit_create;
}, [_group], btc_delay_createUnit] call CBA_fnc_waitAndExecute;

_houses = _houses - [_house];
};
4 changes: 4 additions & 0 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/compile.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,10 @@ if (isServer) then {
btc_fnc_db_saveObjectStatus = compile preprocessFileLineNumbers "core\fnc\db\saveObjectStatus.sqf";
btc_fnc_db_loadCargo = compile preprocessFileLineNumbers "core\fnc\db\loadcargo.sqf";

//DELAY
btc_fnc_delay_createUnit = compile preprocessFileLineNumbers "core\fnc\delay\createUnit.sqf";
btc_fnc_delay_createVehicle = compile preprocessFileLineNumbers "core\fnc\delay\createVehicle.sqf";

//EH
btc_fnc_eh_veh_add_respawn = compile preprocessFileLineNumbers "core\fnc\eh\veh_add_respawn.sqf";
btc_fnc_eh_veh_killed = compile preprocessFileLineNumbers "core\fnc\eh\veh_killed.sqf";
Expand Down
22 changes: 13 additions & 9 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/data/get_group.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -25,10 +25,12 @@ params [
];

private _units = units _group;
if (_units select {alive _x} isEqualTo []) exitWith {nil};

private _type_db = 0;
private _array_pos = [];
private _array_type = [];
private _side = side (leader _group);
private _side = side _group;
private _array_dam = [];
private _behaviour = [behaviour (leader _group), combatMode _group, formation _group];
private _array_wp = [];
Expand All @@ -37,15 +39,17 @@ private _array_veh = [];
private _index_wp = 0;

{
private _pos = getPosATL _x;
if (surfaceIsWater _pos) then {
_array_pos pushBack getPos _x;
} else {
_array_pos pushBack _pos;
};
if (getDammage _x < 1) then {
private _pos = getPosATL _x;
if (surfaceIsWater _pos) then {
_array_pos pushBack getPos _x;
} else {
_array_pos pushBack _pos;
};

_array_type pushBack typeOf _x;
_array_dam pushBack getDammage _x;
_array_type pushBack typeOf _x;
_array_dam pushBack getDammage _x;
};
} forEach _units;

_index_wp = (currentWaypoint _group) + 1;
Expand Down
114 changes: 45 additions & 69 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/data/spawn_group.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -57,79 +57,55 @@ if (_type isEqualTo 7) exitWith {
};

private _group = createGroup _side;

for "_i" from 0 to (count _array_pos - 1) do {
private _u = _group createUnit [_array_type select _i, _array_pos select _i, [], 0, "NONE"];
_u enableSimulation false;
_u setPosATL (_array_pos select _i);
_u setDamage (_array_dam select _i);

if (btc_debug_log) then {
[format ["pos %1 in %2 ", _array_pos select _i, getPos _u], __FILE__, [false]] call btc_fnc_debug_message;
};
};

if (_type isEqualTo 1) then {
private _veh = createVehicle [_array_veh select 0, _array_veh select 1, [], 0, "FLY"];
if !(_veh isKindOf "Plane") then {
_veh setPosATL (_array_veh select 1);
_veh setDir (_array_veh select 2);
};
_veh setFuel (_array_veh select 3);
{
private _assigned = false;
if (!_assigned && _veh emptyPositions "driver" > 0) then {
_x moveInDriver _veh;
_x assignAsDriver _veh;
_assigned = true;
};
if (!_assigned && _veh emptyPositions "gunner" > 0) then {
_x moveinGunner _veh;
_x assignAsGunner _veh;
_assigned = true;
};
if (!_assigned && _veh emptyPositions "commander" > 0) then {
_x moveinCommander _veh;
_x assignAsCommander _veh;
_assigned = true;
};
if (!_assigned && _veh emptyPositions "cargo" > 0) then {
_x moveinCargo _veh;
_x assignAsCargo _veh;
_assigned = true;
[_group, _array_veh select 0, _array_type, _array_veh select 1, {}, _array_veh select 2, _array_veh select 3] call btc_fnc_delay_createVehicle;
} else {
for "_i" from 0 to (count _array_pos - 1) do {
[_group, _array_type select _i, _array_pos select _i, "CAN_COLLIDE"] call btc_fnc_delay_createUnit;
//_u setDamage (_array_dam select _i);

if (btc_debug_log) then {
[format ["pos %1 in %2 ", _array_pos select _i], __FILE__, [false]] call btc_fnc_debug_message;
};
} forEach units _group;
};

units _group joinSilent _group;
(units _group) apply {_x enableSimulation true};

//[waypointPosition _x,waypointType _x,waypointSpeed _x,waypointFormation _x,waypointCombatMode _x,waypointBehaviour _x]
if !(_side isEqualTo civilian && {vehicle leader _group isEqualTo leader _group}) then {
if (count (_array_wp select 1) > 1) then {
{
[_group, _x select 0, -1, _x select 1, _x select 5, _x select 4, _x select 2, _x select 3, "", [0, 0, 0], 20] call CBA_fnc_addWaypoint;
} forEach (_array_wp select 1);
_group setCurrentWaypoint [_group, _array_wp select 0];
};
};
if (_type isEqualTo 3) then {
[_group] call CBA_fnc_clearWaypoints;
[_group, nearestObject [(units _group) select 0, _array_veh]] call btc_fnc_house_addWP;
_group setVariable ["btc_inHouse", _array_veh];
};
if (_type isEqualTo 4) then {[[0, 0, 0], 0, units _group] call btc_fnc_civ_get_weapons;};
if (_type isEqualTo 6) then {
[_group] call CBA_fnc_clearWaypoints;
[_group, _array_veh select 0] call btc_fnc_civ_addWP;
_group setVariable ["btc_data_inhouse", _array_veh];
};

_group setBehaviour (_behaviour select 0);
_group setCombatMode (_behaviour select 1);
_group setFormation (_behaviour select 2);
[{
params ["_data_unit", "_group"];
_data_unit params [
["_type", 1, [0]],
["_array_pos", [], [[]]],
["_array_type", [], [[]]],
["_side", east, [east]],
["_array_dam", [], [[]]],
["_behaviour", [], [[]]],
["_array_wp", [], [[]]],
["_array_veh", [], [[], ""]]
];

//[waypointPosition _x,waypointType _x,waypointSpeed _x,waypointFormation _x,waypointCombatMode _x,waypointBehaviour _x]
if !(_side isEqualTo civilian && {vehicle leader _group isEqualTo leader _group}) then {
if (count (_array_wp select 1) > 1) then {
{
[_group, _x select 0, -1, _x select 1, _x select 5, _x select 4, _x select 2, _x select 3, "", [0, 0, 0], 20] call CBA_fnc_addWaypoint;
} forEach (_array_wp select 1);
_group setCurrentWaypoint [_group, _array_wp select 0];
};
};
if (_type isEqualTo 3) then {
[_group, nearestObject [_array_pos select 0, _array_veh]] call btc_fnc_house_addWP;
_group setVariable ["btc_inHouse", _array_veh];
};
if (_type isEqualTo 4) then {[[0, 0, 0], 0, units _group] call btc_fnc_civ_get_weapons;};
if (_type isEqualTo 6) then {
[_group, _array_veh select 0] call btc_fnc_civ_addWP;
_group setVariable ["btc_data_inhouse", _array_veh];
};

if (_side isEqualTo btc_enemy_side) then {[_group] call btc_fnc_mil_unit_create;};
if (_side isEqualTo civilian) then {[_group] call btc_fnc_civ_unit_create};
_group setBehaviour (_behaviour select 0);
_group setCombatMode (_behaviour select 1);
_group setFormation (_behaviour select 2);

[leader _group, _type]
if (_side isEqualTo btc_enemy_side) then {[_group] call btc_fnc_mil_unit_create;};
if (_side isEqualTo civilian) then {[_group] call btc_fnc_civ_unit_create};
}, [_data_unit, _group], btc_delay_createUnit] call CBA_fnc_waitAndExecute;
2 changes: 1 addition & 1 deletion =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/debug/dlg.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ class TER_fpscounter
class TXT_units: RscText
{
idc = 1002;
text = "UNITS:0 NOT-ON-SERVER:0 | GROUPS:0 | Patrol:0 Traffic:0";
text = "DELAY:0s UNITS:0 NOT-ON-SERVER:0 | GROUPS:0 | Patrol:0 Traffic:0";
x = (0.5525 + 0.085) * safezoneW + safezoneX;
y = 0.71 * safezoneH + safezoneY;
w = (0.0590625 + 0.4) * safezoneW;
Expand Down
2 changes: 1 addition & 1 deletion =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/debug/graph.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ private _maxFps = 60;
private _maxWidth = ctrlPosition _GRPframes select 2;
private _width = _maxWidth/300;

[btc_fnc_debug_fps, 0.5, [_display, _maxFps, _maxWidth, _width, _barArray, _GRPframes, _TXTfps]] call CBA_fnc_addPerFrameHandler;
[btc_fnc_debug_fps, [0.5, 0.1] select (isServer), [_display, _maxFps, _maxWidth, _width, _barArray, _GRPframes, _TXTfps]] call CBA_fnc_addPerFrameHandler;

[btc_fnc_debug_units, 1, [_display, _TXTunits]] call CBA_fnc_addPerFrameHandler;
3 changes: 2 additions & 1 deletion =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/debug/units.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,8 @@ if (isNull _display || !btc_debug_graph) exitWith {
[10, objNull, "btc_units_owners"] remoteExecCall ["btc_fnc_int_ask_var", 2];
["btc_patrol_active", objNull, "btc_patrol_active"] remoteExecCall ["btc_fnc_int_ask_var", 2];
["btc_civ_veh_active", objNull, "btc_civ_veh_active"] remoteExecCall ["btc_fnc_int_ask_var", 2];
["btc_delay_createUnit", objNull, "btc_delay_createUnitDebug"] remoteExecCall ["btc_fnc_int_ask_var", 2];
private _count_units = {(_x select 0) isKindOf "man"} count btc_units_owners;
private _count_units_own = {((_x select 1) isEqualTo 2) && ((_x select 0) isKindOf "man")} count btc_units_owners;

_TXTunits ctrlSetText format ["UNITS:%1 NOT-ON-SERVER:%2 | GROUPS:%3 | Patrol:%4 Traffic:%5", _count_units, _count_units - _count_units_own, count allGroups, count btc_patrol_active, count btc_civ_veh_active];
_TXTunits ctrlSetText format ["DELAY:%1s UNITS:%2 NOT-ON-SERVER:%3 | GROUPS:%4 | Patrol:%5 Traffic:%6", [btc_delay_createUnitDebug, 0] select (btc_delay_createUnitDebug < 0.001), _count_units, _count_units - _count_units_own, count allGroups, count btc_patrol_active, count btc_civ_veh_active];
Loading