summaryrefslogtreecommitdiffstats
path: root/Server/Missions/M_BASE_Attack/m_init.sqf
blob: d16b9770fe226d0b16050db1e590d0d083fb5944 (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
/* Base Attack Script (Hybrid) */
Private ['_attackAfter','_attempts','_boundariesxy','_cpt','_group','_groups','_grps','_hq','_i','_inRange','_isHQDeployed','_jipHandler','_marker','_markerSize','_near','_pos','_position','_retVal','_runFor','_size','_spawnLocations','_structures','_target','_teamType','_uniqueIndex','_uniqueLabel','_vehicles'];

_uniqueLabel = _this select 0;
_uniqueIndex = _this select 1;
_runFor = _this select 2;

//--- Make sure that at least one building is available.
_structures = (_runFor) Call GetSideStructures;
if (count _structures == 0) exitWith{
	[Format['_WFBE_M_RUNNINGMISSIONS_%1',_runFor],((Format['_WFBE_M_RUNNINGMISSIONS_%1',_runFor]) Call GetNamespace) - 1, true] Call SetNamespace;
};

/* Radio the designated team that a new mission is available */
['NewMissionAvailable','',_runFor] Spawn SideMessage;

//--- Grab the HQ.
_isHQDeployed = (_runFor) Call GetSideHQDeployed;
if (_isHQDeployed) then {
	_hq = (_runFor) Call GetSideHQ;
	if (alive _hq) then {_structures = _structures + [_hq]};
};

//--- Pick a target.
_target = _structures select floor(random (count _structures));

//--- Progressive difficulty.
_grps = 2 + ('WFBE_TOWNRESISTANCEDIFFICULTY' Call GetNamespace);

//--- Create the groups.
_groups = [];
for [{_i = 0},{_i < _grps},{_i = _i + 1}] do {
	_groups = _groups + [createGroup resistance];
};

_markerSize = 700;
_size = _markerSize;

//--- Plan the attack delay.
_attackAfter = (300)+(random 100)-(random 100);

//--- Warn the client.
WFBE_M_BASE_Attack = [_runFor,'CLTFNCM_BASE_ATTACK',[_size/2,_uniqueLabel,_uniqueIndex,_target,_groups]];
publicVariable 'WFBE_M_BASE_Attack';
if (isHostedServer || local player) then {[_runFor,'CLTFNCM_BASE_ATTACK',[_size/2,_uniqueLabel,_uniqueIndex,_target,_groups]] Spawn HandlePVF};
_jipHandler = [_runFor,_size,_uniqueLabel,_uniqueIndex,_target,_groups] Spawn {
	Private ['_groups','_oldPlayerList','_runFor','_size','_target','_uniqueLabel','_uniqueIndex','_update'];
	_runFor = _this select 0;
	_size = (_this select 1)/2;
	_uniqueLabel = _this select 2;
	_uniqueIndex = _this select 3;
	_target = _this select 4;
	_groups = _this select 5;
	
	while {true} do {
		_oldPlayerList = playableUnits;
		sleep 15;
		_update = false;
		{
			if !(_x in _oldPlayerList) then {_update = true};
		} forEach playableUnits;
		
		if (_update) then {
			WFBE_M_BASE_Attack = [_runFor,'CLTFNCM_BASE_ATTACK',[_size,_uniqueLabel,_uniqueIndex,_target,_groups]];
			publicVariable 'WFBE_M_BASE_Attack';
			if (isHostedServer || local player) then {[_runFor,'CLTFNCM_BASE_ATTACK',[_size,_uniqueLabel,_uniqueIndex,_target,_groups]] Spawn HandlePVF};
		};
	};
};

sleep _attackAfter;

//--- Targert died?
if !(alive _target) then {
	//--- Pick another target if possible, else send them to the HQ (DoA).
	_structures = (_runFor) Call GetSideStructures;
	if (count _structures == 0) then {
		_hq = (_runFor) Call GetSideHQ;
		_target = _hq;
	} else {
		_target = _structures select floor(random (count _structures));
	};
};

//--- UPSMON Area Definition.
_marker = "";
if (paramUPSMON) then {
	_marker = Format['UPSMON_%1%2',_uniqueLabel,_uniqueIndex];
	createMarkerLocal [_marker, getPos _target];
	_marker setMarkerColorLocal "ColorBlue";
	_marker setMarkerShapeLocal "RECTANGLE";
	_marker setMarkerBrushLocal "BORDER";
	_marker setMarkerSizeLocal [300,300];
	_marker setMarkerAlphaLocal 0;
};

_spawnLocations = [];
_attempts = 0;
while {count _spawnLocations < 8} do {
	sleep 0.05;
	_position = ([getPos _target,(_markerSize * 0.75),(_markerSize)] Call GetRandomPosition);
	_pos = [_position, 50] Call GetSafePlace;
	
	_inRange = true;
	if (paramBoundaries) then {
		_boundariesxy = 'WFBE_BOUNDARIESXY' Call GetNamespace;
		if (((_pos select 0) < (_markerSize / 2) || (_pos select 0) > (_boundariesxy - (_markerSize / 2))) || ((_pos select 1) < (_markerSize / 2) || (_pos select 1) > (_boundariesxy - (_markerSize / 2)))) then {
			_inRange = false;
		};
	};

	_near = _pos nearEntities [['Man','Car','Motorcycle','Ship','Air','Tank','StaticCannon'],_markerSize/8];
	
	if (east countSide _near == 0 && west countSide _near == 0 && _inRange) then {_spawnLocations = _spawnLocations + [_pos];_size = 650};
	_attempts = _attempts + 1;
	
	if (_attempts > 50) then {
		_attempts = 0;
		_size = _size + (_markerSize/5);
	};
};

_i = 0;
_vehicles = [];
while {_i < _grps} do {
	_teamType = Format ["WFBE_RESPATROLTYPE%1%2",1 + round(random 2),round(random 2)] Call GetNamespace;
	_group = _groups select _i;
	_pos = _spawnLocations select floor(random(count _spawnLocations));
	
	_retVal = [_teamType,_pos,resistance,paramResVehLock,_group] Call CreateTeamTemplate;
	_vehicles = _vehicles + (_retVal select 1);
	
	_group setFormation (['COLUMN','ECH RIGHT','LINE','FILE','DIAMOND'] select floor(random 5));
	
	_group setBehaviour 'COMBAT';
	_group setCombatMode 'RED';
	_group move (getPos _target);
	
	//--- If UPS is enabled, the ai will do a bit more than sitting in base.
	if (paramUPSMON) then {[(leader _group),_marker,"move","nofollow","reinforcement"] Spawn UPSMON};
	
	_i = _i + 1;
};

//--- Wait until everyone's dead.
waitUntil {
	sleep 1;

	_cpt = 0;
	{
		if !(isNil '_x') then {
			_cpt = _cpt + (count ((units _x) Call GetLiveUnits));
		};
	} forEach _groups;
	
	_cpt == 0
};

//--- Kill the spawned thread if it still runs.
if !(scriptDone _jipHandler) then {terminate _jipHandler};

//--- Wait for the client to end up his sync.
sleep 35;

//--- Free the mission.
[Format['_WFBE_M_RUNNINGMISSIONS_%1',_runFor],((Format['_WFBE_M_RUNNINGMISSIONS_%1',_runFor]) Call GetNamespace) - 1, true] Call SetNamespace;

//--- Delete UPSMON Marker if necessary.
if (paramUPSMON) then {deleteMarkerLocal _marker};