Allow a selected group to have the attack command even if some units … (#217)
* Allow a selected group to have the attack command even if some units don't have it * Add getUnitFromCC function * return NULL if getFirstCtOfClass founds no unit * Search for the unit containing the attack command in a non uniform selection Co-authored-by: Rampoina <Rampoina@protonmail.com>
This commit is contained in:
parent
94fa13cde7
commit
22a474b93b
|
@ -695,11 +695,18 @@ void Gui::mouseDownDisplayUnitSkills(int posDisplay) {
|
|||
else {
|
||||
activeCommandType= NULL;
|
||||
activeCommandClass= display.getCommandClass(posDisplay);
|
||||
if (activeCommandClass == ccAttack) {
|
||||
unit= selection.getUnitFromCC(ccAttack);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
//give orders depending on command type
|
||||
if(!selection.isEmpty()){
|
||||
const CommandType *ct= selection.getUnit(0)->getType()->getFirstCtOfClass(activeCommandClass);
|
||||
if (activeCommandClass == ccAttack) {
|
||||
ct = selection.getUnitFromCC(ccAttack)->getType()->getFirstCtOfClass(activeCommandClass);
|
||||
}
|
||||
if(activeCommandType!=NULL && activeCommandType->getClass()==ccBuild){
|
||||
assert(selection.isUniform());
|
||||
selectingBuilding= true;
|
||||
|
@ -832,8 +839,13 @@ void Gui::computeInfoString(int posDisplay){
|
|||
const UnitType *ut= selection.getFrontUnit()->getType();
|
||||
CommandClass cc= display.getCommandClass(posDisplay);
|
||||
if(cc!=ccNull){
|
||||
display.setInfoText(lang.getString("CommonCommand") + ": " + ut->getFirstCtOfClass(cc)->toString(true));
|
||||
}
|
||||
if (cc == ccAttack) {
|
||||
const Unit* attackingUnit = selection.getUnitFromCC(ccAttack);
|
||||
display.setInfoText(lang.getString("CommonCommand") + ": " + attackingUnit->getType()->getFirstCtOfClass(cc)->toString(true));
|
||||
} else {
|
||||
display.setInfoText(lang.getString("CommonCommand") + ": " + ut->getFirstCtOfClass(cc)->toString(true));
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -1016,9 +1028,19 @@ void Gui::computeDisplay(){
|
|||
|
||||
//printf("computeDisplay i = %d cc = %d isshared = %d lastCommand = %d\n",i,cc,isSharedCommandClass(cc),lastCommand);
|
||||
|
||||
if(isSharedCommandClass(cc) && cc != ccBuild){
|
||||
const Unit* attackingUnit = NULL;
|
||||
if (cc == ccAttack) {
|
||||
attackingUnit = selection.getUnitFromCC(ccAttack);
|
||||
}
|
||||
|
||||
if((cc == ccAttack && attackingUnit != NULL) || (isSharedCommandClass(cc) && cc != ccBuild)){
|
||||
display.setDownLighted(lastCommand, true);
|
||||
display.setDownImage(lastCommand, ut->getFirstCtOfClass(cc)->getImage());
|
||||
|
||||
if (cc == ccAttack && attackingUnit != NULL) {
|
||||
display.setDownImage(lastCommand, attackingUnit->getType()->getFirstCtOfClass(cc)->getImage());
|
||||
} else {
|
||||
display.setDownImage(lastCommand, ut->getFirstCtOfClass(cc)->getImage());
|
||||
}
|
||||
display.setCommandClass(lastCommand, cc);
|
||||
lastCommand++;
|
||||
}
|
||||
|
@ -1179,6 +1201,7 @@ bool Gui::isSharedCommandClass(CommandClass commandClass){
|
|||
return true;
|
||||
}
|
||||
|
||||
|
||||
void Gui::computeSelected(bool doubleClick, bool force){
|
||||
Selection::UnitContainer units;
|
||||
|
||||
|
|
|
@ -324,6 +324,16 @@ void Selection::removeUnitFromGroup(int groupIndex,int unitId) {
|
|||
}
|
||||
}
|
||||
|
||||
const Unit* Selection::getUnitFromCC(CommandClass commandClass){
|
||||
const Unit *unit = NULL;
|
||||
for(int i=0; i<(int)selectedUnits.size(); ++i){
|
||||
const Unit *unit= selectedUnits[i];
|
||||
const CommandType *ct= unit->getType()->getFirstCtOfClass(commandClass);
|
||||
if(ct != NULL && ct->getClass() == commandClass) return unit;
|
||||
}
|
||||
return unit;
|
||||
}
|
||||
|
||||
//vector<Unit*> Selection::getUnitsForGroup(int groupIndex) {
|
||||
// if(groupIndex < 0 || groupIndex >= maxGroups) {
|
||||
// throw megaglest_runtime_error("Invalid value for groupIndex = " + intToStr(groupIndex));
|
||||
|
|
|
@ -86,6 +86,7 @@ public:
|
|||
const Unit *getUnit(int i) const {return selectedUnits[i];}
|
||||
Unit *getUnitPtr(int i) {return selectedUnits[i];}
|
||||
const Unit *getFrontUnit() const {return selectedUnits.front();}
|
||||
const Unit *getUnitFromCC(CommandClass commandClass);
|
||||
Vec3f getRefPos() const;
|
||||
bool hasUnit(const Unit* unit) const;
|
||||
|
||||
|
|
|
@ -922,6 +922,7 @@ const Level *UnitType::getLevel(string name) const {
|
|||
|
||||
const CommandType *UnitType::getFirstCtOfClass(CommandClass commandClass) const{
|
||||
if(firstCommandTypeOfClass[commandClass] == NULL) {
|
||||
return NULL;
|
||||
//if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] commandClass = %d\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,commandClass);
|
||||
|
||||
/*
|
||||
|
|
Loading…
Reference in New Issue