types:reformat/style (#47)

`indent -i2 -nut -bl -bli0 -ppi3 -nce -npsl` Merging @andy5995 's code reformatting.
This commit is contained in:
Andy Alt
2018-02-03 05:49:20 -06:00
committed by Jammyjamjamman
parent 8f19404e7f
commit b6a891d6c1
24 changed files with 13585 additions and 8921 deletions

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,12 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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 "damage_multiplier.h"
@@ -16,90 +16,117 @@
using namespace Shared::Util;
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
void AttackType::saveGame(XmlNode *rootNode) {
std::map<string,string> mapTagReplacements;
XmlNode *attackTypeNode = rootNode->addChild("AttackType");
void AttackType::saveGame (XmlNode * rootNode)
{
std::map < string, string > mapTagReplacements;
XmlNode *attackTypeNode = rootNode->addChild ("AttackType");
// string name;
attackTypeNode->addAttribute("name",name, mapTagReplacements);
// int id;
attackTypeNode->addAttribute("id",intToStr(id), mapTagReplacements);
}
// string name;
attackTypeNode->addAttribute ("name", name, mapTagReplacements);
// int id;
attackTypeNode->addAttribute ("id", intToStr (id), mapTagReplacements);
}
string AttackType::getName(bool translatedValue) const {
if(translatedValue == false) return name;
string AttackType::getName (bool translatedValue) const
{
if (translatedValue == false)
return name;
Lang &lang = Lang::getInstance();
return lang.getTechTreeString("AttackTypeName_" + name,name.c_str());
}
Lang & lang = Lang::getInstance ();
return lang.getTechTreeString ("AttackTypeName_" + name, name.c_str ());
}
void ArmorType::saveGame(XmlNode *rootNode) {
std::map<string,string> mapTagReplacements;
XmlNode *armorTypeNode = rootNode->addChild("ArmorType");
void ArmorType::saveGame (XmlNode * rootNode)
{
std::map < string, string > mapTagReplacements;
XmlNode *armorTypeNode = rootNode->addChild ("ArmorType");
// string name;
armorTypeNode->addAttribute("name",name, mapTagReplacements);
// int id;
armorTypeNode->addAttribute("id",intToStr(id), mapTagReplacements);
}
// string name;
armorTypeNode->addAttribute ("name", name, mapTagReplacements);
// int id;
armorTypeNode->addAttribute ("id", intToStr (id), mapTagReplacements);
}
string ArmorType::getName(bool translatedValue) const {
if(translatedValue == false) return name;
string ArmorType::getName (bool translatedValue) const
{
if (translatedValue == false)
return name;
Lang &lang = Lang::getInstance();
return lang.getTechTreeString("ArmorTypeName_" + name,name.c_str());
}
Lang & lang = Lang::getInstance ();
return lang.getTechTreeString ("ArmorTypeName_" + name, name.c_str ());
}
// =====================================================
// class DamageMultiplierTable
// class DamageMultiplierTable
// =====================================================
DamageMultiplierTable::DamageMultiplierTable(){
values= NULL;
attackTypeCount=0;
armorTypeCount=0;
}
DamageMultiplierTable::DamageMultiplierTable ()
{
values = NULL;
attackTypeCount = 0;
armorTypeCount = 0;
}
DamageMultiplierTable::~DamageMultiplierTable(){
delete [] values;
values=NULL;
}
DamageMultiplierTable::~DamageMultiplierTable ()
{
delete[]values;
values = NULL;
}
void DamageMultiplierTable::init(int attackTypeCount, int armorTypeCount){
this->attackTypeCount= attackTypeCount;
this->armorTypeCount= armorTypeCount;
int valueCount= attackTypeCount * armorTypeCount;
values= new double[valueCount];
for(int i=0; i<valueCount; ++i){
values[i]= 1.f;
}
}
void DamageMultiplierTable::init (int attackTypeCount, int armorTypeCount)
{
this->attackTypeCount = attackTypeCount;
this->armorTypeCount = armorTypeCount;
double DamageMultiplierTable::getDamageMultiplier(const AttackType *att, const ArmorType *art) const {
return values[attackTypeCount * art->getId() + att->getId()];
}
int valueCount = attackTypeCount * armorTypeCount;
values = new double[valueCount];
for (int i = 0; i < valueCount; ++i)
{
values[i] = 1.f;
}
}
void DamageMultiplierTable::setDamageMultiplier(const AttackType *att, const ArmorType *art, double value) {
values[attackTypeCount * art->getId() + att->getId()] = value;
}
double DamageMultiplierTable::getDamageMultiplier (const AttackType * att,
const ArmorType *
art) const
{
return values[attackTypeCount * art->getId () + att->getId ()];
}
void DamageMultiplierTable::saveGame(XmlNode *rootNode) {
std::map<string,string> mapTagReplacements;
XmlNode *damageMultiplierTableNode = rootNode->addChild("DamageMultiplierTable");
void DamageMultiplierTable::setDamageMultiplier (const AttackType * att,
const ArmorType * art,
double value)
{
values[attackTypeCount * art->getId () + att->getId ()] = value;
}
// float *values;
// int attackTypeCount;
// int armorTypeCount;
damageMultiplierTableNode->addAttribute("attackTypeCount",intToStr(attackTypeCount), mapTagReplacements);
damageMultiplierTableNode->addAttribute("armorTypeCount",intToStr(armorTypeCount), mapTagReplacements);
void DamageMultiplierTable::saveGame (XmlNode * rootNode)
{
std::map < string, string > mapTagReplacements;
XmlNode *damageMultiplierTableNode =
rootNode->addChild ("DamageMultiplierTable");
int valueCount= attackTypeCount * armorTypeCount;
for(int i=0; i < valueCount; ++i) {
XmlNode *valuesNode = damageMultiplierTableNode->addChild("values");
valuesNode->addAttribute("value",doubleToStr(values[i]), mapTagReplacements);
}
}
// float *values;
// int attackTypeCount;
// int armorTypeCount;
damageMultiplierTableNode->addAttribute ("attackTypeCount",
intToStr (attackTypeCount),
mapTagReplacements);
damageMultiplierTableNode->addAttribute ("armorTypeCount",
intToStr (armorTypeCount),
mapTagReplacements);
}}//end namespaces
int valueCount = attackTypeCount * armorTypeCount;
for (int i = 0; i < valueCount; ++i)
{
XmlNode *valuesNode = damageMultiplierTableNode->addChild ("values");
valuesNode->addAttribute ("value", doubleToStr (values[i]),
mapTagReplacements);
}
}
}} //end namespaces

View File

@@ -1,99 +1,127 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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_DAMAGEMULTIPLIER_H_
#define _GLEST_GAME_DAMAGEMULTIPLIER_H_
# define _GLEST_GAME_DAMAGEMULTIPLIER_H_
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#endif
# ifdef WIN32
# include <winsock2.h>
# include <winsock.h>
# endif
#include <string>
#include "xml_parser.h"
#include "leak_dumper.h"
# include <string>
# include "xml_parser.h"
# include "leak_dumper.h"
using std::string;
using Shared::Xml::XmlNode;
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
// ===============================
// class AttackType
// class AttackType
// ===============================
class AttackType {
private:
string name;
int id;
class AttackType
{
private:
string name;
int id;
public:
AttackType() {
id = -1;
}
int getId() const {return id;}
string getName(bool translatedValue=false) const;
public:
AttackType ()
{
id = -1;
}
int getId () const
{
return id;
}
string getName (bool translatedValue = false) const;
void setName(const string &name) {this->name= name;}
void setId(int id) {this->id= id;}
void setName (const string & name)
{
this->name = name;
}
void setId (int id)
{
this->id = id;
}
void saveGame(XmlNode *rootNode);
};
void saveGame (XmlNode * rootNode);
};
// ===============================
// class ArmorType
// class ArmorType
// ===============================
class ArmorType {
private:
string name;
int id;
class ArmorType
{
private:
string name;
int id;
public:
ArmorType() {
id = -1;
}
int getId() const {return id;}
string getName(bool translatedValue=false) const;
public:
ArmorType ()
{
id = -1;
}
int getId () const
{
return id;
}
string getName (bool translatedValue = false) const;
void setName(const string &name) {this->name= name;}
void setId(int id) {this->id= id;}
void setName (const string & name)
{
this->name = name;
}
void setId (int id)
{
this->id = id;
}
void saveGame(XmlNode *rootNode);
};
void saveGame (XmlNode * rootNode);
};
// =====================================================
// class DamageMultiplierTable
// class DamageMultiplierTable
//
/// Some attack types have bonuses against some
/// Some attack types have bonuses against some
/// armor types and vice-versa
// =====================================================
class DamageMultiplierTable {
private:
double *values;
int attackTypeCount;
int armorTypeCount;
class DamageMultiplierTable
{
private:
double *values;
int attackTypeCount;
int armorTypeCount;
public:
DamageMultiplierTable();
~DamageMultiplierTable();
public:
DamageMultiplierTable ();
~DamageMultiplierTable ();
void init(int attackTypeCount, int armorTypeCount);
double getDamageMultiplier(const AttackType *att, const ArmorType *art) const;
void setDamageMultiplier(const AttackType *att, const ArmorType *art, double value);
void init (int attackTypeCount, int armorTypeCount);
double getDamageMultiplier (const AttackType * att,
const ArmorType * art) const;
void setDamageMultiplier (const AttackType * att, const ArmorType * art,
double value);
void saveGame(XmlNode *rootNode);
};
void saveGame (XmlNode * rootNode);
};
}}//end namespace
}} //end namespace
#endif

View File

