mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
removing projectiles if they go out of map bounds
This commit is contained in:
+1
-1
@@ -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(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(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp researchStruct.cpp iceSheet.cpp)
|
||||
set(WEAPONS weapon.cpp)
|
||||
|
||||
+5
-2
@@ -72,7 +72,10 @@ namespace battleship{
|
||||
break;
|
||||
}
|
||||
|
||||
if(flightStage == FlightStage::DESCENT)
|
||||
Projectile::checkCollision();
|
||||
if(flightStage == FlightStage::DESCENT && !remove){
|
||||
checkSurfaceCollision(false);
|
||||
if(remove) return;
|
||||
checkUnitCollision();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+5
-1
@@ -8,6 +8,10 @@ namespace battleship{
|
||||
void DepthCharge::update(){
|
||||
Projectile::update();
|
||||
|
||||
if(!remove) checkUnitCollision();
|
||||
if(!remove){
|
||||
checkSurfaceCollision(true);
|
||||
if(remove) return;
|
||||
checkUnitCollision();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -14,6 +14,7 @@
|
||||
#include "cruiseMissile.h"
|
||||
#include "iceSheet.h"
|
||||
#include "shell.h"
|
||||
#include "torpedo.h"
|
||||
#include "depthCharge.h"
|
||||
#include "defConfigs.h"
|
||||
|
||||
@@ -77,6 +78,8 @@ namespace battleship{
|
||||
return new CruiseMissile(unit, id, targetPos, pos, rot);
|
||||
case ProjectileClass::MISSILE:
|
||||
return new Missile(unit, id, targetPos, pos, rot);
|
||||
case ProjectileClass::TORPEDO:
|
||||
return new Torpedo(unit, id, pos, rot);
|
||||
case ProjectileClass::DEPTH_CHARGE:
|
||||
return new DepthCharge(unit, id, pos, rot);
|
||||
default:
|
||||
|
||||
+6
-1
@@ -22,6 +22,11 @@ namespace battleship{
|
||||
|
||||
Projectile::update();
|
||||
destructable->update();
|
||||
checkCollision();
|
||||
|
||||
if(!remove){
|
||||
checkSurfaceCollision(false);
|
||||
if(remove) return;
|
||||
checkUnitCollision();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+15
-10
@@ -105,20 +105,25 @@ namespace battleship{
|
||||
detonate(targetUnits[i]);
|
||||
}
|
||||
|
||||
void Projectile::checkSurfaceCollision(){
|
||||
//TODO fix map boundary checks
|
||||
void Projectile::checkSurfaceCollision(bool useBottomCell){
|
||||
Map *map = Map::getSingleton();
|
||||
vector<Map::Cell> &cells = map->getCells();
|
||||
int cellId = map->getCellId(pos, false);
|
||||
Vector3 mapSize = map->getMapSize();
|
||||
|
||||
if((pos + dirVec * rayLength).y <= map->getCells()[cellId].pos.y)
|
||||
detonate();
|
||||
}
|
||||
|
||||
void Projectile::checkCollision(){
|
||||
if(!remove){
|
||||
checkSurfaceCollision();
|
||||
if(remove) return;
|
||||
checkUnitCollision();
|
||||
if(cellId < 0 || fabs(pos.x) > .5 * mapSize.x || fabs(pos.z) > .5 * mapSize.z){
|
||||
remove = true;
|
||||
return;
|
||||
}
|
||||
|
||||
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(){
|
||||
|
||||
+1
-2
@@ -28,8 +28,7 @@ namespace battleship {
|
||||
protected:
|
||||
virtual void reinit();
|
||||
virtual void checkUnitCollision();
|
||||
virtual void checkSurfaceCollision();
|
||||
void checkCollision();
|
||||
virtual void checkSurfaceCollision(bool);
|
||||
|
||||
vb01::Vector3 initPos;
|
||||
ProjectileClass projClass;
|
||||
|
||||
@@ -32,6 +32,11 @@ namespace battleship{
|
||||
model->lookAt(dirVec, upVec);
|
||||
|
||||
Projectile::update();
|
||||
checkCollision();
|
||||
|
||||
if(!remove){
|
||||
checkSurfaceCollision(false);
|
||||
if(remove) return;
|
||||
checkUnitCollision();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+17
@@ -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();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user