mirror of
https://github.com/glest/glest-source.git
synced 2025-08-15 12:54:01 +02:00
Bugfixes so that win32 code will work with latest user data changes
This commit is contained in:
@@ -15,7 +15,7 @@
|
|||||||
#include "context.h"
|
#include "context.h"
|
||||||
#include "platform_util.h"
|
#include "platform_util.h"
|
||||||
#include "window_gl.h"
|
#include "window_gl.h"
|
||||||
#include "socket.h"
|
#include "socket.h"
|
||||||
#include "components.h"
|
#include "components.h"
|
||||||
|
|
||||||
using Shared::Graphics::Context;
|
using Shared::Graphics::Context;
|
||||||
@@ -69,25 +69,25 @@ public:
|
|||||||
class Program{
|
class Program{
|
||||||
private:
|
private:
|
||||||
static const int maxTimes;
|
static const int maxTimes;
|
||||||
|
|
||||||
class ShowMessageProgramState : public ProgramState {
|
class ShowMessageProgramState : public ProgramState {
|
||||||
GraphicMessageBox msgBox;
|
GraphicMessageBox msgBox;
|
||||||
int mouseX;
|
int mouseX;
|
||||||
int mouseY;
|
int mouseY;
|
||||||
int mouse2dAnim;
|
int mouse2dAnim;
|
||||||
string msg;
|
string msg;
|
||||||
bool userWantsExit;
|
bool userWantsExit;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ShowMessageProgramState(Program *program, const char *msg);
|
ShowMessageProgramState(Program *program, const char *msg);
|
||||||
|
|
||||||
virtual void render();
|
virtual void render();
|
||||||
virtual void mouseDownLeft(int x, int y);
|
virtual void mouseDownLeft(int x, int y);
|
||||||
virtual void mouseMove(int x, int y, const MouseState &mouseState);
|
virtual void mouseMove(int x, int y, const MouseState &mouseState);
|
||||||
virtual void update();
|
virtual void update();
|
||||||
virtual bool wantExit() { return userWantsExit; }
|
virtual bool wantExit() { return userWantsExit; }
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ProgramState *programState;
|
ProgramState *programState;
|
||||||
@@ -96,13 +96,13 @@ private:
|
|||||||
PerformanceTimer updateTimer;
|
PerformanceTimer updateTimer;
|
||||||
PerformanceTimer updateCameraTimer;
|
PerformanceTimer updateCameraTimer;
|
||||||
|
|
||||||
WindowGl *window;
|
WindowGl *window;
|
||||||
static Program *singleton;
|
static Program *singleton;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
Program();
|
Program();
|
||||||
~Program();
|
~Program();
|
||||||
|
|
||||||
static Program *getInstance() {return singleton;}
|
static Program *getInstance() {return singleton;}
|
||||||
|
|
||||||
void initNormal(WindowGl *window);
|
void initNormal(WindowGl *window);
|
||||||
@@ -119,7 +119,7 @@ public:
|
|||||||
void keyUp(char key);
|
void keyUp(char key);
|
||||||
void keyPress(char c);
|
void keyPress(char c);
|
||||||
void loop();
|
void loop();
|
||||||
void resize(SizeState sizeState);
|
void resize(SizeState sizeState);
|
||||||
void showMessage(const char *msg);
|
void showMessage(const char *msg);
|
||||||
|
|
||||||
//misc
|
//misc
|
||||||
|
155
source/glest_game/types/faction_type.cpp
Normal file
155
source/glest_game/types/faction_type.cpp
Normal file
@@ -0,0 +1,155 @@
|
|||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#include "faction_type.h"
|
||||||
|
|
||||||
|
#include "logger.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "xml_parser.h"
|
||||||
|
#include "tech_tree.h"
|
||||||
|
#include "resource.h"
|
||||||
|
#include "platform_util.h"
|
||||||
|
#include "game_util.h"
|
||||||
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
using namespace Shared::Util;
|
||||||
|
using namespace Shared::Xml;
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
// ======================================================
|
||||||
|
// Class FactionType
|
||||||
|
// ======================================================
|
||||||
|
|
||||||
|
FactionType::FactionType(){
|
||||||
|
music= NULL;
|
||||||
|
}
|
||||||
|
|
||||||
|
//load a faction, given a directory
|
||||||
|
void FactionType::load(const string &dir, const TechTree *techTree, Checksum* checksum){
|
||||||
|
|
||||||
|
name= lastDir(dir);
|
||||||
|
|
||||||
|
Logger::getInstance().add("Faction type: "+ formatString(name), true);
|
||||||
|
|
||||||
|
// a1) preload units
|
||||||
|
string unitsPath= dir + "/units/*.";
|
||||||
|
vector<string> unitFilenames;
|
||||||
|
findAll(unitsPath, unitFilenames);
|
||||||
|
unitTypes.resize(unitFilenames.size());
|
||||||
|
for(int i=0; i<unitTypes.size(); ++i){
|
||||||
|
string str= dir + "/units/" + unitFilenames[i];
|
||||||
|
unitTypes[i].preLoad(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
// a2) preload upgrades
|
||||||
|
string upgradesPath= dir + "/upgrades/*.";
|
||||||
|
vector<string> upgradeFilenames;
|
||||||
|
findAll(upgradesPath, upgradeFilenames);
|
||||||
|
upgradeTypes.resize(upgradeFilenames.size());
|
||||||
|
for(int i=0; i<upgradeTypes.size(); ++i){
|
||||||
|
string str= dir + "/upgrades/" + upgradeFilenames[i];
|
||||||
|
upgradeTypes[i].preLoad(str);
|
||||||
|
}
|
||||||
|
|
||||||
|
// b1) load units
|
||||||
|
try{
|
||||||
|
for(int i=0; i<unitTypes.size(); ++i){
|
||||||
|
string str= dir + "/units/" + unitTypes[i].getName();
|
||||||
|
unitTypes[i].load(i, str, techTree, this, checksum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const exception &e){
|
||||||
|
throw runtime_error("Error loading units: "+ dir + "\n" + e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
// b2) load upgrades
|
||||||
|
try{
|
||||||
|
for(int i=0; i<upgradeTypes.size(); ++i){
|
||||||
|
string str= dir + "/upgrades/" + upgradeTypes[i].getName();
|
||||||
|
upgradeTypes[i].load(str, techTree, this, checksum);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const exception &e){
|
||||||
|
throw runtime_error("Error loading upgrades: "+ dir + "\n" + e.what());
|
||||||
|
}
|
||||||
|
|
||||||
|
//open xml file
|
||||||
|
string path= dir+"/"+name+".xml";
|
||||||
|
checksum->addFile(path);
|
||||||
|
|
||||||
|
XmlTree xmlTree;
|
||||||
|
xmlTree.load(path);
|
||||||
|
const XmlNode *factionNode= xmlTree.getRootNode();
|
||||||
|
|
||||||
|
//read starting resources
|
||||||
|
const XmlNode *startingResourcesNode= factionNode->getChild("starting-resources");
|
||||||
|
|
||||||
|
startingResources.resize(startingResourcesNode->getChildCount());
|
||||||
|
for(int i=0; i<startingResources.size(); ++i){
|
||||||
|
const XmlNode *resourceNode= startingResourcesNode->getChild("resource", i);
|
||||||
|
string name= resourceNode->getAttribute("name")->getRestrictedValue();
|
||||||
|
int amount= resourceNode->getAttribute("amount")->getIntValue();
|
||||||
|
startingResources[i].init(techTree->getResourceType(name), amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
//read starting units
|
||||||
|
const XmlNode *startingUnitsNode= factionNode->getChild("starting-units");
|
||||||
|
for(int i=0; i<startingUnitsNode->getChildCount(); ++i){
|
||||||
|
const XmlNode *unitNode= startingUnitsNode->getChild("unit", i);
|
||||||
|
string name= unitNode->getAttribute("name")->getRestrictedValue();
|
||||||
|
int amount= unitNode->getAttribute("amount")->getIntValue();
|
||||||
|
startingUnits.push_back(PairPUnitTypeInt(getUnitType(name), amount));
|
||||||
|
}
|
||||||
|
|
||||||
|
//read music
|
||||||
|
const XmlNode *musicNode= factionNode->getChild("music");
|
||||||
|
bool value= musicNode->getAttribute("value")->getBoolValue();
|
||||||
|
if(value){
|
||||||
|
music= new StrSound();
|
||||||
|
music->open(dir+"/"+musicNode->getAttribute("path")->getRestrictedValue());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
FactionType::~FactionType(){
|
||||||
|
delete music;
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== get ====================
|
||||||
|
|
||||||
|
const UnitType *FactionType::getUnitType(const string &name) const{
|
||||||
|
for(int i=0; i<unitTypes.size();i++){
|
||||||
|
if(unitTypes[i].getName()==name){
|
||||||
|
return &unitTypes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw runtime_error("Unit not found: "+name);
|
||||||
|
}
|
||||||
|
|
||||||
|
const UpgradeType *FactionType::getUpgradeType(const string &name) const{
|
||||||
|
for(int i=0; i<upgradeTypes.size();i++){
|
||||||
|
if(upgradeTypes[i].getName()==name){
|
||||||
|
return &upgradeTypes[i];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
throw runtime_error("Upgrade not found: "+name);
|
||||||
|
}
|
||||||
|
|
||||||
|
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
|
144
source/glest_game/types/resource_type.cpp
Normal file
144
source/glest_game/types/resource_type.cpp
Normal file
@@ -0,0 +1,144 @@
|
|||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#include "resource_type.h"
|
||||||
|
|
||||||
|
#include "util.h"
|
||||||
|
#include "element_type.h"
|
||||||
|
#include "logger.h"
|
||||||
|
#include "renderer.h"
|
||||||
|
#include "xml_parser.h"
|
||||||
|
#include "game_util.h"
|
||||||
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
using namespace Shared::Util;
|
||||||
|
using namespace Shared::Xml;
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class ResourceType
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
void ResourceType::load(const string &dir, Checksum* checksum){
|
||||||
|
|
||||||
|
string path, str;
|
||||||
|
Renderer &renderer= Renderer::getInstance();
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
recoup_cost = true;
|
||||||
|
|
||||||
|
name= lastDir(dir);
|
||||||
|
|
||||||
|
Logger::getInstance().add("Resource type: "+ formatString(name), true);
|
||||||
|
path= dir+"/"+name+".xml";
|
||||||
|
checksum->addFile(path);
|
||||||
|
|
||||||
|
//tree
|
||||||
|
XmlTree xmlTree;
|
||||||
|
xmlTree.load(path);
|
||||||
|
const XmlNode *resourceNode= xmlTree.getRootNode();
|
||||||
|
|
||||||
|
//image
|
||||||
|
const XmlNode *imageNode= resourceNode->getChild("image");
|
||||||
|
image= renderer.newTexture2D(rsGame);
|
||||||
|
image->load(dir+"/"+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 path=dir+"/" + modelNode->getAttribute("path")->getRestrictedValue();
|
||||||
|
|
||||||
|
model= renderer.newModel(rsGame);
|
||||||
|
model->load(path);
|
||||||
|
|
||||||
|
//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;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch(const exception &e){
|
||||||
|
throw runtime_error("Error loading resource type: " + path + "\n" + e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
// ==================== misc ====================
|
||||||
|
|
||||||
|
ResourceClass ResourceType::strToRc(const string &s){
|
||||||
|
if(s=="tech"){
|
||||||
|
return rcTech;
|
||||||
|
}
|
||||||
|
if(s=="tileset"){
|
||||||
|
return rcTileset;
|
||||||
|
}
|
||||||
|
if(s=="static"){
|
||||||
|
return rcStatic;
|
||||||
|
}
|
||||||
|
if(s=="consumable"){
|
||||||
|
return rcConsumable;
|
||||||
|
}
|
||||||
|
throw runtime_error("Error converting from string ro resourceClass, found: " + s);
|
||||||
|
}
|
||||||
|
|
||||||
|
}}//end namespace
|
@@ -70,52 +70,38 @@ void TechTree::load(const string &dir, set<string> &factions, Checksum* checksum
|
|||||||
XmlTree xmlTree;
|
XmlTree xmlTree;
|
||||||
string path= dir+"/"+lastDir(dir)+".xml";
|
string path= dir+"/"+lastDir(dir)+".xml";
|
||||||
|
|
||||||
bool bCanProcessFile = true;
|
checksum->addFile(path);
|
||||||
#ifdef _WINDOWS
|
|
||||||
|
|
||||||
DWORD fileAttributes = GetFileAttributes(path.c_str());
|
xmlTree.load(path);
|
||||||
if( (fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN)
|
const XmlNode *techTreeNode= xmlTree.getRootNode();
|
||||||
{
|
|
||||||
bCanProcessFile = false;
|
//attack types
|
||||||
|
const XmlNode *attackTypesNode= techTreeNode->getChild("attack-types");
|
||||||
|
attackTypes.resize(attackTypesNode->getChildCount());
|
||||||
|
for(int i=0; i<attackTypes.size(); ++i){
|
||||||
|
const XmlNode *attackTypeNode= attackTypesNode->getChild("attack-type", i);
|
||||||
|
attackTypes[i].setName(attackTypeNode->getAttribute("name")->getRestrictedValue());
|
||||||
|
attackTypes[i].setId(i);
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
//armor types
|
||||||
|
const XmlNode *armorTypesNode= techTreeNode->getChild("armor-types");
|
||||||
|
armorTypes.resize(armorTypesNode->getChildCount());
|
||||||
|
for(int i=0; i<armorTypes.size(); ++i){
|
||||||
|
const XmlNode *armorTypeNode= armorTypesNode->getChild("armor-type", i);
|
||||||
|
armorTypes[i].setName(armorTypeNode->getAttribute("name")->getRestrictedValue());
|
||||||
|
armorTypes[i].setId(i);
|
||||||
|
}
|
||||||
|
|
||||||
if(bCanProcessFile == true)
|
//damage multipliers
|
||||||
{
|
damageMultiplierTable.init(attackTypes.size(), armorTypes.size());
|
||||||
checksum->addFile(path);
|
const XmlNode *damageMultipliersNode= techTreeNode->getChild("damage-multipliers");
|
||||||
|
for(int i=0; i<damageMultipliersNode->getChildCount(); ++i){
|
||||||
xmlTree.load(path);
|
const XmlNode *damageMultiplierNode= damageMultipliersNode->getChild("damage-multiplier", i);
|
||||||
const XmlNode *techTreeNode= xmlTree.getRootNode();
|
const AttackType *attackType= getAttackType(damageMultiplierNode->getAttribute("attack")->getRestrictedValue());
|
||||||
|
const ArmorType *armorType= getArmorType(damageMultiplierNode->getAttribute("armor")->getRestrictedValue());
|
||||||
//attack types
|
float multiplier= damageMultiplierNode->getAttribute("value")->getFloatValue();
|
||||||
const XmlNode *attackTypesNode= techTreeNode->getChild("attack-types");
|
damageMultiplierTable.setDamageMultiplier(attackType, armorType, multiplier);
|
||||||
attackTypes.resize(attackTypesNode->getChildCount());
|
|
||||||
for(int i=0; i<attackTypes.size(); ++i){
|
|
||||||
const XmlNode *attackTypeNode= attackTypesNode->getChild("attack-type", i);
|
|
||||||
attackTypes[i].setName(attackTypeNode->getAttribute("name")->getRestrictedValue());
|
|
||||||
attackTypes[i].setId(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
//armor types
|
|
||||||
const XmlNode *armorTypesNode= techTreeNode->getChild("armor-types");
|
|
||||||
armorTypes.resize(armorTypesNode->getChildCount());
|
|
||||||
for(int i=0; i<armorTypes.size(); ++i){
|
|
||||||
const XmlNode *armorTypeNode= armorTypesNode->getChild("armor-type", i);
|
|
||||||
armorTypes[i].setName(armorTypeNode->getAttribute("name")->getRestrictedValue());
|
|
||||||
armorTypes[i].setId(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
//damage multipliers
|
|
||||||
damageMultiplierTable.init(attackTypes.size(), armorTypes.size());
|
|
||||||
const XmlNode *damageMultipliersNode= techTreeNode->getChild("damage-multipliers");
|
|
||||||
for(int i=0; i<damageMultipliersNode->getChildCount(); ++i){
|
|
||||||
const XmlNode *damageMultiplierNode= damageMultipliersNode->getChild("damage-multiplier", i);
|
|
||||||
const AttackType *attackType= getAttackType(damageMultiplierNode->getAttribute("attack")->getRestrictedValue());
|
|
||||||
const ArmorType *armorType= getArmorType(damageMultiplierNode->getAttribute("armor")->getRestrictedValue());
|
|
||||||
float multiplier= damageMultiplierNode->getAttribute("value")->getFloatValue();
|
|
||||||
damageMultiplierTable.setDamageMultiplier(attackType, armorType, multiplier);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch(const exception &e){
|
catch(const exception &e){
|
||||||
|
@@ -101,17 +101,6 @@ void UnitType::load(int id,const string &dir, const TechTree *techTree, const Fa
|
|||||||
|
|
||||||
//file load
|
//file load
|
||||||
path= dir+"/"+name+".xml";
|
path= dir+"/"+name+".xml";
|
||||||
|
|
||||||
#ifdef _WINDOWS
|
|
||||||
|
|
||||||
DWORD fileAttributes = GetFileAttributes(path.c_str());
|
|
||||||
if( (fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
checksum->addFile(path);
|
checksum->addFile(path);
|
||||||
|
|
||||||
XmlTree xmlTree;
|
XmlTree xmlTree;
|
||||||
|
209
source/glest_game/types/upgrade_type.cpp
Normal file
209
source/glest_game/types/upgrade_type.cpp
Normal file
@@ -0,0 +1,209 @@
|
|||||||
|
// ==============================================================
|
||||||
|
// This file is part of Glest (www.glest.org)
|
||||||
|
//
|
||||||
|
// Copyright (C) 2001-2008 Marti<74>o Figueroa
|
||||||
|
//
|
||||||
|
// You can redistribute this code and/or modify it under
|
||||||
|
// the terms of the GNU General Public License as published
|
||||||
|
// by the Free Software Foundation; either version 2 of the
|
||||||
|
// License, or (at your option) any later version
|
||||||
|
// ==============================================================
|
||||||
|
|
||||||
|
#include "upgrade_type.h"
|
||||||
|
|
||||||
|
#include <algorithm>
|
||||||
|
#include <cassert>
|
||||||
|
|
||||||
|
#include "unit_type.h"
|
||||||
|
#include "util.h"
|
||||||
|
#include "logger.h"
|
||||||
|
#include "lang.h"
|
||||||
|
#include "xml_parser.h"
|
||||||
|
#include "tech_tree.h"
|
||||||
|
#include "faction_type.h"
|
||||||
|
#include "resource.h"
|
||||||
|
#include "renderer.h"
|
||||||
|
#include "game_util.h"
|
||||||
|
#include "leak_dumper.h"
|
||||||
|
|
||||||
|
using namespace Shared::Util;
|
||||||
|
using namespace Shared::Xml;
|
||||||
|
|
||||||
|
namespace Glest{ namespace Game{
|
||||||
|
|
||||||
|
// =====================================================
|
||||||
|
// class UpgradeType
|
||||||
|
// =====================================================
|
||||||
|
|
||||||
|
// ==================== get ====================
|
||||||
|
|
||||||
|
bool UpgradeType::isAffected(const UnitType *unitType) const{
|
||||||
|
return find(effects.begin(), effects.end(), unitType)!=effects.end();
|
||||||
|
}
|
||||||
|
|
||||||
|
// ==================== misc ====================
|
||||||
|
|
||||||
|
void UpgradeType::preLoad(const string &dir){
|
||||||
|
name=lastDir(dir);
|
||||||
|
}
|
||||||
|
|
||||||
|
void UpgradeType::load(const string &dir, const TechTree *techTree, const FactionType *factionType, Checksum* checksum){
|
||||||
|
string path;
|
||||||
|
|
||||||
|
Logger::getInstance().add("Upgrade type: "+ formatString(name), true);
|
||||||
|
|
||||||
|
path=dir+"/"+name+".xml";
|
||||||
|
|
||||||
|
try{
|
||||||
|
checksum->addFile(path);
|
||||||
|
|
||||||
|
XmlTree xmlTree;
|
||||||
|
xmlTree.load(path);
|
||||||
|
const XmlNode *upgradeNode= xmlTree.getRootNode();
|
||||||
|
|
||||||
|
//image
|
||||||
|
const XmlNode *imageNode= upgradeNode->getChild("image");
|
||||||
|
image= Renderer::getInstance().newTexture2D(rsGame);
|
||||||
|
image->load(dir+"/"+imageNode->getAttribute("path")->getRestrictedValue());
|
||||||
|
|
||||||
|
//image cancel
|
||||||
|
const XmlNode *imageCancelNode= upgradeNode->getChild("image-cancel");
|
||||||
|
cancelImage= Renderer::getInstance().newTexture2D(rsGame);
|
||||||
|
cancelImage->load(dir+"/"+imageCancelNode->getAttribute("path")->getRestrictedValue());
|
||||||
|
|
||||||
|
//upgrade time
|
||||||
|
const XmlNode *upgradeTimeNode= upgradeNode->getChild("time");
|
||||||
|
productionTime= upgradeTimeNode->getAttribute("value")->getIntValue();
|
||||||
|
|
||||||
|
//unit requirements
|
||||||
|
const XmlNode *unitRequirementsNode= upgradeNode->getChild("unit-requirements");
|
||||||
|
for(int i=0; i<unitRequirementsNode->getChildCount(); ++i){
|
||||||
|
const XmlNode *unitNode= unitRequirementsNode->getChild("unit", i);
|
||||||
|
string name= unitNode->getAttribute("name")->getRestrictedValue();
|
||||||
|
unitReqs.push_back(factionType->getUnitType(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
//upgrade requirements
|
||||||
|
const XmlNode *upgradeRequirementsNode= upgradeNode->getChild("upgrade-requirements");
|
||||||
|
for(int i=0; i<upgradeRequirementsNode->getChildCount(); ++i){
|
||||||
|
const XmlNode *upgradeReqNode= upgradeRequirementsNode->getChild("upgrade", i);
|
||||||
|
string name= upgradeReqNode->getAttribute("name")->getRestrictedValue();
|
||||||
|
upgradeReqs.push_back(factionType->getUpgradeType(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
//resource requirements
|
||||||
|
const XmlNode *resourceRequirementsNode= upgradeNode->getChild("resource-requirements");
|
||||||
|
costs.resize(resourceRequirementsNode->getChildCount());
|
||||||
|
for(int i=0; i<costs.size(); ++i){
|
||||||
|
const XmlNode *resourceNode= resourceRequirementsNode->getChild("resource", i);
|
||||||
|
string name= resourceNode->getAttribute("name")->getRestrictedValue();
|
||||||
|
int amount= resourceNode->getAttribute("amount")->getIntValue();
|
||||||
|
costs[i].init(techTree->getResourceType(name), amount);
|
||||||
|
}
|
||||||
|
|
||||||
|
//effects
|
||||||
|
const XmlNode *effectsNode= upgradeNode->getChild("effects");
|
||||||
|
for(int i=0; i<effectsNode->getChildCount(); ++i){
|
||||||
|
const XmlNode *unitNode= effectsNode->getChild("unit", i);
|
||||||
|
string name= unitNode->getAttribute("name")->getRestrictedValue();
|
||||||
|
effects.push_back(factionType->getUnitType(name));
|
||||||
|
}
|
||||||
|
|
||||||
|
//values
|
||||||
|
maxHp= upgradeNode->getChild("max-hp")->getAttribute("value")->getIntValue();
|
||||||
|
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();
|
||||||
|
armor= upgradeNode->getChild("armor")->getAttribute("value")->getIntValue();
|
||||||
|
moveSpeed= upgradeNode->getChild("move-speed")->getAttribute("value")->getIntValue();
|
||||||
|
prodSpeed= upgradeNode->getChild("production-speed")->getAttribute("value")->getIntValue();
|
||||||
|
|
||||||
|
}
|
||||||
|
catch(const exception &e){
|
||||||
|
throw runtime_error("Error loading UpgradeType: "+ dir + "\n" +e.what());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
string UpgradeType::getReqDesc() const{
|
||||||
|
|
||||||
|
string str;
|
||||||
|
int i;
|
||||||
|
Lang &lang= Lang::getInstance();
|
||||||
|
|
||||||
|
str= ProducibleType::getReqDesc();
|
||||||
|
if(getEffectCount()>0){
|
||||||
|
str+= "\n"+ lang.get("Upgrades")+":\n";
|
||||||
|
for(i=0; i<getEffectCount(); ++i){
|
||||||
|
str+= getEffect(i)->getName()+"\n";
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(maxHp!=0){
|
||||||
|
str+= lang.get("Hp")+" +"+intToStr(maxHp);
|
||||||
|
}
|
||||||
|
if(sight!=0){
|
||||||
|
str+= lang.get("Sight")+" +"+intToStr(sight);
|
||||||
|
}
|
||||||
|
if(maxEp!=0){
|
||||||
|
str+= lang.get("Ep")+" +"+intToStr(maxEp)+"\n";
|
||||||
|
}
|
||||||
|
if(attackStrength!=0){
|
||||||
|
str+= lang.get("AttackStrenght")+" +"+intToStr(attackStrength)+"\n";
|
||||||
|
}
|
||||||
|
if(attackRange!=0){
|
||||||
|
str+= lang.get("AttackDistance")+" +"+intToStr(attackRange)+"\n";
|
||||||
|
}
|
||||||
|
if(armor!=0){
|
||||||
|
str+= lang.get("Armor")+" +"+intToStr(armor)+"\n";
|
||||||
|
}
|
||||||
|
if(moveSpeed!=0){
|
||||||
|
str+= lang.get("WalkSpeed")+"+ "+intToStr(moveSpeed)+"\n";
|
||||||
|
}
|
||||||
|
if(prodSpeed!=0){
|
||||||
|
str+= lang.get("ProductionSpeed")+" +"+intToStr(prodSpeed)+"\n";
|
||||||
|
}
|
||||||
|
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
// ===============================
|
||||||
|
// class TotalUpgrade
|
||||||
|
// ===============================
|
||||||
|
|
||||||
|
TotalUpgrade::TotalUpgrade(){
|
||||||
|
reset();
|
||||||
|
}
|
||||||
|
|
||||||
|
void TotalUpgrade::reset(){
|
||||||
|
maxHp= 0;
|
||||||
|
maxEp= 0;
|
||||||
|
sight=0;
|
||||||
|
armor= 0;
|
||||||
|
attackStrength= 0;
|
||||||
|
attackRange= 0;
|
||||||
|
moveSpeed= 0;
|
||||||
|
prodSpeed=0;
|
||||||
|
}
|
||||||
|
|
||||||
|
void TotalUpgrade::sum(const UpgradeType *ut){
|
||||||
|
maxHp+= ut->getMaxHp();
|
||||||
|
maxEp+= ut->getMaxEp();
|
||||||
|
sight+= ut->getSight();
|
||||||
|
armor+= ut->getArmor();
|
||||||
|
attackStrength+= ut->getAttackStrength();
|
||||||
|
attackRange+= ut->getAttackRange();
|
||||||
|
moveSpeed+= ut->getMoveSpeed();
|
||||||
|
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
|
@@ -108,16 +108,6 @@ void Tileset::load(const string &dir, Checksum *checksum){
|
|||||||
string name= lastDir(dir);
|
string name= lastDir(dir);
|
||||||
string path= dir+"/"+name+".xml";
|
string path= dir+"/"+name+".xml";
|
||||||
|
|
||||||
#ifdef _WINDOWS
|
|
||||||
|
|
||||||
DWORD fileAttributes = GetFileAttributes(path.c_str());
|
|
||||||
if( (fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN)
|
|
||||||
{
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
#endif
|
|
||||||
|
|
||||||
checksum->addFile(path);
|
checksum->addFile(path);
|
||||||
|
|
||||||
try{
|
try{
|
||||||
|
@@ -224,8 +224,7 @@ void findAll(const string &path, vector<string> &results, bool cutExtension, boo
|
|||||||
do{
|
do{
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fi.name [%s]\n",__FILE__,__FUNCTION__,__LINE__,fi.name);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] fi.name [%s]\n",__FILE__,__FUNCTION__,__LINE__,fi.name);
|
||||||
|
|
||||||
DWORD fileAttributes = GetFileAttributes(fi.name);
|
if((fi.attrib & _A_HIDDEN) == _A_HIDDEN) {
|
||||||
if( (fileAttributes != INVALID_FILE_ATTRIBUTES && ((fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN)) || (fi.attrib & _A_HIDDEN) == _A_HIDDEN) {
|
|
||||||
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] file IS HIDDEN fi.name [%s]\n",__FILE__,__FUNCTION__,__LINE__,fi.name);
|
SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] file IS HIDDEN fi.name [%s]\n",__FILE__,__FUNCTION__,__LINE__,fi.name);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
@@ -264,14 +263,6 @@ bool isdir(const char *path)
|
|||||||
{
|
{
|
||||||
struct stat stats;
|
struct stat stats;
|
||||||
bool ret = stat (path, &stats) == 0 && S_ISDIR(stats.st_mode);
|
bool ret = stat (path, &stats) == 0 && S_ISDIR(stats.st_mode);
|
||||||
|
|
||||||
if(ret == true) {
|
|
||||||
DWORD fileAttributes = GetFileAttributes(path);
|
|
||||||
if( fileAttributes != INVALID_FILE_ATTRIBUTES && (fileAttributes & FILE_ATTRIBUTE_HIDDEN) == FILE_ATTRIBUTE_HIDDEN)
|
|
||||||
{
|
|
||||||
ret = false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
if(ret == false) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] NOT a path [%s]\n",__FILE__,__FUNCTION__,__LINE__,path);
|
if(ret == false) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] NOT a path [%s]\n",__FILE__,__FUNCTION__,__LINE__,path);
|
||||||
|
|
||||||
return ret;
|
return ret;
|
||||||
|
Reference in New Issue
Block a user