@@ -1,19 +1,19 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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 "resource_type.h"
#include "upgrade_type.h"
#include "unit_type.h"
#include "resource.h"
@@ -25,186 +25,232 @@
using namespace Shared::Util;
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
// =====================================================
// class DisplayableType
// class DisplayableType
// =====================================================
DisplayableType::DisplayableType(){
image= NULL;
}
DisplayableType::DisplayableType ()
{
image = NULL;
}
string DisplayableType::getName(bool translatedValue) const {
if(translatedValue == false) return name;
string DisplayableType::getName (bool translatedValue) const
{
if (translatedValue == false)
return name;
Lang &lang = Lang::getInstance();
return lang.getTechTreeString("CommandName_" + name,name.c_str());
}
Lang & lang = Lang::getInstance ();
return lang.getTechTreeString ("CommandName_" + name, name.c_str ());
}
//void DisplayableType::saveGame(XmlNode *rootNode) const {
// std::map<string,string> mapTagReplacements;
// XmlNode *displayableTypeNode = rootNode->addChild("DisplayableType");
// std::map<string,string> mapTagReplacements;
// XmlNode *displayableTypeNode = rootNode->addChild("DisplayableType");
//
// displayableTypeNode->addAttribute("name",name, mapTagReplacements);
// displayableTypeNode->addAttribute("name",name, mapTagReplacements);
//}
// =====================================================
// class RequirableType
// class RequirableType
// =====================================================
string RequirableType::getReqDesc(bool translatedValue) const{
bool anyReqs= false;
string RequirableType::getReqDesc (bool translatedValue) const
{
bool anyReqs = false;
string reqString="";
for(int i=0; i<getUnitReqCount(); ++i){
if(getUnitReq(i) == NULL) {
throw megaglest_runtime_error("getUnitReq(i) == NULL");
}
reqString+= getUnitReq(i)->getName(translatedValue);
reqString+= "\n";
anyReqs= true;
string reqString = "";
for (int i = 0; i < getUnitReqCount (); ++i)
{
if (getUnitReq (i) == NULL)
{
throw megaglest_runtime_error ("getUnitReq(i) == NULL");
}
reqString += getUnitReq (i)->getName (translatedValue);
reqString += "\n";
anyReqs = true;
}
for (int i = 0; i < getUpgradeReqCount (); ++i)
{
if (getUpgradeReq (i) == NULL)
{
throw megaglest_runtime_error ("getUpgradeReq(i) == NULL");
}
reqString += getUpgradeReq (i)->getName (translatedValue);
reqString += "\n";
anyReqs = true;
}
string str = getName (translatedValue);
if (anyReqs)
{
return str + " " + Lang::getInstance ().getString ("Reqs",
(translatedValue ==
true ? "" :
"english")) +
":\n" + reqString;
}
else
{
return str;
}
}
for(int i=0; i<getUpgradeReqCount(); ++i){
if(getUpgradeReq(i) == NULL) {
throw megaglest_runtime_error("getUpgradeReq(i) == NULL");
}
reqString+= getUpgradeReq(i)->getName(translatedValue);
reqString+= "\n";
anyReqs= true;
}
string str= getName(translatedValue);
if(anyReqs){
return str + " " + Lang::getInstance().getString("Reqs",(translatedValue == true ? "" : "english")) + ":\n" + reqString;
}
else{
return str;
}
}
//void RequirableType::saveGame(XmlNode *rootNode) const {
// DisplayableType::saveGame(rootNode);
// DisplayableType::saveGame(rootNode);
//
// std::map<string,string> mapTagReplacements;
// XmlNode *requirableTypeNode = rootNode->addChild("RequirableType");
// 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];
//// 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];
// 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);
// }
// ut->saveGame(requirableTypeNode);
// }
//
//}
// =====================================================
// class ProducibleType
// class ProducibleType
// =====================================================
ProducibleType::ProducibleType(){
cancelImage= NULL;
productionTime=0;
}
ProducibleType::ProducibleType ()
{
cancelImage = NULL;
productionTime = 0;
}
ProducibleType::~ProducibleType(){
}
ProducibleType::~ProducibleType ()
{
}
const Resource *ProducibleType::getCost(const ResourceType *rt) const{
for(int i=0; i < (int)costs.size(); ++i){
if(costs[i].getType()==rt){
return &costs[i];
}
}
return NULL;
}
string ProducibleType::getReqDesc(bool translatedValue) const {
return getReqDesc(false,translatedValue);
}
string ProducibleType::getResourceReqDesc(bool lineBreaks, bool translatedValue) const {
string str= "";
for(int i=0; i<getCostCount(); ++i){
if(getCost(i)->getAmount()!=0){
str+= getCost(i)->getType()->getName(translatedValue);
str+= ": "+ intToStr(getCost(i)->getAmount());
if(lineBreaks == true) {
str+= "\n";
}
else {
str+= " ";
}
}
}
return str;
}
string ProducibleType::getUnitAndUpgradeReqDesc(bool lineBreaks, bool translatedValue) const {
string str= "";
for(int i=0; i<getUnitReqCount(); ++i){
str+= getUnitReq(i)->getName(translatedValue);
if(lineBreaks == true) {
str+= "\n";
const Resource *ProducibleType::getCost (const ResourceType * rt) const
{
for (int i = 0; i < (int) costs.size (); ++i)
{
if (costs[i].getType () == rt)
{
return &costs[i];
}
else {
str+= " ";
}
}
return NULL;
}
for(int i=0; i<getUpgradeReqCount(); ++i){
str+= getUpgradeReq(i)->getName(translatedValue);
if(lineBreaks == true) {
str+= "\n";
string ProducibleType::getReqDesc (bool translatedValue) const
{
return getReqDesc (false, translatedValue);
}
string ProducibleType::getResourceReqDesc (bool lineBreaks,
bool translatedValue) const
{
string str = "";
for (int i = 0; i < getCostCount (); ++i)
{
if (getCost (i)->getAmount () != 0)
{
str += getCost (i)->getType ()->getName (translatedValue);
str += ": " + intToStr (getCost (i)->getAmount ());
if (lineBreaks == true)
{
str += "\n";
}
else
{
str += " ";
}
}
else {
str+= " ";
}
}
return str;
}
return str;
}
string ProducibleType::getUnitAndUpgradeReqDesc (bool lineBreaks,
bool translatedValue)
const
{
string str = "";
for (int i = 0; i < getUnitReqCount (); ++i)
{
str += getUnitReq (i)->getName (translatedValue);
if (lineBreaks == true)
{
str += "\n";
}
else
{
str += " ";
}
}
string ProducibleType::getReqDesc(bool ignoreResourceRequirements, bool translatedValue) const {
string str= getName(translatedValue) + " " + Lang::getInstance().getString("Reqs",(translatedValue == true ? "" : "english")) + ":\n";
if(ignoreResourceRequirements == false) {
str+= getResourceReqDesc(true,translatedValue);
for (int i = 0; i < getUpgradeReqCount (); ++i)
{
str += getUpgradeReq (i)->getName (translatedValue);
if (lineBreaks == true)
{
str += "\n";
}
else
{
str += " ";
}
}
return str;
}
str+= getUnitAndUpgradeReqDesc(true,translatedValue);
return str;
}
string ProducibleType::getReqDesc (bool ignoreResourceRequirements,
bool translatedValue) const
{
string str =
getName (translatedValue) + " " +
Lang::getInstance ().getString ("Reqs",
(translatedValue ==
true ? "" : "english")) + ":\n";
if (ignoreResourceRequirements == false)
{
str += getResourceReqDesc (true, translatedValue);
}
str += getUnitAndUpgradeReqDesc (true, translatedValue);
return str;
}
//void ProducibleType::saveGame(XmlNode *rootNode) const {
// RequirableType::saveGame(rootNode);
// RequirableType::saveGame(rootNode);
//
// std::map<string,string> mapTagReplacements;
// XmlNode *producibleTypeNode = rootNode->addChild("ProducibleType");
// 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);
// }
//// 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);
//// int productionTime;
// producibleTypeNode->addAttribute("productionTime",intToStr(productionTime), mapTagReplacements);
//}
//void ProducibleType::loadGame(const XmlNode *rootNode) {
// const XmlNode *producibleTypeNode = rootNode->getChild("ProducibleType");
// const XmlNode *producibleTypeNode = rootNode->getChild("ProducibleType");
//
// //int newUnitId = producibleTypeNode->getAttribute("id")->getIntValue();
// //int newUnitId = producibleTypeNode->getAttribute("id")->getIntValue();
//}
}}//end namespace
}
} //end namespace

View File

@@ -1,132 +1,169 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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_
#ifndef _GLEST_GAME_ELEMENTTYPE_H_
# define _GLEST_GAME_ELEMENTTYPE_H_
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#endif
# ifdef WIN32
# include <winsock2.h>
# include <winsock.h>
# endif
#include <vector>
#include <string>
#include "texture.h"
#include "resource.h"
#include "leak_dumper.h"
# include <vector>
# include <string>
# include "texture.h"
# include "resource.h"
# include "leak_dumper.h"
using std::vector;
using std::string;
using Shared::Graphics::Texture2D;
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
class UpgradeType;
class TechTree;
class UnitType;
class UpgradeType;
class DisplayableType;
class ResourceType;
class UpgradeType;
class TechTree;
class UnitType;
class UpgradeType;
class DisplayableType;
class ResourceType;
// =====================================================
// class DisplayableType
// class DisplayableType
//
/// Base class for anything that has a name and a portrait
/// Base class for anything that has a name and a portrait
// =====================================================
class DisplayableType {
protected:
string name; //name
Texture2D *image; //portrait
class DisplayableType
{
protected:
string name; //name
Texture2D *image; //portrait
public:
DisplayableType();
virtual ~DisplayableType(){};
public:
DisplayableType ();
virtual ~ DisplayableType ()
{
};
//get
virtual string getName(bool translatedValue=false) const;
virtual const Texture2D *getImage() const { return image; }
//get
virtual string getName (bool translatedValue = false) const;
virtual const Texture2D *getImage () const
{
return image;
}
//virtual void saveGame(XmlNode *rootNode) const;
};
//virtual void saveGame(XmlNode *rootNode) const;
};
// =====================================================
// class RequirableType
// class RequirableType
//
/// Base class for anything that has requirements
/// Base class for anything that has requirements
// =====================================================
class RequirableType: public DisplayableType{
private:
typedef vector<const UnitType*> UnitReqs;
typedef vector<const UpgradeType*> UpgradeReqs;
class RequirableType:public DisplayableType
{
private:
typedef vector < const UnitType *>UnitReqs;
typedef vector < const UpgradeType *>UpgradeReqs;
protected:
UnitReqs unitReqs; //needed units
UpgradeReqs upgradeReqs; //needed upgrades
protected:
UnitReqs unitReqs; //needed units
UpgradeReqs upgradeReqs; //needed upgrades
public:
//get
int getUpgradeReqCount() const {return (int)upgradeReqs.size();}
int getUnitReqCount() const {return (int)unitReqs.size();}
const UpgradeType *getUpgradeReq(int i) const {return upgradeReqs[i];}
const UnitType *getUnitReq(int i) const {return unitReqs[i];}
//other
virtual string getReqDesc(bool translatedValue) const;
public:
//get
int getUpgradeReqCount () const
{
return (int) upgradeReqs.size ();
}
int getUnitReqCount () const
{
return (int) unitReqs.size ();
}
const UpgradeType *getUpgradeReq (int i) const
{
return upgradeReqs[i];
}
const UnitType *getUnitReq (int i) const
{
return unitReqs[i];
}
//virtual void saveGame(XmlNode *rootNode) const;
};
//other
virtual string getReqDesc (bool translatedValue) const;
//virtual void saveGame(XmlNode *rootNode) const;
};
// =====================================================
// class ProducibleType
// class ProducibleType
//
/// Base class for anything that can be produced
/// Base class for anything that can be produced
// =====================================================
class ProducibleType: public RequirableType {
private:
typedef vector<Resource> Costs;
class ProducibleType:public RequirableType
{
private:
typedef vector < Resource > Costs;
protected:
Costs costs;
Texture2D *cancelImage;
int productionTime;
protected:
Costs costs;
Texture2D *cancelImage;
int productionTime;
public:
ProducibleType();
virtual ~ProducibleType();
public:
ProducibleType ();
virtual ~ ProducibleType ();
//get
int getCostCount() const {return (int)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(bool translatedValue) const;
string getResourceReqDesc(bool lineBreaks,bool translatedValue) const;
string getUnitAndUpgradeReqDesc(bool lineBreaks, bool translatedValue) const;
string getReqDesc(bool ignoreResourceRequirements, bool translatedValue) const;
//get
int getCostCount () const
{
return (int) 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;
}
// virtual void saveGame(XmlNode *rootNode) const;
// void loadGame(const XmlNode *rootNode);
};
//varios
void checkCostStrings (TechTree * techTree);
}}//end namespace
virtual string getReqDesc (bool translatedValue) const;
string getResourceReqDesc (bool lineBreaks, bool translatedValue) const;
string getUnitAndUpgradeReqDesc (bool lineBreaks,
bool translatedValue) const;
string getReqDesc (bool ignoreResourceRequirements,
bool translatedValue) const;
// virtual void saveGame(XmlNode *rootNode) const;
// void loadGame(const XmlNode *rootNode);
};
}} //end namespace
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,164 +1,246 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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_FACTIONTYPE_H_
#define _GLEST_GAME_FACTIONTYPE_H_
# define _GLEST_GAME_FACTIONTYPE_H_
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#endif
# ifdef WIN32
# include <winsock2.h>
# include <winsock.h>
# endif
#include "unit_type.h"
#include "upgrade_type.h"
#include "sound.h"
#include <map>
#include <string>
#include "util.h"
#include "leak_dumper.h"
# include "unit_type.h"
# include "upgrade_type.h"
# include "sound.h"
# include <map>
# include <string>
# include "util.h"
# include "leak_dumper.h"
using Shared::Sound::StrSound;
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
// =====================================================
// class FactionType
// class FactionType
//
/// Each of the possible factions the user can select
/// Each of the possible factions the user can select
// =====================================================
enum AIBehaviorUnitCategory {
aibcWorkerUnits,
aibcWarriorUnits,
aibcResourceProducerUnits,
aibcBuildingUnits
};
enum AIBehaviorUnitCategory
{
aibcWorkerUnits,
aibcWarriorUnits,
aibcResourceProducerUnits,
aibcBuildingUnits
};
enum AIBehaviorStaticValueCategory {
aibsvcMaxBuildRadius,
aibsvcMinMinWarriors,
aibsvcMinMinWarriorsExpandCpuEasy,
aibsvcMinMinWarriorsExpandCpuMega,
aibsvcMinMinWarriorsExpandCpuUltra,
aibsvcMinMinWarriorsExpandCpuNormal,
aibsvcMaxMinWarriors,
aibsvcMaxExpansions,
aibsvcVillageRadius,
aibsvcMinStaticResourceCount,
aibsvcScoutResourceRange,
aibsvcMinWorkerAttackersHarvesting,
aibsvcMinBuildSpacing
};
template <>
inline EnumParser<AIBehaviorStaticValueCategory>::EnumParser() {
enumMap["MaxBuildRadius"] = aibsvcMaxBuildRadius;
enumMap["MinMinWarriors"] = aibsvcMinMinWarriors;
enumMap["MinMinWarriorsExpandCpuEasy"] = aibsvcMinMinWarriorsExpandCpuEasy;
enumMap["MinMinWarriorsExpandCpuMega"] = aibsvcMinMinWarriorsExpandCpuMega;
enumMap["MinMinWarriorsExpandCpuUltra"] = aibsvcMinMinWarriorsExpandCpuUltra;
enumMap["MinMinWarriorsExpandCpuNormal"]= aibsvcMinMinWarriorsExpandCpuNormal;
enumMap["MaxMinWarriors"] = aibsvcMaxMinWarriors;
enumMap["MaxExpansions"] = aibsvcMaxExpansions;
enumMap["VillageRadius"] = aibsvcVillageRadius;
enumMap["MinStaticResourceCount"] = aibsvcMinStaticResourceCount;
enumMap["ScoutResourceRange"] = aibsvcScoutResourceRange;
enumMap["MinWorkerAttackersHarvesting"] = aibsvcMinWorkerAttackersHarvesting;
enumMap["MinBuildSpacing"] = aibsvcMinBuildSpacing;
}
enum AIBehaviorStaticValueCategory
{
aibsvcMaxBuildRadius,
aibsvcMinMinWarriors,
aibsvcMinMinWarriorsExpandCpuEasy,
aibsvcMinMinWarriorsExpandCpuMega,
aibsvcMinMinWarriorsExpandCpuUltra,
aibsvcMinMinWarriorsExpandCpuNormal,
aibsvcMaxMinWarriors,
aibsvcMaxExpansions,
aibsvcVillageRadius,
aibsvcMinStaticResourceCount,
aibsvcScoutResourceRange,
aibsvcMinWorkerAttackersHarvesting,
aibsvcMinBuildSpacing
};
template <>
inline EnumParser < AIBehaviorStaticValueCategory >::EnumParser ()
{
enumMap["MaxBuildRadius"] = aibsvcMaxBuildRadius;
enumMap["MinMinWarriors"] = aibsvcMinMinWarriors;
enumMap["MinMinWarriorsExpandCpuEasy"] =
aibsvcMinMinWarriorsExpandCpuEasy;
enumMap["MinMinWarriorsExpandCpuMega"] =
aibsvcMinMinWarriorsExpandCpuMega;
enumMap["MinMinWarriorsExpandCpuUltra"] =
aibsvcMinMinWarriorsExpandCpuUltra;
enumMap["MinMinWarriorsExpandCpuNormal"] =
aibsvcMinMinWarriorsExpandCpuNormal;
enumMap["MaxMinWarriors"] = aibsvcMaxMinWarriors;
enumMap["MaxExpansions"] = aibsvcMaxExpansions;
enumMap["VillageRadius"] = aibsvcVillageRadius;
enumMap["MinStaticResourceCount"] = aibsvcMinStaticResourceCount;
enumMap["ScoutResourceRange"] = aibsvcScoutResourceRange;
enumMap["MinWorkerAttackersHarvesting"] =
aibsvcMinWorkerAttackersHarvesting;
enumMap["MinBuildSpacing"] = aibsvcMinBuildSpacing;
}
class FactionType {
public:
typedef pair<const UnitType*, int> PairPUnitTypeInt;
typedef vector<UnitType> UnitTypes;
typedef vector<UpgradeType> UpgradeTypes;
typedef vector<PairPUnitTypeInt> StartingUnits;
typedef vector<Resource> Resources;
class FactionType
{
public:
typedef pair < const UnitType *, int >PairPUnitTypeInt;
typedef vector < UnitType > UnitTypes;
typedef vector < UpgradeType > UpgradeTypes;
typedef vector < PairPUnitTypeInt > StartingUnits;
typedef vector < Resource > Resources;
private:
string name;
UnitTypes unitTypes;
UpgradeTypes upgradeTypes;
StartingUnits startingUnits;
Resources startingResources;
StrSound *music;
FactionPersonalityType personalityType;
private:
string name;
UnitTypes unitTypes;
UpgradeTypes upgradeTypes;
StartingUnits startingUnits;
Resources startingResources;
StrSound *music;
FactionPersonalityType personalityType;
std::map<AIBehaviorUnitCategory, std::vector<PairPUnitTypeInt> > mapAIBehaviorUnitCategories;
std::vector<const UpgradeType*> vctAIBehaviorUpgrades;
std::map<AIBehaviorStaticValueCategory, int > mapAIBehaviorStaticOverrideValues;
std::map < AIBehaviorUnitCategory,
std::vector < PairPUnitTypeInt > >mapAIBehaviorUnitCategories;
std::vector < const UpgradeType *>vctAIBehaviorUpgrades;
std::map < AIBehaviorStaticValueCategory,
int >mapAIBehaviorStaticOverrideValues;
bool isLinked;
bool isLinked;
float healthbarheight;
float healthbarthickness;
int healthbarVisible;
bool healthbarBorderTextureEnabled;
bool healthbarBackgroundTextureEnabled;
bool healthbarLineBorder;
Texture2D *healthbarTexture;
Texture2D *healthbarBackgroundTexture;
bool flatParticlePositions;
float healthbarheight;
float healthbarthickness;
int healthbarVisible;
bool healthbarBorderTextureEnabled;
bool healthbarBackgroundTextureEnabled;
bool healthbarLineBorder;
Texture2D *healthbarTexture;
Texture2D *healthbarBackgroundTexture;
bool flatParticlePositions;
public:
//init
FactionType();
void load(const string &factionName, const TechTree *techTree, Checksum* checksum,
Checksum *techtreeChecksum,
std::map<string,vector<pair<string, string> > > &loadedFileList,
bool validationMode=false);
virtual ~FactionType();
public:
//init
FactionType ();
void load (const string & factionName, const TechTree * techTree,
Checksum * checksum, Checksum * techtreeChecksum,
std::map < string, vector < pair < string,
string > > >&loadedFileList, bool validationMode = false);
virtual ~ FactionType ();
const std::vector<FactionType::PairPUnitTypeInt> getAIBehaviorUnits(AIBehaviorUnitCategory category) const;
const std::vector<const UpgradeType*> getAIBehaviorUpgrades() const { return vctAIBehaviorUpgrades; };
int getAIBehaviorStaticOverideValue(AIBehaviorStaticValueCategory type) const;
const std::vector < FactionType::PairPUnitTypeInt >
getAIBehaviorUnits (AIBehaviorUnitCategory category) const;
const std::vector < const UpgradeType *>getAIBehaviorUpgrades () const
{
return vctAIBehaviorUpgrades;
};
int getAIBehaviorStaticOverideValue (AIBehaviorStaticValueCategory type)
const;
//get
bool getIsLinked() const { return isLinked; }
int getUnitTypeCount() const {return (int)unitTypes.size();}
int getUpgradeTypeCount() const {return (int)upgradeTypes.size();}
virtual string getName(bool translatedValue=false) const;
const UnitType *getUnitType(int i) const {return &unitTypes[i];}
const UpgradeType *getUpgradeType(int i) const {return &upgradeTypes[i];}
StrSound *getMusic() const {return music;}
int getStartingUnitCount() const {return (int)startingUnits.size();}
const UnitType *getStartingUnit(int i) const {return startingUnits[i].first;}
int getStartingUnitAmount(int i) const {return startingUnits[i].second;}
inline float getHealthbarHeight() const {return healthbarheight;}
inline float getHealthbarThickness() const {return healthbarthickness;}
inline int getHealthbarVisible() const {return healthbarVisible;}
inline bool isHealthbarBorderTextureEnabled() const {return healthbarBorderTextureEnabled;}
inline bool isHealthbarBackgroundTextureEnabled() const {return healthbarBackgroundTextureEnabled;}
inline bool isHealthbarLineBorder() const {return healthbarLineBorder;}
Texture2D *getHealthbarTexture() const {return healthbarTexture;}
Texture2D *getHealthbarBackgroundTexture() const {return healthbarBackgroundTexture;}
bool isFlatParticlePositions() const {return flatParticlePositions;}
//get
bool getIsLinked () const
{
return isLinked;
}
int getUnitTypeCount () const
{
return (int) unitTypes.size ();
}
int getUpgradeTypeCount () const
{
return (int) upgradeTypes.size ();
}
virtual string getName (bool translatedValue = false) const;
const UnitType *getUnitType (int i) const
{
return &unitTypes[i];
}
const UpgradeType *getUpgradeType (int i) const
{
return &upgradeTypes[i];
}
StrSound *getMusic () const
{
return music;
}
int getStartingUnitCount () const
{
return (int) startingUnits.size ();
}
const UnitType *getStartingUnit (int i) const
{
return startingUnits[i].first;
}
int getStartingUnitAmount (int i) const
{
return startingUnits[i].second;
}
inline float getHealthbarHeight () const
{
return healthbarheight;
}
inline float getHealthbarThickness () const
{
return healthbarthickness;
}
inline int getHealthbarVisible () const
{
return healthbarVisible;
}
inline bool isHealthbarBorderTextureEnabled () const
{
return healthbarBorderTextureEnabled;
}
inline bool isHealthbarBackgroundTextureEnabled () const
{
return healthbarBackgroundTextureEnabled;
}
inline bool isHealthbarLineBorder () const
{
return healthbarLineBorder;
}
Texture2D *getHealthbarTexture () const
{
return healthbarTexture;
}
Texture2D *getHealthbarBackgroundTexture () const
{
return healthbarBackgroundTexture;
}
bool isFlatParticlePositions () const
{
return flatParticlePositions;
}
const UnitType *getUnitType(const string &name) const;
//const UnitType *getUnitTypeById(int id) const;
const UpgradeType *getUpgradeType(const string &name) const;
int getStartingResourceAmount(const ResourceType *resourceType) const;
const UnitType *getUnitType (const string & name) const;
//const UnitType *getUnitTypeById(int id) const;
const UpgradeType *getUpgradeType (const string & name) const;
int getStartingResourceAmount (const ResourceType * resourceType) const;
FactionPersonalityType getPersonalityType() const { return personalityType;}
void setPersonalityType(FactionPersonalityType value) { personalityType = value;}
FactionPersonalityType getPersonalityType () const
{
return personalityType;
}
void setPersonalityType (FactionPersonalityType value)
{
personalityType = value;
}
std::string toString() const;
std::vector<std::string> validateFactionType();
std::vector<std::string> validateFactionTypeResourceTypes(vector<ResourceType> &resourceTypes);
std::vector<std::string> validateFactionTypeUpgradeTypes();
std::string toString () const;
std::vector < std::string > validateFactionType ();
std::vector < std::string > validateFactionTypeResourceTypes (vector <
ResourceType
>
&resourceTypes);
std::vector < std::string > validateFactionTypeUpgradeTypes ();
void deletePixels();
bool factionUsesResourceType(const ResourceType *rt) const;
void deletePixels ();
bool factionUsesResourceType (const ResourceType * rt) const;
};
};
}}//end namespace
}} //end namespace
#endif

