From b087238fbb1e54ab7938e4cab16cc212d7a6073c Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sat, 22 Jun 2024 19:42:40 +0300 Subject: [PATCH] simple color coded unit models --- Assets/Scripts/GameObjects/Units/unitData.lua | 5 +++-- gameObject.cpp | 17 +++++++++++++++ playButton.cpp | 2 +- player.cpp | 21 +++++++++++++++++-- player.h | 2 ++ 5 files changed, 42 insertions(+), 5 deletions(-) diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index bf7e8bb..8310d74 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -184,7 +184,8 @@ units = { lineOfSight = 25, name = 'Tank', basePath = PATH .. vehiclePrefix .. 'Tanks/', - meshPath = 'tank.xml', + meshPath = 'tank2.xml', + colorNodes = {'Antenna_S', 'Antenna_L', 'Hatch'}, selectionSfx = PATH .. 'Sounds/Units/Tanks/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', speed = .1, @@ -912,7 +913,7 @@ units = { lineOfSight = 5, name = 'Fort', basePath = PATH .. structurePrefix .. 'Forts/', - meshPath = 'fort.xml', + meshPath = 'fort2.xml', guiScreen = 'fortCommands.lua', selectionSfx = PATH .. 'Sounds/Units/Sample/selection.ogg', deathSfx = PATH .. 'Sounds/SFX/Explosions/explosion01.ogg', diff --git a/gameObject.cpp b/gameObject.cpp index d7b6962..c52cc60 100644 --- a/gameObject.cpp +++ b/gameObject.cpp @@ -101,6 +101,23 @@ namespace battleship{ } model->setMaterial(mat); + + if((sol::optional)gameObjTable["colorNodes"] != sol::nullopt){ + int numColorNodes = ((sol::table)gameObjTable["colorNodes"]).size(); + + for(int i = 0; i < numColorNodes; i++){ + string name = gameObjTable["colorNodes"][i + 1]; + Node *node = model->findDescendant(name, true); + + if(!node) continue; + + vector meshes = node->getMeshes(); + + for(Mesh *mesh : meshes) + mesh->setMaterial(player->getColorMaterial()); + } + } + root->getRootNode()->attachChild(model); } diff --git a/playButton.cpp b/playButton.cpp index 4bdeeed..c3457ea 100644 --- a/playButton.cpp +++ b/playButton.cpp @@ -42,7 +42,7 @@ namespace battleship{ for(int i = 0; i < numPlayers; i++){ bool cpuPlayer = (i < numPlayers - 1); string name = (cpuPlayer ? "CPU player #" + to_string(i) : "Player"); - game->addPlayer(new Player(0, 0, i, Vector3(1, 1, 1), cpuPlayer, map->getSpawnPoint(i), name)); + game->addPlayer(new Player(0, 0, i, Vector3(i, i, i), cpuPlayer, map->getSpawnPoint(i), name)); } map->loadPlayerGameObjects(); diff --git a/player.cpp b/player.cpp index 5d4c947..92b3b5f 100755 --- a/player.cpp +++ b/player.cpp @@ -12,9 +12,26 @@ namespace battleship{ using namespace gameBase; using namespace std; - Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, Vector3 sp, string n) : difficulty(diff), faction(fac), team(t), color(col), cpuPlayer(cpuPl), spawnPoint(sp), name("pl"), refineds(30000), trader(new Trader()) {} + Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, Vector3 sp, string n) : + difficulty(diff), + faction(fac), + team(t), + color(col), + cpuPlayer(cpuPl), + spawnPoint(sp), + name("pl"), + refineds(30000), + trader(new Trader()) + { + colorMaterial = new Material(Root::getSingleton()->getLibPath() + "texture"); + colorMaterial->addBoolUniform("lightingEnabled", false); + colorMaterial->addBoolUniform("texturingEnabled", false); + colorMaterial->addVec4Uniform("diffuseColor", Vector4(color.x, color.y, color.z, 1)); + } - Player::~Player() {} + Player::~Player() { + delete colorMaterial; + } void Player::update() { trader->update(); diff --git a/player.h b/player.h index 04e3010..e64b3db 100755 --- a/player.h +++ b/player.h @@ -68,6 +68,7 @@ namespace battleship{ inline void incStructuresLost(){structuresLost++;} inline vb01::Vector3 getColor(){return color;} inline std::string getName(){return name;} + inline vb01::Material* getColorMaterial(){return colorMaterial;} inline std::vector getTechnologies(){return technologies;} private: bool cpuPlayer = false; @@ -83,6 +84,7 @@ namespace battleship{ std::vector projectiles; std::vector resourceDeposits; vb01::Vector3 spawnPoint, color; + vb01::Material *colorMaterial = nullptr; int getOrderLineId(Order::TYPE, vb01::Vector3, vb01::Vector3); };