Skip to content

career_modules_delivery_vehicleTasks

File: lua/ge/extensions/career/modules/delivery/vehicleTasks.lua · VM: Game Engine (GE) · 713 lines · BeamNG.drive 0.40.5 (buildbot 302427 on GitLab)

Access: extension career_modules_delivery_vehicleTasks: extensions.load("career_modules_delivery_vehicleTasks"), then the global career_modules_delivery_vehicleTasks

Runs the vehicle and trailer delivery tasks accepted in career. Each offer becomes a taskData with a series of steps (coupleTrailer or enterVehicle, bringToDestination, confirmDropOff), an active step index and a GPS path (core_groundMarkers). onUpdate advances the steps according to position and couplings, handles the end of a delivery (vehicle removal, task removal), abandonment (fine) and computes the detailed rewards (damage, detours, delays, loaner organization, branch level, parking precision).

Notes

  • Steps generated by expandTasks: trailerDropOff = coupleTrailer, bringToDestination (backOn='unCouple'), confirmDropOff; vehicleDropOff = enterVehicle, bringToDestination (backOn='exitVehicle'), confirmDropOff.
  • Probable bug: expandTasks writes backOn = 'unCouple' (capital C) whereas processActiveTask tests 'uncouple': going back a step on uncoupling a trailer never triggers.
  • The putIntoParkingSpot step is handled by processActiveTask (checkParking, forwardOn 'unCouple'/'exitVehicle') and by tasklist, but expandTasks never generates it in this version. Here too forwardOn is compared with 'unCouple' whereas tasklist tests 'uncouple'.
  • Arrival-at-destination threshold: 20 m (squared distance 400) between the vehicle and the parking spot.
  • Rewards: >= 25% broken parts = money lost entirely and reputation x-2; beyond the broken parts threshold (valueCalculator) = linear reduction; otherwise +5% money. "No detour" bonus (distance < 1.2x the original distance) and "no delay" bonus (time < distance/12 + 30 s): +15% money + 10, +12.5% reputation, only if no excess broken parts.
  • The parking precision bonuses are computed a second time here (instead of precisionParking.calculateVehiclePrecisionParking) and the logistics bonus is based on originalRewards['logistics'].
  • The onCouplerAttached/onCouplerDetached handlers are in a commented block: they are not exported.
  • navigateToTask changes the GPS path: only one destination is followed at a time (the last task added).

Dependencies (loaded first): util_stepHandler

Functions

