From ed932b7ac99c01ae2b1b3e0b9a6725d8f9faa538 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 26 Nov 2023 10:54:06 +0200 Subject: [PATCH] Point defenses fire at targets within range --- Assets/Scripts/GameObjects/Units/unitData.lua | 6 +++--- pointDefense.cpp | 10 ++++++++-- unit.cpp | 1 - 3 files changed, 11 insertions(+), 6 deletions(-) diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 1c582b9..2a796df 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -46,9 +46,9 @@ units = { health = {500, 600, 200, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500}, cost = {500, 600, 200, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500}, - range = {15, 20, 45, 15, 14, 14, 13, 13, 12, 12, 15, 0, 25}, - damage = {15, 20, 45, 15, 14, 14, 13, 13, 12, 12, 15, 100, 100}, - rateOfFire = {50, 60, 80, 100, 100, 100, 100, 100, 0, 0, 0, 0, 100}, + range = {15, 20, 45, 15, 14, 14, 13, 13, 12, 12, 15, 0, 40}, + damage = {15, 120, 250, 15, 14, 14, 13, 13, 12, 12, 15, 100, 100}, + rateOfFire = {50, 2000, 5000, 100, 100, 100, 100, 100, 0, 0, 0, 0, 100}, garrisonCapacity = {0, 0, 0, 0, 3, 0, 0, 0, 0, 0, 0, 0, 0}, unitCornerPoints = { diff --git a/pointDefense.cpp b/pointDefense.cpp index 463c9b0..3e0c3af 100644 --- a/pointDefense.cpp +++ b/pointDefense.cpp @@ -9,11 +9,17 @@ namespace battleship{ void PointDefense::attack(Order order){ Unit *targUnit = order.targets[0].unit; - Vector3 targDir = ((targUnit ? targUnit->getPos() : order.targets[0].pos) - pos).norm(); + Vector3 targDir = (targUnit ? targUnit->getPos() : order.targets[0].pos) - pos; + + if(targDir.getLength() > range){ + removeOrder(0); + return; + } + float angleToTarg = targDir.getAngleBetween(turretDir); if(angleToTarg > .05) - rotateTurret(calculateRotation(targDir, angleToTarg, .1)); + rotateTurret(calculateRotation(targDir.norm(), angleToTarg, .1)); else if(canFire()) fire(); diff --git a/unit.cpp b/unit.cpp index 3c824a5..de95a95 100755 --- a/unit.cpp +++ b/unit.cpp @@ -24,7 +24,6 @@ using namespace gameBase; using namespace std; namespace battleship{ - //TODO remove the player member field Unit::Unit(Player *player, int id, Vector3 pos, Quaternion rot) : GameObject(GameObject::Type::UNIT, id, player, pos, rot){ this->id = id; this->player = player;