Initial code implementation of ace_trenches

This commit is contained in:
esteldunedain 2016-01-23 20:45:59 -03:00
parent 1d886ac624
commit 8ff8204905
18 changed files with 481 additions and 10 deletions

View File

@ -0,0 +1,20 @@
class Extended_PreInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_preInit));
};
};
class Extended_PostInit_EventHandlers {
class ADDON {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
class Extended_Killed_EventHandlers {
class CAManBase {
class ADDON {
killed = QUOTE(_this call FUNC(handleKilled));
};
};
};

View File

@ -1,4 +1,32 @@
class CfgVehicles {
class Man;
class CAManBase: Man {
class ACE_SelfActions {
class ACE_Equipment {
class GVAR(digEnvelopeSmall) {
displayName = CSTRING(DigEnvelopeSmall);
condition = QUOTE([ARR_2(_this select 0,'ace_trenches_trenchSmall')] call FUNC(canDigTrench));
//wait a frame to handle "Do When releasing action menu key" option
statement = QUOTE([ARR_2({_this call FUNC(placeTrench)},[ARR_2(_this select 0,'ace_trenches_trenchSmall')])] call EFUNC(common,execNextFrame));
exceptions[] = {};
showDisabled = 0;
priority = 4;
//icon = PATHTOF(UI\icon_sandbag_ca.paa);
};
class GVAR(digEnvelopeBig) {
displayName = CSTRING(DigEnvelopeBig);
condition = QUOTE([ARR_2(_this select 0,'ace_trenches_trenchBig')] call FUNC(canDigTrench));
//wait a frame to handle "Do When releasing action menu key" option
statement = QUOTE([ARR_2({_this call FUNC(placeTrench)},[ARR_2(_this select 0,'ace_trenches_trenchBig')])] call EFUNC(common,execNextFrame));
exceptions[] = {};
showDisabled = 0;
priority = 4;
//icon = PATHTOF(UI\icon_sandbag_ca.paa);
};
};
};
};
class BagFence_base_F;
class ACE_envelope_small: BagFence_base_F {
author = ECSTRING(common,ACETeam);
@ -14,4 +42,23 @@ class CfgVehicles {
model = QUOTE(PATHTOEF(apl,ace_envelope_big.p3d));
scope = 2;
};
class ACE_envelope_small_NoGeo: ACE_envelope_small {
scope = 1;
//@todo: replace by a no geo model
model = QUOTE(PATHTOEF(apl,ace_envelope_small.p3d));
};
class ACE_envelope_big_NoGeo: ACE_envelope_big {
scope = 1;
//@todo: replace by a no geo model
model = QUOTE(PATHTOEF(apl,ace_envelope_big.p3d));
};
class Box_NATO_Support_F;
class ACE_Box_Misc: Box_NATO_Support_F {
class TransportItems {
MACRO_ADDITEM(ACE_EntrenchingTool,50);
};
};
};

View File

@ -2,7 +2,7 @@ class CfgWeapons {
class InventoryItem_Base_F;
class ACE_ItemCore;
class ACE_entrenchingtool: ACE_ItemCore {
class ACE_EntrenchingTool: ACE_ItemCore {
author = ECSTRING(common,ACETeam);
displayName = CSTRING(EntrenchingToolName);
descriptionShort = CSTRING(EntrenchingToolDescription);

View File

@ -0,0 +1,27 @@
#include "script_component.hpp"
if (isServer) then {
// Cancel dig on hard disconnection. Function is identical to killed
addMissionEventHandler ["HandleDisconnect", {_this call FUNC(handleKilled)}];
};
if (!hasInterface) exitWith {};
GVAR(trench) = objNull;
GVAR(digPFH) = -1;
GVAR(digDirection) = 0;
[{_this call FUNC(handleScrollWheel)}] call EFUNC(common,addScrollWheelEventHandler);
// Cancel dig sandbag if interact menu opened
["interactMenuOpened", {[ACE_player] call FUNC(handleInteractMenuOpened)}] call EFUNC(common,addEventHandler);
// Cancel dig on player change. This does work when returning to lobby, but not when hard disconnecting.
["playerChanged", {_this call FUNC(handlePlayerChanged)}] call EFUNC(common,addEventhandler);
["playerInventoryChanged", {_this call FUNC(handlePlayerInventoryChanged)}] call EFUNC(common,addEventhandler);
["playerVehicleChanged", {[ACE_player, objNull] call FUNC(handlePlayerChanged)}] call EFUNC(common,addEventhandler);
// handle waking up dragged unit and falling unconscious while dragging
["medical_onUnconscious", {_this call FUNC(handleUnconscious)}] call EFUNC(common,addEventhandler);
//@todo Captivity?

View File

@ -0,0 +1,22 @@
#include "script_component.hpp"
ADDON = false;
PREP(canDigTrench);
PREP(digCancel);
PREP(digConfirm);
PREP(handleInteractMenuOpened);
PREP(handleKilled);
PREP(handlePlayerChanged);
PREP(handlePlayerInventoryChanged);
PREP(handleScrollWheel);
PREP(handleUnconscious);
PREP(placeTrench);
// Trench types
// Name of the object, name of th dummy no geo object, dx, dy
GVAR(trenchSmall) = ["ACE_envelope_small", "ACE_envelope_small_NoGeo", 2, 3, 0.35];
GVAR(trenchBig) = ["ACE_envelope_big", "ACE_envelope_big_NoGeo", 6, 1.1, 0.15];
GVAR(trenchType) = GVAR(trenchSmall);
ADDON = true;

View File

@ -3,13 +3,14 @@
class CfgPatches {
class ADDON {
units[] = {"ACE_envelope_small","ACE_envelope_big"};
weapons[] = {"ACE_entrenchingtool"};
weapons[] = {"ACE_EntrenchingTool"};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_interaction"};
author[] = {"Grey"};
author[] = {"Grey", "esteldunedain"};
authorUrl = "";
VERSION_CONFIG;
};
};
#include "CfgWeapons.hpp"
#include "CfgEventHandlers.hpp"
#include "CfgVehicles.hpp"
#include "CfgWeapons.hpp"

View File

@ -0,0 +1,31 @@
/*
* Author: Ruthberg, commy2, esteldunedain
* Checks if a unit can dig a trench
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Trench type <STRING>
*
* Return Value:
* Can dig <BOOL>
*
* Example:
* [ACE_player] call ace_trenches_fnc_canDigTrench
*
* Public: No
*/
#include "script_component.hpp"
#define SURFACE_BLACKLIST ["water", "concrete", "tarmac", "wood", "metal", "roof_tin", "roof_tiles", "wood_int", "concrete_int", "tiles_int", "metal_int", "stony", "rock", "int_concrete", "int_tiles", "int_wood", "tiling", "wavymetal", "int_metal"]
params ["_unit","_trenchTypeName"];
if !("ACE_EntrenchingTool" in items _unit) exitWith {false};
private ["_surfaceClass", "_surfaceType"];
_surfaceClass = (surfaceType getPosASL _unit) select [1];
_surfaceType = getText (configFile >> "CfgSurfaces" >> _surfaceClass >> "soundEnviron");
TRACE_1("",_surfaceType);
!(_surfaceType in SURFACE_BLACKLIST)

View File

@ -0,0 +1,36 @@
/*
* Author: Garth 'L-H' de Wet, Ruthberg, edited by commy2 for better MP and eventual AI support
* Cancels trench dig
*
* Arguments:
* 0: unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [ACE_player] call ace_sandbag_fnc_digCancel
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit"];
// enable running again
[_unit, "forceWalk", "ACE_Trenches", false] call EFUNC(common,statusEffect_set);
// delete placement dummy
deleteVehicle GVAR(trench);
// remove digment pfh
[GVAR(digPFH)] call CBA_fnc_removePerFrameHandler;
GVAR(digPFH) = -1;
// remove mouse button actions
call EFUNC(interaction,hideMouseHint);
[_unit, "DefaultAction", _unit getVariable [QGVAR(Dig), -1]] call EFUNC(common,removeActionEventHandler);
[_unit, "zoomtemp", _unit getVariable [QGVAR(Cancel), -1]] call EFUNC(common,removeActionEventHandler);
_unit setVariable [QGVAR(isDigging), false, true];

View File

@ -0,0 +1,56 @@
/*
* Author: Garth 'L-H' de Wet, Ruthberg, edited by commy2 for better MP and eventual AI support and esteldunedain
* Confirms trench dig
*
* Arguments:
* 0: unit <OBJECT>
*
* Return Value:
* None
*
* Example:
* [ACE_player] call ace_trenches_fnc_digConfirm
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit"];
// enable running again
[_unit, "forceWalk", "ACE_Trenches", false] call EFUNC(common,statusEffect_set);
// delete placement dummy and create real trench
[{
if (isNull GVAR(trench)) exitWith {};
params ["_unit"];
private ["_position", "_direction", "_trench"];
_position = getPosASL GVAR(trench);
_direction = getDir GVAR(trench);
deleteVehicle GVAR(trench);
_trench = createVehicle [GVAR(trenchType) select 0, [0, 0, 0], [], 0, "NONE"];
_trench setPosASL _position;
_trench setDir _direction;
GVAR(trench) = objNull;
}, [_unit], 1] call EFUNC(common,waitAndExecute);
// remove dig pfh
[GVAR(digPFH)] call CBA_fnc_removePerFrameHandler;
GVAR(digPFH) = -1;
// remove mouse button actions
call EFUNC(interaction,hideMouseHint);
[_unit, "DefaultAction", _unit getVariable [QGVAR(Dig), -1]] call EFUNC(common,removeActionEventHandler);
[_unit, "zoomtemp", _unit getVariable [QGVAR(Cancel), -1]] call EFUNC(common,removeActionEventHandler);
// play animation
_unit playActionNow "PutDown";
_unit setVariable [QGVAR(isDigging), false, true];

View File

@ -0,0 +1,19 @@
/*
* Author: commy2
* Handle opening of interaction menu.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit"];
if (_unit getVariable [QGVAR(isDigging), false]) then {
[_unit] call FUNC(digCancel);
};

View File

@ -0,0 +1,19 @@
/*
* Author: commy2
* Handle death.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit"];
if (_unit getVariable [QGVAR(isDigging), false]) then {
[_unit] call FUNC(digCancel);
};

View File

@ -0,0 +1,24 @@
/*
* Author: commy2
* Handle player changes.
*
* Arguments:
* 0: New Player Unit <OBJECT>
* 1: Old Player Unit <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params ["_newPlayer", "_oldPlayer"];
if (_newPlayer getVariable [QGVAR(isDigging), false]) then {
[_newPlayer] call FUNC(digCancel);
};
if (_oldPlayer getVariable [QGVAR(isDigging), false]) then {
[_oldPlayer] call FUNC(digCancel);
};

View File

@ -0,0 +1,22 @@
/*
* Author: commy2
* Handle the InventoryChanged event.
*
* Arguments:
* 0: Unit <OBJECT>
* 1: Weapon <STRING>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit"];
if (_unit getVariable [QGVAR(isDigging), false]) then {
if !("ACE_EntrenchingTool" in items _unit) then {
[_unit] call FUNC(digCancel);
};
};

View File

@ -0,0 +1,24 @@
/*
* Author: Garth 'L-H' de Wet, Ruthberg
* Handles sandbag rotation
*
* Arguments:
* 0: scroll amount <NUMBER>
*
* Return Value:
* handled <BOOL>
*
* Example:
* [1.2] call ace_sandbag_fnc_handleScrollWheel
*
* Public: No
*/
#include "script_component.hpp"
params ["_scroll"];
if (GETMVAR(ACE_Modifier,0) == 0 || GVAR(digPFH) == -1) exitWith { false };
GVAR(digDirection) = GVAR(digDirection) + (_scroll * 5);
true

View File

@ -0,0 +1,19 @@
/*
* Author: commy2
* Handle unconsciousness.
*
* Arguments:
* 0: Unit <OBJECT>
*
* Return Value:
* None
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit"];
if (_unit getVariable [QGVAR(isDigging), false]) then {
[_unit] call FUNC(digCancel);
};

View File

@ -0,0 +1,88 @@
/*
* Author: Garth 'L-H' de Wet, Ruthberg, edited by commy2 for better MP and eventual AI support, esteldunedain
* Starts the place process for trench.
*
* Arguments:
* 0: unit <OBJECT>
* 1: Trench type <STRING>
*
* Return Value:
* None
*
* Example:
* [ACE_player] call ace_trenches_fnc_placeTrench
*
* Public: No
*/
#include "script_component.hpp"
params ["_unit","_trenchTypeName"];
GVAR(trenchType) = missionNamespace getVariable _trenchTypeName;
TRACE_2("",_trenchTypeName,GVAR(trenchType));
// prevent the placing unit from running
[_unit, "forceWalk", "ACE_Trenches", true] call EFUNC(common,statusEffect_set);
// create the trench
private "_trench";
_trench = createVehicle [GVAR(trenchType) select 1, [0, 0, 0], [], 0, "NONE"];
GVAR(trench) = _trench;
// prevent collisions with trench
["enableSimulationGlobal", [_trench, false]] call EFUNC(common,serverEvent);
GVAR(digDirection) = 0;
// pfh that runs while the dig is in progress
GVAR(digPFH) = [{
(_this select 0) params ["_unit", "_trench"];
if (isNull _trench) exitWith {
[_unit] call FUNC(digCancel);
};
private _basePos = eyePos _unit vectorAdd (positionCameraToWorld [0, 0, 2] vectorDiff positionCameraToWorld [0, 0, 0]);
private _angle = (GVAR(digDirection) + getDir _unit);
// Stick the trench to the ground
GVAR(trenchType) params ["", "", "_dx", "_dy", "_offset"];
private _minz = (getTerrainHeightASL _basePos);
private ["_ix","_iy"];
for [{_ix = -_dx/2},{_ix <= _dx/2},{_ix = _ix + _dx/3}] do {
for [{_iy = -_dy/2},{_iy <= _dy/2},{_iy = _iy + _dy/3}] do {
private _pos = _basePos vectorAdd ([cos _angle, -sin _angle, 0] vectorMultiply _ix)
vectorAdd ([sin _angle, +cos _angle, 0] vectorMultiply _iy);
_minz = _minz min (getTerrainHeightASL _pos);
#ifdef DEBUG_MODE_FULL
_pos set [2, getTerrainHeightASL _pos];
_pos2 = +_pos;
_pos2 set [2, getTerrainHeightASL _pos+2];
drawLine3D [ASLtoAGL _pos, ASLtoAGL _pos2, [1,1,0,1]];
#endif
};
};
_basePos set [2, _minz + _offset];
_trench setPosASL _basePos;
_trench setDir _angle;
}, 0, [_unit, _trench]] call CBA_fnc_addPerFrameHandler;
// add mouse button action and hint
[localize LSTRING(ConfirmDig), localize LSTRING(CancelDig), localize LSTRING(ScrollAction)] call EFUNC(interaction,showMouseHint);
_unit setVariable [QGVAR(Dig), [
_unit, "DefaultAction",
{GVAR(digPFH) != -1},
{[_this select 0] call FUNC(digConfirm)}
] call EFUNC(common,addActionEventHandler)];
_unit setVariable [QGVAR(Cancel), [
_unit, "zoomtemp",
{GVAR(digPFH) != -1},
{[_this select 0] call FUNC(digCancel)}
] call EFUNC(common,addActionEventHandler)];
_unit setVariable [QGVAR(isDigging), true, true];

View File

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

View File

@ -1,25 +1,40 @@
<?xml version="1.0" encoding="utf-8"?>
<Project name="ACE">
<Package name="trenches">
<Key ID="STR_ACE_trenches_EntrenchingToolName">
<Key ID="STR_ACE_Trenches_EntrenchingToolName">
<English>Entrenching Tool</English>
<Polish>Saperka</Polish>
</Key>
<Key ID="STR_ACE_trenches_EntrenchingToolDescription">
<Key ID="STR_ACE_Trenches_EntrenchingToolDescription">
<English>Entrenching Tool</English>
<Polish>Saperka, używana do budowy okopów</Polish>
</Key>
<Key ID="STR_ACE_trenches_EnvelopeSmallName">
<Key ID="STR_ACE_Trenches_EnvelopeSmallName">
<English>Envelope - Small</English>
</Key>
<Key ID="STR_ACE_trenches_EnevlopeSmallDescription">
<Key ID="STR_ACE_Trenches_EnevlopeSmallDescription">
<English>Small Personal Trench</English>
</Key>
<Key ID="STR_ACE_trenches_EnvelopeBigName">
<Key ID="STR_ACE_Trenches_DigEnvelopeSmall">
<English>Dig Small Trench</English>
</Key>
<Key ID="STR_ACE_Trenches_EnvelopeBigName">
<English>Envelope - Big</English>
</Key>
<Key ID="STR_ACE_trenches_EnevlopeBigDescription">
<Key ID="STR_ACE_Trenches_EnevlopeBigDescription">
<English>Large Personal Trench</English>
</Key>
<Key ID="STR_ACE_Trenches_DigEnvelopeBig">
<English>Dig Big Trench</English>
</Key>
<Key ID="STR_ACE_Trenches_ConfirmDig">
<English>Confirm Dig</English>
</Key>
<Key ID="STR_ACE_Trenches_CancelDig">
<English>Cancel Dig</English>
</Key>
<Key ID="STR_ACE_Trenches_ScrollAction">
<English>+Ctrl rotate</English>
</Key>
</Package>
</Project>