new attribute MaxUnitCount in units and yellow select circle for allies
This commit is contained in:
parent
acd2359096
commit
8e281e2faf
|
@ -131,4 +131,4 @@ list<Vec2i>* NodePool::getClosedNodes() {
|
||||||
|
|
||||||
#endif // _GAE_DEBUG_EDITION_
|
#endif // _GAE_DEBUG_EDITION_
|
||||||
|
|
||||||
}}
|
}}
|
||||||
|
|
|
@ -1758,6 +1758,9 @@ void Renderer::renderSelectionEffects(){
|
||||||
if(world->getThisFactionIndex()==unit->getFactionIndex()){
|
if(world->getThisFactionIndex()==unit->getFactionIndex()){
|
||||||
glColor4f(0, unit->getHpRatio(), 0, 0.3f);
|
glColor4f(0, unit->getHpRatio(), 0, 0.3f);
|
||||||
}
|
}
|
||||||
|
else if ( world->getThisTeamIndex()==unit->getTeam()){
|
||||||
|
glColor4f(unit->getHpRatio(), unit->getHpRatio(), 0, 0.3f);
|
||||||
|
}
|
||||||
else{
|
else{
|
||||||
glColor4f(unit->getHpRatio(), 0, 0, 0.3f);
|
glColor4f(unit->getHpRatio(), 0, 0, 0.3f);
|
||||||
}
|
}
|
||||||
|
|
|
@ -133,7 +133,7 @@ void Faction::finishUpgrade(const UpgradeType *ut){
|
||||||
|
|
||||||
// ==================== reqs ====================
|
// ==================== reqs ====================
|
||||||
|
|
||||||
//checks if all required units and upgrades are present
|
//checks if all required units and upgrades are present and maxUnitCount is within limit
|
||||||
bool Faction::reqsOk(const RequirableType *rt) const{
|
bool Faction::reqsOk(const RequirableType *rt) const{
|
||||||
assert(rt != NULL);
|
assert(rt != NULL);
|
||||||
//required units
|
//required units
|
||||||
|
@ -158,10 +158,38 @@ bool Faction::reqsOk(const RequirableType *rt) const{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if(dynamic_cast<const CommandType *>(rt) != NULL ){
|
||||||
|
const CommandType *ct=(CommandType *) rt;
|
||||||
|
if(ct->getProduced() != NULL && dynamic_cast<const UnitType *>(ct->getProduced()) != NULL ){
|
||||||
|
|
||||||
|
const UnitType *producedUnitType= (UnitType *) ct->getProduced();
|
||||||
|
if(producedUnitType->getMaxUnitCount()>0){
|
||||||
|
if(producedUnitType->getMaxUnitCount()<=getCountForMaxUnitCount(producedUnitType)){
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int Faction::getCountForMaxUnitCount(const UnitType *unitType) const{
|
||||||
|
int count=0;
|
||||||
|
//calculate current unit count
|
||||||
|
for(int j=0; j<getUnitCount(); ++j){
|
||||||
|
Unit *unit= getUnit(j);
|
||||||
|
const UnitType *currentUt= unit->getType();
|
||||||
|
if(unitType==currentUt && unit->isOperative()){
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
//check if there is any command active which already produces this unit
|
||||||
|
count=count+unit->getCountOfProducedUnits(unitType);
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
bool Faction::reqsOk(const CommandType *ct) const{
|
bool Faction::reqsOk(const CommandType *ct) const{
|
||||||
assert(ct != NULL);
|
assert(ct != NULL);
|
||||||
if(ct->getProduced()!=NULL && !reqsOk(ct->getProduced())){
|
if(ct->getProduced()!=NULL && !reqsOk(ct->getProduced())){
|
||||||
|
|
|
@ -122,6 +122,8 @@ public:
|
||||||
//reqs
|
//reqs
|
||||||
bool reqsOk(const RequirableType *rt) const;
|
bool reqsOk(const RequirableType *rt) const;
|
||||||
bool reqsOk(const CommandType *ct) const;
|
bool reqsOk(const CommandType *ct) const;
|
||||||
|
int getCountForMaxUnitCount(const UnitType *unitType) const;
|
||||||
|
|
||||||
|
|
||||||
//diplomacy
|
//diplomacy
|
||||||
bool isAlly(const Faction *faction);
|
bool isAlly(const Faction *faction);
|
||||||
|
|
|
@ -648,6 +648,22 @@ unsigned int Unit::getCommandSize() const{
|
||||||
return commands.size();
|
return commands.size();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//return current command, assert that there is always one command
|
||||||
|
int Unit::getCountOfProducedUnits(const UnitType *ut) const{
|
||||||
|
int count=0;
|
||||||
|
for(Commands::const_iterator it= commands.begin(); it!=commands.end(); ++it){
|
||||||
|
const CommandType* ct=(*it)->getCommandType();
|
||||||
|
if(ct->getClass()==ccProduce || ct->getClass()==ccMorph || ct->getClass()==ccBuild ){
|
||||||
|
const UnitType *producedUnitType= static_cast<const UnitType*>(ct->getProduced());
|
||||||
|
if(producedUnitType==ut)
|
||||||
|
{
|
||||||
|
count++;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return count;
|
||||||
|
}
|
||||||
|
|
||||||
#define deleteSingleCommand(command) {\
|
#define deleteSingleCommand(command) {\
|
||||||
undoCommand(command);\
|
undoCommand(command);\
|
||||||
delete command;\
|
delete command;\
|
||||||
|
@ -1097,7 +1113,14 @@ string Unit::getDesc() const{
|
||||||
//str+="Pos: "+v2iToStr(pos)+"\n";
|
//str+="Pos: "+v2iToStr(pos)+"\n";
|
||||||
|
|
||||||
//hp
|
//hp
|
||||||
string str= "\n" + lang.get("Hp")+ ": " + intToStr(hp) + "/" + intToStr(type->getTotalMaxHp(&totalUpgrade));
|
string str= "\n";
|
||||||
|
|
||||||
|
//maxUnitCount
|
||||||
|
if(type->getMaxUnitCount()>0){
|
||||||
|
str += lang.get("MaxUnitCount")+ ": " + intToStr(faction->getCountForMaxUnitCount(type)) + "/" + intToStr(type->getMaxUnitCount());
|
||||||
|
}
|
||||||
|
|
||||||
|
str += "\n"+lang.get("Hp")+ ": " + intToStr(hp) + "/" + intToStr(type->getTotalMaxHp(&totalUpgrade));
|
||||||
if(type->getHpRegeneration()!=0){
|
if(type->getHpRegeneration()!=0){
|
||||||
str+= " (" + lang.get("Regeneration") + ": " + intToStr(type->getHpRegeneration()) + ")";
|
str+= " (" + lang.get("Regeneration") + ": " + intToStr(type->getHpRegeneration()) + ")";
|
||||||
}
|
}
|
||||||
|
@ -1336,7 +1359,7 @@ CommandResult Unit::checkCommand(Command *command) const{
|
||||||
}
|
}
|
||||||
if(!faction->checkCosts(builtUnit)){
|
if(!faction->checkCosts(builtUnit)){
|
||||||
return crFailRes;
|
return crFailRes;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
//upgrade command specific, check that upgrade is not upgraded
|
//upgrade command specific, check that upgrade is not upgraded
|
||||||
|
|
|
@ -49,6 +49,7 @@ enum CommandResult{
|
||||||
crSuccess,
|
crSuccess,
|
||||||
crFailRes,
|
crFailRes,
|
||||||
crFailReqs,
|
crFailReqs,
|
||||||
|
crFailUnitCount,
|
||||||
crFailUndefined,
|
crFailUndefined,
|
||||||
crSomeFailed
|
crSomeFailed
|
||||||
};
|
};
|
||||||
|
@ -342,6 +343,7 @@ public:
|
||||||
//command related
|
//command related
|
||||||
bool anyCommand() const;
|
bool anyCommand() const;
|
||||||
Command *getCurrCommand() const;
|
Command *getCurrCommand() const;
|
||||||
|
int getCountOfProducedUnits(const UnitType *ut) const;
|
||||||
unsigned int getCommandSize() const;
|
unsigned int getCommandSize() const;
|
||||||
CommandResult giveCommand(Command *command, bool tryQueue = false); //give a command
|
CommandResult giveCommand(Command *command, bool tryQueue = false); //give a command
|
||||||
CommandResult finishCommand(); //command finished
|
CommandResult finishCommand(); //command finished
|
||||||
|
|
|
@ -601,7 +601,7 @@ string ProduceCommandType::getDesc(const TotalUpgrade *totalUpgrade) const{
|
||||||
}
|
}
|
||||||
|
|
||||||
str+= "\n" + getProducedUnit()->getReqDesc();
|
str+= "\n" + getProducedUnit()->getReqDesc();
|
||||||
|
|
||||||
return str;
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,117 @@
|
||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||||
|
//
|
||||||
|
// 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_ELEMENTTYPE_H_
|
||||||
|
#define _GLEST_GAME_ELEMENTTYPE_H_
|
||||||
|
|
||||||
|
#include <vector>
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
#include "texture.h"
|
||||||
|
#include "resource.h"
|
||||||
|
|
||||||
|
using std::vector;
|
||||||
|
using std::string;
|
||||||
|
|
||||||
|
using Shared::Graphics::Texture2D;
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
class UpgradeType;
|
||||||
|
class TechTree;
|
||||||
|
class UnitType;
|
||||||
|
class UpgradeType;
|
||||||
|
class DisplayableType;
|
||||||
|
class ResourceType;
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class DisplayableType
|
||||||
|
//
|
||||||
|
/// Base class for anything that has a name and a portrait
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class DisplayableType{
|
||||||
|
protected:
|
||||||
|
string name; //name
|
||||||
|
Texture2D *image; //portrait
|
||||||
|
|
||||||
|
public:
|
||||||
|
DisplayableType();
|
||||||
|
virtual ~DisplayableType(){};
|
||||||
|
|
||||||
|
//get
|
||||||
|
string getName() const {return name;}
|
||||||
|
const Texture2D *getImage() const {return image;}
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class RequirableType
|
||||||
|
//
|
||||||
|
/// Base class for anything that has requirements
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class RequirableType: public DisplayableType{
|
||||||
|
private:
|
||||||
|
typedef vector<const UnitType*> UnitReqs;
|
||||||
|
typedef vector<const UpgradeType*> UpgradeReqs;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
UnitReqs unitReqs; //needed units
|
||||||
|
UpgradeReqs upgradeReqs; //needed upgrades
|
||||||
|
|
||||||
|
public:
|
||||||
|
//get
|
||||||
|
int getUpgradeReqCount() const {return upgradeReqs.size();}
|
||||||
|
int getUnitReqCount() const {return unitReqs.size();}
|
||||||
|
const UpgradeType *getUpgradeReq(int i) const {return upgradeReqs[i];}
|
||||||
|
const UnitType *getUnitReq(int i) const {return unitReqs[i];}
|
||||||
|
|
||||||
|
//other
|
||||||
|
virtual string getReqDesc() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class ProducibleType
|
||||||
|
//
|
||||||
|
/// Base class for anything that can be produced
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
class ProducibleType: public RequirableType{
|
||||||
|
private:
|
||||||
|
typedef vector<Resource> Costs;
|
||||||
|
|
||||||
|
protected:
|
||||||
|
Costs costs;
|
||||||
|
Texture2D *cancelImage;
|
||||||
|
int productionTime;
|
||||||
|
|
||||||
|
public:
|
||||||
|
ProducibleType();
|
||||||
|
virtual ~ProducibleType();
|
||||||
|
|
||||||
|
//get
|
||||||
|
int getCostCount() const {return costs.size();}
|
||||||
|
const Resource *getCost(int i) const {return &costs[i];}
|
||||||
|
const Resource *getCost(const ResourceType *rt) const;
|
||||||
|
int getProductionTime() const {return productionTime;}
|
||||||
|
const Texture2D *getCancelImage() const {return cancelImage;}
|
||||||
|
|
||||||
|
//varios
|
||||||
|
void checkCostStrings(TechTree *techTree);
|
||||||
|
|
||||||
|
virtual string getReqDesc() const;
|
||||||
|
};
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
|
||||||
|
#endif
|
|
@ -77,6 +77,7 @@ UnitType::UnitType(){
|
||||||
cellMap= NULL;
|
cellMap= NULL;
|
||||||
hpRegeneration= 0;
|
hpRegeneration= 0;
|
||||||
epRegeneration= 0;
|
epRegeneration= 0;
|
||||||
|
maxUnitCount= 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
UnitType::~UnitType(){
|
UnitType::~UnitType(){
|
||||||
|
@ -137,6 +138,11 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
|
||||||
epRegeneration= parametersNode->getChild("max-ep")->getAttribute("regeneration")->getIntValue();
|
epRegeneration= parametersNode->getChild("max-ep")->getAttribute("regeneration")->getIntValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//maxUnitCount
|
||||||
|
if(parametersNode->hasChild("max-unit-count")){
|
||||||
|
maxUnitCount= parametersNode->getChild("max-unit-count")->getAttribute("value")->getIntValue();
|
||||||
|
}
|
||||||
|
|
||||||
//armor
|
//armor
|
||||||
armor= parametersNode->getChild("armor")->getAttribute("value")->getIntValue();
|
armor= parametersNode->getChild("armor")->getAttribute("value")->getIntValue();
|
||||||
|
|
||||||
|
@ -629,6 +635,19 @@ string UnitType::getCommandTypeListDesc() const {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
string UnitType::getReqDesc() const{
|
||||||
|
Lang &lang= Lang::getInstance();
|
||||||
|
string desc = "Limits: ";
|
||||||
|
string resultTxt="";
|
||||||
|
if(getMaxUnitCount()>0){
|
||||||
|
resultTxt+="\n"+lang.get("MaxUnitCount")+" "+intToStr(getMaxUnitCount());
|
||||||
|
}
|
||||||
|
if(resultTxt=="")
|
||||||
|
return RequirableType::getReqDesc();
|
||||||
|
else
|
||||||
|
return RequirableType::getReqDesc()+"\nLimits: "+resultTxt;
|
||||||
|
}
|
||||||
|
|
||||||
std::string UnitType::toString() const {
|
std::string UnitType::toString() const {
|
||||||
std::string result = "";
|
std::string result = "";
|
||||||
|
|
||||||
|
@ -637,6 +656,8 @@ std::string UnitType::toString() const {
|
||||||
result += " hpRegeneration = " + intToStr(hpRegeneration);
|
result += " hpRegeneration = " + intToStr(hpRegeneration);
|
||||||
result += " maxEp = " + intToStr(maxEp);
|
result += " maxEp = " + intToStr(maxEp);
|
||||||
result += " epRegeneration = " + intToStr(epRegeneration);
|
result += " epRegeneration = " + intToStr(epRegeneration);
|
||||||
|
result += " maxUnitCount = " + intToStr(getMaxUnitCount());
|
||||||
|
|
||||||
|
|
||||||
for(int i = 0; i < fieldCount; i++) {
|
for(int i = 0; i < fieldCount; i++) {
|
||||||
result += " fields index = " + intToStr(i) + " value = " + intToStr(fields[i]);
|
result += " fields index = " + intToStr(i) + " value = " + intToStr(fields[i]);
|
||||||
|
|
|
@ -86,6 +86,8 @@ private:
|
||||||
int hpRegeneration;
|
int hpRegeneration;
|
||||||
int maxEp;
|
int maxEp;
|
||||||
int epRegeneration;
|
int epRegeneration;
|
||||||
|
int maxUnitCount;
|
||||||
|
|
||||||
|
|
||||||
///@todo remove fields, multiple fields are not supported by the engine
|
///@todo remove fields, multiple fields are not supported by the engine
|
||||||
bool fields[fieldCount]; //fields: land, sea or air
|
bool fields[fieldCount]; //fields: land, sea or air
|
||||||
|
@ -137,6 +139,7 @@ public:
|
||||||
int getHpRegeneration() const {return hpRegeneration;}
|
int getHpRegeneration() const {return hpRegeneration;}
|
||||||
int getMaxEp() const {return maxEp;}
|
int getMaxEp() const {return maxEp;}
|
||||||
int getEpRegeneration() const {return epRegeneration;}
|
int getEpRegeneration() const {return epRegeneration;}
|
||||||
|
int getMaxUnitCount() const {return maxUnitCount;}
|
||||||
bool getField(Field field) const {return fields[field];}
|
bool getField(Field field) const {return fields[field];}
|
||||||
Field getField() const {return field;}
|
Field getField() const {return field;}
|
||||||
bool getProperty(Property property) const {return properties[property];}
|
bool getProperty(Property property) const {return properties[property];}
|
||||||
|
@ -195,6 +198,9 @@ public:
|
||||||
float getRotatedBuildPos() { return rotatedBuildPos; }
|
float getRotatedBuildPos() { return rotatedBuildPos; }
|
||||||
void setRotatedBuildPos(float value) { rotatedBuildPos = value; }
|
void setRotatedBuildPos(float value) { rotatedBuildPos = value; }
|
||||||
|
|
||||||
|
//other
|
||||||
|
virtual string getReqDesc() const;
|
||||||
|
|
||||||
std::string toString() const;
|
std::string toString() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
Loading…
Reference in New Issue