mirror of
https://github.com/devZoGok/PlanetFleet.git
synced 2026-08-26 19:43:29 +00:00
placeable frames of structures to be built
This commit is contained in:
@@ -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}
|
||||
|
||||
@@ -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/",
|
||||
|
||||
+2
-1
@@ -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})
|
||||
|
||||
|
||||
+67
-5
@@ -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<Player*> 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<LineRenderer::Line> 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;
|
||||
}
|
||||
}
|
||||
|
||||
+13
-2
@@ -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<Player*> 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<Unit*>& 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<Player*> players;
|
||||
std::vector<StructureFrame> structureFrames;
|
||||
Player *mainPlayer;
|
||||
vb01::Quad *dragbox = nullptr;
|
||||
vb01::Node *dragboxNode = nullptr, *textNode = nullptr;
|
||||
@@ -48,7 +59,7 @@ namespace battleship{
|
||||
std::vector<vb01::Node*> unitLightNodes;
|
||||
std::vector<Unit*> unitGroups[9], selectedUnits;
|
||||
std::vector<Order::Target> 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;
|
||||
|
||||
+5
-2
@@ -265,11 +265,14 @@ namespace battleship{
|
||||
string pathBase = GameManager::getSingleton()->getPath() + "Scripts/";
|
||||
lm->buildScript(vector<string>{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>{Index(i + 1)});
|
||||
string meshPath = lm->getStringFromTable("meshPath", vector<Index>{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;
|
||||
}
|
||||
|
||||
+2
-1
@@ -30,6 +30,7 @@ namespace battleship{
|
||||
std::vector<Unit*> getSelectedUnits(Player*);
|
||||
inline std::vector<Player*> getPlayers() {return players;}
|
||||
inline std::vector<Projectile*>& 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<Player*> players;
|
||||
std::vector<std::string> difficultyLevels, factions;
|
||||
std::vector<std::string> difficultyLevels, factions, modelPaths;
|
||||
std::vector<Projectile*> projectiles;
|
||||
std::vector<Fx> fx;
|
||||
std::string mapName;
|
||||
|
||||
Reference in New Issue
Block a user