Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/master' into feature/clear-empty…
Browse files Browse the repository at this point in the history
…-vehicles-on-spawn
  • Loading branch information
3Mydlo3 committed Feb 15, 2024
2 parents 9ea10d6 + 81b7105 commit b49718c
Show file tree
Hide file tree
Showing 30 changed files with 475 additions and 39 deletions.
2 changes: 0 additions & 2 deletions addons/civilian/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ PREP(civilianKilled);
PREP(civilianKilledMarker);
PREP(civilianKilledMsg);
PREP(createCivilian);
PREP(createVehicle);
PREP(getCityByLocation);
PREP(getCityName);
PREP(getCityRandomPos);
Expand All @@ -12,6 +11,5 @@ PREP(getNearestVehicle);
PREP(initCity);
PREP(initCivilians);
PREP(initCiviliansConfig);
PREP(initVehicles);
PREP(initCivilian);
PREP(unassignCivilianFromCity);
5 changes: 0 additions & 5 deletions addons/civilian/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,6 @@ if (isServer) then {
_x setVariable [QGVAR(CiviliansCount), _civiliansCount];
_x setVariable [QGVAR(initialCiviliansCount), _civiliansCount];
} forEach GVAR(cities);


// We need some improvements in determining civilian vehicles limit
GVAR(emptyVehiclesLimit) = GVAR(emptyVehiclesLimitMultiplier) * (5 * count (GVAR(cities)));
call FUNC(initVehicles);
};

ADDON = true;
3 changes: 2 additions & 1 deletion addons/civilian/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class CfgPatches {
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {
"afsk_common"
"afsk_common",
"afsk_vehicles"
};
author = "ArmaForces";
VERSION_CONFIG;
Expand Down
4 changes: 2 additions & 2 deletions addons/civilian/functions/fnc_initCity.sqf
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function initializes given city with module, civilians and vehicles.
* Function initializes given city with module and civilians.
*
* Arguments:
* 0: City to initialize <CONFIG/LOCATION>
Expand Down Expand Up @@ -43,5 +43,5 @@ _cityNamespace setVariable [QGVAR(CiviliansList), []];
_cityNamespace setVariable [QGVAR(CiviliansCount), 0];
_cityNamespace setVariable [QGVAR(initialCiviliansCount), 0];

// Init vehicles
// Return
_cityNamespace
11 changes: 0 additions & 11 deletions addons/civilian/initSettings.inc.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,3 @@
[0, 400, 200, 0],
true
] call CBA_fnc_addSetting;

[
QGVAR(emptyVehiclesLimitMultiplier),
"LIST",
[LSTRING(EmptyVehiclesLimit), LSTRING(EmptyVehiclesLimit_Description)],
[LSTRING(DisplayName), localize "str_dn_vehicles"],
[[1, 2, 3], [LSTRING(Low), LSTRING(Medium), LSTRING(High)], 1],
true,
{},
true
] call CBA_fnc_addSetting;
8 changes: 0 additions & 8 deletions addons/civilian/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,6 @@
<English>SerialKillers - Civilian</English>
<Polish>SerialKillers - Cywile</Polish>
</Key>
<Key ID="STR_AFSK_Civilian_EmptyVehiclesLimit">
<English>Civilian vehicles limit</English>
<Polish>Limit pojazdów cywilnych</Polish>
</Key>
<Key ID="STR_AFSK_Civilian_EmptyVehiclesLimit_Description">
<English>Controls how much civilian vehicles will be created on the whole map.</English>
<Polish>Ustala jak dużo pojazdów cywilnych będzie utworzonych na całej mapie.</Polish>
</Key>
<Key ID="STR_AFSK_Civilian_Civilian_Killed_In_City">
<English>Civilian was killed at %1 in %2!</English>
<Polish>Cywil został zabity o godzinie %1 w %2!</Polish>
Expand Down
1 change: 0 additions & 1 deletion addons/common/XEH_PREP.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,4 @@ PREP(isHouseNearby);
PREP(isRoadNearby);
PREP(playMusicServer);
PREP(removeItemsFromArsenal);
PREP(setVehicleRandomTexture);
PREP(showMessage);
4 changes: 1 addition & 3 deletions addons/common/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,7 @@ if (isServer) then {
}] call CBA_fnc_addEventHandler;
};

[QGVAR(showMessage), {
_this call FUNC(showMessage);
}] call CBA_fnc_addEventHandler;
[QGVAR(showMessage), FUNC(showMessage)] call CBA_fnc_addEventHandler;

