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