Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Garage Sell Button #3237

Merged
1 change: 1 addition & 0 deletions A3A/addons/core/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,7 @@ class CfgFunctions
class getAggroLevelString {};
class getRecentDamage {};
class getVehiclesAirSupport {};
class getVehicleSellPrice {};
class getVehiclesGroundSupport {};
class getVehiclesGroundTransport {};
class vehicleBoxRestore {};
Expand Down
2 changes: 1 addition & 1 deletion A3A/addons/core/Stringtable.xml
Original file line number Diff line number Diff line change
Expand Up @@ -2378,7 +2378,7 @@
<Chinesesimp>出售载具</Chinesesimp>
</Key>
<Key ID="STR_A3A_fn_base_sellveh_sold">
<Original>Vehicle Sold.</Original>
<Original>Vehicle sold.</Original>
<German>Fahrzeuge verkauft</German>
<Italian>Veicolo Venduto.</Italian>
<Spanish>Vehículo vendido.</Spanish>
Expand Down
75 changes: 75 additions & 0 deletions A3A/addons/core/functions/Base/fn_getVehicleSellPrice.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
#include "..\..\script_component.hpp"
FIX_LINE_NUMBERS()

#define OccAndInv(VAR) (FactionGet(occ, VAR) + FactionGet(inv, VAR))

params [["_veh",objNull],["_isGRG",false]];

/*
Blacklisted Assets

The array below contains classnames of assets which are not allowed to be sold within Antistasi.
Reason for this is that those items are one or more of the following:
- can be aquired by means that don't cost anything and the ability to sell those would be an infinite money exploit.
- are no proper "statics" in terms of weaponized statics but for example the ACE spotting scoped
- something else
*/
private _blacklistedAssets = [
"ACE_I_SpottingScope","ACE_O_SpottingScope","ACE_O_T_SpottingScope","ACE_B_SpottingScope","ACE_B_T_SpottingScope","ACE_SpottingScopeObject",
"O_Static_Designator_02_F","B_Static_Designator_01_F","B_W_Static_Designator_01_F",
"vn_o_nva_spiderhole_01","vn_o_nva_spiderhole_02","vn_o_nva_spiderhole_03",
"vn_o_pl_spiderhole_01","vn_o_pl_spiderhole_02","vn_o_pl_spiderhole_03",
"vn_o_vc_spiderhole_01","vn_o_vc_spiderhole_02","vn_o_vc_spiderhole_03"];

private _typeX = if (_isGRG) then {_veh;} else {typeOf _veh;};
Tiny-DM marked this conversation as resolved.
Show resolved Hide resolved

if (_typeX in _blacklistedAssets) exitWith {0};

if (_veh isKindOf "StaticWeapon") exitWith {100}; // in case rebel static is same as enemy statics

if (_typeX in FactionGet(all,"vehiclesReb")) exitWith { ([_typeX] call A3A_fnc_vehiclePrice) / 2 };

if (
(_typeX in arrayCivVeh)
or (_typeX in civBoats)
or (_typeX in (FactionGet(reb,"vehiclesCivBoat") + FactionGet(reb,"vehiclesCivCar") + FactionGet(reb,"vehiclesCivTruck")))
) exitWith {25};

if (
(_typeX in FactionGet(all,"vehiclesLight"))
or (_typeX in OccAndInv("vehiclesTrucks"))
or (_typeX in OccAndInv("vehiclesCargoTrucks"))
or (_typeX in OccAndInv("vehiclesMilitiaTrucks"))
or (_typeX in FactionGet(reb,"vehiclesTruck"))
) exitWith {100};

if (
(_typeX in FactionGet(all,"vehiclesBoats"))
or (_typeX in FactionGet(all,"vehiclesLightAPCs"))
or (_typeX in OccAndInv("vehiclesAmmoTrucks"))
or (_typeX in OccAndInv("vehiclesRepairTrucks"))
or (_typeX in OccAndInv("vehiclesFuelTrucks"))
or (_typeX in OccAndInv("vehiclesMedical"))
) exitWith {200};

