2011-01-20 15:56:30 +00:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2011-12-14 07:40:48 +00:00
|
|
|
// Copyright (C) 2001-2008 Martiño Figueroa
|
2011-01-20 15:56:30 +00:00
|
|
|
//
|
|
|
|
// You can redistribute this code and/or modify it under
|
|
|
|
// the terms of the GNU General Public License as published
|
|
|
|
// by the Free Software Foundation; either version 2 of the
|
|
|
|
// License, or (at your option) any later version
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#ifndef _GLEST_GAME_SELECTION_
|
|
|
|
#define _GLEST_GAME_SELECTION_
|
|
|
|
|
2012-04-20 01:04:05 +00:00
|
|
|
#ifdef WIN32
|
|
|
|
#include <winsock2.h>
|
|
|
|
#include <winsock.h>
|
|
|
|
#endif
|
|
|
|
|
2011-01-20 15:56:30 +00:00
|
|
|
#include "unit.h"
|
|
|
|
#include <vector>
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
using std::vector;
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
class Gui;
|
2012-03-15 07:09:36 +00:00
|
|
|
class World;
|
2011-01-20 15:56:30 +00:00
|
|
|
|
2012-10-13 07:33:33 +00:00
|
|
|
class HighlightSpecialUnitInfo {
|
|
|
|
public:
|
|
|
|
float radius;
|
|
|
|
float thickness;
|
|
|
|
Vec4f color;
|
|
|
|
};
|
|
|
|
|
2011-01-20 15:56:30 +00:00
|
|
|
// =====================================================
|
|
|
|
// class Selection
|
|
|
|
//
|
|
|
|
/// List of selected units and groups
|
|
|
|
// =====================================================
|
|
|
|
|
2011-12-02 16:07:59 +00:00
|
|
|
class Selection: public UnitObserver {
|
2011-01-20 15:56:30 +00:00
|
|
|
public:
|
|
|
|
typedef vector<Unit*> UnitContainer;
|
|
|
|
typedef UnitContainer::const_iterator UnitIterator;
|
|
|
|
|
|
|
|
public:
|
2014-01-27 14:15:05 -08:00
|
|
|
static const int maxGroups = 10;
|
|
|
|
static const int maxUnits = 36;
|
2011-01-20 15:56:30 +00:00
|
|
|
|
|
|
|
private:
|
|
|
|
int factionIndex;
|
2011-05-06 08:44:50 +00:00
|
|
|
int teamIndex;
|
2014-01-27 14:15:05 -08:00
|
|
|
bool allowSharedTeamUnits;
|
2011-01-20 15:56:30 +00:00
|
|
|
UnitContainer selectedUnits;
|
|
|
|
UnitContainer groups[maxGroups];
|
|
|
|
Gui *gui;
|
|
|
|
|
|
|
|
public:
|
2011-12-02 16:07:59 +00:00
|
|
|
Selection() : UnitObserver() {
|
2014-01-27 14:15:05 -08:00
|
|
|
factionIndex = 0;
|
|
|
|
teamIndex = 0;
|
|
|
|
allowSharedTeamUnits = false;
|
|
|
|
gui = NULL;
|
2011-12-02 16:07:59 +00:00
|
|
|
}
|
2014-01-27 14:15:05 -08:00
|
|
|
void init(Gui *gui, int factionIndex, int teamIndex, bool allowSharedTeamUnits);
|
2011-01-20 15:56:30 +00:00
|
|
|
virtual ~Selection();
|
|
|
|
|
2016-10-17 03:00:37 +02:00
|
|
|
bool select(Unit *unit, bool addToSelection);
|
|
|
|
void select(const UnitContainer &units, bool addToSelection);
|
2011-01-20 15:56:30 +00:00
|
|
|
void unSelect(const UnitContainer &units);
|
2012-10-17 20:15:50 +00:00
|
|
|
void unSelect(int unitIndex);
|
2011-01-20 15:56:30 +00:00
|
|
|
void clear();
|
|
|
|
|
|
|
|
bool isEmpty() const {return selectedUnits.empty();}
|
|
|
|
bool isUniform() const;
|
|
|
|
bool isEnemy() const;
|
2011-05-06 08:44:50 +00:00
|
|
|
bool isObserver() const;
|
|
|
|
|
2011-01-20 15:56:30 +00:00
|
|
|
bool isCommandable() const;
|
|
|
|
bool isCancelable() const;
|
|
|
|
bool isMeetable() const;
|
2013-11-02 11:04:52 +00:00
|
|
|
int getCount() const {return (int)selectedUnits.size();}
|
2011-01-20 15:56:30 +00:00
|
|
|
const Unit *getUnit(int i) const {return selectedUnits[i];}
|
2012-09-24 17:13:27 +00:00
|
|
|
Unit *getUnitPtr(int i) {return selectedUnits[i];}
|
2011-01-20 15:56:30 +00:00
|
|
|
const Unit *getFrontUnit() const {return selectedUnits.front();}
|
2013-10-02 20:22:10 +00:00
|
|
|
Vec3f getRefPos() const;
|
2011-01-20 15:56:30 +00:00
|
|
|
bool hasUnit(const Unit* unit) const;
|
|
|
|
|
2015-11-03 01:58:19 +01:00
|
|
|
bool assignGroup(int groupIndex, bool clearGroup=true, const UnitContainer *pUnits=NULL);
|
|
|
|
bool addUnitToGroup(int groupIndex,Unit *unit);
|
2012-10-17 20:15:50 +00:00
|
|
|
void removeUnitFromGroup(int groupIndex,int UnitId);
|
2015-06-10 00:42:03 +02:00
|
|
|
void recallGroup(int groupIndex, bool clearSelection=true);
|
2011-01-20 15:56:30 +00:00
|
|
|
|
2012-10-17 20:15:50 +00:00
|
|
|
vector<Unit*> getUnitsForGroup(int groupIndex);
|
2011-01-20 15:56:30 +00:00
|
|
|
|
|
|
|
virtual void unitEvent(UnitObserver::Event event, const Unit *unit);
|
2014-01-27 14:15:05 -08:00
|
|
|
bool canSelectUnitFactionCheck(const Unit *unit) const;
|
2012-03-10 03:27:25 +00:00
|
|
|
|
|
|
|
virtual void saveGame(XmlNode *rootNode) const;
|
2012-03-15 07:09:36 +00:00
|
|
|
void loadGame(const XmlNode *rootNode, World *world);
|
2014-01-27 14:15:05 -08:00
|
|
|
|
2011-01-20 15:56:30 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
}}//end namespace
|
|
|
|
|
|
|
|
#endif
|