summaryrefslogtreecommitdiffstats
path: root/Server/Init/Init_Towns.sqf
blob: 98e69952e939b97e05324378f1497154af78fe86 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
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];