Add ability to carry and place flags

This commit is contained in:
Timi007 2022-06-10 21:46:06 +02:00
parent d8af7b34b7
commit 6a95746434
No known key found for this signature in database
GPG Key ID: AFC60E0DA93308DA
38 changed files with 602 additions and 0 deletions

1
addons/flags/$PBOPREFIX$ Normal file
View File

@ -0,0 +1 @@
z\ace\addons\flags

View File

@ -0,0 +1,23 @@
class Extended_PreStart_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preStart));
};
};
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_SCRIPT(XEH_postInit));
};
};
class Extended_DisplayLoad_EventHandlers {
class RscDisplayMission {
ADDON = QUOTE(_this call COMPILE_SCRIPT(XEH_missionDisplayLoad));
};
};

View File

@ -0,0 +1,20 @@
class CfgVehicles {
class Man;
class CAManBase: Man {
class ACE_SelfActions {
class ACE_Equipment {
class ADDON {
displayName = CSTRING(action);
condition = QUOTE(_player call FUNC(hasFlag));
insertChildren = QUOTE(_this call FUNC(addActions));
class GVAR(furlFlag) {
displayName = CSTRING(furlFlag);
condition = QUOTE(_player call FUNC(carriesFlag));
statement = QUOTE(_player call FUNC(furlFlag));
};
};
};
};
};
};

View File

@ -0,0 +1,53 @@
class CfgWeapons {
class ACE_ItemCore;
class CBA_MiscItem_ItemInfo;
class GVAR(white): ACE_ItemCore {
scope = 2;
author = ECSTRING(common,ACETeam);
descriptionShort = CSTRING(description);
descriptionUse = CSTRING(description);
displayName = CSTRING(white);
picture = QPATHTOF(data\ui\flags\red_item_icon.paa);
GVAR(texture) = "\a3\data_f\flags\flag_white_co.paa";
GVAR(actionIconPlace) = QPATHTOF(data\ui\flags\white_icon.paa);
GVAR(actionIconCarry) = QPATHTOF(data\ui\flags\white_carry_icon.paa);
class ItemInfo: CBA_MiscItem_ItemInfo {
mass = 3;
};
};
class GVAR(red): GVAR(white) {
displayName = CSTRING(red);
picture = QPATHTOF(data\ui\flags\red_item_icon.paa);
GVAR(texture) = "\a3\data_f\flags\flag_red_co.paa";
GVAR(actionIconPlace) = QPATHTOF(data\ui\flags\red_place_icon.paa);
GVAR(actionIconCarry) = QPATHTOF(data\ui\flags\red_carry_icon.paa);
};
class GVAR(blue): GVAR(white) {
displayName = CSTRING(blue);
picture = QPATHTOF(data\ui\flags\blue_item_icon.paa);
GVAR(texture) = "\a3\data_f\flags\Flag_blue_co.paa";
GVAR(actionIconPlace) = QPATHTOF(data\ui\flags\blue_place_icon.paa);
GVAR(actionIconCarry) = QPATHTOF(data\ui\flags\blue_carry_icon.paa);
};
class GVAR(green): GVAR(white) {
displayName = CSTRING(green);
picture = QPATHTOF(data\ui\flags\green_item_icon.paa);
GVAR(texture) = "\a3\data_f\flags\flag_green_co.paa";
GVAR(actionIconPlace) = QPATHTOF(data\ui\flags\green_place_icon.paa);
GVAR(actionIconCarry) = QPATHTOF(data\ui\flags\green_carry_icon.paa);
};
class GVAR(yellow): GVAR(white) {
displayName = CSTRING(yellow);
picture = QPATHTOF(data\ui\flags\yellow_item_icon.paa);
GVAR(texture) = QPATHTOF(data\Flag_yellow_co.paa);
GVAR(actionIconPlace) = QPATHTOF(data\ui\flags\yellow_place_icon.paa);
GVAR(actionIconCarry) = QPATHTOF(data\ui\flags\yellow_carry_icon.paa);
};
};

4
addons/flags/README.md Normal file
View File

@ -0,0 +1,4 @@
ace_flags
===================
Adds flags feature.

View File

@ -0,0 +1,8 @@
PREP(addActions);
PREP(carriesFlag);
PREP(carryFlag);
PREP(furlFlag);
PREP(getFlags);
PREP(handleScrollWheel);
PREP(pickupFlag);
PREP(placeFlag);

View File

@ -0,0 +1,17 @@
#include "script_component.hpp"
if (!hasInterface) exitWith {};
params ["_display"];
_display displayAddEventHandler ["MouseZChanged", {
params ["", "_scroll"];
[_scroll] call FUNC(handleScrollWheel);
}];
_display displayAddEventHandler ["MouseButtonDown", {
params ["", "_button"];
if (GVAR(isPlacing) isNotEqualTo PLACE_WAITING) exitWith {false};
if (_button isNotEqualTo 1) exitWith {false}; // 1 = Left mouse button
GVAR(isPlacing) = PLACE_CANCEL;
}];

