mirror of
https://github.com/glest/glest-source.git
synced 2025-08-21 07:31:21 +02:00
Bugfixes:
- final network fixes for mega-glest multiplayer performance improvements - added ability for windows builds to "ignore" hidden files so that glest wont try to read svn files - bugfix for loading the map editor
This commit is contained in:
@@ -252,7 +252,7 @@ END_EVENT_TABLE()
|
|||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
GlCanvas::GlCanvas(MainWindow * mainWindow):
|
GlCanvas::GlCanvas(MainWindow * mainWindow):
|
||||||
wxGLCanvas(mainWindow, -1)
|
wxGLCanvas(mainWindow, -1, wxDefaultPosition)
|
||||||
{
|
{
|
||||||
this->mainWindow = mainWindow;
|
this->mainWindow = mainWindow;
|
||||||
}
|
}
|
||||||
|
@@ -1,156 +1,166 @@
|
|||||||
// ==============================================================
|
// ==============================================================
|
||||||
// This file is part of Glest (www.glest.org)
|
// This file is part of Glest (www.glest.org)
|
||||||
//
|
//
|
||||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||||
//
|
//
|
||||||
// You can redistribute this code and/or modify it under
|
// You can redistribute this code and/or modify it under
|
||||||
// the terms of the GNU General Public License as published
|
// the terms of the GNU General Public License as published
|
||||||
// by the Free Software Foundation; either version 2 of the
|
// by the Free Software Foundation; either version 2 of the
|
||||||
// License, or (at your option) any later version
|
// License, or (at your option) any later version
|
||||||
// ==============================================================
|
// ==============================================================
|
||||||
|
|
||||||
#include "faction_type.h"
|
#include "faction_type.h"
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "xml_parser.h"
|
#include "xml_parser.h"
|
||||||
#include "tech_tree.h"
|
#include "tech_tree.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "platform_util.h"
|
#include "platform_util.h"
|
||||||
#include "game_util.h"
|
#include "game_util.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
using namespace Shared::Xml;
|
using namespace Shared::Xml;
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
// ======================================================
|
// ======================================================
|
||||||
// Class FactionType
|
// Class FactionType
|
||||||
// ======================================================
|
// ======================================================
|
||||||
|
|
||||||
FactionType::FactionType(){
|
FactionType::FactionType(){
|
||||||
music= NULL;
|
music= NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
//load a faction, given a directory
|
//load a faction, given a directory
|
||||||
void FactionType::load(const string &dir, const TechTree *techTree, Checksum* checksum){
|
void FactionType::load(const string &dir, const TechTree *techTree, Checksum* checksum){
|
||||||
|
|
||||||
name= lastDir(dir);
|
name= lastDir(dir);
|
||||||
|
|
||||||
Logger::getInstance().add("Faction type: "+ formatString(name), true);
|
Logger::getInstance().add("Faction type: "+ formatString(name), true);
|
||||||
|
|
||||||
// a1) preload units
|
// a1) preload units
|
||||||
string unitsPath= dir + "/units/*.";
|
string unitsPath= dir + "/units/*.";
|
||||||
vector<string> unitFilenames;
|
vector<string> unitFilenames;
|
||||||
findAll(unitsPath, unitFilenames);
|
findAll(unitsPath, unitFilenames);
|
||||||
unitTypes.resize(unitFilenames.size());
|
unitTypes.resize(unitFilenames.size());
|
||||||
for(int i=0; i<unitTypes.size(); ++i){
|
for(int i=0; i<unitTypes.size(); ++i){
|
||||||
string str= dir + "/units/" + unitFilenames[i];
|
string str= dir + "/units/" + unitFilenames[i];
|
||||||
unitTypes[i].preLoad(str);
|
unitTypes[i].preLoad(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// a2) preload upgrades
|
// a2) preload upgrades
|
||||||
string upgradesPath= dir + "/upgrades/*.";
|
string upgradesPath= dir + "/upgrades/*.";
|
||||||
vector<string> upgradeFilenames;
|
vector<string> upgradeFilenames;
|
||||||
findAll(upgradesPath, upgradeFilenames);
|
findAll(upgradesPath, upgradeFilenames);
|
||||||
upgradeTypes.resize(upgradeFilenames.size());
|
upgradeTypes.resize(upgradeFilenames.size());
|
||||||
for(int i=0; i<upgradeTypes.size(); ++i){
|
for(int i=0; i<upgradeTypes.size(); ++i){
|
||||||
string str= dir + "/upgrades/" + upgradeFilenames[i];
|
string str= dir + "/upgrades/" + upgradeFilenames[i];
|
||||||
upgradeTypes[i].preLoad(str);
|
upgradeTypes[i].preLoad(str);
|
||||||
}
|
}
|
||||||
|
|
||||||
// b1) load units
|
// b1) load units
|
||||||
try{
|
try{
|
||||||
for(int i=0; i<unitTypes.size(); ++i){
|
for(int i=0; i<unitTypes.size(); ++i){
|
||||||
string str= dir + "/units/" + unitTypes[i].getName();
|
string str= dir + "/units/" + unitTypes[i].getName();
|
||||||
unitTypes[i].load(i, str, techTree, this, checksum);
|
unitTypes[i].load(i, str, techTree, this, checksum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const exception &e){
|
catch(const exception &e){
|
||||||
throw runtime_error("Error loading units: "+ dir + "\n" + e.what());
|
throw runtime_error("Error loading units: "+ dir + "\n" + e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
// b2) load upgrades
|
// b2) load upgrades
|
||||||
try{
|
try{
|
||||||
for(int i=0; i<upgradeTypes.size(); ++i){
|
for(int i=0; i<upgradeTypes.size(); ++i){
|
||||||
string str= dir + "/upgrades/" + upgradeTypes[i].getName();
|
string str= dir + "/upgrades/" + upgradeTypes[i].getName();
|
||||||
upgradeTypes[i].load(str, techTree, this, checksum);
|
upgradeTypes[i].load(str, techTree, this, checksum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const exception &e){
|
catch(const exception &e){
|
||||||
throw runtime_error("Error loading upgrades: "+ dir + "\n" + e.what());
|
throw runtime_error("Error loading upgrades: "+ dir + "\n" + e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
//open xml file
|
//open xml file
|
||||||
string path= dir+"/"+name+".xml";
|
string path= dir+"/"+name+".xml";
|
||||||
|
|
||||||
checksum->addFile(path);
|
#ifdef _WINDOWS
|
||||||
|
|
||||||
XmlTree xmlTree;
|
DWORD fileAttributes = GetFileAttributes(path.c_str());
|
||||||
xmlTree.load(path);
|
if( (fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN)
|
||||||
const XmlNode *factionNode= xmlTree.getRootNode();
|
{
|
||||||
|
return;
|
||||||
//read starting resources
|
}
|
||||||
const XmlNode *startingResourcesNode= factionNode->getChild("starting-resources");
|
|
||||||
|
#endif
|
||||||
startingResources.resize(startingResourcesNode->getChildCount());
|
|
||||||
for(int i=0; i<startingResources.size(); ++i){
|
checksum->addFile(path);
|
||||||
const XmlNode *resourceNode= startingResourcesNode->getChild("resource", i);
|
|
||||||
string name= resourceNode->getAttribute("name")->getRestrictedValue();
|
XmlTree xmlTree;
|
||||||
int amount= resourceNode->getAttribute("amount")->getIntValue();
|
xmlTree.load(path);
|
||||||
startingResources[i].init(techTree->getResourceType(name), amount);
|
const XmlNode *factionNode= xmlTree.getRootNode();
|
||||||
}
|
|
||||||
|
//read starting resources
|
||||||
//read starting units
|
const XmlNode *startingResourcesNode= factionNode->getChild("starting-resources");
|
||||||
const XmlNode *startingUnitsNode= factionNode->getChild("starting-units");
|
|
||||||
for(int i=0; i<startingUnitsNode->getChildCount(); ++i){
|
startingResources.resize(startingResourcesNode->getChildCount());
|
||||||
const XmlNode *unitNode= startingUnitsNode->getChild("unit", i);
|
for(int i=0; i<startingResources.size(); ++i){
|
||||||
string name= unitNode->getAttribute("name")->getRestrictedValue();
|
const XmlNode *resourceNode= startingResourcesNode->getChild("resource", i);
|
||||||
int amount= unitNode->getAttribute("amount")->getIntValue();
|
string name= resourceNode->getAttribute("name")->getRestrictedValue();
|
||||||
startingUnits.push_back(PairPUnitTypeInt(getUnitType(name), amount));
|
int amount= resourceNode->getAttribute("amount")->getIntValue();
|
||||||
}
|
startingResources[i].init(techTree->getResourceType(name), amount);
|
||||||
|
}
|
||||||
//read music
|
|
||||||
const XmlNode *musicNode= factionNode->getChild("music");
|
//read starting units
|
||||||
bool value= musicNode->getAttribute("value")->getBoolValue();
|
const XmlNode *startingUnitsNode= factionNode->getChild("starting-units");
|
||||||
if(value){
|
for(int i=0; i<startingUnitsNode->getChildCount(); ++i){
|
||||||
music= new StrSound();
|
const XmlNode *unitNode= startingUnitsNode->getChild("unit", i);
|
||||||
music->open(dir+"/"+musicNode->getAttribute("path")->getRestrictedValue());
|
string name= unitNode->getAttribute("name")->getRestrictedValue();
|
||||||
}
|
int amount= unitNode->getAttribute("amount")->getIntValue();
|
||||||
}
|
startingUnits.push_back(PairPUnitTypeInt(getUnitType(name), amount));
|
||||||
|
}
|
||||||
FactionType::~FactionType(){
|
|
||||||
delete music;
|
//read music
|
||||||
}
|
const XmlNode *musicNode= factionNode->getChild("music");
|
||||||
|
bool value= musicNode->getAttribute("value")->getBoolValue();
|
||||||
// ==================== get ====================
|
if(value){
|
||||||
|
music= new StrSound();
|
||||||
const UnitType *FactionType::getUnitType(const string &name) const{
|
music->open(dir+"/"+musicNode->getAttribute("path")->getRestrictedValue());
|
||||||
for(int i=0; i<unitTypes.size();i++){
|
}
|
||||||
if(unitTypes[i].getName()==name){
|
}
|
||||||
return &unitTypes[i];
|
|
||||||
}
|
FactionType::~FactionType(){
|
||||||
}
|
delete music;
|
||||||
throw runtime_error("Unit not found: "+name);
|
}
|
||||||
}
|
|
||||||
|
// ==================== get ====================
|
||||||
const UpgradeType *FactionType::getUpgradeType(const string &name) const{
|
|
||||||
for(int i=0; i<upgradeTypes.size();i++){
|
const UnitType *FactionType::getUnitType(const string &name) const{
|
||||||
if(upgradeTypes[i].getName()==name){
|
for(int i=0; i<unitTypes.size();i++){
|
||||||
return &upgradeTypes[i];
|
if(unitTypes[i].getName()==name){
|
||||||
}
|
return &unitTypes[i];
|
||||||
}
|
}
|
||||||
throw runtime_error("Upgrade not found: "+name);
|
}
|
||||||
}
|
throw runtime_error("Unit not found: "+name);
|
||||||
|
}
|
||||||
int FactionType::getStartingResourceAmount(const ResourceType *resourceType) const{
|
|
||||||
for(int i=0; i<startingResources.size(); ++i){
|
const UpgradeType *FactionType::getUpgradeType(const string &name) const{
|
||||||
if(startingResources[i].getType()==resourceType){
|
for(int i=0; i<upgradeTypes.size();i++){
|
||||||
return startingResources[i].getAmount();
|
if(upgradeTypes[i].getName()==name){
|
||||||
}
|
return &upgradeTypes[i];
|
||||||
}
|
}
|
||||||
return 0;
|
}
|
||||||
}
|
throw runtime_error("Upgrade not found: "+name);
|
||||||
|
}
|
||||||
}}//end namespace
|
|
||||||
|
int FactionType::getStartingResourceAmount(const ResourceType *resourceType) const{
|
||||||
|
for(int i=0; i<startingResources.size(); ++i){
|
||||||
|
if(startingResources[i].getType()==resourceType){
|
||||||
|
return startingResources[i].getAmount();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
@@ -1,145 +1,155 @@
|
|||||||
// ==============================================================
|
// ==============================================================
|
||||||
// This file is part of Glest (www.glest.org)
|
// This file is part of Glest (www.glest.org)
|
||||||
//
|
//
|
||||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||||
//
|
//
|
||||||
// You can redistribute this code and/or modify it under
|
// You can redistribute this code and/or modify it under
|
||||||
// the terms of the GNU General Public License as published
|
// the terms of the GNU General Public License as published
|
||||||
// by the Free Software Foundation; either version 2 of the
|
// by the Free Software Foundation; either version 2 of the
|
||||||
// License, or (at your option) any later version
|
// License, or (at your option) any later version
|
||||||
// ==============================================================
|
// ==============================================================
|
||||||
|
|
||||||
#include "resource_type.h"
|
#include "resource_type.h"
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "element_type.h"
|
#include "element_type.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "xml_parser.h"
|
#include "xml_parser.h"
|
||||||
#include "game_util.h"
|
#include "game_util.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
using namespace Shared::Xml;
|
using namespace Shared::Xml;
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class ResourceType
|
// class ResourceType
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
void ResourceType::load(const string &dir, Checksum* checksum){
|
void ResourceType::load(const string &dir, Checksum* checksum){
|
||||||
|
|
||||||
string path, str;
|
string path, str;
|
||||||
Renderer &renderer= Renderer::getInstance();
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
try
|
try
|
||||||
{
|
{
|
||||||
recoup_cost = true;
|
recoup_cost = true;
|
||||||
|
|
||||||
name= lastDir(dir);
|
name= lastDir(dir);
|
||||||
|
|
||||||
Logger::getInstance().add("Resource type: "+ formatString(name), true);
|
Logger::getInstance().add("Resource type: "+ formatString(name), true);
|
||||||
path= dir+"/"+name+".xml";
|
path= dir+"/"+name+".xml";
|
||||||
|
|
||||||
checksum->addFile(path);
|
#ifdef _WINDOWS
|
||||||
|
|
||||||
//tree
|
DWORD fileAttributes = GetFileAttributes(path.c_str());
|
||||||
XmlTree xmlTree;
|
if( (fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN)
|
||||||
xmlTree.load(path);
|
{
|
||||||
const XmlNode *resourceNode= xmlTree.getRootNode();
|
return;
|
||||||
|
}
|
||||||
//image
|
|
||||||
const XmlNode *imageNode= resourceNode->getChild("image");
|
#endif
|
||||||
image= renderer.newTexture2D(rsGame);
|
|
||||||
image->load(dir+"/"+imageNode->getAttribute("path")->getRestrictedValue());
|
checksum->addFile(path);
|
||||||
|
|
||||||
//type
|
//tree
|
||||||
const XmlNode *typeNode= resourceNode->getChild("type");
|
XmlTree xmlTree;
|
||||||
resourceClass= strToRc(typeNode->getAttribute("value")->getRestrictedValue());
|
xmlTree.load(path);
|
||||||
|
const XmlNode *resourceNode= xmlTree.getRootNode();
|
||||||
switch(resourceClass)
|
|
||||||
{
|
//image
|
||||||
case rcTech:
|
const XmlNode *imageNode= resourceNode->getChild("image");
|
||||||
{
|
image= renderer.newTexture2D(rsGame);
|
||||||
//model
|
image->load(dir+"/"+imageNode->getAttribute("path")->getRestrictedValue());
|
||||||
const XmlNode *modelNode= typeNode->getChild("model");
|
|
||||||
string path=dir+"/" + modelNode->getAttribute("path")->getRestrictedValue();
|
//type
|
||||||
|
const XmlNode *typeNode= resourceNode->getChild("type");
|
||||||
model= renderer.newModel(rsGame);
|
resourceClass= strToRc(typeNode->getAttribute("value")->getRestrictedValue());
|
||||||
model->load(path);
|
|
||||||
|
switch(resourceClass)
|
||||||
//default resources
|
{
|
||||||
const XmlNode *defaultAmountNode= typeNode->getChild("default-amount");
|
case rcTech:
|
||||||
defResPerPatch= defaultAmountNode->getAttribute("value")->getIntValue();
|
{
|
||||||
|
//model
|
||||||
//resource number
|
const XmlNode *modelNode= typeNode->getChild("model");
|
||||||
const XmlNode *resourceNumberNode= typeNode->getChild("resource-number");
|
string path=dir+"/" + modelNode->getAttribute("path")->getRestrictedValue();
|
||||||
resourceNumber= resourceNumberNode->getAttribute("value")->getIntValue();
|
|
||||||
|
model= renderer.newModel(rsGame);
|
||||||
}
|
model->load(path);
|
||||||
break;
|
|
||||||
|
//default resources
|
||||||
case rcTileset:
|
const XmlNode *defaultAmountNode= typeNode->getChild("default-amount");
|
||||||
{
|
defResPerPatch= defaultAmountNode->getAttribute("value")->getIntValue();
|
||||||
//resource number
|
|
||||||
const XmlNode *defaultAmountNode= typeNode->getChild("default-amount");
|
//resource number
|
||||||
defResPerPatch= defaultAmountNode->getAttribute("value")->getIntValue();
|
const XmlNode *resourceNumberNode= typeNode->getChild("resource-number");
|
||||||
|
resourceNumber= resourceNumberNode->getAttribute("value")->getIntValue();
|
||||||
//resource number
|
|
||||||
const XmlNode *tilesetObjectNode= typeNode->getChild("tileset-object");
|
}
|
||||||
tilesetObject= tilesetObjectNode->getAttribute("value")->getIntValue();
|
break;
|
||||||
}
|
|
||||||
break;
|
case rcTileset:
|
||||||
|
{
|
||||||
case rcConsumable:
|
//resource number
|
||||||
{
|
const XmlNode *defaultAmountNode= typeNode->getChild("default-amount");
|
||||||
//interval
|
defResPerPatch= defaultAmountNode->getAttribute("value")->getIntValue();
|
||||||
const XmlNode *intervalNode= typeNode->getChild("interval");
|
|
||||||
interval= intervalNode->getAttribute("value")->getIntValue();
|
//resource number
|
||||||
}
|
const XmlNode *tilesetObjectNode= typeNode->getChild("tileset-object");
|
||||||
break;
|
tilesetObject= tilesetObjectNode->getAttribute("value")->getIntValue();
|
||||||
|
}
|
||||||
case rcStatic:
|
break;
|
||||||
{
|
|
||||||
//recoup_cost
|
case rcConsumable:
|
||||||
if(typeNode->hasChild("recoup_cost") == true)
|
{
|
||||||
{
|
//interval
|
||||||
const XmlNode *recoup_costNode= typeNode->getChild("recoup_cost");
|
const XmlNode *intervalNode= typeNode->getChild("interval");
|
||||||
if(recoup_costNode != NULL)
|
interval= intervalNode->getAttribute("value")->getIntValue();
|
||||||
{
|
}
|
||||||
recoup_cost= recoup_costNode->getAttribute("value")->getBoolValue();
|
break;
|
||||||
}
|
|
||||||
}
|
case rcStatic:
|
||||||
}
|
{
|
||||||
break;
|
//recoup_cost
|
||||||
|
if(typeNode->hasChild("recoup_cost") == true)
|
||||||
default:
|
{
|
||||||
break;
|
const XmlNode *recoup_costNode= typeNode->getChild("recoup_cost");
|
||||||
}
|
if(recoup_costNode != NULL)
|
||||||
}
|
{
|
||||||
catch(const exception &e){
|
recoup_cost= recoup_costNode->getAttribute("value")->getBoolValue();
|
||||||
throw runtime_error("Error loading resource type: " + path + "\n" + e.what());
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
break;
|
||||||
|
|
||||||
// ==================== misc ====================
|
default:
|
||||||
|
break;
|
||||||
ResourceClass ResourceType::strToRc(const string &s){
|
}
|
||||||
if(s=="tech"){
|
}
|
||||||
return rcTech;
|
catch(const exception &e){
|
||||||
}
|
throw runtime_error("Error loading resource type: " + path + "\n" + e.what());
|
||||||
if(s=="tileset"){
|
}
|
||||||
return rcTileset;
|
}
|
||||||
}
|
|
||||||
if(s=="static"){
|
|
||||||
return rcStatic;
|
// ==================== misc ====================
|
||||||
}
|
|
||||||
if(s=="consumable"){
|
ResourceClass ResourceType::strToRc(const string &s){
|
||||||
return rcConsumable;
|
if(s=="tech"){
|
||||||
}
|
return rcTech;
|
||||||
throw runtime_error("Error converting from string ro resourceClass, found: " + s);
|
}
|
||||||
}
|
if(s=="tileset"){
|
||||||
|
return rcTileset;
|
||||||
}}//end namespace
|
}
|
||||||
|
if(s=="static"){
|
||||||
|
return rcStatic;
|
||||||
|
}
|
||||||
|
if(s=="consumable"){
|
||||||
|
return rcConsumable;
|
||||||
|
}
|
||||||
|
throw runtime_error("Error converting from string ro resourceClass, found: " + s);
|
||||||
|
}
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
@@ -1,190 +1,204 @@
|
|||||||
// ==============================================================
|
// ==============================================================
|
||||||
// This file is part of Glest (www.glest.org)
|
// This file is part of Glest (www.glest.org)
|
||||||
//
|
//
|
||||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||||
//
|
//
|
||||||
// You can redistribute this code and/or modify it under
|
// You can redistribute this code and/or modify it under
|
||||||
// the terms of the GNU General Public License as published
|
// the terms of the GNU General Public License as published
|
||||||
// by the Free Software Foundation; either version 2 of the
|
// by the Free Software Foundation; either version 2 of the
|
||||||
// License, or (at your option) any later version
|
// License, or (at your option) any later version
|
||||||
// ==============================================================
|
// ==============================================================
|
||||||
|
|
||||||
#include "tech_tree.h"
|
#include "tech_tree.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "faction_type.h"
|
#include "faction_type.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "xml_parser.h"
|
#include "xml_parser.h"
|
||||||
#include "platform_util.h"
|
#include "platform_util.h"
|
||||||
#include "game_util.h"
|
#include "game_util.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
using namespace Shared::Xml;
|
using namespace Shared::Xml;
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class TechTree
|
// class TechTree
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum){
|
void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum){
|
||||||
|
|
||||||
string str;
|
string str;
|
||||||
vector<string> filenames;
|
vector<string> filenames;
|
||||||
string name= lastDir(dir);
|
string name= lastDir(dir);
|
||||||
|
|
||||||
Logger::getInstance().add("TechTree: "+ formatString(name), true);
|
Logger::getInstance().add("TechTree: "+ formatString(name), true);
|
||||||
|
|
||||||
//load resources
|
//load resources
|
||||||
str= dir+"/resources/*.";
|
str= dir+"/resources/*.";
|
||||||
|
|
||||||
try{
|
try{
|
||||||
findAll(str, filenames);
|
findAll(str, filenames);
|
||||||
resourceTypes.resize(filenames.size());
|
resourceTypes.resize(filenames.size());
|
||||||
|
|
||||||
for(int i=0; i<filenames.size(); ++i){
|
for(int i=0; i<filenames.size(); ++i){
|
||||||
str=dir+"/resources/"+filenames[i];
|
str=dir+"/resources/"+filenames[i];
|
||||||
resourceTypes[i].load(str, checksum);
|
resourceTypes[i].load(str, checksum);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const exception &e){
|
catch(const exception &e){
|
||||||
throw runtime_error("Error loading Resource Types: "+ dir + "\n" + e.what());
|
throw runtime_error("Error loading Resource Types: "+ dir + "\n" + e.what());
|
||||||
}
|
}
|
||||||
|
|
||||||
//load tech tree xml info
|
//load tech tree xml info
|
||||||
try{
|
try{
|
||||||
XmlTree xmlTree;
|
XmlTree xmlTree;
|
||||||
string path= dir+"/"+lastDir(dir)+".xml";
|
string path= dir+"/"+lastDir(dir)+".xml";
|
||||||
|
|
||||||
checksum->addFile(path);
|
bool bCanProcessFile = true;
|
||||||
|
#ifdef _WINDOWS
|
||||||
xmlTree.load(path);
|
|
||||||
const XmlNode *techTreeNode= xmlTree.getRootNode();
|
DWORD fileAttributes = GetFileAttributes(path.c_str());
|
||||||
|
if( (fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN)
|
||||||
//attack types
|
{
|
||||||
const XmlNode *attackTypesNode= techTreeNode->getChild("attack-types");
|
bCanProcessFile = false;
|
||||||
attackTypes.resize(attackTypesNode->getChildCount());
|
}
|
||||||
for(int i=0; i<attackTypes.size(); ++i){
|
|
||||||
const XmlNode *attackTypeNode= attackTypesNode->getChild("attack-type", i);
|
#endif
|
||||||
attackTypes[i].setName(attackTypeNode->getAttribute("name")->getRestrictedValue());
|
|
||||||
attackTypes[i].setId(i);
|
if(bCanProcessFile == true)
|
||||||
}
|
{
|
||||||
|
checksum->addFile(path);
|
||||||
//armor types
|
|
||||||
const XmlNode *armorTypesNode= techTreeNode->getChild("armor-types");
|
xmlTree.load(path);
|
||||||
armorTypes.resize(armorTypesNode->getChildCount());
|
const XmlNode *techTreeNode= xmlTree.getRootNode();
|
||||||
for(int i=0; i<armorTypes.size(); ++i){
|
|
||||||
const XmlNode *armorTypeNode= armorTypesNode->getChild("armor-type", i);
|
//attack types
|
||||||
armorTypes[i].setName(armorTypeNode->getAttribute("name")->getRestrictedValue());
|
const XmlNode *attackTypesNode= techTreeNode->getChild("attack-types");
|
||||||
armorTypes[i].setId(i);
|
attackTypes.resize(attackTypesNode->getChildCount());
|
||||||
}
|
for(int i=0; i<attackTypes.size(); ++i){
|
||||||
|
const XmlNode *attackTypeNode= attackTypesNode->getChild("attack-type", i);
|
||||||
//damage multipliers
|
attackTypes[i].setName(attackTypeNode->getAttribute("name")->getRestrictedValue());
|
||||||
damageMultiplierTable.init(attackTypes.size(), armorTypes.size());
|
attackTypes[i].setId(i);
|
||||||
const XmlNode *damageMultipliersNode= techTreeNode->getChild("damage-multipliers");
|
}
|
||||||
for(int i=0; i<damageMultipliersNode->getChildCount(); ++i){
|
|
||||||
const XmlNode *damageMultiplierNode= damageMultipliersNode->getChild("damage-multiplier", i);
|
//armor types
|
||||||
const AttackType *attackType= getAttackType(damageMultiplierNode->getAttribute("attack")->getRestrictedValue());
|
const XmlNode *armorTypesNode= techTreeNode->getChild("armor-types");
|
||||||
const ArmorType *armorType= getArmorType(damageMultiplierNode->getAttribute("armor")->getRestrictedValue());
|
armorTypes.resize(armorTypesNode->getChildCount());
|
||||||
float multiplier= damageMultiplierNode->getAttribute("value")->getFloatValue();
|
for(int i=0; i<armorTypes.size(); ++i){
|
||||||
damageMultiplierTable.setDamageMultiplier(attackType, armorType, multiplier);
|
const XmlNode *armorTypeNode= armorTypesNode->getChild("armor-type", i);
|
||||||
}
|
armorTypes[i].setName(armorTypeNode->getAttribute("name")->getRestrictedValue());
|
||||||
}
|
armorTypes[i].setId(i);
|
||||||
catch(const exception &e){
|
}
|
||||||
throw runtime_error("Error loading Tech Tree: "+ dir + "\n" + e.what());
|
|
||||||
}
|
//damage multipliers
|
||||||
|
damageMultiplierTable.init(attackTypes.size(), armorTypes.size());
|
||||||
//load factions
|
const XmlNode *damageMultipliersNode= techTreeNode->getChild("damage-multipliers");
|
||||||
str= dir+"/factions/*.";
|
for(int i=0; i<damageMultipliersNode->getChildCount(); ++i){
|
||||||
try{
|
const XmlNode *damageMultiplierNode= damageMultipliersNode->getChild("damage-multiplier", i);
|
||||||
factionTypes.resize(factions.size());
|
const AttackType *attackType= getAttackType(damageMultiplierNode->getAttribute("attack")->getRestrictedValue());
|
||||||
|
const ArmorType *armorType= getArmorType(damageMultiplierNode->getAttribute("armor")->getRestrictedValue());
|
||||||
int i=0;
|
float multiplier= damageMultiplierNode->getAttribute("value")->getFloatValue();
|
||||||
for ( set<string>::iterator it = factions.begin(); it != factions.end(); ++it ) {
|
damageMultiplierTable.setDamageMultiplier(attackType, armorType, multiplier);
|
||||||
str=dir+"/factions/" + *it;
|
}
|
||||||
factionTypes[i++].load(str, this, checksum);
|
}
|
||||||
}
|
}
|
||||||
}
|
catch(const exception &e){
|
||||||
catch(const exception &e){
|
throw runtime_error("Error loading Tech Tree: "+ dir + "\n" + e.what());
|
||||||
throw runtime_error("Error loading Faction Types: "+ dir + "\n" + e.what());
|
}
|
||||||
}
|
|
||||||
|
//load factions
|
||||||
}
|
str= dir+"/factions/*.";
|
||||||
|
try{
|
||||||
TechTree::~TechTree(){
|
factionTypes.resize(factions.size());
|
||||||
Logger::getInstance().add("Tech tree", true);
|
|
||||||
}
|
int i=0;
|
||||||
|
for ( set<string>::iterator it = factions.begin(); it != factions.end(); ++it ) {
|
||||||
|
str=dir+"/factions/" + *it;
|
||||||
// ==================== get ====================
|
factionTypes[i++].load(str, this, checksum);
|
||||||
|
}
|
||||||
const FactionType *TechTree::getType(const string &name) const{
|
}
|
||||||
for(int i=0; i<factionTypes.size(); ++i){
|
catch(const exception &e){
|
||||||
if(factionTypes[i].getName()==name){
|
throw runtime_error("Error loading Faction Types: "+ dir + "\n" + e.what());
|
||||||
return &factionTypes[i];
|
}
|
||||||
}
|
|
||||||
}
|
}
|
||||||
throw runtime_error("Faction not found: "+name);
|
|
||||||
}
|
TechTree::~TechTree(){
|
||||||
|
Logger::getInstance().add("Tech tree", true);
|
||||||
const ResourceType *TechTree::getTechResourceType(int i) const{
|
}
|
||||||
|
|
||||||
for(int j=0; j<getResourceTypeCount(); ++j){
|
|
||||||
const ResourceType *rt= getResourceType(j);
|
// ==================== get ====================
|
||||||
if(rt->getResourceNumber()==i && rt->getClass()==rcTech)
|
|
||||||
return getResourceType(j);
|
const FactionType *TechTree::getType(const string &name) const{
|
||||||
}
|
for(int i=0; i<factionTypes.size(); ++i){
|
||||||
|
if(factionTypes[i].getName()==name){
|
||||||
return getFirstTechResourceType();
|
return &factionTypes[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const ResourceType *TechTree::getFirstTechResourceType() const{
|
throw runtime_error("Faction not found: "+name);
|
||||||
for(int i=0; i<getResourceTypeCount(); ++i){
|
}
|
||||||
const ResourceType *rt= getResourceType(i);
|
|
||||||
if(rt->getResourceNumber()==1 && rt->getClass()==rcTech)
|
const ResourceType *TechTree::getTechResourceType(int i) const{
|
||||||
return getResourceType(i);
|
|
||||||
}
|
for(int j=0; j<getResourceTypeCount(); ++j){
|
||||||
|
const ResourceType *rt= getResourceType(j);
|
||||||
throw runtime_error("This tech tree has not tech resources, one at least is required");
|
if(rt->getResourceNumber()==i && rt->getClass()==rcTech)
|
||||||
}
|
return getResourceType(j);
|
||||||
|
}
|
||||||
const ResourceType *TechTree::getResourceType(const string &name) const{
|
|
||||||
|
return getFirstTechResourceType();
|
||||||
for(int i=0; i<resourceTypes.size(); ++i){
|
}
|
||||||
if(resourceTypes[i].getName()==name){
|
|
||||||
return &resourceTypes[i];
|
const ResourceType *TechTree::getFirstTechResourceType() const{
|
||||||
}
|
for(int i=0; i<getResourceTypeCount(); ++i){
|
||||||
}
|
const ResourceType *rt= getResourceType(i);
|
||||||
|
if(rt->getResourceNumber()==1 && rt->getClass()==rcTech)
|
||||||
throw runtime_error("Resource Type not found: "+name);
|
return getResourceType(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
const ArmorType *TechTree::getArmorType(const string &name) const{
|
throw runtime_error("This tech tree has not tech resources, one at least is required");
|
||||||
for(int i=0; i<armorTypes.size(); ++i){
|
}
|
||||||
if(armorTypes[i].getName()==name){
|
|
||||||
return &armorTypes[i];
|
const ResourceType *TechTree::getResourceType(const string &name) const{
|
||||||
}
|
|
||||||
}
|
for(int i=0; i<resourceTypes.size(); ++i){
|
||||||
|
if(resourceTypes[i].getName()==name){
|
||||||
throw runtime_error("Armor Type not found: "+name);
|
return &resourceTypes[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
const AttackType *TechTree::getAttackType(const string &name) const{
|
|
||||||
for(int i=0; i<attackTypes.size(); ++i){
|
throw runtime_error("Resource Type not found: "+name);
|
||||||
if(attackTypes[i].getName()==name){
|
}
|
||||||
return &attackTypes[i];
|
|
||||||
}
|
const ArmorType *TechTree::getArmorType(const string &name) const{
|
||||||
}
|
for(int i=0; i<armorTypes.size(); ++i){
|
||||||
|
if(armorTypes[i].getName()==name){
|
||||||
throw runtime_error("Attack Type not found: "+name);
|
return &armorTypes[i];
|
||||||
}
|
}
|
||||||
|
}
|
||||||
float TechTree::getDamageMultiplier(const AttackType *att, const ArmorType *art) const{
|
|
||||||
return damageMultiplierTable.getDamageMultiplier(att, art);
|
throw runtime_error("Armor Type not found: "+name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}}//end namespace
|
const AttackType *TechTree::getAttackType(const string &name) const{
|
||||||
|
for(int i=0; i<attackTypes.size(); ++i){
|
||||||
|
if(attackTypes[i].getName()==name){
|
||||||
|
return &attackTypes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
throw runtime_error("Attack Type not found: "+name);
|
||||||
|
}
|
||||||
|
|
||||||
|
float TechTree::getDamageMultiplier(const AttackType *att, const ArmorType *art) const{
|
||||||
|
return damageMultiplierTable.getDamageMultiplier(att, art);
|
||||||
|
}
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
File diff suppressed because it is too large
Load Diff
@@ -1,209 +1,219 @@
|
|||||||
// ==============================================================
|
// ==============================================================
|
||||||
// This file is part of Glest (www.glest.org)
|
// This file is part of Glest (www.glest.org)
|
||||||
//
|
//
|
||||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||||
//
|
//
|
||||||
// You can redistribute this code and/or modify it under
|
// You can redistribute this code and/or modify it under
|
||||||
// the terms of the GNU General Public License as published
|
// the terms of the GNU General Public License as published
|
||||||
// by the Free Software Foundation; either version 2 of the
|
// by the Free Software Foundation; either version 2 of the
|
||||||
// License, or (at your option) any later version
|
// License, or (at your option) any later version
|
||||||
// ==============================================================
|
// ==============================================================
|
||||||
|
|
||||||
#include "upgrade_type.h"
|
#include "upgrade_type.h"
|
||||||
|
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
|
|
||||||
#include "unit_type.h"
|
#include "unit_type.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "lang.h"
|
#include "lang.h"
|
||||||
#include "xml_parser.h"
|
#include "xml_parser.h"
|
||||||
#include "tech_tree.h"
|
#include "tech_tree.h"
|
||||||
#include "faction_type.h"
|
#include "faction_type.h"
|
||||||
#include "resource.h"
|
#include "resource.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "game_util.h"
|
#include "game_util.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
using namespace Shared::Xml;
|
using namespace Shared::Xml;
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class UpgradeType
|
// class UpgradeType
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
// ==================== get ====================
|
// ==================== get ====================
|
||||||
|
|
||||||
bool UpgradeType::isAffected(const UnitType *unitType) const{
|
bool UpgradeType::isAffected(const UnitType *unitType) const{
|
||||||
return find(effects.begin(), effects.end(), unitType)!=effects.end();
|
return find(effects.begin(), effects.end(), unitType)!=effects.end();
|
||||||
}
|
}
|
||||||
|
|
||||||
// ==================== misc ====================
|
// ==================== misc ====================
|
||||||
|
|
||||||
void UpgradeType::preLoad(const string &dir){
|
void UpgradeType::preLoad(const string &dir){
|
||||||
name=lastDir(dir);
|
name=lastDir(dir);
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpgradeType::load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum){
|
void UpgradeType::load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum){
|
||||||
string path;
|
string path;
|
||||||
|
|
||||||
Logger::getInstance().add("Upgrade type: "+ formatString(name), true);
|
Logger::getInstance().add("Upgrade type: "+ formatString(name), true);
|
||||||
|
|
||||||
path=dir+"/"+name+".xml";
|
path=dir+"/"+name+".xml";
|
||||||
|
|
||||||
try{
|
#ifdef _WINDOWS
|
||||||
checksum->addFile(path);
|
|
||||||
|
DWORD fileAttributes = GetFileAttributes(path.c_str());
|
||||||
XmlTree xmlTree;
|
if( (fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN)
|
||||||
xmlTree.load(path);
|
{
|
||||||
const XmlNode *upgradeNode= xmlTree.getRootNode();
|
return;
|
||||||
|
}
|
||||||
//image
|
|
||||||
const XmlNode *imageNode= upgradeNode->getChild("image");
|
#endif
|
||||||
image= Renderer::getInstance().newTexture2D(rsGame);
|
|
||||||
image->load(dir+"/"+imageNode->getAttribute("path")->getRestrictedValue());
|
try{
|
||||||
|
checksum->addFile(path);
|
||||||
//image cancel
|
|
||||||
const XmlNode *imageCancelNode= upgradeNode->getChild("image-cancel");
|
XmlTree xmlTree;
|
||||||
cancelImage= Renderer::getInstance().newTexture2D(rsGame);
|
xmlTree.load(path);
|
||||||
cancelImage->load(dir+"/"+imageCancelNode->getAttribute("path")->getRestrictedValue());
|
const XmlNode *upgradeNode= xmlTree.getRootNode();
|
||||||
|
|
||||||
//upgrade time
|
//image
|
||||||
const XmlNode *upgradeTimeNode= upgradeNode->getChild("time");
|
const XmlNode *imageNode= upgradeNode->getChild("image");
|
||||||
productionTime= upgradeTimeNode->getAttribute("value")->getIntValue();
|
image= Renderer::getInstance().newTexture2D(rsGame);
|
||||||
|
image->load(dir+"/"+imageNode->getAttribute("path")->getRestrictedValue());
|
||||||
//unit requirements
|
|
||||||
const XmlNode *unitRequirementsNode= upgradeNode->getChild("unit-requirements");
|
//image cancel
|
||||||
for(int i=0; i<unitRequirementsNode->getChildCount(); ++i){
|
const XmlNode *imageCancelNode= upgradeNode->getChild("image-cancel");
|
||||||
const XmlNode *unitNode= unitRequirementsNode->getChild("unit", i);
|
cancelImage= Renderer::getInstance().newTexture2D(rsGame);
|
||||||
string name= unitNode->getAttribute("name")->getRestrictedValue();
|
cancelImage->load(dir+"/"+imageCancelNode->getAttribute("path")->getRestrictedValue());
|
||||||
unitReqs.push_back(factionType->getUnitType(name));
|
|
||||||
}
|
//upgrade time
|
||||||
|
const XmlNode *upgradeTimeNode= upgradeNode->getChild("time");
|
||||||
//upgrade requirements
|
productionTime= upgradeTimeNode->getAttribute("value")->getIntValue();
|
||||||
const XmlNode *upgradeRequirementsNode= upgradeNode->getChild("upgrade-requirements");
|
|
||||||
for(int i=0; i<upgradeRequirementsNode->getChildCount(); ++i){
|
//unit requirements
|
||||||
const XmlNode *upgradeReqNode= upgradeRequirementsNode->getChild("upgrade", i);
|
const XmlNode *unitRequirementsNode= upgradeNode->getChild("unit-requirements");
|
||||||
string name= upgradeReqNode->getAttribute("name")->getRestrictedValue();
|
for(int i=0; i<unitRequirementsNode->getChildCount(); ++i){
|
||||||
upgradeReqs.push_back(factionType->getUpgradeType(name));
|
const XmlNode *unitNode= unitRequirementsNode->getChild("unit", i);
|
||||||
}
|
string name= unitNode->getAttribute("name")->getRestrictedValue();
|
||||||
|
unitReqs.push_back(factionType->getUnitType(name));
|
||||||
//resource requirements
|
}
|
||||||
const XmlNode *resourceRequirementsNode= upgradeNode->getChild("resource-requirements");
|
|
||||||
costs.resize(resourceRequirementsNode->getChildCount());
|
//upgrade requirements
|
||||||
for(int i=0; i<costs.size(); ++i){
|
const XmlNode *upgradeRequirementsNode= upgradeNode->getChild("upgrade-requirements");
|
||||||
const XmlNode *resourceNode= resourceRequirementsNode->getChild("resource", i);
|
for(int i=0; i<upgradeRequirementsNode->getChildCount(); ++i){
|
||||||
string name= resourceNode->getAttribute("name")->getRestrictedValue();
|
const XmlNode *upgradeReqNode= upgradeRequirementsNode->getChild("upgrade", i);
|
||||||
int amount= resourceNode->getAttribute("amount")->getIntValue();
|
string name= upgradeReqNode->getAttribute("name")->getRestrictedValue();
|
||||||
costs[i].init(techTree->getResourceType(name), amount);
|
upgradeReqs.push_back(factionType->getUpgradeType(name));
|
||||||
}
|
}
|
||||||
|
|
||||||
//effects
|
//resource requirements
|
||||||
const XmlNode *effectsNode= upgradeNode->getChild("effects");
|
const XmlNode *resourceRequirementsNode= upgradeNode->getChild("resource-requirements");
|
||||||
for(int i=0; i<effectsNode->getChildCount(); ++i){
|
costs.resize(resourceRequirementsNode->getChildCount());
|
||||||
const XmlNode *unitNode= effectsNode->getChild("unit", i);
|
for(int i=0; i<costs.size(); ++i){
|
||||||
string name= unitNode->getAttribute("name")->getRestrictedValue();
|
const XmlNode *resourceNode= resourceRequirementsNode->getChild("resource", i);
|
||||||
effects.push_back(factionType->getUnitType(name));
|
string name= resourceNode->getAttribute("name")->getRestrictedValue();
|
||||||
}
|
int amount= resourceNode->getAttribute("amount")->getIntValue();
|
||||||
|
costs[i].init(techTree->getResourceType(name), amount);
|
||||||
//values
|
}
|
||||||
maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue();
|
|
||||||
maxEp= upgradeNode->getChild("max-ep")->getAttribute("value")->getIntValue();
|
//effects
|
||||||
sight= upgradeNode->getChild("sight")->getAttribute("value")->getIntValue();
|
const XmlNode *effectsNode= upgradeNode->getChild("effects");
|
||||||
attackStrength= upgradeNode->getChild("attack-strenght")->getAttribute("value")->getIntValue();
|
for(int i=0; i<effectsNode->getChildCount(); ++i){
|
||||||
attackRange= upgradeNode->getChild("attack-range")->getAttribute("value")->getIntValue();
|
const XmlNode *unitNode= effectsNode->getChild("unit", i);
|
||||||
armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue();
|
string name= unitNode->getAttribute("name")->getRestrictedValue();
|
||||||
moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue();
|
effects.push_back(factionType->getUnitType(name));
|
||||||
prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue();
|
}
|
||||||
|
|
||||||
}
|
//values
|
||||||
catch(const exception &e){
|
maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue();
|
||||||
throw runtime_error("Error loading UpgradeType: "+ dir + "\n" +e.what());
|
maxEp= upgradeNode->getChild("max-ep")->getAttribute("value")->getIntValue();
|
||||||
}
|
sight= upgradeNode->getChild("sight")->getAttribute("value")->getIntValue();
|
||||||
}
|
attackStrength= upgradeNode->getChild("attack-strenght")->getAttribute("value")->getIntValue();
|
||||||
|
attackRange= upgradeNode->getChild("attack-range")->getAttribute("value")->getIntValue();
|
||||||
string UpgradeType::getReqDesc() const{
|
armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue();
|
||||||
|
moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue();
|
||||||
string str;
|
prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue();
|
||||||
int i;
|
|
||||||
Lang &lang= Lang::getInstance();
|
}
|
||||||
|
catch(const exception &e){
|
||||||
str= ProducibleType::getReqDesc();
|
throw runtime_error("Error loading UpgradeType: "+ dir + "\n" +e.what());
|
||||||
if(getEffectCount()>0){
|
}
|
||||||
str+= "\n"+ lang.get("Upgrades")+":\n";
|
}
|
||||||
for(i=0; i<getEffectCount(); ++i){
|
|
||||||
str+= getEffect(i)->getName()+"\n";
|
string UpgradeType::getReqDesc() const{
|
||||||
}
|
|
||||||
}
|
string str;
|
||||||
|
int i;
|
||||||
if(maxHp!=0){
|
Lang &lang= Lang::getInstance();
|
||||||
str+= lang.get("Hp")+" +"+intToStr(maxHp);
|
|
||||||
}
|
str= ProducibleType::getReqDesc();
|
||||||
if(sight!=0){
|
if(getEffectCount()>0){
|
||||||
str+= lang.get("Sight")+" +"+intToStr(sight);
|
str+= "\n"+ lang.get("Upgrades")+":\n";
|
||||||
}
|
for(i=0; i<getEffectCount(); ++i){
|
||||||
if(maxEp!=0){
|
str+= getEffect(i)->getName()+"\n";
|
||||||
str+= lang.get("Ep")+" +"+intToStr(maxEp)+"\n";
|
}
|
||||||
}
|
}
|
||||||
if(attackStrength!=0){
|
|
||||||
str+= lang.get("AttackStrenght")+" +"+intToStr(attackStrength)+"\n";
|
if(maxHp!=0){
|
||||||
}
|
str+= lang.get("Hp")+" +"+intToStr(maxHp);
|
||||||
if(attackRange!=0){
|
}
|
||||||
str+= lang.get("AttackDistance")+" +"+intToStr(attackRange)+"\n";
|
if(sight!=0){
|
||||||
}
|
str+= lang.get("Sight")+" +"+intToStr(sight);
|
||||||
if(armor!=0){
|
}
|
||||||
str+= lang.get("Armor")+" +"+intToStr(armor)+"\n";
|
if(maxEp!=0){
|
||||||
}
|
str+= lang.get("Ep")+" +"+intToStr(maxEp)+"\n";
|
||||||
if(moveSpeed!=0){
|
}
|
||||||
str+= lang.get("WalkSpeed")+"+ "+intToStr(moveSpeed)+"\n";
|
if(attackStrength!=0){
|
||||||
}
|
str+= lang.get("AttackStrenght")+" +"+intToStr(attackStrength)+"\n";
|
||||||
if(prodSpeed!=0){
|
}
|
||||||
str+= lang.get("ProductionSpeed")+" +"+intToStr(prodSpeed)+"\n";
|
if(attackRange!=0){
|
||||||
}
|
str+= lang.get("AttackDistance")+" +"+intToStr(attackRange)+"\n";
|
||||||
|
}
|
||||||
return str;
|
if(armor!=0){
|
||||||
}
|
str+= lang.get("Armor")+" +"+intToStr(armor)+"\n";
|
||||||
|
}
|
||||||
|
if(moveSpeed!=0){
|
||||||
|
str+= lang.get("WalkSpeed")+"+ "+intToStr(moveSpeed)+"\n";
|
||||||
// ===============================
|
}
|
||||||
// class TotalUpgrade
|
if(prodSpeed!=0){
|
||||||
// ===============================
|
str+= lang.get("ProductionSpeed")+" +"+intToStr(prodSpeed)+"\n";
|
||||||
|
}
|
||||||
TotalUpgrade::TotalUpgrade(){
|
|
||||||
reset();
|
return str;
|
||||||
}
|
}
|
||||||
|
|
||||||
void TotalUpgrade::reset(){
|
|
||||||
maxHp= 0;
|
|
||||||
maxEp= 0;
|
// ===============================
|
||||||
sight=0;
|
// class TotalUpgrade
|
||||||
armor= 0;
|
// ===============================
|
||||||
attackStrength= 0;
|
|
||||||
attackRange= 0;
|
TotalUpgrade::TotalUpgrade(){
|
||||||
moveSpeed= 0;
|
reset();
|
||||||
prodSpeed=0;
|
}
|
||||||
}
|
|
||||||
|
void TotalUpgrade::reset(){
|
||||||
void TotalUpgrade::sum(const UpgradeType *ut){
|
maxHp= 0;
|
||||||
maxHp+= ut->getMaxHp();
|
maxEp= 0;
|
||||||
maxEp+= ut->getMaxEp();
|
sight=0;
|
||||||
sight+= ut->getSight();
|
armor= 0;
|
||||||
armor+= ut->getArmor();
|
attackStrength= 0;
|
||||||
attackStrength+= ut->getAttackStrength();
|
attackRange= 0;
|
||||||
attackRange+= ut->getAttackRange();
|
moveSpeed= 0;
|
||||||
moveSpeed+= ut->getMoveSpeed();
|
prodSpeed=0;
|
||||||
prodSpeed+= ut->getProdSpeed();
|
}
|
||||||
}
|
|
||||||
|
void TotalUpgrade::sum(const UpgradeType *ut){
|
||||||
void TotalUpgrade::incLevel(const UnitType *ut){
|
maxHp+= ut->getMaxHp();
|
||||||
maxHp+= ut->getMaxHp()*50/100;
|
maxEp+= ut->getMaxEp();
|
||||||
maxEp+= ut->getMaxEp()*50/100;
|
sight+= ut->getSight();
|
||||||
sight+= ut->getSight()*20/100;
|
armor+= ut->getArmor();
|
||||||
armor+= ut->getArmor()*50/100;
|
attackStrength+= ut->getAttackStrength();
|
||||||
}
|
attackRange+= ut->getAttackRange();
|
||||||
|
moveSpeed+= ut->getMoveSpeed();
|
||||||
}}//end namespace
|
prodSpeed+= ut->getProdSpeed();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TotalUpgrade::incLevel(const UnitType *ut){
|
||||||
|
maxHp+= ut->getMaxHp()*50/100;
|
||||||
|
maxEp+= ut->getMaxEp()*50/100;
|
||||||
|
sight+= ut->getSight()*20/100;
|
||||||
|
armor+= ut->getArmor()*50/100;
|
||||||
|
}
|
||||||
|
|
||||||
|
}}//end namespace
|
||||||
|
@@ -3,8 +3,8 @@
|
|||||||
//
|
//
|
||||||
// Copyright (C) 2001-2005 Marti<74>o Figueroa
|
// Copyright (C) 2001-2005 Marti<74>o Figueroa
|
||||||
//
|
//
|
||||||
// You can redistribute this code and/or modify it under
|
// You can redistribute this code and/or modify it under
|
||||||
// the terms of the GNU General Public License as published
|
// the terms of the GNU General Public License as published
|
||||||
// by the Free Software Foundation; either version 2 of the
|
// by the Free Software Foundation; either version 2 of the
|
||||||
// License, or (at your option) any later version
|
// License, or (at your option) any later version
|
||||||
// ==============================================================
|
// ==============================================================
|
||||||
|
@@ -1,252 +1,262 @@
|
|||||||
// ==============================================================
|
// ==============================================================
|
||||||
// This file is part of Glest (www.glest.org)
|
// This file is part of Glest (www.glest.org)
|
||||||
//
|
//
|
||||||
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||||
//
|
//
|
||||||
// You can redistribute this code and/or modify it under
|
// You can redistribute this code and/or modify it under
|
||||||
// the terms of the GNU General Public License as published
|
// the terms of the GNU General Public License as published
|
||||||
// by the Free Software Foundation; either version 2 of the
|
// by the Free Software Foundation; either version 2 of the
|
||||||
// License, or (at your option) any later version
|
// License, or (at your option) any later version
|
||||||
// ==============================================================
|
// ==============================================================
|
||||||
|
|
||||||
#include "tileset.h"
|
#include "tileset.h"
|
||||||
|
|
||||||
#include <cassert>
|
#include <cassert>
|
||||||
#include <ctime>
|
#include <ctime>
|
||||||
|
|
||||||
#include "logger.h"
|
#include "logger.h"
|
||||||
#include "util.h"
|
#include "util.h"
|
||||||
#include "renderer.h"
|
#include "renderer.h"
|
||||||
#include "game_util.h"
|
#include "game_util.h"
|
||||||
#include "leak_dumper.h"
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
using namespace Shared::Util;
|
using namespace Shared::Util;
|
||||||
using namespace Shared::Xml;
|
using namespace Shared::Xml;
|
||||||
using namespace Shared::Graphics;
|
using namespace Shared::Graphics;
|
||||||
|
|
||||||
namespace Glest{ namespace Game{
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class AmbientSounds
|
// class AmbientSounds
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
|
void AmbientSounds::load(const string &dir, const XmlNode *xmlNode){
|
||||||
string path;
|
string path;
|
||||||
|
|
||||||
//day
|
//day
|
||||||
const XmlNode *dayNode= xmlNode->getChild("day-sound");
|
const XmlNode *dayNode= xmlNode->getChild("day-sound");
|
||||||
enabledDay= dayNode->getAttribute("enabled")->getBoolValue();
|
enabledDay= dayNode->getAttribute("enabled")->getBoolValue();
|
||||||
if(enabledDay){
|
if(enabledDay){
|
||||||
path= dayNode->getAttribute("path")->getRestrictedValue();
|
path= dayNode->getAttribute("path")->getRestrictedValue();
|
||||||
day.open(dir + "/" + path);
|
day.open(dir + "/" + path);
|
||||||
alwaysPlayDay= dayNode->getAttribute("play-always")->getBoolValue();
|
alwaysPlayDay= dayNode->getAttribute("play-always")->getBoolValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
//night
|
//night
|
||||||
const XmlNode *nightNode= xmlNode->getChild("night-sound");
|
const XmlNode *nightNode= xmlNode->getChild("night-sound");
|
||||||
enabledNight= nightNode->getAttribute("enabled")->getBoolValue();
|
enabledNight= nightNode->getAttribute("enabled")->getBoolValue();
|
||||||
if(enabledNight){
|
if(enabledNight){
|
||||||
path= nightNode->getAttribute("path")->getRestrictedValue();
|
path= nightNode->getAttribute("path")->getRestrictedValue();
|
||||||
night.open(dir + "/" + path);
|
night.open(dir + "/" + path);
|
||||||
alwaysPlayNight= nightNode->getAttribute("play-always")->getBoolValue();
|
alwaysPlayNight= nightNode->getAttribute("play-always")->getBoolValue();
|
||||||
}
|
}
|
||||||
|
|
||||||
//rain
|
//rain
|
||||||
const XmlNode *rainNode= xmlNode->getChild("rain-sound");
|
const XmlNode *rainNode= xmlNode->getChild("rain-sound");
|
||||||
enabledRain= rainNode->getAttribute("enabled")->getBoolValue();
|
enabledRain= rainNode->getAttribute("enabled")->getBoolValue();
|
||||||
if(enabledRain){
|
if(enabledRain){
|
||||||
path= rainNode->getAttribute("path")->getRestrictedValue();
|
path= rainNode->getAttribute("path")->getRestrictedValue();
|
||||||
rain.open(dir + "/" + path);
|
rain.open(dir + "/" + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
//snow
|
//snow
|
||||||
const XmlNode *snowNode= xmlNode->getChild("snow-sound");
|
const XmlNode *snowNode= xmlNode->getChild("snow-sound");
|
||||||
enabledSnow= snowNode->getAttribute("enabled")->getBoolValue();
|
enabledSnow= snowNode->getAttribute("enabled")->getBoolValue();
|
||||||
if(enabledSnow){
|
if(enabledSnow){
|
||||||
path= snowNode->getAttribute("path")->getRestrictedValue();
|
path= snowNode->getAttribute("path")->getRestrictedValue();
|
||||||
snow.open(dir + "/" + path);
|
snow.open(dir + "/" + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
//dayStart
|
//dayStart
|
||||||
const XmlNode *dayStartNode= xmlNode->getChild("day-start-sound");
|
const XmlNode *dayStartNode= xmlNode->getChild("day-start-sound");
|
||||||
enabledDayStart= dayStartNode->getAttribute("enabled")->getBoolValue();
|
enabledDayStart= dayStartNode->getAttribute("enabled")->getBoolValue();
|
||||||
if(enabledDayStart){
|
if(enabledDayStart){
|
||||||
path= dayStartNode->getAttribute("path")->getRestrictedValue();
|
path= dayStartNode->getAttribute("path")->getRestrictedValue();
|
||||||
dayStart.load(dir + "/" + path);
|
dayStart.load(dir + "/" + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
//nightStart
|
//nightStart
|
||||||
const XmlNode *nightStartNode= xmlNode->getChild("night-start-sound");
|
const XmlNode *nightStartNode= xmlNode->getChild("night-start-sound");
|
||||||
enabledNightStart= nightStartNode->getAttribute("enabled")->getBoolValue();
|
enabledNightStart= nightStartNode->getAttribute("enabled")->getBoolValue();
|
||||||
if(enabledNightStart){
|
if(enabledNightStart){
|
||||||
path= nightStartNode->getAttribute("path")->getRestrictedValue();
|
path= nightStartNode->getAttribute("path")->getRestrictedValue();
|
||||||
nightStart.load(dir + "/" + path);
|
nightStart.load(dir + "/" + path);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// =====================================================
|
// =====================================================
|
||||||
// class Tileset
|
// class Tileset
|
||||||
// =====================================================
|
// =====================================================
|
||||||
|
|
||||||
void Tileset::load(const string &dir, Checksum *checksum){
|
void Tileset::load(const string &dir, Checksum *checksum){
|
||||||
|
|
||||||
random.init(time(NULL));
|
random.init(time(NULL));
|
||||||
|
|
||||||
string name= lastDir(dir);
|
string name= lastDir(dir);
|
||||||
string path= dir+"/"+name+".xml";
|
string path= dir+"/"+name+".xml";
|
||||||
|
|
||||||
checksum->addFile(path);
|
#ifdef _WINDOWS
|
||||||
|
|
||||||
try{
|
DWORD fileAttributes = GetFileAttributes(path.c_str());
|
||||||
Logger::getInstance().add("Tileset: "+formatString(name), true);
|
if( (fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN)
|
||||||
Renderer &renderer= Renderer::getInstance();
|
{
|
||||||
|
return;
|
||||||
//parse xml
|
}
|
||||||
XmlTree xmlTree;
|
|
||||||
xmlTree.load(path);
|
#endif
|
||||||
const XmlNode *tilesetNode= xmlTree.getRootNode();
|
|
||||||
|
checksum->addFile(path);
|
||||||
//surfaces
|
|
||||||
const XmlNode *surfacesNode= tilesetNode->getChild("surfaces");
|
try{
|
||||||
for(int i=0; i<surfCount; ++i){
|
Logger::getInstance().add("Tileset: "+formatString(name), true);
|
||||||
const XmlNode *surfaceNode= surfacesNode->getChild("surface", i);
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
int childCount= surfaceNode->getChildCount();
|
//parse xml
|
||||||
surfPixmaps[i].resize(childCount);
|
XmlTree xmlTree;
|
||||||
surfProbs[i].resize(childCount);
|
xmlTree.load(path);
|
||||||
for(int j=0; j<childCount; ++j){
|
const XmlNode *tilesetNode= xmlTree.getRootNode();
|
||||||
const XmlNode *textureNode= surfaceNode->getChild("texture", j);
|
|
||||||
surfPixmaps[i][j].init(3);
|
//surfaces
|
||||||
surfPixmaps[i][j].load(dir +"/"+textureNode->getAttribute("path")->getRestrictedValue());
|
const XmlNode *surfacesNode= tilesetNode->getChild("surfaces");
|
||||||
surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue();
|
for(int i=0; i<surfCount; ++i){
|
||||||
}
|
const XmlNode *surfaceNode= surfacesNode->getChild("surface", i);
|
||||||
}
|
|
||||||
|
int childCount= surfaceNode->getChildCount();
|
||||||
//object models
|
surfPixmaps[i].resize(childCount);
|
||||||
const XmlNode *objectsNode= tilesetNode->getChild("objects");
|
surfProbs[i].resize(childCount);
|
||||||
for(int i=0; i<objCount; ++i){
|
for(int j=0; j<childCount; ++j){
|
||||||
const XmlNode *objectNode= objectsNode->getChild("object", i);
|
const XmlNode *textureNode= surfaceNode->getChild("texture", j);
|
||||||
int childCount= objectNode->getChildCount();
|
surfPixmaps[i][j].init(3);
|
||||||
objectTypes[i].init(childCount, i, objectNode->getAttribute("walkable")->getBoolValue());
|
surfPixmaps[i][j].load(dir +"/"+textureNode->getAttribute("path")->getRestrictedValue());
|
||||||
for(int j=0; j<childCount; ++j){
|
surfProbs[i][j]= textureNode->getAttribute("prob")->getFloatValue();
|
||||||
const XmlNode *modelNode= objectNode->getChild("model", j);
|
}
|
||||||
const XmlAttribute *pathAttribute= modelNode->getAttribute("path");
|
}
|
||||||
objectTypes[i].loadModel(dir +"/"+ pathAttribute->getRestrictedValue());
|
|
||||||
}
|
//object models
|
||||||
}
|
const XmlNode *objectsNode= tilesetNode->getChild("objects");
|
||||||
|
for(int i=0; i<objCount; ++i){
|
||||||
//ambient sounds
|
const XmlNode *objectNode= objectsNode->getChild("object", i);
|
||||||
ambientSounds.load(dir, tilesetNode->getChild("ambient-sounds"));
|
int childCount= objectNode->getChildCount();
|
||||||
|
objectTypes[i].init(childCount, i, objectNode->getAttribute("walkable")->getBoolValue());
|
||||||
//parameters
|
for(int j=0; j<childCount; ++j){
|
||||||
const XmlNode *parametersNode= tilesetNode->getChild("parameters");
|
const XmlNode *modelNode= objectNode->getChild("model", j);
|
||||||
|
const XmlAttribute *pathAttribute= modelNode->getAttribute("path");
|
||||||
//water
|
objectTypes[i].loadModel(dir +"/"+ pathAttribute->getRestrictedValue());
|
||||||
const XmlNode *waterNode= parametersNode->getChild("water");
|
}
|
||||||
waterTex= renderer.newTexture3D(rsGame);
|
}
|
||||||
waterTex->setMipmap(false);
|
|
||||||
waterTex->setWrapMode(Texture::wmRepeat);
|
//ambient sounds
|
||||||
waterEffects= waterNode->getAttribute("effects")->getBoolValue();
|
ambientSounds.load(dir, tilesetNode->getChild("ambient-sounds"));
|
||||||
|
|
||||||
int waterFrameCount= waterNode->getChildCount();
|
//parameters
|
||||||
waterTex->getPixmap()->init(waterFrameCount, 4);
|
const XmlNode *parametersNode= tilesetNode->getChild("parameters");
|
||||||
for(int i=0; i<waterFrameCount; ++i){
|
|
||||||
const XmlNode *waterFrameNode= waterNode->getChild("texture", i);
|
//water
|
||||||
waterTex->getPixmap()->loadSlice(dir +"/"+ waterFrameNode->getAttribute("path")->getRestrictedValue(), i);
|
const XmlNode *waterNode= parametersNode->getChild("water");
|
||||||
}
|
waterTex= renderer.newTexture3D(rsGame);
|
||||||
|
waterTex->setMipmap(false);
|
||||||
//fog
|
waterTex->setWrapMode(Texture::wmRepeat);
|
||||||
const XmlNode *fogNode= parametersNode->getChild("fog");
|
waterEffects= waterNode->getAttribute("effects")->getBoolValue();
|
||||||
fog= fogNode->getAttribute("enabled")->getBoolValue();
|
|
||||||
if(fog){
|
int waterFrameCount= waterNode->getChildCount();
|
||||||
fogMode= fogNode->getAttribute("mode")->getIntValue(1, 2);
|
waterTex->getPixmap()->init(waterFrameCount, 4);
|
||||||
fogDensity= fogNode->getAttribute("density")->getFloatValue();
|
for(int i=0; i<waterFrameCount; ++i){
|
||||||
fogColor.x= fogNode->getAttribute("color-red")->getFloatValue(0.f, 1.f);
|
const XmlNode *waterFrameNode= waterNode->getChild("texture", i);
|
||||||
fogColor.y= fogNode->getAttribute("color-green")->getFloatValue(0.f, 1.f);
|
waterTex->getPixmap()->loadSlice(dir +"/"+ waterFrameNode->getAttribute("path")->getRestrictedValue(), i);
|
||||||
fogColor.z= fogNode->getAttribute("color-blue")->getFloatValue(0.f, 1.f);
|
}
|
||||||
}
|
|
||||||
|
//fog
|
||||||
//sun and moon light colors
|
const XmlNode *fogNode= parametersNode->getChild("fog");
|
||||||
const XmlNode *sunLightColorNode= parametersNode->getChild("sun-light");
|
fog= fogNode->getAttribute("enabled")->getBoolValue();
|
||||||
sunLightColor.x= sunLightColorNode->getAttribute("red")->getFloatValue();
|
if(fog){
|
||||||
sunLightColor.y= sunLightColorNode->getAttribute("green")->getFloatValue();
|
fogMode= fogNode->getAttribute("mode")->getIntValue(1, 2);
|
||||||
sunLightColor.z= sunLightColorNode->getAttribute("blue")->getFloatValue();
|
fogDensity= fogNode->getAttribute("density")->getFloatValue();
|
||||||
|
fogColor.x= fogNode->getAttribute("color-red")->getFloatValue(0.f, 1.f);
|
||||||
const XmlNode *moonLightColorNode= parametersNode->getChild("moon-light");
|
fogColor.y= fogNode->getAttribute("color-green")->getFloatValue(0.f, 1.f);
|
||||||
moonLightColor.x= moonLightColorNode->getAttribute("red")->getFloatValue();
|
fogColor.z= fogNode->getAttribute("color-blue")->getFloatValue(0.f, 1.f);
|
||||||
moonLightColor.y= moonLightColorNode->getAttribute("green")->getFloatValue();
|
}
|
||||||
moonLightColor.z= moonLightColorNode->getAttribute("blue")->getFloatValue();
|
|
||||||
|
//sun and moon light colors
|
||||||
|
const XmlNode *sunLightColorNode= parametersNode->getChild("sun-light");
|
||||||
//weather
|
sunLightColor.x= sunLightColorNode->getAttribute("red")->getFloatValue();
|
||||||
const XmlNode *weatherNode= parametersNode->getChild("weather");
|
sunLightColor.y= sunLightColorNode->getAttribute("green")->getFloatValue();
|
||||||
float sunnyProb= weatherNode->getAttribute("sun")->getFloatValue(0.f, 1.f);
|
sunLightColor.z= sunLightColorNode->getAttribute("blue")->getFloatValue();
|
||||||
float rainyProb= weatherNode->getAttribute("rain")->getFloatValue(0.f, 1.f) + sunnyProb;
|
|
||||||
float rnd= fabs(random.randRange(-1.f, 1.f));
|
const XmlNode *moonLightColorNode= parametersNode->getChild("moon-light");
|
||||||
|
moonLightColor.x= moonLightColorNode->getAttribute("red")->getFloatValue();
|
||||||
if(rnd<sunnyProb){
|
moonLightColor.y= moonLightColorNode->getAttribute("green")->getFloatValue();
|
||||||
weather= wSunny;
|
moonLightColor.z= moonLightColorNode->getAttribute("blue")->getFloatValue();
|
||||||
}
|
|
||||||
else if(rnd<rainyProb){
|
|
||||||
weather= wRainy;
|
//weather
|
||||||
}
|
const XmlNode *weatherNode= parametersNode->getChild("weather");
|
||||||
else{
|
float sunnyProb= weatherNode->getAttribute("sun")->getFloatValue(0.f, 1.f);
|
||||||
weather= wSnowy;
|
float rainyProb= weatherNode->getAttribute("rain")->getFloatValue(0.f, 1.f) + sunnyProb;
|
||||||
}
|
float rnd= fabs(random.randRange(-1.f, 1.f));
|
||||||
|
|
||||||
}
|
if(rnd<sunnyProb){
|
||||||
//Exception handling (conversions and so on);
|
weather= wSunny;
|
||||||
catch(const exception &e){
|
}
|
||||||
throw runtime_error("Error: " + path + "\n" + e.what());
|
else if(rnd<rainyProb){
|
||||||
}
|
weather= wRainy;
|
||||||
}
|
}
|
||||||
|
else{
|
||||||
Tileset::~Tileset(){
|
weather= wSnowy;
|
||||||
Logger::getInstance().add("Tileset", true);
|
}
|
||||||
}
|
|
||||||
|
}
|
||||||
const Pixmap2D *Tileset::getSurfPixmap(int type, int var) const{
|
//Exception handling (conversions and so on);
|
||||||
int vars= surfPixmaps[type].size();
|
catch(const exception &e){
|
||||||
return &surfPixmaps[type][var % vars];
|
throw runtime_error("Error: " + path + "\n" + e.what());
|
||||||
}
|
}
|
||||||
|
}
|
||||||
void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, Vec2f &coord, const Texture2D *&texture){
|
|
||||||
|
Tileset::~Tileset(){
|
||||||
//center textures
|
Logger::getInstance().add("Tileset", true);
|
||||||
if(leftUp==rightUp && leftUp==leftDown && leftUp==rightDown){
|
}
|
||||||
|
|
||||||
//texture variation according to probability
|
const Pixmap2D *Tileset::getSurfPixmap(int type, int var) const{
|
||||||
float r= random.randRange(0.f, 1.f);
|
int vars= surfPixmaps[type].size();
|
||||||
int var= 0;
|
return &surfPixmaps[type][var % vars];
|
||||||
float max= 0.f;
|
}
|
||||||
for(int i=0; i<surfProbs[leftUp].size(); ++i){
|
|
||||||
max+= surfProbs[leftUp][i];
|
void Tileset::addSurfTex(int leftUp, int rightUp, int leftDown, int rightDown, Vec2f &coord, const Texture2D *&texture){
|
||||||
if(r<=max){
|
|
||||||
var= i;
|
//center textures
|
||||||
break;
|
if(leftUp==rightUp && leftUp==leftDown && leftUp==rightDown){
|
||||||
}
|
|
||||||
}
|
//texture variation according to probability
|
||||||
SurfaceInfo si(getSurfPixmap(leftUp, var));
|
float r= random.randRange(0.f, 1.f);
|
||||||
surfaceAtlas.addSurface(&si);
|
int var= 0;
|
||||||
coord= si.getCoord();
|
float max= 0.f;
|
||||||
texture= si.getTexture();
|
for(int i=0; i<surfProbs[leftUp].size(); ++i){
|
||||||
}
|
max+= surfProbs[leftUp][i];
|
||||||
|
if(r<=max){
|
||||||
//spatted textures
|
var= i;
|
||||||
else{
|
break;
|
||||||
int var= random.randRange(0, transitionVars);
|
}
|
||||||
|
}
|
||||||
SurfaceInfo si(
|
SurfaceInfo si(getSurfPixmap(leftUp, var));
|
||||||
getSurfPixmap(leftUp, var),
|
surfaceAtlas.addSurface(&si);
|
||||||
getSurfPixmap(rightUp, var),
|
coord= si.getCoord();
|
||||||
getSurfPixmap(leftDown, var),
|
texture= si.getTexture();
|
||||||
getSurfPixmap(rightDown, var));
|
}
|
||||||
surfaceAtlas.addSurface(&si);
|
|
||||||
coord= si.getCoord();
|
//spatted textures
|
||||||
texture= si.getTexture();
|
else{
|
||||||
}
|
int var= random.randRange(0, transitionVars);
|
||||||
|
|
||||||
}
|
SurfaceInfo si(
|
||||||
|
getSurfPixmap(leftUp, var),
|
||||||
}}// end namespace
|
getSurfPixmap(rightUp, var),
|
||||||
|
getSurfPixmap(leftDown, var),
|
||||||
|
getSurfPixmap(rightDown, var));
|
||||||
|
surfaceAtlas.addSurface(&si);
|
||||||
|
coord= si.getCoord();
|
||||||
|
texture= si.getTexture();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}}// end namespace
|
||||||
|
Reference in New Issue
Block a user