launchable cruise missiles

This commit is contained in:
devZoGok
2024-01-21 15:42:17 +02:00
parent e1dde2c90f
commit a36648eabe
11 changed files with 123 additions and 16 deletions
+1 -1
View File
@@ -21,7 +21,7 @@ mappings = {
{bind = 17, trigger = 341, action = true, bindType = 0, inOptions = true},
{bind = 18, trigger = 340, action = true, bindType = 0, inOptions = true},
{bind = 19, trigger = 80, action = true, bindType = 0, inOptions = true},
{bind = 20, trigger = 67, action = true, bindType = 0, inOptions = true},
{bind = 20, trigger = 76, action = true, bindType = 0, inOptions = true},
{bind = 21, trigger = 83, action = true, bindType = 0, inOptions = true},
{bind = 22, trigger = 48, action = true, bindType = 0, inOptions = true},
{bind = 23, trigger = 49, action = true, bindType = 0, inOptions = true},
@@ -1,15 +1,15 @@
ProjectileClass = {GUIDED_MISSILE = 0, TORPEDO = 1}
ProjectileClass = {CRUISE_MISSILE = 0, TORPEDO = 1}
projectiles = {
projectileClass = {
ProjectileClass.GUIDED_MISSILE,
ProjectileClass.CRUISE_MISSILE,
ProjectileClass.TORPEDO,
},
speed = {.5, .06},
speed = {.1, .06},
rayLength = {1.25, .75},
damage = {450, 300},
name = {
"Guided missile",
"Cruise missile",
"Torpedo"
},
basePath = {
@@ -17,7 +17,7 @@ projectiles = {
PATH .. "Models/GameObjects/Projectiles/Torpedos/",
},
meshPath = {
"guidedMissile.xml",
"cruiseMissile.xml",
"torpedo.xml",
},
unitCornerPoints = {
+2 -2
View File
@@ -21,9 +21,9 @@ set(UTIL util.cpp binds.h)
set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp)
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp)
set(CORE gameManager.cpp game.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS})
set(PROJECTILES projectile.cpp)
set(PROJECTILES projectile.cpp cruiseMissile.cpp)
set(FX fx.cpp)
set(VEHICLES vehicle.cpp engineer.cpp transport.cpp submarine.cpp)
set(VEHICLES vehicle.cpp engineer.cpp transport.cpp)
set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp)
set(UNITS gameObjectFactory.cpp unit.cpp ${STRUCTURES} ${VEHICLES})
set(CONTENT player.cpp pathfinder.cpp map.cpp gameObject.cpp gameObjectFrame.h resourceDeposit.cpp ${UNITS} ${PROJECTILES} ${FX})
+7
View File
@@ -407,6 +407,13 @@ namespace battleship{
break;
case Bind::EJECT_GARRISON:
if(isPressed) issueOrder(Order::TYPE::EJECT, vector<Order::Target>{}, shiftPressed);
break;
case Bind::LAUNCH:
if(isPressed){
castRayToTerrain();
issueOrder(Order::TYPE::LAUNCH, targets, shiftPressed);
}
break;
case Bind::TOGGLE_SUB:
break;
+63
View File
@@ -0,0 +1,63 @@
#include "cruiseMissile.h"
#include "unit.h"
#include <util.h>
#include <cmath>
namespace battleship{
using namespace std;
using namespace vb01;
CruiseMissile::CruiseMissile(Unit *unit, Vector3 tp, Vector3 pos, Quaternion rot) : Projectile(unit, 0, pos, rot), targetPoint(tp), flightStage(FlightStage::ASCENT){
Vector3 unitDir = unit->getDirVec();
Vector3 leftDir = unit->getLeftVec();
Vector3 targDir = (Vector3(targetPoint.x, pos.y, targetPoint.z) - pos).norm();
bool left = (leftDir.getAngleBetween(targDir) < PI / 2);
float angle = unitDir.getAngleBetween(targDir) * (left ? 1 : -1);
orientAt(Quaternion(angle, Vector3::VEC_J) * rot);
}
void CruiseMissile::pitch(float rotAngle){
Vector3 horDir = Vector3(dirVec.x, 0, dirVec.z).norm();
float angleToVertDir = dirVec.getAngleBetween(horDir);
Quaternion rotQuat = Quaternion(angleToVertDir > rotAngle ? rotAngle : angleToVertDir, leftVec) * rot;
float minHeight = 20;
if(flightStage == FlightStage::ASCENT && pos.y - initPos.y > minHeight){
orientAt(rotQuat);
if(dirVec.y <= 0)
flightStage = FlightStage::CRUISE;
}
else if(flightStage == FlightStage::DESCENT && dirVec.getAngleBetween((Vector3(targetPoint.x, initPos.y, targetPoint.z) - initPos).norm()) < PI / 2)
orientAt(rotQuat);
}
void CruiseMissile::cruise(){
float minDist = 3;
if(pos.getDistanceFrom(Vector3(targetPoint.x, pos.y, targetPoint.z)) < minDist)
flightStage = FlightStage::DESCENT;
}
void CruiseMissile::update(){
GameObject::update();
placeAt(pos + dirVec * speed);
float rotAngle = .1, eps = .0001;
switch(flightStage){
case FlightStage::ASCENT:
case FlightStage::DESCENT:
pitch(rotAngle);
break;
case FlightStage::CRUISE:
cruise();
break;
}
//if(!exploded && flightStage == FlightStage::DESCENT) checkForCollision();
}
}
+21
View File
@@ -0,0 +1,21 @@
#ifndef CRUISE_MISSILE_H
#define CRUISE_MISSILE_H
#include "projectile.h"
namespace battleship{
class CruiseMissile : public Projectile{
public:
CruiseMissile(Unit*, vb01::Vector3, vb01::Vector3, vb01::Quaternion);
void update();
private:
enum class FlightStage{ASCENT, CRUISE, DESCENT};
FlightStage flightStage;
vb01::Vector3 targetPoint;
void pitch(float);
void cruise();
};
}
#endif
+7 -5
View File
@@ -3,11 +3,10 @@
#include "factory.h"
#include "engineer.h"
#include "transport.h"
#include "submarine.h"
#include "projectile.h"
#include "resourceDeposit.h"
#include "pointDefense.h"
#include "projectile.h"
#include "cruiseMissile.h"
#include "defConfigs.h"
#include <solUtil.h>
@@ -28,9 +27,6 @@ namespace battleship{
return new Engineer(player, id, pos, rot);
case UnitClass::TRANSPORT:
return new Transport(player, id, pos, rot);
case UnitClass::MISSILE_SUBMARINE:
case UnitClass::STEALTH_SUBMARINE:
return new Submarine(player, id, pos, rot);
case UnitClass::LAND_FACTORY:
case UnitClass::NAVAL_FACTORY:
return new Factory(player, id, pos, rot, buildStatus);
@@ -49,6 +45,12 @@ namespace battleship{
int projectileClass = SOL_LUA_STATE["projectiles"]["projectileClass"][id + 1];
switch((ProjectileClass)projectileClass){
case ProjectileClass::CRUISE_MISSILE:
{
Order::Target target = unit->getOrder(0).targets[0];
Vector3 targetPos = (target.unit ? target.unit->getPos() : target.pos);
return new CruiseMissile(unit, targetPos, pos, rot);
}
default:
return new Projectile(unit, id, pos, rot);
}
+1 -1
View File
@@ -24,7 +24,7 @@ namespace battleship{
using namespace configData;
using namespace gameBase;
Projectile::Projectile(Unit *un, int id, Vector3 pos, Quaternion rot) : GameObject(GameObject::Type::PROJECTILE, id, un->getPlayer(), pos, rot), unit(un){
Projectile::Projectile(Unit *un, int id, Vector3 pos, Quaternion rot) : GameObject(GameObject::Type::PROJECTILE, id, un->getPlayer(), pos, rot), unit(un), initPos(pos){
initProperties();
initModel();
initSound();
+2 -1
View File
@@ -12,7 +12,7 @@ namespace vb01{
}
namespace battleship {
enum class ProjectileClass{GUIDED_MISSILE, TORPEDO};
enum class ProjectileClass{CRUISE_MISSILE, TORPEDO};
class Unit;
class Projectile : public GameObject{
@@ -32,6 +32,7 @@ namespace battleship {
bool exploded = false;
float speed, rayLength;
int damage;
vb01::Vector3 initPos;
Unit *unit = nullptr;
sf::SoundBuffer *shotSfxBuffer, *explosionSfxBuffer;
sf::Sound *shotSfx = nullptr, *explosionSfx = nullptr;
+10
View File
@@ -218,6 +218,16 @@ namespace battleship{
delete node;
}
void Unit::launch(Order order){
for(Weapon *weapon : weapons)
if(weapon->getProjectileId() == 0){
weapon->fire(order);
break;
}
removeOrder(0);
}
float Unit::calculateRotation(Vector3 dir, float angle, float maxTurnAngle){
float rotSpeed = (maxTurnAngle > angle ? angle : maxTurnAngle);
+4 -1
View File
@@ -67,6 +67,7 @@ namespace battleship{
Weapon(Unit*, sol::table);
~Weapon();
virtual void fire(Order);
inline int getProjectileId(){return projId;}
inline int getRateOfFire(){return rateOfFire;}
inline int getDamage(){return damage;}
inline int getMinRange(){return minRange;}
@@ -125,6 +126,8 @@ namespace battleship{
inline int getDeathHp(){return DEATH_HP;}
inline bool isVehicle(){return gameBase::generateView()["units"]["isVehicle"][id + 1];}
inline bool isTargetToTheRight(vb01::Vector3 dir, vb01::Vector3 lv){return lv.getAngleBetween(dir) > vb01::PI / 2;}
inline Order getOrder(int i){return orders[i];}
inline int getNumOrders(){return orders.size();}
private:
void renderOrderLine(bool);
void updateScreenCoordinates();
@@ -161,7 +164,7 @@ namespace battleship{
virtual void build(Order){}
virtual void move(Order){}
virtual void patrol(Order){}
virtual void launch(Order){}
virtual void launch(Order);
float calculateRotation(vb01::Vector3, float, float);
void removeBar(vb01::Node*);
vb01::Node* createBar(vb01::Vector2, vb01::Vector2, vb01::Vector4);