View File

@ -0,0 +1,41 @@
#include "script_component.hpp"
if (!hasinterface) exitWith {};
GVAR(isPlacing) = PLACE_CANCEL;
["ace_interactMenuOpened", {GVAR(isPlacing) = PLACE_CANCEL;}] call CBA_fnc_addEventHandler;
[QGVAR(flagPlaced), {
params ["_unit", "_item", "_flag"];
(GVAR(cache) get _item) params ["_displayName"];
private _pickupFlag = [
QGVAR(pickup),
format [LLSTRING(pickup), _displayName],
QPATHTOF(data\ui\flags\pickup_icon.paa),
{
params ["_flag", "_unit", "_args"];
_args params ["_item"];
[_unit, _item, _flag] call FUNC(pickupFlag);
},
{true},
{},
[_item],
[0, 0, 0],
PICKUP_RADIUS
] call ace_interact_menu_fnc_createAction;
[_flag, 0, [], _pickupFlag] call ace_interact_menu_fnc_addActionToObject;
}] call CBA_fnc_addEventHandler;
private _flagItems = (call (uiNamespace getVariable [QGVAR(allFlagItems), {[]}])) apply {configFile >> "CfgWeapons" >> _x};
{
private _name = configName _x;
private _displayName = getText (_x >> "displayName");
private _texture = getText (_x >> QGVAR(texture));
private _actionIconPlace = getText (_x >> QGVAR(actionIconPlace));
private _actionIconCarry = getText (_x >> QGVAR(actionIconCarry));
GVAR(flagItemCache) set [_name, [_displayName, _texture, _actionIconPlace, _actionIconCarry]];
} forEach _flagItems;

View File

@ -0,0 +1,11 @@
#include "script_component.hpp"
ADDON = false;
PREP_RECOMPILE_START;
#include "XEH_PREP.hpp"
PREP_RECOMPILE_END;
ADDON = true;
GVAR(cache) = createHashMap;

View File

@ -0,0 +1,6 @@
#include "script_component.hpp"
#include "XEH_PREP.hpp"
private _flagItems = (configProperties [configfile >> "CfgWeapons", QUOTE(isClass _x && (isText (_x >> QQGVAR(texture)))), true]) apply {configName _x};
uiNamespace setVariable [QGVAR(allFlagItems), compileFinal str _flagItems];

25
addons/flags/config.cpp Normal file
View File

@ -0,0 +1,25 @@
#include "script_component.hpp"
class CfgPatches {
class ADDON {
name = COMPONENT_NAME;
units[] = {};
weapons[] = {
QGVAR(white),
QGVAR(red),
QGVAR(blue),
QGVAR(green),
QGVAR(yellow)
};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common", "ace_interact_menu", "ace_interaction"};
author = ECSTRING(common,ACETeam);
authors[] = {"Timi007"};
url = ECSTRING(main,URL);
VERSION_CONFIG;
};
};
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -0,0 +1,56 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Adds the child actions for placing and carring flags.
*
* Arguments:
* 0: Player <OBJECT>
*
* Return Value:
* Actions <ARRAY>
*
* Example:
* [player] call ace_flags_fnc_addActions
*
* Public: No
*/
params ["_player"];
private _actions = [];
{
(GVAR(flagItemCache) get _x) params ["_displayName", "_texture", "_actionIconPlace", "_actionIconCarry"];
// Place flag
_actions pushBack [
[
"place_" + _x,
format [LSTRING(place), _displayName],
_actionIconPlace,
{[_this select 0, _this select 2] call FUNC(placeFlag)},
{true},
{},
_x
] call EFUNC(interact_menu,createAction),
[],
_player
];
// Carry flag
_actions pushBack [
[
"carry_" + _x,
format [LSTRING(carry), _displayName],
_actionIconCarry,
{[_this select 0, _this select 2] call FUNC(carryFlag)},
{!([_this select 1] call FUNC(carriesFlag))}, // Should not carry flag already
{},
_x
] call EFUNC(interact_menu,createAction),
[],
_player
];
} forEach ([_player] call FUNC(getFlags));
_actions

View File

@ -0,0 +1,21 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Checks if the unit is carrying a flag.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* True if unit is carrying a flag; otherwise flase <BOOLEAN>
*
* Example:
* [player] call ace_flags_fnc_carriesFlag
*
* Public: No
*/
params ["_unit"];
(_unit getVariable [QGVAR(carryingFlag), ""] isNotEqualTo "") &&
{(getForcedFlagTexture _unit) isNotEqualTo ""}

View File

