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

Feature/ambient vehicles #407

Merged
merged 9 commits into from
Dec 19, 2021
Merged
Show file tree
Hide file tree
Changes from 7 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 addons/ambient/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
x\tmf\addons\ambient
3 changes: 3 additions & 0 deletions addons/ambient/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@

XEH_PRESTART;
XEH_PREINIT;
22 changes: 22 additions & 0 deletions addons/ambient/CfgModules.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
class CfgVehicles {
class Logic;
class Module_F: Logic {
class AttributesBase {
class Default;
class Edit;
class Combo;
class Checkbox;
class CheckboxNumber;
class ModuleDescription;
class Units;
};
class ArgumentsBaseUnits {
class Units;
};
class ModuleDescription {
class AnyBrain;
};
class EventHandlers;
};
#include "modules\ambientVehicles.hpp"
};
2 changes: 2 additions & 0 deletions addons/ambient/XEH_PREP.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
PREP(createAmbientVehicles);
PREP(ambientVehicleInit);
3 changes: 3 additions & 0 deletions addons/ambient/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.sqf"
3 changes: 3 additions & 0 deletions addons/ambient/XEH_preStart.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
#include "script_component.hpp"

#include "XEH_PREP.sqf"
24 changes: 24 additions & 0 deletions addons/ambient/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
#include "script_component.hpp"

class CfgPatches
{
class ADDON
{
name = "TMF: Ambient";
author = "TMF Team";
url = "http://www.teamonetactical.com";
units[] = {
QGVAR(ambientVehicles)
};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {
"tmf_common",
"tmf_ai"
};
VERSION_CONFIG;
};
};

#include "CfgEventHandlers.hpp"
#include "CfgModules.hpp"
122 changes: 122 additions & 0 deletions addons/ambient/functions/fnc_ambientVehicleInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,122 @@
#include "../script_component.hpp"
/* ----------------------------------------------------------------------------
Internal Function: TMF_ambient_fnc_ambientVehicleInit

Description:
Initializes the Ambient Vehicles module,
wrapper for the createAmbienVehicles function.

Parameters:
Standard module parameters

Returns:
Nothing

Author:
Freddo
---------------------------------------------------------------------------- */

if !isServer exitWith {};

params ["_mode", "_input"];
TRACE_2("Initializing Ambient Vehicles module",_mode,_input);
_input params ["_logic"];

private _code = _logic getVariable [QGVAR(code), ""];
private _lockedRate = _logic getVariable [QGVAR(lockedRate), 0];
private _spacing = _logic getVariable [QGVAR(spacing), 2];
private _vehicleNumber = _logic getVariable [QGVAR(vehicleNumber), 5];
private _emptyCargo = _logic getVariable [QGVAR(emptyCargo), false];

Freddo3000 marked this conversation as resolved.
Show resolved Hide resolved
private _syncedObjects = [];
if is3DEN then {
private _connections = (get3DENConnections _logic) select {(_x # 0) isEqualTo "Sync"};
_syncedObjects = _connections apply {_x # 1};
} else {
_syncedObjects = synchronizedObjects _logic;
};

private _area = (_syncedObjects select {_x isKindOf QEGVAR(ai,area)}) param [0, objNull];
private _syncedVehicles = _syncedObjects select {_x isKindOf "LandVehicle" && !(_x isKindOf "CAManBase")};
private _vehicleTypes = _syncedVehicles apply {typeOf _x};

if (isNull _area) exitWith {
if (_mode == "init") then {
ERROR_MSG("No area module synchronized to Ambient Vehicles module: %1",_logic);
};
};

if (_vehicleTypes isEqualTo []) exitWith {
if (_mode == "init") then {
ERROR_MSG("No vehicles synchronized to Ambient Vehicles module: %1",_logic);
};
};

// Parse area into an accepted format
if (is3DEN) then {
_area = [
getPos _area,

((_area get3DENAttribute "size2") # 0) +
[direction _area,
(_area get3DENAttribute "IsRectangle") # 0]

] call BIS_fnc_getArea;
} else {
_area = [getPos _area,_area getVariable "objectarea"] call BIS_fnc_getArea;
};

switch _mode do {
// Default object init
case "init": {
_input params ["", "_isActivated", "_isCuratorPlaced"];

{deleteVehicle _x} forEach _syncedVehicles;

if !(_isActivated) exitWith {};

private _vehicles = [_area, _vehicleTypes, _vehicleNumber, _spacing] call FUNC(createAmbientVehicles);

{
if (_emptyCargo) then {
clearWeaponCargoGlobal _x;
clearMagazineCargoGlobal _x;
clearItemCargoGlobal _x;
clearBackpackCargoGlobal _x;
};

if (random 1 < _lockedRate) then {
_x setVehicleLock "LOCKED";
["init",_x] call bis_fnc_carAlarm;
};

_x call _code;

} forEach _vehicles;

_logic setVariable ["spawnedVehicles", _vehicles, true];
};

// When some attributes were changed (including position and rotation)
case "attributesChanged3DEN";
// When connection to object changes (i.e., new one is added or existing one removed)
case "connectionChanged3DEN": {
{
deleteVehicle _x;
} forEach (_logic getVariable ["spawnedVehicles", []]);

private _vehicles = [_area, _vehicleTypes, _vehicleNumber, _spacing] call FUNC(createAmbientVehicles);
{_x call _code;} forEach _vehicles;

_logic setVariable ["spawnedVehicles", _vehicles, true];
};

// When removed from the world (i.e., by deletion or undoing creation)
case "unregisteredFromWorld3DEN": {
{
deleteVehicle _x;
} forEach (_logic getVariable ["spawnedVehicles", []]);
};
};

nil
Loading