View File

@@ -1,12 +1,12 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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 "object_type.h"
@@ -14,48 +14,68 @@
#include "renderer.h"
#include "leak_dumper.h"
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
// =====================================================
// class ObjectType
// class ObjectType
// =====================================================
void ObjectType::init(int modelCount, int objectClass, bool walkable, int height) {
// modeltypes.reserve(modelCount);
this->objectClass= objectClass;
this->walkable= walkable;
this->height = height;
}
void ObjectType::init (int modelCount, int objectClass, bool walkable,
int height)
{
// modeltypes.reserve(modelCount);
this->objectClass = objectClass;
this->walkable = walkable;
this->height = height;
}
ObjectType::~ObjectType(){
while(!(modeltypes.empty())){
delete modeltypes.back();
modeltypes.pop_back();
//Logger::getInstance().add("ObjectType", true);
}
}
ObjectType::~ObjectType ()
{
while (!(modeltypes.empty ()))
{
delete modeltypes.back ();
modeltypes.pop_back ();
//Logger::getInstance().add("ObjectType", true);
}
}
TilesetModelType* ObjectType::loadModel(const string &path, std::map<string,vector<pair<string, string> > > *loadedFileList,
string parentLoader) {
Model *model= Renderer::getInstance().newModel(rsGame, path, false, loadedFileList, &parentLoader);
color= Vec3f(0.f);
if(model && model->getMeshCount()>0 && model->getMesh(0)->getTexture(0) != NULL) {
const Pixmap2D *p= model->getMesh(0)->getTexture(0)->getPixmapConst();
color= p->getPixel3f(p->getW()/2, p->getH()/2);
}
TilesetModelType *modelType=new TilesetModelType();
modelType->setModel(model);
modeltypes.push_back(modelType);
return modelType;
}
TilesetModelType *ObjectType::loadModel (const string & path,
std::map < string,
vector < pair < string,
string > > >*loadedFileList,
string parentLoader)
{
Model *model =
Renderer::getInstance ().newModel (rsGame, path, false,
loadedFileList, &parentLoader);
color = Vec3f (0.f);
if (model && model->getMeshCount () > 0
&& model->getMesh (0)->getTexture (0) != NULL)
{
const Pixmap2D *p =
model->getMesh (0)->getTexture (0)->getPixmapConst ();
color = p->getPixel3f (p->getW () / 2, p->getH () / 2);
}
TilesetModelType *modelType = new TilesetModelType ();
modelType->setModel (model);
modeltypes.push_back (modelType);
return modelType;
}
void ObjectType::deletePixels() {
for(int i = 0; i < (int)modeltypes.size(); ++i) {
TilesetModelType *model = modeltypes[i];
if(model->getModel() != NULL) {
model->getModel()->deletePixels();
}
}
}
void ObjectType::deletePixels ()
{
for (int i = 0; i < (int) modeltypes.size (); ++i)
{
TilesetModelType *model = modeltypes[i];
if (model->getModel () != NULL)
{
model->getModel ()->deletePixels ();
}
}
}
}}//end namespace
}
} //end namespace

View File

@@ -1,81 +1,109 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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_OBJECTTYPE_H_
#define _GLEST_GAME_OBJECTTYPE_H_
# define _GLEST_GAME_OBJECTTYPE_H_
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#endif
# ifdef WIN32
# include <winsock2.h>
# include <winsock.h>
# endif
#include <vector>
#include "model.h"
#include "vec.h"
#include "leak_dumper.h"
#include "unit_particle_type.h"
#include "tileset_model_type.h"
# include <vector>
# include "model.h"
# include "vec.h"
# include "leak_dumper.h"
# include "unit_particle_type.h"
# include "tileset_model_type.h"
using std::vector;
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
using Shared::Graphics::Model;
using Shared::Graphics::Vec3f;
using Shared::Graphics::Model;
using Shared::Graphics::Vec3f;
// =====================================================
// class ObjectType
// class ObjectType
//
/// Each of the possible objects of the map: trees, stones ...
/// Each of the possible objects of the map: trees, stones ...
// =====================================================
typedef vector<ObjectParticleSystemType*> ObjectParticleSystemTypes;
typedef vector<ObjectParticleSystemTypes> ObjectParticleVector;
typedef vector < ObjectParticleSystemType * >ObjectParticleSystemTypes;
typedef vector < ObjectParticleSystemTypes > ObjectParticleVector;
class ObjectType {
private:
typedef vector<TilesetModelType*> ModelTypes;
private:
static const int tree1= 0;
static const int tree2= 1;
static const int choppedTree= 2;
class ObjectType
{
private:
typedef vector < TilesetModelType * >ModelTypes;
private:
static const int tree1 = 0;
static const int tree2 = 1;
static const int choppedTree = 2;
private:
ModelTypes modeltypes;
Vec3f color;
int objectClass;
bool walkable;
int height;
private:
ModelTypes modeltypes;
Vec3f color;
int objectClass;
bool walkable;
int height;
public:
ObjectType() {
objectClass = -1;
walkable = false;
height = 0;
}
~ObjectType();
void init(int modelCount, int objectClass, bool walkable, int height);
public:
ObjectType ()
{
objectClass = -1;
walkable = false;
height = 0;
}
~ObjectType ();
void init (int modelCount, int objectClass, bool walkable, int height);
TilesetModelType* loadModel(const string &path, std::map<string,vector<pair<string, string> > > *loadedFileList=NULL,
string parentLoader="");
TilesetModelType *loadModel (const string & path, std::map < string,
vector < pair < string,
string > > >*loadedFileList =
NULL, string parentLoader = "");
inline TilesetModelType *getTilesetModelType(int i) {return modeltypes[i];}
inline int getModelCount() const {return (int)modeltypes.size();}
inline const Vec3f &getColor() const {return color;}
inline int getClass() const {return objectClass;}
inline bool getWalkable() const {return walkable;}
inline int getHeight() const {return height;}
inline bool isATree() const {return objectClass==tree1 || objectClass==tree2;}
void deletePixels();
};
inline TilesetModelType *getTilesetModelType (int i)
{
return modeltypes[i];
}
inline int getModelCount () const
{
return (int) modeltypes.size ();
}
inline const Vec3f & getColor () const
{
return color;
}
inline int getClass () const
{
return objectClass;
}
inline bool getWalkable () const
{
return walkable;
}
inline int getHeight () const
{
return height;
}
inline bool isATree () const
{
return objectClass == tree1 || objectClass == tree2;
}
void deletePixels ();
};
}}//end namespace
}} //end namespace
#endif

View File

@@ -1,12 +1,12 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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 <cassert>
@@ -17,110 +17,164 @@
using namespace Shared::Util;
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
ProjectileType::ProjectileType() {
ProjectileType::ProjectileType ()
{
projectileParticleSystemType=NULL;
attackStartTime=0.0f;
projectileParticleSystemType = NULL;
attackStartTime = 0.0f;
spawnUnit="";
spawnUnitcount=0;
spawnUnitAtTarget=false;
spawnUnit = "";
spawnUnitcount = 0;
spawnUnitAtTarget = false;
shake=false;
shakeIntensity=0;
shakeDuration=0;
shake = false;
shakeIntensity = 0;
shakeDuration = 0;
shakeVisible=true;
shakeInCameraView=true;
shakeCameraDistanceAffected=false;
damagePercentage=100;
}
shakeVisible = true;
shakeInCameraView = true;
shakeCameraDistanceAffected = false;
damagePercentage = 100;
}
ProjectileType::~ProjectileType() {
deleteValues(hitSounds.getSounds().begin(), hitSounds.getSounds().end());
if(projectileParticleSystemType!=NULL){
delete projectileParticleSystemType;
projectileParticleSystemType = NULL;
}
}
ProjectileType::~ProjectileType ()
{
deleteValues (hitSounds.getSounds ().begin (),
hitSounds.getSounds ().end ());
if (projectileParticleSystemType != NULL)
{
delete projectileParticleSystemType;
projectileParticleSystemType = NULL;
}
}
void ProjectileType::load(const XmlNode *projectileNode, const string &dir, const string &techtreepath, std::map<string,vector<pair<string, string> > > &loadedFileList,
string parentLoader){
void ProjectileType::load (const XmlNode * projectileNode,
const string & dir,
const string & techtreepath, std::map < string,
vector < pair < string,
string > > >&loadedFileList,
string parentLoader)
{
string currentPath = dir;
endPathWithSlash(currentPath);
string currentPath = dir;
endPathWithSlash (currentPath);
if(projectileNode->hasAttribute("attack-start-time")){
attackStartTime =projectileNode->getAttribute("attack-start-time")->getFloatValue();
}
else
{
attackStartTime=0.0f;
}
if (projectileNode->hasAttribute ("attack-start-time"))
{
attackStartTime =
projectileNode->getAttribute ("attack-start-time")->
getFloatValue ();
}
else
{
attackStartTime = 0.0f;
}
// damage percentage MUST be set!
damagePercentage =projectileNode->getAttribute("damage-percentage")->getIntValue();
// damage percentage MUST be set!
damagePercentage =
projectileNode->getAttribute ("damage-percentage")->getIntValue ();
// projectiles MUST have a particle system.
const XmlNode *particleNode= projectileNode->getChild("particle");
string path= particleNode->getAttribute("path")->getRestrictedValue();
ParticleSystemTypeProjectile* projectileParticleSystemType= new ParticleSystemTypeProjectile();
projectileParticleSystemType->load(particleNode, dir, currentPath + path,
&Renderer::getInstance(), loadedFileList, parentLoader,
techtreepath);
loadedFileList[currentPath + path].push_back(make_pair(parentLoader,particleNode->getAttribute("path")->getRestrictedValue()));
setProjectileParticleSystemType(projectileParticleSystemType);
// projectiles MUST have a particle system.
const XmlNode *particleNode = projectileNode->getChild ("particle");
string path =
particleNode->getAttribute ("path")->getRestrictedValue ();
ParticleSystemTypeProjectile *projectileParticleSystemType =
new ParticleSystemTypeProjectile ();
projectileParticleSystemType->load (particleNode, dir,
currentPath + path,
&Renderer::getInstance (),
loadedFileList, parentLoader,
techtreepath);
loadedFileList[currentPath +
path].push_back (make_pair (parentLoader,
particleNode->
getAttribute ("path")->
getRestrictedValue ()));
setProjectileParticleSystemType (projectileParticleSystemType);
//spawnattack
if (projectileNode->hasChild("unit")) {
spawnUnit = projectileNode->getChild("unit")->getAttribute("value")->getValue();
spawnUnitcount = projectileNode->getChild("unit")->getAttribute("amount")->getIntValue();
if(projectileNode->getChild("unit")->hasAttribute("spawnAtTarget")) {
spawnUnitAtTarget = projectileNode->getChild("unit")->getAttribute("spawnAtTarget")->getBoolValue();
} else {
spawnUnitAtTarget = false;
}
} else {
spawnUnit = "";
spawnUnitcount = 0;
spawnUnitAtTarget = false;
}
//spawnattack
if (projectileNode->hasChild ("unit"))
{
spawnUnit =
projectileNode->getChild ("unit")->getAttribute ("value")->
getValue ();
spawnUnitcount =
projectileNode->getChild ("unit")->getAttribute ("amount")->
getIntValue ();
if (projectileNode->getChild ("unit")->hasAttribute ("spawnAtTarget"))
{
spawnUnitAtTarget =
projectileNode->getChild ("unit")->
getAttribute ("spawnAtTarget")->getBoolValue ();
}
else
{
spawnUnitAtTarget = false;
}
}
else
{
spawnUnit = "";
spawnUnitcount = 0;
spawnUnitAtTarget = false;
}
if(projectileNode->hasChild("hitshake")){
const XmlNode *hitShakeNode= projectileNode->getChild("hitshake");
shake=hitShakeNode->getAttribute("enabled")->getBoolValue();
if(shake){
shakeIntensity=hitShakeNode->getAttribute("intensity")->getIntValue();
shakeDuration=hitShakeNode->getAttribute("duration")->getIntValue();
if (projectileNode->hasChild ("hitshake"))
{
const XmlNode *hitShakeNode = projectileNode->getChild ("hitshake");
shake = hitShakeNode->getAttribute ("enabled")->getBoolValue ();
if (shake)
{
shakeIntensity =
hitShakeNode->getAttribute ("intensity")->getIntValue ();
shakeDuration =
hitShakeNode->getAttribute ("duration")->getIntValue ();
shakeVisible=hitShakeNode->getAttribute("visible")->getBoolValue();
shakeInCameraView=hitShakeNode->getAttribute("in-camera-view")->getBoolValue();
shakeCameraDistanceAffected=hitShakeNode->getAttribute("camera-distance-affected")->getBoolValue();
}
}
shakeVisible =
hitShakeNode->getAttribute ("visible")->getBoolValue ();
shakeInCameraView =
hitShakeNode->getAttribute ("in-camera-view")->getBoolValue ();
shakeCameraDistanceAffected =
hitShakeNode->getAttribute ("camera-distance-affected")->
getBoolValue ();
}
}
if(projectileNode->hasChild("hitsound")){
const XmlNode *soundNode= projectileNode->getChild("hitsound");
if(soundNode->getAttribute("enabled")->getBoolValue()){
if (projectileNode->hasChild ("hitsound"))
{
const XmlNode *soundNode = projectileNode->getChild ("hitsound");
if (soundNode->getAttribute ("enabled")->getBoolValue ())
{
hitSounds.resize((int)soundNode->getChildCount());
for(int i=0; i < (int)soundNode->getChildCount(); ++i){
const XmlNode *soundFileNode= soundNode->getChild("sound-file", i);
string path= soundFileNode->getAttribute("path")->getRestrictedValue(currentPath, true);
//printf("\n\n\n\n!@#$ ---> parentLoader [%s] path [%s] nodeValue [%s] i = %d",parentLoader.c_str(),path.c_str(),soundFileNode->getAttribute("path")->getRestrictedValue().c_str(),i);
hitSounds.resize ((int) soundNode->getChildCount ());
for (int i = 0; i < (int) soundNode->getChildCount (); ++i)
{
const XmlNode *soundFileNode =
soundNode->getChild ("sound-file", i);
string path =
soundFileNode->getAttribute ("path")->
getRestrictedValue (currentPath, true);
//printf("\n\n\n\n!@#$ ---> parentLoader [%s] path [%s] nodeValue [%s] i = %d",parentLoader.c_str(),path.c_str(),soundFileNode->getAttribute("path")->getRestrictedValue().c_str(),i);
StaticSound *sound= new StaticSound();
sound->load(path);
loadedFileList[path].push_back(make_pair(parentLoader,soundFileNode->getAttribute("path")->getRestrictedValue()));
hitSounds[i]= sound;
}
}
}
}
StaticSound *sound = new StaticSound ();
sound->load (path);
loadedFileList[path].
push_back (make_pair
(parentLoader,
soundFileNode->getAttribute ("path")->
getRestrictedValue ()));
hitSounds[i] = sound;
}
}
}
}
}}//end namespace
}} //end namespace

View File

