mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
refactor: restructure monorepo
This commit is contained in:
+1
-1
@@ -1,4 +1,4 @@
|
||||
[submodule "gameBase2"]
|
||||
[submodule "external/gameBase"]
|
||||
path = external/gameBase
|
||||
url = https://github.com/devZoGok/gameBase
|
||||
[submodule "external/vb01"]
|
||||
|
||||
+158
-82
@@ -3,86 +3,162 @@ cmake_minimum_required(VERSION 3.5)
|
||||
set(GAME_NAME battleship)
|
||||
project(${GAME_NAME})
|
||||
|
||||
if(MSVC)
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std:c++17")
|
||||
else()
|
||||
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=c++17 -pedantic")
|
||||
endif()
|
||||
|
||||
set(CMAKE_CXX_STANDART 17)
|
||||
set(CMAKE_POLICY_VERSION_MINIMUM 3.5)
|
||||
set(CMAKE_BUILD_TYPE Debug)
|
||||
set(BUILD_TESTS OFF)
|
||||
set(BUILD_SHARED_LIBS OFF CACHE BOOL FORCED)
|
||||
cmake_policy(SET CMP0015 NEW)
|
||||
|
||||
set(STATES activeGameState.cpp inGameAppState.cpp guiAppState.cpp mapEditorAppState.cpp loadingAppState.cpp)
|
||||
|
||||
set(UNIT_BUTTONS unitButton.cpp tradeButton.cpp buildButton.cpp trainButton.cpp researchButton.cpp orderButton.cpp stateToggleButton.cpp)
|
||||
set(OPTIONS_BUTTONS optionsButton.cpp tabButton.cpp okButton.cpp defaultsButton.cpp)
|
||||
set(TRADING_BUTTONS activeStateBackButton.cpp playerTradeButton.cpp tradingScreenButton.cpp offerButton.cpp resourceAmmountButton.cpp)
|
||||
set(MENU_BUTTONS mainMenuButton.cpp singlePlayerButton.cpp exitButton.cpp backButton.cpp playButton.cpp)
|
||||
set(MAP_EDITOR_BUTTONS mapEditorButton.cpp newMapButton.cpp loadMapButton.cpp exportButton.cpp)
|
||||
set(BUTTONS statsButton.cpp activeStateButton.cpp minimapButton.cpp ${TRADING_BUTTONS} ${OPTIONS_BUTTONS} ${MENU_BUTTONS} ${MAP_EDITOR_BUTTONS} ${UNIT_BUTTONS})
|
||||
|
||||
set(LISTBOXES skyboxTextureListbox.cpp landTextureListbox.cpp gameObjectListbox.cpp mapListbox.cpp)
|
||||
set(GUI tooltip.cpp concreteGuiManager.cpp ${BUTTONS} ${LISTBOXES})
|
||||
|
||||
set(CONTROLLERS gameObjectFrameController.cpp cameraController.cpp)
|
||||
set(CONSOLE console.cpp abstractCommand.cpp addUnitCommand.cpp addResourceCommand.cpp addTechnologyCommand.cpp toggleDebugCommand.cpp)
|
||||
set(CORE gameManager.cpp game.cpp pathfinder.cpp environment.cpp fxManager.cpp defConfigs.cpp player.cpp trader.cpp ${CONSOLE} ${CONTROLLERS})
|
||||
|
||||
set(PROJECTILES projectile.cpp missile.cpp cruiseMissile.cpp shell.cpp depthCharge.cpp torpedo.cpp torpedo.h)
|
||||
set(VEHICLES vehicle.cpp submarine.cpp engineer.cpp resourceRover.cpp freezer.cpp)
|
||||
set(STRUCTURES structure.cpp factory.cpp pointDefense.cpp extractor.cpp researchStruct.cpp iceSheet.cpp)
|
||||
set(WEAPONS weapon.cpp)
|
||||
set(UNITS unit.cpp ${WEAPONS} ${STRUCTURES} ${VEHICLES})
|
||||
set(CONTENT map.cpp gameObject.cpp destructable.cpp gameObjectFrame.h gameObjectFactory.cpp resourceDeposit.cpp ${UNITS} ${PROJECTILES})
|
||||
|
||||
set(UTIL util.cpp binds.h)
|
||||
|
||||
set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL})
|
||||
|
||||
set(SFML_DIR external/gameBase/external/SFML)
|
||||
set(VB01_DIR external/vb01)
|
||||
set(VB01_GUI_DIR external/vb01Gui)
|
||||
set(GAME_BASE_DIR external/gameBase)
|
||||
|
||||
add_executable(${GAME_NAME} main.cpp ${GAME_SRC})
|
||||
|
||||
include_directories(external/tinydir)
|
||||
include_directories(external/vb01/external/glm)
|
||||
include_directories(external/vb01/external/glm/glm)
|
||||
include_directories(external/gameBase/external/SFML/include)
|
||||
|
||||
add_subdirectory(${VB01_DIR})
|
||||
set(VB01_LIB_DIR ${VB01_DIR}/build)
|
||||
target_include_directories(${GAME_NAME} PUBLIC ${VB01_DIR})
|
||||
target_link_directories(${GAME_NAME} PUBLIC ${VB01_LIB_DIR})
|
||||
|
||||
add_subdirectory(${GAME_BASE_DIR})
|
||||
set(GAME_BASE_LIB_DIR build/${GAME_BASE_DIR}/src)
|
||||
target_include_directories(${GAME_NAME} PUBLIC ${GAME_BASE_DIR})
|
||||
target_link_directories(${GAME_NAME} PUBLIC ${GAME_BASE_LIB_DIR})
|
||||
|
||||
set(DEPS vb01 gameBase)
|
||||
target_link_libraries(${GAME_NAME} ${DEPS})
|
||||
|
||||
if(BUILD_TESTS)
|
||||
if(UNIX)
|
||||
include_directories(/usr/include/cppunit)
|
||||
link_directories(/usr/lib)
|
||||
elseif(WIN32)
|
||||
include_directories(C:/Program\ Files\ \(x86\)/cppunit/include)
|
||||
link_directories(C:/Program\ Files\ \(x86\)/cppunit/lib)
|
||||
endif()
|
||||
|
||||
set(TEST_SRC testMain.cpp pathfinderTest.cpp ${GAME_SRC})
|
||||
set(TEST_NAME battleshipTests)
|
||||
|
||||
add_executable(${TEST_NAME} ${TEST_SRC})
|
||||
target_include_directories(${TEST_NAME} PUBLIC ${VB01_DIR})
|
||||
target_include_directories(${TEST_NAME} PUBLIC ${VB01_GUI_DIR})
|
||||
target_include_directories(${TEST_NAME} PUBLIC ${GAME_BASE_DIR})
|
||||
target_link_libraries(${TEST_NAME} ${DEPS} cppunit)
|
||||
option(BUILD_GAME_TESTS "Build game unit tests" OFF)
|
||||
|
||||
set(STATES
|
||||
Source/Systems/Private/activeGameState.cpp
|
||||
Source/Systems/Private/inGameAppState.cpp
|
||||
Source/Systems/Private/guiAppState.cpp
|
||||
Source/Systems/Private/mapEditorAppState.cpp
|
||||
Source/Systems/Private/loadingAppState.cpp)
|
||||
|
||||
set(CONSOLE
|
||||
Source/Systems/Private/console.cpp
|
||||
Source/Systems/Private/abstractCommand.cpp
|
||||
Source/Systems/Private/addUnitCommand.cpp
|
||||
Source/Systems/Private/addResourceCommand.cpp
|
||||
Source/Systems/Private/addTechnologyCommand.cpp
|
||||
Source/Systems/Private/toggleDebugCommand.cpp)
|
||||
|
||||
set(UNIT_BUTTONS
|
||||
Source/UI/Private/unitButton.cpp
|
||||
Source/UI/Private/tradeButton.cpp
|
||||
Source/UI/Private/buildButton.cpp
|
||||
Source/UI/Private/trainButton.cpp
|
||||
Source/UI/Private/researchButton.cpp
|
||||
Source/UI/Private/orderButton.cpp
|
||||
Source/UI/Private/stateToggleButton.cpp)
|
||||
|
||||
set(OPTIONS_BUTTONS
|
||||
Source/UI/Private/optionsButton.cpp
|
||||
Source/UI/Private/tabButton.cpp
|
||||
Source/UI/Private/okButton.cpp
|
||||
Source/UI/Private/defaultsButton.cpp)
|
||||
|
||||
set(TRADING_BUTTONS
|
||||
Source/UI/Private/activeStateBackButton.cpp
|
||||
Source/UI/Private/playerTradeButton.cpp
|
||||
Source/UI/Private/tradingScreenButton.cpp
|
||||
Source/UI/Private/offerButton.cpp
|
||||
Source/UI/Private/resourceAmmountButton.cpp)
|
||||
|
||||
set(MENU_BUTTONS
|
||||
Source/UI/Private/mainMenuButton.cpp
|
||||
Source/UI/Private/singlePlayerButton.cpp
|
||||
Source/UI/Private/exitButton.cpp
|
||||
Source/UI/Private/backButton.cpp
|
||||
Source/UI/Private/playButton.cpp)
|
||||
|
||||
set(MAP_EDITOR_BUTTONS
|
||||
Source/UI/Private/mapEditorButton.cpp
|
||||
Source/UI/Private/newMapButton.cpp
|
||||
Source/UI/Private/loadMapButton.cpp
|
||||
Source/UI/Private/exportButton.cpp)
|
||||
|
||||
set(BUTTONS
|
||||
Source/UI/Private/statsButton.cpp
|
||||
Source/UI/Private/activeStateButton.cpp
|
||||
Source/UI/Private/minimapButton.cpp
|
||||
${TRADING_BUTTONS} ${OPTIONS_BUTTONS} ${MENU_BUTTONS}
|
||||
${MAP_EDITOR_BUTTONS} ${UNIT_BUTTONS})
|
||||
|
||||
set(LISTBOXES
|
||||
Source/UI/Private/skyboxTextureListbox.cpp
|
||||
Source/UI/Private/landTextureListbox.cpp
|
||||
Source/UI/Private/gameObjectListbox.cpp
|
||||
Source/UI/Private/mapListbox.cpp)
|
||||
|
||||
set(GUI_SRC
|
||||
Source/UI/Private/tooltip.cpp
|
||||
Source/UI/Private/concreteGuiManager.cpp
|
||||
Source/UI/Private/gameObjectFrame.cpp
|
||||
Source/UI/Private/gameObjectFrameController.cpp
|
||||
${BUTTONS} ${LISTBOXES})
|
||||
|
||||
set(AI_SRC
|
||||
Source/AI/Private/pathfinder.cpp
|
||||
Source/AI/Private/cameraController.cpp)
|
||||
|
||||
set(PROJECTILES
|
||||
Source/Gameplay/Private/projectile.cpp
|
||||
Source/Gameplay/Private/missile.cpp
|
||||
Source/Gameplay/Private/cruiseMissile.cpp
|
||||
Source/Gameplay/Private/shell.cpp
|
||||
Source/Gameplay/Private/depthCharge.cpp
|
||||
Source/Gameplay/Private/torpedo.cpp)
|
||||
|
||||
set(VEHICLES
|
||||
Source/Gameplay/Private/vehicle.cpp
|
||||
Source/Gameplay/Private/submarine.cpp
|
||||
Source/Gameplay/Private/engineer.cpp
|
||||
Source/Gameplay/Private/resourceRover.cpp
|
||||
Source/Gameplay/Private/freezer.cpp
|
||||
Source/Gameplay/Private/vessel.cpp)
|
||||
|
||||
set(STRUCTURES
|
||||
Source/Gameplay/Private/structure.cpp
|
||||
Source/Gameplay/Private/factory.cpp
|
||||
Source/Gameplay/Private/pointDefense.cpp
|
||||
Source/Gameplay/Private/extractor.cpp
|
||||
Source/Gameplay/Private/researchStruct.cpp
|
||||
Source/Gameplay/Private/iceSheet.cpp)
|
||||
|
||||
set(GAMEPLAY_SRC
|
||||
Source/Gameplay/Private/game.cpp
|
||||
Source/Gameplay/Private/gameManager.cpp
|
||||
Source/Gameplay/Private/gameObject.cpp
|
||||
Source/Gameplay/Private/gameObjectFactory.cpp
|
||||
Source/Gameplay/Private/player.cpp
|
||||
Source/Gameplay/Private/trader.cpp
|
||||
Source/Gameplay/Private/tradeCenter.cpp
|
||||
Source/Gameplay/Private/environment.cpp
|
||||
Source/Gameplay/Private/map.cpp
|
||||
Source/Gameplay/Private/fxManager.cpp
|
||||
Source/Gameplay/Private/explosion.cpp
|
||||
Source/Gameplay/Private/destructable.cpp
|
||||
Source/Gameplay/Private/resourceDeposit.cpp
|
||||
Source/Gameplay/Private/garrisonable.cpp
|
||||
Source/Gameplay/Private/unit.cpp
|
||||
Source/Gameplay/Private/weapon.cpp
|
||||
${PROJECTILES} ${VEHICLES} ${STRUCTURES})
|
||||
|
||||
set(CORE_SRC
|
||||
Source/Core/Private/util.cpp
|
||||
Source/Core/Private/defConfigs.cpp)
|
||||
|
||||
set(GAME_SRC ${STATES} ${CONSOLE} ${GUI_SRC} ${AI_SRC} ${GAMEPLAY_SRC} ${CORE_SRC})
|
||||
|
||||
add_executable(${GAME_NAME} Source/Core/Private/main.cpp ${GAME_SRC})
|
||||
|
||||
target_include_directories(${GAME_NAME} PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/Core/Public
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/Systems/Public
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/Gameplay/Public
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/UI/Public
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/AI/Public)
|
||||
|
||||
target_link_libraries(${GAME_NAME} PRIVATE Renderer Engine)
|
||||
|
||||
if(BUILD_GAME_TESTS)
|
||||
if(UNIX)
|
||||
include_directories(/usr/include/cppunit)
|
||||
link_directories(/usr/lib)
|
||||
elseif(WIN32)
|
||||
include_directories("C:/Program Files (x86)/cppunit/include")
|
||||
link_directories("C:/Program Files (x86)/cppunit/lib")
|
||||
endif()
|
||||
|
||||
set(TEST_SRC
|
||||
Tests/testMain.cpp
|
||||
Tests/pathfinderTest.cpp
|
||||
${GAME_SRC})
|
||||
|
||||
add_executable(battleshipTests ${TEST_SRC})
|
||||
target_include_directories(battleshipTests PRIVATE
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/Core/Public
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/Systems/Public
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/Gameplay/Public
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/UI/Public
|
||||
${CMAKE_CURRENT_SOURCE_DIR}/Source/AI/Public)
|
||||
target_link_libraries(battleshipTests PRIVATE Renderer Engine cppunit)
|
||||
endif()
|
||||
|
||||
Executable → Regular
+38
-38
@@ -1,38 +1,38 @@
|
||||
#include "util.h"
|
||||
#include "gameManager.h"
|
||||
#include "guiAppState.h"
|
||||
#include "concreteGuiManager.h"
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include <assetManager.h>
|
||||
#include <root.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace battleship;
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
string gamePath = string(argv[0]);
|
||||
|
||||
for(int i = 0; i < gamePath.length(); i++)
|
||||
if(gamePath[i] == '\\')
|
||||
gamePath[i] = '/';
|
||||
|
||||
gamePath = gamePath.substr(0, gamePath.find_last_of("/") + 1) + "../";
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
gm->start(gamePath);
|
||||
gm->getStateManager()->attachAppState(new GuiAppState());
|
||||
AssetManager::getSingleton()->load(gm->getPath() + "Fonts/batang.ttf");
|
||||
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("mainMenu.lua");
|
||||
|
||||
while(gm->isRunning()){
|
||||
gm->update();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include "util.h"
|
||||
#include "gameManager.h"
|
||||
#include "guiAppState.h"
|
||||
#include "concreteGuiManager.h"
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include <assetManager.h>
|
||||
#include <root.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace battleship;
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
string gamePath = string(argv[0]);
|
||||
|
||||
for(int i = 0; i < gamePath.length(); i++)
|
||||
if(gamePath[i] == '\\')
|
||||
gamePath[i] = '/';
|
||||
|
||||
gamePath = gamePath.substr(0, gamePath.find_last_of("/") + 1) + "../";
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
gm->start(gamePath);
|
||||
gm->getStateManager()->attachAppState(new GuiAppState());
|
||||
AssetManager::getSingleton()->load(gm->getPath() + "Fonts/batang.ttf");
|
||||
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("mainMenu.lua");
|
||||
|
||||
while(gm->isRunning()){
|
||||
gm->update();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Executable → Regular
+145
-145
@@ -1,145 +1,145 @@
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <camera.h>
|
||||
#include <quad.h>
|
||||
#include <root.h>
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
#include <assetManager.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <solUtil.h>
|
||||
|
||||
#include <glm.hpp>
|
||||
#include <ext.hpp>
|
||||
|
||||
#include <tinydir.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "defConfigs.h"
|
||||
#include "gameManager.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "guiAppState.h"
|
||||
#include "inGameAppState.h"
|
||||
#include "loadingAppState.h"
|
||||
#include "mapEditorButton.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::this_thread;
|
||||
using namespace std::chrono;
|
||||
using namespace glm;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
void handleLoadingGui(LoadingAppState *loadState){
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
guiManager->readLuaScreenScript("loadingScreen.lua");
|
||||
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
string vfxPrefix = SOL_LUA_VIEW["vfxPrefix"], gameObjPrefix = SOL_LUA_VIEW["gameObjPrefix"];
|
||||
|
||||
AssetManager *assetManager = AssetManager::getSingleton();
|
||||
string path = GameManager::getSingleton()->getPath();
|
||||
vector<string> assets = vector<string>{path + DEFAULT_TEXTURE};
|
||||
|
||||
assetManager->readDir(path + vfxPrefix, assets, true);
|
||||
assetManager->readDir(path + gameObjPrefix, assets, true);
|
||||
|
||||
loadState->setLoadableAssets(assets);
|
||||
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
stateManager->attachAppState(loadState);
|
||||
}
|
||||
|
||||
Vector3 getVecToPlane(Vector3 pos, Vector3 dirVec, Vector3 upVec){
|
||||
float baseAngle = upVec.getAngleBetween(dirVec.norm());
|
||||
|
||||
if(fabs(baseAngle - PI / 2) > .001){
|
||||
bool acuteAngle = (baseAngle < PI / 2);
|
||||
|
||||
if(acuteAngle) baseAngle = PI / 2 - baseAngle;
|
||||
else baseAngle -= PI / 2;
|
||||
|
||||
float pointToPlane = dirVec.getLength() * sin(baseAngle);
|
||||
return (dirVec + upVec * pointToPlane * (acuteAngle ? -1 : 1)).norm();
|
||||
}
|
||||
else return dirVec.norm();
|
||||
}
|
||||
|
||||
vector<string> readDir(string path, bool findFolders){
|
||||
tinydir_dir dir;
|
||||
tinydir_open_sorted(&dir, path.c_str());
|
||||
vector<string> files;
|
||||
|
||||
for (int i = 0; i < dir.n_files; i++) {
|
||||
tinydir_file file;
|
||||
tinydir_readfile_n(&dir, &file, i);
|
||||
|
||||
if (file.is_dir == findFolders && file.name[0] != '.')
|
||||
files.push_back(file.name);
|
||||
}
|
||||
|
||||
tinydir_close(&dir);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
Vector3 spaceToScreen3d(Vector3 pos){
|
||||
Root *root = Root::getSingleton();
|
||||
Camera *cam = root->getCamera();
|
||||
Vector3 dir = cam->getDirection(), up = cam->getUp();
|
||||
Vector3 camPos = cam->getPosition();
|
||||
mat4 view = lookAt(vec3(camPos.x, camPos.y, camPos.z), vec3(camPos.x + dir.x, camPos.y + dir.y, camPos.z + dir.z), vec3(up.x, up.y, up.z));
|
||||
|
||||
float fov = cam->getFov(), width = root->getWidth(), height = root->getHeight(), nearPlane = cam->getNearPlane(), farPlane = cam->getFarPlane();
|
||||
mat4 proj = perspective(radians(fov), width / height, nearPlane, farPlane);
|
||||
|
||||
vec4 ndcPos = proj * view * vec4(pos.x, pos.y, pos.z, 1);
|
||||
ndcPos.x /= ndcPos.w;
|
||||
ndcPos.y /= ndcPos.w;
|
||||
ndcPos.z /= ndcPos.w;
|
||||
return Vector3(0.5 * width * (1 + ndcPos.x), 0.5 * height * (1 - ndcPos.y), ndcPos.z);
|
||||
}
|
||||
|
||||
Vector2 spaceToScreen(Vector3 pos){
|
||||
Vector3 pos3d = spaceToScreen3d(pos);
|
||||
return Vector2(pos3d.x, pos3d.y);
|
||||
}
|
||||
|
||||
Vector3 screenToSpace(Vector2 pos){
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
float midWidth = .5 * gm->getWidth(), midHeight = .5 * gm->getHeight(), horOffset, vertOffset;
|
||||
bool left, up;
|
||||
|
||||
if(pos.x < midWidth){
|
||||
left = true;
|
||||
horOffset = pos.x / midWidth - 1;
|
||||
}
|
||||
else{
|
||||
left = false;
|
||||
horOffset = (pos.x - midWidth) / midWidth;
|
||||
}
|
||||
|
||||
if(pos.y < midHeight){
|
||||
up = true;
|
||||
vertOffset = 1 - pos.y / midHeight;
|
||||
}
|
||||
else{
|
||||
up = false;
|
||||
vertOffset = -(pos.y - midHeight) / midHeight;
|
||||
}
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
float camNorm = cam->getNearPlane();
|
||||
float tg = tan(radians(cam->getFov()) / 2), ar = midWidth / midHeight;
|
||||
float camHeight = camNorm * tg, camWidth = camHeight * ar;
|
||||
Vector3 posOffset = (cam->getLeft() * camWidth * horOffset + cam->getUp() * camHeight * vertOffset + cam->getDirection() * camNorm);
|
||||
|
||||
return cam->getPosition() + posOffset;
|
||||
}
|
||||
}
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <camera.h>
|
||||
#include <quad.h>
|
||||
#include <root.h>
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
#include <assetManager.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <solUtil.h>
|
||||
|
||||
#include <glm.hpp>
|
||||
#include <ext.hpp>
|
||||
|
||||
#include <tinydir.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "defConfigs.h"
|
||||
#include "gameManager.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "guiAppState.h"
|
||||
#include "inGameAppState.h"
|
||||
#include "loadingAppState.h"
|
||||
#include "mapEditorButton.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::this_thread;
|
||||
using namespace std::chrono;
|
||||
using namespace glm;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
void handleLoadingGui(LoadingAppState *loadState){
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
guiManager->readLuaScreenScript("loadingScreen.lua");
|
||||
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
string vfxPrefix = SOL_LUA_VIEW["vfxPrefix"], gameObjPrefix = SOL_LUA_VIEW["gameObjPrefix"];
|
||||
|
||||
AssetManager *assetManager = AssetManager::getSingleton();
|
||||
string path = GameManager::getSingleton()->getPath();
|
||||
vector<string> assets = vector<string>{path + DEFAULT_TEXTURE};
|
||||
|
||||
assetManager->readDir(path + vfxPrefix, assets, true);
|
||||
assetManager->readDir(path + gameObjPrefix, assets, true);
|
||||
|
||||
loadState->setLoadableAssets(assets);
|
||||
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
stateManager->attachAppState(loadState);
|
||||
}
|
||||
|
||||
Vector3 getVecToPlane(Vector3 pos, Vector3 dirVec, Vector3 upVec){
|
||||
float baseAngle = upVec.getAngleBetween(dirVec.norm());
|
||||
|
||||
if(fabs(baseAngle - PI / 2) > .001){
|
||||
bool acuteAngle = (baseAngle < PI / 2);
|
||||
|
||||
if(acuteAngle) baseAngle = PI / 2 - baseAngle;
|
||||
else baseAngle -= PI / 2;
|
||||
|
||||
float pointToPlane = dirVec.getLength() * sin(baseAngle);
|
||||
return (dirVec + upVec * pointToPlane * (acuteAngle ? -1 : 1)).norm();
|
||||
}
|
||||
else return dirVec.norm();
|
||||
}
|
||||
|
||||
vector<string> readDir(string path, bool findFolders){
|
||||
tinydir_dir dir;
|
||||
tinydir_open_sorted(&dir, path.c_str());
|
||||
vector<string> files;
|
||||
|
||||
for (int i = 0; i < dir.n_files; i++) {
|
||||
tinydir_file file;
|
||||
tinydir_readfile_n(&dir, &file, i);
|
||||
|
||||
if (file.is_dir == findFolders && file.name[0] != '.')
|
||||
files.push_back(file.name);
|
||||
}
|
||||
|
||||
tinydir_close(&dir);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
Vector3 spaceToScreen3d(Vector3 pos){
|
||||
Root *root = Root::getSingleton();
|
||||
Camera *cam = root->getCamera();
|
||||
Vector3 dir = cam->getDirection(), up = cam->getUp();
|
||||
Vector3 camPos = cam->getPosition();
|
||||
mat4 view = lookAt(vec3(camPos.x, camPos.y, camPos.z), vec3(camPos.x + dir.x, camPos.y + dir.y, camPos.z + dir.z), vec3(up.x, up.y, up.z));
|
||||
|
||||
float fov = cam->getFov(), width = root->getWidth(), height = root->getHeight(), nearPlane = cam->getNearPlane(), farPlane = cam->getFarPlane();
|
||||
mat4 proj = perspective(radians(fov), width / height, nearPlane, farPlane);
|
||||
|
||||
vec4 ndcPos = proj * view * vec4(pos.x, pos.y, pos.z, 1);
|
||||
ndcPos.x /= ndcPos.w;
|
||||
ndcPos.y /= ndcPos.w;
|
||||
ndcPos.z /= ndcPos.w;
|
||||
return Vector3(0.5 * width * (1 + ndcPos.x), 0.5 * height * (1 - ndcPos.y), ndcPos.z);
|
||||
}
|
||||
|
||||
Vector2 spaceToScreen(Vector3 pos){
|
||||
Vector3 pos3d = spaceToScreen3d(pos);
|
||||
return Vector2(pos3d.x, pos3d.y);
|
||||
}
|
||||
|
||||
Vector3 screenToSpace(Vector2 pos){
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
float midWidth = .5 * gm->getWidth(), midHeight = .5 * gm->getHeight(), horOffset, vertOffset;
|
||||
bool left, up;
|
||||
|
||||
if(pos.x < midWidth){
|
||||
left = true;
|
||||
horOffset = pos.x / midWidth - 1;
|
||||
}
|
||||
else{
|
||||
left = false;
|
||||
horOffset = (pos.x - midWidth) / midWidth;
|
||||
}
|
||||
|
||||
if(pos.y < midHeight){
|
||||
up = true;
|
||||
vertOffset = 1 - pos.y / midHeight;
|
||||
}
|
||||
else{
|
||||
up = false;
|
||||
vertOffset = -(pos.y - midHeight) / midHeight;
|
||||
}
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
float camNorm = cam->getNearPlane();
|
||||
float tg = tan(radians(cam->getFov()) / 2), ar = midWidth / midHeight;
|
||||
float camHeight = camNorm * tg, camWidth = camHeight * ar;
|
||||
Vector3 posOffset = (cam->getLeft() * camWidth * horOffset + cam->getUp() * camHeight * vertOffset + cam->getDirection() * camNorm);
|
||||
|
||||
return cam->getPosition() + posOffset;
|
||||
}
|
||||
}
|
||||
Executable → Regular
+214
-214
@@ -1,214 +1,214 @@
|
||||
#ifndef DEF_CONFIGS_H
|
||||
#define DEF_CONFIGS_H
|
||||
#define SOL_ALL_SAFETIES_ON 1
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <util.h>
|
||||
|
||||
#include <glfw3.h>
|
||||
|
||||
#include <mapping.h>
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
#include "binds.h"
|
||||
#include "gameManager.h"
|
||||
|
||||
namespace battleship{
|
||||
namespace configData{
|
||||
using namespace gameBase;
|
||||
|
||||
const std::string DEFAULT_TEXTURE = "Textures/defaultTexture.jpg";
|
||||
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 = 300, NUM_SUBDIVS = 100;
|
||||
const vb01::u32 IMPASS_NODE_VAL = 65535;
|
||||
|
||||
const static int numAppStates = 5;
|
||||
const static int numStaticBinds[numAppStates]{6, 0, 5, 19, 0};
|
||||
const static int numConfBinds[numAppStates]{0, 1, 27, 0, 0};
|
||||
const static int maxStaticBinds = 19;
|
||||
const static int maxConfBinds = 23;
|
||||
const static int numScripts = 5;
|
||||
|
||||
const static std::string scriptPathBase = "Scripts/";
|
||||
enum ScriptFiles{
|
||||
CORE_MAIN,
|
||||
GUI_MAIN,
|
||||
OPTIONS,
|
||||
RESOURCE_DATA,
|
||||
PROJECTILE_DATA,
|
||||
UNIT_DATA,
|
||||
AI_AGENT,
|
||||
PLAYER
|
||||
};
|
||||
const static std::vector<std::string> scripts = std::vector<std::string>{
|
||||
"Scripts/Core/main.lua",
|
||||
"Scripts/Gui/main.lua",
|
||||
"Scripts/Core/options.lua",
|
||||
"Scripts/GameObjects/resourceData.lua",
|
||||
"Scripts/GameObjects/Projectiles/projectileData.lua",
|
||||
"Scripts/GameObjects/Units/unitData.lua",
|
||||
"Scripts/aiAgent.lua",
|
||||
"Scripts/Core/player.lua",
|
||||
"Scripts/Technologies/technologyData.lua",
|
||||
"Scripts/Abilities/abilityData.lua",
|
||||
"Scripts/Trading/traderData.lua"
|
||||
};
|
||||
|
||||
const static Bind staticBinds[numAppStates][maxStaticBinds]{
|
||||
{
|
||||
Bind::LEFT_CLICK,
|
||||
Bind::SCROLLING_UP,
|
||||
Bind::SCROLLING_DOWN,
|
||||
Bind::LEFT,
|
||||
Bind::RIGHT,
|
||||
Bind::DELETE_CHAR,
|
||||
},
|
||||
{},
|
||||
{
|
||||
Bind::LOOK_UP,
|
||||
Bind::LOOK_DOWN,
|
||||
Bind::LOOK_LEFT,
|
||||
Bind::LOOK_RIGHT,
|
||||
Bind::LOOK_AROUND,
|
||||
},
|
||||
{
|
||||
Bind::LOOK_UP,
|
||||
Bind::LOOK_DOWN,
|
||||
Bind::LOOK_LEFT,
|
||||
Bind::LOOK_RIGHT,
|
||||
Bind::LOOK_AROUND,
|
||||
},
|
||||
{}
|
||||
};
|
||||
const static Bind confBinds[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{
|
||||
Bind::TOGGLE_MAIN_MENU
|
||||
},
|
||||
{
|
||||
Bind::DRAG_BOX,
|
||||
Bind::MOVE_CAMERA,
|
||||
Bind::ROTATE_OBJ_FRAME,
|
||||
Bind::HALT,
|
||||
Bind::ZOOM_IN,
|
||||
Bind::ZOOM_OUT,
|
||||
Bind::LEFT_CONTROL,
|
||||
Bind::LEFT_SHIFT,
|
||||
Bind::SELECT_PATROL_POINTS,
|
||||
Bind::LAUNCH,
|
||||
Bind::SHIFT_SUB_DEPTH,
|
||||
Bind::GROUP_0,
|
||||
Bind::GROUP_1,
|
||||
Bind::GROUP_2,
|
||||
Bind::GROUP_3,
|
||||
Bind::GROUP_4,
|
||||
Bind::GROUP_5,
|
||||
Bind::GROUP_6,
|
||||
Bind::GROUP_7,
|
||||
Bind::GROUP_8,
|
||||
Bind::GROUP_9,
|
||||
Bind::SELECT_STRUCTURE,
|
||||
Bind::DESELECT_STRUCTURE
|
||||
},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static int staticTriggers[numAppStates][maxStaticBinds]{
|
||||
{
|
||||
0,
|
||||
GLFW_KEY_W,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_BACKSPACE
|
||||
},
|
||||
{},
|
||||
{
|
||||
Mapping::MOUSE_AXIS_UP,
|
||||
Mapping::MOUSE_AXIS_DOWN,
|
||||
Mapping::MOUSE_AXIS_LEFT,
|
||||
Mapping::MOUSE_AXIS_RIGHT,
|
||||
0
|
||||
},
|
||||
{
|
||||
Mapping::MOUSE_AXIS_UP,
|
||||
Mapping::MOUSE_AXIS_DOWN,
|
||||
Mapping::MOUSE_AXIS_LEFT,
|
||||
Mapping::MOUSE_AXIS_RIGHT,
|
||||
0
|
||||
},
|
||||
{}
|
||||
};
|
||||
const static int confTriggers[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{
|
||||
GLFW_KEY_ESCAPE
|
||||
},
|
||||
{
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_H,
|
||||
3,
|
||||
4,
|
||||
GLFW_KEY_LEFT_CONTROL,
|
||||
GLFW_KEY_LEFT_SHIFT,
|
||||
GLFW_KEY_P,
|
||||
GLFW_KEY_C,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_0,
|
||||
GLFW_KEY_1,
|
||||
GLFW_KEY_2,
|
||||
GLFW_KEY_3,
|
||||
GLFW_KEY_4,
|
||||
GLFW_KEY_5,
|
||||
GLFW_KEY_6,
|
||||
GLFW_KEY_7,
|
||||
GLFW_KEY_8,
|
||||
GLFW_KEY_9,
|
||||
GLFW_KEY_B,
|
||||
GLFW_KEY_ESCAPE
|
||||
},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static bool isStaticKey[numAppStates][maxStaticBinds]{
|
||||
{0, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{0, 0, 0, 0, 1},
|
||||
{0, 0, 0, 0, 1},
|
||||
{}
|
||||
};
|
||||
const static bool isConfKey[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static bool isStaticAction[numAppStates][maxStaticBinds]{
|
||||
{1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{0, 0, 0, 0, 1},
|
||||
{0, 0, 0, 0, 1},
|
||||
{}
|
||||
};
|
||||
const static bool isConfAction[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
int calcSumStaticBinds(int, bool);
|
||||
int calcSumConfBinds(int, bool);
|
||||
int calcSumBinds(int, bool);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef DEF_CONFIGS_H
|
||||
#define DEF_CONFIGS_H
|
||||
#define SOL_ALL_SAFETIES_ON 1
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <util.h>
|
||||
|
||||
#include <GLFW/glfw3.h>
|
||||
|
||||
#include <mapping.h>
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
#include "binds.h"
|
||||
#include "gameManager.h"
|
||||
|
||||
namespace battleship{
|
||||
namespace configData{
|
||||
using namespace gameBase;
|
||||
|
||||
const std::string DEFAULT_TEXTURE = "Textures/defaultTexture.jpg";
|
||||
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 = 300, NUM_SUBDIVS = 100;
|
||||
const vb01::u32 IMPASS_NODE_VAL = 65535;
|
||||
|
||||
const static int numAppStates = 5;
|
||||
const static int numStaticBinds[numAppStates]{6, 0, 5, 19, 0};
|
||||
const static int numConfBinds[numAppStates]{0, 1, 27, 0, 0};
|
||||
const static int maxStaticBinds = 19;
|
||||
const static int maxConfBinds = 23;
|
||||
const static int numScripts = 5;
|
||||
|
||||
const static std::string scriptPathBase = "Scripts/";
|
||||
enum ScriptFiles{
|
||||
CORE_MAIN,
|
||||
GUI_MAIN,
|
||||
OPTIONS,
|
||||
RESOURCE_DATA,
|
||||
PROJECTILE_DATA,
|
||||
UNIT_DATA,
|
||||
AI_AGENT,
|
||||
PLAYER
|
||||
};
|
||||
const static std::vector<std::string> scripts = std::vector<std::string>{
|
||||
"Scripts/Core/main.lua",
|
||||
"Scripts/Gui/main.lua",
|
||||
"Scripts/Core/options.lua",
|
||||
"Scripts/GameObjects/resourceData.lua",
|
||||
"Scripts/GameObjects/Projectiles/projectileData.lua",
|
||||
"Scripts/GameObjects/Units/unitData.lua",
|
||||
"Scripts/aiAgent.lua",
|
||||
"Scripts/Core/player.lua",
|
||||
"Scripts/Technologies/technologyData.lua",
|
||||
"Scripts/Abilities/abilityData.lua",
|
||||
"Scripts/Trading/traderData.lua"
|
||||
};
|
||||
|
||||
const static Bind staticBinds[numAppStates][maxStaticBinds]{
|
||||
{
|
||||
Bind::LEFT_CLICK,
|
||||
Bind::SCROLLING_UP,
|
||||
Bind::SCROLLING_DOWN,
|
||||
Bind::LEFT,
|
||||
Bind::RIGHT,
|
||||
Bind::DELETE_CHAR,
|
||||
},
|
||||
{},
|
||||
{
|
||||
Bind::LOOK_UP,
|
||||
Bind::LOOK_DOWN,
|
||||
Bind::LOOK_LEFT,
|
||||
Bind::LOOK_RIGHT,
|
||||
Bind::LOOK_AROUND,
|
||||
},
|
||||
{
|
||||
Bind::LOOK_UP,
|
||||
Bind::LOOK_DOWN,
|
||||
Bind::LOOK_LEFT,
|
||||
Bind::LOOK_RIGHT,
|
||||
Bind::LOOK_AROUND,
|
||||
},
|
||||
{}
|
||||
};
|
||||
const static Bind confBinds[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{
|
||||
Bind::TOGGLE_MAIN_MENU
|
||||
},
|
||||
{
|
||||
Bind::DRAG_BOX,
|
||||
Bind::MOVE_CAMERA,
|
||||
Bind::ROTATE_OBJ_FRAME,
|
||||
Bind::HALT,
|
||||
Bind::ZOOM_IN,
|
||||
Bind::ZOOM_OUT,
|
||||
Bind::LEFT_CONTROL,
|
||||
Bind::LEFT_SHIFT,
|
||||
Bind::SELECT_PATROL_POINTS,
|
||||
Bind::LAUNCH,
|
||||
Bind::SHIFT_SUB_DEPTH,
|
||||
Bind::GROUP_0,
|
||||
Bind::GROUP_1,
|
||||
Bind::GROUP_2,
|
||||
Bind::GROUP_3,
|
||||
Bind::GROUP_4,
|
||||
Bind::GROUP_5,
|
||||
Bind::GROUP_6,
|
||||
Bind::GROUP_7,
|
||||
Bind::GROUP_8,
|
||||
Bind::GROUP_9,
|
||||
Bind::SELECT_STRUCTURE,
|
||||
Bind::DESELECT_STRUCTURE
|
||||
},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static int staticTriggers[numAppStates][maxStaticBinds]{
|
||||
{
|
||||
0,
|
||||
GLFW_KEY_W,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_BACKSPACE
|
||||
},
|
||||
{},
|
||||
{
|
||||
Mapping::MOUSE_AXIS_UP,
|
||||
Mapping::MOUSE_AXIS_DOWN,
|
||||
Mapping::MOUSE_AXIS_LEFT,
|
||||
Mapping::MOUSE_AXIS_RIGHT,
|
||||
0
|
||||
},
|
||||
{
|
||||
Mapping::MOUSE_AXIS_UP,
|
||||
Mapping::MOUSE_AXIS_DOWN,
|
||||
Mapping::MOUSE_AXIS_LEFT,
|
||||
Mapping::MOUSE_AXIS_RIGHT,
|
||||
0
|
||||
},
|
||||
{}
|
||||
};
|
||||
const static int confTriggers[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{
|
||||
GLFW_KEY_ESCAPE
|
||||
},
|
||||
{
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_H,
|
||||
3,
|
||||
4,
|
||||
GLFW_KEY_LEFT_CONTROL,
|
||||
GLFW_KEY_LEFT_SHIFT,
|
||||
GLFW_KEY_P,
|
||||
GLFW_KEY_C,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_0,
|
||||
GLFW_KEY_1,
|
||||
GLFW_KEY_2,
|
||||
GLFW_KEY_3,
|
||||
GLFW_KEY_4,
|
||||
GLFW_KEY_5,
|
||||
GLFW_KEY_6,
|
||||
GLFW_KEY_7,
|
||||
GLFW_KEY_8,
|
||||
GLFW_KEY_9,
|
||||
GLFW_KEY_B,
|
||||
GLFW_KEY_ESCAPE
|
||||
},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static bool isStaticKey[numAppStates][maxStaticBinds]{
|
||||
{0, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{0, 0, 0, 0, 1},
|
||||
{0, 0, 0, 0, 1},
|
||||
{}
|
||||
};
|
||||
const static bool isConfKey[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static bool isStaticAction[numAppStates][maxStaticBinds]{
|
||||
{1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{0, 0, 0, 0, 1},
|
||||
{0, 0, 0, 0, 1},
|
||||
{}
|
||||
};
|
||||
const static bool isConfAction[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
int calcSumStaticBinds(int, bool);
|
||||
int calcSumConfBinds(int, bool);
|
||||
int calcSumBinds(int, bool);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
Executable → Regular
+36
-36
@@ -1,36 +1,36 @@
|
||||
#pragma once
|
||||
#ifndef UTIL_BATTLESHIP_H
|
||||
#define UTIL_BATTLESHIP_H
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
#include <vector.h>
|
||||
|
||||
namespace battleship{
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned long long u64;
|
||||
typedef char s8;
|
||||
typedef short s16;
|
||||
typedef int s32;
|
||||
typedef long long s64;
|
||||
|
||||
enum AppStateType{GUI_STATE, IN_GAME_STATE, ACTIVE_STATE, MAP_EDITOR, LOADING_STATE};
|
||||
|
||||
class GuiAppState;
|
||||
class LoadingAppState;
|
||||
|
||||
void handleLoadingGui(LoadingAppState*);
|
||||
vb01::Vector3 getVecToPlane(vb01::Vector3, vb01::Vector3, vb01::Vector3);
|
||||
std::vector<std::string> readDir(std::string, bool);
|
||||
vb01::Vector2 spaceToScreen(vb01::Vector3);
|
||||
vb01::Vector3 spaceToScreen3d(vb01::Vector3);
|
||||
vb01::Vector3 screenToSpace(vb01::Vector2);
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
#ifndef UTIL_BATTLESHIP_H
|
||||
#define UTIL_BATTLESHIP_H
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
#include <vector.h>
|
||||
|
||||
namespace battleship{
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned long long u64;
|
||||
typedef char s8;
|
||||
typedef short s16;
|
||||
typedef int s32;
|
||||
typedef long long s64;
|
||||
|
||||
enum AppStateType{GUI_STATE, IN_GAME_STATE, ACTIVE_STATE, MAP_EDITOR, LOADING_STATE};
|
||||
|
||||
class GuiAppState;
|
||||
class LoadingAppState;
|
||||
|
||||
void handleLoadingGui(LoadingAppState*);
|
||||
vb01::Vector3 getVecToPlane(vb01::Vector3, vb01::Vector3, vb01::Vector3);
|
||||
std::vector<std::string> readDir(std::string, bool);
|
||||
vb01::Vector2 spaceToScreen(vb01::Vector3);
|
||||
vb01::Vector3 spaceToScreen3d(vb01::Vector3);
|
||||
vb01::Vector3 screenToSpace(vb01::Vector2);
|
||||
}
|
||||
|
||||
#endif
|
||||
Executable → Regular
+279
-279
@@ -1,279 +1,279 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <inputManager.h>
|
||||
#include <soundManager.h>
|
||||
|
||||
#include <assetManager.h>
|
||||
#include <root.h>
|
||||
|
||||
#include "gameManager.h"
|
||||
#include "gameObjectFrameController.h"
|
||||
#include "gameObjectFactory.h"
|
||||
#include "map.h"
|
||||
#include "game.h"
|
||||
#include "guiAppState.h"
|
||||
#include "defConfigs.h"
|
||||
#include "player.h"
|
||||
#include "extractor.h"
|
||||
#include "factory.h"
|
||||
#include "vehicle.h"
|
||||
#include "engineer.h"
|
||||
#include "destructable.h"
|
||||
#include "pointDefense.h"
|
||||
#include "pathfinder.h"
|
||||
#include "resourceDeposit.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
|
||||
namespace battleship{
|
||||
static GameManager *gameManager = nullptr;
|
||||
|
||||
GameManager* GameManager::getSingleton(){
|
||||
if(!gameManager)
|
||||
gameManager = new GameManager();
|
||||
|
||||
return gameManager;
|
||||
}
|
||||
|
||||
void GameManager::registerMembers(){
|
||||
sol::state_view SOL_LUA_STATE = generateView();
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Order>(
|
||||
"Order", sol::constructors<Order(), Order(Order::TYPE, vector<Order::Target>, Vector3, int)>(),
|
||||
"type", &Order::type,
|
||||
"direction", &Order::direction,
|
||||
"targets", &Order::targets
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Order::Target>(
|
||||
"Target", sol::constructors<Order::Target(), Order::Target(GameObject*, Vector3)>(),
|
||||
"unit", &Order::Target::unit,
|
||||
"pos", &Order::Target::pos
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<GameObjectFactory>(
|
||||
"GameObjectFactory",
|
||||
"createUnit", &GameObjectFactory::createUnit,
|
||||
"createResourceDeposit", &GameObjectFactory::createResourceDeposit
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Unit::GarrisonSlot>(
|
||||
"GarrisonSlot",
|
||||
"vehicle", &Unit::GarrisonSlot::vehicle,
|
||||
"category", &Unit::GarrisonSlot::category
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Unit>(
|
||||
"Unit", sol::constructors<Unit(Player*, int, Vector3, Quaternion)>(),
|
||||
"setState", &Unit::setState,
|
||||
"getDestructable", &Unit::getDestructable,
|
||||
"getGarrisonSlots", &Unit::getGarrisonSlots,
|
||||
"getNumFreeGarrisonSlots", &Unit::getNumFreeGarrisonSlots,
|
||||
"getNumGarrisonSlots", &Unit::getNumGarrisonSlots,
|
||||
"isGarrisonEmpty", &Unit::isGarrisonEmpty,
|
||||
"getOrder", &Unit::getOrder,
|
||||
"getNumOrders", &Unit::getNumOrders,
|
||||
"getDirVec", &GameObject::getDirVec,
|
||||
"getLeftVec", &GameObject::getLeftVec,
|
||||
"getPos", &GameObject::getPos,
|
||||
"getUnitClass", &Unit::getUnitClass,
|
||||
"getLineOfSight", &Unit::getLineOfSight,
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits,
|
||||
"toGameObject", [](Unit *u){return (GameObject*)u;},
|
||||
"toVehicle", [](Unit *u){return (Vehicle*)u;},
|
||||
"toEngineer", [](Unit *u){return (Engineer*)u;},
|
||||
"toStructure", [](Unit *u){return (Structure*)u;},
|
||||
"toFactory", [](Unit *u){return (Factory*)u;},
|
||||
"toExtractor", [](Unit *u){return (Extractor*)u;},
|
||||
"toPointDefense", [](Unit *u){return (PointDefense*)u;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Vehicle>(
|
||||
"Engineer", sol::constructors<Vehicle(Player*, int, Vector3, Quaternion, Unit::State)>(),
|
||||
"getGarrisonable", &Vehicle::getGarrisonable
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Engineer>(
|
||||
"Engineer", sol::constructors<Engineer(Player*, int, Vector3, Quaternion, Unit::State)>(),
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Structure>(
|
||||
"Structure", sol::constructors<Structure(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getPos", &GameObject::getPos,
|
||||
"isComplete", &Structure::isComplete,
|
||||
"getBuildStatus", &Structure::getBuildStatus
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<BuildableUnit>(
|
||||
"BuildableUnit", sol::constructors<BuildableUnit(int, bool)>(),
|
||||
"id", &BuildableUnit::id,
|
||||
"buildable", &BuildableUnit::buildable
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Factory>(
|
||||
"Factory", sol::constructors<Factory(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits,
|
||||
"getDirVec", &GameObject::getDirVec,
|
||||
"getLeftVec", &GameObject::getLeftVec,
|
||||
"getPos", &GameObject::getPos,
|
||||
"appendToQueue", &Factory::appendToQueue,
|
||||
"getBuildStatus", &Structure::getBuildStatus,
|
||||
"getNumQueueUnitsById", &Factory::getNumQueueUnitsById,
|
||||
"getRallyPoint", &Factory::getRallyPoint,
|
||||
"setRallyPoint", &Factory::setRallyPoint,
|
||||
"getQueue", &Factory::getQueue
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Player>(
|
||||
"Player", sol::constructors<Player(int, int, int, Vector3, bool, int, string)>(),
|
||||
"getSelectedUnits", &Player::getSelectedUnits,
|
||||
"haltUnits", &Player::haltUnits,
|
||||
"addUnit", &Player::addUnit,
|
||||
"getUnit", &Player::getUnit,
|
||||
"getNumUnits", &Player::getNumUnits,
|
||||
"getResourceDeposits", &Player::getResourceDeposits,
|
||||
"issueOrder", &Player::issueOrder,
|
||||
"selectUnits", &Player::selectUnits,
|
||||
"deselectUnits", &Player::deselectUnits,
|
||||
"getSpawnPointId", &Player::getSpawnPointId,
|
||||
"getFaction", &Player::getFaction,
|
||||
"getTeam", &Player::getTeam,
|
||||
"getUnits", &Player::getUnits,
|
||||
"getHostileUnits", &Player::getHostileUnits,
|
||||
"getFriendlyUnits", &Player::getFriendlyUnits,
|
||||
"getUnitsById", &Player::getUnitsById,
|
||||
"getUnitsByClass", &Player::getUnitsByClass,
|
||||
"isObjectVisible", &Player::isObjectVisible
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Extractor>(
|
||||
"Extractor", sol::constructors<Extractor(Player*, int, Vector3, Quaternion, int, ResourceDeposit*, Unit::State)>(),
|
||||
"getDeposit", &Extractor::getDeposit
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<ResourceDeposit>(
|
||||
"ResourceDeposit", sol::constructors<ResourceDeposit(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getExtractor", &ResourceDeposit::getExtractor,
|
||||
"getAmmount", &ResourceDeposit::getAmmount,
|
||||
"getPos", &GameObject::getPos,
|
||||
"toGameObject", [](ResourceDeposit *rd){return (GameObject*)rd;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Game>(
|
||||
"Game",
|
||||
"getSingleton", &Game::getSingleton,
|
||||
"getPlayers", &Game::getPlayers
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Vector3>(
|
||||
"Vector3", sol::constructors<Vector3(), Vector3(float, float, float)>(),
|
||||
"x", &Vector3::x,
|
||||
"y", &Vector3::y,
|
||||
"z", &Vector3::z,
|
||||
"norm", &Vector3::norm,
|
||||
"getAngleBetween", &Vector3::getAngleBetween,
|
||||
"getDistanceFrom", &Vector3::getDistanceFrom,
|
||||
"neg", [](Vector3 v){return -v;},
|
||||
"add", [](Vector3 v1, Vector3 v2){return v1 + v2;},
|
||||
"subtr", [](Vector3 v1, Vector3 v2){return v1 - v2;},
|
||||
"mult", [](Vector3 v1, float s){return v1 * s;},
|
||||
"div", [](Vector3 v1, float s){return v1 / s;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Quaternion>(
|
||||
"Quaternion", sol::constructors<Quaternion(), Quaternion(float, float, float, float), Quaternion(float, Vector3)>(),
|
||||
"w", &Quaternion::w,
|
||||
"x", &Quaternion::x,
|
||||
"y", &Quaternion::y,
|
||||
"z", &Quaternion::z,
|
||||
"getAngle", &Quaternion::getAngle,
|
||||
"getAxis", &Quaternion::getAxis,
|
||||
"multVec", [](Quaternion q, Vector3 v){return q * v;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Map::Cell>(
|
||||
"Cell",
|
||||
"pos", &Map::Cell::pos,
|
||||
"type", &Map::Cell::type
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Map>(
|
||||
"Map",
|
||||
"getSingleton", &Map::getSingleton,
|
||||
"getCell", &Map::getCell,
|
||||
"getCells", &Map::getCells,
|
||||
"getCellId", &Map::getCellId,
|
||||
"getMapSize", &Map::getMapSize,
|
||||
"getSpawnPoint", &Map::getSpawnPoint,
|
||||
"getNumSpawnPoints", &Map::getNumSpawnPoints
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Pathfinder>(
|
||||
"Pathfinder",
|
||||
"getSingleton", &Pathfinder::getSingleton,
|
||||
"calcHeuristics", &Pathfinder::calcHeuristics,
|
||||
"findPath", &Pathfinder::findPath
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<GameObjectFrame>(
|
||||
"GameObjectFrame", sol::constructors<GameObjectFrame(int, GameObject::Type, Player*, Unit*, Vector3, Quaternion)>(),
|
||||
"getOriginalUnit", &GameObjectFrame::getOriginalUnit,
|
||||
"destroy", &GameObjectFrame::destroy,
|
||||
"placeAt", &GameObjectFrame::placeAt,
|
||||
"getDirVec", &GameObjectFrame::getDirVec,
|
||||
"getLeftVec", &GameObjectFrame::getLeftVec,
|
||||
"getLength", &GameObjectFrame::getLength,
|
||||
"getWidth", &GameObjectFrame::getWidth,
|
||||
"status", &GameObjectFrame::status
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<GameObjectFrameController>(
|
||||
"GameObjectFrameController",
|
||||
"getSingleton", &GameObjectFrameController::getSingleton,
|
||||
"checkPlacement", &GameObjectFrameController::checkPlacement
|
||||
);
|
||||
}
|
||||
|
||||
void GameManager::initLua(string gameDir){
|
||||
sol::state_view SOL_LUA_STATE = generateView();
|
||||
|
||||
path = gameDir + "Assets/";
|
||||
SOL_LUA_STATE.script("PATH = \"" + path + "\";");
|
||||
|
||||
for(string f : configData::scripts)
|
||||
SOL_LUA_STATE.script_file(path + f);
|
||||
|
||||
sol::table resTable = SOL_LUA_STATE["graphics"]["resolution"];
|
||||
width = resTable["x"];
|
||||
height = resTable["y"];
|
||||
}
|
||||
|
||||
void GameManager::start(string gameDir) {
|
||||
running = true;
|
||||
registerMembers();
|
||||
initLua(gameDir);
|
||||
|
||||
Root *root = Root::getSingleton();
|
||||
root->start(width, height, path + "../external/vb01/", "Battleship");
|
||||
|
||||
stateManager = new StateManager();
|
||||
inputManager = new InputManager(stateManager, root->getWindow());
|
||||
}
|
||||
|
||||
void GameManager::update() {
|
||||
Root::getSingleton()->update();
|
||||
SoundManager::getSingleton()->update();
|
||||
inputManager->update();
|
||||
stateManager->update();
|
||||
}
|
||||
}
|
||||
#include <algorithm>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <inputManager.h>
|
||||
#include <soundManager.h>
|
||||
|
||||
#include <assetManager.h>
|
||||
#include <root.h>
|
||||
|
||||
#include "gameManager.h"
|
||||
#include "gameObjectFrameController.h"
|
||||
#include "gameObjectFactory.h"
|
||||
#include "map.h"
|
||||
#include "game.h"
|
||||
#include "guiAppState.h"
|
||||
#include "defConfigs.h"
|
||||
#include "player.h"
|
||||
#include "extractor.h"
|
||||
#include "factory.h"
|
||||
#include "vehicle.h"
|
||||
#include "engineer.h"
|
||||
#include "destructable.h"
|
||||
#include "pointDefense.h"
|
||||
#include "pathfinder.h"
|
||||
#include "resourceDeposit.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
|
||||
namespace battleship{
|
||||
static GameManager *gameManager = nullptr;
|
||||
|
||||
GameManager* GameManager::getSingleton(){
|
||||
if(!gameManager)
|
||||
gameManager = new GameManager();
|
||||
|
||||
return gameManager;
|
||||
}
|
||||
|
||||
void GameManager::registerMembers(){
|
||||
sol::state_view SOL_LUA_STATE = generateView();
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Order>(
|
||||
"Order", sol::constructors<Order(), Order(Order::TYPE, vector<Order::Target>, Vector3, int)>(),
|
||||
"type", &Order::type,
|
||||
"direction", &Order::direction,
|
||||
"targets", &Order::targets
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Order::Target>(
|
||||
"Target", sol::constructors<Order::Target(), Order::Target(GameObject*, Vector3)>(),
|
||||
"unit", &Order::Target::unit,
|
||||
"pos", &Order::Target::pos
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<GameObjectFactory>(
|
||||
"GameObjectFactory",
|
||||
"createUnit", &GameObjectFactory::createUnit,
|
||||
"createResourceDeposit", &GameObjectFactory::createResourceDeposit
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Unit::GarrisonSlot>(
|
||||
"GarrisonSlot",
|
||||
"vehicle", &Unit::GarrisonSlot::vehicle,
|
||||
"category", &Unit::GarrisonSlot::category
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Unit>(
|
||||
"Unit", sol::constructors<Unit(Player*, int, Vector3, Quaternion)>(),
|
||||
"setState", &Unit::setState,
|
||||
"getDestructable", &Unit::getDestructable,
|
||||
"getGarrisonSlots", &Unit::getGarrisonSlots,
|
||||
"getNumFreeGarrisonSlots", &Unit::getNumFreeGarrisonSlots,
|
||||
"getNumGarrisonSlots", &Unit::getNumGarrisonSlots,
|
||||
"isGarrisonEmpty", &Unit::isGarrisonEmpty,
|
||||
"getOrder", &Unit::getOrder,
|
||||
"getNumOrders", &Unit::getNumOrders,
|
||||
"getDirVec", &GameObject::getDirVec,
|
||||
"getLeftVec", &GameObject::getLeftVec,
|
||||
"getPos", &GameObject::getPos,
|
||||
"getUnitClass", &Unit::getUnitClass,
|
||||
"getLineOfSight", &Unit::getLineOfSight,
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits,
|
||||
"toGameObject", [](Unit *u){return (GameObject*)u;},
|
||||
"toVehicle", [](Unit *u){return (Vehicle*)u;},
|
||||
"toEngineer", [](Unit *u){return (Engineer*)u;},
|
||||
"toStructure", [](Unit *u){return (Structure*)u;},
|
||||
"toFactory", [](Unit *u){return (Factory*)u;},
|
||||
"toExtractor", [](Unit *u){return (Extractor*)u;},
|
||||
"toPointDefense", [](Unit *u){return (PointDefense*)u;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Vehicle>(
|
||||
"Engineer", sol::constructors<Vehicle(Player*, int, Vector3, Quaternion, Unit::State)>(),
|
||||
"getGarrisonable", &Vehicle::getGarrisonable
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Engineer>(
|
||||
"Engineer", sol::constructors<Engineer(Player*, int, Vector3, Quaternion, Unit::State)>(),
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Structure>(
|
||||
"Structure", sol::constructors<Structure(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getPos", &GameObject::getPos,
|
||||
"isComplete", &Structure::isComplete,
|
||||
"getBuildStatus", &Structure::getBuildStatus
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<BuildableUnit>(
|
||||
"BuildableUnit", sol::constructors<BuildableUnit(int, bool)>(),
|
||||
"id", &BuildableUnit::id,
|
||||
"buildable", &BuildableUnit::buildable
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Factory>(
|
||||
"Factory", sol::constructors<Factory(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits,
|
||||
"getDirVec", &GameObject::getDirVec,
|
||||
"getLeftVec", &GameObject::getLeftVec,
|
||||
"getPos", &GameObject::getPos,
|
||||
"appendToQueue", &Factory::appendToQueue,
|
||||
"getBuildStatus", &Structure::getBuildStatus,
|
||||
"getNumQueueUnitsById", &Factory::getNumQueueUnitsById,
|
||||
"getRallyPoint", &Factory::getRallyPoint,
|
||||
"setRallyPoint", &Factory::setRallyPoint,
|
||||
"getQueue", &Factory::getQueue
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Player>(
|
||||
"Player", sol::constructors<Player(int, int, int, Vector3, bool, int, string)>(),
|
||||
"getSelectedUnits", &Player::getSelectedUnits,
|
||||
"haltUnits", &Player::haltUnits,
|
||||
"addUnit", &Player::addUnit,
|
||||
"getUnit", &Player::getUnit,
|
||||
"getNumUnits", &Player::getNumUnits,
|
||||
"getResourceDeposits", &Player::getResourceDeposits,
|
||||
"issueOrder", &Player::issueOrder,
|
||||
"selectUnits", &Player::selectUnits,
|
||||
"deselectUnits", &Player::deselectUnits,
|
||||
"getSpawnPointId", &Player::getSpawnPointId,
|
||||
"getFaction", &Player::getFaction,
|
||||
"getTeam", &Player::getTeam,
|
||||
"getUnits", &Player::getUnits,
|
||||
"getHostileUnits", &Player::getHostileUnits,
|
||||
"getFriendlyUnits", &Player::getFriendlyUnits,
|
||||
"getUnitsById", &Player::getUnitsById,
|
||||
"getUnitsByClass", &Player::getUnitsByClass,
|
||||
"isObjectVisible", &Player::isObjectVisible
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Extractor>(
|
||||
"Extractor", sol::constructors<Extractor(Player*, int, Vector3, Quaternion, int, ResourceDeposit*, Unit::State)>(),
|
||||
"getDeposit", &Extractor::getDeposit
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<ResourceDeposit>(
|
||||
"ResourceDeposit", sol::constructors<ResourceDeposit(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getExtractor", &ResourceDeposit::getExtractor,
|
||||
"getAmmount", &ResourceDeposit::getAmmount,
|
||||
"getPos", &GameObject::getPos,
|
||||
"toGameObject", [](ResourceDeposit *rd){return (GameObject*)rd;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Game>(
|
||||
"Game",
|
||||
"getSingleton", &Game::getSingleton,
|
||||
"getPlayers", &Game::getPlayers
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Vector3>(
|
||||
"Vector3", sol::constructors<Vector3(), Vector3(float, float, float)>(),
|
||||
"x", &Vector3::x,
|
||||
"y", &Vector3::y,
|
||||
"z", &Vector3::z,
|
||||
"norm", &Vector3::norm,
|
||||
"getAngleBetween", &Vector3::getAngleBetween,
|
||||
"getDistanceFrom", &Vector3::getDistanceFrom,
|
||||
"neg", [](Vector3 v){return -v;},
|
||||
"add", [](Vector3 v1, Vector3 v2){return v1 + v2;},
|
||||
"subtr", [](Vector3 v1, Vector3 v2){return v1 - v2;},
|
||||
"mult", [](Vector3 v1, float s){return v1 * s;},
|
||||
"div", [](Vector3 v1, float s){return v1 / s;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Quaternion>(
|
||||
"Quaternion", sol::constructors<Quaternion(), Quaternion(float, float, float, float), Quaternion(float, Vector3)>(),
|
||||
"w", &Quaternion::w,
|
||||
"x", &Quaternion::x,
|
||||
"y", &Quaternion::y,
|
||||
"z", &Quaternion::z,
|
||||
"getAngle", &Quaternion::getAngle,
|
||||
"getAxis", &Quaternion::getAxis,
|
||||
"multVec", [](Quaternion q, Vector3 v){return q * v;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Map::Cell>(
|
||||
"Cell",
|
||||
"pos", &Map::Cell::pos,
|
||||
"type", &Map::Cell::type
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Map>(
|
||||
"Map",
|
||||
"getSingleton", &Map::getSingleton,
|
||||
"getCell", &Map::getCell,
|
||||
"getCells", &Map::getCells,
|
||||
"getCellId", &Map::getCellId,
|
||||
"getMapSize", &Map::getMapSize,
|
||||
"getSpawnPoint", &Map::getSpawnPoint,
|
||||
"getNumSpawnPoints", &Map::getNumSpawnPoints
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Pathfinder>(
|
||||
"Pathfinder",
|
||||
"getSingleton", &Pathfinder::getSingleton,
|
||||
"calcHeuristics", &Pathfinder::calcHeuristics,
|
||||
"findPath", &Pathfinder::findPath
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<GameObjectFrame>(
|
||||
"GameObjectFrame", sol::constructors<GameObjectFrame(int, GameObject::Type, Player*, Unit*, Vector3, Quaternion)>(),
|
||||
"getOriginalUnit", &GameObjectFrame::getOriginalUnit,
|
||||
"destroy", &GameObjectFrame::destroy,
|
||||
"placeAt", &GameObjectFrame::placeAt,
|
||||
"getDirVec", &GameObjectFrame::getDirVec,
|
||||
"getLeftVec", &GameObjectFrame::getLeftVec,
|
||||
"getLength", &GameObjectFrame::getLength,
|
||||
"getWidth", &GameObjectFrame::getWidth,
|
||||
"status", &GameObjectFrame::status
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<GameObjectFrameController>(
|
||||
"GameObjectFrameController",
|
||||
"getSingleton", &GameObjectFrameController::getSingleton,
|
||||
"checkPlacement", &GameObjectFrameController::checkPlacement
|
||||
);
|
||||
}
|
||||
|
||||
void GameManager::initLua(string gameDir){
|
||||
sol::state_view SOL_LUA_STATE = generateView();
|
||||
|
||||
path = gameDir + "Assets/";
|
||||
SOL_LUA_STATE.script("PATH = \"" + path + "\";");
|
||||
|
||||
for(string f : configData::scripts)
|
||||
SOL_LUA_STATE.script_file(path + f);
|
||||
|
||||
sol::table resTable = SOL_LUA_STATE["graphics"]["resolution"];
|
||||
width = resTable["x"];
|
||||
height = resTable["y"];
|
||||
}
|
||||
|
||||
void GameManager::start(string gameDir) {
|
||||
running = true;
|
||||
registerMembers();
|
||||
initLua(gameDir);
|
||||
|
||||
Root *root = Root::getSingleton();
|
||||
root->start(width, height, path + "../external/vb01/", "Battleship");
|
||||
|
||||
stateManager = new StateManager();
|
||||
inputManager = new InputManager(stateManager, root->getWindow());
|
||||
}
|
||||
|
||||
void GameManager::update() {
|
||||
Root::getSingleton()->update();
|
||||
SoundManager::getSingleton()->update();
|
||||
inputManager->update();
|
||||
stateManager->update();
|
||||
}
|
||||
}
|
||||
Executable → Regular
+754
-754
File diff suppressed because it is too large
Load Diff
Executable → Regular
+358
-358
@@ -1,358 +1,358 @@
|
||||
#include <solUtil.h>
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "player.h"
|
||||
#include "game.h"
|
||||
#include "structure.h"
|
||||
#include "vehicle.h"
|
||||
#include "projectile.h"
|
||||
#include "tradeOffer.h"
|
||||
#include "destructable.h"
|
||||
#include "activeGameState.h"
|
||||
#include "resourceDeposit.h"
|
||||
|
||||
namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
using namespace std;
|
||||
|
||||
Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, int sp, string n) :
|
||||
difficulty(diff),
|
||||
faction(fac),
|
||||
team(t),
|
||||
color(col),
|
||||
cpuPlayer(cpuPl),
|
||||
spawnPointId(sp),
|
||||
name("pl"),
|
||||
trader(new Trader())
|
||||
{
|
||||
resources[0] = 30000;
|
||||
|
||||
colorMaterial = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
colorMaterial->addBoolUniform("lightingEnabled", false);
|
||||
colorMaterial->addBoolUniform("texturingEnabled", false);
|
||||
colorMaterial->addVec4Uniform("diffuseColor", Vector4(color.x, color.y, color.z, 1));
|
||||
}
|
||||
|
||||
Player::~Player() {
|
||||
delete colorMaterial;
|
||||
}
|
||||
|
||||
void Player::update() {
|
||||
trader->update();
|
||||
|
||||
vector<Unit*> units = this->units;
|
||||
for(Unit *u : units){
|
||||
if(!u->isRemove()) u->update();
|
||||
else removeUnit(u);
|
||||
}
|
||||
|
||||
vector<Projectile*> projectiles = this->projectiles;
|
||||
for(Projectile *proj : projectiles){
|
||||
if(!proj->isRemove()) proj->update();
|
||||
else removeProjectile(proj);
|
||||
}
|
||||
|
||||
for(ResourceDeposit *rd : resourceDeposits) rd->update();
|
||||
|
||||
for(pair<Player*, vector<TradeOffer*>> &pair : tradeOffers){
|
||||
if(pair.second.empty()) continue;
|
||||
|
||||
bool fulfiled = true;
|
||||
|
||||
for(int i = 0; i < NUM_RESOURCES && fulfiled; i++){
|
||||
bool b = (pair.second[0]->tradeResources[i][0] == pair.second[0]->deliveredResources[i][0]);
|
||||
bool s = (pair.second[0]->tradeResources[i][1] == pair.second[0]->deliveredResources[i][1]);
|
||||
|
||||
if(!(b && s)) fulfiled = false;
|
||||
}
|
||||
|
||||
if(fulfiled)
|
||||
pair.second.erase(pair.second.begin());
|
||||
}
|
||||
}
|
||||
|
||||
void Player::haltUnits(){
|
||||
for (Unit *u : selectedUnits)
|
||||
u->halt();
|
||||
}
|
||||
|
||||
int Player::getOrderLineId(Order::TYPE type, Vector3 startPos, Vector3 endPos){
|
||||
Vector3 color;
|
||||
|
||||
switch(type){
|
||||
case Order::TYPE::MOVE:
|
||||
color = Vector3::VEC_J;
|
||||
break;
|
||||
case Order::TYPE::ATTACK:
|
||||
color = Vector3::VEC_I;
|
||||
break;
|
||||
case Order::TYPE::PATROL:
|
||||
case Order::TYPE::GARRISON:
|
||||
case Order::TYPE::EJECT:
|
||||
color = Vector3::VEC_K;
|
||||
break;
|
||||
case Order::TYPE::BUILD:
|
||||
case Order::TYPE::SUPPLY:
|
||||
case Order::TYPE::LOAD:
|
||||
case Order::TYPE::UNLOAD:
|
||||
color = Vector3(1, 1, 0);
|
||||
break;
|
||||
case Order::TYPE::HACK:
|
||||
color = Vector3(1, 0, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
LineRenderer *lineRenderer = LineRenderer::getSingleton();
|
||||
lineRenderer->addLine(startPos, endPos, color);
|
||||
vector<LineRenderer::Line> lines = lineRenderer->getLines();
|
||||
|
||||
return lines[lines.size() - 1].id;
|
||||
}
|
||||
|
||||
void Player::issueOrder(Order::TYPE type, Vector3 destDir, vector<Order::Target> targets, bool append){
|
||||
vector<Unit*> selectedUnits = getSelectedUnits();
|
||||
|
||||
for (Unit *u : selectedUnits) {
|
||||
bool targetingSelf = false, structBuilt = true;
|
||||
|
||||
for(Order::Target &targ : targets){
|
||||
if(targ.unit && targ.unit == u){
|
||||
targetingSelf = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!u->isVehicle() && ((Structure*)u)->isComplete()){
|
||||
structBuilt = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(targetingSelf || !structBuilt) continue;
|
||||
|
||||
int lineId = -1;
|
||||
ActiveGameState *activeState = ((ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE));
|
||||
|
||||
if(activeState && activeState->getPlayer() == this && type != Order::TYPE::EJECT)
|
||||
lineId = getOrderLineId(type, u->getPos(), targets[0].pos);
|
||||
|
||||
u->receiveOrder(Order(type, targets, destDir, lineId), append);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeUnit(Unit *unit){
|
||||
for(int i = 0; i < units.size(); i++)
|
||||
if(unit == units[i]){
|
||||
removeUnit(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeUnit(int id){
|
||||
if(find(selectedUnits.begin(), selectedUnits.end(), units[id]) != selectedUnits.end())
|
||||
deselectUnit(units[id]);
|
||||
|
||||
delete units[id];
|
||||
units.erase(units.begin() + id);
|
||||
|
||||
if(cpuPlayer){
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
int id = getCpuPlayerId() + 1;
|
||||
SOL_LUA_VIEW.script("game.cpuPlayers[" + to_string(id) + "]:updateTaskForces()");
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeResourceDeposit(int id){
|
||||
delete resourceDeposits[id];
|
||||
resourceDeposits.erase(resourceDeposits.begin() + id);
|
||||
}
|
||||
|
||||
void Player::removeProjectile(Projectile *proj){
|
||||
for(int i = 0; i < projectiles.size(); i++)
|
||||
if(proj == projectiles[i]){
|
||||
removeProjectile(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeProjectile(int id){
|
||||
delete projectiles[id];
|
||||
projectiles.erase(projectiles.begin() + id);
|
||||
}
|
||||
|
||||
void Player::selectUnits(vector<Unit*> selUnits){
|
||||
for(Unit *u : selUnits){
|
||||
bool garrisonable = (!u->isVehicle() || (u->isVehicle() && !((Vehicle*)u)->getGarrisonable()));
|
||||
bool selected = (find(selectedUnits.begin(), selectedUnits.end(), u) != selectedUnits.end());
|
||||
|
||||
if(garrisonable && !selected){
|
||||
selectedUnits.push_back(u);
|
||||
u->select();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getUnitsById(int id, int numUnits){
|
||||
vector<Unit*> idUnits;
|
||||
|
||||
for(Unit *unit : units){
|
||||
if(numUnits != -1 && idUnits.size() == numUnits)
|
||||
break;
|
||||
|
||||
if(unit->getId() == id)
|
||||
idUnits.push_back(unit);
|
||||
}
|
||||
|
||||
return idUnits;
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getUnitsByClass(UnitClass uc, int numUnits){
|
||||
vector<Unit*> ucUnits;
|
||||
|
||||
for(Unit *unit : units){
|
||||
if(numUnits != -1 && ucUnits.size() == numUnits)
|
||||
break;
|
||||
|
||||
if(unit->getUnitClass() == uc)
|
||||
ucUnits.push_back(unit);
|
||||
}
|
||||
|
||||
return ucUnits;
|
||||
}
|
||||
|
||||
void Player::updateTradedResource(Player *player, ResourceType type, int amount, bool selfDistributed, bool increased){
|
||||
for(pair<Player*, vector<TradedResource>> pair : tradedResources)
|
||||
if(pair.first == player){
|
||||
TradedResource &tr = pair.second[(int)type];
|
||||
|
||||
if(selfDistributed) (increased ? tr.taken : tr.given) += amount;
|
||||
else (increased ? tr.received : tr.hadTaken) += amount;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::initTradingVecs(){
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers();
|
||||
|
||||
for(Player *pl : players){
|
||||
if(this == pl) continue;
|
||||
|
||||
if(team == pl->getTeam()){
|
||||
tradeOffers.push_back(make_pair(pl, vector<TradeOffer*>{}));
|
||||
tradedResources.push_back(make_pair(pl, vector<TradedResource>{
|
||||
TradedResource(ResourceType::REFINEDS),
|
||||
TradedResource(ResourceType::WEALTH),
|
||||
TradedResource(ResourceType::RESEARCH)
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::addTradeOffer(Player *player, TradeOffer *offer){
|
||||
if(tradeOffers.empty()) initTradingVecs();
|
||||
|
||||
for(pair<Player*, vector<TradeOffer*>> &offers : tradeOffers)
|
||||
if(offers.first == player)
|
||||
offers.second.push_back(offer);
|
||||
}
|
||||
|
||||
vector<TradeOffer*> Player::getTradeOffers(Player *player){
|
||||
for(pair<Player*, vector<TradeOffer*>> offers : tradeOffers)
|
||||
if(offers.first == player)
|
||||
return offers.second;
|
||||
|
||||
return vector<TradeOffer*>{};
|
||||
}
|
||||
|
||||
void Player::deselectUnit(Unit *unit){
|
||||
for(int i = 0; i < selectedUnits.size(); i++)
|
||||
if(selectedUnits[i] == unit){
|
||||
selectedUnits.erase(selectedUnits.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vector<GameObject*> Player::getDestructables(){
|
||||
vector<GameObject*> destructables;
|
||||
|
||||
for(Projectile *p : projectiles)
|
||||
if(p->getDestructable())
|
||||
destructables.push_back(p);
|
||||
|
||||
for(Unit *unit : units)
|
||||
destructables.push_back((GameObject*)unit);
|
||||
|
||||
return destructables;
|
||||
}
|
||||
|
||||
void Player::updateGameStats(Unit *targetUnit){
|
||||
Destructable *destructTarg = targetUnit->getDestructable();
|
||||
|
||||
if(destructTarg->getHealth() <= destructTarg->getDeathHp()){
|
||||
Player *targUnitPlayer = targetUnit->getPlayer();
|
||||
|
||||
if(targetUnit->isVehicle()){
|
||||
incVehiclesDestroyed();
|
||||
targUnitPlayer->incVehiclesLost();
|
||||
}
|
||||
else{
|
||||
incStructuresDestroyed();
|
||||
targUnitPlayer->incStructuresLost();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getFriendlyUnits(bool includeOwn){
|
||||
vector<Unit*> friendlyUnits;
|
||||
|
||||
for (Player *pl : Game::getSingleton()->getPlayers(true))
|
||||
for (Unit *u : pl->getUnits())
|
||||
if((includeOwn && pl == this) || pl->getTeam() == getTeam())
|
||||
friendlyUnits.push_back(u);
|
||||
|
||||
return friendlyUnits;
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getHostileUnits(){
|
||||
vector<Unit*> hostileUnits, friendlyUnits = getFriendlyUnits(true);
|
||||
|
||||
for (Player *pl : Game::getSingleton()->getPlayers(true))
|
||||
for (Unit *u : pl->getUnits())
|
||||
if(pl->getTeam() != getTeam() && isObjectVisible(u, friendlyUnits))
|
||||
hostileUnits.push_back(u);
|
||||
|
||||
return hostileUnits;
|
||||
}
|
||||
|
||||
//TODO improve this for greater accuracy
|
||||
bool Player::isObjectVisible(GameObject *object, std::vector<Unit*> friendlyUnits) {
|
||||
Player *objPlayer = object->getPlayer();
|
||||
|
||||
for(Unit *friendlyUnit : friendlyUnits){
|
||||
if(objPlayer == this || objPlayer->getTeam() == getTeam())
|
||||
return true;
|
||||
|
||||
Vector3 obsUnitPos = object->getPos();
|
||||
Vector2 oup2d = Vector2(obsUnitPos.x, obsUnitPos.z);
|
||||
|
||||
Vector3 compUnitPos = friendlyUnit->getPos();
|
||||
Vector2 cup2d = Vector2(compUnitPos.x, compUnitPos.z);
|
||||
|
||||
if(cup2d.getDistanceFrom(oup2d) <= friendlyUnit->getLineOfSight())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int Player::getCpuPlayerId(){
|
||||
vector<Player*> cpuPlayers = Game::getSingleton()->getCpuPlayers();
|
||||
|
||||
for(int i = 0; i < cpuPlayers.size(); i++)
|
||||
if(cpuPlayers[i] == this)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#include <solUtil.h>
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "player.h"
|
||||
#include "game.h"
|
||||
#include "structure.h"
|
||||
#include "vehicle.h"
|
||||
#include "projectile.h"
|
||||
#include "tradeOffer.h"
|
||||
#include "destructable.h"
|
||||
#include "activeGameState.h"
|
||||
#include "resourceDeposit.h"
|
||||
|
||||
namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
using namespace std;
|
||||
|
||||
Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, int sp, string n) :
|
||||
difficulty(diff),
|
||||
faction(fac),
|
||||
team(t),
|
||||
color(col),
|
||||
cpuPlayer(cpuPl),
|
||||
spawnPointId(sp),
|
||||
name("pl"),
|
||||
trader(new Trader())
|
||||
{
|
||||
resources[0] = 30000;
|
||||
|
||||
colorMaterial = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
colorMaterial->addBoolUniform("lightingEnabled", false);
|
||||
colorMaterial->addBoolUniform("texturingEnabled", false);
|
||||
colorMaterial->addVec4Uniform("diffuseColor", Vector4(color.x, color.y, color.z, 1));
|
||||
}
|
||||
|
||||
Player::~Player() {
|
||||
delete colorMaterial;
|
||||
}
|
||||
|
||||
void Player::update() {
|
||||
trader->update();
|
||||
|
||||
vector<Unit*> units = this->units;
|
||||
for(Unit *u : units){
|
||||
if(!u->isRemove()) u->update();
|
||||
else removeUnit(u);
|
||||
}
|
||||
|
||||
vector<Projectile*> projectiles = this->projectiles;
|
||||
for(Projectile *proj : projectiles){
|
||||
if(!proj->isRemove()) proj->update();
|
||||
else removeProjectile(proj);
|
||||
}
|
||||
|
||||
for(ResourceDeposit *rd : resourceDeposits) rd->update();
|
||||
|
||||
for(pair<Player*, vector<TradeOffer*>> &pair : tradeOffers){
|
||||
if(pair.second.empty()) continue;
|
||||
|
||||
bool fulfiled = true;
|
||||
|
||||
for(int i = 0; i < NUM_RESOURCES && fulfiled; i++){
|
||||
bool b = (pair.second[0]->tradeResources[i][0] == pair.second[0]->deliveredResources[i][0]);
|
||||
bool s = (pair.second[0]->tradeResources[i][1] == pair.second[0]->deliveredResources[i][1]);
|
||||
|
||||
if(!(b && s)) fulfiled = false;
|
||||
}
|
||||
|
||||
if(fulfiled)
|
||||
pair.second.erase(pair.second.begin());
|
||||
}
|
||||
}
|
||||
|
||||
void Player::haltUnits(){
|
||||
for (Unit *u : selectedUnits)
|
||||
u->halt();
|
||||
}
|
||||
|
||||
int Player::getOrderLineId(Order::TYPE type, Vector3 startPos, Vector3 endPos){
|
||||
Vector3 color;
|
||||
|
||||
switch(type){
|
||||
case Order::TYPE::MOVE:
|
||||
color = Vector3::VEC_J;
|
||||
break;
|
||||
case Order::TYPE::ATTACK:
|
||||
color = Vector3::VEC_I;
|
||||
break;
|
||||
case Order::TYPE::PATROL:
|
||||
case Order::TYPE::GARRISON:
|
||||
case Order::TYPE::EJECT:
|
||||
color = Vector3::VEC_K;
|
||||
break;
|
||||
case Order::TYPE::BUILD:
|
||||
case Order::TYPE::SUPPLY:
|
||||
case Order::TYPE::LOAD:
|
||||
case Order::TYPE::UNLOAD:
|
||||
color = Vector3(1, 1, 0);
|
||||
break;
|
||||
case Order::TYPE::HACK:
|
||||
color = Vector3(1, 0, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
LineRenderer *lineRenderer = LineRenderer::getSingleton();
|
||||
lineRenderer->addLine(startPos, endPos, color);
|
||||
vector<LineRenderer::Line> lines = lineRenderer->getLines();
|
||||
|
||||
return lines[lines.size() - 1].id;
|
||||
}
|
||||
|
||||
void Player::issueOrder(Order::TYPE type, Vector3 destDir, vector<Order::Target> targets, bool append){
|
||||
vector<Unit*> selectedUnits = getSelectedUnits();
|
||||
|
||||
for (Unit *u : selectedUnits) {
|
||||
bool targetingSelf = false, structBuilt = true;
|
||||
|
||||
for(Order::Target &targ : targets){
|
||||
if(targ.unit && targ.unit == u){
|
||||
targetingSelf = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!u->isVehicle() && ((Structure*)u)->isComplete()){
|
||||
structBuilt = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(targetingSelf || !structBuilt) continue;
|
||||
|
||||
int lineId = -1;
|
||||
ActiveGameState *activeState = ((ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE));
|
||||
|
||||
if(activeState && activeState->getPlayer() == this && type != Order::TYPE::EJECT)
|
||||
lineId = getOrderLineId(type, u->getPos(), targets[0].pos);
|
||||
|
||||
u->receiveOrder(Order(type, targets, destDir, lineId), append);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeUnit(Unit *unit){
|
||||
for(int i = 0; i < units.size(); i++)
|
||||
if(unit == units[i]){
|
||||
removeUnit(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeUnit(int id){
|
||||
if(find(selectedUnits.begin(), selectedUnits.end(), units[id]) != selectedUnits.end())
|
||||
deselectUnit(units[id]);
|
||||
|
||||
delete units[id];
|
||||
units.erase(units.begin() + id);
|
||||
|
||||
if(cpuPlayer){
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
int id = getCpuPlayerId() + 1;
|
||||
SOL_LUA_VIEW.script("game.cpuPlayers[" + to_string(id) + "]:updateTaskForces()");
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeResourceDeposit(int id){
|
||||
delete resourceDeposits[id];
|
||||
resourceDeposits.erase(resourceDeposits.begin() + id);
|
||||
}
|
||||
|
||||
void Player::removeProjectile(Projectile *proj){
|
||||
for(int i = 0; i < projectiles.size(); i++)
|
||||
if(proj == projectiles[i]){
|
||||
removeProjectile(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeProjectile(int id){
|
||||
delete projectiles[id];
|
||||
projectiles.erase(projectiles.begin() + id);
|
||||
}
|
||||
|
||||
void Player::selectUnits(vector<Unit*> selUnits){
|
||||
for(Unit *u : selUnits){
|
||||
bool garrisonable = (!u->isVehicle() || (u->isVehicle() && !((Vehicle*)u)->getGarrisonable()));
|
||||
bool selected = (find(selectedUnits.begin(), selectedUnits.end(), u) != selectedUnits.end());
|
||||
|
||||
if(garrisonable && !selected){
|
||||
selectedUnits.push_back(u);
|
||||
u->select();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getUnitsById(int id, int numUnits){
|
||||
vector<Unit*> idUnits;
|
||||
|
||||
for(Unit *unit : units){
|
||||
if(numUnits != -1 && idUnits.size() == numUnits)
|
||||
break;
|
||||
|
||||
if(unit->getId() == id)
|
||||
idUnits.push_back(unit);
|
||||
}
|
||||
|
||||
return idUnits;
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getUnitsByClass(UnitClass uc, int numUnits){
|
||||
vector<Unit*> ucUnits;
|
||||
|
||||
for(Unit *unit : units){
|
||||
if(numUnits != -1 && ucUnits.size() == numUnits)
|
||||
break;
|
||||
|
||||
if(unit->getUnitClass() == uc)
|
||||
ucUnits.push_back(unit);
|
||||
}
|
||||
|
||||
return ucUnits;
|
||||
}
|
||||
|
||||
void Player::updateTradedResource(Player *player, ResourceType type, int amount, bool selfDistributed, bool increased){
|
||||
for(pair<Player*, vector<TradedResource>> pair : tradedResources)
|
||||
if(pair.first == player){
|
||||
TradedResource &tr = pair.second[(int)type];
|
||||
|
||||
if(selfDistributed) (increased ? tr.taken : tr.given) += amount;
|
||||
else (increased ? tr.received : tr.hadTaken) += amount;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::initTradingVecs(){
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers();
|
||||
|
||||
for(Player *pl : players){
|
||||
if(this == pl) continue;
|
||||
|
||||
if(team == pl->getTeam()){
|
||||
tradeOffers.push_back(make_pair(pl, vector<TradeOffer*>{}));
|
||||
tradedResources.push_back(make_pair(pl, vector<TradedResource>{
|
||||
TradedResource(ResourceType::REFINEDS),
|
||||
TradedResource(ResourceType::WEALTH),
|
||||
TradedResource(ResourceType::RESEARCH)
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::addTradeOffer(Player *player, TradeOffer *offer){
|
||||
if(tradeOffers.empty()) initTradingVecs();
|
||||
|
||||
for(pair<Player*, vector<TradeOffer*>> &offers : tradeOffers)
|
||||
if(offers.first == player)
|
||||
offers.second.push_back(offer);
|
||||
}
|
||||
|
||||
vector<TradeOffer*> Player::getTradeOffers(Player *player){
|
||||
for(pair<Player*, vector<TradeOffer*>> offers : tradeOffers)
|
||||
if(offers.first == player)
|
||||
return offers.second;
|
||||
|
||||
return vector<TradeOffer*>{};
|
||||
}
|
||||
|
||||
void Player::deselectUnit(Unit *unit){
|
||||
for(int i = 0; i < selectedUnits.size(); i++)
|
||||
if(selectedUnits[i] == unit){
|
||||
selectedUnits.erase(selectedUnits.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vector<GameObject*> Player::getDestructables(){
|
||||
vector<GameObject*> destructables;
|
||||
|
||||
for(Projectile *p : projectiles)
|
||||
if(p->getDestructable())
|
||||
destructables.push_back(p);
|
||||
|
||||
for(Unit *unit : units)
|
||||
destructables.push_back((GameObject*)unit);
|
||||
|
||||
return destructables;
|
||||
}
|
||||
|
||||
void Player::updateGameStats(Unit *targetUnit){
|
||||
Destructable *destructTarg = targetUnit->getDestructable();
|
||||
|
||||
if(destructTarg->getHealth() <= destructTarg->getDeathHp()){
|
||||
Player *targUnitPlayer = targetUnit->getPlayer();
|
||||
|
||||
if(targetUnit->isVehicle()){
|
||||
incVehiclesDestroyed();
|
||||
targUnitPlayer->incVehiclesLost();
|
||||
}
|
||||
else{
|
||||
incStructuresDestroyed();
|
||||
targUnitPlayer->incStructuresLost();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getFriendlyUnits(bool includeOwn){
|
||||
vector<Unit*> friendlyUnits;
|
||||
|
||||
for (Player *pl : Game::getSingleton()->getPlayers(true))
|
||||
for (Unit *u : pl->getUnits())
|
||||
if((includeOwn && pl == this) || pl->getTeam() == getTeam())
|
||||
friendlyUnits.push_back(u);
|
||||
|
||||
return friendlyUnits;
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getHostileUnits(){
|
||||
vector<Unit*> hostileUnits, friendlyUnits = getFriendlyUnits(true);
|
||||
|
||||
for (Player *pl : Game::getSingleton()->getPlayers(true))
|
||||
for (Unit *u : pl->getUnits())
|
||||
if(pl->getTeam() != getTeam() && isObjectVisible(u, friendlyUnits))
|
||||
hostileUnits.push_back(u);
|
||||
|
||||
return hostileUnits;
|
||||
}
|
||||
|
||||
//TODO improve this for greater accuracy
|
||||
bool Player::isObjectVisible(GameObject *object, std::vector<Unit*> friendlyUnits) {
|
||||
Player *objPlayer = object->getPlayer();
|
||||
|
||||
for(Unit *friendlyUnit : friendlyUnits){
|
||||
if(objPlayer == this || objPlayer->getTeam() == getTeam())
|
||||
return true;
|
||||
|
||||
Vector3 obsUnitPos = object->getPos();
|
||||
Vector2 oup2d = Vector2(obsUnitPos.x, obsUnitPos.z);
|
||||
|
||||
Vector3 compUnitPos = friendlyUnit->getPos();
|
||||
Vector2 cup2d = Vector2(compUnitPos.x, compUnitPos.z);
|
||||
|
||||
if(cup2d.getDistanceFrom(oup2d) <= friendlyUnit->getLineOfSight())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int Player::getCpuPlayerId(){
|
||||
vector<Player*> cpuPlayers = Game::getSingleton()->getCpuPlayers();
|
||||
|
||||
for(int i = 0; i < cpuPlayers.size(); i++)
|
||||
if(cpuPlayers[i] == this)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
Executable → Regular
+131
-131
@@ -1,131 +1,131 @@
|
||||
#include <node.h>
|
||||
#include <model.h>
|
||||
#include <material.h>
|
||||
#include <quaternion.h>
|
||||
#include <particleEmitter.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "game.h"
|
||||
#include "unit.h"
|
||||
#include "util.h"
|
||||
#include "player.h"
|
||||
#include "environment.h"
|
||||
#include "projectile.h"
|
||||
#include "defConfigs.h"
|
||||
#include "destructable.h"
|
||||
#include "resourceDeposit.h"
|
||||
#include "inGameAppState.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace configData;
|
||||
using namespace gameBase;
|
||||
|
||||
Projectile::Projectile(Unit *un, int id, Vector3 pos, Quaternion rot) : GameObject(GameObject::Type::PROJECTILE, id, un->getPlayer(), pos, rot), unit(un), initPos(pos){
|
||||
initProperties();
|
||||
initModel();
|
||||
initSound();
|
||||
placeAt(pos);
|
||||
orientAt(rot);
|
||||
}
|
||||
|
||||
Projectile::~Projectile(){
|
||||
destroySound();
|
||||
destroyModel();
|
||||
}
|
||||
|
||||
void Projectile::reinit(){
|
||||
destroySound();
|
||||
destroyModel();
|
||||
|
||||
initProperties();
|
||||
|
||||
initModel();
|
||||
|
||||
GameObject::reinit();
|
||||
}
|
||||
|
||||
void Projectile::initProperties(){
|
||||
GameObject::initProperties();
|
||||
Game *game = Game::getSingleton();
|
||||
vector<int> currTechs = player->getTechnologies();
|
||||
|
||||
sol::table projTable = generateView()[GameObject::getGameObjTableName()][id + 1];
|
||||
projClass = (ProjectileClass)projTable["projectileClass"];
|
||||
|
||||
rayLength = projTable["rayLength"];
|
||||
directHitDamage = projTable["directHitDamage"]; directHitDamage += game->calcAbilFromTech(Ability::Type::DIRECT_HIT_DAMAGE, currTechs, (int)GameObject::type, id);
|
||||
|
||||
string explKey = "explosion";
|
||||
explosionDamage = projTable[explKey]["damage"]; explosionDamage += game->calcAbilFromTech(Ability::Type::EXPLOSION_DAMAGE, currTechs, (int)GameObject::type, id);
|
||||
explosionRadius = projTable[explKey]["radius"]; explosionRadius += game->calcAbilFromTech(Ability::Type::EXPLOSION_RADIUS, currTechs, (int)GameObject::type, id);
|
||||
speed = projTable["speed"];
|
||||
rotAngle = projTable["rotAngle"].get_or(0.0);
|
||||
}
|
||||
|
||||
void Projectile::update() {
|
||||
GameObject::update();
|
||||
placeAt(pos + speed * dirVec);
|
||||
}
|
||||
|
||||
void Projectile::detonate(Unit *target){
|
||||
if(target) target->getDestructable()->takeDamage(directHitDamage);
|
||||
|
||||
sol::table tbl = generateView()[getGameObjTableName()][id + 1]["explosion"];
|
||||
FxManager::Fx *fx = FxManager::getSingleton()->initFx(tbl["fx"], model, false, pos);
|
||||
Environment::explode(fx, (Environment::Detonation)tbl["detonation"], pos, tbl["damage"], tbl["radius"]);
|
||||
|
||||
remove = true;
|
||||
}
|
||||
|
||||
void Projectile::checkUnitCollision(){
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers(true);
|
||||
vector<Unit*> targetUnits;
|
||||
vector<Node*> targetNodes;
|
||||
|
||||
for(Player *pl : players){
|
||||
vector<Unit*> units = pl->getUnits();
|
||||
|
||||
for(Unit *u : units)
|
||||
if(unit && unit != u){
|
||||
targetUnits.push_back(u);
|
||||
targetNodes.push_back(u->getHitbox());
|
||||
}
|
||||
}
|
||||
|
||||
vector<RayCaster::CollisionResult> results = RayCaster::cast(pos, dirVec, targetNodes, rayLength);
|
||||
|
||||
if(!results.empty())
|
||||
for(int i = 0; i < targetNodes.size(); i++)
|
||||
if(targetNodes[i]->getMesh(0) == results[0].mesh)
|
||||
detonate(targetUnits[i]);
|
||||
}
|
||||
|
||||
//TODO fix map boundary checks
|
||||
void Projectile::checkSurfaceCollision(bool useBottomCell){
|
||||
Map *map = Map::getSingleton();
|
||||
vector<Map::Cell> &cells = map->getCells();
|
||||
int cellId = map->getCellId(pos, false);
|
||||
Vector3 mapSize = map->getMapSize();
|
||||
|
||||
if(cellId < 0 || fabs(pos.x) > .5 * mapSize.x || fabs(pos.z) > .5 * mapSize.z){
|
||||
remove = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(useBottomCell && !cells[cellId].underWaterCellIds.empty()){
|
||||
int numUnderwaterCells = cells[cellId].underWaterCellIds.size();
|
||||
cellId = cells[cellId].underWaterCellIds[numUnderwaterCells - 1];
|
||||
}
|
||||
|
||||
if((pos + dirVec * rayLength).y <= cells[cellId].pos.y + .5 * map->getCellSize().y)
|
||||
detonate();
|
||||
}
|
||||
|
||||
void Projectile::debug(){
|
||||
}
|
||||
}
|
||||
#include <node.h>
|
||||
#include <model.h>
|
||||
#include <material.h>
|
||||
#include <quaternion.h>
|
||||
#include <particleEmitter.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "game.h"
|
||||
#include "unit.h"
|
||||
#include "util.h"
|
||||
#include "player.h"
|
||||
#include "environment.h"
|
||||
#include "projectile.h"
|
||||
#include "defConfigs.h"
|
||||
#include "destructable.h"
|
||||
#include "resourceDeposit.h"
|
||||
#include "inGameAppState.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace configData;
|
||||
using namespace gameBase;
|
||||
|
||||
Projectile::Projectile(Unit *un, int id, Vector3 pos, Quaternion rot) : GameObject(GameObject::Type::PROJECTILE, id, un->getPlayer(), pos, rot), unit(un), initPos(pos){
|
||||
initProperties();
|
||||
initModel();
|
||||
initSound();
|
||||
placeAt(pos);
|
||||
orientAt(rot);
|
||||
}
|
||||
|
||||
Projectile::~Projectile(){
|
||||
destroySound();
|
||||
destroyModel();
|
||||
}
|
||||
|
||||
void Projectile::reinit(){
|
||||
destroySound();
|
||||
destroyModel();
|
||||
|
||||
initProperties();
|
||||
|
||||
initModel();
|
||||
|
||||
GameObject::reinit();
|
||||
}
|
||||
|
||||
void Projectile::initProperties(){
|
||||
GameObject::initProperties();
|
||||
Game *game = Game::getSingleton();
|
||||
vector<int> currTechs = player->getTechnologies();
|
||||
|
||||
sol::table projTable = generateView()[GameObject::getGameObjTableName()][id + 1];
|
||||
projClass = (ProjectileClass)projTable["projectileClass"];
|
||||
|
||||
rayLength = projTable["rayLength"];
|
||||
directHitDamage = projTable["directHitDamage"]; directHitDamage += game->calcAbilFromTech(Ability::Type::DIRECT_HIT_DAMAGE, currTechs, (int)GameObject::type, id);
|
||||
|
||||
string explKey = "explosion";
|
||||
explosionDamage = projTable[explKey]["damage"]; explosionDamage += game->calcAbilFromTech(Ability::Type::EXPLOSION_DAMAGE, currTechs, (int)GameObject::type, id);
|
||||
explosionRadius = projTable[explKey]["radius"]; explosionRadius += game->calcAbilFromTech(Ability::Type::EXPLOSION_RADIUS, currTechs, (int)GameObject::type, id);
|
||||
speed = projTable["speed"];
|
||||
rotAngle = projTable["rotAngle"].get_or(0.0);
|
||||
}
|
||||
|
||||
void Projectile::update() {
|
||||
GameObject::update();
|
||||
placeAt(pos + speed * dirVec);
|
||||
}
|
||||
|
||||
void Projectile::detonate(Unit *target){
|
||||
if(target) target->getDestructable()->takeDamage(directHitDamage);
|
||||
|
||||
sol::table tbl = generateView()[getGameObjTableName()][id + 1]["explosion"];
|
||||
FxManager::Fx *fx = FxManager::getSingleton()->initFx(tbl["fx"], model, false, pos);
|
||||
Environment::explode(fx, (Environment::Detonation)tbl["detonation"], pos, tbl["damage"], tbl["radius"]);
|
||||
|
||||
remove = true;
|
||||
}
|
||||
|
||||
void Projectile::checkUnitCollision(){
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers(true);
|
||||
vector<Unit*> targetUnits;
|
||||
vector<Node*> targetNodes;
|
||||
|
||||
for(Player *pl : players){
|
||||
vector<Unit*> units = pl->getUnits();
|
||||
|
||||
for(Unit *u : units)
|
||||
if(unit && unit != u){
|
||||
targetUnits.push_back(u);
|
||||
targetNodes.push_back(u->getHitbox());
|
||||
}
|
||||
}
|
||||
|
||||
vector<RayCaster::CollisionResult> results = RayCaster::cast(pos, dirVec, targetNodes, rayLength);
|
||||
|
||||
if(!results.empty())
|
||||
for(int i = 0; i < targetNodes.size(); i++)
|
||||
if(targetNodes[i]->getMesh(0) == results[0].mesh)
|
||||
detonate(targetUnits[i]);
|
||||
}
|
||||
|
||||
//TODO fix map boundary checks
|
||||
void Projectile::checkSurfaceCollision(bool useBottomCell){
|
||||
Map *map = Map::getSingleton();
|
||||
vector<Map::Cell> &cells = map->getCells();
|
||||
int cellId = map->getCellId(pos, false);
|
||||
Vector3 mapSize = map->getMapSize();
|
||||
|
||||
if(cellId < 0 || fabs(pos.x) > .5 * mapSize.x || fabs(pos.z) > .5 * mapSize.z){
|
||||
remove = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(useBottomCell && !cells[cellId].underWaterCellIds.empty()){
|
||||
int numUnderwaterCells = cells[cellId].underWaterCellIds.size();
|
||||
cellId = cells[cellId].underWaterCellIds[numUnderwaterCells - 1];
|
||||
}
|
||||
|
||||
if((pos + dirVec * rayLength).y <= cells[cellId].pos.y + .5 * map->getCellSize().y)
|
||||
detonate();
|
||||
}
|
||||
|
||||
void Projectile::debug(){
|
||||
}
|
||||
}
|
||||
Executable → Regular
+582
-582
File diff suppressed because it is too large
Load Diff
Executable → Regular
Executable → Regular
+46
-46
@@ -1,46 +1,46 @@
|
||||
#pragma once
|
||||
#ifndef GAME_MANAGER_H
|
||||
#define GAME_MANAGER_H
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <mapping.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace gameBase{
|
||||
class InputManager;
|
||||
class StateManager;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class GameManager {
|
||||
public:
|
||||
static GameManager* getSingleton();
|
||||
void start(std::string);
|
||||
void update();
|
||||
inline int getWidth(){return width;}
|
||||
inline int getHeight(){return height;}
|
||||
inline std::string getPath(){return path;}
|
||||
inline gameBase::InputManager* getInputManager(){return inputManager;}
|
||||
inline bool isServerSide(){return serverSide;}
|
||||
inline bool isRunning(){return running;}
|
||||
inline void setRunning(bool r){this->running = r;}
|
||||
inline gameBase::StateManager* getStateManager(){return stateManager;}
|
||||
private:
|
||||
GameManager(){}
|
||||
~GameManager(){}
|
||||
void registerMembers();
|
||||
void initLua(std::string);
|
||||
|
||||
gameBase::StateManager *stateManager = nullptr;
|
||||
gameBase::InputManager *inputManager = nullptr;
|
||||
int width, height;
|
||||
std::string path = "";
|
||||
bool serverSide, running = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
#ifndef GAME_MANAGER_H
|
||||
#define GAME_MANAGER_H
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <mapping.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace gameBase{
|
||||
class InputManager;
|
||||
class StateManager;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class GameManager {
|
||||
public:
|
||||
static GameManager* getSingleton();
|
||||
void start(std::string);
|
||||
void update();
|
||||
inline int getWidth(){return width;}
|
||||
inline int getHeight(){return height;}
|
||||
inline std::string getPath(){return path;}
|
||||
inline gameBase::InputManager* getInputManager(){return inputManager;}
|
||||
inline bool isServerSide(){return serverSide;}
|
||||
inline bool isRunning(){return running;}
|
||||
inline void setRunning(bool r){this->running = r;}
|
||||
inline gameBase::StateManager* getStateManager(){return stateManager;}
|
||||
private:
|
||||
GameManager(){}
|
||||
~GameManager(){}
|
||||
void registerMembers();
|
||||
void initLua(std::string);
|
||||
|
||||
gameBase::StateManager *stateManager = nullptr;
|
||||
gameBase::InputManager *inputManager = nullptr;
|
||||
int width, height;
|
||||
std::string path = "";
|
||||
bool serverSide, running = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
Executable → Regular
+128
-128
@@ -1,128 +1,128 @@
|
||||
#ifndef MAP_H
|
||||
#define MAP_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <rayCaster.h>
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
namespace vb01{
|
||||
class Model;
|
||||
class Material;
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace vb01Gui{
|
||||
class Button;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class Player;
|
||||
class Unit;
|
||||
class ResourceDeposit;
|
||||
struct Cell;
|
||||
|
||||
class Map {
|
||||
public:
|
||||
struct Cell;
|
||||
|
||||
struct Edge{
|
||||
Edge(vb01::s64 w, vb01::s64 src, vb01::s64 dest) : weight(w), srcCellId(src), destCellId(dest){}
|
||||
vb01::s64 weight, srcCellId, destCellId;
|
||||
};
|
||||
|
||||
struct Cell{
|
||||
enum Type{LAND, WATER};
|
||||
|
||||
Type type;
|
||||
vb01::Vector3 pos;
|
||||
std::vector<Edge> edges;
|
||||
Unit *blockedBy = nullptr;
|
||||
std::vector<int> underWaterCellIds;
|
||||
|
||||
Cell(){}
|
||||
Cell(vb01::Vector3 p, Type t, std::vector<Edge> e = std::vector<Edge>{}, std::vector<int> uc = std::vector<int>{}): pos(p), type(t), edges(e), underWaterCellIds(uc){}
|
||||
};
|
||||
|
||||
class Minimap{
|
||||
public:
|
||||
static Minimap* getSingleton();
|
||||
~Minimap();
|
||||
void update();
|
||||
void updateImage();
|
||||
void load();
|
||||
void unload();
|
||||
inline vb01::u8* getOldMinimapImage(){return oldImageData;}
|
||||
private:
|
||||
Minimap();
|
||||
vb01::Node* initIcon(vb01::Vector3, std::string);
|
||||
void updateCamFrame(vb01Gui::Button*);
|
||||
|
||||
vb01::u8 *oldImageData = nullptr;
|
||||
vb01::Node *camFrame = nullptr;
|
||||
std::vector<vb01::Node*> depositIcons;
|
||||
vb01::Node* camIcon = nullptr;
|
||||
};
|
||||
|
||||
static Map* getSingleton();
|
||||
~Map(){}
|
||||
static std::vector<Edge> generateAdjacentNodeEdges(int, int, int, int, int);
|
||||
void update();
|
||||
void load(std::string);
|
||||
void create(std::string, vb01::Vector3);
|
||||
void unload();
|
||||
std::vector<vb01::RayCaster::CollisionResult> raycastTerrain(vb01::Vector3, vb01::Vector3, bool);
|
||||
int getCellId(vb01::Vector3, bool = true);
|
||||
bool isPointWithinTerrainObject(vb01::Vector3, int);
|
||||
void loadPlayersGameObjects();
|
||||
int getNumMapSpawnPoints(std::string = "");
|
||||
std::vector<int> getSurroundingCells(vb01::Vector3, int);
|
||||
void blockCells(Unit*);
|
||||
void unblockCells(Unit*);
|
||||
inline Map::Cell getCell(int i){return cells[i];}
|
||||
inline std::string getMapName(){return mapName;}
|
||||
inline vb01::Node* getNodeParent(){return terrainNode;}
|
||||
inline vb01::Vector3 getCellSize(){return CELL_SIZE;}
|
||||
inline int getNumSpawnPoints(){return spawnPoints.size();}
|
||||
inline vb01::Vector3 getSpawnPoint(int i){return spawnPoints[i];}
|
||||
inline void setMapSize(vb01::Vector3 s){this->mapSize = s;}
|
||||
inline vb01::Vector3 getMapSize(){return mapSize;}
|
||||
inline void addSpawnPoint(vb01::Vector3 sp){spawnPoints.push_back(sp);}
|
||||
inline std::vector<Map::Cell>& getCells(){return cells;}
|
||||
inline vb01::Node* getLight(int i){return lights[i];}
|
||||
inline std::vector<vb01::Node*> getLights(){return lights;}
|
||||
inline float getBaseHeight(){return baseHeight;}
|
||||
inline void setBaseHeight(float bh){this->baseHeight = bh;}
|
||||
private:
|
||||
std::string mapTable = "metadata";
|
||||
vb01::Node *terrainNode = nullptr, *cellNode = nullptr;
|
||||
vb01::Material *landCellMat = nullptr, *waterCellMat = nullptr;
|
||||
std::string mapName;
|
||||
vb01::Vector3 CELL_SIZE = vb01::Vector3(7, 7, 7), mapSize;
|
||||
std::vector<vb01::Vector3> spawnPoints;
|
||||
std::vector<Cell> cells;
|
||||
float baseHeight;
|
||||
std::vector<vb01::Node*> lights;
|
||||
|
||||
Map(){}
|
||||
void preprareScene(bool);
|
||||
void loadSpawnPoints();
|
||||
void loadLights();
|
||||
void loadSkybox();
|
||||
void loadCells();
|
||||
void loadPlayerGameObjects(Player*, sol::table);
|
||||
void loadTerrainObject(int);
|
||||
void unloadTerrainObjects();
|
||||
void unloadCells();
|
||||
void unloadLights();
|
||||
void unloadSkybox();
|
||||
void unloadPlayerObjects();
|
||||
void destroyScene();
|
||||
template<typename T> int bsearch(std::vector<T>, T, float);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
#ifndef MAP_H
|
||||
#define MAP_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <rayCaster.h>
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
namespace vb01{
|
||||
class Model;
|
||||
class Material;
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace vb01Gui{
|
||||
class Button;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class Player;
|
||||
class Unit;
|
||||
class ResourceDeposit;
|
||||
struct Cell;
|
||||
|
||||
class Map {
|
||||
public:
|
||||
struct Cell;
|
||||
|
||||
struct Edge{
|
||||
Edge(vb01::s64 w, vb01::s64 src, vb01::s64 dest) : weight(w), srcCellId(src), destCellId(dest){}
|
||||
vb01::s64 weight, srcCellId, destCellId;
|
||||
};
|
||||
|
||||
struct Cell{
|
||||
enum Type{LAND, WATER};
|
||||
|
||||
Type type;
|
||||
vb01::Vector3 pos;
|
||||
std::vector<Edge> edges;
|
||||
Unit *blockedBy = nullptr;
|
||||
std::vector<int> underWaterCellIds;
|
||||
|
||||
Cell(){}
|
||||
Cell(vb01::Vector3 p, Type t, std::vector<Edge> e = std::vector<Edge>{}, std::vector<int> uc = std::vector<int>{}): pos(p), type(t), edges(e), underWaterCellIds(uc){}
|
||||
};
|
||||
|
||||
class Minimap{
|
||||
public:
|
||||
static Minimap* getSingleton();
|
||||
~Minimap();
|
||||
void update();
|
||||
void updateImage();
|
||||
void load();
|
||||
void unload();
|
||||
inline vb01::u8* getOldMinimapImage(){return oldImageData;}
|
||||
private:
|
||||
Minimap();
|
||||
vb01::Node* initIcon(vb01::Vector3, std::string);
|
||||
void updateCamFrame(vb01Gui::Button*);
|
||||
|
||||
vb01::u8 *oldImageData = nullptr;
|
||||
vb01::Node *camFrame = nullptr;
|
||||
std::vector<vb01::Node*> depositIcons;
|
||||
vb01::Node* camIcon = nullptr;
|
||||
};
|
||||
|
||||
static Map* getSingleton();
|
||||
~Map(){}
|
||||
static std::vector<Edge> generateAdjacentNodeEdges(int, int, int, int, int);
|
||||
void update();
|
||||
void load(std::string);
|
||||
void create(std::string, vb01::Vector3);
|
||||
void unload();
|
||||
std::vector<vb01::RayCaster::CollisionResult> raycastTerrain(vb01::Vector3, vb01::Vector3, bool);
|
||||
int getCellId(vb01::Vector3, bool = true);
|
||||
bool isPointWithinTerrainObject(vb01::Vector3, int);
|
||||
void loadPlayersGameObjects();
|
||||
int getNumMapSpawnPoints(std::string = "");
|
||||
std::vector<int> getSurroundingCells(vb01::Vector3, int);
|
||||
void blockCells(Unit*);
|
||||
void unblockCells(Unit*);
|
||||
inline Map::Cell getCell(int i){return cells[i];}
|
||||
inline std::string getMapName(){return mapName;}
|
||||
inline vb01::Node* getNodeParent(){return terrainNode;}
|
||||
inline vb01::Vector3 getCellSize(){return CELL_SIZE;}
|
||||
inline int getNumSpawnPoints(){return spawnPoints.size();}
|
||||
inline vb01::Vector3 getSpawnPoint(int i){return spawnPoints[i];}
|
||||
inline void setMapSize(vb01::Vector3 s){this->mapSize = s;}
|
||||
inline vb01::Vector3 getMapSize(){return mapSize;}
|
||||
inline void addSpawnPoint(vb01::Vector3 sp){spawnPoints.push_back(sp);}
|
||||
inline std::vector<Map::Cell>& getCells(){return cells;}
|
||||
inline vb01::Node* getLight(int i){return lights[i];}
|
||||
inline std::vector<vb01::Node*> getLights(){return lights;}
|
||||
inline float getBaseHeight(){return baseHeight;}
|
||||
inline void setBaseHeight(float bh){this->baseHeight = bh;}
|
||||
private:
|
||||
std::string mapTable = "metadata";
|
||||
vb01::Node *terrainNode = nullptr, *cellNode = nullptr;
|
||||
vb01::Material *landCellMat = nullptr, *waterCellMat = nullptr;
|
||||
std::string mapName;
|
||||
vb01::Vector3 CELL_SIZE = vb01::Vector3(7, 7, 7), mapSize;
|
||||
std::vector<vb01::Vector3> spawnPoints;
|
||||
std::vector<Cell> cells;
|
||||
float baseHeight;
|
||||
std::vector<vb01::Node*> lights;
|
||||
|
||||
Map(){}
|
||||
void preprareScene(bool);
|
||||
void loadSpawnPoints();
|
||||
void loadLights();
|
||||
void loadSkybox();
|
||||
void loadCells();
|
||||
void loadPlayerGameObjects(Player*, sol::table);
|
||||
void loadTerrainObject(int);
|
||||
void unloadTerrainObjects();
|
||||
void unloadCells();
|
||||
void unloadLights();
|
||||
void unloadSkybox();
|
||||
void unloadPlayerObjects();
|
||||
void destroyScene();
|
||||
template<typename T> int bsearch(std::vector<T>, T, float);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
Executable → Regular
+118
-118
@@ -1,118 +1,118 @@
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "gameManager.h"
|
||||
#include "trader.h"
|
||||
#include "unit.h"
|
||||
|
||||
namespace battleship{
|
||||
class ResourceDeposit;
|
||||
class Projectile;
|
||||
class Unit;
|
||||
struct TradeOffer;
|
||||
|
||||
const int NUM_RESOURCES = 3;
|
||||
enum class ResourceType{REFINEDS, WEALTH, RESEARCH};
|
||||
|
||||
class Player {
|
||||
public:
|
||||
Player(int, int, int, vb01::Vector3, bool = true, int = -1, std::string = "");
|
||||
~Player();
|
||||
void update();
|
||||
void haltUnits();
|
||||
void issueOrder(Order::TYPE, vb01::Vector3, std::vector<Order::Target>, bool);
|
||||
void removeUnit(Unit*);
|
||||
void removeUnit(int);
|
||||
void removeResourceDeposit(int);
|
||||
void removeProjectile(int);
|
||||
void removeProjectile(Projectile*);
|
||||
bool isThisPlayersUnit(GameObject*);
|
||||
void selectUnits(std::vector<Unit*>);
|
||||
std::vector<Unit*> getUnitsById(int, int = -1);
|
||||
std::vector<Unit*> getUnitsByClass(UnitClass, int = -1);
|
||||
void addTechnology(int id){technologies.push_back(id);}
|
||||
void updateTradedResource(Player*, ResourceType, int, bool, bool);
|
||||
void addTradeOffer(Player*, TradeOffer*);
|
||||
std::vector<TradeOffer*> getTradeOffers(Player*);
|
||||
void deselectUnit(Unit*);
|
||||
std::vector<GameObject*> getDestructables();
|
||||
void updateGameStats(Unit*);
|
||||
std::vector<Unit*> getFriendlyUnits(bool = true);
|
||||
std::vector<Unit*> getHostileUnits();
|
||||
bool isObjectVisible(GameObject*, std::vector<Unit*>);
|
||||
int getCpuPlayerId();
|
||||
inline int getResource(ResourceType rt){return resources[(int)rt];}
|
||||
inline void updateResource(ResourceType rt, int amount, bool add){resources[(int)rt] = (add ? resources[(int)rt] + amount : amount);}
|
||||
inline Trader* getTrader(){return trader;}
|
||||
inline void deselectUnits(){selectedUnits.clear();}
|
||||
inline Unit* getSelectedUnit(int id){return selectedUnits[id];}
|
||||
inline std::vector<Unit*> getSelectedUnits(){return selectedUnits;}
|
||||
inline void deselectUnit(int i){selectedUnits.erase(selectedUnits.begin() + i);}
|
||||
inline int getNumSelectedUnits(){return getSelectedUnits().size();}
|
||||
inline void selectUnit(Unit *u){selectUnits(std::vector<Unit*>{u});}
|
||||
inline void addUnit(Unit *u){units.push_back(u);}
|
||||
inline std::vector<ResourceDeposit*>& getResourceDeposits(){return resourceDeposits;}
|
||||
inline void addResourceDeposit(ResourceDeposit *rd){resourceDeposits.push_back(rd);}
|
||||
inline int getNumResourceDeposits(){return resourceDeposits.size();}
|
||||
inline void addProjectile(Projectile *proj){projectiles.push_back(proj);}
|
||||
inline int getNumProjectiles(){return projectiles.size();}
|
||||
inline std::vector<Projectile*>& getProjectiles(){return projectiles;}
|
||||
inline Unit* getUnit(int i){return units[i];}
|
||||
inline std::vector<Unit*>& getUnits(){return units;}
|
||||
inline void setTeam(int t){team = t;}
|
||||
inline int getTeam(){return team;}
|
||||
inline int getNumUnits(){return units.size();}
|
||||
inline int getFaction(){return faction;}
|
||||
inline int getSpawnPointId(){return spawnPointId;}
|
||||
inline bool isCpuPlayer(){return cpuPlayer;}
|
||||
inline int getNumVehiclesBuilt(){return vehiclesBuilt;}
|
||||
inline int getNumVehiclesDestroyed(){return vehiclesDestroyed;}
|
||||
inline int getNumVehiclesLost(){return vehiclesLost;}
|
||||
inline int getNumStructuresBuilt(){return structuresBuilt;}
|
||||
inline int getNumStructuresDestroyed(){return structuresDestroyed;}
|
||||
inline int getNumStructuresLost(){return structuresLost;}
|
||||
inline void incVehiclesBuilt(){vehiclesBuilt++;}
|
||||
inline void incVehiclesDestroyed(){vehiclesDestroyed++;}
|
||||
inline void incVehiclesLost(){vehiclesLost++;}
|
||||
inline void incStructuresBuilt(){structuresBuilt++;}
|
||||
inline void incStructuresDestroyed(){structuresDestroyed++;}
|
||||
inline void incStructuresLost(){structuresLost++;}
|
||||
inline vb01::Vector3 getColor(){return color;}
|
||||
inline std::string getName(){return name;}
|
||||
inline vb01::Material* getColorMaterial(){return colorMaterial;}
|
||||
inline std::vector<int> getTechnologies(){return technologies;}
|
||||
private:
|
||||
struct TradedResource{
|
||||
ResourceType type;
|
||||
int taken = 0, given = 0, received = 0, hadTaken = 0;
|
||||
|
||||
TradedResource(ResourceType t) : type(t){}
|
||||
};
|
||||
|
||||
bool cpuPlayer = false;
|
||||
std::vector<int> technologies;
|
||||
int luaPlayerId;
|
||||
int resources[3]{0, 0, 0};
|
||||
int faction, difficulty, team;
|
||||
int vehiclesBuilt = 0, vehiclesDestroyed = 0, vehiclesLost = 0;
|
||||
int structuresBuilt = 0, structuresDestroyed = 0, structuresLost = 0;
|
||||
int spawnPointId = -1;
|
||||
Trader *trader = nullptr;
|
||||
std::string name;
|
||||
std::vector<Unit*> units, selectedUnits;
|
||||
std::vector<Projectile*> projectiles;
|
||||
std::vector<ResourceDeposit*> resourceDeposits;
|
||||
vb01::Vector3 color;
|
||||
vb01::Material *colorMaterial = nullptr;
|
||||
std::vector<std::pair<Player*, std::vector<TradeOffer*>>> tradeOffers;
|
||||
std::vector<std::pair<Player*, std::vector<TradedResource>>> tradedResources;
|
||||
|
||||
int getOrderLineId(Order::TYPE, vb01::Vector3, vb01::Vector3);
|
||||
void initTradingVecs();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "gameManager.h"
|
||||
#include "trader.h"
|
||||
#include "unit.h"
|
||||
|
||||
namespace battleship{
|
||||
class ResourceDeposit;
|
||||
class Projectile;
|
||||
class Unit;
|
||||
struct TradeOffer;
|
||||
|
||||
const int NUM_RESOURCES = 3;
|
||||
enum class ResourceType{REFINEDS, WEALTH, RESEARCH};
|
||||
|
||||
class Player {
|
||||
public:
|
||||
Player(int, int, int, vb01::Vector3, bool = true, int = -1, std::string = "");
|
||||
~Player();
|
||||
void update();
|
||||
void haltUnits();
|
||||
void issueOrder(Order::TYPE, vb01::Vector3, std::vector<Order::Target>, bool);
|
||||
void removeUnit(Unit*);
|
||||
void removeUnit(int);
|
||||
void removeResourceDeposit(int);
|
||||
void removeProjectile(int);
|
||||
void removeProjectile(Projectile*);
|
||||
bool isThisPlayersUnit(GameObject*);
|
||||
void selectUnits(std::vector<Unit*>);
|
||||
std::vector<Unit*> getUnitsById(int, int = -1);
|
||||
std::vector<Unit*> getUnitsByClass(UnitClass, int = -1);
|
||||
void addTechnology(int id){technologies.push_back(id);}
|
||||
void updateTradedResource(Player*, ResourceType, int, bool, bool);
|
||||
void addTradeOffer(Player*, TradeOffer*);
|
||||
std::vector<TradeOffer*> getTradeOffers(Player*);
|
||||
void deselectUnit(Unit*);
|
||||
std::vector<GameObject*> getDestructables();
|
||||
void updateGameStats(Unit*);
|
||||
std::vector<Unit*> getFriendlyUnits(bool = true);
|
||||
std::vector<Unit*> getHostileUnits();
|
||||
bool isObjectVisible(GameObject*, std::vector<Unit*>);
|
||||
int getCpuPlayerId();
|
||||
inline int getResource(ResourceType rt){return resources[(int)rt];}
|
||||
inline void updateResource(ResourceType rt, int amount, bool add){resources[(int)rt] = (add ? resources[(int)rt] + amount : amount);}
|
||||
inline Trader* getTrader(){return trader;}
|
||||
inline void deselectUnits(){selectedUnits.clear();}
|
||||
inline Unit* getSelectedUnit(int id){return selectedUnits[id];}
|
||||
inline std::vector<Unit*> getSelectedUnits(){return selectedUnits;}
|
||||
inline void deselectUnit(int i){selectedUnits.erase(selectedUnits.begin() + i);}
|
||||
inline int getNumSelectedUnits(){return getSelectedUnits().size();}
|
||||
inline void selectUnit(Unit *u){selectUnits(std::vector<Unit*>{u});}
|
||||
inline void addUnit(Unit *u){units.push_back(u);}
|
||||
inline std::vector<ResourceDeposit*>& getResourceDeposits(){return resourceDeposits;}
|
||||
inline void addResourceDeposit(ResourceDeposit *rd){resourceDeposits.push_back(rd);}
|
||||
inline int getNumResourceDeposits(){return resourceDeposits.size();}
|
||||
inline void addProjectile(Projectile *proj){projectiles.push_back(proj);}
|
||||
inline int getNumProjectiles(){return projectiles.size();}
|
||||
inline std::vector<Projectile*>& getProjectiles(){return projectiles;}
|
||||
inline Unit* getUnit(int i){return units[i];}
|
||||
inline std::vector<Unit*>& getUnits(){return units;}
|
||||
inline void setTeam(int t){team = t;}
|
||||
inline int getTeam(){return team;}
|
||||
inline int getNumUnits(){return units.size();}
|
||||
inline int getFaction(){return faction;}
|
||||
inline int getSpawnPointId(){return spawnPointId;}
|
||||
inline bool isCpuPlayer(){return cpuPlayer;}
|
||||
inline int getNumVehiclesBuilt(){return vehiclesBuilt;}
|
||||
inline int getNumVehiclesDestroyed(){return vehiclesDestroyed;}
|
||||
inline int getNumVehiclesLost(){return vehiclesLost;}
|
||||
inline int getNumStructuresBuilt(){return structuresBuilt;}
|
||||
inline int getNumStructuresDestroyed(){return structuresDestroyed;}
|
||||
inline int getNumStructuresLost(){return structuresLost;}
|
||||
inline void incVehiclesBuilt(){vehiclesBuilt++;}
|
||||
inline void incVehiclesDestroyed(){vehiclesDestroyed++;}
|
||||
inline void incVehiclesLost(){vehiclesLost++;}
|
||||
inline void incStructuresBuilt(){structuresBuilt++;}
|
||||
inline void incStructuresDestroyed(){structuresDestroyed++;}
|
||||
inline void incStructuresLost(){structuresLost++;}
|
||||
inline vb01::Vector3 getColor(){return color;}
|
||||
inline std::string getName(){return name;}
|
||||
inline vb01::Material* getColorMaterial(){return colorMaterial;}
|
||||
inline std::vector<int> getTechnologies(){return technologies;}
|
||||
private:
|
||||
struct TradedResource{
|
||||
ResourceType type;
|
||||
int taken = 0, given = 0, received = 0, hadTaken = 0;
|
||||
|
||||
TradedResource(ResourceType t) : type(t){}
|
||||
};
|
||||
|
||||
bool cpuPlayer = false;
|
||||
std::vector<int> technologies;
|
||||
int luaPlayerId;
|
||||
int resources[3]{0, 0, 0};
|
||||
int faction, difficulty, team;
|
||||
int vehiclesBuilt = 0, vehiclesDestroyed = 0, vehiclesLost = 0;
|
||||
int structuresBuilt = 0, structuresDestroyed = 0, structuresLost = 0;
|
||||
int spawnPointId = -1;
|
||||
Trader *trader = nullptr;
|
||||
std::string name;
|
||||
std::vector<Unit*> units, selectedUnits;
|
||||
std::vector<Projectile*> projectiles;
|
||||
std::vector<ResourceDeposit*> resourceDeposits;
|
||||
vb01::Vector3 color;
|
||||
vb01::Material *colorMaterial = nullptr;
|
||||
std::vector<std::pair<Player*, std::vector<TradeOffer*>>> tradeOffers;
|
||||
std::vector<std::pair<Player*, std::vector<TradedResource>>> tradedResources;
|
||||
|
||||
int getOrderLineId(Order::TYPE, vb01::Vector3, vb01::Vector3);
|
||||
void initTradingVecs();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Executable → Regular
+44
-44
@@ -1,44 +1,44 @@
|
||||
#ifndef PROJECTILE_H
|
||||
#define PROJECTILE_H
|
||||
|
||||
#include "gameObject.h"
|
||||
#include "fxManager.h"
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace battleship {
|
||||
class Unit;
|
||||
|
||||
enum class ProjectileClass{SHELL, CRUISE_MISSILE, MISSILE, TORPEDO, DEPTH_CHARGE};
|
||||
|
||||
class Projectile : public GameObject{
|
||||
public:
|
||||
Projectile(Unit*, int, vb01::Vector3, vb01::Quaternion);
|
||||
virtual ~Projectile();
|
||||
virtual void update();
|
||||
virtual void debug();
|
||||
inline ProjectileClass getProjectileClass(){return projClass;}
|
||||
private:
|
||||
void initProperties();
|
||||
void detonate(Unit *u = nullptr);
|
||||
protected:
|
||||
virtual void reinit();
|
||||
virtual void checkUnitCollision();
|
||||
virtual void checkSurfaceCollision(bool);
|
||||
|
||||
vb01::Vector3 initPos;
|
||||
ProjectileClass projClass;
|
||||
Unit *unit = nullptr;
|
||||
FxManager::Fx *explosionFx = nullptr;
|
||||
float speed, rayLength, explosionRadius, rotAngle;
|
||||
int directHitDamage, explosionDamage;
|
||||
sf::SoundBuffer *shotSfxBuffer, *explosionSfxBuffer;
|
||||
sf::Sound *shotSfx = nullptr, *explosionSfx = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef PROJECTILE_H
|
||||
#define PROJECTILE_H
|
||||
|
||||
#include "gameObject.h"
|
||||
#include "fxManager.h"
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace battleship {
|
||||
class Unit;
|
||||
|
||||
enum class ProjectileClass{SHELL, CRUISE_MISSILE, MISSILE, TORPEDO, DEPTH_CHARGE};
|
||||
|
||||
class Projectile : public GameObject{
|
||||
public:
|
||||
Projectile(Unit*, int, vb01::Vector3, vb01::Quaternion);
|
||||
virtual ~Projectile();
|
||||
virtual void update();
|
||||
virtual void debug();
|
||||
inline ProjectileClass getProjectileClass(){return projClass;}
|
||||
private:
|
||||
void initProperties();
|
||||
void detonate(Unit *u = nullptr);
|
||||
protected:
|
||||
virtual void reinit();
|
||||
virtual void checkUnitCollision();
|
||||
virtual void checkSurfaceCollision(bool);
|
||||
|
||||
vb01::Vector3 initPos;
|
||||
ProjectileClass projClass;
|
||||
Unit *unit = nullptr;
|
||||
FxManager::Fx *explosionFx = nullptr;
|
||||
float speed, rayLength, explosionRadius, rotAngle;
|
||||
int directHitDamage, explosionDamage;
|
||||
sf::SoundBuffer *shotSfxBuffer, *explosionSfxBuffer;
|
||||
sf::Sound *shotSfx = nullptr, *explosionSfx = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Executable → Regular
+195
-195
@@ -1,195 +1,195 @@
|
||||
#ifndef UNIT_H
|
||||
#define UNIT_H
|
||||
|
||||
#include <vector>
|
||||
#include <util.h>
|
||||
#include <quaternion.h>
|
||||
#include <lineRenderer.h>
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
#include "gameObject.h"
|
||||
#include "buildableUnit.h"
|
||||
#include "fxManager.h"
|
||||
|
||||
namespace sf{
|
||||
class SoundBuffer;
|
||||
class Sound;
|
||||
}
|
||||
|
||||
namespace vb01{
|
||||
class Mesh;
|
||||
class Quad;
|
||||
class Node;
|
||||
class Light;
|
||||
class Camera;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class Player;
|
||||
class Weapon;
|
||||
class GameObject;
|
||||
class Vehicle;
|
||||
class Projectile;
|
||||
|
||||
struct Order {
|
||||
enum class TYPE {ATTACK, BUILD, MOVE, GARRISON, EJECT, PATROL, LAUNCH, SUPPLY, LOAD, UNLOAD, HACK};
|
||||
struct Target{
|
||||
GameObject *unit = nullptr;
|
||||
vb01::Vector3 pos;
|
||||
|
||||
Target(){}
|
||||
Target(GameObject *u, vb01::Vector3 p = vb01::Vector3::VEC_ZERO) : unit(u), pos(p){}
|
||||
};
|
||||
|
||||
TYPE type;
|
||||
int lineId = -1;
|
||||
bool playerAssigned = true;
|
||||
vb01::Vector3 direction;
|
||||
std::vector<Target> targets;
|
||||
|
||||
Order(){}
|
||||
Order(TYPE t, std::vector<Target> targ, vb01::Vector3 dir = vb01::Vector3::VEC_ZERO, int lid = -1, bool pa = true) :
|
||||
type(t),
|
||||
playerAssigned(pa),
|
||||
lineId(lid),
|
||||
targets(targ),
|
||||
direction(dir){}
|
||||
};
|
||||
|
||||
enum class MoveDir {LEFT, UP, FORW};
|
||||
enum class Corner {FRONT_LEFT, FRONT_RIGHT, REAR_LEFT, REAR_RIGHT};
|
||||
enum class UnitType {UNDERWATER, SEA_LEVEL, HOVER, LAND, AIR, NONE = -1};
|
||||
enum class UnitClass {
|
||||
MECH,
|
||||
TANK,
|
||||
ARTILLERY,
|
||||
ROBO_ENGINEER,
|
||||
CYBORG_ENGINEER,
|
||||
TRANSPORT,
|
||||
RESOURCE_ROVER,
|
||||
CRUISER,
|
||||
ANTI_SUB_CRUISER,
|
||||
CARRIER,
|
||||
SUBMARINE,
|
||||
MISSILE_SUBMARINE,
|
||||
ICEBREAKER,
|
||||
FREEZER,
|
||||
EMP_BOAT,
|
||||
LAND_FACTORY,
|
||||
NAVAL_FACTORY,
|
||||
TRADE_CENTER,
|
||||
LAB,
|
||||
POINT_DEFENSE,
|
||||
EXTRACTOR,
|
||||
REFINERY,
|
||||
ICE_SHEET
|
||||
};
|
||||
|
||||
class Unit : public GameObject{
|
||||
public:
|
||||
struct GarrisonSlot{
|
||||
Vehicle *vehicle = nullptr;
|
||||
int category;
|
||||
vb01::Node *background, *foreground;
|
||||
vb01::Vector2 offset;
|
||||
|
||||
GarrisonSlot(vb01::Node *bg, vb01::Node *fg, vb01::Vector2 off, int cat, Vehicle *v = nullptr) : background(bg), foreground(fg), offset(off), category(cat), vehicle(v){}
|
||||
};
|
||||
|
||||
enum class State {CHASE, STAND_GROUND, HOLD_FIRE};
|
||||
enum class Condition{ABLE, FROZEN, EM_JAMMED};
|
||||
|
||||
Unit(Player*, int, vb01::Vector3, vb01::Quaternion, State = State::STAND_GROUND);
|
||||
virtual ~Unit();
|
||||
virtual void update();
|
||||
virtual void halt();
|
||||
void updateGarrison(Vehicle*, bool);
|
||||
virtual void select();
|
||||
void setOrder(Order);
|
||||
std::vector<Projectile*> getProjectiles();
|
||||
virtual void receiveOrder(Order, bool);
|
||||
bool canGarrison(Vehicle*);
|
||||
void initLosLight();
|
||||
void destroyLosLight();
|
||||
int getNumFreeGarrisonSlots();
|
||||
inline void setState(State s){state = s;}
|
||||
inline State getState(){return state;}
|
||||
inline int getNumGarrisonSlots(){return garrisonSlots.size();}
|
||||
inline bool isGarrisonEmpty(){return getNumFreeGarrisonSlots() == getNumGarrisonSlots();}
|
||||
inline const std::vector<GarrisonSlot>& getGarrisonSlots(){return garrisonSlots;}
|
||||
inline float getLineOfSight() {return lineOfSight;}
|
||||
inline UnitType getType() {return type;}
|
||||
inline UnitClass getUnitClass() {return unitClass;}
|
||||
inline int getPlayerId() {return playerId;}
|
||||
inline bool isVehicle(){return vehicle;}
|
||||
inline bool isTargetToTheRight(vb01::Vector3 dir, vb01::Vector3 lv){return lv.getAngleBetween(dir) > vb01::PI / 2;}
|
||||
inline Order getOrder(int i){return orders[i];}
|
||||
inline int getNumOrders(){return orders.size();}
|
||||
inline std::string getGuiScreen(){return guiScreen;}
|
||||
inline std::vector<BuildableUnit> getBuildableUnits(){return buildableUnits;}
|
||||
inline int getNumBuildableUnits(){return buildableUnits.size();}
|
||||
inline BuildableUnit getBuildableUnit(int i){return buildableUnits[i];}
|
||||
inline vb01::Node* getLosLightNode(){return losLightNode;}
|
||||
inline Condition getCondition(){return condition;}
|
||||
inline void setCondition(Condition cond){
|
||||
this->condition = cond;
|
||||
|
||||
if(cond == Condition::EM_JAMMED) lastJamTime = vb01::getTime();
|
||||
}
|
||||
private:
|
||||
void renderOrderLine(bool);
|
||||
void initWeapons();
|
||||
void destroyWeapons();
|
||||
bool validateOrder(Order);
|
||||
inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;}
|
||||
|
||||
const int orderVecDispLength = 2000;
|
||||
sf::SoundBuffer *selectionSfxBuffer;
|
||||
sf::Sound *selectionSfx = nullptr;
|
||||
vb01::Node *losLightNode = nullptr;
|
||||
bool vehicle, currOrderStarted = false, alignToSurface = false;
|
||||
Condition condition = Condition::ABLE;
|
||||
protected:
|
||||
UnitType type;
|
||||
UnitClass unitClass;
|
||||
std::vector<Order> orders;
|
||||
std::string guiScreen = "";
|
||||
int playerId, restartTime, lenHpBar = 200;
|
||||
vb01::s64 orderLineDispTime = 0, lastFireTime = 0, lastJamTime = 0;
|
||||
float lineOfSight;
|
||||
std::vector<Weapon*> weapons;
|
||||
std::vector<GarrisonSlot> garrisonSlots;
|
||||
std::vector<BuildableUnit> buildableUnits;
|
||||
State state = State::STAND_GROUND;
|
||||
vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr;
|
||||
|
||||
void placeAt(vb01::Vector3);
|
||||
std::vector<Player*> getSelectingPlayers();
|
||||
void removeOrder(int);
|
||||
virtual void startCurrentOrder(){currOrderStarted = true;}
|
||||
virtual bool validateLaunchOrder(){return !getWeaponsByOrder(Order::TYPE::LAUNCH).empty();}
|
||||
virtual bool validateGarrisonOrder(Order){return false;}
|
||||
virtual void autoAttackTargets();
|
||||
virtual void reinit();
|
||||
virtual void initProperties();
|
||||
virtual void destroySound();
|
||||
virtual void initSound();
|
||||
virtual void executeOrders();
|
||||
virtual void eject(Order);
|
||||
virtual void attack(Order);
|
||||
virtual void garrison(Order){}
|
||||
virtual void build(Order){}
|
||||
virtual void move(Order){}
|
||||
virtual void patrol(Order){}
|
||||
virtual void launch(Order);
|
||||
virtual void handleResources(Order){}
|
||||
virtual void hack(Order){}
|
||||
virtual void freeze(Order){}
|
||||
float calculateRotation(vb01::Vector3, float, float);
|
||||
std::vector<Weapon*> getWeaponsByOrder(Order::TYPE);
|
||||
std::vector<Weapon*> getWeaponsByType(int);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef UNIT_H
|
||||
#define UNIT_H
|
||||
|
||||
#include <vector>
|
||||
#include <util.h>
|
||||
#include <quaternion.h>
|
||||
#include <lineRenderer.h>
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
#include "gameObject.h"
|
||||
#include "buildableUnit.h"
|
||||
#include "fxManager.h"
|
||||
|
||||
namespace sf{
|
||||
class SoundBuffer;
|
||||
class Sound;
|
||||
}
|
||||
|
||||
namespace vb01{
|
||||
class Mesh;
|
||||
class Quad;
|
||||
class Node;
|
||||
class Light;
|
||||
class Camera;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class Player;
|
||||
class Weapon;
|
||||
class GameObject;
|
||||
class Vehicle;
|
||||
class Projectile;
|
||||
|
||||
struct Order {
|
||||
enum class TYPE {ATTACK, BUILD, MOVE, GARRISON, EJECT, PATROL, LAUNCH, SUPPLY, LOAD, UNLOAD, HACK};
|
||||
struct Target{
|
||||
GameObject *unit = nullptr;
|
||||
vb01::Vector3 pos;
|
||||
|
||||
Target(){}
|
||||
Target(GameObject *u, vb01::Vector3 p = vb01::Vector3::VEC_ZERO) : unit(u), pos(p){}
|
||||
};
|
||||
|
||||
TYPE type;
|
||||
int lineId = -1;
|
||||
bool playerAssigned = true;
|
||||
vb01::Vector3 direction;
|
||||
std::vector<Target> targets;
|
||||
|
||||
Order(){}
|
||||
Order(TYPE t, std::vector<Target> targ, vb01::Vector3 dir = vb01::Vector3::VEC_ZERO, int lid = -1, bool pa = true) :
|
||||
type(t),
|
||||
playerAssigned(pa),
|
||||
lineId(lid),
|
||||
targets(targ),
|
||||
direction(dir){}
|
||||
};
|
||||
|
||||
enum class MoveDir {LEFT, UP, FORW};
|
||||
enum class Corner {FRONT_LEFT, FRONT_RIGHT, REAR_LEFT, REAR_RIGHT};
|
||||
enum class UnitType {UNDERWATER, SEA_LEVEL, HOVER, LAND, AIR, NONE = -1};
|
||||
enum class UnitClass {
|
||||
MECH,
|
||||
TANK,
|
||||
ARTILLERY,
|
||||
ROBO_ENGINEER,
|
||||
CYBORG_ENGINEER,
|
||||
TRANSPORT,
|
||||
RESOURCE_ROVER,
|
||||
CRUISER,
|
||||
ANTI_SUB_CRUISER,
|
||||
CARRIER,
|
||||
SUBMARINE,
|
||||
MISSILE_SUBMARINE,
|
||||
ICEBREAKER,
|
||||
FREEZER,
|
||||
EMP_BOAT,
|
||||
LAND_FACTORY,
|
||||
NAVAL_FACTORY,
|
||||
TRADE_CENTER,
|
||||
LAB,
|
||||
POINT_DEFENSE,
|
||||
EXTRACTOR,
|
||||
REFINERY,
|
||||
ICE_SHEET
|
||||
};
|
||||
|
||||
class Unit : public GameObject{
|
||||
public:
|
||||
struct GarrisonSlot{
|
||||
Vehicle *vehicle = nullptr;
|
||||
int category;
|
||||
vb01::Node *background, *foreground;
|
||||
vb01::Vector2 offset;
|
||||
|
||||
GarrisonSlot(vb01::Node *bg, vb01::Node *fg, vb01::Vector2 off, int cat, Vehicle *v = nullptr) : background(bg), foreground(fg), offset(off), category(cat), vehicle(v){}
|
||||
};
|
||||
|
||||
enum class State {CHASE, STAND_GROUND, HOLD_FIRE};
|
||||
enum class Condition{ABLE, FROZEN, EM_JAMMED};
|
||||
|
||||
Unit(Player*, int, vb01::Vector3, vb01::Quaternion, State = State::STAND_GROUND);
|
||||
virtual ~Unit();
|
||||
virtual void update();
|
||||
virtual void halt();
|
||||
void updateGarrison(Vehicle*, bool);
|
||||
virtual void select();
|
||||
void setOrder(Order);
|
||||
std::vector<Projectile*> getProjectiles();
|
||||
virtual void receiveOrder(Order, bool);
|
||||
bool canGarrison(Vehicle*);
|
||||
void initLosLight();
|
||||
void destroyLosLight();
|
||||
int getNumFreeGarrisonSlots();
|
||||
inline void setState(State s){state = s;}
|
||||
inline State getState(){return state;}
|
||||
inline int getNumGarrisonSlots(){return garrisonSlots.size();}
|
||||
inline bool isGarrisonEmpty(){return getNumFreeGarrisonSlots() == getNumGarrisonSlots();}
|
||||
inline const std::vector<GarrisonSlot>& getGarrisonSlots(){return garrisonSlots;}
|
||||
inline float getLineOfSight() {return lineOfSight;}
|
||||
inline UnitType getType() {return type;}
|
||||
inline UnitClass getUnitClass() {return unitClass;}
|
||||
inline int getPlayerId() {return playerId;}
|
||||
inline bool isVehicle(){return vehicle;}
|
||||
inline bool isTargetToTheRight(vb01::Vector3 dir, vb01::Vector3 lv){return lv.getAngleBetween(dir) > vb01::PI / 2;}
|
||||
inline Order getOrder(int i){return orders[i];}
|
||||
inline int getNumOrders(){return orders.size();}
|
||||
inline std::string getGuiScreen(){return guiScreen;}
|
||||
inline std::vector<BuildableUnit> getBuildableUnits(){return buildableUnits;}
|
||||
inline int getNumBuildableUnits(){return buildableUnits.size();}
|
||||
inline BuildableUnit getBuildableUnit(int i){return buildableUnits[i];}
|
||||
inline vb01::Node* getLosLightNode(){return losLightNode;}
|
||||
inline Condition getCondition(){return condition;}
|
||||
inline void setCondition(Condition cond){
|
||||
this->condition = cond;
|
||||
|
||||
if(cond == Condition::EM_JAMMED) lastJamTime = vb01::getTime();
|
||||
}
|
||||
private:
|
||||
void renderOrderLine(bool);
|
||||
void initWeapons();
|
||||
void destroyWeapons();
|
||||
bool validateOrder(Order);
|
||||
inline bool canDisplayOrderLine(){return vb01::getTime() - orderLineDispTime < orderVecDispLength;}
|
||||
|
||||
const int orderVecDispLength = 2000;
|
||||
sf::SoundBuffer *selectionSfxBuffer;
|
||||
sf::Sound *selectionSfx = nullptr;
|
||||
vb01::Node *losLightNode = nullptr;
|
||||
bool vehicle, currOrderStarted = false, alignToSurface = false;
|
||||
Condition condition = Condition::ABLE;
|
||||
protected:
|
||||
UnitType type;
|
||||
UnitClass unitClass;
|
||||
std::vector<Order> orders;
|
||||
std::string guiScreen = "";
|
||||
int playerId, restartTime, lenHpBar = 200;
|
||||
vb01::s64 orderLineDispTime = 0, lastFireTime = 0, lastJamTime = 0;
|
||||
float lineOfSight;
|
||||
std::vector<Weapon*> weapons;
|
||||
std::vector<GarrisonSlot> garrisonSlots;
|
||||
std::vector<BuildableUnit> buildableUnits;
|
||||
State state = State::STAND_GROUND;
|
||||
vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr;
|
||||
|
||||
void placeAt(vb01::Vector3);
|
||||
std::vector<Player*> getSelectingPlayers();
|
||||
void removeOrder(int);
|
||||
virtual void startCurrentOrder(){currOrderStarted = true;}
|
||||
virtual bool validateLaunchOrder(){return !getWeaponsByOrder(Order::TYPE::LAUNCH).empty();}
|
||||
virtual bool validateGarrisonOrder(Order){return false;}
|
||||
virtual void autoAttackTargets();
|
||||
virtual void reinit();
|
||||
virtual void initProperties();
|
||||
virtual void destroySound();
|
||||
virtual void initSound();
|
||||
virtual void executeOrders();
|
||||
virtual void eject(Order);
|
||||
virtual void attack(Order);
|
||||
virtual void garrison(Order){}
|
||||
virtual void build(Order){}
|
||||
virtual void move(Order){}
|
||||
virtual void patrol(Order){}
|
||||
virtual void launch(Order);
|
||||
virtual void handleResources(Order){}
|
||||
virtual void hack(Order){}
|
||||
virtual void freeze(Order){}
|
||||
float calculateRotation(vb01::Vector3, float, float);
|
||||
std::vector<Weapon*> getWeaponsByOrder(Order::TYPE);
|
||||
std::vector<Weapon*> getWeaponsByType(int);
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Executable → Regular
Executable → Regular
+857
-857
File diff suppressed because it is too large
Load Diff
Executable → Regular
Executable → Regular
+119
-119
@@ -1,119 +1,119 @@
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "defConfigs.h"
|
||||
#include "gameManager.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "guiAppState.h"
|
||||
|
||||
using namespace gameBase;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
GuiAppState::GuiAppState() : AbstractAppState(
|
||||
AppStateType::GUI_STATE,
|
||||
configData::calcSumBinds(AppStateType::GUI_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::GUI_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]){
|
||||
}
|
||||
|
||||
GuiAppState::~GuiAppState() {}
|
||||
|
||||
void GuiAppState::update() {
|
||||
ConcreteGuiManager::getSingleton()->update();
|
||||
}
|
||||
|
||||
void GuiAppState::onAttached() {
|
||||
AbstractAppState::onAttached();
|
||||
}
|
||||
|
||||
void GuiAppState::onDettached() {
|
||||
AbstractAppState::onDettached();
|
||||
}
|
||||
|
||||
void GuiAppState::onAction(int bind, bool isPressed) {
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
|
||||
switch((Bind)bind){
|
||||
case Bind::LEFT_CLICK:
|
||||
leftMousePressed = isPressed;
|
||||
|
||||
if(isPressed)
|
||||
guiManager->updateGui();
|
||||
|
||||
break;
|
||||
case Bind::SCROLLING_UP:{
|
||||
Listbox *l = getOpenListbox();
|
||||
if(l) l->scrollUp();
|
||||
break;
|
||||
}
|
||||
case Bind::SCROLLING_DOWN:{
|
||||
Listbox *l = getOpenListbox();
|
||||
if(l) l->scrollDown();
|
||||
break;
|
||||
}
|
||||
case Bind::DELETE_CHAR:{
|
||||
Textbox *t = getOpenTextbox();
|
||||
if(t)t->setDeleteCharacters(isPressed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::onRawKeyPress(int ch){
|
||||
for(Button *b : ConcreteGuiManager::getSingleton()->getButtons())
|
||||
if(b->getTrigger() == ch){
|
||||
b->onClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::onRawCharPress(u32 codepoint){
|
||||
Textbox *currentTextbox = getOpenTextbox();
|
||||
|
||||
if(currentTextbox)
|
||||
currentTextbox->type(codepoint);
|
||||
}
|
||||
|
||||
void GuiAppState::onRawMousePress(int trigger){
|
||||
}
|
||||
|
||||
Textbox* GuiAppState::getOpenTextbox() {
|
||||
vector<Textbox*> textboxes = ConcreteGuiManager::getSingleton()->getTextboxes();
|
||||
|
||||
for (int i = 0; i < textboxes.size(); i++)
|
||||
if (textboxes[i]->isEnabled())
|
||||
return textboxes[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Listbox* GuiAppState::getOpenListbox() {
|
||||
vector<Listbox*> listboxes = ConcreteGuiManager::getSingleton()->getListboxes();
|
||||
|
||||
for (int i = 0; i < listboxes.size(); i++)
|
||||
if (listboxes[i]->isOpen())
|
||||
return listboxes[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GuiAppState::onAnalog(int bind, float strength) {}
|
||||
|
||||
void GuiAppState::onRawMouseWheelScroll(bool up){
|
||||
Listbox *openListbox = getOpenListbox();
|
||||
|
||||
if(!openListbox) return;
|
||||
|
||||
if(up) openListbox->scrollUp();
|
||||
else openListbox->scrollDown();
|
||||
}
|
||||
}
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "defConfigs.h"
|
||||
#include "gameManager.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "guiAppState.h"
|
||||
|
||||
using namespace gameBase;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
GuiAppState::GuiAppState() : AbstractAppState(
|
||||
AppStateType::GUI_STATE,
|
||||
configData::calcSumBinds(AppStateType::GUI_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::GUI_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]){
|
||||
}
|
||||
|
||||
GuiAppState::~GuiAppState() {}
|
||||
|
||||
void GuiAppState::update() {
|
||||
ConcreteGuiManager::getSingleton()->update();
|
||||
}
|
||||
|
||||
void GuiAppState::onAttached() {
|
||||
AbstractAppState::onAttached();
|
||||
}
|
||||
|
||||
void GuiAppState::onDettached() {
|
||||
AbstractAppState::onDettached();
|
||||
}
|
||||
|
||||
void GuiAppState::onAction(int bind, bool isPressed) {
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
|
||||
switch((Bind)bind){
|
||||
case Bind::LEFT_CLICK:
|
||||
leftMousePressed = isPressed;
|
||||
|
||||
if(isPressed)
|
||||
guiManager->updateGui();
|
||||
|
||||
break;
|
||||
case Bind::SCROLLING_UP:{
|
||||
Listbox *l = getOpenListbox();
|
||||
if(l) l->scrollUp();
|
||||
break;
|
||||
}
|
||||
case Bind::SCROLLING_DOWN:{
|
||||
Listbox *l = getOpenListbox();
|
||||
if(l) l->scrollDown();
|
||||
break;
|
||||
}
|
||||
case Bind::DELETE_CHAR:{
|
||||
Textbox *t = getOpenTextbox();
|
||||
if(t)t->setDeleteCharacters(isPressed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::onRawKeyPress(int ch){
|
||||
for(Button *b : ConcreteGuiManager::getSingleton()->getButtons())
|
||||
if(b->getTrigger() == ch){
|
||||
b->onClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::onRawCharPress(u32 codepoint){
|
||||
Textbox *currentTextbox = getOpenTextbox();
|
||||
|
||||
if(currentTextbox)
|
||||
currentTextbox->type(codepoint);
|
||||
}
|
||||
|
||||
void GuiAppState::onRawMousePress(int trigger){
|
||||
}
|
||||
|
||||
Textbox* GuiAppState::getOpenTextbox() {
|
||||
vector<Textbox*> textboxes = ConcreteGuiManager::getSingleton()->getTextboxes();
|
||||
|
||||
for (int i = 0; i < textboxes.size(); i++)
|
||||
if (textboxes[i]->isEnabled())
|
||||
return textboxes[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Listbox* GuiAppState::getOpenListbox() {
|
||||
vector<Listbox*> listboxes = ConcreteGuiManager::getSingleton()->getListboxes();
|
||||
|
||||
for (int i = 0; i < listboxes.size(); i++)
|
||||
if (listboxes[i]->isOpen())
|
||||
return listboxes[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GuiAppState::onAnalog(int bind, float strength) {}
|
||||
|
||||
void GuiAppState::onRawMouseWheelScroll(bool up){
|
||||
Listbox *openListbox = getOpenListbox();
|
||||
|
||||
if(!openListbox) return;
|
||||
|
||||
if(up) openListbox->scrollUp();
|
||||
else openListbox->scrollDown();
|
||||
}
|
||||
}
|
||||
Executable → Regular
+103
-103
@@ -1,103 +1,103 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <button.h>
|
||||
|
||||
#include <util.h>
|
||||
#include <root.h>
|
||||
#include <camera.h>
|
||||
#include <assetManager.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "defConfigs.h"
|
||||
#include "inGameAppState.h"
|
||||
#include "game.h"
|
||||
#include "console.h"
|
||||
#include "gameObjectFrameController.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "vessel.h"
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
using namespace gameBase;
|
||||
|
||||
InGameAppState::ResumeButton::ResumeButton(Vector3 pos, Vector2 size) : Button(pos, size, "Resume", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {}
|
||||
|
||||
void InGameAppState::ResumeButton::onClick() {
|
||||
Game::getSingleton()->togglePause();
|
||||
}
|
||||
|
||||
InGameAppState::ConsoleButton::ConsoleButton(Vector3 pos, Vector2 size) : Button(pos, size, "Console", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { }
|
||||
|
||||
void InGameAppState::ConsoleButton::onClick() {
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("console.lua");
|
||||
}
|
||||
|
||||
InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::ConsoleCommandEntryButton(Textbox *t, Listbox *l, Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", 257, true) {
|
||||
textbox = t;
|
||||
listbox = l;
|
||||
}
|
||||
|
||||
void InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::onClick() {
|
||||
Console::execute(wstringToString(textbox->getText()));
|
||||
}
|
||||
|
||||
InGameAppState::InGameAppState(std::string mn) : AbstractAppState(
|
||||
AppStateType::IN_GAME_STATE,
|
||||
configData::calcSumBinds(AppStateType::IN_GAME_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::IN_GAME_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]
|
||||
),
|
||||
mapName(mn),
|
||||
playerId(0){}
|
||||
|
||||
void InGameAppState::onAttached() {
|
||||
AbstractAppState::onAttached();
|
||||
|
||||
Map *map = Map::getSingleton();
|
||||
map->load(mapName);
|
||||
map->loadPlayersGameObjects();
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE);
|
||||
cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm());
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
StateManager *stateManager = gm->getStateManager();
|
||||
GuiAppState *guiState = ((GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE));
|
||||
activeState = new ActiveGameState(guiState, playerId);
|
||||
stateManager->attachAppState(activeState);
|
||||
|
||||
Game::getSingleton()->initLuaPlayers();
|
||||
//Map::Minimap::getSingleton()->updateImage();
|
||||
}
|
||||
|
||||
void InGameAppState::onDettached() {
|
||||
StateManager *sm = GameManager::getSingleton()->getStateManager();
|
||||
ActiveGameState *activeState = (ActiveGameState*)sm->getAppStateByType(int(AppStateType::ACTIVE_STATE));
|
||||
sm->dettachAppState(activeState);
|
||||
delete activeState;
|
||||
}
|
||||
|
||||
void InGameAppState::update() {
|
||||
Game::getSingleton()->update();
|
||||
Map::getSingleton()->update();
|
||||
}
|
||||
|
||||
void InGameAppState::onAction(int bind, bool isPressed) {
|
||||
switch((Bind)bind){
|
||||
case Bind::TOGGLE_MAIN_MENU:
|
||||
if(isPressed && !(GameObjectFrameController::getSingleton()->isPlacingOnSurface() || activeState->isForceCursorState()))
|
||||
Game::getSingleton()->togglePause();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::onAnalog(int bind, float str) {}
|
||||
}
|
||||
#include <algorithm>
|
||||
|
||||
#include <button.h>
|
||||
|
||||
#include <util.h>
|
||||
#include <root.h>
|
||||
#include <camera.h>
|
||||
#include <assetManager.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "defConfigs.h"
|
||||
#include "inGameAppState.h"
|
||||
#include "game.h"
|
||||
#include "console.h"
|
||||
#include "gameObjectFrameController.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "vessel.h"
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
using namespace gameBase;
|
||||
|
||||
InGameAppState::ResumeButton::ResumeButton(Vector3 pos, Vector2 size) : Button(pos, size, "Resume", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {}
|
||||
|
||||
void InGameAppState::ResumeButton::onClick() {
|
||||
Game::getSingleton()->togglePause();
|
||||
}
|
||||
|
||||
InGameAppState::ConsoleButton::ConsoleButton(Vector3 pos, Vector2 size) : Button(pos, size, "Console", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { }
|
||||
|
||||
void InGameAppState::ConsoleButton::onClick() {
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("console.lua");
|
||||
}
|
||||
|
||||
InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::ConsoleCommandEntryButton(Textbox *t, Listbox *l, Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", 257, true) {
|
||||
textbox = t;
|
||||
listbox = l;
|
||||
}
|
||||
|
||||
void InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::onClick() {
|
||||
Console::execute(wstringToString(textbox->getText()));
|
||||
}
|
||||
|
||||
InGameAppState::InGameAppState(std::string mn) : AbstractAppState(
|
||||
AppStateType::IN_GAME_STATE,
|
||||
configData::calcSumBinds(AppStateType::IN_GAME_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::IN_GAME_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]
|
||||
),
|
||||
mapName(mn),
|
||||
playerId(0){}
|
||||
|
||||
void InGameAppState::onAttached() {
|
||||
AbstractAppState::onAttached();
|
||||
|
||||
Map *map = Map::getSingleton();
|
||||
map->load(mapName);
|
||||
map->loadPlayersGameObjects();
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE);
|
||||
cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm());
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
StateManager *stateManager = gm->getStateManager();
|
||||
GuiAppState *guiState = ((GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE));
|
||||
activeState = new ActiveGameState(guiState, playerId);
|
||||
stateManager->attachAppState(activeState);
|
||||
|
||||
Game::getSingleton()->initLuaPlayers();
|
||||
//Map::Minimap::getSingleton()->updateImage();
|
||||
}
|
||||
|
||||
void InGameAppState::onDettached() {
|
||||
StateManager *sm = GameManager::getSingleton()->getStateManager();
|
||||
ActiveGameState *activeState = (ActiveGameState*)sm->getAppStateByType(int(AppStateType::ACTIVE_STATE));
|
||||
sm->dettachAppState(activeState);
|
||||
delete activeState;
|
||||
}
|
||||
|
||||
void InGameAppState::update() {
|
||||
Game::getSingleton()->update();
|
||||
Map::getSingleton()->update();
|
||||
}
|
||||
|
||||
void InGameAppState::onAction(int bind, bool isPressed) {
|
||||
switch((Bind)bind){
|
||||
case Bind::TOGGLE_MAIN_MENU:
|
||||
if(isPressed && !(GameObjectFrameController::getSingleton()->isPlacingOnSurface() || activeState->isForceCursorState()))
|
||||
Game::getSingleton()->togglePause();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::onAnalog(int bind, float str) {}
|
||||
}
|
||||
@@ -20,7 +20,7 @@
|
||||
#include <assetManager.h>
|
||||
|
||||
#define STB_IMAGE_WRITE_IMPLEMENTATION
|
||||
#include "external/vb01/external/stb/stb_image_write.h"
|
||||
#include <stb_image_write.h>
|
||||
|
||||
#include <util.h>
|
||||
|
||||
Executable → Regular
+112
-112
@@ -1,112 +1,112 @@
|
||||
#ifndef ACTIVE_GAME_STATE_H
|
||||
#define ACTIVE_GAME_STATE_H
|
||||
|
||||
#include "guiAppState.h"
|
||||
#include "player.h"
|
||||
#include "map.h"
|
||||
#include "unit.h"
|
||||
|
||||
#include <util.h>
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
class Texture;
|
||||
}
|
||||
|
||||
namespace vb01Gui{
|
||||
class Button;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class GameObject;
|
||||
class Unit;
|
||||
class UnitButton;
|
||||
|
||||
class ActiveGameState : public gameBase::AbstractAppState {
|
||||
public:
|
||||
enum CursorState{
|
||||
NORMAL,
|
||||
ATTACK,
|
||||
GARRISON,
|
||||
SUPPLY,
|
||||
LOAD,
|
||||
UNLOAD,
|
||||
HACK
|
||||
};
|
||||
|
||||
ActiveGameState(GuiAppState*, int);
|
||||
~ActiveGameState();
|
||||
void onAttached();
|
||||
void onDettached();
|
||||
void update();
|
||||
void onAction(int, bool);
|
||||
void onAnalog(int, float);
|
||||
void onRawMouseWheelScroll(bool);
|
||||
inline CursorState getCursorState(){return cursorState;}
|
||||
inline void setCursorState(CursorState cs){this->cursorState = cs;}
|
||||
inline void addButton(vb01Gui::Button *b){guiButtons.push_back(b);}
|
||||
inline std::vector<vb01Gui::Button*> getGuiButtons(){return guiButtons;}
|
||||
inline std::vector<vb01::Node*> getGuiRects(){return guiRects;}
|
||||
inline std::vector<vb01::Text*> getGuiTexts(){return guiTexts;}
|
||||
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;}
|
||||
inline void setForceCursorState(bool force){this->forceCursorState = force;}
|
||||
inline bool isForceCursorState(){return forceCursorState;}
|
||||
inline void setTradingScreen(bool ts){this->tradingScreen = ts;}
|
||||
inline bool isTradingScreen(){return tradingScreen;}
|
||||
inline void setOfferScreen(bool os){this->offerScreen = os;}
|
||||
inline bool isOfferScreen(){return offerScreen;}
|
||||
private:
|
||||
bool selectedUnitsAmongst(std::vector<Unit*>);
|
||||
void updateGameObjHoveredOn();
|
||||
void initCursor();
|
||||
void updateCursor();
|
||||
void initDragbox();
|
||||
void removeDragbox();
|
||||
bool isGameObjSelectable(GameObject*, bool);
|
||||
void deselectUnits();
|
||||
void renderUnits();
|
||||
void updateDragBox();
|
||||
void updateStructureFrames();
|
||||
void castRayToTerrain();
|
||||
void issueOrder(Order::TYPE, std::vector<Order::Target>, bool);
|
||||
void enableUnitState(Unit::State);
|
||||
void addUnitGui();
|
||||
inline bool canSelectHoveredOnGameObj(){return gameObjHoveredOn && gameObjHoveredOn->isSelectable() && gameObjHoveredOn->getPlayer() == mainPlayer;}
|
||||
|
||||
CursorState cursorState = CursorState::NORMAL;
|
||||
Player *mainPlayer;
|
||||
GuiAppState *guiState;
|
||||
GameObject *gameObjHoveredOn = nullptr;
|
||||
vb01::Vector2 clickPoint;
|
||||
std::vector<Unit*> unitGroups[9], prevSelectedUnits;
|
||||
std::vector<Order::Target> targets;
|
||||
vb01::Node *dragboxNode = nullptr;
|
||||
std::vector<vb01::Node*> guiRects;
|
||||
std::vector<vb01::Text*> guiTexts;
|
||||
std::vector<vb01Gui::Button*> guiButtons, unitButtons;
|
||||
bool isSelectionBox = false;
|
||||
bool shiftPressed = false;
|
||||
bool controlPressed = false;
|
||||
bool selectMouseClicked = false;
|
||||
bool orderMouseClicked = false;
|
||||
bool buildableStructSelected = false;
|
||||
bool selectingPatrolPoints = false;
|
||||
bool selectingDestOrient = false;
|
||||
bool forceCursorState = false;
|
||||
bool orderPossible = false;
|
||||
bool tradingScreen = false;
|
||||
bool offerScreen = false;
|
||||
int playerId, zooms = 0;
|
||||
const int NUM_MAX_ZOOMS = 10;
|
||||
float depth = 1;
|
||||
vb01::s64 lastSelectMouseClicked = 0, lastOrderMouseClicked = 0;
|
||||
vb01::Node *cursorNode = nullptr;
|
||||
vb01::Texture *pointerTex = nullptr, *attackTex = nullptr, *garrisonTex = nullptr, *noGarrisonTex = nullptr, *supplyTex = nullptr, *noSupplyTex = nullptr, *hackTex = nullptr, *noHackTex = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef ACTIVE_GAME_STATE_H
|
||||
#define ACTIVE_GAME_STATE_H
|
||||
|
||||
#include "guiAppState.h"
|
||||
#include "player.h"
|
||||
#include "map.h"
|
||||
#include "unit.h"
|
||||
|
||||
#include <util.h>
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
class Texture;
|
||||
}
|
||||
|
||||
namespace vb01Gui{
|
||||
class Button;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class GameObject;
|
||||
class Unit;
|
||||
class UnitButton;
|
||||
|
||||
class ActiveGameState : public gameBase::AbstractAppState {
|
||||
public:
|
||||
enum CursorState{
|
||||
NORMAL,
|
||||
ATTACK,
|
||||
GARRISON,
|
||||
SUPPLY,
|
||||
LOAD,
|
||||
UNLOAD,
|
||||
HACK
|
||||
};
|
||||
|
||||
ActiveGameState(GuiAppState*, int);
|
||||
~ActiveGameState();
|
||||
void onAttached();
|
||||
void onDettached();
|
||||
void update();
|
||||
void onAction(int, bool);
|
||||
void onAnalog(int, float);
|
||||
void onRawMouseWheelScroll(bool);
|
||||
inline CursorState getCursorState(){return cursorState;}
|
||||
inline void setCursorState(CursorState cs){this->cursorState = cs;}
|
||||
inline void addButton(vb01Gui::Button *b){guiButtons.push_back(b);}
|
||||
inline std::vector<vb01Gui::Button*> getGuiButtons(){return guiButtons;}
|
||||
inline std::vector<vb01::Node*> getGuiRects(){return guiRects;}
|
||||
inline std::vector<vb01::Text*> getGuiTexts(){return guiTexts;}
|
||||
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;}
|
||||
inline void setForceCursorState(bool force){this->forceCursorState = force;}
|
||||
inline bool isForceCursorState(){return forceCursorState;}
|
||||
inline void setTradingScreen(bool ts){this->tradingScreen = ts;}
|
||||
inline bool isTradingScreen(){return tradingScreen;}
|
||||
inline void setOfferScreen(bool os){this->offerScreen = os;}
|
||||
inline bool isOfferScreen(){return offerScreen;}
|
||||
private:
|
||||
bool selectedUnitsAmongst(std::vector<Unit*>);
|
||||
void updateGameObjHoveredOn();
|
||||
void initCursor();
|
||||
void updateCursor();
|
||||
void initDragbox();
|
||||
void removeDragbox();
|
||||
bool isGameObjSelectable(GameObject*, bool);
|
||||
void deselectUnits();
|
||||
void renderUnits();
|
||||
void updateDragBox();
|
||||
void updateStructureFrames();
|
||||
void castRayToTerrain();
|
||||
void issueOrder(Order::TYPE, std::vector<Order::Target>, bool);
|
||||
void enableUnitState(Unit::State);
|
||||
void addUnitGui();
|
||||
inline bool canSelectHoveredOnGameObj(){return gameObjHoveredOn && gameObjHoveredOn->isSelectable() && gameObjHoveredOn->getPlayer() == mainPlayer;}
|
||||
|
||||
CursorState cursorState = CursorState::NORMAL;
|
||||
Player *mainPlayer;
|
||||
GuiAppState *guiState;
|
||||
GameObject *gameObjHoveredOn = nullptr;
|
||||
vb01::Vector2 clickPoint;
|
||||
std::vector<Unit*> unitGroups[9], prevSelectedUnits;
|
||||
std::vector<Order::Target> targets;
|
||||
vb01::Node *dragboxNode = nullptr;
|
||||
std::vector<vb01::Node*> guiRects;
|
||||
std::vector<vb01::Text*> guiTexts;
|
||||
std::vector<vb01Gui::Button*> guiButtons, unitButtons;
|
||||
bool isSelectionBox = false;
|
||||
bool shiftPressed = false;
|
||||
bool controlPressed = false;
|
||||
bool selectMouseClicked = false;
|
||||
bool orderMouseClicked = false;
|
||||
bool buildableStructSelected = false;
|
||||
bool selectingPatrolPoints = false;
|
||||
bool selectingDestOrient = false;
|
||||
bool forceCursorState = false;
|
||||
bool orderPossible = false;
|
||||
bool tradingScreen = false;
|
||||
bool offerScreen = false;
|
||||
int playerId, zooms = 0;
|
||||
const int NUM_MAX_ZOOMS = 10;
|
||||
float depth = 1;
|
||||
vb01::s64 lastSelectMouseClicked = 0, lastOrderMouseClicked = 0;
|
||||
vb01::Node *cursorNode = nullptr;
|
||||
vb01::Texture *pointerTex = nullptr, *attackTex = nullptr, *garrisonTex = nullptr, *noGarrisonTex = nullptr, *supplyTex = nullptr, *noSupplyTex = nullptr, *hackTex = nullptr, *noHackTex = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user