From 94ee44674105e5843a4dbd5b04a5ea1e30bd6f0d Mon Sep 17 00:00:00 2001 From: devZoGok Date: Wed, 14 May 2025 19:34:01 +0300 Subject: [PATCH] implemented shells --- .../Projectiles/projectileData.lua | 18 ++++++++- Assets/Scripts/GameObjects/Units/unitData.lua | 19 ++++----- CMakeLists.txt | 5 ++- activeGameState.cpp | 2 +- cruiseMissile.cpp | 17 +++----- cruiseMissile.h | 2 +- gameObject.cpp | 5 ++- gameObjectFactory.cpp | 5 ++- projectile.cpp | 18 +++++---- projectile.h | 4 +- shell.cpp | 39 +++++++++++++++++++ shell.h | 19 +++++++++ unit.cpp | 2 +- 13 files changed, 116 insertions(+), 39 deletions(-) create mode 100644 shell.cpp create mode 100644 shell.h diff --git a/Assets/Scripts/GameObjects/Projectiles/projectileData.lua b/Assets/Scripts/GameObjects/Projectiles/projectileData.lua index 8e4f2f0..0682ccd 100644 --- a/Assets/Scripts/GameObjects/Projectiles/projectileData.lua +++ b/Assets/Scripts/GameObjects/Projectiles/projectileData.lua @@ -1,7 +1,21 @@ -ProjectileId = {CRUISE_MISSILE = 0, TORPEDO = 1} -ProjectileClass = {CRUISE_MISSILE = 0, TORPEDO = 1} +ProjectileId = {SHELL = 0, CRUISE_MISSILE = 1, TORPEDO = 2} +ProjectileClass = {SHELL = 0, CRUISE_MISSILE = 1, TORPEDO = 2} +G = 9.8 projectiles = { + { + projectileClass = ProjectileClass.SHELL, + size = {x = 1, y = 1, z = 1}, + speed = 5, + rotAngle = .1, + explosion = {damage = 100, radius = 20, sfx = PATH .. 'Sounds/SFX/Explosions/explosion02.ogg'}, + directHitDamage = 200, + rayLength = 1, + name = "Shell", + basePath = PATH .. "Models/GameObjects/Projectiles/Shells/", + meshPath = "shell.xml", + albedoPath = 'shell.jpg' + }, { projectileClass = ProjectileClass.CRUISE_MISSILE, size = {x = 6, y = 13.5, z = 2.54}, diff --git a/Assets/Scripts/GameObjects/Units/unitData.lua b/Assets/Scripts/GameObjects/Units/unitData.lua index fe09445..aa0e210 100644 --- a/Assets/Scripts/GameObjects/Units/unitData.lua +++ b/Assets/Scripts/GameObjects/Units/unitData.lua @@ -160,11 +160,17 @@ units = { { weapons = { { - type = WeaponClass.HITSCAN, + type = WeaponClass.SHELL, + projectile = {id = ProjectileId.SHELL, pos = {x = 0.06, y = 5.82, z = 11.4}, rot = {w = 1, x = 0, y = 0, z = 0}}, rateOfFire = 1000, damage = 200, maxRange = 25, fireFx = { + { + vfx = false, + duration = 300, + path = PATH .. 'Sounds/Units/Tanks/attack.ogg', + }, { vfx = true, duration = 50, @@ -172,19 +178,14 @@ units = { path = PATH .. vfxPrefix .. 'muzzleFlash.xml', color = {x = 1, y = 1, z = 0, a = 1}, }, - parent = 'Turret', + parent = 'CannonBarrel', pos = {x = 0.06, y = 5.82, z = 11.4}, rot = {w = 1, x = 0, y = 0, z = 0}, --scale = .5 - }, - { - vfx = false, - duration = 300, - path = PATH .. 'Sounds/Units/Tanks/attack.ogg', } }, - landHitFx = {explosionVfx, explosionSfx}, - unitHitFx = {explosionVfx, explosionSfx} + --landHitFx = {explosionVfx, explosionSfx}, + --unitHitFx = {explosionVfx, explosionSfx} } }, unitClass = UnitClass.TANK, diff --git a/CMakeLists.txt b/CMakeLists.txt index f8c479b..4acbc9b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required(VERSION 2.9) +cmake_minimum_required(VERSION 3.5) set(GAME_NAME battleship) project(${GAME_NAME}) @@ -10,6 +10,7 @@ else() endif() set(CMAKE_CXX_STANDART 17) +set(CMAKE_POLICY_VERSION_MINIMUM 3.5) set(CMAKE_BUILD_TYPE Debug) set(BUILD_TESTS ON) set(BUILD_SHARED_LIBS OFF CACHE BOOL FORCED) @@ -30,7 +31,7 @@ set(UTIL util.cpp binds.h) set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp) set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp toggleDebugCommand.cpp) set(CORE gameManager.cpp game.cpp fxManager.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS}) -set(PROJECTILES projectile.cpp cruiseMissile.cpp) +set(PROJECTILES projectile.cpp cruiseMissile.cpp shell.cpp) set(VEHICLES vehicle.cpp engineer.cpp resourceRover.cpp) set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp researchStruct.cpp) set(UNITS gameObjectFactory.cpp unit.cpp ${STRUCTURES} ${VEHICLES}) diff --git a/activeGameState.cpp b/activeGameState.cpp index 397a4e0..fae80c5 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -204,7 +204,7 @@ namespace battleship{ cursorState = (unloadFlag ? CursorState::UNLOAD : CursorState::LOAD); } - else if(gameObjUnit && !(ownGameObj || alliedGameObj)) + else if(controlPressed || gameObjUnit && !(ownGameObj || alliedGameObj)) cursorState = CursorState::ATTACK; else cursorState = CursorState::NORMAL; diff --git a/cruiseMissile.cpp b/cruiseMissile.cpp index e4014b0..1879420 100644 --- a/cruiseMissile.cpp +++ b/cruiseMissile.cpp @@ -47,19 +47,8 @@ namespace battleship{ flightStage = FlightStage::DESCENT; } - void CruiseMissile::checkSurfaceCollision(){ - Map *map = Map::getSingleton(); - int cellId = map->getCellId(pos, false); - - if((pos + dirVec * rayLength).y <= map->getCells()[cellId].pos.y){ - Game::getSingleton()->explode(pos, explosionDamage, explosionRadius, explosionSfx); - remove = true; - } - } - void CruiseMissile::update(){ - GameObject::update(); - placeAt(pos + dirVec * speed); + Projectile::update(); switch(flightStage){ case FlightStage::ASCENT: @@ -73,6 +62,10 @@ namespace battleship{ break; } + checkCollision(); + } + + void CruiseMissile::checkCollision(){ if(!remove && flightStage == FlightStage::DESCENT){ checkSurfaceCollision(); if(remove) return; diff --git a/cruiseMissile.h b/cruiseMissile.h index b7b84d9..30a805e 100644 --- a/cruiseMissile.h +++ b/cruiseMissile.h @@ -15,7 +15,7 @@ namespace battleship{ void pitch(float, vb01::Vector3); void cruise(); - void checkSurfaceCollision(); + void checkCollision(); }; } diff --git a/gameObject.cpp b/gameObject.cpp index ebd5b64..87526ed 100644 --- a/gameObject.cpp +++ b/gameObject.cpp @@ -45,8 +45,11 @@ namespace battleship{ } void GameObject::orientAt(Quaternion rotQuat){ - model->setOrientation(rotQuat); rot = rotQuat; + model->setOrientation(rotQuat); + leftVec = model->getGlobalAxis(0); + upVec = model->getGlobalAxis(1); + dirVec = model->getGlobalAxis(2); } //TODO remove neccessity to create a material for an invisible mesh diff --git a/gameObjectFactory.cpp b/gameObjectFactory.cpp index 1e91069..9833bf1 100644 --- a/gameObjectFactory.cpp +++ b/gameObjectFactory.cpp @@ -7,8 +7,9 @@ #include "resourceDeposit.h" #include "pointDefense.h" #include "extractor.h" -#include "cruiseMissile.h" #include "researchStruct.h" +#include "cruiseMissile.h" +#include "shell.h" #include "defConfigs.h" #include @@ -52,6 +53,8 @@ namespace battleship{ int projectileClass = SOL_LUA_VIEW["projectiles"][id + 1]["projectileClass"]; switch((ProjectileClass)projectileClass){ + case ProjectileClass::SHELL: + return new Shell(unit, id, pos, rot); case ProjectileClass::CRUISE_MISSILE: { Order::Target target = unit->getOrder(0).targets[0]; diff --git a/projectile.cpp b/projectile.cpp index 87b8bcd..8298576 100755 --- a/projectile.cpp +++ b/projectile.cpp @@ -73,12 +73,6 @@ namespace battleship{ void Projectile::update() { GameObject::update(); placeAt(pos + speed * dirVec); - - if(!remove){ - checkSurfaceCollision(); - if(remove) return; - checkUnitCollision(); - } } void Projectile::checkUnitCollision(){ @@ -112,8 +106,18 @@ namespace battleship{ Map *map = Map::getSingleton(); int cellId = map->getCellId(pos, false); - if(map->getCells()[cellId].type == Map::Cell::LAND) + if((pos + dirVec * rayLength).y <= map->getCells()[cellId].pos.y){ + Game::getSingleton()->explode(pos, explosionDamage, explosionRadius, explosionSfx); remove = true; + } + } + + void Projectile::checkCollision(){ + if(!remove){ + checkSurfaceCollision(); + if(remove) return; + checkUnitCollision(); + } } void Projectile::debug(){ diff --git a/projectile.h b/projectile.h index 0062ddf..223c7ba 100755 --- a/projectile.h +++ b/projectile.h @@ -12,7 +12,7 @@ namespace vb01{ } namespace battleship { - enum class ProjectileClass{CRUISE_MISSILE, TORPEDO}; + enum class ProjectileClass{SHELL, CRUISE_MISSILE, TORPEDO}; class Unit; class Projectile : public GameObject{ @@ -24,11 +24,11 @@ namespace battleship { private: void initProperties(); void initSound(); - void checkCollision(); protected: virtual void reinit(); virtual void checkUnitCollision(); virtual void checkSurfaceCollision(); + void checkCollision(); float speed, rayLength, explosionRadius, rotAngle; int directHitDamage, explosionDamage; diff --git a/shell.cpp b/shell.cpp new file mode 100644 index 0000000..c765fbb --- /dev/null +++ b/shell.cpp @@ -0,0 +1,39 @@ +#include "shell.h" + +#include + +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace gameBase; + + Shell::Shell(Unit *un, int id, Vector3 pos, Quaternion rot) : + Projectile(un, id, pos, rot), + initTime(getTime()) + { + initDir = dirVec; + } + + void Shell::update(){ + float currTime = float(getTime() - initTime) / 1000; + + if(currTime == 0) return; + + const float G = generateView()["G"]; + float angle = initDir.getAngleBetween(Vector3(initDir.x, 0, initDir.z).norm()); + + dirVec = ( + pos + + speed * currTime * cos(angle) * Vector3(initDir.x, 0, initDir.z).norm() + + (currTime * speed * sin(angle) - G * currTime * currTime) * Vector3::VEC_J - + pos + ).norm(); + upVec = Quaternion(-PI / 2, leftVec) * dirVec; + model->lookAt(dirVec, upVec); + + Projectile::update(); + checkCollision(); + } +} diff --git a/shell.h b/shell.h new file mode 100644 index 0000000..3b73877 --- /dev/null +++ b/shell.h @@ -0,0 +1,19 @@ +#ifndef SHELL_H +#define SHELL_H + +#include "projectile.h" + +#include + +namespace battleship{ + class Shell : public Projectile{ + public: + Shell(Unit*, int, vb01::Vector3, vb01::Quaternion); + void update(); + private: + vb01::s64 initTime; + vb01::Vector3 initDir; + }; +} + +#endif diff --git a/unit.cpp b/unit.cpp index 587c0cd..18c1fe1 100755 --- a/unit.cpp +++ b/unit.cpp @@ -279,7 +279,7 @@ namespace battleship{ Vector3 upVec = unit->getUpVec(); Vector3 dirVec = unit->getDirVec(); Vector3 p = unit->getPos() + leftVec * projPos.x + upVec * projPos.y + dirVec * projPos.z; - Quaternion r = unit->getRot() * projRot; + Quaternion r = projRot * unit->getRot(); unit->getPlayer()->addProjectile(GameObjectFactory::createProjectile(unit, projId, p, r)); }