mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
Created new folder structure with updates to CMakeLists.txt
This commit is contained in:
@@ -0,0 +1 @@
|
||||
build/
|
||||
+30
-22
@@ -1,4 +1,4 @@
|
||||
cmake_minimum_required(VERSION 3.5)
|
||||
cmake_minimum_required(VERSION 3.10)
|
||||
|
||||
set(GAME_NAME battleship)
|
||||
project(${GAME_NAME})
|
||||
@@ -16,31 +16,30 @@ 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(STATES src/Core/activeGameState.cpp src/Core/inGameAppState.cpp src/Core/guiAppState.cpp src/Core/mapEditorAppState.cpp src/Core/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(UNIT_BUTTONS src/UI/unitButton.cpp src/UI/tradeButton.cpp src/UI/buildButton.cpp src/UI/trainButton.cpp src/UI/researchButton.cpp src/UI/orderButton.cpp src/UI/stateToggleButton.cpp)
|
||||
set(OPTIONS_BUTTONS src/UI/optionsButton.cpp src/UI/tabButton.cpp src/UI/okButton.cpp src/UI/defaultsButton.cpp)
|
||||
set(TRADING_BUTTONS src/UI/activeStateBackButton.cpp src/UI/playerTradeButton.cpp src/UI/tradingScreenButton.cpp src/UI/offerButton.cpp src/UI/resourceAmmountButton.cpp)
|
||||
set(MENU_BUTTONS src/UI/mainMenuButton.cpp src/UI/singlePlayerButton.cpp src/UI/exitButton.cpp src/UI/backButton.cpp src/UI/playButton.cpp)
|
||||
set(MAP_EDITOR_BUTTONS src/UI/mapEditorButton.cpp src/UI/newMapButton.cpp src/UI/loadMapButton.cpp src/UI/exportButton.cpp)
|
||||
set(BUTTONS src/UI/statsButton.cpp src/UI/activeStateButton.cpp src/UI/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(LISTBOXES src/UI/skyboxTextureListbox.cpp src/UI/landTextureListbox.cpp src/UI/gameObjectListbox.cpp src/UI/mapListbox.cpp)
|
||||
set(GUI src/UI/tooltip.cpp src/Core/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(CONTROLLERS src/UI/gameObjectFrameController.cpp src/Map/cameraController.cpp)
|
||||
set(CONSOLE src/Core/console.cpp src/Commands/abstractCommand.cpp src/Commands/addUnitCommand.cpp src/Commands/addResourceCommand.cpp src/Commands/addTechnologyCommand.cpp src/Commands/toggleDebugCommand.cpp)
|
||||
set(CORE src/Core/gameManager.cpp src/Core/game.cpp src/Core/pathfinder.cpp src/Core/environment.cpp src/Core/fxManager.cpp src/Core/defConfigs.cpp src/Core/player.cpp src/Core/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(PROJECTILES src/Entities/projectile.cpp src/Entities/missile.cpp src/Entities/cruiseMissile.cpp src/Entities/shell.cpp src/Entities/depthCharge.cpp src/Entities/torpedo.cpp src/Entities/torpedo.h)
|
||||
set(VEHICLES src/Entities/vehicle.cpp src/Entities/submarine.cpp src/Entities/engineer.cpp src/Entities/resourceRover.cpp src/Entities/freezer.cpp)
|
||||
set(STRUCTURES src/Entities/structure.cpp src/Entities/factory.cpp src/Entities/pointDefense.cpp src/Entities/extractor.cpp src/Entities/researchStruct.cpp src/Entities/iceSheet.cpp)
|
||||
set(WEAPONS src/Entities/weapon.cpp)
|
||||
set(UNITS src/Entities/unit.cpp ${WEAPONS} ${STRUCTURES} ${VEHICLES})
|
||||
set(CONTENT src/Map/map.cpp src/Entities/gameObject.cpp src/EntityComponents/destructable.cpp src/UI/gameObjectFrame.h src/Entities/gameObjectFactory.cpp src/Entities/resourceDeposit.cpp ${UNITS} ${PROJECTILES})
|
||||
|
||||
set(UTIL src/Core/util.cpp src/Core/binds.h)
|
||||
set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL})
|
||||
|
||||
set(SFML_DIR external/gameBase/external/SFML)
|
||||
@@ -48,13 +47,22 @@ 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})
|
||||
add_executable(${GAME_NAME} src/Core/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)
|
||||
|
||||
target_include_directories(${GAME_NAME} PRIVATE
|
||||
src/Core
|
||||
src/Entities
|
||||
src/EntityComponents
|
||||
src/UI
|
||||
src/Commands
|
||||
src/Map
|
||||
)
|
||||
|
||||
add_subdirectory(${VB01_DIR})
|
||||
set(VB01_LIB_DIR ${VB01_DIR}/build)
|
||||
target_include_directories(${GAME_NAME} PUBLIC ${VB01_DIR})
|
||||
|
||||
@@ -1,857 +0,0 @@
|
||||
#include <root.h>
|
||||
#include <quaternion.h>
|
||||
#include <model.h>
|
||||
#include <material.h>
|
||||
#include <texture.h>
|
||||
#include <quad.h>
|
||||
#include <box.h>
|
||||
#include <text.h>
|
||||
#include <assetManager.h>
|
||||
#include <imageAsset.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <solUtil.h>
|
||||
|
||||
#include <algorithm>
|
||||
#include <ctype.h>
|
||||
#include <stdlib.h>
|
||||
#include <map>
|
||||
|
||||
#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<Button*> buttons = guiButtons;
|
||||
buttons.insert(buttons.end(), unitButtons.begin(), unitButtons.end());
|
||||
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript(
|
||||
"activeGameState.lua",
|
||||
buttons,
|
||||
vector<Listbox*>{},
|
||||
vector<Checkbox*>{},
|
||||
vector<Slider*>{},
|
||||
vector<Textbox*>{},
|
||||
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<TradeOffer*> offers = (gameObjHoveredOn && alliedGameObj ? mainPlayer->getTradeOffers(gameObjHoveredOn->getPlayer()) : vector<TradeOffer*>{});
|
||||
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<Unit*> 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<Unit*> 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<GameObject*> gameObjs;
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers(true);
|
||||
|
||||
for(Player *pl : players){
|
||||
vector<ResourceDeposit*> resDeps = pl->getResourceDeposits();
|
||||
vector<Unit*> 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<Unit*> units){
|
||||
vector<Unit*> 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<Vector2> 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>{
|
||||
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<Vector2>{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<Unit*> friendlyUnits = mainPlayer->getFriendlyUnits();
|
||||
Game *game = Game::getSingleton();
|
||||
|
||||
for (Player *p : game->getPlayers(true)){
|
||||
vector<Unit*> 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<Order::Target> 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<RayCaster::CollisionResult> 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<Unit*> selectedUnits = mainPlayer->getSelectedUnits();
|
||||
|
||||
for(Unit *unit : selectedUnits)
|
||||
unit->setState(state);
|
||||
}
|
||||
|
||||
void ActiveGameState::addUnitGui(){
|
||||
vector<Unit*> 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<Unit*> 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<Unit*> 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>{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed);
|
||||
}
|
||||
else if(cursorState == CursorState::SUPPLY){
|
||||
if(orderPossible) issueOrder(Order::TYPE::SUPPLY, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed);
|
||||
}
|
||||
else if(cursorState == CursorState::LOAD){
|
||||
if(orderPossible) issueOrder(Order::TYPE::LOAD, vector<Order::Target>{Order::Target((Unit*)gameObjHoveredOn)}, shiftPressed);
|
||||
}
|
||||
else if(cursorState == CursorState::UNLOAD){
|
||||
if(orderPossible) issueOrder(Order::TYPE::UNLOAD, vector<Order::Target>{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>{Order::Target((Unit*)gameObjHoveredOn, gameObjHoveredOn->getPos())}, shiftPressed);
|
||||
}
|
||||
}
|
||||
else if(cursorState == CursorState::HACK){
|
||||
if(orderPossible) issueOrder(Order::TYPE::HACK, vector<Order::Target>{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::NOT_PLACEABLE) continue;
|
||||
|
||||
Unit *buildStruct = GameObjectFactory::createUnit(mainPlayer, gmObjFr.getId(), gmObjFr.getPos(), gmObjFr.getRot());
|
||||
issueOrder(type, vector<Order::Target>{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<Order::Target>{}, 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>{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<RayCaster::CollisionResult> 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);
|
||||
}
|
||||
}
|
||||
@@ -1,112 +0,0 @@
|
||||
#ifndef ACTIVE_GAME_STATE_H
|
||||
#define ACTIVE_GAME_STATE_H
|
||||
|
||||
#include "guiAppState.h"
|
||||
#include "player.h"
|
||||
#include "map.h"
|
||||
#include "unit.h"
|
||||
|
||||
#include <util.h>
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
class Texture;
|
||||
}
|
||||
|
||||
namespace vb01Gui{
|
||||
class Button;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class GameObject;
|
||||
class Unit;
|
||||
class UnitButton;
|
||||
|
||||
class ActiveGameState : public gameBase::AbstractAppState {
|
||||
public:
|
||||
enum CursorState{
|
||||
NORMAL,
|
||||
ATTACK,
|
||||
GARRISON,
|
||||
SUPPLY,
|
||||
LOAD,
|
||||
UNLOAD,
|
||||
HACK
|
||||
};
|
||||
|
||||
ActiveGameState(GuiAppState*, int);
|
||||
~ActiveGameState();
|
||||
void onAttached();
|
||||
void onDettached();
|
||||
void update();
|
||||
void onAction(int, bool);
|
||||
void onAnalog(int, float);
|
||||
void onRawMouseWheelScroll(bool);
|
||||
inline CursorState getCursorState(){return cursorState;}
|
||||
inline void setCursorState(CursorState cs){this->cursorState = cs;}
|
||||
inline void addButton(vb01Gui::Button *b){guiButtons.push_back(b);}
|
||||
inline std::vector<vb01Gui::Button*> getGuiButtons(){return guiButtons;}
|
||||
inline std::vector<vb01::Node*> getGuiRects(){return guiRects;}
|
||||
inline std::vector<vb01::Text*> getGuiTexts(){return guiTexts;}
|
||||
inline Player* getPlayer(){return mainPlayer;}
|
||||
inline std::vector<Unit*>& getUnitGroup(int i){return unitGroups[i];}
|
||||
inline void setBuildableStructSelected(bool bss){this->buildableStructSelected = bss;}
|
||||
inline bool isBuildableStructSelected(){return buildableStructSelected;}
|
||||
inline float getDepth(){return depth;}
|
||||
inline void setForceCursorState(bool force){this->forceCursorState = force;}
|
||||
inline bool isForceCursorState(){return forceCursorState;}
|
||||
inline void setTradingScreen(bool ts){this->tradingScreen = ts;}
|
||||
inline bool isTradingScreen(){return tradingScreen;}
|
||||
inline void setOfferScreen(bool os){this->offerScreen = os;}
|
||||
inline bool isOfferScreen(){return offerScreen;}
|
||||
private:
|
||||
bool selectedUnitsAmongst(std::vector<Unit*>);
|
||||
void updateGameObjHoveredOn();
|
||||
void initCursor();
|
||||
void updateCursor();
|
||||
void initDragbox();
|
||||
void removeDragbox();
|
||||
bool isGameObjSelectable(GameObject*, bool);
|
||||
void deselectUnits();
|
||||
void renderUnits();
|
||||
void updateDragBox();
|
||||
void updateStructureFrames();
|
||||
void castRayToTerrain();
|
||||
void issueOrder(Order::TYPE, std::vector<Order::Target>, bool);
|
||||
void enableUnitState(Unit::State);
|
||||
void addUnitGui();
|
||||
inline bool canSelectHoveredOnGameObj(){return gameObjHoveredOn && gameObjHoveredOn->isSelectable() && gameObjHoveredOn->getPlayer() == mainPlayer;}
|
||||
|
||||
CursorState cursorState = CursorState::NORMAL;
|
||||
Player *mainPlayer;
|
||||
GuiAppState *guiState;
|
||||
GameObject *gameObjHoveredOn = nullptr;
|
||||
vb01::Vector2 clickPoint;
|
||||
std::vector<Unit*> unitGroups[9], prevSelectedUnits;
|
||||
std::vector<Order::Target> targets;
|
||||
vb01::Node *dragboxNode = nullptr;
|
||||
std::vector<vb01::Node*> guiRects;
|
||||
std::vector<vb01::Text*> guiTexts;
|
||||
std::vector<vb01Gui::Button*> guiButtons, unitButtons;
|
||||
bool isSelectionBox = false;
|
||||
bool shiftPressed = false;
|
||||
bool controlPressed = false;
|
||||
bool selectMouseClicked = false;
|
||||
bool orderMouseClicked = false;
|
||||
bool buildableStructSelected = false;
|
||||
bool selectingPatrolPoints = false;
|
||||
bool selectingDestOrient = false;
|
||||
bool forceCursorState = false;
|
||||
bool orderPossible = false;
|
||||
bool tradingScreen = false;
|
||||
bool offerScreen = false;
|
||||
int playerId, zooms = 0;
|
||||
const int NUM_MAX_ZOOMS = 10;
|
||||
float depth = 1;
|
||||
vb01::s64 lastSelectMouseClicked = 0, lastOrderMouseClicked = 0;
|
||||
vb01::Node *cursorNode = nullptr;
|
||||
vb01::Texture *pointerTex = nullptr, *attackTex = nullptr, *garrisonTex = nullptr, *noGarrisonTex = nullptr, *supplyTex = nullptr, *noSupplyTex = nullptr, *hackTex = nullptr, *noHackTex = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifndef ADD_UNIT_COMMAND_H
|
||||
#define ADD_UNIT_COMMAND_H
|
||||
|
||||
#include "abstractCommand.h"
|
||||
|
||||
#include <vector.h>
|
||||
#include <quaternion.h>
|
||||
|
||||
namespace battleship{
|
||||
class AddUnitCommand : public AbstractCommand{
|
||||
public:
|
||||
AddUnitCommand(std::string argsStr) : AbstractCommand(argsStr){}
|
||||
void validate();
|
||||
void execute();
|
||||
private:
|
||||
int playerId, unitId;
|
||||
bool posEnabled, rotEnabled;
|
||||
vb01::Vector3 pos = vb01::Vector3::VEC_ZERO;
|
||||
vb01::Quaternion rot = vb01::Quaternion::QUAT_W;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifndef CAMERA_CONTROLLER_H
|
||||
#define CAMERA_CONTROLLER_H
|
||||
|
||||
#include <vector.h>
|
||||
|
||||
namespace battleship{
|
||||
class CameraController{
|
||||
public:
|
||||
static CameraController* getSingleton();
|
||||
void updateCameraPosition();
|
||||
void orientCamera(vb01::Vector3, double);
|
||||
void zoomCamera(bool);
|
||||
inline bool isLookingAround(){return lookingAround;}
|
||||
inline void setLookingAround(bool l){lookingAround = l;}
|
||||
private:
|
||||
CameraController(){}
|
||||
|
||||
bool lookingAround = false;
|
||||
int numZooms = 0;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,43 +0,0 @@
|
||||
#ifndef DESTRUCTABLE_H
|
||||
#define DESTRUCTABLE_H
|
||||
|
||||
#include <vector.h>
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
enum class Armor {CAST, COMBINED, MECHANIC, SHELL, STEEL};
|
||||
|
||||
class GameObject;
|
||||
|
||||
class Destructable{
|
||||
public:
|
||||
Destructable(GameObject*);
|
||||
void update();
|
||||
void removeBar(vb01::Node*);
|
||||
vb01::Node* createBar(vb01::Vector2, vb01::Vector2, vb01::Vector4);
|
||||
void displayStats(vb01::Node*, vb01::Node*, int, int, bool, vb01::Vector2 offset = vb01::Vector2::VEC_ZERO);
|
||||
inline int getHealth(){return health;}
|
||||
inline int getMaxHealth(){return maxHealth;}
|
||||
inline int getDeathHp(){return DEATH_HP;}
|
||||
inline void takeDamage(int damage) {health -= damage * (1 + (freezeDmgFactor - 1) * freezeStatus * .01f);}
|
||||
inline GameObject* getGameObject(){return gameObject;}
|
||||
inline std::vector<Armor> getArmorTypes(){return armorTypes;}
|
||||
inline void setFreezeStatus(int fs){this->freezeStatus = std::clamp(fs, 0, 100);}
|
||||
inline int getFreezeStatus(){return freezeStatus;}
|
||||
private:
|
||||
std::vector<Armor> armorTypes;
|
||||
const int DEATH_HP = 0;
|
||||
int health = 0, maxHealth, freezeStatus = 0, freezeDmgFactor = 10;
|
||||
GameObject *gameObject = nullptr;
|
||||
|
||||
void initProperties();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,20 +0,0 @@
|
||||
#ifndef ENVIRONMENT_H
|
||||
#define ENVIRONMENT_H
|
||||
|
||||
#include <vector.h>
|
||||
|
||||
#include "fxManager.h"
|
||||
|
||||
namespace battleship{
|
||||
class Environment{
|
||||
public:
|
||||
enum class Detonation{EXPLOSION, EMP, CRYO};
|
||||
|
||||
static Environment* getSingleton();
|
||||
static void explode(FxManager::Fx*, Detonation, vb01::Vector3, int = 0, float = 0);
|
||||
private:
|
||||
Environment(){}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,80 +0,0 @@
|
||||
#ifndef GAME_OBJECT_H
|
||||
#define GAME_OBJECT_H
|
||||
|
||||
#include <vector.h>
|
||||
#include <quaternion.h>
|
||||
#include <model.h>
|
||||
|
||||
namespace sf{
|
||||
class SoundBuffer;
|
||||
class Sound;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class Player;
|
||||
class Unit;
|
||||
class Destructable;
|
||||
|
||||
class GameObject{
|
||||
public:
|
||||
enum class Type{UNIT, PROJECTILE, RESOURCE_DEPOSIT};
|
||||
|
||||
GameObject(Type, int, Player*, vb01::Vector3, vb01::Quaternion);
|
||||
~GameObject(){}
|
||||
virtual void reinit();
|
||||
virtual void update();
|
||||
virtual void select(){}
|
||||
virtual void placeAt(vb01::Vector3);
|
||||
void orientAt(vb01::Quaternion);
|
||||
std::string getGameObjTableName();
|
||||
static sf::Sound* prepareSfx(sf::SoundBuffer*, std::string);
|
||||
bool pointWithinObj(vb01::Vector3, float = 0, float = 0, bool = false, float = 0);
|
||||
void changePlayer(Player *newPlayer);
|
||||
inline float getMaxUnevenness(){return maxUnevenness;}
|
||||
inline vb01::Vector2 getScreenPos(){return screenPos;}
|
||||
inline vb01::Vector3 getCorner(int i){return corners[i];}
|
||||
inline bool isSelectable(){return selectable;}
|
||||
inline bool isDebuggable(){return debugging;}
|
||||
inline vb01::Vector3 getPos() {return pos;}
|
||||
inline vb01::Quaternion getRot(){return rot;}
|
||||
inline float getWidth() {return width;}
|
||||
inline float getHeight() {return height;}
|
||||
inline float getLength() {return length;}
|
||||
inline vb01::Model* getModel() {return model;}
|
||||
inline void setPlayer(Player *pl){player = pl;}
|
||||
inline Player* getPlayer(){return player;}
|
||||
inline void toggleDebugging(bool d){this->debugging=d;}
|
||||
inline vb01::Vector3 getDirVec() {return dirVec;}
|
||||
inline vb01::Vector3 getLeftVec() {return leftVec;}
|
||||
inline vb01::Vector3 getUpVec() {return upVec;}
|
||||
inline int getId() {return id;}
|
||||
inline Type getType(){return type;}
|
||||
inline vb01::Node* getHitbox(){return hitbox;}
|
||||
inline void setRemove(bool rm){this->remove = rm;}
|
||||
inline bool isRemove(){return remove;}
|
||||
inline Destructable* getDestructable(){return destructable;}
|
||||
protected:
|
||||
virtual void useColor(vb01::Material*);
|
||||
virtual void initProperties();
|
||||
virtual void destroyModel();
|
||||
virtual void initModel(bool = true);
|
||||
virtual void initHitbox();
|
||||
virtual void destroyHitbox();
|
||||
virtual void destroySound();
|
||||
virtual void initSound(){}
|
||||
|
||||
Type type;
|
||||
int id;
|
||||
Player *player;
|
||||
Destructable *destructable = nullptr;
|
||||
vb01::Model *model = nullptr;
|
||||
vb01::Node *hitbox = nullptr;
|
||||
vb01::Vector3 pos = vb01::Vector3(0, 0, 0), upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, 1), leftVec = vb01::Vector3(1, 0, 0), corners[8];
|
||||
vb01::Vector2 screenPos;
|
||||
vb01::Quaternion rot;
|
||||
bool selectable = false, debugging = false, remove = false;
|
||||
float width, height, length, maxUnevenness;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,23 +0,0 @@
|
||||
#ifndef GAME_OBJECT_FACTORY_H
|
||||
#define GAME_OBJECT_FACTORY_H
|
||||
|
||||
#include <vector.h>
|
||||
#include <quaternion.h>
|
||||
|
||||
namespace battleship{
|
||||
class Unit;
|
||||
class Projectile;
|
||||
class ResourceDeposit;
|
||||
class Player;
|
||||
|
||||
class GameObjectFactory{
|
||||
public:
|
||||
enum GameObjectType{UNIT, PROJECTILE, RESOURCE_DEPOSIT};
|
||||
static Unit* createUnit(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0);
|
||||
static Projectile* createProjectile(Unit*, int, vb01::Vector3, vb01::Quaternion);
|
||||
static ResourceDeposit* createResourceDeposit(Player*, int, vb01::Vector3, vb01::Quaternion, int = 0);
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,31 +0,0 @@
|
||||
#ifndef GAME_OBJECT_FRAME_H
|
||||
#define GAME_OBJECT_FRAME_H
|
||||
|
||||
#include "gameObject.h"
|
||||
|
||||
#include <vector.h>
|
||||
#include <quaternion.h>
|
||||
|
||||
namespace battleship{
|
||||
struct GameObjectFrame : public GameObject{
|
||||
enum Status{PLACEABLE, NOT_PLACEABLE, PLACED};
|
||||
|
||||
GameObjectFrame(int i, GameObject::Type t, Player *pl, Unit *ou = nullptr, vb01::Vector3 pos = vb01::Vector3::VEC_ZERO, vb01::Quaternion rot = vb01::Quaternion::QUAT_W) :
|
||||
originalUnit(ou),
|
||||
GameObject(t, i, pl, pos, rot)
|
||||
{
|
||||
initModel(false);
|
||||
initProperties();
|
||||
placeAt(pos);
|
||||
orientAt(rot);
|
||||
}
|
||||
~GameObjectFrame(){}
|
||||
void destroy(){destroyModel();}
|
||||
inline Unit* getOriginalUnit(){return originalUnit;}
|
||||
|
||||
Status status;
|
||||
Unit *originalUnit = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,55 +0,0 @@
|
||||
#ifndef GAME_OBJECT_FRAME_CONTROLLER_H
|
||||
#define GAME_OBJECT_FRAME_CONTROLLER_H
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
#include <vector.h>
|
||||
#include <quaternion.h>
|
||||
|
||||
#include "gameObjectFrame.h"
|
||||
|
||||
namespace vb01{
|
||||
class Model;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class GameObjectFrameController{
|
||||
public:
|
||||
static GameObjectFrameController* getSingleton();
|
||||
void update();
|
||||
void removeGameObjectFrame(int);
|
||||
void removeGameObjectFrames();
|
||||
void rotateGameObjectFrames(float);
|
||||
void checkPlacement(GameObjectFrame&);
|
||||
void addGameObjectFrame(GameObjectFrame);
|
||||
inline int getNumGameObjectFrames(){return gameObjectFrames.size();}
|
||||
inline GameObjectFrame& getGameObjectFrame(int i){return gameObjectFrames[i];}
|
||||
inline bool isPaintSelecting(){return paintSelecting;}
|
||||
inline void setPaintSelecting(bool ps){paintSelecting = ps;}
|
||||
inline bool isRotating(){return rotating;}
|
||||
inline void setRotating(bool rs){rotating = rs;}
|
||||
inline bool isPlacingOnSurface(){return placingOnSurface;}
|
||||
inline void setPlacingOnSurface(bool ps){placingOnSurface = ps;}
|
||||
inline bool isPlacingVertically(){return placingVertically;}
|
||||
inline void setPlacingVertically(bool v){this->placingVertically = v;}
|
||||
inline void setPaintSelectRowStart(vb01::Vector3 st){paintSelectRowStart = st;}
|
||||
inline void toggleFrameTransformations(bool rot, bool pos, bool pv){
|
||||
setRotating(rot);
|
||||
setPlacingOnSurface(pos);
|
||||
setPlacingVertically(pv);
|
||||
}
|
||||
private:
|
||||
GameObjectFrameController(){}
|
||||
void paintSelect(vb01::Vector3);
|
||||
void snapToObj(GameObjectFrame&, std::vector<GameObject*>, float);
|
||||
void shiftVerticalPlacement();
|
||||
|
||||
std::vector<GameObjectFrame> gameObjectFrames;
|
||||
vb01::Vector3 paintSelectRowStart, placementPos;
|
||||
float minDepth, maxDepth;
|
||||
bool paintSelecting = false, rotating = false, placingOnSurface = false, placingVertically = false, minDepthCalculated = false;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
-119
@@ -1,119 +0,0 @@
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "defConfigs.h"
|
||||
#include "gameManager.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "guiAppState.h"
|
||||
|
||||
using namespace gameBase;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
GuiAppState::GuiAppState() : AbstractAppState(
|
||||
AppStateType::GUI_STATE,
|
||||
configData::calcSumBinds(AppStateType::GUI_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::GUI_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]){
|
||||
}
|
||||
|
||||
GuiAppState::~GuiAppState() {}
|
||||
|
||||
void GuiAppState::update() {
|
||||
ConcreteGuiManager::getSingleton()->update();
|
||||
}
|
||||
|
||||
void GuiAppState::onAttached() {
|
||||
AbstractAppState::onAttached();
|
||||
}
|
||||
|
||||
void GuiAppState::onDettached() {
|
||||
AbstractAppState::onDettached();
|
||||
}
|
||||
|
||||
void GuiAppState::onAction(int bind, bool isPressed) {
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
|
||||
switch((Bind)bind){
|
||||
case Bind::LEFT_CLICK:
|
||||
leftMousePressed = isPressed;
|
||||
|
||||
if(isPressed)
|
||||
guiManager->updateGui();
|
||||
|
||||
break;
|
||||
case Bind::SCROLLING_UP:{
|
||||
Listbox *l = getOpenListbox();
|
||||
if(l) l->scrollUp();
|
||||
break;
|
||||
}
|
||||
case Bind::SCROLLING_DOWN:{
|
||||
Listbox *l = getOpenListbox();
|
||||
if(l) l->scrollDown();
|
||||
break;
|
||||
}
|
||||
case Bind::DELETE_CHAR:{
|
||||
Textbox *t = getOpenTextbox();
|
||||
if(t)t->setDeleteCharacters(isPressed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::onRawKeyPress(int ch){
|
||||
for(Button *b : ConcreteGuiManager::getSingleton()->getButtons())
|
||||
if(b->getTrigger() == ch){
|
||||
b->onClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::onRawCharPress(u32 codepoint){
|
||||
Textbox *currentTextbox = getOpenTextbox();
|
||||
|
||||
if(currentTextbox)
|
||||
currentTextbox->type(codepoint);
|
||||
}
|
||||
|
||||
void GuiAppState::onRawMousePress(int trigger){
|
||||
}
|
||||
|
||||
Textbox* GuiAppState::getOpenTextbox() {
|
||||
vector<Textbox*> textboxes = ConcreteGuiManager::getSingleton()->getTextboxes();
|
||||
|
||||
for (int i = 0; i < textboxes.size(); i++)
|
||||
if (textboxes[i]->isEnabled())
|
||||
return textboxes[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Listbox* GuiAppState::getOpenListbox() {
|
||||
vector<Listbox*> listboxes = ConcreteGuiManager::getSingleton()->getListboxes();
|
||||
|
||||
for (int i = 0; i < listboxes.size(); i++)
|
||||
if (listboxes[i]->isOpen())
|
||||
return listboxes[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GuiAppState::onAnalog(int bind, float strength) {}
|
||||
|
||||
void GuiAppState::onRawMouseWheelScroll(bool up){
|
||||
Listbox *openListbox = getOpenListbox();
|
||||
|
||||
if(!openListbox) return;
|
||||
|
||||
if(up) openListbox->scrollUp();
|
||||
else openListbox->scrollDown();
|
||||
}
|
||||
}
|
||||
@@ -1,128 +0,0 @@
|
||||
#ifndef MAP_H
|
||||
#define MAP_H
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <rayCaster.h>
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
namespace vb01{
|
||||
class Model;
|
||||
class Material;
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace vb01Gui{
|
||||
class Button;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class Player;
|
||||
class Unit;
|
||||
class ResourceDeposit;
|
||||
struct Cell;
|
||||
|
||||
class Map {
|
||||
public:
|
||||
struct Cell;
|
||||
|
||||
struct Edge{
|
||||
Edge(vb01::s64 w, vb01::s64 src, vb01::s64 dest) : weight(w), srcCellId(src), destCellId(dest){}
|
||||
vb01::s64 weight, srcCellId, destCellId;
|
||||
};
|
||||
|
||||
struct Cell{
|
||||
enum Type{LAND, WATER};
|
||||
|
||||
Type type;
|
||||
vb01::Vector3 pos;
|
||||
std::vector<Edge> edges;
|
||||
Unit *blockedBy = nullptr;
|
||||
std::vector<int> underWaterCellIds;
|
||||
|
||||
Cell(){}
|
||||
Cell(vb01::Vector3 p, Type t, std::vector<Edge> e = std::vector<Edge>{}, std::vector<int> uc = std::vector<int>{}): pos(p), type(t), edges(e), underWaterCellIds(uc){}
|
||||
};
|
||||
|
||||
class Minimap{
|
||||
public:
|
||||
static Minimap* getSingleton();
|
||||
~Minimap();
|
||||
void update();
|
||||
void updateImage();
|
||||
void load();
|
||||
void unload();
|
||||
inline vb01::u8* getOldMinimapImage(){return oldImageData;}
|
||||
private:
|
||||
Minimap();
|
||||
vb01::Node* initIcon(vb01::Vector3, std::string);
|
||||
void updateCamFrame(vb01Gui::Button*);
|
||||
|
||||
vb01::u8 *oldImageData = nullptr;
|
||||
vb01::Node *camFrame = nullptr;
|
||||
std::vector<vb01::Node*> depositIcons;
|
||||
vb01::Node* camIcon = nullptr;
|
||||
};
|
||||
|
||||
static Map* getSingleton();
|
||||
~Map(){}
|
||||
static std::vector<Edge> generateAdjacentNodeEdges(int, int, int, int, int);
|
||||
void update();
|
||||
void load(std::string);
|
||||
void create(std::string, vb01::Vector3);
|
||||
void unload();
|
||||
std::vector<vb01::RayCaster::CollisionResult> raycastTerrain(vb01::Vector3, vb01::Vector3, bool);
|
||||
int getCellId(vb01::Vector3, bool = true);
|
||||
bool isPointWithinTerrainObject(vb01::Vector3, int);
|
||||
void loadPlayersGameObjects();
|
||||
int getNumMapSpawnPoints(std::string = "");
|
||||
std::vector<int> getSurroundingCells(vb01::Vector3, int);
|
||||
void blockCells(Unit*);
|
||||
void unblockCells(Unit*);
|
||||
inline Map::Cell getCell(int i){return cells[i];}
|
||||
inline std::string getMapName(){return mapName;}
|
||||
inline vb01::Node* getNodeParent(){return terrainNode;}
|
||||
inline vb01::Vector3 getCellSize(){return CELL_SIZE;}
|
||||
inline int getNumSpawnPoints(){return spawnPoints.size();}
|
||||
inline vb01::Vector3 getSpawnPoint(int i){return spawnPoints[i];}
|
||||
inline void setMapSize(vb01::Vector3 s){this->mapSize = s;}
|
||||
inline vb01::Vector3 getMapSize(){return mapSize;}
|
||||
inline void addSpawnPoint(vb01::Vector3 sp){spawnPoints.push_back(sp);}
|
||||
inline std::vector<Map::Cell>& getCells(){return cells;}
|
||||
inline vb01::Node* getLight(int i){return lights[i];}
|
||||
inline std::vector<vb01::Node*> getLights(){return lights;}
|
||||
inline float getBaseHeight(){return baseHeight;}
|
||||
inline void setBaseHeight(float bh){this->baseHeight = bh;}
|
||||
private:
|
||||
std::string mapTable = "metadata";
|
||||
vb01::Node *terrainNode = nullptr, *cellNode = nullptr;
|
||||
vb01::Material *landCellMat = nullptr, *waterCellMat = nullptr;
|
||||
std::string mapName;
|
||||
vb01::Vector3 CELL_SIZE = vb01::Vector3(7, 7, 7), mapSize;
|
||||
std::vector<vb01::Vector3> spawnPoints;
|
||||
std::vector<Cell> cells;
|
||||
float baseHeight;
|
||||
std::vector<vb01::Node*> lights;
|
||||
|
||||
Map(){}
|
||||
void preprareScene(bool);
|
||||
void loadSpawnPoints();
|
||||
void loadLights();
|
||||
void loadSkybox();
|
||||
void loadCells();
|
||||
void loadPlayerGameObjects(Player*, sol::table);
|
||||
void loadTerrainObject(int);
|
||||
void unloadTerrainObjects();
|
||||
void unloadCells();
|
||||
void unloadLights();
|
||||
void unloadSkybox();
|
||||
void unloadPlayerObjects();
|
||||
void destroyScene();
|
||||
template<typename T> int bsearch(std::vector<T>, T, float);
|
||||
};
|
||||
}
|
||||
#endif
|
||||
@@ -1,97 +0,0 @@
|
||||
#ifndef MAP_EDITOR_APP_STATE_H
|
||||
#define MAP_EDITOR_APP_STATE_H
|
||||
|
||||
#include "map.h"
|
||||
#include "player.h"
|
||||
|
||||
#include <listbox.h>
|
||||
|
||||
#include <abstractAppState.h>
|
||||
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace vb01{
|
||||
class Texture;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class MapEditor;
|
||||
|
||||
class MapEditorAppState : public gameBase::AbstractAppState{
|
||||
public:
|
||||
class MapEditor{
|
||||
public:
|
||||
enum TransformAxis{
|
||||
X_AXIS,
|
||||
Y_AXIS,
|
||||
Z_AXIS
|
||||
};
|
||||
|
||||
MapEditor(std::string, vb01::Vector2, bool);
|
||||
void updateCircleRadius(bool);
|
||||
void pushLandmassVerts(float);
|
||||
void castSelectionRay();
|
||||
void createWaterbody();
|
||||
void moveTerrainObject(float);
|
||||
void scaleTerrainObject(float);
|
||||
void exportMap();
|
||||
void prepareTerrainObjects(int = 0, int = -1);
|
||||
void togglePush(bool);
|
||||
inline vb01::Node* getSelectedNode(){return selectedTerrainNode;}
|
||||
inline float getGuiThreshold(){return guiThreshold;}
|
||||
inline float getCircleRadius(){return circleRadius;}
|
||||
inline bool isPushing(){return pushing;}
|
||||
inline void setPushPos(vb01::Vector3 p){pushPos = p;}
|
||||
inline bool isMovingTerrainObject(){return movingTerrainObject;}
|
||||
inline void setMovingTerrainObject(bool m){movingTerrainObject = m;}
|
||||
inline bool isScalingTerrainObject(){return scalingTerrainObject;}
|
||||
inline void setScalingTerrainObject(bool s){scalingTerrainObject = s;}
|
||||
inline TransformAxis getTransformAxis(){return transformAxis;}
|
||||
inline void setTransformAxis(TransformAxis m){transformAxis = m;}
|
||||
inline bool isWeightsGenerated(){return weightsGenerated;}
|
||||
inline vb01::Texture* getSkyTexture(int i){return skyTextures[i];}
|
||||
inline vb01::Texture* getLandmassTexture(int i){return landmassTextures[i];}
|
||||
private:
|
||||
void generatePlane(vb01::Vector2);
|
||||
void prepareTextures(std::string, bool, std::vector<vb01::Texture*>&);
|
||||
void toggleSelection(vb01::Node*, bool);
|
||||
std::vector<Map::Cell> generateMapCells();
|
||||
void generateLandmassXml();
|
||||
void generateMinimap(std::string, std::vector<Map::Cell>&);
|
||||
std::string generatePlayerTableStr(Player*);
|
||||
void generateMapScript(std::vector<Map::Cell>&);
|
||||
void prepareTerrainObject(vb01::u32**, Map::Cell*, int[3], float, bool);
|
||||
|
||||
Map *map;
|
||||
vb01::Node *selectedTerrainNode = nullptr;
|
||||
TransformAxis transformAxis = X_AXIS;
|
||||
vb01Gui::Listbox *skyListbox = nullptr;
|
||||
float *oldLandmassVertHeights = nullptr;
|
||||
bool pushing = false, movingTerrainObject = false, scalingTerrainObject = false, weightsGenerated = false, newMap, cellMarkersVisible = false;
|
||||
const float MIN_RADIUS = 1, MAX_RADIUS = 100, INCREASE_RATE = 1;
|
||||
float circleRadius = MIN_RADIUS, guiThreshold = 200;
|
||||
vb01::Vector3 pushPos = vb01::Vector3::VEC_ZERO;
|
||||
std::vector<vb01::Texture*> skyTextures, landmassTextures, waterTextures;
|
||||
};
|
||||
|
||||
MapEditorAppState(std::string, vb01::Vector2, bool);
|
||||
void update();
|
||||
void onAttached();
|
||||
void onDettached();
|
||||
void onAction(int, bool);
|
||||
void onAnalog(int, float);
|
||||
void onRawMouseWheelScroll(bool);
|
||||
inline MapEditor* getMapEditor(){return mapEditor;}
|
||||
private:
|
||||
MapEditor *mapEditor = nullptr;
|
||||
std::string mapName;
|
||||
vb01::Vector2 mapSize;
|
||||
bool newMap;
|
||||
vb01::Text *radiusText = nullptr, *weightsText = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,118 +0,0 @@
|
||||
#include "pathfinderTest.h"
|
||||
#include "pathfinder.h"
|
||||
#include "unit.h"
|
||||
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace battleship{
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
vector<Map::Cell> PathfinderTest::generateCellGraph(int numCellsOnSide){
|
||||
vector<Map::Cell> cells;
|
||||
float cellSize = 2;
|
||||
|
||||
for(int i = 0; i < numCellsOnSide; i++)
|
||||
for(int j = 0; j < numCellsOnSide; j++){
|
||||
vector<Map::Edge> edges = Map::generateAdjacentNodeEdges(numCellsOnSide, i, numCellsOnSide, j, 1000);
|
||||
cells.push_back(Map::Cell(Vector3(j * cellSize, 0, i * cellSize), Map::Cell::Type::LAND, edges));
|
||||
}
|
||||
|
||||
return cells;
|
||||
}
|
||||
|
||||
int PathfinderTest::calcPathLength(vector<int> &path){
|
||||
int sumPathWeights = 0;
|
||||
|
||||
for(int i = 0; i < path.size() - 1; i++)
|
||||
for(int j = 0; j < cells[path[i]].edges.size(); j++)
|
||||
if(cells[path[i]].edges[j].destCellId == path[i + 1])
|
||||
sumPathWeights += cells[path[i]].edges[j].weight;
|
||||
|
||||
return sumPathWeights;
|
||||
}
|
||||
|
||||
vector<float> PathfinderTest::generateHeuristics(vector<Map::Cell> &cells, int dest, int type){
|
||||
vector<float> heur;
|
||||
int numSideCells = sqrt(cells.size());
|
||||
|
||||
if(type == 0)
|
||||
for(Map::Cell &cell : cells)
|
||||
heur.push_back(145 * cells[dest].pos.getDistanceFrom(cell.pos));
|
||||
else if(type == 1)
|
||||
for(int i = 0; i < cells.size(); i++){
|
||||
int x = i % numSideCells, y = i / numSideCells;
|
||||
heur.push_back(2 * (numSideCells - 1) - (x + y));
|
||||
}
|
||||
|
||||
return heur;
|
||||
}
|
||||
|
||||
void PathfinderTest::testFindPath(){
|
||||
cells = vector<Map::Cell>{
|
||||
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 0, 0), Map::Edge(2, 0, 1), Map::Edge(4, 0, 2)}),
|
||||
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 1, 1), Map::Edge(1, 1, 2), Map::Edge(9, 1, 3), Map::Edge(13, 1, 4)}),
|
||||
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 2, 2), Map::Edge(2, 2, 1), Map::Edge(4, 2, 4), Map::Edge(5, 2, 5)}),
|
||||
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 3, 3), Map::Edge(1, 3, 6)}),
|
||||
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 4, 4), Map::Edge(1, 4, 1), Map::Edge(1, 4, 3), Map::Edge(2, 4, 5), Map::Edge(3, 4, 6)}),
|
||||
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 5, 5), Map::Edge(9, 5, 4), Map::Edge(2, 5, 6)}),
|
||||
Map::Cell(Vector3::VEC_ZERO, Map::Cell::Type::LAND, vector<Map::Edge>{Map::Edge(0, 6, 6)})
|
||||
};
|
||||
|
||||
int src = 0, dest = cells.size() - 1;
|
||||
vector<float> heur;
|
||||
vector<int> path = pathfinder->findPath(cells, heur, src, dest);
|
||||
CPPUNIT_ASSERT(path == vector<int>({0, 1, 2, 4, 3, 6}));
|
||||
|
||||
int sumPathWeights = calcPathLength(path);
|
||||
CPPUNIT_ASSERT(sumPathWeights == 9);
|
||||
}
|
||||
|
||||
void PathfinderTest::testFindBigPath(){
|
||||
cells = generateCellGraph(250);
|
||||
int numIterations = 1, src = 0, dest = cells.size() - 1;
|
||||
vector<float> heur;
|
||||
heur = generateHeuristics(cells, dest, 0);
|
||||
s64 sumTime = 0;
|
||||
|
||||
for(int i = 0; i < numIterations; i++){
|
||||
s64 t0 = getTime();
|
||||
pathfinder->findPath(cells, heur, src, dest);
|
||||
s64 t1 = getTime();
|
||||
sumTime += t1 - t0;
|
||||
}
|
||||
|
||||
int threshold = 100;
|
||||
double avg = (double)sumTime / numIterations, eps = .1;
|
||||
cout << "Total time: " << sumTime << endl;
|
||||
CPPUNIT_ASSERT(sumTime <= threshold);
|
||||
}
|
||||
|
||||
void PathfinderTest::testFindShorePath(){
|
||||
int numSideCells = 25;
|
||||
cells = generateCellGraph(numSideCells);
|
||||
|
||||
for(int i = 0; i < numSideCells; i++)
|
||||
cells[numSideCells * i + int(.5 * numSideCells)].type = Map::Cell::WATER;
|
||||
|
||||
vector<float> heur = vector<float>{};
|
||||
vector<int> p1 = pathfinder->findPath(cells, heur, 0, 4, (int)UnitType::LAND);
|
||||
|
||||
int numEdges = cells[p1[p1.size() - 1]].edges.size();
|
||||
//for(int i = 0; i < numEdges; i++){}
|
||||
|
||||
vector<int> p2 = pathfinder->findPath(cells, heur, 2, 4, (int)UnitType::SEA_LEVEL);
|
||||
CPPUNIT_ASSERT(cells[p2[p2.size() - 1]].type == Map::Cell::WATER);
|
||||
}
|
||||
|
||||
void PathfinderTest::setUp(){
|
||||
pathfinder = Pathfinder::getSingleton();
|
||||
const u16 INF = u16(0 - 1);
|
||||
pathfinder->setImpassibleNodeVal(INF);
|
||||
}
|
||||
|
||||
void PathfinderTest::tearDown(){}
|
||||
}
|
||||
@@ -1,32 +1,36 @@
|
||||
#include "abstractCommand.h"
|
||||
|
||||
#include <cmath>
|
||||
#include <vector.h>
|
||||
#include <vector>
|
||||
|
||||
namespace battleship{
|
||||
namespace battleship
|
||||
{
|
||||
using namespace std;
|
||||
|
||||
void AbstractCommand::handle(){
|
||||
if(cmdStr.find(" ") == -1)
|
||||
void AbstractCommand::handle()
|
||||
{
|
||||
if (cmdStr.find(" ") == -1)
|
||||
return;
|
||||
|
||||
vector<int> spaceIds;
|
||||
arguments.clear();
|
||||
|
||||
for(int i = 0; i < cmdStr.length(); i++)
|
||||
if(cmdStr[i] == ' ')
|
||||
for (int i = 0; i < cmdStr.length(); i++)
|
||||
if (cmdStr[i] == ' ')
|
||||
spaceIds.push_back(i);
|
||||
|
||||
arguments.push_back(cmdStr.substr(0, spaceIds[0]));
|
||||
|
||||
for(int i = 0; i < spaceIds.size(); i++){
|
||||
for (int i = 0; i < spaceIds.size(); i++)
|
||||
{
|
||||
bool lastSpace = (i == spaceIds.size() - 1);
|
||||
string argument = cmdStr.substr(spaceIds[i] + 1, lastSpace ? string::npos : spaceIds[i + 1] - spaceIds[i] - 1);
|
||||
arguments.push_back(argument);
|
||||
}
|
||||
}
|
||||
|
||||
void AbstractCommand::execute(){
|
||||
void AbstractCommand::execute()
|
||||
{
|
||||
handle();
|
||||
validate();
|
||||
}
|
||||
@@ -3,25 +3,28 @@
|
||||
#include "player.h"
|
||||
#include "trader.h"
|
||||
|
||||
namespace battleship{
|
||||
void AddResourceCommand::validate(){
|
||||
if(arguments.size() != 3)
|
||||
namespace battleship
|
||||
{
|
||||
void AddResourceCommand::validate()
|
||||
{
|
||||
if (arguments.size() != 3)
|
||||
return;
|
||||
|
||||
playerId = atoi(arguments[0].c_str());
|
||||
|
||||
if(playerId != 0 && playerId != 1)
|
||||
if (playerId != 0 && playerId != 1)
|
||||
return;
|
||||
|
||||
resourceId = atoi(arguments[1].c_str());
|
||||
|
||||
if(!(0 <= resourceId && resourceId <= 2))
|
||||
if (!(0 <= resourceId && resourceId <= 2))
|
||||
return;
|
||||
|
||||
resourceAmmount = atoi(arguments[2].c_str());
|
||||
}
|
||||
|
||||
void AddResourceCommand::execute(){
|
||||
void AddResourceCommand::execute()
|
||||
{
|
||||
AbstractCommand::execute();
|
||||
|
||||
Player *player = Game::getSingleton()->getPlayer(playerId);
|
||||
@@ -6,31 +6,34 @@
|
||||
|
||||
#include <algorithm>
|
||||
|
||||
namespace battleship{
|
||||
namespace battleship
|
||||
{
|
||||
using namespace std;
|
||||
using namespace gameBase;
|
||||
|
||||
void AddTechnologyCommand::validate(){
|
||||
if(arguments.size() != 2)
|
||||
void AddTechnologyCommand::validate()
|
||||
{
|
||||
if (arguments.size() != 2)
|
||||
return;
|
||||
|
||||
playerId = atoi(arguments[0].c_str());
|
||||
int numPlayers = Game::getSingleton()->getNumPlayers();
|
||||
|
||||
if(!(0 <= playerId && playerId < numPlayers))
|
||||
if (!(0 <= playerId && playerId < numPlayers))
|
||||
return;
|
||||
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
SOL_LUA_VIEW.script("numTechs = #technologies");
|
||||
int numTechs = SOL_LUA_VIEW["numTechs"];
|
||||
int numTechs = SOL_LUA_VIEW["numTechs"];
|
||||
|
||||
techId = atoi(arguments[1].c_str());
|
||||
|
||||
if(!(0 <= techId && techId < numTechs))
|
||||
if (!(0 <= techId && techId < numTechs))
|
||||
return;
|
||||
}
|
||||
|
||||
void AddTechnologyCommand::execute(){
|
||||
void AddTechnologyCommand::execute()
|
||||
{
|
||||
AbstractCommand::execute();
|
||||
Game::getSingleton()->getPlayer(playerId)->addTechnology(techId);
|
||||
}
|
||||
@@ -9,19 +9,21 @@
|
||||
#include "player.h"
|
||||
#include "gameObjectFactory.h"
|
||||
|
||||
namespace battleship{
|
||||
namespace battleship
|
||||
{
|
||||
using namespace gameBase;
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
//TODO implement structure build status argument
|
||||
void AddUnitCommand::validate(){
|
||||
if(!(arguments.size() == 2 || arguments.size() == 5 || arguments.size() == 9))
|
||||
// TODO implement structure build status argument
|
||||
void AddUnitCommand::validate()
|
||||
{
|
||||
if (!(arguments.size() == 2 || arguments.size() == 5 || arguments.size() == 9))
|
||||
return;
|
||||
|
||||
playerId = atoi(arguments[0].c_str());
|
||||
|
||||
if(playerId != 0 && playerId != 1)
|
||||
if (playerId != 0 && playerId != 1)
|
||||
return;
|
||||
|
||||
unitId = atoi(arguments[1].c_str());
|
||||
@@ -31,33 +33,36 @@ namespace battleship{
|
||||
SOL_LUA_VIEW.script(varName + " = #units");
|
||||
int numUnits = SOL_LUA_VIEW[varName];
|
||||
|
||||
if(!(0 <= unitId && unitId <= numUnits))
|
||||
if (!(0 <= unitId && unitId <= numUnits))
|
||||
return;
|
||||
|
||||
if(arguments.size() >= 5){
|
||||
if (arguments.size() >= 5)
|
||||
{
|
||||
float x = atoi(arguments[2].c_str());
|
||||
float y = atoi(arguments[3].c_str());
|
||||
float z = atoi(arguments[4].c_str());
|
||||
pos = Vector3(x, y, z);
|
||||
}
|
||||
else if(2 < arguments.size() && arguments.size() < 5)
|
||||
else if (2 < arguments.size() && arguments.size() < 5)
|
||||
return;
|
||||
|
||||
if(arguments.size() == 9){
|
||||
if (arguments.size() == 9)
|
||||
{
|
||||
float w = atoi(arguments[5].c_str());
|
||||
float x = atoi(arguments[6].c_str());
|
||||
float y = atoi(arguments[7].c_str());
|
||||
float z = atoi(arguments[8].c_str());
|
||||
rot = Quaternion(w, x, y, z);
|
||||
}
|
||||
else if(5 < arguments.size() && arguments.size() < 9)
|
||||
else if (5 < arguments.size() && arguments.size() < 9)
|
||||
return;
|
||||
}
|
||||
|
||||
void AddUnitCommand::execute(){
|
||||
void AddUnitCommand::execute()
|
||||
{
|
||||
AbstractCommand::execute();
|
||||
|
||||
Player* player = Game::getSingleton()->getPlayer(playerId);
|
||||
player->addUnit(GameObjectFactory::createUnit(player, unitId, pos, rot, 100));
|
||||
Player *player = Game::getSingleton()->getPlayer(playerId);
|
||||
player->addUnit(GameObjectFactory::createUnit(player, unitId, pos, rot, 100));
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
#ifndef ADD_UNIT_COMMAND_H
|
||||
#define ADD_UNIT_COMMAND_H
|
||||
|
||||
#include "abstractCommand.h"
|
||||
|
||||
#include <vector>
|
||||
#include <quaternion.h>
|
||||
|
||||
namespace battleship
|
||||
{
|
||||
class AddUnitCommand : public AbstractCommand
|
||||
{
|
||||
public:
|
||||
AddUnitCommand(std::string argsStr) : AbstractCommand(argsStr) {}
|
||||
void validate();
|
||||
void execute();
|
||||
|
||||
private:
|
||||
int playerId, unitId;
|
||||
bool posEnabled, rotEnabled;
|
||||
vb01::Vector3 pos = vb01::Vector3::VEC_ZERO;
|
||||
vb01::Quaternion rot = vb01::Quaternion::QUAT_W;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -1,12 +1,16 @@
|
||||
#include "toggleDebugCommand.h"
|
||||
#include "game.h"
|
||||
|
||||
namespace battleship{
|
||||
void ToggleDebugCommand::validate(){
|
||||
if(!arguments.empty()) return;
|
||||
namespace battleship
|
||||
{
|
||||
void ToggleDebugCommand::validate()
|
||||
{
|
||||
if (!arguments.empty())
|
||||
return;
|
||||
}
|
||||
|
||||
void ToggleDebugCommand::execute(){
|
||||
void ToggleDebugCommand::execute()
|
||||
{
|
||||
AbstractCommand::execute();
|
||||
|
||||
Game *game = Game::getSingleton();
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,119 @@
|
||||
#ifndef ACTIVE_GAME_STATE_H
|
||||
#define ACTIVE_GAME_STATE_H
|
||||
|
||||
#include "guiAppState.h"
|
||||
#include "player.h"
|
||||
#include "map.h"
|
||||
#include "unit.h"
|
||||
|
||||
#include <util.h>
|
||||
|
||||
namespace vb01
|
||||
{
|
||||
class Node;
|
||||
class Texture;
|
||||
}
|
||||
|
||||
namespace vb01Gui
|
||||
{
|
||||
class Button;
|
||||
}
|
||||
|
||||
namespace battleship
|
||||
{
|
||||
class GameObject;
|
||||
class Unit;
|
||||
class UnitButton;
|
||||
|
||||
class ActiveGameState : public gameBase::AbstractAppState
|
||||
{
|
||||
public:
|
||||
enum CursorState
|
||||
{
|
||||
NORMAL,
|
||||
ATTACK,
|
||||
GARRISON,
|
||||
SUPPLY,
|
||||
LOAD,
|
||||
UNLOAD,
|
||||
HACK
|
||||
};
|
||||
|
||||
ActiveGameState(GuiAppState *, int);
|
||||
~ActiveGameState();
|
||||
void onAttached();
|
||||
void onDettached();
|
||||
void update();
|
||||
void onAction(int, bool);
|
||||
void onAnalog(int, float);
|
||||
void onRawMouseWheelScroll(bool);
|
||||
inline CursorState getCursorState() { return cursorState; }
|
||||
inline void setCursorState(CursorState cs) { this->cursorState = cs; }
|
||||
inline void addButton(vb01Gui::Button *b) { guiButtons.push_back(b); }
|
||||
inline std::vector<vb01Gui::Button *> getGuiButtons() { return guiButtons; }
|
||||
inline std::vector<vb01::Node *> getGuiRects() { return guiRects; }
|
||||
inline std::vector<vb01::Text *> getGuiTexts() { return guiTexts; }
|
||||
inline Player *getPlayer() { return mainPlayer; }
|
||||
inline std::vector<Unit *> &getUnitGroup(int i) { return unitGroups[i]; }
|
||||
inline void setBuildableStructSelected(bool bss) { this->buildableStructSelected = bss; }
|
||||
inline bool isBuildableStructSelected() { return buildableStructSelected; }
|
||||
inline float getDepth() { return depth; }
|
||||
inline void setForceCursorState(bool force) { this->forceCursorState = force; }
|
||||
inline bool isForceCursorState() { return forceCursorState; }
|
||||
inline void setTradingScreen(bool ts) { this->tradingScreen = ts; }
|
||||
inline bool isTradingScreen() { return tradingScreen; }
|
||||
inline void setOfferScreen(bool os) { this->offerScreen = os; }
|
||||
inline bool isOfferScreen() { return offerScreen; }
|
||||
|
||||
private:
|
||||
bool selectedUnitsAmongst(std::vector<Unit *>);
|
||||
void updateGameObjHoveredOn();
|
||||
void initCursor();
|
||||
void updateCursor();
|
||||
void initDragbox();
|
||||
void removeDragbox();
|
||||
bool isGameObjSelectable(GameObject *, bool);
|
||||
void deselectUnits();
|
||||
void renderUnits();
|
||||
void updateDragBox();
|
||||
void updateStructureFrames();
|
||||
void castRayToTerrain();
|
||||
void issueOrder(Order::TYPE, std::vector<Order::Target>, bool);
|
||||
bool isInLineOfSight(vb01::Vector3, float, Unit *);
|
||||
void enableUnitState(Unit::State);
|
||||
void addUnitGui();
|
||||
inline bool canSelectHoveredOnGameObj() { return gameObjHoveredOn && gameObjHoveredOn->isSelectable() && gameObjHoveredOn->getPlayer() == mainPlayer; }
|
||||
|
||||
CursorState cursorState = CursorState::NORMAL;
|
||||
Player *mainPlayer;
|
||||
GuiAppState *guiState;
|
||||
GameObject *gameObjHoveredOn = nullptr;
|
||||
vb01::Vector2 clickPoint;
|
||||
std::vector<Unit *> unitGroups[9], prevSelectedUnits;
|
||||
std::vector<Order::Target> targets;
|
||||
vb01::Node *dragboxNode = nullptr;
|
||||
std::vector<vb01::Node *> guiRects;
|
||||
std::vector<vb01::Text *> guiTexts;
|
||||
std::vector<vb01Gui::Button *> guiButtons, unitButtons;
|
||||
bool isSelectionBox = false;
|
||||
bool shiftPressed = false;
|
||||
bool controlPressed = false;
|
||||
bool selectMouseClicked = false;
|
||||
bool orderMouseClicked = false;
|
||||
bool buildableStructSelected = false;
|
||||
bool selectingPatrolPoints = false;
|
||||
bool selectingDestOrient = false;
|
||||
bool forceCursorState = false;
|
||||
bool orderPossible = false;
|
||||
bool tradingScreen = false;
|
||||
bool offerScreen = false;
|
||||
int playerId, zooms = 0;
|
||||
const int NUM_MAX_ZOOMS = 10;
|
||||
float depth = 1;
|
||||
vb01::s64 lastSelectMouseClicked = 0, lastOrderMouseClicked = 0;
|
||||
vb01::Node *cursorNode = nullptr;
|
||||
vb01::Texture *pointerTex = nullptr, *attackTex = nullptr, *garrisonTex = nullptr, *noGarrisonTex = nullptr, *supplyTex = nullptr, *noSupplyTex = nullptr, *hackTex = nullptr, *noHackTex = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Executable → Regular
Executable → Regular
Executable → Regular
+214
-214
@@ -1,214 +1,214 @@
|
||||
#ifndef DEF_CONFIGS_H
|
||||
#define DEF_CONFIGS_H
|
||||
#define SOL_ALL_SAFETIES_ON 1
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <util.h>
|
||||
|
||||
#include <glfw3.h>
|
||||
|
||||
#include <mapping.h>
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
#include "binds.h"
|
||||
#include "gameManager.h"
|
||||
|
||||
namespace battleship{
|
||||
namespace configData{
|
||||
using namespace gameBase;
|
||||
|
||||
const std::string DEFAULT_TEXTURE = "Textures/defaultTexture.jpg";
|
||||
const double camPanSpeed = .5, CAMERA_DISTANCE = 100, CAMERA_ZOOM_INCREMENT = 1, cellLength = 7, cellWidth = 7, cellDepth = 7, DIST_FROM_RAY = 15;
|
||||
const int maxNumGroups = 10, NUM_MAX_ZOOMS = 300, NUM_SUBDIVS = 100;
|
||||
const vb01::u32 IMPASS_NODE_VAL = 65535;
|
||||
|
||||
const static int numAppStates = 5;
|
||||
const static int numStaticBinds[numAppStates]{6, 0, 5, 19, 0};
|
||||
const static int numConfBinds[numAppStates]{0, 1, 27, 0, 0};
|
||||
const static int maxStaticBinds = 19;
|
||||
const static int maxConfBinds = 23;
|
||||
const static int numScripts = 5;
|
||||
|
||||
const static std::string scriptPathBase = "Scripts/";
|
||||
enum ScriptFiles{
|
||||
CORE_MAIN,
|
||||
GUI_MAIN,
|
||||
OPTIONS,
|
||||
RESOURCE_DATA,
|
||||
PROJECTILE_DATA,
|
||||
UNIT_DATA,
|
||||
AI_AGENT,
|
||||
PLAYER
|
||||
};
|
||||
const static std::vector<std::string> scripts = std::vector<std::string>{
|
||||
"Scripts/Core/main.lua",
|
||||
"Scripts/Gui/main.lua",
|
||||
"Scripts/Core/options.lua",
|
||||
"Scripts/GameObjects/resourceData.lua",
|
||||
"Scripts/GameObjects/Projectiles/projectileData.lua",
|
||||
"Scripts/GameObjects/Units/unitData.lua",
|
||||
"Scripts/aiAgent.lua",
|
||||
"Scripts/Core/player.lua",
|
||||
"Scripts/Technologies/technologyData.lua",
|
||||
"Scripts/Abilities/abilityData.lua",
|
||||
"Scripts/Trading/traderData.lua"
|
||||
};
|
||||
|
||||
const static Bind staticBinds[numAppStates][maxStaticBinds]{
|
||||
{
|
||||
Bind::LEFT_CLICK,
|
||||
Bind::SCROLLING_UP,
|
||||
Bind::SCROLLING_DOWN,
|
||||
Bind::LEFT,
|
||||
Bind::RIGHT,
|
||||
Bind::DELETE_CHAR,
|
||||
},
|
||||
{},
|
||||
{
|
||||
Bind::LOOK_UP,
|
||||
Bind::LOOK_DOWN,
|
||||
Bind::LOOK_LEFT,
|
||||
Bind::LOOK_RIGHT,
|
||||
Bind::LOOK_AROUND,
|
||||
},
|
||||
{
|
||||
Bind::LOOK_UP,
|
||||
Bind::LOOK_DOWN,
|
||||
Bind::LOOK_LEFT,
|
||||
Bind::LOOK_RIGHT,
|
||||
Bind::LOOK_AROUND,
|
||||
},
|
||||
{}
|
||||
};
|
||||
const static Bind confBinds[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{
|
||||
Bind::TOGGLE_MAIN_MENU
|
||||
},
|
||||
{
|
||||
Bind::DRAG_BOX,
|
||||
Bind::MOVE_CAMERA,
|
||||
Bind::ROTATE_OBJ_FRAME,
|
||||
Bind::HALT,
|
||||
Bind::ZOOM_IN,
|
||||
Bind::ZOOM_OUT,
|
||||
Bind::LEFT_CONTROL,
|
||||
Bind::LEFT_SHIFT,
|
||||
Bind::SELECT_PATROL_POINTS,
|
||||
Bind::LAUNCH,
|
||||
Bind::SHIFT_SUB_DEPTH,
|
||||
Bind::GROUP_0,
|
||||
Bind::GROUP_1,
|
||||
Bind::GROUP_2,
|
||||
Bind::GROUP_3,
|
||||
Bind::GROUP_4,
|
||||
Bind::GROUP_5,
|
||||
Bind::GROUP_6,
|
||||
Bind::GROUP_7,
|
||||
Bind::GROUP_8,
|
||||
Bind::GROUP_9,
|
||||
Bind::SELECT_STRUCTURE,
|
||||
Bind::DESELECT_STRUCTURE
|
||||
},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static int staticTriggers[numAppStates][maxStaticBinds]{
|
||||
{
|
||||
0,
|
||||
GLFW_KEY_W,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_BACKSPACE
|
||||
},
|
||||
{},
|
||||
{
|
||||
Mapping::MOUSE_AXIS_UP,
|
||||
Mapping::MOUSE_AXIS_DOWN,
|
||||
Mapping::MOUSE_AXIS_LEFT,
|
||||
Mapping::MOUSE_AXIS_RIGHT,
|
||||
0
|
||||
},
|
||||
{
|
||||
Mapping::MOUSE_AXIS_UP,
|
||||
Mapping::MOUSE_AXIS_DOWN,
|
||||
Mapping::MOUSE_AXIS_LEFT,
|
||||
Mapping::MOUSE_AXIS_RIGHT,
|
||||
0
|
||||
},
|
||||
{}
|
||||
};
|
||||
const static int confTriggers[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{
|
||||
GLFW_KEY_ESCAPE
|
||||
},
|
||||
{
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_H,
|
||||
3,
|
||||
4,
|
||||
GLFW_KEY_LEFT_CONTROL,
|
||||
GLFW_KEY_LEFT_SHIFT,
|
||||
GLFW_KEY_P,
|
||||
GLFW_KEY_C,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_0,
|
||||
GLFW_KEY_1,
|
||||
GLFW_KEY_2,
|
||||
GLFW_KEY_3,
|
||||
GLFW_KEY_4,
|
||||
GLFW_KEY_5,
|
||||
GLFW_KEY_6,
|
||||
GLFW_KEY_7,
|
||||
GLFW_KEY_8,
|
||||
GLFW_KEY_9,
|
||||
GLFW_KEY_B,
|
||||
GLFW_KEY_ESCAPE
|
||||
},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static bool isStaticKey[numAppStates][maxStaticBinds]{
|
||||
{0, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{0, 0, 0, 0, 1},
|
||||
{0, 0, 0, 0, 1},
|
||||
{}
|
||||
};
|
||||
const static bool isConfKey[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static bool isStaticAction[numAppStates][maxStaticBinds]{
|
||||
{1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{0, 0, 0, 0, 1},
|
||||
{0, 0, 0, 0, 1},
|
||||
{}
|
||||
};
|
||||
const static bool isConfAction[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
int calcSumStaticBinds(int, bool);
|
||||
int calcSumConfBinds(int, bool);
|
||||
int calcSumBinds(int, bool);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef DEF_CONFIGS_H
|
||||
#define DEF_CONFIGS_H
|
||||
#define SOL_ALL_SAFETIES_ON 1
|
||||
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <util.h>
|
||||
|
||||
#include <glfw3.h>
|
||||
|
||||
#include <mapping.h>
|
||||
#include <sol/sol.hpp>
|
||||
|
||||
#include "binds.h"
|
||||
#include "gameManager.h"
|
||||
|
||||
namespace battleship{
|
||||
namespace configData{
|
||||
using namespace gameBase;
|
||||
|
||||
const std::string DEFAULT_TEXTURE = "Textures/defaultTexture.jpg";
|
||||
const double camPanSpeed = .5, CAMERA_DISTANCE = 100, CAMERA_ZOOM_INCREMENT = 1, cellLength = 7, cellWidth = 7, cellDepth = 7, DIST_FROM_RAY = 15;
|
||||
const int maxNumGroups = 10, NUM_MAX_ZOOMS = 75, NUM_SUBDIVS = 100;
|
||||
const vb01::u32 IMPASS_NODE_VAL = 65535;
|
||||
|
||||
const static int numAppStates = 5;
|
||||
const static int numStaticBinds[numAppStates]{6, 0, 5, 19, 0};
|
||||
const static int numConfBinds[numAppStates]{0, 1, 27, 0, 0};
|
||||
const static int maxStaticBinds = 19;
|
||||
const static int maxConfBinds = 23;
|
||||
const static int numScripts = 5;
|
||||
|
||||
const static std::string scriptPathBase = "Scripts/";
|
||||
enum ScriptFiles{
|
||||
CORE_MAIN,
|
||||
GUI_MAIN,
|
||||
OPTIONS,
|
||||
RESOURCE_DATA,
|
||||
PROJECTILE_DATA,
|
||||
UNIT_DATA,
|
||||
AI_AGENT,
|
||||
PLAYER
|
||||
};
|
||||
const static std::vector<std::string> scripts = std::vector<std::string>{
|
||||
"Scripts/Core/main.lua",
|
||||
"Scripts/Gui/main.lua",
|
||||
"Scripts/Core/options.lua",
|
||||
"Scripts/GameObjects/resourceData.lua",
|
||||
"Scripts/GameObjects/Projectiles/projectileData.lua",
|
||||
"Scripts/GameObjects/Units/unitData.lua",
|
||||
"Scripts/aiAgent.lua",
|
||||
"Scripts/Core/player.lua",
|
||||
"Scripts/Technologies/technologyData.lua",
|
||||
"Scripts/Abilities/abilityData.lua",
|
||||
"Scripts/Trading/traderData.lua"
|
||||
};
|
||||
|
||||
const static Bind staticBinds[numAppStates][maxStaticBinds]{
|
||||
{
|
||||
Bind::LEFT_CLICK,
|
||||
Bind::SCROLLING_UP,
|
||||
Bind::SCROLLING_DOWN,
|
||||
Bind::LEFT,
|
||||
Bind::RIGHT,
|
||||
Bind::DELETE_CHAR,
|
||||
},
|
||||
{},
|
||||
{
|
||||
Bind::LOOK_UP,
|
||||
Bind::LOOK_DOWN,
|
||||
Bind::LOOK_LEFT,
|
||||
Bind::LOOK_RIGHT,
|
||||
Bind::LOOK_AROUND,
|
||||
},
|
||||
{
|
||||
Bind::LOOK_UP,
|
||||
Bind::LOOK_DOWN,
|
||||
Bind::LOOK_LEFT,
|
||||
Bind::LOOK_RIGHT,
|
||||
Bind::LOOK_AROUND,
|
||||
},
|
||||
{}
|
||||
};
|
||||
const static Bind confBinds[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{
|
||||
Bind::TOGGLE_MAIN_MENU
|
||||
},
|
||||
{
|
||||
Bind::DRAG_BOX,
|
||||
Bind::MOVE_CAMERA,
|
||||
Bind::ROTATE_OBJ_FRAME,
|
||||
Bind::HALT,
|
||||
Bind::ZOOM_IN,
|
||||
Bind::ZOOM_OUT,
|
||||
Bind::LEFT_CONTROL,
|
||||
Bind::LEFT_SHIFT,
|
||||
Bind::SELECT_PATROL_POINTS,
|
||||
Bind::LAUNCH,
|
||||
Bind::SHIFT_SUB_DEPTH,
|
||||
Bind::GROUP_0,
|
||||
Bind::GROUP_1,
|
||||
Bind::GROUP_2,
|
||||
Bind::GROUP_3,
|
||||
Bind::GROUP_4,
|
||||
Bind::GROUP_5,
|
||||
Bind::GROUP_6,
|
||||
Bind::GROUP_7,
|
||||
Bind::GROUP_8,
|
||||
Bind::GROUP_9,
|
||||
Bind::SELECT_STRUCTURE,
|
||||
Bind::DESELECT_STRUCTURE
|
||||
},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static int staticTriggers[numAppStates][maxStaticBinds]{
|
||||
{
|
||||
0,
|
||||
GLFW_KEY_W,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_BACKSPACE
|
||||
},
|
||||
{},
|
||||
{
|
||||
Mapping::MOUSE_AXIS_UP,
|
||||
Mapping::MOUSE_AXIS_DOWN,
|
||||
Mapping::MOUSE_AXIS_LEFT,
|
||||
Mapping::MOUSE_AXIS_RIGHT,
|
||||
0
|
||||
},
|
||||
{
|
||||
Mapping::MOUSE_AXIS_UP,
|
||||
Mapping::MOUSE_AXIS_DOWN,
|
||||
Mapping::MOUSE_AXIS_LEFT,
|
||||
Mapping::MOUSE_AXIS_RIGHT,
|
||||
0
|
||||
},
|
||||
{}
|
||||
};
|
||||
const static int confTriggers[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{
|
||||
GLFW_KEY_ESCAPE
|
||||
},
|
||||
{
|
||||
GLFW_KEY_LEFT,
|
||||
GLFW_KEY_RIGHT,
|
||||
GLFW_KEY_H,
|
||||
3,
|
||||
4,
|
||||
GLFW_KEY_LEFT_CONTROL,
|
||||
GLFW_KEY_LEFT_SHIFT,
|
||||
GLFW_KEY_P,
|
||||
GLFW_KEY_C,
|
||||
GLFW_KEY_S,
|
||||
GLFW_KEY_0,
|
||||
GLFW_KEY_1,
|
||||
GLFW_KEY_2,
|
||||
GLFW_KEY_3,
|
||||
GLFW_KEY_4,
|
||||
GLFW_KEY_5,
|
||||
GLFW_KEY_6,
|
||||
GLFW_KEY_7,
|
||||
GLFW_KEY_8,
|
||||
GLFW_KEY_9,
|
||||
GLFW_KEY_B,
|
||||
GLFW_KEY_ESCAPE
|
||||
},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static bool isStaticKey[numAppStates][maxStaticBinds]{
|
||||
{0, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{0, 0, 0, 0, 1},
|
||||
{0, 0, 0, 0, 1},
|
||||
{}
|
||||
};
|
||||
const static bool isConfKey[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
const static bool isStaticAction[numAppStates][maxStaticBinds]{
|
||||
{1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{0, 0, 0, 0, 1},
|
||||
{0, 0, 0, 0, 1},
|
||||
{}
|
||||
};
|
||||
const static bool isConfAction[numAppStates][maxConfBinds]{
|
||||
{},
|
||||
{1},
|
||||
{1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1},
|
||||
{},
|
||||
{}
|
||||
};
|
||||
|
||||
int calcSumStaticBinds(int, bool);
|
||||
int calcSumConfBinds(int, bool);
|
||||
int calcSumBinds(int, bool);
|
||||
}
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,28 @@
|
||||
#ifndef ENVIRONMENT_H
|
||||
#define ENVIRONMENT_H
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include "fxManager.h"
|
||||
|
||||
namespace battleship
|
||||
{
|
||||
class Environment
|
||||
{
|
||||
public:
|
||||
enum class Detonation
|
||||
{
|
||||
EXPLOSION,
|
||||
EMP,
|
||||
CRYO
|
||||
};
|
||||
|
||||
static Environment *getSingleton();
|
||||
static void explode(FxManager::Fx *, Detonation, vb01::Vector3, int = 0, float = 0);
|
||||
|
||||
private:
|
||||
Environment() {}
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -5,37 +5,45 @@
|
||||
#include <model.h>
|
||||
#include <box.h>
|
||||
#include <material.h>
|
||||
#include <vector.h>
|
||||
#include <vector>
|
||||
#include <particleEmitter.h>
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
|
||||
namespace battleship{
|
||||
namespace battleship
|
||||
{
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
FxManager::Fx::Component::Component(void *c, bool v, s64 dur, vb01::Vector3 p, s64 ot) : comp(c), vfx(v), duration(dur), pos(p), offsetTime(ot) {
|
||||
if(v) ((vb01::Node*)c)->setVisible(false);
|
||||
FxManager::Fx::Component::Component(void *c, bool v, s64 dur, vb01::Vector3 p, s64 ot) : comp(c), vfx(v), duration(dur), pos(p), offsetTime(ot)
|
||||
{
|
||||
if (v)
|
||||
((vb01::Node *)c)->setVisible(false);
|
||||
}
|
||||
|
||||
FxManager::Fx::Fx(std::vector<FxManager::Fx::Component> comps, bool re) : components(comps), reuse(re){
|
||||
FxManager::Fx::Fx(std::vector<FxManager::Fx::Component> comps, bool re) : components(comps), reuse(re)
|
||||
{
|
||||
toggleComponents(!re);
|
||||
}
|
||||
|
||||
FxManager::Fx* FxManager::initFx(sol::table fxTbl, Node *baseNode, bool attached, Vector3 cp){
|
||||
FxManager::Fx *FxManager::initFx(sol::table fxTbl, Node *baseNode, bool attached, Vector3 cp)
|
||||
{
|
||||
int numComponents = fxTbl.size();
|
||||
|
||||
if(numComponents == 0) return nullptr;
|
||||
if (numComponents == 0)
|
||||
return nullptr;
|
||||
|
||||
vector<FxManager::Fx::Component> fxComponents;
|
||||
|
||||
for(int i = 0; i < numComponents; i++){
|
||||
for (int i = 0; i < numComponents; i++)
|
||||
{
|
||||
sol::table compTbl = fxTbl[i + 1];
|
||||
|
||||
bool vfx = compTbl["vfx"];
|
||||
s64 duration = compTbl["duration"], offset = compTbl["offset"].get_or(0);
|
||||
|
||||
if(vfx){
|
||||
if (vfx)
|
||||
{
|
||||
sol::table meshTbl = compTbl["mesh"];
|
||||
|
||||
string meshPath = "";
|
||||
@@ -47,30 +55,34 @@ namespace battleship{
|
||||
Quaternion compRot = Quaternion::QUAT_W;
|
||||
float sc = compTbl["scale"].get_or(1);
|
||||
|
||||
if(posOpt != sol::nullopt){
|
||||
if (posOpt != sol::nullopt)
|
||||
{
|
||||
sol::table posTable = compTbl["pos"];
|
||||
compPos = Vector3(posTable["x"], posTable["y"], posTable["z"]);
|
||||
}
|
||||
|
||||
if(rotOpt != sol::nullopt){
|
||||
if (rotOpt != sol::nullopt)
|
||||
{
|
||||
sol::table rotTable = compTbl["rot"];
|
||||
compRot = Quaternion(rotTable["w"], rotTable["x"], rotTable["y"], rotTable["z"]);
|
||||
}
|
||||
|
||||
sol::optional<string> pathOpt = meshTbl["path"];
|
||||
sol::optional<int> numPartOpt = meshTbl["numParticles"];
|
||||
sol::optional<string> pathOpt = meshTbl["path"];
|
||||
sol::optional<int> numPartOpt = meshTbl["numParticles"];
|
||||
|
||||
if(pathOpt != sol::nullopt){
|
||||
if (pathOpt != sol::nullopt)
|
||||
{
|
||||
mat = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
|
||||
meshPath = meshTbl["path"];
|
||||
flashNode = new Model(meshPath);
|
||||
((Model*)flashNode)->setMaterial(mat);
|
||||
((Model *)flashNode)->setMaterial(mat);
|
||||
flashNode->setPosition(compPos);
|
||||
flashNode->setOrientation(compRot);
|
||||
flashNode->setScale(Vector3(sc, sc, sc));
|
||||
}
|
||||
else if(numPartOpt != sol::nullopt){
|
||||
else if (numPartOpt != sol::nullopt)
|
||||
{
|
||||
mat = new Material(Root::getSingleton()->getLibPath() + "particle");
|
||||
|
||||
int numParticles = meshTbl["numParticles"];
|
||||
@@ -87,7 +99,8 @@ namespace battleship{
|
||||
flashNode->attachParticleEmitter(pe);
|
||||
flashNode->lookAt(Vector3::VEC_J, Vector3::VEC_K);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
mat = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
|
||||
sol::table sizeTbl = meshTbl["size"];
|
||||
@@ -100,13 +113,15 @@ namespace battleship{
|
||||
|
||||
sol::optional<string> texOpt = meshTbl["texture"];
|
||||
|
||||
if(texOpt != sol::nullopt){
|
||||
if (texOpt != sol::nullopt)
|
||||
{
|
||||
string p[]{meshTbl["texture"]};
|
||||
Texture *tex = new Texture(p, 1, false);
|
||||
mat->addBoolUniform("texturingEnabled", true);
|
||||
mat->addTexUniform("diffuseMap[0]", tex, false);
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
sol::table colorTable = meshTbl["color"];
|
||||
mat->addVec4Uniform("diffuseColor", Vector4(colorTable["x"], colorTable["y"], colorTable["z"], colorTable["a"]));
|
||||
mat->addBoolUniform("texturingEnabled", false);
|
||||
@@ -116,26 +131,30 @@ namespace battleship{
|
||||
Node *parNode = (attached ? baseNode : Root::getSingleton()->getRootNode());
|
||||
sol::optional<string> parNameOpt = compTbl["parent"];
|
||||
|
||||
if(parNameOpt != sol::nullopt){
|
||||
if (parNameOpt != sol::nullopt)
|
||||
{
|
||||
string parName = compTbl["parent"];
|
||||
parNode = baseNode->findDescendant(parName, true);
|
||||
}
|
||||
|
||||
parNode->attachChild(flashNode);
|
||||
fxComponents.push_back(FxManager::Fx::Component((void*)flashNode, vfx, duration, compPos, offset));
|
||||
fxComponents.push_back(FxManager::Fx::Component((void *)flashNode, vfx, duration, compPos, offset));
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
sf::SoundBuffer *sfxBuffer = new sf::SoundBuffer();
|
||||
sf::Sound *sfx = GameObject::prepareSfx(sfxBuffer, compTbl["path"]);
|
||||
fxComponents.push_back(FxManager::Fx::Component((void*)sfx, vfx, duration, Vector3::VEC_ZERO, offset));
|
||||
fxComponents.push_back(FxManager::Fx::Component((void *)sfx, vfx, duration, Vector3::VEC_ZERO, offset));
|
||||
}
|
||||
}
|
||||
|
||||
return new FxManager::Fx(fxComponents, attached);
|
||||
}
|
||||
|
||||
void FxManager::Fx::toggleComponents(bool active){
|
||||
for(Component &component : components){
|
||||
void FxManager::Fx::toggleComponents(bool active)
|
||||
{
|
||||
for (Component &component : components)
|
||||
{
|
||||
component.active = active;
|
||||
component.initTime = getTime();
|
||||
}
|
||||
@@ -143,50 +162,59 @@ namespace battleship{
|
||||
|
||||
static FxManager *fxManager = nullptr;
|
||||
|
||||
FxManager* FxManager::getSingleton(){
|
||||
if(!fxManager)
|
||||
FxManager *FxManager::getSingleton()
|
||||
{
|
||||
if (!fxManager)
|
||||
fxManager = new FxManager();
|
||||
|
||||
return fxManager;
|
||||
}
|
||||
|
||||
void FxManager::update(){
|
||||
for(int i = 0; i < fxs.size(); i++){
|
||||
void FxManager::update()
|
||||
{
|
||||
for (int i = 0; i < fxs.size(); i++)
|
||||
{
|
||||
s64 currTime = getTime();
|
||||
Fx *fx = fxs[i];
|
||||
|
||||
for(int j = 0; j < fx->components.size(); j++){
|
||||
for (int j = 0; j < fx->components.size(); j++)
|
||||
{
|
||||
Fx::Component &comp = fx->components[j];
|
||||
s64 currTime = getTime();
|
||||
|
||||
if(comp.comp && currTime - comp.initTime > comp.offsetTime){
|
||||
if(comp.active){
|
||||
if(comp.vfx)
|
||||
((Node*)comp.comp)->setVisible(true);
|
||||
if (comp.comp && currTime - comp.initTime > comp.offsetTime)
|
||||
{
|
||||
if (comp.active)
|
||||
{
|
||||
if (comp.vfx)
|
||||
((Node *)comp.comp)->setVisible(true);
|
||||
else
|
||||
((sf::Sound*)comp.comp)->play();
|
||||
((sf::Sound *)comp.comp)->play();
|
||||
|
||||
comp.active = false;
|
||||
comp.initTime = getTime();
|
||||
}
|
||||
else if(!comp.active && currTime - comp.initTime > comp.duration){
|
||||
if(fx->reuse){
|
||||
if(comp.vfx)
|
||||
((Node*)comp.comp)->setVisible(false);
|
||||
else if (!comp.active && currTime - comp.initTime > comp.duration)
|
||||
{
|
||||
if (fx->reuse)
|
||||
{
|
||||
if (comp.vfx)
|
||||
((Node *)comp.comp)->setVisible(false);
|
||||
else
|
||||
((sf::Sound*)comp.comp)->stop();
|
||||
((sf::Sound *)comp.comp)->stop();
|
||||
}
|
||||
else{
|
||||
else
|
||||
{
|
||||
destroyFxComponent(i, j);
|
||||
fx->components.erase(fx->components.begin() + j);
|
||||
j--;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
if(fx->components.empty()){
|
||||
if (fx->components.empty())
|
||||
{
|
||||
delete fx;
|
||||
fxs.erase(fxs.begin() + i);
|
||||
i--;
|
||||
@@ -194,16 +222,19 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
void FxManager::destroyFxComponent(int fid, int cid){
|
||||
void FxManager::destroyFxComponent(int fid, int cid)
|
||||
{
|
||||
Fx *fx = fxs[fid];
|
||||
|
||||
if(fx->components[cid].vfx){
|
||||
Node *vfxNode = (Node*)fx->components[cid].comp, *parNode = vfxNode->getParent();
|
||||
if (fx->components[cid].vfx)
|
||||
{
|
||||
Node *vfxNode = (Node *)fx->components[cid].comp, *parNode = vfxNode->getParent();
|
||||
parNode->dettachChild(vfxNode);
|
||||
delete vfxNode;
|
||||
}
|
||||
else{
|
||||
sf::Sound *sfx = (sf::Sound*)fx->components[cid].comp;
|
||||
else
|
||||
{
|
||||
sf::Sound *sfx = (sf::Sound *)fx->components[cid].comp;
|
||||
const sf::SoundBuffer *buffer = &sfx->getBuffer();
|
||||
sfx->stop();
|
||||
|
||||
@@ -214,16 +245,18 @@ namespace battleship{
|
||||
fx->components[cid].comp = nullptr;
|
||||
}
|
||||
|
||||
void FxManager::removeFx(Fx *fx){
|
||||
void FxManager::removeFx(Fx *fx)
|
||||
{
|
||||
int id = -1;
|
||||
|
||||
for(int i = 0; i < fxs.size(); i++)
|
||||
if(fxs[i] == fx){
|
||||
for (int i = 0; i < fxs.size(); i++)
|
||||
if (fxs[i] == fx)
|
||||
{
|
||||
id = i;
|
||||
break;
|
||||
}
|
||||
|
||||
for(int i = 0; i < fx->components.size(); i++)
|
||||
for (int i = 0; i < fx->components.size(); i++)
|
||||
destroyFxComponent(id, i);
|
||||
|
||||
fxs.erase(fxs.begin() + id);
|
||||
@@ -6,7 +6,6 @@
|
||||
#include "inGameAppState.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "fxManager.h"
|
||||
#include "factory.h"
|
||||
#include "defConfigs.h"
|
||||
|
||||
#include <algorithm>
|
||||
@@ -44,12 +43,14 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void Game::update(){
|
||||
updateLuaPlayers(false);
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
|
||||
for(int i = 0; i < getCpuPlayers().size(); i++) {
|
||||
string plStr = "game.cpuPlayers[" + to_string(i + 1) + "]";
|
||||
SOL_LUA_VIEW.script("executeBtNode(" + plStr + ", " + plStr + ".behaviour)");
|
||||
}
|
||||
for(int i = 0; i < players.size(); i++)
|
||||
if(players[i]->isCpuPlayer()){
|
||||
string plStr = "game.players[" + to_string(i + 1) + "]";
|
||||
SOL_LUA_VIEW.script("executeBtNode(" + plStr + ", " + plStr + ".behaviour)");
|
||||
}
|
||||
|
||||
int numPlayersWithUnits = 0;
|
||||
|
||||
@@ -75,18 +76,18 @@ namespace battleship{
|
||||
FxManager::getSingleton()->update();
|
||||
}
|
||||
|
||||
void Game::initLuaPlayers(){
|
||||
void Game::updateLuaPlayers(bool resetBehaviour){
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
vector<Player*> cpuPlayers = getCpuPlayers();
|
||||
|
||||
for(int i = 0; i < cpuPlayers.size(); i++)
|
||||
SOL_LUA_VIEW["game"]["cpuPlayers"][i + 1] = cpuPlayers[i];
|
||||
for(int i = 0; i < players.size(); i++)
|
||||
SOL_LUA_VIEW["game"]["players"][i + 1] = players[i];
|
||||
|
||||
SOL_LUA_VIEW.script_file(GameManager::getSingleton()->getPath() + "Scripts/Core/playerInit.lua");
|
||||
if(resetBehaviour)
|
||||
SOL_LUA_VIEW.script_file(GameManager::getSingleton()->getPath() + "Scripts/Core/playerInit.lua");
|
||||
}
|
||||
|
||||
void Game::removeAllElements(){
|
||||
generateView().script("game.cpuPlayers = {}");
|
||||
generateView().script("game.players = {}");
|
||||
|
||||
while(!players.empty()){
|
||||
delete players[0];
|
||||
@@ -112,7 +113,7 @@ namespace battleship{
|
||||
for(string f : configData::scripts)
|
||||
SOL_LUA_VIEW.script_file(gm->getPath() + f);
|
||||
|
||||
initLuaPlayers();
|
||||
updateLuaPlayers(true);
|
||||
guiManager->readLuaScreenScript("inGame.lua", activeState->getGuiButtons());
|
||||
|
||||
string gop = SOL_LUA_VIEW["gameObjPrefix"], vfxp = SOL_LUA_VIEW["vfxPrefix"];
|
||||
@@ -232,14 +233,4 @@ namespace battleship{
|
||||
|
||||
return playersVec;
|
||||
}
|
||||
|
||||
vector<Player*> Game::getCpuPlayers(){
|
||||
vector<Player*> playersVec;
|
||||
|
||||
for(Player *pl : players)
|
||||
if(pl->isCpuPlayer())
|
||||
playersVec.push_back(pl);
|
||||
|
||||
return playersVec;
|
||||
}
|
||||
}
|
||||
@@ -20,14 +20,13 @@ namespace battleship{
|
||||
public:
|
||||
static Game* getSingleton();
|
||||
void update();
|
||||
void initLuaPlayers();
|
||||
void updateLuaPlayers(bool);
|
||||
void togglePause();
|
||||
void removeAllElements();
|
||||
void initTechnologies();
|
||||
float calcAbilFromTech(Ability::Type, std::vector<int>, int, int);
|
||||
bool isUnitUnlocked(std::vector<int>, int);
|
||||
std::vector<Player*> getPlayers(bool = false);
|
||||
std::vector<Player*> getCpuPlayers();
|
||||
inline void setDebug(bool d){this->debug = d;}
|
||||
inline void addPlayer(Player *pl){players.push_back(pl);}
|
||||
inline bool isDebug(){return debug;}
|
||||
Executable → Regular
+201
-279
@@ -1,279 +1,201 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <inputManager.h>
|
||||
#include <soundManager.h>
|
||||
|
||||
#include <assetManager.h>
|
||||
#include <root.h>
|
||||
|
||||
#include "gameManager.h"
|
||||
#include "gameObjectFrameController.h"
|
||||
#include "gameObjectFactory.h"
|
||||
#include "map.h"
|
||||
#include "game.h"
|
||||
#include "guiAppState.h"
|
||||
#include "defConfigs.h"
|
||||
#include "player.h"
|
||||
#include "extractor.h"
|
||||
#include "factory.h"
|
||||
#include "vehicle.h"
|
||||
#include "engineer.h"
|
||||
#include "destructable.h"
|
||||
#include "pointDefense.h"
|
||||
#include "pathfinder.h"
|
||||
#include "resourceDeposit.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
|
||||
namespace battleship{
|
||||
static GameManager *gameManager = nullptr;
|
||||
|
||||
GameManager* GameManager::getSingleton(){
|
||||
if(!gameManager)
|
||||
gameManager = new GameManager();
|
||||
|
||||
return gameManager;
|
||||
}
|
||||
|
||||
void GameManager::registerMembers(){
|
||||
sol::state_view SOL_LUA_STATE = generateView();
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Order>(
|
||||
"Order", sol::constructors<Order(), Order(Order::TYPE, vector<Order::Target>, Vector3, int)>(),
|
||||
"type", &Order::type,
|
||||
"direction", &Order::direction,
|
||||
"targets", &Order::targets
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Order::Target>(
|
||||
"Target", sol::constructors<Order::Target(), Order::Target(GameObject*, Vector3)>(),
|
||||
"unit", &Order::Target::unit,
|
||||
"pos", &Order::Target::pos
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<GameObjectFactory>(
|
||||
"GameObjectFactory",
|
||||
"createUnit", &GameObjectFactory::createUnit,
|
||||
"createResourceDeposit", &GameObjectFactory::createResourceDeposit
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Unit::GarrisonSlot>(
|
||||
"GarrisonSlot",
|
||||
"vehicle", &Unit::GarrisonSlot::vehicle,
|
||||
"category", &Unit::GarrisonSlot::category
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Unit>(
|
||||
"Unit", sol::constructors<Unit(Player*, int, Vector3, Quaternion)>(),
|
||||
"setState", &Unit::setState,
|
||||
"getDestructable", &Unit::getDestructable,
|
||||
"getGarrisonSlots", &Unit::getGarrisonSlots,
|
||||
"getNumFreeGarrisonSlots", &Unit::getNumFreeGarrisonSlots,
|
||||
"getNumGarrisonSlots", &Unit::getNumGarrisonSlots,
|
||||
"isGarrisonEmpty", &Unit::isGarrisonEmpty,
|
||||
"getOrder", &Unit::getOrder,
|
||||
"getNumOrders", &Unit::getNumOrders,
|
||||
"getDirVec", &GameObject::getDirVec,
|
||||
"getLeftVec", &GameObject::getLeftVec,
|
||||
"getPos", &GameObject::getPos,
|
||||
"getUnitClass", &Unit::getUnitClass,
|
||||
"getLineOfSight", &Unit::getLineOfSight,
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits,
|
||||
"toGameObject", [](Unit *u){return (GameObject*)u;},
|
||||
"toVehicle", [](Unit *u){return (Vehicle*)u;},
|
||||
"toEngineer", [](Unit *u){return (Engineer*)u;},
|
||||
"toStructure", [](Unit *u){return (Structure*)u;},
|
||||
"toFactory", [](Unit *u){return (Factory*)u;},
|
||||
"toExtractor", [](Unit *u){return (Extractor*)u;},
|
||||
"toPointDefense", [](Unit *u){return (PointDefense*)u;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Vehicle>(
|
||||
"Engineer", sol::constructors<Vehicle(Player*, int, Vector3, Quaternion, Unit::State)>(),
|
||||
"getGarrisonable", &Vehicle::getGarrisonable
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Engineer>(
|
||||
"Engineer", sol::constructors<Engineer(Player*, int, Vector3, Quaternion, Unit::State)>(),
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Structure>(
|
||||
"Structure", sol::constructors<Structure(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getPos", &GameObject::getPos,
|
||||
"isComplete", &Structure::isComplete,
|
||||
"getBuildStatus", &Structure::getBuildStatus
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<BuildableUnit>(
|
||||
"BuildableUnit", sol::constructors<BuildableUnit(int, bool)>(),
|
||||
"id", &BuildableUnit::id,
|
||||
"buildable", &BuildableUnit::buildable
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Factory>(
|
||||
"Factory", sol::constructors<Factory(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits,
|
||||
"getDirVec", &GameObject::getDirVec,
|
||||
"getLeftVec", &GameObject::getLeftVec,
|
||||
"getPos", &GameObject::getPos,
|
||||
"appendToQueue", &Factory::appendToQueue,
|
||||
"getBuildStatus", &Structure::getBuildStatus,
|
||||
"getNumQueueUnitsById", &Factory::getNumQueueUnitsById,
|
||||
"getRallyPoint", &Factory::getRallyPoint,
|
||||
"setRallyPoint", &Factory::setRallyPoint,
|
||||
"getQueue", &Factory::getQueue
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Player>(
|
||||
"Player", sol::constructors<Player(int, int, int, Vector3, bool, int, string)>(),
|
||||
"getSelectedUnits", &Player::getSelectedUnits,
|
||||
"haltUnits", &Player::haltUnits,
|
||||
"addUnit", &Player::addUnit,
|
||||
"getUnit", &Player::getUnit,
|
||||
"getNumUnits", &Player::getNumUnits,
|
||||
"getResourceDeposits", &Player::getResourceDeposits,
|
||||
"issueOrder", &Player::issueOrder,
|
||||
"selectUnits", &Player::selectUnits,
|
||||
"deselectUnits", &Player::deselectUnits,
|
||||
"getSpawnPointId", &Player::getSpawnPointId,
|
||||
"getFaction", &Player::getFaction,
|
||||
"getTeam", &Player::getTeam,
|
||||
"getUnits", &Player::getUnits,
|
||||
"getHostileUnits", &Player::getHostileUnits,
|
||||
"getFriendlyUnits", &Player::getFriendlyUnits,
|
||||
"getUnitsById", &Player::getUnitsById,
|
||||
"getUnitsByClass", &Player::getUnitsByClass,
|
||||
"isObjectVisible", &Player::isObjectVisible
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Extractor>(
|
||||
"Extractor", sol::constructors<Extractor(Player*, int, Vector3, Quaternion, int, ResourceDeposit*, Unit::State)>(),
|
||||
"getDeposit", &Extractor::getDeposit
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<ResourceDeposit>(
|
||||
"ResourceDeposit", sol::constructors<ResourceDeposit(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getExtractor", &ResourceDeposit::getExtractor,
|
||||
"getAmmount", &ResourceDeposit::getAmmount,
|
||||
"getPos", &GameObject::getPos,
|
||||
"toGameObject", [](ResourceDeposit *rd){return (GameObject*)rd;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Game>(
|
||||
"Game",
|
||||
"getSingleton", &Game::getSingleton,
|
||||
"getPlayers", &Game::getPlayers
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Vector3>(
|
||||
"Vector3", sol::constructors<Vector3(), Vector3(float, float, float)>(),
|
||||
"x", &Vector3::x,
|
||||
"y", &Vector3::y,
|
||||
"z", &Vector3::z,
|
||||
"norm", &Vector3::norm,
|
||||
"getAngleBetween", &Vector3::getAngleBetween,
|
||||
"getDistanceFrom", &Vector3::getDistanceFrom,
|
||||
"neg", [](Vector3 v){return -v;},
|
||||
"add", [](Vector3 v1, Vector3 v2){return v1 + v2;},
|
||||
"subtr", [](Vector3 v1, Vector3 v2){return v1 - v2;},
|
||||
"mult", [](Vector3 v1, float s){return v1 * s;},
|
||||
"div", [](Vector3 v1, float s){return v1 / s;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Quaternion>(
|
||||
"Quaternion", sol::constructors<Quaternion(), Quaternion(float, float, float, float), Quaternion(float, Vector3)>(),
|
||||
"w", &Quaternion::w,
|
||||
"x", &Quaternion::x,
|
||||
"y", &Quaternion::y,
|
||||
"z", &Quaternion::z,
|
||||
"getAngle", &Quaternion::getAngle,
|
||||
"getAxis", &Quaternion::getAxis,
|
||||
"multVec", [](Quaternion q, Vector3 v){return q * v;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Map::Cell>(
|
||||
"Cell",
|
||||
"pos", &Map::Cell::pos,
|
||||
"type", &Map::Cell::type
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Map>(
|
||||
"Map",
|
||||
"getSingleton", &Map::getSingleton,
|
||||
"getCell", &Map::getCell,
|
||||
"getCells", &Map::getCells,
|
||||
"getCellId", &Map::getCellId,
|
||||
"getMapSize", &Map::getMapSize,
|
||||
"getSpawnPoint", &Map::getSpawnPoint,
|
||||
"getNumSpawnPoints", &Map::getNumSpawnPoints
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Pathfinder>(
|
||||
"Pathfinder",
|
||||
"getSingleton", &Pathfinder::getSingleton,
|
||||
"calcHeuristics", &Pathfinder::calcHeuristics,
|
||||
"findPath", &Pathfinder::findPath
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<GameObjectFrame>(
|
||||
"GameObjectFrame", sol::constructors<GameObjectFrame(int, GameObject::Type, Player*, Unit*, Vector3, Quaternion)>(),
|
||||
"getOriginalUnit", &GameObjectFrame::getOriginalUnit,
|
||||
"destroy", &GameObjectFrame::destroy,
|
||||
"placeAt", &GameObjectFrame::placeAt,
|
||||
"getDirVec", &GameObjectFrame::getDirVec,
|
||||
"getLeftVec", &GameObjectFrame::getLeftVec,
|
||||
"getLength", &GameObjectFrame::getLength,
|
||||
"getWidth", &GameObjectFrame::getWidth,
|
||||
"status", &GameObjectFrame::status
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<GameObjectFrameController>(
|
||||
"GameObjectFrameController",
|
||||
"getSingleton", &GameObjectFrameController::getSingleton,
|
||||
"checkPlacement", &GameObjectFrameController::checkPlacement
|
||||
);
|
||||
}
|
||||
|
||||
void GameManager::initLua(string gameDir){
|
||||
sol::state_view SOL_LUA_STATE = generateView();
|
||||
|
||||
path = gameDir + "Assets/";
|
||||
SOL_LUA_STATE.script("PATH = \"" + path + "\";");
|
||||
|
||||
for(string f : configData::scripts)
|
||||
SOL_LUA_STATE.script_file(path + f);
|
||||
|
||||
sol::table resTable = SOL_LUA_STATE["graphics"]["resolution"];
|
||||
width = resTable["x"];
|
||||
height = resTable["y"];
|
||||
}
|
||||
|
||||
void GameManager::start(string gameDir) {
|
||||
running = true;
|
||||
registerMembers();
|
||||
initLua(gameDir);
|
||||
|
||||
Root *root = Root::getSingleton();
|
||||
root->start(width, height, path + "../external/vb01/", "Battleship");
|
||||
|
||||
stateManager = new StateManager();
|
||||
inputManager = new InputManager(stateManager, root->getWindow());
|
||||
}
|
||||
|
||||
void GameManager::update() {
|
||||
Root::getSingleton()->update();
|
||||
SoundManager::getSingleton()->update();
|
||||
inputManager->update();
|
||||
stateManager->update();
|
||||
}
|
||||
}
|
||||
#include <algorithm>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <inputManager.h>
|
||||
#include <soundManager.h>
|
||||
|
||||
#include <assetManager.h>
|
||||
#include <root.h>
|
||||
|
||||
#include "gameManager.h"
|
||||
#include "gameObjectFactory.h"
|
||||
#include "map.h"
|
||||
#include "game.h"
|
||||
#include "guiAppState.h"
|
||||
#include "defConfigs.h"
|
||||
#include "player.h"
|
||||
#include "factory.h"
|
||||
#include "engineer.h"
|
||||
#include "destructable.h"
|
||||
#include "pointDefense.h"
|
||||
#include "resourceDeposit.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
|
||||
namespace battleship{
|
||||
static GameManager *gameManager = nullptr;
|
||||
|
||||
GameManager* GameManager::getSingleton(){
|
||||
if(!gameManager)
|
||||
gameManager = new GameManager();
|
||||
|
||||
return gameManager;
|
||||
}
|
||||
|
||||
void GameManager::registerMembers(){
|
||||
sol::state_view SOL_LUA_STATE = generateView();
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Order>(
|
||||
"Order", sol::constructors<Order(), Order(Order::TYPE, vector<Order::Target>, Vector3, int)>(),
|
||||
"type", &Order::type,
|
||||
"direction", &Order::direction,
|
||||
"targets", &Order::targets
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Order::Target>(
|
||||
"Target", sol::constructors<Order::Target(), Order::Target(GameObject*, Vector3)>(),
|
||||
"unit", &Order::Target::unit,
|
||||
"pos", &Order::Target::pos
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<GameObjectFactory>(
|
||||
"GameObjectFactory",
|
||||
"createUnit", &GameObjectFactory::createUnit,
|
||||
"createResourceDeposit", &GameObjectFactory::createResourceDeposit
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Unit>(
|
||||
"Unit", sol::constructors<Unit(Player*, int, Vector3, Quaternion)>(),
|
||||
"setState", &Unit::setState,
|
||||
"getDestructable", &Unit::getDestructable,
|
||||
"getOrder", &Unit::getOrder,
|
||||
"getNumOrders", &Unit::getNumOrders,
|
||||
"getPos", &GameObject::getPos,
|
||||
"getUnitClass", &Unit::getUnitClass,
|
||||
"getLineOfSight", &Unit::getLineOfSight,
|
||||
"toEngineer", &Unit::toEngineer,
|
||||
"toPointDefense", &Unit::toPointDefense,
|
||||
"toStructure", &Unit::toStructure,
|
||||
"toFactory", &Unit::toFactory,
|
||||
"toGameObject", &Unit::toGameObject,
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Engineer>(
|
||||
"Engineer", sol::constructors<Engineer(Player*, int, Vector3, Quaternion, Unit::State)>(),
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Structure>(
|
||||
"Structure", sol::constructors<Structure(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getPos", &GameObject::getPos,
|
||||
"getBuildStatus", &Structure::getBuildStatus
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<BuildableUnit>(
|
||||
"BuildableUnit", sol::constructors<BuildableUnit(int, bool)>(),
|
||||
"id", &BuildableUnit::id,
|
||||
"buildable", &BuildableUnit::buildable
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Factory>(
|
||||
"Factory", sol::constructors<Factory(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getBuildableUnit", &Unit::getBuildableUnit,
|
||||
"getBuildableUnits", &Unit::getBuildableUnits,
|
||||
"getNumBuildableUnits", &Unit::getNumBuildableUnits,
|
||||
"getPos", &GameObject::getPos,
|
||||
"appendToQueue", &Factory::appendToQueue,
|
||||
"getBuildStatus", &Structure::getBuildStatus,
|
||||
"getNumQueueUnitsById", &Factory::getNumQueueUnitsById,
|
||||
"getQueue", &Factory::getQueue
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Player>(
|
||||
"Player", sol::constructors<Player(int, int, int, Vector3, bool, int, string)>(),
|
||||
"getSelectedUnits", &Player::getSelectedUnits,
|
||||
"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,
|
||||
"getUnitsById", &Player::getUnitsById,
|
||||
"getUnitsByClass", &Player::getUnitsByClass
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<ResourceDeposit>(
|
||||
"ResourceDeposit", sol::constructors<ResourceDeposit(Player*, int, Vector3, Quaternion, int)>(),
|
||||
"getPos", &GameObject::getPos
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Game>(
|
||||
"Game",
|
||||
"getSingleton", &Game::getSingleton,
|
||||
"getPlayers", &Game::getPlayers
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Vector3>(
|
||||
"Vector3", sol::constructors<Vector3(), Vector3(float, float, float)>(),
|
||||
"x", &Vector3::x,
|
||||
"y", &Vector3::y,
|
||||
"z", &Vector3::z,
|
||||
"norm", &Vector3::norm,
|
||||
"getAngleBetween", &Vector3::getAngleBetween,
|
||||
"getDistanceFrom", &Vector3::getDistanceFrom,
|
||||
"add", [](Vector3 v1, Vector3 v2){return v1 + v2;},
|
||||
"subtr", [](Vector3 v1, Vector3 v2){return v1 - v2;},
|
||||
"mult", [](Vector3 v1, float s){return v1 * s;},
|
||||
"div", [](Vector3 v1, float s){return v1 / s;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Quaternion>(
|
||||
"Quaternion", sol::constructors<Quaternion(), Quaternion(float, float, float, float), Quaternion(float, Vector3)>(),
|
||||
"w", &Quaternion::w,
|
||||
"x", &Quaternion::x,
|
||||
"y", &Quaternion::y,
|
||||
"z", &Quaternion::z,
|
||||
"multVec", [](Quaternion q, Vector3 v){return q * v;}
|
||||
);
|
||||
|
||||
SOL_LUA_STATE.new_usertype<Map>(
|
||||
"Map",
|
||||
"getSingleton", &Map::getSingleton,
|
||||
"getSpawnPoint", &Map::getSpawnPoint,
|
||||
"getNumSpawnPoints", &Map::getNumSpawnPoints
|
||||
);
|
||||
}
|
||||
|
||||
void GameManager::initLua(string gameDir){
|
||||
sol::state_view SOL_LUA_STATE = generateView();
|
||||
|
||||
path = gameDir + "Assets/";
|
||||
SOL_LUA_STATE.script("PATH = \"" + path + "\";");
|
||||
|
||||
for(string f : configData::scripts)
|
||||
SOL_LUA_STATE.script_file(path + f);
|
||||
|
||||
sol::table resTable = SOL_LUA_STATE["graphics"]["resolution"];
|
||||
width = resTable["x"];
|
||||
height = resTable["y"];
|
||||
}
|
||||
|
||||
void GameManager::start(string gameDir) {
|
||||
running = true;
|
||||
registerMembers();
|
||||
initLua(gameDir);
|
||||
|
||||
Root *root = Root::getSingleton();
|
||||
root->start(width, height, path + "../external/vb01/", "Battleship");
|
||||
|
||||
stateManager = new StateManager();
|
||||
inputManager = new InputManager(stateManager, root->getWindow());
|
||||
}
|
||||
|
||||
void GameManager::update() {
|
||||
Root::getSingleton()->update();
|
||||
SoundManager::getSingleton()->update();
|
||||
inputManager->update();
|
||||
stateManager->update();
|
||||
}
|
||||
}
|
||||
Executable → Regular
+46
-46
@@ -1,46 +1,46 @@
|
||||
#pragma once
|
||||
#ifndef GAME_MANAGER_H
|
||||
#define GAME_MANAGER_H
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <mapping.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace gameBase{
|
||||
class InputManager;
|
||||
class StateManager;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class GameManager {
|
||||
public:
|
||||
static GameManager* getSingleton();
|
||||
void start(std::string);
|
||||
void update();
|
||||
inline int getWidth(){return width;}
|
||||
inline int getHeight(){return height;}
|
||||
inline std::string getPath(){return path;}
|
||||
inline gameBase::InputManager* getInputManager(){return inputManager;}
|
||||
inline bool isServerSide(){return serverSide;}
|
||||
inline bool isRunning(){return running;}
|
||||
inline void setRunning(bool r){this->running = r;}
|
||||
inline gameBase::StateManager* getStateManager(){return stateManager;}
|
||||
private:
|
||||
GameManager(){}
|
||||
~GameManager(){}
|
||||
void registerMembers();
|
||||
void initLua(std::string);
|
||||
|
||||
gameBase::StateManager *stateManager = nullptr;
|
||||
gameBase::InputManager *inputManager = nullptr;
|
||||
int width, height;
|
||||
std::string path = "";
|
||||
bool serverSide, running = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
#pragma once
|
||||
#ifndef GAME_MANAGER_H
|
||||
#define GAME_MANAGER_H
|
||||
|
||||
#include "util.h"
|
||||
|
||||
#include <mapping.h>
|
||||
|
||||
#include <vector>
|
||||
#include <string>
|
||||
|
||||
namespace gameBase{
|
||||
class InputManager;
|
||||
class StateManager;
|
||||
}
|
||||
|
||||
namespace battleship{
|
||||
class GameManager {
|
||||
public:
|
||||
static GameManager* getSingleton();
|
||||
void start(std::string);
|
||||
void update();
|
||||
inline int getWidth(){return width;}
|
||||
inline int getHeight(){return height;}
|
||||
inline std::string getPath(){return path;}
|
||||
inline gameBase::InputManager* getInputManager(){return inputManager;}
|
||||
inline bool isServerSide(){return serverSide;}
|
||||
inline bool isRunning(){return running;}
|
||||
inline void setRunning(bool r){this->running = r;}
|
||||
inline gameBase::StateManager* getStateManager(){return stateManager;}
|
||||
private:
|
||||
GameManager(){}
|
||||
~GameManager(){}
|
||||
void registerMembers();
|
||||
void initLua(std::string);
|
||||
|
||||
gameBase::StateManager *stateManager = nullptr;
|
||||
gameBase::InputManager *inputManager = nullptr;
|
||||
int width, height;
|
||||
std::string path = "";
|
||||
bool serverSide, running = false;
|
||||
};
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,142 @@
|
||||
#include <sstream>
|
||||
#include <algorithm>
|
||||
|
||||
#include <vector>
|
||||
#include <util.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "defConfigs.h"
|
||||
#include "gameManager.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "guiAppState.h"
|
||||
|
||||
using namespace gameBase;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
namespace battleship
|
||||
{
|
||||
using namespace configData;
|
||||
|
||||
GuiAppState::GuiAppState() : AbstractAppState(
|
||||
AppStateType::GUI_STATE,
|
||||
configData::calcSumBinds(AppStateType::GUI_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::GUI_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS])
|
||||
{
|
||||
}
|
||||
|
||||
GuiAppState::~GuiAppState() {}
|
||||
|
||||
void GuiAppState::update()
|
||||
{
|
||||
ConcreteGuiManager::getSingleton()->update();
|
||||
}
|
||||
|
||||
void GuiAppState::onAttached()
|
||||
{
|
||||
AbstractAppState::onAttached();
|
||||
}
|
||||
|
||||
void GuiAppState::onDettached()
|
||||
{
|
||||
AbstractAppState::onDettached();
|
||||
}
|
||||
|
||||
void GuiAppState::onAction(int bind, bool isPressed)
|
||||
{
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
|
||||
switch ((Bind)bind)
|
||||
{
|
||||
case Bind::LEFT_CLICK:
|
||||
leftMousePressed = isPressed;
|
||||
|
||||
if (isPressed)
|
||||
guiManager->updateGui();
|
||||
|
||||
break;
|
||||
case Bind::SCROLLING_UP:
|
||||
{
|
||||
Listbox *l = getOpenListbox();
|
||||
if (l)
|
||||
l->scrollUp();
|
||||
break;
|
||||
}
|
||||
case Bind::SCROLLING_DOWN:
|
||||
{
|
||||
Listbox *l = getOpenListbox();
|
||||
if (l)
|
||||
l->scrollDown();
|
||||
break;
|
||||
}
|
||||
case Bind::DELETE_CHAR:
|
||||
{
|
||||
Textbox *t = getOpenTextbox();
|
||||
if (t)
|
||||
t->setDeleteCharacters(isPressed);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::onRawKeyPress(int ch)
|
||||
{
|
||||
for (Button *b : ConcreteGuiManager::getSingleton()->getButtons())
|
||||
if (b->getTrigger() == ch)
|
||||
{
|
||||
b->onClick();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void GuiAppState::onRawCharPress(u32 codepoint)
|
||||
{
|
||||
Textbox *currentTextbox = getOpenTextbox();
|
||||
|
||||
if (currentTextbox)
|
||||
currentTextbox->type(codepoint);
|
||||
}
|
||||
|
||||
void GuiAppState::onRawMousePress(int trigger)
|
||||
{
|
||||
}
|
||||
|
||||
Textbox *GuiAppState::getOpenTextbox()
|
||||
{
|
||||
vector<Textbox *> textboxes = ConcreteGuiManager::getSingleton()->getTextboxes();
|
||||
|
||||
for (int i = 0; i < textboxes.size(); i++)
|
||||
if (textboxes[i]->isEnabled())
|
||||
return textboxes[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
Listbox *GuiAppState::getOpenListbox()
|
||||
{
|
||||
vector<Listbox *> listboxes = ConcreteGuiManager::getSingleton()->getListboxes();
|
||||
|
||||
for (int i = 0; i < listboxes.size(); i++)
|
||||
if (listboxes[i]->isOpen())
|
||||
return listboxes[i];
|
||||
|
||||
return nullptr;
|
||||
}
|
||||
|
||||
void GuiAppState::onAnalog(int bind, float strength) {}
|
||||
|
||||
void GuiAppState::onRawMouseWheelScroll(bool up)
|
||||
{
|
||||
Listbox *openListbox = getOpenListbox();
|
||||
|
||||
if (!openListbox)
|
||||
return;
|
||||
|
||||
if (up)
|
||||
openListbox->scrollUp();
|
||||
else
|
||||
openListbox->scrollDown();
|
||||
}
|
||||
}
|
||||
Executable → Regular
+42
-42
@@ -1,42 +1,42 @@
|
||||
#pragma once
|
||||
#ifndef GUI_APP_STATE_H
|
||||
#define GUI_APP_STATE_H
|
||||
|
||||
#include <button.h>
|
||||
#include <listbox.h>
|
||||
#include <checkbox.h>
|
||||
#include <textbox.h>
|
||||
#include <slider.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <abstractAppState.h>
|
||||
|
||||
#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 <button.h>
|
||||
#include <listbox.h>
|
||||
#include <checkbox.h>
|
||||
#include <textbox.h>
|
||||
#include <slider.h>
|
||||
|
||||
#include <vector>
|
||||
|
||||
#include <abstractAppState.h>
|
||||
|
||||
#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
|
||||
Executable → Regular
+103
-103
@@ -1,103 +1,103 @@
|
||||
#include <algorithm>
|
||||
|
||||
#include <button.h>
|
||||
|
||||
#include <util.h>
|
||||
#include <root.h>
|
||||
#include <camera.h>
|
||||
#include <assetManager.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "defConfigs.h"
|
||||
#include "inGameAppState.h"
|
||||
#include "game.h"
|
||||
#include "console.h"
|
||||
#include "gameObjectFrameController.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "vessel.h"
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
using namespace gameBase;
|
||||
|
||||
InGameAppState::ResumeButton::ResumeButton(Vector3 pos, Vector2 size) : Button(pos, size, "Resume", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {}
|
||||
|
||||
void InGameAppState::ResumeButton::onClick() {
|
||||
Game::getSingleton()->togglePause();
|
||||
}
|
||||
|
||||
InGameAppState::ConsoleButton::ConsoleButton(Vector3 pos, Vector2 size) : Button(pos, size, "Console", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { }
|
||||
|
||||
void InGameAppState::ConsoleButton::onClick() {
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("console.lua");
|
||||
}
|
||||
|
||||
InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::ConsoleCommandEntryButton(Textbox *t, Listbox *l, Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", 257, true) {
|
||||
textbox = t;
|
||||
listbox = l;
|
||||
}
|
||||
|
||||
void InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::onClick() {
|
||||
Console::execute(wstringToString(textbox->getText()));
|
||||
}
|
||||
|
||||
InGameAppState::InGameAppState(std::string mn) : AbstractAppState(
|
||||
AppStateType::IN_GAME_STATE,
|
||||
configData::calcSumBinds(AppStateType::IN_GAME_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::IN_GAME_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]
|
||||
),
|
||||
mapName(mn),
|
||||
playerId(0){}
|
||||
|
||||
void InGameAppState::onAttached() {
|
||||
AbstractAppState::onAttached();
|
||||
|
||||
Map *map = Map::getSingleton();
|
||||
map->load(mapName);
|
||||
map->loadPlayersGameObjects();
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE);
|
||||
cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm());
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
StateManager *stateManager = gm->getStateManager();
|
||||
GuiAppState *guiState = ((GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE));
|
||||
activeState = new ActiveGameState(guiState, playerId);
|
||||
stateManager->attachAppState(activeState);
|
||||
|
||||
Game::getSingleton()->initLuaPlayers();
|
||||
//Map::Minimap::getSingleton()->updateImage();
|
||||
}
|
||||
|
||||
void InGameAppState::onDettached() {
|
||||
StateManager *sm = GameManager::getSingleton()->getStateManager();
|
||||
ActiveGameState *activeState = (ActiveGameState*)sm->getAppStateByType(int(AppStateType::ACTIVE_STATE));
|
||||
sm->dettachAppState(activeState);
|
||||
delete activeState;
|
||||
}
|
||||
|
||||
void InGameAppState::update() {
|
||||
Game::getSingleton()->update();
|
||||
Map::getSingleton()->update();
|
||||
}
|
||||
|
||||
void InGameAppState::onAction(int bind, bool isPressed) {
|
||||
switch((Bind)bind){
|
||||
case Bind::TOGGLE_MAIN_MENU:
|
||||
if(isPressed && !(GameObjectFrameController::getSingleton()->isPlacingOnSurface() || activeState->isForceCursorState()))
|
||||
Game::getSingleton()->togglePause();
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void InGameAppState::onAnalog(int bind, float str) {}
|
||||
}
|
||||
#include <algorithm>
|
||||
|
||||
#include <button.h>
|
||||
|
||||
#include <util.h>
|
||||
#include <root.h>
|
||||
#include <camera.h>
|
||||
#include <assetManager.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "defConfigs.h"
|
||||
#include "inGameAppState.h"
|
||||
#include "game.h"
|
||||
#include "console.h"
|
||||
#include "gameObjectFrameController.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "vessel.h"
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
using namespace std;
|
||||
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
using namespace gameBase;
|
||||
|
||||
InGameAppState::ResumeButton::ResumeButton(Vector3 pos, Vector2 size) : Button(pos, size, "Resume", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) {}
|
||||
|
||||
void InGameAppState::ResumeButton::onClick() {
|
||||
Game::getSingleton()->togglePause();
|
||||
}
|
||||
|
||||
InGameAppState::ConsoleButton::ConsoleButton(Vector3 pos, Vector2 size) : Button(pos, size, "Console", GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", -1, true) { }
|
||||
|
||||
void InGameAppState::ConsoleButton::onClick() {
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("console.lua");
|
||||
}
|
||||
|
||||
InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::ConsoleCommandEntryButton(Textbox *t, Listbox *l, Vector3 pos, Vector2 size, string name) : Button(pos, size, name, GameManager::getSingleton()->getPath() + "Fonts/batang.ttf", 257, true) {
|
||||
textbox = t;
|
||||
listbox = l;
|
||||
}
|
||||
|
||||
void InGameAppState::ConsoleButton::ConsoleButton::ConsoleCommandEntryButton::onClick() {
|
||||
Console::execute(wstringToString(textbox->getText()));
|
||||
}
|
||||
|
||||
InGameAppState::InGameAppState(std::string mn) : AbstractAppState(
|
||||
AppStateType::IN_GAME_STATE,
|
||||
configData::calcSumBinds(AppStateType::IN_GAME_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::IN_GAME_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]
|
||||
),
|
||||
mapName(mn),
|
||||
playerId(0){}
|
||||
|
||||
void InGameAppState::onAttached() {
|
||||
AbstractAppState::onAttached();
|
||||
|
||||
Map *map = Map::getSingleton();
|
||||
map->load(mapName);
|
||||
map->loadPlayersGameObjects();
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
cam->setPosition(Map::getSingleton()->getSpawnPoint(playerId) + Vector3(1, 1, 1) * configData::CAMERA_DISTANCE);
|
||||
cam->lookAt(Vector3(0, -1, -1).norm(), Vector3(0, 1, -1).norm());
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
StateManager *stateManager = gm->getStateManager();
|
||||
GuiAppState *guiState = ((GuiAppState*)stateManager->getAppStateByType((int)AppStateType::GUI_STATE));
|
||||
activeState = new ActiveGameState(guiState, playerId);
|
||||
stateManager->attachAppState(activeState);
|
||||
|
||||
Game::getSingleton()->updateLuaPlayers(true);
|
||||
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) {}
|
||||
}
|
||||
Executable → Regular
+60
-60
@@ -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 <vector>
|
||||
|
||||
//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<Unit*> getSelectedUnits(Player*);
|
||||
inline ActiveGameState* getActiveState(){return activeState;}
|
||||
private:
|
||||
bool isMainMenuActive = false;
|
||||
std::vector<std::string> 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 <vector>
|
||||
|
||||
//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<Unit*> getSelectedUnits(Player*);
|
||||
inline ActiveGameState* getActiveState(){return activeState;}
|
||||
private:
|
||||
bool isMainMenuActive = false;
|
||||
std::vector<std::string> modelPaths;
|
||||
int playerId;
|
||||
std::string mapName = "";
|
||||
ActiveGameState* activeState;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -5,45 +5,50 @@
|
||||
|
||||
#include <quad.h>
|
||||
#include <node.h>
|
||||
#include <vector.h>
|
||||
#include <vector>
|
||||
#include <assetManager.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
namespace battleship{
|
||||
namespace battleship
|
||||
{
|
||||
using namespace configData;
|
||||
using namespace gameBase;
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
LoadingAppState::LoadingAppState(AbstractAppState *newSt, string newScr) : AbstractAppState(
|
||||
AppStateType::LOADING_STATE,
|
||||
configData::calcSumBinds(AppStateType::LOADING_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::LOADING_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]
|
||||
),
|
||||
newState(newSt),
|
||||
newScreen(newScr)
|
||||
{}
|
||||
AppStateType::LOADING_STATE,
|
||||
configData::calcSumBinds(AppStateType::LOADING_STATE, true),
|
||||
configData::calcSumBinds(AppStateType::LOADING_STATE, false),
|
||||
GameManager::getSingleton()->getPath() + scripts[(int)ScriptFiles::OPTIONS]),
|
||||
newState(newSt),
|
||||
newScreen(newScr)
|
||||
{
|
||||
}
|
||||
|
||||
void LoadingAppState::onDettached(){
|
||||
void LoadingAppState::onDettached()
|
||||
{
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript(newScreen);
|
||||
GameManager::getSingleton()->getStateManager()->attachAppState(newState);
|
||||
|
||||
AbstractAppState::onDettached();
|
||||
AbstractAppState::onDettached();
|
||||
}
|
||||
|
||||
void LoadingAppState::update(){
|
||||
void LoadingAppState::update()
|
||||
{
|
||||
Node *loadingBar = ConcreteGuiManager::getSingleton()->getGuiRectangle("_loadingBar");
|
||||
Quad *quad = (Quad*)loadingBar->getMesh(0);
|
||||
Quad *quad = (Quad *)loadingBar->getMesh(0);
|
||||
quad->setSize(Vector3((1 - (float)loadableAssets.size() / initNumAssets) * 200.f, 20, 0));
|
||||
quad->updateVerts(quad->getMeshBase());
|
||||
|
||||
if(getTime() - lastUpdateTime > 5){
|
||||
if (getTime() - lastUpdateTime > 5)
|
||||
{
|
||||
AssetManager::getSingleton()->load(loadableAssets[0]);
|
||||
loadableAssets.erase(loadableAssets.begin());
|
||||
|
||||
if(loadableAssets.empty()) GameManager::getSingleton()->getStateManager()->dettachAppState(this);
|
||||
if (loadableAssets.empty())
|
||||
GameManager::getSingleton()->getStateManager()->dettachAppState(this);
|
||||
|
||||
lastUpdateTime = getTime();
|
||||
}
|
||||
Executable → Regular
+38
-38
@@ -1,38 +1,38 @@
|
||||
#include "util.h"
|
||||
#include "gameManager.h"
|
||||
#include "guiAppState.h"
|
||||
#include "concreteGuiManager.h"
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include <assetManager.h>
|
||||
#include <root.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace battleship;
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
string gamePath = string(argv[0]);
|
||||
|
||||
for(int i = 0; i < gamePath.length(); i++)
|
||||
if(gamePath[i] == '\\')
|
||||
gamePath[i] = '/';
|
||||
|
||||
gamePath = gamePath.substr(0, gamePath.find_last_of("/") + 1) + "../";
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
gm->start(gamePath);
|
||||
gm->getStateManager()->attachAppState(new GuiAppState());
|
||||
AssetManager::getSingleton()->load(gm->getPath() + "Fonts/batang.ttf");
|
||||
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("mainMenu.lua");
|
||||
|
||||
while(gm->isRunning()){
|
||||
gm->update();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
#include "util.h"
|
||||
#include "gameManager.h"
|
||||
#include "guiAppState.h"
|
||||
#include "concreteGuiManager.h"
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include <assetManager.h>
|
||||
#include <root.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
using namespace battleship;
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
int main(int argc, char **argv) {
|
||||
string gamePath = string(argv[0]);
|
||||
|
||||
for(int i = 0; i < gamePath.length(); i++)
|
||||
if(gamePath[i] == '\\')
|
||||
gamePath[i] = '/';
|
||||
|
||||
gamePath = gamePath.substr(0, gamePath.find_last_of("/") + 1) + "../";
|
||||
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
gm->start(gamePath);
|
||||
gm->getStateManager()->attachAppState(new GuiAppState());
|
||||
AssetManager::getSingleton()->load(gm->getPath() + "Fonts/batang.ttf");
|
||||
|
||||
ConcreteGuiManager::getSingleton()->readLuaScreenScript("mainMenu.lua");
|
||||
|
||||
while(gm->isRunning()){
|
||||
gm->update();
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -354,10 +354,10 @@ namespace battleship{
|
||||
Vector3 waterPos = terrainNode->getChild(k)->getPosition();
|
||||
Vector3 waterSize = ((Quad*)terrainNode->getChild(k)->getMesh(0))->getSize();
|
||||
|
||||
if(pos.y < waterPos.y && fabs(res[0].pos.x - waterPos.x) < .5 * waterSize.x && fabs(res[0].pos.z - waterPos.z) < .5 * waterSize.y){
|
||||
if(fabs(res[0].pos.x - waterPos.x) < .5 * waterSize.x && fabs(res[0].pos.z - waterPos.z) < .5 * waterSize.y){
|
||||
type = Map::Cell::Type::WATER;
|
||||
pos.y = waterPos.y;
|
||||
waterBodyBedPoints.push_back(pair(numVertCells * j + i, res[0].pos.y));
|
||||
waterBodyBedPoints.push_back(pair(numVertCells * i + j, res[0].pos.y));
|
||||
break;
|
||||
}
|
||||
}
|
||||
@@ -478,7 +478,7 @@ namespace battleship{
|
||||
void MapEditorAppState::MapEditor::generateMapScript(vector<Map::Cell> &cells){
|
||||
int numWaterBodies = map->getNodeParent()->getNumChildren() - 1;
|
||||
|
||||
string mapScript = "metadata = {\n\tlights = {";
|
||||
string mapScript = "map = {\n\tlights = {";
|
||||
|
||||
for(Node *light : map->getLights()){
|
||||
mapScript += "\n\t\t{type = " + to_string((int)light->getLight(0)->getLightType());
|
||||
@@ -514,6 +514,31 @@ namespace battleship{
|
||||
|
||||
mapScript += "\t},\n";
|
||||
mapScript += "\tcivilianPlayer = {\n" + generatePlayerTableStr(game->getCivilianPlayer()) + "\n\t},\n";
|
||||
mapScript += "\tcells = {\n";
|
||||
|
||||
for(Map::Cell cell : cells){
|
||||
Vector3 p = cell.pos;
|
||||
mapScript += "\t\t{type = " + to_string((int)cell.type) + ", pos = {x = " + to_string(p.x) + ", y = " + to_string(p.y) + ", z = " + to_string(p.z) + "}, numEdges = " + to_string(cell.edges.size()) + ", edges = {";
|
||||
|
||||
for(Map::Edge edge : cell.edges)
|
||||
mapScript += "{srcCellId = " + to_string(edge.srcCellId) + ", destCellId = " + to_string(edge.destCellId) + ", weight = " + to_string(edge.weight) + "}, ";
|
||||
|
||||
int numSubCells = cell.underWaterCellIds.size();
|
||||
mapScript += "}, numUnderWaterCells = " + to_string(numSubCells) + ",";
|
||||
|
||||
if(numSubCells > 0){
|
||||
mapScript += "underWaterCellId = {";
|
||||
|
||||
for(int subCellId : cell.underWaterCellIds)
|
||||
mapScript += to_string(subCellId) + ", ";
|
||||
|
||||
mapScript += "}";
|
||||
}
|
||||
|
||||
mapScript += "\t\t},\n";
|
||||
}
|
||||
|
||||
mapScript += "\t},\n";
|
||||
|
||||
Root *root = Root::getSingleton();
|
||||
string skyboxPath = "";
|
||||
@@ -543,41 +568,11 @@ namespace battleship{
|
||||
|
||||
mapScript += "\t}\n}";
|
||||
|
||||
string cellsScript = "cells = {\n";
|
||||
string file = GameManager::getSingleton()->getPath() + "Models/Maps/" + map->getMapName() + "/" + map->getMapName() + ".lua";
|
||||
|
||||
for(Map::Cell cell : cells){
|
||||
Vector3 p = cell.pos;
|
||||
cellsScript += "\t\t{type = " + to_string((int)cell.type) + ", pos = {x = " + to_string(p.x) + ", y = " + to_string(p.y) + ", z = " + to_string(p.z) + "}, numEdges = " + to_string(cell.edges.size()) + ", edges = {";
|
||||
|
||||
for(Map::Edge edge : cell.edges)
|
||||
cellsScript += "{srcCellId = " + to_string(edge.srcCellId) + ", destCellId = " + to_string(edge.destCellId) + ", weight = " + to_string(edge.weight) + "}, ";
|
||||
|
||||
int numSubCells = cell.underWaterCellIds.size();
|
||||
cellsScript += "}, numUnderWaterCells = " + to_string(numSubCells) + ",";
|
||||
|
||||
if(numSubCells > 0){
|
||||
cellsScript += "underWaterCellId = {";
|
||||
|
||||
for(int subCellId : cell.underWaterCellIds)
|
||||
cellsScript += to_string(subCellId) + ", ";
|
||||
|
||||
cellsScript += "}";
|
||||
}
|
||||
|
||||
cellsScript += "\t\t},\n";
|
||||
}
|
||||
|
||||
cellsScript += "\t}";
|
||||
|
||||
string basePath = GameManager::getSingleton()->getPath() + "Models/Maps/" + map->getMapName() + "/";
|
||||
|
||||
std::ofstream outFile(basePath + map->getMapName() + ".lua");
|
||||
std::ofstream outFile(file);
|
||||
outFile << mapScript;
|
||||
outFile.close();
|
||||
|
||||
outFile = std::ofstream(basePath + "cells.lua");
|
||||
outFile << cellsScript;
|
||||
outFile.close();
|
||||
}
|
||||
|
||||
void MapEditorAppState::MapEditor::exportMap(){
|
||||
@@ -0,0 +1,104 @@
|
||||
#ifndef MAP_EDITOR_APP_STATE_H
|
||||
#define MAP_EDITOR_APP_STATE_H
|
||||
|
||||
#include "map.h"
|
||||
#include "player.h"
|
||||
|
||||
#include <listbox.h>
|
||||
|
||||
#include <abstractAppState.h>
|
||||
|
||||
#include <vector>
|
||||
#include <util.h>
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace vb01
|
||||
{
|
||||
class Texture;
|
||||
}
|
||||
|
||||
namespace battleship
|
||||
{
|
||||
class MapEditor;
|
||||
|
||||
class MapEditorAppState : public gameBase::AbstractAppState
|
||||
{
|
||||
public:
|
||||
class MapEditor
|
||||
{
|
||||
public:
|
||||
enum TransformAxis
|
||||
{
|
||||
X_AXIS,
|
||||
Y_AXIS,
|
||||
Z_AXIS
|
||||
};
|
||||
|
||||
MapEditor(std::string, vb01::Vector2, bool);
|
||||
void updateCircleRadius(bool);
|
||||
void pushLandmassVerts(float);
|
||||
void castSelectionRay();
|
||||
void createWaterbody();
|
||||
void moveTerrainObject(float);
|
||||
void scaleTerrainObject(float);
|
||||
void exportMap();
|
||||
void prepareTerrainObjects(int = 0, int = -1);
|
||||
void togglePush(bool);
|
||||
inline vb01::Node *getSelectedNode() { return selectedTerrainNode; }
|
||||
inline float getGuiThreshold() { return guiThreshold; }
|
||||
inline float getCircleRadius() { return circleRadius; }
|
||||
inline bool isPushing() { return pushing; }
|
||||
inline void setPushPos(vb01::Vector3 p) { pushPos = p; }
|
||||
inline bool isMovingTerrainObject() { return movingTerrainObject; }
|
||||
inline void setMovingTerrainObject(bool m) { movingTerrainObject = m; }
|
||||
inline bool isScalingTerrainObject() { return scalingTerrainObject; }
|
||||
inline void setScalingTerrainObject(bool s) { scalingTerrainObject = s; }
|
||||
inline TransformAxis getTransformAxis() { return transformAxis; }
|
||||
inline void setTransformAxis(TransformAxis m) { transformAxis = m; }
|
||||
inline bool isWeightsGenerated() { return weightsGenerated; }
|
||||
inline vb01::Texture *getSkyTexture(int i) { return skyTextures[i]; }
|
||||
inline vb01::Texture *getLandmassTexture(int i) { return landmassTextures[i]; }
|
||||
|
||||
private:
|
||||
void generatePlane(vb01::Vector2);
|
||||
void prepareTextures(std::string, bool, std::vector<vb01::Texture *> &);
|
||||
void toggleSelection(vb01::Node *, bool);
|
||||
std::vector<Map::Cell> generateMapCells();
|
||||
void generateLandmassXml();
|
||||
void generateMinimap(std::string, std::vector<Map::Cell> &);
|
||||
std::string generatePlayerTableStr(Player *);
|
||||
void generateMapScript(std::vector<Map::Cell> &);
|
||||
void prepareTerrainObject(vb01::u32 **, Map::Cell *, int[3], float, bool);
|
||||
|
||||
Map *map;
|
||||
vb01::Node *selectedTerrainNode = nullptr;
|
||||
TransformAxis transformAxis = X_AXIS;
|
||||
vb01Gui::Listbox *skyListbox = nullptr;
|
||||
float *oldLandmassVertHeights = nullptr;
|
||||
bool pushing = false, movingTerrainObject = false, scalingTerrainObject = false, weightsGenerated = false, newMap, cellMarkersVisible = false;
|
||||
const float MIN_RADIUS = 1, MAX_RADIUS = 100, INCREASE_RATE = 1;
|
||||
float circleRadius = MIN_RADIUS, guiThreshold = 200;
|
||||
vb01::Vector3 pushPos = vb01::Vector3::VEC_ZERO;
|
||||
std::vector<vb01::Texture *> skyTextures, landmassTextures, waterTextures;
|
||||
};
|
||||
|
||||
MapEditorAppState(std::string, vb01::Vector2, bool);
|
||||
void update();
|
||||
void onAttached();
|
||||
void onDettached();
|
||||
void onAction(int, bool);
|
||||
void onAnalog(int, float);
|
||||
void onRawMouseWheelScroll(bool);
|
||||
inline MapEditor *getMapEditor() { return mapEditor; }
|
||||
|
||||
private:
|
||||
MapEditor *mapEditor = nullptr;
|
||||
std::string mapName;
|
||||
vb01::Vector2 mapSize;
|
||||
bool newMap;
|
||||
vb01::Text *radiusText = nullptr, *weightsText = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -16,64 +16,41 @@ namespace battleship{
|
||||
return pathfinder;
|
||||
}
|
||||
|
||||
vector<float> Pathfinder::calcHeuristics(vector<Map::Cell> &cells, int dest){
|
||||
vector<float> heuristics;
|
||||
|
||||
for(Map::Cell &cell : cells)
|
||||
heuristics.push_back(145 * (cells[dest].pos.getDistanceFrom(cell.pos)));
|
||||
|
||||
return heuristics;
|
||||
}
|
||||
|
||||
vector<int> Pathfinder::findPath(vector<Map::Cell> &cells, vector<float> &heuristics, int source, int dest, int vehicleType){
|
||||
if(heuristics.empty() || (heuristics.size() == 1 && heuristics[0] == 0.0))
|
||||
heuristics = calcHeuristics(cells, dest);
|
||||
|
||||
bool useHeur = !heuristics.empty();
|
||||
|
||||
vector<int> Pathfinder::findPath(vector<Map::Cell> &cells, vector<float> &heuristics, int source, int dest, Vehicle *vehicle){
|
||||
const int size = cells.size();
|
||||
u32 *distances = new u32[size];
|
||||
vector<int> *paths = new vector<int>[size];
|
||||
paths[source].push_back(source);
|
||||
|
||||
vector<pair<int, bool>> cellsByCheck;
|
||||
vector<bool> posMinCellChecked;
|
||||
vector<int> possibleMinCells = vector<int>{source};
|
||||
|
||||
vector<bool> cellChecked;
|
||||
|
||||
for(int i = 0; i < size; i++){
|
||||
cellsByCheck.push_back(pair(i, false));
|
||||
distances[i] = impassibleNodeVal;
|
||||
posMinCellChecked.push_back(false);
|
||||
distances[i] = (i == source ? 0 : impassibleNodeVal);
|
||||
cellChecked.push_back(false);
|
||||
}
|
||||
|
||||
paths[source].push_back(source);
|
||||
distances[source] = 0;
|
||||
posMinCellChecked[source] = true;
|
||||
|
||||
int lastVertStrich = -1;
|
||||
bool useHeur = !heuristics.empty();
|
||||
vector<int> possibleMinCells = vector<int>{source};
|
||||
cellChecked[source] = true;
|
||||
|
||||
while(!cellsByCheck[dest].second){
|
||||
int posMinCellId = 0, vertStrich = possibleMinCells[posMinCellId];
|
||||
int vertStrich = possibleMinCells[0], vsId = 0;
|
||||
|
||||
for(int i = 0; i < possibleMinCells.size(); i++){
|
||||
float sum1 = distances[possibleMinCells[i]] + (useHeur ? heuristics[possibleMinCells[i]] : 0);
|
||||
float sum2 = distances[possibleMinCells[posMinCellId]] + (useHeur ? heuristics[possibleMinCells[posMinCellId]] : 0);
|
||||
float sum2 = distances[possibleMinCells[vsId]] + (useHeur ? heuristics[possibleMinCells[vsId]] : 0);
|
||||
|
||||
if(sum1 < sum2 || (useHeur && sum1 == sum2 && heuristics[i] < heuristics[vertStrich])){
|
||||
posMinCellId = i;
|
||||
vertStrich = possibleMinCells[i];
|
||||
vsId = i;
|
||||
}
|
||||
}
|
||||
|
||||
if(distances[vertStrich] == impassibleNodeVal){
|
||||
vector<int> path = paths[lastVertStrich];
|
||||
|
||||
delete[] paths;
|
||||
delete[] distances;
|
||||
|
||||
return path;
|
||||
}
|
||||
|
||||
posMinCellChecked[possibleMinCells[posMinCellId]] = false;
|
||||
possibleMinCells.erase(possibleMinCells.begin() + posMinCellId);
|
||||
cellChecked[possibleMinCells[vsId]] = false;
|
||||
possibleMinCells.erase(possibleMinCells.begin() + vsId);
|
||||
|
||||
cellsByCheck[vertStrich].second = true;
|
||||
|
||||
@@ -84,20 +61,14 @@ namespace battleship{
|
||||
|
||||
if(cellsByCheck[edgeNode].second) continue;
|
||||
|
||||
if(!posMinCellChecked[edgeNode]){
|
||||
posMinCellChecked[edgeNode] = true;
|
||||
if(!cellChecked[edgeNode]){
|
||||
cellChecked[edgeNode] = true;
|
||||
possibleMinCells.push_back(edgeNode);
|
||||
}
|
||||
|
||||
UnitType ut = (UnitType)vehicleType;
|
||||
Map::Cell::Type ct = cells[edgeNode].type;
|
||||
bool ship = (ut == UnitType::UNDERWATER || ut == UnitType::SEA_LEVEL);
|
||||
int weightMult = 1;
|
||||
bool canMoveToStrichCell = true;
|
||||
|
||||
if((ut == UnitType::LAND && ct == Map::Cell::WATER) || (ship && ct == Map::Cell::LAND))
|
||||
weightMult = 10;
|
||||
/*
|
||||
if(vehicleType != -1){
|
||||
if(vehicle){
|
||||
UnitType unitType = vehicle->getType();
|
||||
bool ship = (unitType == UnitType::UNDERWATER || unitType == UnitType::SEA_LEVEL);
|
||||
Unit *blockingUnit = cells[vertStrich].blockedBy;
|
||||
@@ -123,16 +94,13 @@ namespace battleship{
|
||||
continue;
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
if(distances[vertStrich] + weightMult * cells[vertStrich].edges[i].weight < distances[edgeNode]){
|
||||
distances[edgeNode] = distances[vertStrich] + weightMult * cells[vertStrich].edges[i].weight;
|
||||
if(distances[vertStrich] + cells[vertStrich].edges[i].weight < distances[edgeNode]){
|
||||
distances[edgeNode] = distances[vertStrich] + cells[vertStrich].edges[i].weight;
|
||||
paths[edgeNode] = paths[vertStrich];
|
||||
paths[edgeNode].push_back(edgeNode);
|
||||
}
|
||||
}
|
||||
|
||||
lastVertStrich = vertStrich;
|
||||
}
|
||||
|
||||
vector<int> path = paths[dest];
|
||||
@@ -13,8 +13,7 @@ namespace battleship{
|
||||
class Pathfinder{
|
||||
public:
|
||||
static Pathfinder* getSingleton();
|
||||
std::vector<float> calcHeuristics(std::vector<Map::Cell>&, int);
|
||||
std::vector<int> findPath(std::vector<Map::Cell>&, std::vector<float>&, int, int, int = -1);
|
||||
std::vector<int> findPath(std::vector<Map::Cell>&, std::vector<float>&, int, int, Vehicle* = nullptr);
|
||||
inline vb01::u32 getImpassibleNodeVal(){return impassibleNodeVal;}
|
||||
inline void setImpassibleNodeVal(vb01::u32 val){this->impassibleNodeVal = val;}
|
||||
private:
|
||||
Executable → Regular
+289
-358
@@ -1,358 +1,289 @@
|
||||
#include <solUtil.h>
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "player.h"
|
||||
#include "game.h"
|
||||
#include "structure.h"
|
||||
#include "vehicle.h"
|
||||
#include "projectile.h"
|
||||
#include "tradeOffer.h"
|
||||
#include "destructable.h"
|
||||
#include "activeGameState.h"
|
||||
#include "resourceDeposit.h"
|
||||
|
||||
namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
using namespace std;
|
||||
|
||||
Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, int sp, string n) :
|
||||
difficulty(diff),
|
||||
faction(fac),
|
||||
team(t),
|
||||
color(col),
|
||||
cpuPlayer(cpuPl),
|
||||
spawnPointId(sp),
|
||||
name("pl"),
|
||||
trader(new Trader())
|
||||
{
|
||||
resources[0] = 30000;
|
||||
|
||||
colorMaterial = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
colorMaterial->addBoolUniform("lightingEnabled", false);
|
||||
colorMaterial->addBoolUniform("texturingEnabled", false);
|
||||
colorMaterial->addVec4Uniform("diffuseColor", Vector4(color.x, color.y, color.z, 1));
|
||||
}
|
||||
|
||||
Player::~Player() {
|
||||
delete colorMaterial;
|
||||
}
|
||||
|
||||
void Player::update() {
|
||||
trader->update();
|
||||
|
||||
vector<Unit*> units = this->units;
|
||||
for(Unit *u : units){
|
||||
if(!u->isRemove()) u->update();
|
||||
else removeUnit(u);
|
||||
}
|
||||
|
||||
vector<Projectile*> projectiles = this->projectiles;
|
||||
for(Projectile *proj : projectiles){
|
||||
if(!proj->isRemove()) proj->update();
|
||||
else removeProjectile(proj);
|
||||
}
|
||||
|
||||
for(ResourceDeposit *rd : resourceDeposits) rd->update();
|
||||
|
||||
for(pair<Player*, vector<TradeOffer*>> &pair : tradeOffers){
|
||||
if(pair.second.empty()) continue;
|
||||
|
||||
bool fulfiled = true;
|
||||
|
||||
for(int i = 0; i < NUM_RESOURCES && fulfiled; i++){
|
||||
bool b = (pair.second[0]->tradeResources[i][0] == pair.second[0]->deliveredResources[i][0]);
|
||||
bool s = (pair.second[0]->tradeResources[i][1] == pair.second[0]->deliveredResources[i][1]);
|
||||
|
||||
if(!(b && s)) fulfiled = false;
|
||||
}
|
||||
|
||||
if(fulfiled)
|
||||
pair.second.erase(pair.second.begin());
|
||||
}
|
||||
}
|
||||
|
||||
void Player::haltUnits(){
|
||||
for (Unit *u : selectedUnits)
|
||||
u->halt();
|
||||
}
|
||||
|
||||
int Player::getOrderLineId(Order::TYPE type, Vector3 startPos, Vector3 endPos){
|
||||
Vector3 color;
|
||||
|
||||
switch(type){
|
||||
case Order::TYPE::MOVE:
|
||||
color = Vector3::VEC_J;
|
||||
break;
|
||||
case Order::TYPE::ATTACK:
|
||||
color = Vector3::VEC_I;
|
||||
break;
|
||||
case Order::TYPE::PATROL:
|
||||
case Order::TYPE::GARRISON:
|
||||
case Order::TYPE::EJECT:
|
||||
color = Vector3::VEC_K;
|
||||
break;
|
||||
case Order::TYPE::BUILD:
|
||||
case Order::TYPE::SUPPLY:
|
||||
case Order::TYPE::LOAD:
|
||||
case Order::TYPE::UNLOAD:
|
||||
color = Vector3(1, 1, 0);
|
||||
break;
|
||||
case Order::TYPE::HACK:
|
||||
color = Vector3(1, 0, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
LineRenderer *lineRenderer = LineRenderer::getSingleton();
|
||||
lineRenderer->addLine(startPos, endPos, color);
|
||||
vector<LineRenderer::Line> lines = lineRenderer->getLines();
|
||||
|
||||
return lines[lines.size() - 1].id;
|
||||
}
|
||||
|
||||
void Player::issueOrder(Order::TYPE type, Vector3 destDir, vector<Order::Target> targets, bool append){
|
||||
vector<Unit*> selectedUnits = getSelectedUnits();
|
||||
|
||||
for (Unit *u : selectedUnits) {
|
||||
bool targetingSelf = false, structBuilt = true;
|
||||
|
||||
for(Order::Target &targ : targets){
|
||||
if(targ.unit && targ.unit == u){
|
||||
targetingSelf = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!u->isVehicle() && ((Structure*)u)->isComplete()){
|
||||
structBuilt = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(targetingSelf || !structBuilt) continue;
|
||||
|
||||
int lineId = -1;
|
||||
ActiveGameState *activeState = ((ActiveGameState*)GameManager::getSingleton()->getStateManager()->getAppStateByType(AppStateType::ACTIVE_STATE));
|
||||
|
||||
if(activeState && activeState->getPlayer() == this && type != Order::TYPE::EJECT)
|
||||
lineId = getOrderLineId(type, u->getPos(), targets[0].pos);
|
||||
|
||||
u->receiveOrder(Order(type, targets, destDir, lineId), append);
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeUnit(Unit *unit){
|
||||
for(int i = 0; i < units.size(); i++)
|
||||
if(unit == units[i]){
|
||||
removeUnit(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeUnit(int id){
|
||||
if(find(selectedUnits.begin(), selectedUnits.end(), units[id]) != selectedUnits.end())
|
||||
deselectUnit(units[id]);
|
||||
|
||||
delete units[id];
|
||||
units.erase(units.begin() + id);
|
||||
|
||||
if(cpuPlayer){
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
int id = getCpuPlayerId() + 1;
|
||||
SOL_LUA_VIEW.script("game.cpuPlayers[" + to_string(id) + "]:updateTaskForces()");
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeResourceDeposit(int id){
|
||||
delete resourceDeposits[id];
|
||||
resourceDeposits.erase(resourceDeposits.begin() + id);
|
||||
}
|
||||
|
||||
void Player::removeProjectile(Projectile *proj){
|
||||
for(int i = 0; i < projectiles.size(); i++)
|
||||
if(proj == projectiles[i]){
|
||||
removeProjectile(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeProjectile(int id){
|
||||
delete projectiles[id];
|
||||
projectiles.erase(projectiles.begin() + id);
|
||||
}
|
||||
|
||||
void Player::selectUnits(vector<Unit*> selUnits){
|
||||
for(Unit *u : selUnits){
|
||||
bool garrisonable = (!u->isVehicle() || (u->isVehicle() && !((Vehicle*)u)->getGarrisonable()));
|
||||
bool selected = (find(selectedUnits.begin(), selectedUnits.end(), u) != selectedUnits.end());
|
||||
|
||||
if(garrisonable && !selected){
|
||||
selectedUnits.push_back(u);
|
||||
u->select();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getUnitsById(int id, int numUnits){
|
||||
vector<Unit*> idUnits;
|
||||
|
||||
for(Unit *unit : units){
|
||||
if(numUnits != -1 && idUnits.size() == numUnits)
|
||||
break;
|
||||
|
||||
if(unit->getId() == id)
|
||||
idUnits.push_back(unit);
|
||||
}
|
||||
|
||||
return idUnits;
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getUnitsByClass(UnitClass uc, int numUnits){
|
||||
vector<Unit*> ucUnits;
|
||||
|
||||
for(Unit *unit : units){
|
||||
if(numUnits != -1 && ucUnits.size() == numUnits)
|
||||
break;
|
||||
|
||||
if(unit->getUnitClass() == uc)
|
||||
ucUnits.push_back(unit);
|
||||
}
|
||||
|
||||
return ucUnits;
|
||||
}
|
||||
|
||||
void Player::updateTradedResource(Player *player, ResourceType type, int amount, bool selfDistributed, bool increased){
|
||||
for(pair<Player*, vector<TradedResource>> pair : tradedResources)
|
||||
if(pair.first == player){
|
||||
TradedResource &tr = pair.second[(int)type];
|
||||
|
||||
if(selfDistributed) (increased ? tr.taken : tr.given) += amount;
|
||||
else (increased ? tr.received : tr.hadTaken) += amount;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::initTradingVecs(){
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers();
|
||||
|
||||
for(Player *pl : players){
|
||||
if(this == pl) continue;
|
||||
|
||||
if(team == pl->getTeam()){
|
||||
tradeOffers.push_back(make_pair(pl, vector<TradeOffer*>{}));
|
||||
tradedResources.push_back(make_pair(pl, vector<TradedResource>{
|
||||
TradedResource(ResourceType::REFINEDS),
|
||||
TradedResource(ResourceType::WEALTH),
|
||||
TradedResource(ResourceType::RESEARCH)
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::addTradeOffer(Player *player, TradeOffer *offer){
|
||||
if(tradeOffers.empty()) initTradingVecs();
|
||||
|
||||
for(pair<Player*, vector<TradeOffer*>> &offers : tradeOffers)
|
||||
if(offers.first == player)
|
||||
offers.second.push_back(offer);
|
||||
}
|
||||
|
||||
vector<TradeOffer*> Player::getTradeOffers(Player *player){
|
||||
for(pair<Player*, vector<TradeOffer*>> offers : tradeOffers)
|
||||
if(offers.first == player)
|
||||
return offers.second;
|
||||
|
||||
return vector<TradeOffer*>{};
|
||||
}
|
||||
|
||||
void Player::deselectUnit(Unit *unit){
|
||||
for(int i = 0; i < selectedUnits.size(); i++)
|
||||
if(selectedUnits[i] == unit){
|
||||
selectedUnits.erase(selectedUnits.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vector<GameObject*> Player::getDestructables(){
|
||||
vector<GameObject*> destructables;
|
||||
|
||||
for(Projectile *p : projectiles)
|
||||
if(p->getDestructable())
|
||||
destructables.push_back(p);
|
||||
|
||||
for(Unit *unit : units)
|
||||
destructables.push_back((GameObject*)unit);
|
||||
|
||||
return destructables;
|
||||
}
|
||||
|
||||
void Player::updateGameStats(Unit *targetUnit){
|
||||
Destructable *destructTarg = targetUnit->getDestructable();
|
||||
|
||||
if(destructTarg->getHealth() <= destructTarg->getDeathHp()){
|
||||
Player *targUnitPlayer = targetUnit->getPlayer();
|
||||
|
||||
if(targetUnit->isVehicle()){
|
||||
incVehiclesDestroyed();
|
||||
targUnitPlayer->incVehiclesLost();
|
||||
}
|
||||
else{
|
||||
incStructuresDestroyed();
|
||||
targUnitPlayer->incStructuresLost();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getFriendlyUnits(bool includeOwn){
|
||||
vector<Unit*> friendlyUnits;
|
||||
|
||||
for (Player *pl : Game::getSingleton()->getPlayers(true))
|
||||
for (Unit *u : pl->getUnits())
|
||||
if((includeOwn && pl == this) || pl->getTeam() == getTeam())
|
||||
friendlyUnits.push_back(u);
|
||||
|
||||
return friendlyUnits;
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getHostileUnits(){
|
||||
vector<Unit*> hostileUnits, friendlyUnits = getFriendlyUnits(true);
|
||||
|
||||
for (Player *pl : Game::getSingleton()->getPlayers(true))
|
||||
for (Unit *u : pl->getUnits())
|
||||
if(pl->getTeam() != getTeam() && isObjectVisible(u, friendlyUnits))
|
||||
hostileUnits.push_back(u);
|
||||
|
||||
return hostileUnits;
|
||||
}
|
||||
|
||||
//TODO improve this for greater accuracy
|
||||
bool Player::isObjectVisible(GameObject *object, std::vector<Unit*> friendlyUnits) {
|
||||
Player *objPlayer = object->getPlayer();
|
||||
|
||||
for(Unit *friendlyUnit : friendlyUnits){
|
||||
if(objPlayer == this || objPlayer->getTeam() == getTeam())
|
||||
return true;
|
||||
|
||||
Vector3 obsUnitPos = object->getPos();
|
||||
Vector2 oup2d = Vector2(obsUnitPos.x, obsUnitPos.z);
|
||||
|
||||
Vector3 compUnitPos = friendlyUnit->getPos();
|
||||
Vector2 cup2d = Vector2(compUnitPos.x, compUnitPos.z);
|
||||
|
||||
if(cup2d.getDistanceFrom(oup2d) <= friendlyUnit->getLineOfSight())
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
int Player::getCpuPlayerId(){
|
||||
vector<Player*> cpuPlayers = Game::getSingleton()->getCpuPlayers();
|
||||
|
||||
for(int i = 0; i < cpuPlayers.size(); i++)
|
||||
if(cpuPlayers[i] == this)
|
||||
return i;
|
||||
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
#include <solUtil.h>
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "player.h"
|
||||
#include "game.h"
|
||||
#include "structure.h"
|
||||
#include "projectile.h"
|
||||
#include "tradeOffer.h"
|
||||
#include "destructable.h"
|
||||
#include "activeGameState.h"
|
||||
#include "resourceDeposit.h"
|
||||
|
||||
namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
using namespace std;
|
||||
|
||||
Player::Player(int diff, int fac, int t, Vector3 col, bool cpuPl, int sp, string n) :
|
||||
difficulty(diff),
|
||||
faction(fac),
|
||||
team(t),
|
||||
color(col),
|
||||
cpuPlayer(cpuPl),
|
||||
spawnPointId(sp),
|
||||
name("pl"),
|
||||
trader(new Trader())
|
||||
{
|
||||
resources[0] = 30000;
|
||||
|
||||
colorMaterial = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
colorMaterial->addBoolUniform("lightingEnabled", false);
|
||||
colorMaterial->addBoolUniform("texturingEnabled", false);
|
||||
colorMaterial->addVec4Uniform("diffuseColor", Vector4(color.x, color.y, color.z, 1));
|
||||
}
|
||||
|
||||
Player::~Player() {
|
||||
delete colorMaterial;
|
||||
}
|
||||
|
||||
void Player::update() {
|
||||
trader->update();
|
||||
|
||||
vector<Unit*> units = this->units;
|
||||
for(Unit *u : units){
|
||||
if(!u->isRemove()) u->update();
|
||||
else removeUnit(u);
|
||||
}
|
||||
|
||||
vector<Projectile*> projectiles = this->projectiles;
|
||||
for(Projectile *proj : projectiles){
|
||||
if(!proj->isRemove()) proj->update();
|
||||
else removeProjectile(proj);
|
||||
}
|
||||
|
||||
for(ResourceDeposit *rd : resourceDeposits) rd->update();
|
||||
|
||||
for(pair<Player*, vector<TradeOffer*>> &pair : tradeOffers){
|
||||
if(pair.second.empty()) continue;
|
||||
|
||||
bool fulfiled = true;
|
||||
|
||||
for(int i = 0; i < NUM_RESOURCES && fulfiled; i++){
|
||||
bool b = (pair.second[0]->tradeResources[i][0] == pair.second[0]->deliveredResources[i][0]);
|
||||
bool s = (pair.second[0]->tradeResources[i][1] == pair.second[0]->deliveredResources[i][1]);
|
||||
|
||||
if(!(b && s)) fulfiled = false;
|
||||
}
|
||||
|
||||
if(fulfiled)
|
||||
pair.second.erase(pair.second.begin());
|
||||
}
|
||||
}
|
||||
|
||||
int Player::getOrderLineId(Order::TYPE type, Vector3 startPos, Vector3 endPos){
|
||||
Vector3 color;
|
||||
|
||||
switch(type){
|
||||
case Order::TYPE::MOVE:
|
||||
color = Vector3::VEC_J;
|
||||
break;
|
||||
case Order::TYPE::ATTACK:
|
||||
color = Vector3::VEC_I;
|
||||
break;
|
||||
case Order::TYPE::PATROL:
|
||||
case Order::TYPE::GARRISON:
|
||||
case Order::TYPE::EJECT:
|
||||
color = Vector3::VEC_K;
|
||||
break;
|
||||
case Order::TYPE::BUILD:
|
||||
case Order::TYPE::SUPPLY:
|
||||
case Order::TYPE::LOAD:
|
||||
case Order::TYPE::UNLOAD:
|
||||
color = Vector3(1, 1, 0);
|
||||
break;
|
||||
case Order::TYPE::HACK:
|
||||
color = Vector3(1, 0, 1);
|
||||
break;
|
||||
}
|
||||
|
||||
LineRenderer *lineRenderer = LineRenderer::getSingleton();
|
||||
lineRenderer->addLine(startPos, endPos, color);
|
||||
vector<LineRenderer::Line> lines = lineRenderer->getLines();
|
||||
|
||||
return lines[lines.size() - 1].id;
|
||||
}
|
||||
|
||||
void Player::issueOrder(Order::TYPE type, Vector3 destDir, vector<Order::Target> targets, bool append){
|
||||
vector<Unit*> selectedUnits = getSelectedUnits();
|
||||
|
||||
for (Unit *u : selectedUnits) {
|
||||
bool targetingSelf = false, structBuilt = true;
|
||||
|
||||
for(Order::Target &targ : targets){
|
||||
if(targ.unit && targ.unit == u){
|
||||
targetingSelf = true;
|
||||
break;
|
||||
}
|
||||
|
||||
if(!u->isVehicle() && ((Structure*)u)->getBuildStatus() < 100){
|
||||
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);
|
||||
}
|
||||
|
||||
void Player::removeResourceDeposit(int id){
|
||||
delete resourceDeposits[id];
|
||||
resourceDeposits.erase(resourceDeposits.begin() + id);
|
||||
}
|
||||
|
||||
void Player::removeProjectile(Projectile *proj){
|
||||
for(int i = 0; i < projectiles.size(); i++)
|
||||
if(proj == projectiles[i]){
|
||||
removeProjectile(i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::removeProjectile(int id){
|
||||
delete projectiles[id];
|
||||
projectiles.erase(projectiles.begin() + id);
|
||||
}
|
||||
|
||||
void Player::selectUnits(vector<Unit*> selUnits){
|
||||
for(Unit *u : selUnits)
|
||||
if(find(selectedUnits.begin(), selectedUnits.end(), u) == selectedUnits.end()){
|
||||
selectedUnits.push_back(u);
|
||||
u->select();
|
||||
}
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getUnitsById(int id, int numUnits){
|
||||
vector<Unit*> idUnits;
|
||||
|
||||
for(Unit *unit : units){
|
||||
if(numUnits != -1 && idUnits.size() == numUnits)
|
||||
break;
|
||||
|
||||
if(unit->getId() == id)
|
||||
idUnits.push_back(unit);
|
||||
}
|
||||
|
||||
return idUnits;
|
||||
}
|
||||
|
||||
vector<Unit*> Player::getUnitsByClass(UnitClass uc, int numUnits){
|
||||
vector<Unit*> ucUnits;
|
||||
|
||||
for(Unit *unit : units){
|
||||
if(numUnits != -1 && ucUnits.size() == numUnits)
|
||||
break;
|
||||
|
||||
if(unit->getUnitClass() == uc)
|
||||
ucUnits.push_back(unit);
|
||||
}
|
||||
|
||||
return ucUnits;
|
||||
}
|
||||
|
||||
void Player::updateTradedResource(Player *player, ResourceType type, int amount, bool selfDistributed, bool increased){
|
||||
for(pair<Player*, vector<TradedResource>> pair : tradedResources)
|
||||
if(pair.first == player){
|
||||
TradedResource &tr = pair.second[(int)type];
|
||||
|
||||
if(selfDistributed) (increased ? tr.taken : tr.given) += amount;
|
||||
else (increased ? tr.received : tr.hadTaken) += amount;
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
void Player::initTradingVecs(){
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers();
|
||||
|
||||
for(Player *pl : players){
|
||||
if(this == pl) continue;
|
||||
|
||||
if(team == pl->getTeam()){
|
||||
tradeOffers.push_back(make_pair(pl, vector<TradeOffer*>{}));
|
||||
tradedResources.push_back(make_pair(pl, vector<TradedResource>{
|
||||
TradedResource(ResourceType::REFINEDS),
|
||||
TradedResource(ResourceType::WEALTH),
|
||||
TradedResource(ResourceType::RESEARCH)
|
||||
}));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Player::addTradeOffer(Player *player, TradeOffer *offer){
|
||||
if(tradeOffers.empty()) initTradingVecs();
|
||||
|
||||
for(pair<Player*, vector<TradeOffer*>> &offers : tradeOffers)
|
||||
if(offers.first == player)
|
||||
offers.second.push_back(offer);
|
||||
}
|
||||
|
||||
vector<TradeOffer*> Player::getTradeOffers(Player *player){
|
||||
for(pair<Player*, vector<TradeOffer*>> offers : tradeOffers)
|
||||
if(offers.first == player)
|
||||
return offers.second;
|
||||
|
||||
return vector<TradeOffer*>{};
|
||||
}
|
||||
|
||||
void Player::deselectUnit(Unit *unit){
|
||||
for(int i = 0; i < selectedUnits.size(); i++)
|
||||
if(selectedUnits[i] == unit){
|
||||
selectedUnits.erase(selectedUnits.begin() + i);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
vector<GameObject*> Player::getDestructables(){
|
||||
vector<GameObject*> destructables;
|
||||
|
||||
for(Projectile *p : projectiles)
|
||||
if(p->getDestructable())
|
||||
destructables.push_back(p);
|
||||
|
||||
for(Unit *unit : units)
|
||||
destructables.push_back((GameObject*)unit);
|
||||
|
||||
return destructables;
|
||||
}
|
||||
|
||||
void Player::updateGameStats(Unit *targetUnit){
|
||||
Destructable *destructTarg = targetUnit->getDestructable();
|
||||
|
||||
if(destructTarg->getHealth() <= destructTarg->getDeathHp()){
|
||||
Player *targUnitPlayer = targetUnit->getPlayer();
|
||||
|
||||
if(targetUnit->isVehicle()){
|
||||
incVehiclesDestroyed();
|
||||
targUnitPlayer->incVehiclesLost();
|
||||
}
|
||||
else{
|
||||
incStructuresDestroyed();
|
||||
targUnitPlayer->incStructuresLost();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Executable → Regular
+113
-118
@@ -1,118 +1,113 @@
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "gameManager.h"
|
||||
#include "trader.h"
|
||||
#include "unit.h"
|
||||
|
||||
namespace battleship{
|
||||
class ResourceDeposit;
|
||||
class Projectile;
|
||||
class Unit;
|
||||
struct TradeOffer;
|
||||
|
||||
const int NUM_RESOURCES = 3;
|
||||
enum class ResourceType{REFINEDS, WEALTH, RESEARCH};
|
||||
|
||||
class Player {
|
||||
public:
|
||||
Player(int, int, int, vb01::Vector3, bool = true, int = -1, std::string = "");
|
||||
~Player();
|
||||
void update();
|
||||
void haltUnits();
|
||||
void issueOrder(Order::TYPE, vb01::Vector3, std::vector<Order::Target>, bool);
|
||||
void removeUnit(Unit*);
|
||||
void removeUnit(int);
|
||||
void removeResourceDeposit(int);
|
||||
void removeProjectile(int);
|
||||
void removeProjectile(Projectile*);
|
||||
bool isThisPlayersUnit(GameObject*);
|
||||
void selectUnits(std::vector<Unit*>);
|
||||
std::vector<Unit*> getUnitsById(int, int = -1);
|
||||
std::vector<Unit*> getUnitsByClass(UnitClass, int = -1);
|
||||
void addTechnology(int id){technologies.push_back(id);}
|
||||
void updateTradedResource(Player*, ResourceType, int, bool, bool);
|
||||
void addTradeOffer(Player*, TradeOffer*);
|
||||
std::vector<TradeOffer*> getTradeOffers(Player*);
|
||||
void deselectUnit(Unit*);
|
||||
std::vector<GameObject*> getDestructables();
|
||||
void updateGameStats(Unit*);
|
||||
std::vector<Unit*> getFriendlyUnits(bool = true);
|
||||
std::vector<Unit*> getHostileUnits();
|
||||
bool isObjectVisible(GameObject*, std::vector<Unit*>);
|
||||
int getCpuPlayerId();
|
||||
inline int getResource(ResourceType rt){return resources[(int)rt];}
|
||||
inline void updateResource(ResourceType rt, int amount, bool add){resources[(int)rt] = (add ? resources[(int)rt] + amount : amount);}
|
||||
inline Trader* getTrader(){return trader;}
|
||||
inline void deselectUnits(){selectedUnits.clear();}
|
||||
inline Unit* getSelectedUnit(int id){return selectedUnits[id];}
|
||||
inline std::vector<Unit*> getSelectedUnits(){return selectedUnits;}
|
||||
inline void deselectUnit(int i){selectedUnits.erase(selectedUnits.begin() + i);}
|
||||
inline int getNumSelectedUnits(){return getSelectedUnits().size();}
|
||||
inline void selectUnit(Unit *u){selectUnits(std::vector<Unit*>{u});}
|
||||
inline void addUnit(Unit *u){units.push_back(u);}
|
||||
inline std::vector<ResourceDeposit*>& getResourceDeposits(){return resourceDeposits;}
|
||||
inline void addResourceDeposit(ResourceDeposit *rd){resourceDeposits.push_back(rd);}
|
||||
inline int getNumResourceDeposits(){return resourceDeposits.size();}
|
||||
inline void addProjectile(Projectile *proj){projectiles.push_back(proj);}
|
||||
inline int getNumProjectiles(){return projectiles.size();}
|
||||
inline std::vector<Projectile*>& getProjectiles(){return projectiles;}
|
||||
inline Unit* getUnit(int i){return units[i];}
|
||||
inline std::vector<Unit*>& getUnits(){return units;}
|
||||
inline void setTeam(int t){team = t;}
|
||||
inline int getTeam(){return team;}
|
||||
inline int getNumUnits(){return units.size();}
|
||||
inline int getFaction(){return faction;}
|
||||
inline int getSpawnPointId(){return spawnPointId;}
|
||||
inline bool isCpuPlayer(){return cpuPlayer;}
|
||||
inline int getNumVehiclesBuilt(){return vehiclesBuilt;}
|
||||
inline int getNumVehiclesDestroyed(){return vehiclesDestroyed;}
|
||||
inline int getNumVehiclesLost(){return vehiclesLost;}
|
||||
inline int getNumStructuresBuilt(){return structuresBuilt;}
|
||||
inline int getNumStructuresDestroyed(){return structuresDestroyed;}
|
||||
inline int getNumStructuresLost(){return structuresLost;}
|
||||
inline void incVehiclesBuilt(){vehiclesBuilt++;}
|
||||
inline void incVehiclesDestroyed(){vehiclesDestroyed++;}
|
||||
inline void incVehiclesLost(){vehiclesLost++;}
|
||||
inline void incStructuresBuilt(){structuresBuilt++;}
|
||||
inline void incStructuresDestroyed(){structuresDestroyed++;}
|
||||
inline void incStructuresLost(){structuresLost++;}
|
||||
inline vb01::Vector3 getColor(){return color;}
|
||||
inline std::string getName(){return name;}
|
||||
inline vb01::Material* getColorMaterial(){return colorMaterial;}
|
||||
inline std::vector<int> getTechnologies(){return technologies;}
|
||||
private:
|
||||
struct TradedResource{
|
||||
ResourceType type;
|
||||
int taken = 0, given = 0, received = 0, hadTaken = 0;
|
||||
|
||||
TradedResource(ResourceType t) : type(t){}
|
||||
};
|
||||
|
||||
bool cpuPlayer = false;
|
||||
std::vector<int> technologies;
|
||||
int luaPlayerId;
|
||||
int resources[3]{0, 0, 0};
|
||||
int faction, difficulty, team;
|
||||
int vehiclesBuilt = 0, vehiclesDestroyed = 0, vehiclesLost = 0;
|
||||
int structuresBuilt = 0, structuresDestroyed = 0, structuresLost = 0;
|
||||
int spawnPointId = -1;
|
||||
Trader *trader = nullptr;
|
||||
std::string name;
|
||||
std::vector<Unit*> units, selectedUnits;
|
||||
std::vector<Projectile*> projectiles;
|
||||
std::vector<ResourceDeposit*> resourceDeposits;
|
||||
vb01::Vector3 color;
|
||||
vb01::Material *colorMaterial = nullptr;
|
||||
std::vector<std::pair<Player*, std::vector<TradeOffer*>>> tradeOffers;
|
||||
std::vector<std::pair<Player*, std::vector<TradedResource>>> tradedResources;
|
||||
|
||||
int getOrderLineId(Order::TYPE, vb01::Vector3, vb01::Vector3);
|
||||
void initTradingVecs();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef PLAYER_H
|
||||
#define PLAYER_H
|
||||
|
||||
#include <vector>
|
||||
#include <algorithm>
|
||||
|
||||
#include "gameManager.h"
|
||||
#include "trader.h"
|
||||
#include "unit.h"
|
||||
|
||||
namespace battleship{
|
||||
class ResourceDeposit;
|
||||
class Projectile;
|
||||
class Unit;
|
||||
struct TradeOffer;
|
||||
|
||||
const int NUM_RESOURCES = 3;
|
||||
enum class ResourceType{REFINEDS, WEALTH, RESEARCH};
|
||||
|
||||
class Player {
|
||||
public:
|
||||
Player(int, int, int, vb01::Vector3, bool = true, int = -1, std::string = "");
|
||||
~Player();
|
||||
void update();
|
||||
void issueOrder(Order::TYPE, vb01::Vector3, std::vector<Order::Target>, bool);
|
||||
void removeUnit(Unit*);
|
||||
void removeUnit(int);
|
||||
void removeResourceDeposit(int);
|
||||
void removeProjectile(int);
|
||||
void removeProjectile(Projectile*);
|
||||
bool isThisPlayersUnit(GameObject*);
|
||||
void selectUnits(std::vector<Unit*>);
|
||||
std::vector<Unit*> getUnitsById(int, int = -1);
|
||||
std::vector<Unit*> getUnitsByClass(UnitClass, int = -1);
|
||||
void addTechnology(int id){technologies.push_back(id);}
|
||||
void updateTradedResource(Player*, ResourceType, int, bool, bool);
|
||||
void addTradeOffer(Player*, TradeOffer*);
|
||||
std::vector<TradeOffer*> getTradeOffers(Player*);
|
||||
void deselectUnit(Unit*);
|
||||
std::vector<GameObject*> getDestructables();
|
||||
void updateGameStats(Unit*);
|
||||
inline int getResource(ResourceType rt){return resources[(int)rt];}
|
||||
inline void updateResource(ResourceType rt, int amount, bool add){resources[(int)rt] = (add ? resources[(int)rt] + amount : amount);}
|
||||
inline Trader* getTrader(){return trader;}
|
||||
inline void deselectUnits(){selectedUnits.clear();}
|
||||
inline Unit* getSelectedUnit(int id){return selectedUnits[id];}
|
||||
inline std::vector<Unit*> getSelectedUnits(){return selectedUnits;}
|
||||
inline void deselectUnit(int i){selectedUnits.erase(selectedUnits.begin() + i);}
|
||||
inline int getNumSelectedUnits(){return getSelectedUnits().size();}
|
||||
inline void selectUnit(Unit *u){selectUnits(std::vector<Unit*>{u});}
|
||||
inline void addUnit(Unit *u){units.push_back(u);}
|
||||
inline std::vector<ResourceDeposit*>& getResourceDeposits(){return resourceDeposits;}
|
||||
inline void addResourceDeposit(ResourceDeposit *rd){resourceDeposits.push_back(rd);}
|
||||
inline int getNumResourceDeposits(){return resourceDeposits.size();}
|
||||
inline void addProjectile(Projectile *proj){projectiles.push_back(proj);}
|
||||
inline int getNumProjectiles(){return projectiles.size();}
|
||||
inline std::vector<Projectile*>& getProjectiles(){return projectiles;}
|
||||
inline Unit* getUnit(int i){return units[i];}
|
||||
inline std::vector<Unit*>& getUnits(){return units;}
|
||||
inline void setTeam(int t){team = t;}
|
||||
inline int getTeam(){return team;}
|
||||
inline int getNumUnits(){return units.size();}
|
||||
inline int getFaction(){return faction;}
|
||||
inline int getSpawnPointId(){return spawnPointId;}
|
||||
inline bool isCpuPlayer(){return cpuPlayer;}
|
||||
inline int getNumVehiclesBuilt(){return vehiclesBuilt;}
|
||||
inline int getNumVehiclesDestroyed(){return vehiclesDestroyed;}
|
||||
inline int getNumVehiclesLost(){return vehiclesLost;}
|
||||
inline int getNumStructuresBuilt(){return structuresBuilt;}
|
||||
inline int getNumStructuresDestroyed(){return structuresDestroyed;}
|
||||
inline int getNumStructuresLost(){return structuresLost;}
|
||||
inline void incVehiclesBuilt(){vehiclesBuilt++;}
|
||||
inline void incVehiclesDestroyed(){vehiclesDestroyed++;}
|
||||
inline void incVehiclesLost(){vehiclesLost++;}
|
||||
inline void incStructuresBuilt(){structuresBuilt++;}
|
||||
inline void incStructuresDestroyed(){structuresDestroyed++;}
|
||||
inline void incStructuresLost(){structuresLost++;}
|
||||
inline vb01::Vector3 getColor(){return color;}
|
||||
inline std::string getName(){return name;}
|
||||
inline vb01::Material* getColorMaterial(){return colorMaterial;}
|
||||
inline std::vector<int> getTechnologies(){return technologies;}
|
||||
private:
|
||||
struct TradedResource{
|
||||
ResourceType type;
|
||||
int taken = 0, given = 0, received = 0, hadTaken = 0;
|
||||
|
||||
TradedResource(ResourceType t) : type(t){}
|
||||
};
|
||||
|
||||
bool cpuPlayer = false;
|
||||
std::vector<int> technologies;
|
||||
int luaPlayerId;
|
||||
int resources[3]{0, 0, 0};
|
||||
int faction, difficulty, team;
|
||||
int vehiclesBuilt = 0, vehiclesDestroyed = 0, vehiclesLost = 0;
|
||||
int structuresBuilt = 0, structuresDestroyed = 0, structuresLost = 0;
|
||||
int spawnPointId = -1;
|
||||
Trader *trader = nullptr;
|
||||
std::string name;
|
||||
std::vector<Unit*> units, selectedUnits;
|
||||
std::vector<Projectile*> projectiles;
|
||||
std::vector<ResourceDeposit*> resourceDeposits;
|
||||
vb01::Vector3 color;
|
||||
vb01::Material *colorMaterial = nullptr;
|
||||
std::vector<std::pair<Player*, std::vector<TradeOffer*>>> tradeOffers;
|
||||
std::vector<std::pair<Player*, std::vector<TradedResource>>> tradedResources;
|
||||
|
||||
int getOrderLineId(Order::TYPE, vb01::Vector3, vb01::Vector3);
|
||||
void initTradingVecs();
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -5,16 +5,19 @@
|
||||
|
||||
#include <solUtil.h>
|
||||
|
||||
namespace battleship{
|
||||
namespace battleship
|
||||
{
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
using namespace gameBase;
|
||||
|
||||
Trader::Trader(){
|
||||
Trader::Trader()
|
||||
{
|
||||
initProperties();
|
||||
}
|
||||
|
||||
void Trader::initProperties(){
|
||||
void Trader::initProperties()
|
||||
{
|
||||
sol::table traderTable = generateView()["trading"];
|
||||
fluctuationRate = traderTable["fluctuationRate"];
|
||||
fluctuationAmmount = traderTable["fluctuationAmmount"];
|
||||
@@ -22,21 +25,24 @@ namespace battleship{
|
||||
researchRate = traderTable["researchRate"];
|
||||
}
|
||||
|
||||
void Trader::update(){
|
||||
if(getTime() - lastUpdateTime > fluctuationRate){
|
||||
void Trader::update()
|
||||
{
|
||||
if (getTime() - lastUpdateTime > fluctuationRate)
|
||||
{
|
||||
int flucFact = rand() % 3;
|
||||
int flSpd;
|
||||
|
||||
switch(flucFact){
|
||||
case 0:
|
||||
flSpd = -fluctuationAmmount;
|
||||
break;
|
||||
case 1:
|
||||
flSpd = 0;
|
||||
break;
|
||||
case 2:
|
||||
flSpd = fluctuationAmmount;
|
||||
break;
|
||||
switch (flucFact)
|
||||
{
|
||||
case 0:
|
||||
flSpd = -fluctuationAmmount;
|
||||
break;
|
||||
case 1:
|
||||
flSpd = 0;
|
||||
break;
|
||||
case 2:
|
||||
flSpd = fluctuationAmmount;
|
||||
break;
|
||||
}
|
||||
|
||||
refinedsRate += fluctuationAmmount;
|
||||
@@ -45,23 +51,27 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
void Trader::trade(Player *tradingPlayer, int rt, int ammount, bool buying){
|
||||
void Trader::trade(Player *tradingPlayer, int rt, int ammount, bool buying)
|
||||
{
|
||||
int tradeResRate;
|
||||
|
||||
switch((ResourceType)rt){
|
||||
case ResourceType::REFINEDS:
|
||||
tradeResRate = refinedsRate;
|
||||
break;
|
||||
case ResourceType::RESEARCH:
|
||||
tradeResRate = researchRate;
|
||||
break;
|
||||
switch ((ResourceType)rt)
|
||||
{
|
||||
case ResourceType::REFINEDS:
|
||||
tradeResRate = refinedsRate;
|
||||
break;
|
||||
case ResourceType::RESEARCH:
|
||||
tradeResRate = researchRate;
|
||||
break;
|
||||
}
|
||||
|
||||
if(buying && ammount * tradeResRate <= tradingPlayer->getResource(ResourceType::WEALTH)){
|
||||
if (buying && ammount * tradeResRate <= tradingPlayer->getResource(ResourceType::WEALTH))
|
||||
{
|
||||
tradingPlayer->updateResource((ResourceType)rt, ammount, true);
|
||||
tradingPlayer->updateResource(ResourceType::WEALTH, -ammount * tradeResRate, true);
|
||||
}
|
||||
else if(!buying && tradingPlayer->getResource((ResourceType)rt) >= ammount){
|
||||
else if (!buying && tradingPlayer->getResource((ResourceType)rt) >= ammount)
|
||||
{
|
||||
tradingPlayer->updateResource((ResourceType)rt, -ammount, true);
|
||||
tradingPlayer->updateResource(ResourceType::WEALTH, ammount * tradeResRate, true);
|
||||
}
|
||||
Executable → Regular
+161
-145
@@ -1,145 +1,161 @@
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <camera.h>
|
||||
#include <quad.h>
|
||||
#include <root.h>
|
||||
#include <vector.h>
|
||||
#include <util.h>
|
||||
#include <assetManager.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <solUtil.h>
|
||||
|
||||
#include <glm.hpp>
|
||||
#include <ext.hpp>
|
||||
|
||||
#include <tinydir.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "defConfigs.h"
|
||||
#include "gameManager.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "guiAppState.h"
|
||||
#include "inGameAppState.h"
|
||||
#include "loadingAppState.h"
|
||||
#include "mapEditorButton.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::this_thread;
|
||||
using namespace std::chrono;
|
||||
using namespace glm;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
|
||||
namespace battleship{
|
||||
using namespace configData;
|
||||
|
||||
void handleLoadingGui(LoadingAppState *loadState){
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
guiManager->readLuaScreenScript("loadingScreen.lua");
|
||||
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
string vfxPrefix = SOL_LUA_VIEW["vfxPrefix"], gameObjPrefix = SOL_LUA_VIEW["gameObjPrefix"];
|
||||
|
||||
AssetManager *assetManager = AssetManager::getSingleton();
|
||||
string path = GameManager::getSingleton()->getPath();
|
||||
vector<string> assets = vector<string>{path + DEFAULT_TEXTURE};
|
||||
|
||||
assetManager->readDir(path + vfxPrefix, assets, true);
|
||||
assetManager->readDir(path + gameObjPrefix, assets, true);
|
||||
|
||||
loadState->setLoadableAssets(assets);
|
||||
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
stateManager->attachAppState(loadState);
|
||||
}
|
||||
|
||||
Vector3 getVecToPlane(Vector3 pos, Vector3 dirVec, Vector3 upVec){
|
||||
float baseAngle = upVec.getAngleBetween(dirVec.norm());
|
||||
|
||||
if(fabs(baseAngle - PI / 2) > .001){
|
||||
bool acuteAngle = (baseAngle < PI / 2);
|
||||
|
||||
if(acuteAngle) baseAngle = PI / 2 - baseAngle;
|
||||
else baseAngle -= PI / 2;
|
||||
|
||||
float pointToPlane = dirVec.getLength() * sin(baseAngle);
|
||||
return (dirVec + upVec * pointToPlane * (acuteAngle ? -1 : 1)).norm();
|
||||
}
|
||||
else return dirVec.norm();
|
||||
}
|
||||
|
||||
vector<string> readDir(string path, bool findFolders){
|
||||
tinydir_dir dir;
|
||||
tinydir_open_sorted(&dir, path.c_str());
|
||||
vector<string> files;
|
||||
|
||||
for (int i = 0; i < dir.n_files; i++) {
|
||||
tinydir_file file;
|
||||
tinydir_readfile_n(&dir, &file, i);
|
||||
|
||||
if (file.is_dir == findFolders && file.name[0] != '.')
|
||||
files.push_back(file.name);
|
||||
}
|
||||
|
||||
tinydir_close(&dir);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
Vector3 spaceToScreen3d(Vector3 pos){
|
||||
Root *root = Root::getSingleton();
|
||||
Camera *cam = root->getCamera();
|
||||
Vector3 dir = cam->getDirection(), up = cam->getUp();
|
||||
Vector3 camPos = cam->getPosition();
|
||||
mat4 view = lookAt(vec3(camPos.x, camPos.y, camPos.z), vec3(camPos.x + dir.x, camPos.y + dir.y, camPos.z + dir.z), vec3(up.x, up.y, up.z));
|
||||
|
||||
float fov = cam->getFov(), width = root->getWidth(), height = root->getHeight(), nearPlane = cam->getNearPlane(), farPlane = cam->getFarPlane();
|
||||
mat4 proj = perspective(radians(fov), width / height, nearPlane, farPlane);
|
||||
|
||||
vec4 ndcPos = proj * view * vec4(pos.x, pos.y, pos.z, 1);
|
||||
ndcPos.x /= ndcPos.w;
|
||||
ndcPos.y /= ndcPos.w;
|
||||
ndcPos.z /= ndcPos.w;
|
||||
return Vector3(0.5 * width * (1 + ndcPos.x), 0.5 * height * (1 - ndcPos.y), ndcPos.z);
|
||||
}
|
||||
|
||||
Vector2 spaceToScreen(Vector3 pos){
|
||||
Vector3 pos3d = spaceToScreen3d(pos);
|
||||
return Vector2(pos3d.x, pos3d.y);
|
||||
}
|
||||
|
||||
Vector3 screenToSpace(Vector2 pos){
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
float midWidth = .5 * gm->getWidth(), midHeight = .5 * gm->getHeight(), horOffset, vertOffset;
|
||||
bool left, up;
|
||||
|
||||
if(pos.x < midWidth){
|
||||
left = true;
|
||||
horOffset = pos.x / midWidth - 1;
|
||||
}
|
||||
else{
|
||||
left = false;
|
||||
horOffset = (pos.x - midWidth) / midWidth;
|
||||
}
|
||||
|
||||
if(pos.y < midHeight){
|
||||
up = true;
|
||||
vertOffset = 1 - pos.y / midHeight;
|
||||
}
|
||||
else{
|
||||
up = false;
|
||||
vertOffset = -(pos.y - midHeight) / midHeight;
|
||||
}
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
float camNorm = cam->getNearPlane();
|
||||
float tg = tan(radians(cam->getFov()) / 2), ar = midWidth / midHeight;
|
||||
float camHeight = camNorm * tg, camWidth = camHeight * ar;
|
||||
Vector3 posOffset = (cam->getLeft() * camWidth * horOffset + cam->getUp() * camHeight * vertOffset + cam->getDirection() * camNorm);
|
||||
|
||||
return cam->getPosition() + posOffset;
|
||||
}
|
||||
}
|
||||
#include <cmath>
|
||||
#include <chrono>
|
||||
#include <thread>
|
||||
|
||||
#include <camera.h>
|
||||
#include <quad.h>
|
||||
#include <root.h>
|
||||
#include <vector>
|
||||
#include <util.h>
|
||||
#include <assetManager.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
#include <solUtil.h>
|
||||
|
||||
#include <glm.hpp>
|
||||
#include <ext.hpp>
|
||||
|
||||
#include <tinydir.h>
|
||||
|
||||
#include "util.h"
|
||||
#include "defConfigs.h"
|
||||
#include "gameManager.h"
|
||||
#include "concreteGuiManager.h"
|
||||
#include "guiAppState.h"
|
||||
#include "inGameAppState.h"
|
||||
#include "loadingAppState.h"
|
||||
#include "mapEditorButton.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace std::this_thread;
|
||||
using namespace std::chrono;
|
||||
using namespace glm;
|
||||
using namespace vb01;
|
||||
using namespace vb01Gui;
|
||||
|
||||
namespace battleship
|
||||
{
|
||||
using namespace configData;
|
||||
|
||||
void handleLoadingGui(LoadingAppState *loadState)
|
||||
{
|
||||
ConcreteGuiManager *guiManager = ConcreteGuiManager::getSingleton();
|
||||
guiManager->readLuaScreenScript("loadingScreen.lua");
|
||||
|
||||
sol::state_view SOL_LUA_VIEW = generateView();
|
||||
string vfxPrefix = SOL_LUA_VIEW["vfxPrefix"], gameObjPrefix = SOL_LUA_VIEW["gameObjPrefix"];
|
||||
|
||||
AssetManager *assetManager = AssetManager::getSingleton();
|
||||
string path = GameManager::getSingleton()->getPath();
|
||||
vector<string> assets = vector<string>{path + DEFAULT_TEXTURE};
|
||||
|
||||
assetManager->readDir(path + vfxPrefix, assets, true);
|
||||
assetManager->readDir(path + gameObjPrefix, assets, true);
|
||||
|
||||
loadState->setLoadableAssets(assets);
|
||||
|
||||
StateManager *stateManager = GameManager::getSingleton()->getStateManager();
|
||||
stateManager->attachAppState(loadState);
|
||||
}
|
||||
|
||||
Vector3 getVecToPlane(Vector3 pos, Vector3 dirVec, Vector3 upVec)
|
||||
{
|
||||
float baseAngle = upVec.getAngleBetween(dirVec.norm());
|
||||
|
||||
if (fabs(baseAngle - PI / 2) > .001)
|
||||
{
|
||||
bool acuteAngle = (baseAngle < PI / 2);
|
||||
|
||||
if (acuteAngle)
|
||||
baseAngle = PI / 2 - baseAngle;
|
||||
else
|
||||
baseAngle -= PI / 2;
|
||||
|
||||
float pointToPlane = dirVec.getLength() * sin(baseAngle);
|
||||
return (dirVec + upVec * pointToPlane * (acuteAngle ? -1 : 1)).norm();
|
||||
}
|
||||
else
|
||||
return dirVec.norm();
|
||||
}
|
||||
|
||||
vector<string> readDir(string path, bool findFolders)
|
||||
{
|
||||
tinydir_dir dir;
|
||||
tinydir_open_sorted(&dir, path.c_str());
|
||||
vector<string> files;
|
||||
|
||||
for (int i = 0; i < dir.n_files; i++)
|
||||
{
|
||||
tinydir_file file;
|
||||
tinydir_readfile_n(&dir, &file, i);
|
||||
|
||||
if (file.is_dir == findFolders && file.name[0] != '.')
|
||||
files.push_back(file.name);
|
||||
}
|
||||
|
||||
tinydir_close(&dir);
|
||||
|
||||
return files;
|
||||
}
|
||||
|
||||
Vector3 spaceToScreen3d(Vector3 pos)
|
||||
{
|
||||
Root *root = Root::getSingleton();
|
||||
Camera *cam = root->getCamera();
|
||||
Vector3 dir = cam->getDirection(), up = cam->getUp();
|
||||
Vector3 camPos = cam->getPosition();
|
||||
mat4 view = lookAt(vec3(camPos.x, camPos.y, camPos.z), vec3(camPos.x + dir.x, camPos.y + dir.y, camPos.z + dir.z), vec3(up.x, up.y, up.z));
|
||||
|
||||
float fov = cam->getFov(), width = root->getWidth(), height = root->getHeight(), nearPlane = cam->getNearPlane(), farPlane = cam->getFarPlane();
|
||||
mat4 proj = perspective(radians(fov), width / height, nearPlane, farPlane);
|
||||
|
||||
vec4 ndcPos = proj * view * vec4(pos.x, pos.y, pos.z, 1);
|
||||
ndcPos.x /= ndcPos.w;
|
||||
ndcPos.y /= ndcPos.w;
|
||||
ndcPos.z /= ndcPos.w;
|
||||
return Vector3(0.5 * width * (1 + ndcPos.x), 0.5 * height * (1 - ndcPos.y), ndcPos.z);
|
||||
}
|
||||
|
||||
Vector2 spaceToScreen(Vector3 pos)
|
||||
{
|
||||
Vector3 pos3d = spaceToScreen3d(pos);
|
||||
return Vector2(pos3d.x, pos3d.y);
|
||||
}
|
||||
|
||||
Vector3 screenToSpace(Vector2 pos)
|
||||
{
|
||||
GameManager *gm = GameManager::getSingleton();
|
||||
float midWidth = .5 * gm->getWidth(), midHeight = .5 * gm->getHeight(), horOffset, vertOffset;
|
||||
bool left, up;
|
||||
|
||||
if (pos.x < midWidth)
|
||||
{
|
||||
left = true;
|
||||
horOffset = pos.x / midWidth - 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
left = false;
|
||||
horOffset = (pos.x - midWidth) / midWidth;
|
||||
}
|
||||
|
||||
if (pos.y < midHeight)
|
||||
{
|
||||
up = true;
|
||||
vertOffset = 1 - pos.y / midHeight;
|
||||
}
|
||||
else
|
||||
{
|
||||
up = false;
|
||||
vertOffset = -(pos.y - midHeight) / midHeight;
|
||||
}
|
||||
|
||||
Camera *cam = Root::getSingleton()->getCamera();
|
||||
float camNorm = cam->getNearPlane();
|
||||
float tg = tan(radians(cam->getFov()) / 2), ar = midWidth / midHeight;
|
||||
float camHeight = camNorm * tg, camWidth = camHeight * ar;
|
||||
Vector3 posOffset = (cam->getLeft() * camWidth * horOffset + cam->getUp() * camHeight * vertOffset + cam->getDirection() * camNorm);
|
||||
|
||||
return cam->getPosition() + posOffset;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,44 @@
|
||||
#pragma once
|
||||
#ifndef UTIL_BATTLESHIP_H
|
||||
#define UTIL_BATTLESHIP_H
|
||||
|
||||
#include <iostream>
|
||||
#include <fstream>
|
||||
#include <vector>
|
||||
#include <string>
|
||||
#include <chrono>
|
||||
|
||||
#include <vector>
|
||||
|
||||
namespace battleship
|
||||
{
|
||||
typedef unsigned char u8;
|
||||
typedef unsigned short u16;
|
||||
typedef unsigned int u32;
|
||||
typedef unsigned long long u64;
|
||||
typedef char s8;
|
||||
typedef short s16;
|
||||
typedef int s32;
|
||||
typedef long long s64;
|
||||
|
||||
enum AppStateType
|
||||
{
|
||||
GUI_STATE,
|
||||
IN_GAME_STATE,
|
||||
ACTIVE_STATE,
|
||||
MAP_EDITOR,
|
||||
LOADING_STATE
|
||||
};
|
||||
|
||||
class GuiAppState;
|
||||
class LoadingAppState;
|
||||
|
||||
void handleLoadingGui(LoadingAppState *);
|
||||
vb01::Vector3 getVecToPlane(vb01::Vector3, vb01::Vector3, vb01::Vector3);
|
||||
std::vector<std::string> readDir(std::string, bool);
|
||||
vb01::Vector2 spaceToScreen(vb01::Vector3);
|
||||
vb01::Vector3 spaceToScreen3d(vb01::Vector3);
|
||||
vb01::Vector3 screenToSpace(vb01::Vector2);
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -15,7 +15,7 @@ namespace battleship{
|
||||
using namespace std;
|
||||
using namespace gameBase;
|
||||
|
||||
Factory::Factory(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, Unit::State state) : Structure(player, id, pos, rot, buildStatus, state), rallyPoint(pos + 30 * dirVec){}
|
||||
Factory::Factory(Player *player, int id, Vector3 pos, Quaternion rot, int buildStatus, Unit::State state) : Structure(player, id, pos, rot, buildStatus, state){}
|
||||
|
||||
void Factory::update(){
|
||||
Structure::update();
|
||||
@@ -70,7 +70,7 @@ namespace battleship{
|
||||
if(trainingStatus >= 100){
|
||||
Unit *unit = GameObjectFactory::createUnit(player, unitQueue[0], pos, rot);
|
||||
player->addUnit(unit);
|
||||
unit->receiveOrder(Order(Order::TYPE::MOVE, vector<Order::Target>{Order::Target(nullptr, rallyPoint)}, Vector3::VEC_ZERO), false);
|
||||
unit->receiveOrder(Order(Order::TYPE::MOVE, vector<Order::Target>{Order::Target(nullptr, pos + 30 * dirVec)}, Vector3::VEC_ZERO), false);
|
||||
|
||||
unitQueue.erase(unitQueue.begin());
|
||||
trainingStatus = 0;
|
||||
@@ -20,14 +20,11 @@ namespace battleship{
|
||||
void update();
|
||||
int getNumQueueUnitsById(int);
|
||||
void appendToQueue(int);
|
||||
inline void setRallyPoint(vb01::Vector3 rp){this->rallyPoint = rp;}
|
||||
inline vb01::Vector3 getRallyPoint(){return rallyPoint;}
|
||||
inline std::vector<int> getQueue(){return unitQueue;}
|
||||
private:
|
||||
std::vector<int> unitQueue;
|
||||
int maxLenQueue, trainingStatus = 0;
|
||||
vb01::s64 lastTrainTime = 0;
|
||||
vb01::Vector3 rallyPoint;
|
||||
|
||||
void initProperties();
|
||||
void train();
|
||||
@@ -33,7 +33,7 @@ namespace battleship{
|
||||
|
||||
Vehicle::build(order);
|
||||
|
||||
if(targ->getUnitClass() == UnitClass::ICE_SHEET && ((Structure*)targ)->isComplete())
|
||||
if(targ->getUnitClass() == UnitClass::ICE_SHEET && ((Structure*)targ)->getBuildStatus() >= 100)
|
||||
removeOrder(0);
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ namespace battleship{
|
||||
model->setMaterial(mat);
|
||||
sol::optional<sol::table> colNodeOpt = gameObjTable["colorNodes"];
|
||||
|
||||
if(!(model->isWireframe() || colNodeOpt == sol::nullopt))
|
||||
if(player && colNodeOpt != sol::nullopt)
|
||||
useColor(player->getColorMaterial());
|
||||
|
||||
root->getRootNode()->attachChild(model);
|
||||
@@ -0,0 +1,89 @@
|
||||
#ifndef GAME_OBJECT_H
|
||||
#define GAME_OBJECT_H
|
||||
|
||||
#include <vector>
|
||||
#include <quaternion.h>
|
||||
#include <model.h>
|
||||
|
||||
namespace sf
|
||||
{
|
||||
class SoundBuffer;
|
||||
class Sound;
|
||||
}
|
||||
|
||||
namespace battleship
|
||||
{
|
||||
class Player;
|
||||
class Unit;
|
||||
class Destructable;
|
||||
|
||||
class GameObject
|
||||
{
|
||||
public:
|
||||
enum class Type
|
||||
{
|
||||
UNIT,
|
||||
PROJECTILE,
|
||||
RESOURCE_DEPOSIT
|
||||
};
|
||||
|
||||
GameObject(Type, int, Player *, vb01::Vector3, vb01::Quaternion);
|
||||
~GameObject() {}
|
||||
virtual void reinit();
|
||||
virtual void update();
|
||||
virtual void select() {}
|
||||
virtual void placeAt(vb01::Vector3);
|
||||
void orientAt(vb01::Quaternion);
|
||||
std::string getGameObjTableName();
|
||||
static sf::Sound *prepareSfx(sf::SoundBuffer *, std::string);
|
||||
bool pointWithinObj(vb01::Vector3, float = 0, float = 0, bool = false, float = 0);
|
||||
void changePlayer(Player *newPlayer);
|
||||
inline float getMaxUnevenness() { return maxUnevenness; }
|
||||
inline vb01::Vector2 getScreenPos() { return screenPos; }
|
||||
inline vb01::Vector3 getCorner(int i) { return corners[i]; }
|
||||
inline bool isSelectable() { return selectable; }
|
||||
inline bool isDebuggable() { return debugging; }
|
||||
inline vb01::Vector3 getPos() { return pos; }
|
||||
inline vb01::Quaternion getRot() { return rot; }
|
||||
inline float getWidth() { return width; }
|
||||
inline float getHeight() { return height; }
|
||||
inline float getLength() { return length; }
|
||||
inline vb01::Model *getModel() { return model; }
|
||||
inline void setPlayer(Player *pl) { player = pl; }
|
||||
inline Player *getPlayer() { return player; }
|
||||
inline void toggleDebugging(bool d) { this->debugging = d; }
|
||||
inline vb01::Vector3 getDirVec() { return dirVec; }
|
||||
inline vb01::Vector3 getLeftVec() { return leftVec; }
|
||||
inline vb01::Vector3 getUpVec() { return upVec; }
|
||||
inline int getId() { return id; }
|
||||
inline Type getType() { return type; }
|
||||
inline vb01::Node *getHitbox() { return hitbox; }
|
||||
inline void setRemove(bool rm) { this->remove = rm; }
|
||||
inline bool isRemove() { return remove; }
|
||||
inline Destructable *getDestructable() { return destructable; }
|
||||
|
||||
protected:
|
||||
virtual void useColor(vb01::Material *);
|
||||
virtual void initProperties();
|
||||
virtual void destroyModel();
|
||||
virtual void initModel(bool = true);
|
||||
virtual void initHitbox();
|
||||
virtual void destroyHitbox();
|
||||
virtual void destroySound();
|
||||
virtual void initSound() {}
|
||||
|
||||
Type type;
|
||||
int id;
|
||||
Player *player;
|
||||
Destructable *destructable = nullptr;
|
||||
vb01::Model *model = nullptr;
|
||||
vb01::Node *hitbox = nullptr;
|
||||
vb01::Vector3 pos = vb01::Vector3(0, 0, 0), upVec = vb01::Vector3(0, 1, 0), dirVec = vb01::Vector3(0, 0, 1), leftVec = vb01::Vector3(1, 0, 0), corners[8];
|
||||
vb01::Vector2 screenPos;
|
||||
vb01::Quaternion rot;
|
||||
bool selectable = false, debugging = false, remove = false;
|
||||
float width, height, length, maxUnevenness;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -34,13 +34,11 @@ namespace battleship{
|
||||
|
||||
if(vehicle)
|
||||
switch((UnitClass)unitClass){
|
||||
case UnitClass::ROBO_ENGINEER:
|
||||
case UnitClass::CYBORG_ENGINEER:
|
||||
case UnitClass::ENGINEER:
|
||||
return new Engineer(player, id, pos, rot, Unit::State::STAND_GROUND);
|
||||
case UnitClass::RESOURCE_ROVER:
|
||||
return new ResourceRover(player, id, pos, rot, Unit::State::STAND_GROUND);
|
||||
case UnitClass::SUBMARINE:
|
||||
case UnitClass::MISSILE_SUBMARINE:
|
||||
return new Submarine(player, id, pos, rot, Unit::State::STAND_GROUND);
|
||||
case UnitClass::FREEZER:
|
||||
return new Freezer(player, id, pos, rot, Unit::State::STAND_GROUND);
|
||||
@@ -49,6 +47,7 @@ namespace battleship{
|
||||
}
|
||||
else
|
||||
switch((UnitClass)unitClass){
|
||||
case UnitClass::FORT:
|
||||
case UnitClass::LAND_FACTORY:
|
||||
case UnitClass::NAVAL_FACTORY:
|
||||
return new Factory(player, id, pos, rot, buildStatus, Unit::State::STAND_GROUND);
|
||||
@@ -0,0 +1,31 @@
|
||||
#ifndef GAME_OBJECT_FACTORY_H
|
||||
#define GAME_OBJECT_FACTORY_H
|
||||
|
||||
#include <vector>
|
||||
#include <quaternion.h>
|
||||
|
||||
namespace battleship
|
||||
{
|
||||
class Unit;
|
||||
class Projectile;
|
||||
class ResourceDeposit;
|
||||
class Player;
|
||||
|
||||
class GameObjectFactory
|
||||
{
|
||||
public:
|
||||
enum GameObjectType
|
||||
{
|
||||
UNIT,
|
||||
PROJECTILE,
|
||||
RESOURCE_DEPOSIT
|
||||
};
|
||||
static Unit *createUnit(Player *, int, vb01::Vector3, vb01::Quaternion, int = 0);
|
||||
static Projectile *createProjectile(Unit *, int, vb01::Vector3, vb01::Quaternion);
|
||||
static ResourceDeposit *createResourceDeposit(Player *, int, vb01::Vector3, vb01::Quaternion, int = 0);
|
||||
|
||||
private:
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
Executable → Regular
+131
-131
@@ -1,131 +1,131 @@
|
||||
#include <node.h>
|
||||
#include <model.h>
|
||||
#include <material.h>
|
||||
#include <quaternion.h>
|
||||
#include <particleEmitter.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "game.h"
|
||||
#include "unit.h"
|
||||
#include "util.h"
|
||||
#include "player.h"
|
||||
#include "environment.h"
|
||||
#include "projectile.h"
|
||||
#include "defConfigs.h"
|
||||
#include "destructable.h"
|
||||
#include "resourceDeposit.h"
|
||||
#include "inGameAppState.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace configData;
|
||||
using namespace gameBase;
|
||||
|
||||
Projectile::Projectile(Unit *un, int id, Vector3 pos, Quaternion rot) : GameObject(GameObject::Type::PROJECTILE, id, un->getPlayer(), pos, rot), unit(un), initPos(pos){
|
||||
initProperties();
|
||||
initModel();
|
||||
initSound();
|
||||
placeAt(pos);
|
||||
orientAt(rot);
|
||||
}
|
||||
|
||||
Projectile::~Projectile(){
|
||||
destroySound();
|
||||
destroyModel();
|
||||
}
|
||||
|
||||
void Projectile::reinit(){
|
||||
destroySound();
|
||||
destroyModel();
|
||||
|
||||
initProperties();
|
||||
|
||||
initModel();
|
||||
|
||||
GameObject::reinit();
|
||||
}
|
||||
|
||||
void Projectile::initProperties(){
|
||||
GameObject::initProperties();
|
||||
Game *game = Game::getSingleton();
|
||||
vector<int> currTechs = player->getTechnologies();
|
||||
|
||||
sol::table projTable = generateView()[GameObject::getGameObjTableName()][id + 1];
|
||||
projClass = (ProjectileClass)projTable["projectileClass"];
|
||||
|
||||
rayLength = projTable["rayLength"];
|
||||
directHitDamage = projTable["directHitDamage"]; directHitDamage += game->calcAbilFromTech(Ability::Type::DIRECT_HIT_DAMAGE, currTechs, (int)GameObject::type, id);
|
||||
|
||||
string explKey = "explosion";
|
||||
explosionDamage = projTable[explKey]["damage"]; explosionDamage += game->calcAbilFromTech(Ability::Type::EXPLOSION_DAMAGE, currTechs, (int)GameObject::type, id);
|
||||
explosionRadius = projTable[explKey]["radius"]; explosionRadius += game->calcAbilFromTech(Ability::Type::EXPLOSION_RADIUS, currTechs, (int)GameObject::type, id);
|
||||
speed = projTable["speed"];
|
||||
rotAngle = projTable["rotAngle"].get_or(0.0);
|
||||
}
|
||||
|
||||
void Projectile::update() {
|
||||
GameObject::update();
|
||||
placeAt(pos + speed * dirVec);
|
||||
}
|
||||
|
||||
void Projectile::detonate(Unit *target){
|
||||
if(target) target->getDestructable()->takeDamage(directHitDamage);
|
||||
|
||||
sol::table tbl = generateView()[getGameObjTableName()][id + 1]["explosion"];
|
||||
FxManager::Fx *fx = FxManager::getSingleton()->initFx(tbl["fx"], model, false, pos);
|
||||
Environment::explode(fx, (Environment::Detonation)tbl["detonation"], pos, tbl["damage"], tbl["radius"]);
|
||||
|
||||
remove = true;
|
||||
}
|
||||
|
||||
void Projectile::checkUnitCollision(){
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers(true);
|
||||
vector<Unit*> targetUnits;
|
||||
vector<Node*> targetNodes;
|
||||
|
||||
for(Player *pl : players){
|
||||
vector<Unit*> units = pl->getUnits();
|
||||
|
||||
for(Unit *u : units)
|
||||
if(unit && unit != u){
|
||||
targetUnits.push_back(u);
|
||||
targetNodes.push_back(u->getHitbox());
|
||||
}
|
||||
}
|
||||
|
||||
vector<RayCaster::CollisionResult> results = RayCaster::cast(pos, dirVec, targetNodes, rayLength);
|
||||
|
||||
if(!results.empty())
|
||||
for(int i = 0; i < targetNodes.size(); i++)
|
||||
if(targetNodes[i]->getMesh(0) == results[0].mesh)
|
||||
detonate(targetUnits[i]);
|
||||
}
|
||||
|
||||
//TODO fix map boundary checks
|
||||
void Projectile::checkSurfaceCollision(bool useBottomCell){
|
||||
Map *map = Map::getSingleton();
|
||||
vector<Map::Cell> &cells = map->getCells();
|
||||
int cellId = map->getCellId(pos, false);
|
||||
Vector3 mapSize = map->getMapSize();
|
||||
|
||||
if(cellId < 0 || fabs(pos.x) > .5 * mapSize.x || fabs(pos.z) > .5 * mapSize.z){
|
||||
remove = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(useBottomCell && !cells[cellId].underWaterCellIds.empty()){
|
||||
int numUnderwaterCells = cells[cellId].underWaterCellIds.size();
|
||||
cellId = cells[cellId].underWaterCellIds[numUnderwaterCells - 1];
|
||||
}
|
||||
|
||||
if((pos + dirVec * rayLength).y <= cells[cellId].pos.y + .5 * map->getCellSize().y)
|
||||
detonate();
|
||||
}
|
||||
|
||||
void Projectile::debug(){
|
||||
}
|
||||
}
|
||||
#include <node.h>
|
||||
#include <model.h>
|
||||
#include <material.h>
|
||||
#include <quaternion.h>
|
||||
#include <particleEmitter.h>
|
||||
|
||||
#include <stateManager.h>
|
||||
|
||||
#include "game.h"
|
||||
#include "unit.h"
|
||||
#include "util.h"
|
||||
#include "player.h"
|
||||
#include "environment.h"
|
||||
#include "projectile.h"
|
||||
#include "defConfigs.h"
|
||||
#include "destructable.h"
|
||||
#include "resourceDeposit.h"
|
||||
#include "inGameAppState.h"
|
||||
|
||||
using namespace std;
|
||||
using namespace vb01;
|
||||
|
||||
namespace battleship{
|
||||
using namespace vb01;
|
||||
using namespace configData;
|
||||
using namespace gameBase;
|
||||
|
||||
Projectile::Projectile(Unit *un, int id, Vector3 pos, Quaternion rot) : GameObject(GameObject::Type::PROJECTILE, id, un->getPlayer(), pos, rot), unit(un), initPos(pos){
|
||||
initProperties();
|
||||
initModel();
|
||||
initSound();
|
||||
placeAt(pos);
|
||||
orientAt(rot);
|
||||
}
|
||||
|
||||
Projectile::~Projectile(){
|
||||
destroySound();
|
||||
destroyModel();
|
||||
}
|
||||
|
||||
void Projectile::reinit(){
|
||||
destroySound();
|
||||
destroyModel();
|
||||
|
||||
initProperties();
|
||||
|
||||
initModel();
|
||||
|
||||
GameObject::reinit();
|
||||
}
|
||||
|
||||
void Projectile::initProperties(){
|
||||
GameObject::initProperties();
|
||||
Game *game = Game::getSingleton();
|
||||
vector<int> currTechs = player->getTechnologies();
|
||||
|
||||
sol::table projTable = generateView()[GameObject::getGameObjTableName()][id + 1];
|
||||
projClass = (ProjectileClass)projTable["projectileClass"];
|
||||
|
||||
rayLength = projTable["rayLength"];
|
||||
directHitDamage = projTable["directHitDamage"]; directHitDamage += game->calcAbilFromTech(Ability::Type::DIRECT_HIT_DAMAGE, currTechs, (int)GameObject::type, id);
|
||||
|
||||
string explKey = "explosion";
|
||||
explosionDamage = projTable[explKey]["damage"]; explosionDamage += game->calcAbilFromTech(Ability::Type::EXPLOSION_DAMAGE, currTechs, (int)GameObject::type, id);
|
||||
explosionRadius = projTable[explKey]["radius"]; explosionRadius += game->calcAbilFromTech(Ability::Type::EXPLOSION_RADIUS, currTechs, (int)GameObject::type, id);
|
||||
speed = projTable["speed"];
|
||||
rotAngle = projTable["rotAngle"].get_or(0.0);
|
||||
}
|
||||
|
||||
void Projectile::update() {
|
||||
GameObject::update();
|
||||
placeAt(pos + speed * dirVec);
|
||||
}
|
||||
|
||||
void Projectile::detonate(Unit *target){
|
||||
if(target) target->getDestructable()->takeDamage(directHitDamage);
|
||||
|
||||
sol::table tbl = generateView()[getGameObjTableName()][id + 1]["explosion"];
|
||||
FxManager::Fx *fx = FxManager::getSingleton()->initFx(tbl["fx"], model, false, pos);
|
||||
Environment::explode(fx, (Environment::Detonation)tbl["detonation"], pos, tbl["damage"], tbl["radius"]);
|
||||
|
||||
remove = true;
|
||||
}
|
||||
|
||||
void Projectile::checkUnitCollision(){
|
||||
vector<Player*> players = Game::getSingleton()->getPlayers(true);
|
||||
vector<Unit*> targetUnits;
|
||||
vector<Node*> targetNodes;
|
||||
|
||||
for(Player *pl : players){
|
||||
vector<Unit*> units = pl->getUnits();
|
||||
|
||||
for(Unit *u : units)
|
||||
if(unit && unit != u){
|
||||
targetUnits.push_back(u);
|
||||
targetNodes.push_back(u->getHitbox());
|
||||
}
|
||||
}
|
||||
|
||||
vector<RayCaster::CollisionResult> results = RayCaster::cast(pos, dirVec, targetNodes, rayLength);
|
||||
|
||||
if(!results.empty())
|
||||
for(int i = 0; i < targetNodes.size(); i++)
|
||||
if(targetNodes[i]->getMesh(0) == results[0].mesh)
|
||||
detonate(targetUnits[i]);
|
||||
}
|
||||
|
||||
//TODO fix map boundary checks
|
||||
void Projectile::checkSurfaceCollision(bool useBottomCell){
|
||||
Map *map = Map::getSingleton();
|
||||
vector<Map::Cell> &cells = map->getCells();
|
||||
int cellId = map->getCellId(pos, false);
|
||||
Vector3 mapSize = map->getMapSize();
|
||||
|
||||
if(cellId < 0 || fabs(pos.x) > .5 * mapSize.x || fabs(pos.z) > .5 * mapSize.z){
|
||||
remove = true;
|
||||
return;
|
||||
}
|
||||
|
||||
if(useBottomCell && !cells[cellId].underWaterCellIds.empty()){
|
||||
int numUnderwaterCells = cells[cellId].underWaterCellIds.size();
|
||||
cellId = cells[cellId].underWaterCellIds[numUnderwaterCells - 1];
|
||||
}
|
||||
|
||||
if((pos + dirVec * rayLength).y <= cells[cellId].pos.y + .5 * map->getCellSize().y)
|
||||
detonate();
|
||||
}
|
||||
|
||||
void Projectile::debug(){
|
||||
}
|
||||
}
|
||||
Executable → Regular
+44
-44
@@ -1,44 +1,44 @@
|
||||
#ifndef PROJECTILE_H
|
||||
#define PROJECTILE_H
|
||||
|
||||
#include "gameObject.h"
|
||||
#include "fxManager.h"
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace battleship {
|
||||
class Unit;
|
||||
|
||||
enum class ProjectileClass{SHELL, CRUISE_MISSILE, MISSILE, TORPEDO, DEPTH_CHARGE};
|
||||
|
||||
class Projectile : public GameObject{
|
||||
public:
|
||||
Projectile(Unit*, int, vb01::Vector3, vb01::Quaternion);
|
||||
virtual ~Projectile();
|
||||
virtual void update();
|
||||
virtual void debug();
|
||||
inline ProjectileClass getProjectileClass(){return projClass;}
|
||||
private:
|
||||
void initProperties();
|
||||
void detonate(Unit *u = nullptr);
|
||||
protected:
|
||||
virtual void reinit();
|
||||
virtual void checkUnitCollision();
|
||||
virtual void checkSurfaceCollision(bool);
|
||||
|
||||
vb01::Vector3 initPos;
|
||||
ProjectileClass projClass;
|
||||
Unit *unit = nullptr;
|
||||
FxManager::Fx *explosionFx = nullptr;
|
||||
float speed, rayLength, explosionRadius, rotAngle;
|
||||
int directHitDamage, explosionDamage;
|
||||
sf::SoundBuffer *shotSfxBuffer, *explosionSfxBuffer;
|
||||
sf::Sound *shotSfx = nullptr, *explosionSfx = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
#ifndef PROJECTILE_H
|
||||
#define PROJECTILE_H
|
||||
|
||||
#include "gameObject.h"
|
||||
#include "fxManager.h"
|
||||
|
||||
#include <SFML/Audio.hpp>
|
||||
|
||||
namespace vb01{
|
||||
class Node;
|
||||
}
|
||||
|
||||
namespace battleship {
|
||||
class Unit;
|
||||
|
||||
enum class ProjectileClass{SHELL, CRUISE_MISSILE, MISSILE, TORPEDO, DEPTH_CHARGE};
|
||||
|
||||
class Projectile : public GameObject{
|
||||
public:
|
||||
Projectile(Unit*, int, vb01::Vector3, vb01::Quaternion);
|
||||
virtual ~Projectile();
|
||||
virtual void update();
|
||||
virtual void debug();
|
||||
inline ProjectileClass getProjectileClass(){return projClass;}
|
||||
private:
|
||||
void initProperties();
|
||||
void detonate(Unit *u = nullptr);
|
||||
protected:
|
||||
virtual void reinit();
|
||||
virtual void checkUnitCollision();
|
||||
virtual void checkSurfaceCollision(bool);
|
||||
|
||||
vb01::Vector3 initPos;
|
||||
ProjectileClass projClass;
|
||||
Unit *unit = nullptr;
|
||||
FxManager::Fx *explosionFx = nullptr;
|
||||
float speed, rayLength, explosionRadius, rotAngle;
|
||||
int directHitDamage, explosionDamage;
|
||||
sf::SoundBuffer *shotSfxBuffer, *explosionSfxBuffer;
|
||||
sf::Sound *shotSfx = nullptr, *explosionSfx = nullptr;
|
||||
};
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -31,7 +31,7 @@ namespace battleship{
|
||||
vector<Player*> selectingPlayers = getSelectingPlayers();
|
||||
bool mainPlayerSelecting = (activeState && find(selectingPlayers.begin(), selectingPlayers.end(), mainPlayer) != selectingPlayers.end());
|
||||
|
||||
if(!isComplete())
|
||||
if(buildStatus < 100)
|
||||
destructable->displayStats(buildStatusForeground, buildStatusBackground, buildStatus, 100, mainPlayer == player && mainPlayerSelecting, Vector2(0, -10));
|
||||
else{
|
||||
buildStatusBackground->setVisible(false);
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user