dropping depth charges

This commit is contained in:
devZoGok
2026-01-28 19:12:51 +02:00
parent 5e93806088
commit f70532788a
11 changed files with 151 additions and 24 deletions
@@ -1,5 +1,5 @@
ProjectileId = {HE_SHELL = 0, EMP_SHELL = 1, CRUISE_MISSILE = 2, MISSILE = 3, TORPEDO = 4} ProjectileId = {HE_SHELL = 0, EMP_SHELL = 1, CRUISE_MISSILE = 2, MISSILE = 3, TORPEDO = 4, DEPTH_CHARGE = 5}
ProjectileClass = {SHELL = 0, CRUISE_MISSILE = 1, MISSILE = 2, TORPEDO = 3} ProjectileClass = {SHELL = 0, CRUISE_MISSILE = 1, MISSILE = 2, TORPEDO = 3, DEPTH_CHARGE = 4}
G = 9.8 G = 9.8
explosionVfx = { explosionVfx = {
@@ -20,7 +20,7 @@ explosionSfx = {
path = PATH .. 'Sounds/SFX/Explosions/explosion02.ogg', path = PATH .. 'Sounds/SFX/Explosions/explosion02.ogg',
duration = 2500 duration = 2500
} }
Detonation = {EXPLOSION = 0, EMP = 1, CRYO = 2} Detonation = {EXPLOSION = 0, EMP = 1, CRYO = 2, UNDERWATER = 3}
projectiles = { projectiles = {
{ {
@@ -81,12 +81,24 @@ projectiles = {
projectileClass = ProjectileClass.TORPEDO, projectileClass = ProjectileClass.TORPEDO,
size = {x = 1, y = 6, z = 1}, size = {x = 1, y = 6, z = 1},
speed = .06, speed = .06,
explosion = {detonation = Detonation.EXPLOSION, damage = 20, radius = 3, fx = {explosionVfx, explosionSfx}}, explosion = {detonation = Detonation.UNDERWATER, damage = 20, radius = 3, fx = {explosionVfx, explosionSfx}},
directHitDamage = 450, directHitDamage = 450,
rayLength = 3.5, rayLength = 3.5,
name = "Torpedo", name = "Torpedo",
basePath = PATH .. "Models/GameObjects/Projectiles/Torpedos/", basePath = PATH .. "Models/GameObjects/Projectiles/Torpedos/",
meshPath = "torpedo.xml", meshPath = "torpedo.xml",
albedoPath = 'torpedo.jpg' albedoPath = 'torpedo.jpg'
},
{
projectileClass = ProjectileClass.DEPTH_CHARGE,
size = {x = 5.3, y = 5.3, z = 5.8},
speed = .06,
explosion = {detonation = Detonation.UNDERWATER, damage = 20, radius = 3, fx = {explosionVfx, explosionSfx}},
directHitDamage = 450,
rayLength = 3.5,
name = "Depth charge",
basePath = PATH .. "Models/GameObjects/Projectiles/DepthCharges/",
meshPath = "depthCharge.xml",
albedoPath = 'depthCharge.jpg'
} }
} }
+27 -10
View File
@@ -200,6 +200,7 @@ units = {
rateOfFire = 100, rateOfFire = 100,
maxRange = 14, maxRange = 14,
damage = 50, damage = 50,
maxFireAngle = .15,
fireFx = { fireFx = {
{ {
vfx = true, vfx = true,
@@ -260,7 +261,7 @@ units = {
selectionSfx = PATH .. 'Sounds/Units/WarMechs/selection.ogg', selectionSfx = PATH .. 'Sounds/Units/WarMechs/selection.ogg',
speed = .3, speed = .3,
destinationOffset = .1, destinationOffset = .1,
anglePrecision = .1, anglePrecision = .01,
maxTurnAngle = .1, maxTurnAngle = .1,
garrisonCategory = 1, garrisonCategory = 1,
deathFx = {explosionVfx, explosionSfx}, deathFx = {explosionVfx, explosionSfx},
@@ -623,7 +624,7 @@ units = {
colorNodes = {'barrel'}, colorNodes = {'barrel'},
selectionSfx = PATH .. 'Sounds/Units/Tanks/selection.ogg', selectionSfx = PATH .. 'Sounds/Units/Tanks/selection.ogg',
speed = .3, speed = .3,
destinationOffset = .1, destinationOffset = .01,
anglePrecision = .1, anglePrecision = .1,
maxTurnAngle = .1, maxTurnAngle = .1,
garrisonCategory = 2, garrisonCategory = 2,
@@ -1199,7 +1200,7 @@ units = {
meshPath = 'acsCargoShip.xml', meshPath = 'acsCargoShip.xml',
albedoPath = 'cargoship.jpg', albedoPath = 'cargoship.jpg',
selectionSfx = PATH .. 'Sounds/Units/Cargoships/selection.ogg', selectionSfx = PATH .. 'Sounds/Units/Cargoships/selection.ogg',
speed = .1, speed = .3,
destinationOffset = .1, destinationOffset = .1,
anglePrecision = .1, anglePrecision = .1,
maxTurnAngle = .1, maxTurnAngle = .1,
@@ -1234,7 +1235,7 @@ units = {
meshPath = 'aincCargoShip.xml', meshPath = 'aincCargoShip.xml',
albedoPath = 'cargoship.jpg', albedoPath = 'cargoship.jpg',
selectionSfx = PATH .. 'Sounds/Units/Cargoships/selection.ogg', selectionSfx = PATH .. 'Sounds/Units/Cargoships/selection.ogg',
speed = .1, speed = .3,
destinationOffset = .1, destinationOffset = .1,
anglePrecision = .1, anglePrecision = .1,
maxTurnAngle = .1, maxTurnAngle = .1,
@@ -1269,7 +1270,7 @@ units = {
meshPath = 'erCargoShip.xml', meshPath = 'erCargoShip.xml',
albedoPath = 'cargoship.jpg', albedoPath = 'cargoship.jpg',
selectionSfx = PATH .. 'Sounds/Units/Cargoships/selection.ogg', selectionSfx = PATH .. 'Sounds/Units/Cargoships/selection.ogg',
speed = .1, speed = .3,
destinationOffset = .1, destinationOffset = .1,
anglePrecision = .1, anglePrecision = .1,
maxTurnAngle = .1, maxTurnAngle = .1,
@@ -1607,10 +1608,25 @@ units = {
}, },
{ {
weapons = { weapons = {
{
orderType = OrderType.ATTACK,
rateOfFire = 2000,
damage = 10,
maxRange = 100,
targetUnits = {UnitType.UNDERWATER},
targetProjectiles = {},
fireDir = {x = 0, y = -1, z = 0},
projectile = {id = ProjectileId.DEPTH_CHARGE, parent = 'hull', pos = {x = 0, y = -2, z = 0}, rot = {w = .707, x = .707, y = 0, z = 0}},
fireFx = {
{vfx = false, duration = 50, path = PATH .. 'Sounds/Units/Submarines/fire.ogg'}
},
hitFx = {}
},
{ {
orderType = OrderType.ATTACK, orderType = OrderType.ATTACK,
rateOfFire = 200, rateOfFire = 200,
damage = 10, damage = 10,
minRange = 10,
maxRange = 100, maxRange = 100,
nodes = { nodes = {
{name = 'FrontTurret', rotationSpeed = .05, angleConstraints = {min = -2.53, max = 2.53}, vertical = false}, {name = 'FrontTurret', rotationSpeed = .05, angleConstraints = {min = -2.53, max = 2.53}, vertical = false},
@@ -1634,6 +1650,7 @@ units = {
orderType = OrderType.ATTACK, orderType = OrderType.ATTACK,
rateOfFire = 200, rateOfFire = 200,
damage = 10, damage = 10,
minRange = 10,
maxRange = 100, maxRange = 100,
nodes = { nodes = {
{name = 'RearTurret', rotationSpeed = .05, angleConstraints = {min = -2.53, max = 2.53}, vertical = false}, {name = 'RearTurret', rotationSpeed = .05, angleConstraints = {min = -2.53, max = 2.53}, vertical = false},
@@ -1663,14 +1680,14 @@ units = {
cost = 500, cost = 500,
size = {x = 6.93, y = 17.7, z = 76.1}, size = {x = 6.93, y = 17.7, z = 76.1},
hitboxOffset = {x = 0, y = 4.77, z = 0}, hitboxOffset = {x = 0, y = 4.77, z = 0},
lineOfSight = 5, lineOfSight = 100,
colorNodes = {'FrontTurret', 'RearTurret'}, colorNodes = {'FrontTurret', 'RearTurret'},
name = 'Anti sub cruiser', name = 'Anti sub cruiser',
basePath = PATH .. vehiclePrefix .. 'Cruisers/', basePath = PATH .. vehiclePrefix .. 'Cruisers/',
meshPath = 'acsAntiSubCruiser.xml', meshPath = 'acsAntiSubCruiser.xml',
albedoPath = 'cruiser.jpg', albedoPath = 'cruiser.jpg',
selectionSfx = PATH .. 'Sounds/Units/Cruisers/selection.ogg', selectionSfx = PATH .. 'Sounds/Units/Cruisers/selection.ogg',
speed = .1, speed = .3,
destinationOffset = .1, destinationOffset = .1,
anglePrecision = .1, anglePrecision = .1,
maxTurnAngle = .1, maxTurnAngle = .1,
@@ -2120,7 +2137,7 @@ units = {
cost = 500, cost = 500,
size = {x = 9.29, y = 11.6, z = 32.9}, size = {x = 9.29, y = 11.6, z = 32.9},
hitboxOffset = {x = 0, y = 1.8, z = -1.3}, hitboxOffset = {x = 0, y = 1.8, z = -1.3},
lineOfSight = 5, lineOfSight = 0,
name = 'Stealth submarine', name = 'Stealth submarine',
colorNodes = {'Cube.001'}, colorNodes = {'Cube.001'},
basePath = PATH .. vehiclePrefix .. 'Submarines/', basePath = PATH .. vehiclePrefix .. 'Submarines/',
@@ -2159,7 +2176,7 @@ units = {
cost = 500, cost = 500,
hitboxOffset = {x = 0, y = 1.83, z = -3.46}, hitboxOffset = {x = 0, y = 1.83, z = -3.46},
size = {x = 8.32, y = 12.1, z = 57.4}, size = {x = 8.32, y = 12.1, z = 57.4},
lineOfSight = 5, lineOfSight = 0,
name = 'Stealth submarine', name = 'Stealth submarine',
colorNodes = {'Cube.001'}, colorNodes = {'Cube.001'},
basePath = PATH .. vehiclePrefix .. 'Submarines/', basePath = PATH .. vehiclePrefix .. 'Submarines/',
@@ -2198,7 +2215,7 @@ units = {
cost = 500, cost = 500,
hitboxOffset = {x = 0, y = 1.03, z = -1.41}, hitboxOffset = {x = 0, y = 1.03, z = -1.41},
size = {x = 5.37, y = 7.66, z = 43}, size = {x = 5.37, y = 7.66, z = 43},
lineOfSight = 5, lineOfSight = 0,
name = 'Stealth submarine', name = 'Stealth submarine',
colorNodes = {'Sphere.001'}, colorNodes = {'Sphere.001'},
basePath = PATH .. vehiclePrefix .. 'Submarines/', basePath = PATH .. vehiclePrefix .. 'Submarines/',
+1 -1
View File
@@ -32,7 +32,7 @@ set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp)
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp toggleDebugCommand.cpp) set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp toggleDebugCommand.cpp)
set(CORE gameManager.cpp game.cpp pathfinder.cpp environment.cpp fxManager.cpp defConfigs.cpp player.cpp trader.cpp ${CONSOLE} ${CONTROLLERS}) set(CORE gameManager.cpp game.cpp pathfinder.cpp environment.cpp fxManager.cpp defConfigs.cpp player.cpp trader.cpp ${CONSOLE} ${CONTROLLERS})
set(PROJECTILES projectile.cpp missile.cpp cruiseMissile.cpp shell.cpp) set(PROJECTILES projectile.cpp missile.cpp cruiseMissile.cpp shell.cpp depthCharge.cpp)
set(VEHICLES vehicle.cpp submarine.cpp engineer.cpp resourceRover.cpp freezer.cpp) set(VEHICLES vehicle.cpp submarine.cpp engineer.cpp resourceRover.cpp freezer.cpp)
set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp researchStruct.cpp iceSheet.cpp) set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp researchStruct.cpp iceSheet.cpp)
set(WEAPONS weapon.cpp cryoGun.cpp) set(WEAPONS weapon.cpp cryoGun.cpp)
+13
View File
@@ -0,0 +1,13 @@
#include "depthCharge.h"
namespace battleship{
using namespace vb01;
DepthCharge::DepthCharge(Unit *un, int id, Vector3 pos, Quaternion rot) : Projectile(un, id, pos, rot){}
void DepthCharge::update(){
Projectile::update();
if(!remove) checkUnitCollision();
}
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef DEPTH_CHARGE_H
#define DEPTH_CHARGE_H
#include "projectile.h"
namespace battleship{
class DepthCharge : public Projectile{
public:
DepthCharge(Unit*, int, vb01::Vector3, vb01::Quaternion);
void update();
private:
};
}
#endif
+3
View File
@@ -14,6 +14,7 @@
#include "cruiseMissile.h" #include "cruiseMissile.h"
#include "iceSheet.h" #include "iceSheet.h"
#include "shell.h" #include "shell.h"
#include "depthCharge.h"
#include "defConfigs.h" #include "defConfigs.h"
#include <solUtil.h> #include <solUtil.h>
@@ -76,6 +77,8 @@ namespace battleship{
return new CruiseMissile(unit, id, targetPos, pos, rot); return new CruiseMissile(unit, id, targetPos, pos, rot);
case ProjectileClass::MISSILE: case ProjectileClass::MISSILE:
return new Missile(unit, id, targetPos, pos, rot); return new Missile(unit, id, targetPos, pos, rot);
case ProjectileClass::DEPTH_CHARGE:
return new DepthCharge(unit, id, pos, rot);
default: default:
return new Projectile(unit, id, pos, rot); return new Projectile(unit, id, pos, rot);
} }
+2 -2
View File
@@ -722,7 +722,7 @@ namespace battleship{
int numHorCells = int(mapSize.x / CELL_SIZE.x), horId = -1; int numHorCells = int(mapSize.x / CELL_SIZE.x), horId = -1;
for(int i = 0; i < numHorCells; i++) for(int i = 0; i < numHorCells; i++)
if(fabs(cells[i].pos.x - pos.x) < .5 * CELL_SIZE.x){ if(fabs(cells[i].pos.x - pos.x) <= .5 * CELL_SIZE.x){
horId = i; horId = i;
break; break;
} }
@@ -730,7 +730,7 @@ namespace battleship{
int numVertCells = int(mapSize.z / CELL_SIZE.z), vertId = -1; int numVertCells = int(mapSize.z / CELL_SIZE.z), vertId = -1;
for(int i = 0; i < numVertCells; i++) for(int i = 0; i < numVertCells; i++)
if(fabs(cells[i * numHorCells].pos.z - pos.z) < .5 * CELL_SIZE.z){ if(fabs(cells[i * numHorCells].pos.z - pos.z) <= .5 * CELL_SIZE.z){
vertId = i; vertId = i;
break; break;
} }
+1 -1
View File
@@ -13,7 +13,7 @@ namespace vb01{
namespace battleship { namespace battleship {
class Unit; class Unit;
enum class ProjectileClass{SHELL, CRUISE_MISSILE, MISSILE, TORPEDO}; enum class ProjectileClass{SHELL, CRUISE_MISSILE, MISSILE, TORPEDO, DEPTH_CHARGE};
class Projectile : public GameObject{ class Projectile : public GameObject{
public: public:
+28 -4
View File
@@ -374,15 +374,39 @@ namespace battleship{
targets.insert(targets.end(), targs.begin(), targs.end()); targets.insert(targets.end(), targs.begin(), targs.end());
} }
vector<Weapon*> attackWeapons = getWeaponsByOrder(Order::TYPE::ATTACK);
for(Order::Target &target : orders[0].targets) for(Order::Target &target : orders[0].targets)
if(target.unit){ if(target.unit){
if(find(targets.begin(), targets.end(), target.unit) != targets.end()) if(find(targets.begin(), targets.end(), target.unit) != targets.end()){
break; bool canAttack = false;
removeOrder(0); for(Weapon *aw : attackWeapons){
int tc;
switch(target.unit->getType()){
case GameObject::Type::UNIT:
tc = (int)((Unit*)target.unit)->getType();
break;
case GameObject::Type::PROJECTILE:
tc = (int)((Projectile*)target.unit)->getProjectileClass();
break;
}
if(aw->canAttackTarget((int)target.unit->getType(), tc)) canAttack = true;
}
if(!canAttack){
removeOrder(0);
return;
}
}
else{
removeOrder(0);
return;
}
} }
vector<Weapon*> attackWeapons = getWeaponsByOrder(Order::TYPE::ATTACK);
Vector3 targPos = (order.targets[0].unit ? order.targets[0].unit->getPos() : order.targets[0].pos); Vector3 targPos = (order.targets[0].unit ? order.targets[0].unit->getPos() : order.targets[0].pos);
for(Weapon *weapon : attackWeapons) for(Weapon *weapon : attackWeapons)
+41 -1
View File
@@ -28,6 +28,16 @@ namespace battleship{
maxFireAngle = weaponTable["maxFireAngle"].get_or(.1); maxFireAngle = weaponTable["maxFireAngle"].get_or(.1);
orderType = (Order::TYPE)weaponTable["orderType"]; orderType = (Order::TYPE)weaponTable["orderType"];
sol::optional<sol::table> fireDirOpt = weaponTable["fireDir"];
if(fireDirOpt != sol::nullopt){
sol::table fireDirTbl = weaponTable["fireDir"];
fireDir = Vector3((float)fireDirTbl["x"], (float)fireDirTbl["y"], (float)fireDirTbl["z"]);
}
initTargetData(targetUnits, weaponTable, "targetUnits", "UnitType");
initTargetData(targetProjectiles, weaponTable, "targetProjeciles", "ProjectileClass");
initProjectileData(weaponTable); initProjectileData(weaponTable);
initNodes(weaponTable); initNodes(weaponTable);
@@ -41,6 +51,19 @@ namespace battleship{
} }
} }
void Weapon::initTargetData(std::vector<int> &targetVec, sol::table weaponTable, string tblKey, string defTblKey){
sol::optional<sol::table> unitTblOpt = weaponTable[tblKey];
sol::table tbl;
if(unitTblOpt != sol::nullopt) tbl = weaponTable[tblKey];
else tbl = generateView()[defTblKey];
int tblSize = tbl.size();
for(int i = 0; i < tblSize; i++)
targetVec.push_back((int)tbl[i + 1]);
}
void Weapon::initNodes(sol::table weaponTable){ void Weapon::initNodes(sol::table weaponTable){
sol::optional<sol::table> nodesTblOpt = weaponTable["nodes"]; sol::optional<sol::table> nodesTblOpt = weaponTable["nodes"];
@@ -136,7 +159,13 @@ namespace battleship{
Vector3 refPos = (isWeaponPos ? components[0].node->localToGlobalPosition(Vector3::VEC_ZERO) : unit->getPos()); Vector3 refPos = (isWeaponPos ? components[0].node->localToGlobalPosition(Vector3::VEC_ZERO) : unit->getPos());
if(ordTp == (int)orderType){ if(ordTp == (int)orderType){
Vector3 dirVec = (isWeaponPos ? components[components.size() - 1].node->getGlobalAxis(2) : unit->getDirVec()); Vector3 dirVec;
if(!isWeaponPos)
dirVec = (fireDir.x * unit->getLeftVec() + fireDir.y * unit->getUpVec() + fireDir.z * unit->getDirVec()).norm();
else
dirVec = components[components.size() - 1].node->getGlobalAxis(2);
bool aimedAtTarget = false; bool aimedAtTarget = false;
if(targDestruct && targDestruct->getHitbox()){ if(targDestruct && targDestruct->getHitbox()){
@@ -306,4 +335,15 @@ namespace battleship{
component.node->setOrientation(rot); component.node->setOrientation(rot);
} }
} }
bool Weapon::canAttackTarget(int objType, int typeOrClass){
switch((GameObject::Type)objType){
case GameObject::Type::UNIT:
return (find(targetUnits.begin(), targetUnits.end(), typeOrClass) != targetUnits.end());
case GameObject::Type::PROJECTILE:
return (find(targetProjectiles.begin(), targetProjectiles.end(), typeOrClass) != targetProjectiles.end());
}
return true;
}
} }
+4 -1
View File
@@ -40,6 +40,7 @@ namespace battleship{
virtual void update(); virtual void update();
virtual void fire(Order); virtual void fire(Order);
void trackTarget(vb01::Vector3); void trackTarget(vb01::Vector3);
bool canAttackTarget(int, int);
inline int getProjectileId(){return projId;} inline int getProjectileId(){return projId;}
inline int getRateOfFire(){return rateOfFire;} inline int getRateOfFire(){return rateOfFire;}
inline int getDamage(){return damage;} inline int getDamage(){return damage;}
@@ -51,14 +52,16 @@ namespace battleship{
Unit *unit = nullptr; Unit *unit = nullptr;
Order::TYPE orderType; Order::TYPE orderType;
int id, projId = -1, damage = 0; int id, projId = -1, damage = 0;
std::vector<int> targetUnits, targetProjectiles;
float minRange = 0, maxRange, maxFireAngle; float minRange = 0, maxRange, maxFireAngle;
vb01::s64 lastFireTime = 0; vb01::s64 lastFireTime = 0;
FxManager::Fx *fireFx = nullptr; FxManager::Fx *fireFx = nullptr;
vb01::Quaternion projRot; vb01::Quaternion projRot;
vb01::Vector3 projPos, initUnitSpaceDir; vb01::Vector3 projPos, initUnitSpaceDir, fireDir = vb01::Vector3::VEC_K;
vb01::Node *projPar = nullptr; vb01::Node *projPar = nullptr;
static std::string LASER_FLAG; static std::string LASER_FLAG;
void initTargetData(std::vector<int>&, sol::table, std::string, std::string);
void initProjectileData(sol::table); void initProjectileData(sol::table);
void initNodes(sol::table); void initNodes(sol::table);
void useFx(FxManager::Fx*, vb01::Vector3, bool); void useFx(FxManager::Fx*, vb01::Vector3, bool);