diff --git a/activeGameState.cpp b/activeGameState.cpp index d0b1186..e2e4a5f 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -300,7 +300,7 @@ namespace battleship{ case Bind::TOGGLE_SUB: if (isPressed) { for (Unit *u : selectedUnits) { - if (u->getPlayer() == mainPlayer && u->getType() == unitData::UNIT_TYPE::SUBMARINE) { + if (u->getPlayer() == mainPlayer && u->getType() == UnitType::SUBMARINE) { Submarine *s = (Submarine*) u; if (s->isSubmerged()) diff --git a/destroyer.cpp b/destroyer.cpp index 766dc14..8d8201c 100755 --- a/destroyer.cpp +++ b/destroyer.cpp @@ -31,12 +31,12 @@ namespace battleship{ void Destroyer::attack(Order order){ Vector3 t = order.targets[0].pos; - bool sub=false; + bool sub = false; InGameAppState *inGameState=((InGameAppState*)GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::IN_GAME_STATE)); for(Player *p : inGameState->getPlayers()) for(Unit *u : p->getUnits()) - if(u->getType() == UNIT_TYPE::SUBMARINE && order.targets[0].pos == u->getPos()) + if(u->getType() == UnitType::SUBMARINE && order.targets[0].pos == u->getPos()) sub = true; if(sub) diff --git a/explosion.cpp b/explosion.cpp index 5f4fa31..8fc21d6 100644 --- a/explosion.cpp +++ b/explosion.cpp @@ -8,8 +8,6 @@ using namespace std; using namespace vb01; namespace battleship{ - using namespace configData; - void detonate(InGameAppState *inGameState, Vector3 pos, Vector3 dir){ sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer(); sf::Sound *sfx = nullptr; diff --git a/inGameAppState.cpp b/inGameAppState.cpp index 121b5eb..a755260 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -251,7 +251,7 @@ namespace battleship{ std::vector &units=p->getUnits(),&selectedUnits=activeState->getSelectedUnits(); units.erase(units.begin()+i); - if(u->getType()==unitData::UNIT_TYPE::MISSILE_JET||u->getType()==unitData::UNIT_TYPE::DEMO_JET){ + if(u->getType() == UnitType::MISSILE_JET || u->getType() == UnitType::DEMO_JET){ AircraftCarrier *carrier=nullptr; for(int i2=0;i2getUnits().size()&&!carrier;i2++){ @@ -266,7 +266,7 @@ namespace battleship{ jets[((Jet*)u)->getJetId()]=nullptr; } } - else if(u->getType()==unitData::UNIT_TYPE::AIRCRAFT_CARRIER){ + else if(u->getType() == UnitType::AIRCRAFT_CARRIER){ AircraftCarrier *carrier=(AircraftCarrier*)u; for(int i2=0;i2getMaxNumJets();i2++){ diff --git a/missileJet.cpp b/missileJet.cpp index 78b06d2..4618510 100755 --- a/missileJet.cpp +++ b/missileJet.cpp @@ -24,7 +24,7 @@ namespace battleship{ for(Player *p : inGameState->getPlayers()) for(Unit *u : p->getUnits()){ - bool jet = (u->getType() == UNIT_TYPE::MISSILE_JET || u->getType() == UNIT_TYPE::DEMO_JET); + bool jet = (u->getType() == UnitType::MISSILE_JET || u->getType() == UnitType::DEMO_JET); if((jet && type == AAM) && (!jet && type == AWM) && u->getPos() == order.targets[0].pos) targetPtr = u->getPos(); diff --git a/unit.cpp b/unit.cpp index ced08b9..97b1474 100755 --- a/unit.cpp +++ b/unit.cpp @@ -11,70 +11,69 @@ #include "unit.h" #include "util.h" #include "inGameAppState.h" +#include "defConfigs.h" #include "pathfinder.h" -#include "unitData.h" using namespace glm; using namespace vb01; using namespace std; namespace battleship{ - using namespace unitData; - Unit::Unit(Player *player, vb01::Vector3 pos, int id) { this->id = id; this->player = player; - this->health = unitData::health[id]; - this->maxTurnAngle = unitData::maxTurnAngle[id]; - this->range = unitData::range[id]; - this->lineOfSight = unitData::lineOfSight[id]; - this->speed = unitData::speed[id]; - type = unitData::unitType[id]; - width = unitData::unitCornerPoints[id][0].x - unitData::unitCornerPoints[id][1].x; - height = unitData::unitCornerPoints[id][4].y - unitData::unitCornerPoints[id][0].y; - length = unitData::unitCornerPoints[id][3].z - unitData::unitCornerPoints[id][0].z; + UnitDataManager *udm = UnitDataManager::getSingleton(); + health = udm->getHealth()[id]; + maxTurnAngle = udm->getMaxTurnAngle()[id]; + range = udm->getRange()[id]; + lineOfSight = udm->getLineOfSight()[id]; + speed = udm->getSpeed()[id]; + type = udm->getUnitType()[id]; + width = udm->getUnitCornerPoints()[id][0].x - udm->getUnitCornerPoints()[id][1].x; + height = udm->getUnitCornerPoints()[id][4].y - udm->getUnitCornerPoints()[id][0].y; + length = udm->getUnitCornerPoints()[id][3].z - udm->getUnitCornerPoints()[id][0].z; - GameManager *gm = GameManager::getSingleton(); - model = new Model(basePath[id] + meshPath[id]); - Root *root = Root::getSingleton(); - string libPath = root->getLibPath(); + GameManager *gm = GameManager::getSingleton(); + model = new Model(udm->getBasePath()[id] + udm->getMeshPath()[id]); + Root *root = Root::getSingleton(); + string libPath = root->getLibPath(); - Material *mat = new Material(libPath + "texture"); - string f[]{DEFAULT_TEXTURE}; + Material *mat = new Material(libPath + "texture"); + string f[]{configData::DEFAULT_TEXTURE}; Texture *diffuseTexture = new Texture(f, 1, false); - mat->addBoolUniform("texturingEnabled", true); - mat->addBoolUniform("lightingEnabled", false); - mat->addTexUniform("textures[0]", diffuseTexture, true); + mat->addBoolUniform("texturingEnabled", true); + mat->addBoolUniform("lightingEnabled", false); + mat->addTexUniform("textures[0]", diffuseTexture, true); - model->setMaterial(mat); - root->getRootNode()->attachChild(model); + model->setMaterial(mat); + root->getRootNode()->attachChild(model); placeUnit(pos); selectionSfxBuffer = new sf::SoundBuffer(); - string p = GameManager::getSingleton()->getPath() + "Sounds/" + unitData::name[id] + "s/selection.ogg"; + string p = GameManager::getSingleton()->getPath() + "Sounds/" + udm->getName()[id] + "s/selection.ogg"; if(selectionSfxBuffer->loadFromFile(p.c_str())) selectionSfx = new sf::Sound(*selectionSfxBuffer); - Node *guiNode = root->getGuiNode(); + Node *guiNode = root->getGuiNode(); - hpBackground = new Quad(Vector3(lenHpBar, 10, 0), false); - Material *hpBackgroundMat = new Material(libPath + "gui"); - hpBackgroundMat->addBoolUniform("texturingEnabled", false); - hpBackgroundMat->addVec4Uniform("diffuseColor", Vector4(0, 0, 0, 1)); - hpBackground->setMaterial(hpBackgroundMat); - hpBackgroundNode = new Node(); - hpBackgroundNode->attachMesh(hpBackground); - guiNode->attachChild(hpBackgroundNode); + hpBackground = new Quad(Vector3(lenHpBar, 10, 0), false); + Material *hpBackgroundMat = new Material(libPath + "gui"); + hpBackgroundMat->addBoolUniform("texturingEnabled", false); + hpBackgroundMat->addVec4Uniform("diffuseColor", Vector4(0, 0, 0, 1)); + hpBackground->setMaterial(hpBackgroundMat); + hpBackgroundNode = new Node(); + hpBackgroundNode->attachMesh(hpBackground); + guiNode->attachChild(hpBackgroundNode); - hpForeground = new Quad(Vector3(lenHpBar, 10, 0), false); - Material *hpForegroundMat = new Material(libPath + "gui"); - hpForegroundMat->addBoolUniform("texturingEnabled", false); - hpForegroundMat->addVec4Uniform("diffuseColor", Vector4(0, 1, 0, 1)); - hpForeground->setMaterial(hpForegroundMat); - hpForegroundNode = new Node(); - hpForegroundNode->attachMesh(hpForeground); - guiNode->attachChild(hpForegroundNode); + hpForeground = new Quad(Vector3(lenHpBar, 10, 0), false); + Material *hpForegroundMat = new Material(libPath + "gui"); + hpForegroundMat->addBoolUniform("texturingEnabled", false); + hpForegroundMat->addVec4Uniform("diffuseColor", Vector4(0, 1, 0, 1)); + hpForeground->setMaterial(hpForegroundMat); + hpForegroundNode = new Node(); + hpForegroundNode->attachMesh(hpForeground); + guiNode->attachChild(hpForegroundNode); } Unit::~Unit() { @@ -112,7 +111,7 @@ namespace battleship{ void Unit::displayUnitStats() { float shiftedX = screenPos.x - 0.5 * lenHpBar; hpForegroundNode->setPosition(Vector3(shiftedX, screenPos.y, 0)); - hpForeground->setSize(Vector3(health / unitData::health[id] * lenHpBar, 10, 0)); + hpForeground->setSize(Vector3(health / UnitDataManager::getSingleton()->getHealth()[id] * lenHpBar, 10, 0)); hpBackgroundNode->setPosition(Vector3(shiftedX, screenPos.y, .1)); } @@ -125,7 +124,7 @@ namespace battleship{ attack(order); break; case Order::TYPE::MOVE: - move(order, unitData::destinationOffset[id]); + move(order, UnitDataManager::getSingleton()->getDestinationOffset()[id]); break; case Order::TYPE::PATROL: patrol(order); @@ -166,6 +165,7 @@ namespace battleship{ } bool withinCircle = center.getDistanceFrom(dest) < radius ? true : false; + float anglePrecision = UnitDataManager::getSingleton()->getAnglePrecision()[id]; if (moveDir != MoveDir::FORWARD) { if (withinCircle) @@ -175,14 +175,14 @@ namespace battleship{ angle = isnan(angle) ? 0. : angle; - if (angle > anglePrecision[id]) { + if (angle > anglePrecision) { float rotAngle = maxTurnAngle > angle ? angle : maxTurnAngle; angle -= rotAngle; turn(moveDir == MoveDir::RIGHT ? -rotAngle : rotAngle); } } - if (angle > anglePrecision[id]) + if (angle > anglePrecision) movementAmmount = speed; else { if (withinCircle) { @@ -209,7 +209,7 @@ namespace battleship{ } void Unit::patrol(Order order) { - move(order, unitData::destinationOffset[id]); + move(order, UnitDataManager::getSingleton()->getDestinationOffset()[id]); } void Unit::launch(Order order) {} @@ -261,7 +261,7 @@ namespace battleship{ } Vector3 Unit::getCorner(int i) { - Vector3 corner = unitCornerPoints[id][i]; + Vector3 corner = UnitDataManager::getSingleton()->getUnitCornerPoints()[id][i]; return pos + (leftVec * corner.x + upVec * corner.y - dirVec * corner.z); } diff --git a/unit.h b/unit.h index f95e7b4..72699c1 100755 --- a/unit.h +++ b/unit.h @@ -9,7 +9,7 @@ #include -#include "unitData.h" +#include "unitDataManager.h" #include "gameManager.h" #include "projectile.h" @@ -60,7 +60,7 @@ namespace battleship{ void orientUnit(vb01::Vector3); void addProjectile(Projectile*); float getCircleRadius(); - vb01::Vector3 getCorner(int); + vb01::Vector3 getCorner(int); std::vector getProjectiles(); void addOrder(Order); inline bool isSelected(){return selected;} @@ -76,7 +76,7 @@ namespace battleship{ inline float getLength() {return length;} inline vb01::Model* getNode() {return model;} inline Player* getPlayer(){return player;} - inline unitData::UNIT_TYPE getType() {return type;} + inline UnitType getType() {return type;} inline void toggleDebugging(bool d){this->debugging=d;} inline void takeDamage(int damage) {health -= damage;} inline int getId() {return id;} @@ -100,14 +100,14 @@ namespace battleship{ protected: Player *player; MoveDir moveDir = MoveDir::FORWARD; - unitData::UNIT_TYPE type; - vb01::Vector2 screenPos; + UnitType type; + vb01::Vector2 screenPos; std::vector orders; - vb01::Vector3 pos = vb01::Vector3(0, 0, 0), upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, -1), leftVec = vb01::Vector3(1, 0, 0); - vb01::Quaternion rot = vb01::Quaternion::QUAT_W; + vb01::Vector3 pos = vb01::Vector3(0, 0, 0), upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, -1), leftVec = vb01::Vector3(1, 0, 0); + vb01::Quaternion rot = vb01::Quaternion::QUAT_W; int health, cost, id, patrolPointId = 0, playerId; s64 orderLineDispTime = 0; - vb01::Model *model; + vb01::Model *model; bool selected = false, selectable, debugging = false, working = true; float lineOfSight, speed, maxTurnAngle, range, width, height, length; diff --git a/unitDataManager.h b/unitDataManager.h index 90265da..992714d 100644 --- a/unitDataManager.h +++ b/unitDataManager.h @@ -6,32 +6,43 @@ #include namespace battleship{ - class UnitDataManager{ - public: - static UnitDataManager* getSingleton(); - inline int getNumUnits(){return numUnits;} - inline std::string* getBasePath(){return basePath;} - inline std::string* getMeshPath(){return meshPath;} - private: - UnitDataManager(); + enum class UnitType {VESSEL, DESTROYER, CRUISER, AIRCRAFT_CARRIER, SUBMARINE, MISSILE_JET, DEMO_JET}; - enum class UnitType {VESSEL, DESTROYER, CRUISER, AIRCRAFT_CARRIER, SUBMARINE, MISSILE_JET, DEMO_JET}; - int numUnits; - UnitType unitType; - int *health; - float *speed; - float *destinationOffset; - float *anglePrecision; - int *cost; - float *maxTurnAngle; - float *range; - vb01::Vector3 **unitCornerPoints; - vb01::Vector3 **unitCuboidDimensions; - float *unitAxisLength; - float *lineOfSight; - std::string *name; - std::string *meshPath; - std::string *basePath; + class UnitDataManager{ + public: + static UnitDataManager* getSingleton(); + inline int getNumUnits(){return numUnits;} + inline int* getHealth(){return health;} + inline UnitType* getUnitType(){return unitType;} + inline float* getMaxTurnAngle(){return maxTurnAngle;} + inline float* getRange(){return range;} + inline float* getLineOfSight(){return lineOfSight;} + inline float* getSpeed(){return speed;} + inline float* getAnglePrecision(){return anglePrecision;} + inline float* getDestinationOffset(){return destinationOffset;} + inline vb01::Vector3** getUnitCornerPoints(){return unitCornerPoints;} + inline std::string* getName(){return name;} + inline std::string* getBasePath(){return basePath;} + inline std::string* getMeshPath(){return meshPath;} + private: + UnitDataManager(); + + int numUnits; + UnitType *unitType; + int *health; + float *speed; + float *destinationOffset; + float *anglePrecision; + int *cost; + float *maxTurnAngle; + float *range; + vb01::Vector3 **unitCornerPoints; + vb01::Vector3 **unitCuboidDimensions; + float *unitAxisLength; + float *lineOfSight; + std::string *name; + std::string *meshPath; + std::string *basePath; }; } diff --git a/util.cpp b/util.cpp index 702bdc8..31802f0 100755 --- a/util.cpp +++ b/util.cpp @@ -14,6 +14,7 @@ #include #include "util.h" +#include "defConfigs.h" #include "gameManager.h" #include "guiAppState.h" #include "inGameAppState.h"