This commit is contained in:
vbawol 2017-06-18 07:17:33 -05:00
parent 177831d1bb
commit 5c5e0ad49a
4 changed files with 44 additions and 31 deletions

View File

@ -9,7 +9,7 @@
https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server_settings/EpochEvents/DebrisSpawner.sqf
*/
//[[[cog import generate_private_arrays ]]]
private ["_allRoads","_allowDebris","_debris","_debrisCounter","_debrisLocations","_debrisLocationsKey","_debrisLocationsTMP","_debug","_expiresDebris","_export","_instanceID","_intersections","_marker","_maxDebrisLimit","_newDebrisCounter","_object","_offsetX","_offsetY","_position","_response","_rng","_rngChance","_scriptHiveKey","_seed","_selectedDebris","_worldSize"];
private ["_allRoads","_allowDebris","_debris","_debrisCounter","_debrisLocations","_debrisLocationsKey","_debrisLocationsTMP","_debug","_disallowedLocations","_expiresDebris","_export","_instanceID","_intersections","_marker","_maxDebrisLimit","_nearbyLocations","_newDebrisCounter","_object","_offsetX","_offsetY","_position","_response","_rng","_rngChance","_scriptHiveKey","_seed","_selectedDebris","_upperPos","_worldSize"];
//[[[end]]]
_debug = false;
_expiresDebris = 604800;
@ -34,13 +34,16 @@ _debris = [
"Land_Wreck_Truck_dropside_F",
"Land_Wreck_HMMWV_F"
];
_disallowedLocations = ["Airport"];
_debrisCounter = 0;
_newDebrisCounter = 0;
_worldSize = worldSize/2;
_instanceID = call EPOCH_fn_InstanceID;
_maxDebrisLimit = 500; // max total objects to spawn
_rngChance = 0.95; // Lower this to spawn more positions
_scriptHiveKey = "EPOCH:DynamicDebris456"; // change this to force a new seed to be generated.
_scriptHiveKey = "EPOCH:DynamicDebris789"; // change this to force a new seed to be generated.
_debrisLocationsKey = format ["%1:%2", _instanceID, worldname];
_response = [_scriptHiveKey, _debrisLocationsKey] call EPOCH_fnc_server_hiveGETRANGE;
@ -59,37 +62,47 @@ if (_status == 1 && _data isEqualType [] && !(_data isEqualTo [])) then {
diag_log format["DEBUG: Generating new Debris Locations... with seed %1.",_seed];
{
if (_newDebrisCounter >= _maxDebrisLimit) exitWith {};
_position = getPosWorld _x;
_position = getPosASL _x;
_position params ["_posX","_posY"];
_rng = _seed random [_posX,_posY];
if (_rng > _rngChance) then {
if (_debug) then {
_marker = createMarker[str(_position), _position];
_marker setMarkerShape "ICON";
_marker setMarkerType "waypoint";
_marker setMarkerColor "ColorGreen";
};
_selectedDebris = selectRandom _debris;
_offsetX = (random 10) - 5;
_offsetY = (random 10) - 5;
_position set [0,(_position select 0) + _offsetX];
_position set [1,(_position select 1) + _offsetY];
_position set [2,0];
_intersections = lineIntersectsSurfaces [[_position select 0,_position select 1,1000], _position, objNull, objNull, true, 1];
if !(_intersections isEqualTo []) then {
(_intersections select 0) params ["_intersectPosASL","_surfaceNormal","_intersectObject","_parentObject"];
_allowDebris = true;
if !(isNull _intersectObject) then {
_allowDebris = !((typeOf _intersectObject) in _debris);
_nearbyLocations = nearestLocations [_position, _disallowedLocations, 100];
if (_nearbyLocations isEqualTo []) then {
if (_debug) then {
_marker = createMarker[str(_position), _position];
_marker setMarkerShape "ICON";
_marker setMarkerType "waypoint";
_marker setMarkerColor "ColorGreen";
};
if (_allowDebris) then {
_object = createSimpleObject [_selectedDebris, _intersectPosASL];
_object setDir random 360;
_object setVectorUp _surfaceNormal;
_object setPosASL _intersectPosASL;
_export = [_selectedDebris,getPosWorld _object, vectorDir _object, vectorUp _object];
_debrisLocationsTMP pushBack _export;
_newDebrisCounter = _newDebrisCounter + 1;
_selectedDebris = selectRandom _debris;
_offsetX = (random 10) - 5;
_offsetY = (random 10) - 5;
_position set [0,(_position select 0) + _offsetX];
_position set [1,(_position select 1) + _offsetY];
_position set [2,(_position select 2) - 1];
_upperPos = [] + _position;
_upperPos set [2,(_position select 2) + 3];
_intersections = lineIntersectsSurfaces [_upperPos, _position, objNull, objNull, true, 1];
if !(_intersections isEqualTo []) then {
(_intersections select 0) params ["_intersectPosASL","_surfaceNormal","_intersectObject","_parentObject"];
_allowDebris = true;
if !(isNull _intersectObject) then {
_allowDebris = !((typeOf _intersectObject) in _debris);
};
if (_allowDebris) then {
_object = createSimpleObject [_selectedDebris, _intersectPosASL];
_object setDir random 360;
_object setVectorUp _surfaceNormal;
_object setPosASL _intersectPosASL;
_export = [_selectedDebris,getPosWorld _object, vectorDir _object, vectorUp _object];
_debrisLocationsTMP pushBack _export;
_newDebrisCounter = _newDebrisCounter + 1;
};
};
};
};

View File

@ -1 +1 @@
build=790;
build=794;

View File

@ -1 +1 @@
790
794