if (_typeX in (FactionGet(all,"vehiclesHelisLight") + FactionGet(reb,"vehiclesCivHeli"))) exitWith {500};

if (
(_typeX in FactionGet(all,"vehiclesAPCs"))
|| (_typeX in FactionGet(all,"vehiclesIFVs"))
|| (_typeX in FactionGet(all,"vehiclesLightTanks"))
|| (_typeX in FactionGet(all,"vehiclesHelisLightAttack"))
|| (_typeX in FactionGet(all,"vehiclesTransportAir"))
|| (_typeX in FactionGet(all,"vehiclesUAVs"))
) exitWith {1000};

if (
(_typeX in FactionGet(all,"vehiclesHelisAttack"))
or (_typeX in FactionGet(all,"vehiclesTanks"))
or (_typeX in FactionGet(all,"vehiclesAA"))
or (_typeX in FactionGet(all,"vehiclesArtillery"))
) exitWith {3000};

if (_typeX in (FactionGet(all,"vehiclesPlanesCAS") + FactionGet(all,"vehiclesPlanesAA"))) exitWith {4000};

0;
46 changes: 1 addition & 45 deletions A3A/addons/core/functions/Base/fn_sellVehicle.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,6 @@ params [
#include "..\..\script_component.hpp"
FIX_LINE_NUMBERS()

#define OccAndInv(VAR) (FactionGet(occ, VAR) + FactionGet(inv, VAR))

private _titleStr = localize "STR_A3A_fn_base_sellveh_sell";

/*
Expand Down Expand Up @@ -69,49 +67,7 @@ if !(_owner isEqualTo "" || {getPlayerUID _player isEqualTo _owner}) exitWith {
if (_veh getVariable ["A3A_sellVehicle_inProgress",false]) exitWith {[_titleStr, localize "STR_A3A_fn_base_sellveh_progress"] remoteExecCall ["A3A_fnc_customHint",_player];};
_veh setVariable ["A3A_sellVehicle_inProgress",true,false]; // Only processed on the server. It is absolutely pointless trying to network this due to race conditions.

private _typeX = typeOf _veh;
private _costs = call {
if (_typeX in _blacklistedAssets) exitWith {0};
if (_veh isKindOf "StaticWeapon") exitWith {100}; // in case rebel static is same as enemy statics
if (_typeX in FactionGet(all,"vehiclesReb")) exitWith { ([_typeX] call A3A_fnc_vehiclePrice) / 2 };
if (
(_typeX in arrayCivVeh)
or (_typeX in civBoats)
or (_typeX in (FactionGet(reb,"vehiclesCivBoat") + FactionGet(reb,"vehiclesCivCar") + FactionGet(reb,"vehiclesCivTruck")))
) exitWith {25};
if (
(_typeX in FactionGet(all,"vehiclesLight"))
or (_typeX in OccAndInv("vehiclesTrucks"))
or (_typeX in OccAndInv("vehiclesCargoTrucks"))
or (_typeX in OccAndInv("vehiclesMilitiaTrucks"))
or (_typeX in FactionGet(reb,"vehiclesTruck"))
) exitWith {100};
if (
(_typeX in FactionGet(all,"vehiclesBoats"))
or (_typeX in FactionGet(all,"vehiclesLightAPCs"))
or (_typeX in OccAndInv("vehiclesAmmoTrucks"))
or (_typeX in OccAndInv("vehiclesRepairTrucks"))
or (_typeX in OccAndInv("vehiclesFuelTrucks"))
or (_typeX in OccAndInv("vehiclesMedical"))
) exitWith {200};
if (_typeX in (FactionGet(all,"vehiclesHelisLight") + FactionGet(reb,"vehiclesCivHeli"))) exitWith {500};
if (
(_typeX in FactionGet(all,"vehiclesAPCs"))
|| (_typeX in FactionGet(all,"vehiclesIFVs"))
|| (_typeX in FactionGet(all,"vehiclesLightTanks"))
|| (_typeX in FactionGet(all,"vehiclesHelisLightAttack"))
|| (_typeX in FactionGet(all,"vehiclesTransportAir"))
|| (_typeX in FactionGet(all,"vehiclesUAVs"))
) exitWith {1000};
if (
(_typeX in FactionGet(all,"vehiclesHelisAttack"))
or (_typeX in FactionGet(all,"vehiclesTanks"))
or (_typeX in FactionGet(all,"vehiclesAA"))
or (_typeX in FactionGet(all,"vehiclesArtillery"))
) exitWith {3000};
if (_typeX in (FactionGet(all,"vehiclesPlanesCAS") + FactionGet(all,"vehiclesPlanesAA"))) exitWith {4000};
0;
};
private _costs = [_veh] call A3A_fnc_getVehicleSellPrice;

if (_costs == 0) exitWith {
_veh setVariable ["A3A_sellVehicle_inProgress",false,false];
Expand Down
2 changes: 2 additions & 0 deletions A3A/addons/garage/CfgFunctions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ class CfgFunctions
class requestSelectionChange {};
class requestVehicle {};
class selectionChange {};
class sellVehGRG {};
class sellVehGRGLocal {};
class switchCategory {};
class toggleConfirmBttn {};
class toggleLock {};
Expand Down
25 changes: 16 additions & 9 deletions A3A/addons/garage/Core/fn_removeFromPool.sqf
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@

Arguments:
0. <Int> Client UID
1. <Str> Player, for logging
2. <Bool> Whether or not to exclude mounts from removal (default false)

Return Value:
<Bool> succesfull
Expand All @@ -20,21 +22,26 @@
*/
#include "defines.inc"
FIX_LINE_NUMBERS()
params [["_UID", "", [""]], ["_player", objNull, [objNull]]];
params [["_UID", "", [""]], ["_player", objNull, [objNull]], ["_removeMounts",false,[false]]];
Trace_1("Removing vehicles from garage with UID: %1", _UID);
if (_UID isEqualTo "") exitWith {false};

//find vehicles to remove
private _toRemove = [];
{
private _catIndex = _forEachIndex;
private _hashMap = _x;
if (!_removeMounts) then {
{
_veh = _hashMap get _x;
if ((_veh#3) isEqualTo _UID) then {_toRemove pushBack [_catIndex, _x, _veh]};
} forEach keys _x;
} forEach HR_GRG_Vehicles;

private _catIndex = _forEachIndex;
private _hashMap = _x;
{
_veh = _hashMap get _x;
if ((_veh#3) isEqualTo _UID) then {_toRemove pushBack [_catIndex, _x, _veh]};
} forEach keys _x;
} forEach HR_GRG_Vehicles;
} else {
HR_GRG_SelectedVehicles params [["_catIndex", -1], ["_vehUID", -1], ["_class", ""]];
_toRemove pushBack [_catIndex, _vehUID, _class];
};

//remove vehicles
{
//remove vehicle
Expand Down
48 changes: 48 additions & 0 deletions A3A/addons/garage/Core/fn_sellVehGRG.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
/*
Author: Tiny, parts of code ethically sourced from Håkon
[Description]
Attempts to sell currently selected vehicle

Arguments:
0. <String> player UID
1. <Object> Player
2. <Array> vehicle to sell (intended use with HR_GRG_SelectedVehicles)

Return Value:
n/A

Scope: Server
Environment: Unscheduled
Public: [No]
Dependencies:

Example: [HR_GRG_PlayerUID, player, HR_GRG_SelectedVehicles] remoteExecCall ["HR_GRG_fnc_sellVehGRG",2];

License: APL-ND
*/

#include "defines.inc"
FIX_LINE_NUMBERS()
params ["_UID", "_player", "_selectedVehicle"];

if (!isServer) exitWith {"Not server executed"};
if (_player != theBoss) exitWith {["STR_HR_GRG_Feedback_sellVehicle_comOnly"] call HR_GRG_fnc_Hint; diag_log "Not Commander"};
jaj22 marked this conversation as resolved.
Show resolved Hide resolved
_selectedVehicle params [["_catIndex", -1], ["_vehUID", -1], ["_class", ""]];
if ( (_catIndex isEqualTo -1) || (_vehUID isEqualTo -1) ) exitWith {};
Trace_2("Attempting to sell vehicle at cat: %1 | Vehicle ID: %2 | Classname: %3", _catIndex, _vehUID, _class);

private _refund = [_class,true] call A3A_fnc_getVehicleSellPrice;
if (_refund == 0) exitWith {["STR_HR_GRG_Feedback_sellVehicle_noPrice"] call HR_GRG_fnc_Hint;};

private _cat = HR_GRG_Vehicles#_catIndex;
private _veh = _cat get _vehUID;
private _lock = _veh#2;
if !(_lock isEqualTo "") exitWith {["STR_HR_GRG_Feedback_sellVehicle_locked"] call HR_GRG_fnc_Hint; diag_log "Locked"};

[_UID,_player,true] remoteExecCall ["HR_GRG_fnc_removeFromPool",HR_GRG_Users];
[] remoteExec ["HR_GRG_fnc_sellVehGRGLocal",_player];

[0,_refund] spawn A3A_fnc_resourcesFIA;

["STR_A3A_fn_base_sellveh_sold"] call HR_GRG_fnc_Hint;
Info_3("Vehicle UID %1 sold by %2 for %3.", _vehUID, name _player, _refund);
39 changes: 39 additions & 0 deletions A3A/addons/garage/Core/fn_sellVehGRGLocal.sqf
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
/*
Author: Tiny
[Description]
A helper script to fn_sellvehGRG, runs on the client to reset displays

Arguments:
1. The category to change selection to (default = -1)
2. The vehicle UID to change selection to (default = -1)
3. The classname of the selected vehicle (default = "")


Return Value:
<nil>

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
<nil>
<NIL>

I missed this one somehow.


Scope: Client
Environment: Any
Public: [No]

License: APL-ND
*/
#include "defines.inc"
FIX_LINE_NUMBERS()

if (isNull player) exitWith {Error("fn_manUpdateSelection was not executed by a client")};
params [["_catIndex",-1],["_vehUID",-1],["_class",""]];
HR_GRG_SelectedVehicles = [_catIndex, _vehUID,_class];
[] call HR_GRG_fnc_reloadPreview;
[] call HR_GRG_fnc_reloadExtras;
private _disp = findDisplay HR_GRG_IDD_Garage;

{
_ctrl = _disp displayCtrl _x;
Tiny-DM marked this conversation as resolved.
Show resolved Hide resolved
_ctrl ctrlEnable false;
_ctrl ctrlShow false;
} forEach [HR_GRG_IDC_ExtraMounts,HR_GRG_IDC_ExtraTexture,HR_GRG_IDC_ExtraAnim,HR_GRG_IDC_ExtraPylonsContainer];
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't do anything and can be stripped out. It's only present in onLoad because these controls all start enabled, and switchExtrasMenu only disables the currently-enabled control for some reason.


[0] call HR_GRG_fnc_switchExtrasMenu;
[] call HR_GRG_fnc_reloadPylons;
[] call HR_GRG_fnc_updateVehicleCount;
36 changes: 30 additions & 6 deletions A3A/addons/garage/Dialogs.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -220,7 +220,7 @@ class HR_GRG_VehicleSelect
x = SCREEN_RIGHT - 39 * GRID_NOUISCALE_W;
y = SCREEN_TOP + 4 * GRID_NOUISCALE_H;
w = 39 * GRID_NOUISCALE_W;
h = safeZoneH - (56 * GRID_NOUISCALE_H); // Screen height - title and buttons height
h = safeZoneH - (63 * GRID_NOUISCALE_H); // Screen height - title and buttons height
size = TEXT_SIZE_MEDIUM;
rowHeight = 3 * GRID_NOUISCALE_H;
onMouseButtonClick = "_this call HR_GRG_fnc_requestMount;";
Expand All @@ -244,7 +244,7 @@ class HR_GRG_VehicleSelect
x = SCREEN_RIGHT - 39 * GRID_NOUISCALE_W;
y = SCREEN_TOP + 4 * GRID_NOUISCALE_H;
w = 39 * GRID_NOUISCALE_W;
h = safeZoneH - (56 * GRID_NOUISCALE_H); // Screen height - title and buttons height
h = safeZoneH - (63 * GRID_NOUISCALE_H); // Screen height - title and buttons height

class controls
{
Expand All @@ -254,7 +254,7 @@ class HR_GRG_VehicleSelect
x = 0;
y = 0;
w = 39 * GRID_NOUISCALE_W;
h = safeZoneH - (56 * GRID_NOUISCALE_H);
h = safeZoneH - (63 * GRID_NOUISCALE_H);
};

class HR_GRG_MirrorCheckbox: HR_GRG_RscCheckBox
Expand Down Expand Up @@ -292,7 +292,7 @@ class HR_GRG_VehicleSelect
x = 0;
y = 4 * GRID_NOUISCALE_H;
w = 38 * GRID_NOUISCALE_W;
h = safeZoneH - (65 * GRID_NOUISCALE_H); // Screen height - title and buttons height 51
h = safeZoneH - (67 * GRID_NOUISCALE_H); // Screen height - title and buttons height 51
};
};
};
Expand All @@ -301,7 +301,7 @@ class HR_GRG_VehicleSelect
class HR_GRG_SourcePanel: HR_GRG_RscControlsGroup
{
x = SCREEN_RIGHT - 39 * GRID_NOUISCALE_W;
y = SCREEN_BOTTOM - 52 * GRID_NOUISCALE_H;
y = SCREEN_BOTTOM - 59 * GRID_NOUISCALE_H;
w = 39 * GRID_NOUISCALE_W;
h = 7 * GRID_NOUISCALE_H;
size = TEXT_SIZE_MEDIUM;
Expand Down Expand Up @@ -350,7 +350,7 @@ class HR_GRG_VehicleSelect
class HR_GRG_InfoPanelWrapper: HR_GRG_RscControlsGroup
{
x = SCREEN_RIGHT - 39 * GRID_NOUISCALE_W;
y = SCREEN_BOTTOM - 45 * GRID_NOUISCALE_H;
y = SCREEN_BOTTOM - 52 * GRID_NOUISCALE_H;
w = 39 * GRID_NOUISCALE_W;
h = 45 * GRID_NOUISCALE_H;
size = TEXT_SIZE_MEDIUM;
Expand All @@ -369,6 +369,30 @@ class HR_GRG_VehicleSelect
};
};

class HR_GRG_SellButtonWrapper: HR_GRG_RscControlsGroup
{
x = SCREEN_RIGHT - 39 * GRID_NOUISCALE_W;
y = SCREEN_BOTTOM - 7 * GRID_NOUISCALE_H;
w = 39 * GRID_NOUISCALE_W;
h = 7 * GRID_NOUISCALE_H;
size = TEXT_SIZE_LARGE;

class controls
{
class HR_GRG_SellVeh: HR_GRG_RscButton
{
idc = HR_GRG_IDC_SellVeh;
text = $STR_HR_GRG_Generic_SellVeh;
x = 0;
y = 0;
w = 39 * GRID_NOUISCALE_W;
h = 7 * GRID_NOUISCALE_H;
action = "[HR_GRG_PlayerUID, player, HR_GRG_SelectedVehicles] remoteExecCall ['HR_GRG_fnc_sellVehGRG',2];";
sizeEx = TEXT_SIZE_LARGE;
};
};
};

// Camera controls hint
class HR_GRG_KeyBindHint: HR_GRG_RscStructuredText
{
Expand Down
Loading