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] - Improve ceasefire side relations #101

Merged
merged 16 commits into from
Apr 13, 2022
Merged
55 changes: 55 additions & 0 deletions components/ceasefire/fn_ceasefire.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -33,13 +33,27 @@ if (!isServer) exitWith {};

// Set up some variables
if (isNil "cafe_ceasefire_server_EH") then {cafe_ceasefire_server_EH = -1};
if (isNil "cafe_ceasefire_server_sideRelations") then {cafe_ceasefire_server_sideRelations = []};
private _ceaseFireStateChanged = (cafe_ceasefire_active != _enabled);

cafe_ceasefire_active = _enabled;
cafe_ceasefire_endTime = [-1, CBA_missionTime + _duration] select (_duration > 0);





// Define some macros
#define MACRO_FNC_ALLSIDERELATIONS(THISSIDE) \
[THISSIDE, [east, THISSIDE getFriend east]], \
[THISSIDE, [resistance, THISSIDE getFriend resistance]], \
[THISSIDE, [west, THISSIDE getFriend west]], \
[THISSIDE, [civilian, THISSIDE getFriend civilian]]





// Relay the ceasefire to all clients (JIP compatible)
[_enabled, cafe_ceasefire_endTime, _justification] remoteExecCall ["f_fnc_client_ceasefire", 0, "cafe_ceasefire"];
publicVariable "cafe_ceasefire_active";
Expand All @@ -48,6 +62,41 @@ publicVariable "cafe_ceasefire_active";



if (_ceaseFireStateChanged) then {

// Enforce the ceasefire via side relations
if (_enabled) then {

cafe_ceasefire_server_sideRelations = [
MACRO_FNC_ALLSIDERELATIONS(east),
MACRO_FNC_ALLSIDERELATIONS(resistance),
MACRO_FNC_ALLSIDERELATIONS(west),
MACRO_FNC_ALLSIDERELATIONS(civilian)
];

private _allSides = [east, resistance, west, civilian];
private "_sideX";
{
_sideX = _x;
{
_sideX setFriend [_x, 1];
} forEach _allSides;
} forEach _allSides;

// Otherwise, restore the previous side relations
} else {

{
_x params ["_side", "_state"];
_side setFriend _state;
} forEach cafe_ceasefire_server_sideRelations;
};
};





// Keep track of the countdown
removeMissionEventHandler ["EachFrame", cafe_ceasefire_server_EH];

Expand All @@ -62,6 +111,12 @@ if (_duration > 0) then {
cafe_ceasefire_server_EH = -1;
cafe_ceasefire_active = false;

// Restore the previous side relations
{
_x params ["_side", "_state"];
_side setFriend _state;
} forEach cafe_ceasefire_server_sideRelations;

[false] remoteExecCall ["f_fnc_client_ceasefire", 0, "cafe_ceasefire"];
publicVariable "cafe_ceasefire_active";
};
Expand Down