mirror of
https://github.com/ApfelTeeSaft/PlanetFleet.git
synced 2026-08-26 19:33:38 +00:00
order issuing and unit selection included in Player
This commit is contained in:
+26
-29
@@ -122,11 +122,7 @@ namespace battleship{
|
||||
}
|
||||
|
||||
void ActiveGameState::deselectUnits(){
|
||||
while(!selectedUnits.empty()){
|
||||
selectedUnits[0]->toggleSelection(false);
|
||||
selectedUnits.pop_back();
|
||||
}
|
||||
|
||||
mainPlayer->deselectUnits();
|
||||
removeStructtureFrames();
|
||||
placingStructures = false;
|
||||
}
|
||||
@@ -153,7 +149,7 @@ namespace battleship{
|
||||
if(!shiftPressed)
|
||||
deselectUnits();
|
||||
|
||||
selectedUnits.push_back(u);
|
||||
mainPlayer->selectUnit(u);
|
||||
u->toggleSelection(true);
|
||||
}
|
||||
}
|
||||
@@ -329,24 +325,9 @@ namespace battleship{
|
||||
targets[i + 1] = targets[i];
|
||||
|
||||
LineRenderer *lineRenderer = LineRenderer::getSingleton();
|
||||
Map *map = Map::getSingleton();
|
||||
|
||||
for (int i = 0; i < selectedUnits.size(); ++i) {
|
||||
Unit *u = selectedUnits[i];
|
||||
|
||||
if(u->getType() == UnitType::UNDERWATER && o.type == Order::TYPE::MOVE){
|
||||
for(int j = 1; j < map->getNumTerrainObjects(); j++){
|
||||
if(map->isPointWithinTerrainObject(u->getPos(), j) && map->isPointWithinTerrainObject(o.targets[i].pos, j)){
|
||||
vector<Ray::CollisionResult> res;
|
||||
Vector3 pos = u->getPos();
|
||||
Ray::retrieveCollisions(Vector3(pos.x, map->getTerrainObject(0).size.y, pos.z), Vector3(0, -1, 0), map->getTerrainObject(0).node->getChild(0), res);
|
||||
Ray::sortResults(res);
|
||||
o.targets[i].pos.y = res[0].pos.y + depth * (map->getTerrainObject(j).pos.y - res[0].pos.y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
for (int i = 0; i < mainPlayer->getNumSelectedUnits(); ++i) {
|
||||
Unit *u = mainPlayer->getSelectedUnit(i);
|
||||
lineRenderer->addLine(u->getPos(), o.targets[i].pos, color);
|
||||
vector<LineRenderer::Line> lines = lineRenderer->getLines();
|
||||
o.line = lines[lines.size() - 1];
|
||||
@@ -391,6 +372,22 @@ namespace battleship{
|
||||
mainPlayer->addUnit(unit);
|
||||
}
|
||||
|
||||
Map *map = Map::getSingleton();
|
||||
|
||||
for(Unit *u : mainPlayer->getSelectedUnits())
|
||||
if(u->getType() == UnitType::UNDERWATER){
|
||||
for(int i = 1; i < map->getNumTerrainObjects(); i++){
|
||||
if(map->isPointWithinTerrainObject(u->getPos(), i) && map->isPointWithinTerrainObject(results[0].pos, i)){
|
||||
vector<Ray::CollisionResult> res;
|
||||
Vector3 pos = u->getPos();
|
||||
Ray::retrieveCollisions(Vector3(pos.x, map->getTerrainObject(0).size.y, pos.z), Vector3(0, -1, 0), map->getTerrainObject(0).node->getChild(0), res);
|
||||
Ray::sortResults(res);
|
||||
results[0].pos.y = res[0].pos.y + depth * (map->getTerrainObject(i).pos.y - res[0].pos.y);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
targets.push_back(Order::Target((it != unitData.end() ? unitData[node] : unit), results[0].pos));
|
||||
}
|
||||
}
|
||||
@@ -406,7 +403,7 @@ namespace battleship{
|
||||
if (isPressed) {
|
||||
clickPoint = getCursorPos();
|
||||
|
||||
if (!selectedUnits.empty()){
|
||||
if (mainPlayer->getNumSelectedUnits() > 0){
|
||||
addTarget();
|
||||
|
||||
if(!(targets.empty() || selectingPatrolPoints)){
|
||||
@@ -451,7 +448,7 @@ namespace battleship{
|
||||
lookingAround = isPressed;
|
||||
break;
|
||||
case Bind::HALT:
|
||||
for (Unit *u : selectedUnits)
|
||||
for (Unit *u : mainPlayer->getSelectedUnits())
|
||||
u->halt();
|
||||
break;
|
||||
//TODO reimplement submarine diving mechanic
|
||||
@@ -493,13 +490,13 @@ namespace battleship{
|
||||
int group = bind - Bind::GROUP_0;
|
||||
|
||||
if(controlPressed)
|
||||
unitGroups[group] = selectedUnits;
|
||||
unitGroups[group] = mainPlayer->getSelectedUnits();
|
||||
else{
|
||||
if(!shiftPressed)
|
||||
selectedUnits = unitGroups[group];
|
||||
mainPlayer->selectUnits(unitGroups[group]);
|
||||
else
|
||||
for(Unit *u : unitGroups[group])
|
||||
selectedUnits.push_back(u);
|
||||
mainPlayer->selectUnit(u);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -509,7 +506,7 @@ namespace battleship{
|
||||
if(isPressed){
|
||||
bool engineersSelected = false;
|
||||
|
||||
for(Unit *u : selectedUnits)
|
||||
for(Unit *u : mainPlayer->getSelectedUnits())
|
||||
if(u->getUnitClass() == UnitClass::ENGINEER){
|
||||
engineersSelected = true;
|
||||
break;
|
||||
|
||||
+1
-2
@@ -34,7 +34,6 @@ namespace battleship{
|
||||
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;}
|
||||
inline std::vector<Unit*>& getUnitGroup(int i){return unitGroups[i];}
|
||||
private:
|
||||
void initDragbox();
|
||||
@@ -60,7 +59,7 @@ namespace battleship{
|
||||
vb01::Vector2 clickPoint;
|
||||
std::vector<vb01::Vector2> unitScreenPosVec;
|
||||
std::vector<vb01::Node*> unitLightNodes;
|
||||
std::vector<Unit*> unitGroups[9], selectedUnits;
|
||||
std::vector<Unit*> unitGroups[9];
|
||||
std::vector<Order::Target> targets;
|
||||
bool isSelectionBox = false, shiftPressed = false, controlPressed = false, selectingPatrolPoints = false, selectingGuidedMissileTarget = false, lookingAround = false, placingStructures = false, rotatingStructure = false;
|
||||
int playerId, zooms = 0;
|
||||
|
||||
+4
-2
@@ -210,7 +210,7 @@ namespace battleship{
|
||||
u->update();
|
||||
else{
|
||||
int selectedId = -1;
|
||||
std::vector<Unit*> &units = p->getUnits(), &selectedUnits = activeState->getSelectedUnits();
|
||||
std::vector<Unit*> &units = p->getUnits();
|
||||
units.erase(units.begin() + i);
|
||||
|
||||
for(int j = 0; j < maxNumGroups; j++){
|
||||
@@ -225,12 +225,14 @@ namespace battleship{
|
||||
group.erase(group.begin() + id);
|
||||
}
|
||||
|
||||
const vector<Unit*> &selectedUnits = mainPlayer->getSelectedUnits();
|
||||
|
||||
for(int j = 0; j < selectedUnits.size() && selectedId == -1; j++)
|
||||
if(selectedUnits[j] == u)
|
||||
selectedId = j;
|
||||
|
||||
if(selectedId != -1)
|
||||
selectedUnits.erase(selectedUnits.begin() + selectedId);
|
||||
mainPlayer->deselectUnit(selectedId);
|
||||
|
||||
delete u;
|
||||
}
|
||||
|
||||
+26
@@ -1,6 +1,7 @@
|
||||
#include "player.h"
|
||||
|
||||
using namespace vb01;
|
||||
using namespace std;
|
||||
|
||||
namespace battleship{
|
||||
Player::Player(int difficulty, int faction, Vector3 spawnPoint) {
|
||||
@@ -15,6 +16,19 @@ namespace battleship{
|
||||
void Player::update() {
|
||||
}
|
||||
|
||||
void Player::issueOrder(Order::TYPE type, vector<Order::Target> targets, bool append){
|
||||
Order order;
|
||||
order.type = type;
|
||||
order.targets = targets;
|
||||
|
||||
for(Unit *u : selectedUnits){
|
||||
if(append)
|
||||
u->addOrder(order);
|
||||
else
|
||||
u->setOrder(order);
|
||||
}
|
||||
}
|
||||
|
||||
bool Player::isThisPlayersUnit(Unit *u) {
|
||||
bool foundUnit = false;
|
||||
|
||||
@@ -27,4 +41,16 @@ namespace battleship{
|
||||
} else
|
||||
return false;
|
||||
}
|
||||
|
||||
void Player::deselectUnit(int i){
|
||||
selectedUnits[i]->toggleSelection(false);
|
||||
selectedUnits.erase(selectedUnits.begin() + i);
|
||||
}
|
||||
|
||||
void Player::deselectUnits(){
|
||||
for(Unit *u : selectedUnits)
|
||||
u->toggleSelection(false);
|
||||
|
||||
selectedUnits.clear();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -13,7 +13,15 @@ namespace battleship{
|
||||
Player(int, int, vb01::Vector3 = vb01::Vector3::VEC_ZERO);
|
||||
~Player();
|
||||
void update();
|
||||
void issueOrder(Order::TYPE, std::vector<Order::Target>, bool);
|
||||
void deselectUnit(int);
|
||||
void deselectUnits();
|
||||
bool isThisPlayersUnit(Unit*);
|
||||
const inline std::vector<Unit*>& getSelectedUnits(){return selectedUnits;}
|
||||
inline Unit* getSelectedUnit(int i){return selectedUnits[i];}
|
||||
inline int getNumSelectedUnits(){return selectedUnits.size();}
|
||||
inline void selectUnit(Unit *u){selectedUnits.push_back(u);}
|
||||
inline void selectUnits(std::vector<Unit*> units){selectedUnits = units;}
|
||||
inline void addUnit(Unit *u){units.push_back(u);}
|
||||
inline Unit* getUnit(int i){return units[i];}
|
||||
inline std::vector<Unit*>& getUnits(){return units;}
|
||||
@@ -25,7 +33,7 @@ namespace battleship{
|
||||
inline vb01::Vector3 getSpawnPoint(){return spawnPoint;}
|
||||
private:
|
||||
int credits, faction, difficulty,side,id;
|
||||
std::vector<Unit*> units;
|
||||
std::vector<Unit*> units, selectedUnits;
|
||||
vb01::Vector3 spawnPoint;
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user