From d04c5dbdc66a8f271f0c5479312d697df8dcbc24 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 8 Sep 2024 14:26:12 +0300 Subject: [PATCH 01/11] updated vb01 --- external/vb01 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/vb01 b/external/vb01 index 44afb44..39dc1af 160000 --- a/external/vb01 +++ b/external/vb01 @@ -1 +1 @@ -Subproject commit 44afb4409c62c929e1a886c897582de7a80e8d42 +Subproject commit 39dc1afd25c12290e8e49b1df56a4e474c13ad47 From 52b9ac2ffdabf5a12089ae8e8591f113888921c6 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 8 Sep 2024 15:25:18 +0300 Subject: [PATCH 02/11] improved line of sight detection --- activeGameState.cpp | 36 +++++++++++++++++++----------------- 1 file changed, 19 insertions(+), 17 deletions(-) diff --git a/activeGameState.cpp b/activeGameState.cpp index 22cf484..383f796 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -310,12 +310,6 @@ namespace battleship{ //TODO fix fog of war for hostile units void ActiveGameState::renderUnits() { - vector units; - - for (Player *p : Game::getSingleton()->getPlayers()) - for (Unit *u : p->getUnits()) - units.push_back(u); - ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); vector listboxes{}; vector checkboxes{}; @@ -328,6 +322,13 @@ namespace battleship{ guiManager->getText("wealth"), guiManager->getText("research") }; + + vector units; + + for (Player *p : Game::getSingleton()->getPlayers()) + for (Unit *u : p->getUnits()) + units.push_back(u); + vector selUnits = mainPlayer->getSelectedUnits(); for (Unit *u : units) { @@ -339,21 +340,22 @@ namespace battleship{ guiManager->readLuaScreenScript(u->getGuiScreen(), buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); unitGuiScreen = guiScreen; } - } - else{ - Vector3 rendUnPos = u->getPos(); - rendUnPos.y = 0; - for (int i = 0; i < units.size() && units[i] != u && units[i]->getPlayer() == mainPlayer; i++) { - Vector3 compUnPos = units[i]->getPos(); - compUnPos.y = 0; - float dist = compUnPos.getDistanceFrom(rendUnPos); - u->getNode()->setVisible(dist <= units[i]->getLineOfSight() || isInLineOfSight(compUnPos, units[i]->getLineOfSight(), u)); - } - } + Vector3 obsUnitPos = u->getPos(); + obsUnitPos.y = 0; + + for (int i = 0; i < units.size(); i++) + if(units[i]->getPlayer() != mainPlayer){ + Vector3 compUnitPos = units[i]->getPos(); + compUnitPos.y = 0; + float dist = compUnitPos.getDistanceFrom(obsUnitPos); + units[i]->getNode()->setVisible(dist <= u->getLineOfSight()); + } + } } } + //TODO improve this for greater accuracy bool ActiveGameState::isInLineOfSight(Vector3 center, float radius, Unit *u) { bool inside = false; From a0c1ffb4e2e159593e1ab82aceccb5396b05bba5 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 8 Sep 2024 15:25:46 +0300 Subject: [PATCH 03/11] enabled lighting --- gameObject.cpp | 2 +- main.cpp | 1 + map.cpp | 8 +++++++- player.cpp | 2 +- unit.cpp | 22 +++++++++++++++++++--- unit.h | 4 +++- 6 files changed, 32 insertions(+), 7 deletions(-) diff --git a/gameObject.cpp b/gameObject.cpp index 4083569..0249480 100644 --- a/gameObject.cpp +++ b/gameObject.cpp @@ -102,7 +102,7 @@ namespace battleship{ string f[]{albedoPath == configData::DEFAULT_TEXTURE ? GameManager::getSingleton()->getPath() + albedoPath : basePath + albedoPath}; Texture *diffuseTexture = new Texture(f, 1, false); mat->addBoolUniform("texturingEnabled", true); - mat->addBoolUniform("lightingEnabled", false); + mat->addBoolUniform("lightingEnabled", true); mat->addTexUniform("textures[0]", diffuseTexture, true); } else{ diff --git a/main.cpp b/main.cpp index bea132f..064259f 100755 --- a/main.cpp +++ b/main.cpp @@ -6,6 +6,7 @@ #include #include +#include #include diff --git a/map.cpp b/map.cpp index cbcdadc..7d337e9 100755 --- a/map.cpp +++ b/map.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -123,7 +124,7 @@ namespace battleship{ Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture"); mat->addBoolUniform("texturingEnabled", true); - mat->addBoolUniform("lightingEnabled", false); + mat->addBoolUniform("lightingEnabled", true); string fr[]{texPath}; AssetManager::getSingleton()->load(fr[0]); @@ -230,6 +231,7 @@ namespace battleship{ cam->setFarPlane(600); cam->setPosition(Vector3(1, 1, 1) * configData::CAMERA_DISTANCE); cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm()); + } //TODO implement toggleable cell rendering @@ -294,6 +296,10 @@ namespace battleship{ for(int i = 0; i < numWaterbodies; i++) loadTerrainObject(i); } + + Node *lightNode = new Node(Vector3::VEC_ZERO, Quaternion(1.57, Vector3::VEC_I)); + lightNode->addLight(new Light(Light::Type::DIRECTIONAL)); + Root::getSingleton()->getRootNode()->attachChild(lightNode); } //TODO unload skybox assets diff --git a/player.cpp b/player.cpp index 92b3b5f..5845d4c 100755 --- a/player.cpp +++ b/player.cpp @@ -24,7 +24,7 @@ namespace battleship{ trader(new Trader()) { colorMaterial = new Material(Root::getSingleton()->getLibPath() + "texture"); - colorMaterial->addBoolUniform("lightingEnabled", false); + colorMaterial->addBoolUniform("lightingEnabled", true); colorMaterial->addBoolUniform("texturingEnabled", false); colorMaterial->addVec4Uniform("diffuseColor", Vector4(color.x, color.y, color.z, 1)); } diff --git a/unit.cpp b/unit.cpp index 4c89ff6..751001c 100755 --- a/unit.cpp +++ b/unit.cpp @@ -1,9 +1,10 @@ -#include -#include #include +#include +#include +#include +#include #include #include -#include #include #include @@ -291,6 +292,7 @@ namespace battleship{ Unit::initProperties(); initModel(); initHitbox(); + initLosLight(); initSound(); initWeapons(); placeAt(pos); @@ -306,6 +308,7 @@ namespace battleship{ removeBar(hpForegroundNode); destroyWeapons(); destroySound(); + destroyLosLight(); destroyHitbox(); destroyModel(); } @@ -405,6 +408,19 @@ namespace battleship{ weapons.clear(); } + + void Unit::initLosLight(){ + lightNode = new Node(); + Light *light = new Light(Light::Type::POINT); + //light->setAttenuationValues(1, 1, 1); + model->attachChild(lightNode); + } + + void Unit::destroyLosLight(){ + model->dettachChild(lightNode); + delete lightNode; + lightNode = nullptr; + } void Unit::destroySound(){ selectionSfx->stop(); diff --git a/unit.h b/unit.h index 716f0ab..04df3be 100755 --- a/unit.h +++ b/unit.h @@ -161,12 +161,14 @@ namespace battleship{ void updateScreenCoordinates(); void initWeapons(); void destroyWeapons(); + void initLosLight(); + void destroyLosLight(); inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;} const int orderVecDispLength = 2000, DEATH_HP = 0; sf::SoundBuffer *selectionSfxBuffer; sf::Sound *selectionSfx = nullptr; - vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr; + vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr, *lightNode = nullptr; bool vehicle; protected: UnitClass unitClass; From 166696041c4dbb19471ad3a8ffc648c0b6aeff15 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Thu, 12 Sep 2024 19:27:30 +0300 Subject: [PATCH 04/11] working circular lights around units --- activeGameState.cpp | 4 +++- gameObject.cpp | 1 + map.cpp | 11 +++++++++-- unit.cpp | 19 +++++++++++++------ unit.h | 4 +++- 5 files changed, 29 insertions(+), 10 deletions(-) diff --git a/activeGameState.cpp b/activeGameState.cpp index 383f796..261cdde 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -333,6 +333,7 @@ namespace battleship{ for (Unit *u : units) { if (u->getPlayer() == mainPlayer){ + u->getLosLightNode()->setVisible(true); Vector2 pos = u->getScreenPos(); string guiScreen = u->getGuiScreen(); @@ -349,7 +350,8 @@ namespace battleship{ Vector3 compUnitPos = units[i]->getPos(); compUnitPos.y = 0; float dist = compUnitPos.getDistanceFrom(obsUnitPos); - units[i]->getNode()->setVisible(dist <= u->getLineOfSight()); + units[i]->getNode()->setVisible(true); + //units[i]->getNode()->setVisible(dist <= u->getLineOfSight()); } } } diff --git a/gameObject.cpp b/gameObject.cpp index 0249480..d752e77 100644 --- a/gameObject.cpp +++ b/gameObject.cpp @@ -103,6 +103,7 @@ namespace battleship{ Texture *diffuseTexture = new Texture(f, 1, false); mat->addBoolUniform("texturingEnabled", true); mat->addBoolUniform("lightingEnabled", true); + mat->addBoolUniform("constLightingEnabled", false); mat->addTexUniform("textures[0]", diffuseTexture, true); } else{ diff --git a/map.cpp b/map.cpp index 7d337e9..3ef0167 100755 --- a/map.cpp +++ b/map.cpp @@ -125,6 +125,10 @@ namespace battleship{ Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture"); mat->addBoolUniform("texturingEnabled", true); mat->addBoolUniform("lightingEnabled", true); + mat->addBoolUniform("constLightingEnabled", true); + mat->addBoolUniform("normalMapEnabled", false); + mat->addBoolUniform("specularMapEnabled", false); + mat->addBoolUniform("castShadow", false); string fr[]{texPath}; AssetManager::getSingleton()->load(fr[0]); @@ -297,8 +301,11 @@ namespace battleship{ loadTerrainObject(i); } - Node *lightNode = new Node(Vector3::VEC_ZERO, Quaternion(1.57, Vector3::VEC_I)); - lightNode->addLight(new Light(Light::Type::DIRECTIONAL)); + Light *light = new Light(Light::Type::AMBIENT); + light->setColor(Vector3::VEC_IJK * .3); + + Node *lightNode = new Node(); + lightNode->addLight(light); Root::getSingleton()->getRootNode()->attachChild(lightNode); } diff --git a/unit.cpp b/unit.cpp index 751001c..964570c 100755 --- a/unit.cpp +++ b/unit.cpp @@ -410,16 +410,23 @@ namespace battleship{ } void Unit::initLosLight(){ - lightNode = new Node(); Light *light = new Light(Light::Type::POINT); - //light->setAttenuationValues(1, 1, 1); - model->attachChild(lightNode); + light->setAttenuation(Light::Attenuation::NONE); + light->setRadius(lineOfSight); + light->setColor(Vector3::VEC_IJK * .3); + light->setAdditiveLighting(false); + light->setUseAngle(false); + + losLightNode = new Node(Vector3::VEC_J * 5); + losLightNode->addLight(light); + losLightNode->setVisible(true); + model->attachChild(losLightNode); } void Unit::destroyLosLight(){ - model->dettachChild(lightNode); - delete lightNode; - lightNode = nullptr; + model->dettachChild(losLightNode); + delete losLightNode; + losLightNode = nullptr; } void Unit::destroySound(){ diff --git a/unit.h b/unit.h index 04df3be..3c9d9e1 100755 --- a/unit.h +++ b/unit.h @@ -21,6 +21,7 @@ namespace vb01{ class Mesh; class Quad; class Node; + class Light; class Camera; } @@ -156,6 +157,7 @@ namespace battleship{ inline int getNumOrders(){return orders.size();} inline std::string getGuiScreen(){return guiScreen;} inline BuildableUnit getBuildableUnit(int i){return buildableUnits[i];} + inline vb01::Node* getLosLightNode(){return losLightNode;} private: void renderOrderLine(bool); void updateScreenCoordinates(); @@ -168,7 +170,7 @@ namespace battleship{ const int orderVecDispLength = 2000, DEATH_HP = 0; sf::SoundBuffer *selectionSfxBuffer; sf::Sound *selectionSfx = nullptr; - vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr, *lightNode = nullptr; + vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr, *losLightNode = nullptr; bool vehicle; protected: UnitClass unitClass; From bd0c4a4f55491f137d2d120b1b182d4893b670a9 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Thu, 12 Sep 2024 20:16:25 +0300 Subject: [PATCH 05/11] loading lights from map scripts --- map.cpp | 53 ++++++++++++++++++++++++++++++++++++++++++++--------- map.h | 4 ++++ 2 files changed, 48 insertions(+), 9 deletions(-) diff --git a/map.cpp b/map.cpp index 3ef0167..d2c297d 100755 --- a/map.cpp +++ b/map.cpp @@ -87,6 +87,33 @@ namespace battleship{ Root::getSingleton()->createSkybox(path); } + void Map::loadLights(){ + sol::state_view SOL_LUA_VIEW = generateView(); + sol::table lightsTbl = SOL_LUA_VIEW[mapTable]["lights"]; + int numLights = lightsTbl.size(); + + for(int i = 0; i < numLights; i++){ + int id = i + 1; + Light::Type type = (Light::Type)lightsTbl[id]["type"]; + sol::table colTbl = lightsTbl[id]["color"]; + + Light *light = new Light(type); + light->setColor(Vector3(colTbl["x"], colTbl["y"], colTbl["z"])); + + Node *lightNode = new Node(); + lightNode->addLight(light); + lights.push_back(light); + + if(type == Light::Type::DIRECTIONAL){ + sol::table dirTbl = lightsTbl[id]["dir"]; + Vector3 dir = Vector3(dirTbl["x"], dirTbl["y"], dirTbl["z"]).norm(); + lightNode->lookAt(dir); + } + + Root::getSingleton()->getRootNode()->attachChild(lightNode); + } + } + void Map::loadTerrainObject(int id){ string texPath = "", albedoPath = ""; Quad *quad = nullptr; @@ -288,25 +315,24 @@ namespace battleship{ if(!empty){ SOL_LUA_STATE.script_file(path + "Models/Maps/" + mapName + "/" + mapName + ".lua"); - sol::table sizeTable = SOL_LUA_STATE[mapTable]["size"]; - mapSize = Vector3(sizeTable["x"], sizeTable["y"], sizeTable["z"]); - int numWaterbodies = SOL_LUA_STATE[mapTable]["numWaterBodies"]; + sol::optional lightsOpt = SOL_LUA_STATE[mapTable]["lights"]; + if(lightsOpt != sol::nullopt) + loadLights(); + loadSpawnPoints(); loadSkybox(); loadCells(); loadTerrainObject(-1); + + sol::table sizeTable = SOL_LUA_STATE[mapTable]["size"]; + mapSize = Vector3(sizeTable["x"], sizeTable["y"], sizeTable["z"]); + int numWaterbodies = SOL_LUA_STATE[mapTable]["numWaterBodies"]; for(int i = 0; i < numWaterbodies; i++) loadTerrainObject(i); } - Light *light = new Light(Light::Type::AMBIENT); - light->setColor(Vector3::VEC_IJK * .3); - - Node *lightNode = new Node(); - lightNode->addLight(light); - Root::getSingleton()->getRootNode()->attachChild(lightNode); } //TODO unload skybox assets @@ -314,6 +340,14 @@ namespace battleship{ Root::getSingleton()->removeSkybox(); } + void Map::unloadLights(){ + while(!lights.empty()){ + Root::getSingleton()->getRootNode()->removeLight(lights[0]); + delete lights[0]; + lights.erase(lights.begin()); + } + } + void Map::unloadCells(){ while(cellNode->getNumChildren() > 0){ Node *node = cellNode->getChild(0); @@ -360,6 +394,7 @@ namespace battleship{ void Map::unload(){ unloadSkybox(); + unloadLights(); unloadCells(); unloadTerrainObjects(); unloadPlayerObjects(); diff --git a/map.h b/map.h index ccccf64..ba310b5 100755 --- a/map.h +++ b/map.h @@ -12,6 +12,7 @@ namespace vb01{ class Model; class Material; class Node; + class Light; } namespace battleship{ @@ -67,15 +68,18 @@ namespace battleship{ vb01::Vector3 CELL_SIZE = vb01::Vector3(7, 7, 7), mapSize; std::vector spawnPoints; std::vector cells; + std::vector lights; Map(){} void preprareScene(); void loadSpawnPoints(); + void loadLights(); void loadSkybox(); void loadCells(); void loadTerrainObject(int); void unloadTerrainObjects(); void unloadCells(); + void unloadLights(); void unloadSkybox(); void unloadPlayerObjects(); void destroyScene(); From 999bd77d8f9a51c6c019d7f77a27fd22f56a7573 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Fri, 13 Sep 2024 20:20:06 +0300 Subject: [PATCH 06/11] exporting lighting data --- map.cpp | 12 ++++++++++-- map.h | 5 +++-- mapEditorAppState.cpp | 17 ++++++++++++++++- 3 files changed, 29 insertions(+), 5 deletions(-) diff --git a/map.cpp b/map.cpp index d2c297d..b8224d9 100755 --- a/map.cpp +++ b/map.cpp @@ -101,8 +101,8 @@ namespace battleship{ light->setColor(Vector3(colTbl["x"], colTbl["y"], colTbl["z"])); Node *lightNode = new Node(); + lights.push_back(lightNode); lightNode->addLight(light); - lights.push_back(light); if(type == Light::Type::DIRECTIONAL){ sol::table dirTbl = lightsTbl[id]["dir"]; @@ -332,7 +332,15 @@ namespace battleship{ for(int i = 0; i < numWaterbodies; i++) loadTerrainObject(i); } + else{ + Light *light = new Light(Light::Type::AMBIENT); + light->setColor(Vector3::VEC_IJK * .9); + Node *node = new Node(); + node->addLight(light); + Root::getSingleton()->getRootNode()->attachChild(node); + lights.push_back(node); + } } //TODO unload skybox assets @@ -342,7 +350,7 @@ namespace battleship{ void Map::unloadLights(){ while(!lights.empty()){ - Root::getSingleton()->getRootNode()->removeLight(lights[0]); + Root::getSingleton()->getRootNode()->dettachChild(lights[0]); delete lights[0]; lights.erase(lights.begin()); } diff --git a/map.h b/map.h index ba310b5..bacf47c 100755 --- a/map.h +++ b/map.h @@ -12,7 +12,6 @@ namespace vb01{ class Model; class Material; class Node; - class Light; } namespace battleship{ @@ -60,6 +59,8 @@ namespace battleship{ inline vb01::Vector3 getMapSize(){return mapSize;} inline void addSpawnPoint(vb01::Vector3 sp){spawnPoints.push_back(sp);} inline std::vector& getCells(){return cells;} + inline vb01::Node* getLight(int i){return lights[i];} + inline std::vector getLights(){return lights;} private: std::string mapTable = "map"; vb01::Node *terrainNode = nullptr, *cellNode = nullptr; @@ -68,7 +69,7 @@ namespace battleship{ vb01::Vector3 CELL_SIZE = vb01::Vector3(7, 7, 7), mapSize; std::vector spawnPoints; std::vector cells; - std::vector lights; + std::vector lights; Map(){} void preprareScene(); diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index 92164a4..9f8d642 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include #include #include @@ -394,7 +395,21 @@ namespace battleship{ vector players = Game::getSingleton()->getPlayers(); Vector3 mapSize = map->getMapSize(); - string mapScript = "map = {\nnumWaterBodies = " + to_string(numWaterBodies) + ",\n"; + string mapScript = "map = {\nlights = {\n"; + + for(Node *light : map->getLights()){ + mapScript += "{type = " + to_string((int)light->getLight(0)->getType()); + + if(light->getLight(0)->getLightType() == Light::Type::DIRECTIONAL){ + Vector3 dir = light->getGlobalAxis(2); + mapScript += ", dir = {x = " + to_string(dir.x) + ", y = " + to_string(dir.y) + "z = " + to_string(dir.z) + "}"; + } + + Vector3 color = light->getLight(0)->getColor(); + mapScript += ", color = {x = " + to_string(color.x) + ", y = " + to_string(color.y) + ", z = " + to_string(color.z) + "}},"; + } + + mapScript += "}\nnumWaterBodies = " + to_string(numWaterBodies) + ",\n"; mapScript += "size = {x = " + to_string(mapSize.x) + ", y = 100, z = " + to_string(mapSize.z) + "},\n"; mapScript += "impassibleNodeValue = " + to_string(IMPASS_NODE_VAL) + ",\n"; mapScript += "numPlayers = " + to_string(players.size()) + ",\n"; From 12a94b7fd345a8261bdab8f2ba15f20a47c3d6c0 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Fri, 13 Sep 2024 20:27:23 +0300 Subject: [PATCH 07/11] bugfix to hide and reveal enemy units when the player has multiple --- activeGameState.cpp | 31 ++++++++++++++++++++++--------- engineer.cpp | 1 + unit.cpp | 3 --- unit.h | 4 ++-- 4 files changed, 25 insertions(+), 14 deletions(-) diff --git a/activeGameState.cpp b/activeGameState.cpp index 261cdde..91c5de9 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -332,8 +332,13 @@ namespace battleship{ vector selUnits = mainPlayer->getSelectedUnits(); for (Unit *u : units) { + Node *model = u->getNode(); + if (u->getPlayer() == mainPlayer){ - u->getLosLightNode()->setVisible(true); + if(!u->getLosLightNode()) u->initLosLight(); + + model->setVisible(true); + Vector2 pos = u->getScreenPos(); string guiScreen = u->getGuiScreen(); @@ -341,19 +346,27 @@ namespace battleship{ guiManager->readLuaScreenScript(u->getGuiScreen(), buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts); unitGuiScreen = guiScreen; } + } + else{ + if(u->getLosLightNode()) u->destroyLosLight(); - Vector3 obsUnitPos = u->getPos(); - obsUnitPos.y = 0; + model->setVisible(false); - for (int i = 0; i < units.size(); i++) - if(units[i]->getPlayer() != mainPlayer){ - Vector3 compUnitPos = units[i]->getPos(); + for (int i = 0; i < units.size(); i++) + if(units[i]->getPlayer() == mainPlayer){ + Vector3 obsUnitPos = units[i]->getPos(); + obsUnitPos.y = 0; + + Vector3 compUnitPos = u->getPos(); compUnitPos.y = 0; float dist = compUnitPos.getDistanceFrom(obsUnitPos); - units[i]->getNode()->setVisible(true); - //units[i]->getNode()->setVisible(dist <= u->getLineOfSight()); + + if(dist <= units[i]->getLineOfSight()){ + model->setVisible(true); + break; + } } - } + } } } diff --git a/engineer.cpp b/engineer.cpp index ec1d69f..8d54681 100644 --- a/engineer.cpp +++ b/engineer.cpp @@ -78,6 +78,7 @@ namespace battleship{ } } + //TODO change unit colors after faction change void Engineer::hack(Order order){ Unit *targUnit = order.targets[0].unit; bool withinRange = (targUnit->getPos().getDistanceFrom(pos) < hackRange); diff --git a/unit.cpp b/unit.cpp index 964570c..53ef3d8 100755 --- a/unit.cpp +++ b/unit.cpp @@ -292,7 +292,6 @@ namespace battleship{ Unit::initProperties(); initModel(); initHitbox(); - initLosLight(); initSound(); initWeapons(); placeAt(pos); @@ -308,7 +307,6 @@ namespace battleship{ removeBar(hpForegroundNode); destroyWeapons(); destroySound(); - destroyLosLight(); destroyHitbox(); destroyModel(); } @@ -419,7 +417,6 @@ namespace battleship{ losLightNode = new Node(Vector3::VEC_J * 5); losLightNode->addLight(light); - losLightNode->setVisible(true); model->attachChild(losLightNode); } diff --git a/unit.h b/unit.h index 3c9d9e1..ada7f0d 100755 --- a/unit.h +++ b/unit.h @@ -135,6 +135,8 @@ namespace battleship{ std::vector getProjectiles(); virtual void addOrder(Order); bool canGarrison(Vehicle*); + void initLosLight(); + void destroyLosLight(); inline void setState(State s){state = s;} inline Engineer* toEngineer(){return (Engineer*)this;} inline Structure* toStructure(){return (Structure*)this;} @@ -163,8 +165,6 @@ namespace battleship{ void updateScreenCoordinates(); void initWeapons(); void destroyWeapons(); - void initLosLight(); - void destroyLosLight(); inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;} const int orderVecDispLength = 2000, DEATH_HP = 0; From dea5cf6e496f71cb1b1189d2d7075f3ce7daded8 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Fri, 13 Sep 2024 20:45:30 +0300 Subject: [PATCH 08/11] added lights to some maps fixed light type export --- Assets/Models/Maps/111/111.lua | 5 ++++- Assets/Models/Maps/222/222.lua | 3 +++ Assets/Models/Maps/water/water.lua | 34 +++++++++++++++++------------- mapEditorAppState.cpp | 2 +- 4 files changed, 27 insertions(+), 17 deletions(-) diff --git a/Assets/Models/Maps/111/111.lua b/Assets/Models/Maps/111/111.lua index 07f8284..880fb39 100644 --- a/Assets/Models/Maps/111/111.lua +++ b/Assets/Models/Maps/111/111.lua @@ -1,4 +1,7 @@ map = { + lights = { + {type = 3, color = {x = .9, y = .9, z = .9}}, + }, numWaterBodies = 1, size = {x = 123.000000, y = 100, z = 123.000000}, impassibleNodeValue = 65535, @@ -352,5 +355,5 @@ cells = { skybox = "Skybox1", terrain = {model = "111.xml", albedo = "111.jpg"}, waterbodies = { -{pos = {x = 7.296803, y = -0.948949, z = 6.370515}, size = {x = 42.873222, y = 42.948956}, albedo = "water.jpg"},} +{pos = {x = 7.296803, y = -0.948949, z = 6.370515}, size = {x = 42.873222, y = 42.948956}, albedo = "water.png"},} } diff --git a/Assets/Models/Maps/222/222.lua b/Assets/Models/Maps/222/222.lua index 50da9ab..e2d8b3e 100644 --- a/Assets/Models/Maps/222/222.lua +++ b/Assets/Models/Maps/222/222.lua @@ -1,4 +1,7 @@ map = { + lights = { + {type = 3, color = {x = .9, y = .9, z = .9}}, + }, numWaterBodies = 0, size = {x = 123.000000, y = 100, z = 123.000000}, impassibleNodeValue = 65535, diff --git a/Assets/Models/Maps/water/water.lua b/Assets/Models/Maps/water/water.lua index c8dce7a..9538429 100644 --- a/Assets/Models/Maps/water/water.lua +++ b/Assets/Models/Maps/water/water.lua @@ -1,4 +1,7 @@ map = { + lights = { + {type = 3, color = {x = .9, y = .9, z = .9}}, + }, numWaterBodies = 1, size = {x = 1000.000000, y = 100, z = 1000.000000}, impassibleNodeValue = 65535, @@ -11,7 +14,8 @@ players = { resourceDeposits = { }, units = { - {id = UnitId.TANK, pos = {x = -300.000000, y = 0.000000, z = -50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + {id = UnitId.TANK, pos = {x = 300.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + {id = UnitId.LAB, pos = {x = 300.000000, y = 0.000000, z = 100.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, --{id = UnitId.ENGINEER, pos = {x = -10.000000, y = 0.000000, z = -10.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, --{id = UnitId.POINT_DEFENSE, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, } @@ -19,21 +23,21 @@ units = { { resourceDeposits = {}, units = { - {id = UnitId.WAR_MECH, pos = {x = 300.000000, y = 0.000000, z = 12.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.TANK, pos = {x = 400.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.POINT_DEFENSE, pos = {x = 400.000000, y = 0.000000, z = 20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, - {id = UnitId.SCOUT_TRANSPORT, pos = {x = 400.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + {id = UnitId.WAR_MECH, pos = {x = 300.000000, y = 0.000000, z = 220.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.TANK, pos = {x = 400.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.POINT_DEFENSE, pos = {x = 400.000000, y = 0.000000, z = 20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, + --{id = UnitId.SCOUT_TRANSPORT, pos = {x = 400.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, {id = UnitId.ENGINEER, pos = {x = 450.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.TACTICAL_CRUISER, pos = {x = -60.000000, y = 0.000000, z = -80.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.CHEAP_CRUISER, pos = {x = -60.000000, y = 0.000000, z = -30.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.DEFENSIVE_CRUISER, pos = {x = -60.00000, y = 0.000000, z = 20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.TRANSPORT_CRUISER, pos = {x = -60.00000, y = 0.000000, z = 60.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.CHAMPION_CARRIER, pos = {x = -80.00000, y = 0.000000, z = -80.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.HEAVY_CARRIER, pos = {x = 0.00000, y = 0.000000, z = -80.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.SCOUT_TRANSPORT, pos = {x = 30.00000, y = 0.000000, z = -80.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.HOVER_TRANSPORT, pos = {x = 60.00000, y = 0.000000, z = -80.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.MISSILE_SUBMARINE, pos = {x = -40.00000, y = 0.000000, z = -50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, - {id = UnitId.STEALTH_SUBMARINE, pos = {x = -40.00000, y = 0.000000, z = 20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.TACTICAL_CRUISER, pos = {x = -60.000000, y = 0.000000, z = -80.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.CHEAP_CRUISER, pos = {x = -60.000000, y = 0.000000, z = -30.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.DEFENSIVE_CRUISER, pos = {x = -60.00000, y = 0.000000, z = 20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.TRANSPORT_CRUISER, pos = {x = -60.00000, y = 0.000000, z = 60.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.CHAMPION_CARRIER, pos = {x = -80.00000, y = 0.000000, z = -80.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.HEAVY_CARRIER, pos = {x = 0.00000, y = 0.000000, z = -80.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.SCOUT_TRANSPORT, pos = {x = 30.00000, y = 0.000000, z = -80.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.HOVER_TRANSPORT, pos = {x = 60.00000, y = 0.000000, z = -80.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.MISSILE_SUBMARINE, pos = {x = -40.00000, y = 0.000000, z = -50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, + --{id = UnitId.STEALTH_SUBMARINE, pos = {x = -40.00000, y = 0.000000, z = 20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}}, --{id = UnitId.EXTRACTOR, pos = {x = 30.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, --{id = UnitId.LAB, pos = {x = 50.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100}, } diff --git a/mapEditorAppState.cpp b/mapEditorAppState.cpp index 9f8d642..1fba0f7 100644 --- a/mapEditorAppState.cpp +++ b/mapEditorAppState.cpp @@ -398,7 +398,7 @@ namespace battleship{ string mapScript = "map = {\nlights = {\n"; for(Node *light : map->getLights()){ - mapScript += "{type = " + to_string((int)light->getLight(0)->getType()); + mapScript += "{type = " + to_string((int)light->getLight(0)->getLightType()); if(light->getLight(0)->getLightType() == Light::Type::DIRECTIONAL){ Vector3 dir = light->getGlobalAxis(2); From fff48459feeeb92461ab0e875f0b9c0f94ac8285 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Sun, 15 Sep 2024 14:21:24 +0300 Subject: [PATCH 09/11] cursors and attack orders only work on visible units --- activeGameState.cpp | 4 +++- unit.h | 1 - vehicle.cpp | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/activeGameState.cpp b/activeGameState.cpp index 91c5de9..5d01910 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -225,6 +225,8 @@ namespace battleship{ } bool ActiveGameState::isGameObjSelectable(GameObject *obj, bool useDragBox){ + if(!obj->getModel()->isVisible()) return false; + Node *hitboxNode = obj->getHitbox(); Box *hitbox = (Box*)hitboxNode->getMesh(0); @@ -332,7 +334,7 @@ namespace battleship{ vector selUnits = mainPlayer->getSelectedUnits(); for (Unit *u : units) { - Node *model = u->getNode(); + Node *model = u->getModel(); if (u->getPlayer() == mainPlayer){ if(!u->getLosLightNode()) u->initLosLight(); diff --git a/unit.h b/unit.h index ada7f0d..eaa0725 100755 --- a/unit.h +++ b/unit.h @@ -146,7 +146,6 @@ namespace battleship{ inline int getNumGarrisonSlots(){return garrisonSlots.size();} inline const std::vector& getGarrisonSlots(){return garrisonSlots;} inline float getLineOfSight() {return lineOfSight;} - inline vb01::Model* getNode() {return model;} inline UnitType getType() {return type;} inline UnitClass getUnitClass() {return unitClass;} inline void takeDamage(int damage) {health -= damage;} diff --git a/vehicle.cpp b/vehicle.cpp index 8f7edb4..6a68d11 100644 --- a/vehicle.cpp +++ b/vehicle.cpp @@ -35,7 +35,7 @@ namespace battleship{ void Vehicle::update(){ Unit::update(); - model->setVisible(!garrisonable); + if(garrisonable) model->setVisible(false); } void Vehicle::halt(){ From e37526cd5c89bb735b14cf58dcc826a8f43dbbe3 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Thu, 26 Sep 2024 20:12:13 +0300 Subject: [PATCH 10/11] updated map models --- Assets/Models/Maps/111/111.xml | 2 +- Assets/Models/Maps/222/222.xml | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/Assets/Models/Maps/111/111.xml b/Assets/Models/Maps/111/111.xml index 5cea7e8..7dc7090 100644 --- a/Assets/Models/Maps/111/111.xml +++ b/Assets/Models/Maps/111/111.xml @@ -1,6 +1,6 @@ - + diff --git a/Assets/Models/Maps/222/222.xml b/Assets/Models/Maps/222/222.xml index 3ef5996..ac6632d 100644 --- a/Assets/Models/Maps/222/222.xml +++ b/Assets/Models/Maps/222/222.xml @@ -1,6 +1,6 @@ - + From f5a9739ac1b3d16f83f1bda9375f0f53e6130084 Mon Sep 17 00:00:00 2001 From: devZoGok Date: Thu, 26 Sep 2024 20:30:59 +0300 Subject: [PATCH 11/11] updated vb01 --- external/vb01 | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/external/vb01 b/external/vb01 index 39dc1af..63990e0 160000 --- a/external/vb01 +++ b/external/vb01 @@ -1 +1 @@ -Subproject commit 39dc1afd25c12290e8e49b1df56a4e474c13ad47 +Subproject commit 63990e0ef015c32977e2b42e3d22aa91d77953a5