diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index 35505b0..caee678 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -494,6 +494,8 @@ units = { size = {x = 1, y = 1.15, z = 2}, hitboxOffset = {x = 0, y = 0, z = 0}, lineOfSight = 5, + generationRate = 10000, + generationSpeed = 10, name = 'Lab', basePath = PATH .. structurePrefix .. 'Labs/', meshPath = 'lab.xml', diff --git a/CMakeLists.txt b/CMakeLists.txt index 30c1077..0434627 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 cruiseMissile.cpp) set(FX fx.cpp) set(VEHICLES vehicle.cpp engineer.cpp resourceRover.cpp) -set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.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 pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES} ${FX}) set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL}) diff --git a/gameObjectFactory.cpp b/gameObjectFactory.cpp index 83fbc5f..dd39abc 100644 --- a/gameObjectFactory.cpp +++ b/gameObjectFactory.cpp @@ -8,6 +8,7 @@ #include "pointDefense.h" #include "extractor.h" #include "cruiseMissile.h" +#include "researchStruct.h" #include "defConfigs.h" #include @@ -32,8 +33,9 @@ namespace battleship{ return new PointDefense(player, id, pos, rot, buildStatus, Unit::State::STAND_GROUND); case UnitClass::EXTRACTOR: return new Extractor(player, id, pos, rot, buildStatus); - case UnitClass::MARKET: case UnitClass::LAB: + return new ResearchStruct(player, id, pos, rot, buildStatus); + case UnitClass::MARKET: case UnitClass::REFINERY: return new Structure(player, id, pos, rot, buildStatus, Unit::State::STAND_GROUND); case UnitClass::ENGINEER: diff --git a/player.h b/player.h index a5af80b..639f3e9 100755 --- a/player.h +++ b/player.h @@ -48,12 +48,15 @@ namespace battleship{ inline int getRefineds(){return refineds;} inline void setRefineds(int ref){this->refineds = ref;} inline void addRefineds(int ref){this->refineds += ref;} + inline void subtractRefineds(int ref){this->refineds -= ref;} inline int getWealth(){return wealth;} inline void setWealth(int w){this->wealth = w;} inline void addWealth(int w){this->wealth += w;} + inline void subtractWealth(int w){this->wealth -= w;} inline int getResearch(){return research;} inline void setResearch(int r){this->research = r;} inline void addResearch(int r){this->research += r;} + inline void subtractResearch(int r){this->research -= r;} inline bool isCpuPlayer(){return cpuPlayer;} inline int getNumVehiclesBuilt(){return vehiclesBuilt;} inline int getNumVehiclesDestroyed(){return vehiclesDestroyed;} diff --git a/researchStruct.cpp b/researchStruct.cpp new file mode 100644 index 0000000..9e6a241 --- /dev/null +++ b/researchStruct.cpp @@ -0,0 +1,28 @@ +#include "researchStruct.h" +#include "player.h" + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace gameBase; + + ResearchStruct::ResearchStruct(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, Unit::State state) : Structure(player, id, pos, rot, buildStatus, state){ + sol::table unitTable = generateView()["units"][id + 1]; + generationRate = unitTable["generationRate"]; + generationSpeed = unitTable["generationSpeed"]; + } + + void ResearchStruct::update(){ + Structure::update(); + int cost = 1; + + if(player->getRefineds() >= cost && canGenerateResearch()){ + player->addResearch(generationSpeed); + player->subtractRefineds(cost); + lastGenTime = getTime(); + } + } + + void ResearchStruct::researchTechnology(int techId){ + } +} diff --git a/researchStruct.h b/researchStruct.h new file mode 100644 index 0000000..66b4444 --- /dev/null +++ b/researchStruct.h @@ -0,0 +1,21 @@ +#ifndef RESEARCH_STRUCT_H +#define RESEARCH_STRUCT_H + +#include "structure.h" + +namespace battleship{ + class ResearchStruct : public Structure{ + public: + ResearchStruct(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0, Unit::State = Unit::State::STAND_GROUND); + void update(); + private: + vb01::s64 lastGenTime = 0; + int generationRate, generationSpeed; + + bool canGenerateResearch(){return vb01::getTime() - lastGenTime > generationRate;} + void generateResearch(); + void researchTechnology(int); + }; +} + +#endif