engineers can only hack units within a certain distance

This commit is contained in:
devZoGok
2024-02-17 14:50:21 +02:00
parent b9071536d6
commit 21249e0777
5 changed files with 26 additions and 4 deletions
@@ -130,6 +130,7 @@ units = {
armor = {ArmorType.MECHANIC},
isVehicle = true,
health = 500,
hackRange = 30,
buildTime = 1000,
hackTime = 1000,
cost = 500,
+1
View File
@@ -330,6 +330,7 @@ namespace battleship{
unit->setState(state);
}
//TODO only allow appropriate orders for units
void ActiveGameState::onAction(int bind, bool isPressed) {
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
+20 -1
View File
@@ -16,6 +16,8 @@ namespace battleship{
using namespace gameBase;
Engineer::Engineer(Player *player, int id, Vector3 pos, Quaternion rot, Unit::State state) : Vehicle(player, id, pos, rot, state){
hackRange = generateView()["units"][id + 1]["hackRange"];
Vector2 size = Vector2(lenHpBar, 10);
hackStatusBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
hackStatusForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(1, 0, 1, 1));
@@ -41,6 +43,9 @@ namespace battleship{
hackStatusBackground->setVisible(false);
hackStatusForeground->setVisible(false);
}
if(orders.empty() || orders[0].type != Order::TYPE::HACK)
hackStatus = 0;
}
void Engineer::build(Order order){
@@ -72,11 +77,25 @@ namespace battleship{
}
void Engineer::hack(Order order){
Unit *targUnit = order.targets[0].unit;
bool withinRange = (targUnit->getPos().getDistanceFrom(pos) < hackRange);
int hackRate = int(generateView()["units"][id + 1]["hackTime"]) / 100;
bool canHack = (getTime() - lastIncrementTime > hackRate);
if(canHack)
if(withinRange && canHack){
hackStatus++;
pursuingTarget = false;
}
else if(!withinRange){
hackStatus = 0;
if(!pursuingTarget){
preparePathpoints(order, targUnit->getPos());
pursuingTarget = true;
}
else
navigateToTarget(.9 * hackRange);
}
if(hackStatus >= 100){
Game::getSingleton()->changeUnitPlayer(order.targets[0].unit, player);
+2 -1
View File
@@ -18,8 +18,9 @@ namespace battleship{
~Engineer();
void update();
private:
vb01::s64 lastIncrementTime = 0;
int hackStatus = 0;
float hackRange;
vb01::s64 lastIncrementTime = 0;
vb01::Node *hackStatusBackground = nullptr, *hackStatusForeground = nullptr;
void build(Order);
+2 -2
View File
@@ -19,7 +19,6 @@ namespace battleship{
inline int getGarrisonCategory(){return garrisonCategory;}
private:
Unit *garrisonable = nullptr;
bool pursuingTarget = false;
int patrolPointId = 0, garrisonCategory;
float speed, maxTurnAngle, anglePrecision;
vb01::Material *debugMat = nullptr;
@@ -27,7 +26,6 @@ namespace battleship{
inline int getNextPatrolPointId(int numPoints) {return patrolPointId == numPoints - 1 ? 0 : patrolPointId + 1;}
void enterGarrisonable();
void navigateToTarget(float);
void halt();
void turn(float);
void addOrder(Order);
@@ -38,8 +36,10 @@ namespace battleship{
void select();
protected:
std::vector<vb01::Vector3> pathPoints;
bool pursuingTarget = false;
void navigate(float = 0.);
void navigateToTarget(float);
void preparePathpoints(Order&, vb01::Vector3, bool = false);
void alignToSurface();
void attack(Order);