Browse Source

Logging and some TODOs

m3ales 4 năm trước cách đây
mục cha
commit
ff2c85676d

+ 25 - 7
addons - Copy/RD501_Droid_Dispenser/functions/fnc_spawnDroidPFH.sqf

@@ -4,21 +4,39 @@ _args params ["_target"];
 systemChat format["Evaluating PFH %1",_handle];
 
 if(isNil "_target") exitWith {
-	systemChat format["Removing PFH %1 due to null target",_handle];
+	LOGF_1("Removing PFH %1, Reason: Null Target",_handle);
+	[_handle] call CBA_fnc_removePerFrameHandler;
 };
 
-if(!isServer || ! alive _target) exitWith {
-	systemChat format["Removing PFH %1",_handle];
+if(!isServer) exitWith {
+	LOGF_1("Removing PFH %1, Reason: Not Server",_handle);
+	[_handle] call CBA_fnc_removePerFrameHandler;
+}; 
+
+if(!alive _target) exitWith {
+	LOGF_1("Removing PFH %1, Reason: Spawner Dead",_handle);
 	[_handle] call CBA_fnc_removePerFrameHandler;
 };
+
 _group = _target getVariable QGVAR(group);
 
+if(isNil "_group") then 
+{
+	LOGF_1("PFH %1 Group empty, creating new",_handle);
+	_target setVariable [QGVAR(group), createGroup [opfor, true]];
+	_group = _target getVariable QGVAR(group);
+};
+
 _aliveUnits = ({alive _x} count (units _group));
-systemChat format["%1 :: %2",_target,_aliveUnits];
+LOGF_2("Alive units for spawner %1 :: %2",_target,_aliveUnits);
 if(_aliveUnits < _target getVariable QGVAR(maxUnits)) exitWith 
 {
-	_selectedUnit = selectRandom (_target getVariable QGVAR(possibleUnits));
-	systemChat format["%1 spawning in %2",_target,_selectedUnit];
+	_possibleUnits = _target getVariable QGVAR(possibleUnits);
+	_selectedUnit = selectRandom _possibleUnits;
+	if(_selectedUnit == _possibleUnits select 0) then {
+		_selectedUnit = selectRandom _possibleUnits; // if its a b2, (first be default atm) random again (requires 2 rolls on b2 to spawn one)
+	};
+	LOGF_2("%1 spawning in %2",_target,_selectedUnit);
 	_group createUnit [_selectedUnit, position _target, [], 0, "NONE"];
 };
-systemChat format["%1 not spawning anything"];
+LOGF_1("%1 not spawning anything",_target);

+ 10 - 4
addons - Copy/RD501_Droid_Dispenser/functions/fnc_spawnerInit.sqf

@@ -1,12 +1,18 @@
 #include "function_macros.hpp"
 params ["_target"];
-if(!isServer) exitWith { systemChat "Not Server, Exiting PFH"; };
-systemChat format["Initialising spawner %1",_target];
+
+if(!isServer) exitWith
+{	
+	LOG_ERROR("Not Server, Exiting PFH"); 
+};
+
+LOGF_1("Initialising spawner %1",_target);
+// TODO: Read these vars from config, maybe CfgVehicles to allow placement of vehicles, although may be better to use static object with HP and destroyed mesh rather
 _target setVariable [QGVAR(group), createGroup [opfor, true]]; // group that units will be spawned into
 _target setVariable [QGVAR(boundUnits), []]; // units currently bound to this unit
 _target setVariable [QGVAR(maxUnits),20]; // max units that can be alive at any time from this spawner
-_target setVariable [QGVAR(possibleUnits),["RD501_opfor_unit_B2_droid_Standard","RD501_opfor_unit_b1_grenadier","RD501_opfor_unit_B2_droid_Standard","RD501_opfor_unit_B1_AA","RD501_opfor_unit_B1_AT_heavy","RD501_opfor_unit_B1","RD501_opfor_unit_B1_marksman"]];
+_target setVariable [QGVAR(possibleUnits),["RD501_opfor_unit_B2_droid_Standard","RD501_opfor_unit_b1_grenadier","RD501_opfor_unit_B2_droid_Standard","RD501_opfor_unit_B1_AT_heavy","RD501_opfor_unit_B1","RD501_opfor_unit_B1_marksman"]];
 // Start PFH
-systemChat format["Starting PFH on %1",_target];
+LOGF_1("Attempting to start PFH on %1",_target);
 _params= [_target];
  _handle = [FUNC(spawnDroidPFH), GVAR(spawnTime), _params] call CBA_fnc_addPerFrameHandler;

+ 10 - 1
addons - Copy/RD501_Droid_Dispenser/functions/function_macros.hpp

@@ -1 +1,10 @@
-#include "../config_macros.hpp";
+#include "../config_macros.hpp";
+#define LOG_BASE(level,msg) diag_log text format[QUOTE(ADDON[level]: %1), msg]
+#define LOG(msg) LOG_BASE(DEBUG, LOG_FILENUMBER(msg))
+#define LOGF_1(msg,arg0) LOG(format[ARR_2(msg,arg0)])
+#define LOGF_2(msg,arg0,arg1) LOG(format[ARR_3(msg,arg0,arg1)])
+#define LOGF_3(msg,arg0,arg1,arg2) LOG(format[ARR_4(msg,arg0,arg1,arg2)])
+#define LOG_ERROR(msg) LOG_BASE(ERR,LOG_FILENUMBER(msg))
+#define LOG_ERRORF_1(msg,arg0) LOG_ERROR(format[ARR_2(msg,arg0)])
+#define LOG_ERRORF_2(msg,arg0,arg1) LOG_ERROR(format[ARR_3(msg,arg0,arg1)])
+#define LOG_FILENUMBER(msg) format [ARR_4('%1 at %2:%3',msg,__FILE__,__LINE__ + 1)]