Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add: change foreach for select{} #102

Merged
merged 7 commits into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,8 @@ private ["_useful","_house","_id","_city","_xx","_y","_pos","_houses","_house"];

if (count btc_hideouts == 0) exitWith {};

_useful = [];
_house = objNull;
{if (_x getVariable ["occupied",false] && {_x getVariable ["type",""] != "NameLocal"} && {_x getVariable ["type",""] != "Hill"} && {_x getVariable ["type",""] != "NameMarine"}) then {_useful = _useful + [_x];};} foreach btc_city_all;
_useful = btc_city_all select {(_x getVariable ["occupied",false] && {_x getVariable ["type",""] != "NameLocal"} && {_x getVariable ["type",""] != "Hill"} && {_x getVariable ["type",""] != "NameMarine"})};

if (count _useful == 0) then {_useful = btc_city_all;};

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,8 @@ if ({_x distance _city < (_area/2) || _x distance leader _group < (_area/2)} cou
{deleteVehicle _x;} foreach units _group;deleteGroup _group;
};

_cities = [];
{if (((_x distance _city < _area) && !_iswater && {_x getVariable ["type",""] != "NameMarine"}) || ((_x distance _city < _area*2) && _iswater && {_x getVariable ["type",""] == "NameMarine"})) then {
_cities = _cities + [_x];
};} foreach btc_city_all;
_cities = btc_city_all select {(((_x distance _city < _area) && !_iswater && {_x getVariable ["type",""] != "NameMarine"}) || ((_x distance _city < _area*2) && _iswater && {_x getVariable ["type",""] == "NameMarine"}))};

_pos = [];
if (count _cities == 0) then {_pos = getPos _city;} else {
_pos = getPos (_cities select (floor random count _cities));
Expand Down
24 changes: 10 additions & 14 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/civ/traffic_create.sqf
Original file line number Diff line number Diff line change
@@ -1,28 +1,24 @@

private ["_city","_area","_cities","_useful","_unit_type","_veh_type","_group","_veh","_iswater"];
private ["_city","_area","_cities","_useful","_unit_type","_veh_type","_group","_veh","_iswater","_pos"];

_city = _this select 0;
_area = _this select 1;

if (isNil "btc_traffic_id") then {btc_traffic_id = 0;};

_cities = [];
{if (_x distance _city < _area) then {_cities = _cities + [_x];};} foreach btc_city_all;
_useful = [];
{
if !(_x getVariable ["active",false]) then {_useful = _useful + [getPos _x];};
} foreach _cities;

if (count _useful == 0) then {
while {count _useful == 0} do {
_cities = btc_city_all select {(_x distance _city < _area)};
_useful = _cities select {!(_x getVariable ["active",false])};
if (_useful isEqualTo []) then {
while {_useful isEqualTo []} do {
private "_pos";
_pos = [getPos _city, _area, true] call btc_fnc_randomize_pos;
if ({_x distance _pos < 500} count playableUnits == 0) then {_useful = _useful + [_pos];};
if ({_x distance _pos < 500} count playableUnits == 0) then {_useful pushBack _pos;};
};
_pos = selectRandom _useful;
} else {
_pos = getpos(_useful select (floor random count _useful));
};

_pos = _useful select (floor random count _useful);

_unit_type = btc_civ_type_units select (floor random count btc_civ_type_units);
_veh_type = btc_civ_type_veh select (floor (random (count btc_civ_type_veh)));

Expand All @@ -34,7 +30,7 @@ _group setVariable ["city",_city];

_Spos = [];
if (count (_pos nearRoads 100) > 0) then {
_Spos = getPos ((_pos nearRoads 500) select 0)
_Spos = getPos ((_pos nearRoads 500) select 0);
} else {
_Spos = [_pos, 0, 500, 13, 1, 60 * (pi / 180), 0] call BIS_fnc_findSafePos;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@ btc_city_remaining = [];
_marker setMarkerBrush "SolidBorder";
_marker setMarkerSize [(_radius_x+_radius_y), (_radius_x+_radius_y)];
_marker setMarkerAlpha 0.3;
if (_x getVariable ["occupied",false]) then {_marker setmarkercolor "colorRed";btc_city_remaining = btc_city_remaining + [_x];} else {_marker setmarkercolor "colorGreen";_marker setMarkerAlpha 0;};
if (_x getVariable ["occupied",false]) then {_marker setmarkercolor "colorRed";btc_city_remaining pushBack _x;} else {_marker setmarkercolor "colorGreen";_marker setMarkerAlpha 0;};
_x setVariable ["marker",_marker];
};
} foreach btc_city_all;

waitUntil {sleep 15; (count btc_city_remaining == 0)};
waitUntil {sleep 15; (btc_city_remaining isEqualTo [])};

[0,"btc_fnc_task_set_done",true,true] spawn BIS_fnc_MP;

Expand Down
10 changes: 2 additions & 8 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/common/getHouses.sqf
Original file line number Diff line number Diff line change
@@ -1,11 +1,5 @@
_pos = _this select 0;
_radius = _this select 1;
_buildings = nearestObjects [_pos, ["Building"], _radius];
_useful = [];
{
if (format["%1", _x buildingPos 2] != "[0,0,0]" && {damage _x == 0} && {isNil {_x getVariable "btc_house_taken"}}) then
{
_useful set [count _useful, _x];
};
} forEach _buildings;
_useful
_useful = _buildings select {(format["%1", _x buildingPos 2] != "[0,0,0]" && {damage _x == 0} && {isNil {_x getVariable "btc_house_taken"}})};
_useful
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ _color = "";_markers = [];
switch (true) do {case (side _x == west) : {_color = "ColorBlue"};case (side _x == east) : {_color = "ColorRed"};case (side _x == independent) : {_color = "ColorGreen"}; default {_color = "ColorWhite"};};
format ["%1", _x] setmarkerColorlocal _color;
format ["%1", _x] setMarkerSizeLocal [0.7, 0.7];
_markers = _markers + [_marker];
_markers pushBack _marker;
};
} foreach _units;
player sideChat format ["UNITS:%1 - GROUPS:%2", count allunits, count allgroups];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,6 @@ if !(_city getVariable ["active",false]) then

