From bb94bb429ed77dbb1cd333ecbe85be2775a8a8c3 Mon Sep 17 00:00:00 2001 From: vbawol Date: Wed, 6 Jul 2016 23:30:23 -0500 Subject: [PATCH] reworked trader spawn fixes #489 traders now only spawn in traderBlds classes for work and traderHomes for homes and only if the building has AI positions. traders now also use traderUniforms config array for what uniforms they randomly use. --- .../EPOCH_server_spawnTraders.sqf | 118 ++++++++---------- Sources/epoch_server_settings/config.cpp | 4 +- .../configs/maps/Bootcamp_ACR.h | 2 +- .../configs/maps/Desert_E.h | 2 +- .../configs/maps/Mountains_ACR.h | 2 +- .../epoch_server_settings/configs/maps/Napf.h | 2 +- .../configs/maps/Porto.h | 2 +- .../configs/maps/ProvingGrounds_PMC.h | 2 +- .../epoch_server_settings/configs/maps/Sara.h | 2 +- .../configs/maps/SaraLite.h | 2 +- .../configs/maps/Sara_dbe1.h | 2 +- .../configs/maps/Shapur_BAF.h | 2 +- .../epoch_server_settings/configs/maps/Utes.h | 2 +- .../configs/maps/Woodland_ACR.h | 2 +- 14 files changed, 65 insertions(+), 81 deletions(-) diff --git a/Sources/epoch_server/compile/epoch_traders/EPOCH_server_spawnTraders.sqf b/Sources/epoch_server/compile/epoch_traders/EPOCH_server_spawnTraders.sqf index b55853f2..37882762 100644 --- a/Sources/epoch_server/compile/epoch_traders/EPOCH_server_spawnTraders.sqf +++ b/Sources/epoch_server/compile/epoch_traders/EPOCH_server_spawnTraders.sqf @@ -12,82 +12,64 @@ Github: https://github.com/EpochModTeam/Epoch/tree/release/Sources/epoch_server/compile/epoch_traders/EPOCH_server_spawnTraders.sqf */ -private ["_home","_work","_pos","_marker","_buildingPositions","_startTime","_endTime","_schedule","_agent","_slot","_objHiveKey","_buildingWork","_homeBuildingPositions","_acceptableBlds","_buildings","_randomAIUniform","_randomAIClass","_building","_position","_aiTables","_spawnCount","_usedBuildings"]; - -// TODO: configize -_aiTables = ["U_OG_leader", "U_C_Poloshirt_stripped", "U_C_Poloshirt_blue", "U_C_Poloshirt_burgundy", "U_C_Poloshirt_tricolour", "U_C_Poloshirt_salmon", "U_C_Poloshirt_redwhite", "U_C_Poor_1", "U_C_WorkerCoveralls", "U_C_Journalist", "U_C_Scientist", "U_OrestesBody"]; - +private ["_pos","_marker","_buildingWork","_home","_work","_startTime","_endTime","_schedule","_agent","_slot","_objHiveKey","_buildingHome","_buildings","_randomAIUniform","_aiClass","_homes","_position","_spawnCount","_config","_aiTables","_acceptableBlds","_traderHomes","_usedBuildings","_checkBuilding"]; _spawnCount = count EPOCH_TraderSlots; - -//diag_log format["DEBUG: Tradercount EPOCH_TraderSlots: %1", _spawnCount]; - +_config = (configFile >> "CfgEpoch" >> worldName); +_aiTables = getArray(_config >> "traderUniforms"); +_acceptableBlds = getArray(_config >> "traderBlds"); +_traderHomes = getArray(_config >> "traderHomes"); _usedBuildings = []; +_checkBuilding = { + private ["_return"]; + params ["_building","_aiClass"]; + _return = !(_building in _usedBuildings); + if !(_return) exitWith {_return}; + _return = !((_building buildingPos -1) isEqualTo []); + if !(_return) exitWith {_return}; + _return = (_building nearEntities [_aiClass, 50]) isEqualTo []; + _return +}; for "_i" from 1 to _spawnCount do { - _position = [epoch_centerMarkerPosition, 0, EPOCH_dynamicVehicleArea, 20, 0, 4000, 0] call BIS_fnc_findSafePos; - // only proceed if two params otherwise BIS_fnc_findSafePos failed and may spawn in air if (count _position == 2) then { _randomAIUniform = selectRandom _aiTables; - _randomAIClass = "C_man_1"; // static for now - - _building = nearestBuilding _position; - if !(_building in _usedBuildings) then { - _home = getPosATL _building; - _pos = _home; - _usedBuildings pushBack _building; - - _homeBuildingPositions = _building buildingPos -1; - if !(_homeBuildingPositions isEqualTo []) then { - _home = selectRandom _homeBuildingPositions; - }; - _acceptableBlds = getArray(configFile >> "CfgEpoch" >> worldName >> "traderBlds"); - - _buildings = nearestObjects[_home, _acceptableBlds, 500]; + _aiClass = "C_man_1"; + _homes = (nearestObjects[_position, _traderHomes, 500]) select {[_x,_aiClass] call _checkBuilding}; + if !(_homes isEqualTo []) then { + _buildingHome = selectRandom _homes; + _usedBuildings pushBack _buildingHome; + _buildings = (nearestObjects[_buildingHome, _acceptableBlds, 500]) select {[_x,_aiClass] call _checkBuilding}; if !(_buildings isEqualTo []) then { - _buildingWork = selectRandom _buildings; - if !(_buildingWork in _usedBuildings) then { - _usedBuildings pushBack _buildingWork; - _work = getPosATL _buildingWork; - - _buildingPositions = _buildingWork buildingPos -1; - if !(_buildingPositions isEqualTo []) then { - _work = selectRandom _buildingPositions; - }; - - _startTime = floor(random 16); - _endTime = _startTime + 8; - _schedule = [_startTime, _endTime]; - if (daytime > (_schedule select 0) && daytime < (_schedule select 1)) then { - _pos = _work; - }; - - if (_pos nearEntities[_randomAIClass, 50] isEqualTo []) then { - - _agent = createAgent[_randomAIClass, _pos, [], 0, "CAN_COLLIDE"]; - addToRemainsCollector[_agent]; - _agent addUniform _randomAIUniform; - _slot = EPOCH_TraderSlots deleteAt 0; - _agent setVariable["AI_SLOT", _slot, true]; - _agent setVariable["AI_ITEMS", EPOCH_starterTraderItems, true]; - _objHiveKey = format["%1:%2", (call EPOCH_fn_InstanceID), _slot]; - - ["AI_ITEMS", _objHiveKey, EPOCH_expiresAIdata, EPOCH_starterTraderItems] call EPOCH_fnc_server_hiveSETEX; - _agent addEventHandler["Killed", { _this call EPOCH_server_traderKilled; }]; - - if !(EPOCH_forceStaticTraders) then { - [_agent, _home, [_work, _schedule]] execFSM "\epoch_server\system\Trader_brain.fsm"; - }; - - ["AI", _objHiveKey, [_randomAIClass, _home, [_work, _schedule]]] call EPOCH_fnc_server_hiveSET; - if (EPOCH_SHOW_TRADERS) then { - _marker = createMarker[str(_agent), (_pos)]; - _marker setMarkerShape "ICON"; - _marker setMarkerType "mil_dot"; - _marker setMarkerColor "ColorKhaki"; - _agent setVariable["MARKER_REF", _marker]; - }; - }; + _usedBuildings pushBack _buildingWork; + _home = selectRandom (_buildingHome buildingPos -1); + _work = selectRandom (_buildingWork buildingPos -1); + _startTime = floor(random 16); + _endTime = _startTime + 8; + _schedule = [_startTime, _endTime]; + _pos = _home; + if (daytime > _startTime && daytime < _endTime) then { + _pos = _work; + }; + _agent = createAgent[_aiClass, _pos, [], 0, "CAN_COLLIDE"]; + addToRemainsCollector[_agent]; + _agent addUniform _randomAIUniform; + _slot = EPOCH_TraderSlots deleteAt 0; + _agent setVariable["AI_SLOT", _slot, true]; + _agent setVariable["AI_ITEMS", EPOCH_starterTraderItems, true]; + _objHiveKey = format["%1:%2", (call EPOCH_fn_InstanceID), _slot]; + ["AI_ITEMS", _objHiveKey, EPOCH_expiresAIdata, EPOCH_starterTraderItems] call EPOCH_fnc_server_hiveSETEX; + _agent addEventHandler["Killed", { _this call EPOCH_server_traderKilled; }]; + if !(EPOCH_forceStaticTraders) then { + [_agent, _home, [_work, _schedule]] execFSM "\epoch_server\system\Trader_brain.fsm"; + }; + ["AI", _objHiveKey, [_aiClass, _home, [_work, _schedule]]] call EPOCH_fnc_server_hiveSET; + if (EPOCH_SHOW_TRADERS) then { + _marker = createMarker[str(_agent), (_pos)]; + _marker setMarkerShape "ICON"; + _marker setMarkerType "mil_dot"; + _marker setMarkerColor "ColorKhaki"; + _agent setVariable["MARKER_REF", _marker]; }; }; }; diff --git a/Sources/epoch_server_settings/config.cpp b/Sources/epoch_server_settings/config.cpp index 0323634e..7c16eb5d 100644 --- a/Sources/epoch_server_settings/config.cpp +++ b/Sources/epoch_server_settings/config.cpp @@ -59,7 +59,9 @@ class CfgEpoch {"NameCityCapital",4}, {"Airport",5} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; + traderHomes[] = {"House", "Building"}; + traderUniforms[] = {"U_OG_leader", "U_C_Poloshirt_stripped", "U_C_Poloshirt_blue", "U_C_Poloshirt_burgundy", "U_C_Poloshirt_tricolour", "U_C_Poloshirt_salmon", "U_C_Poloshirt_redwhite", "U_C_Poor_1", "U_C_WorkerCoveralls", "U_C_Journalist", "U_C_Scientist", "U_OrestesBody"}; containerPos[] = {}; telePos[] = {}; propsPos[] = {}; diff --git a/Sources/epoch_server_settings/configs/maps/Bootcamp_ACR.h b/Sources/epoch_server_settings/configs/maps/Bootcamp_ACR.h index a5f22597..1e917b90 100644 --- a/Sources/epoch_server_settings/configs/maps/Bootcamp_ACR.h +++ b/Sources/epoch_server_settings/configs/maps/Bootcamp_ACR.h @@ -29,7 +29,7 @@ class Bootcamp_ACR : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098] diff --git a/Sources/epoch_server_settings/configs/maps/Desert_E.h b/Sources/epoch_server_settings/configs/maps/Desert_E.h index 9fae60f9..a73df1c8 100644 --- a/Sources/epoch_server_settings/configs/maps/Desert_E.h +++ b/Sources/epoch_server_settings/configs/maps/Desert_E.h @@ -29,7 +29,7 @@ class Desert_E : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098] diff --git a/Sources/epoch_server_settings/configs/maps/Mountains_ACR.h b/Sources/epoch_server_settings/configs/maps/Mountains_ACR.h index e58c0791..6b1468d9 100644 --- a/Sources/epoch_server_settings/configs/maps/Mountains_ACR.h +++ b/Sources/epoch_server_settings/configs/maps/Mountains_ACR.h @@ -29,7 +29,7 @@ class Mountains_ACR : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098] diff --git a/Sources/epoch_server_settings/configs/maps/Napf.h b/Sources/epoch_server_settings/configs/maps/Napf.h index e7479ce3..c1b713ad 100644 --- a/Sources/epoch_server_settings/configs/maps/Napf.h +++ b/Sources/epoch_server_settings/configs/maps/Napf.h @@ -29,7 +29,7 @@ class Napf : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098] diff --git a/Sources/epoch_server_settings/configs/maps/Porto.h b/Sources/epoch_server_settings/configs/maps/Porto.h index 908581a5..73b10ee9 100644 --- a/Sources/epoch_server_settings/configs/maps/Porto.h +++ b/Sources/epoch_server_settings/configs/maps/Porto.h @@ -29,7 +29,7 @@ class Porto : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098] diff --git a/Sources/epoch_server_settings/configs/maps/ProvingGrounds_PMC.h b/Sources/epoch_server_settings/configs/maps/ProvingGrounds_PMC.h index 45ebf7c3..1c0dafae 100644 --- a/Sources/epoch_server_settings/configs/maps/ProvingGrounds_PMC.h +++ b/Sources/epoch_server_settings/configs/maps/ProvingGrounds_PMC.h @@ -29,7 +29,7 @@ class ProvingGrounds_PMC : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098] diff --git a/Sources/epoch_server_settings/configs/maps/Sara.h b/Sources/epoch_server_settings/configs/maps/Sara.h index 0ae2287d..fa353461 100644 --- a/Sources/epoch_server_settings/configs/maps/Sara.h +++ b/Sources/epoch_server_settings/configs/maps/Sara.h @@ -29,7 +29,7 @@ class Sara : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098] diff --git a/Sources/epoch_server_settings/configs/maps/SaraLite.h b/Sources/epoch_server_settings/configs/maps/SaraLite.h index ba4ccf47..f6b29071 100644 --- a/Sources/epoch_server_settings/configs/maps/SaraLite.h +++ b/Sources/epoch_server_settings/configs/maps/SaraLite.h @@ -29,7 +29,7 @@ class SaraLite : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098] diff --git a/Sources/epoch_server_settings/configs/maps/Sara_dbe1.h b/Sources/epoch_server_settings/configs/maps/Sara_dbe1.h index 6e5a8a4e..c9bf2e90 100644 --- a/Sources/epoch_server_settings/configs/maps/Sara_dbe1.h +++ b/Sources/epoch_server_settings/configs/maps/Sara_dbe1.h @@ -29,7 +29,7 @@ class Sara_dbe1 : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098] diff --git a/Sources/epoch_server_settings/configs/maps/Shapur_BAF.h b/Sources/epoch_server_settings/configs/maps/Shapur_BAF.h index 2ffb59b4..d0444bee 100644 --- a/Sources/epoch_server_settings/configs/maps/Shapur_BAF.h +++ b/Sources/epoch_server_settings/configs/maps/Shapur_BAF.h @@ -29,7 +29,7 @@ class Shapur_BAF : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098] diff --git a/Sources/epoch_server_settings/configs/maps/Utes.h b/Sources/epoch_server_settings/configs/maps/Utes.h index ed68502e..aad53c1d 100644 --- a/Sources/epoch_server_settings/configs/maps/Utes.h +++ b/Sources/epoch_server_settings/configs/maps/Utes.h @@ -29,7 +29,7 @@ class Utes : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098] diff --git a/Sources/epoch_server_settings/configs/maps/Woodland_ACR.h b/Sources/epoch_server_settings/configs/maps/Woodland_ACR.h index 2606f16e..f9f44013 100644 --- a/Sources/epoch_server_settings/configs/maps/Woodland_ACR.h +++ b/Sources/epoch_server_settings/configs/maps/Woodland_ACR.h @@ -29,7 +29,7 @@ class Woodland_ACR : Default {"VegetationFir",1}, {"ViewPoint",1} }; - traderBlds[] = {}; + traderBlds[] = {"House", "Building"}; containerPos[] = {}; telePos[] = { // N [-0.286865,8.17383,-10.3098]