Skip to content

Commit

Permalink
Merge pull request #621 from KillahPotatoes/v0.97S13-530
Browse files Browse the repository at this point in the history
Side missions framework
  • Loading branch information
Dubjunk authored Jun 23, 2019
2 parents e71ce77 + 6901f74 commit 6049e1c
Show file tree
Hide file tree
Showing 35 changed files with 1,472 additions and 55 deletions.
1 change: 1 addition & 0 deletions .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
"KPLIB_param_fuelInfluence",
"KPLIB_param_limitedZeusCeiling",
"KPLIB_param_limitedZeusRadius",
"KPLIB_param_missionRefund",
"KPLIB_param_mobileRespawn",
"KPLIB_param_permission",
"KPLIB_param_permissionCommander",
Expand Down
4 changes: 3 additions & 1 deletion Missionframework/KPLIB_functions.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: KPLIB_functions.hpp
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2017-10-16
Last Update: 2019-04-22
Last Update: 2019-06-22
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Description:
Expand All @@ -29,4 +29,6 @@ class KPLIB {
#include "modules\23_logistic\functions.hpp"
#include "modules\24_enemy\functions.hpp"
#include "modules\26_cratefiller\functions.hpp"
#include "modules\27_mission\functions.hpp"
#include "modules\90_missions\functions.hpp"
};
3 changes: 2 additions & 1 deletion Missionframework/KPLIB_ui.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: KPLIB_ui.hpp
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2017-10-16
Last Update: 2019-04-22
Last Update: 2019-06-09
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Description:
Expand All @@ -25,3 +25,4 @@
#include "modules\16_garrison\ui.hpp"
#include "modules\23_logistic\ui.hpp"
#include "modules\26_cratefiller\ui.hpp"
#include "modules\27_mission\ui.hpp"
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: fn_cratefiller_postInit.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-04-05
Last Update: 2019-05-19
Last Update: 2019-06-21
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Public: No
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: fn_cratefiller_preInit.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-02-02
Last Update: 2019-05-19
Last Update: 2019-06-23
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Public: No
Expand All @@ -21,10 +21,6 @@
if (isServer) then {
["Module initializing...", "PRE] [CRATEFILLER", true] call KPLIB_fnc_common_log;

/*
----- Module Initialization -----
*/

// Register arsenal filled event handler
["KPLIB_arsenal_newLists", {[] call KPLIB_fnc_cratefiller_presets;}] call CBA_fnc_addEventHandler;

Expand Down
88 changes: 41 additions & 47 deletions Missionframework/modules/26_cratefiller/ui/KPLIB_cratefiller.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
File: KPLIB_cratefiller.hpp
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-04-05
Last Update: 2019-05-04
Last Update: 2019-06-19
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Description:
Expand All @@ -24,31 +24,6 @@ class KPLIB_cratefiller {

class KPLIB_DialogArea: KPGUI_PRE_DialogBackgroundS {};

// Crates

class KPLIB_TransportTitle: KPGUI_PRE_InlineTitle {
text = "$STR_KPLIB_DIALOG_CRATEFILLER_TITLETRANSPORT";
x = KP_GETCX(KP_X_VAL_S,KP_WIDTH_VAL_S,1,2);
y = KP_GETCY(KP_Y_VAL_S,KP_HEIGHT_VAL_S,0,48);
w = KP_GETW(KP_WIDTH_VAL_S,2);
h = KP_GETH(KP_HEIGHT_VAL_S,16);
};

// Equipment

class KPLIB_EquipmentTitle: KPLIB_TransportTitle {
text = "$STR_KPLIB_DIALOG_CRATEFILLER_TITLEEQUIPMENT";
x = KP_GETCX(KP_X_VAL_S,KP_WIDTH_VAL_S,0,2);
y = KP_GETCY(KP_Y_VAL_S,KP_HEIGHT_VAL_S,0,48);
};

// Inventory

class KPLIB_InventoryTitle: KPLIB_TransportTitle {
text = "$STR_KPLIB_DIALOG_CRATEFILLER_TITLEINVENTORY";
y = KP_GETCY(KP_Y_VAL_S,KP_HEIGHT_VAL_S,5,48);
};

// Tools controlsGroup

class KPLIB_GroupTools: KPGUI_PRE_ControlsGroupNoScrollbars {
Expand Down Expand Up @@ -127,30 +102,16 @@ class KPLIB_cratefiller {
action = "[] call KPLIB_fnc_cratefiller_showOverview";
};

// Crates

class KPLIB_ComboCargo: KPGUI_PRE_Combo {
idc = KPLIB_IDC_CRATEFILLER_COMBOCARGO;
x = KP_GETCX(KP_X_VAL_S,KP_WIDTH_VAL_S,1,2);
y = KP_GETCY(KP_Y_VAL_S,KP_HEIGHT_VAL_S,3,48);
w = KP_GETW(KP_WIDTH_VAL_S,(24/11));
h = KP_GETH(KP_HEIGHT_VAL_S,24);
tooltip = "$STR_KPLIB_DIALOG_CRATEFILLER_INVENTORY_TT";
onLBSelChanged = "[] call KPLIB_fnc_cratefiller_showInventory";
};
// Equipment

class KPLIB_RefreshCargo: KPGUI_PRE_CloseCross {
text = "KPGUI\res\icon_refresh.paa";
x = KP_GETCX(KP_X_VAL_S,KP_WIDTH_VAL_S,23,24);
y = KP_GETCY(KP_Y_VAL_S,KP_HEIGHT_VAL_S,3,48);
w = KP_GETW(KP_WIDTH_VAL_S,24);
h = KP_GETH(KP_HEIGHT_VAL_S,24);
tooltip = "$STR_KPLIB_DIALOG_CRATEFILLER_REFRESH_TT";
action = "[] call KPLIB_fnc_cratefiller_getNearStorages";
class KPLIB_EquipmentTitle: KPGUI_PRE_InlineTitle {
text = "$STR_KPLIB_DIALOG_CRATEFILLER_TITLEEQUIPMENT";
x = KP_GETCX(KP_X_VAL_S,KP_WIDTH_VAL_S,0,2);
y = KP_GETCY(KP_Y_VAL_S,KP_HEIGHT_VAL_S,0,48);
w = KP_GETW(KP_WIDTH_VAL_S,2);
h = KP_GETH(KP_HEIGHT_VAL_S,16);
};

// Equipment

class KPLIB_ComboEquipment: KPGUI_PRE_Combo {
idc = KPLIB_IDC_CRATEFILLER_COMBOEQUIPMENT;
x = KP_GETCX(KP_X_VAL_S,KP_WIDTH_VAL_S,0,1);
Expand Down Expand Up @@ -204,8 +165,41 @@ class KPLIB_cratefiller {
idcRight = KPLIB_IDC_CRATEFILLER_RIGHTEQUIPMENTBUTTON;
};

// Crates

class KPLIB_TransportTitle: KPLIB_EquipmentTitle {
text = "$STR_KPLIB_DIALOG_CRATEFILLER_TITLETRANSPORT";
x = KP_GETCX(KP_X_VAL_S,KP_WIDTH_VAL_S,1,2);
y = KP_GETCY(KP_Y_VAL_S,KP_HEIGHT_VAL_S,0,48);
};

class KPLIB_ComboCargo: KPGUI_PRE_Combo {
idc = KPLIB_IDC_CRATEFILLER_COMBOCARGO;
x = KP_GETCX(KP_X_VAL_S,KP_WIDTH_VAL_S,1,2);
y = KP_GETCY(KP_Y_VAL_S,KP_HEIGHT_VAL_S,3,48);
w = KP_GETW(KP_WIDTH_VAL_S,(24/11));
h = KP_GETH(KP_HEIGHT_VAL_S,24);
tooltip = "$STR_KPLIB_DIALOG_CRATEFILLER_INVENTORY_TT";
onLBSelChanged = "[] call KPLIB_fnc_cratefiller_showInventory";
};

class KPLIB_RefreshCargo: KPGUI_PRE_CloseCross {
text = "KPGUI\res\icon_refresh.paa";
x = KP_GETCX(KP_X_VAL_S,KP_WIDTH_VAL_S,23,24);
y = KP_GETCY(KP_Y_VAL_S,KP_HEIGHT_VAL_S,3,48);
w = KP_GETW(KP_WIDTH_VAL_S,24);
h = KP_GETH(KP_HEIGHT_VAL_S,24);
tooltip = "$STR_KPLIB_DIALOG_CRATEFILLER_REFRESH_TT";
action = "[] call KPLIB_fnc_cratefiller_getNearStorages";
};

// Inventory

class KPLIB_InventoryTitle: KPLIB_TransportTitle {
text = "$STR_KPLIB_DIALOG_CRATEFILLER_TITLEINVENTORY";
y = KP_GETCY(KP_Y_VAL_S,KP_HEIGHT_VAL_S,5,48);
};

class KPLIB_ExportName: KPLIB_SearchBar {
idc = KPLIB_IDC_CRATEFILLER_EXPORTNAME;
x = KP_GETCX(KP_X_VAL_S,KP_WIDTH_VAL_S,2,4);
Expand Down
91 changes: 91 additions & 0 deletions Missionframework/modules/27_mission/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,91 @@
# KP Liberation Module Description

## Misison Module
This module provides an mission framework to register created missions.
Also it provides a dialog which can start and abort sidemissions.

### Dependencies
* Init
* Common
* Permission

### Consumed events
**KPLIB_doLoad** (server side)
Calls KPLIB_fnc_mission_loadData to process saved module data

**KPLIB_doSave** (server side)
Calls KPLIB_fnc_mission_saveData to add the module data to the save array

**KPLIB_missionExec** (server side)
Processes a mission start or abort dependent on the passed arguments

**KPLIB_missionEnd** (server side)
Calls KPLIB_fnc_mission_endMission to delete the ended mission from the running missions

### Emitted events
**KPLIB_missionExec** (server side)
Processes a mission start or abort dependent on the passed arguments

### Functions
* KPLIB_fnc_mission_abortMission

*Aborts the given mission.*

* KPLIB_fnc_mission_buttonClick

*Selects which mission should be started/aborted and starts th next function.*

* KPLIB_fnc_mission_displayMission

*Displays the information for the given mission.*

* KPLIB_fnc_mission_endMission

*Deletes the mission from the running missions*

* KPLIB_fnc_mission_loadData

*Loads data which is bound to the this module from the given save data or initializes needed data for a new campaign.*

* KPLIB_fnc_mission_openDialog

*Opens the mission dialog.*

* KPLIB_fnc_mission_postInit

*Module post initialization.*

* KPLIB_fnc_mission_preCheck

*Checks the mission conditions on a changing selection and disables the button.*

* KPLIB_fnc_mission_preInit

*Module pre initialization*

* KPLIB_fnc_mission_readData

*Reads the data of the given listbox.*

* KPLIB_fnc_mission_registerMission

*Registers a mission for the usage as event or "buyable" sidemission.*

* KPLIB_fnc_mission_saveData

*Fetches data which is bound to this module and send it to the global save data array.*

* KPLIB_fnc_mission_settings

*CBA Settings initialization for this module.*

* KPLIB_fnc_mission_setupPlayerActions

*Initialization of actions available to players.*

* KPLIB_fnc_mission_startMission

*Starts the given mission or selects one from the given array.*

### Scripts
No scripts will be started by this module
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
#include "script_component.hpp"
/*
KPLIB_fnc_mission_abortMission
File: fn_mission_abortMission.sqf
Author: KP Liberation Dev Team - https://github.com/KillahPotatoes
Date: 2019-06-13
Last Update: 2019-06-23
License: GNU General Public License v3.0 - https://www.gnu.org/licenses/gpl-3.0.html
Public: No
Description:
Aborts the given mission.
Parameter(s):
_mission - String of the mission [STRING, defaults to ""]
Returns:
Function reached the end [BOOL]
*/

params [
["_mission", "", [""]]
];

// Exit if one of the condition isn't true
if (_mission isEqualTo "") exitWith {
false
};

// Get data from namespace
private _missionData = MGVAR(_mission, []);
private _runningMissions = MGVAR("runningMissions", []);
private _cost = _missionData select 9;
_cost params [
"_costSupply",
"_costAmmo",
"_costFuel",
"_costIntel"
];
private _FOB = (_runningMissions select (_runningMissions findIf {(_x select 0) isEqualTo _mission})) select 1;
private _crateCapacity = 0;
private _crateCount = 0;
_costSupply = _costSupply * (KPLIB_param_missionRefund / 100);
_costAmmo = _costAmmo * (KPLIB_param_missionRefund / 100);
_costFuel = _costFuel * (KPLIB_param_missionRefund / 100);
_costIntel = _costIntel * (KPLIB_param_missionRefund / 100);

// Check if the mission is a buyable mission and if there's enough empty storage capacity
if !(_missionData select 0) then {
private _supplyCrates = ceil (_costSupply / KPLIB_param_crateVolume);
private _ammoCrates = ceil (_costAmmo / KPLIB_param_crateVolume);
private _fuelCrates = ceil (_costFuel / KPLIB_param_crateVolume);
private _crateCount = _supplyCrates + _ammoCrates + _fuelCrates;
private _storages = [getMarkerPos _FOB, KPLIB_param_fobRange] call KPLIB_fnc_resources_getStorages;

{
_crateCapacity = _crateCapacity + ([_x] call KPLIB_fnc_resources_getStorageSpace);
} forEach _storages;
};

// Exit if there's not enough storage
if (_crateCapacity < _crateCount) exitWith {
[
["a3\3den\data\controlsgroups\tutorial\close_ca.paa", 1, [1,0,0]],
[localize "STR_KPLIB_HINT_MISSIONSTORAGE"]
] call CBA_fnc_notify;
false
};

// Delete the mission from the running mission data
_runningMissions deleteAt (_runningMissions findIf {(_x select 0) isEqualTo _mission});

// Refund the costs
if !(_cost isEqualTo [0, 0, 0, 0]) then {
[_FOB, _costSupply, _costAmmo, _costFuel] call KPLIB_fnc_resources_refund;
[_costIntel] call KPLIB_fnc_resources_addIntel;
};

// Set data in namespace
MSVAR("runningMissions", _runningMissions);

// Execute the abort function via server event
["KPLIB_missionExec", [_missionData select 2]] call CBA_fnc_serverEvent;

closeDialog 0;
[{!dialog}, {[] call KPLIB_fnc_mission_openDialog;}] call CBA_fnc_waitUntilAndExecute;

true
Loading

0 comments on commit 6049e1c

Please sign in to comment.