-
Notifications
You must be signed in to change notification settings - Fork 9
HC Experiment and Strongpoints #102
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
Draft
Landric
wants to merge
4
commits into
Crowdedlight:main
Choose a base branch
from
Landric:feature/strongpoint
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Draft
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,124 @@ | ||
| #include "script_component.hpp" | ||
| /*///////////////////////////////////////////////// | ||
| Author: Landric | ||
|
|
||
| File: fn_strongpoint.sqf | ||
| Parameters: _dialogResult, _in | ||
| Return: none | ||
|
|
||
| */////////////////////////////////////////////// | ||
| params ["_dialogResult","_in"]; | ||
|
|
||
| _in params [["_pos",[0,0,0],[[]],3], "_unit"]; | ||
|
|
||
| private _params = ["_composition", "_radius", "_desiredStrongpointCount", "_fill", "_sandbags", "_patrols"]; | ||
| if(!isNull _unit) then { _params = _params - ["_composition"]; }; | ||
| if(!EGVAR(main,zeiLoaded)) then { _params = _params - ["_sandbags"]; }; | ||
|
|
||
| _dialogResult params _params; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should be commented out when done testing ;-)
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hopefully by the time I'm finished, that line will be necessary :D |
||
|
|
||
|
|
||
| private "_groupPrefab"; | ||
| if(isNull _unit) then { | ||
| // TODO: actually link _composition to the UI portion | ||
| _groupPrefab = _composition; | ||
| } | ||
| else { | ||
| _groupPrefab = group _unit; | ||
| }; | ||
|
|
||
|
|
||
| // If an HC is registered, spawn units directly on that. Otherwise, spawn locally | ||
| private _hcRegister = GETMVAR(EGVAR(main,hcRegister),[]); | ||
| private _client = if(count _hcRegister > 0) then { | ||
| // Get the HC(s) with the lowest fps | ||
| private _minfps = selectMin (values _hcRegister); | ||
| private _clients = (keys _hcRegister) select { _hcRegister get _x <= _minfps}; | ||
| if(count _clients > 0) exitWith { selectRandom _clients }; | ||
| // If we can't find a client for some reason (e.g. the register has updated since getting the fps) | ||
| // just return any HC | ||
| selectRandom (keys _hcRegister) | ||
| } else { clientOwner }; | ||
|
|
||
| // Get all buildings in radius | ||
| // TODO: account for dispersion - i.e., cluster strongpoints together, or spread out | ||
| _buildings = ASLtoAGL _pos nearObjects ["House", _radius]; | ||
| _buildings = _buildings call BIS_fnc_arrayShuffle; | ||
|
|
||
|
|
||
| private _strongpointCount = 0; | ||
| while { _strongpointCount < _desiredStrongpointCount && (count _buildings) > 0 } do { | ||
|
|
||
| // Calculate the desired number of units to spawn for this strongpoint, | ||
| // based on the number of available positions in the building | ||
| private _building = _buildings deleteAt 0; | ||
| private _positions = _building buildingPos -1; | ||
| if(count _positions <= 0) then { continue; }; | ||
| private _desiredUnits = (round((count _positions) * _fill)) max 1; | ||
|
|
||
| // TODO: spawn units directly on HC if exists | ||
| // TODO: account for unit being null if we're selecting via dropdown | ||
| private _group = createGroup (side _unit); | ||
|
|
||
| for "_i" from 0 to _desiredUnits-1 do { | ||
| private _prefabUnit = (units _groupPrefab) select (_i % count (units _groupPrefab)); | ||
| [_group , [(typeOf _prefabUnit), position _building, [], 0, "NONE"]] remoteExec ["createUnit", _client]; | ||
| // private _newUnit = _group createUnit [(typeOf _prefabUnit), position _building, [], 0, "NONE"]; | ||
| //_newUnit setUnitLoadout (getUnitLoadout _prefabUnit); | ||
| // How to set the unit's loadout now that we don't have a reference to it, without bundling both commands into a "call"? | ||
| }; | ||
|
|
||
| if(EGVAR(main,lambsLoaded)) then { | ||
| [_group, _building, 1, [], true, true] call lambs_wp_fnc_taskGarrison; | ||
| } else { | ||
| // This is a very basic implementation of garrisoning strongpoints | ||
| private _units = units _group; | ||
| for "_i" from 0 to (count _units)-1 do { | ||
| _units#_i setPos _positions#_i; | ||
| _units#_i setUnitPos (selectRandom ["UP", "MIDDLE"]); | ||
| _units#_i disableAI "PATH"; | ||
| } | ||
| }; | ||
|
|
||
| if(!isNil "_sandbags" && { _sandbags }) then { | ||
| if(EGVAR(main,zeiLoaded)) then { | ||
| [_building,"mil",false,true,false,0] call ZEI_fnc_createTemplate; | ||
| } else { | ||
| // TODO: if zei not loaded, do manually (lol) | ||
| }; | ||
| }; | ||
|
|
||
| _strongpointCount = _strongpointCount + 1; | ||
| }; | ||
|
|
||
|
|
||
| // Create patrols | ||
| for "_i" from 0 to _patrols-1 do { | ||
|
|
||
| // TODO: account for unit being null if we're selecting via dropdown | ||
| private _group = createGroup (side _unit); | ||
| private _startPos = [[[ASLtoAGL _pos, _radius]]] call BIS_fnc_randomPos; | ||
| { | ||
| [_group , [(typeOf _x), _startPos, [], 0, "NONE"]] remoteExec ["createUnit", _client]; | ||
| // private _newUnit = _group createUnit [(typeOf _x), _startPos, [], 0, "NONE"]; | ||
| // _newUnit setUnitLoadout (getUnitLoadout _x); | ||
| // How to set the unit's loadout now that we don't have a reference to it, without bundling both commands into a "call"? | ||
| } forEach units _groupPrefab; | ||
|
|
||
| if(EGVAR(main,lambsLoaded)) then { | ||
| [_group, _pos, _radius, 4, [], true, true] call lambs_wp_fnc_taskPatrol; | ||
| } else { | ||
|
|
||
| // This is a very basic implementation of patroling | ||
| _group setBehaviour "SAFE"; | ||
| for "_i" from 0 to 4 do { | ||
| _group addWaypoint [_startPos, 200]; | ||
| }; | ||
| ((waypoints _group) select ((count waypoints _group)-1)) setWaypointType "CYCLE"; | ||
| }; | ||
| }; | ||
|
|
||
|
|
||
|
|
||
|
|
||
| { deleteVehicle _x } forEach units _groupPrefab; | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| #include "script_component.hpp" | ||
| /*///////////////////////////////////////////////// | ||
| Author: Landric | ||
|
|
||
| File: fn_strongpointZeus.sqf | ||
| Parameters: pos, unit | ||
| Return: none | ||
|
|
||
| */////////////////////////////////////////////// | ||
| params [["_pos",[0,0,0],[[]],3], ["_unit",objNull,[objNull]]]; | ||
|
|
||
| if(isNull _unit) exitWith { hint parseText (localize "STR_CROWSZA_Misc_strongpoint_error_no_unit"); }; //TODO: alternatively, add dropdown(s) with all compositions | ||
|
|
||
|
|
||
| private _controls = []; | ||
|
|
||
| // _controls append [ | ||
| // ["COMBO", "Side", [["west"], [["BLUFOR", "", "\A3\ui_f\data\map\markers\nato\b_unknown.paa"]], 0]], | ||
| // ["COMBO", "Faction", [["1"], [["Gendarmerie"]], 0]], | ||
| // ["COMBO", "Composition", [["1"], [["Gendarmerie Patrol", "", "\A3\ui_f\data\map\markers\nato\b_inf.paa"]], 0]] | ||
| // ]; | ||
|
|
||
| _controls append [ | ||
| ["SLIDER:RADIUS", localize "STR_CROWSZA_Misc_strongpoint_radius", [20, 500, 200, 0, ASLtoAGL _pos, [1, 0, 0, 0.7]]], | ||
| ["SLIDER", [localize "STR_CROWSZA_Misc_strongpoint_ui_strongpoints", localize "STR_CROWSZA_Misc_strongpoint_ui_strongpoints_tooltip"], [1, 20, 6, 0]], | ||
| ["SLIDER:PERCENT", [localize "STR_CROWSZA_Misc_strongpoint_ui_fill", localize "STR_CROWSZA_Misc_strongpoint_ui_fill_tooltip"], [0.1, 1, 0.8, 0]], | ||
| //["SLIDER:PERCENT", [localize "STR_CROWSZA_Misc_strongpoint_ui_dispersion", localize "STR_CROWSZA_Misc_strongpoint_ui_dispersion_tooltip"], [0, 1, 0.8, 0]], | ||
| ["CHECKBOX", [localize "STR_CROWSZA_Misc_strongpoint_ui_sandbags", localize "STR_CROWSZA_Misc_strongpoint_ui_sandbags_tooltip"], true], | ||
| ["SLIDER", [localize "STR_CROWSZA_Misc_strongpoint_ui_patrol", localize "STR_CROWSZA_Misc_strongpoint_ui_patrol_tooltip"], [0, 6, 2, 0]] | ||
| ]; | ||
|
|
||
| if(!EGVAR(main,zeiLoaded)) then { | ||
| _controls deleteAt 3; | ||
| }; | ||
|
|
||
|
|
||
| [ | ||
| localize "STR_CROWSZA_Misc_strongpoint", | ||
| _controls, | ||
| FUNC(strongpoint), | ||
| {}, | ||
| _this | ||
| ] call zen_dialog_fnc_create; |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hmm, not sure if it is worth it to sync an entire hashmap across the network, compared to an array of HCs, and then use
setVariable[GVAR(hcFPS), round diag_fps, true];Or even do nested array so
[[hc1,fps],[hc2,fps]...]As I the usage would be to loop through them, not know the key of the one you want, until you have been through them all.
transmitting an entire hashmap every 5 sec, compared to a single int value, should have some impact ;-)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would only work for one HC though, right? Otherwise you'd still need a mapping from HC id to fps.
Is it much faster to send a nested array than a hashmap? (It'd definitely make updating slower, because you'd have to iterate through the whole array until you found the right HC, rather than just using a key?)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could simply update the register every, say, 60 seconds instead
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hmm.
So good point that when updating the value a nested array wouldn't be quicker.
Usually I would do
player setVariable[GVAR(hcFPS), round diag_fps, true];as then any other client with a reference to that player, could use the_unit getVariable[]syntax to get the value. So if you have a list of registered HCs, you loop through it and read the public variables placed on the reference to the HC. Thus only needing a list of HCs, as you can lookup the variable saved on that player "object".I believe that would work with the HC too, as that is the same reference you need to send spawn event to the HC with CBA events?
But I am honestly not sure if there is any real performance benefit in that compared to sending a hashmap over the network. 😅