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

Adding Direct Vehicle Move waypoint #11

Open
wants to merge 11 commits into
base: master
Choose a base branch
from
1 change: 1 addition & 0 deletions addons/waypoint/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\afmf\addons\waypoint
13 changes: 13 additions & 0 deletions addons/waypoint/CfgWaypoints.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CfgWaypoints {
class AF_Waypoints {
CommandDDOS marked this conversation as resolved.
Show resolved Hide resolved
displayName = "ArmaForces";
class Move_vehicle {
displayName = CSTRING(Vehicle_Move_Name);
Copy link
Member

@veteran29 veteran29 Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Vehicle Move or Move Vehicle, stringtable naming is inconsistent with class. Also use camelpascal case for this (VehicleMove or MoveVehicle)

Copy link
Member

@3Mydlo3 3Mydlo3 Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actually VehicleMove or MoveVehicle would be PascalCase, not camelCase.

file = QPATHTOF(functions\fnc_moveVehicleWp.sqf);
icon = "\a3\3DEN\Data\CfgWaypoints\Move_ca.paa";
tooltip = CSTRING(Vehicle_Move_Description);
};


};
};
8 changes: 8 additions & 0 deletions addons/waypoint/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
## Arsenal

Waypoints:
- Vehicle Move - Order vehicle to move in strain line to target ignoring AI orders and situation. waypoint create pool of vehicles where group units are driver and create new group per vehicle

### Authors

- Command DDOS
2 changes: 2 additions & 0 deletions addons/waypoint/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PREP(fnc_moveVehicleWp);
CommandDDOS marked this conversation as resolved.
Show resolved Hide resolved

1 change: 1 addition & 0 deletions addons/waypoint/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "script_component.hpp"
7 changes: 7 additions & 0 deletions addons/waypoint/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
#include "script_component.hpp"
ADDON = false;

PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;
CommandDDOS marked this conversation as resolved.
Show resolved Hide resolved
ADDON = true;
2 changes: 2 additions & 0 deletions addons/waypoint/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
#include "script_component.hpp"
#include "XEH_PREP.hpp"
7 changes: 7 additions & 0 deletions addons/waypoint/ZEN_CfgWaypointTypes.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
class ZEN_WaypointTypes {
class GVAR(VehicleMove) {
displayName = CSTRING(Vehicle_Move_Name);
type = "SCRIPTED";
script = QPATHTOF(functions\fnc_moveVehicleWP.sqf);
};
};
19 changes: 19 additions & 0 deletions addons/waypoint/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "script_component.hpp"

class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {
"afmf_main"
};
author = "ArmaForces";
authors[] = {"Command DDOS"};
VERSION_CONFIG;
};
};

#include "CfgWaypoints.cfg"
#include "ZEN_CfgWaypointTypes.hpp"
135 changes: 135 additions & 0 deletions addons/waypoint/functions/fnc_moveVehicleWp.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,135 @@
#include "script_component.hpp"
/*
* Author: Command DDOS
*
*
* Arguments:
* 0: group
* 1: pos
*
* Return Value:
* none
*
*/
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Comment does not follow the template, excess line between author and arguments.


params ["_group", "_pos"];

if !(local _group) exitwith {false};

//vehicle list
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Unnecessary comment, it's obvious what _vehicles = []; means.

Suggested change
//vehicle list

private _vehicles = [];
{
_vehicles pushBackUnique (vehicle _x);
} forEach (units _group);

_vehicles = _vehicles select {assignedDriver _x in (units _group)};

if (count _vehicles == 0) exitwith {true};


private _LeaderVehicle = vehicle leader _group;
CommandDDOS marked this conversation as resolved.
Show resolved Hide resolved

// create groups with waypoint for vehicles without leader vehicle
{
private _vehicle = _X;
private _newgroup = createGroup (side _group);
private _UnitsInVehicle = (units _group select {_x in (Crew _vehicle)});
_UnitsInVehicle joinSilent _newGroup;
_group leaveVehicle _vehicle;
_newgroup addVehicle _vehicle;
private _nearPos = _pos vectorAdd [random 5,random 5,0];
private _waypoint = _newGroup addWaypoint [_nearPos,0];
_waypoint setWaypointType "SCRIPTED";
_waypoint setWaypointScript QPATHTOF(functions\fnc_moveVehicleWP.sqf);
} foreach (_vehicles - [_LeaderVehicle]);

