mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
research status bar
This commit is contained in:
@@ -134,7 +134,7 @@ units = {
|
|||||||
{id = UnitId.MARKET, buildable = true},
|
{id = UnitId.MARKET, buildable = true},
|
||||||
{id = UnitId.LAB, buildable = true},
|
{id = UnitId.LAB, buildable = true},
|
||||||
{id = UnitId.POINT_DEFENSE, buildable = true},
|
{id = UnitId.POINT_DEFENSE, buildable = true},
|
||||||
{id = UnitId.FORT, buildable = true},
|
{id = UnitId.FORT, buildable = false},
|
||||||
},
|
},
|
||||||
unitClass = UnitClass.ENGINEER,
|
unitClass = UnitClass.ENGINEER,
|
||||||
unitType = UnitType.HOVER,
|
unitType = UnitType.HOVER,
|
||||||
@@ -526,7 +526,7 @@ units = {
|
|||||||
size = {x = 1, y = 1.15, z = 2},
|
size = {x = 1, y = 1.15, z = 2},
|
||||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||||
lineOfSight = 5,
|
lineOfSight = 5,
|
||||||
generationRate = 10000,
|
generationRate = 100,
|
||||||
generationSpeed = 10,
|
generationSpeed = 10,
|
||||||
researchCost = 1,
|
researchCost = 1,
|
||||||
name = 'Lab',
|
name = 'Lab',
|
||||||
|
|||||||
+30
-5
@@ -1,7 +1,10 @@
|
|||||||
#include "researchStruct.h"
|
#include "researchStruct.h"
|
||||||
|
#include "activeGameState.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
#include "game.h"
|
#include "game.h"
|
||||||
|
|
||||||
|
#include <stateManager.h>
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace vb01;
|
using namespace vb01;
|
||||||
@@ -12,6 +15,15 @@ namespace battleship{
|
|||||||
generationRate = unitTable["generationRate"];
|
generationRate = unitTable["generationRate"];
|
||||||
generationSpeed = unitTable["generationSpeed"];
|
generationSpeed = unitTable["generationSpeed"];
|
||||||
researchCost = unitTable["researchCost"];
|
researchCost = unitTable["researchCost"];
|
||||||
|
|
||||||
|
Vector2 size = Vector2(lenHpBar, 10);
|
||||||
|
researchStatusBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
|
||||||
|
researchStatusForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(1, 0, 1, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
ResearchStruct::~ResearchStruct(){
|
||||||
|
removeBar(researchStatusBackground);
|
||||||
|
removeBar(researchStatusForeground);
|
||||||
}
|
}
|
||||||
|
|
||||||
void ResearchStruct::update(){
|
void ResearchStruct::update(){
|
||||||
@@ -19,17 +31,30 @@ namespace battleship{
|
|||||||
|
|
||||||
if(!isComplete()) return;
|
if(!isComplete()) return;
|
||||||
|
|
||||||
if(researchQueue.empty() && health > .3 * maxHealth && player->getRefineds() >= researchCost && canUpdateResearch()){
|
ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE);
|
||||||
player->addResearch(generationSpeed);
|
Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr);
|
||||||
player->subtractRefineds(researchCost);
|
|
||||||
lastUpdateTime = getTime();
|
vector<Player*> selectingPlayers = Unit::getSelectingPlayers();
|
||||||
|
bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end());
|
||||||
|
|
||||||
|
if(researchQueue.empty()){
|
||||||
|
if(health > .3 * maxHealth && player->getRefineds() >= researchCost && canUpdateResearch()){
|
||||||
|
player->addResearch(generationSpeed);
|
||||||
|
player->subtractRefineds(researchCost);
|
||||||
|
lastUpdateTime = getTime();
|
||||||
|
}
|
||||||
|
|
||||||
|
researchStatusBackground->setVisible(false);
|
||||||
|
researchStatusForeground->setVisible(false);
|
||||||
}
|
}
|
||||||
else if(!researchQueue.empty()){
|
else if(!researchQueue.empty()){
|
||||||
|
Unit::displayUnitStats(researchStatusForeground, researchStatusBackground, researchStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10));
|
||||||
|
|
||||||
int techCost = Game::getSingleton()->getTechnology(researchQueue[0]).cost;
|
int techCost = Game::getSingleton()->getTechnology(researchQueue[0]).cost;
|
||||||
int playerResearch = player->getResearch();
|
int playerResearch = player->getResearch();
|
||||||
|
|
||||||
if(techCost > playerResearch && canUpdateResearch()){
|
if(techCost > playerResearch && canUpdateResearch()){
|
||||||
researchStatus += (int)((float)playerResearch / techCost);
|
researchStatus += int(100 * ((float)playerResearch / techCost));
|
||||||
lastUpdateTime = getTime();
|
lastUpdateTime = getTime();
|
||||||
}
|
}
|
||||||
else if(researchStatus >= 100 || techCost <= playerResearch){
|
else if(researchStatus >= 100 || techCost <= playerResearch){
|
||||||
|
|||||||
@@ -3,16 +3,22 @@
|
|||||||
|
|
||||||
#include "structure.h"
|
#include "structure.h"
|
||||||
|
|
||||||
|
namespace vb01{
|
||||||
|
class Node;
|
||||||
|
}
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
class ResearchStruct : public Structure{
|
class ResearchStruct : public Structure{
|
||||||
public:
|
public:
|
||||||
ResearchStruct(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0, Unit::State = Unit::State::STAND_GROUND);
|
ResearchStruct(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0, Unit::State = Unit::State::STAND_GROUND);
|
||||||
|
~ResearchStruct();
|
||||||
void update();
|
void update();
|
||||||
inline void appendToQueue(int tid){researchQueue.push_back(tid);}
|
inline void appendToQueue(int tid){researchQueue.push_back(tid);}
|
||||||
private:
|
private:
|
||||||
vb01::s64 lastUpdateTime = 0;
|
vb01::s64 lastUpdateTime = 0;
|
||||||
int researchCost, generationRate, generationSpeed, researchStatus = 0;
|
int researchCost, generationRate, generationSpeed, researchStatus = 0;
|
||||||
std::vector<int> researchQueue;
|
std::vector<int> researchQueue;
|
||||||
|
vb01::Node *researchStatusForeground = nullptr, *researchStatusBackground = nullptr;
|
||||||
|
|
||||||
bool canUpdateResearch(){return vb01::getTime() - lastUpdateTime > generationRate;}
|
bool canUpdateResearch(){return vb01::getTime() - lastUpdateTime > generationRate;}
|
||||||
void generateResearch();
|
void generateResearch();
|
||||||
|
|||||||
Reference in New Issue
Block a user