Merge branch 'feat/hotkeys_rebase' into build/windows_cmake_msbuild
This commit is contained in:
commit
935be6fc8f
|
@ -149,7 +149,7 @@ the default keyboard values).
|
||||||
|
|
||||||
* Camera keyboard controls *
|
* Camera keyboard controls *
|
||||||
|
|
||||||
f => toggle free camera mode
|
y => toggle free camera mode
|
||||||
w => move camera up (free camera mode only)
|
w => move camera up (free camera mode only)
|
||||||
s => move camera down (free camera mode only)
|
s => move camera down (free camera mode only)
|
||||||
a => rotate camera left (free camera mode only)
|
a => rotate camera left (free camera mode only)
|
||||||
|
@ -185,21 +185,34 @@ n => show network status
|
||||||
|
|
||||||
* Hotkeys (game camera mode only) *
|
* Hotkeys (game camera mode only) *
|
||||||
|
|
||||||
a => activate attack command for selection
|
, => activate attack command for selection
|
||||||
s => issue stop command to selection
|
; => issue stop command to selection
|
||||||
i => select next idle harvester
|
i => select next idle harvester
|
||||||
b => select next building
|
b => select next building
|
||||||
d => select next damaged unit
|
u => select next damaged unit
|
||||||
t => select next storage unit
|
t => select next storage unit
|
||||||
r => rotate building before placement
|
r => rotate building before placement
|
||||||
|
|
||||||
|
Unit commands can be activated using the keyboard by pressing corresponding
|
||||||
|
keys in the grid layout:
|
||||||
|
|
||||||
|
+---+---+---+---+
|
||||||
|
| q | w | e | r |
|
||||||
|
+---+---+---+---+
|
||||||
|
| a | s | d | f |
|
||||||
|
+---+---+---+---+
|
||||||
|
| z | x | c | v |
|
||||||
|
+---+---+---+---+
|
||||||
|
|
||||||
|
The position of the command for the selected unit (or group) in the UI
|
||||||
|
button grid corresponds to the key in the same position in the grid above.
|
||||||
|
|
||||||
* Other Keys *
|
* Other Keys *
|
||||||
|
|
||||||
- + => adjust game speed (disabled in multiplayer)
|
- + => adjust game speed (disabled in multiplayer)
|
||||||
p => pause game (disabled in multiplayer)
|
p => pause game (disabled in multiplayer)
|
||||||
e => save screen shot to file
|
j => save screen shot to file
|
||||||
c => toggle ingame font color (and font shadow)
|
o => toggle ingame font color (and font shadow)
|
||||||
m => show faded mesages again
|
m => show faded mesages again
|
||||||
? => when DebugMode=true, display debug info
|
? => when DebugMode=true, display debug info
|
||||||
/ => toggle mouse pointer rendering mode (OS/MG)
|
/ => toggle mouse pointer rendering mode (OS/MG)
|
||||||
|
|
|
@ -3,15 +3,15 @@
|
||||||
RenderInGamePerformance=`
|
RenderInGamePerformance=`
|
||||||
RenderNetworkStatus=N
|
RenderNetworkStatus=N
|
||||||
ShowFullConsole=M
|
ShowFullConsole=M
|
||||||
Screenshot=E
|
Screenshot=J
|
||||||
FreeCameraMode=F
|
FreeCameraMode=Y
|
||||||
ResetCameraMode=space
|
ResetCameraMode=space
|
||||||
CameraModeLeft=left
|
CameraModeLeft=left
|
||||||
CameraModeRight=right
|
CameraModeRight=right
|
||||||
CameraModeUp=up
|
CameraModeUp=up
|
||||||
CameraModeDown=down
|
CameraModeDown=down
|
||||||
PauseGame=P
|
PauseGame=P
|
||||||
ChangeFontColor=C
|
ChangeFontColor=O
|
||||||
GameSpeedIncrease='+'
|
GameSpeedIncrease='+'
|
||||||
GameSpeedDecrease='-'
|
GameSpeedDecrease='-'
|
||||||
ExitKey=escape
|
ExitKey=escape
|
||||||
|
@ -30,16 +30,28 @@ CameraRotateLeft=A
|
||||||
CameraRotateRight=D
|
CameraRotateRight=D
|
||||||
CameraRotateUp=S
|
CameraRotateUp=S
|
||||||
CameraRotateDown=W
|
CameraRotateDown=W
|
||||||
|
CommandKey1=Q
|
||||||
|
CommandKey2=W
|
||||||
|
CommandKey3=E
|
||||||
|
CommandKey4=R
|
||||||
|
CommandKey5=A
|
||||||
|
CommandKey6=S
|
||||||
|
CommandKey7=D
|
||||||
|
CommandKey8=F
|
||||||
|
CommandKey9=Z
|
||||||
|
CommandKey10=X
|
||||||
|
CommandKey11=C
|
||||||
|
CommandKey12=V
|
||||||
HotKeyCenterCameraOnSelection=G
|
HotKeyCenterCameraOnSelection=G
|
||||||
HotKeySelectIdleHarvesterUnit=I
|
HotKeySelectIdleHarvesterUnit=I
|
||||||
HotKeySelectBuiltBuilding=B
|
HotKeySelectBuiltBuilding=B
|
||||||
HotKeyShowDebug=?
|
HotKeyShowDebug=?
|
||||||
HotKeyDumpWorldToLog=\
|
HotKeyDumpWorldToLog=\
|
||||||
HotKeyRotateUnitDuringPlacement=R
|
HotKeyRotateUnitDuringPlacement=R
|
||||||
HotKeySelectDamagedUnit=D
|
HotKeySelectDamagedUnit=U
|
||||||
HotKeySelectStoreUnit=T
|
HotKeySelectStoreUnit=T
|
||||||
HotKeySelectedUnitsAttack=A
|
HotKeySelectedUnitsAttack=,
|
||||||
HotKeySelectedUnitsStop=S
|
HotKeySelectedUnitsStop=;
|
||||||
HotKeyToggleOSMouseEnabled=/
|
HotKeyToggleOSMouseEnabled=/
|
||||||
ChatTeamMode=H
|
ChatTeamMode=H
|
||||||
ToggleHealthbars=#
|
ToggleHealthbars=#
|
||||||
|
|
|
@ -38,7 +38,7 @@ using namespace Shared::Util;
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Mouse3d
|
// class Mouse3d
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
const float Mouse3d::fadeSpeed= 1.f/50.f;
|
const float Mouse3d::fadeSpeed= 1.f/50.f;
|
||||||
|
@ -65,7 +65,7 @@ void Mouse3d::update(){
|
||||||
}
|
}
|
||||||
|
|
||||||
// ===============================
|
// ===============================
|
||||||
// class SelectionQuad
|
// class SelectionQuad
|
||||||
// ===============================
|
// ===============================
|
||||||
|
|
||||||
SelectionQuad::SelectionQuad(){
|
SelectionQuad::SelectionQuad(){
|
||||||
|
@ -89,7 +89,7 @@ void SelectionQuad::disable(){
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Gui
|
// class Gui
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
//constructor
|
//constructor
|
||||||
|
@ -97,10 +97,10 @@ Gui::Gui(){
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s] START\n",__FILE__,__FUNCTION__);
|
||||||
|
|
||||||
lastGroupRecall = -1;
|
lastGroupRecall = -1;
|
||||||
posObjWorld= Vec2i(54, 14);
|
posObjWorld= Vec2i(54, 14);
|
||||||
validPosObjWorld= false;
|
validPosObjWorld= false;
|
||||||
activeCommandType= NULL;
|
activeCommandType= NULL;
|
||||||
activeCommandClass= ccStop;
|
activeCommandClass= ccStop;
|
||||||
selectingBuilding= false;
|
selectingBuilding= false;
|
||||||
selectedBuildingFacing = CardinalDir(CardinalDir::NORTH);
|
selectedBuildingFacing = CardinalDir(CardinalDir::NORTH);
|
||||||
selectingPos= false;
|
selectingPos= false;
|
||||||
|
@ -149,8 +149,8 @@ void Gui::end(){
|
||||||
// ==================== get ====================
|
// ==================== get ====================
|
||||||
|
|
||||||
const UnitType *Gui::getBuilding() const{
|
const UnitType *Gui::getBuilding() const{
|
||||||
assert(selectingBuilding);
|
assert(selectingBuilding);
|
||||||
return choosenBuildingType;
|
return choosenBuildingType;
|
||||||
}
|
}
|
||||||
const Object *Gui::getSelectedResourceObject() const{
|
const Object *Gui::getSelectedResourceObject() const{
|
||||||
if(selectedResourceObjectPos.x==-1){
|
if(selectedResourceObjectPos.x==-1){
|
||||||
|
@ -196,17 +196,17 @@ bool Gui::isPlacingBuilding() const{
|
||||||
// ==================== set ====================
|
// ==================== set ====================
|
||||||
|
|
||||||
void Gui::invalidatePosObjWorld(){
|
void Gui::invalidatePosObjWorld(){
|
||||||
validPosObjWorld= false;
|
validPosObjWorld= false;
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== reset state ====================
|
// ==================== reset state ====================
|
||||||
|
|
||||||
void Gui::resetState(){
|
void Gui::resetState(){
|
||||||
selectingBuilding= false;
|
selectingBuilding= false;
|
||||||
selectedBuildingFacing = CardinalDir(CardinalDir::NORTH);
|
selectedBuildingFacing = CardinalDir(CardinalDir::NORTH);
|
||||||
selectingPos= false;
|
selectingPos= false;
|
||||||
selectingMeetingPoint= false;
|
selectingMeetingPoint= false;
|
||||||
activePos= invalidPos;
|
activePos= invalidPos;
|
||||||
activeCommandClass= ccStop;
|
activeCommandClass= ccStop;
|
||||||
activeCommandType= NULL;
|
activeCommandType= NULL;
|
||||||
}
|
}
|
||||||
|
@ -215,9 +215,9 @@ void Gui::resetState(){
|
||||||
|
|
||||||
void Gui::update(){
|
void Gui::update(){
|
||||||
|
|
||||||
if(selectionQuad.isEnabled() && selectionQuad.getPosUp().dist(selectionQuad.getPosDown())>minQuadSize){
|
if(selectionQuad.isEnabled() && selectionQuad.getPosUp().dist(selectionQuad.getPosDown())>minQuadSize){
|
||||||
computeSelected(false,false);
|
computeSelected(false,false);
|
||||||
}
|
}
|
||||||
mouse3d.update();
|
mouse3d.update();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -408,45 +408,58 @@ void Gui::hotKey(SDL_KeyboardEvent key) {
|
||||||
centerCameraOnSelection();
|
centerCameraOnSelection();
|
||||||
}
|
}
|
||||||
//else if(key == configKeys.getCharKey("HotKeySelectIdleHarvesterUnit")) {
|
//else if(key == configKeys.getCharKey("HotKeySelectIdleHarvesterUnit")) {
|
||||||
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectIdleHarvesterUnit"),key) == true) {
|
if(isKeyPressed(configKeys.getSDLKey("HotKeySelectIdleHarvesterUnit"),key) == true) {
|
||||||
selectInterestingUnit(iutIdleHarvester);
|
selectInterestingUnit(iutIdleHarvester);
|
||||||
}
|
}
|
||||||
//else if(key == configKeys.getCharKey("HotKeySelectBuiltBuilding")) {
|
//else if(key == configKeys.getCharKey("HotKeySelectBuiltBuilding")) {
|
||||||
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectBuiltBuilding"),key) == true) {
|
if(isKeyPressed(configKeys.getSDLKey("HotKeySelectBuiltBuilding"),key) == true) {
|
||||||
selectInterestingUnit(iutBuiltBuilding);
|
selectInterestingUnit(iutBuiltBuilding);
|
||||||
}
|
}
|
||||||
//else if(key == configKeys.getCharKey("HotKeyDumpWorldToLog")) {
|
//else if(key == configKeys.getCharKey("HotKeyDumpWorldToLog")) {
|
||||||
else if(isKeyPressed(configKeys.getSDLKey("HotKeyDumpWorldToLog"),key) == true) {
|
if(isKeyPressed(configKeys.getSDLKey("HotKeyDumpWorldToLog"),key) == true) {
|
||||||
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled == true) {
|
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled == true) {
|
||||||
std::string worldLog = world->DumpWorldToLog();
|
std::string worldLog = world->DumpWorldToLog();
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] worldLog dumped to [%s]\n",__FILE__,__FUNCTION__,__LINE__,worldLog.c_str());
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] worldLog dumped to [%s]\n",__FILE__,__FUNCTION__,__LINE__,worldLog.c_str());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//else if(key == configKeys.getCharKey("HotKeyRotateUnitDuringPlacement")){
|
//else if(key == configKeys.getCharKey("HotKeyRotateUnitDuringPlacement")){
|
||||||
else if(isKeyPressed(configKeys.getSDLKey("HotKeyRotateUnitDuringPlacement"),key) == true) {
|
if(isKeyPressed(configKeys.getSDLKey("HotKeyRotateUnitDuringPlacement"),key) == true) {
|
||||||
// Here the user triggers a unit rotation while placing a unit
|
// Here the user triggers a unit rotation while placing a unit
|
||||||
if(isPlacingBuilding()) {
|
if(isPlacingBuilding()) {
|
||||||
if(getBuilding()->getRotationAllowed()){
|
if(getBuilding()->getRotationAllowed()){
|
||||||
++selectedBuildingFacing;
|
++selectedBuildingFacing;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
//else if(key == configKeys.getCharKey("HotKeySelectDamagedUnit")) {
|
//else if(key == configKeys.getCharKey("HotKeySelectDamagedUnit")) {
|
||||||
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectDamagedUnit"),key) == true) {
|
if(isKeyPressed(configKeys.getSDLKey("HotKeySelectDamagedUnit"),key) == true) {
|
||||||
selectInterestingUnit(iutDamaged);
|
selectInterestingUnit(iutDamaged);
|
||||||
}
|
}
|
||||||
//else if(key == configKeys.getCharKey("HotKeySelectStoreUnit")) {
|
//else if(key == configKeys.getCharKey("HotKeySelectStoreUnit")) {
|
||||||
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectStoreUnit"),key) == true) {
|
if(isKeyPressed(configKeys.getSDLKey("HotKeySelectStoreUnit"),key) == true) {
|
||||||
selectInterestingUnit(iutStore);
|
selectInterestingUnit(iutStore);
|
||||||
}
|
}
|
||||||
//else if(key == configKeys.getCharKey("HotKeySelectedUnitsAttack")) {
|
//else if(key == configKeys.getCharKey("HotKeySelectedUnitsAttack")) {
|
||||||
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsAttack"),key) == true) {
|
if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsAttack"),key) == true) {
|
||||||
clickCommonCommand(ccAttack);
|
clickCommonCommand(ccAttack);
|
||||||
}
|
}
|
||||||
//else if(key == configKeys.getCharKey("HotKeySelectedUnitsStop")) {
|
//else if(key == configKeys.getCharKey("HotKeySelectedUnitsStop")) {
|
||||||
else if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsStop"),key) == true) {
|
if(isKeyPressed(configKeys.getSDLKey("HotKeySelectedUnitsStop"),key) == true) {
|
||||||
clickCommonCommand(ccStop);
|
clickCommonCommand(ccStop);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
for (int i=0; i<commandKeys; i++) {
|
||||||
|
string name = "CommandKey" + intToStr(i+1);
|
||||||
|
if(isKeyPressed(configKeys.getSDLKey(name.c_str()),key) == true) {
|
||||||
|
if(activeCommandType != NULL && activeCommandType->getClass() == ccBuild) {
|
||||||
|
mouseDownDisplayUnitBuild(i);
|
||||||
|
} else {
|
||||||
|
mouseDownDisplayUnitSkills(i);
|
||||||
|
}
|
||||||
|
computeDisplay();
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gui::switchToNextDisplayColor(){
|
void Gui::switchToNextDisplayColor(){
|
||||||
|
@ -472,8 +485,10 @@ void Gui::giveOneClickOrders(){
|
||||||
result= commander->tryGiveCommand(&selection, activeCommandClass, Vec2i(0), (Unit*)NULL, queueKeyDown);
|
result= commander->tryGiveCommand(&selection, activeCommandClass, Vec2i(0), (Unit*)NULL, queueKeyDown);
|
||||||
}
|
}
|
||||||
addOrdersResultToConsole(activeCommandClass, result);
|
addOrdersResultToConsole(activeCommandClass, result);
|
||||||
activeCommandType= NULL;
|
activeCommandType= NULL;
|
||||||
activeCommandClass= ccStop;
|
activeCommandClass= ccStop;
|
||||||
|
selectingPos= false;
|
||||||
|
activePos= invalidPos;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gui::giveDefaultOrders(int x, int y) {
|
void Gui::giveDefaultOrders(int x, int y) {
|
||||||
|
@ -543,7 +558,7 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared) {
|
||||||
}
|
}
|
||||||
|
|
||||||
bool queueKeyDown = isKeyDown(queueCommandKey);
|
bool queueKeyDown = isKeyDown(queueCommandKey);
|
||||||
//give orders to the units of this faction
|
//give orders to the units of this faction
|
||||||
if(selectingBuilding == false) {
|
if(selectingBuilding == false) {
|
||||||
if(selection.isUniform()) {
|
if(selection.isUniform()) {
|
||||||
result= commander->tryGiveCommand(&selection, activeCommandType,
|
result= commander->tryGiveCommand(&selection, activeCommandType,
|
||||||
|
@ -552,14 +567,14 @@ void Gui::giveTwoClickOrders(int x, int y , bool prepared) {
|
||||||
else {
|
else {
|
||||||
result= commander->tryGiveCommand(&selection, activeCommandClass,
|
result= commander->tryGiveCommand(&selection, activeCommandClass,
|
||||||
targetPos, targetUnit,queueKeyDown);
|
targetPos, targetUnit,queueKeyDown);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//selecting building
|
//selecting building
|
||||||
result= commander->tryGiveCommand(&selection,
|
result= commander->tryGiveCommand(&selection,
|
||||||
activeCommandType, posObjWorld, choosenBuildingType,
|
activeCommandType, posObjWorld, choosenBuildingType,
|
||||||
selectedBuildingFacing,queueKeyDown);
|
selectedBuildingFacing,queueKeyDown);
|
||||||
}
|
}
|
||||||
|
|
||||||
//graphical result
|
//graphical result
|
||||||
addOrdersResultToConsole(activeCommandClass, result);
|
addOrdersResultToConsole(activeCommandClass, result);
|
||||||
|
@ -585,7 +600,7 @@ void Gui::centerCameraOnSelection() {
|
||||||
}
|
}
|
||||||
|
|
||||||
void Gui::selectInterestingUnit(InterestingUnitType iut) {
|
void Gui::selectInterestingUnit(InterestingUnitType iut) {
|
||||||
const Faction *thisFaction = world->getThisFaction();
|
const Faction *thisFaction = world->getThisFaction();
|
||||||
const Unit* previousUnit = NULL;
|
const Unit* previousUnit = NULL;
|
||||||
bool previousFound = true;
|
bool previousFound = true;
|
||||||
|
|
||||||
|
@ -654,30 +669,7 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) {
|
||||||
|
|
||||||
//uniform selection
|
//uniform selection
|
||||||
if(selection.isUniform()) {
|
if(selection.isUniform()) {
|
||||||
const CommandType *ct = display.getCommandType(posDisplay);
|
const CommandType *ct = display.getCommandType(posDisplay);
|
||||||
|
|
||||||
// try to switch to next attack type
|
|
||||||
if(activeCommandClass == ccAttack && activeCommandType!=NULL) {
|
|
||||||
|
|
||||||
int maxI = unit->getType()->getCommandTypeCount();
|
|
||||||
int cmdTypeId = activeCommandType->getId();
|
|
||||||
int cmdTypeIdNext = cmdTypeId+1;
|
|
||||||
|
|
||||||
while(cmdTypeIdNext != cmdTypeId) {
|
|
||||||
if(cmdTypeIdNext >= maxI) {
|
|
||||||
cmdTypeIdNext = 0;
|
|
||||||
}
|
|
||||||
const CommandType *ctype = display.getCommandType(cmdTypeIdNext);
|
|
||||||
if(ctype != NULL && ctype->getClass() == ccAttack) {
|
|
||||||
if(ctype != NULL && unit->getFaction()->reqsOk(ctype)) {
|
|
||||||
posDisplay=cmdTypeIdNext;
|
|
||||||
ct = display.getCommandType(posDisplay);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
cmdTypeIdNext++;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if(ct != NULL && unit->getFaction()->reqsOk(ct)) {
|
if(ct != NULL && unit->getFaction()->reqsOk(ct)) {
|
||||||
activeCommandType= ct;
|
activeCommandType= ct;
|
||||||
|
@ -690,9 +682,7 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
else {//non uniform selection
|
||||||
//non uniform selection
|
|
||||||
else {
|
|
||||||
activeCommandType= NULL;
|
activeCommandType= NULL;
|
||||||
activeCommandClass= display.getCommandClass(posDisplay);
|
activeCommandClass= display.getCommandClass(posDisplay);
|
||||||
if (activeCommandClass == ccAttack) {
|
if (activeCommandClass == ccAttack) {
|
||||||
|
@ -702,14 +692,17 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) {
|
||||||
}
|
}
|
||||||
|
|
||||||
//give orders depending on command type
|
//give orders depending on command type
|
||||||
if(!selection.isEmpty()){
|
if(activeCommandClass != ccNull){
|
||||||
const CommandType *ct= selection.getUnit(0)->getType()->getFirstCtOfClass(activeCommandClass);
|
const CommandType *ct= selection.getUnit(0)->getType()->getFirstCtOfClass(activeCommandClass);
|
||||||
if (activeCommandClass == ccAttack) {
|
if (activeCommandClass == ccAttack) {
|
||||||
ct = selection.getUnitFromCC(ccAttack)->getType()->getFirstCtOfClass(activeCommandClass);
|
ct = selection.getUnitFromCC(ccAttack)->getType()->getFirstCtOfClass(activeCommandClass);
|
||||||
}
|
}
|
||||||
|
|
||||||
if(activeCommandType!=NULL && activeCommandType->getClass()==ccBuild){
|
if(activeCommandType!=NULL && activeCommandType->getClass()==ccBuild){
|
||||||
assert(selection.isUniform());
|
assert(selection.isUniform());
|
||||||
selectingBuilding= true;
|
selectingBuilding= true;
|
||||||
|
selectingPos= false;
|
||||||
|
activePos= invalidPos;
|
||||||
}
|
}
|
||||||
else if(ct->getClicks()==cOne){
|
else if(ct->getClicks()==cOne){
|
||||||
invalidatePosObjWorld();
|
invalidatePosObjWorld();
|
||||||
|
@ -719,7 +712,7 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) {
|
||||||
selectingPos= true;
|
selectingPos= true;
|
||||||
activePos= posDisplay;
|
activePos= posDisplay;
|
||||||
}
|
}
|
||||||
}
|
} else { posDisplay= invalidPos;}
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
activePos= posDisplay;
|
activePos= posDisplay;
|
||||||
|
@ -743,8 +736,8 @@ void Gui::mouseDownDisplayUnitBuild(int posDisplay) {
|
||||||
activeCommandType->getClass() == ccBuild) {
|
activeCommandType->getClass() == ccBuild) {
|
||||||
|
|
||||||
const BuildCommandType *bct = dynamic_cast<const BuildCommandType*>(activeCommandType);
|
const BuildCommandType *bct = dynamic_cast<const BuildCommandType*>(activeCommandType);
|
||||||
if(bct != NULL) {
|
if(bct != NULL && bct->getBuildingCount() > posDisplay) {
|
||||||
const UnitType *ut = bct->getBuilding(posDisplay);
|
const UnitType *ut = bct->getBuilding(posDisplay);
|
||||||
|
|
||||||
const Unit *unit = selection.getFrontUnit();
|
const Unit *unit = selection.getFrontUnit();
|
||||||
if(unit != NULL && unit->getFaction() != NULL) {
|
if(unit != NULL && unit->getFaction() != NULL) {
|
||||||
|
@ -754,7 +747,7 @@ void Gui::mouseDownDisplayUnitBuild(int posDisplay) {
|
||||||
|
|
||||||
choosenBuildingType = ut;
|
choosenBuildingType = ut;
|
||||||
selectingPos = true;
|
selectingPos = true;
|
||||||
selectedBuildingFacing = CardinalDir(CardinalDir::NORTH);
|
selectedBuildingFacing = CardinalDir(CardinalDir::NORTH);
|
||||||
activePos = posDisplay;
|
activePos = posDisplay;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -784,8 +777,14 @@ void Gui::computeInfoString(int posDisplay){
|
||||||
lastPosDisplay = posDisplay;
|
lastPosDisplay = posDisplay;
|
||||||
|
|
||||||
display.setInfoText(computeDefaultInfoString());
|
display.setInfoText(computeDefaultInfoString());
|
||||||
|
Config &configKeys = Config::getInstance(std::pair<ConfigType,ConfigType>(cfgMainKeys,cfgUserKeys));
|
||||||
|
string commandKeyName = "CommandKey" + intToStr(posDisplay+1);
|
||||||
|
|
||||||
if(posDisplay!=invalidPos && selection.isCommandable()){
|
if(posDisplay!=invalidPos && selection.isCommandable()){
|
||||||
|
string hotkey = "";
|
||||||
|
if (posDisplay < commandKeys) {
|
||||||
|
hotkey=lang.getString("HotKey")+": "+SDL_GetKeyName(configKeys.getSDLKey(commandKeyName.c_str())) +"\n\n";
|
||||||
|
}
|
||||||
if(!selectingBuilding){
|
if(!selectingBuilding){
|
||||||
if(posDisplay==cancelPos){
|
if(posDisplay==cancelPos){
|
||||||
display.setInfoText(lang.getString("Cancel"));
|
display.setInfoText(lang.getString("Cancel"));
|
||||||
|
@ -801,10 +800,10 @@ void Gui::computeInfoString(int posDisplay){
|
||||||
|
|
||||||
if(ct!=NULL){
|
if(ct!=NULL){
|
||||||
if(unit->getFaction()->reqsOk(ct)){
|
if(unit->getFaction()->reqsOk(ct)){
|
||||||
display.setInfoText(ct->getDesc(unit->getTotalUpgrade(),game->showTranslatedTechTree()));
|
display.setInfoText(hotkey+ct->getDesc(unit->getTotalUpgrade(),game->showTranslatedTechTree()));
|
||||||
}
|
}
|
||||||
else{
|
else{
|
||||||
display.setInfoText(ct->getReqDesc(game->showTranslatedTechTree()));
|
display.setInfoText(hotkey+ct->getReqDesc(game->showTranslatedTechTree()));
|
||||||
if(ct->getClass()==ccUpgrade){
|
if(ct->getClass()==ccUpgrade){
|
||||||
string text="";
|
string text="";
|
||||||
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(ct);
|
const UpgradeCommandType *uct= static_cast<const UpgradeCommandType*>(ct);
|
||||||
|
@ -814,20 +813,20 @@ void Gui::computeInfoString(int posDisplay){
|
||||||
else if(unit->getFaction()->getUpgradeManager()->isUpgraded(uct->getProducedUpgrade())){
|
else if(unit->getFaction()->getUpgradeManager()->isUpgraded(uct->getProducedUpgrade())){
|
||||||
text=lang.getString("AlreadyUpgraded")+"\n\n";
|
text=lang.getString("AlreadyUpgraded")+"\n\n";
|
||||||
}
|
}
|
||||||
display.setInfoText(text+ct->getReqDesc(game->showTranslatedTechTree()));
|
display.setInfoText(hotkey+text+ct->getReqDesc(game->showTranslatedTechTree()));
|
||||||
}
|
}
|
||||||
//locked by scenario
|
//locked by scenario
|
||||||
else if(ct->getClass()==ccProduce){
|
else if(ct->getClass()==ccProduce){
|
||||||
string text="";
|
string text="";
|
||||||
const ProduceCommandType *pct= static_cast<const ProduceCommandType*>(ct);
|
const ProduceCommandType *pct= static_cast<const ProduceCommandType*>(ct);
|
||||||
if(unit->getFaction()->isUnitLocked(pct->getProducedUnit())){
|
if(unit->getFaction()->isUnitLocked(pct->getProducedUnit())){
|
||||||
display.setInfoText(lang.getString("LockedByScenario")+"\n\n"+ct->getReqDesc(game->showTranslatedTechTree()));
|
display.setInfoText(hotkey+lang.getString("LockedByScenario")+"\n\n"+ct->getReqDesc(game->showTranslatedTechTree()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if(ct->getClass()==ccMorph){
|
else if(ct->getClass()==ccMorph){
|
||||||
const MorphCommandType *mct= static_cast<const MorphCommandType*>(ct);
|
const MorphCommandType *mct= static_cast<const MorphCommandType*>(ct);
|
||||||
if(unit->getFaction()->isUnitLocked(mct->getMorphUnit())){
|
if(unit->getFaction()->isUnitLocked(mct->getMorphUnit())){
|
||||||
display.setInfoText(lang.getString("LockedByScenario")+"\n\n"+ct->getReqDesc(game->showTranslatedTechTree()));
|
display.setInfoText(hotkey+lang.getString("LockedByScenario")+"\n\n"+ct->getReqDesc(game->showTranslatedTechTree()));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -859,19 +858,19 @@ void Gui::computeInfoString(int posDisplay){
|
||||||
const BuildCommandType *bct= static_cast<const BuildCommandType*>(activeCommandType);
|
const BuildCommandType *bct= static_cast<const BuildCommandType*>(activeCommandType);
|
||||||
const Unit *unit= selection.getFrontUnit();
|
const Unit *unit= selection.getFrontUnit();
|
||||||
if(unit->getFaction()->isUnitLocked(bct->getBuilding(posDisplay))){
|
if(unit->getFaction()->isUnitLocked(bct->getBuilding(posDisplay))){
|
||||||
display.setInfoText(lang.getString("LockedByScenario")+"\n\n"+bct->getBuilding(posDisplay)->getReqDesc(game->showTranslatedTechTree()));
|
display.setInfoText(hotkey+lang.getString("LockedByScenario")+"\n\n"+bct->getBuilding(posDisplay)->getReqDesc(game->showTranslatedTechTree()));
|
||||||
} else {
|
} else {
|
||||||
bool translatedValue= game->showTranslatedTechTree();
|
bool translatedValue= game->showTranslatedTechTree();
|
||||||
const UnitType *building=bct->getBuilding(posDisplay);
|
const UnitType *building=bct->getBuilding(posDisplay);
|
||||||
string str= lang.getString("BuildSpeed",(translatedValue == true ? "" : "english"))+": "+ intToStr(bct->getBuildSkillType()->getSpeed())+"\n";
|
string str= lang.getString("BuildSpeed",(translatedValue == true ? "" : "english"))+": "+ intToStr(bct->getBuildSkillType()->getSpeed())+"\n";
|
||||||
str+=""+Lang::getInstance().getString("TimeSteps",(translatedValue == true ? "" : "english"))+": "+intToStr(building->getProductionTime())+"\n";
|
str+=""+Lang::getInstance().getString("TimeSteps",(translatedValue == true ? "" : "english"))+": "+intToStr(building->getProductionTime())+"\n";
|
||||||
int64 speed=bct->getBuildSkillType()->getSpeed()+bct->getBuildSkillType()->getTotalSpeed(unit->getTotalUpgrade());
|
int64 speed=bct->getBuildSkillType()->getSpeed()+bct->getBuildSkillType()->getTotalSpeed(unit->getTotalUpgrade());
|
||||||
int64 time=building->getProductionTime();
|
int64 time=building->getProductionTime();
|
||||||
int64 seconds=time*100/speed;
|
int64 seconds=time*100/speed;
|
||||||
str+=""+Lang::getInstance().getString("Time",(translatedValue == true ? "" : "english"))+": "+intToStr(seconds);
|
str+=""+Lang::getInstance().getString("Time",(translatedValue == true ? "" : "english"))+": "+intToStr(seconds);
|
||||||
str+="\n\n";
|
str+="\n\n";
|
||||||
str+=building->getReqDesc(translatedValue);
|
str+=building->getReqDesc(translatedValue);
|
||||||
display.setInfoText(str);
|
display.setInfoText(hotkey+str);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -970,10 +969,16 @@ void Gui::computeDisplay(){
|
||||||
if(u->isBuilt()){
|
if(u->isBuilt()){
|
||||||
//printf("u->isBuilt()\n");
|
//printf("u->isBuilt()\n");
|
||||||
|
|
||||||
int morphPos= 8;
|
int morphPos= CommandHelper::getRowPos(crMorphs);
|
||||||
for(int i= 0; i < ut->getCommandTypeCount(); ++i){
|
for(int i= 0; i < ut->getCommandTypeSortedCount(); ++i){
|
||||||
int displayPos= i;
|
int displayPos= i;
|
||||||
const CommandType *ct= ut->getCommandType(i);
|
const CommandType *ct= ut->getCommandTypeSorted(i);
|
||||||
|
if(ct == NULL) {
|
||||||
|
display.setDownImage(displayPos, ut->getCancelImage());
|
||||||
|
display.setCommandType(displayPos, ct);
|
||||||
|
display.setDownLighted(displayPos,false);
|
||||||
|
continue;
|
||||||
|
}
|
||||||
if(ct->getClass() == ccMorph) {
|
if(ct->getClass() == ccMorph) {
|
||||||
displayPos= morphPos++;
|
displayPos= morphPos++;
|
||||||
}
|
}
|
||||||
|
@ -1022,27 +1027,40 @@ void Gui::computeDisplay(){
|
||||||
else{
|
else{
|
||||||
//printf("selection.isUniform() == FALSE\n");
|
//printf("selection.isUniform() == FALSE\n");
|
||||||
//non uniform selection
|
//non uniform selection
|
||||||
int lastCommand= 0;
|
int basicPos = CommandHelper::getRowPos(crBasics);
|
||||||
for(int i= 0; i < ccCount; ++i){
|
|
||||||
CommandClass cc= static_cast<CommandClass> (i);
|
|
||||||
|
|
||||||
//printf("computeDisplay i = %d cc = %d isshared = %d lastCommand = %d\n",i,cc,isSharedCommandClass(cc),lastCommand);
|
// First row is always empty
|
||||||
|
for (int i = 0; i < 5; i++) {
|
||||||
|
display.setDownImage(i, ut->getCancelImage());
|
||||||
|
display.setCommandType(i, NULL);
|
||||||
|
display.setDownLighted(i,false);
|
||||||
|
}
|
||||||
|
|
||||||
|
// only basics can be shared
|
||||||
|
for(auto &&cc : CommandHelper::getBasicsCC()){
|
||||||
|
|
||||||
|
//printf("computeDisplay i = %d cc = %d isshared = %d basicPos = %d\n",i,cc,isSharedCommandClass(cc),basicPos);
|
||||||
|
|
||||||
const Unit* attackingUnit = NULL;
|
const Unit* attackingUnit = NULL;
|
||||||
if (cc == ccAttack) {
|
if (cc == ccAttack) {
|
||||||
attackingUnit = selection.getUnitFromCC(ccAttack);
|
attackingUnit = selection.getUnitFromCC(ccAttack);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
auto ccPos = CommandHelper::getBasicPos(cc);
|
||||||
|
|
||||||
if((cc == ccAttack && attackingUnit != NULL) || (isSharedCommandClass(cc) && cc != ccBuild)){
|
if((cc == ccAttack && attackingUnit != NULL) || (isSharedCommandClass(cc) && cc != ccBuild)){
|
||||||
display.setDownLighted(lastCommand, true);
|
display.setDownLighted(basicPos + ccPos, true);
|
||||||
|
|
||||||
if (cc == ccAttack && attackingUnit != NULL) {
|
if (cc == ccAttack && attackingUnit != NULL) {
|
||||||
display.setDownImage(lastCommand, attackingUnit->getType()->getFirstCtOfClass(cc)->getImage());
|
display.setDownImage(basicPos + ccPos, attackingUnit->getType()->getFirstCtOfClass(cc)->getImage());
|
||||||
} else {
|
} else {
|
||||||
display.setDownImage(lastCommand, ut->getFirstCtOfClass(cc)->getImage());
|
display.setDownImage(basicPos + ccPos, ut->getFirstCtOfClass(cc)->getImage());
|
||||||
}
|
}
|
||||||
display.setCommandClass(lastCommand, cc);
|
display.setCommandClass(basicPos + ccPos, cc);
|
||||||
lastCommand++;
|
} else {
|
||||||
|
display.setDownImage(basicPos+ccPos, ut->getCancelImage());
|
||||||
|
display.setCommandType(basicPos+ccPos, NULL);
|
||||||
|
display.setDownLighted(basicPos+ccPos,false);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -1130,9 +1148,9 @@ int Gui::computePosDisplay(int x, int y){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
posDisplay= invalidPos;
|
posDisplay= invalidPos;
|
||||||
//printf("In [%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
//printf("In [%s:%s] Line: %d\n",__FILE__,__FUNCTION__,__LINE__);
|
||||||
}
|
}
|
||||||
|
|
||||||
//printf("computePosDisplay returning = %d\n",posDisplay);
|
//printf("computePosDisplay returning = %d\n",posDisplay);
|
||||||
|
|
||||||
|
@ -1141,64 +1159,64 @@ int Gui::computePosDisplay(int x, int y){
|
||||||
|
|
||||||
void Gui::addOrdersResultToConsole(CommandClass cc, std::pair<CommandResult,string> result) {
|
void Gui::addOrdersResultToConsole(CommandClass cc, std::pair<CommandResult,string> result) {
|
||||||
|
|
||||||
switch(result.first) {
|
switch(result.first) {
|
||||||
case crSuccess:
|
case crSuccess:
|
||||||
break;
|
break;
|
||||||
case crFailReqs:
|
case crFailReqs:
|
||||||
switch(cc){
|
switch(cc){
|
||||||
case ccBuild:
|
case ccBuild:
|
||||||
console->addStdMessage("BuildingNoReqs",result.second);
|
console->addStdMessage("BuildingNoReqs",result.second);
|
||||||
break;
|
break;
|
||||||
case ccProduce:
|
case ccProduce:
|
||||||
console->addStdMessage("UnitNoReqs",result.second);
|
console->addStdMessage("UnitNoReqs",result.second);
|
||||||
break;
|
break;
|
||||||
case ccMorph:
|
case ccMorph:
|
||||||
console->addStdMessage("MorphNoReqs",result.second);
|
console->addStdMessage("MorphNoReqs",result.second);
|
||||||
break;
|
break;
|
||||||
case ccUpgrade:
|
case ccUpgrade:
|
||||||
console->addStdMessage("UpgradeNoReqs",result.second);
|
console->addStdMessage("UpgradeNoReqs",result.second);
|
||||||
break;
|
break;
|
||||||
default:
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
break;
|
|
||||||
case crFailRes:
|
|
||||||
switch(cc){
|
|
||||||
case ccBuild:
|
|
||||||
console->addStdMessage("BuildingNoRes",result.second);
|
|
||||||
break;
|
|
||||||
case ccProduce:
|
|
||||||
console->addStdMessage("UnitNoRes",result.second);
|
|
||||||
break;
|
|
||||||
case ccMorph:
|
|
||||||
console->addStdMessage("MorphNoRes",result.second);
|
|
||||||
break;
|
|
||||||
case ccUpgrade:
|
|
||||||
console->addStdMessage("UpgradeNoRes",result.second);
|
|
||||||
break;
|
|
||||||
default:
|
default:
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
case crFailRes:
|
||||||
|
switch(cc){
|
||||||
|
case ccBuild:
|
||||||
|
console->addStdMessage("BuildingNoRes",result.second);
|
||||||
|
break;
|
||||||
|
case ccProduce:
|
||||||
|
console->addStdMessage("UnitNoRes",result.second);
|
||||||
|
break;
|
||||||
|
case ccMorph:
|
||||||
|
console->addStdMessage("MorphNoRes",result.second);
|
||||||
|
break;
|
||||||
|
case ccUpgrade:
|
||||||
|
console->addStdMessage("UpgradeNoRes",result.second);
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
break;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case crFailUndefined:
|
case crFailUndefined:
|
||||||
console->addStdMessage("InvalidOrder",result.second);
|
console->addStdMessage("InvalidOrder",result.second);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case crSomeFailed:
|
case crSomeFailed:
|
||||||
console->addStdMessage("SomeOrdersFailed",result.second);
|
console->addStdMessage("SomeOrdersFailed",result.second);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
bool Gui::isSharedCommandClass(CommandClass commandClass){
|
bool Gui::isSharedCommandClass(CommandClass commandClass){
|
||||||
for(int i=0; i<selection.getCount(); ++i){
|
for(int i=0; i<selection.getCount(); ++i){
|
||||||
const Unit *unit= selection.getUnit(i);
|
const Unit *unit= selection.getUnit(i);
|
||||||
const CommandType *ct= unit->getType()->getFirstCtOfClass(commandClass);
|
const CommandType *ct= unit->getType()->getFirstCtOfClass(commandClass);
|
||||||
if(ct==NULL || !unit->getFaction()->reqsOk(ct))
|
if(ct==NULL || !unit->getFaction()->reqsOk(ct))
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -88,13 +88,14 @@ public:
|
||||||
};
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Gui
|
// class Gui
|
||||||
//
|
//
|
||||||
/// In game GUI
|
/// In game GUI
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
class Gui {
|
class Gui {
|
||||||
public:
|
public:
|
||||||
|
static const int commandKeys= 12;
|
||||||
static const int maxSelBuff= 128*5;
|
static const int maxSelBuff= 128*5;
|
||||||
static const int upgradeDisplayIndex= 8;
|
static const int upgradeDisplayIndex= 8;
|
||||||
|
|
||||||
|
|
|
@ -31,6 +31,17 @@ using namespace Shared::Util;
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class CommandHelper
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
int CommandHelper::getBasicPos(CommandClass cc){
|
||||||
|
auto basics = getBasicsCC();
|
||||||
|
auto it = find(basics.begin(), basics.end(), cc);
|
||||||
|
if (it != basics.end())
|
||||||
|
return it - basics.begin();
|
||||||
|
else throw megaglest_runtime_error("Basics command have not class: " + intToStr(cc));
|
||||||
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class CommandType
|
// class CommandType
|
||||||
|
|
|
@ -54,6 +54,12 @@ enum CommandClass {
|
||||||
ccNull
|
ccNull
|
||||||
};
|
};
|
||||||
|
|
||||||
|
enum CommandRow {
|
||||||
|
crCores,
|
||||||
|
crBasics,
|
||||||
|
crMorphs,
|
||||||
|
};
|
||||||
|
|
||||||
enum Clicks {
|
enum Clicks {
|
||||||
cOne,
|
cOne,
|
||||||
cTwo
|
cTwo
|
||||||
|
@ -66,6 +72,17 @@ enum Queueability {
|
||||||
qAlways
|
qAlways
|
||||||
};
|
};
|
||||||
|
|
||||||
|
class CommandHelper {// TODO put magic numbers to settings
|
||||||
|
public:
|
||||||
|
inline static int getRowPos(CommandRow cr) { return cr * 4; }
|
||||||
|
static int getBasicPos(CommandClass cc);
|
||||||
|
inline static vector<CommandClass> getBasicsCC() { return { ccAttack, ccStop, ccMove, ccAttackStopped }; }
|
||||||
|
inline static vector<CommandClass> getCoresCC() { return { ccAttack, ccProduce, ccUpgrade, ccSwitchTeam, ccHarvest, ccRepair, ccBuild }; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
CommandHelper(){ }
|
||||||
|
};
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class CommandType
|
// class CommandType
|
||||||
//
|
//
|
||||||
|
|
|
@ -880,6 +880,7 @@ void UnitType::loaddd(int id,const string &dir, const TechTree *techTree,
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
sortCommandTypes(commandTypes);
|
||||||
|
|
||||||
computeFirstStOfClass();
|
computeFirstStOfClass();
|
||||||
computeFirstCtOfClass();
|
computeFirstCtOfClass();
|
||||||
|
@ -1236,6 +1237,75 @@ void UnitType::computeFirstCtOfClass() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void UnitType::sortCommandTypes(CommandTypes cts){
|
||||||
|
try{
|
||||||
|
CommandTypes ctCores, ctBasics = {NULL,NULL,NULL,NULL}, ctMorphs, ctAttack;
|
||||||
|
vector<int> basicNulls = {0,1,2,3};
|
||||||
|
|
||||||
|
//Morphs
|
||||||
|
for(int i = (int)cts.size(); i --> 0; ) {
|
||||||
|
if(cts[i]->getClass() == ccMorph) {
|
||||||
|
ctMorphs.insert(ctMorphs.begin(), cts[i]);
|
||||||
|
cts.erase(cts.begin() + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Attacks
|
||||||
|
CommandTypeFilter(cts, ctAttack, ccAttack);
|
||||||
|
if(ctAttack.size() > 0) {
|
||||||
|
ctBasics[CommandHelper::getBasicPos(ccAttack)] = ctAttack[0];// first attack to basics
|
||||||
|
basicNulls.erase(basicNulls.begin());
|
||||||
|
ctAttack.erase(ctAttack.begin());// another to cores, see below
|
||||||
|
}
|
||||||
|
|
||||||
|
//Basics
|
||||||
|
for(int i = (int)cts.size(); i --> 0; ) {
|
||||||
|
for(auto &&cc : CommandHelper::getBasicsCC()){
|
||||||
|
if(cc == ccAttack) continue;// we catch all attacks above
|
||||||
|
if(cts[i]->getClass() == cc) {
|
||||||
|
auto ccPos = CommandHelper::getBasicPos(cc);
|
||||||
|
ctBasics[ccPos] = cts[i];
|
||||||
|
cts.erase(cts.begin() + i);
|
||||||
|
basicNulls.erase(std::remove(basicNulls.begin(), basicNulls.end(), ccPos), basicNulls.end());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
//Cores
|
||||||
|
for(auto &&cc : CommandHelper::getCoresCC()){
|
||||||
|
if(cc == ccAttack) ctCores.insert(ctCores.end(), ctAttack.begin(), ctAttack.end());
|
||||||
|
else CommandTypeFilter(cts, ctCores, cc);
|
||||||
|
}
|
||||||
|
int nullCount = 4 - ctCores.size();
|
||||||
|
for(int i=0; i<nullCount; i++){
|
||||||
|
ctCores.push_back(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
if(nullCount < 0) {//magic: if we cant push all commands to cores
|
||||||
|
CommandTypes ctToBasics(ctCores.end() + nullCount, ctCores.end());
|
||||||
|
ctCores.resize(4);
|
||||||
|
for(int i = (int)ctToBasics.size(); i --> 0; ) {// we push it to basics
|
||||||
|
ctBasics[basicNulls[i]] = ctToBasics[i];
|
||||||
|
basicNulls.erase(basicNulls.begin() + i);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
commandTypesSorted.insert(commandTypesSorted.end(), ctCores.begin(), ctCores.end());
|
||||||
|
commandTypesSorted.insert(commandTypesSorted.end(), ctBasics.begin(), ctBasics.end());
|
||||||
|
commandTypesSorted.insert(commandTypesSorted.end(), ctMorphs.begin(), ctMorphs.end());
|
||||||
|
} catch(exception &ex){
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void UnitType::CommandTypeFilter(CommandTypes &input, CommandTypes &output, CommandClass cc){
|
||||||
|
std::copy_if(input.begin(), input.end(), std::back_inserter(output), [cc](CommandType* i) {
|
||||||
|
if(i->getClass() == cc)
|
||||||
|
return true;
|
||||||
|
else return false;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
const CommandType* UnitType::findCommandTypeById(int id) const{
|
const CommandType* UnitType::findCommandTypeById(int id) const{
|
||||||
const HarvestEmergencyReturnCommandType *result = dynamic_cast<const HarvestEmergencyReturnCommandType *>(ctHarvestEmergencyReturnCommandType.get());
|
const HarvestEmergencyReturnCommandType *result = dynamic_cast<const HarvestEmergencyReturnCommandType *>(ctHarvestEmergencyReturnCommandType.get());
|
||||||
if(result != NULL && id == result->getId()) {
|
if(result != NULL && id == result->getId()) {
|
||||||
|
@ -1260,6 +1330,15 @@ const CommandType *UnitType::getCommandType(int i) const {
|
||||||
return commandTypes[i];
|
return commandTypes[i];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const CommandType *UnitType::getCommandTypeSorted(int i) const {
|
||||||
|
if(i >= (int)commandTypesSorted.size()) {
|
||||||
|
char szBuf[8096]="";
|
||||||
|
snprintf(szBuf,8096,"In [%s::%s Line: %d] i >= commandTypesSorted.size(), i = %d, commandTypesSorted.size() = " MG_SIZE_T_SPECIFIER "",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,i,commandTypesSorted.size());
|
||||||
|
throw megaglest_runtime_error(szBuf);
|
||||||
|
}
|
||||||
|
return commandTypesSorted[i];
|
||||||
|
}
|
||||||
|
|
||||||
string UnitType::getCommandTypeListDesc() const {
|
string UnitType::getCommandTypeListDesc() const {
|
||||||
string desc = "Commands: ";
|
string desc = "Commands: ";
|
||||||
for(int i=0; i<getCommandTypeCount(); ++i){
|
for(int i=0; i<getCommandTypeCount(); ++i){
|
||||||
|
|
|
@ -215,6 +215,7 @@ private:
|
||||||
//info
|
//info
|
||||||
SkillTypes skillTypes;
|
SkillTypes skillTypes;
|
||||||
CommandTypes commandTypes;
|
CommandTypes commandTypes;
|
||||||
|
CommandTypes commandTypesSorted;
|
||||||
StoredResources storedResources;
|
StoredResources storedResources;
|
||||||
Levels levels;
|
Levels levels;
|
||||||
LootableResources lootableResources;
|
LootableResources lootableResources;
|
||||||
|
@ -273,10 +274,12 @@ public:
|
||||||
inline const ArmorType *getArmorType() const {return armorType;}
|
inline const ArmorType *getArmorType() const {return armorType;}
|
||||||
inline const SkillType *getSkillType(int i) const {return skillTypes[i];}
|
inline const SkillType *getSkillType(int i) const {return skillTypes[i];}
|
||||||
const CommandType *getCommandType(int i) const;
|
const CommandType *getCommandType(int i) const;
|
||||||
|
const CommandType *getCommandTypeSorted(int i) const;
|
||||||
inline const Level *getLevel(int i) const {return &levels[i];}
|
inline const Level *getLevel(int i) const {return &levels[i];}
|
||||||
const Level *getLevel(string name) const;
|
const Level *getLevel(string name) const;
|
||||||
inline int getSkillTypeCount() const {return (int)skillTypes.size();}
|
inline int getSkillTypeCount() const {return (int)skillTypes.size();}
|
||||||
inline int getCommandTypeCount() const {return (int)commandTypes.size();}
|
inline int getCommandTypeCount() const {return (int)commandTypes.size();}
|
||||||
|
inline int getCommandTypeSortedCount() const {return (int)commandTypesSorted.size();}
|
||||||
inline int getLevelCount() const {return (int)levels.size();}
|
inline int getLevelCount() const {return (int)levels.size();}
|
||||||
inline bool getLight() const {return light;}
|
inline bool getLight() const {return light;}
|
||||||
inline bool getRotationAllowed() const {return rotationAllowed;}
|
inline bool getRotationAllowed() const {return rotationAllowed;}
|
||||||
|
@ -361,6 +364,8 @@ public:
|
||||||
private:
|
private:
|
||||||
void computeFirstStOfClass();
|
void computeFirstStOfClass();
|
||||||
void computeFirstCtOfClass();
|
void computeFirstCtOfClass();
|
||||||
|
void sortCommandTypes(CommandTypes cts);
|
||||||
|
void CommandTypeFilter(CommandTypes &input, CommandTypes &output, CommandClass cc);
|
||||||
};
|
};
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
Loading…
Reference in New Issue