mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
@@ -16,18 +16,19 @@ resourceDeposits = {
|
||||
{id = ResourceId.RESOURCE, pos = {x = 50, y = 0, z = 0}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 30000},
|
||||
},
|
||||
units = {
|
||||
{id = UnitId.TANK, pos = {x = -50.000000, y = 0.000000, z = -50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.ENGINEER, pos = {x = -10.000000, y = 0.000000, z = -10.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.ENGINEER, pos = {x = -10.000000, y = 0.000000, z = -10.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.TANK, pos = {x = -50.000000, y = 0.000000, z = -50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.POINT_DEFENSE, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
}
|
||||
},
|
||||
{
|
||||
resourceDeposits = {},
|
||||
units = {
|
||||
{id = UnitId.WAR_MECH, pos = {x = 3.000000, y = 0.000000, z = 12.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.TANK, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.POINT_DEFENSE, pos = {x = 0.000000, y = 0.000000, z = 20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
|
||||
{id = UnitId.SCOUT_TRANSPORT, pos = {x = 40.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.WAR_MECH, pos = {x = 3.000000, y = 0.000000, z = 12.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.TANK, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.POINT_DEFENSE, pos = {x = 0.000000, y = 0.000000, z = 20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
|
||||
--{id = UnitId.SCOUT_TRANSPORT, pos = {x = 40.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.WAR_MECH, pos = {x = 45.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.ENGINEER, pos = {x = 45.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.EXTRACTOR, pos = {x = 30.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
|
||||
--{id = UnitId.LAB, pos = {x = 50.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
|
||||
|
||||
+3970
-3970
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 6.9 KiB After Width: | Height: | Size: 2.9 KiB |
Executable
BIN
Binary file not shown.
|
After Width: | Height: | Size: 49 KiB |
+37324
-36455
File diff suppressed because it is too large
Load Diff
Binary file not shown.
|
Before Width: | Height: | Size: 1.0 MiB |
+61206
-61206
File diff suppressed because it is too large
Load Diff
@@ -12,7 +12,7 @@ mappings = {
|
||||
{bind = 8, trigger = 313, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 9, trigger = 310, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 10, trigger = 311, action = false, bindType = 2, inOptions = false},
|
||||
{bind = 11, trigger = 1, action = true, bindType = 1, inOptions = false},
|
||||
{bind = 11, trigger = 2, action = true, bindType = 1, inOptions = false},
|
||||
{bind = 12, trigger = 0, action = true, bindType = 1, inOptions = true},
|
||||
{bind = 13, trigger = 1, action = true, bindType = 1, inOptions = true},
|
||||
{bind = 14, trigger = 72, action = true, bindType = 0, inOptions = true},
|
||||
@@ -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},
|
||||
|
||||
+2
-2
@@ -11,7 +11,7 @@ endif()
|
||||
|
||||
set(CMAKE_CXX_STANDART 17)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
set(BUILD_TESTS OFF)
|
||||
set(BUILD_TESTS ON)
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL FORCED)
|
||||
cmake_policy(SET CMP0015 NEW)
|
||||
|
||||
@@ -28,7 +28,7 @@ set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES})
|
||||
set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp)
|
||||
set(UTIL util.cpp binds.h)
|
||||
set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp)
|
||||
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp)
|
||||
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp toggleDebugCommand.cpp)
|
||||
set(CORE gameManager.cpp game.cpp fxManager.cpp defConfigs.cpp ${CONSOLE} ${CONTROLLERS})
|
||||
set(PROJECTILES projectile.cpp cruiseMissile.cpp)
|
||||
set(VEHICLES vehicle.cpp engineer.cpp resourceRover.cpp)
|
||||
|
||||
+19
-20
@@ -6,29 +6,28 @@
|
||||
namespace battleship{
|
||||
using namespace std;
|
||||
|
||||
vector<string> AbstractCommand::explodeString(string commandStr){
|
||||
vector<int> spaceIds;
|
||||
vector<string> fullCommand;
|
||||
|
||||
for(int i = 0; i < commandStr.length(); i++)
|
||||
if(commandStr[i] == ' ')
|
||||
spaceIds.push_back(i);
|
||||
|
||||
fullCommand.push_back(commandStr.substr(0, spaceIds[0]));
|
||||
|
||||
for(int i = 0; i < spaceIds.size(); i++){
|
||||
bool lastSpace = (i == spaceIds.size() - 1);
|
||||
string argument = commandStr.substr(spaceIds[i] + 1, lastSpace ? string::npos : spaceIds[i + 1] - spaceIds[i] - 1);
|
||||
fullCommand.push_back(argument);
|
||||
}
|
||||
|
||||
return fullCommand;
|
||||
}
|
||||
|
||||
void AbstractCommand::handle(){
|
||||
if(cmdStr.find(" ") == -1)
|
||||
return;
|
||||
|
||||
arguments = explodeString(cmdStr);
|
||||
vector<int> spaceIds;
|
||||
arguments.clear();
|
||||
|
||||
for(int i = 0; i < cmdStr.length(); i++)
|
||||
if(cmdStr[i] == ' ')
|
||||
spaceIds.push_back(i);
|
||||
|
||||
arguments.push_back(cmdStr.substr(0, spaceIds[0]));
|
||||
|
||||
for(int i = 0; i < spaceIds.size(); i++){
|
||||
bool lastSpace = (i == spaceIds.size() - 1);
|
||||
string argument = cmdStr.substr(spaceIds[i] + 1, lastSpace ? string::npos : spaceIds[i + 1] - spaceIds[i] - 1);
|
||||
arguments.push_back(argument);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractCommand::execute(){
|
||||
handle();
|
||||
validate();
|
||||
}
|
||||
}
|
||||
|
||||
+2
-4
@@ -8,14 +8,12 @@ namespace battleship{
|
||||
class AbstractCommand{
|
||||
protected:
|
||||
AbstractCommand(std::string str) : cmdStr(str){}
|
||||
virtual void execute(){}
|
||||
virtual void validate(){}
|
||||
virtual void handle();
|
||||
virtual void validate(){}
|
||||
virtual void execute();
|
||||
|
||||
std::string cmdStr;
|
||||
std::vector<std::string> arguments;
|
||||
private:
|
||||
std::vector<std::string> explodeString(std::string);
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+118
-125
@@ -149,7 +149,7 @@ namespace battleship{
|
||||
|
||||
float eps = .01;
|
||||
|
||||
if(!isSelectionBox && leftMouseClicked && (fabs(clickPoint.x - cursorPos.x) > eps || fabs(clickPoint.y - cursorPos.y) > eps) && getTime() - lastLeftMouseClicked > 10)
|
||||
if(!isSelectionBox && selectMouseClicked && (fabs(clickPoint.x - cursorPos.x) > eps || fabs(clickPoint.y - cursorPos.y) > eps) && getTime() - lastSelectMouseClicked > 10)
|
||||
isSelectionBox = true;
|
||||
else if (isSelectionBox)
|
||||
updateDragBox();
|
||||
@@ -161,19 +161,28 @@ namespace battleship{
|
||||
vector<Unit*> selectedUnits = mainPlayer->getSelectedUnits();
|
||||
GameObjectFrameController *fc = GameObjectFrameController::getSingleton();
|
||||
|
||||
if(!selectingDestOrient && leftMouseClicked && !selectedUnits.empty() && getTime() - lastLeftMouseClicked > 100){
|
||||
if(!selectingDestOrient && orderMouseClicked && !selectedUnits.empty() && getTime() - lastOrderMouseClicked > 100){
|
||||
if(targets.empty()) castRayToTerrain();
|
||||
|
||||
if(!buildableStructSelected)
|
||||
for(int i = 0; i < selectedUnits.size(); i++){
|
||||
fc->addGameObjectFrame(GameObjectFrame(selectedUnits[i]->getId(), GameObject::Type::UNIT));
|
||||
fc->placeGameObjectFrame(fc->getNumGameObjectFrames() - 1, targets[0].pos, selectedUnits[i]->getWidth(), selectedUnits[i]->getLength());
|
||||
}
|
||||
|
||||
selectingDestOrient = true;
|
||||
fc->setRotating(true);
|
||||
}
|
||||
else if(selectingDestOrient && !orderMouseClicked){
|
||||
selectingDestOrient = false;
|
||||
|
||||
fc->setPlacingFrames(true);
|
||||
fc->setRotatingFrames(true);
|
||||
|
||||
for(Unit *unit : selectedUnits)
|
||||
fc->addGameObjectFrame(GameObjectFrame(unit->getId(), GameObject::Type::UNIT));
|
||||
fc->toggleFrameTransformations(false, false, false);
|
||||
fc->removeGameObjectFrames();
|
||||
}
|
||||
|
||||
renderUnits();
|
||||
|
||||
if(fc->isPlacingFrames())
|
||||
if(fc->isRotating() || fc->isPlacingOnSurface() || fc->isPlacingVertically())
|
||||
fc->update();
|
||||
|
||||
CameraController *camCtr = CameraController::getSingleton();
|
||||
@@ -210,7 +219,7 @@ namespace battleship{
|
||||
mainPlayer->deselectUnits();
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
ufCtr->removeGameObjectFrames();
|
||||
ufCtr->setPlacingFrames(false);
|
||||
ufCtr->toggleFrameTransformations(false, false, false);
|
||||
|
||||
unitGuiScreen = "";
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua");
|
||||
@@ -416,7 +425,15 @@ namespace battleship{
|
||||
|
||||
//TODO fix ejectable unit selection with multiple transports selected
|
||||
void ActiveGameState::issueOrder(Order::TYPE type, vector<Order::Target> targets, bool addOrder) {
|
||||
Vector3 destDir = (selectingDestOrient ? GameObjectFrameController::getSingleton()->getGameObjectFrame(0).getDirVec() : Vector3::VEC_ZERO);
|
||||
depth = 1;
|
||||
Vector3 destDir = Vector3::VEC_ZERO;
|
||||
|
||||
if(selectingDestOrient){
|
||||
GameObjectFrame &objFrame = GameObjectFrameController::getSingleton()->getGameObjectFrame(0);
|
||||
destDir = objFrame.getDirVec();
|
||||
targets[0].pos = objFrame.getPos();
|
||||
}
|
||||
|
||||
mainPlayer->issueOrder(type, destDir, targets, addOrder);
|
||||
this->targets.clear();
|
||||
}
|
||||
@@ -430,34 +447,8 @@ 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){
|
||||
vector<RayCaster::CollisionResult> res = map->raycastTerrain(Vector3(pos.x, 100, pos.z), Vector3(0, -1, 0), false);
|
||||
|
||||
Vector3 waterBodyPos = Vector3::VEC_ZERO;
|
||||
Vector3 cellSize = map->getCellSize();
|
||||
|
||||
for(int i = 1; i < nodeParent->getNumChildren(); i++){
|
||||
Vector3 wpos = nodeParent->getChild(i)->getPosition();
|
||||
|
||||
if(fabs(wpos.x - pos.x) < .5 * cellSize.x && fabs(wpos.z - pos.z) < .5 * cellSize.z){
|
||||
waterBodyPos = wpos;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
results[0].pos.y = res[0].pos.y + depth * (waterBodyPos.y - res[0].pos.y);
|
||||
}
|
||||
}
|
||||
|
||||
if(!results.empty())
|
||||
targets.push_back(Order::Target(nullptr, results[0].pos));
|
||||
}
|
||||
}
|
||||
|
||||
void ActiveGameState::enableUnitState(Unit::State state){
|
||||
@@ -467,94 +458,27 @@ namespace battleship{
|
||||
unit->setState(state);
|
||||
}
|
||||
|
||||
//TODO only allow appropriate orders for units
|
||||
void ActiveGameState::onAction(int bind, bool isPressed) {
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
|
||||
if(!ConcreteGuiManager::getSingleton()->findClickedButtons().empty())
|
||||
return;
|
||||
|
||||
vector<Unit*> selectedUnits = mainPlayer->getSelectedUnits();
|
||||
|
||||
switch((Bind)bind){
|
||||
case Bind::DRAG_BOX:
|
||||
leftMouseClicked = isPressed;
|
||||
selectMouseClicked = isPressed;
|
||||
|
||||
if(isPressed){
|
||||
clickPoint = getCursorPos();
|
||||
lastLeftMouseClicked = getTime();
|
||||
lastSelectMouseClicked = getTime();
|
||||
}
|
||||
else{
|
||||
int numSelectedUnits = mainPlayer->getNumSelectedUnits();
|
||||
|
||||
if(numSelectedUnits > 0){
|
||||
if(selectingPatrolPoints){
|
||||
castRayToTerrain();
|
||||
|
||||
if(!(targets.empty() || selectingPatrolPoints)){
|
||||
Order::TYPE type = Order::TYPE::MOVE;
|
||||
|
||||
if(controlPressed || (targets[0].unit && targets[0].unit->getPlayer()->getTeam() != mainPlayer->getTeam()))
|
||||
type = Order::TYPE::ATTACK;
|
||||
else if(ufCtr->isPlacingFrames() && !selectingDestOrient)
|
||||
type = Order::TYPE::BUILD;
|
||||
|
||||
issueOrder(type, targets, shiftPressed);
|
||||
}
|
||||
}
|
||||
else if(!(selectingDestOrient || isSelectionBox)){
|
||||
bool canSelect = canSelectHoveredOnGameObj();
|
||||
bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam());
|
||||
|
||||
if(gameObjHoveredOn && gameObjHoveredOn->getType() == GameObject::Type::UNIT && ownGameObj && ((Unit*)gameObjHoveredOn)->getNumGarrisonSlots() > 0){
|
||||
bool canGarrison = true;
|
||||
|
||||
for(int i = 0; i < mainPlayer->getNumSelectedUnits(); i++)
|
||||
if(!((Unit*)gameObjHoveredOn)->canGarrison((Vehicle*)mainPlayer->getSelectedUnit(i))){
|
||||
canGarrison = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(canGarrison)
|
||||
issueOrder(Order::TYPE::GARRISON, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed);
|
||||
}
|
||||
else if(gameObjHoveredOn && ownGameObj && ((Unit*)gameObjHoveredOn)->getUnitClass() == UnitClass::EXTRACTOR && !controlPressed){
|
||||
issueOrder(Order::TYPE::SUPPLY, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed);
|
||||
}
|
||||
else if(gameObjHoveredOn && (controlPressed || (!ownGameObj && gameObjHoveredOn->getType() == GameObject::Type::UNIT)))
|
||||
issueOrder(Order::TYPE::ATTACK, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed);
|
||||
else if(controlPressed && !gameObjHoveredOn){
|
||||
castRayToTerrain();
|
||||
issueOrder(Order::TYPE::ATTACK, targets, shiftPressed);
|
||||
}
|
||||
else if(ufCtr->isPlacingFrames() && !selectingDestOrient){
|
||||
castRayToTerrain();
|
||||
GameObjectFrame gmObjFr = ufCtr->getGameObjectFrame(0);
|
||||
|
||||
if(gmObjFr.status == GameObjectFrame::NOT_PLACEABLE)
|
||||
return;
|
||||
|
||||
Unit *buildStruct = GameObjectFactory::createUnit(mainPlayer, gmObjFr.getId(), gmObjFr.getPos(), gmObjFr.getRot());
|
||||
mainPlayer->addUnit(buildStruct);
|
||||
targets[0].unit = buildStruct;
|
||||
|
||||
issueOrder(Order::TYPE::BUILD, targets, shiftPressed);
|
||||
}
|
||||
else if(canSelect){
|
||||
if(!shiftPressed)
|
||||
deselectUnits();
|
||||
|
||||
mainPlayer->selectUnit((Unit*)gameObjHoveredOn);
|
||||
}
|
||||
else if(!canSelect){
|
||||
castRayToTerrain();
|
||||
issueOrder(Order::TYPE::MOVE, targets, shiftPressed);
|
||||
}
|
||||
}
|
||||
}
|
||||
else if(numSelectedUnits == 0 && canSelectHoveredOnGameObj()){
|
||||
if(!shiftPressed) deselectUnits();
|
||||
if(!shiftPressed) deselectUnits();
|
||||
|
||||
if(canSelectHoveredOnGameObj())
|
||||
mainPlayer->selectUnit((Unit*)gameObjHoveredOn);
|
||||
}
|
||||
|
||||
selectingDestOrient = false;
|
||||
|
||||
@@ -573,12 +497,81 @@ namespace battleship{
|
||||
quad->setSize(Vector3::VEC_ZERO);
|
||||
quad->updateVerts(quad->getMeshBase());
|
||||
|
||||
ufCtr->setPlacingFrames(false);
|
||||
ufCtr->setRotatingFrames(false);
|
||||
ufCtr->toggleFrameTransformations(false, false, false);
|
||||
ufCtr->removeGameObjectFrames();
|
||||
}
|
||||
|
||||
break;
|
||||
case Bind::ROTATE_OBJ_FRAME:
|
||||
orderMouseClicked = isPressed;
|
||||
|
||||
if(isPressed)
|
||||
lastOrderMouseClicked = getTime();
|
||||
else if(!(isPressed || selectedUnits.empty())){
|
||||
if(selectingPatrolPoints){
|
||||
castRayToTerrain();
|
||||
|
||||
if(!(targets.empty() || selectingPatrolPoints)){
|
||||
Order::TYPE type = Order::TYPE::MOVE;
|
||||
|
||||
if(controlPressed || (targets[0].unit && targets[0].unit->getPlayer()->getTeam() != mainPlayer->getTeam()))
|
||||
type = Order::TYPE::ATTACK;
|
||||
else if(ufCtr->isPlacingOnSurface() && !selectingDestOrient)
|
||||
type = Order::TYPE::BUILD;
|
||||
|
||||
issueOrder(type, targets, shiftPressed);
|
||||
}
|
||||
}
|
||||
else if(!isSelectionBox){
|
||||
bool canSelect = canSelectHoveredOnGameObj();
|
||||
bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam());
|
||||
|
||||
if(gameObjHoveredOn && gameObjHoveredOn->getType() == GameObject::Type::UNIT && ownGameObj && ((Unit*)gameObjHoveredOn)->getNumGarrisonSlots() > 0){
|
||||
bool canGarrison = true;
|
||||
|
||||
for(int i = 0; i < mainPlayer->getNumSelectedUnits(); i++)
|
||||
if(!((Unit*)gameObjHoveredOn)->canGarrison((Vehicle*)mainPlayer->getSelectedUnit(i))){
|
||||
canGarrison = false;
|
||||
break;
|
||||
}
|
||||
|
||||
if(canGarrison)
|
||||
issueOrder(Order::TYPE::GARRISON, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed);
|
||||
}
|
||||
else if(gameObjHoveredOn && ownGameObj && ((Unit*)gameObjHoveredOn)->getUnitClass() == UnitClass::EXTRACTOR && !controlPressed){
|
||||
issueOrder(Order::TYPE::SUPPLY, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed);
|
||||
}
|
||||
else if(gameObjHoveredOn && (controlPressed || (!ownGameObj && gameObjHoveredOn->getType() == GameObject::Type::UNIT)))
|
||||
issueOrder(Order::TYPE::ATTACK, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed);
|
||||
else if(controlPressed && !gameObjHoveredOn){
|
||||
castRayToTerrain();
|
||||
issueOrder(Order::TYPE::ATTACK, targets, shiftPressed);
|
||||
}
|
||||
else if(selectedUnits[0]->getUnitClass() == UnitClass::ENGINEER && ufCtr->isPlacingOnSurface()){
|
||||
castRayToTerrain();
|
||||
GameObjectFrame gmObjFr = ufCtr->getGameObjectFrame(0);
|
||||
|
||||
if(gmObjFr.status == GameObjectFrame::NOT_PLACEABLE) return;
|
||||
|
||||
Unit *buildStruct = GameObjectFactory::createUnit(mainPlayer, gmObjFr.getId(), gmObjFr.getPos(), gmObjFr.getRot());
|
||||
mainPlayer->addUnit(buildStruct);
|
||||
targets[0].unit = buildStruct;
|
||||
|
||||
issueOrder(Order::TYPE::BUILD, targets, shiftPressed);
|
||||
|
||||
buildableStructSelected = false;
|
||||
}
|
||||
else if(!canSelect){
|
||||
if(targets.empty()) castRayToTerrain();
|
||||
|
||||
issueOrder(Order::TYPE::MOVE, targets, shiftPressed);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case Bind::MOVE_CAMERA:
|
||||
break;
|
||||
case Bind::ENABLE_CHASE_STATE:
|
||||
if(isPressed) enableUnitState(Unit::State::CHASE);
|
||||
break;
|
||||
@@ -588,10 +581,6 @@ namespace battleship{
|
||||
case Bind::ENABLE_HOLD_FIRE_STATE:
|
||||
if(isPressed) enableUnitState(Unit::State::HOLD_FIRE);
|
||||
break;
|
||||
case Bind::DESELECT:
|
||||
if(ufCtr->isPlacingFrames()) ufCtr->setRotatingFrames(isPressed);
|
||||
if (!isPressed) deselectUnits();
|
||||
break;
|
||||
case Bind::EJECT_GARRISON:
|
||||
if(isPressed) issueOrder(Order::TYPE::EJECT, vector<Order::Target>{}, shiftPressed);
|
||||
break;
|
||||
@@ -609,7 +598,8 @@ namespace battleship{
|
||||
|
||||
break;
|
||||
}
|
||||
case Bind::TOGGLE_SUB:
|
||||
case Bind::SHIFT_SUB_DEPTH:
|
||||
ufCtr->toggleFrameTransformations(false, false, isPressed);
|
||||
break;
|
||||
case Bind::ZOOM_IN:
|
||||
if (zooms > -NUM_MAX_ZOOMS) {
|
||||
@@ -621,12 +611,12 @@ namespace battleship{
|
||||
case Bind::ZOOM_OUT:
|
||||
if (zooms < NUM_MAX_ZOOMS) {
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
cam->setPosition(cam->getPosition() - (cam->getDirection().norm().norm() * .5f));
|
||||
cam->setPosition(cam->getPosition() - (cam->getDirection().norm() * .5f));
|
||||
zooms++;
|
||||
}
|
||||
break;
|
||||
case Bind::LOOK_AROUND:
|
||||
if(!ufCtr->isPlacingFrames())
|
||||
if(!ufCtr->isPlacingOnSurface())
|
||||
CameraController::getSingleton()->setLookingAround(isPressed);
|
||||
break;
|
||||
case Bind::HALT:
|
||||
@@ -637,18 +627,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);
|
||||
|
||||
@@ -690,8 +676,9 @@ namespace battleship{
|
||||
|
||||
break;
|
||||
case Bind::DESELECT_STRUCTURE:
|
||||
buildableStructSelected = false;
|
||||
ufCtr->toggleFrameTransformations(false, false, false);
|
||||
ufCtr->removeGameObjectFrames();
|
||||
ufCtr->setPlacingFrames(false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -708,13 +695,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;
|
||||
|
||||
+12
-2
@@ -34,6 +34,9 @@ namespace battleship{
|
||||
inline std::vector<vb01Gui::Button*> getButtons(){return buttons;}
|
||||
inline Player* getPlayer(){return mainPlayer;}
|
||||
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,
|
||||
@@ -69,11 +72,18 @@ namespace battleship{
|
||||
std::vector<Unit*> unitGroups[9];
|
||||
std::vector<Order::Target> targets;
|
||||
std::vector<vb01Gui::Button*> buttons;
|
||||
bool isSelectionBox = false, shiftPressed = false, controlPressed = false, leftMouseClicked = false, selectingPatrolPoints = false, selectingDestOrient = false;
|
||||
bool isSelectionBox = false;
|
||||
bool shiftPressed = false;
|
||||
bool controlPressed = false;
|
||||
bool selectMouseClicked = false;
|
||||
bool orderMouseClicked = false;
|
||||
bool buildableStructSelected = false;
|
||||
bool selectingPatrolPoints = false;
|
||||
bool selectingDestOrient = false;
|
||||
int playerId, zooms = 0;
|
||||
const int NUM_MAX_ZOOMS = 10;
|
||||
float depth = 1;
|
||||
vb01::s64 lastLeftMouseClicked = 0;
|
||||
vb01::s64 lastSelectMouseClicked = 0, lastOrderMouseClicked = 0;
|
||||
vb01::Node *cursorNode = nullptr;
|
||||
vb01::Texture *pointerTex = nullptr, *attackTex = nullptr, *garrisonTex = nullptr;
|
||||
};
|
||||
|
||||
@@ -21,14 +21,10 @@ namespace battleship{
|
||||
resourceAmmount = atoi(arguments[2].c_str());
|
||||
}
|
||||
|
||||
void AddResourceCommand::addResource(){
|
||||
void AddResourceCommand::execute(){
|
||||
AbstractCommand::execute();
|
||||
|
||||
Player *player = Game::getSingleton()->getPlayer(playerId);
|
||||
player->updateResource(ResourceType(resourceId), resourceAmmount, true);
|
||||
}
|
||||
|
||||
void AddResourceCommand::execute(){
|
||||
AbstractCommand::handle();
|
||||
validate();
|
||||
addResource();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ namespace battleship{
|
||||
void execute();
|
||||
private:
|
||||
void validate();
|
||||
void addResource();
|
||||
|
||||
int playerId, resourceId, resourceAmmount;
|
||||
};
|
||||
|
||||
@@ -30,13 +30,8 @@ namespace battleship{
|
||||
return;
|
||||
}
|
||||
|
||||
void AddTechnologyCommand::addTechnology(){
|
||||
void AddTechnologyCommand::execute(){
|
||||
AbstractCommand::execute();
|
||||
Game::getSingleton()->getPlayer(playerId)->addTechnology(techId);
|
||||
}
|
||||
|
||||
void AddTechnologyCommand::execute(){
|
||||
AbstractCommand::handle();
|
||||
validate();
|
||||
addTechnology();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,7 +10,6 @@ namespace battleship{
|
||||
void execute();
|
||||
private:
|
||||
void validate();
|
||||
void addTechnology();
|
||||
|
||||
int playerId, techId;
|
||||
};
|
||||
|
||||
+3
-7
@@ -54,14 +54,10 @@ namespace battleship{
|
||||
return;
|
||||
}
|
||||
|
||||
void AddUnitCommand::addUnit(){
|
||||
void AddUnitCommand::execute(){
|
||||
AbstractCommand::execute();
|
||||
|
||||
Player* player = Game::getSingleton()->getPlayer(playerId);
|
||||
player->addUnit(GameObjectFactory::createUnit(player, unitId, pos, rot, 100));
|
||||
}
|
||||
|
||||
void AddUnitCommand::execute(){
|
||||
AbstractCommand::handle();
|
||||
validate();
|
||||
addUnit();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -17,8 +17,6 @@ namespace battleship{
|
||||
bool posEnabled, rotEnabled;
|
||||
vb01::Vector3 pos = vb01::Vector3::VEC_ZERO;
|
||||
vb01::Quaternion rot = vb01::Quaternion::QUAT_W;
|
||||
|
||||
void addUnit();
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -16,7 +16,7 @@ namespace battleship{
|
||||
LOOK_RIGHT,
|
||||
LOOK_AROUND,
|
||||
DRAG_BOX,
|
||||
DESELECT,
|
||||
ROTATE_OBJ_FRAME,
|
||||
HALT,
|
||||
ZOOM_IN,
|
||||
ZOOM_OUT,
|
||||
@@ -24,7 +24,7 @@ namespace battleship{
|
||||
LEFT_SHIFT,
|
||||
SELECT_PATROL_POINTS,
|
||||
LAUNCH,
|
||||
TOGGLE_SUB,
|
||||
SHIFT_SUB_DEPTH,
|
||||
GROUP_0,
|
||||
GROUP_1,
|
||||
GROUP_2,
|
||||
@@ -54,7 +54,8 @@ namespace battleship{
|
||||
ENABLE_CHASE_STATE,
|
||||
ENABLE_STAND_GROUND_STATE,
|
||||
ENABLE_HOLD_FIRE_STATE,
|
||||
HACK
|
||||
HACK,
|
||||
MOVE_CAMERA
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
+2
-1
@@ -27,7 +27,8 @@ 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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+4
-1
@@ -2,13 +2,14 @@
|
||||
#include "addUnitCommand.h"
|
||||
#include "addResourceCommand.h"
|
||||
#include "addTechnologyCommand.h"
|
||||
#include "toggleDebugCommand.h"
|
||||
|
||||
using namespace std;
|
||||
|
||||
namespace battleship{
|
||||
void Console::execute(string cmdStr) {
|
||||
int space = cmdStr.find(" ");
|
||||
string cmdName, argsStr;
|
||||
string cmdName = cmdStr, argsStr = "";
|
||||
|
||||
if(space != -1){
|
||||
cmdName = cmdStr.substr(0, space);
|
||||
@@ -21,5 +22,7 @@ namespace battleship{
|
||||
AddResourceCommand(argsStr).execute();
|
||||
else if(cmdName == "add-technology")
|
||||
AddTechnologyCommand(argsStr).execute();
|
||||
else if(cmdName == "toggle-debug")
|
||||
ToggleDebugCommand(argsStr).execute();
|
||||
}
|
||||
}
|
||||
|
||||
+4
-3
@@ -20,7 +20,7 @@ namespace battleship{
|
||||
using namespace gameBase;
|
||||
|
||||
const std::string DEFAULT_TEXTURE = "Textures/defaultTexture.jpg";
|
||||
const double camPanSpeed = .5, CAMERA_DISTANCE = 100, CAMERA_ZOOM_INCREMENT = 1, cellLength = 14, cellWidth = 14, cellDepth = 7, DIST_FROM_RAY = 20;
|
||||
const double camPanSpeed = .5, CAMERA_DISTANCE = 100, CAMERA_ZOOM_INCREMENT = 1, cellLength = 7, cellWidth = 7, cellDepth = 7, DIST_FROM_RAY = 15;
|
||||
const int maxNumGroups = 10, NUM_MAX_ZOOMS = 75;
|
||||
const vb01::u32 IMPASS_NODE_VAL = 65535;
|
||||
|
||||
@@ -88,7 +88,8 @@ namespace battleship{
|
||||
},
|
||||
{
|
||||
Bind::DRAG_BOX,
|
||||
Bind::DESELECT,
|
||||
Bind::MOVE_CAMERA,
|
||||
Bind::ROTATE_OBJ_FRAME,
|
||||
Bind::HALT,
|
||||
Bind::ZOOM_IN,
|
||||
Bind::ZOOM_OUT,
|
||||
@@ -96,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,
|
||||
|
||||
Vendored
+1
-1
Submodule external/vb01 updated: e39f9e358d...21e742f930
+1
-1
@@ -73,7 +73,7 @@ namespace battleship{
|
||||
if(trainingStatus >= 100){
|
||||
Unit *unit = GameObjectFactory::createUnit(player, unitQueue[0], pos, rot);
|
||||
player->addUnit(unit);
|
||||
unit->setOrder(Order(Order::TYPE::MOVE, vector<Order::Target>{Order::Target(nullptr, pos + 30 * dirVec)}, Vector3::VEC_ZERO));
|
||||
unit->receiveOrder(Order(Order::TYPE::MOVE, vector<Order::Target>{Order::Target(nullptr, pos + 30 * dirVec)}, Vector3::VEC_ZERO), false);
|
||||
|
||||
unitQueue.erase(unitQueue.begin());
|
||||
trainingStatus = 0;
|
||||
|
||||
@@ -118,22 +118,24 @@ namespace battleship{
|
||||
AssetManager::getSingleton()->load(gm->getPath() + gop, true);
|
||||
AssetManager::getSingleton()->load(gm->getPath() + vfxp, true);
|
||||
|
||||
vector<GameObject*> gameObjs;
|
||||
if(debug){
|
||||
vector<GameObject*> gameObjs;
|
||||
|
||||
for(Player *pl : Game::getSingleton()->getPlayers()){
|
||||
for(Unit *u : pl->getUnits())
|
||||
gameObjs.push_back((GameObject*)u);
|
||||
for(Player *pl : Game::getSingleton()->getPlayers()){
|
||||
for(Unit *u : pl->getUnits())
|
||||
gameObjs.push_back((GameObject*)u);
|
||||
|
||||
for(Projectile *proj : pl->getProjectiles())
|
||||
gameObjs.push_back((GameObject*)proj);
|
||||
for(Projectile *proj : pl->getProjectiles())
|
||||
gameObjs.push_back((GameObject*)proj);
|
||||
|
||||
for(ResourceDeposit *dep : pl->getResourceDeposits())
|
||||
gameObjs.push_back((GameObject*)dep);
|
||||
for(ResourceDeposit *dep : pl->getResourceDeposits())
|
||||
gameObjs.push_back((GameObject*)dep);
|
||||
}
|
||||
|
||||
for(GameObject *obj : gameObjs)
|
||||
obj->reinit();
|
||||
}
|
||||
|
||||
for(GameObject *obj : gameObjs)
|
||||
obj->reinit();
|
||||
|
||||
gm->getStateManager()->attachAppState(activeState);
|
||||
}
|
||||
|
||||
|
||||
@@ -28,8 +28,10 @@ namespace battleship{
|
||||
float calcAbilFromTech(Ability::Type, std::vector<int>, int, int);
|
||||
bool isUnitUnlocked(std::vector<int>, int);
|
||||
std::vector<TradeOffer*> findTradeOffers(Player*, Player*);
|
||||
inline void setDebug(bool d){this->debug = d;}
|
||||
inline void addTradeOffer(TradeOffer *to){tradeOffers.push_back(to);}
|
||||
inline void addPlayer(Player *pl){players.push_back(pl);}
|
||||
inline bool isDebug(){return debug;}
|
||||
inline std::vector<Player*>& getPlayers(){return players;}
|
||||
inline Player* getPlayer(int id){return players[id];}
|
||||
inline int getNumPlayers(){return players.size();}
|
||||
@@ -41,7 +43,7 @@ namespace battleship{
|
||||
void endGame(bool);
|
||||
std::vector<int> parseTechTable(int, std::string, std::string, std::string);
|
||||
|
||||
bool paused = false, ended = false;
|
||||
bool paused = false, ended = false, debug = false;
|
||||
std::vector<Technology> technologies;
|
||||
std::vector<Ability> abilities;
|
||||
std::vector<Player*> players;
|
||||
|
||||
+12
-10
@@ -51,16 +51,18 @@ namespace battleship{
|
||||
|
||||
//TODO remove neccessity to create a material for an invisible mesh
|
||||
void GameObject::initHitbox(){
|
||||
Box *box = new Box(Vector3(width, height, length));
|
||||
box->setWireframe(true);
|
||||
|
||||
Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
mat->addBoolUniform("texturingEnabled", false);
|
||||
mat->addBoolUniform("lightingEnabled", false);
|
||||
mat->addVec4Uniform("diffuseColor", Vector4(1, 1, 1, 1));
|
||||
|
||||
Box *box = new Box(Vector3(width, height, length));
|
||||
box->setWireframe(true);
|
||||
box->setMaterial(mat);
|
||||
|
||||
sol::table gameObjTable = generateView()[GameObject::getGameObjTableName()][id + 1];
|
||||
sol::table offsetPosTable = gameObjTable["hitboxOffset"];
|
||||
|
||||
hitbox = new Node(Vector3(offsetPosTable["x"], offsetPosTable["y"], offsetPosTable["z"]));
|
||||
hitbox->attachMesh(box);
|
||||
hitbox->setVisible(true);
|
||||
@@ -68,7 +70,6 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void GameObject::destroyHitbox(){
|
||||
hitbox->dettachMesh(0);
|
||||
model->dettachChild(hitbox);
|
||||
delete hitbox;
|
||||
}
|
||||
@@ -81,6 +82,9 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void GameObject::destroyModel(){
|
||||
if(model->getMaterial())
|
||||
delete model->getMaterial();
|
||||
|
||||
Root::getSingleton()->getRootNode()->dettachChild(model);
|
||||
delete model;
|
||||
}
|
||||
@@ -88,19 +92,17 @@ namespace battleship{
|
||||
//TODO improve DEFAULT_TEXTURE handling
|
||||
void GameObject::initModel(bool textured){
|
||||
sol::table gameObjTable = generateView()[GameObject::getGameObjTableName()][id + 1];
|
||||
string basePath = gameObjTable["basePath"];
|
||||
string meshPath = gameObjTable["meshPath"];
|
||||
|
||||
string basePath = gameObjTable["basePath"], meshPath = gameObjTable["meshPath"];
|
||||
model = new Model(basePath + meshPath);
|
||||
Root *root = Root::getSingleton();
|
||||
string libPath = root->getLibPath();
|
||||
|
||||
Material *mat = new Material(libPath + "texture");
|
||||
Root *root = Root::getSingleton();
|
||||
Material *mat = new Material(root->getLibPath() + "texture");
|
||||
|
||||
if(textured){
|
||||
string albedoPath = gameObjTable["albedoPath"].get_or(configData::DEFAULT_TEXTURE);
|
||||
string f[]{albedoPath == configData::DEFAULT_TEXTURE ? GameManager::getSingleton()->getPath() + albedoPath : basePath + albedoPath};
|
||||
Texture *diffuseTexture = new Texture(f, 1, false);
|
||||
|
||||
mat->addBoolUniform("texturingEnabled", true);
|
||||
mat->addBoolUniform("lightingEnabled", true);
|
||||
mat->addBoolUniform("constLightingEnabled", false);
|
||||
|
||||
@@ -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{
|
||||
@@ -52,6 +55,7 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
//TODO specify what to snap the frame to
|
||||
void GameObjectFrameController::snapToObj(GameObjectFrame &s, GameObject::Type type, int unitId, float maxDist){
|
||||
if(s.getType() == GameObject::Type::UNIT && s.getId() == unitId){
|
||||
s.status = GameObjectFrame::NOT_PLACEABLE;
|
||||
@@ -79,6 +83,7 @@ namespace battleship{
|
||||
|
||||
//TODO implement terrain evenness check
|
||||
//TODO factor out literal values
|
||||
//TODO fix which unit frames light green or red
|
||||
void GameObjectFrameController::placeGameObjectFrame(int id, Vector3 newPos, float width, float length){
|
||||
Map *map = Map::getSingleton();
|
||||
MeshData meshData = map->getNodeParent()->getChild(0)->getMesh(0)->getMeshBase();
|
||||
@@ -86,6 +91,7 @@ namespace battleship{
|
||||
int numVerts = 3 * meshData.numTris;
|
||||
|
||||
float maxUnevenness = .5, unevenness = 0;
|
||||
bool placeable = true;
|
||||
|
||||
for(int i = 0; i < numVerts; i++){
|
||||
float diffX = fabs(newPos.x - verts[i].pos->x);
|
||||
@@ -95,53 +101,113 @@ namespace battleship{
|
||||
if(diffX < 0.5 * width && diffZ < 0.5 * length && diffY > unevenness){
|
||||
unevenness = diffY;
|
||||
|
||||
if(unevenness > maxUnevenness)
|
||||
if(unevenness > maxUnevenness){
|
||||
placeable = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
GameObjectFrame &s = gameObjectFrames[id];
|
||||
s.placeAt(newPos);
|
||||
|
||||
if(!rotatingStructure)
|
||||
s.placeAt(newPos);
|
||||
|
||||
s.status = (unevenness < maxUnevenness ? GameObjectFrame::PLACEABLE : GameObjectFrame::NOT_PLACEABLE);
|
||||
snapToObj(s, GameObject::Type::UNIT, 20, 3);
|
||||
|
||||
Vector4 color;
|
||||
|
||||
if(placeable){
|
||||
s.status = GameObjectFrame::PLACEABLE;
|
||||
color = Vector4(0, 1, 0, 1);
|
||||
}
|
||||
else{
|
||||
s.status = GameObjectFrame::NOT_PLACEABLE;
|
||||
color = Vector4(1, 0, 0, 1);
|
||||
}
|
||||
|
||||
Material *mat = s.getModel()->getMaterial();
|
||||
Vector4 color = (s.status == GameObjectFrame::NOT_PLACEABLE ? Vector4(1, 0, 0, 1) : Vector4(0, 1, 0, 1));
|
||||
mat->setVec4Uniform("diffuseColor", color);
|
||||
}
|
||||
|
||||
void GameObjectFrameController::update(){
|
||||
void GameObjectFrameController::updatePlacement(){
|
||||
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, (screenToSpace(getCursorPos()) - 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 - placementPos.x) < .5 * wSize.x && fabs(wPos.z - placementPos.z) < .5 * wSize.y){
|
||||
waterBodyPos = wPos;
|
||||
inWater = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(!inWater) return;
|
||||
|
||||
vector<RayCaster::CollisionResult> res = map->raycastTerrain(
|
||||
Vector3(placementPos.x, 100, placementPos.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 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;
|
||||
}
|
||||
|
||||
placeGameObjectFrame(i, newPos, width, length);
|
||||
if(!rotating && (placingOnSurface || placingVertically))
|
||||
placeGameObjectFrame(i, placementPos, width, length);
|
||||
}
|
||||
}
|
||||
|
||||
void GameObjectFrameController::update(){
|
||||
updatePlacement();
|
||||
|
||||
if(!placingVertically) minDepthCalculated = false;
|
||||
}
|
||||
|
||||
void GameObjectFrameController::removeGameObjectFrame(int i){
|
||||
gameObjectFrames[i].destroy();
|
||||
gameObjectFrames.erase(gameObjectFrames.begin() + i);
|
||||
|
||||
@@ -21,25 +21,34 @@ namespace battleship{
|
||||
void removeGameObjectFrame(int);
|
||||
void removeGameObjectFrames();
|
||||
void rotateGameObjectFrames(float);
|
||||
void placeGameObjectFrame(int, vb01::Vector3, float, float);
|
||||
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;}
|
||||
inline void toggleFrameTransformations(bool rot, bool pos, bool pv){
|
||||
setRotating(rot);
|
||||
setPlacingOnSurface(pos);
|
||||
setPlacingVertically(pv);
|
||||
}
|
||||
private:
|
||||
GameObjectFrameController(){}
|
||||
void paintSelect(vb01::Vector3, float, float);
|
||||
void placeGameObjectFrame(int, vb01::Vector3, float, float);
|
||||
void snapToObj(GameObjectFrame&, GameObject::Type, int, float);
|
||||
void updatePlacement();
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
@@ -520,7 +520,7 @@ namespace battleship{
|
||||
void Map::load(string mapName){
|
||||
this->mapName = mapName;
|
||||
|
||||
Pathfinder::getSingleton()->setImpassibleNodeVal(u16(0 - 1));
|
||||
Pathfinder::getSingleton()->setImpassibleNodeVal(u32(0 - 1));
|
||||
string path = GameManager::getSingleton()->getPath();
|
||||
AssetManager::getSingleton()->load(path + "Textures/", true);
|
||||
|
||||
@@ -698,6 +698,8 @@ namespace battleship{
|
||||
if(fabs(cells[cellId].pos.y - pos.y) < .5 * CELL_SIZE.y)
|
||||
return cellId;
|
||||
}
|
||||
|
||||
return cellId;
|
||||
}
|
||||
else
|
||||
return surfaceCellId;
|
||||
|
||||
+11
-13
@@ -333,23 +333,20 @@ namespace battleship{
|
||||
//TODO add diagnally adjacent edges to underwater cells
|
||||
vector<Map::Cell> MapEditorAppState::MapEditor::generateMapCells(){
|
||||
Vector3 mapSize = map->getMapSize();
|
||||
Vector3 startPos = -.49 * Vector3(mapSize.x, 0, mapSize.z), cellSize = map->getCellSize();
|
||||
Vector3 cellSize = map->getCellSize();
|
||||
Vector3 startPos = -.5 * (Vector3(mapSize.x, 0, mapSize.z) - Vector3(cellSize.x, 0, cellSize.z));
|
||||
|
||||
int numHorCells = int(mapSize.x / cellSize.x);
|
||||
int numVertCells = int(mapSize.z / cellSize.z);
|
||||
vector<Map::Cell> cells;
|
||||
vector<pair<int, float>> waterBodyBedPoints;
|
||||
Node *terrainNode = map->getNodeParent();
|
||||
|
||||
|
||||
for(int i = 0; i < numVertCells; i++)
|
||||
for(int j = 0; j < numHorCells; j++){
|
||||
Vector3 rayPos = startPos + Vector3(cellSize.x * j, 100, cellSize.z * i);
|
||||
vector<RayCaster::CollisionResult> res = RayCaster::cast(rayPos, -Vector3::VEC_J, terrainNode->getChild(0), 0, configData::DIST_FROM_RAY);
|
||||
|
||||
if(res.empty()){
|
||||
RayCaster::CollisionResult r;
|
||||
r.pos = Vector3(rayPos.x, 0, rayPos.z);
|
||||
res.push_back(r);
|
||||
}
|
||||
|
||||
Map::Cell::Type type = Map::Cell::Type::LAND;
|
||||
Vector3 pos = res[0].pos;
|
||||
@@ -367,7 +364,8 @@ namespace battleship{
|
||||
}
|
||||
|
||||
vector<Map::Edge> edges = Map::generateAdjacentNodeEdges(numVertCells, i, numHorCells, j, 10);
|
||||
cells.push_back(Map::Cell(pos, type, edges));
|
||||
Map::Cell cell = Map::Cell(pos, type, edges);
|
||||
cells.push_back(cell);
|
||||
}
|
||||
|
||||
vector<Map::Cell> surfaceWaterCells;
|
||||
@@ -389,7 +387,7 @@ namespace battleship{
|
||||
|
||||
for(int i = 0; i < surfaceWaterCells.size(); i++){
|
||||
for(int j = 0; j < surfaceWaterCells[i].underWaterCellIds.size(); j++){
|
||||
int aboveCellId = (j == 0 ? surfaceWaterCells[i].edges[0].srcCellId : j - 1);
|
||||
int aboveCellId = (j == 0 ? surfaceWaterCells[i].edges[0].srcCellId : surfaceWaterCells[i].underWaterCellIds[j - 1]);
|
||||
vector<Map::Edge> edges = vector<Map::Edge>{Map::Edge(weight, surfaceWaterCells[i].underWaterCellIds[j], aboveCellId)};
|
||||
|
||||
if(surfaceWaterCells[i].underWaterCellIds.size() > j + 1)
|
||||
@@ -626,7 +624,7 @@ namespace battleship{
|
||||
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
|
||||
if(ufCtr->isPlacingFrames())
|
||||
if(ufCtr->isPlacingOnSurface())
|
||||
ufCtr->update();
|
||||
}
|
||||
|
||||
@@ -661,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,9 +676,9 @@ namespace battleship{
|
||||
CameraController::getSingleton()->setLookingAround(isPressed);
|
||||
|
||||
break;
|
||||
case Bind::DESELECT_STRUCTURE:
|
||||
case Bind::ROTATE_OBJ_FRAME:
|
||||
ufCtr->removeGameObjectFrames();
|
||||
ufCtr->setPlacingFrames(false);
|
||||
ufCtr->setPlacingOnSurface(false);
|
||||
break;
|
||||
case Bind::INCREASE_RADIUS:
|
||||
if(isPressed) mapEditor->updateCircleRadius(true);
|
||||
|
||||
+36
-27
@@ -16,55 +16,64 @@ namespace battleship{
|
||||
return pathfinder;
|
||||
}
|
||||
|
||||
int Pathfinder::findMinDistVert(vector<pair<int, bool>> &cells, u32 distances[]){
|
||||
int numCells = cells.size(), minDistVert;
|
||||
|
||||
for(int i = 0; i < numCells; i++)
|
||||
if(!cells[i].second){
|
||||
minDistVert = i;
|
||||
break;
|
||||
}
|
||||
|
||||
for(int i = 0; i < numCells; i++){
|
||||
bool checked = cells[i].second;
|
||||
|
||||
if(!checked && distances[i] < distances[minDistVert])
|
||||
minDistVert = i;
|
||||
}
|
||||
|
||||
return minDistVert;
|
||||
}
|
||||
|
||||
vector<int> Pathfinder::findPath(vector<Map::Cell> &cells, int source, int dest, int unitType){
|
||||
vector<int> Pathfinder::findPath(vector<Map::Cell> &cells, vector<float> &heuristics, int source, int dest, int unitType){
|
||||
const int size = cells.size();
|
||||
u32 *distances = new u32[size];
|
||||
vector<int> *paths = new vector<int>[size];
|
||||
paths[source].push_back(source);
|
||||
|
||||
vector<pair<int, bool>> cellsByCheck;
|
||||
|
||||
vector<bool> cellChecked;
|
||||
|
||||
for(int i = 0; i < size; i++){
|
||||
cellsByCheck.push_back(pair(i, false));
|
||||
distances[i] = (i == source ? 0 : impassibleNodeVal);
|
||||
cellChecked.push_back(false);
|
||||
}
|
||||
|
||||
bool useHeur = !heuristics.empty();
|
||||
vector<int> possibleMinCells = vector<int>{source};
|
||||
cellChecked[source] = true;
|
||||
|
||||
while(!cellsByCheck[dest].second){
|
||||
int vertStrich = findMinDistVert(cellsByCheck, distances);
|
||||
int vertStrich = possibleMinCells[0], vsId = 0;
|
||||
|
||||
for(int i = 0; i < possibleMinCells.size(); i++){
|
||||
float sum1 = distances[possibleMinCells[i]] + (useHeur ? heuristics[possibleMinCells[i]] : 0);
|
||||
float sum2 = distances[possibleMinCells[vsId]] + (useHeur ? heuristics[possibleMinCells[vsId]] : 0);
|
||||
|
||||
if(sum1 < sum2 || (useHeur && sum1 == sum2 && heuristics[i] < heuristics[vertStrich])){
|
||||
vertStrich = possibleMinCells[i];
|
||||
vsId = i;
|
||||
}
|
||||
}
|
||||
|
||||
cellChecked[possibleMinCells[vsId]] = false;
|
||||
possibleMinCells.erase(possibleMinCells.begin() + vsId);
|
||||
|
||||
cellsByCheck[vertStrich].second = true;
|
||||
|
||||
int numEdges = cells[vertStrich].edges.size();
|
||||
|
||||
for(int i = 0; i < numEdges; i++){
|
||||
int edgeNode = cells[vertStrich].edges[i].destCellId;
|
||||
|
||||
if(cellsByCheck[edgeNode].second) continue;
|
||||
|
||||
if(!cellChecked[edgeNode]){
|
||||
cellChecked[edgeNode] = true;
|
||||
possibleMinCells.push_back(edgeNode);
|
||||
}
|
||||
|
||||
bool canMoveToStrichCell = true;
|
||||
bool ship = ((UnitType)unitType == UnitType::UNDERWATER || (UnitType)unitType == UnitType::SEA_LEVEL);
|
||||
|
||||
if((ship && cells[vertStrich].type != Map::Cell::WATER) || ((UnitType)unitType == UnitType::LAND && cells[vertStrich].type != Map::Cell::LAND))
|
||||
canMoveToStrichCell = false;
|
||||
continue;
|
||||
|
||||
int edgeNode = cells[vertStrich].edges[i].destCellId, cellTypeFactor = (canMoveToStrichCell ? 1 : 100);
|
||||
bool isChecked = cellsByCheck[edgeNode].second;
|
||||
|
||||
if(!isChecked && (distances[vertStrich] + cells[vertStrich].edges[i].weight * cellTypeFactor < distances[edgeNode])){
|
||||
distances[edgeNode] = distances[vertStrich] + cells[vertStrich].edges[i].weight * cellTypeFactor;
|
||||
if(distances[vertStrich] + cells[vertStrich].edges[i].weight < distances[edgeNode]){
|
||||
distances[edgeNode] = distances[vertStrich] + cells[vertStrich].edges[i].weight;
|
||||
paths[edgeNode] = paths[vertStrich];
|
||||
paths[edgeNode].push_back(edgeNode);
|
||||
}
|
||||
|
||||
+1
-2
@@ -11,12 +11,11 @@ namespace battleship{
|
||||
class Pathfinder{
|
||||
public:
|
||||
static Pathfinder* getSingleton();
|
||||
std::vector<int> findPath(std::vector<Map::Cell>&, int, int, int = -1);
|
||||
std::vector<int> findPath(std::vector<Map::Cell>&, std::vector<float>&, int, int, int = -1);
|
||||
inline vb01::u32 getImpassibleNodeVal(){return impassibleNodeVal;}
|
||||
inline void setImpassibleNodeVal(vb01::u32 val){this->impassibleNodeVal = val;}
|
||||
private:
|
||||
Pathfinder(){}
|
||||
int findMinDistVert(std::vector<std::pair<int, bool>>&, vb01::u32[]);
|
||||
|
||||
vb01::u32 impassibleNodeVal;
|
||||
};
|
||||
|
||||
+28
-6
@@ -1,6 +1,7 @@
|
||||
#include "pathfinderTest.h"
|
||||
#include "pathfinder.h"
|
||||
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <vector>
|
||||
@@ -11,11 +12,12 @@ namespace battleship{
|
||||
|
||||
vector<Map::Cell> PathfinderTest::generateCellGraph(int numCellsOnSide){
|
||||
vector<Map::Cell> cells;
|
||||
float cellSize = 2;
|
||||
|
||||
for(int i = 0; i < numCellsOnSide; i++)
|
||||
for(int j = 0; j < numCellsOnSide; j++){
|
||||
vector<Map::Edge> edges = Map::generateAdjacentNodeEdges(numCellsOnSide, i, numCellsOnSide, j, 1);
|
||||
cells.push_back(Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, edges));
|
||||
vector<Map::Edge> edges = Map::generateAdjacentNodeEdges(numCellsOnSide, i, numCellsOnSide, j, 1000);
|
||||
cells.push_back(Map::Cell(Vector3(j * cellSize, 0, i * cellSize), Map::Cell::Type::LAND, edges));
|
||||
}
|
||||
|
||||
return cells;
|
||||
@@ -32,6 +34,22 @@ namespace battleship{
|
||||
return sumPathWeights;
|
||||
}
|
||||
|
||||
vector<float> PathfinderTest::generateHeuristics(vector<Map::Cell> &cells, int dest, int type){
|
||||
vector<float> heur;
|
||||
int numSideCells = sqrt(cells.size());
|
||||
|
||||
if(type == 0)
|
||||
for(Map::Cell &cell : cells)
|
||||
heur.push_back(145 * cells[dest].pos.getDistanceFrom(cell.pos));
|
||||
else if(type == 1)
|
||||
for(int i = 0; i < cells.size(); i++){
|
||||
int x = i % numSideCells, y = i / numSideCells;
|
||||
heur.push_back(2 * (numSideCells - 1) - (x + y));
|
||||
}
|
||||
|
||||
return heur;
|
||||
}
|
||||
|
||||
void PathfinderTest::testFindPath(){
|
||||
cells = vector<Map::Cell>{
|
||||
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 0, 0), Map::Edge(2, 0, 1), Map::Edge(4, 0, 2)}),
|
||||
@@ -46,7 +64,9 @@ namespace battleship{
|
||||
const u16 INF = u16(0 - 1);
|
||||
pathfinder->setImpassibleNodeVal(INF);
|
||||
|
||||
vector<int> path = pathfinder->findPath(cells, 0, cells.size() - 1);
|
||||
int src = 0, dest = cells.size() - 1;
|
||||
vector<float> heur;
|
||||
vector<int> path = pathfinder->findPath(cells, heur, src, dest, 3);
|
||||
CPPUNIT_ASSERT(path == vector<int>({0, 1, 2, 4, 3, 6}));
|
||||
|
||||
int sumPathWeights = calcPathLength(path);
|
||||
@@ -54,13 +74,15 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void PathfinderTest::testFindBigPath(){
|
||||
int numIterations = 1;
|
||||
cells = generateCellGraph(60);
|
||||
cells = generateCellGraph(250);
|
||||
int numIterations = 1, src = 0, dest = cells.size() - 1;
|
||||
vector<float> heur;
|
||||
heur = generateHeuristics(cells, dest, 0);
|
||||
s64 sumTime = 0;
|
||||
|
||||
for(int i = 0; i < numIterations; i++){
|
||||
s64 t0 = getTime();
|
||||
pathfinder->findPath(cells, 0, cells.size() - 1);
|
||||
pathfinder->findPath(cells, heur, src, dest, 3);
|
||||
s64 t1 = getTime();
|
||||
sumTime += t1 - t0;
|
||||
}
|
||||
|
||||
@@ -26,6 +26,7 @@ namespace battleship{
|
||||
std::vector<Map::Cell> cells;
|
||||
|
||||
std::vector<Map::Cell> generateCellGraph(int);
|
||||
std::vector<float> generateHeuristics(std::vector<Map::Cell>&, int, int = 0);
|
||||
int calcPathLength(std::vector<int>&);
|
||||
};
|
||||
}
|
||||
|
||||
+2
-21
@@ -88,22 +88,8 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void Player::issueOrder(Order::TYPE type, Vector3 destDir, vector<Order::Target> targets, bool append){
|
||||
if(type != Order::TYPE::EJECT && targets.empty()) return;
|
||||
|
||||
vector<Unit*> selectedUnits = getSelectedUnits();
|
||||
|
||||
if(type == Order::TYPE::EJECT){
|
||||
for(Unit *u : selectedUnits){
|
||||
const vector<Unit::GarrisonSlot> &garrisonSlots = u->getGarrisonSlots();
|
||||
|
||||
for(Unit::GarrisonSlot slot : garrisonSlots)
|
||||
if(slot.vehicle)
|
||||
targets.push_back(Order::Target((Unit*)slot.vehicle));
|
||||
}
|
||||
}
|
||||
else if(type != Order::TYPE::PATROL)
|
||||
targets.push_back(Order::Target());
|
||||
|
||||
for (Unit *u : selectedUnits) {
|
||||
bool targetingSelf = false, structBuilt = true;
|
||||
|
||||
@@ -124,15 +110,10 @@ namespace battleship{
|
||||
int lineId = -1;
|
||||
ActiveGameState *activeState = ((ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE));
|
||||
|
||||
if(activeState && activeState->getPlayer() == this)
|
||||
if(activeState && activeState->getPlayer() == this && type != Order::TYPE::EJECT)
|
||||
lineId = getOrderLineId(type, u->getPos(), targets[0].pos);
|
||||
|
||||
Order order(type, targets, destDir, lineId);
|
||||
|
||||
if (append)
|
||||
u->addOrder(order);
|
||||
else
|
||||
u->setOrder(order);
|
||||
u->receiveOrder(Order(type, targets, destDir, lineId), append);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,15 @@
|
||||
#include "toggleDebugCommand.h"
|
||||
#include "game.h"
|
||||
|
||||
namespace battleship{
|
||||
void ToggleDebugCommand::validate(){
|
||||
if(!arguments.empty()) return;
|
||||
}
|
||||
|
||||
void ToggleDebugCommand::execute(){
|
||||
AbstractCommand::execute();
|
||||
|
||||
Game *game = Game::getSingleton();
|
||||
game->setDebug(!game->isDebug());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,16 @@
|
||||
#ifndef TOGGLE_DEBUG_COMMAND_H
|
||||
#define TOGGLE_DEBUG_COMMAND_H
|
||||
|
||||
#include "abstractCommand.h"
|
||||
|
||||
namespace battleship{
|
||||
class ToggleDebugCommand : public AbstractCommand{
|
||||
public:
|
||||
ToggleDebugCommand(std::string str) : AbstractCommand(str){}
|
||||
void validate();
|
||||
void execute();
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -322,9 +322,11 @@ namespace battleship{
|
||||
vector<int> currTechs = player->getTechnologies();
|
||||
|
||||
string name = unitTable["name"];
|
||||
health = unitTable["health"]; health += game->calcAbilFromTech(Ability::Type::HEALTH, currTechs, (int)GameObject::type, id);
|
||||
vehicle = unitTable["isVehicle"];
|
||||
maxHealth = health;
|
||||
health += game->calcAbilFromTech(Ability::Type::HEALTH, currTechs, (int)GameObject::type, id);
|
||||
maxHealth = unitTable["health"];
|
||||
|
||||
if(health == 0) health = maxHealth;
|
||||
|
||||
lineOfSight = unitTable["lineOfSight"]; lineOfSight += game->calcAbilFromTech(Ability::Type::LINE_OF_SIGHT, currTechs, (int)GameObject::type, id);
|
||||
unitClass = (UnitClass)unitTable["unitClass"];
|
||||
@@ -441,6 +443,9 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void Unit::reinit(){
|
||||
if(losLightNode)
|
||||
destroyLosLight();
|
||||
|
||||
destroyWeapons();
|
||||
destroyHitbox();
|
||||
destroyModel();
|
||||
@@ -539,7 +544,7 @@ namespace battleship{
|
||||
if(orders.empty())
|
||||
for(Unit *unit : units)
|
||||
if(unit->getPos().getDistanceFrom(pos) < lineOfSight){
|
||||
setOrder(Order(Order::TYPE::ATTACK, vector<Order::Target>{Order::Target(unit)}, Vector3::VEC_ZERO, -1, false));
|
||||
receiveOrder(Order(Order::TYPE::ATTACK, vector<Order::Target>{Order::Target(unit)}, Vector3::VEC_ZERO, -1, false), false);
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -646,17 +651,16 @@ namespace battleship{
|
||||
adjWaterCellId = edge.destCellId;
|
||||
}
|
||||
|
||||
if(garrisonSlots.size() > 0){
|
||||
for(Order::Target targ : order.targets){
|
||||
bool exitToLandCell = (targ.unit->getType() == UnitType::LAND && adjLandCellId != -1);
|
||||
bool exitToWaterCell = ((targ.unit->getType() == UnitType::SEA_LEVEL || targ.unit->getType() == UnitType::UNDERWATER) && adjWaterCellId != -1);
|
||||
|
||||
for(GarrisonSlot &slot : garrisonSlots)
|
||||
if(slot.vehicle){
|
||||
bool exitToLandCell = (slot.vehicle->getType() == UnitType::LAND && adjLandCellId != -1);
|
||||
bool exitToWaterCell = ((slot.vehicle->getType() == UnitType::SEA_LEVEL || slot.vehicle->getType() == UnitType::UNDERWATER) && adjWaterCellId != -1);
|
||||
|
||||
if(exitToLandCell || exitToWaterCell)
|
||||
((Vehicle*)targ.unit)->exitGarrisonable(cells[exitToLandCell ? adjLandCellId : adjWaterCellId].pos);
|
||||
slot.vehicle->exitGarrisonable(cells[exitToLandCell ? adjLandCellId : adjWaterCellId].pos);
|
||||
}
|
||||
|
||||
removeOrder(0);
|
||||
}
|
||||
removeOrder(0);
|
||||
}
|
||||
|
||||
void Unit::attack(Order order){
|
||||
@@ -676,12 +680,53 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::setOrder(Order order) {
|
||||
while (!orders.empty())
|
||||
removeOrder(0);
|
||||
bool Unit::validateOrder(Order order){
|
||||
switch (order.type) {
|
||||
case Order::TYPE::ATTACK:
|
||||
return !weapons.empty();
|
||||
case Order::TYPE::BUILD:
|
||||
return unitClass == UnitClass::ENGINEER;
|
||||
case Order::TYPE::PATROL:
|
||||
case Order::TYPE::MOVE:
|
||||
return vehicle;
|
||||
case Order::TYPE::GARRISON:
|
||||
return validateGarrisonOrder(order);
|
||||
case Order::TYPE::EJECT:
|
||||
return !garrisonSlots.empty();
|
||||
case Order::TYPE::LAUNCH:
|
||||
{
|
||||
for(Weapon *weapon : weapons)
|
||||
if(weapon->getType() == Weapon::Type::CRUISE_MISSILE)
|
||||
return true;
|
||||
|
||||
addOrder(order);
|
||||
orderLineDispTime = getTime();
|
||||
return false;
|
||||
}
|
||||
case Order::TYPE::SUPPLY:
|
||||
return unitClass == UnitClass::RESOURCE_ROVER;
|
||||
case Order::TYPE::HACK:
|
||||
{
|
||||
for(Weapon *weapon : weapons)
|
||||
if(weapon->getType() == Weapon::Type::CRUISE_MISSILE)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::receiveOrder(Order order, bool add) {
|
||||
if(!validateOrder(order)) return;
|
||||
|
||||
if(!add){
|
||||
while (!orders.empty())
|
||||
removeOrder(0);
|
||||
|
||||
orderLineDispTime = getTime();
|
||||
}
|
||||
|
||||
orders.push_back(order);
|
||||
}
|
||||
|
||||
void Unit::halt() {
|
||||
@@ -702,10 +747,6 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
void Unit::addOrder(Order order){
|
||||
orders.push_back(order);
|
||||
}
|
||||
|
||||
vector<Player*> Unit::getSelectingPlayers(){
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers(), selectingPlayers;
|
||||
|
||||
|
||||
@@ -133,7 +133,7 @@ namespace battleship{
|
||||
virtual void select();
|
||||
void setOrder(Order);
|
||||
std::vector<Projectile*> getProjectiles();
|
||||
virtual void addOrder(Order);
|
||||
virtual void receiveOrder(Order, bool);
|
||||
bool canGarrison(Vehicle*);
|
||||
void initLosLight();
|
||||
void destroyLosLight();
|
||||
@@ -164,6 +164,7 @@ namespace battleship{
|
||||
void updateScreenCoordinates();
|
||||
void initWeapons();
|
||||
void destroyWeapons();
|
||||
bool validateOrder(Order);
|
||||
inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;}
|
||||
|
||||
const int orderVecDispLength = 2000, DEATH_HP = 0;
|
||||
@@ -176,7 +177,7 @@ namespace battleship{
|
||||
UnitType type;
|
||||
std::vector<Order> orders;
|
||||
std::string guiScreen = "";
|
||||
int health, maxHealth, playerId, lenHpBar = 200;
|
||||
int health = 0, maxHealth, playerId, lenHpBar = 200;
|
||||
vb01::s64 orderLineDispTime = 0, lastFireTime = 0;
|
||||
float lineOfSight;
|
||||
std::vector<Armor> armorTypes;
|
||||
@@ -187,6 +188,7 @@ namespace battleship{
|
||||
|
||||
std::vector<Player*> getSelectingPlayers();
|
||||
void removeOrder(int);
|
||||
virtual bool validateGarrisonOrder(Order){return false;}
|
||||
virtual void targetUnitsAutomatically();
|
||||
virtual void reinit();
|
||||
virtual void initProperties();
|
||||
|
||||
+28
-6
@@ -46,17 +46,27 @@ namespace battleship{
|
||||
pursuingTarget = false;
|
||||
}
|
||||
|
||||
void Vehicle::addOrder(Order order){
|
||||
bool Vehicle::validateGarrisonOrder(Order order){
|
||||
Unit *targUnit = order.targets[0].unit;
|
||||
|
||||
for(GarrisonSlot slot : targUnit->getGarrisonSlots())
|
||||
if(!slot.vehicle && slot.category >= garrisonCategory)
|
||||
return true;
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void Vehicle::receiveOrder(Order order, bool add){
|
||||
if(!(order.type == Order::TYPE::EJECT || order.type == Order::TYPE::LAUNCH)){
|
||||
Order::Target targ = order.targets[0];
|
||||
Vector3 targPos = (targ.unit ? targ.unit->getPos() : targ.pos);
|
||||
preparePathpoints(order, targPos);
|
||||
|
||||
if(!pathPoints.empty())
|
||||
orders.push_back(order);
|
||||
Unit::receiveOrder(order, add);
|
||||
}
|
||||
else
|
||||
orders.push_back(order);
|
||||
Unit::receiveOrder(order, add);
|
||||
}
|
||||
|
||||
void Vehicle::turn(float angle) {
|
||||
@@ -94,6 +104,11 @@ namespace battleship{
|
||||
garrisonCategory = unitTable["garrisonCategory"];
|
||||
}
|
||||
|
||||
void Vehicle::reinit(){
|
||||
Unit::reinit();
|
||||
initProperties();
|
||||
}
|
||||
|
||||
void Vehicle::navigate(float destOffset){
|
||||
Vector3 hypVec = (pathPoints[0] - pos);
|
||||
float hypAngle = hypVec.norm().getAngleBetween(upVec) - PI / 2;
|
||||
@@ -113,7 +128,7 @@ namespace battleship{
|
||||
advance(movementAmmount);
|
||||
}
|
||||
|
||||
if(vertDist > 0.5 * height){
|
||||
if(vertDist > .1){
|
||||
float dist = pos.y - pathPoints[0].y;
|
||||
float movementAmmount = (speed > fabs(dist) ? dist : speed);
|
||||
|
||||
@@ -244,9 +259,16 @@ namespace battleship{
|
||||
|
||||
if(type != UnitType::HOVER && !(waterVehCanMove || landVehCanMove)) return;
|
||||
|
||||
Pathfinder *pathfinder = Pathfinder::getSingleton();
|
||||
int dest = map->getCellId(destPos);
|
||||
vector<int> path = pathfinder->findPath(cells, source, dest, (int)type);
|
||||
|
||||
if(type != UnitType::UNDERWATER && fabs(destPos.y - cells[dest].pos.y) > .1) return;
|
||||
|
||||
vector<float> heuristics;
|
||||
|
||||
for(Map::Cell &cell : cells)
|
||||
heuristics.push_back(145 * (cells[dest].pos.getDistanceFrom(cell.pos)));
|
||||
|
||||
vector<int> path = Pathfinder::getSingleton()->findPath(cells, heuristics, source, dest, (int)type);
|
||||
bool pathTruncated = false;
|
||||
|
||||
for(int i = 0; i < path.size(); i++){
|
||||
|
||||
@@ -25,15 +25,17 @@ namespace battleship{
|
||||
std::vector<vb01::Node*> debugPathPoints;
|
||||
|
||||
inline int getNextPatrolPointId(int numPoints) {return patrolPointId == numPoints - 1 ? 0 : patrolPointId + 1;}
|
||||
bool validateGarrisonOrder(Order);
|
||||
void enterGarrisonable();
|
||||
void halt();
|
||||
void turn(float);
|
||||
void addOrder(Order);
|
||||
void receiveOrder(Order, bool);
|
||||
void advance(float, MoveDir = MoveDir::FORW);
|
||||
void addPathpoint(vb01::Vector3);
|
||||
void removePathpoint(int = 0);
|
||||
void removeAllPathpoints();
|
||||
void select();
|
||||
void reinit();
|
||||
protected:
|
||||
std::vector<vb01::Vector3> pathPoints;
|
||||
bool pursuingTarget = false;
|
||||
|
||||
Reference in New Issue
Block a user