This commit is contained in:
A Man
2020-01-11 00:18:43 +01:00
83 changed files with 2105 additions and 3115 deletions

View File

@@ -16,7 +16,7 @@ Author:
#include "\z\addons\dayz_code\util\Vector.hpp"
#include "\z\addons\dayz_code\loot\Loot.hpp"
private ["_vectorUp","_type","_config","_lootChance","_lootPos","_lootGroup","_worldPos","_existingPile","_loot","_obj"];
private ["_vectorUp","_type","_config","_lootChance","_lootPos","_lootGroup","_worldPos","_existingPile","_loot","_group","_smallGroup"];
_obj = _this select 0;
_type = _this select 1;
@@ -27,8 +27,18 @@ _lootChance = getNumber (_config >> "lootChance");
if (_lootChance <= 0 or ([_obj] call DZE_SafeZonePosCheck)) exitWith {};
_group = getText(_config >> "lootGroup");
_lootPos = getArray (_config >> "lootPos");
_lootGroup = Loot_GetGroup(getText(_config >> "lootGroup"));
_lootPos = [_lootPos,5] call fn_shuffleArray;
// Military buildings spawn matching loot.
if (_group in ["Military","MilitaryIndustrial"]) then {
_lootGroup = Loot_SelectSingle(Loot_GetGroup(_group));
_smallGroup = _lootGroup select 2;
_lootGroup = Loot_GetGroup(_lootGroup select 1);
} else {
_lootGroup = Loot_GetGroup(_group);
};
{
//Get the world position of the spawn position
@@ -39,11 +49,9 @@ _lootGroup = Loot_GetGroup(getText(_config >> "lootGroup"));
{
deleteVehicle _x;
dayz_currentWeaponHolders = dayz_currentWeaponHolders - 1;
}
foreach (_worldPos nearObjects ["ReammoBox", 1]);
} count (_worldPos nearObjects ["ReammoBox", 1]);
if (_lootChance > random 1 && {dayz_currentWeaponHolders < dayz_maxMaxWeaponHolders}) then
{
if (_lootChance > random 1 && {dayz_currentWeaponHolders < dayz_maxMaxWeaponHolders}) then {
Loot_SpawnGroup(_lootGroup, _worldPos);
};
}
@@ -55,8 +63,15 @@ foreach _lootPos;
if (isArray (_config >> "lootPosSmall")) then {
_lootPos = getArray (_config >> "lootPosSmall");
_lootGroup = Loot_GetGroup((getText(_config >> "lootGroup")) + "Small");
if (!isNil "_smallGroup") then {
_lootGroup = Loot_GetGroup(_smallGroup);
} else {
_lootGroup = Loot_GetGroup((_group) + "Small");
};
if (_lootGroup >= 1) then {
_lootPos = [_lootPos,5] call fn_shuffleArray;
{
//Get the world position of the spawn position
_worldPos = _obj modelToWorld _x;
@@ -65,10 +80,9 @@ if (isArray (_config >> "lootPosSmall")) then {
{
deleteVehicle _x;
dayz_currentWeaponHolders = dayz_currentWeaponHolders - 1;
} foreach (_worldPos nearObjects ["ReammoBox", 1]);
} count (_worldPos nearObjects ["ReammoBox", 1]);
if (_lootChance > random 1 && {dayz_currentWeaponHolders < dayz_maxMaxWeaponHolders}) then
{
if (_lootChance > random 1 && {dayz_currentWeaponHolders < dayz_maxMaxWeaponHolders}) then {
Loot_SpawnGroup(_lootGroup, _worldPos);
};
} foreach _lootPos;

View File

@@ -2,58 +2,43 @@
Created exclusively for ArmA2:OA - DayZMod.
Please request permission to use/alter/distribute from project leader (R4Z0R49)
*/
private ["_wreck","_iPos","_nearByZed","_nearByPlayer","_rnd","_positions","_zombieChance","_unitTypes","_min","_max","_num","_clean","_obj","_type","_config","_canLoot","_originalPos","_fastRun","_enabled","_i","_Pos"];
private ["_type","_position","_minDist","_maxDist","_isWreck","_nearByPlayer","_iPos","_positions","_zombieChance","_unitTypes","_min","_max","_num","_clean","_obj","_config","_i","_objPos"];
_obj = _this select 0;
_type = _this select 1;
_objPos = _this select 1;
_config = _this select 2;
_wreck = false;
if (count _this > 3) then {
_wreck = _this select 3;
};
_originalPos = getPosATL _obj;
_isWreck = _this select 3;
_type = typeOf _obj;
if (!([_originalPos] call DZE_SafeZonePosCheck)) then {
//Get zombie class
_unitTypes = getArray (_config >> "zombieClass");
_min = getNumber (_config >> "minRoaming");
_max = getNumber (_config >> "maxRoaming");
if (!([_objPos] call DZE_SafeZonePosCheck)) then {
_unitTypes = getArray (_config >> "zombieClass");
_min = getNumber (_config >> "minRoaming");
_max = getNumber (_config >> "maxRoaming");
_zombieChance = getNumber (_config >> "zombieChance");
//Walking Zombies
_num = (round(random _max)) max _min; // + round(_max / 3);
//diag_log ("Class: " + _type + " / Zombies: " + str(_unitTypes) + " / Walking: " + str(_num));
_num = round(random(_max - _min) + _min);
_minDist = (sizeOf _type);
_maxDist = if (_isWreck) then {(_minDist + 20)} else {(_minDist + 10)}; // zeds at crash sites can spawn further away.
for "_i" from 0 to _num do
{
//_iPos = _obj modelToWorld _originalPos;
// Walking Zombies
for "_i" from 0 to _num do {
if ((dayz_spawnZombies < dayz_maxControlledZombies) && {dayz_CurrentNearByZombies < dayz_maxNearByZombies} && {dayz_currentGlobalZombies < dayz_maxGlobalZeds}) then {
[_originalPos,true,_unitTypes,_wreck] call zombie_generate;
_position = [_objPos,_minDist,_maxDist,1] call fn_selectRandomLocation;
[_position,true,_unitTypes,_isWreck,false] call zombie_generate;
};
};
//Add Internal Zombies
if ((random 1) < _zombieChance) then {
_clean = {alive _x} count ((getPosATL _obj) nearEntities ["zZombie_Base",(sizeOf _type)]) == 0;
if (_clean) then {
_positions = getArray (_config >> "zedPos");
//diag_log format["Building: %1 / Positions: %2 / Chance: %3",_type,_positions,_zombieChance];
{
_Pos = [_x select 0, _x select 1, 0];
_rnd = random 1;
if (_rnd < _zombieChance) then {
_iPos = _obj modelToWorld _Pos;
_nearByZed = {alive _x} count (_iPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 10)]) > 0;
_nearByPlayer = ({isPlayer _x} count (_iPos nearEntities ["CAManBase",30])) > 0;
//diag_log ("BUILDING: " + _type + " / " + str(_nearByZed) + " / " + str(_nearByPlayer));
if ((dayz_spawnZombies < dayz_maxControlledZombies) && {dayz_CurrentNearByZombies < dayz_maxNearByZombies} && {dayz_currentGlobalZombies < dayz_maxGlobalZeds}) then {
if (!_nearByPlayer and {!_nearByZed}) then {
[_iPos,false,_unitTypes,false] call zombie_generate;
};
};
// Internal Zombies
_nearByPlayer = ({isPlayer _x} count (_objPos nearEntities ["CAManBase",30])) > 0;
if (!_nearByPlayer) then {
_positions = getArray (_config >> "zedPos");
{
if (random 1 < _zombieChance) then {
_iPos = _obj modelToWorld _x;
_iPos set [2, 0 max (_iPos select 2)];
if ((dayz_spawnZombies < dayz_maxControlledZombies) && {dayz_CurrentNearByZombies < dayz_maxNearByZombies} && {dayz_currentGlobalZombies < dayz_maxGlobalZeds}) then {
[_iPos,false,_unitTypes,false,true] call zombie_generate;
};
} forEach _positions;
};
};
} forEach _positions;
};
};
//diag_log ("2 end");

View File

@@ -0,0 +1,39 @@
// This function checks to see if a potential zombie spawn position is in the field of view of near players.
private ["_isOk","_zPos","_fov","_safeDistance","_farDistance","_xasl","_eye","_ed","_deg"];
_isOk = true;
_zPos = +(_this select 0);
if (count _zPos < 3) exitWith {
diag_log format["%1::fn_fieldOfView illegal pos %2", __FILE__, _zPos];
false
};
_zPos = ATLtoASL _zPos;
_fov = _this select 1; // players half field of view
_safeDistance = _this select 2; // minimum distance. closer is wrong
_farDistance = _this select 3; // distance further we won't check
_zPos set [2, (_zPos select 2) + 1.7];
{
_xasl = getPosASL _x;
if (_xasl distance _zPos < _farDistance) then {
if (_xasl distance _zPos < _safeDistance) then {
_isOk = false;
} else {
_eye = eyePos _x; // ASL
_ed = eyeDirection _x;
_ed = (_ed select 0) atan2 (_ed select 1);
_deg = [_xasl, _zPos] call BIS_fnc_dirTo;
_deg = (_deg - _ed + 720) % 360;
if (_deg > 180) then { _deg = _deg - 360; };
if ((abs(_deg) < _fov) && {( // in right angle sector?
(!(terrainIntersectASL [_zPos, _eye]) // no terrain between?
&& {(!(lineIntersects [_zPos, _eye]))}) // and no object between?
)}) then {
_isOk = false;
};
};
};
if (!_isOk) exitWith {false};
} forEach playableUnits;
_isOk

View File

@@ -1,13 +1,17 @@
private ["_ar","_rand_array","_rand"];
_ar = _this;
_rand_array = [];
while {count _ar > 0} do {
_rand = (count _ar);
_rand = floor (random _rand);
_rand_array set [count _rand_array, _ar select _rand];
_ar set [_rand, "randarray_del"];
_ar = _ar - ["randarray_del"];
sleep 0.001;
};
//Killzone Kid Array Shuffle Plus
//Usage: array = [array, shuffle count] call fn_shuffleArray;
_rand_array
private ["_arr","_cnt","_el1","_indx","_el2"];
_arr = _this select 0;
_cnt = count _arr - 1;
if (_cnt < 1) exitWith {_arr;}; // add count check to prevent errors.
_el1 = _arr select _cnt;
_arr resize _cnt;
for "_i" from 1 to (_this select 1) do {
_indx = floor random _cnt;
_el2 = _arr select _indx;
_arr set [_indx, _el1];
_el1 = _el2;
};
_arr set [_cnt, _el1];
_arr

View File

@@ -1,16 +1,9 @@
private ["_zeds","_isWreck","_looted","_zombied","_doNothing","_spawnZedRadius","_serverTime","_age","_position","_speed","_radius","_maxtoCreate","_inVehicle","_isAir","_isLand","_isSea","_Controlledzeddivided","_totalcrew","_nearby","_type","_config","_canSpawn","_dis","_checkLoot","_islocal","_bPos","_zombiesNum"];
private ["_zeds","_isWreck","_looted","_zombied","_doNothing","_spawnZedRadius","_serverTime","_age","_position","_radius","_maxtoCreate","_inVehicle","_isAir","_isLand","_isSea","_Controlledzeddivided","_nearby","_type","_config","_canSpawn","_dis","_checkLoot","_islocal","_bPos","_zombiesNum"];
_age = -1;
_position = [player] call fnc_getPos;
_speed = speed (vehicle player);
_radius = 200; //150*0.707; Pointless Processing (106.5)
_radius = 200; // distance from player to perform checks.
_spawnZedRadius = 20;
/*
//Tick Time
PVDZ_getTickTime = player;
publicVariableServer "PVDZ_getTickTime";
*/
// Current zombies
_zeds = entities "zZombie_Base";
dayz_currentGlobalZombies = count _zeds;
@@ -18,7 +11,7 @@ dayz_spawnZombies = 0;
dayz_CurrentNearByZombies = 0;
dayz_maxControlledZombies = dayz_maxLocalZombies; // This variable is also used in building_spawnZombies
{
if ((_x distance _position) < 200 && {alive _x}) then {
if ((_x distance _position) < _radius && {alive _x}) then {
if (local _x) then {
dayz_spawnZombies = dayz_spawnZombies + 1;
};
@@ -27,32 +20,24 @@ dayz_maxControlledZombies = dayz_maxLocalZombies; // This variable is also used
} count _zeds;
// Current loot spawns
dayz_currentWeaponHolders = count (_position nearObjects ["ReammoBox",200]);
dayz_currentWeaponHolders = count (_position nearObjects ["ReammoBox",_radius]);
//Limits (Land,Sea,Air)
_inVehicle = (vehicle player != player);
/*
_isAir = vehicle player iskindof "Air";
_isLand = vehicle player iskindof "Land";
_isSea = vehicle player iskindof "Sea";
if (_isLand) then { } else { };
if (_isAir) then { } else { };
if (_isSea) then { } else { };
*/
// In vehicle check
_vehicle = vehicle player;
_inVehicle = (_vehicle != player);
_doNothing = false;
if (_inVehicle) then {
_Controlledzeddivided = 0;
//exit if too fast
if (_speed > 25) exitwith {_doNothing = true;};
if ((speed _vehicle) > 25) exitwith {_doNothing = true;};
//Crew can spawn zeds.
_totalcrew = count (crew (vehicle player));
if (_totalcrew > 1) then {
if ((count (crew _vehicle)) > 1) then {
_Controlledzeddivided = 2;
//Dont allow driver to spawn if we have other crew members.
if (player == driver (vehicle player)) exitwith {_doNothing = true;};
if (player == driver _vehicle) exitwith {_doNothing = true;};
} else {
_Controlledzeddivided = 4;
};
@@ -62,7 +47,7 @@ if (_inVehicle) then {
};
};
if (_doNothing) exitwith {};
if (_doNothing) exitWith {};
/*if ("ItemMap_Debug" in items player) then {
deleteMarkerLocal "MaxZeds";
@@ -113,9 +98,10 @@ if (_doNothing) exitwith {};
// "Building" includes House and all of its child classes (Crashsite, IC_Fireplace1, IC_Tent, etc.)
_nearby = _position nearObjects ["Building",_radius];
dayz_spawnZombies = dayz_spawnZombies max floor(dayz_maxControlledZombies*.8);
if (dayz_spawnZombies > 0) then { _spawnZedRadius = _spawnZedRadius * 3; };
if (dayz_spawnZombies > 0) then { _spawnZedRadius = _spawnZedRadius * 3;};
//Spawn Zeds & loot in buildings
_serverTime = serverTime; // Get the current time once per cycle.
{
_type = typeOf _x;
_config = missionConfigFile >> "CfgLoot" >> "Buildings" >> _type;
@@ -123,32 +109,17 @@ if (dayz_spawnZombies > 0) then { _spawnZedRadius = _spawnZedRadius * 3; };
if (_canSpawn) then {
_dis = _x distance player;
_checkLoot = (count (getArray (_config >> "lootPos"))) > 0;
_islocal = _x getVariable ["", false]; // object created locally via TownGenerator.
//Make sure wrecks always spawn Zeds
_isWreck = _x isKindOf "CrashSite";
//Loot
if (getNumber(_config >> "lootChance") > 0) then {
if (dayz_currentWeaponHolders < dayz_maxMaxWeaponHolders) then {
//Basic loot check
if ((_dis < 125) and (_dis > 30) and !_inVehicle and _checkLoot) then {
_serverTime = serverTime;
_looted = (_x getVariable ["looted",_serverTime]);
_age = _serverTime - _looted;
//Building refresh rate
if (_age == 0 or (_age > getNumber(_config >> "lootRefreshTimer"))) then {
_x setVariable ["looted",_serverTime,!_islocal];
[_x,_type,_config] call building_spawnLoot;
if (!(_x in dayz_buildingBubbleMonitor)) then {
dayz_buildingBubbleMonitor set [count dayz_buildingBubbleMonitor, _x];
};
//diag_log [ diag_tickTime, "new loot at",_x,"age:", _age, "serverTime:", _serverTime];
}/*
else {
diag_log [ diag_tickTime, "won't spawn loot at",_x,"age:", _age, "serverTime:", _serverTime];
}*/;
//Loot
if (dayz_currentWeaponHolders < dayz_maxMaxWeaponHolders) then { // Check this first
_checkLoot = (count (getArray (_config >> "lootPos"))) > 0;
if ((_dis < 125) && {_dis > 15} && {!_inVehicle} && {_checkLoot}) then {
_looted = (_x getVariable ["looted",_serverTime]);
_age = _serverTime - _looted; // if age is zero then the building hasn't been looted before.
if ((_age == 0) || {_age > getNumber(_config >> "lootRefreshTimer")}) then {
_x setVariable ["looted",_serverTime,!_islocal];
[_x,_type,_config] call building_spawnLoot;
};
};
};
@@ -156,33 +127,23 @@ if (dayz_spawnZombies > 0) then { _spawnZedRadius = _spawnZedRadius * 3; };
//Zeds
if (getNumber(_config >> "zombieChance") > 0) then {
if (_dis > _spawnZedRadius) then {
_serverTime = serverTime;
_zombied = (_x getVariable ["zombieSpawn",_serverTime]);
_age = _serverTime - _zombied;
if ((_age == 0) or (_age > 300)) then {
if ((_age == 0) || {_age > 300}) then {
//Make sure crash sites always spawn Zeds
_isWreck = _x isKindOf "CrashSite";
_bPos = getPosATL _x;
if (!_isWreck) then {
if ((dayz_spawnZombies < dayz_maxControlledZombies) && {dayz_CurrentNearByZombies < dayz_maxNearByZombies} && {dayz_currentGlobalZombies < dayz_maxGlobalZeds}) then {
_bPos = getPosATL _x;
_zombiesNum = count (_bPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 10)]);
if (_zombiesNum == 0) then {
if (_zombiesNum == 0) then {
_x setVariable ["zombieSpawn",_serverTime,!_islocal];
if (!(_x in dayz_buildingBubbleMonitor)) then {
//add active zed to var
dayz_buildingBubbleMonitor set [count dayz_buildingBubbleMonitor, _x];
};
//start spawn
[_x,_type,_config] call building_spawnZombies;
[_x,_bPos,_config,false] call building_spawnZombies;
};
//diag_log (format["%1 building. %2", __FILE__, _x]);
};
} else {
_bPos = getPosATL _x;
_zombiesNum = count (_bPos nearEntities ["zZombie_Base",(((sizeOf _type) * 2) + 30)]);
//Should be a wreck
if (_zombiesNum == 0) then { [_x,_type,_config,_isWreck] call building_spawnZombies; };
if (_zombiesNum == 0) then {[_x,_bPos,_config,_isWreck] call building_spawnZombies;};
};
};
};

View File

@@ -1,81 +1,31 @@
#include "\z\addons\dayz_code\loot\Loot.hpp"
private ["_bypass","_position","_unitTypes","_radius","_method","_agent","_maxlocalspawned","_doLoiter","_wildspawns","_maxControlledZombies",
"_cantSee","_isOk","_zPos","__FILE__","_fov","_safeDistance","_farDistance","_xasl","_eye","_ed","_deg","_skipFOV","_tooClose",
"_type","_loot","_array","_rnd","_lootType","_index","_weights","_loot_count","_favStance","_lootGroup"];
private ["_radius","_isWreck","_position","_unitTypes","_agent","_doLoiter","_type","_favStance","_lootGroup"];
_position = _this select 0;
_doLoiter = _this select 1; // wonder around
_doLoiter = _this select 1; // wander around
_unitTypes = _this select 2; // class of wanted models
//_wildspawns = _this select 3;
_bypass = _this select 3;
_isWreck = _this select 3;
_cantSee = {
private "_isOk";
if (surfaceIsWater _position) exitWith { diag_log "Zombie_Generate: Location is in Water Abort"; };
_isOk = true;
_zPos = +(_this select 0);
if (count _zPos < 3) exitWith {
diag_log format["%1::_cantSee illegal pos %2", __FILE__, _zPos];
false
};
_zPos = ATLtoASL _zPos;
_fov = _this select 1; // players half field of view
_safeDistance = _this select 2; // minimum distance. closer is wrong
_farDistance = _this select 3; // distance further we won't check
_zPos set [2, (_zPos select 2) + 1.7];
{
_xasl = getPosASL _x;
if (_xasl distance _zPos < _farDistance) then {
if (_xasl distance _zPos < _safeDistance) then {
_isOk = false;
} else {
_eye = eyePos _x; // ASL
_ed = eyeDirection _x;
_ed = (_ed select 0) atan2 (_ed select 1);
_deg = [_xasl, _zPos] call BIS_fnc_dirTo;
_deg = (_deg - _ed + 720) % 360;
if (_deg > 180) then { _deg = _deg - 360; };
if ((abs(_deg) < _fov) && {( // in right angle sector?
(!(terrainIntersectASL [_zPos, _eye]) // no terrain between?
&& {(!(lineIntersects [_zPos, _eye]))}) // and no object between?
)}) then {
_isOk = false;
};
};
};
if (!_isOk) exitWith {false};
uiSleep 0.001;
} forEach playableUnits;
_isOk
};
_skipFOV = false;
if (_bypass) then {
_skipFOV = true;
_position = [_position,3,20,1] call fn_selectRandomLocation;
};
if (surfaceIsWater _position) exitWith { diag_log "Location is in Water Abort"; };
if ((_skipFOV) or {([_position, 15, 10, 70] call _cantSee)}) then {
_tooClose = {isPlayer _x} count (_position nearEntities ["CAManBase",30]) > 0;
if (_tooClose) exitwith { diag_log "Zombie_Generate: was too close to player."; };
if (_isWreck || {([_position, 15, 10, 70] call fnc_fieldOfView)}) then {
if (count _unitTypes == 0) then {
_unitTypes = getArray (missionConfigFile >> "CfgLoot" >> "Buildings" >> "Default" >> "zombieClass");
};
// lets create an agent
// Create zombie
_type = _unitTypes call BIS_fnc_selectRandom;
_radius = 5;
//_method = if (_doLoiter) then {"CAN_COLLIDE"} else {"NONE"};
_agent = createAgent [_type, _position, [], _radius, "CAN_COLLIDE"];
uiSleep 0.03;
_agent = createAgent [_type, _position, [], 0, "CAN_COLLIDE"];
_agent setDir (random 360);
_agent setPosATL _position;
_favStance = if (ceil(random 3) == 2) then {"middle"} else {"Up"};
_agent setUnitPos _favStance;
_agent setVariable ["stance", _favStance];
_agent setVariable ["doLoiter", _doLoiter]; // true: Z will be wandering, false: stay still
//add to global counter
// Add to global counters
dayz_spawnZombies = dayz_spawnZombies + 1;
dayz_CurrentNearByZombies = dayz_CurrentNearByZombies + 1;
dayz_currentGlobalZombies = dayz_currentGlobalZombies + 1;
@@ -84,30 +34,8 @@ if ((_skipFOV) or {([_position, 15, 10, 70] call _cantSee)}) then {
if (0.3 > random 1) then {
_lootGroup = configFile >> "CfgVehicles" >> _type >> "zombieLoot";
if (isText _lootGroup) then {
//_lootGroup = dayz_lootGroups find getText (_lootGroup);
_lootGroup = Loot_GetGroup(getText _lootGroup);
//[_agent, _lootGroup, 1] call loot_insert;
Loot_Insert(_agent, _lootGroup, 1);
};
};
_agent setVariable["agentObject",_agent];
if (!isNull _agent) then {
_agent setDir random 360;
uiSleep 0.03;
_position = getPosATL _agent;
_favStance = (
switch ceil(random(3^0.5)^2) do {
//case 3: {"DOWN"}; // prone
case 2: {"middle"}; // Kneel "middle"
default {"Up"}; // stand-up
}
);
_agent setUnitPos _favStance;
_agent setVariable ["stance", _favStance];
_agent setVariable ["BaseLocation", _position];
_agent setVariable ["doLoiter", _doLoiter]; // true: Z will be wandering, false: stay still
};
};