diff --git a/CMakeLists.txt b/CMakeLists.txt index 319783b..e736351 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp) set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp toggleDebugCommand.cpp) set(CORE gameManager.cpp game.cpp fxManager.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS}) set(PROJECTILES projectile.cpp missile.cpp cruiseMissile.cpp shell.cpp) -set(VEHICLES vehicle.cpp engineer.cpp resourceRover.cpp) +set(VEHICLES vehicle.cpp submarine.cpp engineer.cpp resourceRover.cpp) set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp researchStruct.cpp) set(UNITS gameObjectFactory.cpp unit.cpp ${STRUCTURES} ${VEHICLES}) set(CONTENT player.cpp trader.cpp pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES}) diff --git a/gameObjectFactory.cpp b/gameObjectFactory.cpp index 19096ad..2e4193c 100644 --- a/gameObjectFactory.cpp +++ b/gameObjectFactory.cpp @@ -2,6 +2,7 @@ #include "player.h" #include "factory.h" #include "engineer.h" +#include "submarine.h" #include "resourceRover.h" #include "projectile.h" #include "resourceDeposit.h" @@ -44,6 +45,8 @@ namespace battleship{ return new Engineer(player, id, pos, rot, Unit::State::STAND_GROUND); case UnitClass::RESOURCE_ROVER: return new ResourceRover(player, id, pos, rot, Unit::State::STAND_GROUND); + case UnitClass::SUBMARINE: + return new Submarine(player, id, pos, rot, Unit::State::STAND_GROUND); default: return new Vehicle(player, id, pos, rot, Unit::State::STAND_GROUND); } diff --git a/submarine.cpp b/submarine.cpp new file mode 100644 index 0000000..2fc1110 --- /dev/null +++ b/submarine.cpp @@ -0,0 +1,27 @@ +#include "submarine.h" +#include "map.h" + +#include + +namespace battleship{ + using namespace vb01; + using namespace std; + + Submarine::Submarine(Player *player, int id, Vector3 pos, Quaternion rot, Unit::State state) : Vehicle(player, id, pos, rot, state){} + + bool Submarine::validateLaunchOrder(){ + if(!Unit::validateLaunchOrder()) return false; + + vector terrainNodes = Map::getSingleton()->getNodeParent()->getChildren(); + + for(int i = 1; i < terrainNodes.size(); i++){ + Vector3 wbPos = terrainNodes[i]->getPosition(); + Vector3 size = ((Quad*)terrainNodes[i]->getMesh(0))->getSize(); + + if(fabs(wbPos.x - pos.x) < .5 * size.x && fabs(wbPos.z - pos.z) < .5 * size.y && pos.y - wbPos.y > -.1) + return true; + } + + return false; + } +} diff --git a/submarine.h b/submarine.h new file mode 100644 index 0000000..4e1d914 --- /dev/null +++ b/submarine.h @@ -0,0 +1,15 @@ +#ifndef SUBMARINE_H +#define SUBMARINE_H + +#include "vehicle.h" + +namespace battleship{ + class Submarine : public Vehicle{ + public: + Submarine(Player*, int, vb01::Vector3, vb01::Quaternion, Unit::State); + private: + bool validateLaunchOrder(); + }; +} + +#endif diff --git a/unit.cpp b/unit.cpp index 604391d..4fb36a3 100755 --- a/unit.cpp +++ b/unit.cpp @@ -769,7 +769,7 @@ namespace battleship{ case Order::TYPE::EJECT: return !garrisonSlots.empty(); case Order::TYPE::LAUNCH: - return !getWeaponsByOrder(Order::TYPE::LAUNCH).empty(); + return validateLaunchOrder(); case Order::TYPE::SUPPLY: case Order::TYPE::LOAD: case Order::TYPE::UNLOAD: diff --git a/unit.h b/unit.h index 5ba9379..59832c9 100755 --- a/unit.h +++ b/unit.h @@ -198,6 +198,7 @@ namespace battleship{ std::vector getSelectingPlayers(); void removeOrder(int); + virtual bool validateLaunchOrder(){return !getWeaponsByOrder(Order::TYPE::LAUNCH).empty();} virtual bool validateGarrisonOrder(Order){return false;} virtual void targetUnitsAutomatically(); virtual void reinit();