implement sensor range requirements
This commit is contained in:
@@ -41,7 +41,6 @@ struct RepairTool
|
||||
|
||||
struct ThreatResponse
|
||||
{
|
||||
float engagementRange;
|
||||
std::optional<EntityId> currentTarget;
|
||||
};
|
||||
|
||||
@@ -78,7 +77,8 @@ struct Ship
|
||||
QVector2D velocity;
|
||||
float hp;
|
||||
float maxHp;
|
||||
float speedPerTick; // pre-evaluated from speedFormula / kTickRateHz
|
||||
float speedPerTick; // pre-evaluated from speedFormula / kTickRateHz
|
||||
float sensorRange; // pre-evaluated from sensorRangeFormula (REQ-SHP-SENSOR)
|
||||
int level;
|
||||
std::string schematicId;
|
||||
|
||||
|
||||
@@ -47,6 +47,7 @@ EntityId ShipSystem::spawn(const std::string& schematicId, int level, QVector2D
|
||||
ship.speedPerTick = static_cast<float>(
|
||||
def->movement.speedFormula.evaluate(x))
|
||||
/ static_cast<float>(kTickRateHz);
|
||||
ship.sensorRange = static_cast<float>(def->sensor.sensorRangeFormula.evaluate(x));
|
||||
ship.level = level;
|
||||
ship.schematicId = schematicId;
|
||||
ship.isEnemy = isEnemy;
|
||||
@@ -61,9 +62,7 @@ EntityId ShipSystem::spawn(const std::string& schematicId, int level, QVector2D
|
||||
w.cooldownTicks = 0.0f;
|
||||
ship.weapon = w;
|
||||
|
||||
ThreatResponse tr;
|
||||
tr.engagementRange = w.range;
|
||||
ship.threatResponse = tr;
|
||||
ship.threatResponse = ThreatResponse{};
|
||||
|
||||
if (!isEnemy)
|
||||
{
|
||||
@@ -241,7 +240,7 @@ void ShipSystem::tickThreatResponse(const BuildingSystem& buildings)
|
||||
continue;
|
||||
}
|
||||
|
||||
const float range = s.threatResponse->engagementRange;
|
||||
const float range = s.sensorRange;
|
||||
|
||||
if (!s.isEnemy)
|
||||
{
|
||||
@@ -394,7 +393,6 @@ void ShipSystem::tickThreatResponse(const BuildingSystem& buildings)
|
||||
void ShipSystem::tickRepairBehavior(BuildingSystem& buildings)
|
||||
{
|
||||
const std::vector<Building> allBuildings = buildings.allBuildings();
|
||||
const float kPatrolRange = 3.0f; // scan radius relative to repair range
|
||||
|
||||
for (Ship& s : m_ships)
|
||||
{
|
||||
@@ -410,7 +408,7 @@ void ShipSystem::tickRepairBehavior(BuildingSystem& buildings)
|
||||
for (const Ship& candidate : m_ships)
|
||||
{
|
||||
if (candidate.isEnemy
|
||||
&& (candidate.position - s.position).length() <= repairRange)
|
||||
&& (candidate.position - s.position).length() <= s.sensorRange)
|
||||
{
|
||||
enemyNearby = true;
|
||||
break;
|
||||
@@ -450,7 +448,7 @@ void ShipSystem::tickRepairBehavior(BuildingSystem& buildings)
|
||||
{
|
||||
s.repairBehavior->currentTarget = std::nullopt;
|
||||
currentId = kInvalidEntityId;
|
||||
float bestDist = repairRange * kPatrolRange;
|
||||
float bestDist = s.sensorRange;
|
||||
|
||||
for (const Ship& candidate : m_ships)
|
||||
{
|
||||
@@ -640,8 +638,7 @@ void ShipSystem::tickScrapCollector(ScrapSystem& scraps, const BuildingSystem& b
|
||||
else
|
||||
{
|
||||
// Scan for nearest scrap within sensor range.
|
||||
const float sensorRange = collectRange * 5.0f;
|
||||
float bestDist = sensorRange;
|
||||
float bestDist = s.sensorRange;
|
||||
std::optional<QVector2D> bestPos;
|
||||
for (const Scrap& sc : scraps.allScraps())
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user