shifting submarine frame dive depth

This commit is contained in:
devZoGok
2025-02-09 15:14:34 +02:00
parent 0578f6e41b
commit 728f4b6d4a
11 changed files with 105 additions and 91 deletions
+1 -1
View File
@@ -22,7 +22,7 @@ mappings = {
{bind = 18, trigger = 340, 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 = 19, trigger = 80, action = true, bindType = 0, inOptions = true},
{bind = 20, trigger = 76, 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 = 21, trigger = 32, action = true, bindType = 0, inOptions = true},
{bind = 22, trigger = 48, 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}, {bind = 23, trigger = 49, action = true, bindType = 0, inOptions = true},
{bind = 24, trigger = 50, action = true, bindType = 0, inOptions = true}, {bind = 24, trigger = 50, action = true, bindType = 0, inOptions = true},
+24 -64
View File
@@ -170,20 +170,21 @@ namespace battleship{
fc->placeGameObjectFrame(fc->getNumGameObjectFrames() - 1, targets[0].pos, selectedUnits[i]->getWidth(), selectedUnits[i]->getLength()); fc->placeGameObjectFrame(fc->getNumGameObjectFrames() - 1, targets[0].pos, selectedUnits[i]->getWidth(), selectedUnits[i]->getLength());
} }
fc->setRotatingFrames(true);
selectingDestOrient = true; selectingDestOrient = true;
fc->setPlacingOnSurface(true);
fc->setRotating(true);
} }
else if(selectingDestOrient && !orderMouseClicked){ else if(selectingDestOrient && !orderMouseClicked){
selectingDestOrient = false; selectingDestOrient = false;
fc->setPlacingFrames(false); fc->setPlacingOnSurface(false);
fc->setRotatingFrames(false); fc->setRotating(false);
fc->removeGameObjectFrames(); fc->removeGameObjectFrames();
} }
renderUnits(); renderUnits();
if(fc->isPlacingFrames()) if(fc->isPlacingOnSurface())
fc->update(); fc->update();
CameraController *camCtr = CameraController::getSingleton(); CameraController *camCtr = CameraController::getSingleton();
@@ -220,8 +221,8 @@ namespace battleship{
mainPlayer->deselectUnits(); mainPlayer->deselectUnits();
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
ufCtr->removeGameObjectFrames(); ufCtr->removeGameObjectFrames();
ufCtr->setPlacingFrames(false); ufCtr->setPlacingOnSurface(false);
ufCtr->setRotatingFrames(false); ufCtr->setRotating(false);
unitGuiScreen = ""; unitGuiScreen = "";
ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua"); ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua");
@@ -441,53 +442,8 @@ namespace battleship{
Map *map = Map::getSingleton(); Map *map = Map::getSingleton();
vector<RayCaster::CollisionResult> results = map->raycastTerrain(camPos, rayDir, true); vector<RayCaster::CollisionResult> results = map->raycastTerrain(camPos, rayDir, true);
if(!results.empty()){ if(!results.empty())
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
for(Unit *u : mainPlayer->getSelectedUnits()){
Vector3 pos = u->getPos();
Node *nodeParent = map->getNodeParent();
if(u->getType() == UnitType::UNDERWATER && nodeParent->getNumChildren() > 0){
Vector3 cellSize = map->getCellSize(), waterBodyPos;
bool inWater = false;
for(int i = 1; i < nodeParent->getNumChildren(); i++){
Vector3 wPos = nodeParent->getChild(i)->getPosition();
Vector3 wSize = ((Quad*)nodeParent->getChild(i)->getMesh(0))->getSize();
if(fabs(wPos.x - pos.x) < .5 * wSize.x && fabs(wPos.z - pos.z) < .5 * wSize.y){
waterBodyPos = wPos;
inWater = true;
break;
}
}
if(inWater){
vector<RayCaster::CollisionResult> res = map->raycastTerrain(
Vector3(results[0].pos.x, 100, results[0].pos.z),
-Vector3::VEC_J,
false
);
vector<Map::Cell> &cells = map->getCells();
int cid = map->getCellId(results[0].pos, false);
int numSubmarineCells = cells[cid].underWaterCellIds.size();
float maxDepth = cells[cid].pos.y;
float minDepth = (numSubmarineCells > 0 ? cells[cells[cid].underWaterCellIds[numSubmarineCells - 1]].pos.y : maxDepth) - .5 * cellSize.y;
float newDepth = res[0].pos.y + depth * (waterBodyPos.y - res[0].pos.y);
if(newDepth < minDepth) newDepth = minDepth;
else if(newDepth > maxDepth) newDepth = maxDepth;
results[0].pos.y = newDepth;
}
}
}
targets.push_back(Order::Target(nullptr, results[0].pos)); targets.push_back(Order::Target(nullptr, results[0].pos));
}
} }
void ActiveGameState::enableUnitState(Unit::State state){ void ActiveGameState::enableUnitState(Unit::State state){
@@ -536,8 +492,8 @@ namespace battleship{
quad->setSize(Vector3::VEC_ZERO); quad->setSize(Vector3::VEC_ZERO);
quad->updateVerts(quad->getMeshBase()); quad->updateVerts(quad->getMeshBase());
ufCtr->setPlacingFrames(false); ufCtr->setPlacingOnSurface(false);
ufCtr->setRotatingFrames(false); ufCtr->setRotating(false);
ufCtr->removeGameObjectFrames(); ufCtr->removeGameObjectFrames();
} }
@@ -556,7 +512,7 @@ namespace battleship{
if(controlPressed || (targets[0].unit && targets[0].unit->getPlayer()->getTeam() != mainPlayer->getTeam())) if(controlPressed || (targets[0].unit && targets[0].unit->getPlayer()->getTeam() != mainPlayer->getTeam()))
type = Order::TYPE::ATTACK; type = Order::TYPE::ATTACK;
else if(ufCtr->isPlacingFrames() && !selectingDestOrient) else if(ufCtr->isPlacingOnSurface() && !selectingDestOrient)
type = Order::TYPE::BUILD; type = Order::TYPE::BUILD;
issueOrder(type, targets, shiftPressed); issueOrder(type, targets, shiftPressed);
@@ -587,7 +543,7 @@ namespace battleship{
castRayToTerrain(); castRayToTerrain();
issueOrder(Order::TYPE::ATTACK, targets, shiftPressed); issueOrder(Order::TYPE::ATTACK, targets, shiftPressed);
} }
else if(selectedUnits[0]->getUnitClass() == UnitClass::ENGINEER && ufCtr->isPlacingFrames()){ else if(selectedUnits[0]->getUnitClass() == UnitClass::ENGINEER && ufCtr->isPlacingOnSurface()){
castRayToTerrain(); castRayToTerrain();
GameObjectFrame gmObjFr = ufCtr->getGameObjectFrame(0); GameObjectFrame gmObjFr = ufCtr->getGameObjectFrame(0);
@@ -639,7 +595,9 @@ namespace battleship{
break; break;
} }
case Bind::TOGGLE_SUB: case Bind::SHIFT_SUB_DEPTH:
ufCtr->setPlacingVertically(isPressed);
ufCtr->setRotating(false);
break; break;
case Bind::ZOOM_IN: case Bind::ZOOM_IN:
if (zooms > -NUM_MAX_ZOOMS) { if (zooms > -NUM_MAX_ZOOMS) {
@@ -656,7 +614,7 @@ namespace battleship{
} }
break; break;
case Bind::LOOK_AROUND: case Bind::LOOK_AROUND:
if(!ufCtr->isPlacingFrames()) if(!ufCtr->isPlacingOnSurface())
CameraController::getSingleton()->setLookingAround(isPressed); CameraController::getSingleton()->setLookingAround(isPressed);
break; break;
case Bind::HALT: case Bind::HALT:
@@ -667,18 +625,14 @@ namespace battleship{
//TODO reimplement submarine diving mechanic //TODO reimplement submarine diving mechanic
case Bind::LEFT_CONTROL: case Bind::LEFT_CONTROL:
controlPressed = isPressed; controlPressed = isPressed;
if(isPressed) depth -= 0.05;
break; break;
case Bind::LEFT_SHIFT: case Bind::LEFT_SHIFT:
{ {
shiftPressed = isPressed; shiftPressed = isPressed;
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
ufCtr->setPaintSelecting(shiftPressed); ufCtr->setPaintSelecting(shiftPressed);
if(isPressed){ if(isPressed){
depth += 0.05;
Vector3 startPos = Root::getSingleton()->getCamera()->getPosition(); Vector3 startPos = Root::getSingleton()->getCamera()->getPosition();
vector<RayCaster::CollisionResult> results = Map::getSingleton()->raycastTerrain(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), true); vector<RayCaster::CollisionResult> results = Map::getSingleton()->raycastTerrain(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), true);
@@ -721,7 +675,7 @@ namespace battleship{
break; break;
case Bind::DESELECT_STRUCTURE: case Bind::DESELECT_STRUCTURE:
ufCtr->removeGameObjectFrames(); ufCtr->removeGameObjectFrames();
ufCtr->setPlacingFrames(false); ufCtr->setPlacingOnSurface(false);
buildableStructSelected = false; buildableStructSelected = false;
break; break;
} }
@@ -739,13 +693,19 @@ namespace battleship{
dirProj = Vector3(dirProj.x, 0, dirProj.z).norm(); dirProj = Vector3(dirProj.x, 0, dirProj.z).norm();
CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0).cross(dirProj), strength); CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0).cross(dirProj), strength);
} }
else if(ufCtr->isPlacingVertically()){
depth -= .2 * strength;
if(depth < 0) depth = 0;
else if(depth > 1) depth = 1;
}
break; break;
case Bind::LOOK_LEFT: case Bind::LOOK_LEFT:
case Bind::LOOK_RIGHT: case Bind::LOOK_RIGHT:
if(camCtr->isLookingAround()) if(camCtr->isLookingAround())
CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0), strength); CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0), strength);
else if(ufCtr->isRotatingFrames()) else if(ufCtr->isRotating())
ufCtr->rotateGameObjectFrames(100 * strength); ufCtr->rotateGameObjectFrames(100 * strength);
break; break;
+1
View File
@@ -36,6 +36,7 @@ namespace battleship{
inline std::vector<Unit*>& getUnitGroup(int i){return unitGroups[i];} inline std::vector<Unit*>& getUnitGroup(int i){return unitGroups[i];}
inline void setBuildableStructSelected(bool bss){this->buildableStructSelected = bss;} inline void setBuildableStructSelected(bool bss){this->buildableStructSelected = bss;}
inline bool isBuildableStructSelected(){return buildableStructSelected;} inline bool isBuildableStructSelected(){return buildableStructSelected;}
inline float getDepth(){return depth;}
private: private:
enum CursorState{ enum CursorState{
NORMAL, NORMAL,
+1 -1
View File
@@ -24,7 +24,7 @@ namespace battleship{
LEFT_SHIFT, LEFT_SHIFT,
SELECT_PATROL_POINTS, SELECT_PATROL_POINTS,
LAUNCH, LAUNCH,
TOGGLE_SUB, SHIFT_SUB_DEPTH,
GROUP_0, GROUP_0,
GROUP_1, GROUP_1,
GROUP_2, GROUP_2,
+1 -2
View File
@@ -27,8 +27,7 @@ namespace battleship{
if(builder->getBuildableUnit(slotId).buildable){ if(builder->getBuildableUnit(slotId).buildable){
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
ufCtr->addGameObjectFrame(GameObjectFrame(builder->getBuildableUnit(slotId).id, GameObject::Type::UNIT)); ufCtr->addGameObjectFrame(GameObjectFrame(builder->getBuildableUnit(slotId).id, GameObject::Type::UNIT));
ufCtr->setPlacingFrames(true); ufCtr->setPlacingOnSurface(true);
activeState->setBuildableStructSelected(true); activeState->setBuildableStructSelected(true);
} }
} }
+1 -1
View File
@@ -97,7 +97,7 @@ namespace battleship{
Bind::LEFT_SHIFT, Bind::LEFT_SHIFT,
Bind::SELECT_PATROL_POINTS, Bind::SELECT_PATROL_POINTS,
Bind::LAUNCH, Bind::LAUNCH,
Bind::TOGGLE_SUB, Bind::SHIFT_SUB_DEPTH,
Bind::GROUP_0, Bind::GROUP_0,
Bind::GROUP_1, Bind::GROUP_1,
Bind::GROUP_2, Bind::GROUP_2,
+62 -11
View File
@@ -1,6 +1,7 @@
#include <solUtil.h> #include <solUtil.h>
#include "gameObjectFrameController.h" #include "gameObjectFrameController.h"
#include "activeGameState.h"
#include "resourceDeposit.h" #include "resourceDeposit.h"
#include "defConfigs.h" #include "defConfigs.h"
#include "player.h" #include "player.h"
@@ -11,10 +12,12 @@
#include <material.h> #include <material.h>
#include <meshData.h> #include <meshData.h>
#include <mesh.h> #include <quad.h>
#include <model.h> #include <model.h>
#include <root.h> #include <root.h>
#include <stateManager.h>
#include <string> #include <string>
namespace battleship{ namespace battleship{
@@ -116,29 +119,77 @@ namespace battleship{
for(GameObjectFrame &frame : gameObjectFrames) for(GameObjectFrame &frame : gameObjectFrames)
frame.update(); frame.update();
Map *map = Map::getSingleton();
Vector3 startPos = Root::getSingleton()->getCamera()->getPosition(); Vector3 startPos = Root::getSingleton()->getCamera()->getPosition();
vector<RayCaster::CollisionResult> results = Map::getSingleton()->raycastTerrain(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), true); Vector3 endPos = screenToSpace(getCursorPos());
vector<RayCaster::CollisionResult> results = map->raycastTerrain(startPos, (endPos - startPos).norm(), true);
if(results.empty()) return; if(results.empty()) return;
Vector3 newPos, rowEnd; float width, length;
sol::table sizeTable = generateView()[gameObjectFrames[0].getGameObjTableName()][gameObjectFrames[0].getId() + 1]["size"];
float width = sizeTable["x"], length = sizeTable["z"];
if(paintSelecting) if(paintSelecting){
sol::table sizeTable = generateView()[gameObjectFrames[0].getGameObjTableName()][gameObjectFrames[0].getId() + 1]["size"];
width = sizeTable["x"], length = sizeTable["z"];
paintSelect(results[0].pos, width, length); paintSelect(results[0].pos, width, length);
else if(!(paintSelecting || rotatingStructure)) }
newPos = results[0].pos;
if(placingVertically){
if(!minDepthCalculated){
placementPos = results[0].pos;
Node *nodeParent = map->getNodeParent();
Vector3 cellSize = map->getCellSize(), waterBodyPos;
bool inWater = false;
for(int i = 1; i < nodeParent->getNumChildren(); i++){
Vector3 wPos = nodeParent->getChild(i)->getPosition();
Vector3 wSize = ((Quad*)nodeParent->getChild(i)->getMesh(0))->getSize();
if(fabs(wPos.x - endPos.x) < .5 * wSize.x && fabs(wPos.z - endPos.z) < .5 * wSize.y){
waterBodyPos = wPos;
inWater = true;
break;
}
}
if(inWater){
vector<RayCaster::CollisionResult> res = map->raycastTerrain(
Vector3(endPos.x, 100, endPos.z),
-Vector3::VEC_J,
false
);
vector<Map::Cell> &cells = map->getCells();
int cid = map->getCellId(placementPos, false);
int numSubmarineCells = cells[cid].underWaterCellIds.size();
maxDepth = cells[cid].pos.y;
minDepth = (numSubmarineCells > 0 ? cells[cells[cid].underWaterCellIds[numSubmarineCells - 1]].pos.y : maxDepth) - .5 * cellSize.y;
minDepthCalculated = true;
}
}
else{
ActiveGameState *activeState = (ActiveGameState*)(GameManager::getSingleton()->getStateManager()->getAppStateByType((int)AppStateType::ACTIVE_STATE));
float newDepth = minDepth + activeState->getDepth() * (maxDepth - minDepth);
placementPos.y = newDepth;
}
}
else{
minDepthCalculated = false;
if(placingOnSurface)
placementPos = results[0].pos;
}
for(int i = 0; i < gameObjectFrames.size(); i++){ for(int i = 0; i < gameObjectFrames.size(); i++){
if(paintSelecting){ if(paintSelecting){
float hypothenuse = sqrt(width * width + length * length); float hypothenuse = sqrt(width * width + length * length);
Vector3 dir = (results[0].pos - paintSelectRowStart).norm(); Vector3 dir = (results[0].pos - paintSelectRowStart).norm();
newPos = paintSelectRowStart + dir * hypothenuse * i; placementPos = paintSelectRowStart + dir * hypothenuse * i;
} }
if(!rotating && (placingOnSurface || placingVertically))
if(!rotatingStructure) placeGameObjectFrame(i, newPos, width, length); placeGameObjectFrame(i, placementPos, width, length);
} }
} }
+9 -6
View File
@@ -25,12 +25,14 @@ namespace battleship{
inline int getNumGameObjectFrames(){return gameObjectFrames.size();} inline int getNumGameObjectFrames(){return gameObjectFrames.size();}
inline void addGameObjectFrame(GameObjectFrame u){gameObjectFrames.push_back(u);} inline void addGameObjectFrame(GameObjectFrame u){gameObjectFrames.push_back(u);}
inline GameObjectFrame& getGameObjectFrame(int i){return gameObjectFrames[i];} inline GameObjectFrame& getGameObjectFrame(int i){return gameObjectFrames[i];}
inline bool isPlacingFrames(){return placingStructures;}
inline void setPlacingFrames(bool ps){placingStructures = ps;}
inline bool isPaintSelecting(){return paintSelecting;} inline bool isPaintSelecting(){return paintSelecting;}
inline void setPaintSelecting(bool ps){paintSelecting = ps;} inline void setPaintSelecting(bool ps){paintSelecting = ps;}
inline bool isRotatingFrames(){return rotatingStructure;} inline bool isRotating(){return rotating;}
inline void setRotatingFrames(bool rs){rotatingStructure = rs;} inline void setRotating(bool rs){rotating = rs;}
inline bool isPlacingOnSurface(){return placingOnSurface;}
inline void setPlacingOnSurface(bool ps){placingOnSurface = ps;}
inline bool isPlacingVertically(){return placingVertically;}
inline void setPlacingVertically(bool v){this->placingVertically = v;}
inline void setPaintSelectRowStart(vb01::Vector3 st){paintSelectRowStart = st;} inline void setPaintSelectRowStart(vb01::Vector3 st){paintSelectRowStart = st;}
private: private:
GameObjectFrameController(){} GameObjectFrameController(){}
@@ -38,8 +40,9 @@ namespace battleship{
void snapToObj(GameObjectFrame&, GameObject::Type, int, float); void snapToObj(GameObjectFrame&, GameObject::Type, int, float);
std::vector<GameObjectFrame> gameObjectFrames; std::vector<GameObjectFrame> gameObjectFrames;
vb01::Vector3 paintSelectRowStart, rowDir; vb01::Vector3 paintSelectRowStart, placementPos;
bool placingStructures = false, paintSelecting = false, rotatingStructure = false; float minDepth, maxDepth;
bool paintSelecting = false, rotating = false, placingOnSurface = false, placingVertically = false, minDepthCalculated = false;
}; };
} }
+1 -1
View File
@@ -16,6 +16,6 @@ namespace battleship{
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
GameObject::Type type = (unitListbox ? GameObject::Type::UNIT : GameObject::Type::RESOURCE_DEPOSIT); GameObject::Type type = (unitListbox ? GameObject::Type::UNIT : GameObject::Type::RESOURCE_DEPOSIT);
ufCtr->addGameObjectFrame(GameObjectFrame(selectedOption, type)); ufCtr->addGameObjectFrame(GameObjectFrame(selectedOption, type));
ufCtr->setPlacingFrames(true); ufCtr->setPlacingOnSurface(true);
} }
} }
+1 -1
View File
@@ -106,7 +106,7 @@ namespace battleship{
void InGameAppState::onAction(int bind, bool isPressed) { void InGameAppState::onAction(int bind, bool isPressed) {
switch((Bind)bind){ switch((Bind)bind){
case Bind::TOGGLE_MAIN_MENU: case Bind::TOGGLE_MAIN_MENU:
if(isPressed && !GameObjectFrameController::getSingleton()->isPlacingFrames()) if(isPressed && !GameObjectFrameController::getSingleton()->isPlacingOnSurface())
Game::getSingleton()->togglePause(); Game::getSingleton()->togglePause();
break; break;
} }
+3 -3
View File
@@ -624,7 +624,7 @@ namespace battleship{
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
if(ufCtr->isPlacingFrames()) if(ufCtr->isPlacingOnSurface())
ufCtr->update(); ufCtr->update();
} }
@@ -659,7 +659,7 @@ namespace battleship{
switch((Bind)bind){ switch((Bind)bind){
case Bind::LOOK_AROUND: case Bind::LOOK_AROUND:
if(ufCtr->isPlacingFrames()){ if(ufCtr->isPlacingOnSurface()){
Player *player = Game::getSingleton()->getPlayer(0); Player *player = Game::getSingleton()->getPlayer(0);
GameObjectFrame &frame = ufCtr->getGameObjectFrame(0); GameObjectFrame &frame = ufCtr->getGameObjectFrame(0);
Model *model = frame.getModel(); Model *model = frame.getModel();
@@ -678,7 +678,7 @@ namespace battleship{
break; break;
case Bind::ROTATE_OBJ_FRAME: case Bind::ROTATE_OBJ_FRAME:
ufCtr->removeGameObjectFrames(); ufCtr->removeGameObjectFrames();
ufCtr->setPlacingFrames(false); ufCtr->setPlacingOnSurface(false);
break; break;
case Bind::INCREASE_RADIUS: case Bind::INCREASE_RADIUS:
if(isPressed) mapEditor->updateCircleRadius(true); if(isPressed) mapEditor->updateCircleRadius(true);