Skip to content

Commit

Permalink
Merge pull request #3191 from acemod/cargoCleanup
Browse files Browse the repository at this point in the history
Cargo Cleanup, Add makeLoadable
  • Loading branch information
thojkooi committed Feb 4, 2016
2 parents 324edbd + 1a98726 commit 038befb
Show file tree
Hide file tree
Showing 25 changed files with 249 additions and 111 deletions.
4 changes: 3 additions & 1 deletion addons/cargo/CfgEventHandlers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,9 @@ class Extended_PostInit_EventHandlers {

class Extended_Killed_EventHandlers {
class All {
init = QUOTE(call FUNC(handleDestroyed));
class ADDON {
serverKilled = QUOTE(call FUNC(handleDestroyed));
};
};
};

Expand Down
37 changes: 34 additions & 3 deletions addons/cargo/CfgVehicles.hpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,9 @@
class CfgVehicles {
class ACE_Module;
class Logic;
class Module_F: Logic {
class ModuleDescription;
};
class ACE_Module: Module_F {};
class ACE_moduleCargoSettings: ACE_Module {
scope = 2;
displayName = CSTRING(SettingsModule_DisplayName);
Expand All @@ -26,6 +30,33 @@ class CfgVehicles {
sync[] = {};
};
};
class GVAR(makeLoadable): ACE_Module {
scope = 2;
displayName = CSTRING(makeLoadable_displayName);
icon = QUOTE(PATHTOF(UI\Icon_Module_makeLoadable_ca.paa));
category = "ACE_Logistics";
function = QFUNC(moduleMakeLoadable);
isGlobal = 1;
isTriggerActivated = 0;
author = ECSTRING(common,ACETeam);
class Arguments {
class canLoad {
displayName = CSTRING(makeLoadable_displayName);
description = CSTRING(MakeLoadable_description);
typeName = "BOOL";
defaultValue = 1;
};
class setSize {
displayName = CSTRING(makeLoadable_setSize_displayName);
typeName = "NUMBER";
defaultValue = 1;
};
};
class ModuleDescription: ModuleDescription {
description = CSTRING(module_MakeLoadable_description);
sync[] = {"AnyStaticObject"};
};
};

class LandVehicle;
class Car: LandVehicle {
Expand Down Expand Up @@ -178,7 +209,7 @@ class CfgVehicles {
GVAR(space) = 0;
GVAR(hasCargo) = 0;
};

// boats
class Ship;
class Ship_F: Ship {
Expand Down Expand Up @@ -245,7 +276,7 @@ class CfgVehicles {
class RoadBarrier_F: RoadCone_F {
GVAR(size) = 2;
};


class Scrapyard_base_F;
class Land_PaperBox_closed_F: Scrapyard_base_F {
Expand Down
Binary file added addons/cargo/UI/Icon_Module_makeLoadable_ca.paa
Binary file not shown.
20 changes: 9 additions & 11 deletions addons/cargo/XEH_postInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,13 @@

["LoadCargo", {
(_this select 0) params ["_item","_vehicle"];
private ["_loaded", "_hint", "_itemName", "_vehicleName"];

_loaded = [_item, _vehicle] call FUNC(loadItem);
private _loaded = [_item, _vehicle] call FUNC(loadItem);

// Show hint as feedback
_hint = [LSTRING(LoadingFailed), LSTRING(LoadedItem)] select _loaded;
_itemName = getText (configFile >> "CfgVehicles" >> typeOf _item >> "displayName");
_vehicleName = getText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "displayName");
private _hint = [LSTRING(LoadingFailed), LSTRING(LoadedItem)] select _loaded;
private _itemName = getText (configFile >> "CfgVehicles" >> typeOf _item >> "displayName");
private _vehicleName = getText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "displayName");

["displayTextStructured", [[_hint, _itemName, _vehicleName], 3.0]] call EFUNC(common,localEvent);

Expand All @@ -23,16 +22,15 @@

["UnloadCargo", {
(_this select 0) params ["_item","_vehicle"];
private ["_unloaded", "_itemClass", "_hint", "_itemName", "_vehicleName"];

_unloaded = [_item, _vehicle] call FUNC(unloadItem);
private _unloaded = [_item, _vehicle] call FUNC(unloadItem);

_itemClass = if (_item isEqualType "") then {_item} else {typeOf _item};
private _itemClass = if (_item isEqualType "") then {_item} else {typeOf _item};

// Show hint as feedback
_hint = [LSTRING(UnloadingFailed), LSTRING(UnloadedItem)] select _unloaded;
_itemName = getText (configFile >> "CfgVehicles" >> _itemClass >> "displayName");
_vehicleName = getText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "displayName");
private _hint = [LSTRING(UnloadingFailed), LSTRING(UnloadedItem)] select _unloaded;
private _itemName = getText (configFile >> "CfgVehicles" >> _itemClass >> "displayName");
private _vehicleName = getText (configFile >> "CfgVehicles" >> typeOf _vehicle >> "displayName");

["displayTextStructured", [[_hint, _itemName, _vehicleName], 3.0]] call EFUNC(common,localEvent);

Expand Down
3 changes: 3 additions & 0 deletions addons/cargo/XEH_preInit.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ PREP(handleDestroyed);
PREP(initObject);
PREP(initVehicle);
PREP(loadItem);
PREP(makeLoadable);
PREP(moduleMakeLoadable);
PREP(moduleSettings);
PREP(onMenuOpen);
PREP(startLoadIn);
Expand All @@ -21,5 +23,6 @@ PREP(unloadItem);
PREP(validateCargoSpace);

GVAR(initializedItemClasses) = [];
GVAR(initializedVehicleClasses) = [];

ADDON = true;
4 changes: 2 additions & 2 deletions addons/cargo/functions/fnc_canLoad.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,11 @@
#include "script_component.hpp"

params ["_player", "_object"];
TRACE_2("params",_player,_object);

if (!([_player, _object, []] call EFUNC(common,canInteractWith))) exitWith {false};

private ["_nearestVehicle"];
_nearestVehicle = [_player] call FUNC(findNearestVehicle);
private _nearestVehicle = [_player] call FUNC(findNearestVehicle);

if (_nearestVehicle isKindOf "Cargo_Base_F" || isNull _nearestVehicle) then {
{
Expand Down
7 changes: 3 additions & 4 deletions addons/cargo/functions/fnc_canLoadItemIn.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

params [["_item", "", [objNull,""]], "_vehicle"];

if (speed _vehicle > 1 || (((getPos _vehicle) select 2) > 3)) exitWith {false};

private ["_itemSize", "_validItem"];
_itemSize = [_item] call FUNC(getSizeItem);
if (speed _vehicle > 1 || {((getPos _vehicle) select 2) > 3}) exitWith {false};

private _itemSize = [_item] call FUNC(getSizeItem);
private _validItem = false;
if (_item isEqualType "") then {
_validItem =
isClass (configFile >> "CfgVehicles" >> _item) &&
Expand Down
10 changes: 5 additions & 5 deletions addons/cargo/functions/fnc_canUnloadItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@
#include "script_component.hpp"

params ["_item", "_vehicle"];
private ["_loaded", "_itemClass", "_validVehiclestate", "_emptyPos"];
TRACE_2("params",_item,_vehicle);

_loaded = _vehicle getVariable [QGVAR(loaded), []];
private _loaded = _vehicle getVariable [QGVAR(loaded), []];
if !(_item in _loaded) exitWith {false};

_itemClass = if (_item isEqualType "") then {_item} else {typeOf _item};
private _itemClass = if (_item isEqualType "") then {_item} else {typeOf _item};

_validVehiclestate = true;
_emptyPos = [];
private _validVehiclestate = true;
private _emptyPos = [];
if (_vehicle isKindOf "Ship" ) then {
if !(speed _vehicle <1 && {(((getPosATL _vehicle) select 2) < 2)}) then {_validVehiclestate = false};
_emptyPos = ((getPosASL _vehicle) call EFUNC(common,ASLtoPosition) findEmptyPosition [0, 15, _itemClass]); // TODO: if spot is underwater pick another spot.
Expand Down
12 changes: 5 additions & 7 deletions addons/cargo/functions/fnc_findNearestVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -15,23 +15,21 @@
*/
#include "script_component.hpp"

private ["_loadCar", "_loadHelicopter", "_loadTank", "_loadShip", "_loadContainer"];

params ["_unit"];

_loadCar = nearestObject [_unit, "car"];
private _loadCar = nearestObject [_unit, "car"];
if (_unit distance _loadCar <= MAX_LOAD_DISTANCE) exitWith {_loadCar};

_loadHelicopter = nearestObject [_unit, "air"];
private _loadHelicopter = nearestObject [_unit, "air"];
if (_unit distance _loadHelicopter <= MAX_LOAD_DISTANCE) exitWith {_loadHelicopter};

_loadTank = nearestObject [_unit, "tank"];
private _loadTank = nearestObject [_unit, "tank"];
if (_unit distance _loadTank <= MAX_LOAD_DISTANCE) exitWith {_loadTank};

_loadShip = nearestObject [_unit, "ship"];
private _loadShip = nearestObject [_unit, "ship"];
if (_unit distance _loadShip <= MAX_LOAD_DISTANCE) exitWith {_loadShip};

_loadContainer = nearestObject [_unit,"Cargo_base_F"];
private _loadContainer = nearestObject [_unit,"Cargo_base_F"];
if (_unit distance _loadContainer <= MAX_LOAD_DISTANCE) exitWith {_loadContainer};

objNull
1 change: 1 addition & 0 deletions addons/cargo/functions/fnc_getCargoSpaceLeft.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@
#include "script_component.hpp"

params ["_object"];
// TRACE_1("params",_object);

_object getVariable [QGVAR(space), getNumber (configFile >> "CfgVehicles" >> typeOf _object >> QGVAR(space))]
15 changes: 8 additions & 7 deletions addons/cargo/functions/fnc_getSizeItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,22 +16,23 @@
#include "script_component.hpp"

params ["_item"];
private ["_isVirtual","_itemClass","_config"];

scopeName "return";

_isVirtual = (_item isEqualType "");
_itemClass = if (_isVirtual) then {_item} else {typeOf _item};
_config = (configFile >> "CfgVehicles" >> _itemClass >> QGVAR(size));
private _isVirtual = (_item isEqualType "");
private _itemClass = if (_isVirtual) then {_item} else {typeOf _item};
private _config = (configFile >> "CfgVehicles" >> _itemClass >> QGVAR(size));

if (_isVirtual) then {
if (isNumber _config) then {
(getNumber _config) breakOut "return";
};
} else {
_config = (configFile >> "CfgVehicles" >> typeOf _item >> QGVAR(size));

if (!isNil {_item getVariable QGVAR(size)}) then {
(_item getVariable QGVAR(size)) breakOut "return";
};
if (isNumber _config) then {
(_item getVariable [QGVAR(size), getNumber _config]) breakOut "return";
(getNumber _config) breakOut "return";
};
};

Expand Down
8 changes: 4 additions & 4 deletions addons/cargo/functions/fnc_handleDestroyed.sqf
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
/*
* Author: Glowbal
* Handle object being destroyed.
* Handle object being destroyed. Only runs on server.
*
* Arguments:
* 0: Object <OBJECT>
Expand All @@ -16,17 +16,17 @@
#include "script_component.hpp"

params ["_vehicle"];
TRACE_1("params",_vehicle);

private["_loaded"];

_loaded = _vehicle getVariable [QGVAR(loaded), []];
private _loaded = _vehicle getVariable [QGVAR(loaded), []];
if (_loaded isEqualTo []) exitWith {};

{
// TODO Do we want to be able to recover destroyed equipment?
if (_x isEqualType objNull) then {
deleteVehicle _x;
};
nil
} count _loaded;

[_vehicle] call FUNC(validateCargoSpace);
26 changes: 21 additions & 5 deletions addons/cargo/functions/fnc_initObject.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,31 @@
#include "script_component.hpp"

params ["_object"];
private _type = typeOf _object;
TRACE_2("params",_object,_type);

if (getNumber (configFile >> "CfgVehicles" >> typeOf _object >> QGVAR(canLoad)) != 1) exitWith {};

private ["_type", "_action"];
_type = typeOf _object;
if ((_object getVariable [QGVAR(canLoad), getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(canLoad))]) != 1) exitWith {};

// do nothing if the class is already initialized
if (_type in GVAR(initializedItemClasses)) exitWith {};
GVAR(initializedItemClasses) pushBack _type;

_action = [QGVAR(load), localize LSTRING(loadObject), QUOTE(PATHTOF(UI\Icon_load.paa)), {[_player, _target] call FUNC(startLoadIn)}, {GVAR(enable) && {[_player, _target] call FUNC(canLoad)}}] call EFUNC(interact_menu,createAction);
TRACE_1("Adding load cargo action to class", _type);

private _condition = {
GVAR(enable) &&
{(_target getVariable [QGVAR(canLoad), getNumber (configFile >> "CfgVehicles" >> (typeOf _target) >> QGVAR(canLoad))]) == 1} &&
{locked _target < 2} &&
{alive _target} &&
{[_player, _target, []] call EFUNC(common,canInteractWith)}
};
private _statement = {
params ["_target", "_player"];
[_player, _target] call FUNC(startLoadIn);
};
private _text = localize LSTRING(loadObject);
private _icon = QUOTE(PATHTOF(UI\Icon_load.paa));

private _action = [QGVAR(load), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
[_type, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass);

27 changes: 14 additions & 13 deletions addons/cargo/functions/fnc_initVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,7 @@
params ["_vehicle"];
TRACE_1("params", _vehicle);

private ["_type", "_initializedClasses"];
_type = typeOf _vehicle;
_initializedClasses = GETMVAR(GVAR(initializedClasses),[]);
private _type = typeOf _vehicle;

if (isServer) then {
{
Expand All @@ -35,21 +33,24 @@ if (isServer) then {
};

// do nothing if the class is already initialized
if (_type in _initializedClasses) exitWith {};
if (_type in GVAR(initializedVehicleClasses)) exitWith {};
// set class as initialized
_initializedClasses pushBack _type;
SETMVAR(GVAR(initializedClasses),_initializedClasses);
GVAR(initializedVehicleClasses) pushBack _type;

if (!hasInterface) exitWith {};
if (getNumber (configFile >> "CfgVehicles" >> _type >> QGVAR(hasCargo)) != 1) exitWith {};

private ["_text", "_condition", "_statement", "_icon", "_action"];
_condition = {
params ["_target", "_player"];
TRACE_1("Adding unload cargo action to class", _type);

private _condition = {
GVAR(enable) && {locked _target < 2} && {alive _target} && {[_player, _target, []] call EFUNC(common,canInteractWith)}
};
_text = localize LSTRING(openMenu);
_statement = {GVAR(interactionVehicle) = _target; createDialog QGVAR(menu);};
_icon = "";
private _statement = {
GVAR(interactionVehicle) = _target;
createDialog QGVAR(menu);
};
private _text = localize LSTRING(openMenu);
private _icon = "";

_action = [QGVAR(openMenu), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
private _action = [QGVAR(openMenu), _text, _icon, _statement, _condition] call EFUNC(interact_menu,createAction);
[_type, 0, ["ACE_MainActions"], _action] call EFUNC(interact_menu,addActionToClass);
7 changes: 3 additions & 4 deletions addons/cargo/functions/fnc_loadItem.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -19,18 +19,17 @@
#include "script_component.hpp"

params [["_item","",[objNull,""]], ["_vehicle",objNull,[objNull]]];
private ["_loaded", "_space", "_itemSize"];

if !([_item, _vehicle] call FUNC(canLoadItemIn)) exitWith {false};

_loaded = _vehicle getVariable [QGVAR(loaded), []];
private _loaded = _vehicle getVariable [QGVAR(loaded), []];
_loaded pushBack _item;
_vehicle setVariable [QGVAR(loaded), _loaded, true];

TRACE_1("added to loaded array",_loaded);

_space = [_vehicle] call FUNC(getCargoSpaceLeft);
_itemSize = [_item] call FUNC(getSizeItem);
private _space = [_vehicle] call FUNC(getCargoSpaceLeft);
private _itemSize = [_item] call FUNC(getSizeItem);
_vehicle setVariable [QGVAR(space), _space - _itemSize, true];

if (_item isEqualType objNull) then {
Expand Down
Loading

0 comments on commit 038befb

Please sign in to comment.