red command icons if not enough resource

orange icons if not enough resources for whole selection
This commit is contained in:
titiger 2019-10-21 00:46:06 +02:00
parent 2fd87e64c5
commit 011f38912e
6 changed files with 56 additions and 18 deletions

View File

@ -6811,12 +6811,8 @@ void Renderer::renderDisplay() {
//down images
for(int i=0; i<Display::downCellCount; ++i){
if(display->getDownImage(i)!=NULL){
if(display->getDownLighted(i)){
glColor3f(1.f, 1.f, 1.f);
}
else{
glColor3f(0.3f, 0.3f, 0.3f);
}
Vec3f c=display->getDownImageColor(i);
glColor3f(c.x,c.y,c.z );
int x= metrics.getDisplayX()+display->computeDownX(i);
int y= metrics.getDisplayY()+display->computeDownY(i);

View File

@ -77,7 +77,7 @@ void Display::clear(){
for(int i=0; i<downCellCount; ++i){
downImages[i]= NULL;
downLighted[i]= true;
downImageColor[i]= Vec3f(1.0f,1.0f,1.0f);
commandTypes[i]= NULL;
commandClasses[i]= ccNull;
}

View File

@ -28,6 +28,7 @@ using std::string;
using Shared::Graphics::Texture2D;
using Shared::Graphics::Vec4f;
using Shared::Graphics::Vec3f;
using Shared::Util::replaceBy;
namespace Glest{ namespace Game{
@ -55,7 +56,7 @@ private:
string infoText;
const Texture2D *upImages[upCellCount];
const Texture2D *downImages[downCellCount];
bool downLighted[downCellCount];
Vec3f downImageColor[downCellCount];
const CommandType *commandTypes[downCellCount];
CommandClass commandClasses[downCellCount];
int progressBar;
@ -77,7 +78,7 @@ public:
string getInfoText() const {return infoText;}
const Texture2D *getUpImage(int index) const {return upImages[index];}
const Texture2D *getDownImage(int index) const {return downImages[index];}
bool getDownLighted(int index) const {return downLighted[index];}
Vec3f getDownImageColor(int index) const {return downImageColor[index];}
const CommandType *getCommandType(int i) const {return commandTypes[i];}
CommandClass getCommandClass(int i) const {return commandClasses[i];}
Vec4f getColor() const;
@ -94,7 +95,9 @@ public:
void setDownImage(int i, const Texture2D *image) {downImages[i]= image;}
void setCommandType(int i, const CommandType *ct) {commandTypes[i]= ct;}
void setCommandClass(int i, const CommandClass cc) {commandClasses[i]= cc;}
void setDownLighted(int i, bool lighted) {downLighted[i]= lighted;}
void setDownLighted(int i, bool lighted) {downImageColor[i]=lighted?Vec3f(1.f, 1.f, 1.f):Vec3f(0.3f, 0.3f, 0.3);}
void setDownRedLighted(int i) {downImageColor[i]=Vec3f(1.0f, 0.0f, 0.0);}
void setDownOrangeLighted(int i) {downImageColor[i]=Vec3f(1.0f, 0.8f, 0.3);}
void setProgressBar(int i) {progressBar= i;}
void setDownSelectedPos(int i) {downSelectedPos= i;}

View File

@ -939,9 +939,7 @@ void Gui::computeDisplay(){
display.setDownLighted(meetingPointPos, true);
}
//printf("computeDisplay selection.isUniform() = %d\n",selection.isUniform());
if(selection.isUniform()) {
//printf("selection.isUniform()\n");
@ -958,17 +956,48 @@ void Gui::computeDisplay(){
}
//printf("computeDisplay i = %d displayPos = %d morphPos = %d ct->getClass() = %d [%s]\n",i,displayPos,morphPos,ct->getClass(),ct->getName().c_str());
const ProducibleType *produced= ct->getProduced();
int possibleAmount=1;
if(produced != NULL) {
possibleAmount= u->getFaction()->getAmountOfProducable(produced,ct);
}
display.setDownImage(displayPos, ct->getImage());
display.setCommandType(displayPos, ct);
display.setCommandClass(displayPos, ct->getClass());
display.setDownLighted(displayPos, u->getFaction()->reqsOk(ct));
bool reqOk=u->getFaction()->reqsOk(ct);
display.setDownLighted(displayPos,reqOk);
if (reqOk && produced != NULL) {
if (possibleAmount == 0) {
display.setDownRedLighted(displayPos);
} else if (selection.getCount() > possibleAmount) {
// orange colors just for command types that produce or morph units!!
const UnitType *unitType=NULL;
if (dynamic_cast<const MorphCommandType *>(ct) != NULL) {
unitType = dynamic_cast<const MorphCommandType *>(ct)->getMorphUnit();
} else if (dynamic_cast<const ProduceCommandType *>(ct) != NULL) {
unitType = dynamic_cast<const ProduceCommandType *>(ct)->getProducedUnit();
}
if (unitType != NULL) {
if (unitType->getMaxUnitCount() > 0) {
// check for maxUnitCount
int stillAllowed = unitType->getMaxUnitCount() - u->getFaction()->getCountForMaxUnitCount(unitType);
if (stillAllowed > possibleAmount) {
// enough resources to let morph/produce everything possible
display.setDownOrangeLighted(displayPos);
}
} else
// not enough resources to let all morph/produce
display.setDownOrangeLighted(displayPos);
}
}
}
}
}
}
else{
//printf("selection.isUniform() == FALSE\n");
//non uniform selection
int lastCommand= 0;
for(int i= 0; i < ccCount; ++i){

View File

@ -1249,7 +1249,7 @@ void Faction::applyCostsOnInterval(const ResourceType *rtApply) {
}
}
bool Faction::checkCosts(const ProducibleType *pt,const CommandType *ct) {
int Faction::getAmountOfProducable(const ProducibleType *pt,const CommandType *ct) {
assert(pt != NULL);
bool ignoreResourceCosts = false;
@ -1261,6 +1261,7 @@ bool Faction::checkCosts(const ProducibleType *pt,const CommandType *ct) {
//printf("Checking costs = %d for commandtype:\n%s\n",ignoreResourceCosts,mct->getDesc(NULL).c_str());
}
int maxAmount=INT_MAX;
if(ignoreResourceCosts == false) {
//for each unit cost check if enough resources
for(int i = 0; i < pt->getCostCount(); ++i) {
@ -1268,14 +1269,22 @@ bool Faction::checkCosts(const ProducibleType *pt,const CommandType *ct) {
int cost= pt->getCost(i)->getAmount();
if(cost > 0) {
int available= getResource(rt)->getAmount();
if(cost > available){
return false;
int possibleCount=available/cost;
if( maxAmount>possibleCount)
maxAmount=possibleCount;
if(maxAmount==0){
break;
}
}
}
}
return true;
return maxAmount;
}
bool Faction::checkCosts(const ProducibleType *pt,const CommandType *ct) {
return getAmountOfProducable(pt,ct)>0;
}
// ================== diplomacy ==================

View File

@ -316,6 +316,7 @@ public:
void deApplyStaticConsumption(const ProducibleType *p,const CommandType *ct);
void applyCostsOnInterval(const ResourceType *rtApply);
bool checkCosts(const ProducibleType *pt,const CommandType *ct);
int getAmountOfProducable(const ProducibleType *pt,const CommandType *ct);
//reqs
bool reqsOk(const RequirableType *rt) const;