diff --git a/Assets/Scripts/options.lua b/Assets/Scripts/options.lua index 0fd9024..5cad949 100644 --- a/Assets/Scripts/options.lua +++ b/Assets/Scripts/options.lua @@ -34,7 +34,7 @@ mappings = { {bind = 30, trigger = 56, action = true, bindType = 0, inOptions = true}, {bind = 31, trigger = 57, action = true, bindType = 0, inOptions = true}, {bind = 32, trigger = 66, action = true, bindType = 0, inOptions = true}, - {bind = 32, trigger = 256, action = true, bindType = 0, inOptions = true}, + {bind = 33, trigger = 256, action = true, bindType = 0, inOptions = true}, } graphics = { resolution = {x = 1366, y = 768} diff --git a/Assets/Scripts/unitData.lua b/Assets/Scripts/unitData.lua index a857bf5..1835d8b 100644 --- a/Assets/Scripts/unitData.lua +++ b/Assets/Scripts/unitData.lua @@ -1,25 +1,17 @@ -numUnits = 3 +numUnits = 4 -UnitClass = {VESSEL = 0, DESTROYER = 1, CRUISER = 2, AIRCRAFT_CARRIER = 3, SUBMARINE = 4, MISSILE_JET = 5, DEMO_JET = 6, SAMPLE_STRUCTURE = 7}; +UnitClass = {VESSEL = 0, ENGINEER = 1, SAMPLE_STRUCTURE = 2}; UnitType = {UNDERWATER = 0, SEA_LEVEL = 1, LAND = 2, AIR = 3}; unitClass = { UnitClass.VESSEL, UnitClass.VESSEL, - UnitClass.SAMPLE_STRUCTURE, UnitClass.DESTROYER, - UnitClass.CRUISER, UnitClass.CRUISER, - UnitClass.AIRCRAFT_CARRIER, UnitClass.AIRCRAFT_CARRIER, - UnitClass.SUBMARINE, - UnitClass.MISSILE_JET, UnitClass.DEMO_JET + UnitClass.ENGINEER, UnitClass.SAMPLE_STRUCTURE }; unitType = { UnitType.SEA_LEVEL, UnitType.UNDERWATER, - UnitType.LAND, UnitType.SEA_LEVEL, - UnitType.SEA_LEVEL, UnitType.SEA_LEVEL, - UnitType.SEA_LEVEL, UnitType.SEA_LEVEL, - UnitType.UNDERWATER, - UnitType.AIR, UnitType.AIR + UnitType.LAND, UnitType.LAND } health = {500, 500, 500, 500, 500, 500, 500, 500, 500, 500, 500} @@ -255,7 +247,7 @@ unitAxisLength = {8, 8, 6, 6, 5, 5, 8, 8, 7, 2, 2} lineOfSight = {5, 8, 4, 4, 3, 3, 6, 6, 3, 3, 8} name = { "Battleship", "Battleship", - "Sample", "Destroyer", + "Battleship", "Battleship", "Cruiser", "Cruiser", "Aircraft carrier", "Aircraft carrier", "Submarine", @@ -263,7 +255,7 @@ name = { } meshPath = { "battleship00.xml", "battleship00.xml", - "sample.xml", "destroyer01.xml", + "battleship00.xml", "sample.xml", "cruiser00.xml", "cruiser01.xml", "aircraftCarrier00.xml", "aircraftCarrier01.xml", "submarine.xml", @@ -273,7 +265,7 @@ vehiclePrefix = "Models/Units/Vehicles/" structurePrefix = "Models/Units/Structures/" basePath = { PATH .. vehiclePrefix .. "Battleships/", PATH .. vehiclePrefix .. "Battleships/", - PATH .. structurePrefix .. "Sample/", PATH .. vehiclePrefix .. "Destroyers/", + PATH .. vehiclePrefix .. "Battleships/", PATH .. structurePrefix .. "Sample/", PATH .. vehiclePrefix .. "Cruisers/", PATH .. vehiclePrefix .. "Cruisers/", PATH .. vehiclePrefix .. "Aircraft carriers/", PATH .. vehiclePrefix .. "Aircraft carriers/", PATH .. vehiclePrefix .. "Submarines/", diff --git a/CMakeLists.txt b/CMakeLists.txt index acefbb3..8811fa0 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -13,7 +13,8 @@ set(GUI tooltip.cpp optionsButton.cpp exitButton.cpp consoleCommand.cpp) set(CORE gameManager.cpp defConfigs.cpp) set(PROJECTILES projectile.cpp) set(FX explosion.cpp) -set(UNITS unit.cpp structure.cpp vehicle.cpp) +set(VEHICLES vehicle.cpp engineer.cpp) +set(UNITS unit.cpp structure.cpp ${VEHICLES}) set(CONTENT player.cpp pathfinder.cpp map.cpp ${UNITS} ${PROJECTILES} ${FX}) set(GAME_SRC ${STATES} ${GUI} ${CORE} ${CONTENT} ${UTIL}) diff --git a/activeGameState.cpp b/activeGameState.cpp index 31e563c..89d8719 100755 --- a/activeGameState.cpp +++ b/activeGameState.cpp @@ -26,7 +26,23 @@ using namespace std; namespace battleship{ using namespace configData; using namespace gameBase; - + + ActiveGameState::StructureFrame::StructureFrame(string modelPath, int i, int t) : id(i), type(t) { + Root *root = Root::getSingleton(); + Material *mat = new Material(root->getLibPath() + "texture"); + mat->addBoolUniform("texturingEnabled", false); + mat->addBoolUniform("lightingEnabled", false); + mat->addVec4Uniform("diffuseColor", Vector4::VEC_ZERO); + + model = new Model(modelPath); + model->setWireframe(true); + model->setMaterial(mat); + root->getRootNode()->attachChild(model); + } + + ActiveGameState::StructureFrame::~StructureFrame(){ + } + ActiveGameState::ActiveGameState(GuiAppState *guiState, vector players, int playerId) : AbstractAppState( AppStateType::ACTIVE_STATE, configData::calcSumBinds(AppStateType::ACTIVE_STATE, true), @@ -98,6 +114,9 @@ namespace battleship{ if(!lookingAround) updateCameraPosition(); + + if(placingStructures) + updateStructureFrames(); } void ActiveGameState::deselectUnits(){ @@ -187,6 +206,19 @@ namespace battleship{ dragboxNode->setPosition(Vector3(selectionBoxOrigin.x, selectionBoxOrigin.y, 0)); } + //TODO implement terrain evenness check + void ActiveGameState::updateStructureFrames(){ + Map *map = Map::getSingleton(); + MeshData::Vertex *verts = map->getTerrainObject(0).node->getChild(0)->getMesh(0)->getMeshBase().vertices; + + for(StructureFrame s : structureFrames){ + Vector3 cursorSpacePos = screenToSpace(getCursorPos()); + s.model->setPosition(Vector3(0, 0, 0)); + Material *mat = s.model->getMaterial(); + mat->setVec4Uniform("diffuseColor", Vector4(0, 1, 0, 1)); + } + } + void ActiveGameState::updateCameraPosition() { GameManager *gm = GameManager::getSingleton(); Vector2 cursorPos = getCursorPos(); @@ -264,7 +296,7 @@ namespace battleship{ vector lines = lineRenderer->getLines(); o.line = lines[lines.size() - 1]; - if (type != Order::TYPE::LAUNCH || u->getUnitClass() == UnitClass::CRUISER) { + if (type != Order::TYPE::LAUNCH) { if(type == Order::TYPE::PATROL){ Vector3 p = u->getPos(); targets[0] = Order::Target(nullptr, p); @@ -319,6 +351,10 @@ namespace battleship{ if(controlPressed || (targets[0].unit && targets[0].unit->getPlayer()->getSide() != mainPlayer->getSide())) type = Order::TYPE::ATTACK; + else if(placingStructures){ + type = Order::TYPE::BUILD; + placingStructures = false; + } issueOrder(type, shiftPressed); } @@ -346,7 +382,7 @@ namespace battleship{ } break; case Bind::LOOK_AROUND: - if(!placingStructure) + if(!placingStructures) lookingAround = isPressed; break; case Bind::HALT: @@ -404,10 +440,36 @@ namespace battleship{ break; case Bind::SELECT_STRUCTURE: - placingStructure = true; + { + bool engineersSelected = false; + + for(Unit *u : selectedUnits) + if(u->getUnitClass() == UnitClass::ENGINEER){ + engineersSelected = true; + break; + } + + if(!engineersSelected) + break; + + StateManager *sm = GameManager::getSingleton()->getStateManager(); + InGameAppState *inGameState = (InGameAppState*)sm->getAppStateByType(int(AppStateType::IN_GAME_STATE)); + + //TODO fix the magic value + int id = 3; + structureFrames.push_back(StructureFrame(inGameState->getModelPath(id), id, (int)UnitType::LAND)); + + placingStructures = true; break; + } case Bind::DESELECT_STRUCTURE: - placingStructure = false; + for(StructureFrame s : structureFrames){ + Root::getSingleton()->getRootNode()->dettachChild(s.model); + delete s.model; + } + + structureFrames.clear(); + placingStructures = false; break; } } diff --git a/activeGameState.h b/activeGameState.h index bbfd2ae..6ea5b77 100755 --- a/activeGameState.h +++ b/activeGameState.h @@ -13,6 +13,15 @@ namespace vb01{ namespace battleship{ class ActiveGameState : public gameBase::AbstractAppState { public: + struct StructureFrame{ + vb01::Model *model; + int id, type; + bool canPlace; + + StructureFrame(std::string, int, int); + ~StructureFrame(); + }; + ActiveGameState(GuiAppState*, std::vector players, int); ~ActiveGameState(); void onAttached(); @@ -20,7 +29,7 @@ namespace battleship{ void update(); void onAction(int, bool); void onAnalog(int, float); - inline bool isPlacingStructure(){return placingStructure;} + inline bool isPlacingStructures(){return placingStructures;} inline void setSelectingLaunchPoint(bool s){this->selectingGuidedMissileTarget=s;} inline Player* getPlayer(){return mainPlayer;} inline std::vector& getSelectedUnits(){return selectedUnits;} @@ -32,6 +41,7 @@ namespace battleship{ void renderUnits(); void updateCameraPosition(); void updateSelectionBox(); + void updateStructureFrames(); void addTarget(); void issueOrder(Order::TYPE, bool); void lookAround(bool); @@ -40,6 +50,7 @@ namespace battleship{ GuiAppState *guiState; std::vector players; + std::vector structureFrames; Player *mainPlayer; vb01::Quad *dragbox = nullptr; vb01::Node *dragboxNode = nullptr, *textNode = nullptr; @@ -48,7 +59,7 @@ namespace battleship{ std::vector unitLightNodes; std::vector unitGroups[9], selectedUnits; std::vector targets; - bool isSelectionBox = false, shiftPressed = false, controlPressed = false, selectingPatrolPoints = false, selectingGuidedMissileTarget = false, lookingAround = false, placingStructure = false; + bool isSelectionBox = false, shiftPressed = false, controlPressed = false, selectingPatrolPoints = false, selectingGuidedMissileTarget = false, lookingAround = false, placingStructures = false; int playerId, zooms = 0; const int NUM_MAX_ZOOMS = 10; float depth = 1; diff --git a/inGameAppState.cpp b/inGameAppState.cpp index 1297c80..b17e70e 100755 --- a/inGameAppState.cpp +++ b/inGameAppState.cpp @@ -265,11 +265,14 @@ namespace battleship{ string pathBase = GameManager::getSingleton()->getPath() + "Scripts/"; lm->buildScript(vector{pathBase + "defPaths.lua", pathBase + "unitData.lua"}); int numUnits = lm->getInt("numUnits"); + modelPaths.clear(); for(int i = 0; i < numUnits; ++i){ string basePath = lm->getStringFromTable("basePath", vector{Index(i + 1)}); string meshPath = lm->getStringFromTable("meshPath", vector{Index(i + 1)}); - AssetManager::getSingleton()->load(basePath + meshPath); + string modelPath = basePath + meshPath; + AssetManager::getSingleton()->load(modelPath); + modelPaths.push_back(modelPath); } } @@ -318,7 +321,7 @@ namespace battleship{ void InGameAppState::onAction(int bind, bool isPressed) { switch((Bind)bind){ case Bind::TOGGLE_MAIN_MENU: - if(isPressed && !activeState->isPlacingStructure()) + if(isPressed && !activeState->isPlacingStructures()) toggleMainMenu(); break; } diff --git a/inGameAppState.h b/inGameAppState.h index f7b7008..3587584 100755 --- a/inGameAppState.h +++ b/inGameAppState.h @@ -30,6 +30,7 @@ namespace battleship{ std::vector getSelectedUnits(Player*); inline std::vector getPlayers() {return players;} inline std::vector& getProjectiles(){return projectiles;} + inline std::string getModelPath(int i){return modelPaths[i];} inline void addFx(Fx fx){this->fx.push_back(fx);} inline void addProjectile(Projectile *p){projectiles.push_back(p);} private: @@ -99,7 +100,7 @@ namespace battleship{ ExitButton *exitButton; bool isMainMenuActive = false; std::vector players; - std::vector difficultyLevels, factions; + std::vector difficultyLevels, factions, modelPaths; std::vector projectiles; std::vector fx; std::string mapName;