if (btc_final_phase) then
{
btc_city_remaining = btc_city_remaining + [_city];
btc_city_remaining pushBack _city;
};
diag_log format ["END = %1",[]];
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ if (!isNil {_group getVariable "getWeapons"}) then {_type_db = 5;};

if (vehicle leader _group != leader _group) then {_type_db = 1;};

if (_type_db == 1) then
if (_type_db == 1) then
{
private ["_veh"];
_veh = vehicle leader _group;
Expand Down
2 changes: 1 addition & 1 deletion =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/fob/create.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ _name = ctrlText 777;

_name_to_check = ("FOB " + (toUpper(_name)));
_array_markers = [];
{private "_n";_n = toUpper(_x);_array_markers = _array_markers + [_n];} foreach allMapMarkers;
{private "_n";_n = toUpper(_x);_array_markers pushBack _n;} foreach allMapMarkers;

if (_array_markers find _name_to_check >= 0) exitWith {closeDialog 0;hint "Name already in use!";_mat spawn btc_fnc_fob_create;};

Expand Down
10 changes: 5 additions & 5 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/ied/fired_near.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ _pos = getPos _this;
_pos = [_pos select 0, _pos select 1, (_pos select 2) + 0.5];
_range = 2;

_bomb_check =
_bomb_check =
{
_ied = _this select 0;
_bomb = _this select 1;
Expand All @@ -13,21 +13,21 @@ _bomb_check =

_array = [];

while {alive _this && !isNull _this && _this getVariable ["active",false]} do
while {alive _this && !isNull _this && _this getVariable ["active",false]} do
{
_list = _pos nearObjects ["Default",_range];
if (count _list > 0) then
if (count _list > 0) then
{
{
private "_bullet";
_b = _x;
_bullet = typeOf _b;
if ({_bullet isKindOf _x} count ["SmokeShell", "FlareCore", "IRStrobeBase", "GrenadeHand_stone", "Smoke_120mm_AMOS_White", "TMR_R_DG32V_F"] > 0) exitWith {};
if ({_bullet isKindOf _x} count ["TimeBombCore","BombCore", "Grenade"] > 0) then
if ({_bullet isKindOf _x} count ["TimeBombCore","BombCore", "Grenade"] > 0) then
{
if !(_b in _array) then
{
_array = _array + [_b];
_array pushBack _b;
[_this,_b] spawn _bomb_check;
};
}
Expand Down
33 changes: 13 additions & 20 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/mil/check_cap.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,47 +5,40 @@ if (btc_hideout_cap_checking) exitWith {};

btc_hideout_cap_checking = true;

_cap_to = [];
_cap_to = btc_hideouts select {(time - (_x getVariable ["cap_time",time]) > btc_hideout_cap_time)};

{
//_hd = _x;
//if ({_x distance _hd < 700} count playableUnits > 0) exitWith {};
if (time - (_x getVariable ["cap_time",time]) > btc_hideout_cap_time) then {_cap_to = _cap_to + [_x];};
} foreach btc_hideouts;

if (count _cap_to == 0) exitWith {if (btc_debug_log) then {diag_log "btc_fnc_mil_check_cap: exit cap time";};};
if (_cap_to isEqualTo []) exitWith {if (btc_debug_log) then {diag_log "btc_fnc_mil_check_cap: exit cap time";};};

{
private ["_hd","_in_range"];
_hd = _x;
_in_range = [];
{if (_hd distance _x < btc_hideout_range) then {_in_range = _in_range + [_x];};} foreach btc_city_all;

if (count _in_range == 0) exitWith {if (btc_debug_log) then {diag_log format ["btc_fnc_mil_check_cap: exit no in range = %1",_hd getVariable "id"];};};

_in_range = btc_city_all select {(_hd distance _x < btc_hideout_range)};

if (_in_range isEqualTo []) exitWith {if (btc_debug_log) then {diag_log format ["btc_fnc_mil_check_cap: exit no in range = %1",_hd getVariable "id"];};};

private ["_closest","_dist","_pos"];

_closest = objNull;
_dist = 999999;
_pos = getPos _hd;
{if (_x distance _pos < _dist && {!(_x getVariable ["occupied",false])}) then {_closest = _x;_dist = _x distance _pos;};} foreach _in_range;

if (btc_debug_log) then {diag_log format ["btc_fnc_mil_check_cap: _in_range = %1",_in_range];};

if (isNull _closest) exitWith {if (btc_debug_log) then {diag_log format ["btc_fnc_mil_check_cap: exit null _closest = %1",_hd getVariable "id"];};};

if (btc_debug_log) then {diag_log format ["btc_fnc_mil_check_cap: SEND FROM = %1 TO %2 [int %3]",_hd getVariable "id",_closest getVariable ["name","error"],_closest getVariable ["initialized",false]];};

_hd setVariable ["cap_time",time];

if (_closest getVariable ["initialized",false]) then {
/*[_hd,_closest,1,"I_Truck_02_transport_F"] spawn btc_fnc_mil_send;
sleep 1;
[_hd,_closest,1,"I_Truck_02_transport_F"] spawn btc_fnc_mil_send;
sleep 1;*/
for "_i" from 0 to (2 + (round random 3)) do {[_hd,_closest,0] call btc_fnc_mil_send;};
} else {_closest setVariable ["occupied",true];if (btc_debug) then {(format ["loc_%1",_closest getVariable "id"]) setMarkerColor "ColorRed";};};

} foreach _cap_to;

btc_hideout_cap_checking = false;
10 changes: 4 additions & 6 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/mil/check_rinf.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,18 +5,16 @@ _city = objNull;

if (count _this > 0) then {_city = _this;} else {
private ["_useful","_id"];
_useful = [];
//"NameVillage","NameCity","NameCityCapital","NameLocal","Hill"
{
if (
_useful = btc_city_all select {(
!(_x getVariable ["active",false]) && {_x distance (getMarkerPos btc_respawn_marker) > btc_hideout_safezone} &&
{!(_x getVariable ["has_ho",false])} &&
(
_x getVariable ["type",""] == "NameLocal" ||
{_x getVariable ["type",""] == "Hill"} || {_x getVariable ["type",""] == "NameVillage"}
)
) then {_useful = _useful + [_x];};
} foreach btc_city_all;
)
};
_id = floor random count _useful;
_city = _useful select _id;
};
Expand Down Expand Up @@ -53,4 +51,4 @@ if (btc_debug) then {
if (btc_debug_log) then {diag_log format ["btc_fnc_mil_create_hideout: _this = %1 ; POS %2 ID %3",_this,_pos,btc_hideouts_id];};

btc_hideouts_id = btc_hideouts_id + 1;
btc_hideouts = btc_hideouts + [_hideout];
btc_hideouts pushBack _hideout;
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,8 @@ _city = objNull;

if (count _this > 0) then {_city = _this;} else {
private ["_useful","_id"];
_useful = [];
{
//"NameVillage","NameCity","NameCityCapital","NameLocal","Hill"
if (
//"NameVillage","NameCity","NameCityCapital","NameLocal","Hill"
_useful = btc_city_all select {(
!(_x getVariable ["active",false]) &&
{_x distance (getMarkerPos btc_respawn_marker) > btc_hideout_safezone} &&
{!(_x getVariable ["has_ho",false])} &&
Expand All @@ -17,8 +15,7 @@ if (count _this > 0) then {_city = _this;} else {
{_x getVariable ["type",""] == "Hill"} ||
{_x getVariable ["type",""] == "NameVillage"}
)
) then {_useful = _useful + [_x];};
} foreach btc_city_all;
)};
_id = floor random count _useful;
_city = _useful select _id;
};
Expand Down Expand Up @@ -59,6 +56,6 @@ if (btc_debug) then {
if (btc_debug_log) then {diag_log format ["btc_fnc_mil_create_hideout: _this = %1 ; POS %2 ID %3",_this,_pos,btc_hideouts_id];};

btc_hideouts_id = btc_hideouts_id + 1;
btc_hideouts = btc_hideouts + [_hideout];
btc_hideouts pushBack _hideout;

true
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,7 @@ if ({_x distance _city < (_area/2) || _x distance leader _group < (_area/2)} cou
{deleteVehicle _x;} foreach units _group;deleteGroup _group;
};

_cities = [];
{if (((_x distance _city < _area) && !_iswater && {_x getVariable ["type",""] != "NameMarine"}) || ((_x distance _city < _area*2) && _iswater && {_x getVariable ["type",""] == "NameMarine"})) then {
_cities = _cities + [_x];
};} foreach btc_city_all;
_cities = btc_city_all select {(((_x distance _city < _area) && !_iswater && {_x getVariable ["type",""] != "NameMarine"}) || ((_x distance _city < _area*2) && _iswater && {_x getVariable ["type",""] == "NameMarine"}))};
_pos = [];
if (count _cities == 0) then {_pos = getPos _city;} else {
_pos = getPos (_cities select (floor random count _cities));
Expand Down
10 changes: 4 additions & 6 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/mil/patrol_create.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,8 @@ if (_random == 0) then {
case (_n > 96) : {_random = 4;};
};
};
_cities = [];
{if (_x distance _city < _area) then {_cities = _cities + [_x];};} foreach btc_city_all;
_useful = [];
{if (!(_x getVariable ["active",false]) && _x getVariable ["occupied",false]) then {_useful = _useful + [getPos _x];};} foreach _cities;
_cities = btc_city_all select {(_x distance _city < _area)};
_useful = _cities select {(!(_x getVariable ["active",false]) && _x getVariable ["occupied",false])};

/*
if (count _useful == 0) then {
Expand All @@ -36,7 +34,7 @@ if (count _useful == 0) then {

if (count _useful == 0) exitWith {true};

_pos = _useful select (floor random count _useful);
_pos = getpos(_useful select (floor random count _useful));

_group = createGroup btc_enemy_side;
_group setVariable ["city",_city];
Expand Down Expand Up @@ -64,7 +62,7 @@ switch (true) do {
private ["_veh_type","_newZone","_veh","_cargo"];
_newZone = [];
if (count (_pos nearRoads 150) > 0) then {
_newZone = getPos ((_pos nearRoads 150) select 0)
_newZone = getPos ((_pos nearRoads 150) select 0);
} else {
_newZone = [_pos, 0, 500, 13, 1, 60 * (pi / 180), 0] call BIS_fnc_findSafePos;
};
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
private ["_useful","_city","_pos","_road","_roads","_boxes","_marker","_markers","_statics","_tower_type","_tower","_direction","_type_barrel","_type_canister","_type_pallet","_type_box","_btc_composition_checkpoint"];

//// Choose an occupied City \\\\
_useful = [];
{if (_x getVariable ["occupied",false] && {_x getVariable ["type",""] != "NameLocal"} && {_x getVariable ["type",""] != "Hill"} && (_x getVariable ["type",""] != "NameMarine")) then {_useful = _useful + [_x];};} foreach btc_city_all;
if (count _useful == 0) exitWith {[] spawn btc_fnc_side_create;};
_useful = btc_city_all select {(_x getVariable ["occupied",false] && {_x getVariable ["type",""] != "NameLocal"} && {_x getVariable ["type",""] != "Hill"} && (_x getVariable ["type",""] != "NameMarine"))};
if (_useful isEqualTo []) exitWith {[] spawn btc_fnc_side_create;};
_city = _useful select (floor random count _useful);
_pos = getPos _city;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,8 @@
private ["_useful","_veh","_vehpos","_city","_pos","_r","_houses","_roads","_marker","_unit_type","_fx","_phone_type"];

//// Choose a clear City \\\\
_useful = [];
{if (!(_x getVariable ["occupied",false]) && {_x getVariable ["type",""] != "NameLocal"} && {_x getVariable ["type",""] != "Hill"} && (_x getVariable ["type",""] != "NameMarine")) then {_useful = _useful + [_x];};} foreach btc_city_all;
if (count _useful == 0) exitWith {[] spawn btc_fnc_side_create;};
_useful = btc_city_all select {(!(_x getVariable ["occupied",false]) && {_x getVariable ["type",""] != "NameLocal"} && {_x getVariable ["type",""] != "Hill"} && (_x getVariable ["type",""] != "NameMarine"))};
if (_useful isEqualTo []) exitWith {[] spawn btc_fnc_side_create;};
_city = _useful select (floor random count _useful);
_pos = getPos _city;

Expand Down
6 changes: 2 additions & 4 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/side/get_city.sqf
Original file line number Diff line number Diff line change
@@ -1,10 +1,8 @@

private ["_useful","_city","_pos"];

_useful = [];
{if (_x getVariable ["occupied",false] && {_x getVariable ["type",""] != "NameLocal"} && {_x getVariable ["type",""] != "Hill"} && (_x getVariable ["type",""] != "NameMarine")) then {_useful = _useful + [_x];};} foreach btc_city_all;

if (count _useful == 0) exitWith {[] spawn btc_fnc_side_create;};
_useful = btc_city_all select {((_x getVariable ["occupied",false]) && {_x getVariable ["type",""] != "NameLocal"} && {_x getVariable ["type",""] != "Hill"} && {_x getVariable ["type",""] != "NameMarine"})};
if (_useful isEqualTo []) exitWith {[] spawn btc_fnc_side_create;};

_city = _useful select (floor random count _useful);

Expand Down
5 changes: 2 additions & 3 deletions =BTC=co@30_Hearts_and_Minds.Altis/core/fnc/side/mines.sqf
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

private ["_useful","_city","_pos","_area","_marker","_mines"];

_useful = [];
{if (_x getVariable ["type",""] != "NameLocal" && {_x getVariable ["type",""] != "Hill"} && (_x getVariable ["type",""] != "NameMarine")) then {_useful = _useful + [_x];};} foreach btc_city_all;
_useful = btc_city_all select {((_x getVariable ["type",""] != "NameLocal") && {_x getVariable ["type",""] != "Hill"} && (_x getVariable ["type",""] != "NameMarine"))};

if (count _useful == 0) then {_useful = + btc_city_all;};
if (_useful isEqualTo []) then {_useful = + btc_city_all;};

_city = _useful select (floor random count _useful);

Expand Down
Loading