forked from Bob-Murphy/A3-Antistasi-1.4
-
-
Notifications
You must be signed in to change notification settings - Fork 156
/
fn_initSpawnPlaces.sqf
208 lines (186 loc) · 7.05 KB
/
fn_initSpawnPlaces.sqf
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
#include "..\..\script_component.hpp"
FIX_LINE_NUMBERS()
#define SPACING 1
params ["_marker", "_placementMarker"];
private ["_vehicleMarker", "_heliMarker", "_hangarMarker", "_mortarMarker", "_markerPrefix", "_markerSplit", "_first", "_fullName"];
_vehicleMarker = [];
_heliMarker = [];
_hangarMarker = [];
_mortarMarker = [];
//Calculating marker prefix
_markerPrefix = "";
_markerSplit = _marker splitString "_";
switch (_markerSplit select 0) do
{
case ("airport"): {_markerPrefix = "airp_";};
case ("outpost"): {_markerPrefix = "outp_";};
case ("resource"): {_markerPrefix = "reso_";};
case ("factory"): {_markerPrefix = "fact_";};
case ("seaport"): {_markerPrefix = "seap_";};
};
if(count _markerSplit > 1) then
{
_markerPrefix = format ["%1%2_", _markerPrefix, _markerSplit select 1];
};
//Sort marker
_mainMarker = getMarkerPos _marker;
{
_first = (_x splitString "_") select 0;
_fullName = format ["%1%2", _markerPrefix, _x];
if(_mainMarker distance (getMarkerPos _fullName) > 500) then
{
Error_2("Placementmarker %1 is more than 500 meter away from its mainMarker %2. You may want to check that!", _fullName, _marker);
};
switch (_first) do
{
case ("vehicle"): {_vehicleMarker pushBack _fullName;};
case ("helipad"): {_heliMarker pushBack _fullName;};
case ("hangar"): {_hangarMarker pushBack _fullName;};
case ("mortar"): {_mortarMarker pushBack _fullName;};
};
_fullName setMarkerAlpha 0;
} forEach _placementMarker;
if(count _vehicleMarker == 0) then
{
Error_1("InitSpawnPlaces: Could not find any vehicle places on %1!", _marker);
};
private ["_markerSize", "_distance", "_buildings", "_hangars", "_helipads", "_markerX"];
_markerSize = markerSize _marker;
_distance = sqrt ((_markerSize select 0) * (_markerSize select 0) + (_markerSize select 1) * (_markerSize select 1));
_buildings = nearestObjects [getMarkerPos _marker, ["Helipad_Base_F", "Land_Hangar_F", "Land_TentHangar_V1_F", "Land_Airport_01_hangar_F", "Land_Mil_hangar_EP1", "Land_Ss_hangar", "Land_Ss_hangard", "Land_vn_helipad_base", "Land_vn_airport_01_hangar_f", "Land_vn_usaf_hangar_01", "Land_vn_usaf_hangar_02", "Land_vn_usaf_hangar_03"], _distance, true];
_hangars = [];
_helipads = [];
{
if((getPos _x) inArea _marker) then
{
if((_x isKindOf "Helipad_Base_F") or (_x isKindOf "Land_vn_helipad_base")) then
{
_helipads pushBack _x;
}
else
{
_hangars pushBack _x;
};
};
} forEach _buildings;
//Find additional helipads and hangars (maybe a unified system would be better??)
{
_markerX = _x;
_markerSize = markerSize _x;
_distance = sqrt ((_markerSize select 0) * (_markerSize select 0) + (_markerSize select 1) * (_markerSize select 1));
_buildings = nearestObjects [getMarkerPos _x, ["Helipad_Base_F", "Land_vn_helipad_base"], _distance, true];
{
if((getPos _x) inArea _markerX) then
{
_helipads pushBackUnique _x;
};
} forEach _buildings;
} forEach _heliMarker;
{
_markerX = _x;
_markerSize = markerSize _x;
_distance = sqrt ((_markerSize select 0) * (_markerSize select 0) + (_markerSize select 1) * (_markerSize select 1));
_buildings = nearestObjects [getMarkerPos _x, ["Land_Hangar_F", "Land_TentHangar_V1_F", "Land_Airport_01_hangar_F", "Land_Mil_hangar_EP1", "Land_Ss_hangar", "Land_Ss_hangard", "Land_vn_airport_01_hangar_f", "Land_vn_usaf_hangar_01", "Land_vn_usaf_hangar_02", "Land_vn_usaf_hangar_03"], _distance, true];
{
if((getPos _x) inArea _markerX) then
{
_hangars pushBackUnique _x;
};
} forEach _buildings;
} forEach _hangarMarker;
//All additional hangar and helipads found
private ["_vehicleSpawns", "_size", "_length", "_width", "_vehicleCount", "_realLength", "_realSpace", "_markerDir", "_dis", "_pos", "_heliSpawns", "_dir", "_planeSpawns", "_mortarSpawns", "_spawns"];
_vehicleSpawns = [];
{
_markerX = _x;
_size = getMarkerSize _x;
_length = (_size select 0) * 2;
_width = (_size select 1) * 2;
if(_length < (4 + 2 * SPACING)) then
{
Error_2("InitSpawnPlaces: Marker %1 is not wide enough for vehicles, required are %2 meters!", _x , (4 + 2 * SPACING));
}
else
{
if(_width < 10) then
{
Error_1("InitSpawnPlaces: Marker %1 is not long enough for vehicles, required are 10 meters!", _x);
}
else
{
//Cleaning area
private _radius = [0,0] vectorDistance [_length, _width];
if (!isMultiplayer) then
{
{
if((getPos _x) inArea _markerX) then
{
_x hideObject true;
};
} foreach (nearestTerrainObjects [getMarkerPos _markerX, ["Tree","Bush", "Hide", "Rock", "Fence"], _radius, true]);
}
else
{
{
if((getPos _x) inArea _markerX) then
{
[_x,true] remoteExec ["hideObjectGlobal",2];
}
} foreach (nearestTerrainObjects [getMarkerPos _markerX, ["Tree","Bush", "Hide", "Rock", "Fence"], _radius, true]);
};
//Create the places
_vehicleCount = floor ((_length - SPACING) / (4 + SPACING));
_realLength = _vehicleCount * 4;
_realSpace = (_length - _realLength) / (_vehicleCount + 1);
_markerDir = markerDir _markerX;
for "_i" from 1 to _vehicleCount do
{
_dis = (_realSpace + 2 + ((_i - 1) * (4 + _realSpace))) - (_length / 2);
_pos = [getMarkerPos _markerX, _dis, (_markerDir + 90)] call BIS_fnc_relPos;
_pos set [2, ((_pos select 2) + 0.1) max 0.1];
_vehicleSpawns pushBack [[_pos, _markerDir], false];
};
};
};
} forEach _vehicleMarker;
_heliSpawns = [];
{
_pos = getPos _x;
_pos set [2, 0.4];
if (!isMultiplayer) then
{
{
_x hideObject true;
} foreach (nearestTerrainObjects [_pos, ["Tree","Bush", "Hide", "Rock"], 5, true]);
}
else
{
{
[_x,true] remoteExec ["hideObjectGlobal",2];
} foreach (nearestTerrainObjects [_pos, ["Tree","Bush", "Hide", "Rock"], 5, true]);
};
_dir = direction _x;
_heliSpawns pushBack [[_pos, _dir], false];
} forEach _helipads;
_planeSpawns = [];
{
_pos = getPos _x;
_pos set [2, ((_pos select 2) + 0.1) max 0.1];
_dir = direction _x;
if(_x isKindOf "Land_Hangar_F" || {_x isKindOf "Land_Airport_01_hangar_F" || {_x isKindOf "Land_Mil_hangar_EP1" || {_x isKindOf "Land_Ss_hangar" || {_x isKindOf "Land_Ss_hangard" || {_x isKindOf "Land_vn_airport_01_hangar_f" || {_x isKindOf "Land_vn_usaf_hangar_01" || {_x isKindOf "Land_vn_usaf_hangar_02" || {_x isKindOf "Land_vn_usaf_hangar_03"}}}}}}}}) then
{
//This hangar is facing the wrong way...
_dir = _dir + 180;
};
_planeSpawns pushBack [[_pos, _dir], false];
} forEach _hangars;
_mortarSpawns = [];
{
_pos = getMarkerPos _x;
_pos set [2, ((_pos select 2) + 0.1) max 0.1];
_mortarSpawns pushBack [[_pos, 0], false];
} forEach _mortarMarker;
_spawns = [_vehicleSpawns, _heliSpawns, _planeSpawns, _mortarSpawns];
//Debug_2("%1 set to %2", _marker, _spawns);
//Saving the spawn places
spawner setVariable [format ["%1_spawns", _marker], _spawns, true];