From c64fea78b4a33a586d488ead601eb577ed87ee78 Mon Sep 17 00:00:00 2001 From: ApfelTeeSaft <91074565+ApfelTeeSaft@users.noreply.github.com> Date: Mon, 27 Apr 2026 20:07:32 +0200 Subject: [PATCH] refactor: restructure monorepo --- .gitmodules | 2 +- CMakeLists.txt | 240 ++- .../AI/Private/cameraController.cpp | 0 .../AI/Private/pathfinder.cpp | 0 .../AI/Public/cameraController.h | 0 pathfinder.h => Source/AI/Public/pathfinder.h | 0 .../Core/Private/defConfigs.cpp | 0 main.cpp => Source/Core/Private/main.cpp | 76 +- util.cpp => Source/Core/Private/util.cpp | 290 +-- binds.h => Source/Core/Public/binds.h | 0 .../Core/Public/defConfigs.h | 428 ++-- util.h => Source/Core/Public/util.h | 72 +- .../Gameplay/Private/cruiseMissile.cpp | 0 .../Gameplay/Private/depthCharge.cpp | 0 .../Gameplay/Private/destructable.cpp | 0 .../Gameplay/Private/engineer.cpp | 0 .../Gameplay/Private/environment.cpp | 0 .../Gameplay/Private/explosion.cpp | 0 .../Gameplay/Private/extractor.cpp | 0 .../Gameplay/Private/factory.cpp | 0 .../Gameplay/Private/freezer.cpp | 0 .../Gameplay/Private/fxManager.cpp | 0 game.cpp => Source/Gameplay/Private/game.cpp | 0 .../Gameplay/Private/gameManager.cpp | 558 +++--- .../Gameplay/Private/gameObject.cpp | 0 .../Gameplay/Private/gameObjectFactory.cpp | 0 .../Gameplay/Private/garrisonable.cpp | 0 .../Gameplay/Private/iceSheet.cpp | 0 map.cpp => Source/Gameplay/Private/map.cpp | 1508 +++++++-------- .../Gameplay/Private/missile.cpp | 0 .../Gameplay/Private/player.cpp | 716 +++---- .../Gameplay/Private/pointDefense.cpp | 0 .../Gameplay/Private/projectile.cpp | 262 +-- .../Gameplay/Private/researchStruct.cpp | 0 .../Gameplay/Private/resourceDeposit.cpp | 0 .../Gameplay/Private/resourceRover.cpp | 0 .../Gameplay/Private/shell.cpp | 0 .../Gameplay/Private/structure.cpp | 0 .../Gameplay/Private/submarine.cpp | 0 .../Gameplay/Private/torpedo.cpp | 0 .../Gameplay/Private/tradeCenter.cpp | 0 .../Gameplay/Private/trader.cpp | 0 unit.cpp => Source/Gameplay/Private/unit.cpp | 1164 +++++------ .../Gameplay/Private/vehicle.cpp | 0 .../Gameplay/Private/vessel.cpp | 0 .../Gameplay/Private/weapon.cpp | 0 ability.h => Source/Gameplay/Public/ability.h | 0 .../Gameplay/Public/buildableUnit.h | 0 .../Gameplay/Public/cruiseMissile.h | 0 .../Gameplay/Public/depthCharge.h | 0 .../Gameplay/Public/destructable.h | 0 .../Gameplay/Public/engineer.h | 0 .../Gameplay/Public/environment.h | 0 .../Gameplay/Public/explosion.h | 0 .../Gameplay/Public/extractor.h | 0 factory.h => Source/Gameplay/Public/factory.h | 0 freezer.h => Source/Gameplay/Public/freezer.h | 0 .../Gameplay/Public/fxManager.h | 0 game.h => Source/Gameplay/Public/game.h | 0 .../Gameplay/Public/gameManager.h | 92 +- .../Gameplay/Public/gameObject.h | 0 .../Gameplay/Public/gameObjectFactory.h | 0 .../Gameplay/Public/garrisonable.h | 0 .../Gameplay/Public/iceSheet.h | 0 map.h => Source/Gameplay/Public/map.h | 256 +-- missile.h => Source/Gameplay/Public/missile.h | 0 player.h => Source/Gameplay/Public/player.h | 236 +-- .../Gameplay/Public/pointDefense.h | 0 .../Gameplay/Public/projectile.h | 88 +- .../Gameplay/Public/researchStruct.h | 0 .../Gameplay/Public/resourceDeposit.h | 0 .../Gameplay/Public/resourceRover.h | 0 shell.h => Source/Gameplay/Public/shell.h | 0 .../Gameplay/Public/structure.h | 0 .../Gameplay/Public/submarine.h | 0 .../Gameplay/Public/technology.h | 0 torpedo.h => Source/Gameplay/Public/torpedo.h | 0 .../Gameplay/Public/tradeCenter.h | 0 .../Gameplay/Public/tradeOffer.h | 0 trader.h => Source/Gameplay/Public/trader.h | 0 unit.h => Source/Gameplay/Public/unit.h | 390 ++-- vehicle.h => Source/Gameplay/Public/vehicle.h | 0 vessel.h => Source/Gameplay/Public/vessel.h | 0 weapon.h => Source/Gameplay/Public/weapon.h | 0 .../Systems/Private/abstractCommand.cpp | 0 .../Systems/Private/activeGameState.cpp | 1714 ++++++++--------- .../Systems/Private/addResourceCommand.cpp | 0 .../Systems/Private/addTechnologyCommand.cpp | 0 .../Systems/Private/addUnitCommand.cpp | 0 .../Systems/Private/console.cpp | 0 .../Systems/Private/guiAppState.cpp | 238 +-- .../Systems/Private/inGameAppState.cpp | 206 +- .../Systems/Private/loadingAppState.cpp | 0 .../Systems/Private/mapEditorAppState.cpp | 2 +- .../Systems/Private/toggleDebugCommand.cpp | 0 .../Systems/Public/abstractCommand.h | 0 .../Systems/Public/activeGameState.h | 224 +-- .../Systems/Public/addResourceCommand.h | 0 .../Systems/Public/addTechnologyCommand.h | 0 .../Systems/Public/addUnitCommand.h | 0 console.h => Source/Systems/Public/console.h | 0 .../Systems/Public/guiAppState.h | 84 +- .../Systems/Public/inGameAppState.h | 120 +- .../Systems/Public/loadingAppState.h | 0 .../Systems/Public/mapEditorAppState.h | 0 .../Systems/Public/toggleDebugCommand.h | 0 .../UI/Private/activeStateBackButton.cpp | 0 .../UI/Private/activeStateButton.cpp | 0 .../UI/Private/backButton.cpp | 0 .../UI/Private/buildButton.cpp | 0 .../UI/Private/concreteGuiManager.cpp | 0 .../UI/Private/defaultsButton.cpp | 0 .../UI/Private/exitButton.cpp | 0 .../UI/Private/exportButton.cpp | 0 .../UI/Private/gameObjectFrame.cpp | 0 .../UI/Private/gameObjectFrameController.cpp | 0 .../UI/Private/gameObjectListbox.cpp | 0 .../UI/Private/landTextureListbox.cpp | 0 .../UI/Private/loadMapButton.cpp | 0 .../UI/Private/mainMenuButton.cpp | 0 .../UI/Private/mapEditorButton.cpp | 0 .../UI/Private/mapListbox.cpp | 0 .../UI/Private/minimapButton.cpp | 0 .../UI/Private/newMapButton.cpp | 0 .../UI/Private/offerButton.cpp | 0 .../UI/Private/okButton.cpp | 0 .../UI/Private/optionsButton.cpp | 30 +- .../UI/Private/orderButton.cpp | 0 .../UI/Private/playButton.cpp | 2 +- .../UI/Private/playerTradeButton.cpp | 0 .../UI/Private/researchButton.cpp | 0 .../UI/Private/resourceAmmountButton.cpp | 0 .../UI/Private/singlePlayerButton.cpp | 62 +- .../UI/Private/skyboxTextureListbox.cpp | 0 .../UI/Private/stateToggleButton.cpp | 0 .../UI/Private/statsButton.cpp | 0 .../UI/Private/tabButton.cpp | 0 tooltip.cpp => Source/UI/Private/tooltip.cpp | 0 .../UI/Private/tradeButton.cpp | 0 .../UI/Private/tradingScreenButton.cpp | 0 .../UI/Private/trainButton.cpp | 0 .../UI/Private/unitButton.cpp | 0 .../UI/Public/activeStateBackButton.h | 0 .../UI/Public/activeStateButton.h | 0 backButton.h => Source/UI/Public/backButton.h | 0 .../UI/Public/buildButton.h | 0 .../UI/Public/concreteGuiManager.h | 0 .../UI/Public/defaultsButton.h | 0 exitButton.h => Source/UI/Public/exitButton.h | 0 .../UI/Public/exportButton.h | 0 .../UI/Public/gameObjectFrame.h | 0 .../UI/Public/gameObjectFrameController.h | 0 .../UI/Public/gameObjectListbox.h | 0 .../UI/Public/landTextureListbox.h | 0 .../UI/Public/loadMapButton.h | 0 .../UI/Public/mainMenuButton.h | 0 .../UI/Public/mapEditorButton.h | 0 mapListbox.h => Source/UI/Public/mapListbox.h | 0 .../UI/Public/minimapButton.h | 0 .../UI/Public/newMapButton.h | 0 .../UI/Public/offerButton.h | 0 okButton.h => Source/UI/Public/okButton.h | 0 .../UI/Public/optionsButton.h | 30 +- .../UI/Public/orderButton.h | 0 playButton.h => Source/UI/Public/playButton.h | 0 .../UI/Public/playerTradeButton.h | 0 .../UI/Public/researchButton.h | 0 .../UI/Public/resourceAmmountButton.h | 0 .../UI/Public/singlePlayerButton.h | 38 +- .../UI/Public/skyboxTextureListbox.h | 0 .../UI/Public/stateToggleButton.h | 0 .../UI/Public/statsButton.h | 0 tabButton.h => Source/UI/Public/tabButton.h | 0 tooltip.h => Source/UI/Public/tooltip.h | 0 .../UI/Public/tradeButton.h | 0 .../UI/Public/tradingScreenButton.h | 0 .../UI/Public/trainButton.h | 0 unitButton.h => Source/UI/Public/unitButton.h | 0 mapTest.cpp => Tests/mapTest.cpp | 0 mapTest.h => Tests/mapTest.h | 0 .../pathfinderTest.cpp | 0 pathfinderTest.h => Tests/pathfinderTest.h | 0 testMain.cpp => Tests/testMain.cpp | 0 external/gameBase | 1 - external/tinydir | 1 - external/vb01 | 1 - 186 files changed, 4602 insertions(+), 4529 deletions(-) rename cameraController.cpp => Source/AI/Private/cameraController.cpp (100%) rename pathfinder.cpp => Source/AI/Private/pathfinder.cpp (100%) rename cameraController.h => Source/AI/Public/cameraController.h (100%) rename pathfinder.h => Source/AI/Public/pathfinder.h (100%) rename defConfigs.cpp => Source/Core/Private/defConfigs.cpp (100%) rename main.cpp => Source/Core/Private/main.cpp (95%) mode change 100755 => 100644 rename util.cpp => Source/Core/Private/util.cpp (96%) mode change 100755 => 100644 rename binds.h => Source/Core/Public/binds.h (100%) rename defConfigs.h => Source/Core/Public/defConfigs.h (95%) mode change 100755 => 100644 rename util.h => Source/Core/Public/util.h (96%) mode change 100755 => 100644 rename cruiseMissile.cpp => Source/Gameplay/Private/cruiseMissile.cpp (100%) rename depthCharge.cpp => Source/Gameplay/Private/depthCharge.cpp (100%) rename destructable.cpp => Source/Gameplay/Private/destructable.cpp (100%) rename engineer.cpp => Source/Gameplay/Private/engineer.cpp (100%) rename environment.cpp => Source/Gameplay/Private/environment.cpp (100%) rename explosion.cpp => Source/Gameplay/Private/explosion.cpp (100%) rename extractor.cpp => Source/Gameplay/Private/extractor.cpp (100%) rename factory.cpp => Source/Gameplay/Private/factory.cpp (100%) rename freezer.cpp => Source/Gameplay/Private/freezer.cpp (100%) rename fxManager.cpp => Source/Gameplay/Private/fxManager.cpp (100%) rename game.cpp => Source/Gameplay/Private/game.cpp (100%) rename gameManager.cpp => Source/Gameplay/Private/gameManager.cpp (97%) mode change 100755 => 100644 rename gameObject.cpp => Source/Gameplay/Private/gameObject.cpp (100%) rename gameObjectFactory.cpp => Source/Gameplay/Private/gameObjectFactory.cpp (100%) rename garrisonable.cpp => Source/Gameplay/Private/garrisonable.cpp (100%) rename iceSheet.cpp => Source/Gameplay/Private/iceSheet.cpp (100%) rename map.cpp => Source/Gameplay/Private/map.cpp (96%) mode change 100755 => 100644 rename missile.cpp => Source/Gameplay/Private/missile.cpp (100%) rename player.cpp => Source/Gameplay/Private/player.cpp (96%) mode change 100755 => 100644 rename pointDefense.cpp => Source/Gameplay/Private/pointDefense.cpp (100%) rename projectile.cpp => Source/Gameplay/Private/projectile.cpp (96%) mode change 100755 => 100644 rename researchStruct.cpp => Source/Gameplay/Private/researchStruct.cpp (100%) rename resourceDeposit.cpp => Source/Gameplay/Private/resourceDeposit.cpp (100%) rename resourceRover.cpp => Source/Gameplay/Private/resourceRover.cpp (100%) rename shell.cpp => Source/Gameplay/Private/shell.cpp (100%) rename structure.cpp => Source/Gameplay/Private/structure.cpp (100%) rename submarine.cpp => Source/Gameplay/Private/submarine.cpp (100%) rename torpedo.cpp => Source/Gameplay/Private/torpedo.cpp (100%) rename tradeCenter.cpp => Source/Gameplay/Private/tradeCenter.cpp (100%) rename trader.cpp => Source/Gameplay/Private/trader.cpp (100%) rename unit.cpp => Source/Gameplay/Private/unit.cpp (96%) mode change 100755 => 100644 rename vehicle.cpp => Source/Gameplay/Private/vehicle.cpp (100%) rename vessel.cpp => Source/Gameplay/Private/vessel.cpp (100%) mode change 100755 => 100644 rename weapon.cpp => Source/Gameplay/Private/weapon.cpp (100%) rename ability.h => Source/Gameplay/Public/ability.h (100%) rename buildableUnit.h => Source/Gameplay/Public/buildableUnit.h (100%) rename cruiseMissile.h => Source/Gameplay/Public/cruiseMissile.h (100%) rename depthCharge.h => Source/Gameplay/Public/depthCharge.h (100%) rename destructable.h => Source/Gameplay/Public/destructable.h (100%) rename engineer.h => Source/Gameplay/Public/engineer.h (100%) rename environment.h => Source/Gameplay/Public/environment.h (100%) rename explosion.h => Source/Gameplay/Public/explosion.h (100%) rename extractor.h => Source/Gameplay/Public/extractor.h (100%) rename factory.h => Source/Gameplay/Public/factory.h (100%) rename freezer.h => Source/Gameplay/Public/freezer.h (100%) rename fxManager.h => Source/Gameplay/Public/fxManager.h (100%) rename game.h => Source/Gameplay/Public/game.h (100%) rename gameManager.h => Source/Gameplay/Public/gameManager.h (96%) mode change 100755 => 100644 rename gameObject.h => Source/Gameplay/Public/gameObject.h (100%) rename gameObjectFactory.h => Source/Gameplay/Public/gameObjectFactory.h (100%) rename garrisonable.h => Source/Gameplay/Public/garrisonable.h (100%) rename iceSheet.h => Source/Gameplay/Public/iceSheet.h (100%) rename map.h => Source/Gameplay/Public/map.h (96%) mode change 100755 => 100644 rename missile.h => Source/Gameplay/Public/missile.h (100%) rename player.h => Source/Gameplay/Public/player.h (97%) mode change 100755 => 100644 rename pointDefense.h => Source/Gameplay/Public/pointDefense.h (100%) rename projectile.h => Source/Gameplay/Public/projectile.h (96%) mode change 100755 => 100644 rename researchStruct.h => Source/Gameplay/Public/researchStruct.h (100%) rename resourceDeposit.h => Source/Gameplay/Public/resourceDeposit.h (100%) rename resourceRover.h => Source/Gameplay/Public/resourceRover.h (100%) rename shell.h => Source/Gameplay/Public/shell.h (100%) rename structure.h => Source/Gameplay/Public/structure.h (100%) rename submarine.h => Source/Gameplay/Public/submarine.h (100%) rename technology.h => Source/Gameplay/Public/technology.h (100%) rename torpedo.h => Source/Gameplay/Public/torpedo.h (100%) rename tradeCenter.h => Source/Gameplay/Public/tradeCenter.h (100%) rename tradeOffer.h => Source/Gameplay/Public/tradeOffer.h (100%) rename trader.h => Source/Gameplay/Public/trader.h (100%) rename unit.h => Source/Gameplay/Public/unit.h (96%) mode change 100755 => 100644 rename vehicle.h => Source/Gameplay/Public/vehicle.h (100%) rename vessel.h => Source/Gameplay/Public/vessel.h (100%) mode change 100755 => 100644 rename weapon.h => Source/Gameplay/Public/weapon.h (100%) rename abstractCommand.cpp => Source/Systems/Private/abstractCommand.cpp (100%) rename activeGameState.cpp => Source/Systems/Private/activeGameState.cpp (97%) mode change 100755 => 100644 rename addResourceCommand.cpp => Source/Systems/Private/addResourceCommand.cpp (100%) rename addTechnologyCommand.cpp => Source/Systems/Private/addTechnologyCommand.cpp (100%) rename addUnitCommand.cpp => Source/Systems/Private/addUnitCommand.cpp (100%) rename console.cpp => Source/Systems/Private/console.cpp (100%) mode change 100755 => 100644 rename guiAppState.cpp => Source/Systems/Private/guiAppState.cpp (95%) mode change 100755 => 100644 rename inGameAppState.cpp => Source/Systems/Private/inGameAppState.cpp (97%) mode change 100755 => 100644 rename loadingAppState.cpp => Source/Systems/Private/loadingAppState.cpp (100%) rename mapEditorAppState.cpp => Source/Systems/Private/mapEditorAppState.cpp (99%) rename toggleDebugCommand.cpp => Source/Systems/Private/toggleDebugCommand.cpp (100%) rename abstractCommand.h => Source/Systems/Public/abstractCommand.h (100%) rename activeGameState.h => Source/Systems/Public/activeGameState.h (97%) mode change 100755 => 100644 rename addResourceCommand.h => Source/Systems/Public/addResourceCommand.h (100%) rename addTechnologyCommand.h => Source/Systems/Public/addTechnologyCommand.h (100%) rename addUnitCommand.h => Source/Systems/Public/addUnitCommand.h (100%) rename console.h => Source/Systems/Public/console.h (100%) mode change 100755 => 100644 rename guiAppState.h => Source/Systems/Public/guiAppState.h (96%) mode change 100755 => 100644 rename inGameAppState.h => Source/Systems/Public/inGameAppState.h (96%) mode change 100755 => 100644 rename loadingAppState.h => Source/Systems/Public/loadingAppState.h (100%) rename mapEditorAppState.h => Source/Systems/Public/mapEditorAppState.h (100%) rename toggleDebugCommand.h => Source/Systems/Public/toggleDebugCommand.h (100%) rename activeStateBackButton.cpp => Source/UI/Private/activeStateBackButton.cpp (100%) rename activeStateButton.cpp => Source/UI/Private/activeStateButton.cpp (100%) rename backButton.cpp => Source/UI/Private/backButton.cpp (100%) rename buildButton.cpp => Source/UI/Private/buildButton.cpp (100%) rename concreteGuiManager.cpp => Source/UI/Private/concreteGuiManager.cpp (100%) rename defaultsButton.cpp => Source/UI/Private/defaultsButton.cpp (100%) rename exitButton.cpp => Source/UI/Private/exitButton.cpp (100%) mode change 100755 => 100644 rename exportButton.cpp => Source/UI/Private/exportButton.cpp (100%) rename gameObjectFrame.cpp => Source/UI/Private/gameObjectFrame.cpp (100%) rename gameObjectFrameController.cpp => Source/UI/Private/gameObjectFrameController.cpp (100%) rename gameObjectListbox.cpp => Source/UI/Private/gameObjectListbox.cpp (100%) rename landTextureListbox.cpp => Source/UI/Private/landTextureListbox.cpp (100%) rename loadMapButton.cpp => Source/UI/Private/loadMapButton.cpp (100%) rename mainMenuButton.cpp => Source/UI/Private/mainMenuButton.cpp (100%) rename mapEditorButton.cpp => Source/UI/Private/mapEditorButton.cpp (100%) rename mapListbox.cpp => Source/UI/Private/mapListbox.cpp (100%) rename minimapButton.cpp => Source/UI/Private/minimapButton.cpp (100%) rename newMapButton.cpp => Source/UI/Private/newMapButton.cpp (100%) rename offerButton.cpp => Source/UI/Private/offerButton.cpp (100%) rename okButton.cpp => Source/UI/Private/okButton.cpp (100%) rename optionsButton.cpp => Source/UI/Private/optionsButton.cpp (96%) mode change 100755 => 100644 rename orderButton.cpp => Source/UI/Private/orderButton.cpp (100%) rename playButton.cpp => Source/UI/Private/playButton.cpp (99%) rename playerTradeButton.cpp => Source/UI/Private/playerTradeButton.cpp (100%) rename researchButton.cpp => Source/UI/Private/researchButton.cpp (100%) rename resourceAmmountButton.cpp => Source/UI/Private/resourceAmmountButton.cpp (100%) rename singlePlayerButton.cpp => Source/UI/Private/singlePlayerButton.cpp (94%) rename skyboxTextureListbox.cpp => Source/UI/Private/skyboxTextureListbox.cpp (100%) rename stateToggleButton.cpp => Source/UI/Private/stateToggleButton.cpp (100%) rename statsButton.cpp => Source/UI/Private/statsButton.cpp (100%) rename tabButton.cpp => Source/UI/Private/tabButton.cpp (100%) rename tooltip.cpp => Source/UI/Private/tooltip.cpp (100%) rename tradeButton.cpp => Source/UI/Private/tradeButton.cpp (100%) rename tradingScreenButton.cpp => Source/UI/Private/tradingScreenButton.cpp (100%) rename trainButton.cpp => Source/UI/Private/trainButton.cpp (100%) rename unitButton.cpp => Source/UI/Private/unitButton.cpp (100%) rename activeStateBackButton.h => Source/UI/Public/activeStateBackButton.h (100%) rename activeStateButton.h => Source/UI/Public/activeStateButton.h (100%) rename backButton.h => Source/UI/Public/backButton.h (100%) rename buildButton.h => Source/UI/Public/buildButton.h (100%) rename concreteGuiManager.h => Source/UI/Public/concreteGuiManager.h (100%) rename defaultsButton.h => Source/UI/Public/defaultsButton.h (100%) rename exitButton.h => Source/UI/Public/exitButton.h (100%) mode change 100755 => 100644 rename exportButton.h => Source/UI/Public/exportButton.h (100%) rename gameObjectFrame.h => Source/UI/Public/gameObjectFrame.h (100%) rename gameObjectFrameController.h => Source/UI/Public/gameObjectFrameController.h (100%) rename gameObjectListbox.h => Source/UI/Public/gameObjectListbox.h (100%) rename landTextureListbox.h => Source/UI/Public/landTextureListbox.h (100%) rename loadMapButton.h => Source/UI/Public/loadMapButton.h (100%) rename mainMenuButton.h => Source/UI/Public/mainMenuButton.h (100%) rename mapEditorButton.h => Source/UI/Public/mapEditorButton.h (100%) rename mapListbox.h => Source/UI/Public/mapListbox.h (100%) rename minimapButton.h => Source/UI/Public/minimapButton.h (100%) rename newMapButton.h => Source/UI/Public/newMapButton.h (100%) rename offerButton.h => Source/UI/Public/offerButton.h (100%) rename okButton.h => Source/UI/Public/okButton.h (100%) rename optionsButton.h => Source/UI/Public/optionsButton.h (95%) mode change 100755 => 100644 rename orderButton.h => Source/UI/Public/orderButton.h (100%) rename playButton.h => Source/UI/Public/playButton.h (100%) rename playerTradeButton.h => Source/UI/Public/playerTradeButton.h (100%) rename researchButton.h => Source/UI/Public/researchButton.h (100%) rename resourceAmmountButton.h => Source/UI/Public/resourceAmmountButton.h (100%) rename singlePlayerButton.h => Source/UI/Public/singlePlayerButton.h (94%) rename skyboxTextureListbox.h => Source/UI/Public/skyboxTextureListbox.h (100%) rename stateToggleButton.h => Source/UI/Public/stateToggleButton.h (100%) rename statsButton.h => Source/UI/Public/statsButton.h (100%) rename tabButton.h => Source/UI/Public/tabButton.h (100%) rename tooltip.h => Source/UI/Public/tooltip.h (100%) rename tradeButton.h => Source/UI/Public/tradeButton.h (100%) rename tradingScreenButton.h => Source/UI/Public/tradingScreenButton.h (100%) rename trainButton.h => Source/UI/Public/trainButton.h (100%) rename unitButton.h => Source/UI/Public/unitButton.h (100%) rename mapTest.cpp => Tests/mapTest.cpp (100%) rename mapTest.h => Tests/mapTest.h (100%) rename pathfinderTest.cpp => Tests/pathfinderTest.cpp (100%) rename pathfinderTest.h => Tests/pathfinderTest.h (100%) rename testMain.cpp => Tests/testMain.cpp (100%) delete mode 160000 external/gameBase delete mode 160000 external/tinydir delete mode 160000 external/vb01 diff --git a/.gitmodules b/.gitmodules index a4ac710..02f3710 100644 --- a/.gitmodules +++ b/.gitmodules @@ -1,4 +1,4 @@ -[submodule "gameBase2"] +[submodule "external/gameBase"] path = external/gameBase url = https://github.com/devZoGok/gameBase [submodule "external/vb01"] diff --git a/CMakeLists.txt b/CMakeLists.txt index 554c9c1..fcf591b 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -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() diff --git a/cameraController.cpp b/Source/AI/Private/cameraController.cpp similarity index 100% rename from cameraController.cpp rename to Source/AI/Private/cameraController.cpp diff --git a/pathfinder.cpp b/Source/AI/Private/pathfinder.cpp similarity index 100% rename from pathfinder.cpp rename to Source/AI/Private/pathfinder.cpp diff --git a/cameraController.h b/Source/AI/Public/cameraController.h similarity index 100% rename from cameraController.h rename to Source/AI/Public/cameraController.h diff --git a/pathfinder.h b/Source/AI/Public/pathfinder.h similarity index 100% rename from pathfinder.h rename to Source/AI/Public/pathfinder.h diff --git a/defConfigs.cpp b/Source/Core/Private/defConfigs.cpp similarity index 100% rename from defConfigs.cpp rename to Source/Core/Private/defConfigs.cpp diff --git a/main.cpp b/Source/Core/Private/main.cpp old mode 100755 new mode 100644 similarity index 95% rename from main.cpp rename to Source/Core/Private/main.cpp index 064259f..0a01ef0 --- a/main.cpp +++ b/Source/Core/Private/main.cpp @@ -1,38 +1,38 @@ -#include "util.h" -#include "gameManager.h" -#include "guiAppState.h" -#include "concreteGuiManager.h" - -#include - -#include -#include - -#include - -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 + +#include +#include + +#include + +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; +} diff --git a/util.cpp b/Source/Core/Private/util.cpp old mode 100755 new mode 100644 similarity index 96% rename from util.cpp rename to Source/Core/Private/util.cpp index 76e5450..65dcb21 --- a/util.cpp +++ b/Source/Core/Private/util.cpp @@ -1,145 +1,145 @@ -#include -#include -#include - -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include - -#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 assets = vector{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 readDir(string path, bool findFolders){ - tinydir_dir dir; - tinydir_open_sorted(&dir, path.c_str()); - vector 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 +#include +#include + +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include + +#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 assets = vector{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 readDir(string path, bool findFolders){ + tinydir_dir dir; + tinydir_open_sorted(&dir, path.c_str()); + vector 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; + } +} diff --git a/binds.h b/Source/Core/Public/binds.h similarity index 100% rename from binds.h rename to Source/Core/Public/binds.h diff --git a/defConfigs.h b/Source/Core/Public/defConfigs.h old mode 100755 new mode 100644 similarity index 95% rename from defConfigs.h rename to Source/Core/Public/defConfigs.h index e11c178..63906a5 --- a/defConfigs.h +++ b/Source/Core/Public/defConfigs.h @@ -1,214 +1,214 @@ -#ifndef DEF_CONFIGS_H -#define DEF_CONFIGS_H -#define SOL_ALL_SAFETIES_ON 1 - -#include -#include - -#include - -#include - -#include -#include - -#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 scripts = std::vector{ - "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 +#include + +#include + +#include + +#include +#include + +#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 scripts = std::vector{ + "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 diff --git a/util.h b/Source/Core/Public/util.h old mode 100755 new mode 100644 similarity index 96% rename from util.h rename to Source/Core/Public/util.h index 64075a8..75b6700 --- a/util.h +++ b/Source/Core/Public/util.h @@ -1,36 +1,36 @@ -#pragma once -#ifndef UTIL_BATTLESHIP_H -#define UTIL_BATTLESHIP_H - -#include -#include -#include -#include -#include - -#include - -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 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 +#include +#include +#include +#include + +#include + +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 readDir(std::string, bool); + vb01::Vector2 spaceToScreen(vb01::Vector3); + vb01::Vector3 spaceToScreen3d(vb01::Vector3); + vb01::Vector3 screenToSpace(vb01::Vector2); +} + +#endif diff --git a/cruiseMissile.cpp b/Source/Gameplay/Private/cruiseMissile.cpp similarity index 100% rename from cruiseMissile.cpp rename to Source/Gameplay/Private/cruiseMissile.cpp diff --git a/depthCharge.cpp b/Source/Gameplay/Private/depthCharge.cpp similarity index 100% rename from depthCharge.cpp rename to Source/Gameplay/Private/depthCharge.cpp diff --git a/destructable.cpp b/Source/Gameplay/Private/destructable.cpp similarity index 100% rename from destructable.cpp rename to Source/Gameplay/Private/destructable.cpp diff --git a/engineer.cpp b/Source/Gameplay/Private/engineer.cpp similarity index 100% rename from engineer.cpp rename to Source/Gameplay/Private/engineer.cpp diff --git a/environment.cpp b/Source/Gameplay/Private/environment.cpp similarity index 100% rename from environment.cpp rename to Source/Gameplay/Private/environment.cpp diff --git a/explosion.cpp b/Source/Gameplay/Private/explosion.cpp similarity index 100% rename from explosion.cpp rename to Source/Gameplay/Private/explosion.cpp diff --git a/extractor.cpp b/Source/Gameplay/Private/extractor.cpp similarity index 100% rename from extractor.cpp rename to Source/Gameplay/Private/extractor.cpp diff --git a/factory.cpp b/Source/Gameplay/Private/factory.cpp similarity index 100% rename from factory.cpp rename to Source/Gameplay/Private/factory.cpp diff --git a/freezer.cpp b/Source/Gameplay/Private/freezer.cpp similarity index 100% rename from freezer.cpp rename to Source/Gameplay/Private/freezer.cpp diff --git a/fxManager.cpp b/Source/Gameplay/Private/fxManager.cpp similarity index 100% rename from fxManager.cpp rename to Source/Gameplay/Private/fxManager.cpp diff --git a/game.cpp b/Source/Gameplay/Private/game.cpp similarity index 100% rename from game.cpp rename to Source/Gameplay/Private/game.cpp diff --git a/gameManager.cpp b/Source/Gameplay/Private/gameManager.cpp old mode 100755 new mode 100644 similarity index 97% rename from gameManager.cpp rename to Source/Gameplay/Private/gameManager.cpp index ca2167f..913ea76 --- a/gameManager.cpp +++ b/Source/Gameplay/Private/gameManager.cpp @@ -1,279 +1,279 @@ -#include - -#include -#include -#include - -#include -#include - -#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", sol::constructors, Vector3, int)>(), - "type", &Order::type, - "direction", &Order::direction, - "targets", &Order::targets - ); - - SOL_LUA_STATE.new_usertype( - "Target", sol::constructors(), - "unit", &Order::Target::unit, - "pos", &Order::Target::pos - ); - - SOL_LUA_STATE.new_usertype( - "GameObjectFactory", - "createUnit", &GameObjectFactory::createUnit, - "createResourceDeposit", &GameObjectFactory::createResourceDeposit - ); - - SOL_LUA_STATE.new_usertype( - "GarrisonSlot", - "vehicle", &Unit::GarrisonSlot::vehicle, - "category", &Unit::GarrisonSlot::category - ); - - SOL_LUA_STATE.new_usertype( - "Unit", sol::constructors(), - "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( - "Engineer", sol::constructors(), - "getGarrisonable", &Vehicle::getGarrisonable - ); - - SOL_LUA_STATE.new_usertype( - "Engineer", sol::constructors(), - "getBuildableUnit", &Unit::getBuildableUnit, - "getBuildableUnits", &Unit::getBuildableUnits, - "getNumBuildableUnits", &Unit::getNumBuildableUnits - ); - - SOL_LUA_STATE.new_usertype( - "Structure", sol::constructors(), - "getPos", &GameObject::getPos, - "isComplete", &Structure::isComplete, - "getBuildStatus", &Structure::getBuildStatus - ); - - SOL_LUA_STATE.new_usertype( - "BuildableUnit", sol::constructors(), - "id", &BuildableUnit::id, - "buildable", &BuildableUnit::buildable - ); - - SOL_LUA_STATE.new_usertype( - "Factory", sol::constructors(), - "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", sol::constructors(), - "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", sol::constructors(), - "getDeposit", &Extractor::getDeposit - ); - - SOL_LUA_STATE.new_usertype( - "ResourceDeposit", sol::constructors(), - "getExtractor", &ResourceDeposit::getExtractor, - "getAmmount", &ResourceDeposit::getAmmount, - "getPos", &GameObject::getPos, - "toGameObject", [](ResourceDeposit *rd){return (GameObject*)rd;} - ); - - SOL_LUA_STATE.new_usertype( - "Game", - "getSingleton", &Game::getSingleton, - "getPlayers", &Game::getPlayers - ); - - SOL_LUA_STATE.new_usertype( - "Vector3", sol::constructors(), - "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", sol::constructors(), - "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( - "Cell", - "pos", &Map::Cell::pos, - "type", &Map::Cell::type - ); - - SOL_LUA_STATE.new_usertype( - "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", - "getSingleton", &Pathfinder::getSingleton, - "calcHeuristics", &Pathfinder::calcHeuristics, - "findPath", &Pathfinder::findPath - ); - - SOL_LUA_STATE.new_usertype( - "GameObjectFrame", sol::constructors(), - "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", - "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 + +#include +#include +#include + +#include +#include + +#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", sol::constructors, Vector3, int)>(), + "type", &Order::type, + "direction", &Order::direction, + "targets", &Order::targets + ); + + SOL_LUA_STATE.new_usertype( + "Target", sol::constructors(), + "unit", &Order::Target::unit, + "pos", &Order::Target::pos + ); + + SOL_LUA_STATE.new_usertype( + "GameObjectFactory", + "createUnit", &GameObjectFactory::createUnit, + "createResourceDeposit", &GameObjectFactory::createResourceDeposit + ); + + SOL_LUA_STATE.new_usertype( + "GarrisonSlot", + "vehicle", &Unit::GarrisonSlot::vehicle, + "category", &Unit::GarrisonSlot::category + ); + + SOL_LUA_STATE.new_usertype( + "Unit", sol::constructors(), + "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( + "Engineer", sol::constructors(), + "getGarrisonable", &Vehicle::getGarrisonable + ); + + SOL_LUA_STATE.new_usertype( + "Engineer", sol::constructors(), + "getBuildableUnit", &Unit::getBuildableUnit, + "getBuildableUnits", &Unit::getBuildableUnits, + "getNumBuildableUnits", &Unit::getNumBuildableUnits + ); + + SOL_LUA_STATE.new_usertype( + "Structure", sol::constructors(), + "getPos", &GameObject::getPos, + "isComplete", &Structure::isComplete, + "getBuildStatus", &Structure::getBuildStatus + ); + + SOL_LUA_STATE.new_usertype( + "BuildableUnit", sol::constructors(), + "id", &BuildableUnit::id, + "buildable", &BuildableUnit::buildable + ); + + SOL_LUA_STATE.new_usertype( + "Factory", sol::constructors(), + "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", sol::constructors(), + "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", sol::constructors(), + "getDeposit", &Extractor::getDeposit + ); + + SOL_LUA_STATE.new_usertype( + "ResourceDeposit", sol::constructors(), + "getExtractor", &ResourceDeposit::getExtractor, + "getAmmount", &ResourceDeposit::getAmmount, + "getPos", &GameObject::getPos, + "toGameObject", [](ResourceDeposit *rd){return (GameObject*)rd;} + ); + + SOL_LUA_STATE.new_usertype( + "Game", + "getSingleton", &Game::getSingleton, + "getPlayers", &Game::getPlayers + ); + + SOL_LUA_STATE.new_usertype( + "Vector3", sol::constructors(), + "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", sol::constructors(), + "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( + "Cell", + "pos", &Map::Cell::pos, + "type", &Map::Cell::type + ); + + SOL_LUA_STATE.new_usertype( + "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", + "getSingleton", &Pathfinder::getSingleton, + "calcHeuristics", &Pathfinder::calcHeuristics, + "findPath", &Pathfinder::findPath + ); + + SOL_LUA_STATE.new_usertype( + "GameObjectFrame", sol::constructors(), + "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", + "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(); + } +} diff --git a/gameObject.cpp b/Source/Gameplay/Private/gameObject.cpp similarity index 100% rename from gameObject.cpp rename to Source/Gameplay/Private/gameObject.cpp diff --git a/gameObjectFactory.cpp b/Source/Gameplay/Private/gameObjectFactory.cpp similarity index 100% rename from gameObjectFactory.cpp rename to Source/Gameplay/Private/gameObjectFactory.cpp diff --git a/garrisonable.cpp b/Source/Gameplay/Private/garrisonable.cpp similarity index 100% rename from garrisonable.cpp rename to Source/Gameplay/Private/garrisonable.cpp diff --git a/iceSheet.cpp b/Source/Gameplay/Private/iceSheet.cpp similarity index 100% rename from iceSheet.cpp rename to Source/Gameplay/Private/iceSheet.cpp diff --git a/map.cpp b/Source/Gameplay/Private/map.cpp old mode 100755 new mode 100644 similarity index 96% rename from map.cpp rename to Source/Gameplay/Private/map.cpp index b4c3f30..414ca15 --- a/map.cpp +++ b/Source/Gameplay/Private/map.cpp @@ -1,754 +1,754 @@ -#include -#include -#include -#include -#include -#include -#include - -#include - -#include -#include - -#include "map.h" -#include "util.h" -#include "vehicle.h" -#include "game.h" -#include "player.h" -#include "gameObject.h" -#include "pathfinder.h" -#include "gameManager.h" -#include "defConfigs.h" -#include "resourceDeposit.h" -#include "activeGameState.h" -#include "concreteGuiManager.h" -#include "gameObjectFactory.h" - - -namespace battleship{ - using namespace std; - using namespace vb01; - using namespace vb01Gui; - using namespace gameBase; - using namespace configData; - - static Map *map = nullptr; - static Map::Minimap *minimap = nullptr; - - Map::Minimap* Map::Minimap::getSingleton(){ - if(!minimap) minimap = new Map::Minimap(); - - return minimap; - } - - Map::Minimap::Minimap(){ - sol::state_view SOL_STATE_VIEW = generateView(); - SOL_STATE_VIEW.script_file(GameManager::getSingleton()->getPath() + "Scripts/Gui/activeGameState.lua"); - - string refIconFile = SOL_STATE_VIEW["refIcon"]; - string basePath = GameManager::getSingleton()->getPath() + "Textures/Icons/Minimap/"; - - for(ResourceDeposit *rd : Game::getSingleton()->getCivilianPlayer()->getResourceDeposits()) - depositIcons.push_back(initIcon(rd->getPos(), basePath + refIconFile)); - - string camIconFile = SOL_STATE_VIEW["eyeIcon"]; - camIcon = initIcon(Root::getSingleton()->getCamera()->getPosition(), basePath + camIconFile); - } - - Map::Minimap::~Minimap(){ - Node *guiNode = Root::getSingleton()->getGuiNode(); - - for(Node *node : depositIcons){ - guiNode->dettachChild(node); - delete node; - } - - depositIcons.clear(); - - guiNode->dettachChild(camIcon); - delete camIcon; - } - - Node* Map::Minimap::initIcon(Vector3 posOnMap, string iconPath){ - string p[]{iconPath}; - ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(iconPath); - Vector3 iconSize = Vector3(asset->width, asset->height, 0); - Texture *tex = new Texture(p, 1, false); - - Root *root = Root::getSingleton(); - Material *mat = new Material(root->getLibPath() + "gui"); - mat->addBoolUniform("texturingEnabled", true); - mat->addTexUniform("diffuseMap", tex, false); - - sol::state_view SOL_LUA_VIEW = generateView(); - sol::table posTbl = SOL_LUA_VIEW["minimapPos"], sizeTbl = SOL_LUA_VIEW["minimapSize"]; - Vector2 minimapSize = Vector2(sizeTbl["x"], sizeTbl["y"]); - Vector3 minimapPos = Vector3(posTbl["x"], posTbl["y"], posTbl["z"]); - - Vector3 mapSize = Map::getSingleton()->getMapSize(); - Vector2 iconPos = Vector2( - minimapSize.x * (posOnMap.x + .5 * mapSize.x) / mapSize.x, - minimapSize.y * (posOnMap.z + .5 * mapSize.z) / mapSize.z - ); - - Quad *quad = new Quad(iconSize, false); - quad->setMaterial(mat); - - Node *node = new Node(minimapPos + Vector3(iconPos.x, iconPos.y, .1) - .5 * iconSize); - node->attachMesh(quad); - node->setVisible(false); - root->getGuiNode()->attachChild(node); - - return node; - } - - //TODO add a flag to Player::getUnits* whether to include garrisoned units - void Map::Minimap::updateImage(){ - GameManager *gm = GameManager::getSingleton(); - Map *map = Map::getSingleton(); - - string imagePath = gm->getPath() + "Models/Maps/" + map->getMapName() + "/minimap.jpg"; - ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(imagePath); - int width = asset->width, height = asset->height; - - Vector3 mapSize = map->getMapSize(); - vector> unitMinimapPos; - - ActiveGameState *activeState = (ActiveGameState*)gm->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); - - for(Player *pl : Game::getSingleton()->getPlayers(true)) - if(pl->getTeam() == activeState->getPlayer()->getTeam()){ - vector units = pl->getUnits(); - - for(Unit *u : units){ - if(u->isVehicle() && ((Vehicle*)u)->getGarrisonable()) continue; - - Vector2 coords = Vector2( - int(u->getPos().x / mapSize.x * width), - int(-u->getPos().z / mapSize.z * height) - ); - unitMinimapPos.push_back(make_pair(u, coords)); - } - } - - int pxId = 0, numChannels = asset->numChannels, size = width * height * numChannels; - float losFactor = .6; - - for(u8 *p = asset->image; p != asset->image + size; p += numChannels, pxId += numChannels){ - *(p + 0) = losFactor * oldImageData[pxId + 0]; - *(p + 1) = losFactor * oldImageData[pxId + 1]; - *(p + 2) = losFactor * oldImageData[pxId + 2]; - } - - int unitPxRadius = 1; - - for(pair unitPair : unitMinimapPos){ - Unit *losUnit = unitPair.first; - Vector2 losUnitCoords = unitPair.second; - float minimapLos = losUnit->getLineOfSight() / mapSize.x * width; - - for(int x = max(-.5f * width, losUnitCoords.x - minimapLos); x < min(.5f * width, losUnitCoords.x + minimapLos); x++){ - for(int y = max(-.5f * height, losUnitCoords.y - minimapLos); y < min(.5f * height, losUnitCoords.y + minimapLos); y++){ - int pxId = width * (y + .5 * height) + (x + .5 * width); - Vector2 coords = Vector2(x, y); - - if(coords.getDistanceFrom(losUnitCoords) < minimapLos){ - asset->image[numChannels * pxId + 0] = oldImageData[numChannels * pxId + 0]; - asset->image[numChannels * pxId + 1] = oldImageData[numChannels * pxId + 1]; - asset->image[numChannels * pxId + 2] = oldImageData[numChannels * pxId + 2]; - - for(pair addUnitPair : unitMinimapPos) - if(fabs(addUnitPair.second.x - coords.x) < unitPxRadius && fabs(addUnitPair.second.y - coords.y) < unitPxRadius){ - Vector3 unitCol = addUnitPair.first->getPlayer()->getColor(); - asset->image[numChannels * pxId + 0] = unitCol.x * 255; - asset->image[numChannels * pxId + 1] = unitCol.y * 255; - asset->image[numChannels * pxId + 2] = unitCol.z * 255; - - break; - } - } - } - } - } - - Node *rectNode = ConcreteGuiManager::getSingleton()->getButton("minimap")->getRectNode(); - Material *mat = rectNode->getMesh(0)->getMaterial(); - Texture *tex = ((Material::TextureUniform*)mat->getUniform("diffuseMap"))->value; - tex->loadImageData(asset, false); - } - - void Map::Minimap::updateCamFrame(Button *minimapButton){ - Vector3 camPos = Root::getSingleton()->getCamera()->getPosition(); - Vector3 mapSize = Map::getSingleton()->getMapSize(); - Vector2 minimapSize = minimapButton->getSize(); - Vector2 iconPos = Vector2( - minimapSize.x * (camPos.x + .5 * mapSize.x) / mapSize.x, - minimapSize.y * (camPos.z + .5 * mapSize.z) / mapSize.z - ); - - camIcon->setPosition(minimapButton->getPos() + Vector3(iconPos.x, iconPos.y, .1)); - } - - void Map::Minimap::update(){ - if(!GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE)) return; - - Button *mb = ConcreteGuiManager::getSingleton()->getButton("minimap"); - updateCamFrame(mb); - } - - void Map::Minimap::load(){ - for(Node *node : depositIcons) - node->setVisible(true); - - AssetManager *am = AssetManager::getSingleton(); - string minimapPath = GameManager::getSingleton()->getPath() + "Models/Maps/" + Map::getSingleton()->getMapName() + "/minimap.jpg"; - - am->load(minimapPath); - ImageAsset *asset = (ImageAsset*)am->getAsset(minimapPath); - int imgSize = asset->width * asset->height * asset->numChannels; - oldImageData = new u8[imgSize]; - - for(int i = 0; i < imgSize; i++) - oldImageData[i] = asset->image[i]; - } - - void Map::Minimap::unload(){ - for(Node *node : depositIcons) - node->setVisible(false); - - delete[] oldImageData; - } - - Map* Map::getSingleton(){ - if(!map) map = new Map; - - return map; - } - - vector Map::generateAdjacentNodeEdges(int numVertCells, int i, int numHorCells, int j, int weight){ - vector edges; - bool checkUp = (i > 0), checkRight = (j < numHorCells - 1), checkDown = (i < numVertCells - 1), checkLeft = (j > 0); - - if(checkLeft) - edges.push_back(Map::Edge(weight, numHorCells * i + j, numHorCells * i + j - 1)); - - if(checkRight) - edges.push_back(Map::Edge(weight, numHorCells * i + j, numHorCells * i + j + 1)); - - if(checkUp) - edges.push_back(Map::Edge(weight, numHorCells * i + j, numHorCells * (i - 1) + j)); - - if(checkDown) - edges.push_back(Map::Edge(weight, numHorCells * i + j, numHorCells * (i + 1) + j)); - - if(checkUp && checkLeft) - edges.push_back(Map::Edge(int(sqrt(2 * weight * weight)), numHorCells * i + j, numHorCells * (i - 1) + j - 1)); - - if(checkUp && checkRight) - edges.push_back(Map::Edge(int(sqrt(2 * weight * weight)), numHorCells * i + j, numHorCells * (i - 1) + j + 1)); - - if(checkDown && checkLeft) - edges.push_back(Map::Edge(int(sqrt(2 * weight * weight)), numHorCells * i + j, numHorCells * (i + 1) + j - 1)); - - if(checkDown && checkRight) - edges.push_back(Map::Edge(int(sqrt(2 * weight * weight)), numHorCells * i + j, numHorCells * (i + 1) + j + 1)); - - return edges; - } - - void Map::update(){ - Minimap::getSingleton()->update(); - } - - void Map::loadSkybox(){ - sol::state_view SOL_LUA_STATE = generateView(); - string skyboxName = SOL_LUA_STATE[mapTable]["skybox"]; - string basePath = GameManager::getSingleton()->getPath() + "Textures/Skyboxes/" + skyboxName; - - const int numPaths = 6; - string path[numPaths] = { - basePath + "/left.jpg", - basePath + "/right.jpg", - basePath + "/up.jpg", - basePath + "/down.jpg", - basePath + "/front.jpg", - basePath + "/back.jpg" - }; - - for(int i = 0; i < numPaths; i++) - AssetManager::getSingleton()->load(path[i]); - - Root::getSingleton()->createSkybox(path); - } - - void Map::loadLights(){ - sol::state_view SOL_LUA_VIEW = generateView(); - sol::table lightsTbl = SOL_LUA_VIEW[mapTable]["lights"]; - int numLights = lightsTbl.size(); - - for(int i = 0; i < numLights; i++){ - int id = i + 1; - Light::Type type = (Light::Type)lightsTbl[id]["type"]; - sol::table colTbl = lightsTbl[id]["color"]; - - Light *light = new Light(type); - light->setColor(Vector3(colTbl["x"], colTbl["y"], colTbl["z"])); - - Node *lightNode = new Node(); - lights.push_back(lightNode); - lightNode->addLight(light); - - if(type == Light::Type::DIRECTIONAL){ - sol::table dirTbl = lightsTbl[id]["dir"]; - Vector3 dir = Vector3(dirTbl["x"], dirTbl["y"], dirTbl["z"]).norm(); - lightNode->lookAt(dir); - } - - Root::getSingleton()->getRootNode()->attachChild(lightNode); - } - } - - void Map::loadTerrainObject(int id){ - string texPath = "", albedoPath = ""; - Quad *quad = nullptr; - Node *node = nullptr; - sol::state_view SOL_LUA_STATE = generateView(); - - if(id == -1){ - string basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/"; - - albedoPath = SOL_LUA_STATE[mapTable]["terrain"]["albedo"]; - texPath = basePath + albedoPath; - - string modelPath = SOL_LUA_STATE[mapTable]["terrain"]["model"]; - string terrainFile = basePath + modelPath; - - AssetManager::getSingleton()->load(terrainFile); - node = (Model*)((new Model(terrainFile))->getChild(0)); - - Node *par = node->getParent(); - par->dettachChild(node); - delete par; - } - else{ - sol::table waterBodyTable = SOL_LUA_STATE[mapTable]["waterbodies"][id + 1], posTable = waterBodyTable["pos"]; - albedoPath = waterBodyTable["albedo"]; - texPath = GameManager::getSingleton()->getPath() + "Textures/Water/" + albedoPath; - - quad = new Quad(Vector3(waterBodyTable["size"]["x"], waterBodyTable["size"]["y"], 1), true); - Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]); - node = new Node(pos); - node->attachMesh(quad); - } - - terrainNode->attachChild(node); - - Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture"); - mat->addBoolUniform("texturingEnabled", true); - mat->addBoolUniform("lightingEnabled", true); - mat->addBoolUniform("constLightingEnabled", true); - mat->addBoolUniform("normalMapEnabled", false); - mat->addBoolUniform("specularMapEnabled", false); - mat->addBoolUniform("castShadow", false); - - string fr[]{texPath}; - AssetManager::getSingleton()->load(fr[0]); - Texture *t = new Texture(fr, 1, false); - - mat->addTexUniform("textures[0]", t, true); - - if(id == -1) - ((Model*)node)->setMaterial(mat); - else{ - mat->setTransparent(true); - quad->setMaterial(mat); - } - } - - int Map::getNumMapSpawnPoints(string name){ - if(name != "") - generateView().script_file(GameManager::getSingleton()->getPath() + "Models/Maps/" + name + "/" + name + ".lua"); - - sol::table spawnPointsTbl = generateView()["metadata"]["spawnPoints"]; - return spawnPointsTbl.size(); - } - - //TODO improve for underwater cells - vector Map::getSurroundingCells(Vector3 p, int numRings){ - int numHorCells = int(mapSize.x / CELL_SIZE.x); - int numVertCells = int(mapSize.z / CELL_SIZE.z); - int horId = int((.5 * mapSize.x + p.x) / CELL_SIZE.x); - int vertId = int((.5 * mapSize.z + p.z) / CELL_SIZE.z); - - vector cellIds; - - for(int i = max(vertId - numRings, 0); i <= min(vertId + numRings, numVertCells - 1); i++) - for(int j = max(horId - numRings, 0); j <= min(horId + numRings, numHorCells - 1); j++) - cellIds.push_back(numHorCells * i + j); - - return cellIds; - } - - void Map::blockCells(Unit *unit){ - vector surroundingCellIds = getSurroundingCells(unit->getPos(), 0); - - for(int scid : surroundingCellIds){ - if(cells[scid].blockedBy && cells[scid].blockedBy != unit) continue; - - bool within = unit->pointWithinObj(cells[scid].pos); - cells[scid].blockedBy = (within ? unit : nullptr); - } - } - - void Map::unblockCells(Unit *unit){ - vector surroundingCellIds = getSurroundingCells(unit->getPos(), 0); - - for(int scid : surroundingCellIds) - if(cells[scid].blockedBy == unit) - cells[scid].blockedBy = nullptr; - } - - void Map::loadSpawnPoints(){ - sol::state_view SOL_LUA_VIEW = generateView(); - int numSpawnPoints = getNumMapSpawnPoints(); - - for(int i = 0; i < numSpawnPoints; i++){ - sol::table posTable = SOL_LUA_VIEW[mapTable]["spawnPoints"][i + 1]; - spawnPoints.push_back(Vector3(posTable["x"], posTable["y"], posTable["z"])); - } - } - - void Map::loadPlayerGameObjects(Player *player, sol::table playerTbl){ - sol::state_view SOL_LUA_VIEW = generateView(); - - string resDepInd = "resourceDeposits"; - sol::optional resDepTblOpt = playerTbl[resDepInd]; - - if(resDepTblOpt != sol::nullopt){ - sol::table resDepTbl = playerTbl[resDepInd]; - int numNpcObjs = resDepTbl.size(); - - for(int j = 0; j < numNpcObjs; j++){ - sol::table npcObjTable = resDepTbl[j + 1]; - int id = npcObjTable["id"]; - - sol::table posTable = npcObjTable["pos"]; - Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]); - - sol::table rotTable = npcObjTable["rot"]; - Quaternion rot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]); - int initAmmount = resDepTbl[j + 1]["initAmmount"]; - - player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, id, pos, rot, initAmmount)); - } - } - - string unitInd = "units"; - sol::optional unitsTblOpt = playerTbl[unitInd]; - - if(unitsTblOpt != sol::nullopt){ - sol::table unitsTbl = playerTbl[unitInd]; - int numUnits = unitsTbl.size(); - - for(int j = 0; j < numUnits; j++){ - sol::table unitTable = unitsTbl[j + 1]; - - string posInd = "pos"; - Vector3 pos = Vector3(unitTable[posInd]["x"], unitTable[posInd]["y"], unitTable[posInd]["z"]); - - string rotInd = "rot"; - Quaternion rot = Quaternion(unitTable[rotInd]["w"], unitTable[rotInd]["x"], unitTable[rotInd]["y"], unitTable[rotInd]["z"]); - - int id = unitTable["id"]; - int buildStatus = unitTable["buildStatus"].get_or(0); - player->addUnit(GameObjectFactory::createUnit(player, id, pos, rot, buildStatus)); - } - } - } - - //TODO move minimap loading elsewhere - void Map::loadPlayersGameObjects(){ - Game *game = Game::getSingleton(); - vector choosablePlayers = game->getPlayers(false); - sol::state_view SOL_LUA_VIEW = generateView(); - - for(int i = 0; i < choosablePlayers.size(); i++){ - sol::table playerTbl = SOL_LUA_VIEW[mapTable]["choosablePlayers"][i + 1]; - loadPlayerGameObjects(choosablePlayers[i], playerTbl); - } - - sol::table civPlayerTbl = SOL_LUA_VIEW[mapTable]["civilianPlayer"]; - loadPlayerGameObjects(game->getCivilianPlayer(), civPlayerTbl); - - Minimap::getSingleton()->load(); - } - - void Map::preprareScene(bool empty){ - Game::getSingleton()->setCivilianPlayer(new Player(0, 0, 0, .5 * Vector3::VEC_IJK)); - - Root *root = Root::getSingleton(); - Node *rootNode = root->getRootNode(); - string libPath = root->getLibPath(); - terrainNode = new Node(); - rootNode->attachChild(terrainNode); - - cellNode = new Node(); - cellNode->setVisible(false); - rootNode->attachChild(cellNode); - landCellMat = new Material(libPath + "texture"); - landCellMat->addBoolUniform("lightingEnabled", false); - landCellMat->addBoolUniform("texturingEnabled", false); - landCellMat->addVec4Uniform("diffuseColor", Vector4(0, 1, 0, 1)); - waterCellMat = new Material(libPath + "texture"); - waterCellMat->addBoolUniform("lightingEnabled", false); - waterCellMat->addBoolUniform("texturingEnabled", false); - waterCellMat->addVec4Uniform("diffuseColor", Vector4(0, 0, 1, 1)); - - Camera *cam = root->getCamera(); - cam->setFarPlane(600); - cam->setPosition(Vector3(1, 1, 1) * configData::CAMERA_DISTANCE); - cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm()); - - if(empty){ - Light *light = new Light(Light::Type::AMBIENT); - light->setColor(Vector3::VEC_IJK * .9); - - Node *node = new Node(); - node->addLight(light); - Root::getSingleton()->getRootNode()->attachChild(node); - lights.push_back(node); - } - } - - //TODO implement toggleable cell rendering - void Map::loadCells(){ - sol::state_view SOL_LUA_VIEW = generateView(); - sol::table cellsTable = SOL_LUA_VIEW["cells"]; - int numCells = cellsTable.size(); - - for(int i = 0; i < numCells; i++){ - sol::table cellTable = cellsTable[i + 1], posTable = cellTable["pos"]; - int numEdges = cellTable["numEdges"]; - vector edges; - - for(int j = 0; j < numEdges; j++){ - sol::table edgeTable = cellTable["edges"][j + 1]; - edges.push_back(Edge(edgeTable["weight"], edgeTable["srcCellId"], edgeTable["destCellId"])); - } - - int numUnderWaterCells = cellTable["numUnderWaterCells"]; - vector underWaterCellIds; - - for(int j = 0; j < numUnderWaterCells; j++) - underWaterCellIds.push_back((int)cellTable["underWaterCellId"][j + 1]); - - Vector3 cellPos = Vector3(posTable["x"], posTable["y"], posTable["z"]); - Cell::Type cellType = (Cell::Type)cellTable["type"]; - - /* - Quad *quad = new Quad(Vector3(CELL_SIZE.x, CELL_SIZE.z, 0)); - quad->setWireframe(true); - quad->setMaterial(cellType == Cell::Type::LAND ? landCellMat : waterCellMat); - - Node *node = new Node(cellPos + Vector3::VEC_J * .1); - node->attachMesh(quad); - */ - - cells.push_back(Cell(cellPos, cellType, edges, underWaterCellIds)); - - } - } - - void Map::load(string mapName){ - this->mapName = mapName; - - Pathfinder::getSingleton()->setImpassibleNodeVal(u32(0 - 1)); - string path = GameManager::getSingleton()->getPath(); - AssetManager::getSingleton()->load(path + "Textures/", true); - - sol::state_view SOL_LUA_STATE = generateView(); - SOL_LUA_STATE.script_file(path + "Models/Maps/" + mapName + "/" + mapName + ".lua"); - SOL_LUA_STATE.script_file(path + "Models/Maps/" + mapName + "/cells.lua"); - - preprareScene(false); - loadSpawnPoints(); - loadSkybox(); - loadCells(); - loadTerrainObject(-1); - - sol::optional lightsOpt = SOL_LUA_STATE[mapTable]["lights"]; - - if(lightsOpt != sol::nullopt) - loadLights(); - - sol::table sizeTable = SOL_LUA_STATE[mapTable]["size"]; - mapSize = Vector3(sizeTable["x"], sizeTable["y"], sizeTable["z"]); - sol::table wbTbl = SOL_LUA_STATE[mapTable]["waterbodies"]; - int numWaterbodies = wbTbl.size(); - - for(int i = 0; i < numWaterbodies; i++) - loadTerrainObject(i); - } - - void Map::create(string mapName, Vector3 mapSize){ - this->mapName = mapName; - this->mapSize = mapSize; - - //addSpawnPoint(Vector3::VEC_ZERO); - preprareScene(true); - } - - //TODO unload skybox assets - void Map::unloadSkybox(){ - Root::getSingleton()->removeSkybox(); - } - - void Map::unloadLights(){ - while(!lights.empty()){ - Root::getSingleton()->getRootNode()->dettachChild(lights[0]); - delete lights[0]; - lights.erase(lights.begin()); - } - } - - void Map::unloadCells(){ - while(cellNode->getNumChildren() > 0){ - Node *node = cellNode->getChild(0); - node->getMesh(0)->setMaterial(nullptr); - cellNode->dettachChild(node); - delete node; - } - - delete landCellMat; - delete waterCellMat; - - cells.clear(); - } - - //TODO unload terrain assets - void Map::unloadTerrainObjects(){ - while(terrainNode->getNumChildren() > 0){ - Node *node = terrainNode->getChild(0); - terrainNode->dettachChild(node); - delete node; - } - } - - void Map::unloadPlayerObjects(){ - for(Player *pl : Game::getSingleton()->getPlayers(true)){ - while(pl->getNumUnits() > 0){ - pl->removeUnit(0); - } - - while(pl->getNumResourceDeposits() > 0){ - pl->removeResourceDeposit(0); - } - } - } - - void Map::destroyScene(){ - Node *rootNode = Root::getSingleton()->getRootNode(); - rootNode->dettachChild(terrainNode); - rootNode->dettachChild(cellNode); - - delete terrainNode; - delete cellNode; - } - - void Map::unload(){ - Minimap::getSingleton()->unload(); - - unloadPlayerObjects(); - unloadCells(); - unloadTerrainObjects(); - destroyScene(); - unloadLights(); - unloadSkybox(); - spawnPoints.clear(); - } - - vector Map::raycastTerrain(Vector3 rayPos, Vector3 rayDir, bool bothTerrTypes){ - vector allResults = RayCaster::cast(rayPos, rayDir, terrainNode->getChild(0), 0, configData::DIST_FROM_RAY); - - if(bothTerrTypes){ - vector waterNodes = terrainNode->getChildren(); - waterNodes.erase(waterNodes.begin()); - - vector waterResults = RayCaster::cast(rayPos, rayDir, waterNodes); - allResults.insert(allResults.end(), waterResults.begin(), waterResults.end()); - - RayCaster::sortResults(allResults); - } - - return allResults; - } - - template int Map::bsearch(vector haystack, T needle, float eps){ - T haystackMidVal; - bool sizeHaystackEven = (haystack.size() % 2 == 0); - int midValId = haystack.size() / 2; - - if(sizeHaystackEven) - haystackMidVal = (haystack[midValId - 1] + haystack[midValId]) / 2; - else - haystackMidVal = haystack[midValId]; - - int beginId, endId; - - if(fabs(haystackMidVal - needle) > eps){ - if(fabs(haystackMidVal - needle) < eps){ - beginId = 0; - endId = (midValId - 1); - } - else{ - endId = haystack.size() - 1; - endId = (midValId + 1); - } - - return bsearch(vector(haystack.begin() + beginId, haystack.begin() + endId), needle); - } - else{ - if(sizeHaystackEven) - return midValId - (needle > haystackMidVal ? 0 : 1); - else - return midValId; - } - } - - //TODO replace search with binary search - //TODO optimize horizontal and vertical id calculcation - int Map::getCellId(Vector3 pos, bool checkUnderwaterCells){ - int numHorCells = int(mapSize.x / CELL_SIZE.x), horId = -1; - - for(int i = 0; i < numHorCells; i++) - if(fabs(cells[i].pos.x - pos.x) <= .5 * CELL_SIZE.x){ - horId = i; - break; - } - - int numVertCells = int(mapSize.z / CELL_SIZE.z), vertId = -1; - - for(int i = 0; i < numVertCells; i++) - if(fabs(cells[i * numHorCells].pos.z - pos.z) <= .5 * CELL_SIZE.z){ - vertId = i; - break; - } - - int surfaceCellId = vertId * numHorCells + horId; - - if(checkUnderwaterCells && cells[surfaceCellId].type == Cell::Type::WATER && !cells[surfaceCellId].underWaterCellIds.empty()){ - int cellId = surfaceCellId; - - for(int i = 0; i <= cells[surfaceCellId].underWaterCellIds.size(); i++){ - cellId = (i == 0 ? surfaceCellId : cells[surfaceCellId].underWaterCellIds[i - 1]); - - if(fabs(cells[cellId].pos.y - pos.y) < .5 * CELL_SIZE.y) - return cellId; - } - - return surfaceCellId; - } - else return surfaceCellId; - } -} +#include +#include +#include +#include +#include +#include +#include + +#include + +#include +#include + +#include "map.h" +#include "util.h" +#include "vehicle.h" +#include "game.h" +#include "player.h" +#include "gameObject.h" +#include "pathfinder.h" +#include "gameManager.h" +#include "defConfigs.h" +#include "resourceDeposit.h" +#include "activeGameState.h" +#include "concreteGuiManager.h" +#include "gameObjectFactory.h" + + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + using namespace gameBase; + using namespace configData; + + static Map *map = nullptr; + static Map::Minimap *minimap = nullptr; + + Map::Minimap* Map::Minimap::getSingleton(){ + if(!minimap) minimap = new Map::Minimap(); + + return minimap; + } + + Map::Minimap::Minimap(){ + sol::state_view SOL_STATE_VIEW = generateView(); + SOL_STATE_VIEW.script_file(GameManager::getSingleton()->getPath() + "Scripts/Gui/activeGameState.lua"); + + string refIconFile = SOL_STATE_VIEW["refIcon"]; + string basePath = GameManager::getSingleton()->getPath() + "Textures/Icons/Minimap/"; + + for(ResourceDeposit *rd : Game::getSingleton()->getCivilianPlayer()->getResourceDeposits()) + depositIcons.push_back(initIcon(rd->getPos(), basePath + refIconFile)); + + string camIconFile = SOL_STATE_VIEW["eyeIcon"]; + camIcon = initIcon(Root::getSingleton()->getCamera()->getPosition(), basePath + camIconFile); + } + + Map::Minimap::~Minimap(){ + Node *guiNode = Root::getSingleton()->getGuiNode(); + + for(Node *node : depositIcons){ + guiNode->dettachChild(node); + delete node; + } + + depositIcons.clear(); + + guiNode->dettachChild(camIcon); + delete camIcon; + } + + Node* Map::Minimap::initIcon(Vector3 posOnMap, string iconPath){ + string p[]{iconPath}; + ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(iconPath); + Vector3 iconSize = Vector3(asset->width, asset->height, 0); + Texture *tex = new Texture(p, 1, false); + + Root *root = Root::getSingleton(); + Material *mat = new Material(root->getLibPath() + "gui"); + mat->addBoolUniform("texturingEnabled", true); + mat->addTexUniform("diffuseMap", tex, false); + + sol::state_view SOL_LUA_VIEW = generateView(); + sol::table posTbl = SOL_LUA_VIEW["minimapPos"], sizeTbl = SOL_LUA_VIEW["minimapSize"]; + Vector2 minimapSize = Vector2(sizeTbl["x"], sizeTbl["y"]); + Vector3 minimapPos = Vector3(posTbl["x"], posTbl["y"], posTbl["z"]); + + Vector3 mapSize = Map::getSingleton()->getMapSize(); + Vector2 iconPos = Vector2( + minimapSize.x * (posOnMap.x + .5 * mapSize.x) / mapSize.x, + minimapSize.y * (posOnMap.z + .5 * mapSize.z) / mapSize.z + ); + + Quad *quad = new Quad(iconSize, false); + quad->setMaterial(mat); + + Node *node = new Node(minimapPos + Vector3(iconPos.x, iconPos.y, .1) - .5 * iconSize); + node->attachMesh(quad); + node->setVisible(false); + root->getGuiNode()->attachChild(node); + + return node; + } + + //TODO add a flag to Player::getUnits* whether to include garrisoned units + void Map::Minimap::updateImage(){ + GameManager *gm = GameManager::getSingleton(); + Map *map = Map::getSingleton(); + + string imagePath = gm->getPath() + "Models/Maps/" + map->getMapName() + "/minimap.jpg"; + ImageAsset *asset = (ImageAsset*)AssetManager::getSingleton()->getAsset(imagePath); + int width = asset->width, height = asset->height; + + Vector3 mapSize = map->getMapSize(); + vector> unitMinimapPos; + + ActiveGameState *activeState = (ActiveGameState*)gm->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); + + for(Player *pl : Game::getSingleton()->getPlayers(true)) + if(pl->getTeam() == activeState->getPlayer()->getTeam()){ + vector units = pl->getUnits(); + + for(Unit *u : units){ + if(u->isVehicle() && ((Vehicle*)u)->getGarrisonable()) continue; + + Vector2 coords = Vector2( + int(u->getPos().x / mapSize.x * width), + int(-u->getPos().z / mapSize.z * height) + ); + unitMinimapPos.push_back(make_pair(u, coords)); + } + } + + int pxId = 0, numChannels = asset->numChannels, size = width * height * numChannels; + float losFactor = .6; + + for(u8 *p = asset->image; p != asset->image + size; p += numChannels, pxId += numChannels){ + *(p + 0) = losFactor * oldImageData[pxId + 0]; + *(p + 1) = losFactor * oldImageData[pxId + 1]; + *(p + 2) = losFactor * oldImageData[pxId + 2]; + } + + int unitPxRadius = 1; + + for(pair unitPair : unitMinimapPos){ + Unit *losUnit = unitPair.first; + Vector2 losUnitCoords = unitPair.second; + float minimapLos = losUnit->getLineOfSight() / mapSize.x * width; + + for(int x = max(-.5f * width, losUnitCoords.x - minimapLos); x < min(.5f * width, losUnitCoords.x + minimapLos); x++){ + for(int y = max(-.5f * height, losUnitCoords.y - minimapLos); y < min(.5f * height, losUnitCoords.y + minimapLos); y++){ + int pxId = width * (y + .5 * height) + (x + .5 * width); + Vector2 coords = Vector2(x, y); + + if(coords.getDistanceFrom(losUnitCoords) < minimapLos){ + asset->image[numChannels * pxId + 0] = oldImageData[numChannels * pxId + 0]; + asset->image[numChannels * pxId + 1] = oldImageData[numChannels * pxId + 1]; + asset->image[numChannels * pxId + 2] = oldImageData[numChannels * pxId + 2]; + + for(pair addUnitPair : unitMinimapPos) + if(fabs(addUnitPair.second.x - coords.x) < unitPxRadius && fabs(addUnitPair.second.y - coords.y) < unitPxRadius){ + Vector3 unitCol = addUnitPair.first->getPlayer()->getColor(); + asset->image[numChannels * pxId + 0] = unitCol.x * 255; + asset->image[numChannels * pxId + 1] = unitCol.y * 255; + asset->image[numChannels * pxId + 2] = unitCol.z * 255; + + break; + } + } + } + } + } + + Node *rectNode = ConcreteGuiManager::getSingleton()->getButton("minimap")->getRectNode(); + Material *mat = rectNode->getMesh(0)->getMaterial(); + Texture *tex = ((Material::TextureUniform*)mat->getUniform("diffuseMap"))->value; + tex->loadImageData(asset, false); + } + + void Map::Minimap::updateCamFrame(Button *minimapButton){ + Vector3 camPos = Root::getSingleton()->getCamera()->getPosition(); + Vector3 mapSize = Map::getSingleton()->getMapSize(); + Vector2 minimapSize = minimapButton->getSize(); + Vector2 iconPos = Vector2( + minimapSize.x * (camPos.x + .5 * mapSize.x) / mapSize.x, + minimapSize.y * (camPos.z + .5 * mapSize.z) / mapSize.z + ); + + camIcon->setPosition(minimapButton->getPos() + Vector3(iconPos.x, iconPos.y, .1)); + } + + void Map::Minimap::update(){ + if(!GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE)) return; + + Button *mb = ConcreteGuiManager::getSingleton()->getButton("minimap"); + updateCamFrame(mb); + } + + void Map::Minimap::load(){ + for(Node *node : depositIcons) + node->setVisible(true); + + AssetManager *am = AssetManager::getSingleton(); + string minimapPath = GameManager::getSingleton()->getPath() + "Models/Maps/" + Map::getSingleton()->getMapName() + "/minimap.jpg"; + + am->load(minimapPath); + ImageAsset *asset = (ImageAsset*)am->getAsset(minimapPath); + int imgSize = asset->width * asset->height * asset->numChannels; + oldImageData = new u8[imgSize]; + + for(int i = 0; i < imgSize; i++) + oldImageData[i] = asset->image[i]; + } + + void Map::Minimap::unload(){ + for(Node *node : depositIcons) + node->setVisible(false); + + delete[] oldImageData; + } + + Map* Map::getSingleton(){ + if(!map) map = new Map; + + return map; + } + + vector Map::generateAdjacentNodeEdges(int numVertCells, int i, int numHorCells, int j, int weight){ + vector edges; + bool checkUp = (i > 0), checkRight = (j < numHorCells - 1), checkDown = (i < numVertCells - 1), checkLeft = (j > 0); + + if(checkLeft) + edges.push_back(Map::Edge(weight, numHorCells * i + j, numHorCells * i + j - 1)); + + if(checkRight) + edges.push_back(Map::Edge(weight, numHorCells * i + j, numHorCells * i + j + 1)); + + if(checkUp) + edges.push_back(Map::Edge(weight, numHorCells * i + j, numHorCells * (i - 1) + j)); + + if(checkDown) + edges.push_back(Map::Edge(weight, numHorCells * i + j, numHorCells * (i + 1) + j)); + + if(checkUp && checkLeft) + edges.push_back(Map::Edge(int(sqrt(2 * weight * weight)), numHorCells * i + j, numHorCells * (i - 1) + j - 1)); + + if(checkUp && checkRight) + edges.push_back(Map::Edge(int(sqrt(2 * weight * weight)), numHorCells * i + j, numHorCells * (i - 1) + j + 1)); + + if(checkDown && checkLeft) + edges.push_back(Map::Edge(int(sqrt(2 * weight * weight)), numHorCells * i + j, numHorCells * (i + 1) + j - 1)); + + if(checkDown && checkRight) + edges.push_back(Map::Edge(int(sqrt(2 * weight * weight)), numHorCells * i + j, numHorCells * (i + 1) + j + 1)); + + return edges; + } + + void Map::update(){ + Minimap::getSingleton()->update(); + } + + void Map::loadSkybox(){ + sol::state_view SOL_LUA_STATE = generateView(); + string skyboxName = SOL_LUA_STATE[mapTable]["skybox"]; + string basePath = GameManager::getSingleton()->getPath() + "Textures/Skyboxes/" + skyboxName; + + const int numPaths = 6; + string path[numPaths] = { + basePath + "/left.jpg", + basePath + "/right.jpg", + basePath + "/up.jpg", + basePath + "/down.jpg", + basePath + "/front.jpg", + basePath + "/back.jpg" + }; + + for(int i = 0; i < numPaths; i++) + AssetManager::getSingleton()->load(path[i]); + + Root::getSingleton()->createSkybox(path); + } + + void Map::loadLights(){ + sol::state_view SOL_LUA_VIEW = generateView(); + sol::table lightsTbl = SOL_LUA_VIEW[mapTable]["lights"]; + int numLights = lightsTbl.size(); + + for(int i = 0; i < numLights; i++){ + int id = i + 1; + Light::Type type = (Light::Type)lightsTbl[id]["type"]; + sol::table colTbl = lightsTbl[id]["color"]; + + Light *light = new Light(type); + light->setColor(Vector3(colTbl["x"], colTbl["y"], colTbl["z"])); + + Node *lightNode = new Node(); + lights.push_back(lightNode); + lightNode->addLight(light); + + if(type == Light::Type::DIRECTIONAL){ + sol::table dirTbl = lightsTbl[id]["dir"]; + Vector3 dir = Vector3(dirTbl["x"], dirTbl["y"], dirTbl["z"]).norm(); + lightNode->lookAt(dir); + } + + Root::getSingleton()->getRootNode()->attachChild(lightNode); + } + } + + void Map::loadTerrainObject(int id){ + string texPath = "", albedoPath = ""; + Quad *quad = nullptr; + Node *node = nullptr; + sol::state_view SOL_LUA_STATE = generateView(); + + if(id == -1){ + string basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + mapName + "/"; + + albedoPath = SOL_LUA_STATE[mapTable]["terrain"]["albedo"]; + texPath = basePath + albedoPath; + + string modelPath = SOL_LUA_STATE[mapTable]["terrain"]["model"]; + string terrainFile = basePath + modelPath; + + AssetManager::getSingleton()->load(terrainFile); + node = (Model*)((new Model(terrainFile))->getChild(0)); + + Node *par = node->getParent(); + par->dettachChild(node); + delete par; + } + else{ + sol::table waterBodyTable = SOL_LUA_STATE[mapTable]["waterbodies"][id + 1], posTable = waterBodyTable["pos"]; + albedoPath = waterBodyTable["albedo"]; + texPath = GameManager::getSingleton()->getPath() + "Textures/Water/" + albedoPath; + + quad = new Quad(Vector3(waterBodyTable["size"]["x"], waterBodyTable["size"]["y"], 1), true); + Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]); + node = new Node(pos); + node->attachMesh(quad); + } + + terrainNode->attachChild(node); + + Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture"); + mat->addBoolUniform("texturingEnabled", true); + mat->addBoolUniform("lightingEnabled", true); + mat->addBoolUniform("constLightingEnabled", true); + mat->addBoolUniform("normalMapEnabled", false); + mat->addBoolUniform("specularMapEnabled", false); + mat->addBoolUniform("castShadow", false); + + string fr[]{texPath}; + AssetManager::getSingleton()->load(fr[0]); + Texture *t = new Texture(fr, 1, false); + + mat->addTexUniform("textures[0]", t, true); + + if(id == -1) + ((Model*)node)->setMaterial(mat); + else{ + mat->setTransparent(true); + quad->setMaterial(mat); + } + } + + int Map::getNumMapSpawnPoints(string name){ + if(name != "") + generateView().script_file(GameManager::getSingleton()->getPath() + "Models/Maps/" + name + "/" + name + ".lua"); + + sol::table spawnPointsTbl = generateView()["metadata"]["spawnPoints"]; + return spawnPointsTbl.size(); + } + + //TODO improve for underwater cells + vector Map::getSurroundingCells(Vector3 p, int numRings){ + int numHorCells = int(mapSize.x / CELL_SIZE.x); + int numVertCells = int(mapSize.z / CELL_SIZE.z); + int horId = int((.5 * mapSize.x + p.x) / CELL_SIZE.x); + int vertId = int((.5 * mapSize.z + p.z) / CELL_SIZE.z); + + vector cellIds; + + for(int i = max(vertId - numRings, 0); i <= min(vertId + numRings, numVertCells - 1); i++) + for(int j = max(horId - numRings, 0); j <= min(horId + numRings, numHorCells - 1); j++) + cellIds.push_back(numHorCells * i + j); + + return cellIds; + } + + void Map::blockCells(Unit *unit){ + vector surroundingCellIds = getSurroundingCells(unit->getPos(), 0); + + for(int scid : surroundingCellIds){ + if(cells[scid].blockedBy && cells[scid].blockedBy != unit) continue; + + bool within = unit->pointWithinObj(cells[scid].pos); + cells[scid].blockedBy = (within ? unit : nullptr); + } + } + + void Map::unblockCells(Unit *unit){ + vector surroundingCellIds = getSurroundingCells(unit->getPos(), 0); + + for(int scid : surroundingCellIds) + if(cells[scid].blockedBy == unit) + cells[scid].blockedBy = nullptr; + } + + void Map::loadSpawnPoints(){ + sol::state_view SOL_LUA_VIEW = generateView(); + int numSpawnPoints = getNumMapSpawnPoints(); + + for(int i = 0; i < numSpawnPoints; i++){ + sol::table posTable = SOL_LUA_VIEW[mapTable]["spawnPoints"][i + 1]; + spawnPoints.push_back(Vector3(posTable["x"], posTable["y"], posTable["z"])); + } + } + + void Map::loadPlayerGameObjects(Player *player, sol::table playerTbl){ + sol::state_view SOL_LUA_VIEW = generateView(); + + string resDepInd = "resourceDeposits"; + sol::optional resDepTblOpt = playerTbl[resDepInd]; + + if(resDepTblOpt != sol::nullopt){ + sol::table resDepTbl = playerTbl[resDepInd]; + int numNpcObjs = resDepTbl.size(); + + for(int j = 0; j < numNpcObjs; j++){ + sol::table npcObjTable = resDepTbl[j + 1]; + int id = npcObjTable["id"]; + + sol::table posTable = npcObjTable["pos"]; + Vector3 pos = Vector3(posTable["x"], posTable["y"], posTable["z"]); + + sol::table rotTable = npcObjTable["rot"]; + Quaternion rot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]); + int initAmmount = resDepTbl[j + 1]["initAmmount"]; + + player->addResourceDeposit(GameObjectFactory::createResourceDeposit(player, id, pos, rot, initAmmount)); + } + } + + string unitInd = "units"; + sol::optional unitsTblOpt = playerTbl[unitInd]; + + if(unitsTblOpt != sol::nullopt){ + sol::table unitsTbl = playerTbl[unitInd]; + int numUnits = unitsTbl.size(); + + for(int j = 0; j < numUnits; j++){ + sol::table unitTable = unitsTbl[j + 1]; + + string posInd = "pos"; + Vector3 pos = Vector3(unitTable[posInd]["x"], unitTable[posInd]["y"], unitTable[posInd]["z"]); + + string rotInd = "rot"; + Quaternion rot = Quaternion(unitTable[rotInd]["w"], unitTable[rotInd]["x"], unitTable[rotInd]["y"], unitTable[rotInd]["z"]); + + int id = unitTable["id"]; + int buildStatus = unitTable["buildStatus"].get_or(0); + player->addUnit(GameObjectFactory::createUnit(player, id, pos, rot, buildStatus)); + } + } + } + + //TODO move minimap loading elsewhere + void Map::loadPlayersGameObjects(){ + Game *game = Game::getSingleton(); + vector choosablePlayers = game->getPlayers(false); + sol::state_view SOL_LUA_VIEW = generateView(); + + for(int i = 0; i < choosablePlayers.size(); i++){ + sol::table playerTbl = SOL_LUA_VIEW[mapTable]["choosablePlayers"][i + 1]; + loadPlayerGameObjects(choosablePlayers[i], playerTbl); + } + + sol::table civPlayerTbl = SOL_LUA_VIEW[mapTable]["civilianPlayer"]; + loadPlayerGameObjects(game->getCivilianPlayer(), civPlayerTbl); + + Minimap::getSingleton()->load(); + } + + void Map::preprareScene(bool empty){ + Game::getSingleton()->setCivilianPlayer(new Player(0, 0, 0, .5 * Vector3::VEC_IJK)); + + Root *root = Root::getSingleton(); + Node *rootNode = root->getRootNode(); + string libPath = root->getLibPath(); + terrainNode = new Node(); + rootNode->attachChild(terrainNode); + + cellNode = new Node(); + cellNode->setVisible(false); + rootNode->attachChild(cellNode); + landCellMat = new Material(libPath + "texture"); + landCellMat->addBoolUniform("lightingEnabled", false); + landCellMat->addBoolUniform("texturingEnabled", false); + landCellMat->addVec4Uniform("diffuseColor", Vector4(0, 1, 0, 1)); + waterCellMat = new Material(libPath + "texture"); + waterCellMat->addBoolUniform("lightingEnabled", false); + waterCellMat->addBoolUniform("texturingEnabled", false); + waterCellMat->addVec4Uniform("diffuseColor", Vector4(0, 0, 1, 1)); + + Camera *cam = root->getCamera(); + cam->setFarPlane(600); + cam->setPosition(Vector3(1, 1, 1) * configData::CAMERA_DISTANCE); + cam->lookAt(Vector3(-1, -1, -1).norm(), Vector3(-1, 1, -1).norm()); + + if(empty){ + Light *light = new Light(Light::Type::AMBIENT); + light->setColor(Vector3::VEC_IJK * .9); + + Node *node = new Node(); + node->addLight(light); + Root::getSingleton()->getRootNode()->attachChild(node); + lights.push_back(node); + } + } + + //TODO implement toggleable cell rendering + void Map::loadCells(){ + sol::state_view SOL_LUA_VIEW = generateView(); + sol::table cellsTable = SOL_LUA_VIEW["cells"]; + int numCells = cellsTable.size(); + + for(int i = 0; i < numCells; i++){ + sol::table cellTable = cellsTable[i + 1], posTable = cellTable["pos"]; + int numEdges = cellTable["numEdges"]; + vector edges; + + for(int j = 0; j < numEdges; j++){ + sol::table edgeTable = cellTable["edges"][j + 1]; + edges.push_back(Edge(edgeTable["weight"], edgeTable["srcCellId"], edgeTable["destCellId"])); + } + + int numUnderWaterCells = cellTable["numUnderWaterCells"]; + vector underWaterCellIds; + + for(int j = 0; j < numUnderWaterCells; j++) + underWaterCellIds.push_back((int)cellTable["underWaterCellId"][j + 1]); + + Vector3 cellPos = Vector3(posTable["x"], posTable["y"], posTable["z"]); + Cell::Type cellType = (Cell::Type)cellTable["type"]; + + /* + Quad *quad = new Quad(Vector3(CELL_SIZE.x, CELL_SIZE.z, 0)); + quad->setWireframe(true); + quad->setMaterial(cellType == Cell::Type::LAND ? landCellMat : waterCellMat); + + Node *node = new Node(cellPos + Vector3::VEC_J * .1); + node->attachMesh(quad); + */ + + cells.push_back(Cell(cellPos, cellType, edges, underWaterCellIds)); + + } + } + + void Map::load(string mapName){ + this->mapName = mapName; + + Pathfinder::getSingleton()->setImpassibleNodeVal(u32(0 - 1)); + string path = GameManager::getSingleton()->getPath(); + AssetManager::getSingleton()->load(path + "Textures/", true); + + sol::state_view SOL_LUA_STATE = generateView(); + SOL_LUA_STATE.script_file(path + "Models/Maps/" + mapName + "/" + mapName + ".lua"); + SOL_LUA_STATE.script_file(path + "Models/Maps/" + mapName + "/cells.lua"); + + preprareScene(false); + loadSpawnPoints(); + loadSkybox(); + loadCells(); + loadTerrainObject(-1); + + sol::optional lightsOpt = SOL_LUA_STATE[mapTable]["lights"]; + + if(lightsOpt != sol::nullopt) + loadLights(); + + sol::table sizeTable = SOL_LUA_STATE[mapTable]["size"]; + mapSize = Vector3(sizeTable["x"], sizeTable["y"], sizeTable["z"]); + sol::table wbTbl = SOL_LUA_STATE[mapTable]["waterbodies"]; + int numWaterbodies = wbTbl.size(); + + for(int i = 0; i < numWaterbodies; i++) + loadTerrainObject(i); + } + + void Map::create(string mapName, Vector3 mapSize){ + this->mapName = mapName; + this->mapSize = mapSize; + + //addSpawnPoint(Vector3::VEC_ZERO); + preprareScene(true); + } + + //TODO unload skybox assets + void Map::unloadSkybox(){ + Root::getSingleton()->removeSkybox(); + } + + void Map::unloadLights(){ + while(!lights.empty()){ + Root::getSingleton()->getRootNode()->dettachChild(lights[0]); + delete lights[0]; + lights.erase(lights.begin()); + } + } + + void Map::unloadCells(){ + while(cellNode->getNumChildren() > 0){ + Node *node = cellNode->getChild(0); + node->getMesh(0)->setMaterial(nullptr); + cellNode->dettachChild(node); + delete node; + } + + delete landCellMat; + delete waterCellMat; + + cells.clear(); + } + + //TODO unload terrain assets + void Map::unloadTerrainObjects(){ + while(terrainNode->getNumChildren() > 0){ + Node *node = terrainNode->getChild(0); + terrainNode->dettachChild(node); + delete node; + } + } + + void Map::unloadPlayerObjects(){ + for(Player *pl : Game::getSingleton()->getPlayers(true)){ + while(pl->getNumUnits() > 0){ + pl->removeUnit(0); + } + + while(pl->getNumResourceDeposits() > 0){ + pl->removeResourceDeposit(0); + } + } + } + + void Map::destroyScene(){ + Node *rootNode = Root::getSingleton()->getRootNode(); + rootNode->dettachChild(terrainNode); + rootNode->dettachChild(cellNode); + + delete terrainNode; + delete cellNode; + } + + void Map::unload(){ + Minimap::getSingleton()->unload(); + + unloadPlayerObjects(); + unloadCells(); + unloadTerrainObjects(); + destroyScene(); + unloadLights(); + unloadSkybox(); + spawnPoints.clear(); + } + + vector Map::raycastTerrain(Vector3 rayPos, Vector3 rayDir, bool bothTerrTypes){ + vector allResults = RayCaster::cast(rayPos, rayDir, terrainNode->getChild(0), 0, configData::DIST_FROM_RAY); + + if(bothTerrTypes){ + vector waterNodes = terrainNode->getChildren(); + waterNodes.erase(waterNodes.begin()); + + vector waterResults = RayCaster::cast(rayPos, rayDir, waterNodes); + allResults.insert(allResults.end(), waterResults.begin(), waterResults.end()); + + RayCaster::sortResults(allResults); + } + + return allResults; + } + + template int Map::bsearch(vector haystack, T needle, float eps){ + T haystackMidVal; + bool sizeHaystackEven = (haystack.size() % 2 == 0); + int midValId = haystack.size() / 2; + + if(sizeHaystackEven) + haystackMidVal = (haystack[midValId - 1] + haystack[midValId]) / 2; + else + haystackMidVal = haystack[midValId]; + + int beginId, endId; + + if(fabs(haystackMidVal - needle) > eps){ + if(fabs(haystackMidVal - needle) < eps){ + beginId = 0; + endId = (midValId - 1); + } + else{ + endId = haystack.size() - 1; + endId = (midValId + 1); + } + + return bsearch(vector(haystack.begin() + beginId, haystack.begin() + endId), needle); + } + else{ + if(sizeHaystackEven) + return midValId - (needle > haystackMidVal ? 0 : 1); + else + return midValId; + } + } + + //TODO replace search with binary search + //TODO optimize horizontal and vertical id calculcation + int Map::getCellId(Vector3 pos, bool checkUnderwaterCells){ + int numHorCells = int(mapSize.x / CELL_SIZE.x), horId = -1; + + for(int i = 0; i < numHorCells; i++) + if(fabs(cells[i].pos.x - pos.x) <= .5 * CELL_SIZE.x){ + horId = i; + break; + } + + int numVertCells = int(mapSize.z / CELL_SIZE.z), vertId = -1; + + for(int i = 0; i < numVertCells; i++) + if(fabs(cells[i * numHorCells].pos.z - pos.z) <= .5 * CELL_SIZE.z){ + vertId = i; + break; + } + + int surfaceCellId = vertId * numHorCells + horId; + + if(checkUnderwaterCells && cells[surfaceCellId].type == Cell::Type::WATER && !cells[surfaceCellId].underWaterCellIds.empty()){ + int cellId = surfaceCellId; + + for(int i = 0; i <= cells[surfaceCellId].underWaterCellIds.size(); i++){ + cellId = (i == 0 ? surfaceCellId : cells[surfaceCellId].underWaterCellIds[i - 1]); + + if(fabs(cells[cellId].pos.y - pos.y) < .5 * CELL_SIZE.y) + return cellId; + } + + return surfaceCellId; + } + else return surfaceCellId; + } +} diff --git a/missile.cpp b/Source/Gameplay/Private/missile.cpp similarity index 100% rename from missile.cpp rename to Source/Gameplay/Private/missile.cpp diff --git a/player.cpp b/Source/Gameplay/Private/player.cpp old mode 100755 new mode 100644 similarity index 96% rename from player.cpp rename to Source/Gameplay/Private/player.cpp index 16558b2..9b1fa4a --- a/player.cpp +++ b/Source/Gameplay/Private/player.cpp @@ -1,358 +1,358 @@ -#include -#include - -#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 units = this->units; - for(Unit *u : units){ - if(!u->isRemove()) u->update(); - else removeUnit(u); - } - - vector projectiles = this->projectiles; - for(Projectile *proj : projectiles){ - if(!proj->isRemove()) proj->update(); - else removeProjectile(proj); - } - - for(ResourceDeposit *rd : resourceDeposits) rd->update(); - - for(pair> &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 lines = lineRenderer->getLines(); - - return lines[lines.size() - 1].id; - } - - void Player::issueOrder(Order::TYPE type, Vector3 destDir, vector targets, bool append){ - vector 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 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 Player::getUnitsById(int id, int numUnits){ - vector idUnits; - - for(Unit *unit : units){ - if(numUnits != -1 && idUnits.size() == numUnits) - break; - - if(unit->getId() == id) - idUnits.push_back(unit); - } - - return idUnits; - } - - vector Player::getUnitsByClass(UnitClass uc, int numUnits){ - vector 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> 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 players = Game::getSingleton()->getPlayers(); - - for(Player *pl : players){ - if(this == pl) continue; - - if(team == pl->getTeam()){ - tradeOffers.push_back(make_pair(pl, vector{})); - tradedResources.push_back(make_pair(pl, vector{ - TradedResource(ResourceType::REFINEDS), - TradedResource(ResourceType::WEALTH), - TradedResource(ResourceType::RESEARCH) - })); - } - } - } - - void Player::addTradeOffer(Player *player, TradeOffer *offer){ - if(tradeOffers.empty()) initTradingVecs(); - - for(pair> &offers : tradeOffers) - if(offers.first == player) - offers.second.push_back(offer); - } - - vector Player::getTradeOffers(Player *player){ - for(pair> offers : tradeOffers) - if(offers.first == player) - return offers.second; - - return vector{}; - } - - void Player::deselectUnit(Unit *unit){ - for(int i = 0; i < selectedUnits.size(); i++) - if(selectedUnits[i] == unit){ - selectedUnits.erase(selectedUnits.begin() + i); - break; - } - } - - vector Player::getDestructables(){ - vector 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 Player::getFriendlyUnits(bool includeOwn){ - vector 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 Player::getHostileUnits(){ - vector 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 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 cpuPlayers = Game::getSingleton()->getCpuPlayers(); - - for(int i = 0; i < cpuPlayers.size(); i++) - if(cpuPlayers[i] == this) - return i; - - return -1; - } -} +#include +#include + +#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 units = this->units; + for(Unit *u : units){ + if(!u->isRemove()) u->update(); + else removeUnit(u); + } + + vector projectiles = this->projectiles; + for(Projectile *proj : projectiles){ + if(!proj->isRemove()) proj->update(); + else removeProjectile(proj); + } + + for(ResourceDeposit *rd : resourceDeposits) rd->update(); + + for(pair> &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 lines = lineRenderer->getLines(); + + return lines[lines.size() - 1].id; + } + + void Player::issueOrder(Order::TYPE type, Vector3 destDir, vector targets, bool append){ + vector 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 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 Player::getUnitsById(int id, int numUnits){ + vector idUnits; + + for(Unit *unit : units){ + if(numUnits != -1 && idUnits.size() == numUnits) + break; + + if(unit->getId() == id) + idUnits.push_back(unit); + } + + return idUnits; + } + + vector Player::getUnitsByClass(UnitClass uc, int numUnits){ + vector 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> 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 players = Game::getSingleton()->getPlayers(); + + for(Player *pl : players){ + if(this == pl) continue; + + if(team == pl->getTeam()){ + tradeOffers.push_back(make_pair(pl, vector{})); + tradedResources.push_back(make_pair(pl, vector{ + TradedResource(ResourceType::REFINEDS), + TradedResource(ResourceType::WEALTH), + TradedResource(ResourceType::RESEARCH) + })); + } + } + } + + void Player::addTradeOffer(Player *player, TradeOffer *offer){ + if(tradeOffers.empty()) initTradingVecs(); + + for(pair> &offers : tradeOffers) + if(offers.first == player) + offers.second.push_back(offer); + } + + vector Player::getTradeOffers(Player *player){ + for(pair> offers : tradeOffers) + if(offers.first == player) + return offers.second; + + return vector{}; + } + + void Player::deselectUnit(Unit *unit){ + for(int i = 0; i < selectedUnits.size(); i++) + if(selectedUnits[i] == unit){ + selectedUnits.erase(selectedUnits.begin() + i); + break; + } + } + + vector Player::getDestructables(){ + vector 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 Player::getFriendlyUnits(bool includeOwn){ + vector 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 Player::getHostileUnits(){ + vector 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 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 cpuPlayers = Game::getSingleton()->getCpuPlayers(); + + for(int i = 0; i < cpuPlayers.size(); i++) + if(cpuPlayers[i] == this) + return i; + + return -1; + } +} diff --git a/pointDefense.cpp b/Source/Gameplay/Private/pointDefense.cpp similarity index 100% rename from pointDefense.cpp rename to Source/Gameplay/Private/pointDefense.cpp diff --git a/projectile.cpp b/Source/Gameplay/Private/projectile.cpp old mode 100755 new mode 100644 similarity index 96% rename from projectile.cpp rename to Source/Gameplay/Private/projectile.cpp index d76085e..ca321a0 --- a/projectile.cpp +++ b/Source/Gameplay/Private/projectile.cpp @@ -1,131 +1,131 @@ -#include -#include -#include -#include -#include - -#include - -#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 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 players = Game::getSingleton()->getPlayers(true); - vector targetUnits; - vector targetNodes; - - for(Player *pl : players){ - vector units = pl->getUnits(); - - for(Unit *u : units) - if(unit && unit != u){ - targetUnits.push_back(u); - targetNodes.push_back(u->getHitbox()); - } - } - - vector 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 &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 +#include +#include +#include +#include + +#include + +#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 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 players = Game::getSingleton()->getPlayers(true); + vector targetUnits; + vector targetNodes; + + for(Player *pl : players){ + vector units = pl->getUnits(); + + for(Unit *u : units) + if(unit && unit != u){ + targetUnits.push_back(u); + targetNodes.push_back(u->getHitbox()); + } + } + + vector 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 &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(){ + } +} diff --git a/researchStruct.cpp b/Source/Gameplay/Private/researchStruct.cpp similarity index 100% rename from researchStruct.cpp rename to Source/Gameplay/Private/researchStruct.cpp diff --git a/resourceDeposit.cpp b/Source/Gameplay/Private/resourceDeposit.cpp similarity index 100% rename from resourceDeposit.cpp rename to Source/Gameplay/Private/resourceDeposit.cpp diff --git a/resourceRover.cpp b/Source/Gameplay/Private/resourceRover.cpp similarity index 100% rename from resourceRover.cpp rename to Source/Gameplay/Private/resourceRover.cpp diff --git a/shell.cpp b/Source/Gameplay/Private/shell.cpp similarity index 100% rename from shell.cpp rename to Source/Gameplay/Private/shell.cpp diff --git a/structure.cpp b/Source/Gameplay/Private/structure.cpp similarity index 100% rename from structure.cpp rename to Source/Gameplay/Private/structure.cpp diff --git a/submarine.cpp b/Source/Gameplay/Private/submarine.cpp similarity index 100% rename from submarine.cpp rename to Source/Gameplay/Private/submarine.cpp diff --git a/torpedo.cpp b/Source/Gameplay/Private/torpedo.cpp similarity index 100% rename from torpedo.cpp rename to Source/Gameplay/Private/torpedo.cpp diff --git a/tradeCenter.cpp b/Source/Gameplay/Private/tradeCenter.cpp similarity index 100% rename from tradeCenter.cpp rename to Source/Gameplay/Private/tradeCenter.cpp diff --git a/trader.cpp b/Source/Gameplay/Private/trader.cpp similarity index 100% rename from trader.cpp rename to Source/Gameplay/Private/trader.cpp diff --git a/unit.cpp b/Source/Gameplay/Private/unit.cpp old mode 100755 new mode 100644 similarity index 96% rename from unit.cpp rename to Source/Gameplay/Private/unit.cpp index 70e4537..98f337a --- a/unit.cpp +++ b/Source/Gameplay/Private/unit.cpp @@ -1,582 +1,582 @@ -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include - -#include "unit.h" -#include "weapon.h" -#include "util.h" -#include "game.h" -#include "map.h" -#include "vehicle.h" -#include "destructable.h" -#include "gameObjectFactory.h" -#include "activeGameState.h" -#include "gameManager.h" -#include "projectile.h" -#include "defConfigs.h" -#include "pathfinder.h" -#include "ability.h" - -using namespace glm; -using namespace vb01; -using namespace gameBase; -using namespace std; - -namespace battleship{ - //TODO move restartTime to unitData.lua - Unit::Unit(Player *player, int id, Vector3 pos, Quaternion rot, State st) : - GameObject(GameObject::Type::UNIT, id, player, pos, rot), - state(st), - restartTime(2000) - { - selectable = true; - - destructable = new Destructable(this); - - Unit::initProperties(); - initModel(); - initHitbox(); - initSound(); - initWeapons(); - placeAt(pos); - orientAt(rot); - - Vector2 size = Vector2(lenHpBar, 10); - hpBackgroundNode = destructable->createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); - hpForegroundNode = destructable->createBar(Vector2::VEC_ZERO, size, Vector4(0, 1, 0, 1)); - } - - Unit::~Unit() { - Map::getSingleton()->unblockCells(this); - destructable->removeBar(hpBackgroundNode); - destructable->removeBar(hpForegroundNode); - destroyWeapons(); - destroySound(); - destroyHitbox(); - destroyModel(); - } - - void Unit::initProperties(){ - GameObject::initProperties(); - - sol::state_view SOL_LUA_VIEW = generateView(); - string objType = GameObject::getGameObjTableName(); - sol::table unitTable = SOL_LUA_VIEW[objType][id + 1]; - - Game *game = Game::getSingleton(); - vector currTechs = player->getTechnologies(); - - string name = unitTable["name"]; - alignToSurface = unitTable["alignToSurface"].get_or(false); - vehicle = unitTable["isVehicle"]; - - lineOfSight = unitTable["lineOfSight"]; lineOfSight += game->calcAbilFromTech(Ability::Type::LINE_OF_SIGHT, currTechs, (int)GameObject::type, id); - unitClass = (UnitClass)unitTable["unitClass"]; - type = (UnitType)unitTable["unitType"]; - - guiScreen = ""; - string gsk = "guiScreen"; - sol::optional nameOpt = unitTable[gsk]; - - if(nameOpt != sol::nullopt) guiScreen = unitTable[gsk]; - - string tblName = "garrisonCapacity"; - sol::optional gc = unitTable[tblName]; - - if(gc != sol::nullopt){ - string varName = "numGarrisonSlots"; - SOL_LUA_VIEW.script(varName + " = #" + objType + "[" + to_string(id + 1) + "]." + tblName); - int numGarrisonSlots = SOL_LUA_VIEW[varName]; - - for(int i = 0; i < numGarrisonSlots; i++){ - Vector2 size = 10 * Vector2::VEC_IJ; - Vector2 pos = Vector2(1.5 * size.x * i, 20); - Node *bg = destructable->createBar(pos, size, Vector4(0, 0, 0, 1)); - Node *fg = destructable->createBar(pos, size, Vector4(0, 1, 0, 1)); - int category = unitTable[tblName][i + 1]; - garrisonSlots.push_back(GarrisonSlot(bg, fg, pos, category)); - } - } - - tblName = "buildableUnits"; - sol::optional bu = unitTable[tblName]; - - if(bu != sol::nullopt){ - SOL_LUA_VIEW.script("numBuildableUnits = #units[" + to_string(id + 1) + "]." + tblName); - int numBuildableUnits = SOL_LUA_VIEW["numBuildableUnits"]; - - for(int i = 0; i < numBuildableUnits; i++){ - sol::table buTable = unitTable[tblName][i + 1]; - buildableUnits.push_back(BuildableUnit(buTable["id"], game->isUnitUnlocked(currTechs, id) | (bool)buTable["buildable"])); - } - } - } - - void Unit::initWeapons(){ - sol::state_view SOL_STATE_VIEW = generateView(); - string objType = GameObject::getGameObjTableName(); - sol::table unitTable = SOL_STATE_VIEW[objType][id + 1]; - - string tblName = "weapons"; - sol::optional weaponsTblOpt = unitTable[tblName]; - - if(weaponsTblOpt != sol::nullopt){ - string varName = "numWeapons"; - SOL_STATE_VIEW.script(varName + " = #" + objType + "[" + to_string(id + 1) + "]." + tblName); - int numWeapons = SOL_STATE_VIEW[varName]; - - for(int i = 0; i < numWeapons; i++){ - int wt = 0; - sol::optional wtOpt = unitTable[tblName][i + 1]["type"]; - - if(wtOpt != sol::nullopt) wt = unitTable[tblName][i + 1]["type"]; - - weapons.push_back(new Weapon(this, unitTable, i)); - } - } - } - - void Unit::destroyWeapons(){ - for(Weapon *weapon : weapons) - delete weapon; - - weapons.clear(); - } - - void Unit::initLosLight(){ - Light *light = new Light(Light::Type::POINT); - light->setAttenuation(Light::Attenuation::NONE); - light->setRadius(lineOfSight); - light->setColor(Vector3::VEC_IJK * .3); - light->setAdditiveLighting(false); - light->setUseAngle(false); - - losLightNode = new Node(Vector3::VEC_J * 5); - //losLightNode->addLight(light); - model->attachChild(losLightNode); - } - - void Unit::destroyLosLight(){ - model->dettachChild(losLightNode); - delete losLightNode; - losLightNode = nullptr; - } - - int Unit::getNumFreeGarrisonSlots(){ - int numFreeSlots = 0; - - for(GarrisonSlot &slot : garrisonSlots) - if(!slot.vehicle) numFreeSlots++; - - return numFreeSlots; - } - - void Unit::destroySound(){ - selectionSfx->stop(); - delete selectionSfx; - delete selectionSfxBuffer; - } - - //TODO factor out initSound() - void Unit::initSound(){ - GameObject::initSound(); - selectionSfxBuffer = new sf::SoundBuffer(); - string sfxPath = generateView()[getGameObjTableName()][id + 1]["selectionSfx"]; - selectionSfx = GameObject::prepareSfx(selectionSfxBuffer, sfxPath); - } - - void Unit::reinit(){ - if(losLightNode) - destroyLosLight(); - - destroyWeapons(); - destroyHitbox(); - destroyModel(); - destroySound(); - - Unit::initProperties(); - - initModel(); - initHitbox(); - initSound(); - initWeapons(); - - GameObject::reinit(); - } - - bool Unit::canGarrison(Vehicle *vehicle){ - for(int i = 0; i < garrisonSlots.size(); i++) - if(!garrisonSlots[i].vehicle && garrisonSlots[i].category >= vehicle->getGarrisonCategory()) - return true; - - return false; - } - - void Unit::launch(Order order){ - getWeaponsByOrder(Order::TYPE::LAUNCH)[0]->fire(order); - removeOrder(0); - } - - float Unit::calculateRotation(Vector3 dir, float angle, float maxTurnAngle){ - float rotSpeed = (maxTurnAngle > angle ? angle : maxTurnAngle); - - if(isTargetToTheRight(dir, leftVec)) - rotSpeed *= -1; - - return rotSpeed; - } - - void Unit::renderOrderLine(bool mainPlayerSelecting){ - if (!orders.empty() && orders[0].lineId != -1 && mainPlayerSelecting){ - bool display = canDisplayOrderLine(); - LineRenderer *lineRenderer = LineRenderer::getSingleton(); - lineRenderer->toggleVisibility(orders[0].lineId, display); - - if(display){ - lineRenderer->changeLineField(orders[0].lineId, pos, LineRenderer::START); - Vector3 targPos = (orders[0].targets[0].unit ? orders[0].targets[0].unit->getPos() : orders[0].targets[0].pos); - lineRenderer->changeLineField(orders[0].lineId, targPos, LineRenderer::END); - } - } - } - - //TODO clean up method code - void Unit::autoAttackTargets(){ - if(!orders.empty()) return; - - vector players = Game::getSingleton()->getPlayers(); - vector targets; - - for(Player *pl : players) - if(!(pl == player || pl->getTeam() == player->getTeam())){ - vector targs = pl->getDestructables(); - targets.insert(targets.end(), targs.begin(), targs.end()); - } - - for(GameObject *targ : targets) - if(targ->getPos().getDistanceFrom(pos) < lineOfSight){ - receiveOrder(Order(Order::TYPE::ATTACK, vector{Order::Target(targ)}, Vector3::VEC_ZERO, -1, false), false); - break; - } - } - - void Unit::update() { - GameObject::update(); - destructable->update(); - - if(condition == Condition::EM_JAMMED && getTime() - lastJamTime > restartTime) - condition = Condition::ABLE; - - if(destructable->getFreezeStatus() >= 100) condition = Condition::FROZEN; - - if(state != State::HOLD_FIRE) - autoAttackTargets(); - - ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); - Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr); - vector selectingPlayers = getSelectingPlayers(); - bool mainPlayerSelecting = (find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); - bool mainPlayerOwner = (player == mainPlayer); - bool renderSelectables = (mainPlayerSelecting && mainPlayerOwner); - renderOrderLine(renderSelectables); - - executeOrders(); - destructable->displayStats(hpForegroundNode, hpBackgroundNode, destructable->getHealth(), destructable->getMaxHealth(), mainPlayerSelecting); - - for(GarrisonSlot &slot : garrisonSlots) - destructable->displayStats(slot.foreground, slot.background, (int)((bool)slot.vehicle), (int)true, renderSelectables, slot.offset); - - for(Weapon *weapon : weapons) - weapon->update(); - } - - //TODO remove order argument from action methods - void Unit::executeOrders() { - if(orders.empty() || condition != Condition::ABLE) return; - - if(!currOrderStarted) startCurrentOrder(); - - if(!orders[0].targets.empty() && orders[0].targets[0].unit){ - vector units; - - for(Player *pl : Game::getSingleton()->getPlayers(true)){ - vector us = pl->getUnits(); - units.insert(units.end(), us.begin(), us.end()); - } - - if(find(units.begin(), units.end(), orders[0].targets[0].unit) == units.end()){ - removeOrder(0); - return; - } - } - - switch (orders[0].type) { - case Order::TYPE::ATTACK: - attack(orders[0]); - break; - case Order::TYPE::BUILD: - build(orders[0]); - break; - case Order::TYPE::MOVE: - move(orders[0]); - break; - case Order::TYPE::GARRISON: - garrison(orders[0]); - break; - case Order::TYPE::EJECT: - eject(orders[0]); - break; - case Order::TYPE::PATROL: - patrol(orders[0]); - break; - case Order::TYPE::LAUNCH: - launch(orders[0]); - break; - break; - case Order::TYPE::LOAD: - case Order::TYPE::SUPPLY: - case Order::TYPE::UNLOAD: - handleResources(orders[0]); - break; - case Order::TYPE::HACK: - hack(orders[0]); - break; - default: - break; - } - } - - void Unit::eject(Order order){ - Map *map = Map::getSingleton(); - int currCellId = map->getCellId(pos); - vector &cells = map->getCells(); - int adjWaterCellId = -1, adjLandCellId = -1; - - for(Map::Edge edge : cells[currCellId].edges){ - if(adjLandCellId == -1 && cells[edge.destCellId].type == Map::Cell::LAND) - adjLandCellId = edge.destCellId; - if(adjWaterCellId == -1 && cells[edge.destCellId].type == Map::Cell::WATER) - adjWaterCellId = edge.destCellId; - } - - for(GarrisonSlot &slot : garrisonSlots) - if(slot.vehicle){ - bool exitToLandCell = (slot.vehicle->getType() == UnitType::LAND && adjLandCellId != -1); - bool exitToWaterCell = ((slot.vehicle->getType() == UnitType::SEA_LEVEL || slot.vehicle->getType() == UnitType::UNDERWATER) && adjWaterCellId != -1); - - if(exitToLandCell || exitToWaterCell) - slot.vehicle->exitGarrisonable(cells[exitToLandCell ? adjLandCellId : adjWaterCellId].pos); - } - - removeOrder(0); - } - - void Unit::attack(Order order){ - vector targets; - - for(Player *pl : Game::getSingleton()->getPlayers()){ - vector targs = pl->getDestructables(); - targets.insert(targets.end(), targs.begin(), targs.end()); - } - - vector attackWeapons = getWeaponsByOrder(Order::TYPE::ATTACK); - - for(Order::Target &target : orders[0].targets) - if(target.unit){ - if(find(targets.begin(), targets.end(), target.unit) != targets.end()){ - bool canAttack = false; - - for(Weapon *aw : attackWeapons){ - int tc; - - switch(target.unit->getType()){ - case GameObject::Type::UNIT: - tc = (int)((Unit*)target.unit)->getType(); - break; - case GameObject::Type::PROJECTILE: - tc = (int)((Projectile*)target.unit)->getProjectileClass(); - break; - } - - if(aw->canAttackTarget((int)target.unit->getType(), tc)) canAttack = true; - } - - if(!canAttack){ - removeOrder(0); - return; - } - } - else{ - removeOrder(0); - return; - } - } - - Vector3 targPos = (order.targets[0].unit ? order.targets[0].unit->getPos() : order.targets[0].pos); - - for(Weapon *weapon : attackWeapons) - weapon->trackTarget(targPos); - } - - bool Unit::validateOrder(Order order){ - switch (order.type) { - case Order::TYPE::ATTACK:{ - GameObject *target = order.targets[0].unit; - bool destructTarg = (!target || (target && target->getDestructable())); - return destructTarg && !getWeaponsByOrder(Order::TYPE::ATTACK).empty(); - } - case Order::TYPE::BUILD: - return (unitClass == UnitClass::ROBO_ENGINEER || unitClass == UnitClass::CYBORG_ENGINEER || unitClass == UnitClass::FREEZER); - case Order::TYPE::PATROL: - case Order::TYPE::MOVE: - return vehicle; - case Order::TYPE::GARRISON: - return validateGarrisonOrder(order); - case Order::TYPE::EJECT: - return !garrisonSlots.empty(); - case Order::TYPE::LAUNCH: - return validateLaunchOrder(); - case Order::TYPE::SUPPLY: - case Order::TYPE::LOAD: - case Order::TYPE::UNLOAD: - return unitClass == UnitClass::RESOURCE_ROVER; - case Order::TYPE::HACK: - return !getWeaponsByOrder(Order::TYPE::HACK).empty(); - default: - return false; - } - } - - vector Unit::getWeaponsByOrder(Order::TYPE type){ - vector weaps; - - for(Weapon *w : weapons) - if(w->getOrderType() == type) - weaps.push_back(w); - - return weaps; - } - - vector Unit::getWeaponsByType(int type){ - vector weaps; - - for(Weapon *w : weapons) - if(w->getType() == (Weapon::Type)type) - weaps.push_back(w); - - return weaps; - } - - void Unit::receiveOrder(Order order, bool add) { - if(!validateOrder(order)) return; - - if(!add){ - while (!orders.empty()) - removeOrder(0); - - orderLineDispTime = getTime(); - } - - orders.push_back(order); - - if(order.type == Order::TYPE::BUILD && order.targets[0].unit) - player->addUnit((Unit*)order.targets[0].unit); - - executeOrders(); - } - - void Unit::halt() { - while (orders.size() > 0) - removeOrder(orders.size() - 1); - } - - void Unit::updateGarrison(Vehicle *garrVeh, bool entering){ - for(GarrisonSlot &slot : garrisonSlots){ - if(entering && !slot.vehicle){ - slot.vehicle = garrVeh; - break; - } - else if(!entering && slot.vehicle == garrVeh){ - slot.vehicle = nullptr; - break; - } - } - } - - //TODO select only the closest cells based on unit size - void Unit::placeAt(Vector3 p){ - Map *map = Map::getSingleton(); - - if(alignToSurface){ - vector res = map->raycastTerrain(Vector3(p.x, 100, p.z), -Vector3::VEC_J, true); - - if(res.empty() || res[0].mesh->getNode() != map->getNodeParent()->getChild(0)) - model->lookAt(Vector3(dirVec.x, 0, dirVec.z).norm(), Vector3::VEC_J); - else if(res[0].mesh->getNode() == map->getNodeParent()->getChild(0)){ - float angle = upVec.getAngleBetween(res[0].norm); - - //if(angle > 0) - model->lookAt(leftVec.cross(res[0].norm), res[0].norm); - } - } - - ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); - - //check twice in case the unit is warped over a long distance - if(activeState) map->blockCells(this); - GameObject::placeAt(p); - - if(activeState){ - map->blockCells(this); - - //if(activeState->getPlayer()) Map::Minimap::getSingleton()->updateImage(); - } - } - - vector Unit::getSelectingPlayers(){ - vector players = Game::getSingleton()->getPlayers(), selectingPlayers; - - for(Player *pl : players){ - int numSelectedUnits = pl->getNumSelectedUnits(); - - for(int i = 0; i < numSelectedUnits; i++) - if(pl->getSelectedUnit(i) == this){ - selectingPlayers.push_back(pl); - break; - } - } - - return selectingPlayers; - } - - void Unit::removeOrder(int id) { - if(orders[id].lineId != -1) - LineRenderer::getSingleton()->removeLine(orders[id].lineId); - - orders.erase(orders.begin() + id); - currOrderStarted = false; - } - - void Unit::select() { - ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); - Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr); - - vector selectingPlayers = getSelectingPlayers(); - bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); - - if(mainPlayer == player && mainPlayerSelecting && selectionSfx) - selectionSfx->play(); - - orderLineDispTime = getTime(); - } -} +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include + +#include "unit.h" +#include "weapon.h" +#include "util.h" +#include "game.h" +#include "map.h" +#include "vehicle.h" +#include "destructable.h" +#include "gameObjectFactory.h" +#include "activeGameState.h" +#include "gameManager.h" +#include "projectile.h" +#include "defConfigs.h" +#include "pathfinder.h" +#include "ability.h" + +using namespace glm; +using namespace vb01; +using namespace gameBase; +using namespace std; + +namespace battleship{ + //TODO move restartTime to unitData.lua + Unit::Unit(Player *player, int id, Vector3 pos, Quaternion rot, State st) : + GameObject(GameObject::Type::UNIT, id, player, pos, rot), + state(st), + restartTime(2000) + { + selectable = true; + + destructable = new Destructable(this); + + Unit::initProperties(); + initModel(); + initHitbox(); + initSound(); + initWeapons(); + placeAt(pos); + orientAt(rot); + + Vector2 size = Vector2(lenHpBar, 10); + hpBackgroundNode = destructable->createBar(Vector2::VEC_ZERO, size, Vector4(0, 0, 0, 1)); + hpForegroundNode = destructable->createBar(Vector2::VEC_ZERO, size, Vector4(0, 1, 0, 1)); + } + + Unit::~Unit() { + Map::getSingleton()->unblockCells(this); + destructable->removeBar(hpBackgroundNode); + destructable->removeBar(hpForegroundNode); + destroyWeapons(); + destroySound(); + destroyHitbox(); + destroyModel(); + } + + void Unit::initProperties(){ + GameObject::initProperties(); + + sol::state_view SOL_LUA_VIEW = generateView(); + string objType = GameObject::getGameObjTableName(); + sol::table unitTable = SOL_LUA_VIEW[objType][id + 1]; + + Game *game = Game::getSingleton(); + vector currTechs = player->getTechnologies(); + + string name = unitTable["name"]; + alignToSurface = unitTable["alignToSurface"].get_or(false); + vehicle = unitTable["isVehicle"]; + + lineOfSight = unitTable["lineOfSight"]; lineOfSight += game->calcAbilFromTech(Ability::Type::LINE_OF_SIGHT, currTechs, (int)GameObject::type, id); + unitClass = (UnitClass)unitTable["unitClass"]; + type = (UnitType)unitTable["unitType"]; + + guiScreen = ""; + string gsk = "guiScreen"; + sol::optional nameOpt = unitTable[gsk]; + + if(nameOpt != sol::nullopt) guiScreen = unitTable[gsk]; + + string tblName = "garrisonCapacity"; + sol::optional gc = unitTable[tblName]; + + if(gc != sol::nullopt){ + string varName = "numGarrisonSlots"; + SOL_LUA_VIEW.script(varName + " = #" + objType + "[" + to_string(id + 1) + "]." + tblName); + int numGarrisonSlots = SOL_LUA_VIEW[varName]; + + for(int i = 0; i < numGarrisonSlots; i++){ + Vector2 size = 10 * Vector2::VEC_IJ; + Vector2 pos = Vector2(1.5 * size.x * i, 20); + Node *bg = destructable->createBar(pos, size, Vector4(0, 0, 0, 1)); + Node *fg = destructable->createBar(pos, size, Vector4(0, 1, 0, 1)); + int category = unitTable[tblName][i + 1]; + garrisonSlots.push_back(GarrisonSlot(bg, fg, pos, category)); + } + } + + tblName = "buildableUnits"; + sol::optional bu = unitTable[tblName]; + + if(bu != sol::nullopt){ + SOL_LUA_VIEW.script("numBuildableUnits = #units[" + to_string(id + 1) + "]." + tblName); + int numBuildableUnits = SOL_LUA_VIEW["numBuildableUnits"]; + + for(int i = 0; i < numBuildableUnits; i++){ + sol::table buTable = unitTable[tblName][i + 1]; + buildableUnits.push_back(BuildableUnit(buTable["id"], game->isUnitUnlocked(currTechs, id) | (bool)buTable["buildable"])); + } + } + } + + void Unit::initWeapons(){ + sol::state_view SOL_STATE_VIEW = generateView(); + string objType = GameObject::getGameObjTableName(); + sol::table unitTable = SOL_STATE_VIEW[objType][id + 1]; + + string tblName = "weapons"; + sol::optional weaponsTblOpt = unitTable[tblName]; + + if(weaponsTblOpt != sol::nullopt){ + string varName = "numWeapons"; + SOL_STATE_VIEW.script(varName + " = #" + objType + "[" + to_string(id + 1) + "]." + tblName); + int numWeapons = SOL_STATE_VIEW[varName]; + + for(int i = 0; i < numWeapons; i++){ + int wt = 0; + sol::optional wtOpt = unitTable[tblName][i + 1]["type"]; + + if(wtOpt != sol::nullopt) wt = unitTable[tblName][i + 1]["type"]; + + weapons.push_back(new Weapon(this, unitTable, i)); + } + } + } + + void Unit::destroyWeapons(){ + for(Weapon *weapon : weapons) + delete weapon; + + weapons.clear(); + } + + void Unit::initLosLight(){ + Light *light = new Light(Light::Type::POINT); + light->setAttenuation(Light::Attenuation::NONE); + light->setRadius(lineOfSight); + light->setColor(Vector3::VEC_IJK * .3); + light->setAdditiveLighting(false); + light->setUseAngle(false); + + losLightNode = new Node(Vector3::VEC_J * 5); + //losLightNode->addLight(light); + model->attachChild(losLightNode); + } + + void Unit::destroyLosLight(){ + model->dettachChild(losLightNode); + delete losLightNode; + losLightNode = nullptr; + } + + int Unit::getNumFreeGarrisonSlots(){ + int numFreeSlots = 0; + + for(GarrisonSlot &slot : garrisonSlots) + if(!slot.vehicle) numFreeSlots++; + + return numFreeSlots; + } + + void Unit::destroySound(){ + selectionSfx->stop(); + delete selectionSfx; + delete selectionSfxBuffer; + } + + //TODO factor out initSound() + void Unit::initSound(){ + GameObject::initSound(); + selectionSfxBuffer = new sf::SoundBuffer(); + string sfxPath = generateView()[getGameObjTableName()][id + 1]["selectionSfx"]; + selectionSfx = GameObject::prepareSfx(selectionSfxBuffer, sfxPath); + } + + void Unit::reinit(){ + if(losLightNode) + destroyLosLight(); + + destroyWeapons(); + destroyHitbox(); + destroyModel(); + destroySound(); + + Unit::initProperties(); + + initModel(); + initHitbox(); + initSound(); + initWeapons(); + + GameObject::reinit(); + } + + bool Unit::canGarrison(Vehicle *vehicle){ + for(int i = 0; i < garrisonSlots.size(); i++) + if(!garrisonSlots[i].vehicle && garrisonSlots[i].category >= vehicle->getGarrisonCategory()) + return true; + + return false; + } + + void Unit::launch(Order order){ + getWeaponsByOrder(Order::TYPE::LAUNCH)[0]->fire(order); + removeOrder(0); + } + + float Unit::calculateRotation(Vector3 dir, float angle, float maxTurnAngle){ + float rotSpeed = (maxTurnAngle > angle ? angle : maxTurnAngle); + + if(isTargetToTheRight(dir, leftVec)) + rotSpeed *= -1; + + return rotSpeed; + } + + void Unit::renderOrderLine(bool mainPlayerSelecting){ + if (!orders.empty() && orders[0].lineId != -1 && mainPlayerSelecting){ + bool display = canDisplayOrderLine(); + LineRenderer *lineRenderer = LineRenderer::getSingleton(); + lineRenderer->toggleVisibility(orders[0].lineId, display); + + if(display){ + lineRenderer->changeLineField(orders[0].lineId, pos, LineRenderer::START); + Vector3 targPos = (orders[0].targets[0].unit ? orders[0].targets[0].unit->getPos() : orders[0].targets[0].pos); + lineRenderer->changeLineField(orders[0].lineId, targPos, LineRenderer::END); + } + } + } + + //TODO clean up method code + void Unit::autoAttackTargets(){ + if(!orders.empty()) return; + + vector players = Game::getSingleton()->getPlayers(); + vector targets; + + for(Player *pl : players) + if(!(pl == player || pl->getTeam() == player->getTeam())){ + vector targs = pl->getDestructables(); + targets.insert(targets.end(), targs.begin(), targs.end()); + } + + for(GameObject *targ : targets) + if(targ->getPos().getDistanceFrom(pos) < lineOfSight){ + receiveOrder(Order(Order::TYPE::ATTACK, vector{Order::Target(targ)}, Vector3::VEC_ZERO, -1, false), false); + break; + } + } + + void Unit::update() { + GameObject::update(); + destructable->update(); + + if(condition == Condition::EM_JAMMED && getTime() - lastJamTime > restartTime) + condition = Condition::ABLE; + + if(destructable->getFreezeStatus() >= 100) condition = Condition::FROZEN; + + if(state != State::HOLD_FIRE) + autoAttackTargets(); + + ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); + Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr); + vector selectingPlayers = getSelectingPlayers(); + bool mainPlayerSelecting = (find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); + bool mainPlayerOwner = (player == mainPlayer); + bool renderSelectables = (mainPlayerSelecting && mainPlayerOwner); + renderOrderLine(renderSelectables); + + executeOrders(); + destructable->displayStats(hpForegroundNode, hpBackgroundNode, destructable->getHealth(), destructable->getMaxHealth(), mainPlayerSelecting); + + for(GarrisonSlot &slot : garrisonSlots) + destructable->displayStats(slot.foreground, slot.background, (int)((bool)slot.vehicle), (int)true, renderSelectables, slot.offset); + + for(Weapon *weapon : weapons) + weapon->update(); + } + + //TODO remove order argument from action methods + void Unit::executeOrders() { + if(orders.empty() || condition != Condition::ABLE) return; + + if(!currOrderStarted) startCurrentOrder(); + + if(!orders[0].targets.empty() && orders[0].targets[0].unit){ + vector units; + + for(Player *pl : Game::getSingleton()->getPlayers(true)){ + vector us = pl->getUnits(); + units.insert(units.end(), us.begin(), us.end()); + } + + if(find(units.begin(), units.end(), orders[0].targets[0].unit) == units.end()){ + removeOrder(0); + return; + } + } + + switch (orders[0].type) { + case Order::TYPE::ATTACK: + attack(orders[0]); + break; + case Order::TYPE::BUILD: + build(orders[0]); + break; + case Order::TYPE::MOVE: + move(orders[0]); + break; + case Order::TYPE::GARRISON: + garrison(orders[0]); + break; + case Order::TYPE::EJECT: + eject(orders[0]); + break; + case Order::TYPE::PATROL: + patrol(orders[0]); + break; + case Order::TYPE::LAUNCH: + launch(orders[0]); + break; + break; + case Order::TYPE::LOAD: + case Order::TYPE::SUPPLY: + case Order::TYPE::UNLOAD: + handleResources(orders[0]); + break; + case Order::TYPE::HACK: + hack(orders[0]); + break; + default: + break; + } + } + + void Unit::eject(Order order){ + Map *map = Map::getSingleton(); + int currCellId = map->getCellId(pos); + vector &cells = map->getCells(); + int adjWaterCellId = -1, adjLandCellId = -1; + + for(Map::Edge edge : cells[currCellId].edges){ + if(adjLandCellId == -1 && cells[edge.destCellId].type == Map::Cell::LAND) + adjLandCellId = edge.destCellId; + if(adjWaterCellId == -1 && cells[edge.destCellId].type == Map::Cell::WATER) + adjWaterCellId = edge.destCellId; + } + + for(GarrisonSlot &slot : garrisonSlots) + if(slot.vehicle){ + bool exitToLandCell = (slot.vehicle->getType() == UnitType::LAND && adjLandCellId != -1); + bool exitToWaterCell = ((slot.vehicle->getType() == UnitType::SEA_LEVEL || slot.vehicle->getType() == UnitType::UNDERWATER) && adjWaterCellId != -1); + + if(exitToLandCell || exitToWaterCell) + slot.vehicle->exitGarrisonable(cells[exitToLandCell ? adjLandCellId : adjWaterCellId].pos); + } + + removeOrder(0); + } + + void Unit::attack(Order order){ + vector targets; + + for(Player *pl : Game::getSingleton()->getPlayers()){ + vector targs = pl->getDestructables(); + targets.insert(targets.end(), targs.begin(), targs.end()); + } + + vector attackWeapons = getWeaponsByOrder(Order::TYPE::ATTACK); + + for(Order::Target &target : orders[0].targets) + if(target.unit){ + if(find(targets.begin(), targets.end(), target.unit) != targets.end()){ + bool canAttack = false; + + for(Weapon *aw : attackWeapons){ + int tc; + + switch(target.unit->getType()){ + case GameObject::Type::UNIT: + tc = (int)((Unit*)target.unit)->getType(); + break; + case GameObject::Type::PROJECTILE: + tc = (int)((Projectile*)target.unit)->getProjectileClass(); + break; + } + + if(aw->canAttackTarget((int)target.unit->getType(), tc)) canAttack = true; + } + + if(!canAttack){ + removeOrder(0); + return; + } + } + else{ + removeOrder(0); + return; + } + } + + Vector3 targPos = (order.targets[0].unit ? order.targets[0].unit->getPos() : order.targets[0].pos); + + for(Weapon *weapon : attackWeapons) + weapon->trackTarget(targPos); + } + + bool Unit::validateOrder(Order order){ + switch (order.type) { + case Order::TYPE::ATTACK:{ + GameObject *target = order.targets[0].unit; + bool destructTarg = (!target || (target && target->getDestructable())); + return destructTarg && !getWeaponsByOrder(Order::TYPE::ATTACK).empty(); + } + case Order::TYPE::BUILD: + return (unitClass == UnitClass::ROBO_ENGINEER || unitClass == UnitClass::CYBORG_ENGINEER || unitClass == UnitClass::FREEZER); + case Order::TYPE::PATROL: + case Order::TYPE::MOVE: + return vehicle; + case Order::TYPE::GARRISON: + return validateGarrisonOrder(order); + case Order::TYPE::EJECT: + return !garrisonSlots.empty(); + case Order::TYPE::LAUNCH: + return validateLaunchOrder(); + case Order::TYPE::SUPPLY: + case Order::TYPE::LOAD: + case Order::TYPE::UNLOAD: + return unitClass == UnitClass::RESOURCE_ROVER; + case Order::TYPE::HACK: + return !getWeaponsByOrder(Order::TYPE::HACK).empty(); + default: + return false; + } + } + + vector Unit::getWeaponsByOrder(Order::TYPE type){ + vector weaps; + + for(Weapon *w : weapons) + if(w->getOrderType() == type) + weaps.push_back(w); + + return weaps; + } + + vector Unit::getWeaponsByType(int type){ + vector weaps; + + for(Weapon *w : weapons) + if(w->getType() == (Weapon::Type)type) + weaps.push_back(w); + + return weaps; + } + + void Unit::receiveOrder(Order order, bool add) { + if(!validateOrder(order)) return; + + if(!add){ + while (!orders.empty()) + removeOrder(0); + + orderLineDispTime = getTime(); + } + + orders.push_back(order); + + if(order.type == Order::TYPE::BUILD && order.targets[0].unit) + player->addUnit((Unit*)order.targets[0].unit); + + executeOrders(); + } + + void Unit::halt() { + while (orders.size() > 0) + removeOrder(orders.size() - 1); + } + + void Unit::updateGarrison(Vehicle *garrVeh, bool entering){ + for(GarrisonSlot &slot : garrisonSlots){ + if(entering && !slot.vehicle){ + slot.vehicle = garrVeh; + break; + } + else if(!entering && slot.vehicle == garrVeh){ + slot.vehicle = nullptr; + break; + } + } + } + + //TODO select only the closest cells based on unit size + void Unit::placeAt(Vector3 p){ + Map *map = Map::getSingleton(); + + if(alignToSurface){ + vector res = map->raycastTerrain(Vector3(p.x, 100, p.z), -Vector3::VEC_J, true); + + if(res.empty() || res[0].mesh->getNode() != map->getNodeParent()->getChild(0)) + model->lookAt(Vector3(dirVec.x, 0, dirVec.z).norm(), Vector3::VEC_J); + else if(res[0].mesh->getNode() == map->getNodeParent()->getChild(0)){ + float angle = upVec.getAngleBetween(res[0].norm); + + //if(angle > 0) + model->lookAt(leftVec.cross(res[0].norm), res[0].norm); + } + } + + ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); + + //check twice in case the unit is warped over a long distance + if(activeState) map->blockCells(this); + GameObject::placeAt(p); + + if(activeState){ + map->blockCells(this); + + //if(activeState->getPlayer()) Map::Minimap::getSingleton()->updateImage(); + } + } + + vector Unit::getSelectingPlayers(){ + vector players = Game::getSingleton()->getPlayers(), selectingPlayers; + + for(Player *pl : players){ + int numSelectedUnits = pl->getNumSelectedUnits(); + + for(int i = 0; i < numSelectedUnits; i++) + if(pl->getSelectedUnit(i) == this){ + selectingPlayers.push_back(pl); + break; + } + } + + return selectingPlayers; + } + + void Unit::removeOrder(int id) { + if(orders[id].lineId != -1) + LineRenderer::getSingleton()->removeLine(orders[id].lineId); + + orders.erase(orders.begin() + id); + currOrderStarted = false; + } + + void Unit::select() { + ActiveGameState *activeState = (ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE); + Player *mainPlayer = (activeState ? activeState->getPlayer() : nullptr); + + vector selectingPlayers = getSelectingPlayers(); + bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end()); + + if(mainPlayer == player && mainPlayerSelecting && selectionSfx) + selectionSfx->play(); + + orderLineDispTime = getTime(); + } +} diff --git a/vehicle.cpp b/Source/Gameplay/Private/vehicle.cpp similarity index 100% rename from vehicle.cpp rename to Source/Gameplay/Private/vehicle.cpp diff --git a/vessel.cpp b/Source/Gameplay/Private/vessel.cpp old mode 100755 new mode 100644 similarity index 100% rename from vessel.cpp rename to Source/Gameplay/Private/vessel.cpp diff --git a/weapon.cpp b/Source/Gameplay/Private/weapon.cpp similarity index 100% rename from weapon.cpp rename to Source/Gameplay/Private/weapon.cpp diff --git a/ability.h b/Source/Gameplay/Public/ability.h similarity index 100% rename from ability.h rename to Source/Gameplay/Public/ability.h diff --git a/buildableUnit.h b/Source/Gameplay/Public/buildableUnit.h similarity index 100% rename from buildableUnit.h rename to Source/Gameplay/Public/buildableUnit.h diff --git a/cruiseMissile.h b/Source/Gameplay/Public/cruiseMissile.h similarity index 100% rename from cruiseMissile.h rename to Source/Gameplay/Public/cruiseMissile.h diff --git a/depthCharge.h b/Source/Gameplay/Public/depthCharge.h similarity index 100% rename from depthCharge.h rename to Source/Gameplay/Public/depthCharge.h diff --git a/destructable.h b/Source/Gameplay/Public/destructable.h similarity index 100% rename from destructable.h rename to Source/Gameplay/Public/destructable.h diff --git a/engineer.h b/Source/Gameplay/Public/engineer.h similarity index 100% rename from engineer.h rename to Source/Gameplay/Public/engineer.h diff --git a/environment.h b/Source/Gameplay/Public/environment.h similarity index 100% rename from environment.h rename to Source/Gameplay/Public/environment.h diff --git a/explosion.h b/Source/Gameplay/Public/explosion.h similarity index 100% rename from explosion.h rename to Source/Gameplay/Public/explosion.h diff --git a/extractor.h b/Source/Gameplay/Public/extractor.h similarity index 100% rename from extractor.h rename to Source/Gameplay/Public/extractor.h diff --git a/factory.h b/Source/Gameplay/Public/factory.h similarity index 100% rename from factory.h rename to Source/Gameplay/Public/factory.h diff --git a/freezer.h b/Source/Gameplay/Public/freezer.h similarity index 100% rename from freezer.h rename to Source/Gameplay/Public/freezer.h diff --git a/fxManager.h b/Source/Gameplay/Public/fxManager.h similarity index 100% rename from fxManager.h rename to Source/Gameplay/Public/fxManager.h diff --git a/game.h b/Source/Gameplay/Public/game.h similarity index 100% rename from game.h rename to Source/Gameplay/Public/game.h diff --git a/gameManager.h b/Source/Gameplay/Public/gameManager.h old mode 100755 new mode 100644 similarity index 96% rename from gameManager.h rename to Source/Gameplay/Public/gameManager.h index 99e93cb..471abca --- a/gameManager.h +++ b/Source/Gameplay/Public/gameManager.h @@ -1,46 +1,46 @@ -#pragma once -#ifndef GAME_MANAGER_H -#define GAME_MANAGER_H - -#include "util.h" - -#include - -#include -#include - -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 + +#include +#include + +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 diff --git a/gameObject.h b/Source/Gameplay/Public/gameObject.h similarity index 100% rename from gameObject.h rename to Source/Gameplay/Public/gameObject.h diff --git a/gameObjectFactory.h b/Source/Gameplay/Public/gameObjectFactory.h similarity index 100% rename from gameObjectFactory.h rename to Source/Gameplay/Public/gameObjectFactory.h diff --git a/garrisonable.h b/Source/Gameplay/Public/garrisonable.h similarity index 100% rename from garrisonable.h rename to Source/Gameplay/Public/garrisonable.h diff --git a/iceSheet.h b/Source/Gameplay/Public/iceSheet.h similarity index 100% rename from iceSheet.h rename to Source/Gameplay/Public/iceSheet.h diff --git a/map.h b/Source/Gameplay/Public/map.h old mode 100755 new mode 100644 similarity index 96% rename from map.h rename to Source/Gameplay/Public/map.h index c9d0b4a..63d7f31 --- a/map.h +++ b/Source/Gameplay/Public/map.h @@ -1,128 +1,128 @@ -#ifndef MAP_H -#define MAP_H - -#include -#include - -#include -#include -#include - -#include - -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 edges; - Unit *blockedBy = nullptr; - std::vector underWaterCellIds; - - Cell(){} - Cell(vb01::Vector3 p, Type t, std::vector e = std::vector{}, std::vector uc = std::vector{}): 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 depositIcons; - vb01::Node* camIcon = nullptr; - }; - - static Map* getSingleton(); - ~Map(){} - static std::vector generateAdjacentNodeEdges(int, int, int, int, int); - void update(); - void load(std::string); - void create(std::string, vb01::Vector3); - void unload(); - std::vector 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 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& getCells(){return cells;} - inline vb01::Node* getLight(int i){return lights[i];} - inline std::vector 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 spawnPoints; - std::vector cells; - float baseHeight; - std::vector 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 int bsearch(std::vector, T, float); - }; -} -#endif +#ifndef MAP_H +#define MAP_H + +#include +#include + +#include +#include +#include + +#include + +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 edges; + Unit *blockedBy = nullptr; + std::vector underWaterCellIds; + + Cell(){} + Cell(vb01::Vector3 p, Type t, std::vector e = std::vector{}, std::vector uc = std::vector{}): 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 depositIcons; + vb01::Node* camIcon = nullptr; + }; + + static Map* getSingleton(); + ~Map(){} + static std::vector generateAdjacentNodeEdges(int, int, int, int, int); + void update(); + void load(std::string); + void create(std::string, vb01::Vector3); + void unload(); + std::vector 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 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& getCells(){return cells;} + inline vb01::Node* getLight(int i){return lights[i];} + inline std::vector 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 spawnPoints; + std::vector cells; + float baseHeight; + std::vector 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 int bsearch(std::vector, T, float); + }; +} +#endif diff --git a/missile.h b/Source/Gameplay/Public/missile.h similarity index 100% rename from missile.h rename to Source/Gameplay/Public/missile.h diff --git a/player.h b/Source/Gameplay/Public/player.h old mode 100755 new mode 100644 similarity index 97% rename from player.h rename to Source/Gameplay/Public/player.h index 13afc78..b7e6891 --- a/player.h +++ b/Source/Gameplay/Public/player.h @@ -1,118 +1,118 @@ -#ifndef PLAYER_H -#define PLAYER_H - -#include -#include - -#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, bool); - void removeUnit(Unit*); - void removeUnit(int); - void removeResourceDeposit(int); - void removeProjectile(int); - void removeProjectile(Projectile*); - bool isThisPlayersUnit(GameObject*); - void selectUnits(std::vector); - std::vector getUnitsById(int, int = -1); - std::vector 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 getTradeOffers(Player*); - void deselectUnit(Unit*); - std::vector getDestructables(); - void updateGameStats(Unit*); - std::vector getFriendlyUnits(bool = true); - std::vector getHostileUnits(); - bool isObjectVisible(GameObject*, std::vector); - 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 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{u});} - inline void addUnit(Unit *u){units.push_back(u);} - inline std::vector& 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& getProjectiles(){return projectiles;} - inline Unit* getUnit(int i){return units[i];} - inline std::vector& 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 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 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 units, selectedUnits; - std::vector projectiles; - std::vector resourceDeposits; - vb01::Vector3 color; - vb01::Material *colorMaterial = nullptr; - std::vector>> tradeOffers; - std::vector>> tradedResources; - - int getOrderLineId(Order::TYPE, vb01::Vector3, vb01::Vector3); - void initTradingVecs(); - }; -} - -#endif +#ifndef PLAYER_H +#define PLAYER_H + +#include +#include + +#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, bool); + void removeUnit(Unit*); + void removeUnit(int); + void removeResourceDeposit(int); + void removeProjectile(int); + void removeProjectile(Projectile*); + bool isThisPlayersUnit(GameObject*); + void selectUnits(std::vector); + std::vector getUnitsById(int, int = -1); + std::vector 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 getTradeOffers(Player*); + void deselectUnit(Unit*); + std::vector getDestructables(); + void updateGameStats(Unit*); + std::vector getFriendlyUnits(bool = true); + std::vector getHostileUnits(); + bool isObjectVisible(GameObject*, std::vector); + 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 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{u});} + inline void addUnit(Unit *u){units.push_back(u);} + inline std::vector& 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& getProjectiles(){return projectiles;} + inline Unit* getUnit(int i){return units[i];} + inline std::vector& 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 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 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 units, selectedUnits; + std::vector projectiles; + std::vector resourceDeposits; + vb01::Vector3 color; + vb01::Material *colorMaterial = nullptr; + std::vector>> tradeOffers; + std::vector>> tradedResources; + + int getOrderLineId(Order::TYPE, vb01::Vector3, vb01::Vector3); + void initTradingVecs(); + }; +} + +#endif diff --git a/pointDefense.h b/Source/Gameplay/Public/pointDefense.h similarity index 100% rename from pointDefense.h rename to Source/Gameplay/Public/pointDefense.h diff --git a/projectile.h b/Source/Gameplay/Public/projectile.h old mode 100755 new mode 100644 similarity index 96% rename from projectile.h rename to Source/Gameplay/Public/projectile.h index bb81c9a..96cc0f8 --- a/projectile.h +++ b/Source/Gameplay/Public/projectile.h @@ -1,44 +1,44 @@ -#ifndef PROJECTILE_H -#define PROJECTILE_H - -#include "gameObject.h" -#include "fxManager.h" - -#include - -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 + +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 diff --git a/researchStruct.h b/Source/Gameplay/Public/researchStruct.h similarity index 100% rename from researchStruct.h rename to Source/Gameplay/Public/researchStruct.h diff --git a/resourceDeposit.h b/Source/Gameplay/Public/resourceDeposit.h similarity index 100% rename from resourceDeposit.h rename to Source/Gameplay/Public/resourceDeposit.h diff --git a/resourceRover.h b/Source/Gameplay/Public/resourceRover.h similarity index 100% rename from resourceRover.h rename to Source/Gameplay/Public/resourceRover.h diff --git a/shell.h b/Source/Gameplay/Public/shell.h similarity index 100% rename from shell.h rename to Source/Gameplay/Public/shell.h diff --git a/structure.h b/Source/Gameplay/Public/structure.h similarity index 100% rename from structure.h rename to Source/Gameplay/Public/structure.h diff --git a/submarine.h b/Source/Gameplay/Public/submarine.h similarity index 100% rename from submarine.h rename to Source/Gameplay/Public/submarine.h diff --git a/technology.h b/Source/Gameplay/Public/technology.h similarity index 100% rename from technology.h rename to Source/Gameplay/Public/technology.h diff --git a/torpedo.h b/Source/Gameplay/Public/torpedo.h similarity index 100% rename from torpedo.h rename to Source/Gameplay/Public/torpedo.h diff --git a/tradeCenter.h b/Source/Gameplay/Public/tradeCenter.h similarity index 100% rename from tradeCenter.h rename to Source/Gameplay/Public/tradeCenter.h diff --git a/tradeOffer.h b/Source/Gameplay/Public/tradeOffer.h similarity index 100% rename from tradeOffer.h rename to Source/Gameplay/Public/tradeOffer.h diff --git a/trader.h b/Source/Gameplay/Public/trader.h similarity index 100% rename from trader.h rename to Source/Gameplay/Public/trader.h diff --git a/unit.h b/Source/Gameplay/Public/unit.h old mode 100755 new mode 100644 similarity index 96% rename from unit.h rename to Source/Gameplay/Public/unit.h index 0bcf425..c5a8eac --- a/unit.h +++ b/Source/Gameplay/Public/unit.h @@ -1,195 +1,195 @@ -#ifndef UNIT_H -#define UNIT_H - -#include -#include -#include -#include - -#include - -#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 targets; - - Order(){} - Order(TYPE t, std::vector 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 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& 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 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 orders; - std::string guiScreen = ""; - int playerId, restartTime, lenHpBar = 200; - vb01::s64 orderLineDispTime = 0, lastFireTime = 0, lastJamTime = 0; - float lineOfSight; - std::vector weapons; - std::vector garrisonSlots; - std::vector buildableUnits; - State state = State::STAND_GROUND; - vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr; - - void placeAt(vb01::Vector3); - std::vector 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 getWeaponsByOrder(Order::TYPE); - std::vector getWeaponsByType(int); - }; -} - -#endif +#ifndef UNIT_H +#define UNIT_H + +#include +#include +#include +#include + +#include + +#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 targets; + + Order(){} + Order(TYPE t, std::vector 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 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& 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 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 orders; + std::string guiScreen = ""; + int playerId, restartTime, lenHpBar = 200; + vb01::s64 orderLineDispTime = 0, lastFireTime = 0, lastJamTime = 0; + float lineOfSight; + std::vector weapons; + std::vector garrisonSlots; + std::vector buildableUnits; + State state = State::STAND_GROUND; + vb01::Node *hpBackgroundNode = nullptr, *hpForegroundNode = nullptr; + + void placeAt(vb01::Vector3); + std::vector 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 getWeaponsByOrder(Order::TYPE); + std::vector getWeaponsByType(int); + }; +} + +#endif diff --git a/vehicle.h b/Source/Gameplay/Public/vehicle.h similarity index 100% rename from vehicle.h rename to Source/Gameplay/Public/vehicle.h diff --git a/vessel.h b/Source/Gameplay/Public/vessel.h old mode 100755 new mode 100644 similarity index 100% rename from vessel.h rename to Source/Gameplay/Public/vessel.h diff --git a/weapon.h b/Source/Gameplay/Public/weapon.h similarity index 100% rename from weapon.h rename to Source/Gameplay/Public/weapon.h diff --git a/abstractCommand.cpp b/Source/Systems/Private/abstractCommand.cpp similarity index 100% rename from abstractCommand.cpp rename to Source/Systems/Private/abstractCommand.cpp diff --git a/activeGameState.cpp b/Source/Systems/Private/activeGameState.cpp old mode 100755 new mode 100644 similarity index 97% rename from activeGameState.cpp rename to Source/Systems/Private/activeGameState.cpp index bb991f4..1e65dc9 --- a/activeGameState.cpp +++ b/Source/Systems/Private/activeGameState.cpp @@ -1,857 +1,857 @@ -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include -#include -#include -#include - -#include "activeGameState.h" -#include "inGameAppState.h" -#include "defConfigs.h" -#include "structure.h" -#include "game.h" -#include "util.h" -#include "tooltip.h" -#include "gameObjectFrameController.h" -#include "gameObjectFactory.h" -#include "cameraController.h" -#include "unitButton.h" -#include "extractor.h" -#include "resourceDeposit.h" -#include "resourceRover.h" -#include "concreteGuiManager.h" - -using namespace vb01; -using namespace vb01Gui; -using namespace std; - -namespace battleship{ - using namespace configData; - using namespace gameBase; - - ActiveGameState::ActiveGameState(GuiAppState *gs, int plId) : AbstractAppState( - AppStateType::ACTIVE_STATE, - configData::calcSumBinds(AppStateType::ACTIVE_STATE, true), - configData::calcSumBinds(AppStateType::ACTIVE_STATE, false), - GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]), guiState(gs), playerId(plId), depth(1){ - initDragbox(); - - mainPlayer = Game::getSingleton()->getPlayer(playerId); - } - - ActiveGameState::~ActiveGameState() { - removeDragbox(); - } - - void ActiveGameState::initDragbox(){ - Root *root = Root::getSingleton(); - - Material *mat = new Material(root->getLibPath() + "gui"); - mat->addBoolUniform("texturingEnabled", false); - mat->addBoolUniform("diffuseColorEnabled", false); - mat->addVec4Uniform("diffuseColor", Vector4(.5, .5, .5, .5)); - - Quad *dragbox = new Quad(Vector3::VEC_ZERO, false); - dragbox->setMaterial(mat); - dragboxNode = new Node(); - dragboxNode->attachMesh(dragbox); - - root->getGuiNode()->attachChild(dragboxNode); - } - - void ActiveGameState::initCursor(){ - string basePath = GameManager::getSingleton()->getPath() + "Textures/Icons/Cursors/"; - sol::state_view SOL_LUA_VIEW = generateView(); - - string pt = SOL_LUA_VIEW["pointerTex"], - at = SOL_LUA_VIEW["attackTex"], - gt = SOL_LUA_VIEW["garrisonTex"], - st = SOL_LUA_VIEW["supplyTex"], - ht = SOL_LUA_VIEW["hackTex"], - ngt = SOL_LUA_VIEW["noGarrisonTex"], - nst = SOL_LUA_VIEW["noSupplyTex"], - nht = SOL_LUA_VIEW["noHackTex"], - p1[]{basePath + pt}, - p2[]{basePath + at}, - p3[]{basePath + gt}, - p4[]{basePath + st}, - p5[]{basePath + ht}, - p6[]{basePath + ngt}, - p7[]{basePath + nst}, - p8[]{basePath + nht}; - pointerTex = new Texture(p1, 1, false); - attackTex = new Texture(p2, 1, false); - garrisonTex = new Texture(p3, 1, false); - supplyTex = new Texture(p4, 1, false); - hackTex = new Texture(p5, 1, false); - noGarrisonTex = new Texture(p6, 1, false); - noSupplyTex = new Texture(p7, 1, false); - noHackTex = new Texture(p8, 1, false); - - Root *root = Root::getSingleton(); - Material *mat = new Material(root->getLibPath() + "gui"); - mat->addBoolUniform("texturingEnabled", true); - mat->addTexUniform("diffuseMap", pointerTex, false); - - Quad *quad = new Quad(Vector3(20, 20, 0), false); - quad->setMaterial(mat); - - cursorNode = new Node(); - cursorNode->attachMesh(quad); - root->getGuiNode()->attachChild(cursorNode); - } - - void ActiveGameState::removeDragbox(){ - Root::getSingleton()->getRootNode()->dettachChild(dragboxNode); - delete dragboxNode; - } - - void ActiveGameState::onAttached() { - AbstractAppState::onAttached(); - vector buttons = guiButtons; - buttons.insert(buttons.end(), unitButtons.begin(), unitButtons.end()); - - ConcreteGuiManager::getSingleton()->readLuaScreenScript( - "activeGameState.lua", - buttons, - vector{}, - vector{}, - vector{}, - vector{}, - guiRects, - guiTexts, - "music = generateFactionMusic(" + to_string(mainPlayer->getFaction()) + ")" - ); - - if(!cursorNode) initCursor(); - } - - void ActiveGameState::onDettached() { - AbstractAppState::onDettached(); - } - - void ActiveGameState::updateCursor(){ - Vector2 cursorPos = getCursorPos(); - cursorNode->setPosition(Vector3(cursorPos.x, cursorPos.y, .8)); - - if(mainPlayer->getNumSelectedUnits() > 0){ - bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer() == mainPlayer); - bool alliedGameObj = (gameObjHoveredOn && !ownGameObj && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam()); - bool gameObjUnit = (gameObjHoveredOn && gameObjHoveredOn->getType() == GameObject::Type::UNIT); - bool gameObjTransport = (gameObjUnit && ((Unit*)gameObjHoveredOn)->getNumGarrisonSlots() > 0); - bool canGarrison = true; - - if(gameObjUnit && gameObjTransport) - for(int i = 0; i < mainPlayer->getNumSelectedUnits(); i++) - if(!((Unit*)gameObjHoveredOn)->canGarrison((Vehicle*)mainPlayer->getSelectedUnit(i))){ - canGarrison = false; - break; - } - - vector offers = (gameObjHoveredOn && alliedGameObj ? mainPlayer->getTradeOffers(gameObjHoveredOn->getPlayer()) : vector{}); - bool tradeResource[NUM_RESOURCES][2], trade = false; - - for(int i = 0; i < NUM_RESOURCES; i++) - for(int j = 0; j < 2; j++){ - if(!offers.empty() && offers[0]->tradeResources[i][j] > 0){ - tradeResource[i][j] = true; - trade = true; - } - else tradeResource[i][j] = false; - } - - int objClass = (gameObjUnit ? int(((Unit*)gameObjHoveredOn)->getUnitClass()) : -1); - bool tradeCenter = ((UnitClass)objClass == UnitClass::TRADE_CENTER); - bool refinery = ((UnitClass)objClass == UnitClass::REFINERY); - bool lab = ((UnitClass)objClass == UnitClass::LAB); - bool ownExtractor = (ownGameObj && (UnitClass)objClass == UnitClass::EXTRACTOR); - - bool roverSelected = (mainPlayer->getSelectedUnit(0)->getUnitClass() == UnitClass::RESOURCE_ROVER); - ResourceRover *rover = (roverSelected ? (ResourceRover*)mainPlayer->getSelectedUnit(0) : nullptr); - int unloadFlag = (int)shiftPressed; - - if(!forceCursorState){ - if(gameObjUnit && gameObjTransport){ - orderPossible = (ownGameObj && canGarrison); - cursorState = CursorState::GARRISON; - } - else if(roverSelected && ownExtractor){ - orderPossible = (((Extractor*)gameObjHoveredOn)->getDeposit()->getAmmount() > 0); - cursorState = CursorState::SUPPLY; - } - else if(roverSelected && (tradeCenter || refinery || lab) && (ownGameObj || (alliedGameObj && trade))){ - bool tradeRes = false; - int resId; - - switch((UnitClass)objClass){ - case UnitClass::TRADE_CENTER: - tradeRes = tradeResource[(int)ResourceType::WEALTH][unloadFlag]; - resId = (int)ResourceType::WEALTH; - break; - case UnitClass::REFINERY: - tradeRes = tradeResource[(int)ResourceType::REFINEDS][unloadFlag]; - resId = (int)ResourceType::REFINEDS; - break; - case UnitClass::LAB: - tradeRes = tradeResource[(int)ResourceType::RESEARCH][unloadFlag]; - resId = (int)ResourceType::RESEARCH; - break; - } - - bool canLoad = (rover && rover->calcTotalLoad() < rover->getCapacity()); - orderPossible = (unloadFlag ? rover->getLoad(resId) > 0 : canLoad); - - if(alliedGameObj) orderPossible = tradeRes && orderPossible; - - cursorState = (unloadFlag ? CursorState::UNLOAD : CursorState::LOAD); - } - else if(gameObjUnit && !(ownGameObj || alliedGameObj)){ - orderPossible = true; - cursorState = CursorState::ATTACK; - } - else - cursorState = CursorState::NORMAL; - } - else{ - if(cursorState == CursorState::GARRISON) - orderPossible = (ownGameObj && gameObjTransport && canGarrison); - else if(cursorState == CursorState::SUPPLY) - orderPossible = (roverSelected && ownExtractor); - else if(cursorState == CursorState::LOAD || cursorState == CursorState::UNLOAD){ - int ulf = int(cursorState == CursorState::UNLOAD); - bool tradeRefs = tradeResource[(int)ResourceType::REFINEDS][ulf]; - bool tradeWealth = tradeResource[(int)ResourceType::WEALTH][ulf]; - bool tradeTech = tradeResource[(int)ResourceType::RESEARCH][ulf]; - - bool canLoad = (rover->calcTotalLoad() < rover->getCapacity()); - bool loadResource = ( - cursorState == CursorState::LOAD ? canLoad : ( - rover->getLoad((int)ResourceType::REFINEDS) > 0 || - rover->getLoad((int)ResourceType::WEALTH) > 0 || - rover->getLoad((int)ResourceType::RESEARCH) > 0 - ) - ); - - bool transferResource = ( - (refinery && loadResource && (ownGameObj || (alliedGameObj && tradeRefs))) || - (tradeCenter && loadResource && (ownGameObj || (alliedGameObj && tradeWealth))) || - (lab && loadResource && (ownGameObj || (alliedGameObj && tradeTech))) - ); - orderPossible = (roverSelected && transferResource); - } - else if(cursorState == CursorState::HACK) - orderPossible = (!ownGameObj && gameObjUnit && mainPlayer->getSelectedUnit(0)->getUnitClass() == UnitClass::CYBORG_ENGINEER); - else if(controlPressed) - cursorState = CursorState::ATTACK; - else - cursorState = CursorState::NORMAL; - } - } - - cursorNode->setVisible(cursorState != CursorState::NORMAL); - Texture *tex = nullptr; - - switch(cursorState){ - case CursorState::ATTACK: - tex = attackTex; - break; - case CursorState::GARRISON: - tex = (orderPossible ? garrisonTex : noGarrisonTex); - break; - case CursorState::SUPPLY: - case CursorState::LOAD: - case CursorState::UNLOAD: - tex = (orderPossible ? supplyTex : noSupplyTex); - break; - case CursorState::HACK: - tex = (orderPossible ? hackTex : noHackTex); - break; - } - - cursorNode->getMesh(0)->getMaterial()->setTexUniform("diffuseMap", tex, false); - } - - void ActiveGameState::update() { - ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); - guiManager->getText("refineds")->setText(to_wstring(mainPlayer->getResource(ResourceType::REFINEDS))); - guiManager->getText("wealth")->setText(to_wstring(mainPlayer->getResource(ResourceType::WEALTH))); - guiManager->getText("research")->setText(to_wstring(mainPlayer->getResource(ResourceType::RESEARCH))); - - updateCursor(); - Vector2 cursorPos = getCursorPos(); - - float eps = .01; - - if(!isSelectionBox && selectMouseClicked && (fabs(clickPoint.x - cursorPos.x) > eps || fabs(clickPoint.y - cursorPos.y) > eps) && getTime() - lastSelectMouseClicked > 10) - isSelectionBox = true; - else if (isSelectionBox) - updateDragBox(); - - dragboxNode->setVisible(isSelectionBox); - - updateGameObjHoveredOn(); - - vector selectedUnits = mainPlayer->getSelectedUnits(); - GameObjectFrameController *fc = GameObjectFrameController::getSingleton(); - - if(!selectingDestOrient && orderMouseClicked && !selectedUnits.empty() && getTime() - lastOrderMouseClicked > 100){ - if(targets.empty()) castRayToTerrain(); - - if(!buildableStructSelected) - for(int i = 0; i < selectedUnits.size(); i++) - fc->addGameObjectFrame(GameObjectFrame(selectedUnits[i]->getId(), GameObject::Type::UNIT, mainPlayer, selectedUnits[i], targets[0].pos)); - - selectingDestOrient = true; - fc->setRotating(true); - } - else if(selectingDestOrient && !orderMouseClicked){ - selectingDestOrient = false; - - fc->toggleFrameTransformations(false, false, false); - fc->removeGameObjectFrames(); - } - - if(!tradingScreen){ - guiTexts = guiManager->getTexts(); - guiRects = guiManager->getGuiRectangles(); - guiButtons = guiManager->getButtons(); - } - - renderUnits(); - - vector currSelectedUnits = mainPlayer->getSelectedUnits(); - - if(prevSelectedUnits != currSelectedUnits){ - addUnitGui(); - prevSelectedUnits = currSelectedUnits; - } - - if(fc->isRotating() || fc->isPlacingOnSurface() || fc->isPlacingVertically()) - fc->update(); - - CameraController *camCtr = CameraController::getSingleton(); - - if(!camCtr->isLookingAround()) - camCtr->updateCameraPosition(); - } - - void ActiveGameState::updateGameObjHoveredOn(){ - vector gameObjs; - vector players = Game::getSingleton()->getPlayers(true); - - for(Player *pl : players){ - vector resDeps = pl->getResourceDeposits(); - vector units = pl->getUnits(); - - for(ResourceDeposit *rd : resDeps) - gameObjs.push_back((GameObject*)rd); - - for(Unit *u : units) - gameObjs.push_back((GameObject*)u); - } - - for(GameObject *gameObj : gameObjs) - if(isGameObjSelectable(gameObj, false)){ - gameObjHoveredOn = gameObj; - return; - } - - gameObjHoveredOn = nullptr; - } - - void ActiveGameState::deselectUnits(){ - mainPlayer->deselectUnits(); - GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); - ufCtr->removeGameObjectFrames(); - ufCtr->toggleFrameTransformations(false, false, false); - - ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua"); - } - - bool ActiveGameState::selectedUnitsAmongst(vector units){ - vector selUnits = mainPlayer->getSelectedUnits(); - - for(Unit *unit : units) - if(find(selUnits.begin(), selUnits.end(), unit) != selUnits.end()) - return true; - - return false; - } - - bool ActiveGameState::isGameObjSelectable(GameObject *obj, bool useDragBox){ - if(!obj->getModel()->isVisible()) return false; - - Node *hitboxNode = obj->getHitbox(); - Box *hitbox = (Box*)hitboxNode->getMesh(0); - - Vector3 hitboxSize = hitbox->getSize(); - float width = hitboxSize.x, height = hitboxSize.y, length = hitboxSize.z; - const int NUM_CORNERS = 8; - - Vector3 corners[NUM_CORNERS]{ - Vector3(-.5 * width, -.5 * height, -.5 * length), - Vector3(-.5 * width, -.5 * height, .5 * length), - Vector3(.5 * width, -.5 * height, .5 * length), - Vector3(.5 * width, -.5 * height, -.5 * length), - Vector3(-.5 * width, .5 * height, -.5 * length), - Vector3(-.5 * width, .5 * height, .5 * length), - Vector3(.5 * width, .5 * height, .5 * length), - Vector3(.5 * width, .5 * height, -.5 * length), - }; - - Vector2 cornersOnScreen[NUM_CORNERS]; - Vector3 hitboxOffset = hitboxNode->getPosition(); - - for(int i = 0; i < NUM_CORNERS; i++){ - Vector3 cornerInWorld = - obj->getPos() + - obj->getLeftVec() * (corners[i].x + hitboxOffset.x) + - obj->getUpVec() * (corners[i].y + hitboxOffset.y) + - obj->getDirVec() * (corners[i].z + hitboxOffset.z); - - Vector3 screenSpace3d = spaceToScreen3d(cornerInWorld); - - if(fabs(screenSpace3d.z) > 1) return false; - - cornersOnScreen[i] = Vector2(screenSpace3d.x, screenSpace3d.y); - } - - vector selectionPoints; - Vector3 dragboxOrigin = Vector3::VEC_ZERO, dragboxSize = Vector3::VEC_ZERO; - - if(useDragBox){ - dragboxOrigin = dragboxNode->getPosition(); - dragboxSize = ((Quad*)dragboxNode->getMesh(0))->getSize(); - Vector2 objScreenPos = spaceToScreen(obj->getPos()); - - if( - (dragboxOrigin.x < objScreenPos.x && objScreenPos.x < dragboxOrigin.x + dragboxSize.x) && - (dragboxOrigin.y < objScreenPos.y && objScreenPos.y < dragboxOrigin.y + dragboxSize.y) - ) - return true; - - selectionPoints = vector{ - Vector2(dragboxOrigin.x, dragboxOrigin.y), - Vector2(dragboxOrigin.x + dragboxSize.x, dragboxOrigin.y), - Vector2(dragboxOrigin.x + dragboxSize.x, dragboxOrigin.y + dragboxSize.y), - Vector2(dragboxOrigin.x, dragboxOrigin.y + dragboxSize.y) - }; - } - else - selectionPoints = vector{getCursorPos()}; - - int numAboveEdges = 0, numBelowEdges = 0; - - for(int i = 0; i < selectionPoints.size(); i++){ - const int NUM_EDGES = 12; - int edges[NUM_EDGES][2]{{0, 1}, {1, 2}, {2, 3}, {3, 0}, {4, 5}, {5, 6}, {6, 7}, {7, 4}, {0, 4}, {1, 5}, {2, 6}, {3, 7}}; - - for(int j = 0; j < NUM_EDGES && (numAboveEdges == 0 || numBelowEdges == 0); j++){ - Vector2 vertA = cornersOnScreen[edges[j][0]], vertB = cornersOnScreen[edges[j][1]]; - float edgeHorLen = fabs(vertA.x - vertB.x), edgeVertLen = fabs(vertA.y - vertB.y); - - if(fabs(selectionPoints[i].x - vertA.x) < edgeHorLen && fabs(selectionPoints[i].x - vertB.x) < edgeHorLen){ - if(vertA.x > selectionPoints[i].x) swap(vertA, vertB); - - float horOffset = (selectionPoints[i].x - vertA.x) / edgeHorLen; - float height = vertA.y + (vertA.y < vertB.y ? 1 : -1) * horOffset * edgeVertLen; - - (selectionPoints[i].y > height ? numAboveEdges : numBelowEdges)++; - } - } - } - - return (numAboveEdges > 0 && numBelowEdges > 0); - } - - void ActiveGameState::renderUnits() { - vector friendlyUnits = mainPlayer->getFriendlyUnits(); - Game *game = Game::getSingleton(); - - for (Player *p : game->getPlayers(true)){ - vector units = p->getUnits(); - - for (Unit *u : units) { - if(u->isVehicle() && ((Vehicle*)u)->getGarrisonable()) continue; - - bool unitVisible = (game->isDebug() || mainPlayer->isObjectVisible((GameObject*)u, friendlyUnits)); - u->getModel()->setVisible(unitVisible); - } - } - } - - void ActiveGameState::updateDragBox() { - Vector2 mousePos = getCursorPos(), dragBoxOrigin, dragBoxEnd; - - if (mousePos.x >= clickPoint.x && mousePos.y >= clickPoint.y) { - dragBoxOrigin = Vector2(clickPoint.x, clickPoint.y); - dragBoxEnd = Vector2(mousePos.x, mousePos.y); - } - else if (mousePos.x < clickPoint.x && mousePos.y > clickPoint.y) { - dragBoxOrigin = Vector2(mousePos.x, clickPoint.y); - dragBoxEnd = Vector2(clickPoint.x, mousePos.y); - } - else if (mousePos.x >= clickPoint.x && mousePos.y < clickPoint.y) { - dragBoxOrigin = Vector2(clickPoint.x, mousePos.y); - dragBoxEnd = Vector2(mousePos.x, clickPoint.y); - } - else { - dragBoxOrigin = Vector2(mousePos.x, mousePos.y); - dragBoxEnd = Vector2(clickPoint.x, clickPoint.y); - } - - Vector3 size = Vector3(dragBoxEnd.x - dragBoxOrigin.x, dragBoxEnd.y - dragBoxOrigin.y, 0); - Quad *dragbox = (Quad*)dragboxNode->getMesh(0); - dragbox->setSize(size); - dragbox->updateVerts(dragbox->getMeshBase()); - dragboxNode->setPosition(Vector3(dragBoxOrigin.x, dragBoxOrigin.y, 0)); - } - - //TODO fix ejectable unit selection with multiple transports selected - //TODO replace shiftPressed with a dedicated buy flag - void ActiveGameState::issueOrder(Order::TYPE type, vector targets, bool addOrder) { - depth = 1; - Vector3 destDir = Vector3::VEC_ZERO; - - if(selectingDestOrient){ - GameObjectFrame &objFrame = GameObjectFrameController::getSingleton()->getGameObjectFrame(0); - destDir = objFrame.getDirVec(); - targets[0].pos = objFrame.getPos(); - } - - mainPlayer->issueOrder(type, destDir, targets, addOrder); - this->targets.clear(); - - if(cursorState != CursorState::ATTACK) - forceCursorState = false; - } - - void ActiveGameState::castRayToTerrain() { - Camera *cam = Root::getSingleton()->getCamera(); - Vector3 camPos = cam->getPosition(); - Vector3 endPos = screenToSpace(getCursorPos()); - - Vector3 rayDir = (endPos - camPos).norm(); - Map *map = Map::getSingleton(); - vector results = map->raycastTerrain(camPos, rayDir, true); - - if(!results.empty()) - targets.push_back(Order::Target(nullptr, results[0].pos)); - } - - void ActiveGameState::enableUnitState(Unit::State state){ - vector selectedUnits = mainPlayer->getSelectedUnits(); - - for(Unit *unit : selectedUnits) - unit->setState(state); - } - - void ActiveGameState::addUnitGui(){ - vector currSelectedUnits = mainPlayer->getSelectedUnits(); - - if(currSelectedUnits.empty()) return; - - ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); - - sol::state_view SOL_LUA_VIEW = generateView(); - SOL_LUA_VIEW.script("_mainUnitId = " + to_string(currSelectedUnits[0]->getId())); - guiManager->readLuaScreenScriptDel("unitGui.lua", unitButtons); - - SOL_LUA_VIEW.script("numGui = #gui"); - int numButtons = SOL_LUA_VIEW["numGui"]; - - for(int i = 0; i < numButtons; i++) - unitButtons.push_back(guiManager->getButtons()[guiManager->getButtons().size() - (i + 1)]); - } - - void ActiveGameState::onAction(int bind, bool isPressed) { - if(tradingScreen || !ConcreteGuiManager::getSingleton()->findClickedButtons().empty()) return; - - GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); - vector selectedUnits = mainPlayer->getSelectedUnits(); - - switch((Bind)bind){ - case Bind::DRAG_BOX: - selectMouseClicked = isPressed; - - if(isPressed){ - clickPoint = getCursorPos(); - lastSelectMouseClicked = getTime(); - } - else{ - if(!shiftPressed) deselectUnits(); - - if(canSelectHoveredOnGameObj()) - mainPlayer->selectUnit((Unit*)gameObjHoveredOn); - - selectingDestOrient = false; - - if(isSelectionBox){ - if(!shiftPressed) deselectUnits(); - - vector units = mainPlayer->getUnits(); - - for(Unit *un : units) - if(isGameObjSelectable(un, true)) - mainPlayer->selectUnit(un); - } - - isSelectionBox = false; - Quad *quad = (Quad*)dragboxNode->getMesh(0); - quad->setSize(Vector3::VEC_ZERO); - quad->updateVerts(quad->getMeshBase()); - - ufCtr->toggleFrameTransformations(false, false, false); - ufCtr->removeGameObjectFrames(); - } - - break; - case Bind::ROTATE_OBJ_FRAME: - orderMouseClicked = isPressed; - - if(isPressed) - lastOrderMouseClicked = getTime(); - else if(!(isPressed || selectedUnits.empty())){ - if(selectingPatrolPoints){ - castRayToTerrain(); - - if(!(targets.empty() || selectingPatrolPoints)){ - Order::TYPE type = Order::TYPE::MOVE; - - if(controlPressed || (targets[0].unit && targets[0].unit->getPlayer()->getTeam() != mainPlayer->getTeam())) - type = Order::TYPE::ATTACK; - else if(ufCtr->isPlacingOnSurface() && !selectingDestOrient) - type = Order::TYPE::BUILD; - - issueOrder(type, targets, shiftPressed); - } - } - else if(!isSelectionBox){ - bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam()); - - if(cursorState == CursorState::GARRISON){ - if(orderPossible) issueOrder(Order::TYPE::GARRISON, vector{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed); - } - else if(cursorState == CursorState::SUPPLY){ - if(orderPossible) issueOrder(Order::TYPE::SUPPLY, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); - } - else if(cursorState == CursorState::LOAD){ - if(orderPossible) issueOrder(Order::TYPE::LOAD, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); - } - else if(cursorState == CursorState::UNLOAD){ - if(orderPossible) issueOrder(Order::TYPE::UNLOAD, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); - } - else if(cursorState == CursorState::ATTACK){ - if(controlPressed && !gameObjHoveredOn){ - castRayToTerrain(); - issueOrder(Order::TYPE::ATTACK, targets, shiftPressed); - } - else{ - if(orderPossible) issueOrder(Order::TYPE::ATTACK, vector{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed); - } - } - else if(cursorState == CursorState::HACK){ - if(orderPossible) issueOrder(Order::TYPE::HACK, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); - } - else if(ufCtr->isPlacingOnSurface()){ - Order::TYPE type; - - switch(selectedUnits[0]->getUnitClass()){ - case UnitClass::ROBO_ENGINEER: - case UnitClass::CYBORG_ENGINEER: - case UnitClass::FREEZER: - type = Order::TYPE::BUILD; - break; - default: - return; - } - - targets.clear(); - - for(int i = 0; i < ufCtr->getNumGameObjectFrames(); i++){ - GameObjectFrame gmObjFr = ufCtr->getGameObjectFrame(i); - - if(gmObjFr.status == GameObjectFrame::BLOCKED_BY_DIFF_TERR) continue; - - Unit *buildStruct = GameObjectFactory::createUnit(mainPlayer, gmObjFr.getId(), gmObjFr.getPos(), gmObjFr.getRot()); - issueOrder(type, vector{Order::Target(buildStruct, gmObjFr.getPos())}, shiftPressed); - } - - buildableStructSelected = false; - } - else{ - if(targets.empty()) castRayToTerrain(); - - issueOrder(Order::TYPE::MOVE, targets, shiftPressed); - } - } - } - - break; - case Bind::MOVE_CAMERA: - break; - case Bind::ENABLE_CHASE_STATE: - if(isPressed) enableUnitState(Unit::State::CHASE); - break; - case Bind::ENABLE_STAND_GROUND_STATE: - if(isPressed) enableUnitState(Unit::State::STAND_GROUND); - break; - case Bind::ENABLE_HOLD_FIRE_STATE: - if(isPressed) enableUnitState(Unit::State::HOLD_FIRE); - break; - case Bind::EJECT_GARRISON: - if(isPressed) issueOrder(Order::TYPE::EJECT, vector{}, shiftPressed); - break; - case Bind::LAUNCH: - if(isPressed){ - castRayToTerrain(); - issueOrder(Order::TYPE::LAUNCH, targets, shiftPressed); - } - - break; - /* - case Bind::HACK: - if(isPressed){ - if(gameObjHoveredOn && gameObjHoveredOn->getType() == GameObject::Type::UNIT && gameObjHoveredOn->getPlayer()->getTeam() != mainPlayer->getTeam()) - issueOrder(Order::TYPE::HACK, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); - - break; - } - */ - case Bind::SHIFT_SUB_DEPTH: - ufCtr->toggleFrameTransformations(false, false, isPressed); - break; - case Bind::ZOOM_IN: - if (zooms > -NUM_MAX_ZOOMS) { - Camera *cam = Root::getSingleton()->getCamera(); - cam->setPosition(cam->getPosition() + cam->getDirection().norm() * .5f); - zooms--; - } - break; - case Bind::ZOOM_OUT: - if (zooms < NUM_MAX_ZOOMS) { - Camera *cam = Root::getSingleton()->getCamera(); - cam->setPosition(cam->getPosition() - (cam->getDirection().norm() * .5f)); - zooms++; - } - break; - case Bind::LOOK_AROUND: - if(!ufCtr->isPlacingOnSurface()) - CameraController::getSingleton()->setLookingAround(isPressed); - break; - case Bind::HALT: - if(isPressed) mainPlayer->haltUnits(); - break; - //TODO reimplement submarine diving mechanic - case Bind::LEFT_CONTROL: - if(isPressed) cursorState = CursorState::ATTACK; - - forceCursorState = isPressed; - controlPressed = isPressed; - orderPossible = isPressed; - break; - case Bind::LEFT_SHIFT: - { - shiftPressed = isPressed; - - ufCtr->setPaintSelecting(shiftPressed); - - if(isPressed){ - Vector3 startPos = Root::getSingleton()->getCamera()->getPosition(); - vector results = Map::getSingleton()->raycastTerrain(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), true); - - if(!results.empty()) - ufCtr->setPaintSelectRowStart(results[0].pos); - } - } - break; - case Bind::SELECT_PATROL_POINTS: - /* - if(isPressed && mainPlayer->getNumSelectedUnits() > 0){ - targets.push_back(Order::Target(nullptr, mainPlayer->getSelectedUnit(0)->getPos())); - selectingPatrolPoints = isPressed; - } - */ - - break; - case Bind::GROUP_0: - case Bind::GROUP_1: - case Bind::GROUP_2: - case Bind::GROUP_3: - case Bind::GROUP_4: - case Bind::GROUP_5: - case Bind::GROUP_6: - case Bind::GROUP_7: - case Bind::GROUP_8: - case Bind::GROUP_9: - if(isPressed){ - int group = bind - Bind::GROUP_0; - - if(controlPressed) - unitGroups[group] = mainPlayer->getSelectedUnits(); - else{ - if(!shiftPressed) - mainPlayer->selectUnits(unitGroups[group]); - else - for(Unit *u : unitGroups[group]) - mainPlayer->selectUnit(u); - } - } - - break; - case Bind::DESELECT_STRUCTURE: - forceCursorState = false; - buildableStructSelected = false; - ufCtr->toggleFrameTransformations(false, false, false); - ufCtr->removeGameObjectFrames(); - break; - } - } - - void ActiveGameState::onAnalog(int bind, float strength) { - CameraController *camCtr = CameraController::getSingleton(); - GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); - - switch((Bind)bind){ - case Bind::LOOK_UP: - case Bind::LOOK_DOWN: - if(camCtr->isLookingAround()) { - Vector3 dirProj = Root::getSingleton()->getCamera()->getDirection(); - dirProj = Vector3(dirProj.x, 0, dirProj.z).norm(); - CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0).cross(dirProj), strength); - } - else if(ufCtr->isPlacingVertically()){ - depth -= .2 * strength; - - if(depth < 0) depth = 0; - else if(depth > 1) depth = 1; - } - - break; - case Bind::LOOK_LEFT: - case Bind::LOOK_RIGHT: - if(camCtr->isLookingAround()) - CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0), strength); - else if(ufCtr->isRotating()) - ufCtr->rotateGameObjectFrames(100 * strength); - - break; - } - } - - void ActiveGameState::onRawMouseWheelScroll(bool up){ - CameraController::getSingleton()->zoomCamera(up); - } -} +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include +#include + +#include +#include +#include +#include + +#include "activeGameState.h" +#include "inGameAppState.h" +#include "defConfigs.h" +#include "structure.h" +#include "game.h" +#include "util.h" +#include "tooltip.h" +#include "gameObjectFrameController.h" +#include "gameObjectFactory.h" +#include "cameraController.h" +#include "unitButton.h" +#include "extractor.h" +#include "resourceDeposit.h" +#include "resourceRover.h" +#include "concreteGuiManager.h" + +using namespace vb01; +using namespace vb01Gui; +using namespace std; + +namespace battleship{ + using namespace configData; + using namespace gameBase; + + ActiveGameState::ActiveGameState(GuiAppState *gs, int plId) : AbstractAppState( + AppStateType::ACTIVE_STATE, + configData::calcSumBinds(AppStateType::ACTIVE_STATE, true), + configData::calcSumBinds(AppStateType::ACTIVE_STATE, false), + GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]), guiState(gs), playerId(plId), depth(1){ + initDragbox(); + + mainPlayer = Game::getSingleton()->getPlayer(playerId); + } + + ActiveGameState::~ActiveGameState() { + removeDragbox(); + } + + void ActiveGameState::initDragbox(){ + Root *root = Root::getSingleton(); + + Material *mat = new Material(root->getLibPath() + "gui"); + mat->addBoolUniform("texturingEnabled", false); + mat->addBoolUniform("diffuseColorEnabled", false); + mat->addVec4Uniform("diffuseColor", Vector4(.5, .5, .5, .5)); + + Quad *dragbox = new Quad(Vector3::VEC_ZERO, false); + dragbox->setMaterial(mat); + dragboxNode = new Node(); + dragboxNode->attachMesh(dragbox); + + root->getGuiNode()->attachChild(dragboxNode); + } + + void ActiveGameState::initCursor(){ + string basePath = GameManager::getSingleton()->getPath() + "Textures/Icons/Cursors/"; + sol::state_view SOL_LUA_VIEW = generateView(); + + string pt = SOL_LUA_VIEW["pointerTex"], + at = SOL_LUA_VIEW["attackTex"], + gt = SOL_LUA_VIEW["garrisonTex"], + st = SOL_LUA_VIEW["supplyTex"], + ht = SOL_LUA_VIEW["hackTex"], + ngt = SOL_LUA_VIEW["noGarrisonTex"], + nst = SOL_LUA_VIEW["noSupplyTex"], + nht = SOL_LUA_VIEW["noHackTex"], + p1[]{basePath + pt}, + p2[]{basePath + at}, + p3[]{basePath + gt}, + p4[]{basePath + st}, + p5[]{basePath + ht}, + p6[]{basePath + ngt}, + p7[]{basePath + nst}, + p8[]{basePath + nht}; + pointerTex = new Texture(p1, 1, false); + attackTex = new Texture(p2, 1, false); + garrisonTex = new Texture(p3, 1, false); + supplyTex = new Texture(p4, 1, false); + hackTex = new Texture(p5, 1, false); + noGarrisonTex = new Texture(p6, 1, false); + noSupplyTex = new Texture(p7, 1, false); + noHackTex = new Texture(p8, 1, false); + + Root *root = Root::getSingleton(); + Material *mat = new Material(root->getLibPath() + "gui"); + mat->addBoolUniform("texturingEnabled", true); + mat->addTexUniform("diffuseMap", pointerTex, false); + + Quad *quad = new Quad(Vector3(20, 20, 0), false); + quad->setMaterial(mat); + + cursorNode = new Node(); + cursorNode->attachMesh(quad); + root->getGuiNode()->attachChild(cursorNode); + } + + void ActiveGameState::removeDragbox(){ + Root::getSingleton()->getRootNode()->dettachChild(dragboxNode); + delete dragboxNode; + } + + void ActiveGameState::onAttached() { + AbstractAppState::onAttached(); + vector buttons = guiButtons; + buttons.insert(buttons.end(), unitButtons.begin(), unitButtons.end()); + + ConcreteGuiManager::getSingleton()->readLuaScreenScript( + "activeGameState.lua", + buttons, + vector{}, + vector{}, + vector{}, + vector{}, + guiRects, + guiTexts, + "music = generateFactionMusic(" + to_string(mainPlayer->getFaction()) + ")" + ); + + if(!cursorNode) initCursor(); + } + + void ActiveGameState::onDettached() { + AbstractAppState::onDettached(); + } + + void ActiveGameState::updateCursor(){ + Vector2 cursorPos = getCursorPos(); + cursorNode->setPosition(Vector3(cursorPos.x, cursorPos.y, .8)); + + if(mainPlayer->getNumSelectedUnits() > 0){ + bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer() == mainPlayer); + bool alliedGameObj = (gameObjHoveredOn && !ownGameObj && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam()); + bool gameObjUnit = (gameObjHoveredOn && gameObjHoveredOn->getType() == GameObject::Type::UNIT); + bool gameObjTransport = (gameObjUnit && ((Unit*)gameObjHoveredOn)->getNumGarrisonSlots() > 0); + bool canGarrison = true; + + if(gameObjUnit && gameObjTransport) + for(int i = 0; i < mainPlayer->getNumSelectedUnits(); i++) + if(!((Unit*)gameObjHoveredOn)->canGarrison((Vehicle*)mainPlayer->getSelectedUnit(i))){ + canGarrison = false; + break; + } + + vector offers = (gameObjHoveredOn && alliedGameObj ? mainPlayer->getTradeOffers(gameObjHoveredOn->getPlayer()) : vector{}); + bool tradeResource[NUM_RESOURCES][2], trade = false; + + for(int i = 0; i < NUM_RESOURCES; i++) + for(int j = 0; j < 2; j++){ + if(!offers.empty() && offers[0]->tradeResources[i][j] > 0){ + tradeResource[i][j] = true; + trade = true; + } + else tradeResource[i][j] = false; + } + + int objClass = (gameObjUnit ? int(((Unit*)gameObjHoveredOn)->getUnitClass()) : -1); + bool tradeCenter = ((UnitClass)objClass == UnitClass::TRADE_CENTER); + bool refinery = ((UnitClass)objClass == UnitClass::REFINERY); + bool lab = ((UnitClass)objClass == UnitClass::LAB); + bool ownExtractor = (ownGameObj && (UnitClass)objClass == UnitClass::EXTRACTOR); + + bool roverSelected = (mainPlayer->getSelectedUnit(0)->getUnitClass() == UnitClass::RESOURCE_ROVER); + ResourceRover *rover = (roverSelected ? (ResourceRover*)mainPlayer->getSelectedUnit(0) : nullptr); + int unloadFlag = (int)shiftPressed; + + if(!forceCursorState){ + if(gameObjUnit && gameObjTransport){ + orderPossible = (ownGameObj && canGarrison); + cursorState = CursorState::GARRISON; + } + else if(roverSelected && ownExtractor){ + orderPossible = (((Extractor*)gameObjHoveredOn)->getDeposit()->getAmmount() > 0); + cursorState = CursorState::SUPPLY; + } + else if(roverSelected && (tradeCenter || refinery || lab) && (ownGameObj || (alliedGameObj && trade))){ + bool tradeRes = false; + int resId; + + switch((UnitClass)objClass){ + case UnitClass::TRADE_CENTER: + tradeRes = tradeResource[(int)ResourceType::WEALTH][unloadFlag]; + resId = (int)ResourceType::WEALTH; + break; + case UnitClass::REFINERY: + tradeRes = tradeResource[(int)ResourceType::REFINEDS][unloadFlag]; + resId = (int)ResourceType::REFINEDS; + break; + case UnitClass::LAB: + tradeRes = tradeResource[(int)ResourceType::RESEARCH][unloadFlag]; + resId = (int)ResourceType::RESEARCH; + break; + } + + bool canLoad = (rover && rover->calcTotalLoad() < rover->getCapacity()); + orderPossible = (unloadFlag ? rover->getLoad(resId) > 0 : canLoad); + + if(alliedGameObj) orderPossible = tradeRes && orderPossible; + + cursorState = (unloadFlag ? CursorState::UNLOAD : CursorState::LOAD); + } + else if(gameObjUnit && !(ownGameObj || alliedGameObj)){ + orderPossible = true; + cursorState = CursorState::ATTACK; + } + else + cursorState = CursorState::NORMAL; + } + else{ + if(cursorState == CursorState::GARRISON) + orderPossible = (ownGameObj && gameObjTransport && canGarrison); + else if(cursorState == CursorState::SUPPLY) + orderPossible = (roverSelected && ownExtractor); + else if(cursorState == CursorState::LOAD || cursorState == CursorState::UNLOAD){ + int ulf = int(cursorState == CursorState::UNLOAD); + bool tradeRefs = tradeResource[(int)ResourceType::REFINEDS][ulf]; + bool tradeWealth = tradeResource[(int)ResourceType::WEALTH][ulf]; + bool tradeTech = tradeResource[(int)ResourceType::RESEARCH][ulf]; + + bool canLoad = (rover->calcTotalLoad() < rover->getCapacity()); + bool loadResource = ( + cursorState == CursorState::LOAD ? canLoad : ( + rover->getLoad((int)ResourceType::REFINEDS) > 0 || + rover->getLoad((int)ResourceType::WEALTH) > 0 || + rover->getLoad((int)ResourceType::RESEARCH) > 0 + ) + ); + + bool transferResource = ( + (refinery && loadResource && (ownGameObj || (alliedGameObj && tradeRefs))) || + (tradeCenter && loadResource && (ownGameObj || (alliedGameObj && tradeWealth))) || + (lab && loadResource && (ownGameObj || (alliedGameObj && tradeTech))) + ); + orderPossible = (roverSelected && transferResource); + } + else if(cursorState == CursorState::HACK) + orderPossible = (!ownGameObj && gameObjUnit && mainPlayer->getSelectedUnit(0)->getUnitClass() == UnitClass::CYBORG_ENGINEER); + else if(controlPressed) + cursorState = CursorState::ATTACK; + else + cursorState = CursorState::NORMAL; + } + } + + cursorNode->setVisible(cursorState != CursorState::NORMAL); + Texture *tex = nullptr; + + switch(cursorState){ + case CursorState::ATTACK: + tex = attackTex; + break; + case CursorState::GARRISON: + tex = (orderPossible ? garrisonTex : noGarrisonTex); + break; + case CursorState::SUPPLY: + case CursorState::LOAD: + case CursorState::UNLOAD: + tex = (orderPossible ? supplyTex : noSupplyTex); + break; + case CursorState::HACK: + tex = (orderPossible ? hackTex : noHackTex); + break; + } + + cursorNode->getMesh(0)->getMaterial()->setTexUniform("diffuseMap", tex, false); + } + + void ActiveGameState::update() { + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + guiManager->getText("refineds")->setText(to_wstring(mainPlayer->getResource(ResourceType::REFINEDS))); + guiManager->getText("wealth")->setText(to_wstring(mainPlayer->getResource(ResourceType::WEALTH))); + guiManager->getText("research")->setText(to_wstring(mainPlayer->getResource(ResourceType::RESEARCH))); + + updateCursor(); + Vector2 cursorPos = getCursorPos(); + + float eps = .01; + + if(!isSelectionBox && selectMouseClicked && (fabs(clickPoint.x - cursorPos.x) > eps || fabs(clickPoint.y - cursorPos.y) > eps) && getTime() - lastSelectMouseClicked > 10) + isSelectionBox = true; + else if (isSelectionBox) + updateDragBox(); + + dragboxNode->setVisible(isSelectionBox); + + updateGameObjHoveredOn(); + + vector selectedUnits = mainPlayer->getSelectedUnits(); + GameObjectFrameController *fc = GameObjectFrameController::getSingleton(); + + if(!selectingDestOrient && orderMouseClicked && !selectedUnits.empty() && getTime() - lastOrderMouseClicked > 100){ + if(targets.empty()) castRayToTerrain(); + + if(!buildableStructSelected) + for(int i = 0; i < selectedUnits.size(); i++) + fc->addGameObjectFrame(GameObjectFrame(selectedUnits[i]->getId(), GameObject::Type::UNIT, mainPlayer, selectedUnits[i], targets[0].pos)); + + selectingDestOrient = true; + fc->setRotating(true); + } + else if(selectingDestOrient && !orderMouseClicked){ + selectingDestOrient = false; + + fc->toggleFrameTransformations(false, false, false); + fc->removeGameObjectFrames(); + } + + if(!tradingScreen){ + guiTexts = guiManager->getTexts(); + guiRects = guiManager->getGuiRectangles(); + guiButtons = guiManager->getButtons(); + } + + renderUnits(); + + vector currSelectedUnits = mainPlayer->getSelectedUnits(); + + if(prevSelectedUnits != currSelectedUnits){ + addUnitGui(); + prevSelectedUnits = currSelectedUnits; + } + + if(fc->isRotating() || fc->isPlacingOnSurface() || fc->isPlacingVertically()) + fc->update(); + + CameraController *camCtr = CameraController::getSingleton(); + + if(!camCtr->isLookingAround()) + camCtr->updateCameraPosition(); + } + + void ActiveGameState::updateGameObjHoveredOn(){ + vector gameObjs; + vector players = Game::getSingleton()->getPlayers(true); + + for(Player *pl : players){ + vector resDeps = pl->getResourceDeposits(); + vector units = pl->getUnits(); + + for(ResourceDeposit *rd : resDeps) + gameObjs.push_back((GameObject*)rd); + + for(Unit *u : units) + gameObjs.push_back((GameObject*)u); + } + + for(GameObject *gameObj : gameObjs) + if(isGameObjSelectable(gameObj, false)){ + gameObjHoveredOn = gameObj; + return; + } + + gameObjHoveredOn = nullptr; + } + + void ActiveGameState::deselectUnits(){ + mainPlayer->deselectUnits(); + GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); + ufCtr->removeGameObjectFrames(); + ufCtr->toggleFrameTransformations(false, false, false); + + ConcreteGuiManager::getSingleton()->readLuaScreenScript("activeGameState.lua"); + } + + bool ActiveGameState::selectedUnitsAmongst(vector units){ + vector selUnits = mainPlayer->getSelectedUnits(); + + for(Unit *unit : units) + if(find(selUnits.begin(), selUnits.end(), unit) != selUnits.end()) + return true; + + return false; + } + + bool ActiveGameState::isGameObjSelectable(GameObject *obj, bool useDragBox){ + if(!obj->getModel()->isVisible()) return false; + + Node *hitboxNode = obj->getHitbox(); + Box *hitbox = (Box*)hitboxNode->getMesh(0); + + Vector3 hitboxSize = hitbox->getSize(); + float width = hitboxSize.x, height = hitboxSize.y, length = hitboxSize.z; + const int NUM_CORNERS = 8; + + Vector3 corners[NUM_CORNERS]{ + Vector3(-.5 * width, -.5 * height, -.5 * length), + Vector3(-.5 * width, -.5 * height, .5 * length), + Vector3(.5 * width, -.5 * height, .5 * length), + Vector3(.5 * width, -.5 * height, -.5 * length), + Vector3(-.5 * width, .5 * height, -.5 * length), + Vector3(-.5 * width, .5 * height, .5 * length), + Vector3(.5 * width, .5 * height, .5 * length), + Vector3(.5 * width, .5 * height, -.5 * length), + }; + + Vector2 cornersOnScreen[NUM_CORNERS]; + Vector3 hitboxOffset = hitboxNode->getPosition(); + + for(int i = 0; i < NUM_CORNERS; i++){ + Vector3 cornerInWorld = + obj->getPos() + + obj->getLeftVec() * (corners[i].x + hitboxOffset.x) + + obj->getUpVec() * (corners[i].y + hitboxOffset.y) + + obj->getDirVec() * (corners[i].z + hitboxOffset.z); + + Vector3 screenSpace3d = spaceToScreen3d(cornerInWorld); + + if(fabs(screenSpace3d.z) > 1) return false; + + cornersOnScreen[i] = Vector2(screenSpace3d.x, screenSpace3d.y); + } + + vector selectionPoints; + Vector3 dragboxOrigin = Vector3::VEC_ZERO, dragboxSize = Vector3::VEC_ZERO; + + if(useDragBox){ + dragboxOrigin = dragboxNode->getPosition(); + dragboxSize = ((Quad*)dragboxNode->getMesh(0))->getSize(); + Vector2 objScreenPos = spaceToScreen(obj->getPos()); + + if( + (dragboxOrigin.x < objScreenPos.x && objScreenPos.x < dragboxOrigin.x + dragboxSize.x) && + (dragboxOrigin.y < objScreenPos.y && objScreenPos.y < dragboxOrigin.y + dragboxSize.y) + ) + return true; + + selectionPoints = vector{ + Vector2(dragboxOrigin.x, dragboxOrigin.y), + Vector2(dragboxOrigin.x + dragboxSize.x, dragboxOrigin.y), + Vector2(dragboxOrigin.x + dragboxSize.x, dragboxOrigin.y + dragboxSize.y), + Vector2(dragboxOrigin.x, dragboxOrigin.y + dragboxSize.y) + }; + } + else + selectionPoints = vector{getCursorPos()}; + + int numAboveEdges = 0, numBelowEdges = 0; + + for(int i = 0; i < selectionPoints.size(); i++){ + const int NUM_EDGES = 12; + int edges[NUM_EDGES][2]{{0, 1}, {1, 2}, {2, 3}, {3, 0}, {4, 5}, {5, 6}, {6, 7}, {7, 4}, {0, 4}, {1, 5}, {2, 6}, {3, 7}}; + + for(int j = 0; j < NUM_EDGES && (numAboveEdges == 0 || numBelowEdges == 0); j++){ + Vector2 vertA = cornersOnScreen[edges[j][0]], vertB = cornersOnScreen[edges[j][1]]; + float edgeHorLen = fabs(vertA.x - vertB.x), edgeVertLen = fabs(vertA.y - vertB.y); + + if(fabs(selectionPoints[i].x - vertA.x) < edgeHorLen && fabs(selectionPoints[i].x - vertB.x) < edgeHorLen){ + if(vertA.x > selectionPoints[i].x) swap(vertA, vertB); + + float horOffset = (selectionPoints[i].x - vertA.x) / edgeHorLen; + float height = vertA.y + (vertA.y < vertB.y ? 1 : -1) * horOffset * edgeVertLen; + + (selectionPoints[i].y > height ? numAboveEdges : numBelowEdges)++; + } + } + } + + return (numAboveEdges > 0 && numBelowEdges > 0); + } + + void ActiveGameState::renderUnits() { + vector friendlyUnits = mainPlayer->getFriendlyUnits(); + Game *game = Game::getSingleton(); + + for (Player *p : game->getPlayers(true)){ + vector units = p->getUnits(); + + for (Unit *u : units) { + if(u->isVehicle() && ((Vehicle*)u)->getGarrisonable()) continue; + + bool unitVisible = (game->isDebug() || mainPlayer->isObjectVisible((GameObject*)u, friendlyUnits)); + u->getModel()->setVisible(unitVisible); + } + } + } + + void ActiveGameState::updateDragBox() { + Vector2 mousePos = getCursorPos(), dragBoxOrigin, dragBoxEnd; + + if (mousePos.x >= clickPoint.x && mousePos.y >= clickPoint.y) { + dragBoxOrigin = Vector2(clickPoint.x, clickPoint.y); + dragBoxEnd = Vector2(mousePos.x, mousePos.y); + } + else if (mousePos.x < clickPoint.x && mousePos.y > clickPoint.y) { + dragBoxOrigin = Vector2(mousePos.x, clickPoint.y); + dragBoxEnd = Vector2(clickPoint.x, mousePos.y); + } + else if (mousePos.x >= clickPoint.x && mousePos.y < clickPoint.y) { + dragBoxOrigin = Vector2(clickPoint.x, mousePos.y); + dragBoxEnd = Vector2(mousePos.x, clickPoint.y); + } + else { + dragBoxOrigin = Vector2(mousePos.x, mousePos.y); + dragBoxEnd = Vector2(clickPoint.x, clickPoint.y); + } + + Vector3 size = Vector3(dragBoxEnd.x - dragBoxOrigin.x, dragBoxEnd.y - dragBoxOrigin.y, 0); + Quad *dragbox = (Quad*)dragboxNode->getMesh(0); + dragbox->setSize(size); + dragbox->updateVerts(dragbox->getMeshBase()); + dragboxNode->setPosition(Vector3(dragBoxOrigin.x, dragBoxOrigin.y, 0)); + } + + //TODO fix ejectable unit selection with multiple transports selected + //TODO replace shiftPressed with a dedicated buy flag + void ActiveGameState::issueOrder(Order::TYPE type, vector targets, bool addOrder) { + depth = 1; + Vector3 destDir = Vector3::VEC_ZERO; + + if(selectingDestOrient){ + GameObjectFrame &objFrame = GameObjectFrameController::getSingleton()->getGameObjectFrame(0); + destDir = objFrame.getDirVec(); + targets[0].pos = objFrame.getPos(); + } + + mainPlayer->issueOrder(type, destDir, targets, addOrder); + this->targets.clear(); + + if(cursorState != CursorState::ATTACK) + forceCursorState = false; + } + + void ActiveGameState::castRayToTerrain() { + Camera *cam = Root::getSingleton()->getCamera(); + Vector3 camPos = cam->getPosition(); + Vector3 endPos = screenToSpace(getCursorPos()); + + Vector3 rayDir = (endPos - camPos).norm(); + Map *map = Map::getSingleton(); + vector results = map->raycastTerrain(camPos, rayDir, true); + + if(!results.empty()) + targets.push_back(Order::Target(nullptr, results[0].pos)); + } + + void ActiveGameState::enableUnitState(Unit::State state){ + vector selectedUnits = mainPlayer->getSelectedUnits(); + + for(Unit *unit : selectedUnits) + unit->setState(state); + } + + void ActiveGameState::addUnitGui(){ + vector currSelectedUnits = mainPlayer->getSelectedUnits(); + + if(currSelectedUnits.empty()) return; + + ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton(); + + sol::state_view SOL_LUA_VIEW = generateView(); + SOL_LUA_VIEW.script("_mainUnitId = " + to_string(currSelectedUnits[0]->getId())); + guiManager->readLuaScreenScriptDel("unitGui.lua", unitButtons); + + SOL_LUA_VIEW.script("numGui = #gui"); + int numButtons = SOL_LUA_VIEW["numGui"]; + + for(int i = 0; i < numButtons; i++) + unitButtons.push_back(guiManager->getButtons()[guiManager->getButtons().size() - (i + 1)]); + } + + void ActiveGameState::onAction(int bind, bool isPressed) { + if(tradingScreen || !ConcreteGuiManager::getSingleton()->findClickedButtons().empty()) return; + + GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); + vector selectedUnits = mainPlayer->getSelectedUnits(); + + switch((Bind)bind){ + case Bind::DRAG_BOX: + selectMouseClicked = isPressed; + + if(isPressed){ + clickPoint = getCursorPos(); + lastSelectMouseClicked = getTime(); + } + else{ + if(!shiftPressed) deselectUnits(); + + if(canSelectHoveredOnGameObj()) + mainPlayer->selectUnit((Unit*)gameObjHoveredOn); + + selectingDestOrient = false; + + if(isSelectionBox){ + if(!shiftPressed) deselectUnits(); + + vector units = mainPlayer->getUnits(); + + for(Unit *un : units) + if(isGameObjSelectable(un, true)) + mainPlayer->selectUnit(un); + } + + isSelectionBox = false; + Quad *quad = (Quad*)dragboxNode->getMesh(0); + quad->setSize(Vector3::VEC_ZERO); + quad->updateVerts(quad->getMeshBase()); + + ufCtr->toggleFrameTransformations(false, false, false); + ufCtr->removeGameObjectFrames(); + } + + break; + case Bind::ROTATE_OBJ_FRAME: + orderMouseClicked = isPressed; + + if(isPressed) + lastOrderMouseClicked = getTime(); + else if(!(isPressed || selectedUnits.empty())){ + if(selectingPatrolPoints){ + castRayToTerrain(); + + if(!(targets.empty() || selectingPatrolPoints)){ + Order::TYPE type = Order::TYPE::MOVE; + + if(controlPressed || (targets[0].unit && targets[0].unit->getPlayer()->getTeam() != mainPlayer->getTeam())) + type = Order::TYPE::ATTACK; + else if(ufCtr->isPlacingOnSurface() && !selectingDestOrient) + type = Order::TYPE::BUILD; + + issueOrder(type, targets, shiftPressed); + } + } + else if(!isSelectionBox){ + bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam()); + + if(cursorState == CursorState::GARRISON){ + if(orderPossible) issueOrder(Order::TYPE::GARRISON, vector{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed); + } + else if(cursorState == CursorState::SUPPLY){ + if(orderPossible) issueOrder(Order::TYPE::SUPPLY, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); + } + else if(cursorState == CursorState::LOAD){ + if(orderPossible) issueOrder(Order::TYPE::LOAD, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); + } + else if(cursorState == CursorState::UNLOAD){ + if(orderPossible) issueOrder(Order::TYPE::UNLOAD, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); + } + else if(cursorState == CursorState::ATTACK){ + if(controlPressed && !gameObjHoveredOn){ + castRayToTerrain(); + issueOrder(Order::TYPE::ATTACK, targets, shiftPressed); + } + else{ + if(orderPossible) issueOrder(Order::TYPE::ATTACK, vector{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed); + } + } + else if(cursorState == CursorState::HACK){ + if(orderPossible) issueOrder(Order::TYPE::HACK, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); + } + else if(ufCtr->isPlacingOnSurface()){ + Order::TYPE type; + + switch(selectedUnits[0]->getUnitClass()){ + case UnitClass::ROBO_ENGINEER: + case UnitClass::CYBORG_ENGINEER: + case UnitClass::FREEZER: + type = Order::TYPE::BUILD; + break; + default: + return; + } + + targets.clear(); + + for(int i = 0; i < ufCtr->getNumGameObjectFrames(); i++){ + GameObjectFrame gmObjFr = ufCtr->getGameObjectFrame(i); + + if(gmObjFr.status == GameObjectFrame::BLOCKED_BY_DIFF_TERR) continue; + + Unit *buildStruct = GameObjectFactory::createUnit(mainPlayer, gmObjFr.getId(), gmObjFr.getPos(), gmObjFr.getRot()); + issueOrder(type, vector{Order::Target(buildStruct, gmObjFr.getPos())}, shiftPressed); + } + + buildableStructSelected = false; + } + else{ + if(targets.empty()) castRayToTerrain(); + + issueOrder(Order::TYPE::MOVE, targets, shiftPressed); + } + } + } + + break; + case Bind::MOVE_CAMERA: + break; + case Bind::ENABLE_CHASE_STATE: + if(isPressed) enableUnitState(Unit::State::CHASE); + break; + case Bind::ENABLE_STAND_GROUND_STATE: + if(isPressed) enableUnitState(Unit::State::STAND_GROUND); + break; + case Bind::ENABLE_HOLD_FIRE_STATE: + if(isPressed) enableUnitState(Unit::State::HOLD_FIRE); + break; + case Bind::EJECT_GARRISON: + if(isPressed) issueOrder(Order::TYPE::EJECT, vector{}, shiftPressed); + break; + case Bind::LAUNCH: + if(isPressed){ + castRayToTerrain(); + issueOrder(Order::TYPE::LAUNCH, targets, shiftPressed); + } + + break; + /* + case Bind::HACK: + if(isPressed){ + if(gameObjHoveredOn && gameObjHoveredOn->getType() == GameObject::Type::UNIT && gameObjHoveredOn->getPlayer()->getTeam() != mainPlayer->getTeam()) + issueOrder(Order::TYPE::HACK, vector{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed); + + break; + } + */ + case Bind::SHIFT_SUB_DEPTH: + ufCtr->toggleFrameTransformations(false, false, isPressed); + break; + case Bind::ZOOM_IN: + if (zooms > -NUM_MAX_ZOOMS) { + Camera *cam = Root::getSingleton()->getCamera(); + cam->setPosition(cam->getPosition() + cam->getDirection().norm() * .5f); + zooms--; + } + break; + case Bind::ZOOM_OUT: + if (zooms < NUM_MAX_ZOOMS) { + Camera *cam = Root::getSingleton()->getCamera(); + cam->setPosition(cam->getPosition() - (cam->getDirection().norm() * .5f)); + zooms++; + } + break; + case Bind::LOOK_AROUND: + if(!ufCtr->isPlacingOnSurface()) + CameraController::getSingleton()->setLookingAround(isPressed); + break; + case Bind::HALT: + if(isPressed) mainPlayer->haltUnits(); + break; + //TODO reimplement submarine diving mechanic + case Bind::LEFT_CONTROL: + if(isPressed) cursorState = CursorState::ATTACK; + + forceCursorState = isPressed; + controlPressed = isPressed; + orderPossible = isPressed; + break; + case Bind::LEFT_SHIFT: + { + shiftPressed = isPressed; + + ufCtr->setPaintSelecting(shiftPressed); + + if(isPressed){ + Vector3 startPos = Root::getSingleton()->getCamera()->getPosition(); + vector results = Map::getSingleton()->raycastTerrain(startPos, (screenToSpace(getCursorPos()) - startPos).norm(), true); + + if(!results.empty()) + ufCtr->setPaintSelectRowStart(results[0].pos); + } + } + break; + case Bind::SELECT_PATROL_POINTS: + /* + if(isPressed && mainPlayer->getNumSelectedUnits() > 0){ + targets.push_back(Order::Target(nullptr, mainPlayer->getSelectedUnit(0)->getPos())); + selectingPatrolPoints = isPressed; + } + */ + + break; + case Bind::GROUP_0: + case Bind::GROUP_1: + case Bind::GROUP_2: + case Bind::GROUP_3: + case Bind::GROUP_4: + case Bind::GROUP_5: + case Bind::GROUP_6: + case Bind::GROUP_7: + case Bind::GROUP_8: + case Bind::GROUP_9: + if(isPressed){ + int group = bind - Bind::GROUP_0; + + if(controlPressed) + unitGroups[group] = mainPlayer->getSelectedUnits(); + else{ + if(!shiftPressed) + mainPlayer->selectUnits(unitGroups[group]); + else + for(Unit *u : unitGroups[group]) + mainPlayer->selectUnit(u); + } + } + + break; + case Bind::DESELECT_STRUCTURE: + forceCursorState = false; + buildableStructSelected = false; + ufCtr->toggleFrameTransformations(false, false, false); + ufCtr->removeGameObjectFrames(); + break; + } + } + + void ActiveGameState::onAnalog(int bind, float strength) { + CameraController *camCtr = CameraController::getSingleton(); + GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton(); + + switch((Bind)bind){ + case Bind::LOOK_UP: + case Bind::LOOK_DOWN: + if(camCtr->isLookingAround()) { + Vector3 dirProj = Root::getSingleton()->getCamera()->getDirection(); + dirProj = Vector3(dirProj.x, 0, dirProj.z).norm(); + CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0).cross(dirProj), strength); + } + else if(ufCtr->isPlacingVertically()){ + depth -= .2 * strength; + + if(depth < 0) depth = 0; + else if(depth > 1) depth = 1; + } + + break; + case Bind::LOOK_LEFT: + case Bind::LOOK_RIGHT: + if(camCtr->isLookingAround()) + CameraController::getSingleton()->orientCamera(Vector3(0, 1, 0), strength); + else if(ufCtr->isRotating()) + ufCtr->rotateGameObjectFrames(100 * strength); + + break; + } + } + + void ActiveGameState::onRawMouseWheelScroll(bool up){ + CameraController::getSingleton()->zoomCamera(up); + } +} diff --git a/addResourceCommand.cpp b/Source/Systems/Private/addResourceCommand.cpp similarity index 100% rename from addResourceCommand.cpp rename to Source/Systems/Private/addResourceCommand.cpp diff --git a/addTechnologyCommand.cpp b/Source/Systems/Private/addTechnologyCommand.cpp similarity index 100% rename from addTechnologyCommand.cpp rename to Source/Systems/Private/addTechnologyCommand.cpp diff --git a/addUnitCommand.cpp b/Source/Systems/Private/addUnitCommand.cpp similarity index 100% rename from addUnitCommand.cpp rename to Source/Systems/Private/addUnitCommand.cpp diff --git a/console.cpp b/Source/Systems/Private/console.cpp old mode 100755 new mode 100644 similarity index 100% rename from console.cpp rename to Source/Systems/Private/console.cpp diff --git a/guiAppState.cpp b/Source/Systems/Private/guiAppState.cpp old mode 100755 new mode 100644 similarity index 95% rename from guiAppState.cpp rename to Source/Systems/Private/guiAppState.cpp index 456db38..378cb0e --- a/guiAppState.cpp +++ b/Source/Systems/Private/guiAppState.cpp @@ -1,119 +1,119 @@ -#include -#include - -#include -#include - -#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 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 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 +#include + +#include +#include + +#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 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 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(); + } +} diff --git a/inGameAppState.cpp b/Source/Systems/Private/inGameAppState.cpp old mode 100755 new mode 100644 similarity index 97% rename from inGameAppState.cpp rename to Source/Systems/Private/inGameAppState.cpp index 23b23de..04d7817 --- a/inGameAppState.cpp +++ b/Source/Systems/Private/inGameAppState.cpp @@ -1,103 +1,103 @@ -#include - -#include - -#include -#include -#include -#include - -#include - -#include "defConfigs.h" -#include "inGameAppState.h" -#include "game.h" -#include "console.h" -#include "gameObjectFrameController.h" -#include "concreteGuiManager.h" -#include "vessel.h" - -#include - -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 + +#include + +#include +#include +#include +#include + +#include + +#include "defConfigs.h" +#include "inGameAppState.h" +#include "game.h" +#include "console.h" +#include "gameObjectFrameController.h" +#include "concreteGuiManager.h" +#include "vessel.h" + +#include + +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) {} +} diff --git a/loadingAppState.cpp b/Source/Systems/Private/loadingAppState.cpp similarity index 100% rename from loadingAppState.cpp rename to Source/Systems/Private/loadingAppState.cpp diff --git a/mapEditorAppState.cpp b/Source/Systems/Private/mapEditorAppState.cpp similarity index 99% rename from mapEditorAppState.cpp rename to Source/Systems/Private/mapEditorAppState.cpp index 135200c..44a58b8 100644 --- a/mapEditorAppState.cpp +++ b/Source/Systems/Private/mapEditorAppState.cpp @@ -20,7 +20,7 @@ #include #define STB_IMAGE_WRITE_IMPLEMENTATION -#include "external/vb01/external/stb/stb_image_write.h" +#include #include diff --git a/toggleDebugCommand.cpp b/Source/Systems/Private/toggleDebugCommand.cpp similarity index 100% rename from toggleDebugCommand.cpp rename to Source/Systems/Private/toggleDebugCommand.cpp diff --git a/abstractCommand.h b/Source/Systems/Public/abstractCommand.h similarity index 100% rename from abstractCommand.h rename to Source/Systems/Public/abstractCommand.h diff --git a/activeGameState.h b/Source/Systems/Public/activeGameState.h old mode 100755 new mode 100644 similarity index 97% rename from activeGameState.h rename to Source/Systems/Public/activeGameState.h index fef0dcb..dd76498 --- a/activeGameState.h +++ b/Source/Systems/Public/activeGameState.h @@ -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 - -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 getGuiButtons(){return guiButtons;} - inline std::vector getGuiRects(){return guiRects;} - inline std::vector getGuiTexts(){return guiTexts;} - inline Player* getPlayer(){return mainPlayer;} - inline std::vector& 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); - 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, 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 unitGroups[9], prevSelectedUnits; - std::vector targets; - vb01::Node *dragboxNode = nullptr; - std::vector guiRects; - std::vector guiTexts; - std::vector 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 + +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 getGuiButtons(){return guiButtons;} + inline std::vector getGuiRects(){return guiRects;} + inline std::vector getGuiTexts(){return guiTexts;} + inline Player* getPlayer(){return mainPlayer;} + inline std::vector& 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); + 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, 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 unitGroups[9], prevSelectedUnits; + std::vector targets; + vb01::Node *dragboxNode = nullptr; + std::vector guiRects; + std::vector guiTexts; + std::vector 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 diff --git a/addResourceCommand.h b/Source/Systems/Public/addResourceCommand.h similarity index 100% rename from addResourceCommand.h rename to Source/Systems/Public/addResourceCommand.h diff --git a/addTechnologyCommand.h b/Source/Systems/Public/addTechnologyCommand.h similarity index 100% rename from addTechnologyCommand.h rename to Source/Systems/Public/addTechnologyCommand.h diff --git a/addUnitCommand.h b/Source/Systems/Public/addUnitCommand.h similarity index 100% rename from addUnitCommand.h rename to Source/Systems/Public/addUnitCommand.h diff --git a/console.h b/Source/Systems/Public/console.h old mode 100755 new mode 100644 similarity index 100% rename from console.h rename to Source/Systems/Public/console.h diff --git a/guiAppState.h b/Source/Systems/Public/guiAppState.h old mode 100755 new mode 100644 similarity index 96% rename from guiAppState.h rename to Source/Systems/Public/guiAppState.h index 3468766..b2fd3d7 --- a/guiAppState.h +++ b/Source/Systems/Public/guiAppState.h @@ -1,42 +1,42 @@ -#pragma once -#ifndef GUI_APP_STATE_H -#define GUI_APP_STATE_H - -#include -#include -#include -#include -#include - -#include - -#include - -#include "binds.h" -#include "tooltip.h" - -namespace battleship{ - class GuiAppState : public gameBase::AbstractAppState { - public: - GuiAppState(); - ~GuiAppState(); - void onAttached(); - void onDettached(); - void update(); - inline bool isLeftMousePressed(){return leftMousePressed;} - private: - virtual void onAction(int, bool); - virtual void onAnalog(int, float); - virtual void onRawKeyPress(int); - virtual void onRawCharPress(vb01::u32); - virtual void onRawMousePress(int); - virtual void onRawMouseWheelScroll(bool); - vb01Gui::Textbox* getOpenTextbox(); - vb01Gui::Listbox* getOpenListbox(); - - bool leftMousePressed = false, backspacePressed = false; - protected: - }; -} - -#endif +#pragma once +#ifndef GUI_APP_STATE_H +#define GUI_APP_STATE_H + +#include +#include +#include +#include +#include + +#include + +#include + +#include "binds.h" +#include "tooltip.h" + +namespace battleship{ + class GuiAppState : public gameBase::AbstractAppState { + public: + GuiAppState(); + ~GuiAppState(); + void onAttached(); + void onDettached(); + void update(); + inline bool isLeftMousePressed(){return leftMousePressed;} + private: + virtual void onAction(int, bool); + virtual void onAnalog(int, float); + virtual void onRawKeyPress(int); + virtual void onRawCharPress(vb01::u32); + virtual void onRawMousePress(int); + virtual void onRawMouseWheelScroll(bool); + vb01Gui::Textbox* getOpenTextbox(); + vb01Gui::Listbox* getOpenListbox(); + + bool leftMousePressed = false, backspacePressed = false; + protected: + }; +} + +#endif diff --git a/inGameAppState.h b/Source/Systems/Public/inGameAppState.h old mode 100755 new mode 100644 similarity index 96% rename from inGameAppState.h rename to Source/Systems/Public/inGameAppState.h index 14172d5..2a33a90 --- a/inGameAppState.h +++ b/Source/Systems/Public/inGameAppState.h @@ -1,60 +1,60 @@ -#pragma once -#ifndef IN_GAME_APP_STATE_H -#define IN_GAME_APP_STATE_H - -#include "gameManager.h" -#include "player.h" -#include "map.h" -#include "activeGameState.h" -#include "guiAppState.h" -#include "exitButton.h" -#include "optionsButton.h" - -#include - -//TODO refactor dependence on ActiveGameState -namespace battleship{ - class InGameAppState : public gameBase::AbstractAppState { - public: - class ResumeButton : public vb01Gui::Button { - public: - ResumeButton(vb01::Vector3, vb01::Vector2); - void onClick(); - private: - }; - - class ConsoleButton : public vb01Gui::Button { - public: - class ConsoleCommandEntryButton : public Button { - public: - ConsoleCommandEntryButton(vb01Gui::Textbox*, vb01Gui::Listbox*, vb01::Vector3, vb01::Vector2, std::string); - void onClick(); - private: - vb01Gui::Textbox *textbox; - vb01Gui::Listbox *listbox; - }; - - ConsoleButton(vb01::Vector3, vb01::Vector2); - void onClick(); - private: - }; - - InGameAppState(std::string); - ~InGameAppState(){} - void onAttached(); - void onDettached(); - void update(); - void onAction(int, bool); - void onAnalog(int, float); - std::vector getSelectedUnits(Player*); - inline ActiveGameState* getActiveState(){return activeState;} - private: - bool isMainMenuActive = false; - std::vector modelPaths; - int playerId; - std::string mapName = ""; - ActiveGameState* activeState; - }; -} - -#endif +#pragma once +#ifndef IN_GAME_APP_STATE_H +#define IN_GAME_APP_STATE_H + +#include "gameManager.h" +#include "player.h" +#include "map.h" +#include "activeGameState.h" +#include "guiAppState.h" +#include "exitButton.h" +#include "optionsButton.h" + +#include + +//TODO refactor dependence on ActiveGameState +namespace battleship{ + class InGameAppState : public gameBase::AbstractAppState { + public: + class ResumeButton : public vb01Gui::Button { + public: + ResumeButton(vb01::Vector3, vb01::Vector2); + void onClick(); + private: + }; + + class ConsoleButton : public vb01Gui::Button { + public: + class ConsoleCommandEntryButton : public Button { + public: + ConsoleCommandEntryButton(vb01Gui::Textbox*, vb01Gui::Listbox*, vb01::Vector3, vb01::Vector2, std::string); + void onClick(); + private: + vb01Gui::Textbox *textbox; + vb01Gui::Listbox *listbox; + }; + + ConsoleButton(vb01::Vector3, vb01::Vector2); + void onClick(); + private: + }; + + InGameAppState(std::string); + ~InGameAppState(){} + void onAttached(); + void onDettached(); + void update(); + void onAction(int, bool); + void onAnalog(int, float); + std::vector getSelectedUnits(Player*); + inline ActiveGameState* getActiveState(){return activeState;} + private: + bool isMainMenuActive = false; + std::vector modelPaths; + int playerId; + std::string mapName = ""; + ActiveGameState* activeState; + }; +} + +#endif diff --git a/loadingAppState.h b/Source/Systems/Public/loadingAppState.h similarity index 100% rename from loadingAppState.h rename to Source/Systems/Public/loadingAppState.h diff --git a/mapEditorAppState.h b/Source/Systems/Public/mapEditorAppState.h similarity index 100% rename from mapEditorAppState.h rename to Source/Systems/Public/mapEditorAppState.h diff --git a/toggleDebugCommand.h b/Source/Systems/Public/toggleDebugCommand.h similarity index 100% rename from toggleDebugCommand.h rename to Source/Systems/Public/toggleDebugCommand.h diff --git a/activeStateBackButton.cpp b/Source/UI/Private/activeStateBackButton.cpp similarity index 100% rename from activeStateBackButton.cpp rename to Source/UI/Private/activeStateBackButton.cpp diff --git a/activeStateButton.cpp b/Source/UI/Private/activeStateButton.cpp similarity index 100% rename from activeStateButton.cpp rename to Source/UI/Private/activeStateButton.cpp diff --git a/backButton.cpp b/Source/UI/Private/backButton.cpp similarity index 100% rename from backButton.cpp rename to Source/UI/Private/backButton.cpp diff --git a/buildButton.cpp b/Source/UI/Private/buildButton.cpp similarity index 100% rename from buildButton.cpp rename to Source/UI/Private/buildButton.cpp diff --git a/concreteGuiManager.cpp b/Source/UI/Private/concreteGuiManager.cpp similarity index 100% rename from concreteGuiManager.cpp rename to Source/UI/Private/concreteGuiManager.cpp diff --git a/defaultsButton.cpp b/Source/UI/Private/defaultsButton.cpp similarity index 100% rename from defaultsButton.cpp rename to Source/UI/Private/defaultsButton.cpp diff --git a/exitButton.cpp b/Source/UI/Private/exitButton.cpp old mode 100755 new mode 100644 similarity index 100% rename from exitButton.cpp rename to Source/UI/Private/exitButton.cpp diff --git a/exportButton.cpp b/Source/UI/Private/exportButton.cpp similarity index 100% rename from exportButton.cpp rename to Source/UI/Private/exportButton.cpp diff --git a/gameObjectFrame.cpp b/Source/UI/Private/gameObjectFrame.cpp similarity index 100% rename from gameObjectFrame.cpp rename to Source/UI/Private/gameObjectFrame.cpp diff --git a/gameObjectFrameController.cpp b/Source/UI/Private/gameObjectFrameController.cpp similarity index 100% rename from gameObjectFrameController.cpp rename to Source/UI/Private/gameObjectFrameController.cpp diff --git a/gameObjectListbox.cpp b/Source/UI/Private/gameObjectListbox.cpp similarity index 100% rename from gameObjectListbox.cpp rename to Source/UI/Private/gameObjectListbox.cpp diff --git a/landTextureListbox.cpp b/Source/UI/Private/landTextureListbox.cpp similarity index 100% rename from landTextureListbox.cpp rename to Source/UI/Private/landTextureListbox.cpp diff --git a/loadMapButton.cpp b/Source/UI/Private/loadMapButton.cpp similarity index 100% rename from loadMapButton.cpp rename to Source/UI/Private/loadMapButton.cpp diff --git a/mainMenuButton.cpp b/Source/UI/Private/mainMenuButton.cpp similarity index 100% rename from mainMenuButton.cpp rename to Source/UI/Private/mainMenuButton.cpp diff --git a/mapEditorButton.cpp b/Source/UI/Private/mapEditorButton.cpp similarity index 100% rename from mapEditorButton.cpp rename to Source/UI/Private/mapEditorButton.cpp diff --git a/mapListbox.cpp b/Source/UI/Private/mapListbox.cpp similarity index 100% rename from mapListbox.cpp rename to Source/UI/Private/mapListbox.cpp diff --git a/minimapButton.cpp b/Source/UI/Private/minimapButton.cpp similarity index 100% rename from minimapButton.cpp rename to Source/UI/Private/minimapButton.cpp diff --git a/newMapButton.cpp b/Source/UI/Private/newMapButton.cpp similarity index 100% rename from newMapButton.cpp rename to Source/UI/Private/newMapButton.cpp diff --git a/offerButton.cpp b/Source/UI/Private/offerButton.cpp similarity index 100% rename from offerButton.cpp rename to Source/UI/Private/offerButton.cpp diff --git a/okButton.cpp b/Source/UI/Private/okButton.cpp similarity index 100% rename from okButton.cpp rename to Source/UI/Private/okButton.cpp diff --git a/optionsButton.cpp b/Source/UI/Private/optionsButton.cpp old mode 100755 new mode 100644 similarity index 96% rename from optionsButton.cpp rename to Source/UI/Private/optionsButton.cpp index d7297c7..1694a2e --- a/optionsButton.cpp +++ b/Source/UI/Private/optionsButton.cpp @@ -1,15 +1,15 @@ -#include "optionsButton.h" -#include "gameManager.h" -#include "concreteGuiManager.h" - -using namespace vb01Gui; -using namespace vb01; -using namespace std; - -namespace battleship{ - OptionsButton::OptionsButton(Vector3 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {} - - void OptionsButton::onClick() { - ConcreteGuiManager::getSingleton()->readLuaScreenScript("options.lua"); - } -} +#include "optionsButton.h" +#include "gameManager.h" +#include "concreteGuiManager.h" + +using namespace vb01Gui; +using namespace vb01; +using namespace std; + +namespace battleship{ + OptionsButton::OptionsButton(Vector3 pos, Vector2 size, string name, bool separate) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, separate) {} + + void OptionsButton::onClick() { + ConcreteGuiManager::getSingleton()->readLuaScreenScript("options.lua"); + } +} diff --git a/orderButton.cpp b/Source/UI/Private/orderButton.cpp similarity index 100% rename from orderButton.cpp rename to Source/UI/Private/orderButton.cpp diff --git a/playButton.cpp b/Source/UI/Private/playButton.cpp similarity index 99% rename from playButton.cpp rename to Source/UI/Private/playButton.cpp index 785f5ef..4f5d38c 100644 --- a/playButton.cpp +++ b/Source/UI/Private/playButton.cpp @@ -7,7 +7,7 @@ #include -#include +#include namespace battleship{ using namespace std; diff --git a/playerTradeButton.cpp b/Source/UI/Private/playerTradeButton.cpp similarity index 100% rename from playerTradeButton.cpp rename to Source/UI/Private/playerTradeButton.cpp diff --git a/researchButton.cpp b/Source/UI/Private/researchButton.cpp similarity index 100% rename from researchButton.cpp rename to Source/UI/Private/researchButton.cpp diff --git a/resourceAmmountButton.cpp b/Source/UI/Private/resourceAmmountButton.cpp similarity index 100% rename from resourceAmmountButton.cpp rename to Source/UI/Private/resourceAmmountButton.cpp diff --git a/singlePlayerButton.cpp b/Source/UI/Private/singlePlayerButton.cpp similarity index 94% rename from singlePlayerButton.cpp rename to Source/UI/Private/singlePlayerButton.cpp index ef29559..82cb408 100644 --- a/singlePlayerButton.cpp +++ b/Source/UI/Private/singlePlayerButton.cpp @@ -1,31 +1,31 @@ -#include "singlePlayerButton.h" -#include "gameManager.h" -#include "concreteGuiManager.h" - -#include - -#include - -namespace battleship{ - using namespace std; - using namespace vb01; - using namespace vb01Gui; - - SinglePlayerButton::SinglePlayerButton(Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_S, true) {} - - void SinglePlayerButton::onMouseOver(){ - setColor(Vector4(.8, .8, .8, 1)); - } - - void SinglePlayerButton::onMouseOff(){ - setColor(Vector4(.6, .6, .6, 1)); - } - - void SinglePlayerButton::onClick() { - ConcreteGuiManager::getSingleton()->readLuaScreenScript("singlePlayerMenu.lua"); - - Listbox *listbox = ConcreteGuiManager::getSingleton()->getListboxes()[0]; - listbox->openUp(); - listbox->close(); - } -} +#include "singlePlayerButton.h" +#include "gameManager.h" +#include "concreteGuiManager.h" + +#include + +#include + +namespace battleship{ + using namespace std; + using namespace vb01; + using namespace vb01Gui; + + SinglePlayerButton::SinglePlayerButton(Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", GLFW_KEY_S, true) {} + + void SinglePlayerButton::onMouseOver(){ + setColor(Vector4(.8, .8, .8, 1)); + } + + void SinglePlayerButton::onMouseOff(){ + setColor(Vector4(.6, .6, .6, 1)); + } + + void SinglePlayerButton::onClick() { + ConcreteGuiManager::getSingleton()->readLuaScreenScript("singlePlayerMenu.lua"); + + Listbox *listbox = ConcreteGuiManager::getSingleton()->getListboxes()[0]; + listbox->openUp(); + listbox->close(); + } +} diff --git a/skyboxTextureListbox.cpp b/Source/UI/Private/skyboxTextureListbox.cpp similarity index 100% rename from skyboxTextureListbox.cpp rename to Source/UI/Private/skyboxTextureListbox.cpp diff --git a/stateToggleButton.cpp b/Source/UI/Private/stateToggleButton.cpp similarity index 100% rename from stateToggleButton.cpp rename to Source/UI/Private/stateToggleButton.cpp diff --git a/statsButton.cpp b/Source/UI/Private/statsButton.cpp similarity index 100% rename from statsButton.cpp rename to Source/UI/Private/statsButton.cpp diff --git a/tabButton.cpp b/Source/UI/Private/tabButton.cpp similarity index 100% rename from tabButton.cpp rename to Source/UI/Private/tabButton.cpp diff --git a/tooltip.cpp b/Source/UI/Private/tooltip.cpp similarity index 100% rename from tooltip.cpp rename to Source/UI/Private/tooltip.cpp diff --git a/tradeButton.cpp b/Source/UI/Private/tradeButton.cpp similarity index 100% rename from tradeButton.cpp rename to Source/UI/Private/tradeButton.cpp diff --git a/tradingScreenButton.cpp b/Source/UI/Private/tradingScreenButton.cpp similarity index 100% rename from tradingScreenButton.cpp rename to Source/UI/Private/tradingScreenButton.cpp diff --git a/trainButton.cpp b/Source/UI/Private/trainButton.cpp similarity index 100% rename from trainButton.cpp rename to Source/UI/Private/trainButton.cpp diff --git a/unitButton.cpp b/Source/UI/Private/unitButton.cpp similarity index 100% rename from unitButton.cpp rename to Source/UI/Private/unitButton.cpp diff --git a/activeStateBackButton.h b/Source/UI/Public/activeStateBackButton.h similarity index 100% rename from activeStateBackButton.h rename to Source/UI/Public/activeStateBackButton.h diff --git a/activeStateButton.h b/Source/UI/Public/activeStateButton.h similarity index 100% rename from activeStateButton.h rename to Source/UI/Public/activeStateButton.h diff --git a/backButton.h b/Source/UI/Public/backButton.h similarity index 100% rename from backButton.h rename to Source/UI/Public/backButton.h diff --git a/buildButton.h b/Source/UI/Public/buildButton.h similarity index 100% rename from buildButton.h rename to Source/UI/Public/buildButton.h diff --git a/concreteGuiManager.h b/Source/UI/Public/concreteGuiManager.h similarity index 100% rename from concreteGuiManager.h rename to Source/UI/Public/concreteGuiManager.h diff --git a/defaultsButton.h b/Source/UI/Public/defaultsButton.h similarity index 100% rename from defaultsButton.h rename to Source/UI/Public/defaultsButton.h diff --git a/exitButton.h b/Source/UI/Public/exitButton.h old mode 100755 new mode 100644 similarity index 100% rename from exitButton.h rename to Source/UI/Public/exitButton.h diff --git a/exportButton.h b/Source/UI/Public/exportButton.h similarity index 100% rename from exportButton.h rename to Source/UI/Public/exportButton.h diff --git a/gameObjectFrame.h b/Source/UI/Public/gameObjectFrame.h similarity index 100% rename from gameObjectFrame.h rename to Source/UI/Public/gameObjectFrame.h diff --git a/gameObjectFrameController.h b/Source/UI/Public/gameObjectFrameController.h similarity index 100% rename from gameObjectFrameController.h rename to Source/UI/Public/gameObjectFrameController.h diff --git a/gameObjectListbox.h b/Source/UI/Public/gameObjectListbox.h similarity index 100% rename from gameObjectListbox.h rename to Source/UI/Public/gameObjectListbox.h diff --git a/landTextureListbox.h b/Source/UI/Public/landTextureListbox.h similarity index 100% rename from landTextureListbox.h rename to Source/UI/Public/landTextureListbox.h diff --git a/loadMapButton.h b/Source/UI/Public/loadMapButton.h similarity index 100% rename from loadMapButton.h rename to Source/UI/Public/loadMapButton.h diff --git a/mainMenuButton.h b/Source/UI/Public/mainMenuButton.h similarity index 100% rename from mainMenuButton.h rename to Source/UI/Public/mainMenuButton.h diff --git a/mapEditorButton.h b/Source/UI/Public/mapEditorButton.h similarity index 100% rename from mapEditorButton.h rename to Source/UI/Public/mapEditorButton.h diff --git a/mapListbox.h b/Source/UI/Public/mapListbox.h similarity index 100% rename from mapListbox.h rename to Source/UI/Public/mapListbox.h diff --git a/minimapButton.h b/Source/UI/Public/minimapButton.h similarity index 100% rename from minimapButton.h rename to Source/UI/Public/minimapButton.h diff --git a/newMapButton.h b/Source/UI/Public/newMapButton.h similarity index 100% rename from newMapButton.h rename to Source/UI/Public/newMapButton.h diff --git a/offerButton.h b/Source/UI/Public/offerButton.h similarity index 100% rename from offerButton.h rename to Source/UI/Public/offerButton.h diff --git a/okButton.h b/Source/UI/Public/okButton.h similarity index 100% rename from okButton.h rename to Source/UI/Public/okButton.h diff --git a/optionsButton.h b/Source/UI/Public/optionsButton.h old mode 100755 new mode 100644 similarity index 95% rename from optionsButton.h rename to Source/UI/Public/optionsButton.h index 98a5681..becfa2b --- a/optionsButton.h +++ b/Source/UI/Public/optionsButton.h @@ -1,15 +1,15 @@ -#pragma once -#ifndef OPTIONS_BUTTON_H -#define OPTIONS_BUTTON_H - -#include - -namespace battleship { - class OptionsButton : public vb01Gui::Button { - public: - OptionsButton(vb01::Vector3, vb01::Vector2, std::string, bool); - virtual void onClick(); - }; -} - -#endif +#pragma once +#ifndef OPTIONS_BUTTON_H +#define OPTIONS_BUTTON_H + +#include + +namespace battleship { + class OptionsButton : public vb01Gui::Button { + public: + OptionsButton(vb01::Vector3, vb01::Vector2, std::string, bool); + virtual void onClick(); + }; +} + +#endif diff --git a/orderButton.h b/Source/UI/Public/orderButton.h similarity index 100% rename from orderButton.h rename to Source/UI/Public/orderButton.h diff --git a/playButton.h b/Source/UI/Public/playButton.h similarity index 100% rename from playButton.h rename to Source/UI/Public/playButton.h diff --git a/playerTradeButton.h b/Source/UI/Public/playerTradeButton.h similarity index 100% rename from playerTradeButton.h rename to Source/UI/Public/playerTradeButton.h diff --git a/researchButton.h b/Source/UI/Public/researchButton.h similarity index 100% rename from researchButton.h rename to Source/UI/Public/researchButton.h diff --git a/resourceAmmountButton.h b/Source/UI/Public/resourceAmmountButton.h similarity index 100% rename from resourceAmmountButton.h rename to Source/UI/Public/resourceAmmountButton.h diff --git a/singlePlayerButton.h b/Source/UI/Public/singlePlayerButton.h similarity index 94% rename from singlePlayerButton.h rename to Source/UI/Public/singlePlayerButton.h index 09e0224..3b3dff6 100644 --- a/singlePlayerButton.h +++ b/Source/UI/Public/singlePlayerButton.h @@ -1,19 +1,19 @@ -#ifndef SINGLE_PLAYER_BUTTON_H -#define SINGLE_PLAYER_BUTTON_H - -#include - -#include - -namespace battleship{ - class SinglePlayerButton : public vb01Gui::Button { - public: - SinglePlayerButton(vb01::Vector3, vb01::Vector2, std::string); - void onClick(); - void onMouseOver(); - void onMouseOff(); - private: - }; -} - -#endif +#ifndef SINGLE_PLAYER_BUTTON_H +#define SINGLE_PLAYER_BUTTON_H + +#include + +#include + +namespace battleship{ + class SinglePlayerButton : public vb01Gui::Button { + public: + SinglePlayerButton(vb01::Vector3, vb01::Vector2, std::string); + void onClick(); + void onMouseOver(); + void onMouseOff(); + private: + }; +} + +#endif diff --git a/skyboxTextureListbox.h b/Source/UI/Public/skyboxTextureListbox.h similarity index 100% rename from skyboxTextureListbox.h rename to Source/UI/Public/skyboxTextureListbox.h diff --git a/stateToggleButton.h b/Source/UI/Public/stateToggleButton.h similarity index 100% rename from stateToggleButton.h rename to Source/UI/Public/stateToggleButton.h diff --git a/statsButton.h b/Source/UI/Public/statsButton.h similarity index 100% rename from statsButton.h rename to Source/UI/Public/statsButton.h diff --git a/tabButton.h b/Source/UI/Public/tabButton.h similarity index 100% rename from tabButton.h rename to Source/UI/Public/tabButton.h diff --git a/tooltip.h b/Source/UI/Public/tooltip.h similarity index 100% rename from tooltip.h rename to Source/UI/Public/tooltip.h diff --git a/tradeButton.h b/Source/UI/Public/tradeButton.h similarity index 100% rename from tradeButton.h rename to Source/UI/Public/tradeButton.h diff --git a/tradingScreenButton.h b/Source/UI/Public/tradingScreenButton.h similarity index 100% rename from tradingScreenButton.h rename to Source/UI/Public/tradingScreenButton.h diff --git a/trainButton.h b/Source/UI/Public/trainButton.h similarity index 100% rename from trainButton.h rename to Source/UI/Public/trainButton.h diff --git a/unitButton.h b/Source/UI/Public/unitButton.h similarity index 100% rename from unitButton.h rename to Source/UI/Public/unitButton.h diff --git a/mapTest.cpp b/Tests/mapTest.cpp similarity index 100% rename from mapTest.cpp rename to Tests/mapTest.cpp diff --git a/mapTest.h b/Tests/mapTest.h similarity index 100% rename from mapTest.h rename to Tests/mapTest.h diff --git a/pathfinderTest.cpp b/Tests/pathfinderTest.cpp similarity index 100% rename from pathfinderTest.cpp rename to Tests/pathfinderTest.cpp diff --git a/pathfinderTest.h b/Tests/pathfinderTest.h similarity index 100% rename from pathfinderTest.h rename to Tests/pathfinderTest.h diff --git a/testMain.cpp b/Tests/testMain.cpp similarity index 100% rename from testMain.cpp rename to Tests/testMain.cpp diff --git a/external/gameBase b/external/gameBase deleted file mode 160000 index 0002879..0000000 --- a/external/gameBase +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 0002879d41eaa41e6f0a773e9d08f9fa96e057d4 diff --git a/external/tinydir b/external/tinydir deleted file mode 160000 index 9f866c1..0000000 --- a/external/tinydir +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 9f866c1ec09e62aa4df50d7209556ed705a4dd90 diff --git a/external/vb01 b/external/vb01 deleted file mode 160000 index 7f8b6fe..0000000 --- a/external/vb01 +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 7f8b6fe03a48a8579286fb75404d96dcb2b9bdea