mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
shifting submarine frame dive depth
This commit is contained in:
@@ -22,7 +22,7 @@ mappings = {
|
||||
{bind = 18, trigger = 340, 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 = 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 = 23, trigger = 49, action = true, bindType = 0, inOptions = true},
|
||||
{bind = 24, trigger = 50, action = true, bindType = 0, inOptions = true},
|
||||
|
||||
+24
-64
@@ -170,20 +170,21 @@ namespace battleship{
|
||||
fc->placeGameObjectFrame(fc->getNumGameObjectFrames() - 1, targets[0].pos, selectedUnits[i]->getWidth(), selectedUnits[i]->getLength());
|
||||
}
|
||||
|
||||
fc->setRotatingFrames(true);
|
||||
selectingDestOrient = true;
|
||||
fc->setPlacingOnSurface(true);
|
||||
fc->setRotating(true);
|
||||
}
|
||||
else if(selectingDestOrient && !orderMouseClicked){
|
||||
selectingDestOrient = false;
|
||||
|
||||
fc->setPlacingFrames(false);
|
||||
fc->setRotatingFrames(false);
|
||||
fc->setPlacingOnSurface(false);
|
||||
fc->setRotating(false);
|
||||
fc->removeGameObjectFrames();
|
||||
}
|
||||
|
||||
renderUnits();
|
||||
|
||||
if(fc->isPlacingFrames())
|
||||
if(fc->isPlacingOnSurface())
|
||||
fc->update();
|
||||
|
||||
CameraController *camCtr = CameraController::getSingleton();
|
||||
@@ -220,8 +221,8 @@ namespace battleship{
|
||||
mainPlayer->deselectUnits();
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
ufCtr->removeGameObjectFrames();
|
||||
ufCtr->setPlacingFrames(false);
|
||||
ufCtr->setRotatingFrames(false);
|
||||
ufCtr->setPlacingOnSurface(false);
|
||||
ufCtr->setRotating(false);
|
||||
|
||||
unitGuiScreen = "";
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua");
|
||||
@@ -441,54 +442,9 @@ namespace battleship{
|
||||
Map *map = Map::getSingleton();
|
||||
vector<RayCaster::CollisionResult> results = map->raycastTerrain(camPos, rayDir, true);
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if(!results.empty())
|
||||
targets.push_back(Order::Target(nullptr, results[0].pos));
|
||||
}
|
||||
}
|
||||
|
||||
void ActiveGameState::enableUnitState(Unit::State state){
|
||||
vector<Unit*> selectedUnits = mainPlayer->getSelectedUnits();
|
||||
@@ -536,8 +492,8 @@ namespace battleship{
|
||||
quad->setSize(Vector3::VEC_ZERO);
|
||||
quad->updateVerts(quad->getMeshBase());
|
||||
|
||||
ufCtr->setPlacingFrames(false);
|
||||
ufCtr->setRotatingFrames(false);
|
||||
ufCtr->setPlacingOnSurface(false);
|
||||
ufCtr->setRotating(false);
|
||||
ufCtr->removeGameObjectFrames();
|
||||
}
|
||||
|
||||
@@ -556,7 +512,7 @@ namespace battleship{
|
||||
|
||||
if(controlPressed || (targets[0].unit && targets[0].unit->getPlayer()->getTeam() != mainPlayer->getTeam()))
|
||||
type = Order::TYPE::ATTACK;
|
||||
else if(ufCtr->isPlacingFrames() && !selectingDestOrient)
|
||||
else if(ufCtr->isPlacingOnSurface() && !selectingDestOrient)
|
||||
type = Order::TYPE::BUILD;
|
||||
|
||||
issueOrder(type, targets, shiftPressed);
|
||||
@@ -587,7 +543,7 @@ namespace battleship{
|
||||
castRayToTerrain();
|
||||
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();
|
||||
GameObjectFrame gmObjFr = ufCtr->getGameObjectFrame(0);
|
||||
|
||||
@@ -639,7 +595,9 @@ namespace battleship{
|
||||
|
||||
break;
|
||||
}
|
||||
case Bind::TOGGLE_SUB:
|
||||
case Bind::SHIFT_SUB_DEPTH:
|
||||
ufCtr->setPlacingVertically(isPressed);
|
||||
ufCtr->setRotating(false);
|
||||
break;
|
||||
case Bind::ZOOM_IN:
|
||||
if (zooms > -NUM_MAX_ZOOMS) {
|
||||
@@ -656,7 +614,7 @@ namespace battleship{
|
||||
}
|
||||
break;
|
||||
case Bind::LOOK_AROUND:
|
||||
if(!ufCtr->isPlacingFrames())
|
||||
if(!ufCtr->isPlacingOnSurface())
|
||||
CameraController::getSingleton()->setLookingAround(isPressed);
|
||||
break;
|
||||
case Bind::HALT:
|
||||
@@ -667,18 +625,14 @@ namespace battleship{
|
||||
//TODO reimplement submarine diving mechanic
|
||||
case Bind::LEFT_CONTROL:
|
||||
controlPressed = isPressed;
|
||||
if(isPressed) depth -= 0.05;
|
||||
break;
|
||||
case Bind::LEFT_SHIFT:
|
||||
{
|
||||
shiftPressed = isPressed;
|
||||
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
ufCtr->setPaintSelecting(shiftPressed);
|
||||
|
||||
if(isPressed){
|
||||
depth += 0.05;
|
||||
|
||||
Vector3 startPos = Root::getSingleton()->getCamera()->getPosition();
|
||||
vector<RayCaster::CollisionResult> results = Map::getSingleton()->raycastTerrain(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), true);
|
||||
|
||||
@@ -721,7 +675,7 @@ namespace battleship{
|
||||
break;
|
||||
case Bind::DESELECT_STRUCTURE:
|
||||
ufCtr->removeGameObjectFrames();
|
||||
ufCtr->setPlacingFrames(false);
|
||||
ufCtr->setPlacingOnSurface(false);
|
||||
buildableStructSelected = false;
|
||||
break;
|
||||
}
|
||||
@@ -739,13 +693,19 @@ namespace battleship{
|
||||
dirProj = Vector3(dirProj.x, 0, dirProj.z).norm();
|
||||
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;
|
||||
case Bind::LOOK_LEFT:
|
||||
case Bind::LOOK_RIGHT:
|
||||
if(camCtr->isLookingAround())
|
||||
CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0), strength);
|
||||
else if(ufCtr->isRotatingFrames())
|
||||
else if(ufCtr->isRotating())
|
||||
ufCtr->rotateGameObjectFrames(100 * strength);
|
||||
|
||||
break;
|
||||
|
||||
@@ -36,6 +36,7 @@ namespace battleship{
|
||||
inline std::vector<Unit*>& getUnitGroup(int i){return unitGroups[i];}
|
||||
inline void setBuildableStructSelected(bool bss){this->buildableStructSelected = bss;}
|
||||
inline bool isBuildableStructSelected(){return buildableStructSelected;}
|
||||
inline float getDepth(){return depth;}
|
||||
private:
|
||||
enum CursorState{
|
||||
NORMAL,
|
||||
|
||||
@@ -24,7 +24,7 @@ namespace battleship{
|
||||
LEFT_SHIFT,
|
||||
SELECT_PATROL_POINTS,
|
||||
LAUNCH,
|
||||
TOGGLE_SUB,
|
||||
SHIFT_SUB_DEPTH,
|
||||
GROUP_0,
|
||||
GROUP_1,
|
||||
GROUP_2,
|
||||
|
||||
+1
-2
@@ -27,8 +27,7 @@ namespace battleship{
|
||||
if(builder->getBuildableUnit(slotId).buildable){
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
ufCtr->addGameObjectFrame(GameObjectFrame(builder->getBuildableUnit(slotId).id, GameObject::Type::UNIT));
|
||||
ufCtr->setPlacingFrames(true);
|
||||
|
||||
ufCtr->setPlacingOnSurface(true);
|
||||
activeState->setBuildableStructSelected(true);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ namespace battleship{
|
||||
Bind::LEFT_SHIFT,
|
||||
Bind::SELECT_PATROL_POINTS,
|
||||
Bind::LAUNCH,
|
||||
Bind::TOGGLE_SUB,
|
||||
Bind::SHIFT_SUB_DEPTH,
|
||||
Bind::GROUP_0,
|
||||
Bind::GROUP_1,
|
||||
Bind::GROUP_2,
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
#include <solUtil.h>
|
||||
|
||||
#include "gameObjectFrameController.h"
|
||||
#include "activeGameState.h"
|
||||
#include "resourceDeposit.h"
|
||||
#include "defConfigs.h"
|
||||
#include "player.h"
|
||||
@@ -11,10 +12,12 @@
|
||||
|
||||
#include <material.h>
|
||||
#include <meshData.h>
|
||||
#include <mesh.h>
|
||||
#include <quad.h>
|
||||
#include <model.h>
|
||||
#include <root.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace battleship{
|
||||
@@ -116,29 +119,77 @@ namespace battleship{
|
||||
for(GameObjectFrame &frame : gameObjectFrames)
|
||||
frame.update();
|
||||
|
||||
Map *map = Map::getSingleton();
|
||||
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;
|
||||
|
||||
Vector3 newPos, rowEnd;
|
||||
sol::table sizeTable = generateView()[gameObjectFrames[0].getGameObjTableName()][gameObjectFrames[0].getId() + 1]["size"];
|
||||
float width = sizeTable["x"], length = sizeTable["z"];
|
||||
float width, length;
|
||||
|
||||
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);
|
||||
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++){
|
||||
if(paintSelecting){
|
||||
float hypothenuse = sqrt(width * width + length * length);
|
||||
Vector3 dir = (results[0].pos - paintSelectRowStart).norm();
|
||||
newPos = paintSelectRowStart + dir * hypothenuse * i;
|
||||
placementPos = paintSelectRowStart + dir * hypothenuse * i;
|
||||
}
|
||||
|
||||
|
||||
if(!rotatingStructure) placeGameObjectFrame(i, newPos, width, length);
|
||||
if(!rotating && (placingOnSurface || placingVertically))
|
||||
placeGameObjectFrame(i, placementPos, width, length);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -25,12 +25,14 @@ namespace battleship{
|
||||
inline int getNumGameObjectFrames(){return gameObjectFrames.size();}
|
||||
inline void addGameObjectFrame(GameObjectFrame u){gameObjectFrames.push_back(u);}
|
||||
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 void setPaintSelecting(bool ps){paintSelecting = ps;}
|
||||
inline bool isRotatingFrames(){return rotatingStructure;}
|
||||
inline void setRotatingFrames(bool rs){rotatingStructure = rs;}
|
||||
inline bool isRotating(){return rotating;}
|
||||
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;}
|
||||
private:
|
||||
GameObjectFrameController(){}
|
||||
@@ -38,8 +40,9 @@ namespace battleship{
|
||||
void snapToObj(GameObjectFrame&, GameObject::Type, int, float);
|
||||
|
||||
std::vector<GameObjectFrame> gameObjectFrames;
|
||||
vb01::Vector3 paintSelectRowStart, rowDir;
|
||||
bool placingStructures = false, paintSelecting = false, rotatingStructure = false;
|
||||
vb01::Vector3 paintSelectRowStart, placementPos;
|
||||
float minDepth, maxDepth;
|
||||
bool paintSelecting = false, rotating = false, placingOnSurface = false, placingVertically = false, minDepthCalculated = false;
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,6 @@ namespace battleship{
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
GameObject::Type type = (unitListbox ? GameObject::Type::UNIT : GameObject::Type::RESOURCE_DEPOSIT);
|
||||
ufCtr->addGameObjectFrame(GameObjectFrame(selectedOption, type));
|
||||
ufCtr->setPlacingFrames(true);
|
||||
ufCtr->setPlacingOnSurface(true);
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -106,7 +106,7 @@ namespace battleship{
|
||||
void InGameAppState::onAction(int bind, bool isPressed) {
|
||||
switch((Bind)bind){
|
||||
case Bind::TOGGLE_MAIN_MENU:
|
||||
if(isPressed && !GameObjectFrameController::getSingleton()->isPlacingFrames())
|
||||
if(isPressed && !GameObjectFrameController::getSingleton()->isPlacingOnSurface())
|
||||
Game::getSingleton()->togglePause();
|
||||
break;
|
||||
}
|
||||
|
||||
@@ -624,7 +624,7 @@ namespace battleship{
|
||||
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
|
||||
if(ufCtr->isPlacingFrames())
|
||||
if(ufCtr->isPlacingOnSurface())
|
||||
ufCtr->update();
|
||||
}
|
||||
|
||||
@@ -659,7 +659,7 @@ namespace battleship{
|
||||
|
||||
switch((Bind)bind){
|
||||
case Bind::LOOK_AROUND:
|
||||
if(ufCtr->isPlacingFrames()){
|
||||
if(ufCtr->isPlacingOnSurface()){
|
||||
Player *player = Game::getSingleton()->getPlayer(0);
|
||||
GameObjectFrame &frame = ufCtr->getGameObjectFrame(0);
|
||||
Model *model = frame.getModel();
|
||||
@@ -678,7 +678,7 @@ namespace battleship{
|
||||
break;
|
||||
case Bind::ROTATE_OBJ_FRAME:
|
||||
ufCtr->removeGameObjectFrames();
|
||||
ufCtr->setPlacingFrames(false);
|
||||
ufCtr->setPlacingOnSurface(false);
|
||||
break;
|
||||
case Bind::INCREASE_RADIUS:
|
||||
if(isPressed) mapEditor->updateCircleRadius(true);
|
||||
|
||||
Reference in New Issue
Block a user