@@ -1,90 +1,149 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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_PROJEKTILETYPE_H_
#define _GLEST_GAME_PROJEKTILETYPE_H_
# define _GLEST_GAME_PROJEKTILETYPE_H_
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#endif
# ifdef WIN32
# include <winsock2.h>
# include <winsock.h>
# endif
#include "sound.h"
#include "vec.h"
# include "sound.h"
# include "vec.h"
//#include "xml_parser.h"
#include "util.h"
# include "util.h"
//#include "element_type.h"
#include "factory.h"
#include "sound_container.h"
#include "particle_type.h"
#include "leak_dumper.h"
# include "factory.h"
# include "sound_container.h"
# include "particle_type.h"
# include "leak_dumper.h"
using std::vector;
using std::string;
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
// =====================================================
// class ProjectileType
// class ProjectileType
// =====================================================
class ProjectileType {
protected:
ParticleSystemTypeProjectile* projectileParticleSystemType;
SoundContainer hitSounds;
float attackStartTime;
class ProjectileType
{
protected:
ParticleSystemTypeProjectile * projectileParticleSystemType;
SoundContainer hitSounds;
float attackStartTime;
string spawnUnit;
int spawnUnitcount;
bool spawnUnitAtTarget;
string spawnUnit;
int spawnUnitcount;
bool spawnUnitAtTarget;
bool shake;
int shakeIntensity;
int shakeDuration;
bool shake;
int shakeIntensity;
int shakeDuration;
bool shakeVisible;
bool shakeInCameraView;
bool shakeCameraDistanceAffected;
int damagePercentage;
bool shakeVisible;
bool shakeInCameraView;
bool shakeCameraDistanceAffected;
int damagePercentage;
public:
ProjectileType();
virtual ~ProjectileType();
public:
ProjectileType ();
virtual ~ ProjectileType ();
void load(const XmlNode *projectileNode, const string &dir, const string &techtreepath, std::map<string,vector<pair<string, string> > > &loadedFileList,
string parentLoader);
void load (const XmlNode * projectileNode, const string & dir,
const string & techtreepath, std::map < string,
vector < pair < string, string > > >&loadedFileList,
string parentLoader);
//get/set
inline StaticSound *getHitSound() const {return hitSounds.getRandSound();}
ParticleSystemTypeProjectile* getProjectileParticleSystemType() const { return projectileParticleSystemType;}
float getAttackStartTime() const {return attackStartTime;}
void setAttackStartTime(float value) {attackStartTime=value;}
//get/set
inline StaticSound *getHitSound () const
{
return hitSounds.getRandSound ();
}
ParticleSystemTypeProjectile *getProjectileParticleSystemType () const
{
return projectileParticleSystemType;
}
float getAttackStartTime () const
{
return attackStartTime;
}
void setAttackStartTime (float value)
{
attackStartTime = value;
}
string getSpawnUnit() const{return spawnUnit;}
int getSpawnUnitcount() const{return spawnUnitcount;}
bool getSpawnUnitAtTarget() const{return spawnUnitAtTarget;}
string getSpawnUnit () const
{
return spawnUnit;
}
int getSpawnUnitcount () const
{
return spawnUnitcount;
}
bool getSpawnUnitAtTarget () const
{
return spawnUnitAtTarget;
}
bool isShake() const{return shake;}
bool isShakeCameraDistanceAffected() const{return shakeCameraDistanceAffected;}
int getShakeDuration() const{return shakeDuration;}
bool isShakeInCameraView() const{return shakeInCameraView;}
int getShakeIntensity() const{return shakeIntensity;}
bool isShakeVisible() const{return shakeVisible;}
int getDamagePercentage() const {return damagePercentage;}
void setDamagePercentage(int value) {damagePercentage=value;}
bool isShake () const
{
return shake;
}
bool isShakeCameraDistanceAffected () const
{
return shakeCameraDistanceAffected;
}
int getShakeDuration () const
{
return shakeDuration;
}
bool isShakeInCameraView () const
{
return shakeInCameraView;
}
int getShakeIntensity () const
{
return shakeIntensity;
}
bool isShakeVisible () const
{
return shakeVisible;
}
int getDamagePercentage () const
{
return damagePercentage;
}
void setDamagePercentage (int value)
{
damagePercentage = value;
}
void setProjectileParticleSystemType(ParticleSystemTypeProjectile *pointer) {projectileParticleSystemType=pointer;}
ParticleSystemTypeProjectile* getProjectileParticleSystemType() {return projectileParticleSystemType;}
};
void setProjectileParticleSystemType (ParticleSystemTypeProjectile *
pointer)
{
projectileParticleSystemType = pointer;
}
ParticleSystemTypeProjectile *getProjectileParticleSystemType ()
{
return projectileParticleSystemType;
}
};
}}//end namespace
}
} //end namespace
#endif

View File

@@ -1,12 +1,12 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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 "resource_type.h"
@@ -24,231 +24,335 @@
using namespace Shared::Util;
using namespace Shared::Xml;
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
// =====================================================
// class ResourceType
// class ResourceType
// =====================================================
ResourceType::ResourceType() {
resourceClass=rcTech;
tilesetObject=0;
resourceNumber=0;
interval=0;
defResPerPatch=0;
recoup_cost = false;
model = NULL;
displayInHud = false;
cleanupMemory = true;
}
ResourceType::~ResourceType() {
if(cleanupMemory == true) {
while(particleTypes.empty() == false) {
delete particleTypes.back();
particleTypes.pop_back();
}
}
}
string ResourceType::getName(bool translatedValue) const {
if(translatedValue == false) return name;
Lang &lang = Lang::getInstance();
return lang.getTechTreeString("ResourceTypeName_" + name,name.c_str());
}
void ResourceType::load(const string &dir, Checksum* checksum, Checksum *techtreeChecksum,
std::map<string,vector<pair<string, string> > > &loadedFileList, string techtreePath) {
string path, str;
Renderer &renderer= Renderer::getInstance();
try
{
recoup_cost = true;
name= lastDir(dir);
char szBuf[8096]="";
snprintf(szBuf,8096,Lang::getInstance().getString("LogScreenGameLoadingResourceType","",true).c_str(),formatString(getName(true)).c_str());
Logger::getInstance().add(szBuf, true);
string currentPath = dir;
endPathWithSlash(currentPath);
path= currentPath + name + ".xml";
string sourceXMLFile = path;
checksum->addFile(path);
techtreeChecksum->addFile(path);
//tree
XmlTree xmlTree;
std::map<string,string> mapExtraTagReplacementValues;
mapExtraTagReplacementValues["$COMMONDATAPATH"] = techtreePath + "/commondata/";
xmlTree.load(path, Properties::getTagReplacementValues(&mapExtraTagReplacementValues));
loadedFileList[path].push_back(make_pair(currentPath,currentPath));
const XmlNode *resourceNode= xmlTree.getRootNode();
//image
const XmlNode *imageNode= resourceNode->getChild("image");
image= renderer.newTexture2D(rsGame);
if(image) {
image->load(imageNode->getAttribute("path")->getRestrictedValue(currentPath));
}
loadedFileList[imageNode->getAttribute("path")->getRestrictedValue(currentPath)].push_back(make_pair(sourceXMLFile,imageNode->getAttribute("path")->getRestrictedValue()));
//type
const XmlNode *typeNode= resourceNode->getChild("type");
resourceClass = strToRc(typeNode->getAttribute("value")->getRestrictedValue());
switch(resourceClass)
{
case rcTech:
{
//model
const XmlNode *modelNode= typeNode->getChild("model");
string modelPath= modelNode->getAttribute("path")->getRestrictedValue(currentPath);
model= renderer.newModel(rsGame, modelPath, false, &loadedFileList, &sourceXMLFile);
loadedFileList[modelPath].push_back(make_pair(sourceXMLFile,modelNode->getAttribute("path")->getRestrictedValue()));
if(modelNode->hasChild("particles")){
const XmlNode *particleNode= modelNode->getChild("particles");
bool particleEnabled= particleNode->getAttribute("value")->getBoolValue();
if(particleEnabled == true) {
for(int k= 0; k < (int)particleNode->getChildCount(); ++k) {
const XmlNode *particleFileNode= particleNode->getChild("particle-file", k);
string particlePath= particleFileNode->getAttribute("path")->getRestrictedValue();
ObjectParticleSystemType *objectParticleSystemType= new ObjectParticleSystemType();
objectParticleSystemType->load(particleFileNode, dir, currentPath + particlePath,
&Renderer::getInstance(), loadedFileList, sourceXMLFile, techtreePath);
loadedFileList[currentPath + particlePath].push_back(make_pair(sourceXMLFile,particleFileNode->getAttribute("path")->getRestrictedValue()));
particleTypes.push_back(objectParticleSystemType);
}
}
}
//default resources
const XmlNode *defaultAmountNode= typeNode->getChild("default-amount");
defResPerPatch= defaultAmountNode->getAttribute("value")->getIntValue();
//resource number
const XmlNode *resourceNumberNode= typeNode->getChild("resource-number");
resourceNumber= resourceNumberNode->getAttribute("value")->getIntValue();
}
break;
case rcTileset:
{
//resource number
const XmlNode *defaultAmountNode= typeNode->getChild("default-amount");
defResPerPatch= defaultAmountNode->getAttribute("value")->getIntValue();
//resource number
const XmlNode *tilesetObjectNode= typeNode->getChild("tileset-object");
tilesetObject= tilesetObjectNode->getAttribute("value")->getIntValue();
}
break;
case rcConsumable:
{
//interval
const XmlNode *intervalNode= typeNode->getChild("interval");
interval= intervalNode->getAttribute("value")->getIntValue();
}
break;
case rcStatic:
{
//recoup_cost
if(typeNode->hasChild("recoup_cost") == true) {
const XmlNode *recoup_costNode= typeNode->getChild("recoup_cost");
if(recoup_costNode != NULL) {
recoup_cost= recoup_costNode->getAttribute("value")->getBoolValue();
}
}
}
break;
default:
break;
}
//displayInHud
if(resourceNode->hasChild("display") == true) {
const XmlNode *displayNode= resourceNode->getChild("display");
displayInHud= displayNode->getAttribute("value")->getBoolValue();
}
else {
displayInHud=true;
}
}
catch(megaglest_runtime_error& ex) {
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",extractFileFromDirectoryPath(__FILE__).c_str(),__FUNCTION__,__LINE__,ex.what());
throw megaglest_runtime_error("Error loading resource type: "+ path + "\nMessage: " + ex.what(),!ex.wantStackTrace());
ResourceType::ResourceType ()
{
resourceClass = rcTech;
tilesetObject = 0;
resourceNumber = 0;
interval = 0;
defResPerPatch = 0;
recoup_cost = false;
model = NULL;
displayInHud = false;
cleanupMemory = true;
}
ResourceType::~ResourceType ()
{
if (cleanupMemory == true)
{
while (particleTypes.empty () == false)
{
delete particleTypes.back ();
particleTypes.pop_back ();
}
}
}
string ResourceType::getName (bool translatedValue) const
{
if (translatedValue == false)
return name;
Lang & lang = Lang::getInstance ();
return lang.getTechTreeString ("ResourceTypeName_" + name,
name.c_str ());
}
void ResourceType::load (const string & dir, Checksum * checksum,
Checksum * techtreeChecksum, std::map < string,
vector < pair < string,
string > > >&loadedFileList, string techtreePath)
{
string path, str;
Renderer & renderer = Renderer::getInstance ();
try
{
recoup_cost = true;
name = lastDir (dir);
char szBuf[8096] = "";
snprintf (szBuf, 8096,
Lang::getInstance ().
getString ("LogScreenGameLoadingResourceType", "",
true).c_str (),
formatString (getName (true)).c_str ());
Logger::getInstance ().add (szBuf, true);
string currentPath = dir;
endPathWithSlash (currentPath);
path = currentPath + name + ".xml";
string sourceXMLFile = path;
checksum->addFile (path);
techtreeChecksum->addFile (path);
//tree
XmlTree xmlTree;
std::map < string, string > mapExtraTagReplacementValues;
mapExtraTagReplacementValues["$COMMONDATAPATH"] =
techtreePath + "/commondata/";
xmlTree.load (path,
Properties::
getTagReplacementValues
(&mapExtraTagReplacementValues));
loadedFileList[path].push_back (make_pair (currentPath, currentPath));
const XmlNode *resourceNode = xmlTree.getRootNode ();
//image
const XmlNode *imageNode = resourceNode->getChild ("image");
image = renderer.newTexture2D (rsGame);
if (image)
{
image->load (imageNode->getAttribute ("path")->
getRestrictedValue (currentPath));
}
loadedFileList[imageNode->getAttribute ("path")->
getRestrictedValue (currentPath)].
push_back (make_pair
(sourceXMLFile,
imageNode->getAttribute ("path")->
getRestrictedValue ()));
//type
const XmlNode *typeNode = resourceNode->getChild ("type");
resourceClass =
strToRc (typeNode->getAttribute ("value")->getRestrictedValue ());
switch (resourceClass)
{
case rcTech:
{
//model
const XmlNode *modelNode = typeNode->getChild ("model");
string modelPath =
modelNode->getAttribute ("path")->
getRestrictedValue (currentPath);
model =
renderer.newModel (rsGame, modelPath, false, &loadedFileList,
&sourceXMLFile);
loadedFileList[modelPath].
push_back (make_pair
(sourceXMLFile,
modelNode->getAttribute ("path")->
getRestrictedValue ()));
if (modelNode->hasChild ("particles"))
{
const XmlNode *particleNode = modelNode->getChild ("particles");
bool particleEnabled =
particleNode->getAttribute ("value")->getBoolValue ();
if (particleEnabled == true)
{
for (int k = 0; k < (int) particleNode->getChildCount (); ++k)
{
const XmlNode *particleFileNode =
particleNode->getChild ("particle-file", k);
string particlePath =
particleFileNode->getAttribute ("path")->
getRestrictedValue ();
ObjectParticleSystemType *objectParticleSystemType =
new ObjectParticleSystemType ();
objectParticleSystemType->load (particleFileNode, dir,
currentPath + particlePath,
&Renderer::getInstance (),
loadedFileList,
sourceXMLFile,
techtreePath);
loadedFileList[currentPath +
particlePath].
push_back (make_pair
(sourceXMLFile,
particleFileNode->getAttribute ("path")->
getRestrictedValue ()));
particleTypes.push_back (objectParticleSystemType);
}
}
}
//default resources
const XmlNode *defaultAmountNode =
typeNode->getChild ("default-amount");
defResPerPatch =
defaultAmountNode->getAttribute ("value")->getIntValue ();
//resource number
const XmlNode *resourceNumberNode =
typeNode->getChild ("resource-number");
resourceNumber =
resourceNumberNode->getAttribute ("value")->getIntValue ();
}
break;
case rcTileset:
{
//resource number
const XmlNode *defaultAmountNode =
typeNode->getChild ("default-amount");
defResPerPatch =
defaultAmountNode->getAttribute ("value")->getIntValue ();
//resource number
const XmlNode *tilesetObjectNode =
typeNode->getChild ("tileset-object");
tilesetObject =
tilesetObjectNode->getAttribute ("value")->getIntValue ();
}
break;
case rcConsumable:
{
//interval
const XmlNode *intervalNode = typeNode->getChild ("interval");
interval = intervalNode->getAttribute ("value")->getIntValue ();
}
break;
case rcStatic:
{
//recoup_cost
if (typeNode->hasChild ("recoup_cost") == true)
{
const XmlNode *recoup_costNode =
typeNode->getChild ("recoup_cost");
if (recoup_costNode != NULL)
{
recoup_cost =
recoup_costNode->getAttribute ("value")->getBoolValue ();
}
}
}
break;
default:
break;
}
//displayInHud
if (resourceNode->hasChild ("display") == true)
{
const XmlNode *displayNode = resourceNode->getChild ("display");
displayInHud = displayNode->getAttribute ("value")->getBoolValue ();
}
else
{
displayInHud = true;
}
}
catch (megaglest_runtime_error & ex)
{
SystemFlags::OutputDebug (SystemFlags::debugError,
"In [%s::%s Line: %d] Error [%s]\n",
extractFileFromDirectoryPath (__FILE__).
c_str (), __FUNCTION__, __LINE__,
ex.what ());
throw megaglest_runtime_error ("Error loading resource type: " +
path + "\nMessage: " + ex.what (),
!ex.wantStackTrace ());
}
catch (const exception & e)
{
SystemFlags::OutputDebug (SystemFlags::debugError,
"In [%s::%s Line: %d] Error [%s]\n",
__FILE__, __FUNCTION__, __LINE__,
e.what ());
throw megaglest_runtime_error ("Error loading resource type: " +
path + "\n" + e.what ());
}
}
catch(const exception &e){
SystemFlags::OutputDebug(SystemFlags::debugError,"In [%s::%s Line: %d] Error [%s]\n",__FILE__,__FUNCTION__,__LINE__,e.what());
throw megaglest_runtime_error("Error loading resource type: " + path + "\n" + e.what());
}
}
// ==================== misc ====================
ResourceClass ResourceType::strToRc(const string &s){
if(s=="tech"){
ResourceClass ResourceType::strToRc (const string & s)
{
if (s == "tech")
{
return rcTech;
}
if(s=="tileset"){
}
if (s == "tileset")
{
return rcTileset;
}
if(s=="static"){
}
if (s == "static")
{
return rcStatic;
}
if(s=="consumable"){
}
if (s == "consumable")
{
return rcConsumable;
}
throw megaglest_runtime_error("Error converting from string ro resourceClass, found: " + s);
}
}
throw
megaglest_runtime_error
("Error converting from string ro resourceClass, found: " + s);
}
void ResourceType::deletePixels() {
if(model != NULL) {
model->deletePixels();
}
}
void ResourceType::deletePixels ()
{
if (model != NULL)
{
model->deletePixels ();
}
}
void ResourceType::saveGame(XmlNode *rootNode) {
//DisplayableType::saveGame(rootNode);
void ResourceType::saveGame (XmlNode * rootNode)
{
//DisplayableType::saveGame(rootNode);
std::map<string,string> mapTagReplacements;
XmlNode *resourceTypeNode = rootNode->addChild("ResourceType");
std::map < string, string > mapTagReplacements;
XmlNode *resourceTypeNode = rootNode->addChild ("ResourceType");
resourceTypeNode->addAttribute("name",this->getName(), mapTagReplacements);
resourceTypeNode->addAttribute ("name", this->getName (),
mapTagReplacements);
// ResourceClass resourceClass;
resourceTypeNode->addAttribute("resourceClass",intToStr(resourceClass), mapTagReplacements);
// int tilesetObject; //used only if class==rcTileset
resourceTypeNode->addAttribute("tilesetObject",intToStr(tilesetObject), mapTagReplacements);
// int resourceNumber; //used only if class==rcTech, resource number in the map
resourceTypeNode->addAttribute("resourceNumber",intToStr(resourceNumber), mapTagReplacements);
// int interval; //used only if class==rcConsumable
resourceTypeNode->addAttribute("interval",intToStr(interval), mapTagReplacements);
// int defResPerPatch; //used only if class==rcTileset || class==rcTech
resourceTypeNode->addAttribute("defResPerPatch",intToStr(defResPerPatch), mapTagReplacements);
// bool recoup_cost;
resourceTypeNode->addAttribute("recoup_cost",intToStr(recoup_cost), mapTagReplacements);
resourceTypeNode->addAttribute ("resourceClass",
intToStr (resourceClass),
mapTagReplacements);
// int tilesetObject; //used only if class==rcTileset
resourceTypeNode->addAttribute ("tilesetObject",
intToStr (tilesetObject),
mapTagReplacements);
// int resourceNumber; //used only if class==rcTech, resource number in the map
resourceTypeNode->addAttribute ("resourceNumber",
intToStr (resourceNumber),
mapTagReplacements);
// int interval; //used only if class==rcConsumable
resourceTypeNode->addAttribute ("interval", intToStr (interval),
mapTagReplacements);
// int defResPerPatch; //used only if class==rcTileset || class==rcTech
resourceTypeNode->addAttribute ("defResPerPatch",
intToStr (defResPerPatch),
mapTagReplacements);
// bool recoup_cost;
resourceTypeNode->addAttribute ("recoup_cost", intToStr (recoup_cost),
mapTagReplacements);
//
// Model *model;
if(model != NULL) {
resourceTypeNode->addAttribute("model",model->getFileName(), mapTagReplacements);
}
if (model != NULL)
{
resourceTypeNode->addAttribute ("model", model->getFileName (),
mapTagReplacements);
}
// ObjectParticleSystemTypes particleTypes;
for(unsigned int i = 0; i < particleTypes.size(); ++i) {
ObjectParticleSystemType *opst = particleTypes[i];
opst->saveGame(resourceTypeNode);
}
}
for (unsigned int i = 0; i < particleTypes.size (); ++i)
{
ObjectParticleSystemType *opst = particleTypes[i];
opst->saveGame (resourceTypeNode);
}
}
}}//end namespace
}} //end namespace