@ -0,0 +1,37 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Attaches flag to the back of the unit and removes his flag item.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Flag item <STRING>
*
* Return Value:
* Nothing
*
* Example:
* [player, "ace_flags_white"] call ace_flags_fnc_carryFlag
*
* Public: No
*/
params ["_unit", "_item"];
// Arma needs a flag proxy and some modded uniforms don't have them.
// If we temporarily change the uniform to a vanilla one we can work around this problem.
private _loadout = getUnitLoadout _unit;
_unit forceAddUniform "U_B_CombatUniform_mcam";
private _texture = (GVAR(flagItemCache) get _item) param [1, ""];
_unit forceFlagTexture _texture;
// We need to change loadout in the next frame otherwise it will not work
[{
params ["_unit", "_item", "_loadout"];
_unit setUnitLoadout _loadout;
_unit setVariable [QGVAR(carryingFlag), _item, true];
_unit removeItem _item;
}, [_unit, _item, _loadout]] call CBA_fnc_execNextFrame;

View File

@ -0,0 +1,26 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Stops carrying flag and add flag item to unit.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* [player] call ace_flags_fnc_furlFlag
*
* Public: No
*/
params ["_unit"];
// Stop carrying flag and add flag item to unit.
_item = _unit getVariable [QGVAR(carryingFlag), ""];
_unit setVariable [QGVAR(carryingFlag), nil, true];
_unit forceFlagTexture ""; // Remove flag
[_unit, _item] call EFUNC(common,addToInventory);

View File

@ -0,0 +1,20 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Get the placeable and carryable flags in the unit's inventory.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* Flag items <ARRAY>
*
* Example:
* [player] call ace_flags_fnc_getFlags
*
* Public: No
*/
params ["_unit"];
(_unit call EFUNC(common,uniqueItems)) arrayIntersect keys GVAR(flagItemCache)

View File

@ -0,0 +1,33 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Handles the flag object height.
*
* Arguments:
* 0: Scroll amount <NUMBER>
*
* Return Value:
* Handled <BOOLEAN>
*
* Example:
* [5] call ace_flags_fnc_handleScrollWheel
*
* Public: No
*/
params ["_scrollAmount"];
if (GVAR(isPlacing) isNotEqualTo PLACE_WAITING) exitWith {false};
// Move object height 10cm per scroll
GVAR(objectHeight) = GVAR(objectHeight) + (_scrollAmount * 0.1);
if (GVAR(objectHeight) < MIN_HEIGHT) then {
GVAR(objectHeight) = MIN_HEIGHT;
};
if (GVAR(objectHeight) > MAX_HEIGHT) then {
GVAR(objectHeight) = MAX_HEIGHT;
};
true

View File

@ -0,0 +1,30 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Picks up flag and adds item to unit.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Flag item <STRING>
* 2: Flag pole (gets deleted later) <OBJECT>
*
* Return Value:
* Nothing
*
* Example:
* [player] call ace_flags_fnc_pickupFlag
*
* Public: No
*/
params ["_unit", "_item", "_flag"];
[_unit, "PutDown"] call EFUNC(common,doGesture);
[{((animationState _unit) select [25,7]) isEqualTo "putdown"}, {
params ["_unit", "_item", "_flag"];
[_unit, _item] call EFUNC(common,addToInventory);
deleteVehicle _flag;
}, _this] call CBA_fnc_waitUntilAndExecute;

View File