Function Description Line
career_modules_delivery_vehicleTasks.abandonAllVehicleTasks() Removes the vehicles of all tasks (the player goes back on foot if in one of them) and clears the list, without applying a fine. 674
career_modules_delivery_vehicleTasks.addVehicleTask(vehId, offer) Creates an offer's taskData (steps according to the offer type, active index 1, start timestamp), adds it to the list, updates the tasklist and starts navigation to the first step. 73
career_modules_delivery_vehicleTasks.canDropOffCargoAtPsPath(psPath) Counts the vehicles and trailers whose active step is confirmDropOff at this parking spot. 420
career_modules_delivery_vehicleTasks.drawDebugMenu() "Trailer Tasks Debug" ImGui debug window that displays vehicleTasks with dumps. 700
career_modules_delivery_vehicleTasks.finishTasks(offerIds) Finishes the tasks of the given offers: stores the drop-off spot, reads broken parts and odometer, computes the rewards, then marks finished. The vehicle is removed and the task deleted at a later update (processFinished). 434
career_modules_delivery_vehicleTasks.getFineForAbandon(taskData) Computes the abandonment fine: -(offer's money) x the delivery's penalty factor, and the organization's reputation penalty (event discardDeliveryVehicle). 527
career_modules_delivery_vehicleTasks.getFineForAbandonAllVehicleTasks() Sum of the abandonment fines of all vehicle tasks. 663
career_modules_delivery_vehicleTasks.getTargetDestinationsForActiveTasks() Lists the destinations of all steps of all tasks. 624
career_modules_delivery_vehicleTasks.getVehicleDataWithRewardsSummary() Prepares the reward data of the vehicles ready to be dropped off (confirmDropOff step) for the drop-off screen: reads the broken parts and odometer, computes originalRewards/breakdown/adjustedRewards, then calls progress.openDropOffScreenGatheringComplete. Returns the formatted list (finished becomes true later). 362
career_modules_delivery_vehicleTasks.getVehicleTaskForOffer(offer) Looks up the task corresponding to an offer. 686
career_modules_delivery_vehicleTasks.getVehicleTasks() Returns the list (reference) of the vehicle tasks in progress. 658
career_modules_delivery_vehicleTasks.giveBackDeliveryVehicle(vehId) Marks the vehicle's task as given back (giveBack); processGiveBack will remove the vehicle, apply the fine and show a message. 648
career_modules_delivery_vehicleTasks.isVehicleDeliveryVehicle(vehId) Indicates whether this vehicle is the vehicle of a delivery task in progress. 638
career_modules_delivery_vehicleTasks.navigateToNextTask() Restarts the GPS path to the active step of the last task in the list. 571
career_modules_delivery_vehicleTasks.onCareerActivated() Hook called on career activation: stores the delivery extensions and util_stepHandler. (internal) (hook) 8
career_modules_delivery_vehicleTasks.onTrailerAttached(objId1, objId2) Hook called when a trailer is coupled: updates the loaner organizations of each vehicle task. (internal) (hook) 201
career_modules_delivery_vehicleTasks.onUpdate(dtReal, dtSim, dtRaw) Per-frame hook: advances or goes back through the steps according to position, coupling and the controlled vehicle, processes the finished and given-back tasks, removes finished tasks, leaves delivery mode if needed and updates navigation. (internal) (hook) 578

Parameter details

career_modules_delivery_vehicleTasks.addVehicleTask(vehId, offer)

Creates an offer's taskData (steps according to the offer type, active index 1, start timestamp), adds it to the list, updates the tasklist and starts navigation to the first step.

  • vehId (integer) : Vehicle or trailer identifier.
  • offer (table) : Accepted offer (task.type 'trailerDropOff' or 'vehicleDropOff').

career_modules_delivery_vehicleTasks.canDropOffCargoAtPsPath(psPath)

Counts the vehicles and trailers whose active step is confirmDropOff at this parking spot.

  • psPath (string) : Parking spot path.
  • returns: integer Number of vehicles.
  • returns: integer Number of trailers.

career_modules_delivery_vehicleTasks.finishTasks(offerIds)

Finishes the tasks of the given offers: stores the drop-off spot, reads broken parts and odometer, computes the rewards, then marks finished. The vehicle is removed and the task deleted at a later update (processFinished).

  • offerIds (table) : List of offer identifiers.
  • returns: table List of the taskData concerned (finished updated asynchronously).

career_modules_delivery_vehicleTasks.getFineForAbandon(taskData)

Computes the abandonment fine: -(offer's money) x the delivery's penalty factor, and the organization's reputation penalty (event discardDeliveryVehicle).

  • taskData (table) : Vehicle task.
  • returns: table Amounts to add (negative): money and possibly Reputation.

career_modules_delivery_vehicleTasks.getFineForAbandonAllVehicleTasks()

Sum of the abandonment fines of all vehicle tasks.

  • returns: table Amounts accumulated per attribute.

career_modules_delivery_vehicleTasks.getTargetDestinationsForActiveTasks()

Lists the destinations of all steps of all tasks.

  • returns: table List of destinations (psPath, facId…).

career_modules_delivery_vehicleTasks.getVehicleDataWithRewardsSummary()

Prepares the reward data of the vehicles ready to be dropped off (confirmDropOff step) for the drop-off screen: reads the broken parts and odometer, computes originalRewards/breakdown/adjustedRewards, then calls progress.openDropOffScreenGatheringComplete. Returns the formatted list (finished becomes true later).

  • returns: table List of offers formatted for the UI.

career_modules_delivery_vehicleTasks.getVehicleTaskForOffer(offer)

Looks up the task corresponding to an offer.

  • offer (table) : Offer (field id).
  • returns: table|nil taskData or nil.

career_modules_delivery_vehicleTasks.getVehicleTasks()

Returns the list (reference) of the vehicle tasks in progress.

  • returns: table List of taskData.

career_modules_delivery_vehicleTasks.giveBackDeliveryVehicle(vehId)

Marks the vehicle's task as given back (giveBack); processGiveBack will remove the vehicle, apply the fine and show a message.

  • vehId (integer) : Vehicle identifier.

career_modules_delivery_vehicleTasks.isVehicleDeliveryVehicle(vehId)

Indicates whether this vehicle is the vehicle of a delivery task in progress.

  • vehId (integer) : Vehicle identifier.
  • returns: boolean true if so.

career_modules_delivery_vehicleTasks.onTrailerAttached(objId1, objId2)

Hook called when a trailer is coupled: updates the loaner organizations of each vehicle task.

  • objId1 (integer) : First vehicle.
  • objId2 (integer) : Second vehicle.

career_modules_delivery_vehicleTasks.onUpdate(dtReal, dtSim, dtRaw)

Per-frame hook: advances or goes back through the steps according to position, coupling and the controlled vehicle, processes the finished and given-back tasks, removes finished tasks, leaves delivery mode if needed and updates navigation.

  • dtReal (number) : Real time delta (s).
  • dtSim (number) : Simulation time delta (s).
  • dtRaw (number) : Raw time delta (s).

Fields

Field Type Description
debugName string Debug menu name: 'Delivery > Trailer Tasks'.
debugOrder number Order in the debug menu (12).
dependencies table Extensions loaded before: util_stepHandler.

UI events (guihooks.trigger): Message

Calls into the engine (C++)

  • be: getPlayerVehicleID
  • scenetree. findObjectById

tim19Atlas (Tim0219800) — derived from BeamNG GmbH Lua code (bCDDL 1.1, see LICENSE). Source: lua/ge/extensions/career/modules/delivery/vehicleTasks.lua.