auto add actions to replace and remove wheels

This commit is contained in:
commy2 2015-03-11 15:21:35 +01:00
parent 9750e5fbc3
commit ed8e9904c2
7 changed files with 153 additions and 3 deletions

View File

@ -164,9 +164,9 @@ _vehicle setFuel _fuelLevel;
["lockVehicle", {
_this setVariable [QGVAR(lockStatus), locked _this];
_this lock 2
_this lock 2;
}] call FUNC(addEventhandler);
["unlockVehicle", {
_this lock (_this getVariable [QGVAR(lockStatus), locked _this])
_this lock (_this getVariable [QGVAR(lockStatus), locked _this]);
}] call FUNC(addEventhandler);

View File

@ -10,3 +10,35 @@ class Extended_PostInit_EventHandlers {
init = QUOTE(call COMPILE_FILE(XEH_postInit));
};
};
class Extended_Init_EventHandlers {
class Car {
class ADDON {
init = QUOTE(_this call DFUNC(addRepairActions));
};
};
class Tank {
class ADDON {
init = QUOTE(_this call DFUNC(addRepairActions));
};
};
class Helicopter {
class ADDON {
init = QUOTE(_this call DFUNC(addRepairActions));
};
};
class Plane {
class ADDON {
init = QUOTE(_this call DFUNC(addRepairActions));
};
};
class Ship_F {
class ADDON {
init = QUOTE(_this call DFUNC(addRepairActions));
};
};
};

View File

@ -4,9 +4,12 @@ ADDON = false;
PREP(actionCanRepair);
PREP(actionRepair);
PREP(addRepairActions);
PREP(doRepair);
PREP(getWheelHitPointsWithSelections);
PREP(removeWheel);
PREP(repairVehicle);
PREP(replaceWheel);
PREP(setDamage);
PREP(setHitPointDamage);

View File

@ -5,7 +5,7 @@ class CfgPatches {
units[] = {};
weapons[] = {};
requiredVersion = REQUIRED_VERSION;
requiredAddons[] = {"ace_common"};
requiredAddons[] = {"ace_common","ace_interact_menu"};
author[] = {"commy2"};
authorUrl = "https://github.com/commy2";
VERSION_CONFIG;

View File

@ -0,0 +1,113 @@
/*
* Author: commy2
*
* Called from init eventhandler. Checks if the vehicles class already has the actions initialized. Otherwise add all available repair options.
*
* Arguments:
* 0: vehicle (Object)
*
* Return Value:
* NONE
*/
#include "script_component.hpp"
private "_vehicle";
_vehicle = _this select 0;
private ["_type", "_initializedClasses"];
_type = typeOf _vehicle;
_initializedClasses = GETMVAR(GVAR(initializedClasses),[]);
// do nothing if the class is already initialized
if (_type in _initializedClasses) exitWith {};
// get all hitpoints
private "_hitPoints";
_hitPoints = [_vehicle] call EFUNC(common,getHitPoints);
// get hitpoints of wheels with their selections
private ["_wheelHitPointsWithSelections", "_wheelHitPoints", "_wheelHitPointSelections"];
_wheelHitPointsWithSelections = [_vehicle] call FUNC(getWheelHitPointsWithSelections);
_wheelHitPoints = _wheelHitPointsWithSelections select 0;
_wheelHitPointSelections = _wheelHitPointsWithSelections select 1;
// add repair events to this vehicle class
{
if (_x in _wheelHitPoints) then {
// add wheel repair action
private ["_nameRemove", "_nameReplace", "_icon", "_selection"];
_nameRemove = format ["Remove %1", _x];
_nameReplace = format ["Replace %1", _x];
_icon = "";
_selection = _wheelHitPointSelections select (_wheelHitPoints find _x);
private ["_statement_remove", "_condition_remove", "_statement_replace", "_condition_replace"];
_statement_remove = format [QFUNC(removeWheel_%1), _x];
_condition_remove = format [QFUNC(canRemoveWheel_%1), _x];
_statement_replace = format [QFUNC(replaceWheel_%1), _x];
_condition_replace = format [QFUNC(canReplaceWheel_%1), _x];
// compile functions for that hitpoint if no such functions currently exist
if (isNil _statement_remove) then {
// remove wheel
private "_function";
_function = compile format [QUOTE([ARR_2(_target,'%1')] call DFUNC(removeWheel)), _x];
missionNamespace setVariable [_statement_remove, _function];
_function = compile format ["alive _target && {_target getHitPointDamage '%1' < 1}", _x];
missionNamespace setVariable [_condition_remove, _function];
// replace wheel
_function = compile format [QUOTE([ARR_2(_target,'%1')] call DFUNC(replaceWheel)), _x];
missionNamespace setVariable [_statement_replace, _function];
_function = compile format ["alive _target && {_target getHitPointDamage '%1' >= 1}", _x];
missionNamespace setVariable [_condition_replace, _function];
};
_statement_remove = missionNamespace getVariable [_statement_remove, {}];
_condition_remove = missionNamespace getVariable [_condition_remove, {}];
_statement_replace = missionNamespace getVariable [_statement_replace, {}];
_condition_replace = missionNamespace getVariable [_condition_replace, {}];
[_vehicle, 0, [_nameRemove], _nameRemove, _icon, _selection, _statement_remove, _condition_remove, 2] call EFUNC(interact_menu,addAction); // @todo class instead of object
[_vehicle, 0, [_nameReplace], _nameReplace, _icon, _selection, _statement_replace, _condition_replace, 2] call EFUNC(interact_menu,addAction);
} else {
// add misc repair action
/*private ["_selection", "_statement", "_condition"];
_name = format ["Repair %1", _x];
_icon = "";
_statement = {
hint "repaired";
};
_condition = {true};
[_vehicle, 0, ["RepairMe"], _name, _icon, "", _statement, _condition, 4] call ace_interact_menu_fnc_addAction;*/
};
} forEach _hitPoints;
// set class as initialized
_initializedClasses pushBack _type;
SETMVAR(GVAR(initializedClasses),_initializedClasses);

View File

@ -0,0 +1 @@
(_this select 0) setHitPointDamage [_this select 1, 1]; systemChat str _this;

View File

@ -0,0 +1 @@
(_this select 0) setHitPointDamage [_this select 1, 0]; systemChat str _this;