mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
added bars for extractors/deposits and cargo ships
This commit is contained in:
@@ -28,7 +28,7 @@ structurePrefix = modelPrefix .. "Units/Structures/"
|
|||||||
|
|
||||||
units = {
|
units = {
|
||||||
weapons = {
|
weapons = {
|
||||||
{{type = WeaponClass.HITSCAN, rateOfFire = 100, fireSfx = PATH .. 'Sounds/Units/WarMechs/fire.ogg', damage = 50, maxRange = 3}},
|
{{type = WeaponClass.HITSCAN, rateOfFire = 100, fireSfx = PATH .. 'Sounds/Units/WarMechs/fire.ogg', damage = 50, maxRange = 10}},
|
||||||
{{type = WeaponClass.HITSCAN, rateOfFire = 500, fireSfx = PATH .. 'Sounds/Units/Tanks/attack.ogg', damage = 200, maxRange = 20}},
|
{{type = WeaponClass.HITSCAN, rateOfFire = 500, fireSfx = PATH .. 'Sounds/Units/Tanks/attack.ogg', damage = 200, maxRange = 20}},
|
||||||
{{type = WeaponClass.HITSCAN, rateOfFire = 2000, fireSfx = PATH .. 'Sounds/Units/Tanks/attack.ogg', damage = 5000, maxRange = 45}},
|
{{type = WeaponClass.HITSCAN, rateOfFire = 2000, fireSfx = PATH .. 'Sounds/Units/Tanks/attack.ogg', damage = 5000, maxRange = 45}},
|
||||||
{},
|
{},
|
||||||
@@ -373,14 +373,14 @@ units = {
|
|||||||
{x = .5, y =.15, z =.7}
|
{x = .5, y =.15, z =.7}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{x = .5, y =-.1, z =-1.3},
|
{x = 2, y =-.1, z =-2},
|
||||||
{x = -.5, y =-.1, z =-1.3},
|
{x = -2, y =-.1, z =-2},
|
||||||
{x = -.5, y =-.1, z =.7},
|
{x = -2, y =-.1, z =2},
|
||||||
{x = .5, y =-.1, z =.7},
|
{x = 2, y =-.1, z =2},
|
||||||
{x = .5, y =.15, z =-1.3},
|
{x = 2, y =.15, z =-2},
|
||||||
{x = -.5, y =.15, z =-1.3},
|
{x = -2, y =.15, z =-2},
|
||||||
{x = -.5, y =.15, z =.7},
|
{x = -2, y =.15, z =2},
|
||||||
{x = .5, y =.15, z =.7}
|
{x = 2, y =.15, z =2}
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
{x = .5, y =-.1, z =-1.3},
|
{x = .5, y =-.1, z =-1.3},
|
||||||
|
|||||||
@@ -10,14 +10,14 @@ resources = {
|
|||||||
},
|
},
|
||||||
unitCornerPoints = {
|
unitCornerPoints = {
|
||||||
{
|
{
|
||||||
{x = 1, y = .571, z = -1},
|
{x = 0, y = 0, z = 0},
|
||||||
{x = -1, y = .571, z = -1},
|
{x = 0, y = 0, z = 0},
|
||||||
{x = -1, y = .571, z = 1},
|
{x = 0, y = 0, z = 0},
|
||||||
{x = 1, y = .571, z = 1},
|
{x = 0, y = 0, z = 0},
|
||||||
{x = 1, y = .571, z = -1},
|
{x = 0, y = 0, z = 0},
|
||||||
{x = -1, y = .571, z = -1},
|
{x = 0, y = 0, z = 0},
|
||||||
{x = -1, y = .571, z = 1},
|
{x = 0, y = 0, z = 0},
|
||||||
{x = 1, y = .571, z = 1}
|
{x = 0, y = 0, z = 0},
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
hitboxOffset = {{x = 0, y = 0, z = 0}}
|
hitboxOffset = {{x = 0, y = 0, z = 0}}
|
||||||
|
|||||||
+59
-1
@@ -1,8 +1,66 @@
|
|||||||
#include "extractor.h"
|
#include "extractor.h"
|
||||||
|
#include "player.h"
|
||||||
|
#include "game.h"
|
||||||
|
#include "activeGameState.h"
|
||||||
|
#include "resourceDeposit.h"
|
||||||
|
|
||||||
|
#include <stateManager.h>
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
using namespace std;
|
using namespace std;
|
||||||
using namespace vb01;
|
using namespace vb01;
|
||||||
|
using namespace gameBase;
|
||||||
|
|
||||||
Extractor::Extractor(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus) : Structure(player, id, pos, rot, buildStatus){}
|
Extractor::Extractor(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, ResourceDeposit *rd) : Structure(player, id, pos, rot, buildStatus){
|
||||||
|
if(!rd){
|
||||||
|
vector<ResourceDeposit*> deposits;
|
||||||
|
|
||||||
|
for(Player *pl : Game::getSingleton()->getPlayers()){
|
||||||
|
vector<ResourceDeposit*> dep = pl->getResourceDeposits();
|
||||||
|
deposits.insert(deposits.end(), dep.begin(), dep.end());
|
||||||
|
}
|
||||||
|
|
||||||
|
for(ResourceDeposit *dep : deposits)
|
||||||
|
if(dep->getPos().getDistanceFrom(pos) < .001){
|
||||||
|
deposit = dep;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
Vector2 size = Vector2(lenHpBar, 10);
|
||||||
|
ammountBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
|
||||||
|
ammountForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 1, 1));
|
||||||
|
}
|
||||||
|
|
||||||
|
Extractor::~Extractor(){
|
||||||
|
removeBar(ammountForeground);
|
||||||
|
removeBar(ammountBackground);
|
||||||
|
}
|
||||||
|
|
||||||
|
void Extractor::update(){
|
||||||
|
Structure::update();
|
||||||
|
|
||||||
|
ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE);
|
||||||
|
Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr);
|
||||||
|
|
||||||
|
vector<Player*> selectingPlayers = getSelectingPlayers();
|
||||||
|
bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end());
|
||||||
|
int ammount = 0, initAmmount = 0;
|
||||||
|
|
||||||
|
if(deposit){
|
||||||
|
ammount = deposit->getAmmount();
|
||||||
|
initAmmount = deposit->getInitAmmount();
|
||||||
|
}
|
||||||
|
|
||||||
|
Unit::displayUnitStats(ammountForeground, ammountBackground, ammount, initAmmount, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10));
|
||||||
|
}
|
||||||
|
|
||||||
|
void Extractor::draw(){
|
||||||
|
if(canDraw()){
|
||||||
|
deposit->decrementAmmount();
|
||||||
|
lastDrawTime = getTime();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
bool Extractor::canDraw(){return vb01::getTime() - lastDrawTime > drawRate && deposit->getAmmount() > 0;}
|
||||||
}
|
}
|
||||||
|
|||||||
+10
-1
@@ -6,12 +6,21 @@
|
|||||||
#include <util.h>
|
#include <util.h>
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
|
class ResourceDeposit;
|
||||||
|
|
||||||
class Extractor : public Structure{
|
class Extractor : public Structure{
|
||||||
public:
|
public:
|
||||||
Extractor(Player*, int, vb01::Vector3, vb01::Quaternion, int);
|
Extractor(Player*, int, vb01::Vector3, vb01::Quaternion, int, ResourceDeposit *rd = nullptr);
|
||||||
|
~Extractor();
|
||||||
|
void update();
|
||||||
|
void draw();
|
||||||
private:
|
private:
|
||||||
int drawRate;
|
int drawRate;
|
||||||
vb01::s64 lastDrawTime = 0;
|
vb01::s64 lastDrawTime = 0;
|
||||||
|
vb01::Node *ammountBackground = nullptr, *ammountForeground = nullptr;
|
||||||
|
ResourceDeposit *deposit = nullptr;
|
||||||
|
|
||||||
|
bool canDraw();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -63,7 +63,7 @@ namespace battleship{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceDeposit* GameObjectFactory::createResourceDeposit(Player *player, int id, Vector3 pos, Quaternion rot){
|
ResourceDeposit* GameObjectFactory::createResourceDeposit(Player *player, int id, Vector3 pos, Quaternion rot, int initAmmount){
|
||||||
return new ResourceDeposit(player, id, pos, rot);
|
return new ResourceDeposit(player, id, pos, rot, initAmmount);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+1
-1
@@ -15,7 +15,7 @@ namespace battleship{
|
|||||||
enum GameObjectType{UNIT, PROJECTILE, RESOURCE_DEPOSIT};
|
enum GameObjectType{UNIT, PROJECTILE, RESOURCE_DEPOSIT};
|
||||||
static Unit* createUnit(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0);
|
static Unit* createUnit(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0);
|
||||||
static Projectile* createProjectile(Unit*, int, vb01::Vector3, vb01::Quaternion);
|
static Projectile* createProjectile(Unit*, int, vb01::Vector3, vb01::Quaternion);
|
||||||
static ResourceDeposit* createResourceDeposit(Player*, int, vb01::Vector3, vb01::Quaternion);
|
static ResourceDeposit* createResourceDeposit(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0);
|
||||||
private:
|
private:
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -172,8 +172,9 @@ namespace battleship{
|
|||||||
|
|
||||||
sol::table rotTable = npcObjTable["rot"];
|
sol::table rotTable = npcObjTable["rot"];
|
||||||
Quaternion rot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]);
|
Quaternion rot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]);
|
||||||
|
int initAmmount = SOL_LUA_VIEW[mapTable][playerInd][i + 1][resDepInd][j + 1]["initAmmount"];
|
||||||
|
|
||||||
player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, id, pos, rot));
|
player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, id, pos, rot, initAmmount));
|
||||||
}
|
}
|
||||||
|
|
||||||
//int spawnPointId = SOL_LUA_STATE[mapTable]["spawnPointInd"][i + 1][spawnPointId];
|
//int spawnPointId = SOL_LUA_STATE[mapTable]["spawnPointInd"][i + 1][spawnPointId];
|
||||||
|
|||||||
+5
-1
@@ -3,7 +3,11 @@
|
|||||||
namespace battleship{
|
namespace battleship{
|
||||||
using namespace vb01;
|
using namespace vb01;
|
||||||
|
|
||||||
ResourceDeposit::ResourceDeposit(Player *player, int id, Vector3 pos, Quaternion rot) : GameObject(GameObject::Type::RESOURCE_DEPOSIT, id, player, pos, rot){
|
ResourceDeposit::ResourceDeposit(Player *player, int id, Vector3 pos, Quaternion rot, int ia) :
|
||||||
|
GameObject(GameObject::Type::RESOURCE_DEPOSIT, id, player, pos, rot),
|
||||||
|
initAmmount(ia),
|
||||||
|
ammount(ia)
|
||||||
|
{
|
||||||
initProperties();
|
initProperties();
|
||||||
initModel();
|
initModel();
|
||||||
initHitbox();
|
initHitbox();
|
||||||
|
|||||||
+5
-1
@@ -6,9 +6,13 @@
|
|||||||
namespace battleship{
|
namespace battleship{
|
||||||
class ResourceDeposit : public GameObject{
|
class ResourceDeposit : public GameObject{
|
||||||
public:
|
public:
|
||||||
ResourceDeposit(Player*, int, vb01::Vector3, vb01::Quaternion);
|
ResourceDeposit(Player*, int, vb01::Vector3, vb01::Quaternion, int);
|
||||||
~ResourceDeposit();
|
~ResourceDeposit();
|
||||||
|
inline int getAmmount(){return ammount;}
|
||||||
|
inline int getInitAmmount(){return initAmmount;}
|
||||||
|
inline void decrementAmmount(){ammount--;}
|
||||||
private:
|
private:
|
||||||
|
int ammount, initAmmount;
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
+22
-10
@@ -1,6 +1,8 @@
|
|||||||
#include "resourceRover.h"
|
#include "resourceRover.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "player.h"
|
#include "player.h"
|
||||||
|
#include "extractor.h"
|
||||||
|
#include "structure.h"
|
||||||
#include "activeGameState.h"
|
#include "activeGameState.h"
|
||||||
|
|
||||||
#include <stateManager.h>
|
#include <stateManager.h>
|
||||||
@@ -17,7 +19,7 @@ namespace battleship{
|
|||||||
{
|
{
|
||||||
Vector2 size = Vector2(lenHpBar, 10);
|
Vector2 size = Vector2(lenHpBar, 10);
|
||||||
loadBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
|
loadBackground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
|
||||||
loadForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(0, 1, 1, 1));
|
loadForeground = Unit::createBar(Vector2::VEC_ZERO, size, Vector4(1, 1, 0, 1));
|
||||||
}
|
}
|
||||||
|
|
||||||
ResourceRover::~ResourceRover(){
|
ResourceRover::~ResourceRover(){
|
||||||
@@ -31,13 +33,14 @@ namespace battleship{
|
|||||||
if(!pathPoints.empty())
|
if(!pathPoints.empty())
|
||||||
navigate(minDist);
|
navigate(minDist);
|
||||||
else{
|
else{
|
||||||
vector<Unit*> units = player->getUnits(), extractors, refineries;
|
vector<Unit*> units = player->getUnits();
|
||||||
|
vector<Structure*> extractors, refineries;
|
||||||
|
|
||||||
for(Unit *unit : units){
|
for(Unit *unit : units){
|
||||||
if(unit->getUnitClass() == UnitClass::EXTRACTOR)
|
if(unit->getUnitClass() == UnitClass::EXTRACTOR)
|
||||||
extractors.push_back(unit);
|
extractors.push_back((Structure*)unit);
|
||||||
else if(unit->getUnitClass() == UnitClass::REFINERY)
|
else if(unit->getUnitClass() == UnitClass::REFINERY)
|
||||||
refineries.push_back(unit);
|
refineries.push_back((Structure*)unit);
|
||||||
}
|
}
|
||||||
|
|
||||||
nearestExtractor = getClosestUnit(extractors);
|
nearestExtractor = getClosestUnit(extractors);
|
||||||
@@ -45,6 +48,7 @@ namespace battleship{
|
|||||||
|
|
||||||
if(nearestExtractor->getPos().getDistanceFrom(pos) <= minDist){
|
if(nearestExtractor->getPos().getDistanceFrom(pos) <= minDist){
|
||||||
if(canLoad()){
|
if(canLoad()){
|
||||||
|
((Extractor*)nearestExtractor)->draw();
|
||||||
load++;
|
load++;
|
||||||
lastLoadTime = getTime();
|
lastLoadTime = getTime();
|
||||||
}
|
}
|
||||||
@@ -74,15 +78,23 @@ namespace battleship{
|
|||||||
Unit::displayUnitStats(loadForeground, loadBackground, load, capacity, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10));
|
Unit::displayUnitStats(loadForeground, loadBackground, load, capacity, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10));
|
||||||
}
|
}
|
||||||
|
|
||||||
Unit* ResourceRover::getClosestUnit(vector<Unit*> units){
|
Unit* ResourceRover::getClosestUnit(vector<Structure*> structs){
|
||||||
if(units.empty()) return nullptr;
|
if(structs.empty()) return nullptr;
|
||||||
|
|
||||||
int minDistId = 0;
|
int minDistId = -1;
|
||||||
|
|
||||||
for(int i = 0; i < units.size(); i++)
|
for(int i = 0; i < structs.size(); i++)
|
||||||
if(units[minDistId]->getPos().getDistanceFrom(pos) > units[i]->getPos().getDistanceFrom(pos))
|
if(structs[i]->getBuildStatus() == 100){
|
||||||
|
minDistId = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
if(minDistId == -1) return nullptr;
|
||||||
|
|
||||||
|
for(int i = 0; i < structs.size(); i++)
|
||||||
|
if(structs[i]->getBuildStatus() == 100 && structs[minDistId]->getPos().getDistanceFrom(pos) > structs[i]->getPos().getDistanceFrom(pos))
|
||||||
minDistId = i;
|
minDistId = i;
|
||||||
|
|
||||||
return units[minDistId];
|
return structs[minDistId];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
+3
-1
@@ -6,6 +6,8 @@
|
|||||||
#include <util.h>
|
#include <util.h>
|
||||||
|
|
||||||
namespace battleship{
|
namespace battleship{
|
||||||
|
class Structure;
|
||||||
|
|
||||||
class ResourceRover : public Vehicle{
|
class ResourceRover : public Vehicle{
|
||||||
public:
|
public:
|
||||||
ResourceRover(Player*, int, vb01::Vector3, vb01::Quaternion);
|
ResourceRover(Player*, int, vb01::Vector3, vb01::Quaternion);
|
||||||
@@ -13,7 +15,7 @@ namespace battleship{
|
|||||||
void update();
|
void update();
|
||||||
private:
|
private:
|
||||||
void supply(Order);
|
void supply(Order);
|
||||||
Unit* getClosestUnit(std::vector<Unit*>);
|
Unit* getClosestUnit(std::vector<Structure*>);
|
||||||
inline bool canLoad(){return vb01::getTime() - lastLoadTime > loadRate && load < capacity;}
|
inline bool canLoad(){return vb01::getTime() - lastLoadTime > loadRate && load < capacity;}
|
||||||
inline bool canUnload(){return vb01::getTime() - lastLoadTime > loadRate && load > 0;}
|
inline bool canUnload(){return vb01::getTime() - lastLoadTime > loadRate && load > 0;}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user