Part 1
Create 200 footmen on the map at random locations. (but within playable map area)
Loop through all units on map, and kill them if they are in range of 1000 towards the center of the map.
Part 2
Create a trigger that runs when a player presses the 'Esc' button (Skip Cinematic).
When the trigger runs, the amount of alive footmen should be printed on screen.
For solving this part, the "FoG Enumeration" technique must be used.
Create 200 footmen on the map at random locations. (but within playable map area)
Loop through all units on map, and kill them if they are in range of 1000 towards the center of the map.
vJASS:
//! zinc
library UnitGroups {
private {
group Group = CreateGroup();
timer Timer = CreateTimer();
function DeadlyCenter( unit whichUnit ) -> boolean {
real dx = GetUnitX( whichUnit );
real dy = GetUnitY( whichUnit );
return SquareRoot( dx * dx + dy * dy ) <= 1000;
}
function onInit() {
real xMax = GetRectMinX( bj_mapInitialPlayableArea );
real xMin = GetRectMaxX( bj_mapInitialPlayableArea );
real yMax = GetRectMinY( bj_mapInitialPlayableArea );
real yMin = GetRectMaxY( bj_mapInitialPlayableArea );
real x;
real y;
integer Index = 0;
while( Index < 200 ) {
x = GetRandomReal( xMax, xMin );
y = GetRandomReal( yMax, yMin );
GroupAddUnit( Group,
CreateUnit( Player(0), 'hfoo', x, y, GetRandomReal( 0, 360 ) )
);
Index = Index + 1;
}
TimerStart( Timer, 0.0312500, true, function(){
ForGroup( Group, function(){
unit u = GetEnumUnit();
if( DeadlyCenter( u ) ) {
KillUnit( u );
GroupRemoveUnit( Group, u );
}
u = null;
});
});
}
}
}
//! endzinc
Part 2
Create a trigger that runs when a player presses the 'Esc' button (Skip Cinematic).
When the trigger runs, the amount of alive footmen should be printed on screen.
For solving this part, the "FoG Enumeration" technique must be used.
vJASS:
//! zinc
library UnitGroups {
private {
group Group = CreateGroup();
timer Timer = CreateTimer();
integer Counter = 0;
function CountFootmen() -> integer {
Counter = 0;
ForGroup( Group, function() {
Counter = Counter + 1;
});
return Counter;
}
function DeadlyCenter( unit whichUnit ) -> boolean {
real dx = GetUnitX( whichUnit );
real dy = GetUnitY( whichUnit );
return SquareRoot( dx * dx + dy * dy ) <= 1000;
}
function onInit() {
trigger trgESC = CreateTrigger();
real xMax = GetRectMinX( bj_mapInitialPlayableArea );
real xMin = GetRectMaxX( bj_mapInitialPlayableArea );
real yMax = GetRectMinY( bj_mapInitialPlayableArea );
real yMin = GetRectMaxY( bj_mapInitialPlayableArea );
real x;
real y;
integer Count = 0;
integer Index = 0;
while( Count < 200 ) {
x = GetRandomReal( xMax, xMin );
y = GetRandomReal( yMax, yMin );
GroupAddUnit( Group,
CreateUnit( Player(0), 'hfoo', x, y, GetRandomReal( 0, 360 ) )
);
Count = Count + 1;
}
while( Index < bj_MAX_PLAYERS ) {
TriggerRegisterPlayerEvent( trgESC, Player( Index ), EVENT_PLAYER_END_CINEMATIC );
Index = Index + 1;
}
TriggerAddAction( trgESC, function(){
ClearTextMessages();
DisplayTextToPlayer( GetLocalPlayer(), 0, 0,
"Alive Footmen: " + I2S( CountFootmen() )
);
});
TimerStart( Timer, 0.0312500, true, function(){
ForGroup( Group, function(){
unit u = GetEnumUnit();
if( DeadlyCenter( u ) ) {
KillUnit( u );
GroupRemoveUnit( Group, u );
}
u = null;
});
});
trgESC = null;
}
}
}
//! endzinc