Initial port of old pull

Still some problem with interaction...
This commit is contained in:
PabstMirror 2015-01-30 14:32:21 -06:00
parent e5f02f8d63
commit 08763b6b9f
10 changed files with 335 additions and 79 deletions

View File

@ -1,17 +1,59 @@
#define MACRO_ADDITEM(ITEM,COUNT) class _xx_##ITEM { \
name = #ITEM; \
count = COUNT; \
};
name = #ITEM; \
count = COUNT; \
};
#define MACRO_ATTACHTOVEHICLE \
class ACE_Actions { \
class GVAR(AttachVehicle) { \
displayName = "$STR_ACE_Attach_AttachDetach"; \
condition = QUOTE( [ARR_3(_player, _target, '')] call FUNC(canAttach) ); \
statement = QUOTE( [ARR_2(_player, _target)] call FUNC(openAttachUI); ); \
exceptions[] = {"ACE_Drag_isNotDragging"}; \
showDisabled = 0; \
priority = 0; \
icon = PATHTOF(UI\attach_ca.paa); \
hotkey = "T"; \
}; \
class GVAR(DetachVehicle) { \
displayName = "$STR_ACE_Attach_Detach"; \
condition = QUOTE( [ARR_2(_player, _target)] call FUNC(canDetach) ); \
statement = QUOTE( [ARR_2(_player, _target)] call FUNC(detach) ); \
exceptions[] = {"ACE_Drag_isNotDragging"}; \
showDisabled = 0; \
priority = 0; \
icon = PATHTOF(UI\detach_ca.paa); \
}; \
};
class CfgVehicles {
class LandVehicle;
class Car: LandVehicle {
MACRO_ATTACHTOVEHICLE
};
class Tank: LandVehicle {
MACRO_ATTACHTOVEHICLE
};
class Air;
class Helicopter: Air {
MACRO_ATTACHTOVEHICLE
};
class Plane: Air {
MACRO_ATTACHTOVEHICLE
};
class Ship;
class Ship_F: Ship {
MACRO_ATTACHTOVEHICLE
};
class Man;
class CAManBase: Man {
class ACE_SelfActions {
class ACE_Equipment {
class GVAR(Attach) {
displayName = "$STR_ACE_Attach_AttachDetach";
condition = QUOTE( [_player, ''] call FUNC(canAttach) );
statement = QUOTE( [_player] call FUNC(openAttachUI); );
condition = QUOTE( [ARR_3(_player, _player, '')] call FUNC(canAttach) );
statement = QUOTE( [ARR_2(_player, _player)] call FUNC(openAttachUI); );
exceptions[] = {"ACE_Drag_isNotDragging"};
showDisabled = 0;
priority = 5;
@ -20,8 +62,8 @@ class CfgVehicles {
};
class GVAR(Detach) {
displayName = "$STR_ACE_Attach_Detach";
condition = QUOTE( [_player] call FUNC(canDetach) );
statement = QUOTE( [_player] call FUNC(detach) );
condition = QUOTE( [ARR_2(_player, _player)] call FUNC(canDetach) );
statement = QUOTE( [ARR_2(_player, _player)] call FUNC(detach) );
exceptions[] = {"ACE_Drag_isNotDragging"};
showDisabled = 0;
priority = 5;

View File

@ -7,5 +7,7 @@ PREP(canAttach);
PREP(canDetach);
PREP(detach);
PREP(openAttachUI);
PREP(placeApprove);
PREP(placeCancel);
ADDON = true;

View File

@ -6,57 +6,79 @@ Author: eRazeri and CAA-Picard
Attach an item to the unit
Arguments:
0: unit
1: Item name
0: OBJECT - unit doing the attaching (player)
1: OBJECT - vehicle that it will be attached to (player or vehicle)
2: STRING - classname of attached item (from CfgMagazines or CfgWeapons)
Return Value:
none
*/
private ["_unit", "_itemName", "_attachedItem"];
PARAMS_3(_unit,_attachToVehicle,_itemName);
_unit = _this select 0;
_itemName = _this select 1;
//Sanity Check (_unit has item in inventory, not over attach limit)
if (!([_unit,_attachToVehicle,_itemName] call FUNC(canAttach))) exitWith {ERROR("Tried to attach, but check failed");};
// Check if unit has an attached item
if (_unit getVariable [QGVAR(ItemName), ""] != "") exitWith {};
_selfAttachPosition = [_unit, [-0.05,0,0.12], "rightshoulder"];
_itemVehClass = "";
_onAtachText = "";
// Check if the unit still has the item
if !((_itemName in items _unit) or (_itemName in magazines _unit)) exitWith {};
// Attach item
switch true do {
case (_itemName == "ACE_IR_Strobe_Item") : {
_attachedItem = "ACE_IR_Strobe_Effect" createVehicle [0,0,0];
_attachedItem attachTo [_unit,[0,-0.11,0.16],"pilot"];//makes it attach to the head a bit better, shoulder is not good for visibility - eRazeri
[localize "STR_ACE_Attach_IrStrobe_Attached"] call EFUNC(common,displayTextStructured);
case (_itemName == "ACE_IR_Strobe_Item"): {
_itemVehClass = "ACE_IR_Strobe_Effect";
_onAtachText = localize "STR_ACE_Attach_IrStrobe_Attached";
_selfAttachPosition = [_unit,[0,-0.11,0.16],"pilot"]; //makes it attach to the head a bit better, shoulder is not good for visibility - eRazeri
};
case (_itemName == "B_IR_Grenade") : {
_attachedItem = "B_IRStrobe" createVehicle [0,0,0];
_attachedItem attachTo [_unit,[-0.05,0,0.12],"rightshoulder"];
[localize "STR_ACE_Attach_IrGrenade_Attached"] call EFUNC(common,displayTextStructured);
case (_itemName == "B_IR_Grenade"): {
_itemVehClass = "B_IRStrobe";
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
};
case (_itemName == "O_IR_Grenade") : {
_attachedItem = "O_IRStrobe" createVehicle [0,0,0];
_attachedItem attachTo [_unit,[-0.05,0,0.12],"rightshoulder"];
[localize "STR_ACE_Attach_IrGrenade_Attached"] call EFUNC(common,displayTextStructured);
case (_itemName == "O_IR_Grenade"): {
_itemVehClass = "O_IRStrobe";
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
};
case (_itemName == "I_IR_Grenade") : {
_attachedItem = "I_IRStrobe" createVehicle [0,0,0];
_attachedItem attachTo [_unit,[-0.05,0,0.12],"rightshoulder"];
[localize "STR_ACE_Attach_IrGrenade_Attached"] call EFUNC(common,displayTextStructured);
case (_itemName == "I_IR_Grenade"): {
_itemVehClass = "I_IRStrobe";
_onAtachText = localize "STR_ACE_Attach_IrGrenade_Attached";
};
case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}) : {
_attachedItem = _itemName createVehicle [0,0,0];
_attachedItem attachTo [_unit,[-0.05,0,0.12],"rightshoulder"];
[localize "STR_ACE_Attach_Chemlight_Attached"] call EFUNC(common,displayTextStructured);;
};
default {
if (true) exitWith {};
case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}): {
_itemVehClass = _itemName;
_onAtachText = localize "STR_ACE_Attach_Chemlight_Attached";
};
};
// Remove item
_unit removeItem _itemName;
_unit setVariable [QGVAR(ItemName), _itemName, true];
_unit setVariable [QGVAR(Item), _attachedItem, true];
if (_itemVehClass == "") exitWith {ERROR("no _itemVehClass for Item");};
if (_unit == _attachToVehicle) then { //Self Attachment
_unit removeItem _itemName; // Remove item
_attachedItem = _itemVehClass createVehicle [0,0,0];
_attachedItem attachTo _selfAttachPosition;
[_onAtachText] call EFUNC(common,displayTextStructured);
_attachToVehicle setVariable ["ACE_AttachedObjects", [_attachedItem], true];
_attachToVehicle setVariable ["ACE_AttachedItemNames", [_itemName], true];
} else {
GVAR(setupObject) = _itemVehClass createVehicleLocal [0,0,-10000];
GVAR(setupObject) enableSimulationGlobal false;
GVAR(SetupPlacmentText) = _onAtachText;
GVAR(SetupPlacmentItem) = _itemName;
GVAR(SetupAttachVehicle) = _attachToVehicle;
GVAR(placer) = _unit;
[_unit, QGVAR(vehAttach), true] call EFUNC(common,setForceWalkStatus);
[QGVAR(PlacementEachFrame),"OnEachFrame", {
private "_player";
_player = ACE_player;
//Stop if player switch or player gets to far from vehicle
if ((GVAR(placer) != _player) || ((_player distance GVAR(SetupAttachVehicle)) > 9)) exitWith {
call FUNC(placeCancel);
};
GVAR(pfeh_running) = true;
_pos = (ASLtoATL eyePos _player) vectorAdd (positionCameraToWorld [0,0,1] vectorDiff positionCameraToWorld [0,0,0]);
GVAR(setupObject) setPosATL _pos;
}] call BIS_fnc_addStackedEventHandler;
//had to spawn the mouseHint, not sure why
[localize "STR_ACE_Attach_PlaceAction", localize "STR_ACE_Attach_CancelAction"] call EFUNC(interaction,showMouseHint);
_unit setVariable [QGVAR(placeActionEH), [_unit, "DefaultAction", {GVAR(pfeh_running) AND !isNull (GVAR(setupObject))}, {call FUNC(placeApprove);}] call EFUNC(common,AddActionEventHandler)];
_unit setVariable [QGVAR(cancelActionEH), [_unit, "MenuBack", {GVAR(pfeh_running) AND !isNull (GVAR(setupObject))}, {call FUNC(placeCancel);}] call EFUNC(common,AddActionEventHandler)];
};

View File

@ -13,9 +13,9 @@
* Boolean (Bool)
*/
private ["_unit", "_item"];
PARAMS_3(_unit,_attachToVehicle,_item);
_unit = _this select 0;
_item = _this select 1;
_attachLimit = if (_unit == _attachToVehicle) then {1} else {10};
_attachedObjects = _attachToVehicle getVariable ["ACE_AttachedObjects", []];
canStand _unit && {_unit getVariable [QGVAR(ItemName), ""] == ""} && {_item in (magazines _unit + items _unit + [""])}
canStand _unit && {alive _attachToVehicle} && {(count _attachedObjects) < _attachLimit} && {_item in (magazines _unit + items _unit + [""])}

View File

@ -1,19 +1,35 @@
#include "script_component.hpp"
/*
* Author: commy2
*
* Check if a unit has an item attached and if it can remove that item.
*
* Argument:
* 0: Unit that wants to detach something (Object)
*
* Return value:
* Boolean (Bool)
*/
* Author: commy2
*
* Check if a unit has an item attached and if it can remove that item.
*
* Argument:
* 0: Unit that wants to detach something (Object)
*
* Return value:
* Boolean (Bool)
*/
private "_unit";
private ["_attachedObjects", "_inRange", "_unitPos", "_objectPos"];
_unit = _this select 0;
PARAMS_2(_unit,_attachToVehicle);
canStand _unit && {_unit getVariable [QGVAR(ItemName), ""] != ""}
_attachedObjects = _attachToVehicle getVariable ["ACE_AttachedObjects", []];
_inRange = false;
if (_unit == _attachToVehicle) then {
_inRange = (count _attachedObjects) > 0;
} else {
//Scan if unit is within range (using 2d distance)
_unitPos = getPos _unit;
_unitPos set [2,0];
{
_objectPos = getPos _x;
_objectPos set [2, 0];
if ((_objectPos distance _unitPos) < 2.4) exitWith {_inRange = true};
} forEach _attachedObjects;
};
(canStand _unit) && _inRange && {alive _attachToVehicle}

View File

@ -12,14 +12,34 @@ Return Value:
none
*/
private ["_unit", "_itemName", "_count", "_attachedItem", "_fnc_detachDelay"];
private ["_itemName", "_count", "_attachedItem", "_fnc_detachDelay"];
_unit = _this select 0;
_itemName = _unit getVariable [QGVAR(ItemName), ""];
_attachedItem = _unit getVariable [QGVAR(Item), objNull];
PARAMS_2(_unit, _attachToVehicle);
_attachedObjectsArray = _attachToVehicle getVariable ["ACE_AttachedObjects", []];
_attachedItemsArray = _attachToVehicle getVariable ["ACE_AttachedItemNames", []];
_attachedObject = objNull;
_attachedIndex = -1;
_itemName = "";
//Find closest attached object
_minDistance = 1000;
_unitPos = getPos _unit;
_unitPos set [2,0];
{
_objectPos = getPos _x;
_objectPos set [2, 0];
if ((_objectPos distance _unitPos) < _minDistance) then {
_minDistance = (_objectPos distance _unitPos);
_attachedObject = _x;
_itemName = _attachedItemsArray select _forEachIndex;
_attachedIndex = _forEachIndex;
};
} forEach _attachedObjectsArray;
// Check if unit has an attached item
if (_itemName == "") exitWith {};
if ((isNull _attachedObject) || {_itemName == ""}) exitWith {ERROR("Could not find attached object")};
// Add item to inventory
_count = (count items _unit) + (count magazines _unit);
@ -30,21 +50,23 @@ if ((count items _unit) + (count magazines _unit) <= _count) exitWith {
if (_itemName == "B_IR_Grenade" or _itemName == "O_IR_Grenade" or _itemName == "I_IR_Grenade") then {
// Hack for dealing with X_IR_Grenade effect not dissapearing on deleteVehicle
detach _attachedItem;
_attachedItem setPos [getPos _unit select 0, getPos _unit select 1, ((getPos _unit select 2) - 1000)];
detach _attachedObject;
_attachedObject setPos [getPos _unit select 0, getPos _unit select 1, ((getPos _unit select 2) - 1000)];
// Delete attached item after 0.5 seconds
_fnc_detachDelay = {
deleteVehicle (_this select 0);
};
[_fnc_detachDelay, [_attachedItem], 0.5, 0] call EFUNC(common,waitAndExecute);
[_fnc_detachDelay, [_attachedObject], 0.5, 0] call EFUNC(common,waitAndExecute);
} else {
// Delete attached item
deleteVehicle _attachedItem;
deleteVehicle _attachedObject;
};
// Reset unit variables
_unit setVariable [QGVAR(ItemName),"", true];
_unit setVariable [QGVAR(Item),nil, true];
_attachedObjectsArray deleteAt _attachedIndex;
_attachedItemsArray deleteAt _attachedIndex;
_attachToVehicle setVariable ["ACE_AttachedObjects", _attachedObjectsArray, true];
_attachToVehicle setVariable ["ACE_AttachedItemNames", _attachedItemsArray, true];
// Display message
switch true do {
@ -57,7 +79,4 @@ switch true do {
case (_itemName == "Chemlight_blue" or {_itemName == "Chemlight_green"} or {_itemName == "Chemlight_red"} or {_itemName == "Chemlight_yellow"}) : {
[localize "STR_ACE_Attach_Chemlight_Detached"] call EFUNC(common,displayTextStructured);
};
default {
if (true) exitWith {};
};
};

View File

@ -8,6 +8,7 @@
Parameters:
0: OBJECT - unit
0: OBJECT - target
Returns:
Nothing
@ -15,8 +16,11 @@
Example:
[player] call ACE_Attach_fnc_openAttachUI;
*/
private ["_unit", "_actions", "_attachables", "_item"];
_unit = _this select 0;
private ["_actions", "_attachables", "_item"];
PARAMS_2(_unit,_target);
GVAR(attachTarget) = _target;
_listed = [];
_attachables = magazines _unit;
_actions = [localize "STR_ACE_Attach_AttachDetach", localize "STR_ACE_Attach_Attach"] call EFUNC(interaction,prepareSelectMenu);
@ -53,7 +57,7 @@ _attachables = items _unit;
[
_actions,
{
[ACE_player, _this] call FUNC(attach);
[ACE_player, GVAR(attachTarget), _this] call FUNC(attach);
call EFUNC(interaction,hideMenu);
},
{

View File

@ -0,0 +1,87 @@
/*
Name: FUNC(placeApprove)
Author(s):
Pabst Mirror (based on Explosive attach by Garth de Wet (LH))
Description:
Approves placement of the lightObject, releases the placement object for it to settle in a location
Parameters:
Nothing
Returns:
Nothing
Example:
call FUNC(placeApprove);
*/
#include "script_component.hpp"
private ["_setupObject", "_setupClassname", "_itemClassname", "_placementText", "_attachToVehicle", "_player", "_position0", "_closeInRatio", "_offset", "_keepGoingCloser", "_pos0temp", "_position1", "_attachedObject", "_currentObjects", "_currentItemNames"];
if (GVAR(pfeh_running)) then {
[QGVAR(PlacementEachFrame),"OnEachFrame"] call BIS_fnc_removeStackedEventHandler;
GVAR(pfeh_running) = false;
};
_setupObject = GVAR(setupObject);
_setupClassname = typeOf _setupObject;
_itemClassname = GVAR(SetupPlacmentItem);
_placementText = GVAR(SetupPlacmentText);
_attachToVehicle = GVAR(SetupAttachVehicle);
GVAR(SetupPlacmentItem) = "";
GVAR(SetupPlacmentText) = "";
GVAR(setupObject) = objNull;
GVAR(SetupAttachVehicle) = objNull;
[GVAR(placer), QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
GVAR(placer) = objNull;
_player = ACE_player;
[_player, "DefaultAction", _player getVariable [QGVAR(placeActionEH), -1]] call EFUNC(common,removeActionEventHandler);
[_player, "MenuBack", _player getVariable [QGVAR(cancelActionEH), -1]] call EFUNC(common,removeActionEventHandler);
call EFUNC(interaction,hideMouseHint);
//A player can release the attachObject with it floating in mid-air.
//This will use lineIntersectsWith to scan towards the center of the vehicle to find a collision
//ArmA's collision detection is of couse terrible and often misses collisions (difference between what we see and collision LOD)
//So it does multiple scans at slighly different angles
//This is VERY computationaly intensive, but doesn't happen that often.
_position0 = getPosAtl _setupObject;
_closeInRatio = 1;
_offset = _attachToVehicle worldToModel _position0;
_keepGoingCloser = true;
while {_keepGoingCloser} do {
_closeInRatio = _closeInRatio - 0.004;
if (_closeInRatio <= 0) exitWith {};
{
_pos0temp = _position0 vectorAdd _x;
{
_position1 = [(_offset select 0) * _closeInRatio, (_offset select 1) * _closeInRatio, (_offset select 2)];
_position1 = _attachToVehicle modelToWorld _position1;
_position1 = _position1 vectorAdd _x;
//Uncomment to see the lazor show, and see how the scanning works:
// drawLine3D [_pos0temp, _position1, [1,0,0,1]];
if (_attachToVehicle in lineIntersectsWith [(ATLToASL _pos0temp), (ATLToASL _position1), player, _setupObject]) exitWith {_keepGoingCloser = false};
} forEach [[0,0,0], [0,0,0.075], [0,0,-0.075], [0,0.075,0], [0,-0.075,0], [0.075,0,0], [-.075,0,0]];
} forEach [[0,0,0], [0,0,0.075], [0,0,-0.075]];
};
//Move it out slightly, for visability sake (better to look a little funny than be embedded//sunk in the hull)
_closeInRatio = (_closeInRatio + 0.006) min 1;
//Delete Local Placement Object
deleteVehicle _setupObject;
//Create New 'real' Object
_attachedObject = _setupClassname createVehicle (getPos _player);
_attachedObject attachTo [_attachToVehicle, [(_offset select 0) * _closeInRatio, (_offset select 1) * _closeInRatio, (_offset select 2)]];
//Remove Item from inventory
_player removeItem _itemClassname;
//Add Object to ACE_AttachedObjects and ACE_AttachedItemNames
_currentObjects = _attachToVehicle getVariable ["ACE_AttachedObjects", []];
_currentObjects pushBack _attachedObject;
_attachToVehicle setVariable ["ACE_AttachedObjects", _currentObjects, true];
_currentItemNames = _attachToVehicle getVariable ["ACE_AttachedItemNames", []];
_currentItemNames pushBack _itemClassname;
_attachToVehicle setVariable ["ACE_AttachedItemNames", _currentItemNames, true];
[_placementText] call EFUNC(common,displayTextStructured);

View File

@ -0,0 +1,42 @@
/*
Name: FUNC(placeCancel)
Author(s):
Pabst Mirror (based on Explosive attach by Garth de Wet (LH))
Description:
Cancels placement of the lightObject
Parameters:
Nothing
Returns:
Nothing
Example:
call FUNC(placeCancel);
*/
#include "script_component.hpp"
if (GVAR(pfeh_running)) then {
[QGVAR(PlacementEachFrame),"OnEachFrame"] call BIS_fnc_removeStackedEventHandler;
GVAR(pfeh_running) = false;
};
if (!isNull (GVAR(setupObject))) then {
deleteVehicle GVAR(setupObject);
};
GVAR(SetupPlacmentItem) = "";
GVAR(SetupPlacmentText) = "";
GVAR(setupObject) = objNull;
GVAR(SetupAttachVehicle) = objNull;
if (isNil QGVAR(placer)) then {
ERROR("Nil placer?");
GVAR(placer) = objNull;
};
[GVAR(placer), QGVAR(vehAttach), false] call EFUNC(common,setForceWalkStatus);
call EFUNC(interaction,hideMouseHint);
[GVAR(placer), "DefaultAction", GVAR(placer) getVariable [QGVAR(placeActionEH), -1]] call EFUNC(common,removeActionEventHandler);
[GVAR(placer), "MenuBack", GVAR(placer) getVariable [QGVAR(cancelActionEH), -1]] call EFUNC(common,removeActionEventHandler);
GVAR(placer) = objNull;

View File

@ -146,5 +146,27 @@
<Hungarian>Az infravörös jeladóval megjelölheted a helyzetedet úgy, hogy annak pulzáló fénye csak éjjellátó készülékkel látható.</Hungarian>
<Russian>ИК строб позволяет сигнализировать свое местоположение через пульсирующий маяк, видимый только через ПНВ.</Russian>
</Key>
<Key ID="STR_ACE_Attach_PlaceAction">
<English>Place</English>
<German>Platzieren</German>
<Spanish>Colocar</Spanish>
<Polish>Umieść</Polish>
<French>Placer</French>
<Czech>Položit</Czech>
<Portuguese>Colocar</Portuguese>
<Italian>Posiziona</Italian>
<Hungarian>Elhelyez</Hungarian>
</Key>
<Key ID="STR_ACE_Attach_CancelAction">
<English>Cancel</English>
<German>Abbrechen</German>
<Spanish>Cancelar</Spanish>
<Polish>Anuluj</Polish>
<French>Annuler</French>
<Czech>Zrušit</Czech>
<Portuguese>Cancelar</Portuguese>
<Italian>Annulla</Italian>
<Hungarian>Mégse</Hungarian>
</Key>
</Package>
</Project>