# Signal Towers

## Overview

The signal tower system simulates cell tower coverage and signal strength for the in-game phone. It determines the player's signal bars based on proximity to configured towers and updates the UI accordingly. The system also provides exports for other scripts to query or set signal strength.

***

## How Signal Strength is Calculated

* **Towers** are defined in `Config.SignalTowers.Towers` as a list of coordinates.
* The system calculates the distance from the player to the nearest tower.
* Signal strength (bars) is determined by which range threshold the player is within:
  * `Config.SignalTowers.Range[1]` (weakest, farthest)
  * ... up to `Config.SignalTowers.Range[4]` (strongest, closest)
* If the player is outside all tower ranges, the signal is set to 0.

## Debugging

* If `Config.SignalTowers.Debug` is enabled, blips are created for each tower and their signal ranges:
  * Main tower blip (icon)
  * Colored radius blips for each signal level (red, yellow, blue, green)
* Useful for visualizing coverage during development.

***

## Exports

The following exports are provided for use in other scripts:

### Get Current Service Bars

```lua
local bars = exports.yseries:GetCurrentService()
-- bars is 0-4
```

### Get All Towers

```lua
local towers = exports.yseries:GetAllTowers()
-- towers is a table of vector3 positions
```

### Force Signal Update

```lua
local newBars = exports.yseries:UpdateSignalStrength()
-- Recalculates and updates the signal
```

### Set Service Bars Manually

```lua
---@param level   - The level of the service(min:0, max: 4).
---@param disable - If *true disables auto service calculation thread.
exports.yseries:SetServiceBars(3, true)
```

## Configuration Notes

* All towers and ranges are set in `Config.SignalTowers`.
* To enable/disable the system, set `Config.SignalTowers.Enabled`.
* To show debug blips, set `Config.SignalTowers.Debug = true`.

***

## Events

* The system triggers `yseries:client:phone:service-changed` whenever the signal bars change.

***

## Troubleshooting

* If the signal is not updating, check that the config is loaded and the system is enabled.
* Use debug blips to verify tower placement and coverage.

***

For further customization, edit `client/utils/signalTowers.lua` and `Config.SignalTowers` as needed.
