removing projectiles if they go out of map bounds

This commit is contained in:
devZoGok
2026-02-01 10:26:54 +02:00
parent bd12a393b8
commit 0770d64784
10 changed files with 74 additions and 18 deletions
+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 depthCharge.cpp) set(PROJECTILES projectile.cpp missile.cpp cruiseMissile.cpp shell.cpp depthCharge.cpp torpedo.cpp torpedo.h)
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) set(WEAPONS weapon.cpp)
+5 -2
View File
@@ -72,7 +72,10 @@ namespace battleship{
break; break;
} }
if(flightStage == FlightStage::DESCENT) if(flightStage == FlightStage::DESCENT && !remove){
Projectile::checkCollision(); checkSurfaceCollision(false);
if(remove) return;
checkUnitCollision();
}
} }
} }
+5 -1
View File
@@ -8,6 +8,10 @@ namespace battleship{
void DepthCharge::update(){ void DepthCharge::update(){
Projectile::update(); Projectile::update();
if(!remove) checkUnitCollision(); if(!remove){
checkSurfaceCollision(true);
if(remove) return;
checkUnitCollision();
}
} }
} }
+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 "torpedo.h"
#include "depthCharge.h" #include "depthCharge.h"
#include "defConfigs.h" #include "defConfigs.h"
@@ -77,6 +78,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::TORPEDO:
return new Torpedo(unit, id, pos, rot);
case ProjectileClass::DEPTH_CHARGE: case ProjectileClass::DEPTH_CHARGE:
return new DepthCharge(unit, id, pos, rot); return new DepthCharge(unit, id, pos, rot);
default: default:
+6 -1
View File
@@ -22,6 +22,11 @@ namespace battleship{
Projectile::update(); Projectile::update();
destructable->update(); destructable->update();
checkCollision();
if(!remove){
checkSurfaceCollision(false);
if(remove) return;
checkUnitCollision();
}
} }
} }
+15 -10
View File
@@ -105,20 +105,25 @@ namespace battleship{
detonate(targetUnits[i]); detonate(targetUnits[i]);
} }
void Projectile::checkSurfaceCollision(){ //TODO fix map boundary checks
void Projectile::checkSurfaceCollision(bool useBottomCell){
Map *map = Map::getSingleton(); Map *map = Map::getSingleton();
vector<Map::Cell> &cells = map->getCells();
int cellId = map->getCellId(pos, false); int cellId = map->getCellId(pos, false);
Vector3 mapSize = map->getMapSize();
if((pos + dirVec * rayLength).y <= map->getCells()[cellId].pos.y) if(cellId < 0 || fabs(pos.x) > .5 * mapSize.x || fabs(pos.z) > .5 * mapSize.z){
detonate(); remove = true;
} return;
void Projectile::checkCollision(){
if(!remove){
checkSurfaceCollision();
if(remove) return;
checkUnitCollision();
} }
if(useBottomCell && !cells[cellId].underWaterCellIds.empty()){
int numUnderwaterCells = cells[cellId].underWaterCellIds.size();
cellId = cells[cellId].underWaterCellIds[numUnderwaterCells - 1];
}
if((pos + dirVec * rayLength).y <= cells[cellId].pos.y + .5 * map->getCellSize().y)
detonate();
} }
void Projectile::debug(){ void Projectile::debug(){
+1 -2
View File
@@ -28,8 +28,7 @@ namespace battleship {
protected: protected:
virtual void reinit(); virtual void reinit();
virtual void checkUnitCollision(); virtual void checkUnitCollision();
virtual void checkSurfaceCollision(); virtual void checkSurfaceCollision(bool);
void checkCollision();
vb01::Vector3 initPos; vb01::Vector3 initPos;
ProjectileClass projClass; ProjectileClass projClass;
+6 -1
View File
@@ -32,6 +32,11 @@ namespace battleship{
model->lookAt(dirVec, upVec); model->lookAt(dirVec, upVec);
Projectile::update(); Projectile::update();
checkCollision();
if(!remove){
checkSurfaceCollision(false);
if(remove) return;
checkUnitCollision();
}
} }
} }
+17
View File
@@ -0,0 +1,17 @@
#include "torpedo.h"
namespace battleship{
using namespace vb01;
Torpedo::Torpedo(Unit *un, int id, Vector3 pos, Quaternion rot) : Projectile(un, id, pos, rot){}
void Torpedo::update(){
Projectile::update();
if(!remove){
checkSurfaceCollision(true);
if(remove) return;
checkUnitCollision();
}
}
}
+15
View File
@@ -0,0 +1,15 @@
#ifndef TORPEDO_H
#define TORPEDO_H
#include "projectile.h"
namespace battleship{
class Torpedo : public Projectile{
public:
Torpedo(Unit*, int, vb01::Vector3, vb01::Quaternion);
void update();
private:
};
}
#endif