diff --git a/CMakeLists.txt b/CMakeLists.txt index 9bc9719..ed24dea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -24,7 +24,7 @@ set(CORE gameManager.cpp game.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS}) set(PROJECTILES projectile.cpp) set(FX fx.cpp) set(VEHICLES vehicle.cpp engineer.cpp transport.cpp) -set(UNITS gameObjectFactory.cpp unit.cpp structure.cpp garrisonable.cpp ${VEHICLES}) +set(UNITS gameObjectFactory.cpp unit.cpp structure.cpp ${VEHICLES}) set(CONTENT player.cpp pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES} ${FX}) set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL}) diff --git a/garrisonable.cpp b/garrisonable.cpp index 5ce32d4..7857696 100644 --- a/garrisonable.cpp +++ b/garrisonable.cpp @@ -1,10 +1,23 @@ #include "garrisonable.h" +#include "unit.h" #include namespace battleship{ using namespace vb01; + void Garrisonable::update(){ + } + void Garrisonable::ejectVehicle(int id){ } + + void Garrisonable::prepareGarrisonSlots(){ + for(int i = 0; i < capacity; i++){ + Vector2 size = 10 * Vector2::VEC_IJ; + Vector2 pos = Vector2(0, 10 * (i)); + garrisonSlotBackgrounds.push_back(Unit::createBar(pos, size, Vector4(0, 0, 0, 1))); + garrisonSlotForegrounds.push_back(Unit::createBar(pos, size, Vector4(0, 1, 0, 1))); + } + } } diff --git a/garrisonable.h b/garrisonable.h index f4e6e13..df69025 100644 --- a/garrisonable.h +++ b/garrisonable.h @@ -3,6 +3,8 @@ #include +#include "unit.h" + namespace vb01{ class Node; } @@ -13,11 +15,15 @@ namespace battleship{ class Garrisonable{ public: Garrisonable(){} + ~Garrisonable(){} + void update(); void ejectVehicle(int); protected: int capacity; std::vector garrisonedVehicles; std::vector garrisonSlotForegrounds, garrisonSlotBackgrounds; + + void prepareGarrisonSlots(); }; } diff --git a/structure.cpp b/structure.cpp index a244790..f3d2fc2 100644 --- a/structure.cpp +++ b/structure.cpp @@ -9,8 +9,10 @@ using namespace std; namespace battleship{ Structure::Structure(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus) : Unit(player, id, pos, rot){ this->buildStatus = buildStatus; - buildStatusBackground = createBar(Unit::lenHpBar, Vector4(0, 0, 0, 1)); - buildStatusForeground = createBar(Unit::lenHpBar, Vector4(0, 0, 1, 1)); + + Vector2 size = Vector2(lenHpBar, 10); + buildStatusBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); + buildStatusForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 1, 1)); } Structure::~Structure(){ diff --git a/transport.cpp b/transport.cpp index 8fa2651..1742425 100644 --- a/transport.cpp +++ b/transport.cpp @@ -1,8 +1,13 @@ #include "transport.h" #include "player.h" +#include + namespace battleship{ using namespace vb01; + using namespace gameBase; - Transport::Transport(Player *player, int id, Vector3 pos, Quaternion rot) : Vehicle(player, id, pos, rot), Garrisonable(){} + Transport::Transport(Player *player, int id, Vector3 pos, Quaternion rot) : Vehicle(player, id, pos, rot){ + + } } diff --git a/transport.h b/transport.h index 747ba08..48ab8af 100644 --- a/transport.h +++ b/transport.h @@ -2,12 +2,11 @@ #define TRANSPORT_H #include "vehicle.h" -#include "garrisonable.h" namespace battleship{ class Player; - class Transport : public Vehicle, Garrisonable{ + class Transport : public Vehicle{ public: Transport(Player*, int, vb01::Vector3, vb01::Quaternion); private: diff --git a/unit.cpp b/unit.cpp index d109f8e..9c1f790 100755 --- a/unit.cpp +++ b/unit.cpp @@ -30,8 +30,9 @@ namespace battleship{ init(); - hpBackgroundNode = createBar(lenHpBar, Vector4(0, 0, 0, 1)); - hpForegroundNode = createBar(lenHpBar, Vector4(0, 1, 0, 1)); + Vector2 size = Vector2(lenHpBar, 10); + hpBackgroundNode = createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); + hpForegroundNode = createBar(Vector2::VEC_ZERO, size, Vector4(0, 1, 0, 1)); } Unit::~Unit() { @@ -60,6 +61,15 @@ namespace battleship{ lineOfSight = SOL_LUA_STATE["lineOfSight"][id + 1]; unitClass = (UnitClass)SOL_LUA_STATE["unitClass"][id + 1]; type = (UnitType)SOL_LUA_STATE["unitType"][id + 1]; + int capacity = SOL_LUA_STATE["garrisonCapacity"][id + 1]; + + for(int i = 0; i < capacity; i++){ + Vector2 size = 10 * Vector2::VEC_IJ; + Vector2 pos = Vector2(1.5 * size.x * i, 20); + Node *bg = createBar(pos, size, Vector4(0, 0, 0, 1)); + Node *fg = createBar(pos, size, Vector4(0, 1, 0, 1)); + garrisonSlots.push_back(GarrisonSlot(bg, fg, pos)); + } string cornerInd = "unitCornerPoints"; @@ -105,16 +115,16 @@ namespace battleship{ orientAt(rot); } - Node* Unit::createBar(float initLen, Vector4 color){ + 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(initLen, 10, 0), false); + Quad *quad = new Quad(Vector3(size.x, size.y, 0), false); quad->setMaterial(mat); - Node *node = new Node(); + Node *node = new Node(Vector3(pos.x, pos.y, 0)); node->attachMesh(quad); node->setVisible(false); root->getGuiNode()->attachChild(node); @@ -146,6 +156,9 @@ namespace battleship{ screenPos = spaceToScreen(pos); displayUnitStats(hpForegroundNode, hpBackgroundNode, health, maxHealth); + for(GarrisonSlot &slot : garrisonSlots) + displayUnitStats(slot.foreground, slot.background, (int)(slot.vehicle ? 1 : 0), (int)1, slot.offset); + if (health <= 0) blowUp(); } @@ -190,12 +203,13 @@ namespace battleship{ if(selected){ Vector3 offset3d = Vector3(offset.x, offset.y, 0); - float shiftedX = screenPos.x - 0.5 * lenHpBar; + + Quad *fgQuad = (Quad*)foreground->getMesh(0); + Vector3 size = fgQuad->getSize(); + float shiftedX = screenPos.x - 0.5 * size.x; background->setPosition(Vector3(shiftedX, screenPos.y, .1) + offset3d); - - Quad *fgQuad = (Quad*)foreground->getMesh(0); - fgQuad->setSize(Vector3((float)currVal / maxVal * lenHpBar, 10, 0)); + fgQuad->setSize(Vector3((float)currVal / maxVal * size.x, size.y, 0)); fgQuad->updateVerts(fgQuad->getMeshBase()); foreground->setPosition(Vector3(shiftedX, screenPos.y, 0) + offset3d); } diff --git a/unit.h b/unit.h index 27d4d49..d1fd8f0 100755 --- a/unit.h +++ b/unit.h @@ -24,7 +24,8 @@ namespace vb01{ namespace battleship{ class Player; - class Unit; + class Unit; + class Vehicle; struct Order { enum class TYPE {ATTACK, BUILD, MOVE, PATROL, LAUNCH}; @@ -51,6 +52,14 @@ namespace battleship{ class Unit : public GameObject{ public: + struct GarrisonSlot{ + Vehicle *vehicle = nullptr; + vb01::Node *background, *foreground; + vb01::Vector2 offset; + + GarrisonSlot(vb01::Node *bg, vb01::Node *fg, vb01::Vector2 off, Vehicle *v = nullptr) : background(bg), foreground(fg), offset(off), vehicle(v){} + }; + Unit(Player*, int, vb01::Vector3, vb01::Quaternion); ~Unit(); virtual void update(); @@ -90,9 +99,9 @@ namespace battleship{ int health, maxHealth, cost, id, playerId, lenHpBar = 200, rateOfFire; s64 orderLineDispTime = 0, lastFireTime = 0; float lineOfSight, range; + std::vector garrisonSlots; void removeOrder(int); - void displayUnitStats(vb01::Node*, vb01::Node*, int, int, vb01::Vector2 = vb01::Vector2::VEC_ZERO); virtual void initProperties(); virtual void destroySound(); virtual void initSound(); @@ -103,8 +112,9 @@ namespace battleship{ virtual void move(Order){} virtual void patrol(Order){} virtual void launch(Order){} - vb01::Node* createBar(float, vb01::Vector4); void removeBar(vb01::Node*); + vb01::Node* createBar(vb01::Vector2, vb01::Vector2, vb01::Vector4); + void displayUnitStats(vb01::Node*, vb01::Node*, int, int, vb01::Vector2 offset = vb01::Vector2::VEC_ZERO); }; } diff --git a/vehicle.cpp b/vehicle.cpp index 1547e47..dfe9de9 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -74,8 +74,6 @@ namespace battleship{ } void Vehicle::initProperties(){ - Unit::initProperties(); - sol::state_view SOL_LUA_STATE = generateView(); maxTurnAngle = SOL_LUA_STATE["maxTurnAngle"][id + 1]; speed = SOL_LUA_STATE["speed"][id + 1]; diff --git a/vehicle.h b/vehicle.h index 7c0339c..1ac3534 100644 --- a/vehicle.h +++ b/vehicle.h @@ -28,7 +28,6 @@ namespace battleship{ void halt(); void turn(float); void addOrder(Order); - void initProperties(); void advance(float, MoveDir = MoveDir::FORW); void preparePathpoints(Order); void removePathpoint(int = 0); @@ -39,6 +38,7 @@ namespace battleship{ void navigate(Order, float = 0.); void alignToSurface(); void attack(Order); + virtual void initProperties(); virtual void fire(); }; }