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

Battlegroup boats #967

Open
wants to merge 7 commits into
base: v0.96.8
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
* Added: Czech translation. Thanks to [MJVEVERUSKA](https://github.com/MJVEVERUSKA)
* Added: Ability to carry ressource crates.
* Added: Scripts/configs to setup and run development environment from VSCode tasks
* Added: Enemy boats can spawn as part of battlegroups
* Updated: Italian localization. Thanks to [k4s0](https://github.com/k4s0)
* Tweaked: Splitted the config file in separate files, as it was getting quite big.
* Tweaked: Unified the prefix of all variables to `KPLIB_`.
Expand Down
2 changes: 2 additions & 0 deletions Missionframework/functions/fn_initSectors.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

KPLIB_sectors_airSpawn = [];
KPLIB_sectors_all = [];
KPLIB_sectors_boatSpawn = [];
KPLIB_sectors_capital = [];
KPLIB_sectors_city = [];
KPLIB_sectors_factory = [];
Expand All @@ -31,6 +32,7 @@ KPLIB_sectors_tower = [];
case (_x find "factory" == 0): {KPLIB_sectors_factory pushBack _x; KPLIB_sectors_all pushBack _x;};
case (_x find "military" == 0): {KPLIB_sectors_military pushBack _x; KPLIB_sectors_all pushBack _x;};
case (_x find "opfor_airspawn" == 0): {KPLIB_sectors_airSpawn pushBack _x;};
case (_x find "opfor_boatspawn" == 0): {KPLIB_sectors_boatSpawn pushBack _x;};
case (_x find "opfor_point" == 0): {KPLIB_sectors_spawn pushBack _x;};
case (_x find "tower" == 0): {KPLIB_sectors_tower pushBack _x; if (isServer) then {_x setMarkerText format ["%1 %2",markerText _x, mapGridPosition (markerPos _x)];}; KPLIB_sectors_all pushBack _x;};
};
Expand Down
4 changes: 4 additions & 0 deletions Missionframework/presets/enemies/custom.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -149,3 +149,7 @@ KPLIB_o_planes = [
"O_Plane_CAS_02_dynamicLoadout_F", // To-199 Neophron (CAS)
"O_Plane_Fighter_02_F" // To-201 Shikra
];

KPLIB_o_boats = [
"O_Boat_Armed_01_hmg_F" // Speedboat HMG
]
4 changes: 3 additions & 1 deletion Missionframework/presets/init_presets.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,7 @@ KPLIB_o_battleGrpVehiclesLight = KPLIB_o_battleGrpVehiclesLight select {[_x]
KPLIB_o_troopTransports = KPLIB_o_troopTransports select {[_x] call KPLIB_fnc_checkClass};
KPLIB_o_helicopters = KPLIB_o_helicopters select {[_x] call KPLIB_fnc_checkClass};
KPLIB_o_planes = KPLIB_o_planes select {[_x] call KPLIB_fnc_checkClass};
KPLIB_o_boats = KPLIB_o_boats select {[_x] call KPLIB_fnc_checkClass};

// Resistance
KPLIB_r_units = KPLIB_r_units select {[_x] call KPLIB_fnc_checkClass};
Expand Down Expand Up @@ -234,7 +235,8 @@ KPLIB_o_allVeh_classes = [];
KPLIB_o_battleGrpVehiclesLight,
KPLIB_o_troopTransports,
KPLIB_o_helicopters,
KPLIB_o_planes
KPLIB_o_planes,
KPLIB_o_boats
];
KPLIB_o_allVeh_classes = KPLIB_o_allVeh_classes apply {toLower _x};
KPLIB_o_allVeh_classes = KPLIB_o_allVeh_classes arrayIntersect KPLIB_o_allVeh_classes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,6 +68,10 @@ if !(_spawn_marker isEqualTo "") then {
};
} forEach _selected_opfor_battlegroup;

if (KPLIB_param_aggressivity > 0.5) then {
[[markerPos _spawn_marker] call KPLIB_fnc_getNearestBluforObjective] spawn spawn_boat;
};

if (KPLIB_param_aggressivity > 0.9) then {
[[markerPos _spawn_marker] call KPLIB_fnc_getNearestBluforObjective] spawn spawn_air;
};
Expand Down
94 changes: 94 additions & 0 deletions Missionframework/scripts/server/battlegroup/spawn_boat.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
//jank and mangled spawn_air implementation
params ["_first_objective"];

if (KPLIB_o_boats isEqualTo []) exitWith {false};

