mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
added color change upon changing a unit's player
This commit is contained in:
+1
-1
@@ -73,7 +73,7 @@ namespace battleship{
|
||||
}
|
||||
|
||||
if(hackStatus >= 100){
|
||||
Game::getSingleton()->changeUnitPlayer(order.targets[0].unit, player);
|
||||
order.targets[0].unit->changePlayer(player);
|
||||
removeOrder(0);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -144,23 +144,6 @@ namespace battleship{
|
||||
paused = !paused;
|
||||
}
|
||||
|
||||
void Game::changeUnitPlayer(Unit *unit, Player *newPlayer){
|
||||
Player *oldPlayer = unit->getPlayer();
|
||||
vector<Unit*> &oldPlayerUnits = oldPlayer->getUnits();
|
||||
int oldId = -1;
|
||||
|
||||
for(int i = 0; i < oldPlayerUnits.size(); i++)
|
||||
if(oldPlayerUnits[i] == unit){
|
||||
oldId = i;
|
||||
break;
|
||||
}
|
||||
|
||||
oldPlayerUnits.erase(oldPlayerUnits.begin() + oldId);
|
||||
newPlayer->addUnit(unit);
|
||||
unit->setPlayer(newPlayer);
|
||||
unit->halt();
|
||||
}
|
||||
|
||||
vector<int> Game::parseTechTable(int tid, string key, string numVarKey, string varKey){
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
SOL_LUA_VIEW.script(numVarKey + " = #" + key + "[" + to_string(tid + 1) + "]." + varKey);
|
||||
|
||||
@@ -23,7 +23,6 @@ namespace battleship{
|
||||
void updateLuaPlayers(bool);
|
||||
void togglePause();
|
||||
void removeAllElements();
|
||||
void changeUnitPlayer(Unit*, Player*);
|
||||
void initTechnologies();
|
||||
float calcAbilFromTech(Ability::Type, std::vector<int>, int, int);
|
||||
bool isUnitUnlocked(std::vector<int>, int);
|
||||
|
||||
+43
-16
@@ -79,6 +79,29 @@ namespace battleship{
|
||||
delete hitbox;
|
||||
}
|
||||
|
||||
//TODO use a vector for the color nodes
|
||||
void GameObject::useColor(Material *colorMat){
|
||||
if(hitbox) model->dettachChild(hitbox);
|
||||
model->setMaterial(model->getMaterial());
|
||||
if(hitbox) model->attachChild(hitbox);
|
||||
|
||||
sol::table gameObjTable = generateView()[GameObject::getGameObjTableName()][id + 1];
|
||||
sol::table colNodeTbl = gameObjTable["colorNodes"];
|
||||
int numColorNodes = colNodeTbl.size();
|
||||
|
||||
for(int i = 0; i < numColorNodes; i++){
|
||||
string name = colNodeTbl[i + 1];
|
||||
Node *node = model->findDescendant(name, true);
|
||||
|
||||
if(!node) continue;
|
||||
|
||||
vector<Mesh*> meshes = node->getMeshes();
|
||||
|
||||
for(Mesh *mesh : meshes)
|
||||
mesh->setMaterial(colorMat);
|
||||
}
|
||||
}
|
||||
|
||||
void GameObject::initProperties(){
|
||||
sol::table sizeTable = generateView()[GameObject::getGameObjTableName()][id + 1]["size"];
|
||||
width = sizeTable["x"];
|
||||
@@ -123,22 +146,8 @@ namespace battleship{
|
||||
model->setMaterial(mat);
|
||||
sol::optional<sol::table> colNodeOpt = gameObjTable["colorNodes"];
|
||||
|
||||
if(player && colNodeOpt != sol::nullopt){
|
||||
sol::table colNodeTbl = gameObjTable["colorNodes"];
|
||||
int numColorNodes = colNodeTbl.size();
|
||||
|
||||
for(int i = 0; i < numColorNodes; i++){
|
||||
string name = colNodeTbl[i + 1];
|
||||
Node *node = model->findDescendant(name, true);
|
||||
|
||||
if(!node) continue;
|
||||
|
||||
vector<Mesh*> meshes = node->getMeshes();
|
||||
|
||||
for(Mesh *mesh : meshes)
|
||||
mesh->setMaterial(player->getColorMaterial());
|
||||
}
|
||||
}
|
||||
if(player && colNodeOpt != sol::nullopt)
|
||||
useColor(player->getColorMaterial());
|
||||
|
||||
root->getRootNode()->attachChild(model);
|
||||
}
|
||||
@@ -179,6 +188,24 @@ namespace battleship{
|
||||
return within;
|
||||
}
|
||||
|
||||
//TODO improve for other game objs, too
|
||||
void GameObject::changePlayer(Player *newPlayer){
|
||||
vector<Unit*> &oldPlayerUnits = player->getUnits();
|
||||
int oldId = -1;
|
||||
|
||||
for(int i = 0; i < oldPlayerUnits.size(); i++)
|
||||
if(oldPlayerUnits[i] == (Unit*)this){
|
||||
oldId = i;
|
||||
break;
|
||||
}
|
||||
|
||||
oldPlayerUnits.erase(oldPlayerUnits.begin() + oldId);
|
||||
newPlayer->addUnit((Unit*)this);
|
||||
setPlayer(newPlayer);
|
||||
useColor(newPlayer->getColorMaterial());
|
||||
((Unit*)this)->halt();
|
||||
}
|
||||
|
||||
string GameObject::getGameObjTableName(){
|
||||
switch(type){
|
||||
case GameObject::Type::UNIT:
|
||||
|
||||
@@ -29,6 +29,7 @@ namespace battleship{
|
||||
void updateGameStats(Unit*);
|
||||
static sf::Sound* prepareSfx(sf::SoundBuffer*, std::string);
|
||||
bool pointWithinObj(vb01::Vector3, float = 0, float = 0, bool = false, float = 0);
|
||||
void changePlayer(Player *newPlayer);
|
||||
inline vb01::Vector2 getScreenPos(){return screenPos;}
|
||||
inline vb01::Vector3 getCorner(int i){return corners[i];}
|
||||
inline bool isSelectable(){return selectable;}
|
||||
@@ -50,6 +51,7 @@ namespace battleship{
|
||||
inline vb01::Node* getHitbox(){return hitbox;}
|
||||
inline bool isRemove(){return remove;}
|
||||
protected:
|
||||
virtual void useColor(vb01::Material*);
|
||||
virtual void initProperties();
|
||||
virtual void destroyModel();
|
||||
virtual void initModel(bool = true);
|
||||
|
||||
Reference in New Issue
Block a user