This commit is contained in:
A Clark
2013-01-12 20:59:54 -06:00
parent 7e52d6ee28
commit b893b72b72
2 changed files with 70 additions and 60 deletions

View File

@@ -182,19 +182,17 @@ RoadList = MarkerPosition nearRoads DynamicVehicleArea;
BuildingList = MarkerPosition nearObjects ["House",DynamicVehicleArea];
spawn_vehicles = {
private["_vehicle","_isAir","_isShip","_position","_roadlist","_buildinglist","_istoomany","_marker","_veh","_objPosition","_weights","_index","_uid","_velimit","_counter"];
private["_weights","_isOverLimit","_isAbort","_counter","_index","_vehicle","_velimit","_qty","_isAir","_isShip","_position","_dir","_istoomany","_veh","_objPosition"];
if (isDedicated) then {
_counter = _this select 0;
waituntil {!isnil "fnc_buildWeightedArray"};
_weights = [];
_weights = [AllowedVehiclesList,AllowedVehiclesChance] call fnc_buildWeightedArray;
_isOverLimit = true;
_isAbort = false;
_counter = 0;
while {_isOverLimit} do {
waitUntil{!isNil "BIS_fnc_selectRandom"};
@@ -203,7 +201,7 @@ spawn_vehicles = {
_vehicle = AllowedVehiclesList select _index;
_velimit = AllowedVehiclesLimit select _index;
_qty = {_x == _vehicle} count _counter;
_qty = {_x == _vehicle} count serverVehicleCounter;
// If under limit allow to proceed
if(_qty < _velimit) then {
@@ -211,81 +209,92 @@ spawn_vehicles = {
};
// TODO add counter to stop after X attempts
};
// Find Vehicle Type to better control spawns
_isAir = _vehicle isKindOf "Air";
_isShip = _vehicle isKindOf "Ship";
_counter = _counter + 1;
if(_isShip || _isAir) then {
if(_isShip) then {
// Spawn anywhere on coast on water
waitUntil{!isNil "BIS_fnc_selectRandom"};
_position = [MarkerPosition,0,DynamicVehicleArea,10,1,2000,1] call BIS_fnc_findSafePos;
//diag_log("DEBUG: spawning boat near coast " + str(_position));
} else {
// Spawn air anywhere that is flat
waitUntil{!isNil "BIS_fnc_selectRandom"};
_position = [MarkerPosition,0,DynamicVehicleArea,25,0,1,0] call BIS_fnc_findSafePos;
//diag_log("DEBUG: spawning air anywhere flat " + str(_position));
if(_counter > 5) then {
_isOverLimit = false;
_isAbort = true;
};
};
if (_isAbort) then {
diag_log("DEBUG: unable to find sutable vehicle");
} else {
// Spawn around buildings and 50% near roads
if((random 1) > 0.5) then {
// add vehicle to counter for next pass
serverVehicleCounter set [count serverVehicleCounter,_vehicle];
// Find Vehicle Type to better control spawns
_isAir = _vehicle isKindOf "Air";
_isShip = _vehicle isKindOf "Ship";
if(_isShip || _isAir) then {
if(_isShip) then {
// Spawn anywhere on coast on water
waitUntil{!isNil "BIS_fnc_selectRandom"};
_position = [MarkerPosition,0,DynamicVehicleArea,10,1,2000,1] call BIS_fnc_findSafePos;
//diag_log("DEBUG: spawning boat near coast " + str(_position));
} else {
// Spawn air anywhere that is flat
waitUntil{!isNil "BIS_fnc_selectRandom"};
_position = [MarkerPosition,0,DynamicVehicleArea,25,0,1,0] call BIS_fnc_findSafePos;
//diag_log("DEBUG: spawning air anywhere flat " + str(_position));
};
} else {
// Spawn around buildings and 50% near roads
if((random 1) > 0.5) then {
waitUntil{!isNil "BIS_fnc_selectRandom"};
_position = RoadList call BIS_fnc_selectRandom;
waitUntil{!isNil "BIS_fnc_selectRandom"};
_position = RoadList call BIS_fnc_selectRandom;
_position = _position modelToWorld [0,0,0];
_position = _position modelToWorld [0,0,0];
waitUntil{!isNil "BIS_fnc_findSafePos"};
_position = [_position,0,10,10,0,2000,0] call BIS_fnc_findSafePos;
waitUntil{!isNil "BIS_fnc_findSafePos"};
_position = [_position,0,10,10,0,2000,0] call BIS_fnc_findSafePos;
//diag_log("DEBUG: spawning near road " + str(_position));
//diag_log("DEBUG: spawning near road " + str(_position));
} else {
} else {
waitUntil{!isNil "BIS_fnc_selectRandom"};
_position = BuildingList call BIS_fnc_selectRandom;
waitUntil{!isNil "BIS_fnc_selectRandom"};
_position = BuildingList call BIS_fnc_selectRandom;
_position = _position modelToWorld [0,0,0];
_position = _position modelToWorld [0,0,0];
waitUntil{!isNil "BIS_fnc_findSafePos"};
_position = [_position,0,40,5,0,2000,0] call BIS_fnc_findSafePos;
waitUntil{!isNil "BIS_fnc_findSafePos"};
_position = [_position,0,40,5,0,2000,0] call BIS_fnc_findSafePos;
//diag_log("DEBUG: spawning around buildings " + str(_position));
//diag_log("DEBUG: spawning around buildings " + str(_position));
};
};
};
// only proceed if two params otherwise BIS_fnc_findSafePos failed and may spawn in air
if ((count _position) == 2) then {
// only proceed if two params otherwise BIS_fnc_findSafePos failed and may spawn in air
if ((count _position) == 2) then {
_dir = round(random 180);
_dir = round(random 180);
_istoomany = _position nearObjects ["AllVehicles",50];
if((count _istoomany) > 0) exitWith { diag_log("DEBUG: Too many vehicles at " + str(_position)); };
_istoomany = _position nearObjects ["AllVehicles",50];
if((count _istoomany) > 0) exitWith { diag_log("DEBUG: Too many vehicles at " + str(_position)); };
//place vehicle
_veh = createVehicle [_vehicle, _position, [], 0, "CAN_COLLIDE"];
_veh setdir _dir;
_veh setpos _position;
//place vehicle
_veh = createVehicle [_vehicle, _position, [], 0, "CAN_COLLIDE"];
_veh setdir _dir;
_veh setpos _position;
// Get position with ground
_objPosition = getPosATL _veh;
// Get position with ground
_objPosition = getPosATL _veh;
clearWeaponCargoGlobal _veh;
clearMagazineCargoGlobal _veh;
clearWeaponCargoGlobal _veh;
clearMagazineCargoGlobal _veh;
[_veh,[_dir,_objPosition],_vehicle,true,"0"] call server_publishVeh;
[_veh,[_dir,_objPosition],_vehicle,true,"0"] call server_publishVeh;
};
};
};
};

View File

@@ -3,7 +3,7 @@
dayz_versionNo = getText(configFile >> "CfgMods" >> "DayZ" >> "version");
dayz_hiveVersionNo = getNumber(configFile >> "CfgMods" >> "DayZ" >> "hiveVersion");
_serverVehicleCounter = [];
serverVehicleCounter = [];
if ((count playableUnits == 0) and !isDedicated) then {
isSinglePlayer = true;
@@ -169,7 +169,7 @@ diag_log "HIVE: Starting";
_totalvehicles = _totalvehicles + 1;
// total each vehicle
_serverVehicleCounter set [count _serverVehicleCounter,_type];
serverVehicleCounter set [count _serverVehicleCounter,_type];
};
@@ -226,13 +226,14 @@ _vehLimit = MaxVehicleLimit - _totalvehicles;
diag_log ("HIVE: Spawning # of Vehicles: " + str(_vehLimit));
if(_vehLimit > 0) then {
for "_x" from 1 to _vehLimit do {
_id = [_serverVehicleCounter] spawn spawn_vehicles; // Needs setup
_id = [] spawn spawn_vehicles; // Needs setup
waitUntil{scriptDone _id};
};
};
// spawn_roadblocks
diag_log ("HIVE: Spawning # of Debris: " + str(MaxDynamicDebris));
for "_x" from 1 to MaxDynamicDebris do {
_id = [] spawn spawn_roadblocks;
//waitUntil{scriptDone _id};