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