mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
reiniting all game objects
This commit is contained in:
@@ -1,3 +1,5 @@
|
|||||||
|
ResourceId = {RESOURCE = 0}
|
||||||
|
|
||||||
resources = {
|
resources = {
|
||||||
{
|
{
|
||||||
name = 'Resource',
|
name = 'Resource',
|
||||||
|
|||||||
@@ -135,9 +135,21 @@ namespace battleship{
|
|||||||
guiManager->readLuaScreenScript("inGame.lua", activeState->getButtons());
|
guiManager->readLuaScreenScript("inGame.lua", activeState->getButtons());
|
||||||
AssetManager::getSingleton()->load(gm->getPath() + (string)generateView()["modelPrefix"], true);
|
AssetManager::getSingleton()->load(gm->getPath() + (string)generateView()["modelPrefix"], true);
|
||||||
|
|
||||||
for(Player *p : Game::getSingleton()->getPlayers())
|
vector<GameObject*> gameObjs;
|
||||||
for(Unit *u : p->getUnits())
|
|
||||||
u->reinit();
|
for(Player *pl : Game::getSingleton()->getPlayers()){
|
||||||
|
for(Unit *u : pl->getUnits())
|
||||||
|
gameObjs.push_back((GameObject*)u);
|
||||||
|
|
||||||
|
for(Projectile *proj : pl->getProjectiles())
|
||||||
|
gameObjs.push_back((GameObject*)proj);
|
||||||
|
|
||||||
|
for(ResourceDeposit *dep : pl->getResourceDeposits())
|
||||||
|
gameObjs.push_back((GameObject*)dep);
|
||||||
|
}
|
||||||
|
|
||||||
|
for(GameObject *obj : gameObjs)
|
||||||
|
obj->reinit();
|
||||||
|
|
||||||
gm->getStateManager()->attachAppState(activeState);
|
gm->getStateManager()->attachAppState(activeState);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -19,6 +19,11 @@ namespace battleship{
|
|||||||
using namespace gameBase;
|
using namespace gameBase;
|
||||||
using namespace configData;
|
using namespace configData;
|
||||||
|
|
||||||
|
void GameObject::reinit(){
|
||||||
|
placeAt(pos);
|
||||||
|
orientAt(rot);
|
||||||
|
}
|
||||||
|
|
||||||
void GameObject::update(){
|
void GameObject::update(){
|
||||||
leftVec = model->getGlobalAxis(0);
|
leftVec = model->getGlobalAxis(0);
|
||||||
upVec = model->getGlobalAxis(1);
|
upVec = model->getGlobalAxis(1);
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ namespace battleship{
|
|||||||
|
|
||||||
GameObject(Type t, int i, Player *pl, vb01::Vector3 vec, vb01::Quaternion quat) : type(t), id(i), player(pl), pos(vec), rot(quat){}
|
GameObject(Type t, int i, Player *pl, vb01::Vector3 vec, vb01::Quaternion quat) : type(t), id(i), player(pl), pos(vec), rot(quat){}
|
||||||
~GameObject(){}
|
~GameObject(){}
|
||||||
|
virtual void reinit();
|
||||||
virtual void update();
|
virtual void update();
|
||||||
virtual void select(){}
|
virtual void select(){}
|
||||||
void placeAt(vb01::Vector3);
|
void placeAt(vb01::Vector3);
|
||||||
|
|||||||
@@ -36,6 +36,7 @@ namespace battleship{
|
|||||||
inline int getNumResourceDeposits(){return resourceDeposits.size();}
|
inline int getNumResourceDeposits(){return resourceDeposits.size();}
|
||||||
inline void addProjectile(Projectile *proj){projectiles.push_back(proj);}
|
inline void addProjectile(Projectile *proj){projectiles.push_back(proj);}
|
||||||
inline int getNumProjectiles(){return projectiles.size();}
|
inline int getNumProjectiles(){return projectiles.size();}
|
||||||
|
inline std::vector<Projectile*>& getProjectiles(){return projectiles;}
|
||||||
inline Unit* getUnit(int i){return units[i];}
|
inline Unit* getUnit(int i){return units[i];}
|
||||||
inline std::vector<Unit*>& getUnits(){return units;}
|
inline std::vector<Unit*>& getUnits(){return units;}
|
||||||
inline void setTeam(int t){team = t;}
|
inline void setTeam(int t){team = t;}
|
||||||
|
|||||||
@@ -33,9 +33,22 @@ namespace battleship{
|
|||||||
}
|
}
|
||||||
|
|
||||||
Projectile::~Projectile(){
|
Projectile::~Projectile(){
|
||||||
|
destroySound();
|
||||||
destroyModel();
|
destroyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void Projectile::reinit(){
|
||||||
|
destroySound();
|
||||||
|
destroyModel();
|
||||||
|
|
||||||
|
initProperties();
|
||||||
|
|
||||||
|
initModel();
|
||||||
|
initSound();
|
||||||
|
|
||||||
|
GameObject::reinit();
|
||||||
|
}
|
||||||
|
|
||||||
void Projectile::initProperties(){
|
void Projectile::initProperties(){
|
||||||
GameObject::initProperties();
|
GameObject::initProperties();
|
||||||
|
|
||||||
|
|||||||
@@ -26,6 +26,7 @@ namespace battleship {
|
|||||||
void initSound();
|
void initSound();
|
||||||
void checkCollision();
|
void checkCollision();
|
||||||
protected:
|
protected:
|
||||||
|
virtual void reinit();
|
||||||
virtual void checkUnitCollision();
|
virtual void checkUnitCollision();
|
||||||
virtual void checkSurfaceCollision();
|
virtual void checkSurfaceCollision();
|
||||||
|
|
||||||
|
|||||||
@@ -19,4 +19,16 @@ namespace battleship{
|
|||||||
destroyHitbox();
|
destroyHitbox();
|
||||||
destroyModel();
|
destroyModel();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ResourceDeposit::reinit(){
|
||||||
|
destroyHitbox();
|
||||||
|
destroyModel();
|
||||||
|
|
||||||
|
initProperties();
|
||||||
|
|
||||||
|
initModel();
|
||||||
|
initHitbox();
|
||||||
|
|
||||||
|
GameObject::reinit();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -13,6 +13,8 @@ namespace battleship{
|
|||||||
inline void decrementAmmount(){ammount--;}
|
inline void decrementAmmount(){ammount--;}
|
||||||
private:
|
private:
|
||||||
int ammount, initAmmount;
|
int ammount, initAmmount;
|
||||||
|
|
||||||
|
void reinit();
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -100,7 +100,13 @@ namespace battleship{
|
|||||||
this->player = player;
|
this->player = player;
|
||||||
selectable = true;
|
selectable = true;
|
||||||
|
|
||||||
init();
|
initProperties();
|
||||||
|
initModel();
|
||||||
|
initHitbox();
|
||||||
|
initSound();
|
||||||
|
initWeapons();
|
||||||
|
placeAt(pos);
|
||||||
|
orientAt(rot);
|
||||||
|
|
||||||
Vector2 size = Vector2(lenHpBar, 10);
|
Vector2 size = Vector2(lenHpBar, 10);
|
||||||
hpBackgroundNode = createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
|
hpBackgroundNode = createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1));
|
||||||
@@ -116,16 +122,6 @@ namespace battleship{
|
|||||||
destroyWeapons();
|
destroyWeapons();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Unit::init(){
|
|
||||||
initProperties();
|
|
||||||
initModel();
|
|
||||||
initHitbox();
|
|
||||||
initSound();
|
|
||||||
initWeapons();
|
|
||||||
placeAt(pos);
|
|
||||||
orientAt(rot);
|
|
||||||
}
|
|
||||||
|
|
||||||
void Unit::initProperties(){
|
void Unit::initProperties(){
|
||||||
GameObject::initProperties();
|
GameObject::initProperties();
|
||||||
|
|
||||||
@@ -205,6 +201,7 @@ namespace battleship{
|
|||||||
delete selectionSfxBuffer;
|
delete selectionSfxBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//TODO factor out initSound()
|
||||||
void Unit::initSound(){
|
void Unit::initSound(){
|
||||||
GameObject::initSound();
|
GameObject::initSound();
|
||||||
selectionSfxBuffer = new sf::SoundBuffer();
|
selectionSfxBuffer = new sf::SoundBuffer();
|
||||||
@@ -216,12 +213,16 @@ namespace battleship{
|
|||||||
destroySound();
|
destroySound();
|
||||||
destroyHitbox();
|
destroyHitbox();
|
||||||
destroyModel();
|
destroyModel();
|
||||||
|
destroyWeapons();
|
||||||
|
|
||||||
initProperties();
|
initProperties();
|
||||||
|
|
||||||
initModel();
|
initModel();
|
||||||
initHitbox();
|
initHitbox();
|
||||||
initSound();
|
initSound();
|
||||||
placeAt(pos);
|
initWeapons();
|
||||||
orientAt(rot);
|
|
||||||
|
GameObject::reinit();
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Unit::canGarrison(Vehicle *vehicle){
|
bool Unit::canGarrison(Vehicle *vehicle){
|
||||||
|
|||||||
@@ -124,7 +124,6 @@ namespace battleship{
|
|||||||
void setOrder(Order);
|
void setOrder(Order);
|
||||||
std::vector<Projectile*> getProjectiles();
|
std::vector<Projectile*> getProjectiles();
|
||||||
virtual void addOrder(Order);
|
virtual void addOrder(Order);
|
||||||
virtual void reinit();
|
|
||||||
bool canGarrison(Vehicle*);
|
bool canGarrison(Vehicle*);
|
||||||
inline Engineer* toEngineer(){return (Engineer*)this;}
|
inline Engineer* toEngineer(){return (Engineer*)this;}
|
||||||
inline Factory* toFactory(){return (Factory*)this;}
|
inline Factory* toFactory(){return (Factory*)this;}
|
||||||
@@ -147,7 +146,6 @@ namespace battleship{
|
|||||||
private:
|
private:
|
||||||
void renderOrderLine(bool);
|
void renderOrderLine(bool);
|
||||||
void updateScreenCoordinates();
|
void updateScreenCoordinates();
|
||||||
void init();
|
|
||||||
void initWeapons();
|
void initWeapons();
|
||||||
void destroyWeapons();
|
void destroyWeapons();
|
||||||
inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;}
|
inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;}
|
||||||
@@ -170,6 +168,7 @@ namespace battleship{
|
|||||||
|
|
||||||
std::vector<Player*> getSelectingPlayers();
|
std::vector<Player*> getSelectingPlayers();
|
||||||
void removeOrder(int);
|
void removeOrder(int);
|
||||||
|
virtual void reinit();
|
||||||
virtual void initProperties();
|
virtual void initProperties();
|
||||||
virtual void destroySound();
|
virtual void destroySound();
|
||||||
virtual void initSound();
|
virtual void initSound();
|
||||||
|
|||||||
Reference in New Issue
Block a user