View File

@@ -1,91 +1,130 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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_RESOURCETYPE_H_
#define _GLEST_GAME_RESOURCETYPE_H_
# define _GLEST_GAME_RESOURCETYPE_H_
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#endif
# ifdef WIN32
# include <winsock2.h>
# include <winsock.h>
# endif
#include "element_type.h"
#include "model.h"
#include "checksum.h"
#include "leak_dumper.h"
#include "unit_particle_type.h"
#include "object_type.h"
# include "element_type.h"
# include "model.h"
# include "checksum.h"
# include "leak_dumper.h"
# include "unit_particle_type.h"
# include "object_type.h"
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
using Shared::Graphics::Model;
using Shared::Util::Checksum;
using Shared::Graphics::Model;
using Shared::Util::Checksum;
enum ResourceClass{
rcTech,
rcTileset,
rcStatic,
rcConsumable
};
enum ResourceClass
{
rcTech,
rcTileset,
rcStatic,
rcConsumable
};
// =====================================================
// class ResourceType
// class ResourceType
//
/// A type of resource that can be harvested or not
/// A type of resource that can be harvested or not
// =====================================================
class ResourceType: public DisplayableType{
private:
ResourceClass resourceClass;
int tilesetObject; //used only if class==rcTileset
int resourceNumber; //used only if class==rcTech, resource number in the map
int interval; //used only if class==rcConsumable
int defResPerPatch; //used only if class==rcTileset || class==rcTech
bool recoup_cost;
bool displayInHud;
class ResourceType:public DisplayableType
{
private:
ResourceClass resourceClass;
int tilesetObject; //used only if class==rcTileset
int resourceNumber; //used only if class==rcTech, resource number in the map
int interval; //used only if class==rcConsumable
int defResPerPatch; //used only if class==rcTileset || class==rcTech
bool recoup_cost;
bool displayInHud;
Model *model;
ObjectParticleSystemTypes particleTypes;
bool cleanupMemory;
Model *model;
ObjectParticleSystemTypes particleTypes;
bool cleanupMemory;
public:
ResourceType();
~ResourceType();
void load(const string &dir, Checksum* checksum,Checksum *techtreeChecksum,
std::map<string,vector<pair<string, string> > > &loadedFileList,
string techtreePath);
public:
ResourceType ();
~ResourceType ();
void load (const string & dir, Checksum * checksum,
Checksum * techtreeChecksum, std::map < string,
vector < pair < string, string > > >&loadedFileList,
string techtreePath);
virtual string getName(bool translatedValue=false) const;
//get
int getClass() const {return resourceClass;}
int getTilesetObject() const {return tilesetObject;}
int getResourceNumber() const {return resourceNumber;}
int getInterval() const {return interval;}
int getDefResPerPatch() const {return defResPerPatch;}
Model *getModel() const {return model;}
bool getRecoup_cost() const { return recoup_cost;}
bool getDisplayInHud() const { return displayInHud;}
virtual string getName (bool translatedValue = false) const;
//get
int getClass () const
{
return resourceClass;
}
int getTilesetObject () const
{
return tilesetObject;
}
int getResourceNumber () const
{
return resourceNumber;
}
int getInterval () const
{
return interval;
}
int getDefResPerPatch () const
{
return defResPerPatch;
}
Model *getModel () const
{
return model;
}
bool getRecoup_cost () const
{
return recoup_cost;
}
bool getDisplayInHud () const
{
return displayInHud;
}
bool hasParticles() const {return !particleTypes.empty();}
const ObjectParticleSystemTypes *getObjectParticleSystemTypes() const {return &particleTypes;}
bool hasParticles () const
{
return !particleTypes.empty ();
}
const ObjectParticleSystemTypes *getObjectParticleSystemTypes () const
{
return &particleTypes;
}
void setCleanupMemory(bool value) { cleanupMemory = value; }
void setCleanupMemory (bool value)
{
cleanupMemory = value;
}
static ResourceClass strToRc(const string &s);
void deletePixels();
static ResourceClass strToRc (const string & s);
void deletePixels ();
void saveGame(XmlNode *rootNode);
};
void saveGame (XmlNode * rootNode);
};
}} //end namespace
}} //end namespace
#endif

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

File diff suppressed because it is too large Load Diff

View File

@@ -1,119 +1,162 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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_TECHTREE_H_
#define _GLEST_GAME_TECHTREE_H_
# define _GLEST_GAME_TECHTREE_H_
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#endif
# ifdef WIN32
# include <winsock2.h>
# include <winsock.h>
# endif
#include <set>
#include "util.h"
#include "resource_type.h"
#include "faction_type.h"
#include "damage_multiplier.h"
#include "leak_dumper.h"
# include <set>
# include "util.h"
# include "resource_type.h"
# include "faction_type.h"
# include "damage_multiplier.h"
# include "leak_dumper.h"
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
// =====================================================
// class TechTree
// class TechTree
//
/// A set of factions and resources
/// A set of factions and resources
// =====================================================
class TechTree{
private:
typedef vector<ResourceType> ResourceTypes;
typedef vector<FactionType> FactionTypes;
typedef vector<ArmorType> ArmorTypes;
typedef vector<AttackType> AttackTypes;
class TechTree
{
private:
typedef vector < ResourceType > ResourceTypes;
typedef vector < FactionType > FactionTypes;
typedef vector < ArmorType > ArmorTypes;
typedef vector < AttackType > AttackTypes;
private:
private:
string name;
//string desc;
string treePath;
vector<string> pathList;
string name;
//string desc;
string treePath;
vector < string > pathList;
ResourceTypes resourceTypes;
FactionTypes factionTypes;
ArmorTypes armorTypes;
AttackTypes attackTypes;
DamageMultiplierTable damageMultiplierTable;
Checksum checksumValue;
ResourceTypes resourceTypes;
FactionTypes factionTypes;
ArmorTypes armorTypes;
AttackTypes attackTypes;
DamageMultiplierTable damageMultiplierTable;
Checksum checksumValue;
string languageUsedForCache;
std::map<string,string> translatedTechNames;
std::map<string,std::map<string,string> > translatedTechFactionNames;
bool isValidationModeEnabled;
string languageUsedForCache;
std::map < string, string > translatedTechNames;
std::map < string, std::map < string,
string > >translatedTechFactionNames;
bool isValidationModeEnabled;
public:
Checksum loadTech(const string &techName,
set<string> &factions, Checksum* checksum,
std::map<string,vector<pair<string, string> > > &loadedFileList,
bool validationMode=false);
void load(const string &dir, set<string> &factions, Checksum* checksum,
Checksum *techtreeChecksum,
std::map<string,vector<pair<string, string> > > &loadedFileList,
bool validationMode=false);
string findPath(const string &techName) const;
public:
Checksum loadTech (const string & techName,
set < string > &factions, Checksum * checksum,
std::map < string, vector < pair < string,
string > > >&loadedFileList, bool validationMode =
false);
void load (const string & dir, set < string > &factions,
Checksum * checksum, Checksum * techtreeChecksum,
std::map < string, vector < pair < string,
string > > >&loadedFileList, bool validationMode = false);
string findPath (const string & techName) const;
static string findPath(const string &techName, const vector<string> &pathTechList);
static bool exists(const string &techName, const vector<string> &pathTechList);
static string findPath (const string & techName,
const vector < string > &pathTechList);
static bool exists (const string & techName,
const vector < string > &pathTechList);
explicit TechTree(const vector<string> pathList);
~TechTree();
Checksum * getChecksumValue() { return &checksumValue; }
explicit TechTree (const vector < string > pathList);
~TechTree ();
Checksum *getChecksumValue ()
{
return &checksumValue;
}
//get
int getResourceTypeCount() const {return (int)resourceTypes.size();}
int getTypeCount() const {return (int)factionTypes.size();}
const FactionType *getType(int i) const {return &factionTypes[i];}
const ResourceType *getResourceType(int i) const {return &resourceTypes[i];}
string getName(bool translatedValue=false);
string getNameUntranslated() const;
//get
int getResourceTypeCount () const
{
return (int) resourceTypes.size ();
}
int getTypeCount () const
{
return (int) factionTypes.size ();
}
const FactionType *getType (int i) const
{
return &factionTypes[i];
}
const ResourceType *getResourceType (int i) const
{
return &resourceTypes[i];
}
string getName (bool translatedValue = false);
string getNameUntranslated () const;
string getTranslatedName(string techName, bool forceLoad=false, bool forceTechtreeActiveFile=false);
string getTranslatedFactionName(string techName, string factionName);
string getTranslatedName (string techName, bool forceLoad =
false, bool forceTechtreeActiveFile = false);
string getTranslatedFactionName (string techName, string factionName);
vector<string> getPathList() const {return pathList;}
//const string &getDesc() const {return desc;}
vector < string > getPathList () const
{
return pathList;
}
//const string &getDesc() const {return desc;}
const string getPath() const {return treePath;}
const string getPath () const
{
return treePath;
}
const FactionType *getType(const string &name) const;
FactionType *getTypeByName(const string &name);
const ResourceType *getResourceType(const string &name) const;
const ResourceType *getTechResourceType(int i) const;
const ResourceType *getFirstTechResourceType() const;
const FactionType *getType (const string & name) const;
FactionType *getTypeByName (const string & name);
const ResourceType *getResourceType (const string & name) const;
const ResourceType *getTechResourceType (int i) const;
const ResourceType *getFirstTechResourceType () const;
const ArmorType *getArmorType(const string &name) const;
const AttackType *getAttackType(const string &name) const;
const ArmorType *getArmorType (const string & name) const;
const AttackType *getAttackType (const string & name) const;
int getArmorTypeCount() const { return (int)armorTypes.size(); }
const ArmorType * getArmorTypeByIndex(int index) const { return &armorTypes[index]; }
int getAttackTypeCount() const { return (int)attackTypes.size(); }
const AttackType * getAttackTypeByIndex(int index) const { return &attackTypes[index]; }
int getArmorTypeCount () const
{
return (int) armorTypes.size ();
}
const ArmorType *getArmorTypeByIndex (int index) const
{
return &armorTypes[index];
}
int getAttackTypeCount () const
{
return (int) attackTypes.size ();
}
const AttackType *getAttackTypeByIndex (int index) const
{
return &attackTypes[index];
}
double getDamageMultiplier(const AttackType *att, const ArmorType *art) const;
std::vector<std::string> validateFactionTypes();
std::vector<std::string> validateResourceTypes();
double getDamageMultiplier (const AttackType * att,
const ArmorType * art) const;
std::vector < std::string > validateFactionTypes ();
std::vector < std::string > validateResourceTypes ();
void saveGame(XmlNode *rootNode);
void saveGame (XmlNode * rootNode);
};
};
}} //end namespace
}} //end namespace
#endif

View File

@@ -1,45 +1,53 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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 "tileset_model_type.h"
#include "leak_dumper.h"
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
// =====================================================
// class TilesetModelType
// class TilesetModelType
// =====================================================
TilesetModelType::TilesetModelType() {
model = NULL;
height = 0;
rotationAllowed = false;
smoothTwoFrameAnim = false;
randomPositionEnabled = false;
TilesetModelType::TilesetModelType ()
{
model = NULL;
height = 0;
rotationAllowed = false;
smoothTwoFrameAnim = false;
randomPositionEnabled = false;
animSpeed = 0;
}
animSpeed = 0;
}
TilesetModelType::~TilesetModelType(){
while(!(particleTypes.empty())){
delete particleTypes.back();
particleTypes.pop_back();
}
//Logger::getInstance().add("ObjectType", true);
}
TilesetModelType::~TilesetModelType ()
{
while (!(particleTypes.empty ()))
{
delete particleTypes.back ();
particleTypes.pop_back ();
}
//Logger::getInstance().add("ObjectType", true);
}
void TilesetModelType::addParticleSystem(ObjectParticleSystemType *particleSystem){
particleTypes.push_back(particleSystem);
}
void TilesetModelType::addParticleSystem (ObjectParticleSystemType *
particleSystem)
{
particleTypes.push_back (particleSystem);
}
}}//end namespace
}} //end namespace

View File