if !(driver _LeaderVehicle in (units _group)) exitwith {true};

// at this point there should be always 1 vehicle to process with leader inside
private _driver = driver _LeaderVehicle;

//prevent when driver is not avaible
if !(alive _driver) exitwith {true};
if (lifestate _driver == "INCAPACITATED") exitwith {true};

//calculate positions
private _posVehicleATL = getposATL _LeaderVehicle;
private _vectorDir = _posVehicleATL vectorDiff _pos;
private _vectorDirNormalized = vectorNormalized _vectorDir ;
private _pos1 = _pos vectorAdd (_vectorDirNormalized vectorMultiply 1);
private _pos2 = _pos;
private _pos3 = _pos vectorAdd (_vectorDirNormalized vectorMultiply -1);
//update pos used in WUAE
_LeaderVehicle setvariable [QGVAR(TargetArrayMovePosition),[_pos1,_pos2,_pos3]];

//create WUAE only when needed
if !(_LeaderVehicle getvariable [QGVAR(ActiveVehicleMove),false]) then {

_LeaderVehicle setvariable [QGVAR(ActiveVehicleMove),true];

//making group/unit easier to command
_driver setVariable ["lambs_danger_disableAI", true];
(group _driver) setVariable ["lambs_danger_disablegroupAI", true];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should save and restore values of these variables after the waypoint is completed.


_driver enableAI "PATH";
_driver domove _pos2;
_driver disableAI "AUTOTARGET";
_driver disableAI "AUTOCOMBAT";
_driver disableAI "TARGET";
_driver disableai "COVER";
_driver disableai "FSM";
CommandDDOS marked this conversation as resolved.
Show resolved Hide resolved
_driver setBehaviour "AWARE";

_LeaderVehicle setvariable [QGVAR(DriverWaitTime),(time + 1)];
_LeaderVehicle setDriveOnPath (_LeaderVehicle getvariable QGVAR(TargetArrayMovePosition));

[{
//condition
params ["_vehicle","_group"];
if !(waypointScript [_group,currentWaypoint _group] == QPATHTOF(functions\fnc_moveVehicleWP.sqf)) exitwith {true};
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if next waypoint is the same? Will there be 2 competing scripts? I don't see a valid reason for checking waypointScript. The only thing that should matter is active waypoint number (you could pass it as an argument to WUAE to have the old value for comparison).

Copy link
Author

@CommandDDOS CommandDDOS Sep 13, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but waypoint gonna end only when WUAE is complete, so new wuae gonna be created for next waypoint
and this is to complete WUAE after ZEUS change Waypointype
edit. In arma 2.18 gonna be a option to replace it by passing _ThisScript to WUAE

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, can be resolved then.

if !(alive (driver _vehicle)) exitwith {true};
if (lifestate (driver _vehicle) == "INCAPACITATED") exitwith {true};
if (_vehicle distance2d (_vehicle getvariable (QGVAR(TargetArrayMovePosition)) select 1) < 8 ) exitwith {true};
//refresh AI from "stuck" or move to updated position

if (_vehicle getvariable QGVAR(DriverWaitTime) < time) then {
_vehicle setvariable [QGVAR(DriverWaitTime),(time + 2)];
if (speed _vehicle < 4) then {
(driver _vehicle) disableAI "Path";
(driver _vehicle) enableAI "Path";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What does this achieve? Does this reset pathfinding?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Trying reset driver mostly in situationn where driver move vehicle super slowly after hitting object or moving super slowly in turning to waypoint

CommandDDOS marked this conversation as resolved.
Show resolved Hide resolved
};
if !(isFormationLeader (driver _vehicle)) then {
(driver _vehicle) doFollow leader (driver _vehicle);
dostop (driver _vehicle);
};
(driver _vehicle) domove ( _vehicle getvariable QGVAR(TargetArrayMovePosition) select 1);
_vehicle setDriveOnPath ( _vehicle getvariable QGVAR(TargetArrayMovePosition));
false;
}
},{
//code when true
params ["_vehicle"];

//fixing driver behaviour where he can ignore all move orders if vehicle don't achive setDriveOnPath destinations before doFollow.
private _point1 = _vehicle getrelpos [2,0];
private _point2 = _vehicle getrelpos [3,0];
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please review your whole code for such cases, there's plenty of them. Please stick to camelCase/the same casing as on Biki.

Suggested change
private _point1 = _vehicle getrelpos [2,0];
private _point2 = _vehicle getrelpos [3,0];
private _point1 = _vehicle getRelPos [2,0];
private _point2 = _vehicle getRelPos [3,0];

_vehicle setDriveOnPath [_point1,_point2];

[{
params ["_vehicle"];
(driver _vehicle) doFollow (leader (driver _vehicle));
(driver _vehicle) domove (getposATL _vehicle);
(driver _vehicle) enableAI "all";
(driver _vehicle) setVariable ["lambs_danger_disableAI", false];
(group (driver _vehicle)) setVariable ["lambs_danger_disablegroupAI", false];
_vehicle setvariable [QGVAR(ActiveVehicleMove),false];
},[_vehicle],0.2] call cba_fnc_waitAndExecute;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please keep a space after ,. Also multiple occurrences.

Suggested change
_vehicle setvariable [QGVAR(ActiveVehicleMove),false];
},[_vehicle],0.2] call cba_fnc_waitAndExecute;
_vehicle setvariable [QGVAR(ActiveVehicleMove), false];
}, [_vehicle], 0.2] call cba_fnc_waitAndExecute;

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see veteran spared his time writing such comments and will have you fix all the issues that will be automatically reported by updated HEMTT. 🤣


},[_LeaderVehicle,_group]
] call CBA_fnc_waitUntilAndExecute;
};

