diff options
| author | hybrid <hybrid@hybridlabs.pro> | 2026-06-11 19:55:24 +0300 |
|---|---|---|
| committer | hybrid <hybrid@hybridlabs.pro> | 2026-06-11 19:55:24 +0300 |
| commit | 628d33984d9228f1781d13a65fbb80f35facc899 (patch) | |
| tree | cd909141f87e14f22c3511549a9bc067d9ff8b50 /Server/Init/Init_Towns.sqf | |
| download | a2wf_sara-628d33984d9228f1781d13a65fbb80f35facc899.tar.gz a2wf_sara-628d33984d9228f1781d13a65fbb80f35facc899.tar.bz2 a2wf_sara-628d33984d9228f1781d13a65fbb80f35facc899.zip | |
init
Diffstat (limited to '')
| -rw-r--r-- | Server/Init/Init_Towns.sqf | 214 |
1 files changed, 214 insertions, 0 deletions
diff --git a/Server/Init/Init_Towns.sqf b/Server/Init/Init_Towns.sqf new file mode 100644 index 0000000..98e6995 --- /dev/null +++ b/Server/Init/Init_Towns.sqf @@ -0,0 +1,214 @@ +private ['_half','_wStart','_eStart','_nearTownsW','_nearTownsE','_near','_x','_camps','_total','_limit','_defenses','_require',
+'_initied','_towns','_town','_boundaries','_minus','_total','_z'];
+
+waitUntil {townInit};
+
+//--- Special Towns mode.
+switch ('WFBE_TOWNSTARTINGMODE' Call GetNamespace) do {
+ //--- 50-50.
+ case 1: {
+ _half = round ((count towns) / 2 );
+ _wStart = westStartingLocation;
+ _eStart = eastStartingLocation;
+
+ _nearTownsW = [];
+ _nearTownsE = [];
+
+ _near = [_wStart,towns] Call SortByDistance;
+ if (count _near > 0) then {
+ for [{_z = 0},{_z < _half},{_z = _z + 1}] do {_nearTownsW = _nearTownsW + [_near select _z]};
+ };
+
+ _nearTownsE = (towns - _nearTownsW);
+
+ {
+ _x setVariable ['sideID',WESTID,true];
+ _camps = _x getVariable "camps";
+ {_x setVariable ['sideID',WESTID,true]} forEach _camps;
+ } forEach _nearTownsW;
+ {
+ _x setVariable ['sideID',EASTID,true];
+ _camps = _x getVariable "camps";
+ {_x setVariable ['sideID',EASTID,true]} forEach _camps;
+ } forEach _nearTownsE;
+ };
+
+ //--- Nearby Towns.
+ case 2: {
+ _total = count towns;
+ _wStart = westStartingLocation;
+ _eStart = eastStartingLocation;
+ _limit = floor(_total / 6);
+ _nearTownsW = [];
+ _nearTownsE = [];
+
+ _near = [_wStart,towns] Call SortByDistance;
+ if (count _near > 0) then {
+ for [{_z = 0},{_z < _limit},{_z = _z + 1}] do {_nearTownsW = _nearTownsW + [_near select _z]};
+ };
+
+ _near = [_eStart,(towns - _nearTownsW)] Call SortByDistance;
+ if (count _near > 0) then {
+ for [{_z = 0},{_z < _limit},{_z = _z + 1}] do {_nearTownsE = _nearTownsE + [_near select _z]};
+ };
+
+ {
+ _x setVariable ['sideID',WESTID,true];
+ _camps = _x getVariable "camps";
+ {_x setVariable ['sideID',WESTID,true]} forEach _camps;
+ _defenses = _x nearEntities['WFBE_RESISTANCEDEFENSENAMES' Call GetNamespace,_x getVariable "range"];
+ {deleteVehicle _x} forEach _defenses;
+ } forEach _nearTownsW;
+ {
+ _x setVariable ['sideID',EASTID,true];
+ _camps = _x getVariable "camps";
+ {_x setVariable ['sideID',EASTID,true]} forEach _camps;
+ _defenses = _x nearEntities['WFBE_RESISTANCEDEFENSENAMES' Call GetNamespace,_x getVariable "range"];
+ {deleteVehicle _x} forEach _defenses;
+ } forEach _nearTownsE;
+ };
+
+ //--- Random Towns (25% East, 25% West, 50% Res).
+ case 3: {
+ _total = count towns;
+ _half = round(count towns)/4;
+ _minus = round(count towns)/2;
+ _boundaries = 'WFBE_BOUNDARIESXY' Call GetNamespace;
+ _nearTownsW = [];
+ _resTowns = [];
+ _towns = +towns;
+
+ //--- Use boundaries to determinate the center if possible.
+ if !(isNil '_boundaries') then {
+ Private ["_dis1","_dis2","_e","_posF1","_posF2","_posx","_posy","_searchArea","_size"];
+ //--- Attempt to set the center of the island resistance.
+ _searchArea = [(_boundaries / 2)-0.1,(_boundaries / 2)+0.1,0];
+ _posx = _searchArea select 0;
+ _posy = _searchArea select 0;
+ _size = _boundaries/5;
+ _e = sqrt((_size)^2 - (_size)^2);
+ _posF1 = [_posx + (sin (90) * _e),_posy + (cos (90) * _e)];
+ _posF2 = [_posx - (sin (90) * _e),_posy - (cos (90) * _e)];
+ _total = 2 * _size;
+
+ //--- Determinate resistance towns.
+ {
+ _position = getPos _x;
+
+ _dis1 = _position distance _posF1;
+ _dis2 = _position distance _posF2;
+ if (_dis1+_dis2 < _total) then {
+ _resTowns = _resTowns + [_x];
+ };
+
+ if (count _resTowns >= _minus) exitWith {};
+ } forEach towns;
+
+ //--- Update Towns.
+ _towns = _towns - _resTowns;
+ _e = count _towns;
+
+ //--- Check if we couldn't reach 50% Res.
+ if (count _resTowns < _minus) then {
+ for '_z' from 0 to _e-1 do {
+ _town = _towns select round(random((count _towns)-1));
+ _towns = _towns - [_town];
+
+ _resTowns = _resTowns + [_town];
+
+ if (count _resTowns >= _minus) exitWith {};
+ };
+ };
+
+ //--- Update Towns Again.
+ _towns = _towns - _resTowns;
+ _e = count _towns;
+
+ //--- Assign west or east towns.
+ for '_z' from 0 to totalTowns-_minus-1 do {
+ _town = _towns select round(random((count _towns)-1));
+ _towns = _towns - [_town];
+ if (count _nearTownsW < _half) then {
+ _nearTownsW = _nearTownsW + [_town];
+ _town setVariable ['sideID',WESTID,true];
+ _camps = _town getVariable "camps";
+ {_x setVariable ['sideID',WESTID,true]} forEach _camps;
+ _defenses = _town nearEntities['WFBE_RESISTANCEDEFENSENAMES' Call GetNamespace,_town getVariable "range"];
+ {deleteVehicle _x} forEach _defenses;
+ } else {
+ _town setVariable ['sideID',EASTID,true];
+ _camps = _town getVariable "camps";
+ {_x setVariable ['sideID',EASTID,true]} forEach _camps;
+ _defenses = _town nearEntities['WFBE_RESISTANCEDEFENSENAMES' Call GetNamespace,_town getVariable "range"];
+ {deleteVehicle _x} forEach _defenses;
+ };
+ };
+ } else {
+ //--- No boundaries defined, we use a random system.
+ for '_z' from 0 to _minus-1 do {
+ _town = _towns select round(random((count _towns)-1));
+ _towns = _towns - [_town];
+ if (count _nearTownsW < _half) then {
+ _nearTownsW = _nearTownsW + [_town];
+ _town setVariable ['sideID',WESTID,true];
+ _camps = _town getVariable "camps";
+ {_x setVariable ['sideID',WESTID,true]} forEach _camps;
+ _defenses = _town nearEntities['WFBE_RESISTANCEDEFENSENAMES' Call GetNamespace,_town getVariable "range"];
+ {deleteVehicle _x} forEach _defenses;
+ } else {
+ _town setVariable ['sideID',EASTID,true];
+ _camps = _town getVariable "camps";
+ {_x setVariable ['sideID',EASTID,true]} forEach _camps;
+ _defenses = _town nearEntities['WFBE_RESISTANCEDEFENSENAMES' Call GetNamespace,_town getVariable "range"];
+ {deleteVehicle _x} forEach _defenses;
+ };
+ };
+ };
+
+
+ };
+};
+
+//--- Resistance Patrols.
+if (('WFBE_TOWNSTARTINGMODE' Call GetNamespace) != 1 && ('WFBE_RESPATROL' Call GetNamespace > 0)) then {
+ _require = if (('WFBE_RESPATROL' Call GetNamespace) > count towns) then {count towns} else {'WFBE_RESPATROL' Call GetNamespace};
+ _initied = 0;
+ _towns = towns;
+
+ //--- Don't bother with the randomizer if the amount set in RESPATROLMAX is >= count towns.
+ while {_initied < _require} do {
+ if (_require == count towns) then {
+ [_towns select _initied] ExecFSM "Server\FSM\respatrol.fsm";
+ _initied = _initied + 1;
+ } else {
+ if (random 2 > 1) then {
+ _town = [_towns select (round(random((count _towns)-1)))] ExecFSM "Server\FSM\respatrol.fsm";
+ _towns = _towns - [_town];
+ _initied = _initied + 1;
+ };
+ };
+ };
+};
+
+//--- Resistance Strikers.
+if (('WFBE_TOWNSTARTINGMODE' Call GetNamespace) != 1 && ('WFBE_RESSTRIKER' Call GetNamespace) > 0) then {
+ _require = if (('WFBE_RESSTRIKER' Call GetNamespace) > count towns) then {count towns} else {'WFBE_RESSTRIKER' Call GetNamespace};
+ _initied = 0;
+ _towns = towns;
+
+ //--- Don't bother with the randomizer if the amount set in RESSTRIKERMAX is >= count towns.
+ while {_initied < _require} do {
+ if (_require == count towns) then {
+ [_towns select _initied] ExecFSM "Server\FSM\resstriker.fsm";
+ _initied = _initied + 1;
+ } else {
+ if (random 2 > 1) then {
+ _town = [_towns select (round(random((count _towns)-1)))] ExecFSM "Server\FSM\resstriker.fsm";
+ _towns = _towns - [_town];
+ _initied = _initied + 1;
+ };
+ };
+ };
+};
+
+diag_log Format["[WFBE (INIT)][frameno:%1 | ticktime:%2] Init_Towns (Server): Towns starting mode initialization - [Done]",diag_frameno,diag_tickTime];
\ No newline at end of file |
