mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
Merge pull request #151 from devZoGok/bf-147-unit-selection
Bf 147 unit selection
This commit is contained in:
@@ -14,15 +14,22 @@ players = {
|
||||
{
|
||||
resourceDeposits = {},
|
||||
units = {
|
||||
{id = UnitId.ENGINEER, pos = {x = 30.000000, y = 0.000000, z = 30.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.ENGINEER, pos = {x = 30.000000, y = 0.000000, z = 30.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.POINT_DEFENSE, pos = {x = 50.000000, y = 0.000000, z = 40.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
|
||||
{id = UnitId.TANK, pos = {x = 40.000000, y = 0.000000, z = 30.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.WAR_MECH, pos = {x = 40.000000, y = 0.000000, z = 40.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.ARTILLERY, pos = {x = 30.000000, y = 0.000000, z = 40.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.TACTICAL_CRUISER, pos = {x = 5.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.CHEAP_CRUISER, pos = {x = -5.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.DEFENSIVE_CRUISER, pos = {x = 0.00000, y = 0.000000, z = 5.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.TRANSPORT_CRUISER, pos = {x = 0.00000, y = 0.000000, z = -5.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.CHAMPION_CARRIER, pos = {x = 0.00000, y = 0.000000, z = 15.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.HEAVY_CARRIER, pos = {x = 20.00000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.TRADE_CENTER, pos = {x = 10.000000, y = 0.000000, z = 40.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.SCOUT_TRANSPORT, pos = {x = 20.000000, y = 0.000000, z = 40.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.HOVER_TRANSPORT, pos = {x = 10.000000, y = 0.000000, z = 40.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.RESOURCE_ROVER, pos = {x = 0.000000, y = 0.000000, z = 40.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.TACTICAL_CRUISER, pos = {x = 5.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.CHEAP_CRUISER, pos = {x = -5.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.DEFENSIVE_CRUISER, pos = {x = 0.00000, y = 0.000000, z = 5.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.TRANSPORT_CRUISER, pos = {x = 0.00000, y = 0.000000, z = -5.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.CHAMPION_CARRIER, pos = {x = 0.00000, y = 0.000000, z = 15.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.HEAVY_CARRIER, pos = {x = 20.00000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.STEALTH_SUBMARINE, pos = {x = 10.00000, y = 0.000000, z = 5.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.MISSILE_SUBMARINE, pos = {x = 10.00000, y = 0.000000, z = -5.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
},
|
||||
}
|
||||
|
||||
@@ -13,7 +13,7 @@ resourceDeposits = {
|
||||
{id = ResourceId.RESOURCE, pos = {x = 50, y = 0, z = 0}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, initAmmount = 30000},
|
||||
},
|
||||
units = {
|
||||
{id = UnitId.ENGINEER, pos = {x = -50.000000, y = 0.000000, z = -50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.TANK, pos = {x = -50.000000, y = 0.000000, z = -50.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.ENGINEER, pos = {x = -10.000000, y = 0.000000, z = -10.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.POINT_DEFENSE, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
}
|
||||
@@ -22,12 +22,12 @@ units = {
|
||||
resourceDeposits = {},
|
||||
units = {
|
||||
{id = UnitId.WAR_MECH, pos = {x = 3.000000, y = 0.000000, z = 12.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.WAR_MECH, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.TRADE_CENTER, pos = {x = 0.000000, y = 0.000000, z = 20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
|
||||
{id = UnitId.RESOURCE_ROVER, pos = {x = 4.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.TANK, pos = {x = 0.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.POINT_DEFENSE, pos = {x = 0.000000, y = 0.000000, z = 20.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
|
||||
{id = UnitId.SCOUT_TRANSPORT, pos = {x = 40.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
{id = UnitId.ENGINEER, pos = {x = 45.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}},
|
||||
--{id = UnitId.EXTRACTOR, pos = {x = 30.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
|
||||
{id = UnitId.FORT, pos = {x = 50.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
|
||||
--{id = UnitId.LAB, pos = {x = 50.000000, y = 0.000000, z = 0.000000}, rot = {w = 1.000000, x = 0.000000, y = 0.000000, z = 0.000000}, buildStatus = 100},
|
||||
}
|
||||
}
|
||||
},
|
||||
|
||||
@@ -128,8 +128,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2.9, y = 8.22, z = 2.42},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 6, y = 9.22, z = 2.42},
|
||||
hitboxOffset = {x = 0, y = 4.5, z = 0},
|
||||
lineOfSight = 20,
|
||||
name = 'War mech',
|
||||
basePath = PATH .. vehiclePrefix .. 'WarMechs/',
|
||||
@@ -181,8 +181,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2.9, y = 8.22, z = 2.42},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 9.57, y = 7, z = 20.1},
|
||||
hitboxOffset = {x = 0, y = 3, z = 1.06},
|
||||
lineOfSight = 25,
|
||||
name = 'Tank',
|
||||
basePath = PATH .. vehiclePrefix .. 'Tanks/',
|
||||
@@ -233,8 +233,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2.9, y = 8.22, z = 2.42},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 6.8, y = 6.8, z = 15.2},
|
||||
hitboxOffset = {x = 0, y = 1, z = 0},
|
||||
lineOfSight = 30,
|
||||
name = 'Artillery',
|
||||
basePath = PATH .. vehiclePrefix .. 'Artillery/',
|
||||
@@ -272,7 +272,7 @@ units = {
|
||||
buildTime = 1000,
|
||||
hackTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 1, y = 8, z = 13.45},
|
||||
size = {x = 1, y = 8, z = 1},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
lineOfSight = 20,
|
||||
name = 'Engineer',
|
||||
@@ -297,7 +297,7 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2, y = 8.25, z = 2},
|
||||
size = {x = 21, y = 17.5, z = 56.6},
|
||||
garrisonCapacity = {2, 2, 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
lineOfSight = 5,
|
||||
@@ -324,7 +324,7 @@ units = {
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
garrisonCapacity = {2, 2, 2},
|
||||
size = {x = 2, y = 8.25, z = 2},
|
||||
size = {x = 17.5, y = 16.5, z = 63.5},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
lineOfSight = 5,
|
||||
colorNodes = {'Cube.002'},
|
||||
@@ -352,8 +352,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2, y = 8.25, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 3.29, y = 2.23, z = 9.5},
|
||||
hitboxOffset = {x = 0, y = .37, z = 0},
|
||||
lineOfSight = 5,
|
||||
name = 'Cargo ship',
|
||||
colorNodes = {'CargoshipTemplateOBJ.001'},
|
||||
@@ -403,8 +403,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2, y = 8.25, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 18.8, y = 17.5, z = 52.6},
|
||||
hitboxOffset = {x = 0, y = 1.9, z = 0},
|
||||
lineOfSight = 5,
|
||||
colorNodes = {'tacticalCruiser.001'},
|
||||
name = 'Tactical cruiser',
|
||||
@@ -454,8 +454,8 @@ units = {
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
garrisonCapacity = {2, 2, 2},
|
||||
size = {x = 2, y = 8.25, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 17, y = 17, z = 45.1},
|
||||
hitboxOffset = {x = 0, y = 3.78, z = 0},
|
||||
lineOfSight = 5,
|
||||
colorNodes = {'defensiveCruiser.001'},
|
||||
name = 'Defensive cruiser',
|
||||
@@ -504,8 +504,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2, y = 8.25, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 21.1, y = 18.1, z = 28.6},
|
||||
hitboxOffset = {x = 0, y = 4.19, z = 0},
|
||||
lineOfSight = 5,
|
||||
colorNodes = {'cheapCruiser.001'},
|
||||
name = 'Cheap cruiser',
|
||||
@@ -555,8 +555,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2, y = 8.25, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 17.9, y = 14.9, z = 45.6},
|
||||
hitboxOffset = {x = 0, y = 2.98, z = 1.21},
|
||||
lineOfSight = 5,
|
||||
colorNodes = {'transportCruiser.001'},
|
||||
name = 'Transport cruiser',
|
||||
@@ -604,8 +604,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2, y = 8.25, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 37.8, y = 16.7, z = 87},
|
||||
hitboxOffset = {x = 0, y = 6.38, z = 0},
|
||||
lineOfSight = 5,
|
||||
name = 'Heavy carrier',
|
||||
colorNodes = {'heavyCarrier.001'},
|
||||
@@ -668,8 +668,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2, y = 8.25, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 26, y = 21.1, z = 81.8},
|
||||
hitboxOffset = {x = 0, y = 4.13, z = 0},
|
||||
lineOfSight = 5,
|
||||
name = 'Champion carrier',
|
||||
colorNodes = {'Models4.001'},
|
||||
@@ -720,8 +720,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2, y = 8.25, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 14.1, y = 29.2, z = 59.5},
|
||||
hitboxOffset = {x = 0, y = 6.7, z = 0},
|
||||
lineOfSight = 5,
|
||||
name = 'Missile submarine',
|
||||
basePath = PATH .. vehiclePrefix .. 'Submarines/',
|
||||
@@ -759,8 +759,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 1, y = 1.15, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
hitboxOffset = {x = 0, y = 1.25, z = 0},
|
||||
size = {x = 10.7, y = 15.4, z = 50},
|
||||
lineOfSight = 5,
|
||||
name = 'Stealth submarine',
|
||||
colorNodes = {'stealthSubmarine.001'},
|
||||
@@ -788,8 +788,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 1, y = 1.15, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 21.6, y = 11.9, z = 25.4},
|
||||
hitboxOffset = {x = 0, y = 1.02, z = .95},
|
||||
lineOfSight = 5,
|
||||
colorNodes = {'Cube.001'},
|
||||
name = 'Land factory',
|
||||
@@ -825,8 +825,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 1, y = 1.15, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 8.53, y = 51.9, z = 8.53},
|
||||
hitboxOffset = {x = 0, y = .97, z = 0},
|
||||
lineOfSight = 5,
|
||||
colorNodes = {'Cube.001'},
|
||||
name = 'Trade center',
|
||||
@@ -844,8 +844,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 1, y = 1.15, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 40, y = 26.2, z = 40},
|
||||
hitboxOffset = {x = 0, y = 14, z = 0},
|
||||
lineOfSight = 5,
|
||||
generationRate = 100,
|
||||
generationSpeed = 10,
|
||||
@@ -906,8 +906,8 @@ units = {
|
||||
health = 500,
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
size = {x = 2, y = 10, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 5, y = 8, z = 5},
|
||||
hitboxOffset = {x = 0, y = 4, z = 0},
|
||||
lineOfSight = 55,
|
||||
name = 'Point defense',
|
||||
colorNodes = {'Hoses', 'Hoses.001'},
|
||||
@@ -928,8 +928,8 @@ units = {
|
||||
drawSpeed = 5,
|
||||
cost = 500,
|
||||
colorNodes = {'Cube.001'},
|
||||
size = {x = 4, y = 1.15, z = 4},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
hitboxOffset = {x = 0, y = 1, z = 0},
|
||||
size = {x = 3.24, y = 3.38, z = 3.24},
|
||||
lineOfSight = 5,
|
||||
name = 'Extractor',
|
||||
basePath = PATH .. structurePrefix .. 'Extractors/',
|
||||
@@ -946,8 +946,8 @@ units = {
|
||||
buildTime = 1000,
|
||||
cost = 500,
|
||||
colorNodes = {'Cube.001'},
|
||||
size = {x = 1, y = 1.15, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 15.1, y = 13.5, z = 25},
|
||||
hitboxOffset = {x = 0, y = 1.05, z = 1.85},
|
||||
lineOfSight = 5,
|
||||
name = 'Refinery',
|
||||
basePath = PATH .. structurePrefix .. 'Refineries/',
|
||||
@@ -964,8 +964,8 @@ units = {
|
||||
health = 1000,
|
||||
buildTime = 1000,
|
||||
cost = 1000,
|
||||
size = {x = 1, y = 1.15, z = 2},
|
||||
hitboxOffset = {x = 0, y = 0, z = 0},
|
||||
size = {x = 43.3, y = 50, z = 43.3},
|
||||
hitboxOffset = {x = 0, y = .8, z = 0},
|
||||
lineOfSight = 5,
|
||||
name = 'Fort',
|
||||
basePath = PATH .. structurePrefix .. 'Forts/',
|
||||
|
||||
+125
-51
@@ -4,6 +4,7 @@
|
||||
#include <material.h>
|
||||
#include <texture.h>
|
||||
#include <quad.h>
|
||||
#include <box.h>
|
||||
#include <text.h>
|
||||
#include <rayCaster.h>
|
||||
|
||||
@@ -143,22 +144,25 @@ namespace battleship{
|
||||
guiManager->getText("research")->setText(to_wstring(mainPlayer->getResource(ResourceType::RESEARCH)));
|
||||
|
||||
updateCursor();
|
||||
Vector2 cursorPos = getCursorPos();
|
||||
|
||||
if(!isSelectionBox && leftMouseClicked && getTime() - lastLeftMouseClicked > 10)
|
||||
float eps = .01;
|
||||
|
||||
if(!isSelectionBox && leftMouseClicked && (fabs(clickPoint.x - cursorPos.x) > eps || fabs(clickPoint.y - cursorPos.y) > eps) && getTime() - lastLeftMouseClicked > 10)
|
||||
isSelectionBox = true;
|
||||
else if (isSelectionBox)
|
||||
updateSelectionBox();
|
||||
updateDragBox();
|
||||
|
||||
dragboxNode->setVisible(isSelectionBox);
|
||||
|
||||
updateGameObjHoveredOn();
|
||||
|
||||
vector<Unit*> selectedUnits = mainPlayer->getSelectedUnits();
|
||||
GameObjectFrameController *fc = GameObjectFrameController::getSingleton();
|
||||
|
||||
if(!selectingDestOrient && leftMouseClicked && !selectedUnits.empty() && getTime() - lastLeftMouseClicked > 100){
|
||||
selectingDestOrient = true;
|
||||
|
||||
GameObjectFrameController *fc = GameObjectFrameController::getSingleton();
|
||||
fc->setPlacingFrames(true);
|
||||
fc->setRotatingFrames(true);
|
||||
|
||||
@@ -168,15 +172,13 @@ namespace battleship{
|
||||
|
||||
renderUnits();
|
||||
|
||||
if(fc->isPlacingFrames())
|
||||
fc->update();
|
||||
|
||||
CameraController *camCtr = CameraController::getSingleton();
|
||||
|
||||
if(!camCtr->isLookingAround())
|
||||
camCtr->updateCameraPosition();
|
||||
|
||||
GameObjectFrameController *ufCtr = GameObjectFrameController::getSingleton();
|
||||
|
||||
if(ufCtr->isPlacingFrames())
|
||||
ufCtr->update();
|
||||
}
|
||||
|
||||
void ActiveGameState::updateGameObjHoveredOn(){
|
||||
@@ -194,17 +196,11 @@ namespace battleship{
|
||||
gameObjs.push_back((GameObject*)u);
|
||||
}
|
||||
|
||||
Vector2 cursorPos = getCursorPos();
|
||||
|
||||
for(GameObject *gameObj : gameObjs){
|
||||
Vector2 rectSize = gameObj->calculateSelectionRect();
|
||||
Vector2 screenPos = gameObj->getScreenPos();
|
||||
|
||||
if(fabs(cursorPos.x - screenPos.x) < .5 * rectSize.x && fabs(cursorPos.y - screenPos.y) < .5 * rectSize.y){
|
||||
for(GameObject *gameObj : gameObjs)
|
||||
if(isGameObjSelectable(gameObj, false)){
|
||||
gameObjHoveredOn = gameObj;
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
gameObjHoveredOn = nullptr;
|
||||
}
|
||||
@@ -229,6 +225,86 @@ namespace battleship{
|
||||
return false;
|
||||
}
|
||||
|
||||
bool ActiveGameState::isGameObjSelectable(GameObject *obj, bool useDragBox){
|
||||
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);
|
||||
|
||||
cornersOnScreen[i] = spaceToScreen(cornerInWorld);
|
||||
}
|
||||
|
||||
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);
|
||||
}
|
||||
|
||||
//TODO fix fog of war for hostile units
|
||||
void ActiveGameState::renderUnits() {
|
||||
vector<Unit*> units;
|
||||
@@ -250,12 +326,9 @@ namespace battleship{
|
||||
guiManager->getText("research")
|
||||
};
|
||||
vector<Unit*> selUnits = mainPlayer->getSelectedUnits();
|
||||
|
||||
|
||||
for (Unit *u : units) {
|
||||
if (u->getPlayer() == mainPlayer){
|
||||
Vector3 dragboxSize = ((Quad*)dragboxNode->getMesh(0))->getSize();
|
||||
Vector3 dragboxOrigin = dragboxNode->getPosition(), dragboxEnd = dragboxOrigin + dragboxSize;
|
||||
Vector2 pos = u->getScreenPos();
|
||||
string guiScreen = u->getGuiScreen();
|
||||
|
||||
@@ -263,18 +336,6 @@ namespace battleship{
|
||||
guiManager->readLuaScreenScript(u->getGuiScreen(), buttons, listboxes, checkboxes, sliders, textboxes, guiRects, texts);
|
||||
unitGuiScreen = guiScreen;
|
||||
}
|
||||
|
||||
if(isSelectionBox && fabs(pos.x - dragboxOrigin.x) < .5 * dragboxSize.x && fabs(pos.y - dragboxOrigin.y) < .5 * dragboxSize.y){
|
||||
vector<Unit*> selectedUnits = mainPlayer->getSelectedUnits();
|
||||
|
||||
if(find(selectedUnits.begin(), selectedUnits.end(), u) == selectedUnits.end()){
|
||||
if(!shiftPressed)
|
||||
deselectUnits();
|
||||
|
||||
mainPlayer->selectUnit(u);
|
||||
u->select();
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
Vector3 rendUnPos = u->getPos();
|
||||
@@ -302,31 +363,31 @@ namespace battleship{
|
||||
return inside;
|
||||
}
|
||||
|
||||
void ActiveGameState::updateSelectionBox() {
|
||||
Vector2 mousePos = getCursorPos(), selectionBoxOrigin, selectionBoxEnd;
|
||||
void ActiveGameState::updateDragBox() {
|
||||
Vector2 mousePos = getCursorPos(), dragBoxOrigin, dragBoxEnd;
|
||||
|
||||
if (mousePos.x >= clickPoint.x && mousePos.y >= clickPoint.y) {
|
||||
selectionBoxOrigin = Vector2(clickPoint.x, clickPoint.y);
|
||||
selectionBoxEnd = Vector2(mousePos.x, mousePos.y);
|
||||
dragBoxOrigin = Vector2(clickPoint.x, clickPoint.y);
|
||||
dragBoxEnd = Vector2(mousePos.x, mousePos.y);
|
||||
}
|
||||
else if (mousePos.x < clickPoint.x && mousePos.y > clickPoint.y) {
|
||||
selectionBoxOrigin = Vector2(mousePos.x, clickPoint.y);
|
||||
selectionBoxEnd = Vector2(clickPoint.x, mousePos.y);
|
||||
dragBoxOrigin = Vector2(mousePos.x, clickPoint.y);
|
||||
dragBoxEnd = Vector2(clickPoint.x, mousePos.y);
|
||||
}
|
||||
else if (mousePos.x >= clickPoint.x && mousePos.y < clickPoint.y) {
|
||||
selectionBoxOrigin = Vector2(clickPoint.x, mousePos.y);
|
||||
selectionBoxEnd = Vector2(mousePos.x, clickPoint.y);
|
||||
dragBoxOrigin = Vector2(clickPoint.x, mousePos.y);
|
||||
dragBoxEnd = Vector2(mousePos.x, clickPoint.y);
|
||||
}
|
||||
else {
|
||||
selectionBoxOrigin = Vector2(mousePos.x, mousePos.y);
|
||||
selectionBoxEnd = Vector2(clickPoint.x, clickPoint.y);
|
||||
dragBoxOrigin = Vector2(mousePos.x, mousePos.y);
|
||||
dragBoxEnd = Vector2(clickPoint.x, clickPoint.y);
|
||||
}
|
||||
|
||||
Vector3 size = Vector3(selectionBoxEnd.x - selectionBoxOrigin.x, selectionBoxEnd.y - selectionBoxOrigin.y, 0);
|
||||
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(selectionBoxOrigin.x, selectionBoxOrigin.y, 0));
|
||||
dragboxNode->setPosition(Vector3(dragBoxOrigin.x, dragBoxOrigin.y, 0));
|
||||
}
|
||||
|
||||
//TODO fix ejectable unit selection with multiple transports selected
|
||||
@@ -398,7 +459,9 @@ namespace battleship{
|
||||
lastLeftMouseClicked = getTime();
|
||||
}
|
||||
else{
|
||||
if (mainPlayer->getNumSelectedUnits() > 0){
|
||||
int numSelectedUnits = mainPlayer->getNumSelectedUnits();
|
||||
|
||||
if(numSelectedUnits > 0){
|
||||
if(selectingPatrolPoints){
|
||||
castRayToTerrain();
|
||||
|
||||
@@ -413,7 +476,7 @@ namespace battleship{
|
||||
issueOrder(type, targets, shiftPressed);
|
||||
}
|
||||
}
|
||||
else{
|
||||
else if(!(selectingDestOrient || isSelectionBox)){
|
||||
bool canSelect = canSelectHoveredOnGameObj();
|
||||
bool ownGameObj = (gameObjHoveredOn && gameObjHoveredOn->getPlayer()->getTeam() == mainPlayer->getTeam());
|
||||
|
||||
@@ -463,17 +526,28 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
}
|
||||
else{
|
||||
if(canSelectHoveredOnGameObj()){
|
||||
if(!shiftPressed)
|
||||
deselectUnits();
|
||||
else if(numSelectedUnits == 0 && canSelectHoveredOnGameObj()){
|
||||
if(!shiftPressed) deselectUnits();
|
||||
|
||||
mainPlayer->selectUnit((Unit*)gameObjHoveredOn);
|
||||
}
|
||||
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->setPlacingFrames(false);
|
||||
ufCtr->setRotatingFrames(false);
|
||||
|
||||
+2
-1
@@ -46,9 +46,10 @@ namespace battleship{
|
||||
void updateCursor();
|
||||
void initDragbox();
|
||||
void removeDragbox();
|
||||
bool isGameObjSelectable(GameObject*, bool);
|
||||
void deselectUnits();
|
||||
void renderUnits();
|
||||
void updateSelectionBox();
|
||||
void updateDragBox();
|
||||
void updateStructureFrames();
|
||||
void castRayToTerrain();
|
||||
void issueOrder(Order::TYPE, std::vector<Order::Target>, bool);
|
||||
|
||||
+13
-47
@@ -24,6 +24,12 @@ namespace battleship{
|
||||
void GameObject::reinit(){
|
||||
placeAt(pos);
|
||||
orientAt(rot);
|
||||
|
||||
if(hitbox){
|
||||
Box *hbMesh = (Box*)hitbox->getMesh(0);
|
||||
hbMesh->setSize(Vector3(width, height, length));
|
||||
hbMesh->updateVerts(hbMesh->getMeshBase());
|
||||
}
|
||||
}
|
||||
|
||||
void GameObject::update(){
|
||||
@@ -46,14 +52,18 @@ namespace battleship{
|
||||
//TODO remove neccessity to create a material for an invisible mesh
|
||||
void GameObject::initHitbox(){
|
||||
Box *box = new Box(Vector3(width, height, length));
|
||||
box->setMaterial(new Material(Root::getSingleton()->getLibPath() + "texture"));
|
||||
box->setWireframe(false);
|
||||
box->setWireframe(true);
|
||||
|
||||
Material *mat = new Material(Root::getSingleton()->getLibPath() + "texture");
|
||||
mat->addBoolUniform("texturingEnabled", false);
|
||||
mat->addVec4Uniform("diffuseColor", Vector4(1, 1, 1, 1));
|
||||
box->setMaterial(mat);
|
||||
|
||||
sol::table gameObjTable = generateView()[GameObject::getGameObjTableName()][id + 1];
|
||||
sol::table offsetPosTable = gameObjTable["hitboxOffset"];
|
||||
hitbox = new Node(Vector3(offsetPosTable["x"], offsetPosTable["y"], offsetPosTable["z"]));
|
||||
hitbox->attachMesh(box);
|
||||
hitbox->setVisible(false);
|
||||
hitbox->setVisible(true);
|
||||
model->attachChild(hitbox);
|
||||
}
|
||||
|
||||
@@ -157,50 +167,6 @@ namespace battleship{
|
||||
}
|
||||
}
|
||||
|
||||
int GameObject::sortCorners(vector<Vector2> &cornersOnScreen, bool vertical, bool max){
|
||||
const int NUM_CORNERS = cornersOnScreen.size();
|
||||
int ans = 0;
|
||||
|
||||
for(int i = 0; i < NUM_CORNERS; i++){
|
||||
if(vertical && ((max && cornersOnScreen[ans].y < cornersOnScreen[i].y) || (!max && cornersOnScreen[ans].y > cornersOnScreen[i].y)))
|
||||
ans = i;
|
||||
else if(!vertical && ((max && cornersOnScreen[ans].x < cornersOnScreen[i].x) || (!max && cornersOnScreen[ans].x > cornersOnScreen[i].x)))
|
||||
ans = i;
|
||||
}
|
||||
|
||||
return ans;
|
||||
}
|
||||
|
||||
Vector2 GameObject::calculateSelectionRect(){
|
||||
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)
|
||||
};
|
||||
|
||||
vector<Vector2> cornersOnScreen;
|
||||
|
||||
for(int i = 0; i < NUM_CORNERS; i++){
|
||||
Vector3 cornerInWorld = leftVec * corners[i].x + upVec * corners[i].y + dirVec * corners[i].z;
|
||||
cornersOnScreen.push_back(spaceToScreen(cornerInWorld));
|
||||
}
|
||||
|
||||
int leftMostPointId = sortCorners(cornersOnScreen, false, false);
|
||||
int rightMostPointId = sortCorners(cornersOnScreen, false, true);
|
||||
int topMostPointId = sortCorners(cornersOnScreen, true, false);
|
||||
int bottomMostPointId = sortCorners(cornersOnScreen, true, true);
|
||||
|
||||
float sizeX = cornersOnScreen[rightMostPointId].x - cornersOnScreen[leftMostPointId].x;
|
||||
float sizeY = cornersOnScreen[bottomMostPointId].y - cornersOnScreen[topMostPointId].y;
|
||||
return Vector2(sizeX, sizeY);
|
||||
}
|
||||
|
||||
void GameObject::updateGameStats(Unit *targetUnit){
|
||||
if(targetUnit->getHealth() <= targetUnit->getDeathHp()){
|
||||
Player *targUnitPlayer = targetUnit->getPlayer();
|
||||
|
||||
@@ -26,7 +26,6 @@ namespace battleship{
|
||||
void placeAt(vb01::Vector3);
|
||||
void orientAt(vb01::Quaternion);
|
||||
std::string getGameObjTableName();
|
||||
vb01::Vector2 calculateSelectionRect();
|
||||
void updateGameStats(Unit*);
|
||||
static sf::Sound* prepareSfx(sf::SoundBuffer*, std::string);
|
||||
inline vb01::Vector2 getScreenPos(){return screenPos;}
|
||||
@@ -49,8 +48,6 @@ namespace battleship{
|
||||
inline Type getType(){return type;}
|
||||
inline vb01::Node* getHitbox(){return hitbox;}
|
||||
inline bool isRemove(){return remove;}
|
||||
private:
|
||||
int sortCorners(std::vector<vb01::Vector2>&, bool, bool);
|
||||
protected:
|
||||
virtual void initProperties();
|
||||
virtual void destroyModel();
|
||||
|
||||
@@ -288,7 +288,7 @@ namespace battleship{
|
||||
Unit::Unit(Player *player, int id, Vector3 pos, Quaternion rot, State st) : GameObject(GameObject::Type::UNIT, id, player, pos, rot), state(st){
|
||||
selectable = true;
|
||||
|
||||
initProperties();
|
||||
Unit::initProperties();
|
||||
initModel();
|
||||
initHitbox();
|
||||
initSound();
|
||||
@@ -426,7 +426,7 @@ namespace battleship{
|
||||
destroyModel();
|
||||
destroySound();
|
||||
|
||||
initProperties();
|
||||
Unit::initProperties();
|
||||
|
||||
initModel();
|
||||
initHitbox();
|
||||
|
||||
Reference in New Issue
Block a user