| @@ -0,0 +1,27 @@ | ||
| params ["_driver"]; | ||
|
|
||
| _bus = vehicle _driver; | ||
| _waitingTime = 10 + (random 2); | ||
|
|
||
| [_bus, ['doors_1', 'doors_2', 'doors_3']] call grad_publicTransport_fnc_openDoors; | ||
|
|
||
|
|
||
| // check if potential passengers are nearby | ||
| if (count (_driver nearEntities ["Man", 15]) > 0) then { | ||
| _waitingTime = _waitingTime + 10; | ||
| }; | ||
|
|
||
| sleep _waitingTime; | ||
|
|
||
| // make drive ready | ||
| [_bus] call grad_publicTransport_fnc_honk; | ||
| [_bus, ['doors_2']] call grad_publicTransport_fnc_closeDoors; | ||
| sleep 0.5; | ||
| [_bus, ['doors_3']] call grad_publicTransport_fnc_closeDoors; | ||
| sleep 0.75; | ||
| [_bus, ['doors_1']] call grad_publicTransport_fnc_closeDoors; | ||
| sleep 0.5; | ||
| [_bus] call grad_publicTransport_fnc_honk; | ||
|
|
||
| // next waypoint for this line | ||
| [_driver] call grad_publicTransport_fnc_waypointGetNext; |
| @@ -1,11 +1,15 @@ | ||
| params ["_pos", ["_color", "colorRed"], "_number"]; | ||
|
|
||
| _marker = createMarker [format["%1", toString _pos],_pos]; | ||
|
|
||
|
|
||
| diag_log format ["GRAD_publicTransport: Marker %1 created", _pos]; | ||
|
|
||
|
|
||
| _marker setMarkerShape "ICON"; | ||
| _marker setMarkerType "hd_dot"; | ||
|
|
||
| _marker setMarkerAlpha 1; | ||
| _marker setMarkerColor _color; | ||
| _marker setMarkerText (str _number); | ||
|
|
| @@ -0,0 +1,74 @@ | ||
| params["_src","_dst"]; | ||
| private _closed = []; | ||
| private _open = [_src]; | ||
| private _markerArray = []; | ||
|
|
||
| missionNamespace setVariable ["CODI_Path_g_" + str _src, 0]; | ||
| CODI_Path_variables pushBack ("CODI_Path_g_" + str _src); | ||
| missionNamespace setVariable ["CODI_Path_f_" + str _src, [_src, _dst] call GRAD_publicTransport_fnc_h]; | ||
| CODI_Path_variables pushBack ("CODI_Path_f_" + str _src); | ||
| while {!(_open isEqualTo [])} do | ||
| { | ||
| private _current = objNull; | ||
| { | ||
| if ((missionNamespace getVariable ["CODI_Path_f_" + str _x, 999999]) < (missionNamespace getVariable ["CODI_Path_f_" + str _current, 999999])) then | ||
| { | ||
| _current = _x; | ||
| }; | ||
| nil | ||
| } | ||
| count _open; | ||
| if (_current == _dst) exitWith | ||
| { | ||
| _markerArray = [_dst] call GRAD_publicTransport_fnc_mark; | ||
| }; | ||
| _open = _open - [_current]; | ||
| _closed pushBack _current; | ||
| private _roads = roadsConnectedTo _current; | ||
| { | ||
| if (_x != _current) then | ||
| { | ||
| _roads pushBackUnique _x; | ||
| }; | ||
| nil | ||
| } | ||
| count ((getPos _current) nearRoads 20); | ||
| { | ||
| if (!(_x in _closed)) then | ||
| { | ||
| private _tentativeG = (missionNamespace getVariable ["CODI_Path_g_" + str _current, 999999]) + ([_current, _x] call GRAD_publicTransport_fnc_cost); | ||
| private _continue = false; | ||
| if (!(_x in _open)) then | ||
| { | ||
| _open pushBack _x; | ||
| } | ||
| else | ||
| { | ||
| if (_tentativeG >= (missionNamespace getVariable ["CODI_Path_g_" + str _x, 999999])) then | ||
| { | ||
| _continue = true; | ||
| }; | ||
|
|
||
| }; | ||
| if (!_continue) then | ||
| { | ||
| private _marker = createMarkerLocal [str _x, getPos _x]; | ||
| _marker setMarkerShapeLocal "ICON"; | ||
| _marker setMarkerColorLocal "ColorWEST"; | ||
| _marker setMarkerTypeLocal "MIL_DOT"; | ||
| _marker setMarkerAlphaLocal 0.25; | ||
| CODI_Path_markersLocal pushBack _marker; | ||
| missionNamespace setVariable ["CODI_Path_parent_" + str _x, _current]; | ||
| CODI_Path_variables pushBack ("CODI_Path_parent_" + str _x); | ||
| missionNamespace setVariable ["CODI_Path_g_" + str _x, _tentativeG]; | ||
| CODI_Path_variables pushBack ("CODI_Path_g_" + str _x); | ||
| missionNamespace setVariable ["CODI_Path_f_" + str _x, (missionNamespace getVariable ["CODI_Path_g_" + str _x, 999999]) + ([_x, _dst] call GRAD_publicTransport_fnc_h)]; | ||
| CODI_Path_variables pushBack ("CODI_Path_f_" + str _x); | ||
| }; | ||
| }; | ||
| nil | ||
| } | ||
| count _roads; | ||
| }; | ||
|
|
||
| _markerArray |
| @@ -0,0 +1,20 @@ | ||
| params ["_array", "_endpoint"]; | ||
|
|
||
| _vectorizedArray = []; | ||
|
|
||
| _posBefore = _array select 0; | ||
| _dir = _posBefore getDir _endpoint; | ||
|
|
||
| _vectorizedArray = _vectorizedArray + [[_posBefore, _dir]]; | ||
|
|
||
| { | ||
| if (_forEachIndex > 0) then { | ||
| _dir = _x getDir _posBefore; | ||
|
|
||
| diag_log format ["dir %1",_dir]; | ||
| _vectorizedArray = _vectorizedArray + [[_x, _dir]]; | ||
| _posBefore = _x; | ||
| }; | ||
| } forEach _array; | ||
|
|
||
| _vectorizedArray |
| @@ -0,0 +1,52 @@ | ||
| params["_src","_dst", ["_lineNumber", 1]]; | ||
|
|
||
| private _srcRoad = [_src] call GRAD_publicTransport_fnc_getNearestRoad; | ||
| private _dstRoad = [_dst] call GRAD_publicTransport_fnc_getNearestRoad; | ||
|
|
||
| if (isNull _srcRoad || isNull _dstRoad) exitWith {hint "src or dst not close to a road"}; | ||
| _rawData = [_srcRoad, _dstRoad] call GRAD_publicTransport_fnc_aStar; | ||
| _targetRouteDir = [_rawData, _dst] call GRAD_publicTransport_fnc_addVectors; | ||
|
|
||
| _returnRaw = [_rawData] call GRAD_publicTransport_fnc_getReturnRoute; | ||
| _returnRouteDir = [_returnRaw, _src] call GRAD_publicTransport_fnc_addVectors; | ||
|
|
||
| _stationArrayUp = []; | ||
| _stationArrayDown = []; | ||
|
|
||
| diag_log format ["_targetRoute %1", _targetRouteDir]; | ||
| diag_log format ["_returnRoute %1", _returnRouteDir]; | ||
|
|
||
| _nextStation = []; | ||
|
|
||
| { | ||
|
|
||
| _nextStation = [_x select 0, _x select 1] call GRAD_publicTransport_fnc_getNextStation; | ||
|
|
||
| if (_nextStation select 0) then { | ||
| _stationArrayUp = _stationArrayUp + [_nextStation select 1]; | ||
| }; | ||
| } forEach _targetRouteDir; | ||
|
|
||
| { | ||
| [getPos _x, "colorRed", _forEachIndex] call GRAD_publicTransport_fnc_createDebugMarker; | ||
| } forEach _stationArrayUp; | ||
|
|
||
|
|
||
| /* return route */ | ||
| _nextStation = []; | ||
|
|
||
| { | ||
| _nextStation = [_x select 0, _x select 1] call GRAD_publicTransport_fnc_getNextStation; | ||
|
|
||
| if (_nextStation select 0) then { | ||
| _stationArrayDown = _stationArrayDown + [_nextStation select 1]; | ||
| }; | ||
| } forEach _returnRouteDir; | ||
|
|
||
| { | ||
| [getPos _x, "colorBlue", _forEachIndex] call GRAD_publicTransport_fnc_createDebugMarker; | ||
| } forEach _stationArrayDown; | ||
|
|
||
|
|
||
|
|
||
| missionNameSpace setVariable ["GRAD_publicTransport_Stations_Line_" + (str _lineNumber), [_stationArrayUp, _stationArrayDown], true]; |
| @@ -0,0 +1,10 @@ | ||
| params["_src","_dst"]; | ||
| private _dist = ((getPos _src) distance (getPos _dst))*1; | ||
|
|
||
| _stationMapObjects = (nearestTerrainObjects [getPos _dst, [ "BUSSTOP"], 20]); | ||
| if (count _stationMapObjects == 0) then { | ||
| diag_log format ["dist %1 added 10", _dist]; | ||
| _dist = _dist + 10; | ||
| }; | ||
|
|
||
| _dist |
| @@ -0,0 +1,3 @@ | ||
| params ["_start", "_end"]; | ||
|
|
||
| _handle = [_start, _end] spawn GRAD_publicTransport_fnc_calcRoute; |
| @@ -0,0 +1,13 @@ | ||
| params["_pos"]; | ||
| private _roads = _pos nearRoads 1000; | ||
| if (_roads isEqualTo []) exitWith {objNull}; | ||
| private _road = _roads deleteAt 0; | ||
| { | ||
| if (((getPos _x) distance2d _pos) < ((getPos _road) distance2d _pos)) then | ||
| { | ||
| _road = _x; | ||
| }; | ||
| nil | ||
| } | ||
| count _roads; | ||
| _road |
| @@ -0,0 +1,3 @@ | ||
| params["_src","_dst"]; | ||
| private _dist = ((getPos _src) distance (getPos _dst))*1.5; | ||
| _dist |
| @@ -0,0 +1,37 @@ | ||
| { | ||
| deleteMarkerLocal _x; | ||
| nil | ||
| } | ||
| count CODI_Path_markersLocal; | ||
| CODI_Path_markersLocal = []; | ||
|
|
||
| private _dst = param[0, objNull]; | ||
| private _marker = createMarker [str _dst, getPos _dst]; | ||
| private _array = []; | ||
|
|
||
| _marker setMarkerShape "ICON"; | ||
| _marker setMarkerColor "ColorWEST"; | ||
| _marker setMarkerType "MIL_DOT"; | ||
| CODI_Path_markers pushBack _marker; | ||
|
|
||
| while {!isNull _dst} do | ||
| { | ||
| if ((getMarkerPos _marker) distance2d (getPos _dst) > 10) then | ||
| { | ||
| _marker = createMarker [str _dst, getPos _dst]; | ||
| _marker setMarkerShape "ICON"; | ||
| _marker setMarkerColor "ColorWEST"; | ||
| _marker setMarkerType "MIL_DOT"; | ||
| _marker setMarkerAlpha 0; | ||
| }; | ||
| CODI_Path_markers pushBack _marker; | ||
| _dst = missionNamespace getVariable ["CODI_Path_parent_" + str _dst, objNull]; | ||
| }; | ||
|
|
||
| { | ||
|
|
||
| _array = _array + [getMarkerPos _x]; | ||
|
|
||
| } forEach CODI_Path_markers; | ||
|
|
||
| _array |
| @@ -0,0 +1,12 @@ | ||
| { | ||
| deleteMarker _x; | ||
| nil | ||
| } | ||
| count CODI_Path_markers; | ||
| CODI_Path_markers = []; | ||
| { | ||
| missionNamespace setVariable[_x, nil]; | ||
| nil | ||
| } | ||
| count CODI_Path_variables; | ||
| CODI_Path_variables = []; |
| @@ -0,0 +1,9 @@ | ||
| ["CODI_Path_mapClick", "onMapSingleClick",{ | ||
| [getPos player, _pos] spawn GRAD_publicTransport_fnc_calcRoute; | ||
| openMap false; | ||
| }] call BIS_fnc_addStackedEventHandler; | ||
| openMap true; | ||
| [] spawn { | ||
| waitUntil{!visibleMap}; | ||
| ["CODI_Path_mapClick", "onMapSingleClick"] call BIS_fnc_removeStackedEventHandler; | ||
| }; |
| @@ -0,0 +1,20 @@ | ||
| /* | ||
| code by coding @armaworld.de, splitted into files by nomisum | ||
| */ | ||
|
|
||
|
|
||
| CODI_Path_markers = []; | ||
| CODI_Path_markersLocal = []; | ||
| CODI_Path_variables = []; | ||
|
|
||
| /* | ||
| player addAction["Calculate Route", {call GRAD_publicTransport_fnc_start;}, [], 0, false, true, "", "count CODI_Path_markers == 0"]; | ||
| player addAction["Delete Route", {call GRAD_publicTransport_fnc_removeMarkers;}, [], 0, false, true, "", "count CODI_Path_markers > 0"]; | ||
| player addEventHandler ["Respawn", { | ||
| player addAction["Calculate Route", {call GRAD_publicTransport_fnc_start;}, [], 0, false, true, "", "count CODI_Path_markers == 0"]; | ||
| player addAction["Delete Route", {call GRAD_publicTransport_fnc_removeMarkers;}, [], 0, false, true, "", "count CODI_Path_markers > 0"]; | ||
| }]; | ||
| */ |
| @@ -0,0 +1,11 @@ | ||
| /* | ||
| call with | ||
| [driver cursortarget, 1] call grad_publictransport_fnc_assignRoute; | ||
| */ | ||
|
|
||
| params ["_driver", "_line"]; | ||
|
|
||
| _driver setVariable ["GRAD_publicTransport_currentLine", _line]; | ||
| [_driver, _line] call GRAD_publicTransport_fnc_waypointGetNext; |
| @@ -0,0 +1,19 @@ | ||
| params ["_pos", "_dir"]; | ||
|
|
||
| private ["_station", "_stations", "_foundStation"]; | ||
|
|
||
| _stations = (nearestTerrainObjects [_pos, [ "BUSSTOP"], 16]); | ||
| _foundStation = false; | ||
| _station = objNull; | ||
|
|
||
| if (count _stations > 0) then { | ||
| _station = _stations select 0; | ||
|
|
||
| if ([_pos, _station, _dir] call GRAD_publicTransport_fnc_isOnRightSide) then { | ||
| _foundStation = true; | ||
| }; | ||
| }; | ||
|
|
||
| diag_log format ["found station is %1", _foundStation]; | ||
|
|
||
| [_foundStation, _station] |
| @@ -0,0 +1,9 @@ | ||
| params ["_array"]; | ||
|
|
||
| private ["_inverted"]; | ||
|
|
||
|
|
||
| _inverted = + _array; | ||
| reverse _inverted; | ||
|
|
||
| _inverted |
| @@ -0,0 +1,19 @@ | ||
| /* | ||
| checks side relative to road | ||
| */ | ||
|
|
||
| params ["_pos", "_obj", "_traveldirection"]; | ||
|
|
||
|
|
||
| _relDir = (_pos getDir _obj) + _traveldirection; | ||
| // _roadDir = getDir _road; | ||
|
|
||
| _isOnRight = true; | ||
|
|
||
| if ((_relDir > 180 && _relDir < 360) || (_relDir < 0 && _relDir > -180)) then { | ||
| _isOnRight = false; | ||
| _isOnRight | ||
| } else { | ||
| diag_log format ["_reldir is %1", _reldir]; | ||
| _isOnRight | ||
| }; |
| @@ -0,0 +1,26 @@ | ||
| params ["_driver", "_busline"]; | ||
|
|
||
| _busline = _driver getVariable ["GRAD_publicTransport_currentLine", 1]; | ||
| _currentStationIndex = _driver getVariable ["GRAD_publicTransport_currentStationIndex", 0]; | ||
| _allStations = missionNamespace getVariable ["GRAD_publicTransport_Stations_Line_" + (str _busline), []]; | ||
|
|
||
| _stationCount = count (_allStations select 0); | ||
| _nextStationIndex = 0; | ||
|
|
||
|
|
||
| if (_stationCount == 0) exitWith { diag_log format ["no stations found"]; }; | ||
|
|
||
|
|
||
| if (_currentStationIndex >= _stationCount - 1) then { | ||
| _nextStationIndex = 0; | ||
| _currentStationIndex = _driver setVariable ["GRAD_publicTransport_currentStationIndex", _nextStationIndex]; | ||
|
|
||
| hintsilent format ["resetting currentstationindex"]; | ||
|
|
||
| } else { | ||
| _nextStationIndex = _currentStationIndex + 1; | ||
| _currentStationIndex = _driver setVariable ["GRAD_publicTransport_currentStationIndex", _nextStationIndex]; | ||
| }; | ||
|
|
||
| _nextPosition = getPos (_allStations select 0 select _nextStationIndex); | ||
| [_driver, _nextPosition] call GRAD_publicTransport_fnc_waypointsCreate; |
| @@ -0,0 +1,15 @@ | ||
| params ["_waypoint"]; | ||
|
|
||
| // this refers to the group leader | ||
| // thisList refers to an array containing each unit in the group | ||
|
|
||
| _waypoint setWaypointStatements [ | ||
| "true", | ||
| " | ||
| [this] spawn grad_publicTransport_fnc_waitForPassengers; | ||
| "]; | ||
|
|
||
| _waypoint setWaypointTimeout [0,0.25,0.5]; | ||
|
|
||
| _waypoint setWaypointSpeed "NORMAL"; // todo adjust to behaviour |
| @@ -0,0 +1,5 @@ | ||
| params ["_driver", "_pos"]; | ||
|
|
||
| _wp = (group _driver) addWaypoint [_pos, 0]; | ||
|
|
||
| [_wp] call grad_publicTransport_fnc_waypointSetStatements; |
| @@ -1 +1,15 @@ | ||
| /* | ||
| pathfinding by coding @armaworld.de | ||
| */ | ||
|
|
||
| [] execVM "grad_publicTransport\functions\bus\pathfinding_by_coding\init.sqf"; | ||
|
|
||
| /* | ||
| { | ||
| [_x, 0] call GRAD_publicTransport_fnc_createDebugMarker; | ||
| } forEach _waypoints; | ||
| */ | ||
|
|
||
| // call GRAD_publicTransport_fnc_findStations; |