@@ -1,84 +1,130 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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_TILESET_MODEL_TYPE_H_
#define _GLEST_GAME_TILESET_MODEL_TYPE_H_
# define _GLEST_GAME_TILESET_MODEL_TYPE_H_
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#endif
# ifdef WIN32
# include <winsock2.h>
# include <winsock.h>
# endif
#include <vector>
#include "model.h"
#include "vec.h"
#include "leak_dumper.h"
#include "unit_particle_type.h"
# include <vector>
# include "model.h"
# include "vec.h"
# include "leak_dumper.h"
# include "unit_particle_type.h"
using std::vector;
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
using Shared::Graphics::Model;
using Shared::Graphics::Vec3f;
using Shared::Graphics::Model;
using Shared::Graphics::Vec3f;
// =====================================================
// class ObjectType
// class ObjectType
//
/// Each of the possible objects of the map: trees, stones ...
/// Each of the possible objects of the map: trees, stones ...
// =====================================================
typedef vector<ObjectParticleSystemType*> ModelParticleSystemTypes;
typedef vector < ObjectParticleSystemType * >ModelParticleSystemTypes;
class TilesetModelType {
private:
Model *model;
ModelParticleSystemTypes particleTypes;
int height;
bool rotationAllowed;
bool randomPositionEnabled;
bool smoothTwoFrameAnim;
class TilesetModelType
{
private:
Model * model;
ModelParticleSystemTypes particleTypes;
int height;
bool rotationAllowed;
bool randomPositionEnabled;
bool smoothTwoFrameAnim;
int animSpeed;
int animSpeed;
public:
TilesetModelType();
~TilesetModelType();
public:
TilesetModelType ();
~TilesetModelType ();
void addParticleSystem(ObjectParticleSystemType *particleSystem);
inline bool hasParticles() const {return particleTypes.empty() == false;}
inline ModelParticleSystemTypes* getParticleTypes() { return &particleTypes ;}
void addParticleSystem (ObjectParticleSystemType * particleSystem);
inline bool hasParticles () const
{
return particleTypes.empty () == false;
}
inline ModelParticleSystemTypes *getParticleTypes ()
{
return &particleTypes;
}
inline Model * getModel() const {return model;}
inline void setModel(Model *model) {this->model=model;}
inline Model *getModel () const
{
return model;
}
inline void setModel (Model * model)
{
this->model = model;
}
inline int getHeight() const {return height;}
inline void setHeight(int height) {this->height=height;}
inline int getHeight () const
{
return height;
}
inline void setHeight (int height)
{
this->height = height;
}
inline bool getRotationAllowed() const {return rotationAllowed;}
inline void setRotationAllowed(bool rotationAllowed) {this->rotationAllowed=rotationAllowed;}
inline bool getRandomPositionEnabled() const {return randomPositionEnabled;}
inline void setRandomPositionEnabled(bool randomPositionEnabled) {this->randomPositionEnabled=randomPositionEnabled;}
inline bool getRotationAllowed () const
{
return rotationAllowed;
}
inline void setRotationAllowed (bool rotationAllowed)
{
this->rotationAllowed = rotationAllowed;
}
inline bool getSmoothTwoFrameAnim() const {return smoothTwoFrameAnim;}
inline void setSmoothTwoFrameAnim(bool smoothTwoFrameAnim) {this->smoothTwoFrameAnim=smoothTwoFrameAnim;}
inline bool getRandomPositionEnabled () const
{
return randomPositionEnabled;
}
inline void setRandomPositionEnabled (bool randomPositionEnabled)
{
this->randomPositionEnabled = randomPositionEnabled;
}
inline int getAnimSpeed() const {return animSpeed;}
inline void setAnimSpeed(int value) {animSpeed = value;}
inline bool getSmoothTwoFrameAnim () const
{
return smoothTwoFrameAnim;
}
inline void setSmoothTwoFrameAnim (bool smoothTwoFrameAnim)
{
this->smoothTwoFrameAnim = smoothTwoFrameAnim;
}
// inline int getAnimSpeedVariation() const {return animVariation;}
// inline void setAnimSpeedVariation(int value) {animSpeed = valueVariation;}
};
inline int getAnimSpeed () const
{
return animSpeed;
}
inline void setAnimSpeed (int value)
{
animSpeed = value;
}
}}//end namespace
// inline int getAnimSpeedVariation() const {return animVariation;}
// inline void setAnimSpeedVariation(int value) {animSpeed = valueVariation;}
};
}} //end namespace
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,380 +1,622 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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_UNITTYPE_H_
#define _GLEST_GAME_UNITTYPE_H_
# define _GLEST_GAME_UNITTYPE_H_
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#endif
# ifdef WIN32
# include <winsock2.h>
# include <winsock.h>
# endif
#include "element_type.h"
#include "command_type.h"
#include "damage_multiplier.h"
#include "sound_container.h"
#include "checksum.h"
#include "game_constants.h"
#include "platform_common.h"
#include "common_scoped_ptr.h"
#include "leak_dumper.h"
# include "element_type.h"
# include "command_type.h"
# include "damage_multiplier.h"
# include "sound_container.h"
# include "checksum.h"
# include "game_constants.h"
# include "platform_common.h"
# include "common_scoped_ptr.h"
# include "leak_dumper.h"
namespace Glest{ namespace Game{
namespace Glest
{
namespace Game
{
using Shared::Sound::StaticSound;
using Shared::Util::Checksum;
using Shared::PlatformCommon::ValueCheckerVault;
using Shared::Sound::StaticSound;
using Shared::Util::Checksum;
using Shared::PlatformCommon::ValueCheckerVault;
class UpgradeType;
class UnitType;
class UnitParticleSystemType;
class ResourceType;
class TechTree;
class FactionType;
class Faction;
class UpgradeType;
class UnitType;
class UnitParticleSystemType;
class ResourceType;
class TechTree;
class FactionType;
class Faction;
// ===============================
// class Level
// class Level
// ===============================
class Level {
private:
string name;
int kills;
class Level
{
private:
string name;
int kills;
public:
Level() {
kills = 0;
}
void init(string name, int kills);
public:
Level ()
{
kills = 0;
}
void init (string name, int kills);
string getName(bool translatedValue=false) const;
int getKills() const {return kills;}
string getName (bool translatedValue = false) const;
int getKills () const
{
return kills;
}
void saveGame(XmlNode *rootNode) const ;
static const Level * loadGame(const XmlNode *rootNode, const UnitType *ut);
};
void saveGame (XmlNode * rootNode) const;
static const Level *loadGame (const XmlNode * rootNode,
const UnitType * ut);
};
// ===============================
// class LootResource
// class LootResource
//
/// Stores information about a lootable resource. Lootable resources are stolen by the attacker on death.
/// Stores information about a lootable resource. Lootable resources are stolen by the attacker on death.
// ===============================
class LootableResource {
private:
const ResourceType *type;
int amountValue;
int amountFactionPercent;
int lossValue;
int lossFactionPercent;
bool negativeAllowed;
class LootableResource
{
private:
const ResourceType *type;
int amountValue;
int amountFactionPercent;
int lossValue;
int lossFactionPercent;
bool negativeAllowed;
public:
LootableResource() {
type=NULL;
amountValue=0;
amountFactionPercent=0;
lossValue=0;
lossFactionPercent=0;
negativeAllowed=false;
}
public:
LootableResource ()
{
type = NULL;
amountValue = 0;
amountFactionPercent = 0;
lossValue = 0;
lossFactionPercent = 0;
negativeAllowed = false;
}
const ResourceType* getResourceType() const {return type;}
void setResourceType(const ResourceType *type) {this->type=type;}
const ResourceType *getResourceType () const
{
return type;
}
void setResourceType (const ResourceType * type)
{
this->type = type;
}
int getAmountValue() const {return amountValue;}
void setAmountValue(int amountValue) {this->amountValue=amountValue;}
int getAmountValue () const
{
return amountValue;
}
void setAmountValue (int amountValue)
{
this->amountValue = amountValue;
}
int getAmountFactionPercent() const {return amountFactionPercent;}
void setAmountFactionPercent(int amountPercentage) {this->amountFactionPercent=amountPercentage;}
int getAmountFactionPercent () const
{
return amountFactionPercent;
}
void setAmountFactionPercent (int amountPercentage)
{
this->amountFactionPercent = amountPercentage;
}
int getLossValue() const {return lossValue;}
void setLossValue(int lossValue) {this->lossValue=lossValue;}
int getLossValue () const
{
return lossValue;
}
void setLossValue (int lossValue)
{
this->lossValue = lossValue;
}
int getLossFactionPercent() const {return lossFactionPercent;}
void setLossFactionPercent(int lossPercentage) {this->lossFactionPercent=lossPercentage;}
int getLossFactionPercent () const
{
return lossFactionPercent;
}
void setLossFactionPercent (int lossPercentage)
{
this->lossFactionPercent = lossPercentage;
}
bool isNegativeAllowed() const {return negativeAllowed;}
void setNegativeAllowed(bool negativeAllowed) {this->negativeAllowed=negativeAllowed;}
bool isNegativeAllowed () const
{
return negativeAllowed;
}
void setNegativeAllowed (bool negativeAllowed)
{
this->negativeAllowed = negativeAllowed;
}
bool operator==(const LootableResource& other) {
return type == other.getResourceType();
}
};
bool operator== (const LootableResource & other)
{
return type == other.getResourceType ();
}
};
// ===============================
// class UnitType
// class UnitType
//
/// A unit or building type
/// A unit or building type
// ===============================
enum UnitClass {
ucWarrior,
ucWorker,
ucBuilding
};
enum UnitClass
{
ucWarrior,
ucWorker,
ucBuilding
};
typedef vector<UnitParticleSystemType*> DamageParticleSystemTypes;
typedef vector < UnitParticleSystemType * >DamageParticleSystemTypes;
enum HealthbarVisible {
hbvUndefined=0,
hbvOff=1,
hbvAlways=2,
hbvIfNeeded=4,
hbvSelected=8
};
enum HealthbarVisible
{
hbvUndefined = 0,
hbvOff = 1,
hbvAlways = 2,
hbvIfNeeded = 4,
hbvSelected = 8
};
enum UnitCountsInVictoryConditions {
ucvcNotSet,
ucvcTrue,
ucvcFalse
};
enum UnitCountsInVictoryConditions
{
ucvcNotSet,
ucvcTrue,
ucvcFalse
};
class UnitType: public ProducibleType, public ValueCheckerVault {
public:
enum Property {
pBurnable,
pRotatedClimb,
class UnitType:public ProducibleType, public ValueCheckerVault
{
public:
enum Property
{
pBurnable,
pRotatedClimb,
pCount
};
pCount
};
enum StartType {
stValue,
stPercentage
};
enum StartType
{
stValue,
stPercentage
};
static const char *propertyNames[];
DamageParticleSystemTypes damageParticleSystemTypes;
private:
typedef vector<SkillType*> SkillTypes;
typedef vector<CommandType*> CommandTypes;
typedef vector<Resource> StoredResources;
typedef vector<Level> Levels;
typedef vector<LootableResource> LootableResources;
static const char *propertyNames[];
DamageParticleSystemTypes damageParticleSystemTypes;
private:
typedef vector < SkillType * >SkillTypes;
typedef vector < CommandType * >CommandTypes;
typedef vector < Resource > StoredResources;
typedef vector < Level > Levels;
typedef vector < LootableResource > LootableResources;
private:
//basic
int id;
int maxHp;
int startHpValue;
int startHpPercentage;
StartType startHpType;
int hpRegeneration;
int maxEp;
int startEpValue;
int startEpPercentage;
StartType startEpType;
int epRegeneration;
int maxUnitCount;
private:
//basic
int id;
int maxHp;
int startHpValue;
int startHpPercentage;
StartType startHpType;
int hpRegeneration;
int maxEp;
int startEpValue;
int startEpPercentage;
StartType startEpType;
int epRegeneration;
int maxUnitCount;
// remove fields, multiple fields are not supported by the engine
bool fields[fieldCount]; //fields: land, sea or air
Field field;
// remove fields, multiple fields are not supported by the engine
bool fields[fieldCount]; //fields: land, sea or air
Field field;
bool properties[pCount]; //properties
int armor; //armor
const ArmorType *armorType;
bool light;
Vec3f lightColor;
float healthbarheight;
float healthbarthickness;
int healthbarVisible;
bool multiSelect;
bool uniformSelect;
bool commandable;
int sight;
int size; //size in cells
int aiBuildSize;
int renderSize; //size to render in cells
int height;
int burnHeight;
int targetHeight;
float rotatedBuildPos;
bool rotationAllowed;
bool properties[pCount]; //properties
int armor; //armor
const ArmorType *armorType;
bool light;
Vec3f lightColor;
float healthbarheight;
float healthbarthickness;
int healthbarVisible;
bool multiSelect;
bool uniformSelect;
bool commandable;
int sight;
int size; //size in cells
int aiBuildSize;
int renderSize; //size to render in cells
int height;
int burnHeight;
int targetHeight;
float rotatedBuildPos;
bool rotationAllowed;
//cellmap
bool *cellMap;
bool allowEmptyCellMap;
//cellmap
bool *cellMap;
bool allowEmptyCellMap;
//sounds
SoundContainer selectionSounds;
SoundContainer commandSounds;
//sounds
SoundContainer selectionSounds;
SoundContainer commandSounds;
//info
SkillTypes skillTypes;
CommandTypes commandTypes;
StoredResources storedResources;
Levels levels;
LootableResources lootableResources;
std::set<string> tags;
//info
SkillTypes skillTypes;
CommandTypes commandTypes;
StoredResources storedResources;
Levels levels;
LootableResources lootableResources;
std::set < string > tags;
//meeting point
bool meetingPoint;
Texture2D *meetingPointImage;
//meeting point
bool meetingPoint;
Texture2D *meetingPointImage;
// for dummy units and units used as shots and so on ....
bool countUnitDeathInStats;
bool countUnitProductionInStats;
bool countUnitKillInStats;
bool countKillForUnitUpgrade;
// for dummy units and units used as shots and so on ....
bool countUnitDeathInStats;
bool countUnitProductionInStats;
bool countUnitKillInStats;
bool countKillForUnitUpgrade;
//OPTIMIZATION: store first command type and skill type of each class
const CommandType *firstCommandTypeOfClass[ccCount];
const SkillType *firstSkillTypeOfClass[scCount];
//OPTIMIZATION: store first command type and skill type of each class
const CommandType *firstCommandTypeOfClass[ccCount];
const SkillType *firstSkillTypeOfClass[scCount];
UnitCountsInVictoryConditions countInVictoryConditions;
UnitCountsInVictoryConditions countInVictoryConditions;
static auto_ptr<CommandType> ctHarvestEmergencyReturnCommandType;
static auto_ptr < CommandType > ctHarvestEmergencyReturnCommandType;
public:
//creation and loading
UnitType();
virtual ~UnitType();
void preLoad(const string &dir);
void loaddd(int id, const string &dir, const TechTree *techTree,
const string &techTreePath,
const FactionType *factionType, Checksum* checksum,
Checksum* techtreeChecksum,
std::map<string,vector<pair<string, string> > > &loadedFileList,
bool validationMode=false);
public:
//creation and loading
UnitType ();
virtual ~ UnitType ();
void preLoad (const string & dir);
void loaddd (int id, const string & dir, const TechTree * techTree,
const string & techTreePath,
const FactionType * factionType, Checksum * checksum,
Checksum * techtreeChecksum,
std::map < string, vector < pair < string,
string > > >&loadedFileList, bool validationMode = false);
virtual string getName(bool translatedValue=false) const;
virtual string getName (bool translatedValue = false) const;
UnitCountsInVictoryConditions getCountInVictoryConditions() const { return countInVictoryConditions; }
//get
inline int getId() const {return id;}
inline int getMaxHp() const {return maxHp;}
inline int getHpRegeneration() const {return hpRegeneration;}
inline int getStartHpValue() const {return startHpValue;}
inline int getStartHpPercentage() const {return startHpPercentage;}
inline StartType getStartHpType() const {return startHpType;}
inline int getMaxEp() const {return maxEp;}
inline int getEpRegeneration() const {return epRegeneration;}
inline int getStartEpValue() const {return startEpValue;}
inline int getStartEpPercentage() const {return startEpPercentage;}
inline StartType getStartEpType() const {return startEpType;}
inline int getMaxUnitCount() const {return maxUnitCount;}
inline bool getField(Field field) const {return fields[field];}
inline Field getField() const {return field;}
inline bool getProperty(Property property) const {return properties[property];}
inline int getArmor() const {return armor;}
inline const ArmorType *getArmorType() const {return armorType;}
inline const SkillType *getSkillType(int i) const {return skillTypes[i];}
const CommandType *getCommandType(int i) const;
inline const Level *getLevel(int i) const {return &levels[i];}
const Level *getLevel(string name) const;
inline int getSkillTypeCount() const {return (int)skillTypes.size();}
inline int getCommandTypeCount() const {return (int)commandTypes.size();}
inline int getLevelCount() const {return (int)levels.size();}
inline bool getLight() const {return light;}
inline bool getRotationAllowed() const {return rotationAllowed;}
inline Vec3f getLightColor() const {return lightColor;}
inline float getHealthbarHeight() const {return healthbarheight;}
inline float getHealthbarThickness() const {return healthbarthickness;}
inline int getHealthbarVisible() const {return healthbarVisible;}
inline bool getMultiSelect() const {return multiSelect;}
inline bool getUniformSelect() const {return uniformSelect;}
inline bool isCommandable() const {return commandable;}
inline int getSight() const {return sight;}
inline int getSize() const {return size;}
inline int getAiBuildSize() const {return aiBuildSize;}
inline int getRenderSize() const {return renderSize;}
int getHeight() const {return height;}
int getBurnHeight() const {return burnHeight;}
int getTargetHeight() const {return targetHeight;}
int getStoredResourceCount() const {return (int)storedResources.size();}
inline const Resource *getStoredResource(int i) const {return &storedResources[i];}
int getLootableResourceCount() const {return (int)lootableResources.size();}
inline const LootableResource getLootableResource(int i) const {return lootableResources.at(i);}
const set<string> &getTags() const {return tags;}
bool getCellMapCell(int x, int y, CardinalDir facing) const;
inline bool getMeetingPoint() const {return meetingPoint;}
inline bool getCountUnitDeathInStats() const {return countUnitDeathInStats;}
inline bool getCountUnitProductionInStats() const {return countUnitProductionInStats;}
inline bool getCountUnitKillInStats() const {return countUnitKillInStats;}
inline bool getCountKillForUnitUpgrade() const {return countKillForUnitUpgrade;}
inline bool isMobile() const {return (firstSkillTypeOfClass[scMove] != NULL);}
inline Texture2D *getMeetingPointImage() const {return meetingPointImage;}
inline StaticSound *getSelectionSound() const {return selectionSounds.getRandSound();}
inline StaticSound *getCommandSound() const {return commandSounds.getRandSound();}
UnitCountsInVictoryConditions getCountInVictoryConditions () const
{
return countInVictoryConditions;
}
//get
inline int getId () const
{
return id;
}
inline int getMaxHp () const
{
return maxHp;
}
inline int getHpRegeneration () const
{
return hpRegeneration;
}
inline int getStartHpValue () const
{
return startHpValue;
}
inline int getStartHpPercentage () const
{
return startHpPercentage;
}
inline StartType getStartHpType () const
{
return startHpType;
}
inline int getMaxEp () const
{
return maxEp;
}
inline int getEpRegeneration () const
{
return epRegeneration;
}
inline int getStartEpValue () const
{
return startEpValue;
}
inline int getStartEpPercentage () const
{
return startEpPercentage;
}
inline StartType getStartEpType () const
{
return startEpType;
}
inline int getMaxUnitCount () const
{
return maxUnitCount;
}
inline bool getField (Field field) const
{
return fields[field];
}
inline Field getField () const
{
return field;
}
inline bool getProperty (Property property) const
{
return properties[property];
}
inline int getArmor () const
{
return armor;
}
inline const ArmorType *getArmorType () const
{
return armorType;
}
inline const SkillType *getSkillType (int i) const
{
return skillTypes[i];
}
const CommandType *getCommandType (int i) const;
inline const Level *getLevel (int i) const
{
return &levels[i];
}
const Level *getLevel (string name) const;
inline int getSkillTypeCount () const
{
return (int) skillTypes.size ();
}
inline int getCommandTypeCount () const
{
return (int) commandTypes.size ();
}
inline int getLevelCount () const
{
return (int) levels.size ();
}
inline bool getLight () const
{
return light;
}
inline bool getRotationAllowed () const
{
return rotationAllowed;
}
inline Vec3f getLightColor () const
{
return lightColor;
}
inline float getHealthbarHeight () const
{
return healthbarheight;
}
inline float getHealthbarThickness () const
{
return healthbarthickness;
}
inline int getHealthbarVisible () const
{
return healthbarVisible;
}
inline bool getMultiSelect () const
{
return multiSelect;
}
inline bool getUniformSelect () const
{
return uniformSelect;
}
inline bool isCommandable () const
{
return commandable;
}
inline int getSight () const
{
return sight;
}
inline int getSize () const
{
return size;
}
inline int getAiBuildSize () const
{
return aiBuildSize;
}
inline int getRenderSize () const
{
return renderSize;
}
int getHeight () const
{
return height;
}
int getBurnHeight () const
{
return burnHeight;
}
int getTargetHeight () const
{
return targetHeight;
}
int getStoredResourceCount () const
{
return (int) storedResources.size ();
}
inline const Resource *getStoredResource (int i) const
{
return &storedResources[i];
}
int getLootableResourceCount () const
{
return (int) lootableResources.size ();
}
inline const LootableResource getLootableResource (int i) const
{
return lootableResources.at (i);
}
const set < string > &getTags () const
{
return tags;
}
bool getCellMapCell (int x, int y, CardinalDir facing) const;
inline bool getMeetingPoint () const
{
return meetingPoint;
}
inline bool getCountUnitDeathInStats () const
{
return countUnitDeathInStats;
}
inline bool getCountUnitProductionInStats () const
{
return countUnitProductionInStats;
}
inline bool getCountUnitKillInStats () const
{
return countUnitKillInStats;
}
inline bool getCountKillForUnitUpgrade () const
{
return countKillForUnitUpgrade;
}
inline bool isMobile () const
{
return (firstSkillTypeOfClass[scMove] != NULL);
}
inline Texture2D *getMeetingPointImage () const
{
return meetingPointImage;
}
inline StaticSound *getSelectionSound () const
{
return selectionSounds.getRandSound ();
}
inline StaticSound *getCommandSound () const
{
return commandSounds.getRandSound ();
}
inline const SoundContainer & getSelectionSounds() const { return selectionSounds; }
inline const SoundContainer & getCommandSounds() const { return commandSounds; }
inline const SoundContainer & getSelectionSounds () const
{
return selectionSounds;
}
inline const SoundContainer & getCommandSounds () const
{
return commandSounds;
}
int getStore(const ResourceType *rt) const;
const SkillType *getSkillType(const string &skillName, SkillClass skillClass) const;
const SkillType *getFirstStOfClass(SkillClass skillClass) const;
const CommandType *getFirstCtOfClass(CommandClass commandClass) const;
const HarvestCommandType *getFirstHarvestCommand(const ResourceType *resourceType,const Faction *faction) const;
const HarvestEmergencyReturnCommandType *getFirstHarvestEmergencyReturnCommand() const;
const AttackCommandType *getFirstAttackCommand(Field field) const;
const AttackStoppedCommandType *getFirstAttackStoppedCommand(Field field) const;
const RepairCommandType *getFirstRepairCommand(const UnitType *repaired) const;
int getStore (const ResourceType * rt) const;
const SkillType *getSkillType (const string & skillName,
SkillClass skillClass) const;
const SkillType *getFirstStOfClass (SkillClass skillClass) const;
const CommandType *getFirstCtOfClass (CommandClass commandClass) const;
const HarvestCommandType *getFirstHarvestCommand (const ResourceType *
resourceType,
const Faction *
faction) const;
const HarvestEmergencyReturnCommandType
*getFirstHarvestEmergencyReturnCommand () const;
const AttackCommandType *getFirstAttackCommand (Field field) const;
const AttackStoppedCommandType *getFirstAttackStoppedCommand (Field
field)
const;
const RepairCommandType *getFirstRepairCommand (const UnitType *
repaired) const;
//get totals
int getTotalMaxHp(const TotalUpgrade *totalUpgrade) const;
int getTotalMaxHpRegeneration(const TotalUpgrade *totalUpgrade) const;
int getTotalMaxEp(const TotalUpgrade *totalUpgrade) const;
int getTotalMaxEpRegeneration(const TotalUpgrade *totalUpgrade) const;
int getTotalArmor(const TotalUpgrade *totalUpgrade) const;
int getTotalSight(const TotalUpgrade *totalUpgrade) const;
//get totals
int getTotalMaxHp (const TotalUpgrade * totalUpgrade) const;
int getTotalMaxHpRegeneration (const TotalUpgrade * totalUpgrade) const;
int getTotalMaxEp (const TotalUpgrade * totalUpgrade) const;
int getTotalMaxEpRegeneration (const TotalUpgrade * totalUpgrade) const;
int getTotalArmor (const TotalUpgrade * totalUpgrade) const;
int getTotalSight (const TotalUpgrade * totalUpgrade) const;
//has
bool hasCommandType(const CommandType *commandType) const;
inline bool hasCommandClass(CommandClass commandClass) const {
return firstCommandTypeOfClass[commandClass]!=NULL;
}
//bool hasSkillType(const SkillType *skillType) const;
bool hasSkillClass(SkillClass skillClass) const;
inline bool hasCellMap() const {return cellMap!=NULL;}
inline bool getAllowEmptyCellMap() const {return allowEmptyCellMap;}
bool hasEmptyCellMap() const;
Vec2i getFirstOccupiedCellInCellMap(Vec2i currentPos) const;
//has
bool hasCommandType (const CommandType * commandType) const;
inline bool hasCommandClass (CommandClass commandClass) const
{
return firstCommandTypeOfClass[commandClass] != NULL;
}
//bool hasSkillType(const SkillType *skillType) const;
bool hasSkillClass (SkillClass skillClass) const;
inline bool hasCellMap () const
{
return cellMap != NULL;
}
inline bool getAllowEmptyCellMap () const
{
return allowEmptyCellMap;
}
bool hasEmptyCellMap () const;
Vec2i getFirstOccupiedCellInCellMap (Vec2i currentPos) const;
//is
bool isOfClass(UnitClass uc) const;
//is
bool isOfClass (UnitClass uc) const;
//find
const CommandType* findCommandTypeById(int id) const;
string getCommandTypeListDesc() const;
//find
const CommandType *findCommandTypeById (int id) const;
string getCommandTypeListDesc () const;
inline float getRotatedBuildPos() { return rotatedBuildPos; }
inline void setRotatedBuildPos(float value) { rotatedBuildPos = value; }
inline float getRotatedBuildPos ()
{
return rotatedBuildPos;
}
inline void setRotatedBuildPos (float value)
{
rotatedBuildPos = value;
}
//other
virtual string getReqDesc(bool translatedValue) const;
//other
virtual string getReqDesc (bool translatedValue) const;
std::string toString() const;
std::string toString ()const;
private:
void computeFirstStOfClass();
void computeFirstCtOfClass();
};
private:
void computeFirstStOfClass ();
void computeFirstCtOfClass ();
};
/**
* Used to sort UnitType. Sorts by *translated* unit name. Sorting is case sensitive and done in
* lexical order.
*/
struct UnitTypeSorter
{
bool operator()( const UnitType *left, const UnitType *right ) const {
return left->getName(true) < right->getName(true);
}
};
struct UnitTypeSorter
{
bool operator () (const UnitType * left, const UnitType * right) const
{
return left->getName (true) < right->getName (true);
}
};
}}//end namespace
}
} //end namespace
#endif