@ -0,0 +1,80 @@
#include "script_component.hpp"
/*
* Author: Timi007
* Starts the placing process of the flag for the player.
* Flags can be placed with the special flag items.
*
* Arguments:
* 0: Player <OBJECT>
* 1: Flag item <STRING>
*
* Return Value:
* Nothing
*
* Example:
* [player, "ace_flags_white"] call ace_flags_fnc_pickupFlag
*
* Public: No
*/
params ["_player", "_item"];
// Create local object
private _flag = "FlagChecked_F" createVehicle [0, 0, 0];
// Set object start height
GVAR(objectHeight) = MIN_HEIGHT;
GVAR(isPlacing) = PLACE_WAITING;
(GVAR(flagItemCache) get _x) params ["_flagName"];
// Add info dialog for the player which show the controls
private _placeFlagText = format [LLSTRING(place), _flagName];
[_placeFlagText, LLSTRING(cancel), LLSTRING(adjustHeight)] call EFUNC(interaction,showMouseHint);
private _mouseClickID = [_player, "DefaultAction", {
GVAR(isPlacing) isEqualTo PLACE_WAITING
}, {
GVAR(isPlacing) = PLACE_APPROVE
}] call EFUNC(common,addActionEventHandler);
[{ // Start of PFH
params ["_args", "_handle"];
_args params ["_player", "_item", "_flag", "_mouseClickID"];
if (isNull _flag || {!([_player, _flag] call EFUNC(common,canInteractWith))}) then {
GVAR(isPlacing) = PLACE_CANCEL;
};
if (GVAR(isPlacing) isNotEqualTo PLACE_WAITING) exitWith {
[_handle] call CBA_fnc_removePerFrameHandler;
call ace_interaction_fnc_hideMouseHint;
[_player, "DefaultAction", _mouseClickID] call EFUNC(common,removeActionEventHandler);
if (GVAR(isPlacing) isEqualTo PLACE_APPROVE) then {
// End position of the object
GVAR(isPlacing) = PLACE_CANCEL;
[_player, "PutDown"] call EFUNC(common,doGesture);
[{(animationState _player select [25, 7]) isEqualTo "putdown"}, {
params ["_player", "_item", "_flag"];
[QGVAR(flagPlaced), [_player, _item, _flag]] call CBA_fnc_globalEventJIP;
[QGVAR(flagPlaced), _flag] call CBA_fnc_removeGlobalEventJIP;
}, [_player, _item, _flag]] call CBA_fnc_waitUntilAndExecute;
} else {
// Action is canceled
deleteVehicle _flag;
};
};
private _pos = ((eyePos _player) vectorAdd ((getCameraViewDirection _player) vectorMultiply FLAG_PLACING_DISTANCE));
// Adjust height of flag with the scroll wheel
_pos set [2, ((getPosWorld _player) select 2) + GVAR(objectHeight)];
_flag setPosWorld _pos;
_flag setDir (getDir _player);
}, 0, [_player, _item, _flag, _mouseClickID]] call CBA_fnc_addPerFrameHandler;

View File

@ -0,0 +1 @@
#include "\z\ace\addons\flags\script_component.hpp"

View File

@ -0,0 +1,28 @@
#define COMPONENT flags
#define COMPONENT_BEAUTIFIED Flags
#include "\z\ace\addons\main\script_mod.hpp"
#define DEBUG_MODE_FULL
#define DISABLE_COMPILE_CACHE
// #define ENABLE_PERFORMANCE_COUNTERS
#ifdef DEBUG_ENABLED_FLAGS
#define DEBUG_MODE_FULL
#endif
#ifdef DEBUG_SETTINGS_FLAGS
#define DEBUG_SETTINGS DEBUG_SETTINGS_FLAGS
#endif
#include "\z\ace\addons\main\script_macros.hpp"
#define PLACE_WAITING -1
#define PLACE_CANCEL 0
#define PLACE_APPROVE 1
#define MIN_HEIGHT -0.5
#define MAX_HEIGHT 2
#define FLAG_PLACING_DISTANCE 2
#define PICKUP_RADIUS 2

View File

@ -0,0 +1,61 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="ACE">
<Package name="Flags">
<Container name="displayNames">
<Key ID="STR_ACE_Flags_white">
<Original>Flag (White)</Original>
<German>Flagge (Weiß)</German>
</Key>
<Key ID="STR_ACE_Flags_red">
<Original>Flag (Red)</Original>
<German>Flagge (Rot)</German>
</Key>
<Key ID="STR_ACE_Flags_blue">
<Original>Flag (Blue)</Original>
<German>Flagge (Blau)</German>
</Key>
<Key ID="STR_ACE_Flags_green">
<Original>Flag (Green)</Original>
<German>Flagge (Grün)</German>
</Key>
<Key ID="STR_ACE_Flags_yellow">
<Original>Flag (Yellow)</Original>
<German>Flagge (Gelb)</German>
</Key>
<Key ID="STR_ACE_Flags_description">
<Original>Can be carried or placed. Flags are used to mark a specific point in terrain or units.</Original>
<German>Kann getragen oder platziert werden. Flaggen werden zur Kennzeichnung von bestimmten Geländepunkte oder Einheiten eingesetzt.</German>
</Key>
</Container>
<Container name="actions">
<Key ID="STR_ACE_Flags_action">
<Original>Flags</Original>
<German>Flaggen</German>
</Key>
<Key ID="STR_ACE_Flags_carry">
<Original>Carry %1</Original>
<German>%1 tragen</German>
</Key>
<Key ID="STR_ACE_Flags_furl">
<Original>Furl Flag</Original>
<German>Flagge einrollen</German>
</Key>
<Key ID="STR_ACE_Flags_place">
<Original>Place %1</Original>
<German>%1 platzieren</German>
</Key>
<Key ID="STR_ACE_Flags_pickup">
<Original>Pickup %1</Original>
<German>%1 aufnehmen</German>
</Key>
<Key ID="STR_ACE_Flags_cancel">
<Original>Cancel</Original>
<German>Abbrechen</German>
</Key>
<Key ID="STR_ACE_Flags_adjustHeight">
<Original>Adjust height</Original>
<German>Höhe anpassen</German>
</Key>
</Container>
</Package>
</Project>