[QGVAR(teleport), {
params ["_caller", "_destination"];
Expand Down
2 changes: 1 addition & 1 deletion addons/police/functions/fnc_spawnVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -75,4 +75,4 @@ if (_position isEqualTo []) exitWith {

// Spawn vehicle
INFO_2("Creating vehicle %1 at position %2",_vehicleClassname,str _position);
[EFUNC(civilian,createVehicle), [_vehicleClassname, _position, _direction, true, false, true]] call CBA_fnc_execNextFrame;
[EFUNC(vehicles,createVehicle), [_vehicleClassname, _position, _direction, true, false, true]] call CBA_fnc_execNextFrame;
1 change: 1 addition & 0 deletions addons/vehicles/$PBOPREFIX$
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
z\afsk\addons\vehicles
15 changes: 15 additions & 0 deletions addons/vehicles/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preStart));
};
};
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
9 changes: 9 additions & 0 deletions addons/vehicles/CfgSounds.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
class CfgSounds
{
class CarAlarm
{
name = "CarAlarm";
sound[] = {QPATHTOF(assets\sounds\Caralarm.ogg), "db+10", 1.0};
titles[] = {};
};
};
8 changes: 8 additions & 0 deletions addons/vehicles/XEH_PREP.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
PREP(carAlarm);
PREP(carAlarmLoop);
PREP(createVehicle);
PREP(disableCarAlarm);
PREP(initCarAlarm);
PREP(initVehicles);
PREP(setVehicleRandomTexture);
PREP(vehicleStolenMsg);
18 changes: 18 additions & 0 deletions addons/vehicles/XEH_postInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "script_component.hpp"

if (isServer) then {

[QGVAR(carAlarm), FUNC(carAlarm)] call CBA_fnc_addEventHandler;
[QGVAR(disableCarAlarm), FUNC(disableCarAlarm)] call CBA_fnc_addEventHandler;
};

if (hasInterface) then {
[QGVAR(carAlarm), FUNC(carAlarm)] call CBA_fnc_addEventHandler;

[QGVAR(alarmOff), {
params ["_vehicle"];

[QEGVAR(common,showSideChatMsg), [WEST, [_vehicle] call FUNC(vehicleStolenMsg)]] call CBA_fnc_localEvent;
[_vehicle, true, GVAR(alarmDuration)] call FUNC(carAlarmLoop);
}] call CBA_fnc_addEventHandler;
};
14 changes: 14 additions & 0 deletions addons/vehicles/XEH_preInit.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
#include "script_component.hpp"
ADDON = false;
#include "XEH_PREP.hpp"

#include "initSettings.sqf"

// We need some improvements in determining civilian vehicles limit
GVAR(emptyVehiclesLimit) = 500;

if (isServer) then {
call FUNC(initVehicles);
};

ADDON = true;
2 changes: 2 additions & 0 deletions addons/vehicles/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"
Binary file added addons/vehicles/assets/sounds/CarAlarm.ogg
Binary file not shown.
18 changes: 18 additions & 0 deletions addons/vehicles/config.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#include "script_component.hpp"

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

#include "CfgEventHandlers.hpp"
#include "CfgSounds.hpp"
44 changes: 44 additions & 0 deletions addons/vehicles/functions/fnc_carAlarm.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function triggers car alarm on given vehicle.
*
* Arguments:
* 0: Vehicle which has alarm going off <OBJECT>
*
* Return Value:
* True if alarm has gone off <BOOL>
*
* Example:
* None
*
* Public: No
*/

params ["_vehicle"];

// Prevent triggering when triggered already
if (_vehicle getVariable [QGVAR(alarmOn), false]) exitWith { false };

// Prevent triggering multiple times or if unarmed
if (!GVAR(alarmAlwaysArmed) && {
(_vehicle getVariable [QGVAR(hasGoneOff), false] || {
!(_vehicle getVariable [QGVAR(alarmArmed), false])}
)
}) exitWith { false };

// Random chance that alarm will go off
if (_vehicle getVariable [QGVAR(offChance), 1] < random 1) exitWith {
if (GVAR(alarmDisarmIfFailed)) then {
_vehicle setVariable [QGVAR(alarmArmed), false];
};

false
};

_vehicle setVariable [QGVAR(alarmOn), true];
_vehicle setVariable [QGVAR(hasGoneOff), true];

[QGVAR(alarmOff), [_vehicle]] call CBA_fnc_globalEvent;

true
44 changes: 44 additions & 0 deletions addons/vehicles/functions/fnc_carAlarmLoop.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function triggers car alarm on given vehicle.
*
* Arguments:
* 0: Vehicle which has alarm turned on <OBJECT>
*
* Return Value:
* None
*
* Example:
* None
*
* Public: No
*/

#define ALARM_INTERVAL 0.5
#define ALARM_LENGTH 10
#define MAX_DISTANCE GVAR(alarmAudibleDistance)
#define DEFAULT_PITCH 1
#define SOUND_WITHOUT_MUFFLING 2

params ["_vehicle", "_lightsOn", "_remainingDuration", ["_currentSoundDuration", 999]];