private _boats_number = ((floor linearConversion [25, 100, KPLIB_enemyReadiness, 1, 2]) min 2) max 0;

if (_boats_number < 1) exitWith {};

private _class = selectRandom KPLIB_o_boats;
private _spawnPoint = ([KPLIB_sectors_boatSpawn, [_first_objective], {(markerPos _x) distance _input0}, "ASCEND"] call BIS_fnc_sortBy) select 0;
private _spawnPos = [];
private _boat = objNull;
private _boats = [];
private _grp = createGroup [KPLIB_side_enemy, true];

for "_i" from 1 to _boats_number do {
_spawnPos = markerPos _spawnPoint;
_spawnPos = [(((_spawnPos select 0) + 5) - random 1), (((_spawnPos select 1) + 5) - random 1), 2];
_boat = createVehicle [_class, _spawnPos, [], 0, "NONE"];
createVehicleCrew _boat;
_boats pushBack _boat;
_boat addMPEventHandler ["MPKilled", {_this spawn kill_manager}];
[_boat] call KPLIB_fnc_addObjectInit;
{_x addMPEventHandler ["MPKilled", {_this spawn kill_manager}];} forEach (crew _boat);
(crew _boat) joinSilent _grp;
sleep 1;
};

while {!((waypoints _grp) isEqualTo [])} do {deleteWaypoint ((waypoints _grp) select 0);};
sleep 1;
{_x doFollow leader _grp} forEach (units _grp);
sleep 1;

private _posFound = false;
private _randomPos = [];
private _boatWaypoint = [];
private _waterDepth = 0;

//create waypoints for boats
for "_i" from 1 to 6 do{
_searchCounter = 0;
while {!_posFound} do
{
_randomPos - [];
//counter because there are cases where there will be water near an objective but none will be deep enough
//most boats can drive in 1m of water, but i have it set to 2m since that will keep waypoints from being put super close to shore
_searchCounter = _searchCounter + 1;

if(_searchCounter isEqualTo 20) then {break};

_randomPos = [_first_objective,1,300,0,2] call BIS_fnc_findSafePos;

if(_randomPos distance _first_objective > 500) then {break};

_boatWaypoint = _randomPos;
_randomPos pushBack 0;
//this literally just makes a rock that tells me how deep the water is
_depthRock = createSimpleObject ["Land_Cliff_stone_small_F",_randomPos];
_waterDepth = getPosATL _depthRock select 2;
//RIP rock
deleteVehicle _depthRock;
if (!(_waterDepth < 2)) then
{
_posFound = true;
};
};
if(_boatWaypoint isEqualTo []) then {break};
_waypoint = _grp addWaypoint [_boatWaypoint, 1];
_waypoint setWayPointType "SAD";
_posFound = false;
};
//if there's no suitable waypoints for the boat, get rid of it
if (((_randomPos distance _first_objective) > 500) || (_waterDepth < 2)) exitWith {
{deleteVehicle _x} forEach units _grp;
{deleteVehicle _x} forEach _boats;
deleteGroup _grp;
};
_waypoint = _grp addWaypoint [_boatWaypoint,1];
_waypoint setWaypointType "CYCLE";

_grp setCurrentWaypoint [_grp, 2];

// wait and check if the boat has moved yet, and delete it if not (boats won't move if their waypoint can't be reached)
// this is really only necessary on maps with sectors near lakes, which the script would interpret as good waypoints, but would be typically inaccessible
// sleep 15 since with scheduled things spawning of boats can be a bit delayed and with lower timers they could be deleted before they have a chance to move
// checks the first boat in the array since the lead boat will sit still if the waypoint is inaccesssible, but the follower boat will constantly drive around the leader
sleep 15;

if(abs(speed (_boats select 0)) < 5) exitWith{
{deleteVehicle _x} forEach units _grp;
{deleteVehicle _x} forEach _boats;
deleteGroup _grp;
};
1 change: 1 addition & 0 deletions Missionframework/scripts/server/init_server.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ troup_transport = compile preprocessFileLineNumbers "scripts\server\ai\troup_tra

// Battlegroup
spawn_air = compile preprocessFileLineNumbers "scripts\server\battlegroup\spawn_air.sqf";
spawn_boat = compileFinal preprocessFileLineNumbers "scripts\server\battlegroup\spawn_boat.sqf";
spawn_battlegroup = compile preprocessFileLineNumbers "scripts\server\battlegroup\spawn_battlegroup.sqf";

// Game
Expand Down