From 4fa5d73c1b26a4bcd1ac6d427e04f019fc710b14 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 29 Nov 2025 15:57:27 +0200 Subject: [PATCH] using the Destructable class as part of units' and projectiles' inheritance structure --- CMakeLists.txt | 2 +- cruiseMissile.cpp | 29 ++++++------- cruiseMissile.h | 4 +- destructable.cpp | 101 +++++++++++++++++++++++++++++++++++++++++++++ destructable.h | 31 ++++++++++++++ engineer.cpp | 2 +- extractor.cpp | 2 +- factory.cpp | 8 +--- missile.cpp | 8 ++-- missile.h | 3 +- researchStruct.cpp | 2 +- resourceRover.cpp | 2 +- structure.cpp | 2 +- unit.cpp | 89 ++++----------------------------------- unit.h | 23 +++-------- 15 files changed, 178 insertions(+), 130 deletions(-) create mode 100644 destructable.cpp create mode 100644 destructable.h diff --git a/CMakeLists.txt b/CMakeLists.txt index c89e3e3..cde6055 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -35,7 +35,7 @@ set(PROJECTILES projectile.cpp missile.cpp cruiseMissile.cpp shell.cpp) set(VEHICLES vehicle.cpp submarine.cpp engineer.cpp resourceRover.cpp freezer.cpp) set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp researchStruct.cpp iceSheet.cpp) set(UNITS gameObjectFactory.cpp unit.cpp weapon.cpp ${STRUCTURES} ${VEHICLES}) -set(CONTENT player.cpp trader.cpp pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES}) +set(CONTENT player.cpp trader.cpp pathfinder.cpp map.cpp gameObject.cpp destructable.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES}) set(UTIL util.cpp binds.h) diff --git a/cruiseMissile.cpp b/cruiseMissile.cpp index 5034db8..00e23fc 100644 --- a/cruiseMissile.cpp +++ b/cruiseMissile.cpp @@ -12,30 +12,35 @@ namespace battleship{ using namespace std; using namespace vb01; - CruiseMissile::CruiseMissile(Unit *unit, int id, Vector3 tp, Vector3 pos, Quaternion rot) : Projectile(unit, id, pos, rot), targetPoint(tp), flightStage(FlightStage::ASCENT){ + CruiseMissile::CruiseMissile(Unit *unit, int id, Vector3 tp, Vector3 pos, Quaternion rot) : + Projectile(unit, id, pos, rot), + Destructable(unit->getPlayer(), id, GameObject::Type::PROJECTILE, pos, rot), + targetPoint(tp), + flightStage(FlightStage::ASCENT) + { Vector3 unitDir = unit->getDirVec(); Vector3 leftDir = unit->getLeftVec(); Vector3 targDir = (Vector3(targetPoint.x, pos.y, targetPoint.z) - pos).norm(); bool left = (leftDir.getAngleBetween(targDir) < PI / 2); float angle = unitDir.getAngleBetween(targDir) * (left ? 1 : -1); - orientAt(Quaternion(angle, Vector3::VEC_J) * rot); + Projectile::orientAt(Quaternion(angle, Vector3::VEC_J) * rot); } void CruiseMissile::pitch(float rotAngle, Vector3 compVec){ float minHeight = 20; - float angleToCompVec = dirVec.getAngleBetween(compVec); + float angleToCompVec = Projectile::dirVec.getAngleBetween(compVec); float angle = (angleToCompVec > rotAngle ? rotAngle : angleToCompVec); - if(flightStage == FlightStage::ASCENT && pos.y - initPos.y > minHeight){ - orientAt(Quaternion(angle, leftVec) * rot); - if(dirVec.y <= .001) flightStage = FlightStage::CRUISE; + if(flightStage == FlightStage::ASCENT && Projectile::pos.y - initPos.y > minHeight){ + Projectile::orientAt(Quaternion(angle, Projectile::leftVec) * Projectile::rot); + if(Projectile::dirVec.y <= .001) flightStage = FlightStage::CRUISE; } else if(flightStage == FlightStage::DESCENT){ Vector3 targDir = (Vector3(targetPoint.x, initPos.y, targetPoint.z) - initPos).norm(); - if(dirVec.getAngleBetween(targDir) < PI / 2) - orientAt(Quaternion(angle, leftVec) * rot); + if(Projectile::dirVec.getAngleBetween(targDir) < PI / 2) + Projectile::orientAt(Quaternion(angle, Projectile::leftVec) * Projectile::rot); } } @@ -43,7 +48,7 @@ namespace battleship{ float minDist = 6; float initDist = Vector3(targetPoint.x, initPos.y, targetPoint.z).getDistanceFrom(initPos); - if(pos.getDistanceFrom(Vector3(targetPoint.x, pos.y, targetPoint.z)) < minDist) + if(Projectile::pos.getDistanceFrom(Vector3(targetPoint.x, Projectile::pos.y, targetPoint.z)) < minDist) flightStage = FlightStage::DESCENT; } @@ -52,7 +57,7 @@ namespace battleship{ switch(flightStage){ case FlightStage::ASCENT: - pitch(rotAngle, Vector3(dirVec.x, 0, dirVec.z).norm()); + pitch(rotAngle, Vector3(Projectile::dirVec.x, 0, Projectile::dirVec.z).norm()); break; case FlightStage::DESCENT: pitch(rotAngle, -Vector3::VEC_J); @@ -62,10 +67,6 @@ namespace battleship{ break; } - checkCollision(); - } - - void CruiseMissile::checkCollision(){ if(flightStage == FlightStage::DESCENT) Projectile::checkCollision(); } diff --git a/cruiseMissile.h b/cruiseMissile.h index 19101ab..b03b0c7 100644 --- a/cruiseMissile.h +++ b/cruiseMissile.h @@ -2,9 +2,10 @@ #define CRUISE_MISSILE_H #include "projectile.h" +#include "destructable.h" namespace battleship{ - class CruiseMissile : public Projectile{ + class CruiseMissile : public Projectile, Destructable{ public: CruiseMissile(Unit*, int, vb01::Vector3, vb01::Vector3, vb01::Quaternion); void update(); @@ -15,7 +16,6 @@ namespace battleship{ void pitch(float, vb01::Vector3); void cruise(); - void checkCollision(); }; } diff --git a/destructable.cpp b/destructable.cpp new file mode 100644 index 0000000..cf1226d --- /dev/null +++ b/destructable.cpp @@ -0,0 +1,101 @@ +#include "destructable.h" +#include "environment.h" +#include "player.h" +#include "game.h" + +#include +#include +#include +#include + +#include + +#include + +using namespace std; +using namespace vb01; +using namespace gameBase; + +namespace battleship{ + Destructable::Destructable(Player *player, int id, GameObject::Type type, vb01::Vector3 pos, vb01::Quaternion rot) : GameObject(type, id, player, pos, rot){} + + void Destructable::initProperties(){ + GameObject::initProperties(); + + sol::state_view SOL_LUA_VIEW = generateView(); + string objType = GameObject::getGameObjTableName(); + sol::table objTable = SOL_LUA_VIEW[objType][id + 1]; + + vector currTechs = player->getTechnologies(); + health += Game::getSingleton()->calcAbilFromTech(Ability::Type::HEALTH, currTechs, (int)GameObject::type, id); + maxHealth = objTable["health"]; + + if(health == 0) health = maxHealth; + + string tblName = "armor"; + sol::optional at = objTable[tblName]; + + if(at != sol::nullopt){ + string varName = "numArmorTypes"; + SOL_LUA_VIEW.script(varName + " = #" + objType + "[" + to_string(id + 1) + "]." + tblName); + int numArmorTypes = SOL_LUA_VIEW[varName]; + + for(int i = 0; i < numArmorTypes; i++){ + Armor arm = (Armor)objTable[tblName][i + 1]; + armorTypes.push_back(arm); + } + } + } + + void Destructable::update(){ + GameObject::update(); + + if (health <= DEATH_HP){ + sol::table tbl = generateView()[getGameObjTableName()][id + 1]["deathFx"]; + FxManager::Fx *fx = FxManager::getSingleton()->initFx(tbl, model, false, pos); + Environment::explode(fx, Environment::Detonation::EXPLOSION, pos); + remove = true; + } + } + + Node* Destructable::createBar(Vector2 pos, Vector2 size, Vector4 color){ + Root *root = Root::getSingleton(); + Material *mat = new Material(root->getLibPath() + "gui"); + mat->addBoolUniform("texturingEnabled", false); + mat->addVec4Uniform("diffuseColor", color); + + Quad *quad = new Quad(Vector3(size.x, size.y, 0), false); + quad->setMaterial(mat); + + Node *node = new Node(Vector3(pos.x, pos.y, 0)); + node->attachMesh(quad); + node->setVisible(false); + root->getGuiNode()->attachChild(node); + + return node; + } + + void Destructable::displayStats(Node *foreground, Node *background, int currVal, int maxVal, bool render, Vector2 offset) { + foreground->setVisible(render); + background->setVisible(render); + + if(render){ + Vector3 offset3d = Vector3(offset.x, offset.y, 0); + + Quad *bgQuad = (Quad*)background->getMesh(0); + Vector3 size = bgQuad->getSize(); + float shiftedX = screenPos.x - 0.5 * size.x; + background->setPosition(Vector3(shiftedX, screenPos.y, 0) + offset3d); + + Quad *fgQuad = (Quad*)foreground->getMesh(0); + fgQuad->setSize(Vector3((float)currVal / maxVal * size.x, size.y, 0)); + fgQuad->updateVerts(fgQuad->getMeshBase()); + foreground->setPosition(Vector3(shiftedX, screenPos.y, .01) + offset3d); + } + } + + void Destructable::removeBar(Node *node){ + Root::getSingleton()->getGuiNode()->dettachChild(node); + delete node; + } +} diff --git a/destructable.h b/destructable.h new file mode 100644 index 0000000..f3c403d --- /dev/null +++ b/destructable.h @@ -0,0 +1,31 @@ +#ifndef DESTRUCTABLE_H +#define DESTRUCTABLE_H + +#include "gameObject.h" + +namespace battleship{ + enum class Armor {CAST, COMBINED, MECHANIC, SHELL, STEEL}; + + class Destructable : public GameObject{ + public: + Destructable(Player*, int, GameObject::Type, vb01::Vector3, vb01::Quaternion); + void update(); + virtual void initProperties(); + inline int getHealth(){return health;} + inline int getDeathHp(){return DEATH_HP;} + inline std::vector getArmorTypes(){return armorTypes;} + inline void takeDamage(int damage) {health -= damage * (1 + (freezeDmgFactor - 1) * freezeStatus * .01f);} + private: + std::vector armorTypes; + const int DEATH_HP = 0; + protected: + int health = 0, maxHealth, lenHpBar = 200, freezeStatus = 0, freezeDmgFactor = 10; + vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr; + + void removeBar(vb01::Node*); + vb01::Node* createBar(vb01::Vector2, vb01::Vector2, vb01::Vector4); + void displayStats(vb01::Node*, vb01::Node*, int, int, bool, vb01::Vector2 offset = vb01::Vector2::VEC_ZERO); + }; +} + +#endif diff --git a/engineer.cpp b/engineer.cpp index 937cbcb..8ebe582 100644 --- a/engineer.cpp +++ b/engineer.cpp @@ -40,7 +40,7 @@ namespace battleship{ bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); if(hackStatus < 100) - Unit::displayUnitStats(hackStatusForeground, hackStatusBackground, hackStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); + Unit::displayStats(hackStatusForeground, hackStatusBackground, hackStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); else{ hackStatusBackground->setVisible(false); hackStatusForeground->setVisible(false); diff --git a/extractor.cpp b/extractor.cpp index 2e5d0cc..73f5736 100644 --- a/extractor.cpp +++ b/extractor.cpp @@ -58,7 +58,7 @@ namespace battleship{ initAmmount = deposit->getInitAmmount(); } - Unit::displayUnitStats(ammountForeground, ammountBackground, ammount, initAmmount, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); + Unit::displayStats(ammountForeground, ammountBackground, ammount, initAmmount, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); } void Extractor::draw(){ diff --git a/factory.cpp b/factory.cpp index 6008c6e..1d2ae5c 100644 --- a/factory.cpp +++ b/factory.cpp @@ -21,16 +21,12 @@ namespace battleship{ if(!isComplete()) return; - if(!unitQueue.empty()) - train(); + if(!unitQueue.empty()) train(); } //TODO replace repetetive string literals void Factory::initProperties(){ Structure::initProperties(); - Game *game = Game::getSingleton(); - vector currTechs = player->getTechnologies(); - } int Factory::getNumQueueUnitsById(int unitId){ @@ -60,7 +56,7 @@ namespace battleship{ vector selectingPlayers = getSelectingPlayers(); bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); - Unit::displayUnitStats(buildStatusForeground, buildStatusBackground, trainingStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); + Unit::displayStats(buildStatusForeground, buildStatusBackground, trainingStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); sol::table targTable = generateView()["units"][unitQueue[0] + 1]; int costRate = (int)targTable["cost"] / 100, trainRate = (int)targTable["buildTime"] / 100; diff --git a/missile.cpp b/missile.cpp index 64754b5..81230cb 100644 --- a/missile.cpp +++ b/missile.cpp @@ -1,17 +1,19 @@ #include "missile.h" +#include "unit.h" namespace battleship{ using namespace vb01; Missile::Missile(Unit *un, int id, Vector3 tp, Vector3 pos, Quaternion rot) : Projectile(un, id, pos, rot), + Destructable(un->getPlayer(), id, GameObject::Type::PROJECTILE, pos, rot), targetPos(tp){} void Missile::update(){ - Vector3 targDir = (targetPos - pos).norm(); - float angle = targDir.getAngleBetween(dirVec); + Vector3 targDir = (targetPos - Projectile::pos).norm(); + float angle = targDir.getAngleBetween(Projectile::dirVec); float ra = (rotAngle < angle ? rotAngle : angle); - orientAt(Quaternion(ra, dirVec.cross(targDir)) * rot); + Projectile::orientAt(Quaternion(ra, Projectile::dirVec.cross(targDir)) * Projectile::rot); Projectile::update(); checkCollision(); diff --git a/missile.h b/missile.h index 44024f9..a0a82bb 100644 --- a/missile.h +++ b/missile.h @@ -2,9 +2,10 @@ #define MISSILE_H #include "projectile.h" +#include "destructable.h" namespace battleship{ - class Missile : public Projectile{ + class Missile : public Projectile, Destructable{ public: Missile(Unit*, int, vb01::Vector3, vb01::Vector3, vb01::Quaternion); ~Missile(){} diff --git a/researchStruct.cpp b/researchStruct.cpp index b31c89f..9ecd9aa 100644 --- a/researchStruct.cpp +++ b/researchStruct.cpp @@ -48,7 +48,7 @@ namespace battleship{ researchStatusForeground->setVisible(false); } else if(!researchQueue.empty()){ - Unit::displayUnitStats(researchStatusForeground, researchStatusBackground, researchStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); + Unit::displayStats(researchStatusForeground, researchStatusBackground, researchStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); int techCost = Game::getSingleton()->getTechnology(researchQueue[0]).cost; int playerResearch = player->getResource(ResourceType::RESEARCH); diff --git a/resourceRover.cpp b/resourceRover.cpp index 4cbafc5..ef0aadd 100644 --- a/resourceRover.cpp +++ b/resourceRover.cpp @@ -166,7 +166,7 @@ namespace battleship{ vector selectingPlayers = getSelectingPlayers(); bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); - Unit::displayUnitStats(loadForeground, loadBackground, calcTotalLoad(), capacity, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); + Unit::displayStats(loadForeground, loadBackground, calcTotalLoad(), capacity, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); } Unit* ResourceRover::getClosestUnit(vector structs){ diff --git a/structure.cpp b/structure.cpp index 52b5cd2..5785b24 100644 --- a/structure.cpp +++ b/structure.cpp @@ -31,7 +31,7 @@ namespace battleship{ bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); if(buildStatus < 100) - Unit::displayUnitStats(buildStatusForeground, buildStatusBackground, buildStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); + Unit::displayStats(buildStatusForeground, buildStatusBackground, buildStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10)); else{ buildStatusBackground->setVisible(false); buildStatusForeground->setVisible(false); diff --git a/unit.cpp b/unit.cpp index 7f4d295..263553a 100755 --- a/unit.cpp +++ b/unit.cpp @@ -18,7 +18,6 @@ #include "game.h" #include "map.h" #include "vehicle.h" -#include "environment.h" #include "gameObjectFactory.h" #include "activeGameState.h" #include "gameManager.h" @@ -33,7 +32,7 @@ using namespace gameBase; using namespace std; namespace battleship{ - Unit::Unit(Player *player, int id, Vector3 pos, Quaternion rot, State st) : GameObject(GameObject::Type::UNIT, id, player, pos, rot), state(st){ + Unit::Unit(Player *player, int id, Vector3 pos, Quaternion rot, State st) : Destructable(player, id, GameObject::Type::UNIT, pos, rot), state(st){ selectable = true; restartTime = 2000; @@ -61,7 +60,7 @@ namespace battleship{ } void Unit::initProperties(){ - GameObject::initProperties(); + Destructable::initProperties(); sol::state_view SOL_LUA_VIEW = generateView(); string objType = GameObject::getGameObjTableName(); @@ -73,10 +72,6 @@ namespace battleship{ string name = unitTable["name"]; alignToSurface = unitTable["alignToSurface"].get_or(false); vehicle = unitTable["isVehicle"]; - health += game->calcAbilFromTech(Ability::Type::HEALTH, currTechs, (int)GameObject::type, id); - maxHealth = unitTable["health"]; - - if(health == 0) health = maxHealth; lineOfSight = unitTable["lineOfSight"]; lineOfSight += game->calcAbilFromTech(Ability::Type::LINE_OF_SIGHT, currTechs, (int)GameObject::type, id); unitClass = (UnitClass)unitTable["unitClass"]; @@ -106,20 +101,6 @@ namespace battleship{ } } - tblName = "armor"; - sol::optional at = unitTable[tblName]; - - if(at != sol::nullopt){ - string varName = "numArmorTypes"; - SOL_LUA_VIEW.script(varName + " = #" + objType + "[" + to_string(id + 1) + "]." + tblName); - int numArmorTypes = SOL_LUA_VIEW[varName]; - - for(int i = 0; i < numArmorTypes; i++){ - Armor arm = (Armor)unitTable[tblName][i + 1]; - armorTypes.push_back(arm); - } - } - tblName = "buildableUnits"; sol::optional bu = unitTable[tblName]; @@ -226,28 +207,6 @@ namespace battleship{ return false; } - Node* Unit::createBar(Vector2 pos, Vector2 size, Vector4 color){ - Root *root = Root::getSingleton(); - Material *mat = new Material(root->getLibPath() + "gui"); - mat->addBoolUniform("texturingEnabled", false); - mat->addVec4Uniform("diffuseColor", color); - - Quad *quad = new Quad(Vector3(size.x, size.y, 0), false); - quad->setMaterial(mat); - - Node *node = new Node(Vector3(pos.x, pos.y, 0)); - node->attachMesh(quad); - node->setVisible(false); - root->getGuiNode()->attachChild(node); - - return node; - } - - void Unit::removeBar(Node *node){ - Root::getSingleton()->getGuiNode()->dettachChild(node); - delete node; - } - void Unit::launch(Order order){ getWeaponsByOrder(Order::TYPE::LAUNCH)[0]->fire(order); removeOrder(0); @@ -262,10 +221,6 @@ namespace battleship{ return rotSpeed; } - - void Unit::initUnitStats(){ - } - void Unit::renderOrderLine(bool mainPlayerSelecting){ if (!orders.empty() && orders[0].lineId != -1 && mainPlayerSelecting){ bool display = canDisplayOrderLine(); @@ -299,62 +254,34 @@ namespace battleship{ } void Unit::update() { - GameObject::update(); + Destructable::update(); if(condition == Condition::EM_JAMMED && getTime() - lastJamTime > restartTime) condition = Condition::ABLE; if(freezeStatus >= 100) condition = Condition::FROZEN; - ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); - Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr); - if(state != State::HOLD_FIRE) targetUnitsAutomatically(); + ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); + Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr); vector selectingPlayers = getSelectingPlayers(); bool mainPlayerSelecting = (find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); bool mainPlayerOwner = (player == mainPlayer); bool renderSelectables = (mainPlayerSelecting && mainPlayerOwner); - renderOrderLine(renderSelectables); - executeOrders(); - displayUnitStats(hpForegroundNode, hpBackgroundNode, health, maxHealth, mainPlayerSelecting); + executeOrders(); + displayStats(hpForegroundNode, hpBackgroundNode, health, maxHealth, mainPlayerSelecting); for(GarrisonSlot &slot : garrisonSlots) - displayUnitStats(slot.foreground, slot.background, (int)((bool)slot.vehicle), (int)true, renderSelectables, slot.offset); - - if (health <= DEATH_HP){ - sol::table tbl = generateView()[getGameObjTableName()][id + 1]["deathFx"]; - FxManager::Fx *fx = FxManager::getSingleton()->initFx(tbl, model, false, pos); - Environment::explode(fx, Environment::Detonation::EXPLOSION, pos); - remove = true; - } + displayStats(slot.foreground, slot.background, (int)((bool)slot.vehicle), (int)true, renderSelectables, slot.offset); for(Weapon *weapon : weapons) weapon->update(); } - void Unit::displayUnitStats(Node *foreground, Node *background, int currVal, int maxVal, bool render, Vector2 offset) { - foreground->setVisible(render); - background->setVisible(render); - - if(render){ - Vector3 offset3d = Vector3(offset.x, offset.y, 0); - - Quad *bgQuad = (Quad*)background->getMesh(0); - Vector3 size = bgQuad->getSize(); - float shiftedX = screenPos.x - 0.5 * size.x; - background->setPosition(Vector3(shiftedX, screenPos.y, 0) + offset3d); - - Quad *fgQuad = (Quad*)foreground->getMesh(0); - fgQuad->setSize(Vector3((float)currVal / maxVal * size.x, size.y, 0)); - fgQuad->updateVerts(fgQuad->getMeshBase()); - foreground->setPosition(Vector3(shiftedX, screenPos.y, .01) + offset3d); - } - } - //TODO remove order argument from action methods void Unit::executeOrders() { if(orders.empty() || condition != Condition::ABLE) return; diff --git a/unit.h b/unit.h index d9dca9f..71239cb 100755 --- a/unit.h +++ b/unit.h @@ -8,7 +8,7 @@ #include -#include "gameObject.h" +#include "destructable.h" #include "buildableUnit.h" #include "fxManager.h" @@ -89,7 +89,7 @@ namespace battleship{ ICE_SHEET }; - class Unit : public GameObject{ + class Unit : public Destructable{ public: struct GarrisonSlot{ Vehicle *vehicle = nullptr; @@ -100,7 +100,6 @@ namespace battleship{ GarrisonSlot(vb01::Node *bg, vb01::Node *fg, vb01::Vector2 off, int cat, Vehicle *v = nullptr) : background(bg), foreground(fg), offset(off), category(cat), vehicle(v){} }; - enum class Armor {CAST, COMBINED, MECHANIC, SHELL, STEEL}; enum class State {CHASE, STAND_GROUND, HOLD_FIRE}; enum class Condition{ABLE, FROZEN, EM_JAMMED}; @@ -128,10 +127,7 @@ namespace battleship{ inline float getLineOfSight() {return lineOfSight;} inline UnitType getType() {return type;} inline UnitClass getUnitClass() {return unitClass;} - inline void takeDamage(int damage) {health -= damage * (1 + (freezeDmgFactor - 1) * freezeStatus * .01f);} inline int getPlayerId() {return playerId;} - inline int getHealth(){return health;} - inline int getDeathHp(){return DEATH_HP;} inline bool isVehicle(){return vehicle;} inline bool isTargetToTheRight(vb01::Vector3 dir, vb01::Vector3 lv){return lv.getAngleBetween(dir) > vb01::PI / 2;} inline Order getOrder(int i){return orders[i];} @@ -149,27 +145,25 @@ namespace battleship{ } private: void renderOrderLine(bool); - void updateScreenCoordinates(); void initWeapons(); void destroyWeapons(); bool validateOrder(Order); inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;} - const int orderVecDispLength = 2000, DEATH_HP = 0; + const int orderVecDispLength = 2000; sf::SoundBuffer *selectionSfxBuffer; sf::Sound *selectionSfx = nullptr; - vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr, *losLightNode = nullptr; + vb01::Node *losLightNode = nullptr; bool vehicle, currOrderStarted = false, alignToSurface = false; Condition condition = Condition::ABLE; protected: - UnitClass unitClass; UnitType type; + UnitClass unitClass; std::vector orders; std::string guiScreen = ""; - int health = 0, maxHealth, playerId, lenHpBar = 200, freezeStatus = 0, freezeDmgFactor = 10, restartTime; + int playerId, restartTime; vb01::s64 orderLineDispTime = 0, lastFireTime = 0, lastJamTime = 0; float lineOfSight; - std::vector armorTypes; std::vector weapons; std::vector garrisonSlots; std::vector buildableUnits; @@ -186,7 +180,6 @@ namespace battleship{ virtual void initProperties(); virtual void destroySound(); virtual void initSound(); - virtual void initUnitStats(); virtual void executeOrders(); virtual void eject(Order); virtual void attack(Order); @@ -199,11 +192,7 @@ namespace battleship{ virtual void hack(Order){} virtual void freeze(Order){} float calculateRotation(vb01::Vector3, float, float); - void removeBar(vb01::Node*); - vb01::Node* createBar(vb01::Vector2, vb01::Vector2, vb01::Vector4); - void displayUnitStats(vb01::Node*, vb01::Node*, int, int, bool, vb01::Vector2 offset = vb01::Vector2::VEC_ZERO); std::vector getWeaponsByOrder(Order::TYPE); - inline std::vector getArmorTypes(){return armorTypes;} }; }