replace wheel logic

This commit is contained in:
commy2 2015-03-29 11:01:23 +02:00
parent f231b2b14c
commit 54c9cadf38
7 changed files with 116 additions and 6 deletions

View File

@ -8,6 +8,7 @@ PREP(canRepair);
PREP(canReplaceWheel);
PREP(doRemoveWheel);
PREP(doRepair);
PREP(doReplaceWheel);
PREP(getWheelHitPointsWithSelections);
PREP(normalizeHitPoints);
PREP(removeWheel);

View File

@ -21,4 +21,16 @@ _hitPoint = _this select 2;
if !([_unit, _target, []] call EFUNC(common,canInteractWith)) exitWith {false};
// check for a near wheel
private "_wheel";
_wheel = objNull;
{
if ([_unit, _x, ["isNotDragging", "isNotCarrying"]] call EFUNC(common,canInteractWith)) exitWith {
_wheel = _x;
};
} forEach nearestObjects [_unit, ["ACE_Wheel"], 5];
if (isNull _wheel) exitWith {false};
alive _target && {_target getHitPointDamage _hitPoint >= 1}

View File

@ -13,9 +13,9 @@
private ["_unit", "_vehicle", "_hitPoint"];
_unit = _this select 0 select 0;
_vehicle = _this select 0 select 1;
_hitPoint = _this select 0 select 2;
_unit = _this select 0;
_vehicle = _this select 1;
_hitPoint = _this select 2;
// get current hitpoint damage
private "_hitPointDamage";

View File

@ -0,0 +1,45 @@
/*
* Author: commy2
*
* Called by repair action / progress bar. Raise events to set the new hitpoint damage.
*
* Arguments:
* Stuff from progress bar.
*
* Return Value:
* NONE
*/
#include "script_component.hpp"
private ["_unit", "_vehicle", "_hitPoint", "_wheel"];
_unit = _this select 0;
_vehicle = _this select 1;
_hitPoint = _this select 2;
_wheel = _this select 3;
// get current hitpoint damage
private "_hitPointDamage";
_hitPointDamage = _vehicle getHitPointDamage _hitPoint;
// can't replace not destroyed wheel
if (_hitPointDamage < 1) exitWith {};
// don't die by spawning / moving the wheel
_hitPointDamage = damage _wheel;
// can't replace a destroyed wheel
if (_hitPointDamage >= 1) exitWith {};
deleteVehicle _wheel;
// raise event to set the new hitpoint damage
["setWheelHitPointDamage", _vehicle, [_vehicle, _hitPoint, _hitPointDamage]] call EFUNC(common,targetEvent);
// display text message if enabled
if (GVAR(DisplayTextOnRepair)) then {
private "_text";
_text = "WHEEL REMPLACED";
[_text] call EFUNC(common,displayTextStructured);
};

View File

@ -31,7 +31,7 @@ private "_text";
_text = "REMOVE WHEEL";
// open the loading bar
[_time, [_unit, _vehicle, _hitPoint], DFUNC(doRemoveWheel), {hint "abort"}, _text, {true}, []] call EFUNC(common,progressBar);
[_time, [_unit, _vehicle, _hitPoint], {(_this select 0) call DFUNC(doRemoveWheel)}, {hint "abort"}, _text, {true}, []] call EFUNC(common,progressBar);
// do animation
[_unit] call EFUNC(common,goKneeling);

View File

@ -40,7 +40,7 @@ if (isLocalized _text) then {
};
// open the loading bar
[_time, [_vehicle, _hitPoint], DFUNC(doRepair), DFUNC(doRepair), _text, {true}, []] call EFUNC(common,progressBar);
[_time, [_vehicle, _hitPoint], {_this call DFUNC(doRepair)}, {_this call DFUNC(doRepair)}, _text, {true}, []] call EFUNC(common,progressBar);
// do animation
[_unit] call EFUNC(common,goKneeling);

View File

@ -1 +1,53 @@
(_this select 1) setHitPointDamage [_this select 2, 0]; systemChat str _this;
/*
* Author: commy2
*
* Start a replace wheel action and open progress bar.
*
* Arguments:
* 0: Unit that does the repairing (Object)
* 1: vehicle to repair (Object)
* 2: Selected hitpoint (String)
*
* Return Value:
* NONE
*/
#include "script_component.hpp"
private ["_unit", "_vehicle", "_hitPoint"];
_unit = _this select 0;
_vehicle = _this select 1;
_hitPoint = _this select 2;
// exit if not a valid hitpoint
if !(_hitPoint in ([_vehicle] call EFUNC(common,getHitPoints))) exitWith {};
// get nearest wheel
private "_wheel";
_wheel = objNull;
{
if ([_unit, _x, ["isNotDragging", "isNotCarrying"]] call EFUNC(common,canInteractWith)) exitWith {
_wheel = _x;
};
} forEach nearestObjects [_unit, ["ACE_Wheel"], 5];
if (isNull _wheel) exitWith {};
[_unit, _wheel] call EFUNC(common,claim);
// calculate time to fully repair the hitpoint
private "_time";
_time = 10;
// get string of the hitpoint
private "_text";
_text = "REPLACE WHEEL";
// open the loading bar
[_time, [_unit, _vehicle, _hitPoint, _wheel], {(_this select 0) call DFUNC(doReplaceWheel)}, {[objNull, _this select 0 select 3] call DEFUNC(common,claim); hint "abort"}, _text, {true}, []] call EFUNC(common,progressBar);
// do animation
[_unit] call EFUNC(common,goKneeling);
// @todo play sound