2010-08-07 05:26:38 +02:00
|
|
|
// ==============================================================
|
|
|
|
// This file is part of Glest (www.glest.org)
|
|
|
|
//
|
2011-12-14 08:40:48 +01:00
|
|
|
// Copyright (C) 2001-2008 Martiño Figueroa
|
2010-08-07 05:26:38 +02: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
|
|
|
|
// ==============================================================
|
|
|
|
|
|
|
|
#include "element_type.h"
|
|
|
|
|
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
#include "resource_type.h"
|
|
|
|
#include "upgrade_type.h"
|
|
|
|
#include "unit_type.h"
|
|
|
|
#include "resource.h"
|
|
|
|
#include "tech_tree.h"
|
|
|
|
#include "logger.h"
|
|
|
|
#include "lang.h"
|
|
|
|
#include "renderer.h"
|
|
|
|
#include "leak_dumper.h"
|
|
|
|
|
|
|
|
using namespace Shared::Util;
|
|
|
|
|
|
|
|
namespace Glest{ namespace Game{
|
|
|
|
|
|
|
|
// =====================================================
|
|
|
|
// class DisplayableType
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
DisplayableType::DisplayableType(){
|
|
|
|
image= NULL;
|
|
|
|
}
|
|
|
|
|
2013-01-16 22:16:59 +01:00
|
|
|
string DisplayableType::getName(bool translatedValue) const {
|
|
|
|
if(translatedValue == false) return name;
|
|
|
|
|
|
|
|
Lang &lang = Lang::getInstance();
|
|
|
|
return lang.getTechTreeString("CommandName_" + name,name.c_str());
|
|
|
|
}
|
|
|
|
|
2012-03-13 16:21:25 +01:00
|
|
|
//void DisplayableType::saveGame(XmlNode *rootNode) const {
|
|
|
|
// std::map<string,string> mapTagReplacements;
|
|
|
|
// XmlNode *displayableTypeNode = rootNode->addChild("DisplayableType");
|
|
|
|
//
|
|
|
|
// displayableTypeNode->addAttribute("name",name, mapTagReplacements);
|
|
|
|
//}
|
2012-03-10 04:27:25 +01:00
|
|
|
|
2010-08-07 05:26:38 +02:00
|
|
|
// =====================================================
|
|
|
|
// class RequirableType
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
string RequirableType::getReqDesc() const{
|
|
|
|
bool anyReqs= false;
|
|
|
|
|
|
|
|
string reqString="";
|
|
|
|
for(int i=0; i<getUnitReqCount(); ++i){
|
|
|
|
if(getUnitReq(i) == NULL) {
|
2012-04-14 23:21:09 +02:00
|
|
|
throw megaglest_runtime_error("getUnitReq(i) == NULL");
|
2010-08-07 05:26:38 +02:00
|
|
|
}
|
2012-05-02 22:46:47 +02:00
|
|
|
reqString+= getUnitReq(i)->getName(true);
|
2010-08-07 05:26:38 +02:00
|
|
|
reqString+= "\n";
|
|
|
|
anyReqs= true;
|
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=0; i<getUpgradeReqCount(); ++i){
|
|
|
|
if(getUpgradeReq(i) == NULL) {
|
2012-04-14 23:21:09 +02:00
|
|
|
throw megaglest_runtime_error("getUpgradeReq(i) == NULL");
|
2010-08-07 05:26:38 +02:00
|
|
|
}
|
|
|
|
|
2012-05-02 22:46:47 +02:00
|
|
|
reqString+= getUpgradeReq(i)->getName(true);
|
2010-08-07 05:26:38 +02:00
|
|
|
reqString+= "\n";
|
|
|
|
anyReqs= true;
|
|
|
|
}
|
|
|
|
|
2012-05-02 22:46:47 +02:00
|
|
|
string str= getName(true);
|
2010-08-07 05:26:38 +02:00
|
|
|
if(anyReqs){
|
|
|
|
return str + " " + Lang::getInstance().get("Reqs") + ":\n" + reqString;
|
|
|
|
}
|
|
|
|
else{
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2012-03-13 16:21:25 +01:00
|
|
|
//void RequirableType::saveGame(XmlNode *rootNode) const {
|
|
|
|
// DisplayableType::saveGame(rootNode);
|
|
|
|
//
|
|
|
|
// std::map<string,string> mapTagReplacements;
|
|
|
|
// XmlNode *requirableTypeNode = rootNode->addChild("RequirableType");
|
|
|
|
//
|
|
|
|
//// UnitReqs unitReqs; //needed units
|
|
|
|
// for(unsigned int i = 0; i < unitReqs.size(); ++i) {
|
|
|
|
// const UnitType *ut = unitReqs[i];
|
|
|
|
//
|
|
|
|
// XmlNode *unitReqsNode = requirableTypeNode->addChild("unitReqs");
|
|
|
|
// unitReqsNode->addAttribute("name",ut->getName(), mapTagReplacements);
|
|
|
|
// }
|
|
|
|
//// UpgradeReqs upgradeReqs; //needed upgrades
|
|
|
|
// for(unsigned int i = 0; i < upgradeReqs.size(); ++i) {
|
|
|
|
// const UpgradeType* ut = upgradeReqs[i];
|
|
|
|
//
|
|
|
|
// ut->saveGame(requirableTypeNode);
|
|
|
|
// }
|
|
|
|
//
|
|
|
|
//}
|
2012-03-10 04:27:25 +01:00
|
|
|
|
2010-08-07 05:26:38 +02:00
|
|
|
// =====================================================
|
|
|
|
// class ProducibleType
|
|
|
|
// =====================================================
|
|
|
|
|
|
|
|
ProducibleType::ProducibleType(){
|
|
|
|
cancelImage= NULL;
|
2011-09-01 03:11:23 +02:00
|
|
|
productionTime=0;
|
2010-08-07 05:26:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
ProducibleType::~ProducibleType(){
|
|
|
|
}
|
|
|
|
|
|
|
|
const Resource *ProducibleType::getCost(const ResourceType *rt) const{
|
|
|
|
for(int i=0; i<costs.size(); ++i){
|
|
|
|
if(costs[i].getType()==rt){
|
|
|
|
return &costs[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return NULL;
|
|
|
|
}
|
|
|
|
|
2012-03-27 05:23:03 +02:00
|
|
|
string ProducibleType::getReqDesc() const {
|
|
|
|
return getReqDesc(false);
|
|
|
|
}
|
2012-11-10 20:39:55 +01:00
|
|
|
|
|
|
|
string ProducibleType::getResourceReqDesc(bool lineBreaks) const {
|
|
|
|
string str= "";
|
|
|
|
for(int i=0; i<getCostCount(); ++i){
|
|
|
|
if(getCost(i)->getAmount()!=0){
|
|
|
|
str+= getCost(i)->getType()->getName(true);
|
|
|
|
str+= ": "+ intToStr(getCost(i)->getAmount());
|
|
|
|
if(lineBreaks == true) {
|
2012-03-27 05:23:03 +02:00
|
|
|
str+= "\n";
|
|
|
|
}
|
2012-11-10 20:39:55 +01:00
|
|
|
else {
|
|
|
|
str+= " ";
|
|
|
|
}
|
2012-03-27 05:23:03 +02:00
|
|
|
}
|
2012-11-10 20:39:55 +01:00
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
2010-08-07 05:26:38 +02:00
|
|
|
|
2012-11-10 20:39:55 +01:00
|
|
|
string ProducibleType::getUnitAndUpgradeReqDesc(bool lineBreaks) const {
|
|
|
|
string str= "";
|
2010-08-07 05:26:38 +02:00
|
|
|
for(int i=0; i<getUnitReqCount(); ++i){
|
2012-05-02 22:46:47 +02:00
|
|
|
str+= getUnitReq(i)->getName(true);
|
2012-11-10 20:39:55 +01:00
|
|
|
if(lineBreaks == true) {
|
|
|
|
str+= "\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
str+= " ";
|
|
|
|
}
|
2010-08-07 05:26:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
for(int i=0; i<getUpgradeReqCount(); ++i){
|
2012-05-02 22:46:47 +02:00
|
|
|
str+= getUpgradeReq(i)->getName(true);
|
2012-11-10 20:39:55 +01:00
|
|
|
if(lineBreaks == true) {
|
|
|
|
str+= "\n";
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
str+= " ";
|
|
|
|
}
|
2010-08-07 05:26:38 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2012-11-10 20:39:55 +01:00
|
|
|
string ProducibleType::getReqDesc(bool ignoreResourceRequirements) const {
|
|
|
|
string str= getName(true) + " " + Lang::getInstance().get("Reqs") + ":\n";
|
|
|
|
if(ignoreResourceRequirements == false) {
|
|
|
|
str+= getResourceReqDesc();
|
|
|
|
}
|
|
|
|
|
|
|
|
str+= getUnitAndUpgradeReqDesc();
|
|
|
|
return str;
|
|
|
|
}
|
|
|
|
|
2012-03-13 16:21:25 +01:00
|
|
|
//void ProducibleType::saveGame(XmlNode *rootNode) const {
|
|
|
|
// RequirableType::saveGame(rootNode);
|
|
|
|
//
|
|
|
|
// std::map<string,string> mapTagReplacements;
|
|
|
|
// XmlNode *producibleTypeNode = rootNode->addChild("ProducibleType");
|
|
|
|
//
|
|
|
|
//// Costs costs;
|
|
|
|
// for(unsigned int i = 0; i < costs.size(); ++i) {
|
|
|
|
// const Resource &res = costs[i];
|
|
|
|
// res.saveGame(producibleTypeNode);
|
|
|
|
// }
|
|
|
|
//// Texture2D *cancelImage;
|
|
|
|
//// int productionTime;
|
|
|
|
// producibleTypeNode->addAttribute("productionTime",intToStr(productionTime), mapTagReplacements);
|
|
|
|
//}
|
|
|
|
|
|
|
|
//void ProducibleType::loadGame(const XmlNode *rootNode) {
|
|
|
|
// const XmlNode *producibleTypeNode = rootNode->getChild("ProducibleType");
|
|
|
|
//
|
|
|
|
// //int newUnitId = producibleTypeNode->getAttribute("id")->getIntValue();
|
|
|
|
//}
|
2012-03-10 04:27:25 +01:00
|
|
|
|
2010-08-07 05:26:38 +02:00
|
|
|
}}//end namespace
|