_vehicle setPilotLight _lightsOn;
if (_currentSoundDuration > ALARM_LENGTH) then {
_vehicle say3D ["CarAlarm", MAX_DISTANCE, DEFAULT_PITCH, SOUND_WITHOUT_MUFFLING];
_currentSoundDuration = ALARM_INTERVAL;
} else {
_currentSoundDuration = _currentSoundDuration + ALARM_INTERVAL;
};

_remainingDuration = _remainingDuration - 1;

// player sideChat format ["Remaining alarm: %1", _remainingDuration];

if (_remainingDuration < 1 || {!alive _vehicle}) exitWith {
// player sideChat "Ending alarm";
_vehicle setVariable [QGVAR(alarmOn), false, true];
_vehicle setPilotLight false;
};

[FUNC(carAlarmLoop), [_vehicle, !_lightsOn, _remainingDuration, _currentSoundDuration], ALARM_INTERVAL] call CBA_fnc_waitAndExecute;
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
* 0: Created vehicle <OBJECT>
*
* Example:
* ["C_Offroad_01_F", position player] call afsk_civilian_fnc_createVehicle
* ["C_Offroad_01_F", position player] call afsk_vehicles_fnc_createVehicle
*
* Public: No
*/
Expand All @@ -34,7 +34,7 @@ _vehicle setDir _dir;
// Disable randomization and use own function to set texture on vehicle globally (so everyone can see the same color!)
_vehicle setVariable ["BIS_enableRandomization", false];
if (_enableRandomization) then {
[_vehicle] call EFUNC(common,setVehicleRandomTexture);
[_vehicle] call FUNC(setVehicleRandomTexture);
};

if (_emptyCargo) then {
Expand Down
33 changes: 33 additions & 0 deletions addons/vehicles/functions/fnc_disableCarAlarm.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function disables car alarm on given vehicle.
*
* Arguments:
* 0: Vehicle which has alarm armed <OBJECT>
*
* Return Value:
* True if alarm is disabled <BOOL>
*
* Example:
* None
*
* Public: No
*/

params ["_vehicle"];

if (!isServer) exitWith {
[QGVAR(disableCarAlarm), [_vehicle]] call CBA_fnc_serverEvent;
false
};

_vehicle setVariable [QGVAR(alarmArmed), false];

// Remove EH so it doesn't fire unnecessarily
private _ehId = _vehicle getVariable [QGVAR(GetInEHID), -1];
_vehicle removeEventHandler ["GetIn", _ehId];

INFO_1("Disabled alarm in vehicle %1",_vehicle);

true
38 changes: 38 additions & 0 deletions addons/vehicles/functions/fnc_initCarAlarm.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
#include "script_component.hpp"
/*
* Author: 3Mydlo3
* Function initializes car alarm on given vehicle.
*
* Arguments:
* 0: Vehicle which has alarm armed <OBJECT>
* 1: Chance that the alarm will indeed go off <NUMBER>
*
* Return Value:
* True if alarm has been armed <BOOL>
*
* Example:
* None
*
* Public: No
*/

params ["_vehicle", ["_offChance", 1]];

if (_vehicle getVariable [QGVAR(alarmArmed), false]) exitWith { false };

_vehicle setVariable [QGVAR(alarmArmed), true];
_vehicle setVariable [QGVAR(offChance), _offChance];

// Alarm should go off at most once, init a flag to keep that in mind
_vehicle setVariable [QGVAR(hasGoneOff), false];

private _ehId = _vehicle addEventHandler ["GetIn", {
params ["_vehicle", "_role", "_unit", "_turret"];
if (side _unit isEqualTo CIVILIAN) exitWith {};

[QGVAR(carAlarm), [_vehicle]] call CBA_fnc_serverEvent;
}];

_vehicle setVariable [QGVAR(GetInEHID), _ehId];

true
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ private _civilianCarTypes = "( (getNumber (_x >> 'scope') >= 2)
&& {getNumber (_x >> 'side') == 3}
})" configClasses (configFile >> "CfgVehicles");

GVAR(citiesVehicles) = call CBA_fnc_createNamespace;

while {_i > 0} do {
private _carType = selectRandom _civilianCarTypes;
private _pos = [_carType, true, false, true] call EFUNC(common,getRandomPos);
Expand All @@ -39,6 +37,9 @@ while {_i > 0} do {
if (_nearbyCarsCount >= 2 && {(random 1) > 0.1}) exitWith {};
// Create vehicle on given position. We need some way to prevent instant damage to vehicle as these empty positions are not perfect.
private _vehicle = [_carType, _pos] call FUNC(createVehicle);
if (GVAR(alarmEnabled)) then {
[_vehicle, random 1 + GVAR(alarmMinimumChance)] call FUNC(initCarAlarm);
};
_i = _i - 1;
};
};
Loading

0 comments on commit b49718c

Please sign in to comment.