File diff suppressed because it is too large Load Diff

View File

@@ -1,12 +1,12 @@
// ==============================================================
// This file is part of Glest (www.glest.org)
// This file is part of Glest (www.glest.org)
//
// Copyright (C) 2001-2008 Martiño Figueroa
// Copyright (C) 2001-2008 Martiñ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
// 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
// ==============================================================
/**
@@ -18,118 +18,176 @@
*/
#ifndef _GLEST_GAME_UPGRADETYPE_H_
#define _GLEST_GAME_UPGRADETYPE_H_
# define _GLEST_GAME_UPGRADETYPE_H_
#ifdef WIN32
#include <winsock2.h>
#include <winsock.h>
#endif
# ifdef WIN32
# include <winsock2.h>
# include <winsock.h>
# endif
#include "element_type.h"
#include "checksum.h"
#include "conversion.h"
#include "xml_parser.h"
#include "leak_dumper.h"
#include <set>
# include "element_type.h"
# include "checksum.h"
# include "conversion.h"
# include "xml_parser.h"
# include "leak_dumper.h"
# include <set>
using Shared::Util::Checksum;
using namespace Shared::Util;
using namespace Shared::Xml;
namespace Glest { namespace Game {
namespace Glest
{
namespace Game
{
class TechTree;
class FactionType;
class UnitType;
class Unit;
class SkillType;
class AttackSkillType;
class MoveSkillType;
class ProduceSkillType;
class Faction;
class TechTree;
class FactionType;
class UnitType;
class Unit;
class SkillType;
class AttackSkillType;
class MoveSkillType;
class ProduceSkillType;
class Faction;
/**
* Groups all information used for upgrades. Attack boosts also use this class for modifying stats.
*/
class UpgradeTypeBase {
protected:
string upgradename;
int maxHp;
bool maxHpIsMultiplier;
int maxHpRegeneration;
//bool maxHpRegenerationIsMultiplier;
class UpgradeTypeBase
{
protected:
string upgradename;
int maxHp;
bool maxHpIsMultiplier;
int maxHpRegeneration;
//bool maxHpRegenerationIsMultiplier;
int sight;
bool sightIsMultiplier;
int sight;
bool sightIsMultiplier;
int maxEp;
bool maxEpIsMultiplier;
int maxEpRegeneration;
//bool maxEpRegenerationIsMultiplier;
int maxEp;
bool maxEpIsMultiplier;
int maxEpRegeneration;
//bool maxEpRegenerationIsMultiplier;
int armor;
bool armorIsMultiplier;
int armor;
bool armorIsMultiplier;
int attackStrength;
bool attackStrengthIsMultiplier;
/**
int attackStrength;
bool attackStrengthIsMultiplier;
/**
* List of the values (for each skill type) that the stat was boosted by. This is used so
* that we can restore the original values when the upgrade is removed (eg, an attack
* boost wears off).
*/
std::map<string,int> attackStrengthMultiplierValueList;
std::map < string, int >attackStrengthMultiplierValueList;
int attackRange;
bool attackRangeIsMultiplier;
std::map<string,int> attackRangeMultiplierValueList; /**< @see #attackStrengthMultiplierValueList */
int attackRange;
bool attackRangeIsMultiplier;
std::map < string, int >attackRangeMultiplierValueList;
/**< @see #attackStrengthMultiplierValueList */
int moveSpeed;
bool moveSpeedIsMultiplier;
std::map<string,int> moveSpeedIsMultiplierValueList; /**< @see #attackStrengthMultiplierValueList */
int moveSpeed;
bool moveSpeedIsMultiplier;
std::map < string, int >moveSpeedIsMultiplierValueList;
/**< @see #attackStrengthMultiplierValueList */
int prodSpeed;
bool prodSpeedIsMultiplier;
std::map<string,int> prodSpeedProduceIsMultiplierValueList; /**< @see #attackStrengthMultiplierValueList */
std::map<string,int> prodSpeedUpgradeIsMultiplierValueList; /**< @see #attackStrengthMultiplierValueList */
std::map<string,int> prodSpeedMorphIsMultiplierValueList; /**< @see #attackStrengthMultiplierValueList */
int prodSpeed;
bool prodSpeedIsMultiplier;
std::map < string, int >prodSpeedProduceIsMultiplierValueList;
/**< @see #attackStrengthMultiplierValueList */
std::map < string, int >prodSpeedUpgradeIsMultiplierValueList;
/**< @see #attackStrengthMultiplierValueList */
std::map < string, int >prodSpeedMorphIsMultiplierValueList;
/**< @see #attackStrengthMultiplierValueList */
int attackSpeed;
bool attackSpeedIsMultiplier;
std::map<string,int> attackSpeedIsMultiplierValueList;
int attackSpeed;
bool attackSpeedIsMultiplier;
std::map < string, int >attackSpeedIsMultiplierValueList;
protected:
protected:
virtual int getAttackStrength() const { return attackStrength; }
virtual int getAttackRange() const { return attackRange; }
virtual int getMoveSpeed() const { return moveSpeed; }
virtual int getProdSpeed() const { return prodSpeed; }
virtual int getAttackSpeed() const { return attackSpeed; }
virtual int getAttackStrength () const
{
return attackStrength;
}
virtual int getAttackRange () const
{
return attackRange;
}
virtual int getMoveSpeed () const
{
return moveSpeed;
}
virtual int getProdSpeed () const
{
return prodSpeed;
}
virtual int getAttackSpeed () const
{
return attackSpeed;
}
virtual int getMaxHpFromBoosts() const { return 0; }
virtual int getMaxHpRegenerationFromBoosts() const { return 0; }
virtual int getSightFromBoosts() const { return 0; }
virtual int getMaxEpFromBoosts() const { return 0; }
virtual int getMaxEpRegenerationFromBoosts() const { return 0; }
virtual int getArmorFromBoosts() const { return 0; };
virtual int getAttackStrengthFromBoosts(const AttackSkillType *st) const { return 0; }
virtual int getAttackRangeFromBoosts(const AttackSkillType *st) const { return 0; }
virtual int getMoveSpeedFromBoosts(const MoveSkillType *st) const { return 0; }
virtual int getProdSpeedFromBoosts(const SkillType *st) const { return 0; }
virtual int getAttackSpeedFromBoosts(const AttackSkillType *st) const { return 0; }
virtual int getMaxHpFromBoosts () const
{
return 0;
}
virtual int getMaxHpRegenerationFromBoosts () const
{
return 0;
}
virtual int getSightFromBoosts () const
{
return 0;
}
virtual int getMaxEpFromBoosts () const
{
return 0;
}
virtual int getMaxEpRegenerationFromBoosts () const
{
return 0;
}
virtual int getArmorFromBoosts () const
{
return 0;
};
virtual int getAttackStrengthFromBoosts (const AttackSkillType * st) const
{
return 0;
}
virtual int getAttackRangeFromBoosts (const AttackSkillType * st) const
{
return 0;
}
virtual int getMoveSpeedFromBoosts (const MoveSkillType * st) const
{
return 0;
}
virtual int getProdSpeedFromBoosts (const SkillType * st) const
{
return 0;
}
virtual int getAttackSpeedFromBoosts (const AttackSkillType * st) const
{
return 0;
}
public:
/**
public:
/**
* Creates an UpgradeTypeBase with values such that there are no stat changes.
*/
UpgradeTypeBase() {
UpgradeTypeBase ()
{
maxHp = 0;;
maxHpIsMultiplier = false;
maxHpRegeneration = 0;
maxHpRegeneration = 0;
sight = 0;
sightIsMultiplier = false;
maxEp = 0;;
maxEpIsMultiplier = false;
maxEpRegeneration = 0;
maxEpRegeneration = 0;
armor = 0;
armorIsMultiplier = false;
attackStrength = 0;
@@ -142,166 +200,237 @@ public:
prodSpeedIsMultiplier = false;
attackSpeed = 0;
attackSpeedIsMultiplier = false;
}
virtual ~UpgradeTypeBase() {}
}
virtual ~ UpgradeTypeBase ()
{
}
virtual void copyDataFrom(UpgradeTypeBase *source);
virtual void copyDataFrom (UpgradeTypeBase * source);
virtual string getUpgradeName() const { return upgradename; }
virtual int getMaxHp() const {return maxHp;}
virtual int getMaxHpRegeneration() const {return maxHpRegeneration;}
virtual int getSight() const {return sight;}
virtual int getMaxEp() const {return maxEp;}
virtual int getMaxEpRegeneration() const {return maxEpRegeneration;}
virtual int getArmor() const {return armor;}
virtual int getAttackStrength(const AttackSkillType *st) const;
virtual int getAttackRange(const AttackSkillType *st) const;
virtual int getMoveSpeed(const MoveSkillType *st) const;
virtual int getProdSpeed(const SkillType *st) const;
virtual int getAttackSpeed(const AttackSkillType *st) const;
virtual string getUpgradeName () const
{
return upgradename;
}
virtual int getMaxHp () const
{
return maxHp;
}
virtual int getMaxHpRegeneration () const
{
return maxHpRegeneration;
}
virtual int getSight () const
{
return sight;
}
virtual int getMaxEp () const
{
return maxEp;
}
virtual int getMaxEpRegeneration () const
{
return maxEpRegeneration;
}
virtual int getArmor () const
{
return armor;
}
virtual int getAttackStrength (const AttackSkillType * st) const;
virtual int getAttackRange (const AttackSkillType * st) const;
virtual int getMoveSpeed (const MoveSkillType * st) const;
virtual int getProdSpeed (const SkillType * st) const;
virtual int getAttackSpeed (const AttackSkillType * st) const;
virtual bool getAttackStrengthIsMultiplier() const {return attackStrengthIsMultiplier;}
virtual bool getMaxHpIsMultiplier() const {return maxHpIsMultiplier;}
virtual bool getSightIsMultiplier() const {return sightIsMultiplier;}
virtual bool getMaxEpIsMultiplier() const {return maxEpIsMultiplier;}
virtual bool getArmorIsMultiplier() const {return armorIsMultiplier;}
virtual bool getAttackRangeIsMultiplier() const {return attackRangeIsMultiplier;}
virtual bool getMoveSpeedIsMultiplier() const {return moveSpeedIsMultiplier;}
virtual bool getProdSpeedIsMultiplier() const {return prodSpeedIsMultiplier;}
virtual bool getAttackSpeedIsMultiplier() const {return attackSpeedIsMultiplier;}
virtual bool getAttackStrengthIsMultiplier () const
{
return attackStrengthIsMultiplier;
}
virtual bool getMaxHpIsMultiplier () const
{
return maxHpIsMultiplier;
}
virtual bool getSightIsMultiplier () const
{
return sightIsMultiplier;
}
virtual bool getMaxEpIsMultiplier () const
{
return maxEpIsMultiplier;
}
virtual bool getArmorIsMultiplier () const
{
return armorIsMultiplier;
}
virtual bool getAttackRangeIsMultiplier () const
{
return attackRangeIsMultiplier;
}
virtual bool getMoveSpeedIsMultiplier () const
{
return moveSpeedIsMultiplier;
}
virtual bool getProdSpeedIsMultiplier () const
{
return prodSpeedIsMultiplier;
}
virtual bool getAttackSpeedIsMultiplier () const
{
return attackSpeedIsMultiplier;
}
/**
/**
* Loads the upgrade values (stat boosts and whether or not the boosts use a multiplier) from an
* XML node.
* @param upgradeNode Node containing the stat boost elements (`max-hp`, `attack-strength`, etc).
* @param upgradename Unique identifier for the upgrade.
*/
virtual void load(const XmlNode *upgradeNode, string upgradename);
/**
virtual void load (const XmlNode * upgradeNode, string upgradename);
/**
* Creates a string representation of the upgrade. All stat boosts are detailed on their own line
* with their corresponding boosts.
* @param translatedValue If true, the description is translated. Otherwise the description uses
* names as they appear in the XMLs.
*/
virtual string getDesc(bool translatedValue) const;
/**
virtual string getDesc (bool translatedValue) const;
/**
* Returns a string representation of this object. Lists all the value that the object stores.
* For debugging purposes, only.
*/
virtual std::string toString() const {
std::string result = "";
virtual std::string toString () const
{
std::string result = "";
result += "upgradename =" + getUpgradeName();
result += "maxHp = " + intToStr(getMaxHp());
result += "maxHpIsMultiplier = " + intToStr(getMaxHpIsMultiplier());
result += "maxHpRegeneration = " + intToStr(getMaxHpRegeneration());
//result += "maxHpRegenerationIsMultiplier = " + intToStr(maxHpRegenerationIsMultiplier);
result += "upgradename =" + getUpgradeName ();
result += "maxHp = " + intToStr (getMaxHp ());
result += "maxHpIsMultiplier = " + intToStr (getMaxHpIsMultiplier ());
result += "maxHpRegeneration = " + intToStr (getMaxHpRegeneration ());
//result += "maxHpRegenerationIsMultiplier = " + intToStr(maxHpRegenerationIsMultiplier);
result += " sight = " + intToStr(getSight());
result += "sightIsMultiplier = " + intToStr(getSightIsMultiplier());
result += " sight = " + intToStr (getSight ());
result += "sightIsMultiplier = " + intToStr (getSightIsMultiplier ());
result += " maxEp = " + intToStr(getMaxEp());
result += " maxEpIsMultiplier = " + intToStr(getMaxEpIsMultiplier());
result += " maxEpRegeneration = " + intToStr(getMaxEpRegeneration());
//result += "maxEpRegenerationIsMultiplier = " + intToStr(maxEpRegenerationIsMultiplier);
result += " maxEp = " + intToStr (getMaxEp ());
result +=
" maxEpIsMultiplier = " + intToStr (getMaxEpIsMultiplier ());
result +=
" maxEpRegeneration = " + intToStr (getMaxEpRegeneration ());
//result += "maxEpRegenerationIsMultiplier = " + intToStr(maxEpRegenerationIsMultiplier);
result += " armor = " + intToStr(getArmor());
result += " armorIsMultiplier = " + intToStr(getArmorIsMultiplier());
result += " attackStrength = " + intToStr(getAttackStrength());
result += " attackStrengthIsMultiplier = " + intToStr(getAttackStrengthIsMultiplier());
result += " attackRange = " + intToStr(getAttackRange());
result += " attackRangeIsMultiplier = " + intToStr(getAttackRangeIsMultiplier());
result += " moveSpeed = " + intToStr(getMoveSpeed());
result += " moveSpeedIsMultiplier = " + intToStr(getMoveSpeedIsMultiplier());
result += " prodSpeed = " + intToStr(getProdSpeed());
result += " prodSpeedIsMultiplier = " + intToStr(getProdSpeedIsMultiplier());
result += " armor = " + intToStr (getArmor ());
result +=
" armorIsMultiplier = " + intToStr (getArmorIsMultiplier ());
result += " attackStrength = " + intToStr (getAttackStrength ());
result +=
" attackStrengthIsMultiplier = " +
intToStr (getAttackStrengthIsMultiplier ());
result += " attackRange = " + intToStr (getAttackRange ());
result +=
" attackRangeIsMultiplier = " +
intToStr (getAttackRangeIsMultiplier ());
result += " moveSpeed = " + intToStr (getMoveSpeed ());
result +=
" moveSpeedIsMultiplier = " +
intToStr (getMoveSpeedIsMultiplier ());
result += " prodSpeed = " + intToStr (getProdSpeed ());
result +=
" prodSpeedIsMultiplier = " +
intToStr (getProdSpeedIsMultiplier ());
return result;
}
return result;
}
// TODO: It's not clear if these save game methods are being used, currently. I think
// attack boosts might use the few lines that aren't commented out.
virtual void saveGame(XmlNode *rootNode) const;
//virtual void saveGameBoost(XmlNode *rootNode) const;
static const UpgradeType * loadGame(const XmlNode *rootNode, Faction *faction);
//void loadGameBoost(const XmlNode *rootNode);
// TODO: It's not clear if these save game methods are being used, currently. I think
// attack boosts might use the few lines that aren't commented out.
virtual void saveGame (XmlNode * rootNode) const;
//virtual void saveGameBoost(XmlNode *rootNode) const;
static const UpgradeType *loadGame (const XmlNode * rootNode,
Faction * faction);
//void loadGameBoost(const XmlNode *rootNode);
/**
/**
* Generates a checksum value for the upgrade.
*/
virtual Checksum getCRC() {
Checksum crcForUpgradeType;
virtual Checksum getCRC ()
{
Checksum crcForUpgradeType;
crcForUpgradeType.addString(getUpgradeName());
crcForUpgradeType.addInt(getMaxHp());
crcForUpgradeType.addInt(getMaxHpIsMultiplier());
crcForUpgradeType.addInt(getMaxHpRegeneration());
crcForUpgradeType.addString (getUpgradeName ());
crcForUpgradeType.addInt (getMaxHp ());
crcForUpgradeType.addInt (getMaxHpIsMultiplier ());
crcForUpgradeType.addInt (getMaxHpRegeneration ());
crcForUpgradeType.addInt(getSight());
crcForUpgradeType.addInt(getSightIsMultiplier());
crcForUpgradeType.addInt (getSight ());
crcForUpgradeType.addInt (getSightIsMultiplier ());
crcForUpgradeType.addInt(getMaxEp());
crcForUpgradeType.addInt(getMaxEpIsMultiplier());
crcForUpgradeType.addInt(getMaxEpRegeneration());
crcForUpgradeType.addInt (getMaxEp ());
crcForUpgradeType.addInt (getMaxEpIsMultiplier ());
crcForUpgradeType.addInt (getMaxEpRegeneration ());
crcForUpgradeType.addInt(getArmor());
crcForUpgradeType.addInt(getArmorIsMultiplier());
crcForUpgradeType.addInt (getArmor ());
crcForUpgradeType.addInt (getArmorIsMultiplier ());
crcForUpgradeType.addInt(getAttackStrength());
crcForUpgradeType.addInt(getAttackStrengthIsMultiplier());
//std::map<string,int> attackStrengthMultiplierValueList;
crcForUpgradeType.addInt64((int64)attackStrengthMultiplierValueList.size());
crcForUpgradeType.addInt (getAttackStrength ());
crcForUpgradeType.addInt (getAttackStrengthIsMultiplier ());
//std::map<string,int> attackStrengthMultiplierValueList;
crcForUpgradeType.addInt64 ((int64) attackStrengthMultiplierValueList.
size ());
crcForUpgradeType.addInt(getAttackRange());
crcForUpgradeType.addInt(getAttackRangeIsMultiplier());
//std::map<string,int> attackRangeMultiplierValueList;
crcForUpgradeType.addInt64((int64)attackRangeMultiplierValueList.size());
crcForUpgradeType.addInt (getAttackRange ());
crcForUpgradeType.addInt (getAttackRangeIsMultiplier ());
//std::map<string,int> attackRangeMultiplierValueList;
crcForUpgradeType.addInt64 ((int64) attackRangeMultiplierValueList.
size ());
crcForUpgradeType.addInt(getMoveSpeed());
crcForUpgradeType.addInt(getMoveSpeedIsMultiplier());
//std::map<string,int> moveSpeedIsMultiplierValueList;
crcForUpgradeType.addInt64((int64)moveSpeedIsMultiplierValueList.size());
crcForUpgradeType.addInt (getMoveSpeed ());
crcForUpgradeType.addInt (getMoveSpeedIsMultiplier ());
//std::map<string,int> moveSpeedIsMultiplierValueList;
crcForUpgradeType.addInt64 ((int64) moveSpeedIsMultiplierValueList.
size ());
crcForUpgradeType.addInt(getProdSpeed());
crcForUpgradeType.addInt(getProdSpeedIsMultiplier());
//std::map<string,int> prodSpeedProduceIsMultiplierValueList;
crcForUpgradeType.addInt64((int64)prodSpeedProduceIsMultiplierValueList.size());
//std::map<string,int> prodSpeedUpgradeIsMultiplierValueList;
crcForUpgradeType.addInt64((int64)prodSpeedUpgradeIsMultiplierValueList.size());
//std::map<string,int> prodSpeedMorphIsMultiplierValueList;
crcForUpgradeType.addInt64((int64)prodSpeedMorphIsMultiplierValueList.size());
crcForUpgradeType.addInt(getAttackSpeed());
crcForUpgradeType.addInt(getAttackSpeedIsMultiplier());
crcForUpgradeType.addInt (getProdSpeed ());
crcForUpgradeType.addInt (getProdSpeedIsMultiplier ());
//std::map<string,int> prodSpeedProduceIsMultiplierValueList;
crcForUpgradeType.
addInt64 ((int64) prodSpeedProduceIsMultiplierValueList.size ());
//std::map<string,int> prodSpeedUpgradeIsMultiplierValueList;
crcForUpgradeType.
addInt64 ((int64) prodSpeedUpgradeIsMultiplierValueList.size ());
//std::map<string,int> prodSpeedMorphIsMultiplierValueList;
crcForUpgradeType.
addInt64 ((int64) prodSpeedMorphIsMultiplierValueList.size ());
return crcForUpgradeType;
}
};
crcForUpgradeType.addInt (getAttackSpeed ());
crcForUpgradeType.addInt (getAttackSpeedIsMultiplier ());
return crcForUpgradeType;
}
};
/**
* Represents the type of upgrade. That is, the single upgrade as it appears in the faction's XML
* files. Each upgrade has a single `UpgradeType`. Contains information about what units are
* affected by the upgrade.
*/
class UpgradeType: public UpgradeTypeBase, public ProducibleType {
private:
/**
class UpgradeType:public UpgradeTypeBase, public ProducibleType
{
private:
/**
* Set of unit types (the "classes" of units, eg, swordman) that are affected by this upgrade.
*/
std::set<const UnitType*> effects;
std::set<string> tags;
std::set < const UnitType *>effects;
std::set < string > tags;
public:
/**
public:
/**
* Sets the upgrade name to the directory name (the base name of `dir`).
* @param dir Path of the upgrade directory.
*/
void preLoad(const string &dir);
void preLoad (const string & dir);
/**
/**
* Loads an upgrade from an XML file.
* @param dir Path of the upgrade directory. The file name is determined from this.
* @param techTree The techtree that this upgrade is in. Used to access the common data
@@ -313,82 +442,87 @@ public:
* @param techtreeChecksum Cumulative checksum for the techtree. The path of loaded upgrades
* is added to this checksum.
*/
void load(const string &dir, const TechTree *techTree,
const FactionType *factionType, Checksum* checksum,
Checksum* techtreeChecksum,
std::map<string,vector<pair<string, string> > > &loadedFileList,
bool validationMode=false);
/**
void load (const string & dir, const TechTree * techTree,
const FactionType * factionType, Checksum * checksum,
Checksum * techtreeChecksum,
std::map < string, vector < pair < string,
string > > >&loadedFileList, bool validationMode = false);
/**
* Obtains the upgrade name.
* @param translatedValue If true, the name is translated. Otherwise the name is returned as it
* appears in the XMLs.
*/
virtual string getName(bool translatedValue=false) const;
string getTagName(string tag, bool translatedValue=false) const;
virtual string getName (bool translatedValue = false) const;
string getTagName (string tag, bool translatedValue = false) const;
/**
/**
* Determines if a unit is affected by this upgrade.
* @param unitType The UnitType we are checking (to see if they're affected).
* @return True if the unit is affected, false otherwise.
*/
bool isAffected(const UnitType *unitType) const;
bool isAffected (const UnitType * unitType) const;
/**
* Creates a description for this upgrade. Lists the affected units.
*/
virtual string getReqDesc(bool translatedValue) const;
virtual string getReqDesc (bool translatedValue) const;
//virtual void saveGame(XmlNode *rootNode) const;
//virtual void loadGame(const XmlNode *rootNode);
};
//virtual void saveGame(XmlNode *rootNode) const;
//virtual void loadGame(const XmlNode *rootNode);
};
/**
* Keeps track of the cumulative effects of upgrades on units. This allows us to apply multiple
* upgrades to a unit with the effects stacking.
*/
class TotalUpgrade: public UpgradeTypeBase {
class TotalUpgrade:public UpgradeTypeBase
{
private:
private:
// List of boosts
const UpgradeTypeBase *boostUpgradeBase;
int boostUpgradeSourceUnit;
int boostUpgradeDestUnit;
std::vector<TotalUpgrade *> boostUpgrades;
// List of boosts
const UpgradeTypeBase *boostUpgradeBase;
int boostUpgradeSourceUnit;
int boostUpgradeDestUnit;
std::vector < TotalUpgrade * >boostUpgrades;
public:
TotalUpgrade();
virtual ~TotalUpgrade() {}
public:
TotalUpgrade ();
virtual ~ TotalUpgrade ()
{
}
/**
/**
* Resets all stat boosts (so there's effectively no upgrade).
*/
void reset();
void reset ();
/**
/**
* Adds an upgrade to this one, stacking the effects. Note that multipliers are stacked
* by multiplying by the original, unboosted amount, and then adding that to the TotalUpgrade.
* @param ut The upgrade to apply.
* @param unit The unit this TotalUpgrade is associated with (since when we use a multiplier,
* the stats raise by an amount relative to the unit's base stats).
*/
void sum(const UpgradeTypeBase *ut, const Unit *unit, bool boostMode=false);
void sum (const UpgradeTypeBase * ut, const Unit * unit,
bool boostMode = false);
/**
/**
* Increases the level of the unit. Doing so results in their HP, EP, and armour going up by
* 50% while their sight goes up by 20%.
* @param ut The unit type to get the original stats from (so we can determine just how much
* to increase the stats by on level up).
*/
void incLevel(const UnitType *ut);
void incLevel (const UnitType * ut);
/**
/**
* Applies the upgrade. Just a delegate to TotalUpgrade::sum.
*/
void apply(int sourceUnitId, const UpgradeTypeBase *ut, const Unit *unit);
void apply (int sourceUnitId, const UpgradeTypeBase * ut,
const Unit * unit);
/**
/**
* Removes the effect of an upgrade to a specific unit. Using this after applying the upgrade
* is an invariant. ie,
*
@@ -400,45 +534,47 @@ public:
* @param unit The unit this TotalUpgrade is associated with (since when we use a multiplier,
* the stats were raise by an amount relative to the unit's base stats).
*/
void deapply(int sourceUnitId, const UpgradeTypeBase *ut,int destUnitId);
void deapply (int sourceUnitId, const UpgradeTypeBase * ut,
int destUnitId);
virtual int getMaxHp() const;
virtual int getMaxHpRegeneration() const;
virtual int getSight() const;
virtual int getMaxEp() const;
virtual int getMaxEpRegeneration() const;
virtual int getArmor() const;
virtual int getAttackStrength(const AttackSkillType *st) const;
virtual int getAttackRange(const AttackSkillType *st) const;
virtual int getMoveSpeed(const MoveSkillType *st) const;
virtual int getProdSpeed(const SkillType *st) const;
virtual int getAttackSpeed(const AttackSkillType *st) const;
virtual int getMaxHp () const;
virtual int getMaxHpRegeneration () const;
virtual int getSight () const;
virtual int getMaxEp () const;
virtual int getMaxEpRegeneration () const;
virtual int getArmor () const;
virtual int getAttackStrength (const AttackSkillType * st) const;
virtual int getAttackRange (const AttackSkillType * st) const;
virtual int getMoveSpeed (const MoveSkillType * st) const;
virtual int getProdSpeed (const SkillType * st) const;
virtual int getAttackSpeed (const AttackSkillType * st) const;
virtual int getMaxHpFromBoosts() const;
virtual int getMaxHpRegenerationFromBoosts() const;
virtual int getSightFromBoosts() const;
virtual int getMaxEpFromBoosts() const;
virtual int getMaxEpRegenerationFromBoosts() const;
virtual int getArmorFromBoosts() const;
virtual int getAttackStrengthFromBoosts(const AttackSkillType *st) const;
virtual int getAttackRangeFromBoosts(const AttackSkillType *st) const;
virtual int getMoveSpeedFromBoosts(const MoveSkillType *st) const;
virtual int getProdSpeedFromBoosts(const SkillType *st) const;
virtual int getAttackSpeedFromBoosts(const AttackSkillType *st) const;
virtual int getMaxHpFromBoosts () const;
virtual int getMaxHpRegenerationFromBoosts () const;
virtual int getSightFromBoosts () const;
virtual int getMaxEpFromBoosts () const;
virtual int getMaxEpRegenerationFromBoosts () const;
virtual int getArmorFromBoosts () const;
virtual int getAttackStrengthFromBoosts (const AttackSkillType *
st) const;
virtual int getAttackRangeFromBoosts (const AttackSkillType * st) const;
virtual int getMoveSpeedFromBoosts (const MoveSkillType * st) const;
virtual int getProdSpeedFromBoosts (const SkillType * st) const;
virtual int getAttackSpeedFromBoosts (const AttackSkillType * st) const;
/**
/**
* Creates the XML for the save game file. Essentially just stores everything about its state.
* @rootNode The node of the unit that this TotalUpgrade object belongs to.
*/
void saveGame(XmlNode *rootNode) const;
void saveGame (XmlNode * rootNode) const;
/**
/**
* Reloads the object's state from a saved game.
* @rootNode The node of the unit that this TotalUpgrade object belongs to.
*/
void loadGame(const XmlNode *rootNode);
};
void loadGame (const XmlNode * rootNode);
};
}}//end namespace
}} //end namespace
#endif