diff --git a/CMakeLists.txt b/CMakeLists.txt index 4443f17..49156cb 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -32,7 +32,7 @@ set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceComman set(CORE gameManager.cpp game.cpp environment.cpp fxManager.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS}) set(PROJECTILES projectile.cpp missile.cpp cruiseMissile.cpp shell.cpp) -set(VEHICLES vehicle.cpp submarine.cpp engineer.cpp resourceRover.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}) diff --git a/freezer.cpp b/freezer.cpp new file mode 100644 index 0000000..f0f81d0 --- /dev/null +++ b/freezer.cpp @@ -0,0 +1,17 @@ +#include "freezer.h" + +namespace battleship{ + using namespace vb01; + + //TODO rename the class to a more generic name + Freezer::Freezer(Player *player, int id, Vector3 pos, Quaternion rot, Unit::State state) : Vehicle(player, id, pos, rot, state){} + + void Freezer::attack(Order order){ + Vehicle::attack(order); + + Unit *target = order.targets[0].unit; + + if(target && target->getFreezeStatus() == 100) + removeOrder(0); + } +} diff --git a/freezer.h b/freezer.h new file mode 100644 index 0000000..49a3ffb --- /dev/null +++ b/freezer.h @@ -0,0 +1,15 @@ +#ifndef FREEZER_H +#define FREEZER_H + +#include "vehicle.h" + +namespace battleship{ + class Freezer : public Vehicle{ + public: + Freezer(Player*, int, vb01::Vector3, vb01::Quaternion, Unit::State); + private: + void attack(Order); + }; +} + +#endif diff --git a/gameObjectFactory.cpp b/gameObjectFactory.cpp index 5a07ddc..f4550ee 100644 --- a/gameObjectFactory.cpp +++ b/gameObjectFactory.cpp @@ -8,6 +8,7 @@ #include "resourceDeposit.h" #include "pointDefense.h" #include "extractor.h" +#include "freezer.h" #include "researchStruct.h" #include "missile.h" #include "cruiseMissile.h" @@ -37,6 +38,8 @@ namespace battleship{ 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); + case UnitClass::FREEZER: + return new Freezer(player, id, pos, rot, Unit::State::STAND_GROUND); default: return new Vehicle(player, id, pos, rot, Unit::State::STAND_GROUND); } diff --git a/unit.cpp b/unit.cpp index 7d9f176..36730eb 100755 --- a/unit.cpp +++ b/unit.cpp @@ -152,7 +152,7 @@ namespace battleship{ if(wtOpt != sol::nullopt) wt = unitTable[tblName][i + 1]["type"]; - Weapon *weapon = ((Weapon::Type)wt == Weapon::Type::FREEZER ? new Freezer(this, unitTable, i) : new Weapon(this, unitTable, i)); + Weapon *weapon = ((Weapon::Type)wt == Weapon::Type::FREEZER ? new CryoGun(this, unitTable, i) : new Weapon(this, unitTable, i)); weapons.push_back(weapon); } } diff --git a/vehicle.h b/vehicle.h index 04e2ee7..9bbb184 100644 --- a/vehicle.h +++ b/vehicle.h @@ -46,7 +46,7 @@ namespace battleship{ void navigateToTarget(float); void preparePathpoints(Order&, vb01::Vector3, bool = false); void alignToSurface(); - void attack(Order); + virtual void attack(Order); void garrison(Order); void patrol(Order); virtual void initProperties(); diff --git a/weapon.cpp b/weapon.cpp index 0723bd7..ea6d31c 100644 --- a/weapon.cpp +++ b/weapon.cpp @@ -234,9 +234,9 @@ namespace battleship{ //if(vertNode) alignNode(targPos, vertNode, false); } - Freezer::Freezer(Unit *u, sol::table unitTable, int wid) : Weapon(u, unitTable, wid){} + CryoGun::CryoGun(Unit *u, sol::table unitTable, int wid) : Weapon(u, unitTable, wid){} - void Freezer::updateTargetUnit(Unit *targetUnit){ + void CryoGun::updateTargetUnit(Unit *targetUnit){ if(canFreeze()){ targetUnit->setFreezeStatus(targetUnit->getFreezeStatus() + 1); lastFreezeTime = getTime(); diff --git a/weapon.h b/weapon.h index d60ebf4..e734b76 100644 --- a/weapon.h +++ b/weapon.h @@ -54,12 +54,12 @@ namespace battleship{ protected: int rateOfFire; - void updateTargetUnit(Unit*); + virtual void updateTargetUnit(Unit*); }; - class Freezer : public Weapon{ + class CryoGun : public Weapon{ public: - Freezer(Unit*, sol::table, int); + CryoGun(Unit*, sol::table, int); private: vb01::s64 lastFreezeTime = 0;