Skip to content

Commit

Permalink
refactoring de la logique d'utilisation des modules
Browse files Browse the repository at this point in the history
  • Loading branch information
zgmrvn committed Apr 8, 2017
1 parent fc1662a commit f384c21
Show file tree
Hide file tree
Showing 18 changed files with 156 additions and 285 deletions.
14 changes: 10 additions & 4 deletions @corp_edition/addons/corp_edition_area_patrols/config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -45,11 +45,17 @@ class CfgVehicles {
isDisposable = 0;
is3DEN = 0;

canSetArea = 1;
class AttributeValues {
size3[]={50, 50, -1};
isRectangle = 1;
};

class Attributes: AttributesBase {
class GroupsPerArea: Edit {
property = "CORP_Module_AreaPatrols_GroupsPerArea";
displayName = $STR_CORP_AREA_PATROLS_GROUPS_PER_AREA_DN;
description = $STR_CORP_AREA_PATROLS_GROUPS_PER_AREA_DESC;
class NumberOfGroups: Edit {
property = "CORP_Module_AreaPatrols_NumberOfGroups";
displayName = $STR_CORP_AREA_PATROLS_NUMBER_OF_GROUPS_DN;
description = $STR_CORP_AREA_PATROLS_NUMBER_OF_GROUPS_DESC;
typeName = "NUMBER";
defaultValue = "4";
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
/*
framework de mission du CORP
Outils d'édition du CORP
http://www.corp-arma.fr
*/

#define WAYPOINT_COMPLETION_RADIUS 4

private _center = param [0, [0, 0, 0], [[]], 3];
private _area = param [1, [0, 0, 0, false, -1], [[]], 5];
private _side = param [2, east, [sideUnknown]];
Expand Down Expand Up @@ -35,14 +37,21 @@ _group setBehaviour "RED";
_group setSpeedMode "LIMITED";

{
_type = ["MOVE", "CYCLE"] select (_forEachIndex == ((count _waypointsPositions) - 1));

_wp = _group addWaypoint [_waypointsPositions select _forEachIndex, 0];
_wp setWaypointCompletionRadius 4;
_wp setWaypointCompletionRadius WAYPOINT_COMPLETION_RADIUS;
_wp setWaypointFormation (selectRandom _formations);
_wp setWaypointBehaviour "SAFE";
_wp setWaypointCombatMode "RED";
_wp setWaypointType _type;
_wp setWaypointType "MOVE";

if (_forEachIndex == ((count _waypointsPositions) - 1)) then {
_wp = _group addWaypoint [_waypointsPositions select _forEachIndex, 0];
_wp setWaypointCompletionRadius WAYPOINT_COMPLETION_RADIUS;
_wp setWaypointFormation (selectRandom _formations);
_wp setWaypointBehaviour "SAFE";
_wp setWaypointCombatMode "RED";
_wp setWaypointType "CYCLE";
};
} forEach _waypointsPositions;

_group
Original file line number Diff line number Diff line change
@@ -1,19 +1,17 @@
private _logic = param [0, objNull, [objNull]];
private _units = param [1, [], [[]]];
private _areas = _logic call CORP_fnc_getSynchronizedAreas;

if (count _units == 0) exitWith {[format ["%1 %2 : %3", localize "STR_CORP_AREA_PATROLS_DN", _logic, localize "STR_CORP_CORE_NO_UNIT_SYNCHED"]] call BIS_fnc_error;};
if (count _areas == 0) exitWith {[format ["%1 %2 : %3", localize "STR_CORP_AREA_PATROLS_DN", _logic, localize "STR_CORP_CORE_NO_AREA_SYNCHED"]] call BIS_fnc_error;};

// préparation du reste des données de la fonction
private _unitsFinal = [];
private _side = side (_units select 0);
private _groupsPerArea = _logic getVariable ["GroupsPerArea", 4];
private _area = _logic getvariable ["objectArea", [0, 0, 0, false, 0]];
private _numberOfGroups = _logic getVariable ["NumberOfGroups", 4];
private _unitsPerGroup = _logic getVariable ["UnitsPerGroup", 4];
private _waypointsPerGroup = _logic getVariable ["WaypointsPerGroup", 4];
private _dynamicSimulation = _logic getVariable ["DynamicSimulation", true];
private _debug = _logic getVariable ["Debug", false];
private _areasColor = [_side, "STRING"] call CORP_fnc_getSideColor;

private _units = _units call CORP_fnc_getGroupedUnits;
private _side = side (_units select 0);

// si le débug est demandé et que la machine a une interface
if (_debug && {hasInterface}) then {
Expand All @@ -30,10 +28,8 @@ if (_debug && {hasInterface}) then {

// pour chaque groupe créé par un module Area Patrols et dont le paramètre "débug" est coché
{
private _group = _x;

// on détermine la couleur du side du groupe
private _sideColor = [side _group, "ARRAY"] call CORP_fnc_getSideColor;
private _group = _x;
private _sideColor = [side _group, "ARRAY"] call CORP_fnc_getSideColor;

// on dessine chaque unité du groupe
{
Expand All @@ -58,59 +54,36 @@ if (_debug && {hasInterface}) then {
}];
};

// on dessine les zones sur carte
{
private _area = _x getvariable ["objectArea", [0, 0, 0, false, 0]];

private _marker = createMarker [format ["area_%1", _x], _x];
_marker setMarkerShape (["ELLIPSE", "RECTANGLE"] select (_area select 3));
_marker setMarkerSize [_area select 0, _area select 1];
_marker setMarkerDir (_area select 2);
_marker setMarkerBrush "Border";
_marker setMarkerColor _areasColor;
} forEach _areas;
// on dessine la zone
private _marker = createMarker [format ["area_%1", _logic], _logic];
_marker setMarkerShape "RECTANGLE";
_marker setMarkerSize [_area select 0, _area select 1];
_marker setMarkerDir (_area select 2);
_marker setMarkerBrush "Border";
_marker setMarkerColor ([_side, "STRING"] call CORP_fnc_getSideColor);
};

// pour chaque unité synchronisée au module
{
private _unit = _x;
// on créé les patrouilles
for "_i" from 0 to (_numberOfGroups - 1) do {
private _unitsResized = [];
private _random = ceil (random (_unitsPerGroup - 1));

// on récupères toutes les unités de son groupe
// et on ajoute le classname de l'unité au tableau final d'unités s'il n'y est pas déjà
{
_typeOf = typeOf _x;
if !(_typeOf in _unitsFinal) then {
_unitsFinal pushBack _typeOf;
};
} forEach (units _unit);
} forEach _units;

// pour chaque zone on créé les patrouilles
{
private _center = getPosASL _x;
private _area = _x getvariable ["objectArea", [0, 0, 0, false, 0]];;

for "_i" from 0 to (_groupsPerArea - 1) do {
private _unitsResized = [];
private _random = ceil (random (_unitsPerGroup - 1));

for "_ii" from 0 to _random do {
_unitsResized pushBack (selectRandom _unitsFinal);
};

_patrol = [_center, _area, _side, _unitsResized, _waypointsPerGroup] call CORP_fnc_areaPatrols_createAreaPatrol;
if (_debug) then {
CORP_var_areaPatrols_patrols pushBack _patrol;
};

// activation/désactivation de la simulation dynamique pour le groupe créé
_patrol enableDynamicSimulation _dynamicSimulation;
for "_ii" from 0 to _random do {
_unitsResized pushBack (selectRandom _units);
};
} forEach _areas;

// todo : supprimer tous les triggers synchronisés
private _group = [getPosASL _logic, _area, _side, [_unitsResized, {typeOf _x}] call CBA_fnc_filter, _waypointsPerGroup] call CORP_fnc_areaPatrols_createAreaPatrol;

// on supprime manuellement le module
// on ne le fait pas via la propriété "disposable" de la config
// parce que le module est supprimé avant que l'on ait récupéré les déclencheurs synchronisés
deleteVehicle _logic;
// debug
if !(isNil {CORP_var_areaPatrols_patrols}) then {
CORP_var_areaPatrols_patrols pushBack _group;
};

// activation/désactivation de la simulation dynamique pour le groupe créé
_group enableDynamicSimulation _dynamicSimulation;

// copie de l'équipement d'une des unités synchronisée
{
_x setUnitLoadout [getUnitLoadout (selectRandom _units), true];
} forEach (units _group);
};
20 changes: 10 additions & 10 deletions @corp_edition/addons/corp_edition_area_patrols/stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -9,20 +9,20 @@
</Key>

<!-- groups per area -->
<Key ID="STR_CORP_AREA_PATROLS_GROUPS_PER_AREA_DN">
<Original>Number of groups per area</Original>
<French>Nombre de groupes par zone</French>
<Key ID="STR_CORP_AREA_PATROLS_NUMBER_OF_GROUPS_DN">
<Original>Number of groups</Original>
<French>Nombre de groupes</French>
</Key>

<Key ID="STR_CORP_AREA_PATROLS_GROUPS_PER_AREA_DESC">
<Original>Number of groups per area</Original>
<French>Nombre de groupes par zone</French>
<Key ID="STR_CORP_AREA_PATROLS_NUMBER_OF_GROUPS_DESC">
<Original>Number of groups</Original>
<French>Nombre de groupes</French>
</Key>

<!-- units per group -->
<Key ID="STR_CORP_AREA_PATROLS_UNITS_PER_GROUP_DN">
<Original>Max number of units per group</Original>
<French>Nombre d'unités max par groupe</French>
<Original>Max units per group</Original>
<French>Unités max par groupe</French>
</Key>

<Key ID="STR_CORP_AREA_PATROLS_UNITS_PER_GROUP_DESC">
Expand All @@ -32,8 +32,8 @@

<!-- waypoints per group -->
<Key ID="STR_CORP_AREA_PATROLS_WAYPOINTS_PER_GROUP_DN">
<Original>Number of waypoints per group</Original>
<French>Nombre de points de passage par groupe</French>
<Original>Waypoints per group</Original>
<French>Points de passage par groupe</French>
</Key>

<Key ID="STR_CORP_AREA_PATROLS_WAYPOINTS_PER_GROUP_DESC">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,16 @@ class CfgVehicles {
isDisposable = 0;
is3DEN = 0;

canSetArea = 1;
class AttributeValues {
size3[]={50, 50, -1};
};

class Attributes: AttributesBase {
class UnitsPerArea: Edit {
property = "CORP_Module_BuildingsOccupation_UnitsPerArea";
displayName = $STR_CORP_BUILDINGS_OCCUPATION_UNITS_PER_AREA_DN;
description = $STR_CORP_BUILDINGS_OCCUPATION_UNITS_PER_AREA_DESC;
class NumberOfUnits: Edit {
property = "CORP_Module_BuildingsOccupation_NumberOfUnits";
displayName = $STR_CORP_BUILDINGS_OCCUPATION_NUMBER_OF_UNITS_DN;
description = $STR_CORP_BUILDINGS_OCCUPATION_NUMBER_OF_UNITS_DESC;
typeName = "NUMBER";
defaultValue = "10";
};
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,16 @@
private _logic = param [0, objNull, [objNull]];
private _units = param [1, [], [[]]];
private _areas = _logic call CORP_fnc_getSynchronizedAreas;

if (count _units == 0) exitWith {[format ["%1 %2 : %3", localize "STR_CORP_BUILDINGS_OCCUPATION_DN", _logic, localize "STR_CORP_CORE_NO_UNIT_SYNCHED"]] call BIS_fnc_error;};
if (count _areas == 0) exitWith {[format ["%1 %2 : %3", localize "STR_CORP_BUILDINGS_OCCUPATION_DN", _logic, localize "STR_CORP_CORE_NO_AREA_SYNCHED"]] call BIS_fnc_error;};

// préparation du reste des données de la fonction
private _unitsFinal = [];
private _side = side (_units select 0);
private _unitsPerArea = _logic getVariable ["UnitsPerArea", 10];
private _area = _logic getvariable ["objectArea", [0, 0, 0, false, 0]];
private _numberOfUnits = _logic getVariable ["NumberOfUnits", 10];
private _keepPosition = _logic getVariable ["KeepPosition", 0.5];
private _dynamicSimulation = _logic getVariable ["DynamicSimulation", true];
private _debug = _logic getVariable ["Debug", false];

// on définit la couleur des zones en fonction du side des IA synchronisées
private _areasColor = [_side, "STRING"] call CORP_fnc_getSideColor;
private _units = _units call CORP_fnc_getGroupedUnits;
private _side = side (_units select 0);

// si le débug est demandé et que la machine a une interface
if (_debug && {hasInterface}) then {
Expand All @@ -30,74 +26,44 @@ if (_debug && {hasInterface}) then {

// pour chaque zone
{
private _area = _x;

// on définit la couleur de l'icône de l'unité
private _sideColor = [side (_area select 0), "ARRAY"] call CORP_fnc_getSideColor;

// pour chaque unité de la zone on dessine une icône
private _areaUnits = _x;
// pour chaque unité en vie de la zone on dessine une icône
{
_map drawIcon [
getText (configFile >> "CfgVehicles" >> typeOf _x >> "Icon"),
_sideColor,
visiblePosition _x,
0.5 / ctrlMapScale _map,
0.5 / ctrlMapScale _map,
getDirVisual _x
];
} forEach _area;
if (alive _x) then {
_map drawIcon [
getText (configFile >> "CfgVehicles" >> typeOf _x >> "Icon"),
[side _x, "ARRAY"] call CORP_fnc_getSideColor,
visiblePosition _x,
0.5 / ctrlMapScale _map,
0.5 / ctrlMapScale _map,
getDirVisual _x
];
};
} forEach _areaUnits;
} forEach CORP_var_buildingsOccupation_occupations;

}];
};

// on dessine les zones sur carte
{
private _area = _x getvariable ["objectArea", [0, 0, 0, false, 0]];

private _marker = createMarker [format ["area_%1", _x], _x];
_marker setMarkerShape (["ELLIPSE", "RECTANGLE"] select (_area select 3));
_marker setMarkerSize [_area select 0, _area select 1];
_marker setMarkerDir (_area select 2);
_marker setMarkerBrush "Border";
_marker setMarkerColor _areasColor;
} forEach _areas;
// on dessine la zone sur carte
private _marker = createMarker [format ["area_%1", _logic], _logic];
_marker setMarkerShape (["ELLIPSE", "RECTANGLE"] select (_area select 3));
_marker setMarkerSize [_area select 0, _area select 1];
_marker setMarkerDir (_area select 2);
_marker setMarkerBrush "Border";
_marker setMarkerColor ([_side, "STRING"] call CORP_fnc_getSideColor);
};

// on récupères les unités synchronisées au module
// et on génère un tableau consolidé de toutes les classnames
{
private _unit = _x;
// création de l'occupation
private _occupation = [getPosASL _logic, (_area select 0) max (_area select 1), _numberOfUnits, _side, [_units, {typeOf _x}] call CBA_fnc_filter, _keepPosition] call CORP_fnc_buildingsOccupation_occupation;

{
_typeOf = typeOf _x;
if !(_typeOf in _unitsFinal) then {
_unitsFinal pushBack _typeOf;
};
} forEach (units _unit);
} forEach _units;
if !(isNil {CORP_var_buildingsOccupation_occupations}) then {
CORP_var_buildingsOccupation_occupations pushBack _occupation;
};

// pour chaque zone on créé l'occupation
{
private _center = getPosASL _x;
private _area = _x getvariable ["objectArea", [0, 0, 0, false, 0]];
private _radius = (_area select 0) max (_area select 1);

private _occupation = [_center, _radius, _unitsPerArea, _side, _unitsFinal, _keepPosition] call CORP_fnc_buildingsOccupation_occupation;

if (_debug) then {
CORP_var_buildingsOccupation_occupations pushBack _occupation;
};

// activation/désactivation de la simulation dynamique pour les unités créées
{
_x enableDynamicSimulation _dynamicSimulation;
} forEach _occupation;
} forEach _areas;

// todo : supprimer tous les triggers synchronisés
_x enableDynamicSimulation _dynamicSimulation;

// on supprime manuellement le module
// on ne le fait pas via la propriété "disposable" de la config
// parce que le module est supprimé avant que l'on ait récupéré les déclencheurs synchronisés
deleteVehicle _logic;
// copie de l'équipement d'une des unités synchronisée
_x setUnitLoadout [getUnitLoadout (selectRandom _units), true];
} forEach _occupation;
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ for [{private _i = 0}, {(_i < _unitsCount) && {_i < _positionsCount}}, {_i = _i
while {_loop && {alive _unit}} do {
private _players = [_pos, PATH_ACTIVATION_DISTANCE, _sides] call CORP_fnc_alivePlayersRadius;

// si des joueurs ont été trouvé, on réactive le PATH
// si des joueurs ont été trouvés, on réactive le PATH
if (count _players > 0) then {
_unit enableAI "PATH";
_loop = false;
Expand Down
Loading

1 comment on commit f384c21

@zgmrvn
Copy link
Collaborator Author

@zgmrvn zgmrvn commented on f384c21 Apr 8, 2017

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

résolution de #2 et #4

Please sign in to comment.