GMS_RC/@GMS/addons/GMS/Compiles/Missions/fn_initializeMission.sqf

278 lines
9.6 KiB
Plaintext
Raw Permalink Normal View History

2023-09-23 14:05:31 +00:00
/*
GMS_fnc_initializeMission
Perform all functions necessary to initialize a mission.
2023-10-25 23:53:01 +00:00
2023-09-23 14:05:31 +00:00
*/
#include "\x\addons\GMS\Compiles\Init\GMS_defines.hpp"
2023-09-23 14:05:31 +00:00
private ["_coords","_coordArray","_return"];
params[
"_key", // This key can be used to seach the list of available mission types to update that list when a mission is completed or times out
"_missionConfigs", // Selfevident but this is an array with all configs for the mission
"_missionCount", // The number of missions run thus far which is used to unsure each marker has a unique name
2023-10-25 23:53:01 +00:00
"_isStatic",
"_missionFile"
2023-09-23 14:05:31 +00:00
];
// _missionConfigs is configured as:
/*
params [
_aiDifficultyLevel, // index 0
_markerConfigs, // index 1
_endCondition, // index 2
_isscubamission, // index 3
_missionLootConfigs, // index 4
_aiConfigs, // index 5
_missionMessages, // index 6
_paraConfigs, // index 7
_defaultMissionLocations, // index 8
_maxMissionRespawns, // index 9
_timesSpawned, // index 10
_chanceMissionSpawned, // index 11
_isSpawned, // index 12
_spawnedAt // index 13
];
*/
2023-09-23 14:05:31 +00:00
_missionConfigs params [
"_difficulty", // index 0
"_markerConfigs", // index 1
"_endCondition", // index 2
"_isscubamission", // index 3
"_missionLootConfigs", // index 4
"_aiConfigs", // index 5
"_missionMessages", // index 6
"_paraConfigs", // index 7
2023-09-23 14:05:31 +00:00
"_defaultMissionLocations",
"_maxMissionRespawns", // index 9
"_timesSpawned", // index 10
"_chanceMissionSpawned", // index 11
"_isSpawned", // index 12
"_spawnedAt" // index 13
];
#define timesSpawnedIndex 11
2023-10-25 23:53:01 +00:00
private _initialized = 0;
2023-09-23 14:05:31 +00:00
2023-10-25 23:53:01 +00:00
private _markers = [];
/*
private _markerConfigs = [
_markerLabel,
_markerMissionName, // Name used for setMarkerText and also for the root name for all markers
_markerShape,
_markerColor,
_markerSize,
_markerBrush,
_showMarker
];
*/
_markerConfigs params [
["_markerLabel","NoLabelGiven"], // Text used to label the marker
["_markerMissionName","NoNameGiven"], // the name used when creating the marker. Must be unique.
["_markerShape","NoTypeGiven"], // Use either the name of the icon or "ELLIPSE" or "RECTANGLE" where non-icon markers are used
["_markerColor","NoColorGiven"],
["_markerSize",[0,0]],
["_markerBrush","NoBrushGiven"],
["_showMarkers",true]
2023-09-23 14:05:31 +00:00
];
2023-10-25 23:53:01 +00:00
try {
[format["_initializeMission(248): Initializeing mission %1",_missionFile]] call GMS_fnc_log;
//if (GMS_debugLevel > 0) then {[format["_initializeMission (82): _timesSpawned %1 | _maxMissionRespawns %2 | _missionFile %3",_timesSpawned,_maxMissionRespawns,_missionFile]] call GMS_fnc_log};
2023-10-25 23:53:01 +00:00
if (_timesSpawned >= _maxMissionRespawns && !(_maxMissionRespawns == -1)) throw -2;
2023-09-23 14:05:31 +00:00
2023-10-25 23:53:01 +00:00
// If the mission is a static mission and it has been spawned but not cleared then pass back a code indicating that
if (_isStatic && _isSpawned) throw 3; // We do not want to respawn this static mission till it has been cleared.
// If the mission has not been spawned, but is a static mission and could be spawned if it met the test for chance of a spawn, pass back a code indicating that.
if (random(1) > _chanceMissionSpawned && (_isStatic) && (_timesSpawned == 0)) throw 2;
2023-09-23 14:05:31 +00:00
2023-10-25 23:53:01 +00:00
// do not initialize if the odds of spawning are not favorable.
if (random(1) > _chanceMissionSpawned) throw 0;
/*
private _labels = ["_markerLabel","_markerMissionName","_markerShape","_markerColor","_markerSize","_markerBrush","_showMarkers"];
{
[format["_initializeMission (95): _markerConfigs index %1 | name %2 = %3",_forEachIndex, _labels select _forEachIndex, _x]] call GMS_fnc_log;
} forEach _markerConfigs;
*/
// [format["initializeMission (100): _markerShape = %1",_markerShape]] call GMS_fnc_log;
if (_markerMissionName isEqualTo "NoNameGiven") throw -1; // This is a FATAL ERROR
if !(toLowerANSI (_markerShape) in ["ellipse","rectangle"] || {isClass(configFile >> "CfgMarkers" >> _markerShape)} ) then
{
[format["_markerShape set to 'ELLIPSE': Illegal marker type %1 used for _missionFile %2",_markerShape,_missionFile,_difficulty],"warning"] call GMS_fnc_log;
_markerShape = GMS_defaultMarkerType;
_markerSize = GMS_defaultMarkerSize;
_markerBrush = GMS_defaultMarkerBrush;
};
if !(isClass(configFile >> "CfgMarkerColors" >> _markerColor)) then
{
[format["_markerColor set to 'default': Illegal color %1 used for mission %2 of difficulty %3",_markerColor,_missionFile,_difficulty],"warning"] call GMS_fnc_log;
_markerColor = "NoColorGiven";
};
if (_markerLabel isEqualTo "NoLabelGiven") then {
[format["No Marker Text (_markerLabel) defined for mission %1",_missionFile],'warning'] call GMS_fnc_log;
// Probably not a fatal error but it will look funny on the server
};
if (_markerColor isEqualTo "NoColorGiven") then {
[format["No Marker Color (_markerColor) defined for mission %1 SO GMS_defaultMarkerColor used instead",_missionFile],'warning'] call GMS_fnc_log;
// Probably not FATAL but will apply a Default Color anyhow
_markerColor = GMS_defaultMarkerColor;
};
if (_markerShape isEqualTo "NoTypeGiven") then {
[format["No Marker Type (triangle, mil_dot) or Shape ('Elipse', 'Rectangle') defined for mission %1 SO default setting GMS_defaultMarkerType used",_missionFile],'warning'] call GMS_fnc_log;
// Apply a default setting here
_markerShape = GMS_defaultMarkerType;
};
if !(_markerSize isEqualTypeArray [0,0]) then {
[format["_markerSize = %1 BUT must be given as an array of [xsize, ysize] SO defaults of GMS_defaultMarkerSize were used for mission file %1",_markerSize,_missionFile],'warning'] call GMS_fnc_log;
_markerSize = GMS_defaultMarkerSize;
// Just alert the server scripter of the problem and apply a default.
};
if (toUpper(_markerShape) in ["ELLIPSE","RECTANGLE"] && (_markerBrush isEqualTo "NoBrushGiven" || !(isClass(configFile >> "CfgMarkerBrushes" >> _markerBrush)))) then {
[format["_markerBrush not defined for shaped marker in mission %1 SO default of GMS_defaultMarkerBrush used"],'warning'] call GMS_fnc_log;
_markerBrush = GMS_defaultMarkerBrush;
};
_coordsArray = [];
if !(_defaultMissionLocations isEqualTo []) then
2023-09-23 14:05:31 +00:00
{
2023-10-25 23:53:01 +00:00
_coords = selectRandom _defaultMissionLocations;
2023-09-23 14:05:31 +00:00
} else {
2023-10-25 23:53:01 +00:00
if (_isScubaMission) then
{
_coords = [] call GMS_fnc_findShoreLocation;
} else {
_coords = [] call GMS_fnc_findSafePosn;
_coords = [_coords select 0, _coords select 1, 0];
};
2023-09-23 14:05:31 +00:00
};
2023-10-25 23:53:01 +00:00
_missionConfigs set[timesSpawnedIndex, _timesSpawned + 1];
_missionConfigs set[isSpawned, true];
_missionConfigs set[spawnedAt, diag_tickTime];
2023-10-25 23:53:01 +00:00
if (_coords isEqualTo [] || {_coords isEqualTo [0,0,0]}) throw -2;
2023-09-23 14:05:31 +00:00
2023-10-25 23:53:01 +00:00
if (GMS_debugLevel > 0) then {[format["Initializing mission: _coords = %1 | _markerMissionName %2 | _missionFile = %3",_coords,_markerMissionName,_missionFile]] call GMS_fnc_log};
2023-09-23 14:05:31 +00:00
2023-10-25 23:53:01 +00:00
GMS_ActiveMissionCoords pushback _coords;
GMS_missionsRunning = GMS_missionsRunning + 1;
2023-09-23 14:05:31 +00:00
2023-10-25 23:53:01 +00:00
private _markers = [];
2023-09-23 14:05:31 +00:00
2023-10-25 23:53:01 +00:00
/*
Handle map markers
*/
2023-09-23 14:05:31 +00:00
2023-10-25 23:53:01 +00:00
private "_markerPos";
if (GMS_labelMapMarkers select 0) then
{
_markerPos = _coords;
};
if !(GMS_preciseMapMarkers) then
{
_markerPos = [_coords,75] call GMS_fnc_randomPosition;
};
2023-10-25 23:53:01 +00:00
// _markers holds the two markers generated for the mission.
// The first can be "" if the marker type used is an icon such as a triangle.
// The second is always an icon which may have a label.
_markers = [
format["%1:%2",_markerMissionName,_missionCount],
_markerPos,
_markerMissionName,
_markerColor,
_markerShape,
_markerSize,
_markerBrush,
_showMarkers,
_missionFile
] call GMS_fnc_createMissionMarkers;
2023-10-25 23:53:01 +00:00
if (_markers isEqualTo []) throw -1; // Something happened when creating markers so alert the server scripter.
/*
Send a message to players.
*/
_missionMessages params [
"_assetKilledMsg",
"_endMsg",
"_timeoutMsg",
"_startMsg"
];
2023-09-23 14:05:31 +00:00
2023-10-25 23:53:01 +00:00
[["start",_startMsg,_markerMissionName]] call GMS_fnc_messageplayers;
2023-09-23 14:05:31 +00:00
2023-10-25 23:53:01 +00:00
#define missionTimeoutAt (diag_tickTime + GMS_MissionTimeout)
#define triggered 0
#define objects []
#define hiddenObjects []
#define mines []
#define crates []
#define missionVehicles []
#define missionAI []
#define lootVehicles []
#define assetSpawned objNull
2023-09-23 14:05:31 +00:00
2023-10-25 23:53:01 +00:00
private _missionData = [
_coords, // index 0
mines, // index 1
objects, // index 2
hiddenObjects, // index 3
crates, // index 4
missionAI, // index 5
assetSpawned, /// Used for missions for which a hostage or target is spawned.
missionVehicles, // index 7
lootVehicles, // index 8
_markers // index 9
];
2023-10-15 18:53:11 +00:00
2023-11-04 04:46:53 +00:00
#define spawnPara true
GMS_initializedMissionsList pushBack [_key, missionTimeoutAt, triggered, _missionData, _missionConfigs, spawnPara,_isStatic,_missionFile];
2023-10-25 23:53:01 +00:00
// Repair any damage done by prior activities.
{_x setDamage 0} forEach ( nearestObjects [_coords, ["Building"], 500]);
2023-10-25 23:53:01 +00:00
throw 1; // Normal script termination
}
catch {
switch (_exception) do {
case -3: {
[format["No Safe Mission Spawn Position Found to spawn Mission %1",_missionFile],'warning'] call GMS_fnc_log;
_initialized = -3;
};
case -2: { // The mission was spawned the maximum number of times.
[format["Mission %1 has been spawn the maximum allowable number of times",_missionFile]] call GMS_fnc_log;
_initialized = -2;
};
2023-10-25 23:53:01 +00:00
case -1: { // A fatal error in marker configs was found or GMS_fnc_createMissionMarkers did not create any for some reason.
_initialized = -1;
};
2023-10-21 11:42:13 +00:00
2023-10-25 23:53:01 +00:00
case 0: { // The mission failed the test for chance it would be spawned.
_initialized = 0;
};
case 1: { // The marker was configured in a legal way and a safe position was found to spawn it.
_initialized = 1;
};
case 2: { // This static mission failed the test for chance that it would be spawned.
_initialized = 2;
};
case 3: { // Case of a static mission that has already been spawned.
_initialized = 3;
};
};
};
2023-10-21 11:42:13 +00:00
2023-09-23 14:05:31 +00:00
_initialized