waitUntil {sleep 0.4; !(_LeaderVehicle getvariable [QGVAR(ActiveVehicleMove),false])};
3Mydlo3 marked this conversation as resolved.
Show resolved Hide resolved

// end
true
1 change: 1 addition & 0 deletions addons/waypoint/functions/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
#include "\z\afmf\addons\waypoint\script_component.hpp"
15 changes: 15 additions & 0 deletions addons/waypoint/script_component.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
#define COMPONENT waypoint
Copy link
Member

@3Mydlo3 3Mydlo3 Sep 12, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Personally I think plural would be more in-place for component concerning (possibly) multiple waypoints.

Suggested change
#define COMPONENT waypoint
#define COMPONENT waypoints

Keep in mind renaming folder.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I agree, do not forget to change pboprefix and folder names too.

#include "\z\afmf\addons\main\script_mod.hpp"

// #define DEBUG_MODE_FULL
// #define DISABLE_COMPILE_CACHE

#ifdef DEBUG_ENABLED_WAYPOINT
#define DEBUG_MODE_FULL
#endif
#ifdef DEBUG_ENABLED_WAYPOINT
#define DEBUG_SETTINGS DEBUG_SETTINGS_DEBUG_ENABLED_WAYPOINT
#endif

#include "\z\afmf\addons\main\script_macros.hpp"

13 changes: 13 additions & 0 deletions addons/waypoint/stringtable.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="AFMF">
<Package name="Waypoint">
<Key ID="STR_AFMF_Waypoint_Vehicle_Move_Name">
<English>Direct Vehicle Move</English>
<Polish>Bezpośredni ruch pojazdu</Polish>
</Key>
<Key ID="STR_AFMF_Waypoint_Vehicle_Move_Description">
<English>Direct Vehicle Move. Waypoint create new groups for all drivers in original group and assign new waypoint for them. Waypoint is complete after reaching destination or after losing life by driver</English>
<Polish>Bezpośredni ruch pojazdu. Waypoint tworzy nowe grupy na każdego kierowce który znajduję się w grupie i przypisuje im również waypoint. Zalicza się po dotarciu lub straceniu życia przez kierowce</Polish>
</Key>
</Package>
</Project>
Loading